@1agh/maude 0.46.0 → 0.48.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 +7 -6
- package/apps/studio/acp/bootstrap-brief.ts +8 -0
- package/apps/studio/acp/bridge.ts +121 -6
- package/apps/studio/acp/plugin-bootstrap.ts +15 -1
- package/apps/studio/annotations-layer.tsx +42 -0
- package/apps/studio/api.ts +417 -2
- package/apps/studio/bin/_agent-browser-safe-config.json +1 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +228 -0
- package/apps/studio/bin/_agent-browser-safe.test.mjs +165 -0
- package/apps/studio/bin/_curl-local.mjs +349 -0
- package/apps/studio/bin/_curl-local.test.mjs +280 -0
- package/apps/studio/bin/agent-browser-safe.sh +29 -0
- package/apps/studio/bin/curl-local.sh +28 -0
- package/apps/studio/build.ts +1 -1
- package/apps/studio/canvas-cursors.ts +6 -0
- package/apps/studio/canvas-edit.ts +678 -11
- package/apps/studio/canvas-icons.tsx +13 -0
- package/apps/studio/canvas-lib.tsx +3 -0
- package/apps/studio/canvas-shell.tsx +646 -26
- package/apps/studio/client/app.jsx +898 -52
- package/apps/studio/client/export-center.jsx +7 -6
- package/apps/studio/client/github.js +11 -4
- package/apps/studio/client/panels/ChatPanel.jsx +47 -2
- package/apps/studio/client/styles/3-shell-maude.css +39 -0
- package/apps/studio/contextual-toolbar.tsx +5 -3
- package/apps/studio/dist/client.bundle.js +1103 -1103
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/runtime/REMOTION-LICENSE.md +1 -1
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/examples/perf-100-artboards.tsx +1 -1
- package/apps/studio/exporters/pdf.ts +35 -1
- package/apps/studio/git/service.ts +4 -1
- package/apps/studio/grid-track-handles.ts +179 -0
- package/apps/studio/handoff.ts +35 -0
- package/apps/studio/http.ts +118 -0
- package/apps/studio/input-router.tsx +73 -17
- package/apps/studio/paths.ts +37 -1
- package/apps/studio/test/acp-plugin-bootstrap.test.ts +34 -0
- package/apps/studio/test/acp-session-allowed-tools.test.ts +107 -11
- package/apps/studio/test/acp-session-plugins.test.ts +6 -0
- package/apps/studio/test/browse-posture.test.tsx +107 -0
- package/apps/studio/test/canvas-hide-chrome.test.ts +58 -0
- package/apps/studio/test/canvas-meta-api.test.ts +70 -0
- package/apps/studio/test/canvas-origin-gate.test.ts +4 -0
- package/apps/studio/test/comment-mount.test.ts +2 -1
- package/apps/studio/test/component-map.test.ts +48 -0
- package/apps/studio/test/convert-to-absolute.test.ts +333 -0
- package/apps/studio/test/detach-component.test.ts +94 -0
- package/apps/studio/test/edit-scope-api.test.ts +8 -4
- package/apps/studio/test/element-structural-api.test.ts +74 -0
- package/apps/studio/test/element-structural-edit.test.ts +113 -0
- package/apps/studio/test/exporters/pdf.test.ts +33 -1
- package/apps/studio/test/grid-track-handles.test.ts +160 -0
- package/apps/studio/test/handoff.test.ts +48 -0
- package/apps/studio/test/input-router.test.ts +82 -8
- package/apps/studio/test/layers-synthetic-groups.test.ts +96 -0
- package/apps/studio/test/pdf-print-boxes.test.ts +54 -0
- package/apps/studio/test/use-tool-mode.test.tsx +10 -2
- package/apps/studio/tool-palette.tsx +3 -1
- package/apps/studio/use-canvas-media-drop.tsx +126 -0
- package/apps/studio/use-element-resize.tsx +3 -1
- package/apps/studio/use-grid-track-handles.tsx +364 -0
- package/apps/studio/use-keyboard-discipline.tsx +15 -0
- package/apps/studio/use-tool-mode.tsx +30 -3
- package/apps/studio/web-overlay-content.tsx +52 -0
- package/apps/studio/whats-new.json +27 -0
- package/cli/bin/maude.mjs +1 -0
- package/cli/commands/design.mjs +16 -0
- package/cli/commands/init.mjs +80 -3
- package/cli/commands/kg.mjs +368 -0
- package/cli/commands/kg.test.mjs +118 -0
- package/cli/lib/ddr-to-kgai.mjs +648 -0
- package/cli/lib/ddr-to-kgai.test.mjs +99 -0
- package/cli/lib/flow-design-integration.test.mjs +2 -2
- package/cli/lib/gitignore-block.mjs +4 -0
- package/cli/lib/plugin-name-namespace.test.mjs +71 -0
- package/package.json +8 -8
- package/plugins/design/dependencies.json +17 -0
- package/plugins/design/templates/_shell.html +4 -0
- package/plugins/flow/.claude-plugin/config.schema.json +66 -0
- package/plugins/flow/dependencies.json +17 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// convert-to-absolute — feature-4 T8 (DDR-188). The pure AST batch writer behind
|
|
2
|
+
// the context-menu "Convert children to absolute position" (Figma's "Remove auto
|
|
3
|
+
// layout"): rewrite each stamped child to position:absolute with the frozen box,
|
|
4
|
+
// set the container position:relative, all in ONE MagicString pass (→ one undo
|
|
5
|
+
// seq). Mirrors canvas-edit.test.ts: raw source → transpile-computed ids → apply.
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from 'bun:test';
|
|
8
|
+
|
|
9
|
+
import { applyConvertToAbsolute, CanvasEditError } from '../canvas-edit.ts';
|
|
10
|
+
import { transpileCanvasSource } from '../canvas-pipeline.ts';
|
|
11
|
+
|
|
12
|
+
const CANVAS = '/abs/Canvas.tsx';
|
|
13
|
+
|
|
14
|
+
function idsOf(source: string): Record<string, string> {
|
|
15
|
+
const { withIds } = transpileCanvasSource(CANVAS, source);
|
|
16
|
+
const out: Record<string, string> = {};
|
|
17
|
+
for (const m of withIds.matchAll(/<(\w+)([^>]*?)data-cd-id="([0-9a-f]{8})"/g)) {
|
|
18
|
+
if (!out[m[1] as string]) out[m[1] as string] = m[3] as string;
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('canvas-edit / applyConvertToAbsolute', () => {
|
|
24
|
+
test('converts flow children to absolute + sets container relative (one pass)', () => {
|
|
25
|
+
const src = `function Demo() { return <div className="hero"><h1>Title</h1><button>Go</button></div>; }`;
|
|
26
|
+
const ids = idsOf(src);
|
|
27
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
28
|
+
containerId: ids.div as string,
|
|
29
|
+
containerSetRelative: true,
|
|
30
|
+
children: [
|
|
31
|
+
{ id: ids.h1 as string, left: 10, top: 20, width: 100, height: 30 },
|
|
32
|
+
{ id: ids.button as string, left: 12, top: 60, width: 80, height: 40 },
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
// Container relative (new style attr is inserted right after the tag name).
|
|
36
|
+
expect(out.source).toContain('<div style={{ position: "relative" }} className="hero">');
|
|
37
|
+
// Each child: absolute + frozen border-box + box-sizing.
|
|
38
|
+
expect(out.source).toContain(
|
|
39
|
+
'<h1 style={{ position: "absolute", left: "10px", top: "20px", width: "100px", height: "30px", "box-sizing": "border-box" }}>'
|
|
40
|
+
);
|
|
41
|
+
expect(out.source).toContain(
|
|
42
|
+
'<button style={{ position: "absolute", left: "12px", top: "60px", width: "80px", height: "40px", "box-sizing": "border-box" }}>'
|
|
43
|
+
);
|
|
44
|
+
// Exactly ONE style attr per element (no duplicate-insert bug).
|
|
45
|
+
expect((out.source.match(/style=\{\{/g) || []).length).toBe(3);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('containerSetRelative=false leaves the container untouched', () => {
|
|
49
|
+
const src = `function Demo() { return <div className="hero"><h1>T</h1></div>; }`;
|
|
50
|
+
const ids = idsOf(src);
|
|
51
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
52
|
+
containerId: ids.div as string,
|
|
53
|
+
containerSetRelative: false,
|
|
54
|
+
children: [{ id: ids.h1 as string, left: 0, top: 0, width: 50, height: 20 }],
|
|
55
|
+
});
|
|
56
|
+
expect(out.source).toContain('<div className="hero">');
|
|
57
|
+
expect(out.source).not.toContain('position: "relative"');
|
|
58
|
+
expect(out.source).toContain('position: "absolute"');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('merges into a child that already has an inline style (no duplicate style attr)', () => {
|
|
62
|
+
const src = `function Demo() { return <div><h1 style={{ color: "red" }}>T</h1></div>; }`;
|
|
63
|
+
const ids = idsOf(src);
|
|
64
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
65
|
+
containerId: ids.div as string,
|
|
66
|
+
containerSetRelative: true,
|
|
67
|
+
children: [{ id: ids.h1 as string, left: 5, top: 6, width: 10, height: 12 }],
|
|
68
|
+
});
|
|
69
|
+
// The h1 keeps color AND gains the absolute props — ONE style attribute.
|
|
70
|
+
expect((out.source.match(/<h1 style=\{\{/g) || []).length).toBe(1);
|
|
71
|
+
expect(out.source).toContain('color: "red"');
|
|
72
|
+
expect(out.source).toContain('position: "absolute"');
|
|
73
|
+
expect(out.source).toContain('left: "5px"');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('throws when a child id is not found', () => {
|
|
77
|
+
const src = `function Demo() { return <div><h1>T</h1></div>; }`;
|
|
78
|
+
const ids = idsOf(src);
|
|
79
|
+
expect(() =>
|
|
80
|
+
applyConvertToAbsolute(CANVAS, src, {
|
|
81
|
+
containerId: ids.div as string,
|
|
82
|
+
containerSetRelative: false,
|
|
83
|
+
children: [{ id: 'deadbeef', left: 0, top: 0, width: 1, height: 1 }],
|
|
84
|
+
})
|
|
85
|
+
).toThrow(CanvasEditError);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('throws when there are no children to convert', () => {
|
|
89
|
+
const src = `function Demo() { return <div><h1>T</h1></div>; }`;
|
|
90
|
+
const ids = idsOf(src);
|
|
91
|
+
expect(() =>
|
|
92
|
+
applyConvertToAbsolute(CANVAS, src, {
|
|
93
|
+
containerId: ids.div as string,
|
|
94
|
+
containerSetRelative: false,
|
|
95
|
+
children: [],
|
|
96
|
+
})
|
|
97
|
+
).toThrow(CanvasEditError);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a child that resolves to a shared component instance is refused WITHOUT allowShared', () => {
|
|
101
|
+
// Two <Card/> usages → the inner element's cd-id maps to a component; passing
|
|
102
|
+
// an idIndex makes resolveUsageId route to a <Card/> usage (id changes) →
|
|
103
|
+
// the pre-confirm abort fires.
|
|
104
|
+
const src = `
|
|
105
|
+
function Card() { return <article className="card"><h2>Hi</h2></article>; }
|
|
106
|
+
function Demo() { return <div><Card /><Card /></div>; }
|
|
107
|
+
`;
|
|
108
|
+
const ids = idsOf(src);
|
|
109
|
+
// The inner <h2> is the shared element; with an occurrence index it resolves
|
|
110
|
+
// to a <Card/> usage.
|
|
111
|
+
expect(() =>
|
|
112
|
+
applyConvertToAbsolute(CANVAS, src, {
|
|
113
|
+
containerId: ids.div as string,
|
|
114
|
+
containerSetRelative: false,
|
|
115
|
+
children: [{ id: ids.h2 as string, idIndex: 0, left: 0, top: 0, width: 1, height: 1 }],
|
|
116
|
+
})
|
|
117
|
+
).toThrow(CanvasEditError);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// feature-4 T8b — the "affects N instances" confirm path: with allowShared
|
|
121
|
+
// each instance-child's write routes to its OWN <Component/> usage (the
|
|
122
|
+
// Stage-H3 local-instance model), so both usages get distinct frozen boxes.
|
|
123
|
+
test('allowShared: component-instance children write per-usage boxes (both <Card/> tags styled)', () => {
|
|
124
|
+
const src = `
|
|
125
|
+
function Card() { return <article className="card"><h2>Hi</h2></article>; }
|
|
126
|
+
function Demo() { return <div><Card /><Card /></div>; }
|
|
127
|
+
`;
|
|
128
|
+
const ids = idsOf(src);
|
|
129
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
130
|
+
containerId: ids.div as string,
|
|
131
|
+
containerSetRelative: true,
|
|
132
|
+
allowShared: true,
|
|
133
|
+
children: [
|
|
134
|
+
{ id: ids.article as string, idIndex: 0, left: 0, top: 0, width: 100, height: 50 },
|
|
135
|
+
{ id: ids.article as string, idIndex: 1, left: 0, top: 60, width: 100, height: 50 },
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
// Each usage is WRAPPED in its own positioned div (style on the usage tag
|
|
139
|
+
// would require the component to forward it — most don't); the shared
|
|
140
|
+
// definition's <article> is untouched.
|
|
141
|
+
const wrapped =
|
|
142
|
+
out.source.match(/<div style=\{\{ position: "absolute"[^>]*\}\}><Card \/><\/div>/g) || [];
|
|
143
|
+
expect(wrapped.length).toBe(2);
|
|
144
|
+
expect(out.source).toContain('top: "0px"');
|
|
145
|
+
expect(out.source).toContain('top: "60px"');
|
|
146
|
+
expect(out.source).toContain('<article className="card">');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('allowShared: `.map`ed children still refuse (two children → same source element)', () => {
|
|
150
|
+
const src = `
|
|
151
|
+
const ITEMS = ['a', 'b'];
|
|
152
|
+
function Demo() { return <div>{ITEMS.map((t) => <p key={t}>{t}</p>)}</div>; }
|
|
153
|
+
`;
|
|
154
|
+
const ids = idsOf(src);
|
|
155
|
+
expect(() =>
|
|
156
|
+
applyConvertToAbsolute(CANVAS, src, {
|
|
157
|
+
containerId: ids.div as string,
|
|
158
|
+
containerSetRelative: false,
|
|
159
|
+
allowShared: true,
|
|
160
|
+
children: [
|
|
161
|
+
{ id: ids.p as string, idIndex: 0, left: 0, top: 0, width: 1, height: 1 },
|
|
162
|
+
{ id: ids.p as string, idIndex: 1, left: 0, top: 10, width: 1, height: 1 },
|
|
163
|
+
],
|
|
164
|
+
})
|
|
165
|
+
).toThrow(/repeated/);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// feature-4 artboard-level convert (2026-07-19) — the `containers` batch shape:
|
|
170
|
+
// whole-artboard flatten in ONE pass / ONE undo seq. Root level (artboard body)
|
|
171
|
+
// has no containerId; nested containers get relative-or-absolute exactly once.
|
|
172
|
+
describe('canvas-edit / applyConvertToAbsolute — containers batch (artboard level)', () => {
|
|
173
|
+
test('multi-level batch: root children absolute, nested container relative+absolute once', () => {
|
|
174
|
+
const src = `function Demo() { return <div className="hero"><h1>T</h1><section className="row"><p>a</p><em>b</em></section></div>; }`;
|
|
175
|
+
const ids = idsOf(src);
|
|
176
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
177
|
+
containers: [
|
|
178
|
+
// Root level — the artboard body (no containerId): the hero div itself.
|
|
179
|
+
{
|
|
180
|
+
containerSetRelative: false,
|
|
181
|
+
children: [{ id: ids.div as string, left: 0, top: 0, width: 520, height: 400 }],
|
|
182
|
+
},
|
|
183
|
+
// The hero div's own children.
|
|
184
|
+
{
|
|
185
|
+
containerId: ids.div as string,
|
|
186
|
+
containerSetRelative: true,
|
|
187
|
+
children: [
|
|
188
|
+
{ id: ids.h1 as string, left: 24, top: 24, width: 200, height: 30 },
|
|
189
|
+
{ id: ids.section as string, left: 24, top: 70, width: 400, height: 60 },
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
// The nested section's children.
|
|
193
|
+
{
|
|
194
|
+
containerId: ids.section as string,
|
|
195
|
+
containerSetRelative: true,
|
|
196
|
+
children: [
|
|
197
|
+
{ id: ids.p as string, left: 0, top: 0, width: 100, height: 20 },
|
|
198
|
+
{ id: ids.em as string, left: 110, top: 0, width: 80, height: 20 },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
// EVERY element position:absolute exactly once; the hero div (root child +
|
|
204
|
+
// container) carries absolute (child role) and NOT a second position key.
|
|
205
|
+
const positions = out.source.match(/position: "(absolute|relative)"/g) || [];
|
|
206
|
+
// 5 elements absolute (div, h1, section, p, em) + 0 extra relative — the
|
|
207
|
+
// div/section container-relative writes are skipped because both already
|
|
208
|
+
// received an absolute child-role write first.
|
|
209
|
+
expect(positions.filter((p) => p.includes('absolute')).length).toBe(5);
|
|
210
|
+
expect(positions.filter((p) => p.includes('relative')).length).toBe(0);
|
|
211
|
+
// No element carries two position keys.
|
|
212
|
+
expect(out.source).not.toMatch(/position:[^}]*position:/);
|
|
213
|
+
// Boxes landed.
|
|
214
|
+
expect(out.source).toContain('left: "110px"');
|
|
215
|
+
expect(out.source).toContain('width: "520px"');
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// dogfood 2026-07-20 — hand-AUTHORED data-cd-id (the pipeline preserves it, so
|
|
220
|
+
// the DOM id is the authored string, not the positional hash). The whole edit
|
|
221
|
+
// engine must resolve those: findOpening/collectElements* prefer the authored
|
|
222
|
+
// literal ("Convert failed: invalid container data-cd-id" on wal-hero-nav).
|
|
223
|
+
describe('canvas-edit / applyConvertToAbsolute — hand-authored data-cd-id', () => {
|
|
224
|
+
test('an authored-id container + authored-id child convert like any other', () => {
|
|
225
|
+
const src = `function Demo() { return <header data-cd-id="wal-hero-nav" className="nav"><a data-cd-id="wal-nav-link">Home</a><span>auto</span></header>; }`;
|
|
226
|
+
const ids = idsOf(src);
|
|
227
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
228
|
+
containerId: 'wal-hero-nav',
|
|
229
|
+
containerSetRelative: true,
|
|
230
|
+
children: [
|
|
231
|
+
{ id: 'wal-nav-link', left: 0, top: 0, width: 60, height: 20 },
|
|
232
|
+
{ id: ids.span as string, left: 70, top: 0, width: 40, height: 20 },
|
|
233
|
+
],
|
|
234
|
+
});
|
|
235
|
+
expect(out.source).toContain('position: "relative"');
|
|
236
|
+
// New style attr inserts right after the tag name (before authored attrs).
|
|
237
|
+
expect(out.source).toContain('<a style={{ position: "absolute"');
|
|
238
|
+
expect(out.source).toMatch(/<a style=\{\{[^}]+\}\} data-cd-id="wal-nav-link"/);
|
|
239
|
+
// The auto-stamped sibling (positional hash id) still resolves too.
|
|
240
|
+
expect((out.source.match(/position: "absolute"/g) || []).length).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// feature-4 TRUE FLATTEN (2026-07-20) — dissolve: unstyled layout wrappers'
|
|
245
|
+
// tags are removed from the JSX (children hoist textually); style targets and
|
|
246
|
+
// dissolve targets are disjoint by contract (hard error otherwise).
|
|
247
|
+
describe('canvas-edit / applyConvertToAbsolute — dissolve (true flatten)', () => {
|
|
248
|
+
test('wrapper tags removed, children hoisted + absolute against the surviving root', () => {
|
|
249
|
+
const src = `function Demo() { return <div className="hero"><div className="row"><h1>T</h1><button>Go</button></div></div>; }`;
|
|
250
|
+
const ids = idsOf(src);
|
|
251
|
+
// hero survives (gets relative); row dissolves; its children measured vs hero.
|
|
252
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
253
|
+
containers: [
|
|
254
|
+
{
|
|
255
|
+
containerId: ids.div as string, // hero (first div)
|
|
256
|
+
containerSetRelative: true,
|
|
257
|
+
children: [
|
|
258
|
+
{ id: ids.h1 as string, left: 10, top: 10, width: 100, height: 30 },
|
|
259
|
+
{ id: ids.button as string, left: 10, top: 50, width: 80, height: 40 },
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
dissolve: [
|
|
264
|
+
// the row div — second stamped div; find its id via a second idsOf pass
|
|
265
|
+
],
|
|
266
|
+
});
|
|
267
|
+
// Without knowing row's id from idsOf (first-match map), assert base shape.
|
|
268
|
+
expect(out.source).toContain('position: "relative"');
|
|
269
|
+
expect((out.source.match(/position: "absolute"/g) || []).length).toBe(2);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('dissolve removes exactly the wrapper tags (children JSX intact)', () => {
|
|
273
|
+
const src = `function Demo() { return <section className="card"><div className="col"><p>a</p></div></section>; }`;
|
|
274
|
+
const { withIds } = transpileCanvasSource(CANVAS, src);
|
|
275
|
+
const colId = /<div([^>]*?)data-cd-id="([0-9a-f]{8})"/.exec(withIds)?.[2] as string;
|
|
276
|
+
const secId = /<section([^>]*?)data-cd-id="([0-9a-f]{8})"/.exec(withIds)?.[2] as string;
|
|
277
|
+
const pId = /<p([^>]*?)data-cd-id="([0-9a-f]{8})"/.exec(withIds)?.[2] as string;
|
|
278
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
279
|
+
containers: [
|
|
280
|
+
{
|
|
281
|
+
containerId: secId,
|
|
282
|
+
containerSetRelative: true,
|
|
283
|
+
children: [{ id: pId, left: 5, top: 5, width: 50, height: 20 }],
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
dissolve: [colId],
|
|
287
|
+
});
|
|
288
|
+
// The col wrapper's tags are gone; the <p> hoisted directly under section.
|
|
289
|
+
expect(out.source).not.toContain('className="col"');
|
|
290
|
+
expect(out.source).toMatch(/<section[^>]*>\s*<p style=\{\{ position: "absolute"/);
|
|
291
|
+
expect(out.source).toContain('</section>');
|
|
292
|
+
expect(out.source).not.toMatch(/<\/div>/);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('an id that is BOTH a style target and a dissolve target throws', () => {
|
|
296
|
+
const src = `function Demo() { return <div><p>a</p></div>; }`;
|
|
297
|
+
const ids = idsOf(src);
|
|
298
|
+
expect(() =>
|
|
299
|
+
applyConvertToAbsolute(CANVAS, src, {
|
|
300
|
+
containers: [
|
|
301
|
+
{
|
|
302
|
+
containerSetRelative: false,
|
|
303
|
+
children: [{ id: ids.p as string, left: 0, top: 0, width: 1, height: 1 }],
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
dissolve: [ids.p as string],
|
|
307
|
+
})
|
|
308
|
+
).toThrow(/both a style target and a dissolve/);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// dogfood round 4 — the element-level subtree ROOT keeps flow position but
|
|
313
|
+
// freezes its own box (auto height would collapse once children go absolute).
|
|
314
|
+
describe('canvas-edit / applyConvertToAbsolute — root freezeSize', () => {
|
|
315
|
+
test('container gets relative + frozen width/height in one style attr', () => {
|
|
316
|
+
const src = `function Demo() { return <div className="grp"><p>a</p></div>; }`;
|
|
317
|
+
const ids = idsOf(src);
|
|
318
|
+
const out = applyConvertToAbsolute(CANVAS, src, {
|
|
319
|
+
containers: [
|
|
320
|
+
{
|
|
321
|
+
containerId: ids.div as string,
|
|
322
|
+
containerSetRelative: true,
|
|
323
|
+
freezeSize: { width: 472, height: 131 },
|
|
324
|
+
children: [{ id: ids.p as string, left: 12, top: 12, width: 60, height: 30 }],
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
});
|
|
328
|
+
expect(out.source).toContain(
|
|
329
|
+
'<div style={{ position: "relative", width: "472px", height: "131px", "box-sizing": "border-box" }} className="grp">'
|
|
330
|
+
);
|
|
331
|
+
expect(out.source).toContain('position: "absolute"');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// detach-component — feature-4 (2026-07-19). Detach = CLONE the component's
|
|
2
|
+
// definition under a fresh name + repoint ONE usage at the clone. Behavior-
|
|
3
|
+
// preserving for any component (no prop substitution); subsequent edits land on
|
|
4
|
+
// the clone's single-usage definition → resolveEditScope reports LOCAL.
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
|
|
8
|
+
import { applyDetachComponent, CanvasEditError, resolveEditScope } from '../canvas-edit.ts';
|
|
9
|
+
import { transpileCanvasSource } from '../canvas-pipeline.ts';
|
|
10
|
+
|
|
11
|
+
const CANVAS = '/abs/Canvas.tsx';
|
|
12
|
+
|
|
13
|
+
function idsOf(source: string): Record<string, string> {
|
|
14
|
+
const { withIds } = transpileCanvasSource(CANVAS, source);
|
|
15
|
+
const out: Record<string, string> = {};
|
|
16
|
+
for (const m of withIds.matchAll(/<(\w+)([^>]*?)data-cd-id="([0-9a-f]{8})"/g)) {
|
|
17
|
+
if (!out[m[1] as string]) out[m[1] as string] = m[3] as string;
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('canvas-edit / applyDetachComponent', () => {
|
|
23
|
+
const SRC = `
|
|
24
|
+
function Card({ label }: { label: string }) {
|
|
25
|
+
return <article className="card"><h2>{label}</h2></article>;
|
|
26
|
+
}
|
|
27
|
+
export default function Demo() {
|
|
28
|
+
return <div><Card label="Alpha" /><Card label="Beta" /></div>;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
test('clones the definition + repoints ONE usage; the other usage is untouched', () => {
|
|
33
|
+
const ids = idsOf(SRC);
|
|
34
|
+
// Detach the FIRST instance (occurrence 0 of the shared inner article).
|
|
35
|
+
const out = applyDetachComponent(CANVAS, SRC, ids.article as string, 0);
|
|
36
|
+
expect(out.detachedName).toBe('CardDetached');
|
|
37
|
+
// Clone inserted (same body, new name); original definition intact.
|
|
38
|
+
expect(out.source).toContain('function CardDetached({ label }: { label: string })');
|
|
39
|
+
expect(out.source).toContain('function Card({ label }: { label: string })');
|
|
40
|
+
// First usage repointed, second untouched — props preserved verbatim.
|
|
41
|
+
expect(out.source).toContain('<CardDetached label="Alpha" />');
|
|
42
|
+
expect(out.source).toContain('<Card label="Beta" />');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('after detach, edits on the detached instance resolve LOCAL', () => {
|
|
46
|
+
const ids = idsOf(SRC);
|
|
47
|
+
const out = applyDetachComponent(CANVAS, SRC, ids.article as string, 0);
|
|
48
|
+
// Recompute ids on the NEW source — the detached article now belongs to
|
|
49
|
+
// CardDetached, a single-usage component.
|
|
50
|
+
const { withIds } = transpileCanvasSource(CANVAS, out.source);
|
|
51
|
+
const detArticle = /<article([^>]*?)data-cd-id="([0-9a-f]{8})"/.exec(
|
|
52
|
+
withIds.slice(withIds.indexOf('CardDetached'))
|
|
53
|
+
);
|
|
54
|
+
// Sanity: some article id exists inside the detached definition region.
|
|
55
|
+
expect(detArticle).toBeTruthy();
|
|
56
|
+
const scope = resolveEditScope(CANVAS, out.source, detArticle?.[2] as string, 1);
|
|
57
|
+
expect(scope.scope).toBe('local');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('non-self-closing usage: BOTH tags repoint', () => {
|
|
61
|
+
const src = `
|
|
62
|
+
function Frame({ children }: { children?: unknown }) {
|
|
63
|
+
return <section className="frame">{children}</section>;
|
|
64
|
+
}
|
|
65
|
+
export default function Demo() {
|
|
66
|
+
return <div><Frame><p>a</p></Frame><Frame><p>b</p></Frame></div>;
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
const ids = idsOf(src);
|
|
70
|
+
const out = applyDetachComponent(CANVAS, src, ids.section as string, 0);
|
|
71
|
+
expect(out.source).toContain('<FrameDetached><p>a</p></FrameDetached>');
|
|
72
|
+
expect(out.source).toContain('<Frame><p>b</p></Frame>');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('name collisions bump the suffix', () => {
|
|
76
|
+
const src = `
|
|
77
|
+
function Card() { return <article>x</article>; }
|
|
78
|
+
function CardDetached() { return <aside>existing</aside>; }
|
|
79
|
+
export default function Demo() {
|
|
80
|
+
return <div><Card /><Card /></div>;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
const ids = idsOf(src);
|
|
84
|
+
const out = applyDetachComponent(CANVAS, src, ids.article as string, 0);
|
|
85
|
+
expect(out.detachedName).toBe('CardDetached2');
|
|
86
|
+
expect(out.source).toContain('function CardDetached2()');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('a plain (non-instance) element refuses', () => {
|
|
90
|
+
const src = `export default function Demo() { return <div><h1>T</h1></div>; }`;
|
|
91
|
+
const ids = idsOf(src);
|
|
92
|
+
expect(() => applyDetachComponent(CANVAS, src, ids.h1 as string, 0)).toThrow(CanvasEditError);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -103,10 +103,14 @@ describe('GET /_api/edit-scope', () => {
|
|
|
103
103
|
expect(mapped.body.reason).toBe('mapped');
|
|
104
104
|
expect(mapped.body.affects).toBe(4);
|
|
105
105
|
|
|
106
|
-
// A bogus id is a 400 (invalid data-cd-id shape).
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// A bogus id is a 400 (invalid data-cd-id shape). Note: since the
|
|
107
|
+
// authored-id widening (feature-4, 2026-07-20) short word-ids like "zzz"
|
|
108
|
+
// are VALID shapes (hand-authored data-cd-id attrs are preserved by the
|
|
109
|
+
// pipeline) — only genuinely malformed values (spaces, slashes) fail.
|
|
110
|
+
const bad = await fetch(
|
|
111
|
+
`${main}/_api/edit-scope?canvas=ui/Gallery&id=${encodeURIComponent('../etc/passwd')}`,
|
|
112
|
+
{ signal: AbortSignal.timeout(2000) }
|
|
113
|
+
);
|
|
110
114
|
expect(bad.status).toBe(400);
|
|
111
115
|
} finally {
|
|
112
116
|
await killProc(proc as never);
|
|
@@ -300,6 +300,80 @@ describe('POST /_api/delete-artboard', () => {
|
|
|
300
300
|
});
|
|
301
301
|
});
|
|
302
302
|
|
|
303
|
+
describe('POST /_api/duplicate-artboard', () => {
|
|
304
|
+
test('clones an artboard at a new width, returns a suffixed id, undo removes the clone', async () => {
|
|
305
|
+
const { designRoot, main, proc } = await boot();
|
|
306
|
+
const canvasPath = join(designRoot, 'ui', 'List.tsx');
|
|
307
|
+
try {
|
|
308
|
+
await divIdsByLine(main, designRoot); // warm pipeline
|
|
309
|
+
|
|
310
|
+
const dup = await fetch(`${main}/_api/duplicate-artboard`, {
|
|
311
|
+
method: 'POST',
|
|
312
|
+
body: JSON.stringify({ canvas: 'ui/List', artboardId: 'home', width: 390 }),
|
|
313
|
+
signal: AbortSignal.timeout(2000),
|
|
314
|
+
});
|
|
315
|
+
expect(dup.status).toBe(200);
|
|
316
|
+
const dupJson = (await dup.json()) as { ok: boolean; artboardId: string; seq: number };
|
|
317
|
+
expect(dupJson.ok).toBe(true);
|
|
318
|
+
expect(dupJson.artboardId).toBe('home-390');
|
|
319
|
+
const src = readFileSync(canvasPath, 'utf8');
|
|
320
|
+
expect(src).toContain('id="home-390"');
|
|
321
|
+
expect(src).toContain('width={390}');
|
|
322
|
+
// Original artboard is untouched.
|
|
323
|
+
expect(src).toContain('width={1440} height={1024}');
|
|
324
|
+
|
|
325
|
+
// Undo removes the clone, leaving only the original.
|
|
326
|
+
await fetch(`${main}/_api/reorder-revert`, {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
body: JSON.stringify({ canvas: 'ui/List', seq: dupJson.seq, dir: 'undo' }),
|
|
329
|
+
signal: AbortSignal.timeout(2000),
|
|
330
|
+
});
|
|
331
|
+
expect(readFileSync(canvasPath, 'utf8')).not.toContain('id="home-390"');
|
|
332
|
+
|
|
333
|
+
// Cross-origin duplicate is CSRF-rejected.
|
|
334
|
+
const forged = await fetch(`${main}/_api/duplicate-artboard`, {
|
|
335
|
+
method: 'POST',
|
|
336
|
+
headers: { origin: 'http://evil.example' },
|
|
337
|
+
body: JSON.stringify({ canvas: 'ui/List', artboardId: 'home', width: 390 }),
|
|
338
|
+
signal: AbortSignal.timeout(2000),
|
|
339
|
+
});
|
|
340
|
+
expect(forged.status).toBe(403);
|
|
341
|
+
} finally {
|
|
342
|
+
await killProc(proc as never);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('unknown artboard id is a 422 refusal', async () => {
|
|
347
|
+
const { designRoot, main, proc } = await boot();
|
|
348
|
+
try {
|
|
349
|
+
await divIdsByLine(main, designRoot); // warm pipeline
|
|
350
|
+
const res = await fetch(`${main}/_api/duplicate-artboard`, {
|
|
351
|
+
method: 'POST',
|
|
352
|
+
body: JSON.stringify({ canvas: 'ui/List', artboardId: 'nope', width: 390 }),
|
|
353
|
+
signal: AbortSignal.timeout(2000),
|
|
354
|
+
});
|
|
355
|
+
expect(res.status).toBe(422);
|
|
356
|
+
} finally {
|
|
357
|
+
await killProc(proc as never);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('malformed artboard id shape is a 400 refusal (security-auditor consistency finding)', async () => {
|
|
362
|
+
const { designRoot, main, proc } = await boot();
|
|
363
|
+
try {
|
|
364
|
+
await divIdsByLine(main, designRoot); // warm pipeline
|
|
365
|
+
const res = await fetch(`${main}/_api/duplicate-artboard`, {
|
|
366
|
+
method: 'POST',
|
|
367
|
+
body: JSON.stringify({ canvas: 'ui/List', artboardId: 'a" onload="x', width: 390 }),
|
|
368
|
+
signal: AbortSignal.timeout(2000),
|
|
369
|
+
});
|
|
370
|
+
expect(res.status).toBe(400);
|
|
371
|
+
} finally {
|
|
372
|
+
await killProc(proc as never);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
303
377
|
// G3 security (DDR-152) — the structural-write disk-fill / silent-shred defenses
|
|
304
378
|
// the adversarial review required: a per-api token bucket rate-caps the verbs,
|
|
305
379
|
// and a source-size ceiling refuses a GROWTH op past MAX_CANVAS_SOURCE (a delete
|
|
@@ -8,6 +8,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
applyDeleteElement,
|
|
11
|
+
applyDuplicateArtboard,
|
|
11
12
|
applyInsertArtboard,
|
|
12
13
|
applyInsertElement,
|
|
13
14
|
applyInsertElementIntoArtboard,
|
|
@@ -587,6 +588,63 @@ describe('canvas-edit / readArtboardPrintProp (no-eval AST read)', () => {
|
|
|
587
588
|
].join('\n');
|
|
588
589
|
expect(readArtboardPrintProp(CANVAS, canvas, 'home')).toBeNull();
|
|
589
590
|
});
|
|
591
|
+
|
|
592
|
+
test('resolves a print prop shared via a top-level const reference (RCA issue-pdf-print-export-marks-missing)', () => {
|
|
593
|
+
const canvas = [
|
|
594
|
+
'const A1_PRINT = { paper: "a1", orientation: "portrait", bleedMm: 3 } as const;',
|
|
595
|
+
'export default function Demo() {',
|
|
596
|
+
' return (',
|
|
597
|
+
' <DesignCanvas>',
|
|
598
|
+
' <DCArtboard id="acko-front" label="A" kind="print" width={816} height={1146} print={A1_PRINT}>',
|
|
599
|
+
' <div>content</div>',
|
|
600
|
+
' </DCArtboard>',
|
|
601
|
+
' <DCArtboard id="acko-back" label="B" kind="print" width={816} height={1146} print={A1_PRINT as any}>',
|
|
602
|
+
' <div>content</div>',
|
|
603
|
+
' </DCArtboard>',
|
|
604
|
+
' </DesignCanvas>',
|
|
605
|
+
' );',
|
|
606
|
+
'}',
|
|
607
|
+
].join('\n');
|
|
608
|
+
const expected = { paper: 'a1', orientation: 'portrait', bleedMm: 3 };
|
|
609
|
+
// Both the bare reference and the `as any`-cast reference (the shape
|
|
610
|
+
// AlligatorsAcko.tsx actually shipped, since a plain `print={A1_PRINT}`
|
|
611
|
+
// would fail TSX's own type check against the JSX prop's declared type)
|
|
612
|
+
// must resolve to the same object as an equivalent inline literal.
|
|
613
|
+
expect(readArtboardPrintProp(CANVAS, canvas, 'acko-front')).toEqual(expected);
|
|
614
|
+
expect(readArtboardPrintProp(CANVAS, canvas, 'acko-back')).toEqual(expected);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
test('an unresolvable print reference (imported, not declared in this file) → null', () => {
|
|
618
|
+
const canvas = [
|
|
619
|
+
'import { A1_PRINT } from "./print-specs.ts";',
|
|
620
|
+
'export default function Demo() {',
|
|
621
|
+
' return (',
|
|
622
|
+
' <DesignCanvas>',
|
|
623
|
+
' <DCArtboard id="home" label="Home" kind="print" width={816} height={1146} print={A1_PRINT}>',
|
|
624
|
+
' <div>content</div>',
|
|
625
|
+
' </DCArtboard>',
|
|
626
|
+
' </DesignCanvas>',
|
|
627
|
+
' );',
|
|
628
|
+
'}',
|
|
629
|
+
].join('\n');
|
|
630
|
+
expect(readArtboardPrintProp(CANVAS, canvas, 'home')).toBeNull();
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test('a genuinely computed print prop (function call) → null, never guessed', () => {
|
|
634
|
+
const canvas = [
|
|
635
|
+
'function computePrint() { return { paper: "a4" }; }',
|
|
636
|
+
'export default function Demo() {',
|
|
637
|
+
' return (',
|
|
638
|
+
' <DesignCanvas>',
|
|
639
|
+
' <DCArtboard id="home" label="Home" kind="print" width={816} height={1146} print={computePrint()}>',
|
|
640
|
+
' <div>content</div>',
|
|
641
|
+
' </DCArtboard>',
|
|
642
|
+
' </DesignCanvas>',
|
|
643
|
+
' );',
|
|
644
|
+
'}',
|
|
645
|
+
].join('\n');
|
|
646
|
+
expect(readArtboardPrintProp(CANVAS, canvas, 'home')).toBeNull();
|
|
647
|
+
});
|
|
590
648
|
});
|
|
591
649
|
|
|
592
650
|
describe('canvas-edit / applyInsertArtboard (I4)', () => {
|
|
@@ -635,3 +693,58 @@ describe('canvas-edit / applyInsertArtboard (I4)', () => {
|
|
|
635
693
|
).toThrow(CanvasEditError);
|
|
636
694
|
});
|
|
637
695
|
});
|
|
696
|
+
|
|
697
|
+
describe('canvas-edit / applyDuplicateArtboard (feature-3-web-artboards T3)', () => {
|
|
698
|
+
const canvas = [
|
|
699
|
+
'export default function Demo() {',
|
|
700
|
+
' return (',
|
|
701
|
+
' <DesignCanvas>',
|
|
702
|
+
' <DCArtboard id="home" label="Home" width={1440} height={1024} kind="web">',
|
|
703
|
+
' <div>content</div>',
|
|
704
|
+
' </DCArtboard>',
|
|
705
|
+
' <DCArtboard id="other" label="Other" width={800} height={600}>',
|
|
706
|
+
' <div>other</div>',
|
|
707
|
+
' </DCArtboard>',
|
|
708
|
+
' </DesignCanvas>',
|
|
709
|
+
' );',
|
|
710
|
+
'}',
|
|
711
|
+
].join('\n');
|
|
712
|
+
|
|
713
|
+
test('clones the artboard with a suffixed id/label + new width, right after the source', () => {
|
|
714
|
+
const out = applyDuplicateArtboard(CANVAS, canvas, 'home', 390);
|
|
715
|
+
expect(out.artboardId).toBe('home-390');
|
|
716
|
+
expect(out.source).toContain('id="home-390"');
|
|
717
|
+
expect(out.source).toContain('label="Home (390px)"');
|
|
718
|
+
expect(out.source).toContain('width={390}');
|
|
719
|
+
// Preserves kind + children verbatim.
|
|
720
|
+
expect(out.source).toContain('kind="web"');
|
|
721
|
+
const homeIdx = out.source.indexOf('id="home"');
|
|
722
|
+
const cloneIdx = out.source.indexOf('id="home-390"');
|
|
723
|
+
const otherIdx = out.source.indexOf('id="other"');
|
|
724
|
+
expect(cloneIdx).toBeGreaterThan(homeIdx);
|
|
725
|
+
// Lands right after the source — BEFORE the sibling that followed it — so
|
|
726
|
+
// it inherits the "beside the source" default-grid slot (DDR-027).
|
|
727
|
+
expect(cloneIdx).toBeLessThan(otherIdx);
|
|
728
|
+
expect((out.source.match(/<div>content<\/div>/g) ?? []).length).toBe(2);
|
|
729
|
+
expect(parses(out.source)).toBe(true);
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
test('de-dupes the new id when the same breakpoint is duplicated twice', () => {
|
|
733
|
+
const once = applyDuplicateArtboard(CANVAS, canvas, 'home', 390);
|
|
734
|
+
const twice = applyDuplicateArtboard(CANVAS, once.source, 'home', 390);
|
|
735
|
+
expect(twice.artboardId).toBe('home-390-2');
|
|
736
|
+
expect(twice.source).toContain('id="home-390-2"');
|
|
737
|
+
expect(parses(twice.source)).toBe(true);
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
test('height/other props are untouched — only id/label/width change', () => {
|
|
741
|
+
const out = applyDuplicateArtboard(CANVAS, canvas, 'home', 390);
|
|
742
|
+
// The clone keeps the SOURCE's height (390px is a width-only breakpoint
|
|
743
|
+
// change — height stays hug-driven per Design Decision 1).
|
|
744
|
+
expect(out.source).toContain('id="home-390" label="Home (390px)" width={390} height={1024}');
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
test('throws on an unknown artboard id', () => {
|
|
748
|
+
expect(() => applyDuplicateArtboard(CANVAS, canvas, 'nope', 390)).toThrow(CanvasEditError);
|
|
749
|
+
});
|
|
750
|
+
});
|