@smilodon/react 1.10.0 → 1.11.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/index.cjs CHANGED
@@ -27,7 +27,29 @@ const jsxRuntime = require("react/jsx-runtime");
27
27
  const React = require("react");
28
28
  const client = require("react-dom/client");
29
29
  const core = require("@smilodon/core");
30
+ const DEFAULT_DATA_LOADING_CONFIG = {
31
+ protocol: "legacy",
32
+ searchMode: "local",
33
+ paginationMode: "page",
34
+ firstPage: 1
35
+ };
36
+ function isPlainRecord(value) {
37
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
38
+ return false;
39
+ }
40
+ const prototype = Object.getPrototypeOf(value);
41
+ return prototype === Object.prototype || prototype === null;
42
+ }
43
+ function isBusyToken(value) {
44
+ return value === true || value === "true";
45
+ }
46
+ function composeBusyToken(consumerValue, externalBusy) {
47
+ if (externalBusy || isBusyToken(consumerValue)) return "true";
48
+ if (consumerValue === false || consumerValue === "false") return consumerValue;
49
+ return consumerValue;
50
+ }
30
51
  const Select = React.forwardRef((props, ref) => {
52
+ var _a, _b;
31
53
  const {
32
54
  items = [],
33
55
  groupedItems,
@@ -51,6 +73,7 @@ const Select = React.forwardRef((props, ref) => {
51
73
  styles: stylesConfig,
52
74
  config: coreConfig,
53
75
  removeButtonIcon,
76
+ arrowIcon,
54
77
  disabledOptionBehavior,
55
78
  showSelectedIndicator = true,
56
79
  toggleOnTriggerClick = true,
@@ -75,6 +98,9 @@ const Select = React.forwardRef((props, ref) => {
75
98
  onLoadMore,
76
99
  onClear,
77
100
  onDiagnostic,
101
+ onDataRequestCancel,
102
+ onDataProjection,
103
+ onDataLoadingConfigError,
78
104
  trackingEnabled = false,
79
105
  trackEvents = true,
80
106
  trackStyling = true,
@@ -88,16 +114,65 @@ const Select = React.forwardRef((props, ref) => {
88
114
  onCreate,
89
115
  classMap,
90
116
  groupHeaderRenderer,
117
+ "aria-busy": consumerAriaBusy,
91
118
  ...hostProps
92
119
  } = props;
120
+ const [isControlled] = React.useState(value !== void 0);
121
+ const [internalValue, setInternalValue] = React.useState(defaultValue);
122
+ const hasAppliedInitialValueRef = React.useRef(false);
93
123
  const elementRef = React.useRef(null);
124
+ const coreModuleRef = React.useRef(null);
125
+ const acceptedDataLoadingConfigRef = React.useRef({
126
+ ...DEFAULT_DATA_LOADING_CONFIG
127
+ });
128
+ const configUpdateStackRef = React.useRef([]);
129
+ const configUpdateInProgressRef = React.useRef(false);
130
+ const queuedConfigUpdatesRef = React.useRef([]);
131
+ const queuedImperativeConfigsRef = React.useRef([]);
132
+ const activeListenersRef = React.useRef(null);
133
+ const callbackStateRef = React.useRef({
134
+ onSelect,
135
+ onChange,
136
+ onOpen,
137
+ onClose,
138
+ onSearch,
139
+ onLoadMore,
140
+ onClear,
141
+ onDiagnostic,
142
+ onDataRequestCancel,
143
+ onDataProjection,
144
+ onDataLoadingConfigError,
145
+ isControlled,
146
+ multiple
147
+ });
148
+ callbackStateRef.current = {
149
+ onSelect,
150
+ onChange,
151
+ onOpen,
152
+ onClose,
153
+ onSearch,
154
+ onLoadMore,
155
+ onClear,
156
+ onDiagnostic,
157
+ onDataRequestCancel,
158
+ onDataProjection,
159
+ onDataLoadingConfigError,
160
+ isControlled,
161
+ multiple
162
+ };
163
+ const ariaBusyInputsRef = React.useRef({ consumerAriaBusy, loading });
164
+ ariaBusyInputsRef.current = { consumerAriaBusy, loading };
165
+ const initializingRef = React.useRef(true);
166
+ const compatibilityFailureReportedRef = React.useRef(false);
167
+ const unusableRef = React.useRef(false);
168
+ const [acceptedProtocol, setAcceptedProtocol] = React.useState("legacy");
169
+ const [isCoreModuleLoaded, setIsCoreModuleLoaded] = React.useState(false);
170
+ const [isAcknowledgedQualified, setIsAcknowledgedQualified] = React.useState(false);
171
+ const [isUnusable, setIsUnusable] = React.useState(false);
94
172
  const resolvedDropdownPlacement = React.useMemo(() => {
95
173
  if (placement == null ? void 0 : placement.startsWith("top")) return "top";
96
174
  return "bottom";
97
175
  }, [placement]);
98
- const [isControlled] = React.useState(value !== void 0);
99
- const [internalValue, setInternalValue] = React.useState(defaultValue);
100
- const hasAppliedInitialValueRef = React.useRef(false);
101
176
  const reactRendererCache = React.useRef(
102
177
  /* @__PURE__ */ new Map()
103
178
  );
@@ -148,8 +223,8 @@ const Select = React.forwardRef((props, ref) => {
148
223
  const resolvedOptionRenderer = React.useMemo(() => {
149
224
  if (optionRenderer) {
150
225
  return (item, index, helpers) => {
151
- var _a;
152
- return ((_a = optionRendererRef.current) == null ? void 0 : _a.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
226
+ var _a2;
227
+ return ((_a2 = optionRendererRef.current) == null ? void 0 : _a2.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
153
228
  };
154
229
  }
155
230
  const hasReactRenderer = !!(customRenderer ?? renderItem);
@@ -228,6 +303,240 @@ const Select = React.forwardRef((props, ref) => {
228
303
  reactRendererCache.current.clear();
229
304
  }, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
230
305
  const [isElementReady, setIsElementReady] = React.useState(false);
306
+ const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_a = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _a.protocol) === "acknowledged";
307
+ const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
308
+ const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
309
+ const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
310
+ const markUnusable = React.useCallback(
311
+ (message) => {
312
+ if (unusableRef.current) return;
313
+ unusableRef.current = true;
314
+ setIsUnusable(true);
315
+ const element = elementRef.current;
316
+ const { consumerAriaBusy: currentConsumerBusy } = ariaBusyInputsRef.current;
317
+ if (element) {
318
+ if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
319
+ else element.setAttribute("aria-busy", String(currentConsumerBusy));
320
+ }
321
+ if (!compatibilityFailureReportedRef.current) {
322
+ compatibilityFailureReportedRef.current = true;
323
+ console.error(`[Smilodon React] ${message}`);
324
+ }
325
+ },
326
+ []
327
+ );
328
+ const syncHostBusy = React.useCallback((element) => {
329
+ const { consumerAriaBusy: currentConsumerBusy, loading: externalBusy } = ariaBusyInputsRef.current;
330
+ if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged" && !unusableRef.current) {
331
+ const composed = composeBusyToken(currentConsumerBusy, externalBusy);
332
+ if (composed === void 0) element.removeAttribute("aria-busy");
333
+ else element.setAttribute("aria-busy", String(composed));
334
+ return;
335
+ }
336
+ if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
337
+ else element.setAttribute("aria-busy", String(currentConsumerBusy));
338
+ }, []);
339
+ const applyInstanceConfig = React.useCallback(
340
+ (element, config) => {
341
+ if (!(element == null ? void 0 : element.updateConfig) || unusableRef.current) return;
342
+ if (configUpdateInProgressRef.current) {
343
+ queuedConfigUpdatesRef.current.push({ ...config });
344
+ return;
345
+ }
346
+ configUpdateInProgressRef.current = true;
347
+ const queue = [{ ...config }];
348
+ let processed = 0;
349
+ try {
350
+ while (queue.length > 0 && !unusableRef.current) {
351
+ if (processed++ >= 100) {
352
+ queuedConfigUpdatesRef.current = [];
353
+ markUnusable(
354
+ "Too many reentrant configuration updates were queued; the wrapper has been stopped to avoid an unbounded update loop."
355
+ );
356
+ break;
357
+ }
358
+ const currentConfig = queue.shift();
359
+ const module2 = coreModuleRef.current;
360
+ let validation;
361
+ if (currentConfig.dataLoading !== void 0) {
362
+ const candidate = isPlainRecord(currentConfig.dataLoading) ? { ...acceptedDataLoadingConfigRef.current, ...currentConfig.dataLoading } : currentConfig.dataLoading;
363
+ if (!module2) {
364
+ markUnusable(
365
+ "The core validator is unavailable; acknowledged configuration cannot be reconciled safely."
366
+ );
367
+ break;
368
+ }
369
+ try {
370
+ validation = module2.validateDataLoadingConfig(candidate);
371
+ } catch (error2) {
372
+ markUnusable(
373
+ `Core data-loading preflight failed unexpectedly: ${String(error2)}`
374
+ );
375
+ break;
376
+ }
377
+ }
378
+ const update = { sawConfigError: false };
379
+ configUpdateStackRef.current.push(update);
380
+ let threw = false;
381
+ try {
382
+ element.updateConfig(currentConfig);
383
+ } catch (error2) {
384
+ threw = true;
385
+ markUnusable(
386
+ `Core configuration acceptance is uncertain after updateConfig() threw: ${String(error2)}`
387
+ );
388
+ } finally {
389
+ configUpdateStackRef.current.pop();
390
+ }
391
+ if ((validation == null ? void 0 : validation.valid) && !threw) {
392
+ if (update.sawConfigError) {
393
+ markUnusable(
394
+ "Core reported a data-loading configuration error for a preflight-valid candidate; the accepted protocol is uncertain."
395
+ );
396
+ break;
397
+ }
398
+ acceptedDataLoadingConfigRef.current = { ...validation.value };
399
+ setAcceptedProtocol(validation.value.protocol);
400
+ syncHostBusy(element);
401
+ }
402
+ if (queuedConfigUpdatesRef.current.length > 0) {
403
+ queue.push(...queuedConfigUpdatesRef.current);
404
+ queuedConfigUpdatesRef.current = [];
405
+ }
406
+ }
407
+ } finally {
408
+ configUpdateInProgressRef.current = false;
409
+ }
410
+ },
411
+ [markUnusable, syncHostBusy]
412
+ );
413
+ const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
414
+ const qualifyAcknowledgedElement = React.useCallback(() => {
415
+ const element = elementRef.current;
416
+ const module2 = coreModuleRef.current;
417
+ if (!element || !module2 || typeof customElements === "undefined") return false;
418
+ const registered = customElements.get("enhanced-select");
419
+ const observed = registered == null ? void 0 : registered.observedAttributes;
420
+ const compatible = registered === module2.EnhancedSelect && element.constructor === module2.EnhancedSelect && Array.isArray(observed) && observed.includes("aria-busy") && typeof element.updateConfig === "function" && typeof element.startDataLoading === "function" && typeof element.getDataLoadingState === "function" && typeof element.completeDataRequest === "function";
421
+ if (!compatible) {
422
+ markUnusable(
423
+ "Acknowledged data loading requires the exact peer-resolved EnhancedSelect constructor with the Phase 2F facade and aria-busy observation support."
424
+ );
425
+ return false;
426
+ }
427
+ setIsAcknowledgedQualified(true);
428
+ return true;
429
+ }, [markUnusable]);
430
+ const subscribeToCoreEvents = React.useCallback((element) => {
431
+ const currentSubscription = activeListenersRef.current;
432
+ if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
433
+ currentSubscription == null ? void 0 : currentSubscription.dispose();
434
+ const handleSelect = (event) => {
435
+ var _a2, _b2;
436
+ const detail = event.detail;
437
+ (_b2 = (_a2 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a2, detail.item, detail.index);
438
+ };
439
+ const handleChange = (event) => {
440
+ var _a2;
441
+ const { selectedItems, selectedValues } = event.detail;
442
+ const callbacks = callbackStateRef.current;
443
+ const values = selectedValues;
444
+ const nextSingleValue = values.length > 0 ? values[0] : "";
445
+ if (initializingRef.current) return;
446
+ if (!callbacks.isControlled) {
447
+ setInternalValue(callbacks.multiple ? values : nextSingleValue);
448
+ }
449
+ (_a2 = callbacks.onChange) == null ? void 0 : _a2.call(
450
+ callbacks,
451
+ callbacks.multiple ? values : nextSingleValue,
452
+ selectedItems
453
+ );
454
+ };
455
+ const handleOpen = () => {
456
+ var _a2, _b2;
457
+ return (_b2 = (_a2 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a2);
458
+ };
459
+ const handleClose = () => {
460
+ var _a2, _b2;
461
+ return (_b2 = (_a2 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a2);
462
+ };
463
+ const handleSearch = (event) => {
464
+ const { query, results, count, request } = event.detail;
465
+ const callback = callbackStateRef.current.onSearch;
466
+ if (!callback) return;
467
+ if (request) callback(query, results, count, request);
468
+ else callback(query, results, count);
469
+ };
470
+ const handleLoadMore = (event) => {
471
+ const { page, request } = event.detail;
472
+ const callback = callbackStateRef.current.onLoadMore;
473
+ if (!callback) return;
474
+ if (request) callback(page, request);
475
+ else callback(page);
476
+ };
477
+ const handleClear = (event) => {
478
+ var _a2, _b2;
479
+ const { clearedSelection, clearedSearch } = event.detail;
480
+ (_b2 = (_a2 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a2, { clearedSelection, clearedSearch });
481
+ };
482
+ const handleDiagnostic = (event) => {
483
+ var _a2, _b2;
484
+ (_b2 = (_a2 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
485
+ _a2,
486
+ event.detail
487
+ );
488
+ };
489
+ const handleDataRequestCancel = (event) => {
490
+ var _a2, _b2;
491
+ (_b2 = (_a2 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
492
+ _a2,
493
+ event.detail
494
+ );
495
+ };
496
+ const handleDataProjection = (event) => {
497
+ var _a2, _b2;
498
+ (_b2 = (_a2 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
499
+ _a2,
500
+ event.detail
501
+ );
502
+ };
503
+ const handleDataLoadingConfigError = (event) => {
504
+ var _a2, _b2;
505
+ const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
506
+ if (activeUpdate) activeUpdate.sawConfigError = true;
507
+ (_b2 = (_a2 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
508
+ _a2,
509
+ event.detail
510
+ );
511
+ };
512
+ const listeners = [
513
+ ["select", handleSelect],
514
+ ["change", handleChange],
515
+ ["open", handleOpen],
516
+ ["close", handleClose],
517
+ ["search", handleSearch],
518
+ ["loadMore", handleLoadMore],
519
+ ["clear", handleClear],
520
+ ["diagnostic", handleDiagnostic],
521
+ ["dataRequestCancel", handleDataRequestCancel],
522
+ ["dataProjection", handleDataProjection],
523
+ ["dataLoadingConfigError", handleDataLoadingConfigError]
524
+ ];
525
+ for (const [name, listener] of listeners) {
526
+ element.addEventListener(name, listener);
527
+ }
528
+ const dispose = () => {
529
+ var _a2;
530
+ if (((_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose) === dispose) {
531
+ activeListenersRef.current = null;
532
+ }
533
+ for (const [name, listener] of listeners) {
534
+ element.removeEventListener(name, listener);
535
+ }
536
+ };
537
+ activeListenersRef.current = { element, dispose };
538
+ return dispose;
539
+ }, []);
231
540
  React.useEffect(() => {
232
541
  const element = elementRef.current;
233
542
  if (!element || !isElementReady) return;
@@ -258,23 +567,61 @@ const Select = React.forwardRef((props, ref) => {
258
567
  }
259
568
  }, [isElementReady, classMap, areClassMapsEqual]);
260
569
  React.useEffect(() => {
261
- if (typeof window !== "undefined") {
262
- if (customElements.get("enhanced-select")) {
263
- setIsElementReady(true);
264
- } else {
265
- import("@smilodon/core").then((module2) => {
266
- if (!customElements.get("enhanced-select")) {
267
- customElements.define("enhanced-select", module2.EnhancedSelect);
268
- }
269
- setIsElementReady(true);
270
- });
570
+ if (typeof window === "undefined" || typeof customElements === "undefined") return;
571
+ let active = true;
572
+ const existingConstructor = customElements.get("enhanced-select");
573
+ if (existingConstructor) setIsElementReady(true);
574
+ import("@smilodon/core").then((module2) => {
575
+ if (!active) return;
576
+ coreModuleRef.current = module2;
577
+ setIsCoreModuleLoaded(true);
578
+ const currentConstructor = customElements.get("enhanced-select");
579
+ if (!currentConstructor) {
580
+ customElements.define("enhanced-select", module2.EnhancedSelect);
271
581
  }
272
- }
582
+ setIsElementReady(true);
583
+ }).catch((error2) => {
584
+ if (!active) return;
585
+ if (requiresAcknowledgedQualification) {
586
+ markUnusable(`Unable to load the compatible core runtime: ${String(error2)}`);
587
+ } else if (!customElements.get("enhanced-select")) {
588
+ console.error(`[Smilodon React] Unable to register enhanced-select: ${String(error2)}`);
589
+ }
590
+ });
591
+ return () => {
592
+ active = false;
593
+ };
594
+ }, [markUnusable]);
595
+ React.useEffect(() => {
596
+ if (!isElementReady || !isCoreModuleLoaded || !requiresAcknowledgedQualification || isUnusable) return;
597
+ qualifyAcknowledgedElement();
598
+ }, [
599
+ isElementReady,
600
+ isCoreModuleLoaded,
601
+ requiresAcknowledgedQualification,
602
+ isUnusable,
603
+ qualifyAcknowledgedElement
604
+ ]);
605
+ React.useEffect(() => {
606
+ const element = elementRef.current;
607
+ if (!(acknowledgedRequested || dataLoadingConfigured) || !isElementUsable || !element) return;
608
+ return subscribeToCoreEvents(element);
609
+ }, [
610
+ acknowledgedRequested,
611
+ dataLoadingConfigured,
612
+ isElementUsable,
613
+ subscribeToCoreEvents
614
+ ]);
615
+ React.useEffect(() => {
616
+ return () => {
617
+ var _a2;
618
+ return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
619
+ };
273
620
  }, []);
274
621
  React.useEffect(() => {
275
- var _a;
622
+ var _a2;
276
623
  const element = elementRef.current;
277
- if (!element || !isElementReady) return;
624
+ if (!element || !isElementUsable) return;
278
625
  if (!element.setItems) {
279
626
  console.warn("Enhanced select element not fully initialized yet");
280
627
  return;
@@ -334,13 +681,13 @@ const Select = React.forwardRef((props, ref) => {
334
681
  autoMitigateRuntimeModeSwitch
335
682
  }
336
683
  };
337
- element.updateConfig(config);
684
+ applyInstanceConfig(element, config);
338
685
  if (coreConfig) {
339
- element.updateConfig(coreConfig);
686
+ applyInstanceConfig(element, coreConfig);
340
687
  }
341
688
  if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
342
689
  const values = Array.isArray(internalValue) ? internalValue : [internalValue];
343
- const currentValues = ((_a = element.getSelectedValues) == null ? void 0 : _a.call(element)) || [];
690
+ const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
344
691
  if (!areValuesEqual(values, currentValues)) {
345
692
  element.setSelectedValues(values);
346
693
  }
@@ -355,7 +702,7 @@ const Select = React.forwardRef((props, ref) => {
355
702
  element.setRequired(true);
356
703
  }
357
704
  }, [
358
- isElementReady,
705
+ isElementUsable,
359
706
  items,
360
707
  groupedItems,
361
708
  searchable,
@@ -397,11 +744,12 @@ const Select = React.forwardRef((props, ref) => {
397
744
  required,
398
745
  internalValue,
399
746
  isControlled,
400
- areValuesEqual
747
+ areValuesEqual,
748
+ applyInstanceConfig
401
749
  ]);
402
750
  React.useEffect(() => {
403
751
  const element = elementRef.current;
404
- if (!element || !isElementReady || !element.setItems) return;
752
+ if (!element || !isElementUsable || !element.setItems) return;
405
753
  if (groupedItems) {
406
754
  element.setGroupedItems(groupedItems);
407
755
  } else if (items && items.length && items[0] && items[0].group !== void 0) {
@@ -419,23 +767,23 @@ const Select = React.forwardRef((props, ref) => {
419
767
  } else {
420
768
  element.setItems(items);
421
769
  }
422
- }, [items, groupedItems, isElementReady]);
770
+ }, [items, groupedItems, isElementUsable]);
423
771
  React.useEffect(() => {
424
- var _a;
772
+ var _a2;
425
773
  const element = elementRef.current;
426
- if (!element || !isControlled || !isElementReady || !element.setSelectedValues)
774
+ if (!element || !isControlled || !isElementUsable || !element.setSelectedValues)
427
775
  return;
428
776
  if (value !== void 0) {
429
777
  const values = Array.isArray(value) ? value : [value];
430
- const currentValues = ((_a = element.getSelectedValues) == null ? void 0 : _a.call(element)) || [];
778
+ const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
431
779
  if (!areValuesEqual(values, currentValues)) {
432
780
  element.setSelectedValues(values);
433
781
  }
434
782
  }
435
- }, [value, isControlled, isElementReady, areValuesEqual]);
783
+ }, [value, isControlled, isElementUsable, areValuesEqual]);
436
784
  React.useEffect(() => {
437
785
  const element = elementRef.current;
438
- if (!element || !isElementReady || !element.updateConfig) return;
786
+ if (!element || !isElementUsable || !element.updateConfig) return;
439
787
  const config = {
440
788
  searchable,
441
789
  placeholder,
@@ -485,9 +833,9 @@ const Select = React.forwardRef((props, ref) => {
485
833
  autoMitigateRuntimeModeSwitch
486
834
  }
487
835
  };
488
- element.updateConfig(config);
836
+ applyInstanceConfig(element, config);
489
837
  if (coreConfig) {
490
- element.updateConfig(coreConfig);
838
+ applyInstanceConfig(element, coreConfig);
491
839
  }
492
840
  }, [
493
841
  searchable,
@@ -523,188 +871,232 @@ const Select = React.forwardRef((props, ref) => {
523
871
  autoMitigateRuntimeModeSwitch,
524
872
  direction,
525
873
  resolvedDropdownPlacement,
526
- isElementReady
874
+ isElementUsable,
875
+ applyInstanceConfig
527
876
  ]);
528
877
  React.useEffect(() => {
529
878
  const element = elementRef.current;
530
- if (!element || !isElementReady) return;
879
+ if (!element || !isElementUsable) return;
531
880
  if (error) {
532
881
  if (element.setError)
533
882
  element.setError(errorMessage || "Invalid selection");
534
883
  } else {
535
884
  if (element.clearError) element.clearError();
536
885
  }
537
- }, [error, errorMessage, isElementReady]);
886
+ }, [error, errorMessage, isElementUsable]);
538
887
  React.useEffect(() => {
539
888
  const element = elementRef.current;
540
- if (!element || !isElementReady || !element.setRequired) return;
889
+ if (!element || !isElementUsable || !element.setRequired) return;
541
890
  element.setRequired(required);
542
- }, [required, isElementReady]);
891
+ }, [required, isElementUsable]);
543
892
  React.useEffect(() => {
893
+ var _a2, _b2;
544
894
  const element = elementRef.current;
545
- if (!element) return;
546
- const handleSelect = (e) => {
547
- const { item, index } = e.detail;
548
- onSelect == null ? void 0 : onSelect(item, index);
549
- };
550
- const handleChange = (e) => {
551
- const { selectedItems, selectedValues } = e.detail;
552
- const values = selectedValues;
553
- const nextSingleValue = values.length > 0 ? values[0] : "";
554
- if (!isControlled) {
555
- setInternalValue(multiple ? values : nextSingleValue);
556
- }
557
- if (onChange) {
558
- const value2 = multiple ? values : nextSingleValue;
559
- onChange(value2, selectedItems);
895
+ if (!element || !isElementUsable) return;
896
+ if (isCoreModuleLoaded && queuedImperativeConfigsRef.current.length > 0) {
897
+ const queued = queuedImperativeConfigsRef.current;
898
+ queuedImperativeConfigsRef.current = [];
899
+ for (const config of queued) {
900
+ const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
901
+ if (requestsAcknowledged && !qualifyAcknowledgedElement()) break;
902
+ if (config.dataLoading !== void 0 || requestsAcknowledged) {
903
+ subscribeToCoreEvents(element);
904
+ }
905
+ applyInstanceConfig(element, config);
906
+ if (unusableRef.current) break;
560
907
  }
561
- };
562
- const handleOpen = (e) => {
563
- onOpen == null ? void 0 : onOpen();
564
- };
565
- const handleClose = (e) => {
566
- onClose == null ? void 0 : onClose();
567
- };
568
- const handleSearch = (e) => {
569
- const { query, results, count } = e.detail;
570
- onSearch == null ? void 0 : onSearch(query, results, count);
571
- };
572
- const handleLoadMore = (e) => {
573
- const { page } = e.detail;
574
- onLoadMore == null ? void 0 : onLoadMore(page);
575
- };
576
- const handleClear = (e) => {
577
- onClear == null ? void 0 : onClear({
578
- clearedSelection: e.detail.clearedSelection,
579
- clearedSearch: e.detail.clearedSearch
580
- });
581
- };
582
- const handleDiagnostic = (e) => {
583
- onDiagnostic == null ? void 0 : onDiagnostic(e.detail);
584
- };
585
- element.addEventListener("select", handleSelect);
586
- element.addEventListener("change", handleChange);
587
- element.addEventListener("open", handleOpen);
588
- element.addEventListener("close", handleClose);
589
- element.addEventListener("search", handleSearch);
590
- element.addEventListener("loadMore", handleLoadMore);
591
- element.addEventListener("clear", handleClear);
592
- element.addEventListener("diagnostic", handleDiagnostic);
593
- return () => {
594
- element.removeEventListener("select", handleSelect);
595
- element.removeEventListener("change", handleChange);
596
- element.removeEventListener("open", handleOpen);
597
- element.removeEventListener("close", handleClose);
598
- element.removeEventListener("search", handleSearch);
599
- element.removeEventListener("loadMore", handleLoadMore);
600
- element.removeEventListener("clear", handleClear);
601
- element.removeEventListener("diagnostic", handleDiagnostic);
602
- };
908
+ }
909
+ initializingRef.current = false;
910
+ syncHostBusy(element);
911
+ if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged") {
912
+ (_b2 = element.startDataLoading) == null ? void 0 : _b2.call(element);
913
+ }
603
914
  }, [
604
- onSelect,
605
- onChange,
606
- onOpen,
607
- onClose,
608
- onSearch,
609
- onLoadMore,
610
- onClear,
611
- onDiagnostic,
612
- isControlled,
613
- multiple
915
+ isElementUsable,
916
+ acceptedProtocol,
917
+ acknowledgedRequested,
918
+ coreConfig,
919
+ items,
920
+ groupedItems,
921
+ value,
922
+ defaultValue,
923
+ loading,
924
+ consumerAriaBusy,
925
+ syncHostBusy,
926
+ isCoreModuleLoaded,
927
+ qualifyAcknowledgedElement,
928
+ subscribeToCoreEvents,
929
+ applyInstanceConfig
930
+ ]);
931
+ React.useEffect(() => {
932
+ const element = elementRef.current;
933
+ if (!element || acknowledgedRequested || dataLoadingConfigured || !isElementReady) return;
934
+ return subscribeToCoreEvents(element);
935
+ }, [
936
+ acknowledgedRequested,
937
+ dataLoadingConfigured,
938
+ isElementReady,
939
+ subscribeToCoreEvents
614
940
  ]);
615
941
  React.useImperativeHandle(ref, () => ({
616
942
  focus: () => {
617
- var _a;
618
- (_a = elementRef.current) == null ? void 0 : _a.focus();
943
+ var _a2;
944
+ const element = elementRef.current;
945
+ const input = (_a2 = element == null ? void 0 : element.shadowRoot) == null ? void 0 : _a2.querySelector("input");
946
+ if (input instanceof HTMLElement) {
947
+ input.focus();
948
+ } else {
949
+ element == null ? void 0 : element.focus();
950
+ }
619
951
  },
620
952
  open: () => {
621
- var _a;
622
- (_a = elementRef.current) == null ? void 0 : _a.open();
953
+ var _a2;
954
+ (_a2 = elementRef.current) == null ? void 0 : _a2.open();
623
955
  },
624
956
  close: () => {
625
- var _a;
626
- (_a = elementRef.current) == null ? void 0 : _a.close();
957
+ var _a2;
958
+ (_a2 = elementRef.current) == null ? void 0 : _a2.close();
627
959
  },
628
960
  getSelectedItems: () => {
629
- var _a;
630
- return ((_a = elementRef.current) == null ? void 0 : _a.getSelectedItems()) || [];
961
+ var _a2;
962
+ return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedItems()) || [];
631
963
  },
632
964
  getSelectedValues: () => {
633
- var _a;
634
- return ((_a = elementRef.current) == null ? void 0 : _a.getSelectedValues()) || [];
965
+ var _a2;
966
+ return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
635
967
  },
636
968
  setItems: (items2) => {
637
- var _a;
638
- (_a = elementRef.current) == null ? void 0 : _a.setItems(items2);
969
+ var _a2;
970
+ (_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
639
971
  },
640
972
  setGroupedItems: (groups) => {
641
- var _a;
642
- (_a = elementRef.current) == null ? void 0 : _a.setGroupedItems(groups);
973
+ var _a2;
974
+ (_a2 = elementRef.current) == null ? void 0 : _a2.setGroupedItems(groups);
643
975
  },
644
976
  clear: () => {
645
- var _a;
646
- (_a = elementRef.current) == null ? void 0 : _a.setSelectedValues([]);
977
+ var _a2;
978
+ (_a2 = elementRef.current) == null ? void 0 : _a2.setSelectedValues([]);
647
979
  if (!isControlled) {
648
980
  setInternalValue(multiple ? [] : void 0);
649
981
  }
650
982
  onChange == null ? void 0 : onChange(multiple ? [] : "", []);
651
983
  },
652
984
  clearSearch: () => {
653
- var _a, _b;
654
- (_b = (_a = elementRef.current) == null ? void 0 : _a.clearSearch) == null ? void 0 : _b.call(_a);
985
+ var _a2, _b2;
986
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearSearch) == null ? void 0 : _b2.call(_a2);
655
987
  },
656
988
  updateConfig: (config) => {
657
- var _a, _b;
658
- (_b = (_a = elementRef.current) == null ? void 0 : _a.updateConfig) == null ? void 0 : _b.call(_a, config);
989
+ var _a2;
990
+ const element = elementRef.current;
991
+ if (!element || unusableRef.current) return;
992
+ const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
993
+ if (!isElementReady || !isCoreModuleLoaded) {
994
+ queuedImperativeConfigsRef.current.push({ ...config });
995
+ return;
996
+ }
997
+ if (requestsAcknowledged && !qualifyAcknowledgedElement()) return;
998
+ if (config.dataLoading !== void 0 || requestsAcknowledged) {
999
+ subscribeToCoreEvents(element);
1000
+ }
1001
+ applyInstanceConfig(element, config);
1002
+ },
1003
+ getDataLoadingState: () => {
1004
+ var _a2, _b2, _c;
1005
+ const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
1006
+ if (snapshot) return snapshot;
1007
+ return {
1008
+ status: "idle",
1009
+ connected: Boolean((_c = elementRef.current) == null ? void 0 : _c.isConnected),
1010
+ busy: false,
1011
+ projectionPending: false,
1012
+ queryGeneration: 0,
1013
+ activeRequest: null,
1014
+ hasMore: false,
1015
+ nextEligiblePosition: {
1016
+ mode: "page",
1017
+ page: DEFAULT_DATA_LOADING_CONFIG.firstPage
1018
+ },
1019
+ error: null,
1020
+ resourceLimit: null
1021
+ };
1022
+ },
1023
+ completeDataRequest: (completion) => {
1024
+ var _a2, _b2;
1025
+ return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.completeDataRequest) == null ? void 0 : _b2.call(_a2, completion)) ?? "unknown-request";
659
1026
  },
660
1027
  setError: (message) => {
661
- var _a, _b;
662
- (_b = (_a = elementRef.current) == null ? void 0 : _a.setError) == null ? void 0 : _b.call(_a, message);
1028
+ var _a2, _b2;
1029
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setError) == null ? void 0 : _b2.call(_a2, message);
663
1030
  },
664
1031
  clearError: () => {
665
- var _a, _b;
666
- (_b = (_a = elementRef.current) == null ? void 0 : _a.clearError) == null ? void 0 : _b.call(_a);
1032
+ var _a2, _b2;
1033
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearError) == null ? void 0 : _b2.call(_a2);
667
1034
  },
668
1035
  setRequired: (isRequired) => {
669
- var _a, _b;
670
- (_b = (_a = elementRef.current) == null ? void 0 : _a.setRequired) == null ? void 0 : _b.call(_a, isRequired);
1036
+ var _a2, _b2;
1037
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setRequired) == null ? void 0 : _b2.call(_a2, isRequired);
671
1038
  },
672
1039
  validate: () => {
673
- var _a, _b;
674
- return ((_b = (_a = elementRef.current) == null ? void 0 : _a.validate) == null ? void 0 : _b.call(_a)) ?? true;
1040
+ var _a2, _b2;
1041
+ return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.validate) == null ? void 0 : _b2.call(_a2)) ?? true;
675
1042
  },
676
1043
  getCapabilities: () => {
677
- var _a, _b;
678
- return (_b = (_a = elementRef.current) == null ? void 0 : _a.getCapabilities) == null ? void 0 : _b.call(_a);
1044
+ var _a2, _b2;
1045
+ return (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getCapabilities) == null ? void 0 : _b2.call(_a2);
679
1046
  },
680
1047
  getKnownLimitations: () => {
681
- var _a, _b;
682
- return ((_b = (_a = elementRef.current) == null ? void 0 : _a.getKnownLimitations) == null ? void 0 : _b.call(_a)) || [];
1048
+ var _a2, _b2;
1049
+ return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getKnownLimitations) == null ? void 0 : _b2.call(_a2)) || [];
683
1050
  },
684
1051
  getTrackingSnapshot: () => {
685
- var _a, _b;
686
- return ((_b = (_a = elementRef.current) == null ? void 0 : _a.getTrackingSnapshot) == null ? void 0 : _b.call(_a)) || {
1052
+ var _a2, _b2;
1053
+ return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getTrackingSnapshot) == null ? void 0 : _b2.call(_a2)) || {
687
1054
  events: [],
688
1055
  styles: [],
689
1056
  limitations: []
690
1057
  };
691
1058
  },
692
1059
  clearTracking: (source) => {
693
- var _a, _b;
694
- (_b = (_a = elementRef.current) == null ? void 0 : _a.clearTracking) == null ? void 0 : _b.call(_a, source);
1060
+ var _a2, _b2;
1061
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearTracking) == null ? void 0 : _b2.call(_a2, source);
695
1062
  },
696
1063
  setLimitationPolicies: (policies) => {
697
- var _a, _b;
698
- (_b = (_a = elementRef.current) == null ? void 0 : _a.setLimitationPolicies) == null ? void 0 : _b.call(_a, policies);
1064
+ var _a2, _b2;
1065
+ (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setLimitationPolicies) == null ? void 0 : _b2.call(_a2, policies);
699
1066
  }
700
- }));
701
- return React.createElement("enhanced-select", {
702
- ref: elementRef,
703
- ...hostProps,
704
- className,
705
- dir: direction,
706
- style
707
- });
1067
+ }), [
1068
+ applyInstanceConfig,
1069
+ isElementReady,
1070
+ isCoreModuleLoaded,
1071
+ qualifyAcknowledgedElement,
1072
+ subscribeToCoreEvents,
1073
+ isElementUsable,
1074
+ isControlled,
1075
+ multiple,
1076
+ onChange
1077
+ ]);
1078
+ const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
1079
+ return React.createElement(
1080
+ "enhanced-select",
1081
+ {
1082
+ ref: elementRef,
1083
+ ...hostProps,
1084
+ "aria-busy": renderedAriaBusy,
1085
+ "data-custom-arrow": arrowIcon != null ? "true" : void 0,
1086
+ class: className,
1087
+ dir: direction,
1088
+ style
1089
+ },
1090
+ arrowIcon != null ? React.createElement(
1091
+ "span",
1092
+ {
1093
+ slot: "arrow",
1094
+ className: "smilodon-custom-arrow",
1095
+ "aria-hidden": "true"
1096
+ },
1097
+ arrowIcon
1098
+ ) : null
1099
+ );
708
1100
  });
709
1101
  Select.displayName = "Select";
710
1102
  Object.defineProperty(exports, "configureSelect", {