sard 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import { type CalendarProps } from './common';
2
2
  declare const __VLS_export: import("vue").DefineComponent<CalendarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
3
- change: (value: string | string[] | Date | Date[]) => any;
4
- "update:modelValue": (value: string | string[] | Date | Date[]) => any;
3
+ change: (value: string | Date | string[] | Date[]) => any;
4
+ "update:modelValue": (value: string | Date | string[] | Date[]) => any;
5
5
  }, string, import("vue").PublicProps, Readonly<CalendarProps> & Readonly<{
6
- onChange?: ((value: string | string[] | Date | Date[]) => any) | undefined;
7
- "onUpdate:modelValue"?: ((value: string | string[] | Date | Date[]) => any) | undefined;
6
+ onChange?: ((value: string | Date | string[] | Date[]) => any) | undefined;
7
+ "onUpdate:modelValue"?: ((value: string | Date | string[] | Date[]) => any) | undefined;
8
8
  }>, {
9
9
  min: Date;
10
10
  max: Date;
@@ -2,7 +2,7 @@ import { type CalendarType } from '../calendar/common';
2
2
  import { type CalendarInputProps, type CalendarInputSlots } from './common';
3
3
  type __VLS_Slots = CalendarInputSlots;
4
4
  declare const __VLS_base: import("vue").DefineComponent<CalendarInputProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
5
- change: (value: string | string[] | Date | Date[] | undefined) => any;
5
+ change: (value: string | Date | string[] | Date[] | undefined) => any;
6
6
  "before-enter": (el: Element) => any;
7
7
  enter: (el: Element) => any;
8
8
  "after-enter": (el: Element) => any;
@@ -13,10 +13,10 @@ declare const __VLS_base: import("vue").DefineComponent<CalendarInputProps, {},
13
13
  "leave-cancelled": (el: Element) => any;
14
14
  "visible-hook": (name: import("../index.ts").MotionHookName, el: Element) => any;
15
15
  "update:visible": (visible: boolean) => any;
16
- "update:modelValue": (value: string | string[] | Date | Date[] | undefined) => any;
17
- confirm: (value: string | string[] | Date | Date[] | undefined) => any;
16
+ "update:modelValue": (value: string | Date | string[] | Date[] | undefined) => any;
17
+ confirm: (value: string | Date | string[] | Date[] | undefined) => any;
18
18
  }, string, import("vue").PublicProps, Readonly<CalendarInputProps> & Readonly<{
19
- onChange?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
19
+ onChange?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
20
20
  "onBefore-enter"?: ((el: Element) => any) | undefined;
21
21
  onEnter?: ((el: Element) => any) | undefined;
22
22
  "onAfter-enter"?: ((el: Element) => any) | undefined;
@@ -27,8 +27,8 @@ declare const __VLS_base: import("vue").DefineComponent<CalendarInputProps, {},
27
27
  "onLeave-cancelled"?: ((el: Element) => any) | undefined;
28
28
  "onVisible-hook"?: ((name: import("../index.ts").MotionHookName, el: Element) => any) | undefined;
29
29
  "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
30
- "onUpdate:modelValue"?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
31
- onConfirm?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
30
+ "onUpdate:modelValue"?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
31
+ onConfirm?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
32
32
  }>, {
33
33
  title: string;
34
34
  min: Date;
@@ -1,5 +1,5 @@
1
- import { formatDate, parseDate } from "../../utils/date.js";
2
1
  import { isString } from "../../utils/is.js";
2
+ import { formatDate, parseDate } from "../../utils/date.js";
3
3
  import { useTranslateWithPrefix } from "../../locale/index.js";
4
4
  import popout_input_default from "../popout-input/popout-input.vue.js";
5
5
  import calendar_popout_default from "../calendar-popout/calendar-popout.vue.js";
@@ -1,7 +1,7 @@
1
1
  import { type CalendarPopoutProps, type CalendarPopoutSlots } from './common';
2
2
  type __VLS_Slots = CalendarPopoutSlots;
3
3
  declare const __VLS_base: import("vue").DefineComponent<CalendarPopoutProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
4
- change: (value: string | string[] | Date | Date[] | undefined) => any;
4
+ change: (value: string | Date | string[] | Date[] | undefined) => any;
5
5
  "before-enter": (el: Element) => any;
6
6
  enter: (el: Element) => any;
7
7
  "after-enter": (el: Element) => any;
@@ -12,10 +12,10 @@ declare const __VLS_base: import("vue").DefineComponent<CalendarPopoutProps, {},
12
12
  "leave-cancelled": (el: Element) => any;
13
13
  "visible-hook": (name: import("../index.ts").MotionHookName, el: Element) => any;
14
14
  "update:visible": (visible: boolean) => any;
15
- "update:modelValue": (value: string | string[] | Date | Date[] | undefined) => any;
16
- confirm: (value: string | string[] | Date | Date[] | undefined) => any;
15
+ "update:modelValue": (value: string | Date | string[] | Date[] | undefined) => any;
16
+ confirm: (value: string | Date | string[] | Date[] | undefined) => any;
17
17
  }, string, import("vue").PublicProps, Readonly<CalendarPopoutProps> & Readonly<{
18
- onChange?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
18
+ onChange?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
19
19
  "onBefore-enter"?: ((el: Element) => any) | undefined;
20
20
  onEnter?: ((el: Element) => any) | undefined;
21
21
  "onAfter-enter"?: ((el: Element) => any) | undefined;
@@ -26,8 +26,8 @@ declare const __VLS_base: import("vue").DefineComponent<CalendarPopoutProps, {},
26
26
  "onLeave-cancelled"?: ((el: Element) => any) | undefined;
27
27
  "onVisible-hook"?: ((name: import("../index.ts").MotionHookName, el: Element) => any) | undefined;
28
28
  "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
29
- "onUpdate:modelValue"?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
30
- onConfirm?: ((value: string | string[] | Date | Date[] | undefined) => any) | undefined;
29
+ "onUpdate:modelValue"?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
30
+ onConfirm?: ((value: string | Date | string[] | Date[] | undefined) => any) | undefined;
31
31
  }>, {
32
32
  title: string;
33
33
  min: Date;
@@ -1,11 +1,11 @@
1
1
  import { type DateStripProps } from './common';
2
2
  import { type CalendarDay } from '../calendar';
3
3
  declare const __VLS_export: import("vue").DefineComponent<DateStripProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
4
- change: (value: string | string[] | Date | Date[]) => any;
5
- "update:modelValue": (value: string | string[] | Date | Date[]) => any;
4
+ change: (value: string | Date | string[] | Date[]) => any;
5
+ "update:modelValue": (value: string | Date | string[] | Date[]) => any;
6
6
  }, string, import("vue").PublicProps, Readonly<DateStripProps> & Readonly<{
7
- onChange?: ((value: string | string[] | Date | Date[]) => any) | undefined;
8
- "onUpdate:modelValue"?: ((value: string | string[] | Date | Date[]) => any) | undefined;
7
+ onChange?: ((value: string | Date | string[] | Date[]) => any) | undefined;
8
+ "onUpdate:modelValue"?: ((value: string | Date | string[] | Date[]) => any) | undefined;
9
9
  }>, {
10
10
  filter: (date: Date) => boolean;
11
11
  min: Date;
@@ -1,6 +1,6 @@
1
+ import { isDate } from "../../utils/is.js";
1
2
  import { clamp } from "../../utils/number.js";
2
3
  import { formatDate, getDaysInMonth, getLunarDayName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, solarToLunar, toDate } from "../../utils/date.js";
3
- import { isDate } from "../../utils/is.js";
4
4
  //#region packages/sard/components/datetime-picker/common.ts
5
5
  const defaultDatetimePickerProps = {
6
6
  type: "yMd",
@@ -1,5 +1,5 @@
1
- import { formatDate, parseDate } from "../../utils/date.js";
2
1
  import { isString } from "../../utils/is.js";
2
+ import { formatDate, parseDate } from "../../utils/date.js";
3
3
  import popout_input_default from "../popout-input/popout-input.vue.js";
4
4
  import { partitionPopoutInputProps, usePopoutInput } from "../popout-input/usePopoutInput.js";
5
5
  import datetime_picker_popout_default from "../datetime-picker-popout/datetime-picker-popout.vue.js";
@@ -1,5 +1,5 @@
1
- import { formatDate, parseDate } from "../../utils/date.js";
2
1
  import { isString } from "../../utils/is.js";
2
+ import { formatDate, parseDate } from "../../utils/date.js";
3
3
  import { useTranslateWithPrefix } from "../../locale/index.js";
4
4
  import popout_input_default from "../popout-input/popout-input.vue.js";
5
5
  import { partitionPopoutInputProps, usePopoutInput } from "../popout-input/usePopoutInput.js";
@@ -1,6 +1,6 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
- import { clamp, formatNumber } from "../../utils/number.js";
3
2
  import { isNullish } from "../../utils/is.js";
3
+ import { clamp, formatNumber } from "../../utils/number.js";
4
4
  import { usePointerDown } from "../../use/usePointerDown.js";
5
5
  import { useSimulatedClick } from "../../use/useSimulatedClick.js";
6
6
  import { useComposition } from "../../use/useComposition.js";
@@ -1,6 +1,6 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
- import { clamp } from "../../utils/number.js";
3
2
  import { isNullish } from "../../utils/is.js";
3
+ import { clamp } from "../../utils/number.js";
4
4
  import { usePointerDown } from "../../use/usePointerDown.js";
5
5
  import { useSimulatedPress } from "../../use/useSimulatedPress.js";
6
6
  import { useFormContext } from "../form/common.js";
@@ -1,5 +1,5 @@
1
- import { clamp } from "../../utils/number.js";
2
1
  import { isNullish } from "../../utils/is.js";
2
+ import { clamp } from "../../utils/number.js";
3
3
  import { usePointerDown } from "../../use/usePointerDown.js";
4
4
  import { useInitialVelocity } from "../../use/useInitialVelocity.js";
5
5
  import { useResizeObserver } from "../../use/useResizeObserver.js";
@@ -1,6 +1,6 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
- import { chooseFile, isImageFile, isImageUrl } from "../../utils/file.js";
3
2
  import { isFunction } from "../../utils/is.js";
3
+ import { chooseFile, isImageFile, isImageUrl } from "../../utils/file.js";
4
4
  import { toArray } from "../../utils/array.js";
5
5
  import { useFormContext, useFormItemContext } from "../form/common.js";
6
6
  import { previewImage } from "../preview-image/imperative.js";
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createBem, createBemStruct, cssVar, cssVarName, defaultBemConfig } from "./utils/bem.js";
2
+ import { isBoolean, isConfigObject, isDate, isEmptyArray, isFunction, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from "./utils/is.js";
2
3
  import { clamp, compactNumber, formatNumber, formatThousands, getDecimalsLength, inRange, looseToNumber, mround, random, round, truncToFixed } from "./utils/number.js";
3
4
  import { baseLunarYear, earthlyBranches, formatDate, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getFirstDayWeekday, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getPrevMonthDate, getPrevMonthTailDays, heavenlyStems, isLeapYear, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, minmaxDate, parseDate, solarToLunar, springFestivals, toDate, toDateNumber, toDateString, toMonthNumber } from "./utils/date.js";
4
5
  import { checkRtl, getScrollTop, toTouchEvent } from "./utils/dom.js";
5
6
  import { chooseFile, getFileName, imageDataToDataURL, isFileUrl, isImageFile, isImageUrl, isVideoFile, isVideoUrl, loadImage, readFileContent } from "./utils/file.js";
6
- import { isBoolean, isConfigObject, isDate, isEmptyArray, isFunction, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from "./utils/is.js";
7
7
  import { addUnit, debounce, getPageRange, isEmptyBinding, isEmptyValue, isRenderVisible, isVisibleEmpty, noop, sleep, splitUnit, throttle } from "./utils/utils.js";
8
8
  import { ALPHANUMERIC_CHARS, ECLList, qrcode } from "./utils/qrcode.js";
9
9
  import { assignDeep, chainGet, chainSet, deepClone, extend, nestedToMulti, omit, partition, pick, treeToMap } from "./utils/object.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sard",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "sard 是基于 Vue3 的 Web 移动端 UI 组件库",
5
5
  "keywords": [
6
6
  "UI",
package/utils/date.d.ts CHANGED
@@ -49,12 +49,15 @@ export declare function getNextMonthHeadDays(year: number, month: number, weekSt
49
49
  /**
50
50
  * 根据传入的占位符返回格式化后的日期。
51
51
  */
52
- export declare function formatDate(date: Date, format?: string): string;
52
+ export declare function formatDate(date: Date | number | string, format?: string): string;
53
53
  /**
54
54
  * 解析日期的字符串表示形式,并返回 Date 实例对象。
55
55
  */
56
56
  export declare function parseDate(value: string, format?: string): Date;
57
- export declare function toDate(date: Date | string, valueFormat?: string): Date;
57
+ /**
58
+ * 确保返回一个Date对象,可以传递时间戳(10位或13位,字符串或数字),或者传递特定格式的字符串,则使用 parseDate 解析。
59
+ */
60
+ export declare function toDate(date: Date | string | number, valueFormat?: string): Date;
58
61
  export declare function minmaxDate(date: Date, minDate: Date, maxDate: Date): Date;
59
62
  export declare function getPrevMonthDate(date: Date): Date;
60
63
  export declare function getNextMonthDate(date: Date): Date;
package/utils/date.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isNumber } from "./is.js";
1
2
  import { clamp } from "./number.js";
2
3
  import { escapeRegExp } from "./regexp.js";
3
4
  //#region packages/sard/utils/date.ts
@@ -121,6 +122,7 @@ const dateGetters = {
121
122
  * 根据传入的占位符返回格式化后的日期。
122
123
  */
123
124
  function formatDate(date, format = "YYYY-MM-DD HH:mm:ss") {
125
+ date = toDate(date);
124
126
  return format.replace(dateTokensReg, (match) => {
125
127
  return dateGetters[match](date);
126
128
  });
@@ -175,8 +177,13 @@ function parseDate(value, format) {
175
177
  });
176
178
  return date;
177
179
  }
180
+ /**
181
+ * 确保返回一个Date对象,可以传递时间戳(10位或13位,字符串或数字),或者传递特定格式的字符串,则使用 parseDate 解析。
182
+ */
178
183
  function toDate(date, valueFormat) {
179
184
  if (date instanceof Date) return date;
185
+ if (isNumber(date)) return new Date(String(date).length === 10 ? date * 1e3 : date);
186
+ if ((date.length === 10 || date.length === 13) && /^\d+$/.test(date)) return /* @__PURE__ */ new Date(date.length === 10 ? +date * 1e3 : +date);
180
187
  return parseDate(date, valueFormat);
181
188
  }
182
189
  function minmaxDate(date, minDate, maxDate) {
package/utils/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createBem, createBemStruct, cssVar, cssVarName, defaultBemConfig } from "./bem.js";
2
+ import { isBoolean, isConfigObject, isDate, isEmptyArray, isFunction, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from "./is.js";
2
3
  import { clamp, compactNumber, formatNumber, formatThousands, getDecimalsLength, inRange, looseToNumber, mround, random, round, truncToFixed } from "./number.js";
3
4
  import { baseLunarYear, earthlyBranches, formatDate, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getFirstDayWeekday, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getPrevMonthDate, getPrevMonthTailDays, heavenlyStems, isLeapYear, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, minmaxDate, parseDate, solarToLunar, springFestivals, toDate, toDateNumber, toDateString, toMonthNumber } from "./date.js";
4
5
  import { checkRtl, getScrollTop, toTouchEvent } from "./dom.js";
5
6
  import { chooseFile, getFileName, imageDataToDataURL, isFileUrl, isImageFile, isImageUrl, isVideoFile, isVideoUrl, loadImage, readFileContent } from "./file.js";
6
- import { isBoolean, isConfigObject, isDate, isEmptyArray, isFunction, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from "./is.js";
7
7
  import { addUnit, debounce, getPageRange, isEmptyBinding, isEmptyValue, isRenderVisible, isVisibleEmpty, noop, sleep, splitUnit, throttle } from "./utils.js";
8
8
  import { ALPHANUMERIC_CHARS, ECLList, qrcode } from "./qrcode.js";
9
9
  import { assignDeep, chainGet, chainSet, deepClone, extend, nestedToMulti, omit, partition, pick, treeToMap } from "./object.js";