@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.
- package/CHANGELOG.md +13 -0
- package/LICENSE +1 -1
- package/README.md +17 -16
- package/doc/html-ctrls-btn.md +17 -10
- package/doc/html-ctrls-fields.md +11 -3
- package/doc/html-ctrls-list.md +33 -8
- package/doc/html-helper-lib.md +19 -4
- package/index.js +54 -47
- package/lib/html-ctrls/buttons.js +157 -3
- package/lib/html-ctrls/fields.js +128 -6
- package/lib/html-ctrls/list.js +356 -3
- package/lib/html-ctrls/lists-btn.js +75 -17
- package/lib/html-ctrls/lists-stubs.js +109 -7
- package/lib/html-ctrls/mod-hfunc.js +35 -3
- package/lib/html-helper-lib.js +254 -56
- package/package.json +15 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.049-20240713]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -31,14 +31,37 @@ const BTS_DEF_GROUP_NAME = 'all';
|
|
|
31
31
|
|
|
32
32
|
// === module extra block (function definitions) ===
|
|
33
33
|
|
|
34
|
-
// === module main block
|
|
34
|
+
// === module main block ===
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/***
|
|
37
|
+
* (* constant definitions *)
|
|
38
|
+
*/
|
|
37
39
|
|
|
40
|
+
/***
|
|
41
|
+
* (* function definitions *)
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/***
|
|
45
|
+
* (* class definitions *)
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @description This class implements an instance of a pre-defined
|
|
50
|
+
* buttons set that is used in pair with a list elements.
|
|
51
|
+
* A set provide a buttons: <next>, <previous>, <first>
|
|
52
|
+
* and <last>.
|
|
53
|
+
*/
|
|
38
54
|
class THtmlListButtonsController {
|
|
39
55
|
#_btnSet = null;
|
|
40
56
|
#_events = null;
|
|
41
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param {object} opt
|
|
60
|
+
* @param {HTMLElement} opt.btnFirst
|
|
61
|
+
* @param {HTMLElement} opt.btnPrev
|
|
62
|
+
* @param {HTMLElement} opt.btnNext
|
|
63
|
+
* @param {HTMLElement} opt.btnLast
|
|
64
|
+
*/
|
|
42
65
|
constructor(opt) {
|
|
43
66
|
// load options
|
|
44
67
|
const _options = isPlainObject(opt) ? opt : {};
|
|
@@ -48,25 +71,11 @@ class THtmlListButtonsController {
|
|
|
48
71
|
btnPrev,
|
|
49
72
|
btnNext,
|
|
50
73
|
btnLast,
|
|
51
|
-
btn_frst, //* will deprecate
|
|
52
|
-
btn_prev, //* will deprecate
|
|
53
|
-
btn_next, //* will deprecate
|
|
54
|
-
btn_last, //* will deprecate
|
|
55
74
|
} = _options;
|
|
56
|
-
if (btnFirst === undefined) btnFirst = btn_frst;
|
|
57
|
-
if (btnPrev === undefined) btnPrev = btn_prev;
|
|
58
|
-
if (btnNext === undefined) btnNext = btn_next;
|
|
59
|
-
if (btnLast === undefined) btnLast = btn_last;
|
|
60
75
|
if (!isHTMLButton(btnFirst)) btnFirst = null;
|
|
61
76
|
if (!isHTMLButton(btnPrev)) btnPrev = null;
|
|
62
77
|
if (!isHTMLButton(btnNext)) btnNext = null;
|
|
63
78
|
if (!isHTMLButton(btnLast)) btnLast = null;
|
|
64
|
-
/*const controls = {
|
|
65
|
-
btnFirst,
|
|
66
|
-
btnPrev,
|
|
67
|
-
btnNext,
|
|
68
|
-
btnLast,
|
|
69
|
-
};*/ // // TODO: ???
|
|
70
79
|
// init buttons set
|
|
71
80
|
const _btnSet = new THtmlButtonsSet();
|
|
72
81
|
this.#_btnSet = _btnSet;
|
|
@@ -98,6 +107,12 @@ class THtmlListButtonsController {
|
|
|
98
107
|
this.#_events = new Map();
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
/**
|
|
111
|
+
* @param {object}
|
|
112
|
+
* @param {ID_STRING}
|
|
113
|
+
* @returns {none}
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
101
116
|
#_on_btn_pressed = (e, key) => {
|
|
102
117
|
//console.log(`THtmlListButtonsController._on_btn_pressed().key(${key}) ==> was called...`);
|
|
103
118
|
//e.preventDefault(); /* need to reconsider reason for use */
|
|
@@ -111,38 +126,81 @@ class THtmlListButtonsController {
|
|
|
111
126
|
};
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @param {ID_STRING}
|
|
131
|
+
* @param {...any}
|
|
132
|
+
* @returns {none}
|
|
133
|
+
* @private
|
|
134
|
+
* @see triggerEventHandler
|
|
135
|
+
*/
|
|
114
136
|
#_triggerEvent = (name, ...args) => {
|
|
115
137
|
triggerEventHandler(this.#_events, name, ...args);
|
|
116
138
|
}
|
|
117
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @param {none}
|
|
142
|
+
* @returns {none}
|
|
143
|
+
* @description Disables all buttons.
|
|
144
|
+
*/
|
|
118
145
|
disableAll(){
|
|
119
146
|
const _btnSet = this.#_btnSet;
|
|
120
147
|
_btnSet.disableGroup('move_bkwd');
|
|
121
148
|
_btnSet.disableGroup('move_frwd');
|
|
122
149
|
}
|
|
123
150
|
|
|
151
|
+
/**
|
|
152
|
+
* @param {none}
|
|
153
|
+
* @returns {none}
|
|
154
|
+
* @description Disables all buttons in 'move_bkwd' group.
|
|
155
|
+
*/
|
|
124
156
|
disableBkwd(){
|
|
125
157
|
this.#_btnSet.disableGroup('move_bkwd');
|
|
126
158
|
}
|
|
127
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @param {none}
|
|
162
|
+
* @returns {none}
|
|
163
|
+
* @description Disables all buttons in 'move_frwd' group.
|
|
164
|
+
*/
|
|
128
165
|
disableFrwd(){
|
|
129
166
|
this.#_btnSet.disableGroup('move_frwd');
|
|
130
167
|
}
|
|
131
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @param {none}
|
|
171
|
+
* @returns {none}
|
|
172
|
+
* @description Enables all buttons.
|
|
173
|
+
*/
|
|
132
174
|
enableAll(){
|
|
133
175
|
const _btnSet = this.#_btnSet;
|
|
134
176
|
_btnSet.enableGroup('move_bkwd');
|
|
135
177
|
_btnSet.enableGroup('move_frwd');
|
|
136
178
|
}
|
|
137
179
|
|
|
180
|
+
/**
|
|
181
|
+
* @param {none}
|
|
182
|
+
* @returns {none}
|
|
183
|
+
* @description Enables all buttons in 'move_bkwd' group.
|
|
184
|
+
*/
|
|
138
185
|
enableBkwd(){
|
|
139
186
|
this.#_btnSet.enableGroup('move_bkwd');
|
|
140
187
|
}
|
|
141
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @param {none}
|
|
191
|
+
* @returns {none}
|
|
192
|
+
* @description Enables all buttons in 'move_frwd' group.
|
|
193
|
+
*/
|
|
142
194
|
enableFrwd(){
|
|
143
195
|
this.#_btnSet.enableGroup('move_frwd');
|
|
144
196
|
}
|
|
145
197
|
|
|
198
|
+
/**
|
|
199
|
+
* @param {ID_STRING}
|
|
200
|
+
* @param {func}
|
|
201
|
+
* @returns {none}
|
|
202
|
+
* @description Sets a callback function to handle event.
|
|
203
|
+
*/
|
|
146
204
|
on(name, evnt){
|
|
147
205
|
pushEventHandler(this.#_events, name, evnt);
|
|
148
206
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.042-20240705]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -24,24 +24,51 @@ const {
|
|
|
24
24
|
|
|
25
25
|
// === module extra block (helper functions) ===
|
|
26
26
|
|
|
27
|
-
// === module main block
|
|
27
|
+
// === module main block ===
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/***
|
|
30
|
+
* (* constant definitions *)
|
|
31
|
+
*/
|
|
30
32
|
|
|
33
|
+
/***
|
|
34
|
+
* (* function definitions *)
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/***
|
|
38
|
+
* (* class definitions *)
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description This class implements an instance of a stub-items set
|
|
43
|
+
*/
|
|
31
44
|
class THtmlStubItemsSet {
|
|
32
45
|
#_host = null;
|
|
33
46
|
#_items = null;
|
|
34
47
|
#_defItem = '';
|
|
35
48
|
#_shownItem = null;
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @param {HTMLElement}
|
|
52
|
+
* @param {(array|object)} opt
|
|
53
|
+
* @param {(array|object)} opt.items
|
|
54
|
+
* @param {ID_STRING} opt.defaultItem
|
|
55
|
+
* @param {bool} opt.force
|
|
56
|
+
*/
|
|
57
|
+
constructor(host, opt) {
|
|
38
58
|
this.#_host = isHTMLElement(host) ? host : null;
|
|
39
59
|
this.#_items = new Map();
|
|
40
60
|
this.#_defItem = '';
|
|
41
61
|
this.#_shownItem = null;
|
|
42
|
-
if (isObject(
|
|
62
|
+
if (isObject(opt)) {
|
|
63
|
+
const obj = isArray(opt) ? { items: opt } : opt;
|
|
64
|
+
const { items, defaultItem, force } = obj;
|
|
65
|
+
this.loadItems(items, { defaultItem, force });
|
|
66
|
+
};
|
|
43
67
|
}
|
|
44
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @property {ID_STRING}
|
|
71
|
+
*/
|
|
45
72
|
get defItem(){
|
|
46
73
|
return this.#_defItem;
|
|
47
74
|
}
|
|
@@ -50,10 +77,19 @@ class THtmlStubItemsSet {
|
|
|
50
77
|
this.setDefItem(name);
|
|
51
78
|
}
|
|
52
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @property {number}
|
|
82
|
+
* @readonly
|
|
83
|
+
*/
|
|
53
84
|
get count(){
|
|
54
85
|
return this.#_items.size;
|
|
55
86
|
}
|
|
56
87
|
|
|
88
|
+
/**
|
|
89
|
+
* @param {none}
|
|
90
|
+
* @returns {none}
|
|
91
|
+
* @description Clears an instance content.
|
|
92
|
+
*/
|
|
57
93
|
clear(){
|
|
58
94
|
// // TODO: check if any item is shown
|
|
59
95
|
this.#_items.clear();
|
|
@@ -61,6 +97,11 @@ class THtmlStubItemsSet {
|
|
|
61
97
|
this.#_shownItem = null;
|
|
62
98
|
}
|
|
63
99
|
|
|
100
|
+
/**
|
|
101
|
+
* @param {ID_STRING}
|
|
102
|
+
* @returns {bool}
|
|
103
|
+
* @description Sets a default item.
|
|
104
|
+
*/
|
|
64
105
|
setDefItem(name){
|
|
65
106
|
let isACCEPTED = false;
|
|
66
107
|
if (typeof name === 'string') {
|
|
@@ -71,26 +112,53 @@ class THtmlStubItemsSet {
|
|
|
71
112
|
return isACCEPTED;
|
|
72
113
|
}
|
|
73
114
|
|
|
115
|
+
/**
|
|
116
|
+
* @param {none}
|
|
117
|
+
* @returns {none}
|
|
118
|
+
* @description Resets a default item.
|
|
119
|
+
*/
|
|
74
120
|
rstDefItem(){
|
|
75
121
|
// // TODO: check if item is shown
|
|
76
122
|
this.#_defItem = '';
|
|
77
123
|
}
|
|
78
124
|
|
|
125
|
+
/**
|
|
126
|
+
* @param {ID_STRING}
|
|
127
|
+
* @returns {bool}
|
|
128
|
+
* @description Checks if an item exists.
|
|
129
|
+
*/
|
|
79
130
|
hasItem(name){
|
|
80
131
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
81
132
|
return this.#_items.has(_name);
|
|
82
133
|
}
|
|
83
134
|
|
|
135
|
+
/**
|
|
136
|
+
* @param {none}
|
|
137
|
+
* @returns {none}
|
|
138
|
+
* @description Checks if any items exists.
|
|
139
|
+
*/
|
|
84
140
|
hasItems(){
|
|
85
141
|
return this.#_items.size > 0;
|
|
86
142
|
}
|
|
87
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @param {ID_STRING}
|
|
146
|
+
* @returns {?HTMLElement}
|
|
147
|
+
* @description Returns an item by its name.
|
|
148
|
+
*/
|
|
88
149
|
getItem(name){
|
|
89
150
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
90
151
|
const item = this.#_items.has(_name) ? this.#_items.get(_name) : null;
|
|
91
152
|
return isHTMLElement(item) ? item : null;
|
|
92
153
|
}
|
|
93
154
|
|
|
155
|
+
/**
|
|
156
|
+
* @param {ID_STRING}
|
|
157
|
+
* @param {HTMLElement}
|
|
158
|
+
* @param {bool}
|
|
159
|
+
* @returns {bool}
|
|
160
|
+
* @description Adds an item to an instance members.
|
|
161
|
+
*/
|
|
94
162
|
addItem(name, item, opt){
|
|
95
163
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
96
164
|
let isSUCCEED = false;
|
|
@@ -104,6 +172,11 @@ class THtmlStubItemsSet {
|
|
|
104
172
|
return isSUCCEED;
|
|
105
173
|
}
|
|
106
174
|
|
|
175
|
+
/**
|
|
176
|
+
* @param {ID_STRING}
|
|
177
|
+
* @returns {bool}
|
|
178
|
+
* @description Deletes an item from an instance members.
|
|
179
|
+
*/
|
|
107
180
|
delItem(name){
|
|
108
181
|
let _name = '';
|
|
109
182
|
let isSUCCEED = (
|
|
@@ -117,6 +190,11 @@ class THtmlStubItemsSet {
|
|
|
117
190
|
return isSUCCEED;
|
|
118
191
|
}
|
|
119
192
|
|
|
193
|
+
/**
|
|
194
|
+
* @param {ID_STRING}
|
|
195
|
+
* @returns {bool}
|
|
196
|
+
* @description Shows an item.
|
|
197
|
+
*/
|
|
120
198
|
showItem(name){
|
|
121
199
|
const item = this.getItem(name);
|
|
122
200
|
const isSUCCEED = this.#_host && item ? true : false;
|
|
@@ -124,10 +202,20 @@ class THtmlStubItemsSet {
|
|
|
124
202
|
return isSUCCEED;
|
|
125
203
|
}
|
|
126
204
|
|
|
205
|
+
/**
|
|
206
|
+
* @param {none}
|
|
207
|
+
* @returns {bool}
|
|
208
|
+
* @description Shows a default item.
|
|
209
|
+
*/
|
|
127
210
|
showDefItem(){
|
|
128
211
|
return this.showItem(this.#_defItem);
|
|
129
212
|
}
|
|
130
213
|
|
|
214
|
+
/**
|
|
215
|
+
* @param {ID_STRING}
|
|
216
|
+
* @returns {bool}
|
|
217
|
+
* @description Hides an item.
|
|
218
|
+
*/
|
|
131
219
|
hideItem(name){
|
|
132
220
|
const item = this.getItem(name);
|
|
133
221
|
const isSUCCEED = this.#_host && item ? true : false;
|
|
@@ -135,10 +223,24 @@ class THtmlStubItemsSet {
|
|
|
135
223
|
return isSUCCEED;
|
|
136
224
|
}
|
|
137
225
|
|
|
226
|
+
/**
|
|
227
|
+
* @param {none}
|
|
228
|
+
* @returns {bool}
|
|
229
|
+
* @description Hides a default item.
|
|
230
|
+
*/
|
|
138
231
|
hideDefItem(){
|
|
139
232
|
return this.hideItem(this.#_defItem);
|
|
140
233
|
}
|
|
141
234
|
|
|
235
|
+
/**
|
|
236
|
+
* @param {(array|object)}
|
|
237
|
+
* @param {(bool|object)} [opt]
|
|
238
|
+
* @param {ID_STRING} [opt.defaultItem]
|
|
239
|
+
* @param {bool} [opt.useClear=true]
|
|
240
|
+
* @param {bool} [opt.force=false]
|
|
241
|
+
* @returns {count}
|
|
242
|
+
* @description Adds an items to an instance members.
|
|
243
|
+
*/
|
|
142
244
|
loadItems(list, opt){
|
|
143
245
|
let _options = opt;
|
|
144
246
|
if (typeof _options === 'boolean') _options = { useClear: _options };
|
|
@@ -147,9 +249,9 @@ class THtmlStubItemsSet {
|
|
|
147
249
|
defaultItem,
|
|
148
250
|
useClear,
|
|
149
251
|
force,
|
|
150
|
-
load_as_new, //* will deprecate
|
|
252
|
+
//load_as_new, //* will deprecate
|
|
151
253
|
} = _options;
|
|
152
|
-
if (useClear === undefined) useClear = load_as_new;
|
|
254
|
+
//if (useClear === undefined) useClear = load_as_new;
|
|
153
255
|
if (typeof useClear !== 'boolean') useClear = true;
|
|
154
256
|
if (typeof force !== 'boolean') force = false;
|
|
155
257
|
let _list = list;
|
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.061-20240705]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
// === module extra block (helper functions) ===
|
|
6
6
|
|
|
7
|
-
// === module main block
|
|
7
|
+
// === module main block ===
|
|
8
8
|
|
|
9
|
+
/***
|
|
10
|
+
* (* constant definitions *)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/***
|
|
14
|
+
* (* function definitions *)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @function pushEventHandler
|
|
19
|
+
* @param {object}
|
|
20
|
+
* @param {ID_STRING}
|
|
21
|
+
* @param {func}
|
|
22
|
+
* @returns {none}
|
|
23
|
+
* @inner
|
|
24
|
+
*/
|
|
9
25
|
function pushEventHandler(pool, name, evnt){
|
|
10
26
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
11
27
|
if (_name !== '' && typeof evnt === 'function') {
|
|
@@ -19,6 +35,14 @@ function pushEventHandler(pool, name, evnt){
|
|
|
19
35
|
};
|
|
20
36
|
};
|
|
21
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @function triggerEventHandler
|
|
40
|
+
* @param {object}
|
|
41
|
+
* @param {ID_STRING}
|
|
42
|
+
* @param {...any}
|
|
43
|
+
* @returns {none}
|
|
44
|
+
* @inner
|
|
45
|
+
*/
|
|
22
46
|
function triggerEventHandler(pool, name, ...args){
|
|
23
47
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
24
48
|
if (_name !== '') {
|
|
@@ -26,6 +50,12 @@ function triggerEventHandler(pool, name, ...args){
|
|
|
26
50
|
};
|
|
27
51
|
};
|
|
28
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @function readOnClickEventInfo
|
|
55
|
+
* @param {object}
|
|
56
|
+
* @returns {object}
|
|
57
|
+
* @inner
|
|
58
|
+
*/
|
|
29
59
|
function readOnClickEventInfo(e) {
|
|
30
60
|
let item = null;
|
|
31
61
|
const { eventPhase, detail: onClickNum } = e;
|
|
@@ -51,7 +81,9 @@ function readOnClickEventInfo(e) {
|
|
|
51
81
|
return { item, onClickNum };
|
|
52
82
|
};
|
|
53
83
|
|
|
54
|
-
|
|
84
|
+
/***
|
|
85
|
+
* (* class definitions *)
|
|
86
|
+
*/
|
|
55
87
|
|
|
56
88
|
// === module exports block ===
|
|
57
89
|
|