vultus-core 0.5.1 → 0.5.2
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 +38 -8
- package/dist/field.d.ts +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kinds.d.ts +2 -2
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +6 -6
- package/dist/kinds.js.map +1 -1
- package/dist/parseApiError.d.ts +6 -0
- package/dist/parseApiError.d.ts.map +1 -1
- package/dist/parseApiError.js +7 -1
- package/dist/parseApiError.js.map +1 -1
- package/dist/tree.d.ts +21 -9
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +64 -21
- package/dist/tree.js.map +1 -1
- package/dist/{useTreeField.d.ts → useManyOfTreeField.d.ts} +10 -9
- package/dist/useManyOfTreeField.d.ts.map +1 -0
- package/dist/{useTreeField.js → useManyOfTreeField.js} +9 -8
- package/dist/useManyOfTreeField.js.map +1 -0
- package/package.json +3 -2
- package/src/field.ts +1 -1
- package/src/index.ts +3 -3
- package/src/kinds.ts +8 -8
- package/src/parseApiError.ts +7 -1
- package/src/tree.ts +71 -20
- package/src/{useTreeField.ts → useManyOfTreeField.ts} +14 -13
- package/dist/useTreeField.d.ts.map +0 -1
- package/dist/useTreeField.js.map +0 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ npm install vultus-core
|
|
|
23
23
|
`useAction`, `useActionList`; the field context (`FieldContextProvider`,
|
|
24
24
|
`createFieldContext`, `useFieldContext`, `NO_FIELD_CONTEXT`); every field
|
|
25
25
|
kind's hook (`useBoolField`, `useMixedBoolField`, `useOneOfField`,
|
|
26
|
-
`useManyOfField`, `useNumericField`, `useRangeField`, `
|
|
26
|
+
`useManyOfField`, `useNumericField`, `useRangeField`, `useManyOfTreeField`,
|
|
27
27
|
`useTextField`, `useFieldCore` and their types) and their shared helpers
|
|
28
28
|
(`resolveChoice`, `normalizeText`, `clamp`, `resolveNumeric`, the tree
|
|
29
29
|
helpers `normalizeTreeValue` / `coveredNodes` / `toggleTreeValue` /
|
|
@@ -46,7 +46,12 @@ An action's `fire(args, ctx)` receives an `ExecutionContext` next to its argumen
|
|
|
46
46
|
`ctx.info(text)`, `ctx.warn(text)` and `ctx.error(text)` report messages while it runs.
|
|
47
47
|
They land on the action's status as `messages` (with their `severity`) and go to the
|
|
48
48
|
`MessageSink` (`(text, severity?)`). A thrown error still fails the action and ends the
|
|
49
|
-
run's messages; `errors` lists the error texts among them.
|
|
49
|
+
run's messages; `errors` lists the error texts among them. What a thrown error shows
|
|
50
|
+
(`parseApiError`): an API error's body message (ts-rest's `{ status, body: { message, reason } }`);
|
|
51
|
+
without one, a thrown `Error`'s own message (`throw new Error('Printer offline')` shows "Printer
|
|
52
|
+
offline", a failed fetch its TypeError's); with neither, "Action failed" (a routed action
|
|
53
|
+
(`errorRoute`): the registry's entry for the body's `reason`, else the message, else
|
|
54
|
+
`t('common.error')`). A field's commit is an action, so the same holds for the field's messages.
|
|
50
55
|
|
|
51
56
|
## Fields
|
|
52
57
|
|
|
@@ -205,7 +210,7 @@ const field = useRangeField({ id: 'years', min: 2010, max: 2026 });
|
|
|
205
210
|
field.valueText; // '2010–2026'
|
|
206
211
|
```
|
|
207
212
|
|
|
208
|
-
### tree (`
|
|
213
|
+
### many-of tree (`useManyOfTreeField`)
|
|
209
214
|
|
|
210
215
|
The value is a list of node ids (`nodes`: `TreeNode`, a choice with
|
|
211
216
|
`children`), kept as a set. `selection` says which of the covered nodes the
|
|
@@ -219,8 +224,33 @@ nodes a widget opens at first, controlled by `expand`: `'top'` (default),
|
|
|
219
224
|
`'none'`, `'selected'`, `'all'`) and `toggle(value)` (refused, with a
|
|
220
225
|
warning, for an unknown or disabled node, as many-of's does).
|
|
221
226
|
`coveredNodes(nodes, value, selection)` expands a value to every node it
|
|
222
|
-
stands for — what a module matches an item's categories against.
|
|
223
|
-
|
|
227
|
+
stands for — what a module matches an item's categories against.
|
|
228
|
+
|
|
229
|
+
Disabled nodes follow antd's check conduction, so the hook and the antd
|
|
230
|
+
widgets agree: a disabled node is never covered through a checked ancestor
|
|
231
|
+
(nor is its subtree, through it), and a parent counts as checked once all
|
|
232
|
+
its *enabled* children are; a parent whose children are all disabled, or a
|
|
233
|
+
disabled parent, is never checked through its children. With nodes
|
|
234
|
+
Geometria (Síkgeometria, Térgeometria — disabled), checking Síkgeometria
|
|
235
|
+
gives `['geometria']` under `'topmost'` and `['geometria', 'sikgeometria']`
|
|
236
|
+
under `'all'`, and `coveredNodes` does not include Térgeometria. A disabled
|
|
237
|
+
node in the value (`setValue` and a stored value do not police them) stays
|
|
238
|
+
there and covers itself only. Where a disabled node breaks the cascade, the
|
|
239
|
+
value names what the other named nodes would not cover: under `'topmost'`
|
|
240
|
+
a checked disabled node beside its checked parent (`['geometria',
|
|
241
|
+
'tergeometria']`), and checked children beside their checked disabled parent,
|
|
242
|
+
as antd TreeSelect's `SHOW_PARENT` does; under `'leaves'` a checked node with
|
|
243
|
+
children that is disabled or has only disabled children — where antd's
|
|
244
|
+
`SHOW_CHILD` would drop it (and with it what it covers), so vultus-antd's
|
|
245
|
+
`ManyOfTreePicker` requests the field's value with the clicked node toggled rather
|
|
246
|
+
than antd's list. So normalizing never changes what a value covers. The same rule sanitizes a stored value. The
|
|
247
|
+
cost: a parent in the value stands for its subtree as it is when read, so
|
|
248
|
+
under `'topmost'` (and `'all'`, which lists the parent too) a child that was
|
|
249
|
+
disabled when the value was stored and is enabled later is covered from
|
|
250
|
+
then on — a stored `['geometria']` then covers Térgeometria too; `'leaves'`
|
|
251
|
+
names only the leaves and does not widen.
|
|
252
|
+
|
|
253
|
+
Search over labels is accent- and case-insensitive (`normalizeText`); the matching
|
|
224
254
|
`filterTree(nodes, query)` follows antd TreeSelect's rule: a node whose own
|
|
225
255
|
label matches stays with its whole subtree, any other node stays if one of
|
|
226
256
|
its descendants matches (with only the children that stay), and the rest
|
|
@@ -228,7 +258,7 @@ is trimmed, leaving the nodes given unchanged. Implicit initial value: the
|
|
|
228
258
|
empty list.
|
|
229
259
|
|
|
230
260
|
```ts
|
|
231
|
-
const field =
|
|
261
|
+
const field = useManyOfTreeField({
|
|
232
262
|
id: 'categories',
|
|
233
263
|
nodes: [{ value: 'a', children: [{ value: 'a1' }, { value: 'a2' }] }],
|
|
234
264
|
});
|
|
@@ -255,7 +285,7 @@ const field = useTextField({ id: 'search', control: 'input' });
|
|
|
255
285
|
A `FieldDefinition` is a field's options in their "inside" form (no `value`
|
|
256
286
|
plus `onChange` or `commit`), tagged with a required `kind` — one of
|
|
257
287
|
`'boolean'`, `'mixed-boolean'`, `'oneOf'`, `'manyOf'`, `'numeric'`,
|
|
258
|
-
`'range'`, `'
|
|
288
|
+
`'range'`, `'manyOfTree'`, `'text'` (the same strings `FieldControls.type` already
|
|
259
289
|
carries). `kind` stays optional on each hook's own options — a hook knows
|
|
260
290
|
its own kind, and throws if a definition names a different one — but is
|
|
261
291
|
required once a field becomes plain data: a module declares its filters as a
|
|
@@ -304,7 +334,7 @@ type's own meaning (a list as a set, a range by both ends), used everywhere
|
|
|
304
334
|
two values of that type are compared — including whether a value is the
|
|
305
335
|
default, so it's left out of the store. `valueTypeOf(kind)` gives each field
|
|
306
336
|
kind's: `booleanType` (`'1'` / `'0'`), `stringType` (one-of, text),
|
|
307
|
-
`stringSetType` (many-of, tree — a sorted comma list; a *present but empty*
|
|
337
|
+
`stringSetType` (many-of, many-of tree — a sorted comma list; a *present but empty*
|
|
308
338
|
value reads as the empty list, which differs from the key being absent
|
|
309
339
|
altogether), `numberType`, `rangeType` (`from..to`). A mixed-boolean field
|
|
310
340
|
shows an aggregate of other data and has no value type:
|
package/dist/field.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { ConfirmationSpec, Decision, ErrorRoutesRegistry, ExecutionContext,
|
|
|
9
9
|
* Design notes: unitas docs/2026-10-05-vultus-field-model-design.md.
|
|
10
10
|
*/
|
|
11
11
|
/** The field kinds (FieldControls.type and a FieldDefinition's `kind`). */
|
|
12
|
-
export type FieldKind = 'boolean' | 'mixed-boolean' | 'oneOf' | 'manyOf' | 'numeric' | 'range' | '
|
|
12
|
+
export type FieldKind = 'boolean' | 'mixed-boolean' | 'oneOf' | 'manyOf' | 'numeric' | 'range' | 'manyOfTree' | 'text';
|
|
13
13
|
/** The widget to render a field with: a name, or a name with display options overriding its defaults. */
|
|
14
14
|
export type WidgetHint = string | {
|
|
15
15
|
name: string;
|
package/dist/field.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AAEH,2EAA2E;AAC3E,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AAEH,2EAA2E;AAC3E,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;AAEvH,yGAAyG;AACzG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAA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B,YAAY,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,EAC/G,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAClD,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CA6EjC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { clamp, resolveNumeric, type NumericBounds, type ResolvedNumeric } from
|
|
|
18
18
|
export { useNumericField, numericInitialValue, type NumericFieldControls, type NumericFieldOptions, type NumericOwnOptions, } from './useNumericField.js';
|
|
19
19
|
export { useRangeField, rangeInitialValue, type NumberRange, type RangeFieldControls, type RangeFieldOptions, type RangeOwnOptions, } from './useRangeField.js';
|
|
20
20
|
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, type TreeNode, type TreeNodeControls, type TreeSelection, type TreeExpand, } from './tree.js';
|
|
21
|
-
export {
|
|
21
|
+
export { useManyOfTreeField, manyOfTreeInitialValue, type ManyOfTreeFieldControls, type ManyOfTreeFieldOptions, type ManyOfTreeOwnOptions, } from './useManyOfTreeField.js';
|
|
22
22
|
export { useTextField, textInitialValue, type TextFieldControls, type TextFieldOptions, type TextOwnOptions, } from './useTextField.js';
|
|
23
23
|
export { booleanType, stringType, stringSetType, numberType, rangeType, type ValueType, } from './valueTypes.js';
|
|
24
24
|
export { initialValueOf, valueTypeOf, sanitizeStored, type FieldDefinition } from './kinds.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE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a,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,GACrD,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,GAC5E,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EACL,uBAAuB,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EACzE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,GAChE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export { clamp, resolveNumeric } from './numeric.js';
|
|
|
17
17
|
export { useNumericField, numericInitialValue, } from './useNumericField.js';
|
|
18
18
|
export { useRangeField, rangeInitialValue, } from './useRangeField.js';
|
|
19
19
|
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, } from './tree.js';
|
|
20
|
-
export {
|
|
20
|
+
export { useManyOfTreeField, manyOfTreeInitialValue, } from './useManyOfTreeField.js';
|
|
21
21
|
export { useTextField, textInitialValue, } from './useTextField.js';
|
|
22
22
|
export { booleanType, stringType, stringSetType, numberType, rangeType, } from './valueTypes.js';
|
|
23
23
|
export { initialValueOf, valueTypeOf, sanitizeStored } from './kinds.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,w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,cAAc,EAAwB,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAoD,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EACL,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,GAEvC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,EAAE,cAAc,EAAE,eAAe,GACvC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAA8B,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAC;AACxF,OAAO,EACL,uBAAuB,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,GAE1E,MAAM,iBAAiB,CAAC"}
|
package/dist/kinds.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type NumericOwnOptions } from './useNumericField.js';
|
|
|
7
7
|
import { type OneOfOwnOptions } from './useOneOfField.js';
|
|
8
8
|
import { type NumberRange, type RangeOwnOptions } from './useRangeField.js';
|
|
9
9
|
import { type TextOwnOptions } from './useTextField.js';
|
|
10
|
-
import { type
|
|
10
|
+
import { type ManyOfTreeOwnOptions } from './useManyOfTreeField.js';
|
|
11
11
|
import { type ValueType } from './valueTypes.js';
|
|
12
12
|
/**
|
|
13
13
|
* A definition of kind `K`: the kind's hook options in their inside form, with `kind` required.
|
|
@@ -24,7 +24,7 @@ type Definition<K extends FieldKind, V, Own, Ctx> = {
|
|
|
24
24
|
* by `kind`, a definition is its kind's hook options as they are: `useOneOfField(definition)`.
|
|
25
25
|
* Its functions receive the field context `Ctx` (see FieldContextProvider).
|
|
26
26
|
*/
|
|
27
|
-
export type FieldDefinition<Ctx = any> = Definition<'boolean', boolean, {}, Ctx> | Definition<'mixed-boolean', MixedBool, {}, Ctx> | Definition<'oneOf', string, OneOfOwnOptions<string, Ctx>, Ctx> | Definition<'manyOf', string[], ManyOfOwnOptions<string, Ctx>, Ctx> | Definition<'numeric', number, NumericOwnOptions<Ctx>, Ctx> | Definition<'range', NumberRange, RangeOwnOptions<Ctx>, Ctx> | Definition<'
|
|
27
|
+
export type FieldDefinition<Ctx = any> = Definition<'boolean', boolean, {}, Ctx> | Definition<'mixed-boolean', MixedBool, {}, Ctx> | Definition<'oneOf', string, OneOfOwnOptions<string, Ctx>, Ctx> | Definition<'manyOf', string[], ManyOfOwnOptions<string, Ctx>, Ctx> | Definition<'numeric', number, NumericOwnOptions<Ctx>, Ctx> | Definition<'range', NumberRange, RangeOwnOptions<Ctx>, Ctx> | Definition<'manyOfTree', string[], ManyOfTreeOwnOptions<string, Ctx>, Ctx> | Definition<'text', string, TextOwnOptions, Ctx>;
|
|
28
28
|
/**
|
|
29
29
|
* A definition's default: `initialValue` resolved with the field context, else its kind's
|
|
30
30
|
* implicit initial value (false; the first enabled choice; the empty list; `min`, or 0, clamped
|
package/dist/kinds.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,KAAK,EAAQ,SAAS,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAsB,KAAK,gBAAgB,EAAuB,MAAM,qBAAqB,CAAC;AACrG,OAAO,EAAyB,KAAK,SAAS,EAA0B,MAAM,wBAAwB,CAAC;AACvG,OAAO,EAAuB,KAAK,iBAAiB,EAAwB,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAqB,KAAK,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAqB,KAAK,WAAW,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AC,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,CAAC,GAC/C,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAC9D,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAClE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAC1D,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAC3D,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,oBAAoB,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,GAC1E,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;AAgDpD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAclF;AAED,gIAAgI;AAChI,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAY3D;AAQD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,eAAe,EAC3B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,QAAQ,EACb,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAyC,GACnE,OAAO,CAyDT"}
|
package/dist/kinds.js
CHANGED
|
@@ -9,7 +9,7 @@ import { numericInitialValue } from './useNumericField.js';
|
|
|
9
9
|
import { oneOfInitialValue } from './useOneOfField.js';
|
|
10
10
|
import { rangeInitialValue } from './useRangeField.js';
|
|
11
11
|
import { textInitialValue } from './useTextField.js';
|
|
12
|
-
import {
|
|
12
|
+
import { manyOfTreeInitialValue } from './useManyOfTreeField.js';
|
|
13
13
|
import { booleanType, numberType, rangeType, stringSetType, stringType } from './valueTypes.js';
|
|
14
14
|
const NOT_STORABLE = 'a mixed-boolean field is an aggregate of other data and cannot be stored';
|
|
15
15
|
/** A definition whose kind is none of FieldKind's (plain data can carry anything): fail loudly rather than give nothing. */
|
|
@@ -31,7 +31,7 @@ function nodeValues(nodes, into = new Set()) {
|
|
|
31
31
|
}
|
|
32
32
|
return into;
|
|
33
33
|
}
|
|
34
|
-
/** A tree definition's nodes, resolved as
|
|
34
|
+
/** A tree definition's nodes, resolved as useManyOfTreeField resolves them. */
|
|
35
35
|
function nodesOf(definition, ctx) {
|
|
36
36
|
return resolveIn(definition.nodes, [], ctx, `Field '${definition.id}': option 'nodes'`);
|
|
37
37
|
}
|
|
@@ -52,8 +52,8 @@ export function initialValueOf(definition, ctx) {
|
|
|
52
52
|
case 'manyOf': return manyOfInitialValue(definition, ctx, id);
|
|
53
53
|
case 'numeric': return numericInitialValue(definition, ctx, id);
|
|
54
54
|
case 'range': return rangeInitialValue(definition, ctx, id);
|
|
55
|
-
case '
|
|
56
|
-
return normalizeTreeValue(nodesOf(definition, ctx),
|
|
55
|
+
case 'manyOfTree':
|
|
56
|
+
return normalizeTreeValue(nodesOf(definition, ctx), manyOfTreeInitialValue(definition, ctx, id), definition.selection ?? 'topmost');
|
|
57
57
|
case 'text': return textInitialValue(definition, ctx, id);
|
|
58
58
|
default: return unknownKind(definition);
|
|
59
59
|
}
|
|
@@ -65,7 +65,7 @@ export function valueTypeOf(kind) {
|
|
|
65
65
|
case 'oneOf':
|
|
66
66
|
case 'text': return stringType;
|
|
67
67
|
case 'manyOf':
|
|
68
|
-
case '
|
|
68
|
+
case 'manyOfTree': return stringSetType;
|
|
69
69
|
case 'numeric': return numberType;
|
|
70
70
|
case 'range': return rangeType;
|
|
71
71
|
case 'mixed-boolean': throw new Error(NOT_STORABLE);
|
|
@@ -115,7 +115,7 @@ export function sanitizeStored(definition, value, ctx, warn = (message) => conso
|
|
|
115
115
|
warnDropped(id, 'choices', stored.filter((v) => !known.includes(v)), warn);
|
|
116
116
|
return known.filter((v) => stored.includes(v));
|
|
117
117
|
}
|
|
118
|
-
case '
|
|
118
|
+
case 'manyOfTree': {
|
|
119
119
|
const stored = value;
|
|
120
120
|
const nodes = nodesOf(definition, ctx);
|
|
121
121
|
const known = nodeValues(nodes);
|
package/dist/kinds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.js","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8C,MAAM,cAAc,CAAC;AAGzF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAiB,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAqB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAA8C,MAAM,qBAAqB,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAA0C,MAAM,wBAAwB,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAgD,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,iBAAiB,EAA4C,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAA8D,MAAM,oBAAoB,CAAC;AACnH,OAAO,EAAE,gBAAgB,EAA0C,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"kinds.js","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8C,MAAM,cAAc,CAAC;AAGzF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,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iC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;gBAC9H,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,UAAU,EAAE,mBAAmB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,+CAA+C,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;gBAC5I,CAAC;YACH,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,CAAC,CAAC,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC"}
|
package/dist/parseApiError.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { ParsedApiError } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a thrown error says, for an action's or a field commit's error message: an API error's
|
|
4
|
+
* status, reason and message (ts-rest's reject shape, `{ status, body: { message, reason } }`);
|
|
5
|
+
* without a body message, a thrown `Error`'s own message (`new Error('Printer offline')`, a
|
|
6
|
+
* failed fetch's TypeError), unless empty. `status` is 0 when the error carries none.
|
|
7
|
+
*/
|
|
2
8
|
export declare function parseApiError(err: unknown): ParsedApiError;
|
|
3
9
|
//# sourceMappingURL=parseApiError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseApiError.d.ts","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAQ1D"}
|
|
1
|
+
{"version":3,"file":"parseApiError.d.ts","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAQ1D"}
|
package/dist/parseApiError.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a thrown error says, for an action's or a field commit's error message: an API error's
|
|
3
|
+
* status, reason and message (ts-rest's reject shape, `{ status, body: { message, reason } }`);
|
|
4
|
+
* without a body message, a thrown `Error`'s own message (`new Error('Printer offline')`, a
|
|
5
|
+
* failed fetch's TypeError), unless empty. `status` is 0 when the error carries none.
|
|
6
|
+
*/
|
|
1
7
|
export function parseApiError(err) {
|
|
2
8
|
if (typeof err !== 'object' || err === null)
|
|
3
9
|
return { status: 0 };
|
|
@@ -5,7 +11,7 @@ export function parseApiError(err) {
|
|
|
5
11
|
return {
|
|
6
12
|
status: e.status ?? 0,
|
|
7
13
|
reason: e.body?.reason,
|
|
8
|
-
message: e.body?.message,
|
|
14
|
+
message: e.body?.message ?? ((err instanceof Error && err.message) || undefined),
|
|
9
15
|
};
|
|
10
16
|
}
|
|
11
17
|
//# sourceMappingURL=parseApiError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseApiError.js","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAClE,MAAM,CAAC,GAAG,GAAwE,CAAC;IACnF,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM;QACtB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"parseApiError.js","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAClE,MAAM,CAAC,GAAG,GAAwE,CAAC;IACnF,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM;QACtB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;KACjF,CAAC;AACJ,CAAC"}
|
package/dist/tree.d.ts
CHANGED
|
@@ -12,12 +12,20 @@ export interface TreeNodeControls<T extends string = string> extends OneOfChoice
|
|
|
12
12
|
/**
|
|
13
13
|
* What a tree field's value lists, as antd TreeSelect's `showCheckedStrategy` and
|
|
14
14
|
* `checkStrictly` do. In the three cascading selections a node stands for its subtree, and
|
|
15
|
-
* a node all of whose children are covered is covered too
|
|
16
|
-
* covered nodes the
|
|
15
|
+
* a node all of whose children are covered is covered too — disabled nodes aside, as antd
|
|
16
|
+
* conducts its checks (see `cascade`); they differ only in which of the covered nodes the
|
|
17
|
+
* value names:
|
|
17
18
|
* - `'topmost'` (`SHOW_PARENT`, the default): the covered nodes whose parent is not covered;
|
|
18
19
|
* - `'all'` (`SHOW_ALL`): every covered node;
|
|
19
20
|
* - `'leaves'` (`SHOW_CHILD`): the covered leaves.
|
|
20
21
|
*
|
|
22
|
+
* Where a disabled node breaks the cascade, the value also names what the others would not
|
|
23
|
+
* cover: `'topmost'` a covered disabled node under a covered parent, and a covered node under
|
|
24
|
+
* a covered disabled parent (as antd TreeSelect's SHOW_PARENT does); `'leaves'` a covered node
|
|
25
|
+
* with children that is disabled or has no enabled child (stricter than antd's SHOW_CHILD,
|
|
26
|
+
* which drops a checked disabled parent whose enabled children are all checked, and a parent
|
|
27
|
+
* whose only children are disabled and checked — so the value would no longer cover them).
|
|
28
|
+
*
|
|
21
29
|
* `'independent'` (`checkStrictly`, moxb's `strictSelect`): each node is chosen on its own.
|
|
22
30
|
*/
|
|
23
31
|
export type TreeSelection = 'topmost' | 'all' | 'leaves' | 'independent';
|
|
@@ -37,16 +45,20 @@ export declare function normalizeTreeValue<T extends string>(nodes: TreeNode<T>[
|
|
|
37
45
|
/**
|
|
38
46
|
* Every node a tree field's value stands for, in pre-order (what an item filed under some
|
|
39
47
|
* node matches against): in the cascading selections the covered nodes (the value's nodes,
|
|
40
|
-
* their descendants, and every node all of whose children are
|
|
41
|
-
* `'independent'` the value's nodes themselves. Values that
|
|
42
|
-
* normalizeTreeValue.
|
|
48
|
+
* their enabled descendants, and every enabled node all of whose enabled children are
|
|
49
|
+
* covered; see `cascade`); with `'independent'` the value's nodes themselves. Values that
|
|
50
|
+
* name no node follow, as in normalizeTreeValue. A node disabled when the value was stored
|
|
51
|
+
* and enabled now is covered from then on (with `'topmost'`, a stored parent covers it).
|
|
43
52
|
*/
|
|
44
53
|
export declare function coveredNodes<T extends string>(nodes: TreeNode<T>[], value: T[], selection?: TreeSelection): T[];
|
|
45
54
|
/**
|
|
46
|
-
* The value after flipping `node`, normalized
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
55
|
+
* The value after flipping `node`, normalized, as antd's Tree flips a checkbox. In the
|
|
56
|
+
* cascading selections a covered node is removed with the descendants it covers through
|
|
57
|
+
* enabled nodes and with its enabled ancestors up to the first disabled one (they no longer
|
|
58
|
+
* have all their enabled children); an uncovered one is added, covering its subtree as
|
|
59
|
+
* `cascade` says. With `'independent'` the node alone is added or removed. A `node` that is
|
|
60
|
+
* not one of the nodes changes nothing. Whether `node` itself may be flipped is the caller's
|
|
61
|
+
* to decide (useManyOfTreeField refuses a disabled one).
|
|
50
62
|
*/
|
|
51
63
|
export declare function toggleTreeValue<T extends string>(nodes: TreeNode<T>[], value: T[], node: T, selection: TreeSelection): T[];
|
|
52
64
|
/** The nodes a tree widget opens at first under `expand` (see TreeExpand), in pre-order. */
|
package/dist/tree.d.ts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CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,GAAE,aAAyB,GAAG,CAAC,EAAE,CAE1H;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,aAAa,GAAG,CAAC,EAAE,CAoB1H;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,CAU5G;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAYtH"}
|
package/dist/tree.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getVerdict } from './decision.js';
|
|
1
2
|
import { normalizeText } from './normalizeText.js';
|
|
2
3
|
function hasChildren(node) {
|
|
3
4
|
return (node.children?.length ?? 0) > 0;
|
|
@@ -23,14 +24,33 @@ function unknownValues(order, value) {
|
|
|
23
24
|
const known = new Set(order.map((n) => n.value));
|
|
24
25
|
return [...new Set(value.filter((v) => !known.has(v)))];
|
|
25
26
|
}
|
|
26
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Whether a node can be checked: its `enabled` / `disabled` resolved as resolveChoice does (a
|
|
29
|
+
* Decision takes no context, so this needs none). Works on a definition's nodes (TreeNode,
|
|
30
|
+
* Decisions) and on the widgets' node controls (TreeNodeControls, `enabled: boolean`) alike.
|
|
31
|
+
*/
|
|
32
|
+
function nodeEnabled(node) {
|
|
33
|
+
if (node.enabled !== undefined)
|
|
34
|
+
return getVerdict(node.enabled, true);
|
|
35
|
+
return !getVerdict(node.disabled, false);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The nodes a value covers in the cascading selections, by antd's check conduction (rc-tree's
|
|
39
|
+
* conductCheck), so the hook and the widgets agree: the value's nodes; the enabled children of
|
|
40
|
+
* a covered enabled node, and so on down (a disabled node is never covered through a checked
|
|
41
|
+
* ancestor, nor is its subtree through it); and an enabled node all of whose enabled children
|
|
42
|
+
* are covered, if it has any (a parent whose children are all disabled, or a disabled parent,
|
|
43
|
+
* is never covered through its children). A disabled node in the value covers itself only.
|
|
44
|
+
*/
|
|
27
45
|
function cascade(nodes, value) {
|
|
28
46
|
const listed = new Set(value);
|
|
29
47
|
const covered = new Set();
|
|
30
48
|
const walk = (node, inherited) => {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
49
|
+
const enabled = nodeEnabled(node);
|
|
50
|
+
const self = listed.has(node.value) || (inherited && enabled);
|
|
51
|
+
const children = (node.children ?? []).map((child) => ({ enabled: nodeEnabled(child), covered: walk(child, self && enabled) }));
|
|
52
|
+
const counted = children.filter((child) => child.enabled);
|
|
53
|
+
const isCovered = self || (enabled && counted.length > 0 && counted.every((child) => child.covered));
|
|
34
54
|
if (isCovered)
|
|
35
55
|
covered.add(node.value);
|
|
36
56
|
return isCovered;
|
|
@@ -39,16 +59,31 @@ function cascade(nodes, value) {
|
|
|
39
59
|
walk(node, false);
|
|
40
60
|
return covered;
|
|
41
61
|
}
|
|
42
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The covered nodes the value names under `selection` (see TreeSelection), in pre-order, by
|
|
64
|
+
* rc-tree-select's formatStrategyValues (for `'leaves'`, a stricter form of it), so that the
|
|
65
|
+
* named nodes cover exactly what `covered` does (`cascade` of them gives it back) also where
|
|
66
|
+
* disabled nodes break the cascade:
|
|
67
|
+
* - `'topmost'`: a covered node unless its parent is covered and neither of the two is
|
|
68
|
+
* disabled (only then does the parent cover it);
|
|
69
|
+
* - `'leaves'`: the covered leaves, and a covered node with children that is disabled, has
|
|
70
|
+
* no enabled child, or has an enabled child not covered (its children would not cover it);
|
|
71
|
+
* - `'all'`: every covered node.
|
|
72
|
+
*/
|
|
43
73
|
function namedNodes(order, parent, covered, selection) {
|
|
74
|
+
const enabled = new Map(order.map((node) => [node.value, nodeEnabled(node)]));
|
|
44
75
|
const named = order.filter((node) => {
|
|
45
76
|
if (!covered.has(node.value))
|
|
46
77
|
return false;
|
|
47
|
-
if (selection === 'leaves')
|
|
48
|
-
return !hasChildren(node);
|
|
49
78
|
if (selection === 'topmost') {
|
|
50
79
|
const up = parent.get(node.value);
|
|
51
|
-
return up === undefined || !covered.has(up);
|
|
80
|
+
return up === undefined || !covered.has(up) || !enabled.get(node.value) || !enabled.get(up);
|
|
81
|
+
}
|
|
82
|
+
if (selection === 'leaves') {
|
|
83
|
+
if (!hasChildren(node) || !enabled.get(node.value))
|
|
84
|
+
return true;
|
|
85
|
+
const counted = node.children.filter((child) => enabled.get(child.value));
|
|
86
|
+
return counted.length === 0 || !counted.every((child) => covered.has(child.value));
|
|
52
87
|
}
|
|
53
88
|
return true;
|
|
54
89
|
});
|
|
@@ -71,18 +106,22 @@ export function normalizeTreeValue(nodes, value, selection) {
|
|
|
71
106
|
/**
|
|
72
107
|
* Every node a tree field's value stands for, in pre-order (what an item filed under some
|
|
73
108
|
* node matches against): in the cascading selections the covered nodes (the value's nodes,
|
|
74
|
-
* their descendants, and every node all of whose children are
|
|
75
|
-
* `'independent'` the value's nodes themselves. Values that
|
|
76
|
-
* normalizeTreeValue.
|
|
109
|
+
* their enabled descendants, and every enabled node all of whose enabled children are
|
|
110
|
+
* covered; see `cascade`); with `'independent'` the value's nodes themselves. Values that
|
|
111
|
+
* name no node follow, as in normalizeTreeValue. A node disabled when the value was stored
|
|
112
|
+
* and enabled now is covered from then on (with `'topmost'`, a stored parent covers it).
|
|
77
113
|
*/
|
|
78
114
|
export function coveredNodes(nodes, value, selection = 'topmost') {
|
|
79
115
|
return normalizeTreeValue(nodes, value, selection === 'independent' ? 'independent' : 'all');
|
|
80
116
|
}
|
|
81
117
|
/**
|
|
82
|
-
* The value after flipping `node`, normalized
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
118
|
+
* The value after flipping `node`, normalized, as antd's Tree flips a checkbox. In the
|
|
119
|
+
* cascading selections a covered node is removed with the descendants it covers through
|
|
120
|
+
* enabled nodes and with its enabled ancestors up to the first disabled one (they no longer
|
|
121
|
+
* have all their enabled children); an uncovered one is added, covering its subtree as
|
|
122
|
+
* `cascade` says. With `'independent'` the node alone is added or removed. A `node` that is
|
|
123
|
+
* not one of the nodes changes nothing. Whether `node` itself may be flipped is the caller's
|
|
124
|
+
* to decide (useManyOfTreeField refuses a disabled one).
|
|
86
125
|
*/
|
|
87
126
|
export function toggleTreeValue(nodes, value, node, selection) {
|
|
88
127
|
const { order, parent } = indexTree(nodes);
|
|
@@ -93,16 +132,20 @@ export function toggleTreeValue(nodes, value, node, selection) {
|
|
|
93
132
|
return normalizeTreeValue(nodes, value.includes(node) ? value.filter((v) => v !== node) : [...value, node], selection);
|
|
94
133
|
}
|
|
95
134
|
const covered = cascade(nodes, value);
|
|
96
|
-
const subtree = indexTree([target]).order.map((n) => n.value);
|
|
97
135
|
if (covered.has(node)) {
|
|
98
|
-
|
|
99
|
-
covered.delete(
|
|
100
|
-
|
|
136
|
+
const uncover = (n) => {
|
|
137
|
+
covered.delete(n.value);
|
|
138
|
+
for (const child of n.children ?? [])
|
|
139
|
+
if (nodeEnabled(child))
|
|
140
|
+
uncover(child);
|
|
141
|
+
};
|
|
142
|
+
uncover(target);
|
|
143
|
+
const byValue = new Map(order.map((n) => [n.value, n]));
|
|
144
|
+
for (let up = parent.get(node); up !== undefined && nodeEnabled(byValue.get(up)); up = parent.get(up))
|
|
101
145
|
covered.delete(up);
|
|
102
146
|
}
|
|
103
147
|
else {
|
|
104
|
-
|
|
105
|
-
covered.add(v);
|
|
148
|
+
covered.add(node);
|
|
106
149
|
}
|
|
107
150
|
return normalizeTreeValue(nodes, [...covered, ...unknownValues(order, value)], selection);
|
|
108
151
|
}
|
package/dist/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA0CnD,SAAS,WAAW,CAAC,IAA8B;IACjD,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,sDAAsD;AACtD,SAAS,SAAS,CAAmB,KAAoB;IACvD,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAQ,CAAC;IAC/B,MAAM,IAAI,GAAG,CAAC,IAAmB,EAAE,EAAiB,EAAE,EAAE;QACtD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,EAAE,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACjD,IAAI,IAAI,CAAC,QAAQ;gBAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,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M,OAAO,GAAG,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACjD,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,OAAO,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { type FieldControls, type FieldOptions } from './field.js';
|
|
|
2
2
|
import { type FieldCtx } from './FieldContext.js';
|
|
3
3
|
import { type TreeExpand, type TreeNode, type TreeNodeControls, type TreeSelection } from './tree.js';
|
|
4
4
|
import type { ErrorRoutesRegistry, ValueOrFn } from './types.js';
|
|
5
|
-
export type
|
|
5
|
+
export type ManyOfTreeOwnOptions<T extends string = string, Ctx = any> = {
|
|
6
6
|
/** The roots, each with its children; static or derived (a function, of the field context if it declares a parameter). */
|
|
7
7
|
nodes: ValueOrFn<TreeNode<T>[], Ctx>;
|
|
8
8
|
/** What the value lists; default `'topmost'` (see TreeSelection). */
|
|
@@ -10,8 +10,8 @@ export type TreeOwnOptions<T extends string = string, Ctx = any> = {
|
|
|
10
10
|
/** Which nodes a widget opens at first; default `'top'` (see TreeExpand). */
|
|
11
11
|
expand?: TreeExpand;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
14
|
-
export interface
|
|
13
|
+
export type ManyOfTreeFieldOptions<T extends string = string, RouteId extends string = string, Ctx = any> = FieldOptions<T[], T[], RouteId, Ctx> & ManyOfTreeOwnOptions<T, Ctx>;
|
|
14
|
+
export interface ManyOfTreeFieldControls<T extends string = string> extends FieldControls<T[], T[]> {
|
|
15
15
|
/** The roots as the widgets get them, each with its children. */
|
|
16
16
|
nodes: TreeNodeControls<T>[];
|
|
17
17
|
selection: TreeSelection;
|
|
@@ -22,18 +22,19 @@ export interface TreeFieldControls<T extends string = string> extends FieldContr
|
|
|
22
22
|
/** Checks or unchecks a node (with its subtree, in the cascading selections); ignored (with a warning) for an unknown or disabled node. */
|
|
23
23
|
toggle(value: T): void;
|
|
24
24
|
}
|
|
25
|
-
/** The implicit initial value for a tree field: `initialValue` resolved, else the empty list. */
|
|
26
|
-
export declare function
|
|
25
|
+
/** The implicit initial value for a many-of tree field: `initialValue` resolved, else the empty list. */
|
|
26
|
+
export declare function manyOfTreeInitialValue<T extends string>(opts: {
|
|
27
27
|
initialValue?: ValueOrFn<T[]>;
|
|
28
28
|
}, ctx: FieldCtx, id: string): T[];
|
|
29
29
|
/**
|
|
30
30
|
* A field whose value is a set of tree nodes (Praeceptor's category filter), with antd
|
|
31
|
-
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
32
|
-
*
|
|
31
|
+
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
32
|
+
* (its enabled part: disabled nodes follow antd's check conduction, so the widgets show what
|
|
33
|
+
* the value covers), and `selection` says which nodes the value lists (see TreeSelection). The value is shown
|
|
33
34
|
* and requested normalized (normalizeTreeValue): in tree pre-order, values that name no
|
|
34
35
|
* node (a stored value naming a removed node) kept at the end. `setValue` does not police
|
|
35
36
|
* disabled nodes (the widgets disable them); `toggle` refuses a disabled or unknown node with
|
|
36
37
|
* a warning, as useManyOfField does.
|
|
37
38
|
*/
|
|
38
|
-
export declare function
|
|
39
|
-
//# sourceMappingURL=
|
|
39
|
+
export declare function useManyOfTreeField<T extends string = string, RouteId extends string = string, Ctx = any>(opts: ManyOfTreeFieldOptions<T, RouteId, Ctx>, registry?: ErrorRoutesRegistry<RouteId>): ManyOfTreeFieldControls<T>;
|
|
40
|
+
//# sourceMappingURL=useManyOfTreeField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useManyOfTreeField.d.ts","sourceRoot":"","sources":["../src/useManyOfTreeField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAEL,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAC1E,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI;IACvE,0HAA0H;IAC1H,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACrC,qEAAqE;IACrE,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,IACtG,YAAY,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAEtE,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IACjG,iEAAiE;IACjE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,yDAAyD;IACzD,YAAY,EAAE,CAAC,EAAE,CAAC;IAClB,gCAAgC;IAChC,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,2IAA2I;IAC3I,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACxB;AAED,yGAAyG;AACzG,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,IAAI,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAA;CAAE,EACvC,GAAG,EAAE,QAAQ,EACb,EAAE,EAAE,MAAM,GACT,CAAC,EAAE,CAEL;AAMD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,EACtG,IAAI,EAAE,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAC7C,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACtC,uBAAuB,CAAC,CAAC,CAAC,CAgD5B"}
|
|
@@ -3,8 +3,8 @@ import { resolveChoice } from './choices.js';
|
|
|
3
3
|
import { useFieldContext } from './FieldContext.js';
|
|
4
4
|
import { resolveIn } from './resolve.js';
|
|
5
5
|
import { coveredNodes, expandedTreeKeys, normalizeTreeValue, toggleTreeValue, } from './tree.js';
|
|
6
|
-
/** The implicit initial value for a tree field: `initialValue` resolved, else the empty list. */
|
|
7
|
-
export function
|
|
6
|
+
/** The implicit initial value for a many-of tree field: `initialValue` resolved, else the empty list. */
|
|
7
|
+
export function manyOfTreeInitialValue(opts, ctx, id) {
|
|
8
8
|
return resolveIn(opts.initialValue, [], ctx, `Field '${id}': option 'initialValue'`);
|
|
9
9
|
}
|
|
10
10
|
function sameList(a, b) {
|
|
@@ -12,20 +12,21 @@ function sameList(a, b) {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* A field whose value is a set of tree nodes (Praeceptor's category filter), with antd
|
|
15
|
-
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
16
|
-
*
|
|
15
|
+
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
16
|
+
* (its enabled part: disabled nodes follow antd's check conduction, so the widgets show what
|
|
17
|
+
* the value covers), and `selection` says which nodes the value lists (see TreeSelection). The value is shown
|
|
17
18
|
* and requested normalized (normalizeTreeValue): in tree pre-order, values that name no
|
|
18
19
|
* node (a stored value naming a removed node) kept at the end. `setValue` does not police
|
|
19
20
|
* disabled nodes (the widgets disable them); `toggle` refuses a disabled or unknown node with
|
|
20
21
|
* a warning, as useManyOfField does.
|
|
21
22
|
*/
|
|
22
|
-
export function
|
|
23
|
+
export function useManyOfTreeField(opts, registry) {
|
|
23
24
|
const ctx = useFieldContext();
|
|
24
25
|
const nodes = resolveIn(opts.nodes, [], ctx, `Field '${opts.id}': option 'nodes'`);
|
|
25
26
|
const selection = opts.selection ?? 'topmost';
|
|
26
27
|
const inside = !opts.onChange && !opts.commit;
|
|
27
|
-
const initialValue = () =>
|
|
28
|
-
const field = useFieldCore('
|
|
28
|
+
const initialValue = () => manyOfTreeInitialValue(opts, ctx, opts.id);
|
|
29
|
+
const field = useFieldCore('manyOfTree', inside ? { ...opts, initialValue } : opts, registry);
|
|
29
30
|
// The same list object while it is already normalized, so the value is stable across renders.
|
|
30
31
|
const normalized = normalizeTreeValue(nodes, field.value, selection);
|
|
31
32
|
const value = sameList(normalized, field.value) ? field.value : normalized;
|
|
@@ -63,4 +64,4 @@ export function useTreeField(opts, registry) {
|
|
|
63
64
|
toggle,
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
|
-
//# sourceMappingURL=
|
|
67
|
+
//# sourceMappingURL=useManyOfTreeField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useManyOfTreeField.js","sourceRoot":"","sources":["../src/useManyOfTreeField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyC,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,GAEpE,MAAM,WAAW,CAAC;AA2BnB,yGAAyG;AACzG,MAAM,UAAU,sBAAsB,CACpC,IAAuC,EACvC,GAAa,EACb,EAAU;IAEV,OAAO,SAAS,CAAM,IAAI,CAAC,YAAY,EAAE,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,0BAA0B,CAAC,CAAC;AAC5F,CAAC;AAED,SAAS,QAAQ,CAAI,CAAM,EAAE,CAAM;IACjC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAA6C,EAC7C,QAAuC;IAEvC,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,SAAS,CAAgB,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,UAAU,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAClG,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC;IAE9C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ACF,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAExC,MAAM,QAAQ,GAAG,CAAC,IAAS,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAE3F,MAAM,MAAM,GAAG,CAAC,CAAI,EAAE,EAAE;QACtB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,YAAY,CAAC,mBAAmB,IAAI,CAAC,WAAW,IAAI,aAAa,EAAE,CAAC,CAAC;YACnG,OAAO;QACT,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,KAAK;QACL,QAAQ;QACR,KAAK,EAAE,YAAY;QACnB,SAAS;QACT,YAAY,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;QAClE,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vultus-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Framework-neutral action model + hooks for vultus (antd-free by design)",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
56
|
-
"test": "vitest run"
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
57
58
|
},
|
|
58
59
|
"main": "./dist/index.js",
|
|
59
60
|
"types": "./dist/index.d.ts"
|
package/src/field.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/** The field kinds (FieldControls.type and a FieldDefinition's `kind`). */
|
|
26
|
-
export type FieldKind = 'boolean' | 'mixed-boolean' | 'oneOf' | 'manyOf' | 'numeric' | 'range' | '
|
|
26
|
+
export type FieldKind = 'boolean' | 'mixed-boolean' | 'oneOf' | 'manyOf' | 'numeric' | 'range' | 'manyOfTree' | 'text';
|
|
27
27
|
|
|
28
28
|
/** The widget to render a field with: a name, or a name with display options overriding its defaults. */
|
|
29
29
|
export type WidgetHint = string | { name: string; [option: string]: unknown };
|
package/src/index.ts
CHANGED
|
@@ -46,9 +46,9 @@ export {
|
|
|
46
46
|
type TreeNode, type TreeNodeControls, type TreeSelection, type TreeExpand,
|
|
47
47
|
} from './tree.js';
|
|
48
48
|
export {
|
|
49
|
-
|
|
50
|
-
type
|
|
51
|
-
} from './
|
|
49
|
+
useManyOfTreeField, manyOfTreeInitialValue,
|
|
50
|
+
type ManyOfTreeFieldControls, type ManyOfTreeFieldOptions, type ManyOfTreeOwnOptions,
|
|
51
|
+
} from './useManyOfTreeField.js';
|
|
52
52
|
export {
|
|
53
53
|
useTextField, textInitialValue,
|
|
54
54
|
type TextFieldControls, type TextFieldOptions, type TextOwnOptions,
|
package/src/kinds.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { numericInitialValue, type NumericOwnOptions, type useNumericField } fro
|
|
|
12
12
|
import { oneOfInitialValue, type OneOfOwnOptions, type useOneOfField } from './useOneOfField.js';
|
|
13
13
|
import { rangeInitialValue, type NumberRange, type RangeOwnOptions, type useRangeField } from './useRangeField.js';
|
|
14
14
|
import { textInitialValue, type TextOwnOptions, type useTextField } from './useTextField.js';
|
|
15
|
-
import {
|
|
15
|
+
import { manyOfTreeInitialValue, type ManyOfTreeOwnOptions, type useManyOfTreeField } from './useManyOfTreeField.js';
|
|
16
16
|
import { booleanType, numberType, rangeType, stringSetType, stringType, type ValueType } from './valueTypes.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -35,7 +35,7 @@ export type FieldDefinition<Ctx = any> =
|
|
|
35
35
|
| Definition<'manyOf', string[], ManyOfOwnOptions<string, Ctx>, Ctx>
|
|
36
36
|
| Definition<'numeric', number, NumericOwnOptions<Ctx>, Ctx>
|
|
37
37
|
| Definition<'range', NumberRange, RangeOwnOptions<Ctx>, Ctx>
|
|
38
|
-
| Definition<'
|
|
38
|
+
| Definition<'manyOfTree', string[], ManyOfTreeOwnOptions<string, Ctx>, Ctx>
|
|
39
39
|
| Definition<'text', string, TextOwnOptions, Ctx>;
|
|
40
40
|
|
|
41
41
|
type DefinitionOf<K extends FieldKind> = Extract<FieldDefinition, { kind: K }>;
|
|
@@ -52,7 +52,7 @@ type DefinitionsFitTheirHooks = [
|
|
|
52
52
|
Fits<DefinitionOf<'manyOf'>, HookOptions<typeof useManyOfField>>,
|
|
53
53
|
Fits<DefinitionOf<'numeric'>, HookOptions<typeof useNumericField>>,
|
|
54
54
|
Fits<DefinitionOf<'range'>, HookOptions<typeof useRangeField>>,
|
|
55
|
-
Fits<DefinitionOf<'
|
|
55
|
+
Fits<DefinitionOf<'manyOfTree'>, HookOptions<typeof useManyOfTreeField>>,
|
|
56
56
|
Fits<DefinitionOf<'text'>, HookOptions<typeof useTextField>>,
|
|
57
57
|
];
|
|
58
58
|
|
|
@@ -79,7 +79,7 @@ function nodeValues(nodes: TreeNode[], into = new Set<string>()): Set<string> {
|
|
|
79
79
|
return into;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/** A tree definition's nodes, resolved as
|
|
82
|
+
/** A tree definition's nodes, resolved as useManyOfTreeField resolves them. */
|
|
83
83
|
function nodesOf(definition: { id: string; nodes: ValueOrFn<TreeNode[]> }, ctx: FieldCtx): TreeNode[] {
|
|
84
84
|
return resolveIn<TreeNode[]>(definition.nodes, [], ctx, `Field '${definition.id}': option 'nodes'`);
|
|
85
85
|
}
|
|
@@ -101,8 +101,8 @@ export function initialValueOf(definition: FieldDefinition, ctx: FieldCtx): unkn
|
|
|
101
101
|
case 'manyOf': return manyOfInitialValue(definition, ctx, id);
|
|
102
102
|
case 'numeric': return numericInitialValue(definition, ctx, id);
|
|
103
103
|
case 'range': return rangeInitialValue(definition, ctx, id);
|
|
104
|
-
case '
|
|
105
|
-
return normalizeTreeValue(nodesOf(definition, ctx),
|
|
104
|
+
case 'manyOfTree':
|
|
105
|
+
return normalizeTreeValue(nodesOf(definition, ctx), manyOfTreeInitialValue(definition, ctx, id), definition.selection ?? 'topmost');
|
|
106
106
|
case 'text': return textInitialValue(definition, ctx, id);
|
|
107
107
|
default: return unknownKind(definition);
|
|
108
108
|
}
|
|
@@ -115,7 +115,7 @@ export function valueTypeOf(kind: FieldKind): ValueType<any> {
|
|
|
115
115
|
case 'oneOf':
|
|
116
116
|
case 'text': return stringType;
|
|
117
117
|
case 'manyOf':
|
|
118
|
-
case '
|
|
118
|
+
case 'manyOfTree': return stringSetType;
|
|
119
119
|
case 'numeric': return numberType;
|
|
120
120
|
case 'range': return rangeType;
|
|
121
121
|
case 'mixed-boolean': throw new Error(NOT_STORABLE);
|
|
@@ -169,7 +169,7 @@ export function sanitizeStored(
|
|
|
169
169
|
warnDropped(id, 'choices', stored.filter((v) => !known.includes(v)), warn);
|
|
170
170
|
return known.filter((v) => stored.includes(v));
|
|
171
171
|
}
|
|
172
|
-
case '
|
|
172
|
+
case 'manyOfTree': {
|
|
173
173
|
const stored = value as string[];
|
|
174
174
|
const nodes = nodesOf(definition, ctx);
|
|
175
175
|
const known = nodeValues(nodes);
|
package/src/parseApiError.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { ParsedApiError } from './types.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* What a thrown error says, for an action's or a field commit's error message: an API error's
|
|
5
|
+
* status, reason and message (ts-rest's reject shape, `{ status, body: { message, reason } }`);
|
|
6
|
+
* without a body message, a thrown `Error`'s own message (`new Error('Printer offline')`, a
|
|
7
|
+
* failed fetch's TypeError), unless empty. `status` is 0 when the error carries none.
|
|
8
|
+
*/
|
|
3
9
|
export function parseApiError(err: unknown): ParsedApiError {
|
|
4
10
|
if (typeof err !== 'object' || err === null) return { status: 0 };
|
|
5
11
|
const e = err as { status?: number; body?: { message?: string; reason?: string } };
|
|
6
12
|
return {
|
|
7
13
|
status: e.status ?? 0,
|
|
8
14
|
reason: e.body?.reason,
|
|
9
|
-
message: e.body?.message,
|
|
15
|
+
message: e.body?.message ?? ((err instanceof Error && err.message) || undefined),
|
|
10
16
|
};
|
|
11
17
|
}
|
package/src/tree.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OneOfChoice, OneOfChoiceControls } from './choices.js';
|
|
2
|
+
import { getVerdict } from './decision.js';
|
|
2
3
|
import { normalizeText } from './normalizeText.js';
|
|
3
4
|
|
|
4
5
|
/** A node of a tree field (Praeceptor's categories): a choice with children. */
|
|
@@ -16,12 +17,20 @@ export interface TreeNodeControls<T extends string = string> extends OneOfChoice
|
|
|
16
17
|
/**
|
|
17
18
|
* What a tree field's value lists, as antd TreeSelect's `showCheckedStrategy` and
|
|
18
19
|
* `checkStrictly` do. In the three cascading selections a node stands for its subtree, and
|
|
19
|
-
* a node all of whose children are covered is covered too
|
|
20
|
-
* covered nodes the
|
|
20
|
+
* a node all of whose children are covered is covered too — disabled nodes aside, as antd
|
|
21
|
+
* conducts its checks (see `cascade`); they differ only in which of the covered nodes the
|
|
22
|
+
* value names:
|
|
21
23
|
* - `'topmost'` (`SHOW_PARENT`, the default): the covered nodes whose parent is not covered;
|
|
22
24
|
* - `'all'` (`SHOW_ALL`): every covered node;
|
|
23
25
|
* - `'leaves'` (`SHOW_CHILD`): the covered leaves.
|
|
24
26
|
*
|
|
27
|
+
* Where a disabled node breaks the cascade, the value also names what the others would not
|
|
28
|
+
* cover: `'topmost'` a covered disabled node under a covered parent, and a covered node under
|
|
29
|
+
* a covered disabled parent (as antd TreeSelect's SHOW_PARENT does); `'leaves'` a covered node
|
|
30
|
+
* with children that is disabled or has no enabled child (stricter than antd's SHOW_CHILD,
|
|
31
|
+
* which drops a checked disabled parent whose enabled children are all checked, and a parent
|
|
32
|
+
* whose only children are disabled and checked — so the value would no longer cover them).
|
|
33
|
+
*
|
|
25
34
|
* `'independent'` (`checkStrictly`, moxb's `strictSelect`): each node is chosen on its own.
|
|
26
35
|
*/
|
|
27
36
|
export type TreeSelection = 'topmost' | 'all' | 'leaves' | 'independent';
|
|
@@ -58,14 +67,33 @@ function unknownValues<T extends string>(order: TreeNode<T>[], value: T[]): T[]
|
|
|
58
67
|
return [...new Set(value.filter((v) => !known.has(v)))];
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Whether a node can be checked: its `enabled` / `disabled` resolved as resolveChoice does (a
|
|
72
|
+
* Decision takes no context, so this needs none). Works on a definition's nodes (TreeNode,
|
|
73
|
+
* Decisions) and on the widgets' node controls (TreeNodeControls, `enabled: boolean`) alike.
|
|
74
|
+
*/
|
|
75
|
+
function nodeEnabled(node: Pick<TreeNode, 'enabled' | 'disabled'>): boolean {
|
|
76
|
+
if (node.enabled !== undefined) return getVerdict(node.enabled, true);
|
|
77
|
+
return !getVerdict(node.disabled, false);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The nodes a value covers in the cascading selections, by antd's check conduction (rc-tree's
|
|
82
|
+
* conductCheck), so the hook and the widgets agree: the value's nodes; the enabled children of
|
|
83
|
+
* a covered enabled node, and so on down (a disabled node is never covered through a checked
|
|
84
|
+
* ancestor, nor is its subtree through it); and an enabled node all of whose enabled children
|
|
85
|
+
* are covered, if it has any (a parent whose children are all disabled, or a disabled parent,
|
|
86
|
+
* is never covered through its children). A disabled node in the value covers itself only.
|
|
87
|
+
*/
|
|
62
88
|
function cascade<T extends string>(nodes: TreeNode<T>[], value: T[]): Set<T> {
|
|
63
89
|
const listed = new Set(value);
|
|
64
90
|
const covered = new Set<T>();
|
|
65
91
|
const walk = (node: TreeNode<T>, inherited: boolean): boolean => {
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
92
|
+
const enabled = nodeEnabled(node);
|
|
93
|
+
const self = listed.has(node.value) || (inherited && enabled);
|
|
94
|
+
const children = (node.children ?? []).map((child) => ({ enabled: nodeEnabled(child), covered: walk(child, self && enabled) }));
|
|
95
|
+
const counted = children.filter((child) => child.enabled);
|
|
96
|
+
const isCovered = self || (enabled && counted.length > 0 && counted.every((child) => child.covered));
|
|
69
97
|
if (isCovered) covered.add(node.value);
|
|
70
98
|
return isCovered;
|
|
71
99
|
};
|
|
@@ -73,14 +101,29 @@ function cascade<T extends string>(nodes: TreeNode<T>[], value: T[]): Set<T> {
|
|
|
73
101
|
return covered;
|
|
74
102
|
}
|
|
75
103
|
|
|
76
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The covered nodes the value names under `selection` (see TreeSelection), in pre-order, by
|
|
106
|
+
* rc-tree-select's formatStrategyValues (for `'leaves'`, a stricter form of it), so that the
|
|
107
|
+
* named nodes cover exactly what `covered` does (`cascade` of them gives it back) also where
|
|
108
|
+
* disabled nodes break the cascade:
|
|
109
|
+
* - `'topmost'`: a covered node unless its parent is covered and neither of the two is
|
|
110
|
+
* disabled (only then does the parent cover it);
|
|
111
|
+
* - `'leaves'`: the covered leaves, and a covered node with children that is disabled, has
|
|
112
|
+
* no enabled child, or has an enabled child not covered (its children would not cover it);
|
|
113
|
+
* - `'all'`: every covered node.
|
|
114
|
+
*/
|
|
77
115
|
function namedNodes<T extends string>(order: TreeNode<T>[], parent: Map<T, T>, covered: Set<T>, selection: TreeSelection): T[] {
|
|
116
|
+
const enabled = new Map(order.map((node) => [node.value, nodeEnabled(node)]));
|
|
78
117
|
const named = order.filter((node) => {
|
|
79
118
|
if (!covered.has(node.value)) return false;
|
|
80
|
-
if (selection === 'leaves') return !hasChildren(node);
|
|
81
119
|
if (selection === 'topmost') {
|
|
82
120
|
const up = parent.get(node.value);
|
|
83
|
-
return up === undefined || !covered.has(up);
|
|
121
|
+
return up === undefined || !covered.has(up) || !enabled.get(node.value) || !enabled.get(up);
|
|
122
|
+
}
|
|
123
|
+
if (selection === 'leaves') {
|
|
124
|
+
if (!hasChildren(node) || !enabled.get(node.value)) return true;
|
|
125
|
+
const counted = node.children!.filter((child) => enabled.get(child.value));
|
|
126
|
+
return counted.length === 0 || !counted.every((child) => covered.has(child.value));
|
|
84
127
|
}
|
|
85
128
|
return true;
|
|
86
129
|
});
|
|
@@ -105,19 +148,23 @@ export function normalizeTreeValue<T extends string>(nodes: TreeNode<T>[], value
|
|
|
105
148
|
/**
|
|
106
149
|
* Every node a tree field's value stands for, in pre-order (what an item filed under some
|
|
107
150
|
* node matches against): in the cascading selections the covered nodes (the value's nodes,
|
|
108
|
-
* their descendants, and every node all of whose children are
|
|
109
|
-
* `'independent'` the value's nodes themselves. Values that
|
|
110
|
-
* normalizeTreeValue.
|
|
151
|
+
* their enabled descendants, and every enabled node all of whose enabled children are
|
|
152
|
+
* covered; see `cascade`); with `'independent'` the value's nodes themselves. Values that
|
|
153
|
+
* name no node follow, as in normalizeTreeValue. A node disabled when the value was stored
|
|
154
|
+
* and enabled now is covered from then on (with `'topmost'`, a stored parent covers it).
|
|
111
155
|
*/
|
|
112
156
|
export function coveredNodes<T extends string>(nodes: TreeNode<T>[], value: T[], selection: TreeSelection = 'topmost'): T[] {
|
|
113
157
|
return normalizeTreeValue(nodes, value, selection === 'independent' ? 'independent' : 'all');
|
|
114
158
|
}
|
|
115
159
|
|
|
116
160
|
/**
|
|
117
|
-
* The value after flipping `node`, normalized
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
161
|
+
* The value after flipping `node`, normalized, as antd's Tree flips a checkbox. In the
|
|
162
|
+
* cascading selections a covered node is removed with the descendants it covers through
|
|
163
|
+
* enabled nodes and with its enabled ancestors up to the first disabled one (they no longer
|
|
164
|
+
* have all their enabled children); an uncovered one is added, covering its subtree as
|
|
165
|
+
* `cascade` says. With `'independent'` the node alone is added or removed. A `node` that is
|
|
166
|
+
* not one of the nodes changes nothing. Whether `node` itself may be flipped is the caller's
|
|
167
|
+
* to decide (useManyOfTreeField refuses a disabled one).
|
|
121
168
|
*/
|
|
122
169
|
export function toggleTreeValue<T extends string>(nodes: TreeNode<T>[], value: T[], node: T, selection: TreeSelection): T[] {
|
|
123
170
|
const { order, parent } = indexTree(nodes);
|
|
@@ -127,12 +174,16 @@ export function toggleTreeValue<T extends string>(nodes: TreeNode<T>[], value: T
|
|
|
127
174
|
return normalizeTreeValue(nodes, value.includes(node) ? value.filter((v) => v !== node) : [...value, node], selection);
|
|
128
175
|
}
|
|
129
176
|
const covered = cascade(nodes, value);
|
|
130
|
-
const subtree = indexTree([target]).order.map((n) => n.value);
|
|
131
177
|
if (covered.has(node)) {
|
|
132
|
-
|
|
133
|
-
|
|
178
|
+
const uncover = (n: TreeNode<T>) => {
|
|
179
|
+
covered.delete(n.value);
|
|
180
|
+
for (const child of n.children ?? []) if (nodeEnabled(child)) uncover(child);
|
|
181
|
+
};
|
|
182
|
+
uncover(target);
|
|
183
|
+
const byValue = new Map(order.map((n) => [n.value, n]));
|
|
184
|
+
for (let up = parent.get(node); up !== undefined && nodeEnabled(byValue.get(up)!); up = parent.get(up)) covered.delete(up);
|
|
134
185
|
} else {
|
|
135
|
-
|
|
186
|
+
covered.add(node);
|
|
136
187
|
}
|
|
137
188
|
return normalizeTreeValue(nodes, [...covered, ...unknownValues(order, value)], selection);
|
|
138
189
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './tree.js';
|
|
9
9
|
import type { ErrorRoutesRegistry, ValueOrFn } from './types.js';
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export type ManyOfTreeOwnOptions<T extends string = string, Ctx = any> = {
|
|
12
12
|
/** The roots, each with its children; static or derived (a function, of the field context if it declares a parameter). */
|
|
13
13
|
nodes: ValueOrFn<TreeNode<T>[], Ctx>;
|
|
14
14
|
/** What the value lists; default `'topmost'` (see TreeSelection). */
|
|
@@ -17,10 +17,10 @@ export type TreeOwnOptions<T extends string = string, Ctx = any> = {
|
|
|
17
17
|
expand?: TreeExpand;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type
|
|
21
|
-
FieldOptions<T[], T[], RouteId, Ctx> &
|
|
20
|
+
export type ManyOfTreeFieldOptions<T extends string = string, RouteId extends string = string, Ctx = any> =
|
|
21
|
+
FieldOptions<T[], T[], RouteId, Ctx> & ManyOfTreeOwnOptions<T, Ctx>;
|
|
22
22
|
|
|
23
|
-
export interface
|
|
23
|
+
export interface ManyOfTreeFieldControls<T extends string = string> extends FieldControls<T[], T[]> {
|
|
24
24
|
/** The roots as the widgets get them, each with its children. */
|
|
25
25
|
nodes: TreeNodeControls<T>[];
|
|
26
26
|
selection: TreeSelection;
|
|
@@ -32,8 +32,8 @@ export interface TreeFieldControls<T extends string = string> extends FieldContr
|
|
|
32
32
|
toggle(value: T): void;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** The implicit initial value for a tree field: `initialValue` resolved, else the empty list. */
|
|
36
|
-
export function
|
|
35
|
+
/** The implicit initial value for a many-of tree field: `initialValue` resolved, else the empty list. */
|
|
36
|
+
export function manyOfTreeInitialValue<T extends string>(
|
|
37
37
|
opts: { initialValue?: ValueOrFn<T[]> },
|
|
38
38
|
ctx: FieldCtx,
|
|
39
39
|
id: string,
|
|
@@ -47,24 +47,25 @@ function sameList<T>(a: T[], b: T[]): boolean {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* A field whose value is a set of tree nodes (Praeceptor's category filter), with antd
|
|
50
|
-
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
51
|
-
*
|
|
50
|
+
* TreeSelect's semantics: in the cascading selections a checked node stands for its subtree
|
|
51
|
+
* (its enabled part: disabled nodes follow antd's check conduction, so the widgets show what
|
|
52
|
+
* the value covers), and `selection` says which nodes the value lists (see TreeSelection). The value is shown
|
|
52
53
|
* and requested normalized (normalizeTreeValue): in tree pre-order, values that name no
|
|
53
54
|
* node (a stored value naming a removed node) kept at the end. `setValue` does not police
|
|
54
55
|
* disabled nodes (the widgets disable them); `toggle` refuses a disabled or unknown node with
|
|
55
56
|
* a warning, as useManyOfField does.
|
|
56
57
|
*/
|
|
57
|
-
export function
|
|
58
|
-
opts:
|
|
58
|
+
export function useManyOfTreeField<T extends string = string, RouteId extends string = string, Ctx = any>(
|
|
59
|
+
opts: ManyOfTreeFieldOptions<T, RouteId, Ctx>,
|
|
59
60
|
registry?: ErrorRoutesRegistry<RouteId>,
|
|
60
|
-
):
|
|
61
|
+
): ManyOfTreeFieldControls<T> {
|
|
61
62
|
const ctx = useFieldContext();
|
|
62
63
|
const nodes = resolveIn<TreeNode<T>[]>(opts.nodes, [], ctx, `Field '${opts.id}': option 'nodes'`);
|
|
63
64
|
const selection = opts.selection ?? 'topmost';
|
|
64
65
|
|
|
65
66
|
const inside = !opts.onChange && !opts.commit;
|
|
66
|
-
const initialValue = () =>
|
|
67
|
-
const field = useFieldCore<T[], T[], RouteId, Ctx>('
|
|
67
|
+
const initialValue = () => manyOfTreeInitialValue<T>(opts, ctx, opts.id);
|
|
68
|
+
const field = useFieldCore<T[], T[], RouteId, Ctx>('manyOfTree', inside ? { ...opts, initialValue } : opts, registry);
|
|
68
69
|
|
|
69
70
|
// The same list object while it is already normalized, so the value is stable across renders.
|
|
70
71
|
const normalized = normaliz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