@smilodon/core 1.3.0 → 1.3.2

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
@@ -1539,9 +1539,6 @@
1539
1539
  // Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
1540
1540
  this._initializeStyles();
1541
1541
  console.log('[EnhancedSelect] Styles initialized');
1542
- // Initialize option renderer
1543
- this._initializeOptionRenderer();
1544
- console.log('[EnhancedSelect] Option renderer initialized');
1545
1542
  this._assembleDOM();
1546
1543
  console.log('[EnhancedSelect] DOM assembled');
1547
1544
  this._attachEventListeners();
@@ -1578,11 +1575,6 @@
1578
1575
  clearTimeout(this._typeTimeout);
1579
1576
  if (this._searchTimeout)
1580
1577
  clearTimeout(this._searchTimeout);
1581
- // Cleanup option renderer
1582
- if (this._optionRenderer) {
1583
- this._optionRenderer.unmountAll();
1584
- console.log('[EnhancedSelect] Option renderer cleaned up');
1585
- }
1586
1578
  // Cleanup arrow click listener
1587
1579
  if (this._boundArrowClick && this._arrowContainer) {
1588
1580
  this._arrowContainer.removeEventListener('click', this._boundArrowClick);
@@ -2122,40 +2114,6 @@
2122
2114
  }, { threshold: 0.1 });
2123
2115
  }
2124
2116
  }
2125
- _initializeOptionRenderer() {
2126
- const getValue = this._config.serverSide.getValueFromItem || ((item) => item?.value ?? item);
2127
- const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
2128
- const getDisabled = (item) => item?.disabled ?? false;
2129
- const rendererConfig = {
2130
- enableRecycling: true,
2131
- maxPoolSize: 100,
2132
- getValue,
2133
- getLabel,
2134
- getDisabled,
2135
- onSelect: (index) => {
2136
- this._selectOption(index);
2137
- },
2138
- onCustomEvent: (index, eventName, data) => {
2139
- console.log(`[EnhancedSelect] Custom event from option ${index}: ${eventName}`, data);
2140
- // Emit as a generic event since these aren't in the standard event map
2141
- this.dispatchEvent(new CustomEvent('option:custom-event', {
2142
- detail: { index, eventName, data },
2143
- bubbles: true,
2144
- composed: true
2145
- }));
2146
- },
2147
- onError: (index, error) => {
2148
- console.error(`[EnhancedSelect] Error in option ${index}:`, error);
2149
- this.dispatchEvent(new CustomEvent('option:mount-error', {
2150
- detail: { index, error },
2151
- bubbles: true,
2152
- composed: true
2153
- }));
2154
- }
2155
- };
2156
- this._optionRenderer = new OptionRenderer(rendererConfig);
2157
- console.log('[EnhancedSelect] Option renderer initialized with config:', rendererConfig);
2158
- }
2159
2117
  async _loadInitialSelectedItems() {
2160
2118
  if (!this._config.serverSide.fetchSelectedItems || !this._config.serverSide.initialSelectedValues) {
2161
2119
  return;
@@ -2371,13 +2329,31 @@
2371
2329
  const options = Array.from(this._optionsContainer.children);
2372
2330
  // Clear previous active state
2373
2331
  if (this._state.activeIndex >= 0 && options[this._state.activeIndex]) {
2374
- options[this._state.activeIndex].setActive(false);
2332
+ const prevOption = options[this._state.activeIndex];
2333
+ // Check if it's a custom SelectOption or a lightweight DOM element
2334
+ if ('setActive' in prevOption && typeof prevOption.setActive === 'function') {
2335
+ prevOption.setActive(false);
2336
+ }
2337
+ else {
2338
+ // Lightweight option - remove active class
2339
+ prevOption.classList.remove('smilodon-option--active');
2340
+ prevOption.setAttribute('aria-selected', 'false');
2341
+ }
2375
2342
  }
2376
2343
  this._state.activeIndex = index;
2377
2344
  // Set new active state
2378
2345
  if (options[index]) {
2379
- options[index].setActive(true);
2380
- options[index].scrollIntoView({ block: 'nearest', behavior: 'smooth' });
2346
+ const option = options[index];
2347
+ // Check if it's a custom SelectOption or a lightweight DOM element
2348
+ if ('setActive' in option && typeof option.setActive === 'function') {
2349
+ option.setActive(true);
2350
+ }
2351
+ else {
2352
+ // Lightweight option - add active class
2353
+ option.classList.add('smilodon-option--active');
2354
+ option.setAttribute('aria-selected', 'true');
2355
+ }
2356
+ option.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
2381
2357
  // Announce position for screen readers
2382
2358
  const total = options.length;
2383
2359
  this._announce(`Item ${index + 1} of ${total}`);
@@ -2410,10 +2386,23 @@
2410
2386
  return;
2411
2387
  }
2412
2388
  if (!this._state.selectedIndices.has(index)) {
2413
- const config = option.getConfig();
2414
- this._state.selectedIndices.add(index);
2415
- this._state.selectedItems.set(index, config.item);
2416
- option.setSelected(true);
2389
+ // Check if it's a custom SelectOption or a lightweight DOM element
2390
+ if ('getConfig' in option && typeof option.getConfig === 'function') {
2391
+ const config = option.getConfig();
2392
+ this._state.selectedIndices.add(index);
2393
+ this._state.selectedItems.set(index, config.item);
2394
+ option.setSelected(true);
2395
+ }
2396
+ else {
2397
+ // Lightweight option - get item from data attribute or state
2398
+ const item = this._state.loadedItems[index];
2399
+ if (item) {
2400
+ this._state.selectedIndices.add(index);
2401
+ this._state.selectedItems.set(index, item);
2402
+ option.classList.add('smilodon-option--selected');
2403
+ option.setAttribute('aria-selected', 'true');
2404
+ }
2405
+ }
2417
2406
  }
2418
2407
  });
