@v-c/tree-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/LegacyContext.cjs +12 -0
- package/dist/LegacyContext.d.ts +25 -0
- package/dist/LegacyContext.js +9 -0
- package/dist/OptionList.cjs +230 -0
- package/dist/OptionList.d.ts +2 -0
- package/dist/OptionList.js +223 -0
- package/dist/TreeNode.cjs +11 -0
- package/dist/TreeNode.d.ts +7 -0
- package/dist/TreeNode.js +5 -0
- package/dist/TreeSelect.cjs +953 -0
- package/dist/TreeSelect.d.ts +76 -0
- package/dist/TreeSelect.js +947 -0
- package/dist/TreeSelectContext.cjs +12 -0
- package/dist/TreeSelectContext.d.ts +28 -0
- package/dist/TreeSelectContext.js +9 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/useCache.cjs +25 -0
- package/dist/hooks/useCache.d.ts +6 -0
- package/dist/hooks/useCache.js +20 -0
- package/dist/hooks/useCheckedKeys.cjs +25 -0
- package/dist/hooks/useCheckedKeys.d.ts +4 -0
- package/dist/hooks/useCheckedKeys.js +20 -0
- package/dist/hooks/useDataEntities.cjs +40 -0
- package/dist/hooks/useDataEntities.d.ts +7 -0
- package/dist/hooks/useDataEntities.js +35 -0
- package/dist/hooks/useFilterTreeData.cjs +28 -0
- package/dist/hooks/useFilterTreeData.d.ts +8 -0
- package/dist/hooks/useFilterTreeData.js +23 -0
- package/dist/hooks/useRefFunc.cjs +15 -0
- package/dist/hooks/useRefFunc.d.ts +5 -0
- package/dist/hooks/useRefFunc.js +10 -0
- package/dist/hooks/useSearchConfig.cjs +23 -0
- package/dist/hooks/useSearchConfig.d.ts +6 -0
- package/dist/hooks/useSearchConfig.js +18 -0
- package/dist/hooks/useTreeData.cjs +43 -0
- package/dist/hooks/useTreeData.d.ts +6 -0
- package/dist/hooks/useTreeData.js +38 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +10 -0
- package/dist/interface.cjs +1 -0
- package/dist/interface.d.ts +57 -0
- package/dist/interface.js +0 -0
- package/dist/utils/legacyUtil.cjs +85 -0
- package/dist/utils/legacyUtil.d.ts +5 -0
- package/dist/utils/legacyUtil.js +80 -0
- package/dist/utils/strategyUtil.cjs +22 -0
- package/dist/utils/strategyUtil.d.ts +7 -0
- package/dist/utils/strategyUtil.js +18 -0
- package/dist/utils/valueUtil.cjs +36 -0
- package/dist/utils/valueUtil.d.ts +11 -0
- package/dist/utils/valueUtil.js +31 -0
- package/dist/utils/warningPropsUtil.cjs +18 -0
- package/dist/utils/warningPropsUtil.d.ts +4 -0
- package/dist/utils/warningPropsUtil.js +12 -0
- package/package.json +43 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
var TreeSelectContextKey = Symbol("TreeSelectContext");
|
|
5
|
+
function useTreeSelectProvider(value) {
|
|
6
|
+
(0, vue.provide)(TreeSelectContextKey, value);
|
|
7
|
+
}
|
|
8
|
+
function useTreeSelectContext() {
|
|
9
|
+
return (0, vue.inject)(TreeSelectContextKey, (0, vue.ref)(null));
|
|
10
|
+
}
|
|
11
|
+
exports.useTreeSelectContext = useTreeSelectContext;
|
|
12
|
+
exports.useTreeSelectProvider = useTreeSelectProvider;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataEntity, ExpandAction } from '@v-c/tree';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { DataNode, FieldNames, Key, SelectSource } from './interface';
|
|
4
|
+
import { TreeSelectProps } from './TreeSelect';
|
|
5
|
+
export interface TreeSelectContextProps {
|
|
6
|
+
virtual?: boolean;
|
|
7
|
+
popupMatchSelectWidth?: boolean | number;
|
|
8
|
+
listHeight: number;
|
|
9
|
+
listItemHeight: number;
|
|
10
|
+
listItemScrollOffset?: number;
|
|
11
|
+
treeData: DataNode[];
|
|
12
|
+
fieldNames: FieldNames;
|
|
13
|
+
onSelect: (value: Key, info: {
|
|
14
|
+
selected: boolean;
|
|
15
|
+
source?: SelectSource;
|
|
16
|
+
}) => void;
|
|
17
|
+
treeExpandAction?: ExpandAction;
|
|
18
|
+
treeTitleRender?: (node: any) => any;
|
|
19
|
+
onPopupScroll?: (event: Event) => void;
|
|
20
|
+
leftMaxCount: number | null;
|
|
21
|
+
/** When `true`, only take leaf node as count, or take all as count with `maxCount` limitation */
|
|
22
|
+
leafCountOnly: boolean;
|
|
23
|
+
valueEntities: Map<Key, DataEntity>;
|
|
24
|
+
classNames?: TreeSelectProps['classNames'];
|
|
25
|
+
styles?: TreeSelectProps['styles'];
|
|
26
|
+
}
|
|
27
|
+
export declare function useTreeSelectProvider(value: Ref<TreeSelectContextProps>): void;
|
|
28
|
+
export declare function useTreeSelectContext(): Ref<TreeSelectContextProps | null>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { inject, provide, ref } from "vue";
|
|
2
|
+
var TreeSelectContextKey = Symbol("TreeSelectContext");
|
|
3
|
+
function useTreeSelectProvider(value) {
|
|
4
|
+
provide(TreeSelectContextKey, value);
|
|
5
|
+
}
|
|
6
|
+
function useTreeSelectContext() {
|
|
7
|
+
return inject(TreeSelectContextKey, ref(null));
|
|
8
|
+
}
|
|
9
|
+
export { useTreeSelectContext, useTreeSelectProvider };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: ((k) => from[k]).bind(null, key),
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
value: mod,
|
|
19
|
+
enumerable: true
|
|
20
|
+
}) : target, mod));
|
|
21
|
+
exports.__toESM = __toESM;
|
|
@@ -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
|
+
let vue = require("vue");
|
|
7
|
+
function useCache(values) {
|
|
8
|
+
const cacheRef = (0, vue.shallowRef)({ valueLabels: /* @__PURE__ */ new Map() });
|
|
9
|
+
return [(0, vue.computed)(() => {
|
|
10
|
+
const { valueLabels } = cacheRef.value;
|
|
11
|
+
const valueLabelsCache = /* @__PURE__ */ new Map();
|
|
12
|
+
const merged = values.value.map((item) => {
|
|
13
|
+
const { value, label } = item;
|
|
14
|
+
const mergedLabel = label ?? valueLabels.get(value);
|
|
15
|
+
valueLabelsCache.set(value, mergedLabel);
|
|
16
|
+
return {
|
|
17
|
+
...item,
|
|
18
|
+
label: mergedLabel
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
cacheRef.value.valueLabels = valueLabelsCache;
|
|
22
|
+
return merged;
|
|
23
|
+
})];
|
|
24
|
+
}
|
|
25
|
+
exports.default = useCache;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { LabeledValueType } from '../interface';
|
|
3
|
+
/**
|
|
4
|
+
* This function will try to cache labels for values to avoid label missing when options removed.
|
|
5
|
+
*/
|
|
6
|
+
export default function useCache(values: Ref<LabeledValueType[]>): [Ref<LabeledValueType[]>];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { computed, shallowRef } from "vue";
|
|
2
|
+
function useCache(values) {
|
|
3
|
+
const cacheRef = shallowRef({ valueLabels: /* @__PURE__ */ new Map() });
|
|
4
|
+
return [computed(() => {
|
|
5
|
+
const { valueLabels } = cacheRef.value;
|
|
6
|
+
const valueLabelsCache = /* @__PURE__ */ new Map();
|
|
7
|
+
const merged = values.value.map((item) => {
|
|
8
|
+
const { value, label } = item;
|
|
9
|
+
const mergedLabel = label ?? valueLabels.get(value);
|
|
10
|
+
valueLabelsCache.set(value, mergedLabel);
|
|
11
|
+
return {
|
|
12
|
+
...item,
|
|
13
|
+
label: mergedLabel
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
cacheRef.value.valueLabels = valueLabelsCache;
|
|
17
|
+
return merged;
|
|
18
|
+
})];
|
|
19
|
+
}
|
|
20
|
+
export { useCache 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
|
+
let vue = require("vue");
|
|
7
|
+
let _v_c_tree = require("@v-c/tree");
|
|
8
|
+
function useCheckedKeys(rawLabeledValues, rawHalfCheckedValues, treeConduction, keyEntities) {
|
|
9
|
+
const merged = (0, vue.computed)(() => {
|
|
10
|
+
const extractValues = (values) => values.map(({ value }) => value);
|
|
11
|
+
const checkedKeys = extractValues(rawLabeledValues.value);
|
|
12
|
+
const halfCheckedKeys = extractValues(rawHalfCheckedValues.value);
|
|
13
|
+
const missingValues = checkedKeys.filter((key) => !keyEntities.value[String(key)]);
|
|
14
|
+
let finalCheckedKeys = checkedKeys;
|
|
15
|
+
let finalHalfCheckedKeys = halfCheckedKeys;
|
|
16
|
+
if (treeConduction.value) {
|
|
17
|
+
const conductResult = (0, _v_c_tree.conductCheck)(checkedKeys, true, keyEntities.value);
|
|
18
|
+
finalCheckedKeys = conductResult.checkedKeys;
|
|
19
|
+
finalHalfCheckedKeys = conductResult.halfCheckedKeys;
|
|
20
|
+
}
|
|
21
|
+
return [Array.from(new Set([...missingValues, ...finalCheckedKeys])), finalHalfCheckedKeys];
|
|
22
|
+
});
|
|
23
|
+
return [(0, vue.computed)(() => merged.value[0]), (0, vue.computed)(() => merged.value[1])];
|
|
24
|
+
}
|
|
25
|
+
exports.default = useCheckedKeys;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DataEntity } from '@v-c/tree';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { Key, LabeledValueType } from '../interface';
|
|
4
|
+
export default function useCheckedKeys(rawLabeledValues: Ref<LabeledValueType[]>, rawHalfCheckedValues: Ref<LabeledValueType[]>, treeConduction: Ref<boolean>, keyEntities: Ref<Record<string, DataEntity>>): readonly [Ref<Key[]>, Ref<Key[]>];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { conductCheck } from "@v-c/tree";
|
|
3
|
+
function useCheckedKeys(rawLabeledValues, rawHalfCheckedValues, treeConduction, keyEntities) {
|
|
4
|
+
const merged = computed(() => {
|
|
5
|
+
const extractValues = (values) => values.map(({ value }) => value);
|
|
6
|
+
const checkedKeys = extractValues(rawLabeledValues.value);
|
|
7
|
+
const halfCheckedKeys = extractValues(rawHalfCheckedValues.value);
|
|
8
|
+
const missingValues = checkedKeys.filter((key) => !keyEntities.value[String(key)]);
|
|
9
|
+
let finalCheckedKeys = checkedKeys;
|
|
10
|
+
let finalHalfCheckedKeys = halfCheckedKeys;
|
|
11
|
+
if (treeConduction.value) {
|
|
12
|
+
const conductResult = conductCheck(checkedKeys, true, keyEntities.value);
|
|
13
|
+
finalCheckedKeys = conductResult.checkedKeys;
|
|
14
|
+
finalHalfCheckedKeys = conductResult.halfCheckedKeys;
|
|
15
|
+
}
|
|
16
|
+
return [Array.from(new Set([...missingValues, ...finalCheckedKeys])), finalHalfCheckedKeys];
|
|
17
|
+
});
|
|
18
|
+
return [computed(() => merged.value[0]), computed(() => merged.value[1])];
|
|
19
|
+
}
|
|
20
|
+
export { useCheckedKeys as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
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_valueUtil = require("../utils/valueUtil.cjs");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
let _v_c_tree = require("@v-c/tree");
|
|
9
|
+
let _v_c_util = require("@v-c/util");
|
|
10
|
+
function useDataEntities(treeData, fieldNames) {
|
|
11
|
+
const valueEntities = (0, vue.shallowRef)(/* @__PURE__ */ new Map());
|
|
12
|
+
const keyEntities = (0, vue.shallowRef)({});
|
|
13
|
+
(0, vue.watchEffect)(() => {
|
|
14
|
+
const mergedFieldNames = fieldNames.value;
|
|
15
|
+
const collection = (0, _v_c_tree.convertDataToEntities)(treeData.value, {
|
|
16
|
+
fieldNames: mergedFieldNames,
|
|
17
|
+
initWrapper: (wrapper) => ({
|
|
18
|
+
...wrapper,
|
|
19
|
+
valueEntities: /* @__PURE__ */ new Map()
|
|
20
|
+
}),
|
|
21
|
+
processEntity: (entity, wrapper) => {
|
|
22
|
+
const val = entity.node[mergedFieldNames.value];
|
|
23
|
+
if (process.env.NODE_ENV !== "production") {
|
|
24
|
+
const key = entity.node.key;
|
|
25
|
+
(0, _v_c_util.warning)(!require_valueUtil.isNil(val), "TreeNode `value` is invalidate: undefined");
|
|
26
|
+
(0, _v_c_util.warning)(!wrapper.valueEntities.has(val), `Same \`value\` exist in the tree: ${val}`);
|
|
27
|
+
(0, _v_c_util.warning)(!key || String(key) === String(val), `\`key\` or \`value\` with TreeNode must be the same or you can remove one of them. key: ${key}, value: ${val}.`);
|
|
28
|
+
}
|
|
29
|
+
wrapper.valueEntities.set(val, entity);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
keyEntities.value = collection.keyEntities;
|
|
33
|
+
valueEntities.value = collection.valueEntities;
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
valueEntities,
|
|
37
|
+
keyEntities
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.default = useDataEntities;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataEntity, KeyEntities } from '@v-c/tree';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { DataNode, FieldNames, SafeKey } from '../interface';
|
|
4
|
+
export default function useDataEntities(treeData: Ref<DataNode[]>, fieldNames: Ref<FieldNames>): {
|
|
5
|
+
valueEntities: Ref<Map<SafeKey, DataEntity>>;
|
|
6
|
+
keyEntities: Ref<KeyEntities>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isNil } from "../utils/valueUtil.js";
|
|
2
|
+
import { shallowRef, watchEffect } from "vue";
|
|
3
|
+
import { convertDataToEntities } from "@v-c/tree";
|
|
4
|
+
import { warning } from "@v-c/util";
|
|
5
|
+
function useDataEntities(treeData, fieldNames) {
|
|
6
|
+
const valueEntities = shallowRef(/* @__PURE__ */ new Map());
|
|
7
|
+
const keyEntities = shallowRef({});
|
|
8
|
+
watchEffect(() => {
|
|
9
|
+
const mergedFieldNames = fieldNames.value;
|
|
10
|
+
const collection = convertDataToEntities(treeData.value, {
|
|
11
|
+
fieldNames: mergedFieldNames,
|
|
12
|
+
initWrapper: (wrapper) => ({
|
|
13
|
+
...wrapper,
|
|
14
|
+
valueEntities: /* @__PURE__ */ new Map()
|
|
15
|
+
}),
|
|
16
|
+
processEntity: (entity, wrapper) => {
|
|
17
|
+
const val = entity.node[mergedFieldNames.value];
|
|
18
|
+
if (process.env.NODE_ENV !== "production") {
|
|
19
|
+
const key = entity.node.key;
|
|
20
|
+
warning(!isNil(val), "TreeNode `value` is invalidate: undefined");
|
|
21
|
+
warning(!wrapper.valueEntities.has(val), `Same \`value\` exist in the tree: ${val}`);
|
|
22
|
+
warning(!key || String(key) === String(val), `\`key\` or \`value\` with TreeNode must be the same or you can remove one of them. key: ${key}, value: ${val}.`);
|
|
23
|
+
}
|
|
24
|
+
wrapper.valueEntities.set(val, entity);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
keyEntities.value = collection.keyEntities;
|
|
28
|
+
valueEntities.value = collection.valueEntities;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
valueEntities,
|
|
32
|
+
keyEntities
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { useDataEntities as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
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_legacyUtil = require("../utils/legacyUtil.cjs");
|
|
7
|
+
let vue = require("vue");
|
|
8
|
+
function useFilterTreeData(treeData, searchValue, options) {
|
|
9
|
+
return (0, vue.computed)(() => {
|
|
10
|
+
const { children: fieldChildren } = options.fieldNames.value;
|
|
11
|
+
const mergedSearchValue = searchValue.value;
|
|
12
|
+
if (!mergedSearchValue || options.filterTreeNode.value === false) return treeData.value;
|
|
13
|
+
const filterOptionFunc = typeof options.filterTreeNode.value === "function" ? options.filterTreeNode.value : (_, dataNode) => String(dataNode[options.treeNodeFilterProp.value]).toUpperCase().includes(mergedSearchValue.toUpperCase());
|
|
14
|
+
const filterTreeNodes = (nodes, keepAll = false) => nodes.reduce((filtered, node) => {
|
|
15
|
+
const children = node[fieldChildren];
|
|
16
|
+
const isMatch = keepAll || filterOptionFunc(mergedSearchValue, require_legacyUtil.fillLegacyProps(node));
|
|
17
|
+
const filteredChildren = filterTreeNodes(children || [], isMatch);
|
|
18
|
+
if (isMatch || filteredChildren.length) filtered.push({
|
|
19
|
+
...node,
|
|
20
|
+
isLeaf: void 0,
|
|
21
|
+
[fieldChildren]: filteredChildren
|
|
22
|
+
});
|
|
23
|
+
return filtered;
|
|
24
|
+
}, []);
|
|
25
|
+
return filterTreeNodes(treeData.value);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.default = useFilterTreeData;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DataNode, FieldNames } from '../interface';
|
|
3
|
+
import { TreeSelectProps } from '../TreeSelect';
|
|
4
|
+
export default function useFilterTreeData(treeData: Ref<DataNode[]>, searchValue: Ref<string>, options: {
|
|
5
|
+
fieldNames: Ref<FieldNames>;
|
|
6
|
+
treeNodeFilterProp: Ref<string>;
|
|
7
|
+
filterTreeNode: Ref<TreeSelectProps['filterTreeNode']>;
|
|
8
|
+
}): Ref<DataNode[]>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fillLegacyProps } from "../utils/legacyUtil.js";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
function useFilterTreeData(treeData, searchValue, options) {
|
|
4
|
+
return computed(() => {
|
|
5
|
+
const { children: fieldChildren } = options.fieldNames.value;
|
|
6
|
+
const mergedSearchValue = searchValue.value;
|
|
7
|
+
if (!mergedSearchValue || options.filterTreeNode.value === false) return treeData.value;
|
|
8
|
+
const filterOptionFunc = typeof options.filterTreeNode.value === "function" ? options.filterTreeNode.value : (_, dataNode) => String(dataNode[options.treeNodeFilterProp.value]).toUpperCase().includes(mergedSearchValue.toUpperCase());
|
|
9
|
+
const filterTreeNodes = (nodes, keepAll = false) => nodes.reduce((filtered, node) => {
|
|
10
|
+
const children = node[fieldChildren];
|
|
11
|
+
const isMatch = keepAll || filterOptionFunc(mergedSearchValue, fillLegacyProps(node));
|
|
12
|
+
const filteredChildren = filterTreeNodes(children || [], isMatch);
|
|
13
|
+
if (isMatch || filteredChildren.length) filtered.push({
|
|
14
|
+
...node,
|
|
15
|
+
isLeaf: void 0,
|
|
16
|
+
[fieldChildren]: filteredChildren
|
|
17
|
+
});
|
|
18
|
+
return filtered;
|
|
19
|
+
}, []);
|
|
20
|
+
return filterTreeNodes(treeData.value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { useFilterTreeData as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
function useRefFunc(callback) {
|
|
8
|
+
const callbackRef = (0, vue.shallowRef)(callback);
|
|
9
|
+
callbackRef.value = callback;
|
|
10
|
+
const cacheFn = ((...args) => {
|
|
11
|
+
return callbackRef.value(...args);
|
|
12
|
+
});
|
|
13
|
+
return cacheFn;
|
|
14
|
+
}
|
|
15
|
+
exports.default = useRefFunc;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
|
+
function useRefFunc(callback) {
|
|
3
|
+
const callbackRef = shallowRef(callback);
|
|
4
|
+
callbackRef.value = callback;
|
|
5
|
+
const cacheFn = ((...args) => {
|
|
6
|
+
return callbackRef.value(...args);
|
|
7
|
+
});
|
|
8
|
+
return cacheFn;
|
|
9
|
+
}
|
|
10
|
+
export { useRefFunc as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
function useSearchConfig(showSearch, props) {
|
|
8
|
+
return [(0, vue.computed)(() => {
|
|
9
|
+
return typeof showSearch.value === "object" ? true : showSearch.value;
|
|
10
|
+
}), (0, vue.computed)(() => {
|
|
11
|
+
const { searchValue, inputValue, onSearch, autoClearSearchValue, filterTreeNode, treeNodeFilterProp } = props.value;
|
|
12
|
+
const isObject = typeof showSearch.value === "object";
|
|
13
|
+
return {
|
|
14
|
+
searchValue: searchValue ?? inputValue,
|
|
15
|
+
onSearch,
|
|
16
|
+
autoClearSearchValue,
|
|
17
|
+
filterTreeNode,
|
|
18
|
+
treeNodeFilterProp,
|
|
19
|
+
...isObject ? showSearch.value : {}
|
|
20
|
+
};
|
|
21
|
+
})];
|
|
22
|
+
}
|
|
23
|
+
exports.default = useSearchConfig;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { SearchConfig } from '../TreeSelect';
|
|
3
|
+
export type SearchConfigResult = [Ref<boolean | undefined>, Ref<SearchConfig>];
|
|
4
|
+
export default function useSearchConfig(showSearch: Ref<boolean | SearchConfig | undefined>, props: Ref<SearchConfig & {
|
|
5
|
+
inputValue?: string;
|
|
6
|
+
}>): SearchConfigResult;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function useSearchConfig(showSearch, props) {
|
|
3
|
+
return [computed(() => {
|
|
4
|
+
return typeof showSearch.value === "object" ? true : showSearch.value;
|
|
5
|
+
}), computed(() => {
|
|
6
|
+
const { searchValue, inputValue, onSearch, autoClearSearchValue, filterTreeNode, treeNodeFilterProp } = props.value;
|
|
7
|
+
const isObject = typeof showSearch.value === "object";
|
|
8
|
+
return {
|
|
9
|
+
searchValue: searchValue ?? inputValue,
|
|
10
|
+
onSearch,
|
|
11
|
+
autoClearSearchValue,
|
|
12
|
+
filterTreeNode,
|
|
13
|
+
treeNodeFilterProp,
|
|
14
|
+
...isObject ? showSearch.value : {}
|
|
15
|
+
};
|
|
16
|
+
})];
|
|
17
|
+
}
|
|
18
|
+
export { useSearchConfig as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
function buildTreeStructure(nodes, config) {
|
|
8
|
+
const { id, pId, rootPId } = config;
|
|
9
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
10
|
+
const rootNodes = [];
|
|
11
|
+
nodes.forEach((node) => {
|
|
12
|
+
const nodeKey = node[id];
|
|
13
|
+
const clonedNode = {
|
|
14
|
+
...node,
|
|
15
|
+
key: node.key || nodeKey
|
|
16
|
+
};
|
|
17
|
+
nodeMap.set(nodeKey, clonedNode);
|
|
18
|
+
});
|
|
19
|
+
nodeMap.forEach((node) => {
|
|
20
|
+
const parentKey = node[pId];
|
|
21
|
+
const parent = nodeMap.get(parentKey);
|
|
22
|
+
if (parent) {
|
|
23
|
+
parent.children = parent.children || [];
|
|
24
|
+
parent.children.push(node);
|
|
25
|
+
} else if (parentKey === rootPId || rootPId === null) rootNodes.push(node);
|
|
26
|
+
});
|
|
27
|
+
return rootNodes;
|
|
28
|
+
}
|
|
29
|
+
function useTreeData(treeData, simpleMode) {
|
|
30
|
+
return (0, vue.computed)(() => {
|
|
31
|
+
if (simpleMode.value) {
|
|
32
|
+
const config = {
|
|
33
|
+
id: "id",
|
|
34
|
+
pId: "pId",
|
|
35
|
+
rootPId: null,
|
|
36
|
+
...typeof simpleMode.value === "object" ? simpleMode.value : {}
|
|
37
|
+
};
|
|
38
|
+
return buildTreeStructure(treeData.value, config);
|
|
39
|
+
}
|
|
40
|
+
return treeData.value;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.default = useTreeData;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { DataNode, SimpleModeConfig } from '../interface';
|
|
3
|
+
/**
|
|
4
|
+
* Convert `treeData` by `simpleMode` config.
|
|
5
|
+
*/
|
|
6
|
+
export default function useTreeData(treeData: Ref<DataNode[]>, simpleMode: Ref<boolean | SimpleModeConfig | undefined>): Ref<DataNode[]>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function buildTreeStructure(nodes, config) {
|
|
3
|
+
const { id, pId, rootPId } = config;
|
|
4
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
5
|
+
const rootNodes = [];
|
|
6
|
+
nodes.forEach((node) => {
|
|
7
|
+
const nodeKey = node[id];
|
|
8
|
+
const clonedNode = {
|
|
9
|
+
...node,
|
|
10
|
+
key: node.key || nodeKey
|
|
11
|
+
};
|
|
12
|
+
nodeMap.set(nodeKey, clonedNode);
|
|
13
|
+
});
|
|
14
|
+
nodeMap.forEach((node) => {
|
|
15
|
+
const parentKey = node[pId];
|
|
16
|
+
const parent = nodeMap.get(parentKey);
|
|
17
|
+
if (parent) {
|
|
18
|
+
parent.children = parent.children || [];
|
|
19
|
+
parent.children.push(node);
|
|
20
|
+
} else if (parentKey === rootPId || rootPId === null) rootNodes.push(node);
|
|
21
|
+
});
|
|
22
|
+
return rootNodes;
|
|
23
|
+
}
|
|
24
|
+
function useTreeData(treeData, simpleMode) {
|
|
25
|
+
return computed(() => {
|
|
26
|
+
if (simpleMode.value) {
|
|
27
|
+
const config = {
|
|
28
|
+
id: "id",
|
|
29
|
+
pId: "pId",
|
|
30
|
+
rootPId: null,
|
|
31
|
+
...typeof simpleMode.value === "object" ? simpleMode.value : {}
|
|
32
|
+
};
|
|
33
|
+
return buildTreeStructure(treeData.value, config);
|
|
34
|
+
}
|
|
35
|
+
return treeData.value;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export { useTreeData as default };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_TreeNode = require("./TreeNode.cjs");
|
|
6
|
+
const require_strategyUtil = require("./utils/strategyUtil.cjs");
|
|
7
|
+
const require_TreeSelect = require("./TreeSelect.cjs");
|
|
8
|
+
var ExportTreeSelect = require_TreeSelect.default;
|
|
9
|
+
ExportTreeSelect.TreeNode = require_TreeNode.default;
|
|
10
|
+
ExportTreeSelect.SHOW_ALL = require_strategyUtil.SHOW_ALL;
|
|
11
|
+
ExportTreeSelect.SHOW_PARENT = require_strategyUtil.SHOW_PARENT;
|
|
12
|
+
ExportTreeSelect.SHOW_CHILD = require_strategyUtil.SHOW_CHILD;
|
|
13
|
+
var src_default = ExportTreeSelect;
|
|
14
|
+
exports.SHOW_ALL = require_strategyUtil.SHOW_ALL;
|
|
15
|
+
exports.SHOW_CHILD = require_strategyUtil.SHOW_CHILD;
|
|
16
|
+
exports.SHOW_PARENT = require_strategyUtil.SHOW_PARENT;
|
|
17
|
+
exports.TreeNode = require_TreeNode.default;
|
|
18
|
+
exports.default = src_default;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TreeSelectProps, default as TreeSelect } from './TreeSelect';
|
|
2
|
+
import { default as TreeNode } from './TreeNode';
|
|
3
|
+
import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from './utils/strategyUtil';
|
|
4
|
+
export { SHOW_ALL, SHOW_CHILD, SHOW_PARENT, TreeNode };
|
|
5
|
+
export type { TreeSelectProps };
|
|
6
|
+
type TreeSelectType = typeof TreeSelect & {
|
|
7
|
+
TreeNode: typeof TreeNode;
|
|
8
|
+
SHOW_ALL: typeof SHOW_ALL;
|
|
9
|
+
SHOW_PARENT: typeof SHOW_PARENT;
|
|
10
|
+
SHOW_CHILD: typeof SHOW_CHILD;
|
|
11
|
+
};
|
|
12
|
+
declare const ExportTreeSelect: TreeSelectType;
|
|
13
|
+
export default ExportTreeSelect;
|
|
14
|
+
export type { DataNode } from './interface';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import TreeNode_default from "./TreeNode.js";
|
|
2
|
+
import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from "./utils/strategyUtil.js";
|
|
3
|
+
import TreeSelect_default from "./TreeSelect.js";
|
|
4
|
+
var ExportTreeSelect = TreeSelect_default;
|
|
5
|
+
ExportTreeSelect.TreeNode = TreeNode_default;
|
|
6
|
+
ExportTreeSelect.SHOW_ALL = SHOW_ALL;
|
|
7
|
+
ExportTreeSelect.SHOW_PARENT = SHOW_PARENT;
|
|
8
|
+
ExportTreeSelect.SHOW_CHILD = SHOW_CHILD;
|
|
9
|
+
var src_default = ExportTreeSelect;
|
|
10
|
+
export { SHOW_ALL, SHOW_CHILD, SHOW_PARENT, TreeNode_default as TreeNode, src_default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Key, DataNode as TreeDataNode } from '@v-c/tree';
|
|
2
|
+
export type { Key };
|
|
3
|
+
export type SafeKey = Key;
|
|
4
|
+
export interface DataNode extends Record<string, any>, Omit<TreeDataNode, 'key' | 'children'> {
|
|
5
|
+
key?: Key;
|
|
6
|
+
value?: Key;
|
|
7
|
+
children?: DataNode[];
|
|
8
|
+
}
|
|
9
|
+
export type SelectSource = 'option' | 'selection' | 'input' | 'clear';
|
|
10
|
+
export interface LabeledValueType {
|
|
11
|
+
key?: Key;
|
|
12
|
+
value?: Key;
|
|
13
|
+
label?: any;
|
|
14
|
+
/** Only works on `treeCheckStrictly` */
|
|
15
|
+
halfChecked?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type DefaultValueType = Key | LabeledValueType | (Key | LabeledValueType)[];
|
|
18
|
+
export interface LegacyDataNode extends DataNode {
|
|
19
|
+
props: any;
|
|
20
|
+
}
|
|
21
|
+
export interface FlattenDataNode {
|
|
22
|
+
data: DataNode;
|
|
23
|
+
key: Key;
|
|
24
|
+
value: Key;
|
|
25
|
+
level: number;
|
|
26
|
+
parent?: FlattenDataNode;
|
|
27
|
+
}
|
|
28
|
+
export interface SimpleModeConfig {
|
|
29
|
+
id?: string;
|
|
30
|
+
pId?: string;
|
|
31
|
+
rootPId?: SafeKey | null;
|
|
32
|
+
}
|
|
33
|
+
/** @deprecated This is only used for legacy compatible. Not works on new code. */
|
|
34
|
+
export interface LegacyCheckedNode {
|
|
35
|
+
pos: string;
|
|
36
|
+
node: any;
|
|
37
|
+
children?: LegacyCheckedNode[];
|
|
38
|
+
}
|
|
39
|
+
export interface ChangeEventExtra {
|
|
40
|
+
/** @deprecated Please save prev value by control logic instead */
|
|
41
|
+
preValue: LabeledValueType[];
|
|
42
|
+
triggerValue: Key;
|
|
43
|
+
/** @deprecated Use `onSelect` or `onDeselect` instead. */
|
|
44
|
+
selected?: boolean;
|
|
45
|
+
/** @deprecated Use `onSelect` or `onDeselect` instead. */
|
|
46
|
+
checked?: boolean;
|
|
47
|
+
/** @deprecated This prop not work as react node anymore. */
|
|
48
|
+
triggerNode: any;
|
|
49
|
+
/** @deprecated This prop not work as react node anymore. */
|
|
50
|
+
allCheckedNodes: LegacyCheckedNode[];
|
|
51
|
+
}
|
|
52
|
+
export interface FieldNames {
|
|
53
|
+
value?: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
children?: string;
|
|
56
|
+
_title?: string[];
|
|
57
|
+
}
|
|
File without changes
|