@htmltools/hdom 0.1.0 → 0.1.1
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 +10 -8
- package/lib/hdom.js +18 -13
- package/package.json +1 -1
package/lib/hdom.d.ts
CHANGED
|
@@ -23,28 +23,30 @@ export class hdom {
|
|
|
23
23
|
static createCheckBox(id: string, checked: boolean): HTMLInputElement;
|
|
24
24
|
/**
|
|
25
25
|
* @param {string} name
|
|
26
|
-
* @param {Object<string,string|number>|string} [attributes]
|
|
26
|
+
* @param {Object<string,string|number|undefined>|string} [attributes]
|
|
27
|
+
* @param {Element} [parent]
|
|
27
28
|
* @returns {HTMLElement}
|
|
28
29
|
*/
|
|
29
30
|
static createElement(name: string, attributes?: {
|
|
30
|
-
[x: string]: string | number;
|
|
31
|
-
} | string): HTMLElement;
|
|
31
|
+
[x: string]: string | number | undefined;
|
|
32
|
+
} | string, parent?: Element): HTMLElement;
|
|
32
33
|
/**
|
|
33
|
-
* @param {Object.<string,string|number>|string} attributes
|
|
34
|
+
* @param {Object.<string,string|number|undefined>|string} attributes
|
|
34
35
|
* @returns {HTMLInputElement}
|
|
35
36
|
*/
|
|
36
37
|
static createInputElement(attributes: {
|
|
37
|
-
[x: string]: string | number;
|
|
38
|
+
[x: string]: string | number | undefined;
|
|
38
39
|
} | string): HTMLInputElement;
|
|
39
40
|
/**
|
|
40
41
|
* @param {string} name
|
|
41
|
-
* @param {Object<string,string
|
|
42
|
+
* @param {Object<string,string>|string} attributes
|
|
42
43
|
* @param {string|number} text
|
|
43
|
-
* @
|
|
44
|
+
* @param {Element} [parent]
|
|
45
|
+
* @returns {HTMLElement}
|
|
44
46
|
*/
|
|
45
47
|
static createTextElement(name: string, attributes: {
|
|
46
48
|
[x: string]: string;
|
|
47
|
-
}, text: string | number):
|
|
49
|
+
} | string, text: string | number, parent?: Element): HTMLElement;
|
|
48
50
|
/**
|
|
49
51
|
* @param {string|HTMLElement} e
|
|
50
52
|
* @param {boolean} [enable=true]
|
package/lib/hdom.js
CHANGED
|
@@ -50,10 +50,11 @@ export class hdom {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @param {string} name
|
|
53
|
-
* @param {Object<string,string|number>|string} [attributes]
|
|
53
|
+
* @param {Object<string,string|number|undefined>|string} [attributes]
|
|
54
|
+
* @param {Element} [parent]
|
|
54
55
|
* @returns {HTMLElement}
|
|
55
56
|
*/
|
|
56
|
-
static createElement(name, attributes) {
|
|
57
|
+
static createElement(name, attributes, parent) {
|
|
57
58
|
const e = document.createElement(name);
|
|
58
59
|
switch (typeof attributes) {
|
|
59
60
|
case "string":
|
|
@@ -62,33 +63,37 @@ export class hdom {
|
|
|
62
63
|
break;
|
|
63
64
|
case "object":
|
|
64
65
|
for (const [k, v] of Object.entries(attributes)) {
|
|
65
|
-
|
|
66
|
+
if (v !== undefined) {
|
|
67
|
+
e.setAttribute(k, v.toString());
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
70
|
break;
|
|
68
71
|
}
|
|
72
|
+
if (parent) {
|
|
73
|
+
parent.appendChild(e);
|
|
74
|
+
}
|
|
69
75
|
return e;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/**
|
|
73
|
-
* @param {Object.<string,string|number>|string} attributes
|
|
79
|
+
* @param {Object.<string,string|number|undefined>|string} attributes
|
|
74
80
|
* @returns {HTMLInputElement}
|
|
75
81
|
*/
|
|
76
82
|
static createInputElement(attributes) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return e;
|
|
83
|
+
return /** @type {HTMLInputElement} */ (
|
|
84
|
+
this.createElement("input", attributes)
|
|
85
|
+
);
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
/**
|
|
85
89
|
* @param {string} name
|
|
86
|
-
* @param {Object<string,string
|
|
90
|
+
* @param {Object<string,string>|string} attributes
|
|
87
91
|
* @param {string|number} text
|
|
88
|
-
* @
|
|
92
|
+
* @param {Element} [parent]
|
|
93
|
+
* @returns {HTMLElement}
|
|
89
94
|
*/
|
|
90
|
-
static createTextElement(name, attributes, text) {
|
|
91
|
-
const elem = this.createElement(name, attributes);
|
|
95
|
+
static createTextElement(name, attributes, text, parent) {
|
|
96
|
+
const elem = this.createElement(name, attributes, parent);
|
|
92
97
|
this.setTextValue(elem, text.toString());
|
|
93
98
|
return elem;
|
|
94
99
|
}
|