cogsbox-state 0.5.471 → 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 (46) hide show
  1. package/README.md +2 -5
  2. package/dist/CogsState.d.ts +105 -79
  3. package/dist/CogsState.d.ts.map +1 -1
  4. package/dist/CogsState.jsx +1082 -987
  5. package/dist/CogsState.jsx.map +1 -1
  6. package/dist/Components.d.ts.map +1 -1
  7. package/dist/Components.jsx +293 -243
  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 +128 -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 +43 -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 +1326 -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 +69 -26
  26. package/dist/store.d.ts.map +1 -1
  27. package/dist/store.js +436 -152
  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 +18 -13
  38. package/src/CogsState.tsx +719 -458
  39. package/src/Components.tsx +304 -180
  40. package/src/PluginRunner.tsx +208 -0
  41. package/src/index.ts +2 -0
  42. package/src/pluginStore.ts +159 -0
  43. package/src/plugins.ts +548 -0
  44. package/src/store.ts +881 -189
  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,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,304 +1,354 @@
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
- import { isDeepEqual as Y } 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: Z,
9
- getShadowMetadata: H,
10
- setShadowMetadata: I,
11
- getShadowValue: R,
12
- registerComponent: K,
13
- unregisterComponent: ee,
14
- notifyPathSubscribers: te,
15
- subscribeToPath: re
16
- } = b.getState();
17
- function ne({
18
- formOpts: e,
19
- path: t,
20
- stateKey: n,
21
- children: o
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({
21
+ formOpts: t,
22
+ path: e,
23
+ stateKey: o,
24
+ children: i
22
25
  }) {
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
- path: t
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,
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,
28
+ path: e
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: e?.validation?.hideMessage ? "" : e?.validation?.message || L || "",
32
- severity: V,
33
- hasErrors: u.length > 0,
34
- hasWarnings: c.length > 0,
35
- allErrors: v,
36
- path: t,
37
- getData: () => a(n, t)
38
- }) : /* @__PURE__ */ w(U.Fragment, { children: o }, t.toString()) });
34
+ message: t?.validation?.hideMessage ? "" : t?.validation?.message || M || "",
35
+ severity: S,
36
+ hasErrors: d.length > 0,
37
+ hasWarnings: a.length > 0,
38
+ allErrors: g,
39
+ path: e,
40
+ getData: () => r(o, e)
41
+ }) : /* @__PURE__ */ A(U.Fragment, { children: i }, e.toString()) });
39
42
  }
