@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.umd.js CHANGED
@@ -2127,8 +2127,10 @@
2127
2127
  busyBucket: {
2128
2128
  enabled: true,
2129
2129
  showSpinner: true,
2130
+ showMessage: true,
2130
2131
  message: 'Loading...',
2131
2132
  minDisplayTime: 200,
2133
+ contentMode: 'append',
2132
2134
  },
2133
2135
  styles: {
2134
2136
  classNames: {},
@@ -4047,6 +4049,10 @@
4047
4049
  super();
4048
4050
  this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
4049
4051
  this._hasLastInvalidDataLoadingCandidate = false;
4052
+ this._busyPresentationVisible = false;
4053
+ this._busyPresentationStartedAt = null;
4054
+ this._busyPresentationGeneration = 0;
4055
+ this._busyPresentationHideTimer = null;
4050
4056
  this._engine = new SelectEngineBridge();
4051
4057
  this._virtualizationScope = {
4052
4058
  dataKeys: [],
@@ -4310,6 +4316,7 @@
4310
4316
  this._syncListboxAccessibility();
4311
4317
  }
4312
4318
  disconnectedCallback() {
4319
+ this._cancelBusyPresentation();
4313
4320
  if (this._dataRequestCoordinator) {
4314
4321
  const actions = this._dataRequestCoordinator.disconnect();
4315
4322
  this._acknowledgedReady = false;
@@ -6652,12 +6659,40 @@
6652
6659
  }
6653
6660
 
6654
6661
  .busy-bucket {
6662
+ display: flex;
6663
+ flex-direction: column;
6664
+ align-items: center;
6665
+ justify-content: center;
6666
+ gap: var(--select-busy-gap, 8px);
6655
6667
  padding: var(--select-busy-padding, 20px);
6656
6668
  text-align: center;
6657
6669
  color: var(--select-busy-color, var(--select-text-muted));
6658
6670
  background: var(--select-busy-bg, transparent);
6659
6671
  font-size: var(--select-busy-font-size, 0.8667em);
6660
6672
  }
6673
+
6674
+ .busy-icon {
6675
+ display: flex;
6676
+ align-items: center;
6677
+ justify-content: center;
6678
+ }
6679
+
6680
+ .busy-icon[hidden] {
6681
+ display: none;
6682
+ }
6683
+
6684
+ .busy-message {
6685
+ text-align: center;
6686
+ }
6687
+
6688
+ .busy-content[hidden] {
6689
+ display: none;
6690
+ }
6691
+
6692
+ .busy-bucket--replace .busy-icon,
6693
+ .busy-bucket--replace .busy-message {
6694
+ display: none;
6695
+ }
6661
6696
 
6662
6697
  .spinner {
6663
6698
  display: inline-block;
@@ -8396,6 +8431,8 @@
8396
8431
  }
8397
8432
  }
8398
8433
  _setBusy(busy) {
8434
+ if (busy)
8435
+ this._beginBusyPresentation();
8399
8436
  this._state.isBusy = busy;
8400
8437
  this._syncListboxAccessibility();
8401
8438
  // Trigger re-render to show/hide busy indicator
@@ -9576,6 +9613,7 @@
9576
9613
  _dispatchAcknowledgedActions(actions) {
9577
9614
  for (const action of actions) {
9578
9615
  if (action.type === 'cancel') {
9616
+ this._cancelBusyPresentation();
9579
9617
  this._dispatchAcknowledgedEvent('dataRequestCancel', action.notification);
9580
9618
  try {
9581
9619
  this._dataRequestCancelCallback?.(action.notification);
@@ -9600,6 +9638,7 @@
9600
9638
  this._state.preserveScrollPosition = false;
9601
9639
  this._state.isSearching = true;
9602
9640
  }
9641
+ this._beginBusyPresentation();
9603
9642
  this._state.isBusy = true;
9604
9643
  this._acknowledgedLastRequest = request;
9605
9644
  this._syncListboxAccessibility();
@@ -9727,7 +9766,10 @@
9727
9766
  throw new Error('Acknowledged snapshot render was superseded before completion');
9728
9767
  this._state.isBusy = snapshot.busy;
9729
9768
  if (!snapshot.busy) {
9730
- this._optionsContainer.querySelector('.busy-bucket')?.remove();
9769
+ this._syncBusyPresentation();
9770
+ if (!this._busyPresentationVisible) {
9771
+ this._optionsContainer.querySelector('.busy-bucket')?.remove();
9772
+ }
9731
9773
  if (this._shouldRenderLoadMoreTrigger())
9732
9774
  this._addLoadMoreTrigger();
9733
9775
  }
@@ -10045,7 +10087,166 @@
10045
10087
  _refreshVirtualizationScope(filteredIndices) {
10046
10088
  this._virtualizationScope = this._deriveVirtualizationScope(filteredIndices);
10047
10089
  }
10090
+ _clearBusyPresentationHideTimer() {
10091
+ if (this._busyPresentationHideTimer === null)
10092
+ return;
10093
+ window.clearTimeout(this._busyPresentationHideTimer);
10094
+ this._lifecycleTimers.delete(this._busyPresentationHideTimer);
10095
+ this._busyPresentationHideTimer = null;
10096
+ }
10097
+ _beginBusyPresentation() {
10098
+ this._busyPresentationGeneration += 1;
10099
+ this._clearBusyPresentationHideTimer();
10100
+ this._busyPresentationVisible = this._config.busyBucket.enabled;
10101
+ this._busyPresentationStartedAt = this._busyBucket?.isConnected ? Date.now() : null;
10102
+ }
10103
+ _syncBusyPresentation() {
10104
+ if (!this._config.busyBucket.enabled) {
10105
+ this._cancelBusyPresentation();
10106
+ return;
10107
+ }
10108
+ if (this._state.isBusy) {
10109
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null) {
10110
+ this._beginBusyPresentation();
10111
+ }
10112
+ return;
10113
+ }
10114
+ if (!this._busyPresentationVisible || this._busyPresentationHideTimer !== null)
10115
+ return;
10116
+ const configuredMinimum = Number(this._config.busyBucket.minDisplayTime ?? 0);
10117
+ const minimum = Number.isFinite(configuredMinimum) ? Math.max(0, configuredMinimum) : 0;
10118
+ if (this._busyPresentationStartedAt === null)
10119
+ this._busyPresentationStartedAt = Date.now();
10120
+ const shownAt = this._busyPresentationStartedAt;
10121
+ const remaining = minimum - Math.max(0, Date.now() - shownAt);
10122
+ if (remaining <= 0) {
10123
+ this._busyPresentationGeneration += 1;
10124
+ this._busyPresentationVisible = false;
10125
+ this._busyPresentationStartedAt = null;
10126
+ return;
10127
+ }
10128
+ const generation = this._busyPresentationGeneration;
10129
+ this._busyPresentationHideTimer = this._setLifecycleTimeout(() => {
10130
+ if (generation !== this._busyPresentationGeneration || this._state.isBusy)
10131
+ return;
10132
+ this._busyPresentationHideTimer = null;
10133
+ this._busyPresentationVisible = false;
10134
+ this._busyPresentationStartedAt = null;
10135
+ this._busyBucket = undefined;
10136
+ this._clearBusyBucketContentObserver();
10137
+ this._renderOptions();
10138
+ }, remaining);
10139
+ }
10140
+ _clearBusyBucketContentObserver() {
10141
+ this._busyBucketContentObserver?.disconnect();
10142
+ this._busyBucketContentObserver = undefined;
10143
+ }
10144
+ _cancelBusyPresentation() {
10145
+ this._busyPresentationGeneration += 1;
10146
+ this._clearBusyPresentationHideTimer();
10147
+ this._busyPresentationVisible = false;
10148
+ this._busyPresentationStartedAt = null;
10149
+ this._clearBusyBucketContentObserver();
10150
+ this._busyBucket = undefined;
10151
+ this._optionsContainer?.querySelector('.busy-bucket')?.remove();
10152
+ }
10153
+ _hasAccessibleBusyContent(nodes) {
10154
+ return nodes.some((node) => {
10155
+ if (node.nodeType === Node.TEXT_NODE)
10156
+ return Boolean(node.textContent?.trim());
10157
+ if (!(node instanceof Element))
10158
+ return false;
10159
+ if (node.hasAttribute('hidden')
10160
+ || node.hasAttribute('inert')
10161
+ || node.getAttribute('aria-hidden')?.toLowerCase() === 'true')
10162
+ return false;
10163
+ if (['aria-label', 'aria-labelledby', 'alt', 'title'].some((name) => Boolean(node.getAttribute(name)?.trim()))) {
10164
+ return true;
10165
+ }
10166
+ return this._hasAccessibleBusyContent(Array.from(node.childNodes));
10167
+ });
10168
+ }
10169
+ _syncBusyBucketContent(bucket) {
10170
+ if (bucket !== this._busyBucket)
10171
+ return;
10172
+ const contentSlot = bucket.querySelector('slot[name="loading-content"]');
10173
+ const iconSlot = bucket.querySelector('slot[name="loading-icon"]');
10174
+ if (!contentSlot || !iconSlot)
10175
+ return;
10176
+ const contentNodes = contentSlot.assignedNodes({ flatten: true });
10177
+ const iconNodes = iconSlot.assignedNodes({ flatten: true });
10178
+ const hasContent = contentNodes.length > 0;
10179
+ const hasAccessibleContent = this._hasAccessibleBusyContent(contentNodes);
10180
+ const icon = bucket.querySelector('.busy-icon');
10181
+ icon?.toggleAttribute('hidden', this._config.busyBucket.showSpinner === false && iconNodes.length === 0);
10182
+ const content = bucket.querySelector('.busy-content');
10183
+ content?.toggleAttribute('hidden', !hasContent);
10184
+ bucket.classList.toggle('busy-bucket--replace', this._config.busyBucket.contentMode === 'replace' && hasAccessibleContent);
10185
+ const message = bucket.querySelector('.busy-message');
10186
+ if (message) {
10187
+ const needsAccessibleFallback = this._config.busyBucket.contentMode === 'replace' && !hasAccessibleContent;
10188
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false && !needsAccessibleFallback);
10189
+ if (needsAccessibleFallback && !message.textContent?.trim()) {
10190
+ message.textContent = this._config.busyBucket.message || 'Loading...';
10191
+ }
10192
+ }
10193
+ }
10194
+ _createBusyBucket() {
10195
+ const bucket = document.createElement('div');
10196
+ bucket.setAttribute('part', 'loading');
10197
+ bucket.className = 'busy-bucket';
10198
+ this._busyBucket = bucket;
10199
+ const icon = document.createElement('div');
10200
+ icon.className = 'busy-icon';
10201
+ icon.setAttribute('part', 'loading-icon');
10202
+ icon.setAttribute('aria-hidden', 'true');
10203
+ const iconSlot = document.createElement('slot');
10204
+ iconSlot.name = 'loading-icon';
10205
+ if (this._config.busyBucket.showSpinner !== false) {
10206
+ const spinner = document.createElement('div');
10207
+ spinner.className = 'spinner';
10208
+ spinner.setAttribute('part', 'loading-spinner');
10209
+ spinner.setAttribute('aria-hidden', 'true');
10210
+ iconSlot.appendChild(spinner);
10211
+ }
10212
+ icon.appendChild(iconSlot);
10213
+ bucket.appendChild(icon);
10214
+ const message = document.createElement('div');
10215
+ message.className = 'busy-message';
10216
+ message.setAttribute('part', 'loading-message');
10217
+ message.textContent = this._config.busyBucket.message ?? 'Loading...';
10218
+ message.toggleAttribute('hidden', this._config.busyBucket.showMessage === false);
10219
+ bucket.appendChild(message);
10220
+ const content = document.createElement('div');
10221
+ content.className = 'busy-content';
10222
+ content.setAttribute('part', 'loading-content');
10223
+ const contentSlot = document.createElement('slot');
10224
+ contentSlot.name = 'loading-content';
10225
+ content.appendChild(contentSlot);
10226
+ bucket.appendChild(content);
10227
+ const syncContent = () => this._syncBusyBucketContent(bucket);
10228
+ contentSlot.addEventListener('slotchange', syncContent);
10229
+ iconSlot.addEventListener('slotchange', syncContent);
10230
+ syncContent();
10231
+ if (typeof MutationObserver !== 'undefined') {
10232
+ this._clearBusyBucketContentObserver();
10233
+ this._busyBucketContentObserver = new MutationObserver(syncContent);
10234
+ this._busyBucketContentObserver.observe(this, { childList: true, subtree: true, characterData: true });
10235
+ }
10236
+ return bucket;
10237
+ }
10238
+ _appendBusyBucket() {
10239
+ const bucket = this._createBusyBucket();
10240
+ this._optionsContainer.appendChild(bucket);
10241
+ if (this._busyPresentationStartedAt === null)
10242
+ this._busyPresentationStartedAt = Date.now();
10243
+ this._syncBusyBucketContent(bucket);
10244
+ return bucket;
10245
+ }
10048
10246
  _renderOptions() {
10247
+ this._syncBusyPresentation();
10248
+ this._clearBusyBucketContentObserver();
10249
+ this._busyBucket = undefined;
10049
10250
  this._ensureRegistryCurrent();
10050
10251
  const scrollTopBeforeRender = this._optionsContainer.scrollTop;
10051
10252
  this._renderCycleId += 1;
@@ -10234,11 +10435,20 @@
10234
10435
  this._renderSingleOption(item, itemIndex, getValue, getLabel, fragment);
10235
10436
  }
10236
10437
  const renderedTargets = Array.from(fragment.children);
10237
- this._optionsContainer.appendChild(fragment);
10438
+ const existingBusyBucket = this._optionsContainer.querySelector('.busy-bucket');
10439
+ if (existingBusyBucket)
10440
+ this._optionsContainer.insertBefore(fragment, existingBusyBucket);
10441
+ else
10442
+ this._optionsContainer.appendChild(fragment);
10238
10443
  this._appendMountedVirtualizationTargets(renderedTargets);
10239
10444
  this._syncRenderedOptionAccessibility();
10240
10445
  this._syncLegacyActiveAria();
10241
10446
  if (cursor < filteredIndices.length) {
10447
+ if (this._busyPresentationVisible
10448
+ && this._config.busyBucket.enabled
10449
+ && !this._optionsContainer.querySelector('.busy-bucket')) {
10450
+ this._appendBusyBucket();
10451
+ }
10242
10452
  this._requestLifecycleFrame(renderChunk);
10243
10453
  }
10244
10454
  else {
@@ -10264,25 +10474,12 @@
10264
10474
  this._appendGuardedBottomSpacer();
10265
10475
  }
10266
10476
  this._refreshMountedVirtualizationScope();
10267
- // Append Busy Indicator if busy
10268
- if (this._state.isBusy && this._config.busyBucket.enabled) {
10269
- const busyBucket = document.createElement('div');
10270
- busyBucket.setAttribute('part', 'loading');
10271
- busyBucket.className = 'busy-bucket';
10272
- if (this._config.busyBucket.showSpinner) {
10273
- const spinner = document.createElement('div');
10274
- spinner.className = 'spinner';
10275
- busyBucket.appendChild(spinner);
10276
- }
10277
- if (this._config.busyBucket.message) {
10278
- const message = document.createElement('div');
10279
- message.textContent = this._config.busyBucket.message;
10280
- busyBucket.appendChild(message);
10281
- }
10282
- this._optionsContainer.appendChild(busyBucket);
10283
- }
10284
- // Append Load More Trigger (Button or Sentinel) if enabled and not busy
10285
- else if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
10477
+ if (this._busyPresentationVisible && this._config.busyBucket.enabled) {
10478
+ this._appendBusyBucket();
10479
+ }
10480
+ // The load-more trigger follows logical busy state, not any optional
10481
+ // visual minimum-display hold after a request has already completed.
10482
+ if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
10286
10483
  this._addLoadMoreTrigger();
10287
10484
  }
10288
10485
  // Rebuilding the list temporarily removes its spacer geometry. Browsers