@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/README.md +39 -9
- package/dist/index.cjs +58 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -69
- 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 +58 -69
- 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 +0 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1533,9 +1533,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
1533
1533
|
// Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
|
|
1534
1534
|
this._initializeStyles();
|
|
1535
1535
|
console.log('[EnhancedSelect] Styles initialized');
|
|
1536
|
-
// Initialize option renderer
|
|
1537
|
-
this._initializeOptionRenderer();
|
|
1538
|
-
console.log('[EnhancedSelect] Option renderer initialized');
|
|
1539
1536
|
this._assembleDOM();
|
|
1540
1537
|
console.log('[EnhancedSelect] DOM assembled');
|
|
1541
1538
|
this._attachEventListeners();
|
|
@@ -1572,11 +1569,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
1572
1569
|
clearTimeout(this._typeTimeout);
|
|
1573
1570
|
if (this._searchTimeout)
|
|
1574
1571
|
clearTimeout(this._searchTimeout);
|
|
1575
|
-
// Cleanup option renderer
|
|
1576
|
-
if (this._optionRenderer) {
|
|
1577
|
-
this._optionRenderer.unmountAll();
|
|
1578
|
-
console.log('[EnhancedSelect] Option renderer cleaned up');
|
|
1579
|
-
}
|
|
1580
1572
|
// Cleanup arrow click listener
|
|
1581
1573
|
if (this._boundArrowClick && this._arrowContainer) {
|
|
1582
1574
|
this._arrowContainer.removeEventListener('click', this._boundArrowClick);
|
|
@@ -2116,40 +2108,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2116
2108
|
}, { threshold: 0.1 });
|
|
2117
2109
|
}
|
|
2118
2110
|
}
|
|
2119
|
-
_initializeOptionRenderer() {
|
|
2120
|
-
const getValue = this._config.serverSide.getValueFromItem || ((item) => item?.value ?? item);
|
|
2121
|
-
const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
|
|
2122
|
-
const getDisabled = (item) => item?.disabled ?? false;
|
|
2123
|
-
const rendererConfig = {
|
|
2124
|
-
enableRecycling: true,
|
|
2125
|
-
maxPoolSize: 100,
|
|
2126
|
-
getValue,
|
|
2127
|
-
getLabel,
|
|
2128
|
-
getDisabled,
|
|
2129
|
-
onSelect: (index) => {
|
|
2130
|
-
this._selectOption(index);
|
|
2131
|
-
},
|
|
2132
|
-
onCustomEvent: (index, eventName, data) => {
|
|
2133
|
-
console.log(`[EnhancedSelect] Custom event from option ${index}: ${eventName}`, data);
|
|
2134
|
-
// Emit as a generic event since these aren't in the standard event map
|
|
2135
|
-
this.dispatchEvent(new CustomEvent('option:custom-event', {
|
|
2136
|
-
detail: { index, eventName, data },
|
|
2137
|
-
bubbles: true,
|
|
2138
|
-
composed: true
|
|
2139
|
-
}));
|
|
2140
|
-
},
|
|
2141
|
-
onError: (index, error) => {
|
|
2142
|
-
console.error(`[EnhancedSelect] Error in option ${index}:`, error);
|
|
2143
|
-
this.dispatchEvent(new CustomEvent('option:mount-error', {
|
|
2144
|
-
detail: { index, error },
|
|
2145
|
-
bubbles: true,
|
|
2146
|
-
composed: true
|
|
2147
|
-
}));
|
|
2148
|
-
}
|
|
2149
|
-
};
|
|
2150
|
-
this._optionRenderer = new OptionRenderer(rendererConfig);
|
|
2151
|
-
console.log('[EnhancedSelect] Option renderer initialized with config:', rendererConfig);
|
|
2152
|
-
}
|
|
2153
2111
|
async _loadInitialSelectedItems() {
|
|
2154
2112
|
if (!this._config.serverSide.fetchSelectedItems || !this._config.serverSide.initialSelectedValues) {
|
|
2155
2113
|
return;
|
|
@@ -2365,13 +2323,31 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2365
2323
|
const options = Array.from(this._optionsContainer.children);
|
|
2366
2324
|
// Clear previous active state
|
|
2367
2325
|
if (this._state.activeIndex >= 0 && options[this._state.activeIndex]) {
|
|
2368
|
-
options[this._state.activeIndex]
|
|
2326
|
+
const prevOption = options[this._state.activeIndex];
|
|
2327
|
+
// Check if it's a custom SelectOption or a lightweight DOM element
|
|
2328
|
+
if ('setActive' in prevOption && typeof prevOption.setActive === 'function') {
|
|
2329
|
+
prevOption.setActive(false);
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
// Lightweight option - remove active class
|
|
2333
|
+
prevOption.classList.remove('smilodon-option--active');
|
|
2334
|
+
prevOption.setAttribute('aria-selected', 'false');
|
|
2335
|
+
}
|
|
2369
2336
|
}
|
|
2370
2337
|
this._state.activeIndex = index;
|
|
2371
2338
|
// Set new active state
|
|
2372
2339
|
if (options[index]) {
|
|
2373
|
-
options[index]
|
|
2374
|
-
|
|
2340
|
+
const option = options[index];
|
|
2341
|
+
// Check if it's a custom SelectOption or a lightweight DOM element
|
|
2342
|
+
if ('setActive' in option && typeof option.setActive === 'function') {
|
|
2343
|
+
option.setActive(true);
|
|
2344
|
+
}
|
|
2345
|
+
else {
|
|
2346
|
+
// Lightweight option - add active class
|
|
2347
|
+
option.classList.add('smilodon-option--active');
|
|
2348
|
+
option.setAttribute('aria-selected', 'true');
|
|
2349
|
+
}
|
|
2350
|
+
option.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
2375
2351
|
// Announce position for screen readers
|
|
2376
2352
|
const total = options.length;
|
|
2377
2353
|
this._announce(`Item ${index + 1} of ${total}`);
|
|
@@ -2404,10 +2380,23 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2404
2380
|
return;
|
|
2405
2381
|
}
|
|
2406
2382
|
if (!this._state.selectedIndices.has(index)) {
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2383
|
+
// Check if it's a custom SelectOption or a lightweight DOM element
|
|
2384
|
+
if ('getConfig' in option && typeof option.getConfig === 'function') {
|
|
2385
|
+
const config = option.getConfig();
|
|
2386
|
+
this._state.selectedIndices.add(index);
|
|
2387
|
+
this._state.selectedItems.set(index, config.item);
|
|
2388
|
+
option.setSelected(true);
|
|
2389
|
+
}
|
|
2390
|
+
else {
|
|
2391
|
+
// Lightweight option - get item from data attribute or state
|
|
2392
|
+
const item = this._state.loadedItems[index];
|
|
2393
|
+
if (item) {
|
|
2394
|
+
this._state.selectedIndices.add(index);
|
|
2395
|
+
this._state.selectedItems.set(index, item);
|
|
2396
|
+
option.classList.add('smilodon-option--selected');
|
|
2397
|
+
option.setAttribute('aria-selected', 'true');
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2411
2400
|
}
|
|
2412
2401
|
});
|
|
2413
2402
|
this._updateInputDisplay();
|
|
@@ -2870,11 +2859,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2870
2859
|
if (this._loadMoreTrigger && this._intersectionObserver) {
|
|
2871
2860
|
this._intersectionObserver.unobserve(this._loadMoreTrigger);
|
|
2872
2861
|
}
|
|
2873
|
-
// Cleanup all rendered options (including custom components)
|
|
2874
|
-
if (this._optionRenderer) {
|
|
2875
|
-
this._optionRenderer.unmountAll();
|
|
2876
|
-
console.log('[EnhancedSelect] Unmounted all option components');
|
|
2877
|
-
}
|
|
2878
2862
|
// Clear options container
|
|
2879
2863
|
console.log('[EnhancedSelect] Clearing options container, previous children:', this._optionsContainer.children.length);
|
|
2880
2864
|
this._optionsContainer.innerHTML = '';
|
|
@@ -2991,23 +2975,28 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2991
2975
|
console.log('[EnhancedSelect] _renderOptions complete, optionsContainer children:', this._optionsContainer.children.length);
|
|
2992
2976
|
}
|
|
2993
2977
|
_renderSingleOption(item, index, getValue, getLabel) {
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2978
|
+
const option = document.createElement('div');
|
|
2979
|
+
option.className = 'option';
|
|
2980
|
+
option.id = `${this._uniqueId}-option-${index}`;
|
|
2981
|
+
const value = getValue(item);
|
|
2982
|
+
const label = getLabel(item);
|
|
2983
|
+
console.log('[EnhancedSelect] Rendering option', index, ':', { value, label });
|
|
2984
|
+
option.textContent = label;
|
|
2985
|
+
option.dataset.value = String(value);
|
|
2986
|
+
option.dataset.index = String(index); // Also useful for debugging/selectors
|
|
2987
|
+
// Check if selected using selectedItems map
|
|
2999
2988
|
const isSelected = this._state.selectedIndices.has(index);
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
2989
|
+
if (isSelected) {
|
|
2990
|
+
option.classList.add('selected');
|
|
2991
|
+
option.setAttribute('aria-selected', 'true');
|
|
2992
|
+
}
|
|
2993
|
+
else {
|
|
2994
|
+
option.setAttribute('aria-selected', 'false');
|
|
2995
|
+
}
|
|
2996
|
+
option.addEventListener('click', () => {
|
|
2997
|
+
this._selectOption(index);
|
|
3007
2998
|
});
|
|
3008
|
-
|
|
3009
|
-
const optionElement = this._optionRenderer.render(item, index, isSelected, isFocused, this._uniqueId);
|
|
3010
|
-
this._optionsContainer.appendChild(optionElement);
|
|
2999
|
+
this._optionsContainer.appendChild(option);
|
|
3011
3000
|
console.log('[EnhancedSelect] Option', index, 'appended to optionsContainer');
|
|
3012
3001
|
}
|
|
3013
3002
|
_addLoadMoreTrigger() {
|