@rescui/chip-list 0.14.5-RUI-308-Fix-select-issues-405b9fa40.12 → 0.15.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.
@@ -1,4 +1,5 @@
1
- import React, { useRef, useCallback, useMemo, cloneElement } from 'react';
1
+ import { c } from 'react-compiler-runtime';
2
+ import React, { useRef, cloneElement } from 'react';
2
3
  import { deepMap } from './deep-map.js';
3
4
  import Chip from './chip.js';
4
5
 
@@ -32,90 +33,129 @@ const hasElHref = el => typeof el.props?.href !== 'undefined';
32
33
 
33
34
  const hasElAriaControls = el => typeof el.props?.['aria-controls'] !== 'undefined';
34
35
 
35
- const useItemsIds = _ref2 => {
36
- let {
37
- children,
38
- compareValues,
39
- value
40
- } = _ref2;
41
- const tabRefs = useRef(new Map());
42
- const createChipRef = useCallback((itemId, childRef) => node => {
43
- if (node) {
44
- tabRefs.current.set(itemId, node);
36
+ function getChildrenWithValues(children, compareValues, value, createChipRef) {
37
+ let counter = 0;
38
+ const currentSelectedItemIds = [];
39
+ let currentHasHref = false;
40
+ let currentHasControls = false;
41
+ let currentAllItemsHaveControls = true;
42
+ const items = deepMap(children, child => {
43
+ if (child.type === Chip) {
44
+ if (hasElHref(child)) {
45
+ currentHasHref = true;
46
+ }
47
+
48
+ if (hasElAriaControls(child)) {
49
+ currentHasControls = true;
50
+ } else {
51
+ currentAllItemsHaveControls = false;
52
+ }
53
+
54
+ const childValue = hasElValue(child) ? child.props.value : counter;
55
+ const isSelectedItem = compareValues(value, childValue);
56
+
57
+ if (isSelectedItem) {
58
+ currentSelectedItemIds.push(counter);
59
+ }
60
+
61
+ const patchedItem = patchItemIfNeeded({
62
+ child,
63
+ itemId: counter,
64
+ childValue,
65
+ ref: createChipRef(counter, getElementRef(child))
66
+ });
67
+ counter += 1;
68
+ return patchedItem;
45
69
  } else {
46
- tabRefs.current.delete(itemId);
70
+ return child;
47
71
  }
72
+ });
73
+ return {
74
+ childrenWithValues: React.Children.toArray(items),
75
+ selectedIds: currentSelectedItemIds,
76
+ hasHref: currentHasHref,
77
+ hasControls: currentHasControls,
78
+ allItemsHaveControls: counter > 0 && currentAllItemsHaveControls
79
+ };
80
+ }
48
81
 
49
- setRef(childRef, node);
50
- }, []);
82
+ const useItemsIds = t0 => {
83
+ const $ = c(12);
51
84
  const {
52
- childrenWithValues,
53
- selectedIds,
54
- hasHref,
55
- hasControls,
56
- allItemsHaveControls
57
- } = useMemo(() => {
58
- let counter = 0;
59
- const currentSelectedItemIds = [];
60
- let currentHasHref = false;
61
- let currentHasControls = false;
62
- let currentAllItemsHaveControls = true;
63
- /*
64
- * deepMap invokes its callback synchronously. The callback ref is created
65
- * during render, but accesses tabRefs.current only when React invokes it
66
- * during commit.
67
- */
68
- // eslint-disable-next-line react-hooks/refs
69
-
70
- const items = deepMap(children, child => {
71
- if (child.type === Chip) {
72
- if (hasElHref(child)) {
73
- // same explanation as above
74
- // eslint-disable-next-line react-hooks/immutability
75
- currentHasHref = true;
76
- }
77
-
78
- if (hasElAriaControls(child)) {
79
- currentHasControls = true;
80
- } else {
81
- currentAllItemsHaveControls = false;
82
- }
83
-
84
- const childValue = hasElValue(child) ? child.props.value : counter;
85
- const isSelectedItem = compareValues(value, childValue);
86
-
87
- if (isSelectedItem) {
88
- currentSelectedItemIds.push(counter);
89
- }
90
-
91
- const patchedItem = patchItemIfNeeded({
92
- child,
93
- itemId: counter,
94
- childValue,
95
- ref: createChipRef(counter, getElementRef(child))
96
- });
97
- counter += 1;
98
- return patchedItem;
85
+ children,
86
+ compareValues,
87
+ value
88
+ } = t0;
89
+ let t1;
90
+
91
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
92
+ t1 = new Map();
93
+ $[0] = t1;
94
+ } else {
95
+ t1 = $[0];
96
+ }
97
+
98
+ const tabRefs = useRef(t1);
99
+ let t2;
100
+
101
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
102
+ t2 = (itemId, childRef) => node => {
103
+ if (node) {
104
+ tabRefs.current.set(itemId, node);
99
105
  } else {
100
- return child;
106
+ tabRefs.current.delete(itemId);
101
107
  }
102
- });
103
- return {
104
- childrenWithValues: React.Children.toArray(items),
105
- selectedIds: currentSelectedItemIds,
106
- hasHref: currentHasHref,
107
- hasControls: currentHasControls,
108
- allItemsHaveControls: counter > 0 && currentAllItemsHaveControls
108
+
109
+ setRef(childRef, node);
109
110
  };
110
- }, [children, value, compareValues, createChipRef]);
111
- return {
111
+
112
+ $[1] = t2;
113
+ } else {
114
+ t2 = $[1];
115
+ }
116
+
117
+ const createChipRef = t2;
118
+ let t3;
119
+
120
+ if ($[2] !== children || $[3] !== compareValues || $[4] !== value) {
121
+ t3 = getChildrenWithValues(children, compareValues, value, createChipRef);
122
+ $[2] = children;
123
+ $[3] = compareValues;
124
+ $[4] = value;
125
+ $[5] = t3;
126
+ } else {
127
+ t3 = $[5];
128
+ }
129
+
130
+ const {
112
131
  childrenWithValues,
113
132
  selectedIds,
114
133
  hasHref,
115
134
  hasControls,
116
- allItemsHaveControls,
117
- tabRefs
118
- };
135
+ allItemsHaveControls
136
+ } = t3;
137
+ let t4;
138
+
139
+ if ($[6] !== allItemsHaveControls || $[7] !== childrenWithValues || $[8] !== hasControls || $[9] !== hasHref || $[10] !== selectedIds) {
140
+ t4 = {
141
+ childrenWithValues,
142
+ selectedIds,
143
+ hasHref,
144
+ hasControls,
145
+ allItemsHaveControls,
146
+ tabRefs
147
+ };
148
+ $[6] = allItemsHaveControls;
149
+ $[7] = childrenWithValues;
150
+ $[8] = hasControls;
151
+ $[9] = hasHref;
152
+ $[10] = selectedIds;
153
+ $[11] = t4;
154
+ } else {
155
+ t4 = $[11];
156
+ }
157
+
158
+ return t4;
119
159
  };
120
160
 
121
161
  export { useItemsIds };
@@ -1,5 +1,6 @@
1
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
- import React from 'react'; // eslint-disable-next-line complexity
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
 
4
5
  const getNextItemId = _ref => {
5
6
  let {
@@ -31,49 +32,73 @@ const getNextItemId = _ref => {
31
32
  return currentItemId;
32
33
  };
33
34
 
34
- const useRovingTabIndex = _ref2 => {
35
- let {
35
+ const useRovingTabIndex = t0 => {
36
+ const $ = c(6);
37
+ const {
36
38
  enabled,
37
39
  selectedId,
38
40
  tabRefs
39
- } = _ref2;
40
- const [currentTabStopId, setCurrentTabStopId] = React.useState(selectedId ?? 0);
41
- const [previousSelectedId, setPreviousSelectedId] = React.useState(selectedId);
41
+ } = t0;
42
+ const [currentTabStopId, setCurrentTabStopId] = useState(selectedId ?? 0);
43
+ const [previousSelectedId, setPreviousSelectedId] = useState(selectedId);
42
44
 
43
45
  if (!Object.is(selectedId, previousSelectedId)) {
44
46
  setPreviousSelectedId(selectedId);
45
47
 
46
- if (typeof selectedId !== 'undefined') {
48
+ if (typeof selectedId !== "undefined") {
47
49
  setCurrentTabStopId(selectedId);
48
50
  }
49
51
  }
50
52
 
51
53
  const currentTabsRefs = tabRefs?.current;
52
- const onTabKeyDown = React.useCallback((e, itemId) => {
53
- var _context;
54
+ let t1;
54
55
 
55
- if (!enabled) {
56
- return;
57
- }
56
+ if ($[0] !== currentTabsRefs || $[1] !== enabled) {
57
+ t1 = (e, itemId) => {
58
+ var _context;
58
59
 
59
- if (!_includesInstanceProperty(_context = ['ArrowLeft', 'ArrowRight', 'Home', 'End']).call(_context, e.key)) {
60
- return;
61
- }
60
+ if (!enabled) {
61
+ return;
62
+ }
63
+
64
+ if (!_includesInstanceProperty(_context = ["ArrowLeft", "ArrowRight", "Home", "End"]).call(_context, e.key)) {
65
+ return;
66
+ }
67
+
68
+ const itemsCount = currentTabsRefs.size ?? 0;
69
+ const nextItemId = getNextItemId({
70
+ currentItemId: itemId,
71
+ itemsCount,
72
+ key: e.key
73
+ });
74
+ e.preventDefault();
75
+ setCurrentTabStopId(nextItemId);
76
+ currentTabsRefs.get(nextItemId)?.focus();
77
+ };
78
+
79
+ $[0] = currentTabsRefs;
80
+ $[1] = enabled;
81
+ $[2] = t1;
82
+ } else {
83
+ t1 = $[2];
84
+ }
85
+
86
+ const onTabKeyDown = t1;
87
+ let t2;
88
+
89
+ if ($[3] !== currentTabStopId || $[4] !== onTabKeyDown) {
90
+ t2 = {
91
+ currentTabStopId,
92
+ onTabKeyDown
93
+ };
94
+ $[3] = currentTabStopId;
95
+ $[4] = onTabKeyDown;
96
+ $[5] = t2;
97
+ } else {
98
+ t2 = $[5];
99
+ }
62
100
 
63
- const itemsCount = currentTabsRefs.size ?? 0;
64
- const nextItemId = getNextItemId({
65
- currentItemId: itemId,
66
- itemsCount,
67
- key: e.key
68
- });
69
- e.preventDefault();
70
- setCurrentTabStopId(nextItemId);
71
- currentTabsRefs.get(nextItemId)?.focus();
72
- }, [enabled, currentTabsRefs]);
73
- return {
74
- currentTabStopId,
75
- onTabKeyDown
76
- };
101
+ return t2;
77
102
  };
78
103
 
79
104
  export { useRovingTabIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescui/chip-list",
3
- "version": "0.14.5-RUI-308-Fix-select-issues-405b9fa40.12+405b9fa40",
3
+ "version": "0.15.1",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -17,23 +17,24 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime-corejs3": "^7.26.0",
20
- "classnames": "^2.2.6"
20
+ "classnames": "^2.2.6",
21
+ "react-compiler-runtime": "^1.0.0"
21
22
  },
22
23
  "peerDependencies": {
23
- "@rescui/ui-contexts": "^0.6.0",
24
+ "@rescui/ui-contexts": "^0.7.0",
24
25
  "prop-types": "^15",
25
- "react": ">=16.8.0 <20"
26
+ "react": ">=17.0.0 <20"
26
27
  },
27
28
  "devDependencies": {
28
- "@rescui/colors": "0.3.4-RUI-308-Fix-select-issues-405b9fa40.12+405b9fa40",
29
- "@rescui/scripts": "0.5.2",
30
- "@rescui/typography": "0.27.5-RUI-308-Fix-select-issues-405b9fa40.12+405b9fa40",
31
- "@rescui/visual-regression": "0.1.4"
29
+ "@rescui/colors": "^0.3.4",
30
+ "@rescui/scripts": "^0.5.3",
31
+ "@rescui/typography": "^0.28.1",
32
+ "@rescui/visual-regression": "^0.1.4"
32
33
  },
33
34
  "scripts": {
34
35
  "build": "rescui-scripts build && yarn run build-pcss-api",
35
36
  "build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
36
37
  },
37
38
  "nx": {},
38
- "gitHead": "405b9fa40886b0ab6709c9185e8214599d2d792e"
39
+ "gitHead": "ce4c6c5e3fd5aede0006f6ef8e655fc0ab394c0f"
39
40
  }