@jobber/components 6.85.2 → 6.86.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.
@@ -209,6 +209,13 @@ function isTypeableCombobox(element) {
209
209
  return element.getAttribute('role') === 'combobox' && isTypeableElement(element);
210
210
  }
211
211
 
212
+ /**
213
+ * Custom positioning reference element.
214
+ * @see https://floating-ui.com/docs/virtual-elements
215
+ */
216
+
217
+ const floor$1 = Math.floor;
218
+
212
219
  var jsxRuntime = {exports: {}};
213
220
 
214
221
  var reactJsxRuntime_production_min = {};
@@ -4134,6 +4141,247 @@ function useEffectEvent(callback) {
4134
4141
  }, []);
4135
4142
  }
4136
4143
 
4144
+ const ARROW_UP = 'ArrowUp';
4145
+ const ARROW_DOWN = 'ArrowDown';
4146
+ const ARROW_LEFT = 'ArrowLeft';
4147
+ const ARROW_RIGHT = 'ArrowRight';
4148
+ function isDifferentRow(index, cols, prevRow) {
4149
+ return Math.floor(index / cols) !== prevRow;
4150
+ }
4151
+ function isIndexOutOfBounds(listRef, index) {
4152
+ return index < 0 || index >= listRef.current.length;
4153
+ }
4154
+ function getMinIndex(listRef, disabledIndices) {
4155
+ return findNonDisabledIndex(listRef, {
4156
+ disabledIndices
4157
+ });
4158
+ }
4159
+ function getMaxIndex(listRef, disabledIndices) {
4160
+ return findNonDisabledIndex(listRef, {
4161
+ decrement: true,
4162
+ startingIndex: listRef.current.length,
4163
+ disabledIndices
4164
+ });
4165
+ }
4166
+ function findNonDisabledIndex(listRef, _temp) {
4167
+ let {
4168
+ startingIndex = -1,
4169
+ decrement = false,
4170
+ disabledIndices,
4171
+ amount = 1
4172
+ } = _temp === void 0 ? {} : _temp;
4173
+ const list = listRef.current;
4174
+ let index = startingIndex;
4175
+ do {
4176
+ index += decrement ? -amount : amount;
4177
+ } while (index >= 0 && index <= list.length - 1 && isDisabled(list, index, disabledIndices));
4178
+ return index;
4179
+ }
4180
+ function getGridNavigatedIndex(elementsRef, _ref) {
4181
+ let {
4182
+ event,
4183
+ orientation,
4184
+ loop,
4185
+ rtl,
4186
+ cols,
4187
+ disabledIndices,
4188
+ minIndex,
4189
+ maxIndex,
4190
+ prevIndex,
4191
+ stopEvent: stop = false
4192
+ } = _ref;
4193
+ let nextIndex = prevIndex;
4194
+ if (event.key === ARROW_UP) {
4195
+ stop && stopEvent(event);
4196
+ if (prevIndex === -1) {
4197
+ nextIndex = maxIndex;
4198
+ } else {
4199
+ nextIndex = findNonDisabledIndex(elementsRef, {
4200
+ startingIndex: nextIndex,
4201
+ amount: cols,
4202
+ decrement: true,
4203
+ disabledIndices
4204
+ });
4205
+ if (loop && (prevIndex - cols < minIndex || nextIndex < 0)) {
4206
+ const col = prevIndex % cols;
4207
+ const maxCol = maxIndex % cols;
4208
+ const offset = maxIndex - (maxCol - col);
4209
+ if (maxCol === col) {
4210
+ nextIndex = maxIndex;
4211
+ } else {
4212
+ nextIndex = maxCol > col ? offset : offset - cols;
4213
+ }
4214
+ }
4215
+ }
4216
+ if (isIndexOutOfBounds(elementsRef, nextIndex)) {
4217
+ nextIndex = prevIndex;
4218
+ }
4219
+ }
4220
+ if (event.key === ARROW_DOWN) {
4221
+ stop && stopEvent(event);
4222
+ if (prevIndex === -1) {
4223
+ nextIndex = minIndex;
4224
+ } else {
4225
+ nextIndex = findNonDisabledIndex(elementsRef, {
4226
+ startingIndex: prevIndex,
4227
+ amount: cols,
4228
+ disabledIndices
4229
+ });
4230
+ if (loop && prevIndex + cols > maxIndex) {
4231
+ nextIndex = findNonDisabledIndex(elementsRef, {
4232
+ startingIndex: prevIndex % cols - cols,
4233
+ amount: cols,
4234
+ disabledIndices
4235
+ });
4236
+ }
4237
+ }
4238
+ if (isIndexOutOfBounds(elementsRef, nextIndex)) {
4239
+ nextIndex = prevIndex;
4240
+ }
4241
+ }
4242
+
4243
+ // Remains on the same row/column.
4244
+ if (orientation === 'both') {
4245
+ const prevRow = floor$1(prevIndex / cols);
4246
+ if (event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT)) {
4247
+ stop && stopEvent(event);
4248
+ if (prevIndex % cols !== cols - 1) {
4249
+ nextIndex = findNonDisabledIndex(elementsRef, {
4250
+ startingIndex: prevIndex,
4251
+ disabledIndices
4252
+ });
4253
+ if (loop && isDifferentRow(nextIndex, cols, prevRow)) {
4254
+ nextIndex = findNonDisabledIndex(elementsRef, {
4255
+ startingIndex: prevIndex - prevIndex % cols - 1,
4256
+ disabledIndices
4257
+ });
4258
+ }
4259
+ } else if (loop) {
4260
+ nextIndex = findNonDisabledIndex(elementsRef, {
4261
+ startingIndex: prevIndex - prevIndex % cols - 1,
4262
+ disabledIndices
4263
+ });
4264
+ }
4265
+ if (isDifferentRow(nextIndex, cols, prevRow)) {
4266
+ nextIndex = prevIndex;
4267
+ }
4268
+ }
4269
+ if (event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT)) {
4270
+ stop && stopEvent(event);
4271
+ if (prevIndex % cols !== 0) {
4272
+ nextIndex = findNonDisabledIndex(elementsRef, {
4273
+ startingIndex: prevIndex,
4274
+ decrement: true,
4275
+ disabledIndices
4276
+ });
4277
+ if (loop && isDifferentRow(nextIndex, cols, prevRow)) {
4278
+ nextIndex = findNonDisabledIndex(elementsRef, {
4279
+ startingIndex: prevIndex + (cols - prevIndex % cols),
4280
+ decrement: true,
4281
+ disabledIndices
4282
+ });
4283
+ }
4284
+ } else if (loop) {
4285
+ nextIndex = findNonDisabledIndex(elementsRef, {
4286
+ startingIndex: prevIndex + (cols - prevIndex % cols),
4287
+ decrement: true,
4288
+ disabledIndices
4289
+ });
4290
+ }
4291
+ if (isDifferentRow(nextIndex, cols, prevRow)) {
4292
+ nextIndex = prevIndex;
4293
+ }
4294
+ }
4295
+ const lastRow = floor$1(maxIndex / cols) === prevRow;
4296
+ if (isIndexOutOfBounds(elementsRef, nextIndex)) {
4297
+ if (loop && lastRow) {
4298
+ nextIndex = event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT) ? maxIndex : findNonDisabledIndex(elementsRef, {
4299
+ startingIndex: prevIndex - prevIndex % cols - 1,
4300
+ disabledIndices
4301
+ });
4302
+ } else {
4303
+ nextIndex = prevIndex;
4304
+ }
4305
+ }
4306
+ }
4307
+ return nextIndex;
4308
+ }
4309
+
4310
+ /** For each cell index, gets the item index that occupies that cell */
4311
+ function buildCellMap(sizes, cols, dense) {
4312
+ const cellMap = [];
4313
+ let startIndex = 0;
4314
+ sizes.forEach((_ref2, index) => {
4315
+ let {
4316
+ width,
4317
+ height
4318
+ } = _ref2;
4319
+ if (width > cols) {
4320
+ if (process.env.NODE_ENV !== "production") {
4321
+ throw new Error("[Floating UI]: Invalid grid - item width at index " + index + " is greater than grid columns");
4322
+ }
4323
+ }
4324
+ let itemPlaced = false;
4325
+ if (dense) {
4326
+ startIndex = 0;
4327
+ }
4328
+ while (!itemPlaced) {
4329
+ const targetCells = [];
4330
+ for (let i = 0; i < width; i++) {
4331
+ for (let j = 0; j < height; j++) {
4332
+ targetCells.push(startIndex + i + j * cols);
4333
+ }
4334
+ }
4335
+ if (startIndex % cols + width <= cols && targetCells.every(cell => cellMap[cell] == null)) {
4336
+ targetCells.forEach(cell => {
4337
+ cellMap[cell] = index;
4338
+ });
4339
+ itemPlaced = true;
4340
+ } else {
4341
+ startIndex++;
4342
+ }
4343
+ }
4344
+ });
4345
+
4346
+ // convert into a non-sparse array
4347
+ return [...cellMap];
4348
+ }
4349
+
4350
+ /** Gets cell index of an item's corner or -1 when index is -1. */
4351
+ function getCellIndexOfCorner(index, sizes, cellMap, cols, corner) {
4352
+ if (index === -1) return -1;
4353
+ const firstCellIndex = cellMap.indexOf(index);
4354
+ const sizeItem = sizes[index];
4355
+ switch (corner) {
4356
+ case 'tl':
4357
+ return firstCellIndex;
4358
+ case 'tr':
4359
+ if (!sizeItem) {
4360
+ return firstCellIndex;
4361
+ }
4362
+ return firstCellIndex + sizeItem.width - 1;
4363
+ case 'bl':
4364
+ if (!sizeItem) {
4365
+ return firstCellIndex;
4366
+ }
4367
+ return firstCellIndex + (sizeItem.height - 1) * cols;
4368
+ case 'br':
4369
+ return cellMap.lastIndexOf(index);
4370
+ }
4371
+ }
4372
+
4373
+ /** Gets all cell indices that correspond to the specified indices */
4374
+ function getCellIndices(indices, cellMap) {
4375
+ return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);
4376
+ }
4377
+ function isDisabled(list, index, disabledIndices) {
4378
+ if (disabledIndices) {
4379
+ return disabledIndices.includes(index);
4380
+ }
4381
+ const element = list[index];
4382
+ return element == null || element.hasAttribute('disabled') || element.getAttribute('aria-disabled') === 'true';
4383
+ }
4384
+
4137
4385
  var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
