@v-c/select 1.2.2 → 1.2.4
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/OptionList.js +14 -2
- package/dist/Select.d.ts +2 -2
- package/dist/Select.js +9 -3
- package/dist/hooks/useFilterOptions.d.ts +1 -1
- package/dist/hooks/useFilterOptions.js +1 -1
- package/dist/hooks/useOptions.d.ts +1 -1
- package/dist/hooks/useOptions.js +3 -1
- package/dist/hooks/useSearchConfig.d.ts +1 -1
- package/package.json +3 -3
package/dist/OptionList.js
CHANGED
|
@@ -23,9 +23,21 @@ var OptionList = /* @__PURE__ */ defineComponent({
|
|
|
23
23
|
const baseProps = useBaseProps();
|
|
24
24
|
const context = useSelectContext();
|
|
25
25
|
const itemPrefixCls = computed(() => `${baseProps.value?.prefixCls}-item`);
|
|
26
|
+
const cacheRef = shallowRef({
|
|
27
|
+
value: context.value?.flattenOptions || [],
|
|
28
|
+
condition: [!!baseProps.value?.open, !!baseProps.value?.lockOptions]
|
|
29
|
+
});
|
|
26
30
|
const memoFlattenOptions = computed(() => {
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
const nextCondition = [!!baseProps.value?.open, !!baseProps.value?.lockOptions];
|
|
32
|
+
const nextValue = context.value?.flattenOptions || [];
|
|
33
|
+
if (nextCondition[0] && !nextCondition[1]) {
|
|
34
|
+
cacheRef.value = {
|
|
35
|
+
value: nextValue,
|
|
36
|
+
condition: nextCondition
|
|
37
|
+
};
|
|
38
|
+
return nextValue;
|
|
39
|
+
}
|
|
40
|
+
return cacheRef.value.value;
|
|
29
41
|
});
|
|
30
42
|
const listRef = shallowRef(null);
|
|
31
43
|
const overMaxCount = computed(() => {
|
package/dist/Select.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export interface SearchConfig {
|
|
|
43
43
|
filterSort?: (optionA: any, optionB: any, info: {
|
|
44
44
|
searchValue: string;
|
|
45
45
|
}) => number;
|
|
46
|
-
optionFilterProp?: string;
|
|
46
|
+
optionFilterProp?: string | string[];
|
|
47
47
|
}
|
|
48
48
|
export interface SelectProps extends Omit<BaseSelectPropsWithoutPrivate, 'showSearch'> {
|
|
49
49
|
prefixCls?: string;
|
|
@@ -70,7 +70,7 @@ export interface SelectProps extends Omit<BaseSelectPropsWithoutPrivate, 'showSe
|
|
|
70
70
|
/** @deprecated please use showSearch.filterSort */
|
|
71
71
|
filterSort?: SearchConfig['filterSort'];
|
|
72
72
|
/** @deprecated please use showSearch.optionFilterProp */
|
|
73
|
-
optionFilterProp?: string;
|
|
73
|
+
optionFilterProp?: string | string[];
|
|
74
74
|
optionLabelProp?: string;
|
|
75
75
|
options?: DefaultOptionType[];
|
|
76
76
|
optionRender?: (oriOption: FlattenOptionData, info: {
|
package/dist/Select.js
CHANGED
|
@@ -122,7 +122,7 @@ var Select = /* @__PURE__ */ defineComponent({
|
|
|
122
122
|
default: void 0
|
|
123
123
|
},
|
|
124
124
|
optionFilterProp: {
|
|
125
|
-
type: String,
|
|
125
|
+
type: [String, Array],
|
|
126
126
|
required: false,
|
|
127
127
|
default: void 0
|
|
128
128
|
},
|
|
@@ -573,7 +573,9 @@ var Select = /* @__PURE__ */ defineComponent({
|
|
|
573
573
|
autoClearSearchValue: toRef(props, "autoClearSearchValue")
|
|
574
574
|
}, toRef(props, "mode"));
|
|
575
575
|
const normalizedOptionFilterProps = computed(() => {
|
|
576
|
-
|
|
576
|
+
const prop = searchConfig.value?.optionFilterProp;
|
|
577
|
+
if (!prop) return [];
|
|
578
|
+
return Array.isArray(prop) ? prop : [prop];
|
|
577
579
|
});
|
|
578
580
|
const mergedFilterOption = computed(() => {
|
|
579
581
|
if (searchConfig.value.filterOption === void 0 && props.mode === "combobox") return false;
|
|
@@ -668,7 +670,11 @@ var Select = /* @__PURE__ */ defineComponent({
|
|
|
668
670
|
return cloneOptions;
|
|
669
671
|
}), mergedFieldNames, mergedSearchValue, mergedFilterOption, normalizedOptionFilterProps);
|
|
670
672
|
const filledSearchOptions = computed(() => {
|
|
671
|
-
|
|
673
|
+
const hasItemMatchingSearch = (item) => {
|
|
674
|
+
if (normalizedOptionFilterProps.value.length) return normalizedOptionFilterProps.value.some((prop) => item?.[prop] === mergedSearchValue.value);
|
|
675
|
+
return item?.value === mergedSearchValue.value;
|
|
676
|
+
};
|
|
677
|
+
if (props.mode !== "tags" || !mergedSearchValue.value || filteredOptions.value.some((item) => hasItemMatchingSearch(item))) return filteredOptions.value;
|
|
672
678
|
if (filteredOptions.value.some((item) => item[mergedFieldNames.value.value] === mergedSearchValue.value)) return filteredOptions.value;
|
|
673
679
|
if (valueOptions.value.get(mergedSearchValue.value)?.disabled) return filteredOptions.value;
|
|
674
680
|
return [createTagOption(mergedSearchValue.value), ...filteredOptions.value];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
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[]>;
|
|
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[]>;
|
|
@@ -12,7 +12,7 @@ function useFilterOptions(options, fieldNames, searchValue, filterOption, option
|
|
|
12
12
|
const customizeFilter = typeof filterOption.value === "function";
|
|
13
13
|
const upperSearch = searchValue.value.toUpperCase();
|
|
14
14
|
const defaultFilter = (_, option) => {
|
|
15
|
-
if (optionFilterProp.value && option) return includes(option[
|
|
15
|
+
if (optionFilterProp.value && optionFilterProp.value.length && option) return optionFilterProp.value.some((prop) => includes(option[prop], upperSearch));
|
|
16
16
|
if (option && option[fieldOptions]) return includes(option[fieldLabel !== "children" ? fieldLabel : "label"], upperSearch);
|
|
17
17
|
return option ? includes(option[fieldValue], upperSearch) : false;
|
|
18
18
|
};
|
|
@@ -10,4 +10,4 @@ export interface OptionsResult<OptionType> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Parse `options` and flatten them.
|
|
12
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>>;
|
|
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>>;
|
package/dist/hooks/useOptions.js
CHANGED
|
@@ -24,7 +24,9 @@ function useOptions(options, childrenOptions, fieldNames, optionFilterProp, opti
|
|
|
24
24
|
if (!option[optionsKey] || isChildren) {
|
|
25
25
|
valueOptions.set(option[valueKey], option);
|
|
26
26
|
setLabelOptions(labelOptions, option, labelKey);
|
|
27
|
-
|
|
27
|
+
if (optionFilterProp.value) optionFilterProp.value.forEach((prop) => {
|
|
28
|
+
setLabelOptions(labelOptions, option, prop);
|
|
29
|
+
});
|
|
28
30
|
setLabelOptions(labelOptions, option, optionLabelProp.value);
|
|
29
31
|
} else dig(option[optionsKey], true);
|
|
30
32
|
}
|
|
@@ -4,7 +4,7 @@ export type SearchConfigResult = [Ref<boolean | undefined>, Ref<SearchConfig>];
|
|
|
4
4
|
export default function useSearchConfig(showSearch: Ref<boolean | SearchConfig | undefined>, props: {
|
|
5
5
|
filterOption?: Ref<SelectProps['filterOption']>;
|
|
6
6
|
searchValue?: Ref<string | undefined>;
|
|
7
|
-
optionFilterProp?: Ref<string | undefined>;
|
|
7
|
+
optionFilterProp?: Ref<string | string[] | undefined>;
|
|
8
8
|
filterSort?: Ref<SelectProps['filterSort']>;
|
|
9
9
|
onSearch?: Ref<((value: string) => void) | undefined>;
|
|
10
10
|
autoClearSearchValue?: Ref<boolean | undefined>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/select",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.4",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@v-c/overflow": "^1.1.1",
|
|
38
38
|
"@v-c/trigger": "^1.1.0",
|
|
39
|
-
"@v-c/
|
|
40
|
-
"@v-c/
|
|
39
|
+
"@v-c/util": "^1.1.0",
|
|
40
|
+
"@v-c/virtual-list": "^1.1.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "vite build",
|