sard 1.0.4 → 1.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.
@@ -78,11 +78,11 @@ var cascader_default = /*@__PURE__*/ defineComponent({
78
78
  const emit = __emit;
79
79
  const bem = createBem("cascader");
80
80
  const { t } = useTranslateWithPrefix("cascader");
81
- const useOptionKeysReturn = useOptionKeys(props);
81
+ const optionKeys = useOptionKeys(props);
82
82
  const innerValue = ref();
83
83
  const { treeData, originalTreeData, loadStatus, toStateNodes, setSelectedByNode, updateChecked, setCheckedByNode, isLeaf, getCheckedLeaves, getCheckedNodes, getAncestors, initialize } = useCascaderTree(props, {
84
84
  innerValue,
85
- useOptionKeysReturn
85
+ optionKeys
86
86
  });
87
87
  initialize();
88
88
  const { panels, currentTab, tabsOptions } = useCascaderTabs(props, { treeData });
@@ -54,7 +54,7 @@ export interface CascaderPanel {
54
54
  nodes: CascaderStateNode[];
55
55
  selected: CascaderStateNode | null;
56
56
  }
57
- export declare function getSelectedOptionsByValue(options: CascaderOption[], value: CascaderValue, useOptionKeysReturn: UseOptionKeysReturn, multiple?: boolean): CascaderOption[] | CascaderOption[][] | undefined;
57
+ export declare function getSelectedOptionsByValue(options: CascaderOption[], value: CascaderValue, optionKeys: UseOptionKeysReturn, multiple?: boolean): CascaderOption[] | CascaderOption[][] | undefined;
58
58
  interface CascaderOptionsContext {
59
59
  set: (options: CascaderOption[]) => void;
60
60
  }
@@ -1,10 +1,10 @@
1
1
  import { isNullish } from "../../utils/is.js";
2
2
  //#region packages/sard/components/cascader/common.ts
3
3
  const defaultCascaderProps = { options: () => [] };
4
- function getSelectedOptionsByValue(options, value, useOptionKeysReturn, multiple) {
5
- const { getValue, getChildren } = useOptionKeysReturn;
4
+ function getSelectedOptionsByValue(options, value, optionKeys, multiple) {
5
+ const { getValue, getChildren } = optionKeys;
6
6
  if (multiple) {
7
- if (Array.isArray(value)) return value.map((item) => getSelectedOptionsByValue(options, item, useOptionKeysReturn)).filter((item) => Array.isArray(item) ? item.length !== 0 : !isNullish(item));
7
+ if (Array.isArray(value)) return value.map((item) => getSelectedOptionsByValue(options, item, optionKeys)).filter((item) => Array.isArray(item) ? item.length !== 0 : !isNullish(item));
8
8
  } else if (Array.isArray(value)) {
9
9
  const selectedOptions = [];
10
10
  let list = options;
@@ -18,7 +18,7 @@ function getSelectedOptionsByValue(options, value, useOptionKeysReturn, multiple
18
18
  return selectedOptions;
19
19
  } else for (const option of options) {
20
20
  if (Array.isArray(getChildren(option))) {
21
- const selectedOptions = getSelectedOptionsByValue(getChildren(option), value, useOptionKeysReturn, multiple);
21
+ const selectedOptions = getSelectedOptionsByValue(getChildren(option), value, optionKeys, multiple);
22
22
  if (selectedOptions) return [option, ...selectedOptions];
23
23
  }
24
24
  if (getValue(option) === value) return [option];
@@ -2,7 +2,7 @@ import { type Ref } from 'vue';
2
2
  import { type CascaderValue, type CascaderOption, type CascaderProps, type CascaderStateNode } from './common';
3
3
  import { type UseOptionKeysReturn } from '../../use';
4
4
  export declare function useCascaderTree(props: CascaderProps, config: {
5
- useOptionKeysReturn: UseOptionKeysReturn;
5
+ optionKeys: UseOptionKeysReturn;
6
6
  innerValue: Ref<CascaderValue | undefined>;
7
7
  }): {
8
8
  treeData: Ref<{
@@ -4,7 +4,7 @@ import { cascaderOptionsContextKey } from "./common.js";
4
4
  import { computed, inject, reactive, ref, shallowRef, watch } from "vue";
5
5
  //#region packages/sard/components/cascader/useCascaderTree.ts
6
6
  function useCascaderTree(props, config) {
7
- const { useOptionKeysReturn: { getValue, getLabel, getDisabled, getIsLeaf, getChildren }, innerValue } = config;
7
+ const { optionKeys: { getValue, getLabel, getDisabled, getIsLeaf, getChildren }, innerValue } = config;
8
8
  const options = computed(() => props.options || []);
9
9
  const treeData = ref([]);
10
10
  const originalTreeData = shallowRef([]);
@@ -140,13 +140,13 @@ var cascader_input_default = /*@__PURE__*/ defineComponent({
140
140
  const props = __props;
141
141
  const slots = useSlots();
142
142
  const emit = __emit;
143
- const useOptionKeysReturn = useOptionKeys(props);
143
+ const optionKeys = useOptionKeys(props);
144
144
  const partitionedProps = partitionPopoutInputProps(props);
145
145
  const { innerVisible, innerValue, inputValue, show, onChange, onClear, onVisibleHook } = usePopoutInput(props, emit, { onClear(value) {
146
146
  emit("update:modelValue", value, []);
147
147
  emit("change", value, []);
148
148
  } });
149
- const { getLabel } = useOptionKeysReturn;
149
+ const { getLabel } = optionKeys;
150
150
  const lazyOptions = shallowRef([]);
151
151
  provide(cascaderOptionsContextKey, { set(options) {
152
152
  lazyOptions.value = options;
@@ -155,7 +155,7 @@ var cascader_input_default = /*@__PURE__*/ defineComponent({
155
155
  return props.lazy && !!props.load ? lazyOptions.value : props.options;
156
156
  });
157
157
  function getOutletText(options, value) {
158
- const selectedOptions = getSelectedOptionsByValue(options, value, useOptionKeysReturn, props.multiple);
158
+ const selectedOptions = getSelectedOptionsByValue(options, value, optionKeys, props.multiple);
159
159
  if (!selectedOptions || selectedOptions.length === 0) return getValueDisplay(value);
160
160
  const labels = selectedOptions.map((option) => {
161
161
  return Array.isArray(option) ? option.map((item) => getLabel(item)) : getLabel(option);
@@ -1 +1 @@
1
- :root{--s-divider-margin-y:var(--s-size);--s-divider-margin-x:var(--s-size-xs);--s-divider-gap:var(--s-size);--s-divider-color:var(--s-text-color-tertiary);--s-divider-border-color:var(--s-border-color);--s-divider-left-width:10%;--s-divider-right-width:10%;--s-divider-vertical-height:1em}.s-divider{display:flex;align-items:center;margin:var(--s-divider-margin-y) 0;gap:var(--s-divider-gap);border-width:0;border-color:var(--s-divider-border-color);color:var(--s-divider-color)}.s-divider::before,.s-divider::after{display:block;flex:1;border-color:inherit;border-style:inherit;border-width:1px 0 0;content:""}.s-divider--only-line::after{display:none}.s-divider--left::before{max-width:var(--s-divider-left-width)}.s-divider--right::after{max-width:var(--s-divider-right-width)}.s-divider--vertical{display:inline-block;height:var(--s-divider-vertical-height);margin:0 var(--s-divider-margin-x);vertical-align:middle}.s-divider--vertical::before{height:100%;border-width:0 0 0 1px}.s-divider--vertical::after{display:none}.s-divider--hairline::before,.s-divider--hairline::after{transform:scaleY(0.5)}.s-divider--vertical.s-divider--hairline::before{transform:scaleX(0.5)}
1
+ :root{--s-divider-margin-y:var(--s-size);--s-divider-margin-x:var(--s-size-xs);--s-divider-gap:var(--s-size);--s-divider-color:var(--s-text-color-fourth);--s-divider-font-size:var(--s-font-size-sm);--s-divider-border-color:var(--s-border-color);--s-divider-left-width:10%;--s-divider-right-width:10%;--s-divider-vertical-height:1em}.s-divider{display:flex;align-items:center;margin:var(--s-divider-margin-y) 0;gap:var(--s-divider-gap);border-width:0;border-color:var(--s-divider-border-color);color:var(--s-divider-color);font-size:var(--s-divider-font-size)}.s-divider::before,.s-divider::after{display:block;flex:1;border-color:inherit;border-style:inherit;border-width:1px 0 0;content:""}.s-divider--only-line::after{display:none}.s-divider--left::before{max-width:var(--s-divider-left-width)}.s-divider--right::after{max-width:var(--s-divider-right-width)}.s-divider--vertical{display:inline-block;height:var(--s-divider-vertical-height);margin:0 var(--s-divider-margin-x);vertical-align:middle}.s-divider--vertical::before{height:100%;border-width:0 0 0 1px}.s-divider--vertical::after{display:none}.s-divider--hairline::before,.s-divider--hairline::after{transform:scaleY(0.5)}.s-divider--vertical.s-divider--hairline::before{transform:scaleX(0.5)}
@@ -18,8 +18,8 @@ export interface PickerEmits<T> {
18
18
  (e: 'change', value: any, selectedOptions: T[], indexes: number[]): void;
19
19
  }
20
20
  export declare function getColumnsType<T>(columns: T[] | T[][], { getChildren }: UseOptionKeysReturn): "single" | "multi" | "cascader";
21
- export declare function getOptionsByIndexes<T>(indexes: number[], columns: T[] | T[][], useOptionKeysReturn: UseOptionKeysReturn): T[];
21
+ export declare function getOptionsByIndexes<T>(indexes: number[], columns: T[] | T[][], optionKeys: UseOptionKeysReturn): T[];
22
22
  export declare function getCascaderValidIndexes<T>(indexes: number[], columns: T[] | T[][], { getChildren }: UseOptionKeysReturn): number[];
23
- export declare function getMaySingleValueByOptions<T>(options: T[], useOptionKeysReturn: UseOptionKeysReturn, columns: T[] | T[][]): any;
24
- export declare function getIndexesByValue<T>(value: any[], columns: T[] | T[][], useOptionKeysReturn: UseOptionKeysReturn): number[];
25
- export declare function getInitialValue<T>(columns: T[] | T[][], useOptionKeysReturn: UseOptionKeysReturn): any[];
23
+ export declare function getMaySingleValueByOptions<T>(options: T[], optionKeys: UseOptionKeysReturn, columns: T[] | T[][]): any;
24
+ export declare function getIndexesByValue<T>(value: any[], columns: T[] | T[][], optionKeys: UseOptionKeysReturn): number[];
25
+ export declare function getInitialValue<T>(columns: T[] | T[][], optionKeys: UseOptionKeysReturn): any[];
@@ -6,15 +6,15 @@ function getColumnsType(columns, { getChildren }) {
6
6
  if (firstColumn && typeof firstColumn === "object" && Array.isArray(getChildren(firstColumn))) return "cascader";
7
7
  return "single";
8
8
  }
9
- function getOptionsByIndexes(indexes, columns, useOptionKeysReturn) {
10
- const { getChildren } = useOptionKeysReturn;
9
+ function getOptionsByIndexes(indexes, columns, optionKeys) {
10
+ const { getChildren } = optionKeys;
11
11
  function recurse(columns, i = 0) {
12
12
  const option = columns[Math.min(indexes[i], columns.length - 1)];
13
13
  const nextColumn = getChildren(option);
14
14
  if (Array.isArray(nextColumn)) return [option, ...recurse(nextColumn, ++i)];
15
15
  return [option];
16
16
  }
17
- switch (getColumnsType(columns, useOptionKeysReturn)) {
17
+ switch (getColumnsType(columns, optionKeys)) {
18
18
  case "single": return [columns[indexes[0]]];
19
19
  case "multi": return columns.map((column, i) => column[indexes[i]]);
20
20
  case "cascader": return recurse(columns);
@@ -31,14 +31,14 @@ function getCascaderValidIndexes(indexes, columns, { getChildren }) {
31
31
  }
32
32
  return recurse(columns);
33
33
  }
34
- function getMaySingleValueByOptions(options, useOptionKeysReturn, columns) {
35
- const { getValue } = useOptionKeysReturn;
34
+ function getMaySingleValueByOptions(options, optionKeys, columns) {
35
+ const { getValue } = optionKeys;
36
36
  const values = options.map((option) => getValue(option));
37
- return getColumnsType(columns, useOptionKeysReturn) === "single" ? values[0] : values;
37
+ return getColumnsType(columns, optionKeys) === "single" ? values[0] : values;
38
38
  }
39
- function getIndexesByValue(value, columns, useOptionKeysReturn) {
40
- const { getValue, getChildren } = useOptionKeysReturn;
41
- const type = getColumnsType(columns, useOptionKeysReturn);
39
+ function getIndexesByValue(value, columns, optionKeys) {
40
+ const { getValue, getChildren } = optionKeys;
41
+ const type = getColumnsType(columns, optionKeys);
42
42
  function recurse(columns, i = 0) {
43
43
  let index = columns.findIndex((option) => getValue(option) === value[i]);
44
44
  if (index === -1) index = 0;
@@ -54,8 +54,8 @@ function getIndexesByValue(value, columns, useOptionKeysReturn) {
54
54
  return Math.max(optionIndex, 0);
55
55
  });
56
56
  }
57
- function getInitialValue(columns, useOptionKeysReturn) {
58
- const { getChildren, getValue } = useOptionKeysReturn;
57
+ function getInitialValue(columns, optionKeys) {
58
+ const { getChildren, getValue } = optionKeys;
59
59
  function recurse(columns, options) {
60
60
  const option = columns[0];
61
61
  options.push(option);
@@ -63,7 +63,7 @@ function getInitialValue(columns, useOptionKeysReturn) {
63
63
  if (Array.isArray(nextColumn) && nextColumn.length > 0) return recurse(nextColumn, options);
64
64
  return option;
65
65
  }
66
- switch (getColumnsType(columns, useOptionKeysReturn)) {
66
+ switch (getColumnsType(columns, optionKeys)) {
67
67
  case "single": return [getValue(columns[0]), [columns[0]]];
68
68
  case "multi": return [columns.map((column) => getValue(column[0])), columns.map((column) => column[0])];
69
69
  case "cascader": {
@@ -1,13 +1,11 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
- import { isEmptyArray } from "../../utils/is.js";
3
- import { isEmptyBinding } from "../../utils/utils.js";
4
2
  import { nestedToMulti } from "../../utils/object.js";
5
3
  import { arrayEqual, toArray } from "../../utils/array.js";
6
4
  import { useOptionKeys } from "../../use/useOptionKeys.js";
7
5
  import { defaultPickerProps, getCascaderValidIndexes, getColumnsType, getIndexesByValue, getMaySingleValueByOptions, getOptionsByIndexes } from "./common.js";
8
6
  import picker_view_default from "../picker-view/picker-view.js";
9
7
  import picker_view_column_default from "../picker-view/picker-view-column.js";
10
- import { Fragment, computed, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeDefaults, nextTick, normalizeClass, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useSlots, watch, withCtx } from "vue";
8
+ import { Fragment, computed, createBlock, createElementBlock, createTextVNode, createVNode, defineComponent, mergeDefaults, normalizeClass, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useSlots, watch, withCtx } from "vue";
11
9
  //#region packages/sard/components/picker/picker.vue
12
10
  var picker_default = /*@__PURE__*/ defineComponent({
13
11
  __name: "picker",
@@ -31,37 +29,34 @@ var picker_default = /*@__PURE__*/ defineComponent({
31
29
  useSlots();
32
30
  const emit = __emit;
33
31
  const bem = createBem("picker");
34
- const useOptionKeysReturn = useOptionKeys(props);
35
- const { aliasProps, getLabel } = useOptionKeysReturn;
36
- const columnsType = computed(() => {
37
- return getColumnsType(props.columns, useOptionKeysReturn);
38
- });
32
+ const optionKeys = useOptionKeys(props);
39
33
  const innerValue = ref(props.modelValue);
40
34
  watch(() => props.modelValue, () => {
41
35
  innerValue.value = props.modelValue;
42
36
  });
37
+ const columnsType = computed(() => {
38
+ return getColumnsType(props.columns, optionKeys);
39
+ });
43
40
  const columnIndexes = ref([]);
44
- const updateColumnIndexes = () => {
45
- const indexes = getIndexesByValue(toArray(innerValue.value), props.columns, useOptionKeysReturn);
46
- if (!arrayEqual(indexes, columnIndexes.value)) columnIndexes.value = indexes;
47
- };
48
- updateColumnIndexes();
49
41
  watch([
50
42
  innerValue,
51
43
  () => props.columns,
52
- aliasProps
44
+ optionKeys.aliasProps
53
45
  ], () => {
54
- if (!isEmptyBinding(innerValue.value) && !isEmptyArray(innerValue.value)) updateColumnIndexes();
46
+ const indexes = getIndexesByValue(toArray(innerValue.value), props.columns, optionKeys);
47
+ if (!arrayEqual(indexes, columnIndexes.value)) columnIndexes.value = indexes;
48
+ }, { immediate: true });
49
+ const renderedColumns = computed(() => {
50
+ switch (columnsType.value) {
51
+ case "single": return [props.columns];
52
+ case "multi": return props.columns;
53
+ case "cascader": return nestedToMulti(props.columns, toArray(innerValue.value), optionKeys);
54
+ default: return [];
55
+ }
55
56
  });
56
57
  const onChange = (value) => {
57
58
  if (!props.columns || props.columns.length === 0) return;
58
59
  let indexes = value;
59
- if (indexes.some((index) => index === Infinity)) {
60
- nextTick(() => {
61
- columnIndexes.value = isEmptyBinding(innerValue.value) || isEmptyArray(innerValue.value) ? columnIndexes.value.map(() => 0) : [...columnIndexes.value];
62
- });
63
- return;
64
- }
65
60
  indexes = renderedColumns.value.map((_, index) => indexes[index] || 0);
66
61
  if (columnsType.value === "cascader") {
67
62
  let startIndex = -1;
@@ -72,42 +67,22 @@ var picker_default = /*@__PURE__*/ defineComponent({
72
67
  }
73
68
  indexes = nextIndexes;
74
69
  {
75
- const validIndexes = getCascaderValidIndexes(indexes, props.columns, useOptionKeysReturn);
70
+ const validIndexes = getCascaderValidIndexes(indexes, props.columns, optionKeys);
76
71
  if (!arrayEqual(indexes, validIndexes)) indexes = validIndexes;
77
72
  }
78
73
  }
79
- const selectedOptions = getOptionsByIndexes(indexes, props.columns, useOptionKeysReturn);
74
+ const selectedOptions = getOptionsByIndexes(indexes, props.columns, optionKeys);
80
75
  if (!arrayEqual(indexes, columnIndexes.value)) columnIndexes.value = indexes;
81
- const nextValue = getMaySingleValueByOptions(selectedOptions, useOptionKeysReturn, props.columns);
76
+ const nextValue = getMaySingleValueByOptions(selectedOptions, optionKeys, props.columns);
82
77
  innerValue.value = nextValue;
83
78
  emit("update:modelValue", nextValue, selectedOptions, indexes);
84
79
  emit("change", nextValue, selectedOptions, indexes);
85
80
  };
86
- const getRenderedColumns = () => {
87
- switch (columnsType.value) {
88
- case "single": return [props.columns];
89
- case "multi": return props.columns;
90
- case "cascader": return nestedToMulti(props.columns, toArray(innerValue.value), useOptionKeysReturn);
91
- default: return [];
92
- }
93
- };
94
- const renderedColumns = ref(getRenderedColumns());
95
- const updateRenderedColumns = () => {
96
- renderedColumns.value = getRenderedColumns();
97
- };
98
- watch([() => props.columns, innerValue], ([newColumns, newValue], [oldColumns, oldValue]) => {
99
- if (newColumns !== oldColumns || newValue !== oldValue && columnsType.value === "cascader" && !isEmptyBinding(newValue) && !isEmptyArray(newValue)) updateRenderedColumns();
100
- });
101
- watch(() => props.modelValue, () => {
102
- if (isEmptyBinding(props.modelValue) || isEmptyArray(props.modelValue)) {
103
- updateColumnIndexes();
104
- updateRenderedColumns();
105
- }
106
- });
81
+ const pickerClass = bem.b();
107
82
  const pickerViewClass = bem.e("picker-view");
108
83
  const indicatorClass = bem.e("indicator");
109
84
  return (_ctx, _cache) => {
110
- return openBlock(), createElementBlock("div", { class: normalizeClass(unref(bem).b()) }, [createVNode(unref(picker_view_default), {
85
+ return openBlock(), createElementBlock("div", { class: normalizeClass(unref(pickerClass)) }, [createVNode(unref(picker_view_default), {
111
86
  class: normalizeClass(unref(pickerViewClass)),
112
87
  "indicator-class": unref(indicatorClass),
113
88
  value: columnIndexes.value,
@@ -123,7 +98,7 @@ var picker_default = /*@__PURE__*/ defineComponent({
123
98
  option,
124
99
  rowIndex: j,
125
100
  columnIndex: i
126
- }, () => [createTextVNode(toDisplayString(unref(getLabel)(option)), 1)])], 2);
101
+ }, () => [createTextVNode(toDisplayString(unref(optionKeys).getLabel(option)), 1)])], 2);
127
102
  }), 128))]),
128
103
  _: 2
129
104
  }, 1024);
@@ -96,15 +96,15 @@ var picker_input_default = /*@__PURE__*/ defineComponent({
96
96
  const props = __props;
97
97
  const slots = useSlots();
98
98
  const emit = __emit;
99
- const useOptionKeysReturn = useOptionKeys(props);
99
+ const optionKeys = useOptionKeys(props);
100
100
  const partitionedProps = partitionPopoutInputProps(props);
101
101
  const { innerVisible, innerValue, inputValue, show, onChange, onClear, onVisibleHook } = usePopoutInput(props, emit);
102
- const { getLabel } = useOptionKeysReturn;
102
+ const { getLabel } = optionKeys;
103
103
  const onClick = () => {
104
104
  if (props.columns && props.columns.length > 0) show();
105
105
  };
106
106
  function getOutletText(columns, value) {
107
- return getOptionsByIndexes(getIndexesByValue(toArray(value), columns || [], useOptionKeysReturn), columns || [], useOptionKeysReturn).map((option) => getLabel(option)).join("/");
107
+ return getOptionsByIndexes(getIndexesByValue(toArray(value), columns || [], optionKeys), columns || [], optionKeys).map((option) => getLabel(option)).join("/");
108
108
  }
109
109
  function getInputValue() {
110
110
  if (isEmptyBinding(innerValue.value) || isEmptyArray(innerValue.value)) return "";
@@ -63,11 +63,11 @@ var picker_popout_default = /*@__PURE__*/ defineComponent({
63
63
  const props = __props;
64
64
  const slots = useSlots();
65
65
  const emit = __emit;
66
- const useOptionKeysReturn = useOptionKeys(props);
66
+ const optionKeys = useOptionKeys(props);
67
67
  const omittedProps = omitFormPopoutProps(props);
68
68
  const { innerVisible, innerValue, draftValue, onChange, onConfirm, onVisibleHook } = useFormPopout(props, emit, { onConfirmBefore() {
69
69
  if (isEmptyBinding(draftValue.value) || isEmptyArray(draftValue.value)) {
70
- const [initialValue, selectedOptions] = getInitialValue(props.columns, useOptionKeysReturn);
70
+ const [initialValue, selectedOptions] = getInitialValue(props.columns, optionKeys);
71
71
  draftValue.value = initialValue;
72
72
  return [selectedOptions];
73
73
  }
@@ -46,7 +46,6 @@ export interface PickerViewContext {
46
46
  maskClass: any;
47
47
  indicatorClass: any;
48
48
  indicatorStyle: any;
49
- height: number;
50
49
  getColumnValue: (ins: ComponentInternalInstance) => WritableComputedRef<number>;
51
50
  }
52
51
  export declare const pickerViewContextKey: InjectionKey<PickerViewContext>;
@@ -7,26 +7,26 @@ import { usePointerDown } from "../../use/usePointerDown.js";
7
7
  import { useResizeObserver } from "../../use/useResizeObserver.js";
8
8
  import { useScroller } from "../../utils/scroller/useScroller.js";
9
9
  import { pickerViewContextKey } from "./common.js";
10
- import { computed, createVNode, getCurrentInstance, inject, nextTick, onMounted, ref, useTemplateRef, watch } from "vue";
10
+ import { computed, createVNode, getCurrentInstance, inject, ref, watch, watchPostEffect } from "vue";
11
11
  //#region packages/sard/components/picker-view/picker-view-column.tsx
12
12
  var picker_view_column_default = defineSetupFnComponent((_props, { slots }) => {
13
13
  const bem = createBem("picker-view-column");
14
+ const instance = getCurrentInstance();
14
15
  const rootRef = ref(null);
15
16
  const contentRef = ref(null);
16
- const instance = getCurrentInstance();
17
+ const indicatorRef = ref(null);
17
18
  const context = inject(pickerViewContextKey);
18
19
  const columnValue = context.getColumnValue(instance);
19
20
  const itemCount = ref(0);
20
- const indicatorHeight = ref(48);
21
- useResizeObserver(useTemplateRef("indicator"), (size) => {
22
- if (size.height > 0) indicatorHeight.value = size.height;
21
+ const rootSize = useResizeObserver(rootRef);
22
+ const contentSize = useResizeObserver(contentRef);
23
+ const indicatorSize = useResizeObserver(indicatorRef);
24
+ const maskSize = computed(() => (rootSize.height - indicatorSize.height) / 2);
25
+ const contentHeight = computed(() => {
26
+ return contentSize.height + maskSize.value * 2;
23
27
  });
24
- const maskSize = computed(() => (context.height - indicatorHeight.value) / 2);
25
- const { update, scrollTo, isIdle, handleTouchStart, handleTouchMove, handleTouchEnd } = useScroller(contentRef, {
26
- enableY: true,
27
- enableX: false,
28
- enableSnap: true,
29
- itemSize: indicatorHeight.value,
28
+ const { position, update, scrollTo, isIdle, handleTouchStart, handleTouchMove, handleTouchEnd } = useScroller({
29
+ itemSize: indicatorSize.height,
30
30
  friction: new Friction(1e-4),
31
31
  spring: new Spring(2, 90, 20),
32
32
  onSnap: (index) => {
@@ -36,27 +36,29 @@ var picker_view_column_default = defineSetupFnComponent((_props, { slots }) => {
36
36
  handleTap(event);
37
37
  }
38
38
  });
39
- let updatesScrollerRequest;
40
- function updatesScroller() {
41
- if (!updatesScrollerRequest && indicatorHeight.value) {
42
- updatesScrollerRequest = true;
43
- nextTick(() => {
44
- updatesScrollerRequest = false;
45
- const current = Math.max(Math.min(columnValue.value, itemCount.value - 1), 0);
46
- update(current * indicatorHeight.value, void 0, indicatorHeight.value);
47
- });
48
- }
49
- }
39
+ let updatePending = false;
50
40
  watch([
51
- indicatorHeight,
41
+ () => indicatorSize.height,
42
+ columnValue,
52
43
  itemCount,
53
- () => context.height,
54
- columnValue
44
+ () => rootSize.height,
45
+ contentHeight
55
46
  ], () => {
56
- updatesScroller();
57
- });
58
- onMounted(() => {
59
- updatesScroller();
47
+ if (updatePending) return;
48
+ updatePending = true;
49
+ setTimeout(() => {
50
+ updatePending = false;
51
+ if (indicatorSize.height) {
52
+ const current = Math.max(Math.min(columnValue.value, itemCount.value - 1), 0);
53
+ update(current * indicatorSize.height, indicatorSize.height, rootSize.height, contentHeight.value);
54
+ }
55
+ });
56
+ }, { flush: "post" });
57
+ watchPostEffect(() => {
58
+ const el = contentRef.value;
59
+ if (!el) return;
60
+ const transform = "translateY(" + position.value + "px) translateZ(0)";
61
+ el.style.transform = transform;
60
62
  });
61
63
  let oldDeltaY = 0;
62
64
  function handleWheel(event) {
@@ -65,21 +67,21 @@ var picker_view_column_default = defineSetupFnComponent((_props, { slots }) => {
65
67
  oldDeltaY = 0;
66
68
  let current = Math.min(columnValue.value + (deltaY < 0 ? -1 : 1), itemCount.value - 1);
67
69
  columnValue.value = current = Math.max(current, 0);
68
- scrollTo(current * indicatorHeight.value);
70
+ scrollTo(current * indicatorSize.height);
69
71
  } else oldDeltaY = deltaY;
70
72
  event.preventDefault();
71
73
  }
72
74
  function handleTap({ changedTouches: [{ clientY }] }) {
73
75
  const el = rootRef.value;
74
76
  if (isIdle()) {
75
- const r = clientY - el.getBoundingClientRect().top - context.height / 2;
76
- const o = indicatorHeight.value / 2;
77
+ const r = clientY - el.getBoundingClientRect().top - rootSize.height / 2;
78
+ const o = indicatorSize.height / 2;
77
79
  if (!(Math.abs(r) <= o)) {
78
- const a = Math.ceil((Math.abs(r) - o) / indicatorHeight.value);
80
+ const a = Math.ceil((Math.abs(r) - o) / indicatorSize.height);
79
81
  const s = r < 0 ? -a : a;
80
82
  let current = Math.min(columnValue.value + s, itemCount.value - 1);
81
83
  columnValue.value = current = Math.max(current, 0);
82
- scrollTo(current * indicatorHeight.value);
84
+ scrollTo(current * indicatorSize.height);
83
85
  }
84
86
  }
85
87
  }
@@ -115,7 +117,7 @@ var picker_view_column_default = defineSetupFnComponent((_props, { slots }) => {
115
117
  "style": [`background-size: 100% ${maskSize.value}px;`, context.maskStyle]
116
118
  }, null),
117
119
  createVNode("div", {
118
- "ref": "indicator",
120
+ "ref": indicatorRef,
119
121
  "class": [bem.e("indicator"), context.indicatorClass],
120
122
  "style": context.indicatorStyle
121
123
  }, null),
@@ -124,7 +126,7 @@ var picker_view_column_default = defineSetupFnComponent((_props, { slots }) => {
124
126
  "class": [bem.e("content")],
125
127
  "style": {
126
128
  padding,
127
- "--picker-view-indicator-height": `${indicatorHeight.value}px`
129
+ "--picker-view-indicator-height": `${indicatorSize.height}px`
128
130
  }
129
131
  }, [defaultSlots])
130
132
  ])]);
@@ -1,13 +1,11 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
2
  import { flatVNode } from "../../utils/vnode.js";
3
3
  import { defineSetupFnComponent } from "../../utils/component.js";
4
- import { useResizeObserver } from "../../use/useResizeObserver.js";
5
4
  import { pickerViewContextKey, pickerViewProps } from "./common.js";
6
- import { computed, createVNode, provide, reactive, ref, toRef, useTemplateRef, watch } from "vue";
5
+ import { computed, createVNode, provide, reactive, ref, toRef, watch } from "vue";
7
6
  //#region packages/sard/components/picker-view/picker-view.tsx
8
7
  var picker_view_default = defineSetupFnComponent((props, { slots, emit }) => {
9
8
  const bem = createBem("picker-view");
10
- const rootRef = useTemplateRef("root");
11
9
  const innerValue = reactive([...props.value]);
12
10
  watch(() => props.value, (value) => {
13
11
  innerValue.length = value.length;
@@ -30,32 +28,24 @@ var picker_view_default = defineSetupFnComponent((props, { slots, emit }) => {
30
28
  if (index < 0) return;
31
29
  if (innerValue[index] !== current) {
32
30
  innerValue[index] = current;
33
- const value = innerValue.map((val) => val);
31
+ const value = [...innerValue];
34
32
  emit("update:value", value);
35
33
  emit("change", value);
36
34
  }
37
35
  }
38
36
  });
39
37
  };
40
- const height = ref(48);
41
- useResizeObserver(rootRef, (size) => {
42
- height.value = size.height;
43
- });
44
38
  provide(pickerViewContextKey, reactive({
45
39
  maskStyle: toRef(() => props.maskStyle),
46
40
  maskClass: toRef(() => props.maskClass),
47
41
  indicatorClass: toRef(() => props.indicatorClass),
48
42
  indicatorStyle: toRef(() => props.indicatorStyle),
49
- height,
50
43
  getColumnValue
51
44
  }));
52
45
  return () => {
53
46
  const defaultSlots = slots.default && slots.default();
54
47
  columnsRef.value = flatVNode(defaultSlots);
55
- return createVNode("div", {
56
- "ref": "root",
57
- "class": bem.b()
58
- }, [createVNode("div", { "class": bem.e("wrapper") }, [defaultSlots])]);
48
+ return createVNode("div", { "class": bem.b() }, [createVNode("div", { "class": bem.e("wrapper") }, [defaultSlots])]);
59
49
  };
60
50
  }, {
61
51
  name: "PickerView",
@@ -1,6 +1,5 @@
1
1
  import type { DefaultProps } from '../config';
2
2
  export interface StatusBarProps {
3
- reverse?: boolean;
4
3
  }
5
4
  export declare const defaultStatusBarProps: DefaultProps<StatusBarProps>;
6
5
  export interface StatusBarSlots {
@@ -1,8 +1,6 @@
1
1
  import { type StatusBarProps, type StatusBarSlots, type StatusBarExpose } from './common';
2
2
  type __VLS_Slots = StatusBarSlots;
3
- declare const __VLS_base: import("vue").DefineComponent<StatusBarProps, StatusBarExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<StatusBarProps> & Readonly<{}>, {
4
- reverse: boolean;
5
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
3
+ declare const __VLS_base: import("vue").DefineComponent<StatusBarProps, StatusBarExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<StatusBarProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
4
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
5
  declare const _default: typeof __VLS_export;
8
6
  export default _default;
@@ -1,23 +1,17 @@
1
1
  import { createBem } from "../../utils/bem.js";
2
2
  import { windowInfo } from "../config/windowInfo.js";
3
- import { defaultStatusBarProps } from "./common.js";
4
- import { computed, createElementBlock, defineComponent, mergeDefaults, normalizeClass, normalizeStyle, openBlock, unref } from "vue";
3
+ import { computed, createElementBlock, defineComponent, normalizeClass, normalizeStyle, openBlock, unref } from "vue";
5
4
  //#region packages/sard/components/status-bar/status-bar.vue
6
5
  var status_bar_default = /*@__PURE__*/ defineComponent({
7
6
  __name: "status-bar",
8
- props: /*@__PURE__*/ mergeDefaults({ reverse: {
9
- type: Boolean,
10
- required: false
11
- } }, defaultStatusBarProps),
12
7
  setup(__props, { expose: __expose }) {
13
- const props = __props;
14
8
  const bem = createBem("status-bar");
15
9
  const statusBarHeight = computed(() => {
16
10
  return windowInfo.statusBarHeight + "px";
17
11
  });
18
12
  __expose();
19
13
  const statusBarStyle = computed(() => {
20
- return [{ [props.reverse ? "width" : "height"]: statusBarHeight.value }];
14
+ return { height: statusBarHeight.value };
21
15
  });
22
16
  return (_ctx, _cache) => {
23
17
  return openBlock(), createElementBlock("div", {