@aestheticfunction/dspack-emit 0.3.0 → 0.3.1
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.
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Honest scope (mirrors MAPPING.md):
|
|
15
15
|
* - Compound composition flattens per the documented casualty mapping
|
|
16
|
-
* (`subText` / `subButtonText` consume the node's whole subtree).
|
|
16
|
+
* (`subText` / `subButtonText` consume the node's whole subtree). When no
|
|
17
|
+
* label-bearing component carries a `subButtonText` label, the first
|
|
18
|
+
* direct text under that sub is LIFTED (audited, `surface-label-lifted`;
|
|
19
|
+
* spec v0.4 amendment 2026-07-04) — relocation of existing text, never
|
|
20
|
+
* synthesis.
|
|
17
21
|
* - A2UI requires declarative actions the surface format does not express;
|
|
18
22
|
* they are synthesized (deterministic event-name slug) and recorded as
|
|
19
23
|
* warnings, not silently invented.
|
|
@@ -173,6 +173,36 @@ class SurfaceEmitter {
|
|
|
173
173
|
visit(child.node, nextInside);
|
|
174
174
|
};
|
|
175
175
|
visit(node, null);
|
|
176
|
+
// Audited label lift (spec v0.4 amendment, 2026-07-04): when no
|
|
177
|
+
// label-bearing component inside a subButtonText sub carried direct text,
|
|
178
|
+
// lift the FIRST direct text found under that sub (the sub's own text
|
|
179
|
+
// included, document order). This is a LIFT of existing text — relocation,
|
|
180
|
+
// never synthesis: if nothing exists to lift, the prop stays missing and
|
|
181
|
+
// gate A3 refuses the instance exactly as before. Every lift is recorded,
|
|
182
|
+
// like the other documented casualties, so audit reports can count them.
|
|
183
|
+
for (const [subId, buttonProp] of Object.entries(subButtonText)) {
|
|
184
|
+
if (instance[buttonProp] !== undefined)
|
|
185
|
+
continue;
|
|
186
|
+
const lift = (n, inside) => {
|
|
187
|
+
const here = inside || n.component === subId;
|
|
188
|
+
if (here && n.text !== undefined && n.text !== "")
|
|
189
|
+
return { text: n.text, component: n.component };
|
|
190
|
+
for (const child of collectChildren(n)) {
|
|
191
|
+
const found = lift(child.node, here);
|
|
192
|
+
if (found)
|
|
193
|
+
return found;
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
};
|
|
197
|
+
const found = lift(node, false);
|
|
198
|
+
if (found) {
|
|
199
|
+
instance[buttonProp] = found.text;
|
|
200
|
+
this.warnings.push({
|
|
201
|
+
code: "surface-label-lifted",
|
|
202
|
+
message: `${path}: '${buttonProp}' lifted from direct text on '${found.component}' inside '${subId}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
176
206
|
this.warnings.push({
|
|
177
207
|
code: "surface-composition-flattened",
|
|
178
208
|
message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "dspack emitters: compile a dspack design-system contract and dspack surfaces into protocol targets — an A2UI catalog + surface messages (gates A1-A3) and json-render catalog/registry modules + specs (gates J1-J3).",
|
|
6
6
|
"license": "Apache-2.0",
|
package/src/surface-emit.test.ts
CHANGED
|
@@ -92,6 +92,36 @@ describe("emitSurface: worked example (ex.delete-account-confirmation)", () => {
|
|
|
92
92
|
const again = emitSurface(workedExample.surface, doc);
|
|
93
93
|
expect(again.messages).toEqual(messages);
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
it("lifts a nested label when no label-bearing component carries it — audited, and A3 passes (spec v0.4 amendment)", () => {
|
|
97
|
+
// The measured 2026-07-03 signature shape: trigger > button > badge{text}.
|
|
98
|
+
const nested: DspackSurface = structuredClone(workedExample.surface);
|
|
99
|
+
const trigger = nested.root.children![0].children![0];
|
|
100
|
+
trigger.children = [
|
|
101
|
+
{ component: "button", props: { variant: "destructive" }, children: [{ component: "badge", text: "Delete account" }] },
|
|
102
|
+
];
|
|
103
|
+
const { messages: lifted, warnings: liftWarnings } = emitSurface(nested, doc);
|
|
104
|
+
const dialog = componentsOf(lifted).find((c) => c.component === "AlertDialog")!;
|
|
105
|
+
expect(dialog.triggerLabel).toBe("Delete account");
|
|
106
|
+
const lift = liftWarnings.find((w) => w.code === "surface-label-lifted")!;
|
|
107
|
+
expect(lift.message).toMatch(/'triggerLabel' lifted from direct text on 'badge' inside 'alert-dialog-trigger'/);
|
|
108
|
+
for (const version of ["0.9.1", "1.0"] as const) {
|
|
109
|
+
const { validation } = transform(doc, version, { messages: lifted });
|
|
110
|
+
expect(validation.gates.every((g) => g.pass), `gates for ${version}`).toBe(true);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("lift is relocation, never synthesis: a trigger with no text anywhere still fails A3", () => {
|
|
115
|
+
const bare: DspackSurface = structuredClone(workedExample.surface);
|
|
116
|
+
const trigger = bare.root.children![0].children![0];
|
|
117
|
+
trigger.children = [{ component: "button", props: { variant: "destructive" }, children: [{ component: "badge" }] }];
|
|
118
|
+
const { messages: bareMessages, warnings: bareWarnings } = emitSurface(bare, doc);
|
|
119
|
+
const dialog = componentsOf(bareMessages).find((c) => c.component === "AlertDialog")!;
|
|
120
|
+
expect(dialog.triggerLabel).toBeUndefined();
|
|
121
|
+
expect(bareWarnings.map((w) => w.code)).not.toContain("surface-label-lifted");
|
|
122
|
+
const { validation } = transform(doc, "0.9.1", { messages: bareMessages });
|
|
123
|
+
expect(validation.gates.find((g) => g.name === "instance")!.pass).toBe(false); // A3 refuses, as before
|
|
124
|
+
});
|
|
95
125
|
});
|
|
96
126
|
|
|
97
127
|
describe("emitSurface: general projection", () => {
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Honest scope (mirrors MAPPING.md):
|
|
15
15
|
* - Compound composition flattens per the documented casualty mapping
|
|
16
|
-
* (`subText` / `subButtonText` consume the node's whole subtree).
|
|
16
|
+
* (`subText` / `subButtonText` consume the node's whole subtree). When no
|
|
17
|
+
* label-bearing component carries a `subButtonText` label, the first
|
|
18
|
+
* direct text under that sub is LIFTED (audited, `surface-label-lifted`;
|
|
19
|
+
* spec v0.4 amendment 2026-07-04) — relocation of existing text, never
|
|
20
|
+
* synthesis.
|
|
17
21
|
* - A2UI requires declarative actions the surface format does not express;
|
|
18
22
|
* they are synthesized (deterministic event-name slug) and recorded as
|
|
19
23
|
* warnings, not silently invented.
|
|
@@ -239,6 +243,35 @@ class SurfaceEmitter {
|
|
|
239
243
|
for (const child of collectChildren(n)) visit(child.node, nextInside);
|
|
240
244
|
};
|
|
241
245
|
visit(node, null);
|
|
246
|
+
|
|
247
|
+
// Audited label lift (spec v0.4 amendment, 2026-07-04): when no
|
|
248
|
+
// label-bearing component inside a subButtonText sub carried direct text,
|
|
249
|
+
// lift the FIRST direct text found under that sub (the sub's own text
|
|
250
|
+
// included, document order). This is a LIFT of existing text — relocation,
|
|
251
|
+
// never synthesis: if nothing exists to lift, the prop stays missing and
|
|
252
|
+
// gate A3 refuses the instance exactly as before. Every lift is recorded,
|
|
253
|
+
// like the other documented casualties, so audit reports can count them.
|
|
254
|
+
for (const [subId, buttonProp] of Object.entries(subButtonText)) {
|
|
255
|
+
if (instance[buttonProp] !== undefined) continue;
|
|
256
|
+
const lift = (n: SurfaceNode, inside: boolean): { text: string; component: string } | undefined => {
|
|
257
|
+
const here = inside || n.component === subId;
|
|
258
|
+
if (here && n.text !== undefined && n.text !== "") return { text: n.text, component: n.component };
|
|
259
|
+
for (const child of collectChildren(n)) {
|
|
260
|
+
const found = lift(child.node, here);
|
|
261
|
+
if (found) return found;
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
};
|
|
265
|
+
const found = lift(node, false);
|
|
266
|
+
if (found) {
|
|
267
|
+
instance[buttonProp] = found.text;
|
|
268
|
+
this.warnings.push({
|
|
269
|
+
code: "surface-label-lifted",
|
|
270
|
+
message: `${path}: '${buttonProp}' lifted from direct text on '${found.component}' inside '${subId}' — no label-bearing component carried it (documented projection extension; lift, never synthesis).`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
242
275
|
this.warnings.push({
|
|
243
276
|
code: "surface-composition-flattened",
|
|
244
277
|
message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
|