@rc-component/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 +9 -0
  2. package/README.md +191 -0
  3. package/assets/index.css +306 -0
  4. package/assets/index.less +397 -0
  5. package/es/BaseSelect/Polite.d.ts +7 -0
  6. package/es/BaseSelect/Polite.js +26 -0
  7. package/es/BaseSelect/index.d.ts +118 -0
  8. package/es/BaseSelect/index.js +569 -0
  9. package/es/OptGroup.d.ts +12 -0
  10. package/es/OptGroup.js +6 -0
  11. package/es/Option.d.ts +14 -0
  12. package/es/Option.js +6 -0
  13. package/es/OptionList.d.ts +10 -0
  14. package/es/OptionList.js +379 -0
  15. package/es/Select.d.ts +114 -0
  16. package/es/Select.js +480 -0
  17. package/es/SelectContext.d.ts +23 -0
  18. package/es/SelectContext.js +6 -0
  19. package/es/SelectTrigger.d.ts +30 -0
  20. package/es/SelectTrigger.js +138 -0
  21. package/es/Selector/Input.d.ts +27 -0
  22. package/es/Selector/Input.js +114 -0
  23. package/es/Selector/MultipleSelector.d.ts +16 -0
  24. package/es/Selector/MultipleSelector.js +185 -0
  25. package/es/Selector/SingleSelector.d.ts +8 -0
  26. package/es/Selector/SingleSelector.js +104 -0
  27. package/es/Selector/index.d.ts +85 -0
  28. package/es/Selector/index.js +184 -0
  29. package/es/TransBtn.d.ts +12 -0
  30. package/es/TransBtn.js +30 -0
  31. package/es/hooks/useAllowClear.d.ts +8 -0
  32. package/es/hooks/useAllowClear.js +26 -0
  33. package/es/hooks/useBaseProps.d.ts +13 -0
  34. package/es/hooks/useBaseProps.js +10 -0
  35. package/es/hooks/useCache.d.ts +7 -0
  36. package/es/hooks/useCache.js +40 -0
  37. package/es/hooks/useDelayReset.d.ts +5 -0
  38. package/es/hooks/useDelayReset.js +24 -0
  39. package/es/hooks/useFilterOptions.d.ts +3 -0
  40. package/es/hooks/useFilterOptions.js +57 -0
  41. package/es/hooks/useId.d.ts +5 -0
  42. package/es/hooks/useId.js +29 -0
  43. package/es/hooks/useLayoutEffect.d.ts +5 -0
  44. package/es/hooks/useLayoutEffect.js +17 -0
  45. package/es/hooks/useLock.d.ts +7 -0
  46. package/es/hooks/useLock.js +27 -0
  47. package/es/hooks/useOptions.d.ts +12 -0
  48. package/es/hooks/useOptions.js +45 -0
  49. package/es/hooks/useRefFunc.d.ts +5 -0
  50. package/es/hooks/useRefFunc.js +14 -0
  51. package/es/hooks/useSelectTriggerControl.d.ts +1 -0
  52. package/es/hooks/useSelectTriggerControl.js +27 -0
  53. package/es/index.d.ts +10 -0
  54. package/es/index.js +7 -0
  55. package/es/interface.d.ts +23 -0
  56. package/es/interface.js +1 -0
  57. package/es/utils/__mocks__/platformUtil.d.ts +1 -0
  58. package/es/utils/__mocks__/platformUtil.js +3 -0
  59. package/es/utils/commonUtil.d.ts +9 -0
  60. package/es/utils/commonUtil.js +32 -0
  61. package/es/utils/keyUtil.d.ts +2 -0
  62. package/es/utils/keyUtil.js +16 -0
  63. package/es/utils/legacyUtil.d.ts +3 -0
  64. package/es/utils/legacyUtil.js +44 -0
  65. package/es/utils/platformUtil.d.ts +1 -0
  66. package/es/utils/platformUtil.js +4 -0
  67. package/es/utils/valueUtil.d.ts +24 -0
  68. package/es/utils/valueUtil.js +128 -0
  69. package/es/utils/warningPropsUtil.d.ts +4 -0
  70. package/es/utils/warningPropsUtil.js +119 -0
  71. package/lib/BaseSelect/Polite.d.ts +7 -0
  72. package/lib/BaseSelect/Polite.js +34 -0
  73. package/lib/BaseSelect/index.d.ts +118 -0
  74. package/lib/BaseSelect/index.js +579 -0
  75. package/lib/OptGroup.d.ts +12 -0
  76. package/lib/OptGroup.js +12 -0
  77. package/lib/Option.d.ts +14 -0
  78. package/lib/Option.js +12 -0
  79. package/lib/OptionList.d.ts +10 -0
  80. package/lib/OptionList.js +387 -0
  81. package/lib/Select.d.ts +114 -0
  82. package/lib/Select.js +487 -0
  83. package/lib/SelectContext.d.ts +23 -0
  84. package/lib/SelectContext.js +13 -0
  85. package/lib/SelectTrigger.d.ts +30 -0
  86. package/lib/SelectTrigger.js +147 -0
  87. package/lib/Selector/Input.d.ts +27 -0
  88. package/lib/Selector/Input.js +123 -0
  89. package/lib/Selector/MultipleSelector.d.ts +16 -0
  90. package/lib/Selector/MultipleSelector.js +194 -0
  91. package/lib/Selector/SingleSelector.d.ts +8 -0
  92. package/lib/Selector/SingleSelector.js +113 -0
  93. package/lib/Selector/index.d.ts +85 -0
  94. package/lib/Selector/index.js +191 -0
  95. package/lib/TransBtn.d.ts +12 -0
  96. package/lib/TransBtn.js +39 -0
  97. package/lib/hooks/useAllowClear.d.ts +8 -0
  98. package/lib/hooks/useAllowClear.js +34 -0
  99. package/lib/hooks/useBaseProps.d.ts +13 -0
  100. package/lib/hooks/useBaseProps.js +19 -0
  101. package/lib/hooks/useCache.d.ts +7 -0
  102. package/lib/hooks/useCache.js +49 -0
  103. package/lib/hooks/useDelayReset.d.ts +5 -0
  104. package/lib/hooks/useDelayReset.js +31 -0
  105. package/lib/hooks/useFilterOptions.d.ts +3 -0
  106. package/lib/hooks/useFilterOptions.js +66 -0
  107. package/lib/hooks/useId.d.ts +5 -0
  108. package/lib/hooks/useId.js +40 -0
  109. package/lib/hooks/useLayoutEffect.d.ts +5 -0
  110. package/lib/hooks/useLayoutEffect.js +25 -0
  111. package/lib/hooks/useLock.d.ts +7 -0
  112. package/lib/hooks/useLock.js +34 -0
  113. package/lib/hooks/useOptions.d.ts +12 -0
  114. package/lib/hooks/useOptions.js +52 -0
  115. package/lib/hooks/useRefFunc.d.ts +5 -0
  116. package/lib/hooks/useRefFunc.js +21 -0
  117. package/lib/hooks/useSelectTriggerControl.d.ts +1 -0
  118. package/lib/hooks/useSelectTriggerControl.js +35 -0
  119. package/lib/index.d.ts +10 -0
  120. package/lib/index.js +37 -0
  121. package/lib/interface.d.ts +23 -0
  122. package/lib/interface.js +5 -0
  123. package/lib/utils/__mocks__/platformUtil.d.ts +1 -0
  124. package/lib/utils/__mocks__/platformUtil.js +9 -0
  125. package/lib/utils/commonUtil.d.ts +9 -0
  126. package/lib/utils/commonUtil.js +42 -0
  127. package/lib/utils/keyUtil.d.ts +2 -0
  128. package/lib/utils/keyUtil.js +22 -0
  129. package/lib/utils/legacyUtil.d.ts +3 -0
  130. package/lib/utils/legacyUtil.js +53 -0
  131. package/lib/utils/platformUtil.d.ts +1 -0
  132. package/lib/utils/platformUtil.js +10 -0
  133. package/lib/utils/valueUtil.d.ts +24 -0
  134. package/lib/utils/valueUtil.js +140 -0
  135. package/lib/utils/warningPropsUtil.d.ts +4 -0
  136. package/lib/utils/warningPropsUtil.js +129 -0
  137. package/package.json +86 -0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Locker return cached mark.
