@smilodon/core 1.21.0 → 1.22.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.js CHANGED
@@ -2938,6 +2938,15 @@ class SelectOption extends HTMLElement {
2938
2938
  pointer-events: none;
2939
2939
  }
2940
2940
 
2941
+ .remove-button-icon > [data-smilodon-fallback-icon],
2942
+ .remove-button-icon > [data-smilodon-react-icon-root] {
2943
+ display: contents;
2944
+ }
2945
+
2946
+ .remove-button-icon[data-smilodon-icon-owner="react"] > [data-smilodon-fallback-icon] {
2947
+ display: none;
2948
+ }
2949
+
2941
2950
  .remove-button-icon svg {
2942
2951
  width: 100%;
2943
2952
  height: 100%;
@@ -3060,15 +3069,20 @@ class SelectOption extends HTMLElement {
3060
3069
  const removeIcon = document.createElement('span');
3061
3070
  removeIcon.className = 'remove-button-icon';
3062
3071
  removeIcon.setAttribute('part', 'chip-remove-icon');
3072
+ const fallbackIcon = document.createElement('span');
3073
+ fallbackIcon.setAttribute('data-smilodon-fallback-icon', '');
3074
+ const portalRoot = document.createElement('span');
3075
+ portalRoot.setAttribute('data-smilodon-react-icon-root', '');
3063
3076
  const iconMarkup = this._config.removeButtonIcon && this._config.removeButtonIcon.trim()
3064
3077
  ? this._config.removeButtonIcon
3065
3078
  : '×';
3066
3079
  if (iconMarkup.trim().startsWith('<')) {
3067
- removeIcon.innerHTML = iconMarkup;
3080
+ fallbackIcon.innerHTML = iconMarkup;
3068
3081
  }
3069
3082
  else {
3070
- removeIcon.textContent = iconMarkup;
3083
+ fallbackIcon.textContent = iconMarkup;
3071
3084
  }
3085
+ removeIcon.append(fallbackIcon, portalRoot);
3072
3086
  this._removeButton.appendChild(removeIcon);
3073
3087
  this._container.appendChild(this._removeButton);
3074
3088
  }
@@ -4682,6 +4696,7 @@ class EnhancedSelect extends HTMLElement {
4682
4696
  this._inputContent = this._createInputContent();
4683
4697
  this._input = this._createInput();
4684
4698
  this._selectedLabelTooltip = this._createSelectedLabelTooltip();
4699
+ this._selectedLabelTooltipTextMeasure = this._createSelectedLabelTooltipTextMeasure();
4685
4700
  this._arrowContainer = this._createArrowContainer();
4686
4701
  this._clearControl = this._createClearControl();
4687
4702
  this._dropdown = this._createDropdown();
@@ -4701,6 +4716,9 @@ class EnhancedSelect extends HTMLElement {
4701
4716
  }
4702
4717
  connectedCallback() {
4703
4718
  this._hasEverConnected = true;
4719
+ // Adapter capability marker without adding a field to the public class
4720
+ // declaration. React-node remove icons require the isolated root contract.
4721
+ this.setAttribute('data-smilodon-react-icon-portals', 'isolated-v1');
4704
4722
  // register instance
4705
4723
  EnhancedSelect._instances.add(this);
4706
4724
  this._runEngineEffects(this._engine.dispatch({ type: 'CONNECT' }));
@@ -4708,6 +4726,7 @@ class EnhancedSelect extends HTMLElement {
4708
4726
  this._connectionController?.abort();
4709
4727
  this._connectionController = new AbortController();
4710
4728
  this._observeSelectedLabelTooltipTargets();
4729
+ this._inputContent.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, { passive: true });
4711
4730
  document.addEventListener('pointerdown', this._onDocumentPointerDown, {
4712
4731
  signal: this._connectionController.signal,
4713
4732
  });
@@ -4791,6 +4810,7 @@ class EnhancedSelect extends HTMLElement {
4791
4810
  this._handleClose('disconnect');
4792
4811
  }
4793
4812
  this._runEngineEffects(this._engine.dispatch({ type: 'DISCONNECT' }));
4813
+ this._inputContent.removeEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure);
4794
4814
  this._connectionController?.abort();
4795
4815
  this._connectionController = undefined;
4796
4816
  this._hideSelectedLabelTooltip(true);
@@ -5731,12 +5751,25 @@ class EnhancedSelect extends HTMLElement {
5731
5751
  }
5732
5752
  _setIconContent(target, markup, fallback) {
5733
5753
  const content = markup && markup.trim() ? markup : fallback;
5734
- target.innerHTML = '';
5754
+ let fallbackTarget = target.querySelector(':scope > [data-smilodon-fallback-icon]');
5755
+ if (!fallbackTarget) {
5756
+ fallbackTarget = document.createElement('span');
5757
+ fallbackTarget.setAttribute('data-smilodon-fallback-icon', '');
5758
+ target.prepend(fallbackTarget);
5759
+ }
5760
+ if (!target.querySelector(':scope > [data-smilodon-react-icon-root]')) {
5761
+ const portalRoot = document.createElement('span');
5762
+ portalRoot.setAttribute('data-smilodon-react-icon-root', '');
5763
+ target.append(portalRoot);
5764
+ }
5765
+ // Only Core's fallback subtree is replaceable. React may reconcile a
5766
+ // separate portal root beneath this stable icon target.
5767
+ fallbackTarget.replaceChildren();
5735
5768
  if (content.trim().startsWith('<')) {
5736
- target.innerHTML = content;
5769
+ fallbackTarget.innerHTML = content;
5737
5770
  return;
5738
5771
  }
5739
- target.textContent = content;
5772
+ fallbackTarget.textContent = content;
5740
5773
  }
5741
5774
  _syncInputContainerMode() {
5742
5775
  if (!this._inputContainer || !this._input)
@@ -5959,6 +5992,27 @@ class EnhancedSelect extends HTMLElement {
5959
5992
  tooltip.hidden = true;
5960
5993
  return tooltip;
5961
5994
  }
5995
+ _createSelectedLabelTooltipTextMeasure() {
5996
+ const measure = document.createElement('span');
5997
+ measure.setAttribute('aria-hidden', 'true');
5998
+ measure.dataset.selectInternal = 'tooltip-measure';
5999
+ measure.style.cssText = [
6000
+ 'all: initial',
6001
+ 'position: fixed',
6002
+ 'left: -100000px',
6003
+ 'top: 0',
6004
+ 'display: inline-block',
6005
+ 'width: max-content',
6006
+ 'height: auto',
6007
+ 'padding: 0',
6008
+ 'margin: 0',
6009
+ 'border: 0',
6010
+ 'white-space: pre',
6011
+ 'visibility: hidden',
6012
+ 'pointer-events: none',
6013
+ ].join(';');
6014
+ return measure;
6015
+ }
5962
6016
  _createDropdown() {
5963
6017
  const dropdown = document.createElement('div');
5964
6018
  dropdown.className = 'select-dropdown';
@@ -6054,6 +6108,7 @@ class EnhancedSelect extends HTMLElement {
6054
6108
  this._shadow.appendChild(this._errorDescription);
6055
6109
  }
6056
6110
  this._shadow.appendChild(this._selectedLabelTooltip);
6111
+ this._shadow.appendChild(this._selectedLabelTooltipTextMeasure);
6057
6112
  // Set ARIA relationships
6058
6113
  const listboxId = `${this._uniqueId}-listbox`;
6059
6114
  this._dropdown.id = listboxId;
@@ -6405,6 +6460,15 @@ class EnhancedSelect extends HTMLElement {
6405
6460
  pointer-events: none;
6406
6461
  }
6407
6462
 
6463
+ .badge-remove-icon > [data-smilodon-fallback-icon],
6464
+ .badge-remove-icon > [data-smilodon-react-icon-root] {
6465
+ display: contents;
6466
+ }
6467
+
6468
+ .badge-remove-icon[data-smilodon-icon-owner="react"] > [data-smilodon-fallback-icon] {
6469
+ display: none;
6470
+ }
6471
+
6408
6472
  .badge-remove-icon svg {
6409
6473
  width: 100%;
6410
6474
  height: 100%;
@@ -7580,7 +7644,6 @@ class EnhancedSelect extends HTMLElement {
7580
7644
  keyboardEvent.stopPropagation();
7581
7645
  this._dismissSelectedLabelTooltip();
7582
7646
  });
7583
- this._inputContent.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, { passive: true });
7584
7647
  // Arrow click handler
7585
7648
  if (this._arrowContainer) {
7586
7649
  this._boundArrowClick = (e) => {
@@ -7749,9 +7812,8 @@ class EnhancedSelect extends HTMLElement {
7749
7812
  if (!this._config.searchable)
7750
7813
  return;
7751
7814
  const query = e.target.value;
7752
- if (this._selectedLabelTooltipTrigger === this._input
7753
- && this._getSelectedLabelForTrigger(this._input) === null) {
7754
- this._hideSelectedLabelTooltip();
7815
+ if (this._selectedLabelTooltipDismissedTrigger === this._input) {
7816
+ this._selectedLabelTooltipDismissedTrigger = null;
7755
7817
  }
7756
7818
  this._handleSearch(query);
7757
7819
  });
@@ -7928,7 +7990,7 @@ class EnhancedSelect extends HTMLElement {
7928
7990
  _getSelectedLabelForTrigger(trigger) {
7929
7991
  const entries = this._getSelectedEntries();
7930
7992
  if (trigger === this._input) {
7931
- if (this._config.selection.mode !== 'single' || this._state.searchQuery.length > 0)
7993
+ if (this._config.selection.mode !== 'single')
7932
7994
  return null;
7933
7995
  const item = entries[0]?.item;
7934
7996
  if (item === undefined)
@@ -7952,6 +8014,57 @@ class EnhancedSelect extends HTMLElement {
7952
8014
  return false;
7953
8015
  return trigger.clientWidth > 0 && trigger.scrollWidth > trigger.clientWidth + 1;
7954
8016
  }
8017
+ _getSelectedLabelTooltipContent(trigger) {
8018
+ if (trigger === this._input && this._config.searchable) {
8019
+ const visibleText = this._input.value;
8020
+ const pendingQuery = this._acknowledgedPendingSearchQuery;
8021
+ const committedQuery = this._state.searchQuery;
8022
+ const isPendingQuery = pendingQuery !== null && pendingQuery.length > 0 && visibleText === pendingQuery;
8023
+ const isCommittedQuery = committedQuery.length > 0 && visibleText === committedQuery;
8024
+ if (visibleText.length > 0 && (isPendingQuery || isCommittedQuery)) {
8025
+ return { kind: 'search-query', text: visibleText };
8026
+ }
8027
+ }
8028
+ const selectedLabel = this._getSelectedLabelForTrigger(trigger);
8029
+ return selectedLabel === null ? null : { kind: 'selected-label', text: selectedLabel };
8030
+ }
8031
+ _isSelectedLabelTooltipContentTruncated(trigger, content) {
8032
+ if (trigger !== this._input)
8033
+ return this._isSelectedLabelTruncated(trigger);
8034
+ if (!trigger.isConnected || !content.text)
8035
+ return false;
8036
+ const style = getComputedStyle(this._input);
8037
+ const measure = this._selectedLabelTooltipTextMeasure;
8038
+ measure.textContent = content.text;
8039
+ const mirroredProperties = [
8040
+ 'font',
8041
+ 'font-family',
8042
+ 'font-size',
8043
+ 'font-style',
8044
+ 'font-weight',
8045
+ 'font-stretch',
8046
+ 'font-variant',
8047
+ 'font-kerning',
8048
+ 'font-feature-settings',
8049
+ 'font-variation-settings',
8050
+ 'letter-spacing',
8051
+ 'word-spacing',
8052
+ 'text-transform',
8053
+ 'direction',
8054
+ 'unicode-bidi',
8055
+ ];
8056
+ for (const property of mirroredProperties) {
8057
+ const value = style.getPropertyValue(property);
8058
+ if (value)
8059
+ measure.style.setProperty(property, value);
8060
+ }
8061
+ const contentWidth = measure.getBoundingClientRect().width;
8062
+ const inputStyle = style;
8063
+ const horizontalPadding = Number.parseFloat(inputStyle.paddingLeft) + Number.parseFloat(inputStyle.paddingRight);
8064
+ const textIndent = Number.parseFloat(inputStyle.textIndent) || 0;
8065
+ const availableWidth = this._input.clientWidth - (Number.isFinite(horizontalPadding) ? horizontalPadding : 0) - textIndent;
8066
+ return availableWidth > 0 && contentWidth > availableWidth + 1;
8067
+ }
7955
8068
  _handleSelectedLabelPointerOver(event) {
7956
8069
  const target = event.target;
7957
8070
  if (target?.closest('.selected-label-tooltip') === this._selectedLabelTooltip) {
@@ -8017,8 +8130,8 @@ class EnhancedSelect extends HTMLElement {
8017
8130
  this._hideSelectedLabelTooltip();
8018
8131
  return;
8019
8132
  }
8020
- const label = this._getSelectedLabelForTrigger(trigger);
8021
- if (label === null || !this._isSelectedLabelTruncated(trigger)) {
8133
+ const content = this._getSelectedLabelTooltipContent(trigger);
8134
+ if (content === null || !this._isSelectedLabelTooltipContentTruncated(trigger, content)) {
8022
8135
  if (trigger.classList.contains('selection-badge-label'))
8023
8136
  trigger.tabIndex = -1;
8024
8137
  if (this._selectedLabelTooltipTrigger === trigger)
@@ -8031,7 +8144,7 @@ class EnhancedSelect extends HTMLElement {
8031
8144
  this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8032
8145
  this._selectedLabelTooltipTrigger = trigger;
8033
8146
  }
8034
- this._selectedLabelTooltip.textContent = label;
8147
+ this._selectedLabelTooltip.textContent = content.text;
8035
8148
  this._selectedLabelTooltip.hidden = false;
8036
8149
  this._positionSelectedLabelTooltip(trigger);
8037
8150
  this._syncSelectedLabelTooltipDescription();
@@ -8085,6 +8198,7 @@ class EnhancedSelect extends HTMLElement {
8085
8198
  this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8086
8199
  this._selectedLabelTooltipTrigger = null;
8087
8200
  this._selectedLabelTooltip.hidden = true;
8201
+ this._selectedLabelTooltipTextMeasure.textContent = '';
8088
8202
  if (clearInteractionState) {
8089
8203
  this._selectedLabelTooltipPointerTrigger = null;
8090
8204
  this._selectedLabelTooltipFocusTrigger = null;
@@ -8142,10 +8256,12 @@ class EnhancedSelect extends HTMLElement {
8142
8256
  return;
8143
8257
  const hasSingleSelection = this._config.selection.mode === 'single'
8144
8258
  && this._getSelectedEntries().length > 0;
8259
+ const inputContent = this._getSelectedLabelTooltipContent(this._input);
8260
+ const shouldObserveInput = hasSingleSelection || inputContent?.kind === 'search-query';
8145
8261
  const chipLabels = this._getActiveChipBadges()
8146
8262
  .map((badge) => badge.querySelector('.selection-badge-label'))
8147
8263
  .filter((label) => label !== null);
8148
- if (!hasSingleSelection && chipLabels.length === 0) {
8264
+ if (!shouldObserveInput && chipLabels.length === 0) {
8149
8265
  this._selectedLabelTooltipResizeObserver?.disconnect();
8150
8266
  this._selectedLabelTooltipResizeObserver = null;
8151
8267
  return;
@@ -8154,7 +8270,7 @@ class EnhancedSelect extends HTMLElement {
8154
8270
  this._selectedLabelTooltipResizeObserver = new ResizeObserver(() => this._scheduleSelectedLabelTooltipMeasure());
8155
8271
  }
8156
8272
  this._selectedLabelTooltipResizeObserver.disconnect();
8157
- if (hasSingleSelection)
8273
+ if (shouldObserveInput)
8158
8274
  this._selectedLabelTooltipResizeObserver.observe(this._input);
8159
8275
  chipLabels.forEach((label) => {
8160
8276
  this._selectedLabelTooltipResizeObserver?.observe(label);
@@ -8188,8 +8304,8 @@ class EnhancedSelect extends HTMLElement {
8188
8304
  this._hideSelectedLabelTooltip();
8189
8305
  return;
8190
8306
  }
8191
- const label = this._getSelectedLabelForTrigger(trigger);
8192
- if (label === null || !this._isSelectedLabelTruncated(trigger)) {
8307
+ const content = this._getSelectedLabelTooltipContent(trigger);
8308
+ if (content === null || !this._isSelectedLabelTooltipContentTruncated(trigger, content)) {
8193
8309
  if (this._selectedLabelTooltipTrigger === trigger)
8194
8310
  this._hideSelectedLabelTooltip();
8195
8311
  return;
@@ -8791,10 +8907,8 @@ class EnhancedSelect extends HTMLElement {
8791
8907
  return results;
8792
8908
  }
8793
8909
  _handleSearch(query) {
8794
- if (this._selectedLabelTooltipTrigger === this._input
8795
- && (query.length > 0 || this._getSelectedLabelForTrigger(this._input) === null)) {
8796
- this._hideSelectedLabelTooltip();
8797
- }
8910
+ const previousQuery = this._acknowledgedPendingSearchQuery ?? this._state.searchQuery;
8911
+ const queryPresenceChanged = Boolean(previousQuery) !== Boolean(query);
8798
8912
  if (this._dataRequestCoordinator
8799
8913
  && (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)) {
8800
8914
  // Keep the committed query/generation stable until the accepted snapshot
@@ -8803,6 +8917,9 @@ class EnhancedSelect extends HTMLElement {
8803
8917
  this._acknowledgedPendingSearchQuery = query;
8804
8918
  this._input.value = query;
8805
8919
  this._syncClearControlState();
8920
+ if (queryPresenceChanged)
8921
+ this._observeSelectedLabelTooltipTargets();
8922
+ this._refreshSelectedLabelTooltipMeasurements();
8806
8923
  return;
8807
8924
  }
8808
8925
  if (this._dataLoadingConfig.protocol === 'acknowledged'
@@ -8814,6 +8931,9 @@ class EnhancedSelect extends HTMLElement {
8814
8931
  this._cancelBusyPresentation();
8815
8932
  this._state.searchQuery = query;
8816
8933
  this._syncClearControlState();
8934
+ if (queryPresenceChanged)
8935
+ this._observeSelectedLabelTooltipTargets();
8936
+ this._refreshSelectedLabelTooltipMeasurements();
8817
8937
  this._state.lastNotifiedQuery = query;
8818
8938
  this._state.lastNotifiedResultCount = 0;
8819
8939
  if (this._dataRequestCoordinator) {
@@ -8852,6 +8972,9 @@ class EnhancedSelect extends HTMLElement {
8852
8972
  }
8853
8973
  this._state.searchQuery = query;
8854
8974
  this._syncClearControlState();
8975
+ if (queryPresenceChanged)
8976
+ this._observeSelectedLabelTooltipTargets();
8977
+ this._refreshSelectedLabelTooltipMeasurements();
8855
8978
  if (this._dataLoadingConfig.protocol === 'acknowledged' && this._dataRequestCoordinator) {
8856
8979
  // Local acknowledged search has no remote request, but pagination still
8857
8980
  // belongs to the coordinator's current query generation.
@@ -10474,6 +10597,8 @@ class EnhancedSelect extends HTMLElement {
10474
10597
  }
10475
10598
  this._renderOptions();
10476
10599
  this._syncClearControlState();
10600
+ this._observeSelectedLabelTooltipTargets();
10601
+ this._refreshSelectedLabelTooltipMeasurements();
10477
10602
  }
10478
10603
  /**
10479
10604
  * Open dropdown
@@ -10682,6 +10807,8 @@ class EnhancedSelect extends HTMLElement {
10682
10807
  }
10683
10808
  }
10684
10809
  }
10810
+ this._observeSelectedLabelTooltipTargets();
10811
+ this._refreshSelectedLabelTooltipMeasurements();
10685
10812
  if (configErrorDetail) {
10686
10813
  this._emit('dataLoadingConfigError', configErrorDetail);
10687
10814
  try {