@rc-component/cascader 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 (95) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +300 -0
  3. package/assets/index.less +3 -0
  4. package/assets/list.less +106 -0
  5. package/assets/panel.less +7 -0
  6. package/assets/select.less +3 -0
  7. package/es/Cascader.d.ts +88 -0
  8. package/es/Cascader.js +230 -0
  9. package/es/OptionList/CacheContent.d.ts +7 -0
  10. package/es/OptionList/CacheContent.js +8 -0
  11. package/es/OptionList/Checkbox.d.ts +10 -0
  12. package/es/OptionList/Checkbox.js +24 -0
  13. package/es/OptionList/Column.d.ts +21 -0
  14. package/es/OptionList/Column.js +175 -0
  15. package/es/OptionList/List.d.ts +6 -0
  16. package/es/OptionList/List.js +216 -0
  17. package/es/OptionList/index.d.ts +4 -0
  18. package/es/OptionList/index.js +13 -0
  19. package/es/OptionList/useActive.d.ts +6 -0
  20. package/es/OptionList/useActive.js +26 -0
  21. package/es/OptionList/useKeyboard.d.ts +10 -0
  22. package/es/OptionList/useKeyboard.js +165 -0
  23. package/es/Panel.d.ts +5 -0
  24. package/es/Panel.js +116 -0
  25. package/es/context.d.ts +21 -0
  26. package/es/context.js +3 -0
  27. package/es/hooks/useDisplayValues.d.ts +10 -0
  28. package/es/hooks/useDisplayValues.js +44 -0
  29. package/es/hooks/useEntities.d.ts +10 -0
  30. package/es/hooks/useEntities.js +35 -0
  31. package/es/hooks/useMissingValues.d.ts +3 -0
  32. package/es/hooks/useMissingValues.js +17 -0
  33. package/es/hooks/useOptions.d.ts +9 -0
  34. package/es/hooks/useOptions.js +20 -0
  35. package/es/hooks/useSearchConfig.d.ts +2 -0
  36. package/es/hooks/useSearchConfig.js +27 -0
  37. package/es/hooks/useSearchOptions.d.ts +4 -0
  38. package/es/hooks/useSearchOptions.js +63 -0
  39. package/es/hooks/useSelect.d.ts +4 -0
  40. package/es/hooks/useSelect.js +49 -0
  41. package/es/hooks/useValues.d.ts +9 -0
  42. package/es/hooks/useValues.js +21 -0
  43. package/es/index.d.ts +5 -0
  44. package/es/index.js +4 -0
  45. package/es/utils/commonUtil.d.ts +18 -0
  46. package/es/utils/commonUtil.js +69 -0
  47. package/es/utils/treeUtil.d.ts +9 -0
  48. package/es/utils/treeUtil.js +35 -0
  49. package/es/utils/warningPropsUtil.d.ts +4 -0
  50. package/es/utils/warningPropsUtil.js +29 -0
  51. package/lib/Cascader.d.ts +88 -0
  52. package/lib/Cascader.js +239 -0
  53. package/lib/OptionList/CacheContent.d.ts +7 -0
  54. package/lib/OptionList/CacheContent.js +16 -0
  55. package/lib/OptionList/Checkbox.d.ts +10 -0
  56. package/lib/OptionList/Checkbox.js +33 -0
  57. package/lib/OptionList/Column.d.ts +21 -0
  58. package/lib/OptionList/Column.js +185 -0
  59. package/lib/OptionList/List.d.ts +6 -0
  60. package/lib/OptionList/List.js +224 -0
  61. package/lib/OptionList/index.d.ts +4 -0
  62. package/lib/OptionList/index.js +22 -0
  63. package/lib/OptionList/useActive.d.ts +6 -0
  64. package/lib/OptionList/useActive.js +34 -0
  65. package/lib/OptionList/useKeyboard.d.ts +10 -0
  66. package/lib/OptionList/useKeyboard.js +175 -0
  67. package/lib/Panel.d.ts +5 -0
  68. package/lib/Panel.js +125 -0
  69. package/lib/context.d.ts +21 -0
  70. package/lib/context.js +11 -0
  71. package/lib/hooks/useDisplayValues.d.ts +10 -0
  72. package/lib/hooks/useDisplayValues.js +53 -0
  73. package/lib/hooks/useEntities.d.ts +10 -0
  74. package/lib/hooks/useEntities.js +44 -0
  75. package/lib/hooks/useMissingValues.d.ts +3 -0
  76. package/lib/hooks/useMissingValues.js +25 -0
  77. package/lib/hooks/useOptions.d.ts +9 -0
  78. package/lib/hooks/useOptions.js +29 -0
  79. package/lib/hooks/useSearchConfig.d.ts +2 -0
  80. package/lib/hooks/useSearchConfig.js +36 -0
  81. package/lib/hooks/useSearchOptions.d.ts +4 -0
  82. package/lib/hooks/useSearchOptions.js +71 -0
  83. package/lib/hooks/useSelect.d.ts +4 -0
  84. package/lib/hooks/useSelect.js +55 -0
  85. package/lib/hooks/useValues.d.ts +9 -0
  86. package/lib/hooks/useValues.js +29 -0
  87. package/lib/index.d.ts +5 -0
  88. package/lib/index.js +16 -0
  89. package/lib/utils/commonUtil.d.ts +18 -0
  90. package/lib/utils/commonUtil.js +83 -0
  91. package/lib/utils/treeUtil.d.ts +9 -0
  92. package/lib/utils/treeUtil.js +42 -0
  93. package/lib/utils/warningPropsUtil.d.ts +4 -0
  94. package/lib/utils/warningPropsUtil.js +37 -0
  95. package/package.json +88 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _treeUtil = require("../utils/treeUtil");
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _commonUtil = require("../utils/commonUtil");
10
+ 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); }
11
+ 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; }
12
+ var _default = (rawValues, options, fieldNames, multiple, displayRender) => {
13
+ return React.useMemo(() => {
14
+ const mergedDisplayRender = displayRender || (
15
+ // Default displayRender
16
+ labels => {
17
+ const mergedLabels = multiple ? labels.slice(-1) : labels;
18
+ const SPLIT = ' / ';
19
+ if (mergedLabels.every(label => ['string', 'number'].includes(typeof label))) {
20
+ return mergedLabels.join(SPLIT);
21
+ }
22
+
23
+ // If exist non-string value, use ReactNode instead
24
+ return mergedLabels.reduce((list, label, index) => {
25
+ const keyedLabel = /*#__PURE__*/React.isValidElement(label) ? /*#__PURE__*/React.cloneElement(label, {
26
+ key: index
27
+ }) : label;
28
+ if (index === 0) {
29
+ return [keyedLabel];
30
+ }
31
+ return [...list, SPLIT, keyedLabel];
32
+ }, []);
33
+ });
34
+ return rawValues.map(valueCells => {
35
+ const valueOptions = (0, _treeUtil.toPathOptions)(valueCells, options, fieldNames);
36
+ const label = mergedDisplayRender(valueOptions.map(({
37
+ option,
38
+ value
39
+ }) => option?.[fieldNames.label] ?? value), valueOptions.map(({
40
+ option
41
+ }) => option));
42
+ const value = (0, _commonUtil.toPathKey)(valueCells);
43
+ return {
44
+ label,
45
+ value,
46
+ key: value,
47
+ valueCells,
48
+ disabled: valueOptions[valueOptions.length - 1]?.option?.disabled
49
+ };
50
+ });
51
+ }, [rawValues, options, fieldNames, displayRender, multiple]);
52
+ };
53
+ exports.default = _default;
@@ -0,0 +1,10 @@
1
+ import type { DefaultOptionType, InternalFieldNames } from '../Cascader';
2
+ import type { DataEntity } from 'rc-tree/lib/interface';
3
+ export interface OptionsInfo {
4
+ keyEntities: Record<string, DataEntity>;
5
+ pathKeyEntities: Record<string, DataEntity>;
6
+ }
7
+ export type GetEntities = () => OptionsInfo['pathKeyEntities'];
8
+ /** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
9
+ declare const _default: (options: DefaultOptionType[], fieldNames: InternalFieldNames) => GetEntities;
10
+ export default _default;
@@ -0,0 +1,44 @@
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 _commonUtil = require("../utils/commonUtil");
10
+ 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); }
11
+ 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; }
12
+ /** Lazy parse options data into conduct-able info to avoid perf issue in single mode */
13
+ var _default = (options, fieldNames) => {
14
+ const cacheRef = React.useRef({
15
+ options: [],
16
+ info: {
17
+ keyEntities: {},
18
+ pathKeyEntities: {}
19
+ }
20
+ });
21
+ const getEntities = React.useCallback(() => {
22
+ if (cacheRef.current.options !== options) {
23
+ cacheRef.current.options = options;
24
+ cacheRef.current.info = (0, _treeUtil.convertDataToEntities)(options, {
25
+ fieldNames: fieldNames,
26
+ initWrapper: wrapper => ({
27
+ ...wrapper,
28
+ pathKeyEntities: {}
29
+ }),
30
+ processEntity: (entity, wrapper) => {
31
+ const pathKey = entity.nodes.map(node => node[fieldNames.value]).join(_commonUtil.VALUE_SPLIT);
32
+ wrapper.pathKeyEntities[pathKey] = entity;
33
+
34
+ // Overwrite origin key.
35
+ // this is very hack but we need let conduct logic work with connect path
36
+ entity.key = pathKey;
37
+ }
38
+ });
39
+ }
40
+ return cacheRef.current.info.pathKeyEntities;
41
+ }, [fieldNames, options]);
42
+ return getEntities;
43
+ };
44
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
2
+ export type GetMissValues = ReturnType<typeof useMissingValues>;
3
+ export default function useMissingValues(options: DefaultOptionType[], fieldNames: InternalFieldNames): (rawValues: SingleValueType[]) => [SingleValueType[], SingleValueType[]];
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useMissingValues;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _treeUtil = require("../utils/treeUtil");
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 useMissingValues(options, fieldNames) {
12
+ return React.useCallback(rawValues => {
13
+ const missingValues = [];
14
+ const existsValues = [];
15
+ rawValues.forEach(valueCell => {
16
+ const pathOptions = (0, _treeUtil.toPathOptions)(valueCell, options, fieldNames);
17
+ if (pathOptions.every(opt => opt.option)) {
18
+ existsValues.push(valueCell);
19
+ } else {
20
+ missingValues.push(valueCell);
21
+ }
22
+ });
23
+ return [existsValues, missingValues];
24
+ }, [options, fieldNames]);
25
+ }
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import type { DefaultOptionType } from '..';
3
+ import type { InternalFieldNames, SingleValueType } from '../Cascader';
4
+ import { type GetEntities } from './useEntities';
5
+ export default function useOptions(mergedFieldNames: InternalFieldNames, options?: DefaultOptionType[]): [
6
+ mergedOptions: DefaultOptionType[],
7
+ getPathKeyEntities: GetEntities,
8
+ getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[]
9
+ ];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useOptions;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _useEntities = _interopRequireDefault(require("./useEntities"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ 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); }
11
+ 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; }
12
+ function useOptions(mergedFieldNames, options) {
13
+ const mergedOptions = React.useMemo(() => options || [], [options]);
14
+
15
+ // Only used in multiple mode, this fn will not call in single mode
16
+ const getPathKeyEntities = (0, _useEntities.default)(mergedOptions, mergedFieldNames);
17
+
18
+ /** Convert path key back to value format */
19
+ const getValueByKeyPath = React.useCallback(pathKeys => {
20
+ const keyPathEntities = getPathKeyEntities();
21
+ return pathKeys.map(pathKey => {
22
+ const {
23
+ nodes
24
+ } = keyPathEntities[pathKey];
25
+ return nodes.map(node => node[mergedFieldNames.value]);
26
+ });
27
+ }, [getPathKeyEntities, mergedFieldNames]);
28
+ return [mergedOptions, getPathKeyEntities, getValueByKeyPath];
29
+ }
@@ -0,0 +1,2 @@
1
+ import type { CascaderProps, ShowSearchType } from '../Cascader';
2
+ export default function useSearchConfig(showSearch?: CascaderProps['showSearch']): [boolean, ShowSearchType<import("../Cascader").DefaultOptionType, string>];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useSearchConfig;
7
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
8
+ var React = _interopRequireWildcard(require("react"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ // Convert `showSearch` to unique config
13
+ function useSearchConfig(showSearch) {
14
+ return React.useMemo(() => {
15
+ if (!showSearch) {
16
+ return [false, {}];
17
+ }
18
+ let searchConfig = {
19
+ matchInputWidth: true,
20
+ limit: 50
21
+ };
22
+ if (showSearch && typeof showSearch === 'object') {
23
+ searchConfig = {
24
+ ...searchConfig,
25
+ ...showSearch
26
+ };
27
+ }
28
+ if (searchConfig.limit <= 0) {
29
+ searchConfig.limit = false;
30
+ if (process.env.NODE_ENV !== 'production') {
31
+ (0, _warning.default)(false, "'limit' of showSearch should be positive number or false.");
32
+ }
33
+ }
34
+ return [true, searchConfig];
35
+ }, [showSearch]);
36
+ }
@@ -0,0 +1,4 @@
1
+ import type { DefaultOptionType, InternalFieldNames, ShowSearchType } from '../Cascader';
2
+ export declare const SEARCH_MARK = "__rc_cascader_search_mark__";
3
+ declare const useSearchOptions: (search: string, options: DefaultOptionType[], fieldNames: InternalFieldNames, prefixCls: string, config: ShowSearchType, enableHalfPath?: boolean) => DefaultOptionType[];
4
+ export default useSearchOptions;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.SEARCH_MARK = void 0;
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
+ const SEARCH_MARK = exports.SEARCH_MARK = '__rc_cascader_search_mark__';
11
+ const defaultFilter = (search, options, {
12
+ label = ''
13
+ }) => options.some(opt => String(opt[label]).toLowerCase().includes(search.toLowerCase()));
14
+ const defaultRender = (inputValue, path, prefixCls, fieldNames) => path.map(opt => opt[fieldNames.label]).join(' / ');
15
+ const useSearchOptions = (search, options, fieldNames, prefixCls, config, enableHalfPath) => {
16
+ const {
17
+ filter = defaultFilter,
18
+ render = defaultRender,
19
+ limit = 50,
20
+ sort
21
+ } = config;
22
+ return React.useMemo(() => {
23
+ const filteredOptions = [];
24
+ if (!search) {
25
+ return [];
26
+ }
27
+ function dig(list, pathOptions, parentDisabled = false) {
28
+ list.forEach(option => {
29
+ // Perf saving when `sort` is disabled and `limit` is provided
30
+ if (!sort && limit !== false && limit > 0 && filteredOptions.length >= limit) {
31
+ return;
32
+ }
33
+ const connectedPathOptions = [...pathOptions, option];
34
+ const children = option[fieldNames.children];
35
+ const mergedDisabled = parentDisabled || option.disabled;
36
+
37
+ // If current option is filterable
38
+ if (
39
+ // If is leaf option
40
+ !children || children.length === 0 ||
41
+ // If is changeOnSelect or multiple
42
+ enableHalfPath) {
43
+ if (filter(search, connectedPathOptions, {
44
+ label: fieldNames.label
45
+ })) {
46
+ filteredOptions.push({
47
+ ...option,
48
+ disabled: mergedDisabled,
49
+ [fieldNames.label]: render(search, connectedPathOptions, prefixCls, fieldNames),
50
+ [SEARCH_MARK]: connectedPathOptions,
51
+ [fieldNames.children]: undefined
52
+ });
53
+ }
54
+ }
55
+ if (children) {
56
+ dig(option[fieldNames.children], connectedPathOptions, mergedDisabled);
57
+ }
58
+ });
59
+ }
60
+ dig(options, []);
61
+
62
+ // Do sort
63
+ if (sort) {
64
+ filteredOptions.sort((a, b) => {
65
+ return sort(a[SEARCH_MARK], b[SEARCH_MARK], search, fieldNames);
66
+ });
67
+ }
68
+ return limit !== false && limit > 0 ? filteredOptions.slice(0, limit) : filteredOptions;
69
+ }, [search, options, fieldNames, prefixCls, render, enableHalfPath, filter, sort, limit]);
70
+ };
71
+ var _default = exports.default = useSearchOptions;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { InternalValueType, ShowCheckedStrategy, SingleValueType } from '../Cascader';
3
+ import type { GetEntities } from './useEntities';
4
+ export default function useSelect(multiple: boolean, triggerChange: (nextValues: InternalValueType) => void, checkedValues: SingleValueType[], halfCheckedValues: SingleValueType[], missingCheckedValues: SingleValueType[], getPathKeyEntities: GetEntities, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], showCheckedStrategy?: ShowCheckedStrategy): (valuePath: SingleValueType) => void;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useSelect;
7
+ var _conductUtil = require("rc-tree/lib/utils/conductUtil");
8
+ var _commonUtil = require("../utils/commonUtil");
9
+ var _treeUtil = require("../utils/treeUtil");
10
+ function useSelect(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy) {
11
+ return valuePath => {
12
+ if (!multiple) {
13
+ triggerChange(valuePath);
14
+ } else {
15
+ // Prepare conduct required info
16
+ const pathKey = (0, _commonUtil.toPathKey)(valuePath);
17
+ const checkedPathKeys = (0, _commonUtil.toPathKeys)(checkedValues);
18
+ const halfCheckedPathKeys = (0, _commonUtil.toPathKeys)(halfCheckedValues);
19
+ const existInChecked = checkedPathKeys.includes(pathKey);
20
+ const existInMissing = missingCheckedValues.some(valueCells => (0, _commonUtil.toPathKey)(valueCells) === pathKey);
21
+
22
+ // Do update
23
+ let nextCheckedValues = checkedValues;
24
+ let nextMissingValues = missingCheckedValues;
25
+ if (existInMissing && !existInChecked) {
26
+ // Missing value only do filter
27
+ nextMissingValues = missingCheckedValues.filter(valueCells => (0, _commonUtil.toPathKey)(valueCells) !== pathKey);
28
+ } else {
29
+ // Update checked key first
30
+ const nextRawCheckedKeys = existInChecked ? checkedPathKeys.filter(key => key !== pathKey) : [...checkedPathKeys, pathKey];
31
+ const pathKeyEntities = getPathKeyEntities();
32
+
33
+ // Conduction by selected or not
34
+ let checkedKeys;
35
+ if (existInChecked) {
36
+ ({
37
+ checkedKeys
38
+ } = (0, _conductUtil.conductCheck)(nextRawCheckedKeys, {
39
+ checked: false,
40
+ halfCheckedKeys: halfCheckedPathKeys
41
+ }, pathKeyEntities));
42
+ } else {
43
+ ({
44
+ checkedKeys
45
+ } = (0, _conductUtil.conductCheck)(nextRawCheckedKeys, true, pathKeyEntities));
46
+ }
47
+
48
+ // Roll up to parent level keys
49
+ const deDuplicatedKeys = (0, _treeUtil.formatStrategyValues)(checkedKeys, getPathKeyEntities, showCheckedStrategy);
50
+ nextCheckedValues = getValueByKeyPath(deDuplicatedKeys);
51
+ }
52
+ triggerChange([...nextMissingValues, ...nextCheckedValues]);
53
+ }
54
+ };
55
+ }
@@ -0,0 +1,9 @@
1
+ import type { DataEntity } from 'rc-tree/lib/interface';
2
+ import * as React from 'react';
3
+ import type { SingleValueType } from '../Cascader';
4
+ import type { GetMissValues } from './useMissingValues';
5
+ export default function useValues(multiple: boolean, rawValues: SingleValueType[], getPathKeyEntities: () => Record<string, DataEntity>, getValueByKeyPath: (pathKeys: React.Key[]) => SingleValueType[], getMissingValues: GetMissValues): [
6
+ checkedValues: SingleValueType[],
7
+ halfCheckedValues: SingleValueType[],
8
+ missingCheckedValues: SingleValueType[]
9
+ ];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useValues;
7
+ var _conductUtil = require("rc-tree/lib/utils/conductUtil");
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _commonUtil = require("../utils/commonUtil");
10
+ 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); }
11
+ 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; }
12
+ function useValues(multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues) {
13
+ // Fill `rawValues` with checked conduction values
14
+ return React.useMemo(() => {
15
+ const [existValues, missingValues] = getMissingValues(rawValues);
16
+ if (!multiple || !rawValues.length) {
17
+ return [existValues, [], missingValues];
18
+ }
19
+ const keyPathValues = (0, _commonUtil.toPathKeys)(existValues);
20
+ const keyPathEntities = getPathKeyEntities();
21
+ const {
22
+ checkedKeys,
23
+ halfCheckedKeys
24
+ } = (0, _conductUtil.conductCheck)(keyPathValues, true, keyPathEntities);
25
+
26
+ // Convert key back to value cells
27
+ return [getValueByKeyPath(checkedKeys), getValueByKeyPath(halfCheckedKeys), missingValues];
28
+ }, [multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues]);
29
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import Cascader from './Cascader';
2
+ import Panel from './Panel';
3
+ export type { BaseOptionType, DefaultOptionType, CascaderProps, FieldNames, ShowSearchType, CascaderRef, } from './Cascader';
4
+ export { Panel };
5
+ export default Cascader;
package/lib/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Panel", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Panel.default;
10
+ }
11
+ });
12
+ exports.default = void 0;
13
+ var _Cascader = _interopRequireDefault(require("./Cascader"));
14
+ var _Panel = _interopRequireDefault(require("./Panel"));
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ var _default = exports.default = _Cascader.default;
@@ -0,0 +1,18 @@
1
+ import type { DefaultOptionType, FieldNames, InternalFieldNames, InternalValueType, SingleValueType } from '../Cascader';
2
+ export declare const VALUE_SPLIT = "__RC_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): any;
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,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VALUE_SPLIT = exports.SHOW_PARENT = exports.SHOW_CHILD = void 0;
7
+ exports.fillFieldNames = fillFieldNames;
8
+ exports.getFullPathKeys = getFullPathKeys;
9
+ exports.isLeaf = isLeaf;
10
+ exports.scrollIntoParentView = scrollIntoParentView;
11
+ exports.toPathKey = toPathKey;
12
+ exports.toPathKeys = toPathKeys;
13
+ exports.toPathValueStr = toPathValueStr;
14
+ exports.toRawValues = toRawValues;
15
+ var _useSearchOptions = require("../hooks/useSearchOptions");
16
+ const VALUE_SPLIT = exports.VALUE_SPLIT = '__RC_CASCADER_SPLIT__';
17
+ const SHOW_PARENT = exports.SHOW_PARENT = 'SHOW_PARENT';
18
+ const SHOW_CHILD = exports.SHOW_CHILD = 'SHOW_CHILD';
19
+
20
+ /**
21
+ * Will convert value to string, and join with `VALUE_SPLIT`
22
+ */
23
+ function toPathKey(value) {
24
+ return value.join(VALUE_SPLIT);
25
+ }
26
+
27
+ /**
28
+ * Batch convert value to string, and join with `VALUE_SPLIT`
29
+ */
30
+ function toPathKeys(value) {
31
+ return value.map(toPathKey);
32
+ }
33
+ function toPathValueStr(pathKey) {
34
+ return pathKey.split(VALUE_SPLIT);
35
+ }
36
+ function fillFieldNames(fieldNames) {
37
+ const {
38
+ label,
39
+ value,
40
+ children
41
+ } = fieldNames || {};
42
+ const val = value || 'value';
43
+ return {
44
+ label: label || 'label',
45
+ value: val,
46
+ key: val,
47
+ children: children || 'children'
48
+ };
49
+ }
50
+ function isLeaf(option, fieldNames) {
51
+ return option.isLeaf ?? !option[fieldNames.children]?.length;
52
+ }
53
+ function scrollIntoParentView(element) {
54
+ const parent = element.parentElement;
55
+ if (!parent) {
56
+ return;
57
+ }
58
+ const elementToParent = element.offsetTop - parent.offsetTop; // offsetParent may not be parent.
59
+ if (elementToParent - parent.scrollTop < 0) {
60
+ parent.scrollTo({
61
+ top: elementToParent
62
+ });
63
+ } else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) {
64
+ parent.scrollTo({
65
+ top: elementToParent + element.offsetHeight - parent.offsetHeight
66
+ });
67
+ }
68
+ }
69
+ function getFullPathKeys(options, fieldNames) {
70
+ return options.map(item => item[_useSearchOptions.SEARCH_MARK]?.map(opt => opt[fieldNames.value]));
71
+ }
72
+ function isMultipleValue(value) {
73
+ return Array.isArray(value) && Array.isArray(value[0]);
74
+ }
75
+ function toRawValues(value) {
76
+ if (!value) {
77
+ return [];
78
+ }
79
+ if (isMultipleValue(value)) {
80
+ return value;
81
+ }
82
+ return (value.length === 0 ? [] : [value]).map(val => Array.isArray(val) ? val : [val]);
83
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { SingleValueType, DefaultOptionType, InternalFieldNames, ShowCheckedStrategy } from '../Cascader';
3
+ import type { GetEntities } from '../hooks/useEntities';
4
+ export declare function formatStrategyValues(pathKeys: React.Key[], getKeyPathEntities: GetEntities, showCheckedStrategy?: ShowCheckedStrategy): import("react").Key[];
5
+ export declare function toPathOptions(valueCells: SingleValueType, options: DefaultOptionType[], fieldNames: InternalFieldNames, stringMode?: boolean): {
6
+ value: SingleValueType[number];
7
+ index: number;
8
+ option: DefaultOptionType;
9
+ }[];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatStrategyValues = formatStrategyValues;
7
+ exports.toPathOptions = toPathOptions;
8
+ var _commonUtil = require("./commonUtil");
9
+ function formatStrategyValues(pathKeys, getKeyPathEntities, showCheckedStrategy) {
10
+ const valueSet = new Set(pathKeys);
11
+ const keyPathEntities = getKeyPathEntities();
12
+ return pathKeys.filter(key => {
13
+ const entity = keyPathEntities[key];
14
+ const parent = entity ? entity.parent : null;
15
+ const children = entity ? entity.children : null;
16
+ if (entity && entity.node.disabled) {
17
+ return true;
18
+ }
19
+ return showCheckedStrategy === _commonUtil.SHOW_CHILD ? !(children && children.some(child => child.key && valueSet.has(child.key))) : !(parent && !parent.node.disabled && valueSet.has(parent.key));
20
+ });
21
+ }
22
+ function toPathOptions(valueCells, options, fieldNames,
23
+ // Used for loadingKeys which saved loaded keys as string
24
+ stringMode = false) {
25
+ let currentList = options;
26
+ const valueOptions = [];
27
+ for (let i = 0; i < valueCells.length; i += 1) {
28
+ const valueCell = valueCells[i];
29
+ const foundIndex = currentList?.findIndex(option => {
30
+ const val = option[fieldNames.value];
31
+ return stringMode ? String(val) === String(valueCell) : val === valueCell;
32
+ });
33
+ const foundOption = foundIndex !== -1 ? currentList?.[foundIndex] : null;
34
+ valueOptions.push({
35
+ value: foundOption?.[fieldNames.value] ?? valueCell,
36
+ index: foundIndex,
37
+ option: foundOption
38
+ });
39
+ currentList = foundOption?.[fieldNames.children];
40
+ }
41
+ return valueOptions;
42
+ }
@@ -0,0 +1,4 @@
1
+ import type { DefaultOptionType, FieldNames, InternalCascaderProps } from '../Cascader';
2
+ declare function warningProps(props: InternalCascaderProps): void;
3
+ export declare function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames): void;
4
+ 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
+ exports.warningNullOptions = warningNullOptions;
8
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function warningProps(props) {
11
+ const {
12
+ popupVisible,
13
+ popupPlacement
14
+ } = props;
15
+ (0, _warning.default)(popupVisible === undefined, '`popupVisible` is deprecated. Please use `open` instead.');
16
+ (0, _warning.default)(popupPlacement === undefined, '`popupPlacement` is deprecated. Please use `placement` instead.');
17
+ }
18
+
19
+ // value in Cascader options should not be null
20
+ function warningNullOptions(options, fieldNames) {
21
+ if (options) {
22
+ const recursiveOptions = optionsList => {
23
+ for (let i = 0; i < optionsList.length; i++) {
24
+ const option = optionsList[i];
25
+ if (option[fieldNames?.value] === null) {
26
+ (0, _warning.default)(false, '`value` in Cascader options should not be `null`.');
27
+ return true;
28
+ }
29
+ if (Array.isArray(option[fieldNames?.children]) && recursiveOptions(option[fieldNames?.children])) {
30
+ return true;
31
+ }
32
+ }
33
+ };
34
+ recursiveOptions(options);
35
+ }
36
+ }
37
+ var _default = exports.default = warningProps;