@azx-pbc/axiom-builder 0.0.0-stage → 0.0.6

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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +648 -2
  3. package/dist/cards/selectors.d.ts +70 -0
  4. package/dist/cards/selectors.d.ts.map +1 -0
  5. package/dist/cards/selectors.js +194 -0
  6. package/dist/cards/selectors.js.map +1 -0
  7. package/dist/definition.d.ts +36 -0
  8. package/dist/definition.d.ts.map +1 -0
  9. package/dist/definition.js +48 -0
  10. package/dist/definition.js.map +1 -0
  11. package/dist/evidence/cases.d.ts +44 -0
  12. package/dist/evidence/cases.d.ts.map +1 -0
  13. package/dist/evidence/cases.js +578 -0
  14. package/dist/evidence/cases.js.map +1 -0
  15. package/dist/evidence/repairs.d.ts +99 -0
  16. package/dist/evidence/repairs.d.ts.map +1 -0
  17. package/dist/evidence/repairs.js +181 -0
  18. package/dist/evidence/repairs.js.map +1 -0
  19. package/dist/evidence/summary.d.ts +35 -0
  20. package/dist/evidence/summary.d.ts.map +1 -0
  21. package/dist/evidence/summary.js +38 -0
  22. package/dist/evidence/summary.js.map +1 -0
  23. package/dist/i18n/gaps.d.ts +3 -0
  24. package/dist/i18n/gaps.d.ts.map +1 -0
  25. package/dist/i18n/gaps.js +2 -0
  26. package/dist/i18n/gaps.js.map +1 -0
  27. package/dist/i18n/message-slots.d.ts +19 -0
  28. package/dist/i18n/message-slots.d.ts.map +1 -0
  29. package/dist/i18n/message-slots.js +101 -0
  30. package/dist/i18n/message-slots.js.map +1 -0
  31. package/dist/i18n/text-locale.d.ts +13 -0
  32. package/dist/i18n/text-locale.d.ts.map +1 -0
  33. package/dist/i18n/text-locale.js +14 -0
  34. package/dist/i18n/text-locale.js.map +1 -0
  35. package/dist/i18n/translations.d.ts +56 -0
  36. package/dist/i18n/translations.d.ts.map +1 -0
  37. package/dist/i18n/translations.js +103 -0
  38. package/dist/i18n/translations.js.map +1 -0
  39. package/dist/impact/references.d.ts +143 -0
  40. package/dist/impact/references.d.ts.map +1 -0
  41. package/dist/impact/references.js +429 -0
  42. package/dist/impact/references.js.map +1 -0
  43. package/dist/index.d.ts +86 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +58 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/preview/compile-preview.d.ts +67 -0
  48. package/dist/preview/compile-preview.d.ts.map +1 -0
  49. package/dist/preview/compile-preview.js +286 -0
  50. package/dist/preview/compile-preview.js.map +1 -0
  51. package/dist/preview/handle.d.ts +119 -0
  52. package/dist/preview/handle.d.ts.map +1 -0
  53. package/dist/preview/handle.js +2 -0
  54. package/dist/preview/handle.js.map +1 -0
  55. package/dist/preview/held.d.ts +39 -0
  56. package/dist/preview/held.d.ts.map +1 -0
  57. package/dist/preview/held.js +15 -0
  58. package/dist/preview/held.js.map +1 -0
  59. package/dist/preview/measurement.d.ts +5 -0
  60. package/dist/preview/measurement.d.ts.map +1 -0
  61. package/dist/preview/measurement.js +18 -0
  62. package/dist/preview/measurement.js.map +1 -0
  63. package/dist/publish/build.d.ts +33 -0
  64. package/dist/publish/build.d.ts.map +1 -0
  65. package/dist/publish/build.js +15 -0
  66. package/dist/publish/build.js.map +1 -0
  67. package/dist/publish/diff.d.ts +208 -0
  68. package/dist/publish/diff.d.ts.map +1 -0
  69. package/dist/publish/diff.js +227 -0
  70. package/dist/publish/diff.js.map +1 -0
  71. package/dist/publish/review.d.ts +41 -0
  72. package/dist/publish/review.d.ts.map +1 -0
  73. package/dist/publish/review.js +22 -0
  74. package/dist/publish/review.js.map +1 -0
  75. package/dist/schema/dataset-input.d.ts +30 -0
  76. package/dist/schema/dataset-input.d.ts.map +1 -0
  77. package/dist/schema/dataset-input.js +58 -0
  78. package/dist/schema/dataset-input.js.map +1 -0
  79. package/dist/schema/dataset.d.ts +166 -0
  80. package/dist/schema/dataset.d.ts.map +1 -0
  81. package/dist/schema/dataset.js +281 -0
  82. package/dist/schema/dataset.js.map +1 -0
  83. package/dist/schema/declarations.d.ts +15 -0
  84. package/dist/schema/declarations.d.ts.map +1 -0
  85. package/dist/schema/declarations.js +47 -0
  86. package/dist/schema/declarations.js.map +1 -0
  87. package/dist/schema/document.d.ts +504 -0
  88. package/dist/schema/document.d.ts.map +1 -0
  89. package/dist/schema/document.js +337 -0
  90. package/dist/schema/document.js.map +1 -0
  91. package/dist/schema/error.d.ts +15 -0
  92. package/dist/schema/error.d.ts.map +1 -0
  93. package/dist/schema/error.js +18 -0
  94. package/dist/schema/error.js.map +1 -0
  95. package/dist/schema/field-id.d.ts +8 -0
  96. package/dist/schema/field-id.d.ts.map +1 -0
  97. package/dist/schema/field-id.js +47 -0
  98. package/dist/schema/field-id.js.map +1 -0
  99. package/dist/schema/layout.d.ts +118 -0
  100. package/dist/schema/layout.d.ts.map +1 -0
  101. package/dist/schema/layout.js +101 -0
  102. package/dist/schema/layout.js.map +1 -0
  103. package/dist/schema/palette.d.ts +103 -0
  104. package/dist/schema/palette.d.ts.map +1 -0
  105. package/dist/schema/palette.js +140 -0
  106. package/dist/schema/palette.js.map +1 -0
  107. package/dist/schema/read.d.ts +49 -0
  108. package/dist/schema/read.d.ts.map +1 -0
  109. package/dist/schema/read.js +942 -0
  110. package/dist/schema/read.js.map +1 -0
  111. package/dist/store/apply-dataset.d.ts +14 -0
  112. package/dist/store/apply-dataset.d.ts.map +1 -0
  113. package/dist/store/apply-dataset.js +513 -0
  114. package/dist/store/apply-dataset.js.map +1 -0
  115. package/dist/store/apply.d.ts +37 -0
  116. package/dist/store/apply.d.ts.map +1 -0
  117. package/dist/store/apply.js +2269 -0
  118. package/dist/store/apply.js.map +1 -0
  119. package/dist/store/candidate.d.ts +37 -0
  120. package/dist/store/candidate.d.ts.map +1 -0
  121. package/dist/store/candidate.js +178 -0
  122. package/dist/store/candidate.js.map +1 -0
  123. package/dist/store/commands/coverage.d.ts +58 -0
  124. package/dist/store/commands/coverage.d.ts.map +1 -0
  125. package/dist/store/commands/coverage.js +354 -0
  126. package/dist/store/commands/coverage.js.map +1 -0
  127. package/dist/store/commands/dataset.d.ts +26 -0
  128. package/dist/store/commands/dataset.d.ts.map +1 -0
  129. package/dist/store/commands/dataset.js +368 -0
  130. package/dist/store/commands/dataset.js.map +1 -0
  131. package/dist/store/commands/document.d.ts +21 -0
  132. package/dist/store/commands/document.d.ts.map +1 -0
  133. package/dist/store/commands/document.js +160 -0
  134. package/dist/store/commands/document.js.map +1 -0
  135. package/dist/store/commands/field.d.ts +32 -0
  136. package/dist/store/commands/field.d.ts.map +1 -0
  137. package/dist/store/commands/field.js +572 -0
  138. package/dist/store/commands/field.js.map +1 -0
  139. package/dist/store/commands/layout.d.ts +16 -0
  140. package/dist/store/commands/layout.d.ts.map +1 -0
  141. package/dist/store/commands/layout.js +70 -0
  142. package/dist/store/commands/layout.js.map +1 -0
  143. package/dist/store/commands/parse.d.ts +19 -0
  144. package/dist/store/commands/parse.d.ts.map +1 -0
  145. package/dist/store/commands/parse.js +328 -0
  146. package/dist/store/commands/parse.js.map +1 -0
  147. package/dist/store/commands/readers.d.ts +198 -0
  148. package/dist/store/commands/readers.d.ts.map +1 -0
  149. package/dist/store/commands/readers.js +711 -0
  150. package/dist/store/commands/readers.js.map +1 -0
  151. package/dist/store/commands/rule.d.ts +24 -0
  152. package/dist/store/commands/rule.d.ts.map +1 -0
  153. package/dist/store/commands/rule.js +379 -0
  154. package/dist/store/commands/rule.js.map +1 -0
  155. package/dist/store/commands/shapes.d.ts +900 -0
  156. package/dist/store/commands/shapes.d.ts.map +1 -0
  157. package/dist/store/commands/shapes.js +166 -0
  158. package/dist/store/commands/shapes.js.map +1 -0
  159. package/dist/store/commands/suggestions.d.ts +37 -0
  160. package/dist/store/commands/suggestions.d.ts.map +1 -0
  161. package/dist/store/commands/suggestions.js +177 -0
  162. package/dist/store/commands/suggestions.js.map +1 -0
  163. package/dist/store/commands.d.ts +16 -0
  164. package/dist/store/commands.d.ts.map +1 -0
  165. package/dist/store/commands.js +13 -0
  166. package/dist/store/commands.js.map +1 -0
  167. package/dist/store/dataset-candidate.d.ts +33 -0
  168. package/dist/store/dataset-candidate.d.ts.map +1 -0
  169. package/dist/store/dataset-candidate.js +31 -0
  170. package/dist/store/dataset-candidate.js.map +1 -0
  171. package/dist/store/dataset-pin.d.ts +93 -0
  172. package/dist/store/dataset-pin.d.ts.map +1 -0
  173. package/dist/store/dataset-pin.js +86 -0
  174. package/dist/store/dataset-pin.js.map +1 -0
  175. package/dist/store/dataset-store.d.ts +96 -0
  176. package/dist/store/dataset-store.d.ts.map +1 -0
  177. package/dist/store/dataset-store.js +112 -0
  178. package/dist/store/dataset-store.js.map +1 -0
  179. package/dist/store/history.d.ts +149 -0
  180. package/dist/store/history.d.ts.map +1 -0
  181. package/dist/store/history.js +173 -0
  182. package/dist/store/history.js.map +1 -0
  183. package/dist/store/measurement.d.ts +5 -0
  184. package/dist/store/measurement.d.ts.map +1 -0
  185. package/dist/store/measurement.js +20 -0
  186. package/dist/store/measurement.js.map +1 -0
  187. package/dist/store/notify.d.ts +11 -0
  188. package/dist/store/notify.d.ts.map +1 -0
  189. package/dist/store/notify.js +26 -0
  190. package/dist/store/notify.js.map +1 -0
  191. package/dist/store/published.d.ts +50 -0
  192. package/dist/store/published.d.ts.map +1 -0
  193. package/dist/store/published.js +27 -0
  194. package/dist/store/published.js.map +1 -0
  195. package/dist/store/refusals.d.ts +175 -0
  196. package/dist/store/refusals.d.ts.map +1 -0
  197. package/dist/store/refusals.js +160 -0
  198. package/dist/store/refusals.js.map +1 -0
  199. package/dist/store/steps.d.ts +14 -0
  200. package/dist/store/steps.d.ts.map +1 -0
  201. package/dist/store/steps.js +124 -0
  202. package/dist/store/steps.js.map +1 -0
  203. package/dist/store/store.d.ts +142 -0
  204. package/dist/store/store.d.ts.map +1 -0
  205. package/dist/store/store.js +136 -0
  206. package/dist/store/store.js.map +1 -0
  207. package/dist/store/unchanged.d.ts +12 -0
  208. package/dist/store/unchanged.d.ts.map +1 -0
  209. package/dist/store/unchanged.js +35 -0
  210. package/dist/store/unchanged.js.map +1 -0
  211. package/dist/visual/emit.d.ts +21 -0
  212. package/dist/visual/emit.d.ts.map +1 -0
  213. package/dist/visual/emit.js +133 -0
  214. package/dist/visual/emit.js.map +1 -0
  215. package/dist/visual/parse.d.ts +32 -0
  216. package/dist/visual/parse.d.ts.map +1 -0
  217. package/dist/visual/parse.js +330 -0
  218. package/dist/visual/parse.js.map +1 -0
  219. package/dist/visual/project.d.ts +40 -0
  220. package/dist/visual/project.d.ts.map +1 -0
  221. package/dist/visual/project.js +349 -0
  222. package/dist/visual/project.js.map +1 -0
  223. package/dist/visual/represent.d.ts +50 -0
  224. package/dist/visual/represent.d.ts.map +1 -0
  225. package/dist/visual/represent.js +66 -0
  226. package/dist/visual/represent.js.map +1 -0
  227. package/dist/visual/vocabulary.d.ts +121 -0
  228. package/dist/visual/vocabulary.d.ts.map +1 -0
  229. package/dist/visual/vocabulary.js +32 -0
  230. package/dist/visual/vocabulary.js.map +1 -0
  231. package/package.json +52 -3
