@cntwg/html-helper 0.0.20 → 0.0.21

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.049-20230614]
1
+ // [v0.1.050-20240705]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -54,13 +54,29 @@ function isHTMLButton(obj){
54
54
  return result;
55
55
  }
56
56
 
57
- // === module main block (function definitions) ===
57
+ // === module main block ===
58
58
 
59
- // === module main block (class definitions) ===
59
+ /***
60
+ * (* constant definitions *)
61
+ */
60
62
 
63
+ /***
64
+ * (* function definitions *)
65
+ */
66
+
67
+ /***
68
+ * (* class definitions *)
69
+ */
70
+
71
+ /**
72
+ * @description This class implements an instance of a buttons set
73
+ */
61
74
  class THtmlButtonsSet {
62
75
  #_btnCol = null;
63
76
 
77
+ /**
78
+ * @param {none}
79
+ */
64
80
  constructor(){
65
81
  // define default functions for manipulators
66
82
  const __user_index_getter = (value) => {
@@ -79,82 +95,181 @@ class THtmlButtonsSet {
79
95
  });
80
96
  }
81
97
 
98
+ /**
99
+ * @property {array}
100
+ * @readonly
101
+ * @see TItemsICollection.ItemNames
102
+ */
82
103
  get ItemNames(){
83
104
  return this.#_btnCol.ItemNames;
84
105
  }
85
106
 
107
+ /**
108
+ * @property {array}
109
+ * @readonly
110
+ * @see TItemsICollection.CategoryNames
111
+ */
86
112
  get GroupNames(){
87
113
  return this.#_btnCol.CategoryNames;
88
114
  }
89
115
 
116
+ /**
117
+ * @param {ID_STRING}
118
+ * @returns {bool}
119
+ * @see TItemsICollection.hasItem
120
+ * @description Checks whether a target item with a given name exists.
121
+ */
90
122
  hasItem(name){
91
123
  return this.#_btnCol.hasItem(name);
92
124
  }
93
125
 
126
+ /**
127
+ * @see TItemsICollection.addItem
128
+ * @description Adds buttons to a set members.
129
+ */
94
130
  addItem(...args){
95
131
  return this.#_btnCol.addItem(...args);
96
132
  }
97
133
 
134
+ /**
135
+ * @see TItemsICollection.addItemToCategory
136
+ * @description Adds button to a listed groups.
137
+ */
98
138
  addItemToGroup(...args){
99
139
  return this.#_btnCol.addItemToCategory(...args);
100
140
  }
101
141
 
142
+ /**
143
+ * @param {ID_STRING}
144
+ * @see TItemsICollection.delItem
145
+ * @description Deletes button from a set members.
146
+ */
102
147
  delItem(name){
103
148
  return this.#_btnCol.delItem(name);
104
149
  }
105
150
 
151
+ /**
152
+ * @see TItemsICollection.delItemFromGroup
153
+ * @description Deletes button from a listed groups.
154
+ */
106
155
  delItemFromGroup(...args){
107
156
  return this.#_btnCol.delItemFromGroup(...args);
108
157
  }
109
158
 
159
+ /**
160
+ * @param {ID_STRING} - old name
161
+ * @param {ID_STRING} - new name
162
+ * @see TItemsICollection.renameItem
163
+ * @description Renames button in a set.
164
+ */
110
165
  renameItem(oldName, newName){
111
166
  return this.#_btnCol.renameItem(oldName, newName, false);
112
167
  }
113
168
 
169
+ /**
170
+ * @param {ID_STRING}
171
+ * @returns {none}
172
+ * @description Tries to enable button.
173
+ */
114
174
  enableItem(name){
115
175
  unlockHtmlElement(this.#_btnCol.getItem(name));
116
176
  }
117
177
 
178
+ /**
179
+ * @param {ID_STRING}
180
+ * @returns {none}
181
+ * @description Tries to disable button.
182
+ */
118
183
  disableItem(name){
119
184
  lockHtmlElement(this.#_btnCol.getItem(name));
120
185
  }
121
186
 
187
+ /**
188
+ * @param {ID_STRING}
189
+ * @returns {bool}
190
+ * @see TItemsICollection.hasCategory
191
+ * @description Checks whether a target group with a given name exists.
192
+ */
122
193
  hasGroup(name){
123
194
  return this.#_btnCol.hasCategory(name);
124
195
  }
125
196
 
197
+ /**
198
+ * @param {ID_STRING}
199
+ * @returns {bool}
200
+ * @see TItemsICollection.addCategory
201
+ * @description Adds a group with a given name.
202
+ */
126
203
  addGroup(name){
127
204
  return this.#_btnCol.addCategory(name);
128
205
  }
129
206
 
207
+ /**
208
+ * @param {ID_STRING}
209
+ * @returns {bool}
210
+ * @see TItemsICollection.delCategory
211
+ * @description Deletes a group with a given name.
212
+ */
130
213
  delGroup(name){
131
214
  return this.#_btnCol.delCategory(name);
132
215
  }
133
216
 
217
+ /**
218
+ * @param {ID_STRING} - old name
219
+ * @param {ID_STRING} - new name
220
+ * @returns {bool}
221
+ * @see TItemsICollection.renameCategory
222
+ * @description Renames group in a set.
223
+ */
134
224
  renameGroup(oldName, newName){
135
225
  return this.#_btnCol.renameCategory(oldName, newName, false);
136
226
  }
137
227
 
228
+ /**
229
+ * @param {ID_STRING}
230
+ * @returns {none}
231
+ * @description Enables all buttons in a given group.
232
+ */
138
233
  enableGroup(value){
139
234
  const group = this.#_btnCol.getCategory(value);
140
235
  valueToArray(group).forEach(item => unlockHtmlElement(item));
141
236
  }
142
237
 
238
+ /**
239
+ * @param {ID_STRING}
240
+ * @returns {none}
241
+ * @description Disables all buttons in a given group.
242
+ */
143
243
  disableGroup(value){
144
244
  const group = this.#_btnCol.getCategory(value);
145
245
  valueToArray(group).forEach(item => lockHtmlElement(item));
146
246
  }
147
247
 
248
+ /**
249
+ * @returns {function}
250
+ * @static
251
+ * @description Returns a function wich do a validation check.
252
+ */
148
253
  static get isHTMLButton(){
149
254
  return isHTMLButton;
150
255
  }
151
256
 
152
257
  };
153
258
 
259
+ /**
260
+ * @description This class implements an instance of a pre-defined buttons set.
261
+ * A set provide a three button: <apply>, <reset> and <cancel>.
262
+ */
154
263
  class THtmlButtonsControllerARCSet {
155
264
  #_btnSet = null;
156
265
  #_events = null;
157
266
 
267
+ /**
268
+ * @param {object} opt
269
+ * @param {HTMLElement} opt.btnApply
270
+ * @param {HTMLElement} opt.btnReset
271
+ * @param {HTMLElement} opt.btnCancel
272
+ */
158
273
  constructor(opt) {
159
274
  // load options
160
275
  const _options = isPlainObject(opt) ? opt : {};
@@ -194,6 +309,12 @@ class THtmlButtonsControllerARCSet {
194
309
  this.#_events = new Map();
195
310
  }
196
311
 
312
+ /**
313
+ * @param {object}
314
+ * @param {ID_STRING}
315
+ * @returns {none}
316
+ * @private
317
+ */
197
318
  #_on_btn_pressed = (e, key) => {
198
319
  //console.log(`THtmlListButtonsController._on_btn_pressed().key(${key}) ==> was called...`);
199
320
  //e.preventDefault(); /* need to reconsider reason for use */
@@ -207,26 +328,59 @@ class THtmlButtonsControllerARCSet {
207
328
  };
208
329
  }
209
330
 
331
+ /**
332
+ * @param {ID_STRING}
333
+ * @param {...any}
334
+ * @returns {none}
335
+ * @private
336
+ * @see triggerEventHandler
337
+ */
210
338
  #_triggerEvent = (name, ...args) => {
211
339
  triggerEventHandler(this.#_events, name, ...args);
212
340
  }
213
341
 
342
+ /**
343
+ * @param {none}
344
+ * @returns {none}
345
+ * @description Disables all buttons in 'main' group.
346
+ */
214
347
  disableMain(){
215
348
  this.#_btnSet.disableGroup('main');
216
349
  }
217
350
 
351
+ /**
352
+ * @param {none}
353
+ * @returns {none}
354
+ * @description Enables all buttons in 'main' group.
355
+ */
218
356
  enableMain(){
219
357
  this.#_btnSet.enableGroup('main');
220
358
  }
221
359
 
360
+ /**
361
+ * @param {none}
362
+ * @returns {none}
363
+ * @description Disables all buttons.
364
+ */
222
365
  disableAll(){
223
366
  this.#_btnSet.disableGroup('all');
224
367
  }
225
368
 
369
+ /**
370
+ * @param {none}
371
+ * @returns {none}
372
+ * @description Enables all buttons.
373
+ */
226
374
  enableAll(){
227
375
  this.#_btnSet.enableGroup('all');
228
376
  }
229
377
 
378
+ /**
379
+ * @param {ID_STRING}
380
+ * @param {func}
381
+ * @returns {none}
382
+ * @description Sets a callback function to handle event.
383
+ */
230
384
  on(name, evnt){
231
385
  pushEventHandler(this.#_events, name, evnt);
232
386
  }
@@ -1,4 +1,4 @@
1
- // [v0.1.011-20230704]
1
+ // [v0.1.013-20240705]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -28,7 +28,7 @@ const lpAllowedValues = new Map([
28
28
  ]);
29
29
 
30
30
  function getInputFieldTypeDescr(value){
31
- let fldType = readAsString(value, '', true);
31
+ let fldType = readAsString(value, true);
32
32
  if (fldType === '') fldType = 'default';
33
33
  let fldSubType = '';
34
34
  switch (fldType) {
@@ -55,7 +55,7 @@ function getInputFieldTypeDescr(value){
55
55
  };
56
56
 
57
57
  function getLabelPositionID(value){
58
- let key = readAsString(value, '', true);
58
+ let key = readAsString(value, true);
59
59
  if (!lpAllowedValues.has(key)) key = 'default';
60
60
  return lpAllowedValues.get(key);
61
61
  };
@@ -74,6 +74,9 @@ function getLabelPositionID(value){
74
74
  * (* class definitions *)
75
75
  */
76
76
 
77
+ /**
78
+ * @description This class implements an instance of an input field element
79
+ */
77
80
  class THtmlInputField {
78
81
  #_host = null;
79
82
  #_label = null;
@@ -84,6 +87,19 @@ class THtmlInputField {
84
87
  #_status = null;
85
88
  #_events = null;
86
89
 
90
+ /**
91
+ * @param {ID_STRING} name - <*reserved*>
92
+ * @param {object} eholds
93
+ * @param {HTMLElement} eholds.host
94
+ * @param {HTMLElement} eholds.label
95
+ * @param {HTMLElement} eholds.field
96
+ * @param {object} [opt]
97
+ * @param {ID_STRING} [opt.idPref]
98
+ * @param {(string|array)} [opt.baseClassID]
99
+ * @param {string} [opt.hint]
100
+ * @param {object} [opt.type]
101
+ * @param {bool} [opt.readonly=true]
102
+ */
87
103
  constructor(name, eholds, opt){
88
104
  // load elements
89
105
  const _eholds = isPlainObject(eholds) ? eholds : {};
@@ -125,10 +141,17 @@ class THtmlInputField {
125
141
  this.#_events = new Map();
126
142
  }
127
143
 
144
+ /**
145
+ * @property {bool}
146
+ * @readonly
147
+ */
128
148
  get isModified(){
129
149
  return this.#_status.isModified;
130
150
  }
131
151
 
152
+ /**
153
+ * @property {string}
154
+ */
132
155
  get value(){
133
156
  const field = this.#_field;
134
157
  let result = '';
@@ -147,13 +170,16 @@ class THtmlInputField {
147
170
  field.checked = value;
148
171
  this.#_status.isModified = false;
149
172
  } else {
150
- let _value = readAsString(value, '', {
173
+ let _value = readAsString(value, {
151
174
  boolToString: true,
152
175
  numberToString: true,
153
176
  });
154
177
  field.value = _value;
155
178
  this.#_status.isModified = false;
156
179
  if (_value === '') {
180
+ /**
181
+ * @see THtmlInputField#value-empty
182
+ */
157
183
  this.#_triggerEvent('value-empty', {
158
184
  type: 'value-empty',
159
185
  target: null,
@@ -163,21 +189,46 @@ class THtmlInputField {
163
189
  };
164
190
  }
165
191
 
192
+ /**
193
+ * @param {ID_STRING}
194
+ * @param {...any}
195
+ * @returns {none}
196
+ * @private
197
+ * @see triggerEventHandler
198
+ */
166
199
  #_triggerEvent = (name, ...args) => {
167
200
  triggerEventHandler(this.#_events, name, ...args);
168
201
  };
169
202
 
203
+ /**
204
+ * @param {object}
205
+ * @returns {none}
206
+ * @private
207
+ * @fires THtmlInputField#value-changed
208
+ */
170
209
  #_saveFieldData = (e) => {
171
210
  e.preventDefault();
172
211
  const target = e.target;
173
212
  //***/console.log(':'+e.type+':'+target.getAttribute('id')+':\n:saveFieldData() => received OnChange-event');
174
213
  // // TODO:
214
+ /**
215
+ * @event THtmlInputField#value-changed
216
+ * @type {object}
217
+ * @property {ID_STRING} type
218
+ * @property {object} target
219
+ */
175
220
  this.#_triggerEvent('value-changed', {
176
221
  type: 'value-changed',
177
222
  target,
178
223
  });
179
224
  };
180
225
 
226
+ /**
227
+ * @param {object}
228
+ * @returns {none}
229
+ * @private
230
+ * @fires THtmlInputField#value-empty
231
+ */
181
232
  #_switchFieldStatusOnInput = (e) => {
182
233
  e.preventDefault();
183
234
  const target = e.target;
@@ -185,6 +236,12 @@ class THtmlInputField {
185
236
  this.#_status.isModified = true;
186
237
  // // TODO:
187
238
  if (target.value === '') {
239
+ /**
240
+ * @event THtmlInputField#value-empty
241
+ * @type {object}
242
+ * @property {ID_STRING} type
243
+ * @property {object} target
244
+ */
188
245
  this.#_triggerEvent('value-empty', {
189
246
  type: 'value-empty',
190
247
  target,
@@ -192,12 +249,22 @@ class THtmlInputField {
192
249
  };
193
250
  };
194
251
 
252
+ /**
253
+ * @param {object}
254
+ * @returns {none}
255
+ * @private
256
+ */
195
257
  #_switchFieldStatusOnBlur = (e) => {
196
258
  e.preventDefault();
197
259
  //***/console.log(':'+e.type+':'+e.target.getAttribute('id')+':\n:switchFieldStatusOnBlur() => received OnBlur-event');
198
260
  // // TODO:
199
261
  };
200
262
 
263
+ /**
264
+ * @param {HTMLElement}
265
+ * @returns {bool}
266
+ * @description Tries to attach an element to a given target.
267
+ */
201
268
  attachTo(target){
202
269
  const host = this.#_host;
203
270
  let result = false;
@@ -211,26 +278,58 @@ class THtmlInputField {
211
278
  return result;
212
279
  }
213
280
 
281
+ /**
282
+ * @param {none}
283
+ * @returns {bool}
284
+ * @description Checks if a value of an element is not set.
285
+ */
214
286
  isEmpty(){
215
287
  return isEmptyString(this.value);
216
288
  }
217
289
 
290
+ /**
291
+ * @param {none}
292
+ * @returns {bool}
293
+ * @description Checks if a value of an element is set.
294
+ */
218
295
  isNotEmpty(){
219
296
  return isNotEmptyString(this.value);
220
297
  }
221
298
 
299
+ /**
300
+ * @param {none}
301
+ * @returns {none}
302
+ * @description Shows an element.
303
+ */
222
304
  show(){
223
305
  showHtmlElement(this.#_host);
224
306
  }
225
307
 
308
+ /**
309
+ * @param {none}
310
+ * @returns {none}
311
+ * @description Hides an element.
312
+ */
226
313
  hide(){
227
314
  hideHtmlElement(this.#_host);
228
315
  }
229
316
 
317
+ /**
318
+ * @param {none}
319
+ * @returns {none}
320
+ * @description not implemented yet.
321
+ */
230
322
  clear(){
231
323
  // // TODO:
232
324
  }
233
325
 
326
+ /**
327
+ * @param {ID_STRING}
328
+ * @param {object}
329
+ * @returns {?THtmlInputField}
330
+ * @static
331
+ * @description Creates a new element.
332
+ */
234
333
  static create(name, opt){
235
334
  const eholds = THtmlInputField.createElement(name, opt, true);
236
335
  const { field } = eholds;
@@ -241,6 +340,23 @@ class THtmlInputField {
241
340
  );
242
341
  }
243
342
 
343
+ /**
344
+ * @param {ID_STRING}
345
+ * @param {object} [opt]
346
+ * @param {object} [opt.host]
347
+ * @param {ID_STRING} [opt.idPref]
348
+ * @param {object} [opt.label]
349
+ * @param {object} [opt.labelPosition]
350
+ * @param {bool} [opt.useDelim]
351
+ * @param {object} [opt.baseClassID]
352
+ * @param {string} [opt.hint]
353
+ * @param {object} [opt.type]
354
+ * @param {bool} [opt.readonly]
355
+ * @param {bool} [doRetChild=false]
356
+ * @returns {(HTMLElement|object)}
357
+ * @static
358
+ * @description Creates a new elements.
359
+ */
244
360
  static createElement(name, opt, doRetChild){
245
361
  const id = valueToIDString(name);
246
362
  const _options = isPlainObject(opt) ? opt : {};
@@ -268,12 +384,12 @@ class THtmlInputField {
268
384
  bcidLabel = valueToClassList(bcidLabel);
269
385
  bcidField = valueToClassList(bcidField);
270
386
  idPref = valueToIDString(idPref);
271
- hint = readAsString(hint, '', true);
387
+ hint = readAsString(hint, true);
272
388
  ({ type: fldType, subtype: fldSubType } = getInputFieldTypeDescr(fldType));
273
389
  if (fldSubType === 'switch') bcidField.push('switch');
274
390
  labelPosition = getLabelPositionID(labelPosition);
275
391
  if (typeof useDelim !== 'boolean') useDelim = true;
276
- label = readAsString(label, '', true);
392
+ label = readAsString(label, true);
277
393
  if (label !== '') label = `${label}${useDelim ? ':' : ''}`;
278
394
  isReadOnly = readAsBool(isReadOnly, true);
279
395
  let fldID = idPref === '' ? id : `${idPref}-${id}`;
@@ -331,6 +447,12 @@ class THtmlInputField {
331
447
  );
332
448
  }
333
449
 
450
+ /**
451
+ * @param {ID_STRING}
452
+ * @param {func}
453
+ * @returns {none}
454
+ * @description Sets a callback function to handle event.
455
+ */
334
456
  on(name, evnt){
335
457
  pushEventHandler(this.#_events, name, evnt);
336
458
  }