sard 1.0.6 → 1.0.7

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.
@@ -64,12 +64,24 @@ function getInitialValue(columns, optionKeys) {
64
64
  return option;
65
65
  }
66
66
  switch (getColumnsType(columns, optionKeys)) {
67
- case "single": return [getValue(columns[0]), [columns[0]]];
68
- case "multi": return [columns.map((column) => getValue(column[0])), columns.map((column) => column[0])];
67
+ case "single": return [
68
+ getValue(columns[0]),
69
+ [columns[0]],
70
+ [0]
71
+ ];
72
+ case "multi": return [
73
+ columns.map((column) => getValue(column[0])),
74
+ columns.map((column) => column[0]),
75
+ columns.map(() => 0)
76
+ ];
69
77
  case "cascader": {
70
78
  const options = [];
71
79
  recurse(columns, options);
72
- return [options.map((option) => getValue(option)), options];
80
+ return [
81
+ options.map((option) => getValue(option)),
82
+ options,
83
+ options.map(() => 0)
84
+ ];
73
85
  }
74
86
  }
75
87
  }
@@ -1,7 +1,7 @@
1
1
  import { type PickerInputProps, type PickerInputEmits, type PickerInputSlots } from './common';
2
2
  declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
3
3
  props: import("vue").PublicProps & __VLS_PrettifyLocal<PickerInputProps<T> & {
4
- onChange?: ((value: any) => any) | undefined;
4
+ onChange?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
5
5
  "onBefore-enter"?: ((el: Element) => any) | undefined;
6
6
  onEnter?: ((el: Element) => any) | undefined;
7
7
  "onAfter-enter"?: ((el: Element) => any) | undefined;
@@ -12,8 +12,8 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
12
12
  "onLeave-cancelled"?: ((el: Element) => any) | undefined;
13
13
  "onVisible-hook"?: ((name: import("../index.ts").MotionHookName, el: Element) => any) | undefined;
14
14
  "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
15
- "onUpdate:modelValue"?: ((value: any) => any) | undefined;
16
- onConfirm?: (() => any) | undefined;
15
+ "onUpdate:modelValue"?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
16
+ onConfirm?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
17
17
  }> & (typeof globalThis extends {
18
18
  __VLS_PROPS_FALLBACK: infer P;
19
19
  } ? P : {});
