mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-02 13:25:40 +09:00
Closes #6306 ## Outcome Content Block templates are now the public component model for MDX authoring. - Standard Markdown resolves through matching Content Block templates. - PascalCase JSX resolves to a named template first, then to a registered component. - Adding or changing a template immediately affects matching MDX, including content authored before that template existed. - Every supported standard MDX element is present in new Content Blocks by default. - Template `name` is a stable PascalCase JSX identifier. `label` remains optional display text only. - Lowercase JSX represents native HTML and SVG without exposing `ws.element` in authored syntax. - Unknown, ambiguous, and unsafe JSX stays in source, produces a source-ranged Builder diagnostic, and is omitted from published output. - Frontmatter images preserve exact `$ref` values and use the Asset description for `alt` text. - Keyboard and mouse insertion from the slash menu remove the trigger slash and preserve the selected template. ## Public MDX contract - Markdown is canonical for standard prose. - Lowercase JSX creates native elements: `<section><p>Text</p></section>`. - PascalCase JSX uses templates and registered components: `<PromotionCard />`, `<Heading tag="h1">Title</Heading>`, and `<YouTube src="https://youtu.be/KI5JHpzBK1s" />`. - Component-name collisions use stable qualified identifiers such as `Checkbox` and `RadixCheckbox`. - A self-closing template keeps its designed default subtree. An explicitly paired empty template clears it. - Static quoted values and bare booleans are supported. - Imports, exports, expressions, spreads, functions, executable JavaScript, unsafe attributes, `<$.*>`, and authored `<ws.element>` are rejected. - `ws` remains only for compiler primitives with no React component. ## Implementation - [x] Add stable, unique template names and keep them separate from labels. - [x] Parse and validate Markdown and JSX through their ASTs with precise source ranges. - [x] Share component identity between template JSX, Content MDX, Builder materialization, reload, copy, and publication. - [x] Resolve templates live after add, edit, rename, reorder, removal, undo/redo, collaboration updates, and reload. - [x] Preserve authored props, children, Asset references, template defaults, and the exact slash-menu template choice. - [x] Make one typed MDX semantic inventory drive default templates and slash-menu eligibility. - [x] Move component-dependent template assembly into the component registry. - [x] Replace production `$`, `animation`, and `radix` JSX namespaces with direct component imports. - [x] Keep only explicit compiler primitives in `ws` template JSX. - [x] Migrate repository templates, fixtures, stories, examples, MCP guidance, CLI guidance, and generated outputs. - [x] Add Builder unit and Playwright coverage for authoring, diagnostics, insertion, synchronization, reload, and publication. - [x] Review and update the authoritative Content Block and generated MCP documentation. ## Compatibility - Persisted project data continues to use namespaced component IDs and `ws:element` for generic HTML elements. No project-data migration is required. - Legacy `<ws.element ws:tag="…">`, `<ws.element ws:name="…">`, `<$.*>`, `<animation.*>`, and `<radix.*>` input remains readable during the compatibility window. - Current serializers and repository-owned sources emit only canonical Markdown, lowercase intrinsic JSX, or PascalCase identifiers. - Untouched user MDX is not rewritten automatically. Legacy syntax is canonicalized when its owning source is edited. - Deferred follow-up: remove legacy namespace readers and proxy support only after the canonical writer is deployed and existing projects are backfilled. This is intentionally outside this PR. ## Verification - [x] CI package tests, typechecks, lint, package boundaries, generated assets, migrations, and size checks pass. - [x] All six Builder E2E shards pass. - [x] Fixture checks pass on Ubuntu and Windows. - [x] Targeted local Content Engine, Template, SDK, registry, Project Build, migration, Builder, component, CLI, and Playwright tests pass. - [x] Runtime contracts, CLI docs, and MCP docs were regenerated from their owning sources. - [x] Local fixture generation completed without an unexpected fixture diff. - [x] Documentation impact reviewed and included in this PR. - [x] Review and approve the intentional List visual snapshot change. - [x] Run the complete agent evaluation suite after explicit approval. - [x] Run the network fixture link/sync pipeline against the matching PR deployment after explicit permission. ## Known visual change The generated List story now targets its actual default `ul` element instead of `ol`, so the default list styling appears in the visual snapshot. The visual change was reviewed and the approved visual check passes.
294 lines
6.5 KiB
TypeScript
294 lines
6.5 KiB
TypeScript
/** @jsxImportSource @webstudio-is/template */
|
|
import {
|
|
css,
|
|
PlaceholderValue,
|
|
setInstanceMeta,
|
|
type TemplateMeta,
|
|
} from "@webstudio-is/template";
|
|
import {
|
|
Blockquote,
|
|
Bold,
|
|
Box,
|
|
Button,
|
|
Checkbox,
|
|
Fragment,
|
|
Heading,
|
|
HtmlEmbed,
|
|
Image,
|
|
Input,
|
|
Italic,
|
|
JsonLd,
|
|
Label,
|
|
Link,
|
|
List,
|
|
ListItem,
|
|
Paragraph,
|
|
RadioButton,
|
|
RemixForm,
|
|
RichTextLink,
|
|
Separator,
|
|
Span,
|
|
Subscript,
|
|
Superscript,
|
|
Text,
|
|
Textarea,
|
|
Time,
|
|
Video,
|
|
} from "./components";
|
|
|
|
const sampleImage =
|
|
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 360'%3E%3Crect width='640' height='360' fill='%23eef2ff'/%3E%3Cpath d='M96 264l120-120 88 88 56-56 184 184H96z' fill='%2394a3b8'/%3E%3Ccircle cx='456' cy='112' r='44' fill='%23f59e0b'/%3E%3C/svg%3E";
|
|
|
|
const BlockquoteTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
description: "A quoted customer insight or design principle.",
|
|
template: (
|
|
<Blockquote>
|
|
<Text>
|
|
{
|
|
new PlaceholderValue(
|
|
"Operations teams need interfaces that make the next action obvious."
|
|
)
|
|
}
|
|
</Text>
|
|
</Blockquote>
|
|
),
|
|
};
|
|
|
|
const BoldTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Bold>{new PlaceholderValue("Critical update")}</Bold>,
|
|
};
|
|
|
|
const BoxTemplate: TemplateMeta = {
|
|
category: "general",
|
|
template: setInstanceMeta(
|
|
{ label: "Example Card" },
|
|
<Box
|
|
ws:style={css`
|
|
padding: 16px;
|
|
border: 1px solid #d4d4d8;
|
|
border-radius: 8px;
|
|
`}
|
|
>
|
|
<Text>{new PlaceholderValue("Component example container")}</Text>
|
|
</Box>
|
|
),
|
|
};
|
|
|
|
const ButtonTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: <Button>{new PlaceholderValue("Save changes")}</Button>,
|
|
};
|
|
|
|
const CheckboxTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: <Checkbox aria-label="Enable weekly summary" />,
|
|
};
|
|
|
|
const FragmentTemplate: TemplateMeta = {
|
|
category: "general",
|
|
template: (
|
|
<Fragment>
|
|
<Text>{new PlaceholderValue("Reusable fragment content")}</Text>
|
|
</Fragment>
|
|
),
|
|
};
|
|
|
|
const HeadingTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: (
|
|
<Heading tag="h2">{new PlaceholderValue("Operational UI pattern")}</Heading>
|
|
),
|
|
};
|
|
|
|
const HtmlEmbedTemplate: TemplateMeta = {
|
|
category: "media",
|
|
template: (
|
|
<HtmlEmbed code="<div style='padding:12px;border:1px dashed #94a3b8;border-radius:8px'>Embedded status widget</div>" />
|
|
),
|
|
};
|
|
|
|
const JsonLdTemplate: TemplateMeta = {
|
|
category: "general",
|
|
order: 6,
|
|
template: (
|
|
<JsonLd
|
|
code={JSON.stringify({
|
|
"@context": "https://schema.org",
|
|
"@type": "Organization",
|
|
name: "Organization name",
|
|
})}
|
|
/>
|
|
),
|
|
};
|
|
|
|
const ImageTemplate: TemplateMeta = {
|
|
category: "media",
|
|
template: (
|
|
<Image
|
|
src={sampleImage}
|
|
alt="Abstract dashboard illustration"
|
|
width={640}
|
|
height={360}
|
|
/>
|
|
),
|
|
};
|
|
|
|
const InputTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: <Input name="workspace" placeholder="Workspace name" />,
|
|
};
|
|
|
|
const ItalicTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Italic>{new PlaceholderValue("Draft state")}</Italic>,
|
|
};
|
|
|
|
const LabelTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: <Label>{new PlaceholderValue("Workspace")}</Label>,
|
|
};
|
|
|
|
const LinkTemplate: TemplateMeta = {
|
|
category: "general",
|
|
template: (
|
|
<Link href="#components">{new PlaceholderValue("View components")}</Link>
|
|
),
|
|
};
|
|
|
|
const ListTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: (
|
|
<List>
|
|
<ListItem>{new PlaceholderValue("Triage incoming requests")}</ListItem>
|
|
<ListItem>{new PlaceholderValue("Assign an owner")}</ListItem>
|
|
<ListItem>{new PlaceholderValue("Resolve before SLA")}</ListItem>
|
|
</List>
|
|
),
|
|
};
|
|
|
|
const ListItemTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <ListItem>{new PlaceholderValue("Review queue health")}</ListItem>,
|
|
};
|
|
|
|
const ParagraphTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: (
|
|
<Paragraph>
|
|
{
|
|
new PlaceholderValue(
|
|
"Use these patterns to compose dense operational screens that stay readable under pressure."
|
|
)
|
|
}
|
|
</Paragraph>
|
|
),
|
|
};
|
|
|
|
const RadioButtonTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: (
|
|
<RadioButton
|
|
name="priority"
|
|
value="standard"
|
|
aria-label="Standard priority"
|
|
/>
|
|
),
|
|
};
|
|
|
|
const RemixFormTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: (
|
|
<RemixForm>
|
|
<Label>{new PlaceholderValue("Search")}</Label>
|
|
<Input name="query" placeholder="Find a ticket" />
|
|
<Button>{new PlaceholderValue("Search")}</Button>
|
|
</RemixForm>
|
|
),
|
|
};
|
|
|
|
const RichTextLinkTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: (
|
|
<RichTextLink href="#guidelines">
|
|
{new PlaceholderValue("Read the usage guidelines")}
|
|
</RichTextLink>
|
|
),
|
|
};
|
|
|
|
const SeparatorTemplate: TemplateMeta = {
|
|
category: "general",
|
|
template: <Separator />,
|
|
};
|
|
|
|
const SpanTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Span>{new PlaceholderValue("Inline status")}</Span>,
|
|
};
|
|
|
|
const SubscriptTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Subscript>{new PlaceholderValue("beta")}</Subscript>,
|
|
};
|
|
|
|
const SuperscriptTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Superscript>{new PlaceholderValue("new")}</Superscript>,
|
|
};
|
|
|
|
const TextTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: <Text>{new PlaceholderValue("System message")}</Text>,
|
|
};
|
|
|
|
const TextareaTemplate: TemplateMeta = {
|
|
category: "forms",
|
|
template: <Textarea name="notes" placeholder="Add handoff notes" />,
|
|
};
|
|
|
|
const TimeTemplate: TemplateMeta = {
|
|
category: "typography",
|
|
template: (
|
|
<Time datetime="2026-07-06T09:00:00Z">
|
|
{new PlaceholderValue("Jul 6, 2026, 09:00")}
|
|
</Time>
|
|
),
|
|
};
|
|
|
|
const VideoTemplate: TemplateMeta = {
|
|
category: "media",
|
|
template: <Video controls aria-label="Workflow walkthrough video" />,
|
|
};
|
|
|
|
export const templates = [
|
|
BlockquoteTemplate,
|
|
BoldTemplate,
|
|
BoxTemplate,
|
|
ButtonTemplate,
|
|
CheckboxTemplate,
|
|
FragmentTemplate,
|
|
HeadingTemplate,
|
|
HtmlEmbedTemplate,
|
|
ImageTemplate,
|
|
InputTemplate,
|
|
ItalicTemplate,
|
|
JsonLdTemplate,
|
|
LabelTemplate,
|
|
LinkTemplate,
|
|
ListTemplate,
|
|
ListItemTemplate,
|
|
ParagraphTemplate,
|
|
RadioButtonTemplate,
|
|
RemixFormTemplate,
|
|
RichTextLinkTemplate,
|
|
SeparatorTemplate,
|
|
SpanTemplate,
|
|
SubscriptTemplate,
|
|
SuperscriptTemplate,
|
|
TextTemplate,
|
|
TextareaTemplate,
|
|
TimeTemplate,
|
|
VideoTemplate,
|
|
].map((meta) => ({ meta }));
|