aprog 2.1.6 → 2.1.8
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/index.js +1 -0
- package/package.json +1 -1
- package/src/classes/AprogClass.js +23 -0
- package/src/html.js +13 -0
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class AprogClass {
|
|
2
|
+
#states = [];
|
|
3
|
+
#cursor = 0;
|
|
4
|
+
|
|
5
|
+
useState(initialValue) {
|
|
6
|
+
const index = this.#cursor;
|
|
7
|
+
|
|
8
|
+
if (this.#states[index] === undefined) {
|
|
9
|
+
this.#states[index] = initialValue;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const setState = (newValue) => {
|
|
13
|
+
const current = this.#states[index];
|
|
14
|
+
this.#states[index] = typeof newValue === "function" ? newValue(current) : newValue;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const value = this.#states[index];
|
|
18
|
+
this.#cursor++;
|
|
19
|
+
return [value, setState];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default AprogClass;
|
package/src/html.js
CHANGED
|
@@ -68,6 +68,18 @@ export function repeatHTMLElementPrototype() {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export function replaceChildrenHTMLElementPrototype() {
|
|
72
|
+
if (!HTMLElement.prototype.replaceChildren) {
|
|
73
|
+
HTMLElement.prototype.replaceChildren = function (newElement) {
|
|
74
|
+
if (!(newElement instanceof HTMLElement)) {
|
|
75
|
+
throw new Error('Argument must be an HTMLElement');
|
|
76
|
+
}
|
|
77
|
+
this.innerHTML = null;
|
|
78
|
+
this.appendChild(HTMLElement);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
71
83
|
pushHTMLElementPrototype();
|
|
72
84
|
pushAfterHTMLElementPrototype();
|
|
73
85
|
pushBeforeHTMLElementPrototype();
|
|
@@ -75,3 +87,4 @@ dataHTMLElementPrototype();
|
|
|
75
87
|
toKebabCaseStringPrototype();
|
|
76
88
|
toSnakeCaseStringPrototype();
|
|
77
89
|
repeatHTMLElementPrototype();
|
|
90
|
+
replaceChildrenHTMLElementPrototype();
|