@rescui/select 0.15.1-RUI-280-Update-select-component-e516591ed.54 → 0.15.1-RUI-280-Update-select-component-downshift-cd2a98813.66

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 (65) hide show
  1. package/lib/_virtual/index.css.js +12 -12
  2. package/lib/constants.d.ts +0 -1
  3. package/lib/constants.js +1 -2
  4. package/lib/hooks/use-a11y.d.ts +29 -0
  5. package/lib/hooks/use-a11y.js +53 -0
  6. package/lib/hooks/use-backward-compatible-id.d.ts +4 -0
  7. package/lib/hooks/use-backward-compatible-id.js +14 -0
  8. package/lib/hooks/use-label-focus.d.ts +1 -3
  9. package/lib/hooks/use-label-focus.js +3 -9
  10. package/lib/hooks/use-multi-handlers.d.ts +11 -0
  11. package/lib/hooks/use-multi-handlers.js +48 -0
  12. package/lib/hooks/use-options.d.ts +13 -0
  13. package/lib/hooks/use-options.js +89 -0
  14. package/lib/index.css +323 -371
  15. package/lib/multiselect.d.ts +3 -29
  16. package/lib/multiselect.js +249 -171
  17. package/lib/native-select.js +67 -44
  18. package/lib/parts/hidden-select.d.ts +13 -0
  19. package/lib/parts/hidden-select.js +45 -0
  20. package/lib/parts/icons.d.ts +3 -1
  21. package/lib/parts/icons.js +11 -14
  22. package/lib/parts/list-box.d.ts +7 -15
  23. package/lib/parts/list-box.js +50 -80
  24. package/lib/parts/multi-trigger.d.ts +5 -4
  25. package/lib/parts/multi-trigger.js +27 -15
  26. package/lib/parts/native-select-trigger.d.ts +6 -8
  27. package/lib/parts/native-select-trigger.js +14 -23
  28. package/lib/select-basic.d.ts +2 -2
  29. package/lib/select-basic.js +162 -95
  30. package/lib/select-searchable.d.ts +2 -2
  31. package/lib/select-searchable.js +209 -119
  32. package/lib/select.d.ts +1 -1
  33. package/lib/select.js +38 -31
  34. package/lib/styles/common.p.module.css.js +25 -24
  35. package/lib/styles/form-trigger.p.module.css.js +12 -12
  36. package/lib/styles/list-box.p.module.css.js +11 -13
  37. package/lib/styles/native-select-trigger.p.module.css.js +15 -14
  38. package/lib/styles/native-select.p.module.css.js +6 -6
  39. package/lib/types.d.ts +26 -26
  40. package/lib/utils/get-real-items-cnt.d.ts +2 -2
  41. package/lib/utils/get-real-items-cnt.js +8 -10
  42. package/lib/utils/item-to-string.d.ts +2 -0
  43. package/lib/utils/item-to-string.js +7 -0
  44. package/lib/utils/merge-props.d.ts +29 -0
  45. package/lib/utils/merge-props.js +106 -0
  46. package/package.json +12 -8
  47. package/lib/hooks/use-css-context-transfer.d.ts +0 -14
  48. package/lib/hooks/use-css-context-transfer.js +0 -40
  49. package/lib/hooks/use-multi-option-serialization.d.ts +0 -10
  50. package/lib/hooks/use-multi-option-serialization.js +0 -82
  51. package/lib/hooks/use-observable-force-rerender.d.ts +0 -2
  52. package/lib/hooks/use-observable-force-rerender.js +0 -16
  53. package/lib/hooks/use-option-serialization.d.ts +0 -10
  54. package/lib/hooks/use-option-serialization.js +0 -59
  55. package/lib/parts/popover.d.ts +0 -12
  56. package/lib/parts/popover.js +0 -62
  57. package/lib/parts/popup-content.d.ts +0 -19
  58. package/lib/parts/popup-content.js +0 -76
  59. package/lib/styles/popover.p.module.css.js +0 -10
  60. package/lib/utils/convert-options.d.ts +0 -3
  61. package/lib/utils/convert-options.js +0 -52
  62. package/lib/utils/convert-placement.d.ts +0 -3
  63. package/lib/utils/convert-placement.js +0 -22
  64. package/lib/utils/css-vars-utils.d.ts +0 -3
  65. package/lib/utils/css-vars-utils.js +0 -20