40
- const me = _(
41
- oe,
42
- (e, t) => e.itemPath.join(".") === t.itemPath.join(".") && e.stateKey === t.stateKey && e.itemComponentId === t.itemComponentId && e.localIndex === t.localIndex
43
+ const Mt = _(
44
+ ct,
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 oe({
45
- stateKey: e,
46
- itemComponentId: t,
47
- itemPath: n,
48
- localIndex: o,
47
+ function ct({
48
+ stateKey: t,
49
+ itemComponentId: e,
50
+ itemPath: o,
51
+ localIndex: i,
49
52
  arraySetter: l,
50
53
  rebuildStateShape: s,
51
- renderFn: a
54
+ renderFn: r
52
55
  }) {
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(
56
- (r) => {
57
- i.current = r, h(r);
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
- [h]
62
+ [m]
60
63
  );
61
- C(() => {
62
- const r = re(c, (g) => {
64
+ R(() => {
65
+ const h = it(a, (H) => {
63
66
  f({});
64
67
  });
65
- return () => r();
66
- }, [c]), C(() => {
67
- if (!m || !v || u.current)
68
+ return () => h();
69
+ }, [a]), R(() => {
70
+ if (!T || !g || d.current)
68
71
  return;
69
- const r = i.current;
70
- if (r && r.offsetHeight > 0) {
71
- u.current = !0;
72
- const g = r.offsetHeight;
73
- I(e, 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: g,
76
- domRef: r
78
+ itemHeight: H,
79
+ domRef: h
77
80
  }
78
81
  });
79
- const S = n.slice(0, -1), D = [e, ...S].join(".");
80
- te(D, {
82
+ const F = o.slice(0, -1), N = [t, ...F].join(".");
83
+ rt(N, {
81
84
  type: "ITEMHEIGHT",
82
- itemKey: n.join("."),
83
- ref: i.current
85
+ itemKey: o.join("."),
86
+ ref: w.current
84
87
  });
85
88
  }
86
- }, [m, v, e, n]);
87
- const V = R(e, n);
88
- if (V === void 0)
89
+ }, [T, g, t, o]);
90
+ const S = z(t, o);
91
+ if (S === void 0)
89
92
  return null;
90
- const d = s({
91
- currentState: V,
92
- path: n,
93
- componentId: t
94
- }), z = a(d, o, l);
95
- return /* @__PURE__ */ w("div", { ref: L, children: z });
93
+ const c = s({
94
+ currentState: S,
95
+ path: o,
96
+ componentId: e
97
+ }), D = r(c, i, l);
98
+ return /* @__PURE__ */ A("div", { ref: M, children: D });
96
99
  }
97
- function ge({
98
- stateKey: e,
99
- path: t,
100
- rebuildStateShape: n,
101
- renderFn: o,
100
+ function Tt({
101
+ stateKey: t,
102
+ path: e,
103
+ rebuildStateShape: o,
104
+ renderFn: i,
102
105
  formOpts: l,
103
106
  setState: s
104
107
  }) {
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({});
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(), c.current && (clearTimeout(c.current), u.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 L = J(
119
- (r) => {
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;
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));
159
+ }
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);
171
+ const b = l?.debounceTime ?? 200;
122
172
  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;
125
- if (N) {
126
- const E = R(e, []), y = N.safeParse(E), O = H(e, t) || {};
127
- if (y.success)
128
- I(e, t, {
129
- ...O,
130
- validation: {
131
- status: "VALID",
132
- errors: [],
133
- lastValidated: Date.now(),
134
- validatedValue: r
135
- }
136
- });
137
- else {
138
- const W = ("issues" in y.error ? y.error.issues : y.error.errors).filter(
139
- (T) => JSON.stringify(T.path) === JSON.stringify(t)
140
- );
141
- W.length > 0 ? I(e, t, {
142
- ...O,
143
- validation: {
144
- status: "INVALID",
145
- errors: [
146
- {
147
- source: "client",
148
- message: W[0]?.message,
149
- severity: "warning"
150
- // Gentle error during typing
151
- }
152
- ],
153
- lastValidated: Date.now(),
154
- validatedValue: r
155
- }
156
- }) : I(e, t, {
157
- ...O,
158
- validation: {
159
- status: "VALID",
160
- errors: [],
161
- lastValidated: Date.now(),
162
- validatedValue: r
163
- }
164
- });
165
- }
166
- }
167
- }, S), f({});
173
+ S.current = !1, s(n, e, {
174
+ updateType: "update",
175
+ validationTrigger: "onChange"
176
+ });
177
+ }, b);
168
178
  },
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,
177
- validation: {
178
- status: "VALIDATING",
179
- errors: [],
180
- lastValidated: Date.now(),
181
- validatedValue: i
182
- }
183
- });
184
- const N = R(e, []), E = D.safeParse(N);
185
- if (E.success)
186
- I(e, t, {
187
- ...M,
188
- validation: {
189
- status: "VALID",
190
- errors: [],
191
- lastValidated: Date.now(),
192
- validatedValue: i
193
- }
194
- });
195
- else {
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);
202
- }
203
- }
204
- return JSON.stringify(A.path) === JSON.stringify(t);
205
- });
206
- I(e, t, {
207
- ...M,
208
- validation: {
209
- status: "INVALID",
210
- errors: O.map((A) => ({
211
- source: "client",
212
- message: A.message,
213
- severity: "error"
214
- // Hard error on blur
215
- })),
216
- lastValidated: Date.now(),
217
- validatedValue: i
179
+ [
180
+ s,
181
+ e,
182
+ l?.debounceTime,
183
+ g,
184
+ d,
185
+ t,
186
+ r
187
+ ]
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
218
198
  }
219
- });
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);
220
217
  }
