@acusti/dropdown 0.50.0 → 0.51.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/README.md +264 -17
- package/dist/Dropdown.d.ts +2 -1
- package/dist/Dropdown.js +274 -273
- package/dist/Dropdown.js.map +1 -1
- package/dist/helpers.d.ts +14 -20
- package/package.json +10 -10
package/dist/Dropdown.js
CHANGED
|
@@ -4,7 +4,7 @@ import { SYSTEM_UI_FONT, Style } from "@acusti/styling";
|
|
|
4
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
|
-
import { Children,
|
|
7
|
+
import { Children, useState, useId, useRef, useEffect, isValidElement, Fragment } from "react";
|
|
8
8
|
import { getBestMatch } from "@acusti/matchmaking";
|
|
9
9
|
const ROOT_CLASS_NAME = "uktdropdown";
|
|
10
10
|
const ROOT_SELECTOR = `.${ROOT_CLASS_NAME}`;
|
|
@@ -128,9 +128,11 @@ const clearItemElementsState = (itemElements) => {
|
|
|
128
128
|
const setActiveItem = ({
|
|
129
129
|
dropdownElement,
|
|
130
130
|
element,
|
|
131
|
+
event,
|
|
131
132
|
index,
|
|
132
133
|
indexAddend,
|
|
133
134
|
isExactMatch,
|
|
135
|
+
onActiveItem,
|
|
134
136
|
text
|
|
135
137
|
}) => {
|
|
136
138
|
const items = getItemElements(dropdownElement);
|
|
@@ -151,11 +153,7 @@ const setActiveItem = ({
|
|
|
151
153
|
} else {
|
|
152
154
|
nextActiveIndex += indexAddend;
|
|
153
155
|
}
|
|
154
|
-
|
|
155
|
-
nextActiveIndex = 0;
|
|
156
|
-
} else if (nextActiveIndex > lastIndex) {
|
|
157
|
-
nextActiveIndex = lastIndex;
|
|
158
|
-
}
|
|
156
|
+
nextActiveIndex = Math.max(0, Math.min(nextActiveIndex, lastIndex));
|
|
159
157
|
} else if (typeof text === "string") {
|
|
160
158
|
if (!text) {
|
|
161
159
|
clearItemElementsState(itemElements);
|
|
@@ -176,47 +174,50 @@ const setActiveItem = ({
|
|
|
176
174
|
nextActiveIndex = itemTexts.findIndex((itemText) => itemText === bestMatch);
|
|
177
175
|
}
|
|
178
176
|
}
|
|
179
|
-
if (nextActiveIndex === -1 || nextActiveIndex === currentActiveIndex) return;
|
|
180
|
-
clearItemElementsState(itemElements);
|
|
181
177
|
const nextActiveItem = items[nextActiveIndex];
|
|
182
|
-
if (nextActiveItem
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
178
|
+
if (nextActiveItem == null || nextActiveIndex === currentActiveIndex) return;
|
|
179
|
+
clearItemElementsState(itemElements);
|
|
180
|
+
nextActiveItem.setAttribute("data-ukt-active", "");
|
|
181
|
+
const label = nextActiveItem.innerText;
|
|
182
|
+
const value = nextActiveItem.dataset.uktValue ?? label;
|
|
183
|
+
onActiveItem?.({
|
|
184
|
+
element: nextActiveItem,
|
|
185
|
+
event,
|
|
186
|
+
label,
|
|
187
|
+
value
|
|
188
|
+
});
|
|
189
|
+
let {
|
|
190
|
+
parentElement
|
|
191
|
+
} = nextActiveItem;
|
|
192
|
+
let scrollableParent = null;
|
|
193
|
+
while (!scrollableParent && parentElement && parentElement !== dropdownElement) {
|
|
194
|
+
const isScrollable = parentElement.scrollHeight > parentElement.clientHeight + 15;
|
|
195
|
+
if (isScrollable) {
|
|
196
|
+
scrollableParent = parentElement;
|
|
197
|
+
} else {
|
|
198
|
+
parentElement = parentElement.parentElement;
|
|
195
199
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
scrollableParent.scrollTop = scrollTop;
|
|
200
|
+
}
|
|
201
|
+
if (scrollableParent) {
|
|
202
|
+
const parentRect = scrollableParent.getBoundingClientRect();
|
|
203
|
+
const itemRect = nextActiveItem.getBoundingClientRect();
|
|
204
|
+
const isAboveTop = itemRect.top < parentRect.top;
|
|
205
|
+
const isBelowBottom = itemRect.bottom > parentRect.bottom;
|
|
206
|
+
if (isAboveTop || isBelowBottom) {
|
|
207
|
+
let {
|
|
208
|
+
scrollTop
|
|
209
|
+
} = scrollableParent;
|
|
210
|
+
if (isAboveTop) {
|
|
211
|
+
scrollTop -= parentRect.top - itemRect.top;
|
|
212
|
+
} else {
|
|
213
|
+
scrollTop += itemRect.bottom - parentRect.bottom;
|
|
211
214
|
}
|
|
215
|
+
scrollableParent.scrollTop = scrollTop;
|
|
212
216
|
}
|
|
213
217
|
}
|
|
214
218
|
};
|
|
215
|
-
const noop = () => {
|
|
216
|
-
};
|
|
217
219
|
const CHILDREN_ERROR = "@acusti/dropdown requires either 1 child (the dropdown body) or 2 children: the dropdown trigger and the dropdown body.";
|
|
218
220
|
const TEXT_INPUT_SELECTOR = "input:not([type=radio]):not([type=checkbox]):not([type=range]),textarea";
|
|
219
|
-
let idCounter = 0;
|
|
220
221
|
function Dropdown(t0) {
|
|
221
222
|
const $ = c(102);
|
|
222
223
|
const {
|
|
@@ -233,6 +234,7 @@ function Dropdown(t0) {
|
|
|
233
234
|
minHeightBody: t4,
|
|
234
235
|
minWidthBody: t5,
|
|
235
236
|
name,
|
|
237
|
+
onActiveItem,
|
|
236
238
|
onClick,
|
|
237
239
|
onClose,
|
|
238
240
|
onMouseDown,
|
|
@@ -260,20 +262,11 @@ function Dropdown(t0) {
|
|
|
260
262
|
if (childrenCount > 1) {
|
|
261
263
|
trigger = children[0];
|
|
262
264
|
}
|
|
263
|
-
let t6;
|
|
264
|
-
if ($[0] !== trigger) {
|
|
265
|
-
t6 = isValidElement(trigger);
|
|
266
|
-
$[0] = trigger;
|
|
267
|
-
$[1] = t6;
|
|
268
|
-
} else {
|
|
269
|
-
t6 = $[1];
|
|
270
|
-
}
|
|
271
|
-
const isTriggerFromProps = t6;
|
|
272
265
|
const [isOpen, setIsOpen] = useState(isOpenOnMount ?? false);
|
|
273
266
|
const [isOpening, setIsOpening] = useState(!isOpenOnMount);
|
|
274
267
|
const [dropdownElement, setDropdownElement] = useState(null);
|
|
275
268
|
const [dropdownBodyElement, setDropdownBodyElement] = useState(null);
|
|
276
|
-
const
|
|
269
|
+
const id = useId();
|
|
277
270
|
const inputElementRef = useRef(null);
|
|
278
271
|
const closingTimerRef = useRef(null);
|
|
279
272
|
const isOpeningTimerRef = useRef(null);
|
|
@@ -291,10 +284,10 @@ function Dropdown(t0) {
|
|
|
291
284
|
const onOpenRef = useRef(onOpen);
|
|
292
285
|
const onSubmitItemRef = useRef(onSubmitItem);
|
|
293
286
|
const valueRef = useRef(value);
|
|
287
|
+
let t6;
|
|
294
288
|
let t7;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
t7 = () => {
|
|
289
|
+
if ($[0] !== allowCreate || $[1] !== allowEmpty || $[2] !== hasItems || $[3] !== isOpen || $[4] !== isOpening || $[5] !== keepOpenOnSubmit || $[6] !== onClose || $[7] !== onOpen || $[8] !== onSubmitItem || $[9] !== value) {
|
|
290
|
+
t6 = () => {
|
|
298
291
|
allowCreateRef.current = allowCreate;
|
|
299
292
|
allowEmptyRef.current = allowEmpty;
|
|
300
293
|
hasItemsRef.current = hasItems;
|
|
@@ -306,29 +299,29 @@ function Dropdown(t0) {
|
|
|
306
299
|
onSubmitItemRef.current = onSubmitItem;
|
|
307
300
|
valueRef.current = value;
|
|
308
301
|
};
|
|
309
|
-
|
|
310
|
-
$[
|
|
311
|
-
$[
|
|
312
|
-
$[
|
|
313
|
-
$[
|
|
314
|
-
$[
|
|
315
|
-
$[
|
|
316
|
-
$[
|
|
317
|
-
$[
|
|
318
|
-
$[
|
|
319
|
-
$[
|
|
320
|
-
$[
|
|
321
|
-
$[
|
|
302
|
+
t7 = [allowCreate, allowEmpty, hasItems, isOpen, isOpening, keepOpenOnSubmit, onClose, onOpen, onSubmitItem, value];
|
|
303
|
+
$[0] = allowCreate;
|
|
304
|
+
$[1] = allowEmpty;
|
|
305
|
+
$[2] = hasItems;
|
|
306
|
+
$[3] = isOpen;
|
|
307
|
+
$[4] = isOpening;
|
|
308
|
+
$[5] = keepOpenOnSubmit;
|
|
309
|
+
$[6] = onClose;
|
|
310
|
+
$[7] = onOpen;
|
|
311
|
+
$[8] = onSubmitItem;
|
|
312
|
+
$[9] = value;
|
|
313
|
+
$[10] = t6;
|
|
314
|
+
$[11] = t7;
|
|
322
315
|
} else {
|
|
323
|
-
|
|
324
|
-
|
|
316
|
+
t6 = $[10];
|
|
317
|
+
t7 = $[11];
|
|
325
318
|
}
|
|
326
|
-
useEffect(
|
|
319
|
+
useEffect(t6, t7);
|
|
327
320
|
const isMountedRef = useRef(false);
|
|
328
|
-
let
|
|
321
|
+
let t8;
|
|
329
322
|
let t9;
|
|
330
|
-
if ($[
|
|
331
|
-
|
|
323
|
+
if ($[12] !== isOpen) {
|
|
324
|
+
t8 = () => {
|
|
332
325
|
if (!isMountedRef.current) {
|
|
333
326
|
isMountedRef.current = true;
|
|
334
327
|
if (isOpenRef.current && onOpenRef.current) {
|
|
@@ -344,18 +337,18 @@ function Dropdown(t0) {
|
|
|
344
337
|
}
|
|
345
338
|
}
|
|
346
339
|
};
|
|
347
|
-
|
|
348
|
-
$[
|
|
349
|
-
$[
|
|
350
|
-
$[
|
|
340
|
+
t9 = [isOpen];
|
|
341
|
+
$[12] = isOpen;
|
|
342
|
+
$[13] = t8;
|
|
343
|
+
$[14] = t9;
|
|
351
344
|
} else {
|
|
352
|
-
|
|
353
|
-
t9 = $[
|
|
345
|
+
t8 = $[13];
|
|
346
|
+
t9 = $[14];
|
|
354
347
|
}
|
|
355
|
-
useEffect(
|
|
356
|
-
let
|
|
357
|
-
if ($[
|
|
358
|
-
|
|
348
|
+
useEffect(t8, t9);
|
|
349
|
+
let t10;
|
|
350
|
+
if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
|
|
351
|
+
t10 = () => {
|
|
359
352
|
setIsOpen(false);
|
|
360
353
|
setIsOpening(false);
|
|
361
354
|
mouseDownPositionRef.current = null;
|
|
@@ -364,15 +357,14 @@ function Dropdown(t0) {
|
|
|
364
357
|
closingTimerRef.current = null;
|
|
365
358
|
}
|
|
366
359
|
};
|
|
367
|
-
$[
|
|
360
|
+
$[15] = t10;
|
|
368
361
|
} else {
|
|
369
|
-
|
|
362
|
+
t10 = $[15];
|
|
370
363
|
}
|
|
371
|
-
const closeDropdown =
|
|
372
|
-
let
|
|
373
|
-
if ($[
|
|
374
|
-
|
|
375
|
-
var _a;
|
|
364
|
+
const closeDropdown = t10;
|
|
365
|
+
let t11;
|
|
366
|
+
if ($[16] !== dropdownElement) {
|
|
367
|
+
t11 = (event) => {
|
|
376
368
|
if (isOpenRef.current && !keepOpenOnSubmitRef.current) {
|
|
377
369
|
closingTimerRef.current = setTimeout(closeDropdown, 90);
|
|
378
370
|
}
|
|
@@ -384,11 +376,11 @@ function Dropdown(t0) {
|
|
|
384
376
|
if (!allowEmptyRef.current) {
|
|
385
377
|
return;
|
|
386
378
|
}
|
|
387
|
-
if (
|
|
379
|
+
if (inputElementRef.current?.value) {
|
|
388
380
|
return;
|
|
389
381
|
}
|
|
390
382
|
}
|
|
391
|
-
let itemLabel =
|
|
383
|
+
let itemLabel = element?.innerText ?? "";
|
|
392
384
|
if (inputElementRef.current) {
|
|
393
385
|
if (!element) {
|
|
394
386
|
itemLabel = inputElementRef.current.value;
|
|
@@ -399,7 +391,7 @@ function Dropdown(t0) {
|
|
|
399
391
|
inputElementRef.current.blur();
|
|
400
392
|
}
|
|
401
393
|
}
|
|
402
|
-
const nextValue =
|
|
394
|
+
const nextValue = element?.dataset.uktValue ?? itemLabel;
|
|
403
395
|
if (valueRef.current && valueRef.current === nextValue) {
|
|
404
396
|
return;
|
|
405
397
|
}
|
|
@@ -412,19 +404,19 @@ function Dropdown(t0) {
|
|
|
412
404
|
});
|
|
413
405
|
}
|
|
414
406
|
};
|
|
415
|
-
$[
|
|
416
|
-
$[
|
|
407
|
+
$[16] = dropdownElement;
|
|
408
|
+
$[17] = t11;
|
|
417
409
|
} else {
|
|
418
|
-
|
|
410
|
+
t11 = $[17];
|
|
419
411
|
}
|
|
420
|
-
const handleSubmitItem =
|
|
421
|
-
let
|
|
422
|
-
if ($[
|
|
423
|
-
|
|
412
|
+
const handleSubmitItem = t11;
|
|
413
|
+
let t12;
|
|
414
|
+
if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
|
|
415
|
+
t12 = (t132) => {
|
|
424
416
|
const {
|
|
425
417
|
clientX,
|
|
426
418
|
clientY
|
|
427
|
-
} =
|
|
419
|
+
} = t132;
|
|
428
420
|
currentInputMethodRef.current = "mouse";
|
|
429
421
|
const initialPosition = mouseDownPositionRef.current;
|
|
430
422
|
if (!initialPosition) {
|
|
@@ -435,14 +427,14 @@ function Dropdown(t0) {
|
|
|
435
427
|
}
|
|
436
428
|
setIsOpening(false);
|
|
437
429
|
};
|
|
438
|
-
$[
|
|
430
|
+
$[18] = t12;
|
|
439
431
|
} else {
|
|
440
|
-
|
|
432
|
+
t12 = $[18];
|
|
441
433
|
}
|
|
442
|
-
const handleMouseMove =
|
|
443
|
-
let
|
|
444
|
-
if ($[
|
|
445
|
-
|
|
434
|
+
const handleMouseMove = t12;
|
|
435
|
+
let t13;
|
|
436
|
+
if ($[19] !== dropdownElement || $[20] !== onActiveItem) {
|
|
437
|
+
t13 = (event_0) => {
|
|
446
438
|
if (!hasItemsRef.current) {
|
|
447
439
|
return;
|
|
448
440
|
}
|
|
@@ -463,21 +455,24 @@ function Dropdown(t0) {
|
|
|
463
455
|
if (itemElement === element_0) {
|
|
464
456
|
setActiveItem({
|
|
465
457
|
dropdownElement,
|
|
466
|
-
element: element_0
|
|
458
|
+
element: element_0,
|
|
459
|
+
event: event_0,
|
|
460
|
+
onActiveItem
|
|
467
461
|
});
|
|
468
462
|
return;
|
|
469
463
|
}
|
|
470
464
|
}
|
|
471
465
|
};
|
|
472
|
-
$[
|
|
473
|
-
$[
|
|
466
|
+
$[19] = dropdownElement;
|
|
467
|
+
$[20] = onActiveItem;
|
|
468
|
+
$[21] = t13;
|
|
474
469
|
} else {
|
|
475
|
-
|
|
470
|
+
t13 = $[21];
|
|
476
471
|
}
|
|
477
|
-
const handleMouseOver =
|
|
478
|
-
let
|
|
479
|
-
if ($[
|
|
480
|
-
|
|
472
|
+
const handleMouseOver = t13;
|
|
473
|
+
let t14;
|
|
474
|
+
if ($[22] !== dropdownElement) {
|
|
475
|
+
t14 = (event_1) => {
|
|
481
476
|
if (!hasItemsRef.current) {
|
|
482
477
|
return;
|
|
483
478
|
}
|
|
@@ -491,15 +486,15 @@ function Dropdown(t0) {
|
|
|
491
486
|
}
|
|
492
487
|
delete activeItem.dataset.uktActive;
|
|
493
488
|
};
|
|
494
|
-
$[
|
|
495
|
-
$[
|
|
489
|
+
$[22] = dropdownElement;
|
|
490
|
+
$[23] = t14;
|
|
496
491
|
} else {
|
|
497
|
-
|
|
492
|
+
t14 = $[23];
|
|
498
493
|
}
|
|
499
|
-
const handleMouseOut =
|
|
500
|
-
let
|
|
501
|
-
if ($[
|
|
502
|
-
|
|
494
|
+
const handleMouseOut = t14;
|
|
495
|
+
let t15;
|
|
496
|
+
if ($[24] !== onMouseDown) {
|
|
497
|
+
t15 = (event_2) => {
|
|
503
498
|
if (onMouseDown) {
|
|
504
499
|
onMouseDown(event_2);
|
|
505
500
|
}
|
|
@@ -517,15 +512,15 @@ function Dropdown(t0) {
|
|
|
517
512
|
isOpeningTimerRef.current = null;
|
|
518
513
|
}, 1e3);
|
|
519
514
|
};
|
|
520
|
-
$[
|
|
521
|
-
$[
|
|
515
|
+
$[24] = onMouseDown;
|
|
516
|
+
$[25] = t15;
|
|
522
517
|
} else {
|
|
523
|
-
|
|
518
|
+
t15 = $[25];
|
|
524
519
|
}
|
|
525
|
-
const handleMouseDown =
|
|
526
|
-
let
|
|
527
|
-
if ($[
|
|
528
|
-
|
|
520
|
+
const handleMouseDown = t15;
|
|
521
|
+
let t16;
|
|
522
|
+
if ($[26] !== handleSubmitItem || $[27] !== onMouseUp) {
|
|
523
|
+
t16 = (event_3) => {
|
|
529
524
|
if (onMouseUp) {
|
|
530
525
|
onMouseUp(event_3);
|
|
531
526
|
}
|
|
@@ -544,16 +539,16 @@ function Dropdown(t0) {
|
|
|
544
539
|
}
|
|
545
540
|
handleSubmitItem(event_3);
|
|
546
541
|
};
|
|
547
|
-
$[
|
|
548
|
-
$[
|
|
549
|
-
$[
|
|
542
|
+
$[26] = handleSubmitItem;
|
|
543
|
+
$[27] = onMouseUp;
|
|
544
|
+
$[28] = t16;
|
|
550
545
|
} else {
|
|
551
|
-
|
|
546
|
+
t16 = $[28];
|
|
552
547
|
}
|
|
553
|
-
const handleMouseUp =
|
|
554
|
-
let
|
|
555
|
-
if ($[
|
|
556
|
-
|
|
548
|
+
const handleMouseUp = t16;
|
|
549
|
+
let t17;
|
|
550
|
+
if ($[29] !== dropdownElement || $[30] !== handleSubmitItem || $[31] !== onActiveItem) {
|
|
551
|
+
t17 = (event_4) => {
|
|
557
552
|
const {
|
|
558
553
|
altKey,
|
|
559
554
|
ctrlKey,
|
|
@@ -595,7 +590,9 @@ function Dropdown(t0) {
|
|
|
595
590
|
}
|
|
596
591
|
setActiveItem({
|
|
597
592
|
dropdownElement,
|
|
593
|
+
event: event_4,
|
|
598
594
|
isExactMatch: allowCreateRef.current,
|
|
595
|
+
onActiveItem,
|
|
599
596
|
text: enteredCharactersRef.current
|
|
600
597
|
});
|
|
601
598
|
if (clearEnteredCharactersTimerRef.current) {
|
|
@@ -625,12 +622,16 @@ function Dropdown(t0) {
|
|
|
625
622
|
if (altKey || metaKey) {
|
|
626
623
|
setActiveItem({
|
|
627
624
|
dropdownElement,
|
|
628
|
-
|
|
625
|
+
event: event_4,
|
|
626
|
+
index: 0,
|
|
627
|
+
onActiveItem
|
|
629
628
|
});
|
|
630
629
|
} else {
|
|
631
630
|
setActiveItem({
|
|
632
631
|
dropdownElement,
|
|
633
|
-
|
|
632
|
+
event: event_4,
|
|
633
|
+
indexAddend: -1,
|
|
634
|
+
onActiveItem
|
|
634
635
|
});
|
|
635
636
|
}
|
|
636
637
|
return;
|
|
@@ -640,52 +641,54 @@ function Dropdown(t0) {
|
|
|
640
641
|
if (altKey || metaKey) {
|
|
641
642
|
setActiveItem({
|
|
642
643
|
dropdownElement,
|
|
643
|
-
|
|
644
|
+
event: event_4,
|
|
645
|
+
index: -1,
|
|
646
|
+
onActiveItem
|
|
644
647
|
});
|
|
645
648
|
} else {
|
|
646
649
|
setActiveItem({
|
|
647
650
|
dropdownElement,
|
|
648
|
-
|
|
651
|
+
event: event_4,
|
|
652
|
+
indexAddend: 1,
|
|
653
|
+
onActiveItem
|
|
649
654
|
});
|
|
650
655
|
}
|
|
651
656
|
return;
|
|
652
657
|
}
|
|
653
658
|
}
|
|
654
659
|
};
|
|
655
|
-
$[
|
|
656
|
-
$[
|
|
657
|
-
$[
|
|
660
|
+
$[29] = dropdownElement;
|
|
661
|
+
$[30] = handleSubmitItem;
|
|
662
|
+
$[31] = onActiveItem;
|
|
663
|
+
$[32] = t17;
|
|
658
664
|
} else {
|
|
659
|
-
|
|
665
|
+
t17 = $[32];
|
|
660
666
|
}
|
|
661
|
-
const handleKeyDown =
|
|
662
|
-
let
|
|
667
|
+
const handleKeyDown = t17;
|
|
668
|
+
let t18;
|
|
663
669
|
if ($[33] !== handleKeyDown) {
|
|
664
|
-
|
|
670
|
+
t18 = {
|
|
665
671
|
ignoreUsedKeyboardEvents: false,
|
|
666
672
|
onKeyDown: handleKeyDown
|
|
667
673
|
};
|
|
668
674
|
$[33] = handleKeyDown;
|
|
669
|
-
$[34] =
|
|
675
|
+
$[34] = t18;
|
|
670
676
|
} else {
|
|
671
|
-
|
|
677
|
+
t18 = $[34];
|
|
672
678
|
}
|
|
673
|
-
useKeyboardEvents(
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
t20 = (ref) => {
|
|
679
|
+
useKeyboardEvents(t18);
|
|
680
|
+
let t19;
|
|
681
|
+
if ($[35] !== isOpenOnMount || $[36] !== onActiveItem) {
|
|
682
|
+
t19 = (ref) => {
|
|
678
683
|
setDropdownElement(ref);
|
|
679
684
|
if (!ref) {
|
|
680
|
-
cleanupEventListenersRef.current();
|
|
681
|
-
cleanupEventListenersRef.current = noop;
|
|
682
685
|
return;
|
|
683
686
|
}
|
|
684
687
|
const {
|
|
685
688
|
ownerDocument
|
|
686
689
|
} = ref;
|
|
687
690
|
let inputElement = inputElementRef.current;
|
|
688
|
-
if (
|
|
691
|
+
if (!inputElement && ref.firstElementChild) {
|
|
689
692
|
if (ref.firstElementChild.matches(TEXT_INPUT_SELECTOR)) {
|
|
690
693
|
inputElement = ref.firstElementChild;
|
|
691
694
|
} else {
|
|
@@ -693,19 +696,19 @@ function Dropdown(t0) {
|
|
|
693
696
|
}
|
|
694
697
|
inputElementRef.current = inputElement;
|
|
695
698
|
}
|
|
696
|
-
const handleGlobalMouseDown = (
|
|
699
|
+
const handleGlobalMouseDown = (t202) => {
|
|
697
700
|
const {
|
|
698
701
|
target
|
|
699
|
-
} =
|
|
702
|
+
} = t202;
|
|
700
703
|
const eventTarget_2 = target;
|
|
701
704
|
if (!ref.contains(eventTarget_2)) {
|
|
702
705
|
closeDropdown();
|
|
703
706
|
}
|
|
704
707
|
};
|
|
705
|
-
const handleGlobalMouseUp = (
|
|
708
|
+
const handleGlobalMouseUp = (t212) => {
|
|
706
709
|
const {
|
|
707
710
|
target: target_0
|
|
708
|
-
} =
|
|
711
|
+
} = t212;
|
|
709
712
|
if (!isOpenRef.current || closingTimerRef.current) {
|
|
710
713
|
return;
|
|
711
714
|
}
|
|
@@ -722,10 +725,10 @@ function Dropdown(t0) {
|
|
|
722
725
|
closeDropdown();
|
|
723
726
|
}
|
|
724
727
|
};
|
|
725
|
-
const handleGlobalFocusIn = (
|
|
728
|
+
const handleGlobalFocusIn = (t222) => {
|
|
726
729
|
const {
|
|
727
730
|
target: target_1
|
|
728
|
-
} =
|
|
731
|
+
} = t222;
|
|
729
732
|
if (!isOpenRef.current) {
|
|
730
733
|
return;
|
|
731
734
|
}
|
|
@@ -758,14 +761,16 @@ function Dropdown(t0) {
|
|
|
758
761
|
}
|
|
759
762
|
setActiveItem({
|
|
760
763
|
dropdownElement: ref,
|
|
764
|
+
event: event_5,
|
|
761
765
|
isExactMatch: allowCreateRef.current,
|
|
766
|
+
onActiveItem,
|
|
762
767
|
text: enteredCharactersRef.current
|
|
763
768
|
});
|
|
764
769
|
};
|
|
765
770
|
if (inputElement) {
|
|
766
771
|
inputElement.addEventListener("input", handleInput);
|
|
767
772
|
}
|
|
768
|
-
|
|
773
|
+
return () => {
|
|
769
774
|
document.removeEventListener("focusin", handleGlobalFocusIn);
|
|
770
775
|
document.removeEventListener("mousedown", handleGlobalMouseDown);
|
|
771
776
|
document.removeEventListener("mouseup", handleGlobalMouseUp);
|
|
@@ -780,177 +785,177 @@ function Dropdown(t0) {
|
|
|
780
785
|
};
|
|
781
786
|
};
|
|
782
787
|
$[35] = isOpenOnMount;
|
|
783
|
-
$[36] =
|
|
784
|
-
$[37] =
|
|
788
|
+
$[36] = onActiveItem;
|
|
789
|
+
$[37] = t19;
|
|
785
790
|
} else {
|
|
786
|
-
|
|
791
|
+
t19 = $[37];
|
|
787
792
|
}
|
|
788
|
-
const handleRef =
|
|
789
|
-
if (!
|
|
793
|
+
const handleRef = t19;
|
|
794
|
+
if (!isValidElement(trigger)) {
|
|
790
795
|
if (isSearchable) {
|
|
791
|
-
const
|
|
792
|
-
let
|
|
796
|
+
const t202 = value ?? "";
|
|
797
|
+
let t212;
|
|
793
798
|
if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
|
|
794
|
-
|
|
795
|
-
$[38] =
|
|
799
|
+
t212 = () => setIsOpen(true);
|
|
800
|
+
$[38] = t212;
|
|
796
801
|
} else {
|
|
797
|
-
|
|
802
|
+
t212 = $[38];
|
|
798
803
|
}
|
|
799
|
-
let
|
|
800
|
-
if ($[39] !== disabled || $[40] !== name || $[41] !== placeholder || $[42] !==
|
|
801
|
-
|
|
804
|
+
let t222;
|
|
805
|
+
if ($[39] !== disabled || $[40] !== name || $[41] !== placeholder || $[42] !== t202 || $[43] !== tabIndex) {
|
|
806
|
+
t222 = /* @__PURE__ */ jsx("input", { autoComplete: "off", className: TRIGGER_CLASS_NAME, defaultValue: t202, disabled, name, onFocus: t212, placeholder, ref: inputElementRef, tabIndex, type: "text" });
|
|
802
807
|
$[39] = disabled;
|
|
803
808
|
$[40] = name;
|
|
804
809
|
$[41] = placeholder;
|
|
805
|
-
$[42] =
|
|
810
|
+
$[42] = t202;
|
|
806
811
|
$[43] = tabIndex;
|
|
807
|
-
$[44] =
|
|
812
|
+
$[44] = t222;
|
|
808
813
|
} else {
|
|
809
|
-
|
|
814
|
+
t222 = $[44];
|
|
810
815
|
}
|
|
811
|
-
trigger =
|
|
816
|
+
trigger = t222;
|
|
812
817
|
} else {
|
|
813
|
-
let
|
|
818
|
+
let t202;
|
|
814
819
|
if ($[45] !== trigger) {
|
|
815
|
-
|
|
820
|
+
t202 = /* @__PURE__ */ jsx("button", { className: TRIGGER_CLASS_NAME, tabIndex: 0, type: "button", children: trigger });
|
|
816
821
|
$[45] = trigger;
|
|
817
|
-
$[46] =
|
|
822
|
+
$[46] = t202;
|
|
818
823
|
} else {
|
|
819
|
-
|
|
824
|
+
t202 = $[46];
|
|
820
825
|
}
|
|
821
|
-
trigger =
|
|
826
|
+
trigger = t202;
|
|
822
827
|
}
|
|
823
828
|
}
|
|
824
829
|
if (label) {
|
|
825
|
-
let
|
|
830
|
+
let t202;
|
|
826
831
|
if ($[47] !== label) {
|
|
827
|
-
|
|
832
|
+
t202 = /* @__PURE__ */ jsx("div", { className: LABEL_TEXT_CLASS_NAME, children: label });
|
|
828
833
|
$[47] = label;
|
|
829
|
-
$[48] =
|
|
834
|
+
$[48] = t202;
|
|
830
835
|
} else {
|
|
831
|
-
|
|
836
|
+
t202 = $[48];
|
|
832
837
|
}
|
|
833
|
-
let
|
|
834
|
-
if ($[49] !==
|
|
835
|
-
|
|
836
|
-
|
|
838
|
+
let t212;
|
|
839
|
+
if ($[49] !== t202 || $[50] !== trigger) {
|
|
840
|
+
t212 = /* @__PURE__ */ jsxs("label", { className: LABEL_CLASS_NAME, children: [
|
|
841
|
+
t202,
|
|
837
842
|
trigger
|
|
838
843
|
] });
|
|
839
|
-
$[49] =
|
|
844
|
+
$[49] = t202;
|
|
840
845
|
$[50] = trigger;
|
|
841
|
-
$[51] =
|
|
846
|
+
$[51] = t212;
|
|
842
847
|
} else {
|
|
843
|
-
|
|
848
|
+
t212 = $[51];
|
|
844
849
|
}
|
|
845
|
-
trigger =
|
|
850
|
+
trigger = t212;
|
|
846
851
|
}
|
|
847
852
|
const dropdownRect = useBoundingClientRect(dropdownElement);
|
|
848
853
|
const dropdownBodyRect = useBoundingClientRect(dropdownBodyElement);
|
|
849
|
-
let
|
|
854
|
+
let t20;
|
|
850
855
|
if ($[52] !== dropdownBodyElement) {
|
|
851
|
-
|
|
856
|
+
t20 = getBoundingAncestor(dropdownBodyElement);
|
|
852
857
|
$[52] = dropdownBodyElement;
|
|
853
|
-
$[53] =
|
|
858
|
+
$[53] = t20;
|
|
854
859
|
} else {
|
|
855
|
-
|
|
860
|
+
t20 = $[53];
|
|
856
861
|
}
|
|
857
|
-
const boundingElement =
|
|
862
|
+
const boundingElement = t20;
|
|
858
863
|
const boundingElementRect = useBoundingClientRect(boundingElement);
|
|
859
864
|
let maxHeight;
|
|
860
865
|
let maxWidth;
|
|
861
866
|
if (dropdownBodyRect.top != null && dropdownRect.top != null && boundingElementRect.top != null) {
|
|
862
867
|
const maxHeightUp = dropdownBodyRect.bottom - boundingElementRect.top;
|
|
863
868
|
const maxHeightDown = boundingElementRect.bottom - dropdownBodyRect.top;
|
|
864
|
-
let
|
|
869
|
+
let t212;
|
|
865
870
|
if ($[54] !== dropdownBodyRect.top || $[55] !== dropdownRect.top || $[56] !== maxHeightDown || $[57] !== maxHeightUp) {
|
|
866
|
-
|
|
871
|
+
t212 = Math.round(dropdownBodyRect.top > dropdownRect.top ? maxHeightDown : maxHeightUp);
|
|
867
872
|
$[54] = dropdownBodyRect.top;
|
|
868
873
|
$[55] = dropdownRect.top;
|
|
869
874
|
$[56] = maxHeightDown;
|
|
870
875
|
$[57] = maxHeightUp;
|
|
871
|
-
$[58] =
|
|
876
|
+
$[58] = t212;
|
|
872
877
|
} else {
|
|
873
|
-
|
|
878
|
+
t212 = $[58];
|
|
874
879
|
}
|
|
875
|
-
maxHeight =
|
|
880
|
+
maxHeight = t212;
|
|
876
881
|
const maxWidthLeft = dropdownBodyRect.right - boundingElementRect.left;
|
|
877
882
|
const maxWidthRight = boundingElementRect.right - dropdownBodyRect.left;
|
|
878
|
-
let
|
|
883
|
+
let t222;
|
|
879
884
|
if ($[59] !== dropdownBodyRect.left || $[60] !== dropdownRect.left || $[61] !== maxWidthLeft || $[62] !== maxWidthRight) {
|
|
880
|
-
|
|
885
|
+
t222 = Math.round(dropdownBodyRect.left > dropdownRect.left ? maxWidthRight : maxWidthLeft);
|
|
881
886
|
$[59] = dropdownBodyRect.left;
|
|
882
887
|
$[60] = dropdownRect.left;
|
|
883
888
|
$[61] = maxWidthLeft;
|
|
884
889
|
$[62] = maxWidthRight;
|
|
885
|
-
$[63] =
|
|
890
|
+
$[63] = t222;
|
|
886
891
|
} else {
|
|
887
|
-
|
|
892
|
+
t222 = $[63];
|
|
888
893
|
}
|
|
889
|
-
maxWidth =
|
|
894
|
+
maxWidth = t222;
|
|
890
895
|
}
|
|
891
|
-
let
|
|
896
|
+
let t21;
|
|
892
897
|
if ($[64] !== maxHeight || $[65] !== minHeightBody) {
|
|
893
|
-
|
|
898
|
+
t21 = maxHeight != null && maxHeight > minHeightBody ? {
|
|
894
899
|
[BODY_MAX_HEIGHT_VAR]: `calc(${maxHeight}px - var(--uktdd-body-buffer))`
|
|
895
900
|
} : null;
|
|
896
901
|
$[64] = maxHeight;
|
|
897
902
|
$[65] = minHeightBody;
|
|
898
|
-
$[66] =
|
|
903
|
+
$[66] = t21;
|
|
899
904
|
} else {
|
|
900
|
-
|
|
905
|
+
t21 = $[66];
|
|
901
906
|
}
|
|
902
|
-
let
|
|
907
|
+
let t22;
|
|
903
908
|
if ($[67] !== maxWidth || $[68] !== minWidthBody) {
|
|
904
|
-
|
|
909
|
+
t22 = maxWidth != null && maxWidth > minWidthBody ? {
|
|
905
910
|
[BODY_MAX_WIDTH_VAR]: `calc(${maxWidth}px - var(--uktdd-body-buffer))`
|
|
906
911
|
} : null;
|
|
907
912
|
$[67] = maxWidth;
|
|
908
913
|
$[68] = minWidthBody;
|
|
909
|
-
$[69] =
|
|
914
|
+
$[69] = t22;
|
|
910
915
|
} else {
|
|
911
|
-
|
|
916
|
+
t22 = $[69];
|
|
912
917
|
}
|
|
913
|
-
let
|
|
914
|
-
if ($[70] !== styleFromProps || $[71] !==
|
|
915
|
-
|
|
918
|
+
let t23;
|
|
919
|
+
if ($[70] !== styleFromProps || $[71] !== t21 || $[72] !== t22) {
|
|
920
|
+
t23 = {
|
|
916
921
|
...styleFromProps,
|
|
917
|
-
...
|
|
918
|
-
...
|
|
922
|
+
...t21,
|
|
923
|
+
...t22
|
|
919
924
|
};
|
|
920
925
|
$[70] = styleFromProps;
|
|
921
|
-
$[71] =
|
|
922
|
-
$[72] =
|
|
923
|
-
$[73] =
|
|
926
|
+
$[71] = t21;
|
|
927
|
+
$[72] = t22;
|
|
928
|
+
$[73] = t23;
|
|
924
929
|
} else {
|
|
925
|
-
|
|
930
|
+
t23 = $[73];
|
|
926
931
|
}
|
|
927
|
-
const style =
|
|
932
|
+
const style = t23;
|
|
928
933
|
const anchorStyles = `[data-ukt-id="${id}"] > :first-child {
|
|
929
934
|
anchor-name: --uktdd-anchor${id};
|
|
930
935
|
}
|
|
931
936
|
[data-ukt-id="${id}"] ${BODY_SELECTOR} {
|
|
932
937
|
position-anchor: --uktdd-anchor${id};
|
|
933
938
|
}`;
|
|
934
|
-
let
|
|
939
|
+
let t24;
|
|
935
940
|
if ($[74] === Symbol.for("react.memo_cache_sentinel")) {
|
|
936
|
-
|
|
937
|
-
$[74] =
|
|
941
|
+
t24 = /* @__PURE__ */ jsx(Style, { href: "@acusti/dropdown/Dropdown", children: STYLES });
|
|
942
|
+
$[74] = t24;
|
|
938
943
|
} else {
|
|
939
|
-
|
|
944
|
+
t24 = $[74];
|
|
940
945
|
}
|
|
941
|
-
const
|
|
942
|
-
let
|
|
943
|
-
if ($[75] !== anchorStyles || $[76] !==
|
|
944
|
-
|
|
946
|
+
const t25 = `@acusti/dropdown/Dropdown/${id}`;
|
|
947
|
+
let t26;
|
|
948
|
+
if ($[75] !== anchorStyles || $[76] !== t25) {
|
|
949
|
+
t26 = /* @__PURE__ */ jsx(Style, { href: t25, children: anchorStyles });
|
|
945
950
|
$[75] = anchorStyles;
|
|
946
|
-
$[76] =
|
|
947
|
-
$[77] =
|
|
951
|
+
$[76] = t25;
|
|
952
|
+
$[77] = t26;
|
|
948
953
|
} else {
|
|
949
|
-
|
|
954
|
+
t26 = $[77];
|
|
950
955
|
}
|
|
951
|
-
let
|
|
956
|
+
let t27;
|
|
952
957
|
if ($[78] !== className || $[79] !== disabled || $[80] !== isOpen || $[81] !== isSearchable) {
|
|
953
|
-
|
|
958
|
+
t27 = clsx(ROOT_CLASS_NAME, className, {
|
|
954
959
|
disabled,
|
|
955
960
|
"is-open": isOpen,
|
|
956
961
|
"is-searchable": isSearchable
|
|
@@ -959,25 +964,25 @@ function Dropdown(t0) {
|
|
|
959
964
|
$[79] = disabled;
|
|
960
965
|
$[80] = isOpen;
|
|
961
966
|
$[81] = isSearchable;
|
|
962
|
-
$[82] =
|
|
967
|
+
$[82] = t27;
|
|
963
968
|
} else {
|
|
964
|
-
|
|
969
|
+
t27 = $[82];
|
|
965
970
|
}
|
|
966
|
-
let
|
|
971
|
+
let t28;
|
|
967
972
|
if ($[83] !== children || $[84] !== childrenCount || $[85] !== isOpen) {
|
|
968
|
-
|
|
973
|
+
t28 = isOpen ? /* @__PURE__ */ jsx("div", { className: BODY_CLASS_NAME, ref: setDropdownBodyElement, children: childrenCount > 1 ? children[1] : children }) : null;
|
|
969
974
|
$[83] = children;
|
|
970
975
|
$[84] = childrenCount;
|
|
971
976
|
$[85] = isOpen;
|
|
972
|
-
$[86] =
|
|
977
|
+
$[86] = t28;
|
|
973
978
|
} else {
|
|
974
|
-
|
|
979
|
+
t28 = $[86];
|
|
975
980
|
}
|
|
976
|
-
let
|
|
977
|
-
if ($[87] !== handleMouseDown || $[88] !== handleMouseOut || $[89] !== handleMouseOver || $[90] !== handleMouseUp || $[91] !== handleRef || $[92] !== id || $[93] !== onClick || $[94] !== style || $[95] !==
|
|
978
|
-
|
|
981
|
+
let t29;
|
|
982
|
+
if ($[87] !== handleMouseDown || $[88] !== handleMouseOut || $[89] !== handleMouseOver || $[90] !== handleMouseUp || $[91] !== handleRef || $[92] !== id || $[93] !== onClick || $[94] !== style || $[95] !== t27 || $[96] !== t28 || $[97] !== trigger) {
|
|
983
|
+
t29 = /* @__PURE__ */ jsxs("div", { className: t27, "data-ukt-id": id, onClick, onMouseDown: handleMouseDown, onMouseMove: handleMouseMove, onMouseOut: handleMouseOut, onMouseOver: handleMouseOver, onMouseUp: handleMouseUp, ref: handleRef, style, children: [
|
|
979
984
|
trigger,
|
|
980
|
-
|
|
985
|
+
t28
|
|
981
986
|
] });
|
|
982
987
|
$[87] = handleMouseDown;
|
|
983
988
|
$[88] = handleMouseOut;
|
|
@@ -987,34 +992,30 @@ function Dropdown(t0) {
|
|
|
987
992
|
$[92] = id;
|
|
988
993
|
$[93] = onClick;
|
|
989
994
|
$[94] = style;
|
|
990
|
-
$[95] =
|
|
991
|
-
$[96] =
|
|
995
|
+
$[95] = t27;
|
|
996
|
+
$[96] = t28;
|
|
992
997
|
$[97] = trigger;
|
|
993
|
-
$[98] =
|
|
998
|
+
$[98] = t29;
|
|
994
999
|
} else {
|
|
995
|
-
|
|
1000
|
+
t29 = $[98];
|
|
996
1001
|
}
|
|
997
|
-
let
|
|
998
|
-
if ($[99] !==
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1002
|
+
let t30;
|
|
1003
|
+
if ($[99] !== t26 || $[100] !== t29) {
|
|
1004
|
+
t30 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1005
|
+
t24,
|
|
1006
|
+
t26,
|
|
1007
|
+
t29
|
|
1003
1008
|
] });
|
|
1004
|
-
$[99] =
|
|
1005
|
-
$[100] =
|
|
1006
|
-
$[101] =
|
|
1009
|
+
$[99] = t26;
|
|
1010
|
+
$[100] = t29;
|
|
1011
|
+
$[101] = t30;
|
|
1007
1012
|
} else {
|
|
1008
|
-
|
|
1013
|
+
t30 = $[101];
|
|
1009
1014
|
}
|
|
1010
|
-
return
|
|
1011
|
-
}
|
|
1012
|
-
function _temp() {
|
|
1013
|
-
idCounter = idCounter >= 999999 ? 0 : idCounter + 1;
|
|
1014
|
-
return idCounter;
|
|
1015
|
+
return t30;
|
|
1015
1016
|
}
|
|
1016
1017
|
function getBoundingAncestor(element) {
|
|
1017
|
-
while (element
|
|
1018
|
+
while (element?.parentElement) {
|
|
1018
1019
|
if (element.parentElement.tagName === "BODY") return element.parentElement;
|
|
1019
1020
|
if (getComputedStyle(element.parentElement).overflowX !== "visible") {
|
|
1020
1021
|
return element.parentElement;
|