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