@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
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
// [v0.1.
|
|
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('
|
|
18
|
+
} = require('../html-helper-lib.js');
|
|
21
19
|
|
|
22
|
-
const { THtmlStubItemsSet } = require('./
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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(
|
|
212
|
-
|
|
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
|
-
|
|
212
|
+
const { item } = srchListElementByAttr(this.#_items, 'id', value);
|
|
213
|
+
return item;
|
|
217
214
|
}
|
|
218
215
|
|
|
219
216
|
addItem(item, opt){
|
|
@@ -225,9 +222,12 @@ class THtmlItemsListContainer {
|
|
|
225
222
|
);
|
|
226
223
|
const isSUCCEED = index !== -1;
|
|
227
224
|
if (isSUCCEED) {
|
|
228
|
-
|
|
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
|
-
|
|
229
|
+
const _host = this.#_host;
|
|
230
|
+
if (_host) _host.append(item);
|
|
231
231
|
};
|
|
232
232
|
return isSUCCEED ? index : -1;
|
|
233
233
|
}
|
|
@@ -300,6 +300,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
300
300
|
let {
|
|
301
301
|
//autoHideNewItems, // [*] processed by parent
|
|
302
302
|
//markCurrentItem, // [*] processed by parent
|
|
303
|
+
//itemBaseClassID, // [*] processed by parent
|
|
303
304
|
showStubsIfEmpty,
|
|
304
305
|
allowGroupSelection,
|
|
305
306
|
allowSelectionLocks,
|
|
@@ -364,16 +365,19 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
364
365
|
//* // NOTE: currently on eventPhase = 2 and 3
|
|
365
366
|
//*case 1:
|
|
366
367
|
/**/// capturing stage
|
|
367
|
-
case 2:
|
|
368
|
+
case 2: {
|
|
368
369
|
/**/// target stage
|
|
369
370
|
if (target !== this.#_host) curItem = target;
|
|
370
371
|
break;
|
|
371
|
-
|
|
372
|
+
}
|
|
373
|
+
case 3: {
|
|
372
374
|
/**/// bubblig stage
|
|
373
375
|
curItem = catchEventOnHost ? target : currentTarget;
|
|
374
376
|
break;
|
|
375
|
-
|
|
377
|
+
}
|
|
378
|
+
default: {
|
|
376
379
|
break;
|
|
380
|
+
}
|
|
377
381
|
};
|
|
378
382
|
if (
|
|
379
383
|
!isSelectionLocked
|
|
@@ -391,11 +395,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
391
395
|
};
|
|
392
396
|
|
|
393
397
|
#_triggerEvent = (name, ...args) => {
|
|
394
|
-
|
|
395
|
-
if (_name !== '') {
|
|
396
|
-
const _events = this.#_events;
|
|
397
|
-
if (_events.has(_name)) _events.get(_name)(...args);
|
|
398
|
-
};
|
|
398
|
+
triggerEventHandler(this.#_events, name, ...args);
|
|
399
399
|
};
|
|
400
400
|
|
|
401
401
|
get SelectedItems(){
|
|
@@ -597,20 +597,23 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
597
597
|
_selects.clear();
|
|
598
598
|
};
|
|
599
599
|
switch (mode) {
|
|
600
|
-
case ILC_SMODE_SHFT:
|
|
600
|
+
case ILC_SMODE_SHFT: {
|
|
601
601
|
if (indexCI > indexNI) [ indexCI, indexNI ] = [ indexNI, indexCI ];
|
|
602
602
|
for (let i = indexCI; i < indexNI + 1; i++) {
|
|
603
603
|
this.#_selectItem(i);
|
|
604
604
|
};
|
|
605
605
|
break;
|
|
606
|
-
|
|
606
|
+
}
|
|
607
|
+
case ILC_SMODE_CTRL: {
|
|
607
608
|
this.#_selectItem(this.srchIndex(item));
|
|
608
609
|
break;
|
|
609
|
-
|
|
610
|
+
}
|
|
611
|
+
default: {
|
|
610
612
|
if (this.#_selectItem(this.srchIndex(item))) {
|
|
611
613
|
if (forceCI) this.#_setCurIndex(indexNI);
|
|
612
614
|
};
|
|
613
615
|
break;
|
|
616
|
+
}
|
|
614
617
|
};
|
|
615
618
|
}
|
|
616
619
|
|
|
@@ -666,17 +669,7 @@ class THtmlItemsListController extends THtmlItemsListContainer {
|
|
|
666
669
|
}
|
|
667
670
|
|
|
668
671
|
on(name, evnt){
|
|
669
|
-
|
|
670
|
-
if (_name !== '' && typeof evnt === 'function') {
|
|
671
|
-
const _events = this.#_events;
|
|
672
|
-
if (!_events.has(_name)) {
|
|
673
|
-
_events.set(_name, evnt);
|
|
674
|
-
} else {
|
|
675
|
-
/* NOTE:
|
|
676
|
-
* for current you can't reset or set new one on the same event
|
|
677
|
-
*/
|
|
678
|
-
};
|
|
679
|
-
};
|
|
672
|
+
pushEventHandler(this.#_events, name, evnt);
|
|
680
673
|
}
|
|
681
674
|
|
|
682
675
|
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// [v0.1.047-20230614]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isPlainObject,
|
|
7
|
+
} = require('@ygracs/bsfoc-lib-js');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
isHTMLElement,
|
|
11
|
+
CSS_CLASS_STRING,
|
|
12
|
+
} = require('../html-helper-lib.js');
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
isHTMLButton,
|
|
16
|
+
THtmlButtonsSet,
|
|
17
|
+
} = require('./buttons.js');
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
pushEventHandler, triggerEventHandler,
|
|
21
|
+
readOnClickEventInfo,
|
|
22
|
+
} = require('./mod-hfunc.js');
|
|
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
|
+
};*/ // // TODO: ???
|
|
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', e => this.#_on_btn_pressed(e, 'first'));
|
|
80
|
+
btnLast.addEventListener('click', e => this.#_on_btn_pressed(e, 'last'));
|
|
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', e => this.#_on_btn_pressed(e, 'prev'));
|
|
89
|
+
btnNext.addEventListener('click', e => this.#_on_btn_pressed(e, 'next'));
|
|
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_pressed = (e, key) => {
|
|
102
|
+
//console.log(`THtmlListButtonsController._on_btn_pressed().key(${key}) ==> was called...`);
|
|
103
|
+
//e.preventDefault(); /* need to reconsider reason for use */
|
|
104
|
+
const { item, onClickNum } = readOnClickEventInfo(e);
|
|
105
|
+
if (
|
|
106
|
+
item instanceof HTMLElement
|
|
107
|
+
&& (onClickNum === 0 || onClickNum === 1)
|
|
108
|
+
&& !item.classList.contains(CSS_CLASS_DISABLED)
|
|
109
|
+
) {
|
|
110
|
+
this.#_triggerEvent(`btn-${key}-pressed`, e);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#_triggerEvent = (name, ...args) => {
|
|
115
|
+
triggerEventHandler(this.#_events, name, ...args);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
disableAll(){
|
|
119
|
+
const _btnSet = this.#_btnSet;
|
|
120
|
+
_btnSet.disableGroup('move_bkwd');
|
|
121
|
+
_btnSet.disableGroup('move_frwd');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
disableBkwd(){
|
|
125
|
+
this.#_btnSet.disableGroup('move_bkwd');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
disableFrwd(){
|
|
129
|
+
this.#_btnSet.disableGroup('move_frwd');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
enableAll(){
|
|
133
|
+
const _btnSet = this.#_btnSet;
|
|
134
|
+
_btnSet.enableGroup('move_bkwd');
|
|
135
|
+
_btnSet.enableGroup('move_frwd');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
enableBkwd(){
|
|
139
|
+
this.#_btnSet.enableGroup('move_bkwd');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
enableFrwd(){
|
|
143
|
+
this.#_btnSet.enableGroup('move_frwd');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
on(name, evnt){
|
|
147
|
+
pushEventHandler(this.#_events, name, evnt);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// === module exports block ===
|
|
152
|
+
|
|
153
|
+
exports.THtmlListButtonsController = THtmlListButtonsController;
|
|
154
|
+
|
|
155
|
+
exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
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
|
|
146
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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,60 @@
|
|
|
1
|
+
// [v0.1.060-20230614]
|
|
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
|
+
|
|
29
|
+
function readOnClickEventInfo(e) {
|
|
30
|
+
let item = null;
|
|
31
|
+
const { eventPhase, detail: onClickNum } = e;
|
|
32
|
+
//console.log('CHECK: e => ditail:['+onClickNum+']');
|
|
33
|
+
//console.log('CHECK: e => phase:['+eventPhase+']');
|
|
34
|
+
switch (eventPhase) {
|
|
35
|
+
//*case 1:
|
|
36
|
+
//* // NOTE: currently on eventPhase = 2 and 3
|
|
37
|
+
case 2: {
|
|
38
|
+
/**/// capturing stage
|
|
39
|
+
item = e.target;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 3: {
|
|
43
|
+
/**/// bubblig stage
|
|
44
|
+
item = e.currentTarget;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
default: {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return { item, onClickNum };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// === module main block (class definitions) ===
|
|
55
|
+
|
|
56
|
+
// === module exports block ===
|
|
57
|
+
|
|
58
|
+
exports.pushEventHandler = pushEventHandler;
|
|
59
|
+
exports.triggerEventHandler = triggerEventHandler;
|
|
60
|
+
exports.readOnClickEventInfo = readOnClickEventInfo;
|
package/lib/html-helper-lib.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.019-20230614]
|
|
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){
|
|
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);
|
|
@@ -85,34 +85,77 @@ function unmarkActiveHtmlElement(obj){
|
|
|
85
85
|
return isSUCCEED;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
function lockHtmlElement(obj){
|
|
89
|
+
let isSUCCEED = isHTMLElement(obj);
|
|
90
|
+
if (isSUCCEED) {
|
|
91
|
+
const { classList, tagName } = obj;
|
|
92
|
+
classList.add(CSS_CLASS_DISABLED);
|
|
93
|
+
switch (tagName.toLowerCase()) {
|
|
94
|
+
case 'button':
|
|
95
|
+
case 'input': {
|
|
96
|
+
obj.disabled = true;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
default: {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
return isSUCCEED;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
function unlockHtmlElement(obj){
|
|
108
|
+
let isSUCCEED = isHTMLElement(obj);
|
|
109
|
+
if (isSUCCEED) {
|
|
110
|
+
const { classList, tagName } = obj;
|
|
111
|
+
classList.remove(CSS_CLASS_DISABLED);
|
|
112
|
+
switch (tagName.toLowerCase()) {
|
|
113
|
+
case 'button':
|
|
114
|
+
case 'input': {
|
|
115
|
+
obj.disabled = false;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
default: {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
return isSUCCEED;
|
|
124
|
+
};
|
|
125
|
+
|
|
88
126
|
function inactivateHtmlElements(...args) {
|
|
89
127
|
for (let item of args) {
|
|
90
|
-
|
|
91
|
-
item.classList.add(CSS_CLASS_DISABLED);
|
|
92
|
-
switch (item.tagName.toLowerCase()) {
|
|
93
|
-
case 'button':
|
|
94
|
-
case 'input':
|
|
95
|
-
item.disabled = true; break;
|
|
96
|
-
default:
|
|
97
|
-
break;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
128
|
+
lockHtmlElement(item);
|
|
100
129
|
};
|
|
101
130
|
};
|
|
102
131
|
|
|
103
132
|
function activateHtmlElements(...args) {
|
|
104
133
|
for (let item of args) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
unlockHtmlElement(item);
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
function readAsAttrValue(value){
|
|
139
|
+
let result = null;
|
|
140
|
+
switch (typeof value) {
|
|
141
|
+
case 'boolean': {
|
|
142
|
+
result = value.toString();
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'number': {
|
|
146
|
+
if (Number.isNaN(value)) break;
|
|
147
|
+
result = value.toString();
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'string': {
|
|
151
|
+
result = value.trim();
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
115
157
|
};
|
|
158
|
+
return result;
|
|
116
159
|
};
|
|
117
160
|
|
|
118
161
|
function valueToClassList(value, opt){
|
|
@@ -137,16 +180,19 @@ function valueToClassList(value, opt){
|
|
|
137
180
|
function valueToIDString(value){
|
|
138
181
|
let result = '';
|
|
139
182
|
switch (typeof value) {
|
|
140
|
-
case 'number':
|
|
183
|
+
case 'number': {
|
|
141
184
|
if (Number.isNaN(value) || value < 0) break;
|
|
142
185
|
if (Number.isInteger(value)) result = value.toString();
|
|
143
186
|
break;
|
|
144
|
-
|
|
187
|
+
}
|
|
188
|
+
case 'string': {
|
|
145
189
|
result = value.trim();
|
|
146
190
|
// // TODO: check if a valid character sequencies
|
|
147
191
|
break;
|
|
148
|
-
|
|
192
|
+
}
|
|
193
|
+
default: {
|
|
149
194
|
break;
|
|
195
|
+
}
|
|
150
196
|
};
|
|
151
197
|
return result;
|
|
152
198
|
};
|
|
@@ -160,6 +206,7 @@ function createNewHtmlElement(tagName, opt){
|
|
|
160
206
|
id,
|
|
161
207
|
text,
|
|
162
208
|
attr,
|
|
209
|
+
classNames,
|
|
163
210
|
class: _class,
|
|
164
211
|
data: dset,
|
|
165
212
|
} = opt;
|
|
@@ -185,6 +232,7 @@ function createNewHtmlElement(tagName, opt){
|
|
|
185
232
|
};
|
|
186
233
|
};
|
|
187
234
|
// set a class-attributes of the element
|
|
235
|
+
if (_class === undefined) _class = classNames;
|
|
188
236
|
if (_class !== undefined) {
|
|
189
237
|
const cl = valueToClassList(_class, true);
|
|
190
238
|
if (cl.length > 0) item.classList.add(...cl);
|
|
@@ -235,6 +283,8 @@ exports.markHtmlElementAsCurrent = markHtmlElementAsCurrent;
|
|
|
235
283
|
exports.unmarkCurrentHtmlElement = unmarkCurrentHtmlElement;
|
|
236
284
|
exports.markHtmlElementAsActive = markHtmlElementAsActive;
|
|
237
285
|
exports.unmarkActiveHtmlElement = unmarkActiveHtmlElement;
|
|
286
|
+
exports.lockHtmlElement = lockHtmlElement;
|
|
287
|
+
exports.unlockHtmlElement = unlockHtmlElement;
|
|
238
288
|
exports.activateHtmlElements = activateHtmlElements;
|
|
239
289
|
exports.inactivateHtmlElements = inactivateHtmlElements;
|
|
240
290
|
|
|
@@ -243,3 +293,4 @@ exports.valueToClassList = valueToClassList;
|
|
|
243
293
|
// experimental
|
|
244
294
|
exports.createNewHtmlElement = createNewHtmlElement;
|
|
245
295
|
exports.valueToIDString = valueToIDString;
|
|
296
|
+
exports.readAsAttrValue = readAsAttrValue;
|