@azx-pbc/axiom-form-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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -2
  3. package/dist/bridge/index.d.ts +12 -0
  4. package/dist/bridge/index.d.ts.map +1 -0
  5. package/dist/bridge/index.js +10 -0
  6. package/dist/bridge/index.js.map +1 -0
  7. package/dist/bridge/inspector-commands.d.ts +55 -0
  8. package/dist/bridge/inspector-commands.d.ts.map +1 -0
  9. package/dist/bridge/inspector-commands.js +532 -0
  10. package/dist/bridge/inspector-commands.js.map +1 -0
  11. package/dist/bridge/rule-context.d.ts +57 -0
  12. package/dist/bridge/rule-context.d.ts.map +1 -0
  13. package/dist/bridge/rule-context.js +302 -0
  14. package/dist/bridge/rule-context.js.map +1 -0
  15. package/dist/index.d.ts +32 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +28 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/inspector.d.ts +125 -0
  20. package/dist/inspector.d.ts.map +1 -0
  21. package/dist/inspector.js +2 -0
  22. package/dist/inspector.js.map +1 -0
  23. package/dist/reference/ReferencePicker.d.ts +59 -0
  24. package/dist/reference/ReferencePicker.d.ts.map +1 -0
  25. package/dist/reference/ReferencePicker.js +145 -0
  26. package/dist/reference/ReferencePicker.js.map +1 -0
  27. package/dist/reference/index.d.ts +13 -0
  28. package/dist/reference/index.d.ts.map +1 -0
  29. package/dist/reference/index.js +11 -0
  30. package/dist/reference/index.js.map +1 -0
  31. package/dist/reference/token.d.ts +44 -0
  32. package/dist/reference/token.d.ts.map +1 -0
  33. package/dist/reference/token.js +141 -0
  34. package/dist/reference/token.js.map +1 -0
  35. package/dist/reference/types.d.ts +49 -0
  36. package/dist/reference/types.d.ts.map +1 -0
  37. package/dist/reference/types.js +2 -0
  38. package/dist/reference/types.js.map +1 -0
  39. package/dist/rules/ConditionEditor.d.ts +38 -0
  40. package/dist/rules/ConditionEditor.d.ts.map +1 -0
  41. package/dist/rules/ConditionEditor.js +79 -0
  42. package/dist/rules/ConditionEditor.js.map +1 -0
  43. package/dist/rules/RuleBuilder.d.ts +76 -0
  44. package/dist/rules/RuleBuilder.d.ts.map +1 -0
  45. package/dist/rules/RuleBuilder.js +336 -0
  46. package/dist/rules/RuleBuilder.js.map +1 -0
  47. package/dist/rules/RuleList.d.ts +45 -0
  48. package/dist/rules/RuleList.d.ts.map +1 -0
  49. package/dist/rules/RuleList.js +62 -0
  50. package/dist/rules/RuleList.js.map +1 -0
  51. package/dist/rules/RuleMessageEditor.d.ts +38 -0
  52. package/dist/rules/RuleMessageEditor.d.ts.map +1 -0
  53. package/dist/rules/RuleMessageEditor.js +38 -0
  54. package/dist/rules/RuleMessageEditor.js.map +1 -0
  55. package/dist/rules/ValidationEditor.d.ts +60 -0
  56. package/dist/rules/ValidationEditor.d.ts.map +1 -0
  57. package/dist/rules/ValidationEditor.js +299 -0
  58. package/dist/rules/ValidationEditor.js.map +1 -0
  59. package/dist/rules/condition.d.ts +12 -0
  60. package/dist/rules/condition.d.ts.map +1 -0
  61. package/dist/rules/condition.js +46 -0
  62. package/dist/rules/condition.js.map +1 -0
  63. package/dist/rules/expression.d.ts +57 -0
  64. package/dist/rules/expression.d.ts.map +1 -0
  65. package/dist/rules/expression.js +286 -0
  66. package/dist/rules/expression.js.map +1 -0
  67. package/dist/rules/index.d.ts +28 -0
  68. package/dist/rules/index.d.ts.map +1 -0
  69. package/dist/rules/index.js +19 -0
  70. package/dist/rules/index.js.map +1 -0
  71. package/dist/rules/messages.d.ts +64 -0
  72. package/dist/rules/messages.d.ts.map +1 -0
  73. package/dist/rules/messages.js +114 -0
  74. package/dist/rules/messages.js.map +1 -0
  75. package/dist/rules/operators.d.ts +25 -0
  76. package/dist/rules/operators.d.ts.map +1 -0
  77. package/dist/rules/operators.js +128 -0
  78. package/dist/rules/operators.js.map +1 -0
  79. package/dist/rules/sentence.d.ts +151 -0
  80. package/dist/rules/sentence.d.ts.map +1 -0
  81. package/dist/rules/sentence.js +527 -0
  82. package/dist/rules/sentence.js.map +1 -0
  83. package/dist/rules/templates.d.ts +163 -0
  84. package/dist/rules/templates.d.ts.map +1 -0
  85. package/dist/rules/templates.js +560 -0
  86. package/dist/rules/templates.js.map +1 -0
  87. package/dist/rules/types.d.ts +209 -0
  88. package/dist/rules/types.d.ts.map +1 -0
  89. package/dist/rules/types.js +2 -0
  90. package/dist/rules/types.js.map +1 -0
  91. package/dist/rules/validation-editor-api.d.ts +12 -0
  92. package/dist/rules/validation-editor-api.d.ts.map +1 -0
  93. package/dist/rules/validation-editor-api.js +12 -0
  94. package/dist/rules/validation-editor-api.js.map +1 -0
  95. package/dist/rules/validation.d.ts +27 -0
  96. package/dist/rules/validation.d.ts.map +1 -0
  97. package/dist/rules/validation.js +184 -0
  98. package/dist/rules/validation.js.map +1 -0
  99. package/dist/styles.css +900 -0
  100. package/package.json +65 -3