2419
2408
  this._updateInputDisplay();
@@ -2876,11 +2865,6 @@
2876
2865
  if (this._loadMoreTrigger && this._intersectionObserver) {
2877
2866
  this._intersectionObserver.unobserve(this._loadMoreTrigger);
2878
2867
  }
2879
- // Cleanup all rendered options (including custom components)
2880
- if (this._optionRenderer) {
2881
- this._optionRenderer.unmountAll();
2882
- console.log('[EnhancedSelect] Unmounted all option components');
2883
- }
2884
2868
  // Clear options container
2885
2869
  console.log('[EnhancedSelect] Clearing options container, previous children:', this._optionsContainer.children.length);
2886
2870
  this._optionsContainer.innerHTML = '';
@@ -2997,23 +2981,28 @@
2997
2981
  console.log('[EnhancedSelect] _renderOptions complete, optionsContainer children:', this._optionsContainer.children.length);
2998
2982
  }
2999
2983
  _renderSingleOption(item, index, getValue, getLabel) {
3000
- if (!this._optionRenderer) {
3001
- console.error('[EnhancedSelect] Option renderer not initialized');
3002
- return;
3003
- }
3004
- // Check if selected
2984
+ const option = document.createElement('div');
2985
+ option.className = 'option';
2986
+ option.id = `${this._uniqueId}-option-${index}`;
2987
+ const value = getValue(item);
2988
+ const label = getLabel(item);
2989
+ console.log('[EnhancedSelect] Rendering option', index, ':', { value, label });
2990
+ option.textContent = label;
2991
+ option.dataset.value = String(value);
2992
+ option.dataset.index = String(index); // Also useful for debugging/selectors
2993
+ // Check if selected using selectedItems map
3005
2994
  const isSelected = this._state.selectedIndices.has(index);
3006
- const isFocused = this._state.activeIndex === index;
3007
- console.log('[EnhancedSelect] Rendering option', index, ':', {
3008
- value: getValue(item),
3009
- label: getLabel(item),
3010
- isSelected,
3011
- isFocused,
3012
- hasCustomComponent: !!item.optionComponent
2995
+ if (isSelected) {
2996
+ option.classList.add('selected');
2997
+ option.setAttribute('aria-selected', 'true');
2998
+ }
2999
+ else {
3000
+ option.setAttribute('aria-selected', 'false');
3001
+ }
3002
+ option.addEventListener('click', () => {
3003
+ this._selectOption(index);
3013
3004
  });
3014
- // Use the OptionRenderer to render both lightweight and custom component options
3015
- const optionElement = this._optionRenderer.render(item, index, isSelected, isFocused, this._uniqueId);
3016
- this._optionsContainer.appendChild(optionElement);
3005
+ this._optionsContainer.appendChild(option);
3017
3006
  console.log('[EnhancedSelect] Option', index, 'appended to optionsContainer');
3018
3007
  }
3019
3008
  _addLoadMoreTrigger() {