3
+ * If set to `true`, will return `true` in a short time even if set `false`.
4
+ * If set to `false` and then set to `true`, will change to `true`.
5
+ * And after time duration, it will back to `null` automatically.
6
+ */
7
+ export default function useLock(duration?: number): [() => boolean, (lock: boolean) => void];
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useLock;
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
+ * Locker return cached mark.
12
+ * If set to `true`, will return `true` in a short time even if set `false`.
13
+ * If set to `false` and then set to `true`, will change to `true`.
14
+ * And after time duration, it will back to `null` automatically.
15
+ */
16
+ function useLock(duration = 250) {
17
+ const lockRef = React.useRef(null);
18
+ const timeoutRef = React.useRef(null);
19
+
20
+ // Clean up
21
+ React.useEffect(() => () => {
22
+ window.clearTimeout(timeoutRef.current);
23
+ }, []);
24
+ function doLock(locked) {
25
+ if (locked || lockRef.current === null) {
26
+ lockRef.current = locked;
27
+ }
28
+ window.clearTimeout(timeoutRef.current);
29
+ timeoutRef.current = window.setTimeout(() => {
30
+ lockRef.current = null;
31
+ }, duration);
32
+ }
33
+ return [() => lockRef.current, doLock];
34
+ }
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import type { FieldNames, RawValueType } from '../Select';
3
+ /**
4
+ * Parse `children` to `options` if `options` is not provided.
5
+ * Then flatten the `options`.
6
+ */
7
+ declare const useOptions: <OptionType>(options: OptionType[], children: React.ReactNode, fieldNames: FieldNames, optionFilterProp: string, optionLabelProp: string) => {
8
+ options: OptionType[];
9
+ valueOptions: Map<RawValueType, OptionType>;
10
+ labelOptions: Map<React.ReactNode, OptionType>;
11
+ };
12
+ export default useOptions;
@@ -0,0 +1,52 @@
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
+ /**
12
+ * Parse `children` to `options` if `options` is not provided.
13
+ * Then flatten the `options`.
14
+ */
15
+ const useOptions = (options, children, fieldNames, optionFilterProp, optionLabelProp) => {
16
+ return React.useMemo(() => {
17
+ let mergedOptions = options;
18
+ const childrenAsData = !options;
19
+ if (childrenAsData) {
20
+ mergedOptions = (0, _legacyUtil.convertChildrenToData)(children);
21
+ }
22
+ const valueOptions = new Map();
23
+ const labelOptions = new Map();
24
+ const setLabelOptions = (labelOptionsMap, option, key) => {
25
+ if (key && typeof key === 'string') {
26
+ labelOptionsMap.set(option[key], option);
27
+ }
28
+ };
29
+ const dig = (optionList, isChildren = false) => {
30
+ // for loop to speed up collection speed
31
+ for (let i = 0; i < optionList.length; i += 1) {
32
+ const option = optionList[i];
33
+ if (!option[fieldNames.options] || isChildren) {
34
+ valueOptions.set(option[fieldNames.value], option);
35
+ setLabelOptions(labelOptions, option, fieldNames.label);
36
+ // https://github.com/ant-design/ant-design/issues/35304
37
+ setLabelOptions(labelOptions, option, optionFilterProp);
38
+ setLabelOptions(labelOptions, option, optionLabelProp);
39
+ } else {
40
+ dig(option[fieldNames.options], true);
41
+ }
42
+ }
43
+ };
44
+ dig(mergedOptions);
45
+ return {
46
+ options: mergedOptions,
47
+ valueOptions,
48
+ labelOptions
49
+ };
50
+ }, [options, children, fieldNames, optionFilterProp, optionLabelProp]);
51
+ };
52
+ var _default = exports.default = useOptions;
@@ -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 @@
1
+ export default function useSelectTriggerControl(elements: () => (HTMLElement | undefined)[], open: boolean, triggerOpen: (open: boolean) => void, customizedTrigger: boolean): void;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useSelectTriggerControl;
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
+ function useSelectTriggerControl(elements, open, triggerOpen, customizedTrigger) {
11
+ const propsRef = React.useRef(null);
12
+ propsRef.current = {
13
+ open,
14
+ triggerOpen,
15
+ customizedTrigger
16
+ };
17
+ React.useEffect(() => {
18
+ function onGlobalMouseDown(event) {
19
+ // If trigger is customized, Trigger will take control of popupVisible
20
+ if (propsRef.current?.customizedTrigger) {
21
+ return;
22
+ }
23
+ let target = event.target;
24
+ if (target.shadowRoot && event.composed) {
25
+ target = event.composedPath()[0] || target;
26
+ }
27
+ if (propsRef.current.open && elements().filter(element => element).every(element => !element.contains(target) && element !== target)) {
28
+ // Should trigger close
29
+ propsRef.current.triggerOpen(false);
30
+ }
31
+ }
32
+ window.addEventListener('mousedown', onGlobalMouseDown);
33
+ return () => window.removeEventListener('mousedown', onGlobalMouseDown);
34
+ }, []);
35
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import Select from './Select';
2
+ import Option from './Option';
3
+ import OptGroup from './OptGroup';
4
+ import type { SelectProps } from './Select';
5
+ import BaseSelect from './BaseSelect';
6
+ import type { BaseSelectProps, BaseSelectRef, BaseSelectPropsWithoutPrivate } from './BaseSelect';
7
+ import useBaseProps from './hooks/useBaseProps';
8
+ export { Option, OptGroup, BaseSelect, useBaseProps };
9
+ export type { SelectProps, BaseSelectProps, BaseSelectRef, BaseSelectPropsWithoutPrivate };
10
+ export default Select;
package/lib/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BaseSelect", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _BaseSelect.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "OptGroup", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _OptGroup.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "Option", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _Option.default;
22
+ }
23
+ });
24
+ exports.default = void 0;
25
+ Object.defineProperty(exports, "useBaseProps", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _useBaseProps.default;
29
+ }
30
+ });
31
+ var _Select = _interopRequireDefault(require("./Select"));
32
+ var _Option = _interopRequireDefault(require("./Option"));
33
+ var _OptGroup = _interopRequireDefault(require("./OptGroup"));
34
+ var _BaseSelect = _interopRequireDefault(require("./BaseSelect"));
35
+ var _useBaseProps = _interopRequireDefault(require("./hooks/useBaseProps"));
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+ var _default = exports.default = _Select.default;
@@ -0,0 +1,23 @@
1
+ import type * as React from 'react';
2
+ export type RawValueType = string | number;
3
+ export interface FlattenOptionData<OptionType> {
4
+ label?: React.ReactNode;
5
+ data: OptionType;
6
+ key: React.Key;
7
+ value?: RawValueType;
8
+ groupOption?: boolean;
9
+ group?: boolean;
10
+ }
11
+ export interface DisplayValueType {
12
+ key?: React.Key;
13
+ value?: RawValueType;
14
+ label?: React.ReactNode;
15
+ title?: React.ReactNode;
16
+ disabled?: boolean;
17
+ index?: number;
18
+ }
19
+ export type RenderNode = React.ReactNode | ((props: any) => React.ReactNode);
20
+ export type RenderDOMFunc = (props: any) => HTMLElement;
21
+ export type Mode = 'multiple' | 'tags' | 'combobox';
22
+ export type Placement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
23
+ export type DisplayInfoType = 'add' | 'remove' | 'clear';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export declare function isPlatformMac(): boolean;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isPlatformMac = isPlatformMac;
7
+ function isPlatformMac() {
8
+ return true;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { DisplayValueType } from '../BaseSelect';
2
+ export declare function toArray<T>(value: T | T[]): T[];
3
+ export declare const isClient: HTMLElement;
4
+ /** Is client side and not jsdom */
5
+ export declare const isBrowserClient: HTMLElement;
6
+ export declare function hasValue(value: any): boolean;
7
+ /** combo mode no value judgment function */
8
+ export declare function isComboNoValue(value: any): boolean;
9
+ export declare function getTitle(item: DisplayValueType): string;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTitle = getTitle;
7
+ exports.hasValue = hasValue;
8
+ exports.isClient = exports.isBrowserClient = void 0;
9
+ exports.isComboNoValue = isComboNoValue;
10
+ exports.toArray = toArray;
11
+ function toArray(value) {
12
+ if (Array.isArray(value)) {
13
+ return value;
14
+ }
15
+ return value !== undefined ? [value] : [];
16
+ }
17
+ const isClient = exports.isClient = typeof window !== 'undefined' && window.document && window.document.documentElement;
18
+
19
+ /** Is client side and not jsdom */
20
+ const isBrowserClient = exports.isBrowserClient = process.env.NODE_ENV !== 'test' && isClient;
21
+ function hasValue(value) {
22
+ return value !== undefined && value !== null;
23
+ }
24
+
25
+ /** combo mode no value judgment function */
26
+ function isComboNoValue(value) {
27
+ return !value && value !== 0;
28
+ }
29
+ function isTitleType(title) {
30
+ return ['string', 'number'].includes(typeof title);
31
+ }
32
+ function getTitle(item) {
33
+ let title = undefined;
34
+ if (item) {
35
+ if (isTitleType(item.title)) {
36
+ title = item.title.toString();
37
+ } else if (isTitleType(item.label)) {
38
+ title = item.label.toString();
39
+ }
40
+ }
41
+ return title;
42
+ }
@@ -0,0 +1,2 @@
1
+ /** keyCode Judgment function */
2
+ export declare function isValidateOpenKey(currentKeyCode: number): boolean;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isValidateOpenKey = isValidateOpenKey;
7
+ var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /** keyCode Judgment function */
10
+ function isValidateOpenKey(currentKeyCode) {
11
+ return (
12
+ // Undefined for Edge bug:
13
+ // https://github.com/ant-design/ant-design/issues/51292
14
+ currentKeyCode &&
15
+ // Other keys
16
+ ![
17
+ // System function button
18
+ _KeyCode.default.ESC, _KeyCode.default.SHIFT, _KeyCode.default.BACKSPACE, _KeyCode.default.TAB, _KeyCode.default.WIN_KEY, _KeyCode.default.ALT, _KeyCode.default.META, _KeyCode.default.WIN_KEY_RIGHT, _KeyCode.default.CTRL, _KeyCode.default.SEMICOLON, _KeyCode.default.EQUALS, _KeyCode.default.CAPS_LOCK, _KeyCode.default.CONTEXT_MENU,
19
+ // F1-F12
20
+ _KeyCode.default.F1, _KeyCode.default.F2, _KeyCode.default.F3, _KeyCode.default.F4, _KeyCode.default.F5, _KeyCode.default.F6, _KeyCode.default.F7, _KeyCode.default.F8, _KeyCode.default.F9, _KeyCode.default.F10, _KeyCode.default.F11, _KeyCode.default.F12].includes(currentKeyCode)
21
+ );
22
+ }
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import type { BaseOptionType, DefaultOptionType } from '../Select';
3
+ export declare function convertChildrenToData<OptionType extends BaseOptionType = DefaultOptionType>(nodes: React.ReactNode, optionOnly?: boolean): OptionType[];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertChildrenToData = convertChildrenToData;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _toArray = _interopRequireDefault(require("@rc-component/util/lib/Children/toArray"));
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 convertNodeToOption(node) {
13
+ const {
14
+ key,
15
+ props: {
16
+ children,
17
+ value,
18
+ ...restProps
19
+ }
20
+ } = node;
21
+ return {
22
+ key,
23
+ value: value !== undefined ? value : key,
24
+ children,
25
+ ...restProps
26
+ };
27
+ }
28
+ function convertChildrenToData(nodes, optionOnly = false) {
29
+ return (0, _toArray.default)(nodes).map((node, index) => {
30
+ if (! /*#__PURE__*/React.isValidElement(node) || !node.type) {
31
+ return null;
32
+ }
33
+ const {
34
+ type: {
35
+ isSelectOptGroup
36
+ },
37
+ key,
38
+ props: {
39
+ children,
40
+ ...restProps
41
+ }
42
+ } = node;
43
+ if (optionOnly || !isSelectOptGroup) {
44
+ return convertNodeToOption(node);
45
+ }
46
+ return {
47
+ key: `__RC_SELECT_GRP__${key === null ? index : key}__`,
48
+ label: key,
49
+ ...restProps,
50
+ options: convertChildrenToData(children)
51
+ };
52
+ }).filter(data => data);
53
+ }
@@ -0,0 +1 @@
1
+ export declare function isPlatformMac(): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isPlatformMac = isPlatformMac;
7
+ /* istanbul ignore file */
8
+ function isPlatformMac() {
9
+ return /(mac\sos|macintosh)/i.test(navigator.appVersion);
10
+ }
@@ -0,0 +1,24 @@
1
+ import type { BaseOptionType, DefaultOptionType } from '../Select';
2
+ import type { FieldNames } from '../Select';
3
+ import type { FlattenOptionData } from '../interface';
4
+ export declare function isValidCount(value?: number): boolean;
5
+ export declare function fillFieldNames(fieldNames: FieldNames | undefined, childrenAsData: boolean): {
6
+ label: string;
7
+ value: string;
8
+ options: string;
9
+ groupLabel: string;
10
+ };
11
+ /**
12
+ * Flat options into flatten list.
13
+ * We use `optionOnly` here is aim to avoid user use nested option group.
14
+ * Here is simply set `key` to the index if not provided.
15
+ */
16
+ export declare function flattenOptions<OptionType extends BaseOptionType = DefaultOptionType>(options: OptionType[], { fieldNames, childrenAsData }?: {
17
+ fieldNames?: FieldNames;
18
+ childrenAsData?: boolean;
19
+ }): FlattenOptionData<OptionType>[];
20
+ /**
21
+ * Inject `props` into `option` for legacy usage
22
+ */
23
+ export declare function injectPropsWithOption<T extends object>(option: T): T;
24
+ export declare const getSeparatedContent: (text: string, tokens: string[], end?: number) => string[];
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fillFieldNames = fillFieldNames;
7
+ exports.flattenOptions = flattenOptions;
8
+ exports.getSeparatedContent = void 0;
9
+ exports.injectPropsWithOption = injectPropsWithOption;
10
+ exports.isValidCount = isValidCount;
11
+ var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function getKey(data, index) {
14
+ const {
15
+ key
16
+ } = data;
17
+ let value;
18
+ if ('value' in data) {
19
+ ({
20
+ value
21
+ } = data);
22
+ }
23
+ if (key !== null && key !== undefined) {
24
+ return key;
25
+ }
26
+ if (value !== undefined) {
27
+ return value;
28
+ }
29
+ return `rc-index-key-${index}`;
30
+ }
31
+ function isValidCount(value) {
32
+ return typeof value !== 'undefined' && !Number.isNaN(value);
33
+ }
34
+ function fillFieldNames(fieldNames, childrenAsData) {
35
+ const {
36
+ label,
37
+ value,
38
+ options,
39
+ groupLabel
40
+ } = fieldNames || {};
41
+ const mergedLabel = label || (childrenAsData ? 'children' : 'label');
42
+ return {
43
+ label: mergedLabel,
44
+ value: value || 'value',
45
+ options: options || 'options',
46
+ groupLabel: groupLabel || mergedLabel
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Flat options into flatten list.
52
+ * We use `optionOnly` here is aim to avoid user use nested option group.
53
+ * Here is simply set `key` to the index if not provided.
54
+ */
55
+ function flattenOptions(options, {
56
+ fieldNames,
57
+ childrenAsData
58
+ } = {}) {
59
+ const flattenList = [];
60
+ const {
61
+ label: fieldLabel,
62
+ value: fieldValue,
63
+ options: fieldOptions,
64
+ groupLabel
65
+ } = fillFieldNames(fieldNames, false);
66
+ function dig(list, isGroupOption) {
67
+ if (!Array.isArray(list)) {
68
+ return;
69
+ }
70
+ list.forEach(data => {
71
+ if (isGroupOption || !(fieldOptions in data)) {
72
+ const value = data[fieldValue];
73
+
74
+ // Option
75
+ flattenList.push({
76
+ key: getKey(data, flattenList.length),
77
+ groupOption: isGroupOption,
78
+ data,
79
+ label: data[fieldLabel],
80
+ value
81
+ });
82
+ } else {
83
+ let grpLabel = data[groupLabel];
84
+ if (grpLabel === undefined && childrenAsData) {
85
+ grpLabel = data.label;
86
+ }
87
+
88
+ // Option Group
89
+ flattenList.push({
90
+ key: getKey(data, flattenList.length),
91
+ group: true,
92
+ data,
93
+ label: grpLabel
94
+ });
95
+ dig(data[fieldOptions], true);
96
+ }
97
+ });
98
+ }
99
+ dig(options, false);
100
+ return flattenList;
101
+ }
102
+
103
+ /**
104
+ * Inject `props` into `option` for legacy usage
105
+ */
106
+ function injectPropsWithOption(option) {
107
+ const newOption = {
108
+ ...option
109
+ };
110
+ if (!('props' in newOption)) {
111
+ Object.defineProperty(newOption, 'props', {
112
+ get() {
113
+ (0, _warning.default)(false, 'Return type is option instead of Option instance. Please read value directly instead of reading from `props`.');
114
+ return newOption;
115
+ }
116
+ });
117
+ }
118
+ return newOption;
119
+ }
120
+ const getSeparatedContent = (text, tokens, end) => {
121
+ if (!tokens || !tokens.length) {
122
+ return null;
123
+ }
124
+ let match = false;
125
+ const separate = (str, [token, ...restTokens]) => {
126
+ if (!token) {
127
+ return [str];
128
+ }
129
+ const list = str.split(token);
130
+ match = match || list.length > 1;
131
+ return list.reduce((prevList, unitStr) => [...prevList, ...separate(unitStr, restTokens)], []).filter(Boolean);
132
+ };
133
+ const list = separate(text, tokens);
134
+ if (match) {
135
+ return typeof end !== 'undefined' ? list.slice(0, end) : list;
136
+ } else {
137
+ return null;
138
+ }
139
+ };
140
+ exports.getSeparatedContent = getSeparatedContent;
@@ -0,0 +1,4 @@
1
+ import type { DefaultOptionType, FieldNames, SelectProps } from '../Select';
2
+ declare function warningProps(props: SelectProps): void;
3
+ export declare function warningNullOptions(options: DefaultOptionType[], fieldNames: FieldNames): void;
4
+ export default warningProps;