cogsbox-state 0.5.468 → 0.5.470
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/README.md +62 -311
- package/dist/CogsState.d.ts +63 -69
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +945 -995
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts +10 -0
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +141 -119
- package/dist/Components.jsx.map +1 -1
- package/dist/index.js +5 -4
- package/dist/store.d.ts +3 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +23 -18
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +149 -209
- package/src/Components.tsx +55 -4
- package/src/store.ts +11 -6
package/dist/Components.d.ts
CHANGED
|
@@ -36,4 +36,14 @@ export declare function FormElementWrapper({ stateKey, path, rebuildStateShape,
|
|
|
36
36
|
setState: any;
|
|
37
37
|
}): import("react/jsx-runtime").JSX.Element;
|
|
38
38
|
export declare function useRegisterComponent(stateKey: string, componentId: string, forceUpdate: (o: object) => void): void;
|
|
39
|
+
export declare function IsolatedComponentWrapper({ stateKey, path, rebuildStateShape, renderFn, }: {
|
|
40
|
+
stateKey: string;
|
|
41
|
+
path: string[];
|
|
42
|
+
rebuildStateShape: (options: {
|
|
43
|
+
path: string[];
|
|
44
|
+
componentId: string;
|
|
45
|
+
meta?: any;
|
|
46
|
+
}) => any;
|
|
47
|
+
renderFn: (state: any) => React.ReactNode;
|
|
48
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
39
49
|
//# sourceMappingURL=Components.d.ts.map
|
package/dist/Components.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.d.ts","sourceRoot":"","sources":["../src/Components.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnE,OAA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,EACR,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAC3B,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,CAAC;KACZ,KAAK,GAAG,CAAC;IACV,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IAC9D,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,QAAQ,EAAE,GAAG,CAAC;CACf,2CAsQA;AACD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,QAiBjC;AAiDD,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,IAAI,EACJ,iBAAiB,EACjB,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAC3B,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,CAAC;KACZ,KAAK,GAAG,CAAC;IACV,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,SAAS,CAAC;CAC3C,2CAuBA"}
|
package/dist/Components.jsx
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { getGlobalStore as
|
|
4
|
-
import { useInView as
|
|
5
|
-
import { v4 as
|
|
1
|
+
import { jsx as w, Fragment as x } from "react/jsx-runtime";
|
|
2
|
+
import U, { memo as _, useState as p, useRef as j, useCallback as J, useEffect as C, useLayoutEffect as B } from "react";
|
|
3
|
+
import { getGlobalStore as b, formRefStore as Q } from "./store.js";
|
|
4
|
+
import { useInView as X } from "react-intersection-observer";
|
|
5
|
+
import { v4 as G } from "uuid";
|
|
6
6
|
import { isDeepEqual as Y } from "./utility.js";
|
|
7
7
|
const {
|
|
8
8
|
getInitialOptions: Z,
|
|
9
9
|
getShadowMetadata: H,
|
|
10
|
-
setShadowMetadata:
|
|
10
|
+
setShadowMetadata: I,
|
|
11
11
|
getShadowValue: R,
|
|
12
12
|
registerComponent: K,
|
|
13
13
|
unregisterComponent: ee,
|
|
14
14
|
notifyPathSubscribers: te,
|
|
15
15
|
subscribeToPath: re
|
|
16
|
-
} =
|
|
16
|
+
} = b.getState();
|
|
17
17
|
function ne({
|
|
18
18
|
formOpts: e,
|
|
19
19
|
path: t,
|
|
20
20
|
stateKey: n,
|
|
21
21
|
children: o
|
|
22
22
|
}) {
|
|
23
|
-
const { getInitialOptions:
|
|
24
|
-
...
|
|
23
|
+
const { getInitialOptions: l, getShadowMetadata: s, getShadowValue: a } = b.getState(), f = l(n), m = s(n, t)?.validation, i = m?.status || "NOT_VALIDATED", v = (m?.errors || []).map((d) => ({
|
|
24
|
+
...d,
|
|
25
25
|
path: t
|
|
26
|
-
})), u =
|
|
27
|
-
return /* @__PURE__ */
|
|
28
|
-
children: /* @__PURE__ */
|
|
29
|
-
status:
|
|
26
|
+
})), u = v.filter((d) => d.severity === "error").map((d) => d.message), c = v.filter((d) => d.severity === "warning").map((d) => d.message), L = u[0] || c[0], V = u.length > 0 ? "error" : c.length > 0 ? "warning" : void 0;
|
|
27
|
+
return /* @__PURE__ */ w(x, { children: f?.formElements?.validation && !e?.validation?.disable ? f.formElements.validation({
|
|
28
|
+
children: /* @__PURE__ */ w(U.Fragment, { children: o }, t.toString()),
|
|
29
|
+
status: i,
|
|
30
30
|
// Now passes the new ValidationStatus type
|
|
31
|
-
message: e?.validation?.hideMessage ? "" : e?.validation?.message ||
|
|
31
|
+
message: e?.validation?.hideMessage ? "" : e?.validation?.message || L || "",
|
|
32
|
+
severity: V,
|
|
32
33
|
hasErrors: u.length > 0,
|
|
33
|
-
hasWarnings:
|
|
34
|
-
allErrors:
|
|
34
|
+
hasWarnings: c.length > 0,
|
|
35
|
+
allErrors: v,
|
|
35
36
|
path: t,
|
|
36
|
-
getData: () =>
|
|
37
|
-
}) : /* @__PURE__ */
|
|
37
|
+
getData: () => a(n, t)
|
|
38
|
+
}) : /* @__PURE__ */ w(U.Fragment, { children: o }, t.toString()) });
|
|
38
39
|
}
|
|
39
|
-
const me =
|
|
40
|
+
const me = _(
|
|
40
41
|
oe,
|
|
41
42
|
(e, t) => e.itemPath.join(".") === t.itemPath.join(".") && e.stateKey === t.stateKey && e.itemComponentId === t.itemComponentId && e.localIndex === t.localIndex
|
|
42
43
|
);
|
|
@@ -45,87 +46,87 @@ function oe({
|
|
|
45
46
|
itemComponentId: t,
|
|
46
47
|
itemPath: n,
|
|
47
48
|
localIndex: o,
|
|
48
|
-
arraySetter:
|
|
49
|
+
arraySetter: l,
|
|
49
50
|
rebuildStateShape: s,
|
|
50
|
-
renderFn:
|
|
51
|
+
renderFn: a
|
|
51
52
|
}) {
|
|
52
|
-
const [,
|
|
53
|
-
|
|
54
|
-
const
|
|
53
|
+
const [, f] = p({}), { ref: h, inView: m } = X(), i = j(null), v = se(i), u = j(!1), c = [e, ...n].join(".");
|
|
54
|
+
F(e, t, f);
|
|
55
|
+
const L = J(
|
|
55
56
|
(r) => {
|
|
56
|
-
|
|
57
|
+
i.current = r, h(r);
|
|
57
58
|
},
|
|
58
|
-
[
|
|
59
|
+
[h]
|
|
59
60
|
);
|
|
60
|
-
|
|
61
|
-
const r = re(
|
|
62
|
-
|
|
61
|
+
C(() => {
|
|
62
|
+
const r = re(c, (g) => {
|
|
63
|
+
f({});
|
|
63
64
|
});
|
|
64
65
|
return () => r();
|
|
65
|
-
}, [
|
|
66
|
-
if (!
|
|
66
|
+
}, [c]), C(() => {
|
|
67
|
+
if (!m || !v || u.current)
|
|
67
68
|
return;
|
|
68
|
-
const r =
|
|
69
|
+
const r = i.current;
|
|
69
70
|
if (r && r.offsetHeight > 0) {
|
|
70
71
|
u.current = !0;
|
|
71
72
|
const g = r.offsetHeight;
|
|
72
|
-
|
|
73
|
+
I(e, n, {
|
|
73
74
|
virtualizer: {
|
|
74
75
|
itemHeight: g,
|
|
75
76
|
domRef: r
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
|
-
const
|
|
79
|
-
te(
|
|
79
|
+
const S = n.slice(0, -1), D = [e, ...S].join(".");
|
|
80
|
+
te(D, {
|
|
80
81
|
type: "ITEMHEIGHT",
|
|
81
82
|
itemKey: n.join("."),
|
|
82
|
-
ref:
|
|
83
|
+
ref: i.current
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
|
-
}, [
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
86
|
+
}, [m, v, e, n]);
|
|
87
|
+
const V = R(e, n);
|
|
88
|
+
if (V === void 0)
|
|
88
89
|
return null;
|
|
89
|
-
const
|
|
90
|
-
currentState:
|
|
90
|
+
const d = s({
|
|
91
|
+
currentState: V,
|
|
91
92
|
path: n,
|
|
92
93
|
componentId: t
|
|
93
|
-
}),
|
|
94
|
-
return /* @__PURE__ */
|
|
94
|
+
}), z = a(d, o, l);
|
|
95
|
+
return /* @__PURE__ */ w("div", { ref: L, children: z });
|
|
95
96
|
}
|
|
96
97
|
function ge({
|
|
97
98
|
stateKey: e,
|
|
98
99
|
path: t,
|
|
99
100
|
rebuildStateShape: n,
|
|
100
101
|
renderFn: o,
|
|
101
|
-
formOpts:
|
|
102
|
+
formOpts: l,
|
|
102
103
|
setState: s
|
|
103
104
|
}) {
|
|
104
|
-
const [
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
!u.current && !Y(
|
|
109
|
-
}, [
|
|
110
|
-
const r =
|
|
111
|
-
!u.current &&
|
|
105
|
+
const [a] = p(() => G()), [, f] = p({}), h = [e, ...t].join(".");
|
|
106
|
+
F(e, a, f);
|
|
107
|
+
const m = R(e, t), [i, v] = p(m), u = j(!1), c = j(null);
|
|
108
|
+
C(() => {
|
|
109
|
+
!u.current && !Y(m, i) && v(m);
|
|
110
|
+
}, [m]), C(() => {
|
|
111
|
+
const r = b.getState().subscribeToPath(h, (g) => {
|
|
112
|
+
!u.current && i !== g && f({});
|
|
112
113
|
});
|
|
113
114
|
return () => {
|
|
114
|
-
r(),
|
|
115
|
+
r(), c.current && (clearTimeout(c.current), u.current = !1);
|
|
115
116
|
};
|
|
116
117
|
}, []);
|
|
117
|
-
const
|
|
118
|
+
const L = J(
|
|
118
119
|
(r) => {
|
|
119
|
-
typeof
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
if (u.current = !1, s(r, t, { updateType: "update" }), !
|
|
123
|
-
const
|
|
120
|
+
typeof m === "number" && typeof r == "string" && (r = r === "" ? 0 : Number(r)), v(r), u.current = !0, c.current && clearTimeout(c.current);
|
|
121
|
+
const S = l?.debounceTime ?? 200;
|
|
122
|
+
c.current = setTimeout(() => {
|
|
123
|
+
if (u.current = !1, s(r, t, { updateType: "update" }), !b.getState().getShadowMetadata(e, [])?.features?.validationEnabled) return;
|
|
124
|
+
const M = Z(e)?.validation, N = M?.zodSchemaV4 || M?.zodSchemaV3;
|
|
124
125
|
if (N) {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
...
|
|
126
|
+
const E = R(e, []), y = N.safeParse(E), O = H(e, t) || {};
|
|
127
|
+
if (y.success)
|
|
128
|
+
I(e, t, {
|
|
129
|
+
...O,
|
|
129
130
|
validation: {
|
|
130
131
|
status: "VALID",
|
|
131
132
|
errors: [],
|
|
@@ -134,11 +135,11 @@ function ge({
|
|
|
134
135
|
}
|
|
135
136
|
});
|
|
136
137
|
else {
|
|
137
|
-
const W = ("issues" in
|
|
138
|
-
(
|
|
138
|
+
const W = ("issues" in y.error ? y.error.issues : y.error.errors).filter(
|
|
139
|
+
(T) => JSON.stringify(T.path) === JSON.stringify(t)
|
|
139
140
|
);
|
|
140
|
-
W.length > 0 ?
|
|
141
|
-
...
|
|
141
|
+
W.length > 0 ? I(e, t, {
|
|
142
|
+
...O,
|
|
142
143
|
validation: {
|
|
143
144
|
status: "INVALID",
|
|
144
145
|
errors: [
|
|
@@ -152,8 +153,8 @@ function ge({
|
|
|
152
153
|
lastValidated: Date.now(),
|
|
153
154
|
validatedValue: r
|
|
154
155
|
}
|
|
155
|
-
}) :
|
|
156
|
-
...
|
|
156
|
+
}) : I(e, t, {
|
|
157
|
+
...O,
|
|
157
158
|
validation: {
|
|
158
159
|
status: "VALID",
|
|
159
160
|
errors: [],
|
|
@@ -163,83 +164,83 @@ function ge({
|
|
|
163
164
|
});
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
},
|
|
167
|
+
}, S), f({});
|
|
167
168
|
},
|
|
168
|
-
[s, t,
|
|
169
|
-
),
|
|
170
|
-
if (console.log("handleBlur triggered"),
|
|
171
|
-
const { getInitialOptions: g } =
|
|
172
|
-
if (!
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
...
|
|
169
|
+
[s, t, l?.debounceTime, e]
|
|
170
|
+
), V = J(async () => {
|
|
171
|
+
if (console.log("handleBlur triggered"), c.current && (clearTimeout(c.current), c.current = null, u.current = !1, s(i, t, { updateType: "update" })), !H(e, [])?.features?.validationEnabled) return;
|
|
172
|
+
const { getInitialOptions: g } = b.getState(), S = g(e)?.validation, D = S?.zodSchemaV4 || S?.zodSchemaV3;
|
|
173
|
+
if (!D) return;
|
|
174
|
+
const M = H(e, t);
|
|
175
|
+
I(e, t, {
|
|
176
|
+
...M,
|
|
176
177
|
validation: {
|
|
177
178
|
status: "VALIDATING",
|
|
178
179
|
errors: [],
|
|
179
180
|
lastValidated: Date.now(),
|
|
180
|
-
validatedValue:
|
|
181
|
+
validatedValue: i
|
|
181
182
|
}
|
|
182
183
|
});
|
|
183
|
-
const N = R(e, []),
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
...
|
|
184
|
+
const N = R(e, []), E = D.safeParse(N);
|
|
185
|
+
if (E.success)
|
|
186
|
+
I(e, t, {
|
|
187
|
+
...M,
|
|
187
188
|
validation: {
|
|
188
189
|
status: "VALID",
|
|
189
190
|
errors: [],
|
|
190
191
|
lastValidated: Date.now(),
|
|
191
|
-
validatedValue:
|
|
192
|
+
validatedValue: i
|
|
192
193
|
}
|
|
193
194
|
});
|
|
194
195
|
else {
|
|
195
|
-
const
|
|
196
|
-
if (t.some((
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
const
|
|
200
|
-
return JSON.stringify(
|
|
196
|
+
const O = ("issues" in E.error ? E.error.issues : E.error.errors).filter((A) => {
|
|
197
|
+
if (t.some((T) => T.startsWith("id:"))) {
|
|
198
|
+
const T = t[0].startsWith("id:") ? [] : t.slice(0, -1), P = b.getState().getShadowMetadata(e, T);
|
|
199
|
+
if (P?.arrayKeys) {
|
|
200
|
+
const $ = [e, ...t.slice(0, -1)].join("."), q = P.arrayKeys.indexOf($), k = [...T, q, ...t.slice(-1)];
|
|
201
|
+
return JSON.stringify(A.path) === JSON.stringify(k);
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
|
-
return JSON.stringify(
|
|
204
|
+
return JSON.stringify(A.path) === JSON.stringify(t);
|
|
204
205
|
});
|
|
205
|
-
|
|
206
|
-
...
|
|
206
|
+
I(e, t, {
|
|
207
|
+
...M,
|
|
207
208
|
validation: {
|
|
208
209
|
status: "INVALID",
|
|
209
|
-
errors:
|
|
210
|
+
errors: O.map((A) => ({
|
|
210
211
|
source: "client",
|
|
211
|
-
message:
|
|
212
|
+
message: A.message,
|
|
212
213
|
severity: "error"
|
|
213
214
|
// Hard error on blur
|
|
214
215
|
})),
|
|
215
216
|
lastValidated: Date.now(),
|
|
216
|
-
validatedValue:
|
|
217
|
+
validatedValue: i
|
|
217
218
|
}
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
|
-
|
|
221
|
-
}, [e, t,
|
|
221
|
+
f({});
|
|
222
|
+
}, [e, t, i, s]), d = n({
|
|
222
223
|
path: t,
|
|
223
|
-
componentId:
|
|
224
|
+
componentId: a,
|
|
224
225
|
meta: void 0
|
|
225
|
-
}),
|
|
226
|
+
}), z = new Proxy(d, {
|
|
226
227
|
get(r, g) {
|
|
227
|
-
return g === "inputProps" ? {
|
|
228
|
-
value:
|
|
229
|
-
onChange: (
|
|
230
|
-
|
|
228
|
+
return g === "$inputProps" ? {
|
|
229
|
+
value: i ?? "",
|
|
230
|
+
onChange: (S) => {
|
|
231
|
+
L(S.target.value);
|
|
231
232
|
},
|
|
232
233
|
// 5. Wire the new onBlur handler to the input props.
|
|
233
|
-
onBlur:
|
|
234
|
-
ref:
|
|
234
|
+
onBlur: V,
|
|
235
|
+
ref: Q.getState().getFormRef(e + "." + t.join("."))
|
|
235
236
|
} : r[g];
|
|
236
237
|
}
|
|
237
238
|
});
|
|
238
|
-
return /* @__PURE__ */
|
|
239
|
+
return /* @__PURE__ */ w(ne, { formOpts: l, path: t, stateKey: e, children: o(z) });
|
|
239
240
|
}
|
|
240
|
-
function
|
|
241
|
+
function F(e, t, n) {
|
|
241
242
|
const o = `${e}////${t}`;
|
|
242
|
-
|
|
243
|
+
B(() => (K(e, o, {
|
|
243
244
|
forceUpdate: () => n({}),
|
|
244
245
|
paths: /* @__PURE__ */ new Set(),
|
|
245
246
|
reactiveType: ["component"]
|
|
@@ -247,9 +248,9 @@ function B(e, t, n) {
|
|
|
247
248
|
ee(e, o);
|
|
248
249
|
}), [e, o]);
|
|
249
250
|
}
|
|
250
|
-
const
|
|
251
|
-
const [t, n] =
|
|
252
|
-
return
|
|
251
|
+
const se = (e) => {
|
|
252
|
+
const [t, n] = p(!1);
|
|
253
|
+
return B(() => {
|
|
253
254
|
if (!e.current) {
|
|
254
255
|
n(!0);
|
|
255
256
|
return;
|
|
@@ -259,24 +260,45 @@ const ae = (e) => {
|
|
|
259
260
|
n(!0);
|
|
260
261
|
return;
|
|
261
262
|
}
|
|
262
|
-
let
|
|
263
|
+
let l = 0;
|
|
263
264
|
const s = () => {
|
|
264
|
-
|
|
265
|
+
l++, l === o.length && n(!0);
|
|
265
266
|
};
|
|
266
|
-
return o.forEach((
|
|
267
|
-
|
|
267
|
+
return o.forEach((a) => {
|
|
268
|
+
a.complete ? s() : (a.addEventListener("load", s), a.addEventListener("error", s));
|
|
268
269
|
}), () => {
|
|
269
|
-
o.forEach((
|
|
270
|
-
|
|
270
|
+
o.forEach((a) => {
|
|
271
|
+
a.removeEventListener("load", s), a.removeEventListener("error", s);
|
|
271
272
|
});
|
|
272
273
|
};
|
|
273
274
|
}, [e.current]), t;
|
|
274
275
|
};
|
|
276
|
+
function ve({
|
|
277
|
+
stateKey: e,
|
|
278
|
+
path: t,
|
|
279
|
+
rebuildStateShape: n,
|
|
280
|
+
renderFn: o
|
|
281
|
+
}) {
|
|
282
|
+
const [l] = p(() => G()), [, s] = p({}), a = [e, ...t].join(".");
|
|
283
|
+
F(e, l, s), C(() => {
|
|
284
|
+
const h = b.getState().subscribeToPath(a, () => {
|
|
285
|
+
s({});
|
|
286
|
+
});
|
|
287
|
+
return () => h();
|
|
288
|
+
}, [a]);
|
|
289
|
+
const f = n({
|
|
290
|
+
path: t,
|
|
291
|
+
componentId: l,
|
|
292
|
+
meta: void 0
|
|
293
|
+
});
|
|
294
|
+
return /* @__PURE__ */ w(x, { children: o(f) });
|
|
295
|
+
}
|
|
275
296
|
export {
|
|
276
297
|
ge as FormElementWrapper,
|
|
298
|
+
ve as IsolatedComponentWrapper,
|
|
277
299
|
oe as ListItemWrapper,
|
|
278
300
|
me as MemoizedCogsItemWrapper,
|
|
279
301
|
ne as ValidationWrapper,
|
|
280
|
-
|
|
302
|
+
F as useRegisterComponent
|
|
281
303
|
};
|
|
282
304
|
//# sourceMappingURL=Components.jsx.map
|
package/dist/Components.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.jsx","sources":["../src/Components.tsx"],"sourcesContent":["import { FormElementParams, type FormOptsType } from './CogsState';\r\nimport React, {\r\n memo,\r\n RefObject,\r\n useCallback,\r\n useEffect,\r\n useLayoutEffect,\r\n useRef,\r\n useState,\r\n} from 'react';\r\nimport { formRefStore, getGlobalStore, ValidationError } from './store';\r\nimport { useInView } from 'react-intersection-observer';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport { isDeepEqual } from './utility';\r\nconst {\r\n getInitialOptions,\r\n\r\n getShadowMetadata,\r\n setShadowMetadata,\r\n getShadowValue,\r\n\r\n registerComponent,\r\n unregisterComponent,\r\n\r\n notifyPathSubscribers,\r\n subscribeToPath,\r\n} = getGlobalStore.getState();\r\nexport type ValidationWrapperProps = {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n stateKey: string;\r\n children: React.ReactNode;\r\n};\r\n\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n stateKey,\r\n children,\r\n}: ValidationWrapperProps) {\r\n const { getInitialOptions, getShadowMetadata, getShadowValue } =\r\n getGlobalStore.getState();\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n\r\n const shadowMeta = getShadowMetadata(stateKey!, path);\r\n const validationState = shadowMeta?.validation;\r\n\r\n const status = validationState?.status || 'NOT_VALIDATED';\r\n\r\n const errors = (validationState?.errors || []).map((err) => ({\r\n ...err,\r\n path: path,\r\n })) as ValidationError[];\r\n const errorMessages = errors\r\n .filter((err) => err.severity === 'error')\r\n .map((err) => err.message);\r\n const warningMessages = errors\r\n .filter((err) => err.severity === 'warning')\r\n .map((err) => err.message);\r\n\r\n // Use first error, or first warning if no errors\r\n const message = errorMessages[0] || warningMessages[0];\r\n\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n ),\r\n status, // Now passes the new ValidationStatus type\r\n message: formOpts?.validation?.hideMessage\r\n ? ''\r\n : formOpts?.validation?.message || message || '',\r\n\r\n hasErrors: errorMessages.length > 0,\r\n hasWarnings: warningMessages.length > 0,\r\n allErrors: errors,\r\n path: path,\r\n getData: () => getShadowValue(stateKey!, path),\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\nexport const MemoizedCogsItemWrapper = memo(\r\n ListItemWrapper,\r\n (prevProps, nextProps) => {\r\n // Re-render if any of these change:\r\n return (\r\n prevProps.itemPath.join('.') === nextProps.itemPath.join('.') &&\r\n prevProps.stateKey === nextProps.stateKey &&\r\n prevProps.itemComponentId === nextProps.itemComponentId &&\r\n prevProps.localIndex === nextProps.localIndex\r\n );\r\n }\r\n);\r\nexport function ListItemWrapper({\r\n stateKey,\r\n itemComponentId,\r\n itemPath,\r\n localIndex,\r\n arraySetter,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n itemComponentId: string;\r\n itemPath: string[];\r\n localIndex: number;\r\n arraySetter: any;\r\n\r\n rebuildStateShape: (options: {\r\n currentState: any;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (\r\n setter: any,\r\n index: number,\r\n\r\n arraySetter: any\r\n ) => React.ReactNode;\r\n}) {\r\n const [, forceUpdate] = useState({});\r\n const { ref: inViewRef, inView } = useInView();\r\n const elementRef = useRef<HTMLDivElement | null>(null);\r\n\r\n const imagesLoaded = useImageLoaded(elementRef);\r\n const hasReportedInitialHeight = useRef(false);\r\n const fullKey = [stateKey, ...itemPath].join('.');\r\n useRegisterComponent(stateKey, itemComponentId, forceUpdate);\r\n\r\n const setRefs = useCallback(\r\n (element: HTMLDivElement | null) => {\r\n elementRef.current = element;\r\n inViewRef(element); // This is the ref from useInView\r\n },\r\n [inViewRef]\r\n );\r\n\r\n useEffect(() => {\r\n const unsubscribe = subscribeToPath(fullKey, (e) => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [fullKey]);\r\n useEffect(() => {\r\n if (!inView || !imagesLoaded || hasReportedInitialHeight.current) {\r\n return;\r\n }\r\n\r\n const element = elementRef.current;\r\n if (element && element.offsetHeight > 0) {\r\n hasReportedInitialHeight.current = true;\r\n const newHeight = element.offsetHeight;\r\n\r\n setShadowMetadata(stateKey, itemPath, {\r\n virtualizer: {\r\n itemHeight: newHeight,\r\n domRef: element,\r\n },\r\n });\r\n\r\n const arrayPath = itemPath.slice(0, -1);\r\n const arrayPathKey = [stateKey, ...arrayPath].join('.');\r\n notifyPathSubscribers(arrayPathKey, {\r\n type: 'ITEMHEIGHT',\r\n itemKey: itemPath.join('.'),\r\n\r\n ref: elementRef.current,\r\n });\r\n }\r\n }, [inView, imagesLoaded, stateKey, itemPath]);\r\n\r\n const itemValue = getShadowValue(stateKey, itemPath);\r\n\r\n if (itemValue === undefined) {\r\n return null;\r\n }\r\n\r\n const itemSetter = rebuildStateShape({\r\n currentState: itemValue,\r\n path: itemPath,\r\n componentId: itemComponentId,\r\n });\r\n const children = renderFn(itemSetter, localIndex, arraySetter);\r\n\r\n return <div ref={setRefs}>{children}</div>;\r\n}\r\n\r\nexport function FormElementWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n formOpts,\r\n setState,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (params: FormElementParams<any>) => React.ReactNode;\r\n formOpts?: FormOptsType;\r\n setState: any;\r\n}) {\r\n const [componentId] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n const globalStateValue = getShadowValue(stateKey, path);\r\n const [localValue, setLocalValue] = useState<any>(globalStateValue);\r\n const isCurrentlyDebouncing = useRef(false);\r\n const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);\r\n\r\n useEffect(() => {\r\n if (\r\n !isCurrentlyDebouncing.current &&\r\n !isDeepEqual(globalStateValue, localValue)\r\n ) {\r\n setLocalValue(globalStateValue);\r\n }\r\n }, [globalStateValue]);\r\n\r\n useEffect(() => {\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, (newValue) => {\r\n if (!isCurrentlyDebouncing.current && localValue !== newValue) {\r\n forceUpdate({});\r\n }\r\n });\r\n return () => {\r\n unsubscribe();\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n isCurrentlyDebouncing.current = false;\r\n }\r\n };\r\n }, []);\r\n\r\n const debouncedUpdate = useCallback(\r\n (newValue: any) => {\r\n const currentType = typeof globalStateValue;\r\n if (currentType === 'number' && typeof newValue === 'string') {\r\n newValue = newValue === '' ? 0 : Number(newValue);\r\n }\r\n setLocalValue(newValue);\r\n isCurrentlyDebouncing.current = true;\r\n\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n }\r\n\r\n const debounceTime = formOpts?.debounceTime ?? 200;\r\n\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n isCurrentlyDebouncing.current = false;\r\n setState(newValue, path, { updateType: 'update' });\r\n\r\n // NEW: Check if validation is enabled via features\r\n const rootMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (zodSchema) {\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n const currentMeta = getShadowMetadata(stateKey, path) || {};\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n const pathErrors = errors.filter(\r\n (error: any) =>\r\n JSON.stringify(error.path) === JSON.stringify(path)\r\n );\r\n\r\n if (pathErrors.length > 0) {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: [\r\n {\r\n source: 'client',\r\n message: pathErrors[0]?.message,\r\n severity: 'warning', // Gentle error during typing\r\n },\r\n ],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n }\r\n }, debounceTime);\r\n forceUpdate({});\r\n },\r\n [setState, path, formOpts?.debounceTime, stateKey]\r\n );\r\n\r\n const handleBlur = useCallback(async () => {\r\n console.log('handleBlur triggered');\r\n\r\n // Commit any pending changes\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n debounceTimeoutRef.current = null;\r\n isCurrentlyDebouncing.current = false;\r\n setState(localValue, path, { updateType: 'update' });\r\n }\r\n const rootMeta = getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n const { getInitialOptions } = getGlobalStore.getState();\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (!zodSchema) return;\r\n\r\n // Get the full path including stateKey\r\n\r\n // Update validation state to \"validating\"\r\n const currentMeta = getShadowMetadata(stateKey, path);\r\n\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALIDATING',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n\r\n // Validate full state\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n // Find errors for this specific path\r\n const pathErrors = errors.filter((error: any) => {\r\n // For array paths, we need to translate indices to ULIDs\r\n if (path.some((p) => p.startsWith('id:'))) {\r\n // This is an array item path like [\"id:xyz\", \"name\"]\r\n const parentPath = path[0]!.startsWith('id:')\r\n ? []\r\n : path.slice(0, -1);\r\n\r\n const arrayMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, parentPath);\r\n\r\n if (arrayMeta?.arrayKeys) {\r\n const itemKey = [stateKey, ...path.slice(0, -1)].join('.');\r\n const itemIndex = arrayMeta.arrayKeys.indexOf(itemKey);\r\n\r\n // Compare with Zod path\r\n const zodPath = [...parentPath, itemIndex, ...path.slice(-1)];\r\n const match =\r\n JSON.stringify(error.path) === JSON.stringify(zodPath);\r\n\r\n return match;\r\n }\r\n }\r\n\r\n const directMatch = JSON.stringify(error.path) === JSON.stringify(path);\r\n\r\n return directMatch;\r\n });\r\n\r\n // Update shadow metadata with validation result\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: pathErrors.map((err: any) => ({\r\n source: 'client' as const,\r\n message: err.message,\r\n severity: 'error' as const, // Hard error on blur\r\n })),\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n } else {\r\n // Validation passed\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n }\r\n forceUpdate({});\r\n }, [stateKey, path, localValue, setState]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n const stateWithInputProps = new Proxy(baseState, {\r\n get(target, prop) {\r\n if (prop === 'inputProps') {\r\n return {\r\n value: localValue ?? '',\r\n onChange: (e: any) => {\r\n debouncedUpdate(e.target.value);\r\n },\r\n // 5. Wire the new onBlur handler to the input props.\r\n onBlur: handleBlur,\r\n ref: formRefStore\r\n .getState()\r\n .getFormRef(stateKey + '.' + path.join('.')),\r\n };\r\n }\r\n\r\n return target[prop];\r\n },\r\n });\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {renderFn(stateWithInputProps)}\r\n </ValidationWrapper>\r\n );\r\n}\r\nexport function useRegisterComponent(\r\n stateKey: string,\r\n componentId: string,\r\n forceUpdate: (o: object) => void\r\n) {\r\n const fullComponentId = `${stateKey}////${componentId}`;\r\n\r\n useLayoutEffect(() => {\r\n // Call the safe, centralized function to register\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n\r\n // The cleanup now calls the safe, centralized unregister function\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]); // Dependencies are stable and correct\r\n}\r\n\r\nconst useImageLoaded = (ref: RefObject<HTMLElement>): boolean => {\r\n const [loaded, setLoaded] = useState(false);\r\n\r\n useLayoutEffect(() => {\r\n if (!ref.current) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n const images = Array.from(ref.current.querySelectorAll('img'));\r\n\r\n // If there are no images, we are \"loaded\" immediately.\r\n if (images.length === 0) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n let loadedCount = 0;\r\n const handleImageLoad = () => {\r\n loadedCount++;\r\n if (loadedCount === images.length) {\r\n setLoaded(true);\r\n }\r\n };\r\n\r\n images.forEach((image) => {\r\n if (image.complete) {\r\n handleImageLoad();\r\n } else {\r\n image.addEventListener('load', handleImageLoad);\r\n image.addEventListener('error', handleImageLoad);\r\n }\r\n });\r\n\r\n return () => {\r\n images.forEach((image) => {\r\n image.removeEventListener('load', handleImageLoad);\r\n image.removeEventListener('error', handleImageLoad);\r\n });\r\n };\r\n }, [ref.current]);\r\n\r\n return loaded;\r\n};\r\n"],"names":["getInitialOptions","getShadowMetadata","setShadowMetadata","getShadowValue","registerComponent","unregisterComponent","notifyPathSubscribers","subscribeToPath","getGlobalStore","ValidationWrapper","formOpts","path","stateKey","children","thisStateOpts","validationState","status","errors","err","errorMessages","warningMessages","message","jsx","Fragment","React","MemoizedCogsItemWrapper","memo","ListItemWrapper","prevProps","nextProps","itemComponentId","itemPath","localIndex","arraySetter","rebuildStateShape","renderFn","forceUpdate","useState","inViewRef","inView","useInView","elementRef","useRef","imagesLoaded","useImageLoaded","hasReportedInitialHeight","fullKey","useRegisterComponent","setRefs","useCallback","element","useEffect","unsubscribe","e","newHeight","arrayPath","arrayPathKey","itemValue","itemSetter","FormElementWrapper","setState","componentId","uuidv4","stateKeyPathKey","globalStateValue","localValue","setLocalValue","isCurrentlyDebouncing","debounceTimeoutRef","isDeepEqual","newValue","debouncedUpdate","debounceTime","validationOptions","zodSchema","fullState","result","currentMeta","pathErrors","error","handleBlur","p","parentPath","arrayMeta","itemKey","itemIndex","zodPath","baseState","stateWithInputProps","target","prop","formRefStore","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image"],"mappings":";;;;;;AAcA,MAAM;AAAA,EACJ,mBAAAA;AAAA,EAEA,mBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EAEA,mBAAAC;AAAA,EACA,qBAAAC;AAAA,EAEA,uBAAAC;AAAA,EACA,iBAAAC;AACF,IAAIC,EAAe,SAAA;AAQZ,SAASC,GAAkB;AAAA,EAChC,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAM,EAAE,mBAAAb,GAAmB,m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gF,CAAe;AAAA,EAC/C,IACC,CAAChF,GAAUgF,CAAe,CAAC;AAChC;AAEA,MAAMhD,KAAiB,CAACkD,MAAyC;AAC/D,QAAM,CAACC,GAAQC,CAAS,IAAI3D,EAAS,EAAK;AAE1C,SAAAwD,EAAgB,MAAM;AACpB,QAAI,CAACC,EAAI,SAAS;AAChB,MAAAE,EAAU,EAAI;AACd;AAAA,IACF;AAEA,UAAMC,IAAS,MAAM,KAAKH,EAAI,QAAQ,iBAAiB,KAAK,CAAC;AAG7D,QAAIG,EAAO,WAAW,GAAG;AACvB,MAAAD,EAAU,EAAI;AACd;AAAA,IACF;AAEA,QAAIE,IAAc;AAClB,UAAMC,IAAkB,MAAM;AAC5B,MAAAD,KACIA,MAAgBD,EAAO,UACzBD,EAAU,EAAI;AAAA,IAElB;AAEA,WAAAC,EAAO,QAAQ,CAACG,MAAU;AACxB,MAAIA,EAAM,WACRD,EAAA,KAEAC,EAAM,iBAAiB,QAAQD,CAAe,GAC9CC,EAAM,iBAAiB,SAASD,CAAe;AAAA,IAEnD,CAAC,GAEM,MAAM;AACX,MAAAF,EAAO,QAAQ,CAACG,MAAU;AACxB,QAAAA,EAAM,oBAAoB,QAAQD,CAAe,GACjDC,EAAM,oBAAoB,SAASD,CAAe;AAAA,MACpD,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAACL,EAAI,OAAO,CAAC,GAETC;AACT;"}
|
|
1
|
+
{"version":3,"file":"Components.jsx","sources":["../src/Components.tsx"],"sourcesContent":["import { FormElementParams, type FormOptsType } from './CogsState';\r\nimport React, {\r\n memo,\r\n RefObject,\r\n useCallback,\r\n useEffect,\r\n useLayoutEffect,\r\n useRef,\r\n useState,\r\n} from 'react';\r\nimport {\r\n formRefStore,\r\n getGlobalStore,\r\n ValidationError,\r\n ValidationSeverity,\r\n} from './store';\r\nimport { useInView } from 'react-intersection-observer';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport { isDeepEqual } from './utility';\r\nconst {\r\n getInitialOptions,\r\n\r\n getShadowMetadata,\r\n setShadowMetadata,\r\n getShadowValue,\r\n\r\n registerComponent,\r\n unregisterComponent,\r\n\r\n notifyPathSubscribers,\r\n subscribeToPath,\r\n} = getGlobalStore.getState();\r\nexport type ValidationWrapperProps = {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n stateKey: string;\r\n children: React.ReactNode;\r\n};\r\n\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n stateKey,\r\n children,\r\n}: ValidationWrapperProps) {\r\n const { getInitialOptions, getShadowMetadata, getShadowValue } =\r\n getGlobalStore.getState();\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n\r\n const shadowMeta = getShadowMetadata(stateKey!, path);\r\n const validationState = shadowMeta?.validation;\r\n\r\n const status = validationState?.status || 'NOT_VALIDATED';\r\n\r\n const errors = (validationState?.errors || []).map((err) => ({\r\n ...err,\r\n path: path,\r\n })) as ValidationError[];\r\n const errorMessages = errors\r\n .filter((err) => err.severity === 'error')\r\n .map((err) => err.message);\r\n const warningMessages = errors\r\n .filter((err) => err.severity === 'warning')\r\n .map((err) => err.message);\r\n\r\n // Use first error, or first warning if no errors\r\n const message = errorMessages[0] || warningMessages[0];\r\n const primarySeverity: ValidationSeverity =\r\n errorMessages.length > 0\r\n ? 'error'\r\n : warningMessages.length > 0\r\n ? 'warning'\r\n : undefined;\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n ),\r\n status, // Now passes the new ValidationStatus type\r\n message: formOpts?.validation?.hideMessage\r\n ? ''\r\n : formOpts?.validation?.message || message || '',\r\n severity: primarySeverity,\r\n hasErrors: errorMessages.length > 0,\r\n hasWarnings: warningMessages.length > 0,\r\n allErrors: errors,\r\n path: path,\r\n getData: () => getShadowValue(stateKey!, path),\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\nexport const MemoizedCogsItemWrapper = memo(\r\n ListItemWrapper,\r\n (prevProps, nextProps) => {\r\n // Re-render if any of these change:\r\n return (\r\n prevProps.itemPath.join('.') === nextProps.itemPath.join('.') &&\r\n prevProps.stateKey === nextProps.stateKey &&\r\n prevProps.itemComponentId === nextProps.itemComponentId &&\r\n prevProps.localIndex === nextProps.localIndex\r\n );\r\n }\r\n);\r\nexport function ListItemWrapper({\r\n stateKey,\r\n itemComponentId,\r\n itemPath,\r\n localIndex,\r\n arraySetter,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n itemComponentId: string;\r\n itemPath: string[];\r\n localIndex: number;\r\n arraySetter: any;\r\n\r\n rebuildStateShape: (options: {\r\n currentState: any;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (\r\n setter: any,\r\n index: number,\r\n\r\n arraySetter: any\r\n ) => React.ReactNode;\r\n}) {\r\n const [, forceUpdate] = useState({});\r\n const { ref: inViewRef, inView } = useInView();\r\n const elementRef = useRef<HTMLDivElement | null>(null);\r\n\r\n const imagesLoaded = useImageLoaded(elementRef);\r\n const hasReportedInitialHeight = useRef(false);\r\n const fullKey = [stateKey, ...itemPath].join('.');\r\n useRegisterComponent(stateKey, itemComponentId, forceUpdate);\r\n\r\n const setRefs = useCallback(\r\n (element: HTMLDivElement | null) => {\r\n elementRef.current = element;\r\n inViewRef(element); // This is the ref from useInView\r\n },\r\n [inViewRef]\r\n );\r\n\r\n useEffect(() => {\r\n const unsubscribe = subscribeToPath(fullKey, (e) => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [fullKey]);\r\n useEffect(() => {\r\n if (!inView || !imagesLoaded || hasReportedInitialHeight.current) {\r\n return;\r\n }\r\n\r\n const element = elementRef.current;\r\n if (element && element.offsetHeight > 0) {\r\n hasReportedInitialHeight.current = true;\r\n const newHeight = element.offsetHeight;\r\n\r\n setShadowMetadata(stateKey, itemPath, {\r\n virtualizer: {\r\n itemHeight: newHeight,\r\n domRef: element,\r\n },\r\n });\r\n\r\n const arrayPath = itemPath.slice(0, -1);\r\n const arrayPathKey = [stateKey, ...arrayPath].join('.');\r\n notifyPathSubscribers(arrayPathKey, {\r\n type: 'ITEMHEIGHT',\r\n itemKey: itemPath.join('.'),\r\n\r\n ref: elementRef.current,\r\n });\r\n }\r\n }, [inView, imagesLoaded, stateKey, itemPath]);\r\n\r\n const itemValue = getShadowValue(stateKey, itemPath);\r\n\r\n if (itemValue === undefined) {\r\n return null;\r\n }\r\n\r\n const itemSetter = rebuildStateShape({\r\n currentState: itemValue,\r\n path: itemPath,\r\n componentId: itemComponentId,\r\n });\r\n const children = renderFn(itemSetter, localIndex, arraySetter);\r\n\r\n return <div ref={setRefs}>{children}</div>;\r\n}\r\n\r\nexport function FormElementWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n formOpts,\r\n setState,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (params: FormElementParams<any>) => React.ReactNode;\r\n formOpts?: FormOptsType;\r\n setState: any;\r\n}) {\r\n const [componentId] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n const globalStateValue = getShadowValue(stateKey, path);\r\n const [localValue, setLocalValue] = useState<any>(globalStateValue);\r\n const isCurrentlyDebouncing = useRef(false);\r\n const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);\r\n\r\n useEffect(() => {\r\n if (\r\n !isCurrentlyDebouncing.current &&\r\n !isDeepEqual(globalStateValue, localValue)\r\n ) {\r\n setLocalValue(globalStateValue);\r\n }\r\n }, [globalStateValue]);\r\n\r\n useEffect(() => {\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, (newValue) => {\r\n if (!isCurrentlyDebouncing.current && localValue !== newValue) {\r\n forceUpdate({});\r\n }\r\n });\r\n return () => {\r\n unsubscribe();\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n isCurrentlyDebouncing.current = false;\r\n }\r\n };\r\n }, []);\r\n\r\n const debouncedUpdate = useCallback(\r\n (newValue: any) => {\r\n const currentType = typeof globalStateValue;\r\n if (currentType === 'number' && typeof newValue === 'string') {\r\n newValue = newValue === '' ? 0 : Number(newValue);\r\n }\r\n setLocalValue(newValue);\r\n isCurrentlyDebouncing.current = true;\r\n\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n }\r\n\r\n const debounceTime = formOpts?.debounceTime ?? 200;\r\n\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n isCurrentlyDebouncing.current = false;\r\n setState(newValue, path, { updateType: 'update' });\r\n\r\n // NEW: Check if validation is enabled via features\r\n const rootMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (zodSchema) {\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n const currentMeta = getShadowMetadata(stateKey, path) || {};\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n const pathErrors = errors.filter(\r\n (error: any) =>\r\n JSON.stringify(error.path) === JSON.stringify(path)\r\n );\r\n\r\n if (pathErrors.length > 0) {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: [\r\n {\r\n source: 'client',\r\n message: pathErrors[0]?.message,\r\n severity: 'warning', // Gentle error during typing\r\n },\r\n ],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n }\r\n }, debounceTime);\r\n forceUpdate({});\r\n },\r\n [setState, path, formOpts?.debounceTime, stateKey]\r\n );\r\n\r\n const handleBlur = useCallback(async () => {\r\n console.log('handleBlur triggered');\r\n\r\n // Commit any pending changes\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n debounceTimeoutRef.current = null;\r\n isCurrentlyDebouncing.current = false;\r\n setState(localValue, path, { updateType: 'update' });\r\n }\r\n const rootMeta = getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n const { getInitialOptions } = getGlobalStore.getState();\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (!zodSchema) return;\r\n\r\n // Get the full path including stateKey\r\n\r\n // Update validation state to \"validating\"\r\n const currentMeta = getShadowMetadata(stateKey, path);\r\n\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALIDATING',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n\r\n // Validate full state\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n // Find errors for this specific path\r\n const pathErrors = errors.filter((error: any) => {\r\n // For array paths, we need to translate indices to ULIDs\r\n if (path.some((p) => p.startsWith('id:'))) {\r\n // This is an array item path like [\"id:xyz\", \"name\"]\r\n const parentPath = path[0]!.startsWith('id:')\r\n ? []\r\n : path.slice(0, -1);\r\n\r\n const arrayMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, parentPath);\r\n\r\n if (arrayMeta?.arrayKeys) {\r\n const itemKey = [stateKey, ...path.slice(0, -1)].join('.');\r\n const itemIndex = arrayMeta.arrayKeys.indexOf(itemKey);\r\n\r\n // Compare with Zod path\r\n const zodPath = [...parentPath, itemIndex, ...path.slice(-1)];\r\n const match =\r\n JSON.stringify(error.path) === JSON.stringify(zodPath);\r\n\r\n return match;\r\n }\r\n }\r\n\r\n const directMatch = JSON.stringify(error.path) === JSON.stringify(path);\r\n\r\n return directMatch;\r\n });\r\n\r\n // Update shadow metadata with validation result\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: pathErrors.map((err: any) => ({\r\n source: 'client' as const,\r\n message: err.message,\r\n severity: 'error' as const, // Hard error on blur\r\n })),\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n } else {\r\n // Validation passed\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n }\r\n forceUpdate({});\r\n }, [stateKey, path, localValue, setState]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n const stateWithInputProps = new Proxy(baseState, {\r\n get(target, prop) {\r\n if (prop === '$inputProps') {\r\n return {\r\n value: localValue ?? '',\r\n onChange: (e: any) => {\r\n debouncedUpdate(e.target.value);\r\n },\r\n // 5. Wire the new onBlur handler to the input props.\r\n onBlur: handleBlur,\r\n ref: formRefStore\r\n .getState()\r\n .getFormRef(stateKey + '.' + path.join('.')),\r\n };\r\n }\r\n\r\n return target[prop];\r\n },\r\n });\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {renderFn(stateWithInputProps)}\r\n </ValidationWrapper>\r\n );\r\n}\r\nexport function useRegisterComponent(\r\n stateKey: string,\r\n componentId: string,\r\n forceUpdate: (o: object) => void\r\n) {\r\n const fullComponentId = `${stateKey}////${componentId}`;\r\n\r\n useLayoutEffect(() => {\r\n // Call the safe, centralized function to register\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n\r\n // The cleanup now calls the safe, centralized unregister function\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]); // Dependencies are stable and correct\r\n}\r\n\r\nconst useImageLoaded = (ref: RefObject<HTMLElement>): boolean => {\r\n const [loaded, setLoaded] = useState(false);\r\n\r\n useLayoutEffect(() => {\r\n if (!ref.current) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n const images = Array.from(ref.current.querySelectorAll('img'));\r\n\r\n // If there are no images, we are \"loaded\" immediately.\r\n if (images.length === 0) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n let loadedCount = 0;\r\n const handleImageLoad = () => {\r\n loadedCount++;\r\n if (loadedCount === images.length) {\r\n setLoaded(true);\r\n }\r\n };\r\n\r\n images.forEach((image) => {\r\n if (image.complete) {\r\n handleImageLoad();\r\n } else {\r\n image.addEventListener('load', handleImageLoad);\r\n image.addEventListener('error', handleImageLoad);\r\n }\r\n });\r\n\r\n return () => {\r\n images.forEach((image) => {\r\n image.removeEventListener('load', handleImageLoad);\r\n image.removeEventListener('error', handleImageLoad);\r\n });\r\n };\r\n }, [ref.current]);\r\n\r\n return loaded;\r\n};\r\n// Components.tsx\r\n\r\n// Generic isolated component wrapper\r\nexport function IsolatedComponentWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (state: any) => React.ReactNode;\r\n}) {\r\n const [componentId] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n\r\n useEffect(() => {\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, () => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [stateKeyPathKey]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n return <>{renderFn(baseState)}</>;\r\n}\r\n"],"names":["getInitialOptions","getShadowMetadata","setShadowMetadata","getShadowValue","registerComponent","unregisterComponent","notifyPathSubscribers","subscribeToPath","getGlobalStore","ValidationWrapper","formOpts","path","stateKey","children","thisStateOpts","validationState","status","errors","err","errorMessages","warningMessages","message","primarySeverity","jsx","Fragment","React","MemoizedCogsItemWrapper","memo","ListItemWrapper","prevProps","nextProps","itemComponentId","itemPath","localIndex","arraySetter","rebuildStateShape","renderFn","forceUpdate","useState","inViewRef","inView","useInView","elementRef","useRef","imagesLoaded","useImageLoaded","hasReportedInitialHeight","fullKey","useRegisterComponent","setRefs","useCallback","element","useEffect","unsubscribe","e","newHeight","arrayPath","arrayPathKey","itemValue","itemSetter","FormElementWrapper","setState","componentId","uuidv4","stateKeyPathKey","globalStateValue","localValue","setLocalValue","isCurrentlyDebouncing","debounceTimeoutRef","isDeepEqual","newValue","debouncedUpdate","debounceTime","validationOptions","zodSchema","fullState","result","currentMeta","pathErrors","error","handleBlur","p","parentPath","arrayMeta","itemKey","itemIndex","zodPath","baseState","stateWithInputProps","target","prop","formRefStore","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image","IsolatedComponentWrapper"],"mappings":";;;;;;AAmBA,MAAM;AAAA,EACJ,mBAAAA;AAAA,EAEA,mBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EAEA,mBAAAC;AAAA,EACA,qBAAAC;AAAA,EAEA,uBAAAC;AAAA,EACA,iBAAAC;AACF,IAAIC,EAAe,SAAA;AAQZ,SAASC,GAAkB;AAAA,EAChC,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAM,EAAE,mBAAAb,GAAmB,mBAAAC,GAAmB,gBAAAE,EAAAA,IAC5CK,EAAe,SAAA,GACXM,IAAgBd,EAAkBY,CAAS,GAG3CG,IADad,EAAkBW,GAAWD,CAAI,GAChB,YAE9BK,IAASD,GAAiB,UAAU,iBAEpCE,KAAUF,GAAiB,UAAU,CAAA,GAAI,IAAI,CAACG,OAAS;AAAA,IAC3D,GAAGA;AAAA,IACH,MAAAP;AAAA,EAAA,EACA,GACIQ,IAAgBF,EACnB,OAAO,CAACC,MAAQA,EAAI,aAAa,OAAO,EACxC,IAAI,CAACA,MAAQA,EAAI,OAAO,GACrBE,IAAkBH,EACrB,OAAO,CAACC,MAAQA,EAAI,aAAa,SAAS,EAC1C,IAAI,CAACA,MAAQA,EAAI,OAAO,GAGrBG,IAAUF,EAAc,CAAC,KAAKC,EAAgB,CAAC,GAC/CE,IACJH,EAAc,SAAS,IACnB,UACAC,EAAgB,SAAS,IACvB,YACA;AACR,SACE,gBAAAG,EAAAC,GAAA,EACG,UAAAV,GAAe,cAAc,cAC9B,CAACJ,GAAU,YAAY,UACrBI,EAAc,aAAc,WAAY;AAAA,IACtC,4BACGW,EAAM,UAAN,EAAsC,UAAAZ,KAAlBF,EAAK,UAAsB;AAAA,IAElD,QAAAK;AAAA;AAAA,IACA,SAASN,GAAU,YAAY,cAC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AAA,EAAM,oBAAoB,QAAQD,CAAe,GACjDC,EAAM,oBAAoB,SAASD,CAAe;AAAA,MACpD,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAACL,EAAI,OAAO,CAAC,GAETC;AACT;AAIO,SAASM,GAAyB;AAAA,EACvC,UAAA1F;AAAA,EACA,MAAAD;AAAA,EACA,mBAAAwB;AAAA,EACA,UAAAC;AACF,GASG;AACD,QAAM,CAAC0B,CAAW,IAAIxB,EAAS,MAAMyB,GAAQ,GACvC,GAAG1B,CAAW,IAAIC,EAAS,EAAE,GAE7B0B,IAAkB,CAACpD,GAAU,GAAGD,CAAI,EAAE,KAAK,GAAG;AACpD,EAAAqC,EAAqBpC,GAAUkD,GAAazB,CAAW,GAEvDe,EAAU,MAAM;AACd,UAAMC,IAAc7C,EACjB,SAAA,EACA,gBAAgBwD,GAAiB,MAAM;AACtC,MAAA3B,EAAY,CAAA,CAAE;AAAA,IAChB,CAAC;AACH,WAAO,MAAMgB,EAAA;AAAA,EACf,GAAG,CAACW,CAAe,CAAC;AAEpB,QAAMwB,IAAYrD,EAAkB;AAAA,IAClC,MAAAxB;AAAA,IACA,aAAAmD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,SAAO,gBAAAvC,EAAAC,GAAA,EAAG,UAAAY,EAASoD,CAAS,GAAE;AAChC;"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { $cogsSignal as r, addStateOptions as o, createCogsState as a, createCogsStateFromSync as s, useCogsStateFn as n } from "./CogsState.jsx";
|
|
2
|
-
import { CogsStateClient as
|
|
2
|
+
import { CogsStateClient as f, config as i, useCogsConfig as c } from "./CogsStateClient.jsx";
|
|
3
3
|
import { debounce as p, deepMerge as S, deleteNestedProperty as u, getArrayLengthDifferences as l, getArrayLengthDifferencesArray as m, getDifferences as y, getDifferencesArray as C, isArray as x, isDeepEqual as A, isFunction as D, isObject as b, transformStateFunc as F, updateNestedProperty as h } from "./utility.js";
|
|
4
4
|
import { useCogsTrpcValidationLink as N } from "./TRPCValidationLink.js";
|
|
5
|
-
import { buildShadowNode as P, formRefStore as j,
|
|
5
|
+
import { buildShadowNode as P, formRefStore as j, generateId as k, getGlobalStore as q } from "./store.js";
|
|
6
6
|
export {
|
|
7
7
|
r as $cogsSignal,
|
|
8
|
-
|
|
8
|
+
f as CogsStateClient,
|
|
9
9
|
o as addStateOptions,
|
|
10
10
|
P as buildShadowNode,
|
|
11
11
|
i as config,
|
|
@@ -15,11 +15,12 @@ export {
|
|
|
15
15
|
S as deepMerge,
|
|
16
16
|
u as deleteNestedProperty,
|
|
17
17
|
j as formRefStore,
|
|
18
|
+
k as generateId,
|
|
18
19
|
l as getArrayLengthDifferences,
|
|
19
20
|
m as getArrayLengthDifferencesArray,
|
|
20
21
|
y as getDifferences,
|
|
21
22
|
C as getDifferencesArray,
|
|
22
|
-
|
|
23
|
+
q as getGlobalStore,
|
|
23
24
|
x as isArray,
|
|
24
25
|
A as isDeepEqual,
|
|
25
26
|
D as isFunction,
|
package/dist/store.d.ts
CHANGED
|
@@ -31,10 +31,11 @@ export type ComponentsType = {
|
|
|
31
31
|
}>;
|
|
32
32
|
};
|
|
33
33
|
export type ValidationStatus = 'NOT_VALIDATED' | 'VALIDATING' | 'VALID' | 'INVALID';
|
|
34
|
+
export type ValidationSeverity = 'warning' | 'error' | undefined;
|
|
34
35
|
export type ValidationError = {
|
|
35
36
|
source: 'client' | 'sync_engine' | 'api';
|
|
36
37
|
message: string;
|
|
37
|
-
severity:
|
|
38
|
+
severity: ValidationSeverity;
|
|
38
39
|
code?: string;
|
|
39
40
|
};
|
|
40
41
|
export type ValidationState = {
|
|
@@ -149,6 +150,7 @@ export type CogsGlobalState = {
|
|
|
149
150
|
getSyncInfo: (key: string) => SyncInfo | null;
|
|
150
151
|
};
|
|
151
152
|
export declare function buildShadowNode(value: any): ShadowNode;
|
|
153
|
+
export declare function generateId(prefix?: string): string;
|
|
152
154
|
export declare const getGlobalStore: import('zustand').UseBoundStore<import('zustand').StoreApi<CogsGlobalState>>;
|
|
153
155
|
export {};
|
|
154
156
|
//# sourceMappingURL=store.d.ts.map
|