aprog 2.2.0 → 2.2.2
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 +2 -1
- package/package.json +1 -1
- package/src/classes/SmartWrapper.js +2 -0
- package/src/classes/StateWrapper.js +57 -0
- package/src/constructs/ButtonConstructor.js +1 -1
- package/src/constructs/InputConstructor.js +1 -1
- package/src/constructs/SelectConstructor.js +45 -0
- package/src/helper.js +6 -0
- package/src/classes/AprogClass.js +0 -23
package/index.js
CHANGED
|
@@ -22,5 +22,6 @@ export {
|
|
|
22
22
|
} from './src/html.js';
|
|
23
23
|
export { prism } from "./src/prism.js";
|
|
24
24
|
export { uniquePage } from "./src/pages.js";
|
|
25
|
-
export {
|
|
25
|
+
export { state, wrap } from "./src/helper.js";
|
|
26
|
+
export { default as StateWrapper } from './src/classes/StateWrapper.js';
|
|
26
27
|
export { default as SmartWrapper } from './src/classes/SmartWrapper.js';
|
package/package.json
CHANGED
|
@@ -150,6 +150,8 @@ class SmartWrapper {
|
|
|
150
150
|
if (typeof this._value === 'number' || typeof this._value === 'boolean') {
|
|
151
151
|
return String(this._value);
|
|
152
152
|
}
|
|
153
|
+
if (Array.isArray(this._value)) return JSON.stringify(this._value);
|
|
154
|
+
if (typeof this._value === 'object' && this._value !== null) return JSON.stringify(Object.values(this._value));
|
|
153
155
|
return '';
|
|
154
156
|
}
|
|
155
157
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
class StateWrapper {
|
|
2
|
+
#value;
|
|
3
|
+
|
|
4
|
+
constructor(initialValue) {
|
|
5
|
+
this.#value = initialValue;
|
|
6
|
+
|
|
7
|
+
const handler = {
|
|
8
|
+
get: (target, prop, receiver) => {
|
|
9
|
+
if (prop === 'val') return target.#value;
|
|
10
|
+
|
|
11
|
+
if (prop === 'set') {
|
|
12
|
+
return (newValue) => {
|
|
13
|
+
target.#value = typeof newValue === 'function' ? newValue(target.#value) : newValue;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (prop === 'merge') {
|
|
18
|
+
return (patch) => {
|
|
19
|
+
if (typeof target.#value === 'object' && target.#value !== null) {
|
|
20
|
+
target.#value = { ...target.#value, ...patch };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (prop === 'toJSON') return () => target.#value;
|
|
26
|
+
if (prop === 'toString') return () => String(target.#value);
|
|
27
|
+
if (prop === 'valueOf') return () => target.#value;
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
typeof target.#value === 'object' &&
|
|
31
|
+
target.#value !== null &&
|
|
32
|
+
prop in target.#value
|
|
33
|
+
) {
|
|
34
|
+
return target.#value[prop];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return Reflect.get(target, prop, receiver);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
set: (target, prop, newVal) => {
|
|
41
|
+
if (typeof target.#value === 'object' && target.#value !== null) {
|
|
42
|
+
target.#value[prop] = newVal;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return new Proxy(this, handler);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
valueOf() {
|
|
53
|
+
return this.#value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default StateWrapper;
|
|
@@ -28,7 +28,7 @@ export const ButtonConstructor = {
|
|
|
28
28
|
} = {}) {
|
|
29
29
|
return this.is = button({
|
|
30
30
|
id: id || GUID(),
|
|
31
|
-
class: `${this.class} btn ${className} disabled
|
|
31
|
+
class: `${this.class} btn ${className} disabled`.trim(),
|
|
32
32
|
style: style,
|
|
33
33
|
...(type && {type: type}),
|
|
34
34
|
value: text,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {GUID, select} from "aprog";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AprogJS Constructor
|
|
5
|
+
* --- SelectConstructor ---
|
|
6
|
+
* Copyright (c) 2025 AlexProger.
|
|
7
|
+
*/
|
|
8
|
+
export const SelectConstructor = {
|
|
9
|
+
/**
|
|
10
|
+
* create HTMLElement
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
const instance = Object.create(this);
|
|
14
|
+
instance.class = GUID();
|
|
15
|
+
return instance;
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* set HTMLElement
|
|
20
|
+
*/
|
|
21
|
+
element({
|
|
22
|
+
id = undefined,
|
|
23
|
+
className = "",
|
|
24
|
+
style = {},
|
|
25
|
+
option = undefined,
|
|
26
|
+
options = undefined,
|
|
27
|
+
callback = () => {},
|
|
28
|
+
} = {}) {
|
|
29
|
+
return this.is = select({
|
|
30
|
+
id: id || GUID(),
|
|
31
|
+
class: `${this.class} input ${className}`.trim(),
|
|
32
|
+
style: style,
|
|
33
|
+
...(option && {option: option}),
|
|
34
|
+
...(options && {options: options}),
|
|
35
|
+
onChange: callback,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* get target [HTMLElement]
|
|
41
|
+
*/
|
|
42
|
+
get target() {
|
|
43
|
+
return this?.is;
|
|
44
|
+
}
|
|
45
|
+
};
|
package/src/helper.js
ADDED
|
@@ -1,23 +0,0 @@
|
|
|
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;
|