@cntwg/html-helper 0.0.24 → 0.0.26

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,13 +1,17 @@
1
- // [v0.1.067-20241119]
1
+ // [v0.1.070-20250504]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
6
  readAsNumber,
7
7
  isPlainObject,
8
- TItemsListEx,
8
+ //TItemsListEx,
9
9
  } = require('@ygracs/bsfoc-lib-js');
10
10
 
11
+ const {
12
+ TItemsListEx,
13
+ } = require('@ygracs/lists-lib-js');
14
+
11
15
  const {
12
16
  isHTMLElement, isSelectedHTMLElement, isHiddenHTMLElement,
13
17
  showHTMLElement, hideHTMLElement,
@@ -85,15 +89,23 @@ const ILC_SMODE_CTRL = 2;
85
89
  * (* class definitions *)
86
90
  */
87
91
 
92
+ /**
93
+ * @typedef {Object} OPT_hlconsett
94
+ * @property {boolean} [autoHideNewItems=false]
95
+ * @property {boolean} [markCurrentItem=false]
96
+ * @property {(string|string[])} [itemBaseClassID]
97
+ * @description An options set for `THtmlItemsListContainer`-class
98
+ */
99
+
88
100
  /**
89
101
  * @classdesc This class implements an interfaco for a list container
90
102
  */
91
103
  class THtmlItemsListContainer {
92
- /** @property {?HTMLElement} */
104
+ /** @type {?HTMLElement} */
93
105
  #_host;
94
- /** @property {TItemsListEx} */
106
+ /** @type {TItemsListEx} */
95
107
  #_items;
96
- /** @property {object} */
108
+ /** @type {OPT_hlconsett} */
97
109
  #_options;// = null;
98
110
  /**
99
111
  * @typedef {Object} statILCont
@@ -102,15 +114,12 @@ class THtmlItemsListContainer {
102
114
  * @inner
103
115
  * @description A container status
104
116
  */
105
- /** @property {statILCont} */
117
+ /** @type {statILCont} */
106
118
  #_status;
107
119
 
108
120
  /**
109
121
  * @param {HTMLElement} host
110
- * @param {object} [opt]
111
- * @param {boolean} [opt.autoHideNewItems=false]
112
- * @param {boolean} [opt.markCurrentItem=false]
113
- * @param {(string|string[])} [opt.itemBaseClassID]
122
+ * @param {OPT_hlconsett} [opt] - options
114
123
  * @description Creates an instance of a list container
115
124
  */
116
125
  constructor(host, opt) {
@@ -120,6 +129,7 @@ class THtmlItemsListContainer {
120
129
  const _items = new TItemsListEx();
121
130
  this.#_items = _items;
122
131
  // load options
132
+ /** @type {OPT_hlconsett} */
123
133
  const _options = isPlainObject(opt) ? opt : {};
124
134
  let {
125
135
  autoHideNewItems,
@@ -146,63 +156,63 @@ class THtmlItemsListContainer {
146
156
  }
147
157
 
148
158
  /**
149
- * @property {number}
159
+ * Contains a Qty of an elements
160
+ * @type {number}
150
161
  * @readonly
151
- * @description Contains a Qty of an elements
152
162
  */
153
163
  get count() {
154
164
  return this.#_items.count;
155
165
  }
156
166
 
157
167
  /**
158
- * @property {number}
168
+ * Contains an of the current element
169
+ * @type {number}
159
170
  * @readonly
160
- * @description Contains an of the current element
161
171
  */
162
172
  get curIndex() {
163
173
  return this.#_items.curIndex;
164
174
  }
165
175
 
166
176
  /**
167
- * @property {number}
177
+ * Returns a minimum value of an index
178
+ * @type {number}
168
179
  * @readonly
169
- * @description Returns a minimum value of an index
170
180
  */
171
181
  get minIndex() {
172
182
  return this.#_items.minIndex;
173
183
  }
174
184
 
175
185
  /**
176
- * @property {number}
186
+ * Returns a maximum value of an index
187
+ * @type {number}
177
188
  * @readonly
178
- * @description Returns a maximum value of an index
179
189
  */
180
190
  get maxIndex() {
181
191
  return this.#_items.maxIndex;
182
192
  }
183
193
 
184
194
  /**
185
- * @property {number}
195
+ * Returns a value of a previous index
196
+ * @type {number}
186
197
  * @readonly
187
- * @description Returns a value of a previous index
188
198
  */
189
199
  get prevIndex() {
190
200
  return this.#_items.prevIndex;
191
201
  }
192
202
 
193
203
  /**
194
- * @property {number}
204
+ * Returns a value of a next index
205
+ * @type {number}
195
206
  * @readonly
196
- * @description Returns a value of a next index
197
207
  */
198
208
  get nextIndex() {
199
209
  return this.#_items.nextIndex;
200
210
  }
201
211
 
202
212
  /**
203
- * @property {?HTMLElement}
213
+ * Returns an element in the current index
214
+ * @type {?HTMLElement}
204
215
  * @readonly
205
- * @description Returns an element in the current index
206
216
  */
207
217
  get curItem() {
208
218
  const item = this.#_items.curItem;
@@ -471,19 +481,31 @@ class THtmlItemsListContainer {
471
481
 
472
482
  };
473
483
 
484
+ /**
485
+ * @typedef {Object} OPT_hlctlsett
486
+ * @property {boolean} [autoHideNewItems=false]
487
+ * @property {boolean} [markCurrentItem=false]
488
+ * @property {(string|string[])} [itemBaseClassID]
489
+ * @property {boolean} [showStubsIfEmpty=false]
490
+ * @property {boolean} [allowGroupSelection=false]
491
+ * @property {boolean} [allowSelectionLocks=false]
492
+ * @property {object} [stubs]
493
+ * @description An options set for `THtmlItemsListController`-class
494
+ */
495
+
474
496
  /**
475
497
  * @augments THtmlItemsListContainer
476
498
  * @classdesc This class enhanced a capabilities implemented
477
499
  * in the `THtmlItemsListContainer` class
478
500
  */
479
501
  class THtmlItemsListController extends THtmlItemsListContainer {
480
- /** @property {?HTMLElement} */
502
+ /** @type {?HTMLElement} */
481
503
  #_host;
482
- /** @property {THtmlStubItemsSet} */
504
+ /** @type {THtmlStubItemsSet} */
483
505
  #_stubs;
484
- /** @property {Set} */
506
+ /** @type {Set<HTMLElement>} */
485
507
  #_selects;
486
- /** @property {object} */
508
+ /** @property {OPT_hlctlsett} */
487
509
  #_options;// = null;
488
510
  /**
489
511
  * @typedef {Object} statILCtrl
@@ -499,19 +521,12 @@ class THtmlItemsListController extends THtmlItemsListContainer {
499
521
  */
500
522
  /** @property {statILCtrl} */
501
523
  #_status;
502
- /** @property {Map} */
524
+ /** @property {Map<string, Function>} */
503
525
  #_events;
504
526
 
505
527
  /**
506
528
  * @param {?HTMLElement} host
507
- * @param {object} [opt]
508
- * @param {boolean} [opt.autoHideNewItems=false]
509
- * @param {boolean} [opt.markCurrentItem=false]
510
- * @param {(string|string[])} [opt.itemBaseClassID]
511
- * @param {boolean} [opt.showStubsIfEmpty=false]
512
- * @param {boolean} [opt.allowGroupSelection=false]
513
- * @param {boolean} [opt.allowSelectionLocks=false]
514
- * @param {object} [opt.stubs]
529
+ * @param {OPT_hlctlsett} [opt]
515
530
  * @description Creates a new instance of the class.
516
531
  */
517
532
  constructor(host, opt) {
@@ -573,7 +588,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
573
588
  }
574
589
 
575
590
  /**
576
- * @param {object} e
591
+ * @param {object} e - event
577
592
  * @returns {void}
578
593
  * @private
579
594
  */
@@ -590,8 +605,8 @@ class THtmlItemsListController extends THtmlItemsListContainer {
590
605
  //console.log('CHECK: e => ditail:['+e.detail+']');
591
606
  //console.log('CHECK: e => phase:['+eventPhase+']');
592
607
  const onClickNum = readAsNumber(e.detail, 0);
593
- const _status = this.#_status;
594
- const { isSelectionLocked, catchEventOnHost } = _status;
608
+ const host = this.#_host;
609
+ const { isSelectionLocked, catchEventOnHost } = this.#_status;
595
610
  let curItem = null;
596
611
  switch (eventPhase) {
597
612
  //* // NOTE: currently on eventPhase = 2 and 3
@@ -599,7 +614,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
599
614
  /**/// capturing stage
600
615
  case 2: {
601
616
  /**/// target stage
602
- if (target !== this.#_host) curItem = target;
617
+ if (target !== host) curItem = target;
603
618
  break;
604
619
  }
605
620
  case 3: {
@@ -607,9 +622,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
607
622
  curItem = catchEventOnHost ? target : currentTarget;
608
623
  break;
609
624
  }
610
- default: {
611
- break;
612
- }
625
+ default: {}
613
626
  };
614
627
  if (
615
628
  !isSelectionLocked
@@ -617,7 +630,19 @@ class THtmlItemsListController extends THtmlItemsListContainer {
617
630
  && (onClickNum === 0 || onClickNum === 1)
618
631
  && !curItem.classList.contains(CSS_CLASS_DISABLED)
619
632
  ) {
620
- //console.log('CHECK: e => tag:['+curItem.tagName+']');
633
+ //console.log(`CHECK: e => tag:[${curItem.tagName}]`);
634
+ if (host) {
635
+ // find an actual list element in case when some inner element was clicking
636
+ let tmpItem = curItem;
637
+ while (tmpItem) {
638
+ //console.log(`CHECK: e => target.tag:[${tmpItem.tagName}]`);
639
+ tmpItem = tmpItem.parentElement;
640
+ //console.log(`CHECK: e => next.tag:[${tmpItem.tagName}]`);
641
+ if (tmpItem === host) break;
642
+ if (tmpItem) curItem = tmpItem;
643
+ };
644
+ };
645
+ //console.log(`CHECK: e => tag:[${curItem.tagName}]`);
621
646
  this.#_selectItemEx(curItem, {
622
647
  ctrlKey: ctrlKey,
623
648
  shiftKey: shiftKey,
@@ -638,9 +663,9 @@ class THtmlItemsListController extends THtmlItemsListContainer {
638
663
  };
639
664
 
640
665
  /**
641
- * @property {HTMLElement[]}
666
+ * Returns a list of the selected elements
667
+ * @type {HTMLElement[]}
642
668
  * @readonly
643
- * @description Returns a list of the selected elements
644
669
  */
645
670
  get SelectedItems() {
646
671
  const _selects = this.#_selects;
@@ -653,18 +678,18 @@ class THtmlItemsListController extends THtmlItemsListContainer {
653
678
  }
654
679
 
655
680
  /**
656
- * @property {THtmlStubItemsSet}
681
+ * Returns a `THtmlStubItemsSet` instance
682
+ * @type {THtmlStubItemsSet}
657
683
  * @readonly
658
- * @description Returns a `THtmlStubItemsSet` instance
659
684
  */
660
685
  get StubItems() {
661
686
  return this.#_stubs;
662
687
  }
663
688
 
664
689
  /**
665
- * @property {boolean}
690
+ * Indicates whether a selection is locked
691
+ * @type {boolean}
666
692
  * @readonly
667
- * @description Indicates whether a selection is locked
668
693
  */
669
694
  get isSelectionLocked() {
670
695
  return this.#_status.isSelectionLocked;
@@ -1,4 +1,4 @@
1
- // [v0.1.052-20241119]
1
+ // [v0.1.054-20250509]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -48,9 +48,9 @@ const BTS_DEF_GROUP_NAME = 'all';
48
48
  * A set provide a buttons: <next>, <previous>, <first> and <last>.
49
49
  */
50
50
  class THtmlListButtonsController {
51
- /** @property {THtmlButtonsSet} */
51
+ /** @type {THtmlButtonsSet} */
52
52
  #_btnSet;
53
- /** @property {Map} */
53
+ /** @type {Map<string, Function>} */
54
54
  #_events;
55
55
 
56
56
  /**
@@ -67,8 +67,6 @@ class THtmlListButtonsController {
67
67
  * @description Creates an instance of a buttons set.
68
68
  */
69
69
  constructor(opt) {
70
- // load options
71
- const _options = isPlainObject(opt) ? opt : {};
72
70
  // load controls
73
71
  /** @type {listButtonsSetDesc} */
74
72
  let {
@@ -76,7 +74,7 @@ class THtmlListButtonsController {
76
74
  btnPrev,
77
75
  btnNext,
78
76
  btnLast,
79
- } = _options;
77
+ } = isPlainObject(opt) ? opt : {};
80
78
  if (!isHTMLButton(btnFirst)) btnFirst = null;
81
79
  if (!isHTMLButton(btnPrev)) btnPrev = null;
82
80
  if (!isHTMLButton(btnNext)) btnNext = null;
@@ -1,4 +1,4 @@
1
- // [v0.1.045-20241119]
1
+ // [v0.1.049-20250505]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -26,32 +26,47 @@ const {
26
26
  * (* class definitions *)
27
27
  */
28
28
 
29
+ /**
30
+ * @typedef {Object} OPT_ldstubs
31
+ * @property {string} [defaultItem] - <*deprecated*> a default element name
32
+ * @property {boolean} [useClear=true] - to clear before load an elements
33
+ * @property {boolean} [force=false] - run in a force mode
34
+ * @description A settings to load a stub-elements.
35
+ * @todo [since v0.0.26] `defaultItem`-option deprecated
36
+ */
37
+
38
+ /**
39
+ * @typedef {Object} OBJ_stubEList
40
+ * @property {Array} items - array of `name`-`element` pairs
41
+ * @property {string} [defaultItem] - a default element name
42
+ * @description A stub-elements description list.
43
+ */
44
+
45
+ /**
46
+ * @typedef {Object} OPT_stubconsett
47
+ * @property {(any[])} items - array of `name`-`element` pairs
48
+ * @property {string} [defaultItem] - a default element name
49
+ * @property {boolean} [force=false] - run in a force mode
50
+ * @description A an options set for a `THtmlStubItemsSet`-class constructor
51
+ */
52
+
29
53
  /**
30
54
  * @classdesc This class implements an interface of a stub-items set
31
55
  */
32
56
  class THtmlStubItemsSet {
33
- /** @property {?HTMLElement} */
57
+ /** @type {?HTMLElement} */
34
58
  #_host;
35
- /** @property {Map} */
59
+ /** @type {Map<string, HTMLElement>} */
36
60
  #_items;
37
- /** @property {string} */
61
+ /** @type {string} */
38
62
  #_defItem;
39
63
  #_shownItem = null;
40
64
 
41
65
  /**
42
- * @typedef {Object} OBJ_stubEList
43
- * @property {Array} items - array of `name`-`element` pairs
44
- * @property {string} [defaultItem] - a default element name
45
- * @description A stub-elements description list.
46
- */
47
-
48
- /**
49
- * @param {HTMLElement} host
50
- * @param {(array|object|OBJ_stubEList)} opt
51
- * @param {(array|object)} opt.items
52
- * @param {string} opt.defaultItem
53
- * @param {boolean} opt.force - <*deprecated (since: v0.0.23)*>
66
+ * @param {HTMLElement} host - host element
67
+ * @param {(array|OPT_stubconsett|OBJ_stubEList)} [opt] - options
54
68
  * @description Creates an instance of a stub-items set
69
+ * @todo [since v0.0.26] use of an `array`-type as a value of an `opt` is deprecated
55
70
  */
56
71
  constructor(host, opt) {
57
72
  this.#_host = isHTMLElement(host) ? host : null;
@@ -59,15 +74,21 @@ class THtmlStubItemsSet {
59
74
  this.#_defItem = '';
60
75
  this.#_shownItem = null;
61
76
  if (isObject(opt)) {
77
+ /** @type {(OPT_stubconsett|OBJ_stubEList)} */
62
78
  const obj = isArray(opt) ? { items: opt } : opt;
63
79
  const { items, defaultItem, force } = obj;
64
- this.loadItems(items, { defaultItem, force });
80
+ this.loadItems({
81
+ items,
82
+ defaultItem,
83
+ }, {
84
+ force,
85
+ });
65
86
  };
66
87
  }
67
88
 
68
89
  /**
69
- * @property {string}
70
- * @description Defines a default element name
90
+ * Defines a default element name
91
+ * @type {string}
71
92
  */
72
93
  get defItem() {
73
94
  return this.#_defItem;
@@ -78,9 +99,9 @@ class THtmlStubItemsSet {
78
99
  }
79
100
 
80
101
  /**
81
- * @property {number}
102
+ * Contains a Qty of an elements
103
+ * @type {number}
82
104
  * @readonly
83
- * @description Contains a Qty of an elements
84
105
  */
85
106
  get count() {
86
107
  return this.#_items.size;
@@ -229,40 +250,33 @@ class THtmlStubItemsSet {
229
250
  }
230
251
 
231
252
  /**
232
- * @typedef {Object} OPT_ldstubs
233
- * @property {string} [defaultItem] - a default element name
234
- * @property {boolean} [useClear=true] - to clear before load an elements
235
- * @property {boolean} [force=false] - run in a force mode
236
- * @description A settings to load stub-elements.
237
- */
238
-
239
- /**
240
- * @param {(Array|OBJ_stubEList)} list - an array of entries or special object
253
+ * @param {(Array|OBJ_stubEList)} data - an array of entries or special object
241
254
  * @param {(boolean|OPT_ldstubs)} [opt] - an options
242
255
  * @returns {number}
243
256
  * @description Adds an items to an instance members.
257
+ * @todo [since 0.0.25] deprecate use of `opt` as `boolean`
258
+ * @todo [since v0.0.26] for `OPT_ldstubs` a `defaultItem`-option deprecated
244
259
  */
245
- loadItems(list, opt) {
246
- let _options = opt;
247
- if (typeof _options === 'boolean') _options = { useClear: _options };
248
- if (!isPlainObject(_options)) _options = {};
249
- /** @type {OPT_ldstubs} */
260
+ loadItems(data, opt) {
261
+ /** @type {OBJ_stubEList} */
250
262
  let {
263
+ items,
251
264
  defaultItem,
265
+ } = isPlainObject(data) ? data : { items: data };
266
+ /** @type {OPT_ldstubs} */
267
+ let _options = isPlainObject(opt) ? opt : { useClear: opt };
268
+ let {
252
269
  useClear,
253
270
  force,
254
271
  } = _options;
255
272
  if (typeof useClear !== 'boolean') useClear = true;
256
273
  if (typeof force !== 'boolean') force = false;
257
- let _list = list;
258
- if (isPlainObject(_list)) {
259
- ({ items: _list, defaultItem } = _list);
260
- };
274
+ if (defaultItem === undefined) defaultItem = _options.defaultItem; /* deprecated */
261
275
  const setDefs = defaultItem !== undefined;
262
276
  let count = 0;
263
- if (isArray(_list)) {
277
+ if (isArray(items)) {
264
278
  if (useClear) this.clear();
265
- _list.forEach((obj) => {
279
+ items.forEach((obj) => {
266
280
  if (isArray(obj)) {
267
281
  const [ name, item ] = obj;
268
282
  if (this.addItem(name, item, force)) count++;