@cntwg/html-ctrls-lists 0.0.31 → 0.0.33

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.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A description for list buttons set.
3
+ */
4
+ export type listButtonsSetDesc = {
5
+ /**
6
+ * - button 'move to first'
7
+ */
8
+ btnFirst: HTMLElement | null;
9
+ /**
10
+ * - button 'move to previous'
11
+ */
12
+ btnPrev: HTMLElement | null;
13
+ /**
14
+ * - button 'move to next'
15
+ */
16
+ btnNext: HTMLElement | null;
17
+ /**
18
+ * - button 'move to last'
19
+ */
20
+ btnLast: HTMLElement | null;
21
+ };
22
+ export const BTS_DEF_GROUP_NAME: "all";
23
+
24
+ /**
25
+ * This class implements an interface of a pre-defined
26
+ * buttons set that is used in pair with a list elements.
27
+ * A set provide a buttons: <next>, <previous>, <first> and <last>.
28
+ */
29
+ export class THtmlListButtonsController {
30
+ /**
31
+ * Creates an instance of a buttons set.
32
+ */
33
+ constructor(opt?: listButtonsSetDesc);
34
+ /**
35
+ * Disables all buttons.
36
+ */
37
+ disableAll(): void;
38
+ /**
39
+ * Disables all buttons in 'move_bkwd' group.
40
+ */
41
+ disableBkwd(): void;
42
+ /**
43
+ * Disables all buttons in 'move_frwd' group.
44
+ */
45
+ disableFrwd(): void;
46
+ /**
47
+ * Enables all buttons.
48
+ */
49
+ enableAll(): void;
50
+ /**
51
+ * Enables all buttons in 'move_bkwd' group.
52
+ */
53
+ enableBkwd(): void;
54
+ /**
55
+ * Enables all buttons in 'move_frwd' group.
56
+ */
57
+ enableFrwd(): void;
58
+ /**
59
+ * Sets a callback function to handle event.
60
+ */
61
+ on(name: string, evnt: Function): void;
62
+ #private;
63
+ }
package/lib/lists-btn.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.061-20260309]
1
+ // [v0.1.063-20260505]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -18,7 +18,7 @@ const {
18
18
 
19
19
  const {
20
20
  readOnClickEventInfo,
21
- } = require('./mod-hfunc.js');
21
+ } = require('./mod-hfunc');
22
22
 
23
23
  // === module inner block ===
24
24
 
