@rescui/select 0.18.4 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/_virtual/check-outline.js +294 -63
  2. package/lib/_virtual/close-outline.js +294 -63
  3. package/lib/_virtual/down-outline.js +294 -63
  4. package/lib/_virtual/index.css.js +12 -12
  5. package/lib/_virtual/loading-outline.js +310 -79
  6. package/lib/hooks/use-a11y.d.ts +2 -2
  7. package/lib/hooks/use-a11y.js +124 -36
  8. package/lib/hooks/use-actual-size-from-css.d.ts +3 -4
  9. package/lib/hooks/use-actual-size-from-css.js +47 -18
  10. package/lib/hooks/use-focus.js +54 -10
  11. package/lib/hooks/use-hover.js +54 -10
  12. package/lib/hooks/use-label-focus.js +45 -15
  13. package/lib/hooks/use-multi-handlers.js +113 -38
  14. package/lib/hooks/use-options.d.ts +2 -1
  15. package/lib/hooks/use-options.js +92 -56
  16. package/lib/hooks/use-primary-contrast-css-var-transfer.d.ts +2 -3
  17. package/lib/hooks/use-primary-contrast-css-var-transfer.js +45 -15
  18. package/lib/index.css +194 -194
  19. package/lib/multiselect.js +527 -174
  20. package/lib/native-select.js +416 -118
  21. package/lib/parts/form-trigger-wrapper.js +159 -39
  22. package/lib/parts/hidden-select.js +105 -29
  23. package/lib/parts/icons.js +191 -49
  24. package/lib/parts/list-box.js +277 -74
  25. package/lib/parts/multi-trigger.d.ts +2 -2
  26. package/lib/parts/multi-trigger.js +125 -48
  27. package/lib/parts/native-select-options-with-groups.js +154 -52
  28. package/lib/parts/popup-content.d.ts +3 -3
  29. package/lib/parts/popup-content.js +146 -46
  30. package/lib/select-basic.js +456 -147
  31. package/lib/select-searchable.js +448 -155
  32. package/lib/select.js +228 -56
  33. package/lib/styles/common.p.module.css.js +29 -29
  34. package/lib/styles/form-trigger.p.module.css.js +12 -12
  35. package/lib/styles/list-box.p.module.css.js +13 -13
  36. package/lib/utils/get-text-from-nodes.js +1 -1
  37. package/package.json +13 -12
@@ -1,27 +1,56 @@
1
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
1
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
2
+ import { c } from 'react-compiler-runtime';
2
3
  import { useRef, useState } from 'react';
3
4
  import { useResizeObserver } from '@rescui/use-resize-observer';
4
5
 
