@v-c/picker 0.0.3 → 0.0.5

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.
@@ -170,8 +170,10 @@ var RangePicker = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose }) =
170
170
  const enabledIndex = disabled.value.findIndex((d) => !d);
171
171
  if (enabledIndex >= 0) selectorRef.value?.focus({ index: enabledIndex });
172
172
  }
173
- triggerOpen(true);
174
- onClick.value?.(event);
173
+ (0, vue.nextTick)(() => {
174
+ triggerOpen(true);
175
+ onClick.value?.(event);
176
+ });
175
177
  };
176
178
  const onSelectorClear = () => {
177
179
  triggerSubmitChange(null);
@@ -15,7 +15,7 @@ import useRangeValue, { useInnerValue } from "./hooks/useRangeValue.js";
15
15
  import useShowNow from "./hooks/useShowNow.js";
16
16
  import Popup_default from "./Popup/index.js";
17
17
  import RangeSelector_default from "./Selector/RangeSelector.js";
18
- import { computed, createVNode, defineComponent, mergeProps, ref, shallowRef, watch } from "vue";
18
+ import { computed, createVNode, defineComponent, mergeProps, nextTick, ref, shallowRef, watch } from "vue";
19
19
  import { clsx } from "@v-c/util";
20
20
  import omit$1 from "@v-c/util/dist/omit";
21
21
  import pickAttrs from "@v-c/util/dist/pickAttrs";
@@ -162,8 +162,10 @@ var RangePicker_default = /* @__PURE__ */ defineComponent((props, { expose }) =>
162
162
  const enabledIndex = disabled.value.findIndex((d) => !d);
163
163
  if (enabledIndex >= 0) selectorRef.value?.focus({ index: enabledIndex });
164
164
  }
165
- triggerOpen(true);
166
- onClick.value?.(event);
165
+ nextTick(() => {
166
+ triggerOpen(true);
167
+ onClick.value?.(event);
168
+ });
167
169
  };
