cogsbox-state 0.5.472 → 0.5.474

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.
Files changed (46) hide show
  1. package/README.md +48 -18
  2. package/dist/CogsState.d.ts +98 -82
  3. package/dist/CogsState.d.ts.map +1 -1
  4. package/dist/CogsState.jsx +1030 -960
  5. package/dist/CogsState.jsx.map +1 -1
  6. package/dist/Components.d.ts.map +1 -1
  7. package/dist/Components.jsx +299 -219
  8. package/dist/Components.jsx.map +1 -1
  9. package/dist/PluginRunner.d.ts +10 -0
  10. package/dist/PluginRunner.d.ts.map +1 -0
  11. package/dist/PluginRunner.jsx +122 -0
  12. package/dist/PluginRunner.jsx.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +33 -26
  16. package/dist/index.js.map +1 -1
  17. package/dist/pluginStore.d.ts +81 -0
  18. package/dist/pluginStore.d.ts.map +1 -0
  19. package/dist/pluginStore.js +52 -0
  20. package/dist/pluginStore.js.map +1 -0
  21. package/dist/plugins.d.ts +1323 -0
  22. package/dist/plugins.d.ts.map +1 -0
  23. package/dist/plugins.js +76 -0
  24. package/dist/plugins.js.map +1 -0
  25. package/dist/store.d.ts +50 -15
  26. package/dist/store.d.ts.map +1 -1
  27. package/dist/store.js +509 -470
  28. package/dist/store.js.map +1 -1
  29. package/dist/utility.d.ts +1 -1
  30. package/dist/utility.d.ts.map +1 -1
  31. package/dist/utility.js +12 -12
  32. package/dist/utility.js.map +1 -1
  33. package/dist/validation.d.ts +7 -0
  34. package/dist/validation.d.ts.map +1 -0
  35. package/dist/validation.js +39 -0
  36. package/dist/validation.js.map +1 -0
  37. package/package.json +13 -3
  38. package/src/CogsState.tsx +657 -457
  39. package/src/Components.tsx +291 -194
  40. package/src/PluginRunner.tsx +203 -0
  41. package/src/index.ts +2 -0
  42. package/src/pluginStore.ts +176 -0
  43. package/src/plugins.ts +544 -0
  44. package/src/store.ts +748 -493
  45. package/src/utility.ts +31 -31
  46. package/src/validation.ts +84 -0
