@ea-lab/reactive-json 1.4.0 → 2.0.0
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/dist/component/action/CustomEventListener.js +3 -2
- package/dist/component/action/ReactOnEvent.js +6 -5
- package/dist/component/attributeTransformer/setAttributeValue.js +20 -19
- package/dist/component/attributeTransformer/toggleAttributeValue.js +15 -14
- package/dist/component/attributeTransformer/unsetAttributeValue.js +8 -7
- package/dist/component/element/debug/VariablesDebug/VariablesDebug.js +74 -60
- package/dist/component/element/html/LabelFromValue.js +30 -18
- package/dist/component/element/index.js +28 -26
- package/dist/component/element/special/DataFilter.js +49 -40
- package/dist/component/element/special/DataSync.js +94 -0
- package/dist/component/element/special/index.js +15 -13
- package/dist/component/index.js +57 -55
- package/dist/component/reaction/fetchData.js +1 -1
- package/dist/component/reaction/index.js +1 -1
- package/dist/component/reaction/submitData.js +1 -1
- package/dist/component/reaction/utility/httpRequestCommon.js +118 -5
- package/dist/component/reaction/utility/index.js +1 -1
- package/dist/engine/DataStore.js +120 -0
- package/dist/engine/ReactiveJsonRoot.js +218 -277
- package/dist/engine/StoreContext.js +17 -0
- package/dist/engine/View.js +94 -58
- package/dist/engine/hook/useReactiveData.js +9 -0
- package/dist/engine/index.js +53 -45
- package/dist/engine/utility/formElementsCommon.js +36 -23
- package/dist/{httpRequestCommon-C7MsJIKA.js → index-BUPRVmV-.js} +616 -733
- package/dist/index-DJuOXIM5.js +25 -0
- package/dist/main.js +156 -146
- package/package.json +1 -1
- package/dist/index-Ya6_R5yr.js +0 -23
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { l as p } from "../lodash-CYNxjS-I.js";
|
|
2
|
+
class w {
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} initialData The initial data object.
|
|
5
|
+
*/
|
|
6
|
+
constructor(t = {}) {
|
|
7
|
+
this.data = t, this.listeners = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the value at the given path.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} path Dot-separated path (e.g., "user.name").
|
|
13
|
+
* @returns {*} The value at the path, or undefined.
|
|
14
|
+
*/
|
|
15
|
+
get(t) {
|
|
16
|
+
if (!t)
|
|
17
|
+
return this.data;
|
|
18
|
+
const i = t.split(".");
|
|
19
|
+
let e = this.data;
|
|
20
|
+
for (const f of i) {
|
|
21
|
+
if (e == null)
|
|
22
|
+
return;
|
|
23
|
+
e = e[f];
|
|
24
|
+
}
|
|
25
|
+
return e;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Updates the data at the given path and notifies listeners.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} path Dot-separated path.
|
|
31
|
+
* @param {*} value The new value.
|
|
32
|
+
* @param {string} updateMode "add", "remove", "move", or default (replace).
|
|
33
|
+
*/
|
|
34
|
+
set(t, i, e = void 0) {
|
|
35
|
+
if (t === "" || t === void 0 || t === null) {
|
|
36
|
+
this.data = i, this.notify("");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const f = this.updateDataObject(
|
|
40
|
+
{ realCurrentData: this.data },
|
|
41
|
+
t,
|
|
42
|
+
i,
|
|
43
|
+
e
|
|
44
|
+
);
|
|
45
|
+
this.data = f.realCurrentData, this.notify(t);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Subscribes to changes at the given path.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} path The path to listen to.
|
|
51
|
+
* @param {Function} callback Function to call when data changes.
|
|
52
|
+
* @returns {Function} Unsubscribe function.
|
|
53
|
+
*/
|
|
54
|
+
subscribe(t, i) {
|
|
55
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(i), () => {
|
|
56
|
+
const e = this.listeners.get(t);
|
|
57
|
+
e && (e.delete(i), e.size === 0 && this.listeners.delete(t));
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Notifies listeners about a change at the given path.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} changedPath The path that changed.
|
|
64
|
+
*/
|
|
65
|
+
notify(t) {
|
|
66
|
+
this.notifyListenersForPath(t);
|
|
67
|
+
let i = t;
|
|
68
|
+
for (; i.includes("."); )
|
|
69
|
+
i = i.substring(0, i.lastIndexOf(".")), this.notifyListenersForPath(i);
|
|
70
|
+
t !== "" && this.notifyListenersForPath("");
|
|
71
|
+
for (const e of this.listeners.keys())
|
|
72
|
+
e.startsWith(t + ".") && e !== t && this.notifyListenersForPath(e);
|
|
73
|
+
}
|
|
74
|
+
notifyListenersForPath(t) {
|
|
75
|
+
this.listeners.has(t) && this.listeners.get(t).forEach((i) => i());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Updates the given data object immutably.
|
|
79
|
+
* Adapted from ReactiveJsonRoot.updateDataObject but modified for immutability.
|
|
80
|
+
*/
|
|
81
|
+
updateDataObject(t, i, e, f = void 0) {
|
|
82
|
+
return this._immutableUpdate(t, i, e, f);
|
|
83
|
+
}
|
|
84
|
+
_immutableUpdate(t, i, e, f) {
|
|
85
|
+
const y = t.realCurrentData, a = i.split("."), m = (n) => Array.isArray(n) ? [...n] : typeof n == "object" && n !== null ? { ...n } : {}, u = (n, l) => {
|
|
86
|
+
const r = a[l], d = l === a.length - 1;
|
|
87
|
+
n == null && !d && (n = {});
|
|
88
|
+
const s = n === void 0 ? {} : m(n);
|
|
89
|
+
if (d) {
|
|
90
|
+
if (f === "remove" && Array.isArray(s))
|
|
91
|
+
s.splice(r, 1);
|
|
92
|
+
else if (f === "move") {
|
|
93
|
+
if (e.increment) {
|
|
94
|
+
if (!Array.isArray(s)) return s;
|
|
95
|
+
const o = parseInt(r), c = Math.min(
|
|
96
|
+
s.length,
|
|
97
|
+
Math.max(0, o + parseInt(e.increment))
|
|
98
|
+
);
|
|
99
|
+
if (c === o) return s;
|
|
100
|
+
const h = s.splice(o, 1);
|
|
101
|
+
if (h.length < 1) return s;
|
|
102
|
+
s.splice(c, 0, h[0]);
|
|
103
|
+
}
|
|
104
|
+
} else if (e === void 0)
|
|
105
|
+
delete s[r];
|
|
106
|
+
else {
|
|
107
|
+
if (p.isEqual(e, s[r]))
|
|
108
|
+
return s;
|
|
109
|
+
f === "add" ? (s[r] === void 0 ? s[r] = [] : Array.isArray(s[r]) ? s[r] = [...s[r]] : s[r] = [s[r]], s[r].push(e)) : s[r] = e;
|
|
110
|
+
}
|
|
111
|
+
return s;
|
|
112
|
+
}
|
|
113
|
+
return s[r] = u(n[r], l + 1), s;
|
|
114
|
+
};
|
|
115
|
+
return { realCurrentData: u(y, 0) };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
w as DataStore
|
|
120
|
+
};
|