4138
4386
 
4139
4387
  let serverHandoffComplete = false;
@@ -4168,6 +4416,18 @@ let devMessageSet;
4168
4416
  if (process.env.NODE_ENV !== "production") {
4169
4417
  devMessageSet = /*#__PURE__*/new Set();
4170
4418
  }
4419
+ function warn() {
4420
+ var _devMessageSet;
4421
+ for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
4422
+ messages[_key] = arguments[_key];
4423
+ }
4424
+ const message = "Floating UI: " + messages.join(' ');
4425
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(message))) {
4426
+ var _devMessageSet2;
4427
+ (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(message);
4428
+ console.warn(message);
4429
+ }
4430
+ }
4171
4431
  function error() {
4172
4432
  var _devMessageSet3;
4173
4433
  for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
@@ -4353,6 +4613,22 @@ function getChildren(nodes, id) {
4353
4613
  }
4354
4614
  return allChildren;
4355
4615
  }
4616
+ function getDeepestNode(nodes, id) {
4617
+ let deepestNodeId;
4618
+ let maxDepth = -1;
4619
+ function findDeepest(nodeId, depth) {
4620
+ if (depth > maxDepth) {
4621
+ deepestNodeId = nodeId;
4622
+ maxDepth = depth;
4623
+ }
4624
+ const children = getChildren(nodes, nodeId);
4625
+ children.forEach(child => {
4626
+ findDeepest(child.id, depth + 1);
4627
+ });
4628
+ }
4629
+ findDeepest(id, 0);
4630
+ return nodes.find(node => node.id === deepestNodeId);
4631
+ }
4356
4632
 
