6c036992b8c9ce0fb437c1858f32eaac.json
23.3 KB
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useMemo from \"rc-util/es/hooks/useMemo\";\nimport TimeUnitColumn from './TimeUnitColumn';\nimport { leftPad } from '../../utils/miscUtil';\nimport { setTime as utilSetTime } from '../../utils/timeUtil';\n\nfunction shouldUnitsUpdate(prevUnits, nextUnits) {\n if (prevUnits.length !== nextUnits.length) return true; // if any unit's disabled status is different, the units should be re-evaluted\n\n for (var i = 0; i < prevUnits.length; i += 1) {\n if (prevUnits[i].disabled !== nextUnits[i].disabled) return true;\n }\n\n return false;\n}\n\nfunction generateUnits(start, end, step, disabledUnits) {\n var units = [];\n\n for (var i = start; i <= end; i += step) {\n units.push({\n label: leftPad(i, 2),\n value: i,\n disabled: (disabledUnits || []).includes(i)\n });\n }\n\n return units;\n}\n\nfunction TimeBody(props) {\n var generateConfig = props.generateConfig,\n prefixCls = props.prefixCls,\n operationRef = props.operationRef,\n activeColumnIndex = props.activeColumnIndex,\n value = props.value,\n showHour = props.showHour,\n showMinute = props.showMinute,\n showSecond = props.showSecond,\n use12Hours = props.use12Hours,\n _props$hourStep = props.hourStep,\n hourStep = _props$hourStep === void 0 ? 1 : _props$hourStep,\n _props$minuteStep = props.minuteStep,\n minuteStep = _props$minuteStep === void 0 ? 1 : _props$minuteStep,\n _props$secondStep = props.secondStep,\n secondStep = _props$secondStep === void 0 ? 1 : _props$secondStep,\n disabledHours = props.disabledHours,\n disabledMinutes = props.disabledMinutes,\n disabledSeconds = props.disabledSeconds,\n hideDisabledOptions = props.hideDisabledOptions,\n onSelect = props.onSelect;\n var columns = [];\n var contentPrefixCls = \"\".concat(prefixCls, \"-content\");\n var columnPrefixCls = \"\".concat(prefixCls, \"-time-panel\");\n var isPM;\n var originHour = value ? generateConfig.getHour(value) : -1;\n var hour = originHour;\n var minute = value ? generateConfig.getMinute(value) : -1;\n var second = value ? generateConfig.getSecond(value) : -1;\n\n var setTime = function setTime(isNewPM, newHour, newMinute, newSecond) {\n var newDate = value || generateConfig.getNow();\n var mergedHour = Math.max(0, newHour);\n var mergedMinute = Math.max(0, newMinute);\n var mergedSecond = Math.max(0, newSecond);\n newDate = utilSetTime(generateConfig, newDate, !use12Hours || !isNewPM ? mergedHour : mergedHour + 12, mergedMinute, mergedSecond);\n return newDate;\n }; // ========================= Unit =========================\n\n\n var rawHours = generateUnits(0, 23, hourStep, disabledHours && disabledHours());\n var memorizedRawHours = useMemo(function () {\n return rawHours;\n }, rawHours, shouldUnitsUpdate); // Should additional logic to handle 12 hours\n\n if (use12Hours) {\n isPM = hour >= 12; // -1 means should display AM\n\n hour %= 12;\n }\n\n var _React$useMemo = React.useMemo(function () {\n if (!use12Hours) {\n return [false, false];\n }\n\n var AMPMDisabled = [true, true];\n memorizedRawHours.forEach(function (_ref) {\n var disabled = _ref.disabled,\n hourValue = _ref.value;\n if (disabled) return;\n\n if (hourValue >= 12) {\n AMPMDisabled[1] = false;\n } else {\n AMPMDisabled[0] = false;\n }\n });\n return AMPMDisabled;\n }, [use12Hours, memorizedRawHours]),\n _React$useMemo2 = _slicedToArray(_React$useMemo, 2),\n AMDisabled = _React$useMemo2[0],\n PMDisabled = _React$useMemo2[1];\n\n var hours = React.useMemo(function () {\n if (!use12Hours) return memorizedRawHours;\n return memorizedRawHours.filter(isPM ? function (hourMeta) {\n return hourMeta.value >= 12;\n } : function (hourMeta) {\n return hourMeta.value < 12;\n }).map(function (hourMeta) {\n var hourValue = hourMeta.value % 12;\n var hourLabel = hourValue === 0 ? '12' : leftPad(hourValue, 2);\n return _objectSpread(_objectSpread({}, hourMeta), {}, {\n label: hourLabel,\n value: hourValue\n });\n });\n }, [use12Hours, memorizedRawHours]);\n var minutes = generateUnits(0, 59, minuteStep, disabledMinutes && disabledMinutes(originHour));\n var seconds = generateUnits(0, 59, secondStep, disabledSeconds && disabledSeconds(originHour, minute)); // ====================== Operations ======================\n\n operationRef.current = {\n onUpDown: function onUpDown(diff) {\n var column = columns[activeColumnIndex];\n\n if (column) {\n var valueIndex = column.units.findIndex(function (unit) {\n return unit.value === column.value;\n });\n var unitLen = column.units.length;\n\n for (var i = 1; i < unitLen; i += 1) {\n var nextUnit = column.units[(valueIndex + diff * i + unitLen) % unitLen];\n\n if (nextUnit.disabled !== true) {\n column.onSelect(nextUnit.value);\n break;\n }\n }\n }\n }\n }; // ======================== Render ========================\n\n function addColumnNode(condition, node, columnValue, units, onColumnSelect) {\n if (condition !== false) {\n columns.push({\n node: /*#__PURE__*/React.cloneElement(node, {\n prefixCls: columnPrefixCls,\n value: columnValue,\n active: activeColumnIndex === columns.length,\n onSelect: onColumnSelect,\n units: units,\n hideDisabledOptions: hideDisabledOptions\n }),\n onSelect: onColumnSelect,\n value: columnValue,\n units: units\n });\n }\n } // Hour\n\n\n addColumnNode(showHour, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"hour\"\n }), hour, hours, function (num) {\n onSelect(setTime(isPM, num, minute, second), 'mouse');\n }); // Minute\n\n addColumnNode(showMinute, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"minute\"\n }), minute, minutes, function (num) {\n onSelect(setTime(isPM, hour, num, second), 'mouse');\n }); // Second\n\n addColumnNode(showSecond, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"second\"\n }), second, seconds, function (num) {\n onSelect(setTime(isPM, hour, minute, num), 'mouse');\n }); // 12 Hours\n\n var PMIndex = -1;\n\n if (typeof isPM === 'boolean') {\n PMIndex = isPM ? 1 : 0;\n }\n\n addColumnNode(use12Hours === true, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"12hours\"\n }), PMIndex, [{\n label: 'AM',\n value: 0,\n disabled: AMDisabled\n }, {\n label: 'PM',\n value: 1,\n disabled: PMDisabled\n }], function (num) {\n onSelect(setTime(!!num, hour, minute, second), 'mouse');\n });\n return /*#__PURE__*/React.createElement(\"div\", {\n className: contentPrefixCls\n }, columns.map(function (_ref2) {\n var node = _ref2.node;\n return node;\n }));\n}\n\nexport default TimeBody;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-picker/es/panels/TimePanel/TimeBody.js"],"names":["_objectSpread","_slicedToArray","React","useMemo","TimeUnitColumn","leftPad","setTime","utilSetTime","shouldUnitsUpdate","prevUnits","nextUnits","length","i","disabled","generateUnits","start","end","step","disabledUnits","units","push","label","value","includes","TimeBody","props","generateConfig","prefixCls","operationRef","activeColumnIndex","showHour","showMinute","showSecond","use12Hours","_props$hourStep","hourStep","_props$minuteStep","minuteStep","_props$secondStep","secondStep","disabledHours","disabledMinutes","disabledSeconds","hideDisabledOptions","onSelect","columns","contentPrefixCls","concat","columnPrefixCls","isPM","originHour","getHour","hour","minute","getMinute","second","getSecond","isNewPM","newHour","newMinute","newSecond","newDate","getNow","mergedHour","Math","max","mergedMinute","mergedSecond","rawHours","memorizedRawHours","_React$useMemo","AMPMDisabled","forEach","_ref","hourValue","_React$useMemo2","AMDisabled","PMDisabled","hours","filter","hourMeta","map","hourLabel","minutes","seconds","current","onUpDown","diff","column","valueIndex","findIndex","unit","unitLen","nextUnit","addColumnNode","condition","node","columnValue","onColumnSelect","cloneElement","active","createElement","key","num","PMIndex","className","_ref2"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,0CAA1B;AACA,OAAOC,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,0BAApB;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,SAASC,OAAT,QAAwB,sBAAxB;AACA,SAASC,OAAO,IAAIC,WAApB,QAAuC,sBAAvC;;AAEA,SAASC,iBAAT,CAA2BC,SAA3B,EAAsCC,SAAtC,EAAiD;AAC/C,MAAID,SAAS,CAACE,MAAV,KAAqBD,SAAS,CAACC,MAAnC,EAA2C,OAAO,IAAP,C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;AAaA,SAAO,aAAarD,KAAK,CAACmG,aAAN,CAAoB,KAApB,EAA2B;AAC7CI,IAAAA,SAAS,EAAE3D;AADkC,GAA3B,EAEjBD,OAAO,CAACoC,GAAR,CAAY,UAAUyB,KAAV,EAAiB;AAC9B,QAAIV,IAAI,GAAGU,KAAK,CAACV,IAAjB;AACA,WAAOA,IAAP;AACD,GAHE,CAFiB,CAApB;AAMD;;AAED,eAAexE,QAAf","sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport useMemo from \"rc-util/es/hooks/useMemo\";\nimport TimeUnitColumn from './TimeUnitColumn';\nimport { leftPad } from '../../utils/miscUtil';\nimport { setTime as utilSetTime } from '../../utils/timeUtil';\n\nfunction shouldUnitsUpdate(prevUnits, nextUnits) {\n if (prevUnits.length !== nextUnits.length) return true; // if any unit's disabled status is different, the units should be re-evaluted\n\n for (var i = 0; i < prevUnits.length; i += 1) {\n if (prevUnits[i].disabled !== nextUnits[i].disabled) return true;\n }\n\n return false;\n}\n\nfunction generateUnits(start, end, step, disabledUnits) {\n var units = [];\n\n for (var i = start; i <= end; i += step) {\n units.push({\n label: leftPad(i, 2),\n value: i,\n disabled: (disabledUnits || []).includes(i)\n });\n }\n\n return units;\n}\n\nfunction TimeBody(props) {\n var generateConfig = props.generateConfig,\n prefixCls = props.prefixCls,\n operationRef = props.operationRef,\n activeColumnIndex = props.activeColumnIndex,\n value = props.value,\n showHour = props.showHour,\n showMinute = props.showMinute,\n showSecond = props.showSecond,\n use12Hours = props.use12Hours,\n _props$hourStep = props.hourStep,\n hourStep = _props$hourStep === void 0 ? 1 : _props$hourStep,\n _props$minuteStep = props.minuteStep,\n minuteStep = _props$minuteStep === void 0 ? 1 : _props$minuteStep,\n _props$secondStep = props.secondStep,\n secondStep = _props$secondStep === void 0 ? 1 : _props$secondStep,\n disabledHours = props.disabledHours,\n disabledMinutes = props.disabledMinutes,\n disabledSeconds = props.disabledSeconds,\n hideDisabledOptions = props.hideDisabledOptions,\n onSelect = props.onSelect;\n var columns = [];\n var contentPrefixCls = \"\".concat(prefixCls, \"-content\");\n var columnPrefixCls = \"\".concat(prefixCls, \"-time-panel\");\n var isPM;\n var originHour = value ? generateConfig.getHour(value) : -1;\n var hour = originHour;\n var minute = value ? generateConfig.getMinute(value) : -1;\n var second = value ? generateConfig.getSecond(value) : -1;\n\n var setTime = function setTime(isNewPM, newHour, newMinute, newSecond) {\n var newDate = value || generateConfig.getNow();\n var mergedHour = Math.max(0, newHour);\n var mergedMinute = Math.max(0, newMinute);\n var mergedSecond = Math.max(0, newSecond);\n newDate = utilSetTime(generateConfig, newDate, !use12Hours || !isNewPM ? mergedHour : mergedHour + 12, mergedMinute, mergedSecond);\n return newDate;\n }; // ========================= Unit =========================\n\n\n var rawHours = generateUnits(0, 23, hourStep, disabledHours && disabledHours());\n var memorizedRawHours = useMemo(function () {\n return rawHours;\n }, rawHours, shouldUnitsUpdate); // Should additional logic to handle 12 hours\n\n if (use12Hours) {\n isPM = hour >= 12; // -1 means should display AM\n\n hour %= 12;\n }\n\n var _React$useMemo = React.useMemo(function () {\n if (!use12Hours) {\n return [false, false];\n }\n\n var AMPMDisabled = [true, true];\n memorizedRawHours.forEach(function (_ref) {\n var disabled = _ref.disabled,\n hourValue = _ref.value;\n if (disabled) return;\n\n if (hourValue >= 12) {\n AMPMDisabled[1] = false;\n } else {\n AMPMDisabled[0] = false;\n }\n });\n return AMPMDisabled;\n }, [use12Hours, memorizedRawHours]),\n _React$useMemo2 = _slicedToArray(_React$useMemo, 2),\n AMDisabled = _React$useMemo2[0],\n PMDisabled = _React$useMemo2[1];\n\n var hours = React.useMemo(function () {\n if (!use12Hours) return memorizedRawHours;\n return memorizedRawHours.filter(isPM ? function (hourMeta) {\n return hourMeta.value >= 12;\n } : function (hourMeta) {\n return hourMeta.value < 12;\n }).map(function (hourMeta) {\n var hourValue = hourMeta.value % 12;\n var hourLabel = hourValue === 0 ? '12' : leftPad(hourValue, 2);\n return _objectSpread(_objectSpread({}, hourMeta), {}, {\n label: hourLabel,\n value: hourValue\n });\n });\n }, [use12Hours, memorizedRawHours]);\n var minutes = generateUnits(0, 59, minuteStep, disabledMinutes && disabledMinutes(originHour));\n var seconds = generateUnits(0, 59, secondStep, disabledSeconds && disabledSeconds(originHour, minute)); // ====================== Operations ======================\n\n operationRef.current = {\n onUpDown: function onUpDown(diff) {\n var column = columns[activeColumnIndex];\n\n if (column) {\n var valueIndex = column.units.findIndex(function (unit) {\n return unit.value === column.value;\n });\n var unitLen = column.units.length;\n\n for (var i = 1; i < unitLen; i += 1) {\n var nextUnit = column.units[(valueIndex + diff * i + unitLen) % unitLen];\n\n if (nextUnit.disabled !== true) {\n column.onSelect(nextUnit.value);\n break;\n }\n }\n }\n }\n }; // ======================== Render ========================\n\n function addColumnNode(condition, node, columnValue, units, onColumnSelect) {\n if (condition !== false) {\n columns.push({\n node: /*#__PURE__*/React.cloneElement(node, {\n prefixCls: columnPrefixCls,\n value: columnValue,\n active: activeColumnIndex === columns.length,\n onSelect: onColumnSelect,\n units: units,\n hideDisabledOptions: hideDisabledOptions\n }),\n onSelect: onColumnSelect,\n value: columnValue,\n units: units\n });\n }\n } // Hour\n\n\n addColumnNode(showHour, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"hour\"\n }), hour, hours, function (num) {\n onSelect(setTime(isPM, num, minute, second), 'mouse');\n }); // Minute\n\n addColumnNode(showMinute, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"minute\"\n }), minute, minutes, function (num) {\n onSelect(setTime(isPM, hour, num, second), 'mouse');\n }); // Second\n\n addColumnNode(showSecond, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"second\"\n }), second, seconds, function (num) {\n onSelect(setTime(isPM, hour, minute, num), 'mouse');\n }); // 12 Hours\n\n var PMIndex = -1;\n\n if (typeof isPM === 'boolean') {\n PMIndex = isPM ? 1 : 0;\n }\n\n addColumnNode(use12Hours === true, /*#__PURE__*/React.createElement(TimeUnitColumn, {\n key: \"12hours\"\n }), PMIndex, [{\n label: 'AM',\n value: 0,\n disabled: AMDisabled\n }, {\n label: 'PM',\n value: 1,\n disabled: PMDisabled\n }], function (num) {\n onSelect(setTime(!!num, hour, minute, second), 'mouse');\n });\n return /*#__PURE__*/React.createElement(\"div\", {\n className: contentPrefixCls\n }, columns.map(function (_ref2) {\n var node = _ref2.node;\n return node;\n }));\n}\n\nexport default TimeBody;"]},"metadata":{},"sourceType":"module"}