@@ -1,15 +1,15 @@
1
1
  var styles = {
2
- "icon": "_icon_1ouylgb_4",
3
- "sizeXS": "_sizeXS_1ouylgb_14",
4
- "sizeS": "_sizeS_1ouylgb_18",
5
- "sizeM": "_sizeM_1ouylgb_22",
6
- "sizeL": "_sizeL_1ouylgb_26",
7
- "light": "_light_1ouylgb_30",
8
- "dark": "_dark_1ouylgb_34",
9
- "allVariants": "_allVariants_1ouylgb_48",
10
- "variant16": "_variant16_1ouylgb_53",
11
- "variant20": "_variant20_1ouylgb_54",
12
- "variant24": "_variant24_1ouylgb_55",
13
- "variant28": "_variant28_1ouylgb_58"
2
+ "icon": "_icon_3cnwak_4",
3
+ "sizeXS": "_sizeXS_3cnwak_14",
4
+ "sizeS": "_sizeS_3cnwak_18",
5
+ "sizeM": "_sizeM_3cnwak_22",
6
+ "sizeL": "_sizeL_3cnwak_26",
7
+ "light": "_light_3cnwak_30",
8
+ "dark": "_dark_3cnwak_34",
9
+ "allVariants": "_allVariants_3cnwak_48",
10
+ "variant16": "_variant16_3cnwak_53",
11
+ "variant20": "_variant20_3cnwak_54",
12
+ "variant24": "_variant24_3cnwak_55",
13
+ "variant28": "_variant28_3cnwak_58"
14
14
  };
15
15
  export { styles as default };
@@ -1,4 +1,3 @@
1
- export declare const VIRTUAL_ITEMS_SECTION_KEY = "\0__rs_hidden_section_virtual_items__";
2
1
  export declare const NO_OPTIONS_VALUE = "\0__rs_select_no_options__";
