ba40d12e198b77eb50218b1eba1f84da.json 16.3 KB
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport DatePanel from '../DatePanel';\nimport TimePanel from '../TimePanel';\nimport { tuple } from '../../utils/miscUtil';\n\nfunction setTime(generateConfig, date, defaultDate) {\n  if (!defaultDate) {\n    return date;\n  }\n\n  var newDate = date;\n  newDate = generateConfig.setHour(newDate, generateConfig.getHour(defaultDate));\n  newDate = generateConfig.setMinute(newDate, generateConfig.getMinute(defaultDate));\n  newDate = generateConfig.setSecond(newDate, generateConfig.getSecond(defaultDate));\n  return newDate;\n}\n\nvar ACTIVE_PANEL = tuple('date', 'time');\n\nfunction DatetimePanel(props) {\n  var prefixCls = props.prefixCls,\n      operationRef = props.operationRef,\n      generateConfig = props.generateConfig,\n      value = props.value,\n      defaultValue = props.defaultValue,\n      disabledTime = props.disabledTime,\n      showTime = props.showTime,\n      onSelect = props.onSelect;\n  var panelPrefixCls = \"\".concat(prefixCls, \"-datetime-panel\");\n\n  var _React$useState = React.useState(null),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      activePanel = _React$useState2[0],\n      setActivePanel = _React$useState2[1];\n\n  var dateOperationRef = React.useRef({});\n  var timeOperationRef = React.useRef({});\n  var timeProps = _typeof(showTime) === 'object' ? _objectSpread({}, showTime) : {}; // ======================= Keyboard =======================\n\n  function getNextActive(offset) {\n    var activeIndex = ACTIVE_PANEL.indexOf(activePanel) + offset;\n    var nextActivePanel = ACTIVE_PANEL[activeIndex] || null;\n    return nextActivePanel;\n  }\n\n  var onBlur = function onBlur(e) {\n    if (timeOperationRef.current.onBlur) {\n      timeOperationRef.current.onBlur(e);\n    }\n\n    setActivePanel(null);\n  };\n\n  operationRef.current = {\n    onKeyDown: function onKeyDown(event) {\n      // Switch active panel\n      if (event.which === KeyCode.TAB) {\n        var nextActivePanel = getNextActive(event.shiftKey ? -1 : 1);\n        setActivePanel(nextActivePanel);\n\n        if (nextActivePanel) {\n          event.preventDefault();\n        }\n\n        return true;\n      } // Operate on current active panel\n\n\n      if (activePanel) {\n        var ref = activePanel === 'date' ? dateOperationRef : timeOperationRef;\n\n        if (ref.current && ref.current.onKeyDown) {\n          ref.current.onKeyDown(event);\n        }\n\n        return true;\n      } // Switch first active panel if operate without panel\n\n\n      if ([KeyCode.LEFT, KeyCode.RIGHT, KeyCode.UP, KeyCode.DOWN].includes(event.which)) {\n        setActivePanel('date');\n        return true;\n      }\n\n      return false;\n    },\n    onBlur: onBlur,\n    onClose: onBlur\n  }; // ======================== Events ========================\n\n  var onInternalSelect = function onInternalSelect(date, source) {\n    var selectedDate = date;\n\n    if (source === 'date' && !value && timeProps.defaultValue) {\n      // Date with time defaultValue\n      selectedDate = generateConfig.setHour(selectedDate, generateConfig.getHour(timeProps.defaultValue));\n      selectedDate = generateConfig.setMinute(selectedDate, generateConfig.getMinute(timeProps.defaultValue));\n      selectedDate = generateConfig.setSecond(selectedDate, generateConfig.getSecond(timeProps.defaultValue));\n    } else if (source === 'time' && !value && defaultValue) {\n      selectedDate = generateConfig.setYear(selectedDate, generateConfig.getYear(defaultValue));\n      selectedDate = generateConfig.setMonth(selectedDate, generateConfig.getMonth(defaultValue));\n      selectedDate = generateConfig.setDate(selectedDate, generateConfig.getDate(defaultValue));\n    }\n\n    if (onSelect) {\n      onSelect(selectedDate, 'mouse');\n    }\n  }; // ======================== Render ========================\n\n\n  var disabledTimes = disabledTime ? disabledTime(value || null) : {};\n  return /*#__PURE__*/React.createElement(\"div\", {\n    className: classNames(panelPrefixCls, _defineProperty({}, \"\".concat(panelPrefixCls, \"-active\"), activePanel))\n  }, /*#__PURE__*/React.createElement(DatePanel, Object.assign({}, props, {\n    operationRef: dateOperationRef,\n    active: activePanel === 'date',\n    onSelect: function onSelect(date) {\n      onInternalSelect(setTime(generateConfig, date, showTime && _typeof(showTime) === 'object' ? showTime.defaultValue : null), 'date');\n    }\n  })), /*#__PURE__*/React.createElement(TimePanel, Object.assign({}, props, {\n    format: undefined\n  }, timeProps, disabledTimes, {\n    defaultValue: undefined,\n    operationRef: timeOperationRef,\n    active: activePanel === 'time',\n    onSelect: function onSelect(date) {\n      onInternalSelect(date, 'time');\n    }\n  })));\n}\n\nexport default DatetimePanel;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-picker/es/panels/DatetimePanel/index.js"],"names":["_defineProperty","_objectSpread","_typeof","_slicedToArray","React","classNames","KeyCode","DatePanel","TimePanel","tuple","setTime","generateConfig","date","defaultDate","newDate","setHour","getHour","setMinute","getMinute","setSecond","getSecond","ACTIVE_PANEL","DatetimePanel","props","prefixCls","operationRef","value","defaultValue","disabledTime","showTime","onSelect","panelPrefixCls","concat","_React$useState","useState","_React$useState2","activePanel","setActivePanel","dateOperationRef","useRef","timeOperationRef","timeProps","getNextActive","offset","activeIndex","indexOf","nextActivePanel","onBlur","e","current","onKeyDown","event","which","TAB","shiftKey","preventDefault","ref","LEFT","RIGHT","UP","DOWN","includes","onClose","onInternalSelect","source","selectedDate","setYear","getYear","setMonth","getMonth","setDate","getDate","disabledTimes","createElement","className","Object","assign","active","format","undefined"],"mappings":"AAAA,OAAOA,eAAP,MAA4B,2CAA5B;AACA,OAAOC,aAAP,MAA0B,0CAA1B;AACA,OAAOC,OAAP,MAAoB,mCAApB;AACA,OAAOC,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,UAAP,MAAuB,YAAvB;AACA,OAAOC,OAAP,MAAoB,oBAApB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AACA,SAASC,KAAT,QAAsB,sB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AAlB,EAAwB;AAChCmD,MAAAA,gBAAgB,CAACrD,OAAO,CAACC,cAAD,EAAiBC,IAAjB,EAAuBiB,QAAQ,IAAI3B,OAAO,CAAC2B,QAAD,CAAP,KAAsB,QAAlC,GAA6CA,QAAQ,CAACF,YAAtD,GAAqE,IAA5F,CAAR,EAA2G,MAA3G,CAAhB;AACD;AALqE,GAAzB,CAA/B,CAFI,EAQf,aAAavB,KAAK,CAACqE,aAAN,CAAoBjE,SAApB,EAA+BmE,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBrD,KAAlB,EAAyB;AACxEuD,IAAAA,MAAM,EAAEC;AADgE,GAAzB,EAE9CtC,SAF8C,EAEnC+B,aAFmC,EAEpB;AAC3B7C,IAAAA,YAAY,EAAEoD,SADa;AAE3BtD,IAAAA,YAAY,EAAEe,gBAFa;AAG3BqC,IAAAA,MAAM,EAAEzC,WAAW,KAAK,MAHG;AAI3BN,IAAAA,QAAQ,EAAE,SAASA,QAAT,CAAkBlB,IAAlB,EAAwB;AAChCmD,MAAAA,gBAAgB,CAACnD,IAAD,EAAO,MAAP,CAAhB;AACD;AAN0B,GAFoB,CAA/B,CARE,CAApB;AAkBD;;AAED,eAAeU,aAAf","sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport DatePanel from '../DatePanel';\nimport TimePanel from '../TimePanel';\nimport { tuple } from '../../utils/miscUtil';\n\nfunction setTime(generateConfig, date, defaultDate) {\n  if (!defaultDate) {\n    return date;\n  }\n\n  var newDate = date;\n  newDate = generateConfig.setHour(newDate, generateConfig.getHour(defaultDate));\n  newDate = generateConfig.setMinute(newDate, generateConfig.getMinute(defaultDate));\n  newDate = generateConfig.setSecond(newDate, generateConfig.getSecond(defaultDate));\n  return newDate;\n}\n\nvar ACTIVE_PANEL = tuple('date', 'time');\n\nfunction DatetimePanel(props) {\n  var prefixCls = props.prefixCls,\n      operationRef = props.operationRef,\n      generateConfig = props.generateConfig,\n      value = props.value,\n      defaultValue = props.defaultValue,\n      disabledTime = props.disabledTime,\n      showTime = props.showTime,\n      onSelect = props.onSelect;\n  var panelPrefixCls = \"\".concat(prefixCls, \"-datetime-panel\");\n\n  var _React$useState = React.useState(null),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      activePanel = _React$useState2[0],\n      setActivePanel = _React$useState2[1];\n\n  var dateOperationRef = React.useRef({});\n  var timeOperationRef = React.useRef({});\n  var timeProps = _typeof(showTime) === 'object' ? _objectSpread({}, showTime) : {}; // ======================= Keyboard =======================\n\n  function getNextActive(offset) {\n    var activeIndex = ACTIVE_PANEL.indexOf(activePanel) + offset;\n    var nextActivePanel = ACTIVE_PANEL[activeIndex] || null;\n    return nextActivePanel;\n  }\n\n  var onBlur = function onBlur(e) {\n    if (timeOperationRef.current.onBlur) {\n      timeOperationRef.current.onBlur(e);\n    }\n\n    setActivePanel(null);\n  };\n\n  operationRef.current = {\n    onKeyDown: function onKeyDown(event) {\n      // Switch active panel\n      if (event.which === KeyCode.TAB) {\n        var nextActivePanel = getNextActive(event.shiftKey ? -1 : 1);\n        setActivePanel(nextActivePanel);\n\n        if (nextActivePanel) {\n          event.preventDefault();\n        }\n\n        return true;\n      } // Operate on current active panel\n\n\n      if (activePanel) {\n        var ref = activePanel === 'date' ? dateOperationRef : timeOperationRef;\n\n        if (ref.current && ref.current.onKeyDown) {\n          ref.current.onKeyDown(event);\n        }\n\n        return true;\n      } // Switch first active panel if operate without panel\n\n\n      if ([KeyCode.LEFT, KeyCode.RIGHT, KeyCode.UP, KeyCode.DOWN].includes(event.which)) {\n        setActivePanel('date');\n        return true;\n      }\n\n      return false;\n    },\n    onBlur: onBlur,\n    onClose: onBlur\n  }; // ======================== Events ========================\n\n  var onInternalSelect = function onInternalSelect(date, source) {\n    var selectedDate = date;\n\n    if (source === 'date' && !value && timeProps.defaultValue) {\n      // Date with time defaultValue\n      selectedDate = generateConfig.setHour(selectedDate, generateConfig.getHour(timeProps.defaultValue));\n      selectedDate = generateConfig.setMinute(selectedDate, generateConfig.getMinute(timeProps.defaultValue));\n      selectedDate = generateConfig.setSecond(selectedDate, generateConfig.getSecond(timeProps.defaultValue));\n    } else if (source === 'time' && !value && defaultValue) {\n      selectedDate = generateConfig.setYear(selectedDate, generateConfig.getYear(defaultValue));\n      selectedDate = generateConfig.setMonth(selectedDate, generateConfig.getMonth(defaultValue));\n      selectedDate = generateConfig.setDate(selectedDate, generateConfig.getDate(defaultValue));\n    }\n\n    if (onSelect) {\n      onSelect(selectedDate, 'mouse');\n    }\n  }; // ======================== Render ========================\n\n\n  var disabledTimes = disabledTime ? disabledTime(value || null) : {};\n  return /*#__PURE__*/React.createElement(\"div\", {\n    className: classNames(panelPrefixCls, _defineProperty({}, \"\".concat(panelPrefixCls, \"-active\"), activePanel))\n  }, /*#__PURE__*/React.createElement(DatePanel, Object.assign({}, props, {\n    operationRef: dateOperationRef,\n    active: activePanel === 'date',\n    onSelect: function onSelect(date) {\n      onInternalSelect(setTime(generateConfig, date, showTime && _typeof(showTime) === 'object' ? showTime.defaultValue : null), 'date');\n    }\n  })), /*#__PURE__*/React.createElement(TimePanel, Object.assign({}, props, {\n    format: undefined\n  }, timeProps, disabledTimes, {\n    defaultValue: undefined,\n    operationRef: timeOperationRef,\n    active: activePanel === 'time',\n    onSelect: function onSelect(date) {\n      onInternalSelect(date, 'time');\n    }\n  })));\n}\n\nexport default DatetimePanel;"]},"metadata":{},"sourceType":"module"}