@v-c/tree-select 1.0.2 → 1.1.0-rc.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/dist/LegacyContext.js +2 -0
- package/dist/OptionList.js +10 -6
- package/dist/TreeNode.js +5 -2
- package/dist/TreeSelect.js +7 -5
- package/dist/TreeSelectContext.js +2 -0
- package/dist/hooks/useCache.js +5 -0
- package/dist/hooks/useCheckedKeys.js +2 -0
- package/dist/hooks/useDataEntities.js +2 -0
- package/dist/hooks/useFilterTreeData.js +2 -0
- package/dist/hooks/useRefFunc.js +6 -0
- package/dist/hooks/useSearchConfig.js +2 -0
- package/dist/hooks/useTreeData.js +5 -0
- package/dist/index.js +7 -6
- package/dist/utils/legacyUtil.js +4 -2
- package/dist/utils/strategyUtil.js +5 -3
- package/dist/utils/valueUtil.js +3 -1
- package/dist/utils/warningPropsUtil.js +2 -0
- package/package.json +4 -4
package/dist/LegacyContext.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inject, provide, ref } from "vue";
|
|
2
|
+
//#region src/LegacyContext.ts
|
|
2
3
|
var LegacyContextKey = Symbol("LegacyTreeSelectContext");
|
|
3
4
|
function useLegacyProvider(value) {
|
|
4
5
|
provide(LegacyContextKey, value);
|
|
@@ -6,4 +7,5 @@ function useLegacyProvider(value) {
|
|
|
6
7
|
function useLegacyContext() {
|
|
7
8
|
return inject(LegacyContextKey, ref(null));
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
9
11
|
export { useLegacyContext, useLegacyProvider };
|
package/dist/OptionList.js
CHANGED
|
@@ -5,6 +5,7 @@ import { computed, createVNode, defineComponent, provide, ref, shallowRef, watch
|
|
|
5
5
|
import { useBaseProps } from "@v-c/select";
|
|
6
6
|
import Tree, { UnstableContextKey } from "@v-c/tree";
|
|
7
7
|
import { KeyCode } from "@v-c/util";
|
|
8
|
+
//#region src/OptionList.tsx
|
|
8
9
|
var HIDDEN_STYLE = {
|
|
9
10
|
width: 0,
|
|
10
11
|
height: 0,
|
|
@@ -15,7 +16,7 @@ var HIDDEN_STYLE = {
|
|
|
15
16
|
padding: 0,
|
|
16
17
|
margin: 0
|
|
17
18
|
};
|
|
18
|
-
var
|
|
19
|
+
var OptionList = /* @__PURE__ */ defineComponent({
|
|
19
20
|
name: "OptionList",
|
|
20
21
|
inheritAttrs: false,
|
|
21
22
|
setup(_, { expose }) {
|
|
@@ -37,7 +38,7 @@ var OptionList_default = /* @__PURE__ */ defineComponent({
|
|
|
37
38
|
const onListMouseDown = (event) => {
|
|
38
39
|
event.preventDefault();
|
|
39
40
|
};
|
|
40
|
-
const onInternalSelect = (_
|
|
41
|
+
const onInternalSelect = (_, info) => {
|
|
41
42
|
const { node } = info;
|
|
42
43
|
if (legacyContext.value?.checkable && isCheckDisabled(node)) return;
|
|
43
44
|
const checkedKeys = legacyContext.value?.checkedKeys || [];
|
|
@@ -112,15 +113,17 @@ var OptionList_default = /* @__PURE__ */ defineComponent({
|
|
|
112
113
|
};
|
|
113
114
|
const activeKey = ref(null);
|
|
114
115
|
const activeEntity = computed(() => legacyContext.value?.keyEntities?.[String(activeKey.value)]);
|
|
115
|
-
watch(() =>
|
|
116
|
+
watch([() => baseProps.value?.open, () => baseProps.value?.searchValue], ([open]) => {
|
|
116
117
|
if (!open) return;
|
|
117
118
|
const fieldNames = context.value?.fieldNames;
|
|
118
119
|
const getFirstNode = () => {
|
|
119
120
|
const firstNode = getFirstMatchingNode(memoTreeData.value);
|
|
120
121
|
return firstNode ? firstNode[fieldNames?.value] : null;
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
let nextActiveKey = null;
|
|
124
|
+
if (!baseProps.value?.multiple && legacyContext.value?.checkedKeys?.length && !baseProps.value?.searchValue) nextActiveKey = legacyContext.value.checkedKeys[0];
|
|
125
|
+
else nextActiveKey = getFirstNode();
|
|
126
|
+
activeKey.value = nextActiveKey;
|
|
124
127
|
}, { immediate: true });
|
|
125
128
|
const onKeyDown = (event) => {
|
|
126
129
|
switch (event.which || event.keyCode) {
|
|
@@ -220,4 +223,5 @@ var OptionList_default = /* @__PURE__ */ defineComponent({
|
|
|
220
223
|
};
|
|
221
224
|
}
|
|
222
225
|
});
|
|
223
|
-
|
|
226
|
+
//#endregion
|
|
227
|
+
export { OptionList as default };
|
package/dist/TreeNode.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { defineComponent } from "vue";
|
|
2
|
-
|
|
2
|
+
//#region src/TreeNode.tsx
|
|
3
|
+
/** This is a placeholder, not real render in dom */
|
|
4
|
+
var TreeNode = /* @__PURE__ */ defineComponent(() => {
|
|
3
5
|
return () => null;
|
|
4
6
|
});
|
|
5
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { TreeNode as default };
|
package/dist/TreeSelect.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useLegacyProvider } from "./LegacyContext.js";
|
|
2
2
|
import { useTreeSelectProvider } from "./TreeSelectContext.js";
|
|
3
3
|
import { fillFieldNames, isNil, toArray } from "./utils/valueUtil.js";
|
|
4
|
-
import
|
|
4
|
+
import OptionList from "./OptionList.js";
|
|
5
5
|
import useCache from "./hooks/useCache.js";
|
|
6
6
|
import useCheckedKeys from "./hooks/useCheckedKeys.js";
|
|
7
7
|
import useDataEntities from "./hooks/useDataEntities.js";
|
|
@@ -10,13 +10,14 @@ import useFilterTreeData from "./hooks/useFilterTreeData.js";
|
|
|
10
10
|
import useRefFunc from "./hooks/useRefFunc.js";
|
|
11
11
|
import useSearchConfig from "./hooks/useSearchConfig.js";
|
|
12
12
|
import useTreeData from "./hooks/useTreeData.js";
|
|
13
|
-
import { SHOW_ALL,
|
|
13
|
+
import { SHOW_ALL, formatStrategyValues } from "./utils/strategyUtil.js";
|
|
14
14
|
import warningProps from "./utils/warningPropsUtil.js";
|
|
15
15
|
import { computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, watch } from "vue";
|
|
16
16
|
import { BaseSelect } from "@v-c/select";
|
|
17
17
|
import { conductCheck } from "@v-c/tree";
|
|
18
18
|
import { omit, useId, useMergedState } from "@v-c/util";
|
|
19
19
|
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
20
|
+
//#region src/TreeSelect.tsx
|
|
20
21
|
function isRawValue(value) {
|
|
21
22
|
return !value || typeof value !== "object";
|
|
22
23
|
}
|
|
@@ -76,7 +77,7 @@ var omitKeyList = [
|
|
|
76
77
|
"classNames",
|
|
77
78
|
"styles"
|
|
78
79
|
];
|
|
79
|
-
var
|
|
80
|
+
var TreeSelect = /* @__PURE__ */ defineComponent({
|
|
80
81
|
props: /* @__PURE__ */ mergeDefaults({
|
|
81
82
|
prefixCls: {
|
|
82
83
|
type: String,
|
|
@@ -936,7 +937,7 @@ var TreeSelect_default = /* @__PURE__ */ defineComponent({
|
|
|
936
937
|
"onSearch": (v) => {
|
|
937
938
|
onInternalSearch(v);
|
|
938
939
|
},
|
|
939
|
-
"OptionList":
|
|
940
|
+
"OptionList": OptionList,
|
|
940
941
|
"emptyOptions": !mergedTreeData.value.length,
|
|
941
942
|
"onPopupVisibleChange": onInternalPopupVisibleChange,
|
|
942
943
|
"popupMatchSelectWidth": props.popupMatchSelectWidth ?? defaults.popupMatchSelectWidth
|
|
@@ -944,4 +945,5 @@ var TreeSelect_default = /* @__PURE__ */ defineComponent({
|
|
|
944
945
|
};
|
|
945
946
|
}
|
|
946
947
|
});
|
|
947
|
-
|
|
948
|
+
//#endregion
|
|
949
|
+
export { TreeSelect as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inject, provide, ref } from "vue";
|
|
2
|
+
//#region src/TreeSelectContext.ts
|
|
2
3
|
var TreeSelectContextKey = Symbol("TreeSelectContext");
|
|
3
4
|
function useTreeSelectProvider(value) {
|
|
4
5
|
provide(TreeSelectContextKey, value);
|
|
@@ -6,4 +7,5 @@ function useTreeSelectProvider(value) {
|
|
|
6
7
|
function useTreeSelectContext() {
|
|
7
8
|
return inject(TreeSelectContextKey, ref(null));
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
9
11
|
export { useTreeSelectContext, useTreeSelectProvider };
|
package/dist/hooks/useCache.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { computed, shallowRef } from "vue";
|
|
2
|
+
//#region src/hooks/useCache.ts
|
|
3
|
+
/**
|
|
4
|
+
* This function will try to cache labels for values to avoid label missing when options removed.
|
|
5
|
+
*/
|
|
2
6
|
function useCache(values) {
|
|
3
7
|
const cacheRef = shallowRef({ valueLabels: /* @__PURE__ */ new Map() });
|
|
4
8
|
return [computed(() => {
|
|
@@ -17,4 +21,5 @@ function useCache(values) {
|
|
|
17
21
|
return merged;
|
|
18
22
|
})];
|
|
19
23
|
}
|
|
24
|
+
//#endregion
|
|
20
25
|
export { useCache as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import { conductCheck } from "@v-c/tree";
|
|
3
|
+
//#region src/hooks/useCheckedKeys.ts
|
|
3
4
|
function useCheckedKeys(rawLabeledValues, rawHalfCheckedValues, treeConduction, keyEntities) {
|
|
4
5
|
const merged = computed(() => {
|
|
5
6
|
const extractValues = (values) => values.map(({ value }) => value);
|
|
@@ -17,4 +18,5 @@ function useCheckedKeys(rawLabeledValues, rawHalfCheckedValues, treeConduction,
|
|
|
17
18
|
});
|
|
18
19
|
return [computed(() => merged.value[0]), computed(() => merged.value[1])];
|
|
19
20
|
}
|
|
21
|
+
//#endregion
|
|
20
22
|
export { useCheckedKeys as default };
|
|
@@ -2,6 +2,7 @@ import { isNil } from "../utils/valueUtil.js";
|
|
|
2
2
|
import { shallowRef, watchEffect } from "vue";
|
|
3
3
|
import { convertDataToEntities } from "@v-c/tree";
|
|
4
4
|
import { warning } from "@v-c/util";
|
|
5
|
+
//#region src/hooks/useDataEntities.ts
|
|
5
6
|
function useDataEntities(treeData, fieldNames) {
|
|
6
7
|
const valueEntities = shallowRef(/* @__PURE__ */ new Map());
|
|
7
8
|
const keyEntities = shallowRef({});
|
|
@@ -32,4 +33,5 @@ function useDataEntities(treeData, fieldNames) {
|
|
|
32
33
|
keyEntities
|
|
33
34
|
};
|
|
34
35
|
}
|
|
36
|
+
//#endregion
|
|
35
37
|
export { useDataEntities as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fillLegacyProps } from "../utils/legacyUtil.js";
|
|
2
2
|
import { computed } from "vue";
|
|
3
|
+
//#region src/hooks/useFilterTreeData.ts
|
|
3
4
|
function useFilterTreeData(treeData, searchValue, options) {
|
|
4
5
|
return computed(() => {
|
|
5
6
|
const { children: fieldChildren } = options.fieldNames.value;
|
|
@@ -20,4 +21,5 @@ function useFilterTreeData(treeData, searchValue, options) {
|
|
|
20
21
|
return filterTreeNodes(treeData.value);
|
|
21
22
|
});
|
|
22
23
|
}
|
|
24
|
+
//#endregion
|
|
23
25
|
export { useFilterTreeData as default };
|
package/dist/hooks/useRefFunc.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { shallowRef } from "vue";
|
|
2
|
+
//#region src/hooks/useRefFunc.ts
|
|
3
|
+
/**
|
|
4
|
+
* Same as `useCallback` but always return a memoized function
|
|
5
|
+
* which will call latest callback from ref.
|
|
6
|
+
*/
|
|
2
7
|
function useRefFunc(callback) {
|
|
3
8
|
const callbackRef = shallowRef(callback);
|
|
4
9
|
callbackRef.value = callback;
|
|
@@ -7,4 +12,5 @@ function useRefFunc(callback) {
|
|
|
7
12
|
});
|
|
8
13
|
return cacheFn;
|
|
9
14
|
}
|
|
15
|
+
//#endregion
|
|
10
16
|
export { useRefFunc as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
+
//#region src/hooks/useSearchConfig.ts
|
|
2
3
|
function useSearchConfig(showSearch, props) {
|
|
3
4
|
return [computed(() => {
|
|
4
5
|
return typeof showSearch.value === "object" ? true : showSearch.value;
|
|
@@ -15,4 +16,5 @@ function useSearchConfig(showSearch, props) {
|
|
|
15
16
|
};
|
|
16
17
|
})];
|
|
17
18
|
}
|
|
19
|
+
//#endregion
|
|
18
20
|
export { useSearchConfig as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
+
//#region src/hooks/useTreeData.ts
|
|
2
3
|
function buildTreeStructure(nodes, config) {
|
|
3
4
|
const { id, pId, rootPId } = config;
|
|
4
5
|
const nodeMap = /* @__PURE__ */ new Map();
|
|
@@ -21,6 +22,9 @@ function buildTreeStructure(nodes, config) {
|
|
|
21
22
|
});
|
|
22
23
|
return rootNodes;
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Convert `treeData` by `simpleMode` config.
|
|
27
|
+
*/
|
|
24
28
|
function useTreeData(treeData, simpleMode) {
|
|
25
29
|
return computed(() => {
|
|
26
30
|
if (simpleMode.value) {
|
|
@@ -35,4 +39,5 @@ function useTreeData(treeData, simpleMode) {
|
|
|
35
39
|
return treeData.value;
|
|
36
40
|
});
|
|
37
41
|
}
|
|
42
|
+
//#endregion
|
|
38
43
|
export { useTreeData as default };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TreeNode from "./TreeNode.js";
|
|
2
2
|
import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from "./utils/strategyUtil.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
ExportTreeSelect
|
|
3
|
+
import TreeSelect from "./TreeSelect.js";
|
|
4
|
+
//#region src/index.tsx
|
|
5
|
+
var ExportTreeSelect = TreeSelect;
|
|
6
|
+
ExportTreeSelect.TreeNode = TreeNode;
|
|
6
7
|
ExportTreeSelect.SHOW_ALL = SHOW_ALL;
|
|
7
8
|
ExportTreeSelect.SHOW_PARENT = SHOW_PARENT;
|
|
8
9
|
ExportTreeSelect.SHOW_CHILD = SHOW_CHILD;
|
|
9
|
-
|
|
10
|
-
export { SHOW_ALL, SHOW_CHILD, SHOW_PARENT,
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SHOW_ALL, SHOW_CHILD, SHOW_PARENT, TreeNode, ExportTreeSelect as default };
|
package/dist/utils/legacyUtil.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TreeNode from "../TreeNode.js";
|
|
2
2
|
import { createVNode, isVNode, toRaw } from "vue";
|
|
3
3
|
import warning from "@v-c/util/dist/warning";
|
|
4
|
+
//#region src/utils/legacyUtil.tsx
|
|
4
5
|
function getNodeChildren(children) {
|
|
5
6
|
let finalChildren = children;
|
|
6
7
|
if (typeof children === "function") finalChildren = children();
|
|
@@ -41,7 +42,7 @@ function fillAdditionalInfo(extra, triggerValue, checkedValues, treeData, showPo
|
|
|
41
42
|
const value = option[fieldNames.value];
|
|
42
43
|
const included = checkedValues.includes(value);
|
|
43
44
|
const children = dig(option[fieldNames.children] || [], pos, included);
|
|
44
|
-
const node = createVNode(
|
|
45
|
+
const node = createVNode(TreeNode, option, { default: () => children.map((child) => child.node) });
|
|
45
46
|
if (triggerValue === value) triggerNode = node;
|
|
46
47
|
if (included) {
|
|
47
48
|
const checkedNode = {
|
|
@@ -77,4 +78,5 @@ function fillAdditionalInfo(extra, triggerValue, checkedValues, treeData, showPo
|
|
|
77
78
|
return (nodeList || []).map(({ node }) => node);
|
|
78
79
|
} });
|
|
79
80
|
}
|
|
81
|
+
//#endregion
|
|
80
82
|
export { convertChildrenToData, fillAdditionalInfo, fillLegacyProps };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isCheckDisabled } from "./valueUtil.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
//#region src/utils/strategyUtil.ts
|
|
3
|
+
var SHOW_ALL = "SHOW_ALL";
|
|
4
|
+
var SHOW_PARENT = "SHOW_PARENT";
|
|
5
|
+
var SHOW_CHILD = "SHOW_CHILD";
|
|
5
6
|
function formatStrategyValues(values, strategy, keyEntities, fieldNames) {
|
|
6
7
|
const valueSet = new Set(values);
|
|
7
8
|
if (strategy === "SHOW_CHILD") return values.filter((key) => {
|
|
@@ -15,4 +16,5 @@ function formatStrategyValues(values, strategy, keyEntities, fieldNames) {
|
|
|
15
16
|
});
|
|
16
17
|
return values;
|
|
17
18
|
}
|
|
19
|
+
//#endregion
|
|
18
20
|
export { SHOW_ALL, SHOW_CHILD, SHOW_PARENT, formatStrategyValues };
|
package/dist/utils/valueUtil.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/utils/valueUtil.ts
|
|
1
2
|
function toArray(value) {
|
|
2
3
|
return Array.isArray(value) ? value : value !== void 0 ? [value] : [];
|
|
3
4
|
}
|
|
@@ -27,5 +28,6 @@ function getAllKeys(treeData, fieldNames) {
|
|
|
27
28
|
dig(treeData);
|
|
28
29
|
return keys;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
var isNil = (val) => val === null || val === void 0;
|
|
32
|
+
//#endregion
|
|
31
33
|
export { fillFieldNames, getAllKeys, isCheckDisabled, isNil, toArray };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toArray } from "./valueUtil.js";
|
|
2
2
|
import warning from "@v-c/util/dist/warning";
|
|
3
|
+
//#region src/utils/warningPropsUtil.ts
|
|
3
4
|
function warningProps(props) {
|
|
4
5
|
const { searchPlaceholder, treeCheckStrictly, treeCheckable, labelInValue, value, multiple, showCheckedStrategy, maxCount } = props;
|
|
5
6
|
warning(!searchPlaceholder, "`searchPlaceholder` has been removed.");
|
|
@@ -9,4 +10,5 @@ function warningProps(props) {
|
|
|
9
10
|
else warning(!Array.isArray(value), "`value` should not be array when `TreeSelect` is single mode.");
|
|
10
11
|
if (maxCount && (showCheckedStrategy === "SHOW_ALL" && !treeCheckStrictly || showCheckedStrategy === "SHOW_PARENT")) warning(false, "`maxCount` not work with `showCheckedStrategy=SHOW_ALL` (when `treeCheckStrictly=false`) or `showCheckedStrategy=SHOW_PARENT`.");
|
|
11
12
|
}
|
|
13
|
+
//#endregion
|
|
12
14
|
export { warningProps as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/tree-select",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.1.0-rc.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"vue": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@v-c/select": "^1.0.
|
|
33
|
-
"@v-c/
|
|
34
|
-
"@v-c/
|
|
32
|
+
"@v-c/select": "^1.0.23",
|
|
33
|
+
"@v-c/util": "^1.0.19",
|
|
34
|
+
"@v-c/tree": "^1.1.0-rc.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "vite build",
|