@aestheticfunction/dspack-emit 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +1004 -222
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +66 -2
- package/dist/transform/model.d.ts +368 -0
- package/dist/transform/model.js +169 -0
- package/dist/transform/parse-v2.d.ts +109 -0
- package/dist/transform/parse-v2.js +479 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +608 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
- package/dist/transform/shadcn-v2-respelling.js +456 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +136 -0
- package/dist/types.d.ts +23 -0
- package/dist/validate/ajv.js +96 -25
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/a0.test.ts +235 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +102 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +369 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/t1.test.ts +369 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +1468 -235
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +60 -2
- package/src/transform/model.ts +427 -0
- package/src/transform/parse-v2.ts +608 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +608 -0
- package/src/transform/profile.v2.schema.json +600 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +475 -0
- package/src/transform/validate-v2.ts +174 -0
- package/src/types.ts +32 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shadcn plans' v2 re-spelling — the six shipped v1 surface plans written
|
|
3
|
+
* in the primitive language. Byte-proven equivalent: src/profile-v2.test.ts
|
|
4
|
+
* emits every pinned artifact identically through these blocks.
|
|
5
|
+
*
|
|
6
|
+
* Shared by the keystone test and by eval/build-eval-profile.mjs, which
|
|
7
|
+
* transplants them onto a scaffold of the production v3 contract to build the
|
|
8
|
+
* reproducible coverage-evaluation fixture. One source, two consumers — the
|
|
9
|
+
* respelling is committed mapping evidence, not per-file copies.
|
|
10
|
+
*/
|
|
11
|
+
import type { SurfaceV2 } from "./parse-v2.js";
|
|
12
|
+
|
|
13
|
+
export const SHADCN_V2_SURFACES: Record<string, SurfaceV2> = {
|
|
14
|
+
button: {
|
|
15
|
+
routes: [
|
|
16
|
+
{ from: ["self.text"], to: "textChild:child", overwrite: true },
|
|
17
|
+
{ from: ["synthesized.action"], to: "action:action" },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
card: {
|
|
21
|
+
routes: [{ from: ["children"], to: "slot:child" }],
|
|
22
|
+
subs: {
|
|
23
|
+
"card-header": "transparent",
|
|
24
|
+
"card-content": "transparent",
|
|
25
|
+
"card-footer": "transparent",
|
|
26
|
+
"card-title": { asText: "h3" },
|
|
27
|
+
"card-description": { asText: "caption" },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
input: {
|
|
31
|
+
routes: [{ from: ["self.text"], to: "prop:label", overwrite: true }],
|
|
32
|
+
},
|
|
33
|
+
badge: {
|
|
34
|
+
routes: [{ from: ["self.text"], to: "prop:label", overwrite: true }],
|
|
35
|
+
},
|
|
36
|
+
table: {
|
|
37
|
+
routes: [
|
|
38
|
+
{ from: ["self.props.caption"], to: "prop:caption" },
|
|
39
|
+
{ from: ["self.props.columns"], to: "prop:columns" },
|
|
40
|
+
{ from: ["self.props.rows"], to: "prop:rows" },
|
|
41
|
+
{ from: ["sub(table-caption).subtreeText"], to: "prop:caption" },
|
|
42
|
+
],
|
|
43
|
+
collects: [
|
|
44
|
+
{ of: ["table-header"], into: "prop:columns", shape: "flat", row: ["table-row"], cells: ["table-cell", "table-head"] },
|
|
45
|
+
{ of: ["table-body"], into: "prop:rows", shape: "records", field: "cells", row: ["table-row"], cells: ["table-cell", "table-head"] },
|
|
46
|
+
],
|
|
47
|
+
subs: {
|
|
48
|
+
"table-footer": { drop: "summary rows have no slot in the synthesized caption/columns/rows shape" },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"alert-dialog": {
|
|
52
|
+
routes: [
|
|
53
|
+
{ from: ["sub(alert-dialog-title).text"], to: "prop:title" },
|
|
54
|
+
{ from: ["sub(alert-dialog-description).text"], to: "prop:description" },
|
|
55
|
+
{ from: ["sub(alert-dialog-cancel).text"], to: "prop:cancelLabel" },
|
|
56
|
+
{ from: ["sub(alert-dialog-action).text"], to: "prop:confirmLabel" },
|
|
57
|
+
{ from: ["sub(alert-dialog-trigger).label", "sub(alert-dialog-trigger).firstText"], to: "prop:triggerLabel" },
|
|
58
|
+
{ from: ["synthesized.action"], to: "action:action" },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* T1 resolutions for the production v3 contract — the transparent-identity
|
|
65
|
+
* spellings proven by src/t1.test.ts against the named production failure
|
|
66
|
+
* (`card > form > form-field > form-item > form-label + input`). Consumed by
|
|
67
|
+
* the eval fixture builder as committed mapping evidence; the fixture's other
|
|
68
|
+
* unresolved decisions stay deliberately open.
|
|
69
|
+
*/
|
|
70
|
+
export const SHADCN_V3_T1_SURFACES: Record<string, SurfaceV2> = {
|
|
71
|
+
form: {
|
|
72
|
+
transparent: true,
|
|
73
|
+
subs: {
|
|
74
|
+
"form-field": "transparent",
|
|
75
|
+
"form-control": "transparent",
|
|
76
|
+
"form-item": { transparent: { donate: [{ from: "sub(form-label).text", to: "prop:label" }] } },
|
|
77
|
+
"form-description": { asText: "caption" },
|
|
78
|
+
"form-message": { drop: "validation state is runtime data the declarative surface does not carry" },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* T2 resolutions for the production v3 contract — item-mode collection
|
|
85
|
+
* spellings proven by src/t2.test.ts. `radio-group` collects what each item
|
|
86
|
+
* itself carries ({value: self.id}); its htmlFor-joined sibling labels are
|
|
87
|
+
* the measured T3 frontier, dropped with record until declared joins land.
|
|
88
|
+
* `select` is the pure homogeneous shape ({label: self.text}).
|
|
89
|
+
*
|
|
90
|
+
* Each entry carries the full receiving plan (structural options schema) —
|
|
91
|
+
* unlike T1's transparent plans, a collecting plan IS a catalog component.
|
|
92
|
+
*/
|
|
93
|
+
export const SHADCN_V3_T3_PLANS: Record<string, Record<string, unknown>> = {
|
|
94
|
+
tabs: {
|
|
95
|
+
a2ui: "Tabs",
|
|
96
|
+
dspackId: "tabs",
|
|
97
|
+
commons: ["ComponentCommon"],
|
|
98
|
+
structural: {
|
|
99
|
+
sections: {
|
|
100
|
+
schema: {
|
|
101
|
+
type: "array",
|
|
102
|
+
items: {
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: { title: { type: "string" }, value: { type: "string" }, child: { $ref: "#/$defs/ComponentId" } },
|
|
105
|
+
required: ["title", "child"],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
description: "The tab sections: a title and the panel it reveals.",
|
|
110
|
+
synthNote: "A2UI models paired trigger/panel families as one array of {title, child} records (T3 declared join; the worked example keys on ids).",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
|
|
114
|
+
required: ["sections"],
|
|
115
|
+
surface: {
|
|
116
|
+
collects: [
|
|
117
|
+
{
|
|
118
|
+
of: ["tabs-trigger"],
|
|
119
|
+
into: "prop:sections",
|
|
120
|
+
item: { title: "self.text", value: "self.id" },
|
|
121
|
+
join: { with: ["tabs-content"], on: { left: "self.id", right: "self.id" }, fields: { child: "children" } },
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const SHADCN_V3_T2_PLANS: Record<string, Record<string, unknown>> = {
|
|
129
|
+
"radio-group": {
|
|
130
|
+
a2ui: "RadioGroup",
|
|
131
|
+
dspackId: "radio-group",
|
|
132
|
+
commons: ["ComponentCommon"],
|
|
133
|
+
structural: {
|
|
134
|
+
label: {
|
|
135
|
+
schema: { type: "string" },
|
|
136
|
+
description: "The group-level label naming the choice being made.",
|
|
137
|
+
synthNote: "Sourced by T1 form-label donation when the group sits inside a form field; a group without one relies on context.",
|
|
138
|
+
},
|
|
139
|
+
options: {
|
|
140
|
+
schema: { type: "array", items: { type: "object", properties: { value: { type: "string" }, label: { type: "string" } }, required: ["value"], additionalProperties: false } },
|
|
141
|
+
description: "The selectable options, one record per item.",
|
|
142
|
+
synthNote: "A2UI models repeated options as data on the group; dspack models them as repeated sub-components (T2 item-mode collection).",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
propMap: {
|
|
146
|
+
name: { a2ui: "name", kind: "string" },
|
|
147
|
+
defaultValue: { a2ui: "defaultValue", kind: "string" },
|
|
148
|
+
},
|
|
149
|
+
required: ["options"],
|
|
150
|
+
// T3: the htmlFor->id join carries each item's sibling label into its
|
|
151
|
+
// record. Value still sources from self.id — a documented limitation:
|
|
152
|
+
// ids are DOM identity, not semantic values ("reimbursement-payroll" vs
|
|
153
|
+
// defaultValue "payroll"); the real shadcn API declares value on the
|
|
154
|
+
// item, and the contract gap is filed upstream.
|
|
155
|
+
surface: {
|
|
156
|
+
collects: [
|
|
157
|
+
{
|
|
158
|
+
of: ["radio-group-item"],
|
|
159
|
+
into: "prop:options",
|
|
160
|
+
item: { value: "self.id" },
|
|
161
|
+
join: { with: ["label"], on: { left: "self.id", right: "self.props.htmlFor" }, fields: { label: "self.text" } },
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
select: {
|
|
167
|
+
a2ui: "Select",
|
|
168
|
+
dspackId: "select",
|
|
169
|
+
commons: ["ComponentCommon"],
|
|
170
|
+
structural: {
|
|
171
|
+
options: {
|
|
172
|
+
schema: { type: "array", items: { type: "object", properties: { label: { type: "string" } }, required: ["label"], additionalProperties: false } },
|
|
173
|
+
description: "The selectable options.",
|
|
174
|
+
synthNote: "A2UI models repeated options as data on the control (T2 item-mode collection).",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
|
|
178
|
+
required: ["options"],
|
|
179
|
+
surface: {
|
|
180
|
+
collects: [{ of: ["select-item"], into: "prop:options", item: { label: "self.text" } }],
|
|
181
|
+
subs: {
|
|
182
|
+
"select-trigger": { drop: "the trigger renders from the bound value, not authored content" },
|
|
183
|
+
"select-value": { drop: "the visible value is runtime state derived from the selection" },
|
|
184
|
+
"select-label": { drop: "group headings are not carried by the flat options shape" },
|
|
185
|
+
"select-separator": { drop: "visual grouping chrome with no data meaning" },
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* A0 authoring resolutions (the zero-new-capability milestone): production
|
|
193
|
+
* profile judgment for the families the shipped Identity/Routing/Repetition
|
|
194
|
+
* model already supports, proven by src/a0.test.ts. Six compound plans plus
|
|
195
|
+
* label-slot additions on the five controls that appear as a field's single
|
|
196
|
+
* control (the T1 donation destination). No new primitive anywhere.
|
|
197
|
+
*
|
|
198
|
+
* Grounded in measured usage across the 14 worked examples (contract 3.2.0):
|
|
199
|
+
* alert-title 5/5 + alert-description 5/5 carry the content; avatar-fallback
|
|
200
|
+
* carries text while avatar-image is an EMPTY node (the contract declares no
|
|
201
|
+
* src/alt — the dspack#39 class, recorded on the drop); scroll-area's two
|
|
202
|
+
* subs are scrollbar chrome; the field family follows the corrected
|
|
203
|
+
* declaration (dspack#40) with field as its own donating boundary.
|
|
204
|
+
*/
|
|
205
|
+
export const SHADCN_V3_A0_PLANS: Record<string, Record<string, unknown>> = {
|
|
206
|
+
alert: {
|
|
207
|
+
a2ui: "Alert",
|
|
208
|
+
dspackId: "alert",
|
|
209
|
+
commons: ["ComponentCommon"],
|
|
210
|
+
structural: {
|
|
211
|
+
title: {
|
|
212
|
+
schema: { type: "string" },
|
|
213
|
+
description: "The one-line heading naming what happened.",
|
|
214
|
+
synthNote: "Lifted from the alert-title sub (5/5 worked examples carry it there).",
|
|
215
|
+
},
|
|
216
|
+
description: {
|
|
217
|
+
schema: { type: "string" },
|
|
218
|
+
description: "Supporting detail under the title.",
|
|
219
|
+
synthNote: "Lifted from the alert-description sub.",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
propMap: {
|
|
223
|
+
variant: { a2ui: "variant", kind: "enum", targetEnum: ["default", "destructive"], default: "default" },
|
|
224
|
+
},
|
|
225
|
+
required: ["title"],
|
|
226
|
+
surface: {
|
|
227
|
+
routes: [
|
|
228
|
+
{ from: ["sub(alert-title).text"], to: "prop:title" },
|
|
229
|
+
{ from: ["sub(alert-description).text"], to: "prop:description" },
|
|
230
|
+
],
|
|
231
|
+
subs: {
|
|
232
|
+
"alert-action": {
|
|
233
|
+
drop:
|
|
234
|
+
"an action slot holds component children (a button), and routing a sub's children to a slot is T4's mechanism — dropped WITH RECORD until T4, not approximated (one production instance: ex.import-run-status)",
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
avatar: {
|
|
240
|
+
a2ui: "Avatar",
|
|
241
|
+
dspackId: "avatar",
|
|
242
|
+
commons: ["ComponentCommon"],
|
|
243
|
+
structural: {
|
|
244
|
+
fallback: {
|
|
245
|
+
schema: { type: "string" },
|
|
246
|
+
description: "Initials shown while no image is available.",
|
|
247
|
+
synthNote: "Lifted from the avatar-fallback sub's text.",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
propMap: { size: { a2ui: "size", kind: "enum", targetEnum: ["sm", "default", "lg"], default: "default" } },
|
|
251
|
+
required: ["fallback"],
|
|
252
|
+
surface: {
|
|
253
|
+
routes: [{ from: ["sub(avatar-fallback).text"], to: "prop:fallback" }],
|
|
254
|
+
subs: {
|
|
255
|
+
"avatar-image": {
|
|
256
|
+
drop: "the contract declares no src/alt on avatar-image — an empty node carries nothing to project (contract-gap class, cf. dspack#39)",
|
|
257
|
+
},
|
|
258
|
+
"avatar-badge": { drop: "no worked example exercises it; no measured shape to project — revisit with usage evidence" },
|
|
259
|
+
"avatar-group": { drop: "no worked example exercises it; a grouped-avatars shape is repetition to be measured, not guessed" },
|
|
260
|
+
"avatar-group-count": { drop: "no worked example exercises it; belongs to the unmeasured avatar-group shape" },
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
"scroll-area": {
|
|
265
|
+
a2ui: "ScrollArea",
|
|
266
|
+
dspackId: "scroll-area",
|
|
267
|
+
commons: ["ComponentCommon"],
|
|
268
|
+
structural: {},
|
|
269
|
+
required: [],
|
|
270
|
+
surface: {
|
|
271
|
+
transparent: true,
|
|
272
|
+
subs: {
|
|
273
|
+
"scroll-area-scrollbar": { drop: "scrollbar chrome: presentation of the scroll container, not content" },
|
|
274
|
+
"scroll-area-thumb": { drop: "the scrollbar's drag indicator: chrome, not content" },
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
field: {
|
|
279
|
+
a2ui: "Field",
|
|
280
|
+
dspackId: "field",
|
|
281
|
+
commons: ["ComponentCommon"],
|
|
282
|
+
structural: {},
|
|
283
|
+
required: [],
|
|
284
|
+
surface: {
|
|
285
|
+
transparent: { donate: [{ from: "sub(field-label).text", to: "prop:label" }] },
|
|
286
|
+
subs: {
|
|
287
|
+
"field-content": "transparent",
|
|
288
|
+
"field-title": { asText: "h4" },
|
|
289
|
+
"field-description": { asText: "caption" },
|
|
290
|
+
"field-error": { drop: "validation state is runtime data the declarative surface does not carry (mirrors form-message)" },
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
"field-set": {
|
|
295
|
+
a2ui: "FieldSet",
|
|
296
|
+
dspackId: "field-set",
|
|
297
|
+
commons: ["ComponentCommon"],
|
|
298
|
+
structural: {},
|
|
299
|
+
required: [],
|
|
300
|
+
surface: {
|
|
301
|
+
transparent: true,
|
|
302
|
+
subs: { "field-legend": { asText: "h4" } },
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
"field-group": {
|
|
306
|
+
a2ui: "FieldGroup",
|
|
307
|
+
dspackId: "field-group",
|
|
308
|
+
commons: ["ComponentCommon"],
|
|
309
|
+
structural: {},
|
|
310
|
+
required: [],
|
|
311
|
+
surface: {
|
|
312
|
+
transparent: true,
|
|
313
|
+
subs: {
|
|
314
|
+
"field-separator": { drop: "a visual section boundary; its optional inline text is presentation of the divider, and no worked example carries one" },
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* A0 label additions: the five controls that appear as a field's (or
|
|
322
|
+
* form-item's) single control across the worked examples — input already
|
|
323
|
+
* declares `label`; these gain the same structural slot so the T1 donation
|
|
324
|
+
* has a declared destination. Merged onto the scaffolded plans (select's T2
|
|
325
|
+
* plan) by the fixture builder; nothing else on those plans changes.
|
|
326
|
+
*/
|
|
327
|
+
export const SHADCN_V3_A0_LABEL_ADDITIONS: Record<string, { description: string; synthNote: string }> = {
|
|
328
|
+
switch: {
|
|
329
|
+
description: "The label naming what the switch turns on or off.",
|
|
330
|
+
synthNote: "Sourced by the T1 field-label/form-label donation; 4/4 worked-example switches sit inside a field.",
|
|
331
|
+
},
|
|
332
|
+
checkbox: {
|
|
333
|
+
description: "The label naming what checking the box asserts.",
|
|
334
|
+
synthNote: "Sourced by the T1 form-label donation (ex.expense-report-form's billable field).",
|
|
335
|
+
},
|
|
336
|
+
textarea: {
|
|
337
|
+
description: "The label naming the long-text entry.",
|
|
338
|
+
synthNote: "Sourced by the T1 field-label/form-label donation, exactly as on input.",
|
|
339
|
+
},
|
|
340
|
+
progress: {
|
|
341
|
+
description: "The label naming what is progressing.",
|
|
342
|
+
synthNote: "Sourced by the T1 field-label donation; 2/2 worked-example progress bars sit inside a field.",
|
|
343
|
+
},
|
|
344
|
+
select: {
|
|
345
|
+
description: "The label naming the choice being made.",
|
|
346
|
+
synthNote: "Sourced by the T1 field-label/form-label donation when the select is a field's control (ex.invite-teammates-dialog).",
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* T4 resolutions: multi-slot compounds, proven by src/t4.test.ts. The new
|
|
352
|
+
* primitive is ONE closed spelling — `sub(x).children -> slot:name` — the
|
|
353
|
+
* region's ordered children emitted as instances, the slot carrying the
|
|
354
|
+
* reference (multi wraps in Column, exactly like T3's joined-children).
|
|
355
|
+
*
|
|
356
|
+
* Measured shapes (contract 3.2.0 worked examples):
|
|
357
|
+
* - dialog/sheet: trigger and close labels are TEXT lifts (the alert-dialog
|
|
358
|
+
* idiom); title/description lift; header dissolves; content minus the
|
|
359
|
+
* claimed regions is the body slot; footer minus close is the footer slot.
|
|
360
|
+
* - popover: same family; its measured body is EMPTY after the header
|
|
361
|
+
* dissolves — the slot stays absent and gate A3 arbitrates. The unused
|
|
362
|
+
* popover-anchor drops pending usage evidence.
|
|
363
|
+
* - dropdown-menu is DATA-shaped, not slot-shaped: its items are a T2
|
|
364
|
+
* item-mode collect and its labels are scalar text routes — resolved with
|
|
365
|
+
* ZERO new primitive. The historic taxonomy called it T4; measurement
|
|
366
|
+
* says otherwise, and the plan follows the measurement.
|
|
367
|
+
*/
|
|
368
|
+
export const SHADCN_V3_T4_PLANS: Record<string, Record<string, unknown>> = {
|
|
369
|
+
dialog: {
|
|
370
|
+
a2ui: "Dialog",
|
|
371
|
+
dspackId: "dialog",
|
|
372
|
+
commons: ["ComponentCommon"],
|
|
373
|
+
structural: {
|
|
374
|
+
title: { schema: { type: "string" }, description: "The dialog's title (aria-labelledby).", synthNote: "Lifted from dialog-title." },
|
|
375
|
+
description: { schema: { type: "string" }, description: "Supporting context under the title.", synthNote: "Lifted from dialog-description." },
|
|
376
|
+
triggerLabel: { schema: { type: "string" }, description: "Label of the control that opens the dialog.", synthNote: "Lifted from the trigger's button label (the alert-dialog idiom)." },
|
|
377
|
+
closeLabel: { schema: { type: "string" }, description: "Label of the explicit close control.", synthNote: "Lifted from dialog-close." },
|
|
378
|
+
child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The dialog body: content minus the claimed regions, Column-wrapped when several.", synthNote: "T4 slot route from dialog-content's children." },
|
|
379
|
+
footer: { schema: { $ref: "#/$defs/ComponentId" }, description: "The action row minus the close control.", synthNote: "T4 slot route from dialog-footer's children." },
|
|
380
|
+
},
|
|
381
|
+
required: ["title"],
|
|
382
|
+
surface: {
|
|
383
|
+
routes: [
|
|
384
|
+
{ from: ["sub(dialog-title).text"], to: "prop:title" },
|
|
385
|
+
{ from: ["sub(dialog-description).text"], to: "prop:description" },
|
|
386
|
+
{ from: ["sub(dialog-trigger).label", "sub(dialog-trigger).firstText"], to: "prop:triggerLabel" },
|
|
387
|
+
{ from: ["sub(dialog-close).text"], to: "prop:closeLabel" },
|
|
388
|
+
{ from: ["sub(dialog-content).children"], to: "slot:child" },
|
|
389
|
+
{ from: ["sub(dialog-footer).children"], to: "slot:footer" },
|
|
390
|
+
],
|
|
391
|
+
subs: { "dialog-header": "transparent" },
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
sheet: {
|
|
395
|
+
a2ui: "Sheet",
|
|
396
|
+
dspackId: "sheet",
|
|
397
|
+
commons: ["ComponentCommon"],
|
|
398
|
+
structural: {
|
|
399
|
+
title: { schema: { type: "string" }, description: "The panel's title.", synthNote: "Lifted from sheet-title." },
|
|
400
|
+
description: { schema: { type: "string" }, description: "Supporting copy beneath the title.", synthNote: "Lifted from sheet-description." },
|
|
401
|
+
triggerLabel: { schema: { type: "string" }, description: "Label of the control that opens the sheet.", synthNote: "Lifted from the trigger's button label." },
|
|
402
|
+
closeLabel: { schema: { type: "string" }, description: "Label of the explicit close control.", synthNote: "Lifted from sheet-close." },
|
|
403
|
+
child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The panel body: content minus the claimed regions, Column-wrapped when several.", synthNote: "T4 slot route from sheet-content's children." },
|
|
404
|
+
footer: { schema: { $ref: "#/$defs/ComponentId" }, description: "The action row minus the close control.", synthNote: "T4 slot route from sheet-footer's children." },
|
|
405
|
+
},
|
|
406
|
+
required: ["title"],
|
|
407
|
+
surface: {
|
|
408
|
+
routes: [
|
|
409
|
+
{ from: ["sub(sheet-title).text"], to: "prop:title" },
|
|
410
|
+
{ from: ["sub(sheet-description).text"], to: "prop:description" },
|
|
411
|
+
{ from: ["sub(sheet-trigger).label", "sub(sheet-trigger).firstText"], to: "prop:triggerLabel" },
|
|
412
|
+
{ from: ["sub(sheet-close).text"], to: "prop:closeLabel" },
|
|
413
|
+
{ from: ["sub(sheet-content).children"], to: "slot:child" },
|
|
414
|
+
{ from: ["sub(sheet-footer).children"], to: "slot:footer" },
|
|
415
|
+
],
|
|
416
|
+
subs: { "sheet-header": "transparent" },
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
popover: {
|
|
420
|
+
a2ui: "Popover",
|
|
421
|
+
dspackId: "popover",
|
|
422
|
+
commons: ["ComponentCommon"],
|
|
423
|
+
structural: {
|
|
424
|
+
title: { schema: { type: "string" }, description: "The panel's visible title.", synthNote: "Lifted from popover-title." },
|
|
425
|
+
description: { schema: { type: "string" }, description: "Supporting copy beneath the title.", synthNote: "Lifted from popover-description." },
|
|
426
|
+
triggerLabel: { schema: { type: "string" }, description: "Label of the control that toggles the popover.", synthNote: "Lifted from the trigger's button label." },
|
|
427
|
+
child: { schema: { $ref: "#/$defs/ComponentId" }, description: "The panel body beyond title and description; absent when the measured body is empty.", synthNote: "T4 slot route from popover-content's children; the worked example's body is empty after the header dissolves." },
|
|
428
|
+
},
|
|
429
|
+
required: ["triggerLabel"],
|
|
430
|
+
surface: {
|
|
431
|
+
routes: [
|
|
432
|
+
{ from: ["sub(popover-title).text"], to: "prop:title" },
|
|
433
|
+
{ from: ["sub(popover-description).text"], to: "prop:description" },
|
|
434
|
+
{ from: ["sub(popover-trigger).label", "sub(popover-trigger).firstText"], to: "prop:triggerLabel" },
|
|
435
|
+
{ from: ["sub(popover-content).children"], to: "slot:child" },
|
|
436
|
+
],
|
|
437
|
+
subs: {
|
|
438
|
+
"popover-header": "transparent",
|
|
439
|
+
"popover-anchor": { drop: "no worked example exercises it; an alternative positioning reference is presentation until measured" },
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
"dropdown-menu": {
|
|
444
|
+
a2ui: "DropdownMenu",
|
|
445
|
+
dspackId: "dropdown-menu",
|
|
446
|
+
commons: ["ComponentCommon"],
|
|
447
|
+
structural: {
|
|
448
|
+
triggerLabel: { schema: { type: "string" }, description: "Label of the element that opens the menu.", synthNote: "Lifted from the trigger's button label." },
|
|
449
|
+
menuLabel: { schema: { type: "string" }, description: "The non-interactive heading above the items.", synthNote: "Lifted from dropdown-menu-label." },
|
|
450
|
+
items: {
|
|
451
|
+
schema: { type: "array", items: { type: "object", properties: { label: { type: "string" } }, required: ["label"], additionalProperties: false } },
|
|
452
|
+
description: "The actionable menu items, in order.",
|
|
453
|
+
synthNote: "T2 item-mode collect — the menu is DATA, not slots; measurement overruled the historic T4 classification.",
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
required: ["items"],
|
|
457
|
+
surface: {
|
|
458
|
+
routes: [
|
|
459
|
+
{ from: ["sub(dropdown-menu-trigger).label", "sub(dropdown-menu-trigger).firstText"], to: "prop:triggerLabel" },
|
|
460
|
+
{ from: ["sub(dropdown-menu-label).text"], to: "prop:menuLabel" },
|
|
461
|
+
],
|
|
462
|
+
collects: [{ of: ["dropdown-menu-item"], into: "prop:items", item: { label: "self.text" } }],
|
|
463
|
+
subs: {
|
|
464
|
+
"dropdown-menu-separator": { drop: "a visual divider between item groups; grouping is not carried by the flat items shape" },
|
|
465
|
+
"dropdown-menu-group": { drop: "grouping chrome; no worked example gives it meaning beyond adjacency" },
|
|
466
|
+
"dropdown-menu-checkbox-item": { drop: "no worked example exercises it; a toggleable item is a different record shape to measure, not guess" },
|
|
467
|
+
"dropdown-menu-radio-group": { drop: "no worked example exercises it" },
|
|
468
|
+
"dropdown-menu-radio-item": { drop: "no worked example exercises it" },
|
|
469
|
+
"dropdown-menu-sub": { drop: "nested menus are unmeasured; representing them is a decision for evidence, not defaults" },
|
|
470
|
+
"dropdown-menu-sub-trigger": { drop: "belongs to the unmeasured nested-menu shape" },
|
|
471
|
+
"dropdown-menu-sub-content": { drop: "belongs to the unmeasured nested-menu shape" },
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract-facing validation for v2 profiles.
|
|
3
|
+
*
|
|
4
|
+
* parse-v2.ts checks everything a plan can be wrong about ON ITS OWN — grammar
|
|
5
|
+
* closure, declared destinations, write conflicts. This module checks what a
|
|
6
|
+
* plan can only be wrong about AGAINST A CONTRACT, and it runs at every entry
|
|
7
|
+
* that has one in hand (transform, emitSurface), before any emission:
|
|
8
|
+
*
|
|
9
|
+
* - every `sub(x)` a route, collect, or disposition names must be a declared
|
|
10
|
+
* sub-component of the plan's contract component;
|
|
11
|
+
* - every `self.props.X` must be declared — by the contract as an ordinary
|
|
12
|
+
* prop, or by the plan's own structural block as a same-named passthrough;
|
|
13
|
+
* - derived sub-component coverage must be COMPLETE: every declared sub is
|
|
14
|
+
* routed, collected, absorbed, transparent, re-identified, or explicitly
|
|
15
|
+
* dropped — anything else is an unresolved authoring decision, and v2
|
|
16
|
+
* fails closed on it with a finding per sub.
|
|
17
|
+
*
|
|
18
|
+
* v1 is deliberately not gated here: its behaviour is frozen, and its
|
|
19
|
+
* coverage story stays report-plus-`--strict-coverage`. The split is the
|
|
20
|
+
* compatibility policy in one sentence — v2 refuses what v1 merely reports.
|
|
21
|
+
*/
|
|
22
|
+
import type { DspackDoc } from "../types.js";
|
|
23
|
+
import type { Profile } from "./profiles.js";
|
|
24
|
+
import { surfaceModelOf } from "./desugar.js";
|
|
25
|
+
import { describeDestination, referencedSubs, unclassifiedSubs, type Donation, type SurfaceModel } from "./model.js";
|
|
26
|
+
|
|
27
|
+
export interface ProfileContractIssue {
|
|
28
|
+
path: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class ProfileContractError extends Error {
|
|
33
|
+
constructor(readonly issues: ProfileContractIssue[]) {
|
|
34
|
+
super(
|
|
35
|
+
`profile does not fit this contract (${issues.length} issue${issues.length === 1 ? "" : "s"}): ` +
|
|
36
|
+
issues
|
|
37
|
+
.slice(0, 3)
|
|
38
|
+
.map((i) => `${i.path || "$"}: ${i.message}`)
|
|
39
|
+
.join("; ") +
|
|
40
|
+
(issues.length > 3 ? "; …" : ""),
|
|
41
|
+
);
|
|
42
|
+
this.name = "ProfileContractError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface ContractComponent {
|
|
47
|
+
props?: Record<string, unknown>;
|
|
48
|
+
composition?: { subComponents?: Array<{ id: string }> };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Every sub-component id a model's selectors, collects, and subs name. */
|
|
52
|
+
function namedSubs(model: SurfaceModel): Set<string> {
|
|
53
|
+
const out = new Set<string>(referencedSubs(model).keys());
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Every `self.props.X` a model reads, with the destination reading it. */
|
|
58
|
+
function namedSelfProps(model: SurfaceModel): Array<{ prop: string; to: string }> {
|
|
59
|
+
const out: Array<{ prop: string; to: string }> = [];
|
|
60
|
+
for (const r of model.routes) {
|
|
61
|
+
for (const s of r.from) if (s.kind === "self-prop") out.push({ prop: s.prop, to: r.to.name });
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Validate a v2 profile against the contract it is about to project. A no-op
|
|
68
|
+
* for v1 profiles (language undefined): their behaviour is frozen.
|
|
69
|
+
*/
|
|
70
|
+
export function validateProfileAgainstContract(profile: Profile, doc: DspackDoc): void {
|
|
71
|
+
if (profile.language !== "v2") return;
|
|
72
|
+
|
|
73
|
+
const issues: ProfileContractIssue[] = [];
|
|
74
|
+
const components = (doc.components ?? {}) as Record<string, ContractComponent>;
|
|
75
|
+
|
|
76
|
+
// Both collections: mapping.ts counts any synthesized plan with a dspackId
|
|
77
|
+
// as mapped, so the gate must see exactly what the mapper sees. And a plan
|
|
78
|
+
// with NO surface block validates against the empty model — for a compound,
|
|
79
|
+
// that means every declared sub is unresolved and refuses, identically to
|
|
80
|
+
// `surface: {}`. Presence of an empty key must never flip the gate.
|
|
81
|
+
const collections: Array<["components" | "synthesized", typeof profile.components]> = [
|
|
82
|
+
["components", profile.components],
|
|
83
|
+
["synthesized", profile.synthesized],
|
|
84
|
+
];
|
|
85
|
+
for (const [collection, plans] of collections) {
|
|
86
|
+
for (const [i, plan] of plans.entries()) {
|
|
87
|
+
if (!plan.dspackId) continue;
|
|
88
|
+
const at = `/${collection}/${i}/surface`;
|
|
89
|
+
const component = components[plan.dspackId];
|
|
90
|
+
if (!component) continue; // mapping.ts already warns on unknown dspackIds
|
|
91
|
+
|
|
92
|
+
const declaredSubs = (component.composition?.subComponents ?? []).map((s) => s.id);
|
|
93
|
+
const declaredProps = new Set(Object.keys(component.props ?? {}));
|
|
94
|
+
const model = surfaceModelOf(plan);
|
|
95
|
+
|
|
96
|
+
// A referenced name resolves against the compound's declared subs OR the
|
|
97
|
+
// contract's top-level components — a T3 join may pair a sub-family with
|
|
98
|
+
// a component family (the production radio-group joins its items to
|
|
99
|
+
// sibling `label` COMPONENTS via htmlFor), and surfaces carry both kinds
|
|
100
|
+
// of node identically.
|
|
101
|
+
for (const sub of namedSubs(model)) {
|
|
102
|
+
if (!declaredSubs.includes(sub) && !(sub in components)) {
|
|
103
|
+
issues.push({
|
|
104
|
+
path: at,
|
|
105
|
+
message: `'${sub}' is neither a declared sub-component of '${plan.dspackId}' nor a component of this contract (declared subs: ${declaredSubs.length ? declaredSubs.join(", ") : "none"})`,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A self-prop read is declared either by the CONTRACT (an ordinary prop)
|
|
111
|
+
// or by the PLAN's own structural block when source and destination share
|
|
112
|
+
// its name — the passthrough shape, where an A2UI structural slot may be
|
|
113
|
+
// authored directly on the surface node (v1's structuralPassthrough, and
|
|
114
|
+
// the reason the Table's caption/columns/rows are legal without the
|
|
115
|
+
// contract declaring them). Reading an undeclared prop into a
|
|
116
|
+
// DIFFERENTLY-named destination declares nothing anywhere, and refuses.
|
|
117
|
+
for (const { prop, to } of namedSelfProps(model)) {
|
|
118
|
+
const contractDeclared = declaredProps.has(prop);
|
|
119
|
+
const passthroughShaped = to === prop && prop in (plan.structural ?? {});
|
|
120
|
+
if (!contractDeclared && !passthroughShaped) {
|
|
121
|
+
issues.push({
|
|
122
|
+
path: at,
|
|
123
|
+
message: `self.props.${prop} reads a prop '${plan.dspackId}' does not declare in this contract, and it is not a same-named structural passthrough`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Derived coverage, enforced. The measured gates behind making this fatal:
|
|
129
|
+
// pinned shadcn v2.3.0, astryx and acme all derive zero-unresolved, and
|
|
130
|
+
// the production v3 pair's single finding (radio-group -> radio-group-item)
|
|
131
|
+
// is the known T2 gap — see scripts/sub-coverage-report.mjs and the
|
|
132
|
+
// 2aac076 measurement record.
|
|
133
|
+
for (const sub of unclassifiedSubs(model, declaredSubs)) {
|
|
134
|
+
issues.push({
|
|
135
|
+
path: at,
|
|
136
|
+
message: `sub-component '${sub}' of '${plan.dspackId}' is unresolved: no route consumes it, no collect gathers it, no disposition dissolves or drops it. Decide it — route, collect, transparent, asText, or drop with a reason.`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// T1 donations: every donated destination must be declared by at least one
|
|
143
|
+
// mapped, NON-transparent plan — otherwise no surface could ever satisfy
|
|
144
|
+
// the exactly-one-eligible-control rule and every use would refuse at emit.
|
|
145
|
+
// Checked profile-wide (the eligible control is chosen per surface).
|
|
146
|
+
const receiverProps = new Set<string>();
|
|
147
|
+
for (const plan of [...profile.components, ...profile.synthesized]) {
|
|
148
|
+
const m = surfaceModelOf(plan);
|
|
149
|
+
if (m.transparent) continue;
|
|
150
|
+
for (const k of Object.keys(plan.structural ?? {})) receiverProps.add(k);
|
|
151
|
+
for (const p of Object.values(plan.propMap ?? {})) receiverProps.add(p.a2ui);
|
|
152
|
+
}
|
|
153
|
+
for (const [collection, plans] of collections) {
|
|
154
|
+
for (const [i, plan] of plans.entries()) {
|
|
155
|
+
const m = surfaceModelOf(plan);
|
|
156
|
+
const donations: Array<{ d: Donation; at: string }> = [
|
|
157
|
+
...m.transparentDonate.map((d) => ({ d, at: `/${collection}/${i}/surface/transparent/donate` })),
|
|
158
|
+
...Object.values(m.subIdentity).flatMap((id) =>
|
|
159
|
+
id.kind === "transparent" && id.donate ? id.donate.map((d) => ({ d, at: `/${collection}/${i}/surface/subs` })) : [],
|
|
160
|
+
),
|
|
161
|
+
];
|
|
162
|
+
for (const { d, at } of donations) {
|
|
163
|
+
if (!receiverProps.has(d.to.name)) {
|
|
164
|
+
issues.push({
|
|
165
|
+
path: at,
|
|
166
|
+
message: `donation writes ${describeDestination(d.to)}, but no mapped non-transparent plan declares '${d.to.name}' — no surface could ever satisfy it`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (issues.length > 0) throw new ProfileContractError(issues);
|
|
174
|
+
}
|