@v-c/select 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/BaseSelect/Polite.cjs +37 -0
- package/dist/BaseSelect/Polite.d.ts +7 -0
- package/dist/BaseSelect/Polite.js +34 -0
- package/dist/BaseSelect/index.cjs +763 -0
- package/dist/BaseSelect/index.d.ts +133 -0
- package/dist/BaseSelect/index.js +759 -0
- package/dist/OptGroup.cjs +5 -0
- package/dist/OptGroup.d.ts +6 -0
- package/dist/OptGroup.js +4 -0
- package/dist/Option.cjs +5 -0
- package/dist/Option.d.ts +8 -0
- package/dist/Option.js +4 -0
- package/dist/OptionList.cjs +255 -0
- package/dist/OptionList.d.ts +17 -0
- package/dist/OptionList.js +249 -0
- package/dist/Select.cjs +833 -0
- package/dist/Select.d.ts +96 -0
- package/dist/Select.js +828 -0
- package/dist/SelectContext.cjs +11 -0
- package/dist/SelectContext.d.ts +32 -0
- package/dist/SelectContext.js +9 -0
- package/dist/SelectInput/Affix.cjs +16 -0
- package/dist/SelectInput/Affix.d.ts +2 -0
- package/dist/SelectInput/Affix.js +13 -0
- package/dist/SelectInput/Content/MultipleContent.cjs +142 -0
- package/dist/SelectInput/Content/MultipleContent.d.ts +3 -0
- package/dist/SelectInput/Content/MultipleContent.js +138 -0
- package/dist/SelectInput/Content/Placeholder.cjs +33 -0
- package/dist/SelectInput/Content/Placeholder.d.ts +5 -0
- package/dist/SelectInput/Content/Placeholder.js +30 -0
- package/dist/SelectInput/Content/SingleContent.cjs +80 -0
- package/dist/SelectInput/Content/SingleContent.d.ts +3 -0
- package/dist/SelectInput/Content/SingleContent.js +77 -0
- package/dist/SelectInput/Content/index.cjs +40 -0
- package/dist/SelectInput/Content/index.d.ts +6 -0
- package/dist/SelectInput/Content/index.js +36 -0
- package/dist/SelectInput/Input.cjs +176 -0
- package/dist/SelectInput/Input.d.ts +22 -0
- package/dist/SelectInput/Input.js +173 -0
- package/dist/SelectInput/context.cjs +11 -0
- package/dist/SelectInput/context.d.ts +5 -0
- package/dist/SelectInput/context.js +9 -0
- package/dist/SelectInput/index.cjs +330 -0
- package/dist/SelectInput/index.d.ts +44 -0
- package/dist/SelectInput/index.js +325 -0
- package/dist/SelectTrigger.cjs +189 -0
- package/dist/SelectTrigger.d.ts +26 -0
- package/dist/SelectTrigger.js +185 -0
- package/dist/TransBtn.cjs +69 -0
- package/dist/TransBtn.d.ts +22 -0
- package/dist/TransBtn.js +66 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/index.cjs +23 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/useAllowClear.cjs +17 -0
- package/dist/hooks/useAllowClear.d.ts +9 -0
- package/dist/hooks/useAllowClear.js +16 -0
- package/dist/hooks/useBaseProps.cjs +12 -0
- package/dist/hooks/useBaseProps.d.ts +10 -0
- package/dist/hooks/useBaseProps.js +9 -0
- package/dist/hooks/useCache.cjs +36 -0
- package/dist/hooks/useCache.d.ts +7 -0
- package/dist/hooks/useCache.js +34 -0
- package/dist/hooks/useComponents.cjs +15 -0
- package/dist/hooks/useComponents.d.ts +8 -0
- package/dist/hooks/useComponents.js +13 -0
- package/dist/hooks/useFilterOptions.cjs +39 -0
- package/dist/hooks/useFilterOptions.d.ts +3 -0
- package/dist/hooks/useFilterOptions.js +37 -0
- package/dist/hooks/useLock.cjs +26 -0
- package/dist/hooks/useLock.d.ts +1 -0
- package/dist/hooks/useLock.js +24 -0
- package/dist/hooks/useOpen.cjs +58 -0
- package/dist/hooks/useOpen.d.ts +19 -0
- package/dist/hooks/useOpen.js +56 -0
- package/dist/hooks/useOptions.cjs +38 -0
- package/dist/hooks/useOptions.d.ts +13 -0
- package/dist/hooks/useOptions.js +36 -0
- package/dist/hooks/useRefFunc.cjs +12 -0
- package/dist/hooks/useRefFunc.d.ts +6 -0
- package/dist/hooks/useRefFunc.js +10 -0
- package/dist/hooks/useSearchConfig.cjs +21 -0
- package/dist/hooks/useSearchConfig.d.ts +11 -0
- package/dist/hooks/useSearchConfig.js +19 -0
- package/dist/hooks/useSelectTriggerControl.cjs +18 -0
- package/dist/hooks/useSelectTriggerControl.d.ts +2 -0
- package/dist/hooks/useSelectTriggerControl.js +16 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/interface.cjs +0 -0
- package/dist/interface.d.ts +23 -0
- package/dist/interface.js +0 -0
- package/dist/utils/commonUtil.cjs +37 -0
- package/dist/utils/commonUtil.d.ts +12 -0
- package/dist/utils/commonUtil.js +30 -0
- package/dist/utils/keyUtil.cjs +36 -0
- package/dist/utils/keyUtil.d.ts +2 -0
- package/dist/utils/keyUtil.js +34 -0
- package/dist/utils/legacyUtil.cjs +32 -0
- package/dist/utils/legacyUtil.d.ts +3 -0
- package/dist/utils/legacyUtil.js +31 -0
- package/dist/utils/platformUtil.cjs +5 -0
- package/dist/utils/platformUtil.d.ts +1 -0
- package/dist/utils/platformUtil.js +5 -0
- package/dist/utils/valueUtil.cjs +79 -0
- package/dist/utils/valueUtil.d.ts +18 -0
- package/dist/utils/valueUtil.js +75 -0
- package/package.json +43 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
var BaseSelectContext = Symbol("BaseSelectContext");
|
|
5
|
+
function useBaseSelectProvider(context) {
|
|
6
|
+
(0, vue.provide)(BaseSelectContext, context);
|
|
7
|
+
}
|
|
8
|
+
function useBaseProps() {
|
|
9
|
+
return (0, vue.inject)(BaseSelectContext, (0, vue.ref)(null));
|
|
10
|
+
}
|
|
11
|
+
exports.default = useBaseProps;
|
|
12
|
+
exports.useBaseSelectProvider = useBaseSelectProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { BaseSelectProps } from '../BaseSelect';
|
|
3
|
+
export interface BaseSelectContextProps extends BaseSelectProps {
|
|
4
|
+
triggerOpen: boolean;
|
|
5
|
+
multiple: boolean;
|
|
6
|
+
toggleOpen: (open?: boolean) => void;
|
|
7
|
+
role?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function useBaseSelectProvider(context: Ref<BaseSelectContextProps>): void;
|
|
10
|
+
export default function useBaseProps(): Ref<BaseSelectContextProps | null>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { inject, provide, ref } from "vue";
|
|
2
|
+
var BaseSelectContext = Symbol("BaseSelectContext");
|
|
3
|
+
function useBaseSelectProvider(context) {
|
|
4
|
+
provide(BaseSelectContext, context);
|
|
5
|
+
}
|
|
6
|
+
function useBaseProps() {
|
|
7
|
+
return inject(BaseSelectContext, ref(null));
|
|
8
|
+
}
|
|
9
|
+
export { useBaseProps as default, useBaseSelectProvider };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useCache(labeledValues, valueOptions) {
|
|
5
|
+
const cacheRef = (0, vue.shallowRef)({
|
|
6
|
+
values: /* @__PURE__ */ new Map(),
|
|
7
|
+
options: /* @__PURE__ */ new Map()
|
|
8
|
+
});
|
|
9
|
+
const filledLabeledValues = (0, vue.computed)(() => {
|
|
10
|
+
const { values: prevValueCache, options: prevOptionCache } = cacheRef.value;
|
|
11
|
+
const patchedValues = labeledValues.value.map((item) => {
|
|
12
|
+
if (item.label === void 0) return {
|
|
13
|
+
...item,
|
|
14
|
+
label: prevValueCache.get(item.value)?.label
|
|
15
|
+
};
|
|
16
|
+
return item;
|
|
17
|
+
});
|
|
18
|
+
const valueCache = /* @__PURE__ */ new Map();
|
|
19
|
+
const optionCache = /* @__PURE__ */ new Map();
|
|
20
|
+
patchedValues.forEach((item) => {
|
|
21
|
+
valueCache.set(item.value, item);
|
|
22
|
+
const option = valueOptions.value.get(item.value) || prevOptionCache.get(item.value);
|
|
23
|
+
if (option) optionCache.set(item.value, option);
|
|
24
|
+
});
|
|
25
|
+
cacheRef.value = {
|
|
26
|
+
values: valueCache,
|
|
27
|
+
options: optionCache
|
|
28
|
+
};
|
|
29
|
+
return patchedValues;
|
|
30
|
+
});
|
|
31
|
+
const getOption = (val) => {
|
|
32
|
+
return valueOptions.value.get(val) || cacheRef.value.options.get(val);
|
|
33
|
+
};
|
|
34
|
+
return [filledLabeledValues, getOption];
|
|
35
|
+
}
|
|
36
|
+
exports.default = useCache;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { RawValueType } from '../interface';
|
|
3
|
+
import { DefaultOptionType, LabelInValueType } from '../Select';
|
|
4
|
+
/**
|
|
5
|
+
* Cache `value` related LabeledValue & options.
|
|
6
|
+
*/
|
|
7
|
+
export default function useCache(labeledValues: Ref<LabelInValueType[]>, valueOptions: Ref<Map<RawValueType, DefaultOptionType>>): [Ref<LabelInValueType[]>, (val: RawValueType) => DefaultOptionType | undefined];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { computed, shallowRef } from "vue";
|
|
2
|
+
function useCache(labeledValues, valueOptions) {
|
|
3
|
+
const cacheRef = shallowRef({
|
|
4
|
+
values: /* @__PURE__ */ new Map(),
|
|
5
|
+
options: /* @__PURE__ */ new Map()
|
|
6
|
+
});
|
|
7
|
+
const filledLabeledValues = computed(() => {
|
|
8
|
+
const { values: prevValueCache, options: prevOptionCache } = cacheRef.value;
|
|
9
|
+
const patchedValues = labeledValues.value.map((item) => {
|
|
10
|
+
if (item.label === void 0) return {
|
|
11
|
+
...item,
|
|
12
|
+
label: prevValueCache.get(item.value)?.label
|
|
13
|
+
};
|
|
14
|
+
return item;
|
|
15
|
+
});
|
|
16
|
+
const valueCache = /* @__PURE__ */ new Map();
|
|
17
|
+
const optionCache = /* @__PURE__ */ new Map();
|
|
18
|
+
patchedValues.forEach((item) => {
|
|
19
|
+
valueCache.set(item.value, item);
|
|
20
|
+
const option = valueOptions.value.get(item.value) || prevOptionCache.get(item.value);
|
|
21
|
+
if (option) optionCache.set(item.value, option);
|
|
22
|
+
});
|
|
23
|
+
cacheRef.value = {
|
|
24
|
+
values: valueCache,
|
|
25
|
+
options: optionCache
|
|
26
|
+
};
|
|
27
|
+
return patchedValues;
|
|
28
|
+
});
|
|
29
|
+
const getOption = (val) => {
|
|
30
|
+
return valueOptions.value.get(val) || cacheRef.value.options.get(val);
|
|
31
|
+
};
|
|
32
|
+
return [filledLabeledValues, getOption];
|
|
33
|
+
}
|
|
34
|
+
export { useCache as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useComponents(components, getInputElement, getRawInputElement) {
|
|
5
|
+
return (0, vue.computed)(() => {
|
|
6
|
+
let { root, input } = components.value || {};
|
|
7
|
+
if (getRawInputElement?.value) root = getRawInputElement.value?.();
|
|
8
|
+
if (getInputElement?.value) input = getInputElement.value?.();
|
|
9
|
+
return {
|
|
10
|
+
root,
|
|
11
|
+
input
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.default = useComponents;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { BaseSelectProps } from '../BaseSelect';
|
|
4
|
+
export interface ComponentsConfig {
|
|
5
|
+
root?: VueNode | string | any;
|
|
6
|
+
input?: VueNode | string | any;
|
|
7
|
+
}
|
|
8
|
+
export default function useComponents(components: Ref<ComponentsConfig>, getInputElement?: Ref<BaseSelectProps['getInputElement']>, getRawInputElement?: Ref<BaseSelectProps['getRawInputElement']>): Ref<ComponentsConfig>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function useComponents(components, getInputElement, getRawInputElement) {
|
|
3
|
+
return computed(() => {
|
|
4
|
+
let { root, input } = components.value || {};
|
|
5
|
+
if (getRawInputElement?.value) root = getRawInputElement.value?.();
|
|
6
|
+
if (getInputElement?.value) input = getInputElement.value?.();
|
|
7
|
+
return {
|
|
8
|
+
root,
|
|
9
|
+
input
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export { useComponents as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_commonUtil = require("../utils/commonUtil.cjs");
|
|
4
|
+
let vue = require("vue");
|
|
5
|
+
function includes(test, search) {
|
|
6
|
+
return require_commonUtil.toArray(test).join("").toUpperCase().includes(search);
|
|
7
|
+
}
|
|
8
|
+
function useFilterOptions(options, fieldNames, searchValue, filterOption, optionFilterProp) {
|
|
9
|
+
return (0, vue.computed)(() => {
|
|
10
|
+
if (!searchValue.value || filterOption.value === false) return options.value;
|
|
11
|
+
const { options: fieldOptions, label: fieldLabel, value: fieldValue } = fieldNames.value;
|
|
12
|
+
const filteredOptions = [];
|
|
13
|
+
const customizeFilter = typeof filterOption.value === "function";
|
|
14
|
+
const upperSearch = searchValue.value.toUpperCase();
|
|
15
|
+
const defaultFilter = (_, option) => {
|
|
16
|
+
if (optionFilterProp.value && option) return includes(option[optionFilterProp.value], upperSearch);
|
|
17
|
+
if (option && option[fieldOptions]) return includes(option[fieldLabel !== "children" ? fieldLabel : "label"], upperSearch);
|
|
18
|
+
return option ? includes(option[fieldValue], upperSearch) : false;
|
|
19
|
+
};
|
|
20
|
+
const filterFunc = customizeFilter ? filterOption.value : defaultFilter;
|
|
21
|
+
const wrapOption = customizeFilter ? (opt) => require_commonUtil.injectPropsWithOption(opt) : (opt) => opt;
|
|
22
|
+
options.value.forEach((item) => {
|
|
23
|
+
if (item[fieldOptions]) {
|
|
24
|
+
if (filterFunc(searchValue.value, wrapOption(item))) filteredOptions.push(item);
|
|
25
|
+
else {
|
|
26
|
+
const subOptions = item[fieldOptions].filter((subItem) => filterFunc(searchValue.value, wrapOption(subItem)));
|
|
27
|
+
if (subOptions.length) filteredOptions.push({
|
|
28
|
+
...item,
|
|
29
|
+
[fieldOptions]: subOptions
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (filterFunc(searchValue.value, wrapOption(item))) filteredOptions.push(item);
|
|
35
|
+
});
|
|
36
|
+
return filteredOptions;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.default = useFilterOptions;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DefaultOptionType, FieldNames, SelectProps } from '../Select';
|
|
3
|
+
export default function useFilterOptions(options: Ref<DefaultOptionType[]>, fieldNames: Ref<FieldNames>, searchValue: Ref<string | undefined>, filterOption: Ref<SelectProps['filterOption']>, optionFilterProp: Ref<string | undefined>): import('vue').ComputedRef<DefaultOptionType[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { injectPropsWithOption, toArray } from "../utils/commonUtil.js";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
function includes(test, search) {
|
|
4
|
+
return toArray(test).join("").toUpperCase().includes(search);
|
|
5
|
+
}
|
|
6
|
+
function useFilterOptions(options, fieldNames, searchValue, filterOption, optionFilterProp) {
|
|
7
|
+
return computed(() => {
|
|
8
|
+
if (!searchValue.value || filterOption.value === false) return options.value;
|
|
9
|
+
const { options: fieldOptions, label: fieldLabel, value: fieldValue } = fieldNames.value;
|
|
10
|
+
const filteredOptions = [];
|
|
11
|
+
const customizeFilter = typeof filterOption.value === "function";
|
|
12
|
+
const upperSearch = searchValue.value.toUpperCase();
|
|
13
|
+
const defaultFilter = (_, option) => {
|
|
14
|
+
if (optionFilterProp.value && option) return includes(option[optionFilterProp.value], upperSearch);
|
|
15
|
+
if (option && option[fieldOptions]) return includes(option[fieldLabel !== "children" ? fieldLabel : "label"], upperSearch);
|
|
16
|
+
return option ? includes(option[fieldValue], upperSearch) : false;
|
|
17
|
+
};
|
|
18
|
+
const filterFunc = customizeFilter ? filterOption.value : defaultFilter;
|
|
19
|
+
const wrapOption = customizeFilter ? (opt) => injectPropsWithOption(opt) : (opt) => opt;
|
|
20
|
+
options.value.forEach((item) => {
|
|
21
|
+
if (item[fieldOptions]) {
|
|
22
|
+
if (filterFunc(searchValue.value, wrapOption(item))) filteredOptions.push(item);
|
|
23
|
+
else {
|
|
24
|
+
const subOptions = item[fieldOptions].filter((subItem) => filterFunc(searchValue.value, wrapOption(subItem)));
|
|
25
|
+
if (subOptions.length) filteredOptions.push({
|
|
26
|
+
...item,
|
|
27
|
+
[fieldOptions]: subOptions
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (filterFunc(searchValue.value, wrapOption(item))) filteredOptions.push(item);
|
|
33
|
+
});
|
|
34
|
+
return filteredOptions;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { useFilterOptions as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useLock(duration = 250) {
|
|
5
|
+
const lockRef = (0, vue.shallowRef)(null);
|
|
6
|
+
const timeoutRef = (0, vue.shallowRef)(null);
|
|
7
|
+
function cleanup() {
|
|
8
|
+
if (timeoutRef.value !== null) {
|
|
9
|
+
window.clearTimeout(timeoutRef.value);
|
|
10
|
+
timeoutRef.value = null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
(0, vue.onUnmounted)(() => {
|
|
14
|
+
cleanup();
|
|
15
|
+
});
|
|
16
|
+
function doLock(locked) {
|
|
17
|
+
if (locked || lockRef.value === null) lockRef.value = locked;
|
|
18
|
+
cleanup();
|
|
19
|
+
timeoutRef.value = window.setTimeout(() => {
|
|
20
|
+
lockRef.value = null;
|
|
21
|
+
timeoutRef.value = null;
|
|
22
|
+
}, duration);
|
|
23
|
+
}
|
|
24
|
+
return [() => !!lockRef.value, doLock];
|
|
25
|
+
}
|
|
26
|
+
exports.default = useLock;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useLock(duration?: number): [() => boolean, (lock: boolean) => void];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { onUnmounted, shallowRef } from "vue";
|
|
2
|
+
function useLock(duration = 250) {
|
|
3
|
+
const lockRef = shallowRef(null);
|
|
4
|
+
const timeoutRef = shallowRef(null);
|
|
5
|
+
function cleanup() {
|
|
6
|
+
if (timeoutRef.value !== null) {
|
|
7
|
+
window.clearTimeout(timeoutRef.value);
|
|
8
|
+
timeoutRef.value = null;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
onUnmounted(() => {
|
|
12
|
+
cleanup();
|
|
13
|
+
});
|
|
14
|
+
function doLock(locked) {
|
|
15
|
+
if (locked || lockRef.value === null) lockRef.value = locked;
|
|
16
|
+
cleanup();
|
|
17
|
+
timeoutRef.value = window.setTimeout(() => {
|
|
18
|
+
lockRef.value = null;
|
|
19
|
+
timeoutRef.value = null;
|
|
20
|
+
}, duration);
|
|
21
|
+
}
|
|
22
|
+
return [() => !!lockRef.value, doLock];
|
|
23
|
+
}
|
|
24
|
+
export { useLock as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function internalMacroTask(fn) {
|
|
5
|
+
const channel = new MessageChannel();
|
|
6
|
+
channel.port1.onmessage = fn;
|
|
7
|
+
channel.port2.postMessage(null);
|
|
8
|
+
}
|
|
9
|
+
function macroTask(fn, times = 1) {
|
|
10
|
+
if (times <= 0) {
|
|
11
|
+
fn();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
internalMacroTask(() => {
|
|
15
|
+
macroTask(fn, times - 1);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function useOpen(propOpen, onOpen, postOpen) {
|
|
19
|
+
const rendered = (0, vue.shallowRef)(false);
|
|
20
|
+
(0, vue.onMounted)(() => {
|
|
21
|
+
rendered.value = true;
|
|
22
|
+
});
|
|
23
|
+
const stateOpen = (0, vue.shallowRef)(false);
|
|
24
|
+
(0, vue.watch)(propOpen, () => {
|
|
25
|
+
stateOpen.value = propOpen.value;
|
|
26
|
+
});
|
|
27
|
+
const ssrSafeOpen = (0, vue.computed)(() => rendered.value ? stateOpen.value : false);
|
|
28
|
+
const mergedOpen = (0, vue.computed)(() => postOpen(ssrSafeOpen.value));
|
|
29
|
+
const taskIdRef = (0, vue.shallowRef)(0);
|
|
30
|
+
const taskLockRef = (0, vue.shallowRef)(false);
|
|
31
|
+
const triggerEvent = (nextOpen) => {
|
|
32
|
+
if (onOpen && mergedOpen.value !== nextOpen) onOpen(nextOpen);
|
|
33
|
+
stateOpen.value = nextOpen;
|
|
34
|
+
};
|
|
35
|
+
const toggleOpen = (nextOpen, config = {}) => {
|
|
36
|
+
const { ignoreNext = false, lazy = false } = config;
|
|
37
|
+
taskIdRef.value += 1;
|
|
38
|
+
const id = taskIdRef.value;
|
|
39
|
+
const nextOpenVal = typeof nextOpen === "boolean" ? nextOpen : !mergedOpen.value;
|
|
40
|
+
if (nextOpenVal !== lazy) {
|
|
41
|
+
if (!taskLockRef.value) {
|
|
42
|
+
triggerEvent(nextOpenVal);
|
|
43
|
+
if (ignoreNext) {
|
|
44
|
+
taskLockRef.value = ignoreNext;
|
|
45
|
+
macroTask(() => {
|
|
46
|
+
taskLockRef.value = false;
|
|
47
|
+
}, 2);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
macroTask(() => {
|
|
53
|
+
if (id === taskIdRef.value && !taskLockRef.value) triggerEvent(nextOpenVal);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return [mergedOpen, toggleOpen];
|
|
57
|
+
}
|
|
58
|
+
exports.default = useOpen;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Trigger by latest open call, if nextOpen is undefined, means toggle.
|
|
4
|
+
* ignoreNext will skip next call in the macro task queue.
|
|
5
|
+
*/
|
|
6
|
+
export type TriggerOpenType = (nextOpen?: boolean, config?: {
|
|
7
|
+
ignoreNext?: boolean;
|
|
8
|
+
lazy?: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
/**
|
|
11
|
+
* When `open` is controlled, follow the controlled value;
|
|
12
|
+
* Otherwise use uncontrolled logic.
|
|
13
|
+
* Setting `open` takes effect immediately,
|
|
14
|
+
* but setting it to `false` is delayed via MessageChannel.
|
|
15
|
+
*
|
|
16
|
+
* SSR handling: During SSR, `open` is always false to avoid Portal issues.
|
|
17
|
+
* On client-side hydration, it syncs with the actual open state.
|
|
18
|
+
*/
|
|
19
|
+
export default function useOpen(propOpen: Ref<boolean>, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): readonly [import('vue').ComputedRef<boolean>, TriggerOpenType];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { computed, onMounted, shallowRef, watch } from "vue";
|
|
2
|
+
function internalMacroTask(fn) {
|
|
3
|
+
const channel = new MessageChannel();
|
|
4
|
+
channel.port1.onmessage = fn;
|
|
5
|
+
channel.port2.postMessage(null);
|
|
6
|
+
}
|
|
7
|
+
function macroTask(fn, times = 1) {
|
|
8
|
+
if (times <= 0) {
|
|
9
|
+
fn();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
internalMacroTask(() => {
|
|
13
|
+
macroTask(fn, times - 1);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function useOpen(propOpen, onOpen, postOpen) {
|
|
17
|
+
const rendered = shallowRef(false);
|
|
18
|
+
onMounted(() => {
|
|
19
|
+
rendered.value = true;
|
|
20
|
+
});
|
|
21
|
+
const stateOpen = shallowRef(false);
|
|
22
|
+
watch(propOpen, () => {
|
|
23
|
+
stateOpen.value = propOpen.value;
|
|
24
|
+
});
|
|
25
|
+
const ssrSafeOpen = computed(() => rendered.value ? stateOpen.value : false);
|
|
26
|
+
const mergedOpen = computed(() => postOpen(ssrSafeOpen.value));
|
|
27
|
+
const taskIdRef = shallowRef(0);
|
|
28
|
+
const taskLockRef = shallowRef(false);
|
|
29
|
+
const triggerEvent = (nextOpen) => {
|
|
30
|
+
if (onOpen && mergedOpen.value !== nextOpen) onOpen(nextOpen);
|
|
31
|
+
stateOpen.value = nextOpen;
|
|
32
|
+
};
|
|
33
|
+
const toggleOpen = (nextOpen, config = {}) => {
|
|
34
|
+
const { ignoreNext = false, lazy = false } = config;
|
|
35
|
+
taskIdRef.value += 1;
|
|
36
|
+
const id = taskIdRef.value;
|
|
37
|
+
const nextOpenVal = typeof nextOpen === "boolean" ? nextOpen : !mergedOpen.value;
|
|
38
|
+
if (nextOpenVal !== lazy) {
|
|
39
|
+
if (!taskLockRef.value) {
|
|
40
|
+
triggerEvent(nextOpenVal);
|
|
41
|
+
if (ignoreNext) {
|
|
42
|
+
taskLockRef.value = ignoreNext;
|
|
43
|
+
macroTask(() => {
|
|
44
|
+
taskLockRef.value = false;
|
|
45
|
+
}, 2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
macroTask(() => {
|
|
51
|
+
if (id === taskIdRef.value && !taskLockRef.value) triggerEvent(nextOpenVal);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
return [mergedOpen, toggleOpen];
|
|
55
|
+
}
|
|
56
|
+
export { useOpen as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useOptions(options, childrenOptions, fieldNames, optionFilterProp, optionLabelProp) {
|
|
5
|
+
return (0, vue.computed)(() => {
|
|
6
|
+
let mergedOptions = [];
|
|
7
|
+
if (options.value && options.value.length > 0) mergedOptions = options.value;
|
|
8
|
+
else if (childrenOptions.value && childrenOptions.value.length > 0) mergedOptions = childrenOptions.value;
|
|
9
|
+
const valueOptions = /* @__PURE__ */ new Map();
|
|
10
|
+
const labelOptions = /* @__PURE__ */ new Map();
|
|
11
|
+
const setLabelOptions = (labelOptionsMap, option, key) => {
|
|
12
|
+
if (key && typeof key === "string") labelOptionsMap.set(option[key], option);
|
|
13
|
+
};
|
|
14
|
+
const dig = (optionList, isChildren = false) => {
|
|
15
|
+
if (!Array.isArray(optionList)) return;
|
|
16
|
+
for (let i = 0; i < optionList.length; i += 1) {
|
|
17
|
+
const option = optionList[i];
|
|
18
|
+
if (!option) continue;
|
|
19
|
+
const optionsKey = fieldNames.value?.options || "options";
|
|
20
|
+
const valueKey = fieldNames.value?.value || "value";
|
|
21
|
+
const labelKey = fieldNames.value?.label || "label";
|
|
22
|
+
if (!option[optionsKey] || isChildren) {
|
|
23
|
+
valueOptions.set(option[valueKey], option);
|
|
24
|
+
setLabelOptions(labelOptions, option, labelKey);
|
|
25
|
+
setLabelOptions(labelOptions, option, optionFilterProp.value);
|
|
26
|
+
setLabelOptions(labelOptions, option, optionLabelProp.value);
|
|
27
|
+
} else dig(option[optionsKey], true);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
dig(mergedOptions);
|
|
31
|
+
return {
|
|
32
|
+
options: mergedOptions,
|
|
33
|
+
valueOptions,
|
|
34
|
+
labelOptions
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.default = useOptions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { Ref, ShallowRef } from 'vue';
|
|
3
|
+
import { RawValueType } from '../interface';
|
|
4
|
+
import { DefaultOptionType, FieldNames } from '../Select';
|
|
5
|
+
export interface OptionsResult<OptionType> {
|
|
6
|
+
options: OptionType[];
|
|
7
|
+
valueOptions: Map<RawValueType, OptionType>;
|
|
8
|
+
labelOptions: Map<VueNode, OptionType>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse `options` and flatten them.
|
|
12
|
+
*/
|
|
13
|
+
export default function useOptions<OptionType extends DefaultOptionType = DefaultOptionType>(options: Ref<OptionType[] | undefined>, childrenOptions: ShallowRef<OptionType[]>, fieldNames: Ref<FieldNames>, optionFilterProp: Ref<string | undefined>, optionLabelProp: Ref<string | undefined>): Ref<OptionsResult<OptionType>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function useOptions(options, childrenOptions, fieldNames, optionFilterProp, optionLabelProp) {
|
|
3
|
+
return computed(() => {
|
|
4
|
+
let mergedOptions = [];
|
|
5
|
+
if (options.value && options.value.length > 0) mergedOptions = options.value;
|
|
6
|
+
else if (childrenOptions.value && childrenOptions.value.length > 0) mergedOptions = childrenOptions.value;
|
|
7
|
+
const valueOptions = /* @__PURE__ */ new Map();
|
|
8
|
+
const labelOptions = /* @__PURE__ */ new Map();
|
|
9
|
+
const setLabelOptions = (labelOptionsMap, option, key) => {
|
|
10
|
+
if (key && typeof key === "string") labelOptionsMap.set(option[key], option);
|
|
11
|
+
};
|
|
12
|
+
const dig = (optionList, isChildren = false) => {
|
|
13
|
+
if (!Array.isArray(optionList)) return;
|
|
14
|
+
for (let i = 0; i < optionList.length; i += 1) {
|
|
15
|
+
const option = optionList[i];
|
|
16
|
+
if (!option) continue;
|
|
17
|
+
const optionsKey = fieldNames.value?.options || "options";
|
|
18
|
+
const valueKey = fieldNames.value?.value || "value";
|
|
19
|
+
const labelKey = fieldNames.value?.label || "label";
|
|
20
|
+
if (!option[optionsKey] || isChildren) {
|
|
21
|
+
valueOptions.set(option[valueKey], option);
|
|
22
|
+
setLabelOptions(labelOptions, option, labelKey);
|
|
23
|
+
setLabelOptions(labelOptions, option, optionFilterProp.value);
|
|
24
|
+
setLabelOptions(labelOptions, option, optionLabelProp.value);
|
|
25
|
+
} else dig(option[optionsKey], true);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
dig(mergedOptions);
|
|
29
|
+
return {
|
|
30
|
+
options: mergedOptions,
|
|
31
|
+
valueOptions,
|
|
32
|
+
labelOptions
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export { useOptions as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useRefFunc(callback) {
|
|
5
|
+
const funcRef = (0, vue.shallowRef)(callback);
|
|
6
|
+
funcRef.value = callback;
|
|
7
|
+
const cacheFn = (...args) => {
|
|
8
|
+
return funcRef.value(...args);
|
|
9
|
+
};
|
|
10
|
+
return cacheFn;
|
|
11
|
+
}
|
|
12
|
+
exports.default = useRefFunc;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
|
+
function useRefFunc(callback) {
|
|
3
|
+
const funcRef = shallowRef(callback);
|
|
4
|
+
funcRef.value = callback;
|
|
5
|
+
const cacheFn = (...args) => {
|
|
6
|
+
return funcRef.value(...args);
|
|
7
|
+
};
|
|
8
|
+
return cacheFn;
|
|
9
|
+
}
|
|
10
|
+
export { useRefFunc as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useSearchConfig(showSearch, props, mode) {
|
|
5
|
+
const { filterOption, searchValue, optionFilterProp, filterSort, onSearch, autoClearSearchValue } = props;
|
|
6
|
+
return [(0, vue.computed)(() => {
|
|
7
|
+
return typeof showSearch.value === "object" || mode.value === "combobox" || mode.value === "tags" || mode.value === "multiple" && showSearch.value === void 0 ? true : showSearch.value;
|
|
8
|
+
}), (0, vue.computed)(() => {
|
|
9
|
+
const isObject = typeof showSearch.value === "object";
|
|
10
|
+
return {
|
|
11
|
+
filterOption: filterOption?.value,
|
|
12
|
+
searchValue: searchValue?.value,
|
|
13
|
+
optionFilterProp: optionFilterProp?.value,
|
|
14
|
+
filterSort: filterSort?.value,
|
|
15
|
+
onSearch: onSearch?.value,
|
|
16
|
+
autoClearSearchValue: autoClearSearchValue?.value,
|
|
17
|
+
...isObject ? showSearch.value : {}
|
|
18
|
+
};
|
|
19
|
+
})];
|
|
20
|
+
}
|
|
21
|
+
exports.default = useSearchConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { SearchConfig, SelectProps } from '../Select';
|
|
3
|
+
export type SearchConfigResult = [Ref<boolean | undefined>, Ref<SearchConfig>];
|
|
4
|
+
export default function useSearchConfig(showSearch: Ref<boolean | SearchConfig | undefined>, props: {
|
|
5
|
+
filterOption?: Ref<SelectProps['filterOption']>;
|
|
6
|
+
searchValue?: Ref<string | undefined>;
|
|
7
|
+
optionFilterProp?: Ref<string | undefined>;
|
|
8
|
+
filterSort?: Ref<SelectProps['filterSort']>;
|
|
9
|
+
onSearch?: Ref<((value: string) => void) | undefined>;
|
|
10
|
+
autoClearSearchValue?: Ref<boolean | undefined>;
|
|
11
|
+
}, mode: Ref<SelectProps['mode']>): SearchConfigResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function useSearchConfig(showSearch, props, mode) {
|
|
3
|
+
const { filterOption, searchValue, optionFilterProp, filterSort, onSearch, autoClearSearchValue } = props;
|
|
4
|
+
return [computed(() => {
|
|
5
|
+
return typeof showSearch.value === "object" || mode.value === "combobox" || mode.value === "tags" || mode.value === "multiple" && showSearch.value === void 0 ? true : showSearch.value;
|
|
6
|
+
}), computed(() => {
|
|
7
|
+
const isObject = typeof showSearch.value === "object";
|
|
8
|
+
return {
|
|
9
|
+
filterOption: filterOption?.value,
|
|
10
|
+
searchValue: searchValue?.value,
|
|
11
|
+
optionFilterProp: optionFilterProp?.value,
|
|
12
|
+
filterSort: filterSort?.value,
|
|
13
|
+
onSearch: onSearch?.value,
|
|
14
|
+
autoClearSearchValue: autoClearSearchValue?.value,
|
|
15
|
+
...isObject ? showSearch.value : {}
|
|
16
|
+
};
|
|
17
|
+
})];
|
|
18
|
+
}
|
|
19
|
+
export { useSearchConfig as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useSelectTriggerControl(elements, open, triggerOpen, customizedTrigger) {
|
|
5
|
+
const onGlobalMouseDown = (event) => {
|
|
6
|
+
if (customizedTrigger.value) return;
|
|
7
|
+
let target = event.target;
|
|
8
|
+
if (target.shadowRoot && event.composed) target = event.composedPath()[0] || target;
|
|
9
|
+
if (open.value && elements().filter((element) => element).every((element) => !element.contains(target) && element !== target)) triggerOpen(false);
|
|
10
|
+
};
|
|
11
|
+
(0, vue.onMounted)(() => {
|
|
12
|
+
window.addEventListener("mousedown", onGlobalMouseDown);
|
|
13
|
+
(0, vue.onUnmounted)(() => {
|
|
14
|
+
window.removeEventListener("mousedown", onGlobalMouseDown);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.default = useSelectTriggerControl;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { onMounted, onUnmounted } from "vue";
|
|
2
|
+
function useSelectTriggerControl(elements, open, triggerOpen, customizedTrigger) {
|
|
3
|
+
const onGlobalMouseDown = (event) => {
|
|
4
|
+
if (customizedTrigger.value) return;
|
|
5
|
+
let target = event.target;
|
|
6
|
+
if (target.shadowRoot && event.composed) target = event.composedPath()[0] || target;
|
|
7
|
+
if (open.value && elements().filter((element) => element).every((element) => !element.contains(target) && element !== target)) triggerOpen(false);
|
|
8
|
+
};
|
|
9
|
+
onMounted(() => {
|
|
10
|
+
window.addEventListener("mousedown", onGlobalMouseDown);
|
|
11
|
+
onUnmounted(() => {
|
|
12
|
+
window.removeEventListener("mousedown", onGlobalMouseDown);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export { useSelectTriggerControl as default };
|