vultus-core 0.5.1 → 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.
Files changed (44) hide show
  1. package/README.md +96 -10
  2. package/dist/field.d.ts +12 -1
  3. package/dist/field.d.ts.map +1 -1
  4. package/dist/field.js +6 -1
  5. package/dist/field.js.map +1 -1
  6. package/dist/index.d.ts +3 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/kinds.d.ts +20 -15
  11. package/dist/kinds.d.ts.map +1 -1
  12. package/dist/kinds.js +46 -20
  13. package/dist/kinds.js.map +1 -1
  14. package/dist/parseApiError.d.ts +6 -0
  15. package/dist/parseApiError.d.ts.map +1 -1
  16. package/dist/parseApiError.js +7 -1
  17. package/dist/parseApiError.js.map +1 -1
  18. package/dist/tree.d.ts +38 -9
  19. package/dist/tree.d.ts.map +1 -1
  20. package/dist/tree.js +91 -21
  21. package/dist/tree.js.map +1 -1
  22. package/dist/{useTreeField.d.ts → useManyOfTreeField.d.ts} +10 -9
  23. package/dist/useManyOfTreeField.d.ts.map +1 -0
  24. package/dist/{useTreeField.js → useManyOfTreeField.js} +9 -8
  25. package/dist/useManyOfTreeField.js.map +1 -0
  26. package/dist/useOneOfTreeField.d.ts +79 -0
  27. package/dist/useOneOfTreeField.d.ts.map +1 -0
  28. package/dist/useOneOfTreeField.js +117 -0
  29. package/dist/useOneOfTreeField.js.map +1 -0
  30. package/dist/useStoredField.d.ts +1 -0
  31. package/dist/useStoredField.d.ts.map +1 -1
  32. package/dist/useStoredField.js +3 -3
  33. package/dist/useStoredField.js.map +1 -1
  34. package/package.json +3 -2
  35. package/src/field.ts +25 -5
  36. package/src/index.ts +9 -4
  37. package/src/kinds.ts +46 -22
  38. package/src/parseApiError.ts +7 -1
  39. package/src/tree.ts +105 -20
  40. package/src/{useTreeField.ts → useManyOfTreeField.ts} +14 -13
  41. package/src/useOneOfTreeField.ts +182 -0
  42. package/src/useStoredField.ts +6 -4
  43. package/dist/useTreeField.d.ts.map +0 -1
  44. package/dist/useTreeField.js.map +0 -1
