vultus-core 0.5.3 → 0.5.4
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 +117 -1
- package/dist/FieldContext.d.ts +37 -1
- package/dist/FieldContext.d.ts.map +1 -1
- package/dist/FieldContext.js +68 -11
- package/dist/FieldContext.js.map +1 -1
- package/dist/fieldGroupValues.d.ts +63 -0
- package/dist/fieldGroupValues.d.ts.map +1 -0
- package/dist/fieldGroupValues.js +119 -0
- package/dist/fieldGroupValues.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/kindHooks.d.ts +23 -0
- package/dist/kindHooks.d.ts.map +1 -0
- package/dist/kindHooks.js +38 -0
- package/dist/kindHooks.js.map +1 -0
- package/dist/useArg.d.ts +6 -0
- package/dist/useArg.d.ts.map +1 -1
- package/dist/useArg.js +6 -2
- package/dist/useArg.js.map +1 -1
- package/dist/useFieldGroup.d.ts +80 -0
- package/dist/useFieldGroup.d.ts.map +1 -0
- package/dist/useFieldGroup.js +266 -0
- package/dist/useFieldGroup.js.map +1 -0
- package/dist/useStoredField.d.ts +8 -0
- package/dist/useStoredField.d.ts.map +1 -1
- package/dist/useStoredField.js +4 -2
- package/dist/useStoredField.js.map +1 -1
- package/package.json +1 -1
- package/src/FieldContext.tsx +73 -11
- package/src/fieldGroupValues.ts +169 -0
- package/src/index.ts +1 -0
- package/src/kindHooks.ts +52 -0
- package/src/useArg.ts +6 -2
- package/src/useFieldGroup.ts +346 -0
- package/src/useStoredField.ts +4 -2
package/dist/useArg.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface ArgControls<T> {
|
|
|
15
15
|
/** The href `set(value)` would produce, where the store supports it (a URL store); `undefined` otherwise. */
|
|
16
16
|
hrefFor(value: T): string | undefined;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The raw value a write needs for `value`: `undefined` (removes the key) when it equals the
|
|
20
|
+
* default, else its formatted form. Exported for the field group (useFieldGroup), which writes a
|
|
21
|
+
* store by the same rule; not part of the package's API.
|
|
22
|
+
*/
|
|
23
|
+
export declare function rawFor<T>(value: T, defaultValue: T, valueType: ValueType<T>): string | undefined;
|
|
18
24
|
/**
|
|
19
25
|
* An argument read from and written to the nearest ArgStore. An absent key reads as the default;
|
|
20
26
|
* writing the default removes the key.
|
package/dist/useArg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useArg.d.ts","sourceRoot":"","sources":["../src/useArg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,8GAA8G;AAC9G,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,6GAA6G;IAC7G,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;CACvC;
|
|
1
|
+
{"version":3,"file":"useArg.d.ts","sourceRoot":"","sources":["../src/useArg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,eAA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,KAAK,EAAE,CAAC,GAAG,SAAS,CAE3E;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAElE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,EAAE,YAAY,KAAK,IAAI,CAepF"}
|
package/dist/useArg.js
CHANGED
|
@@ -2,8 +2,12 @@ import { useCallback, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
|
2
2
|
import { useArgStore } from './ArgStoreContext.js';
|
|
3
3
|
import { useFieldContext } from './FieldContext.js';
|
|
4
4
|
import { resolveIn } from './resolve.js';
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The raw value a write needs for `value`: `undefined` (removes the key) when it equals the
|
|
7
|
+
* default, else its formatted form. Exported for the field group (useFieldGroup), which writes a
|
|
8
|
+
* store by the same rule; not part of the package's API.
|
|
9
|
+
*/
|
|
10
|
+
export function rawFor(value, defaultValue, valueType) {
|
|
7
11
|
return valueType.isEqual(value, defaultValue) ? undefined : valueType.format(value);
|
|
8
12
|
}
|
|
9
13
|
/**
|
package/dist/useArg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useArg.js","sourceRoot":"","sources":["../src/useArg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAoBzC
|
|
1
|
+
{"version":3,"file":"useArg.js","sourceRoot":"","sources":["../src/useArg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,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qB,CAAC,CAAC;YACnG,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;QACrE,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC,EACD,CAAC,KAAK,EAAE,GAAG,CAAC,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { UpdateMethod } from './argStore.js';
|
|
2
|
+
import type { FieldControls } from './field.js';
|
|
3
|
+
import { type FieldDefinition } from './kinds.js';
|
|
4
|
+
/** A field group's fields as one component runs them (see useFieldGroup). */
|
|
5
|
+
export interface FieldGroup {
|
|
6
|
+
/**
|
|
7
|
+
* Each field's controls, exactly as its kind's hook returns them, in definition order: what the
|
|
8
|
+
* widgets render. Typed `FieldControls`; for a kind's own controls, cast by kind
|
|
9
|
+
* (`group.byId.toc as OneOfTreeFieldControls<string>`).
|
|
10
|
+
*/
|
|
11
|
+
fields: FieldControls<any, any>[];
|
|
12
|
+
/** The same controls, by field id. */
|
|
13
|
+
byId: Record<string, FieldControls<any, any>>;
|
|
14
|
+
/**
|
|
15
|
+
* The fields' shown values by id (after the fallback rule), as of this render: a plain object,
|
|
16
|
+
* which keeps its identity until a shown value changes (an effect keyed on it runs only then).
|
|
17
|
+
*/
|
|
18
|
+
values: Readonly<Record<string, unknown>>;
|
|
19
|
+
/** Whether the field with this id shows its current default; an id not in the group throws. */
|
|
20
|
+
isDefault(id: string): boolean;
|
|
21
|
+
/** How many of the fields do not show their defaults ("more filters (3)"). */
|
|
22
|
+
changedCount: number;
|
|
23
|
+
/**
|
|
24
|
+
* Every field back to its default: no field keeps a value any more. Stored, one store write
|
|
25
|
+
* removes every field's key (`method`, 'replace' unless told otherwise); the group's own state
|
|
26
|
+
* ignores `method`.
|
|
27
|
+
*/
|
|
28
|
+
resetAll(method?: UpdateMethod): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs a list of field definitions together, as a group: every option function of each
|
|
32
|
+
* definition (but `initialValue`) receives `ctx.values`, the fields' shown values by id, beside
|
|
33
|
+
* the app's own field context, so a field's choices, bounds or visibility can follow another
|
|
34
|
+
* field. A field's default is its `initialValue` (which cannot read `values`), else its kind's
|
|
35
|
+
* implicit initial value from its options as they are now, so it moves with the fields those
|
|
36
|
+
* read. It throws, naming the field (and the option), for an option reading an id not in the
|
|
37
|
+
* group, two definitions with the same id and a mixed-boolean definition; naming the cycle for
|
|
38
|
+
* fields whose values depend on each other; and for an app context that already has `values`
|
|
39
|
+
* (`Field group: the field context already has 'values'; a field group provides it`).
|
|
40
|
+
*
|
|
41
|
+
* Storage, for the whole group, is the caller's choice. By default the group keeps the values in
|
|
42
|
+
* its own state, as a store keeps them: a field never set, or set to its current default, keeps
|
|
43
|
+
* nothing and shows its current default, which moves with the fields its options read. A kept
|
|
44
|
+
* value that another field's change made invalid shows the field's fallback, silently (that is
|
|
45
|
+
* how a group behaves, not bad input), and shows again once it is valid again; it is never
|
|
46
|
+
* rewritten. `resetAll()` clears every kept value (the update method is for a store; here it is
|
|
47
|
+
* ignored).
|
|
48
|
+
*
|
|
49
|
+
* With `{ stored: true }` the values live in the nearest ArgStore (the URL, localStorage) under
|
|
50
|
+
* each field's id, as useStoredField keeps a field there, all read in one subscription: an absent
|
|
51
|
+
* key reads as the field's current default, and a value equal to it is written as an absent key
|
|
52
|
+
* (`'replace'`). The default compared with is the one under the store's values at the moment of
|
|
53
|
+
* the write, as in the group's own state, so a write batched after another field's (in one
|
|
54
|
+
* event) compares with the default that one gives. The controls' `hrefFor` links a value
|
|
55
|
+
* through the store's `hrefFor` (`undefined` where the store has none), as rendered. The fallback
|
|
56
|
+
* rule is the same, and the stored value is never rewritten either, but a raw value that does not
|
|
57
|
+
* parse, or falls back, warns once, as useStoredField's does: an unparsable one reads as the
|
|
58
|
+
* current default. A raw value the group itself wrote does not warn (a write chained after
|
|
59
|
+
* another field's in one event may fall back at once). `resetAll(method = 'replace')` removes
|
|
60
|
+
* every field's key in one write.
|
|
61
|
+
*
|
|
62
|
+
* Each field runs its kind's hook with the definition in its outside form (the group's value and
|
|
63
|
+
* writer), with the group's context as its field context, so its controls are the kind's own,
|
|
64
|
+
* and a request goes through the kind's own checks before it is kept. The hooks run per field,
|
|
65
|
+
* so the ids and kinds, in order, are kept from the first render, and so is the storage: a list
|
|
66
|
+
* of another shape, or another `stored`, throws (remount the component running the group, with a
|
|
67
|
+
* React `key`, to swap lists). The definitions' contents may change, and new objects of the same
|
|
68
|
+
* shape on every render (inline literals) are fine.
|
|
69
|
+
*
|
|
70
|
+
* A field's shown value, in `values` and as passed to its kind's hook, keeps its identity while it
|
|
71
|
+
* stays equal (element by element, as useStoredField's does), so a list does not become a new array
|
|
72
|
+
* on every render; the `values` object keeps its identity until a shown value changes, so an
|
|
73
|
+
* effect keyed on it (one that loads data, say, and feeds the app's field context) runs only
|
|
74
|
+
* then. A kind's own controls may still rebuild a composite value: range's `[from, to]` pair is
|
|
75
|
+
* put in order and within bounds anew on every render.
|
|
76
|
+
*/
|
|
77
|
+
export declare function useFieldGroup(definitions: readonly FieldDefinition[], options?: {
|
|
78
|
+
stored?: boolean;
|
|
79
|
+
}): FieldGroup;
|
|
80
|
+
//# sourceMappingURL=useFieldGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFieldGroup.d.ts","sourceRoot":"","sources":["../src/useFieldGroup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAK/D,6EAA6E;AAC7E,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,MAAM,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAClC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C;;;OAGG;IACH,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACvC;AAwMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,EAAE,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,UAAU,CA6DrH"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { useCallback, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
|
+
import { useArgStore } from './ArgStoreContext.js';
|
|
3
|
+
import { useFieldContext, withFieldContext } from './FieldContext.js';
|
|
4
|
+
import { createGroupValues } from './fieldGroupValues.js';
|
|
5
|
+
import { useKindField } from './kindHooks.js';
|
|
6
|
+
import { valueTypeOf } from './kinds.js';
|
|
7
|
+
import { rawFor } from './useArg.js';
|
|
8
|
+
import { sameValue } from './useStoredField.js';
|
|
9
|
+
const NOTHING_KEPT = {};
|
|
10
|
+
const WHERE = 'Field group';
|
|
11
|
+
function silently(_id, _message) { }
|
|
12
|
+
/** A field's kept value in `kept`, or `undefined` for none (an id such as `toString` is not Object's member). */
|
|
13
|
+
function keptIn(kept) {
|
|
14
|
+
return (id) => (Object.hasOwn(kept, id) ? kept[id] : undefined);
|
|
15
|
+
}
|
|
16
|
+
/** The ids and kinds of a list of definitions, in order: what has to stay the same across renders. */
|
|
17
|
+
function shapeOf(definitions) {
|
|
18
|
+
return definitions.map(({ id, kind }) => `${id} (${String(kind)})`).join(', ');
|
|
19
|
+
}
|
|
20
|
+
/** Where a group keeps its values, in the words of the error for a change of it. */
|
|
21
|
+
function storageOf(stored) {
|
|
22
|
+
return stored ? 'the nearest ArgStore ({ stored: true })' : "the group's own state";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether a field shows its default, by useStoredField's rule: nothing is kept, or the kept
|
|
26
|
+
* value equals the current default, or what it shows does (a kept value that falls back to it).
|
|
27
|
+
*/
|
|
28
|
+
function showsDefault(definition, kept, group) {
|
|
29
|
+
if (kept === undefined)
|
|
30
|
+
return true;
|
|
31
|
+
const { isEqual } = valueTypeOf(definition.kind);
|
|
32
|
+
const fallback = group.defaultOf(definition.id);
|
|
33
|
+
return isEqual(kept, fallback) || isEqual(group.valueOf(definition.id), fallback);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A field's default under the given kept values (the state a write applies to, not necessarily
|
|
37
|
+
* this render's), computed afresh and silently. A write compares with it, so a write batched
|
|
38
|
+
* after another field's (in one event) compares with the default that one gives.
|
|
39
|
+
*/
|
|
40
|
+
function defaultUnder(definitions, appCtx, kept, id) {
|
|
41
|
+
return createGroupValues({ definitions, appCtx, kept, warn: silently }).defaultOf(id);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The group's own state: the kept values by id. A write keeps the value unless it equals the
|
|
45
|
+
* field's default under the state the write applies to, so a write batched after another
|
|
46
|
+
* field's (in one event) compares with the default that one gives. A fallback is silent: a value
|
|
47
|
+
* another field made invalid is how a group behaves, not bad input. There are no links.
|
|
48
|
+
*/
|
|
49
|
+
function useOwnState(definitions, appCtx) {
|
|
50
|
+
const [kept, setKept] = useState(NOTHING_KEPT);
|
|
51
|
+
const resetAll = useCallback(() => setKept((state) => (Object.keys(state).length === 0 ? state : NOTHING_KEPT)), []);
|
|
52
|
+
const write = ({ id, kind }) => (value) => setKept((state) => {
|
|
53
|
+
if (!valueTypeOf(kind).isEqual(value, defaultUnder(definitions, appCtx, keptIn(state), id)))
|
|
54
|
+
return { ...state, [id]: value };
|
|
55
|
+
if (!Object.hasOwn(state, id))
|
|
56
|
+
return state;
|
|
57
|
+
const { [id]: _dropped, ...rest } = state;
|
|
58
|
+
return rest;
|
|
59
|
+
});
|
|
60
|
+
return { kept: keptIn(kept), warn: silently, outside: (definition) => ({ onChange: write(definition) }), resetAll };
|
|
61
|
+
}
|
|
62
|
+
/** How a field's value is kept in a store; an unknown kind throws, naming the field (as argOf does). */
|
|
63
|
+
function valueTypeFor({ id, kind }) {
|
|
64
|
+
try {
|
|
65
|
+
return valueTypeOf(kind);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error(`Field '${id}': ${error.message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** A stored raw value as the field's value: `undefined` for an absent key, or for a raw value its kind's value type cannot read. */
|
|
72
|
+
function parseRaw(definition, raw) {
|
|
73
|
+
return raw === undefined ? undefined : valueTypeFor(definition).parse(raw);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The nearest ArgStore, under each field's id, as useStoredField keeps a field there, read in one
|
|
77
|
+
* subscription (as useStoredFields): its snapshot is the fields' raw values joined into one
|
|
78
|
+
* string, which changes exactly when one of them does. A raw value is parsed by the kind's value
|
|
79
|
+
* type; one that does not parse is no kept value, so the field shows its current default.
|
|
80
|
+
*
|
|
81
|
+
* A write carries the value's raw form, the key absent when the value equals the field's default
|
|
82
|
+
* as the store has it at that moment: the values computed afresh, silently, from the store's
|
|
83
|
+
* current raw values, which include its own writes not rendered yet (every store reads them back
|
|
84
|
+
* at once). So, as in the group's own state, a write batched after another field's (in one
|
|
85
|
+
* event) compares with the default that one gives. A link (the store's `hrefFor`, where it has
|
|
86
|
+
* one) is the render's: its key is absent when the value equals the default as rendered, and it
|
|
87
|
+
* keeps its identity while the store and that default stay the same (a tree list rebuilds its
|
|
88
|
+
* rows for a new one, and asks again when a link is used).
|
|
89
|
+
*
|
|
90
|
+
* A raw value warns (it does not parse, or it falls back) once, as useStoredField's does: in the
|
|
91
|
+
* render that first reads it, not again on a re-render, nor when another field's change makes it
|
|
92
|
+
* fall back later; another raw value warns again. The warnings are for raw values from elsewhere
|
|
93
|
+
* (the URL, another tab): the one the group itself last wrote for a field, read by the next render,
|
|
94
|
+
* does not warn, as a write chained after another field's in one event may fall back at once
|
|
95
|
+
* (`layout.setValue('rendered'); paper.setValue('letter')`, Letter offered under the old layout).
|
|
96
|
+
*/
|
|
97
|
+
function useStoredValues(definitions, appCtx) {
|
|
98
|
+
const store = useArgStore();
|
|
99
|
+
// The first render's ids: the shape check keeps them the same.
|
|
100
|
+
const [ids] = useState(() => definitions.map((definition) => definition.id));
|
|
101
|
+
// Called on the store, not passed detached: a store written as a class uses `this`.
|
|
102
|
+
const subscribe = useCallback((listener) => store.subscribe(listener), [store]);
|
|
103
|
+
const readAll = useCallback(() => JSON.stringify(ids.map((id) => store.read(id) ?? null)), [store, ids]);
|
|
104
|
+
const snapshot = useSyncExternalStore(subscribe, readAll);
|
|
105
|
+
const rawList = JSON.parse(snapshot);
|
|
106
|
+
const raws = new Map(ids.map((id, i) => [id, rawList[i]]));
|
|
107
|
+
const seenRef = useRef(new Map());
|
|
108
|
+
/** The raw value the group itself last wrote for a field, until the next render reads the store. */
|
|
109
|
+
const writtenRef = useRef(new Map());
|
|
110
|
+
const seen = seenRef.current;
|
|
111
|
+
const written = writtenRef.current;
|
|
112
|
+
/** The fields whose raw value this render reads first, from elsewhere than the group's own write: each may warn, once. */
|
|
113
|
+
const fresh = new Set();
|
|
114
|
+
for (const id of ids) {
|
|
115
|
+
const raw = raws.get(id) ?? null;
|
|
116
|
+
if (raw !== seen.get(id) && raw !== null && raw !== written.get(id))
|
|
117
|
+
fresh.add(id);
|
|
118
|
+
}
|
|
119
|
+
// Every store reads its own writes back at once, so the render after a write reads it: the memory
|
|
120
|
+
// lasts until then, and a write undone before any render is not remembered later.
|
|
121
|
+
written.clear();
|
|
122
|
+
seenRef.current = raws;
|
|
123
|
+
const warn = (id, message) => {
|
|
124
|
+
if (fresh.delete(id))
|
|
125
|
+
console.warn(message);
|
|
126
|
+
};
|
|
127
|
+
const byId = new Map(definitions.map((definition) => [definition.id, definition]));
|
|
128
|
+
const parsed = new Map();
|
|
129
|
+
const kept = (id) => {
|
|
130
|
+
if (!parsed.has(id)) {
|
|
131
|
+
const raw = raws.get(id) ?? undefined;
|
|
132
|
+
const value = parseRaw(byId.get(id), raw);
|
|
133
|
+
if (raw !== undefined && value === undefined)
|
|
134
|
+
warn(id, `Argument '${id}': cannot read '${raw}', using the default`);
|
|
135
|
+
parsed.set(id, value);
|
|
136
|
+
}
|
|
137
|
+
return parsed.get(id);
|
|
138
|
+
};
|
|
139
|
+
/** A field's default as the store has it now: under its current raw values, its own writes not rendered yet included. */
|
|
140
|
+
const defaultNow = (id) => defaultUnder(definitions, appCtx, (key) => parseRaw(byId.get(key), store.read(key)), id);
|
|
141
|
+
const linksRef = useRef(new Map());
|
|
142
|
+
const outside = (definition, group) => {
|
|
143
|
+
const { id } = definition;
|
|
144
|
+
const valueType = valueTypeFor(definition);
|
|
145
|
+
const onChange = (value) => {
|
|
146
|
+
const raw = rawFor(value, defaultNow(id), valueType);
|
|
147
|
+
written.set(id, raw);
|
|
148
|
+
store.write([{ key: id, raw }], 'replace');
|
|
149
|
+
};
|
|
150
|
+
if (store.hrefFor === undefined)
|
|
151
|
+
return { onChange };
|
|
152
|
+
const defaultValue = group.defaultOf(id);
|
|
153
|
+
let link = linksRef.current.get(id);
|
|
154
|
+
if (link === undefined || link.store !== store || !valueType.isEqual(link.defaultValue, defaultValue)) {
|
|
155
|
+
link = { store, defaultValue, hrefFor: (value) => store.hrefFor?.([{ key: id, raw: rawFor(value, defaultValue, valueType) }]) };
|
|
156
|
+
linksRef.current.set(id, link);
|
|
157
|
+
}
|
|
158
|
+
return { onChange, hrefFor: link.hrefFor };
|
|
159
|
+
};
|
|
160
|
+
const resetAll = useCallback((method = 'replace') => store.write(ids.map((id) => ({ key: id, raw: undefined })), method), [store, ids]);
|
|
161
|
+
return { kept, warn, outside, resetAll };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Runs a list of field definitions together, as a group: every option function of each
|
|
165
|
+
* definition (but `initialValue`) receives `ctx.values`, the fields' shown values by id, beside
|
|
166
|
+
* the app's own field context, so a field's choices, bounds or visibility can follow another
|
|
167
|
+
* field. A field's default is its `initialValue` (which cannot read `values`), else its kind's
|
|
168
|
+
* implicit initial value from its options as they are now, so it moves with the fields those
|
|
169
|
+
* read. It throws, naming the field (and the option), for an option reading an id not in the
|
|
170
|
+
* group, two definitions with the same id and a mixed-boolean definition; naming the cycle for
|
|
171
|
+
* fields whose values depend on each other; and for an app context that already has `values`
|
|
172
|
+
* (`Field group: the field context already has 'values'; a field group provides it`).
|
|
173
|
+
*
|
|
174
|
+
* Storage, for the whole group, is the caller's choice. By default the group keeps the values in
|
|
175
|
+
* its own state, as a store keeps them: a field never set, or set to its current default, keeps
|
|
176
|
+
* nothing and shows its current default, which moves with the fields its options read. A kept
|
|
177
|
+
* value that another field's change made invalid shows the field's fallback, silently (that is
|
|
178
|
+
* how a group behaves, not bad input), and shows again once it is valid again; it is never
|
|
179
|
+
* rewritten. `resetAll()` clears every kept value (the update method is for a store; here it is
|
|
180
|
+
* ignored).
|
|
181
|
+
*
|
|
182
|
+
* With `{ stored: true }` the values live in the nearest ArgStore (the URL, localStorage) under
|
|
183
|
+
* each field's id, as useStoredField keeps a field there, all read in one subscription: an absent
|
|
184
|
+
* key reads as the field's current default, and a value equal to it is written as an absent key
|
|
185
|
+
* (`'replace'`). The default compared with is the one under the store's values at the moment of
|
|
186
|
+
* the write, as in the group's own state, so a write batched after another field's (in one
|
|
187
|
+
* event) compares with the default that one gives. The controls' `hrefFor` links a value
|
|
188
|
+
* through the store's `hrefFor` (`undefined` where the store has none), as rendered. The fallback
|
|
189
|
+
* rule is the same, and the stored value is never rewritten either, but a raw value that does not
|
|
190
|
+
* parse, or falls back, warns once, as useStoredField's does: an unparsable one reads as the
|
|
191
|
+
* current default. A raw value the group itself wrote does not warn (a write chained after
|
|
192
|
+
* another field's in one event may fall back at once). `resetAll(method = 'replace')` removes
|
|
193
|
+
* every field's key in one write.
|
|
194
|
+
*
|
|
195
|
+
* Each field runs its kind's hook with the definition in its outside form (the group's value and
|
|
196
|
+
* writer), with the group's context as its field context, so its controls are the kind's own,
|
|
197
|
+
* and a request goes through the kind's own checks before it is kept. The hooks run per field,
|
|
198
|
+
* so the ids and kinds, in order, are kept from the first render, and so is the storage: a list
|
|
199
|
+
* of another shape, or another `stored`, throws (remount the component running the group, with a
|
|
200
|
+
* React `key`, to swap lists). The definitions' contents may change, and new objects of the same
|
|
201
|
+
* shape on every render (inline literals) are fine.
|
|
202
|
+
*
|
|
203
|
+
* A field's shown value, in `values` and as passed to its kind's hook, keeps its identity while it
|
|
204
|
+
* stays equal (element by element, as useStoredField's does), so a list does not become a new array
|
|
205
|
+
* on every render; the `values` object keeps its identity until a shown value changes, so an
|
|
206
|
+
* effect keyed on it (one that loads data, say, and feeds the app's field context) runs only
|
|
207
|
+
* then. A kind's own controls may still rebuild a composite value: range's `[from, to]` pair is
|
|
208
|
+
* put in order and within bounds anew on every render.
|
|
209
|
+
*/
|
|
210
|
+
export function useFieldGroup(definitions, options = {}) {
|
|
211
|
+
const stored = options.stored === true;
|
|
212
|
+
const appCtx = useFieldContext();
|
|
213
|
+
const shape = shapeOf(definitions);
|
|
214
|
+
const firstRef = useRef({ shape, stored });
|
|
215
|
+
const first = firstRef.current;
|
|
216
|
+
if (stored !== first.stored) {
|
|
217
|
+
throw new Error(`${WHERE}: the storage changed from ${storageOf(first.stored)} to ${storageOf(stored)}; a group runs `
|
|
218
|
+
+ 'other hooks for each, so it keeps its storage across renders: to switch, remount the component running it with a React `key`');
|
|
219
|
+
}
|
|
220
|
+
if (shape !== first.shape) {
|
|
221
|
+
throw new Error(`${WHERE}: the fields changed from ${first.shape} to ${shape}; a group runs hooks per field, so it `
|
|
222
|
+
+ 'keeps the same ids and kinds, in order, across renders: to swap lists, remount the component running it with a React `key`');
|
|
223
|
+
}
|
|
224
|
+
const shownRef = useRef(new Map());
|
|
225
|
+
const valuesRef = useRef(undefined);
|
|
226
|
+
// The storage is the first render's (checked above), so the hooks it runs stay the same.
|
|
227
|
+
const keeping = stored ? useStoredValues(definitions, appCtx) : useOwnState(definitions, appCtx);
|
|
228
|
+
const group = createGroupValues({ definitions, appCtx, kept: keeping.kept, warn: keeping.warn });
|
|
229
|
+
const previous = shownRef.current;
|
|
230
|
+
const shown = new Map();
|
|
231
|
+
for (const { id } of definitions) {
|
|
232
|
+
const value = group.valueOf(id);
|
|
233
|
+
shown.set(id, previous.has(id) && sameValue(previous.get(id), value) ? previous.get(id) : value);
|
|
234
|
+
}
|
|
235
|
+
shownRef.current = shown;
|
|
236
|
+
// The previous object while every shown value is the previous one (kept above while it stays
|
|
237
|
+
// equal): a host's effect keyed on `values` runs when a value changes, not on every render.
|
|
238
|
+
const unchanged = valuesRef.current !== undefined
|
|
239
|
+
&& definitions.every(({ id }) => previous.has(id) && Object.is(previous.get(id), shown.get(id)));
|
|
240
|
+
const values = unchanged ? valuesRef.current : Object.fromEntries(shown);
|
|
241
|
+
valuesRef.current = values;
|
|
242
|
+
// One kind hook per definition, in order; the shape check above keeps the hooks' order.
|
|
243
|
+
const fields = definitions.map((definition) => {
|
|
244
|
+
const { initialValue: _default, ...outside } = definition;
|
|
245
|
+
const { onChange, hrefFor } = keeping.outside(definition, group);
|
|
246
|
+
return withFieldContext(group.ctx, () => useKindField(definition, {
|
|
247
|
+
...outside, value: shown.get(definition.id), onChange, hrefFor,
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
const changed = new Set(definitions.filter((d) => !showsDefault(d, keeping.kept(d.id), group)).map((d) => d.id));
|
|
251
|
+
const isDefault = (id) => {
|
|
252
|
+
if (!shown.has(id)) {
|
|
253
|
+
throw new Error(`${WHERE}: no field '${id}' in the group (fields: ${definitions.map((d) => d.id).join(', ')})`);
|
|
254
|
+
}
|
|
255
|
+
return !changed.has(id);
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
fields,
|
|
259
|
+
byId: Object.fromEntries(definitions.map((d, i) => [d.id, fields[i]])),
|
|
260
|
+
values,
|
|
261
|
+
isDefault,
|
|
262
|
+
changedCount: changed.size,
|
|
263
|
+
resetAll: keeping.resetAll,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=useFieldGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFieldGroup.js","sourceRoot":"","sources":["../src/useFieldGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAiB,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAoB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAwB,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAiChD,MAAM,YAAY,GAAS,EAAE,CAAC;AAC9B,MAAM,KAAK,GAAG,aAAa,CAAC;AAE5B,SAAS,QAAQ,CAAC,GAAW,EAAE,QAAgB,IAAS,CAAC;AAEzD,iHAAiH;AACjH,SAAS,MAAM,CAAC,IAAU;IACxB,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MA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AAE,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtE,MAAM;QACN,SAAS;QACT,YAAY,EAAE,OAAO,CAAC,IAAI;QAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC"}
|
package/dist/useStoredField.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ import { type ArgDefinition } from './useArg.js';
|
|
|
9
9
|
* shows an aggregate of other data and cannot be stored: it throws, naming the field.
|
|
10
10
|
*/
|
|
11
11
|
export declare function argOf(definition: FieldDefinition, ctx: FieldCtx): ArgDefinition<any>;
|
|
12
|
+
/**
|
|
13
|
+
* The same value element by element: a list in the same order, a range with the same ends, a
|
|
14
|
+
* scalar. Stricter than the value types' `isEqual` (lists as sets), because the order a field
|
|
15
|
+
* shows (choice order, tree order) matters to the identity kept below. Exported for the field
|
|
16
|
+
* group (useFieldGroup), which keeps its values' identity by the same rule; not part of the
|
|
17
|
+
* package's API.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sameValue(a: unknown, b: unknown): boolean;
|
|
12
20
|
/**
|
|
13
21
|
* A field kept in the nearest ArgStore: its options for the kind's hook, and whether it shows
|
|
14
22
|
* its default. `options` follows `D` member by member, so options of a definition typed as the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStoredField.d.ts","sourceRoot":"","sources":["../src/useStoredField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAA+C,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzD;;;;;GAK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vF;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,2FAA2F;IAC3F,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACvC;AAsBD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,GAAG,YAAY,CAwCrF"}
|
package/dist/useStoredField.js
CHANGED
|
@@ -27,9 +27,11 @@ function warnOnConsole(message) {
|
|
|
27
27
|
/**
|
|
28
28
|
* The same value element by element: a list in the same order, a range with the same ends, a
|
|
29
29
|
* scalar. Stricter than the value types' `isEqual` (lists as sets), because the order a field
|
|
30
|
-
* shows (choice order, tree order) matters to the identity kept below.
|
|
30
|
+
* shows (choice order, tree order) matters to the identity kept below. Exported for the field
|
|
31
|
+
* group (useFieldGroup), which keeps its values' identity by the same rule; not part of the
|
|
32
|
+
* package's API.
|
|
31
33
|
*/
|
|
32
|
-
function sameValue(a, b) {
|
|
34
|
+
export function sameValue(a, b) {
|
|
33
35
|
if (Array.isArray(a) && Array.isArray(b))
|
|
34
36
|
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
35
37
|
return a === b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStoredField.js","sourceRoot":"","sources":["../src/useStoredField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAwB,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,MAAM,EAAsB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CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACjG,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;IAEjC,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,EAAU,EAAE,EAAE;QACb,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,kDAAkD,CAAC,CAAC;QAC3H,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC,EACD,CAAC,WAAW,EAAE,OAAO,CAAC,CACvB,CAAC;IACF,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,SAAuB,SAAS,EAAE,EAAE;QACnC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC/E,CAAC,EACD,CAAC,KAAK,EAAE,WAAW,CAAC,CACrB,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC7D,CAAC"}
|
package/package.json
CHANGED
package/src/FieldContext.tsx
CHANGED
|
@@ -31,25 +31,46 @@ function isProbe(key: string): boolean {
|
|
|
31
31
|
return PROBED_KEYS.has(key) || key.startsWith('@@');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
34
|
+
/**
|
|
35
|
+
* What the guard throws for a key no provider gave, so readingContext can tell it from the
|
|
36
|
+
* function's own errors. Exported for the field group (fieldGroupValues), whose own reads that
|
|
37
|
+
* fail (an id not in the group, `values` read from `initialValue`) get the field and option in
|
|
38
|
+
* front the same way; not part of the package's API.
|
|
39
|
+
*/
|
|
40
|
+
export class MissingKeyError extends Error {}
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
43
|
+
* `raw` guarded against reading a key it lacks: such a read throws a MissingKeyError with
|
|
44
|
+
* `missing(key)` as its message, which readingContext puts the field and the option in front
|
|
45
|
+
* of. `has` says whether `raw` has the key; by default inherited members (`toString`) count,
|
|
46
|
+
* and `Object.hasOwn` makes them missing too. Probes and symbol keys read as usual. Exported for
|
|
47
|
+
* the field group's `values` (an id not in the group); not part of the package's API.
|
|
41
48
|
*/
|
|
42
|
-
function
|
|
49
|
+
export function guardKeys(
|
|
50
|
+
raw: object,
|
|
51
|
+
missing: (key: string) => string,
|
|
52
|
+
has: (target: object, key: string) => boolean = (target, key) => key in target,
|
|
53
|
+
): object {
|
|
43
54
|
return new Proxy(raw, {
|
|
44
55
|
get(target, key, receiver) {
|
|
45
|
-
if (typeof key === 'string' && !isProbe(key) && !(key
|
|
46
|
-
throw new MissingKeyError(`Field context: '${key}' was never provided (provided: ${Object.keys(target).join(', ')})`);
|
|
47
|
-
}
|
|
56
|
+
if (typeof key === 'string' && !isProbe(key) && !has(target, key)) throw new MissingKeyError(missing(key));
|
|
48
57
|
return Reflect.get(target, key, receiver);
|
|
49
58
|
},
|
|
50
59
|
});
|
|
51
60
|
}
|
|
52
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The context value as the definitions' functions receive it: reading a key that no provider
|
|
64
|
+
* gave throws, naming it and the keys present, so a forgotten value fails loudly instead of
|
|
65
|
+
* passing `undefined` along. A key provided with the value `undefined` is fine. `values` is the
|
|
66
|
+
* key a field group adds (extendFieldContext), so reading it from any other context says so.
|
|
67
|
+
*/
|
|
68
|
+
function guard(raw: object): object {
|
|
69
|
+
return guardKeys(raw, (key) => (key === 'values'
|
|
70
|
+
? 'ctx.values is only available inside a field group'
|
|
71
|
+
: `Field context: '${key}' was never provided (provided: ${Object.keys(raw).join(', ')})`));
|
|
72
|
+
}
|
|
73
|
+
|
|
53
74
|
/**
|
|
54
75
|
* Runs `read`, a call of a definition's function with the field context. A key it reads that
|
|
55
76
|
* no provider gave throws with `where` (`Field '<id>': option '<name>'`) in front of the
|
|
@@ -92,7 +113,48 @@ export function createFieldContext<Ctx extends object>(): {
|
|
|
92
113
|
return { Provider: FieldContextProvider };
|
|
93
114
|
}
|
|
94
115
|
|
|
95
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* A field context with `base`'s keys (none for NO_FIELD_CONTEXT) and `extra`'s, guarded as a
|
|
118
|
+
* provider's value is: how a field group gives its fields' functions `values` beside the app's
|
|
119
|
+
* own keys. `extra`'s properties are copied as defined, so a getter among them runs when its
|
|
120
|
+
* key is read, not here. A key of `extra` that `base` already has throws, `where` in front,
|
|
121
|
+
* instead of shadowing the app's value; every key the copy takes is checked (non-enumerable
|
|
122
|
+
* and symbol keys too).
|
|
123
|
+
*/
|
|
124
|
+
export function extendFieldContext(base: FieldCtx, extra: Record<string, unknown>, where: string): object {
|
|
125
|
+
const raw: object = base === NO_FIELD_CONTEXT ? {} : { ...base };
|
|
126
|
+
for (const key of Reflect.ownKeys(extra)) {
|
|
127
|
+
if (Object.hasOwn(raw, key)) throw new Error(`${where}: the field context already has '${String(key)}'; a field group provides it`);
|
|
128
|
+
}
|
|
129
|
+
return guard(Object.defineProperties(raw, Object.getOwnPropertyDescriptors(extra)));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The context withFieldContext gives the hooks it is running, if any. */
|
|
133
|
+
let override: FieldCtx | undefined;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Runs `run` with `ctx` as the field context: a hook it calls gets `ctx` from useFieldContext
|
|
137
|
+
* instead of the providers' value. It is for a hook that calls other hooks in its own render,
|
|
138
|
+
* each with its own context (a field group runs each field's kind hook with the group's); the
|
|
139
|
+
* components rendered below do not see it. `run` must be synchronous: the previous context
|
|
140
|
+
* comes back when it returns or throws. Calls nest.
|
|
141
|
+
*/
|
|
142
|
+
export function withFieldContext<T>(ctx: FieldCtx, run: () => T): T {
|
|
143
|
+
const previous = override;
|
|
144
|
+
override = ctx;
|
|
145
|
+
try {
|
|
146
|
+
return run();
|
|
147
|
+
} finally {
|
|
148
|
+
override = previous;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The field context the hooks resolve functions with: the one withFieldContext gives while it
|
|
154
|
+
* runs, else the providers' guarded value, or NO_FIELD_CONTEXT.
|
|
155
|
+
*/
|
|
96
156
|
export function useFieldContext(): FieldCtx {
|
|
97
|
-
|
|
157
|
+
// Called under an override too, so that the hooks' order never depends on one.
|
|
158
|
+
const provided = useContext(FieldContext);
|
|
159
|
+
return override ?? provided?.guarded ?? NO_FIELD_CONTEXT;
|
|
98
160
|
}
|