UNPKG

@txdfe/at

Version:

一个设计体系组件库

129 lines (107 loc) 5.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.YEAR_TABLE_ROW_COUNT = exports.YEAR_TABLE_COL_COUNT = exports.MONTH_TABLE_ROW_COUNT = exports.MONTH_TABLE_COL_COUNT = exports.DAYS_OF_WEEK = exports.CALENDAR_TABLE_ROW_COUNT = exports.CALENDAR_TABLE_COL_COUNT = exports.CALENDAR_MODE_YEAR = exports.CALENDAR_MODE_MONTH = exports.CALENDAR_MODE_DATE = exports.CALENDAR_MODES = void 0; exports.checkMomentObj = checkMomentObj; exports.formatDateValue = formatDateValue; exports.getLocaleData = getLocaleData; exports.getVisibleMonth = getVisibleMonth; exports.isDisabledDate = isDisabledDate; exports.isSameYearMonth = isSameYearMonth; exports.preFormatDateValue = preFormatDateValue; var _moment = _interopRequireDefault(require("moment")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var DAYS_OF_WEEK = 7; exports.DAYS_OF_WEEK = DAYS_OF_WEEK; var CALENDAR_TABLE_COL_COUNT = 7; exports.CALENDAR_TABLE_COL_COUNT = CALENDAR_TABLE_COL_COUNT; var CALENDAR_TABLE_ROW_COUNT = 6; exports.CALENDAR_TABLE_ROW_COUNT = CALENDAR_TABLE_ROW_COUNT; var MONTH_TABLE_ROW_COUNT = 4; exports.MONTH_TABLE_ROW_COUNT = MONTH_TABLE_ROW_COUNT; var MONTH_TABLE_COL_COUNT = 3; exports.MONTH_TABLE_COL_COUNT = MONTH_TABLE_COL_COUNT; var YEAR_TABLE_ROW_COUNT = 4; exports.YEAR_TABLE_ROW_COUNT = YEAR_TABLE_ROW_COUNT; var YEAR_TABLE_COL_COUNT = 3; exports.YEAR_TABLE_COL_COUNT = YEAR_TABLE_COL_COUNT; var CALENDAR_MODE_YEAR = 'year'; exports.CALENDAR_MODE_YEAR = CALENDAR_MODE_YEAR; var CALENDAR_MODE_MONTH = 'month'; exports.CALENDAR_MODE_MONTH = CALENDAR_MODE_MONTH; var CALENDAR_MODE_DATE = 'date'; exports.CALENDAR_MODE_DATE = CALENDAR_MODE_DATE; var CALENDAR_MODES = [CALENDAR_MODE_DATE, CALENDAR_MODE_MONTH, CALENDAR_MODE_YEAR]; exports.CALENDAR_MODES = CALENDAR_MODES; function isDisabledDate(date, fn, view) { if (typeof fn === 'function' && fn(date, view)) { return true; } return false; } function checkMomentObj(props, propName, componentName) { if (props[propName] && !_moment["default"].isMoment(props[propName])) { return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Required a moment object")); } } function formatDateValue(value) { var reservedValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (value && _moment["default"].isMoment(value)) { return value; } return reservedValue; } function getVisibleMonth(defaultVisibleMonth, value) { var getVM = defaultVisibleMonth; if (typeof getVM !== 'function' || !_moment["default"].isMoment(getVM())) { getVM = function getVM() { if (value) { return value; } return (0, _moment["default"])(); }; } return getVM(); } function isSameYearMonth(dateA, dateB) { return dateA.month() === dateB.month() && dateA.year() === dateB.year(); } function preFormatDateValue(value, format) { var val = typeof value === 'string' ? (0, _moment["default"])(value, format, false) : value; if (val && _moment["default"].isMoment(val) && val.isValid()) { return val; } return null; } function getLocaleData(_ref, localeData) { var _months = _ref.months, shortMonths = _ref.shortMonths, _firstDayOfWeek = _ref.firstDayOfWeek, _weekdays = _ref.weekdays, shortWeekdays = _ref.shortWeekdays, veryShortWeekdays = _ref.veryShortWeekdays; return _objectSpread(_objectSpread({}, localeData), {}, { monthsShort: function monthsShort() { return shortMonths || localeData.monthsShort(); }, months: function months() { return _months || localeData.months(); }, firstDayOfWeek: function firstDayOfWeek() { return _firstDayOfWeek || localeData.firstDayOfWeek(); }, weekdays: function weekdays() { return _weekdays || localeData.weekdays; }, weekdaysShort: function weekdaysShort() { return shortWeekdays || localeData.weekdaysShort(); }, weekdaysMin: function weekdaysMin() { return veryShortWeekdays || localeData.weekdaysMin(); } }); }