hd-garden 0.13.3 → 0.14.2
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/.agents/skills/garden-compose/SKILL.md +24 -0
- package/.agents/skills/garden-compose/references/colors.md +11 -0
- package/.agents/skills/garden-compose/references/composition-patterns.md +162 -0
- package/.agents/skills/garden-compose/references/examples.md +55 -0
- package/.agents/skills/garden-compose/references/frames.md +7 -0
- package/.agents/skills/garden-compose/references/layout-recipes.md +84 -0
- package/.agents/skills/garden-compose/references/rendering-model.md +120 -0
- package/.agents/skills/garden-compose/references/static-play.md +19 -0
- package/.agents/skills/garden-compose/references/visual-selection.md +38 -0
- package/.agents/skills/garden-compose/references/workflow.md +27 -0
- package/.agents/skills/garden-compose/scripts/_cli.mjs +12 -0
- package/.agents/skills/garden-compose/scripts/apply.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/check.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/prompt.mjs +2 -0
- package/.agents/skills/garden-compose/scripts/scan.mjs +2 -0
- package/.agents/skills/garden-post-review/SKILL.md +5 -16
- package/Makefile +12 -3
- package/README.en.md +10 -5
- package/README.md +10 -5
- package/app/admin/preview/[...path]/page.tsx +4 -16
- package/app/api/admin/ui/blocks/route.ts +1 -1
- package/app/components/AdminUiPanels.tsx +6 -3
- package/app/components/GardenContentGuide.tsx +7 -8
- package/app/components/MarkdownArticle.tsx +2 -0
- package/app/components/UiStudio.tsx +29 -32
- package/app/components/garden/AuthorRich.tsx +5 -0
- package/app/components/garden/ComposePreview.tsx +9 -0
- package/app/components/garden/GardenBlock.tsx +12 -10
- package/app/components/garden/GardenFile.tsx +1 -1
- package/app/components/garden/blocks.tsx +9 -197
- package/app/components/garden/file-icons.tsx +1 -1
- package/app/components/garden/patterns.tsx +7 -65
- package/app/lib/rehype-garden-blocks.mjs +30 -0
- package/app/lib/remark-garden.mjs +0 -4
- package/app/lib/ui-model.ts +8 -9
- package/app/styles/a2.css +17 -1
- package/bin/garden.mjs +34 -35
- package/docs/handbook/ai-writing.md +19 -22
- package/docs/handbook/components/compose.md +16 -7
- package/docs/handbook/components/image.md +1 -1
- package/docs/handbook/components/link-card.md +2 -2
- package/docs/handbook/components.md +5 -213
- package/docs/handbook/deploy.md +11 -0
- package/docs/handbook/en/ai-writing.md +17 -20
- package/docs/handbook/en/components/compose.md +15 -6
- package/docs/handbook/en/components/image.md +1 -1
- package/docs/handbook/en/components/link-card.md +2 -2
- package/docs/handbook/en/components.md +7 -215
- package/docs/handbook/en/deploy.md +11 -0
- package/docs/handbook/en/index.md +29 -53
- package/docs/handbook/en/reference/compose.md +77 -148
- package/docs/handbook/en/reference.md +6 -22
- package/docs/handbook/en/start.md +1 -1
- package/docs/handbook/en/workflow.md +21 -17
- package/docs/handbook/en/writing.md +3 -3
- package/docs/handbook/index.md +26 -47
- package/docs/handbook/reference/compose.md +79 -148
- package/docs/handbook/reference.md +6 -22
- package/docs/handbook/start.md +1 -1
- package/docs/handbook/workflow.md +21 -17
- package/docs/handbook/writing.md +3 -3
- package/editors/dist/typora/main.js +324 -330
- package/editors/dist/typora/style.css +4299 -11
- package/editors/dist/vscode/garden-ui-0.14.2.vsix +0 -0
- package/eslint.config.mjs +3 -0
- package/package.json +5 -3
- package/public/images/compose-resources/resource-015b41eb0f32.svg +1 -0
- package/public/images/compose-resources/resource-ecee6b47f015.svg +1 -0
- package/public/images/compose-resources/resource-fd51121b5e8c.svg +1 -0
- package/scripts/build-content.mjs +40 -131
- package/scripts/build-ui-preview.mjs +7 -5
- package/scripts/check-post.mjs +10 -106
- package/scripts/check-site.mjs +80 -0
- package/scripts/compose-style-reference.mjs +22 -0
- package/scripts/editor-preview-css.mjs +14 -0
- package/scripts/file-preview.mjs +1 -1
- package/scripts/file-sizes.mjs +7 -7
- package/scripts/generated-cache.mjs +36 -0
- package/scripts/handbook-facts.mjs +10 -3
- package/scripts/image-sizes.mjs +6 -12
- package/scripts/link-assets.mjs +35 -10
- package/scripts/managed-skills.mjs +56 -0
- package/scripts/pack-editors.mjs +12 -1
- package/scripts/prepare-pages-output.mjs +1 -1
- package/scripts/site-guide.mjs +19 -0
- package/scripts/sync-editor-version.mjs +28 -0
- package/scripts/ui-cli.mjs +26 -33
- package/templates/garden-blocks.md +4 -180
- package/templates/garden-snippets.plist +2 -183
- package/templates/site/AGENTS.en.md +89 -0
- package/templates/site/AGENTS.md +72 -0
- package/templates/site/Makefile +12 -3
- package/templates/site/Makefile.en +12 -3
- package/templates/site/README.en.md +6 -1
- package/templates/site/README.md +6 -1
- package/templates/skills-en/garden-compose/SKILL.md +24 -0
- package/templates/skills-en/garden-post-review/SKILL.md +5 -16
- package/templates/workflows/pages.en.yml +11 -0
- package/templates/workflows/pages.yml +11 -0
- package/ui/compose/compose.css +54 -14
- package/ui/compose/contracts.mjs +16 -0
- package/ui/compose/dil.mjs +109 -48
- package/ui/compose/distribution.mjs +7 -0
- package/ui/compose/features.mjs +90 -0
- package/ui/compose/icons.mjs +8 -0
- package/ui/compose/index.mjs +2 -0
- package/ui/compose/inspect.mjs +11 -0
- package/ui/compose/markup.mjs +80 -23
- package/ui/compose/preview.mjs +13 -0
- package/ui/compose/prompt-catalog.mjs +15 -3
- package/ui/compose/render.mjs +46 -11
- package/ui/compose/scenes.mjs +10 -0
- package/ui/core/apply.mjs +12 -45
- package/ui/core/catalog.mjs +22 -32
- package/ui/core/cli-locale.mjs +8 -18
- package/ui/core/color.mjs +34 -0
- package/ui/core/compile.mjs +1 -8
- package/ui/core/demos.mjs +138 -108
- package/ui/core/fence.mjs +14 -70
- package/ui/core/fix-prompt.mjs +1 -3
- package/ui/core/garden-fence.mjs +3 -63
- package/ui/core/index.mjs +3 -5
- package/ui/core/parse.mjs +22 -8
- package/ui/core/scan.mjs +31 -43
- package/ui/core/starters.mjs +3 -3
- package/ui/core/static.mjs +36 -6
- package/ui/core/transform.mjs +64 -149
- package/ui/core/validate.mjs +20 -9
- package/ui/garden/article-content.mjs +98 -0
- package/ui/garden/catalog.mjs +21 -427
- package/ui/garden/check.mjs +18 -60
- package/ui/garden/file-block.mjs +1 -1
- package/ui/garden/file-paths.mjs +8 -6
- package/ui/garden/parse.mjs +19 -182
- package/ui/garden/relations.mjs +1 -1
- package/ui/garden/snippets.mjs +12 -153
- package/ui/garden/source-icon.mjs +17 -9
- package/ui/garden/word-count.mjs +16 -85
- package/ui/index.mjs +1 -5
- package/ui/preview/dist/garden-ui.css +4300 -11
- package/ui/preview/dist/garden-ui.esm.js +446 -418
- package/ui/preview/dist/garden-ui.iife.js +446 -418
- package/ui/preview/index.tsx +31 -98
- package/ui/preview/site-config.ts +4 -0
- package/ui/prompt/build.mjs +1 -4
- package/ui/prompt/recipes/code-walkthrough.md +17 -12
- package/ui/prompt/recipes/compare.md +14 -10
- package/ui/prompt/recipes/compose.md +3 -3
- package/ui/prompt/recipes/converter.md +17 -14
- package/ui/prompt/recipes/data-chart.md +9 -8
- package/ui/prompt/recipes/inspect-grid.md +9 -8
- package/ui/prompt/recipes/param-bench.md +17 -12
- package/ui/prompt/recipes/plan.md +4 -3
- package/ui/prompt/recipes/stepper.md +18 -16
- package/ui/prompt/recipes/trace.md +20 -18
- package/ui/prompt/rules.md +26 -133
- package/ui/prompt/studio.md +3 -18
- package/ui/react/CatalogPage.tsx +19 -21
- package/ui/react/recipes.ts +3 -3
- package/ui/react/runtime.tsx +23 -2
- package/ui/react/ui.css +17 -11
- package/vite.config.ts +16 -3
- package/.agents/skills/garden-interactive-chart/SKILL.md +0 -84
- package/.agents/skills/garden-interactive-chart/references/shell.html +0 -49
- package/.agents/skills/garden-interactive-chart/references/style.md +0 -61
- package/.agents/skills/garden-ui/SKILL.md +0 -125
- package/app/components/UiBlock.tsx +0 -23
- package/app/components/WidgetChart.tsx +0 -224
- package/app/lib/generated-content.ts +0 -385
- package/docs/handbook/components/card.md +0 -67
- package/docs/handbook/components/chart.md +0 -38
- package/docs/handbook/components/choice.md +0 -42
- package/docs/handbook/components/compare.md +0 -53
- package/docs/handbook/components/file.md +0 -29
- package/docs/handbook/components/html.md +0 -49
- package/docs/handbook/components/interactive.md +0 -48
- package/docs/handbook/components/list.md +0 -65
- package/docs/handbook/components/relations.md +0 -95
- package/docs/handbook/components/stat.md +0 -39
- package/docs/handbook/components/timeline.md +0 -37
- package/docs/handbook/en/components/card.md +0 -67
- package/docs/handbook/en/components/chart.md +0 -38
- package/docs/handbook/en/components/choice.md +0 -42
- package/docs/handbook/en/components/compare.md +0 -53
- package/docs/handbook/en/components/file.md +0 -29
- package/docs/handbook/en/components/html.md +0 -49
- package/docs/handbook/en/components/interactive.md +0 -44
- package/docs/handbook/en/components/list.md +0 -65
- package/docs/handbook/en/components/relations.md +0 -95
- package/docs/handbook/en/components/stat.md +0 -39
- package/docs/handbook/en/components/timeline.md +0 -37
- package/docs/handbook/en/reference/card.md +0 -85
- package/docs/handbook/en/reference/chart.md +0 -68
- package/docs/handbook/en/reference/choice.md +0 -69
- package/docs/handbook/en/reference/compare.md +0 -59
- package/docs/handbook/en/reference/file.md +0 -50
- package/docs/handbook/en/reference/html.md +0 -62
- package/docs/handbook/en/reference/interactive.md +0 -71
- package/docs/handbook/en/reference/list.md +0 -72
- package/docs/handbook/en/reference/relations.md +0 -113
- package/docs/handbook/en/reference/stat.md +0 -60
- package/docs/handbook/en/reference/timeline.md +0 -56
- package/docs/handbook/reference/card.md +0 -85
- package/docs/handbook/reference/chart.md +0 -68
- package/docs/handbook/reference/choice.md +0 -69
- package/docs/handbook/reference/compare.md +0 -59
- package/docs/handbook/reference/file.md +0 -50
- package/docs/handbook/reference/html.md +0 -62
- package/docs/handbook/reference/interactive.md +0 -71
- package/docs/handbook/reference/list.md +0 -72
- package/docs/handbook/reference/relations.md +0 -113
- package/docs/handbook/reference/stat.md +0 -60
- package/docs/handbook/reference/timeline.md +0 -56
- package/editors/dist/vscode/garden-ui-0.1.1.vsix +0 -0
- package/templates/skills-en/garden-interactive-chart/SKILL.md +0 -84
- package/templates/skills-en/garden-interactive-chart/references/shell.html +0 -49
- package/templates/skills-en/garden-interactive-chart/references/style.md +0 -61
- package/templates/skills-en/garden-ui/SKILL.md +0 -125
package/ui/core/garden-fence.mjs
CHANGED
|
@@ -1,67 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The `garden` fences the authoring tools act on, next to the older
|
|
5
|
-
* `intent` / `ui` ones:
|
|
6
|
-
* ```garden an idea, one sentence to compile before publishing
|
|
7
|
-
* ```garden interactive #id a compiled interactive block
|
|
8
|
-
* ```garden compose an idea until the body is DIL (Markdown + catalog tags)
|
|
9
|
-
* Other `garden <name>` fences (card, stat, ...) are checked by `garden check`.
|
|
10
|
-
*/
|
|
1
|
+
/** Author fence identification; all component choices live inside Compose. */
|
|
11
2
|
export function gardenKind(fence) {
|
|
12
|
-
|
|
13
|
-
const [name = ""] = fence.info.split(/\s+/u);
|
|
14
|
-
if (!name) return "idea";
|
|
15
|
-
const folded = name.toLowerCase();
|
|
16
|
-
if (folded === "interactive") return "interactive";
|
|
17
|
-
if (folded === "compose") return "compose";
|
|
18
|
-
return null;
|
|
3
|
+
return fence.lang === "garden" && /^compose(?:\s|$)/iu.test(fence.info??"") ? "compose" : null;
|
|
19
4
|
}
|
|
20
|
-
|
|
21
|
-
/** `#id` on the info line wins over an `id:` key. */
|
|
22
5
|
export function gardenInfoId(info) {
|
|
23
|
-
return /(?:^|\s)#([\w-]+)/u.exec(String(info
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Splits a `garden interactive` body into the YAML keys and the component tree. */
|
|
27
|
-
export function splitInteractiveBody(body) {
|
|
28
|
-
const lines = String(body ?? "").replace(/\r\n?/gu, "\n").split("\n");
|
|
29
|
-
const sep = lines.findIndex((line, index) => index > 0 && /^---\s*$/u.test(line));
|
|
30
|
-
if (sep < 0) return { yamlText: lines.join("\n"), children: "", childrenLine: lines.length + 1 };
|
|
31
|
-
return { yamlText: lines.slice(0, sep).join("\n"), children: lines.slice(sep + 1).join("\n"), childrenLine: sep + 2 };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The `ui` block source a `garden interactive` stands for. The reading page
|
|
36
|
-
* and `garden ui check` both validate this same text, so they cannot disagree.
|
|
37
|
-
*/
|
|
38
|
-
export function interactiveUiSource({ id, props = {}, children = "" }) {
|
|
39
|
-
const header = {
|
|
40
|
-
id: id || props.id || "interactive",
|
|
41
|
-
caption: props.caption ?? "",
|
|
42
|
-
intent: props.intent ?? "",
|
|
43
|
-
...(props.expect ? { expect: props.expect } : {}),
|
|
44
|
-
};
|
|
45
|
-
const yaml = stringify(header);
|
|
46
|
-
return { source: `---\n${yaml}---\n${children ?? ""}`, header, childrenLine: yaml.split("\n").length - 1 + 3 };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Reads one `garden interactive` fence: id, props, ui source and a line mapper. */
|
|
50
|
-
export function readInteractiveFence(fence) {
|
|
51
|
-
const { yamlText, children, childrenLine } = splitInteractiveBody(fence.body);
|
|
52
|
-
let props = {};
|
|
53
|
-
let yamlError = null;
|
|
54
|
-
try {
|
|
55
|
-
const parsed = yamlText.trim() ? parseYaml(yamlText) : {};
|
|
56
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) props = parsed;
|
|
57
|
-
else yamlError = "YAML 必须是一组键值";
|
|
58
|
-
} catch (error) {
|
|
59
|
-
yamlError = `YAML 解析失败:${error instanceof Error ? error.message.split("\n")[0] : "解析失败"}`;
|
|
60
|
-
}
|
|
61
|
-
const id = gardenInfoId(fence.info) ?? (typeof props.id === "string" ? props.id : null);
|
|
62
|
-
const ui = interactiveUiSource({ id, props, children });
|
|
63
|
-
// A line in the ui source → the line in the Markdown file.
|
|
64
|
-
const toFileLine = (sourceLine) =>
|
|
65
|
-
sourceLine >= ui.childrenLine ? fence.startLine + childrenLine + (sourceLine - ui.childrenLine) : fence.startLine;
|
|
66
|
-
return { id, props, yamlError, source: ui.source, toFileLine };
|
|
6
|
+
return /(?:^|\s)#([\w-]+)/u.exec(String(info??""))?.[1]??null;
|
|
67
7
|
}
|
package/ui/core/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { applyBlock, ApplyError, classifyReplacement } from "./apply.mjs";
|
|
2
|
-
export { CATALOG_VERSION,
|
|
3
|
-
export { compileUiBlock,
|
|
2
|
+
export { CATALOG_VERSION, catalogSchema, COMPONENTS, COMPONENT_NAMES, GROUPS, TONES, TONE_LABELS } from "./catalog.mjs";
|
|
3
|
+
export { compileUiBlock, PAYLOAD_VERSION, readPayload } from "./compile.mjs";
|
|
4
4
|
export { analyzeExpr, createBudget, evaluate, ExprError, FUNCTION_NAMES } from "./expr.mjs";
|
|
5
5
|
export {
|
|
6
|
-
compiledOf,
|
|
7
6
|
fenceHash,
|
|
8
7
|
findBlocks,
|
|
9
8
|
ID_PATTERN,
|
|
@@ -13,13 +12,12 @@ export {
|
|
|
13
12
|
normalizeNewlines,
|
|
14
13
|
resolveSidecarPath,
|
|
15
14
|
scanFences,
|
|
16
|
-
setCompiled,
|
|
17
15
|
splitUiBody,
|
|
18
16
|
} from "./fence.mjs";
|
|
19
17
|
export { bits32, bits64, bytes, fixed, float32, formatValue, isValidFormat, percent, si, thousands } from "./format.mjs";
|
|
20
18
|
export { parseUiBody, parseUiBodyPartial } from "./parse.mjs";
|
|
21
19
|
export { blockStatus, scanMarkdown } from "./scan.mjs";
|
|
22
|
-
export {
|
|
20
|
+
export { composeFence, STARTERS } from "./starters.mjs";
|
|
23
21
|
export { docToHtml, docToMarkdown, docToText, renderStatic, toDoc } from "./static.mjs";
|
|
24
22
|
export {
|
|
25
23
|
collectDecls,
|
package/ui/core/parse.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ARTICLE_TAGS, articleParseExtensions, articleUrl, renderArticleContent } from "../garden/article-content.mjs";
|
|
1
2
|
import * as acorn from "acorn";
|
|
2
3
|
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
3
4
|
import { mdxExpressionFromMarkdown } from "mdast-util-mdx-expression";
|
|
@@ -9,12 +10,13 @@ import { pruneExpr } from "./expr.mjs";
|
|
|
9
10
|
|
|
10
11
|
const parseOptions = {
|
|
11
12
|
extensions: [
|
|
13
|
+
...articleParseExtensions().extensions,
|
|
12
14
|
mdxJsx({ acorn, addResult: true }),
|
|
13
15
|
mdxExpression({ acorn, addResult: true }),
|
|
14
16
|
// Same as MDX: indentation inside elements must not become code blocks.
|
|
15
17
|
{ disable: { null: ["autolink", "codeIndented", "htmlFlow", "htmlText"] } },
|
|
16
18
|
],
|
|
17
|
-
mdastExtensions: [mdxJsxFromMarkdown(), mdxExpressionFromMarkdown()],
|
|
19
|
+
mdastExtensions: [...articleParseExtensions().mdastExtensions, mdxJsxFromMarkdown(), mdxExpressionFromMarkdown()],
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
const lineOf = (node) => node?.position?.start?.line ?? 1;
|
|
@@ -29,7 +31,7 @@ function errorLine(error) {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
const isBlockElement = (node) =>
|
|
32
|
-
node.t === "el" && !(COMPONENTS[node.n]?.inline);
|
|
34
|
+
node.t === "rich-block" || node.t === "el" && !(COMPONENTS[node.n]?.inline);
|
|
33
35
|
|
|
34
36
|
function expressionFrom(estree) {
|
|
35
37
|
const statement = estree?.body?.[0];
|
|
@@ -81,6 +83,12 @@ export function parseUiBody(text) {
|
|
|
81
83
|
return props;
|
|
82
84
|
};
|
|
83
85
|
|
|
86
|
+
const rich = (node, block = false) => {
|
|
87
|
+
const source = text.slice(node.position.start.offset, node.position.end.offset);
|
|
88
|
+
try { renderArticleContent(source, { inline: !block }); }
|
|
89
|
+
catch (error) { report("compose-content", lineOf(node), error.message); }
|
|
90
|
+
return { t: block ? "rich-block" : "rich", v: source, l: lineOf(node) };
|
|
91
|
+
};
|
|
84
92
|
const convertInline = (node) => {
|
|
85
93
|
switch (node.type) {
|
|
86
94
|
case "text":
|
|
@@ -94,6 +102,8 @@ export function parseUiBody(text) {
|
|
|
94
102
|
}
|
|
95
103
|
return [{ t: "x", e: expression, s: node.value, l: lineOf(node) }];
|
|
96
104
|
}
|
|
105
|
+
case "delete":
|
|
106
|
+
return [rich(node)];
|
|
97
107
|
case "strong":
|
|
98
108
|
return [{ t: "strong", c: node.children.flatMap(convertInline) }];
|
|
99
109
|
case "emphasis":
|
|
@@ -104,8 +114,9 @@ export function parseUiBody(text) {
|
|
|
104
114
|
return [{ t: "br" }];
|
|
105
115
|
case "link": {
|
|
106
116
|
const url = String(node.url ?? "");
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
try { articleUrl(url); }
|
|
118
|
+
catch (error) {
|
|
119
|
+
report("ui-markdown", lineOf(node), error.message);
|
|
109
120
|
return node.children.flatMap(convertInline);
|
|
110
121
|
}
|
|
111
122
|
return [{ t: "link", u: url, c: node.children.flatMap(convertInline) }];
|
|
@@ -179,11 +190,9 @@ export function parseUiBody(text) {
|
|
|
179
190
|
case "thematicBreak":
|
|
180
191
|
return [{ t: "hr" }];
|
|
181
192
|
case "heading":
|
|
182
|
-
report("ui-markdown", lineOf(node), "块里不能写标题,它会打乱文章目录");
|
|
183
|
-
return [];
|
|
184
193
|
case "code":
|
|
185
|
-
|
|
186
|
-
return [];
|
|
194
|
+
case "table":
|
|
195
|
+
return [rich(node, true)];
|
|
187
196
|
case "html":
|
|
188
197
|
report("ui-markdown", lineOf(node), "块里不能写 HTML");
|
|
189
198
|
return [];
|
|
@@ -198,6 +207,11 @@ export function parseUiBody(text) {
|
|
|
198
207
|
|
|
199
208
|
function convertElement(node) {
|
|
200
209
|
const name = node.name ?? "";
|
|
210
|
+
if (ARTICLE_TAGS.has(name) && !COMPONENTS[name]) {
|
|
211
|
+
const hasDynamic = value => value.type?.includes("Expression") || value.attributes?.some(attribute => attribute.value?.type === "mdxJsxAttributeValueExpression") || value.children?.some(hasDynamic);
|
|
212
|
+
if (hasDynamic(node)) report("compose-content", lineOf(node), "HTML 内容必须静态;将状态插值放在相邻 Compose 内容中,不要在 HTML 标签内写表达式。");
|
|
213
|
+
return rich(node, !["u", "span", "b", "i", "strong", "em", "del", "s", "code", "kbd", "mark", "sub", "sup", "small", "a", "br"].includes(name));
|
|
214
|
+
}
|
|
201
215
|
if (!name) report("ui-syntax", lineOf(node), "块里不能写空标签 <>");
|
|
202
216
|
let children;
|
|
203
217
|
if (node.type === "mdxJsxTextElement") {
|
package/ui/core/scan.mjs
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { parseCompose } from "../compose/parse.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { AUTHOR_PLAY_TAGS, looksLikePlayCompose, parsePlayCompose } from "../compose/dil.mjs";
|
|
3
|
+
import { fenceHash, findBlocks, idOf, intentHash, intentOf } from "./fence.mjs";
|
|
3
4
|
import { checkUiBlock } from "./validate.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/** Diagnostics of a `garden interactive`, on file lines. */
|
|
7
|
-
export function checkInteractiveFence(block, options = {}) {
|
|
8
|
-
const read = readInteractiveFence(block);
|
|
9
|
-
if (read.yamlError) {
|
|
10
|
-
return { ok: false, diagnostics: [{ code: "garden-yaml", line: block.startLine, message: read.yamlError, severity: "error" }] };
|
|
11
|
-
}
|
|
12
|
-
const check = checkUiBlock(read.source, { ...options, lineOffset: 0 });
|
|
13
|
-
return { ...check, diagnostics: check.diagnostics.map((item) => ({ ...item, line: read.toFileLine(item.line) })) };
|
|
14
|
-
}
|
|
5
|
+
import { gardenInfoId } from "./garden-fence.mjs";
|
|
15
6
|
|
|
16
7
|
/** A `garden compose` fence whose body is still prose, or a DIL tree that fails the catalog. */
|
|
17
|
-
export function checkComposeFence(block) {
|
|
8
|
+
export function checkComposeFence(block, options = {}) {
|
|
9
|
+
if (looksLikePlayCompose(block.body)) {
|
|
10
|
+
const parsed = parsePlayCompose({ id: gardenInfoId(block.info) }, block.body);
|
|
11
|
+
if (parsed.error) return { ok: false, uncompiled: false, doc: null, diagnostics: [{ ...parsed.error, line: block.startLine, severity: "error" }] };
|
|
12
|
+
const check = checkUiBlock(parsed.uiSource, { ...options, lineOffset: 0 });
|
|
13
|
+
const authorNames = Object.fromEntries(Object.entries(AUTHOR_PLAY_TAGS).map(([author, internal]) => [internal, author]));
|
|
14
|
+
const authorTags = value => value.replace(/<(\/?)([A-Z][A-Za-z0-9]*)/gu, (whole, slash, name) => authorNames[name] ? `<${slash}${authorNames[name]}` : whole);
|
|
15
|
+
const bodyLines = block.body.split(/\r?\n/u);
|
|
16
|
+
const loweredLines = parsed.uiSource.split("\n");
|
|
17
|
+
const diagnostics = check.diagnostics.map(item => {
|
|
18
|
+
// Report an exact author line only when the emitted line survives uniquely.
|
|
19
|
+
// Declarations/control lowering can synthesize lines: those stay at the fence,
|
|
20
|
+
// rather than falsely presenting internal IR coordinates as article positions.
|
|
21
|
+
const emitted = authorTags(loweredLines[item.line - 1] ?? "").trim();
|
|
22
|
+
const matches = emitted ? bodyLines.flatMap((line, index) => line.trim() === emitted ? [index] : []) : [];
|
|
23
|
+
return {
|
|
24
|
+
...item,
|
|
25
|
+
line: matches.length === 1 ? block.startLine + 1 + matches[0] : block.startLine,
|
|
26
|
+
message: authorTags(item.message),
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
return { ...check, uncompiled: false, doc: parsed.props, diagnostics };
|
|
30
|
+
}
|
|
18
31
|
const result = parseCompose(block.body);
|
|
19
32
|
if (result.uncompiled) return { ok: false, uncompiled: true, diagnostics: [], doc: null };
|
|
20
33
|
if (!result.ok) {
|
|
@@ -28,22 +41,9 @@ export function checkComposeFence(block) {
|
|
|
28
41
|
return { ok: true, uncompiled: false, diagnostics: [], doc: result.doc };
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
/** Status of one block: uncompiled /
|
|
32
|
-
export function blockStatus(block,
|
|
33
|
-
|
|
34
|
-
if (block.lang === "garden-compose") {
|
|
35
|
-
if (check?.uncompiled) return "uncompiled";
|
|
36
|
-
return check && !check.ok ? "error" : "ok";
|
|
37
|
-
}
|
|
38
|
-
if (block.lang === "garden-interactive") return check && !check.ok ? "error" : "ok";
|
|
39
|
-
if (block.lang === "ui") {
|
|
40
|
-
if (check && !check.ok) return "error";
|
|
41
|
-
const { header, headerText } = splitUiBody(block.body);
|
|
42
|
-
const compiled = compiledOf(headerText);
|
|
43
|
-
if (typeof header?.intent === "string" && compiled !== undefined && compiled !== intentHash(header.intent)) return "stale";
|
|
44
|
-
return "ok";
|
|
45
|
-
}
|
|
46
|
-
return "ok";
|
|
44
|
+
/** Status of one block: uncompiled / error / ok. */
|
|
45
|
+
export function blockStatus(block,check) {
|
|
46
|
+
return check?.uncompiled?"uncompiled":check&&!check.ok?"error":"ok";
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function sectionTitle(lines, startLine) {
|
|
@@ -63,20 +63,8 @@ export function scanMarkdown(markdown, options = {}) {
|
|
|
63
63
|
const lines = markdown.split(/\r?\n/u);
|
|
64
64
|
return findBlocks(markdown).map((block) => {
|
|
65
65
|
const intent = intentOf(block);
|
|
66
|
-
const check
|
|
67
|
-
|
|
68
|
-
: block.lang === "garden-interactive"
|
|
69
|
-
? checkInteractiveFence(block, { markdownPath, readData, skipData })
|
|
70
|
-
: block.lang === "garden-compose"
|
|
71
|
-
? checkComposeFence(block)
|
|
72
|
-
: null;
|
|
73
|
-
const header = block.lang === "ui"
|
|
74
|
-
? splitUiBody(block.body).header
|
|
75
|
-
: block.lang === "garden-interactive"
|
|
76
|
-
? readInteractiveFence(block).props
|
|
77
|
-
: block.lang === "garden-compose"
|
|
78
|
-
? check?.doc
|
|
79
|
-
: null;
|
|
66
|
+
const check=checkComposeFence(block,{markdownPath,readData,skipData});
|
|
67
|
+
const header=check.doc;
|
|
80
68
|
return {
|
|
81
69
|
lang: block.lang,
|
|
82
70
|
id: idOf(block),
|
package/ui/core/starters.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Spoken starters for "insert
|
|
2
|
+
* Spoken starters for "insert a Compose brief". Editors show `label`, insert
|
|
3
3
|
* `text`; component names never appear, authors only describe what readers do.
|
|
4
4
|
*/
|
|
5
5
|
export const STARTERS = [
|
|
@@ -13,6 +13,6 @@ export const STARTERS = [
|
|
|
13
13
|
];
|
|
14
14
|
|
|
15
15
|
/** The fence an editor inserts; `text` may be empty for a blank block. */
|
|
16
|
-
export function
|
|
17
|
-
return `\`\`\`
|
|
16
|
+
export function composeFence(text = "") {
|
|
17
|
+
return `\`\`\`garden compose\n${text}\n\`\`\`\n`;
|
|
18
18
|
}
|
package/ui/core/static.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {composeMarkdown} from "../compose/distribution.mjs";
|
|
2
|
+
import { parseCompose, renderCompose, composeText } from "../compose/index.mjs";
|
|
3
|
+
import { articleContentText, articleUrl, renderArticleContent } from "../garden/article-content.mjs";
|
|
1
4
|
import { TONE_LABELS } from "./catalog.mjs";
|
|
2
5
|
import { createBudget, evaluate } from "./expr.mjs";
|
|
3
6
|
import { formatValue } from "./format.mjs";
|
|
@@ -80,6 +83,8 @@ export function toDoc(payload) {
|
|
|
80
83
|
}
|
|
81
84
|
return [text(formatValue(result))];
|
|
82
85
|
}
|
|
86
|
+
case "rich":
|
|
87
|
+
return [{ k: "rich", source: node.v ?? "" }];
|
|
83
88
|
case "strong":
|
|
84
89
|
return [{ k: "b", c: inlines(node.c, ctx) }];
|
|
85
90
|
case "em":
|
|
@@ -92,6 +97,8 @@ export function toDoc(payload) {
|
|
|
92
97
|
return [{ k: "a", href: node.u, c: inlines(node.c, ctx) }];
|
|
93
98
|
case "p":
|
|
94
99
|
return inlines(node.c, ctx);
|
|
100
|
+
case "rich-block":
|
|
101
|
+
return [{ k: "content", source: node.v ?? "" }];
|
|
95
102
|
case "el":
|
|
96
103
|
if (node.n === "Badge") return [text(`[${plainInline(inlines(node.c, ctx))}]`)];
|
|
97
104
|
if (node.n === "Cite") return [text(value(node, "label", ctx) ?? "")];
|
|
@@ -146,6 +153,8 @@ export function toDoc(payload) {
|
|
|
146
153
|
case "text":
|
|
147
154
|
case "x":
|
|
148
155
|
return [{ k: "p", inl: inlines([node], ctx) }];
|
|
156
|
+
case "rich-block":
|
|
157
|
+
return [{ k: "content", source: node.v ?? "" }];
|
|
149
158
|
case "el":
|
|
150
159
|
return element(node, ctx);
|
|
151
160
|
default:
|
|
@@ -356,6 +365,10 @@ export function toDoc(payload) {
|
|
|
356
365
|
: []),
|
|
357
366
|
];
|
|
358
367
|
}
|
|
368
|
+
case "Scene":
|
|
369
|
+
return [{k:"scene",doc:parseCompose(String(v("source")??"")).doc}];
|
|
370
|
+
case "Content":
|
|
371
|
+
return [{ k: "content", source: String(v("source") ?? "") }];
|
|
359
372
|
case "Code": {
|
|
360
373
|
const highlight = v("highlight");
|
|
361
374
|
return [
|
|
@@ -381,6 +394,7 @@ export function toDoc(payload) {
|
|
|
381
394
|
export function plainInline(inline) {
|
|
382
395
|
return inline.map((item) => {
|
|
383
396
|
if (item.k === "t") return item.v;
|
|
397
|
+
if (item.k === "rich") return articleContentText(item.source);
|
|
384
398
|
if (item.k === "code") return item.v;
|
|
385
399
|
if (item.k === "br") return " ";
|
|
386
400
|
if (item.c) return plainInline(item.c);
|
|
@@ -391,11 +405,13 @@ export function plainInline(inline) {
|
|
|
391
405
|
const escapeHtml = (value) =>
|
|
392
406
|
String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
393
407
|
|
|
394
|
-
const safeHref = (href) =>
|
|
408
|
+
const safeHref = (href) => { try { return articleUrl(href); } catch { return "#"; } };
|
|
395
409
|
|
|
396
410
|
function inlineHtml(inline) {
|
|
397
411
|
return inline.map((item) => {
|
|
398
412
|
switch (item.k) {
|
|
413
|
+
case "rich":
|
|
414
|
+
return renderArticleContent(item.source, { inline: true });
|
|
399
415
|
case "t":
|
|
400
416
|
return escapeHtml(item.v);
|
|
401
417
|
case "b":
|
|
@@ -417,6 +433,10 @@ function inlineHtml(inline) {
|
|
|
417
433
|
export function docToHtml(doc) {
|
|
418
434
|
return doc.map((block) => {
|
|
419
435
|
switch (block.k) {
|
|
436
|
+
case "scene":
|
|
437
|
+
return renderCompose({...block.doc,frame:"none"});
|
|
438
|
+
case "content":
|
|
439
|
+
return renderArticleContent(block.source);
|
|
420
440
|
case "p":
|
|
421
441
|
return `<p>${inlineHtml(block.inl)}</p>`;
|
|
422
442
|
case "list": {
|
|
@@ -446,6 +466,8 @@ const escapeMarkdown = (value) => String(value).replace(/([\\`*_[\]<>|])/gu, "\\
|
|
|
446
466
|
function inlineMarkdown(inline) {
|
|
447
467
|
return inline.map((item) => {
|
|
448
468
|
switch (item.k) {
|
|
469
|
+
case "rich":
|
|
470
|
+
return item.source;
|
|
449
471
|
case "t":
|
|
450
472
|
return escapeMarkdown(item.v);
|
|
451
473
|
case "b":
|
|
@@ -464,19 +486,23 @@ function inlineMarkdown(inline) {
|
|
|
464
486
|
}).join("");
|
|
465
487
|
}
|
|
466
488
|
|
|
467
|
-
export function docToMarkdown(doc, indent = "") {
|
|
489
|
+
export function docToMarkdown(doc, indent = "",options={}) {
|
|
468
490
|
return doc.map((block) => {
|
|
469
491
|
switch (block.k) {
|
|
492
|
+
case "scene":
|
|
493
|
+
return `${indent}${composeMarkdown(block.doc,options)}`;
|
|
494
|
+
case "content":
|
|
495
|
+
return `${indent}${block.source}`;
|
|
470
496
|
case "p":
|
|
471
497
|
return `${indent}${inlineMarkdown(block.inl)}`;
|
|
472
498
|
case "list":
|
|
473
499
|
return block.items.map((item, index) => {
|
|
474
500
|
const bullet = block.ordered ? `${index + 1}. ` : "- ";
|
|
475
|
-
const body = docToMarkdown(item, `${indent}${" ".repeat(bullet.length)}
|
|
501
|
+
const body = docToMarkdown(item, `${indent}${" ".repeat(bullet.length)}`,options).trimStart();
|
|
476
502
|
return `${indent}${bullet}${body}`;
|
|
477
503
|
}).join("\n");
|
|
478
504
|
case "quote":
|
|
479
|
-
return docToMarkdown(block.blocks).split("\n").map((line) => `${indent}> ${line}`).join("\n");
|
|
505
|
+
return docToMarkdown(block.blocks,"",options).split("\n").map((line) => `${indent}> ${line}`).join("\n");
|
|
480
506
|
case "hr":
|
|
481
507
|
return `${indent}---`;
|
|
482
508
|
case "table": {
|
|
@@ -500,6 +526,10 @@ export function docToMarkdown(doc, indent = "") {
|
|
|
500
526
|
export function docToText(doc) {
|
|
501
527
|
return doc.map((block) => {
|
|
502
528
|
switch (block.k) {
|
|
529
|
+
case "scene":
|
|
530
|
+
return composeText(block.doc);
|
|
531
|
+
case "content":
|
|
532
|
+
return articleContentText(block.source);
|
|
503
533
|
case "p":
|
|
504
534
|
return plainInline(block.inl);
|
|
505
535
|
case "list":
|
|
@@ -518,9 +548,9 @@ export function docToText(doc) {
|
|
|
518
548
|
}).filter(Boolean).join(" ");
|
|
519
549
|
}
|
|
520
550
|
|
|
521
|
-
export function renderStatic(payload, format = "html") {
|
|
551
|
+
export function renderStatic(payload, format = "html",options={}) {
|
|
522
552
|
const doc = toDoc(payload);
|
|
523
|
-
if (format === "markdown") return docToMarkdown(doc);
|
|
553
|
+
if (format === "markdown") return docToMarkdown(doc,"",options);
|
|
524
554
|
if (format === "text") return docToText(doc);
|
|
525
555
|
return docToHtml(doc);
|
|
526
556
|
}
|