UNPKG

winbox-ui-next

Version:

We Design Vue 2.0: A Vue.js 3 UI Library

128 lines (127 loc) 4.19 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import originDayjs from "dayjs"; import customParseFormat from "dayjs/plugin/customParseFormat"; import isBetween from "dayjs/plugin/isBetween"; import weekOfYear from "dayjs/plugin/weekOfYear"; import AdvancedFormat from "dayjs/plugin/advancedFormat"; import weekYear from "dayjs/plugin/weekYear"; import QuarterOfYear from "dayjs/plugin/quarterOfYear"; import { isDayjs, isArray } from "./is.js"; import "dayjs/locale/zh-cn"; const overwriteIsDayjs = (_, Dayjs2, dayjs2) => { dayjs2 = function(date, c) { if (isDayjs(date)) { return date.clone(); } const cfg = typeof c === "object" ? c : {}; cfg.date = date; cfg.args = arguments; return new Dayjs2(cfg); }; const proto = Dayjs2.prototype; const old$Utils = proto.$utils; proto.$utils = () => { const newUtils = old$Utils(); newUtils.i = isDayjs; return newUtils; }; dayjs2.isDayjs = isDayjs; }; originDayjs.extend(overwriteIsDayjs); originDayjs.extend(customParseFormat); originDayjs.extend(isBetween); originDayjs.extend(weekOfYear); originDayjs.extend(AdvancedFormat); originDayjs.extend(weekYear); originDayjs.extend(QuarterOfYear); const dayjs = originDayjs; const methods = { add(time, value, unit) { return time.add(value, unit); }, subtract(time, value, unit) { return time.subtract(value, unit); }, startOf(time, unit) { return time.startOf(unit); }, endOf(time, unit) { return time.endOf(unit); }, set(time, unit, value) { return time.set(unit, value); }, isSameWeek(date1, date2, weekStart, localeName) { return date1.locale(__spreadProps(__spreadValues({}, dayjs.Ls[localeName]), { weekStart })).isSame(date2, "week"); } }; function getNow() { return dayjs(); } function getSortedDayjsArray(values) { return [...values].sort((a, b) => a.valueOf() - b.valueOf()); } function isValueChange(prevValue, currentValue) { const isDifference = (value1, value2) => { if (value1 === void 0 && value2 === void 0) { return false; } if (value1 && !value2 || !value1 && value2) { return true; } return (value1 == null ? void 0 : value1.valueOf()) !== (value2 == null ? void 0 : value2.valueOf()); }; if (currentValue === void 0 && prevValue === void 0) { return false; } if (isArray(currentValue) && isArray(prevValue)) { return isDifference(currentValue[0], prevValue[0]) || isDifference(currentValue[1], prevValue[1]); } if (!isArray(currentValue) && !isArray(prevValue)) { return isDifference(currentValue, prevValue); } return true; } function getDayjsValue(time, format) { const formatValue = (value) => { if (!value) return void 0; if (typeof value === "string") { return dayjs(value, format); } return dayjs(value); }; if (isArray(time)) { return time.map(formatValue); } return formatValue(time); } function getDateValue(value) { const formatValue = (t) => t ? t.toDate() : void 0; if (isArray(value)) { return value.map(formatValue); } return formatValue(value); } function initializeDateLocale(localeName, weekStart) { dayjs.locale(__spreadProps(__spreadValues({}, dayjs.Ls[localeName.toLocaleLowerCase()]), { weekStart })); } export { dayjs, getDateValue, getDayjsValue, getNow, getSortedDayjsArray, initializeDateLocale, isValueChange, methods };