@qualtrics/ui-react 2.85.2 → 2.85.5

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 (122) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/__node_modules/@radix-ui/primitive/dist/index.js +14 -3
  3. package/dist/__node_modules/@radix-ui/primitive/dist/internal/is-development.false.js +4 -0
  4. package/dist/__node_modules/@radix-ui/react-arrow/dist/index.js +9 -6
  5. package/dist/__node_modules/@radix-ui/react-collection/dist/index.js +263 -153
  6. package/dist/__node_modules/@radix-ui/react-compose-refs/dist/index.js +8 -1
  7. package/dist/__node_modules/@radix-ui/react-context/dist/index.js +35 -12
  8. package/dist/__node_modules/@radix-ui/react-direction/dist/index.js +16 -6
  9. package/dist/__node_modules/@radix-ui/react-dismissable-layer/dist/index.js +172 -43
  10. package/dist/__node_modules/@radix-ui/react-dropdown-menu/dist/index.js +76 -95
  11. package/dist/__node_modules/@radix-ui/react-focus-guards/dist/index.js +30 -6
  12. package/dist/__node_modules/@radix-ui/react-focus-scope/dist/index.js +111 -30
  13. package/dist/__node_modules/@radix-ui/react-id/dist/index.js +6 -0
  14. package/dist/__node_modules/@radix-ui/react-menu/dist/index.js +232 -197
  15. package/dist/__node_modules/@radix-ui/react-popper/dist/index.js +104 -49
  16. package/dist/__node_modules/@radix-ui/react-portal/dist/index.js +10 -8
  17. package/dist/__node_modules/@radix-ui/react-presence/dist/index.js +72 -14
  18. package/dist/__node_modules/@radix-ui/react-primitive/dist/index.js +8 -2
  19. package/dist/__node_modules/@radix-ui/react-roving-focus/dist/index.js +52 -18
  20. package/dist/__node_modules/@radix-ui/react-slot/dist/index.js +106 -54
  21. package/dist/__node_modules/@radix-ui/react-use-callback-ref/dist/index.js +17 -4
  22. package/dist/__node_modules/@radix-ui/react-use-controllable-state/dist/index.js +14 -4
  23. package/dist/__node_modules/@radix-ui/react-use-effect-event/dist/index.js +6 -1
  24. package/dist/__node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +37 -0
  25. package/dist/__node_modules/@radix-ui/react-use-layout-effect/dist/index.js +1 -1
  26. package/dist/__node_modules/@radix-ui/react-use-size/dist/index.js +28 -15
  27. package/dist/__shared/cjs/{index-e03dac36.js → index-bd03241f.js} +213 -208
  28. package/dist/__shared/cjs/{index-507024ee.js → index-ccb5282a.js} +12 -3
  29. package/dist/components/Accordion/Accordion2.js +3 -3
  30. package/dist/components/Button/Button.js +52 -6
  31. package/dist/components/Button/Button2.js +6 -52
  32. package/dist/components/Button/index.js +1 -1
  33. package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
  34. package/dist/components/Checkbox/Checkbox2.js +3 -3
  35. package/dist/components/ColorPicker/ColorPicker2.js +3 -3
  36. package/dist/components/ColorPicker/ColorPickerFlyout.js +1 -1
  37. package/dist/components/Combobox/Combobox2.js +3 -3
  38. package/dist/components/ConfigPane/ConfigPane.js +6 -2
  39. package/dist/components/ConfigPane/ConfigPane2.js +3 -3
  40. package/dist/components/Divider/Divider2.js +3 -3
  41. package/dist/components/Dropdown/ChildIndexContext/reach-descendants.js +1 -1
  42. package/dist/components/Dropdown/Dropdown2.js +3 -3
  43. package/dist/components/FilePicker/FilePicker.js +1 -1
  44. package/dist/components/FilePicker/FilePicker2.js +3 -3
  45. package/dist/components/FormField/Caption.js +3 -3
  46. package/dist/components/FormField/FormField2.js +3 -3
  47. package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
  48. package/dist/components/Icon/IconTypes.js +1 -0
  49. package/dist/components/IconButton/IconButton2.js +3 -3
  50. package/dist/components/InlineInput/InlineInput2.js +3 -3
  51. package/dist/components/Input/Input2.js +3 -3
  52. package/dist/components/InputGroup/InputGroup2.js +3 -3
  53. package/dist/components/Label/Label2.js +3 -3
  54. package/dist/components/Link/Link2.js +3 -3
  55. package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
  56. package/dist/components/LogicEditor/LogicEditor2.js +3 -3
  57. package/dist/components/Modal/Modal2.js +3 -3
  58. package/dist/components/NewMenu/NewMenu.js +3 -3
  59. package/dist/components/NumberStepper/NumberStepper2.js +3 -3
  60. package/dist/components/PageLayout/PageLayout.js +3 -3
  61. package/dist/components/Pagination/Pagination2.js +3 -3
  62. package/dist/components/Pagination/PaginationNextButton.js +1 -1
  63. package/dist/components/Pagination/PaginationPreviousButton.js +1 -1
  64. package/dist/components/Popover/Popover2.js +3 -3
  65. package/dist/components/QuickSearch/QuickSearch.js +1 -1
  66. package/dist/components/QuickSearch/QuickSearch2.js +3 -3
  67. package/dist/components/Radio/Radio2.js +3 -3
  68. package/dist/components/SearchInput/SearchInput2.js +3 -3
  69. package/dist/components/SidebarNav/SidebarNav2.js +3 -3
  70. package/dist/components/Slider/Slider2.js +3 -3
  71. package/dist/components/Switch/Switch2.js +3 -3
  72. package/dist/components/Table/Table2.js +3 -3
  73. package/dist/components/Tabs/Tabs2.js +3 -3
  74. package/dist/components/Tooltip/Tooltip2.js +3 -3
  75. package/dist/components/deprecated_ColorPicker/ColorPicker.js +1 -1
  76. package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
  77. package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
  78. package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
  79. package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
  80. package/dist/design-tokens/less/typography.js +3 -3
  81. package/dist/hooks/useOverlay/useOverlay2.js +3 -3
  82. package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
  83. package/dist/icons/Icon.js +3 -3
  84. package/dist/icons/components/PulseIcon.js +11 -0
  85. package/dist/icons/index.d.ts +2 -0
  86. package/dist/icons/index.es.js +1 -0
  87. package/dist/icons/index.js +2 -1
  88. package/dist/index.d.ts +72 -71
  89. package/dist/index.es.js +2 -2
  90. package/dist/index.js +3 -3
  91. package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
  92. package/dist/next/Chat/Loader.js +1 -1
  93. package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
  94. package/dist/next/Combobox/Combobox2.js +3 -3
  95. package/dist/next/Drawer/Drawer2.js +3 -3
  96. package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
  97. package/dist/next/Form/FormFields/InputField.js +3 -3
  98. package/dist/next/Indicator/Indicator2.js +3 -3
  99. package/dist/next/Input/Input2.js +3 -3
  100. package/dist/next/LoadingSpinner/LoadingSpinner2.js +3 -3
  101. package/dist/next/Menu/Hooks/useFlyoutNode.js +48 -0
  102. package/dist/next/Menu/Menu.js +2 -2
  103. package/dist/next/Menu/Menu2.js +3 -3
  104. package/dist/next/Menu/MenuButton.js +6 -5
  105. package/dist/next/Menu/MenuItem.js +5 -4
  106. package/dist/next/Menu/MenuPane.js +20 -19
  107. package/dist/next/Menu/PaneChildren.js +15 -10
  108. package/dist/next/Menu/SubMenu.js +22 -21
  109. package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
  110. package/dist/next/Select/Select2.js +3 -3
  111. package/dist/next/SplitButton/SplitButton.js +1 -1
  112. package/dist/next/SplitButton/SplitButton2.js +3 -3
  113. package/dist/next/TimePicker/TimePicker2.js +3 -3
  114. package/dist/next/ToggleButton/ToggleButton.js +1 -1
  115. package/dist/next/ToggleButton/styles.js +3 -3
  116. package/dist/next/index.js +1581 -850
  117. package/dist/translations-en.js +71 -71
  118. package/dist/utils/Flyout/Flyout2.js +3 -3
  119. package/icons/package.json +4 -4
  120. package/next/package.json +5 -5
  121. package/package.json +16 -16
  122. package/dist/__node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +0 -23
