vultus-core 0.5.2 → 0.5.3
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 +59 -3
- package/dist/field.d.ts +12 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +6 -1
- package/dist/field.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/kinds.d.ts +19 -14
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +40 -14
- package/dist/kinds.js.map +1 -1
- package/dist/tree.d.ts +17 -0
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +27 -0
- package/dist/tree.js.map +1 -1
- package/dist/useOneOfTreeField.d.ts +79 -0
- package/dist/useOneOfTreeField.d.ts.map +1 -0
- package/dist/useOneOfTreeField.js +117 -0
- package/dist/useOneOfTreeField.js.map +1 -0
- package/dist/useStoredField.d.ts +1 -0
- package/dist/useStoredField.d.ts.map +1 -1
- package/dist/useStoredField.js +3 -3
- package/dist/useStoredField.js.map +1 -1
- package/package.json +1 -1
- package/src/field.ts +25 -5
- package/src/index.ts +6 -1
- package/src/kinds.ts +38 -14
- package/src/tree.ts +34 -0
- package/src/useOneOfTreeField.ts +182 -0
- package/src/useStoredField.ts +6 -4
package/README.md
CHANGED
|
@@ -257,6 +257,12 @@ its descendants matches (with only the children that stay), and the rest
|
|
|
257
257
|
is trimmed, leaving the nodes given unchanged. Implicit initial value: the
|
|
258
258
|
empty list.
|
|
259
259
|
|
|
260
|
+
A `TreeNode`'s `choosable` (default `true`; a folder when `false`) is for the one-of tree, below;
|
|
261
|
+
this hook ignores it, so one node list can feed both kinds. Its helpers: `canChooseNode(node,
|
|
262
|
+
choose)` (choosable, enabled, and, under `choose: 'leaves'`, no children), `choosableValues(nodes,
|
|
263
|
+
choose)` (the values it accepts, in pre-order) and `treePath(nodes, value)` (the values from the
|
|
264
|
+
root down to `value`, inclusive; `[]` when no node has it).
|
|
265
|
+
|
|
260
266
|
```ts
|
|
261
267
|
const field = useManyOfTreeField({
|
|
262
268
|
id: 'categories',
|
|
@@ -265,6 +271,39 @@ const field = useManyOfTreeField({
|
|
|
265
271
|
field.toggle('a'); // field.value === ['a'] — 'topmost' collapses the subtree to the parent
|
|
266
272
|
```
|
|
267
273
|
|
|
274
|
+
### one-of tree (`useOneOfTreeField`)
|
|
275
|
+
|
|
276
|
+
The value is a single node id (`nodes`, the many-of tree's `TreeNode`), or `''` meaning nothing
|
|
277
|
+
chosen (Praeceptor's category picker, a table of contents). A node is choosable when its own
|
|
278
|
+
`choosable` is not `false` (a folder — a part heading with no page, a category group — is
|
|
279
|
+
`choosable: false`; the many-of tree ignores it, so one node list can feed both kinds), it is
|
|
280
|
+
enabled, and, under `choose: 'leaves'` (default `'any'`), has no children (`canChooseNode`,
|
|
281
|
+
`choosableValues`, `treePath` — see many-of tree, above). `setValue` refuses, with a warning (as
|
|
282
|
+
`useOneOfField` refuses a disabled choice): a value naming no node, a node that cannot be
|
|
283
|
+
chosen, and `''` unless `optional` (default `false`, as `oneOf`'s value is never empty); `clear()`
|
|
284
|
+
requests `''`. Controls add `nodes` (each with `choosable`, `current` — it is the value — and
|
|
285
|
+
`onPath` — an ancestor of it) and `byValue`, as the many-of tree's; `current` (the chosen node, or
|
|
286
|
+
undefined when the value is empty or names no node), `path` (the nodes from the root down to
|
|
287
|
+
`current`, inclusive; empty when there is none), `previous` / `next` (the choosable nodes just
|
|
288
|
+
before and after `current`'s own position in tree pre-order — so a `current` that cannot itself
|
|
289
|
+
be chosen, e.g. a value naming a folder or a node a context change disabled, still gets its true
|
|
290
|
+
neighbours; undefined at the ends, and with no `current`, `previous` undefined and `next` the
|
|
291
|
+
first choosable node), `optional`, `choose` and `expandedKeys`
|
|
292
|
+
(from `expand`, default `'selected'` — the value's ancestors, so a table of contents opens where
|
|
293
|
+
the reader is; `'top'`, `'none'` and `'all'` as the many-of tree's). The field's current state is
|
|
294
|
+
the chosen node's description, unless `valueDescriptions` words it differently (as `oneOf`).
|
|
295
|
+
Implicit initial value: `initialValue`, else `''` when `optional`, else the first node that can be
|
|
296
|
+
chosen in tree pre-order, else `''` (no node can be chosen; as `oneOf`'s undefined choice).
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
const field = useOneOfTreeField({
|
|
300
|
+
id: 'category',
|
|
301
|
+
nodes: [{ value: 'geo', choosable: false, children: [{ value: 'sik' }, { value: 'ter' }] }],
|
|
302
|
+
});
|
|
303
|
+
field.value; // 'sik' — the first node that can be chosen ('geo' is a folder)
|
|
304
|
+
field.next?.value; // 'ter'
|
|
305
|
+
```
|
|
306
|
+
|
|
268
307
|
### text (`useTextField`)
|
|
269
308
|
|
|
270
309
|
The value is a string. `control: 'input' | 'textarea'` (default `'input'`)
|
|
@@ -285,7 +324,7 @@ const field = useTextField({ id: 'search', control: 'input' });
|
|
|
285
324
|
A `FieldDefinition` is a field's options in their "inside" form (no `value`
|
|
286
325
|
plus `onChange` or `commit`), tagged with a required `kind` — one of
|
|
287
326
|
`'boolean'`, `'mixed-boolean'`, `'oneOf'`, `'manyOf'`, `'numeric'`,
|
|
288
|
-
`'range'`, `'manyOfTree'`, `'text'` (the same strings `FieldControls.type` already
|
|
327
|
+
`'range'`, `'manyOfTree'`, `'oneOfTree'`, `'text'` (the same strings `FieldControls.type` already
|
|
289
328
|
carries). `kind` stays optional on each hook's own options — a hook knows
|
|
290
329
|
its own kind, and throws if a definition names a different one — but is
|
|
291
330
|
required once a field becomes plain data: a module declares its filters as a
|
|
@@ -333,7 +372,7 @@ b)`) say how a value is kept as a string and compared; equality is the
|
|
|
333
372
|
type's own meaning (a list as a set, a range by both ends), used everywhere
|
|
334
373
|
two values of that type are compared — including whether a value is the
|
|
335
374
|
default, so it's left out of the store. `valueTypeOf(kind)` gives each field
|
|
336
|
-
kind's: `booleanType` (`'1'` / `'0'`), `stringType` (one-of, text),
|
|
375
|
+
kind's: `booleanType` (`'1'` / `'0'`), `stringType` (one-of, one-of tree, text),
|
|
337
376
|
`stringSetType` (many-of, many-of tree — a sorted comma list; a *present but empty*
|
|
338
377
|
value reads as the empty list, which differs from the key being absent
|
|
339
378
|
altogether), `numberType`, `rangeType` (`from..to`). A mixed-boolean field
|
|
@@ -381,7 +420,9 @@ is the definition's `id`, its value type comes from the kind, its default
|
|
|
381
420
|
is `initialValueOf`. It returns `{ options, isDefault, reset }` — `options`
|
|
382
421
|
is the definition in its outside form (`value` plus `onChange`, ready for
|
|
383
422
|
the kind's hook), with the stored raw value made to fit the definition as
|
|
384
|
-
it is now (`sanitizeStored`: unknown choices or nodes dropped
|
|
423
|
+
it is now (`sanitizeStored`: unknown choices or nodes dropped; a one-of
|
|
424
|
+
tree value naming no node, a folder or a node it cannot choose, or `''`
|
|
425
|
+
when the field is not optional, replaced by the initial value; numbers and
|
|
385
426
|
ranges clamped, and rounded when `integer`). A value that needed fixing up
|
|
386
427
|
warns once per field and per raw value — not again on every render, and not
|
|
387
428
|
at all when the key is simply absent (then the default applies, and an
|
|
@@ -392,6 +433,21 @@ definitions), `changedCount`, and `resetAll(method)` (one write for every
|
|
|
392
433
|
field). Being a summary, it never warns — only `useStoredField` on the
|
|
393
434
|
field itself does.
|
|
394
435
|
|
|
436
|
+
**Links.** Every kind's hook gives its controls `hrefFor(value)`: the link that requesting `value`
|
|
437
|
+
amounts to, or `undefined` where nothing gives one. With `value` + `onChange` or `value` +
|
|
438
|
+
`commit`, the caller passes it; inside the field it is always `undefined` (an `hrefFor` passed
|
|
439
|
+
anyway is ignored). `FieldControls` has it optional (`hrefFor?(value)`), so controls built by
|
|
440
|
+
hand need none; a widget calls `field.hrefFor?.(value)`. `useStoredField` wires its own from the
|
|
441
|
+
store (`useArg`'s `hrefFor`, itself from the store's), so a field stored over a URL store
|
|
442
|
+
(vultus-react-router's) links each value it could be set to, e.g.
|
|
443
|
+
`field.hrefFor?.(field.choices[0].value)` next to the field's own widget. A link built from
|
|
444
|
+
`hrefFor` is as fresh as the render that built it: a URL that changes without re-rendering its
|
|
445
|
+
component (another key of the query, the path) leaves it stale. Render an app's own links (a
|
|
446
|
+
previous / next pair) in a component that re-renders on location changes (with react-router,
|
|
447
|
+
one that calls `useLocation`), or compute them at interaction time (vultus-antd's
|
|
448
|
+
`OneOfTreeList` asks again as the pointer enters a link, on its focus, a button press, its
|
|
449
|
+
context menu, a modified click).
|
|
450
|
+
|
|
395
451
|
```tsx
|
|
396
452
|
const store = memoryStore();
|
|
397
453
|
|
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' | 'manyOfTree' | 'text';
|
|
12
|
+
export type FieldKind = 'boolean' | 'mixed-boolean' | 'oneOf' | 'manyOf' | 'numeric' | 'range' | 'manyOfTree' | 'oneOfTree' | '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;
|
|
@@ -67,6 +67,7 @@ export type FieldStorage<TValue, TRequest = TValue, RouteId extends string = str
|
|
|
67
67
|
value?: never;
|
|
68
68
|
onChange?: never;
|
|
69
69
|
commit?: never;
|
|
70
|
+
hrefFor?: never;
|
|
70
71
|
}
|
|
71
72
|
/** Outside, changed locally: the caller owns the value and applies `onChange`. */
|
|
72
73
|
| {
|
|
@@ -74,6 +75,8 @@ export type FieldStorage<TValue, TRequest = TValue, RouteId extends string = str
|
|
|
74
75
|
onChange: (value: TRequest) => void;
|
|
75
76
|
initialValue?: never;
|
|
76
77
|
commit?: never;
|
|
78
|
+
/** The link that requesting `value` amounts to, where the caller has one (e.g. a URL store). */
|
|
79
|
+
hrefFor?: (value: TRequest) => string | undefined;
|
|
77
80
|
}
|
|
78
81
|
/** Outside, committed immediately: `commit.fire` stores the change (pending, messages, confirmation). */
|
|
79
82
|
| {
|
|
@@ -81,6 +84,7 @@ export type FieldStorage<TValue, TRequest = TValue, RouteId extends string = str
|
|
|
81
84
|
commit: FieldCommit<TRequest, RouteId>;
|
|
82
85
|
initialValue?: never;
|
|
83
86
|
onChange?: never;
|
|
87
|
+
hrefFor?: (value: TRequest) => string | undefined;
|
|
84
88
|
};
|
|
85
89
|
export type FieldOptions<TValue, TRequest = TValue, RouteId extends string = string, Ctx = any> = FieldBaseOptions<TValue, Ctx> & FieldStorage<TValue, TRequest, RouteId, Ctx>;
|
|
86
90
|
/** What a field widget receives: everything it shows, and the one way to change the value. */
|
|
@@ -106,6 +110,13 @@ export interface FieldControls<TValue, TRequest = TValue> {
|
|
|
106
110
|
messages: Message[];
|
|
107
111
|
/** The confirmation a widget must obtain before requesting `next`, if any. */
|
|
108
112
|
confirmationFor(next: TRequest): ConfirmationSpec | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The link that requesting `value` amounts to, where whoever keeps the value gave one (a URL
|
|
115
|
+
* store does); `undefined` otherwise, and always inside the field. Every kind's hook provides
|
|
116
|
+
* it; optional here so that controls built by hand (as before vultus-core 0.5.3) need none, so
|
|
117
|
+
* a widget calls it as `field.hrefFor?.(value)`.
|
|
118
|
+
*/
|
|
119
|
+
hrefFor?(value: TRequest): string | undefined;
|
|
109
120
|
widget: WidgetHint | undefined;
|
|
110
121
|
}
|
|
111
122
|
export type FieldStorageMode = 'inside' | 'local' | 'commit';
|
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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ClD,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAmFjC"}
|
package/dist/field.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import { getReason, getVerdict, invertDecision } from './decision.js';
|
|
3
3
|
import { useFieldContext } from './FieldContext.js';
|
|
4
4
|
import { resolveIn } from './resolve.js';
|
|
@@ -86,6 +86,10 @@ export function useFieldCore(type, opts, registry) {
|
|
|
86
86
|
const spec = opts.commit?.confirmation;
|
|
87
87
|
return typeof spec === 'function' ? spec(next) : spec;
|
|
88
88
|
};
|
|
89
|
+
// Inside the field nothing outside keeps the value, so nothing gives a link: an `hrefFor` that
|
|
90
|
+
// came anyway (untyped options; the types forbid it) is ignored.
|
|
91
|
+
const hrefForOpt = mode === 'inside' ? undefined : opts.hrefFor;
|
|
92
|
+
const hrefFor = useCallback((next) => hrefForOpt?.(next), [hrefForOpt]);
|
|
89
93
|
return {
|
|
90
94
|
type,
|
|
91
95
|
id: opts.id,
|
|
@@ -102,6 +106,7 @@ export function useFieldCore(type, opts, registry) {
|
|
|
102
106
|
commits: mode === 'commit',
|
|
103
107
|
messages: mode === 'commit' ? (setter.messages ?? []) : [],
|
|
104
108
|
confirmationFor,
|
|
109
|
+
hrefFor,
|
|
105
110
|
widget: opts.widget,
|
|
106
111
|
};
|
|
107
112
|
}
|
package/dist/field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,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,UAAU,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,IAA8D,CAAC,OAAO,CAAC;IAC3H,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,IAAc,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAElF,OAAO;QACL,IAAI;QACJ,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK;QACL,WAAW;QACX,WAAW;QACX,gBAAgB;QAChB,OAAO;QACP,OAAO;QACP,WAAW;QACX,KAAK;QACL,QAAQ;QACR,OAAO;QACP,OAAO,EAAE,IAAI,KAAK,QAAQ;QAC1B,QAAQ,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;QAC1D,eAAe;QACf,OAAO;QACP,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ export { useManyOfField, manyOfInitialValue, type ManyOfFieldControls, type Many
|
|
|
17
17
|
export { clamp, resolveNumeric, type NumericBounds, type ResolvedNumeric } from './numeric.js';
|
|
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
|
-
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, type TreeNode, type TreeNodeControls, type TreeSelection, type TreeExpand, } from './tree.js';
|
|
20
|
+
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, canChooseNode, choosableValues, treePath, type TreeNode, type TreeNodeControls, type TreeSelection, type TreeExpand, type TreeChoose, } from './tree.js';
|
|
21
21
|
export { useManyOfTreeField, manyOfTreeInitialValue, type ManyOfTreeFieldControls, type ManyOfTreeFieldOptions, type ManyOfTreeOwnOptions, } from './useManyOfTreeField.js';
|
|
22
|
+
export { useOneOfTreeField, oneOfTreeInitialValue, type OneOfTreeFieldControls, type OneOfTreeFieldOptions, type OneOfTreeOwnOptions, type OneOfTreeNodeControls, } from './useOneOfTreeField.js';
|
|
22
23
|
export { useTextField, textInitialValue, type TextFieldControls, type TextFieldOptions, type TextOwnOptions, } from './useTextField.js';
|
|
23
24
|
export { booleanType, stringType, stringSetType, numberType, rangeType, type ValueType, } from './valueTypes.js';
|
|
24
25
|
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,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAC3F,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,GACjH,MAAM,YAAY,CAAC;AACpB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,oBAAoB,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,KAAK,QAAQ,GAC3F,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EAAE,gBAAg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AgB,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,GAChE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,9 @@ export { useManyOfField, manyOfInitialValue, } from './useManyOfField.js';
|
|
|
16
16
|
export { clamp, resolveNumeric } from './numeric.js';
|
|
17
17
|
export { useNumericField, numericInitialValue, } from './useNumericField.js';
|
|
18
18
|
export { useRangeField, rangeInitialValue, } from './useRangeField.js';
|
|
19
|
-
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, } from './tree.js';
|
|
19
|
+
export { normalizeTreeValue, coveredNodes, toggleTreeValue, expandedTreeKeys, filterTree, canChooseNode, choosableValues, treePath, } from './tree.js';
|
|
20
20
|
export { useManyOfTreeField, manyOfTreeInitialValue, } from './useManyOfTreeField.js';
|
|
21
|
+
export { useOneOfTreeField, oneOfTreeInitialValue, } from './useOneOfTreeField.js';
|
|
21
22
|
export { useTextField, textInitialValue, } from './useTextField.js';
|
|
22
23
|
export { booleanType, stringType, stringSetType, numberType, rangeType, } from './valueTypes.js';
|
|
23
24
|
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,wBAAwB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,oBAAoB,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,GAC5E,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YA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AE,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
|
@@ -5,6 +5,7 @@ import { type ManyOfOwnOptions } from './useManyOfField.js';
|
|
|
5
5
|
import { type MixedBool } from './useMixedBoolField.js';
|
|
6
6
|
import { type NumericOwnOptions } from './useNumericField.js';
|
|
7
7
|
import { type OneOfOwnOptions } from './useOneOfField.js';
|
|
8
|
+
import { type OneOfTreeOwnOptions } from './useOneOfTreeField.js';
|
|
8
9
|
import { type NumberRange, type RangeOwnOptions } from './useRangeField.js';
|
|
9
10
|
import { type TextOwnOptions } from './useTextField.js';
|
|
10
11
|
import { type ManyOfTreeOwnOptions } from './useManyOfTreeField.js';
|
|
@@ -24,14 +25,15 @@ type Definition<K extends FieldKind, V, Own, Ctx> = {
|
|
|
24
25
|
* by `kind`, a definition is its kind's hook options as they are: `useOneOfField(definition)`.
|
|
25
26
|
* Its functions receive the field context `Ctx` (see FieldContextProvider).
|
|
26
27
|
*/
|
|
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
|
+
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<'oneOfTree', string, OneOfTreeOwnOptions<string, Ctx>, Ctx> | Definition<'text', string, TextOwnOptions, Ctx>;
|
|
28
29
|
/**
|
|
29
30
|
* A definition's default: `initialValue` resolved with the field context, else its kind's
|
|
30
31
|
* implicit initial value (false; the first enabled choice; the empty list; `min`, or 0, clamped
|
|
31
|
-
* into the bounds; `[min, max]`; the empty string). A tree's comes normalized under its
|
|
32
|
+
* into the bounds; `[min, max]`; the empty string). A many-of tree's comes normalized under its
|
|
32
33
|
* selection, as the hook shows it, so a value equal to what the field shows by default is equal
|
|
33
|
-
* to the default too
|
|
34
|
-
*
|
|
34
|
+
* to the default too; a one-of tree's is `''` when `optional`, else the first node it can choose
|
|
35
|
+
* in pre-order, else `''` (none can be chosen). It is what a store falls back to, what a reset
|
|
36
|
+
* restores, and what "is it set?" compares against; the kind's hook starts at the same value.
|
|
35
37
|
*/
|
|
36
38
|
export declare function initialValueOf(definition: FieldDefinition, ctx: FieldCtx): unknown;
|
|
37
39
|
/** How a kind's value is kept in a store. A mixed-boolean field shows an aggregate of other data, so it has none and throws. */
|
|
@@ -39,16 +41,19 @@ export declare function valueTypeOf(kind: FieldKind): ValueType<any>;
|
|
|
39
41
|
/**
|
|
40
42
|
* A stored value (already parsed by the kind's value type) made fit for the definition as it is
|
|
41
43
|
* now: choices, nodes and bounds follow the data, and an old URL may not. A one-of value that is
|
|
42
|
-
* not a choice becomes the initial value; many-of
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
44
|
+
* not a choice becomes the initial value; many-of values that are not choices or nodes are
|
|
45
|
+
* dropped. A one-of tree value is replaced by the initial value too, when it names no node, when
|
|
46
|
+
* the node it names cannot be chosen (a folder, or one a context change disabled), or when it is
|
|
47
|
+
* `''` and the field is not optional. Numbers and ranges are clamped into the bounds, then
|
|
48
|
+
* rounded when the field is `integer` (so a stored `2.5` reads `3`; a whole number inside the
|
|
49
|
+
* bounds, see `fit`), with one warning for whichever of the two actually changed the value:
|
|
50
|
+
* "outside its bounds" when clamping did (whether or not rounding also did), "not a whole
|
|
51
|
+
* number" ("has ends that are not whole numbers" for a range) when only rounding did. Each such
|
|
52
|
+
* change warns, naming the field: the value came from outside, so it is not an error. Reordering
|
|
53
|
+
* is silent: lists come back in choice order or normalized under the tree's selection (a store
|
|
54
|
+
* keeps them sorted, so a warning would come on every read), and a range's ends in order. The
|
|
55
|
+
* warnings go to `warn`, console.warn unless a caller that only summarizes (useStoredFields)
|
|
56
|
+
* silences them.
|
|
52
57
|
*/
|
|
53
58
|
export declare function sanitizeStored(definition: FieldDefinition, value: unknown, ctx: FieldCtx, warn?: (message: string) => void): unknown;
|
|
54
59
|
export {};
|
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,MAA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QD;;;;;;;;;;;;;;;;GAgBG;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,CAwET"}
|
package/dist/kinds.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { resolveChoice } from './choices.js';
|
|
2
2
|
import { clamp, fit, resolveNumeric } from './numeric.js';
|
|
3
3
|
import { resolveIn } from './resolve.js';
|
|
4
|
-
import { normalizeTreeValue } from './tree.js';
|
|
4
|
+
import { choosableValues, normalizeTreeValue } from './tree.js';
|
|
5
5
|
import { boolInitialValue } from './useBoolField.js';
|
|
6
6
|
import { manyOfInitialValue } from './useManyOfField.js';
|
|
7
7
|
import { mixedBoolInitialValue } from './useMixedBoolField.js';
|
|
8
8
|
import { numericInitialValue } from './useNumericField.js';
|
|
9
9
|
import { oneOfInitialValue } from './useOneOfField.js';
|
|
10
|
+
import { oneOfTreeInitialValue } from './useOneOfTreeField.js';
|
|
10
11
|
import { rangeInitialValue } from './useRangeField.js';
|
|
11
12
|
import { textInitialValue } from './useTextField.js';
|
|
12
13
|
import { manyOfTreeInitialValue } from './useManyOfTreeField.js';
|
|
@@ -38,10 +39,11 @@ function nodesOf(definition, ctx) {
|
|
|
38
39
|
/**
|
|
39
40
|
* A definition's default: `initialValue` resolved with the field context, else its kind's
|
|
40
41
|
* implicit initial value (false; the first enabled choice; the empty list; `min`, or 0, clamped
|
|
41
|
-
* into the bounds; `[min, max]`; the empty string). A tree's comes normalized under its
|
|
42
|
+
* into the bounds; `[min, max]`; the empty string). A many-of tree's comes normalized under its
|
|
42
43
|
* selection, as the hook shows it, so a value equal to what the field shows by default is equal
|
|
43
|
-
* to the default too
|
|
44
|
-
*
|
|
44
|
+
* to the default too; a one-of tree's is `''` when `optional`, else the first node it can choose
|
|
45
|
+
* in pre-order, else `''` (none can be chosen). It is what a store falls back to, what a reset
|
|
46
|
+
* restores, and what "is it set?" compares against; the kind's hook starts at the same value.
|
|
45
47
|
*/
|
|
46
48
|
export function initialValueOf(definition, ctx) {
|
|
47
49
|
const { id } = definition;
|
|
@@ -54,6 +56,7 @@ export function initialValueOf(definition, ctx) {
|
|
|
54
56
|
case 'range': return rangeInitialValue(definition, ctx, id);
|
|
55
57
|
case 'manyOfTree':
|
|
56
58
|
return normalizeTreeValue(nodesOf(definition, ctx), manyOfTreeInitialValue(definition, ctx, id), definition.selection ?? 'topmost');
|
|
59
|
+
case 'oneOfTree': return oneOfTreeInitialValue(definition, ctx, id, nodesOf(definition, ctx));
|
|
57
60
|
case 'text': return textInitialValue(definition, ctx, id);
|
|
58
61
|
default: return unknownKind(definition);
|
|
59
62
|
}
|
|
@@ -63,6 +66,7 @@ export function valueTypeOf(kind) {
|
|
|
63
66
|
switch (kind) {
|
|
64
67
|
case 'boolean': return booleanType;
|
|
65
68
|
case 'oneOf':
|
|
69
|
+
case 'oneOfTree':
|
|
66
70
|
case 'text': return stringType;
|
|
67
71
|
case 'manyOf':
|
|
68
72
|
case 'manyOfTree': return stringSetType;
|
|
@@ -81,16 +85,19 @@ function warnDropped(id, among, dropped, warn) {
|
|
|
81
85
|
/**
|
|
82
86
|
* A stored value (already parsed by the kind's value type) made fit for the definition as it is
|
|
83
87
|
* now: choices, nodes and bounds follow the data, and an old URL may not. A one-of value that is
|
|
84
|
-
* not a choice becomes the initial value; many-of
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
88
|
+
* not a choice becomes the initial value; many-of values that are not choices or nodes are
|
|
89
|
+
* dropped. A one-of tree value is replaced by the initial value too, when it names no node, when
|
|
90
|
+
* the node it names cannot be chosen (a folder, or one a context change disabled), or when it is
|
|
91
|
+
* `''` and the field is not optional. Numbers and ranges are clamped into the bounds, then
|
|
92
|
+
* rounded when the field is `integer` (so a stored `2.5` reads `3`; a whole number inside the
|
|
93
|
+
* bounds, see `fit`), with one warning for whichever of the two actually changed the value:
|
|
94
|
+
* "outside its bounds" when clamping did (whether or not rounding also did), "not a whole
|
|
95
|
+
* number" ("has ends that are not whole numbers" for a range) when only rounding did. Each such
|
|
96
|
+
* change warns, naming the field: the value came from outside, so it is not an error. Reordering
|
|
97
|
+
* is silent: lists come back in choice order or normalized under the tree's selection (a store
|
|
98
|
+
* keeps them sorted, so a warning would come on every read), and a range's ends in order. The
|
|
99
|
+
* warnings go to `warn`, console.warn unless a caller that only summarizes (useStoredFields)
|
|
100
|
+
* silences them.
|
|
94
101
|
*/
|
|
95
102
|
export function sanitizeStored(definition, value, ctx, warn = (message) => console.warn(message)) {
|
|
96
103
|
const { id } = definition;
|
|
@@ -122,6 +129,25 @@ export function sanitizeStored(definition, value, ctx, warn = (message) => conso
|
|
|
122
129
|
warnDropped(id, 'nodes', stored.filter((v) => !known.has(v)), warn);
|
|
123
130
|
return normalizeTreeValue(nodes, stored.filter((v) => known.has(v)), definition.selection ?? 'topmost');
|
|
124
131
|
}
|
|
132
|
+
case 'oneOfTree': {
|
|
133
|
+
const stored = value;
|
|
134
|
+
const nodes = nodesOf(definition, ctx);
|
|
135
|
+
if (stored === '') {
|
|
136
|
+
if (definition.optional ?? false)
|
|
137
|
+
return stored;
|
|
138
|
+
const fallback = oneOfTreeInitialValue(definition, ctx, id, nodes);
|
|
139
|
+
if (fallback !== stored)
|
|
140
|
+
warn(`Field '${id}': stored value '' is empty but the field is not optional, using '${fallback}'`);
|
|
141
|
+
return fallback;
|
|
142
|
+
}
|
|
143
|
+
if (choosableValues(nodes, definition.choose ?? 'any').includes(stored))
|
|
144
|
+
return stored;
|
|
145
|
+
const fallback = oneOfTreeInitialValue(definition, ctx, id, nodes);
|
|
146
|
+
const reason = nodeValues(nodes).has(stored) ? 'cannot be chosen' : 'names no node';
|
|
147
|
+
if (fallback !== stored)
|
|
148
|
+
warn(`Field '${id}': stored value '${stored}' ${reason}, using '${fallback}'`);
|
|
149
|
+
return fallback;
|
|
150
|
+
}
|
|
125
151
|
case 'numeric': {
|
|
126
152
|
const stored = value;
|
|
127
153
|
const { min, max, integer } = resolveNumeric(id, definition, ctx);
|
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;
|
|
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,eAAe,EAAE,kBAAkB,EAAiB,MAAM,WAAW,CAAC;AAE/E,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,qBAAqB,EAAoD,MAAM,wBAAwB,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAA8D,MAAM,oBAAoB,CAAC;AACnH,OAAO,EAA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CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5G,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,SAAS,GAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;YACxE,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3C,IAAI,cAAc,EAAE,CAAC;oBACnB,IAAI,CAAC,UAAU,EAAE,mBAAmB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,iCAAiC,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/tree.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { OneOfChoice, OneOfChoiceControls } from './choices.js';
|
|
|
2
2
|
/** A node of a tree field (Praeceptor's categories): a choice with children. */
|
|
3
3
|
export interface TreeNode<T extends string = string> extends OneOfChoice<T> {
|
|
4
4
|
children?: TreeNode<T>[];
|
|
5
|
+
/** Whether the one-of tree may choose this node (default true); a folder when false. Ignored by the many-of tree. */
|
|
6
|
+
choosable?: boolean;
|
|
5
7
|
}
|
|
6
8
|
/** A node as the widgets get it: the resolved choice, its children likewise, and whether it shows checked. */
|
|
7
9
|
export interface TreeNodeControls<T extends string = string> extends OneOfChoiceControls<T> {
|
|
@@ -78,4 +80,19 @@ export declare function filterTree<N extends {
|
|
|
78
80
|
value: string;
|
|
79
81
|
children?: N[];
|
|
80
82
|
}>(nodes: N[], query: string): N[];
|
|
83
|
+
/**
|
|
84
|
+
* Which nodes the one-of tree field may choose: `'any'` node, or only `'leaves'` (a node with
|
|
85
|
+
* no children).
|
|
86
|
+
*/
|
|
87
|
+
export type TreeChoose = 'any' | 'leaves';
|
|
88
|
+
/**
|
|
89
|
+
* Whether the one-of tree field may choose `node` under `choose` (see TreeChoose): choosable
|
|
90
|
+
* (its `choosable` is not `false`), enabled (as nodeEnabled resolves it), and, under `'leaves'`,
|
|
91
|
+
* has no children.
|
|
92
|
+
*/
|
|
93
|
+
export declare function canChooseNode(node: TreeNode, choose: TreeChoose): boolean;
|
|
94
|
+
/** The values canChooseNode accepts, in tree pre-order. */
|
|
95
|
+
export declare function choosableValues<T extends string>(nodes: TreeNode<T>[], choose: TreeChoose): T[];
|
|
96
|
+
/** The values from the root down to `value` inclusive, in tree order; `[]` when no node has it. */
|
|
97
|
+
export declare function treePath<T extends string>(nodes: TreeNode<T>[], value: T): T[];
|
|
81
98
|
//# sourceMappingURL=tree.d.ts.map
|
package/dist/tree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAIrE,gFAAgF;AAChF,MAAM,WAAW,QAAQ,CAAC,CAAC,S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AE,CAM9E"}
|
package/dist/tree.js
CHANGED
|
@@ -191,4 +191,31 @@ export function filterTree(nodes, query) {
|
|
|
191
191
|
});
|
|
192
192
|
return keep(nodes, false);
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Whether the one-of tree field may choose `node` under `choose` (see TreeChoose): choosable
|
|
196
|
+
* (its `choosable` is not `false`), enabled (as nodeEnabled resolves it), and, under `'leaves'`,
|
|
197
|
+
* has no children.
|
|
198
|
+
*/
|
|
199
|
+
export function canChooseNode(node, choose) {
|
|
200
|
+
if (node.choosable === false)
|
|
201
|
+
return false;
|
|
202
|
+
if (!nodeEnabled(node))
|
|
203
|
+
return false;
|
|
204
|
+
return choose !== 'leaves' || !hasChildren(node);
|
|
205
|
+
}
|
|
206
|
+
/** The values canChooseNode accepts, in tree pre-order. */
|
|
207
|
+
export function choosableValues(nodes, choose) {
|
|
208
|
+
const { order } = indexTree(nodes);
|
|
209
|
+
return order.filter((node) => canChooseNode(node, choose)).map((node) => node.value);
|
|
210
|
+
}
|
|
211
|
+
/** The values from the root down to `value` inclusive, in tree order; `[]` when no node has it. */
|
|
212
|
+
export function treePath(nodes, value) {
|
|
213
|
+
const { order, parent } = indexTree(nodes);
|
|
214
|
+
if (!order.some((node) => node.value === value))
|
|
215
|
+
return [];
|
|
216
|
+
const path = [value];
|
|
217
|
+
for (let up = parent.get(value); up !== undefined; up = parent.get(up))
|
|
218
|
+
path.unshift(up);
|
|
219
|
+
return path;
|
|
220
|
+
}
|
|
194
221
|
//# sourceMappingURL=tree.js.map
|