trama-forms 0.1.2 → 0.2.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/README.md +1 -1
- package/dist/react/async.d.ts +3 -3
- package/dist/react/async.js +52 -34
- package/dist/react/coverage.d.ts +10 -0
- package/dist/react/coverage.js +12 -0
- package/dist/react/field.d.ts +9 -1
- package/dist/react/field.js +50 -23
- package/dist/react/form-state.d.ts +1 -0
- package/dist/react/form-state.js +25 -14
- package/dist/react/index.js +1 -0
- package/dist/react/opening.js +6 -1
- package/dist/react/outputs.d.ts +1 -0
- package/dist/react/outputs.js +19 -10
- package/dist/react/render.d.ts +1 -1
- package/dist/react/render.js +6 -18
- package/dist/react/rows.js +21 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ pnpm run docs:dev
|
|
|
44
44
|
|
|
45
45
|
## Development
|
|
46
46
|
|
|
47
|
-
The pnpm version is pinned in `packageManager`, and dependencies are pinned in `pnpm-lock.yaml`. Use Node 26.9.0 (`.node-version`) or later and pnpm 12.4.2
|
|
47
|
+
The pnpm version is pinned in `packageManager`, and dependencies are pinned in `pnpm-lock.yaml`. Use Node 26.9.0 (`.node-version`) or later and pnpm 12.4.2 for development and verification. The React binding supports server rendering and hydration. General production use in Node is outside the runtime contract. There is no guarantee of support for CommonJS or older browsers.
|
|
48
48
|
|
|
49
49
|
```sh
|
|
50
50
|
pnpm run check
|
package/dist/react/async.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ComponentType } from "react";
|
|
2
|
-
import
|
|
2
|
+
import { type FieldSource } from "./field.js";
|
|
3
3
|
import type { CommonFieldProps } from "./props.js";
|
|
4
|
-
export declare const AsyncField: ({ renderer,
|
|
4
|
+
export declare const AsyncField: ({ renderer, source, ...props }: CommonFieldProps<unknown> & {
|
|
5
5
|
readonly renderer: ComponentType<CommonFieldProps<unknown>>;
|
|
6
|
-
readonly
|
|
6
|
+
readonly source: FieldSource;
|
|
7
7
|
}) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
package/dist/react/async.js
CHANGED
|
@@ -1,67 +1,85 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { openingOf } from "./field.js";
|
|
5
|
+
import { sameEntries } from "./form-state.js";
|
|
4
6
|
// Creates the option list of its view, from the session or from the handle of
|
|
5
7
|
// a row, which only a field that is not hidden has, and adds it to the props
|
|
6
|
-
// of the renderer with actions that keep their identity.
|
|
8
|
+
// of the renderer with actions that keep their identity. The server and the
|
|
9
|
+
// hydration render the list of the opening, when its params then differ.
|
|
7
10
|
export const AsyncField = (t0) => {
|
|
8
|
-
const $ = _c(
|
|
9
|
-
let lists;
|
|
11
|
+
const $ = _c(21);
|
|
10
12
|
let props;
|
|
11
13
|
let renderer;
|
|
14
|
+
let source;
|
|
12
15
|
if ($[0] !== t0) {
|
|
13
|
-
({renderer,
|
|
16
|
+
({renderer, source, ...props} = t0);
|
|
14
17
|
$[0] = t0;
|
|
15
|
-
$[1] =
|
|
16
|
-
$[2] =
|
|
17
|
-
$[3] =
|
|
18
|
+
$[1] = props;
|
|
19
|
+
$[2] = renderer;
|
|
20
|
+
$[3] = source;
|
|
18
21
|
} else {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
props = $[1];
|
|
23
|
+
renderer = $[2];
|
|
24
|
+
source = $[3];
|
|
22
25
|
}
|
|
23
26
|
let t1;
|
|
24
|
-
if ($[4] !==
|
|
25
|
-
t1 = () =>
|
|
26
|
-
$[4] =
|
|
27
|
-
$[5] =
|
|
27
|
+
if ($[4] !== props.name || $[5] !== source) {
|
|
28
|
+
t1 = () => source.list(props.name);
|
|
29
|
+
$[4] = props.name;
|
|
30
|
+
$[5] = source;
|
|
28
31
|
$[6] = t1;
|
|
29
32
|
} else {
|
|
30
33
|
t1 = $[6];
|
|
31
34
|
}
|
|
32
35
|
const [list] = useState(t1);
|
|
33
|
-
const snapshot = useSyncExternalStore(list.subscribe, list.getSnapshot);
|
|
34
36
|
let t2;
|
|
35
|
-
if ($[7] !== list
|
|
36
|
-
t2 =
|
|
37
|
+
if ($[7] !== list || $[8] !== props.name || $[9] !== source.owner) {
|
|
38
|
+
t2 = () => {
|
|
39
|
+
const current = list.getSnapshot();
|
|
40
|
+
const opened = openingOf(source.owner)?.lists.get(props.name);
|
|
41
|
+
return opened === undefined || sameEntries(opened, current) ? current : opened;
|
|
42
|
+
};
|
|
43
|
+
$[7] = list;
|
|
44
|
+
$[8] = props.name;
|
|
45
|
+
$[9] = source.owner;
|
|
46
|
+
$[10] = t2;
|
|
47
|
+
} else {
|
|
48
|
+
t2 = $[10];
|
|
49
|
+
}
|
|
50
|
+
const server = t2;
|
|
51
|
+
const snapshot = useSyncExternalStore(list.subscribe, list.getSnapshot, server);
|
|
52
|
+
let t3;
|
|
53
|
+
if ($[11] !== list.more || $[12] !== list.open || $[13] !== list.retry || $[14] !== list.search || $[15] !== snapshot) {
|
|
54
|
+
t3 = Object.freeze({
|
|
37
55
|
...snapshot,
|
|
38
56
|
open: list.open,
|
|
39
57
|
search: list.search,
|
|
40
58
|
more: list.more,
|
|
41
59
|
retry: list.retry
|
|
42
60
|
});
|
|
43
|
-
$[
|
|
44
|
-
$[
|
|
45
|
-
$[
|
|
46
|
-
$[
|
|
47
|
-
$[
|
|
48
|
-
$[
|
|
61
|
+
$[11] = list.more;
|
|
62
|
+
$[12] = list.open;
|
|
63
|
+
$[13] = list.retry;
|
|
64
|
+
$[14] = list.search;
|
|
65
|
+
$[15] = snapshot;
|
|
66
|
+
$[16] = t3;
|
|
49
67
|
} else {
|
|
50
|
-
|
|
68
|
+
t3 = $[16];
|
|
51
69
|
}
|
|
52
|
-
const view =
|
|
53
|
-
let
|
|
54
|
-
if ($[
|
|
55
|
-
|
|
70
|
+
const view = t3;
|
|
71
|
+
let t4;
|
|
72
|
+
if ($[17] !== props || $[18] !== renderer || $[19] !== view) {
|
|
73
|
+
t4 = jsx(renderer, {
|
|
56
74
|
...props,
|
|
57
75
|
list: view
|
|
58
76
|
});
|
|
59
|
-
$[
|
|
60
|
-
$[
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
77
|
+
$[17] = props;
|
|
78
|
+
$[18] = renderer;
|
|
79
|
+
$[19] = view;
|
|
80
|
+
$[20] = t4;
|
|
63
81
|
} else {
|
|
64
|
-
|
|
82
|
+
t4 = $[20];
|
|
65
83
|
}
|
|
66
|
-
return
|
|
84
|
+
return t4;
|
|
67
85
|
};
|
package/dist/react/coverage.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { FieldDefinition, FormDefinition, Loader } from "../core/index.js";
|
|
2
2
|
import type { ShowErrors } from "./visible-messages.js";
|
|
3
|
+
export declare const listed: {
|
|
4
|
+
text: false;
|
|
5
|
+
number: false;
|
|
6
|
+
checkbox: false;
|
|
7
|
+
select: false;
|
|
8
|
+
async: true;
|
|
9
|
+
date: false;
|
|
10
|
+
multiSelect: false;
|
|
11
|
+
multiAsync: true;
|
|
12
|
+
};
|
|
3
13
|
export type RendererTable = Readonly<Record<string, unknown>>;
|
|
4
14
|
type Forms = {
|
|
5
15
|
readonly field: Readonly<Record<string, unknown>>;
|
package/dist/react/coverage.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Whether the renderer of each field type takes the list of its view, as its
|
|
2
|
+
// props say.
|
|
3
|
+
export const listed = {
|
|
4
|
+
text: false,
|
|
5
|
+
number: false,
|
|
6
|
+
checkbox: false,
|
|
7
|
+
select: false,
|
|
8
|
+
async: true,
|
|
9
|
+
date: false,
|
|
10
|
+
multiSelect: false,
|
|
11
|
+
multiAsync: true
|
|
12
|
+
};
|
|
1
13
|
// The subtype of a field, undefined for a field of a base type.
|
|
2
14
|
export const subtypeOf = (item) => item.subtype;
|
|
3
15
|
// How a diagnostic names the subtype of a field.
|
package/dist/react/field.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ShowErrors } from "./visible-messages.js";
|
|
2
|
-
import type { FieldDefinition, FormDefinition, Option, OptionList, RowHandle, Session } from "../core/index.js";
|
|
2
|
+
import type { FieldDefinition, FormDefinition, Option, OptionList, OptionListSnapshot, RowHandle, Session } from "../core/index.js";
|
|
3
3
|
export type FieldSource = {
|
|
4
4
|
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
5
5
|
readonly subscribe: (listener: () => void) => () => void;
|
|
@@ -45,12 +45,20 @@ export type Selection = {
|
|
|
45
45
|
export declare const sessionSource: (session: Session<FormDefinition>) => FieldSource;
|
|
46
46
|
export declare const sourceOf: (props: object) => FieldSource;
|
|
47
47
|
export declare const rowSource: (row: RowHandle) => FieldSource;
|
|
48
|
+
type Opened = {
|
|
49
|
+
readonly snapshot: unknown;
|
|
50
|
+
readonly lists: ReadonlyMap<string, OptionListSnapshot<Option>>;
|
|
51
|
+
};
|
|
52
|
+
export declare const openingOf: (owner: object) => Opened | undefined;
|
|
53
|
+
export declare const openedSnapshot: <S>(owner: object, current: () => S) => S;
|
|
54
|
+
export declare const rememberOpening: (session: Session<FormDefinition>) => void;
|
|
48
55
|
export declare const useField: (source: FieldSource, name: string, policy: ShowErrors) => {
|
|
49
56
|
id: string;
|
|
50
57
|
selection: Selection | undefined;
|
|
51
58
|
view: {
|
|
52
59
|
subscribe: (listener: () => void) => () => void;
|
|
53
60
|
select: () => Selection | undefined;
|
|
61
|
+
serverSelect: () => Selection | undefined;
|
|
54
62
|
report: (message?: string) => void;
|
|
55
63
|
edit: (next: unknown) => void;
|
|
56
64
|
touch: () => void;
|
package/dist/react/field.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useId, useSyncExternalStore } from "react";
|
|
3
3
|
import { showsErrors, visibleErrors } from "./visible-messages.js";
|
|
4
|
-
import {
|
|
4
|
+
import { listed } from "./coverage.js";
|
|
5
|
+
import { rememberOutputs, sessionKey } from "./outputs.js";
|
|
5
6
|
const sessions = new WeakMap();
|
|
6
7
|
export const sessionSource = (session) => {
|
|
7
8
|
let source = sessions.get(session);
|
|
@@ -53,39 +54,65 @@ export const rowSource = (row) => {
|
|
|
53
54
|
}
|
|
54
55
|
return source;
|
|
55
56
|
};
|
|
57
|
+
const openings = new WeakMap();
|
|
58
|
+
export const openingOf = (owner) => openings.get(owner);
|
|
59
|
+
// What a server snapshot reads: the opening of a session or row the binding
|
|
60
|
+
// remembered, or else its current snapshot.
|
|
61
|
+
export const openedSnapshot = (owner, current) => {
|
|
62
|
+
const opened = openings.get(owner);
|
|
63
|
+
return opened === undefined ? current() : opened.snapshot;
|
|
64
|
+
};
|
|
65
|
+
export const rememberOpening = (session) => {
|
|
66
|
+
if (openings.has(session)) return;
|
|
67
|
+
remember(sessionSource(session));
|
|
68
|
+
const keysBy = session.getSnapshot().rows;
|
|
69
|
+
for (const [collection, keys] of Object.entries(keysBy)) for (const key of keys) remember(rowSource(session.row(collection, key)));
|
|
70
|
+
rememberOutputs(session);
|
|
71
|
+
};
|
|
72
|
+
const remember = (source) => {
|
|
73
|
+
const lists = new Map();
|
|
74
|
+
for (const [name, item] of Object.entries(source.fields)) if (listed[item.type]) lists.set(name, source.list(name).getSnapshot());
|
|
75
|
+
openings.set(source.owner, {
|
|
76
|
+
snapshot: source.snapshot(),
|
|
77
|
+
lists
|
|
78
|
+
});
|
|
79
|
+
};
|
|
56
80
|
// The view of one field of a source, the same while the Field keeps its
|
|
57
81
|
// source, name and policy.
|
|
58
82
|
// - Its selection keeps its object while the value, the state object, the
|
|
59
83
|
// reset version and the errors shown do not change: an attempt renders
|
|
60
|
-
// again only the fields whose errors it reveals.
|
|
84
|
+
// again only the fields whose errors it reveals. The server and the
|
|
85
|
+
// hydration select from the opening with the same held selection, so React
|
|
86
|
+
// renders again after hydrating only the fields that changed since.
|
|
61
87
|
// - Its commands: the source accepts every edit, and the binding ignores one
|
|
62
88
|
// from the renderer while the field is disabled or read-only.
|
|
63
89
|
const viewOf = (source, name, policy) => {
|
|
64
90
|
let selected;
|
|
65
91
|
let attempted = false;
|
|
66
92
|
const { subscribe, report } = pendingInput(source, name);
|
|
93
|
+
const selectFrom = (snapshot) => {
|
|
94
|
+
if (snapshot === undefined) return selected = undefined;
|
|
95
|
+
const value = snapshot.values[name];
|
|
96
|
+
const state = snapshot.fieldStates[name];
|
|
97
|
+
const { resetVersion } = snapshot;
|
|
98
|
+
const scope = source.attempted(snapshot);
|
|
99
|
+
const held = selected;
|
|
100
|
+
const same = held !== undefined && Object.is(held.value, value) && held.state === state && held.resetVersion === resetVersion;
|
|
101
|
+
if (same && attempted === scope) return held;
|
|
102
|
+
attempted = scope;
|
|
103
|
+
const errors = visibleErrors(state, showsErrors(policy, state.touched, scope), held?.errors);
|
|
104
|
+
if (same && held.errors === errors) return held;
|
|
105
|
+
return selected = {
|
|
106
|
+
value,
|
|
107
|
+
state,
|
|
108
|
+
resetVersion,
|
|
109
|
+
errors
|
|
110
|
+
};
|
|
111
|
+
};
|
|
67
112
|
return {
|
|
68
113
|
subscribe,
|
|
69
|
-
select: () =>
|
|
70
|
-
|
|
71
|
-
if (snapshot === undefined) return selected = undefined;
|
|
72
|
-
const value = snapshot.values[name];
|
|
73
|
-
const state = snapshot.fieldStates[name];
|
|
74
|
-
const { resetVersion } = snapshot;
|
|
75
|
-
const scope = source.attempted(snapshot);
|
|
76
|
-
const held = selected;
|
|
77
|
-
const same = held !== undefined && Object.is(held.value, value) && held.state === state && held.resetVersion === resetVersion;
|
|
78
|
-
if (same && attempted === scope) return held;
|
|
79
|
-
attempted = scope;
|
|
80
|
-
const errors = visibleErrors(state, showsErrors(policy, state.touched, scope), held?.errors);
|
|
81
|
-
if (same && held.errors === errors) return held;
|
|
82
|
-
return selected = {
|
|
83
|
-
value,
|
|
84
|
-
state,
|
|
85
|
-
resetVersion,
|
|
86
|
-
errors
|
|
87
|
-
};
|
|
88
|
-
},
|
|
114
|
+
select: () => selectFrom(source.snapshot()),
|
|
115
|
+
serverSelect: () => selectFrom(openedSnapshot(source.owner, source.snapshot)),
|
|
89
116
|
report,
|
|
90
117
|
edit: (next) => {
|
|
91
118
|
const state = source.snapshot()?.fieldStates[name];
|
|
@@ -164,7 +191,7 @@ export const useField = (source, name, policy) => {
|
|
|
164
191
|
t0 = $[3];
|
|
165
192
|
}
|
|
166
193
|
const view = t0;
|
|
167
|
-
const selection = useSyncExternalStore(view.subscribe, view.select);
|
|
194
|
+
const selection = useSyncExternalStore(view.subscribe, view.select, view.serverSelect);
|
|
168
195
|
let t1;
|
|
169
196
|
if ($[4] !== source.owner) {
|
|
170
197
|
t1 = sessionKey(source.owner);
|
|
@@ -11,4 +11,5 @@ type Scope = {
|
|
|
11
11
|
type View = Omit<Scope, "externalErrors"> & Readonly<Record<string, unknown>>;
|
|
12
12
|
type Source = Session<FormDefinition> | RowHandle;
|
|
13
13
|
export declare const formStateOf: (policy: ShowErrors) => (source: Source, collection?: string) => View | undefined;
|
|
14
|
+
export declare const sameEntries: (a: object, b: object) => boolean;
|
|
14
15
|
export {};
|
package/dist/react/form-state.js
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
// It keeps its object while that content does not change, so the hook of a
|
|
6
6
|
// row does not render for another, and a removed row gives undefined.
|
|
7
7
|
import { useMemo, useSyncExternalStore } from "react";
|
|
8
|
+
import { openedSnapshot } from "./field.js";
|
|
8
9
|
import { showsErrors, visibleErrors } from "./visible-messages.js";
|
|
9
10
|
export const formStateOf = (policy) => (source, collection) => {
|
|
10
11
|
if ("definition" in source && collection !== undefined && !hasCollection(source, collection)) throw new Error(`Unknown collection "${collection}"`);
|
|
11
12
|
const select = useMemo(() => selectorOf(source, collection, policy), [source, collection]);
|
|
12
|
-
return useSyncExternalStore(source.subscribe, select);
|
|
13
|
+
return useSyncExternalStore(source.subscribe, select.current, select.server);
|
|
13
14
|
};
|
|
14
15
|
const hasCollection = (session, name) => Object.hasOwn(session.definition.collections, name);
|
|
15
16
|
// What a scope reads of the snapshot of its source: the form without its
|
|
@@ -17,7 +18,8 @@ const hasCollection = (session, name) => Object.hasOwn(session.definition.collec
|
|
|
17
18
|
// version and queries, and whether it shows its own errors. Its view has the
|
|
18
19
|
// errors shown in place of the two lists, and keeps its object while the
|
|
19
20
|
// scope read and whether it shows are the same, and, when they are not, while
|
|
20
|
-
// its content is.
|
|
21
|
+
// its content is. The server and the hydration read the opening of the
|
|
22
|
+
// source through the same view.
|
|
21
23
|
const selectorOf = (source, collection, policy) => {
|
|
22
24
|
let held;
|
|
23
25
|
let heldShown = false;
|
|
@@ -31,22 +33,28 @@ const selectorOf = (source, collection, policy) => {
|
|
|
31
33
|
...withoutKeys(scope, omitted),
|
|
32
34
|
errors
|
|
33
35
|
};
|
|
34
|
-
if (last === undefined || !
|
|
36
|
+
if (last === undefined || !sameEntries(last, candidate)) last = Object.freeze(candidate);
|
|
35
37
|
return last;
|
|
36
38
|
};
|
|
37
|
-
if ("definition" in source)
|
|
38
|
-
const { form }
|
|
39
|
-
|
|
39
|
+
if ("definition" in source) {
|
|
40
|
+
const read = ({ form }) => {
|
|
41
|
+
if (collection === undefined) return view(form, form.attempted, ofForm);
|
|
40
42
|
const scope = form.collections[collection];
|
|
41
43
|
return view(scope, form.attempted, external);
|
|
42
|
-
}
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
current: () => read(source.getSnapshot()),
|
|
47
|
+
server: () => read(openedSnapshot(source, () => source.getSnapshot()))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const read = (row) => {
|
|
47
51
|
if (row === undefined) return last = undefined;
|
|
48
52
|
return view(row, showsErrors(policy, row.touched, row.attempted), ofRow);
|
|
49
53
|
};
|
|
54
|
+
return {
|
|
55
|
+
current: () => read(source.getSnapshot()),
|
|
56
|
+
server: () => read(openedSnapshot(source, () => source.getSnapshot()))
|
|
57
|
+
};
|
|
50
58
|
};
|
|
51
59
|
// What a view leaves out of each scope: the external errors, which are among
|
|
52
60
|
// its errors, and what is not of the scope alone.
|
|
@@ -64,7 +72,10 @@ const withoutKeys = (scope, keys) => {
|
|
|
64
72
|
for (const key of Object.keys(scope)) if (!keys.includes(key)) rest[key] = scope[key];
|
|
65
73
|
return rest;
|
|
66
74
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
// Whether two objects have the same keys with the same values.
|
|
76
|
+
export const sameEntries = (a, b) => {
|
|
77
|
+
const left = a;
|
|
78
|
+
const right = b;
|
|
79
|
+
const keys = Object.keys(right);
|
|
80
|
+
return keys.length === Object.keys(left).length && keys.every((key) => left[key] === right[key]);
|
|
70
81
|
};
|
package/dist/react/index.js
CHANGED
package/dist/react/opening.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useEffect, useLayoutEffect, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { createSession as createCoreSession } from "../core/index.js";
|
|
4
|
+
import { rememberOpening } from "./field.js";
|
|
4
5
|
// The core requires scope for a form with async fields and the context a form
|
|
5
6
|
// declares, which a generic definition cannot show; useFormSession requires
|
|
6
7
|
// them in types.
|
|
@@ -46,6 +47,10 @@ class Opening {
|
|
|
46
47
|
return this.#result.status !== "ready" || sameData(this.#context, context);
|
|
47
48
|
}
|
|
48
49
|
getSnapshot = () => this.#result;
|
|
50
|
+
getServerSnapshot = () => {
|
|
51
|
+
if (this.#result.status === "ready") rememberOpening(this.#result.session);
|
|
52
|
+
return this.#result;
|
|
53
|
+
};
|
|
49
54
|
subscribe = (listener) => {
|
|
50
55
|
this.#listeners.add(listener);
|
|
51
56
|
return () => {
|
|
@@ -193,7 +198,7 @@ export const useSession = (definition, options, loader) => {
|
|
|
193
198
|
t4 = $[12];
|
|
194
199
|
}
|
|
195
200
|
useEffect(t4);
|
|
196
|
-
return useSyncExternalStore(opening.subscribe, opening.getSnapshot);
|
|
201
|
+
return useSyncExternalStore(opening.subscribe, opening.getSnapshot, opening.getServerSnapshot);
|
|
197
202
|
};
|
|
198
203
|
// Whether two values are equal as data, as the core compares them: the
|
|
199
204
|
// binding reaches the core only through its public entry.
|
package/dist/react/outputs.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ type BoundaryProps<D extends FormDefinition> = {
|
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
};
|
|
8
8
|
export declare const sessionKey: (session: object) => number;
|
|
9
|
+
export declare const rememberOutputs: (session: Session<FormDefinition>) => void;
|
|
9
10
|
export declare const OutputBoundary: <D extends FormDefinition>(props: BoundaryProps<D>) => ReactNode;
|
|
10
11
|
export declare const useOutputs: <D extends FormDefinition>(session: Session<D>) => FormOutputs<D>;
|
|
11
12
|
export {};
|
package/dist/react/outputs.js
CHANGED
|
@@ -14,6 +14,21 @@ export const sessionKey = (session) => {
|
|
|
14
14
|
}
|
|
15
15
|
return key;
|
|
16
16
|
};
|
|
17
|
+
// The outputs of a session at its opening, which the server and the hydration
|
|
18
|
+
// render: the view of watchOutputs reads the evaluations it was given.
|
|
19
|
+
const openedOutputs = new WeakMap();
|
|
20
|
+
export const rememberOutputs = (session) => {
|
|
21
|
+
openedOutputs.set(session, outputsOf(session));
|
|
22
|
+
};
|
|
23
|
+
// The current outputs of a session: watchOutputs gives them to its observer
|
|
24
|
+
// at once.
|
|
25
|
+
const outputsOf = (session) => {
|
|
26
|
+
let current;
|
|
27
|
+
session.watchOutputs((outputs) => {
|
|
28
|
+
current = outputs;
|
|
29
|
+
})();
|
|
30
|
+
return current;
|
|
31
|
+
};
|
|
17
32
|
export const OutputBoundary = (props) => createElement(CatchOutput, {
|
|
18
33
|
...props,
|
|
19
34
|
key: sessionKey(props.session)
|
|
@@ -78,7 +93,7 @@ const RecoverOutput = (t0) => {
|
|
|
78
93
|
export const useOutputs = (session) => {
|
|
79
94
|
"use no memo";
|
|
80
95
|
const selection = selectOutputs(session);
|
|
81
|
-
const snapshot = useSyncExternalStore(selection.subscribe, selection.getSnapshot);
|
|
96
|
+
const snapshot = useSyncExternalStore(selection.subscribe, selection.getSnapshot, selection.getServerSnapshot);
|
|
82
97
|
useLayoutEffect(() => {
|
|
83
98
|
selection.finishRender();
|
|
84
99
|
});
|
|
@@ -89,20 +104,14 @@ const selectOutputs = (session) => {
|
|
|
89
104
|
failures.set(session, errors);
|
|
90
105
|
const names = new Set();
|
|
91
106
|
let tracking = true;
|
|
92
|
-
|
|
93
|
-
let current;
|
|
94
|
-
session.watchOutputs((outputs) => {
|
|
95
|
-
current = outputs;
|
|
96
|
-
})();
|
|
97
|
-
return current;
|
|
98
|
-
};
|
|
99
|
-
let snapshot = capture();
|
|
107
|
+
let snapshot = outputsOf(session);
|
|
100
108
|
const update = (current) => {
|
|
101
109
|
if ([...names].some((name) => !sameRead(snapshot, current, name))) snapshot = current;
|
|
102
110
|
return snapshot;
|
|
103
111
|
};
|
|
104
112
|
return {
|
|
105
|
-
getSnapshot: () => update(
|
|
113
|
+
getSnapshot: () => update(outputsOf(session)),
|
|
114
|
+
getServerSnapshot: () => snapshot = openedOutputs.get(session) ?? snapshot,
|
|
106
115
|
subscribe: (notify) => session.watchOutputs((current) => {
|
|
107
116
|
const previous = snapshot;
|
|
108
117
|
for (const name of names) read(current, name);
|
package/dist/react/render.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type RendererTable } from "./coverage.js";
|
|
|
2
2
|
import type { ShowErrors } from "./visible-messages.js";
|
|
3
3
|
import { type FieldSource } from "./field.js";
|
|
4
4
|
import type { AsyncFieldProps, CheckboxFieldProps, CommonFieldProps, DateFieldProps, MultiAsyncFieldProps, MultiSelectFieldProps, NumberFieldProps, SelectFieldProps, TextFieldProps, ViewProps } from "./props.js";
|
|
5
|
-
type Props = {
|
|
5
|
+
export type Props = {
|
|
6
6
|
text: TextFieldProps;
|
|
7
7
|
number: NumberFieldProps;
|
|
8
8
|
checkbox: CheckboxFieldProps;
|
package/dist/react/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { AsyncField } from "./async.js";
|
|
4
|
-
import { rendererOf, subtypeOf } from "./coverage.js";
|
|
4
|
+
import { listed, rendererOf, subtypeOf } from "./coverage.js";
|
|
5
5
|
import { useField } from "./field.js";
|
|
6
6
|
// What each field type adds to the common props of its renderer, from its
|
|
7
7
|
// definition and its state. Every field type of the core needs one, with a
|
|
@@ -27,18 +27,6 @@ export const typeProps = {
|
|
|
27
27
|
multiSelect: optionProps,
|
|
28
28
|
multiAsync: placeholderProps
|
|
29
29
|
};
|
|
30
|
-
// Whether the renderer of each field type takes the list of its view, as its
|
|
31
|
-
// props say.
|
|
32
|
-
const listed = {
|
|
33
|
-
text: false,
|
|
34
|
-
number: false,
|
|
35
|
-
checkbox: false,
|
|
36
|
-
select: false,
|
|
37
|
-
async: true,
|
|
38
|
-
date: false,
|
|
39
|
-
multiSelect: false,
|
|
40
|
-
multiAsync: true
|
|
41
|
-
};
|
|
42
30
|
// Renders the field name of a source, or nothing for a row that no longer
|
|
43
31
|
// exists or a hidden field. The props of a Field override the label and the
|
|
44
32
|
// placeholder of the state.
|
|
@@ -56,7 +44,7 @@ export const useFieldRenderer = (renderers, source, props, policy) => {
|
|
|
56
44
|
const { value, state, resetVersion, errors } = selection;
|
|
57
45
|
const t0 = props.label ?? state.label;
|
|
58
46
|
let t1;
|
|
59
|
-
if ($[0] !== errors || $[1] !== id || $[2] !== item || $[3] !== key || $[4] !== name || $[5] !== props.placeholder || $[6] !== renderers || $[7] !== resetVersion || $[8] !== source
|
|
47
|
+
if ($[0] !== errors || $[1] !== id || $[2] !== item || $[3] !== key || $[4] !== name || $[5] !== props.placeholder || $[6] !== renderers || $[7] !== resetVersion || $[8] !== source || $[9] !== state || $[10] !== t0 || $[11] !== value || $[12] !== view.edit || $[13] !== view.report || $[14] !== view.touch) {
|
|
60
48
|
const common = {
|
|
61
49
|
id,
|
|
62
50
|
name,
|
|
@@ -71,7 +59,7 @@ export const useFieldRenderer = (renderers, source, props, policy) => {
|
|
|
71
59
|
onBlur: view.touch,
|
|
72
60
|
onInputError: view.report
|
|
73
61
|
};
|
|
74
|
-
t1 = renderField(renderers, source
|
|
62
|
+
t1 = renderField(renderers, source, item, value, view.edit, common, {
|
|
75
63
|
placeholder: props.placeholder ?? state.placeholder,
|
|
76
64
|
state,
|
|
77
65
|
key: `${key}:${resetVersion}`
|
|
@@ -84,7 +72,7 @@ export const useFieldRenderer = (renderers, source, props, policy) => {
|
|
|
84
72
|
$[5] = props.placeholder;
|
|
85
73
|
$[6] = renderers;
|
|
86
74
|
$[7] = resetVersion;
|
|
87
|
-
$[8] = source
|
|
75
|
+
$[8] = source;
|
|
88
76
|
$[9] = state;
|
|
89
77
|
$[10] = t0;
|
|
90
78
|
$[11] = value;
|
|
@@ -100,7 +88,7 @@ export const useFieldRenderer = (renderers, source, props, policy) => {
|
|
|
100
88
|
// The element of the renderer, whose key, out of its props, remounts it with
|
|
101
89
|
// another source, name or reset: jsx takes the props as they are, without
|
|
102
90
|
// copying them.
|
|
103
|
-
const renderField = (renderers,
|
|
91
|
+
const renderField = (renderers, source, item, value, edit, common, { placeholder, state, key }) => {
|
|
104
92
|
const own = typeProps[item.type](item, placeholder, state);
|
|
105
93
|
const Renderer = rendererOf(renderers, item, `Field "${common.name}"`);
|
|
106
94
|
const props = {
|
|
@@ -113,7 +101,7 @@ const renderField = (renderers, lists, item, value, edit, common, { placeholder,
|
|
|
113
101
|
if (listed[item.type]) return jsx(AsyncField, {
|
|
114
102
|
...props,
|
|
115
103
|
renderer: Renderer,
|
|
116
|
-
|
|
104
|
+
source
|
|
117
105
|
}, key);
|
|
118
106
|
return jsx(Renderer, props, key);
|
|
119
107
|
};
|
package/dist/react/rows.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { openedSnapshot } from "./field.js";
|
|
3
4
|
// The keys of the rows of a collection, in visual order. The array keeps its
|
|
4
5
|
// identity while the rows of the collection and their order do not change, so
|
|
5
|
-
// a table that renders them does not render again on every key stroke.
|
|
6
|
+
// a table that renders them does not render again on every key stroke. The
|
|
7
|
+
// server and the hydration render the keys of the opening.
|
|
6
8
|
export const useRows = (session, collection) => {
|
|
7
|
-
const $ = _c(
|
|
9
|
+
const $ = _c(6);
|
|
8
10
|
let t0;
|
|
9
11
|
if ($[0] !== collection || $[1] !== session) {
|
|
10
|
-
t0 = () =>
|
|
11
|
-
const keys = session.getSnapshot().rows[collection];
|
|
12
|
-
if (keys === undefined) {
|
|
13
|
-
throw new Error(`Unknown collection "${collection}"`);
|
|
14
|
-
}
|
|
15
|
-
return keys;
|
|
16
|
-
};
|
|
12
|
+
t0 = () => keysOf(session.getSnapshot(), collection);
|
|
17
13
|
$[0] = collection;
|
|
18
14
|
$[1] = session;
|
|
19
15
|
$[2] = t0;
|
|
@@ -21,5 +17,20 @@ export const useRows = (session, collection) => {
|
|
|
21
17
|
t0 = $[2];
|
|
22
18
|
}
|
|
23
19
|
const select = t0;
|
|
24
|
-
|
|
20
|
+
let t1;
|
|
21
|
+
if ($[3] !== collection || $[4] !== session) {
|
|
22
|
+
t1 = () => keysOf(openedSnapshot(session, () => session.getSnapshot()), collection);
|
|
23
|
+
$[3] = collection;
|
|
24
|
+
$[4] = session;
|
|
25
|
+
$[5] = t1;
|
|
26
|
+
} else {
|
|
27
|
+
t1 = $[5];
|
|
28
|
+
}
|
|
29
|
+
const server = t1;
|
|
30
|
+
return useSyncExternalStore(session.subscribe, select, server);
|
|
31
|
+
};
|
|
32
|
+
const keysOf = (snapshot, collection) => {
|
|
33
|
+
const keys = snapshot.rows[collection];
|
|
34
|
+
if (keys === undefined) throw new Error(`Unknown collection "${collection}"`);
|
|
35
|
+
return keys;
|
|
25
36
|
};
|