@cntwg/html-helper 0.0.16 → 0.0.18

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 ADDED
@@ -0,0 +1,165 @@
1
+ #### *v0.0.18*
2
+
3
+ Pre-release version.
4
+
5
+ > - `html-helper-lib.md` updated;
6
+ > - some fixes in `html-helper-lib.js` module;
7
+ > - add `mod-hfunc.js` module;
8
+ > - rename module `html-ctrls-list.js` to `html-ctrls/list.js`;
9
+ > - some fixes in `list.js` module;
10
+ > - rename module `html-ctrls-btn.js` to `html-ctrls/buttons.js`;
11
+ > - some fixes in `buttons.js` module;
12
+ > - some fixes in `lists-btn.js` module;
13
+ > - some fixes in `lists-stubs.js` module;
14
+ > - add function `readAsAttrValue` into `html-helper-lib.js` module;
15
+ > - add settings `itemBaseClassID` to `THtmlItemsListContainer` class constructor `options` parameter;
16
+ > - added 'component' property for module exports;
17
+ > - deprecated 'classes' property for module exports (*use `component` instead*);
18
+
19
+ #### *v0.0.17*
20
+
21
+ Pre-release version.
22
+
23
+ > improved event logic on items deletion for `THtmlItemsListController` class.
24
+
25
+ #### *v0.0.16*
26
+
27
+ Pre-release version.
28
+
29
+ > improved items selection logic for `THtmlItemsListController` class.
30
+
31
+ #### *v0.0.15*
32
+
33
+ Pre-release version.
34
+
35
+ > - `html-helper-lib.md` updated;
36
+ > - `html-ctrls-list.md` updated;
37
+ > - some fixes in `html-ctrls-btn.js` module;
38
+ > - some fixes in `html-ctrls-list.js` module;
39
+ > - alter behavior for the `srchIndexByAttr` method of a `THtmlItemsListContainer` class (*see docs for details*);
40
+ > - add settings `markCurrentItem` to `THtmlItemsListContainer` class constructor `options` parameter;
41
+ > - add function `valueToIDString` into `html-helper-lib.js` module;
42
+
43
+ #### *v0.0.14*
44
+
45
+ Pre-release version.
46
+
47
+ > - `html-ctrls-list.md` updated;
48
+ > - some fixes in `html-ctrls/list-stubs.js` module;
49
+ > - alter behavior for the `loadItems` method of a `THtmlStubItemsSet` class in case when its `options` parameter is set to `boolean` (see `html-ctrls-list.md` for details);
50
+ > - added method `rstDefItem` to `THtmlStubItemsSet` class;
51
+ > - added `THtmlButtonsControllerARCSet` class.
52
+
53
+ #### *v0.0.13*
54
+
55
+ Pre-release version.
56
+
57
+ > - `html-helper-lib.md` updated;
58
+ > - `html-ctrls-btn.md` updated;
59
+ > - `html-ctrls-list.md` updated;
60
+ > - some fixes in `html-helper-lib.js` module;
61
+ > - some fixes in `html-ctrls-btn.js` module;
62
+ > - some fixes in `html-ctrls-list.js` module;
63
+ > - move definition of `THtmlStubItemsSet` from `html-ctrls-list.js` module to `html-ctrls/lists-stubs.js` submodule;
64
+ > - add function `valueToClassList` into `html-helper-lib.js` module;
65
+ > - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.2.
66
+
67
+ #### *v0.0.12*
68
+
69
+ Pre-release version.
70
+
71
+ > - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.1.
72
+
73
+ #### *v0.0.11*
74
+
75
+ Pre-release version.
76
+
77
+ > - `html-ctrls-btn.md` updated;
78
+ > - `html-ctrls-list.md` updated;
79
+ > - some fixes in `html-ctrls-list.js` module;
80
+ > - some fixes in `html-ctrls-btn.js` module.
81
+
82
+ #### *v0.0.10*
83
+
84
+ Pre-release version.
85
+
86
+ > - `html-ctrls-btn.md` updated;
87
+ > - added `THtmlListButtonsController` class;
88
+
89
+ #### *v0.0.9*
90
+
91
+ Pre-release version.
92
+
93
+ > - switch dependency from `@cntwg/bsfoc-lib-js` module to `@ygracs/bsfoc-lib-js` module.
94
+
95
+ #### *v0.0.8*
96
+
97
+ Pre-release version.
98
+
99
+ > - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.11.
100
+
101
+ #### *v0.0.7*
102
+
103
+ Pre-release version.
104
+
105
+ > - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.10;
106
+ > - some fixes in `html-helper-lib.js` module;
107
+ > - some fixes in `html-ctrls-list.js` module.
108
+
109
+ #### *v0.0.6*
110
+
111
+ Pre-release version.
112
+
113
+ > - `html-ctrls-btn.md` updated;
114
+ > - `html-ctrls-list.md` updated;
115
+ > - `html-helper-lib.md` updated;
116
+ > - some fixes in `html-ctrls-btn.js` module;
117
+ > - some fixes in `html-ctrls-list.js` module.
118
+
119
+ #### *v0.0.5*
120
+
121
+ Pre-release version.
122
+
123
+ > - `$module/test/README.md` added;
124
+ > - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.8;
125
+ > - `html-ctrls-list.md` updated;
126
+ > - added `minIndex` property to `THtmlItemsListContainer` class;
127
+ > - some fixes in `html-ctrls-list.js` module;
128
+ > - added 'classes' property for module exports;
129
+ > - MIT-license applied.
130
+
131
+ #### *v0.0.4*
132
+
133
+ Pre-release version.
134
+
135
+ > - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.5.
136
+
137
+ #### *v0.0.3*
138
+
139
+ Pre-release version.
140
+
141
+ > - added `activateHTMLElements` function;
142
+ > - added `inactivateHTMLElements` function;
143
+ > - added `createNewHtmlElement` function (experimental);
144
+ > - `html-helper-lib.md` updated;
145
+ > - `html-ctrls-btn.md` updated;
146
+ > - `html-ctrls-list.md` updated.
147
+
148
+ #### *v0.0.2*
149
+
150
+ Pre-release version.
151
+
152
+ > - `README.md` added;
153
+ > - `html-helper-lib.md` added to `doc`;
154
+ > - `html-ctrls-btn.md` added to `doc`;
155
+ > - `html-ctrls-list.md` added to `doc`;
156
+ > - added `CSS_CLASS_ACTIVE` constant to `CSS_CLASS_STRING`;
157
+ > - added `isActiveHTMLElement` function;
158
+ > - added `markHtmlElementAsActive` function;
159
+ > - added `unmarkActiveHtmlElement` function;
160
+ > - `html-btn-ctrl.js` was renamed `html-ctrls-btn.js`;
161
+ > - `html-list-ctrl.js` was renamed `html-ctrls-list.js`.
162
+
163
+ #### *v0.0.1*
164
+
165
+ Pre-release version.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019-2022 Yuri Grachev
3
+ Copyright (c) 2019-2023 Yuri Grachev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.2|
1
+ >|***rev.*:**|0.1.3|
2
2
  >|:---|---:|