4357
4633
  // Modified to add conditional `aria-hidden` support:
4358
4634
  // https://github.com/theKashey/aria-hidden/blob/9220c8f4a4fd35f63bee5510a9f41a37264382d4/src/index.ts
@@ -5921,6 +6197,574 @@ function useInteractions(propsList) {
5921
6197
  }), [getReferenceProps, getFloatingProps, getItemProps]);
5922
6198
  }
5923
6199
 
6200
+ const ESCAPE = 'Escape';
6201
+ function doSwitch(orientation, vertical, horizontal) {
6202
+ switch (orientation) {
6203
+ case 'vertical':
6204
+ return vertical;
6205
+ case 'horizontal':
6206
+ return horizontal;
6207
+ default:
6208
+ return vertical || horizontal;
6209
+ }
6210
+ }
6211
+ function isMainOrientationKey(key, orientation) {
6212
+ const vertical = key === ARROW_UP || key === ARROW_DOWN;
6213
+ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
6214
+ return doSwitch(orientation, vertical, horizontal);
6215
+ }
6216
+ function isMainOrientationToEndKey(key, orientation, rtl) {
6217
+ const vertical = key === ARROW_DOWN;
6218
+ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
6219
+ return doSwitch(orientation, vertical, horizontal) || key === 'Enter' || key === ' ' || key === '';
6220
+ }
6221
+ function isCrossOrientationOpenKey(key, orientation, rtl) {
6222
+ const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
6223
+ const horizontal = key === ARROW_DOWN;
6224
+ return doSwitch(orientation, vertical, horizontal);
6225
+ }
6226
+ function isCrossOrientationCloseKey(key, orientation, rtl, cols) {
6227
+ const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
6228
+ const horizontal = key === ARROW_UP;
6229
+ if (orientation === 'both' || orientation === 'horizontal' && cols && cols > 1) {
6230
+ return key === ESCAPE;
6231
+ }
6232
+ return doSwitch(orientation, vertical, horizontal);
6233
+ }
6234
+ /**
6235
+ * Adds arrow key-based navigation of a list of items, either using real DOM
6236
+ * focus or virtual focus.
6237
+ * @see https://floating-ui.com/docs/useListNavigation
6238
+ */
6239
+ function useListNavigation(context, props) {
6240
+ const {
6241
+ open,
6242
+ onOpenChange,
6243
+ elements
6244
+ } = context;
6245
+ const {
6246
+ listRef,
6247
+ activeIndex,
6248
+ onNavigate: unstable_onNavigate = () => {},
6249
+ enabled = true,
6250
+ selectedIndex = null,
6251
+ allowEscape = false,
6252
+ loop = false,
6253
+ nested = false,
6254
+ rtl = false,
6255
+ virtual = false,
6256
+ focusItemOnOpen = 'auto',
6257
+ focusItemOnHover = true,
6258
+ openOnArrowKeyDown = true,
6259
+ disabledIndices = undefined,
6260
+ orientation = 'vertical',
6261
+ cols = 1,
6262
+ scrollItemIntoView = true,
6263
+ virtualItemRef,
6264
+ itemSizes,
6265
+ dense = false
6266
+ } = props;
6267
+ if (process.env.NODE_ENV !== "production") {
6268
+ if (allowEscape) {
6269
+ if (!loop) {
6270
+ warn('`useListNavigation` looping must be enabled to allow escaping.');
6271
+ }
6272
+ if (!virtual) {
6273
+ warn('`useListNavigation` must be virtual to allow escaping.');
6274
+ }
6275
+ }
6276
+ if (orientation === 'vertical' && cols > 1) {
6277
+ warn('In grid list navigation mode (`cols` > 1), the `orientation` should', 'be either "horizontal" or "both".');
6278
+ }
6279
+ }
6280
+ const floatingFocusElement = getFloatingFocusElement(elements.floating);
6281
+ const floatingFocusElementRef = useLatestRef(floatingFocusElement);
6282
+ const parentId = useFloatingParentNodeId();
6283
+ const tree = useFloatingTree();
6284
+ index(() => {
6285
+ context.dataRef.current.orientation = orientation;
6286
+ }, [context, orientation]);
6287
+ const onNavigate = useEffectEvent(() => {
6288
+ unstable_onNavigate(indexRef.current === -1 ? null : indexRef.current);
6289
+ });
6290
+ const typeableComboboxReference = isTypeableCombobox(elements.domReference);
6291
+ const focusItemOnOpenRef = React.useRef(focusItemOnOpen);
6292
+ const indexRef = React.useRef(selectedIndex != null ? selectedIndex : -1);
6293
+ const keyRef = React.useRef(null);
6294
+ const isPointerModalityRef = React.useRef(true);
6295
+ const previousOnNavigateRef = React.useRef(onNavigate);
6296
+ const previousMountedRef = React.useRef(!!elements.floating);
6297
+ const previousOpenRef = React.useRef(open);
6298
+ const forceSyncFocusRef = React.useRef(false);
6299
+ const forceScrollIntoViewRef = React.useRef(false);
6300
+ const disabledIndicesRef = useLatestRef(disabledIndices);
6301
+ const latestOpenRef = useLatestRef(open);
6302
+ const scrollItemIntoViewRef = useLatestRef(scrollItemIntoView);
6303
+ const selectedIndexRef = useLatestRef(selectedIndex);
6304
+ const [activeId, setActiveId] = React.useState();
6305
+ const [virtualId, setVirtualId] = React.useState();
6306
+ const focusItem = useEffectEvent(() => {
6307
+ function runFocus(item) {
6308
+ if (virtual) {
6309
+ setActiveId(item.id);
6310
+ tree == null || tree.events.emit('virtualfocus', item);
6311
+ if (virtualItemRef) {
6312
+ virtualItemRef.current = item;
6313
+ }
6314
+ } else {
6315
+ enqueueFocus(item, {
6316
+ sync: forceSyncFocusRef.current,
6317
+ preventScroll: true
6318
+ });
6319
+ }
6320
+ }
6321
+ const initialItem = listRef.current[indexRef.current];
6322
+ if (initialItem) {
6323
+ runFocus(initialItem);
6324
+ }
6325
+ const scheduler = forceSyncFocusRef.current ? v => v() : requestAnimationFrame;
6326
+ scheduler(() => {
6327
+ const waitedItem = listRef.current[indexRef.current] || initialItem;
6328
+ if (!waitedItem) return;
6329
+ if (!initialItem) {
6330
+ runFocus(waitedItem);
6331
+ }
6332
+ const scrollIntoViewOptions = scrollItemIntoViewRef.current;
6333
+ const shouldScrollIntoView = scrollIntoViewOptions && item && (forceScrollIntoViewRef.current || !isPointerModalityRef.current);
6334
+ if (shouldScrollIntoView) {
6335
+ // JSDOM doesn't support `.scrollIntoView()` but it's widely supported
6336
+ // by all browsers.
6337
+ waitedItem.scrollIntoView == null || waitedItem.scrollIntoView(typeof scrollIntoViewOptions === 'boolean' ? {
6338
+ block: 'nearest',
6339
+ inline: 'nearest'
6340
+ } : scrollIntoViewOptions);
6341
+ }
6342
+ });
6343
+ });
6344
+
6345
+ // Sync `selectedIndex` to be the `activeIndex` upon opening the floating
6346
+ // element. Also, reset `activeIndex` upon closing the floating element.
6347
+ index(() => {
6348
+ if (!enabled) return;
6349
+ if (open && elements.floating) {
6350
+ if (focusItemOnOpenRef.current && selectedIndex != null) {
6351
+ // Regardless of the pointer modality, we want to ensure the selected
6352
+ // item comes into view when the floating element is opened.
6353
+ forceScrollIntoViewRef.current = true;
6354
+ indexRef.current = selectedIndex;
6355
+ onNavigate();
6356
+ }
6357
+ } else if (previousMountedRef.current) {
6358
+ // Since the user can specify `onNavigate` conditionally
6359
+ // (onNavigate: open ? setActiveIndex : setSelectedIndex),
6360
+ // we store and call the previous function.
6361
+ indexRef.current = -1;
6362
+ previousOnNavigateRef.current();
6363
+ }
6364
+ }, [enabled, open, elements.floating, selectedIndex, onNavigate]);
6365
+
6366
+ // Sync `activeIndex` to be the focused item while the floating element is
6367
+ // open.
6368
+ index(() => {
6369
+ if (!enabled) return;
6370
+ if (!open) return;
6371
+ if (!elements.floating) return;
6372
+ if (activeIndex == null) {
6373
+ forceSyncFocusRef.current = false;
6374
+ if (selectedIndexRef.current != null) {
6375
+ return;
6376
+ }
6377
+
6378
+ // Reset while the floating element was open (e.g. the list changed).
6379
+ if (previousMountedRef.current) {
6380
+ indexRef.current = -1;
6381
+ focusItem();
6382
+ }
6383
+
6384
+ // Initial sync.
6385
+ if ((!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {
6386
+ let runs = 0;
6387
+ const waitForListPopulated = () => {
6388
+ if (listRef.current[0] == null) {
6389
+ // Avoid letting the browser paint if possible on the first try,
6390
+ // otherwise use rAF. Don't try more than twice, since something
6391
+ // is wrong otherwise.
6392
+ if (runs < 2) {
6393
+ const scheduler = runs ? requestAnimationFrame : queueMicrotask;
6394
+ scheduler(waitForListPopulated);
6395
+ }
6396
+ runs++;
6397
+ } else {
6398
+ indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? getMinIndex(listRef, disabledIndicesRef.current) : getMaxIndex(listRef, disabledIndicesRef.current);
6399
+ keyRef.current = null;
6400
+ onNavigate();
6401
+ }
6402
+ };
6403
+ waitForListPopulated();
6404
+ }
6405
+ } else if (!isIndexOutOfBounds(listRef, activeIndex)) {
6406
+ indexRef.current = activeIndex;
6407
+ focusItem();
6408
+ forceScrollIntoViewRef.current = false;
6409
+ }
6410
+ }, [enabled, open, elements.floating, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]);
6411
+
6412
+ // Ensure the parent floating element has focus when a nested child closes
6413
+ // to allow arrow key navigation to work after the pointer leaves the child.
6414
+ index(() => {
6415
+ var _nodes$find;
6416
+ if (!enabled || elements.floating || !tree || virtual || !previousMountedRef.current) {
6417
+ return;
6418
+ }
6419
+ const nodes = tree.nodesRef.current;
6420
+ const parent = (_nodes$find = nodes.find(node => node.id === parentId)) == null || (_nodes$find = _nodes$find.context) == null ? void 0 : _nodes$find.elements.floating;
6421
+ const activeEl = activeElement(getDocument(elements.floating));
6422
+ const treeContainsActiveEl = nodes.some(node => node.context && contains(node.context.elements.floating, activeEl));
6423
+ if (parent && !treeContainsActiveEl && isPointerModalityRef.current) {
6424
+ parent.focus({
6425
+ preventScroll: true
6426
+ });
6427
+ }
6428
+ }, [enabled, elements.floating, tree, parentId, virtual]);
6429
+ index(() => {
6430
+ if (!enabled) return;
6431
+ if (!tree) return;
6432
+ if (!virtual) return;
6433
+ if (parentId) return;
6434
+ function handleVirtualFocus(item) {
6435
+ setVirtualId(item.id);
6436
+ if (virtualItemRef) {
6437
+ virtualItemRef.current = item;
6438
+ }
6439
+ }
6440
+ tree.events.on('virtualfocus', handleVirtualFocus);
6441
+ return () => {
6442
+ tree.events.off('virtualfocus', handleVirtualFocus);
6443
+ };
6444
+ }, [enabled, tree, virtual, parentId, virtualItemRef]);
6445
+ index(() => {
6446
+ previousOnNavigateRef.current = onNavigate;
6447
+ previousOpenRef.current = open;
6448
+ previousMountedRef.current = !!elements.floating;
6449
+ });
6450
+ index(() => {
6451
+ if (!open) {
6452
+ keyRef.current = null;
6453
+ }
6454
+ }, [open]);
6455
+ const hasActiveIndex = activeIndex != null;
6456
+ const item = React.useMemo(() => {
6457
+ function syncCurrentTarget(currentTarget) {
6458
+ if (!open) return;
6459
+ const index = listRef.current.indexOf(currentTarget);
6460
+ if (index !== -1 && indexRef.current !== index) {
6461
+ indexRef.current = index;
6462
+ onNavigate();
6463
+ }
6464
+ }
6465
+ const props = {
6466
+ onFocus(_ref) {
6467
+ let {
6468
+ currentTarget
6469
+ } = _ref;
6470
+ forceSyncFocusRef.current = true;
6471
+ syncCurrentTarget(currentTarget);
6472
+ },
6473
+ onClick: _ref2 => {
6474
+ let {
6475
+ currentTarget
6476
+ } = _ref2;
6477
+ return currentTarget.focus({
6478
+ preventScroll: true
6479
+ });
6480
+ },
6481
+ // Safari
6482
+ ...(focusItemOnHover && {
6483
+ onMouseMove(_ref3) {
6484
+ let {
6485
+ currentTarget
6486
+ } = _ref3;
6487
+ forceSyncFocusRef.current = true;
6488
+ forceScrollIntoViewRef.current = false;
6489
+ syncCurrentTarget(currentTarget);
6490
+ },
6491
+ onPointerLeave(_ref4) {
6492
+ let {
6493
+ pointerType
6494
+ } = _ref4;
6495
+ if (!isPointerModalityRef.current || pointerType === 'touch') {
6496
+ return;
6497
+ }
6498
+ forceSyncFocusRef.current = true;
6499
+ indexRef.current = -1;
6500
+ onNavigate();
6501
+ if (!virtual) {
6502
+ var _floatingFocusElement;
6503
+ (_floatingFocusElement = floatingFocusElementRef.current) == null || _floatingFocusElement.focus({
6504
+ preventScroll: true
6505
+ });
6506
+ }
6507
+ }
6508
+ })
6509
+ };
6510
+ return props;
6511
+ }, [open, floatingFocusElementRef, focusItemOnHover, listRef, onNavigate, virtual]);
6512
+ const commonOnKeyDown = useEffectEvent(event => {
6513
+ isPointerModalityRef.current = false;
6514
+ forceSyncFocusRef.current = true;
6515
+
6516
+ // When composing a character, Chrome fires ArrowDown twice. Firefox/Safari
6517
+ // don't appear to suffer from this. `event.isComposing` is avoided due to
6518
+ // Safari not supporting it properly (although it's not needed in the first
6519
+ // place for Safari, just avoiding any possible issues).
6520
+ if (event.which === 229) {
6521
+ return;
6522
+ }
6523
+
6524
+ // If the floating element is animating out, ignore navigation. Otherwise,
6525
+ // the `activeIndex` gets set to 0 despite not being open so the next time
6526
+ // the user ArrowDowns, the first item won't be focused.
6527
+ if (!latestOpenRef.current && event.currentTarget === floatingFocusElementRef.current) {
6528
+ return;
6529
+ }
6530
+ if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl, cols)) {
6531
+ stopEvent(event);
6532
+ onOpenChange(false, event.nativeEvent, 'list-navigation');
6533
+ if (isHTMLElement$1(elements.domReference)) {
6534
+ if (virtual) {
6535
+ tree == null || tree.events.emit('virtualfocus', elements.domReference);
6536
+ } else {
6537
+ elements.domReference.focus();
6538
+ }
6539
+ }
6540
+ return;
6541
+ }
6542
+ const currentIndex = indexRef.current;
6543
+ const minIndex = getMinIndex(listRef, disabledIndices);
6544
+ const maxIndex = getMaxIndex(listRef, disabledIndices);
6545
+ if (!typeableComboboxReference) {
6546
+ if (event.key === 'Home') {
6547
+ stopEvent(event);
6548
+ indexRef.current = minIndex;
6549
+ onNavigate();
6550
+ }
6551
+ if (event.key === 'End') {
6552
+ stopEvent(event);
6553
+ indexRef.current = maxIndex;
6554
+ onNavigate();
6555
+ }
6556
+ }
6557
+
6558
+ // Grid navigation.
6559
+ if (cols > 1) {
6560
+ const sizes = itemSizes || Array.from({
6561
+ length: listRef.current.length
6562
+ }, () => ({
6563
+ width: 1,
6564
+ height: 1
6565
+ }));
6566
+ // To calculate movements on the grid, we use hypothetical cell indices
6567
+ // as if every item was 1x1, then convert back to real indices.
6568
+ const cellMap = buildCellMap(sizes, cols, dense);
6569
+ const minGridIndex = cellMap.findIndex(index => index != null && !isDisabled(listRef.current, index, disabledIndices));
6570
+ // last enabled index
6571
+ const maxGridIndex = cellMap.reduce((foundIndex, index, cellIndex) => index != null && !isDisabled(listRef.current, index, disabledIndices) ? cellIndex : foundIndex, -1);
6572
+ const index = cellMap[getGridNavigatedIndex({
6573
+ current: cellMap.map(itemIndex => itemIndex != null ? listRef.current[itemIndex] : null)
6574
+ }, {
6575
+ event,
6576
+ orientation,
6577
+ loop,
6578
+ rtl,
6579
+ cols,
6580
+ // treat undefined (empty grid spaces) as disabled indices so we
6581
+ // don't end up in them
6582
+ disabledIndices: getCellIndices([...(disabledIndices || listRef.current.map((_, index) => isDisabled(listRef.current, index) ? index : undefined)), undefined], cellMap),
6583
+ minIndex: minGridIndex,
6584
+ maxIndex: maxGridIndex,
6585
+ prevIndex: getCellIndexOfCorner(indexRef.current > maxIndex ? minIndex : indexRef.current, sizes, cellMap, cols,
6586
+ // use a corner matching the edge closest to the direction
6587
+ // we're moving in so we don't end up in the same item. Prefer
6588
+ // top/left over bottom/right.
6589
+ event.key === ARROW_DOWN ? 'bl' : event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT) ? 'tr' : 'tl'),
6590
+ stopEvent: true
6591
+ })];
6592
+ if (index != null) {
6593
+ indexRef.current = index;
6594
+ onNavigate();
6595
+ }
6596
+ if (orientation === 'both') {
6597
+ return;
6598
+ }
6599
+ }
6600
+ if (isMainOrientationKey(event.key, orientation)) {
6601
+ stopEvent(event);
6602
+
6603
+ // Reset the index if no item is focused.
6604
+ if (open && !virtual && activeElement(event.currentTarget.ownerDocument) === event.currentTarget) {
6605
+ indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;
6606
+ onNavigate();
6607
+ return;
6608
+ }
6609
+ if (isMainOrientationToEndKey(event.key, orientation, rtl)) {
6610
+ if (loop) {
6611
+ indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : findNonDisabledIndex(listRef, {
6612
+ startingIndex: currentIndex,
6613
+ disabledIndices
6614
+ });
6615
+ } else {
6616
+ indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, {
6617
+ startingIndex: currentIndex,
6618
+ disabledIndices
6619
+ }));
6620
+ }
6621
+ } else {
6622
+ if (loop) {
6623
+ indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : findNonDisabledIndex(listRef, {
6624
+ startingIndex: currentIndex,
6625
+ decrement: true,
6626
+ disabledIndices
6627
+ });
6628
+ } else {
6629
+ indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, {
6630
+ startingIndex: currentIndex,
6631
+ decrement: true,
6632
+ disabledIndices
6633
+ }));
6634
+ }
6635
+ }
6636
+ if (isIndexOutOfBounds(listRef, indexRef.current)) {
6637
+ indexRef.current = -1;
6638
+ }
6639
+ onNavigate();
6640
+ }
6641
+ });
6642
+ const ariaActiveDescendantProp = React.useMemo(() => {
6643
+ return virtual && open && hasActiveIndex && {
6644
+ 'aria-activedescendant': virtualId || activeId
6645
+ };
6646
+ }, [virtual, open, hasActiveIndex, virtualId, activeId]);
6647
+ const floating = React.useMemo(() => {
6648
+ return {
6649
+ 'aria-orientation': orientation === 'both' ? undefined : orientation,
6650
+ ...(!typeableComboboxReference ? ariaActiveDescendantProp : {}),
6651
+ onKeyDown: commonOnKeyDown,
6652
+ onPointerMove() {
6653
+ isPointerModalityRef.current = true;
6654
+ }
6655
+ };
6656
+ }, [ariaActiveDescendantProp, commonOnKeyDown, orientation, typeableComboboxReference]);
6657
+ const reference = React.useMemo(() => {
6658
+ function checkVirtualMouse(event) {
6659
+ if (focusItemOnOpen === 'auto' && isVirtualClick(event.nativeEvent)) {
6660
+ focusItemOnOpenRef.current = true;
6661
+ }
6662
+ }
6663
+ function checkVirtualPointer(event) {
6664
+ // `pointerdown` fires first, reset the state then perform the checks.
6665
+ focusItemOnOpenRef.current = focusItemOnOpen;
6666
+ if (focusItemOnOpen === 'auto' && isVirtualPointerEvent(event.nativeEvent)) {
6667
+ focusItemOnOpenRef.current = true;
6668
+ }
6669
+ }
6670
+ return {
6671
+ ...ariaActiveDescendantProp,
6672
+ onKeyDown(event) {
6673
+ var _tree$nodesRef$curren;
6674
+ isPointerModalityRef.current = false;
6675
+ const isArrowKey = event.key.startsWith('Arrow');
6676
+ const isHomeOrEndKey = ['Home', 'End'].includes(event.key);
6677
+ const isMoveKey = isArrowKey || isHomeOrEndKey;
6678
+ const parentOrientation = tree == null || (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.context) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.dataRef) == null ? void 0 : _tree$nodesRef$curren.current.orientation;
6679
+ const isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl);
6680
+ const isCrossCloseKey = isCrossOrientationCloseKey(event.key, orientation, rtl, cols);
6681
+ const isParentCrossOpenKey = isCrossOrientationOpenKey(event.key, parentOrientation, rtl);
6682
+ const isMainKey = isMainOrientationKey(event.key, orientation);
6683
+ const isNavigationKey = (nested ? isParentCrossOpenKey : isMainKey) || event.key === 'Enter' || event.key.trim() === '';
6684
+ if (virtual && open) {
6685
+ const rootNode = tree == null ? void 0 : tree.nodesRef.current.find(node => node.parentId == null);
6686
+ const deepestNode = tree && rootNode ? getDeepestNode(tree.nodesRef.current, rootNode.id) : null;
6687
+ if (isMoveKey && deepestNode && virtualItemRef) {
6688
+ const eventObject = new KeyboardEvent('keydown', {
6689
+ key: event.key,
6690
+ bubbles: true
6691
+ });
6692
+ if (isCrossOpenKey || isCrossCloseKey) {
6693
+ var _deepestNode$context, _deepestNode$context2;
6694
+ const isCurrentTarget = ((_deepestNode$context = deepestNode.context) == null ? void 0 : _deepestNode$context.elements.domReference) === event.currentTarget;
6695
+ const dispatchItem = isCrossCloseKey && !isCurrentTarget ? (_deepestNode$context2 = deepestNode.context) == null ? void 0 : _deepestNode$context2.elements.domReference : isCrossOpenKey ? listRef.current.find(item => (item == null ? void 0 : item.id) === activeId) : null;
6696
+ if (dispatchItem) {
6697
+ stopEvent(event);
6698
+ dispatchItem.dispatchEvent(eventObject);
6699
+ setVirtualId(undefined);
6700
+ }
6701
+ }
6702
+ if ((isMainKey || isHomeOrEndKey) && deepestNode.context) {
6703
+ if (deepestNode.context.open && deepestNode.parentId && event.currentTarget !== deepestNode.context.elements.domReference) {
6704
+ var _deepestNode$context$;
6705
+ stopEvent(event);
6706
+ (_deepestNode$context$ = deepestNode.context.elements.domReference) == null || _deepestNode$context$.dispatchEvent(eventObject);
6707
+ return;
6708
+ }
6709
+ }
6710
+ }
6711
+ return commonOnKeyDown(event);
6712
+ }
6713
+ // If a floating element should not open on arrow key down, avoid
6714
+ // setting `activeIndex` while it's closed.
6715
+ if (!open && !openOnArrowKeyDown && isArrowKey) {
6716
+ return;
6717
+ }
6718
+ if (isNavigationKey) {
6719
+ const isParentMainKey = isMainOrientationKey(event.key, parentOrientation);
6720
+ keyRef.current = nested && isParentMainKey ? null : event.key;
6721
+ }
6722
+ if (nested) {
6723
+ if (isParentCrossOpenKey) {
6724
+ stopEvent(event);
6725
+ if (open) {
6726
+ indexRef.current = getMinIndex(listRef, disabledIndicesRef.current);
6727
+ onNavigate();
6728
+ } else {
6729
+ onOpenChange(true, event.nativeEvent, 'list-navigation');
6730
+ }
6731
+ }
6732
+ return;
6733
+ }
6734
+ if (isMainKey) {
6735
+ if (selectedIndex != null) {
6736
+ indexRef.current = selectedIndex;
6737
+ }
6738
+ stopEvent(event);
6739
+ if (!open && openOnArrowKeyDown) {
6740
+ onOpenChange(true, event.nativeEvent, 'list-navigation');
6741
+ } else {
6742
+ commonOnKeyDown(event);
6743
+ }
6744
+ if (open) {
6745
+ onNavigate();
6746
+ }
6747
+ }
6748
+ },
6749
+ onFocus() {
6750
+ if (open && !virtual) {
6751
+ indexRef.current = -1;
6752
+ onNavigate();
6753
+ }
6754
+ },
6755
+ onPointerDown: checkVirtualPointer,
6756
+ onPointerEnter: checkVirtualPointer,
6757
+ onMouseDown: checkVirtualMouse,
6758
+ onClick: checkVirtualMouse
6759
+ };
6760
+ }, [activeId, ariaActiveDescendantProp, cols, commonOnKeyDown, disabledIndicesRef, focusItemOnOpen, listRef, nested, onNavigate, onOpenChange, open, openOnArrowKeyDown, orientation, parentId, rtl, selectedIndex, tree, virtual, virtualItemRef]);
6761
+ return React.useMemo(() => enabled ? {
6762
+ reference,
6763
+ floating,
6764
+ item
6765
+ } : {}, [enabled, reference, floating, item]);
6766
+ }
6767
+
5924
6768
  const componentRoleToAriaRoleMap = /*#__PURE__*/new Map([['select', 'listbox'], ['combobox', 'listbox'], ['label', false]]);