5
- const useActualSizeFromCss = _ref => {
6
- let {
6
+ const useActualSizeFromCss = t0 => {
7
+ const $ = c(5);
8
+ const {
7
9
  sizeFromProps,
8
- triggerRef
9
- } = _ref;
10
- // We use invisible and "untouchable" dummy element to observe `size` changes from css to fetch the actual size
10
+ triggerEl
11
+ } = t0;
11
12
  const observableRef = useRef(null);
12
13
  const [size, setSize] = useState(sizeFromProps);
13
- useResizeObserver(observableRef, () => {
14
- var _context;
15
-
16
- const triggerFormWrapperStyles = getComputedStyle(triggerRef.current);
17
- const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue('--_rs-select-size');
18
- const sizeFromCss = _includesInstanceProperty(_context = ['s', 'm', 'l']).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
19
- setSize(sizeFromCss || sizeFromProps);
20
- });
21
- return {
22
- observableRef,
23
- size
24
- };
14
+ let t1;
15
+
16
+ if ($[0] !== sizeFromProps || $[1] !== triggerEl) {
17
+ t1 = () => {
18
+ var _context;
19
+
20
+ const ownerWindow = triggerEl?.ownerDocument.defaultView;
21
+
22
+ if (!ownerWindow) {
23
+ return;
24
+ }
25
+
26
+ const triggerFormWrapperStyles = ownerWindow.getComputedStyle(triggerEl);
27
+ const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue("--_rs-select-size");
28
+ const sizeFromCss = _includesInstanceProperty(_context = ["s", "m", "l"]).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
29
+ setSize(sizeFromCss || sizeFromProps);
30
+ };
31
+
32
+ $[0] = sizeFromProps;
33
+ $[1] = triggerEl;
34
+ $[2] = t1;
35
+ } else {
36
+ t1 = $[2];
37
+ }
38
+
39
+ useResizeObserver(observableRef, t1);
40
+ let t2;
41
+
42
+ if ($[3] !== size) {
43
+ t2 = {
44
+ observableRef,
45
+ size
46
+ };
47
+ $[3] = size;
48
+ $[4] = t2;
49
+ } else {
50
+ t2 = $[4];
51
+ }
52
+
53
+ return t2;
25
54
  };
26
55
 
27
56
  export { useActualSizeFromCss };
@@ -1,17 +1,61 @@
1
+ import { c } from 'react-compiler-runtime';
1
2
  import { useState } from 'react';
2
3
 
3
- const useFocus = _ref => {
4
- let {
4
+ const useFocus = t0 => {
5
+ const $ = c(8);
6
+ const {
5
7
  isDisabled
6
- } = _ref;
8
+ } = t0;
7
9
  const [isFocused, setIsFocused] = useState(false);
8
- return {
9
- isFocused,
10
- focusProps: {
11
- onFocus: () => setIsFocused(!isDisabled),
12
- onBlur: () => setIsFocused(false)
13
- }
14
- };
10
+ let t1;
11
+
12
+ if ($[0] !== isDisabled) {
13
+ t1 = () => setIsFocused(!isDisabled);
14
+
15
+ $[0] = isDisabled;
16
+ $[1] = t1;
17
+ } else {
18
+ t1 = $[1];
19
+ }
20
+
21
+ let t2;
22
+
23
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
24
+ t2 = () => setIsFocused(false);
25
+
26
+ $[2] = t2;
27
+ } else {
28
+ t2 = $[2];
29
+ }
30
+
31
+ let t3;
32
+
33
+ if ($[3] !== t1) {
34
+ t3 = {
35
+ onFocus: t1,
36
+ onBlur: t2
37
+ };
38
+ $[3] = t1;
39
+ $[4] = t3;
40
+ } else {
41
+ t3 = $[4];
42
+ }
43
+
44
+ let t4;
45
+
46
+ if ($[5] !== isFocused || $[6] !== t3) {
47
+ t4 = {
48
+ isFocused,
49
+ focusProps: t3
50
+ };
51
+ $[5] = isFocused;
52
+ $[6] = t3;
53
+ $[7] = t4;
54
+ } else {
55
+ t4 = $[7];
56
+ }
57
+
58
+ return t4;
15
59
  };
16
60
 
17
61
  export { useFocus };
@@ -1,17 +1,61 @@
1
+ import { c } from 'react-compiler-runtime';
1
2
  import { useState } from 'react';
2
3
 
3
- const useHover = _ref => {
4
- let {
4
+ const useHover = t0 => {
5
+ const $ = c(8);
6
+ const {
5
7
  isDisabled
6
- } = _ref;
8
+ } = t0;
7
9
  const [isHovered, setIsHovered] = useState(false);
8
- return {
9
- isHovered,
10
- hoverProps: {
11
- onMouseEnter: () => setIsHovered(!isDisabled),
12
- onMouseLeave: () => setIsHovered(false)
13
- }
14
- };
10
+ let t1;
11
+
12
+ if ($[0] !== isDisabled) {
13
+ t1 = () => setIsHovered(!isDisabled);
14
+
15
+ $[0] = isDisabled;
16
+ $[1] = t1;
17
+ } else {
18
+ t1 = $[1];
19
+ }
20
+
21
+ let t2;
22
+
23
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
24
+ t2 = () => setIsHovered(false);
25
+
26
+ $[2] = t2;
27
+ } else {
28
+ t2 = $[2];
29
+ }
30
+
31
+ let t3;
32
+
33
+ if ($[3] !== t1) {
34
+ t3 = {
35
+ onMouseEnter: t1,
36
+ onMouseLeave: t2
37
+ };
38
+ $[3] = t1;
39
+ $[4] = t3;
40
+ } else {
41
+ t3 = $[4];
42
+ }
43
+
44
+ let t4;
45
+
46
+ if ($[5] !== isHovered || $[6] !== t3) {
47
+ t4 = {
48
+ isHovered,
49
+ hoverProps: t3
50
+ };
51
+ $[5] = isHovered;
52
+ $[6] = t3;
53
+ $[7] = t4;
54
+ } else {
55
+ t4 = $[7];
56
+ }
57
+
58
+ return t4;
15
59
  };
16
60
 
17
61
  export { useHover };
@@ -1,22 +1,52 @@
1
+ import { c } from 'react-compiler-runtime';
1
2
  import { useState } from 'react';
2
3
 
3
4
  const useLabelFocus = () => {
5
+ const $ = c(4);
4
6
  const [isFocusedByLabel, setIsFocusedByLabel] = useState(false);
5
- const triggerFocusProps = {
6
- onBlur: () => {
7
- setIsFocusedByLabel(false);
8
- }
9
- };
10
- const labelClickProps = {
11
- onClick: () => {
12
- setIsFocusedByLabel(true);
13
- }
14
- };
15
- return {
16
- isFocusedByLabel,
17
- triggerFocusProps,
18
- labelClickProps
19
- };
7
+ let t0;
8
+
9
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
10
+ t0 = {
11
+ onBlur: () => {
12
+ setIsFocusedByLabel(false);
13
+ }
14
+ };
15
+ $[0] = t0;
16
+ } else {
17
+ t0 = $[0];
18
+ }
19
+
20
+ const triggerFocusProps = t0;
21
+ let t1;
22
+
23
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
24
+ t1 = {
25
+ onClick: () => {
26
+ setIsFocusedByLabel(true);
27
+ }
28
+ };
29
+ $[1] = t1;
30
+ } else {
31
+ t1 = $[1];
32
+ }
33
+
34
+ const labelClickProps = t1;
35
+ let t2;
36
+
37
+ if ($[2] !== isFocusedByLabel) {
38
+ t2 = {
39
+ isFocusedByLabel,
40
+ triggerFocusProps,
41
+ labelClickProps
42
+ };
43
+ $[2] = isFocusedByLabel;
44
+ $[3] = t2;
45
+ } else {
46
+ t2 = $[3];
47
+ }
48
+
49
+ return t2;
20
50
  };
