@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.
- package/CHANGELOG.md +19 -0
- package/doc/html-ctrls-btn.md +4 -11
- package/doc/html-ctrls-list.md +13 -13
- package/doc/html-helper-lib.md +11 -2
- package/index.js +3 -2
- package/lib/event-hfunc.js +26 -8
- package/lib/html-ctrls/buttons.js +37 -72
- package/lib/html-ctrls/fields.js +42 -42
- package/lib/html-ctrls/list.js +83 -72
- package/lib/html-ctrls/lists-btn.js +20 -22
- package/lib/html-ctrls/lists-stubs.js +55 -42
- package/lib/html-helper-lib.js +64 -40
- package/package.json +6 -16
package/lib/html-helper-lib.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.043-20250827]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
readAsString,
|
|
7
6
|
isArray, isObject, isPlainObject, valueToArray,
|
|
8
7
|
valueToIDString,
|
|
9
8
|
} = require('@ygracs/bsfoc-lib-js');
|
|
10
9
|
|
|
11
|
-
// === module
|
|
10
|
+
// === module inner block ===
|
|
11
|
+
|
|
12
|
+
const etlHTagInputForBtn = new Set([
|
|
13
|
+
'button', 'submit', 'reset', 'image',
|
|
14
|
+
]);
|
|
12
15
|
|
|
13
16
|
// === module main block ===
|
|
14
17
|
|
|
@@ -27,65 +30,89 @@ const CSS_CLASS_HIDDEN = 'hidden';
|
|
|
27
30
|
*/
|
|
28
31
|
|
|
29
32
|
/**
|
|
33
|
+
* Checks if the given object is an instance of an `HTMLElement`.
|
|
30
34
|
* @function isHTMLElement
|
|
31
35
|
* @param {any} obj - some element
|
|
32
36
|
* @return {boolean}
|
|
33
|
-
* @description Checks if the given object is an instance of an `HTMLElement`.
|
|
34
37
|
*/
|
|
35
38
|
function isHTMLElement(obj) {
|
|
36
39
|
return obj instanceof HTMLElement;
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
/**
|
|
43
|
+
* Checks if the given object is an HTML-button.
|
|
44
|
+
* @function isHTMLButton
|
|
45
|
+
* @param {any} obj - element to be verified
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
function isHTMLButton(obj) {
|
|
49
|
+
let result = false;
|
|
50
|
+
if (isHTMLElement(obj)) {
|
|
51
|
+
switch (obj.tagName.toLowerCase()) {
|
|
52
|
+
case 'button': {
|
|
53
|
+
result = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'input': {
|
|
57
|
+
result = etlHTagInputForBtn.has(obj.type.toLowerCase());
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
default: {}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
68
|
+
* and if so it's marked as "selected".
|
|
40
69
|
* @function isSelectedHTMLElement
|
|
41
70
|
* @param {HTMLElement} obj - some element
|
|
42
71
|
* @return {boolean}
|
|
43
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
44
|
-
* and if so it's marked as "selected".
|
|
45
72
|
*/
|
|
46
73
|
function isSelectedHTMLElement(obj) {
|
|
47
74
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_SELECTED);
|
|
48
75
|
};
|
|
49
76
|
|
|
50
77
|
/**
|
|
78
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
79
|
+
* and if so it's marked as "current".
|
|
51
80
|
* @function isCurrentHTMLElement
|
|
52
81
|
* @param {HTMLElement} obj - some element
|
|
53
82
|
* @return {boolean}
|
|
54
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
55
|
-
* and if so it's marked as "current".
|
|
56
83
|
*/
|
|
57
84
|
function isCurrentHTMLElement(obj) {
|
|
58
85
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_CURRENT);
|
|
59
86
|
};
|
|
60
87
|
|
|
61
88
|
/**
|
|
89
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
90
|
+
* and if so it's marked as "active".
|
|
62
91
|
* @function isActiveHTMLElement
|
|
63
92
|
* @param {HTMLElement} obj - some element
|
|
64
93
|
* @return {boolean}
|
|
65
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
66
|
-
* and if so it's marked as "active".
|
|
67
94
|
*/
|
|
68
95
|
function isActiveHTMLElement(obj) {
|
|
69
96
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_ACTIVE);
|
|
70
97
|
};
|
|
71
98
|
|
|
72
99
|
/**
|
|
100
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
101
|
+
* and if so it's marked as "hidden".
|
|
73
102
|
* @function isHiddenHTMLElement
|
|
74
103
|
* @param {HTMLElement} obj - some element
|
|
75
104
|
* @return {boolean}
|
|
76
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
77
|
-
* and if so it's marked as "hidden".
|
|
78
105
|
*/
|
|
79
106
|
function isHiddenHTMLElement(obj) {
|
|
80
107
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_HIDDEN);
|
|
81
108
|
};
|
|
82
109
|
|
|
83
110
|
/**
|
|
111
|
+
* Hides a given HTML-element.
|
|
84
112
|
* @since v0.0.23
|
|
85
113
|
* @function hideHTMLElement
|
|
86
114
|
* @param {HTMLElement} obj - some element
|
|
87
115
|
* @return {boolean}
|
|
88
|
-
* @description Hides a given HTML-element.
|
|
89
116
|
*/
|
|
90
117
|
function hideHTMLElement(obj) {
|
|
91
118
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -94,11 +121,11 @@ function hideHTMLElement(obj) {
|
|
|
94
121
|
};
|
|
95
122
|
|
|
96
123
|
/**
|
|
124
|
+
* Shows a given HTML-element.
|
|
97
125
|
* @since v0.0.23
|
|
98
126
|
* @function showHTMLElement
|
|
99
127
|
* @param {HTMLElement} obj - some element
|
|
100
128
|
* @return {boolean}
|
|
101
|
-
* @description Shows a given HTML-element.
|
|
102
129
|
*/
|
|
103
130
|
function showHTMLElement(obj) {
|
|
104
131
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -107,11 +134,11 @@ function showHTMLElement(obj) {
|
|
|
107
134
|
};
|
|
108
135
|
|
|
109
136
|
/**
|
|
137
|
+
* Makes selected a given HTML-element.
|
|
110
138
|
* @since v0.0.23
|
|
111
139
|
* @function selectHTMLElement
|
|
112
140
|
* @param {HTMLElement} obj - some element
|
|
113
141
|
* @return {boolean}
|
|
114
|
-
* @description Makes selected a given HTML-element.
|
|
115
142
|
*/
|
|
116
143
|
function selectHTMLElement(obj) {
|
|
117
144
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -120,11 +147,11 @@ function selectHTMLElement(obj) {
|
|
|
120
147
|
};
|
|
121
148
|
|
|
122
149
|
/**
|
|
150
|
+
* Makes unselected a given HTML-element.
|
|
123
151
|
* @since v0.0.23
|
|
124
152
|
* @function unselectHTMLElement
|
|
125
153
|
* @param {HTMLElement} obj - some element
|
|
126
154
|
* @return {boolean}
|
|
127
|
-
* @description Makes unselected a given HTML-element.
|
|
128
155
|
*/
|
|
129
156
|
function unselectHTMLElement(obj) {
|
|
130
157
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -133,11 +160,11 @@ function unselectHTMLElement(obj) {
|
|
|
133
160
|
};
|
|
134
161
|
|
|
135
162
|
/**
|
|
163
|
+
* Marks a given HTML-element as "current".
|
|
136
164
|
* @since v0.0.23
|
|
137
165
|
* @function markHTMLElementAsCurrent
|
|
138
166
|
* @param {HTMLElement} obj - some element
|
|
139
167
|
* @return {boolean} - `true` if succeed.
|
|
140
|
-
* @description Marks a given HTML-element as "current".
|
|
141
168
|
*/
|
|
142
169
|
function markHTMLElementAsCurrent(obj) {
|
|
143
170
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -146,11 +173,11 @@ function markHTMLElementAsCurrent(obj) {
|
|
|
146
173
|
};
|
|
147
174
|
|
|
148
175
|
/**
|
|
176
|
+
* Unmarks a given HTML-element previous marked as "current".
|
|
149
177
|
* @since v0.0.23
|
|
150
178
|
* @function unmarkCurrentHTMLElement
|
|
151
179
|
* @param {HTMLElement} obj - some element
|
|
152
180
|
* @return {boolean}
|
|
153
|
-
* @description Unmarks a given HTML-element previous marked as "current".
|
|
154
181
|
*/
|
|
155
182
|
function unmarkCurrentHTMLElement(obj) {
|
|
156
183
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -159,11 +186,11 @@ function unmarkCurrentHTMLElement(obj) {
|
|
|
159
186
|
};
|
|
160
187
|
|
|
161
188
|
/**
|
|
189
|
+
* Marks a given HTML-element as "active".
|
|
162
190
|
* @since v0.0.23
|
|
163
191
|
* @function markHTMLElementAsActive
|
|
164
192
|
* @param {HTMLElement} obj - some element
|
|
165
193
|
* @return {boolean}
|
|
166
|
-
* @description Marks a given HTML-element as "active".
|
|
167
194
|
*/
|
|
168
195
|
function markHTMLElementAsActive(obj) {
|
|
169
196
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -172,11 +199,11 @@ function markHTMLElementAsActive(obj) {
|
|
|
172
199
|
};
|
|
173
200
|
|
|
174
201
|
/**
|
|
202
|
+
* Unmarks a given HTML-element previous marked as "active".
|
|
175
203
|
* @since v0.0.23
|
|
176
204
|
* @function unmarkActiveHTMLElement
|
|
177
205
|
* @param {HTMLElement} obj - some element
|
|
178
206
|
* @return {boolean}
|
|
179
|
-
* @description Unmarks a given HTML-element previous marked as "active".
|
|
180
207
|
*/
|
|
181
208
|
function unmarkActiveHTMLElement(obj) {
|
|
182
209
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -185,11 +212,11 @@ function unmarkActiveHTMLElement(obj) {
|
|
|
185
212
|
};
|
|
186
213
|
|
|
187
214
|
/**
|
|
215
|
+
* Disables a given HTML-element.
|
|
188
216
|
* @since v0.0.23
|
|
189
217
|
* @function lockHTMLElement
|
|
190
218
|
* @param {HTMLElement} obj - some element
|
|
191
219
|
* @return {boolean}
|
|
192
|
-
* @description Disables a given HTML-element.
|
|
193
220
|
*/
|
|
194
221
|
function lockHTMLElement(obj) {
|
|
195
222
|
let isSUCCEED = isHTMLElement(obj);
|
|
@@ -202,20 +229,18 @@ function lockHTMLElement(obj) {
|
|
|
202
229
|
obj.disabled = true;
|
|
203
230
|
break;
|
|
204
231
|
}
|
|
205
|
-
default: {
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
232
|
+
default: {}
|
|
208
233
|
};
|
|
209
234
|
};
|
|
210
235
|
return isSUCCEED;
|
|
211
236
|
};
|
|
212
237
|
|
|
213
238
|
/**
|
|
239
|
+
* Enables a given HTML-element.
|
|
214
240
|
* @since v0.0.23
|
|
215
241
|
* @function unlockHTMLElement
|
|
216
242
|
* @param {HTMLElement} obj - some element
|
|
217
243
|
* @return {boolean}
|
|
218
|
-
* @description Enables a given HTML-element.
|
|
219
244
|
*/
|
|
220
245
|
function unlockHTMLElement(obj) {
|
|
221
246
|
let isSUCCEED = isHTMLElement(obj);
|
|
@@ -235,11 +260,11 @@ function unlockHTMLElement(obj) {
|
|
|
235
260
|
};
|
|
236
261
|
|
|
237
262
|
/**
|
|
263
|
+
* Enables an HTML-elements given by a list of a function params.
|
|
238
264
|
* @since v0.0.23
|
|
239
265
|
* @function activateHTMLElements
|
|
240
266
|
* @param {...HTMLElement} obj - some element
|
|
241
267
|
* @return {void}
|
|
242
|
-
* @description Enables an HTML-elements given by a list of a function params.
|
|
243
268
|
*/
|
|
244
269
|
function activateHTMLElements(...args) {
|
|
245
270
|
for (let item of args) {
|
|
@@ -248,11 +273,11 @@ function activateHTMLElements(...args) {
|
|
|
248
273
|
};
|
|
249
274
|
|
|
250
275
|
/**
|
|
276
|
+
* Disables an HTML-elements given by a list of a function params.
|
|
251
277
|
* @since v0.0.23
|
|
252
278
|
* @function inactivateHTMLElements
|
|
253
279
|
* @param {...HTMLElement} obj - some element
|
|
254
280
|
* @return {void}
|
|
255
|
-
* @description Disables an HTML-elements given by a list of a function params.
|
|
256
281
|
*/
|
|
257
282
|
function inactivateHTMLElements(...args) {
|
|
258
283
|
for (let item of args) {
|
|
@@ -261,11 +286,11 @@ function inactivateHTMLElements(...args) {
|
|
|
261
286
|
};
|
|
262
287
|
|
|
263
288
|
/**
|
|
289
|
+
* Tries to convert a given value to a valid name of an HTML-tag.
|
|
264
290
|
* @since v0.0.21
|
|
265
291
|
* @function readAsTagName
|
|
266
292
|
* @param {any} value - some value
|
|
267
293
|
* @return {string}
|
|
268
|
-
* @description Tries to convert a given value to a valid name of an HTML-tag.
|
|
269
294
|
*/
|
|
270
295
|
function readAsTagName(value) {
|
|
271
296
|
let tagName = valueToIDString(value, { ignoreNumbers: true });
|
|
@@ -284,12 +309,11 @@ function readAsTagName(value) {
|
|
|
284
309
|
};
|
|
285
310
|
|
|
286
311
|
/**
|
|
312
|
+
* Tries to convert a given value to a valid name of an HTML-attribute.
|
|
287
313
|
* @since v0.0.21
|
|
288
314
|
* @function readAsAttrName
|
|
289
315
|
* @param {any} value - some value
|
|
290
316
|
* @return {string}
|
|
291
|
-
* @description Tries to convert a given value to a valid name
|
|
292
|
-
* of an HTML-attribute.
|
|
293
317
|
*/
|
|
294
318
|
function readAsAttrName(value) {
|
|
295
319
|
let attrName = valueToIDString(value, { ignoreNumbers: true });
|
|
@@ -307,11 +331,11 @@ function readAsAttrName(value) {
|
|
|
307
331
|
};
|
|
308
332
|
|
|
309
333
|
/**
|
|
334
|
+
* Tries to convert a given value to a valid "attribute value".
|
|
310
335
|
* @since v0.0.18
|
|
311
336
|
* @function readAsAttrValue
|
|
312
337
|
* @param {any} value - some value
|
|
313
338
|
* @return {?string}
|
|
314
|
-
* @description Tries to convert a given value to a valid "attribute value".
|
|
315
339
|
*/
|
|
316
340
|
function readAsAttrValue(value) {
|
|
317
341
|
let result = null;
|
|
@@ -335,13 +359,12 @@ function readAsAttrValue(value) {
|
|
|
335
359
|
};
|
|
336
360
|
|
|
337
361
|
/**
|
|
362
|
+
* Tries to convert a given value to a list of a valid "class attributes".
|
|
338
363
|
* @since v0.0.13
|
|
339
364
|
* @function valueToClassList
|
|
340
365
|
* @param {any} value - some value
|
|
341
366
|
* @param {boolean} [opt] - flag that indicates whether a dups allowed
|
|
342
367
|
* @return {string[]}
|
|
343
|
-
* @description Tries to convert a given value to a list of a valid
|
|
344
|
-
* "class attributes".
|
|
345
368
|
*/
|
|
346
369
|
function valueToClassList(value, opt) {
|
|
347
370
|
let result = [];
|
|
@@ -363,12 +386,12 @@ function valueToClassList(value, opt) {
|
|
|
363
386
|
};
|
|
364
387
|
|
|
365
388
|
/**
|
|
389
|
+
* Tries to convert a given value to a valid identifier suitable as a value
|
|
390
|
+
* for an "ID-attribute" of an HTML-element.
|
|
366
391
|
* @since v0.0.22
|
|
367
392
|
* @function valueToElementID
|
|
368
393
|
* @param {any} value - some value
|
|
369
394
|
* @return {string}
|
|
370
|
-
* @description Tries to convert a given value to a valid identifier
|
|
371
|
-
* suitable as a value for an "ID-attribute" of an HTML-element.
|
|
372
395
|
*/
|
|
373
396
|
function valueToElementID(value) {
|
|
374
397
|
let id = valueToIDString(value);
|
|
@@ -386,22 +409,22 @@ function valueToElementID(value) {
|
|
|
386
409
|
};
|
|
387
410
|
|
|
388
411
|
/**
|
|
412
|
+
* An element descriptor.
|
|
389
413
|
* @typedef {Object} elemDesc
|
|
390
414
|
* @property {string} [id] - element ID
|
|
391
415
|
* @property {string} [text] - some text
|
|
392
|
-
* @property {
|
|
416
|
+
* @property {Object<string, any>} [attr] - an attributes list
|
|
393
417
|
* @property {string|string[]} [classNames] - a class names list (added since v0.0.19)
|
|
394
|
-
* @property {
|
|
395
|
-
* @description An element description.
|
|
418
|
+
* @property {Object<string, any>} [data] - a 'dataset'-attributes list
|
|
396
419
|
*/
|
|
397
420
|
|
|
398
421
|
/**
|
|
422
|
+
* Creates a new HTML-element.
|
|
399
423
|
* @since 0.0.25
|
|
400
424
|
* @function createNewHTMLElement
|
|
401
425
|
* @param {string} tagName - an element tag name
|
|
402
|
-
* @param {elemDesc} [opt] - an element
|
|
426
|
+
* @param {elemDesc} [opt] - an element descriptor object
|
|
403
427
|
* @return {?HTMLElement}
|
|
404
|
-
* @description Creates a new HTML-element.
|
|
405
428
|
*/
|
|
406
429
|
function createNewHTMLElement(tagName, opt) {
|
|
407
430
|
let item = null;
|
|
@@ -495,6 +518,7 @@ module.exports.CSS_CLASS_STRING = /*function(){ return*/ {
|
|
|
495
518
|
}/*}*/;
|
|
496
519
|
|
|
497
520
|
module.exports.isHTMLElement = isHTMLElement;
|
|
521
|
+
module.exports.isHTMLButton = isHTMLButton;
|
|
498
522
|
module.exports.isCurrentHTMLElement = isCurrentHTMLElement;
|
|
499
523
|
module.exports.isSelectedHTMLElement = isSelectedHTMLElement;
|
|
500
524
|
module.exports.isActiveHTMLElement = isActiveHTMLElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntwg/html-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "A base HTML-helper library for js",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,18 +32,8 @@
|
|
|
32
32
|
"test-bs": "jest base/",
|
|
33
33
|
"test-bs:g1": "jest base/fg-1",
|
|
34
34
|
"test-bs:g2": "jest base/fg-2",
|
|
35
|
-
"test-lc1": "jest THtmlItemsListContainer",
|
|
36
|
-
"test-lc2": "jest THtmlItemsListController",
|
|
37
35
|
"test-lc2:bs": "jest THtmlItemsListController/base",
|
|
38
36
|
"test-lc2:ec": "jest THtmlItemsListController/events",
|
|
39
|
-
"test-sis": "jest THtmlStubItemsSet",
|
|
40
|
-
"test-btn": "jest THtmlButtonsSet",
|
|
41
|
-
"test-lbc": "jest THtmlListButtonsController",
|
|
42
|
-
"test-lbc:bs": "jest THtmlListButtonsController/base",
|
|
43
|
-
"test-lbc:ec": "jest THtmlListButtonsController/events",
|
|
44
|
-
"test-bc1": "jest THtmlButtonsControllerARCSet",
|
|
45
|
-
"test-bc1:bs": "jest THtmlButtonsControllerARCSet/base",
|
|
46
|
-
"test-bc1:ec": "jest THtmlButtonsControllerARCSet/events",
|
|
47
37
|
"build-doc-md": "jsdoc2md",
|
|
48
38
|
"build-doc-html": "jsdoc"
|
|
49
39
|
},
|
|
@@ -52,13 +42,13 @@
|
|
|
52
42
|
"#test-dir/*": "./__test__/*"
|
|
53
43
|
},
|
|
54
44
|
"dependencies": {
|
|
55
|
-
"@ygracs/bsfoc-lib-js": "^0.
|
|
56
|
-
"@ygracs/lists-lib-js": "^0.0
|
|
45
|
+
"@ygracs/bsfoc-lib-js": "^0.3.0",
|
|
46
|
+
"@ygracs/lists-lib-js": "^0.1.0"
|
|
57
47
|
},
|
|
58
48
|
"devDependencies": {
|
|
59
|
-
"jest": "^
|
|
60
|
-
"jest-environment-jsdom": "^
|
|
61
|
-
"jsdoc-to-markdown": "^9.1.
|
|
49
|
+
"jest": "^30.0.5",
|
|
50
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
51
|
+
"jsdoc-to-markdown": "^9.1.2",
|
|
62
52
|
"minimist": "^1.2.8"
|
|
63
53
|
}
|
|
64
54
|
}
|