@voltro/client 0.84.0 → 0.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/analyticsCatalog.js +47 -0
- package/dist/apiConnectivity.js +33 -0
- package/dist/apiRuntime.js +135 -0
- package/dist/apiSupervisor.js +125 -0
- package/dist/authRefresh.js +20 -0
- package/dist/awaitResolvedApi.js +23 -0
- package/dist/bootstrap.d.ts +1144 -0
- package/dist/bootstrap.js +8 -0
- package/dist/cellMerger.js +6 -0
- package/dist/clientDiagnostics.js +94 -0
- package/dist/clientErrorBus.js +16 -0
- package/dist/clientScheduler.js +31 -0
- package/dist/connectionPrerequisite.js +70 -0
- package/dist/connectionScope.js +35 -0
- package/dist/connectionSetupController.js +206 -0
- package/dist/createHooks.js +15 -0
- package/dist/deepLink.js +69 -0
- package/dist/filters.js +58 -0
- package/dist/form.d.ts +8 -11
- package/dist/form.js +5 -2
- package/dist/formBinding.js +325 -0
- package/dist/formData.js +65 -0
- package/dist/formFlashId.js +4 -0
- package/dist/frameworkRuntimesContext.js +8 -0
- package/dist/globalContext.js +10 -0
- package/dist/index.d.ts +285 -279
- package/dist/index.js +83 -3686
- package/dist/liveRowSort.js +66 -0
- package/dist/mutationConnectionSetup.js +16 -0
- package/dist/mutationIdentity.js +10 -0
- package/dist/mutationSerialExecution.js +53 -0
- package/dist/mutationsBus.js +40 -0
- package/dist/onlineSource.js +13 -0
- package/dist/outbox.js +213 -0
- package/dist/outboxHttp.js +104 -0
- package/dist/outboxState.js +43 -0
- package/dist/permissions.js +20 -0
- package/dist/platform.js +121 -0
- package/dist/preloadSeed.js +47 -0
- package/dist/provider.js +22 -0
- package/dist/query.js +12 -2
- package/dist/recoveryCoordinator.js +195 -0
- package/dist/recoveryRetry.js +24 -0
- package/dist/richText.js +176 -0
- package/dist/rpcErrorBus.js +39 -0
- package/dist/rpcErrorKind.js +13 -0
- package/dist/runRpc.js +12 -0
- package/dist/runtime.d.ts +79 -15
- package/dist/runtime.js +16 -129
- package/dist/runtimeCapabilities.js +44 -0
- package/dist/runtimeContext.js +49 -0
- package/dist/schemaFields.js +219 -0
- package/dist/scopeMembership.js +12 -0
- package/dist/seedResolvers.js +7 -0
- package/dist/sequence.js +65 -0
- package/dist/serverRequest.js +24 -0
- package/dist/serviceClient.js +128 -0
- package/dist/squashRpcCause.js +8 -0
- package/dist/stableKey.js +21 -0
- package/dist/store.js +288 -0
- package/dist/storeStorage.js +28 -0
- package/dist/subscriptionCache.js +724 -0
- package/dist/tagWalk.js +23 -0
- package/dist/traceBus.js +10 -0
- package/dist/tracking.js +40 -0
- package/dist/uploadProgress.js +21 -0
- package/dist/useAction.js +101 -0
- package/dist/useAgent.js +53 -0
- package/dist/useAgentChat.js +43 -0
- package/dist/useAgentStream.js +64 -0
- package/dist/useApiOnline.js +14 -0
- package/dist/useCapabilityManifest.js +101 -0
- package/dist/useConnectionSetup.js +28 -0
- package/dist/useConnectionStatus.js +38 -0
- package/dist/useConnections.js +107 -0
- package/dist/useDataCopilot.js +24 -0
- package/dist/useDataTable.js +34 -0
- package/dist/useDerived.js +22 -0
- package/dist/useEvent.js +88 -0
- package/dist/useFormBinding.js +476 -0
- package/dist/useLocalQuery.js +59 -0
- package/dist/useMutation.js +214 -0
- package/dist/useOnRpcError.js +13 -0
- package/dist/usePreloadedSubscription.js +18 -0
- package/dist/usePreview.js +14 -0
- package/dist/useProvenance.js +51 -0
- package/dist/useQueryField.js +34 -0
- package/dist/useRecord.js +12 -0
- package/dist/useRefreshSubscriptions.js +22 -0
- package/dist/useResourceCan.js +18 -0
- package/dist/useResumableAgentStream.js +75 -0
- package/dist/useSequence.js +25 -0
- package/dist/useSkeleton.js +13 -0
- package/dist/useSubscription.js +89 -0
- package/dist/useSubscriptionHealth.js +32 -0
- package/dist/useTranscription.js +51 -0
- package/dist/useUndo.js +33 -0
- package/dist/useUndoLog.js +44 -0
- package/dist/useUpload.js +296 -0
- package/dist/useWindowedSubscription.js +65 -0
- package/dist/useWorkflow.js +284 -0
- package/dist/useWorkflowRunState.js +93 -0
- package/dist/validation.js +39 -0
- package/dist/validationMessages.js +5 -0
- package/package.json +8 -5
- package/dist/authRefresh-C4Ow8HH7.js +0 -346
- package/dist/formData-dGz5aoUR.js +0 -649
- package/dist/queryOnce-CvdopzOj.js +0 -55
- package/dist/runRpc-DvHpFZAZ.js +0 -1034
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { useSubscription as t } from "./useSubscription.js";
|
|
3
|
+
import { schemaToColumns as n } from "./schemaFields.js";
|
|
4
|
+
import { createLiveRowSorter as r } from "./liveRowSort.js";
|
|
5
|
+
import { useCallback as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
6
|
+
//#region src/useDataTable.ts
|
|
7
|
+
var c = (c, l, u = {}) => {
|
|
8
|
+
let d = e(c), [f, p] = s(u.pageSize), m = a(() => f === void 0 ? u.input ?? {} : {
|
|
9
|
+
...u.input,
|
|
10
|
+
limit: f
|
|
11
|
+
}, [u.input, f]), h = t(c, l, m), g = d.descriptors[l]?.output, _ = i(() => {
|
|
12
|
+
u.pageSize !== void 0 && p((e) => (e ?? u.pageSize) + u.pageSize);
|
|
13
|
+
}, [u.pageSize]), v = a(() => u.columns ?? (g === void 0 ? [] : n(g)), [u.columns, g]), [y, b] = s(u.initialSort), x = i((e) => {
|
|
14
|
+
b((t) => t?.column === e ? {
|
|
15
|
+
column: e,
|
|
16
|
+
direction: t.direction === "asc" ? "desc" : "asc"
|
|
17
|
+
} : {
|
|
18
|
+
column: e,
|
|
19
|
+
direction: "asc"
|
|
20
|
+
});
|
|
21
|
+
}, []), S = o(void 0);
|
|
22
|
+
return S.current === void 0 && (S.current = r()), {
|
|
23
|
+
columns: v,
|
|
24
|
+
rows: a(() => S.current(h.data ?? [], y), [h.data, y]),
|
|
25
|
+
loading: h.data === void 0,
|
|
26
|
+
error: h.error,
|
|
27
|
+
sort: y,
|
|
28
|
+
toggleSort: x,
|
|
29
|
+
loadMore: _,
|
|
30
|
+
hasMore: f !== void 0 && (h.data?.length ?? 0) >= f
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { c as useDataTable };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useRef as e } from "react";
|
|
2
|
+
//#region src/useDerived.ts
|
|
3
|
+
var t = (e, t) => {
|
|
4
|
+
if (e === t) return !0;
|
|
5
|
+
if (e.length !== t.length) return !1;
|
|
6
|
+
for (let n = 0; n < e.length; n += 1) if (!Object.is(e[n], t[n])) return !1;
|
|
7
|
+
return !0;
|
|
8
|
+
}, n = (e) => Object.keys(e).sort().map((t) => e[t]), r = (n, r) => {
|
|
9
|
+
let i = e(null), a = i.current, o = Object.keys(n), s = a !== null && t(a.insertionKeys, o) ? a.names : [...o].sort(), c = s.map((e) => n[e]);
|
|
10
|
+
return a === null || !t(a.names, s) || !t(a.key, c) ? i.current = {
|
|
11
|
+
insertionKeys: o,
|
|
12
|
+
names: s,
|
|
13
|
+
key: c,
|
|
14
|
+
value: r(n)
|
|
15
|
+
} : s !== a.names && (i.current = {
|
|
16
|
+
...a,
|
|
17
|
+
insertionKeys: o,
|
|
18
|
+
names: s
|
|
19
|
+
}), i.current.value;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { t as shallowArrayEqual, n as sourceValues, r as useDerived };
|
package/dist/useEvent.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { recordClientDiagnostic as e } from "./clientDiagnostics.js";
|
|
2
|
+
import { isUnresolvedApi as t } from "./frameworkRuntimesContext.js";
|
|
3
|
+
import { useFrameworkApi as n } from "./runtimeContext.js";
|
|
4
|
+
import { resolveByTag as r } from "./tagWalk.js";
|
|
5
|
+
import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
|
|
6
|
+
import { Effect as c, Fiber as l, Schedule as u, Stream as d } from "effect";
|
|
7
|
+
//#region src/useEvent.ts
|
|
8
|
+
var f = {
|
|
9
|
+
status: "idle",
|
|
10
|
+
missed: 0,
|
|
11
|
+
lastMiss: void 0
|
|
12
|
+
}, p = class {
|
|
13
|
+
_tag = "EventStreamClosed";
|
|
14
|
+
};
|
|
15
|
+
function m(m, h, g, _ = {}) {
|
|
16
|
+
let { skip: v = !1, apiName: y = "app", onMissed: b } = _, x = n(y), { runtime: S, client: C } = x, [w, T] = s(f), E = o(g);
|
|
17
|
+
E.current = g;
|
|
18
|
+
let D = o(b);
|
|
19
|
+
D.current = b;
|
|
20
|
+
let O = o(C);
|
|
21
|
+
O.current = C;
|
|
22
|
+
let k = o(S);
|
|
23
|
+
k.current = S;
|
|
24
|
+
let A = o(/* @__PURE__ */ new Map()), j = h === null ? null : JSON.stringify(Object.entries(h).sort(([e], [t]) => e < t ? -1 : 1)), M = o(h);
|
|
25
|
+
M.current = h;
|
|
26
|
+
let N = o(null);
|
|
27
|
+
N.current !== j && (N.current = j, A.current = /* @__PURE__ */ new Map());
|
|
28
|
+
let P = i((t, n) => {
|
|
29
|
+
t <= 0 || (e(y, "event.gap", {
|
|
30
|
+
tag: m.name,
|
|
31
|
+
missed: t,
|
|
32
|
+
reason: n
|
|
33
|
+
}), T((e) => ({
|
|
34
|
+
...e,
|
|
35
|
+
missed: e.missed + t,
|
|
36
|
+
lastMiss: {
|
|
37
|
+
count: t,
|
|
38
|
+
reason: n
|
|
39
|
+
}
|
|
40
|
+
})), D.current?.({
|
|
41
|
+
count: t,
|
|
42
|
+
reason: n
|
|
43
|
+
}));
|
|
44
|
+
}, [y, m.name]), F = !v && j !== null && !t(x);
|
|
45
|
+
return a(() => {
|
|
46
|
+
if (!F) {
|
|
47
|
+
T(f);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
T((e) => ({
|
|
51
|
+
...e,
|
|
52
|
+
status: "connecting"
|
|
53
|
+
}));
|
|
54
|
+
let e = 0, t = c.sync(() => {
|
|
55
|
+
let e = [];
|
|
56
|
+
for (let [t, n] of A.current) e.push({
|
|
57
|
+
origin: t,
|
|
58
|
+
n
|
|
59
|
+
});
|
|
60
|
+
return r(O.current, m.name)({
|
|
61
|
+
key: M.current,
|
|
62
|
+
...e.length > 0 ? { resume: e } : {}
|
|
63
|
+
});
|
|
64
|
+
}), n = d.unwrap(t).pipe(d.tap(() => c.sync(() => {
|
|
65
|
+
e = 0;
|
|
66
|
+
})), d.concat(d.fail(new p())), d.retry(u.min([u.exponential("250 millis", 2), u.spaced("30 seconds")]).pipe(u.jittered, u.tap(() => c.sync(() => {
|
|
67
|
+
e += 1, T((e) => ({
|
|
68
|
+
...e,
|
|
69
|
+
status: "connecting"
|
|
70
|
+
}));
|
|
71
|
+
}))))), i = k.current.runFork(d.runForEach(n, (e) => c.sync(() => {
|
|
72
|
+
e._tag === "attached" ? T((e) => ({
|
|
73
|
+
...e,
|
|
74
|
+
status: "live"
|
|
75
|
+
})) : e._tag === "gap" ? P(e.missed, e.reason) : (A.current.set(e.origin, Math.max(A.current.get(e.origin) ?? 0, e.n)), E.current(e.payload));
|
|
76
|
+
})));
|
|
77
|
+
return () => {
|
|
78
|
+
k.current.runFork(c.forkDetach(l.interrupt(i)));
|
|
79
|
+
};
|
|
80
|
+
}, [
|
|
81
|
+
F,
|
|
82
|
+
j,
|
|
83
|
+
m.name,
|
|
84
|
+
P
|
|
85
|
+
]), F ? w : f;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { m as useEvent };
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { globalContext as e } from "./globalContext.js";
|
|
2
|
+
import { useFrameworkApi as t } from "./runtimeContext.js";
|
|
3
|
+
import { useMutation as n } from "./useMutation.js";
|
|
4
|
+
import { schemaToFields as r } from "./schemaFields.js";
|
|
5
|
+
import { resolveValidationMessage as i, restrictToSchema as a, validateFields as o } from "./formBinding.js";
|
|
6
|
+
import { useValidationMessages as s } from "./validationMessages.js";
|
|
7
|
+
import { createElement as c, useCallback as l, useContext as u, useEffect as ee, useId as d, useLayoutEffect as te, useMemo as f, useRef as p, useState as m, useSyncExternalStore as h } from "react";
|
|
8
|
+
import { Schema as g } from "effect";
|
|
9
|
+
import { fieldIssuesOf as _ } from "@voltro/protocol";
|
|
10
|
+
import { FormApi as ne } from "@tanstack/form-core";
|
|
11
|
+
import { useStore as re } from "@tanstack/react-store";
|
|
12
|
+
//#region src/useFormBinding.ts
|
|
13
|
+
var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie = (e, t) => Object.is(e.value, t.value) && e.error === t.error && e.serverError === t.serverError && e.touched === t.touched && e.blurred === t.blurred && e.dirty === t.dirty && e.required === t.required && e.label === t.label && e.widget === t.widget && e.options === t.options && e.description === t.description && e.asyncStatus === t.asyncStatus && e.a11y.id === t.a11y.id && e.a11y["aria-invalid"] === t.a11y["aria-invalid"] && e.a11y["aria-required"] === t.a11y["aria-required"] && e.a11y["aria-describedby"] === t.a11y["aria-describedby"], ae = (e, t) => {
|
|
14
|
+
let n = t, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a, o = (e) => {
|
|
15
|
+
let t = n(e), i = r.get(e);
|
|
16
|
+
return i !== void 0 && ie(i, t) ? i : (r.set(e, t), t);
|
|
17
|
+
}, s = () => {
|
|
18
|
+
for (let [e, t] of i) {
|
|
19
|
+
let n = r.get(e);
|
|
20
|
+
if (o(e) !== n) for (let e of [...t]) e();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
snapshot: o,
|
|
25
|
+
refresh: (e) => {
|
|
26
|
+
n = e, s();
|
|
27
|
+
},
|
|
28
|
+
subscribe: (t, n) => {
|
|
29
|
+
let o = i.get(t);
|
|
30
|
+
if (o === void 0 && (o = /* @__PURE__ */ new Set(), i.set(t, o)), o.add(n), a === void 0) {
|
|
31
|
+
let t = e.subscribe(s);
|
|
32
|
+
a = () => t.unsubscribe();
|
|
33
|
+
}
|
|
34
|
+
let c = o;
|
|
35
|
+
return () => {
|
|
36
|
+
c.delete(n), c.size === 0 && i.get(t) === c && (i.delete(t), r.delete(t)), i.size === 0 && (a?.(), a = void 0);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, b = e("formBinding", void 0), oe = (e, t) => {
|
|
41
|
+
let n = e;
|
|
42
|
+
for (let e of t.split(".")) {
|
|
43
|
+
if (typeof n != "object" || !n) return;
|
|
44
|
+
n = n[e];
|
|
45
|
+
}
|
|
46
|
+
return n;
|
|
47
|
+
}, se = (e, t) => {
|
|
48
|
+
let n = `vf-${e}-${t}-`.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
49
|
+
return (e) => n + `${e}`.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
50
|
+
}, ce = (e, t) => {
|
|
51
|
+
let n = e.map((e) => e.name), r = Object.keys(t), i;
|
|
52
|
+
if (e.length >= 32 && r.length >= 32 && Object.getPrototypeOf(e) === Array.prototype && Object.getOwnPropertyDescriptor(e, "some") === void 0) {
|
|
53
|
+
let t = /* @__PURE__ */ new Set();
|
|
54
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
55
|
+
let r = Object.getOwnPropertyDescriptor(e, String(n)), a = r !== void 0 && "value" in r && r.value !== null && typeof r.value == "object" ? Object.getOwnPropertyDescriptor(r.value, "name") : void 0;
|
|
56
|
+
if (a === void 0 || !("value" in a) || typeof a.value != "string") break;
|
|
57
|
+
t.add(a.value), n === e.length - 1 && (i = t);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return [...n, ...r.filter((t) => i === void 0 ? !e.some((e) => e.name === t) : !i.has(t))];
|
|
61
|
+
}, le = {
|
|
62
|
+
isTouched: !1,
|
|
63
|
+
isBlurred: !1,
|
|
64
|
+
isDirty: !1,
|
|
65
|
+
isPristine: !0,
|
|
66
|
+
isDefaultValue: !0,
|
|
67
|
+
isValidating: !1,
|
|
68
|
+
errorMap: {},
|
|
69
|
+
errorSourceMap: {}
|
|
70
|
+
}, ue = (e) => {
|
|
71
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
72
|
+
for (let r of e) {
|
|
73
|
+
if (t.has(r.name) || t.set(r.name, r), r.widget !== "array" || n.has(r.name)) continue;
|
|
74
|
+
let e = /* @__PURE__ */ new Map();
|
|
75
|
+
for (let t of r.item ?? []) e.has(t.name) || e.set(t.name, t);
|
|
76
|
+
n.set(r.name, e);
|
|
77
|
+
}
|
|
78
|
+
return (e) => {
|
|
79
|
+
let r = t.get(e);
|
|
80
|
+
if (r !== void 0) return r;
|
|
81
|
+
let i = /^(.+?)\.\d+\.(.+)$/.exec(e);
|
|
82
|
+
return i === null ? void 0 : n.get(i[1])?.get(i[2]);
|
|
83
|
+
};
|
|
84
|
+
}, x = (e, r, i) => {
|
|
85
|
+
let a = t(e), o = p(void 0), s = typeof r == "function" ? r(o.current?.state?.values ?? i.defaults ?? {}) : r, c = p(s).current, l = n(e, s), u = i.schema ?? a.descriptors[s]?.input;
|
|
86
|
+
return process.env.NODE_ENV !== "production" && u === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${r}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`), C(e, c, i, u, o, l);
|
|
87
|
+
}, S = (e) => {
|
|
88
|
+
let t = p(void 0);
|
|
89
|
+
return C("local", d(), {
|
|
90
|
+
...e,
|
|
91
|
+
onSubmit: async ({ input: t }) => e.onSubmit(await g.decodeUnknownPromise(e.schema)(t))
|
|
92
|
+
}, e.schema, t);
|
|
93
|
+
}, C = (e, t, n, c, u, d) => {
|
|
94
|
+
let h = f(() => c ? r(c) : [], [c]), g = f(() => ue(h), [h]), y = f(() => se(e, t), [e, t]), ie = s(), b = n.messages ?? ie, x = f(() => ({
|
|
95
|
+
...n.locale === void 0 ? {} : { locale: n.locale },
|
|
96
|
+
...b === void 0 ? {} : { messages: b }
|
|
97
|
+
}), [n.locale, b]), S = p(n.asyncFields);
|
|
98
|
+
S.current = n.asyncFields;
|
|
99
|
+
let C = p(n);
|
|
100
|
+
C.current = n;
|
|
101
|
+
let w = p(d);
|
|
102
|
+
w.current = d;
|
|
103
|
+
let T = p(x);
|
|
104
|
+
T.current = x;
|
|
105
|
+
let E = p(c);
|
|
106
|
+
E.current = c;
|
|
107
|
+
let [D, O] = m(() => n.flash?.errors ?? {}), [de, k] = m(n.flash?.formError), [fe, A] = m(void 0), j = p(void 0), M = p(!1), N = l((e) => {
|
|
108
|
+
let t = E.current;
|
|
109
|
+
if (t === void 0) return [];
|
|
110
|
+
let n = C.current, r = e;
|
|
111
|
+
if (n.toInput !== void 0) try {
|
|
112
|
+
r = n.toInput(e);
|
|
113
|
+
} catch {
|
|
114
|
+
r = e;
|
|
115
|
+
}
|
|
116
|
+
let i = o(t, r, T.current).issues;
|
|
117
|
+
if (n.toInput === void 0) return i;
|
|
118
|
+
let a = n.errorPath ?? {};
|
|
119
|
+
return i.map((t) => {
|
|
120
|
+
let n = a[t.path];
|
|
121
|
+
return n === void 0 ? (oe(e, t.path) !== void 0 || t.path.includes("."), t) : {
|
|
122
|
+
...t,
|
|
123
|
+
path: n
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}, []), P = l((e) => {
|
|
127
|
+
let t = { ...e ?? {} }, n = E.current;
|
|
128
|
+
if (n !== void 0) for (let e of r(n)) (e.widget === "checkbox" || e.widget === "switch") && !(e.name in t) && (t[e.name] = !1);
|
|
129
|
+
return t;
|
|
130
|
+
}, []), pe = p(() => Promise.resolve());
|
|
131
|
+
if (u.current === void 0) {
|
|
132
|
+
let e = n.flash, t = e === void 0 ? P(n.defaults) : {
|
|
133
|
+
...P(n.defaults),
|
|
134
|
+
...e.values
|
|
135
|
+
};
|
|
136
|
+
u.current = new ne({
|
|
137
|
+
onSubmit: ({ value: e }) => pe.current(e),
|
|
138
|
+
defaultValues: t,
|
|
139
|
+
validators: { onChange: ({ value: e }) => {
|
|
140
|
+
let t = N(e);
|
|
141
|
+
if (t.length === 0) return;
|
|
142
|
+
let n = {};
|
|
143
|
+
for (let e of t) e.path !== "" && !(e.path in n) && (n[e.path] = i(e, T.current));
|
|
144
|
+
return { fields: n };
|
|
145
|
+
} }
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
let F = u.current, I = F;
|
|
149
|
+
ee(() => I.mount(), [I]);
|
|
150
|
+
let me = n.subscribe ?? "all";
|
|
151
|
+
re(F.store, (e) => me === "all" ? e : `${e.submissionAttempts}|${String(e.isSubmitting)}|${String(e.isDirty)}|${String(e.isTouched)}`);
|
|
152
|
+
let L = F.store.state.values, R = F.store.state, z = f(() => N(L), [
|
|
153
|
+
N,
|
|
154
|
+
L,
|
|
155
|
+
c,
|
|
156
|
+
n.toInput,
|
|
157
|
+
n.errorPath,
|
|
158
|
+
x
|
|
159
|
+
]), B = f(() => {
|
|
160
|
+
let e = /* @__PURE__ */ new Map();
|
|
161
|
+
for (let t of z) e.has(t.path) || e.set(t.path, t);
|
|
162
|
+
return e;
|
|
163
|
+
}, [z]), V = p({
|
|
164
|
+
values: L,
|
|
165
|
+
index: B
|
|
166
|
+
});
|
|
167
|
+
V.current = {
|
|
168
|
+
values: L,
|
|
169
|
+
index: B
|
|
170
|
+
};
|
|
171
|
+
let he = l((e) => {
|
|
172
|
+
let t = F.store.state.values;
|
|
173
|
+
if (V.current.values !== t) {
|
|
174
|
+
let e = /* @__PURE__ */ new Map();
|
|
175
|
+
for (let n of N(t)) e.has(n.path) || e.set(n.path, n);
|
|
176
|
+
V.current = {
|
|
177
|
+
values: t,
|
|
178
|
+
index: e
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return V.current.index.get(e);
|
|
182
|
+
}, [F, N]), H = n.isLoading === !0, ge = n.validate, U = ge?.onChange ?? "afterTouched", _e = ge?.onBlur ?? !0, ve = l((e) => {
|
|
183
|
+
if (H) return !1;
|
|
184
|
+
if (F.store.state.submissionAttempts > 0 || U === "always") return !0;
|
|
185
|
+
if (U === "never") return !1;
|
|
186
|
+
let t = I.getFieldMeta(e);
|
|
187
|
+
return t === void 0 ? !1 : _e ? t.isBlurred === !0 : t.isTouched === !0;
|
|
188
|
+
}, [
|
|
189
|
+
F,
|
|
190
|
+
I,
|
|
191
|
+
H,
|
|
192
|
+
U,
|
|
193
|
+
_e
|
|
194
|
+
]), W = l((e) => {
|
|
195
|
+
let t = D[e];
|
|
196
|
+
if (t !== void 0) return t;
|
|
197
|
+
let n = S.current?.[e];
|
|
198
|
+
if (n !== void 0 && n.status === "invalid") return n.message ?? i({
|
|
199
|
+
id: "validation.invalid",
|
|
200
|
+
fallback: "Invalid value"
|
|
201
|
+
}, T.current);
|
|
202
|
+
if (!ve(e)) return;
|
|
203
|
+
let r = he(e);
|
|
204
|
+
return r === void 0 ? void 0 : i(r, T.current);
|
|
205
|
+
}, [
|
|
206
|
+
D,
|
|
207
|
+
ve,
|
|
208
|
+
he
|
|
209
|
+
]), G = f(() => {
|
|
210
|
+
let e = {}, t = /* @__PURE__ */ new Set();
|
|
211
|
+
for (let e of z) e.path !== "" && t.add(e.path);
|
|
212
|
+
for (let e of Object.keys(D)) t.add(e);
|
|
213
|
+
for (let [e, n] of Object.entries(S.current ?? {})) n.status === "invalid" && t.add(e);
|
|
214
|
+
for (let n of t) {
|
|
215
|
+
let t = W(n);
|
|
216
|
+
t !== void 0 && (e[n] = t);
|
|
217
|
+
}
|
|
218
|
+
return e;
|
|
219
|
+
}, [
|
|
220
|
+
z,
|
|
221
|
+
D,
|
|
222
|
+
W,
|
|
223
|
+
R.fieldMetaBase,
|
|
224
|
+
R.submissionAttempts,
|
|
225
|
+
n.asyncFields
|
|
226
|
+
]), K = l((e) => {
|
|
227
|
+
O((t) => {
|
|
228
|
+
if (!(e in t)) return t;
|
|
229
|
+
let n = { ...t };
|
|
230
|
+
return delete n[e], n;
|
|
231
|
+
});
|
|
232
|
+
}, []), q = l((e) => {
|
|
233
|
+
let t = g(e), n = I.getFieldMeta(e), r = W(e), i = y(e), a = S.current?.[e], o = [r === void 0 ? void 0 : `${i}-error`, t?.description === void 0 ? void 0 : `${i}-help`].filter((e) => e !== void 0);
|
|
234
|
+
return {
|
|
235
|
+
value: I.getFieldValue(e),
|
|
236
|
+
setValue: (t) => {
|
|
237
|
+
K(e), !Object.is(I.getFieldValue(e), t) && I.setFieldValue(e, t);
|
|
238
|
+
},
|
|
239
|
+
onBlur: () => {
|
|
240
|
+
I.setFieldMeta(e, (e) => ({
|
|
241
|
+
...le,
|
|
242
|
+
...e ?? {},
|
|
243
|
+
isTouched: !0,
|
|
244
|
+
isBlurred: !0
|
|
245
|
+
}));
|
|
246
|
+
},
|
|
247
|
+
error: r,
|
|
248
|
+
serverError: D[e],
|
|
249
|
+
touched: n?.isTouched === !0,
|
|
250
|
+
blurred: n?.isBlurred === !0,
|
|
251
|
+
dirty: n?.isDirty === !0,
|
|
252
|
+
required: t?.required === !0,
|
|
253
|
+
label: t?.label ?? e,
|
|
254
|
+
widget: t?.widget ?? "text",
|
|
255
|
+
options: t?.options,
|
|
256
|
+
description: t?.description,
|
|
257
|
+
asyncStatus: a?.status ?? "idle",
|
|
258
|
+
a11y: {
|
|
259
|
+
id: i,
|
|
260
|
+
"aria-invalid": r !== void 0 || void 0,
|
|
261
|
+
"aria-required": t?.required === !0 || void 0,
|
|
262
|
+
"aria-describedby": o.length > 0 ? o.join(" ") : void 0
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}, [
|
|
266
|
+
y,
|
|
267
|
+
K,
|
|
268
|
+
I,
|
|
269
|
+
g,
|
|
270
|
+
D,
|
|
271
|
+
W
|
|
272
|
+
]), J = p(void 0);
|
|
273
|
+
J.current === void 0 && (J.current = ae(F.store, q));
|
|
274
|
+
let ye = J.current;
|
|
275
|
+
te(() => {
|
|
276
|
+
ye.refresh(q);
|
|
277
|
+
});
|
|
278
|
+
let be = l((e) => ({
|
|
279
|
+
items: I.getFieldValue(e) ?? [],
|
|
280
|
+
push: (t) => {
|
|
281
|
+
I.pushFieldValue(e, t);
|
|
282
|
+
},
|
|
283
|
+
insert: (t, n) => {
|
|
284
|
+
I.insertFieldValue(e, t, n);
|
|
285
|
+
},
|
|
286
|
+
remove: (t) => {
|
|
287
|
+
I.removeFieldValue(e, t);
|
|
288
|
+
},
|
|
289
|
+
move: (t, n) => {
|
|
290
|
+
I.moveFieldValues(e, t, n);
|
|
291
|
+
},
|
|
292
|
+
swap: (t, n) => {
|
|
293
|
+
I.swapFieldValues(e, t, n);
|
|
294
|
+
},
|
|
295
|
+
field: (t, n) => q(`${e}.${t}.${n}`)
|
|
296
|
+
}), [I, q]), xe = l((e) => h.filter((t) => t.section === e), [h]), Se = l((e, t) => {
|
|
297
|
+
K(e), !Object.is(I.getFieldValue(e), t) && I.setFieldValue(e, t);
|
|
298
|
+
}, [K, I]), Ce = l((e) => {
|
|
299
|
+
for (let [t, n] of Object.entries(e)) I.setFieldValue(t, n);
|
|
300
|
+
}, [I]), we = l((e) => {
|
|
301
|
+
O({}), k(void 0), A(void 0), j.current = void 0, M.current = !1, e === void 0 ? I.reset() : I.reset(P(e));
|
|
302
|
+
}, [I, P]), Te = n.asyncTimeoutMs ?? 5e3, Ee = l(async () => {
|
|
303
|
+
let e = Date.now();
|
|
304
|
+
for (;;) {
|
|
305
|
+
let t = S.current;
|
|
306
|
+
if (t === void 0) return;
|
|
307
|
+
let n = Object.entries(t), r;
|
|
308
|
+
for (let e of n) e[1].status === "checking" && (r ??= []).push(e);
|
|
309
|
+
if (r === void 0) {
|
|
310
|
+
let e = 0;
|
|
311
|
+
for (let t of n) t[1].status === "invalid" && (n[e++] = t);
|
|
312
|
+
n.length = e;
|
|
313
|
+
let t = n;
|
|
314
|
+
if (t.length === 0) return;
|
|
315
|
+
let r = Object.fromEntries(t);
|
|
316
|
+
for (let [e, n] of t) r[e] = n.message ?? i({
|
|
317
|
+
id: "validation.invalid",
|
|
318
|
+
fallback: "Invalid value"
|
|
319
|
+
}, T.current);
|
|
320
|
+
return r;
|
|
321
|
+
}
|
|
322
|
+
if (Date.now() - e > Te) {
|
|
323
|
+
let e = Object.fromEntries(r);
|
|
324
|
+
for (let [t] of r) e[t] = i({
|
|
325
|
+
id: "validation.checking",
|
|
326
|
+
fallback: "Still checking…"
|
|
327
|
+
}, T.current);
|
|
328
|
+
return e;
|
|
329
|
+
}
|
|
330
|
+
await new Promise((e) => setTimeout(e, 50));
|
|
331
|
+
}
|
|
332
|
+
}, [Te]), Y = l(() => {
|
|
333
|
+
let e = globalThis.document;
|
|
334
|
+
if (e?.getElementById === void 0) return;
|
|
335
|
+
let t = ce(h, D);
|
|
336
|
+
for (let n of t) if (W(n) !== void 0) {
|
|
337
|
+
e.getElementById(y(n))?.focus?.();
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
}, [
|
|
341
|
+
y,
|
|
342
|
+
h,
|
|
343
|
+
D,
|
|
344
|
+
W
|
|
345
|
+
]), X = p(Y);
|
|
346
|
+
X.current = Y;
|
|
347
|
+
let De = l(async () => {
|
|
348
|
+
k(void 0), O({}), A(void 0), j.current = void 0, M.current = !1;
|
|
349
|
+
let e, t = !1;
|
|
350
|
+
if (await I.handleSubmit().catch((n) => {
|
|
351
|
+
t = !0, e = n;
|
|
352
|
+
}), t) throw e;
|
|
353
|
+
return M.current || queueMicrotask(() => {
|
|
354
|
+
X.current();
|
|
355
|
+
}), j.current;
|
|
356
|
+
}, [I]);
|
|
357
|
+
pe.current = (async (e) => {
|
|
358
|
+
let t = C.current, n = e, r = n;
|
|
359
|
+
if (t.toInput !== void 0) try {
|
|
360
|
+
r = t.toInput(n);
|
|
361
|
+
} catch (e) {
|
|
362
|
+
k(e instanceof Error ? e.message : String(e));
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (N(n).length > 0) {
|
|
366
|
+
queueMicrotask(() => {
|
|
367
|
+
X.current();
|
|
368
|
+
});
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
let o = E.current;
|
|
372
|
+
if (o !== void 0) {
|
|
373
|
+
let e = a(o, r);
|
|
374
|
+
e.dropped.length > 0 && process.env.NODE_ENV !== "production" && console.warn(`[@voltro/client] useFormBinding: dropped ${e.dropped.length} value(s) the mutation's input does not declare (${e.dropped.join(", ")}). The server refuses undeclared fields, so they are not sent. Map them with \`toInput\` if they belong in the write; ignore this if they are form-only state.`), r = e.input;
|
|
375
|
+
}
|
|
376
|
+
let s = await Ee();
|
|
377
|
+
if (s !== void 0) {
|
|
378
|
+
O((e) => ({
|
|
379
|
+
...e,
|
|
380
|
+
...s
|
|
381
|
+
})), queueMicrotask(() => {
|
|
382
|
+
X.current();
|
|
383
|
+
});
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
let c = (e) => {
|
|
387
|
+
let t = w.current;
|
|
388
|
+
return t === void 0 ? Promise.reject(/* @__PURE__ */ Error("A schema form submits through its onSubmit callback")) : t.mutate(e);
|
|
389
|
+
};
|
|
390
|
+
try {
|
|
391
|
+
let e = t.onSubmit === void 0 ? await c(r) : await t.onSubmit({
|
|
392
|
+
input: r,
|
|
393
|
+
values: n,
|
|
394
|
+
mutate: c
|
|
395
|
+
});
|
|
396
|
+
j.current = e, M.current = !0, t.onSuccess?.(e);
|
|
397
|
+
} catch (e) {
|
|
398
|
+
let t = _(e);
|
|
399
|
+
if (t.length === 0) {
|
|
400
|
+
A(e), C.current.onError?.(e);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
let n = {};
|
|
404
|
+
for (let e of t) e.field in n || (n[e.field] = i({
|
|
405
|
+
id: e.message,
|
|
406
|
+
...e.params === void 0 ? {} : { params: e.params },
|
|
407
|
+
fallback: e.message
|
|
408
|
+
}, T.current));
|
|
409
|
+
O((e) => ({
|
|
410
|
+
...e,
|
|
411
|
+
...n
|
|
412
|
+
})), queueMicrotask(() => {
|
|
413
|
+
X.current();
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
let Z = z.length === 0, Oe = Object.values(S.current ?? {}).some((e) => e.status === "checking"), Q = fe ?? d?.error, ke = Q !== void 0 && _(Q).length > 0 ? void 0 : Q, Ae = Object.keys(G).length, je = (() => {
|
|
418
|
+
for (let e of h) if (G[e.name] !== void 0) return e.name;
|
|
419
|
+
let e = Object.keys(G);
|
|
420
|
+
return e.length > 0 ? e[0] : void 0;
|
|
421
|
+
})(), Me = {
|
|
422
|
+
isDirty: !H && R.isDirty,
|
|
423
|
+
isPristine: R.isPristine,
|
|
424
|
+
isTouched: R.isTouched,
|
|
425
|
+
isValid: Z,
|
|
426
|
+
isValidating: Oe,
|
|
427
|
+
canSubmit: Z && !Oe && !R.isSubmitting && !H,
|
|
428
|
+
isSubmitting: R.isSubmitting,
|
|
429
|
+
isSubmitted: R.isSubmitted,
|
|
430
|
+
isSubmitSuccessful: R.isSubmitSuccessful && M.current,
|
|
431
|
+
submissionAttempts: R.submissionAttempts,
|
|
432
|
+
errorCount: Ae,
|
|
433
|
+
firstInvalidPath: je,
|
|
434
|
+
pending: d?.pending ?? R.isSubmitting,
|
|
435
|
+
isLoading: H,
|
|
436
|
+
submitError: ke,
|
|
437
|
+
data: d?.data ?? j.current
|
|
438
|
+
}, $ = {
|
|
439
|
+
fields: h,
|
|
440
|
+
values: L,
|
|
441
|
+
errors: G,
|
|
442
|
+
issues: z,
|
|
443
|
+
isValid: Z,
|
|
444
|
+
pending: d?.pending ?? R.isSubmitting,
|
|
445
|
+
submitError: ke,
|
|
446
|
+
formError: de,
|
|
447
|
+
data: d?.data ?? j.current,
|
|
448
|
+
setValue: Se,
|
|
449
|
+
setValues: Ce,
|
|
450
|
+
reset: we,
|
|
451
|
+
submit: De,
|
|
452
|
+
field: q,
|
|
453
|
+
array: be,
|
|
454
|
+
section: xe,
|
|
455
|
+
state: Me,
|
|
456
|
+
focusFirstInvalid: Y
|
|
457
|
+
};
|
|
458
|
+
return Object.defineProperty($, v, {
|
|
459
|
+
value: {
|
|
460
|
+
store: F.store,
|
|
461
|
+
field: q,
|
|
462
|
+
channel: ye
|
|
463
|
+
},
|
|
464
|
+
enumerable: !1
|
|
465
|
+
}), $;
|
|
466
|
+
}, w = (e) => {
|
|
467
|
+
let t = e.binding[v];
|
|
468
|
+
return c(b.Provider, { value: e.binding }, c(y.Provider, { value: t?.channel }, e.children));
|
|
469
|
+
}, T = () => u(b);
|
|
470
|
+
function E(e, t) {
|
|
471
|
+
let n = u(y), r = typeof e == "string" ? void 0 : e, i = typeof e == "string" ? e : t, a = r?.[v], o = r === void 0 ? n : a?.channel;
|
|
472
|
+
if (o === void 0) throw Error(r === void 0 ? "useFormField(path) found no form binding — mount <FormBindingProvider binding={form}> above this field, or call useFormField(form, path)." : "useFormField: not a useFormBinding result");
|
|
473
|
+
return h(l((e) => o.subscribe(i, e), [o, i]), l(() => o.snapshot(i), [o, i]), l(() => o.snapshot(i), [o, i]));
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
export { w as FormBindingProvider, x as useFormBinding, T as useFormBindingContext, E as useFormField, S as useSchemaFormBinding };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { useCallback as t, useMemo as n, useRef as r, useSyncExternalStore as i } from "react";
|
|
3
|
+
//#region src/useLocalQuery.ts
|
|
4
|
+
var a = (e, t) => e === t ? 0 : e == null ? 1 : t == null ? -1 : e instanceof Date && t instanceof Date ? e.getTime() - t.getTime() : typeof e == "number" && typeof t == "number" ? e - t : String(e).localeCompare(String(t)), o = (e, t = {}) => {
|
|
5
|
+
let n = t.limit === void 0 ? void 0 : Math.max(0, Math.trunc(t.limit));
|
|
6
|
+
if (n === 0 || Number.isNaN(n)) return [];
|
|
7
|
+
let r = t.where === void 0 ? [...e] : e.filter(t.where), i = t.orderBy;
|
|
8
|
+
if (i !== void 0) {
|
|
9
|
+
let e = typeof i == "function" ? i : typeof i == "string" ? (e, t) => a(e[i], t[i]) : (e, t) => {
|
|
10
|
+
let [n, r] = typeof i == "string" ? [i, "asc"] : i, o = a(e[n], t[n]);
|
|
11
|
+
return r === "desc" ? -o : o;
|
|
12
|
+
};
|
|
13
|
+
if (n !== void 0 && Number.isFinite(n) && n < r.length / 2) {
|
|
14
|
+
let t = (t, n) => {
|
|
15
|
+
let r = t.row === void 0 ? n.row === void 0 ? 0 : 1 : n.row === void 0 ? -1 : e(t.row, n.row);
|
|
16
|
+
return (Number.isNaN(r) ? 0 : r) || t.index - n.index;
|
|
17
|
+
}, i = [], a = () => {
|
|
18
|
+
let e = 0;
|
|
19
|
+
for (;;) {
|
|
20
|
+
let n = e * 2 + 1, r = n + 1;
|
|
21
|
+
if (n >= i.length) return;
|
|
22
|
+
let a = r < i.length && t(i[r], i[n]) > 0 ? r : n;
|
|
23
|
+
if (t(i[e], i[a]) >= 0) return;
|
|
24
|
+
[i[e], i[a]] = [i[a], i[e]], e = a;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
for (let e = 0; e < r.length; e++) {
|
|
28
|
+
let o = {
|
|
29
|
+
row: r[e],
|
|
30
|
+
index: e
|
|
31
|
+
};
|
|
32
|
+
if (i.length < n) {
|
|
33
|
+
i.push(o);
|
|
34
|
+
let e = i.length - 1;
|
|
35
|
+
for (; e > 0;) {
|
|
36
|
+
let n = e - 1 >> 1;
|
|
37
|
+
if (t(i[n], i[e]) >= 0) break;
|
|
38
|
+
[i[n], i[e]] = [i[e], i[n]], e = n;
|
|
39
|
+
}
|
|
40
|
+
} else t(o, i[0]) < 0 && (i[0] = o, a());
|
|
41
|
+
}
|
|
42
|
+
return i.sort(t).map((e) => e.row);
|
|
43
|
+
}
|
|
44
|
+
r = r.sort(e);
|
|
45
|
+
}
|
|
46
|
+
return t.limit === void 0 ? r : r.slice(0, Math.max(0, t.limit));
|
|
47
|
+
}, s = (a, s, l = {}) => {
|
|
48
|
+
let { cache: u } = e(a), d = i(t((e) => u.subscribeTable(s, e), [u, s]), t(() => u.rowsOf(s), [u, s]), () => c), f = r(l);
|
|
49
|
+
f.current = l;
|
|
50
|
+
let { where: p, orderBy: m, limit: h } = l;
|
|
51
|
+
return n(() => o(d, f.current), [
|
|
52
|
+
d,
|
|
53
|
+
p,
|
|
54
|
+
m,
|
|
55
|
+
h
|
|
56
|
+
]);
|
|
57
|
+
}, c = [];
|
|
58
|
+
//#endregion
|
|
59
|
+
export { o as runLocalQuery, s as useLocalQuery };
|