21
51
 
22
52
  export { useLabelFocus };
@@ -1,47 +1,122 @@
1
- import { useRef, useMemo, useCallback, useEffect, useLayoutEffect } from 'react';
1
+ import { c } from 'react-compiler-runtime';
2
+ import { useRef, useEffect, useLayoutEffect } from 'react';
2
3
  import { getOptionValue } from '../utils/get-option-value.js';
3
4
  const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
4
5
 
5
- const useMultiHandlers = _ref => {
6
- let {
6
+ const useMultiHandlers = t0 => {
7
+ const $ = c(14);
8
+ const {
7
9
  selectedItems,
8
10
  onChange
9
- } = _ref;
11
+ } = t0;
10
12
  const onChangeRef = useRef(null);
11
- useIsomorphicLayoutEffect(() => {
12
- onChangeRef.current = onChange;
13
- }, [onChange]);
14
- const selectedMap = useMemo(() => new Map(selectedItems.map(item => [getOptionValue(item), item])), [selectedItems]);
15
- const addItem = useCallback(item => {
16
- if (selectedMap.has(getOptionValue(item))) {
17
- return;
18
- }
19
-
20
- const newValues = [...selectedMap.values(), item];
21
- onChangeRef.current?.(newValues);
22
- }, [selectedMap]);
23
- const removeItem = useCallback(item => {
24
- const key = getOptionValue(item);
25
- const newValues = [...selectedMap.entries()].filter(_ref2 => {
26
- let [k] = _ref2;
27
- return k !== key;
28
- }).map(_ref3 => {
29
- let [, v] = _ref3;
30
- return v;
31
- });
32
- onChangeRef.current?.(newValues);
33
- }, [selectedMap]);
34
-
35
- const removeAllItems = () => {
36
- onChangeRef.current?.([]);
37
- };
38
-
39
- return {
40
- selectedMap,
41
- addItem,
42
- removeItem,
43
- removeAllItems
44
- };
13
+ let t1;
14
+ let t2;
15
+
16
+ if ($[0] !== onChange) {
17
+ t1 = () => {
18
+ onChangeRef.current = onChange;
19
+ };
20
+
21
+ t2 = [onChange];
22
+ $[0] = onChange;
23
+ $[1] = t1;
24
+ $[2] = t2;
25
+ } else {
26
+ t1 = $[1];
27
+ t2 = $[2];
28
+ }
29
+
30
+ useIsomorphicLayoutEffect(t1, t2);
31
+ let t3;
32
+
33
+ if ($[3] !== selectedItems) {
34
+ t3 = new Map(selectedItems.map(_temp));
35
+ $[3] = selectedItems;
36
+ $[4] = t3;
37
+ } else {
38
+ t3 = $[4];
39
+ }
40
+
41
+ const selectedMap = t3;
42
+ let t4;
43
+
44
+ if ($[5] !== selectedMap) {
45
+ t4 = item_0 => {
46
+ if (selectedMap.has(getOptionValue(item_0))) {
47
+ return;
48
+ }
49
+
50
+ const newValues = [...selectedMap.values(), item_0];
51
+ onChangeRef.current?.(newValues);
52
+ };
53
+
54
+ $[5] = selectedMap;
55
+ $[6] = t4;
56
+ } else {
57
+ t4 = $[6];
58
+ }
59
+
60
+ const addItem = t4;
61
+ let t5;
62
+
63
+ if ($[7] !== selectedMap) {
64
+ t5 = item_1 => {
65
+ const key = getOptionValue(item_1);
66
+ const newValues_0 = [...selectedMap.entries()].filter(t6 => {
67
+ const [k] = t6;
68
+ return k !== key;
69
+ }).map(_temp2);
70
+ onChangeRef.current?.(newValues_0);
71
+ };
72
+
73
+ $[7] = selectedMap;
74
+ $[8] = t5;
75
+ } else {
76
+ t5 = $[8];
77
+ }
78
+
79
+ const removeItem = t5;
80
+ let t6;
81
+
82
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
83
+ t6 = () => {
84
+ onChangeRef.current?.([]);
85
+ };
86
+
87
+ $[9] = t6;
88
+ } else {
89
+ t6 = $[9];
90
+ }
91
+
92
+ const removeAllItems = t6;
93
+ let t7;
94
+
95
+ if ($[10] !== addItem || $[11] !== removeItem || $[12] !== selectedMap) {
96
+ t7 = {
97
+ selectedMap,
98
+ addItem,
99
+ removeItem,
100
+ removeAllItems
101
+ };
102
+ $[10] = addItem;
103
+ $[11] = removeItem;
104
+ $[12] = selectedMap;
105
+ $[13] = t7;
106
+ } else {
107
+ t7 = $[13];
108
+ }
109
+
110
+ return t7;
45
111
  };