3
2
  export declare const DEFAULT_NO_OPTIONS_MESSAGES: {
4
3
  noOptions: string;
package/lib/constants.js CHANGED
@@ -1,8 +1,7 @@
1
- const VIRTUAL_ITEMS_SECTION_KEY = `\0__rs_hidden_section_virtual_items__`;
2
1
  const NO_OPTIONS_VALUE = '\0__rs_select_no_options__';
3
2
  const DEFAULT_NO_OPTIONS_MESSAGES = {
4
3
  noOptions: 'No options',
5
4
  nothingFound: 'Nothing found',
6
5
  loading: 'Loading...'
7
6
  };
8
- export { DEFAULT_NO_OPTIONS_MESSAGES, NO_OPTIONS_VALUE, VIRTUAL_ITEMS_SECTION_KEY };
7
+ export { DEFAULT_NO_OPTIONS_MESSAGES, NO_OPTIONS_VALUE };
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ export declare type UseA11yArgs = {
3
+ prefix?: string;
4
+ baseId?: string;
5
+ description?: React.ReactNode;
6
+ error?: React.ReactNode;
7
+ label?: React.ReactNode;
8
+ fieldRef?: React.RefObject<HTMLElement>;
9
+ };
10
+ export declare const useA11y: ({ baseId: baseIdFromProps, prefix, description, error, label, fieldRef }: UseA11yArgs) => {
11
+ baseId: string;
12
+ fieldProps: {
13
+ 'aria-invalid': boolean;
14
+ 'aria-describedby': string;
15
+ 'aria-labelledby': string;
16
+ id: string;
17
+ };
18
+ descriptionProps: {
19
+ id: string;
20
+ };
21
+ errorMessageProps: {
22
+ id: string;
23
+ };
24
+ labelProps: {
25
+ id: string;
26
+ htmlFor: string;
27
+ onClick: () => void;
28
+ };
29
+ };
@@ -0,0 +1,53 @@
1
+ import { useBackwardCompatibleId } from './use-backward-compatible-id.js'; // eslint-disable-next-line complexity
2
+
3
+ const useA11y = _ref => {
4
+ let {
5
+ baseId: baseIdFromProps,
6
+ prefix = '',
7
+ description,
8
+ error,
9
+ label,
10
+ fieldRef
11
+ } = _ref;
12
+ const uniqueId = `${prefix ? `${prefix}-` : ''}${useBackwardCompatibleId()}`;
13
+ const baseId = baseIdFromProps ?? uniqueId;
14
+ const fieldId = `${baseId}-field`;
15
+ const descriptionId = description ? `${baseId}-description` : undefined;
16
+ const errorId = error ? `${baseId}-error` : undefined;
17
+ const labelId = label ? `${baseId}-label` : undefined;
18
+ const describedBy = [descriptionId, errorId].filter(Boolean).join(' ') || undefined;
19
+ const fieldProps = {
20
+ 'aria-invalid': Boolean(error),
21
+ 'aria-describedby': describedBy,
22
+ 'aria-labelledby': labelId,
23
+ id: fieldId
24
+ };
25
+ const errorMessageProps = {
26
+ id: errorId
27
+ };
28
+ const descriptionProps = {
29
+ id: descriptionId
30
+ };
31
+ const labelProps = {
32
+ id: labelId,
33
+ htmlFor: fieldId,
34
+ onClick: () => {
35
+ if (fieldRef !== null && fieldRef !== void 0 && fieldRef.current) {
36
+ fieldRef.current.focus();
37
+ } else {
38
+ var _document$getElementB;
39
+
40
+ (_document$getElementB = document.getElementById(fieldId)) === null || _document$getElementB === void 0 || _document$getElementB.focus();
41
+ }
42
+ }
43
+ };
44
+ return {
45
+ baseId,
46
+ fieldProps,
47
+ descriptionProps,
48
+ errorMessageProps,
49
+ labelProps
50
+ };
51
+ };
52
+
53
+ export { useA11y };
@@ -0,0 +1,4 @@
1
+ export declare const useBackwardCompatibleId: {
2
+ (): string | number;
3
+ counter: number;
4
+ };
@@ -0,0 +1,14 @@
1
+ import React, { useRef } from 'react';
2
+
3
+ const useBackwardCompatibleId = () => {
4
+ const id = useRef(null);
5
+
6
+ if (id.current === null) {
7
+ id.current = useBackwardCompatibleId.counter++;
8
+ }
9
+
10
+ return (React.useId ? React.useId : () => id.current)();
11
+ };
12
+
13
+ useBackwardCompatibleId.counter = 0;
14
+ export { useBackwardCompatibleId };
@@ -1,8 +1,6 @@
1
- import React from 'react';
2
- export declare const useLabelFocus: (triggerRef: React.RefObject<HTMLElement>) => {
1
+ export declare const useLabelFocus: () => {
3
2
  isFocusedByLabel: boolean;
4
3
  triggerFocusProps: {
5
- onFocus: () => void;
6
4
  onBlur: () => void;
7
5
  };
8
6
  labelClickProps: {
@@ -1,21 +1,15 @@
1
- import { useRef, useState } from 'react';
1
+ import { useState } from 'react';
2
2
 
3
- const useLabelFocus = triggerRef => {
4
- const isLabelClick = useRef(false);
3
+ const useLabelFocus = () => {
5
4
  const [isFocusedByLabel, setIsFocusedByLabel] = useState(false);
6
5
  const triggerFocusProps = {
7
- onFocus: () => {
8
- setIsFocusedByLabel(isLabelClick.current);
9
- },
10
6
  onBlur: () => {
11
7
  setIsFocusedByLabel(false);
12
8
  }
13
9
  };
14
10
  const labelClickProps = {
15
11
  onClick: () => {
16
- isLabelClick.current = true;
17
- triggerRef.current.focus();
18
- isLabelClick.current = false;
12
+ setIsFocusedByLabel(true);
19
13
  }
20
14
  };
21
15
  return {
@@ -0,0 +1,11 @@
1
+ import type { SelectOption } from '../types';
2
+ export declare type UseMultiHandlersArgs = {
3
+ selectedItems: SelectOption[];
4
+ onChange: (value: SelectOption[]) => void;
5
+ };
6
+ export declare const useMultiHandlers: ({ selectedItems, onChange }: UseMultiHandlersArgs) => {
7
+ selectedMap: Map<import("../types").Key, SelectOption>;
8
+ addItem: (item: SelectOption) => void;
9
+ removeItem: (item: SelectOption) => void;
10
+ removeAllItems: () => void;
11
+ };
@@ -0,0 +1,48 @@
1
+ import { useRef, useMemo, useCallback } from 'react';
2
+ import { getOptionValue } from '../utils/get-option-value.js';
3
+
4
+ const useMultiHandlers = _ref => {
5
+ let {
6
+ selectedItems,
7
+ onChange
8
+ } = _ref;
9
+ const onChangeRef = useRef(null);
10
+ onChangeRef.current = onChange;
11
+ const selectedMap = useMemo(() => new Map(selectedItems.map(item => [getOptionValue(item), item])), [selectedItems]);
12
+ const addItem = useCallback(item => {
13
+ var _onChangeRef$current;
14
+
15
+ if (selectedMap.has(getOptionValue(item))) {
16
+ return;
17
+ }
18
+
19
+ (_onChangeRef$current = onChangeRef.current) === null || _onChangeRef$current === void 0 || _onChangeRef$current.call(onChangeRef, [...selectedMap.values(), item]);
20
+ }, [selectedMap]);
21
+ const removeItem = useCallback(item => {
22
+ var _onChangeRef$current2;
23
+
24
+ const key = getOptionValue(item);
25
+ (_onChangeRef$current2 = onChangeRef.current) === null || _onChangeRef$current2 === void 0 || _onChangeRef$current2.call(onChangeRef, [...selectedMap.entries()].filter(_ref2 => {
26
+ let [k] = _ref2;
27
+ return k !== key;
28
+ }).map(_ref3 => {
29
+ let [, v] = _ref3;
30
+ return v;
31
+ }));
32
+ }, [selectedMap]);
33
+
34
+ const removeAllItems = () => {
35
+ var _onChangeRef$current3;
36
+
37
+ (_onChangeRef$current3 = onChangeRef.current) === null || _onChangeRef$current3 === void 0 || _onChangeRef$current3.call(onChangeRef, []);
38
+ };
39
+
40
+ return {
41
+ selectedMap,
42
+ addItem,
43
+ removeItem,
44
+ removeAllItems
45
+ };
46
+ };
47
+
48
+ export { useMultiHandlers };
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import type { SelectOptionOrGroup, SelectOption, ListBoxItem } from '../types';
3
+ /**
4
+ * Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
5
+ * Also creating a list for ListBox component with indexes and keys.
6
+ * Supports filtering by returning the setFilterString function.
7
+ * @param options
8
+ */
9
+ export declare const useOptions: (options: SelectOptionOrGroup[]) => {
10
+ setFilterString: import("react").Dispatch<import("react").SetStateAction<string>>;
11
+ flattenedOptions: SelectOption[];
12
+ listBoxItems: ListBoxItem[];
13
+ };
@@ -0,0 +1,89 @@
1
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
+ import { useState, useMemo } from 'react';
3
+ import { isOptionAGroup } from '../utils/is-option-a-group.js';
4
+ import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
5
+ import { getOptionValue } from '../utils/get-option-value.js';
6
+
7
+ const createFilter = substring => {
8
+ if (substring.length === 0) {
9
+ return () => true;
10
+ }
11
+
12
+ const lowerSubstring = substring.toLowerCase();
13
+ return string => {
14
+ var _context;
15
+
16
+ return _includesInstanceProperty(_context = string.toLowerCase()).call(_context, lowerSubstring);
17
+ };
18
+ };
19
+ /**
20
+ * Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
21
+ * Also creating a list for ListBox component with indexes and keys.
22
+ * Supports filtering by returning the setFilterString function.
23
+ * @param options
24
+ */
25
+
26
+
27
+ 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
+ };
42
+
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
53
+
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
+ });
66
+
67
+ if (listBoxGroupItem.options.length > 0) {
68
+ listBoxItems.push(listBoxGroupItem);
69
+ }
70
+
71
+ return;
72
+ }
73
+
74
+ if (filterFn(getTextFromNodes(optionOrGroup.label))) {
75
+ flattenedOptions.push(optionOrGroup);
76
+ listBoxItems.push(createOptionItem(optionOrGroup));
77
+ }
78
+ });
79
+ return {
80
+ flattenedOptions,
81
+ listBoxItems
82
+ };
83
+ }, [options, filterFn]);
84
+ return { ...processedOptions,
85
+ setFilterString
86
+ };
87
+ };
88
+
89
+ export { useOptions };