@@ -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"}
@@ -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;KACzB,CAAC;AACJ,CAAC"}
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
@@ -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> {
@@ -12,12 +14,20 @@ export interface TreeNodeControls<T extends string = string> extends OneOfChoice
12
14
  /**
13
15
  * What a tree field's value lists, as antd TreeSelect's `showCheckedStrategy` and
14
16
  * `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; they differ only in which of the
16
- * covered nodes the value names:
17
+ * a node all of whose children are covered is covered too — disabled nodes aside, as antd
18
+ * conducts its checks (see `cascade`); they differ only in which of the covered nodes the
19
+ * value names:
17
20
  * - `'topmost'` (`SHOW_PARENT`, the default): the covered nodes whose parent is not covered;
18
21
  * - `'all'` (`SHOW_ALL`): every covered node;
19
22
  * - `'leaves'` (`SHOW_CHILD`): the covered leaves.
20
23
  *
24
+ * Where a disabled node breaks the cascade, the value also names what the others would not
25
+ * cover: `'topmost'` a covered disabled node under a covered parent, and a covered node under
26
+ * a covered disabled parent (as antd TreeSelect's SHOW_PARENT does); `'leaves'` a covered node
27
+ * with children that is disabled or has no enabled child (stricter than antd's SHOW_CHILD,
28
+ * which drops a checked disabled parent whose enabled children are all checked, and a parent
29
+ * whose only children are disabled and checked — so the value would no longer cover them).
30
+ *
21
31
  * `'independent'` (`checkStrictly`, moxb's `strictSelect`): each node is chosen on its own.
22
32
  */
23
33
  export type TreeSelection = 'topmost' | 'all' | 'leaves' | 'independent';
@@ -37,16 +47,20 @@ export declare function normalizeTreeValue<T extends string>(nodes: TreeNode<T>[
37
47
  /**
38
48
  * Every node a tree field's value stands for, in pre-order (what an item filed under some
39
49
  * 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 covered); with
41
- * `'independent'` the value's nodes themselves. Values that name no node follow, as in
42
- * normalizeTreeValue.
50
+ * their enabled descendants, and every enabled node all of whose enabled children are
51
+ * covered; see `cascade`); with `'independent'` the value's nodes themselves. Values that
52
+ * name no node follow, as in normalizeTreeValue. A node disabled when the value was stored
53
+ * and enabled now is covered from then on (with `'topmost'`, a stored parent covers it).
43
54
  */
44
55
  export declare function coveredNodes<T extends string>(nodes: TreeNode<T>[], value: T[], selection?: TreeSelection): T[];
45
56
  /**
46
- * The value after flipping `node`, normalized. In the cascading selections a covered node
47
- * is removed with its descendants and its ancestors (they no longer have all their
48
- * children), and an uncovered one is added with its descendants; with `'independent'` the
49
- * node alone is added or removed. A `node` that is not one of the nodes changes nothing.
57
+ * The value after flipping `node`, normalized, as antd's Tree flips a checkbox. In the
58
+ * cascading selections a covered node is removed with the descendants it covers through
59
+ * enabled nodes and with its enabled ancestors up to the first disabled one (they no longer
60
+ * have all their enabled children); an uncovered one is added, covering its subtree as
61
+ * `cascade` says. With `'independent'` the node alone is added or removed. A `node` that is
62
+ * not one of the nodes changes nothing. Whether `node` itself may be flipped is the caller's
63
+ * to decide (useManyOfTreeField refuses a disabled one).
50
64
  */
51
65
  export declare function toggleTreeValue<T extends string>(nodes: TreeNode<T>[], value: T[], node: T, selection: TreeSelection): T[];
52
66
  /** The nodes a tree widget opens at first under `expand` (see TreeExpand), in pre-order. */
@@ -66,4 +80,19 @@ export declare function filterTree<N extends {
66
80
  value: string;
67
81
  children?: N[];
68
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[];
69
98
  //# sourceMappingURL=tree.d.ts.map
@@ -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;AAGrE,gFAAgF;AAChF,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACzE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1B;AAED,8GAA8G;AAC9G,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACzF,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;IAC5C,6FAA6F;IAC7F,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AAwD7D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,aAAa,GAAG,CAAC,EAAE,CAOpH;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE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AC,EAAE,CAAC,EAAE,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAYtH;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAIzE;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,CAG/F;AAED,mGAAmG;AACnG,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAM9E"}
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
- /** The nodes a value covers in the cascading selections: the value's nodes, their descendants, and every node all of whose children are covered. */
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 self = inherited || listed.has(node.value);
32
- const children = (node.children ?? []).map((child) => walk(child, self));
33
- const isCovered = self || (children.length > 0 && children.every(Boolean));
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
- /** The covered nodes the value names under `selection` (see TreeSelection), in pre-order. */
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 covered); with
75
- * `'independent'` the value's nodes themselves. Values that name no node follow, as in
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. In the cascading selections a covered node
83
- * is removed with its descendants and its ancestors (they no longer have all their
84
- * children), and an uncovered one is added with its descendants; with `'independent'` the
85
- * node alone is added or removed. A `node` that is not one of the nodes changes nothing.
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
- for (const v of subtree)
99
- covered.delete(v);
100
- for (let up = parent.get(node); up !== undefined; up = parent.get(up))
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
- for (const v of subtree)
105
- covered.add(v);
148
+ covered.add(node);
106
149
  }
107
150
  return normalizeTreeValue(nodes, [...covered, ...unknownValues(order, value)], selection);
108
151
  }
@@ -148,4 +191,31 @@ export function filterTree(nodes, query) {
148
191
  });