46
112
 
113
+ function _temp(item) {
114
+ return [getOptionValue(item), item];
115
+ }
116
+
117
+ function _temp2(t0) {
118
+ const [, v] = t0;
119
+ return v;
120
+ }
121
+
47
122
  export { useMultiHandlers };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import type { SelectOptionOrGroup, SelectOption, ListBoxItem } from '../types';
2
3
  /**
3
4
  * Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
@@ -6,7 +7,7 @@ import type { SelectOptionOrGroup, SelectOption, ListBoxItem } from '../types';
6
7
  * @param options
7
8
  */
8
9
  export declare const useOptions: (options: SelectOptionOrGroup[]) => {
9
- setFilterString: import("react").Dispatch<import("react").SetStateAction<string>>;
10
+ setFilterString: React.Dispatch<React.SetStateAction<string>>;
10
11
  filterString: string;
11
12
  flattenedOptions: SelectOption[];
12
13
  listBoxItems: ListBoxItem[];
@@ -1,5 +1,6 @@
1
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
- import { useState, useMemo } from 'react';
1
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
2
+ import { c } from 'react-compiler-runtime';
3
+ import { useState } from 'react';
3
4
  import { isOptionAGroup } from '../utils/is-option-a-group.js';
4
5
  import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
5
6
  import { getOptionValue } from '../utils/get-option-value.js';
@@ -16,6 +17,61 @@ const createFilter = substring => {
16
17
  return _includesInstanceProperty(_context = string.toLowerCase()).call(_context, lowerSubstring);
17
18
  };
18
19
  };