@@ -0,0 +1,57 @@
1
+ import type { AuthoringCommand, AuthoringDocument } from '@azx-pbc/axiom-builder';
2
+ import type { EmittedRule } from '../rules/templates.js';
3
+ import type { ReadableRule, RuleContext } from '../rules/types.js';
4
+ /** Optional localisation overrides for `ruleContextOf`. */
5
+ export interface RuleContextOptions {
6
+ /** Fallback label for a layout section that declares no title text. */
7
+ readonly defaultSectionLabel?: string | undefined;
8
+ /** Fallback label for a wizard step that declares no title text. */
9
+ readonly defaultStepLabel?: string | undefined;
10
+ }
11
+ /** Optional multi-locale translation settings for `commandsForRule`. */
12
+ export interface RuleCommandOptions {
13
+ /**
14
+ * Additional locale texts to write after the rule is added, keyed by canonical locale tag.
15
+ *
16
+ * `addRule` mints the rule's message key (and any gate item's key) in the document's default
17
+ * locale. Supplying `translations` appends one `setMessageText` command per non-empty locale
18
+ * entry so a host can commit a rule and its translations in one sequence.
19
+ */
20
+ readonly translations?: Readonly<Record<string, string>> | undefined;
21
+ /**
22
+ * The locale `message` was written in; skipped from `translations` so the default text is not
23
+ * written twice when the caller passes a full locale map.
24
+ */
25
+ readonly defaultLocale?: string | undefined;
26
+ }
27
+ /** The descriptor set the rule, condition, and validation editors build their sentences from. */
28
+ export declare function ruleContextOf(document: AuthoringDocument, locale: string, options?: RuleContextOptions): RuleContext;
29
+ /** Every declared rule as `RuleList` renders it, with the message key it resolves to. */
30
+ export declare function readableRulesOf(document: AuthoringDocument): readonly ReadableRule[];
31
+ /**
32
+ * A stable rule id for one page's capability restriction, inside the 64-character identifier
33
+ * grammar.
34
+ *
35
+ * Section and step ids may carry dots (`layout.section.window`), mixed case, or exceed the
36
+ * identifier ceiling. Whenever sanitization changes the raw id or the prefixed id would exceed
37
+ * the ceiling, an 8-hex-char deterministic FNV-1a suffix is appended so distinct ids such as
38
+ * `layout.section.window` and `layout_section_window` can never collide.
39
+ */
40
+ export declare function capabilityRuleId(sectionId: string): string;
41
+ /**
42
+ * A rule id no declared rule holds, from the base the caller names.
43
+ *
44
+ * `addRule` refuses a duplicate id rather than renumbering it, and the message key is minted from
45
+ * the id, so two checks added after one has been removed must still get two distinct ids.
46
+ */
47
+ export declare function freshRuleId(document: AuthoringDocument, base: string): string;
48
+ /**
49
+ * The command sequence a committed `EmittedRule` becomes.
50
+ *
51
+ * `RuleBuilder` hands back an `EmittedRule` whose expression is canonical Expr v1 source.
52
+ * `addRule` mints the message key from the rule id in the document's default locale, so this
53
+ * mapping sends `message` text rather than `messageKey`. When `options.translations` is supplied,
54
+ * a `setMessageText` command is appended for each non-empty additional locale.
55
+ */
56
+ export declare function commandsForRule(rule: EmittedRule, message: string, options?: RuleCommandOptions): readonly [AuthoringCommand, ...AuthoringCommand[]];
57
+ //# sourceMappingURL=rule-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-context.d.ts","sourceRoot":"","sources":["../../src/bridge/rule-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAGlB,MAAM,wBAA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**
2
+ * Pure, stateless document-bridge helpers connecting `@azx-pbc/axiom-builder` documents to the
3
+ * controlled authoring surfaces in `@azx-pbc/axiom-form-builder`.
4
+ *
5
+ * The surfaces are store-free: they read `RuleContext`/`ReadableRule` descriptors and emit
6
+ * `EmittedRule` values. These helpers project an `AuthoringDocument` into those descriptors,
7
+ * allocate collision-free rule identifiers, and map an emitted rule to `AuthoringCommand` steps.
8
+ */
9
+ const IDENTIFIER_MAX_LENGTH = 64;
10
+ const CAPABILITY_RULE_PREFIX = 'r_cap_';
11
+ /** Narrows an unknown layout node to a plain object record without casting. */
12
+ function isRecord(value) {
13
+ return typeof value === 'object' && value !== null;
14
+ }
15
+ /** The document's fallback locale when the requested locale has no entry. */
16
+ function fallbackLocaleOf(document) {
17
+ return document.defaultLocale ?? document.locales?.[0];
18
+ }
19
+ /** One catalogue entry looked up as an own property so prototype names never resolve. */
20
+ function messageEntryOf(document, key) {
21
+ return Object.hasOwn(document.messages, key) ? document.messages[key] : undefined;
22
+ }
23
+ /** One locale text looked up as an own property of a catalogue entry. */
24
+ function localeTextOf(entry, locale) {
25
+ if (entry === undefined || locale === undefined)
26
+ return undefined;
27
+ return Object.hasOwn(entry, locale) ? entry[locale] : undefined;
28
+ }
29
+ /** The text of one message key in `locale`, falling back to the document's default. */
30
+ function textOf(document, key, locale) {
31
+ if (key === undefined)
32
+ return '';
33
+ const entry = messageEntryOf(document, key);
34
+ return localeTextOf(entry, locale) ?? localeTextOf(entry, fallbackLocaleOf(document)) ?? key;
35
+ }
36
+ /** One declaration as the rule editors name it, with its members for an array of rows. */
37
+ function ruleFieldOf(document, field, locale) {
38
+ return {
39
+ fieldId: field.fieldId,
40
+ label: textOf(document, field.labelKey, locale),
41
+ primitive: field.primitive,
42
+ ...(field.currency === undefined ? {} : { currency: field.currency }),
43
+ ...(field.scale === undefined ? {} : { scale: field.scale }),
44
+ ...(field.items === undefined ? {} : { itemPrimitive: field.items.primitive }),
45
+ ...(field.options === undefined
46
+ ? {}
47
+ : { optionCodes: field.options.map((option) => String(option.code)) }),
48
+ ...(field.fields === undefined
49
+ ? {}
50
+ : {
51
+ columns: field.fields.map((member) => ({
52
+ fieldId: member.fieldId,
53
+ label: textOf(document, member.labelKey, locale),
54
+ primitive: member.primitive,
55
+ ...(member.currency === undefined ? {} : { currency: member.currency }),
56
+ ...(member.scale === undefined ? {} : { scale: member.scale }),
57
+ })),
58
+ }),
59
+ };
60
+ }
61
+ /** Every declared field id, including the members nested inside a table's rows. */
62
+ function declaredIds(document) {
63
+ const ids = new Set();
64
+ const visit = (fields) => {
65
+ for (const field of fields) {
66
+ ids.add(field.fieldId);
67
+ if (field.fields !== undefined)
68
+ visit(field.fields);
69
+ }
70
+ };
71
+ visit(document.fields);
72
+ return ids;
73
+ }
74
+ /** Every declared field id inside one section's subtree, in document order. */
75
+ function fieldsUnder(document, nodes) {
76
+ // The walk is generic over every container kind: a group, a wizard and a step all hold their
77
+ // rows in `children`, so a page whose questions sit inside a group reports those questions.
78
+ // The filter reads the flattened declaration set rather than the top-level list, so a table's
79
+ // nested members count as fields the section holds instead of vanishing from it.
80
+ const declared = declaredIds(document);
81
+ const found = [];
82
+ const visit = (entries) => {
83
+ for (const entry of entries) {
84
+ if (!isRecord(entry))
85
+ continue;
86
+ const fieldId = entry['fieldId'];
87
+ if (typeof fieldId === 'string')
88
+ found.push(fieldId);
89
+ const children = entry['children'];
90
+ if (Array.isArray(children))
91
+ visit(children);
92
+ }
93
+ };
94
+ visit(nodes);
95
+ return found.filter((id) => declared.has(id));
96
+ }
97
+ /** Every section or wizard step of the layout, with the fields it holds, so a rule can target it. */
98
+ function sectionsOf(document, locale, options) {
99
+ const defaultSectionLabel = options?.defaultSectionLabel ?? 'Section';
100
+ const defaultStepLabel = options?.defaultStepLabel ?? 'Page';
101
+ const found = [];
102
+ const visit = (nodes) => {
103
+ for (const entry of nodes) {
104
+ if (!isRecord(entry))
105
+ continue;
106
+ const kind = entry['kind'];
107
+ const key = entry['titleKey'];
108
+ const children = entry['children'];
109
+ if ((kind === 'section' || kind === 'step') && Array.isArray(children)) {
110
+ const titleKey = typeof key === 'string' ? key : undefined;
111
+ // A wizard step is the page an author restricts, so it is a target beside a section.
112
+ const id = entry[kind === 'step' ? 'stepId' : 'sectionId'];
113
+ found.push({
114
+ sectionId: typeof id === 'string' ? id : (titleKey ?? kind),
115
+ label: textOf(document, titleKey, locale) ||
116
+ (kind === 'step' ? defaultStepLabel : defaultSectionLabel),
117
+ fieldIds: fieldsUnder(document, children),
118
+ });
119
+ }
120
+ if (Array.isArray(children))
121
+ visit(children);
122
+ }
123
+ };
124
+ visit(document.layout);
125
+ return found;
126
+ }
127
+ /** The descriptor set the rule, condition, and validation editors build their sentences from. */
128
+ export function ruleContextOf(document, locale, options) {
129
+ return {
130
+ fields: document.fields.map((field) => ruleFieldOf(document, field, locale)),
131
+ sections: sectionsOf(document, locale, options),
132
+ };
133
+ }
134
+ /** Every declared rule as `RuleList` renders it, with the message key it resolves to. */
135
+ export function readableRulesOf(document) {
136
+ return (document.rules ?? []).map((rule) => ({
137
+ ruleId: rule.ruleId,
138
+ kind: rule.kind,
139
+ scope: rule.scope,
140
+ expr: rule.expr,
141
+ ...(rule.fieldId === undefined ? {} : { fieldId: rule.fieldId }),
142
+ ...(rule.fieldIds === undefined ? {} : { fieldIds: rule.fieldIds }),
143
+ ...(rule.messageKey === undefined ? {} : { messageKey: rule.messageKey }),
144
+ ...(rule.severity === undefined ? {} : { severity: rule.severity }),
145
+ ...(rule.gate === undefined
146
+ ? {}
147
+ : {
148
+ gate: {
149
+ hard: rule.gate.hard,
150
+ ...(rule.gate.activeWhen === undefined ? {} : { activeWhen: rule.gate.activeWhen }),
151
+ items: rule.gate.items.map((item) => ({
152
+ itemId: item.itemId,
153
+ messageKey: item.messageKey,
154
+ expr: item.expr,
155
+ })),
156
+ },
157
+ }),
158
+ }));
159
+ }
160
+ /** Deterministic 32-bit FNV-1a digest as 8 lower-case hex characters, with zero crypto imports. */
161
+ function fnv1aHex(input) {
162
+ let hash = 0x811c9dc5;
163
+ for (let index = 0; index < input.length; index += 1) {
164
+ hash ^= input.charCodeAt(index);
165
+ hash = Math.imul(hash, 0x01000193);
166
+ }
167
+ return (hash >>> 0).toString(16).padStart(8, '0');
168
+ }
169
+ /**
170
+ * A stable rule id for one page's capability restriction, inside the 64-character identifier
171
+ * grammar.
172
+ *
173
+ * Section and step ids may carry dots (`layout.section.window`), mixed case, or exceed the
174
+ * identifier ceiling. Whenever sanitization changes the raw id or the prefixed id would exceed
175
+ * the ceiling, an 8-hex-char deterministic FNV-1a suffix is appended so distinct ids such as
176
+ * `layout.section.window` and `layout_section_window` can never collide.
177
+ */
178
+ export function capabilityRuleId(sectionId) {
179
+ const sanitized = sectionId
180
+ .toLowerCase()
181
+ .replace(/[^a-z0-9_]+/gu, '_')
182
+ .replace(/^_+|_+$/gu, '');
183
+ const stem = sanitized === '' ? 'page' : sanitized;
184
+ const direct = `${CAPABILITY_RULE_PREFIX}${stem}`;
185
+ if (sanitized === sectionId && stem === sectionId && direct.length <= IDENTIFIER_MAX_LENGTH) {
186
+ return direct;
187
+ }
188
+ const digest = fnv1aHex(sectionId);
189
+ const maxStem = IDENTIFIER_MAX_LENGTH - CAPABILITY_RULE_PREFIX.length - digest.length - 1;
190
+ const truncated = stem.slice(0, maxStem).replace(/_+$/gu, '') || 'page';
191
+ return `${CAPABILITY_RULE_PREFIX}${truncated}_${digest}`;
192
+ }
193
+ /**
194
+ * A rule id no declared rule holds, from the base the caller names.
195
+ *
196
+ * `addRule` refuses a duplicate id rather than renumbering it, and the message key is minted from
197
+ * the id, so two checks added after one has been removed must still get two distinct ids.
198
+ */
199
+ export function freshRuleId(document, base) {
200
+ const declared = new Set((document.rules ?? []).map((rule) => rule.ruleId));
201
+ const stem = base.slice(0, IDENTIFIER_MAX_LENGTH);
202
+ if (!declared.has(stem))
203
+ return stem;
204
+ for (let suffix = 2;; suffix += 1) {
205
+ const tail = `_${String(suffix)}`;
206
+ const prefix = stem.slice(0, Math.max(1, IDENTIFIER_MAX_LENGTH - tail.length));
207
+ const candidate = `${prefix}${tail}`;
208
+ if (!declared.has(candidate))
209
+ return candidate;
210
+ }
211
+ }
212
+ /** Maps all emitted gate items into the non-empty tuple `addRule` requires. */
213
+ function mappedGateItems(ruleId, gate, message) {
214
+ const [first, ...rest] = gate.items;
215
+ if (first === undefined) {
216
+ // A gate declares at least one item, which is the shape the union states; a gate
217
+ // without one is not a document the metaschema admits.
218
+ const stem = ruleId.slice(0, IDENTIFIER_MAX_LENGTH - 5).replace(/_+$/u, '') || 'r';
219
+ return [
220
+ {
221
+ itemId: `${stem}_item`,
222
+ message,
223
+ expression: { mode: 'advanced', source: 'true' },
224
+ },
225
+ ];
226
+ }
227
+ const toSpec = (item) => ({
228
+ itemId: item.itemId,
229
+ message,
230
+ expression: { mode: 'advanced', source: item.expr },
231
+ });
232
+ return [toSpec(first), ...rest.map(toSpec)];
233
+ }
234
+ /**
235
+ * The command sequence a committed `EmittedRule` becomes.
236
+ *
237
+ * `RuleBuilder` hands back an `EmittedRule` whose expression is canonical Expr v1 source.
238
+ * `addRule` mints the message key from the rule id in the document's default locale, so this
239
+ * mapping sends `message` text rather than `messageKey`. When `options.translations` is supplied,
240
+ * a `setMessageText` command is appended for each non-empty additional locale.
241
+ */
242
+ export function commandsForRule(rule, message, options) {
243
+ const ruleId = rule.ruleId ?? `r_${rule.kind}`;
244
+ const gateItems = rule.gate === undefined ? undefined : mappedGateItems(ruleId, rule.gate, message);
245
+ const hasRuleMessage = rule.messageKey !== undefined ||
246
+ rule.kind === 'validate' ||
247
+ rule.kind === 'gate' ||
248
+ rule.kind === 'screen';
249
+ const addRule = {
250
+ kind: 'addRule',
251
+ rule: {
252
+ ruleId,
253
+ kind: rule.kind,
254
+ scope: rule.scope,
255
+ expression: { mode: 'advanced', source: rule.expr },
256
+ ...(rule.severity === undefined ? {} : { severity: rule.severity }),
257
+ ...(rule.fieldId === undefined ? {} : { fieldId: rule.fieldId }),
258
+ ...(rule.fieldIds === undefined ? {} : { fieldIds: rule.fieldIds }),
259
+ ...(rule.gate === undefined || gateItems === undefined
260
+ ? {}
261
+ : {
262
+ gate: {
263
+ hard: rule.gate.hard,
264
+ items: gateItems,
265
+ ...(rule.gate.activeWhen === undefined
266
+ ? {}
267
+ : { activeWhen: { mode: 'advanced', source: rule.gate.activeWhen } }),
268
+ },
269
+ }),
270
+ ...(hasRuleMessage ? { message } : {}),
271
+ },
272
+ };
273
+ if (options?.translations === undefined) {
274
+ return [addRule];
275
+ }
276
+ const extra = [];
277
+ for (const [entryLocale, entryText] of Object.entries(options.translations)) {
278
+ const trimmed = entryText.trim();
279
+ if (entryLocale === options.defaultLocale || trimmed === '')
280
+ continue;
281
+ if (hasRuleMessage) {
282
+ extra.push({
283
+ kind: 'setMessageText',
284
+ messageKey: `rule.${ruleId}`,
285
+ locale: entryLocale,
286
+ text: trimmed,
287
+ });
288
+ }
289
+ if (gateItems !== undefined) {
290
+ for (const item of gateItems) {
291
+ extra.push({
292
+ kind: 'setMessageText',
293
+ messageKey: `gate.${ruleId}.${item.itemId}`,
294
+ locale: entryLocale,
295
+ text: trimmed,
296
+ });
297
+ }
298
+ }
299
+ }
300
+ return [addRule, ...extra];
301
+ }
302
+ //# sourceMappingURL=rule-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-context.js","sourceRoot":"","sources":["../../src/bridge/rule-context.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AAEH,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AA2BxC,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,6EAA6E;AAC7E,SAAS,gBAAgB,CAAC,QAA2B;IACnD,OAAO,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,OAAO,EAAE,CAA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AM,EAAE;gBAC5B,MAAM,EAAE,WAAW;gBACnB,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;QACL,CAAC;QACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;gBAC7B,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE,gBAAgB;oBACtB,UAAU,EAAE,QAAQ,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE;oBAC3C,MAAM,EAAE,WAAW;oBACnB,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import type {\n AuthoringCommand,\n AuthoringDocument,\n AuthoringField,\n GateItemSpec,\n} from '@azx-pbc/axiom-builder';\nimport type { EmittedRule } from '../rules/templates.js';\nimport type { ReadableRule, RuleContext, RuleField, RuleSection } from '../rules/types.js';\n\n/**\n * Pure, stateless document-bridge helpers connecting `@azx-pbc/axiom-builder` documents to the\n * controlled authoring surfaces in `@azx-pbc/axiom-form-builder`.\n *\n * The surfaces are store-free: they read `RuleContext`/`ReadableRule` descriptors and emit\n * `EmittedRule` values. These helpers project an `AuthoringDocument` into those descriptors,\n * allocate collision-free rule identifiers, and map an emitted rule to `AuthoringCommand` steps.\n */\n\nconst IDENTIFIER_MAX_LENGTH = 64;\nconst CAPABILITY_RULE_PREFIX = 'r_cap_';\n\n/** Optional localisation overrides for `ruleContextOf`. */\nexport interface RuleContextOptions {\n /** Fallback label for a layout section that declares no title text. */\n readonly defaultSectionLabel?: string | undefined;\n /** Fallback label for a wizard step that declares no title text. */\n readonly defaultStepLabel?: string | undefined;\n}\n\n/** Optional multi-locale translation settings for `commandsForRule`. */\nexport interface RuleCommandOptions {\n /**\n * Additional locale texts to write after the rule is added, keyed by canonical locale tag.\n *\n * `addRule` mints the rule's message key (and any gate item's key) in the document's default\n * locale. Supplying `translations` appends one `setMessageText` command per non-empty locale\n * entry so a host can commit a rule and its translations in one sequence.\n */\n readonly translations?: Readonly<Record<string, string>> | undefined;\n /**\n * The locale `message` was written in; skipped from `translations` so the default text is not\n * written twice when the caller passes a full locale map.\n */\n readonly defaultLocale?: string | undefined;\n}\n\n/** Narrows an unknown layout node to a plain object record without casting. */\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null;\n}\n\n/** The document's fallback locale when the requested locale has no entry. */\nfunction fallbackLocaleOf(document: AuthoringDocument): string | undefined {\n return document.defaultLocale ?? document.locales?.[0];\n}\n\n/** One catalogue entry looked up as an own property so prototype names never resolve. */\nfunction messageEntryOf(\n document: AuthoringDocument,\n key: string,\n): Readonly<Record<string, string>> | undefined {\n return Object.hasOwn(document.messages, key) ? document.messages[key] : undefined;\n}\n\n/** One locale text looked up as an own property of a catalogue entry. */\nfunction localeTextOf(\n entry: Readonly<Record<string, string>> | undefined,\n locale: string | undefined,\n): string | undefined {\n if (entry === undefined || locale === undefined) return undefined;\n return Object.hasOwn(entry, locale) ? entry[locale] : undefined;\n}\n\n/** The text of one message key in `locale`, falling back to the document's default. */\nfunction textOf(document: AuthoringDocument, key: string | undefined, locale: string): string {\n if (key === undefined) return '';\n const entry = messageEntryOf(document, key);\n return localeTextOf(entry, locale) ?? localeTextOf(entry, fallbackLocaleOf(document)) ?? key;\n}\n\n/** One declaration as the rule editors name it, with its members for an array of rows. */\nfunction ruleFieldOf(\n document: AuthoringDocument,\n field: AuthoringField,\n locale: string,\n): RuleField {\n return {\n fieldId: field.fieldId,\n label: textOf(document, field.labelKey, locale),\n primitive: field.primitive,\n ...(field.currency === undefined ? {} : { currency: field.currency }),\n ...(field.scale === undefined ? {} : { scale: field.scale }),\n ...(field.items === undefined ? {} : { itemPrimitive: field.items.primitive }),\n ...(field.options === undefined\n ? {}\n : { optionCodes: field.options.map((option) => String(option.code)) }),\n ...(field.fields === undefined\n ? {}\n : {\n columns: field.fields.map((member) => ({\n fieldId: member.fieldId,\n label: textOf(document, member.labelKey, locale),\n primitive: member.primitive,\n ...(member.currency === undefined ? {} : { currency: member.currency }),\n ...(member.scale === undefined ? {} : { scale: member.scale }),\n })),\n }),\n };\n}\n\n/** Every declared field id, including the members nested inside a table's rows. */\nfunction declaredIds(document: AuthoringDocument): ReadonlySet<string> {\n const ids = new Set<string>();\n const visit = (fields: readonly AuthoringField[]): void => {\n for (const field of fields) {\n ids.add(field.fieldId);\n if (field.fields !== undefined) visit(field.fields);\n }\n };\n visit(document.fields);\n return ids;\n}\n\n/** Every declared field id inside one section's subtree, in document order. */\nfunction fieldsUnder(document: AuthoringDocument, nodes: readonly unknown[]): readonly string[] {\n // The walk is generic over every container kind: a group, a wizard and a step all hold their\n // rows in `children`, so a page whose questions sit inside a group reports those questions.\n // The filter reads the flattened declaration set rather than the top-level list, so a table's\n // nested members count as fields the section holds instead of vanishing from it.\n const declared = declaredIds(document);\n const found: string[] = [];\n const visit = (entries: readonly unknown[]): void => {\n for (const entry of entries) {\n if (!isRecord(entry)) continue;\n const fieldId = entry['fieldId'];\n if (typeof fieldId === 'string') found.push(fieldId);\n const children = entry['children'];\n if (Array.isArray(children)) visit(children);\n }\n };\n visit(nodes);\n return found.filter((id) => declared.has(id));\n}\n\n/** Every section or wizard step of the layout, with the fields it holds, so a rule can target it. */\nfunction sectionsOf(\n document: AuthoringDocument,\n locale: string,\n options?: RuleContextOptions,\n): readonly RuleSection[] {\n const defaultSectionLabel = options?.defaultSectionLabel ?? 'Section';\n const defaultStepLabel = options?.defaultStepLabel ?? 'Page';\n const found: RuleSection[] = [];\n const visit = (nodes: readonly unknown[]): void => {\n for (const entry of nodes) {\n if (!isRecord(entry)) continue;\n const kind = entry['kind'];\n const key = entry['titleKey'];\n const children = entry['children'];\n if ((kind === 'section' || kind === 'step') && Array.isArray(children)) {\n const titleKey = typeof key === 'string' ? key : undefined;\n // A wizard step is the page an author restricts, so it is a target beside a section.\n const id = entry[kind === 'step' ? 'stepId' : 'sectionId'];\n found.push({\n sectionId: typeof id === 'string' ? id : (titleKey ?? kind),\n label:\n textOf(document, titleKey, locale) ||\n (kind === 'step' ? defaultStepLabel : defaultSectionLabel),\n fieldIds: fieldsUnder(document, children),\n });\n }\n if (Array.isArray(children)) visit(children);\n }\n };\n visit(document.layout);\n return found;\n}\n\n/** The descriptor set the rule, condition, and validation editors build their sentences from. */\nexport function ruleContextOf(\n document: AuthoringDocument,\n locale: string,\n options?: RuleContextOptions,\n): RuleContext {\n return {\n fields: document.fields.map((field) => ruleFieldOf(document, field, locale)),\n sections: sectionsOf(document, locale, options),\n };\n}\n\n/** Every declared rule as `RuleList` renders it, with the message key it resolves to. */\nexport function readableRulesOf(document: AuthoringDocument): readonly ReadableRule[] {\n return (document.rules ?? []).map((rule) => ({\n ruleId: rule.ruleId,\n kind: rule.kind,\n scope: rule.scope,\n expr: rule.expr,\n ...(rule.fieldId === undefined ? {} : { fieldId: rule.fieldId }),\n ...(rule.fieldIds === undefined ? {} : { fieldIds: rule.fieldIds }),\n ...(rule.messageKey === undefined ? {} : { messageKey: rule.messageKey }),\n ...(rule.severity === undefined ? {} : { severity: rule.severity }),\n ...(rule.gate === undefined\n ? {}\n : {\n gate: {\n hard: rule.gate.hard,\n ...(rule.gate.activeWhen === undefined ? {} : { activeWhen: rule.gate.activeWhen }),\n items: rule.gate.items.map((item) => ({\n itemId: item.itemId,\n messageKey: item.messageKey,\n expr: item.expr,\n })),\n },\n }),\n }));\n}\n\n/** Deterministic 32-bit FNV-1a digest as 8 lower-case hex characters, with zero crypto imports. */\nfunction fnv1aHex(input: string): string {\n let hash = 0x811c9dc5;\n for (let index = 0; index < input.length; index += 1) {\n hash ^= input.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16).padStart(8, '0');\n}\n\n/**\n * A stable rule id for one page's capability restriction, inside the 64-character identifier\n * grammar.\n *\n * Section and step ids may carry dots (`layout.section.window`), mixed case, or exceed the\n * identifier ceiling. Whenever sanitization changes the raw id or the prefixed id would exceed\n * the ceiling, an 8-hex-char deterministic FNV-1a suffix is appended so distinct ids such as\n * `layout.section.window` and `layout_section_window` can never collide.\n */\nexport function capabilityRuleId(sectionId: string): string {\n const sanitized = sectionId\n .toLowerCase()\n .replace(/[^a-z0-9_]+/gu, '_')\n .replace(/^_+|_+$/gu, '');\n const stem = sanitized === '' ? 'page' : sanitized;\n const direct = `${CAPABILITY_RULE_PREFIX}${stem}`;\n if (sanitized === sectionId && stem === sectionId && direct.length <= IDENTIFIER_MAX_LENGTH) {\n return direct;\n }\n const digest = fnv1aHex(sectionId);\n const maxStem = IDENTIFIER_MAX_LENGTH - CAPABILITY_RULE_PREFIX.length - digest.length - 1;\n const truncated = stem.slice(0, maxStem).replace(/_+$/gu, '') || 'page';\n return `${CAPABILITY_RULE_PREFIX}${truncated}_${digest}`;\n}\n\n/**\n * A rule id no declared rule holds, from the base the caller names.\n *\n * `addRule` refuses a duplicate id rather than renumbering it, and the message key is minted from\n * the id, so two checks added after one has been removed must still get two distinct ids.\n */\nexport function freshRuleId(document: AuthoringDocument, base: string): string {\n const declared = new Set((document.rules ?? []).map((rule) => rule.ruleId));\n const stem = base.slice(0, IDENTIFIER_MAX_LENGTH);\n if (!declared.has(stem)) return stem;\n for (let suffix = 2; ; suffix += 1) {\n const tail = `_${String(suffix)}`;\n const prefix = stem.slice(0, Math.max(1, IDENTIFIER_MAX_LENGTH - tail.length));\n const candidate = `${prefix}${tail}`;\n if (!declared.has(candidate)) return candidate;\n }\n}\n\n/** Maps all emitted gate items into the non-empty tuple `addRule` requires. */\nfunction mappedGateItems(\n ruleId: string,\n gate: NonNullable<EmittedRule['gate']>,\n message: string,\n): readonly [GateItemSpec, ...GateItemSpec[]] {\n const [first, ...rest] = gate.items;\n if (first === undefined) {\n // A gate declares at least one item, which is the shape the union states; a gate\n // without one is not a document the metaschema admits.\n const stem = ruleId.slice(0, IDENTIFIER_MAX_LENGTH - 5).replace(/_+$/u, '') || 'r';\n return [\n {\n itemId: `${stem}_item`,\n message,\n expression: { mode: 'advanced', source: 'true' },\n },\n ];\n }\n const toSpec = (item: NonNullable<EmittedRule['gate']>['items'][number]): GateItemSpec => ({\n itemId: item.itemId,\n message,\n expression: { mode: 'advanced', source: item.expr },\n });\n return [toSpec(first), ...rest.map(toSpec)];\n}\n\n/**\n * The command sequence a committed `EmittedRule` becomes.\n *\n * `RuleBuilder` hands back an `EmittedRule` whose expression is canonical Expr v1 source.\n * `addRule` mints the message key from the rule id in the document's default locale, so this\n * mapping sends `message` text rather than `messageKey`. When `options.translations` is supplied,\n * a `setMessageText` command is appended for each non-empty additional locale.\n */\nexport function commandsForRule(\n rule: EmittedRule,\n message: string,\n options?: RuleCommandOptions,\n): readonly [AuthoringCommand, ...AuthoringCommand[]] {\n const ruleId = rule.ruleId ?? `r_${rule.kind}`;\n const gateItems =\n rule.gate === undefined ? undefined : mappedGateItems(ruleId, rule.gate, message);\n const hasRuleMessage =\n rule.messageKey !== undefined ||\n rule.kind === 'validate' ||\n rule.kind === 'gate' ||\n rule.kind === 'screen';\n const addRule: AuthoringCommand = {\n kind: 'addRule',\n rule: {\n ruleId,\n kind: rule.kind,\n scope: rule.scope,\n expression: { mode: 'advanced', source: rule.expr },\n ...(rule.severity === undefined ? {} : { severity: rule.severity }),\n ...(rule.fieldId === undefined ? {} : { fieldId: rule.fieldId }),\n ...(rule.fieldIds === undefined ? {} : { fieldIds: rule.fieldIds }),\n ...(rule.gate === undefined || gateItems === undefined\n ? {}\n : {\n gate: {\n hard: rule.gate.hard,\n items: gateItems,\n ...(rule.gate.activeWhen === undefined\n ? {}\n : { activeWhen: { mode: 'advanced', source: rule.gate.activeWhen } }),\n },\n }),\n ...(hasRuleMessage ? { message } : {}),\n },\n };\n\n if (options?.translations === undefined) {\n return [addRule];\n }\n\n const extra: AuthoringCommand[] = [];\n for (const [entryLocale, entryText] of Object.entries(options.translations)) {\n const trimmed = entryText.trim();\n if (entryLocale === options.defaultLocale || trimmed === '') continue;\n if (hasRuleMessage) {\n extra.push({\n kind: 'setMessageText',\n messageKey: `rule.${ruleId}`,\n locale: entryLocale,\n text: trimmed,\n });\n }\n if (gateItems !== undefined) {\n for (const item of gateItems) {\n extra.push({\n kind: 'setMessageText',\n messageKey: `gate.${ruleId}.${item.itemId}`,\n locale: entryLocale,\n text: trimmed,\n });\n }\n }\n }\n return [addRule, ...extra];\n}\n"]}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The Axiom authoring surfaces, as one door.
3
+ *
4
+ * This package ships the *surfaces* and the vocabulary an authoring application is built from —
5
+ * the rule builder, the rule list, the condition and validation editors, the reference picker, and
6
+ * the projections a host renders beside them. It does not ship the application shell: the tray, the
7
+ * canvas and the selected-row rail are the host's own components over the builder's store, because
8
+ * a host brings its own design system and this package declares none. The reference Studio in
9
+ * `examples/studio` is that host, and it mounts these pieces inside its own tray, canvas and rail.
10
+ *
11
+ * The door is a contract: `test/package-entry-surface.test.ts` pins it by name, so adding an export
12
+ * fails that test until the list is updated, and `test/packed-consumer.test.ts` proves a
13
+ * consumer of the tarball compiles against exactly this list.
14
+ *
15
+ * The components are controlled: they read the document they are handed and report what the author
16
+ * asked for. None of them creates a store, writes a message catalogue or publishes on the host's
17
+ * behalf. Two vocabularies leave them: `EmittedRule` is a complete rule the
18
+ * builder hands back, and `InspectorChange` is the selected-row pane's own vocabulary, which a host
19
+ * maps to its commands because several of those edits are not one command.
20
+ *
21
+ * The stylesheet is a separate import so a host can ship its own:
22
+ *
23
+ * import '@azx-pbc/axiom-form-builder/styles.css';
24
+ */
25
+ export { ConditionEditor, DEFAULT_RULE_SENTENCE_LABELS, RuleBuilder, RuleList, RULE_TEMPLATES, RuleMessageEditor, ValidationEditor, copyMessageFromDefault, defaultOperatorFor, defaultRuleTemplateDraft, defaultValidationDraft, messageRows, renameMessageKey, ruleTemplateNeedsMessage, missingMessageLocales, ruleSentence, validationExpression, withValidationField, withValidationOperator, } from './rules/index.js';
26
+ export type { ConditionDraft, ConditionEditorLabels, ConditionEditorProps, EmittedRule, ExpressionProblem, MessageCatalogue, MessageKeyRename, MessageRow, ReadableRule, RuleBuilderLabels, RuleBuilderProps, RuleContext, RuleField, RuleListLabels, RuleListProps, RuleMessageEditorProps, RuleMessageLabels, RuleProblem, RuleSection, RuleSentenceLabels, RuleStatus, RuleTable, RuleTableColumn, RuleTemplateDefinition, RuleTemplateDraft, RuleTemplateId, ValidationDraft, ValidationEditorLabels, ValidationEditorProps, ValidationOperator, } from './rules/index.js';
27
+ export { ReferencePicker, insertReferenceAtCaret, insertTokenAtCaret, referenceIndex, referenceTokenOf, resolveReferenceField, resolveReferenceToken, resolveTokensInSource, } from './reference/index.js';
28
+ export type { FieldReference, ReferencePickerLabels, ReferencePickerProps, ReferableField, } from './reference/index.js';
29
+ export type { InspectorChange, PaletteColumnDraft, PaletteColumnType, PaletteValidationDraft, PaletteValidationOperator, } from './inspector.js';
30
+ export { capabilityRuleId, commandsForInspectorChange, commandsForRule, freshRuleId, readableRulesOf, ruleContextOf, } from './bridge/index.js';
31
+ export type { GeneratedDeclarationMessages, InspectorCommandNotes, InspectorCommandOptions, InspectorOutcome, RuleCommandOptions, RuleContextOptions, } from './bridge/index.js';
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,WAAW,EACX,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The Axiom authoring surfaces, as one door.
3
+ *
4
+ * This package ships the *surfaces* and the vocabulary an authoring application is built from —
5
+ * the rule builder, the rule list, the condition and validation editors, the reference picker, and
6
+ * the projections a host renders beside them. It does not ship the application shell: the tray, the
7
+ * canvas and the selected-row rail are the host's own components over the builder's store, because
8
+ * a host brings its own design system and this package declares none. The reference Studio in
9
+ * `examples/studio` is that host, and it mounts these pieces inside its own tray, canvas and rail.
10
+ *
11
+ * The door is a contract: `test/package-entry-surface.test.ts` pins it by name, so adding an export
12
+ * fails that test until the list is updated, and `test/packed-consumer.test.ts` proves a
13
+ * consumer of the tarball compiles against exactly this list.
14
+ *
15
+ * The components are controlled: they read the document they are handed and report what the author
16
+ * asked for. None of them creates a store, writes a message catalogue or publishes on the host's
17
+ * behalf. Two vocabularies leave them: `EmittedRule` is a complete rule the
18
+ * builder hands back, and `InspectorChange` is the selected-row pane's own vocabulary, which a host
19
+ * maps to its commands because several of those edits are not one command.
20
+ *
21
+ * The stylesheet is a separate import so a host can ship its own:
22
+ *
23
+ * import '@azx-pbc/axiom-form-builder/styles.css';
24
+ */
25
+ export { ConditionEditor, DEFAULT_RULE_SENTENCE_LABELS, RuleBuilder, RuleList, RULE_TEMPLATES, RuleMessageEditor, ValidationEditor, copyMessageFromDefault, defaultOperatorFor, defaultRuleTemplateDraft, defaultValidationDraft, messageRows, renameMessageKey, ruleTemplateNeedsMessage, missingMessageLocales, ruleSentence, validationExpression, withValidationField, withValidationOperator, } from './rules/index.js';
26
+ export { ReferencePicker, insertReferenceAtCaret, insertTokenAtCaret, referenceIndex, referenceTokenOf, resolveReferenceField, resolveReferenceToken, resolveTokensInSource, } from './reference/index.js';
27
+ export { capabilityRuleId, commandsForInspectorChange, commandsForRule, freshRuleId, readableRulesOf, ruleContextOf, } from './bridge/index.js';
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,WAAW,EACX,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAkC1B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAgB9B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC","sourcesContent":["/**\n * The Axiom authoring surfaces, as one door.\n *\n * This package ships the *surfaces* and the vocabulary an authoring application is built from —\n * the rule builder, the rule list, the condition and validation editors, the reference picker, and\n * the projections a host renders beside them. It does not ship the application shell: the tray, the\n * canvas and the selected-row rail are the host's own components over the builder's store, because\n * a host brings its own design system and this package declares none. The reference Studio in\n * `examples/studio` is that host, and it mounts these pieces inside its own tray, canvas and rail.\n *\n * The door is a contract: `test/package-entry-surface.test.ts` pins it by name, so adding an export\n * fails that test until the list is updated, and `test/packed-consumer.test.ts` proves a\n * consumer of the tarball compiles against exactly this list.\n *\n * The components are controlled: they read the document they are handed and report what the author\n * asked for. None of them creates a store, writes a message catalogue or publishes on the host's\n * behalf. Two vocabularies leave them: `EmittedRule` is a complete rule the\n * builder hands back, and `InspectorChange` is the selected-row pane's own vocabulary, which a host\n * maps to its commands because several of those edits are not one command.\n *\n * The stylesheet is a separate import so a host can ship its own:\n *\n * import '@azx-pbc/axiom-form-builder/styles.css';\n */\nexport {\n ConditionEditor,\n DEFAULT_RULE_SENTENCE_LABELS,\n RuleBuilder,\n RuleList,\n RULE_TEMPLATES,\n RuleMessageEditor,\n ValidationEditor,\n copyMessageFromDefault,\n defaultOperatorFor,\n defaultRuleTemplateDraft,\n defaultValidationDraft,\n messageRows,\n renameMessageKey,\n ruleTemplateNeedsMessage,\n missingMessageLocales,\n ruleSentence,\n validationExpression,\n withValidationField,\n withValidationOperator,\n} from './rules/index.js';\nexport type {\n ConditionDraft,\n ConditionEditorLabels,\n ConditionEditorProps,\n EmittedRule,\n ExpressionProblem,\n MessageCatalogue,\n MessageKeyRename,\n MessageRow,\n ReadableRule,\n RuleBuilderLabels,\n RuleBuilderProps,\n RuleContext,\n RuleField,\n RuleListLabels,\n RuleListProps,\n RuleMessageEditorProps,\n RuleMessageLabels,\n RuleProblem,\n RuleSection,\n RuleSentenceLabels,\n RuleStatus,\n RuleTable,\n RuleTableColumn,\n RuleTemplateDefinition,\n RuleTemplateDraft,\n RuleTemplateId,\n ValidationDraft,\n ValidationEditorLabels,\n ValidationEditorProps,\n ValidationOperator,\n} from './rules/index.js';\n\nexport {\n ReferencePicker,\n insertReferenceAtCaret,\n insertTokenAtCaret,\n referenceIndex,\n referenceTokenOf,\n resolveReferenceField,\n resolveReferenceToken,\n resolveTokensInSource,\n} from './reference/index.js';\nexport type {\n FieldReference,\n ReferencePickerLabels,\n ReferencePickerProps,\n ReferableField,\n} from './reference/index.js';\n\nexport type {\n InspectorChange,\n PaletteColumnDraft,\n PaletteColumnType,\n PaletteValidationDraft,\n PaletteValidationOperator,\n} from './inspector.js';\n\nexport {\n capabilityRuleId,\n commandsForInspectorChange,\n commandsForRule,\n freshRuleId,\n readableRulesOf,\n ruleContextOf,\n} from './bridge/index.js';\nexport type {\n GeneratedDeclarationMessages,\n InspectorCommandNotes,\n InspectorCommandOptions,\n InspectorOutcome,\n RuleCommandOptions,\n RuleContextOptions,\n} from './bridge/index.js';\n"]}
@@ -0,0 +1,125 @@
1
+ import type { FieldPrimitiveSpec } from '@azx-pbc/axiom-builder';
2
+ /**
3
+ * The vocabulary a host's inspector speaks.
4
+ *
5
+ * The inspector pane itself is the host's: this package ships the rule and reference surfaces and
6
+ * the vocabulary around them, not a skin, so the selected-row rail in the reference Studio is a
7
+ * host component and every edit it makes crosses into the store through the union below. Keeping
8
+ * the union here — beside the rule editor that also edits a field's validation — is what lets two
9
+ * different panes state one intent without either owning the store.
10
+ *
11
+ * Both draft types carry the `Palette` prefix because that is the name they were published under
12
+ * while the palette was a component of this package; a host imports them by that name, so the
13
+ * prefix stays even though the palette no longer ships. Renaming a published type is a break with
14
+ * no benefit to the reader of a `change.draft`.
15
+ */
16
+ /** One table column a host's inspector holds before it states the declaration. */
17
+ export type PaletteColumnType = 'text' | 'number' | 'money' | 'date' | 'boolean';
18
+ /** One table column the inspector holds. */
19
+ export interface PaletteColumnDraft {
20
+ readonly name: string;
21
+ readonly type: PaletteColumnType;
22
+ }
23
+ /** The comparison operators an inspector's validation row offers. */
24
+ export type PaletteValidationOperator = 'is_empty' | 'is_not_empty' | 'equals' | 'not_equals' | 'greater_than' | 'less_than' | 'greater_or_equal' | 'less_or_equal' | 'contains' | 'starts_with' | 'ends_with' | 'one_of' | 'not_one_of' | 'matches_pattern' | 'between';
25
+ /** A validation the inspector hands to its host, with one message per declared locale. */
26
+ export interface PaletteValidationDraft {
27
+ readonly fieldId: string;
28
+ readonly operator: PaletteValidationOperator;
29
+ /** The first operand; empty for a none-arity operator. */
30
+ readonly value: string;
31
+ /** The second operand, used only by `between`. */
32
+ readonly secondValue: string;
33
+ /** One value per line for the list operators. */
34
+ readonly values: string;
35
+ /** The pattern text for `matches_pattern`. */
36
+ readonly pattern: string;
37
+ readonly severity: 'block' | 'warn';
38
+ readonly messageByLocale: Readonly<Record<string, string>>;
39
+ }
40
+ /** Every intent an inspector can hand its host. */
41
+ export type InspectorChange = {
42
+ readonly kind: 'text';
43
+ readonly fieldId: string;
44
+ readonly member: 'label' | 'help' | 'placeholder';
45
+ readonly locale: string;
46
+ readonly text: string;
47
+ /** The key to mint when the member has none. */
48
+ readonly messageKey: string;
49
+ } | {
50
+ readonly kind: 'translations';
51
+ readonly fieldId: string;
52
+ readonly entries: readonly {
53
+ readonly member: 'label' | 'help' | 'placeholder';
54
+ readonly locale: string;
55
+ readonly text: string;
56
+ readonly messageKey: string;
57
+ }[];
58
+ } | {
59
+ readonly kind: 'message';
60
+ readonly messageKey: string;
61
+ readonly locale: string;
62
+ readonly text: string;
63
+ } | {
64
+ readonly kind: 'required';
65
+ readonly fieldId: string;
66
+ readonly required: boolean;
67
+ /** The key the required rule raises; the host mints it when the field has none. */
68
+ readonly messageKey: string;
69
+ } | {
70
+ readonly kind: 'options';
71
+ readonly fieldId: string;
72
+ /**
73
+ * The option domain as the row shows it. A code is the option's identity and is the value a
74
+ * record stores, so a field whose values are numbers (a rating's points) keeps numeric
75
+ * codes rather than spelling them as text.
76
+ */
77
+ readonly options: readonly {
78
+ readonly code: string | number;
79
+ readonly label: string;
80
+ }[];
81
+ } | {
82
+ /**
83
+ * Reorders one option by one position. The code is the identity; only the list moves.
84
+ */
85
+ readonly kind: 'optionMove';
86
+ readonly fieldId: string;
87
+ readonly code: string | number;
88
+ readonly direction: 'up' | 'down';
89
+ } | {
90
+ readonly kind: 'columns';
91
+ readonly fieldId: string;
92
+ readonly columns: readonly PaletteColumnDraft[];
93
+ } | {
94
+ readonly kind: 'covers';
95
+ readonly fieldId: string;
96
+ readonly covers: readonly string[];
97
+ } | {
98
+ readonly kind: 'money';
99
+ readonly fieldId: string;
100
+ readonly currency: string;
101
+ readonly scale: number;
102
+ } | {
103
+ readonly kind: 'bounds';
104
+ readonly fieldId: string;
105
+ readonly bounds: {
106
+ readonly minLength?: number;
107
+ readonly maxLength?: number;
108
+ readonly minimum?: number;
109
+ readonly maximum?: number;
110
+ readonly minItems?: number;
111
+ readonly maxItems?: number;
112
+ };
113
+ } | {
114
+ readonly kind: 'primitive';
115
+ readonly fieldId: string;
116
+ readonly primitive: FieldPrimitiveSpec;
117
+ } | {
118
+ readonly kind: 'locales';
119
+ readonly locales: readonly string[];
120
+ readonly defaultLocale: string;
121
+ } | {
122
+ readonly kind: 'validation';
123
+ readonly draft: PaletteValidationDraft;
124
+ };
125
+ //# sourceMappingURL=inspector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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