@cntwg/html-helper 0.0.17 → 0.0.19
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 +176 -0
- package/LICENSE +1 -1
- package/README.md +11 -2
- package/doc/html-ctrls-btn.md +7 -7
- package/doc/html-ctrls-fields.md +140 -0
- package/doc/html-ctrls-list.md +9 -5
- package/doc/html-helper-lib.md +23 -10
- package/index.js +16 -5
- package/lib/html-ctrls/buttons.js +242 -0
- package/lib/html-ctrls/fields.js +342 -0
- package/lib/{html-ctrls-list.js → html-ctrls/list.js} +61 -68
- package/lib/html-ctrls/lists-btn.js +155 -0
- package/lib/html-ctrls/lists-stubs.js +6 -10
- package/lib/html-ctrls/mod-hfunc.js +60 -0
- package/lib/html-helper-lib.js +78 -27
- package/package.json +18 -8
- package/lib/html-ctrls/lists-btns.js +0 -277
- package/lib/html-ctrls-btn.js +0 -343
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntwg/html-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "A base HTML-helper library for js",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,16 +13,22 @@
|
|
|
13
13
|
"doc/html-helper-lib.md",
|
|
14
14
|
"doc/html-ctrls-list.md",
|
|
15
15
|
"doc/html-ctrls-btn.md",
|
|
16
|
+
"doc/html-ctrls-fields.md",
|
|
16
17
|
"lib/html-helper-lib.js",
|
|
17
18
|
"lib/html-ctrls/lists-stubs.js",
|
|
18
|
-
"lib/html-ctrls/lists-
|
|
19
|
-
"lib/html-ctrls
|
|
20
|
-
"lib/html-ctrls
|
|
21
|
-
"
|
|
19
|
+
"lib/html-ctrls/lists-btn.js",
|
|
20
|
+
"lib/html-ctrls/list.js",
|
|
21
|
+
"lib/html-ctrls/buttons.js",
|
|
22
|
+
"lib/html-ctrls/fields.js",
|
|
23
|
+
"lib/html-ctrls/mod-hfunc.js",
|
|
24
|
+
"index.js",
|
|
25
|
+
"CHANGELOG.md"
|
|
22
26
|
],
|
|
23
27
|
"scripts": {
|
|
24
28
|
"test": "jest",
|
|
25
29
|
"test-bs": "jest base/",
|
|
30
|
+
"test-bs:g1": "jest base/fg-1",
|
|
31
|
+
"test-bs:g2": "jest base/fg-2",
|
|
26
32
|
"test-lc1": "jest THtmlItemsListContainer",
|
|
27
33
|
"test-lc2": "jest THtmlItemsListController",
|
|
28
34
|
"test-lc2:bs": "jest THtmlItemsListController/base",
|
|
@@ -36,11 +42,15 @@
|
|
|
36
42
|
"test-bc1:bs": "jest THtmlButtonsControllerARCSet/base",
|
|
37
43
|
"test-bc1:ec": "jest THtmlButtonsControllerARCSet/events"
|
|
38
44
|
},
|
|
45
|
+
"imports": {
|
|
46
|
+
"#lib/*": "./lib/*"
|
|
47
|
+
},
|
|
39
48
|
"dependencies": {
|
|
40
|
-
"@ygracs/bsfoc-lib-js": "^0.1.
|
|
49
|
+
"@ygracs/bsfoc-lib-js": "^0.1.3"
|
|
41
50
|
},
|
|
42
51
|
"devDependencies": {
|
|
43
|
-
"jest": "^29.0
|
|
44
|
-
"jest-environment-jsdom": "^29.0
|
|
52
|
+
"jest": "^29.5.0",
|
|
53
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
54
|
+
"minimist": "^1.2.8"
|
|
45
55
|
}
|
|
46
56
|
}
|
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
// [v0.1.042-20220912]
|
|
2
|
-
|
|
3
|
-
// === module init block ===
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
readAsString,
|
|
7
|
-
readAsNumber,
|
|
8
|
-
isNotEmptyString,
|
|
9
|
-
isPlainObject,
|
|
10
|
-
valueToArray,
|
|
11
|
-
TItemsICollection,
|
|
12
|
-
} = require('@ygracs/bsfoc-lib-js');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
CSS_CLASS_STRING,
|
|
16
|
-
isHTMLElement,
|
|
17
|
-
} = require('../html-helper-lib.js');
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
isHTMLButton,
|
|
21
|
-
THtmlButtonsSet,
|
|
22
|
-
} = require('../html-ctrls-btn');
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
CSS_CLASS_SELECTED,
|
|
26
|
-
CSS_CLASS_DISABLED,
|
|
27
|
-
CSS_CLASS_HIDDEN,
|
|
28
|
-
} = CSS_CLASS_STRING;
|
|
29
|
-
|
|
30
|
-
const BTS_DEF_GROUP_NAME = 'all';
|
|
31
|
-
|
|
32
|
-
// === module extra block (function definitions) ===
|
|
33
|
-
|
|
34
|
-
// === module main block (function definitions) ===
|
|
35
|
-
|
|
36
|
-
// === module main block (class definitions) ===
|
|
37
|
-
|
|
38
|
-
class THtmlListButtonsController {
|
|
39
|
-
#_btnSet = null;
|
|
40
|
-
#_events = null;
|
|
41
|
-
|
|
42
|
-
constructor(opt) {
|
|
43
|
-
// load options
|
|
44
|
-
const _options = isPlainObject(opt) ? opt : {};
|
|
45
|
-
// load controls
|
|
46
|
-
let {
|
|
47
|
-
btnFirst,
|
|
48
|
-
btnPrev,
|
|
49
|
-
btnNext,
|
|
50
|
-
btnLast,
|
|
51
|
-
btn_frst, //* will deprecate
|
|
52
|
-
btn_prev, //* will deprecate
|
|
53
|
-
btn_next, //* will deprecate
|
|
54
|
-
btn_last, //* will deprecate
|
|
55
|
-
} = _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
|
-
if (!isHTMLButton(btnFirst)) btnFirst = null;
|
|
61
|
-
if (!isHTMLButton(btnPrev)) btnPrev = null;
|
|
62
|
-
if (!isHTMLButton(btnNext)) btnNext = null;
|
|
63
|
-
if (!isHTMLButton(btnLast)) btnLast = null;
|
|
64
|
-
const controls = {
|
|
65
|
-
btnFirst,
|
|
66
|
-
btnPrev,
|
|
67
|
-
btnNext,
|
|
68
|
-
btnLast,
|
|
69
|
-
};
|
|
70
|
-
// init buttons set
|
|
71
|
-
const _btnSet = new THtmlButtonsSet();
|
|
72
|
-
this.#_btnSet = _btnSet;
|
|
73
|
-
_btnSet.addGroup('move_frwd');
|
|
74
|
-
_btnSet.addGroup('move_bkwd');
|
|
75
|
-
_btnSet.addGroup('dsbl_ctrls');
|
|
76
|
-
if (btnFirst && btnLast) {
|
|
77
|
-
_btnSet.addItem('btn_frst', btnFirst, 'move_bkwd');
|
|
78
|
-
_btnSet.addItem('btn_last', btnLast, 'move_frwd');
|
|
79
|
-
btnFirst.addEventListener('click', this.#_on_btn_frst_pressed);
|
|
80
|
-
btnLast.addEventListener('click', this.#_on_btn_last_pressed);
|
|
81
|
-
} else {
|
|
82
|
-
_btnSet.addItem('btn_frst', btnFirst, 'dsbl_ctrls');
|
|
83
|
-
_btnSet.addItem('btn_last', btnLast, 'dsbl_ctrls');
|
|
84
|
-
};
|
|
85
|
-
if (btnPrev && btnNext) {
|
|
86
|
-
_btnSet.addItem('btn_prev', btnPrev, 'move_bkwd');
|
|
87
|
-
_btnSet.addItem('btn_next', btnNext, 'move_frwd');
|
|
88
|
-
btnPrev.addEventListener('click', this.#_on_btn_prev_pressed);
|
|
89
|
-
btnNext.addEventListener('click', this.#_on_btn_next_pressed);
|
|
90
|
-
} else {
|
|
91
|
-
_btnSet.addItem('btn_prev', btnPrev, 'dsbl_ctrls');
|
|
92
|
-
_btnSet.addItem('btn_next', btnNext, 'dsbl_ctrls');
|
|
93
|
-
};
|
|
94
|
-
_btnSet.disableGroup('move_frwd');
|
|
95
|
-
_btnSet.disableGroup('move_bkwd');
|
|
96
|
-
_btnSet.disableGroup('dsbl_ctrls');
|
|
97
|
-
// init events controller
|
|
98
|
-
this.#_events = new Map();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
#_on_btn_frst_pressed = (e) => {
|
|
102
|
-
//console.log('THtmlListButtonsController._on_btn_frst_pressed() ==> was called...');
|
|
103
|
-
//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
|
-
};
|
|
122
|
-
if (
|
|
123
|
-
curItem instanceof HTMLElement
|
|
124
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
125
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
126
|
-
) {
|
|
127
|
-
this.#_triggerEvent('btn-first-pressed', e);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
#_on_btn_last_pressed = (e) => {
|
|
132
|
-
//console.log('THtmlListButtonsController._on_btn_last_pressed() ==> was called...');
|
|
133
|
-
//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
|
-
};
|
|
152
|
-
if (
|
|
153
|
-
curItem instanceof HTMLElement
|
|
154
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
155
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
156
|
-
) {
|
|
157
|
-
this.#_triggerEvent('btn-last-pressed', e);
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
#_on_btn_prev_pressed = (e) => {
|
|
162
|
-
//console.log('THtmlListButtonsController._on_btn_prev_pressed() ==> was called...');
|
|
163
|
-
//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
|
-
};
|
|
182
|
-
if (
|
|
183
|
-
curItem instanceof HTMLElement
|
|
184
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
185
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
186
|
-
) {
|
|
187
|
-
this.#_triggerEvent('btn-prev-pressed', e);
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
#_on_btn_next_pressed = (e) => {
|
|
192
|
-
//console.log('THtmlListButtonsController._on_btn_next_pressed() ==> was called...');
|
|
193
|
-
//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
|
-
};
|
|
212
|
-
if (
|
|
213
|
-
curItem instanceof HTMLElement
|
|
214
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
215
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
216
|
-
) {
|
|
217
|
-
this.#_triggerEvent('btn-next-pressed', e);
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
#_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
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
disableAll(){
|
|
230
|
-
const _btnSet = this.#_btnSet;
|
|
231
|
-
_btnSet.disableGroup('move_bkwd');
|
|
232
|
-
_btnSet.disableGroup('move_frwd');
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
disableBkwd(){
|
|
236
|
-
this.#_btnSet.disableGroup('move_bkwd');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
disableFrwd(){
|
|
240
|
-
this.#_btnSet.disableGroup('move_frwd');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
enableAll(){
|
|
244
|
-
const _btnSet = this.#_btnSet;
|
|
245
|
-
_btnSet.enableGroup('move_bkwd');
|
|
246
|
-
_btnSet.enableGroup('move_frwd');
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
enableBkwd(){
|
|
250
|
-
this.#_btnSet.enableGroup('move_bkwd');
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
enableFrwd(){
|
|
254
|
-
this.#_btnSet.enableGroup('move_frwd');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
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
|
-
};
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// === module exports block ===
|
|
274
|
-
|
|
275
|
-
exports.THtmlListButtonsController = THtmlListButtonsController;
|
|
276
|
-
|
|
277
|
-
exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
|
package/lib/html-ctrls-btn.js
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
// [v0.1.043-20220922]
|
|
2
|
-
|
|
3
|
-
// === module init block ===
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
readAsString, readAsNumber, isNotEmptyString,
|
|
7
|
-
isPlainObject, valueToArray,
|
|
8
|
-
TItemsICollection,
|
|
9
|
-
} = require('@ygracs/bsfoc-lib-js');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
isHTMLElement, CSS_CLASS_STRING,
|
|
13
|
-
valueToIDString,
|
|
14
|
-
} = require('./html-helper-lib.js');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
CSS_CLASS_SELECTED,
|
|
18
|
-
CSS_CLASS_DISABLED,
|
|
19
|
-
CSS_CLASS_HIDDEN,
|
|
20
|
-
} = CSS_CLASS_STRING;
|
|
21
|
-
|
|
22
|
-
const BTS_DEF_GROUP_NAME = 'all';
|
|
23
|
-
|
|
24
|
-
const etlHTagInputForBtn = new Set([
|
|
25
|
-
'button', 'submit', 'reset', 'image',
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
// === module extra block (function definitions) ===
|
|
29
|
-
|
|
30
|
-
function isHTMLButton(obj){
|
|
31
|
-
let result = false;
|
|
32
|
-
if (isHTMLElement(obj)) {
|
|
33
|
-
switch (obj.tagName.toLowerCase()) {
|
|
34
|
-
case 'button':
|
|
35
|
-
result = true;
|
|
36
|
-
break;
|
|
37
|
-
case 'input':
|
|
38
|
-
result = etlHTagInputForBtn.has(obj.type.toLowerCase());
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
break;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// === module main block (function definitions) ===
|
|
48
|
-
|
|
49
|
-
// === module main block (class definitions) ===
|
|
50
|
-
|
|
51
|
-
class THtmlButtonsSet {
|
|
52
|
-
#_btnCol = null;
|
|
53
|
-
|
|
54
|
-
constructor(){
|
|
55
|
-
// define default functions for manipulators
|
|
56
|
-
const __user_index_getter = (value) => {
|
|
57
|
-
//return readAsString(value, '', { useTrim: true, numberToString: true });
|
|
58
|
-
return valueToIDString(value);
|
|
59
|
-
};
|
|
60
|
-
const __user_item_getter = (value) => {
|
|
61
|
-
return THtmlButtonsSet.isHTMLButton(value) ? value : null;
|
|
62
|
-
};
|
|
63
|
-
this.#_btnCol = new TItemsICollection({
|
|
64
|
-
userFn: {
|
|
65
|
-
checkIndexFn: isNotEmptyString,
|
|
66
|
-
readIndexFn: __user_index_getter,
|
|
67
|
-
checkItemFn: THtmlButtonsSet.isHTMLButton,
|
|
68
|
-
readItemFn: __user_item_getter,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get ItemNames(){
|
|
74
|
-
return this.#_btnCol.ItemNames;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get GroupNames(){
|
|
78
|
-
return this.#_btnCol.CategoryNames;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
hasItem(name){
|
|
82
|
-
return this.#_btnCol.hasItem(name);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
addItem(...args){
|
|
86
|
-
return this.#_btnCol.addItem(...args);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
addItemToGroup(...args){
|
|
90
|
-
return this.#_btnCol.addItemToCategory(...args);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
delItem(name){
|
|
94
|
-
return this.#_btnCol.delItem(name);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
delItemFromGroup(...args){
|
|
98
|
-
return this.#_btnCol.delItemFromGroup(...args);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
renameItem(oldName, newName){
|
|
102
|
-
return this.#_btnCol.renameItem(oldName, newName, false);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
enableItem(name){
|
|
106
|
-
const item = this.#_btnCol.getItem(name);
|
|
107
|
-
if (item) {
|
|
108
|
-
item.classList.remove(CSS_CLASS_DISABLED);
|
|
109
|
-
item.disabled = false;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
disableItem(name){
|
|
114
|
-
const item = this.#_btnCol.getItem(name);
|
|
115
|
-
if (item) {
|
|
116
|
-
item.classList.add(CSS_CLASS_DISABLED);
|
|
117
|
-
item.disabled = true;
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
hasGroup(name){
|
|
122
|
-
return this.#_btnCol.hasCategory(name);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
addGroup(name){
|
|
126
|
-
return this.#_btnCol.addCategory(name);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
delGroup(name){
|
|
130
|
-
return this.#_btnCol.delCategory(name);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
renameGroup(oldName, newName){
|
|
134
|
-
return this.#_btnCol.renameCategory(oldName, newName, false);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
enableGroup(value){
|
|
138
|
-
const group = this.#_btnCol.getCategory(value);
|
|
139
|
-
valueToArray(group).forEach((item) => {
|
|
140
|
-
if (item) {
|
|
141
|
-
item.classList.remove(CSS_CLASS_DISABLED);
|
|
142
|
-
item.disabled = false;
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
disableGroup(value){
|
|
148
|
-
const group = this.#_btnCol.getCategory(value);
|
|
149
|
-
valueToArray(group).forEach((item) => {
|
|
150
|
-
if (item) {
|
|
151
|
-
item.classList.add(CSS_CLASS_DISABLED);
|
|
152
|
-
item.disabled = true;
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
static get isHTMLButton(){
|
|
158
|
-
return isHTMLButton;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
class THtmlButtonsControllerARCSet {
|
|
164
|
-
#_btnSet = null;
|
|
165
|
-
#_events = null;
|
|
166
|
-
|
|
167
|
-
constructor(opt) {
|
|
168
|
-
// load options
|
|
169
|
-
const _options = isPlainObject(opt) ? opt : {};
|
|
170
|
-
// load controls
|
|
171
|
-
let {
|
|
172
|
-
btnApply,
|
|
173
|
-
btnReset,
|
|
174
|
-
btnCancel,
|
|
175
|
-
} = _options;
|
|
176
|
-
if (!isHTMLButton(btnApply)) btnApply = null;
|
|
177
|
-
if (!isHTMLButton(btnReset)) btnReset = null;
|
|
178
|
-
if (!isHTMLButton(btnCancel)) btnCancel = null;
|
|
179
|
-
const controls = {
|
|
180
|
-
btnApply,
|
|
181
|
-
btnReset,
|
|
182
|
-
btnCancel,
|
|
183
|
-
};
|
|
184
|
-
// init buttons set
|
|
185
|
-
const _btnSet = new THtmlButtonsSet();
|
|
186
|
-
this.#_btnSet = _btnSet;
|
|
187
|
-
_btnSet.addGroup('main');
|
|
188
|
-
_btnSet.addGroup('all');
|
|
189
|
-
if (btnApply) {
|
|
190
|
-
_btnSet.addItem('btn_apply', btnApply, 'main', 'all');
|
|
191
|
-
btnApply.addEventListener('click', this.#_on_btn_apply_pressed);
|
|
192
|
-
};
|
|
193
|
-
if (btnReset) {
|
|
194
|
-
_btnSet.addItem('btn_reset', btnReset, 'main', 'all');
|
|
195
|
-
btnReset.addEventListener('click', this.#_on_btn_reset_pressed);
|
|
196
|
-
};
|
|
197
|
-
if (btnCancel) {
|
|
198
|
-
_btnSet.addItem('btn_cancel', btnCancel, 'all');
|
|
199
|
-
btnCancel.addEventListener('click', this.#_on_btn_cancel_pressed);
|
|
200
|
-
};
|
|
201
|
-
_btnSet.disableGroup('main');
|
|
202
|
-
// init events controller
|
|
203
|
-
this.#_events = new Map();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
#_on_btn_apply_pressed = (e) => {
|
|
207
|
-
//console.log('THtmlListButtonsController._on_btn_apply_pressed() ==> was called...');
|
|
208
|
-
//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
|
-
};
|
|
227
|
-
if (
|
|
228
|
-
curItem instanceof HTMLElement
|
|
229
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
230
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
231
|
-
) {
|
|
232
|
-
this.#_triggerEvent('btn-apply-pressed', e);
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
#_on_btn_reset_pressed = (e) => {
|
|
237
|
-
//console.log('THtmlListButtonsController._on_btn_reset_pressed() ==> was called...');
|
|
238
|
-
//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
|
-
};
|
|
257
|
-
if (
|
|
258
|
-
curItem instanceof HTMLElement
|
|
259
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
260
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
261
|
-
) {
|
|
262
|
-
this.#_triggerEvent('btn-reset-pressed', e);
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
#_on_btn_cancel_pressed = (e) => {
|
|
267
|
-
//console.log('THtmlListButtonsController._on_btn_cancel_pressed() ==> was called...');
|
|
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
|
-
};
|
|
287
|
-
if (
|
|
288
|
-
curItem instanceof HTMLElement
|
|
289
|
-
&& (on_click_num === 0 || on_click_num === 1)
|
|
290
|
-
&& !curItem.classList.contains(CSS_CLASS_DISABLED)
|
|
291
|
-
) {
|
|
292
|
-
this.#_triggerEvent('btn-cancel-pressed', e);
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
#_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
|
-
};
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
disableMain(){
|
|
305
|
-
this.#_btnSet.disableGroup('main');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
enableMain(){
|
|
309
|
-
this.#_btnSet.enableGroup('main');
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
disableAll(){
|
|
313
|
-
this.#_btnSet.disableGroup('all');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
enableAll(){
|
|
317
|
-
this.#_btnSet.enableGroup('all');
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
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
|
-
};
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
// === module exports block ===
|
|
337
|
-
|
|
338
|
-
exports.THtmlButtonsSet = THtmlButtonsSet;
|
|
339
|
-
exports.THtmlButtonsControllerARCSet = THtmlButtonsControllerARCSet;
|
|
340
|
-
|
|
341
|
-
exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
|
|
342
|
-
|
|
343
|
-
exports.isHTMLButton = isHTMLButton;
|