@rc-component/tree-select 1.0.0

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.
Files changed (137) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +140 -0
  3. package/assets/icons.png +0 -0
  4. package/assets/index.less +2 -0
  5. package/assets/loading.gif +0 -0
  6. package/assets/minus.gif +0 -0
  7. package/assets/select.less +3 -0
  8. package/assets/tree.less +3 -0
  9. package/dist/223.90c7e648.async.js +3 -0
  10. package/dist/338.a2a48f3b.async.js +15 -0
  11. package/dist/338.e8c51481.chunk.css +5 -0
  12. package/dist/404.html +20 -0
  13. package/dist/439.67bede3f.async.js +137 -0
  14. package/dist/929.df8dd03f.async.js +32 -0
  15. package/dist/demo/basic/index.html +20 -0
  16. package/dist/demo/big-data/index.html +20 -0
  17. package/dist/demo/controlled/index.html +20 -0
  18. package/dist/demo/custom-icons/index.html +20 -0
  19. package/dist/demo/debug/index.html +20 -0
  20. package/dist/demo/disable/index.html +20 -0
  21. package/dist/demo/dynamic/index.html +20 -0
  22. package/dist/demo/field-names/index.html +20 -0
  23. package/dist/demo/filter/index.html +20 -0
  24. package/dist/demo/form/index.html +20 -0
  25. package/dist/demo/mutiple-with-max-count/index.html +20 -0
  26. package/dist/demo/tree-node-label-prop/index.html +20 -0
  27. package/dist/demo/width/index.html +20 -0
  28. package/dist/demos.f221b577.async.js +1 -0
  29. package/dist/docs__demo__basic.md.bcb0edb7.async.js +1 -0
  30. package/dist/docs__demo__big-data.md.8783cd6b.async.js +1 -0
  31. package/dist/docs__demo__controlled.md.e65ef7d7.async.js +1 -0
  32. package/dist/docs__demo__custom-icons.md.d53bf2f9.async.js +1 -0
  33. package/dist/docs__demo__debug.md.099ad226.async.js +1 -0
  34. package/dist/docs__demo__disable.md.6ba57652.async.js +1 -0
  35. package/dist/docs__demo__dynamic.md.f7559890.async.js +1 -0
  36. package/dist/docs__demo__fieldNames.md.16131d9f.async.js +1 -0
  37. package/dist/docs__demo__filter.md.02527db4.async.js +1 -0
  38. package/dist/docs__demo__form.md.6b77dffe.async.js +1 -0
  39. package/dist/docs__demo__mutiple-with-maxCount.md.7268d4ad.async.js +1 -0
  40. package/dist/docs__demo__treeNodeLabelProp.md.24709916.async.js +1 -0
  41. package/dist/docs__demo__width.md.24bfecd6.async.js +1 -0
  42. package/dist/docs__index.md.a6e45331.async.js +1 -0
  43. package/dist/dumi__tmp-production__dumi__theme__ContextWrapper.f56a0670.async.js +1 -0
  44. package/dist/index.html +20 -0
  45. package/dist/meta__docs.255fc42b.chunk.css +1 -0
  46. package/dist/meta__docs.dbf04b66.async.js +3359 -0
  47. package/dist/nm__dumi__dist__client__pages__404.8b85f2d9.chunk.css +1 -0
  48. package/dist/nm__dumi__dist__client__pages__404.ca2add38.async.js +1 -0
  49. package/dist/nm__dumi__dist__client__pages__Demo__index.29e9ef8f.async.js +1 -0
  50. package/dist/nm__dumi__dist__client__pages__Demo__index.578aa5c0.chunk.css +1 -0
  51. package/dist/nm__dumi__theme-default__layouts__DocLayout__index.8ed833d7.async.js +1 -0
  52. package/dist/preload_helper.d41c4da0.js +1 -0
  53. package/dist/umi.4f47b921.js +124 -0
  54. package/dist/umi.8faca2de.css +1 -0
  55. package/dist/~demos/:id/index.html +20 -0
  56. package/dist/~demos/docs-demo-basic-demo-basic/index.html +20 -0
  57. package/dist/~demos/docs-demo-big-data-demo-big-data/index.html +20 -0
  58. package/dist/~demos/docs-demo-controlled-demo-controlled/index.html +20 -0
  59. package/dist/~demos/docs-demo-custom-icons-demo-custom-icons/index.html +20 -0
  60. package/dist/~demos/docs-demo-debug-demo-debug/index.html +20 -0
  61. package/dist/~demos/docs-demo-disable-demo-disable/index.html +20 -0
  62. package/dist/~demos/docs-demo-dynamic-demo-dynamic/index.html +20 -0
  63. package/dist/~demos/docs-demo-field-names-demo-fieldnames/index.html +20 -0
  64. package/dist/~demos/docs-demo-filter-demo-filter/index.html +20 -0
  65. package/dist/~demos/docs-demo-form-demo-form/index.html +20 -0
  66. package/dist/~demos/docs-demo-mutiple-with-max-count-demo-mutiple-with-maxcount/index.html +20 -0
  67. package/dist/~demos/docs-demo-tree-node-label-prop-demo-treenodelabelprop/index.html +20 -0
  68. package/dist/~demos/docs-demo-width-demo-width/index.html +20 -0
  69. package/es/LegacyContext.d.ts +24 -0
  70. package/es/LegacyContext.js +3 -0
  71. package/es/OptionList.d.ts +8 -0
  72. package/es/OptionList.js +351 -0
  73. package/es/TreeNode.d.ts +9 -0
  74. package/es/TreeNode.js +5 -0
  75. package/es/TreeSelect.d.ts +65 -0
  76. package/es/TreeSelect.js +507 -0
  77. package/es/TreeSelectContext.d.ts +25 -0
  78. package/es/TreeSelectContext.js +3 -0
  79. package/es/hooks/useCache.d.ts +7 -0
  80. package/es/hooks/useCache.js +32 -0
  81. package/es/hooks/useCheckedKeys.d.ts +5 -0
  82. package/es/hooks/useCheckedKeys.js +21 -0
  83. package/es/hooks/useDataEntities.d.ts +7 -0
  84. package/es/hooks/useDataEntities.js +26 -0
  85. package/es/hooks/useFilterTreeData.d.ts +8 -0
  86. package/es/hooks/useFilterTreeData.js +33 -0
  87. package/es/hooks/useRefFunc.d.ts +5 -0
  88. package/es/hooks/useRefFunc.js +14 -0
  89. package/es/hooks/useTreeData.d.ts +7 -0
  90. package/es/hooks/useTreeData.js +52 -0
  91. package/es/index.d.ts +7 -0
  92. package/es/index.js +5 -0
  93. package/es/interface.d.ts +57 -0
  94. package/es/interface.js +1 -0
  95. package/es/utils/legacyUtil.d.ts +5 -0
  96. package/es/utils/legacyUtil.js +120 -0
  97. package/es/utils/strategyUtil.d.ts +7 -0
  98. package/es/utils/strategyUtil.js +25 -0
  99. package/es/utils/valueUtil.d.ts +11 -0
  100. package/es/utils/valueUtil.js +30 -0
  101. package/es/utils/warningPropsUtil.d.ts +5 -0
  102. package/es/utils/warningPropsUtil.js +30 -0
  103. package/lib/LegacyContext.d.ts +24 -0
  104. package/lib/LegacyContext.js +11 -0
  105. package/lib/OptionList.d.ts +8 -0
  106. package/lib/OptionList.js +359 -0
  107. package/lib/TreeNode.d.ts +9 -0
  108. package/lib/TreeNode.js +11 -0
  109. package/lib/TreeSelect.d.ts +65 -0
  110. package/lib/TreeSelect.js +516 -0
  111. package/lib/TreeSelectContext.d.ts +25 -0
  112. package/lib/TreeSelectContext.js +11 -0
  113. package/lib/hooks/useCache.d.ts +7 -0
  114. package/lib/hooks/useCache.js +41 -0
  115. package/lib/hooks/useCheckedKeys.d.ts +5 -0
  116. package/lib/hooks/useCheckedKeys.js +29 -0
  117. package/lib/hooks/useDataEntities.d.ts +7 -0
  118. package/lib/hooks/useDataEntities.js +36 -0
  119. package/lib/hooks/useFilterTreeData.d.ts +8 -0
  120. package/lib/hooks/useFilterTreeData.js +41 -0
  121. package/lib/hooks/useRefFunc.d.ts +5 -0
  122. package/lib/hooks/useRefFunc.js +21 -0
  123. package/lib/hooks/useTreeData.d.ts +7 -0
  124. package/lib/hooks/useTreeData.js +60 -0
  125. package/lib/index.d.ts +7 -0
  126. package/lib/index.js +35 -0
  127. package/lib/interface.d.ts +57 -0
  128. package/lib/interface.js +5 -0
  129. package/lib/utils/legacyUtil.d.ts +5 -0
  130. package/lib/utils/legacyUtil.js +131 -0
  131. package/lib/utils/strategyUtil.d.ts +7 -0
  132. package/lib/utils/strategyUtil.js +32 -0
  133. package/lib/utils/valueUtil.d.ts +11 -0
  134. package/lib/utils/valueUtil.js +41 -0
  135. package/lib/utils/warningPropsUtil.d.ts +5 -0
  136. package/lib/utils/warningPropsUtil.js +37 -0
  137. package/package.json +89 -0
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _treeUtil = require("rc-tree/lib/utils/treeUtil");
9
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
10
+ var _valueUtil = require("../utils/valueUtil");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ var _default = (treeData, fieldNames) => React.useMemo(() => {
15
+ const collection = (0, _treeUtil.convertDataToEntities)(treeData, {
16
+ fieldNames,
17
+ initWrapper: wrapper => ({
18
+ ...wrapper,
19
+ valueEntities: new Map()
20
+ }),
21
+ processEntity: (entity, wrapper) => {
22
+ const val = entity.node[fieldNames.value];
23
+
24
+ // Check if exist same value
25
+ if (process.env.NODE_ENV !== 'production') {
26
+ const key = entity.node.key;
27
+ (0, _warning.default)(!(0, _valueUtil.isNil)(val), 'TreeNode `value` is invalidate: undefined');
28
+ (0, _warning.default)(!wrapper.valueEntities.has(val), `Same \`value\` exist in the tree: ${val}`);
29
+ (0, _warning.default)(!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}.`);
30
+ }
31
+ wrapper.valueEntities.set(val, entity);
32
+ }
33
+ });
34
+ return collection;
35
+ }, [treeData, fieldNames]);
36
+ exports.default = _default;
@@ -0,0 +1,8 @@
1
+ import type { TreeSelectProps } from '../TreeSelect';
2
+ import type { DataNode, FieldNames } from '../interface';
3
+ declare const useFilterTreeData: (treeData: DataNode[], searchValue: string, options: {
4
+ fieldNames: FieldNames;
5
+ treeNodeFilterProp: string;
6
+ filterTreeNode: TreeSelectProps['filterTreeNode'];
7
+ }) => DataNode[];
8
+ export default useFilterTreeData;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _legacyUtil = require("../utils/legacyUtil");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const useFilterTreeData = (treeData, searchValue, options) => {
12
+ const {
13
+ fieldNames,
14
+ treeNodeFilterProp,
15
+ filterTreeNode
16
+ } = options;
17
+ const {
18
+ children: fieldChildren
19
+ } = fieldNames;
20
+ return React.useMemo(() => {
21
+ if (!searchValue || filterTreeNode === false) {
22
+ return treeData;
23
+ }
24
+ const filterOptionFunc = typeof filterTreeNode === 'function' ? filterTreeNode : (_, dataNode) => String(dataNode[treeNodeFilterProp]).toUpperCase().includes(searchValue.toUpperCase());
25
+ const filterTreeNodes = (nodes, keepAll = false) => nodes.reduce((filtered, node) => {
26
+ const children = node[fieldChildren];
27
+ const isMatch = keepAll || filterOptionFunc(searchValue, (0, _legacyUtil.fillLegacyProps)(node));
28
+ const filteredChildren = filterTreeNodes(children || [], isMatch);
29
+ if (isMatch || filteredChildren.length) {
30
+ filtered.push({
31
+ ...node,
32
+ isLeaf: undefined,
33
+ [fieldChildren]: filteredChildren
34
+ });
35
+ }
36
+ return filtered;
37
+ }, []);
38
+ return filterTreeNodes(treeData);
39
+ }, [treeData, searchValue, fieldChildren, treeNodeFilterProp, filterTreeNode]);
40
+ };
41
+ var _default = exports.default = useFilterTreeData;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Same as `React.useCallback` but always return a memoized function
3
+ * but redirect to real function.
4
+ */
5
+ export default function useRefFunc<T extends (...args: any[]) => any>(callback: T): T;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useRefFunc;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ /**
11
+ * Same as `React.useCallback` but always return a memoized function
12
+ * but redirect to real function.
13
+ */
14
+ function useRefFunc(callback) {
15
+ const funcRef = React.useRef();
16
+ funcRef.current = callback;
17
+ const cacheFn = React.useCallback((...args) => {
18
+ return funcRef.current(...args);
19
+ }, []);
20
+ return cacheFn;
21
+ }
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import type { DataNode, SimpleModeConfig } from '../interface';
3
+ /**
4
+ * 将 `treeData` 或 `children` 转换为格式化的 `treeData`。
5
+ * 如果 `treeData` 或 `children` 没有变化,则不会重新计算。
6
+ */
7
+ export default function useTreeData(treeData: DataNode[], children: React.ReactNode, simpleMode: boolean | SimpleModeConfig): DataNode[];
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useTreeData;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _legacyUtil = require("../utils/legacyUtil");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ function buildTreeStructure(nodes, config) {
12
+ const {
13
+ id,
14
+ pId,
15
+ rootPId
16
+ } = config;
17
+ const nodeMap = new Map();
18
+ const rootNodes = [];
19
+ nodes.forEach(node => {
20
+ const nodeKey = node[id];
21
+ const clonedNode = {
22
+ ...node,
23
+ key: node.key || nodeKey
24
+ };
25
+ nodeMap.set(nodeKey, clonedNode);
26
+ });
27
+ nodeMap.forEach(node => {
28
+ const parentKey = node[pId];
29
+ const parent = nodeMap.get(parentKey);
30
+ if (parent) {
31
+ parent.children = parent.children || [];
32
+ parent.children.push(node);
33
+ } else if (parentKey === rootPId || rootPId === null) {
34
+ rootNodes.push(node);
35
+ }
36
+ });
37
+ return rootNodes;
38
+ }
39
+
40
+ /**
41
+ * 将 `treeData` 或 `children` 转换为格式化的 `treeData`。
42
+ * 如果 `treeData` 或 `children` 没有变化,则不会重新计算。
43
+ */
44
+ function useTreeData(treeData, children, simpleMode) {
45
+ return React.useMemo(() => {
46
+ if (treeData) {
47
+ if (simpleMode) {
48
+ const config = {
49
+ id: 'id',
50
+ pId: 'pId',
51
+ rootPId: null,
52
+ ...(typeof simpleMode === 'object' ? simpleMode : {})
53
+ };
54
+ return buildTreeStructure(treeData, config);
55
+ }
56
+ return treeData;
57
+ }
58
+ return (0, _legacyUtil.convertChildrenToData)(children);
59
+ }, [children, simpleMode, treeData]);
60
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import TreeSelect from './TreeSelect';
2
+ import type { TreeSelectProps } from './TreeSelect';
3
+ import TreeNode from './TreeNode';
4
+ import { SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from './utils/strategyUtil';
5
+ export { TreeNode, SHOW_ALL, SHOW_CHILD, SHOW_PARENT };
6
+ export type { TreeSelectProps };
7
+ export default TreeSelect;
package/lib/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SHOW_ALL", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _strategyUtil.SHOW_ALL;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "SHOW_CHILD", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _strategyUtil.SHOW_CHILD;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "SHOW_PARENT", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _strategyUtil.SHOW_PARENT;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "TreeNode", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _TreeNode.default;
28
+ }
29
+ });
30
+ exports.default = void 0;
31
+ var _TreeSelect = _interopRequireDefault(require("./TreeSelect"));
32
+ var _TreeNode = _interopRequireDefault(require("./TreeNode"));
33
+ var _strategyUtil = require("./utils/strategyUtil");
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ var _default = exports.default = _TreeSelect.default;
@@ -0,0 +1,57 @@
1
+ import type * as React from 'react';
2
+ import type { SafeKey, Key, DataNode as TreeDataNode } from 'rc-tree/lib/interface';
3
+ export type { SafeKey, Key };
4
+ export interface DataNode extends Record<string, any>, Omit<TreeDataNode, 'key' | 'children'> {
5
+ key?: Key;
6
+ value?: SafeKey;
7
+ children?: DataNode[];
8
+ }
9
+ export type SelectSource = 'option' | 'selection' | 'input' | 'clear';
10
+ export interface LabeledValueType {
11
+ key?: Key;
12
+ value?: SafeKey;
13
+ label?: React.ReactNode;
14
+ /** Only works on `treeCheckStrictly` */
15
+ halfChecked?: boolean;
16
+ }
17
+ export type DefaultValueType = SafeKey | LabeledValueType | (SafeKey | LabeledValueType)[];
18
+ export interface LegacyDataNode extends DataNode {
19
+ props: any;
20
+ }
21
+ export interface FlattenDataNode {
22
+ data: DataNode;
23
+ key: Key;
24
+ value: SafeKey;
25
+ level: number;
26
+ parent?: FlattenDataNode;
27
+ }
28
+ export interface SimpleModeConfig {
29
+ id?: SafeKey;
30
+ pId?: SafeKey;
31
+ rootPId?: SafeKey;
32
+ }
33
+ /** @deprecated This is only used for legacy compatible. Not works on new code. */
34
+ export interface LegacyCheckedNode {
35
+ pos: string;
36
+ node: React.ReactElement;
37
+ children?: LegacyCheckedNode[];
38
+ }
39
+ export interface ChangeEventExtra {
40
+ /** @deprecated Please save prev value by control logic instead */
41
+ preValue: LabeledValueType[];
42
+ triggerValue: SafeKey;
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: React.ReactElement;
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
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ import type { DataNode, ChangeEventExtra, SafeKey, FieldNames } from '../interface';
3
+ export declare function convertChildrenToData(nodes: React.ReactNode): DataNode[];
4
+ export declare function fillLegacyProps(dataNode: DataNode): DataNode;
5
+ export declare function fillAdditionalInfo(extra: ChangeEventExtra, triggerValue: SafeKey, checkedValues: SafeKey[], treeData: DataNode[], showPosition: boolean, fieldNames: FieldNames): void;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertChildrenToData = convertChildrenToData;
7
+ exports.fillAdditionalInfo = fillAdditionalInfo;
8
+ exports.fillLegacyProps = fillLegacyProps;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
11
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
12
+ var _TreeNode = _interopRequireDefault(require("../TreeNode"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ function convertChildrenToData(nodes) {
17
+ return (0, _toArray.default)(nodes).map(node => {
18
+ if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
19
+ return null;
20
+ }
21
+ const {
22
+ key,
23
+ props: {
24
+ children,
25
+ value,
26
+ ...restProps
27
+ }
28
+ } = node;
29
+ const data = {
30
+ key,
31
+ value,
32
+ ...restProps
33
+ };
34
+ const childData = convertChildrenToData(children);
35
+ if (childData.length) {
36
+ data.children = childData;
37
+ }
38
+ return data;
39
+ }).filter(data => data);
40
+ }
41
+ function fillLegacyProps(dataNode) {
42
+ if (!dataNode) {
43
+ return dataNode;
44
+ }
45
+ const cloneNode = {
46
+ ...dataNode
47
+ };
48
+ if (!('props' in cloneNode)) {
49
+ Object.defineProperty(cloneNode, 'props', {
50
+ get() {
51
+ (0, _warning.default)(false, 'New `rc-tree-select` not support return node instance as argument anymore. Please consider to remove `props` access.');
52
+ return cloneNode;
53
+ }
54
+ });
55
+ }
56
+ return cloneNode;
57
+ }
58
+ function fillAdditionalInfo(extra, triggerValue, checkedValues, treeData, showPosition, fieldNames) {
59
+ let triggerNode = null;
60
+ let nodeList = null;
61
+ function generateMap() {
62
+ function dig(list, level = '0', parentIncluded = false) {
63
+ return list.map((option, index) => {
64
+ const pos = `${level}-${index}`;
65
+ const value = option[fieldNames.value];
66
+ const included = checkedValues.includes(value);
67
+ const children = dig(option[fieldNames.children] || [], pos, included);
68
+ const node = /*#__PURE__*/React.createElement(_TreeNode.default, option, children.map(child => child.node));
69
+
70
+ // Link with trigger node
71
+ if (triggerValue === value) {
72
+ triggerNode = node;
73
+ }
74
+ if (included) {
75
+ const checkedNode = {
76
+ pos,
77
+ node,
78
+ children
79
+ };
80
+ if (!parentIncluded) {
81
+ nodeList.push(checkedNode);
82
+ }
83
+ return checkedNode;
84
+ }
85
+ return null;
86
+ }).filter(node => node);
87
+ }
88
+ if (!nodeList) {
89
+ nodeList = [];
90
+ dig(treeData);
91
+
92
+ // Sort to keep the checked node length
93
+ nodeList.sort(({
94
+ node: {
95
+ props: {
96
+ value: val1
97
+ }
98
+ }
99
+ }, {
100
+ node: {
101
+ props: {
102
+ value: val2
103
+ }
104
+ }
105
+ }) => {
106
+ const index1 = checkedValues.indexOf(val1);
107
+ const index2 = checkedValues.indexOf(val2);
108
+ return index1 - index2;
109
+ });
110
+ }
111
+ }
112
+ Object.defineProperty(extra, 'triggerNode', {
113
+ get() {
114
+ (0, _warning.default)(false, '`triggerNode` is deprecated. Please consider decoupling data with node.');
115
+ generateMap();
116
+ return triggerNode;
117
+ }
118
+ });
119
+ Object.defineProperty(extra, 'allCheckedNodes', {
120
+ get() {
121
+ (0, _warning.default)(false, '`allCheckedNodes` is deprecated. Please consider decoupling data with node.');
122
+ generateMap();
123
+ if (showPosition) {
124
+ return nodeList;
125
+ }
126
+ return nodeList.map(({
127
+ node
128
+ }) => node);
129
+ }
130
+ });
131
+ }
@@ -0,0 +1,7 @@
1
+ import type { DataEntity } from 'rc-tree/lib/interface';
2
+ import type { SafeKey, FieldNames } from '../interface';
3
+ export declare const SHOW_ALL = "SHOW_ALL";
4
+ export declare const SHOW_PARENT = "SHOW_PARENT";
5
+ export declare const SHOW_CHILD = "SHOW_CHILD";
6
+ export type CheckedStrategy = typeof SHOW_ALL | typeof SHOW_PARENT | typeof SHOW_CHILD;
7
+ export declare function formatStrategyValues(values: SafeKey[], strategy: CheckedStrategy, keyEntities: Record<SafeKey, DataEntity>, fieldNames: FieldNames): SafeKey[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SHOW_PARENT = exports.SHOW_CHILD = exports.SHOW_ALL = void 0;
7
+ exports.formatStrategyValues = formatStrategyValues;
8
+ var _valueUtil = require("./valueUtil");
9
+ const SHOW_ALL = exports.SHOW_ALL = 'SHOW_ALL';
10
+ const SHOW_PARENT = exports.SHOW_PARENT = 'SHOW_PARENT';
11
+ const SHOW_CHILD = exports.SHOW_CHILD = 'SHOW_CHILD';
12
+ function formatStrategyValues(values, strategy, keyEntities, fieldNames) {
13
+ const valueSet = new Set(values);
14
+ if (strategy === SHOW_CHILD) {
15
+ return values.filter(key => {
16
+ const entity = keyEntities[key];
17
+ return !entity || !entity.children || !entity.children.some(({
18
+ node
19
+ }) => valueSet.has(node[fieldNames.value])) || !entity.children.every(({
20
+ node
21
+ }) => (0, _valueUtil.isCheckDisabled)(node) || valueSet.has(node[fieldNames.value]));
22
+ });
23
+ }
24
+ if (strategy === SHOW_PARENT) {
25
+ return values.filter(key => {
26
+ const entity = keyEntities[key];
27
+ const parent = entity ? entity.parent : null;
28
+ return !parent || (0, _valueUtil.isCheckDisabled)(parent.node) || !valueSet.has(parent.key);
29
+ });
30
+ }
31
+ return values;
32
+ }
@@ -0,0 +1,11 @@
1
+ import type { DataNode, FieldNames, SafeKey } from '../interface';
2
+ export declare const toArray: <T>(value: T | T[]) => T[];
3
+ export declare const fillFieldNames: (fieldNames?: FieldNames) => {
4
+ _title: string[];
5
+ value: string;
6
+ key: string;
7
+ children: string;
8
+ };
9
+ export declare const isCheckDisabled: (node: DataNode) => boolean;
10
+ export declare const getAllKeys: (treeData: DataNode[], fieldNames: FieldNames) => SafeKey[];
11
+ export declare const isNil: (val: any) => boolean;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toArray = exports.isNil = exports.isCheckDisabled = exports.getAllKeys = exports.fillFieldNames = void 0;
7
+ const toArray = value => Array.isArray(value) ? value : value !== undefined ? [value] : [];
8
+ exports.toArray = toArray;
9
+ const fillFieldNames = fieldNames => {
10
+ const {
11
+ label,
12
+ value,
13
+ children
14
+ } = fieldNames || {};
15
+ return {
16
+ _title: label ? [label] : ['title', 'label'],
17
+ value: value || 'value',
18
+ key: value || 'value',
19
+ children: children || 'children'
20
+ };
21
+ };
22
+ exports.fillFieldNames = fillFieldNames;
23
+ const isCheckDisabled = node => !node || node.disabled || node.disableCheckbox || node.checkable === false;
24
+ exports.isCheckDisabled = isCheckDisabled;
25
+ const getAllKeys = (treeData, fieldNames) => {
26
+ const keys = [];
27
+ const dig = list => {
28
+ list.forEach(item => {
29
+ const children = item[fieldNames.children];
30
+ if (children) {
31
+ keys.push(item[fieldNames.value]);
32
+ dig(children);
33
+ }
34
+ });
35
+ };
36
+ dig(treeData);
37
+ return keys;
38
+ };
39
+ exports.getAllKeys = getAllKeys;
40
+ const isNil = val => val === null || val === undefined;
41
+ exports.isNil = isNil;
@@ -0,0 +1,5 @@
1
+ import type { TreeSelectProps } from '../TreeSelect';
2
+ declare function warningProps(props: TreeSelectProps & {
3
+ searchPlaceholder?: string;
4
+ }): void;
5
+ export default warningProps;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
8
+ var _valueUtil = require("./valueUtil");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function warningProps(props) {
11
+ const {
12
+ searchPlaceholder,
13
+ treeCheckStrictly,
14
+ treeCheckable,
15
+ labelInValue,
16
+ value,
17
+ multiple,
18
+ showCheckedStrategy,
19
+ maxCount
20
+ } = props;
21
+ (0, _warning.default)(!searchPlaceholder, '`searchPlaceholder` has been removed.');
22
+ if (treeCheckStrictly && labelInValue === false) {
23
+ (0, _warning.default)(false, '`treeCheckStrictly` will force set `labelInValue` to `true`.');
24
+ }
25
+ if (labelInValue || treeCheckStrictly) {
26
+ (0, _warning.default)((0, _valueUtil.toArray)(value).every(val => val && typeof val === 'object' && 'value' in val), 'Invalid prop `value` supplied to `TreeSelect`. You should use { label: string, value: string | number } or [{ label: string, value: string | number }] instead.');
27
+ }
28
+ if (treeCheckStrictly || multiple || treeCheckable) {
29
+ (0, _warning.default)(!value || Array.isArray(value), '`value` should be an array when `TreeSelect` is checkable or multiple.');
30
+ } else {
31
+ (0, _warning.default)(!Array.isArray(value), '`value` should not be array when `TreeSelect` is single mode.');
32
+ }
33
+ if (maxCount && (showCheckedStrategy === 'SHOW_ALL' && !treeCheckStrictly || showCheckedStrategy === 'SHOW_PARENT')) {
34
+ (0, _warning.default)(false, '`maxCount` not work with `showCheckedStrategy=SHOW_ALL` (when `treeCheckStrictly=false`) or `showCheckedStrategy=SHOW_PARENT`.');
35
+ }
36
+ }
37
+ var _default = exports.default = warningProps;
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@rc-component/tree-select",
3
+ "version": "1.0.0",
4
+ "description": "tree-select ui component for react",
5
+ "keywords": [
6
+ "react",
7
+ "react-component",
8
+ "react-tree-select",
9
+ "tree-select"
10
+ ],
11
+ "homepage": "https://github.com/react-component/tree-select",
12
+ "bugs": {
13
+ "url": "https://github.com/react-component/tree-select/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/react-component/tree-select.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "smith3816@gmail.com",
21
+ "main": "./lib/index",
22
+ "module": "./es/index",
23
+ "files": [
24
+ "es",
25
+ "lib",
26
+ "dist",
27
+ "assets/*.less",
28
+ "assets/*.css",
29
+ "assets/*.png",
30
+ "assets/*.gif"
31
+ ],
32
+ "scripts": {
33
+ "build": "dumi build",
34
+ "compile": "father build",
35
+ "lint": "eslint src/ examples/ --ext .tsx,.ts,.jsx,.js",
36
+ "now-build": "npm run build",
37
+ "prepare": "husky && dumi setup",
38
+ "prepublishOnly": "npm run compile && rc-np",
39
+ "prettier": "prettier '{src,tests}/**/*.{ts,tsx}' 'tests/**/*.js' --write",
40
+ "start": "dumi dev",
41
+ "test": "rc-test"
42
+ },
43
+ "lint-staged": {
44
+ "*": "prettier --write --ignore-unknown"
45
+ },
46
+ "dependencies": {
47
+ "classnames": "2.x",
48
+ "@rc-component/select": "~1.0.0",
49
+ "rc-tree": "~5.13.1",
50
+ "@rc-component/util": "^1.2.1"
51
+ },
52
+ "devDependencies": {
53
+ "@rc-component/father-plugin": "^2.0.2",
54
+ "@rc-component/np": "^1.0.3",
55
+ "@rc-component/trigger": "^3.0.0",
56
+ "@testing-library/react": "^12.1.5",
57
+ "@types/jest": "^29.5.13",
58
+ "@types/node": "^22.7.5",
59
+ "@types/react": "^18.3.11",
60
+ "@types/react-dom": "^19.0.1",
61
+ "@types/warning": "^3.0.3",
62
+ "@umijs/fabric": "^4.0.1",
63
+ "cheerio": "1.0.0-rc.12",
64
+ "cross-env": "^7.0.3",
65
+ "dumi": "^2.4.12",
66
+ "enzyme": "^3.11.0",
67
+ "enzyme-adapter-react-16": "^1.15.8",
68
+ "enzyme-to-json": "^3.6.2",
69
+ "eslint": "^8.57.1",
70
+ "eslint-plugin-jest": "^28.10.0",
71
+ "eslint-plugin-unicorn": "^56.0.0",
72
+ "father": "^4.5.0",
73
+ "glob": "^11.0.0",
74
+ "husky": "^9.1.6",
75
+ "lint-staged": "^15.2.10",
76
+ "prettier": "^3.3.3",
77
+ "rc-dialog": "^9.6.0",
78
+ "rc-field-form": "^2.4.0",
79
+ "rc-test": "^7.1.1",
80
+ "rc-virtual-list": "^3.14.8",
81
+ "react": "^16.0.0",
82
+ "react-dom": "^16.0.0",
83
+ "typescript": "^5.6.3"
84
+ },
85
+ "peerDependencies": {
86
+ "react": "*",
87
+ "react-dom": "*"
88
+ }
89
+ }