@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,41 @@
|
|
|
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_commonUtil = require("../utils/commonUtil.cjs");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
let _v_c_tree = require("@v-c/tree");
|
|
9
|
+
function useEntities(options, fieldNames) {
|
|
10
|
+
const cacheRef = (0, vue.shallowRef)({
|
|
11
|
+
options: [],
|
|
12
|
+
fieldNames: null,
|
|
13
|
+
info: {
|
|
14
|
+
keyEntities: {},
|
|
15
|
+
pathKeyEntities: {}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const getEntities = () => {
|
|
19
|
+
const mergedOptions = options.value;
|
|
20
|
+
const mergedFieldNames = fieldNames.value;
|
|
21
|
+
if (cacheRef.value.options !== mergedOptions || cacheRef.value.fieldNames !== mergedFieldNames) {
|
|
22
|
+
cacheRef.value.options = mergedOptions;
|
|
23
|
+
cacheRef.value.fieldNames = mergedFieldNames;
|
|
24
|
+
cacheRef.value.info = (0, _v_c_tree.convertDataToEntities)(mergedOptions, {
|
|
25
|
+
fieldNames: mergedFieldNames,
|
|
26
|
+
initWrapper: (wrapper) => ({
|
|
27
|
+
...wrapper,
|
|
28
|
+
pathKeyEntities: {}
|
|
29
|
+
}),
|
|
30
|
+
processEntity: (entity, wrapper) => {
|
|
31
|
+
const pathKey = entity.nodes.map((node) => node[mergedFieldNames.value]).join(require_commonUtil.VALUE_SPLIT);
|
|
32
|
+
wrapper.pathKeyEntities[pathKey] = entity;
|
|
33
|
+
entity.key = pathKey;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return cacheRef.value.info.pathKeyEntities;
|
|
38
|
+
};
|
|
39
|
+
return getEntities;
|
|
40
|
+
}
|
|
41
|
+
exports.default = useEntities;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataEntity } from '@v-c/tree';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { DefaultOptionType, InternalFieldNames } from '../Cascader';
|
|
4
|
+
export interface OptionsInfo {
|
|
5
|
+
keyEntities: Record<string, DataEntity>;
|
|
6
|
+
pathKeyEntities: Record<string, DataEntity>;
|
|
7
|
+
}
|
|
8
|
+
export type GetEntities = () => OptionsInfo['pathKeyEntities'];
|
|
9
|
+
/** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
|
|
10
|
+
export default function useEntities(options: Ref<DefaultOptionType[]>, fieldNames: Ref<InternalFieldNames>): GetEntities;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VALUE_SPLIT } from "../utils/commonUtil.js";
|
|
2
|
+
import { shallowRef } from "vue";
|
|
3
|
+
import { convertDataToEntities } from "@v-c/tree";
|
|
4
|
+
function useEntities(options, fieldNames) {
|
|
5
|
+
const cacheRef = shallowRef({
|
|
6
|
+
options: [],
|
|
7
|
+
fieldNames: null,
|
|
8
|
+
info: {
|
|
9
|
+
keyEntities: {},
|
|
10
|
+
pathKeyEntities: {}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const getEntities = () => {
|
|
14
|
+
const mergedOptions = options.value;
|
|
15
|
+
const mergedFieldNames = fieldNames.value;
|
|
16
|
+
if (cacheRef.value.options !== mergedOptions || cacheRef.value.fieldNames !== mergedFieldNames) {
|
|
17
|
+
cacheRef.value.options = mergedOptions;
|
|
18
|
+
cacheRef.value.fieldNames = mergedFieldNames;
|
|
19
|
+
cacheRef.value.info = convertDataToEntities(mergedOptions, {
|
|
20
|
+
fieldNames: mergedFieldNames,
|
|
21
|
+
initWrapper: (wrapper) => ({
|
|
22
|
+
...wrapper,
|
|
23
|
+
pathKeyEntities: {}
|
|
24
|
+
}),
|
|
25
|
+
processEntity: (entity, wrapper) => {
|
|
26
|
+
const pathKey = entity.nodes.map((node) => node[mergedFieldNames.value]).join(VALUE_SPLIT);
|
|
27
|
+
wrapper.pathKeyEntities[pathKey] = entity;
|
|
28
|
+
entity.key = pathKey;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return cacheRef.value.info.pathKeyEntities;
|
|
33
|
+
};
|
|
34
|
+
return getEntities;
|
|
35
|
+
}
|
|
36
|
+
export { useEntities as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_treeUtil = require("../utils/treeUtil.cjs");
|
|
6
|
+
function useMissingValues(options, fieldNames) {
|
|
7
|
+
return (rawValues) => {
|
|
8
|
+
const missingValues = [];
|
|
9
|
+
const existsValues = [];
|
|
10
|
+
rawValues.forEach((valueCell) => {
|
|
11
|
+
if (require_treeUtil.toPathOptions(valueCell, options.value, fieldNames.value).every((opt) => opt.option)) existsValues.push(valueCell);
|
|
12
|
+
else missingValues.push(valueCell);
|
|
13
|
+
});
|
|
14
|
+
return [existsValues, missingValues];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.default = useMissingValues;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
|
|
3
|
+
export type GetMissValues = ReturnType<typeof useMissingValues>;
|
|
4
|
+
export default function useMissingValues(options: Ref<DefaultOptionType[]>, fieldNames: Ref<InternalFieldNames>): (rawValues: SingleValueType[]) => [SingleValueType[], SingleValueType[]];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { toPathOptions } from "../utils/treeUtil.js";
|
|
2
|
+
function useMissingValues(options, fieldNames) {
|
|
3
|
+
return (rawValues) => {
|
|
4
|
+
const missingValues = [];
|
|
5
|
+
const existsValues = [];
|
|
6
|
+
rawValues.forEach((valueCell) => {
|
|
7
|
+
if (toPathOptions(valueCell, options.value, fieldNames.value).every((opt) => opt.option)) existsValues.push(valueCell);
|
|
8
|
+
else missingValues.push(valueCell);
|
|
9
|
+
});
|
|
10
|
+
return [existsValues, missingValues];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export { useMissingValues as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
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_useEntities = require("./useEntities.cjs");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
function useOptions(mergedFieldNames, options) {
|
|
9
|
+
const emptyOptions = [];
|
|
10
|
+
const mergedOptions = (0, vue.computed)(() => options.value || emptyOptions);
|
|
11
|
+
const getPathKeyEntities = require_useEntities.default(mergedOptions, mergedFieldNames);
|
|
12
|
+
const getValueByKeyPath = (pathKeys) => {
|
|
13
|
+
const keyPathEntities = getPathKeyEntities();
|
|
14
|
+
return pathKeys.map((pathKey) => {
|
|
15
|
+
const { nodes } = keyPathEntities[pathKey];
|
|
16
|
+
return nodes.map((node) => node[mergedFieldNames.value.value]);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return [
|
|
20
|
+
mergedOptions,
|
|
21
|
+
getPathKeyEntities,
|
|
22
|
+
getValueByKeyPath
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
exports.default = useOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DefaultOptionType } from '..';
|
|
3
|
+
import { InternalFieldNames, LegacyKey, SingleValueType } from '../Cascader';
|
|
4
|
+
import { GetEntities } from './useEntities';
|
|
5
|
+
export default function useOptions(mergedFieldNames: Ref<InternalFieldNames>, options: Ref<DefaultOptionType[] | undefined>): [
|
|
6
|
+
mergedOptions: Ref<DefaultOptionType[]>,
|
|
7
|
+
getPathKeyEntities: GetEntities,
|
|
8
|
+
getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[]
|
|
9
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import useEntities from "./useEntities.js";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
function useOptions(mergedFieldNames, options) {
|
|
4
|
+
const emptyOptions = [];
|
|
5
|
+
const mergedOptions = computed(() => options.value || emptyOptions);
|
|
6
|
+
const getPathKeyEntities = useEntities(mergedOptions, mergedFieldNames);
|
|
7
|
+
const getValueByKeyPath = (pathKeys) => {
|
|
8
|
+
const keyPathEntities = getPathKeyEntities();
|
|
9
|
+
return pathKeys.map((pathKey) => {
|
|
10
|
+
const { nodes } = keyPathEntities[pathKey];
|
|
11
|
+
return nodes.map((node) => node[mergedFieldNames.value.value]);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
return [
|
|
15
|
+
mergedOptions,
|
|
16
|
+
getPathKeyEntities,
|
|
17
|
+
getValueByKeyPath
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
export { useOptions as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
let vue = require("vue");
|
|
7
|
+
let _v_c_util = require("@v-c/util");
|
|
8
|
+
function useSearchConfig(showSearch, props) {
|
|
9
|
+
const mergedShowSearch = (0, vue.computed)(() => {
|
|
10
|
+
if (!showSearch.value) return false;
|
|
11
|
+
return typeof showSearch.value === "object" ? true : !!showSearch.value;
|
|
12
|
+
});
|
|
13
|
+
return [mergedShowSearch, (0, vue.computed)(() => {
|
|
14
|
+
if (!mergedShowSearch.value) return {};
|
|
15
|
+
const { autoClearSearchValue, searchValue, onSearch } = props.value;
|
|
16
|
+
let config = {
|
|
17
|
+
matchInputWidth: true,
|
|
18
|
+
limit: 50,
|
|
19
|
+
autoClearSearchValue,
|
|
20
|
+
searchValue,
|
|
21
|
+
onSearch
|
|
22
|
+
};
|
|
23
|
+
if (showSearch.value && typeof showSearch.value === "object") config = {
|
|
24
|
+
...config,
|
|
25
|
+
...showSearch.value
|
|
26
|
+
};
|
|
27
|
+
if (config.limit <= 0) {
|
|
28
|
+
config.limit = false;
|
|
29
|
+
if (process.env.NODE_ENV !== "production") (0, _v_c_util.warning)(false, "'limit' of showSearch should be positive number or false.");
|
|
30
|
+
}
|
|
31
|
+
return config;
|
|
32
|
+
})];
|
|
33
|
+
}
|
|
34
|
+
exports.default = useSearchConfig;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { CascaderProps, SearchConfig } from '../Cascader';
|
|
3
|
+
export type SearchConfigResult = [Ref<boolean>, Ref<SearchConfig>];
|
|
4
|
+
export default function useSearchConfig(showSearch: Ref<CascaderProps['showSearch']>, props: Ref<Pick<CascaderProps, 'autoClearSearchValue' | 'searchValue' | 'onSearch'>>): SearchConfigResult;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { warning } from "@v-c/util";
|
|
3
|
+
function useSearchConfig(showSearch, props) {
|
|
4
|
+
const mergedShowSearch = computed(() => {
|
|
5
|
+
if (!showSearch.value) return false;
|
|
6
|
+
return typeof showSearch.value === "object" ? true : !!showSearch.value;
|
|
7
|
+
});
|
|
8
|
+
return [mergedShowSearch, computed(() => {
|
|
9
|
+
if (!mergedShowSearch.value) return {};
|
|
10
|
+
const { autoClearSearchValue, searchValue, onSearch } = props.value;
|
|
11
|
+
let config = {
|
|
12
|
+
matchInputWidth: true,
|
|
13
|
+
limit: 50,
|
|
14
|
+
autoClearSearchValue,
|
|
15
|
+
searchValue,
|
|
16
|
+
onSearch
|
|
17
|
+
};
|
|
18
|
+
if (showSearch.value && typeof showSearch.value === "object") config = {
|
|
19
|
+
...config,
|
|
20
|
+
...showSearch.value
|
|
21
|
+
};
|
|
22
|
+
if (config.limit <= 0) {
|
|
23
|
+
config.limit = false;
|
|
24
|
+
if (process.env.NODE_ENV !== "production") warning(false, "'limit' of showSearch should be positive number or false.");
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
})];
|
|
28
|
+
}
|
|
29
|
+
export { useSearchConfig as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
let vue = require("vue");
|
|
7
|
+
const SEARCH_MARK = "__vc_cascader_search_mark__";
|
|
8
|
+
var defaultFilter = (search, options, { label = "" }) => options.some((opt) => String(opt[label]).toLowerCase().includes(search.toLowerCase()));
|
|
9
|
+
var defaultRender = (_inputValue, path, _prefixCls, fieldNames) => path.map((opt) => opt[fieldNames.label]).join(" / ");
|
|
10
|
+
function useSearchOptions(search, options, fieldNames, prefixCls, config, enableHalfPath) {
|
|
11
|
+
return (0, vue.computed)(() => {
|
|
12
|
+
const mergedSearch = search.value;
|
|
13
|
+
const mergedOptions = options.value;
|
|
14
|
+
const mergedFieldNames = fieldNames.value;
|
|
15
|
+
const mergedPrefixCls = prefixCls.value;
|
|
16
|
+
const { filter = defaultFilter, render = defaultRender, limit = 50, sort } = config.value;
|
|
17
|
+
const filteredOptions = [];
|
|
18
|
+
if (!mergedSearch) return [];
|
|
19
|
+
function dig(list, pathOptions, parentDisabled = false) {
|
|
20
|
+
list.forEach((option) => {
|
|
21
|
+
if (!sort && limit !== false && limit > 0 && filteredOptions.length >= limit) return;
|
|
22
|
+
const connectedPathOptions = [...pathOptions, option];
|
|
23
|
+
const children = option[mergedFieldNames.children];
|
|
24
|
+
const mergedDisabled = parentDisabled || option.disabled;
|
|
25
|
+
if (!children || children.length === 0 || enableHalfPath?.value) {
|
|
26
|
+
if (filter?.(mergedSearch, connectedPathOptions, { label: mergedFieldNames.label })) filteredOptions.push({
|
|
27
|
+
...option,
|
|
28
|
+
disabled: mergedDisabled,
|
|
29
|
+
[mergedFieldNames.label]: render?.(mergedSearch, connectedPathOptions, mergedPrefixCls, mergedFieldNames),
|
|
30
|
+
[SEARCH_MARK]: connectedPathOptions,
|
|
31
|
+
[mergedFieldNames.children]: void 0
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (children) dig(option[mergedFieldNames.children], connectedPathOptions, mergedDisabled);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
dig(mergedOptions, []);
|
|
38
|
+
if (sort) filteredOptions.sort((a, b) => {
|
|
39
|
+
return sort(a[SEARCH_MARK], b[SEARCH_MARK], mergedSearch, mergedFieldNames);
|
|
40
|
+
});
|
|
41
|
+
return limit !== false && limit > 0 ? filteredOptions.slice(0, limit) : filteredOptions;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var useSearchOptions_default = useSearchOptions;
|
|
45
|
+
exports.SEARCH_MARK = SEARCH_MARK;
|
|
46
|
+
exports.default = useSearchOptions_default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { DefaultOptionType, InternalFieldNames, SearchConfig } from '../Cascader';
|
|
3
|
+
export declare const SEARCH_MARK = "__vc_cascader_search_mark__";
|
|
4
|
+
declare function useSearchOptions(search: Ref<string>, options: Ref<DefaultOptionType[]>, fieldNames: Ref<InternalFieldNames>, prefixCls: Ref<string>, config: Ref<SearchConfig>, enableHalfPath?: Ref<boolean>): ComputedRef<DefaultOptionType[]>;
|
|
5
|
+
export default useSearchOptions;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
const SEARCH_MARK = "__vc_cascader_search_mark__";
|
|
3
|
+
var defaultFilter = (search, options, { label = "" }) => options.some((opt) => String(opt[label]).toLowerCase().includes(search.toLowerCase()));
|
|
4
|
+
var defaultRender = (_inputValue, path, _prefixCls, fieldNames) => path.map((opt) => opt[fieldNames.label]).join(" / ");
|
|
5
|
+
function useSearchOptions(search, options, fieldNames, prefixCls, config, enableHalfPath) {
|
|
6
|
+
return computed(() => {
|
|
7
|
+
const mergedSearch = search.value;
|
|
8
|
+
const mergedOptions = options.value;
|
|
9
|
+
const mergedFieldNames = fieldNames.value;
|
|
10
|
+
const mergedPrefixCls = prefixCls.value;
|
|
11
|
+
const { filter = defaultFilter, render = defaultRender, limit = 50, sort } = config.value;
|
|
12
|
+
const filteredOptions = [];
|
|
13
|
+
if (!mergedSearch) return [];
|
|
14
|
+
function dig(list, pathOptions, parentDisabled = false) {
|
|
15
|
+
list.forEach((option) => {
|
|
16
|
+
if (!sort && limit !== false && limit > 0 && filteredOptions.length >= limit) return;
|
|
17
|
+
const connectedPathOptions = [...pathOptions, option];
|
|
18
|
+
const children = option[mergedFieldNames.children];
|
|
19
|
+
const mergedDisabled = parentDisabled || option.disabled;
|
|
20
|
+
if (!children || children.length === 0 || enableHalfPath?.value) {
|
|
21
|
+
if (filter?.(mergedSearch, connectedPathOptions, { label: mergedFieldNames.label })) filteredOptions.push({
|
|
22
|
+
...option,
|
|
23
|
+
disabled: mergedDisabled,
|
|
24
|
+
[mergedFieldNames.label]: render?.(mergedSearch, connectedPathOptions, mergedPrefixCls, mergedFieldNames),
|
|
25
|
+
[SEARCH_MARK]: connectedPathOptions,
|
|
26
|
+
[mergedFieldNames.children]: void 0
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (children) dig(option[mergedFieldNames.children], connectedPathOptions, mergedDisabled);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
dig(mergedOptions, []);
|
|
33
|
+
if (sort) filteredOptions.sort((a, b) => {
|
|
34
|
+
return sort(a[SEARCH_MARK], b[SEARCH_MARK], mergedSearch, mergedFieldNames);
|
|
35
|
+
});
|
|
36
|
+
return limit !== false && limit > 0 ? filteredOptions.slice(0, limit) : filteredOptions;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
var useSearchOptions_default = useSearchOptions;
|
|
40
|
+
export { SEARCH_MARK, useSearchOptions_default as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
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_commonUtil = require("../utils/commonUtil.cjs");
|
|
7
|
+
const require_treeUtil = require("../utils/treeUtil.cjs");
|
|
8
|
+
let _v_c_tree = require("@v-c/tree");
|
|
9
|
+
function useSelect(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy) {
|
|
10
|
+
return (valuePath) => {
|
|
11
|
+
if (!multiple.value) triggerChange(valuePath);
|
|
12
|
+
else {
|
|
13
|
+
const pathKey = require_commonUtil.toPathKey(valuePath);
|
|
14
|
+
const checkedPathKeys = require_commonUtil.toPathKeys(checkedValues.value);
|
|
15
|
+
const halfCheckedPathKeys = require_commonUtil.toPathKeys(halfCheckedValues.value);
|
|
16
|
+
const existInChecked = checkedPathKeys.includes(pathKey);
|
|
17
|
+
const existInMissing = missingCheckedValues.value.some((valueCells) => require_commonUtil.toPathKey(valueCells) === pathKey);
|
|
18
|
+
let nextCheckedValues = checkedValues.value;
|
|
19
|
+
let nextMissingValues = missingCheckedValues.value;
|
|
20
|
+
if (existInMissing && !existInChecked) nextMissingValues = missingCheckedValues.value.filter((valueCells) => require_commonUtil.toPathKey(valueCells) !== pathKey);
|
|
21
|
+
else {
|
|
22
|
+
const nextRawCheckedKeys = existInChecked ? checkedPathKeys.filter((key) => key !== pathKey) : [...checkedPathKeys, pathKey];
|
|
23
|
+
const pathKeyEntities = getPathKeyEntities();
|
|
24
|
+
let checkedKeys;
|
|
25
|
+
if (existInChecked) ({checkedKeys} = (0, _v_c_tree.conductCheck)(nextRawCheckedKeys, {
|
|
26
|
+
checked: false,
|
|
27
|
+
halfCheckedKeys: halfCheckedPathKeys
|
|
28
|
+
}, pathKeyEntities));
|
|
29
|
+
else ({checkedKeys} = (0, _v_c_tree.conductCheck)(nextRawCheckedKeys, true, pathKeyEntities));
|
|
30
|
+
nextCheckedValues = getValueByKeyPath(require_treeUtil.formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy?.value));
|
|
31
|
+
}
|
|
32
|
+
triggerChange([...nextMissingValues, ...nextCheckedValues]);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.default = useSelect;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { InternalValueType, LegacyKey, ShowCheckedStrategy, SingleValueType } from '../Cascader';
|
|
3
|
+
import { GetEntities } from './useEntities';
|
|
4
|
+
export default function useSelect(multiple: Ref<boolean>, triggerChange: (nextValues: InternalValueType) => void, checkedValues: Ref<SingleValueType[]>, halfCheckedValues: Ref<SingleValueType[]>, missingCheckedValues: Ref<SingleValueType[]>, getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], showCheckedStrategy?: Ref<ShowCheckedStrategy | undefined>): (valuePath: SingleValueType) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { toPathKey, toPathKeys } from "../utils/commonUtil.js";
|
|
2
|
+
import { formatStrategyValues } from "../utils/treeUtil.js";
|
|
3
|
+
import { conductCheck } from "@v-c/tree";
|
|
4
|
+
function useSelect(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy) {
|
|
5
|
+
return (valuePath) => {
|
|
6
|
+
if (!multiple.value) triggerChange(valuePath);
|
|
7
|
+
else {
|
|
8
|
+
const pathKey = toPathKey(valuePath);
|
|
9
|
+
const checkedPathKeys = toPathKeys(checkedValues.value);
|
|
10
|
+
const halfCheckedPathKeys = toPathKeys(halfCheckedValues.value);
|
|
11
|
+
const existInChecked = checkedPathKeys.includes(pathKey);
|
|
12
|
+
const existInMissing = missingCheckedValues.value.some((valueCells) => toPathKey(valueCells) === pathKey);
|
|
13
|
+
let nextCheckedValues = checkedValues.value;
|
|
14
|
+
let nextMissingValues = missingCheckedValues.value;
|
|
15
|
+
if (existInMissing && !existInChecked) nextMissingValues = missingCheckedValues.value.filter((valueCells) => toPathKey(valueCells) !== pathKey);
|
|
16
|
+
else {
|
|
17
|
+
const nextRawCheckedKeys = existInChecked ? checkedPathKeys.filter((key) => key !== pathKey) : [...checkedPathKeys, pathKey];
|
|
18
|
+
const pathKeyEntities = getPathKeyEntities();
|
|
19
|
+
let checkedKeys;
|
|
20
|
+
if (existInChecked) ({checkedKeys} = conductCheck(nextRawCheckedKeys, {
|
|
21
|
+
checked: false,
|
|
22
|
+
halfCheckedKeys: halfCheckedPathKeys
|
|
23
|
+
}, pathKeyEntities));
|
|
24
|
+
else ({checkedKeys} = conductCheck(nextRawCheckedKeys, true, pathKeyEntities));
|
|
25
|
+
nextCheckedValues = getValueByKeyPath(formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy?.value));
|
|
26
|
+
}
|
|
27
|
+
triggerChange([...nextMissingValues, ...nextCheckedValues]);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { useSelect as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
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_commonUtil = require("../utils/commonUtil.cjs");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
let _v_c_tree = require("@v-c/tree");
|
|
9
|
+
function useValues(multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues) {
|
|
10
|
+
return (0, vue.computed)(() => {
|
|
11
|
+
const [existValues, missingValues] = getMissingValues(rawValues.value);
|
|
12
|
+
if (!multiple.value || !rawValues.value.length) return [
|
|
13
|
+
existValues,
|
|
14
|
+
[],
|
|
15
|
+
missingValues
|
|
16
|
+
];
|
|
17
|
+
const { checkedKeys, halfCheckedKeys } = (0, _v_c_tree.conductCheck)(require_commonUtil.toPathKeys(existValues), true, getPathKeyEntities());
|
|
18
|
+
return [
|
|
19
|
+
getValueByKeyPath(checkedKeys),
|
|
20
|
+
getValueByKeyPath(halfCheckedKeys),
|
|
21
|
+
missingValues
|
|
22
|
+
];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.default = useValues;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataEntity } from '@v-c/tree';
|
|
2
|
+
import { ComputedRef, Ref } from 'vue';
|
|
3
|
+
import { LegacyKey, SingleValueType } from '../Cascader';
|
|
4
|
+
import { GetMissValues } from './useMissingValues';
|
|
5
|
+
export default function useValues(multiple: Ref<boolean>, rawValues: Ref<SingleValueType[]>, getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: LegacyKey[]) => SingleValueType[], getMissingValues: GetMissValues): ComputedRef<[
|
|
6
|
+
checkedValues: SingleValueType[],
|
|
7
|
+
halfCheckedValues: SingleValueType[],
|
|
8
|
+
missingCheckedValues: SingleValueType[]
|
|
9
|
+
]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { toPathKeys } from "../utils/commonUtil.js";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { conductCheck } from "@v-c/tree";
|
|
4
|
+
function useValues(multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues) {
|
|
5
|
+
return computed(() => {
|
|
6
|
+
const [existValues, missingValues] = getMissingValues(rawValues.value);
|
|
7
|
+
if (!multiple.value || !rawValues.value.length) return [
|
|
8
|
+
existValues,
|
|
9
|
+
[],
|
|
10
|
+
missingValues
|
|
11
|
+
];
|
|
12
|
+
const { checkedKeys, halfCheckedKeys } = conductCheck(toPathKeys(existValues), true, getPathKeyEntities());
|
|
13
|
+
return [
|
|
14
|
+
getValueByKeyPath(checkedKeys),
|
|
15
|
+
getValueByKeyPath(halfCheckedKeys),
|
|
16
|
+
missingValues
|
|
17
|
+
];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { useValues as default };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_commonUtil = require("./utils/commonUtil.cjs");
|
|
6
|
+
const require_Cascader = require("./Cascader.cjs");
|
|
7
|
+
const require_Panel = require("./Panel.cjs");
|
|
8
|
+
var ExportCascader = require_Cascader.default;
|
|
9
|
+
ExportCascader.Panel = require_Panel.default;
|
|
10
|
+
ExportCascader.SHOW_PARENT = require_commonUtil.SHOW_PARENT;
|
|
11
|
+
ExportCascader.SHOW_CHILD = require_commonUtil.SHOW_CHILD;
|
|
12
|
+
var src_default = ExportCascader;
|
|
13
|
+
exports.Panel = require_Panel.default;
|
|
14
|
+
exports.SHOW_CHILD = require_commonUtil.SHOW_CHILD;
|
|
15
|
+
exports.SHOW_PARENT = require_commonUtil.SHOW_PARENT;
|
|
16
|
+
exports.default = src_default;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as Cascader } from './Cascader';
|
|
2
|
+
import { default as Panel } from './Panel';
|
|
3
|
+
import { SHOW_CHILD, SHOW_PARENT } from './utils/commonUtil';
|
|
4
|
+
export type { BaseOptionType, CascaderProps, CascaderRef, DefaultOptionType, FieldNames, SearchConfig, } from './Cascader';
|
|
5
|
+
export { Panel, SHOW_CHILD, SHOW_PARENT };
|
|
6
|
+
type CascaderType = typeof Cascader & {
|
|
7
|
+
Panel: typeof Panel;
|
|
8
|
+
SHOW_PARENT: typeof SHOW_PARENT;
|
|
9
|
+
SHOW_CHILD: typeof SHOW_CHILD;
|
|
10
|
+
};
|
|
11
|
+
declare const ExportCascader: CascaderType;
|
|
12
|
+
export default ExportCascader;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SHOW_CHILD, SHOW_PARENT } from "./utils/commonUtil.js";
|
|
2
|
+
import Cascader_default from "./Cascader.js";
|
|
3
|
+
import Panel_default from "./Panel.js";
|
|
4
|
+
var ExportCascader = Cascader_default;
|
|
5
|
+
ExportCascader.Panel = Panel_default;
|
|
6
|
+
ExportCascader.SHOW_PARENT = SHOW_PARENT;
|
|
7
|
+
ExportCascader.SHOW_CHILD = SHOW_CHILD;
|
|
8
|
+
var src_default = ExportCascader;
|
|
9
|
+
export { Panel_default as Panel, SHOW_CHILD, SHOW_PARENT, src_default as default };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_useSearchOptions = require("../hooks/useSearchOptions.cjs");
|
|
3
|
+
const VALUE_SPLIT = "__VC_CASCADER_SPLIT__";
|
|
4
|
+
const SHOW_PARENT = "SHOW_PARENT";
|
|
5
|
+
const SHOW_CHILD = "SHOW_CHILD";
|
|
6
|
+
function toPathKey(value) {
|
|
7
|
+
return value.join(VALUE_SPLIT);
|
|
8
|
+
}
|
|
9
|
+
function toPathKeys(value) {
|
|
10
|
+
return value.map(toPathKey);
|
|
11
|
+
}
|
|
12
|
+
function toPathValueStr(pathKey) {
|
|
13
|
+
return pathKey.split(VALUE_SPLIT);
|
|
14
|
+
}
|
|
15
|
+
function fillFieldNames(fieldNames) {
|
|
16
|
+
const { label, value, children } = fieldNames || {};
|
|
17
|
+
const val = value || "value";
|
|
18
|
+
return {
|
|
19
|
+
label: label || "label",
|
|
20
|
+
value: val,
|
|
21
|
+
key: val,
|
|
22
|
+
children: children || "children"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isLeaf(option, fieldNames) {
|
|
26
|
+
return option.isLeaf ?? !option[fieldNames.children]?.length;
|
|
27
|
+
}
|
|
28
|
+
function scrollIntoParentView(element) {
|
|
29
|
+
const parent = element.parentElement;
|
|
30
|
+
if (!parent) return;
|
|
31
|
+
const elementToParent = element.offsetTop - parent.offsetTop;
|
|
32
|
+
if (elementToParent - parent.scrollTop < 0) parent.scrollTo({ top: elementToParent });
|
|
33
|
+
else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight });
|
|
34
|
+
}
|
|
35
|
+
function getFullPathKeys(options, fieldNames) {
|
|
36
|
+
return options.map((item) => item[require_useSearchOptions.SEARCH_MARK]?.map((opt) => opt[fieldNames.value]));
|
|
37
|
+
}
|
|
38
|
+
function isMultipleValue(value) {
|
|
39
|
+
return Array.isArray(value) && Array.isArray(value[0]);
|
|
40
|
+
}
|
|
41
|
+
function toRawValues(value) {
|
|
42
|
+
if (!value) return [];
|
|
43
|
+
if (isMultipleValue(value)) return value;
|
|
44
|
+
return (value.length === 0 ? [] : [value]).map((val) => Array.isArray(val) ? val : [val]);
|
|
45
|
+
}
|
|
46
|
+
exports.SHOW_CHILD = SHOW_CHILD;
|
|
47
|
+
exports.SHOW_PARENT = SHOW_PARENT;
|
|
48
|
+
exports.VALUE_SPLIT = VALUE_SPLIT;
|
|
49
|
+
exports.fillFieldNames = fillFieldNames;
|
|
50
|
+
exports.getFullPathKeys = getFullPathKeys;
|
|
51
|
+
exports.isLeaf = isLeaf;
|
|
52
|
+
exports.scrollIntoParentView = scrollIntoParentView;
|
|
53
|
+
exports.toPathKey = toPathKey;
|
|
54
|
+
exports.toPathKeys = toPathKeys;
|
|
55
|
+
exports.toPathValueStr = toPathValueStr;
|
|
56
|
+
exports.toRawValues = toRawValues;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DefaultOptionType, FieldNames, InternalFieldNames, InternalValueType, SingleValueType } from '../Cascader';
|
|
2
|
+
export declare const VALUE_SPLIT = "__VC_CASCADER_SPLIT__";
|
|
3
|
+
export declare const SHOW_PARENT = "SHOW_PARENT";
|
|
4
|
+
export declare const SHOW_CHILD = "SHOW_CHILD";
|
|
5
|
+
/**
|
|
6
|
+
* Will convert value to string, and join with `VALUE_SPLIT`
|
|
7
|
+
*/
|
|
8
|
+
export declare function toPathKey(value: SingleValueType): string;
|
|
9
|
+
/**
|
|
10
|
+
* Batch convert value to string, and join with `VALUE_SPLIT`
|
|
11
|
+
*/
|
|
12
|
+
export declare function toPathKeys(value: SingleValueType[]): string[];
|
|
13
|
+
export declare function toPathValueStr(pathKey: string): string[];
|
|
14
|
+
export declare function fillFieldNames(fieldNames?: FieldNames): InternalFieldNames;
|
|
15
|
+
export declare function isLeaf(option: DefaultOptionType, fieldNames: FieldNames): boolean;
|
|
16
|
+
export declare function scrollIntoParentView(element: HTMLElement): void;
|
|
17
|
+
export declare function getFullPathKeys(options: DefaultOptionType[], fieldNames: FieldNames): any[];
|
|
18
|
+
export declare function toRawValues(value?: InternalValueType): SingleValueType[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SEARCH_MARK } from "../hooks/useSearchOptions.js";
|
|
2
|
+
const VALUE_SPLIT = "__VC_CASCADER_SPLIT__";
|
|
3
|
+
const SHOW_PARENT = "SHOW_PARENT";
|
|
4
|
+
const SHOW_CHILD = "SHOW_CHILD";
|
|
5
|
+
function toPathKey(value) {
|
|
6
|
+
return value.join(VALUE_SPLIT);
|
|
7
|
+
}
|
|
8
|
+
function toPathKeys(value) {
|
|
9
|
+
return value.map(toPathKey);
|
|
10
|
+
}
|
|
11
|
+
function toPathValueStr(pathKey) {
|
|
12
|
+
return pathKey.split(VALUE_SPLIT);
|
|
13
|
+
}
|
|
14
|
+
function fillFieldNames(fieldNames) {
|
|
15
|
+
const { label, value, children } = fieldNames || {};
|
|
16
|
+
const val = value || "value";
|
|
17
|
+
return {
|
|
18
|
+
label: label || "label",
|
|
19
|
+
value: val,
|
|
20
|
+
key: val,
|
|
21
|
+
children: children || "children"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function isLeaf(option, fieldNames) {
|
|
25
|
+
return option.isLeaf ?? !option[fieldNames.children]?.length;
|
|
26
|
+
}
|
|
27
|
+
function scrollIntoParentView(element) {
|
|
28
|
+
const parent = element.parentElement;
|
|
29
|
+
if (!parent) return;
|
|
30
|
+
const elementToParent = element.offsetTop - parent.offsetTop;
|
|
31
|
+
if (elementToParent - parent.scrollTop < 0) parent.scrollTo({ top: elementToParent });
|
|
32
|
+
else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight });
|
|
33
|
+
}
|
|
34
|
+
function getFullPathKeys(options, fieldNames) {
|
|
35
|
+
return options.map((item) => item[SEARCH_MARK]?.map((opt) => opt[fieldNames.value]));
|
|
36
|
+
}
|
|
37
|
+
function isMultipleValue(value) {
|
|
38
|
+
return Array.isArray(value) && Array.isArray(value[0]);
|
|
39
|
+
}
|
|
40
|
+
function toRawValues(value) {
|
|
41
|
+
if (!value) return [];
|
|
42
|
+
if (isMultipleValue(value)) return value;
|
|
43
|
+
return (value.length === 0 ? [] : [value]).map((val) => Array.isArray(val) ? val : [val]);
|
|
44
|
+
}
|
|
45
|
+
export { SHOW_CHILD, SHOW_PARENT, VALUE_SPLIT, fillFieldNames, getFullPathKeys, isLeaf, scrollIntoParentView, toPathKey, toPathKeys, toPathValueStr, toRawValues };
|