mdx-artifacts 0.1.1 → 0.2.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.
Files changed (142) hide show
  1. package/README.md +224 -60
  2. package/README.zh-CN.md +299 -42
  3. package/agents/AGENTS.snippet.md +21 -10
  4. package/artifact-docs/examples/commentable-feedback.mdx +76 -70
  5. package/artifact-docs/examples/decision-matrix.mdx +122 -50
  6. package/artifact-docs/examples/layout-composition.mdx +106 -128
  7. package/artifact-docs/examples/streamlit-style-mixed.mdx +100 -85
  8. package/dist/lib/cli/{build.js → commands/build.js} +2 -2
  9. package/dist/lib/cli/{components.js → commands/components.js} +19 -3
  10. package/dist/lib/cli/{dev.js → commands/dev.js} +2 -2
  11. package/dist/lib/cli/commands/interactions.d.ts +2 -0
  12. package/dist/lib/cli/commands/interactions.js +280 -0
  13. package/dist/lib/cli/commands/review.d.ts +1 -0
  14. package/dist/lib/cli/commands/review.js +171 -0
  15. package/dist/lib/cli/commands/scaffold.d.ts +16 -0
  16. package/dist/lib/cli/commands/scaffold.js +440 -0
  17. package/dist/lib/cli/commands/validate.d.ts +18 -0
  18. package/dist/lib/cli/commands/validate.js +311 -0
  19. package/dist/lib/cli/config/config.d.ts +2 -0
  20. package/dist/lib/cli/{config.js → config/config.js} +3 -2
  21. package/dist/lib/cli/{types.d.ts → config/types.d.ts} +2 -1
  22. package/dist/lib/cli/{vite-artifact.d.ts → dev-server/vite-artifact.d.ts} +3 -3
  23. package/dist/lib/cli/dev-server/vite-artifact.js +415 -0
  24. package/dist/lib/cli/diagnostics/diagnostics.d.ts +11 -0
  25. package/dist/lib/cli/diagnostics/diagnostics.js +1 -0
  26. package/dist/lib/cli/index.js +39 -18
  27. package/dist/lib/cli/mdx/sortable-list.d.ts +14 -0
  28. package/dist/lib/cli/mdx/sortable-list.js +520 -0
  29. package/dist/lib/cli/resources/resource-policy.d.ts +15 -0
  30. package/dist/lib/cli/resources/resource-policy.js +46 -0
  31. package/dist/lib/cli/resources/safe-path.d.ts +13 -0
  32. package/dist/lib/cli/resources/safe-path.js +55 -0
  33. package/dist/lib/cli/services/interaction-service.d.ts +40 -0
  34. package/dist/lib/cli/services/interaction-service.js +226 -0
  35. package/dist/lib/cli/services/review.d.ts +43 -0
  36. package/dist/lib/cli/{review.js → services/review.js} +34 -172
  37. package/dist/lib/react/{components → composites/comparison-set}/ComparisonSet.d.ts +1 -1
  38. package/dist/lib/react/{components → composites/comparison-set}/ComparisonSet.js +3 -3
  39. package/dist/lib/react/composites/comparison-set/index.d.ts +2 -0
  40. package/dist/lib/react/composites/comparison-set/index.js +1 -0
  41. package/dist/lib/react/composites/content-set/ContentItem.d.ts +37 -0
  42. package/dist/lib/react/composites/content-set/ContentItem.js +49 -0
  43. package/dist/lib/react/composites/content-set/index.d.ts +2 -0
  44. package/dist/lib/react/composites/content-set/index.js +1 -0
  45. package/dist/lib/react/{components → composites/export-panel}/ExportPanel.js +2 -2
  46. package/dist/lib/react/composites/export-panel/index.d.ts +2 -0
  47. package/dist/lib/react/composites/export-panel/index.js +1 -0
  48. package/dist/lib/react/{components → composites/section}/Section.js +1 -1
  49. package/dist/lib/react/composites/section/index.d.ts +2 -0
  50. package/dist/lib/react/composites/section/index.js +1 -0
  51. package/dist/lib/react/index.d.ts +36 -31
  52. package/dist/lib/react/index.js +18 -15
  53. package/dist/lib/react/interactions/artifact-state/index.d.ts +1 -0
  54. package/dist/lib/react/interactions/artifact-state/index.js +1 -0
  55. package/dist/lib/react/{components → interactions/comments}/Comments.d.ts +2 -2
  56. package/dist/lib/react/{components → interactions/comments}/Comments.js +3 -3
  57. package/dist/lib/react/interactions/comments/index.d.ts +1 -0
  58. package/dist/lib/react/interactions/comments/index.js +1 -0
  59. package/dist/lib/react/interactions/sortable-list/SortableList.d.ts +29 -0
  60. package/dist/lib/react/interactions/sortable-list/SortableList.js +282 -0
  61. package/dist/lib/react/interactions/sortable-list/index.d.ts +1 -0
  62. package/dist/lib/react/interactions/sortable-list/index.js +1 -0
  63. package/dist/lib/react/layout/layout-primitives/index.d.ts +2 -0
  64. package/dist/lib/react/layout/layout-primitives/index.js +1 -0
  65. package/dist/lib/react/legacy/LegacyContentComponents.d.ts +65 -0
  66. package/dist/lib/react/legacy/LegacyContentComponents.js +26 -0
  67. package/dist/lib/react/mdx-components.d.ts +5 -0
  68. package/dist/lib/react/mdx-components.js +38 -0
  69. package/dist/lib/react/{components → primitives/annotated-code}/AnnotatedCode.d.ts +1 -1
  70. package/dist/lib/react/{components → primitives/annotated-code}/AnnotatedCode.js +5 -5
  71. package/dist/lib/react/primitives/annotated-code/index.d.ts +2 -0
  72. package/dist/lib/react/primitives/annotated-code/index.js +1 -0
  73. package/dist/lib/react/primitives/callout/Callout.d.ts +11 -0
  74. package/dist/lib/react/{components → primitives/callout}/Callout.js +9 -6
  75. package/dist/lib/react/primitives/callout/index.d.ts +2 -0
  76. package/dist/lib/react/primitives/callout/index.js +1 -0
  77. package/dist/lib/react/primitives/code-block/CodeBlock.d.ts +20 -0
  78. package/dist/lib/react/primitives/code-block/CodeBlock.js +32 -0
  79. package/dist/lib/react/primitives/code-block/index.d.ts +2 -0
  80. package/dist/lib/react/primitives/code-block/index.js +1 -0
  81. package/dist/lib/react/primitives/code-surface/CodeSurface.d.ts +11 -0
  82. package/dist/lib/react/primitives/code-surface/CodeSurface.js +34 -0
  83. package/dist/lib/react/primitives/code-surface/index.d.ts +2 -0
  84. package/dist/lib/react/primitives/code-surface/index.js +1 -0
  85. package/dist/lib/react/primitives/diff-block/DiffBlock.js +25 -0
  86. package/dist/lib/react/primitives/diff-block/index.d.ts +2 -0
  87. package/dist/lib/react/primitives/diff-block/index.js +1 -0
  88. package/dist/lib/react/{components → primitives/inline-text}/InlineText.d.ts +4 -2
  89. package/dist/lib/react/primitives/inline-text/InlineText.js +28 -0
  90. package/dist/lib/react/primitives/inline-text/index.d.ts +2 -0
  91. package/dist/lib/react/primitives/inline-text/index.js +1 -0
  92. package/dist/lib/react/primitives/markdown-body/MarkdownBody.d.ts +9 -0
  93. package/dist/lib/react/primitives/markdown-body/MarkdownBody.js +49 -0
  94. package/dist/lib/react/primitives/markdown-body/index.d.ts +2 -0
  95. package/dist/lib/react/primitives/markdown-body/index.js +1 -0
  96. package/dist/lib/react/primitives/severity-badge/index.d.ts +2 -0
  97. package/dist/lib/react/primitives/severity-badge/index.js +1 -0
  98. package/dist/lib/react/registry.d.ts +10 -0
  99. package/dist/lib/react/registry.js +505 -210
  100. package/dist/lib/react/styles.css +490 -38
  101. package/docs/cli-structure.md +141 -0
  102. package/docs/component-protocol.md +199 -33
  103. package/docs/component-taxonomy.md +40 -4
  104. package/docs/design.md +42 -21
  105. package/docs/design.zh-CN.md +41 -21
  106. package/docs/naming.md +17 -7
  107. package/docs/releasing.md +132 -0
  108. package/docs/testing.md +35 -10
  109. package/package.json +9 -7
  110. package/dist/lib/cli/config.d.ts +0 -2
  111. package/dist/lib/cli/review.d.ts +0 -33
  112. package/dist/lib/cli/scaffold.d.ts +0 -1
  113. package/dist/lib/cli/scaffold.js +0 -56
  114. package/dist/lib/cli/validate.d.ts +0 -6
  115. package/dist/lib/cli/validate.js +0 -79
  116. package/dist/lib/cli/vite-artifact.js +0 -237
  117. package/dist/lib/react/components/Callout.d.ts +0 -9
  118. package/dist/lib/react/components/CodeBlock.d.ts +0 -10
  119. package/dist/lib/react/components/CodeBlock.js +0 -28
  120. package/dist/lib/react/components/DecisionMatrix.d.ts +0 -16
  121. package/dist/lib/react/components/DecisionMatrix.js +0 -27
  122. package/dist/lib/react/components/DiffBlock.js +0 -24
  123. package/dist/lib/react/components/InlineText.js +0 -18
  124. package/dist/lib/react/components/MarkdownBody.d.ts +0 -7
  125. package/dist/lib/react/components/MarkdownBody.js +0 -36
  126. package/dist/lib/react/components/OptionGrid.d.ts +0 -13
  127. package/dist/lib/react/components/OptionGrid.js +0 -21
  128. /package/dist/lib/cli/{build.d.ts → commands/build.d.ts} +0 -0
  129. /package/dist/lib/cli/{components.d.ts → commands/components.d.ts} +0 -0
  130. /package/dist/lib/cli/{dev.d.ts → commands/dev.d.ts} +0 -0
  131. /package/dist/lib/cli/{types.js → config/types.js} +0 -0
  132. /package/dist/lib/cli/{artifact-state.d.ts → state/artifact-state.d.ts} +0 -0
  133. /package/dist/lib/cli/{artifact-state.js → state/artifact-state.js} +0 -0
  134. /package/dist/lib/react/{components → composites/export-panel}/ExportPanel.d.ts +0 -0
  135. /package/dist/lib/react/{components → composites/section}/Section.d.ts +0 -0
  136. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.d.ts +0 -0
  137. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.js +0 -0
  138. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.d.ts +0 -0
  139. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.js +0 -0
  140. /package/dist/lib/react/{components → primitives/diff-block}/DiffBlock.d.ts +0 -0
  141. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.d.ts +0 -0
  142. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.js +0 -0
