cogsbox-state 0.5.472 → 0.5.473

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 (45) hide show
  1. package/dist/CogsState.d.ts +98 -82
  2. package/dist/CogsState.d.ts.map +1 -1
  3. package/dist/CogsState.jsx +1020 -950
  4. package/dist/CogsState.jsx.map +1 -1
  5. package/dist/Components.d.ts.map +1 -1
  6. package/dist/Components.jsx +276 -217
  7. package/dist/Components.jsx.map +1 -1
  8. package/dist/PluginRunner.d.ts +10 -0
  9. package/dist/PluginRunner.d.ts.map +1 -0
  10. package/dist/PluginRunner.jsx +128 -0
  11. package/dist/PluginRunner.jsx.map +1 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +33 -26
  15. package/dist/index.js.map +1 -1
  16. package/dist/pluginStore.d.ts +43 -0
  17. package/dist/pluginStore.d.ts.map +1 -0
  18. package/dist/pluginStore.js +52 -0
  19. package/dist/pluginStore.js.map +1 -0
  20. package/dist/plugins.d.ts +1326 -0
  21. package/dist/plugins.d.ts.map +1 -0
  22. package/dist/plugins.js +76 -0
  23. package/dist/plugins.js.map +1 -0
  24. package/dist/store.d.ts +50 -15
  25. package/dist/store.d.ts.map +1 -1
  26. package/dist/store.js +509 -470
  27. package/dist/store.js.map +1 -1
  28. package/dist/utility.d.ts +1 -1
  29. package/dist/utility.d.ts.map +1 -1
  30. package/dist/utility.js +12 -12
  31. package/dist/utility.js.map +1 -1
  32. package/dist/validation.d.ts +7 -0
  33. package/dist/validation.d.ts.map +1 -0
  34. package/dist/validation.js +39 -0
  35. package/dist/validation.js.map +1 -0
  36. package/package.json +13 -3
  37. package/src/CogsState.tsx +658 -457
  38. package/src/Components.tsx +272 -194
  39. package/src/PluginRunner.tsx +208 -0
  40. package/src/index.ts +2 -0
  41. package/src/pluginStore.ts +159 -0
  42. package/src/plugins.ts +548 -0
  43. package/src/store.ts +748 -493
  44. package/src/utility.ts +31 -31
  45. 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,IAAI,EACJ,iBAAiB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;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,2CAwTA;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,354 @@
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 A, Fragment as O } from "react/jsx-runtime";
2
+ import { pluginStore as C } from "./pluginStore.js";
3
+ import { createMetadataContext as X, toDeconstructedMethods as Y } from "./plugins.js";
4
+ import U, { memo as _, useState as E, useRef as L, useCallback as k, useEffect as R, useLayoutEffect as $, useMemo as Z } from "react";
5
+ import { getGlobalStore as v } 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: bt,
13
+ setShadowMetadata: et,
14
+ getShadowValue: z,
15
+ registerComponent: nt,
16
+ unregisterComponent: ot,
17
+ notifyPathSubscribers: rt,
18
+ subscribeToPath: it
19
+ } = v.getState(), { stateHandlers: yt, notifyFormUpdate: x } = C.getState();
20
+ function at({
18
21
  formOpts: t,
19
22
  path: e,
20
- stateKey: n,
21
- children: s
23
+ stateKey: o,
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: s, getShadowValue: r } = v.getState(), f = l(o), T = s(o, e)?.validation, w = T?.status || "NOT_VALIDATED", g = (T?.errors || []).map((c) => ({
27
+ ...c,
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((c) => c.severity === "error").map((c) => c.message), a = g.filter((c) => c.severity === "warning").map((c) => c.message), M = d[0] || a[0], S = d.length > 0 ? "error" : a.length > 0 ? "warning" : void 0;
30
+ return /* @__PURE__ */ A(O, { children: f?.formElements?.validation && !t?.validation?.disable ? f.formElements.validation({
31
+ children: /* @__PURE__ */ A(U.Fragment, { children: i }, e.toString()),
32
+ status: w,
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: S,
36
+ hasErrors: d.length > 0,
37
+ hasWarnings: a.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: () => r(o, e)
41
+ }) : /* @__PURE__ */ A(U.Fragment, { children: i }, e.toString()) });
39
42
  }
40
- const Te = ne(
41
- me,
43
+ const Mt = _(
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: o,
51
+ localIndex: i,
49
52
  arraySetter: l,
50
- rebuildStateShape: i,
51
- renderFn: a
53
+ rebuildStateShape: s,
54
+ renderFn: r
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 [, f] = E({}), { ref: m, inView: T } = V(), w = L(null), g = st(w), d = L(!1), a = [t, ...o].join(".");
57
+ P(t, e, f);
58
+ const M = k(
59
+ (h) => {
60
+ w.current = h, m(h);
58
61
  },
59
- [I]
62
+ [m]
60
63
  );
61
- w(() => {
62
- const S = fe(d, (O) => {
64
+ R(() => {
65
+ const h = it(a, (H) => {
63
66
  f({});
64
67
  });
65
- return () => S();
66
- }, [d]), w(() => {
67
- if (!T || !g || u.current)
68
+ return () => h();
69
+ }, [a]), R(() => {
70
+ if (!T || !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 h = w.current;
73
+ if (h && h.offsetHeight > 0) {
74
+ d.current = !0;
75
+ const H = h.offsetHeight;
76
+ et(t, o, {
74
77
  virtualizer: {
75
- itemHeight: O,
76
- domRef: S
78
+ itemHeight: H,
79
+ domRef: h
77
80
  }
78
81
  });
79
- const B = n.slice(0, -1), F = [t, ...B].join(".");
80
- de(F, {
82
+ const F = o.slice(0, -1), N = [t, ...F].join(".");
83
+ rt(N, {
81
84
  type: "ITEMHEIGHT",
82
- itemKey: n.join("."),
83
- ref: c.current
85
+ itemKey: o.join("."),
86
+ ref: w.current
84
87
  });
85
88
  }
86
- }, [T, g, t, n]);
87
- const m = x(t, n);
88
- if (m === void 0)
89
+ }, [T, g, t, o]);
90
+ const S = z(t, o);
91
+ if (S === void 0)
89
92
  return null;
90
- const o = i({
91
- currentState: m,
92
- path: n,
93
+ const c = s({
94
+ currentState: S,
95
+ path: o,
93
96
  componentId: e
94
- }), M = a(o, s, l);
95
- return /* @__PURE__ */ N("div", { ref: E, children: M });
97
+ }), D = r(c, i, l);
98
+ return /* @__PURE__ */ A("div", { ref: M, children: D });
96
99
  }
97
- function Ee({
100
+ function Tt({
98
101
  stateKey: t,
99
102
  path: e,
100
- rebuildStateShape: n,
101
- renderFn: s,
103
+ rebuildStateShape: o,
104
+ renderFn: i,
102
105
  formOpts: l,
103
- setState: i
106
+ setState: s
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 r = L(q()).current, [, f] = E({}), m = L(null), T = [t, ...e].join(".");
109
+ P(t, r, f);
110
+ const g = v.getState().getShadowNode(t, e)?._meta?.typeInfo, d = z(t, e), [a, M] = E(d), S = L(!1), c = L(null), D = Z(() => C.getState().getPluginConfigsForState(t).filter((n) => typeof n.plugin.formWrapper == "function"), [t]);
111
+ R(() => {
112
+ !S.current && !K(d, a) && M(d);
113
+ }, [d]), R(() => {
114
+ const { getShadowMetadata: n, setShadowMetadata: p } = v.getState(), u = n(t, e) || {};
115
+ u.clientActivityState || (u.clientActivityState = { elements: /* @__PURE__ */ new Map() });
116
+ const I = () => {
117
+ const b = m.current;
118
+ if (!b) return "input";
119
+ const y = b.tagName.toLowerCase();
120
+ if (y === "textarea") return "textarea";
121
+ if (y === "select") return "select";
122
+ if (y === "input") {
123
+ const j = b.type;
124
+ if (j === "checkbox") return "checkbox";
125
+ if (j === "radio") return "radio";
126
+ if (j === "range") return "range";
127
+ if (j === "file") return "file";
128
+ }
129
+ return "input";
130
+ };
131
+ u.clientActivityState.elements.set(r, {
132
+ domRef: m,
133
+ elementType: I(),
134
+ inputType: m.current?.type,
135
+ mountedAt: Date.now()
136
+ }), p(t, e, u);
137
+ const W = v.getState().subscribeToPath(T, (b) => {
138
+ !S.current && a !== b && f({});
113
139
  });
114
140
  return () => {
115
- r(), o.current && (clearTimeout(o.current), m.current = !1);
141
+ W(), c.current && (clearTimeout(c.current), S.current = !1);
142
+ const b = v.getState().getShadowMetadata(t, e);
143
+ b?.clientActivityState?.elements && (b.clientActivityState.elements.delete(r), p(t, e, b));
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 h = k(
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 } = v.getState(), I = p(t, e);
150
+ if (I?.clientActivityState?.elements?.has(r)) {
151
+ const y = I.clientActivityState.elements.get(r);
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, I));
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
178
- }
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);
160
+ x({
161
+ stateKey: t,
162
+ type: "input",
163
+ path: e,
164
+ value: n
165
+ }), B({
166
+ stateKey: t,
167
+ path: e,
168
+ newValue: n,
169
+ updateType: "update"
170
+ }, "onChange"), S.current = !0, c.current && clearTimeout(c.current);
199
171
  const b = l?.debounceTime ?? 200;
200
- o.current = setTimeout(() => {
201
- m.current = !1, i(r, e, { updateType: "update" });
172
+ c.current = setTimeout(() => {
173
+ S.current = !1, s(n, e, {
174
+ updateType: "update",
175
+ validationTrigger: "onChange"
176
+ });
202
177
  }, b);
203
178
  },
204
179
  [
205
- i,
180
+ s,
206
181
  e,
207
182
  l?.debounceTime,
208
- M,
209
- c,
210
- u
183
+ g,
184
+ d,
185
+ t,
186
+ r
211
187
  ]
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({
188
+ ), H = k(() => {
189
+ const { getShadowMetadata: n, setShadowMetadata: p } = v.getState(), u = n(t, e);
190
+ if (u?.clientActivityState?.elements?.has(r)) {
191
+ const I = u.clientActivityState.elements.get(r);
192
+ I.currentActivity = {
193
+ type: "focus",
194
+ startTime: Date.now(),
195
+ details: {
196
+ value: a,
197
+ inputLength: typeof a == "string" ? a.length : void 0
198
+ }
199
+ }, p(t, e, u);
200
+ }
201
+ x({
202
+ stateKey: t,
203
+ type: "focus",
204
+ path: e,
205
+ value: a
206
+ });
207
+ }, [t, e, r, a]), F = k(() => {
208
+ const { getShadowMetadata: n, setShadowMetadata: p } = v.getState();
209
+ c.current && (clearTimeout(c.current), c.current = null, S.current = !1, s(a, e, {
210
+ updateType: "update",
211
+ validationTrigger: "onBlur"
212
+ }));
213
+ const u = n(t, e);
214
+ if (u?.clientActivityState?.elements?.has(r)) {
215
+ const W = u.clientActivityState.elements.get(r);
216
+ W.currentActivity = void 0, p(t, e, u);
217
+ }
218
+ x({
219
+ stateKey: t,
220
+ type: "blur",
221
+ path: e,
222
+ value: a
223
+ }), tt(t)?.validation?.onBlur && B({
224
+ stateKey: t,
225
+ path: e,
226
+ newValue: a,
227
+ updateType: "update"
228
+ }, "onBlur");
229
+ }, [a, s, e, t, r, d]), N = o({
215
230
  path: e,
216
- componentId: a,
231
+ componentId: r,
217
232
  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);
233
+ }), G = new Proxy(N, {
234
+ get(n, p) {
235
+ return p === "$inputProps" ? {
236
+ value: a ?? "",
237
+ onChange: (u) => {
238
+ h(u.target.value);
224
239
  },
225
- onBlur: O,
226
- ref: oe.getState().getFormRef(t + "." + e.join("."))
227
- } : r[b];
240
+ onFocus: H,
241
+ onBlur: F,
242
+ ref: m
243
+ } : n[p];
228
244
  }
229
- });
230
- return /* @__PURE__ */ N(ge, { formOpts: l, path: e, stateKey: t, children: s(F) });
245
+ }), J = i(G), Q = D.reduceRight(
246
+ (n, p, u) => /* @__PURE__ */ A(
247
+ ut,
248
+ {
249
+ stateKey: t,
250
+ path: e,
251
+ pluginName: p.plugin.name,
252
+ wrapperDepth: D.length - 1 - u,
253
+ children: n
254
+ }
255
+ ),
256
+ J
257
+ );
258
+ return /* @__PURE__ */ A(at, { formOpts: l, path: e, stateKey: t, children: Q });
231
259
  }
232
- function $(t, e, n) {
233
- const s = `${t}////${e}`;
234
- Y(() => (le(t, s, {
235
- forceUpdate: () => n({}),
260
+ function P(t, e, o) {
261
+ const i = `${t}////${e}`;
262
+ $(() => (nt(t, i, {
263
+ forceUpdate: () => o({}),
236
264
  paths: /* @__PURE__ */ new Set(),
237
265
  reactiveType: ["component"]
238
266
  }), () => {
239
- ue(t, s);
240
- }), [t, s]);
267
+ ot(t, i);
268
+ }), [t, i]);
241
269
  }
242
- const Se = (t) => {
243
- const [e, n] = R(!1);
244
- return Y(() => {
270
+ const st = (t) => {
271
+ const [e, o] = E(!1);
272
+ return $(() => {
245
273
  if (!t.current) {
246
- n(!0);
274
+ o(!0);
247
275
  return;
248
276
  }
249
- const s = Array.from(t.current.querySelectorAll("img"));
250
- if (s.length === 0) {
251
- n(!0);
277
+ const i = Array.from(t.current.querySelectorAll("img"));
278
+ if (i.length === 0) {
279
+ o(!0);
252
280
  return;
253
281
  }
254
282
  let l = 0;
255
- const i = () => {
256
- l++, l === s.length && n(!0);
283
+ const s = () => {
284
+ l++, l === i.length && o(!0);
257
285
  };
258
- return s.forEach((a) => {
259
- a.complete ? i() : (a.addEventListener("load", i), a.addEventListener("error", i));
286
+ return i.forEach((r) => {
287
+ r.complete ? s() : (r.addEventListener("load", s), r.addEventListener("error", s));
260
288
  }), () => {
261
- s.forEach((a) => {
262
- a.removeEventListener("load", i), a.removeEventListener("error", i);
289
+ i.forEach((r) => {
290
+ r.removeEventListener("load", s), r.removeEventListener("error", s);
263
291
  });
264
292
  };
265
293
  }, [t.current]), e;
266
294
  };
267
- function Me({
295
+ function wt({
268
296
  stateKey: t,
269
297
  path: e,
270
- rebuildStateShape: n,
271
- renderFn: s
298
+ rebuildStateShape: o,
299
+ renderFn: i
272
300
  }) {
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({});
301
+ const [l] = E(() => q()), [, s] = E({}), r = [t, ...e].join(".");
302
+ P(t, l, s), R(() => {
303
+ const m = v.getState().subscribeToPath(r, () => {
304
+ s({});
277
305
  });
278
- return () => I();
279
- }, [a]);
280
- const f = n({
306
+ return () => m();
307
+ }, [r]);
308
+ const f = o({
281
309
  path: e,
282
310
  componentId: l,
283
311
  meta: void 0
284
312
  });
285
- return /* @__PURE__ */ N(X, { children: s(f) });
313
+ return /* @__PURE__ */ A(O, { children: i(f) });
286
314
  }
315
+ const ut = _(function({
316
+ children: e,
317
+ stateKey: o,
318
+ path: i,
319
+ pluginName: l,
320
+ wrapperDepth: s
321
+ }) {
322
+ const [, r] = E({});
323
+ R(() => {
324
+ const M = [o, ...i].join(".");
325
+ return v.getState().subscribeToPath(M, () => {
326
+ r({});
327
+ });
328
+ }, [o, i]);
329
+ const f = C.getState().registeredPlugins.find((M) => M.name === l), m = C.getState().stateHandlers.get(o), T = v.getState().getShadowNode(o, i)?._meta?.typeInfo, w = C.getState().pluginOptions.get(o)?.get(l), g = C.getState().getHookResult(o, l);
330
+ if (!f?.formWrapper || !m)
331
+ return /* @__PURE__ */ A(O, { children: e });
332
+ const d = X(o, f.name), a = Y(m);
333
+ return f.formWrapper({
334
+ element: e,
335
+ path: i,
336
+ stateKey: o,
337
+ pluginName: f.name,
338
+ ...a,
339
+ ...d,
340
+ options: w,
341
+ hookData: g,
342
+ fieldType: T?.type,
343
+ wrapperDepth: s
344
+ });
345
+ });
287
346
  export {
288
- Ee as FormElementWrapper,
289
- Me as IsolatedComponentWrapper,
290
- me as ListItemWrapper,
291
- Te as MemoizedCogsItemWrapper,
292
- ge as ValidationWrapper,
293
- $ as useRegisterComponent
347
+ Tt as FormElementWrapper,
348
+ wt as IsolatedComponentWrapper,
349
+ ct as ListItemWrapper,
350
+ Mt as MemoizedCogsItemWrapper,
351
+ at as ValidationWrapper,
352
+ P as useRegisterComponent
294
353
  };
295
354
  //# sourceMappingURL=Components.jsx.map