amis-rpc-design/node_modules/rc-picker/lib/panels/DatePanel/index.js

104 lines
4.9 KiB
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _classnames = _interopRequireDefault(require("classnames"));
var React = _interopRequireWildcard(require("react"));
var _dateUtil = require("../../utils/dateUtil");
var _uiUtil = require("../../utils/uiUtil");
var _DateBody = _interopRequireDefault(require("./DateBody"));
var _DateHeader = _interopRequireDefault(require("./DateHeader"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var DATE_ROW_COUNT = 6;
function DatePanel(props) {
var prefixCls = props.prefixCls,
_props$panelName = props.panelName,
panelName = _props$panelName === void 0 ? 'date' : _props$panelName,
keyboardConfig = props.keyboardConfig,
active = props.active,
operationRef = props.operationRef,
generateConfig = props.generateConfig,
value = props.value,
viewDate = props.viewDate,
onViewDateChange = props.onViewDateChange,
onPanelChange = props.onPanelChange,
_onSelect = props.onSelect;
var panelPrefixCls = "".concat(prefixCls, "-").concat(panelName, "-panel");
// ======================= Keyboard =======================
operationRef.current = {
onKeyDown: function onKeyDown(event) {
return (0, _uiUtil.createKeyDownHandler)(event, (0, _objectSpread2.default)({
onLeftRight: function onLeftRight(diff) {
_onSelect(generateConfig.addDate(value || viewDate, diff), 'key');
},
onCtrlLeftRight: function onCtrlLeftRight(diff) {
_onSelect(generateConfig.addYear(value || viewDate, diff), 'key');
},
onUpDown: function onUpDown(diff) {
_onSelect(generateConfig.addDate(value || viewDate, diff * _dateUtil.WEEK_DAY_COUNT), 'key');
},
onPageUpDown: function onPageUpDown(diff) {
_onSelect(generateConfig.addMonth(value || viewDate, diff), 'key');
}
}, keyboardConfig));
}
};
// ==================== View Operation ====================
var onYearChange = function onYearChange(diff) {
var newDate = generateConfig.addYear(viewDate, diff);
onViewDateChange(newDate);
onPanelChange(null, newDate);
};
var onMonthChange = function onMonthChange(diff) {
var newDate = generateConfig.addMonth(viewDate, diff);
onViewDateChange(newDate);
onPanelChange(null, newDate);
};
return /*#__PURE__*/React.createElement("div", {
className: (0, _classnames.default)(panelPrefixCls, (0, _defineProperty2.default)({}, "".concat(panelPrefixCls, "-active"), active))
}, /*#__PURE__*/React.createElement(_DateHeader.default, (0, _extends2.default)({}, props, {
prefixCls: prefixCls,
value: value,
viewDate: viewDate
// View Operation
,
onPrevYear: function onPrevYear() {
onYearChange(-1);
},
onNextYear: function onNextYear() {
onYearChange(1);
},
onPrevMonth: function onPrevMonth() {
onMonthChange(-1);
},
onNextMonth: function onNextMonth() {
onMonthChange(1);
},
onMonthClick: function onMonthClick() {
onPanelChange('month', viewDate);
},
onYearClick: function onYearClick() {
onPanelChange('year', viewDate);
}
})), /*#__PURE__*/React.createElement(_DateBody.default, (0, _extends2.default)({}, props, {
onSelect: function onSelect(date) {
return _onSelect(date, 'mouse');
},
prefixCls: prefixCls,
value: value,
viewDate: viewDate,
rowCount: DATE_ROW_COUNT
})));
}
var _default = DatePanel;
exports.default = _default;