@cntwg/html-ctrls-lists 0.0.31 → 0.0.33
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/CHANGELOG.md +16 -0
- package/doc/html-ctrls-list.md +11 -10
- package/index.d.ts +32 -0
- package/index.js +27 -6
- package/lib/list-cont.d.ts +207 -0
- package/lib/list-cont.js +538 -0
- package/lib/list-ctrl.d.ts +85 -0
- package/lib/{list.js → list-ctrl.js} +74 -545
- package/lib/lists-btn.d.ts +63 -0
- package/lib/lists-btn.js +5 -10
- package/lib/lists-stubs.d.ts +134 -0
- package/lib/lists-stubs.js +37 -21
- package/lib/mod-hfunc.d.ts +18 -0
- package/lib/mod-hfunc.js +11 -3
- package/package.json +12 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.
|
|
1
|
+
// [v0.2.091-20260510]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -8,20 +8,22 @@ const {
|
|
|
8
8
|
} = require('@ygracs/bsfoc-lib-js');
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
|
-
|
|
12
|
-
} = require('@ygracs/lists-lib-js');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
isHTMLElement, isSelectedHTMLElement, isHiddenHTMLElement,
|
|
11
|
+
isHTMLElement,
|
|
16
12
|
showHTMLElement, hideHTMLElement,
|
|
17
13
|
selectHTMLElement, unselectHTMLElement,
|
|
18
|
-
markHTMLElementAsCurrent, unmarkCurrentHTMLElement,
|
|
19
|
-
readAsAttrValue, valueToClassList,
|
|
20
14
|
eventHelper, // [!] not oficialy exported yet
|
|
21
15
|
CSS_CLASS_STRING,
|
|
22
16
|
} = require('@cntwg/html-helper');
|
|
23
17
|
|
|
24
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
THtmlItemsListContainer,
|
|
20
|
+
} = require('./list-cont');
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
THtmlStubItemsSet,
|
|
24
|
+
// * import types definitions *
|
|
25
|
+
IStubItemsSetOptions,
|
|
26
|
+
} = require('./lists-stubs');
|
|
25
27
|
|
|
26
28
|
// === module inner block ===
|
|
27
29
|
|
|
@@ -33,511 +35,37 @@ const {
|
|
|
33
35
|
CSS_CLASS_DISABLED,
|
|
34
36
|
} = CSS_CLASS_STRING;
|
|
35
37
|
|
|
36
|
-
/**
|
|
37
|
-
* Searches an element in a list by a given attributes of that element.
|
|
38
|
-
* @function srchListElementByAttr
|
|
39
|
-
* @param {TItemsListEx} list
|
|
40
|
-
* @param {string} name - target attribute name
|
|
41
|
-
* @param {string} [value=""] - target attribute value
|
|
42
|
-
* @returns {object}
|
|
43
|
-
* @inner
|
|
44
|
-
*/
|
|
45
|
-
function srchListElementByAttr(list, name, value = '') {
|
|
46
|
-
const _value = readAsAttrValue(value);
|
|
47
|
-
let item = null;
|
|
48
|
-
let index = -1;
|
|
49
|
-
let count = list.count;
|
|
50
|
-
let isACCEPTED = false;
|
|
51
|
-
if (count > 0 && name !== '' && _value !== null) {
|
|
52
|
-
const acceptAnyVal = _value === '';
|
|
53
|
-
for (let i = 0; i < count; i++) {
|
|
54
|
-
item = list.getItem(i);
|
|
55
|
-
if (
|
|
56
|
-
isHTMLElement(item)
|
|
57
|
-
&& item.hasAttribute(name)
|
|
58
|
-
&& (acceptAnyVal || item.getAttribute(name) === value)
|
|
59
|
-
) {
|
|
60
|
-
index = i;
|
|
61
|
-
isACCEPTED = true;
|
|
62
|
-
break;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
return isACCEPTED ? { index, item } : { index, item: null };
|
|
67
|
-
};
|
|
68
|
-
|
|
69
38
|
// === module main block ===
|
|
70
39
|
|
|
71
40
|
const ILC_SMODE_DEF = 0;
|
|
72
41
|
const ILC_SMODE_SHFT = 1;
|
|
73
42
|
const ILC_SMODE_CTRL = 2;
|
|
74
43
|
|
|
75
|
-
|
|
76
|
-
* An options set for `THtmlItemsListContainer`-class
|
|
77
|
-
* @typedef {Object} OPT_hlconsett
|
|
78
|
-
* @property {boolean} [autoHideNewItems=false] - indicates whether to hide
|
|
79
|
-
* a new element
|
|
80
|
-
* @property {boolean} [markCurrentItem=false] - indicates whether to mark
|
|
81
|
-
* a current element
|
|
82
|
-
* @property {(string|string[])} [itemBaseClassID] - contains a base class
|
|
83
|
-
* attributes applayed to each a newly added list member
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @classdesc This class implements an interfaco for a list container
|
|
88
|
-
*/
|
|
89
|
-
class THtmlItemsListContainer {
|
|
90
|
-
/** @type {?HTMLElement} */
|
|
91
|
-
#_host;
|
|
92
|
-
/** @type {TItemsListEx} */
|
|
93
|
-
#_items;
|
|
94
|
-
/** @type {OPT_hlconsett} */
|
|
95
|
-
#_options;
|
|
96
|
-
/**
|
|
97
|
-
* A container status
|
|
98
|
-
* @typedef {Object} statILCont
|
|
99
|
-
* @property {number} curIndex
|
|
100
|
-
* @property {?HTMLElement} curItem
|
|
101
|
-
* @inner
|
|
102
|
-
*/
|
|
103
|
-
/** @type {statILCont} */
|
|
104
|
-
#_status;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Creates an instance of a list container
|
|
108
|
-
* @param {HTMLElement} host - host element
|
|
109
|
-
* @param {OPT_hlconsett} [opt] - options
|
|
110
|
-
*/
|
|
111
|
-
constructor(host, opt) {
|
|
112
|
-
// check host
|
|
113
|
-
this.#_host = isHTMLElement(host) ? host : null;
|
|
114
|
-
// init items container
|
|
115
|
-
const _items = new TItemsListEx();
|
|
116
|
-
this.#_items = _items;
|
|
117
|
-
// load options
|
|
118
|
-
/** @type {OPT_hlconsett} */
|
|
119
|
-
const _options = isPlainObject(opt) ? opt : {};
|
|
120
|
-
let {
|
|
121
|
-
autoHideNewItems,
|
|
122
|
-
markCurrentItem,
|
|
123
|
-
itemBaseClassID,
|
|
124
|
-
} = _options;
|
|
125
|
-
if (typeof autoHideNewItems !== 'boolean') {
|
|
126
|
-
_options.autoHideNewItems = autoHideNewItems = false;
|
|
127
|
-
};
|
|
128
|
-
if (typeof markCurrentItem !== 'boolean') {
|
|
129
|
-
_options.markCurrentItem = markCurrentItem = false;
|
|
130
|
-
};
|
|
131
|
-
itemBaseClassID = valueToClassList(itemBaseClassID, true);
|
|
132
|
-
_options.itemBaseClassID = itemBaseClassID;
|
|
133
|
-
// init status
|
|
134
|
-
/** @type {statILCont} */
|
|
135
|
-
const _status = {
|
|
136
|
-
curIndex: _items.curIndex,
|
|
137
|
-
curItem: _items.curItem,
|
|
138
|
-
};
|
|
139
|
-
this.#_status = _status;
|
|
140
|
-
// save options
|
|
141
|
-
this.#_options = _options;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
[Symbol.iterator]() {
|
|
145
|
-
let index = 0;
|
|
146
|
-
return {
|
|
147
|
-
next: () => {
|
|
148
|
-
if (index < this.count) {
|
|
149
|
-
return { done: false, value: this.getItem(index++) };
|
|
150
|
-
} else {
|
|
151
|
-
return { done: true, value: undefined };
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
return() {
|
|
155
|
-
return { done: true, value: undefined };
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Contains a Qty of an elements
|
|
162
|
-
* @type {number}
|
|
163
|
-
* @readonly
|
|
164
|
-
*/
|
|
165
|
-
get count() {
|
|
166
|
-
return this.#_items.count;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Contains an index of the current element
|
|
171
|
-
* @type {number}
|
|
172
|
-
* @readonly
|
|
173
|
-
*/
|
|
174
|
-
get curIndex() {
|
|
175
|
-
return this.#_items.curIndex;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Returns a minimum value of an index
|
|
180
|
-
* @type {number}
|
|
181
|
-
* @readonly
|
|
182
|
-
*/
|
|
183
|
-
get minIndex() {
|
|
184
|
-
return this.#_items.minIndex;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Returns a maximum value of an index
|
|
189
|
-
* @type {number}
|
|
190
|
-
* @readonly
|
|
191
|
-
*/
|
|
192
|
-
get maxIndex() {
|
|
193
|
-
return this.#_items.maxIndex;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Returns a value of a previous index
|
|
198
|
-
* @type {number}
|
|
199
|
-
* @readonly
|
|
200
|
-
*/
|
|
201
|
-
get prevIndex() {
|
|
202
|
-
return this.#_items.prevIndex;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Returns a value of a next index
|
|
207
|
-
* @type {number}
|
|
208
|
-
* @readonly
|
|
209
|
-
*/
|
|
210
|
-
get nextIndex() {
|
|
211
|
-
return this.#_items.nextIndex;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Returns an element in the current index
|
|
216
|
-
* @type {?HTMLElement}
|
|
217
|
-
* @readonly
|
|
218
|
-
*/
|
|
219
|
-
get curItem() {
|
|
220
|
-
const item = this.#_items.curItem;
|
|
221
|
-
return isHTMLElement(item) ? item : null;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Clears an instance content.
|
|
226
|
-
* @returns {void}
|
|
227
|
-
*/
|
|
228
|
-
clear() {
|
|
229
|
-
this.#_items.clear();
|
|
230
|
-
const _status = this.#_status;
|
|
231
|
-
_status.curIndex = this.curIndex;
|
|
232
|
-
_status.curItem = this.curItem;
|
|
233
|
-
const _host = this.#_host;
|
|
234
|
-
if (_host) _host.innerHTML = '';
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Checks if an instance contains no items.
|
|
239
|
-
* @returns {boolean}
|
|
240
|
-
*/
|
|
241
|
-
isEmpty() {
|
|
242
|
-
return this.#_items.isEmpty();
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Checks if an instance contains any items.
|
|
247
|
-
* @returns {boolean}
|
|
248
|
-
*/
|
|
249
|
-
isNotEmpty() {
|
|
250
|
-
return this.#_items.isNotEmpty();
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Checks if a given value is a valid index and
|
|
255
|
-
* it fits an index range within an instance.
|
|
256
|
-
* @param {number|string} value - index value
|
|
257
|
-
* @returns {boolean}
|
|
258
|
-
* @deprecated
|
|
259
|
-
* @todo \[since v0.0.3x] deprecated. Use
|
|
260
|
-
* {@link THtmlItemsListContainer.checkIndex} instead
|
|
261
|
-
*/
|
|
262
|
-
chkIndex(value) {
|
|
263
|
-
return this.#_items.checkIndex(value);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Checks if a given value is a valid index and
|
|
268
|
-
* it fits an index range within an instance.
|
|
269
|
-
* @since 0.0.3x
|
|
270
|
-
* @param {number|string} value - index value
|
|
271
|
-
* @returns {boolean}
|
|
272
|
-
*/
|
|
273
|
-
checkIndex(value) {
|
|
274
|
-
return this.#_items.checkIndex(value);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Checks if a given value is a valid index and
|
|
279
|
-
* it fits an index range within an instance.
|
|
280
|
-
* @param {number|string} value - value to check
|
|
281
|
-
* @param {boolean} [opt=false] - defines a type of result
|
|
282
|
-
* @returns {boolean|number}
|
|
283
|
-
* @see TItemsListEx.chkIndexEx
|
|
284
|
-
* @todo \[since v0.0.3x] deprecated. Use
|
|
285
|
-
* {@link THtmlItemsListContainer.checkIndex} or
|
|
286
|
-
* {@link THtmlItemsListContainer.tryIndex} instead
|
|
287
|
-
*/
|
|
288
|
-
chkIndexEx(value, opt) {
|
|
289
|
-
return opt ? this.#_items.tryIndex(value) : this.#_items.checkIndex(value);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Returns an index in case a given value is a valid index value and not exceeds
|
|
294
|
-
* an index range within the list. If failed a `-1` returned
|
|
295
|
-
* @since 0.0.3x
|
|
296
|
-
* @param {any} value - value to evaluate
|
|
297
|
-
* @returns {number}
|
|
298
|
-
*/
|
|
299
|
-
tryIndex(value) {
|
|
300
|
-
return this.#_items.tryIndex(value);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Returns an index of a given element.
|
|
305
|
-
* @param {HTMLElement} item - element to search
|
|
306
|
-
* @returns {number}
|
|
307
|
-
* @todo add 2nd param
|
|
308
|
-
* @see TItemsListEx.srchIndex
|
|
309
|
-
*/
|
|
310
|
-
srchIndex(item) {
|
|
311
|
-
return isHTMLElement(item) ? this.#_items.srchIndex(item) : -1;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Returns an index of an element wich has an attribute
|
|
316
|
-
* with a given name and value.
|
|
317
|
-
* @param {string} name - attribute name
|
|
318
|
-
* @param {any} [value=""] - attribute value
|
|
319
|
-
* @returns {number}
|
|
320
|
-
*/
|
|
321
|
-
srchIndexByAttr(name, value = '') {
|
|
322
|
-
const _name = typeof name === 'string' ? name.trim() : '';
|
|
323
|
-
const { index } = srchListElementByAttr(this.#_items, _name, value);
|
|
324
|
-
return index;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Returns an index of an element wich has a given ID.
|
|
329
|
-
* @param {string} value - element ID
|
|
330
|
-
* @returns {number}
|
|
331
|
-
*/
|
|
332
|
-
srchIndexByID(value) {
|
|
333
|
-
const { index } = srchListElementByAttr(this.#_items, 'id', value);
|
|
334
|
-
return index;
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Sets a current index.
|
|
339
|
-
* @param {(number|string)} index - element index
|
|
340
|
-
* @returns {boolean}
|
|
341
|
-
*/
|
|
342
|
-
setCurIndex(index) {
|
|
343
|
-
const isSUCCEED = this.#_items.setIndex(index);
|
|
344
|
-
if (isSUCCEED) {
|
|
345
|
-
const markCurrentItem = this.#_options.markCurrentItem;
|
|
346
|
-
const _status = this.#_status;
|
|
347
|
-
if (markCurrentItem && _status.curIndex !== -1) {
|
|
348
|
-
unmarkCurrentHTMLElement(_status.curItem);
|
|
349
|
-
};
|
|
350
|
-
const item = this.getItem(index);
|
|
351
|
-
_status.curIndex = Number(index);
|
|
352
|
-
_status.curItem = item;
|
|
353
|
-
if (markCurrentItem) markHTMLElementAsCurrent(item);
|
|
354
|
-
};
|
|
355
|
-
return isSUCCEED;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Resets a current index.
|
|
360
|
-
* @returns {void}
|
|
361
|
-
*/
|
|
362
|
-
rstCurIndex() {
|
|
363
|
-
const _status = this.#_status;
|
|
364
|
-
if (this.#_options.markCurrentItem && _status.curIndex !== -1) {
|
|
365
|
-
unmarkCurrentHTMLElement(_status.curItem);
|
|
366
|
-
};
|
|
367
|
-
this.#_items.rstIndex();
|
|
368
|
-
_status.curIndex = this.#_items.curIndex;
|
|
369
|
-
_status.curItem = this.curItem;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Returns an item addressed by a given index.
|
|
374
|
-
* @param {(number|string)} index - element index
|
|
375
|
-
* @returns {?HTMLElement}
|
|
376
|
-
*/
|
|
377
|
-
getItem(index) {
|
|
378
|
-
const item = this.#_items.getItem(index);
|
|
379
|
-
return isHTMLElement(item) ? item : null;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Returns an item wich has an attribute with a given name and value.
|
|
384
|
-
* @param {string} name - attribute name
|
|
385
|
-
* @param {any} [value=""] - attribute value
|
|
386
|
-
* @returns {?HTMLElement}
|
|
387
|
-
*/
|
|
388
|
-
getItemByAttr(name, value = '') {
|
|
389
|
-
const _name = typeof name === 'string' ? name.trim() : '';
|
|
390
|
-
const { item } = srchListElementByAttr(this.#_items, _name, value);
|
|
391
|
-
return item;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Returns an item wich has a given ID.
|
|
396
|
-
* @param {string} value - element ID
|
|
397
|
-
* @returns {?HTMLElement}
|
|
398
|
-
*/
|
|
399
|
-
getItemByID(value) {
|
|
400
|
-
const { item } = srchListElementByAttr(this.#_items, 'id', value);
|
|
401
|
-
return item;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Adds an item to an instance.
|
|
406
|
-
* @param {HTMLElement} item - some element
|
|
407
|
-
* @param {boolean} [opt=false] - indicates whether to correct a current index
|
|
408
|
-
* @returns {number}
|
|
409
|
-
*/
|
|
410
|
-
addItem(item, opt) {
|
|
411
|
-
const forceCI = typeof opt === 'boolean' ? opt : false;
|
|
412
|
-
const index = (
|
|
413
|
-
isHTMLElement(item)
|
|
414
|
-
? this.#_items.addItemEx(item, false)
|
|
415
|
-
: -1
|
|
416
|
-
);
|
|
417
|
-
const isSUCCEED = index !== -1;
|
|
418
|
-
if (isSUCCEED) {
|
|
419
|
-
const { autoHideNewItems, itemBaseClassID } = this.#_options;
|
|
420
|
-
if (autoHideNewItems) hideHTMLElement(item);
|
|
421
|
-
if (itemBaseClassID.length > 0) item.classList.add(...itemBaseClassID);
|
|
422
|
-
if (forceCI) this.setCurIndex(index);
|
|
423
|
-
const _host = this.#_host;
|
|
424
|
-
if (_host) _host.append(item);
|
|
425
|
-
};
|
|
426
|
-
return isSUCCEED ? index : -1;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Deletes an item from an instance.
|
|
431
|
-
* @param {(number|string)} index - element index
|
|
432
|
-
* @param {any} [opt]
|
|
433
|
-
* @param {boolean} [optEx=true]
|
|
434
|
-
* @returns {boolean}
|
|
435
|
-
*/
|
|
436
|
-
delItem(index, opt, optEx) {
|
|
437
|
-
const _items = this.#_items;
|
|
438
|
-
const item = _items.delItemEx(index, opt);
|
|
439
|
-
const isSUCCEED = item !== undefined;
|
|
440
|
-
if (isSUCCEED) {
|
|
441
|
-
if (this.#_host && isHTMLElement(item)) item.remove();
|
|
442
|
-
const doProcEx = typeof optEx === 'boolean' ? optEx : true;
|
|
443
|
-
if (doProcEx) {
|
|
444
|
-
const index = _items.curIndex;
|
|
445
|
-
if (index === -1) {
|
|
446
|
-
this.rstCurIndex();
|
|
447
|
-
} else {
|
|
448
|
-
this.setCurIndex(index);
|
|
449
|
-
};
|
|
450
|
-
};
|
|
451
|
-
};
|
|
452
|
-
return isSUCCEED;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Selects an item addressed by a given index.
|
|
457
|
-
* @param {(number|string)} index - element index
|
|
458
|
-
* @param {boolean} [opt=false] - indicates whether to correct a current index
|
|
459
|
-
* @returns {boolean}
|
|
460
|
-
*/
|
|
461
|
-
selectItem(index, opt) {
|
|
462
|
-
const forceCI = typeof opt === 'boolean' ? opt : false;
|
|
463
|
-
const isSUCCEED = selectHTMLElement(this.#_items.getItem(index));
|
|
464
|
-
if (isSUCCEED && forceCI) this.setCurIndex(index);
|
|
465
|
-
return isSUCCEED;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Unselects an item addressed by a given index.
|
|
470
|
-
* @param {(number|string)} index - element index
|
|
471
|
-
* @returns {boolean}
|
|
472
|
-
*/
|
|
473
|
-
unselectItem(index) {
|
|
474
|
-
return unselectHTMLElement(this.#_items.getItem(index));
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Hides an item addressed by a given index.
|
|
479
|
-
* @param {(number|string)} index - element index
|
|
480
|
-
* @returns {boolean}
|
|
481
|
-
*/
|
|
482
|
-
hideItem(index) {
|
|
483
|
-
return hideHTMLElement(this.#_items.getItem(index));
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Shows an item addressed by a given index.
|
|
488
|
-
* @param {(number|string)} index - element index
|
|
489
|
-
* @returns {boolean}
|
|
490
|
-
*/
|
|
491
|
-
showItem(index) {
|
|
492
|
-
return showHTMLElement(this.#_items.getItem(index));
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Checks whether an item is selected.
|
|
497
|
-
* @param {(number|string)} index - element index
|
|
498
|
-
* @returns {boolean}
|
|
499
|
-
*/
|
|
500
|
-
isSelectedItem(index) {
|
|
501
|
-
return isSelectedHTMLElement(this.#_items.getItem(index));
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Checks whether an item is hidden.
|
|
506
|
-
* @param {(number|string)} index - element index
|
|
507
|
-
* @returns {boolean}
|
|
508
|
-
*/
|
|
509
|
-
isHiddenItem(index) {
|
|
510
|
-
return isHiddenHTMLElement(this.#_items.getItem(index));
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
exports.THtmlItemsListContainer = THtmlItemsListContainer;
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* A an options set for a `THtmlStubItemsSet`-class constructor
|
|
518
|
-
* @typedef {Object} OPT_stubconsett
|
|
519
|
-
* @property {(any[])} items - array of `name`-`element` pairs
|
|
520
|
-
* @property {string} [defaultItem] - a default element name
|
|
521
|
-
* @property {boolean} [force=false] - run in a force mode
|
|
522
|
-
*/
|
|
523
|
-
|
|
44
|
+
// // NOTE: @extends ITHtmlItemsListContainerOptions
|
|
524
45
|
/**
|
|
525
46
|
* An options set for `THtmlItemsListController`-class
|
|
526
|
-
* @typedef {Object}
|
|
47
|
+
* @typedef {Object} IHtmlItemsListControllerOptions
|
|
527
48
|
* @property {boolean} [autoHideNewItems=false] - indicates whether to hide
|
|
528
49
|
* a new element
|
|
529
50
|
* @property {boolean} [markCurrentItem=false] - indicates whether to mark
|
|
530
51
|
* a current element
|
|
531
|
-
* @property {
|
|
52
|
+
* @property {string|string[]} [itemBaseClassID] - contains a base class
|
|
532
53
|
* attributes applayed to each a newly added list member
|
|
54
|
+
* @property {number|string} [targetScopeForEID] - \[since v0.0.33] indicates
|
|
55
|
+
* a target scope chosen to select an ID-attribute of the element
|
|
533
56
|
* @property {boolean} [showStubsIfEmpty=false] - indicates whether to show
|
|
534
57
|
* stubs if empty
|
|
535
58
|
* @property {boolean} [allowGroupSelection=false] - indicates whether
|
|
536
59
|
* a selection of the elements group is allowed
|
|
537
60
|
* @property {boolean} [allowSelectionLocks=false] - indicates whether locking
|
|
538
61
|
* of an element selection is allowed
|
|
539
|
-
* @property {
|
|
62
|
+
* @property {IStubItemsSetOptions} [stubs] - stub elements options
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* A virtual constant meant for support jsdoc notation:
|
|
66
|
+
* @type {IHtmlItemsListControllerOptions}
|
|
540
67
|
*/
|
|
68
|
+
module.exports.IHtmlItemsListControllerOptions = {};
|
|
541
69
|
|
|
542
70
|
/**
|
|
543
71
|
* @augments THtmlItemsListContainer
|
|
@@ -551,7 +79,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
551
79
|
#_stubs;
|
|
552
80
|
/** @type {Set<HTMLElement>} */
|
|
553
81
|
#_selects;
|
|
554
|
-
/** @property {
|
|
82
|
+
/** @property {IHtmlItemsListControllerOptions} */
|
|
555
83
|
#_options;// = null;
|
|
556
84
|
/**
|
|
557
85
|
* A controler status
|
|
@@ -573,17 +101,15 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
573
101
|
/**
|
|
574
102
|
* Creates a new instance of the class.
|
|
575
103
|
* @param {?HTMLElement} host - host element
|
|
576
|
-
* @param {
|
|
104
|
+
* @param {IHtmlItemsListControllerOptions} [opt] - options
|
|
577
105
|
*/
|
|
578
106
|
constructor(host, opt) {
|
|
579
|
-
// check host element
|
|
580
|
-
const isHostEnabled = isHTMLElement(host);
|
|
581
|
-
const _host = isHostEnabled ? host : null;
|
|
582
107
|
// check options
|
|
583
|
-
/** @type {OPT_hlctlsett} */
|
|
584
108
|
const _options = isPlainObject(opt) ? opt : {};
|
|
585
109
|
// call parent constructor
|
|
586
|
-
super(
|
|
110
|
+
super(host, _options);
|
|
111
|
+
// check host
|
|
112
|
+
const _host = this.#_host = isHTMLElement(host) ? host : null;
|
|
587
113
|
// load options
|
|
588
114
|
let {
|
|
589
115
|
//autoHideNewItems, // [*] processed by parent
|
|
@@ -595,17 +121,24 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
595
121
|
stubs: stubsList,
|
|
596
122
|
} = _options;
|
|
597
123
|
if (typeof showStubsIfEmpty !== 'boolean') {
|
|
598
|
-
|
|
124
|
+
showStubsIfEmpty = false;
|
|
125
|
+
// // TODO: next line planned to be removed
|
|
126
|
+
_options.showStubsIfEmpty = showStubsIfEmpty;
|
|
599
127
|
};
|
|
600
128
|
if (typeof allowGroupSelection !== 'boolean') {
|
|
601
|
-
|
|
129
|
+
allowGroupSelection = false;
|
|
130
|
+
// // TODO: next line planned to be removed
|
|
131
|
+
_options.allowGroupSelection = allowGroupSelection;
|
|
602
132
|
};
|
|
603
133
|
if (typeof allowSelectionLocks !== 'boolean') {
|
|
604
|
-
|
|
134
|
+
allowSelectionLocks = false;
|
|
135
|
+
// // TODO: next line planned to be removed
|
|
136
|
+
_options.allowSelectionLocks = allowSelectionLocks;
|
|
605
137
|
};
|
|
606
138
|
// save options
|
|
607
139
|
this.#_options = _options;
|
|
608
140
|
// init status flags set
|
|
141
|
+
const isHostEnabled = isHTMLElement(_host);
|
|
609
142
|
/** @type {statILCtrl} */
|
|
610
143
|
const _status = {
|
|
611
144
|
isSelectionLocked: false,
|
|
@@ -616,8 +149,6 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
616
149
|
execDelItemDI: -1,
|
|
617
150
|
execDelItemCI: -1,
|
|
618
151
|
}
|
|
619
|
-
// bind ref to host
|
|
620
|
-
this.#_host = _host;
|
|
621
152
|
// init stub items set
|
|
622
153
|
this.#_stubs = new THtmlStubItemsSet(_host, stubsList);
|
|
623
154
|
// init index of selected items
|
|
@@ -635,9 +166,8 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
635
166
|
}
|
|
636
167
|
|
|
637
168
|
/**
|
|
638
|
-
* @param {
|
|
169
|
+
* @param {UIEvent} e - event
|
|
639
170
|
* @returns {void}
|
|
640
|
-
* @private
|
|
641
171
|
*/
|
|
642
172
|
#_on_will_select_item = (e) => {
|
|
643
173
|
//console.log('THtmlItemsListController._on_will_select_item() ==> was called...');
|
|
@@ -680,6 +210,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
680
210
|
//console.log(`CHECK: e => tag:[${curItem.tagName}]`);
|
|
681
211
|
if (host) {
|
|
682
212
|
// find an actual list element in case when some inner element was clicking
|
|
213
|
+
/** @type {?HTMLElement} */
|
|
683
214
|
let tmpItem = curItem;
|
|
684
215
|
while (tmpItem) {
|
|
685
216
|
//console.log(`CHECK: e => target.tag:[${tmpItem.tagName}]`);
|
|
@@ -702,7 +233,6 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
702
233
|
* @param {string} name - event name
|
|
703
234
|
* @param {...any} args
|
|
704
235
|
* @returns {void}
|
|
705
|
-
* @private
|
|
706
236
|
* @see triggerEventHandler
|
|
707
237
|
*/
|
|
708
238
|
#_triggerEvent = (name, ...args) => {
|
|
@@ -782,10 +312,9 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
782
312
|
|
|
783
313
|
/**
|
|
784
314
|
* Sets a current index.
|
|
785
|
-
* @param {
|
|
315
|
+
* @param {number|string} index - element index
|
|
786
316
|
* @returns {boolean}
|
|
787
317
|
* @fires THtmlItemsListController#current-item-chosen
|
|
788
|
-
* @private
|
|
789
318
|
*/
|
|
790
319
|
#_setCurIndex(index) {
|
|
791
320
|
const isSUCCEED = super.setCurIndex(index);
|
|
@@ -804,7 +333,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
804
333
|
|
|
805
334
|
/**
|
|
806
335
|
* Sets a current index.
|
|
807
|
-
* @param {
|
|
336
|
+
* @param {number|string} index - element index
|
|
808
337
|
* @returns {boolean}
|
|
809
338
|
*/
|
|
810
339
|
setCurIndex(index) {
|
|
@@ -896,7 +425,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
896
425
|
|
|
897
426
|
/**
|
|
898
427
|
* Deletes an element from an instance members.
|
|
899
|
-
* @param {
|
|
428
|
+
* @param {number|string} index - element index
|
|
900
429
|
* @param {any} [opt]
|
|
901
430
|
* @returns {boolean}
|
|
902
431
|
* @fires THtmlItemsListController#list-clear
|
|
@@ -956,15 +485,14 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
956
485
|
|
|
957
486
|
/**
|
|
958
487
|
* Selects an element.
|
|
959
|
-
* @param {
|
|
488
|
+
* @param {number|string} index - element index
|
|
960
489
|
* @returns {boolean}
|
|
961
|
-
* @private
|
|
962
490
|
* @fires THtmlItemsListController#item-selected
|
|
963
491
|
*/
|
|
964
492
|
#_selectItem(index) {
|
|
965
493
|
const item = super.getItem(index);
|
|
966
|
-
|
|
967
|
-
if (
|
|
494
|
+
let isSucceed = false;
|
|
495
|
+
if (item && (isSucceed = selectHTMLElement(item))) {
|
|
968
496
|
this.#_selects.add(item);
|
|
969
497
|
/**
|
|
970
498
|
* @event THtmlItemsListController#item-selected
|
|
@@ -977,18 +505,22 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
977
505
|
item: item,
|
|
978
506
|
});
|
|
979
507
|
};
|
|
980
|
-
return
|
|
508
|
+
return isSucceed;
|
|
981
509
|
}
|
|
982
510
|
|
|
511
|
+
/**
|
|
512
|
+
*
|
|
513
|
+
* @typedef {Object} OPT_selectStat
|
|
514
|
+
* @property {boolean} [ctrlKey=false]
|
|
515
|
+
* @property {boolean} [shiftKey=false]
|
|
516
|
+
* @property {boolean} [forceCI=false]
|
|
517
|
+
*/
|
|
518
|
+
|
|
983
519
|
/**
|
|
984
520
|
* Selects an element.
|
|
985
|
-
* @param {
|
|
986
|
-
* @param {
|
|
987
|
-
* @param {boolean} [opt.ctrlKey=false]
|
|
988
|
-
* @param {boolean} [opt.shiftKey=false]
|
|
989
|
-
* @param {boolean} [opt.forceCI=false]
|
|
521
|
+
* @param {HTMLElement} item - element
|
|
522
|
+
* @param {OPT_selectStat} opt - select options
|
|
990
523
|
* @returns {void}
|
|
991
|
-
* @private
|
|
992
524
|
*/
|
|
993
525
|
#_selectItemEx(item, opt){
|
|
994
526
|
const _selects = this.#_selects;
|
|
@@ -1044,34 +576,35 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
1044
576
|
|
|
1045
577
|
/**
|
|
1046
578
|
* Selects an element.
|
|
1047
|
-
* @param {
|
|
579
|
+
* @param {number|string} index - element index
|
|
1048
580
|
* @param {boolean} [opt=false] - indicates whether to correct a current index
|
|
1049
581
|
* @returns {boolean}
|
|
1050
582
|
*/
|
|
1051
583
|
selectItem(index, opt) {
|
|
1052
584
|
const item = super.getItem(index);
|
|
1053
|
-
let
|
|
1054
|
-
if (
|
|
585
|
+
let isSucceed = false;
|
|
586
|
+
if (isHTMLElement(item)) {
|
|
1055
587
|
const forceCI = typeof opt === 'boolean' ? opt : false;
|
|
1056
588
|
this.#_selectItemEx(item, {
|
|
1057
589
|
ctrlKey: false,
|
|
1058
590
|
shiftKey: false,
|
|
1059
591
|
forceCI: forceCI,
|
|
1060
592
|
});
|
|
593
|
+
isSucceed = true;
|
|
1061
594
|
};
|
|
1062
|
-
return
|
|
595
|
+
return isSucceed;
|
|
1063
596
|
}
|
|
1064
597
|
|
|
1065
598
|
/**
|
|
1066
599
|
* Unselects an element.
|
|
1067
|
-
* @param {
|
|
600
|
+
* @param {number|string} index - element index
|
|
1068
601
|
* @returns {boolean}
|
|
1069
602
|
* @fires THtmlItemsListController#item-unselected
|
|
1070
603
|
*/
|
|
1071
604
|
unselectItem(index) {
|
|
1072
605
|
const item = super.getItem(index);
|
|
1073
|
-
let
|
|
1074
|
-
if (
|
|
606
|
+
let isSucceed = false;
|
|
607
|
+
if (item && (isSucceed = unselectHTMLElement(item))) {
|
|
1075
608
|
this.#_selects.delete(item);
|
|
1076
609
|
/**
|
|
1077
610
|
* @event THtmlItemsListController#item-unselected
|
|
@@ -1084,19 +617,19 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
1084
617
|
item: item,
|
|
1085
618
|
});
|
|
1086
619
|
};
|
|
1087
|
-
return
|
|
620
|
+
return isSucceed;
|
|
1088
621
|
}
|
|
1089
622
|
|
|
1090
623
|
/**
|
|
1091
624
|
* Hides an element.
|
|
1092
|
-
* @param {
|
|
625
|
+
* @param {number|string} index - element index
|
|
1093
626
|
* @returns {boolean}
|
|
1094
627
|
* @fires THtmlItemsListController#item-hidden
|
|
1095
628
|
*/
|
|
1096
629
|
hideItem(index) {
|
|
1097
630
|
const item = super.getItem(index);
|
|
1098
|
-
let
|
|
1099
|
-
if (
|
|
631
|
+
let isSucceed = false;
|
|
632
|
+
if (item && (isSucceed = hideHTMLElement(item))) {
|
|
1100
633
|
/**
|
|
1101
634
|
* @event THtmlItemsListController#item-hidden
|
|
1102
635
|
* @type {Object}
|
|
@@ -1108,19 +641,19 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
1108
641
|
item: item,
|
|
1109
642
|
});
|
|
1110
643
|
};
|
|
1111
|
-
return
|
|
644
|
+
return isSucceed;
|
|
1112
645
|
}
|
|
1113
646
|
|
|
1114
647
|
/**
|
|
1115
648
|
* Shows an element.
|
|
1116
|
-
* @param {
|
|
649
|
+
* @param {number|string} index - element index
|
|
1117
650
|
* @returns {boolean}
|
|
1118
651
|
* @fires THtmlItemsListController#item-shown
|
|
1119
652
|
*/
|
|
1120
653
|
showItem(index) {
|
|
1121
654
|
const item = super.getItem(index);
|
|
1122
|
-
let
|
|
1123
|
-
if (
|
|
655
|
+
let isSucceed = false;
|
|
656
|
+
if (item && (isSucceed = showHTMLElement(item))) {
|
|
1124
657
|
/**
|
|
1125
658
|
* @event THtmlItemsListController#item-shown
|
|
1126
659
|
* @type {Object}
|
|
@@ -1132,7 +665,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
1132
665
|
item: item,
|
|
1133
666
|
});
|
|
1134
667
|
};
|
|
1135
|
-
return
|
|
668
|
+
return isSucceed;
|
|
1136
669
|
}
|
|
1137
670
|
|
|
1138
671
|
/**
|
|
@@ -1146,8 +679,4 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
1146
679
|
}
|
|
1147
680
|
|
|
1148
681
|
};
|
|
1149
|
-
exports.THtmlItemsListController = THtmlItemsListController;
|
|
1150
|
-
|
|
1151
|
-
// === module exports block ===
|
|
1152
|
-
|
|
1153
|
-
exports.THtmlStubItemsSet = THtmlStubItemsSet;
|
|
682
|
+
module.exports.THtmlItemsListController = THtmlItemsListController;
|