Files
site-builder/craft/src/utils/canvas-summary.test.ts
T
shadowdaoandClaude Opus 5.5 7e8812a752 feat(site-builder): inline bold/italic/underline/links on Heading and Text
Select text inside a selected Heading or Text block and a floating
toolbar offers B / I / U / Link / Unlink (execCommand; mousedown is
prevented so the selection survives; mod+b/i/u handled on the editable).

Storage: new `html` prop holding sanitised inline HTML, with `text` kept
as the plain mirror for AI summaries, search and legacy content.
Unmarked edits store html '' so legacy nodes keep their shape. The
allowlist (b strong i em u a br span; style=color only, hex/rgb/
var(--wsb-*); href via DOMPurify URI check AND safeUrl, unsafe links
unwrapped; target only _blank with forced rel=noopener) runs on commit,
on canvas render and again at export. If `text` was changed without
`html` (Sitesmith update_props), the stale html is ignored.

Each edit commits once (blur, or deselect if no blur came first) as one
setProp = one undo step; the old blur+deselect double commit is gone.
Heading colour default now tokenRef('text'). Sitesmith canvas summary
skips `html`.

Refs #46

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 11:41:56 -07:00

43 lines
1.8 KiB
TypeScript

import { describe, test, expect } from 'vitest';
import { summarizeCanvas } from './canvas-summary';
const fixture = {
ROOT: { type: { resolvedName: 'Container' }, props: { aiName: 'Page Root', node_id: 'ai-root-1' }, nodes: ['n1','n2'], parent: null },
n1: { type: { resolvedName: 'Heading' }, props: { aiName: 'Hero Title', node_id: 'ai-hero-1', text: 'Welcome', level: 1, style: { color: '#fff' } }, nodes: [], parent: 'ROOT' },
n2: { type: { resolvedName: 'HtmlBlock' }, props: { aiName: 'Custom Embed', node_id: 'ai-html-1', code: '<div>opaque</div>' }, nodes: [], parent: 'ROOT' },
};
describe('summarizeCanvas', () => {
test('one line per node with id and aiName', () => {
const out = summarizeCanvas(fixture as any);
expect(out).toContain('Container id=ai-root-1');
expect(out).toContain('Heading id=ai-hero-1 name="Hero Title"');
});
test('excludes style props', () => {
expect(summarizeCanvas(fixture as any)).not.toContain('color=');
});
test('truncates to maxChars', () => {
const out = summarizeCanvas(fixture as any, 60);
expect(out.length).toBeLessThanOrEqual(60);
expect(out).toContain('truncated');
});
});
describe('summarizeCanvas with inline rich text (#46)', () => {
test('summarises the plain text mirror, never the html markup', () => {
const state = {
ROOT: { type: { resolvedName: 'Container' }, props: {}, nodes: ['h'] },
h: {
type: { resolvedName: 'Heading' },
props: { text: 'Hello World', html: 'Hello <b>World</b>', level: 'h2' },
nodes: [],
},
};
const out = summarizeCanvas(state as any);
expect(out).toContain('text=Hello World');
expect(out).toContain('level=h2');
expect(out).not.toContain('<b>');
expect(out).not.toContain('html=');
});
});