@rescui/select 0.15.2 → 0.16.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/lib/_virtual/index.css.js +12 -12
  2. package/lib/common-prop-types.d.ts +8 -14
  3. package/lib/common-prop-types.js +4 -3
  4. package/lib/constants.d.ts +6 -0
  5. package/lib/constants.js +7 -0
  6. package/lib/hooks/use-a11y.d.ts +30 -0
  7. package/lib/hooks/use-a11y.js +56 -0
  8. package/lib/hooks/use-actual-size-from-css.d.ts +10 -0
  9. package/lib/hooks/use-actual-size-from-css.js +27 -0
  10. package/lib/hooks/use-focus.d.ts +10 -0
  11. package/lib/hooks/use-focus.js +17 -0
  12. package/lib/hooks/use-hover.d.ts +10 -0
  13. package/lib/hooks/use-hover.js +17 -0
  14. package/lib/hooks/use-label-focus.d.ts +9 -0
  15. package/lib/hooks/use-label-focus.js +22 -0
  16. package/lib/hooks/use-multi-handlers.d.ts +11 -0
  17. package/lib/hooks/use-multi-handlers.js +44 -0
  18. package/lib/hooks/use-options.d.ts +14 -0
  19. package/lib/hooks/use-options.js +90 -0
  20. package/lib/hooks/use-primary-contrast-css-var-transfer.d.ts +11 -0
  21. package/lib/hooks/use-primary-contrast-css-var-transfer.js +29 -0
  22. package/lib/hooks/use-safe-id.d.ts +6 -0
  23. package/lib/hooks/use-safe-id.js +15 -0
  24. package/lib/index.css +713 -304
  25. package/lib/index.d.ts +4 -6
  26. package/lib/index.js +3 -3
  27. package/lib/multiselect.d.ts +3 -0
  28. package/lib/multiselect.js +308 -0
  29. package/lib/native-select.d.ts +4 -0
  30. package/lib/native-select.js +208 -0
  31. package/lib/parts/foldable.js +1 -2
  32. package/lib/parts/form-trigger-wrapper.d.ts +7 -7
  33. package/lib/parts/form-trigger-wrapper.js +16 -34
  34. package/lib/parts/hidden-select.d.ts +13 -0
  35. package/lib/parts/hidden-select.js +45 -0
  36. package/lib/parts/icons.d.ts +17 -0
  37. package/lib/parts/icons.js +69 -0
  38. package/lib/parts/list-box.d.ts +13 -0
  39. package/lib/parts/list-box.js +120 -0
  40. package/lib/parts/multi-trigger.d.ts +12 -0
  41. package/lib/parts/multi-trigger.js +70 -0
  42. package/lib/parts/native-select-options-with-groups.d.ts +8 -0
  43. package/lib/parts/native-select-options-with-groups.js +76 -0
  44. package/lib/parts/popup-content.d.ts +20 -0
  45. package/lib/parts/popup-content.js +68 -0
  46. package/lib/public-api.p.css +543 -307
  47. package/lib/public-api.pcss +543 -307
  48. package/lib/select-basic.d.ts +3 -0
  49. package/lib/select-basic.js +204 -0
  50. package/lib/select-searchable.d.ts +3 -0
  51. package/lib/select-searchable.js +245 -0
  52. package/lib/select.d.ts +27 -91
  53. package/lib/select.js +51 -351
  54. package/lib/styles/common.p.module.css.js +32 -0
  55. package/lib/styles/form-trigger.p.module.css.js +15 -0
  56. package/lib/styles/list-box.p.module.css.js +16 -0
  57. package/lib/types.d.ts +172 -4
  58. package/lib/utils/calculate-max-height-by-items.d.ts +13 -0
  59. package/lib/utils/calculate-max-height-by-items.js +22 -0
  60. package/lib/utils/get-empty-message.d.ts +6 -0
  61. package/lib/utils/get-empty-message.js +32 -0
  62. package/lib/utils/get-option-value.d.ts +2 -0
  63. package/lib/utils/get-option-value.js +11 -0
  64. package/lib/utils/get-real-items-cnt.d.ts +2 -0
  65. package/lib/utils/get-real-items-cnt.js +19 -0
  66. package/lib/utils/get-text-from-nodes.d.ts +2 -0
  67. package/lib/utils/get-text-from-nodes.js +26 -0
  68. package/lib/utils/is-option-a-group.d.ts +2 -0
  69. package/lib/utils/is-option-a-group.js +5 -0
  70. package/lib/utils/item-to-string.d.ts +2 -0
  71. package/lib/utils/item-to-string.js +7 -0
  72. package/lib/utils/merge-props.d.ts +19 -0
  73. package/lib/utils/merge-props.js +104 -0
  74. package/lib/utils/throttle.d.ts +1 -0
  75. package/package.json +6 -6
  76. package/lib/key-codes.d.ts +0 -7
  77. package/lib/key-codes.js +0 -8
  78. package/lib/parts/common-select.p.module.css.js +0 -15
  79. package/lib/parts/form-trigger.p.module.css.js +0 -15
  80. package/lib/parts/multiselect.d.ts +0 -86
  81. package/lib/parts/multiselect.js +0 -455
  82. package/lib/parts/native-select.d.ts +0 -36
  83. package/lib/parts/native-select.js +0 -255
  84. package/lib/parts/native-select.p.module.css.js +0 -9
  85. package/lib/parts/throttle.d.ts +0 -1
  86. package/lib/parts/trigger.d.ts +0 -37
  87. package/lib/parts/trigger.js +0 -255
  88. package/lib/parts/trigger.p.module.css.js +0 -31
  89. package/lib/parts/use-backward-compatible-id.d.ts +0 -4
  90. package/lib/parts/use-backward-compatible-id.js +0 -14
  91. package/lib/parts/use-observable-force-rerender.d.ts +0 -2
  92. package/lib/parts/use-observable-force-rerender.js +0 -16
  93. package/lib/utils.d.ts +0 -22
  94. package/lib/utils.js +0 -199
  95. /package/lib/{parts → utils}/throttle.js +0 -0
