@acusti/dropdown 0.47.0 → 0.49.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.
package/dist/Dropdown.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { c } from "react/compiler-runtime";
3
3
  import { SYSTEM_UI_FONT, Style } from "@acusti/styling";
4
- import useIsOutOfBounds from "@acusti/use-is-out-of-bounds";
4
+ import useBoundingClientRect from "@acusti/use-bounding-client-rect";
5
5
  import useKeyboardEvents, { isEventTargetUsingKeyEvent } from "@acusti/use-keyboard-events";
6
6
  import clsx from "clsx";
7
7
  import * as React from "react";
@@ -38,8 +38,7 @@ ${TRIGGER_SELECTOR} {
38
38
  font-family: var(--uktdd-font-family);
39
39
  }
40
40
  ${ROOT_SELECTOR} {
41
- position: relative;
42
- display: inline-block;
41
+ width: max-content;
43
42
  }
44
43
  ${ROOT_SELECTOR}.disabled {
45
44
  pointer-events: none;
@@ -49,6 +48,7 @@ ${ROOT_SELECTOR} > * {
49
48
  }
50
49
  ${LABEL_SELECTOR} {
51
50
  display: flex;
51
+ align-items: center;
52
52
  }
53
53
  ${LABEL_TEXT_SELECTOR} {
54
54
  padding-right: var(--uktdd-label-pad-right);
@@ -56,31 +56,38 @@ ${LABEL_TEXT_SELECTOR} {
56
56
  ${BODY_SELECTOR} {
57
57
  box-sizing: border-box;
58
58
  position: absolute;
59
- top: 100%;
60
- max-height: var(${BODY_MAX_HEIGHT_VAR});
59
+ top: anchor(bottom);
60
+ left: anchor(left);
61
+ bottom: auto;
62
+ right: auto;
63
+ position-try-fallbacks: --uktdd-top-left, --uktdd-bottom-right, --uktdd-top-right;
61
64
  min-height: 50px;
65
+ max-height: var(${BODY_MAX_HEIGHT_VAR});
66
+ min-width: min(50px, 100%);
62
67
  max-width: var(${BODY_MAX_WIDTH_VAR});
63
- min-width: 100%;
64
68
  overflow: auto;
65
69
  z-index: 2;
66
70
  padding: var(--uktdd-body-pad-top) var(--uktdd-body-pad-right) var(--uktdd-body-pad-bottom) var(--uktdd-body-pad-left);
67
71
  background-color: var(--uktdd-body-bg-color);
68
72
  box-shadow: 0 8px 18px rgba(0,0,0,0.25);
69
73
  }
70
- ${BODY_SELECTOR}.calculating-position {
71
- visibility: hidden;
72
- }
73
- ${BODY_SELECTOR}.out-of-bounds-bottom:not(.out-of-bounds-top) {
74
+ @position-try --uktdd-top-left {
75
+ bottom: anchor(top);
76
+ left: anchor(left);
74
77
  top: auto;
75
- bottom: 100%;
78
+ right: auto;
76
79
  }
77
- ${BODY_SELECTOR}.out-of-bounds-right:not(.out-of-bounds-left) {
80
+ @position-try --uktdd-bottom-right {
81
+ top: anchor(bottom);
82
+ right: anchor(right);
83
+ bottom: auto;
78
84
  left: auto;
79
- right: 0px;
80
85
  }
81
- ${LABEL_SELECTOR} + ${BODY_SELECTOR} {
86
+ @position-try --uktdd-top-right {
87
+ bottom: anchor(top);
88
+ right: anchor(right);
89
+ top: auto;
82
90
  left: auto;
83
- right: 0;
84
91
  }
85
92
  ${BODY_SELECTOR}.has-items {
86
93
  user-select: none;
@@ -216,8 +223,9 @@ const noop = () => {
216
223
  };
217
224
  const CHILDREN_ERROR = "@acusti/dropdown requires either 1 child (the dropdown body) or 2 children: the dropdown trigger and the dropdown body.";
218
225
  const TEXT_INPUT_SELECTOR = "input:not([type=radio]):not([type=checkbox]):not([type=range]),textarea";
226
+ let idCounter = 0;
219
227
  function Dropdown(t0) {
220
- const $ = c(97);
228
+ const $ = c(119);
221
229
  const {
222
230
  allowCreate,
223
231
  allowEmpty: t1,
@@ -229,6 +237,8 @@ function Dropdown(t0) {
229
237
  isSearchable,
230
238
  keepOpenOnSubmit: t3,
231
239
  label,
240
+ minHeightBody: t4,
241
+ minWidthBody: t5,
232
242
  name,
233
243
  onClick,
234
244
  onClose,
@@ -244,6 +254,8 @@ function Dropdown(t0) {
244
254
  const allowEmpty = t1 === void 0 ? true : t1;
245
255
  const hasItems = t2 === void 0 ? true : t2;
246
256
  const keepOpenOnSubmit = t3 === void 0 ? !hasItems : t3;
257
+ const minHeightBody = t4 === void 0 ? 30 : t4;
258
+ const minWidthBody = t5 === void 0 ? 100 : t5;
247
259
  const childrenCount = Children.count(children);
248
260
  if (childrenCount !== 1 && childrenCount !== 2) {
249
261
  if (childrenCount === 0) {
@@ -255,19 +267,20 @@ function Dropdown(t0) {
255
267
  if (childrenCount > 1) {
256
268
  trigger = children[0];
257
269
  }
258
- let t4;
270
+ let t6;
259
271
  if ($[0] !== trigger) {
260
- t4 = React.isValidElement(trigger);
272
+ t6 = React.isValidElement(trigger);
261
273
  $[0] = trigger;
262
- $[1] = t4;
274
+ $[1] = t6;
263
275
  } else {
264
- t4 = $[1];
276
+ t6 = $[1];
265
277
  }
266
- const isTriggerFromProps = t4;
278
+ const isTriggerFromProps = t6;
267
279
  const [isOpen, setIsOpen] = useState(isOpenOnMount ?? false);
268
280
  const [isOpening, setIsOpening] = useState(!isOpenOnMount);
281
+ const [dropdownElement, setDropdownElement] = useState(null);
269
282
  const [dropdownBodyElement, setDropdownBodyElement] = useState(null);
270
- const dropdownElementRef = useRef(null);
283
+ const [id] = useState(_temp);
271
284
  const inputElementRef = useRef(null);
272
285
  const closingTimerRef = useRef(null);
273
286
  const isOpeningTimerRef = useRef(null);
@@ -275,7 +288,6 @@ function Dropdown(t0) {
275
288
  const clearEnteredCharactersTimerRef = useRef(null);
276
289
  const enteredCharactersRef = useRef("");
277
290
  const mouseDownPositionRef = useRef(null);
278
- const outOfBounds = useIsOutOfBounds(dropdownBodyElement);
279
291
  const allowCreateRef = useRef(allowCreate);
280
292
  const allowEmptyRef = useRef(allowEmpty);
281
293
  const hasItemsRef = useRef(hasItems);
@@ -286,10 +298,10 @@ function Dropdown(t0) {
286
298
  const onOpenRef = useRef(onOpen);
287
299
  const onSubmitItemRef = useRef(onSubmitItem);
288
300
  const valueRef = useRef(value);
289
- let t5;
290
- let t6;
301
+ let t7;
302
+ let t8;
291
303
  if ($[2] !== allowCreate || $[3] !== allowEmpty || $[4] !== hasItems || $[5] !== isOpen || $[6] !== isOpening || $[7] !== keepOpenOnSubmit || $[8] !== onClose || $[9] !== onOpen || $[10] !== onSubmitItem || $[11] !== value) {
292
- t5 = () => {
304
+ t7 = () => {
293
305
  allowCreateRef.current = allowCreate;
294
306
  allowEmptyRef.current = allowEmpty;
295
307
  hasItemsRef.current = hasItems;
@@ -301,7 +313,7 @@ function Dropdown(t0) {
301
313
  onSubmitItemRef.current = onSubmitItem;
302
314
  valueRef.current = value;
303
315
  };
304
- t6 = [allowCreate, allowEmpty, hasItems, isOpen, isOpening, keepOpenOnSubmit, onClose, onOpen, onSubmitItem, value];
316
+ t8 = [allowCreate, allowEmpty, hasItems, isOpen, isOpening, keepOpenOnSubmit, onClose, onOpen, onSubmitItem, value];
305
317
  $[2] = allowCreate;
306
318
  $[3] = allowEmpty;
307
319
  $[4] = hasItems;
@@ -312,18 +324,18 @@ function Dropdown(t0) {
312
324
  $[9] = onOpen;
313
325
  $[10] = onSubmitItem;
314
326
  $[11] = value;
315
- $[12] = t5;
316
- $[13] = t6;
327
+ $[12] = t7;
328
+ $[13] = t8;
317
329
  } else {
318
- t5 = $[12];
319
- t6 = $[13];
330
+ t7 = $[12];
331
+ t8 = $[13];
320
332
  }
321
- useEffect(t5, t6);
333
+ useEffect(t7, t8);
322
334
  const isMountedRef = useRef(false);
323
- let t7;
324
- let t8;
335
+ let t10;
336
+ let t9;
325
337
  if ($[14] !== isOpen) {
326
- t7 = () => {
338
+ t9 = () => {
327
339
  if (!isMountedRef.current) {
328
340
  isMountedRef.current = true;
329
341
  if (isOpenRef.current && onOpenRef.current) {
@@ -339,18 +351,18 @@ function Dropdown(t0) {
339
351
  }
340
352
  }
341
353
  };
342
- t8 = [isOpen];
354
+ t10 = [isOpen];
343
355
  $[14] = isOpen;
344
- $[15] = t7;
345
- $[16] = t8;
356
+ $[15] = t10;
357
+ $[16] = t9;
346
358
  } else {
347
- t7 = $[15];
348
- t8 = $[16];
359
+ t10 = $[15];
360
+ t9 = $[16];
349
361
  }
350
- useEffect(t7, t8);
351
- let t9;
362
+ useEffect(t9, t10);
363
+ let t11;
352
364
  if ($[17] !== setIsOpen || $[18] !== setIsOpening) {
353
- t9 = () => {
365
+ t11 = () => {
354
366
  setIsOpen(false);
355
367
  setIsOpening(false);
356
368
  mouseDownPositionRef.current = null;
@@ -361,26 +373,22 @@ function Dropdown(t0) {
361
373
  };
362
374
  $[17] = setIsOpen;
363
375
  $[18] = setIsOpening;
364
- $[19] = t9;
376
+ $[19] = t11;
365
377
  } else {
366
- t9 = $[19];
378
+ t11 = $[19];
367
379
  }
368
- const closeDropdown = t9;
369
- let t10;
370
- if ($[20] !== closeDropdown) {
371
- t10 = (event) => {
380
+ const closeDropdown = t11;
381
+ let t12;
382
+ if ($[20] !== closeDropdown || $[21] !== dropdownElement) {
383
+ t12 = (event) => {
372
384
  var _a;
373
- const eventTarget = event.target;
374
385
  if (isOpenRef.current && !keepOpenOnSubmitRef.current) {
375
- const keepOpen = eventTarget.closest("[data-ukt-keep-open]");
376
- if (!(keepOpen == null ? void 0 : keepOpen.dataset.uktKeepOpen) || keepOpen.dataset.uktKeepOpen === "false") {
377
- closingTimerRef.current = setTimeout(closeDropdown, 90);
378
- }
386
+ closingTimerRef.current = setTimeout(closeDropdown, 90);
379
387
  }
380
388
  if (!hasItemsRef.current) {
381
389
  return;
382
390
  }
383
- const element = getActiveItemElement(dropdownElementRef.current);
391
+ const element = getActiveItemElement(dropdownElement);
384
392
  if (!element && !allowCreateRef.current) {
385
393
  if (!allowEmptyRef.current) {
386
394
  return;
@@ -414,18 +422,19 @@ function Dropdown(t0) {
414
422
  }
415
423
  };
416
424
  $[20] = closeDropdown;
417
- $[21] = t10;
425
+ $[21] = dropdownElement;
426
+ $[22] = t12;
418
427
  } else {
419
- t10 = $[21];
428
+ t12 = $[22];
420
429
  }
421
- const handleSubmitItem = t10;
422
- let t11;
423
- if ($[22] !== setIsOpening) {
424
- t11 = (t122) => {
430
+ const handleSubmitItem = t12;
431
+ let t13;
432
+ if ($[23] !== setIsOpening) {
433
+ t13 = (t142) => {
425
434
  const {
426
435
  clientX,
427
436
  clientY
428
- } = t122;
437
+ } = t142;
429
438
  currentInputMethodRef.current = "mouse";
430
439
  const initialPosition = mouseDownPositionRef.current;
431
440
  if (!initialPosition) {
@@ -436,22 +445,21 @@ function Dropdown(t0) {
436
445
  }
437
446
  setIsOpening(false);
438
447
  };
439
- $[22] = setIsOpening;
440
- $[23] = t11;
448
+ $[23] = setIsOpening;
449
+ $[24] = t13;
441
450
  } else {
442
- t11 = $[23];
451
+ t13 = $[24];
443
452
  }
444
- const handleMouseMove = t11;
445
- let t12;
446
- if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
447
- t12 = (event_0) => {
453
+ const handleMouseMove = t13;
454
+ let t14;
455
+ if ($[25] !== dropdownElement) {
456
+ t14 = (event_0) => {
448
457
  if (!hasItemsRef.current) {
449
458
  return;
450
459
  }
451
460
  if (currentInputMethodRef.current !== "mouse") {
452
461
  return;
453
462
  }
454
- const dropdownElement = dropdownElementRef.current;
455
463
  if (!dropdownElement) {
456
464
  return;
457
465
  }
@@ -459,9 +467,9 @@ function Dropdown(t0) {
459
467
  if (!itemElements) {
460
468
  return;
461
469
  }
462
- const eventTarget_0 = event_0.target;
463
- const item = eventTarget_0.closest(ITEM_SELECTOR);
464
- const element_0 = item ?? eventTarget_0;
470
+ const eventTarget = event_0.target;
471
+ const item = eventTarget.closest(ITEM_SELECTOR);
472
+ const element_0 = item ?? eventTarget;
465
473
  for (const itemElement of itemElements) {
466
474
  if (itemElement === element_0) {
467
475
  setActiveItem({
@@ -472,18 +480,19 @@ function Dropdown(t0) {
472
480
  }
473
481
  }
474
482
  };
475
- $[24] = t12;
483
+ $[25] = dropdownElement;
484
+ $[26] = t14;
476
485
  } else {
477
- t12 = $[24];
486
+ t14 = $[26];
478
487
  }
479
- const handleMouseOver = t12;
480
- let t13;
481
- if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
482
- t13 = (event_1) => {
488
+ const handleMouseOver = t14;
489
+ let t15;
490
+ if ($[27] !== dropdownElement) {
491
+ t15 = (event_1) => {
483
492
  if (!hasItemsRef.current) {
484
493
  return;
485
494
  }
486
- const activeItem = getActiveItemElement(dropdownElementRef.current);
495
+ const activeItem = getActiveItemElement(dropdownElement);
487
496
  if (!activeItem) {
488
497
  return;
489
498
  }
@@ -493,14 +502,15 @@ function Dropdown(t0) {
493
502
  }
494
503
  delete activeItem.dataset.uktActive;
495
504
  };
496
- $[25] = t13;
505
+ $[27] = dropdownElement;
506
+ $[28] = t15;
497
507
  } else {
498
- t13 = $[25];
508
+ t15 = $[28];
499
509
  }
500
- const handleMouseOut = t13;
501
- let t14;
502
- if ($[26] !== onMouseDown || $[27] !== setIsOpen || $[28] !== setIsOpening) {
503
- t14 = (event_2) => {
510
+ const handleMouseOut = t15;
511
+ let t16;
512
+ if ($[29] !== onMouseDown || $[30] !== setIsOpen || $[31] !== setIsOpening) {
513
+ t16 = (event_2) => {
504
514
  if (onMouseDown) {
505
515
  onMouseDown(event_2);
506
516
  }
@@ -518,26 +528,26 @@ function Dropdown(t0) {
518
528
  isOpeningTimerRef.current = null;
519
529
  }, 1e3);
520
530
  };
521
- $[26] = onMouseDown;
522
- $[27] = setIsOpen;
523
- $[28] = setIsOpening;
524
- $[29] = t14;
531
+ $[29] = onMouseDown;
532
+ $[30] = setIsOpen;
533
+ $[31] = setIsOpening;
534
+ $[32] = t16;
525
535
  } else {
526
- t14 = $[29];
536
+ t16 = $[32];
527
537
  }
528
- const handleMouseDown = t14;
529
- let t15;
530
- if ($[30] !== closeDropdown || $[31] !== handleSubmitItem || $[32] !== onMouseUp) {
531
- t15 = (event_3) => {
538
+ const handleMouseDown = t16;
539
+ let t17;
540
+ if ($[33] !== closeDropdown || $[34] !== handleSubmitItem || $[35] !== onMouseUp) {
541
+ t17 = (event_3) => {
532
542
  if (onMouseUp) {
533
543
  onMouseUp(event_3);
534
544
  }
535
545
  if (isOpeningRef.current || !isOpenRef.current || closingTimerRef.current) {
536
546
  return;
537
547
  }
538
- const eventTarget_1 = event_3.target;
539
- if (!eventTarget_1.closest(BODY_SELECTOR)) {
540
- if (!isOpeningRef.current && inputElementRef.current !== eventTarget_1.ownerDocument.activeElement) {
548
+ const eventTarget_0 = event_3.target;
549
+ if (!eventTarget_0.closest(BODY_SELECTOR)) {
550
+ if (!isOpeningRef.current && inputElementRef.current !== eventTarget_0.ownerDocument.activeElement) {
541
551
  closeDropdown();
542
552
  }
543
553
  return;
@@ -547,26 +557,25 @@ function Dropdown(t0) {
547
557
  }
548
558
  handleSubmitItem(event_3);
549
559
  };
550
- $[30] = closeDropdown;
551
- $[31] = handleSubmitItem;
552
- $[32] = onMouseUp;
553
- $[33] = t15;
560
+ $[33] = closeDropdown;
561
+ $[34] = handleSubmitItem;
562
+ $[35] = onMouseUp;
563
+ $[36] = t17;
554
564
  } else {
555
- t15 = $[33];
565
+ t17 = $[36];
556
566
  }
557
- const handleMouseUp = t15;
558
- let t16;
559
- if ($[34] !== closeDropdown || $[35] !== handleSubmitItem || $[36] !== setIsOpen) {
560
- t16 = (event_4) => {
567
+ const handleMouseUp = t17;
568
+ let t18;
569
+ if ($[37] !== closeDropdown || $[38] !== dropdownElement || $[39] !== handleSubmitItem || $[40] !== setIsOpen) {
570
+ t18 = (event_4) => {
561
571
  const {
562
572
  altKey,
563
573
  ctrlKey,
564
574
  key,
565
575
  metaKey
566
576
  } = event_4;
567
- const eventTarget_2 = event_4.target;
568
- const dropdownElement_0 = dropdownElementRef.current;
569
- if (!dropdownElement_0) {
577
+ const eventTarget_1 = event_4.target;
578
+ if (!dropdownElement) {
570
579
  return;
571
580
  }
572
581
  const onEventHandled = () => {
@@ -574,7 +583,7 @@ function Dropdown(t0) {
574
583
  event_4.preventDefault();
575
584
  currentInputMethodRef.current = "keyboard";
576
585
  };
577
- const isEventTargetingDropdown = dropdownElement_0.contains(eventTarget_2);
586
+ const isEventTargetingDropdown = dropdownElement.contains(eventTarget_1);
578
587
  if (!isOpenRef.current) {
579
588
  if (!isEventTargetingDropdown) {
580
589
  return;
@@ -599,7 +608,7 @@ function Dropdown(t0) {
599
608
  enteredCharactersRef.current = enteredCharactersRef.current + key;
600
609
  }
601
610
  setActiveItem({
602
- dropdownElement: dropdownElement_0,
611
+ dropdownElement,
603
612
  isExactMatch: allowCreateRef.current,
604
613
  text: enteredCharactersRef.current
605
614
  });
@@ -629,12 +638,12 @@ function Dropdown(t0) {
629
638
  onEventHandled();
630
639
  if (altKey || metaKey) {
631
640
  setActiveItem({
632
- dropdownElement: dropdownElement_0,
641
+ dropdownElement,
633
642
  index: 0
634
643
  });
635
644
  } else {
636
645
  setActiveItem({
637
- dropdownElement: dropdownElement_0,
646
+ dropdownElement,
638
647
  indexAddend: -1
639
648
  });
640
649
  }
@@ -644,12 +653,12 @@ function Dropdown(t0) {
644
653
  onEventHandled();
645
654
  if (altKey || metaKey) {
646
655
  setActiveItem({
647
- dropdownElement: dropdownElement_0,
656
+ dropdownElement,
648
657
  index: -1
649
658
  });
650
659
  } else {
651
660
  setActiveItem({
652
- dropdownElement: dropdownElement_0,
661
+ dropdownElement,
653
662
  indexAddend: 1
654
663
  });
655
664
  }
@@ -657,31 +666,32 @@ function Dropdown(t0) {
657
666
  }
658
667
  }
659
668
  };
660
- $[34] = closeDropdown;
661
- $[35] = handleSubmitItem;
662
- $[36] = setIsOpen;
663
- $[37] = t16;
669
+ $[37] = closeDropdown;
670
+ $[38] = dropdownElement;
671
+ $[39] = handleSubmitItem;
672
+ $[40] = setIsOpen;
673
+ $[41] = t18;
664
674
  } else {
665
- t16 = $[37];
675
+ t18 = $[41];
666
676
  }
667
- const handleKeyDown = t16;
668
- let t17;
669
- if ($[38] !== handleKeyDown) {
670
- t17 = {
677
+ const handleKeyDown = t18;
678
+ let t19;
679
+ if ($[42] !== handleKeyDown) {
680
+ t19 = {
671
681
  ignoreUsedKeyboardEvents: false,
672
682
  onKeyDown: handleKeyDown
673
683
  };
674
- $[38] = handleKeyDown;
675
- $[39] = t17;
684
+ $[42] = handleKeyDown;
685
+ $[43] = t19;
676
686
  } else {
677
- t17 = $[39];
687
+ t19 = $[43];
678
688
  }
679
- useKeyboardEvents(t17);
689
+ useKeyboardEvents(t19);
680
690
  const cleanupEventListenersRef = useRef(noop);
681
- let t18;
682
- if ($[40] !== closeDropdown || $[41] !== isOpenOnMount || $[42] !== isTriggerFromProps || $[43] !== setIsOpen || $[44] !== setIsOpening) {
683
- t18 = (ref) => {
684
- dropdownElementRef.current = ref;
691
+ let t20;
692
+ if ($[44] !== closeDropdown || $[45] !== isOpenOnMount || $[46] !== isTriggerFromProps || $[47] !== setDropdownElement || $[48] !== setIsOpen || $[49] !== setIsOpening) {
693
+ t20 = (ref) => {
694
+ setDropdownElement(ref);
685
695
  if (!ref) {
686
696
  cleanupEventListenersRef.current();
687
697
  cleanupEventListenersRef.current = noop;
@@ -699,20 +709,19 @@ function Dropdown(t0) {
699
709
  }
700
710
  inputElementRef.current = inputElement;
701
711
  }
702
- const handleGlobalMouseDown = (t192) => {
712
+ const handleGlobalMouseDown = (t212) => {
703
713
  const {
704
714
  target
705
- } = t192;
706
- const eventTarget_3 = target;
707
- if (dropdownElementRef.current && !dropdownElementRef.current.contains(eventTarget_3)) {
715
+ } = t212;
716
+ const eventTarget_2 = target;
717
+ if (!ref.contains(eventTarget_2)) {
708
718
  closeDropdown();
709
719
  }
710
720
  };
711
- const handleGlobalMouseUp = (t202) => {
712
- var _a;
721
+ const handleGlobalMouseUp = (t222) => {
713
722
  const {
714
723
  target: target_0
715
- } = t202;
724
+ } = t222;
716
725
  if (!isOpenRef.current || closingTimerRef.current) {
717
726
  return;
718
727
  }
@@ -724,20 +733,20 @@ function Dropdown(t0) {
724
733
  }
725
734
  return;
726
735
  }
727
- const eventTarget_4 = target_0;
728
- if (!((_a = dropdownElementRef.current) == null ? void 0 : _a.contains(eventTarget_4))) {
736
+ const eventTarget_3 = target_0;
737
+ if (!ref.contains(eventTarget_3)) {
729
738
  closeDropdown();
730
739
  }
731
740
  };
732
- const handleGlobalFocusIn = (t212) => {
741
+ const handleGlobalFocusIn = (t232) => {
733
742
  const {
734
743
  target: target_1
735
- } = t212;
744
+ } = t232;
736
745
  if (!isOpenRef.current) {
737
746
  return;
738
747
  }
739
- const eventTarget_5 = target_1;
740
- if (!dropdownElementRef.current || dropdownElementRef.current.contains(eventTarget_5) || eventTarget_5.contains(dropdownElementRef.current)) {
748
+ const eventTarget_4 = target_1;
749
+ if (ref.contains(eventTarget_4) || eventTarget_4.contains(ref)) {
741
750
  return;
742
751
  }
743
752
  closeDropdown();
@@ -754,21 +763,17 @@ function Dropdown(t0) {
754
763
  ref.focus();
755
764
  }
756
765
  const handleInput = (event_5) => {
757
- const dropdownElement_1 = dropdownElementRef.current;
758
- if (!dropdownElement_1) {
759
- return;
760
- }
761
766
  if (!isOpenRef.current) {
762
767
  setIsOpen(true);
763
768
  }
764
769
  const input = event_5.target;
765
770
  const isDeleting = enteredCharactersRef.current.length > input.value.length;
766
771
  enteredCharactersRef.current = input.value;
767
- if (isDeleting && input.value.length && getActiveItemElement(dropdownElement_1)) {
772
+ if (isDeleting && input.value.length && getActiveItemElement(ref)) {
768
773
  return;
769
774
  }
770
775
  setActiveItem({
771
- dropdownElement: dropdownElement_1,
776
+ dropdownElement: ref,
772
777
  isExactMatch: allowCreateRef.current,
773
778
  text: enteredCharactersRef.current
774
779
  });
@@ -790,180 +795,257 @@ function Dropdown(t0) {
790
795
  }
791
796
  };
792
797
  };
793
- $[40] = closeDropdown;
794
- $[41] = isOpenOnMount;
795
- $[42] = isTriggerFromProps;
796
- $[43] = setIsOpen;
797
- $[44] = setIsOpening;
798
- $[45] = t18;
798
+ $[44] = closeDropdown;
799
+ $[45] = isOpenOnMount;
800
+ $[46] = isTriggerFromProps;
801
+ $[47] = setDropdownElement;
802
+ $[48] = setIsOpen;
803
+ $[49] = setIsOpening;
804
+ $[50] = t20;
799
805
  } else {
800
- t18 = $[45];
806
+ t20 = $[50];
801
807
  }
802
- const handleRef = t18;
808
+ const handleRef = t20;
803
809
  if (!isTriggerFromProps) {
804
810
  if (isSearchable) {
805
- const t192 = value ?? "";
806
- let t202;
807
- if ($[46] !== setIsOpen) {
808
- t202 = () => setIsOpen(true);
809
- $[46] = setIsOpen;
810
- $[47] = t202;
811
+ const t212 = value ?? "";
812
+ let t222;
813
+ if ($[51] !== setIsOpen) {
814
+ t222 = () => setIsOpen(true);
815
+ $[51] = setIsOpen;
816
+ $[52] = t222;
811
817
  } else {
812
- t202 = $[47];
818
+ t222 = $[52];
813
819
  }
814
- let t212;
815
- if ($[48] !== disabled || $[49] !== name || $[50] !== placeholder || $[51] !== t192 || $[52] !== t202 || $[53] !== tabIndex) {
816
- t212 = /* @__PURE__ */ jsx("input", { autoComplete: "off", className: TRIGGER_CLASS_NAME, defaultValue: t192, disabled, name, onFocus: t202, placeholder, ref: inputElementRef, tabIndex, type: "text" });
817
- $[48] = disabled;
818
- $[49] = name;
819
- $[50] = placeholder;
820
- $[51] = t192;
821
- $[52] = t202;
822
- $[53] = tabIndex;
823
- $[54] = t212;
820
+ let t232;
821
+ if ($[53] !== disabled || $[54] !== name || $[55] !== placeholder || $[56] !== t212 || $[57] !== t222 || $[58] !== tabIndex) {
822
+ t232 = /* @__PURE__ */ jsx("input", { autoComplete: "off", className: TRIGGER_CLASS_NAME, defaultValue: t212, disabled, name, onFocus: t222, placeholder, ref: inputElementRef, tabIndex, type: "text" });
823
+ $[53] = disabled;
824
+ $[54] = name;
825
+ $[55] = placeholder;
826
+ $[56] = t212;
827
+ $[57] = t222;
828
+ $[58] = tabIndex;
829
+ $[59] = t232;
824
830
  } else {
825
- t212 = $[54];
831
+ t232 = $[59];
826
832
  }
827
- trigger = t212;
833
+ trigger = t232;
828
834
  } else {
829
- let t192;
830
- if ($[55] !== trigger) {
831
- t192 = /* @__PURE__ */ jsx("button", { className: TRIGGER_CLASS_NAME, tabIndex: 0, children: trigger });
832
- $[55] = trigger;
833
- $[56] = t192;
835
+ let t212;
836
+ if ($[60] !== trigger) {
837
+ t212 = /* @__PURE__ */ jsx("button", { className: TRIGGER_CLASS_NAME, tabIndex: 0, children: trigger });
838
+ $[60] = trigger;
839
+ $[61] = t212;
834
840
  } else {
835
- t192 = $[56];
841
+ t212 = $[61];
836
842
  }
837
- trigger = t192;
843
+ trigger = t212;
838
844
  }
839
845
  }
840
846
  if (label) {
841
- let t192;
842
- if ($[57] !== label) {
843
- t192 = /* @__PURE__ */ jsx("div", { className: LABEL_TEXT_CLASS_NAME, children: label });
844
- $[57] = label;
845
- $[58] = t192;
847
+ let t212;
848
+ if ($[62] !== label) {
849
+ t212 = /* @__PURE__ */ jsx("div", { className: LABEL_TEXT_CLASS_NAME, children: label });
850
+ $[62] = label;
851
+ $[63] = t212;
846
852
  } else {
847
- t192 = $[58];
853
+ t212 = $[63];
848
854
  }
849
- let t202;
850
- if ($[59] !== t192 || $[60] !== trigger) {
851
- t202 = /* @__PURE__ */ jsxs("label", { className: LABEL_CLASS_NAME, children: [
852
- t192,
855
+ let t222;
856
+ if ($[64] !== t212 || $[65] !== trigger) {
857
+ t222 = /* @__PURE__ */ jsxs("label", { className: LABEL_CLASS_NAME, children: [
858
+ t212,
853
859
  trigger
854
860
  ] });
855
- $[59] = t192;
856
- $[60] = trigger;
857
- $[61] = t202;
861
+ $[64] = t212;
862
+ $[65] = trigger;
863
+ $[66] = t222;
858
864
  } else {
859
- t202 = $[61];
865
+ t222 = $[66];
860
866
  }
861
- trigger = t202;
867
+ trigger = t222;
862
868
  }
863
- let t19;
864
- if ($[62] !== outOfBounds.maxHeight) {
865
- t19 = outOfBounds.maxHeight != null && outOfBounds.maxHeight > 0 ? {
866
- [BODY_MAX_HEIGHT_VAR]: `calc(${outOfBounds.maxHeight}px - var(--uktdd-body-buffer))`
869
+ const dropdownRect = useBoundingClientRect(dropdownElement);
870
+ const dropdownBodyRect = useBoundingClientRect(dropdownBodyElement);
871
+ let t21;
872
+ if ($[67] !== dropdownBodyElement) {
873
+ t21 = getBoundingAncestor(dropdownBodyElement);
874
+ $[67] = dropdownBodyElement;
875
+ $[68] = t21;
876
+ } else {
877
+ t21 = $[68];
878
+ }
879
+ const boundingElement = t21;
880
+ const boundingElementRect = useBoundingClientRect(boundingElement);
881
+ let maxHeight;
882
+ let maxWidth;
883
+ if (dropdownBodyRect.top != null && dropdownRect.top != null && boundingElementRect.top != null) {
884
+ const maxHeightUp = dropdownBodyRect.bottom - boundingElementRect.top;
885
+ const maxHeightDown = boundingElementRect.bottom - dropdownBodyRect.top;
886
+ let t222;
887
+ if ($[69] !== dropdownBodyRect.top || $[70] !== dropdownRect.top || $[71] !== maxHeightDown || $[72] !== maxHeightUp) {
888
+ t222 = Math.round(dropdownBodyRect.top > dropdownRect.top ? maxHeightDown : maxHeightUp);
889
+ $[69] = dropdownBodyRect.top;
890
+ $[70] = dropdownRect.top;
891
+ $[71] = maxHeightDown;
892
+ $[72] = maxHeightUp;
893
+ $[73] = t222;
894
+ } else {
895
+ t222 = $[73];
896
+ }
897
+ maxHeight = t222;
898
+ const maxWidthLeft = dropdownBodyRect.right - boundingElementRect.left;
899
+ const maxWidthRight = boundingElementRect.right - dropdownBodyRect.left;
900
+ let t232;
901
+ if ($[74] !== dropdownBodyRect.left || $[75] !== dropdownRect.left || $[76] !== maxWidthLeft || $[77] !== maxWidthRight) {
902
+ t232 = Math.round(dropdownBodyRect.left > dropdownRect.left ? maxWidthRight : maxWidthLeft);
903
+ $[74] = dropdownBodyRect.left;
904
+ $[75] = dropdownRect.left;
905
+ $[76] = maxWidthLeft;
906
+ $[77] = maxWidthRight;
907
+ $[78] = t232;
908
+ } else {
909
+ t232 = $[78];
910
+ }
911
+ maxWidth = t232;
912
+ }
913
+ let t22;
914
+ if ($[79] !== maxHeight || $[80] !== minHeightBody) {
915
+ t22 = maxHeight != null && maxHeight > minHeightBody ? {
916
+ [BODY_MAX_HEIGHT_VAR]: `calc(${maxHeight}px - var(--uktdd-body-buffer))`
867
917
  } : null;
868
- $[62] = outOfBounds.maxHeight;
869
- $[63] = t19;
918
+ $[79] = maxHeight;
919
+ $[80] = minHeightBody;
920
+ $[81] = t22;
870
921
  } else {
871
- t19 = $[63];
922
+ t22 = $[81];
872
923
  }
873
- let t20;
874
- if ($[64] !== outOfBounds.maxWidth) {
875
- t20 = outOfBounds.maxWidth != null && outOfBounds.maxWidth > 0 ? {
876
- [BODY_MAX_WIDTH_VAR]: `calc(${outOfBounds.maxWidth}px - var(--uktdd-body-buffer))`
924
+ let t23;
925
+ if ($[82] !== maxWidth || $[83] !== minWidthBody) {
926
+ t23 = maxWidth != null && maxWidth > minWidthBody ? {
927
+ [BODY_MAX_WIDTH_VAR]: `calc(${maxWidth}px - var(--uktdd-body-buffer))`
877
928
  } : null;
878
- $[64] = outOfBounds.maxWidth;
879
- $[65] = t20;
929
+ $[82] = maxWidth;
930
+ $[83] = minWidthBody;
931
+ $[84] = t23;
880
932
  } else {
881
- t20 = $[65];
933
+ t23 = $[84];
882
934
  }
883
- let t21;
884
- if ($[66] !== styleFromProps || $[67] !== t19 || $[68] !== t20) {
885
- t21 = {
935
+ let t24;
936
+ if ($[85] !== styleFromProps || $[86] !== t22 || $[87] !== t23) {
937
+ t24 = {
886
938
  ...styleFromProps,
887
- ...t19,
888
- ...t20
939
+ ...t22,
940
+ ...t23
889
941
  };
890
- $[66] = styleFromProps;
891
- $[67] = t19;
892
- $[68] = t20;
893
- $[69] = t21;
942
+ $[85] = styleFromProps;
943
+ $[86] = t22;
944
+ $[87] = t23;
945
+ $[88] = t24;
894
946
  } else {
895
- t21 = $[69];
947
+ t24 = $[88];
896
948
  }
897
- const style = t21;
898
- let t22;
899
- if ($[70] === Symbol.for("react.memo_cache_sentinel")) {
900
- t22 = /* @__PURE__ */ jsx(Style, { href: "@acusti/dropdown/Dropdown", children: STYLES });
901
- $[70] = t22;
949
+ const style = t24;
950
+ const anchorStyles = `[data-ukt-id="${id}"] > :first-child {
951
+ anchor-name: --uktdd-anchor${id};
952
+ }
953
+ [data-ukt-id="${id}"] ${BODY_SELECTOR} {
954
+ position-anchor: --uktdd-anchor${id};
955
+ }`;
956
+ let t25;
957
+ if ($[89] === Symbol.for("react.memo_cache_sentinel")) {
958
+ t25 = /* @__PURE__ */ jsx(Style, { href: "@acusti/dropdown/Dropdown", children: STYLES });
959
+ $[89] = t25;
902
960
  } else {
903
- t22 = $[70];
961
+ t25 = $[89];
904
962
  }
905
- let t23;
906
- if ($[71] !== className || $[72] !== disabled || $[73] !== isOpen || $[74] !== isSearchable) {
907
- t23 = clsx(ROOT_CLASS_NAME, className, {
963
+ const t26 = `@acusti/dropdown/Dropdown/${id}`;
964
+ let t27;
965
+ if ($[90] !== anchorStyles || $[91] !== t26) {
966
+ t27 = /* @__PURE__ */ jsx(Style, { href: t26, children: anchorStyles });
967
+ $[90] = anchorStyles;
968
+ $[91] = t26;
969
+ $[92] = t27;
970
+ } else {
971
+ t27 = $[92];
972
+ }
973
+ let t28;
974
+ if ($[93] !== className || $[94] !== disabled || $[95] !== isOpen || $[96] !== isSearchable) {
975
+ t28 = clsx(ROOT_CLASS_NAME, className, {
908
976
  disabled,
909
977
  "is-open": isOpen,
910
978
  "is-searchable": isSearchable
911
979
  });
912
- $[71] = className;
913
- $[72] = disabled;
914
- $[73] = isOpen;
915
- $[74] = isSearchable;
916
- $[75] = t23;
980
+ $[93] = className;
981
+ $[94] = disabled;
982
+ $[95] = isOpen;
983
+ $[96] = isSearchable;
984
+ $[97] = t28;
917
985
  } else {
918
- t23 = $[75];
986
+ t28 = $[97];
919
987
  }
920
- let t24;
921
- if ($[76] !== children || $[77] !== childrenCount || $[78] !== hasItems || $[79] !== isOpen || $[80] !== outOfBounds.bottom || $[81] !== outOfBounds.hasLayout || $[82] !== outOfBounds.left || $[83] !== outOfBounds.right || $[84] !== outOfBounds.top || $[85] !== setDropdownBodyElement) {
922
- t24 = isOpen ? /* @__PURE__ */ jsx("div", { className: clsx(BODY_CLASS_NAME, {
923
- "calculating-position": !outOfBounds.hasLayout,
924
- "has-items": hasItems,
925
- "out-of-bounds-bottom": outOfBounds.bottom && !outOfBounds.top,
926
- "out-of-bounds-left": outOfBounds.left && !outOfBounds.right,
927
- "out-of-bounds-right": outOfBounds.right && !outOfBounds.left,
928
- "out-of-bounds-top": outOfBounds.top && !outOfBounds.bottom
929
- }), ref: setDropdownBodyElement, children: childrenCount > 1 ? children[1] : children }) : null;
930
- $[76] = children;
931
- $[77] = childrenCount;
932
- $[78] = hasItems;
933
- $[79] = isOpen;
934
- $[80] = outOfBounds.bottom;
935
- $[81] = outOfBounds.hasLayout;
936
- $[82] = outOfBounds.left;
937
- $[83] = outOfBounds.right;
938
- $[84] = outOfBounds.top;
939
- $[85] = setDropdownBodyElement;
940
- $[86] = t24;
988
+ let t29;
989
+ if ($[98] !== children || $[99] !== childrenCount || $[100] !== isOpen || $[101] !== setDropdownBodyElement) {
990
+ t29 = isOpen ? /* @__PURE__ */ jsx("div", { className: BODY_CLASS_NAME, ref: setDropdownBodyElement, children: childrenCount > 1 ? children[1] : children }) : null;
991
+ $[98] = children;
992
+ $[99] = childrenCount;
993
+ $[100] = isOpen;
994
+ $[101] = setDropdownBodyElement;
995
+ $[102] = t29;
941
996
  } else {
942
- t24 = $[86];
997
+ t29 = $[102];
943
998
  }
944
- let t25;
945
- if ($[87] !== handleMouseDown || $[88] !== handleMouseMove || $[89] !== handleMouseUp || $[90] !== handleRef || $[91] !== onClick || $[92] !== style || $[93] !== t23 || $[94] !== t24 || $[95] !== trigger) {
946
- t25 = /* @__PURE__ */ jsxs(Fragment, { children: [
947
- t22,
948
- /* @__PURE__ */ jsxs("div", { className: t23, onClick, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseOut: handleMouseOut, onMouseOver: handleMouseOver, onMouseUp: handleMouseUp, ref: handleRef, style, children: [
949
- trigger,
950
- t24
951
- ] })
999
+ let t30;
1000
+ if ($[103] !== handleMouseDown || $[104] !== handleMouseMove || $[105] !== handleMouseOut || $[106] !== handleMouseOver || $[107] !== handleMouseUp || $[108] !== handleRef || $[109] !== id || $[110] !== onClick || $[111] !== style || $[112] !== t28 || $[113] !== t29 || $[114] !== trigger) {
1001
+ t30 = /* @__PURE__ */ jsxs("div", { className: t28, "data-ukt-id": id, onClick, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseOut: handleMouseOut, onMouseOver: handleMouseOver, onMouseUp: handleMouseUp, ref: handleRef, style, children: [
1002
+ trigger,
1003
+ t29
1004
+ ] });
1005
+ $[103] = handleMouseDown;
1006
+ $[104] = handleMouseMove;
1007
+ $[105] = handleMouseOut;
1008
+ $[106] = handleMouseOver;
1009
+ $[107] = handleMouseUp;
1010
+ $[108] = handleRef;
1011
+ $[109] = id;
1012
+ $[110] = onClick;
1013
+ $[111] = style;
1014
+ $[112] = t28;
1015
+ $[113] = t29;
1016
+ $[114] = trigger;
1017
+ $[115] = t30;
1018
+ } else {
1019
+ t30 = $[115];
1020
+ }
1021
+ let t31;
1022
+ if ($[116] !== t27 || $[117] !== t30) {
1023
+ t31 = /* @__PURE__ */ jsxs(Fragment, { children: [
1024
+ t25,
1025
+ t27,
1026
+ t30
952
1027
  ] });
953
- $[87] = handleMouseDown;
954
- $[88] = handleMouseMove;
955
- $[89] = handleMouseUp;
956
- $[90] = handleRef;
957
- $[91] = onClick;
958
- $[92] = style;
959
- $[93] = t23;
960
- $[94] = t24;
961
- $[95] = trigger;
962
- $[96] = t25;
1028
+ $[116] = t27;
1029
+ $[117] = t30;
1030
+ $[118] = t31;
963
1031
  } else {
964
- t25 = $[96];
1032
+ t31 = $[118];
1033
+ }
1034
+ return t31;
1035
+ }
1036
+ function _temp() {
1037
+ idCounter = idCounter >= 999999 ? 0 : idCounter + 1;
1038
+ return idCounter;
1039
+ }
1040
+ function getBoundingAncestor(element) {
1041
+ while (element == null ? void 0 : element.parentElement) {
1042
+ if (element.parentElement.tagName === "BODY") return element.parentElement;
1043
+ if (getComputedStyle(element.parentElement).overflowX !== "visible") {
1044
+ return element.parentElement;
1045
+ }
1046
+ element = element.parentElement;
965
1047
  }
966
- return t25;
1048
+ return null;
967
1049
  }
968
1050
  export {
969
1051
  Dropdown as default