@v-c/cascader 0.0.1
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.
- package/LICENSE +21 -0
- package/dist/Cascader.cjs +647 -0
- package/dist/Cascader.d.ts +90 -0
- package/dist/Cascader.js +639 -0
- package/dist/OptionList/CacheContent.cjs +38 -0
- package/dist/OptionList/CacheContent.d.ts +7 -0
- package/dist/OptionList/CacheContent.js +32 -0
- package/dist/OptionList/Checkbox.cjs +75 -0
- package/dist/OptionList/Checkbox.d.ts +12 -0
- package/dist/OptionList/Checkbox.js +69 -0
- package/dist/OptionList/Column.cjs +223 -0
- package/dist/OptionList/Column.d.ts +23 -0
- package/dist/OptionList/Column.js +215 -0
- package/dist/OptionList/List.cjs +195 -0
- package/dist/OptionList/List.d.ts +12 -0
- package/dist/OptionList/List.js +189 -0
- package/dist/OptionList/index.cjs +24 -0
- package/dist/OptionList/index.d.ts +2 -0
- package/dist/OptionList/index.js +18 -0
- package/dist/OptionList/useActive.cjs +19 -0
- package/dist/OptionList/useActive.d.ts +7 -0
- package/dist/OptionList/useActive.js +14 -0
- package/dist/OptionList/useKeyboard.cjs +108 -0
- package/dist/OptionList/useKeyboard.d.ts +9 -0
- package/dist/OptionList/useKeyboard.js +102 -0
- package/dist/Panel.cjs +209 -0
- package/dist/Panel.d.ts +5 -0
- package/dist/Panel.js +202 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/context.cjs +12 -0
- package/dist/context.d.ts +23 -0
- package/dist/context.js +9 -0
- package/dist/hooks/useDisplayValues.cjs +39 -0
- package/dist/hooks/useDisplayValues.d.ts +4 -0
- package/dist/hooks/useDisplayValues.js +34 -0
- package/dist/hooks/useEntities.cjs +41 -0
- package/dist/hooks/useEntities.d.ts +10 -0
- package/dist/hooks/useEntities.js +36 -0
- package/dist/hooks/useMissingValues.cjs +17 -0
- package/dist/hooks/useMissingValues.d.ts +4 -0
- package/dist/hooks/useMissingValues.js +13 -0
- package/dist/hooks/useOptions.cjs +25 -0
- package/dist/hooks/useOptions.d.ts +9 -0
- package/dist/hooks/useOptions.js +20 -0
- package/dist/hooks/useSearchConfig.cjs +34 -0
- package/dist/hooks/useSearchConfig.d.ts +4 -0
- package/dist/hooks/useSearchConfig.js +29 -0
- package/dist/hooks/useSearchOptions.cjs +46 -0
- package/dist/hooks/useSearchOptions.d.ts +5 -0
- package/dist/hooks/useSearchOptions.js +40 -0
- package/dist/hooks/useSelect.cjs +36 -0
- package/dist/hooks/useSelect.d.ts +4 -0
- package/dist/hooks/useSelect.js +31 -0
- package/dist/hooks/useValues.cjs +25 -0
- package/dist/hooks/useValues.d.ts +9 -0
- package/dist/hooks/useValues.js +20 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +9 -0
- package/dist/utils/commonUtil.cjs +56 -0
- package/dist/utils/commonUtil.d.ts +18 -0
- package/dist/utils/commonUtil.js +45 -0
- package/dist/utils/treeUtil.cjs +34 -0
- package/dist/utils/treeUtil.d.ts +8 -0
- package/dist/utils/treeUtil.js +32 -0
- package/dist/utils/warningPropsUtil.cjs +19 -0
- package/dist/utils/warningPropsUtil.d.ts +2 -0
- package/dist/utils/warningPropsUtil.js +17 -0
- package/package.json +38 -0
|
@@ -0,0 +1,195 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RawOptionListProps {
|
|
2
|
+
prefixCls: string;
|
|
3
|
+
multiple?: boolean;
|
|
4
|
+
searchValue?: string;
|
|
5
|
+
toggleOpen: (open?: boolean) => void;
|
|
6
|
+
notFoundContent?: any;
|
|
7
|
+
direction?: 'ltr' | 'rtl';
|
|
8
|
+
open?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const RawOptionList: import('vue').DefineSetupFnComponent<RawOptionListProps, {}, {}, RawOptionListProps & {}, import('vue').PublicProps>;
|
|
12
|
+
export default RawOptionList;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { useCascaderContext } from "../context.js";
|
|
2
|
+
import { getFullPathKeys, isLeaf, scrollIntoParentView, toPathKey, toPathKeys, toPathValueStr } from "../utils/commonUtil.js";
|
|
3
|
+
import { toPathOptions } from "../utils/treeUtil.js";
|
|
4
|
+
import CacheContent_default from "./CacheContent.js";
|
|
5
|
+
import Column_default, { FIX_LABEL } from "./Column.js";
|
|
6
|
+
import useActive_default from "./useActive.js";
|
|
7
|
+
import useKeyboard from "./useKeyboard.js";
|
|
8
|
+
import { computed, createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, ref, watch, watchEffect } from "vue";
|
|
9
|
+
import { clsx } from "@v-c/util";
|
|
10
|
+
var List_default = /* @__PURE__ */ defineComponent((props, { expose }) => {
|
|
11
|
+
const containerRef = ref(null);
|
|
12
|
+
const rtl = computed(() => props.direction === "rtl");
|
|
13
|
+
const context = useCascaderContext();
|
|
14
|
+
const mergedPrefixCls = computed(() => context.value?.popupPrefixCls || props.prefixCls);
|
|
15
|
+
const mergedFieldNames = computed(() => context.value?.fieldNames);
|
|
16
|
+
const loadingKeys = ref([]);
|
|
17
|
+
const internalLoadData = (valueCells) => {
|
|
18
|
+
if (!context.value?.loadData || props.searchValue) return;
|
|
19
|
+
const fieldNames = mergedFieldNames.value;
|
|
20
|
+
const options = context.value?.options || [];
|
|
21
|
+
if (!fieldNames) return;
|
|
22
|
+
const rawOptions = toPathOptions(valueCells, options, fieldNames).map(({ option }) => option);
|
|
23
|
+
const lastOption = rawOptions[rawOptions.length - 1];
|
|
24
|
+
if (lastOption && !isLeaf(lastOption, fieldNames)) {
|
|
25
|
+
const pathKey = toPathKey(valueCells);
|
|
26
|
+
loadingKeys.value = [...loadingKeys.value, pathKey];
|
|
27
|
+
context.value.loadData(rawOptions);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
watchEffect(() => {
|
|
31
|
+
const fieldNames = mergedFieldNames.value;
|
|
32
|
+
const options = context.value?.options || [];
|
|
33
|
+
if (!loadingKeys.value.length || !fieldNames) return;
|
|
34
|
+
const nextLoadingKeys = loadingKeys.value.filter((loadingKey) => {
|
|
35
|
+
const optionList = toPathOptions(toPathValueStr(String(loadingKey)), options, fieldNames, true).map(({ option }) => option);
|
|
36
|
+
const lastOption = optionList[optionList.length - 1];
|
|
37
|
+
return !(!lastOption || lastOption[fieldNames.children] || isLeaf(lastOption, fieldNames));
|
|
38
|
+
});
|
|
39
|
+
if (!(nextLoadingKeys.length === loadingKeys.value.length && nextLoadingKeys.every((key, index) => key === loadingKeys.value[index]))) loadingKeys.value = nextLoadingKeys;
|
|
40
|
+
});
|
|
41
|
+
const checkedSet = computed(() => new Set(toPathKeys(context.value?.values || [])));
|
|
42
|
+
const halfCheckedSet = computed(() => new Set(toPathKeys(context.value?.halfValues || [])));
|
|
43
|
+
const [activeValueCells, setActiveValueCells] = useActive_default(computed(() => !!props.multiple), computed(() => props.open));
|
|
44
|
+
const onPathOpen = (nextValueCells) => {
|
|
45
|
+
setActiveValueCells(nextValueCells);
|
|
46
|
+
internalLoadData(nextValueCells);
|
|
47
|
+
};
|
|
48
|
+
const isSelectable = (option) => {
|
|
49
|
+
if (props.disabled) return false;
|
|
50
|
+
const { disabled: optionDisabled } = option;
|
|
51
|
+
const fieldNames = mergedFieldNames.value;
|
|
52
|
+
if (!fieldNames) return false;
|
|
53
|
+
const isMergedLeaf = isLeaf(option, fieldNames);
|
|
54
|
+
return !optionDisabled && (isMergedLeaf || context.value?.changeOnSelect || props.multiple);
|
|
55
|
+
};
|
|
56
|
+
const onPathSelect = (valuePath, leaf, fromKeyboard = false) => {
|
|
57
|
+
context.value?.onSelect(valuePath);
|
|
58
|
+
if (!props.multiple && (leaf || context.value?.changeOnSelect && (context.value?.expandTrigger === "hover" || fromKeyboard))) props.toggleOpen(false);
|
|
59
|
+
};
|
|
60
|
+
const mergedOptions = computed(() => {
|
|
61
|
+
if (props.searchValue) return context.value?.searchOptions || [];
|
|
62
|
+
return context.value?.options || [];
|
|
63
|
+
});
|
|
64
|
+
const optionColumns = computed(() => {
|
|
65
|
+
const fieldNames = mergedFieldNames.value;
|
|
66
|
+
if (!fieldNames) return [];
|
|
67
|
+
const optionList = [{ options: mergedOptions.value }];
|
|
68
|
+
let currentList = mergedOptions.value;
|
|
69
|
+
const fullPathKeys = getFullPathKeys(currentList, fieldNames);
|
|
70
|
+
for (let i = 0; i < activeValueCells.value.length; i += 1) {
|
|
71
|
+
const activeValueCell = activeValueCells.value[i];
|
|
72
|
+
const subOptions = currentList.find((option, index) => (fullPathKeys[index] ? toPathKey(fullPathKeys[index]) : option[fieldNames.value]) === activeValueCell)?.[fieldNames.children];
|
|
73
|
+
if (!subOptions?.length) break;
|
|
74
|
+
currentList = subOptions;
|
|
75
|
+
optionList.push({ options: subOptions });
|
|
76
|
+
}
|
|
77
|
+
return optionList;
|
|
78
|
+
});
|
|
79
|
+
const onKeyboardSelect = (selectValueCells, option) => {
|
|
80
|
+
if (isSelectable(option) && mergedFieldNames.value) onPathSelect(selectValueCells, isLeaf(option, mergedFieldNames.value), true);
|
|
81
|
+
};
|
|
82
|
+
expose(useKeyboard(mergedOptions, mergedFieldNames, activeValueCells, onPathOpen, onKeyboardSelect, {
|
|
83
|
+
direction: computed(() => props.direction),
|
|
84
|
+
searchValue: computed(() => props.searchValue || ""),
|
|
85
|
+
toggleOpen: props.toggleOpen,
|
|
86
|
+
open: computed(() => props.open)
|
|
87
|
+
}));
|
|
88
|
+
watch([() => activeValueCells.value, () => props.searchValue], () => {
|
|
89
|
+
if (props.searchValue) return;
|
|
90
|
+
nextTick(() => {
|
|
91
|
+
for (let i = 0; i < activeValueCells.value.length; i += 1) {
|
|
92
|
+
const cellKeyPath = toPathKey(activeValueCells.value.slice(0, i + 1));
|
|
93
|
+
const ele = containerRef.value?.querySelector(`li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, "\\\"")}"]`);
|
|
94
|
+
if (ele) scrollIntoParentView(ele);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}, { deep: true });
|
|
98
|
+
return () => {
|
|
99
|
+
const fieldNames = mergedFieldNames.value;
|
|
100
|
+
if (!fieldNames) return null;
|
|
101
|
+
const isEmpty = !optionColumns.value[0]?.options?.length;
|
|
102
|
+
const emptyList = [{
|
|
103
|
+
[fieldNames.value]: "__EMPTY__",
|
|
104
|
+
[FIX_LABEL]: props.notFoundContent,
|
|
105
|
+
disabled: true
|
|
106
|
+
}];
|
|
107
|
+
const columnProps = {
|
|
108
|
+
...props,
|
|
109
|
+
multiple: !isEmpty && props.multiple,
|
|
110
|
+
onSelect: onPathSelect,
|
|
111
|
+
onActive: onPathOpen,
|
|
112
|
+
onToggleOpen: props.toggleOpen,
|
|
113
|
+
checkedSet: checkedSet.value,
|
|
114
|
+
halfCheckedSet: halfCheckedSet.value,
|
|
115
|
+
loadingKeys: loadingKeys.value,
|
|
116
|
+
isSelectable
|
|
117
|
+
};
|
|
118
|
+
const columnNodes = (isEmpty ? [{ options: emptyList }] : optionColumns.value).map((col, index) => {
|
|
119
|
+
const prevValuePath = activeValueCells.value.slice(0, index);
|
|
120
|
+
const activeValue = activeValueCells.value[index];
|
|
121
|
+
return createVNode(Column_default, mergeProps({ "key": index }, columnProps, {
|
|
122
|
+
"prefixCls": mergedPrefixCls.value,
|
|
123
|
+
"options": col.options,
|
|
124
|
+
"prevValuePath": prevValuePath,
|
|
125
|
+
"activeValue": activeValue
|
|
126
|
+
}), null);
|
|
127
|
+
});
|
|
128
|
+
return createVNode(CacheContent_default, { "open": props.open }, { default: () => [createVNode("div", {
|
|
129
|
+
"class": clsx(`${mergedPrefixCls.value}-menus`, {
|
|
130
|
+
[`${mergedPrefixCls.value}-menu-empty`]: isEmpty,
|
|
131
|
+
[`${mergedPrefixCls.value}-rtl`]: rtl.value
|
|
132
|
+
}),
|
|
133
|
+
"ref": containerRef
|
|
134
|
+
}, [columnNodes])] });
|
|
135
|
+
};
|
|
136
|
+
}, {
|
|
137
|
+
props: /* @__PURE__ */ mergeDefaults({
|
|
138
|
+
prefixCls: {
|
|
139
|
+
type: String,
|
|
140
|
+
required: true,
|
|
141
|
+
default: void 0
|
|
142
|
+
},
|
|
143
|
+
multiple: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
required: false,
|
|
146
|
+
default: void 0
|
|
147
|
+
},
|
|
148
|
+
searchValue: {
|
|
149
|
+
type: String,
|
|
150
|
+
required: false,
|
|
151
|
+
default: void 0
|
|
152
|
+
},
|
|
153
|
+
toggleOpen: {
|
|
154
|
+
type: Function,
|
|
155
|
+
required: true,
|
|
156
|
+
default: void 0
|
|
157
|
+
},
|
|
158
|
+
notFoundContent: {
|
|
159
|
+
required: false,
|
|
160
|
+
default: void 0
|
|
161
|
+
},
|
|
162
|
+
direction: {
|
|
163
|
+
type: String,
|
|
164
|
+
required: false,
|
|
165
|
+
default: void 0
|
|
166
|
+
},
|
|
167
|
+
open: {
|
|
168
|
+
type: Boolean,
|
|
169
|
+
required: false,
|
|
170
|
+
default: void 0
|
|
171
|
+
},
|
|
172
|
+
disabled: {
|
|
173
|
+
type: Boolean,
|
|
174
|
+
required: false,
|
|
175
|
+
default: void 0
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
prefixCls: "",
|
|
179
|
+
multiple: false,
|
|
180
|
+
searchValue: "",
|
|
181
|
+
toggleOpen: () => {},
|
|
182
|
+
open: false,
|
|
183
|
+
direction: "ltr",
|
|
184
|
+
disabled: false
|
|
185
|
+
}),
|
|
186
|
+
name: "RawOptionList",
|
|
187
|
+
inheritAttrs: false
|
|
188
|
+
});
|
|
189
|
+
export { List_default as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import List_default from "./List.js";
|
|
2
|
+
import { createVNode, defineComponent, mergeProps, shallowRef } from "vue";
|
|
3
|
+
import { useBaseProps } from "@v-c/select";
|
|
4
|
+
var OptionList_default = /* @__PURE__ */ defineComponent((_, { expose }) => {
|
|
5
|
+
const baseProps = useBaseProps();
|
|
6
|
+
const listRef = shallowRef(null);
|
|
7
|
+
expose({
|
|
8
|
+
onKeyDown: (event) => listRef.value?.onKeyDown(event),
|
|
9
|
+
onKeyUp: (event) => listRef.value?.onKeyUp(event)
|
|
10
|
+
});
|
|
11
|
+
return () => createVNode(List_default, mergeProps(baseProps.value || {}, { "ref": (el) => {
|
|
12
|
+
listRef.value = el;
|
|
13
|
+
} }), null);
|
|
14
|
+
}, {
|
|
15
|
+
name: "OptionList",
|
|
16
|
+
inheritAttrs: false
|
|
17
|
+
});
|
|
18
|
+
export { OptionList_default as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { LegacyKey } from '../Cascader';
|
|
3
|
+
/**
|
|
4
|
+
* Control the active open options path.
|
|
5
|
+
*/
|
|
6
|
+
declare function useActive(multiple: Ref<boolean>, open: Ref<boolean | undefined>): [Ref<LegacyKey[]>, (activeValueCells: LegacyKey[]) => void];
|
|
7
|
+
export default useActive;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCascaderContext } from "../context.js";
|
|
2
|
+
import { ref, watch } from "vue";
|
|
3
|
+
function useActive(multiple, open) {
|
|
4
|
+
const context = useCascaderContext();
|
|
5
|
+
const activeValueCells = ref([]);
|
|
6
|
+
watch([open, () => context.value?.values?.[0]], () => {
|
|
7
|
+
if (!multiple.value) activeValueCells.value = context.value?.values?.[0] || [];
|
|
8
|
+
}, { immediate: true });
|
|
9
|
+
return [activeValueCells, (next) => {
|
|
10
|
+
activeValueCells.value = next;
|
|
11
|
+
}];
|
|
12
|
+
}
|
|
13
|
+
var useActive_default = useActive;
|
|
14
|
+
export { useActive_default as default };
|
|
@@ -0,0 +1,108 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RefOptionListProps } from '@v-c/select';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { DefaultOptionType, InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
|
|
4
|
+
export default function useKeyboard(options: Ref<DefaultOptionType[]>, fieldNames: Ref<InternalFieldNames>, activeValueCells: Ref<LegacyKey[]>, setActiveValueCells: (activeValueCells: LegacyKey[]) => void, onKeyBoardSelect: (valueCells: SingleValueType, option: DefaultOptionType) => void, contextProps: {
|
|
5
|
+
direction: Ref<'ltr' | 'rtl' | undefined>;
|
|
6
|
+
searchValue: Ref<string>;
|
|
7
|
+
toggleOpen: (open?: boolean) => void;
|
|
8
|
+
open: Ref<boolean | undefined>;
|
|
9
|
+
}): RefOptionListProps;
|