@frontile/collections 0.17.0-beta.5 → 0.17.0-beta.7
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/declarations/components/listbox/listbox.d.ts +2 -2
- package/declarations/components/listbox/listbox.d.ts.map +1 -1
- package/declarations/utils/listManager.d.ts +4 -2
- package/declarations/utils/listManager.d.ts.map +1 -1
- package/dist/_app_/components/listbox/item.js +1 -0
- package/dist/_app_/components/listbox/listbox.js +1 -0
- package/dist/components/dropdown.js +49 -53
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/listbox/item.js +104 -0
- package/dist/components/listbox/item.js.map +1 -0
- package/dist/components/listbox/listbox.js +109 -0
- package/dist/components/listbox/listbox.js.map +1 -0
- package/dist/components/listbox.js +2 -1
- package/dist/components/listbox.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js +67 -0
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js.map +1 -0
- package/dist/utils/listManager.js +233 -193
- package/dist/utils/listManager.js.map +1 -1
- package/package.json +46 -47
- package/dist/listbox-BUkpkk6G.js +0 -205
- package/dist/listbox-BUkpkk6G.js.map +0 -1
- package/dist/listbox-DSfkMsrl.js +0 -207
- package/dist/listbox-DSfkMsrl.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-BPCpkOf1-B5Lbloj7.js","sources":["../../../node_modules/.pnpm/decorator-transforms@2.3.0_@babel+core@7.26.7/node_modules/decorator-transforms/dist/runtime-BPCpkOf1.js"],"sourcesContent":["const deferred = /* @__PURE__ */ new WeakMap();\nfunction deferDecorator(proto, prop, desc) {\n let map = deferred.get(proto);\n if (!map) {\n map = /* @__PURE__ */ new Map();\n deferred.set(proto, map);\n }\n map.set(prop, desc);\n}\nfunction findDeferredDecorator(target, prop) {\n var _a;\n let cursor = target.prototype;\n while (cursor) {\n let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);\n if (desc) {\n return desc;\n }\n cursor = cursor.prototype;\n }\n}\nfunction decorateFieldV1(target, prop, decorators, initializer) {\n return decorateFieldV2(target.prototype, prop, decorators, initializer);\n}\nfunction decorateFieldV2(prototype, prop, decorators, initializer) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: null\n };\n if (initializer) {\n desc.initializer = initializer;\n }\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer === void 0) {\n Object.defineProperty(prototype, prop, desc);\n } else {\n deferDecorator(prototype, prop, desc);\n }\n}\nfunction decorateMethodV1({ prototype }, prop, decorators) {\n return decorateMethodV2(prototype, prop, decorators);\n}\nfunction decorateMethodV2(prototype, prop, decorators) {\n const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);\n let desc = { ...origDesc };\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;\n desc.initializer = void 0;\n }\n Object.defineProperty(prototype, prop, desc);\n}\nfunction initializeDeferredDecorator(target, prop) {\n let desc = findDeferredDecorator(target.constructor, prop);\n if (desc) {\n Object.defineProperty(target, prop, {\n enumerable: desc.enumerable,\n configurable: desc.configurable,\n writable: desc.writable,\n value: desc.initializer ? desc.initializer.call(target) : void 0\n });\n }\n}\nfunction decorateClass(target, decorators) {\n return decorators.reduce(\n (accum, decorator) => decorator(accum) || accum,\n target\n );\n}\nfunction decoratePOJO(pojo, decorated) {\n for (let [type, prop, decorators] of decorated) {\n if (type === \"field\") {\n decoratePojoField(pojo, prop, decorators);\n } else {\n decorateMethodV2(pojo, prop, decorators);\n }\n }\n return pojo;\n}\nfunction decoratePojoField(pojo, prop, decorators) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: () => {\n var _a;\n return (_a = Object.getOwnPropertyDescriptor(pojo, prop)) == null ? void 0 : _a.value;\n }\n };\n for (let decorator of decorators) {\n desc = decorator(pojo, prop, desc) || desc;\n }\n if (desc.initializer) {\n desc.value = desc.initializer.call(pojo);\n delete desc.initializer;\n }\n Object.defineProperty(pojo, prop, desc);\n}\nconst runtime = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({\n __proto__: null,\n c: decorateClass,\n f: decorateFieldV1,\n g: decorateFieldV2,\n i: initializeDeferredDecorator,\n m: decorateMethodV1,\n n: decorateMethodV2,\n p: decoratePOJO\n}, Symbol.toStringTag, { value: \"Module\" }));\nexport {\n decorateFieldV2 as a,\n decorateMethodV1 as b,\n decorateMethodV2 as c,\n decorateFieldV1 as d,\n decorateClass as e,\n decoratePOJO as f,\n initializeDeferredDecorator as i,\n runtime as r\n};\n//# sourceMappingURL=runtime-BPCpkOf1.js.map\n"],"names":["deferred","WeakMap","deferDecorator","proto","prop","desc","map","get","Map","set","findDeferredDecorator","target","_a","cursor","prototype","decorateFieldV2","decorators","initializer","configurable","enumerable","writable","decorator","Object","defineProperty","decorateMethodV2","origDesc","getOwnPropertyDescriptor","value","call","initializeDeferredDecorator","constructor"],"mappings":"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","x_google_ignoreList":[0]}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import _initializerDefineProperty from '@babel/runtime/helpers/esm/initializerDefineProperty';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
3
|
-
import _applyDecoratedDescriptor from '@babel/runtime/helpers/esm/applyDecoratedDescriptor';
|
|
4
|
-
import '@babel/runtime/helpers/esm/initializerWarningHelper';
|
|
5
1
|
import { tracked } from '@glimmer/tracking';
|
|
6
|
-
import { debounce } from '@ember/runloop';
|
|
2
|
+
import { later, debounce } from '@ember/runloop';
|
|
7
3
|
import { modifier } from 'ember-modifier';
|
|
4
|
+
import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../runtime-BPCpkOf1-B5Lbloj7.js';
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
/* eslint-disable ember/no-runloop */
|
|
7
|
+
class ListItem {
|
|
8
|
+
el;
|
|
9
|
+
key;
|
|
10
|
+
textValue;
|
|
11
|
+
static {
|
|
12
|
+
decorateFieldV2(this.prototype, "isSelected", [tracked]);
|
|
13
|
+
}
|
|
14
|
+
#isSelected = (initializeDeferredDecorator(this, "isSelected"), void 0);
|
|
15
|
+
static {
|
|
16
|
+
decorateFieldV2(this.prototype, "isDisabled", [tracked]);
|
|
17
|
+
}
|
|
18
|
+
#isDisabled = (initializeDeferredDecorator(this, "isDisabled"), void 0);
|
|
19
|
+
static {
|
|
20
|
+
decorateFieldV2(this.prototype, "isActive", [tracked]);
|
|
21
|
+
}
|
|
22
|
+
#isActive = (initializeDeferredDecorator(this, "isActive"), void 0);
|
|
18
23
|
constructor(el, args) {
|
|
19
|
-
_defineProperty(this, "el", void 0);
|
|
20
|
-
_defineProperty(this, "key", void 0);
|
|
21
|
-
_defineProperty(this, "textValue", void 0);
|
|
22
|
-
_initializerDefineProperty(this, "isSelected", _descriptor, this);
|
|
23
|
-
_initializerDefineProperty(this, "isDisabled", _descriptor2, this);
|
|
24
|
-
_initializerDefineProperty(this, "isActive", _descriptor3, this);
|
|
25
24
|
this.el = el;
|
|
26
25
|
this.key = args.key;
|
|
27
26
|
this.textValue = args.textValue;
|
|
@@ -29,127 +28,63 @@ let ListItem = (_class = class ListItem {
|
|
|
29
28
|
this.isDisabled = args.isDisabled;
|
|
30
29
|
this.isActive = args.isActive;
|
|
31
30
|
}
|
|
32
|
-
}
|
|
33
|
-
configurable: true,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
initializer: null
|
|
37
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "isDisabled", [tracked], {
|
|
38
|
-
configurable: true,
|
|
39
|
-
enumerable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
initializer: null
|
|
42
|
-
}), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "isActive", [tracked], {
|
|
43
|
-
configurable: true,
|
|
44
|
-
enumerable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
initializer: null
|
|
47
|
-
}), _class);
|
|
48
|
-
var _items = /*#__PURE__*/new WeakMap();
|
|
49
|
-
var _ListManager_brand = /*#__PURE__*/new WeakSet();
|
|
31
|
+
}
|
|
50
32
|
class ListManager {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_defineProperty(this, "setup", modifier((_el, _, args) => {
|
|
63
|
-
this.updateArgs({
|
|
64
|
-
selectionMode: args.selectionMode,
|
|
65
|
-
disabledKeys: args.disabledKeys,
|
|
66
|
-
selectedKeys: args.selectedKeys,
|
|
67
|
-
allowEmpty: args.allowEmpty,
|
|
68
|
-
autoActivateFirstItem: args.autoActivateFirstItem
|
|
69
|
-
});
|
|
70
|
-
}));
|
|
71
|
-
_defineProperty(this, "setupItem", modifier((el, _, args) => {
|
|
72
|
-
let textValue = args.textValue;
|
|
73
|
-
if (typeof textValue === 'undefined' || textValue === '' || textValue === null) {
|
|
74
|
-
const labelId = el.getAttribute('aria-labelledby');
|
|
75
|
-
if (labelId) {
|
|
76
|
-
const labelElement = el.querySelector(`#${labelId}`);
|
|
77
|
-
if (labelElement) {
|
|
78
|
-
textValue = labelElement.textContent?.trim() || '';
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
textValue = el.textContent?.trim() || '';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
this.register(el, {
|
|
85
|
-
key: args.key,
|
|
86
|
-
textValue: textValue || '',
|
|
87
|
-
isActive: false,
|
|
88
|
-
isDisabled: this.isKeyDisabled(args.key),
|
|
89
|
-
isSelected: this.isKeySelected(args.key)
|
|
90
|
-
});
|
|
91
|
-
const item = this.at(el);
|
|
92
|
-
if (item && typeof args.onRegister === 'function') {
|
|
93
|
-
args.onRegister(item);
|
|
94
|
-
}
|
|
95
|
-
const mouseEnter = () => {
|
|
96
|
-
this.activateItem(item);
|
|
97
|
-
};
|
|
98
|
-
const mouseLeave = () => {
|
|
99
|
-
if (item) {
|
|
100
|
-
item.isActive = false;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
if (!args.disableEvents) {
|
|
104
|
-
el.addEventListener('mouseenter', mouseEnter);
|
|
105
|
-
el.addEventListener('mouseleave', mouseLeave);
|
|
106
|
-
el.addEventListener('focusin', mouseEnter);
|
|
107
|
-
el.addEventListener('focusout', mouseLeave);
|
|
108
|
-
}
|
|
109
|
-
return () => {
|
|
110
|
-
this.unregister(el);
|
|
111
|
-
if (!args.disableEvents) {
|
|
112
|
-
el.removeEventListener('mouseenter', mouseEnter);
|
|
113
|
-
el.removeEventListener('mouseleave', mouseLeave);
|
|
114
|
-
el.removeEventListener('focusin', mouseEnter);
|
|
115
|
-
el.removeEventListener('focusout', mouseLeave);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}));
|
|
119
|
-
this.updateArgs(_args);
|
|
33
|
+
#items = [];
|
|
34
|
+
searchKeys = '';
|
|
35
|
+
args = {
|
|
36
|
+
selectionMode: 'none',
|
|
37
|
+
selectedKeys: [],
|
|
38
|
+
disabledKeys: [],
|
|
39
|
+
allowEmpty: false,
|
|
40
|
+
autoActivateMode: 'none'
|
|
41
|
+
};
|
|
42
|
+
constructor(args = {}) {
|
|
43
|
+
this.updateArgs(args);
|
|
120
44
|
}
|
|
121
45
|
register(el, args) {
|
|
122
|
-
if (this.args.
|
|
46
|
+
if (this.args.autoActivateMode == 'first' && this.#items.length === 0 && !args.isDisabled) {
|
|
123
47
|
args.isActive = true;
|
|
124
48
|
this.args.onActiveItemChange?.(args.key);
|
|
125
49
|
}
|
|
126
|
-
|
|
50
|
+
const newItem = new ListItem(el, args);
|
|
51
|
+
this.#items.push(newItem);
|
|
52
|
+
this.#syncItemsOrderWithDOM();
|
|
127
53
|
if (typeof this.args.onListItemsChange === 'function') {
|
|
128
|
-
this.args.onListItemsChange(
|
|
54
|
+
this.args.onListItemsChange(this.#items, 'add');
|
|
55
|
+
}
|
|
56
|
+
if (this.args.autoActivateMode != 'none' && this.#items.length > 1) {
|
|
57
|
+
later(() => {
|
|
58
|
+
if (this.args.autoActivateMode == 'first') {
|
|
59
|
+
this.setFirstOptionActive();
|
|
60
|
+
} else {
|
|
61
|
+
this.setSelectedOptionActive();
|
|
62
|
+
}
|
|
63
|
+
}, 1);
|
|
129
64
|
}
|
|
130
65
|
}
|
|
131
66
|
unregister(el) {
|
|
132
|
-
|
|
133
|
-
if (this.args.
|
|
134
|
-
this.activateItem(
|
|
67
|
+
this.#items = this.#items.filter(item => item.el !== el);
|
|
68
|
+
if (this.args.autoActivateMode == 'first' && this.#items.length >= 1) {
|
|
69
|
+
this.activateItem(this.#items[0]);
|
|
135
70
|
}
|
|
136
71
|
if (typeof this.args.onListItemsChange === 'function') {
|
|
137
|
-
this.args.onListItemsChange(
|
|
72
|
+
this.args.onListItemsChange(this.#items, 'remove');
|
|
138
73
|
}
|
|
139
74
|
}
|
|
140
75
|
at(el) {
|
|
141
|
-
return
|
|
76
|
+
return this.#items.find(item => item.el === el);
|
|
142
77
|
}
|
|
143
78
|
atKey(key) {
|
|
144
|
-
return
|
|
79
|
+
return this.#items.find(item => item.key === key);
|
|
145
80
|
}
|
|
146
81
|
updateArgs(args) {
|
|
147
82
|
this.args.selectedKeys = args.selectedKeys || [];
|
|
148
83
|
this.args.disabledKeys = args.disabledKeys || [];
|
|
149
84
|
this.args.allowEmpty = args.allowEmpty || false;
|
|
150
|
-
this.args.
|
|
151
|
-
for (let i = 0; i <
|
|
152
|
-
const item =
|
|
85
|
+
this.args.autoActivateMode = args.autoActivateMode || 'none';
|
|
86
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
87
|
+
const item = this.#items[i];
|
|
153
88
|
item.isSelected = this.isKeySelected(item.key);
|
|
154
89
|
item.isDisabled = this.isKeyDisabled(item.key);
|
|
155
90
|
}
|
|
@@ -170,7 +105,7 @@ class ListManager {
|
|
|
170
105
|
}
|
|
171
106
|
}
|
|
172
107
|
selectActiveItem() {
|
|
173
|
-
const item =
|
|
108
|
+
const item = this.#activeItem;
|
|
174
109
|
if (item) {
|
|
175
110
|
item.el.click();
|
|
176
111
|
}
|
|
@@ -184,47 +119,69 @@ class ListManager {
|
|
|
184
119
|
this.args.onAction(item.key);
|
|
185
120
|
}
|
|
186
121
|
if (typeof this.args.onSelectionChange === 'function' && this.args.selectionMode !== 'none') {
|
|
187
|
-
this.args.onSelectionChange(
|
|
122
|
+
this.args.onSelectionChange(this.#toggleSelectedItem(item));
|
|
188
123
|
}
|
|
189
124
|
}
|
|
190
125
|
}
|
|
191
126
|
activateItem(item) {
|
|
192
|
-
if (item) {
|
|
193
|
-
|
|
127
|
+
if (item && !item.isActive) {
|
|
128
|
+
this.#clearActive();
|
|
194
129
|
item.isActive = true;
|
|
195
130
|
this.args.onActiveItemChange?.(item.key);
|
|
131
|
+
|
|
132
|
+
// Ensure the item is scrolled into view
|
|
133
|
+
requestAnimationFrame(() => {
|
|
134
|
+
item.el.scrollIntoView({
|
|
135
|
+
block: 'nearest',
|
|
136
|
+
inline: 'nearest'
|
|
137
|
+
});
|
|
138
|
+
});
|
|
196
139
|
}
|
|
197
140
|
}
|
|
198
141
|
setNextOptionActive() {
|
|
199
|
-
for (let i =
|
|
200
|
-
const item =
|
|
201
|
-
if (item && !item.isDisabled) {
|
|
142
|
+
for (let i = this.#indexofActiveItem + 1; i < this.#items.length; i++) {
|
|
143
|
+
const item = this.#items[i];
|
|
144
|
+
if (item && !item.isDisabled && !item.isActive) {
|
|
202
145
|
this.activateItem(item);
|
|
203
146
|
break;
|
|
204
147
|
}
|
|
205
148
|
}
|
|
206
149
|
}
|
|
207
150
|
setPreviousOptionActive() {
|
|
208
|
-
for (let i =
|
|
209
|
-
const item =
|
|
210
|
-
if (item && !item.isDisabled) {
|
|
151
|
+
for (let i = this.#indexofActiveItem - 1; i >= 0; i--) {
|
|
152
|
+
const item = this.#items[i];
|
|
153
|
+
if (item && !item.isDisabled && !item.isActive) {
|
|
211
154
|
this.activateItem(item);
|
|
212
155
|
break;
|
|
213
156
|
}
|
|
214
157
|
}
|
|
215
158
|
}
|
|
216
159
|
setFirstOptionActive() {
|
|
217
|
-
for (let i = 0; i <
|
|
218
|
-
const item =
|
|
160
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
161
|
+
const item = this.#items[i];
|
|
219
162
|
if (item && !item.isDisabled) {
|
|
220
163
|
this.activateItem(item);
|
|
221
164
|
break;
|
|
222
165
|
}
|
|
223
166
|
}
|
|
224
167
|
}
|
|
168
|
+
setSelectedOptionActive() {
|
|
169
|
+
let activated = false;
|
|
170
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
171
|
+
const item = this.#items[i];
|
|
172
|
+
if (item && !item.isDisabled && item.isSelected) {
|
|
173
|
+
this.activateItem(item);
|
|
174
|
+
activated = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!activated) {
|
|
179
|
+
this.setFirstOptionActive();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
225
182
|
setLastOptionActive() {
|
|
226
|
-
for (let i =
|
|
227
|
-
const item =
|
|
183
|
+
for (let i = this.#items.length - 1; i >= 0; i--) {
|
|
184
|
+
const item = this.#items[i];
|
|
228
185
|
if (item && !item.isDisabled) {
|
|
229
186
|
this.activateItem(item);
|
|
230
187
|
break;
|
|
@@ -232,10 +189,10 @@ class ListManager {
|
|
|
232
189
|
}
|
|
233
190
|
}
|
|
234
191
|
search(key) {
|
|
235
|
-
debounce(this,
|
|
192
|
+
debounce(this, this.#clearSeaerch, 500);
|
|
236
193
|
this.searchKeys += key.toLowerCase();
|
|
237
|
-
for (let i = 0; i <
|
|
238
|
-
const item =
|
|
194
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
195
|
+
const item = this.#items[i];
|
|
239
196
|
if (!item.isDisabled && this.searchKeys && item.textValue.trim().toLowerCase().startsWith(this.searchKeys)) {
|
|
240
197
|
this.activateItem(item);
|
|
241
198
|
break;
|
|
@@ -248,82 +205,165 @@ class ListManager {
|
|
|
248
205
|
isKeySelected(key) {
|
|
249
206
|
return this.args.selectedKeys?.includes(key) || false;
|
|
250
207
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
208
|
+
get #indexofActiveItem() {
|
|
209
|
+
let item = this.#activeItem;
|
|
210
|
+
if (!item) {
|
|
211
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
212
|
+
const n = this.#items[i];
|
|
213
|
+
if (n.isSelected) {
|
|
214
|
+
item = n;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
260
217
|
}
|
|
261
218
|
}
|
|
219
|
+
if (!item) {
|
|
220
|
+
return -1;
|
|
221
|
+
}
|
|
222
|
+
return this.#items.indexOf(item);
|
|
262
223
|
}
|
|
263
|
-
|
|
264
|
-
|
|
224
|
+
|
|
225
|
+
// Ensure #items is always in sync with DOM order
|
|
226
|
+
#syncItemsOrderWithDOM() {
|
|
227
|
+
if (!this.#items.length) return;
|
|
228
|
+
|
|
229
|
+
// Sort items based on their position in the DOM
|
|
230
|
+
this.#items.sort((a, b) => {
|
|
231
|
+
const position = a.el.compareDocumentPosition(b.el);
|
|
232
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
233
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
234
|
+
return 0;
|
|
235
|
+
});
|
|
265
236
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
selectedKeys.push(_item.key);
|
|
237
|
+
#toggleSelectedItem(item) {
|
|
238
|
+
let selectedKeys = [];
|
|
239
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
240
|
+
const _item = this.#items[i];
|
|
241
|
+
if (_item.isSelected) {
|
|
242
|
+
selectedKeys.push(_item.key);
|
|
243
|
+
}
|
|
274
244
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
245
|
+
if (selectedKeys.includes(item.key) && (this.args.allowEmpty && selectedKeys.length == 1 || selectedKeys.length > 1)) {
|
|
246
|
+
const indexToRemove = selectedKeys.indexOf(item.key);
|
|
247
|
+
selectedKeys.splice(indexToRemove, 1);
|
|
248
|
+
} else {
|
|
249
|
+
if (this.args.selectionMode === 'single') {
|
|
250
|
+
selectedKeys = [item.key];
|
|
251
|
+
} else if (!selectedKeys.includes(item.key)) {
|
|
252
|
+
selectedKeys.push(item.key);
|
|
253
|
+
}
|
|
284
254
|
}
|
|
255
|
+
return selectedKeys;
|
|
285
256
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return item;
|
|
257
|
+
get #activeItem() {
|
|
258
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
259
|
+
const item = this.#items[i];
|
|
260
|
+
if (item.isActive) {
|
|
261
|
+
return item;
|
|
262
|
+
}
|
|
293
263
|
}
|
|
294
264
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
265
|
+
#clearSeaerch() {
|
|
266
|
+
this.searchKeys = '';
|
|
267
|
+
}
|
|
268
|
+
#clearActive() {
|
|
269
|
+
for (let i = 0; i < this.#items.length; i++) {
|
|
270
|
+
const item = this.#items[i];
|
|
271
|
+
if (item.isActive) {
|
|
272
|
+
item.isActive = false;
|
|
273
|
+
}
|
|
304
274
|
}
|
|
305
275
|
}
|
|
276
|
+
setup = modifier((_el, _, args) => {
|
|
277
|
+
this.updateArgs({
|
|
278
|
+
selectionMode: args.selectionMode,
|
|
279
|
+
disabledKeys: args.disabledKeys,
|
|
280
|
+
selectedKeys: args.selectedKeys,
|
|
281
|
+
allowEmpty: args.allowEmpty,
|
|
282
|
+
autoActivateMode: args.autoActivateMode
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
setupItem = modifier((el, _, args) => {
|
|
286
|
+
let textValue = args.textValue;
|
|
287
|
+
if (typeof textValue === 'undefined' || textValue === '' || textValue === null) {
|
|
288
|
+
const labelId = el.getAttribute('aria-labelledby');
|
|
289
|
+
if (labelId) {
|
|
290
|
+
const labelElement = el.querySelector(`#${labelId}`);
|
|
291
|
+
if (labelElement) {
|
|
292
|
+
textValue = labelElement.textContent?.trim() || '';
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
textValue = el.textContent?.trim() || '';
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
this.register(el, {
|
|
299
|
+
key: args.key,
|
|
300
|
+
textValue: textValue || '',
|
|
301
|
+
isActive: false,
|
|
302
|
+
isDisabled: this.isKeyDisabled(args.key),
|
|
303
|
+
isSelected: this.isKeySelected(args.key)
|
|
304
|
+
});
|
|
305
|
+
const item = this.at(el);
|
|
306
|
+
if (item && typeof args.onRegister === 'function') {
|
|
307
|
+
args.onRegister(item);
|
|
308
|
+
}
|
|
309
|
+
const mouseEnter = () => {
|
|
310
|
+
this.activateItem(item);
|
|
311
|
+
};
|
|
312
|
+
const mouseLeave = () => {
|
|
313
|
+
if (item) {
|
|
314
|
+
item.isActive = false;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
if (!args.disableEvents) {
|
|
318
|
+
el.addEventListener('mouseenter', mouseEnter);
|
|
319
|
+
el.addEventListener('mouseleave', mouseLeave);
|
|
320
|
+
el.addEventListener('focusin', mouseEnter);
|
|
321
|
+
el.addEventListener('focusout', mouseLeave);
|
|
322
|
+
}
|
|
323
|
+
return () => {
|
|
324
|
+
this.unregister(el);
|
|
325
|
+
if (!args.disableEvents) {
|
|
326
|
+
el.removeEventListener('mouseenter', mouseEnter);
|
|
327
|
+
el.removeEventListener('mouseleave', mouseLeave);
|
|
328
|
+
el.removeEventListener('focusin', mouseEnter);
|
|
329
|
+
el.removeEventListener('focusout', mouseLeave);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
});
|
|
306
333
|
}
|
|
307
334
|
function keyAndLabelForItem(item) {
|
|
335
|
+
// Handle primitive types directly
|
|
308
336
|
if (typeof item === 'string' || typeof item === 'number') {
|
|
337
|
+
const value = item.toString();
|
|
309
338
|
return {
|
|
310
|
-
key:
|
|
311
|
-
label:
|
|
339
|
+
key: value,
|
|
340
|
+
label: value
|
|
312
341
|
};
|
|
313
|
-
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// If the item is an object, try to extract key and label using common property names
|
|
345
|
+
if (typeof item === 'object' && item !== null) {
|
|
346
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
314
347
|
const typedItem = item;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
348
|
+
|
|
349
|
+
// Try to use the 'key' property first; if not available, use 'id'
|
|
350
|
+
let keyProp = typedItem.key || typedItem.id;
|
|
351
|
+
if (keyProp === undefined) {
|
|
352
|
+
keyProp = item.toString();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Determine the label by checking multiple possible properties
|
|
356
|
+
let labelProp = typedItem.label || typedItem.value || typedItem.name || typedItem.title;
|
|
357
|
+
if (labelProp === undefined) {
|
|
358
|
+
labelProp = item.toString();
|
|
325
359
|
}
|
|
360
|
+
return {
|
|
361
|
+
key: keyProp.toString(),
|
|
362
|
+
label: labelProp.toString()
|
|
363
|
+
};
|
|
326
364
|
}
|
|
365
|
+
|
|
366
|
+
// Fallback if item does not match expected types
|
|
327
367
|
return {
|
|
328
368
|
key: '',
|
|
329
369
|
label: ''
|