@@ -33,6 +33,7 @@ const {
33
33
  // === module main block ===
34
34
 
35
35
  const BTS_DEF_GROUP_NAME = 'all';
36
+ module.exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
36
37
 
37
38
  /**
38
39
  * A description for list buttons set.
@@ -103,10 +104,9 @@ class THtmlListButtonsController {
103
104
  }
104
105
 
105
106
  /**
106
- * @param {Event} e - event
107
+ * @param {UIEvent} e - event
107
108
  * @param {string} key - button ID
108
109
  * @returns {void}
109
- * @private
110
110
  */
111
111
  #_on_btn_pressed = (e, key) => {
112
112
  //console.log(`THtmlListButtonsController._on_btn_pressed().key(${key}) ==> was called...`);
@@ -125,7 +125,6 @@ class THtmlListButtonsController {
125
125
  * @param {string} name - event name
126
126
  * @param {...any} args
127
127
  * @returns {void}
128
- * @private
129
128
  * @see triggerEventHandler
130
129
  */
131
130
  #_triggerEvent = (name, ...args) => {
@@ -194,8 +193,4 @@ class THtmlListButtonsController {
194
193
  pushEventHandler(this.#_events, name, evnt);
195
194
  }
196
195
  };
197
- exports.THtmlListButtonsController = THtmlListButtonsController;
198
-
199
- // === module exports block ===
200
-
201
- exports.BTS_DEF_GROUP_NAME = BTS_DEF_GROUP_NAME;
196
+ module.exports.THtmlListButtonsController = THtmlListButtonsController;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * A set of options for a `THtmlStubItemsSet`-class constructor
3
+ */
4
+ export type IStubItemsSetOptions = {
5
+ /**
6
+ * - array of `name`-`element` pairs
7
+ */
8
+ items: pairOfNameAndElement[];
9
+ /**
10
+ * - a default element name
11
+ */
12
+ defaultItem?: string;
13
+ /**
14
+ * - run in a force mode
15
+ */
16
+ force?: boolean | undefined;
17
+ };
18
+ export const IStubItemsSetOptions: IStubItemsSetOptions;
19
+ /**
20
+ * A `name`-`element` pair
21
+ */
22
+ export type pairOfNameAndElement = [ name: string, item: HTMLElement ];
23
+ /**
24
+ * A settings to load a stub-elements.
25
+ */
26
+ export type OPT_ldstubs = {
27
+ /**
28
+ * - a default element name
29
+ * @deprecated
30
+ */
31
+ defaultItem?: string;
32
+ /**
33
+ * - to clear before load an elements
34
+ */
35
+ useClear?: boolean;
36
+ /**
37
+ * - run in a force mode
38
+ */
39
+ force?: boolean;
40
+ };
41
+ /**
42
+ * A stub-elements list descriptor
43
+ */
44
+ export type IStubEListDesc = {
45
+ /**
46
+ * - array of `name`-`element` pairs
47
+ */
48
+ items: pairOfNameAndElement[];
49
+ /**
50
+ * - a default element name
51
+ */
52
+ defaultItem?: string;
53
+ };
54
+
55
+ /**
56
+ * This class implements an interface of a stub-items set
57
+ */
58
+ export class THtmlStubItemsSet {
59
+ /**
60
+ * Creates an instance of a stub-items set
61
+ * @todo [since v0.0.26] use of an `array`-type as a value of an `opt` is deprecated
62
+ */
63
+ constructor(host: HTMLElement, opt?: pairOfNameAndElement[] | IStubEListDesc | IStubItemsSetOptions);
64
+ /**
65
+ * Defines a default element name
66
+ * @type {string}
67
+ */
68
+ set defItem(name: string);
69
+ get defItem(): string;
70
+ /**
71
+ * Contains a Qty of an elements
72
+ * @type {number}
73
+ */
74
+ get count(): number;
75
+ /**
76
+ * Clears an instance content.
77
+ * @todo check if any item is shown
78
+ */
79
+ clear(): void;
80
+ /**
81
+ * Sets a default item.
82
+ */
83
+ setDefItem(name: string): boolean;
84
+ /**
85
+ * Resets a default item.
86
+ * @todo check if item is shown
87
+ */
88
+ rstDefItem(): void;
89
+ /**
90
+ * Checks if an item exists.
91
+ */
92
+ hasItem(name: string): boolean;
93
+ /**
94
+ * Checks if any items exists.
95
+ */
96
+ hasItems(): boolean;
97
+ /**
98
+ * Returns an item by its name.
99
+ */
100
+ getItem(name: string): HTMLElement | null;
101
+ /**
102
+ * Adds an item to an instance members.
103
+ */
104
+ addItem(name: string, item: HTMLElement, opt?: boolean): boolean;
105
+ /**
106
+ * Deletes an item from an instance members.
107
+ * @todo check if item is shown
108
+ */
109
+ delItem(name: string): boolean;
110
+ /**
111
+ * Shows an item.
112
+ */
113
+ showItem(name: string): boolean;
114
+ /**
115
+ * Shows a default item.
116
+ */
117
+ showDefItem(): boolean;
118
+ /**
119
+ * Hides an item.
120
+ */
121
+ hideItem(name: string): boolean;
122
+ /**
123
+ * Hides a default item.
124
+ */
125
+ hideDefItem(): boolean;
126
+ /**
127
+ * Adds an items to an instance members.
128
+ * @todo [since 0.0.25] deprecate use of `opt` as `boolean`
129
+ * @todo [since v0.0.26] for `OPT_ldstubs` a `defaultItem`-option deprecated
130
+ * @todo [since 0.0.32] deprecate use of `data` as `array`
131
+ */
132
+ loadItems(data: pairOfNameAndElement[] | IStubEListDesc, opt?: boolean | OPT_ldstubs): number;
133
+ #private;
134
+ }
@@ -1,4 +1,4 @@
1
- // [v0.1.053-20260309]
1
+ // [v0.1.058-20260510]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -14,6 +14,11 @@ const {
14
14
 
15
15
  // === module main block ===
16
16
 
17
+ /**
18
+ * A `name`-`element` pair
19
+ * @typedef {any[]} pairOfNameAndElement
20
+ */
21
+
17
22
  /**
18
23
  * A settings to load a stub-elements.
19
24
  * @typedef {Object} OPT_ldstubs
@@ -24,19 +29,24 @@ const {
24
29
  */
25
30
 
26
31
  /**
27
- * A stub-elements description list.
28
- * @typedef {Object} OBJ_stubEList
29
- * @property {Array} items - array of `name`-`element` pairs
32
+ * A stub-elements list descriptor
33
+ * @typedef {Object} IStubEListDesc
34
+ * @property {pairOfNameAndElement[]} items - array of `name`-`element` pairs
30
35
  * @property {string} [defaultItem] - a default element name
31
36
  */
32
37
 
33
38
  /**
34
- * A an options set for a `THtmlStubItemsSet`-class constructor
35
- * @typedef {Object} OPT_stubconsett
36
- * @property {(any[])} items - array of `name`-`element` pairs
39
+ * A set of options for a `THtmlStubItemsSet`-class constructor
40
+ * @typedef {Object} IStubItemsSetOptions
41
+ * @property {pairOfNameAndElement[]} items - array of `name`-`element` pairs
37
42
  * @property {string} [defaultItem] - a default element name
38
43
  * @property {boolean} [force=false] - run in a force mode
39
44
  */
45
+ /**
46
+ * A virtual constant meant for support jsdoc notation:
47
+ * @type {IStubItemsSetOptions}
48
+ */
49
+ module.exports.IStubItemsSetOptions = { items: [] };
40
50
 
41
51
  /**
42
52
  * @classdesc This class implements an interface of a stub-items set
@@ -53,7 +63,7 @@ class THtmlStubItemsSet {
53
63
  /**
54
64
  * Creates an instance of a stub-items set
55
65
  * @param {HTMLElement} host - host element
56
- * @param {(any[]|OPT_stubconsett|OBJ_stubEList)} [opt] - options
66
+ * @param {pairOfNameAndElement[]|IStubEListDesc|IStubItemsSetOptions} [opt] - options
57
67
  * @todo [since v0.0.26] use of an `array`-type as a value of an `opt` is deprecated
58
68
  */
59
69
  constructor(host, opt) {
@@ -62,7 +72,7 @@ class THtmlStubItemsSet {
62
72
  this.#_defItem = '';
63
73
  this.#_shownItem = null;
64
74
  if (isObject(opt)) {
65
- /** @type {(OPT_stubconsett|OBJ_stubEList)} */
75
+ /** @type {IStubItemsSetOptions} */
66
76
  const obj = isArray(opt) ? { items: opt } : opt;
67
77
  const { items, defaultItem, force } = obj;
68
78
  this.loadItems({
@@ -205,9 +215,12 @@ class THtmlStubItemsSet {
205
215
  */
206
216
  showItem(name) {
207
217
  const item = this.getItem(name);
208
- const isSUCCEED = this.#_host && item ? true : false;
209
- if (isSUCCEED) this.#_host.append(item);
210
- return isSUCCEED;
218
+ let isSucceed = false;
219
+ if (this.#_host && item) {
220
+ this.#_host.append(item);
221
+ isSucceed = true;
222
+ };
223
+ return isSucceed;
211
224
  }
212
225
 
213
226
  /**
@@ -225,9 +238,12 @@ class THtmlStubItemsSet {
225
238
  */
226
239
  hideItem(name) {
227
240
  const item = this.getItem(name);
228
- const isSUCCEED = this.#_host && item ? true : false;
229
- if (isSUCCEED && this.#_host.contains(item)) item.remove();
230
- return isSUCCEED;
241
+ let isSucceed = false;
242
+ if (this.#_host && item && this.#_host.contains(item)) {
243
+ isSucceed = true;
244
+ item.remove();
245
+ };
246
+ return isSucceed;
231
247
  }
232
248
 
233
249
  /**
@@ -240,14 +256,15 @@ class THtmlStubItemsSet {
240
256
 
241
257
  /**
242
258
  * Adds an items to an instance members.
243
- * @param {(Array|OBJ_stubEList)} data - an array of entries or special object
244
- * @param {(boolean|OPT_ldstubs)} [opt] - an options
259
+ * @param {pairOfNameAndElement[]|IStubEListDesc} data - an array of entries or special object
260
+ * @param {boolean|OPT_ldstubs} [opt] - an options
245
261
  * @returns {number}
246
262
  * @todo [since 0.0.25] deprecate use of `opt` as `boolean`
247
263
  * @todo [since v0.0.26] for `OPT_ldstubs` a `defaultItem`-option deprecated
264
+ * @todo [since 0.0.32] deprecate use of `data` as `array`
248
265
  */
249
266
  loadItems(data, opt) {
250
- /** @type {OBJ_stubEList} */
267
+ /** @type {IStubEListDesc} */
251
268
  let {
252
269
  items,
253
270
  defaultItem,
@@ -261,7 +278,6 @@ class THtmlStubItemsSet {
261
278
  if (typeof useClear !== 'boolean') useClear = true;
262
279
  if (typeof force !== 'boolean') force = false;
263
280
  if (defaultItem === undefined) defaultItem = _options.defaultItem; /* deprecated */
264
- const setDefs = defaultItem !== undefined;
265
281
  let count = 0;
266
282
  if (isArray(items)) {
267
283
  if (useClear) this.clear();
@@ -275,9 +291,9 @@ class THtmlStubItemsSet {
275
291
  };
276
292
  });
277
293
  };
278
- if (setDefs && count > 0) this.setDefItem(defaultItem);
294
+ if (defaultItem && count > 0) this.setDefItem(defaultItem);
279
295
  return count;
280
296
  }
281
297
 
282
298
  };
283
- exports.THtmlStubItemsSet = THtmlStubItemsSet;
299
+ module.exports.THtmlStubItemsSet = THtmlStubItemsSet;
@@ -0,0 +1,18 @@
1
+ export type IClickEventInfo = {
2
+ /**
3
+ * - some target element
4
+ */
5
+ item: object | null;
6
+ /**
7
+ * - reflects a current click count
8
+ */
9
+ onClickNum: number;
10
+ };
11
+
12
+ /**
13
+ * @function readOnClickEventInfo
14
+ * @param {UIEvent} e - event
15
+ * @returns {IClickEventInfo}
16
+ * @inner
17
+ */
18
+ export function readOnClickEventInfo(e: UIEvent): IClickEventInfo;
package/lib/mod-hfunc.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.067-20260417]
1
+ // [v0.1.068-20260422]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -6,10 +6,18 @@
6
6
 
7
7
  // === module main block ===
8
8
 
9
+ /**
10
+ *
11
+ * @typedef {Object} IClickEventInfo
12
+ * @property {?object} item - some target element
13
+ * @property {number} onClickNum - reflects a current click count
14
+ * @inner
15
+ */
16
+
9
17
  /**
10
18
  * @function readOnClickEventInfo
11
- * @param {Event} e
12
- * @returns {object}
19
+ * @param {UIEvent} e - event
20
+ * @returns {IClickEventInfo}
13
21
  * @inner
14
22
  */
15
23
  function readOnClickEventInfo(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-ctrls-lists",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "An HTML-form component: lists",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -14,35 +14,41 @@
14
14
  "component"
15
15
  ],
16
16
  "main": "./index.js",
17
+ "types": "./index.d.ts",
17
18
  "files": [
18
19
  "doc/*.md",
20
+ "lib/list-cont.js",
21
+ "lib/list-ctrl.js",
19
22
  "lib/lists-stubs.js",
20
23
  "lib/lists-btn.js",
21
- "lib/list.js",
22
24
  "lib/mod-hfunc.js",
25
+ "lib/*.d.ts",
23
26
  "index.js",
27
+ "index.d.ts",
24
28
  "CHANGELOG.md"
25
29
  ],
26
30
  "scripts": {
27
31
  "test": "jest",
28
32
  "build-doc-md": "jsdoc2md",
29
- "build-doc-html": "jsdoc"
33
+ "build-doc-html": "jsdoc",
34
+ "gen-dts": "npx -p typescript tsc"
30
35
  },
31
36
  "imports": {
32
37
  "#lib/*": "./lib/*",
33
38
  "#test-dir/*": "./__test__/*"
34
39
  },
35
40
  "dependencies": {
36
- "@cntwg/html-ctrls-buttons": "~0.1.0",
41
+ "@cntwg/html-ctrls-buttons": "~0.1.1",
37
42
  "@cntwg/html-helper": "~0.1.3",
38
43
  "@ygracs/bsfoc-lib-js": "~0.3.4",
39
- "@ygracs/lists-lib-js": "~0.2.0"
44
+ "@ygracs/lists-lib-js": "~0.2.1"
40
45
  },
41
46
  "devDependencies": {
42
47
  "@ygracs/test-helper": "~0.0.2-b",
43
48
  "jest": "^30.3.0",
44
49
  "jest-environment-jsdom": "^30.3.0",
45
50
  "jsdoc-to-markdown": "^9.1.3",
46
- "minimist": "^1.2.8"
51
+ "minimist": "^1.2.8",
52
+ "typescript": "~5.9.3"
47
53
  }
48
54
  }