3
- >|date:|2022-09-12|
3
+ >|date:|2023-04-09|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -10,6 +10,10 @@ This module provide a base set of helpers for javascript. So your work can run a
10
10
 
11
11
  This module was make for use as a library in a development of a Web-apps based on [Electron](https://en.wikipedia.org/wiki/Electron_(software_framework)) as main target.
12
12
 
13
+ ### Installation
14
+
15
+ `npm install @cntwg/html-helper`
16
+
13
17
  ## Description
14
18
 
15
19
  This module contains the following components:
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.11|
1
+ >|***rev.*:**|0.1.14|
2
2
  >|:---|---:|
3
- >|date:|2022-09-25|
3
+ >|date:|2023-04-04|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -27,6 +27,7 @@ The `options` structure has listed below:
27
27
  |:---|---|---:|:---|
28
28
  |`autoHideNewItems`|`boolean`|`false`|alters behavior of the `addItem` class method. If set to `true`, the item which was added to a container members will be automatically hidden|
29
29
  |`markCurrentItem`|`boolean`|`false`|alters behavior of the `setCurIndex` class method. If set to `true`, the item which was added to a container members will be automatically marked as current|
30
+ |`itemBaseClassID`|`array`|---|alters behavior of the `addItem` class method. It accepts value of a string or an array of strings. For more see description of an `addItem` method|
30
31
 
31
32
  #### class properties
32
33
 
@@ -112,6 +113,8 @@ This method adds a given item to a container members and if succeed returns its
112
113
 
113
114
  If `options` parameter is given and is set to `true`, in case of success, the `curIndex` property is adjusted by the method.
114
115
 
116
+ If `itemBaseClassID` option of the container is set, the method will applied a value given by this option as a `class` attribute of an item which was successfully added.
117
+
115
118
  ##### **delItem(index\[, options])**
116
119
 
117
120
  This method deletes an item addressed by the given `index` from a container members and if succeed `true` is returned.
@@ -161,8 +164,9 @@ The `options` structure has listed below:
161
164
 
162
165
  |option name|value type|default value|description|
163
166
  |:---|---|---:|:---|
164
- |`autoHideNewItems`|`boolean`|`false`|alters behavior of the `addItem` class method. If set to `true`, the item which was added to a container members will be automatically hidden|
165
- |`markCurrentItem`|`boolean`|`false`|alters behavior of the `setCurIndex` class method. If set to `true`, the item which was added to a container members will be automatically marked as current|
167
+ |`autoHideNewItems`|`boolean`|`false`|for details see options on `THtmlItemsListContainer` class constructor section|
168
+ |`markCurrentItem`|`boolean`|`false`|for details see options on `THtmlItemsListContainer` class constructor section|
169
+ |`itemBaseClassID`|`array`|---|for details see options on `THtmlItemsListContainer` class constructor section|
166
170
  |`showStubsIfEmpty`|`boolean`|`false`|if set, in case of the empty list, the default stub-item will be displayed|
167
171
  |`allowGroupSelection`|`boolean`|`false`|if set the more than one element can be selected in the list|
168
172
  |`allowSelectionLocks`|`boolean`|`false`|<*reserved, experimental*>|
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.4|
1
+ >|***rev.*:**|0.1.5|
2
2
  >|:---|---:|
3
- >|date:|2022-09-22|
3
+ >|date:|2023-03-30|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -120,3 +120,7 @@ This function make all the jobs under the hood. So there is no need to call DOM-
120
120
  #### **valueToIDString(value)**
121
121
 
122
122
  This function tries to convert a given `value` to `ID_STRING`. If failed an empty string is returned.
123
+
124
+ #### **readAsAttrValue(value)**
125
+
126
+ This function tries to convert a given `value` to the value of type which is suitable for an HTML-element's attribute. If failed a `null` is returned.
package/index.js CHANGED
@@ -1,12 +1,12 @@
1
- // [v0.1.010-20220922]
1
+ // [v0.1.016-20230409]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const html_helper = require('./lib/html-helper-lib.js');
6
- const html_list = require('./lib/html-ctrls-list.js');
7
- const html_bts = require('./lib/html-ctrls-btn.js');
6
+ const html_list = require('./lib/html-ctrls/list.js');
7
+ const html_bts = require('./lib/html-ctrls/buttons.js');
8
8
 
9
- const html_list_btn = require('./lib/html-ctrls/lists-btns.js');
9
+ const html_list_btn = require('./lib/html-ctrls/lists-btn.js');
10
10
 
11
11
  // === module extra block (helper functions) ===
12
12
 
@@ -44,9 +44,10 @@ exports.THtmlListButtonsController = html_list_btn.THtmlListButtonsController;
44
44
 
45
45
  // experimental
46
46
  exports.valueToIDString = html_helper.valueToIDString;
47
+ exports.readAsAttrValue = html_helper.readAsAttrValue;
47
48
  exports.createNewHtmlElement = html_helper.createNewHtmlElement;
48
49
 
49
- exports.classes = {
50
+ exports.component = {
50
51
  THtmlStubItemsSet: exports.THtmlStubItemsSet,
51
52
  THtmlItemsListContainer: exports.THtmlItemsListContainer,
52
53
  THtmlItemsListController: exports.THtmlItemsListController,
@@ -54,3 +55,5 @@ exports.classes = {
54
55
  THtmlListButtonsController: exports.THtmlListButtonsController,
55
56
  THtmlButtonsControllerARCSet: exports.THtmlButtonsControllerARCSet,
56
57
  };
58
+ // will deprecate
59
+ exports.classes = exports.component;
@@ -1,9 +1,11 @@
1
- // [v0.1.043-20220922]
1
+ // [v0.1.047-20230408]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- readAsString, readAsNumber, isNotEmptyString,
6
+ //readAsString,
7
+ //readAsNumber,
8
+ isNotEmptyString,
7
9
  isPlainObject, valueToArray,
8
10
  TItemsICollection,
9
11
  } = require('@ygracs/bsfoc-lib-js');
@@ -11,7 +13,11 @@ const {
11
13
  const {
12
14
  isHTMLElement, CSS_CLASS_STRING,
13
15
  valueToIDString,
14
- } = require('./html-helper-lib.js');
16
+ } = require('../html-helper-lib.js');
17
+
18
+ const {
19
+ pushEventHandler, triggerEventHandler,
20
+ } = require('./mod-hfunc.js');
15
21
 
16
22
  const {
17
23
  CSS_CLASS_SELECTED,
@@ -25,25 +31,54 @@ const etlHTagInputForBtn = new Set([
25
31
  'button', 'submit', 'reset', 'image',
26
32
  ]);
27
33
 
28
- // === module extra block (function definitions) ===
34
+ // === module extra block (helper functions) ===
29
35
 
30
36
  function isHTMLButton(obj){
31
37
  let result = false;
32
38
  if (isHTMLElement(obj)) {
33
39
  switch (obj.tagName.toLowerCase()) {
34
- case 'button':
40
+ case 'button': {
35
41
  result = true;
36
42
  break;
37
- case 'input':
43
+ }
44
+ case 'input': {
38
45
  result = etlHTagInputForBtn.has(obj.type.toLowerCase());
39
46
  break;
40
- default:
47
+ }
48
+ default: {
41
49
  break;
50
+ }
42
51
  };
43
52
  };
44
53
  return result;
45
54
  }
46
55
 
56
+ function readOnClickEventInfo(e) {
57
+ let item = null;
58
+ //let on_click_num = readAsNumber(e.detail, 0);
59
+ const { eventPhase, detail: onClickNum } = e;
60
+ //console.log('CHECK: e => ditail:['+onClickNum+']');
61
+ //console.log('CHECK: e => phase:['+eventPhase+']');
62
+ switch (eventPhase) {
63
+ //*case 1:
64
+ //* // NOTE: currently on eventPhase = 2 and 3
65
+ case 2: {
66
+ /**/// capturing stage
67
+ item = e.target;
68
+ break;
69
+ }
70
+ case 3: {
71
+ /**/// bubblig stage
72
+ item = e.currentTarget;
73
+ break;
74
+ }
75
+ default: {
76
+ break;
77
+ }
78
+ };
79
+ return { item, onClickNum };
80
+ };
81
+
47
82
  // === module main block (function definitions) ===
48
83
 
49
84
  // === module main block (class definitions) ===
@@ -54,7 +89,6 @@ class THtmlButtonsSet {
54
89
  constructor(){
55
90
  // define default functions for manipulators
56
91
  const __user_index_getter = (value) => {
57
- //return readAsString(value, '', { useTrim: true, numberToString: true });
58
92
  return valueToIDString(value);
59
93
  };
60
94
  const __user_item_getter = (value) => {
@@ -206,28 +240,11 @@ class THtmlButtonsControllerARCSet {
206
240
  #_on_btn_apply_pressed = (e) => {
207
241
  //console.log('THtmlListButtonsController._on_btn_apply_pressed() ==> was called...');
208
242
  //e.preventDefault(); /* need to reconsider reason for use */
209
- let curItem = null;
210
- let on_click_num = readAsNumber(e.detail, 0);
211
- //console.log('CHECK: e => ditail:['+on_click_num+']');
212
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
213
- switch (e.eventPhase) {
214
- //*case 1:
215
- //* // NOTE: currently on eventPhase = 2 and 3
216
- case 2:
217
- /**/// capturing stage
218
- curItem = e.target;
219
- break;
220
- case 3:
221
- /**/// bubblig stage
222
- curItem = e.currentTarget;
223
- break;
224
- default:
225
- break;
226
- };
243
+ const { item, onClickNum } = readOnClickEventInfo(e);
227
244
  if (
228
- curItem instanceof HTMLElement
229
- && (on_click_num === 0 || on_click_num === 1)
230
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
245
+ item instanceof HTMLElement
246
+ && (onClickNum === 0 || onClickNum === 1)
247
+ && !item.classList.contains(CSS_CLASS_DISABLED)
231
248
  ) {
232
249
  this.#_triggerEvent('btn-apply-pressed', e);
233
250
  };
@@ -236,28 +253,11 @@ class THtmlButtonsControllerARCSet {
236
253
  #_on_btn_reset_pressed = (e) => {
237
254
  //console.log('THtmlListButtonsController._on_btn_reset_pressed() ==> was called...');
238
255
  //e.preventDefault(); /* need to reconsider reason for use */
239
- let curItem = null;
240
- let on_click_num = readAsNumber(e.detail, 0);
241
- //console.log('CHECK: e => ditail:['+on_click_num+']');
242
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
243
- switch (e.eventPhase) {
244
- //*case 1:
245
- //* // NOTE: currently on eventPhase = 2 and 3
246
- case 2:
247
- /**/// capturing stage
248
- curItem = e.target;
249
- break;
250
- case 3:
251
- /**/// bubblig stage
252
- curItem = e.currentTarget;
253
- break;
254
- default:
255
- break;
256
- };
256
+ const { item, onClickNum } = readOnClickEventInfo(e);
257
257
  if (
258
- curItem instanceof HTMLElement
259
- && (on_click_num === 0 || on_click_num === 1)
260
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
258
+ item instanceof HTMLElement
259
+ && (onClickNum === 0 || onClickNum === 1)
260
+ && !item.classList.contains(CSS_CLASS_DISABLED)
261
261
  ) {
262
262
  this.#_triggerEvent('btn-reset-pressed', e);
263
263
  };
@@ -266,39 +266,18 @@ class THtmlButtonsControllerARCSet {
266
266
  #_on_btn_cancel_pressed = (e) => {
267
267
  //console.log('THtmlListButtonsController._on_btn_cancel_pressed() ==> was called...');
268
268
  //e.preventDefault(); /* need to reconsider reason for use */
269
- let curItem = null;
270
- let on_click_num = readAsNumber(e.detail, 0);
271
- //console.log('CHECK: e => ditail:['+on_click_num+']');
272
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
273
- switch (e.eventPhase) {
274
- //*case 1:
275
- //* // NOTE: currently on eventPhase = 2 and 3
276
- case 2:
277
- /**/// capturing stage
278
- curItem = e.target;
279
- break;
280
- case 3:
281
- /**/// bubblig stage
282
- curItem = e.currentTarget;
283
- break;
284
- default:
285
- break;
286
- };
269
+ const { item, onClickNum } = readOnClickEventInfo(e);
287
270
  if (
288
- curItem instanceof HTMLElement
289
- && (on_click_num === 0 || on_click_num === 1)
290
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
271
+ item instanceof HTMLElement
272
+ && (onClickNum === 0 || onClickNum === 1)
273
+ && !item.classList.contains(CSS_CLASS_DISABLED)
291
274
  ) {
292
275
  this.#_triggerEvent('btn-cancel-pressed', e);
293
276
  };
294
277
  }
295
278
 
296
279
  #_triggerEvent = (name, ...args) => {
297
- const _name = typeof name === 'string' ? name.trim() : '';
298
- if (_name !== '') {
299
- const _events = this.#_events;
300
- if (_events.has(_name)) _events.get(name)(...args);
301
- };
280
+ triggerEventHandler(this.#_events, name, ...args);
302
281
  }
303
282
 
304
283
  disableMain(){
@@ -318,18 +297,7 @@ class THtmlButtonsControllerARCSet {
318
297
  }
319
298
 
320
299
  on(name, evnt){
321
- const _name = typeof name === 'string' ? name.trim() : '';
322
- if (_name !== '' && typeof evnt === 'function') {
323
- const _events = this.#_events;
324
- if (!_events.has(_name)) {
325
- _events.set(_name, evnt);
326
- } else {
327
- /* NOTE:
328
- * for current you can't reset or set new one on the same event
329
- */
330
- //console.log('THtmlListButtonsController.on() ==> event:['+name+'] - already exists...');
331
- };
332
- };
300
+ pushEventHandler(this.#_events, name, evnt);
333
301
  }
334
302
  };
335
303
 
@@ -341,3 +309,5 @@ exports.THtmlButtonsControllerARCSet = THtmlButtonsControllerARCSet;
341
309
  exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
342
310
 
343
311
  exports.isHTMLButton = isHTMLButton;
312
+
313
+ exports.readOnClickEventInfo = readOnClickEventInfo;
@@ -1,12 +1,9 @@
1
- // [v0.1.051-20221009]
1
+ // [v0.1.060-20230408]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- //readAsBool,
7
6
  readAsNumber,
8
- //valueToIndex,
9
- //isArray, isObject,
10
7
  isPlainObject,
11
8
  TItemsListEx,
12
9
  } = require('@ygracs/bsfoc-lib-js');
@@ -16,10 +13,15 @@ const {
16
13
  showHtmlElement, hideHtmlElement,
17
14
  selectHtmlElement, unselectHtmlElement,
18
15
  markHtmlElementAsCurrent, unmarkCurrentHtmlElement,
16
+ readAsAttrValue, valueToClassList,
19
17
  CSS_CLASS_STRING,
20
- } = require('./html-helper-lib.js');
18
+ } = require('../html-helper-lib.js');
21
19
 
22
- const { THtmlStubItemsSet } = require('./html-ctrls/lists-stubs.js');
20
+ const { THtmlStubItemsSet } = require('./lists-stubs.js');
21
+
22
+ const {
23
+ pushEventHandler, triggerEventHandler,
24
+ } = require('./mod-hfunc.js');
23
25
 
24
26
  const {
25
27
  CSS_CLASS_SELECTED,
@@ -35,23 +37,28 @@ const ILC_SMODE_CTRL = 2;
35
37
 
36
38
  // === module extra block (helper functions) ===
37
39
 
38
- function readAsAttrValue(value){
39
- let result = null;
40
- switch (typeof value) {
41
- case 'boolean':
42
- result = value.toString();
43
- break;
44
- case 'number':
45
- if (Number.isNaN(value)) break;
46
- result = value.toString();
47
- break;
48
- case 'string':
49
- result = value.trim();
50
- break;
51
- default:
52
- break;
40
+ function srchListElementByAttr(list, name, value = '') {
41
+ const _value = readAsAttrValue(value);
42
+ let item = null;
43
+ let index = -1;
44
+ let count = list.count;
45
+ let isACCEPTED = false;
46
+ if (count > 0 && name !== '' && _value !== null) {
47
+ const acceptAnyVal = _value === '';
48
+ for (let i = 0; i < count; i++) {
49
+ item = list.getItem(i);
50
+ if (
51
+ isHTMLElement(item)
52
+ && item.hasAttribute(name)
53
+ && (acceptAnyVal || item.getAttribute(name) === value)
54
+ ) {
55
+ index = i;
56
+ isACCEPTED = true;
57
+ break;
58
+ };
59
+ };
53
60
  };
54
- return result;
61
+ return isACCEPTED ? { index, item } : { index, item: null };
55
62
  };
56
63
 
57
64
  // === module main block (function definitions) ===
@@ -75,6 +82,7 @@ class THtmlItemsListContainer {
75
82
  let {
76
83
  autoHideNewItems,
77
84
  markCurrentItem,
85
+ itemBaseClassID,
78
86
  } = _options;
79
87
  if (typeof autoHideNewItems !== 'boolean') {
80
88
  _options.autoHideNewItems = autoHideNewItems = false;
@@ -82,6 +90,8 @@ class THtmlItemsListContainer {
82
90
  if (typeof markCurrentItem !== 'boolean') {
83
91
  _options.markCurrentItem = markCurrentItem = false;
84
92
  };
93
+ itemBaseClassID = valueToClassList(itemBaseClassID, true);
94
+ _options.itemBaseClassID = itemBaseClassID;
85
95
  // init status
86
96
  const _status = {
87
97
  curIndex: _items.curIndex,
@@ -152,29 +162,13 @@ class THtmlItemsListContainer {
152
162
 
153
163
  srchIndexByAttr(name, value = ''){
154
164
  const _name = typeof name === 'string' ? name.trim() : '';
155
- const _value = readAsAttrValue(value);
156
- let index = -1;
157
- if (_name !== '' && _value !== null) {
158
- const acceptAnyVal = _value === '';
159
- const _items = this.#_items;
160
- let item = null;
161
- for (let i = 0; i < _items.count; i++) {
162
- item = _items.getItem(i);
163
- if (
164
- isHTMLElement(item)
165
- && item.hasAttribute(_name)
166
- && (acceptAnyVal || item.getAttribute(_name) === _value)
167
- ) {
168
- index = i;
169
- break;
170
- };
171
- };
172
- };
165
+ const { index } = srchListElementByAttr(this.#_items, _name, value);
173
166
  return index;
174
167
  };
175
168
 
176
169
  srchIndexByID(value){
177
- return this.srchIndexByAttr('id', value);
170
+ const { index } = srchListElementByAttr(this.#_items, 'id', value);
171
+ return index;
178
172
  };
179
173
 
180
174
  setCurIndex(index){
@@ -208,12 +202,15 @@ class THtmlItemsListContainer {
208
202
  return isHTMLElement(item) ? item : null;
209
203
  }
210
204
 
211
- getItemByAttr(...args){
212
- return this.getItem(this.srchIndexByAttr(...args));
205
+ getItemByAttr(name, value = ''){
206
+ const _name = typeof name === 'string' ? name.trim() : '';
207
+ const { item } = srchListElementByAttr(this.#_items, _name, value);
208
+ return item;
213
209
  }
214
210
 
215
211
  getItemByID(value){
216
- return this.getItem(this.srchIndexByID(value));
212
+ const { item } = srchListElementByAttr(this.#_items, 'id', value);
213
+ return item;
217
214
  }
218
215
 
219
216
  addItem(item, opt){
@@ -225,26 +222,31 @@ class THtmlItemsListContainer {
225
222
  );
226
223
  const isSUCCEED = index !== -1;
227
224
  if (isSUCCEED) {
228
- if (this.#_options.autoHideNewItems) hideHtmlElement(item);
225
+ const { autoHideNewItems, itemBaseClassID } = this.#_options;
226
+ if (autoHideNewItems) hideHtmlElement(item);
227
+ if (itemBaseClassID.length > 0) item.classList.add(...itemBaseClassID);
229
228
  if (forceCI) this.setCurIndex(index);
230
- if (this.#_host) this.#_host.append(item);
229
+ const _host = this.#_host;
230
+ if (_host) _host.append(item);
231
231
  };
232
232
  return isSUCCEED ? index : -1;
233
233
  }
234
234
 
235
- delItem(index, opt){
236
- const forceCI = typeof opt === 'boolean' ? opt : true;
235
+ delItem(index, opt, optEx){
237
236
  const _items = this.#_items;
238
- const item = _items.delItemEx(index, forceCI);
239
- const isSUCCEED = isHTMLElement(item);
237
+ const item = _items.delItemEx(index, opt);
238
+ const isSUCCEED = item !== undefined;
240
239
  if (isSUCCEED) {
241
- const index = _items.curIndex;
242
- if (index === -1) {
243
- this.rstCurIndex();
244
- } else {
245
- this.setCurIndex(_items.curIndex);
240
+ if (this.#_host && isHTMLElement(item)) item.remove();
241
+ const doProcEx = typeof optEx === 'boolean' ? optEx : true;
242
+ if (doProcEx) {
243
+ const index = _items.curIndex;
244
+ if (index === -1) {
245
+ this.rstCurIndex();
246
+ } else {
247
+ this.setCurIndex(index);
248
+ };
246
249
  };
247
- if (this.#_host) item.remove();
248
250
  };
249
251
  return isSUCCEED;
250
252
  }
@@ -298,6 +300,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
298
300
  let {
299
301
  //autoHideNewItems, // [*] processed by parent
300
302
  //markCurrentItem, // [*] processed by parent
303
+ //itemBaseClassID, // [*] processed by parent
301
304
  showStubsIfEmpty,
302
305
  allowGroupSelection,
303
306
  allowSelectionLocks,
@@ -362,16 +365,19 @@ class THtmlItemsListController extends THtmlItemsListContainer {
362
365
  //* // NOTE: currently on eventPhase = 2 and 3
363
366
  //*case 1:
364
367
  /**/// capturing stage
365
- case 2:
368
+ case 2: {
366
369
  /**/// target stage
367
370
  if (target !== this.#_host) curItem = target;
368
371
  break;
369
- case 3:
372
+ }
373
+ case 3: {
370
374
  /**/// bubblig stage
371
375
  curItem = catchEventOnHost ? target : currentTarget;
372
376
  break;
373
- default:
377
+ }
378
+ default: {
374
379
  break;
380
+ }
375
381
  };
376
382
  if (
377
383
  !isSelectionLocked
@@ -389,11 +395,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
389
395
  };
390
396
 
391
397
  #_triggerEvent = (name, ...args) => {
392
- const _name = typeof name === 'string' ? name.trim() : '';
393
- if (_name !== '') {
394
- const _events = this.#_events;
395
- if (_events.has(_name)) _events.get(_name)(...args);
396
- };
398
+ triggerEventHandler(this.#_events, name, ...args);
397
399
  };
398
400
 
399
401
  get SelectedItems(){
@@ -509,38 +511,44 @@ class THtmlItemsListController extends THtmlItemsListContainer {
509
511
 
510
512
  delItem(index, opt){
511
513
  const item = super.getItem(index);
514
+ let isSUCCEED = item !== undefined;
512
515
  const _status = this.#_status;
513
- let isSUCCEED = isHTMLElement(item);
514
516
  if (isSUCCEED) {
515
517
  _status.execDelItem = true;
516
518
  _status.execDelItemCI = this.curIndex;
517
519
  _status.execDelItemDI = Number(index);
518
- isSUCCEED = super.delItem(index, opt);
520
+ isSUCCEED = super.delItem(index, opt, false);
521
+ if (isSUCCEED) {
522
+ const _options = this.#_options;
523
+ if (!_status.catchEventOnHost && isHTMLElement(item)) {
524
+ // remove event handler on element if it was set by addItem()
525
+ item.removeEventListener('click', this.#_on_will_select_item);
526
+ };
527
+ if (this.isEmpty()) {
528
+ this.#_selects.clear();
529
+ if (_options.showStubsIfEmpty) {
530
+ // show default stub-item
531
+ _status.isStubItemShown = this.#_stubs.showDefItem();
532
+ };
533
+ this.#_triggerEvent('list-clear');
534
+ } else {
535
+ this.#_selects.delete(item);
536
+ this.#_triggerEvent('item-removed', {
537
+ index: Number(index),
538
+ item: item,
539
+ });
540
+ const current = this.curIndex;
541
+ if (current === -1) {
542
+ this.rstCurIndex();
543
+ } else {
544
+ this.setCurIndex(current);
545
+ };
546
+ };
547
+ };
519
548
  _status.execDelItemDI = -1;
520
549
  _status.execDelItemCI = -1;
521
550
  _status.execDelItem = false;
522
551
  };
523
- if (isSUCCEED) {
524
- const _options = this.#_options;
525
- if (!_status.catchEventOnHost) {
526
- // remove event handler on element if it was set by addItem()
527
- item.removeEventListener('click', this.#_on_will_select_item);
528
- };
529
- if (this.isEmpty()) {
530
- this.#_selects.clear();
531
- if (_options.showStubsIfEmpty) {
532
- // show default stub-item
533
- _status.isStubItemShown = this.#_stubs.showDefItem();
534
- };
535
- this.#_triggerEvent('list-clear');
536
- } else {
537
- this.#_selects.delete(item);
538
- this.#_triggerEvent('item-removed', {
539
- index: Number(index),
540
- item: item,
541
- });
542
- };
543
- };
544
552
  return isSUCCEED;
545
553
  }
546
554
 
@@ -589,20 +597,23 @@ class THtmlItemsListController extends THtmlItemsListContainer {
589
597
  _selects.clear();
590
598
  };
591
599
  switch (mode) {
592
- case ILC_SMODE_SHFT:
600
+ case ILC_SMODE_SHFT: {
593
601
  if (indexCI > indexNI) [ indexCI, indexNI ] = [ indexNI, indexCI ];
594
602
  for (let i = indexCI; i < indexNI + 1; i++) {
595
603
  this.#_selectItem(i);
596
604
  };
597
605
  break;
598
- case ILC_SMODE_CTRL:
606
+ }
607
+ case ILC_SMODE_CTRL: {
599
608
  this.#_selectItem(this.srchIndex(item));
600
609
  break;
601
- default:
610
+ }
611
+ default: {
602
612
  if (this.#_selectItem(this.srchIndex(item))) {
603
613
  if (forceCI) this.#_setCurIndex(indexNI);
604
614
  };
605
615
  break;
616
+ }
606
617
  };
607
618
  }
608
619
 
@@ -658,17 +669,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
658
669
  }
659
670
 
660
671
  on(name, evnt){
661
- const _name = typeof name === 'string' ? name.trim() : '';
662
- if (_name !== '' && typeof evnt === 'function') {
663
- const _events = this.#_events;
664
- if (!_events.has(_name)) {
665
- _events.set(_name, evnt);
666
- } else {
667
- /* NOTE:
668
- * for current you can't reset or set new one on the same event
669
- */
670
- };
671
- };
672
+ pushEventHandler(this.#_events, name, evnt);
672
673
  }
673
674
 
674
675
  };
@@ -1,14 +1,14 @@
1
- // [v0.1.042-20220912]
1
+ // [v0.1.045-20230408]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- readAsString,
6
+ //readAsString,
7
7
  readAsNumber,
8
- isNotEmptyString,
8
+ //isNotEmptyString,
9
9
  isPlainObject,
10
- valueToArray,
11
- TItemsICollection,
10
+ //valueToArray,
11
+ //TItemsICollection,
12
12
  } = require('@ygracs/bsfoc-lib-js');
13
13
 
14
14
  const {
@@ -19,7 +19,12 @@ const {
19
19
  const {
20
20
  isHTMLButton,
21
21
  THtmlButtonsSet,
22
- } = require('../html-ctrls-btn');
22
+ readOnClickEventInfo,
23
+ } = require('./buttons.js');
24
+
25
+ const {
26
+ pushEventHandler, triggerEventHandler,
27
+ } = require('./mod-hfunc.js');
23
28
 
24
29
  const {
25
30
  CSS_CLASS_SELECTED,
@@ -101,28 +106,11 @@ class THtmlListButtonsController {
101
106
  #_on_btn_frst_pressed = (e) => {
102
107
  //console.log('THtmlListButtonsController._on_btn_frst_pressed() ==> was called...');
103
108
  //e.preventDefault(); /* need to reconsider reason for use */
104
- let curItem = null;
105
- let on_click_num = readAsNumber(e.detail, 0);
106
- //console.log('CHECK: e => ditail:['+on_click_num+']');
107
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
108
- switch (e.eventPhase) {
109
- //*case 1:
110
- //* // NOTE: currently on eventPhase = 2 and 3
111
- case 2:
112
- /**/// capturing stage
113
- curItem = e.target;
114
- break;
115
- case 3:
116
- /**/// bubblig stage
117
- curItem = e.currentTarget;
118
- break;
119
- default:
120
- break;
121
- };
109
+ const { item, onClickNum } = readOnClickEventInfo(e);
122
110
  if (
123
- curItem instanceof HTMLElement
124
- && (on_click_num === 0 || on_click_num === 1)
125
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
111
+ item instanceof HTMLElement
112
+ && (onClickNum === 0 || onClickNum === 1)
113
+ && !item.classList.contains(CSS_CLASS_DISABLED)
126
114
  ) {
127
115
  this.#_triggerEvent('btn-first-pressed', e);
128
116
  };
@@ -131,28 +119,11 @@ class THtmlListButtonsController {
131
119
  #_on_btn_last_pressed = (e) => {
132
120
  //console.log('THtmlListButtonsController._on_btn_last_pressed() ==> was called...');
133
121
  //e.preventDefault(); /* need to reconsider reason for use */
134
- let curItem = null;
135
- let on_click_num = readAsNumber(e.detail, 0);
136
- //console.log('CHECK: e => ditail:['+on_click_num+']');
137
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
138
- switch (e.eventPhase) {
139
- //*case 1:
140
- //* // NOTE: currently on eventPhase = 2 and 3
141
- case 2:
142
- /**/// capturing stage
143
- curItem = e.target;
144
- break;
145
- case 3:
146
- /**/// bubblig stage
147
- curItem = e.currentTarget;
148
- break;
149
- default:
150
- break;
151
- };
122
+ const { item, onClickNum } = readOnClickEventInfo(e);
152
123
  if (
153
- curItem instanceof HTMLElement
154
- && (on_click_num === 0 || on_click_num === 1)
155
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
124
+ item instanceof HTMLElement
125
+ && (onClickNum === 0 || onClickNum === 1)
126
+ && !item.classList.contains(CSS_CLASS_DISABLED)
156
127
  ) {
157
128
  this.#_triggerEvent('btn-last-pressed', e);
158
129
  };
@@ -161,28 +132,11 @@ class THtmlListButtonsController {
161
132
  #_on_btn_prev_pressed = (e) => {
162
133
  //console.log('THtmlListButtonsController._on_btn_prev_pressed() ==> was called...');
163
134
  //e.preventDefault(); /* need to reconsider reason for use */
164
- let curItem = null;
165
- let on_click_num = readAsNumber(e.detail, 0);
166
- //console.log('CHECK: e => ditail:['+on_click_num+']');
167
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
168
- switch (e.eventPhase) {
169
- //*case 1:
170
- //* // NOTE: currently on eventPhase = 2 and 3
171
- case 2:
172
- /**/// capturing stage
173
- curItem = e.target;
174
- break;
175
- case 3:
176
- /**/// bubblig stage
177
- curItem = e.currentTarget;
178
- break;
179
- default:
180
- break;
181
- };
135
+ const { item, onClickNum } = readOnClickEventInfo(e);
182
136
  if (
183
- curItem instanceof HTMLElement
184
- && (on_click_num === 0 || on_click_num === 1)
185
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
137
+ item instanceof HTMLElement
138
+ && (onClickNum === 0 || onClickNum === 1)
139
+ && !item.classList.contains(CSS_CLASS_DISABLED)
186
140
  ) {
187
141
  this.#_triggerEvent('btn-prev-pressed', e);
188
142
  };
@@ -191,39 +145,18 @@ class THtmlListButtonsController {
191
145
  #_on_btn_next_pressed = (e) => {
192
146
  //console.log('THtmlListButtonsController._on_btn_next_pressed() ==> was called...');
193
147
  //e.preventDefault(); /* need to reconsider reason for use */
194
- let curItem = null;
195
- let on_click_num = readAsNumber(e.detail, 0);
196
- //console.log('CHECK: e => ditail:['+on_click_num+']');
197
- //console.log('CHECK: e => phase:['+e.eventPhase+']');
198
- switch (e.eventPhase) {
199
- //*case 1:
200
- //* // NOTE: currently on eventPhase = 2 and 3
201
- case 2:
202
- /**/// capturing stage
203
- curItem = e.target;
204
- break;
205
- case 3:
206
- /**/// bubblig stage
207
- curItem = e.currentTarget;
208
- break;
209
- default:
210
- break;
211
- };
148
+ const { item, onClickNum } = readOnClickEventInfo(e);
212
149
  if (
213
- curItem instanceof HTMLElement
214
- && (on_click_num === 0 || on_click_num === 1)
215
- && !curItem.classList.contains(CSS_CLASS_DISABLED)
150
+ item instanceof HTMLElement
151
+ && (onClickNum === 0 || onClickNum === 1)
152
+ && !item.classList.contains(CSS_CLASS_DISABLED)
216
153
  ) {
217
154
  this.#_triggerEvent('btn-next-pressed', e);
218
155
  };
219
156
  }
220
157
 
221
158
  #_triggerEvent = (name, ...args) => {
222
- const _name = typeof name === 'string' ? name.trim() : '';
223
- if (_name !== '') {
224
- const _events = this.#_events;
225
- if (_events.has(_name)) _events.get(name)(...args);
226
- };
159
+ triggerEventHandler(this.#_events, name, ...args);
227
160
  }
228
161
 
229
162
  disableAll(){
@@ -255,18 +188,7 @@ class THtmlListButtonsController {
255
188
  }
256
189
 
257
190
  on(name, evnt){
258
- const _name = typeof name === 'string' ? name.trim() : '';
259
- if (_name !== '' && typeof evnt === 'function') {
260
- const _events = this.#_events;
261
- if (!_events.has(_name)) {
262
- _events.set(_name, evnt);
263
- } else {
264
- /* NOTE:
265
- * for current you can't reset or set new one on the same event
266
- */
267
- //console.log('THtmlListButtonsController.on() ==> event:['+name+'] - already exists...');
268
- };
269
- };
191
+ pushEventHandler(this.#_events, name, evnt);
270
192
  }
271
193
  };
272
194
 
@@ -1,4 +1,4 @@
1
- // [v0.1.038-20220912]
1
+ // [v0.1.039-20230409]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -6,7 +6,6 @@ const {
6
6
  //readAsBool, readAsNumber, readAsString,
7
7
  //isEmptyString, isNotEmptyString,
8
8
  isArray, isObject, isPlainObject,
9
- //TItemsListEx,
10
9
  } = require('@ygracs/bsfoc-lib-js');
11
10
 
12
11
  const {
@@ -141,12 +140,9 @@ class THtmlStubItemsSet {
141
140
  }
142
141
 
143
142
  loadItems(list, opt){
144
- let _options = {};
145
- if (typeof opt === 'boolean') {
146
- _options.useClear = opt;
147
- } else if (isPlainObject(opt)) {
148
- _options = opt;
149
- };
143
+ let _options = opt;
144
+ if (typeof _options === 'boolean') _options = { useClear: _options };
145
+ if (!isPlainObject(_options)) _options = {};
150
146
  let {
151
147
  defaultItem,
152
148
  useClear,
@@ -154,8 +150,8 @@ class THtmlStubItemsSet {
154
150
  load_as_new, //* will deprecate
155
151
  } = _options;
156
152
  if (useClear === undefined) useClear = load_as_new;
157
- useClear = typeof useClear === 'boolean' ? useClear : true;
158
- force = typeof force === 'boolean' ? force : false;
153
+ if (typeof useClear !== 'boolean') useClear = true;
154
+ if (typeof force !== 'boolean') force = false;
159
155
  let _list = list;
160
156
  if (isPlainObject(_list)) {
161
157
  ({ items: _list, defaultItem } = _list);
@@ -0,0 +1,33 @@
1
+ // [v0.1.059-20230408]
2
+
3
+ // === module init block ===
4
+
5
+ // === module extra block (helper functions) ===
6
+
7
+ // === module main block (function definitions) ===
8
+
9
+ function pushEventHandler(pool, name, evnt){
10
+ const _name = typeof name === 'string' ? name.trim() : '';
11
+ if (_name !== '' && typeof evnt === 'function') {
12
+ if (!pool.has(_name)) {
13
+ pool.set(_name, evnt);
14
+ } else {
15
+ /* NOTE:
16
+ * for current you can't reset or set new one on the same event
17
+ */
18
+ };
19
+ };
20
+ };
21
+
22
+ function triggerEventHandler(pool, name, ...args){
23
+ const _name = typeof name === 'string' ? name.trim() : '';
24
+ if (_name !== '') {
25
+ if (pool.has(_name)) pool.get(_name)(...args);
26
+ };
27
+ };
28
+ // === module main block (class definitions) ===
29
+
30
+ // === module exports block ===
31
+
32
+ exports.pushEventHandler = pushEventHandler;
33
+ exports.triggerEventHandler = triggerEventHandler;
@@ -1,11 +1,9 @@
1
- // [v0.1.014-20220922]
1
+ // [v0.1.016-20230330]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- //isEmptyString, isNotEmptyString,
7
6
  readAsString,
8
- //readAsListS,
9
7
  isArray, isObject, isPlainObject, valueToArray,
10
8
  } = require('@ygracs/bsfoc-lib-js');
11
9
 
@@ -19,7 +17,9 @@ const CSS_CLASS_HIDDEN = 'hidden';
19
17
 
20
18
  // === module main block (function definitions) ===
21
19
 
22
- function isHTMLElement(obj){ return obj instanceof HTMLElement; };
20
+ function isHTMLElement(obj){
21
+ return obj instanceof HTMLElement;
22
+ };
23
23
 
24
24
  function isSelectedHTMLElement(obj){
25
25
  return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_SELECTED);
@@ -87,14 +87,17 @@ function unmarkActiveHtmlElement(obj){
87
87
 
88
88
  function inactivateHtmlElements(...args) {
89
89
  for (let item of args) {
90
- if (item instanceof HTMLElement) {
90
+ if (isHTMLElement(item)) {
91
91
  item.classList.add(CSS_CLASS_DISABLED);
92
92
  switch (item.tagName.toLowerCase()) {
93
93
  case 'button':
94
- case 'input':
95
- item.disabled = true; break;
96
- default:
94
+ case 'input': {
95
+ item.disabled = true;
96
+ break;
97
+ }
98
+ default: {
97
99
  break;
100
+ }
98
101
  };
99
102
  };
100
103
  };
@@ -102,19 +105,45 @@ function inactivateHtmlElements(...args) {
102
105
 
103
106
  function activateHtmlElements(...args) {
104
107
  for (let item of args) {
105
- if (item instanceof HTMLElement) {
108
+ if (isHTMLElement(item)) {
106
109
  item.classList.remove(CSS_CLASS_DISABLED);
107
110
  switch (item.tagName.toLowerCase()) {
108
111
  case 'button':
109
- case 'input':
110
- item.disabled = false; break;
111
- default:
112
+ case 'input': {
113
+ item.disabled = false;
112
114
  break;
115
+ }
116
+ default: {
117
+ break;
118
+ }
113
119
  };
114
120
  };
115
121
  };
116
122
  };
117
123
 
124
+ function readAsAttrValue(value){
125
+ let result = null;
126
+ switch (typeof value) {
127
+ case 'boolean': {
128
+ result = value.toString();
129
+ break;
130
+ }
131
+ case 'number': {
132
+ if (Number.isNaN(value)) break;
133
+ result = value.toString();
134
+ break;
135
+ }
136
+ case 'string': {
137
+ result = value.trim();
138
+ break;
139
+ }
140
+ default: {
141
+ break;
142
+ }
143
+ };
144
+ return result;
145
+ };
146
+
118
147
  function valueToClassList(value, opt){
119
148
  let result = [];
120
149
  let list = valueToArray(value);
@@ -137,16 +166,19 @@ function valueToClassList(value, opt){
137
166
  function valueToIDString(value){
138
167
  let result = '';
139
168
  switch (typeof value) {
140
- case 'number':
169
+ case 'number': {
141
170
  if (Number.isNaN(value) || value < 0) break;
142
171
  if (Number.isInteger(value)) result = value.toString();
143
172
  break;
144
- case 'string':
173
+ }
174
+ case 'string': {
145
175
  result = value.trim();
146
176
  // // TODO: check if a valid character sequencies
147
177
  break;
148
- default:
178
+ }
179
+ default: {
149
180
  break;
181
+ }
150
182
  };
151
183
  return result;
152
184
  };
@@ -243,3 +275,4 @@ exports.valueToClassList = valueToClassList;
243
275
  // experimental
244
276
  exports.createNewHtmlElement = createNewHtmlElement;
245
277
  exports.valueToIDString = valueToIDString;
278
+ exports.readAsAttrValue = readAsAttrValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-helper",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "A base HTML-helper library for js",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -15,14 +15,18 @@
15
15
  "doc/html-ctrls-btn.md",
16
16
  "lib/html-helper-lib.js",
17
17
  "lib/html-ctrls/lists-stubs.js",
18
- "lib/html-ctrls/lists-btns.js",
19
- "lib/html-ctrls-list.js",
20
- "lib/html-ctrls-btn.js",
21
- "index.js"
18
+ "lib/html-ctrls/lists-btn.js",
19
+ "lib/html-ctrls/list.js",
20
+ "lib/html-ctrls/buttons.js",
21
+ "lib/html-ctrls/mod-hfunc.js",
22
+ "index.js",
23
+ "CHANGELOG.md"
22
24
  ],
23
25
  "scripts": {
24
26
  "test": "jest",
25
27
  "test-bs": "jest base/",
28
+ "test-bs:g1": "jest base/fg-1",
29
+ "test-bs:g2": "jest base/fg-2",
26
30
  "test-lc1": "jest THtmlItemsListContainer",
27
31
  "test-lc2": "jest THtmlItemsListController",
28
32
  "test-lc2:bs": "jest THtmlItemsListController/base",