149
192
  return keep(nodes, false);
150
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
+ }
151
221
  //# sourceMappingURL=tree.js.map
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;AAkCnD,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,KAAK,EAAE,SAAS,CAAC,CAAC;IACvB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC;AAED,yHAAyH;AACzH,SAAS,aAAa,CAAmB,KAAoB,EAAE,KAAU;IACvE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAA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AC,KAAK,CAAC,CAAC;IAC1B,KAAK,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,SAAS,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC;AACd,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 TreeOwnOptions<T extends string = string, Ctx = any> = {
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 TreeFieldOptions<T extends string = string, RouteId extends string = string, Ctx = any> = FieldOptions<T[], T[], RouteId, Ctx> & TreeOwnOptions<T, Ctx>;
14
- export interface TreeFieldControls<T extends string = string> extends FieldControls<T[], T[]> {
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 treeInitialValue<T extends string>(opts: {
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
- * and `selection` says which nodes the value lists (see TreeSelection). The value is shown
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 useTreeField<T extends string = string, RouteId extends string = string, Ctx = any>(opts: TreeFieldOptions<T, RouteId, Ctx>, registry?: ErrorRoutesRegistry<RouteId>): TreeFieldControls<T>;
39
- //# sourceMappingURL=useTreeField.d.ts.map
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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AAG,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 treeInitialValue(opts, ctx, id) {
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
- * and `selection` says which nodes the value lists (see TreeSelection). The value is shown
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 useTreeField(opts, registry) {
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 = () => treeInitialValue(opts, ctx, opts.id);
28
- const field = useFieldCore('tree', inside ? { ...opts, initialValue } : opts, registry);
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=useTreeField.js.map
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,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C,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"}
@@ -0,0 +1,79 @@
1
+ import { type FieldControls, type FieldOptions } from './field.js';
2
+ import { type OneOfChoiceControls } from './choices.js';
3
+ import { type FieldCtx } from './FieldContext.js';
4
+ import { type TreeChoose, type TreeExpand, type TreeNode } from './tree.js';
5
+ import type { ErrorRoutesRegistry, ValueOrFn } from './types.js';
6
+ export type OneOfTreeOwnOptions<T extends string = string, Ctx = any> = {
7
+ /** The roots, each with its children; static or derived (a function, of the field context if it declares a parameter). */
8
+ nodes: ValueOrFn<TreeNode<T>[], Ctx>;
9
+ /** Which nodes may be chosen; default 'any' (see TreeChoose). */
10
+ choose?: TreeChoose;
11
+ /** Whether the value may be empty (''), nothing chosen; default false (as oneOf, never empty). */
12
+ optional?: boolean;
13
+ /** Which nodes a widget opens at first; default 'selected' (the value's ancestors; see TreeExpand). */
14
+ expand?: TreeExpand;
15
+ };
16
+ export type OneOfTreeFieldOptions<T extends string = string, RouteId extends string = string, Ctx = any> = FieldOptions<T | '', T | '', RouteId, Ctx> & OneOfTreeOwnOptions<T, Ctx>;
17
+ /** A tree node as the one-of tree's widgets get it: the resolved choice, its children likewise, and whether it may be chosen, is the value, or an ancestor of it. */
18
+ export interface OneOfTreeNodeControls<T extends string = string> extends OneOfChoiceControls<T> {
19
+ children: OneOfTreeNodeControls<T>[] | undefined;
20
+ /** Whether the field may choose this node under `choose` (see canChooseNode). */
21
+ choosable: boolean;
22
+ /** It is the value. */
23
+ current: boolean;
24
+ /** An ancestor of the value (not the value itself). */
25
+ onPath: boolean;
26
+ }
27
+ export interface OneOfTreeFieldControls<T extends string = string> extends FieldControls<T | '', T | ''> {
28
+ /** The roots as the widgets get them, each with its children. */
29
+ nodes: OneOfTreeNodeControls<T>[];
30
+ /** Every node, by its value. */
31
+ byValue: Map<T, OneOfTreeNodeControls<T>>;
32
+ /** The chosen node, or undefined (the value is empty, or names no node). */
33
+ current: OneOfTreeNodeControls<T> | undefined;
34
+ /** The nodes from the root down to `current`, inclusive; empty when there is none. */
35
+ path: OneOfTreeNodeControls<T>[];
36
+ /**
37
+ * The choosable node just before `current` in tree pre-order — by `current`'s own position,
38
+ * not its position among the choosable nodes, so a `current` that cannot itself be chosen
39
+ * (a value naming a folder, or a node a context change disabled) still gets its true
40
+ * neighbours. Undefined at the start, and with no `current`.
41
+ */
42
+ previous: OneOfTreeNodeControls<T> | undefined;
43
+ /** The choosable node just after `current` in tree pre-order, by the same rule; with no `current`, the first choosable node. */
44
+ next: OneOfTreeNodeControls<T> | undefined;
45
+ optional: boolean;
46
+ choose: TreeChoose;
47
+ /** The nodes a widget opens at first (from `expand`). */
48
+ expandedKeys: T[];
49
+ /** Requests ''; refused (with a warning) unless `optional`, as `setValue('')` would be. */
50
+ clear(): void;
51
+ }
52
+ /**
53
+ * The implicit initial value for a one-of tree field: `initialValue` resolved through the field
54
+ * context, else '' when `optional`, else the first node `canChooseNode` accepts in tree
55
+ * pre-order, else '' (no node can be chosen; as oneOf's undefined choice).
56
+ */
57
+ export declare function oneOfTreeInitialValue<T extends string>(opts: {
58
+ initialValue?: ValueOrFn<T | ''>;
59
+ choose?: TreeChoose;
60
+ optional?: boolean;
61
+ }, ctx: FieldCtx, id: string, nodes: TreeNode<T>[]): T | '';
62
+ /**
63
+ * A field whose value is a single tree node, or nothing (Praeceptor's category picker, a
64
+ * table of contents): `choosable` (a per-node flag, default true; a folder) and the field's
65
+ * `choose: 'any' | 'leaves'` together say which nodes `setValue` accepts (canChooseNode);
66
+ * `optional` says whether '' (nothing chosen) is one of them too. `setValue` refuses, with a
67
+ * warning (as useOneOfField refuses a disabled choice): a value naming no node, a node
68
+ * `canChooseNode` rejects, and '' unless `optional`. `clear()` requests ''. The field's current
69
+ * state is the chosen node's description, unless `valueDescriptions` words it differently (as
70
+ * oneOf). `previous` / `next` are the choosable nodes just before and after `current`'s own
71
+ * position in tree pre-order (so a `current` that cannot itself be chosen still gets its true
72
+ * neighbours, skipping only the nodes between them that cannot be chosen); with no `current`,
73
+ * `previous` is undefined and `next` is the first choosable node. `expandedKeys` (from `expand`,
74
+ * default `'selected'`) are the value's ancestors,
75
+ * so a table of contents opens where the reader is. Inside the field the value starts at
76
+ * `oneOfTreeInitialValue`.
77
+ */
78
+ export declare function useOneOfTreeField<T extends string = string, RouteId extends string = string, Ctx = any>(opts: OneOfTreeFieldOptions<T, RouteId, Ctx>, registry?: ErrorRoutesRegistry<RouteId>): OneOfTreeFieldControls<T>;
79
+ //# sourceMappingURL=useOneOfTreeField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOneOfTreeField.d.ts","sourceRoot":"","sources":["../src/useOneOfTreeField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAEL,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAChD,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,mBAA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