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