@cntwg/html-helper 0.0.25 → 0.0.27

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,4 +1,4 @@
1
- // [v0.1.053-20250416]
1
+ // [v0.1.056-20250827]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -7,11 +7,11 @@ const {
7
7
  } = require('@ygracs/bsfoc-lib-js');
8
8
 
9
9
  const {
10
+ isHTMLButton,
10
11
  CSS_CLASS_STRING,
11
12
  } = require('../html-helper-lib.js');
12
13
 
13
14
  const {
14
- isHTMLButton,
15
15
  THtmlButtonsSet,
16
16
  } = require('./buttons.js');
17
17
 
@@ -42,6 +42,15 @@ const BTS_DEF_GROUP_NAME = 'all';
42
42
  * (* class definitions *)
43
43
  */
44
44
 
45
+ /**
46
+ * A description for list buttons set.
47
+ * @typedef {Object} listButtonsSetDesc
48
+ * @property {?HTMLElement} btnFirst - button 'move to first'
49
+ * @property {?HTMLElement} btnPrev - button 'move to previous'
50
+ * @property {?HTMLElement} btnNext - button 'move to next'
51
+ * @property {?HTMLElement} btnLast - button 'move to last'
52
+ */
53
+
45
54
  /**
46
55
  * @classdesc This class implements an interface of a pre-defined
47
56
  * buttons set that is used in pair with a list elements.
@@ -54,21 +63,10 @@ class THtmlListButtonsController {
54
63
  #_events;
55
64
 
56
65
  /**
57
- * @typedef {Object} listButtonsSetDesc
58
- * @property {?HTMLElement} btnFirst - button 'move to first'
59
- * @property {?HTMLElement} btnPrev - button 'move to previous'
60
- * @property {?HTMLElement} btnNext - button 'move to next'
61
- * @property {?HTMLElement} btnLast - button 'move to last'
62
- * @description A description for list buttons set.
63
- */
64
-
65
- /**
66
+ * Creates an instance of a buttons set.
66
67
  * @param {listButtonsSetDesc} [opt] - an options
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;
@@ -143,8 +141,8 @@ class THtmlListButtonsController {
143
141
  }
144
142
 
145
143
  /**
144
+ * Disables all buttons.
146
145
  * @returns {void}
147
- * @description Disables all buttons.
148
146
  */
