vultus-core 0.5.2 → 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.
Files changed (57) hide show
  1. package/README.md +176 -4
  2. package/dist/FieldContext.d.ts +37 -1
  3. package/dist/FieldContext.d.ts.map +1 -1
  4. package/dist/FieldContext.js +68 -11
  5. package/dist/FieldContext.js.map +1 -1
  6. package/dist/field.d.ts +12 -1
  7. package/dist/field.d.ts.map +1 -1
  8. package/dist/field.js +6 -1
  9. package/dist/field.js.map +1 -1
  10. package/dist/fieldGroupValues.d.ts +63 -0
  11. package/dist/fieldGroupValues.d.ts.map +1 -0
  12. package/dist/fieldGroupValues.js +119 -0
  13. package/dist/fieldGroupValues.js.map +1 -0
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/kindHooks.d.ts +23 -0
  19. package/dist/kindHooks.d.ts.map +1 -0
  20. package/dist/kindHooks.js +38 -0
  21. package/dist/kindHooks.js.map +1 -0
  22. package/dist/kinds.d.ts +19 -14
  23. package/dist/kinds.d.ts.map +1 -1
  24. package/dist/kinds.js +40 -14
  25. package/dist/kinds.js.map +1 -1
  26. package/dist/tree.d.ts +17 -0
  27. package/dist/tree.d.ts.map +1 -1
  28. package/dist/tree.js +27 -0
  29. package/dist/tree.js.map +1 -1
  30. package/dist/useArg.d.ts +6 -0
  31. package/dist/useArg.d.ts.map +1 -1
  32. package/dist/useArg.js +6 -2
  33. package/dist/useArg.js.map +1 -1
  34. package/dist/useFieldGroup.d.ts +80 -0
  35. package/dist/useFieldGroup.d.ts.map +1 -0
  36. package/dist/useFieldGroup.js +266 -0
  37. package/dist/useFieldGroup.js.map +1 -0
  38. package/dist/useOneOfTreeField.d.ts +79 -0
  39. package/dist/useOneOfTreeField.d.ts.map +1 -0
  40. package/dist/useOneOfTreeField.js +117 -0
  41. package/dist/useOneOfTreeField.js.map +1 -0
  42. package/dist/useStoredField.d.ts +9 -0
  43. package/dist/useStoredField.d.ts.map +1 -1
  44. package/dist/useStoredField.js +7 -5
  45. package/dist/useStoredField.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/FieldContext.tsx +73 -11
  48. package/src/field.ts +25 -5
  49. package/src/fieldGroupValues.ts +169 -0
  50. package/src/index.ts +7 -1
  51. package/src/kindHooks.ts +52 -0
  52. package/src/kinds.ts +38 -14
  53. package/src/tree.ts +34 -0
  54. package/src/useArg.ts +6 -2
  55. package/src/useFieldGroup.ts +346 -0
  56. package/src/useOneOfTreeField.ts +182 -0
  57. package/src/useStoredField.ts +10 -6
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.
@@ -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,SAA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S,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
- /** The raw value a write needs for `value`: `undefined` (removes the key) when it equals the default, else its formatted form. */
6
- function rawFor(value, defaultValue, valueType) {
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
  /**
@@ -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,kIAAkI;AAClI,SAAS,MAAM,CAAI,KAAQ,EAAE,YAAe,EAAE,SAAuB;IACnE,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAI,UAA4B;IACpD,MAAM,EAAE,GAAG,EAAE,S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,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,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAClE,CAAC;AAED,sGAAsG;AACtG,SAAS,OAAO,CAAC,WAAuC;IACtD,OAAO,WA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YAAY,EAAE,OAAO,CAAC,IAAI;QAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { type FieldControls, type FieldOptions } from './field.js';
2
+ import { type OneOfChoiceControls } from './choices.js';
3
+ import { type FieldCtx } from './FieldContext.js';
4
+ import { type TreeChoose, type TreeExpand, type TreeNode } from './tree.js';
5
+ import type { ErrorRoutesRegistry, ValueOrFn } from './types.js';
6
+ export type OneOfTreeOwnOptions<T extends string = string, Ctx = any> = {
7
+ /** The roots, each with its children; static or derived (a function, of the field context if it declares a parameter). */
8
+ nodes: ValueOrFn<TreeNode<T>[], Ctx>;
9
+ /** Which nodes may be chosen; default 'any' (see TreeChoose). */
10
+ choose?: TreeChoose;
11
+ /** Whether the value may be empty (''), nothing chosen; default false (as oneOf, never empty). */
12
+ optional?: boolean;
13
+ /** Which nodes a widget opens at first; default 'selected' (the value's ancestors; see TreeExpand). */
14
+ expand?: TreeExpand;
15
+ };
16
+ export type OneOfTreeFieldOptions<T extends string = string, RouteId extends string = string, Ctx = any> = FieldOptions<T | '', T | '', RouteId, Ctx> & OneOfTreeOwnOptions<T, Ctx>;
17
+ /** A tree node as the one-of tree's widgets get it: the resolved choice, its children likewise, and whether it may be chosen, is the value, or an ancestor of it. */
18
+ export interface OneOfTreeNodeControls<T extends string = string> extends OneOfChoiceControls<T> {
19
+ children: OneOfTreeNodeControls<T>[] | undefined;
20
+ /** Whether the field may choose this node under `choose` (see canChooseNode). */
21
+ choosable: boolean;
22
+ /** It is the value. */
23
+ current: boolean;
24
+ /** An ancestor of the value (not the value itself). */
25
+ onPath: boolean;
26
+ }
27
+ export interface OneOfTreeFieldControls<T extends string = string> extends FieldControls<T | '', T | ''> {
28
+ /** The roots as the widgets get them, each with its children. */
29
+ nodes: OneOfTreeNodeControls<T>[];
30
+ /** Every node, by its value. */
31
+ byValue: Map<T, OneOfTreeNodeControls<T>>;
32
+ /** The chosen node, or undefined (the value is empty, or names no node). */
33
+ current: OneOfTreeNodeControls<T> | undefined;
34
+ /** The nodes from the root down to `current`, inclusive; empty when there is none. */
35
+ path: OneOfTreeNodeControls<T>[];
36
+ /**
37
+ * The choosable node just before `current` in tree pre-order — by `current`'s own position,
38
+ * not its position among the choosable nodes, so a `current` that cannot itself be chosen
39
+ * (a value naming a folder, or a node a context change disabled) still gets its true
40
+ * neighbours. Undefined at the start, and with no `current`.
41
+ */
42
+ previous: OneOfTreeNodeControls<T> | undefined;
43
+ /** The choosable node just after `current` in tree pre-order, by the same rule; with no `current`, the first choosable node. */
44
+ next: OneOfTreeNodeControls<T> | undefined;
45
+ optional: boolean;
46
+ choose: TreeChoose;
47
+ /** The nodes a widget opens at first (from `expand`). */
48
+ expandedKeys: T[];
49
+ /** Requests ''; refused (with a warning) unless `optional`, as `setValue('')` would be. */
50
+ clear(): void;
51
+ }
52
+ /**
53
+ * The implicit initial value for a one-of tree field: `initialValue` resolved through the field
54
+ * context, else '' when `optional`, else the first node `canChooseNode` accepts in tree
55
+ * pre-order, else '' (no node can be chosen; as oneOf's undefined choice).
56
+ */
57
+ export declare function oneOfTreeInitialValue<T extends string>(opts: {
58
+ initialValue?: ValueOrFn<T | ''>;
59
+ choose?: TreeChoose;
60
+ optional?: boolean;
61
+ }, ctx: FieldCtx, id: string, nodes: TreeNode<T>[]): T | '';
62
+ /**
63
+ * A field whose value is a single tree node, or nothing (Praeceptor's category picker, a
64
+ * table of contents): `choosable` (a per-node flag, default true; a folder) and the field's
65
+ * `choose: 'any' | 'leaves'` together say which nodes `setValue` accepts (canChooseNode);
66
+ * `optional` says whether '' (nothing chosen) is one of them too. `setValue` refuses, with a
67
+ * warning (as useOneOfField refuses a disabled choice): a value naming no node, a node
68
+ * `canChooseNode` rejects, and '' unless `optional`. `clear()` requests ''. The field's current
69
+ * state is the chosen node's description, unless `valueDescriptions` words it differently (as
70
+ * oneOf). `previous` / `next` are the choosable nodes just before and after `current`'s own
71
+ * position in tree pre-order (so a `current` that cannot itself be chosen still gets its true
72
+ * neighbours, skipping only the nodes between them that cannot be chosen); with no `current`,
73
+ * `previous` is undefined and `next` is the first choosable node. `expandedKeys` (from `expand`,
74
+ * default `'selected'`) are the value's ancestors,
75
+ * so a table of contents opens where the reader is. Inside the field the value starts at
76
+ * `oneOfTreeInitialValue`.
77
+ */
78
+ export declare function useOneOfTreeField<T extends string = string, RouteId extends string = string, Ctx = any>(opts: OneOfTreeFieldOptions<T, RouteId, Ctx>, registry?: ErrorRoutesRegistry<RouteId>): OneOfTreeFieldControls<T>;
79
+ //# sourceMappingURL=useOneOfTreeField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOneOfTreeField.d.ts","sourceRoot":"","sources":["../src/useOneOfTreeField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAEL,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAChD,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI;IACtE,0HAA0H;IAC1H,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACrC,iEAAiE;IACjE,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,kGAAkG;IAClG,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uGAAuG;IACvG,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,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IACnB,yDAAyD;IACzD,YAAY,EAAE,CAAC,EAAE,CAAC;IAClB,2FAA2F;IAC3F,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,IAAI,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EACnF,GAAG,EAAE,QAAQ,EACb,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,GACnB,CAAC,GAAG,EAAE,CAKR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,EACrG,IAAI,EAAE,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAC5C,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACtC,sBAAsB,CAAC,CAAC,CAAC,CAoF3B"}
@@ -0,0 +1,117 @@
1
+ import { useFieldCore } from './field.js';
2
+ import { resolveChoice } from './choices.js';
3
+ import { useFieldContext } from './FieldContext.js';
4
+ import { resolveIn } from './resolve.js';
5
+ import { canChooseNode, choosableValues, expandedTreeKeys, treePath, } from './tree.js';
6
+ /**
7
+ * The implicit initial value for a one-of tree field: `initialValue` resolved through the field
8
+ * context, else '' when `optional`, else the first node `canChooseNode` accepts in tree
9
+ * pre-order, else '' (no node can be chosen; as oneOf's undefined choice).
10
+ */
11
+ export function oneOfTreeInitialValue(opts, ctx, id, nodes) {
12
+ const resolved = resolveIn(opts.initialValue, undefined, ctx, `Field '${id}': option 'initialValue'`);
13
+ if (resolved !== undefined)
14
+ return resolved;
15
+ if (opts.optional)
16
+ return '';
17
+ return choosableValues(nodes, opts.choose ?? 'any')[0] ?? '';
18
+ }
19
+ /**
20
+ * A field whose value is a single tree node, or nothing (Praeceptor's category picker, a
21
+ * table of contents): `choosable` (a per-node flag, default true; a folder) and the field's
22
+ * `choose: 'any' | 'leaves'` together say which nodes `setValue` accepts (canChooseNode);
23
+ * `optional` says whether '' (nothing chosen) is one of them too. `setValue` refuses, with a
24
+ * warning (as useOneOfField refuses a disabled choice): a value naming no node, a node
25
+ * `canChooseNode` rejects, and '' unless `optional`. `clear()` requests ''. The field's current
26
+ * state is the chosen node's description, unless `valueDescriptions` words it differently (as
27
+ * oneOf). `previous` / `next` are the choosable nodes just before and after `current`'s own
28
+ * position in tree pre-order (so a `current` that cannot itself be chosen still gets its true
29
+ * neighbours, skipping only the nodes between them that cannot be chosen); with no `current`,
30
+ * `previous` is undefined and `next` is the first choosable node. `expandedKeys` (from `expand`,
31
+ * default `'selected'`) are the value's ancestors,
32
+ * so a table of contents opens where the reader is. Inside the field the value starts at
33
+ * `oneOfTreeInitialValue`.
34
+ */
35
+ export function useOneOfTreeField(opts, registry) {
36
+ const ctx = useFieldContext();
37
+ const nodes = resolveIn(opts.nodes, [], ctx, `Field '${opts.id}': option 'nodes'`);
38
+ const choose = opts.choose ?? 'any';
39
+ const optional = opts.optional ?? false;
40
+ const inside = !opts.onChange && !opts.commit;
41
+ const initialValue = () => oneOfTreeInitialValue(opts, ctx, opts.id, nodes);
42
+ const field = useFieldCore('oneOfTree', inside ? { ...opts, initialValue } : opts, registry);
43
+ const valuePath = field.value ? treePath(nodes, field.value) : [];
44
+ const ancestors = new Set(valuePath);
45
+ const byValue = new Map();
46
+ const control = (node) => {
47
+ const controls = {
48
+ ...resolveChoice(opts.id, node),
49
+ children: undefined,
50
+ choosable: canChooseNode(node, choose),
51
+ current: node.value === field.value,
52
+ onPath: ancestors.has(node.value) && node.value !== field.value,
53
+ };
54
+ byValue.set(node.value, controls);
55
+ if (node.children)
56
+ controls.children = node.children.map(control);
57
+ return controls;
58
+ };
59
+ const nodeControls = nodes.map(control);
60
+ const current = field.value ? byValue.get(field.value) : undefined;
61
+ const pathControls = valuePath.map((v) => byValue.get(v));
62
+ // byValue's insertion order is the full tree's pre-order (control() visits a node before its
63
+ // children), so it doubles as "every node, choosable or not" for finding current's neighbours.
64
+ const fullOrder = [...byValue.keys()];
65
+ const nearestChoosable = (from, step) => {
66
+ for (let i = from; i >= 0 && i < fullOrder.length; i += step) {
67
+ const node = byValue.get(fullOrder[i]);
68
+ if (node.choosable)
69
+ return node;
70
+ }
71
+ return undefined;
72
+ };
73
+ const index = current ? fullOrder.indexOf(current.value) : -1;
74
+ const previous = nearestChoosable(index - 1, -1);
75
+ const next = nearestChoosable(index + 1, 1);
76
+ const setValue = (requested) => {
77
+ if (requested === '') {
78
+ if (!optional) {
79
+ console.warn(`Field '${opts.id}': '' is refused — the field is not optional`);
80
+ return;
81
+ }
82
+ field.setValue('');
83
+ return;
84
+ }
85
+ const node = byValue.get(requested);
86
+ if (!node) {
87
+ console.warn(`Field '${opts.id}': '${requested}' is not one of its nodes`);
88
+ return;
89
+ }
90
+ if (!node.choosable) {
91
+ if (!node.enabled) {
92
+ console.warn(`Field '${opts.id}': node '${requested}' is disabled — ${node.whyDisabled ?? '(no reason)'}`);
93
+ }
94
+ else {
95
+ console.warn(`Field '${opts.id}': node '${requested}' cannot be chosen`);
96
+ }
97
+ return;
98
+ }
99
+ field.setValue(requested);
100
+ };
101
+ return {
102
+ ...field,
103
+ valueDescription: field.valueDescription ?? current?.description,
104
+ setValue,
105
+ nodes: nodeControls,
106
+ byValue,
107
+ current,
108
+ path: pathControls,
109
+ previous,
110
+ next,
111
+ optional,
112
+ choose,
113
+ expandedKeys: expandedTreeKeys(nodes, field.value ? [field.value] : [], opts.expand ?? 'selected'),
114
+ clear: () => setValue(''),
115
+ };
116
+ }
117
+ //# sourceMappingURL=useOneOfTreeField.js.map