@v-c/cascader 1.0.0 → 1.0.2

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,75 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_context = require("../context.cjs");
7
- let vue = require("vue");
8
- let _v_c_util = require("@v-c/util");
9
- var Checkbox = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
10
- const context = require_context.useCascaderContext();
11
- return () => {
12
- const checkable = context.value?.checkable;
13
- const customCheckbox = typeof checkable !== "boolean" ? checkable : null;
14
- return (0, vue.createVNode)("span", {
15
- "class": (0, _v_c_util.clsx)(`${props.prefixCls}`, {
16
- [`${props.prefixCls}-checked`]: props.checked,
17
- [`${props.prefixCls}-indeterminate`]: !props.checked && props.halfChecked,
18
- [`${props.prefixCls}-disabled`]: props.disabled || props.disableCheckbox
19
- }),
20
- "onClick": props.onClick
21
- }, [customCheckbox]);
22
- };
23
- }, { props: /* @__PURE__ */ (0, vue.mergeDefaults)({
24
- prefixCls: {
25
- type: String,
26
- required: true,
27
- default: void 0
28
- },
29
- checked: {
30
- type: Boolean,
31
- required: false,
32
- default: void 0
33
- },
34
- halfChecked: {
35
- type: Boolean,
36
- required: false,
37
- default: void 0
38
- },
39
- disabled: {
40
- type: Boolean,
41
- required: false,
42
- default: void 0
43
- },
44
- onClick: {
45
- type: Function,
46
- required: false,
47
- default: void 0
48
- },
49
- disableCheckbox: {
50
- type: Boolean,
51
- required: false,
52
- default: void 0
53
- },
54
- children: {
55
- type: [
56
- Object,
57
- Function,
58
- String,
59
- Number,
60
- null,
61
- Boolean,
62
- Array
63
- ],
64
- required: false,
65
- default: void 0
66
- }
67
- }, {
68
- prefixCls: "",
69
- checked: false,
70
- halfChecked: false,
71
- disabled: false,
72
- disableCheckbox: false
73
- }) });
74
- var Checkbox_default = Checkbox;
75
- exports.default = Checkbox_default;
@@ -1,224 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_context = require("../context.cjs");
7
- const require_useSearchOptions = require("../hooks/useSearchOptions.cjs");
8
- const require_commonUtil = require("../utils/commonUtil.cjs");
9
- const require_Checkbox = require("./Checkbox.cjs");
10
- let vue = require("vue");
11
- let _v_c_util = require("@v-c/util");
12
- let _v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
13
- _v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(_v_c_util_dist_pickAttrs);
14
- const FIX_LABEL = "__cascader_fix_label__";
15
- var columnDefaults = {
16
- prefixCls: "",
17
- options: [],
18
- prevValuePath: [],
19
- onToggleOpen: () => {},
20
- onSelect: () => {},
21
- onActive: () => {},
22
- checkedSet: /* @__PURE__ */ new Set(),
23
- halfCheckedSet: /* @__PURE__ */ new Set(),
24
- loadingKeys: [],
25
- isSelectable: () => false
26
- };
27
- var Column = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
28
- const menuRef = (0, vue.ref)(null);
29
- const context = require_context.useCascaderContext();
30
- const menuPrefixCls = (0, vue.computed)(() => `${props.prefixCls}-menu`);
31
- const menuItemPrefixCls = (0, vue.computed)(() => `${props.prefixCls}-menu-item`);
32
- const hoverOpen = (0, vue.computed)(() => context.value?.expandTrigger === "hover");
33
- const isOptionDisabled = (disabled) => props.disabled || disabled;
34
- const optionInfoList = (0, vue.computed)(() => {
35
- const fieldNames = context.value?.fieldNames;
36
- if (!fieldNames) return [];
37
- return props.options.map((option) => {
38
- const { disabled, disableCheckbox } = option;
39
- const searchOptions = option[require_useSearchOptions.SEARCH_MARK];
40
- const label = option["__cascader_fix_label__"] ?? option[fieldNames.label];
41
- const value = option[fieldNames.value];
42
- const isMergedLeaf = require_commonUtil.isLeaf(option, fieldNames);
43
- const fullPath = searchOptions ? searchOptions.map((opt) => opt[fieldNames.value]) : [...props.prevValuePath, value];
44
- const fullPathKey = require_commonUtil.toPathKey(fullPath);
45
- return {
46
- disabled,
47
- label,
48
- value,
49
- isLeaf: isMergedLeaf,
50
- isLoading: props.loadingKeys.includes(fullPathKey),
51
- checked: props.checkedSet.has(fullPathKey),
52
- halfChecked: props.halfCheckedSet.has(fullPathKey),
53
- option,
54
- disableCheckbox,
55
- fullPath,
56
- fullPathKey
57
- };
58
- });
59
- });
60
- (0, vue.watch)(() => props.activeValue, async () => {
61
- if (menuRef.value) {
62
- const selector = `.${menuItemPrefixCls.value}-active`;
63
- const activeElement = menuRef.value.querySelector(selector);
64
- if (activeElement) require_commonUtil.scrollIntoParentView(activeElement);
65
- }
66
- }, {
67
- immediate: true,
68
- flush: "post"
69
- });
70
- return () => {
71
- const fieldNames = context.value?.fieldNames;
72
- const changeOnSelect = context.value?.changeOnSelect;
73
- const expandIcon = context.value?.expandIcon;
74
- const loadingIcon = context.value?.loadingIcon;
75
- const popupMenuColumnStyle = context.value?.popupMenuColumnStyle;
76
- const optionRender = context.value?.optionRender;
77
- const classNames = context.value?.classNames;
78
- const styles = context.value?.styles;
79
- if (!fieldNames) return null;
80
- return (0, vue.createVNode)("ul", {
81
- "class": (0, _v_c_util.clsx)(menuPrefixCls.value, classNames?.popup?.list),
82
- "style": styles?.popup?.list,
83
- "ref": menuRef,
84
- "role": "menu"
85
- }, [optionInfoList.value.map(({ disabled, label, value, isLeaf: isMergedLeaf, isLoading, checked, halfChecked, option, fullPath, fullPathKey, disableCheckbox }) => {
86
- const ariaProps = (0, _v_c_util_dist_pickAttrs.default)(option, {
87
- aria: true,
88
- data: true
89
- });
90
- const triggerOpenPath = () => {
91
- if (isOptionDisabled(disabled)) return;
92
- const nextValueCells = [...fullPath];
93
- if (hoverOpen.value && isMergedLeaf) nextValueCells.pop();
94
- props.onActive(nextValueCells);
95
- };
96
- const triggerSelect = () => {
97
- if (props.isSelectable(option) && !isOptionDisabled(disabled)) props.onSelect(fullPath, isMergedLeaf);
98
- };
99
- let title;
100
- if (typeof option.title === "string") title = option.title;
101
- else if (typeof label === "string") title = label;
102
- return (0, vue.createVNode)("li", (0, vue.mergeProps)({ "key": fullPathKey }, ariaProps, {
103
- "class": (0, _v_c_util.clsx)(menuItemPrefixCls.value, classNames?.popup?.listItem, {
104
- [`${menuItemPrefixCls.value}-expand`]: !isMergedLeaf,
105
- [`${menuItemPrefixCls.value}-active`]: props.activeValue === value || props.activeValue === fullPathKey,
106
- [`${menuItemPrefixCls.value}-disabled`]: isOptionDisabled(disabled),
107
- [`${menuItemPrefixCls.value}-loading`]: isLoading
108
- }),
109
- "style": {
110
- ...popupMenuColumnStyle,
111
- ...styles?.popup?.listItem
112
- },
113
- "role": "menuitemcheckbox",
114
- "title": title,
115
- "aria-checked": checked,
116
- "data-path-key": fullPathKey,
117
- "onClick": () => {
118
- triggerOpenPath();
119
- if (disableCheckbox) return;
120
- if (!props.multiple || isMergedLeaf) triggerSelect();
121
- },
122
- "onDblclick": () => {
123
- if (changeOnSelect) props.onToggleOpen(false);
124
- },
125
- "onMouseenter": () => {
126
- if (hoverOpen.value) triggerOpenPath();
127
- },
128
- "onMousedown": (e) => {
129
- e.preventDefault();
130
- }
131
- }), [
132
- props.multiple && (0, vue.createVNode)(require_Checkbox.default, {
133
- "prefixCls": `${props.prefixCls}-checkbox`,
134
- "checked": checked,
135
- "halfChecked": halfChecked,
136
- "disabled": isOptionDisabled(disabled) || disableCheckbox,
137
- "disableCheckbox": disableCheckbox,
138
- "onClick": (e) => {
139
- if (disableCheckbox) return;
140
- e.stopPropagation();
141
- triggerSelect();
142
- }
143
- }, null),
144
- (0, vue.createVNode)("div", { "class": `${menuItemPrefixCls.value}-content` }, [optionRender && value !== "__EMPTY__" ? optionRender(option) : label]),
145
- !isLoading && expandIcon && !isMergedLeaf && (0, vue.createVNode)("div", { "class": `${menuItemPrefixCls.value}-expand-icon` }, [expandIcon]),
146
- isLoading && loadingIcon && (0, vue.createVNode)("div", { "class": `${menuItemPrefixCls.value}-loading-icon` }, [loadingIcon])
147
- ]);
148
- })]);
149
- };
150
- }, { props: /* @__PURE__ */ (0, vue.mergeDefaults)({
151
- prefixCls: {
152
- type: String,
153
- required: true,
154
- default: void 0
155
- },
156
- multiple: {
157
- type: Boolean,
158
- required: false,
159
- default: void 0
160
- },
161
- options: {
162
- type: Array,
163
- required: true,
164
- default: void 0
165
- },
166
- activeValue: {
167
- type: [String, Number],
168
- required: false,
169
- default: void 0
170
- },
171
- prevValuePath: {
172
- type: Array,
173
- required: true,
174
- default: void 0
175
- },
176
- onToggleOpen: {
177
- type: Function,
178
- required: true,
179
- default: void 0
180
- },
181
- onSelect: {
182
- type: Function,
183
- required: true,
184
- default: void 0
185
- },
186
- onActive: {
187
- type: Function,
188
- required: true,
189
- default: void 0
190
- },
191
- checkedSet: {
192
- type: Set,
193
- required: true,
194
- default: void 0
195
- },
196
- halfCheckedSet: {
197
- type: Set,
198
- required: true,
199
- default: void 0
200
- },
201
- loadingKeys: {
202
- type: Array,
203
- required: true,
204
- default: void 0
205
- },
206
- isSelectable: {
207
- type: Function,
208
- required: true,
209
- default: void 0
210
- },
211
- disabled: {
212
- type: Boolean,
213
- required: false,
214
- default: void 0
215
- },
216
- style: {
217
- type: Object,
218
- required: false,
219
- default: void 0
220
- }
221
- }, columnDefaults) });
222
- var Column_default = Column;
223
- exports.FIX_LABEL = FIX_LABEL;
224
- exports.default = Column_default;
@@ -1,195 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_context = require("../context.cjs");
7
- const require_commonUtil = require("../utils/commonUtil.cjs");
8
- const require_treeUtil = require("../utils/treeUtil.cjs");
9
- const require_CacheContent = require("./CacheContent.cjs");
10
- const require_Column = require("./Column.cjs");
11
- const require_useActive = require("./useActive.cjs");
12
- const require_useKeyboard = require("./useKeyboard.cjs");
13
- let vue = require("vue");
14
- let _v_c_util = require("@v-c/util");
15
- var RawOptionList = /* @__PURE__ */ (0, vue.defineComponent)((props, { expose }) => {
16
- const containerRef = (0, vue.ref)(null);
17
- const rtl = (0, vue.computed)(() => props.direction === "rtl");
18
- const context = require_context.useCascaderContext();
19
- const mergedPrefixCls = (0, vue.computed)(() => context.value?.popupPrefixCls || props.prefixCls);
20
- const mergedFieldNames = (0, vue.computed)(() => context.value?.fieldNames);
21
- const loadingKeys = (0, vue.ref)([]);
22
- const internalLoadData = (valueCells) => {
23
- if (!context.value?.loadData || props.searchValue) return;
24
- const fieldNames = mergedFieldNames.value;
25
- const options = context.value?.options || [];
26
- if (!fieldNames) return;
27
- const rawOptions = require_treeUtil.toPathOptions(valueCells, options, fieldNames).map(({ option }) => option);
28
- const lastOption = rawOptions[rawOptions.length - 1];
29
- if (lastOption && !require_commonUtil.isLeaf(lastOption, fieldNames)) {
30
- const pathKey = require_commonUtil.toPathKey(valueCells);
31
- loadingKeys.value = [...loadingKeys.value, pathKey];
32
- context.value.loadData(rawOptions);
33
- }
34
- };
35
- (0, vue.watchEffect)(() => {
36
- const fieldNames = mergedFieldNames.value;
37
- const options = context.value?.options || [];
38
- if (!loadingKeys.value.length || !fieldNames) return;
39
- const nextLoadingKeys = loadingKeys.value.filter((loadingKey) => {
40
- const optionList = require_treeUtil.toPathOptions(require_commonUtil.toPathValueStr(String(loadingKey)), options, fieldNames, true).map(({ option }) => option);
41
- const lastOption = optionList[optionList.length - 1];
42
- return !(!lastOption || lastOption[fieldNames.children] || require_commonUtil.isLeaf(lastOption, fieldNames));
43
- });
44
- if (!(nextLoadingKeys.length === loadingKeys.value.length && nextLoadingKeys.every((key, index) => key === loadingKeys.value[index]))) loadingKeys.value = nextLoadingKeys;
45
- });
46
- const checkedSet = (0, vue.computed)(() => new Set(require_commonUtil.toPathKeys(context.value?.values || [])));
47
- const halfCheckedSet = (0, vue.computed)(() => new Set(require_commonUtil.toPathKeys(context.value?.halfValues || [])));
48
- const [activeValueCells, setActiveValueCells] = require_useActive.default((0, vue.computed)(() => !!props.multiple), (0, vue.computed)(() => props.open));
49
- const onPathOpen = (nextValueCells) => {
50
- setActiveValueCells(nextValueCells);
51
- internalLoadData(nextValueCells);
52
- };
53
- const isSelectable = (option) => {
54
- if (props.disabled) return false;
55
- const { disabled: optionDisabled } = option;
56
- const fieldNames = mergedFieldNames.value;
57
- if (!fieldNames) return false;
58
- const isMergedLeaf = require_commonUtil.isLeaf(option, fieldNames);
59
- return !optionDisabled && (isMergedLeaf || context.value?.changeOnSelect || props.multiple);
60
- };
61
- const onPathSelect = (valuePath, leaf, fromKeyboard = false) => {
62
- context.value?.onSelect(valuePath);
63
- if (!props.multiple && (leaf || context.value?.changeOnSelect && (context.value?.expandTrigger === "hover" || fromKeyboard))) props.toggleOpen(false);
64
- };
65
- const mergedOptions = (0, vue.computed)(() => {
66
- if (props.searchValue) return context.value?.searchOptions || [];
67
- return context.value?.options || [];
68
- });
69
- const optionColumns = (0, vue.computed)(() => {
70
- const fieldNames = mergedFieldNames.value;
71
- if (!fieldNames) return [];
72
- const optionList = [{ options: mergedOptions.value }];
73
- let currentList = mergedOptions.value;
74
- const fullPathKeys = require_commonUtil.getFullPathKeys(currentList, fieldNames);
75
- for (let i = 0; i < activeValueCells.value.length; i += 1) {
76
- const activeValueCell = activeValueCells.value[i];
77
- const subOptions = currentList.find((option, index) => (fullPathKeys[index] ? require_commonUtil.toPathKey(fullPathKeys[index]) : option[fieldNames.value]) === activeValueCell)?.[fieldNames.children];
78
- if (!subOptions?.length) break;
79
- currentList = subOptions;
80
- optionList.push({ options: subOptions });
81
- }
82
- return optionList;
83
- });
84
- const onKeyboardSelect = (selectValueCells, option) => {
85
- if (isSelectable(option) && mergedFieldNames.value) onPathSelect(selectValueCells, require_commonUtil.isLeaf(option, mergedFieldNames.value), true);
86
- };
87
- expose(require_useKeyboard.default(mergedOptions, mergedFieldNames, activeValueCells, onPathOpen, onKeyboardSelect, {
88
- direction: (0, vue.computed)(() => props.direction),
89
- searchValue: (0, vue.computed)(() => props.searchValue || ""),
90
- toggleOpen: props.toggleOpen,
91
- open: (0, vue.computed)(() => props.open)
92
- }));
93
- (0, vue.watch)([() => activeValueCells.value, () => props.searchValue], () => {
94
- if (props.searchValue) return;
95
- (0, vue.nextTick)(() => {
96
- for (let i = 0; i < activeValueCells.value.length; i += 1) {
97
- const cellKeyPath = require_commonUtil.toPathKey(activeValueCells.value.slice(0, i + 1));
98
- const ele = containerRef.value?.querySelector(`li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, "\\\"")}"]`);
99
- if (ele) require_commonUtil.scrollIntoParentView(ele);
100
- }
101
- });
102
- }, { deep: true });
103
- return () => {
104
- const fieldNames = mergedFieldNames.value;
105
- if (!fieldNames) return null;
106
- const isEmpty = !optionColumns.value[0]?.options?.length;
107
- const emptyList = [{
108
- [fieldNames.value]: "__EMPTY__",
109
- [require_Column.FIX_LABEL]: props.notFoundContent,
110
- disabled: true
111
- }];
112
- const columnProps = {
113
- ...props,
114
- multiple: !isEmpty && props.multiple,
115
- onSelect: onPathSelect,
116
- onActive: onPathOpen,
117
- onToggleOpen: props.toggleOpen,
118
- checkedSet: checkedSet.value,
119
- halfCheckedSet: halfCheckedSet.value,
120
- loadingKeys: loadingKeys.value,
121
- isSelectable
122
- };
123
- const columnNodes = (isEmpty ? [{ options: emptyList }] : optionColumns.value).map((col, index) => {
124
- const prevValuePath = activeValueCells.value.slice(0, index);
125
- const activeValue = activeValueCells.value[index];
126
- return (0, vue.createVNode)(require_Column.default, (0, vue.mergeProps)({ "key": index }, columnProps, {
127
- "prefixCls": mergedPrefixCls.value,
128
- "options": col.options,
129
- "prevValuePath": prevValuePath,
130
- "activeValue": activeValue
131
- }), null);
132
- });
133
- return (0, vue.createVNode)(require_CacheContent.default, { "open": props.open }, { default: () => [(0, vue.createVNode)("div", {
134
- "class": (0, _v_c_util.clsx)(`${mergedPrefixCls.value}-menus`, {
135
- [`${mergedPrefixCls.value}-menu-empty`]: isEmpty,
136
- [`${mergedPrefixCls.value}-rtl`]: rtl.value
137
- }),
138
- "ref": containerRef
139
- }, [columnNodes])] });
140
- };
141
- }, {
142
- props: /* @__PURE__ */ (0, vue.mergeDefaults)({
143
- prefixCls: {
144
- type: String,
145
- required: true,
146
- default: void 0
147
- },
148
- multiple: {
149
- type: Boolean,
150
- required: false,
151
- default: void 0
152
- },
153
- searchValue: {
154
- type: String,
155
- required: false,
156
- default: void 0
157
- },
158
- toggleOpen: {
159
- type: Function,
160
- required: true,
161
- default: void 0
162
- },
163
- notFoundContent: {
164
- required: false,
165
- default: void 0
166
- },
167
- direction: {
168
- type: String,
169
- required: false,
170
- default: void 0
171
- },
172
- open: {
173
- type: Boolean,
174
- required: false,
175
- default: void 0
176
- },
177
- disabled: {
178
- type: Boolean,
179
- required: false,
180
- default: void 0
181
- }
182
- }, {
183
- prefixCls: "",
184
- multiple: false,
185
- searchValue: "",
186
- toggleOpen: () => {},
187
- open: false,
188
- direction: "ltr",
189
- disabled: false
190
- }),
191
- name: "RawOptionList",
192
- inheritAttrs: false
193
- });
194
- var List_default = RawOptionList;
195
- exports.default = List_default;
@@ -1,24 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_List = require("./List.cjs");
7
- let vue = require("vue");
8
- let _v_c_select = require("@v-c/select");
9
- var OptionList = /* @__PURE__ */ (0, vue.defineComponent)((_, { expose }) => {
10
- const baseProps = (0, _v_c_select.useBaseProps)();
11
- const listRef = (0, vue.shallowRef)(null);
12
- expose({
13
- onKeyDown: (event) => listRef.value?.onKeyDown(event),
14
- onKeyUp: (event) => listRef.value?.onKeyUp(event)
15
- });
16
- return () => (0, vue.createVNode)(require_List.default, (0, vue.mergeProps)(baseProps.value || {}, { "ref": (el) => {
17
- listRef.value = el;
18
- } }), null);
19
- }, {
20
- name: "OptionList",
21
- inheritAttrs: false
22
- });
23
- var OptionList_default = OptionList;
24
- exports.default = OptionList_default;
@@ -1,19 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_context = require("../context.cjs");
7
- let vue = require("vue");
8
- function useActive(multiple, open) {
9
- const context = require_context.useCascaderContext();
10
- const activeValueCells = (0, vue.ref)([]);
11
- (0, vue.watch)([open, () => context.value?.values?.[0]], () => {
12
- if (!multiple.value) activeValueCells.value = context.value?.values?.[0] || [];
13
- }, { immediate: true });
14
- return [activeValueCells, (next) => {
15
- activeValueCells.value = next;
16
- }];
17
- }
18
- var useActive_default = useActive;
19
- exports.default = useActive_default;
@@ -1,108 +0,0 @@
1
- Object.defineProperties(exports, {
2
- __esModule: { value: true },
3
- [Symbol.toStringTag]: { value: "Module" }
4
- });
5
- const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
6
- const require_useSearchOptions = require("../hooks/useSearchOptions.cjs");
7
- const require_commonUtil = require("../utils/commonUtil.cjs");
8
- let _v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
9
- _v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(_v_c_util_dist_KeyCode);
10
- function useKeyboard(options, fieldNames, activeValueCells, setActiveValueCells, onKeyBoardSelect, contextProps) {
11
- const getActiveStatus = () => {
12
- let activeIndex = -1;
13
- let currentOptions = options.value;
14
- const mergedActiveIndexes = [];
15
- const mergedActiveValueCells = [];
16
- const len = activeValueCells.value.length;
17
- const pathKeys = require_commonUtil.getFullPathKeys(options.value, fieldNames.value);
18
- for (let i = 0; i < len && currentOptions; i += 1) {
19
- const nextActiveIndex = currentOptions.findIndex((option, index) => (pathKeys[index] ? require_commonUtil.toPathKey(pathKeys[index]) : option[fieldNames.value.value]) === activeValueCells.value[i]);
20
- if (nextActiveIndex === -1) break;
21
- activeIndex = nextActiveIndex;
22
- mergedActiveIndexes.push(activeIndex);
23
- mergedActiveValueCells.push(activeValueCells.value[i]);
24
- currentOptions = currentOptions[activeIndex]?.[fieldNames.value.children];
25
- }
26
- let activeOptions = options.value;
27
- for (let i = 0; i < mergedActiveIndexes.length - 1; i += 1) activeOptions = activeOptions[mergedActiveIndexes[i]]?.[fieldNames.value.children] || [];
28
- return {
29
- validActiveValueCells: mergedActiveValueCells,
30
- lastActiveIndex: activeIndex,
31
- lastActiveOptions: activeOptions,
32
- fullPathKeys: pathKeys
33
- };
34
- };
35
- const internalSetActiveValueCells = (next) => {
36
- setActiveValueCells(next);
37
- };
38
- const offsetActiveOption = (offset) => {
39
- const { lastActiveOptions, lastActiveIndex, fullPathKeys, validActiveValueCells } = getActiveStatus();
40
- const len = lastActiveOptions.length;
41
- let currentIndex = lastActiveIndex;
42
- if (currentIndex === -1 && offset < 0) currentIndex = len;
43
- for (let i = 0; i < len; i += 1) {
44
- currentIndex = (currentIndex + offset + len) % len;
45
- const option = lastActiveOptions[currentIndex];
46
- if (option && !option.disabled) {
47
- internalSetActiveValueCells(validActiveValueCells.slice(0, -1).concat(fullPathKeys[currentIndex] ? require_commonUtil.toPathKey(fullPathKeys[currentIndex]) : option[fieldNames.value.value]));
48
- return;
49
- }
50
- }
51
- };
52
- const prevColumn = () => {
53
- const { validActiveValueCells } = getActiveStatus();
54
- if (validActiveValueCells.length > 1) internalSetActiveValueCells(validActiveValueCells.slice(0, -1));
55
- else contextProps.toggleOpen(false);
56
- };
57
- const nextColumn = () => {
58
- const { lastActiveOptions, lastActiveIndex, validActiveValueCells } = getActiveStatus();
59
- const nextOption = (lastActiveOptions[lastActiveIndex]?.[fieldNames.value.children] || []).find((option) => !option.disabled);
60
- if (nextOption) internalSetActiveValueCells([...validActiveValueCells, nextOption[fieldNames.value.value]]);
61
- };
62
- return {
63
- scrollTo: () => {},
64
- onKeyDown: (event) => {
65
- const { which } = event;
66
- const rtl = contextProps.direction.value === "rtl";
67
- const searchValue = contextProps.searchValue.value;
68
- const open = contextProps.open.value;
69
- switch (which) {
70
- case _v_c_util_dist_KeyCode.default.UP:
71
- case _v_c_util_dist_KeyCode.default.DOWN: {
72
- let offset = 0;
73
- if (which === _v_c_util_dist_KeyCode.default.UP) offset = -1;
74
- else if (which === _v_c_util_dist_KeyCode.default.DOWN) offset = 1;
75
- if (offset !== 0) offsetActiveOption(offset);
76
- break;
77
- }
78
- case _v_c_util_dist_KeyCode.default.LEFT:
79
- if (searchValue) break;
80
- if (rtl) nextColumn();
81
- else prevColumn();
82
- break;
83
- case _v_c_util_dist_KeyCode.default.RIGHT:
84
- if (searchValue) break;
85
- if (rtl) prevColumn();
86
- else nextColumn();
87
- break;
88
- case _v_c_util_dist_KeyCode.default.BACKSPACE:
89
- if (!searchValue) prevColumn();
90
- break;
91
- case _v_c_util_dist_KeyCode.default.ENTER: {
92
- const { validActiveValueCells, lastActiveOptions, lastActiveIndex } = getActiveStatus();
93
- if (validActiveValueCells.length) {
94
- const originOptions = lastActiveOptions[lastActiveIndex]?.["__vc_cascader_search_mark__"] || [];
95
- if (originOptions.length) onKeyBoardSelect(originOptions.map((opt) => opt[fieldNames.value.value]), originOptions[originOptions.length - 1]);
96
- else onKeyBoardSelect(validActiveValueCells, lastActiveOptions[lastActiveIndex]);
97
- }
98
- break;
99
- }
100
- case _v_c_util_dist_KeyCode.default.ESC:
101
- contextProps.toggleOpen(false);
102
- if (open) event.stopPropagation();
103
- }
104
- },
105
- onKeyUp: () => {}
106
- };
107
- }
108
- exports.default = useKeyboard;