5925
6769
 
5926
6770
  /**
@@ -6029,4 +6873,146 @@ function useRole(context, props) {
6029
6873
  } : {}, [enabled, reference, floating, item]);
6030
6874
  }
6031
6875
 
6032
- export { FloatingPortal as F, arrow as a, autoUpdate as b, useDismiss as c, useInteractions as d, size as e, flip as f, useFloatingParentNodeId as g, useFloatingNodeId as h, FloatingTree as i, FloatingNode as j, autoPlacement as k, limitShift as l, useClick as m, useRole as n, offset as o, FloatingOverlay as p, FloatingFocusManager as q, shift as s, useFloating as u };
6876
+ // Converts a JS style key like `backgroundColor` to a CSS transition-property
6877
+ // like `background-color`.
6878
+ const camelCaseToKebabCase = str => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
6879
+ function execWithArgsOrReturn(valueOrFn, args) {
6880
+ return typeof valueOrFn === 'function' ? valueOrFn(args) : valueOrFn;
6881
+ }
6882
+ function useDelayUnmount(open, durationMs) {
6883
+ const [isMounted, setIsMounted] = React.useState(open);
6884
+ if (open && !isMounted) {
6885
+ setIsMounted(true);
6886
+ }
6887
+ React.useEffect(() => {
6888
+ if (!open && isMounted) {
6889
+ const timeout = setTimeout(() => setIsMounted(false), durationMs);
6890
+ return () => clearTimeout(timeout);
6891
+ }
6892
+ }, [open, isMounted, durationMs]);
6893
+ return isMounted;
6894
+ }
6895
+ /**
6896
+ * Provides a status string to apply CSS transitions to a floating element,
6897
+ * correctly handling placement-aware transitions.
6898
+ * @see https://floating-ui.com/docs/useTransition#usetransitionstatus
6899
+ */
6900
+ function useTransitionStatus(context, props) {
6901
+ if (props === void 0) {
6902
+ props = {};
6903
+ }
6904
+ const {
6905
+ open,
6906
+ elements: {
6907
+ floating
6908
+ }
6909
+ } = context;
6910
+ const {
6911
+ duration = 250
6912
+ } = props;
6913
+ const isNumberDuration = typeof duration === 'number';
6914
+ const closeDuration = (isNumberDuration ? duration : duration.close) || 0;
6915
+ const [status, setStatus] = React.useState('unmounted');
6916
+ const isMounted = useDelayUnmount(open, closeDuration);
6917
+ if (!isMounted && status === 'close') {
6918
+ setStatus('unmounted');
6919
+ }
6920
+ index(() => {
6921
+ if (!floating) return;
6922
+ if (open) {
6923
+ setStatus('initial');
6924
+ const frame = requestAnimationFrame(() => {
6925
+ setStatus('open');
6926
+ });
6927
+ return () => {
6928
+ cancelAnimationFrame(frame);
6929
+ };
6930
+ }
6931
+ setStatus('close');
6932
+ }, [open, floating]);
6933
+ return {
6934
+ isMounted,
6935
+ status
6936
+ };
6937
+ }
6938
+ /**
6939
+ * Provides styles to apply CSS transitions to a floating element, correctly
6940
+ * handling placement-aware transitions. Wrapper around `useTransitionStatus`.
6941
+ * @see https://floating-ui.com/docs/useTransition#usetransitionstyles
6942
+ */
6943
+ function useTransitionStyles(context, props) {
6944
+ if (props === void 0) {
6945
+ props = {};
6946
+ }
6947
+ const {
6948
+ initial: unstable_initial = {
6949
+ opacity: 0
6950
+ },
6951
+ open: unstable_open,
6952
+ close: unstable_close,
6953
+ common: unstable_common,
6954
+ duration = 250
6955
+ } = props;
6956
+ const placement = context.placement;
6957
+ const side = placement.split('-')[0];
6958
+ const fnArgs = React.useMemo(() => ({
6959
+ side,
6960
+ placement
6961
+ }), [side, placement]);
6962
+ const isNumberDuration = typeof duration === 'number';
6963
+ const openDuration = (isNumberDuration ? duration : duration.open) || 0;
6964
+ const closeDuration = (isNumberDuration ? duration : duration.close) || 0;
6965
+ const [styles, setStyles] = React.useState(() => ({
6966
+ ...execWithArgsOrReturn(unstable_common, fnArgs),
6967
+ ...execWithArgsOrReturn(unstable_initial, fnArgs)
6968
+ }));
6969
+ const {
6970
+ isMounted,
6971
+ status
6972
+ } = useTransitionStatus(context, {
6973
+ duration
6974
+ });
6975
+ const initialRef = useLatestRef(unstable_initial);
6976
+ const openRef = useLatestRef(unstable_open);
6977
+ const closeRef = useLatestRef(unstable_close);
6978
+ const commonRef = useLatestRef(unstable_common);
6979
+ index(() => {
6980
+ const initialStyles = execWithArgsOrReturn(initialRef.current, fnArgs);
6981
+ const closeStyles = execWithArgsOrReturn(closeRef.current, fnArgs);
6982
+ const commonStyles = execWithArgsOrReturn(commonRef.current, fnArgs);
6983
+ const openStyles = execWithArgsOrReturn(openRef.current, fnArgs) || Object.keys(initialStyles).reduce((acc, key) => {
6984
+ acc[key] = '';
6985
+ return acc;
6986
+ }, {});
6987
+ if (status === 'initial') {
6988
+ setStyles(styles => ({
6989
+ transitionProperty: styles.transitionProperty,
6990
+ ...commonStyles,
6991
+ ...initialStyles
6992
+ }));
6993
+ }
6994
+ if (status === 'open') {
6995
+ setStyles({
6996
+ transitionProperty: Object.keys(openStyles).map(camelCaseToKebabCase).join(','),
6997
+ transitionDuration: openDuration + "ms",
6998
+ ...commonStyles,
6999
+ ...openStyles
7000
+ });
7001
+ }
7002
+ if (status === 'close') {
7003
+ const styles = closeStyles || initialStyles;
7004
+ setStyles({
7005
+ transitionProperty: Object.keys(styles).map(camelCaseToKebabCase).join(','),
7006
+ transitionDuration: closeDuration + "ms",
7007
+ ...commonStyles,
7008
+ ...styles
7009
+ });
7010
+ }
7011
+ }, [closeDuration, closeRef, initialRef, openRef, commonRef, openDuration, status, fnArgs]);
7012
+ return {
7013
+ isMounted,
7014
+ styles
7015
+ };
7016
+ }
7017
+
7018
+ export { FloatingPortal as F, arrow as a, autoUpdate as b, useDismiss as c, useInteractions as d, size as e, flip as f, useFloatingParentNodeId as g, useFloatingNodeId as h, FloatingTree as i, FloatingNode as j, autoPlacement as k, limitShift as l, useClick as m, useRole as n, offset as o, FloatingOverlay as p, FloatingFocusManager as q, useListNavigation as r, shift as s, useTransitionStyles as t, useFloating as u };