20
+
21
+ const processOptions = (options, filterFn) => {
22
+ const flattenedOptions = [];
23
+ const listBoxItems = [];
24
+ let index = 0;
25
+
26
+ const createOptionItem = option => {
27
+ return { ...option,
28
+ index: index++,
29
+ type: 'option',
30
+ key: getOptionValue(option)
31
+ };
32
+ };
33
+
34
+ options.forEach((optionOrGroup, arrayIndex) => {
35
+ if (isOptionAGroup(optionOrGroup)) {
36
+ const group = optionOrGroup;
37
+
38
+ if (!group.options || group.options.length === 0) {
39
+ return;
40
+ } // Render as Group (with or without label)
41
+
42
+
43
+ const groupLabelText = group.label ? getTextFromNodes(group.label) : ''; // Use a special prefix that's unlikely to collide with user values
44
+
45
+ const groupKey = `\0__rs_select_group_${arrayIndex}_${groupLabelText}`;
46
+ const listBoxGroupItem = { ...group,
47
+ type: 'group',
48
+ options: [],
49
+ key: groupKey
50
+ };
51
+ group.options.forEach(option => {
52
+ if (filterFn(getTextFromNodes(option.label))) {
53
+ flattenedOptions.push(option);
54
+ listBoxGroupItem.options.push(createOptionItem(option));
55
+ }
56
+ });
57
+
58
+ if (listBoxGroupItem.options.length > 0) {
59
+ listBoxItems.push(listBoxGroupItem);
60
+ }
61
+
62
+ return;
63
+ }
64
+
65
+ if (filterFn(getTextFromNodes(optionOrGroup.label))) {
66
+ flattenedOptions.push(optionOrGroup);
67
+ listBoxItems.push(createOptionItem(optionOrGroup));
68
+ }
69
+ });
70
+ return {
71
+ flattenedOptions,
72
+ listBoxItems
73
+ };
74
+ };
19
75
  /**
20
76
  * Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
21
77
  * Also creating a list for ListBox component with indexes and keys.
@@ -25,66 +81,46 @@ const createFilter = substring => {
25
81
 
26
82
 
27
83
  const useOptions = options => {
28
- const [filterString, setFilterString] = useState('');
29
- const filterFn = useMemo(() => createFilter(filterString), [filterString]);
30
- const processedOptions = useMemo(() => {
31
- const flattenedOptions = [];
32
- const listBoxItems = [];
33
- let index = 0;
34
-
35
- const createOptionItem = option => {
36
- return { ...option,
37
- index: index++,
38
- type: 'option',
39
- key: getOptionValue(option)
40
- };
41
- };
84
+ const $ = c(8);
85
+ const [filterString, setFilterString] = useState("");
86
+ let t0;
42
87
 
43
- options.forEach((optionOrGroup, arrayIndex) => {
44
- if (isOptionAGroup(optionOrGroup)) {
45
- const group = optionOrGroup;
46
-
47
- if (!group.options || group.options.length === 0) {
48
- return;
49
- } // Render as Group (with or without label)
50
-
51
-
52
- const groupLabelText = group.label ? getTextFromNodes(group.label) : ''; // Use a special prefix that's unlikely to collide with user values
88
+ if ($[0] !== filterString) {
89
+ t0 = createFilter(filterString);
90
+ $[0] = filterString;
91
+ $[1] = t0;
92
+ } else {
93
+ t0 = $[1];
94
+ }
53
95
 
54
- const groupKey = `\0__rs_select_group_${arrayIndex}_${groupLabelText}`;
55
- const listBoxGroupItem = { ...group,
56
- type: 'group',
57
- options: [],
58
- key: groupKey
59
- };
60
- group.options.forEach(option => {
61
- if (filterFn(getTextFromNodes(option.label))) {
62
- flattenedOptions.push(option);
63
- listBoxGroupItem.options.push(createOptionItem(option));
64
- }
65
- });
96
+ const filterFn = t0;
97
+ let t1;
66
98
 
67
- if (listBoxGroupItem.options.length > 0) {
68
- listBoxItems.push(listBoxGroupItem);
69
- }
99
+ if ($[2] !== filterFn || $[3] !== options) {
100
+ t1 = processOptions(options, filterFn);
101
+ $[2] = filterFn;
102
+ $[3] = options;
103
+ $[4] = t1;
104
+ } else {
105
+ t1 = $[4];
106
+ }
70
107
 
71
- return;
72
- }
108
+ const processedOptions = t1;
109
+ let t2;
73
110
 
74
- if (filterFn(getTextFromNodes(optionOrGroup.label))) {
75
- flattenedOptions.push(optionOrGroup);
76
- listBoxItems.push(createOptionItem(optionOrGroup));
77
- }
78
- });
79
- return {
80
- flattenedOptions,
81
- listBoxItems
111
+ if ($[5] !== filterString || $[6] !== processedOptions) {
112
+ t2 = { ...processedOptions,
113
+ setFilterString,
114
+ filterString
82
115
  };
83
- }, [options, filterFn]);
84
- return { ...processedOptions,
85
- setFilterString,
86
- filterString
87
- };
116
+ $[5] = filterString;
117
+ $[6] = processedOptions;
118
+ $[7] = t2;
119
+ } else {
120
+ t2 = $[7];
121
+ }
122
+
123
+ return t2;
88
124
  };
89
125
 
90
126
  export { useOptions };
@@ -1,11 +1,10 @@
1
- import React from 'react';
2
1
  export type UsePrimaryContrastCssVarTransferParams = {
3
- triggerRef: React.RefObject<HTMLElement>;
2
+ triggerEl: HTMLElement | null;
4
3
  isOpen: boolean;
5
4
  };
6
5
  /**
7
6
  * Transfer primary contrast css var to the dropdown, but only when the dropdown opens
8
7
  */
9
- export declare const usePrimaryContrastCssVarTransfer: ({ triggerRef, isOpen }: UsePrimaryContrastCssVarTransferParams) => {
8
+ export declare const usePrimaryContrastCssVarTransfer: ({ triggerEl, isOpen }: UsePrimaryContrastCssVarTransferParams) => {
10
9
  isPrimaryContrast: boolean;
11
10
  };