@smilodon/core 1.13.0 → 1.18.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
@@ -2111,6 +2111,8 @@
2111
2111
  overflowX: 'hidden',
2112
2112
  overflowY: 'auto',
2113
2113
  dragScroll: true,
2114
+ scrollToLatestChip: false,
2115
+ scrollToLatestChipBehavior: 'smooth',
2114
2116
  },
2115
2117
  scrollToSelected: {
2116
2118
  enabled: true,
@@ -2976,23 +2978,23 @@
2976
2978
  }
2977
2979
  }
2978
2980
  _attachEventListeners() {
2979
- // Click handler for selection
2981
+ // One delegated handler survives all SelectOption re-renders. In
2982
+ // particular, SVG descendants of the remove icon must remove the option,
2983
+ // not accidentally activate the surrounding option.
2980
2984
  this._container.addEventListener('click', (e) => {
2981
- // Don't trigger selection if clicking remove button
2982
- if (e.target === this._removeButton) {
2985
+ const target = e.target;
2986
+ if (this._removeButton
2987
+ && target instanceof Node
2988
+ && this._removeButton.contains(target)) {
2989
+ e.preventDefault();
2990
+ e.stopPropagation();
2991
+ this._handleRemove();
2983
2992
  return;
2984
2993
  }
2985
2994
  if (!this._isDisabledSelectionBlocked()) {
2986
2995
  this._handleSelect();
2987
2996
  }
2988
2997
  });
2989
- // Remove button handler
2990
- if (this._removeButton) {
2991
- this._removeButton.addEventListener('click', (e) => {
2992
- e.stopPropagation();
2993
- this._handleRemove();
2994
- });
2995
- }
2996
2998
  // Keyboard handler
2997
2999
  this.addEventListener('keydown', (e) => {
2998
3000
  if (this._isDisabledSelectionBlocked())
@@ -3055,7 +3057,6 @@
3055
3057
  updateConfig(updates) {
3056
3058
  this._config = { ...this._config, ...updates };
3057
3059
  this._render();
3058
- this._attachEventListeners();
3059
3060
  }
3060
3061
  /**
3061
3062
  * Get current configuration
@@ -4070,6 +4071,7 @@
4070
4071
  intendedRenderKeys: [],
4071
4072
  filteredIndexByKey: new Map(),
4072
4073
  };
4074
+ this._emptyStateContext = null;
4073
4075
  // Null keeps the public/default renderer on its legacy full path. This
4074
4076
  // private state is only used by guarded virtualization integration.
4075
4077
  this._guardedVirtualWindow = null;
@@ -4126,6 +4128,10 @@
4126
4128
  this._pendingFirstRenderMark = false;
4127
4129
  this._pendingSearchRenderMark = false;
4128
4130
  this._rangeAnchorIndex = null;
4131
+ /** Chip identity is tracked independently of dropdown option positions. */
4132
+ this._lastRenderedChipKeys = null;
4133
+ this._latestChipScrollGeneration = 0;
4134
+ this._latestChipScrollFrame = null;
4129
4135
  this._customOptionBoundElements = new WeakSet();
4130
4136
  this._customOptionManagedActiveClasses = new WeakMap();
4131
4137
  this._customOptionNormalizedIds = new WeakMap();
@@ -4316,6 +4322,7 @@
4316
4322
  this._syncListboxAccessibility();
4317
4323
  }
4318
4324
  disconnectedCallback() {
4325
+ this._cancelLatestChipScroll();
4319
4326
  this._cancelBusyPresentation();
4320
4327
  if (this._dataRequestCoordinator) {
4321
4328
  const actions = this._dataRequestCoordinator.disconnect();
@@ -5533,7 +5540,9 @@
5533
5540
  `;
5534
5541
  const slot = container.querySelector('slot[name="arrow"]');
5535
5542
  slot?.addEventListener('slotchange', () => {
5536
- if (slot.assignedElements({ flatten: true }).length > 0) {
5543
+ // Do not flatten: flattening can expose the built-in SVG fallback
5544
+ // as an assigned element after the last custom arrow is removed.
5545
+ if (slot.assignedElements().length > 0) {
5537
5546
  this.setAttribute('data-custom-arrow', 'true');
5538
5547
  }
5539
5548
  else {
@@ -6262,7 +6271,7 @@
6262
6271
  }
6263
6272
 
6264
6273
  :host([data-custom-arrow="true"]) .dropdown-arrow-container:hover {
6265
- background-color: transparent;
6274
+ background-color: var(--select-arrow-hover-bg, transparent);
6266
6275
  }
6267
6276
 
6268
6277
  .dropdown-arrow {
@@ -7908,6 +7917,12 @@
7908
7917
  : delta >= 0
7909
7918
  ? -1
7910
7919
  : selectableIndices.length;
7920
+ // The final selectable option is the keyboard pagination boundary.
7921
+ // Keep the active option stable while the coordinator requests more data.
7922
+ if (delta === 1
7923
+ && currentPosition === selectableIndices.length - 1
7924
+ && this._requestKeyboardLoadMore())
7925
+ return;
7911
7926
  const nextPosition = Math.max(0, Math.min(selectableIndices.length - 1, basePosition + delta));
7912
7927
  const next = selectableIndices[nextPosition];
7913
7928
  this._setActive(next);
@@ -7920,6 +7935,33 @@
7920
7935
  this._selectRange(anchorIndex, next, { clear: !opts?.toggleKey });
7921
7936
  }
7922
7937
  }
7938
+ /** Return true only when boundary navigation is held for an in-flight/new page. */
7939
+ _requestKeyboardLoadMore() {
7940
+ if (!this._state.isOpen
7941
+ || !this._config.infiniteScroll.enabled
7942
+ || this._dataLoadingConfig.protocol !== 'acknowledged'
7943
+ || !this._dataRequestCoordinator
7944
+ || !this._acknowledgedReady)
7945
+ return false;
7946
+ if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)
7947
+ return true;
7948
+ const snapshot = this._dataRequestCoordinator.getSnapshot();
7949
+ if (!snapshot.connected)
7950
+ return false;
7951
+ if (snapshot.busy)
7952
+ return true;
7953
+ if (!snapshot.hasMore
7954
+ || snapshot.error !== null
7955
+ || snapshot.resourceLimit !== null
7956
+ || (snapshot.status !== 'succeeded' && snapshot.status !== 'empty'))
7957
+ return false;
7958
+ // Delegate identity, pagination, and in-flight protection to the coordinator.
7959
+ const actions = this._dataRequestCoordinator.requestLoadMore('manual');
7960
+ if (actions.length === 0)
7961
+ return false;
7962
+ this._dispatchAcknowledgedActions(actions);
7963
+ return true;
7964
+ }
7923
7965
  _setActive(index, reason = 'keyboard') {
7924
7966
  this._ensureRegistryCurrent();
7925
7967
  const record = this._getRecordByIndex(index);
@@ -8239,6 +8281,19 @@
8239
8281
  _updateInputDisplay() {
8240
8282
  const selectedEntries = this._getSelectedEntries();
8241
8283
  const selectedItems = selectedEntries.map(({ item }) => item);
8284
+ const nextKeys = new Set(selectedEntries.map(({ key }) => key));
8285
+ const previousKeys = this._lastRenderedChipKeys;
8286
+ let newlyAddedKey;
8287
+ if (previousKeys) {
8288
+ for (const key of nextKeys) {
8289
+ if (!previousKeys.has(key))
8290
+ newlyAddedKey = key;
8291
+ }
8292
+ }
8293
+ this._lastRenderedChipKeys = nextKeys;
8294
+ const previousChipScrollLeft = this._inputContent.scrollLeft;
8295
+ // Only a newly added selected key can initiate auto-scroll.
8296
+ this._cancelLatestChipScroll();
8242
8297
  const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
8243
8298
  if (selectedItems.length === 0) {
8244
8299
  this._input.value = '';
@@ -8314,8 +8369,87 @@
8314
8369
  if (this._acknowledgedPendingSearchQuery !== null) {
8315
8370
  this._input.value = this._acknowledgedPendingSearchQuery;
8316
8371
  }
8372
+ // Recreating the chip DOM must not reset manual scrolling. In particular,
8373
+ // remove/clear, config rerenders, and item refreshes are not scroll intents.
8374
+ if (this._config.selection.mode === 'multi') {
8375
+ this._inputContent.scrollLeft = previousChipScrollLeft;
8376
+ if (newlyAddedKey !== undefined)
8377
+ this._scheduleLatestChipScroll(newlyAddedKey);
8378
+ }
8317
8379
  this._syncClearControlState();
8318
8380
  }
8381
+ _cancelLatestChipScroll() {
8382
+ this._latestChipScrollGeneration += 1;
8383
+ if (this._latestChipScrollFrame !== null) {
8384
+ cancelAnimationFrame(this._latestChipScrollFrame);
8385
+ this._latestChipScrollFrame = null;
8386
+ }
8387
+ }
8388
+ _scheduleLatestChipScroll(key) {
8389
+ if (!this.isConnected
8390
+ || this._config.selection.mode !== 'multi'
8391
+ || this._config.multiSelectDisplay.mode !== 'horizontal'
8392
+ || this._config.multiSelectDisplay.scrollToLatestChip !== true
8393
+ || this._config.multiSelectDisplay.overflowX === 'hidden')
8394
+ return;
8395
+ const generation = this._latestChipScrollGeneration;
8396
+ this._latestChipScrollFrame = requestAnimationFrame(() => {
8397
+ this._latestChipScrollFrame = null;
8398
+ if (generation !== this._latestChipScrollGeneration
8399
+ || !this.isConnected
8400
+ || this._multiScrollDrag.active
8401
+ || this._config.selection.mode !== 'multi'
8402
+ || this._config.multiSelectDisplay.mode !== 'horizontal'
8403
+ || this._config.multiSelectDisplay.scrollToLatestChip !== true)
8404
+ return;
8405
+ // Match the canonical selected-key sequence, not option indices:
8406
+ // selected items may be reordered or detached from the loaded page.
8407
+ const entries = this._getSelectedEntries();
8408
+ const index = entries.findIndex((entry) => entry.key === key);
8409
+ if (index < 0)
8410
+ return;
8411
+ const chip = this._inputContent.querySelectorAll('.selection-badge')[index];
8412
+ if (!chip)
8413
+ return;
8414
+ const hostBounds = this._inputContent.getBoundingClientRect();
8415
+ const chipBounds = chip.getBoundingClientRect();
8416
+ const leftEdge = hostBounds.left + this._inputContent.clientLeft;
8417
+ const rightEdge = leftEdge + this._inputContent.clientWidth;
8418
+ let delta;
8419
+ if (chip.parentElement === this._inputContent && chip.offsetWidth > 0) {
8420
+ // getBoundingClientRect() includes the chip's entry animation transform.
8421
+ // Use layout dimensions so the scroll target remains correct while the
8422
+ // chip scales into its final size. In RTL layouts, offsetLeft and
8423
+ // scrollLeft are both negative relative to the inline-start origin, so
8424
+ // the same subtraction maps the chip into the viewport's coordinates.
8425
+ const chipLeft = chip.offsetLeft - this._inputContent.scrollLeft;
8426
+ const chipRight = chipLeft + chip.offsetWidth;
8427
+ delta = chipRight > this._inputContent.clientWidth
8428
+ ? chipRight - this._inputContent.clientWidth
8429
+ : chipLeft < 0
8430
+ ? chipLeft
8431
+ : 0;
8432
+ }
8433
+ else {
8434
+ // DOM test environments without layout use the measurable rectangle.
8435
+ delta = chipBounds.right > rightEdge
8436
+ ? chipBounds.right - rightEdge
8437
+ : chipBounds.left < leftEdge
8438
+ ? chipBounds.left - leftEdge
8439
+ : 0;
8440
+ }
8441
+ if (Math.abs(delta) < 0.5)
8442
+ return;
8443
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
8444
+ const behavior = reducedMotion ? 'auto' : (this._config.multiSelectDisplay.scrollToLatestChipBehavior ?? 'smooth');
8445
+ if (typeof this._inputContent.scrollBy === 'function') {
8446
+ this._inputContent.scrollBy({ left: delta, behavior });
8447
+ }
8448
+ else {
8449
+ this._inputContent.scrollLeft += delta;
8450
+ }
8451
+ });
8452
+ }
8319
8453
  _isActivelyEditingSearchInput() {
8320
8454
  return this._config.searchable === true
8321
8455
  && this._state.isOpen
@@ -8581,12 +8715,13 @@
8581
8715
  classMap: true,
8582
8716
  optionRenderer: true,
8583
8717
  groupHeaderRenderer: true,
8718
+ emptyStateSlot: true,
8584
8719
  cssCustomProperties: true,
8585
8720
  shadowParts: true,
8586
8721
  globalStyleMirroring: true,
8587
8722
  },
8588
8723
  events: {
8589
- emitted: ['select', 'open', 'close', 'search', 'change', 'loadMore', 'remove', 'clear', 'error', 'diagnostic'],
8724
+ emitted: ['select', 'open', 'close', 'search', 'change', 'loadMore', 'remove', 'clear', 'emptyStateChange', 'error', 'diagnostic'],
8590
8725
  diagnosticEvent: true,
8591
8726
  },
8592
8727
  functionality: {
@@ -8602,6 +8737,36 @@
8602
8737
  limitations: this.getKnownLimitations(),
8603
8738
  };
8604
8739
  }
8740
+ /** Return a detached immutable snapshot of the currently rendered empty state. */
8741
+ getEmptyStateContext() {
8742
+ const context = this._emptyStateContext;
8743
+ return context ? Object.freeze({ query: context.query, reason: context.reason }) : null;
8744
+ }
8745
+ _syncEmptyStateContext(context) {
8746
+ const current = this._emptyStateContext;
8747
+ if (current?.query === context?.query
8748
+ && current?.reason === context?.reason
8749
+ && Boolean(current) === Boolean(context))
8750
+ return;
8751
+ this._emptyStateContext = context
8752
+ ? Object.freeze({ query: context.query, reason: context.reason })
8753
+ : null;
8754
+ const detail = Object.freeze({ context: this.getEmptyStateContext() });
8755
+ this._emit('emptyStateChange', detail);
8756
+ }
8757
+ _appendEmptyState(context) {
8758
+ const empty = document.createElement('div');
8759
+ empty.setAttribute('part', 'no-results');
8760
+ empty.className = 'empty-state';
8761
+ const slot = document.createElement('slot');
8762
+ slot.name = 'empty-state';
8763
+ slot.appendChild(document.createTextNode(context.reason === 'no-results'
8764
+ ? `No results found for "${context.query}"`
8765
+ : 'No options available'));
8766
+ empty.appendChild(slot);
8767
+ this._optionsContainer.appendChild(empty);
8768
+ this._syncEmptyStateContext(context);
8769
+ }
8605
8770
  _emitChange() {
8606
8771
  const selectedEntries = this._getSelectedEntries();
8607
8772
  const selectedItems = selectedEntries.map(({ item }) => item);
@@ -9767,11 +9932,27 @@
9767
9932
  this._state.isBusy = snapshot.busy;
9768
9933
  if (!snapshot.busy) {
9769
9934
  this._syncBusyPresentation();
9770
- if (!this._busyPresentationVisible) {
9771
- this._optionsContainer.querySelector('.busy-bucket')?.remove();
9935
+ const shouldReconcileEmptyState = snapshot.status === 'exhausted'
9936
+ && this._renderPlan.filteredKeys.length === 0;
9937
+ if (shouldReconcileEmptyState) {
9938
+ // The first projection rendered while logically busy, so the empty
9939
+ // state was intentionally suppressed. Reconcile only this terminal
9940
+ // empty case after settlement; keep any minimum-duration busy
9941
+ // presentation and its timer intact.
9942
+ this._renderOptions();
9943
+ const emptyStateRenderCycleId = this._renderCycleId;
9944
+ const emptyStateRenderCompleted = await this._waitForRenderCycle(emptyStateRenderCycleId);
9945
+ if (!emptyStateRenderCompleted) {
9946
+ throw new Error('Acknowledged empty-state render was superseded before completion');
9947
+ }
9948
+ }
9949
+ else {
9950
+ if (!this._busyPresentationVisible) {
9951
+ this._optionsContainer.querySelector('.busy-bucket')?.remove();
9952
+ }
9953
+ if (this._shouldRenderLoadMoreTrigger())
9954
+ this._addLoadMoreTrigger();
9772
9955
  }
9773
- if (this._shouldRenderLoadMoreTrigger())
9774
- this._addLoadMoreTrigger();
9775
9956
  }
9776
9957
  this._optionsContainer.scrollTop = this._acknowledgedProjectionScrollTop;
9777
9958
  this._syncListboxAccessibility();
@@ -10098,7 +10279,7 @@
10098
10279
  this._busyPresentationGeneration += 1;
10099
10280
  this._clearBusyPresentationHideTimer();
10100
10281
  this._busyPresentationVisible = this._config.busyBucket.enabled;
10101
- this._busyPresentationStartedAt = this._busyBucket?.isConnected ? Date.now() : null;
10282
+ this._busyPresentationStartedAt = Date.now();
10102
10283
  }
10103
10284
  _syncBusyPresentation() {
10104
10285
  if (!this._config.busyBucket.enabled) {
@@ -10266,6 +10447,7 @@
10266
10447
  this._optionsContainer.innerHTML = '';
10267
10448
  let filteredIndicesForScope = [];
10268
10449
  let guardedScrollTopToRestore = null;
10450
+ let renderedEmptyStateContext = null;
10269
10451
  // Ensure dropdown only contains options container (cleanup legacy direct children)
10270
10452
  // We need to preserve optionsContainer, so we can't just clear dropdown.innerHTML
10271
10453
  // But we can check if there are other children and remove them
@@ -10289,6 +10471,7 @@
10289
10471
  searching.setAttribute('part', 'loading');
10290
10472
  searching.textContent = 'Searching...';
10291
10473
  this._optionsContainer.appendChild(searching);
10474
+ this._syncEmptyStateContext(null);
10292
10475
  this._resolveRenderCycle(renderCycleId, true);
10293
10476
  return;
10294
10477
  }
@@ -10392,17 +10575,11 @@
10392
10575
  const filteredIndices = this._renderPlan.filteredIndices;
10393
10576
  this._refreshVirtualizationScope(filteredIndicesForScope);
10394
10577
  this._appendGuardedTopSpacer();
10395
- if (filteredIndices.length === 0 && !this._state.isBusy) {
10396
- const empty = document.createElement('div');
10397
- empty.setAttribute('part', 'no-results');
10398
- empty.className = 'empty-state';
10399
- if (query) {
10400
- empty.textContent = `No results found for "${this._state.searchQuery}"`;
10401
- }
10402
- else {
10403
- empty.textContent = 'No options available';
10404
- }
10405
- this._optionsContainer.appendChild(empty);
10578
+ if (this._renderPlan.filteredKeys.length === 0 && !this._state.isBusy) {
10579
+ renderedEmptyStateContext = this._state.searchQuery
10580
+ ? { query: this._state.searchQuery, reason: 'no-results' }
10581
+ : { query: '', reason: 'no-options' };
10582
+ this._appendEmptyState(renderedEmptyStateContext);
10406
10583
  }
10407
10584
  else {
10408
10585
  const shouldIncrementalRender = !this._guardedVirtualizer
@@ -10464,6 +10641,7 @@
10464
10641
  }
10465
10642
  };
10466
10643
  renderChunk();
10644
+ this._syncEmptyStateContext(null);
10467
10645
  return;
10468
10646
  }
10469
10647
  filteredIndices.forEach((itemIndex) => {
@@ -10488,6 +10666,7 @@
10488
10666
  if (guardedScrollTopToRestore !== null) {
10489
10667
  this._optionsContainer.scrollTop = guardedScrollTopToRestore;
10490
10668
  }
10669
+ this._syncEmptyStateContext(renderedEmptyStateContext);
10491
10670
  this._syncRenderedOptionAccessibility();
10492
10671
  this._syncLegacyActiveAria();
10493
10672
  this._syncGuardedOptionResizeTargets();