@@ -113,8 +113,8 @@ var picker_input_default = /*@__PURE__*/ defineComponent({
113
113
  watch([innerValue, () => props.columns], () => {
114
114
  inputValue.value = getInputValue();
115
115
  }, { immediate: true });
116
- const onConfirm = () => {
117
- emit("confirm");
116
+ const onConfirm = (...args) => {
117
+ emit("confirm", ...args);
118
118
  };
119
119
  return (_ctx, _cache) => {
120
120
  return openBlock(), createBlock(popout_input_default, mergeProps(unref(partitionedProps)[0], {
@@ -9,9 +9,9 @@ export interface PickerPopoutSlots<T> extends PickerSlots<T> {
9
9
  }
10
10
  export interface PickerPopoutEmits extends MotionEmits {
11
11
  (e: 'update:visible', visible: boolean): void;
12
- (e: 'update:modelValue', value: any): void;
13
- (e: 'change', value: any): void;
14
- (e: 'confirm'): void;
12
+ (e: 'update:modelValue', value: any, selectedOptions: any[], indexes: number[]): void;
13
+ (e: 'change', value: any, selectedOptions: any[], indexes: number[]): void;
14
+ (e: 'confirm', value: any, selectedOptions: any[], indexes: number[]): void;
15
15
  }
16
16
  export interface PickerPopoutExpose {
17
17
  }
@@ -1,7 +1,7 @@
1
1
  import { type PickerPopoutProps, type PickerPopoutSlots, type PickerPopoutEmits } from './common';
2
2
  declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
3
3
  props: import("vue").PublicProps & __VLS_PrettifyLocal<PickerPopoutProps<T> & {
4
- onChange?: ((value: any) => any) | undefined;
4
+ onChange?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
5
5
  "onBefore-enter"?: ((el: Element) => any) | undefined;
6
6
  onEnter?: ((el: Element) => any) | undefined;
7
7
  "onAfter-enter"?: ((el: Element) => any) | undefined;
@@ -12,8 +12,8 @@ declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_se
12
12
  "onLeave-cancelled"?: ((el: Element) => any) | undefined;
13
13
  "onVisible-hook"?: ((name: import("../index.ts").MotionHookName, el: Element) => any) | undefined;
14
14
  "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
15
- "onUpdate:modelValue"?: ((value: any) => any) | undefined;
16
- onConfirm?: (() => any) | undefined;
15
+ "onUpdate:modelValue"?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
16
+ onConfirm?: ((value: any, selectedOptions: any[], indexes: number[]) => any) | undefined;
17
17
  }> & (typeof globalThis extends {
18
18
  __VLS_PROPS_FALLBACK: infer P;
19
19
  } ? P : {});
@@ -65,11 +65,11 @@ var picker_popout_default = /*@__PURE__*/ defineComponent({
65
65
  const emit = __emit;
66
66
  const optionKeys = useOptionKeys(props);
67
67
  const omittedProps = omitFormPopoutProps(props);
68
- const { innerVisible, innerValue, draftValue, onChange, onConfirm, onVisibleHook } = useFormPopout(props, emit, { onConfirmBefore() {
69
- if (isEmptyBinding(draftValue.value) || isEmptyArray(draftValue.value)) {
70
- const [initialValue, selectedOptions] = getInitialValue(props.columns, optionKeys);
68
+ const { hasChange, innerVisible, innerValue, draftValue, onChange, onConfirm, onVisibleHook } = useFormPopout(props, emit, { onConfirmBefore() {
69
+ if (!hasChange.value || isEmptyBinding(draftValue.value) || isEmptyArray(draftValue.value)) {
70
+ const [initialValue, selectedOptions, indexes] = getInitialValue(props.columns, optionKeys);
71
71
  draftValue.value = initialValue;
72
- return [selectedOptions];
72
+ return [selectedOptions, indexes];
73
73
  }
74
74
  } });
75
75
  const onEnter = () => {
@@ -17,7 +17,7 @@ export interface UseFormPopoutEmits extends MotionEmits {
17
17
  (e: 'update:visible', visible: boolean): void;
18
18
  (e: 'update:modelValue', ...args: any[]): void;
19
19
  (e: 'change', ...args: any[]): void;
20
- (e: 'confirm'): void;
20
+ (e: 'confirm', ...args: any[]): void;
21
21
  }
22
22
  /**
23
23
  * 表单 Popout 组合式函数
@@ -34,6 +34,7 @@ export declare function useFormPopout(props: UseFormPopoutProps, emit: UseFormPo
34
34
  onChange?: (...args: any[]) => void;
35
35
  onConfirmBefore?: () => any;
36
36
  }): {
37
+ hasChange: import("vue").Ref<boolean, boolean>;
37
38
  innerVisible: import("vue").ModelRef<boolean | undefined, PropertyKey, boolean | undefined, boolean | undefined>;
38
39
  innerValue: import("vue").Ref<any, any>;
39
40
  draftValue: import("vue").Ref<any, any>;
@@ -35,18 +35,20 @@ function useFormPopout(props, emit, options = {}) {
35
35
  draftValue.value = innerValue.value;
36
36
  });
37
37
  let restArgs = [];
38
+ const hasChange = ref(false);
38
39
  const onChange = (value, ...args) => {
40
+ hasChange.value = true;
39
41
  draftValue.value = value;
40
42
  restArgs = args;
41
43
  options.onChange?.(value, ...args);
42
44
  };
43
45
  const onConfirm = (showConfirm = true) => {
44
- if (showConfirm) emit("confirm");
45
46
  const extraArgs = options.onConfirmBefore?.();
46
47
  if (extraArgs) restArgs = extraArgs;
48
+ const args = [draftValue.value, ...restArgs];
49
+ if (showConfirm) emit("confirm", ...args);
47
50
  if (draftValue.value !== innerValue.value) {
48
51
  innerValue.value = draftValue.value;
49
- const args = [innerValue.value, ...restArgs];
50
52
  emit("update:modelValue", ...args);
51
53
  emit("change", ...args);
52
54
  }
@@ -57,6 +59,7 @@ function useFormPopout(props, emit, options = {}) {
57
59
  emit(name, el);
58
60
  };
59
61
  return {
62
+ hasChange,
60
63
  innerVisible: visible,
61
64
  innerValue,
62
65
  draftValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sard",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "sard 是基于 Vue3 的 Web 移动端 UI 组件库",
5
5
  "keywords": [
6
6
  "UI",