@jinntec/fore 2.5.0 → 2.6.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.
@@ -1,89 +0,0 @@
1
- export class FxSelect extends HTMLElement {
2
- constructor() {
3
- super();
4
-
5
- // Attach Shadow DOM to encapsulate the component
6
- this.attachShadow({ mode: 'open' });
7
-
8
- // Create and attach the <select> element
9
- this.selectElement = document.createElement('select');
10
- this.shadowRoot.appendChild(this.selectElement);
11
-
12
- // Set default values
13
- this.batchSize = parseInt(this.getAttribute('batch-size')) || 20;
14
- this.size = parseInt(this.getAttribute('size')) || 5;
15
- this.currentLoadedItems = 0;
16
- this.hasMoreItems = true; // Assume there are more items initially
17
-
18
- // Set the size of the <select> element
19
- this.selectElement.setAttribute('size', this.size);
20
-
21
- // Bind the scroll event handler
22
- this.handleScroll = this.handleScroll.bind(this);
23
- }
24
-
25
- connectedCallback() {
26
- // Initial load of options
27
- this.loadOptions(this.currentLoadedItems, this.batchSize);
28
-
29
- // Attach scroll event listener
30
- this.selectElement.addEventListener('scroll', this.handleScroll);
31
- }
32
-
33
- disconnectedCallback() {
34
- // Clean up event listeners when the element is removed
35
- this.selectElement.removeEventListener('scroll', this.handleScroll);
36
- }
37
-
38
- // Mock function to simulate fetching more options
39
- fetchMoreItems(start, count) {
40
- // Simulate an async fetch or data load (replace with real fetch if needed)
41
- return new Promise((resolve) => {
42
- setTimeout(() => {
43
- const items = [];
44
- for (let i = start; i < start + count; i++) {
45
- if (i < 200) { // Let's say we stop after 200 items (remove this limit for real use)
46
- items.push({ value: i, label: `Option ${i + 1}` });
47
- }
48
- }
49
- resolve(items);
50
- }, 500); // Simulate fetch delay
51
- });
52
- }
53
-
54
- // Method to load a batch of options
55
- async loadOptions(start, count) {
56
- const fragment = document.createDocumentFragment();
57
- const newItems = await this.fetchMoreItems(start, count);
58
-
59
- if (newItems.length > 0) {
60
- newItems.forEach(item => {
61
- const option = document.createElement('option');
62
- option.value = item.value;
63
- option.textContent = item.label;
64
- fragment.appendChild(option);
65
- });
66
-
67
- this.selectElement.appendChild(fragment);
68
- this.currentLoadedItems += newItems.length;
69
- } else {
70
- // If no more items are returned, stop further loading
71
- this.hasMoreItems = false;
72
- }
73
- }
74
-
75
- // Scroll event handler to load more items
76
- handleScroll() {
77
- const { scrollTop, scrollHeight, clientHeight } = this.selectElement;
78
- const isNearBottom = scrollTop + clientHeight >= scrollHeight - 10;
79
-
80
- if (isNearBottom && this.hasMoreItems) {
81
- this.loadOptions(this.currentLoadedItems, this.batchSize);
82
- }
83
- }
84
- }
85
-
86
- // Register the custom element
87
- if (!customElements.get('fx-select')) {
88
- customElements.define('fx-select', FxSelect);
89
- }