@htmltools/hdom 0.1.1 → 0.1.4
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/lib/hdom.d.ts +49 -0
- package/lib/hdom.js +94 -1
- package/package.json +1 -1
package/lib/hdom.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export class hdom {
|
|
|
11
11
|
* @returns {Element}
|
|
12
12
|
*/
|
|
13
13
|
static addEventListener(e: string | Element, type: string, fn: (arg0: Event) => void): Element;
|
|
14
|
+
/**
|
|
15
|
+
* @param {string|HTMLElement} e
|
|
16
|
+
*/
|
|
17
|
+
static clickElement(e: string | HTMLElement): void;
|
|
14
18
|
/**
|
|
15
19
|
* @param {string|HTMLDialogElement} e
|
|
16
20
|
*/
|
|
@@ -37,6 +41,46 @@ export class hdom {
|
|
|
37
41
|
static createInputElement(attributes: {
|
|
38
42
|
[x: string]: string | number | undefined;
|
|
39
43
|
} | string): HTMLInputElement;
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} forId
|
|
46
|
+
* @param {string} text
|
|
47
|
+
* @param {Object<string,string>} [extraAtts]
|
|
48
|
+
* @returns {HTMLElement}
|
|
49
|
+
*/
|
|
50
|
+
static createLabelElement(forId: string, text: string, extraAtts?: {
|
|
51
|
+
[x: string]: string;
|
|
52
|
+
}): HTMLElement;
|
|
53
|
+
/**
|
|
54
|
+
* @param {URL|string|undefined} url
|
|
55
|
+
* @param {Node|string|number} eLinkText
|
|
56
|
+
* @param {Object.<string,string>|string} [attributes]
|
|
57
|
+
* @returns {HTMLElement}
|
|
58
|
+
*/
|
|
59
|
+
static createLinkElement(url: URL | string | undefined, eLinkText: Node | string | number, attributes?: {
|
|
60
|
+
[x: string]: string;
|
|
61
|
+
} | string): HTMLElement;
|
|
62
|
+
/**
|
|
63
|
+
* @param {string} id
|
|
64
|
+
* @param {{value?:string,label?:string}[]} options
|
|
65
|
+
* @returns {HTMLElement}
|
|
66
|
+
*/
|
|
67
|
+
static createSelectElement(id: string, options: {
|
|
68
|
+
value?: string;
|
|
69
|
+
label?: string;
|
|
70
|
+
}[]): HTMLElement;
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} id
|
|
73
|
+
* @param {string} label
|
|
74
|
+
* @param {{value?:string,label?:string}[]} options
|
|
75
|
+
* @returns {{label:HTMLElement,select:HTMLElement}}
|
|
76
|
+
*/
|
|
77
|
+
static createSelectElementWithLabel(id: string, label: string, options: {
|
|
78
|
+
value?: string;
|
|
79
|
+
label?: string;
|
|
80
|
+
}[]): {
|
|
81
|
+
label: HTMLElement;
|
|
82
|
+
select: HTMLElement;
|
|
83
|
+
};
|
|
40
84
|
/**
|
|
41
85
|
* @param {string} name
|
|
42
86
|
* @param {Object<string,string>|string} attributes
|
|
@@ -104,6 +148,11 @@ export class hdom {
|
|
|
104
148
|
* @param {string} value
|
|
105
149
|
*/
|
|
106
150
|
static setAttribute(e: string | HTMLElement, attName: string, value: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* @param {string|HTMLElement} e
|
|
153
|
+
* @param {boolean} state
|
|
154
|
+
*/
|
|
155
|
+
static setCheckBoxState(e: string | HTMLElement, state: boolean): void;
|
|
107
156
|
/**
|
|
108
157
|
* @param {string|Element} e
|
|
109
158
|
* @param {string|number} text
|
package/lib/hdom.js
CHANGED
|
@@ -22,6 +22,17 @@ export class hdom {
|
|
|
22
22
|
return elem;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @param {string|HTMLElement} e
|
|
27
|
+
*/
|
|
28
|
+
static clickElement(e) {
|
|
29
|
+
const elem = this.getElement(e);
|
|
30
|
+
if (!(elem instanceof HTMLInputElement)) {
|
|
31
|
+
throw new Error();
|
|
32
|
+
}
|
|
33
|
+
elem.click();
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
/**
|
|
26
37
|
* @param {string|HTMLDialogElement} e
|
|
27
38
|
*/
|
|
@@ -85,6 +96,76 @@ export class hdom {
|
|
|
85
96
|
);
|
|
86
97
|
}
|
|
87
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @param {string} forId
|
|
101
|
+
* @param {string} text
|
|
102
|
+
* @param {Object<string,string>} [extraAtts]
|
|
103
|
+
* @returns {HTMLElement}
|
|
104
|
+
*/
|
|
105
|
+
static createLabelElement(forId, text, extraAtts = {}) {
|
|
106
|
+
const attributes = { for: forId, ...extraAtts };
|
|
107
|
+
const el = this.createElement("label", attributes);
|
|
108
|
+
this.setTextValue(el, text);
|
|
109
|
+
return el;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {URL|string|undefined} url
|
|
114
|
+
* @param {Node|string|number} eLinkText
|
|
115
|
+
* @param {Object.<string,string>|string} [attributes]
|
|
116
|
+
* @returns {HTMLElement}
|
|
117
|
+
*/
|
|
118
|
+
static createLinkElement(url, eLinkText, attributes) {
|
|
119
|
+
const eLink = this.createElement("a", attributes);
|
|
120
|
+
if (url !== undefined) {
|
|
121
|
+
eLink.setAttribute("href", url.toString());
|
|
122
|
+
}
|
|
123
|
+
eLink.appendChild(
|
|
124
|
+
eLinkText instanceof Node
|
|
125
|
+
? eLinkText
|
|
126
|
+
: document.createTextNode(eLinkText.toString()),
|
|
127
|
+
);
|
|
128
|
+
return eLink;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {string} id
|
|
133
|
+
* @param {{value?:string,label?:string}[]} options
|
|
134
|
+
* @returns {HTMLElement}
|
|
135
|
+
*/
|
|
136
|
+
static createSelectElement(id, options) {
|
|
137
|
+
const select = this.createElement("select", { id: id });
|
|
138
|
+
for (const option of options) {
|
|
139
|
+
const optionEl = this.createElement(
|
|
140
|
+
"option",
|
|
141
|
+
option.value
|
|
142
|
+
? {
|
|
143
|
+
value: option.value,
|
|
144
|
+
}
|
|
145
|
+
: {},
|
|
146
|
+
);
|
|
147
|
+
if (option.label) {
|
|
148
|
+
this.setTextValue(optionEl, option.label);
|
|
149
|
+
}
|
|
150
|
+
select.appendChild(optionEl);
|
|
151
|
+
}
|
|
152
|
+
return select;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param {string} id
|
|
157
|
+
* @param {string} label
|
|
158
|
+
* @param {{value?:string,label?:string}[]} options
|
|
159
|
+
* @returns {{label:HTMLElement,select:HTMLElement}}
|
|
160
|
+
*/
|
|
161
|
+
static createSelectElementWithLabel(id, label, options) {
|
|
162
|
+
const labelEl = this.createLabelElement(id, label);
|
|
163
|
+
return {
|
|
164
|
+
label: labelEl,
|
|
165
|
+
select: this.createSelectElement(id, options),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
88
169
|
/**
|
|
89
170
|
* @param {string} name
|
|
90
171
|
* @param {Object<string,string>|string} attributes
|
|
@@ -194,7 +275,7 @@ export class hdom {
|
|
|
194
275
|
*/
|
|
195
276
|
static isHidden(e) {
|
|
196
277
|
const elem = this.getElement(e);
|
|
197
|
-
return elem
|
|
278
|
+
return elem.hidden === true;
|
|
198
279
|
}
|
|
199
280
|
|
|
200
281
|
/**
|
|
@@ -240,6 +321,18 @@ export class hdom {
|
|
|
240
321
|
elem.setAttribute(attName, value);
|
|
241
322
|
}
|
|
242
323
|
|
|
324
|
+
/**
|
|
325
|
+
* @param {string|HTMLElement} e
|
|
326
|
+
* @param {boolean} state
|
|
327
|
+
*/
|
|
328
|
+
static setCheckBoxState(e, state) {
|
|
329
|
+
const elem = this.getElement(e);
|
|
330
|
+
if (!(elem instanceof HTMLInputElement)) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
elem.checked = state;
|
|
334
|
+
}
|
|
335
|
+
|
|
243
336
|
/**
|
|
244
337
|
* @param {string|Element} e
|
|
245
338
|
* @param {string|number} text
|