168
170
  const onSelectorClear = () => {
169
171
  triggerSubmitChange(null);
@@ -15,7 +15,9 @@ function useDelayState(value, defaultValue, onChange) {
15
15
  if (rafRef.value) _v_c_util_dist_raf.default.cancel(rafRef.value);
16
16
  };
17
17
  const doUpdate = () => {
18
- if (value.value === void 0) internalValue.value = nextValueRef.value;
18
+ if (value.value === void 0) (0, vue.nextTick)(() => {
19
+ internalValue.value = nextValueRef.value;
20
+ });
19
21
  if (onChange && state.value !== nextValueRef.value) onChange(nextValueRef.value);
20
22
  };
21
23
  const updateValue = (next, immediately) => {
@@ -1,4 +1,4 @@
1
- import { computed, onBeforeUnmount, ref, watch } from "vue";
1
+ import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
2
2
  import raf from "@v-c/util/dist/raf";
3
3
  function useDelayState(value, defaultValue, onChange) {
4
4
  const internalValue = ref(defaultValue);
@@ -9,7 +9,9 @@ function useDelayState(value, defaultValue, onChange) {
9
9
  if (rafRef.value) raf.cancel(rafRef.value);
10
10
  };
11
11
  const doUpdate = () => {
12
- if (value.value === void 0) internalValue.value = nextValueRef.value;
12
+ if (value.value === void 0) nextTick(() => {
13
+ internalValue.value = nextValueRef.value;
14
+ });
13
15
  if (onChange && state.value !== nextValueRef.value) onChange(nextValueRef.value);
14
16
  };
15
17
  const updateValue = (next, immediately) => {
@@ -17,7 +17,7 @@ var TimePanel = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
17
17
  }));
18
18
  return () => {
19
19
  const { prefixCls, value, locale, generateConfig, showTime } = props;
20
- const format = typeof showTime === "object" && showTime.format ? showTime.format : locale?.fieldTimeFormat || "HH:mm:ss";
20
+ const format = typeof showTime === "object" && showTime && showTime.format ? showTime.format : locale?.fieldTimeFormat || "HH:mm:ss";
21
21
  const panelPrefixCls = `${prefixCls}-time-panel`;
22
22
  return (0, vue.createVNode)("div", { "class": (0, _v_c_util.clsx)(panelPrefixCls) }, [(0, vue.createVNode)(require_PanelHeader.default, null, { default: () => [value ? require_dateUtil.formatValue(value, {
23
23
  locale,
@@ -12,7 +12,7 @@ var TimePanel_default = /* @__PURE__ */ defineComponent((props) => {
12
12
  }));
13
13
  return () => {
14
14
  const { prefixCls, value, locale, generateConfig, showTime } = props;
15
- const format = typeof showTime === "object" && showTime.format ? showTime.format : locale?.fieldTimeFormat || "HH:mm:ss";
15
+ const format = typeof showTime === "object" && showTime && showTime.format ? showTime.format : locale?.fieldTimeFormat || "HH:mm:ss";
16
16
  const panelPrefixCls = `${prefixCls}-time-panel`;
17
17
  return createVNode("div", { "class": clsx(panelPrefixCls) }, [createVNode(PanelHeader_default, null, { default: () => [value ? formatValue(value, {
18
18
  locale,
@@ -92,22 +92,23 @@ function useTimeInfo(generateConfig, props, date) {
92
92
  ];
93
93
  }
94
94
  function findValidateTime(nextTime, getHourUnits, getMinuteUnits, getSecondUnits, getMillisecondUnits, generateConfig) {
95
- const curHour = generateConfig.getHour(nextTime);
96
- const hourUnits = getHourUnits();
97
- const validHour = hourUnits.find((u) => u.value === curHour && !u.disabled)?.value ?? hourUnits.find((u) => !u.disabled)?.value ?? curHour;
98
- let ret = generateConfig.setHour(nextTime, validHour);
99
- const curMinute = generateConfig.getMinute(ret);
100
- const minuteUnits = getMinuteUnits(validHour);
101
- const validMinute = minuteUnits.find((u) => u.value === curMinute && !u.disabled)?.value ?? minuteUnits.find((u) => !u.disabled)?.value ?? curMinute;
102
- ret = generateConfig.setMinute(ret, validMinute);
103
- const curSecond = generateConfig.getSecond(ret);
104
- const secondUnits = getSecondUnits(validHour, validMinute);
105
- const validSecond = secondUnits.find((u) => u.value === curSecond && !u.disabled)?.value ?? secondUnits.find((u) => !u.disabled)?.value ?? curSecond;
106
- ret = generateConfig.setSecond(ret, validSecond);
107
- const curMs = generateConfig.getMillisecond(ret);
108
- const msUnits = getMillisecondUnits(validHour, validMinute, validSecond);
109
- const validMs = msUnits.find((u) => u.value === curMs && !u.disabled)?.value ?? msUnits.find((u) => !u.disabled)?.value ?? curMs;
110
- ret = generateConfig.setMillisecond(ret, validMs);
111
- return ret;
95
+ let nextDate = nextTime;
96
+ function alignValidate(getUnitValue, setUnitValue, units) {
97
+ let nextValue = Reflect.get(generateConfig, getUnitValue)(nextDate);
98
+ const nextUnit = units.find((unit) => unit.value === nextValue);
99
+ if (!nextUnit || nextUnit.disabled) {
100
+ const validateUnits = units.filter((unit) => !unit.disabled);
101
+ const validateUnit = [...validateUnits].reverse().find((unit) => unit.value <= nextValue) || validateUnits[0];
102
+ if (validateUnit) {
103
+ nextValue = validateUnit.value;
104
+ nextDate = Reflect.get(generateConfig, setUnitValue)(nextDate, nextValue);
105
+ }
106
+ }
107
+ return nextValue;
108
+ }
109
+ const nextHour = alignValidate("getHour", "setHour", getHourUnits());
110
+ const nextMinute = alignValidate("getMinute", "setMinute", getMinuteUnits(nextHour));
111
+ alignValidate("getMillisecond", "setMillisecond", getMillisecondUnits(nextHour, nextMinute, alignValidate("getSecond", "setSecond", getSecondUnits(nextHour, nextMinute))));
112
+ return nextDate;
112
113
  }
113
114
  exports.default = useTimeInfo;
@@ -87,22 +87,23 @@ function useTimeInfo(generateConfig, props, date) {
87
87
  ];
88
88
  }
89
89
  function findValidateTime(nextTime, getHourUnits, getMinuteUnits, getSecondUnits, getMillisecondUnits, generateConfig) {
90
- const curHour = generateConfig.getHour(nextTime);
91
- const hourUnits = getHourUnits();
92
- const validHour = hourUnits.find((u) => u.value === curHour && !u.disabled)?.value ?? hourUnits.find((u) => !u.disabled)?.value ?? curHour;
93
- let ret = generateConfig.setHour(nextTime, validHour);
94
- const curMinute = generateConfig.getMinute(ret);
95
- const minuteUnits = getMinuteUnits(validHour);
96
- const validMinute = minuteUnits.find((u) => u.value === curMinute && !u.disabled)?.value ?? minuteUnits.find((u) => !u.disabled)?.value ?? curMinute;
97
- ret = generateConfig.setMinute(ret, validMinute);
98
- const curSecond = generateConfig.getSecond(ret);
99
- const secondUnits = getSecondUnits(validHour, validMinute);
100
- const validSecond = secondUnits.find((u) => u.value === curSecond && !u.disabled)?.value ?? secondUnits.find((u) => !u.disabled)?.value ?? curSecond;
101
- ret = generateConfig.setSecond(ret, validSecond);
102
- const curMs = generateConfig.getMillisecond(ret);
103
- const msUnits = getMillisecondUnits(validHour, validMinute, validSecond);
104
- const validMs = msUnits.find((u) => u.value === curMs && !u.disabled)?.value ?? msUnits.find((u) => !u.disabled)?.value ?? curMs;
105
- ret = generateConfig.setMillisecond(ret, validMs);
106
- return ret;
90
+ let nextDate = nextTime;
91
+ function alignValidate(getUnitValue, setUnitValue, units) {
92
+ let nextValue = Reflect.get(generateConfig, getUnitValue)(nextDate);
93
+ const nextUnit = units.find((unit) => unit.value === nextValue);
94
+ if (!nextUnit || nextUnit.disabled) {
95
+ const validateUnits = units.filter((unit) => !unit.disabled);
96
+ const validateUnit = [...validateUnits].reverse().find((unit) => unit.value <= nextValue) || validateUnits[0];
97
+ if (validateUnit) {
98
+ nextValue = validateUnit.value;
99
+ nextDate = Reflect.get(generateConfig, setUnitValue)(nextDate, nextValue);
100
+ }
101
+ }
102
+ return nextValue;
103
+ }
104
+ const nextHour = alignValidate("getHour", "setHour", getHourUnits());
105
+ const nextMinute = alignValidate("getMinute", "setMinute", getMinuteUnits(nextHour));
106
+ alignValidate("getMillisecond", "setMillisecond", getMillisecondUnits(nextHour, nextMinute, alignValidate("getSecond", "setSecond", getSecondUnits(nextHour, nextMinute))));
107
+ return nextDate;
107
108
  }
108
109
  export { useTimeInfo as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/picker",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "description": "picker ui component for vue",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@v-c/overflow": "^1.0.1",
76
- "@v-c/util": "^1.0.6",
76
+ "@v-c/util": "^1.0.7",
77
77
  "@v-c/trigger": "^1.0.2"
78
78
  },
79
79
  "devDependencies": {