@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.019-20250416]
1
+ // [v0.1.023-20250827]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -19,7 +19,7 @@ const {
19
19
  pushEventHandler, triggerEventHandler,
20
20
  } = require('./mod-hfunc.js');
21
21
 
22
- // === module extra block (helper functions) ===
22
+ // === module inner block ===
23
23
 
24
24
  const lpAllowedValues = new Map([
25
25
  [ 'before', 0 ],
@@ -28,18 +28,18 @@ const lpAllowedValues = new Map([
28
28
  ]);
29
29
 
30
30
  /**
31
+ * An input field type descriptor
31
32
  * @typedef {Object} ifcTypeDesc
32
- * @property {string} type - type
33
- * @property {string} subtype - subtype
34
- * @description An input field type description
33
+ * @property {string} type - field general type
34
+ * @property {string} subtype - field sub-type
35
35
  */
36
36
 
37
37
  /**
38
+ * Returns field description by a given type.
38
39
  * @function getInputFieldTypeDescr
39
- * @param {string} value
40
+ * @param {string} value - field type
40
41
  * @returns {ifcTypeDesc}
41
42
  * @inner
42
- * @description Returns field description by a given type.
43
43
  */
44
44
  function getInputFieldTypeDescr(value) {
45
45
  let fldType = readAsString(value, { useTrim: true });
@@ -69,14 +69,14 @@ function getInputFieldTypeDescr(value) {
69
69
  };
70
70
 
71
71
  /**
72
+ * Returns label position ID by its name.
72
73
  * @function getLabelPositionID
73
- * @param {string} value
74
+ * @param {string} value - label position identifier
74
75
  * @returns {number}
75
76
  * @inner
76
- * @description Returns label position ID by its name.
77
77
  */
78
78
  function getLabelPositionID(value) {
79
- let key = readAsString(value, true);
79
+ let key = readAsString(value, { useTrim: true });
80
80
  if (!lpAllowedValues.has(key)) key = 'default';
81
81
  return lpAllowedValues.get(key);
82
82
  };
@@ -96,35 +96,35 @@ function getLabelPositionID(value) {
96
96
  */
97
97
 
98
98
  /**
99
+ * An options set for create ifc
99
100
  * @typedef {Object} OPT_ifcdesc
100
- * @property {object} [host]
101
+ * @property {HTMLElement} [host] - host element
101
102
  * @property {string} [idPref]
102
- * @property {object} [label]
103
+ * @property {string} [label] - text of a label
103
104
  * @property {object} [labelPosition]
104
105
  * @property {boolean} [useDelim]
105
106
  * @property {object} [baseClassID]
106
- * @property {string} [hint]
107
- * @property {object} [type]
107
+ * @property {string} [hint] - hint to show when empty
108
+ * @property {string} [type] - field type
108
109
  * @property {boolean} [readonly] - mode flag
109
- * @description An options set for create ifc
110
110
  */
111
111
 
112
112
  /**
113
+ * An options set for `THtmlInputField`-class
113
114
  * @typedef {Object} OPT_ifcsett
114
115
  * @property {string} [idPref]
115
116
  * @property {(string|string[])} [baseClassID]
116
- * @property {string} [hint]
117
- * @property {string} [type]
117
+ * @property {string} [hint] - hint to show when empty
118
+ * @property {string} [type] - field type
118
119
  * @property {boolean} [readonly=true] - mode flag
119
- * @description An options set for `THtmlInputField`-class
120
120
  */
121
121
 
122
122
  /**
123
+ * A descriptor for an input field elements set.
123
124
  * @typedef {Object} ifcElementsDesc
124
125
  * @property {HTMLElement} host - host element
125
126
  * @property {HTMLElement} label - label element
126
127
  * @property {HTMLElement} field - field element
127
- * @description A description for input field elements set.
128
128
  */
129
129
 
130
130
  /**
@@ -142,13 +142,13 @@ class THtmlInputField {
142
142
  /** @type {OPT_ifcsett} */
143
143
  #_options = null;
144
144
  /**
145
+ * A controller status
145
146
  * @typedef {Object} statIFCtrl
146
- * @property {string} fldType
147
- * @property {string} fldSubType
148
- * @property {boolean} isReadOnly
149
- * @property {boolean} isModified
147
+ * @property {string} fldType - field general type
148
+ * @property {string} fldSubType - field sub-type
149
+ * @property {boolean} isReadOnly - mode flag
150
+ * @property {boolean} isModified - indicates whether any changes was made
150
151
  * @inner
151
- * @description A controller status
152
152
  */
153
153
  /** @type {statIFCtrl} */
154
154
  #_status;// = null;
@@ -156,10 +156,10 @@ class THtmlInputField {
156
156
  #_events;// = null;
157
157
 
158
158
  /**
159
+ * Creates an instance of an input field element
159
160
  * @param {string} name - <*reserved*>
160
161
  * @param {ifcElementsDesc} eholds - elements set
161
162
  * @param {OPT_ifcsett} [opt] - options
162
- * @description Creates an instance of an input field element
163
163
  */
164
164
  constructor(name, eholds, opt) {
165
165
  // load elements
@@ -271,7 +271,7 @@ class THtmlInputField {
271
271
  };
272
272
 
273
273
  /**
274
- * @param {object} e
274
+ * @param {object} e - event
275
275
  * @returns {void}
276
276
  * @private
277
277
  * @fires THtmlInputField#value-changed
@@ -294,7 +294,7 @@ class THtmlInputField {
294
294
  };
295
295
 
296
296
  /**
297
- * @param {object} e
297
+ * @param {object} e - event
298
298
  * @returns {void}
299
299
  * @private
300
300
  * @fires THtmlInputField#value-empty
@@ -320,7 +320,7 @@ class THtmlInputField {
320
320
  };
321
321
 
322
322
  /**
323
- * @param {object} e
323
+ * @param {object} e - event
324
324
  * @returns {void}
325
325
  * @private
326
326
  */
@@ -331,9 +331,9 @@ class THtmlInputField {
331
331
  };
332
332
 
333
333
  /**
334
+ * Tries to attach an element to a given target.
334
335
  * @param {HTMLElement} target - target element
335
336
  * @returns {boolean}
336
- * @description Tries to attach an element to a given target.
337
337
  */
338
338
  attachTo(target) {
339
339
  const host = this.#_host;
@@ -349,32 +349,32 @@ class THtmlInputField {
349
349
  }
350
350
 
351
351
  /**
352
+ * Checks if a value of an element is not set.
352
353
  * @returns {boolean}
353
- * @description Checks if a value of an element is not set.
354
354
  */
355
355
  isEmpty() {
356
356
  return isEmptyString(this.value);
357
357
  }
358
358
 
359
359
  /**
360
+ * Checks if a value of an element is set.
360
361
  * @returns {boolean}
361
- * @description Checks if a value of an element is set.
362
362
  */
363
363
  isNotEmpty() {
364
364
  return isNotEmptyString(this.value);
365
365
  }
366
366
 
367
367
  /**
368
+ * Shows an element.
368
369
  * @returns {void}
369
- * @description Shows an element.
370
370
  */
371
371
  show() {
372
372
  showHTMLElement(this.#_host);
373
373
  }
374
374
 
375
375
  /**
376
+ * Hides an element.
376
377
  * @returns {void}
377
- * @description Hides an element.
378
378
  */
379
379
  hide() {
380
380
  hideHTMLElement(this.#_host);
@@ -382,18 +382,18 @@ class THtmlInputField {
382
382
 
383
383
  /**
384
384
  * @returns {void}
385
- * @description not implemented yet.
385
+ * @todo not implemented yet.
386
386
  */
387
387
  clear() {
388
388
  // // TODO:
389
389
  }
390
390
 
391
391
  /**
392
+ * Creates a new instance.
392
393
  * @param {string} name - <*reserved*>
393
394
  * @param {OPT_ifcdesc} opt - options
394
395
  * @returns {?THtmlInputField}
395
396
  * @static
396
- * @description Creates a new element.
397
397
  */
398
398
  static create(name, opt) {
399
399
  const eholds = THtmlInputField.createElement(name, opt, true);
@@ -406,12 +406,12 @@ class THtmlInputField {
406
406
  }
407
407
 
408
408
  /**
409
+ * Creates a new elements.
409
410
  * @param {string} name
410
411
  * @param {OPT_ifcdesc} [opt] - options
411
412
  * @param {boolean} [doRetChild=false] - mode flag
412
413
  * @returns {(HTMLElement|ifcElementsDesc)}
413
414
  * @static
414
- * @description Creates a new elements.
415
415
  */
416
416
  static createElement(name, opt, doRetChild) {
417
417
  const id = valueToIDString(name);
@@ -441,18 +441,18 @@ class THtmlInputField {
441
441
  bcidLabel = valueToClassList(bcidLabel);
442
442
  bcidField = valueToClassList(bcidField);
443
443
  idPref = valueToIDString(idPref);
444
- hint = readAsString(hint, true);
444
+ hint = readAsString(hint, { useTrim: true });
445
445
  ({ type: fldType, subtype: fldSubType } = getInputFieldTypeDescr(fldType));
446
446
  if (fldSubType === 'switch') bcidField.push('switch');
447
447
  labelPosition = getLabelPositionID(labelPosition);
448
448
  if (typeof useDelim !== 'boolean') useDelim = true;
449
- label = readAsString(label, true);
449
+ label = readAsString(label, { useTrim: true });
450
450
  if (label !== '') label = `${label}${useDelim ? ':' : ''}`;
451
451
  isReadOnly = readAsBool(isReadOnly, true);
452
452
  let fldID = idPref === '' ? id : `${idPref}-${id}`;
453
453
  if (!isHTMLElement(host)) {
454
454
  host = createNewHTMLElement('div', {
455
- class: bcidHost,
455
+ classNames: bcidHost,
456
456
  });
457
457
  };
458
458
  let lblHolder = null;
@@ -466,7 +466,7 @@ class THtmlInputField {
466
466
  attr: {
467
467
  for: fldID,
468
468
  },
469
- class: bcidLabel,
469
+ classNames: bcidLabel,
470
470
  });
471
471
  };
472
472
  fldHolder = host.querySelector(`input#${fldID}`);
@@ -477,7 +477,7 @@ class THtmlInputField {
477
477
  type: fldType,
478
478
  placeholder: hint,
479
479
  },
480
- class: bcidField,
480
+ classNames: bcidField,
481
481
  });
482
482
  };
483
483
  if (fldHolder) {
@@ -505,10 +505,10 @@ class THtmlInputField {
505
505
  }
506
506
 
507
507
  /**
508
+ * Sets a callback function to handle event.
508
509
  * @param {string} name - event name
509
510
  * @param {func} evnt - callback function
510
511
  * @returns {void}
511
- * @description Sets a callback function to handle event.
512
512
  */
513
513
  on(name, evnt) {
514
514
  pushEventHandler(this.#_events, name, evnt);