@smilodon/core 1.0.16 → 1.1.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.cjs +875 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +875 -1
- 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 +875 -0
- 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/angular-enhanced-select.d.ts +88 -0
- package/dist/types/src/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2474,6 +2474,880 @@ if (!customElements.get('enhanced-select')) {
|
|
|
2474
2474
|
customElements.define('enhanced-select', EnhancedSelect);
|
|
2475
2475
|
}
|
|
2476
2476
|
|
|
2477
|
+
/**
|
|
2478
|
+
* Angular-Optimized Enhanced Select Component
|
|
2479
|
+
*
|
|
2480
|
+
* This is a specialized variant that uses light DOM instead of shadow DOM
|
|
2481
|
+
* to ensure perfect compatibility with Angular's rendering pipeline and
|
|
2482
|
+
* view encapsulation system.
|
|
2483
|
+
*
|
|
2484
|
+
* Key differences from standard EnhancedSelect:
|
|
2485
|
+
* - Uses light DOM with scoped CSS classes
|
|
2486
|
+
* - Integrates seamlessly with Angular's change detection
|
|
2487
|
+
* - Maintains all core features (virtualization, accessibility, performance)
|
|
2488
|
+
* - Uses unique class prefixes to avoid style conflicts
|
|
2489
|
+
*
|
|
2490
|
+
* @performance Optimized for Angular's zone.js and rendering cycle
|
|
2491
|
+
* @accessibility Full WCAG 2.1 AAA compliance maintained
|
|
2492
|
+
*/
|
|
2493
|
+
/**
|
|
2494
|
+
* Angular-Enhanced Select Web Component
|
|
2495
|
+
* Uses light DOM for Angular compatibility
|
|
2496
|
+
*/
|
|
2497
|
+
class AngularEnhancedSelect extends HTMLElement {
|
|
2498
|
+
constructor() {
|
|
2499
|
+
super();
|
|
2500
|
+
this._pageCache = {};
|
|
2501
|
+
this._typeBuffer = '';
|
|
2502
|
+
this._hasError = false;
|
|
2503
|
+
this._errorMessage = '';
|
|
2504
|
+
this._boundArrowClick = null;
|
|
2505
|
+
// Unique class prefix to avoid conflicts
|
|
2506
|
+
this.PREFIX = 'smilodon-ang-';
|
|
2507
|
+
this._uniqueId = `angular-select-${Math.random().toString(36).substr(2, 9)}`;
|
|
2508
|
+
// Merge global config
|
|
2509
|
+
this._config = selectConfig.getConfig();
|
|
2510
|
+
// Initialize state
|
|
2511
|
+
this._state = {
|
|
2512
|
+
isOpen: false,
|
|
2513
|
+
isBusy: false,
|
|
2514
|
+
isSearching: false,
|
|
2515
|
+
currentPage: this._config.infiniteScroll.initialPage || 1,
|
|
2516
|
+
totalPages: 1,
|
|
2517
|
+
selectedIndices: new Set(),
|
|
2518
|
+
selectedItems: new Map(),
|
|
2519
|
+
activeIndex: -1,
|
|
2520
|
+
searchQuery: '',
|
|
2521
|
+
loadedItems: [],
|
|
2522
|
+
groupedItems: [],
|
|
2523
|
+
preserveScrollPosition: false,
|
|
2524
|
+
lastScrollPosition: 0,
|
|
2525
|
+
lastNotifiedQuery: null,
|
|
2526
|
+
lastNotifiedResultCount: 0,
|
|
2527
|
+
isExpanded: false,
|
|
2528
|
+
};
|
|
2529
|
+
// Create DOM structure in light DOM
|
|
2530
|
+
this._initializeStyles();
|
|
2531
|
+
this._container = this._createContainer();
|
|
2532
|
+
this._inputContainer = this._createInputContainer();
|
|
2533
|
+
this._input = this._createInput();
|
|
2534
|
+
this._arrowContainer = this._createArrowContainer();
|
|
2535
|
+
this._dropdown = this._createDropdown();
|
|
2536
|
+
this._optionsContainer = this._createOptionsContainer();
|
|
2537
|
+
this._liveRegion = this._createLiveRegion();
|
|
2538
|
+
this._assembleDOM();
|
|
2539
|
+
this._attachEventListeners();
|
|
2540
|
+
this._initializeObservers();
|
|
2541
|
+
}
|
|
2542
|
+
connectedCallback() {
|
|
2543
|
+
// Ensure host has proper layout
|
|
2544
|
+
if (!this.style.display) {
|
|
2545
|
+
this.style.display = 'block';
|
|
2546
|
+
}
|
|
2547
|
+
if (!this.style.position) {
|
|
2548
|
+
this.style.position = 'relative';
|
|
2549
|
+
}
|
|
2550
|
+
// Load initial data if server-side is enabled
|
|
2551
|
+
if (this._config.serverSide.enabled && this._config.serverSide.initialSelectedValues) {
|
|
2552
|
+
this._loadInitialSelectedItems();
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
disconnectedCallback() {
|
|
2556
|
+
// Cleanup observers
|
|
2557
|
+
this._resizeObserver?.disconnect();
|
|
2558
|
+
this._intersectionObserver?.disconnect();
|
|
2559
|
+
if (this._busyTimeout)
|
|
2560
|
+
clearTimeout(this._busyTimeout);
|
|
2561
|
+
if (this._typeTimeout)
|
|
2562
|
+
clearTimeout(this._typeTimeout);
|
|
2563
|
+
if (this._searchTimeout)
|
|
2564
|
+
clearTimeout(this._searchTimeout);
|
|
2565
|
+
// Cleanup arrow click listener
|
|
2566
|
+
if (this._boundArrowClick && this._arrowContainer) {
|
|
2567
|
+
this._arrowContainer.removeEventListener('click', this._boundArrowClick);
|
|
2568
|
+
}
|
|
2569
|
+
// Remove style element
|
|
2570
|
+
if (this._styleElement && this._styleElement.parentNode) {
|
|
2571
|
+
this._styleElement.parentNode.removeChild(this._styleElement);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
_initializeStyles() {
|
|
2575
|
+
// Create scoped styles for this component instance
|
|
2576
|
+
this._styleElement = document.createElement('style');
|
|
2577
|
+
this._styleElement.setAttribute('data-component', 'angular-enhanced-select');
|
|
2578
|
+
this._styleElement.setAttribute('data-id', this._uniqueId);
|
|
2579
|
+
const p = this.PREFIX; // shorthand
|
|
2580
|
+
this._styleElement.textContent = `
|
|
2581
|
+
/* Host styles - applied to <angular-enhanced-select> */
|
|
2582
|
+
angular-enhanced-select {
|
|
2583
|
+
display: block;
|
|
2584
|
+
position: relative;
|
|
2585
|
+
width: 100%;
|
|
2586
|
+
min-height: 44px;
|
|
2587
|
+
box-sizing: border-box;
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
/* Container */
|
|
2591
|
+
.${p}container {
|
|
2592
|
+
position: relative;
|
|
2593
|
+
width: 100%;
|
|
2594
|
+
min-height: 44px;
|
|
2595
|
+
box-sizing: border-box;
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
/* Input Container */
|
|
2599
|
+
.${p}input-container {
|
|
2600
|
+
position: relative;
|
|
2601
|
+
width: 100%;
|
|
2602
|
+
display: flex;
|
|
2603
|
+
align-items: center;
|
|
2604
|
+
flex-wrap: wrap;
|
|
2605
|
+
gap: 6px;
|
|
2606
|
+
padding: 6px 52px 6px 8px;
|
|
2607
|
+
min-height: 44px;
|
|
2608
|
+
background: white;
|
|
2609
|
+
border: 1px solid #d1d5db;
|
|
2610
|
+
border-radius: 6px;
|
|
2611
|
+
box-sizing: border-box;
|
|
2612
|
+
transition: all 0.2s ease;
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
.${p}input-container:focus-within {
|
|
2616
|
+
border-color: #667eea;
|
|
2617
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
/* Gradient separator before arrow */
|
|
2621
|
+
.${p}input-container::after {
|
|
2622
|
+
content: '';
|
|
2623
|
+
position: absolute;
|
|
2624
|
+
top: 50%;
|
|
2625
|
+
right: 40px;
|
|
2626
|
+
transform: translateY(-50%);
|
|
2627
|
+
width: 1px;
|
|
2628
|
+
height: 60%;
|
|
2629
|
+
background: linear-gradient(
|
|
2630
|
+
to bottom,
|
|
2631
|
+
transparent 0%,
|
|
2632
|
+
rgba(0, 0, 0, 0.1) 20%,
|
|
2633
|
+
rgba(0, 0, 0, 0.1) 80%,
|
|
2634
|
+
transparent 100%
|
|
2635
|
+
);
|
|
2636
|
+
pointer-events: none;
|
|
2637
|
+
z-index: 1;
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
/* Dropdown Arrow Container */
|
|
2641
|
+
.${p}arrow-container {
|
|
2642
|
+
position: absolute;
|
|
2643
|
+
top: 0;
|
|
2644
|
+
right: 0;
|
|
2645
|
+
bottom: 0;
|
|
2646
|
+
width: 40px;
|
|
2647
|
+
display: flex;
|
|
2648
|
+
align-items: center;
|
|
2649
|
+
justify-content: center;
|
|
2650
|
+
cursor: pointer;
|
|
2651
|
+
transition: background-color 0.2s ease;
|
|
2652
|
+
border-radius: 0 4px 4px 0;
|
|
2653
|
+
z-index: 2;
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
.${p}arrow-container:hover {
|
|
2657
|
+
background-color: rgba(102, 126, 234, 0.08);
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
.${p}arrow {
|
|
2661
|
+
width: 16px;
|
|
2662
|
+
height: 16px;
|
|
2663
|
+
color: #667eea;
|
|
2664
|
+
transition: transform 0.2s ease, color 0.2s ease;
|
|
2665
|
+
transform: translateY(0);
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
.${p}arrow-container:hover .${p}arrow {
|
|
2669
|
+
color: #667eea;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
.${p}arrow.${p}open {
|
|
2673
|
+
transform: rotate(180deg);
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
/* Input */
|
|
2677
|
+
.${p}input {
|
|
2678
|
+
flex: 1;
|
|
2679
|
+
min-width: 120px;
|
|
2680
|
+
padding: 4px;
|
|
2681
|
+
border: none;
|
|
2682
|
+
font-size: 14px;
|
|
2683
|
+
line-height: 1.5;
|
|
2684
|
+
color: #1f2937;
|
|
2685
|
+
background: transparent;
|
|
2686
|
+
box-sizing: border-box;
|
|
2687
|
+
outline: none;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
.${p}input::placeholder {
|
|
2691
|
+
color: #9ca3af;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
/* Selection Badges */
|
|
2695
|
+
.${p}badge {
|
|
2696
|
+
display: inline-flex;
|
|
2697
|
+
align-items: center;
|
|
2698
|
+
gap: 4px;
|
|
2699
|
+
padding: 4px 8px;
|
|
2700
|
+
margin: 2px;
|
|
2701
|
+
background: #667eea;
|
|
2702
|
+
color: white;
|
|
2703
|
+
border-radius: 4px;
|
|
2704
|
+
font-size: 13px;
|
|
2705
|
+
line-height: 1;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
.${p}badge-remove {
|
|
2709
|
+
display: inline-flex;
|
|
2710
|
+
align-items: center;
|
|
2711
|
+
justify-content: center;
|
|
2712
|
+
width: 16px;
|
|
2713
|
+
height: 16px;
|
|
2714
|
+
padding: 0;
|
|
2715
|
+
margin-left: 4px;
|
|
2716
|
+
background: rgba(255, 255, 255, 0.3);
|
|
2717
|
+
border: none;
|
|
2718
|
+
border-radius: 50%;
|
|
2719
|
+
color: white;
|
|
2720
|
+
font-size: 16px;
|
|
2721
|
+
line-height: 1;
|
|
2722
|
+
cursor: pointer;
|
|
2723
|
+
transition: background 0.2s;
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
.${p}badge-remove:hover {
|
|
2727
|
+
background: rgba(255, 255, 255, 0.5);
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
/* Dropdown */
|
|
2731
|
+
.${p}dropdown {
|
|
2732
|
+
position: absolute;
|
|
2733
|
+
scroll-behavior: smooth;
|
|
2734
|
+
top: 100%;
|
|
2735
|
+
left: 0;
|
|
2736
|
+
right: 0;
|
|
2737
|
+
margin-top: 4px;
|
|
2738
|
+
max-height: 300px;
|
|
2739
|
+
overflow: hidden;
|
|
2740
|
+
background: white;
|
|
2741
|
+
border: 1px solid #ccc;
|
|
2742
|
+
border-radius: 4px;
|
|
2743
|
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
2744
|
+
z-index: 1000;
|
|
2745
|
+
box-sizing: border-box;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
.${p}dropdown[style*="display: none"] {
|
|
2749
|
+
display: none !important;
|
|
2750
|
+
}
|
|
2751
|
+
|
|
2752
|
+
/* Options Container */
|
|
2753
|
+
.${p}options-container {
|
|
2754
|
+
position: relative;
|
|
2755
|
+
max-height: 300px;
|
|
2756
|
+
overflow: auto;
|
|
2757
|
+
transition: opacity 0.2s ease-in-out;
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
/* Option */
|
|
2761
|
+
.${p}option {
|
|
2762
|
+
padding: 8px 12px;
|
|
2763
|
+
cursor: pointer;
|
|
2764
|
+
color: inherit;
|
|
2765
|
+
transition: background-color 0.15s ease;
|
|
2766
|
+
user-select: none;
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
.${p}option:hover {
|
|
2770
|
+
background-color: #f3f4f6;
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
.${p}option.${p}selected {
|
|
2774
|
+
background-color: #e0e7ff;
|
|
2775
|
+
color: #4338ca;
|
|
2776
|
+
font-weight: 500;
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
.${p}option.${p}active {
|
|
2780
|
+
background-color: #f3f4f6;
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
/* Load More */
|
|
2784
|
+
.${p}load-more-container {
|
|
2785
|
+
padding: 12px;
|
|
2786
|
+
text-align: center;
|
|
2787
|
+
border-top: 1px solid #e0e0e0;
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
.${p}load-more-button {
|
|
2791
|
+
padding: 8px 16px;
|
|
2792
|
+
border: 1px solid #1976d2;
|
|
2793
|
+
background: white;
|
|
2794
|
+
color: #1976d2;
|
|
2795
|
+
border-radius: 4px;
|
|
2796
|
+
cursor: pointer;
|
|
2797
|
+
font-size: 14px;
|
|
2798
|
+
transition: all 0.2s ease;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
.${p}load-more-button:hover {
|
|
2802
|
+
background: #1976d2;
|
|
2803
|
+
color: white;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
.${p}load-more-button:disabled {
|
|
2807
|
+
opacity: 0.5;
|
|
2808
|
+
cursor: not-allowed;
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
/* Busy State */
|
|
2812
|
+
.${p}busy-bucket {
|
|
2813
|
+
padding: 16px;
|
|
2814
|
+
text-align: center;
|
|
2815
|
+
color: #666;
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
.${p}spinner {
|
|
2819
|
+
display: inline-block;
|
|
2820
|
+
width: 20px;
|
|
2821
|
+
height: 20px;
|
|
2822
|
+
border: 2px solid #ccc;
|
|
2823
|
+
border-top-color: #1976d2;
|
|
2824
|
+
border-radius: 50%;
|
|
2825
|
+
animation: ${p}spin 0.6s linear infinite;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
@keyframes ${p}spin {
|
|
2829
|
+
to { transform: rotate(360deg); }
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
/* Empty State */
|
|
2833
|
+
.${p}empty-state {
|
|
2834
|
+
padding: 24px;
|
|
2835
|
+
text-align: center;
|
|
2836
|
+
color: #999;
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
/* Searching State */
|
|
2840
|
+
.${p}searching-state {
|
|
2841
|
+
padding: 24px;
|
|
2842
|
+
text-align: center;
|
|
2843
|
+
color: #667eea;
|
|
2844
|
+
font-style: italic;
|
|
2845
|
+
animation: ${p}pulse 1.5s ease-in-out infinite;
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
@keyframes ${p}pulse {
|
|
2849
|
+
0%, 100% { opacity: 1; }
|
|
2850
|
+
50% { opacity: 0.5; }
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
/* Error states */
|
|
2854
|
+
.${p}input[aria-invalid="true"] {
|
|
2855
|
+
border-color: #dc2626;
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
.${p}input[aria-invalid="true"]:focus {
|
|
2859
|
+
border-color: #dc2626;
|
|
2860
|
+
box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.1);
|
|
2861
|
+
outline-color: #dc2626;
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
/* Live Region (Screen reader only) */
|
|
2865
|
+
.${p}live-region {
|
|
2866
|
+
position: absolute;
|
|
2867
|
+
left: -10000px;
|
|
2868
|
+
width: 1px;
|
|
2869
|
+
height: 1px;
|
|
2870
|
+
overflow: hidden;
|
|
2871
|
+
clip: rect(0, 0, 0, 0);
|
|
2872
|
+
white-space: nowrap;
|
|
2873
|
+
border-width: 0;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
/* Accessibility: Reduced motion */
|
|
2877
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2878
|
+
.${p}arrow,
|
|
2879
|
+
.${p}badge-remove,
|
|
2880
|
+
.${p}option,
|
|
2881
|
+
.${p}dropdown {
|
|
2882
|
+
animation-duration: 0.01ms !important;
|
|
2883
|
+
animation-iteration-count: 1 !important;
|
|
2884
|
+
transition-duration: 0.01ms !important;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
/* Touch targets (WCAG 2.5.5) */
|
|
2889
|
+
.${p}load-more-button,
|
|
2890
|
+
.${p}option {
|
|
2891
|
+
min-height: 44px;
|
|
2892
|
+
}
|
|
2893
|
+
`;
|
|
2894
|
+
// Append to document head
|
|
2895
|
+
document.head.appendChild(this._styleElement);
|
|
2896
|
+
}
|
|
2897
|
+
_createContainer() {
|
|
2898
|
+
const container = document.createElement('div');
|
|
2899
|
+
container.className = `${this.PREFIX}container`;
|
|
2900
|
+
return container;
|
|
2901
|
+
}
|
|
2902
|
+
_createInputContainer() {
|
|
2903
|
+
const container = document.createElement('div');
|
|
2904
|
+
container.className = `${this.PREFIX}input-container`;
|
|
2905
|
+
return container;
|
|
2906
|
+
}
|
|
2907
|
+
_createInput() {
|
|
2908
|
+
const input = document.createElement('input');
|
|
2909
|
+
input.type = 'text';
|
|
2910
|
+
input.className = `${this.PREFIX}input`;
|
|
2911
|
+
input.placeholder = this.getAttribute('placeholder') || 'Select an option...';
|
|
2912
|
+
input.setAttribute('readonly', '');
|
|
2913
|
+
input.setAttribute('role', 'combobox');
|
|
2914
|
+
input.setAttribute('aria-expanded', 'false');
|
|
2915
|
+
input.setAttribute('aria-haspopup', 'listbox');
|
|
2916
|
+
input.setAttribute('aria-autocomplete', 'none');
|
|
2917
|
+
input.setAttribute('aria-controls', `${this._uniqueId}-listbox`);
|
|
2918
|
+
input.setAttribute('aria-owns', `${this._uniqueId}-listbox`);
|
|
2919
|
+
input.tabIndex = 0;
|
|
2920
|
+
return input;
|
|
2921
|
+
}
|
|
2922
|
+
_createArrowContainer() {
|
|
2923
|
+
const container = document.createElement('div');
|
|
2924
|
+
container.className = `${this.PREFIX}arrow-container`;
|
|
2925
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
2926
|
+
svg.setAttribute('class', `${this.PREFIX}arrow`);
|
|
2927
|
+
svg.setAttribute('width', '16');
|
|
2928
|
+
svg.setAttribute('height', '16');
|
|
2929
|
+
svg.setAttribute('viewBox', '0 0 16 16');
|
|
2930
|
+
svg.setAttribute('fill', 'none');
|
|
2931
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
2932
|
+
path.setAttribute('d', 'M4 6l4 4 4-4');
|
|
2933
|
+
path.setAttribute('stroke', 'currentColor');
|
|
2934
|
+
path.setAttribute('stroke-width', '2');
|
|
2935
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
2936
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
2937
|
+
svg.appendChild(path);
|
|
2938
|
+
container.appendChild(svg);
|
|
2939
|
+
return container;
|
|
2940
|
+
}
|
|
2941
|
+
_createDropdown() {
|
|
2942
|
+
const dropdown = document.createElement('div');
|
|
2943
|
+
dropdown.id = `${this._uniqueId}-listbox`;
|
|
2944
|
+
dropdown.className = `${this.PREFIX}dropdown`;
|
|
2945
|
+
dropdown.style.display = 'none';
|
|
2946
|
+
dropdown.setAttribute('role', 'listbox');
|
|
2947
|
+
return dropdown;
|
|
2948
|
+
}
|
|
2949
|
+
_createOptionsContainer() {
|
|
2950
|
+
const container = document.createElement('div');
|
|
2951
|
+
container.className = `${this.PREFIX}options-container`;
|
|
2952
|
+
return container;
|
|
2953
|
+
}
|
|
2954
|
+
_createLiveRegion() {
|
|
2955
|
+
const region = document.createElement('div');
|
|
2956
|
+
region.className = `${this.PREFIX}live-region`;
|
|
2957
|
+
region.setAttribute('role', 'status');
|
|
2958
|
+
region.setAttribute('aria-live', 'polite');
|
|
2959
|
+
region.setAttribute('aria-atomic', 'true');
|
|
2960
|
+
return region;
|
|
2961
|
+
}
|
|
2962
|
+
_assembleDOM() {
|
|
2963
|
+
// Assemble in light DOM
|
|
2964
|
+
this._inputContainer.appendChild(this._input);
|
|
2965
|
+
this._inputContainer.appendChild(this._arrowContainer);
|
|
2966
|
+
this._container.appendChild(this._inputContainer);
|
|
2967
|
+
this._dropdown.appendChild(this._optionsContainer);
|
|
2968
|
+
this._container.appendChild(this._dropdown);
|
|
2969
|
+
this._container.appendChild(this._liveRegion);
|
|
2970
|
+
this.appendChild(this._container);
|
|
2971
|
+
}
|
|
2972
|
+
_attachEventListeners() {
|
|
2973
|
+
// Arrow click handler
|
|
2974
|
+
if (this._arrowContainer) {
|
|
2975
|
+
this._boundArrowClick = (e) => {
|
|
2976
|
+
e.stopPropagation();
|
|
2977
|
+
e.preventDefault();
|
|
2978
|
+
const wasOpen = this._state.isOpen;
|
|
2979
|
+
this._state.isOpen = !this._state.isOpen;
|
|
2980
|
+
this._updateDropdownVisibility();
|
|
2981
|
+
this._updateArrowRotation();
|
|
2982
|
+
if (this._state.isOpen && this._config.callbacks.onOpen) {
|
|
2983
|
+
this._config.callbacks.onOpen();
|
|
2984
|
+
}
|
|
2985
|
+
else if (!this._state.isOpen && this._config.callbacks.onClose) {
|
|
2986
|
+
this._config.callbacks.onClose();
|
|
2987
|
+
}
|
|
2988
|
+
if (!wasOpen && this._state.isOpen && this._state.selectedIndices.size > 0) {
|
|
2989
|
+
setTimeout(() => this._scrollToSelected(), 50);
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
this._arrowContainer.addEventListener('click', this._boundArrowClick);
|
|
2993
|
+
}
|
|
2994
|
+
// Input focus handler
|
|
2995
|
+
this._input.addEventListener('focus', () => {
|
|
2996
|
+
if (!this._state.isOpen) {
|
|
2997
|
+
this._state.isOpen = true;
|
|
2998
|
+
this._updateDropdownVisibility();
|
|
2999
|
+
this._updateArrowRotation();
|
|
3000
|
+
if (this._config.callbacks.onOpen) {
|
|
3001
|
+
this._config.callbacks.onOpen();
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
// Input keyboard handler
|
|
3006
|
+
this._input.addEventListener('keydown', (e) => this._handleKeydown(e));
|
|
3007
|
+
// Click outside to close
|
|
3008
|
+
document.addEventListener('click', (e) => {
|
|
3009
|
+
if (!this.contains(e.target) && this._state.isOpen) {
|
|
3010
|
+
this._state.isOpen = false;
|
|
3011
|
+
this._updateDropdownVisibility();
|
|
3012
|
+
this._updateArrowRotation();
|
|
3013
|
+
if (this._config.callbacks.onClose) {
|
|
3014
|
+
this._config.callbacks.onClose();
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
});
|
|
3018
|
+
// Search handler
|
|
3019
|
+
if (this.hasAttribute('searchable')) {
|
|
3020
|
+
this._input.removeAttribute('readonly');
|
|
3021
|
+
this._input.addEventListener('input', (e) => {
|
|
3022
|
+
const query = e.target.value;
|
|
3023
|
+
this._handleSearch(query);
|
|
3024
|
+
});
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
_initializeObservers() {
|
|
3028
|
+
// Resize observer for dropdown positioning
|
|
3029
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
3030
|
+
this._resizeObserver = new ResizeObserver(() => {
|
|
3031
|
+
if (this._state.isOpen) {
|
|
3032
|
+
this._updateDropdownPosition();
|
|
3033
|
+
}
|
|
3034
|
+
});
|
|
3035
|
+
this._resizeObserver.observe(this);
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
_updateDropdownVisibility() {
|
|
3039
|
+
if (this._state.isOpen) {
|
|
3040
|
+
this._dropdown.style.display = 'block';
|
|
3041
|
+
this._input.setAttribute('aria-expanded', 'true');
|
|
3042
|
+
this._updateDropdownPosition();
|
|
3043
|
+
}
|
|
3044
|
+
else {
|
|
3045
|
+
this._dropdown.style.display = 'none';
|
|
3046
|
+
this._input.setAttribute('aria-expanded', 'false');
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
_updateDropdownPosition() {
|
|
3050
|
+
// Ensure dropdown is positioned correctly relative to input
|
|
3051
|
+
const rect = this._inputContainer.getBoundingClientRect();
|
|
3052
|
+
const viewportHeight = window.innerHeight;
|
|
3053
|
+
const spaceBelow = viewportHeight - rect.bottom;
|
|
3054
|
+
const spaceAbove = rect.top;
|
|
3055
|
+
// Auto placement
|
|
3056
|
+
if (spaceBelow < 300 && spaceAbove > spaceBelow) {
|
|
3057
|
+
// Open upward
|
|
3058
|
+
this._dropdown.style.top = 'auto';
|
|
3059
|
+
this._dropdown.style.bottom = '100%';
|
|
3060
|
+
this._dropdown.style.marginTop = '0';
|
|
3061
|
+
this._dropdown.style.marginBottom = '4px';
|
|
3062
|
+
}
|
|
3063
|
+
else {
|
|
3064
|
+
// Open downward (default)
|
|
3065
|
+
this._dropdown.style.top = '100%';
|
|
3066
|
+
this._dropdown.style.bottom = 'auto';
|
|
3067
|
+
this._dropdown.style.marginTop = '4px';
|
|
3068
|
+
this._dropdown.style.marginBottom = '0';
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
_updateArrowRotation() {
|
|
3072
|
+
const arrow = this._arrowContainer?.querySelector(`.${this.PREFIX}arrow`);
|
|
3073
|
+
if (arrow) {
|
|
3074
|
+
if (this._state.isOpen) {
|
|
3075
|
+
arrow.classList.add(`${this.PREFIX}open`);
|
|
3076
|
+
}
|
|
3077
|
+
else {
|
|
3078
|
+
arrow.classList.remove(`${this.PREFIX}open`);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
_handleKeydown(e) {
|
|
3083
|
+
// Implement keyboard navigation
|
|
3084
|
+
switch (e.key) {
|
|
3085
|
+
case 'ArrowDown':
|
|
3086
|
+
e.preventDefault();
|
|
3087
|
+
if (!this._state.isOpen) {
|
|
3088
|
+
this._state.isOpen = true;
|
|
3089
|
+
this._updateDropdownVisibility();
|
|
3090
|
+
this._updateArrowRotation();
|
|
3091
|
+
}
|
|
3092
|
+
else {
|
|
3093
|
+
this._moveActive(1);
|
|
3094
|
+
}
|
|
3095
|
+
break;
|
|
3096
|
+
case 'ArrowUp':
|
|
3097
|
+
e.preventDefault();
|
|
3098
|
+
if (this._state.isOpen) {
|
|
3099
|
+
this._moveActive(-1);
|
|
3100
|
+
}
|
|
3101
|
+
break;
|
|
3102
|
+
case 'Enter':
|
|
3103
|
+
e.preventDefault();
|
|
3104
|
+
if (this._state.isOpen && this._state.activeIndex >= 0) {
|
|
3105
|
+
this._selectByIndex(this._state.activeIndex);
|
|
3106
|
+
}
|
|
3107
|
+
else {
|
|
3108
|
+
this._state.isOpen = true;
|
|
3109
|
+
this._updateDropdownVisibility();
|
|
3110
|
+
this._updateArrowRotation();
|
|
3111
|
+
}
|
|
3112
|
+
break;
|
|
3113
|
+
case 'Escape':
|
|
3114
|
+
e.preventDefault();
|
|
3115
|
+
if (this._state.isOpen) {
|
|
3116
|
+
this._state.isOpen = false;
|
|
3117
|
+
this._updateDropdownVisibility();
|
|
3118
|
+
this._updateArrowRotation();
|
|
3119
|
+
}
|
|
3120
|
+
break;
|
|
3121
|
+
case 'Tab':
|
|
3122
|
+
if (this._state.isOpen) {
|
|
3123
|
+
this._state.isOpen = false;
|
|
3124
|
+
this._updateDropdownVisibility();
|
|
3125
|
+
this._updateArrowRotation();
|
|
3126
|
+
}
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
_moveActive(direction) {
|
|
3131
|
+
const options = this._optionsContainer.querySelectorAll(`.${this.PREFIX}option`);
|
|
3132
|
+
if (options.length === 0)
|
|
3133
|
+
return;
|
|
3134
|
+
let newIndex = this._state.activeIndex + direction;
|
|
3135
|
+
if (newIndex < 0)
|
|
3136
|
+
newIndex = 0;
|
|
3137
|
+
if (newIndex >= options.length)
|
|
3138
|
+
newIndex = options.length - 1;
|
|
3139
|
+
this._state.activeIndex = newIndex;
|
|
3140
|
+
// Update visual active state
|
|
3141
|
+
options.forEach((opt, idx) => {
|
|
3142
|
+
if (idx === newIndex) {
|
|
3143
|
+
opt.classList.add(`${this.PREFIX}active`);
|
|
3144
|
+
opt.scrollIntoView({ block: 'nearest' });
|
|
3145
|
+
}
|
|
3146
|
+
else {
|
|
3147
|
+
opt.classList.remove(`${this.PREFIX}active`);
|
|
3148
|
+
}
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
3151
|
+
_selectByIndex(index) {
|
|
3152
|
+
const item = this._state.loadedItems[index];
|
|
3153
|
+
if (!item)
|
|
3154
|
+
return;
|
|
3155
|
+
const isMultiple = this.hasAttribute('multiple');
|
|
3156
|
+
if (isMultiple) {
|
|
3157
|
+
// Toggle selection
|
|
3158
|
+
if (this._state.selectedIndices.has(index)) {
|
|
3159
|
+
this._state.selectedIndices.delete(index);
|
|
3160
|
+
this._state.selectedItems.delete(index);
|
|
3161
|
+
}
|
|
3162
|
+
else {
|
|
3163
|
+
this._state.selectedIndices.add(index);
|
|
3164
|
+
this._state.selectedItems.set(index, item);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
else {
|
|
3168
|
+
// Single selection
|
|
3169
|
+
this._state.selectedIndices.clear();
|
|
3170
|
+
this._state.selectedItems.clear();
|
|
3171
|
+
this._state.selectedIndices.add(index);
|
|
3172
|
+
this._state.selectedItems.set(index, item);
|
|
3173
|
+
// Close dropdown
|
|
3174
|
+
this._state.isOpen = false;
|
|
3175
|
+
this._updateDropdownVisibility();
|
|
3176
|
+
this._updateArrowRotation();
|
|
3177
|
+
}
|
|
3178
|
+
this._updateInputDisplay();
|
|
3179
|
+
this._renderOptions();
|
|
3180
|
+
this._emitChangeEvent();
|
|
3181
|
+
}
|
|
3182
|
+
_updateInputDisplay() {
|
|
3183
|
+
const selectedItems = Array.from(this._state.selectedItems.values());
|
|
3184
|
+
const isMultiple = this.hasAttribute('multiple');
|
|
3185
|
+
if (isMultiple) {
|
|
3186
|
+
// Clear input, show badges
|
|
3187
|
+
this._input.value = '';
|
|
3188
|
+
// Remove existing badges
|
|
3189
|
+
this._inputContainer.querySelectorAll(`.${this.PREFIX}badge`).forEach(badge => badge.remove());
|
|
3190
|
+
// Add new badges
|
|
3191
|
+
selectedItems.forEach((item, idx) => {
|
|
3192
|
+
const badge = document.createElement('span');
|
|
3193
|
+
badge.className = `${this.PREFIX}badge`;
|
|
3194
|
+
badge.textContent = item.label;
|
|
3195
|
+
const removeBtn = document.createElement('button');
|
|
3196
|
+
removeBtn.className = `${this.PREFIX}badge-remove`;
|
|
3197
|
+
removeBtn.textContent = '×';
|
|
3198
|
+
removeBtn.addEventListener('click', (e) => {
|
|
3199
|
+
e.stopPropagation();
|
|
3200
|
+
const itemIndex = Array.from(this._state.selectedItems.keys())[idx];
|
|
3201
|
+
this._state.selectedIndices.delete(itemIndex);
|
|
3202
|
+
this._state.selectedItems.delete(itemIndex);
|
|
3203
|
+
this._updateInputDisplay();
|
|
3204
|
+
this._renderOptions();
|
|
3205
|
+
this._emitChangeEvent();
|
|
3206
|
+
});
|
|
3207
|
+
badge.appendChild(removeBtn);
|
|
3208
|
+
this._inputContainer.insertBefore(badge, this._input);
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3211
|
+
else {
|
|
3212
|
+
// Single selection - show label in input
|
|
3213
|
+
if (selectedItems.length > 0) {
|
|
3214
|
+
this._input.value = selectedItems[0].label;
|
|
3215
|
+
}
|
|
3216
|
+
else {
|
|
3217
|
+
this._input.value = '';
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
_renderOptions() {
|
|
3222
|
+
// Clear existing options
|
|
3223
|
+
this._optionsContainer.innerHTML = '';
|
|
3224
|
+
const items = this._state.loadedItems;
|
|
3225
|
+
if (items.length === 0) {
|
|
3226
|
+
const emptyDiv = document.createElement('div');
|
|
3227
|
+
emptyDiv.className = `${this.PREFIX}empty-state`;
|
|
3228
|
+
emptyDiv.textContent = 'No options available';
|
|
3229
|
+
this._optionsContainer.appendChild(emptyDiv);
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
// Render options
|
|
3233
|
+
items.forEach((item, index) => {
|
|
3234
|
+
const optionDiv = document.createElement('div');
|
|
3235
|
+
optionDiv.className = `${this.PREFIX}option`;
|
|
3236
|
+
optionDiv.textContent = item.label;
|
|
3237
|
+
optionDiv.setAttribute('role', 'option');
|
|
3238
|
+
optionDiv.setAttribute('data-index', String(index));
|
|
3239
|
+
if (this._state.selectedIndices.has(index)) {
|
|
3240
|
+
optionDiv.classList.add(`${this.PREFIX}selected`);
|
|
3241
|
+
optionDiv.setAttribute('aria-selected', 'true');
|
|
3242
|
+
}
|
|
3243
|
+
if (item.disabled) {
|
|
3244
|
+
optionDiv.style.opacity = '0.5';
|
|
3245
|
+
optionDiv.style.cursor = 'not-allowed';
|
|
3246
|
+
}
|
|
3247
|
+
else {
|
|
3248
|
+
optionDiv.addEventListener('click', () => {
|
|
3249
|
+
this._selectByIndex(index);
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
this._optionsContainer.appendChild(optionDiv);
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
_handleSearch(query) {
|
|
3256
|
+
this._state.searchQuery = query;
|
|
3257
|
+
// Filter items based on search
|
|
3258
|
+
const allItems = this._state.loadedItems;
|
|
3259
|
+
const filtered = allItems.filter(item => item.label.toLowerCase().includes(query.toLowerCase()));
|
|
3260
|
+
// Temporarily replace loaded items with filtered
|
|
3261
|
+
this._state.loadedItems;
|
|
3262
|
+
this._state.loadedItems = filtered;
|
|
3263
|
+
this._renderOptions();
|
|
3264
|
+
// Emit search event
|
|
3265
|
+
this.dispatchEvent(new CustomEvent('search', {
|
|
3266
|
+
detail: { query },
|
|
3267
|
+
bubbles: true,
|
|
3268
|
+
composed: true,
|
|
3269
|
+
}));
|
|
3270
|
+
}
|
|
3271
|
+
_emitChangeEvent() {
|
|
3272
|
+
const selectedItems = Array.from(this._state.selectedItems.values());
|
|
3273
|
+
const selectedValues = selectedItems.map(item => item.value);
|
|
3274
|
+
const selectedIndices = Array.from(this._state.selectedIndices);
|
|
3275
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
3276
|
+
detail: { selectedItems, selectedValues, selectedIndices },
|
|
3277
|
+
bubbles: true,
|
|
3278
|
+
composed: true,
|
|
3279
|
+
}));
|
|
3280
|
+
}
|
|
3281
|
+
_scrollToSelected() {
|
|
3282
|
+
const firstSelected = this._optionsContainer.querySelector(`.${this.PREFIX}selected`);
|
|
3283
|
+
if (firstSelected) {
|
|
3284
|
+
firstSelected.scrollIntoView({ block: 'nearest' });
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
_loadInitialSelectedItems() {
|
|
3288
|
+
// Placeholder for server-side data loading
|
|
3289
|
+
}
|
|
3290
|
+
_announce(message) {
|
|
3291
|
+
if (this._liveRegion) {
|
|
3292
|
+
this._liveRegion.textContent = message;
|
|
3293
|
+
setTimeout(() => {
|
|
3294
|
+
if (this._liveRegion)
|
|
3295
|
+
this._liveRegion.textContent = '';
|
|
3296
|
+
}, 1000);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
// Public API methods
|
|
3300
|
+
setItems(items) {
|
|
3301
|
+
this._state.loadedItems = items;
|
|
3302
|
+
this._renderOptions();
|
|
3303
|
+
}
|
|
3304
|
+
setGroupedItems(groups) {
|
|
3305
|
+
this._state.groupedItems = groups;
|
|
3306
|
+
// Flatten for now
|
|
3307
|
+
const items = [];
|
|
3308
|
+
groups.forEach(group => {
|
|
3309
|
+
if (group.items) {
|
|
3310
|
+
items.push(...group.items);
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
this.setItems(items);
|
|
3314
|
+
}
|
|
3315
|
+
setSelectedValues(values) {
|
|
3316
|
+
this._state.selectedIndices.clear();
|
|
3317
|
+
this._state.selectedItems.clear();
|
|
3318
|
+
values.forEach(value => {
|
|
3319
|
+
const index = this._state.loadedItems.findIndex(item => item.value === value);
|
|
3320
|
+
if (index >= 0) {
|
|
3321
|
+
this._state.selectedIndices.add(index);
|
|
3322
|
+
this._state.selectedItems.set(index, this._state.loadedItems[index]);
|
|
3323
|
+
}
|
|
3324
|
+
});
|
|
3325
|
+
this._updateInputDisplay();
|
|
3326
|
+
this._renderOptions();
|
|
3327
|
+
}
|
|
3328
|
+
getSelectedValues() {
|
|
3329
|
+
return Array.from(this._state.selectedItems.values()).map(item => item.value);
|
|
3330
|
+
}
|
|
3331
|
+
updateConfig(config) {
|
|
3332
|
+
this._config = { ...this._config, ...config };
|
|
3333
|
+
}
|
|
3334
|
+
setError(message) {
|
|
3335
|
+
this._hasError = true;
|
|
3336
|
+
this._errorMessage = message;
|
|
3337
|
+
this._input.setAttribute('aria-invalid', 'true');
|
|
3338
|
+
this._announce(`Error: ${message}`);
|
|
3339
|
+
}
|
|
3340
|
+
clearError() {
|
|
3341
|
+
this._hasError = false;
|
|
3342
|
+
this._errorMessage = '';
|
|
3343
|
+
this._input.removeAttribute('aria-invalid');
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
// Register the custom element
|
|
3347
|
+
if (typeof customElements !== 'undefined' && !customElements.get('angular-enhanced-select')) {
|
|
3348
|
+
customElements.define('angular-enhanced-select', AngularEnhancedSelect);
|
|
3349
|
+
}
|
|
3350
|
+
|
|
2477
3351
|
/**
|
|
2478
3352
|
* Independent Option Component
|
|
2479
3353
|
* High cohesion, low coupling - handles its own selection state and events
|
|
@@ -3736,5 +4610,5 @@ function warnCSPViolation(feature, fallback) {
|
|
|
3736
4610
|
}
|
|
3737
4611
|
}
|
|
3738
4612
|
|
|
3739
|
-
export { CSPFeatures, DOMPool, EnhancedSelect, FenwickTree, NativeSelectElement, PerformanceTelemetry, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, configureSelect, containsSuspiciousPatterns, createElement, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getCustomProperty, getHTMLSanitizer, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, injectShadowStyles, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, validateTemplate, warnCSPViolation };
|
|
4613
|
+
export { AngularEnhancedSelect, CSPFeatures, DOMPool, EnhancedSelect, FenwickTree, NativeSelectElement, PerformanceTelemetry, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, configureSelect, containsSuspiciousPatterns, createElement, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getCustomProperty, getHTMLSanitizer, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, injectShadowStyles, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, validateTemplate, warnCSPViolation };
|
|
3740
4614
|
//# sourceMappingURL=index.js.map
|