@smilodon/core 1.5.3 → 1.5.4

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
@@ -1598,7 +1598,7 @@ class SelectOption extends HTMLElement {
1598
1598
  transform: var(--select-option-selected-hover-transform, var(--select-option-selected-transform, var(--select-option-transform, none)));
1599
1599
  }
1600
1600
 
1601
- .option-container.active {
1601
+ .option-container.active:not(.disabled) {
1602
1602
  background: var(--select-option-active-bg, var(--select-option-hover-bg, #f0f0f0));
1603
1603
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text-color, #1f2937))));
1604
1604
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -1726,7 +1726,7 @@ class SelectOption extends HTMLElement {
1726
1726
  toggleClasses(this._container, [...selectedClasses, 'smilodon-option--selected'], false);
1727
1727
  toggleClasses(this, [...selectedClasses, 'smilodon-option--selected'], false);
1728
1728
  }
1729
- if (active) {
1729
+ if (active && !disabled) {
1730
1730
  toggleClasses(this._container, [...activeClasses, 'smilodon-option--active'], true);
1731
1731
  toggleClasses(this, [...activeClasses, 'smilodon-option--active'], true); // Make focus ring visible on host
1732
1732
  }
@@ -1794,8 +1794,12 @@ class SelectOption extends HTMLElement {
1794
1794
  // Set ARIA attributes and State attributes on Host
1795
1795
  this.setAttribute('role', 'option');
1796
1796
  this.setAttribute('aria-selected', String(selected));
1797
- if (disabled)
1797
+ if (disabled) {
1798
1798
  this.setAttribute('aria-disabled', 'true');
1799
+ }
1800
+ else {
1801
+ this.removeAttribute('aria-disabled');
1802
+ }
1799
1803
  this.id = this._config.id || `select-option-${index}`;
1800
1804
  // Add checkmark (part="checkmark") - standard for object mode
1801
1805
  // Only show if NOT showing remove button (avoid clutter)
@@ -1814,7 +1818,7 @@ class SelectOption extends HTMLElement {
1814
1818
  const state = [];
1815
1819
  if (selected)
1816
1820
  state.push('selected');
1817
- if (active)
1821
+ if (active && !disabled)
1818
1822
  state.push('active');
1819
1823
  if (state.length) {
1820
1824
  this.dataset.smState = state.join(' ');
@@ -1938,7 +1942,7 @@ class SelectOption extends HTMLElement {
1938
1942
  * Set active state
1939
1943
  */
1940
1944
  setActive(active) {
1941
- this._config.active = active;
1945
+ this._config.active = active && !this._config.disabled;
1942
1946
  this._render();
1943
1947
  }
1944
1948
  /**
@@ -2451,11 +2455,11 @@ class EnhancedSelect extends HTMLElement {
2451
2455
  this._inputContainer.removeAttribute('data-multi-scroll-mode');
2452
2456
  this._inputContainer.removeAttribute('data-drag-scroll');
2453
2457
  this._inputContainer.classList.remove('is-dragging-scroll');
2454
- this._inputContainer.style.removeProperty('--select-multi-input-max-height');
2455
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-x');
2456
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-y');
2457
- this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap');
2458
- this._inputContainer.style.removeProperty('--select-multi-input-align-content');
2458
+ this._inputContainer.style.removeProperty('--select-multi-input-max-height-config');
2459
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-x-config');
2460
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-y-config');
2461
+ this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap-config');
2462
+ this._inputContainer.style.removeProperty('--select-multi-input-align-content-config');
2459
2463
  return;
2460
2464
  }
2461
2465
  const maxHeight = this._config.multiSelectDisplay?.maxHeight ?? '160px';
@@ -2465,11 +2469,11 @@ class EnhancedSelect extends HTMLElement {
2465
2469
  const alignContent = mode === 'horizontal' ? 'center' : 'flex-start';
2466
2470
  this._inputContainer.setAttribute('data-multi-scroll-mode', mode);
2467
2471
  this._inputContainer.setAttribute('data-drag-scroll', String(dragEnabled && mode === 'horizontal'));
2468
- this._inputContainer.style.setProperty('--select-multi-input-max-height', maxHeight);
2469
- this._inputContainer.style.setProperty('--select-multi-input-overflow-x', overflowX);
2470
- this._inputContainer.style.setProperty('--select-multi-input-overflow-y', overflowY);
2471
- this._inputContainer.style.setProperty('--select-multi-input-flex-wrap', flexWrap);
2472
- this._inputContainer.style.setProperty('--select-multi-input-align-content', alignContent);
2472
+ this._inputContainer.style.setProperty('--select-multi-input-max-height-config', maxHeight);
2473
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-x-config', overflowX);
2474
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-y-config', overflowY);
2475
+ this._inputContainer.style.setProperty('--select-multi-input-flex-wrap-config', flexWrap);
2476
+ this._inputContainer.style.setProperty('--select-multi-input-align-content-config', alignContent);
2473
2477
  }
2474
2478
  _canUseHorizontalMultiScroll(target) {
2475
2479
  if (this._config.selection.mode !== 'multi')
@@ -3097,14 +3101,14 @@ class EnhancedSelect extends HTMLElement {
3097
3101
  }
3098
3102
 
3099
3103
  .input-container.input-container--multi {
3100
- max-height: var(--select-multi-input-max-height, var(--select-input-max-height, 160px));
3104
+ max-height: var(--select-multi-input-max-height, var(--select-multi-input-max-height-config, var(--select-input-max-height, 160px)));
3101
3105
  }
3102
3106
 
3103
3107
  .input-container.input-container--multi .input-content {
3104
- flex-wrap: var(--select-multi-input-flex-wrap, wrap);
3105
- align-content: var(--select-multi-input-align-content, flex-start);
3106
- overflow-x: var(--select-multi-input-overflow-x, hidden);
3107
- overflow-y: var(--select-multi-input-overflow-y, auto);
3108
+ flex-wrap: var(--select-multi-input-flex-wrap, var(--select-multi-input-flex-wrap-config, wrap));
3109
+ align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
3110
+ overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
3111
+ overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
3108
3112
  }
3109
3113
 
3110
3114
  .input-container.input-container--multi::after {
@@ -3121,6 +3125,11 @@ class EnhancedSelect extends HTMLElement {
3121
3125
  cursor: var(--select-multi-input-horizontal-cursor, grab);
3122
3126
  overflow-y: hidden;
3123
3127
  overscroll-behavior-x: contain;
3128
+ padding-right: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3129
+ }
3130
+
3131
+ .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3132
+ padding-right: calc(var(--select-arrow-width, 42px) + var(--select-clear-button-size, 26px) + var(--select-clear-button-right, 8px) + var(--select-multi-horizontal-end-gap, 12px));
3124
3133
  }
3125
3134
 
3126
3135
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"]::after {
@@ -3162,6 +3171,15 @@ class EnhancedSelect extends HTMLElement {
3162
3171
  left: var(--select-arrow-right-with-clear, 34px);
3163
3172
  }
3164
3173
 
3174
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .input-content {
3175
+ padding-right: 0;
3176
+ padding-left: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3177
+ }
3178
+
3179
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3180
+ padding-left: calc(var(--select-arrow-width, 42px) + var(--select-clear-button-size, 26px) + var(--select-clear-button-right, 8px) + var(--select-multi-horizontal-end-gap, 12px));
3181
+ }
3182
+
3165
3183
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .clear-control-button {
3166
3184
  background: var(--select-multi-action-surface-bg, var(--select-input-bg, var(--select-surface)));
3167
3185
  z-index: 4;
@@ -3515,8 +3533,10 @@ class EnhancedSelect extends HTMLElement {
3515
3533
  }
3516
3534
 
3517
3535
  .group-header:not(:first-child) {
3518
- margin-top: var(--select-group-header-separator-margin-top);
3519
- padding-top: var(--select-group-header-separator-padding-top);
3536
+ margin-top: calc(
3537
+ var(--select-group-header-separator-margin-top, 0px) +
3538
+ var(--select-group-header-separator-padding-top, 0px)
3539
+ );
3520
3540
  border-top: var(--select-group-header-separator-border-top);
3521
3541
  }
3522
3542
 
@@ -3598,7 +3618,7 @@ class EnhancedSelect extends HTMLElement {
3598
3618
  color: var(--select-option-selected-hover-color, var(--select-option-selected-color, var(--select-accent)));
3599
3619
  }
3600
3620
 
3601
- .option.active:not(.selected) {
3621
+ .option.active:not(.selected):not(.disabled) {
3602
3622
  background: var(--select-option-active-bg, var(--select-surface-elevated));
3603
3623
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text))));
3604
3624
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -3608,7 +3628,7 @@ class EnhancedSelect extends HTMLElement {
3608
3628
  transform: var(--select-option-active-transform, none);
3609
3629
  }
3610
3630
 
3611
- .option.selected.active {
3631
+ .option.selected.active:not(.disabled) {
3612
3632
  outline: var(--select-option-selected-active-outline, 2px solid rgba(15, 52, 96, 0.4));
3613
3633
  outline-offset: var(--select-option-selected-active-outline-offset);
3614
3634
  }
@@ -3826,6 +3846,9 @@ class EnhancedSelect extends HTMLElement {
3826
3846
 
3827
3847
  --select-badge-bg: var(--select-dark-badge-bg, rgba(99, 102, 241, 0.2));
3828
3848
  --select-badge-color: var(--select-dark-badge-color, #e0e7ff);
3849
+ --select-badge-border: var(--select-dark-badge-border, var(--select-badge-border, none));
3850
+ --select-badge-hover-border: var(--select-dark-badge-hover-border, var(--select-badge-hover-border, var(--select-badge-border, none)));
3851
+ --select-badge-active-border: var(--select-dark-badge-active-border, var(--select-badge-active-border, var(--select-badge-hover-border, var(--select-badge-border, none))));
3829
3852
 
3830
3853
  --select-group-header-bg: var(--select-group-header-dark-bg, #1a1a2e);
3831
3854
  --select-group-header-color: var(--select-group-header-dark-color, #9ca3af);
@@ -3861,6 +3884,36 @@ class EnhancedSelect extends HTMLElement {
3861
3884
  border-color: var(--select-border);
3862
3885
  }
3863
3886
 
3887
+ :host(.dark-mode) .input-container:hover,
3888
+ :host([dark-mode]) .input-container:hover,
3889
+ :host([darkmode]) .input-container:hover,
3890
+ :host([data-theme="dark"]) .input-container:hover,
3891
+ :host([theme="dark"]) .input-container:hover,
3892
+ :host-context(.dark-mode) .input-container:hover,
3893
+ :host-context(.dark) .input-container:hover,
3894
+ :host-context([dark-mode]) .input-container:hover,
3895
+ :host-context([darkmode]) .input-container:hover,
3896
+ :host-context([data-theme="dark"]) .input-container:hover,
3897
+ :host-context([theme="dark"]) .input-container:hover {
3898
+ border-color: var(--select-dark-input-hover-border, var(--select-input-hover-border, var(--select-dark-border-focus, var(--select-border-focus, #6366f1))));
3899
+ box-shadow: var(--select-dark-input-hover-shadow, var(--select-input-hover-shadow, var(--select-shadow-sm), 0 0 0 1px rgba(99, 102, 241, 0.12)));
3900
+ }
3901
+
3902
+ :host(.dark-mode) .input-container:focus-within,
3903
+ :host([dark-mode]) .input-container:focus-within,
3904
+ :host([darkmode]) .input-container:focus-within,
3905
+ :host([data-theme="dark"]) .input-container:focus-within,
3906
+ :host([theme="dark"]) .input-container:focus-within,
3907
+ :host-context(.dark-mode) .input-container:focus-within,
3908
+ :host-context(.dark) .input-container:focus-within,
3909
+ :host-context([dark-mode]) .input-container:focus-within,
3910
+ :host-context([darkmode]) .input-container:focus-within,
3911
+ :host-context([data-theme="dark"]) .input-container:focus-within,
3912
+ :host-context([theme="dark"]) .input-container:focus-within {
3913
+ border-color: var(--select-dark-border-focus, var(--select-border-focus, #6366f1));
3914
+ box-shadow: var(--select-dark-shadow-focus, var(--select-shadow-focus, 0 0 0 3px rgba(99, 102, 241, 0.25))), var(--select-shadow-sm);
3915
+ }
3916
+
3864
3917
  :host(.dark-mode) .input-container::after,
3865
3918
  :host([dark-mode]) .input-container::after,
3866
3919
  :host([darkmode]) .input-container::after,
@@ -3916,7 +3969,8 @@ class EnhancedSelect extends HTMLElement {
3916
3969
  :host-context([darkmode]) .selection-badge,
3917
3970
  :host-context([data-theme="dark"]) .selection-badge,
3918
3971
  :host-context([theme="dark"]) .selection-badge {
3919
- background: var(--select-badge-dark-bg);
3972
+ background: var(--select-dark-badge-bg, var(--select-badge-bg, var(--select-badge-dark-bg)));
3973
+ color: var(--select-dark-badge-color, var(--select-badge-color, #e0e7ff));
3920
3974
  }
3921
3975
 
3922
3976
  :host(.dark-mode) .group-header:not(:first-child),
@@ -4097,6 +4151,10 @@ class EnhancedSelect extends HTMLElement {
4097
4151
  this._inputContent.addEventListener('wheel', (e) => {
4098
4152
  if (this._config.selection.mode === 'multi'
4099
4153
  && (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal') {
4154
+ const primaryDelta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
4155
+ if (primaryDelta !== 0) {
4156
+ this._inputContent.scrollLeft += primaryDelta;
4157
+ }
4100
4158
  e.preventDefault();
4101
4159
  }
4102
4160
  }, { passive: false });
@@ -4491,6 +4549,8 @@ class EnhancedSelect extends HTMLElement {
4491
4549
  }
4492
4550
  }
4493
4551
  _handleKeydown(e) {
4552
+ if (!this._config.enabled)
4553
+ return;
4494
4554
  switch (e.key) {
4495
4555
  case 'ArrowDown':
4496
4556
  e.preventDefault();
@@ -4513,17 +4573,23 @@ class EnhancedSelect extends HTMLElement {
4513
4573
  case 'Home':
4514
4574
  e.preventDefault();
4515
4575
  if (this._state.isOpen) {
4516
- this._setActive(0);
4576
+ const selectableIndices = this._getSelectableOptionIndices();
4577
+ const firstIndex = selectableIndices[0];
4578
+ if (firstIndex === undefined)
4579
+ break;
4580
+ this._setActive(firstIndex);
4517
4581
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4518
- this._selectRange(this._rangeAnchorIndex ?? 0, 0, { clear: !(e.ctrlKey || e.metaKey) });
4582
+ this._selectRange(this._rangeAnchorIndex ?? firstIndex, firstIndex, { clear: !(e.ctrlKey || e.metaKey) });
4519
4583
  }
4520
4584
  }
4521
4585
  break;
4522
4586
  case 'End':
4523
4587
  e.preventDefault();
4524
4588
  if (this._state.isOpen) {
4525
- const options = this._getSelectableOptions();
4526
- const lastIndex = Math.max(0, options.length - 1);
4589
+ const selectableIndices = this._getSelectableOptionIndices();
4590
+ const lastIndex = selectableIndices[selectableIndices.length - 1];
4591
+ if (lastIndex === undefined)
4592
+ break;
4527
4593
  this._setActive(lastIndex);
4528
4594
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4529
4595
  this._selectRange(this._rangeAnchorIndex ?? lastIndex, lastIndex, { clear: !(e.ctrlKey || e.metaKey) });
@@ -4577,8 +4643,17 @@ class EnhancedSelect extends HTMLElement {
4577
4643
  }
4578
4644
  }
4579
4645
  _moveActive(delta, opts) {
4580
- const options = this._getSelectableOptions();
4581
- const next = Math.max(0, Math.min(options.length - 1, this._state.activeIndex + delta));
4646
+ const selectableIndices = this._getSelectableOptionIndices();
4647
+ if (selectableIndices.length === 0)
4648
+ return;
4649
+ const currentPosition = selectableIndices.indexOf(this._state.activeIndex);
4650
+ const basePosition = currentPosition >= 0
4651
+ ? currentPosition
4652
+ : delta >= 0
4653
+ ? -1
4654
+ : selectableIndices.length;
4655
+ const nextPosition = Math.max(0, Math.min(selectableIndices.length - 1, basePosition + delta));
4656
+ const next = selectableIndices[nextPosition];
4582
4657
  this._setActive(next);
4583
4658
  if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
4584
4659
  const anchor = this._rangeAnchorIndex ?? this._state.activeIndex;
@@ -4590,6 +4665,10 @@ class EnhancedSelect extends HTMLElement {
4590
4665
  }
4591
4666
  }
4592
4667
  _setActive(index) {
4668
+ const option = this._getOptionElementByIndex(index);
4669
+ if (!option || option.getAttribute('aria-disabled') === 'true') {
4670
+ return;
4671
+ }
4593
4672
  // Clear previous active state
4594
4673
  if (this._state.activeIndex >= 0) {
4595
4674
  const prevOption = this._getOptionElementByIndex(this._state.activeIndex);
@@ -4606,7 +4685,6 @@ class EnhancedSelect extends HTMLElement {
4606
4685
  }
4607
4686
  this._state.activeIndex = index;
4608
4687
  // Set new active state
4609
- const option = this._getOptionElementByIndex(index);
4610
4688
  if (option) {
4611
4689
  // Check if it's a custom SelectOption or a lightweight DOM element
4612
4690
  if ('setActive' in option && typeof option.setActive === 'function') {
@@ -4635,9 +4713,15 @@ class EnhancedSelect extends HTMLElement {
4635
4713
  // Filter out group headers and other non-selectable elements
4636
4714
  // Only return elements with data-index or data-sm-selectable attributes
4637
4715
  return Array.from(this._optionsContainer.children).filter((child) => {
4638
- return child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable');
4716
+ return (child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable'))
4717
+ && child.getAttribute('aria-disabled') !== 'true';
4639
4718
  });
4640
4719
  }
4720
+ _getSelectableOptionIndices() {
4721
+ return this._getSelectableOptions()
4722
+ .map((option) => Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index')))
4723
+ .filter((index) => Number.isFinite(index));
4724
+ }
4641
4725
  _buildRendererHelpers() {
4642
4726
  return {
4643
4727
  onSelect: (_item, index) => this._selectOption(index),
@@ -4674,24 +4758,27 @@ class EnhancedSelect extends HTMLElement {
4674
4758
  return;
4675
4759
  const options = this._getSelectableOptions();
4676
4760
  const maxSelections = this._config.selection.maxSelections || 0;
4677
- options.forEach((option, index) => {
4761
+ options.forEach((option) => {
4762
+ const optionIndex = Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index'));
4763
+ if (!Number.isFinite(optionIndex))
4764
+ return;
4678
4765
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections) {
4679
4766
  return;
4680
4767
  }
4681
- if (!this._state.selectedIndices.has(index)) {
4768
+ if (!this._state.selectedIndices.has(optionIndex)) {
4682
4769
  // Check if it's a custom SelectOption or a lightweight DOM element
4683
4770
  if ('getConfig' in option && typeof option.getConfig === 'function') {
4684
4771
  const config = option.getConfig();
4685
- this._state.selectedIndices.add(index);
4686
- this._state.selectedItems.set(index, config.item);
4772
+ this._state.selectedIndices.add(optionIndex);
4773
+ this._state.selectedItems.set(optionIndex, config.item);
4687
4774
  option.setSelected(true);
4688
4775
  }
4689
4776
  else {
4690
4777
  // Lightweight option - get item from data attribute or state
4691
- const item = this._state.loadedItems[index];
4778
+ const item = this._state.loadedItems[optionIndex];
4692
4779
  if (item) {
4693
- this._state.selectedIndices.add(index);
4694
- this._state.selectedItems.set(index, item);
4780
+ this._state.selectedIndices.add(optionIndex);
4781
+ this._state.selectedItems.set(optionIndex, item);
4695
4782
  option.classList.add('smilodon-option--selected');
4696
4783
  option.setAttribute('aria-selected', 'true');
4697
4784
  }
@@ -4715,6 +4802,9 @@ class EnhancedSelect extends HTMLElement {
4715
4802
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections)
4716
4803
  break;
4717
4804
  const item = this._state.loadedItems[i];
4805
+ const optionEl = this._getOptionElementByIndex(i);
4806
+ if (optionEl?.getAttribute('aria-disabled') === 'true')
4807
+ continue;
4718
4808
  if (!item)
4719
4809
  continue;
4720
4810
  this._state.selectedIndices.add(i);
@@ -4726,8 +4816,8 @@ class EnhancedSelect extends HTMLElement {
4726
4816
  this._announce(`${this._state.selectedIndices.size} items selected`);
4727
4817
  }
4728
4818
  _setInitialActiveOption() {
4729
- const options = this._getSelectableOptions();
4730
- if (options.length === 0)
4819
+ const selectableIndices = this._getSelectableOptionIndices();
4820
+ if (selectableIndices.length === 0)
4731
4821
  return;
4732
4822
  const selected = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
4733
4823
  if (this._config.selection.mode === 'multi' && selected.length === 0) {
@@ -4735,8 +4825,8 @@ class EnhancedSelect extends HTMLElement {
4735
4825
  this._input.removeAttribute('aria-activedescendant');
4736
4826
  return;
4737
4827
  }
4738
- const target = selected.length > 0 ? selected[0] : 0;
4739
- this._setActive(Math.min(target, options.length - 1));
4828
+ const target = selected.find((index) => selectableIndices.includes(index)) ?? selectableIndices[0];
4829
+ this._setActive(target);
4740
4830
  }
4741
4831
  _announce(message) {
4742
4832
  if (this._liveRegion) {