@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/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
26
26
  const jsxRuntime = require("react/jsx-runtime");
27
27
  const React = require("react");
28
28
  const client = require("react-dom/client");
29
+ const reactDom = require("react-dom");
29
30
  const core = require("@smilodon/core");
30
31
  const DEFAULT_DATA_LOADING_CONFIG = {
31
32
  protocol: "legacy",
@@ -40,6 +41,64 @@ function isPlainRecord(value) {
40
41
  const prototype = Object.getPrototypeOf(value);
41
42
  return prototype === Object.prototype || prototype === null;
42
43
  }
44
+ function areSemanticallyEqual(left, right, seen = /* @__PURE__ */ new WeakMap()) {
45
+ var _a;
46
+ if (Object.is(left, right)) return true;
47
+ if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
48
+ return false;
49
+ }
50
+ const leftArray = Array.isArray(left);
51
+ const rightArray = Array.isArray(right);
52
+ if (leftArray !== rightArray) return false;
53
+ if (!leftArray && (!isPlainRecord(left) || !isPlainRecord(right))) return false;
54
+ if (leftArray && !Array.isArray(right)) return false;
55
+ if (leftArray && rightArray && left.length !== right.length) return false;
56
+ const leftPrototype = Object.getPrototypeOf(left);
57
+ const rightPrototype = Object.getPrototypeOf(right);
58
+ if (leftPrototype !== rightPrototype && !(isPlainRecord(left) && isPlainRecord(right))) return false;
59
+ const prior = (_a = seen.get(left)) == null ? void 0 : _a.get(right);
60
+ if (prior !== void 0) return prior;
61
+ let rightPairs = seen.get(left);
62
+ if (!rightPairs) {
63
+ rightPairs = /* @__PURE__ */ new WeakMap();
64
+ seen.set(left, rightPairs);
65
+ }
66
+ rightPairs.set(right, true);
67
+ const enumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => {
68
+ var _a2;
69
+ return (_a2 = Object.getOwnPropertyDescriptor(value, key)) == null ? void 0 : _a2.enumerable;
70
+ });
71
+ const leftKeys = enumerableKeys(left);
72
+ const rightKeys = enumerableKeys(right);
73
+ const rightKeySet = new Set(rightKeys);
74
+ if (leftKeys.length !== rightKeys.length) {
75
+ rightPairs.set(right, false);
76
+ return false;
77
+ }
78
+ for (const key of leftKeys) {
79
+ if (!rightKeySet.has(key)) {
80
+ rightPairs.set(right, false);
81
+ return false;
82
+ }
83
+ const leftDescriptor = Object.getOwnPropertyDescriptor(left, key);
84
+ const rightDescriptor = Object.getOwnPropertyDescriptor(right, key);
85
+ if ("value" in leftDescriptor !== "value" in rightDescriptor) {
86
+ rightPairs.set(right, false);
87
+ return false;
88
+ }
89
+ if ("value" in leftDescriptor) {
90
+ if (!areSemanticallyEqual(leftDescriptor.value, rightDescriptor.value, seen)) {
91
+ rightPairs.set(right, false);
92
+ return false;
93
+ }
94
+ } else if (leftDescriptor.get !== rightDescriptor.get || leftDescriptor.set !== rightDescriptor.set) {
95
+ rightPairs.set(right, false);
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ const EMPTY_ITEMS = [];
43
102
  function isBusyToken(value) {
44
103
  return value === true || value === "true";
45
104
  }
@@ -49,9 +108,9 @@ function composeBusyToken(consumerValue, externalBusy) {
49
108
  return consumerValue;
50
109
  }
51
110
  const Select = React.forwardRef((props, ref) => {
52
- var _a, _b;
111
+ var _a, _b, _c;
53
112
  const {
54
- items = [],
113
+ items = EMPTY_ITEMS,
55
114
  groupedItems,
56
115
  value,
57
116
  defaultValue,
@@ -74,6 +133,9 @@ const Select = React.forwardRef((props, ref) => {
74
133
  config: coreConfig,
75
134
  removeButtonIcon,
76
135
  arrowIcon,
136
+ loadingIcon,
137
+ loadingContent,
138
+ emptyStateRenderer,
77
139
  disabledOptionBehavior,
78
140
  showSelectedIndicator = true,
79
141
  toggleOnTriggerClick = true,
@@ -101,6 +163,7 @@ const Select = React.forwardRef((props, ref) => {
101
163
  onDataRequestCancel,
102
164
  onDataProjection,
103
165
  onDataLoadingConfigError,
166
+ onEmptyStateChange,
104
167
  trackingEnabled = false,
105
168
  trackEvents = true,
106
169
  trackStyling = true,
@@ -142,6 +205,7 @@ const Select = React.forwardRef((props, ref) => {
142
205
  onDataRequestCancel,
143
206
  onDataProjection,
144
207
  onDataLoadingConfigError,
208
+ onEmptyStateChange,
145
209
  isControlled,
146
210
  multiple
147
211
  });
@@ -157,6 +221,7 @@ const Select = React.forwardRef((props, ref) => {
157
221
  onDataRequestCancel,
158
222
  onDataProjection,
159
223
  onDataLoadingConfigError,
224
+ onEmptyStateChange,
160
225
  isControlled,
161
226
  multiple
162
227
  };
@@ -303,7 +368,10 @@ const Select = React.forwardRef((props, ref) => {
303
368
  reactRendererCache.current.clear();
304
369
  }, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
305
370
  const [isElementReady, setIsElementReady] = React.useState(false);
306
- const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_a = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _a.protocol) === "acknowledged";
371
+ const [emptyStateContext, setEmptyStateContext] = React.useState(null);
372
+ const [removeIconTargets, setRemoveIconTargets] = React.useState([]);
373
+ 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;
374
+ const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
307
375
  const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
308
376
  const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
309
377
  const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
@@ -410,7 +478,7 @@ const Select = React.forwardRef((props, ref) => {
410
478
  },
411
479
  [markUnusable, syncHostBusy]
412
480
  );
413
- const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
481
+ const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_c = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _c.protocol) === "acknowledged";
414
482
  const qualifyAcknowledgedElement = React.useCallback(() => {
415
483
  const element = elementRef.current;
416
484
  const module2 = coreModuleRef.current;
@@ -428,16 +496,17 @@ const Select = React.forwardRef((props, ref) => {
428
496
  return true;
429
497
  }, [markUnusable]);
430
498
  const subscribeToCoreEvents = React.useCallback((element) => {
499
+ var _a2;
431
500
  const currentSubscription = activeListenersRef.current;
432
501
  if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
433
502
  currentSubscription == null ? void 0 : currentSubscription.dispose();
434
503
  const handleSelect = (event) => {
435
- var _a2, _b2;
504
+ var _a3, _b2;
436
505
  const detail = event.detail;
437
- (_b2 = (_a2 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a2, detail.item, detail.index);
506
+ (_b2 = (_a3 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a3, detail.item, detail.index);
438
507
  };
439
508
  const handleChange = (event) => {
440
- var _a2;
509
+ var _a3;
441
510
  const { selectedItems, selectedValues } = event.detail;
442
511
  const callbacks = callbackStateRef.current;
443
512
  const values = selectedValues;
@@ -446,19 +515,19 @@ const Select = React.forwardRef((props, ref) => {
446
515
  if (!callbacks.isControlled) {
447
516
  setInternalValue(callbacks.multiple ? values : nextSingleValue);
448
517
  }
449
- (_a2 = callbacks.onChange) == null ? void 0 : _a2.call(
518
+ (_a3 = callbacks.onChange) == null ? void 0 : _a3.call(
450
519
  callbacks,
451
520
  callbacks.multiple ? values : nextSingleValue,
452
521
  selectedItems
453
522
  );
454
523
  };
455
524
  const handleOpen = () => {
456
- var _a2, _b2;
457
- return (_b2 = (_a2 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a2);
525
+ var _a3, _b2;
526
+ return (_b2 = (_a3 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a3);
458
527
  };
459
528
  const handleClose = () => {
460
- var _a2, _b2;
461
- return (_b2 = (_a2 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a2);
529
+ var _a3, _b2;
530
+ return (_b2 = (_a3 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a3);
462
531
  };
463
532
  const handleSearch = (event) => {
464
533
  const { query, results, count, request } = event.detail;
@@ -475,40 +544,46 @@ const Select = React.forwardRef((props, ref) => {
475
544
  else callback(page);
476
545
  };
477
546
  const handleClear = (event) => {
478
- var _a2, _b2;
547
+ var _a3, _b2;
479
548
  const { clearedSelection, clearedSearch } = event.detail;
480
- (_b2 = (_a2 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a2, { clearedSelection, clearedSearch });
549
+ (_b2 = (_a3 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a3, { clearedSelection, clearedSearch });
481
550
  };
482
551
  const handleDiagnostic = (event) => {
483
- var _a2, _b2;
484
- (_b2 = (_a2 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
485
- _a2,
552
+ var _a3, _b2;
553
+ (_b2 = (_a3 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
554
+ _a3,
486
555
  event.detail
487
556
  );
488
557
  };
489
558
  const handleDataRequestCancel = (event) => {
490
- var _a2, _b2;
491
- (_b2 = (_a2 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
492
- _a2,
559
+ var _a3, _b2;
560
+ (_b2 = (_a3 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
561
+ _a3,
493
562
  event.detail
494
563
  );
495
564
  };
496
565
  const handleDataProjection = (event) => {
497
- var _a2, _b2;
498
- (_b2 = (_a2 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
499
- _a2,
566
+ var _a3, _b2;
567
+ (_b2 = (_a3 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
568
+ _a3,
500
569
  event.detail
501
570
  );
502
571
  };
503
572
  const handleDataLoadingConfigError = (event) => {
504
- var _a2, _b2;
573
+ var _a3, _b2;
505
574
  const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
506
575
  if (activeUpdate) activeUpdate.sawConfigError = true;
507
- (_b2 = (_a2 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
508
- _a2,
576
+ (_b2 = (_a3 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
577
+ _a3,
509
578
  event.detail
510
579
  );
511
580
  };
581
+ const handleEmptyStateChange = (event) => {
582
+ var _a3, _b2;
583
+ const context = event.detail.context;
584
+ setEmptyStateContext(context);
585
+ (_b2 = (_a3 = callbackStateRef.current).onEmptyStateChange) == null ? void 0 : _b2.call(_a3, context);
586
+ };
512
587
  const listeners = [
513
588
  ["select", handleSelect],
514
589
  ["change", handleChange],
@@ -520,14 +595,18 @@ const Select = React.forwardRef((props, ref) => {
520
595
  ["diagnostic", handleDiagnostic],
521
596
  ["dataRequestCancel", handleDataRequestCancel],
522
597
  ["dataProjection", handleDataProjection],
523
- ["dataLoadingConfigError", handleDataLoadingConfigError]
598
+ ["dataLoadingConfigError", handleDataLoadingConfigError],
599
+ ["emptyStateChange", handleEmptyStateChange]
524
600
  ];
525
601
  for (const [name, listener] of listeners) {
526
602
  element.addEventListener(name, listener);
527
603
  }
604
+ setEmptyStateContext(
605
+ ((_a2 = element.getEmptyStateContext) == null ? void 0 : _a2.call(element)) ?? null
606
+ );
528
607
  const dispose = () => {
529
- var _a2;
530
- if (((_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose) === dispose) {
608
+ var _a3;
609
+ if (((_a3 = activeListenersRef.current) == null ? void 0 : _a3.dispose) === dispose) {
531
610
  activeListenersRef.current = null;
532
611
  }
533
612
  for (const [name, listener] of listeners) {
@@ -618,156 +697,108 @@ const Select = React.forwardRef((props, ref) => {
618
697
  return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
619
698
  };
620
699
  }, []);
621
- React.useEffect(() => {
622
- var _a2;
623
- const element = elementRef.current;
624
- if (!element || !isElementUsable) return;
625
- if (!element.setItems) {
626
- console.warn("Enhanced select element not fully initialized yet");
627
- return;
628
- }
629
- if (groupedItems) {
630
- element.setGroupedItems(groupedItems);
631
- } else if (items.length > 0) {
632
- element.setItems(items);
633
- }
634
- const config = {
635
- searchable,
636
- placeholder,
637
- virtualize: virtualized,
638
- estimatedItemHeight,
639
- enabled: !disabled,
640
- dropdownPlacement: {
641
- mode: resolvedDropdownPlacement
642
- },
643
- selection: {
644
- ...selectionConfig,
645
- mode: multiple ? "multi" : "single",
646
- maxSelections,
647
- removeButtonIcon,
648
- disabledOptionBehavior,
649
- showSelectedIndicator,
650
- toggleOnTriggerClick
651
- },
652
- direction,
653
- multiSelectDisplay,
654
- infiniteScroll: {
655
- enabled: infiniteScroll,
656
- pageSize
657
- },
658
- scrollToSelected: {
659
- enabled: true,
660
- ...scrollToSelected
661
- },
662
- creatable,
663
- styles: stylesConfig,
664
- clearControl: {
665
- enabled: clearable,
666
- clearSelection: clearSelectionOnClear,
667
- clearSearch: clearSearchOnClear,
668
- ariaLabel: clearAriaLabel,
669
- icon: clearIcon
670
- },
671
- tracking: {
672
- enabled: trackingEnabled,
673
- events: trackEvents,
674
- styling: trackStyling,
675
- limitations: trackLimitations,
676
- emitDiagnostics,
677
- maxEntries: trackingMaxEntries
678
- },
679
- limitations: {
680
- policies: limitationPolicies,
681
- autoMitigateRuntimeModeSwitch
682
- }
683
- };
684
- applyInstanceConfig(element, config);
685
- if (coreConfig) {
686
- applyInstanceConfig(element, coreConfig);
687
- }
688
- if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
689
- const values = Array.isArray(internalValue) ? internalValue : [internalValue];
690
- const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
691
- if (!areValuesEqual(values, currentValues)) {
692
- element.setSelectedValues(values);
693
- }
694
- hasAppliedInitialValueRef.current = true;
695
- }
696
- if (error) {
697
- element.setError(errorMessage || "Invalid selection");
698
- } else {
699
- element.clearError();
700
- }
701
- if (required) {
702
- element.setRequired(true);
703
- }
704
- }, [
705
- isElementUsable,
706
- items,
707
- groupedItems,
700
+ const componentConfig = {
708
701
  searchable,
709
702
  placeholder,
710
- virtualized,
703
+ virtualize: virtualized,
711
704
  estimatedItemHeight,
712
- disabled,
713
- multiple,
714
- maxSelections,
715
- selectionConfig,
705
+ enabled: !disabled,
706
+ dropdownPlacement: { mode: resolvedDropdownPlacement },
707
+ selection: {
708
+ ...selectionConfig,
709
+ mode: multiple ? "multi" : "single",
710
+ maxSelections,
711
+ removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
712
+ disabledOptionBehavior,
713
+ showSelectedIndicator,
714
+ toggleOnTriggerClick
715
+ },
716
+ direction,
716
717
  multiSelectDisplay,
717
- scrollToSelected,
718
- stylesConfig,
719
- coreConfig,
720
- removeButtonIcon,
721
- disabledOptionBehavior,
722
- showSelectedIndicator,
723
- toggleOnTriggerClick,
724
- infiniteScroll,
725
- pageSize,
718
+ infiniteScroll: { enabled: infiniteScroll, pageSize },
719
+ scrollToSelected: { enabled: true, ...scrollToSelected },
726
720
  creatable,
727
- clearable,
728
- clearSelectionOnClear,
729
- clearSearchOnClear,
730
- clearAriaLabel,
731
- clearIcon,
732
- trackingEnabled,
733
- trackEvents,
734
- trackStyling,
735
- trackLimitations,
736
- emitDiagnostics,
737
- trackingMaxEntries,
738
- limitationPolicies,
739
- autoMitigateRuntimeModeSwitch,
740
- direction,
741
- resolvedDropdownPlacement,
742
- error,
743
- errorMessage,
744
- required,
745
- internalValue,
746
- isControlled,
747
- areValuesEqual,
748
- applyInstanceConfig
749
- ]);
721
+ styles: stylesConfig,
722
+ clearControl: {
723
+ enabled: clearable,
724
+ clearSelection: clearSelectionOnClear,
725
+ clearSearch: clearSearchOnClear,
726
+ ariaLabel: clearAriaLabel,
727
+ icon: clearIcon
728
+ },
729
+ tracking: {
730
+ enabled: trackingEnabled,
731
+ events: trackEvents,
732
+ styling: trackStyling,
733
+ limitations: trackLimitations,
734
+ emitDiagnostics,
735
+ maxEntries: trackingMaxEntries
736
+ },
737
+ limitations: { policies: limitationPolicies, autoMitigateRuntimeModeSwitch }
738
+ };
739
+ const configCandidate = { component: componentConfig, core: coreConfig };
740
+ const appliedConfigRef = React.useRef({ hasComponent: false, component: null, hasCore: false, core: void 0 });
741
+ React.useEffect(() => {
742
+ const element = elementRef.current;
743
+ if (!element || !isElementUsable || !element.updateConfig) return;
744
+ const previous = appliedConfigRef.current;
745
+ const componentChanged = !previous.hasComponent || !areSemanticallyEqual(previous.component, configCandidate.component);
746
+ const coreChanged = !previous.hasCore || !areSemanticallyEqual(previous.core, configCandidate.core);
747
+ if (!componentChanged && !coreChanged) return;
748
+ if (componentChanged) {
749
+ applyInstanceConfig(element, configCandidate.component);
750
+ if (configCandidate.core) applyInstanceConfig(element, configCandidate.core);
751
+ } else if (coreChanged) {
752
+ if (configCandidate.core) {
753
+ applyInstanceConfig(element, configCandidate.core);
754
+ } else {
755
+ applyInstanceConfig(element, configCandidate.component);
756
+ }
757
+ }
758
+ appliedConfigRef.current = {
759
+ hasComponent: true,
760
+ component: configCandidate.component,
761
+ hasCore: true,
762
+ core: configCandidate.core
763
+ };
764
+ });
765
+ const sourceCandidate = groupedItems !== void 0 ? { kind: "grouped", data: groupedItems } : { kind: "items", data: items };
766
+ const synchronizedSourceRef = React.useRef(null);
750
767
  React.useEffect(() => {
768
+ var _a2;
751
769
  const element = elementRef.current;
752
770
  if (!element || !isElementUsable || !element.setItems) return;
753
- if (groupedItems) {
754
- element.setGroupedItems(groupedItems);
755
- } else if (items && items.length && items[0] && items[0].group !== void 0) {
756
- const map = /* @__PURE__ */ new Map();
757
- items.forEach((it) => {
758
- const g = it.group ?? "Ungrouped";
759
- if (!map.has(g)) map.set(g, []);
760
- map.get(g).push(it);
761
- });
762
- const groups = Array.from(map.entries()).map(([label, options]) => ({
763
- label,
764
- options
765
- }));
766
- element.setGroupedItems(groups);
771
+ if (areSemanticallyEqual(synchronizedSourceRef.current, sourceCandidate)) return;
772
+ if (sourceCandidate.kind === "grouped") {
773
+ element.setGroupedItems(sourceCandidate.data);
767
774
  } else {
768
- element.setItems(items);
775
+ const sourceItems = sourceCandidate.data;
776
+ if (sourceItems.length > 0 && ((_a2 = sourceItems[0]) == null ? void 0 : _a2.group) !== void 0) {
777
+ const groups = /* @__PURE__ */ new Map();
778
+ sourceItems.forEach((item) => {
779
+ const label = item.group ?? "Ungrouped";
780
+ if (!groups.has(label)) groups.set(label, []);
781
+ groups.get(label).push(item);
782
+ });
783
+ element.setGroupedItems(
784
+ Array.from(groups, ([label, options]) => ({ label, options }))
785
+ );
786
+ } else {
787
+ element.setItems(sourceItems);
788
+ }
769
789
  }
770
- }, [items, groupedItems, isElementUsable]);
790
+ synchronizedSourceRef.current = sourceCandidate;
791
+ });
792
+ React.useEffect(() => {
793
+ var _a2;
794
+ const element = elementRef.current;
795
+ if (!element || !isElementUsable || isControlled || hasAppliedInitialValueRef.current) return;
796
+ if (internalValue === void 0) return;
797
+ const values = Array.isArray(internalValue) ? internalValue : [internalValue];
798
+ const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
799
+ if (!areValuesEqual(values, currentValues)) element.setSelectedValues(values);
800
+ hasAppliedInitialValueRef.current = true;
801
+ }, [isElementUsable, isControlled, internalValue, areValuesEqual]);
771
802
  React.useEffect(() => {
772
803
  var _a2;
773
804
  const element = elementRef.current;
@@ -783,97 +814,46 @@ const Select = React.forwardRef((props, ref) => {
783
814
  }, [value, isControlled, isElementUsable, areValuesEqual]);
784
815
  React.useEffect(() => {
785
816
  const element = elementRef.current;
786
- if (!element || !isElementUsable || !element.updateConfig) return;
787
- const config = {
788
- searchable,
789
- placeholder,
790
- virtualize: virtualized,
791
- estimatedItemHeight,
792
- enabled: !disabled,
793
- dropdownPlacement: {
794
- mode: resolvedDropdownPlacement
795
- },
796
- selection: {
797
- ...selectionConfig,
798
- mode: multiple ? "multi" : "single",
799
- maxSelections,
800
- removeButtonIcon,
801
- disabledOptionBehavior,
802
- showSelectedIndicator,
803
- toggleOnTriggerClick
804
- },
805
- direction,
806
- multiSelectDisplay,
807
- infiniteScroll: {
808
- enabled: infiniteScroll,
809
- pageSize
810
- },
811
- scrollToSelected: {
812
- enabled: true,
813
- ...scrollToSelected
814
- },
815
- styles: stylesConfig,
816
- clearControl: {
817
- enabled: clearable,
818
- clearSelection: clearSelectionOnClear,
819
- clearSearch: clearSearchOnClear,
820
- ariaLabel: clearAriaLabel,
821
- icon: clearIcon
822
- },
823
- tracking: {
824
- enabled: trackingEnabled,
825
- events: trackEvents,
826
- styling: trackStyling,
827
- limitations: trackLimitations,
828
- emitDiagnostics,
829
- maxEntries: trackingMaxEntries
830
- },
831
- limitations: {
832
- policies: limitationPolicies,
833
- autoMitigateRuntimeModeSwitch
817
+ const shadow = element == null ? void 0 : element.shadowRoot;
818
+ if (!isElementUsable || !shouldPortalRemoveIcon || !shadow) {
819
+ setRemoveIconTargets((previous) => previous.length ? [] : previous);
820
+ return;
821
+ }
822
+ const observed = /* @__PURE__ */ new Set();
823
+ let currentTargets = [];
824
+ let disposed = false;
825
+ const observer = new MutationObserver(() => refresh());
826
+ const refresh = () => {
827
+ if (disposed) return;
828
+ const optionRoots = Array.from(shadow.querySelectorAll("select-option")).map((option) => option.shadowRoot).filter((root) => root !== null);
829
+ const roots = [shadow, ...optionRoots];
830
+ if (roots.length !== observed.size || roots.some((root) => !observed.has(root))) {
831
+ observer.disconnect();
832
+ observed.clear();
833
+ for (const root of roots) {
834
+ observer.observe(root, { childList: true, subtree: true });
835
+ observed.add(root);
836
+ }
834
837
  }
838
+ const targets = [
839
+ ...Array.from(shadow.querySelectorAll('[part="chip-remove-icon"]')),
840
+ ...optionRoots.flatMap(
841
+ (root) => Array.from(root.querySelectorAll('[part="chip-remove-icon"]'))
842
+ )
843
+ ];
844
+ if (targets.length === currentTargets.length && targets.every((target, index) => target === currentTargets[index])) return;
845
+ for (const target of targets) {
846
+ if (!currentTargets.includes(target)) target.replaceChildren();
847
+ }
848
+ currentTargets = targets;
849
+ setRemoveIconTargets(targets);
835
850
  };
836
- applyInstanceConfig(element, config);
837
- if (coreConfig) {
838
- applyInstanceConfig(element, coreConfig);
839
- }
840
- }, [
841
- searchable,
842
- placeholder,
843
- virtualized,
844
- estimatedItemHeight,
845
- disabled,
846
- multiple,
847
- maxSelections,
848
- selectionConfig,
849
- multiSelectDisplay,
850
- scrollToSelected,
851
- stylesConfig,
852
- coreConfig,
853
- removeButtonIcon,
854
- disabledOptionBehavior,
855
- showSelectedIndicator,
856
- toggleOnTriggerClick,
857
- infiniteScroll,
858
- pageSize,
859
- clearable,
860
- clearSelectionOnClear,
861
- clearSearchOnClear,
862
- clearAriaLabel,
863
- clearIcon,
864
- trackingEnabled,
865
- trackEvents,
866
- trackStyling,
867
- trackLimitations,
868
- emitDiagnostics,
869
- trackingMaxEntries,
870
- limitationPolicies,
871
- autoMitigateRuntimeModeSwitch,
872
- direction,
873
- resolvedDropdownPlacement,
874
- isElementUsable,
875
- applyInstanceConfig
876
- ]);
851
+ refresh();
852
+ return () => {
853
+ disposed = true;
854
+ observer.disconnect();
855
+ };
856
+ }, [isElementUsable, shouldPortalRemoveIcon]);
877
857
  React.useEffect(() => {
878
858
  const element = elementRef.current;
879
859
  if (!element || !isElementUsable) return;
@@ -915,11 +895,6 @@ const Select = React.forwardRef((props, ref) => {
915
895
  isElementUsable,
916
896
  acceptedProtocol,
917
897
  acknowledgedRequested,
918
- coreConfig,
919
- items,
920
- groupedItems,
921
- value,
922
- defaultValue,
923
898
  loading,
924
899
  consumerAriaBusy,
925
900
  syncHostBusy,
@@ -965,6 +940,10 @@ const Select = React.forwardRef((props, ref) => {
965
940
  var _a2;
966
941
  return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
967
942
  },
943
+ getEmptyStateContext: () => {
944
+ var _a2, _b2;
945
+ return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getEmptyStateContext) == null ? void 0 : _b2.call(_a2)) ?? null;
946
+ },
968
947
  setItems: (items2) => {
969
948
  var _a2;
970
949
  (_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
@@ -1001,12 +980,12 @@ const Select = React.forwardRef((props, ref) => {
1001
980
  applyInstanceConfig(element, config);
1002
981
  },
1003
982
  getDataLoadingState: () => {
1004
- var _a2, _b2, _c;
983
+ var _a2, _b2, _c2;
1005
984
  const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
1006
985
  if (snapshot) return snapshot;
1007
986
  return {
1008
987
  status: "idle",
1009
- connected: Boolean((_c = elementRef.current) == null ? void 0 : _c.isConnected),
988
+ connected: Boolean((_c2 = elementRef.current) == null ? void 0 : _c2.isConnected),
1010
989
  busy: false,
1011
990
  projectionPending: false,
1012
991
  queryGeneration: 0,
@@ -1076,6 +1055,7 @@ const Select = React.forwardRef((props, ref) => {
1076
1055
  onChange
1077
1056
  ]);
1078
1057
  const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
1058
+ const renderedEmptyState = emptyStateContext && emptyStateRenderer ? emptyStateRenderer(emptyStateContext) : null;
1079
1059
  return React.createElement(
1080
1060
  "enhanced-select",
1081
1061
  {
@@ -1095,6 +1075,35 @@ const Select = React.forwardRef((props, ref) => {
1095
1075
  "aria-hidden": "true"
1096
1076
  },
1097
1077
  arrowIcon
1078
+ ) : null,
1079
+ loadingIcon != null ? React.createElement(
1080
+ "span",
1081
+ {
1082
+ slot: "loading-icon",
1083
+ className: "smilodon-loading-icon",
1084
+ "aria-hidden": "true"
1085
+ },
1086
+ loadingIcon
1087
+ ) : null,
1088
+ loadingContent != null ? React.createElement(
1089
+ "div",
1090
+ {
1091
+ slot: "loading-content",
1092
+ className: "smilodon-loading-content"
1093
+ },
1094
+ loadingContent
1095
+ ) : null,
1096
+ renderedEmptyState != null && typeof renderedEmptyState !== "boolean" ? React.createElement(
1097
+ "div",
1098
+ { slot: "empty-state", className: "smilodon-empty-state" },
1099
+ renderedEmptyState
1100
+ ) : null,
1101
+ shouldPortalRemoveIcon ? removeIconTargets.map(
1102
+ (target, index) => reactDom.createPortal(
1103
+ React.createElement("span", { "aria-hidden": "true" }, removeButtonIcon),
1104
+ target,
1105
+ index
1106
+ )
1098
1107
  ) : null
1099
1108
  );
1100
1109
  });