221
- f({});
222
- }, [e, t, i, s]), d = n({
223
- path: t,
224
- componentId: a,
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({
230
+ path: e,
231
+ componentId: r,
225
232
  meta: void 0
226
- }), z = new Proxy(d, {
227
- get(r, g) {
228
- return g === "$inputProps" ? {
229
- value: i ?? "",
230
- onChange: (S) => {
231
- L(S.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);
232
239
  },
233
- // 5. Wire the new onBlur handler to the input props.
234
- onBlur: V,
235
- ref: Q.getState().getFormRef(e + "." + t.join("."))
236
- } : r[g];
240
+ onFocus: H,
241
+ onBlur: F,
242
+ ref: m
243
+ } : n[p];
237
244
  }
238
- });
239
- return /* @__PURE__ */ w(ne, { formOpts: l, path: t, stateKey: e, children: o(z) });
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 });
240
259
  }
241
- function F(e, t, n) {
242
- const o = `${e}////${t}`;
243
- B(() => (K(e, o, {
244
- forceUpdate: () => n({}),
260
+ function P(t, e, o) {
261
+ const i = `${t}////${e}`;
262
+ $(() => (nt(t, i, {
263
+ forceUpdate: () => o({}),
245
264
  paths: /* @__PURE__ */ new Set(),
246
265
  reactiveType: ["component"]
247
266
  }), () => {
248
- ee(e, o);
249
- }), [e, o]);
267
+ ot(t, i);
268
+ }), [t, i]);
250
269
  }
251
- const se = (e) => {
252
- const [t, n] = p(!1);
253
- return B(() => {
254
- if (!e.current) {
255
- n(!0);
270
+ const st = (t) => {
271
+ const [e, o] = E(!1);
272
+ return $(() => {
273
+ if (!t.current) {
274
+ o(!0);
256
275
  return;
257
276
  }
258
- const o = Array.from(e.current.querySelectorAll("img"));
259
- if (o.length === 0) {
260
- n(!0);
277
+ const i = Array.from(t.current.querySelectorAll("img"));
278
+ if (i.length === 0) {
279
+ o(!0);
261
280
  return;
262
281
  }
263
282
  let l = 0;
264
283
  const s = () => {
265
- l++, l === o.length && n(!0);
284
+ l++, l === i.length && o(!0);
266
285
  };
267
- return o.forEach((a) => {
268
- a.complete ? s() : (a.addEventListener("load", s), a.addEventListener("error", s));
286
+ return i.forEach((r) => {
287
+ r.complete ? s() : (r.addEventListener("load", s), r.addEventListener("error", s));
269
288
  }), () => {
270
- o.forEach((a) => {
271
- a.removeEventListener("load", s), a.removeEventListener("error", s);
289
+ i.forEach((r) => {
290
+ r.removeEventListener("load", s), r.removeEventListener("error", s);
272
291
  });
273
292
  };
274
- }, [e.current]), t;
293
+ }, [t.current]), e;
275
294
  };
276
- function ve({
277
- stateKey: e,
278
- path: t,
279
- rebuildStateShape: n,
280
- renderFn: o
295
+ function wt({
296
+ stateKey: t,
297
+ path: e,
298
+ rebuildStateShape: o,
299
+ renderFn: i
281
300
  }) {
282
- const [l] = p(() => G()), [, s] = p({}), a = [e, ...t].join(".");
283
- F(e, l, s), C(() => {
284
- const h = b.getState().subscribeToPath(a, () => {
301
+ const [l] = E(() => q()), [, s] = E({}), r = [t, ...e].join(".");
302
+ P(t, l, s), R(() => {
303
+ const m = v.getState().subscribeToPath(r, () => {
285
304
  s({});
286
305
  });
287
- return () => h();
288
- }, [a]);
289
- const f = n({
290
- path: t,
306
+ return () => m();
307
+ }, [r]);
308
+ const f = o({
309
+ path: e,
291
310
  componentId: l,
292
311
  meta: void 0
293
312
  });
294
- return /* @__PURE__ */ w(x, { children: o(f) });
313
+ return /* @__PURE__ */ A(O, { children: i(f) });
295
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
+ });
296
346
  export {
297
- ge as FormElementWrapper,
298
- ve as IsolatedComponentWrapper,
299
- oe as ListItemWrapper,
300
- me as MemoizedCogsItemWrapper,
301
- ne as ValidationWrapper,
302
- F 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
303
353
  };
304
354
  //# sourceMappingURL=Components.jsx.map