package/lib/utils.js DELETED
@@ -1,199 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import { ARROW_DOWN, ARROW_UP, SPACE, ENTER } from './key-codes.js';
3
- const DEFAULT_NO_OPTIONS_MESSAGES = {
4
- noOptions: 'No options',
5
- nothingFound: 'Nothing found',
6
- loading: 'Loading...'
7
- };
8
- const MAX_VISIBLE_ITEMS = 5;
9
- const ITEM_HEIGHT_BY_SIZE = {
10
- s: 32,
11
- m: 40,
12
- l: 52
13
- };
14
-
15
- const getTextFromNodes = function (node) {
16
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
17
-
18
- if (typeof node === 'string' || typeof node === 'number') {
19
- return node.toString();
20
- }
21
-
22
- if (depth > 15) {
23
- console.warn('Max depth reached while getting text from nodes');
24
- return '';
25
- }
26
-
27
- if (Array.isArray(node)) {
28
- return node.map(n => getTextFromNodes(n, depth + 1)).join('');
29
- }
30
-
31
- if ( /*#__PURE__*/React.isValidElement(node) && node?.type?.toString()?.toLowerCase() !== 'svg') {
32
- return getTextFromNodes(node.props.children, depth + 1);
33
- }
34
-
35
- return '';
36
- };
37
-
38
- const isOptionsGroup = optionOrGroup => typeof optionOrGroup.options !== 'undefined';
39
-
40
- function shouldOpenSelect(key) {
41
- let isTriggerTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
42
- return key === ARROW_DOWN || key === ARROW_UP || (key === SPACE || key === ENTER) && isTriggerTarget;
43
- }
44
-
45
- function isString(s) {
46
- return Object.prototype.toString.call(s) === '[object String]';
47
- }
48
-
49
- function getEmptyMessage(isLoading, isNothingFound, noOptionsMessage) {
50
- const {
51
- noOptions,
52
- nothingFound,
53
- loading
54
- } = isString(noOptionsMessage) ? { ...DEFAULT_NO_OPTIONS_MESSAGES,
55
- noOptions: noOptionsMessage
56
- } : { ...DEFAULT_NO_OPTIONS_MESSAGES,
57
- ...noOptionsMessage
58
- };
59
-
60
- if (isLoading) {
61
- return loading;
62
- } else if (isNothingFound) {
63
- return nothingFound;
64
- } else {
65
- return noOptions;
66
- }
67
- }
68
-
69
- function escapeRegex(str) {
70
- return str.replace(/[\-\[\]\/{}()\*+?.\\^$|]/g, '\\$&');
71
- }
72
-
73
- function convertToOptionGroupsIfNeeded() {
74
- let optionsOrGroups = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
75
- const newOptions = [];
76
- let topLevelOptions = [];
77
- optionsOrGroups.forEach(optionOrGroup => {
78
- if (isOptionsGroup(optionOrGroup)) {
79
- if (topLevelOptions.length) {
80
- newOptions.push({
81
- options: topLevelOptions
82
- });
83
- topLevelOptions = [];
84
- }
85
-
86
- newOptions.push(optionOrGroup);
87
- } else {
88
- topLevelOptions.push(optionOrGroup);
89
- }
90
- });
91
-
92
- if (topLevelOptions.length) {
93
- newOptions.push({
94
- options: topLevelOptions
95
- });
96
- topLevelOptions = [];
97
- }
98
-
99
- return newOptions;
100
- }
101
-
102
- const calculateMaxHeight = size => {
103
- const itemHeight = ITEM_HEIGHT_BY_SIZE[size]; // half of item added to show that there is more items even if scroll bar hidden
104
-
105
- return (Math.ceil(MAX_VISIBLE_ITEMS) + 0.5) * itemHeight;
106
- };
107
-
108
- function getOptionValue(option) {
109
- return typeof option.value === 'string' ? option.value : getTextFromNodes(option.label);
110
- }
111
-
112
- const OptionGroupTypes = {
113
- HEADER: 'header',
114
- OPTION: 'option',
115
- DIVIDER: 'divider'
116
- };
117
-
118
- const getDefaultCursorIndex = groups => {
119
- if (groups.length === 0) {
120
- return null;
121
- }
122
-
123
- const firstNonEmptyGroupIndex = groups.findIndex(group => group.options && group.options.length > 0);
124
-
125
- if (firstNonEmptyGroupIndex === -1) {
126
- return null;
127
- }
128
-
129
- return [firstNonEmptyGroupIndex, 0];
130
- };
131
-
132
- function optionsNotEmpty(options) {
133
- return options && options.length > 0;
134
- }
135
-
136
- const getPlainOptionsFromGroups = groups => groups.reduce( // eslint-disable-next-line no-shadow
137
- (acc, group, i) => acc.concat([optionsNotEmpty(group.options) && i !== 0 && !group.label && {
138
- type: OptionGroupTypes.DIVIDER
139
- }, optionsNotEmpty(group.options) && group.label && {
140
- type: OptionGroupTypes.HEADER,
141
- label: group.label
142
- }, ...group.options.map((option, j) => ({ ...option,
143
- index: [i, j],
144
- type: OptionGroupTypes.OPTION
145
- }))].filter(e => e)), []);
146
-
147
- function isGroupsEmpty(groups) {
148
- return groups.length === 0 || groups.every(g => !g.options || g.options.length === 0);
149
- }
150
-
151
- function useStrongMemo(callback, deps) {
152
- const prevDeps = useRef([]);
153
- const memoResult = useRef(null);
154
-
155
- if (deps.length !== prevDeps.current.length || !prevDeps.current.every((dep, i) => dep === deps[i])) {
156
- prevDeps.current = [...deps];
157
- memoResult.current = callback();
158
- }
159
-
160
- return memoResult.current;
161
- }
162
-
163
- function nextIndex(index, isDownDirection) {
164
- return isDownDirection ? index + 1 : index - 1;
165
- }
166
-
167
- function isIndexOutOfRange(index, len) {
168
- return index < 0 || index >= len;
169
- } // eslint-disable-next-line complexity
170
-
171
-
172
- function getMovedCursorIndex(groups, currentCursorIndex, isDownDirection) {
173
- if (isGroupsEmpty(groups)) return currentCursorIndex;
174
- const [grpIndex, optIndex] = currentCursorIndex;
175
- const optLenByGroup = groups.map(g => g.options ? g.options.length : 0);
176
- let newGrpIndex = grpIndex;
177
- let newOptIndex = nextIndex(optIndex, isDownDirection);
178
-
179
- while (isIndexOutOfRange(newOptIndex, optLenByGroup[newGrpIndex]) || isIndexOutOfRange(newGrpIndex, groups.length)) {
180
- newGrpIndex = nextIndex(newGrpIndex, isDownDirection);
181
-
182
- if (isIndexOutOfRange(newGrpIndex, groups.length)) {
183
- newGrpIndex = isDownDirection ? 0 : groups.length - 1;
184
- }
185
-
186
- newOptIndex = isDownDirection ? 0 : optLenByGroup[newGrpIndex] - 1;
187
- }
188
-
189
- return [newGrpIndex, newOptIndex];
190
- }
191
-
192
- const isIndexMatchCursor = (cursorIndex, index) => {
193
- if (cursorIndex === null) return false;
194
- return index[0] === cursorIndex[0] && index[1] === cursorIndex[1];
195
- };
196
-
197
- const withoutGroupsLabel = groups => groups.every(g => !g.label);
198
-
199
- export { OptionGroupTypes, calculateMaxHeight, convertToOptionGroupsIfNeeded, escapeRegex, getDefaultCursorIndex, getEmptyMessage, getMovedCursorIndex, getOptionValue, getPlainOptionsFromGroups, getTextFromNodes, isGroupsEmpty, isIndexMatchCursor, shouldOpenSelect, useStrongMemo, withoutGroupsLabel };
File without changes