@@ -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,OAAO,KAQN,MAAM,OAAO,CAAC;AAuBf,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,QAAQ,GACT,EAAE,sBAAsB,2CAqDxB;AACD,eAAO,MAAM,uBAAuB,mDAWnC,CAAC;AACF,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,GAAG,CAAC;IAEjB,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAC3B,YAAY,EAAE,GAAG,CAAC;QAClB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,CAAC;KACZ,KAAK,GAAG,CAAC;IACV,QAAQ,EAAE,CACR,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,MAAM,EAEb,WAAW,EAAE,GAAG,KACb,KAAK,CAAC,SAAS,CAAC;CACtB,kDAkEA;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,IA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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,2CA2UA;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"}
@@ -1,295 +1,375 @@
1
- import { jsx as N, Fragment as X } from "react/jsx-runtime";
2
- import Q, { memo as ne, useState as R, useRef as D, useCallback as z, useEffect as w, useLayoutEffect as Y } from "react";
3
- import { getGlobalStore as y, formRefStore as oe } from "./store.js";
4
- import { useInView as se } from "react-intersection-observer";
5
- import { v4 as Z } from "uuid";
6
- import { isDeepEqual as ie } from "./utility.js";
1
+ import { jsx as I, Fragment as x } from "react/jsx-runtime";
2
+ import { pluginStore as E } from "./pluginStore.js";
3
+ import { createMetadataContext as X, toDeconstructedMethods as Y } from "./plugins.js";
4
+ import U, { memo as _, useState as C, useRef as D, useCallback as j, useEffect as L, useLayoutEffect as $, useMemo as Z } from "react";
5
+ import { getGlobalStore as b } from "./store.js";
6
+ import { useInView as V } from "react-intersection-observer";
7
+ import { v4 as q } from "uuid";
8
+ import { isDeepEqual as K } from "./utility.js";
9
+ import { runValidation as B } from "./validation.js";
7
10
  const {
8
- getInitialOptions: ae,
9
- getShadowMetadata: ce,
10
- setShadowMetadata: U,
11
- getShadowValue: x,
12
- registerComponent: le,
13
- unregisterComponent: ue,
14
- notifyPathSubscribers: de,
15
- subscribeToPath: fe
16
- } = y.getState();
17
- function ge({
11
+ getInitialOptions: tt,
12
+ getShadowMetadata: yt,
13
+ setShadowMetadata: et,
14
+ getShadowValue: z,
15
+ registerComponent: nt,
16
+ unregisterComponent: ot,
17
+ notifyPathSubscribers: rt,
18
+ subscribeToPath: it
19
+ } = b.getState(), { stateHandlers: bt, notifyFormUpdate: P } = E.getState();
20
+ function at({
18
21
  formOpts: t,
19
22
  path: e,
20
- stateKey: n,
21
- children: s
23
+ stateKey: r,
24
+ children: i
22
25
  }) {
23
- const { getInitialOptions: l, getShadowMetadata: i, getShadowValue: a } = y.getState(), f = l(n), T = i(n, e)?.validation, c = T?.status || "NOT_VALIDATED", g = (T?.errors || []).map((o) => ({
24
- ...o,
26
+ const { getInitialOptions: l, getShadowMetadata: c, getShadowValue: o } = b.getState(), m = l(r), w = c(r, e)?.validation, A = w?.status || "NOT_VALIDATED", g = (w?.errors || []).map((a) => ({
27
+ ...a,
25
28
  path: e
26
- })), u = g.filter((o) => o.severity === "error").map((o) => o.message), d = g.filter((o) => o.severity === "warning").map((o) => o.message), E = u[0] || d[0], m = u.length > 0 ? "error" : d.length > 0 ? "warning" : void 0;
27
- return /* @__PURE__ */ N(X, { children: f?.formElements?.validation && !t?.validation?.disable ? f.formElements.validation({
28
- children: /* @__PURE__ */ N(Q.Fragment, { children: s }, e.toString()),
29
- status: c,
29
+ })), d = g.filter((a) => a.severity === "error").map((a) => a.message), s = g.filter((a) => a.severity === "warning").map((a) => a.message), M = d[0] || s[0], h = d.length > 0 ? "error" : s.length > 0 ? "warning" : void 0;
30
+ return /* @__PURE__ */ I(x, { children: m?.formElements?.validation && !t?.validation?.disable ? m.formElements.validation({
31
+ children: /* @__PURE__ */ I(U.Fragment, { children: i }, e.toString()),
32
+ status: A,
30
33
  // Now passes the new ValidationStatus type
31
- message: t?.validation?.hideMessage ? "" : t?.validation?.message || E || "",
32
- severity: m,
33
- hasErrors: u.length > 0,
34
- hasWarnings: d.length > 0,
34
+ message: t?.validation?.hideMessage ? "" : t?.validation?.message || M || "",
35
+ severity: h,
36
+ hasErrors: d.length > 0,
37
+ hasWarnings: s.length > 0,
35
38
  allErrors: g,
36
39
  path: e,
37
- getData: () => a(n, e)
38
- }) : /* @__PURE__ */ N(Q.Fragment, { children: s }, e.toString()) });
40
+ getData: () => o(r, e)
41
+ }) : /* @__PURE__ */ I(U.Fragment, { children: i }, e.toString()) });
39
42
  }
40
- const Te = ne(
41
- me,
43
+ const Tt = _(
44
+ ct,
42
45
  (t, e) => t.itemPath.join(".") === e.itemPath.join(".") && t.stateKey === e.stateKey && t.itemComponentId === e.itemComponentId && t.localIndex === e.localIndex
43
46
  );
44
- function me({
47
+ function ct({
45
48
  stateKey: t,
46
49
  itemComponentId: e,
47
- itemPath: n,
48
- localIndex: s,
50
+ itemPath: r,
51
+ localIndex: i,
49
52
  arraySetter: l,
50
- rebuildStateShape: i,
51
- renderFn: a
53
+ rebuildStateShape: c,
54
+ renderFn: o
52
55
  }) {
53
- const [, f] = R({}), { ref: I, inView: T } = se(), c = D(null), g = Se(c), u = D(!1), d = [t, ...n].join(".");
54
- $(t, e, f);
55
- const E = z(
56
- (S) => {
57
- c.current = S, I(S);
56
+ const [, m] = C({}), { ref: f, inView: w } = V(), A = D(null), g = st(A), d = D(!1), s = [t, ...r].join(".");
57
+ O(t, e, m);
58
+ const M = j(
59
+ (T) => {
60
+ A.current = T, f(T);
58
61
  },
59
- [I]
62
+ [f]
60
63
  );
61
- w(() => {
62
- const S = fe(d, (O) => {
63
- f({});
64
+ L(() => {
65
+ const T = it(s, (W) => {
66
+ m({});
64
67
  });
65
- return () => S();
66
- }, [d]), w(() => {
67
- if (!T || !g || u.current)
68
+ return () => T();
69
+ }, [s]), L(() => {
70
+ if (!w || !g || d.current)
68
71
  return;
69
- const S = c.current;
70
- if (S && S.offsetHeight > 0) {
71
- u.current = !0;
72
- const O = S.offsetHeight;
73
- U(t, n, {
72
+ const T = A.current;
73
+ if (T && T.offsetHeight > 0) {
74
+ d.current = !0;
75
+ const W = T.offsetHeight;
76
+ et(t, r, {
74
77
  virtualizer: {
75
- itemHeight: O,
76
- domRef: S
78
+ itemHeight: W,
79
+ domRef: T
77
80
  }
78
81
  });
79
- const B = n.slice(0, -1), F = [t, ...B].join(".");
80
- de(F, {
82
+ const F = r.slice(0, -1), N = [t, ...F].join(".");
83
+ rt(N, {
81
84
  type: "ITEMHEIGHT",
82
- itemKey: n.join("."),
83
- ref: c.current
85
+ itemKey: r.join("."),
86
+ ref: A.current
84
87
  });
85
88
  }
86
- }, [T, g, t, n]);
87
- const m = x(t, n);
88
- if (m === void 0)
89
+ }, [w, g, t, r]);
90
+ const h = z(t, r);
91
+ if (h === void 0)
89
92
  return null;
90
- const o = i({
91
- currentState: m,
92
- path: n,
93
+ const a = c({
94
+ currentState: h,
95
+ path: r,
93
96
  componentId: e
94
- }), M = a(o, s, l);
95
- return /* @__PURE__ */ N("div", { ref: E, children: M });
97
+ }), R = o(a, i, l);
98
+ return /* @__PURE__ */ I("div", { ref: M, children: R });
96
99
  }
97
- function Ee({
100
+ function Mt({
98
101
  stateKey: t,
99
102
  path: e,
100
- rebuildStateShape: n,
101
- renderFn: s,
103
+ rebuildStateShape: r,
104
+ renderFn: i,
102
105
  formOpts: l,
103
- setState: i
106
+ setState: c
104
107
  }) {
105
- const a = D(Z()).current, [, f] = R({}), I = [t, ...e].join(".");
106
- $(t, a, f);
107
- const c = y.getState().getShadowNode(t, e)?._meta?.typeInfo, g = c?.schema, u = x(t, e), [d, E] = R(u), m = D(!1), o = D(null);
108
- w(() => {
109
- !m.current && !ie(u, d) && E(u);
110
- }, [u]), w(() => {
111
- const r = y.getState().subscribeToPath(I, (b) => {
112
- !m.current && d !== b && f({});
108
+ const o = D(q()).current, [, m] = C({}), f = D(null), w = [t, ...e].join(".");
109
+ O(t, o, m);
110
+ const g = b.getState().getShadowNode(t, e)?._meta?.typeInfo, d = z(t, e), [s, M] = C(d), h = D(!1), a = D(null), R = Z(() => E.getState().getPluginConfigsForState(t).filter((n) => typeof n.plugin.formWrapper == "function"), [t]);
111
+ L(() => {
112
+ !h.current && !K(d, s) && M(d);
113
+ }, [d]), L(() => {
114
+ const { getShadowMetadata: n, setShadowMetadata: p } = b.getState(), u = n(t, e) || {};
115
+ u.clientActivityState || (u.clientActivityState = { elements: /* @__PURE__ */ new Map() });
116
+ const S = () => {
117
+ const v = f.current;
118
+ if (!v) return "input";
119
+ const k = v.tagName.toLowerCase();
120
+ if (k === "textarea") return "textarea";
121
+ if (k === "select") return "select";
122
+ if (k === "input") {
123
+ const y = v.type;
124
+ if (y === "checkbox") return "checkbox";
125
+ if (y === "radio") return "radio";
126
+ if (y === "range") return "range";
127
+ if (y === "file") return "file";
128
+ }
129
+ return "input";
130
+ };
131
+ u.clientActivityState.elements.set(o, {
132
+ domRef: f,
133
+ elementType: S(),
134
+ inputType: f.current?.type,
135
+ mountedAt: Date.now()
136
+ }), p(t, e, u);
137
+ const H = b.getState().subscribeToPath(w, (v) => {
138
+ !h.current && s !== v && m({});
113
139
  });
114
140
  return () => {
115
- r(), o.current && (clearTimeout(o.current), m.current = !1);
141
+ H(), a.current && (clearTimeout(a.current), h.current = !1);
142
+ const v = b.getState().getShadowMetadata(t, e);
143
+ v?.clientActivityState?.elements && (v.clientActivityState.elements.delete(o), p(t, e, v));
116
144
  };
117
145
  }, []);
118
- const M = z(
119
- (r, b) => {
120
- if (!y.getState().getShadowMetadata(t, [])?.features?.validationEnabled) return;
121
- const h = ae(t)?.validation;
122
- if (!h) return;
123
- const V = ce(t, e) || {}, K = V?.validation?.status;
124
- let C = !1, W;
125
- if (console.log("trigger", b, h), b === "onBlur" && h.onBlur ? (C = !0, W = h.onBlur ?? "error") : b === "onChange" && (h.onChange ? (C = !0, W = h.onChange) : K === "INVALID" && (C = !0, W = "warning")), !C) return;
126
- let v = null;
127
- if (console.log(
128
- "shouldValidate 33",
129
- e,
130
- g,
131
- C,
132
- r,
133
- typeof r
134
- ), g && C) {
135
- const p = g.safeParse(r);
136
- p.success ? v = { success: !0 } : v = {
137
- success: !1,
138
- message: ("issues" in p.error ? p.error.issues : p.error.errors)[0]?.message || "Invalid value"
139
- };
140
- } else {
141
- const p = h.zodSchemaV4 || h.zodSchemaV3;
142
- if (!p) return;
143
- const q = x(t, []), P = JSON.parse(JSON.stringify(q));
144
- let j = P;
145
- for (let L = 0; L < e.length - 1; L++)
146
- j[e[L]] || (j[e[L]] = {}), j = j[e[L]];
147
- e.length > 0 ? j[e[e.length - 1]] = r : Object.assign(P, r);
148
- const A = p.safeParse(P);
149
- if (A.success)
150
- v = { success: !0 };
151
- else {
152
- const G = ("issues" in A.error ? A.error.issues : A.error.errors).filter((_) => {
153
- if (e.some((H) => H.startsWith("id:"))) {
154
- const H = e[0].startsWith("id:") ? [] : e.slice(0, -1), k = y.getState().getShadowMetadata(t, H);
155
- if (k?.arrayKeys) {
156
- e.slice(0, -1).join(".");
157
- const ee = k.arrayKeys.findIndex(
158
- (re) => re === e[e.length - 2]
159
- ), te = [...H, ee, ...e.slice(-1)];
160
- return JSON.stringify(_.path) === JSON.stringify(te);
161
- }
162
- }
163
- return JSON.stringify(_.path) === JSON.stringify(e);
164
- });
165
- G.length > 0 ? v = {
166
- success: !1,
167
- message: G[0]?.message
168
- } : v = { success: !0 };
169
- }
146
+ const T = j(
147
+ (n) => {
148
+ g ? g.type === "number" && typeof n == "string" ? n = n === "" ? g.nullable ? null : g.default ?? 0 : Number(n) : g.type === "boolean" && typeof n == "string" ? n = n === "true" || n === "1" : g.type === "date" && typeof n == "string" && (n = new Date(n)) : typeof d === "number" && typeof n == "string" && (n = n === "" ? 0 : Number(n)), M(n);
149
+ const { getShadowMetadata: p, setShadowMetadata: u } = b.getState(), S = p(t, e);
150
+ if (S?.clientActivityState?.elements?.has(o)) {
151
+ const y = S.clientActivityState.elements.get(o);
152
+ y && y.currentActivity?.type === "focus" && (y.currentActivity.details = {
153
+ ...y.currentActivity.details,
154
+ value: n,
155
+ previousValue: y.currentActivity.details?.value || d,
156
+ inputLength: typeof n == "string" ? n.length : void 0,
157
+ keystrokeCount: (y.currentActivity.details?.keystrokeCount || 0) + 1
158
+ }, u(t, e, S));
170
159
  }
171
- v && (v.success ? U(t, e, {
172
- ...V,
173
- validation: {
174
- status: "VALID",
175
- errors: [],
176
- lastValidated: Date.now(),
177
- validatedValue: r
160
+ const H = S?.clientActivityState?.elements?.get(o);
161
+ P({
162
+ stateKey: t,
163
+ activityType: "input",
164
+ // Changed from 'type'
165
+ path: e,
166
+ timestamp: Date.now(),
167
+ details: {
168
+ value: n,
169
+ inputLength: typeof n == "string" ? n.length : void 0,
170
+ isComposing: !1,
171
+ // You'd need to track this from the actual input event
172
+ isPasting: !1,
173
+ // You'd need to track this from paste events
174
+ keystrokeCount: (H?.currentActivity?.details?.keystrokeCount || 0) + 1
178
175
  }
179
- }) : U(t, e, {
180
- ...V,
181
- validation: {
182
- status: "INVALID",
183
- errors: [
184
- {
185
- source: "client",
186
- message: v.message,
187
- severity: W
188
- }
189
- ],
190
- lastValidated: Date.now(),
191
- validatedValue: r
192
- }
193
- })), f({});
194
- },
195
- [t, e, g]
196
- ), S = z(
197
- (r) => {
198
- c ? c.type === "number" && typeof r == "string" ? r = r === "" ? c.nullable ? null : c.default ?? 0 : Number(r) : c.type === "boolean" && typeof r == "string" ? r = r === "true" || r === "1" : c.type === "date" && typeof r == "string" && (r = new Date(r)) : typeof u === "number" && typeof r == "string" && (r = r === "" ? 0 : Number(r)), E(r), M(r, "onChange"), m.current = !0, o.current && clearTimeout(o.current);
199
- const b = l?.debounceTime ?? 200;
200
- o.current = setTimeout(() => {
201
- m.current = !1, i(r, e, { updateType: "update" });
202
- }, b);
176
+ }), B({
177
+ stateKey: t,
178
+ path: e,
179
+ newValue: n,
180
+ updateType: "update"
181
+ }, "onChange"), h.current = !0, a.current && clearTimeout(a.current);
182
+ const k = l?.debounceTime ?? 200;
183
+ a.current = setTimeout(() => {
184
+ h.current = !1, c(n, e, {
185
+ updateType: "update",
186
+ validationTrigger: "onChange"
187
+ });
188
+ }, k);
203
189
  },
204
190
  [
205
- i,
191
+ c,
206
192
  e,
207
193
  l?.debounceTime,
208
- M,
209
- c,
210
- u
194
+ g,
195
+ d,
196
+ t,
197
+ o
211
198
  ]
212
- ), O = z(() => {
213
- o.current && (clearTimeout(o.current), o.current = null, m.current = !1, i(d, e, { updateType: "update" })), M(d, "onBlur");
214
- }, [d, i, e, M]), B = n({
199
+ ), W = j(() => {
200
+ const { getShadowMetadata: n, setShadowMetadata: p } = b.getState(), u = n(t, e);
201
+ if (u?.clientActivityState?.elements?.has(o)) {
202
+ const S = u.clientActivityState.elements.get(o);
203
+ S.currentActivity = {
204
+ type: "focus",
205
+ startTime: Date.now(),
206
+ details: {
207
+ value: s,
208
+ inputLength: typeof s == "string" ? s.length : void 0
209
+ }
210
+ }, p(t, e, u);
211
+ }
212
+ P({
213
+ stateKey: t,
214
+ activityType: "focus",
215
+ // Changed from 'type'
216
+ path: e,
217
+ timestamp: Date.now(),
218
+ details: {
219
+ cursorPosition: f.current?.selectionStart
220
+ }
221
+ });
222
+ }, [t, e, o, s]), F = j(() => {
223
+ const { getShadowMetadata: n, setShadowMetadata: p } = b.getState();
224
+ a.current && (clearTimeout(a.current), a.current = null, h.current = !1, c(s, e, {
225
+ updateType: "update",
226
+ validationTrigger: "onBlur"
227
+ }));
228
+ const u = n(t, e);
229
+ if (u?.clientActivityState?.elements?.has(o)) {
230
+ const v = u.clientActivityState.elements.get(o);
231
+ v.currentActivity = void 0, p(t, e, u);
232
+ }
233
+ const S = u?.clientActivityState?.elements?.get(o)?.currentActivity?.startTime;
234
+ P({
235
+ stateKey: t,
236
+ activityType: "blur",
237
+ // Changed from 'type'
238
+ path: e,
239
+ timestamp: Date.now(),
240
+ duration: S ? Date.now() - S : void 0,
241
+ details: {
242
+ duration: S ? Date.now() - S : 0
243
+ }
244
+ }), tt(t)?.validation?.onBlur && B({
245
+ stateKey: t,
246
+ path: e,
247
+ newValue: s,
248
+ updateType: "update"
249
+ }, "onBlur");
250
+ }, [s, c, e, t, o, d]), N = r({
215
251
  path: e,
216
- componentId: a,
252
+ componentId: o,
217
253
  meta: void 0
218
- }), F = new Proxy(B, {
219
- get(r, b) {
220
- return b === "$inputProps" ? {
221
- value: d ?? "",
222
- onChange: (J) => {
223
- S(J.target.value);
254
+ }), G = new Proxy(N, {
255
+ get(n, p) {
256
+ return p === "$inputProps" ? {
257
+ value: s ?? "",
258
+ onChange: (u) => {
259
+ T(u.target.value);
224
260
  },
225
- onBlur: O,
226
- ref: oe.getState().getFormRef(t + "." + e.join("."))
227
- } : r[b];
261
+ onFocus: W,
262
+ onBlur: F,
263
+ ref: f
264
+ } : n[p];
228
265
  }
229
- });
230
- return /* @__PURE__ */ N(ge, { formOpts: l, path: e, stateKey: t, children: s(F) });
266
+ }), J = i(G), Q = R.reduceRight(
267
+ (n, p, u) => /* @__PURE__ */ I(
268
+ ut,
269
+ {
270
+ stateKey: t,
271
+ path: e,
272
+ pluginName: p.plugin.name,
273
+ wrapperDepth: R.length - 1 - u,
274
+ children: n
275
+ }
276
+ ),
277
+ J
278
+ );
279
+ return /* @__PURE__ */ I(at, { formOpts: l, path: e, stateKey: t, children: Q });
231
280
  }
232
- function $(t, e, n) {
233
- const s = `${t}////${e}`;
234
- Y(() => (le(t, s, {
235
- forceUpdate: () => n({}),
281
+ function O(t, e, r) {
282
+ const i = `${t}////${e}`;
283
+ $(() => (nt(t, i, {
284
+ forceUpdate: () => r({}),
236
285
  paths: /* @__PURE__ */ new Set(),
237
286
  reactiveType: ["component"]
238
287
  }), () => {
239
- ue(t, s);
240
- }), [t, s]);
288
+ ot(t, i);
289
+ }), [t, i]);
241
290
  }
242
- const Se = (t) => {
243
- const [e, n] = R(!1);
244
- return Y(() => {
291
+ const st = (t) => {
292
+ const [e, r] = C(!1);
293
+ return $(() => {
245
294
  if (!t.current) {
246
- n(!0);
295
+ r(!0);
247
296
  return;
248
297
  }
249
- const s = Array.from(t.current.querySelectorAll("img"));
250
- if (s.length === 0) {
251
- n(!0);
298
+ const i = Array.from(t.current.querySelectorAll("img"));
299
+ if (i.length === 0) {
300
+ r(!0);
252
301
  return;
253
302
  }
254
303
  let l = 0;
255
- const i = () => {
256
- l++, l === s.length && n(!0);
304
+ const c = () => {
305
+ l++, l === i.length && r(!0);
257
306
  };
258
- return s.forEach((a) => {
259
- a.complete ? i() : (a.addEventListener("load", i), a.addEventListener("error", i));
307
+ return i.forEach((o) => {
308
+ o.complete ? c() : (o.addEventListener("load", c), o.addEventListener("error", c));
260
309
  }), () => {
261
- s.forEach((a) => {
262
- a.removeEventListener("load", i), a.removeEventListener("error", i);
310
+ i.forEach((o) => {
311
+ o.removeEventListener("load", c), o.removeEventListener("error", c);
263
312
  });
264
313
  };
265
314
  }, [t.current]), e;
266
315
  };
267
- function Me({
316
+ function wt({
268
317
  stateKey: t,
269
318
  path: e,
270
- rebuildStateShape: n,
271
- renderFn: s
319
+ rebuildStateShape: r,
320
+ renderFn: i
272
321
  }) {
273
- const [l] = R(() => Z()), [, i] = R({}), a = [t, ...e].join(".");
274
- $(t, l, i), w(() => {
275
- const I = y.getState().subscribeToPath(a, () => {
276
- i({});
322
+ const [l] = C(() => q()), [, c] = C({}), o = [t, ...e].join(".");
323
+ O(t, l, c), L(() => {
324
+ const f = b.getState().subscribeToPath(o, () => {
325
+ c({});
277
326
  });
278
- return () => I();
279
- }, [a]);
280
- const f = n({
327
+ return () => f();
328
+ }, [o]);
329
+ const m = r({
281
330
  path: e,
282
331
  componentId: l,
283
332
  meta: void 0
284
333
  });
285
- return /* @__PURE__ */ N(X, { children: s(f) });
334
+ return /* @__PURE__ */ I(x, { children: i(m) });
286
335
  }
336
+ const ut = _(function({
337
+ children: e,
338
+ stateKey: r,
339
+ path: i,
340
+ pluginName: l,
341
+ wrapperDepth: c
342
+ }) {
343
+ const [, o] = C({});
344
+ L(() => {
345
+ const M = [r, ...i].join(".");
346
+ return b.getState().subscribeToPath(M, () => {
347
+ o({});
348
+ });
349
+ }, [r, i]);
350
+ const m = E.getState().registeredPlugins.find((M) => M.name === l), f = E.getState().stateHandlers.get(r), w = b.getState().getShadowNode(r, i)?._meta?.typeInfo, A = E.getState().pluginOptions.get(r)?.get(l), g = E.getState().getHookResult(r, l);
351
+ if (!m?.formWrapper || !f)
352
+ return /* @__PURE__ */ I(x, { children: e });
353
+ const d = X(r, m.name), s = Y(f);
354
+ return m.formWrapper({
355
+ element: e,
356
+ path: i,
357
+ stateKey: r,
358
+ pluginName: m.name,
359
+ ...s,
360
+ ...d,
361
+ options: A,
362
+ hookData: g,
363
+ fieldType: w?.type,
364
+ wrapperDepth: c
365
+ });
366
+ });
287
367
  export {
288
- Ee as FormElementWrapper,
289
- Me as IsolatedComponentWrapper,
290
- me as ListItemWrapper,
291
- Te as MemoizedCogsItemWrapper,
292
- ge as ValidationWrapper,
293
- $ as useRegisterComponent
368
+ Mt as FormElementWrapper,
369
+ wt as IsolatedComponentWrapper,
370
+ ct as ListItemWrapper,
371
+ Tt as MemoizedCogsItemWrapper,
372
+ at as ValidationWrapper,
373
+ O as useRegisterComponent
294
374
  };
295
375
  //# sourceMappingURL=Components.jsx.map