@@ -1,12 +1,13 @@
1
1
  import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
2
2
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
3
- import React__default from 'react';
3
+ import * as React from 'react';
4
4
  import { createContextScope } from '../../react-context/dist/index.js';
5
5
  import { useComposedRefs } from '../../react-compose-refs/dist/index.js';
6
6
  import { createSlot } from '../../react-slot/dist/index.js';
7
+ import { useLayoutEffect as useLayoutEffect2 } from '../../react-use-layout-effect/dist/index.js';
7
8
 
8
9
  "use client";
9
- var _keys;
10
+ var _OrderedDict2, _keys;
10
11
  const _excluded = ["scope", "children"],
11
12
  _excluded2 = ["state"],
12
13
  _excluded3 = ["scope", "children"];
@@ -15,6 +16,12 @@ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("C
15
16
  function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
16
17
  function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
17
18
  function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
19
+ var __defProp = Object.defineProperty;
20
+ var __name = (target, value) => __defProp(target, "name", {
21
+ value,
22
+ configurable: true
23
+ });
24
+ // @__NO_SIDE_EFFECTS__
18
25
  function createCollection(name) {
19
26
  const PROVIDER_NAME = name + "CollectionProvider";
20
27
  const _createContextScope = createContextScope(PROVIDER_NAME),
@@ -30,27 +37,27 @@ function createCollection(name) {
30
37
  _createCollectionCont2 = _slicedToArray(_createCollectionCont, 2),
31
38
  CollectionProviderImpl = _createCollectionCont2[0],
32
39
  useCollectionContext = _createCollectionCont2[1];
33
- const CollectionProvider = props => {
40
+ const CollectionProvider = /* @__PURE__ */__name(props => {
34
41
  const scope = props.scope,
35
42
  children = props.children;
36
- const ref = React__default.useRef(null);
37
- const itemMap = React__default.useRef(/* @__PURE__ */new Map()).current;
38
- return /* @__PURE__ */React__default.createElement(CollectionProviderImpl, {
43
+ const ref = React.useRef(null);
44
+ const itemMap = React.useRef(/* @__PURE__ */new Map()).current;
45
+ return /* @__PURE__ */React.createElement(CollectionProviderImpl, {
39
46
  scope,
40
47
  itemMap,
41
48
  collectionRef: ref,
42
49
  children
43
50
  });
44
- };
51
+ }, "CollectionProvider");
45
52
  CollectionProvider.displayName = PROVIDER_NAME;
46
53
  const COLLECTION_SLOT_NAME = name + "CollectionSlot";
47
54
  const CollectionSlotImpl = createSlot(COLLECTION_SLOT_NAME);
48
- const CollectionSlot = /*#__PURE__*/React__default.forwardRef((props, forwardedRef) => {
55
+ const CollectionSlot = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
49
56
  const scope = props.scope,
50
57
  children = props.children;
51
58
  const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
52
59
  const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
53
- return /* @__PURE__ */React__default.createElement(CollectionSlotImpl, {
60
+ return /* @__PURE__ */React.createElement(CollectionSlotImpl, {
54
61
  ref: composedRefs,
55
62
  children
56
63
  });
@@ -59,21 +66,21 @@ function createCollection(name) {
59
66
  const ITEM_SLOT_NAME = name + "CollectionItemSlot";
60
67
  const ITEM_DATA_ATTR = "data-radix-collection-item";
61
68
  const CollectionItemSlotImpl = createSlot(ITEM_SLOT_NAME);
62
- const CollectionItemSlot = /*#__PURE__*/React__default.forwardRef((props, forwardedRef) => {
69
+ const CollectionItemSlot = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
63
70
  const scope = props.scope,
64
71
  children = props.children,
65
72
  itemData = _objectWithoutProperties(props, _excluded);
66
- const ref = React__default.useRef(null);
73
+ const ref = React.useRef(null);
67
74
  const composedRefs = useComposedRefs(forwardedRef, ref);
68
75
  const context = useCollectionContext(ITEM_SLOT_NAME, scope);
69
- React__default.useEffect(() => {
76
+ React.useEffect(() => {
70
77
  context.itemMap.set(ref, {
71
78
  ref,
72
79
  ...itemData
73
80
  });
74
81
  return () => void context.itemMap.delete(ref);
75
82
  });
76
- return /* @__PURE__ */React__default.createElement(CollectionItemSlotImpl, {
83
+ return /* @__PURE__ */React.createElement(CollectionItemSlotImpl, {
77
84
  ...{
78
85
  [ITEM_DATA_ATTR]: ""
79
86
  },
@@ -84,7 +91,7 @@ function createCollection(name) {
84
91
  CollectionItemSlot.displayName = ITEM_SLOT_NAME;
85
92
  function useCollection(scope) {
86
93
  const context = useCollectionContext(name + "CollectionConsumer", scope);
87
- const getItems = React__default.useCallback(() => {
94
+ const getItems = React.useCallback(() => {
88
95
  const collectionNode = context.collectionRef.current;
89
96
  if (!collectionNode) return [];
90
97
  const orderedNodes = Array.from(collectionNode.querySelectorAll("[".concat(ITEM_DATA_ATTR, "]")));
@@ -94,16 +101,18 @@ function createCollection(name) {
94
101
  }, [context.collectionRef, context.itemMap]);
95
102
  return getItems;
96
103
  }
104
+ __name(useCollection, "useCollection");
97
105
  return [{
98
106
  Provider: CollectionProvider,
99
107
  Slot: CollectionSlot,
100
108
  ItemSlot: CollectionItemSlot
101
109
  }, useCollection, createCollectionScope];
102
110
  }
111
+ __name(createCollection, "createCollection");
103
112
 
104
113
  // src/ordered-dictionary.ts
105
114
  var __instanciated = /* @__PURE__ */new WeakMap();
106
- var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extends Map {
115
+ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), _OrderedDict2 = class _OrderedDict extends Map {
107
116
  constructor(entries) {
108
117
  super(entries);
109
118
  _classPrivateFieldInitSpec(this, _keys, void 0);
@@ -111,54 +120,37 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
111
120
  __instanciated.set(this, true);
112
121
  }
113
122
  set(key, value) {
114
- if (__instanciated.get(this)) {
115
- if (this.has(key)) {
116
- _classPrivateFieldGet(_keys, this)[_classPrivateFieldGet(_keys, this).indexOf(key)] = key;
117
- } else {
118
- _classPrivateFieldGet(_keys, this).push(key);
119
- }
123
+ if (__instanciated.get(this) && !this.has(key)) {
124
+ _classPrivateFieldGet(_keys, this).push(key);
120
125
  }
121
126
  super.set(key, value);
122
127
  return this;
123
128
  }
129
+ /**
130
+ * Sets a key-value pair so that it ends up at the given index.
131
+ * - Existing keys are moved
132
+ * - Negative indices count from the end of the resulting dictionary, so
133
+ * inserting at -1 makes the item the last one, -2 the second to last, etc.
134
+ * - Out-of-range indices are clamped
135
+ */
124
136
  insert(index, key, value) {
125
137
  const has = this.has(key);
126
- const length = _classPrivateFieldGet(_keys, this).length;
138
+ const finalSize = has ? this.size : this.size + 1;
127
139
  const relativeIndex = toSafeInteger(index);
128
- let actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
129
- const safeIndex = actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
130
- if (safeIndex === this.size || has && safeIndex === this.size - 1 || safeIndex === -1) {
140
+ const targetIndex = relativeIndex >= 0 ? Math.min(relativeIndex, finalSize - 1) : Math.max(finalSize + relativeIndex, 0);
141
+ if (has ? _classPrivateFieldGet(_keys, this).indexOf(key) === targetIndex : targetIndex === this.size) {
131
142
  this.set(key, value);
132
143
  return this;
133
144
  }
134
- const size = this.size + (has ? 0 : 1);
135
- if (relativeIndex < 0) {
136
- actualIndex++;
137
- }
138
- const keys = [..._classPrivateFieldGet(_keys, this)];
139
- let nextValue;
140
- let shouldSkip = false;
141
- for (let i = actualIndex; i < size; i++) {
142
- if (actualIndex === i) {
143
- let nextKey = keys[i];
144
- if (keys[i] === key) {
145
- nextKey = keys[i + 1];
146
- }
147
- if (has) {
148
- this.delete(key);
149
- }
150
- nextValue = this.get(nextKey);
151
- this.set(key, value);
152
- } else {
153
- if (!shouldSkip && keys[i - 1] === key) {
154
- shouldSkip = true;
155
- }
156
- const currentKey = keys[shouldSkip ? i : i - 1];
157
- const currentValue = nextValue;
158
- nextValue = this.get(currentKey);
159
- this.delete(currentKey);
160
- this.set(currentKey, currentValue);
161
- }
145
+ const keys = _classPrivateFieldGet(_keys, this).filter(existingKey => existingKey !== key);
146
+ keys.splice(targetIndex, 0, key);
147
+ const entries = keys.map(entryKey => [entryKey, entryKey === key ? value : this.get(entryKey)]);
148
+ this.clear();
149
+ for (const _ref of entries) {
150
+ var _ref2 = _slicedToArray(_ref, 2);
151
+ const entryKey = _ref2[0];
152
+ const entryValue = _ref2[1];
153
+ this.set(entryKey, entryValue);
162
154
  }
163
155
  return this;
164
156
  }
@@ -182,7 +174,9 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
182
174
  if (index === -1) {
183
175
  return this;
184
176
  }
185
- return this.insert(index, newKey, value);
177
+ const currentIndex = _classPrivateFieldGet(_keys, this).indexOf(newKey);
178
+ const targetIndex = currentIndex !== -1 && currentIndex < index ? index - 1 : index;
179
+ return this.insert(targetIndex, newKey, value);
186
180
  }
187
181
  after(key) {
188
182
  let index = _classPrivateFieldGet(_keys, this).indexOf(key);
@@ -200,7 +194,9 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
200
194
  if (index === -1) {
201
195
  return this;
202
196
  }
203
- return this.insert(index + 1, newKey, value);
197
+ const currentIndex = _classPrivateFieldGet(_keys, this).indexOf(newKey);
198
+ const targetIndex = currentIndex !== -1 && currentIndex <= index ? index : index + 1;
199
+ return this.insert(targetIndex, newKey, value);
204
200
  }
205
201
  first() {
206
202
  return this.entryAt(0);
@@ -310,10 +306,14 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
310
306
  }
311
307
  const callbackfn = args[0],
312
308
  initialValue = args[1];
309
+ const hasInitialValue = args.length > 1;
310
+ if (!hasInitialValue && this.size === 0) {
311
+ throw new TypeError("Reduce of empty OrderedDict with no initial value");
312
+ }
313
313
  let index = 0;
314
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : this.at(0);
314
+ let accumulator = initialValue;
315
315
  for (const entry of this) {
316
- if (index === 0 && args.length === 1) {
316
+ if (index === 0 && !hasInitialValue) {
317
317
  accumulator = entry;
318
318
  } else {
319
319
  accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
@@ -328,10 +328,14 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
328
328
  }
329
329
  const callbackfn = args[0],
330
330
  initialValue = args[1];
331
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : this.at(-1);
331
+ const hasInitialValue = args.length > 1;
332
+ if (!hasInitialValue && this.size === 0) {
333
+ throw new TypeError("Reduce of empty OrderedDict with no initial value");
334
+ }
335
+ let accumulator = initialValue;
332
336
  for (let index = this.size - 1; index >= 0; index--) {
333
- const entry = this.at(index);
334
- if (index === this.size - 1 && args.length === 1) {
337
+ const entry = this.entryAt(index);
338
+ if (index === this.size - 1 && !hasInitialValue) {
335
339
  accumulator = entry;
336
340
  } else {
337
341
  accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
@@ -339,7 +343,39 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
339
343
  }
340
344
  return accumulator;
341
345
  }
346
+ /**
347
+ * Sorts the dictionary in place. This method mutates the dictionary and
348
+ * returns a reference to the same object
349
+ *
350
+ * @param compareFn Function used to determine the order of the elements. It
351
+ * is expected to return a negative value if the first argument is less than
352
+ * the second argument, zero if they're equal, and a positive value otherwise.
353
+ */
354
+ sort(compareFn) {
355
+ if (typeof compareFn !== "function") {
356
+ throw new TypeError("OrderedDict.sort requires a compare function");
357
+ }
358
+ const entries = [...this.entries()].sort(compareFn);
359
+ this.clear();
360
+ for (const _ref3 of entries) {
361
+ var _ref4 = _slicedToArray(_ref3, 2);
362
+ const key = _ref4[0];
363
+ const value = _ref4[1];
364
+ this.set(key, value);
365
+ }
366
+ return this;
367
+ }
368
+ /**
369
+ * Returns a copy of the dictionary with its elements sorted.
370
+ *
371
+ * @param compareFn Function used to determine the order of the elements. It
372
+ * is expected to return a negative value if the first argument is less than
373
+ * the second argument, zero if they're equal, and a positive value otherwise.
374
+ */
342
375
  toSorted(compareFn) {
376
+ if (typeof compareFn !== "function") {
377
+ throw new TypeError("OrderedDict.toSorted requires a compare function");
378
+ }
343
379
  const entries = [...this.entries()].sort(compareFn);
344
380
  return new _OrderedDict(entries);
345
381
  }
@@ -359,20 +395,8 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
359
395
  }
360
396
  slice(start, end) {
361
397
  const result = new _OrderedDict();
362
- let stop = this.size - 1;
363
- if (start === void 0) {
364
- return result;
365
- }
366
- if (start < 0) {
367
- start = start + this.size;
368
- }
369
- if (end !== void 0 && end > 0) {
370
- stop = end - 1;
371
- }
372
- for (let index = start; index <= stop; index++) {
373
- const key = this.keyAt(index);
374
- const element = this.get(key);
375
- result.set(key, element);
398
+ for (const key of _classPrivateFieldGet(_keys, this).slice(start, end)) {
399
+ result.set(key, this.get(key));
376
400
  }
377
401
  return result;
378
402
  }
@@ -396,7 +420,7 @@ var OrderedDict = (_keys = /*#__PURE__*/new WeakMap(), class _OrderedDict extend
396
420
  }
397
421
  return false;
398
422
  }
399
- });
423
+ }, __name(_OrderedDict2, "OrderedDict"), _OrderedDict2);
400
424
  function at(array, index) {
401
425
  if ("at" in Array.prototype) {
402
426
  return Array.prototype.at.call(array, index);
@@ -404,73 +428,93 @@ function at(array, index) {
404
428
  const actualIndex = toSafeIndex(array, index);
405
429
  return actualIndex === -1 ? void 0 : array[actualIndex];
406
430
  }
431
+ __name(at, "at");
407
432
  function toSafeIndex(array, index) {
408
433
  const length = array.length;
409
434
  const relativeIndex = toSafeInteger(index);
410
435
  const actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
411
436
  return actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
412
437
  }
438
+ __name(toSafeIndex, "toSafeIndex");
413
439
  function toSafeInteger(number) {
414
440
  return number !== number || number === 0 ? 0 : Math.trunc(number);
415
441
  }
442
+ __name(toSafeInteger, "toSafeInteger");
416
443
 
417
444
  // src/collection.tsx
418
445
 
446
+ // @__NO_SIDE_EFFECTS__
419
447
  function createCollection2(name) {
420
448
  const PROVIDER_NAME = name + "CollectionProvider";
421
449
  const _createContextScope3 = createContextScope(PROVIDER_NAME),
422
450
  _createContextScope4 = _slicedToArray(_createContextScope3, 2),
423
451
  createCollectionContext = _createContextScope4[0],
424
452
  createCollectionScope = _createContextScope4[1];
425
- const _createCollectionCont3 = createCollectionContext(PROVIDER_NAME, {
426
- collectionElement: null,
427
- collectionRef: {
428
- current: null
429
- },
430
- collectionRefObject: {
431
- current: null
432
- },
433
- itemMap: new OrderedDict(),
434
- setItemMap: () => void 0
435
- }),
453
+ const _createCollectionCont3 = createCollectionContext(PROVIDER_NAME),
436
454
  _createCollectionCont4 = _slicedToArray(_createCollectionCont3, 2),
437
- CollectionContextProvider = _createCollectionCont4[0],
438
- useCollectionContext = _createCollectionCont4[1];
439
- const CollectionProvider = _ref => {
440
- let state = _ref.state,
441
- props = _objectWithoutProperties(_ref, _excluded2);
442
- return state ? /* @__PURE__ */React__default.createElement(CollectionProviderImpl, {
455
+ CollectionStableContextProvider = _createCollectionCont4[0],
456
+ useStableCollectionContext = _createCollectionCont4[1];
457
+ CollectionStableContextProvider.displayName = name + "CollectionStableContextProvider";
458
+ const _createCollectionCont5 = createCollectionContext(PROVIDER_NAME),
459
+ _createCollectionCont6 = _slicedToArray(_createCollectionCont5, 2),
460
+ CollectionStatefulContextProvider = _createCollectionCont6[0],
461
+ useStatefulCollectionContext = _createCollectionCont6[1];
462
+ CollectionStatefulContextProvider.displayName = name + "CollectionStatefulContextProvider";
463
+ const CollectionProvider = /* @__PURE__ */__name(_ref5 => {
464
+ let state = _ref5.state,
465
+ props = _objectWithoutProperties(_ref5, _excluded2);
466
+ return state ? /* @__PURE__ */React.createElement(CollectionProviderImpl, {
443
467
  ...props,
444
468
  state
445
- }) : /* @__PURE__ */React__default.createElement(CollectionInit, {
469
+ }) : /* @__PURE__ */React.createElement(CollectionInit, {
446
470
  ...props
447
471
  });
448
- };
472
+ }, "CollectionProvider");
449
473
  CollectionProvider.displayName = PROVIDER_NAME;
450
- const CollectionInit = props => {
474
+ const CollectionInit = /* @__PURE__ */__name(props => {
451
475
  const state = useInitCollection();
452
- return /* @__PURE__ */React__default.createElement(CollectionProviderImpl, {
476
+ return /* @__PURE__ */React.createElement(CollectionProviderImpl, {
453
477
  ...props,
454
478
  state
455
479
  });
456
- };
457
- CollectionInit.displayName = PROVIDER_NAME + "Init";
458
- const CollectionProviderImpl = props => {
480
+ }, "CollectionInit");
481
+ CollectionInit.displayName = name + "CollectionInit";
482
+ const CollectionProviderImpl = /* @__PURE__ */__name(props => {
459
483
  const scope = props.scope,
460
484
  children = props.children,
461
485
  state = props.state;
462
- const ref = React__default.useRef(null);
463
- const _React2$useState = React__default.useState(null),
486
+ const ref = React.useRef(null);
487
+ const _React2$useState = React.useState(null),
464
488
  _React2$useState2 = _slicedToArray(_React2$useState, 2),
465
489
  collectionElement = _React2$useState2[0],
466
490
  setCollectionElement = _React2$useState2[1];
467
491
  const composeRefs = useComposedRefs(ref, setCollectionElement);
468
492
  const _state = _slicedToArray(state, 2),
469
- itemMap = _state[0],
470
- setItemMap = _state[1];
471
- React__default.useEffect(() => {
472
- if (!collectionElement) return;
473
- const observer = getChildListObserver(() => {});
493
+ collection = _state[0],
494
+ setCollection = _state[1];
495
+ const registryRef = React.useRef(new OrderedDict());
496
+ const getCollection = React.useCallback(() => {
497
+ const registry = registryRef.current;
498
+ if (!isInDocumentOrder(registry)) {
499
+ registry.sort(sortByDocumentPosition);
500
+ }
501
+ return registry;
502
+ }, []);
503
+ React.useEffect(() => {
504
+ if (!collectionElement) {
505
+ return;
506
+ }
507
+ const observer = getChildListObserver(() => {
508
+ setCollection(map => {
509
+ const sorted = map.toSorted(sortByDocumentPosition);
510
+ const orderChanged = sorted.some((_ref6, index) => {
511
+ let _ref7 = _slicedToArray(_ref6, 1),
512
+ key = _ref7[0];
513
+ return map.keyAt(index) !== key;
514
+ });
515
+ return orderChanged ? sorted : map;
516
+ });
517
+ });
474
518
  observer.observe(collectionElement, {
475
519
  childList: true,
476
520
  subtree: true
@@ -478,26 +522,31 @@ function createCollection2(name) {
478
522
  return () => {
479
523
  observer.disconnect();
480
524
  };
481
- }, [collectionElement]);
482
- return /* @__PURE__ */React__default.createElement(CollectionContextProvider, {
525
+ }, [collectionElement, setCollection]);
526
+ return /* @__PURE__ */React.createElement(CollectionStableContextProvider, {
483
527
  scope,
484
- itemMap,
485
- setItemMap,
486
- collectionRef: composeRefs,
487
- collectionRefObject: ref,
488
- collectionElement,
489
- children
528
+ collectionElementRef: composeRefs,
529
+ collectionElementRefObject: ref,
530
+ getCollection,
531
+ setCollection,
532
+ registryRef,
533
+ children: /* @__PURE__ */React.createElement(CollectionStatefulContextProvider, {
534
+ scope,
535
+ collectionElement,
536
+ collection,
537
+ children
538
+ })
490
539
  });
491
- };
492
- CollectionProviderImpl.displayName = PROVIDER_NAME + "Impl";
540
+ }, "CollectionProviderImpl");
541
+ CollectionProviderImpl.displayName = name + "CollectionProviderImpl";
493
542
  const COLLECTION_SLOT_NAME = name + "CollectionSlot";
494
543
  const CollectionSlotImpl = createSlot(COLLECTION_SLOT_NAME);
495
- const CollectionSlot = /*#__PURE__*/React__default.forwardRef((props, forwardedRef) => {
544
+ const CollectionSlot = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
496
545
  const scope = props.scope,
497
546
  children = props.children;
498
- const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
499
- const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
500
- return /* @__PURE__ */React__default.createElement(CollectionSlotImpl, {
547
+ const context = useStableCollectionContext(COLLECTION_SLOT_NAME, scope);
548
+ const composedRefs = useComposedRefs(forwardedRef, context.collectionElementRef);
549
+ return /* @__PURE__ */React.createElement(CollectionSlotImpl, {
501
550
  ref: composedRefs,
502
551
  children
503
552
  });
@@ -506,52 +555,85 @@ function createCollection2(name) {
506
555
  const ITEM_SLOT_NAME = name + "CollectionItemSlot";
507
556
  const ITEM_DATA_ATTR = "data-radix-collection-item";
508
557
  const CollectionItemSlotImpl = createSlot(ITEM_SLOT_NAME);
509
- const CollectionItemSlot = /*#__PURE__*/React__default.forwardRef((props, forwardedRef) => {
558
+ const CollectionItemSlot = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
510
559
  const scope = props.scope,
511
560
  children = props.children,
512
561
  itemData = _objectWithoutProperties(props, _excluded3);
513
- const ref = React__default.useRef(null);
514
- const _React2$useState3 = React__default.useState(null),
515
- _React2$useState4 = _slicedToArray(_React2$useState3, 2),
516
- element = _React2$useState4[0],
517
- setElement = _React2$useState4[1];
518
- const composedRefs = useComposedRefs(forwardedRef, ref, setElement);
519
- const context = useCollectionContext(ITEM_SLOT_NAME, scope);
520
- const setItemMap = context.setItemMap;
521
- const itemDataRef = React__default.useRef(itemData);
562
+ const ref = React.useRef(null);
563
+ const context = useStableCollectionContext(ITEM_SLOT_NAME, scope);
564
+ const setCollection = context.setCollection,
565
+ registryRef = context.registryRef;
566
+ const itemDataRef = React.useRef(itemData);
522
567
  if (!shallowEqual(itemDataRef.current, itemData)) {
523
568
  itemDataRef.current = itemData;
524
569
  }
525
570
  const memoizedItemData = itemDataRef.current;
526
- React__default.useEffect(() => {
527
- const itemData2 = memoizedItemData;
528
- setItemMap(map => {
529
- if (!element) {
530
- return map;
571
+ const registerElement = React.useCallback(node => {
572
+ const registry = registryRef.current;
573
+ if (node) {
574
+ registry.set(node, {
575
+ ...itemDataRef.current,
576
+ element: node
577
+ });
578
+ } else if (ref.current) {
579
+ registry.delete(ref.current);
580
+ }
581
+ }, [registryRef]);
582
+ const composedRefs = useComposedRefs(forwardedRef, registerElement, ref);
583
+ useLayoutEffect2(() => {
584
+ const node = ref.current;
585
+ const registry = registryRef.current;
586
+ if (node && registry.has(node)) {
587
+ registry.set(node, {
588
+ ...memoizedItemData,
589
+ element: node
590
+ });
591
+ }
592
+ }, [memoizedItemData, registryRef]);
593
+ const registeredRef = React.useRef(null);
594
+ React.useEffect(() => {
595
+ var _registered$element;
596
+ const element = ref.current;
597
+ const registered = registeredRef.current;
598
+ if (((_registered$element = registered === null || registered === void 0 ? void 0 : registered.element) !== null && _registered$element !== void 0 ? _registered$element : null) === element && (!element || (registered === null || registered === void 0 ? void 0 : registered.itemData) === memoizedItemData)) {
599
+ return;
600
+ }
601
+ registeredRef.current = element ? {
602
+ element,
603
+ itemData: memoizedItemData
604
+ } : null;
605
+ setCollection(map => {
606
+ const next = new OrderedDict(map);
607
+ if (registered && registered.element !== element) {
608
+ next.delete(registered.element);
531
609
  }
532
- if (!map.has(element)) {
533
- map.set(element, {
534
- ...itemData2,
610
+ if (element) {
611
+ next.set(element, {
612
+ ...memoizedItemData,
535
613
  element
536
614
  });
537
- return map.toSorted(sortByDocumentPosition);
538
615
  }
539
- return map.set(element, {
540
- ...itemData2,
541
- element
542
- }).toSorted(sortByDocumentPosition);
616
+ return next.sort(sortByDocumentPosition);
543
617
  });
618
+ });
619
+ React.useEffect(() => {
544
620
  return () => {
545
- setItemMap(map => {
546
- if (!element || !map.has(element)) {
621
+ const registered = registeredRef.current;
622
+ registeredRef.current = null;
623
+ if (!registered) {
624
+ return;
625
+ }
626
+ setCollection(map => {
627
+ if (!map.has(registered.element)) {
547
628
  return map;
548
629
  }
549
- map.delete(element);
550
- return new OrderedDict(map);
630
+ const next = new OrderedDict(map);
631
+ next.delete(registered.element);
632
+ return next;
551
633
  });
552
634
  };
553
- }, [element, memoizedItemData, setItemMap]);
554
- return /* @__PURE__ */React__default.createElement(CollectionItemSlotImpl, {
635
+ }, [setCollection]);
636
+ return /* @__PURE__ */React.createElement(CollectionItemSlotImpl, {
555
637
  ...{
556
638
  [ITEM_DATA_ATTR]: ""
557
639
  },
@@ -561,16 +643,25 @@ function createCollection2(name) {
561
643
  });
562
644
  CollectionItemSlot.displayName = ITEM_SLOT_NAME;
563
645
  function useInitCollection() {
564
- return React__default.useState(new OrderedDict());
646
+ return React.useState(new OrderedDict());
565
647
  }
648
+ __name(useInitCollection, "useInitCollection");
566
649
  function useCollection(scope) {
567
- const _useCollectionContext = useCollectionContext(name + "CollectionConsumer", scope),
568
- itemMap = _useCollectionContext.itemMap;
569
- return itemMap;
650
+ const _useStatefulCollectio = useStatefulCollectionContext(name + "CollectionConsumer", scope),
651
+ collection = _useStatefulCollectio.collection;
652
+ return collection;
653
+ }
654
+ __name(useCollection, "useCollection");
655
+ function useGetCollection(scope) {
656
+ const _useStableCollectionC = useStableCollectionContext(name + "CollectionConsumer", scope),
657
+ getCollection = _useStableCollectionC.getCollection;
658
+ return getCollection;
570
659
  }
660
+ __name(useGetCollection, "useGetCollection");
571
661
  const functions = {
572
662
  createCollectionScope,
573
663
  useCollection,
664
+ useGetCollection,
574
665
  useInitCollection
575
666
  };
576
667
  return [{
@@ -579,6 +670,7 @@ function createCollection2(name) {
579
670
  ItemSlot: CollectionItemSlot
580
671
  }, functions];
581
672
  }
673
+ __name(createCollection2, "createCollection");
582
674
  function shallowEqual(a, b) {
583
675
  if (a === b) return true;
584
676
  if (typeof a !== "object" || typeof b !== "object") return false;
@@ -592,12 +684,29 @@ function shallowEqual(a, b) {
592
684
  }
593
685
  return true;
594
686
  }
687
+ __name(shallowEqual, "shallowEqual");
595
688
  function isElementPreceding(a, b) {
596
689
  return !!(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);
597
690
  }
691
+ __name(isElementPreceding, "isElementPreceding");
692
+ function isInDocumentOrder(dict) {
693
+ let previous;
694
+ for (const element of dict.keys()) {
695
+ if (previous) {
696
+ const position = previous.compareDocumentPosition(element);
697
+ if (!(position & Node.DOCUMENT_POSITION_DISCONNECTED) && position & Node.DOCUMENT_POSITION_PRECEDING) {
698
+ return false;
699
+ }
700
+ }
701
+ previous = element;
702
+ }
703
+ return true;
704
+ }
705
+ __name(isInDocumentOrder, "isInDocumentOrder");
598
706
  function sortByDocumentPosition(a, b) {
599
707
  return !a[1].element || !b[1].element ? 0 : isElementPreceding(a[1].element, b[1].element) ? -1 : 1;
600
708
  }
709
+ __name(sortByDocumentPosition, "sortByDocumentPosition");
601
710
  function getChildListObserver(callback) {
602
711
  const observer = new MutationObserver(mutationsList => {
603
712
  for (const mutation of mutationsList) {
@@ -609,5 +718,6 @@ function getChildListObserver(callback) {
609
718
  });
610
719
  return observer;
611
720
  }
721
+ __name(getChildListObserver, "getChildListObserver");
612
722
 
613
723
  export { createCollection, createCollection2 as unstable_createCollection };