@smilodon/core 1.12.0 → 1.17.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.js CHANGED
@@ -2105,6 +2105,8 @@ const defaultConfig = {
2105
2105
  overflowX: 'hidden',
2106
2106
  overflowY: 'auto',
2107
2107
  dragScroll: true,
2108
+ scrollToLatestChip: false,
2109
+ scrollToLatestChipBehavior: 'smooth',
2108
2110
  },
2109
2111
  scrollToSelected: {
2110
2112
  enabled: true,
@@ -2121,8 +2123,10 @@ const defaultConfig = {
2121
2123
  busyBucket: {
2122
2124
  enabled: true,
2123
2125
  showSpinner: true,
2126
+ showMessage: true,
2124
2127
  message: 'Loading...',
2125
2128
  minDisplayTime: 200,
2129
+ contentMode: 'append',
2126
2130
  },
2127
2131
  styles: {
2128
2132
  classNames: {},
@@ -2968,23 +2972,23 @@ class SelectOption extends HTMLElement {
2968
2972
  }
2969
2973
  }
2970
2974
  _attachEventListeners() {
2971
- // Click handler for selection
2975
+ // One delegated handler survives all SelectOption re-renders. In
2976
+ // particular, SVG descendants of the remove icon must remove the option,
2977
+ // not accidentally activate the surrounding option.
2972
2978
  this._container.addEventListener('click', (e) => {
2973
- // Don't trigger selection if clicking remove button
2974
- if (e.target === this._removeButton) {
2979
+ const target = e.target;
2980
+ if (this._removeButton
2981
+ && target instanceof Node
2982
+ && this._removeButton.contains(target)) {
2983
+ e.preventDefault();
2984
+ e.stopPropagation();
2985
+ this._handleRemove();
2975
2986
  return;
2976
2987
  }
2977
2988
  if (!this._isDisabledSelectionBlocked()) {
2978
2989
  this._handleSelect();
2979
2990
  }
2980
2991
  });
2981
- // Remove button handler
2982
- if (this._removeButton) {
2983
- this._removeButton.addEventListener('click', (e) => {
2984
- e.stopPropagation();
2985
- this._handleRemove();
2986
- });
2987
- }
2988
2992
  // Keyboard handler
2989
2993
  this.addEventListener('keydown', (e) => {
2990
2994
  if (this._isDisabledSelectionBlocked())
@@ -3047,7 +3051,6 @@ class SelectOption extends HTMLElement {
3047
3051
  updateConfig(updates) {
3048
3052
  this._config = { ...this._config, ...updates };
3049
3053
  this._render();
3050
- this._attachEventListeners();
3051
3054
  }
3052
3055
  /**
3053
3056
  * Get current configuration
@@ -4041,6 +4044,10 @@ class EnhancedSelect extends HTMLElement {
4041
4044
  super();
4042
4045
  this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
4043
4046
  this._hasLastInvalidDataLoadingCandidate = false;
4047
+ this._busyPresentationVisible = false;
4048
+ this._busyPresentationStartedAt = null;
4049
+ this._busyPresentationGeneration = 0;
4050
+ this._busyPresentationHideTimer = null;
4044
4051
  this._engine = new SelectEngineBridge();
4045
4052
  this._virtualizationScope = {
4046
4053
  dataKeys: [],
@@ -4058,6 +4065,7 @@ class EnhancedSelect extends HTMLElement {
4058
4065
  intendedRenderKeys: [],
4059
4066
  filteredIndexByKey: new Map(),
4060
4067
  };
4068
+ this._emptyStateContext = null;
4061
4069
  // Null keeps the public/default renderer on its legacy full path. This
4062
4070
  // private state is only used by guarded virtualization integration.
4063
4071
  this._guardedVirtualWindow = null;
@@ -4114,6 +4122,10 @@ class EnhancedSelect extends HTMLElement {
4114
4122
  this._pendingFirstRenderMark = false;
4115
4123
  this._pendingSearchRenderMark = false;
4116
4124
  this._rangeAnchorIndex = null;
4125
+ /** Chip identity is tracked independently of dropdown option positions. */
4126
+ this._lastRenderedChipKeys = null;
4127
+ this._latestChipScrollGeneration = 0;
4128
+ this._latestChipScrollFrame = null;
4117
4129
  this._customOptionBoundElements = new WeakSet();
4118
4130
  this._customOptionManagedActiveClasses = new WeakMap();
4119
4131
  this._customOptionNormalizedIds = new WeakMap();
@@ -4304,6 +4316,8 @@ class EnhancedSelect extends HTMLElement {
4304
4316
  this._syncListboxAccessibility();
4305
4317
  }
4306
4318
  disconnectedCallback() {
4319
+ this._cancelLatestChipScroll();
4320
+ this._cancelBusyPresentation();
4307
4321
  if (this._dataRequestCoordinator) {
4308
4322
  const actions = this._dataRequestCoordinator.disconnect();
4309
4323
  this._acknowledgedReady = false;
@@ -6646,12 +6660,40 @@ class EnhancedSelect extends HTMLElement {
6646
6660
  }
6647
6661
 
6648
6662
  .busy-bucket {
6663
+ display: flex;
6664
+ flex-direction: column;
6665
+ align-items: center;
6666
+ justify-content: center;
6667
+ gap: var(--select-busy-gap, 8px);
6649
6668
  padding: var(--select-busy-padding, 20px);
6650
6669
  text-align: center;
6651
6670
  color: var(--select-busy-color, var(--select-text-muted));
6652
6671
  background: var(--select-busy-bg, transparent);
6653
6672
  font-size: var(--select-busy-font-size, 0.8667em);
6654
6673
  }
6674
+
6675
+ .busy-icon {
6676
+ display: flex;
6677
+ align-items: center;
6678
+ justify-content: center;
6679
+ }
6680
+
6681
+ .busy-icon[hidden] {
6682
+ display: none;
6683
+ }
6684
+
6685
+ .busy-message {
6686
+ text-align: center;
6687
+ }
6688
+
6689
+ .busy-content[hidden] {
6690
+ display: none;
6691
+ }
6692
+
6693
+ .busy-bucket--replace .busy-icon,
6694
+ .busy-bucket--replace .busy-message {
6695
+ display: none;
6696
+ }
6655
6697
 
6656
6698
  .spinner {
6657
6699
  display: inline-block;
@@ -7867,6 +7909,12 @@ class EnhancedSelect extends HTMLElement {
7867
7909
  : delta >= 0
7868
7910
  ? -1
7869
7911
  : selectableIndices.length;
7912
+ // The final selectable option is the keyboard pagination boundary.
7913
+ // Keep the active option stable while the coordinator requests more data.
7914
+ if (delta === 1
7915
+ && currentPosition === selectableIndices.length - 1
7916
+ && this._requestKeyboardLoadMore())
7917
+ return;
7870
7918
  const nextPosition = Math.max(0, Math.min(selectableIndices.length - 1, basePosition + delta));
7871
7919
  const next = selectableIndices[nextPosition];
7872
7920
  this._setActive(next);
@@ -7879,6 +7927,33 @@ class EnhancedSelect extends HTMLElement {
7879
7927
  this._selectRange(anchorIndex, next, { clear: !opts?.toggleKey });
7880
7928
  }
7881
7929
  }
7930
+ /** Return true only when boundary navigation is held for an in-flight/new page. */
7931
+ _requestKeyboardLoadMore() {
7932
+ if (!this._state.isOpen
7933
+ || !this._config.infiniteScroll.enabled
7934
+ || this._dataLoadingConfig.protocol !== 'acknowledged'
7935
+ || !this._dataRequestCoordinator
7936
+ || !this._acknowledgedReady)
7937
+ return false;
7938
+ if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)
7939
+ return true;
7940
+ const snapshot = this._dataRequestCoordinator.getSnapshot();
7941
+ if (!snapshot.connected)
7942
+ return false;
7943
+ if (snapshot.busy)
7944
+ return true;
7945
+ if (!snapshot.hasMore
7946
+ || snapshot.error !== null
7947
+ || snapshot.resourceLimit !== null
7948
+ || (snapshot.status !== 'succeeded' && snapshot.status !== 'empty'))
7949
+ return false;
7950
+ // Delegate identity, pagination, and in-flight protection to the coordinator.
7951
+ const actions = this._dataRequestCoordinator.requestLoadMore('manual');
7952
+ if (actions.length === 0)
7953
+ return false;
7954
+ this._dispatchAcknowledgedActions(actions);
7955
+ return true;
7956
+ }
7882
7957
  _setActive(index, reason = 'keyboard') {
7883
7958
  this._ensureRegistryCurrent();
7884
7959
  const record = this._getRecordByIndex(index);
@@ -8198,6 +8273,19 @@ class EnhancedSelect extends HTMLElement {
8198
8273
  _updateInputDisplay() {
8199
8274
  const selectedEntries = this._getSelectedEntries();
8200
8275
  const selectedItems = selectedEntries.map(({ item }) => item);
8276
+ const nextKeys = new Set(selectedEntries.map(({ key }) => key));
8277
+ const previousKeys = this._lastRenderedChipKeys;
8278
+ let newlyAddedKey;
8279
+ if (previousKeys) {
8280
+ for (const key of nextKeys) {
8281
+ if (!previousKeys.has(key))
8282
+ newlyAddedKey = key;
8283
+ }
8284
+ }
8285
+ this._lastRenderedChipKeys = nextKeys;
8286
+ const previousChipScrollLeft = this._inputContent.scrollLeft;
8287
+ // Only a newly added selected key can initiate auto-scroll.
8288
+ this._cancelLatestChipScroll();
8201
8289
  const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
8202
8290
  if (selectedItems.length === 0) {
8203
8291
  this._input.value = '';
@@ -8273,8 +8361,87 @@ class EnhancedSelect extends HTMLElement {
8273
8361
  if (this._acknowledgedPendingSearchQuery !== null) {
8274
8362
  this._input.value = this._acknowledgedPendingSearchQuery;
8275
8363
  }
8364
+ // Recreating the chip DOM must not reset manual scrolling. In particular,
8365
+ // remove/clear, config rerenders, and item refreshes are not scroll intents.
8366
+ if (this._config.selection.mode === 'multi') {
8367
+ this._inputContent.scrollLeft = previousChipScrollLeft;
8368
+ if (newlyAddedKey !== undefined)
8369
+ this._scheduleLatestChipScroll(newlyAddedKey);
8370
+ }
8276
8371
  this._syncClearControlState();
8277
8372
  }
8373
+ _cancelLatestChipScroll() {
8374
+ this._latestChipScrollGeneration += 1;
8375
+ if (this._latestChipScrollFrame !== null) {
8376
+ cancelAnimationFrame(this._latestChipScrollFrame);
8377
+ this._latestChipScrollFrame = null;
8378
+ }
8379
+ }
8380
+ _scheduleLatestChipScroll(key) {
8381
+ if (!this.isConnected
8382
+ || this._config.selection.mode !== 'multi'
8383
+ || this._config.multiSelectDisplay.mode !== 'horizontal'
8384
+ || this._config.multiSelectDisplay.scrollToLatestChip !== true
8385
+ || this._config.multiSelectDisplay.overflowX === 'hidden')
8386
+ return;
8387
+ const generation = this._latestChipScrollGeneration;
8388
+ this._latestChipScrollFrame = requestAnimationFrame(() => {
8389
+ this._latestChipScrollFrame = null;
8390
+ if (generation !== this._latestChipScrollGeneration
8391
+ || !this.isConnected
8392
+ || this._multiScrollDrag.active
8393
+ || this._config.selection.mode !== 'multi'
8394
+ || this._config.multiSelectDisplay.mode !== 'horizontal'
8395
+ || this._config.multiSelectDisplay.scrollToLatestChip !== true)
8396
+ return;
8397
+ // Match the canonical selected-key sequence, not option indices:
8398
+ // selected items may be reordered or detached from the loaded page.
8399
+ const entries = this._getSelectedEntries();
8400
+ const index = entries.findIndex((entry) => entry.key === key);
8401
+ if (index < 0)
8402
+ return;
8403
+ const chip = this._inputContent.querySelectorAll('.selection-badge')[index];
8404
+ if (!chip)
8405
+ return;
8406
+ const hostBounds = this._inputContent.getBoundingClientRect();
8407
+ const chipBounds = chip.getBoundingClientRect();
8408
+ const leftEdge = hostBounds.left + this._inputContent.clientLeft;
8409
+ const rightEdge = leftEdge + this._inputContent.clientWidth;
8410
+ let delta;
8411
+ if (chip.parentElement === this._inputContent && chip.offsetWidth > 0) {
8412
+ // getBoundingClientRect() includes the chip's entry animation transform.
8413
+ // Use layout dimensions so the scroll target remains correct while the
8414
+ // chip scales into its final size. In RTL layouts, offsetLeft and
8415
+ // scrollLeft are both negative relative to the inline-start origin, so
8416
+ // the same subtraction maps the chip into the viewport's coordinates.
8417
+ const chipLeft = chip.offsetLeft - this._inputContent.scrollLeft;
8418
+ const chipRight = chipLeft + chip.offsetWidth;
8419
+ delta = chipRight > this._inputContent.clientWidth
8420
+ ? chipRight - this._inputContent.clientWidth
8421
+ : chipLeft < 0
8422
+ ? chipLeft
8423
+ : 0;
8424
+ }
8425
+ else {
8426
+ // DOM test environments without layout use the measurable rectangle.
8427
+ delta = chipBounds.right > rightEdge
8428
+ ? chipBounds.right - rightEdge
8429
+ : chipBounds.left < leftEdge
8430
+ ? chipBounds.left - leftEdge
8431
+ : 0;
8432
+ }
8433
+ if (Math.abs(delta) < 0.5)
8434
+ return;
8435
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
8436
+ const behavior = reducedMotion ? 'auto' : (this._config.multiSelectDisplay.scrollToLatestChipBehavior ?? 'smooth');
8437
+ if (typeof this._inputContent.scrollBy === 'function') {
8438
+ this._inputContent.scrollBy({ left: delta, behavior });
8439
+ }
8440
+ else {
8441
+ this._inputContent.scrollLeft += delta;
8442
+ }
8443
+ });
8444
+ }
8278
8445
  _isActivelyEditingSearchInput() {
8279
8446
  return this._config.searchable === true
8280
8447
  && this._state.isOpen
@@ -8390,6 +8557,8 @@ class EnhancedSelect extends HTMLElement {
8390
8557
  }
8391
8558
  }
8392
8559
  _setBusy(busy) {
8560
+ if (busy)
8561
+ this._beginBusyPresentation();
8393
8562
  this._state.isBusy = busy;
8394
8563
  this._syncListboxAccessibility();
8395
8564
  // Trigger re-render to show/hide busy indicator
@@ -8538,12 +8707,13 @@ class EnhancedSelect extends HTMLElement {
8538
8707
  classMap: true,
8539
8708
  optionRenderer: true,
8540
8709
  groupHeaderRenderer: true,
8710
+ emptyStateSlot: true,
8541
8711
  cssCustomProperties: true,
8542
8712
  shadowParts: true,
8543
8713
  globalStyleMirroring: true,
8544
8714
  },
8545
8715
  events: {
8546
- emitted: ['select', 'open', 'close', 'search', 'change', 'loadMore', 'remove', 'clear', 'error', 'diagnostic'],
8716
+ emitted: ['select', 'open', 'close', 'search', 'change', 'loadMore', 'remove', 'clear', 'emptyStateChange', 'error', 'diagnostic'],
8547
8717
  diagnosticEvent: true,
8548
8718
  },
8549
8719
  functionality: {
@@ -8559,6 +8729,36 @@ class EnhancedSelect extends HTMLElement {
8559
8729
  limitations: this.getKnownLimitations(),
8560
8730
  };
8561
8731
  }
8732
+ /** Return a detached immutable snapshot of the currently rendered empty state. */
8733
+ getEmptyStateContext() {
8734
+ const context = this._emptyStateContext;
8735
+ return context ? Object.freeze({ query: context.query, reason: context.reason }) : null;
8736
+ }
8737
+ _syncEmptyStateContext(context) {
8738
+ const current = this._emptyStateContext;
8739
+ if (current?.query === context?.query
8740
+ && current?.reason === context?.reason
8741
+ && Boolean(current) === Boolean(context))
8742
+ return;
8743
+ this._emptyStateContext = context
8744
+ ? Object.freeze({ query: context.query, reason: context.reason })
8745
+ : null;
8746
+ const detail = Object.freeze({ context: this.getEmptyStateContext() });
8747
+ this._emit('emptyStateChange', detail);
8748
+ }
8749
+ _appendEmptyState(context) {
8750
+ const empty = document.createElement('div');
8751
+ empty.setAttribute('part', 'no-results');
8752
+ empty.className = 'empty-state';
8753
+ const slot = document.createElement('slot');
8754
+ slot.name = 'empty-state';
8755
+ slot.appendChild(document.createTextNode(context.reason === 'no-results'
8756
+ ? `No results found for "${context.query}"`
8757
+ : 'No options available'));
8758
+ empty.appendChild(slot);
8759
+ this._optionsContainer.appendChild(empty);
8760
+ this._syncEmptyStateContext(context);
8761
+ }
8562
8762
  _emitChange() {
8563
8763
  const selectedEntries = this._getSelectedEntries();
8564
8764
  const selectedItems = selectedEntries.map(({ item }) => item);
@@ -9570,6 +9770,7 @@ class EnhancedSelect extends HTMLElement {
9570
9770
  _dispatchAcknowledgedActions(actions) {
9571
9771
  for (const action of actions) {
9572
9772
  if (action.type === 'cancel') {
9773
+ this._cancelBusyPresentation();
9573
9774
  this._dispatchAcknowledgedEvent('dataRequestCancel', action.notification);
9574
9775
  try {
9575
9776
  this._dataRequestCancelCallback?.(action.notification);
@@ -9594,6 +9795,7 @@ class EnhancedSelect extends HTMLElement {
9594
9795
  this._state.preserveScrollPosition = false;
9595
9796
  this._state.isSearching = true;
9596
9797
  }
9798
+ this._beginBusyPresentation();
9597
9799
  this._state.isBusy = true;
9598
9800
  this._acknowledgedLastRequest = request;
9599
9801
  this._syncListboxAccessibility();
@@ -9721,9 +9923,28 @@ class EnhancedSelect extends HTMLElement {
9721
9923
  throw new Error('Acknowledged snapshot render was superseded before completion');
9722
9924
  this._state.isBusy = snapshot.busy;
9723
9925
  if (!snapshot.busy) {
9724
- this._optionsContainer.querySelector('.busy-bucket')?.remove();
9725
- if (this._shouldRenderLoadMoreTrigger())
9726
- this._addLoadMoreTrigger();
9926
+ this._syncBusyPresentation();
9927
+ const shouldReconcileEmptyState = snapshot.status === 'exhausted'
9928
+ && this._renderPlan.filteredKeys.length === 0;
9929
+ if (shouldReconcileEmptyState) {
9930
+ // The first projection rendered while logically busy, so the empty
9931
+ // state was intentionally suppressed. Reconcile only this terminal
9932
+ // empty case after settlement; keep any minimum-duration busy
9933
+ // presentation and its timer intact.
9934
+ this._renderOptions();
9935
+ const emptyStateRenderCycleId = this._renderCycleId;
9936
+ const emptyStateRenderCompleted = await this._waitForRenderCycle(emptyStateRenderCycleId);
9937
+ if (!emptyStateRenderCompleted) {
9938
+ throw new Error('Acknowledged empty-state render was superseded before completion');
9939
+ }
9940
+ }
9941
+ else {
9942
+ if (!this._busyPresentationVisible) {
9943
+ this._optionsContainer.querySelector('.busy-bucket')?.remove();
9944
+ }
9945
+ if (this._shouldRenderLoadMoreTrigger())
9946
+ this._addLoadMoreTrigger();
9947
+ }
9727
9948
  }
9728
9949
  this._optionsContainer.scrollTop = this._acknowledgedProjectionScrollTop;
9729
9950
  this._syncListboxAccessibility();
@@ -10039,7 +10260,166 @@ class EnhancedSelect extends HTMLElement {
10039
10260
  _refreshVirtualizationScope(filteredIndices) {
10040
10261
  this._virtualizationScope = this._deriveVirtualizationScope(filteredIndices);
10041
10262
  }
10263
+ _clearBusyPresentationHideTimer() {
10264
+ if (this._busyPresentationHideTimer === null)
10265
+ return;
10266
+ window.clearTimeout(this._busyPresentationHideTimer);
10267
+ this._lifecycleTimers.delete(this._busyPresentationHideTimer);
10268
+ this._busyPresentationHideTimer = null;
10269
+ }
10270
+ _beginBusyPresentation() {
10271
+ this._busyPresentationGeneration += 1;
10272
+ this._clearBusyPresentationHideTimer();
10273
+ this._busyPresentationVisible = this._config.busyBucket.enabled;
10274
+ this._busyPresentationStartedAt = Date.now();
10275
+ }
10276
+ _syncBusyPresentation() {
10277
+ if (!this._config.busyBucket.enabled) {
10278
+ this._cancelBusyPresentation();
10279
+ return;
10280
+ }
10281
+ if (this._state.isBusy) {
10282
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null) {
10283
+ this._beginBusyPresentation();
10284
+ }
10285
+ return;
10286
+ }
10287
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null)
10288
+ return;
10289
+ const configuredMinimum = Number(this._config.busyBucket.minDisplayTime ?? 0);
10290
+ const minimum = Number.isFinite(configuredMinimum) ? Math.max(0, configuredMinimum) : 0;
10291
+ if (this._busyPresentationStartedAt === null)
10292
+ this._busyPresentationStartedAt = Date.now();
10293
+ const shownAt = this._busyPresentationStartedAt;
10294
+ const remaining = minimum - Math.max(0, Date.now() - shownAt);
10295
+ if (remaining <= 0) {
10296
+ this._busyPresentationGeneration += 1;
10297
+ this._busyPresentationVisible = false;
10298
+ this._busyPresentationStartedAt = null;
10299
+ return;
10300
+ }
10301
+ const generation = this._busyPresentationGeneration;
10302
+ this._busyPresentationHideTimer = this._setLifecycleTimeout(() => {
10303
+ if (generation !== this._busyPresentationGeneration || this._state.isBusy)
10304
+ return;
10305
+ this._busyPresentationHideTimer = null;
10306
+ this._busyPresentationVisible = false;
10307
+ this._busyPresentationStartedAt = null;
10308
+ this._busyBucket = undefined;
10309
+ this._clearBusyBucketContentObserver();
10310
+ this._renderOptions();
10311
+ }, remaining);
10312
+ }
10313
+ _clearBusyBucketContentObserver() {
10314
+ this._busyBucketContentObserver?.disconnect();
10315
+ this._busyBucketContentObserver = undefined;
10316
+ }
10317
+ _cancelBusyPresentation() {
10318
+ this._busyPresentationGeneration += 1;
10319
+ this._clearBusyPresentationHideTimer();
10320
+ this._busyPresentationVisible = false;
10321
+ this._busyPresentationStartedAt = null;
10322
+ this._clearBusyBucketContentObserver();
10323
+ this._busyBucket = undefined;
10324
+ this._optionsContainer?.querySelector('.busy-bucket')?.remove();
10325
+ }
10326
+ _hasAccessibleBusyContent(nodes) {
10327
+ return nodes.some((node) => {
10328
+ if (node.nodeType === Node.TEXT_NODE)
10329
+ return Boolean(node.textContent?.trim());
10330
+ if (!(node instanceof Element))
10331
+ return false;
10332
+ if (node.hasAttribute('hidden')
10333
+ || node.hasAttribute('inert')
10334
+ || node.getAttribute('aria-hidden')?.toLowerCase() === 'true')
10335
+ return false;
10336
+ if (['aria-label', 'aria-labelledby', 'alt', 'title'].some((name) => Boolean(node.getAttribute(name)?.trim()))) {
10337
+ return true;
10338
+ }
10339
+ return this._hasAccessibleBusyContent(Array.from(node.childNodes));
10340
+ });
10341
+ }
10342
+ _syncBusyBucketContent(bucket) {
10343
+ if (bucket !== this._busyBucket)
10344
+ return;
10345
+ const contentSlot = bucket.querySelector('slot[name="loading-content"]');
10346
+ const iconSlot = bucket.querySelector('slot[name="loading-icon"]');
10347
+ if (!contentSlot || !iconSlot)
10348
+ return;
10349
+ const contentNodes = contentSlot.assignedNodes({ flatten: true });
10350
+ const iconNodes = iconSlot.assignedNodes({ flatten: true });
10351
+ const hasContent = contentNodes.length > 0;
10352
+ const hasAccessibleContent = this._hasAccessibleBusyContent(contentNodes);
10353
+ const icon = bucket.querySelector('.busy-icon');
10354
+ icon?.toggleAttribute('hidden', this._config.busyBucket.showSpinner === false && iconNodes.length === 0);
10355
+ const content = bucket.querySelector('.busy-content');
10356
+ content?.toggleAttribute('hidden', !hasContent);
10357
+ bucket.classList.toggle('busy-bucket--replace', this._config.busyBucket.contentMode === 'replace' && hasAccessibleContent);
10358
+ const message = bucket.querySelector('.busy-message');
10359
+ if (message) {
10360
+ const needsAccessibleFallback = this._config.busyBucket.contentMode === 'replace' && !hasAccessibleContent;
10361
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false && !needsAccessibleFallback);
10362
+ if (needsAccessibleFallback && !message.textContent?.trim()) {
10363
+ message.textContent = this._config.busyBucket.message || 'Loading...';
10364
+ }
10365
+ }
10366
+ }
10367
+ _createBusyBucket() {
10368
+ const bucket = document.createElement('div');
10369
+ bucket.setAttribute('part', 'loading');
10370
+ bucket.className = 'busy-bucket';
10371
+ this._busyBucket = bucket;
10372
+ const icon = document.createElement('div');
10373
+ icon.className = 'busy-icon';
10374
+ icon.setAttribute('part', 'loading-icon');
10375
+ icon.setAttribute('aria-hidden', 'true');
10376
+ const iconSlot = document.createElement('slot');
10377
+ iconSlot.name = 'loading-icon';
10378
+ if (this._config.busyBucket.showSpinner !== false) {
10379
+ const spinner = document.createElement('div');
10380
+ spinner.className = 'spinner';
10381
+ spinner.setAttribute('part', 'loading-spinner');
10382
+ spinner.setAttribute('aria-hidden', 'true');
10383
+ iconSlot.appendChild(spinner);
10384
+ }
10385
+ icon.appendChild(iconSlot);
10386
+ bucket.appendChild(icon);
10387
+ const message = document.createElement('div');
10388
+ message.className = 'busy-message';
10389
+ message.setAttribute('part', 'loading-message');
10390
+ message.textContent = this._config.busyBucket.message ?? 'Loading...';
10391
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false);
10392
+ bucket.appendChild(message);
10393
+ const content = document.createElement('div');
10394
+ content.className = 'busy-content';
10395
+ content.setAttribute('part', 'loading-content');
10396
+ const contentSlot = document.createElement('slot');
10397
+ contentSlot.name = 'loading-content';
10398
+ content.appendChild(contentSlot);
10399
+ bucket.appendChild(content);
10400
+ const syncContent = () => this._syncBusyBucketContent(bucket);
10401
+ contentSlot.addEventListener('slotchange', syncContent);
10402
+ iconSlot.addEventListener('slotchange', syncContent);
10403
+ syncContent();
10404
+ if (typeof MutationObserver !== 'undefined') {
10405
+ this._clearBusyBucketContentObserver();
10406
+ this._busyBucketContentObserver = new MutationObserver(syncContent);
10407
+ this._busyBucketContentObserver.observe(this, { childList: true, subtree: true, characterData: true });
10408
+ }
10409
+ return bucket;
10410
+ }
10411
+ _appendBusyBucket() {
10412
+ const bucket = this._createBusyBucket();
10413
+ this._optionsContainer.appendChild(bucket);
10414
+ if (this._busyPresentationStartedAt === null)
10415
+ this._busyPresentationStartedAt = Date.now();
10416
+ this._syncBusyBucketContent(bucket);
10417
+ return bucket;
10418
+ }
10042
10419
  _renderOptions() {
10420
+ this._syncBusyPresentation();
10421
+ this._clearBusyBucketContentObserver();
10422
+ this._busyBucket = undefined;
10043
10423
  this._ensureRegistryCurrent();
10044
10424
  const scrollTopBeforeRender = this._optionsContainer.scrollTop;
10045
10425
  this._renderCycleId += 1;
@@ -10059,6 +10439,7 @@ class EnhancedSelect extends HTMLElement {
10059
10439
  this._optionsContainer.innerHTML = '';
10060
10440
  let filteredIndicesForScope = [];
10061
10441
  let guardedScrollTopToRestore = null;
10442
+ let renderedEmptyStateContext = null;
10062
10443
  // Ensure dropdown only contains options container (cleanup legacy direct children)
10063
10444
  // We need to preserve optionsContainer, so we can't just clear dropdown.innerHTML
10064
10445
  // But we can check if there are other children and remove them
@@ -10082,6 +10463,7 @@ class EnhancedSelect extends HTMLElement {
10082
10463
  searching.setAttribute('part', 'loading');
10083
10464
  searching.textContent = 'Searching...';
10084
10465
  this._optionsContainer.appendChild(searching);
10466
+ this._syncEmptyStateContext(null);
10085
10467
  this._resolveRenderCycle(renderCycleId, true);
10086
10468
  return;
10087
10469
  }
@@ -10185,17 +10567,11 @@ class EnhancedSelect extends HTMLElement {
10185
10567
  const filteredIndices = this._renderPlan.filteredIndices;
10186
10568
  this._refreshVirtualizationScope(filteredIndicesForScope);
10187
10569
  this._appendGuardedTopSpacer();
10188
- if (filteredIndices.length === 0 && !this._state.isBusy) {
10189
- const empty = document.createElement('div');
10190
- empty.setAttribute('part', 'no-results');
10191
- empty.className = 'empty-state';
10192
- if (query) {
10193
- empty.textContent = `No results found for "${this._state.searchQuery}"`;
10194
- }
10195
- else {
10196
- empty.textContent = 'No options available';
10197
- }
10198
- this._optionsContainer.appendChild(empty);
10570
+ if (this._renderPlan.filteredKeys.length === 0 && !this._state.isBusy) {
10571
+ renderedEmptyStateContext = this._state.searchQuery
10572
+ ? { query: this._state.searchQuery, reason: 'no-results' }
10573
+ : { query: '', reason: 'no-options' };
10574
+ this._appendEmptyState(renderedEmptyStateContext);
10199
10575
  }
10200
10576
  else {
10201
10577
  const shouldIncrementalRender = !this._guardedVirtualizer
@@ -10228,11 +10604,20 @@ class EnhancedSelect extends HTMLElement {
10228
10604
  this._renderSingleOption(item, itemIndex, getValue, getLabel, fragment);
10229
10605
  }
10230
10606
  const renderedTargets = Array.from(fragment.children);
10231
- this._optionsContainer.appendChild(fragment);
10607
+ const existingBusyBucket = this._optionsContainer.querySelector('.busy-bucket');
10608
+ if (existingBusyBucket)
10609
+ this._optionsContainer.insertBefore(fragment, existingBusyBucket);
10610
+ else
10611
+ this._optionsContainer.appendChild(fragment);
10232
10612
  this._appendMountedVirtualizationTargets(renderedTargets);
10233
10613
  this._syncRenderedOptionAccessibility();
10234
10614
  this._syncLegacyActiveAria();
10235
10615
  if (cursor < filteredIndices.length) {
10616
+ if (this._busyPresentationVisible
10617
+ && this._config.busyBucket.enabled
10618
+ && !this._optionsContainer.querySelector('.busy-bucket')) {
10619
+ this._appendBusyBucket();
10620
+ }
10236
10621
  this._requestLifecycleFrame(renderChunk);
10237
10622
  }
10238
10623
  else {
@@ -10248,6 +10633,7 @@ class EnhancedSelect extends HTMLElement {
10248
10633
  }
10249
10634
  };
10250
10635
  renderChunk();
10636
+ this._syncEmptyStateContext(null);
10251
10637
  return;
10252
10638
  }
10253
10639
  filteredIndices.forEach((itemIndex) => {
@@ -10258,25 +10644,12 @@ class EnhancedSelect extends HTMLElement {
10258
10644
  this._appendGuardedBottomSpacer();
10259
10645
  }
10260
10646
  this._refreshMountedVirtualizationScope();
10261
- // Append Busy Indicator if busy
10262
- if (this._state.isBusy && this._config.busyBucket.enabled) {
10263
- const busyBucket = document.createElement('div');
10264
- busyBucket.setAttribute('part', 'loading');
10265
- busyBucket.className = 'busy-bucket';
10266
- if (this._config.busyBucket.showSpinner) {
10267
- const spinner = document.createElement('div');
10268
- spinner.className = 'spinner';
10269
- busyBucket.appendChild(spinner);
10270
- }
10271
- if (this._config.busyBucket.message) {
10272
- const message = document.createElement('div');
10273
- message.textContent = this._config.busyBucket.message;
10274
- busyBucket.appendChild(message);
10275
- }
10276
- this._optionsContainer.appendChild(busyBucket);
10277
- }
10278
- // Append Load More Trigger (Button or Sentinel) if enabled and not busy
10279
- else if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
10647
+ if (this._busyPresentationVisible && this._config.busyBucket.enabled) {
10648
+ this._appendBusyBucket();
10649
+ }
10650
+ // The load-more trigger follows logical busy state, not any optional
10651
+ // visual minimum-display hold after a request has already completed.
10652
+ if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
10280
10653
  this._addLoadMoreTrigger();
10281
10654
  }
10282
10655
  // Rebuilding the list temporarily removes its spacer geometry. Browsers
@@ -10285,6 +10658,7 @@ class EnhancedSelect extends HTMLElement {
10285
10658
  if (guardedScrollTopToRestore !== null) {
10286
10659
  this._optionsContainer.scrollTop = guardedScrollTopToRestore;
10287
10660
  }
10661
+ this._syncEmptyStateContext(renderedEmptyStateContext);
10288
10662
  this._syncRenderedOptionAccessibility();
10289
10663
  this._syncLegacyActiveAria();
10290
10664
  this._syncGuardedOptionResizeTargets();