149
147
  disableAll() {
150
148
  const _btnSet = this.#_btnSet;
@@ -153,24 +151,24 @@ class THtmlListButtonsController {
153
151
  }
154
152
 
155
153
  /**
154
+ * Disables all buttons in 'move_bkwd' group.
156
155
  * @returns {void}
157
- * @description Disables all buttons in 'move_bkwd' group.
158
156
  */
159
157
  disableBkwd() {
160
158
  this.#_btnSet.disableGroup('move_bkwd');
161
159
  }
162
160
 
163
161
  /**
162
+ * Disables all buttons in 'move_frwd' group.
164
163
  * @returns {void}
165
- * @description Disables all buttons in 'move_frwd' group.
166
164
  */
167
165
  disableFrwd() {
168
166
  this.#_btnSet.disableGroup('move_frwd');
169
167
  }
170
168
 
171
169
  /**
170
+ * Enables all buttons.
172
171
  * @returns {void}
173
- * @description Enables all buttons.
174
172
  */
175
173
  enableAll() {
176
174
  const _btnSet = this.#_btnSet;
@@ -179,26 +177,26 @@ class THtmlListButtonsController {
179
177
  }
180
178
 
181
179
  /**
180
+ * Enables all buttons in 'move_bkwd' group.
182
181
  * @returns {void}
183
- * @description Enables all buttons in 'move_bkwd' group.
184
182
  */
185
183
  enableBkwd() {
186
184
  this.#_btnSet.enableGroup('move_bkwd');
187
185
  }
188
186
 
189
187
  /**
188
+ * Enables all buttons in 'move_frwd' group.
190
189
  * @returns {void}
191
- * @description Enables all buttons in 'move_frwd' group.
192
190
  */
193
191
  enableFrwd() {
194
192
  this.#_btnSet.enableGroup('move_frwd');
195
193
  }
196
194
 
197
195
  /**
196
+ * Sets a callback function to handle event.
198
197
  * @param {string} name - event name
199
198
  * @param {func} evnt - callback function
200
199
  * @returns {void}
201
- * @description Sets a callback function to handle event.
202
200
  */
203
201
  on(name, evnt) {
204
202
  pushEventHandler(this.#_events, name, evnt);
@@ -1,4 +1,4 @@
1
- // [v0.1.046-20250416]
1
+ // [v0.1.050-20250827]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -27,11 +27,27 @@ const {
27
27
  */
28
28
 
29
29
  /**
30
+ * A settings to load a stub-elements.
30
31
  * @typedef {Object} OPT_ldstubs
31
- * @property {string} [defaultItem] - a default element name
32
+ * @property {string} [defaultItem] - <*deprecated*> a default element name
32
33
  * @property {boolean} [useClear=true] - to clear before load an elements
33
34
  * @property {boolean} [force=false] - run in a force mode
34
- * @description A settings to load stub-elements.
35
+ * @todo [since v0.0.26] `defaultItem`-option deprecated
36
+ */
37
+
38
+ /**
39
+ * A stub-elements description list.
40
+ * @typedef {Object} OBJ_stubEList
41
+ * @property {Array} items - array of `name`-`element` pairs
42
+ * @property {string} [defaultItem] - a default element name
43
+ */
44
+
45
+ /**
46
+ * A an options set for a `THtmlStubItemsSet`-class constructor
47
+ * @typedef {Object} OPT_stubconsett
48
+ * @property {(any[])} items - array of `name`-`element` pairs
49
+ * @property {string} [defaultItem] - a default element name
50
+ * @property {boolean} [force=false] - run in a force mode
35
51
  */
36
52
 
37
53
  /**
@@ -47,19 +63,10 @@ class THtmlStubItemsSet {
47
63
  #_shownItem = null;
48
64
 
49
65
  /**
50
- * @typedef {Object} OBJ_stubEList
51
- * @property {Array} items - array of `name`-`element` pairs
52
- * @property {string} [defaultItem] - a default element name
53
- * @description A stub-elements description list.
54
- */
55
-
56
- /**
57
- * @param {HTMLElement} host
58
- * @param {(array|object|OBJ_stubEList)} opt - options
59
- * @param {(array|object)} opt.items
60
- * @param {string} opt.defaultItem
61
- * @param {boolean} opt.force - <*deprecated (since: v0.0.23)*>
62
- * @description Creates an instance of a stub-items set
66
+ * Creates an instance of a stub-items set
67
+ * @param {HTMLElement} host - host element
68
+ * @param {(array|OPT_stubconsett|OBJ_stubEList)} [opt] - options
69
+ * @todo [since v0.0.26] use of an `array`-type as a value of an `opt` is deprecated
63
70
  */
64
71
  constructor(host, opt) {
65
72
  this.#_host = isHTMLElement(host) ? host : null;
@@ -67,9 +74,15 @@ class THtmlStubItemsSet {
67
74
  this.#_defItem = '';
68
75
  this.#_shownItem = null;
69
76
  if (isObject(opt)) {
77
+ /** @type {(OPT_stubconsett|OBJ_stubEList)} */
70
78
  const obj = isArray(opt) ? { items: opt } : opt;
71
79
  const { items, defaultItem, force } = obj;
72
- this.loadItems(items, { defaultItem, force });
80
+ this.loadItems({
81
+ items,
82
+ defaultItem,
83
+ }, {
84
+ force,
85
+ });
73
86
  };
74
87
  }
75
88
 
@@ -95,8 +108,8 @@ class THtmlStubItemsSet {
95
108
  }
96
109
 
97
110
  /**
111
+ * Clears an instance content.
98
112
  * @returns {void}
99
- * @description Clears an instance content.
100
113
  */
101
114
  clear() {
102
115
  // // TODO: check if any item is shown
@@ -106,9 +119,9 @@ class THtmlStubItemsSet {
106
119
  }
107
120
 
108
121
  /**
122
+ * Sets a default item.
109
123
  * @param {string} name - an element name
110
124
  * @returns {boolean}
111
- * @description Sets a default item.
112
125
  */
113
126
  setDefItem(name) {
114
127
  let isACCEPTED = false;
@@ -121,8 +134,8 @@ class THtmlStubItemsSet {
121
134
  }
122
135
 
123
136
  /**
137
+ * Resets a default item.
124
138
  * @returns {void}
125
- * @description Resets a default item.
126
139
  */
127
140
  rstDefItem() {
128
141
  // // TODO: check if item is shown
@@ -130,9 +143,9 @@ class THtmlStubItemsSet {
130
143
  }
131
144
 
132
145
  /**
146
+ * Checks if an item exists.
133
147
  * @param {string} name - an element name
134
148
  * @returns {boolean}
135
- * @description Checks if an item exists.
136
149
  */
137
150
  hasItem(name) {
138
151
  const _name = typeof name === 'string' ? name.trim() : '';
@@ -140,17 +153,17 @@ class THtmlStubItemsSet {
140
153
  }
141
154
 
142
155
  /**
156
+ * Checks if any items exists.
143
157
  * @returns {boolean}
144
- * @description Checks if any items exists.
145
158
  */
146
159
  hasItems() {
147
160
  return this.#_items.size > 0;
148
161
  }
149
162
 
150
163
  /**
164
+ * Returns an item by its name.
151
165
  * @param {string} name - an element name
152
166
  * @returns {?HTMLElement}
153
- * @description Returns an item by its name.
154
167
  */
155
168
  getItem(name) {
156
169
  const _name = typeof name === 'string' ? name.trim() : '';
@@ -159,11 +172,11 @@ class THtmlStubItemsSet {
159
172
  }
160
173
 
161
174
  /**
175
+ * Adds an item to an instance members.
162
176
  * @param {string} name - an element name
163
177
  * @param {HTMLElement} item - an element
164
178
  * @param {boolean} [opt=false] - flag indicating a force mode
165
179
  * @returns {boolean}
166
- * @description Adds an item to an instance members.
167
180
  */
168
181
  addItem(name, item, opt) {
169
182
  const _name = typeof name === 'string' ? name.trim() : '';
@@ -179,9 +192,9 @@ class THtmlStubItemsSet {
179
192
  }
180
193
 
181
194
  /**
195
+ * Deletes an item from an instance members.
182
196
  * @param {string} name - an element name
183
197
  * @returns {boolean}
184
- * @description Deletes an item from an instance members.
185
198
  */
186
199
  delItem(name) {
187
200
  let _name = '';
@@ -197,9 +210,9 @@ class THtmlStubItemsSet {
197
210
  }
198
211
 
199
212
  /**
213
+ * Shows an item.
200
214
  * @param {string} name - an element name
201
215
  * @returns {boolean}
202
- * @description Shows an item.
203
216
  */
204
217
  showItem(name) {
205
218
  const item = this.getItem(name);
@@ -209,17 +222,17 @@ class THtmlStubItemsSet {
209
222
  }
210
223
 
211
224
  /**
225
+ * Shows a default item.
212
226
  * @returns {boolean}
213
- * @description Shows a default item.
214
227
  */
215
228
  showDefItem() {
216
229
  return this.showItem(this.#_defItem);
217
230
  }
218
231
 
219
232
  /**
233
+ * Hides an item.
220
234
  * @param {string} name - an element name
221
235
  * @returns {boolean}
222
- * @description Hides an item.
223
236
  */
224
237
  hideItem(name) {
225
238
  const item = this.getItem(name);
@@ -229,41 +242,41 @@ class THtmlStubItemsSet {
229
242
  }
230
243
 
231
244
  /**
245
+ * Hides a default item.
232
246
  * @returns {boolean}
233
- * @description Hides a default item.
234
247
  */
235
248
  hideDefItem() {
236
249
  return this.hideItem(this.#_defItem);
237
250
  }
238
251
 
239
252
  /**
240
- * @param {(Array|OBJ_stubEList)} list - an array of entries or special object
253
+ * Adds an items to an instance members.
254
+ * @param {(Array|OBJ_stubEList)} data - an array of entries or special object
241
255
  * @param {(boolean|OPT_ldstubs)} [opt] - an options
242
256
  * @returns {number}
243
- * @description Adds an items to an instance members.
244
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
245
259
  */
246
- loadItems(list, opt) {
247
- let _options = opt;
248
- if (typeof _options === 'boolean') _options = { useClear: _options };
249
- if (!isPlainObject(_options)) _options = {};
250
- /** @type {OPT_ldstubs} */
260
+ loadItems(data, opt) {
261
+ /** @type {OBJ_stubEList} */
251
262
  let {
263
+ items,
252
264
  defaultItem,
265
+ } = isPlainObject(data) ? data : { items: data };
266
+ /** @type {OPT_ldstubs} */
267
+ let _options = isPlainObject(opt) ? opt : { useClear: opt };
268
+ let {
253
269
  useClear,
254
270
  force,
255
271
  } = _options;
256
272
  if (typeof useClear !== 'boolean') useClear = true;
257
273
  if (typeof force !== 'boolean') force = false;
258
- let _list = list;
259
- if (isPlainObject(_list)) {
260
- ({ items: _list, defaultItem } = _list);
261
- };
274
+ if (defaultItem === undefined) defaultItem = _options.defaultItem; /* deprecated */
262
275
  const setDefs = defaultItem !== undefined;
263
276
  let count = 0;
264
- if (isArray(_list)) {
277
+ if (isArray(items)) {
265
278
  if (useClear) this.clear();
266
- _list.forEach((obj) => {
279
+ items.forEach((obj) => {
267
280
  if (isArray(obj)) {
268
281
  const [ name, item ] = obj;
269
282
  if (this.addItem(name, item, force)) count++;