@@ -1,237 +0,0 @@
1
- import mdx from "@mdx-js/rollup";
2
- import tailwindcss from "@tailwindcss/vite";
3
- import react from "@vitejs/plugin-react";
4
- import { randomUUID } from "node:crypto";
5
- import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
6
- import { createRequire } from "node:module";
7
- import path from "node:path";
8
- import { fileURLToPath } from "node:url";
9
- import { createServer, build as viteBuild } from "vite";
10
- import { createArtifactMeta, createArtifactRoute, readArtifactState, writeArtifactState } from "./artifact-state.js";
11
- const packageCliDir = path.dirname(fileURLToPath(import.meta.url));
12
- const defaultStylesPath = path.resolve(packageCliDir, "../react/styles.css");
13
- export async function createArtifactProject(projectRoot, mdxPath, config) {
14
- const tmpDir = path.join(projectRoot, ".artifact-kit", "tmp", randomUUID());
15
- const artifact = createArtifactRoute(projectRoot, mdxPath, config.docsDir);
16
- const srcDir = path.join(tmpDir, "src");
17
- const distDir = path.join(tmpDir, "dist");
18
- const entryPath = path.join(srcDir, "entry.tsx");
19
- const mdxImport = toRelativeImport(entryPath, mdxPath);
20
- const styleImports = createStyleImports(projectRoot, entryPath, config);
21
- const reactEntryPath = await resolveReactEntryPath();
22
- const reactEntryImport = toRelativeImport(entryPath, reactEntryPath);
23
- const reactAliases = resolveReactAliases(projectRoot);
24
- await mkdir(srcDir, { recursive: true });
25
- await writeFile(path.join(tmpDir, "index.html"), `<!doctype html>
26
- <html lang="en">
27
- <head>
28
- <meta charset="UTF-8" />
29
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
30
- <title>MDX Artifact</title>
31
- </head>
32
- <body>
33
- <div id="root"></div>
34
- <script type="module" src="/src/entry.tsx"></script>
35
- </body>
36
- </html>
37
- `);
38
- await writeFile(entryPath, `import React from "react";
39
- import { createRoot } from "react-dom/client";
40
- import { ArtifactStateProvider, CommentLayer } from "${reactEntryImport}";
41
- import Doc from "${mdxImport}";
42
- ${styleImports}
43
-
44
- function App() {
45
- return (
46
- <main className="ak-shell">
47
- <article className="ak-document">
48
- <ArtifactStateProvider>
49
- <CommentLayer>
50
- <Doc />
51
- </CommentLayer>
52
- </ArtifactStateProvider>
53
- </article>
54
- </main>
55
- );
56
- }
57
-
58
- createRoot(document.getElementById("root")!).render(<App />);
59
- `);
60
- const viteConfig = {
61
- root: tmpDir,
62
- logLevel: "warn",
63
- plugins: [artifactStatePlugin(projectRoot, artifact), react(), mdx(), tailwindcss()],
64
- resolve: {
65
- alias: [
66
- ...reactAliases,
67
- { find: /^mdx-artifacts\/react$/, replacement: reactEntryPath },
68
- { find: /^mdx-artifacts$/, replacement: reactEntryPath }
69
- ],
70
- dedupe: ["react", "react-dom"]
71
- },
72
- optimizeDeps: {
73
- exclude: ["mdx-artifacts", "mdx-artifacts/react"]
74
- },
75
- server: {
76
- port: config.port,
77
- fs: {
78
- allow: [projectRoot]
79
- }
80
- },
81
- build: {
82
- outDir: distDir,
83
- emptyOutDir: true,
84
- cssCodeSplit: false,
85
- assetsInlineLimit: Number.MAX_SAFE_INTEGER,
86
- rollupOptions: {
87
- input: path.join(tmpDir, "index.html")
88
- }
89
- }
90
- };
91
- return {
92
- artifact,
93
- tmpDir,
94
- distDir,
95
- config: viteConfig,
96
- cleanup: () => rm(tmpDir, { recursive: true, force: true })
97
- };
98
- }
99
- function artifactStatePlugin(projectRoot, artifact) {
100
- return {
101
- name: "artifact-kit-state",
102
- configureServer(server) {
103
- server.middlewares.use(async (request, response, next) => {
104
- const requestUrl = new URL(request.url ?? "/", "http://localhost");
105
- try {
106
- if (requestUrl.pathname === "/__artifact/meta") {
107
- await handleArtifactMeta(projectRoot, artifact, request, response);
108
- return;
109
- }
110
- if (requestUrl.pathname === "/__artifact/state") {
111
- await handleArtifactState(projectRoot, artifact, request, response);
112
- return;
113
- }
114
- }
115
- catch (error) {
116
- sendJson(response, 500, {
117
- error: error instanceof Error ? error.message : String(error)
118
- });
119
- return;
120
- }
121
- next();
122
- });
123
- }
124
- };
125
- }
126
- async function handleArtifactMeta(projectRoot, artifact, request, response) {
127
- if (request.method !== "GET") {
128
- sendJson(response, 405, { error: "Method not allowed." });
129
- return;
130
- }
131
- sendJson(response, 200, await createArtifactMeta(projectRoot, artifact));
132
- }
133
- async function handleArtifactState(projectRoot, artifact, request, response) {
134
- if (request.method === "GET") {
135
- sendJson(response, 200, await readArtifactState(artifact));
136
- return;
137
- }
138
- if (request.method === "POST") {
139
- let value;
140
- try {
141
- value = JSON.parse(await readRequestBody(request));
142
- }
143
- catch {
144
- sendJson(response, 400, { error: "Request body must be valid JSON." });
145
- return;
146
- }
147
- const state = await writeArtifactState(projectRoot, artifact, value);
148
- sendJson(response, 200, { ok: true, state });
149
- return;
150
- }
151
- sendJson(response, 405, { error: "Method not allowed." });
152
- }
153
- function readRequestBody(request) {
154
- return new Promise((resolve, reject) => {
155
- let body = "";
156
- request.setEncoding("utf8");
157
- request.on("data", (chunk) => {
158
- body += chunk;
159
- });
160
- request.on("end", () => resolve(body));
161
- request.on("error", reject);
162
- });
163
- }
164
- function sendJson(response, statusCode, value) {
165
- response.statusCode = statusCode;
166
- response.setHeader("content-type", "application/json; charset=utf-8");
167
- response.end(JSON.stringify(value, null, 2));
168
- }
169
- async function resolveReactEntryPath() {
170
- const builtEntryPath = path.resolve(packageCliDir, "../react/index.js");
171
- const sourceEntryPath = path.resolve(packageCliDir, "../react/index.ts");
172
- try {
173
- await access(builtEntryPath);
174
- return builtEntryPath;
175
- }
176
- catch {
177
- return sourceEntryPath;
178
- }
179
- }
180
- function resolveReactAliases(projectRoot) {
181
- const projectRequire = createRequire(path.join(projectRoot, "package.json"));
182
- return [
183
- { find: /^react$/, replacement: projectRequire.resolve("react") },
184
- { find: /^react\/jsx-runtime$/, replacement: projectRequire.resolve("react/jsx-runtime") },
185
- { find: /^react\/jsx-dev-runtime$/, replacement: projectRequire.resolve("react/jsx-dev-runtime") },
186
- { find: /^react-dom$/, replacement: projectRequire.resolve("react-dom") },
187
- { find: /^react-dom\/client$/, replacement: projectRequire.resolve("react-dom/client") }
188
- ];
189
- }
190
- export async function startDevServer(project) {
191
- const server = await createServer(project.config);
192
- await server.listen();
193
- return server;
194
- }
195
- export async function buildArtifact(project) {
196
- await viteBuild(project.config);
197
- return inlineBuildAssets(project.distDir);
198
- }
199
- async function inlineBuildAssets(distDir) {
200
- const htmlPath = path.join(distDir, "index.html");
201
- let html = await readFile(htmlPath, "utf8");
202
- html = await replaceAsync(html, /<link rel="stylesheet" crossorigin href="([^"]+)">/g, async (_match, href) => {
203
- const css = await readFile(assetPath(distDir, href), "utf8");
204
- return `<style>${css}</style>`;
205
- });
206
- html = await replaceAsync(html, /<script type="module" crossorigin src="([^"]+)"><\/script>/g, async (_match, src) => {
207
- const js = await readFile(assetPath(distDir, src), "utf8");
208
- return `<script type="module">${escapeScriptContent(js)}</script>`;
209
- });
210
- return html;
211
- }
212
- function assetPath(distDir, value) {
213
- return path.join(distDir, value.replace(/^\//, ""));
214
- }
215
- function toRelativeImport(fromFile, targetFile) {
216
- const relative = path.relative(path.dirname(fromFile), targetFile).replaceAll(path.sep, "/");
217
- return relative.startsWith(".") ? relative : `./${relative}`;
218
- }
219
- function createStyleImports(projectRoot, entryPath, config) {
220
- const styles = [
221
- ...(config.includeDefaultStyles ? [defaultStylesPath] : []),
222
- ...config.styles.map((stylePath) => path.resolve(projectRoot, stylePath))
223
- ];
224
- return styles.map((stylePath) => `import "${toRelativeImport(entryPath, stylePath)}";`).join("\n");
225
- }
226
- async function replaceAsync(source, pattern, replacer) {
227
- const matches = Array.from(source.matchAll(pattern));
228
- let output = source;
229
- for (const match of matches) {
230
- const replacement = await replacer(match[0], ...match.slice(1));
231
- output = output.replace(match[0], () => replacement);
232
- }
233
- return output;
234
- }
235
- function escapeScriptContent(source) {
236
- return source.replace(/<\/script/gi, "<\\/script");
237
- }
@@ -1,9 +0,0 @@
1
- export type CalloutTone = "info" | "success" | "warning" | "danger";
2
- export type CalloutProps = {
3
- id?: string;
4
- body: string;
5
- title?: string;
6
- tone?: CalloutTone;
7
- className?: string;
8
- };
9
- export declare function Callout({ id, body, title, tone, className }: CalloutProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- export type CodeBlockProps = {
2
- id?: string;
3
- code: string;
4
- language?: string;
5
- filename?: string;
6
- showLineNumbers?: boolean;
7
- highlightLines?: number[];
8
- className?: string;
9
- };
10
- export declare function CodeBlock({ id, code, language, filename, showLineNumbers, highlightLines, className }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
@@ -1,28 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CommentTarget } from "./Comments.js";
3
- export function CodeBlock({ id, code, language, filename, showLineNumbers = false, highlightLines = [], className }) {
4
- const lines = splitCodeLines(code);
5
- const highlighted = new Set(highlightLines);
6
- const title = filename ?? (language ? `${language} code block` : "Code block");
7
- const targetId = id ?? `code:${slugify(filename ?? language ?? code)}`;
8
- return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "CodeBlock component", targetId: targetId, title: title, children: _jsxs("figure", { className: "ak-code-block", children: [(filename || language) && (_jsxs("figcaption", { className: "ak-code-header", children: [filename && _jsx("span", { className: "ak-code-filename", children: filename }), language && _jsx("span", { className: "ak-code-language", children: language })] })), _jsx("pre", { className: "ak-code-pre", children: _jsx("code", { className: language ? `language-${language}` : undefined, children: lines.map((line, index) => {
9
- const lineNumber = index + 1;
10
- return (_jsxs("span", { className: classNames("ak-code-line", showLineNumbers ? "ak-code-line-numbered" : undefined, highlighted.has(lineNumber) ? "ak-code-line-highlighted" : undefined), "data-line": lineNumber, children: [showLineNumbers && _jsx("span", { className: "ak-code-line-number", children: lineNumber }), _jsx("span", { className: "ak-code-line-content", children: line || "\u00a0" })] }, lineNumber));
11
- }) }) })] }) }));
12
- }
13
- function splitCodeLines(code) {
14
- const normalized = code.endsWith("\n") ? code.slice(0, -1) : code;
15
- return normalized.split("\n");
16
- }
17
- function classNames(...values) {
18
- return values.filter(Boolean).join(" ");
19
- }
20
- function slugify(value) {
21
- const slug = value
22
- .toLowerCase()
23
- .replace(/[`*_~[\]()]/g, "")
24
- .replace(/[^a-z0-9]+/g, "-")
25
- .replace(/^-+|-+$/g, "")
26
- .slice(0, 64);
27
- return slug || "item";
28
- }
@@ -1,16 +0,0 @@
1
- export type DecisionMatrixOption = {
2
- id?: string;
3
- name: string;
4
- summary?: string;
5
- pros?: string[];
6
- cons?: string[];
7
- risks?: string[];
8
- confidence?: "low" | "medium" | "high";
9
- verdict?: string;
10
- };
11
- export type DecisionMatrixProps = {
12
- id?: string;
13
- question: string;
14
- options: DecisionMatrixOption[];
15
- };
16
- export declare function DecisionMatrix({ id, question, options }: DecisionMatrixProps): import("react/jsx-runtime").JSX.Element;
@@ -1,27 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CommentTarget } from "./Comments.js";
3
- import { InlineText } from "./InlineText.js";
4
- export function DecisionMatrix({ id, question, options }) {
5
- const targetId = id ?? `decision:${slugify(question)}`;
6
- return (_jsx(CommentTarget, { className: "ak-comment-target-section", description: "DecisionMatrix component", targetId: targetId, title: question, children: _jsxs("section", { className: "ak-section ak-decision-matrix", children: [_jsxs("div", { className: "ak-section-header", children: [_jsx("p", { className: "ak-eyebrow", children: "Decision Matrix" }), _jsx(InlineText, { as: "h2", text: question, variant: "title" })] }), _jsx("div", { className: "ak-decision-grid", children: options.map((option, index) => {
7
- const optionTargetId = id
8
- ? `${id}.${option.id ?? `${index + 1}`}`
9
- : `decision:${slugify(question)}:${index + 1}:${slugify(option.name)}`;
10
- return (_jsx(CommentTarget, { className: "ak-comment-target-card", description: `DecisionMatrix option in ${question}`, targetId: optionTargetId, title: option.name, children: _jsxs("article", { className: "ak-card", children: [_jsxs("div", { className: "ak-card-header", children: [_jsx(InlineText, { as: "h3", text: option.name, variant: "subtitle" }), option.confidence ? (_jsx("span", { className: `ak-badge ak-badge-${option.confidence}`, children: option.confidence })) : null] }), option.summary ? _jsx(InlineText, { as: "p", className: "ak-muted", text: option.summary }) : null, _jsx(ListBlock, { title: "Pros", items: option.pros }), _jsx(ListBlock, { title: "Cons", items: option.cons }), _jsx(ListBlock, { title: "Risks", items: option.risks }), option.verdict ? _jsx(InlineText, { as: "p", className: "ak-verdict", text: option.verdict }) : null] }) }, option.name));
11
- }) })] }) }));
12
- }
13
- function ListBlock({ title, items }) {
14
- if (!items?.length) {
15
- return null;
16
- }
17
- return (_jsxs("div", { className: "ak-list-block", children: [_jsx("h4", { children: title }), _jsx("ul", { children: items.map((item) => (_jsx("li", { children: _jsx(InlineText, { text: item }) }, item))) })] }));
18
- }
19
- function slugify(value) {
20
- const slug = value
21
- .toLowerCase()
22
- .replace(/[`*_~[\]()]/g, "")
23
- .replace(/[^a-z0-9]+/g, "-")
24
- .replace(/^-+|-+$/g, "")
25
- .slice(0, 64);
26
- return slug || "item";
27
- }
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CommentTarget } from "./Comments.js";
3
- const markers = {
4
- add: "+",
5
- remove: "-",
6
- context: " "
7
- };
8
- export function DiffBlock({ id, lines, filename, language, className }) {
9
- const title = filename ?? (language ? `${language} diff block` : "Diff block");
10
- const targetId = id ?? `diff:${slugify(filename ?? language ?? lines.map((line) => line.content).join("-"))}`;
11
- return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "DiffBlock component", targetId: targetId, title: title, children: _jsxs("figure", { className: "ak-code-block ak-diff-block", children: [(filename || language) && (_jsxs("figcaption", { className: "ak-code-header", children: [filename && _jsx("span", { className: "ak-code-filename", children: filename }), language && _jsx("span", { className: "ak-code-language", children: language })] })), _jsx("pre", { className: "ak-code-pre", children: _jsx("code", { className: language ? `language-${language}` : undefined, children: lines.map((line, index) => (_jsxs("span", { className: classNames("ak-diff-line", `ak-diff-line-${line.type}`), children: [_jsx("span", { className: "ak-diff-line-number", children: line.newLine ?? line.oldLine ?? "" }), _jsx("span", { className: "ak-diff-marker", children: markers[line.type] }), _jsx("span", { className: "ak-diff-line-content", children: line.content || "\u00a0" })] }, `${line.type}-${index}`))) }) })] }) }));
12
- }
13
- function classNames(...values) {
14
- return values.filter(Boolean).join(" ");
15
- }
16
- function slugify(value) {
17
- const slug = value
18
- .toLowerCase()
19
- .replace(/[`*_~[\]()]/g, "")
20
- .replace(/[^a-z0-9]+/g, "-")
21
- .replace(/^-+|-+$/g, "")
22
- .slice(0, 64);
23
- return slug || "item";
24
- }
@@ -1,18 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import ReactMarkdown from "react-markdown";
3
- import remarkGfm from "remark-gfm";
4
- const inlineAllowedElements = ["p", "strong", "em", "del", "code", "a", "br"];
5
- const inlineComponents = {
6
- p({ children }) {
7
- return _jsx(_Fragment, { children: children });
8
- },
9
- a({ children, href }) {
10
- return (_jsx("a", { href: href, rel: "noreferrer", target: "_blank", children: children }));
11
- }
12
- };
13
- export function InlineText({ text, as: Component = "span", variant = "default", className }) {
14
- return (_jsx(Component, { className: classNames("ak-inline-text", `ak-inline-text--${variant}`, className), children: _jsx(ReactMarkdown, { allowedElements: inlineAllowedElements, components: inlineComponents, remarkPlugins: [remarkGfm], skipHtml: true, unwrapDisallowed: true, children: text }) }));
15
- }
16
- function classNames(...values) {
17
- return values.filter(Boolean).join(" ");
18
- }
@@ -1,7 +0,0 @@
1
- export type MarkdownBodyVariant = "default" | "compact";
2
- export type MarkdownBodyProps = {
3
- body: string;
4
- variant?: MarkdownBodyVariant;
5
- className?: string;
6
- };
7
- export declare function MarkdownBody({ body, variant, className }: MarkdownBodyProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import ReactMarkdown from "react-markdown";
3
- import remarkGfm from "remark-gfm";
4
- const blockAllowedElements = [
5
- "p",
6
- "h1",
7
- "h2",
8
- "h3",
9
- "h4",
10
- "h5",
11
- "h6",
12
- "strong",
13
- "em",
14
- "del",
15
- "code",
16
- "a",
17
- "br",
18
- "ul",
19
- "ol",
20
- "li",
21
- "blockquote"
22
- ];
23
- const blockComponents = {
24
- a({ children, href }) {
25
- return (_jsx("a", { href: href, rel: "noreferrer", target: "_blank", children: children }));
26
- }
27
- };
28
- export function MarkdownBody({ body, variant = "default", className }) {
29
- if (!body.trim()) {
30
- return null;
31
- }
32
- return (_jsx("div", { className: classNames("ak-markdown-body", `ak-markdown-body--${variant}`, className), children: _jsx(ReactMarkdown, { allowedElements: blockAllowedElements, components: blockComponents, remarkPlugins: [remarkGfm], skipHtml: true, unwrapDisallowed: true, children: body }) }));
33
- }
34
- function classNames(...values) {
35
- return values.filter(Boolean).join(" ");
36
- }
@@ -1,13 +0,0 @@
1
- export type OptionGridItem = {
2
- id?: string;
3
- name: string;
4
- intent?: string;
5
- description?: string;
6
- tradeoffs?: string[];
7
- };
8
- export type OptionGridProps = {
9
- id?: string;
10
- title: string;
11
- options: OptionGridItem[];
12
- };
13
- export declare function OptionGrid({ id, title, options }: OptionGridProps): import("react/jsx-runtime").JSX.Element;
@@ -1,21 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CommentTarget } from "./Comments.js";
3
- import { InlineText } from "./InlineText.js";
4
- export function OptionGrid({ id, title, options }) {
5
- const targetId = id ?? `option:${slugify(title)}`;
6
- return (_jsx(CommentTarget, { className: "ak-comment-target-section", description: "OptionGrid component", targetId: targetId, title: title, children: _jsxs("section", { className: "ak-section", children: [_jsxs("div", { className: "ak-section-header", children: [_jsx("p", { className: "ak-eyebrow", children: "Option Grid" }), _jsx(InlineText, { as: "h2", text: title, variant: "title" })] }), _jsx("div", { className: "ak-option-grid", children: options.map((option, index) => {
7
- const optionTargetId = id
8
- ? `${id}.${option.id ?? `${index + 1}`}`
9
- : `option:${slugify(title)}:${index + 1}:${slugify(option.name)}`;
10
- return (_jsx(CommentTarget, { className: "ak-comment-target-card", description: `OptionGrid item in ${title}`, targetId: optionTargetId, title: option.name, children: _jsxs("article", { className: "ak-card", children: [_jsx(InlineText, { as: "h3", text: option.name, variant: "subtitle" }), option.intent ? _jsx(InlineText, { as: "p", className: "ak-intent", text: option.intent }) : null, option.description ? _jsx(InlineText, { as: "p", text: option.description }) : null, option.tradeoffs?.length ? (_jsx("ul", { children: option.tradeoffs.map((tradeoff) => (_jsx("li", { children: _jsx(InlineText, { text: tradeoff }) }, tradeoff))) })) : null] }) }, option.name));
11
- }) })] }) }));
12
- }
13
- function slugify(value) {
14
- const slug = value
15
- .toLowerCase()
16
- .replace(/[`*_~[\]()]/g, "")
17
- .replace(/[^a-z0-9]+/g, "-")
18
- .replace(/^-+|-+$/g, "")
19
- .slice(0, 64);
20
- return slug || "item";
21
- }
File without changes
File without changes