@smilodon/core 1.12.0 → 1.13.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
@@ -2121,8 +2121,10 @@ const defaultConfig = {
2121
2121
  busyBucket: {
2122
2122
  enabled: true,
2123
2123
  showSpinner: true,
2124
+ showMessage: true,
2124
2125
  message: 'Loading...',
2125
2126
  minDisplayTime: 200,
2127
+ contentMode: 'append',
2126
2128
  },
2127
2129
  styles: {
2128
2130
  classNames: {},
@@ -4041,6 +4043,10 @@ class EnhancedSelect extends HTMLElement {
4041
4043
  super();
4042
4044
  this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
4043
4045
  this._hasLastInvalidDataLoadingCandidate = false;
4046
+ this._busyPresentationVisible = false;
4047
+ this._busyPresentationStartedAt = null;
4048
+ this._busyPresentationGeneration = 0;
4049
+ this._busyPresentationHideTimer = null;
4044
4050
  this._engine = new SelectEngineBridge();
4045
4051
  this._virtualizationScope = {
4046
4052
  dataKeys: [],
@@ -4304,6 +4310,7 @@ class EnhancedSelect extends HTMLElement {
4304
4310
  this._syncListboxAccessibility();
4305
4311
  }
4306
4312
  disconnectedCallback() {
4313
+ this._cancelBusyPresentation();
4307
4314
  if (this._dataRequestCoordinator) {
4308
4315
  const actions = this._dataRequestCoordinator.disconnect();
4309
4316
  this._acknowledgedReady = false;
@@ -6646,12 +6653,40 @@ class EnhancedSelect extends HTMLElement {
6646
6653
  }
6647
6654
 
6648
6655
  .busy-bucket {
6656
+ display: flex;
6657
+ flex-direction: column;
6658
+ align-items: center;
6659
+ justify-content: center;
6660
+ gap: var(--select-busy-gap, 8px);
6649
6661
  padding: var(--select-busy-padding, 20px);
6650
6662
  text-align: center;
6651
6663
  color: var(--select-busy-color, var(--select-text-muted));
6652
6664
  background: var(--select-busy-bg, transparent);
6653
6665
  font-size: var(--select-busy-font-size, 0.8667em);
6654
6666
  }
6667
+
6668
+ .busy-icon {
6669
+ display: flex;
6670
+ align-items: center;
6671
+ justify-content: center;
6672
+ }
6673
+
6674
+ .busy-icon[hidden] {
6675
+ display: none;
6676
+ }
6677
+
6678
+ .busy-message {
6679
+ text-align: center;
6680
+ }
6681
+
6682
+ .busy-content[hidden] {
6683
+ display: none;
6684
+ }
6685
+
6686
+ .busy-bucket--replace .busy-icon,
6687
+ .busy-bucket--replace .busy-message {
6688
+ display: none;
6689
+ }
6655
6690
 
6656
6691
  .spinner {
6657
6692
  display: inline-block;
@@ -8390,6 +8425,8 @@ class EnhancedSelect extends HTMLElement {
8390
8425
  }
8391
8426
  }
8392
8427
  _setBusy(busy) {
8428
+ if (busy)
8429
+ this._beginBusyPresentation();
8393
8430
  this._state.isBusy = busy;
8394
8431
  this._syncListboxAccessibility();
8395
8432
  // Trigger re-render to show/hide busy indicator
@@ -9570,6 +9607,7 @@ class EnhancedSelect extends HTMLElement {
9570
9607
  _dispatchAcknowledgedActions(actions) {
9571
9608
  for (const action of actions) {
9572
9609
  if (action.type === 'cancel') {
9610
+ this._cancelBusyPresentation();
9573
9611
  this._dispatchAcknowledgedEvent('dataRequestCancel', action.notification);
9574
9612
  try {
9575
9613
  this._dataRequestCancelCallback?.(action.notification);
@@ -9594,6 +9632,7 @@ class EnhancedSelect extends HTMLElement {
9594
9632
  this._state.preserveScrollPosition = false;
9595
9633
  this._state.isSearching = true;
9596
9634
  }
9635
+ this._beginBusyPresentation();
9597
9636
  this._state.isBusy = true;
9598
9637
  this._acknowledgedLastRequest = request;
9599
9638
  this._syncListboxAccessibility();
@@ -9721,7 +9760,10 @@ class EnhancedSelect extends HTMLElement {
9721
9760
  throw new Error('Acknowledged snapshot render was superseded before completion');
9722
9761
  this._state.isBusy = snapshot.busy;
9723
9762
  if (!snapshot.busy) {
9724
- this._optionsContainer.querySelector('.busy-bucket')?.remove();
9763
+ this._syncBusyPresentation();
9764
+ if (!this._busyPresentationVisible) {
9765
+ this._optionsContainer.querySelector('.busy-bucket')?.remove();
9766
+ }
9725
9767
  if (this._shouldRenderLoadMoreTrigger())
9726
9768
  this._addLoadMoreTrigger();
9727
9769
  }
@@ -10039,7 +10081,166 @@ class EnhancedSelect extends HTMLElement {
10039
10081
  _refreshVirtualizationScope(filteredIndices) {
10040
10082
  this._virtualizationScope = this._deriveVirtualizationScope(filteredIndices);
10041
10083
  }
10084
+ _clearBusyPresentationHideTimer() {
10085
+ if (this._busyPresentationHideTimer === null)
10086
+ return;
10087
+ window.clearTimeout(this._busyPresentationHideTimer);
10088
+ this._lifecycleTimers.delete(this._busyPresentationHideTimer);
10089
+ this._busyPresentationHideTimer = null;
10090
+ }
10091
+ _beginBusyPresentation() {
10092
+ this._busyPresentationGeneration += 1;
10093
+ this._clearBusyPresentationHideTimer();
10094
+ this._busyPresentationVisible = this._config.busyBucket.enabled;
10095
+ this._busyPresentationStartedAt = this._busyBucket?.isConnected ? Date.now() : null;
10096
+ }
10097
+ _syncBusyPresentation() {
10098
+ if (!this._config.busyBucket.enabled) {
10099
+ this._cancelBusyPresentation();
10100
+ return;
10101
+ }
10102
+ if (this._state.isBusy) {
10103
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null) {
10104
+ this._beginBusyPresentation();
10105
+ }
10106
+ return;
10107
+ }
10108
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null)
10109
+ return;
10110
+ const configuredMinimum = Number(this._config.busyBucket.minDisplayTime ?? 0);
10111
+ const minimum = Number.isFinite(configuredMinimum) ? Math.max(0, configuredMinimum) : 0;
10112
+ if (this._busyPresentationStartedAt === null)
10113
+ this._busyPresentationStartedAt = Date.now();
10114
+ const shownAt = this._busyPresentationStartedAt;
10115
+ const remaining = minimum - Math.max(0, Date.now() - shownAt);
10116
+ if (remaining <= 0) {
10117
+ this._busyPresentationGeneration += 1;
10118
+ this._busyPresentationVisible = false;
10119
+ this._busyPresentationStartedAt = null;
10120
+ return;
10121
+ }
10122
+ const generation = this._busyPresentationGeneration;
10123
+ this._busyPresentationHideTimer = this._setLifecycleTimeout(() => {
10124
+ if (generation !== this._busyPresentationGeneration || this._state.isBusy)
10125
+ return;
10126
+ this._busyPresentationHideTimer = null;
10127
+ this._busyPresentationVisible = false;
10128
+ this._busyPresentationStartedAt = null;
10129
+ this._busyBucket = undefined;
10130
+ this._clearBusyBucketContentObserver();
10131
+ this._renderOptions();
10132
+ }, remaining);
10133
+ }
10134
+ _clearBusyBucketContentObserver() {
10135
+ this._busyBucketContentObserver?.disconnect();
10136
+ this._busyBucketContentObserver = undefined;
10137
+ }
10138
+ _cancelBusyPresentation() {
10139
+ this._busyPresentationGeneration += 1;
10140
+ this._clearBusyPresentationHideTimer();
10141
+ this._busyPresentationVisible = false;
10142
+ this._busyPresentationStartedAt = null;
10143
+ this._clearBusyBucketContentObserver();
10144
+ this._busyBucket = undefined;
10145
+ this._optionsContainer?.querySelector('.busy-bucket')?.remove();
10146
+ }
10147
+ _hasAccessibleBusyContent(nodes) {
10148
+ return nodes.some((node) => {
10149
+ if (node.nodeType === Node.TEXT_NODE)
10150
+ return Boolean(node.textContent?.trim());
10151
+ if (!(node instanceof Element))
10152
+ return false;
10153
+ if (node.hasAttribute('hidden')
10154
+ || node.hasAttribute('inert')
10155
+ || node.getAttribute('aria-hidden')?.toLowerCase() === 'true')
10156
+ return false;
10157
+ if (['aria-label', 'aria-labelledby', 'alt', 'title'].some((name) => Boolean(node.getAttribute(name)?.trim()))) {
10158
+ return true;
10159
+ }
10160
+ return this._hasAccessibleBusyContent(Array.from(node.childNodes));
10161
+ });
10162
+ }
10163
+ _syncBusyBucketContent(bucket) {
10164
+ if (bucket !== this._busyBucket)
10165
+ return;
10166
+ const contentSlot = bucket.querySelector('slot[name="loading-content"]');
10167
+ const iconSlot = bucket.querySelector('slot[name="loading-icon"]');
10168
+ if (!contentSlot || !iconSlot)
10169
+ return;
10170
+ const contentNodes = contentSlot.assignedNodes({ flatten: true });
10171
+ const iconNodes = iconSlot.assignedNodes({ flatten: true });
10172
+ const hasContent = contentNodes.length > 0;
10173
+ const hasAccessibleContent = this._hasAccessibleBusyContent(contentNodes);
10174
+ const icon = bucket.querySelector('.busy-icon');
10175
+ icon?.toggleAttribute('hidden', this._config.busyBucket.showSpinner === false && iconNodes.length === 0);
10176
+ const content = bucket.querySelector('.busy-content');
10177
+ content?.toggleAttribute('hidden', !hasContent);
10178
+ bucket.classList.toggle('busy-bucket--replace', this._config.busyBucket.contentMode === 'replace' && hasAccessibleContent);
10179
+ const message = bucket.querySelector('.busy-message');
10180
+ if (message) {
10181
+ const needsAccessibleFallback = this._config.busyBucket.contentMode === 'replace' && !hasAccessibleContent;
10182
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false && !needsAccessibleFallback);
10183
+ if (needsAccessibleFallback && !message.textContent?.trim()) {
10184
+ message.textContent = this._config.busyBucket.message || 'Loading...';
10185
+ }
10186
+ }
10187
+ }
10188
+ _createBusyBucket() {
10189
+ const bucket = document.createElement('div');
10190
+ bucket.setAttribute('part', 'loading');
10191
+ bucket.className = 'busy-bucket';
10192
+ this._busyBucket = bucket;
10193
+ const icon = document.createElement('div');
10194
+ icon.className = 'busy-icon';
10195
+ icon.setAttribute('part', 'loading-icon');
10196
+ icon.setAttribute('aria-hidden', 'true');
10197
+ const iconSlot = document.createElement('slot');
10198
+ iconSlot.name = 'loading-icon';
10199
+ if (this._config.busyBucket.showSpinner !== false) {
10200
+ const spinner = document.createElement('div');
10201
+ spinner.className = 'spinner';
10202
+ spinner.setAttribute('part', 'loading-spinner');
10203
+ spinner.setAttribute('aria-hidden', 'true');
10204
+ iconSlot.appendChild(spinner);
10205
+ }
10206
+ icon.appendChild(iconSlot);
10207
+ bucket.appendChild(icon);
10208
+ const message = document.createElement('div');
10209
+ message.className = 'busy-message';
10210
+ message.setAttribute('part', 'loading-message');
10211
+ message.textContent = this._config.busyBucket.message ?? 'Loading...';
10212
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false);
10213
+ bucket.appendChild(message);
10214
+ const content = document.createElement('div');
10215
+ content.className = 'busy-content';
10216
+ content.setAttribute('part', 'loading-content');
10217
+ const contentSlot = document.createElement('slot');
10218
+ contentSlot.name = 'loading-content';
10219
+ content.appendChild(contentSlot);
10220
+ bucket.appendChild(content);
10221
+ const syncContent = () => this._syncBusyBucketContent(bucket);
10222
+ contentSlot.addEventListener('slotchange', syncContent);
10223
+ iconSlot.addEventListener('slotchange', syncContent);
10224
+ syncContent();
10225
+ if (typeof MutationObserver !== 'undefined') {
10226
+ this._clearBusyBucketContentObserver();
10227
+ this._busyBucketContentObserver = new MutationObserver(syncContent);
10228
+ this._busyBucketContentObserver.observe(this, { childList: true, subtree: true, characterData: true });
10229
+ }
10230
+ return bucket;
10231
+ }
10232
+ _appendBusyBucket() {
10233
+ const bucket = this._createBusyBucket();
10234
+ this._optionsContainer.appendChild(bucket);
10235
+ if (this._busyPresentationStartedAt === null)
10236
+ this._busyPresentationStartedAt = Date.now();
10237
+ this._syncBusyBucketContent(bucket);
10238
+ return bucket;
10239
+ }
10042
10240
  _renderOptions() {
10241
+ this._syncBusyPresentation();
10242
+ this._clearBusyBucketContentObserver();
10243
+ this._busyBucket = undefined;
10043
10244
  this._ensureRegistryCurrent();
10044
10245
  const scrollTopBeforeRender = this._optionsContainer.scrollTop;
10045
10246
  this._renderCycleId += 1;
@@ -10228,11 +10429,20 @@ class EnhancedSelect extends HTMLElement {
10228
10429
  this._renderSingleOption(item, itemIndex, getValue, getLabel, fragment);
10229
10430
  }
10230
10431
  const renderedTargets = Array.from(fragment.children);
10231
- this._optionsContainer.appendChild(fragment);
10432
+ const existingBusyBucket = this._optionsContainer.querySelector('.busy-bucket');
10433
+ if (existingBusyBucket)
10434
+ this._optionsContainer.insertBefore(fragment, existingBusyBucket);
10435
+ else
10436
+ this._optionsContainer.appendChild(fragment);
10232
10437
  this._appendMountedVirtualizationTargets(renderedTargets);
10233
10438
  this._syncRenderedOptionAccessibility();
10234
10439
  this._syncLegacyActiveAria();
10235
10440
  if (cursor < filteredIndices.length) {
10441
+ if (this._busyPresentationVisible
10442
+ && this._config.busyBucket.enabled
10443
+ && !this._optionsContainer.querySelector('.busy-bucket')) {
10444
+ this._appendBusyBucket();
10445
+ }
10236
10446
  this._requestLifecycleFrame(renderChunk);
10237
10447
  }
10238
10448
  else {
@@ -10258,25 +10468,12 @@ class EnhancedSelect extends HTMLElement {
10258
10468
  this._appendGuardedBottomSpacer();
10259
10469
  }
10260
10470
  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()) {
10471
+ if (this._busyPresentationVisible && this._config.busyBucket.enabled) {
10472
+ this._appendBusyBucket();
10473
+ }
10474
+ // The load-more trigger follows logical busy state, not any optional
10475
+ // visual minimum-display hold after a request has already completed.
10476
+ if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
10280
10477
  this._addLoadMoreTrigger();
10281
10478
  }
10282
10479
  // Rebuilding the list temporarily removes its spacer geometry. Browsers