@@ -0,0 +1,118 @@
1
+ import { LAYOUT_KINDS } from '@azx-pbc/axiom-compiler';
2
+ import type { AuthoringDocument } from './document.js';
3
+ import type { LayoutPath } from '../store/commands.js';
4
+ /**
5
+ * The document's layout as an editor addresses it.
6
+ *
7
+ * An authoring UI needs the layout's structure — which kinds it declares, the child-index path
8
+ * that names each node, the column count that bounds each placement, the wizard and its steps —
9
+ * and it needs those facts as types rather than as members of `AuthoringLayoutNode`, which is wire
10
+ * JSON. This module is that projection, and it is one walk of the compiler's own reader
11
+ * (`readLayout`): the kinds, the members and the child structure are the grammar's answers, so a
12
+ * node this index reports is a node the compile reads the same way.
13
+ *
14
+ * It is a projection, not a second parser. A spelling the grammar does not admit is reported as
15
+ * `kind: 'unknown'` rather than dropped or thrown — the document is a draft, and an illegal node
16
+ * still occupies the path the author has to repair. The expression slots (`visibleWhen`, `params`,
17
+ * a readout's `value`) stay `unknown` for the reason the document type keeps them: an authored
18
+ * draft states source text, while a value loaded from another process may already be the
19
+ * compiler's parsed form, and this index does not narrow either.
20
+ *
21
+ * The studio used to hand-walk `AuthoringDocument['layout']` with casts for exactly these facts;
22
+ * one exported walk is what removes that second implementation without removing the facts.
23
+ */
24
+ /** One node kind of the closed layout grammar, as the compiler's own table states it. */
25
+ export type LayoutKind = (typeof LAYOUT_KINDS)[number];
26
+ /** One summary-card readout, as the node states it: a label key and an expression slot. */
27
+ export interface IndexedReadout {
28
+ readonly labelKey: string | undefined;
29
+ /** The authored source text, or a loaded draft's compiled form; this index narrows neither. */
30
+ readonly value: unknown;
31
+ }
32
+ /**
33
+ * One layout node, typed and addressed.
34
+ *
35
+ * `path` is the child-index chain every layout command takes (`addLayoutNode`'s `parent`,
36
+ * `editLayoutNode` and `removeLayoutNode`'s `target`, `setGroupColumns`' `group`), so an editor
37
+ * dispatches with the value it read here rather than rebuilding it. `columns` is the count this
38
+ * node lays its own children out in — the grammar's default of 1 for a leaf or a container that
39
+ * states none — and `parentColumns` is the count that bounds this node's `colSpan`, which the
40
+ * compiler's column check uses and the top level of which is 1.
41
+ */
42
+ export interface IndexedLayoutNode {
43
+ /** The grammar kind, or `unknown` for a spelling no kind admits. */
44
+ readonly kind: LayoutKind | 'unknown';
45
+ /** The child-index path that names this node, `[]`-rooted at the layout list. */
46
+ readonly path: LayoutPath;
47
+ /** The path of the node that holds this one, or `undefined` at the top level. */
48
+ readonly parent: LayoutPath | undefined;
49
+ /** This node's position among its parent's children. */
50
+ readonly index: number;
51
+ /** The number of nodes above this one; a top-level node is 0 deep. */
52
+ readonly depth: number;
53
+ /** The columns this node lays its children out in; 1 for a leaf or an unstated container. */
54
+ readonly columns: number;
55
+ /** The columns of the node that holds this one, which bound its `colSpan`; 1 at the top level. */
56
+ readonly parentColumns: number;
57
+ /** The span this node states, or 1; a field leaf spans at most `parentColumns`. */
58
+ readonly colSpan: number;
59
+ readonly sectionId: string | undefined;
60
+ readonly stepId: string | undefined;
61
+ readonly gateId: string | undefined;
62
+ /** The declaration a `field` leaf places. */
63
+ readonly fieldId: string | undefined;
64
+ readonly titleKey: string | undefined;
65
+ readonly descriptionKey: string | undefined;
66
+ readonly textKey: string | undefined;
67
+ /** A callout's tone, exactly as the node spells it; the grammar's vocabulary is small. */
68
+ readonly tone: string | undefined;
69
+ readonly collapsible: boolean | undefined;
70
+ readonly defaultExpanded: boolean | undefined;
71
+ readonly hideWhenEmpty: boolean | undefined;
72
+ /** An authored source expression, or a loaded draft's compiled form; this index narrows neither. */
73
+ readonly visibleWhen: unknown;
74
+ /** A node's message arguments, as expression slots; `undefined` when it states none. */
75
+ readonly params: Readonly<Record<string, unknown>> | undefined;
76
+ /** A `summary_card`'s read-only declarations, in the order the node states them. */
77
+ readonly summaryFields: readonly string[];
78
+ readonly readouts: readonly IndexedReadout[];
79
+ readonly children: readonly IndexedLayoutNode[];
80
+ }
81
+ /** One `field` leaf as a placement: the path, the declaration it places and its column facts. */
82
+ export interface LayoutPlacement {
83
+ readonly path: LayoutPath;
84
+ readonly fieldId: string;
85
+ readonly colSpan: number;
86
+ readonly parentColumns: number;
87
+ /** The node itself, so a caller reads its other members without a second walk. */
88
+ readonly node: IndexedLayoutNode;
89
+ }
90
+ /**
91
+ * Every layout node of one document, indexed by the questions an editor asks.
92
+ *
93
+ * `nodes` is the whole tree in depth-first declaration order, `root` its top level, and `groups`
94
+ * and `placements` are the two subsets layout commands address. `wizard` is the one wizard the
95
+ * grammar admits at the top level, or `undefined` when the draft declares none. Both lookups are
96
+ * exact: a path names a node or answers `undefined`, and a field id answers the first placement
97
+ * that names it (a legal document has exactly one).
98
+ */
99
+ export interface LayoutIndex {
100
+ readonly root: readonly IndexedLayoutNode[];
101
+ readonly nodes: readonly IndexedLayoutNode[];
102
+ readonly groups: readonly IndexedLayoutNode[];
103
+ readonly placements: readonly LayoutPlacement[];
104
+ readonly wizard: IndexedLayoutNode | undefined;
105
+ /** The node at a child-index path, or `undefined` when the path names none. */
106
+ nodeAt(path: LayoutPath): IndexedLayoutNode | undefined;
107
+ /** The placement of one declared field, or `undefined` when the layout does not place it. */
108
+ placementOf(fieldId: string): LayoutPlacement | undefined;
109
+ }
110
+ /**
111
+ * Projects the document's layout, walking the compiler's own read once.
112
+ *
113
+ * The projection is a pure derivation of the document it is given: an unchanged document produces
114
+ * an equal index, and a caller that needs it once per render can keep it beside the document
115
+ * rather than reconstructing a walk of its own.
116
+ */
117
+ export declare function layoutIndex(document: AuthoringDocument): LayoutIndex;
118
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/schema/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,yBAAyB,CAAC;AAEnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,2FAA2F;AAC3F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IACtC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,M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AAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC/C,+EAA+E;IAC/E,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACxD,6FAA6F;IAC7F,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CAC3D;AAyED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,WAAW,CA+BpE"}
@@ -0,0 +1,101 @@
1
+ import { LAYOUT_KINDS, readLayout } from '@azx-pbc/axiom-compiler';
2
+ /** The grammar kind a spelling names, or `unknown` for one it does not. */
3
+ function kindOf(spelled) {
4
+ return LAYOUT_KINDS.find((kind) => kind === spelled) ?? 'unknown';
5
+ }
6
+ /** Whether a kind lays its children out in `columns`; every other kind lays out one. */
7
+ function laysOutColumns(kind) {
8
+ return kind === 'section' || kind === 'group' || kind === 'step';
9
+ }
10
+ /** One level of raw nodes, projected to the tree and the depth-first list in one walk. */
11
+ function indexLevel(raw, parent, parentColumns, depth) {
12
+ const flat = [];
13
+ const nodes = raw.map((node, index) => {
14
+ const path = parent === undefined ? [index] : [...parent, index];
15
+ const kind = kindOf(node.kind);
16
+ const columns = laysOutColumns(kind) ? (node.columns ?? 1) : 1;
17
+ const children = indexLevel(node.children, path, columns, depth + 1);
18
+ const indexed = {
19
+ kind,
20
+ path,
21
+ parent,
22
+ index,
23
+ depth,
24
+ columns,
25
+ parentColumns,
26
+ colSpan: node.colSpan ?? 1,
27
+ sectionId: node.sectionId,
28
+ stepId: node.stepId,
29
+ gateId: node.gateId,
30
+ fieldId: node.fieldId,
31
+ titleKey: node.titleKey,
32
+ descriptionKey: node.descriptionKey,
33
+ textKey: node.textKey,
34
+ tone: node.tone,
35
+ collapsible: node.collapsible,
36
+ defaultExpanded: node.defaultExpanded,
37
+ hideWhenEmpty: node.hideWhenEmpty,
38
+ visibleWhen: node.visibleWhen,
39
+ params: node.params,
40
+ summaryFields: node.fields,
41
+ readouts: node.readouts.map((readout) => ({
42
+ labelKey: readout.labelKey,
43
+ value: readout.value,
44
+ })),
45
+ children: children.nodes,
46
+ };
47
+ flat.push(indexed);
48
+ // A loop rather than a spread: a wide layout would pass one argument per descendant.
49
+ for (const descendant of children.flat)
50
+ flat.push(descendant);
51
+ return indexed;
52
+ });
53
+ return { nodes, flat };
54
+ }
55
+ /** The key a path is looked up by; the separator cannot occur in a child index. */
56
+ function pathKey(path) {
57
+ return path.join(',\u0000');
58
+ }
59
+ /**
60
+ * Projects the document's layout, walking the compiler's own read once.
61
+ *
62
+ * The projection is a pure derivation of the document it is given: an unchanged document produces
63
+ * an equal index, and a caller that needs it once per render can keep it beside the document
64
+ * rather than reconstructing a walk of its own.
65
+ */
66
+ export function layoutIndex(document) {
67
+ const level = indexLevel(readLayout(document), undefined, 1, 0);
68
+ const byPath = new Map();
69
+ const groups = [];
70
+ const placements = [];
71
+ const byField = new Map();
72
+ for (const node of level.flat) {
73
+ byPath.set(pathKey(node.path), node);
74
+ if (node.kind === 'group')
75
+ groups.push(node);
76
+ if (node.kind !== 'field' || node.fieldId === undefined)
77
+ continue;
78
+ const placement = {
79
+ path: node.path,
80
+ fieldId: node.fieldId,
81
+ colSpan: node.colSpan,
82
+ parentColumns: node.parentColumns,
83
+ node,
84
+ };
85
+ placements.push(placement);
86
+ // A legal layout places a field once; a draft that places it twice answers the first, which
87
+ // is the placement a reader reaches first.
88
+ if (!byField.has(node.fieldId))
89
+ byField.set(node.fieldId, placement);
90
+ }
91
+ return {
92
+ root: level.nodes,
93
+ nodes: level.flat,
94
+ groups,
95
+ placements,
96
+ wizard: level.nodes.find((node) => node.kind === 'wizard'),
97
+ nodeAt: (path) => byPath.get(pathKey(path)),
98
+ placementOf: (fieldId) => byField.get(fieldId),
99
+ };
100
+ }
101
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/schema/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AA2HnE,2EAA2E;AAC3E,SAAS,MAAM,CAAC,OAAe;IAC7B,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,SAAS,CAAC;AACpE,CAAC;AAED,wFAAwF;AACxF,SAAS,cAAc,CAAC,IAA4B;IAClD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,MAAM,CAAC;AACnE,CAAC;AAED,0FAA0F;AAC1F,SAAS,UAAU,CACjB,GAA6B,EAC7B,MAA8B,EAC9B,aAAqB,EACrB,KAAa;IAEb,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpC,MAAM,IAAI,GAAe,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC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AAE,IAAI,CAAC,aAAa;YACjC,IAAI;SACL,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,4FAA4F;QAC5F,2CAA2C;QAC3C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvE,CAAC;IACD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,KAAK;QACjB,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,MAAM;QACN,UAAU;QACV,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;QAC1D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3C,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import { LAYOUT_KINDS, readLayout } from '@azx-pbc/axiom-compiler';\nimport type { RawLayoutNode } from '@azx-pbc/axiom-compiler';\nimport type { AuthoringDocument } from './document.js';\nimport type { LayoutPath } from '../store/commands.js';\n\n/**\n * The document's layout as an editor addresses it.\n *\n * An authoring UI needs the layout's structure — which kinds it declares, the child-index path\n * that names each node, the column count that bounds each placement, the wizard and its steps —\n * and it needs those facts as types rather than as members of `AuthoringLayoutNode`, which is wire\n * JSON. This module is that projection, and it is one walk of the compiler's own reader\n * (`readLayout`): the kinds, the members and the child structure are the grammar's answers, so a\n * node this index reports is a node the compile reads the same way.\n *\n * It is a projection, not a second parser. A spelling the grammar does not admit is reported as\n * `kind: 'unknown'` rather than dropped or thrown — the document is a draft, and an illegal node\n * still occupies the path the author has to repair. The expression slots (`visibleWhen`, `params`,\n * a readout's `value`) stay `unknown` for the reason the document type keeps them: an authored\n * draft states source text, while a value loaded from another process may already be the\n * compiler's parsed form, and this index does not narrow either.\n *\n * The studio used to hand-walk `AuthoringDocument['layout']` with casts for exactly these facts;\n * one exported walk is what removes that second implementation without removing the facts.\n */\n\n/** One node kind of the closed layout grammar, as the compiler's own table states it. */\nexport type LayoutKind = (typeof LAYOUT_KINDS)[number];\n\n/** One summary-card readout, as the node states it: a label key and an expression slot. */\nexport interface IndexedReadout {\n readonly labelKey: string | undefined;\n /** The authored source text, or a loaded draft's compiled form; this index narrows neither. */\n readonly value: unknown;\n}\n\n/**\n * One layout node, typed and addressed.\n *\n * `path` is the child-index chain every layout command takes (`addLayoutNode`'s `parent`,\n * `editLayoutNode` and `removeLayoutNode`'s `target`, `setGroupColumns`' `group`), so an editor\n * dispatches with the value it read here rather than rebuilding it. `columns` is the count this\n * node lays its own children out in — the grammar's default of 1 for a leaf or a container that\n * states none — and `parentColumns` is the count that bounds this node's `colSpan`, which the\n * compiler's column check uses and the top level of which is 1.\n */\nexport interface IndexedLayoutNode {\n /** The grammar kind, or `unknown` for a spelling no kind admits. */\n readonly kind: LayoutKind | 'unknown';\n /** The child-index path that names this node, `[]`-rooted at the layout list. */\n readonly path: LayoutPath;\n /** The path of the node that holds this one, or `undefined` at the top level. */\n readonly parent: LayoutPath | undefined;\n /** This node's position among its parent's children. */\n readonly index: number;\n /** The number of nodes above this one; a top-level node is 0 deep. */\n readonly depth: number;\n /** The columns this node lays its children out in; 1 for a leaf or an unstated container. */\n readonly columns: number;\n /** The columns of the node that holds this one, which bound its `colSpan`; 1 at the top level. */\n readonly parentColumns: number;\n /** The span this node states, or 1; a field leaf spans at most `parentColumns`. */\n readonly colSpan: number;\n readonly sectionId: string | undefined;\n readonly stepId: string | undefined;\n readonly gateId: string | undefined;\n /** The declaration a `field` leaf places. */\n readonly fieldId: string | undefined;\n readonly titleKey: string | undefined;\n readonly descriptionKey: string | undefined;\n readonly textKey: string | undefined;\n /** A callout's tone, exactly as the node spells it; the grammar's vocabulary is small. */\n readonly tone: string | undefined;\n readonly collapsible: boolean | undefined;\n readonly defaultExpanded: boolean | undefined;\n readonly hideWhenEmpty: boolean | undefined;\n /** An authored source expression, or a loaded draft's compiled form; this index narrows neither. */\n readonly visibleWhen: unknown;\n /** A node's message arguments, as expression slots; `undefined` when it states none. */\n readonly params: Readonly<Record<string, unknown>> | undefined;\n /** A `summary_card`'s read-only declarations, in the order the node states them. */\n readonly summaryFields: readonly string[];\n readonly readouts: readonly IndexedReadout[];\n readonly children: readonly IndexedLayoutNode[];\n}\n\n/** One `field` leaf as a placement: the path, the declaration it places and its column facts. */\nexport interface LayoutPlacement {\n readonly path: LayoutPath;\n readonly fieldId: string;\n readonly colSpan: number;\n readonly parentColumns: number;\n /** The node itself, so a caller reads its other members without a second walk. */\n readonly node: IndexedLayoutNode;\n}\n\n/**\n * Every layout node of one document, indexed by the questions an editor asks.\n *\n * `nodes` is the whole tree in depth-first declaration order, `root` its top level, and `groups`\n * and `placements` are the two subsets layout commands address. `wizard` is the one wizard the\n * grammar admits at the top level, or `undefined` when the draft declares none. Both lookups are\n * exact: a path names a node or answers `undefined`, and a field id answers the first placement\n * that names it (a legal document has exactly one).\n */\nexport interface LayoutIndex {\n readonly root: readonly IndexedLayoutNode[];\n readonly nodes: readonly IndexedLayoutNode[];\n readonly groups: readonly IndexedLayoutNode[];\n readonly placements: readonly LayoutPlacement[];\n readonly wizard: IndexedLayoutNode | undefined;\n /** The node at a child-index path, or `undefined` when the path names none. */\n nodeAt(path: LayoutPath): IndexedLayoutNode | undefined;\n /** The placement of one declared field, or `undefined` when the layout does not place it. */\n placementOf(fieldId: string): LayoutPlacement | undefined;\n}\n\n/** One level of the walk: its nodes as a tree, and the same nodes depth-first. */\ninterface IndexedLevel {\n readonly nodes: readonly IndexedLayoutNode[];\n readonly flat: readonly IndexedLayoutNode[];\n}\n\n/** The grammar kind a spelling names, or `unknown` for one it does not. */\nfunction kindOf(spelled: string): LayoutKind | 'unknown' {\n return LAYOUT_KINDS.find((kind) => kind === spelled) ?? 'unknown';\n}\n\n/** Whether a kind lays its children out in `columns`; every other kind lays out one. */\nfunction laysOutColumns(kind: LayoutKind | 'unknown'): boolean {\n return kind === 'section' || kind === 'group' || kind === 'step';\n}\n\n/** One level of raw nodes, projected to the tree and the depth-first list in one walk. */\nfunction indexLevel(\n raw: readonly RawLayoutNode[],\n parent: LayoutPath | undefined,\n parentColumns: number,\n depth: number,\n): IndexedLevel {\n const flat: IndexedLayoutNode[] = [];\n const nodes = raw.map((node, index) => {\n const path: LayoutPath = parent === undefined ? [index] : [...parent, index];\n const kind = kindOf(node.kind);\n const columns = laysOutColumns(kind) ? (node.columns ?? 1) : 1;\n const children = indexLevel(node.children, path, columns, depth + 1);\n const indexed: IndexedLayoutNode = {\n kind,\n path,\n parent,\n index,\n depth,\n columns,\n parentColumns,\n colSpan: node.colSpan ?? 1,\n sectionId: node.sectionId,\n stepId: node.stepId,\n gateId: node.gateId,\n fieldId: node.fieldId,\n titleKey: node.titleKey,\n descriptionKey: node.descriptionKey,\n textKey: node.textKey,\n tone: node.tone,\n collapsible: node.collapsible,\n defaultExpanded: node.defaultExpanded,\n hideWhenEmpty: node.hideWhenEmpty,\n visibleWhen: node.visibleWhen,\n params: node.params,\n summaryFields: node.fields,\n readouts: node.readouts.map((readout) => ({\n labelKey: readout.labelKey,\n value: readout.value,\n })),\n children: children.nodes,\n };\n flat.push(indexed);\n // A loop rather than a spread: a wide layout would pass one argument per descendant.\n for (const descendant of children.flat) flat.push(descendant);\n return indexed;\n });\n return { nodes, flat };\n}\n\n/** The key a path is looked up by; the separator cannot occur in a child index. */\nfunction pathKey(path: LayoutPath): string {\n return path.join(',\\u0000');\n}\n\n/**\n * Projects the document's layout, walking the compiler's own read once.\n *\n * The projection is a pure derivation of the document it is given: an unchanged document produces\n * an equal index, and a caller that needs it once per render can keep it beside the document\n * rather than reconstructing a walk of its own.\n */\nexport function layoutIndex(document: AuthoringDocument): LayoutIndex {\n const level = indexLevel(readLayout(document), undefined, 1, 0);\n const byPath = new Map<string, IndexedLayoutNode>();\n const groups: IndexedLayoutNode[] = [];\n const placements: LayoutPlacement[] = [];\n const byField = new Map<string, LayoutPlacement>();\n for (const node of level.flat) {\n byPath.set(pathKey(node.path), node);\n if (node.kind === 'group') groups.push(node);\n if (node.kind !== 'field' || node.fieldId === undefined) continue;\n const placement: LayoutPlacement = {\n path: node.path,\n fieldId: node.fieldId,\n colSpan: node.colSpan,\n parentColumns: node.parentColumns,\n node,\n };\n placements.push(placement);\n // A legal layout places a field once; a draft that places it twice answers the first, which\n // is the placement a reader reaches first.\n if (!byField.has(node.fieldId)) byField.set(node.fieldId, placement);\n }\n return {\n root: level.nodes,\n nodes: level.flat,\n groups,\n placements,\n wizard: level.nodes.find((node) => node.kind === 'wizard'),\n nodeAt: (path) => byPath.get(pathKey(path)),\n placementOf: (fieldId) => byField.get(fieldId),\n };\n}\n"]}
@@ -0,0 +1,103 @@
1
+ import type { Control, DurationUnit, ItemPrimitive, Primitive } from '@azx-pbc/axiom-runtime';
2
+ import type { ScalarPrimitive } from './document.js';
3
+ /**
4
+ * The field palette: every declaration an author may add, derived from the compiler's control
5
+ * matrix rather than restated.
6
+ *
7
+ * A palette row is what a builder UI offers as a new field. A scalar row is one
8
+ * `(primitive, control)` pair the matrix pairs — `.text` on `string`, `.rating` on `integer` —
9
+ * and a container row is a repeating structure, which is a declaration and not a control: a
10
+ * `record` has no control and the palette does not invent one. A scalar array is a third kind
11
+ * because its `items` declaration is what makes `multiselect`, `rank` and `tags` mean anything.
12
+ *
13
+ * `CONTROLS_BY_PRIMITIVE` is the one authority for the pairing; `FIELD_PALETTE` is a view of it.
14
+ * A control added to the matrix appears here without an edit, and a primitive the matrix gives
15
+ * no controls renders no scalar row.
16
+ *
17
+ * A row is a *declaration shape*, not a whole command: a rating reads its point count from an
18
+ * option domain, a money declaration needs a currency and a scale, an array needs a row identity
19
+ * or a domain, and a container needs members. `needs` states exactly which of those the row
20
+ * cannot supply itself, so a UI can build a complete `addField` (or `addRecordArray`) from the
21
+ * row instead of discovering the missing member from a refusal.
22
+ */
23
+ /**
24
+ * The controls that draw their content from a declared option domain.
25
+ *
26
+ * A rating and a Likert scale read their point count from it, and a chooser offers one of its
27
+ * values; a field with one of these controls and no `options`/`optionSource` renders a control
28
+ * with nothing in it. The compiler states both halves (`OPTION_BOUND_CONTROLS` and
29
+ * `CHOOSER_CONTROLS`), so this is a union of its sets rather than a mirror of them.
30
+ */
31
+ export declare const OPTION_DOMAIN_CONTROLS: ReadonlySet<Control>;
32
+ /** The item primitives whose rows a declared option domain identifies. */
33
+ export declare const OPTION_ARRAY_ITEMS: ReadonlySet<ItemPrimitive>;
34
+ /**
35
+ * What a palette row cannot state on its own.
36
+ *
37
+ * A row names a shape; the command that authors it must also carry these members, because the
38
+ * closed metaschema requires them for that shape. Every row states all five, so a caller can
39
+ * read the answer without knowing which control or primitive it is looking at.
40
+ */
41
+ export interface PaletteNeeds {
42
+ /** An option domain: the control draws its scale or its list from the codes. */
43
+ readonly options: boolean;
44
+ /** A `currency` and a `scale`: the declaration holds money. */
45
+ readonly moneyDomain: boolean;
46
+ /** A row identity: the array's rows are freeform values rather than an option domain. */
47
+ readonly rowKey: boolean;
48
+ /** At least one member: the declaration is a container. */
49
+ readonly members: boolean;
50
+ /**
51
+ * A `covers` list: the declaration is a signature capture, and the fields its signature
52
+ * binds are other declarations a row cannot name.
53
+ */
54
+ readonly covers: boolean;
55
+ }
56
+ /**
57
+ * The declaration members a row states itself, in the command's own vocabulary.
58
+ *
59
+ * They are the members a shape carries wherever it is authored — a slider's range and its
60
+ * sentences, a duration's unit, a quantity's unit domain — rather than choices the author makes
61
+ * per instance. A row states them so a UI can build the whole `addField` from the row, and the
62
+ * slider's defaults are the ordinary 0–100 track: the author edits the range afterwards with
63
+ * `setFieldDeclaration`.
64
+ */
65
+ export interface PaletteDeclaration {
66
+ /** A slider's two bounds, `MODEL-2.1.16`; the compiler refuses a slider without both. */
67
+ readonly minimum?: number | string;
68
+ readonly maximum?: number | string;
69
+ /** The sentence each bound raises; the store mints `field.<trail>.minimum`/`.maximum`. */
70
+ readonly minimumMessage?: string;
71
+ readonly maximumMessage?: string;
72
+ /** A number control's increment, `MODEL-2.1.16`. */
73
+ readonly step?: number | string;
74
+ /** A `quantity` declaration's unit domain, `MODEL-2.1.21`. */
75
+ readonly units?: readonly string[];
76
+ /** A `duration` declaration's unit, `MODEL-2.1.24`. */
77
+ readonly unit?: DurationUnit;
78
+ }
79
+ /** One palette row: a scalar control, a scalar array, or a container declaration. */
80
+ export type FieldPaletteEntry = {
81
+ readonly kind: 'control';
82
+ readonly primitive: ScalarPrimitive;
83
+ readonly control: Control;
84
+ readonly needs: PaletteNeeds;
85
+ readonly declaration?: PaletteDeclaration;
86
+ } | {
87
+ readonly kind: 'scalar_array';
88
+ readonly item: ItemPrimitive;
89
+ readonly control: Control;
90
+ readonly needs: PaletteNeeds;
91
+ readonly declaration?: PaletteDeclaration;
92
+ } | {
93
+ readonly kind: 'container';
94
+ readonly container: 'record' | 'record_array';
95
+ readonly needs: PaletteNeeds;
96
+ };
97
+ /** Every value a builder UI may offer, in one closed list. */
98
+ export declare const FIELD_PALETTE: readonly FieldPaletteEntry[];
99
+ /** Whether a field of this shape must state a control at all. */
100
+ export declare function fieldRequiresControl(primitive: Primitive, items: ItemPrimitive | undefined): boolean;
101
+ /** Every control hint a field of this shape admits. */
102
+ export declare function fieldsControls(primitive: Primitive, items: ItemPrimitive | undefined): readonly Control[];
103
+ //# sourceMappingURL=palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/schema/palette.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC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,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAC3C,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAC3C,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,cAAc,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B,CAAC;AAyCN,8DAA8D;AAC9D,eAAO,MAAM,aAAa,EAAE,SAAS,iBAAiB,EAKrD,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,aAAa,GAAG,SAAS,GAC/B,OAAO,CAIT;AAED,uDAAuD;AACvD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,aAAa,GAAG,SAAS,GAC/B,SAAS,OAAO,EAAE,CAIpB"}
@@ -0,0 +1,140 @@
1
+ import { CHOOSER_CONTROLS, CONTROLS_BY_PRIMITIVE, OPTION_BOUND_CONTROLS, controlsFor, requiresControl, } from '@azx-pbc/axiom-compiler';
2
+ import { ITEM_PRIMITIVES } from '@azx-pbc/axiom-runtime';
3
+ /**
4
+ * The field palette: every declaration an author may add, derived from the compiler's control
5
+ * matrix rather than restated.
6
+ *
7
+ * A palette row is what a builder UI offers as a new field. A scalar row is one
8
+ * `(primitive, control)` pair the matrix pairs — `.text` on `string`, `.rating` on `integer` —
9
+ * and a container row is a repeating structure, which is a declaration and not a control: a
10
+ * `record` has no control and the palette does not invent one. A scalar array is a third kind
11
+ * because its `items` declaration is what makes `multiselect`, `rank` and `tags` mean anything.
12
+ *
13
+ * `CONTROLS_BY_PRIMITIVE` is the one authority for the pairing; `FIELD_PALETTE` is a view of it.
14
+ * A control added to the matrix appears here without an edit, and a primitive the matrix gives
15
+ * no controls renders no scalar row.
16
+ *
17
+ * A row is a *declaration shape*, not a whole command: a rating reads its point count from an
18
+ * option domain, a money declaration needs a currency and a scale, an array needs a row identity
19
+ * or a domain, and a container needs members. `needs` states exactly which of those the row
20
+ * cannot supply itself, so a UI can build a complete `addField` (or `addRecordArray`) from the
21
+ * row instead of discovering the missing member from a refusal.
22
+ */
23
+ /**
24
+ * The controls that draw their content from a declared option domain.
25
+ *
26
+ * A rating and a Likert scale read their point count from it, and a chooser offers one of its
27
+ * values; a field with one of these controls and no `options`/`optionSource` renders a control
28
+ * with nothing in it. The compiler states both halves (`OPTION_BOUND_CONTROLS` and
29
+ * `CHOOSER_CONTROLS`), so this is a union of its sets rather than a mirror of them.
30
+ */
31
+ export const OPTION_DOMAIN_CONTROLS = new Set([
32
+ ...OPTION_BOUND_CONTROLS,
33
+ ...CHOOSER_CONTROLS,
34
+ ]);
35
+ /** The primitives a field, rather than a container, may declare. */
36
+ const SCALAR_PRIMITIVES = [
37
+ 'string',
38
+ 'boolean',
39
+ 'integer',
40
+ 'decimal',
41
+ 'money',
42
+ 'quantity',
43
+ 'duration',
44
+ 'date',
45
+ 'instant',
46
+ 'time',
47
+ 'media_ref',
48
+ 'signature_ref',
49
+ 'timeslot',
50
+ 'address',
51
+ 'coordinate',
52
+ ];
53
+ /** The item primitives whose rows a declared option domain identifies. */
54
+ export const OPTION_ARRAY_ITEMS = new Set([
55
+ 'string',
56
+ 'integer',
57
+ 'duration',
58
+ ]);
59
+ /** The common case: a row that states everything its command needs. */
60
+ const NO_NEEDS = {
61
+ options: false,
62
+ moneyDomain: false,
63
+ rowKey: false,
64
+ members: false,
65
+ covers: false,
66
+ };
67
+ /** The members a scalar control row states itself, or `undefined` when it states everything. */
68
+ function controlDeclaration(primitive, control) {
69
+ if (control === 'slider') {
70
+ return {
71
+ minimum: 0,
72
+ maximum: 100,
73
+ minimumMessage: 'Must be at least 0',
74
+ maximumMessage: 'Must be at most 100',
75
+ step: primitive === 'integer' ? 1 : '0.1',
76
+ };
77
+ }
78
+ if (primitive === 'quantity')
79
+ return { units: ['each'] };
80
+ if (primitive === 'duration')
81
+ return { unit: 'minutes' };
82
+ return undefined;
83
+ }
84
+ /** The members a scalar array row states itself, or `undefined` when it states everything. */
85
+ function itemDeclaration(item) {
86
+ if (item === 'quantity')
87
+ return { units: ['each'] };
88
+ if (item === 'duration')
89
+ return { unit: 'minutes' };
90
+ return undefined;
91
+ }
92
+ const CONTROL_ENTRIES = SCALAR_PRIMITIVES.flatMap((primitive) => CONTROLS_BY_PRIMITIVE[primitive].map((control) => {
93
+ const declaration = controlDeclaration(primitive, control);
94
+ return {
95
+ kind: 'control',
96
+ primitive,
97
+ control,
98
+ needs: {
99
+ ...NO_NEEDS,
100
+ options: OPTION_DOMAIN_CONTROLS.has(control),
101
+ moneyDomain: primitive === 'money',
102
+ covers: control === 'signature_capture',
103
+ },
104
+ ...(declaration === undefined ? {} : { declaration }),
105
+ };
106
+ }));
107
+ const SCALAR_ARRAY_ENTRIES = ITEM_PRIMITIVES.flatMap((item) => CONTROLS_BY_PRIMITIVE.array.map((control) => {
108
+ const declaration = itemDeclaration(item);
109
+ return {
110
+ kind: 'scalar_array',
111
+ item,
112
+ control,
113
+ needs: {
114
+ ...NO_NEEDS,
115
+ // A string, integer or duration domain identifies its rows by their values; every
116
+ // other item primitive has no option domain the metaschema admits, so the array states
117
+ // a row key.
118
+ options: OPTION_ARRAY_ITEMS.has(item),
119
+ moneyDomain: item === 'money',
120
+ rowKey: !OPTION_ARRAY_ITEMS.has(item),
121
+ },
122
+ ...(declaration === undefined ? {} : { declaration }),
123
+ };
124
+ }));
125
+ /** Every value a builder UI may offer, in one closed list. */
126
+ export const FIELD_PALETTE = [
127
+ ...CONTROL_ENTRIES,
128
+ ...SCALAR_ARRAY_ENTRIES,
129
+ { kind: 'container', container: 'record', needs: { ...NO_NEEDS, members: true } },
130
+ { kind: 'container', container: 'record_array', needs: { ...NO_NEEDS, members: true } },
131
+ ];
132
+ /** Whether a field of this shape must state a control at all. */
133
+ export function fieldRequiresControl(primitive, items) {
134
+ return requiresControl(items === undefined ? { primitive } : { primitive, items: { primitive: items } });
135
+ }
136
+ /** Every control hint a field of this shape admits. */
137
+ export function fieldsControls(primitive, items) {
138
+ return controlsFor(items === undefined ? { primitive } : { primitive, items: { primitive: items } });
139
+ }
140
+ //# sourceMappingURL=palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"palette.js","sourceRoot":"","sources":["../../src/schema/palette.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyB,IAAI,GAAG,CAAU;IAC3E,GAAG,qBAAqB;IACxB,GAAG,gBAAgB;CACpB,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,iBAAiB,GAAG;IACxB,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,OAAO;IACP,UAAU;IACV,UAAU;IACV,MAAM;IACN,SAAS;IACT,MAAM;IACN,WAAW;IACX,eAAe;IACf,UAAU;IACV,SAAS;IACT,YAAY;CACiC,CAAC;AAEhD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,kBAAkB,GAA+B,IAAI,GAAG,CAAC;IACpE,QAAQ;IACR,SAAS;IACT,UAAU;CACX,CAAC,CAAC;AAyBH,uEAAuE;AACvE,MAAM,QAAQ,GAAiB;IAC7B,OAAO,EAAE,KA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E,EAAE;CACxF,CAAC;AAEF,iEAAiE;AACjE,MAAM,UAAU,oBAAoB,CAClC,SAAoB,EACpB,KAAgC;IAEhC,OAAO,eAAe,CACpB,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CACjF,CAAC;AACJ,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,cAAc,CAC5B,SAAoB,EACpB,KAAgC;IAEhC,OAAO,WAAW,CAChB,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CACjF,CAAC;AACJ,CAAC","sourcesContent":["import {\n CHOOSER_CONTROLS,\n CONTROLS_BY_PRIMITIVE,\n OPTION_BOUND_CONTROLS,\n controlsFor,\n requiresControl,\n} from '@azx-pbc/axiom-compiler';\nimport { ITEM_PRIMITIVES } from '@azx-pbc/axiom-runtime';\nimport type { Control, DurationUnit, ItemPrimitive, Primitive } from '@azx-pbc/axiom-runtime';\nimport type { ScalarPrimitive } from './document.js';\n\n/**\n * The field palette: every declaration an author may add, derived from the compiler's control\n * matrix rather than restated.\n *\n * A palette row is what a builder UI offers as a new field. A scalar row is one\n * `(primitive, control)` pair the matrix pairs — `.text` on `string`, `.rating` on `integer` —\n * and a container row is a repeating structure, which is a declaration and not a control: a\n * `record` has no control and the palette does not invent one. A scalar array is a third kind\n * because its `items` declaration is what makes `multiselect`, `rank` and `tags` mean anything.\n *\n * `CONTROLS_BY_PRIMITIVE` is the one authority for the pairing; `FIELD_PALETTE` is a view of it.\n * A control added to the matrix appears here without an edit, and a primitive the matrix gives\n * no controls renders no scalar row.\n *\n * A row is a *declaration shape*, not a whole command: a rating reads its point count from an\n * option domain, a money declaration needs a currency and a scale, an array needs a row identity\n * or a domain, and a container needs members. `needs` states exactly which of those the row\n * cannot supply itself, so a UI can build a complete `addField` (or `addRecordArray`) from the\n * row instead of discovering the missing member from a refusal.\n */\n\n/**\n * The controls that draw their content from a declared option domain.\n *\n * A rating and a Likert scale read their point count from it, and a chooser offers one of its\n * values; a field with one of these controls and no `options`/`optionSource` renders a control\n * with nothing in it. The compiler states both halves (`OPTION_BOUND_CONTROLS` and\n * `CHOOSER_CONTROLS`), so this is a union of its sets rather than a mirror of them.\n */\nexport const OPTION_DOMAIN_CONTROLS: ReadonlySet<Control> = new Set<Control>([\n ...OPTION_BOUND_CONTROLS,\n ...CHOOSER_CONTROLS,\n]);\n\n/** The primitives a field, rather than a container, may declare. */\nconst SCALAR_PRIMITIVES = [\n 'string',\n 'boolean',\n 'integer',\n 'decimal',\n 'money',\n 'quantity',\n 'duration',\n 'date',\n 'instant',\n 'time',\n 'media_ref',\n 'signature_ref',\n 'timeslot',\n 'address',\n 'coordinate',\n] as const satisfies readonly ScalarPrimitive[];\n\n/** The item primitives whose rows a declared option domain identifies. */\nexport const OPTION_ARRAY_ITEMS: ReadonlySet<ItemPrimitive> = new Set([\n 'string',\n 'integer',\n 'duration',\n]);\n\n/**\n * What a palette row cannot state on its own.\n *\n * A row names a shape; the command that authors it must also carry these members, because the\n * closed metaschema requires them for that shape. Every row states all five, so a caller can\n * read the answer without knowing which control or primitive it is looking at.\n */\nexport interface PaletteNeeds {\n /** An option domain: the control draws its scale or its list from the codes. */\n readonly options: boolean;\n /** A `currency` and a `scale`: the declaration holds money. */\n readonly moneyDomain: boolean;\n /** A row identity: the array's rows are freeform values rather than an option domain. */\n readonly rowKey: boolean;\n /** At least one member: the declaration is a container. */\n readonly members: boolean;\n /**\n * A `covers` list: the declaration is a signature capture, and the fields its signature\n * binds are other declarations a row cannot name.\n */\n readonly covers: boolean;\n}\n\n/** The common case: a row that states everything its command needs. */\nconst NO_NEEDS: PaletteNeeds = {\n options: false,\n moneyDomain: false,\n rowKey: false,\n members: false,\n covers: false,\n};\n\n/**\n * The declaration members a row states itself, in the command's own vocabulary.\n *\n * They are the members a shape carries wherever it is authored — a slider's range and its\n * sentences, a duration's unit, a quantity's unit domain — rather than choices the author makes\n * per instance. A row states them so a UI can build the whole `addField` from the row, and the\n * slider's defaults are the ordinary 0–100 track: the author edits the range afterwards with\n * `setFieldDeclaration`.\n */\nexport interface PaletteDeclaration {\n /** A slider's two bounds, `MODEL-2.1.16`; the compiler refuses a slider without both. */\n readonly minimum?: number | string;\n readonly maximum?: number | string;\n /** The sentence each bound raises; the store mints `field.<trail>.minimum`/`.maximum`. */\n readonly minimumMessage?: string;\n readonly maximumMessage?: string;\n /** A number control's increment, `MODEL-2.1.16`. */\n readonly step?: number | string;\n /** A `quantity` declaration's unit domain, `MODEL-2.1.21`. */\n readonly units?: readonly string[];\n /** A `duration` declaration's unit, `MODEL-2.1.24`. */\n readonly unit?: DurationUnit;\n}\n\n/** The members a scalar control row states itself, or `undefined` when it states everything. */\nfunction controlDeclaration(\n primitive: ScalarPrimitive,\n control: Control,\n): PaletteDeclaration | undefined {\n if (control === 'slider') {\n return {\n minimum: 0,\n maximum: 100,\n minimumMessage: 'Must be at least 0',\n maximumMessage: 'Must be at most 100',\n step: primitive === 'integer' ? 1 : '0.1',\n };\n }\n if (primitive === 'quantity') return { units: ['each'] };\n if (primitive === 'duration') return { unit: 'minutes' };\n return undefined;\n}\n\n/** The members a scalar array row states itself, or `undefined` when it states everything. */\nfunction itemDeclaration(item: ItemPrimitive): PaletteDeclaration | undefined {\n if (item === 'quantity') return { units: ['each'] };\n if (item === 'duration') return { unit: 'minutes' };\n return undefined;\n}\n\n/** One palette row: a scalar control, a scalar array, or a container declaration. */\nexport type FieldPaletteEntry =\n | {\n readonly kind: 'control';\n readonly primitive: ScalarPrimitive;\n readonly control: Control;\n readonly needs: PaletteNeeds;\n readonly declaration?: PaletteDeclaration;\n }\n | {\n readonly kind: 'scalar_array';\n readonly item: ItemPrimitive;\n readonly control: Control;\n readonly needs: PaletteNeeds;\n readonly declaration?: PaletteDeclaration;\n }\n | {\n readonly kind: 'container';\n readonly container: 'record' | 'record_array';\n readonly needs: PaletteNeeds;\n };\n\nconst CONTROL_ENTRIES: readonly FieldPaletteEntry[] = SCALAR_PRIMITIVES.flatMap((primitive) =>\n CONTROLS_BY_PRIMITIVE[primitive].map((control): FieldPaletteEntry => {\n const declaration = controlDeclaration(primitive, control);\n return {\n kind: 'control',\n primitive,\n control,\n needs: {\n ...NO_NEEDS,\n options: OPTION_DOMAIN_CONTROLS.has(control),\n moneyDomain: primitive === 'money',\n covers: control === 'signature_capture',\n },\n ...(declaration === undefined ? {} : { declaration }),\n };\n }),\n);\n\nconst SCALAR_ARRAY_ENTRIES: readonly FieldPaletteEntry[] = ITEM_PRIMITIVES.flatMap((item) =>\n CONTROLS_BY_PRIMITIVE.array.map((control): FieldPaletteEntry => {\n const declaration = itemDeclaration(item);\n return {\n kind: 'scalar_array',\n item,\n control,\n needs: {\n ...NO_NEEDS,\n // A string, integer or duration domain identifies its rows by their values; every\n // other item primitive has no option domain the metaschema admits, so the array states\n // a row key.\n options: OPTION_ARRAY_ITEMS.has(item),\n moneyDomain: item === 'money',\n rowKey: !OPTION_ARRAY_ITEMS.has(item),\n },\n ...(declaration === undefined ? {} : { declaration }),\n };\n }),\n);\n\n/** Every value a builder UI may offer, in one closed list. */\nexport const FIELD_PALETTE: readonly FieldPaletteEntry[] = [\n ...CONTROL_ENTRIES,\n ...SCALAR_ARRAY_ENTRIES,\n { kind: 'container', container: 'record', needs: { ...NO_NEEDS, members: true } },\n { kind: 'container', container: 'record_array', needs: { ...NO_NEEDS, members: true } },\n];\n\n/** Whether a field of this shape must state a control at all. */\nexport function fieldRequiresControl(\n primitive: Primitive,\n items: ItemPrimitive | undefined,\n): boolean {\n return requiresControl(\n items === undefined ? { primitive } : { primitive, items: { primitive: items } },\n );\n}\n\n/** Every control hint a field of this shape admits. */\nexport function fieldsControls(\n primitive: Primitive,\n items: ItemPrimitive | undefined,\n): readonly Control[] {\n return controlsFor(\n items === undefined ? { primitive } : { primitive, items: { primitive: items } },\n );\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import type { AuthoringDocument } from './document.js';
2
+ import type { AuthoringRefusal } from '../store/refusals.js';
3
+ /**
4
+ * The one door a host-loaded draft comes through.
5
+ *
6
+ * A stored draft, a fixture on disk and a value from another process all arrive as `unknown`.
7
+ * This reads one into the authoring document or states why it is not one, so no caller has to
8
+ * assert the type of a value it did not build — the failure a cast hides until a document reaches
9
+ * a walker that assumes a member the file never stated.
10
+ *
11
+ * Validity is the closed metaschema's, not a second grammar: `closedShapeErrors` is the stage
12
+ * `compile()` itself runs, so a draft this reader refuses is one the compiler refuses, at the same
13
+ * location and in the same words. What this module adds is the narrowing — the metaschema proves
14
+ * the shape and the walk below turns the validated tree into the declared document types. A member
15
+ * the metaschema admits and this walk cannot read is a disagreement between the contract and its
16
+ * reader, which is a defect here rather than an authoring mistake, so it throws rather than
17
+ * reporting a refusal no author could act on.
18
+ *
19
+ * Two slots are narrower than the metaschema because they are the *authored* form of a value the
20
+ * compiler also accepts already parsed: an `expr` may be source text or the closed AST, and a
21
+ * catalogue entry may be source text or a compiled message AST. A draft carries the text an author
22
+ * writes, so a document holding the parsed form is refused with the repair an author has.
23
+ */
24
+ /** One host-loaded value, read as a draft document or refused. */
25
+ export type DocumentRead = {
26
+ readonly ok: true;
27
+ readonly document: AuthoringDocument;
28
+ } | {
29
+ readonly ok: false;
30
+ readonly refusal: AuthoringRefusal;
31
+ };
32
+ /**
33
+ * Reads a host-loaded value as a draft document, or explains why it is not one.
34
+ *
35
+ * The runtime's restricted-profile reader first copies the host value onto a plain tree without
36
+ * invoking its accessors, refusing what canonical JSON cannot carry (negative zero, an accessor, a
37
+ * cycle or excessive nesting). The closed metaschema then answers over that data, so its refusal is
38
+ * the compiler's own — the failing keyword, the document path and the detail an author repairs.
39
+ * Only that plain tree reaches the narrowing, so a caller holds a document of the declared type
40
+ * rather than a checked `unknown`, which is what keeps every later authoring entry free of casts.
41
+ *
42
+ * One closed-shape reason is admitted rather than refused: the document-level `fields` `minItems`.
43
+ * `createEmptySchema` starts a draft with no declarations — that is the state the store opens on,
44
+ * and its first diagnostics already say it is not a compilable schema — so a draft a host saved
45
+ * before adding its first field has to load back as the document it was saved from. Every other
46
+ * reason, including an empty member list on a record, stays the metaschema's.
47
+ */
48
+ export declare function readDocument(value: unknown): DocumentRead;
49
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/schema/read.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAKV,iBAAiB,EAclB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,kEAAkE;AAClE,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAu4B/D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CA2BzD"}