@cntwg/html-helper 0.0.22 → 0.0.23
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 +13 -0
- package/README.md +8 -8
- package/doc/html-ctrls-btn.md +145 -104
- package/doc/html-ctrls-fields.md +104 -57
- package/doc/html-ctrls-list.md +570 -136
- package/doc/html-helper-lib.md +177 -49
- package/index.js +39 -15
- package/lib/event-hfunc.js +60 -0
- package/lib/html-ctrls/buttons.js +122 -101
- package/lib/html-ctrls/fields.js +126 -80
- package/lib/html-ctrls/list.js +247 -209
- package/lib/html-ctrls/lists-btn.js +44 -45
- package/lib/html-ctrls/lists-stubs.js +71 -71
- package/lib/html-ctrls/mod-hfunc.js +8 -38
- package/lib/html-helper-lib.js +186 -96
- package/package.json +5 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.056-20241119]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
const {
|
|
12
12
|
isHTMLElement,
|
|
13
13
|
valueToIDString,
|
|
14
|
-
|
|
14
|
+
lockHTMLElement, unlockHTMLElement,
|
|
15
15
|
CSS_CLASS_STRING,
|
|
16
16
|
} = require('../html-helper-lib.js');
|
|
17
17
|
|
|
@@ -26,15 +26,31 @@ const {
|
|
|
26
26
|
//CSS_CLASS_HIDDEN,
|
|
27
27
|
} = CSS_CLASS_STRING;
|
|
28
28
|
|
|
29
|
-
const BTS_DEF_GROUP_NAME = 'all';
|
|
30
|
-
|
|
31
29
|
const etlHTagInputForBtn = new Set([
|
|
32
30
|
'button', 'submit', 'reset', 'image',
|
|
33
31
|
]);
|
|
34
32
|
|
|
35
33
|
// === module extra block (helper functions) ===
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
// === module main block ===
|
|
36
|
+
|
|
37
|
+
/***
|
|
38
|
+
* (* constant definitions *)
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const BTS_DEF_GROUP_NAME = 'all';
|
|
42
|
+
|
|
43
|
+
/***
|
|
44
|
+
* (* function definitions *)
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @function isHTMLButton
|
|
49
|
+
* @param {any} obj - element to be verified
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
* @description Checks if the given object is an HTML-button.
|
|
52
|
+
*/
|
|
53
|
+
function isHTMLButton(obj) {
|
|
38
54
|
let result = false;
|
|
39
55
|
if (isHTMLElement(obj)) {
|
|
40
56
|
switch (obj.tagName.toLowerCase()) {
|
|
@@ -54,30 +70,21 @@ function isHTMLButton(obj){
|
|
|
54
70
|
return result;
|
|
55
71
|
}
|
|
56
72
|
|
|
57
|
-
// === module main block ===
|
|
58
|
-
|
|
59
|
-
/***
|
|
60
|
-
* (* constant definitions *)
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/***
|
|
64
|
-
* (* function definitions *)
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
73
|
/***
|
|
68
74
|
* (* class definitions *)
|
|
69
75
|
*/
|
|
70
76
|
|
|
71
77
|
/**
|
|
72
|
-
* @
|
|
78
|
+
* @classdesc This class implements an interface of a buttons set
|
|
73
79
|
*/
|
|
74
80
|
class THtmlButtonsSet {
|
|
75
|
-
|
|
81
|
+
/** @property {TItemsICollection} */
|
|
82
|
+
#_btnCol;
|
|
76
83
|
|
|
77
84
|
/**
|
|
78
|
-
* @
|
|
85
|
+
* @description Creates an instance of a buttons set
|
|
79
86
|
*/
|
|
80
|
-
constructor(){
|
|
87
|
+
constructor() {
|
|
81
88
|
// define default functions for manipulators
|
|
82
89
|
const __user_index_getter = (value) => {
|
|
83
90
|
return valueToIDString(value);
|
|
@@ -96,153 +103,167 @@ class THtmlButtonsSet {
|
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/**
|
|
99
|
-
* @property {
|
|
106
|
+
* @property {string[]}
|
|
100
107
|
* @readonly
|
|
101
108
|
* @see TItemsICollection.ItemNames
|
|
109
|
+
* @description Contains a list of an element names
|
|
102
110
|
*/
|
|
103
|
-
get ItemNames(){
|
|
111
|
+
get ItemNames() {
|
|
104
112
|
return this.#_btnCol.ItemNames;
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
/**
|
|
108
|
-
* @property {
|
|
116
|
+
* @property {string[]}
|
|
109
117
|
* @readonly
|
|
110
118
|
* @see TItemsICollection.CategoryNames
|
|
119
|
+
* @description Contains a list of an elements group names
|
|
111
120
|
*/
|
|
112
|
-
get GroupNames(){
|
|
121
|
+
get GroupNames() {
|
|
113
122
|
return this.#_btnCol.CategoryNames;
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
/**
|
|
117
|
-
* @param {
|
|
118
|
-
* @returns {
|
|
126
|
+
* @param {string} name - element name
|
|
127
|
+
* @returns {boolean}
|
|
119
128
|
* @see TItemsICollection.hasItem
|
|
120
129
|
* @description Checks whether a target item with a given name exists.
|
|
121
130
|
*/
|
|
122
|
-
hasItem(name){
|
|
131
|
+
hasItem(name) {
|
|
123
132
|
return this.#_btnCol.hasItem(name);
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
/**
|
|
136
|
+
* @param {string} name - element name
|
|
137
|
+
* @param {any} item - element
|
|
138
|
+
* @param {...string} [group] - name of a target groups
|
|
139
|
+
* @returns {boolean}
|
|
127
140
|
* @see TItemsICollection.addItem
|
|
128
141
|
* @description Adds buttons to a set members.
|
|
129
142
|
*/
|
|
130
|
-
addItem(...args){
|
|
143
|
+
addItem(...args) {
|
|
131
144
|
return this.#_btnCol.addItem(...args);
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
/**
|
|
148
|
+
* @param {string} name - element name
|
|
149
|
+
* @param {...string} [group] - name of a target groups
|
|
150
|
+
* @returns {boolean}
|
|
135
151
|
* @see TItemsICollection.addItemToCategory
|
|
136
152
|
* @description Adds button to a listed groups.
|
|
137
153
|
*/
|
|
138
|
-
addItemToGroup(...args){
|
|
154
|
+
addItemToGroup(...args) {
|
|
139
155
|
return this.#_btnCol.addItemToCategory(...args);
|
|
140
156
|
}
|
|
141
157
|
|
|
142
158
|
/**
|
|
143
|
-
* @param {
|
|
159
|
+
* @param {string} name - element name
|
|
160
|
+
* @returns {boolean}
|
|
144
161
|
* @see TItemsICollection.delItem
|
|
145
162
|
* @description Deletes button from a set members.
|
|
146
163
|
*/
|
|
147
|
-
delItem(name){
|
|
164
|
+
delItem(name) {
|
|
148
165
|
return this.#_btnCol.delItem(name);
|
|
149
166
|
}
|
|
150
167
|
|
|
151
168
|
/**
|
|
169
|
+
* @param {string} name - element name
|
|
170
|
+
* @param {...string} [group] - name of a target groups
|
|
171
|
+
* @returns {boolean}
|
|
152
172
|
* @see TItemsICollection.delItemFromGroup
|
|
153
173
|
* @description Deletes button from a listed groups.
|
|
154
174
|
*/
|
|
155
|
-
delItemFromGroup(...args){
|
|
175
|
+
delItemFromGroup(...args) {
|
|
156
176
|
return this.#_btnCol.delItemFromGroup(...args);
|
|
157
177
|
}
|
|
158
178
|
|
|
159
179
|
/**
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {
|
|
180
|
+
* @param {string} name - old name
|
|
181
|
+
* @param {string} value - new name
|
|
182
|
+
* @returns {boolean}
|
|
162
183
|
* @see TItemsICollection.renameItem
|
|
163
184
|
* @description Renames button in a set.
|
|
164
185
|
*/
|
|
165
|
-
renameItem(
|
|
166
|
-
return this.#_btnCol.renameItem(
|
|
186
|
+
renameItem(name, value) {
|
|
187
|
+
return this.#_btnCol.renameItem(name, value, false);
|
|
167
188
|
}
|
|
168
189
|
|
|
169
190
|
/**
|
|
170
|
-
* @param {
|
|
171
|
-
* @returns {
|
|
191
|
+
* @param {string} name - element name
|
|
192
|
+
* @returns {void}
|
|
172
193
|
* @description Tries to enable button.
|
|
173
194
|
*/
|
|
174
|
-
enableItem(name){
|
|
175
|
-
|
|
195
|
+
enableItem(name) {
|
|
196
|
+
unlockHTMLElement(this.#_btnCol.getItem(name));
|
|
176
197
|
}
|
|
177
198
|
|
|
178
199
|
/**
|
|
179
|
-
* @param {
|
|
180
|
-
* @returns {
|
|
200
|
+
* @param {string} name - element name
|
|
201
|
+
* @returns {void}
|
|
181
202
|
* @description Tries to disable button.
|
|
182
203
|
*/
|
|
183
|
-
disableItem(name){
|
|
184
|
-
|
|
204
|
+
disableItem(name) {
|
|
205
|
+
lockHTMLElement(this.#_btnCol.getItem(name));
|
|
185
206
|
}
|
|
186
207
|
|
|
187
208
|
/**
|
|
188
|
-
* @param {
|
|
189
|
-
* @returns {
|
|
209
|
+
* @param {string} name - group name
|
|
210
|
+
* @returns {boolean}
|
|
190
211
|
* @see TItemsICollection.hasCategory
|
|
191
212
|
* @description Checks whether a target group with a given name exists.
|
|
192
213
|
*/
|
|
193
|
-
hasGroup(name){
|
|
214
|
+
hasGroup(name) {
|
|
194
215
|
return this.#_btnCol.hasCategory(name);
|
|
195
216
|
}
|
|
196
217
|
|
|
197
218
|
/**
|
|
198
|
-
* @param {
|
|
199
|
-
* @returns {
|
|
219
|
+
* @param {string} name - group name
|
|
220
|
+
* @returns {boolean}
|
|
200
221
|
* @see TItemsICollection.addCategory
|
|
201
222
|
* @description Adds a group with a given name.
|
|
202
223
|
*/
|
|
203
|
-
addGroup(name){
|
|
224
|
+
addGroup(name) {
|
|
204
225
|
return this.#_btnCol.addCategory(name);
|
|
205
226
|
}
|
|
206
227
|
|
|
207
228
|
/**
|
|
208
|
-
* @param {
|
|
209
|
-
* @returns {
|
|
229
|
+
* @param {string} name - group name
|
|
230
|
+
* @returns {boolean}
|
|
210
231
|
* @see TItemsICollection.delCategory
|
|
211
232
|
* @description Deletes a group with a given name.
|
|
212
233
|
*/
|
|
213
|
-
delGroup(name){
|
|
234
|
+
delGroup(name) {
|
|
214
235
|
return this.#_btnCol.delCategory(name);
|
|
215
236
|
}
|
|
216
237
|
|
|
217
238
|
/**
|
|
218
|
-
* @param {
|
|
219
|
-
* @param {
|
|
220
|
-
* @returns {
|
|
239
|
+
* @param {string} name - old name
|
|
240
|
+
* @param {string} value - new name
|
|
241
|
+
* @returns {boolean}
|
|
221
242
|
* @see TItemsICollection.renameCategory
|
|
222
243
|
* @description Renames group in a set.
|
|
223
244
|
*/
|
|
224
|
-
renameGroup(
|
|
225
|
-
return this.#_btnCol.renameCategory(
|
|
245
|
+
renameGroup(name, value) {
|
|
246
|
+
return this.#_btnCol.renameCategory(name, value, false);
|
|
226
247
|
}
|
|
227
248
|
|
|
228
249
|
/**
|
|
229
|
-
* @param {
|
|
230
|
-
* @returns {
|
|
250
|
+
* @param {string} value - group name
|
|
251
|
+
* @returns {void}
|
|
231
252
|
* @description Enables all buttons in a given group.
|
|
232
253
|
*/
|
|
233
|
-
enableGroup(value){
|
|
254
|
+
enableGroup(value) {
|
|
234
255
|
const group = this.#_btnCol.getCategory(value);
|
|
235
|
-
valueToArray(group).forEach(item =>
|
|
256
|
+
valueToArray(group).forEach(item => unlockHTMLElement(item));
|
|
236
257
|
}
|
|
237
258
|
|
|
238
259
|
/**
|
|
239
|
-
* @param {
|
|
240
|
-
* @returns {
|
|
260
|
+
* @param {string} value - group name
|
|
261
|
+
* @returns {void}
|
|
241
262
|
* @description Disables all buttons in a given group.
|
|
242
263
|
*/
|
|
243
|
-
disableGroup(value){
|
|
264
|
+
disableGroup(value) {
|
|
244
265
|
const group = this.#_btnCol.getCategory(value);
|
|
245
|
-
valueToArray(group).forEach(item =>
|
|
266
|
+
valueToArray(group).forEach(item => lockHTMLElement(item));
|
|
246
267
|
}
|
|
247
268
|
|
|
248
269
|
/**
|
|
@@ -250,30 +271,39 @@ class THtmlButtonsSet {
|
|
|
250
271
|
* @static
|
|
251
272
|
* @description Returns a function wich do a validation check.
|
|
252
273
|
*/
|
|
253
|
-
static get isHTMLButton(){
|
|
274
|
+
static get isHTMLButton() {
|
|
254
275
|
return isHTMLButton;
|
|
255
276
|
}
|
|
256
277
|
|
|
257
278
|
};
|
|
258
279
|
|
|
259
280
|
/**
|
|
260
|
-
* @
|
|
261
|
-
*
|
|
281
|
+
* @classdesc This class implements an interface of a pre-defined buttons set.
|
|
282
|
+
* A set provide a three button: <apply>, <reset> and <cancel>.
|
|
262
283
|
*/
|
|
263
284
|
class THtmlButtonsControllerARCSet {
|
|
264
|
-
|
|
265
|
-
#
|
|
285
|
+
/** @property {THtmlButtonsSet} */
|
|
286
|
+
#_btnSet;
|
|
287
|
+
/** @property {Map} */
|
|
288
|
+
#_events;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @typedef {Object} arcButtonsDesc
|
|
292
|
+
* @property {?HTMLElement} btnApply - button 'apply'
|
|
293
|
+
* @property {?HTMLElement} btnReset - button 'reset'
|
|
294
|
+
* @property {?HTMLElement} btnCancel - button 'cancel'
|
|
295
|
+
* @description A description for ARC-buttons set.
|
|
296
|
+
*/
|
|
266
297
|
|
|
267
298
|
/**
|
|
268
|
-
* @param {
|
|
269
|
-
* @
|
|
270
|
-
* @param {HTMLElement} opt.btnReset
|
|
271
|
-
* @param {HTMLElement} opt.btnCancel
|
|
299
|
+
* @param {arcButtonsDesc} opt - an option
|
|
300
|
+
* @description Creates an instance of the buttons set.
|
|
272
301
|
*/
|
|
273
302
|
constructor(opt) {
|
|
274
303
|
// load options
|
|
275
304
|
const _options = isPlainObject(opt) ? opt : {};
|
|
276
305
|
// load controls
|
|
306
|
+
/** @type {arcButtonsDesc} */
|
|
277
307
|
let {
|
|
278
308
|
btnApply,
|
|
279
309
|
btnReset,
|
|
@@ -282,11 +312,6 @@ class THtmlButtonsControllerARCSet {
|
|
|
282
312
|
if (!isHTMLButton(btnApply)) btnApply = null;
|
|
283
313
|
if (!isHTMLButton(btnReset)) btnReset = null;
|
|
284
314
|
if (!isHTMLButton(btnCancel)) btnCancel = null;
|
|
285
|
-
/*const controls = {
|
|
286
|
-
btnApply,
|
|
287
|
-
btnReset,
|
|
288
|
-
btnCancel,
|
|
289
|
-
};*/ // // TODO: ???
|
|
290
315
|
// init buttons set
|
|
291
316
|
const _btnSet = new THtmlButtonsSet();
|
|
292
317
|
this.#_btnSet = _btnSet;
|
|
@@ -310,9 +335,9 @@ class THtmlButtonsControllerARCSet {
|
|
|
310
335
|
}
|
|
311
336
|
|
|
312
337
|
/**
|
|
313
|
-
* @param {object}
|
|
314
|
-
* @param {
|
|
315
|
-
* @returns {
|
|
338
|
+
* @param {object} e - event
|
|
339
|
+
* @param {string} key - button ID
|
|
340
|
+
* @returns {void}
|
|
316
341
|
* @private
|
|
317
342
|
*/
|
|
318
343
|
#_on_btn_pressed = (e, key) => {
|
|
@@ -329,9 +354,9 @@ class THtmlButtonsControllerARCSet {
|
|
|
329
354
|
}
|
|
330
355
|
|
|
331
356
|
/**
|
|
332
|
-
* @param {
|
|
333
|
-
* @param {...any}
|
|
334
|
-
* @returns {
|
|
357
|
+
* @param {string} name - event name
|
|
358
|
+
* @param {...any} args
|
|
359
|
+
* @returns {void}
|
|
335
360
|
* @private
|
|
336
361
|
* @see triggerEventHandler
|
|
337
362
|
*/
|
|
@@ -340,48 +365,44 @@ class THtmlButtonsControllerARCSet {
|
|
|
340
365
|
}
|
|
341
366
|
|
|
342
367
|
/**
|
|
343
|
-
* @
|
|
344
|
-
* @returns {none}
|
|
368
|
+
* @returns {void}
|
|
345
369
|
* @description Disables all buttons in 'main' group.
|
|
346
370
|
*/
|
|
347
|
-
disableMain(){
|
|
371
|
+
disableMain() {
|
|
348
372
|
this.#_btnSet.disableGroup('main');
|
|
349
373
|
}
|
|
350
374
|
|
|
351
375
|
/**
|
|
352
|
-
* @
|
|
353
|
-
* @returns {none}
|
|
376
|
+
* @returns {void}
|
|
354
377
|
* @description Enables all buttons in 'main' group.
|
|
355
378
|
*/
|
|
356
|
-
enableMain(){
|
|
379
|
+
enableMain() {
|
|
357
380
|
this.#_btnSet.enableGroup('main');
|
|
358
381
|
}
|
|
359
382
|
|
|
360
383
|
/**
|
|
361
|
-
* @
|
|
362
|
-
* @returns {none}
|
|
384
|
+
* @returns {void}
|
|
363
385
|
* @description Disables all buttons.
|
|
364
386
|
*/
|
|
365
|
-
disableAll(){
|
|
387
|
+
disableAll() {
|
|
366
388
|
this.#_btnSet.disableGroup('all');
|
|
367
389
|
}
|
|
368
390
|
|
|
369
391
|
/**
|
|
370
|
-
* @
|
|
371
|
-
* @returns {none}
|
|
392
|
+
* @returns {void}
|
|
372
393
|
* @description Enables all buttons.
|
|
373
394
|
*/
|
|
374
|
-
enableAll(){
|
|
395
|
+
enableAll() {
|
|
375
396
|
this.#_btnSet.enableGroup('all');
|
|
376
397
|
}
|
|
377
398
|
|
|
378
399
|
/**
|
|
379
|
-
* @param {
|
|
380
|
-
* @param {func}
|
|
381
|
-
* @returns {
|
|
400
|
+
* @param {string} name - event name
|
|
401
|
+
* @param {func} evnt - a callback function
|
|
402
|
+
* @returns {void}
|
|
382
403
|
* @description Sets a callback function to handle event.
|
|
383
404
|
*/
|
|
384
|
-
on(name, evnt){
|
|
405
|
+
on(name, evnt) {
|
|
385
406
|
pushEventHandler(this.#_events, name, evnt);
|
|
386
407
|
}
|
|
387
408
|
};
|