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