@v-c/select 1.0.9 → 1.0.10
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/dist/BaseSelect/index.js +9 -4
- package/dist/SelectInput/Content/SingleContent.js +32 -26
- package/dist/hooks/useBaseProps.d.ts +1 -0
- package/dist/hooks/useOpen.d.ts +1 -1
- package/dist/hooks/useOpen.js +3 -2
- package/package.json +4 -4
- package/dist/BaseSelect/Polite.cjs +0 -40
- package/dist/BaseSelect/index.cjs +0 -778
- package/dist/OptGroup.cjs +0 -8
- package/dist/Option.cjs +0 -8
- package/dist/OptionList.cjs +0 -258
- package/dist/Select.cjs +0 -838
- package/dist/SelectContext.cjs +0 -12
- package/dist/SelectInput/Affix.cjs +0 -19
- package/dist/SelectInput/Content/MultipleContent.cjs +0 -145
- package/dist/SelectInput/Content/Placeholder.cjs +0 -36
- package/dist/SelectInput/Content/SingleContent.cjs +0 -83
- package/dist/SelectInput/Content/index.cjs +0 -43
- package/dist/SelectInput/Input.cjs +0 -179
- package/dist/SelectInput/context.cjs +0 -12
- package/dist/SelectInput/index.cjs +0 -341
- package/dist/SelectTrigger.cjs +0 -198
- package/dist/TransBtn.cjs +0 -72
- package/dist/_virtual/rolldown_runtime.cjs +0 -21
- package/dist/hooks/index.cjs +0 -24
- package/dist/hooks/useAllowClear.cjs +0 -18
- package/dist/hooks/useBaseProps.cjs +0 -15
- package/dist/hooks/useCache.cjs +0 -39
- package/dist/hooks/useComponents.cjs +0 -18
- package/dist/hooks/useFilterOptions.cjs +0 -42
- package/dist/hooks/useLock.cjs +0 -29
- package/dist/hooks/useOpen.cjs +0 -63
- package/dist/hooks/useOptions.cjs +0 -41
- package/dist/hooks/useRefFunc.cjs +0 -15
- package/dist/hooks/useSearchConfig.cjs +0 -26
- package/dist/hooks/useSelectTriggerControl.cjs +0 -26
- package/dist/index.cjs +0 -22
- package/dist/interface.cjs +0 -1
- package/dist/utils/commonUtil.cjs +0 -38
- package/dist/utils/keyUtil.cjs +0 -37
- package/dist/utils/legacyUtil.cjs +0 -33
- package/dist/utils/platformUtil.cjs +0 -6
- package/dist/utils/valueUtil.cjs +0 -80
package/dist/OptGroup.cjs
DELETED
package/dist/Option.cjs
DELETED
package/dist/OptionList.cjs
DELETED
|
@@ -1,258 +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_useBaseProps = require("./hooks/useBaseProps.cjs");
|
|
7
|
-
const require_SelectContext = require("./SelectContext.cjs");
|
|
8
|
-
const require_TransBtn = require("./TransBtn.cjs");
|
|
9
|
-
const require_platformUtil = require("./utils/platformUtil.cjs");
|
|
10
|
-
const require_valueUtil = require("./utils/valueUtil.cjs");
|
|
11
|
-
let vue = require("vue");
|
|
12
|
-
let _v_c_util = require("@v-c/util");
|
|
13
|
-
let _v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
14
|
-
_v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(_v_c_util_dist_KeyCode);
|
|
15
|
-
let _v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
|
|
16
|
-
_v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(_v_c_util_dist_pickAttrs);
|
|
17
|
-
let _v_c_virtual_list = require("@v-c/virtual-list");
|
|
18
|
-
_v_c_virtual_list = require_rolldown_runtime.__toESM(_v_c_virtual_list);
|
|
19
|
-
function isTitleType(content) {
|
|
20
|
-
return typeof content === "string" || typeof content === "number";
|
|
21
|
-
}
|
|
22
|
-
var OptionList = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
23
|
-
name: "OptionList",
|
|
24
|
-
inheritAttrs: false,
|
|
25
|
-
setup(_, { expose }) {
|
|
26
|
-
const baseProps = require_useBaseProps.default();
|
|
27
|
-
const context = require_SelectContext.useSelectContext();
|
|
28
|
-
const itemPrefixCls = (0, vue.computed)(() => `${baseProps.value?.prefixCls}-item`);
|
|
29
|
-
const memoFlattenOptions = (0, vue.computed)(() => {
|
|
30
|
-
if (!baseProps.value?.open) return context.value?.flattenOptions || [];
|
|
31
|
-
return context.value?.flattenOptions || [];
|
|
32
|
-
});
|
|
33
|
-
const listRef = (0, vue.shallowRef)(null);
|
|
34
|
-
const overMaxCount = (0, vue.computed)(() => {
|
|
35
|
-
const { maxCount, rawValues } = context.value || {};
|
|
36
|
-
return !!(baseProps.value?.multiple && require_valueUtil.isValidCount(maxCount) && rawValues && rawValues.size >= maxCount);
|
|
37
|
-
});
|
|
38
|
-
const onListMouseDown = (event) => {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
};
|
|
41
|
-
const scrollIntoView = (args) => {
|
|
42
|
-
listRef.value?.scrollTo(typeof args === "number" ? { index: args } : args);
|
|
43
|
-
};
|
|
44
|
-
const isSelected = (value) => {
|
|
45
|
-
if (baseProps.value?.mode === "combobox") return false;
|
|
46
|
-
return context.value?.rawValues?.has(value) || false;
|
|
47
|
-
};
|
|
48
|
-
const getEnabledActiveIndex = (index, offset = 1) => {
|
|
49
|
-
const len = memoFlattenOptions.value.length;
|
|
50
|
-
for (let i = 0; i < len; i += 1) {
|
|
51
|
-
const current = (index + i * offset + len) % len;
|
|
52
|
-
const { group, data } = memoFlattenOptions.value[current] || {};
|
|
53
|
-
if (!group && !data?.disabled && (isSelected(data?.value) || !overMaxCount.value)) return current;
|
|
54
|
-
}
|
|
55
|
-
return -1;
|
|
56
|
-
};
|
|
57
|
-
const activeIndex = (0, vue.shallowRef)(-1);
|
|
58
|
-
const setActive = (index, fromKeyboard = false) => {
|
|
59
|
-
activeIndex.value = index;
|
|
60
|
-
const info = { source: fromKeyboard ? "keyboard" : "mouse" };
|
|
61
|
-
const flattenItem = memoFlattenOptions.value[index];
|
|
62
|
-
if (!flattenItem) {
|
|
63
|
-
context.value?.onActiveValue?.(null, -1, info);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
context.value?.onActiveValue?.(flattenItem.value, index, info);
|
|
67
|
-
};
|
|
68
|
-
(0, vue.watch)([() => memoFlattenOptions.value.length, () => baseProps.value?.searchValue], () => {
|
|
69
|
-
setActive(context.value?.defaultActiveFirstOption !== false ? getEnabledActiveIndex(0) : -1);
|
|
70
|
-
}, { immediate: true });
|
|
71
|
-
const isAriaSelected = (value) => {
|
|
72
|
-
if (baseProps.value?.mode === "combobox") return String(value).toLowerCase() === (baseProps.value?.searchValue || "").toLowerCase();
|
|
73
|
-
return context.value?.rawValues?.has(value) || false;
|
|
74
|
-
};
|
|
75
|
-
(0, vue.watch)([() => baseProps.value?.open, () => baseProps.value?.searchValue], () => {
|
|
76
|
-
let timeoutId;
|
|
77
|
-
const rawValues = context.value?.rawValues;
|
|
78
|
-
if (!baseProps.value?.multiple && baseProps.value?.open && rawValues?.size === 1) {
|
|
79
|
-
const value = Array.from(rawValues)[0];
|
|
80
|
-
const searchValue = baseProps.value?.searchValue;
|
|
81
|
-
const index = memoFlattenOptions.value.findIndex(({ data }) => searchValue ? String(data.value).startsWith(searchValue) : data.value === value);
|
|
82
|
-
if (index !== -1) {
|
|
83
|
-
setActive(index);
|
|
84
|
-
timeoutId = setTimeout(() => {
|
|
85
|
-
scrollIntoView(index);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (baseProps.value?.open) listRef.value?.scrollTo(void 0);
|
|
90
|
-
return () => {
|
|
91
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
const onSelectValue = (value) => {
|
|
95
|
-
if (value !== void 0) context.value?.onSelect?.(value, { selected: !context.value?.rawValues?.has(value) });
|
|
96
|
-
if (!baseProps.value?.multiple) baseProps.value?.toggleOpen?.(false);
|
|
97
|
-
};
|
|
98
|
-
const onKeyDown = (event) => {
|
|
99
|
-
const { which, ctrlKey } = event;
|
|
100
|
-
switch (which) {
|
|
101
|
-
case _v_c_util_dist_KeyCode.default.N:
|
|
102
|
-
case _v_c_util_dist_KeyCode.default.P:
|
|
103
|
-
case _v_c_util_dist_KeyCode.default.UP:
|
|
104
|
-
case _v_c_util_dist_KeyCode.default.DOWN: {
|
|
105
|
-
let offset = 0;
|
|
106
|
-
if (which === _v_c_util_dist_KeyCode.default.UP) offset = -1;
|
|
107
|
-
else if (which === _v_c_util_dist_KeyCode.default.DOWN) offset = 1;
|
|
108
|
-
else if (require_platformUtil.isPlatformMac() && ctrlKey) {
|
|
109
|
-
if (which === _v_c_util_dist_KeyCode.default.N) offset = 1;
|
|
110
|
-
else if (which === _v_c_util_dist_KeyCode.default.P) offset = -1;
|
|
111
|
-
}
|
|
112
|
-
if (offset !== 0) {
|
|
113
|
-
const nextActiveIndex = getEnabledActiveIndex(activeIndex.value + offset, offset);
|
|
114
|
-
scrollIntoView(nextActiveIndex);
|
|
115
|
-
setActive(nextActiveIndex, true);
|
|
116
|
-
}
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
case _v_c_util_dist_KeyCode.default.TAB:
|
|
120
|
-
case _v_c_util_dist_KeyCode.default.ENTER: {
|
|
121
|
-
const item = memoFlattenOptions.value[activeIndex.value];
|
|
122
|
-
if (!item || item.data.disabled) {
|
|
123
|
-
onSelectValue(void 0);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (!overMaxCount.value || context.value?.rawValues?.has(item.value)) onSelectValue(item.value);
|
|
127
|
-
else onSelectValue(void 0);
|
|
128
|
-
if (baseProps.value?.open) event.preventDefault();
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
case _v_c_util_dist_KeyCode.default.ESC:
|
|
132
|
-
baseProps.value?.toggleOpen?.(false);
|
|
133
|
-
if (baseProps.value?.open) event.stopPropagation();
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const onKeyUp = () => {};
|
|
137
|
-
expose({
|
|
138
|
-
onKeyDown,
|
|
139
|
-
onKeyUp,
|
|
140
|
-
scrollTo: (index) => {
|
|
141
|
-
scrollIntoView(index);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return () => {
|
|
145
|
-
const { id, notFoundContent, onPopupScroll } = baseProps.value || {};
|
|
146
|
-
const { menuItemSelectedIcon, fieldNames, virtual, direction, listHeight, listItemHeight, optionRender, classNames: contextClassNames, styles: contextStyles } = context.value || {};
|
|
147
|
-
if (memoFlattenOptions.value.length === 0) return (0, vue.createVNode)("div", {
|
|
148
|
-
"role": "listbox",
|
|
149
|
-
"id": `${id}_list`,
|
|
150
|
-
"class": `${itemPrefixCls.value}-empty`,
|
|
151
|
-
"onMousedown": onListMouseDown
|
|
152
|
-
}, [notFoundContent]);
|
|
153
|
-
const omitFieldNameList = Object.keys(fieldNames || {}).map((key) => fieldNames?.[key]);
|
|
154
|
-
const getLabel = (item) => item.label;
|
|
155
|
-
function getItemAriaProps(item, index) {
|
|
156
|
-
const { group } = item;
|
|
157
|
-
return {
|
|
158
|
-
role: group ? "presentation" : "option",
|
|
159
|
-
id: `${id}_list_${index}`
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const renderItem = (index) => {
|
|
163
|
-
const item = memoFlattenOptions.value[index];
|
|
164
|
-
if (!item) return null;
|
|
165
|
-
const itemData = item.data || {};
|
|
166
|
-
const { value } = itemData;
|
|
167
|
-
const { group } = item;
|
|
168
|
-
const attrs = (0, _v_c_util_dist_pickAttrs.default)(itemData, true);
|
|
169
|
-
const mergedLabel = getLabel(item);
|
|
170
|
-
return item ? (0, vue.createVNode)("div", (0, vue.mergeProps)({ "aria-label": typeof mergedLabel === "string" && !group ? mergedLabel : void 0 }, attrs, { "key": index }, getItemAriaProps(item, index), { "aria-selected": isAriaSelected(value) }), [value]) : null;
|
|
171
|
-
};
|
|
172
|
-
const a11yProps = {
|
|
173
|
-
role: "listbox",
|
|
174
|
-
id: `${id}_list`
|
|
175
|
-
};
|
|
176
|
-
return (0, vue.createVNode)(vue.Fragment, null, [virtual && (0, vue.createVNode)("div", (0, vue.mergeProps)(a11yProps, { "style": {
|
|
177
|
-
height: 0,
|
|
178
|
-
width: 0,
|
|
179
|
-
overflow: "hidden"
|
|
180
|
-
} }), [
|
|
181
|
-
renderItem(activeIndex.value - 1),
|
|
182
|
-
renderItem(activeIndex.value),
|
|
183
|
-
renderItem(activeIndex.value + 1)
|
|
184
|
-
]), (0, vue.createVNode)(_v_c_virtual_list.default, (0, vue.mergeProps)({
|
|
185
|
-
"itemKey": "key",
|
|
186
|
-
"ref": (el) => {
|
|
187
|
-
listRef.value = el;
|
|
188
|
-
},
|
|
189
|
-
"data": memoFlattenOptions.value,
|
|
190
|
-
"height": listHeight,
|
|
191
|
-
"itemHeight": listItemHeight,
|
|
192
|
-
"fullHeight": false
|
|
193
|
-
}, { onMousedown: onListMouseDown }, {
|
|
194
|
-
"onScroll": onPopupScroll,
|
|
195
|
-
"virtual": virtual,
|
|
196
|
-
"direction": direction,
|
|
197
|
-
"innerProps": virtual ? void 0 : a11yProps,
|
|
198
|
-
"class": contextClassNames?.popup?.list,
|
|
199
|
-
"style": contextStyles?.popup?.list
|
|
200
|
-
}), { default: ({ item, index: itemIndex }) => {
|
|
201
|
-
const { group, groupOption, data, label, value } = item;
|
|
202
|
-
const { key } = data;
|
|
203
|
-
if (group) {
|
|
204
|
-
const groupTitle = data.title ?? (isTitleType(label) ? label.toString() : void 0);
|
|
205
|
-
return (0, vue.createVNode)("div", {
|
|
206
|
-
"class": (0, _v_c_util.clsx)(itemPrefixCls.value, `${itemPrefixCls.value}-group`, data.className),
|
|
207
|
-
"title": groupTitle
|
|
208
|
-
}, [label !== void 0 ? label : key]);
|
|
209
|
-
}
|
|
210
|
-
const { disabled, title, children, style, className, ...otherProps } = data;
|
|
211
|
-
const passedProps = {};
|
|
212
|
-
Object.keys(otherProps).forEach((propKey) => {
|
|
213
|
-
if (!omitFieldNameList.includes(propKey)) passedProps[propKey] = otherProps[propKey];
|
|
214
|
-
});
|
|
215
|
-
const selected = isSelected(value);
|
|
216
|
-
const mergedDisabled = disabled || !selected && overMaxCount.value;
|
|
217
|
-
const optionPrefixCls = `${itemPrefixCls.value}-option`;
|
|
218
|
-
const optionClassName = (0, _v_c_util.clsx)(itemPrefixCls.value, optionPrefixCls, className, contextClassNames?.popup?.listItem, {
|
|
219
|
-
[`${optionPrefixCls}-grouped`]: groupOption,
|
|
220
|
-
[`${optionPrefixCls}-active`]: activeIndex.value === itemIndex && !mergedDisabled,
|
|
221
|
-
[`${optionPrefixCls}-disabled`]: mergedDisabled,
|
|
222
|
-
[`${optionPrefixCls}-selected`]: selected
|
|
223
|
-
});
|
|
224
|
-
const mergedLabel = getLabel(item);
|
|
225
|
-
const iconVisible = !menuItemSelectedIcon || typeof menuItemSelectedIcon === "function" || selected;
|
|
226
|
-
const content = typeof mergedLabel === "number" ? mergedLabel : mergedLabel || value;
|
|
227
|
-
let optionTitle = isTitleType(content) ? content.toString() : void 0;
|
|
228
|
-
if (title !== void 0) optionTitle = title;
|
|
229
|
-
return (0, vue.createVNode)("div", (0, vue.mergeProps)((0, _v_c_util_dist_pickAttrs.default)(passedProps), !virtual ? getItemAriaProps(item, itemIndex) : {}, {
|
|
230
|
-
"aria-selected": virtual ? void 0 : isAriaSelected(value),
|
|
231
|
-
"class": optionClassName,
|
|
232
|
-
"title": optionTitle,
|
|
233
|
-
"onMousemove": () => {
|
|
234
|
-
if (activeIndex.value === itemIndex || mergedDisabled) return;
|
|
235
|
-
setActive(itemIndex);
|
|
236
|
-
},
|
|
237
|
-
"onClick": () => {
|
|
238
|
-
if (!mergedDisabled) onSelectValue(value);
|
|
239
|
-
},
|
|
240
|
-
"style": {
|
|
241
|
-
...contextStyles?.popup?.listItem,
|
|
242
|
-
...style
|
|
243
|
-
}
|
|
244
|
-
}), [(0, vue.createVNode)("div", { "class": `${optionPrefixCls}-content` }, [typeof optionRender === "function" ? optionRender(item, { index: itemIndex }) : content]), iconVisible && (0, vue.createVNode)(require_TransBtn.default, {
|
|
245
|
-
"className": `${itemPrefixCls.value}-option-state`,
|
|
246
|
-
"customizeIcon": menuItemSelectedIcon,
|
|
247
|
-
"customizeIconProps": {
|
|
248
|
-
value,
|
|
249
|
-
disabled: mergedDisabled,
|
|
250
|
-
isSelected: selected
|
|
251
|
-
}
|
|
252
|
-
}, { default: () => [selected ? "✓" : null] })]);
|
|
253
|
-
} })]);
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
var OptionList_default = OptionList;
|
|
258
|
-
exports.default = OptionList_default;
|