@smilodon/react 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPLETE-GUIDE.md +67 -0
- package/README.md +142 -0
- package/dist/index.cjs +274 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +274 -265
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +19 -4
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import React, { forwardRef, useState, useRef, useMemo, useCallback, useEffect, useImperativeHandle } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
5
6
|
import { configureSelect, resetSelectConfig, selectConfig } from "@smilodon/core";
|
|
6
7
|
const DEFAULT_DATA_LOADING_CONFIG = {
|
|
7
8
|
protocol: "legacy",
|
|
@@ -16,6 +17,64 @@ function isPlainRecord(value) {
|
|
|
16
17
|
const prototype = Object.getPrototypeOf(value);
|
|
17
18
|
return prototype === Object.prototype || prototype === null;
|
|
18
19
|
}
|
|
20
|
+
function areSemanticallyEqual(left, right, seen = /* @__PURE__ */ new WeakMap()) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (Object.is(left, right)) return true;
|
|
23
|
+
if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const leftArray = Array.isArray(left);
|
|
27
|
+
const rightArray = Array.isArray(right);
|
|
28
|
+
if (leftArray !== rightArray) return false;
|
|
29
|
+
if (!leftArray && (!isPlainRecord(left) || !isPlainRecord(right))) return false;
|
|
30
|
+
if (leftArray && !Array.isArray(right)) return false;
|
|
31
|
+
if (leftArray && rightArray && left.length !== right.length) return false;
|
|
32
|
+
const leftPrototype = Object.getPrototypeOf(left);
|
|
33
|
+
const rightPrototype = Object.getPrototypeOf(right);
|
|
34
|
+
if (leftPrototype !== rightPrototype && !(isPlainRecord(left) && isPlainRecord(right))) return false;
|
|
35
|
+
const prior = (_a = seen.get(left)) == null ? void 0 : _a.get(right);
|
|
36
|
+
if (prior !== void 0) return prior;
|
|
37
|
+
let rightPairs = seen.get(left);
|
|
38
|
+
if (!rightPairs) {
|
|
39
|
+
rightPairs = /* @__PURE__ */ new WeakMap();
|
|
40
|
+
seen.set(left, rightPairs);
|
|
41
|
+
}
|
|
42
|
+
rightPairs.set(right, true);
|
|
43
|
+
const enumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => {
|
|
44
|
+
var _a2;
|
|
45
|
+
return (_a2 = Object.getOwnPropertyDescriptor(value, key)) == null ? void 0 : _a2.enumerable;
|
|
46
|
+
});
|
|
47
|
+
const leftKeys = enumerableKeys(left);
|
|
48
|
+
const rightKeys = enumerableKeys(right);
|
|
49
|
+
const rightKeySet = new Set(rightKeys);
|
|
50
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
51
|
+
rightPairs.set(right, false);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (const key of leftKeys) {
|
|
55
|
+
if (!rightKeySet.has(key)) {
|
|
56
|
+
rightPairs.set(right, false);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const leftDescriptor = Object.getOwnPropertyDescriptor(left, key);
|
|
60
|
+
const rightDescriptor = Object.getOwnPropertyDescriptor(right, key);
|
|
61
|
+
if ("value" in leftDescriptor !== "value" in rightDescriptor) {
|
|
62
|
+
rightPairs.set(right, false);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if ("value" in leftDescriptor) {
|
|
66
|
+
if (!areSemanticallyEqual(leftDescriptor.value, rightDescriptor.value, seen)) {
|
|
67
|
+
rightPairs.set(right, false);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
} else if (leftDescriptor.get !== rightDescriptor.get || leftDescriptor.set !== rightDescriptor.set) {
|
|
71
|
+
rightPairs.set(right, false);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const EMPTY_ITEMS = [];
|
|
19
78
|
function isBusyToken(value) {
|
|
20
79
|
return value === true || value === "true";
|
|
21
80
|
}
|
|
@@ -25,9 +84,9 @@ function composeBusyToken(consumerValue, externalBusy) {
|
|
|
25
84
|
return consumerValue;
|
|
26
85
|
}
|
|
27
86
|
const Select = forwardRef((props, ref) => {
|
|
28
|
-
var _a, _b;
|
|
87
|
+
var _a, _b, _c;
|
|
29
88
|
const {
|
|
30
|
-
items =
|
|
89
|
+
items = EMPTY_ITEMS,
|
|
31
90
|
groupedItems,
|
|
32
91
|
value,
|
|
33
92
|
defaultValue,
|
|
@@ -50,6 +109,9 @@ const Select = forwardRef((props, ref) => {
|
|
|
50
109
|
config: coreConfig,
|
|
51
110
|
removeButtonIcon,
|
|
52
111
|
arrowIcon,
|
|
112
|
+
loadingIcon,
|
|
113
|
+
loadingContent,
|
|
114
|
+
emptyStateRenderer,
|
|
53
115
|
disabledOptionBehavior,
|
|
54
116
|
showSelectedIndicator = true,
|
|
55
117
|
toggleOnTriggerClick = true,
|
|
@@ -77,6 +139,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
77
139
|
onDataRequestCancel,
|
|
78
140
|
onDataProjection,
|
|
79
141
|
onDataLoadingConfigError,
|
|
142
|
+
onEmptyStateChange,
|
|
80
143
|
trackingEnabled = false,
|
|
81
144
|
trackEvents = true,
|
|
82
145
|
trackStyling = true,
|
|
@@ -118,6 +181,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
118
181
|
onDataRequestCancel,
|
|
119
182
|
onDataProjection,
|
|
120
183
|
onDataLoadingConfigError,
|
|
184
|
+
onEmptyStateChange,
|
|
121
185
|
isControlled,
|
|
122
186
|
multiple
|
|
123
187
|
});
|
|
@@ -133,6 +197,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
133
197
|
onDataRequestCancel,
|
|
134
198
|
onDataProjection,
|
|
135
199
|
onDataLoadingConfigError,
|
|
200
|
+
onEmptyStateChange,
|
|
136
201
|
isControlled,
|
|
137
202
|
multiple
|
|
138
203
|
};
|
|
@@ -279,7 +344,10 @@ const Select = forwardRef((props, ref) => {
|
|
|
279
344
|
reactRendererCache.current.clear();
|
|
280
345
|
}, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
|
|
281
346
|
const [isElementReady, setIsElementReady] = useState(false);
|
|
282
|
-
const
|
|
347
|
+
const [emptyStateContext, setEmptyStateContext] = useState(null);
|
|
348
|
+
const [removeIconTargets, setRemoveIconTargets] = useState([]);
|
|
349
|
+
const shouldPortalRemoveIcon = multiple && removeButtonIcon != null && typeof removeButtonIcon !== "string" && typeof removeButtonIcon !== "boolean" && ((_a = coreConfig == null ? void 0 : coreConfig.selection) == null ? void 0 : _a.removeButtonIcon) === void 0;
|
|
350
|
+
const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
|
|
283
351
|
const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
|
|
284
352
|
const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
|
|
285
353
|
const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
|
|
@@ -386,7 +454,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
386
454
|
},
|
|
387
455
|
[markUnusable, syncHostBusy]
|
|
388
456
|
);
|
|
389
|
-
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((
|
|
457
|
+
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_c = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _c.protocol) === "acknowledged";
|
|
390
458
|
const qualifyAcknowledgedElement = useCallback(() => {
|
|
391
459
|
const element = elementRef.current;
|
|
392
460
|
const module = coreModuleRef.current;
|
|
@@ -404,16 +472,17 @@ const Select = forwardRef((props, ref) => {
|
|
|
404
472
|
return true;
|
|
405
473
|
}, [markUnusable]);
|
|
406
474
|
const subscribeToCoreEvents = useCallback((element) => {
|
|
475
|
+
var _a2;
|
|
407
476
|
const currentSubscription = activeListenersRef.current;
|
|
408
477
|
if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
|
|
409
478
|
currentSubscription == null ? void 0 : currentSubscription.dispose();
|
|
410
479
|
const handleSelect = (event) => {
|
|
411
|
-
var
|
|
480
|
+
var _a3, _b2;
|
|
412
481
|
const detail = event.detail;
|
|
413
|
-
(_b2 = (
|
|
482
|
+
(_b2 = (_a3 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a3, detail.item, detail.index);
|
|
414
483
|
};
|
|
415
484
|
const handleChange = (event) => {
|
|
416
|
-
var
|
|
485
|
+
var _a3;
|
|
417
486
|
const { selectedItems, selectedValues } = event.detail;
|
|
418
487
|
const callbacks = callbackStateRef.current;
|
|
419
488
|
const values = selectedValues;
|
|
@@ -422,19 +491,19 @@ const Select = forwardRef((props, ref) => {
|
|
|
422
491
|
if (!callbacks.isControlled) {
|
|
423
492
|
setInternalValue(callbacks.multiple ? values : nextSingleValue);
|
|
424
493
|
}
|
|
425
|
-
(
|
|
494
|
+
(_a3 = callbacks.onChange) == null ? void 0 : _a3.call(
|
|
426
495
|
callbacks,
|
|
427
496
|
callbacks.multiple ? values : nextSingleValue,
|
|
428
497
|
selectedItems
|
|
429
498
|
);
|
|
430
499
|
};
|
|
431
500
|
const handleOpen = () => {
|
|
432
|
-
var
|
|
433
|
-
return (_b2 = (
|
|
501
|
+
var _a3, _b2;
|
|
502
|
+
return (_b2 = (_a3 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a3);
|
|
434
503
|
};
|
|
435
504
|
const handleClose = () => {
|
|
436
|
-
var
|
|
437
|
-
return (_b2 = (
|
|
505
|
+
var _a3, _b2;
|
|
506
|
+
return (_b2 = (_a3 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a3);
|
|
438
507
|
};
|
|
439
508
|
const handleSearch = (event) => {
|
|
440
509
|
const { query, results, count, request } = event.detail;
|
|
@@ -451,40 +520,46 @@ const Select = forwardRef((props, ref) => {
|
|
|
451
520
|
else callback(page);
|
|
452
521
|
};
|
|
453
522
|
const handleClear = (event) => {
|
|
454
|
-
var
|
|
523
|
+
var _a3, _b2;
|
|
455
524
|
const { clearedSelection, clearedSearch } = event.detail;
|
|
456
|
-
(_b2 = (
|
|
525
|
+
(_b2 = (_a3 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a3, { clearedSelection, clearedSearch });
|
|
457
526
|
};
|
|
458
527
|
const handleDiagnostic = (event) => {
|
|
459
|
-
var
|
|
460
|
-
(_b2 = (
|
|
461
|
-
|
|
528
|
+
var _a3, _b2;
|
|
529
|
+
(_b2 = (_a3 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
|
|
530
|
+
_a3,
|
|
462
531
|
event.detail
|
|
463
532
|
);
|
|
464
533
|
};
|
|
465
534
|
const handleDataRequestCancel = (event) => {
|
|
466
|
-
var
|
|
467
|
-
(_b2 = (
|
|
468
|
-
|
|
535
|
+
var _a3, _b2;
|
|
536
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
|
|
537
|
+
_a3,
|
|
469
538
|
event.detail
|
|
470
539
|
);
|
|
471
540
|
};
|
|
472
541
|
const handleDataProjection = (event) => {
|
|
473
|
-
var
|
|
474
|
-
(_b2 = (
|
|
475
|
-
|
|
542
|
+
var _a3, _b2;
|
|
543
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
|
|
544
|
+
_a3,
|
|
476
545
|
event.detail
|
|
477
546
|
);
|
|
478
547
|
};
|
|
479
548
|
const handleDataLoadingConfigError = (event) => {
|
|
480
|
-
var
|
|
549
|
+
var _a3, _b2;
|
|
481
550
|
const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
|
|
482
551
|
if (activeUpdate) activeUpdate.sawConfigError = true;
|
|
483
|
-
(_b2 = (
|
|
484
|
-
|
|
552
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
|
|
553
|
+
_a3,
|
|
485
554
|
event.detail
|
|
486
555
|
);
|
|
487
556
|
};
|
|
557
|
+
const handleEmptyStateChange = (event) => {
|
|
558
|
+
var _a3, _b2;
|
|
559
|
+
const context = event.detail.context;
|
|
560
|
+
setEmptyStateContext(context);
|
|
561
|
+
(_b2 = (_a3 = callbackStateRef.current).onEmptyStateChange) == null ? void 0 : _b2.call(_a3, context);
|
|
562
|
+
};
|
|
488
563
|
const listeners = [
|
|
489
564
|
["select", handleSelect],
|
|
490
565
|
["change", handleChange],
|
|
@@ -496,14 +571,18 @@ const Select = forwardRef((props, ref) => {
|
|
|
496
571
|
["diagnostic", handleDiagnostic],
|
|
497
572
|
["dataRequestCancel", handleDataRequestCancel],
|
|
498
573
|
["dataProjection", handleDataProjection],
|
|
499
|
-
["dataLoadingConfigError", handleDataLoadingConfigError]
|
|
574
|
+
["dataLoadingConfigError", handleDataLoadingConfigError],
|
|
575
|
+
["emptyStateChange", handleEmptyStateChange]
|
|
500
576
|
];
|
|
501
577
|
for (const [name, listener] of listeners) {
|
|
502
578
|
element.addEventListener(name, listener);
|
|
503
579
|
}
|
|
580
|
+
setEmptyStateContext(
|
|
581
|
+
((_a2 = element.getEmptyStateContext) == null ? void 0 : _a2.call(element)) ?? null
|
|
582
|
+
);
|
|
504
583
|
const dispose = () => {
|
|
505
|
-
var
|
|
506
|
-
if (((
|
|
584
|
+
var _a3;
|
|
585
|
+
if (((_a3 = activeListenersRef.current) == null ? void 0 : _a3.dispose) === dispose) {
|
|
507
586
|
activeListenersRef.current = null;
|
|
508
587
|
}
|
|
509
588
|
for (const [name, listener] of listeners) {
|
|
@@ -594,156 +673,108 @@ const Select = forwardRef((props, ref) => {
|
|
|
594
673
|
return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
|
|
595
674
|
};
|
|
596
675
|
}, []);
|
|
597
|
-
|
|
598
|
-
var _a2;
|
|
599
|
-
const element = elementRef.current;
|
|
600
|
-
if (!element || !isElementUsable) return;
|
|
601
|
-
if (!element.setItems) {
|
|
602
|
-
console.warn("Enhanced select element not fully initialized yet");
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
if (groupedItems) {
|
|
606
|
-
element.setGroupedItems(groupedItems);
|
|
607
|
-
} else if (items.length > 0) {
|
|
608
|
-
element.setItems(items);
|
|
609
|
-
}
|
|
610
|
-
const config = {
|
|
611
|
-
searchable,
|
|
612
|
-
placeholder,
|
|
613
|
-
virtualize: virtualized,
|
|
614
|
-
estimatedItemHeight,
|
|
615
|
-
enabled: !disabled,
|
|
616
|
-
dropdownPlacement: {
|
|
617
|
-
mode: resolvedDropdownPlacement
|
|
618
|
-
},
|
|
619
|
-
selection: {
|
|
620
|
-
...selectionConfig,
|
|
621
|
-
mode: multiple ? "multi" : "single",
|
|
622
|
-
maxSelections,
|
|
623
|
-
removeButtonIcon,
|
|
624
|
-
disabledOptionBehavior,
|
|
625
|
-
showSelectedIndicator,
|
|
626
|
-
toggleOnTriggerClick
|
|
627
|
-
},
|
|
628
|
-
direction,
|
|
629
|
-
multiSelectDisplay,
|
|
630
|
-
infiniteScroll: {
|
|
631
|
-
enabled: infiniteScroll,
|
|
632
|
-
pageSize
|
|
633
|
-
},
|
|
634
|
-
scrollToSelected: {
|
|
635
|
-
enabled: true,
|
|
636
|
-
...scrollToSelected
|
|
637
|
-
},
|
|
638
|
-
creatable,
|
|
639
|
-
styles: stylesConfig,
|
|
640
|
-
clearControl: {
|
|
641
|
-
enabled: clearable,
|
|
642
|
-
clearSelection: clearSelectionOnClear,
|
|
643
|
-
clearSearch: clearSearchOnClear,
|
|
644
|
-
ariaLabel: clearAriaLabel,
|
|
645
|
-
icon: clearIcon
|
|
646
|
-
},
|
|
647
|
-
tracking: {
|
|
648
|
-
enabled: trackingEnabled,
|
|
649
|
-
events: trackEvents,
|
|
650
|
-
styling: trackStyling,
|
|
651
|
-
limitations: trackLimitations,
|
|
652
|
-
emitDiagnostics,
|
|
653
|
-
maxEntries: trackingMaxEntries
|
|
654
|
-
},
|
|
655
|
-
limitations: {
|
|
656
|
-
policies: limitationPolicies,
|
|
657
|
-
autoMitigateRuntimeModeSwitch
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
applyInstanceConfig(element, config);
|
|
661
|
-
if (coreConfig) {
|
|
662
|
-
applyInstanceConfig(element, coreConfig);
|
|
663
|
-
}
|
|
664
|
-
if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
|
|
665
|
-
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
666
|
-
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
667
|
-
if (!areValuesEqual(values, currentValues)) {
|
|
668
|
-
element.setSelectedValues(values);
|
|
669
|
-
}
|
|
670
|
-
hasAppliedInitialValueRef.current = true;
|
|
671
|
-
}
|
|
672
|
-
if (error) {
|
|
673
|
-
element.setError(errorMessage || "Invalid selection");
|
|
674
|
-
} else {
|
|
675
|
-
element.clearError();
|
|
676
|
-
}
|
|
677
|
-
if (required) {
|
|
678
|
-
element.setRequired(true);
|
|
679
|
-
}
|
|
680
|
-
}, [
|
|
681
|
-
isElementUsable,
|
|
682
|
-
items,
|
|
683
|
-
groupedItems,
|
|
676
|
+
const componentConfig = {
|
|
684
677
|
searchable,
|
|
685
678
|
placeholder,
|
|
686
|
-
virtualized,
|
|
679
|
+
virtualize: virtualized,
|
|
687
680
|
estimatedItemHeight,
|
|
688
|
-
disabled,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
681
|
+
enabled: !disabled,
|
|
682
|
+
dropdownPlacement: { mode: resolvedDropdownPlacement },
|
|
683
|
+
selection: {
|
|
684
|
+
...selectionConfig,
|
|
685
|
+
mode: multiple ? "multi" : "single",
|
|
686
|
+
maxSelections,
|
|
687
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
688
|
+
disabledOptionBehavior,
|
|
689
|
+
showSelectedIndicator,
|
|
690
|
+
toggleOnTriggerClick
|
|
691
|
+
},
|
|
692
|
+
direction,
|
|
692
693
|
multiSelectDisplay,
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
coreConfig,
|
|
696
|
-
removeButtonIcon,
|
|
697
|
-
disabledOptionBehavior,
|
|
698
|
-
showSelectedIndicator,
|
|
699
|
-
toggleOnTriggerClick,
|
|
700
|
-
infiniteScroll,
|
|
701
|
-
pageSize,
|
|
694
|
+
infiniteScroll: { enabled: infiniteScroll, pageSize },
|
|
695
|
+
scrollToSelected: { enabled: true, ...scrollToSelected },
|
|
702
696
|
creatable,
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
697
|
+
styles: stylesConfig,
|
|
698
|
+
clearControl: {
|
|
699
|
+
enabled: clearable,
|
|
700
|
+
clearSelection: clearSelectionOnClear,
|
|
701
|
+
clearSearch: clearSearchOnClear,
|
|
702
|
+
ariaLabel: clearAriaLabel,
|
|
703
|
+
icon: clearIcon
|
|
704
|
+
},
|
|
705
|
+
tracking: {
|
|
706
|
+
enabled: trackingEnabled,
|
|
707
|
+
events: trackEvents,
|
|
708
|
+
styling: trackStyling,
|
|
709
|
+
limitations: trackLimitations,
|
|
710
|
+
emitDiagnostics,
|
|
711
|
+
maxEntries: trackingMaxEntries
|
|
712
|
+
},
|
|
713
|
+
limitations: { policies: limitationPolicies, autoMitigateRuntimeModeSwitch }
|
|
714
|
+
};
|
|
715
|
+
const configCandidate = { component: componentConfig, core: coreConfig };
|
|
716
|
+
const appliedConfigRef = useRef({ hasComponent: false, component: null, hasCore: false, core: void 0 });
|
|
717
|
+
useEffect(() => {
|
|
718
|
+
const element = elementRef.current;
|
|
719
|
+
if (!element || !isElementUsable || !element.updateConfig) return;
|
|
720
|
+
const previous = appliedConfigRef.current;
|
|
721
|
+
const componentChanged = !previous.hasComponent || !areSemanticallyEqual(previous.component, configCandidate.component);
|
|
722
|
+
const coreChanged = !previous.hasCore || !areSemanticallyEqual(previous.core, configCandidate.core);
|
|
723
|
+
if (!componentChanged && !coreChanged) return;
|
|
724
|
+
if (componentChanged) {
|
|
725
|
+
applyInstanceConfig(element, configCandidate.component);
|
|
726
|
+
if (configCandidate.core) applyInstanceConfig(element, configCandidate.core);
|
|
727
|
+
} else if (coreChanged) {
|
|
728
|
+
if (configCandidate.core) {
|
|
729
|
+
applyInstanceConfig(element, configCandidate.core);
|
|
730
|
+
} else {
|
|
731
|
+
applyInstanceConfig(element, configCandidate.component);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
appliedConfigRef.current = {
|
|
735
|
+
hasComponent: true,
|
|
736
|
+
component: configCandidate.component,
|
|
737
|
+
hasCore: true,
|
|
738
|
+
core: configCandidate.core
|
|
739
|
+
};
|
|
740
|
+
});
|
|
741
|
+
const sourceCandidate = groupedItems !== void 0 ? { kind: "grouped", data: groupedItems } : { kind: "items", data: items };
|
|
742
|
+
const synchronizedSourceRef = useRef(null);
|
|
726
743
|
useEffect(() => {
|
|
744
|
+
var _a2;
|
|
727
745
|
const element = elementRef.current;
|
|
728
746
|
if (!element || !isElementUsable || !element.setItems) return;
|
|
729
|
-
if (
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
const map = /* @__PURE__ */ new Map();
|
|
733
|
-
items.forEach((it) => {
|
|
734
|
-
const g = it.group ?? "Ungrouped";
|
|
735
|
-
if (!map.has(g)) map.set(g, []);
|
|
736
|
-
map.get(g).push(it);
|
|
737
|
-
});
|
|
738
|
-
const groups = Array.from(map.entries()).map(([label, options]) => ({
|
|
739
|
-
label,
|
|
740
|
-
options
|
|
741
|
-
}));
|
|
742
|
-
element.setGroupedItems(groups);
|
|
747
|
+
if (areSemanticallyEqual(synchronizedSourceRef.current, sourceCandidate)) return;
|
|
748
|
+
if (sourceCandidate.kind === "grouped") {
|
|
749
|
+
element.setGroupedItems(sourceCandidate.data);
|
|
743
750
|
} else {
|
|
744
|
-
|
|
751
|
+
const sourceItems = sourceCandidate.data;
|
|
752
|
+
if (sourceItems.length > 0 && ((_a2 = sourceItems[0]) == null ? void 0 : _a2.group) !== void 0) {
|
|
753
|
+
const groups = /* @__PURE__ */ new Map();
|
|
754
|
+
sourceItems.forEach((item) => {
|
|
755
|
+
const label = item.group ?? "Ungrouped";
|
|
756
|
+
if (!groups.has(label)) groups.set(label, []);
|
|
757
|
+
groups.get(label).push(item);
|
|
758
|
+
});
|
|
759
|
+
element.setGroupedItems(
|
|
760
|
+
Array.from(groups, ([label, options]) => ({ label, options }))
|
|
761
|
+
);
|
|
762
|
+
} else {
|
|
763
|
+
element.setItems(sourceItems);
|
|
764
|
+
}
|
|
745
765
|
}
|
|
746
|
-
|
|
766
|
+
synchronizedSourceRef.current = sourceCandidate;
|
|
767
|
+
});
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
var _a2;
|
|
770
|
+
const element = elementRef.current;
|
|
771
|
+
if (!element || !isElementUsable || isControlled || hasAppliedInitialValueRef.current) return;
|
|
772
|
+
if (internalValue === void 0) return;
|
|
773
|
+
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
774
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
775
|
+
if (!areValuesEqual(values, currentValues)) element.setSelectedValues(values);
|
|
776
|
+
hasAppliedInitialValueRef.current = true;
|
|
777
|
+
}, [isElementUsable, isControlled, internalValue, areValuesEqual]);
|
|
747
778
|
useEffect(() => {
|
|
748
779
|
var _a2;
|
|
749
780
|
const element = elementRef.current;
|
|
@@ -759,97 +790,46 @@ const Select = forwardRef((props, ref) => {
|
|
|
759
790
|
}, [value, isControlled, isElementUsable, areValuesEqual]);
|
|
760
791
|
useEffect(() => {
|
|
761
792
|
const element = elementRef.current;
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
multiSelectDisplay,
|
|
783
|
-
infiniteScroll: {
|
|
784
|
-
enabled: infiniteScroll,
|
|
785
|
-
pageSize
|
|
786
|
-
},
|
|
787
|
-
scrollToSelected: {
|
|
788
|
-
enabled: true,
|
|
789
|
-
...scrollToSelected
|
|
790
|
-
},
|
|
791
|
-
styles: stylesConfig,
|
|
792
|
-
clearControl: {
|
|
793
|
-
enabled: clearable,
|
|
794
|
-
clearSelection: clearSelectionOnClear,
|
|
795
|
-
clearSearch: clearSearchOnClear,
|
|
796
|
-
ariaLabel: clearAriaLabel,
|
|
797
|
-
icon: clearIcon
|
|
798
|
-
},
|
|
799
|
-
tracking: {
|
|
800
|
-
enabled: trackingEnabled,
|
|
801
|
-
events: trackEvents,
|
|
802
|
-
styling: trackStyling,
|
|
803
|
-
limitations: trackLimitations,
|
|
804
|
-
emitDiagnostics,
|
|
805
|
-
maxEntries: trackingMaxEntries
|
|
806
|
-
},
|
|
807
|
-
limitations: {
|
|
808
|
-
policies: limitationPolicies,
|
|
809
|
-
autoMitigateRuntimeModeSwitch
|
|
793
|
+
const shadow = element == null ? void 0 : element.shadowRoot;
|
|
794
|
+
if (!isElementUsable || !shouldPortalRemoveIcon || !shadow) {
|
|
795
|
+
setRemoveIconTargets((previous) => previous.length ? [] : previous);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
const observed = /* @__PURE__ */ new Set();
|
|
799
|
+
let currentTargets = [];
|
|
800
|
+
let disposed = false;
|
|
801
|
+
const observer = new MutationObserver(() => refresh());
|
|
802
|
+
const refresh = () => {
|
|
803
|
+
if (disposed) return;
|
|
804
|
+
const optionRoots = Array.from(shadow.querySelectorAll("select-option")).map((option) => option.shadowRoot).filter((root) => root !== null);
|
|
805
|
+
const roots = [shadow, ...optionRoots];
|
|
806
|
+
if (roots.length !== observed.size || roots.some((root) => !observed.has(root))) {
|
|
807
|
+
observer.disconnect();
|
|
808
|
+
observed.clear();
|
|
809
|
+
for (const root of roots) {
|
|
810
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
811
|
+
observed.add(root);
|
|
812
|
+
}
|
|
810
813
|
}
|
|
814
|
+
const targets = [
|
|
815
|
+
...Array.from(shadow.querySelectorAll('[part="chip-remove-icon"]')),
|
|
816
|
+
...optionRoots.flatMap(
|
|
817
|
+
(root) => Array.from(root.querySelectorAll('[part="chip-remove-icon"]'))
|
|
818
|
+
)
|
|
819
|
+
];
|
|
820
|
+
if (targets.length === currentTargets.length && targets.every((target, index) => target === currentTargets[index])) return;
|
|
821
|
+
for (const target of targets) {
|
|
822
|
+
if (!currentTargets.includes(target)) target.replaceChildren();
|
|
823
|
+
}
|
|
824
|
+
currentTargets = targets;
|
|
825
|
+
setRemoveIconTargets(targets);
|
|
811
826
|
};
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
placeholder,
|
|
819
|
-
virtualized,
|
|
820
|
-
estimatedItemHeight,
|
|
821
|
-
disabled,
|
|
822
|
-
multiple,
|
|
823
|
-
maxSelections,
|
|
824
|
-
selectionConfig,
|
|
825
|
-
multiSelectDisplay,
|
|
826
|
-
scrollToSelected,
|
|
827
|
-
stylesConfig,
|
|
828
|
-
coreConfig,
|
|
829
|
-
removeButtonIcon,
|
|
830
|
-
disabledOptionBehavior,
|
|
831
|
-
showSelectedIndicator,
|
|
832
|
-
toggleOnTriggerClick,
|
|
833
|
-
infiniteScroll,
|
|
834
|
-
pageSize,
|
|
835
|
-
clearable,
|
|
836
|
-
clearSelectionOnClear,
|
|
837
|
-
clearSearchOnClear,
|
|
838
|
-
clearAriaLabel,
|
|
839
|
-
clearIcon,
|
|
840
|
-
trackingEnabled,
|
|
841
|
-
trackEvents,
|
|
842
|
-
trackStyling,
|
|
843
|
-
trackLimitations,
|
|
844
|
-
emitDiagnostics,
|
|
845
|
-
trackingMaxEntries,
|
|
846
|
-
limitationPolicies,
|
|
847
|
-
autoMitigateRuntimeModeSwitch,
|
|
848
|
-
direction,
|
|
849
|
-
resolvedDropdownPlacement,
|
|
850
|
-
isElementUsable,
|
|
851
|
-
applyInstanceConfig
|
|
852
|
-
]);
|
|
827
|
+
refresh();
|
|
828
|
+
return () => {
|
|
829
|
+
disposed = true;
|
|
830
|
+
observer.disconnect();
|
|
831
|
+
};
|
|
832
|
+
}, [isElementUsable, shouldPortalRemoveIcon]);
|
|
853
833
|
useEffect(() => {
|
|
854
834
|
const element = elementRef.current;
|
|
855
835
|
if (!element || !isElementUsable) return;
|
|
@@ -891,11 +871,6 @@ const Select = forwardRef((props, ref) => {
|
|
|
891
871
|
isElementUsable,
|
|
892
872
|
acceptedProtocol,
|
|
893
873
|
acknowledgedRequested,
|
|
894
|
-
coreConfig,
|
|
895
|
-
items,
|
|
896
|
-
groupedItems,
|
|
897
|
-
value,
|
|
898
|
-
defaultValue,
|
|
899
874
|
loading,
|
|
900
875
|
consumerAriaBusy,
|
|
901
876
|
syncHostBusy,
|
|
@@ -941,6 +916,10 @@ const Select = forwardRef((props, ref) => {
|
|
|
941
916
|
var _a2;
|
|
942
917
|
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
|
|
943
918
|
},
|
|
919
|
+
getEmptyStateContext: () => {
|
|
920
|
+
var _a2, _b2;
|
|
921
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getEmptyStateContext) == null ? void 0 : _b2.call(_a2)) ?? null;
|
|
922
|
+
},
|
|
944
923
|
setItems: (items2) => {
|
|
945
924
|
var _a2;
|
|
946
925
|
(_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
|
|
@@ -977,12 +956,12 @@ const Select = forwardRef((props, ref) => {
|
|
|
977
956
|
applyInstanceConfig(element, config);
|
|
978
957
|
},
|
|
979
958
|
getDataLoadingState: () => {
|
|
980
|
-
var _a2, _b2,
|
|
959
|
+
var _a2, _b2, _c2;
|
|
981
960
|
const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
|
|
982
961
|
if (snapshot) return snapshot;
|
|
983
962
|
return {
|
|
984
963
|
status: "idle",
|
|
985
|
-
connected: Boolean((
|
|
964
|
+
connected: Boolean((_c2 = elementRef.current) == null ? void 0 : _c2.isConnected),
|
|
986
965
|
busy: false,
|
|
987
966
|
projectionPending: false,
|
|
988
967
|
queryGeneration: 0,
|
|
@@ -1052,6 +1031,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
1052
1031
|
onChange
|
|
1053
1032
|
]);
|
|
1054
1033
|
const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
|
|
1034
|
+
const renderedEmptyState = emptyStateContext && emptyStateRenderer ? emptyStateRenderer(emptyStateContext) : null;
|
|
1055
1035
|
return React.createElement(
|
|
1056
1036
|
"enhanced-select",
|
|
1057
1037
|
{
|
|
@@ -1071,6 +1051,35 @@ const Select = forwardRef((props, ref) => {
|
|
|
1071
1051
|
"aria-hidden": "true"
|
|
1072
1052
|
},
|
|
1073
1053
|
arrowIcon
|
|
1054
|
+
) : null,
|
|
1055
|
+
loadingIcon != null ? React.createElement(
|
|
1056
|
+
"span",
|
|
1057
|
+
{
|
|
1058
|
+
slot: "loading-icon",
|
|
1059
|
+
className: "smilodon-loading-icon",
|
|
1060
|
+
"aria-hidden": "true"
|
|
1061
|
+
},
|
|
1062
|
+
loadingIcon
|
|
1063
|
+
) : null,
|
|
1064
|
+
loadingContent != null ? React.createElement(
|
|
1065
|
+
"div",
|
|
1066
|
+
{
|
|
1067
|
+
slot: "loading-content",
|
|
1068
|
+
className: "smilodon-loading-content"
|
|
1069
|
+
},
|
|
1070
|
+
loadingContent
|
|
1071
|
+
) : null,
|
|
1072
|
+
renderedEmptyState != null && typeof renderedEmptyState !== "boolean" ? React.createElement(
|
|
1073
|
+
"div",
|
|
1074
|
+
{ slot: "empty-state", className: "smilodon-empty-state" },
|
|
1075
|
+
renderedEmptyState
|
|
1076
|
+
) : null,
|
|
1077
|
+
shouldPortalRemoveIcon ? removeIconTargets.map(
|
|
1078
|
+
(target, index) => createPortal(
|
|
1079
|
+
React.createElement("span", { "aria-hidden": "true" }, removeButtonIcon),
|
|
1080
|
+
target,
|
|
1081
|
+
index
|
|
1082
|
+
)
|
|
1074
1083
|
) : null
|
|
1075
1084
|
);
|
|
1076
1085
|
});
|