@cntwg/html-ctrls-lists 0.0.30 → 0.0.32
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 +22 -0
- package/doc/html-ctrls-list.md +180 -127
- package/index.d.ts +19 -0
- package/lib/list.d.ts +278 -0
- package/lib/list.js +133 -78
- package/lib/lists-btn.d.ts +63 -0
- package/lib/lists-btn.js +5 -10
- package/lib/lists-stubs.d.ts +134 -0
- package/lib/lists-stubs.js +36 -19
- package/lib/mod-hfunc.d.ts +18 -0
- package/lib/mod-hfunc.js +9 -30
- package/package.json +13 -8
|
@@ -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
|
+
}
|
package/lib/lists-stubs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.057-20260505]
|
|
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
|
|
28
|
-
* @typedef {Object}
|
|
29
|
-
* @property {
|
|
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
|
|
35
|
-
* @typedef {Object}
|
|
36
|
-
* @property {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
209
|
-
if (
|
|
210
|
-
|
|
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
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
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 {
|
|
244
|
-
* @param {
|
|
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 {
|
|
267
|
+
/** @type {IStubEListDesc} */
|
|
251
268
|
let {
|
|
252
269
|
items,
|
|
253
270
|
defaultItem,
|
|
@@ -280,4 +297,4 @@ class THtmlStubItemsSet {
|
|
|
280
297
|
}
|
|
281
298
|
|
|
282
299
|
};
|
|
283
|
-
exports.THtmlStubItemsSet = THtmlStubItemsSet;
|
|
300
|
+
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,32 +1,23 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.068-20260422]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
eventHelper, // [!] not oficialy exported yet
|
|
7
|
-
} = require('@cntwg/html-helper');
|
|
8
|
-
|
|
9
5
|
// === module inner block ===
|
|
10
6
|
|
|
11
|
-
const {
|
|
12
|
-
pushEventHandler, removeEventHandler,
|
|
13
|
-
triggerEventHandler,
|
|
14
|
-
} = eventHelper;
|
|
15
|
-
|
|
16
7
|
// === module main block ===
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @typedef {Object} IClickEventInfo
|
|
12
|
+
* @property {?object} item - some target element
|
|
13
|
+
* @property {number} onClickNum - reflects a current click count
|
|
14
|
+
* @inner
|
|
24
15
|
*/
|
|
25
16
|
|
|
26
17
|
/**
|
|
27
18
|
* @function readOnClickEventInfo
|
|
28
|
-
* @param {
|
|
29
|
-
* @returns {
|
|
19
|
+
* @param {UIEvent} e - event
|
|
20
|
+
* @returns {IClickEventInfo}
|
|
30
21
|
* @inner
|
|
31
22
|
*/
|
|
32
23
|
function readOnClickEventInfo(e) {
|
|
@@ -51,16 +42,4 @@ function readOnClickEventInfo(e) {
|
|
|
51
42
|
};
|
|
52
43
|
return { item, onClickNum };
|
|
53
44
|
};
|
|
54
|
-
|
|
55
|
-
/***
|
|
56
|
-
* (* class definitions *)
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
// === module exports block ===
|
|
60
|
-
|
|
61
45
|
module.exports.readOnClickEventInfo = readOnClickEventInfo;
|
|
62
|
-
|
|
63
|
-
// * re-exported *
|
|
64
|
-
module.exports.pushEventHandler = pushEventHandler;
|
|
65
|
-
module.exports.removeEventHandler = removeEventHandler;
|
|
66
|
-
module.exports.triggerEventHandler = triggerEventHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntwg/html-ctrls-lists",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "An HTML-form component: lists",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,35 +14,40 @@
|
|
|
14
14
|
"component"
|
|
15
15
|
],
|
|
16
16
|
"main": "./index.js",
|
|
17
|
+
"types": "./index.d.ts",
|
|
17
18
|
"files": [
|
|
18
19
|
"doc/*.md",
|
|
19
20
|
"lib/lists-stubs.js",
|
|
20
21
|
"lib/lists-btn.js",
|
|
21
22
|
"lib/list.js",
|
|
22
23
|
"lib/mod-hfunc.js",
|
|
24
|
+
"lib/*.d.ts",
|
|
23
25
|
"index.js",
|
|
26
|
+
"index.d.ts",
|
|
24
27
|
"CHANGELOG.md"
|
|
25
28
|
],
|
|
26
29
|
"scripts": {
|
|
27
30
|
"test": "jest",
|
|
28
31
|
"build-doc-md": "jsdoc2md",
|
|
29
|
-
"build-doc-html": "jsdoc"
|
|
32
|
+
"build-doc-html": "jsdoc",
|
|
33
|
+
"gen-dts": "npx -p typescript tsc"
|
|
30
34
|
},
|
|
31
35
|
"imports": {
|
|
32
36
|
"#lib/*": "./lib/*",
|
|
33
37
|
"#test-dir/*": "./__test__/*"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@cntwg/html-ctrls-buttons": "~0.
|
|
37
|
-
"@cntwg/html-helper": "~0.1.
|
|
40
|
+
"@cntwg/html-ctrls-buttons": "~0.1.1",
|
|
41
|
+
"@cntwg/html-helper": "~0.1.3",
|
|
38
42
|
"@ygracs/bsfoc-lib-js": "~0.3.4",
|
|
39
|
-
"@ygracs/lists-lib-js": "~0.1
|
|
43
|
+
"@ygracs/lists-lib-js": "~0.2.1"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
46
|
"@ygracs/test-helper": "~0.0.2-b",
|
|
43
|
-
"jest": "^30.
|
|
44
|
-
"jest-environment-jsdom": "^30.
|
|
47
|
+
"jest": "^30.3.0",
|
|
48
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
45
49
|
"jsdoc-to-markdown": "^9.1.3",
|
|
46
|
-
"minimist": "^1.2.8"
|
|
50
|
+
"minimist": "^1.2.8",
|
|
51
|
+
"typescript": "~5.9.3"
|
|
47
52
|
}
|
|
48
53
|
}
|