@smilodon/core 1.11.0 → 1.12.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 +33 -0
- package/dist/index.cjs +139 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +139 -21
- 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 +139 -21
- 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 +11 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4115,6 +4115,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4115
4115
|
this._pendingSearchRenderMark = false;
|
|
4116
4116
|
this._rangeAnchorIndex = null;
|
|
4117
4117
|
this._customOptionBoundElements = new WeakSet();
|
|
4118
|
+
this._customOptionManagedActiveClasses = new WeakMap();
|
|
4118
4119
|
this._customOptionNormalizedIds = new WeakMap();
|
|
4119
4120
|
this._customOptionNormalizedLabels = new WeakMap();
|
|
4120
4121
|
this._mirrorGlobalStylesForCustomOptions = false;
|
|
@@ -4134,6 +4135,22 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4134
4135
|
this._renderCycleWaiterTimeouts = new Map();
|
|
4135
4136
|
this._suppressNextOpenClick = false;
|
|
4136
4137
|
this._resolvedDropdownPlacement = 'bottom';
|
|
4138
|
+
// Presentation only: the popup engine is already closed while the exit runs.
|
|
4139
|
+
this._dropdownExitTimer = null;
|
|
4140
|
+
this._onDropdownExitAnimationEnd = (event) => {
|
|
4141
|
+
if (event.target !== this._dropdown || this._state.isOpen)
|
|
4142
|
+
return;
|
|
4143
|
+
if (this._dropdown.getAttribute('data-motion') !== 'closing')
|
|
4144
|
+
return;
|
|
4145
|
+
// A composite consumer animation must finish all timelines, not just the first.
|
|
4146
|
+
const names = getComputedStyle(this._dropdown).animationName
|
|
4147
|
+
.split(',').map((name) => name.trim()).filter((name) => name && name !== 'none');
|
|
4148
|
+
if (names.length > 1)
|
|
4149
|
+
return; // bounded timeout waits for the longest timeline
|
|
4150
|
+
if (event.animationName && names[0] && event.animationName !== names[0])
|
|
4151
|
+
return;
|
|
4152
|
+
this._finishDropdownExit();
|
|
4153
|
+
};
|
|
4137
4154
|
this._multiScrollDrag = {
|
|
4138
4155
|
active: false,
|
|
4139
4156
|
moved: false,
|
|
@@ -4295,6 +4312,11 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4295
4312
|
this._state.isSearching = false;
|
|
4296
4313
|
this._state.preserveScrollPosition = false;
|
|
4297
4314
|
}
|
|
4315
|
+
// A disconnected popup must not retain a visual exit or a live timer.
|
|
4316
|
+
this._cancelDropdownExit();
|
|
4317
|
+
this._dropdown.style.display = 'none';
|
|
4318
|
+
this._dropdown.setAttribute('inert', '');
|
|
4319
|
+
this._dropdown.setAttribute('aria-hidden', 'true');
|
|
4298
4320
|
// unregister instance
|
|
4299
4321
|
EnhancedSelect._instances.delete(this);
|
|
4300
4322
|
if (this._state.isOpen) {
|
|
@@ -5648,6 +5670,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5648
5670
|
--select-dropdown-top: calc(100% + 6px);
|
|
5649
5671
|
--select-dropdown-bottom: calc(100% + 6px);
|
|
5650
5672
|
--select-dropdown-animation: dropdownEnter 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
5673
|
+
--select-dropdown-exit-animation: dropdownExit 160ms cubic-bezier(0.4, 0, 1, 1) forwards;
|
|
5674
|
+
--select-dropdown-exit-from-opacity: 1;
|
|
5675
|
+
--select-dropdown-exit-from-transform: translateY(0) scale(1);
|
|
5676
|
+
--select-dropdown-exit-to-opacity: 0;
|
|
5677
|
+
--select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
|
|
5678
|
+
--select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
|
|
5651
5679
|
--select-dropdown-enter-from-opacity: 0;
|
|
5652
5680
|
--select-dropdown-enter-from-transform: translateY(-8px) scale(0.98);
|
|
5653
5681
|
--select-dropdown-enter-to-opacity: 1;
|
|
@@ -6350,8 +6378,26 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6350
6378
|
|
|
6351
6379
|
.select-dropdown[data-placement="top"] {
|
|
6352
6380
|
--select-dropdown-enter-from-transform: var(--select-dropdown-top-enter-from-transform, translateY(8px) scale(0.98));
|
|
6381
|
+
--select-dropdown-exit-to-transform: var(--select-dropdown-top-exit-to-transform, translateY(8px) scale(0.98));
|
|
6353
6382
|
}
|
|
6354
|
-
|
|
6383
|
+
|
|
6384
|
+
/* A closed popup stays visually mounted for exit, but cannot be interacted with. */
|
|
6385
|
+
.select-dropdown[data-motion="closing"] {
|
|
6386
|
+
animation: var(--select-dropdown-exit-animation);
|
|
6387
|
+
pointer-events: none;
|
|
6388
|
+
}
|
|
6389
|
+
|
|
6390
|
+
@keyframes dropdownExit {
|
|
6391
|
+
from {
|
|
6392
|
+
opacity: var(--select-dropdown-exit-from-opacity);
|
|
6393
|
+
transform: var(--select-dropdown-exit-from-transform);
|
|
6394
|
+
}
|
|
6395
|
+
to {
|
|
6396
|
+
opacity: var(--select-dropdown-exit-to-opacity);
|
|
6397
|
+
transform: var(--select-dropdown-exit-to-transform);
|
|
6398
|
+
}
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6355
6401
|
@keyframes dropdownEnter {
|
|
6356
6402
|
0% {
|
|
6357
6403
|
opacity: var(--select-dropdown-enter-from-opacity);
|
|
@@ -7357,6 +7403,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7357
7403
|
if (!effects.some((effect) => effect.type === 'POPUP_OPENED'))
|
|
7358
7404
|
return;
|
|
7359
7405
|
this._runEngineEffects(effects);
|
|
7406
|
+
// Reopening during exit cancels the old finish callback and restores interactivity.
|
|
7407
|
+
this._cancelDropdownExit();
|
|
7408
|
+
this._dropdown.removeAttribute('inert');
|
|
7409
|
+
this._dropdown.removeAttribute('aria-hidden');
|
|
7360
7410
|
this._markOpenStart();
|
|
7361
7411
|
this.setAttribute('data-open', 'true');
|
|
7362
7412
|
this._liftStackingAncestors();
|
|
@@ -7393,14 +7443,78 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7393
7443
|
return;
|
|
7394
7444
|
this.removeAttribute('data-open');
|
|
7395
7445
|
this._restoreLiftedAncestors();
|
|
7396
|
-
this._dropdown.style.display = 'none';
|
|
7397
7446
|
this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
|
|
7398
7447
|
this._updateArrowRotation();
|
|
7448
|
+
// Engine + ARIA close immediately. Only the visual panel waits for exit.
|
|
7399
7449
|
this._runEngineEffects(effects);
|
|
7450
|
+
this._beginDropdownExit(reason === 'disconnect' || !this.isConnected);
|
|
7400
7451
|
this._emit('close', {});
|
|
7401
7452
|
this._config.callbacks.onClose?.();
|
|
7402
7453
|
this._announce('Options collapsed');
|
|
7403
7454
|
}
|
|
7455
|
+
/** Stop an outstanding exit before reopening, disconnecting or starting another one. */
|
|
7456
|
+
_cancelDropdownExit() {
|
|
7457
|
+
if (this._dropdownExitTimer !== null) {
|
|
7458
|
+
window.clearTimeout(this._dropdownExitTimer);
|
|
7459
|
+
this._dropdownExitTimer = null;
|
|
7460
|
+
}
|
|
7461
|
+
this._dropdown.removeEventListener('animationend', this._onDropdownExitAnimationEnd);
|
|
7462
|
+
this._dropdown.removeAttribute('data-motion');
|
|
7463
|
+
}
|
|
7464
|
+
_finishDropdownExit() {
|
|
7465
|
+
if (this._state.isOpen || this._dropdown.getAttribute('data-motion') !== 'closing')
|
|
7466
|
+
return;
|
|
7467
|
+
this._cancelDropdownExit();
|
|
7468
|
+
this._dropdown.style.display = 'none';
|
|
7469
|
+
}
|
|
7470
|
+
_beginDropdownExit(immediate) {
|
|
7471
|
+
this._cancelDropdownExit();
|
|
7472
|
+
// Inert + aria-hidden apply at logical close, not at animation completion.
|
|
7473
|
+
this._dropdown.setAttribute('inert', '');
|
|
7474
|
+
this._dropdown.setAttribute('aria-hidden', 'true');
|
|
7475
|
+
if (immediate || this._dropdown.style.display === 'none') {
|
|
7476
|
+
this._dropdown.style.display = 'none';
|
|
7477
|
+
return;
|
|
7478
|
+
}
|
|
7479
|
+
this._dropdown.setAttribute('data-motion', 'closing');
|
|
7480
|
+
const duration = this._getDropdownExitDurationMs();
|
|
7481
|
+
if (duration <= 0) {
|
|
7482
|
+
this._finishDropdownExit();
|
|
7483
|
+
return;
|
|
7484
|
+
}
|
|
7485
|
+
// animationend optimizes normal completion; timeout handles missing/cancelled events.
|
|
7486
|
+
this._dropdown.addEventListener('animationend', this._onDropdownExitAnimationEnd);
|
|
7487
|
+
this._dropdownExitTimer = window.setTimeout(() => this._finishDropdownExit(), duration + 34);
|
|
7488
|
+
}
|
|
7489
|
+
/** CSS animations may be disabled or customized by consumers; never wait forever. */
|
|
7490
|
+
_getDropdownExitDurationMs() {
|
|
7491
|
+
if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
|
|
7492
|
+
return 0;
|
|
7493
|
+
const style = getComputedStyle(this._dropdown);
|
|
7494
|
+
const names = style.animationName.split(',').map((value) => value.trim());
|
|
7495
|
+
if (!names.length || names.every((name) => !name || name === 'none'))
|
|
7496
|
+
return 0;
|
|
7497
|
+
const toMs = (value) => {
|
|
7498
|
+
const trimmed = value.trim();
|
|
7499
|
+
const parsed = Number.parseFloat(trimmed);
|
|
7500
|
+
if (!Number.isFinite(parsed))
|
|
7501
|
+
return 0;
|
|
7502
|
+
return trimmed.endsWith('ms') ? parsed : trimmed.endsWith('s') ? parsed * 1000 : 0;
|
|
7503
|
+
};
|
|
7504
|
+
const durations = style.animationDuration.split(',');
|
|
7505
|
+
const delays = style.animationDelay.split(',');
|
|
7506
|
+
const counts = style.animationIterationCount.split(',');
|
|
7507
|
+
const maximum = names.reduce((max, name, index) => {
|
|
7508
|
+
if (!name || name === 'none')
|
|
7509
|
+
return max;
|
|
7510
|
+
const duration = toMs(durations[index % durations.length] ?? '0s');
|
|
7511
|
+
const delay = toMs(delays[index % delays.length] ?? '0s');
|
|
7512
|
+
const count = Number.parseFloat(counts[index % counts.length] ?? '1');
|
|
7513
|
+
const iterations = Number.isFinite(count) ? Math.max(0, count) : 1;
|
|
7514
|
+
return Math.max(max, Math.max(0, duration * iterations + delay));
|
|
7515
|
+
}, 0);
|
|
7516
|
+
return Math.min(maximum, 10000);
|
|
7517
|
+
}
|
|
7404
7518
|
_updateDropdownVisibility() {
|
|
7405
7519
|
if (this._state.isOpen) {
|
|
7406
7520
|
this.setAttribute('data-open', 'true');
|
|
@@ -7791,8 +7905,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7791
7905
|
prevOption.setActive(false);
|
|
7792
7906
|
}
|
|
7793
7907
|
else {
|
|
7794
|
-
|
|
7795
|
-
prevOption.classList.remove('active', 'smilodon-option--active');
|
|
7908
|
+
this._syncCustomOptionActiveClasses(prevOption, false);
|
|
7796
7909
|
}
|
|
7797
7910
|
}
|
|
7798
7911
|
}
|
|
@@ -7803,8 +7916,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7803
7916
|
option.setActive(true);
|
|
7804
7917
|
}
|
|
7805
7918
|
else {
|
|
7806
|
-
|
|
7807
|
-
option.classList.add('active', 'smilodon-option--active');
|
|
7919
|
+
this._syncCustomOptionActiveClasses(option, true);
|
|
7808
7920
|
}
|
|
7809
7921
|
if (typeof option.scrollIntoView === 'function') {
|
|
7810
7922
|
// Don't scroll wildly when just opening with pre-selections
|
|
@@ -10299,6 +10411,26 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10299
10411
|
option.ensureRendered();
|
|
10300
10412
|
}
|
|
10301
10413
|
}
|
|
10414
|
+
/** Keep custom option active classes aligned with the engine, including previous class maps. */
|
|
10415
|
+
_syncCustomOptionActiveClasses(option, active) {
|
|
10416
|
+
const mapped = (this.classMap?.active ?? 'active sm-active').split(/\s+/).filter(Boolean);
|
|
10417
|
+
const styled = (this._config.styles.classNames?.activeOption ?? '').split(/\s+/).filter(Boolean);
|
|
10418
|
+
const current = [...new Set([...mapped, ...styled, 'smilodon-option--active'])];
|
|
10419
|
+
const previous = this._customOptionManagedActiveClasses.get(option) ?? [];
|
|
10420
|
+
option.classList.remove(...new Set([...previous, ...current, 'active', 'sm-active', 'smilodon-option--active']));
|
|
10421
|
+
if (active)
|
|
10422
|
+
option.classList.add(...current);
|
|
10423
|
+
this._customOptionManagedActiveClasses.set(option, current);
|
|
10424
|
+
const states = new Set((option.dataset.smState ?? '').split(/\s+/).filter(Boolean));
|
|
10425
|
+
if (active)
|
|
10426
|
+
states.add('active');
|
|
10427
|
+
else
|
|
10428
|
+
states.delete('active');
|
|
10429
|
+
if (states.size)
|
|
10430
|
+
option.dataset.smState = [...states].join(' ');
|
|
10431
|
+
else
|
|
10432
|
+
delete option.dataset.smState;
|
|
10433
|
+
}
|
|
10302
10434
|
_normalizeCustomOptionElement(element, meta) {
|
|
10303
10435
|
const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
|
|
10304
10436
|
// Add part attribute for styling
|
|
@@ -10320,7 +10452,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10320
10452
|
const isDisabledInteractive = isDisabled && (isDisabledSelectable || isDisabledHoverable);
|
|
10321
10453
|
// Resolve classes from classMap or defaults
|
|
10322
10454
|
const selectedClasses = (this.classMap?.selected ?? 'selected sm-selected').split(' ').filter(Boolean);
|
|
10323
|
-
const activeClasses = (this.classMap?.active ?? 'active sm-active').split(' ').filter(Boolean);
|
|
10324
10455
|
const disabledClasses = (this.classMap?.disabled ?? 'disabled sm-disabled').split(' ').filter(Boolean);
|
|
10325
10456
|
if (isSelected) {
|
|
10326
10457
|
optionEl.classList.add(...selectedClasses);
|
|
@@ -10336,20 +10467,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10336
10467
|
optionEl.classList.remove(...this._config.styles.classNames.selectedOption.split(' ').filter(Boolean));
|
|
10337
10468
|
}
|
|
10338
10469
|
}
|
|
10339
|
-
|
|
10340
|
-
optionEl.classList.add(...activeClasses);
|
|
10341
|
-
optionEl.classList.add('smilodon-option--active');
|
|
10342
|
-
if (this._config.styles.classNames?.activeOption) {
|
|
10343
|
-
optionEl.classList.add(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
|
|
10344
|
-
}
|
|
10345
|
-
}
|
|
10346
|
-
else {
|
|
10347
|
-
optionEl.classList.remove(...activeClasses);
|
|
10348
|
-
optionEl.classList.remove('smilodon-option--active');
|
|
10349
|
-
if (this._config.styles.classNames?.activeOption) {
|
|
10350
|
-
optionEl.classList.remove(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
|
|
10351
|
-
}
|
|
10352
|
-
}
|
|
10470
|
+
this._syncCustomOptionActiveClasses(optionEl, isActive);
|
|
10353
10471
|
if (isDisabled) {
|
|
10354
10472
|
optionEl.classList.add(...disabledClasses);
|
|
10355
10473
|
optionEl.classList.add('smilodon-option--disabled');
|