@mostra/react 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @mostra/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The client runtime of [Mostra](https://github.com/mostra-dev/mostra), the agent artifact runtime.
4
+ Artifacts import it for `defineArtifact`, the manifest an artifact declares in its entry:
5
+
6
+ ```tsx
7
+ import { defineArtifact } from "@mostra/react";
8
+
9
+ export const artifact = defineArtifact({ title: "Sidebar options", family: "review" });
10
+
11
+ export default function Page() {
12
+ return <h1>Sidebar options</h1>;
13
+ }
14
+ ```
15
+
16
+ Artifacts don't install it: every Mostra build resolves it from the warm set. Fields, submissions,
17
+ actions and live data arrive in later releases. Apache-2.0.
package/dist/form.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { FieldPath, FieldValues, UseFormProps, UseFormReturn } from "react-hook-form";
2
+ //#region src/form.d.ts
3
+ /** Options of {@link useForm}: react-hook-form's, and the form's field ID. */
4
+ export interface MostraFormOptions<TFieldValues extends FieldValues> extends Omit<UseFormProps<TFieldValues>, "values"> {
5
+ /** The field ID every field of the form is persisted under: `<id>.<name>` (D52). */
6
+ readonly id: string;
7
+ /** Labels for results and the shell's blockers, by field name. */
8
+ readonly labels?: Readonly<Partial<Record<FieldPath<TFieldValues>, string>>>;
9
+ /** `viewer` (default): the viewer's draft. `artifact`: shared state (D63). */
10
+ readonly scope?: "viewer" | "artifact";
11
+ /** Field names kept out of events and logs (D52), still delivered with the submission. */
12
+ readonly sensitive?: readonly FieldPath<TFieldValues>[];
13
+ }
14
+ /**
15
+ * react-hook-form's `useForm`, persisted to Mostra fields under `id` (D52). Everything else is
16
+ * react-hook-form's own: `register`, `handleSubmit`, `formState`, resolvers.
17
+ */
18
+ export declare function useForm<TFieldValues extends FieldValues = FieldValues>(options: MostraFormOptions<TFieldValues>): UseFormReturn<TFieldValues>;
19
+ //#endregion
20
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.d.ts","names":[],"sources":["../src/form.ts"],"mappings":";;;iBA8EiB,kBAAkB,qBAAqB,qBAC9C,KAAK,aAAa;;WAEjB;;WAEA,SAAS,SAAS,QAAQ,OAAO,UAAU;;WAE3C;;WAEA,qBAAqB,UAAU;;;;;;wBAO1B,QAAQ,qBAAqB,cAAc,aACzD,SAAS,kBAAkB,gBAC1B,cAAc"}
package/dist/form.js ADDED
@@ -0,0 +1,259 @@
1
+ "use client";
2
+ import { g as fieldKey, o as useStore } from "./hooks-Dh_l8KqJ.js";
3
+ import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
+ import { get, set, useForm as useForm$1 } from "react-hook-form";
5
+ //#region src/form.ts
6
+ /**
7
+ * `@mostra/react/form`: react-hook-form on Mostra fields (D52, D26). `useForm` is react-hook-form's
8
+ * own, with one more option, `id`: every answer persists as the Mostra field `<id>.<path>` (a
9
+ * field array as one answer, `<id>.items`), so a large form saves as the viewer types, resets
10
+ * included, survives reloads and other tabs, converges with other writers, and arrives in
11
+ * results nested under `id`. Its `required` rules and validation errors become the shell's
12
+ * blockers.
13
+ *
14
+ * ```tsx
15
+ * import { useForm } from "@mostra/react/form";
16
+ *
17
+ * const form = useForm({ id: "intake", defaultValues: { name: "", team: "" }, labels: { name: "Your name" } });
18
+ * <input {...form.register("name", { required: true })} />
19
+ * ```
20
+ */
21
+ /** Whether two JSON values are the same. */
22
+ function sameJson(a, b) {
23
+ return a === b || JSON.stringify(a) === JSON.stringify(b);
24
+ }
25
+ /** Whether a value is a plain object, whose keys the form's values nest by. */
26
+ function isPlainObject(value) {
27
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
28
+ const proto = Object.getPrototypeOf(value);
29
+ return proto === Object.prototype || proto === null;
30
+ }
31
+ /**
32
+ * A form's answers as Mostra fields (Claude review finding 1): one field per leaf, where a leaf is
33
+ * any value that isn't a plain object, arrays included. A field array is one answer, so a row
34
+ * removed is gone from that answer, never left behind as a field of its own, and `items` and
35
+ * `items.1` never both exist.
36
+ */
37
+ function leaves(values, path = "", out = /* @__PURE__ */ new Map()) {
38
+ if (isPlainObject(values)) for (const [key, value] of Object.entries(values)) leaves(value, path === "" ? key : `${path}.${key}`, out);
39
+ else if (path !== "") out.set(path, values);
40
+ return out;
41
+ }
42
+ /** The leaf a registered name lives in: the name itself, or the array it is inside. */
43
+ function leafOf(values, name) {
44
+ const parts = name.split(".");
45
+ let current = values;
46
+ for (let index = 0; index < parts.length; index += 1) {
47
+ if (Array.isArray(current)) return parts.slice(0, index).join(".");
48
+ if (!isPlainObject(current)) return name;
49
+ current = current[parts[index]];
50
+ }
51
+ return name;
52
+ }
53
+ /**
54
+ * react-hook-form's `useForm`, persisted to Mostra fields under `id` (D52). Everything else is
55
+ * react-hook-form's own: `register`, `handleSubmit`, `formState`, resolvers.
56
+ */
57
+ function useForm(options) {
58
+ const store = useStore();
59
+ const { id, labels, scope = "viewer", sensitive, ...hookOptions } = options;
60
+ const prefix = `${id}.`;
61
+ const version = useSyncExternalStore(store.subscribe, store.version, store.version);
62
+ const [defaults] = useState(() => hookOptions.defaultValues);
63
+ const defaultOf = useCallback((leaf) => get(defaults ?? {}, leaf), [defaults]);
64
+ const storedValue = useCallback((leaf) => store.value(fieldKey(scope, `${prefix}${leaf}`), defaultOf(leaf)), [
65
+ store,
66
+ scope,
67
+ prefix,
68
+ defaultOf
69
+ ]);
70
+ const stored = useCallback((leaf) => store.value(fieldKey(scope, `${prefix}${leaf}`), void 0) !== void 0, [
71
+ store,
72
+ scope,
73
+ prefix
74
+ ]);
75
+ const [initial] = useState(() => {
76
+ const base = typeof defaults === "object" && defaults !== null ? structuredClone(defaults) : {};
77
+ for (const fieldId of store.ids(scope)) {
78
+ if (!fieldId.startsWith(prefix)) continue;
79
+ set(base, fieldId.slice(prefix.length), store.value(fieldKey(scope, fieldId), void 0));
80
+ }
81
+ return base;
82
+ });
83
+ const form = useForm$1({
84
+ ...hookOptions,
85
+ defaultValues: initial
86
+ });
87
+ const labelsKey = JSON.stringify(labels ?? {});
88
+ const stableLabels = useMemo(() => JSON.parse(labelsKey), [labelsKey]);
89
+ const sensitiveNames = useMemo(() => new Set(sensitive ?? []), [sensitive]);
90
+ const save = useCallback((values) => {
91
+ const current = leaves(values);
92
+ for (const [leaf, value] of current) {
93
+ const key = fieldKey(scope, `${prefix}${leaf}`);
94
+ if (!store.writable(key)) continue;
95
+ if (stored(leaf) ? sameJson(value, storedValue(leaf)) : sameJson(value, defaultOf(leaf))) continue;
96
+ const label = stableLabels?.[leaf];
97
+ store.set(scope, `${prefix}${leaf}`, value, {
98
+ ...label !== void 0 ? { label } : {},
99
+ ...sensitiveNames.has(leaf) ? { sensitive: true } : {}
100
+ });
101
+ }
102
+ }, [
103
+ store,
104
+ scope,
105
+ prefix,
106
+ stored,
107
+ storedValue,
108
+ defaultOf,
109
+ stableLabels,
110
+ sensitiveNames
111
+ ]);
112
+ useEffect(() => form.subscribe({
113
+ formState: { values: true },
114
+ callback: ({ values }) => save(values)
115
+ }), [form, save]);
116
+ const { getValues, setValue } = form;
117
+ useEffect(() => {
118
+ const current = leaves(getValues());
119
+ for (const [leaf, value] of current) {
120
+ const next = storedValue(leaf);
121
+ if (sameJson(next, value)) continue;
122
+ setValue(leaf, next, {
123
+ shouldDirty: false,
124
+ shouldTouch: false,
125
+ shouldValidate: false
126
+ });
127
+ }
128
+ }, [
129
+ version,
130
+ store,
131
+ scope,
132
+ prefix,
133
+ storedValue,
134
+ getValues,
135
+ setValue
136
+ ]);
137
+ const rules = useRef(/* @__PURE__ */ new Map());
138
+ const mounted = useRef(/* @__PURE__ */ new Map());
139
+ const [, setReleased] = useState(0);
140
+ const release = useCallback((name) => {
141
+ rules.current.delete(name);
142
+ queueMicrotask(() => setReleased((count) => count + 1));
143
+ }, []);
144
+ const { register, unregister } = form;
145
+ const refs = useRef(/* @__PURE__ */ new Map());
146
+ const wrapped = useMemo(() => ((name, ruleOptions) => {
147
+ const required = ruleOptions?.required !== void 0 && ruleOptions.required !== false;
148
+ rules.current.set(name, required);
149
+ const registered = register(name, ruleOptions);
150
+ let entry = refs.current.get(name);
151
+ if (!entry) {
152
+ const created = {
153
+ latest: registered.ref,
154
+ ref: (element) => {
155
+ created.latest(element);
156
+ if (element === null) release(name);
157
+ else rules.current.set(name, rules.current.get(name) ?? required);
158
+ }
159
+ };
160
+ entry = created;
161
+ refs.current.set(name, entry);
162
+ }
163
+ entry.latest = registered.ref;
164
+ return {
165
+ ...registered,
166
+ ref: entry.ref
167
+ };
168
+ }), [register, release]);
169
+ const wrappedUnregister = useMemo(() => ((name, options) => {
170
+ const names = name === void 0 ? [...rules.current.keys()] : Array.isArray(name) ? name : [name];
171
+ for (const each of names) release(each);
172
+ unregister(name, options);
173
+ }), [unregister, release]);
174
+ const errors = form.formState.errors;
175
+ const sync = useCallback((errorOf) => {
176
+ const values = getValues();
177
+ const byLeaf = /* @__PURE__ */ new Map();
178
+ for (const [name, required] of rules.current) {
179
+ const leaf = leafOf(values, name);
180
+ const failure = errorOf(name);
181
+ const message = failure === void 0 ? void 0 : typeof failure.message === "string" && failure.message !== "" ? failure.message : required ? "This answer is required." : "Invalid value.";
182
+ const entry = byLeaf.get(leaf) ?? { required: false };
183
+ if (leaf === name && required) entry.required = true;
184
+ if (entry.message === void 0 && message !== void 0) entry.message = message;
185
+ byLeaf.set(leaf, entry);
186
+ }
187
+ for (const [leaf, { required, message }] of byLeaf) {
188
+ const fieldId = `${prefix}${leaf}`;
189
+ const label = stableLabels?.[leaf];
190
+ const registration = {
191
+ id: fieldId,
192
+ scope,
193
+ hook: "useForm",
194
+ initial: defaultOf(leaf),
195
+ ...label !== void 0 ? { label } : {},
196
+ ...required ? { required } : {},
197
+ ...sensitiveNames.has(leaf) ? { sensitive: true } : {},
198
+ ...message !== void 0 ? { error: message } : {}
199
+ };
200
+ const signature = JSON.stringify([
201
+ label,
202
+ required,
203
+ sensitiveNames.has(leaf),
204
+ message
205
+ ]);
206
+ const current = mounted.current.get(fieldId);
207
+ if (!current) {
208
+ mounted.current.set(fieldId, {
209
+ release: store.register(registration),
210
+ signature
211
+ });
212
+ if (message !== void 0) store.updateRegistration(registration);
213
+ } else if (current.signature !== signature) {
214
+ current.signature = signature;
215
+ store.updateRegistration(registration);
216
+ }
217
+ }
218
+ for (const [fieldId, entry] of mounted.current) {
219
+ if (byLeaf.has(fieldId.slice(prefix.length))) continue;
220
+ entry.release();
221
+ mounted.current.delete(fieldId);
222
+ }
223
+ }, [
224
+ prefix,
225
+ scope,
226
+ stableLabels,
227
+ sensitiveNames,
228
+ store,
229
+ defaultOf,
230
+ getValues
231
+ ]);
232
+ useEffect(() => sync((name) => get(errors, name)));
233
+ const { trigger, getFieldState } = form;
234
+ useEffect(() => store.beforeSubmit(async () => {
235
+ save(getValues());
236
+ await trigger();
237
+ sync((name) => getFieldState(name).error);
238
+ }), [
239
+ store,
240
+ trigger,
241
+ getFieldState,
242
+ sync,
243
+ save,
244
+ getValues
245
+ ]);
246
+ useEffect(() => () => {
247
+ for (const entry of mounted.current.values()) entry.release();
248
+ mounted.current.clear();
249
+ }, []);
250
+ return {
251
+ ...form,
252
+ register: wrapped,
253
+ unregister: wrappedUnregister
254
+ };
255
+ }
256
+ //#endregion
257
+ export { useForm };
258
+
259
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.js","names":["useHookForm"],"sources":["../src/form.ts"],"sourcesContent":["\"use client\";\n\n/**\n * `@mostra/react/form`: react-hook-form on Mostra fields (D52, D26). `useForm` is react-hook-form's\n * own, with one more option, `id`: every answer persists as the Mostra field `<id>.<path>` (a\n * field array as one answer, `<id>.items`), so a large form saves as the viewer types, resets\n * included, survives reloads and other tabs, converges with other writers, and arrives in\n * results nested under `id`. Its `required` rules and validation errors become the shell's\n * blockers.\n *\n * ```tsx\n * import { useForm } from \"@mostra/react/form\";\n *\n * const form = useForm({ id: \"intake\", defaultValues: { name: \"\", team: \"\" }, labels: { name: \"Your name\" } });\n * <input {...form.register(\"name\", { required: true })} />\n * ```\n */\nimport { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport {\n type FieldPath,\n type FieldValues,\n get,\n type RegisterOptions,\n set as setPath,\n type UseFormProps,\n type UseFormReturn,\n useForm as useHookForm,\n} from \"react-hook-form\";\nimport { useStore } from \"./hooks.ts\";\n\n/** Whether two JSON values are the same. */\nfunction sameJson(a: unknown, b: unknown): boolean {\n return a === b || JSON.stringify(a) === JSON.stringify(b);\n}\n\nimport { fieldKey } from \"./runtime/store.ts\";\n\n/** Whether a value is a plain object, whose keys the form's values nest by. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * A form's answers as Mostra fields (Claude review finding 1): one field per leaf, where a leaf is\n * any value that isn't a plain object, arrays included. A field array is one answer, so a row\n * removed is gone from that answer, never left behind as a field of its own, and `items` and\n * `items.1` never both exist.\n */\nfunction leaves(\n values: unknown,\n path = \"\",\n out = new Map<string, unknown>(),\n): Map<string, unknown> {\n if (isPlainObject(values)) {\n for (const [key, value] of Object.entries(values)) {\n leaves(value, path === \"\" ? key : `${path}.${key}`, out);\n }\n } else if (path !== \"\") {\n out.set(path, values);\n }\n return out;\n}\n\n/** The leaf a registered name lives in: the name itself, or the array it is inside. */\nfunction leafOf(values: unknown, name: string): string {\n const parts = name.split(\".\");\n let current: unknown = values;\n for (let index = 0; index < parts.length; index += 1) {\n if (Array.isArray(current)) return parts.slice(0, index).join(\".\");\n if (!isPlainObject(current)) return name;\n current = current[parts[index] as string];\n }\n return name;\n}\n\n/** Options of {@link useForm}: react-hook-form's, and the form's field ID. */\nexport interface MostraFormOptions<TFieldValues extends FieldValues>\n extends Omit<UseFormProps<TFieldValues>, \"values\"> {\n /** The field ID every field of the form is persisted under: `<id>.<name>` (D52). */\n readonly id: string;\n /** Labels for results and the shell's blockers, by field name. */\n readonly labels?: Readonly<Partial<Record<FieldPath<TFieldValues>, string>>>;\n /** `viewer` (default): the viewer's draft. `artifact`: shared state (D63). */\n readonly scope?: \"viewer\" | \"artifact\";\n /** Field names kept out of events and logs (D52), still delivered with the submission. */\n readonly sensitive?: readonly FieldPath<TFieldValues>[];\n}\n\n/**\n * react-hook-form's `useForm`, persisted to Mostra fields under `id` (D52). Everything else is\n * react-hook-form's own: `register`, `handleSubmit`, `formState`, resolvers.\n */\nexport function useForm<TFieldValues extends FieldValues = FieldValues>(\n options: MostraFormOptions<TFieldValues>,\n): UseFormReturn<TFieldValues> {\n const store = useStore();\n const { id, labels, scope = \"viewer\", sensitive, ...hookOptions } = options;\n const prefix = `${id}.`;\n const version = useSyncExternalStore(store.subscribe, store.version, store.version);\n\n // The form starts from its answers as Mostra has them, over its defaults. After that, every\n // answer follows the store: the store's value of a field is the viewer's own unsaved edit while\n // there is one, else the gateway's, so another writer's change reaches the input once the\n // viewer's edit landed, and never overwrites it before (GPT review finding 5).\n const [defaults] = useState(() => hookOptions.defaultValues);\n const defaultOf = useCallback((leaf: string): unknown => get(defaults ?? {}, leaf), [defaults]);\n const storedValue = useCallback(\n (leaf: string): unknown => store.value(fieldKey(scope, `${prefix}${leaf}`), defaultOf(leaf)),\n [store, scope, prefix, defaultOf],\n );\n const stored = useCallback(\n (leaf: string): boolean =>\n store.value(fieldKey(scope, `${prefix}${leaf}`), undefined) !== undefined,\n [store, scope, prefix],\n );\n const [initial] = useState(() => {\n const base =\n typeof defaults === \"object\" && defaults !== null\n ? structuredClone(defaults as TFieldValues)\n : ({} as TFieldValues);\n for (const fieldId of store.ids(scope)) {\n if (!fieldId.startsWith(prefix)) continue;\n setPath(base, fieldId.slice(prefix.length), store.value(fieldKey(scope, fieldId), undefined));\n }\n return base;\n });\n\n const form = useHookForm<TFieldValues>({ ...hookOptions, defaultValues: initial as never });\n\n // Labels usually come as an object literal: the same labels are the same registration.\n const labelsKey = JSON.stringify(labels ?? {});\n const stableLabels = useMemo(\n () => JSON.parse(labelsKey) as MostraFormOptions<TFieldValues>[\"labels\"],\n [labelsKey],\n );\n const sensitiveNames = useMemo(() => new Set<string>(sensitive ?? []), [sensitive]);\n\n // Every change saves the answers that differ from what Mostra holds, leaf by leaf: a typed\n // value, a row appended or removed, and a `reset()` alike, so what the viewer sees is what a\n // submit sends (Claude review findings 1 and 2). An answer still at its default and never\n // stored stays unstored: a default is written only before a submit (D110).\n const save = useCallback(\n (values: unknown): void => {\n const current = leaves(values);\n for (const [leaf, value] of current) {\n const key = fieldKey(scope, `${prefix}${leaf}`);\n if (!store.writable(key)) continue;\n if (stored(leaf) ? sameJson(value, storedValue(leaf)) : sameJson(value, defaultOf(leaf))) {\n continue;\n }\n const label = stableLabels?.[leaf as FieldPath<TFieldValues>];\n store.set(scope, `${prefix}${leaf}`, value, {\n ...(label !== undefined ? { label } : {}),\n ...(sensitiveNames.has(leaf) ? { sensitive: true } : {}),\n });\n }\n // A stored answer the form doesn't have is left alone: it may be an answer an earlier\n // version asked for, which is kept and delivered as not carried over (D42).\n },\n [store, scope, prefix, stored, storedValue, defaultOf, stableLabels, sensitiveNames],\n );\n useEffect(\n () =>\n form.subscribe({\n formState: { values: true },\n callback: ({ values }) => save(values),\n }),\n [form, save],\n );\n\n // Answers that changed in the store (another writer, another tab, a snapshot) reach the form,\n // leaf by leaf; the store's own value coming back isn't saved again (`save` finds no change).\n const { getValues, setValue } = form;\n // `version` stands for the store's state, which the effect reads through `store`.\n // biome-ignore lint/correctness/useExhaustiveDependencies: as above.\n useEffect(() => {\n // Only the form's own answers: a stored answer it doesn't have (an earlier version's) stays\n // out of its values.\n const current = leaves(getValues());\n for (const [leaf, value] of current) {\n const next = storedValue(leaf);\n if (sameJson(next, value)) continue;\n setValue(leaf as FieldPath<TFieldValues>, next as never, {\n shouldDirty: false,\n shouldTouch: false,\n shouldValidate: false,\n });\n }\n }, [version, store, scope, prefix, storedValue, getValues, setValue]);\n\n // Registered fields become Mostra registrations of the leaves they live in, so the shell lists\n // their blockers. Only mounted ones: a field whose input left the page, or that `unregister`\n // removed, is released, so it neither blocks a submit nor has its default written (D110, GPT\n // review finding 11). A field inside a field array registers its array: its own rules run in\n // react-hook-form, whose errors block the submit (D106).\n const rules = useRef(new Map<string, boolean>());\n const mounted = useRef(new Map<string, { release: () => void; signature: string }>());\n // Bumped when a field is released: the render that follows lets its registration go.\n const [, setReleased] = useState(0);\n const release = useCallback((name: string): void => {\n rules.current.delete(name);\n // Inside React's commit (a ref callback): the store hears of it after, never re-entering it.\n queueMicrotask(() => setReleased((count) => count + 1));\n }, []);\n const { register, unregister } = form;\n // One ref callback per field, so React calls it on mount and unmount only, not every render.\n const refs = useRef(\n new Map<string, { latest: (element: unknown) => void; ref: (element: unknown) => void }>(),\n );\n const wrapped = useMemo(\n () =>\n ((name: FieldPath<TFieldValues>, ruleOptions?: RegisterOptions<TFieldValues>) => {\n const required = ruleOptions?.required !== undefined && ruleOptions.required !== false;\n rules.current.set(name, required);\n const registered = register(name, ruleOptions);\n let entry = refs.current.get(name);\n if (!entry) {\n const created = {\n latest: registered.ref as (element: unknown) => void,\n ref: (element: unknown): void => {\n created.latest(element);\n if (element === null) release(name);\n else rules.current.set(name, rules.current.get(name) ?? required);\n },\n };\n entry = created;\n refs.current.set(name, entry);\n }\n entry.latest = registered.ref as (element: unknown) => void;\n return { ...registered, ref: entry.ref };\n }) as UseFormReturn<TFieldValues>[\"register\"],\n [register, release],\n );\n const wrappedUnregister = useMemo(\n () =>\n ((name?: FieldPath<TFieldValues> | readonly FieldPath<TFieldValues>[], options?: never) => {\n const names =\n name === undefined ? [...rules.current.keys()] : Array.isArray(name) ? name : [name];\n for (const each of names) release(each as string);\n unregister(name as never, options);\n }) as UseFormReturn<TFieldValues>[\"unregister\"],\n [unregister, release],\n );\n const errors = form.formState.errors;\n // Registered on the first render that names a field, updated only when a rule, label or error\n // changes, and released when no mounted field lives in the leaf: re-registering on every\n // render would never settle.\n const sync = useCallback(\n (errorOf: (name: string) => unknown): void => {\n const values = getValues();\n const byLeaf = new Map<string, { required: boolean; message?: string }>();\n for (const [name, required] of rules.current) {\n const leaf = leafOf(values, name);\n const failure = errorOf(name) as { message?: unknown } | undefined;\n const message =\n failure === undefined\n ? undefined\n : typeof failure.message === \"string\" && failure.message !== \"\"\n ? failure.message\n : required\n ? \"This answer is required.\"\n : \"Invalid value.\";\n const entry = byLeaf.get(leaf) ?? { required: false };\n // A required rule inside an array is react-hook-form's to check, not the leaf's.\n if (leaf === name && required) entry.required = true;\n if (entry.message === undefined && message !== undefined) entry.message = message;\n byLeaf.set(leaf, entry);\n }\n for (const [leaf, { required, message }] of byLeaf) {\n const fieldId = `${prefix}${leaf}`;\n const label = stableLabels?.[leaf as FieldPath<TFieldValues>];\n const registration = {\n id: fieldId,\n scope,\n hook: \"useForm\",\n initial: defaultOf(leaf),\n ...(label !== undefined ? { label } : {}),\n ...(required ? { required } : {}),\n ...(sensitiveNames.has(leaf) ? { sensitive: true } : {}),\n ...(message !== undefined ? { error: message } : {}),\n };\n const signature = JSON.stringify([label, required, sensitiveNames.has(leaf), message]);\n const current = mounted.current.get(fieldId);\n if (!current) {\n mounted.current.set(fieldId, { release: store.register(registration), signature });\n if (message !== undefined) store.updateRegistration(registration);\n } else if (current.signature !== signature) {\n current.signature = signature;\n store.updateRegistration(registration);\n }\n }\n for (const [fieldId, entry] of mounted.current) {\n if (byLeaf.has(fieldId.slice(prefix.length))) continue;\n entry.release();\n mounted.current.delete(fieldId);\n }\n },\n [prefix, scope, stableLabels, sensitiveNames, store, defaultOf, getValues],\n );\n useEffect(() => sync((name) => get(errors, name)));\n // react-hook-form validates on submit unless told otherwise; before either channel's submit\n // it validates now, so its errors are the submit's blockers (D106: the client checks), and\n // every answer the viewer sees is saved first.\n const { trigger, getFieldState } = form;\n useEffect(\n () =>\n store.beforeSubmit(async () => {\n save(getValues());\n await trigger();\n sync((name) => getFieldState(name as FieldPath<TFieldValues>).error);\n }),\n [store, trigger, getFieldState, sync, save, getValues],\n );\n useEffect(\n () => () => {\n for (const entry of mounted.current.values()) entry.release();\n mounted.current.clear();\n },\n [],\n );\n\n // A new object each render: react-hook-form renews `formState`'s proxy every render.\n return { ...form, register: wrapped, unregister: wrappedUnregister };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+BA,SAAS,SAAS,GAAY,GAAqB;CACjD,OAAO,MAAM,KAAK,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AAC1D;;AAKA,SAAS,cAAc,OAAkD;CACvE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG,OAAO;CAChF,MAAM,QAAQ,OAAO,eAAe,KAAK;CACzC,OAAO,UAAU,OAAO,aAAa,UAAU;AACjD;;;;;;;AAQA,SAAS,OACP,QACA,OAAO,IACP,sBAAM,IAAI,IAAqB,GACT;CACtB,IAAI,cAAc,MAAM,GACtB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAC9C,OAAO,OAAO,SAAS,KAAK,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG;MAEpD,IAAI,SAAS,IAClB,IAAI,IAAI,MAAM,MAAM;CAEtB,OAAO;AACT;;AAGA,SAAS,OAAO,QAAiB,MAAsB;CACrD,MAAM,QAAQ,KAAK,MAAM,GAAG;CAC5B,IAAI,UAAmB;CACvB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;EACpD,IAAI,MAAM,QAAQ,OAAO,GAAG,OAAO,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG;EACjE,IAA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