mdx-artifacts 0.1.2 → 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 (141) hide show
  1. package/README.md +211 -59
  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/{vite-artifact.js → dev-server/vite-artifact.js} +170 -10
  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/react/components/Callout.d.ts +0 -9
  117. package/dist/lib/react/components/CodeBlock.d.ts +0 -10
  118. package/dist/lib/react/components/CodeBlock.js +0 -28
  119. package/dist/lib/react/components/DecisionMatrix.d.ts +0 -16
  120. package/dist/lib/react/components/DecisionMatrix.js +0 -27
  121. package/dist/lib/react/components/DiffBlock.js +0 -24
  122. package/dist/lib/react/components/InlineText.js +0 -18
  123. package/dist/lib/react/components/MarkdownBody.d.ts +0 -7
  124. package/dist/lib/react/components/MarkdownBody.js +0 -36
  125. package/dist/lib/react/components/OptionGrid.d.ts +0 -13
  126. package/dist/lib/react/components/OptionGrid.js +0 -21
  127. /package/dist/lib/cli/{build.d.ts → commands/build.d.ts} +0 -0
  128. /package/dist/lib/cli/{components.d.ts → commands/components.d.ts} +0 -0
  129. /package/dist/lib/cli/{dev.d.ts → commands/dev.d.ts} +0 -0
  130. /package/dist/lib/cli/{types.js → config/types.js} +0 -0
  131. /package/dist/lib/cli/{artifact-state.d.ts → state/artifact-state.d.ts} +0 -0
  132. /package/dist/lib/cli/{artifact-state.js → state/artifact-state.js} +0 -0
  133. /package/dist/lib/react/{components → composites/export-panel}/ExportPanel.d.ts +0 -0
  134. /package/dist/lib/react/{components → composites/section}/Section.d.ts +0 -0
  135. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.d.ts +0 -0
  136. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.js +0 -0
  137. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.d.ts +0 -0
  138. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.js +0 -0
  139. /package/dist/lib/react/{components → primitives/diff-block}/DiffBlock.d.ts +0 -0
  140. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.d.ts +0 -0
  141. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.js +0 -0
@@ -0,0 +1,65 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ContentItemEmphasis, type ContentItemTone, type ContentSetColumns, type ContentSetSurface } from "../composites/content-set/ContentItem";
3
+ type LegacyListValue = ReactNode[] | readonly ReactNode[];
4
+ export type DecisionMatrixOptionProps = {
5
+ id?: string;
6
+ title?: string;
7
+ name?: string;
8
+ badge?: string;
9
+ summary?: string;
10
+ verdict?: string;
11
+ confidence?: string;
12
+ pros?: LegacyListValue;
13
+ cons?: LegacyListValue;
14
+ risks?: LegacyListValue;
15
+ tone?: ContentItemTone;
16
+ emphasis?: ContentItemEmphasis;
17
+ children?: ReactNode;
18
+ };
19
+ export type DecisionMatrixProps = {
20
+ id?: string;
21
+ title?: string;
22
+ question?: string;
23
+ options?: DecisionMatrixOptionProps[];
24
+ columns?: ContentSetColumns;
25
+ surface?: ContentSetSurface;
26
+ tone?: ContentItemTone;
27
+ emphasis?: ContentItemEmphasis;
28
+ className?: string;
29
+ children?: ReactNode;
30
+ };
31
+ export type OptionGridItemProps = {
32
+ id?: string;
33
+ title?: string;
34
+ name?: string;
35
+ badge?: string;
36
+ summary?: string;
37
+ intent?: string;
38
+ description?: string;
39
+ tradeoffs?: LegacyListValue;
40
+ tone?: ContentItemTone;
41
+ emphasis?: ContentItemEmphasis;
42
+ children?: ReactNode;
43
+ };
44
+ export type OptionGridProps = {
45
+ id?: string;
46
+ title: string;
47
+ options?: OptionGridItemProps[];
48
+ columns?: ContentSetColumns;
49
+ surface?: ContentSetSurface;
50
+ tone?: ContentItemTone;
51
+ emphasis?: ContentItemEmphasis;
52
+ className?: string;
53
+ children?: ReactNode;
54
+ };
55
+ declare function DecisionMatrixRoot({ id, title, question, options, columns, surface, tone, emphasis, className, children }: DecisionMatrixProps): import("react/jsx-runtime").JSX.Element;
56
+ declare function DecisionMatrixOption({ id, title, name, badge, summary, verdict, confidence, pros, cons, risks, tone, emphasis, children }: DecisionMatrixOptionProps): import("react/jsx-runtime").JSX.Element;
57
+ declare function OptionGridRoot({ id, title, options, columns, surface, tone, emphasis, className, children }: OptionGridProps): import("react/jsx-runtime").JSX.Element;
58
+ declare function OptionGridItem({ id, title, name, badge, summary, intent, description, tradeoffs, tone, emphasis, children }: OptionGridItemProps): import("react/jsx-runtime").JSX.Element;
59
+ export declare const DecisionMatrix: typeof DecisionMatrixRoot & {
60
+ Option: typeof DecisionMatrixOption;
61
+ };
62
+ export declare const OptionGrid: typeof OptionGridRoot & {
63
+ Item: typeof OptionGridItem;
64
+ };
65
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ContentSet } from "../composites/content-set/ContentItem.js";
3
+ function DecisionMatrixRoot({ id, title, question, options, columns = 3, surface, tone, emphasis, className, children }) {
4
+ return (_jsxs(ContentSet, { className: className, columns: columns, emphasis: emphasis, id: id, surface: surface, title: title ?? question ?? "Decision matrix", tone: tone, children: [options?.map((option, index) => (_jsx(DecisionMatrixOption, { ...option }, option.id ?? option.title ?? option.name ?? index))), children] }));
5
+ }
6
+ function DecisionMatrixOption({ id, title, name, badge, summary, verdict, confidence, pros, cons, risks, tone, emphasis, children }) {
7
+ return (_jsxs(ContentSet.Item, { badge: badge ?? confidence, emphasis: emphasis, id: id, summary: summary ?? verdict, title: title ?? name ?? "Option", tone: tone, children: [children, _jsx(LegacyList, { title: "Pros", values: pros }), _jsx(LegacyList, { title: "Cons", values: cons }), _jsx(LegacyList, { title: "Risks", values: risks })] }));
8
+ }
9
+ function OptionGridRoot({ id, title, options, columns = 3, surface, tone, emphasis, className, children }) {
10
+ return (_jsxs(ContentSet, { className: className, columns: columns, emphasis: emphasis, id: id, surface: surface, title: title, tone: tone, children: [options?.map((option, index) => (_jsx(OptionGridItem, { ...option }, option.id ?? option.title ?? option.name ?? index))), children] }));
11
+ }
12
+ function OptionGridItem({ id, title, name, badge, summary, intent, description, tradeoffs, tone, emphasis, children }) {
13
+ return (_jsxs(ContentSet.Item, { badge: badge, emphasis: emphasis, id: id, summary: summary ?? intent, title: title ?? name ?? "Option", tone: tone, children: [description ? _jsx("p", { children: description }) : null, children, _jsx(LegacyList, { title: "Tradeoffs", values: tradeoffs })] }));
14
+ }
15
+ function LegacyList({ title, values }) {
16
+ if (!values?.length) {
17
+ return null;
18
+ }
19
+ return (_jsxs("div", { children: [_jsx("h4", { children: title }), _jsx("ul", { children: values.map((value, index) => (_jsx("li", { children: value }, index))) })] }));
20
+ }
21
+ export const DecisionMatrix = Object.assign(DecisionMatrixRoot, {
22
+ Option: DecisionMatrixOption
23
+ });
24
+ export const OptionGrid = Object.assign(OptionGridRoot, {
25
+ Item: OptionGridItem
26
+ });
@@ -0,0 +1,5 @@
1
+ import { type ComponentPropsWithoutRef } from "react";
2
+ export declare const artifactMdxComponents: {
3
+ pre: typeof ArtifactCodePre;
4
+ };
5
+ export declare function ArtifactCodePre({ children, ...props }: ComponentPropsWithoutRef<"pre">): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, isValidElement } from "react";
3
+ import { CodeBlockView } from "./primitives/code-block/CodeBlock.js";
4
+ export const artifactMdxComponents = {
5
+ pre: ArtifactCodePre
6
+ };
7
+ export function ArtifactCodePre({ children, ...props }) {
8
+ const codeChild = getSingleCodeChild(children);
9
+ if (!codeChild) {
10
+ return _jsx("pre", { ...props, children: children });
11
+ }
12
+ const codeProps = codeChild.props;
13
+ const code = getTextContent(codeProps.children);
14
+ if (code == null) {
15
+ return _jsx("pre", { ...props, children: children });
16
+ }
17
+ return _jsx(CodeBlockView, { code: code, copyable: true, language: getLanguage(codeProps.className), showLineNumbers: true });
18
+ }
19
+ function getSingleCodeChild(children) {
20
+ const child = Children.toArray(children).find((item) => isValidElement(item));
21
+ if (!isValidElement(child) || child.type !== "code") {
22
+ return undefined;
23
+ }
24
+ return child;
25
+ }
26
+ function getTextContent(node) {
27
+ if (typeof node === "string" || typeof node === "number") {
28
+ return String(node);
29
+ }
30
+ if (Array.isArray(node)) {
31
+ return node.map(getTextContent).filter((item) => item != null).join("");
32
+ }
33
+ return undefined;
34
+ }
35
+ function getLanguage(className) {
36
+ const languageClass = className?.split(/\s+/).find((item) => item.startsWith("language-"));
37
+ return languageClass?.replace(/^language-/, "") || undefined;
38
+ }
@@ -1,4 +1,4 @@
1
- import { type SeverityLevel } from "./SeverityBadge";
1
+ import { type SeverityLevel } from "../severity-badge/SeverityBadge";
2
2
  export type CodeAnnotation = {
3
3
  id?: string;
4
4
  line: number;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CodeBlock } from "./CodeBlock.js";
3
- import { CommentTarget } from "./Comments.js";
4
- import { InlineText } from "./InlineText.js";
5
- import { MarkdownBody } from "./MarkdownBody.js";
6
- import { SeverityBadge } from "./SeverityBadge.js";
2
+ import { CommentTarget } from "../../interactions/comments/Comments.js";
3
+ import { CodeBlock } from "../code-block/CodeBlock.js";
4
+ import { InlineText } from "../inline-text/InlineText.js";
5
+ import { MarkdownBody } from "../markdown-body/MarkdownBody.js";
6
+ import { SeverityBadge } from "../severity-badge/SeverityBadge.js";
7
7
  export function AnnotatedCode({ id, code, annotations, language, filename, showLineNumbers = true, highlightLines = [], className }) {
8
8
  const annotationLines = annotations.map((annotation) => annotation.line);
9
9
  const highlighted = Array.from(new Set([...highlightLines, ...annotationLines])).sort((a, b) => a - b);
@@ -0,0 +1,2 @@
1
+ export { AnnotatedCode } from "./AnnotatedCode";
2
+ export type { AnnotatedCodeProps, CodeAnnotation } from "./AnnotatedCode";
@@ -0,0 +1 @@
1
+ export { AnnotatedCode } from "./AnnotatedCode.js";
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ export type CalloutTone = "info" | "success" | "warning" | "danger";
3
+ export type CalloutProps = {
4
+ id?: string;
5
+ body?: string;
6
+ children?: ReactNode;
7
+ title?: string;
8
+ tone?: CalloutTone;
9
+ className?: string;
10
+ };
11
+ export declare function Callout({ id, body, children, title, tone, className }: CalloutProps): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,11 @@
1
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
- import { MarkdownBody } from "./MarkdownBody.js";
5
- export function Callout({ id, body, title, tone = "info", className }) {
2
+ import { CommentTarget } from "../../interactions/comments/Comments.js";
3
+ import { InlineText } from "../inline-text/InlineText.js";
4
+ import { MarkdownBody } from "../markdown-body/MarkdownBody.js";
5
+ export function Callout({ id, body, children, title, tone = "info", className }) {
6
6
  const displayTitle = title ?? `${tone} callout`;
7
- const targetId = id ?? `callout:${slugify(displayTitle)}:${slugify(body)}`;
8
- return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "Callout component", targetId: targetId, title: displayTitle, children: _jsxs("aside", { className: classNames("ak-callout", `ak-callout-${tone}`), children: [title ? _jsx(InlineText, { as: "h3", text: title, variant: "subtitle" }) : null, _jsx(MarkdownBody, { body: body, variant: "compact" })] }) }));
7
+ const targetId = id ?? `callout:${slugify(displayTitle)}:${slugify(body ?? textFromChildren(children) ?? displayTitle)}`;
8
+ return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "Callout component", targetId: targetId, title: displayTitle, children: _jsxs("aside", { className: classNames("ak-callout", `ak-callout-${tone}`), children: [title ? _jsx(InlineText, { as: "h3", variant: "subtitle", children: title }) : null, _jsx(MarkdownBody, { body: body, variant: "compact", children: children })] }) }));
9
9
  }
10
10
  function classNames(...values) {
11
11
  return values.filter(Boolean).join(" ");
@@ -19,3 +19,6 @@ function slugify(value) {
19
19
  .slice(0, 64);
20
20
  return slug || "item";
21
21
  }
22
+ function textFromChildren(children) {
23
+ return typeof children === "string" ? children : undefined;
24
+ }
@@ -0,0 +1,2 @@
1
+ export { Callout } from "./Callout";
2
+ export type { CalloutProps, CalloutTone } from "./Callout";
@@ -0,0 +1 @@
1
+ export { Callout } from "./Callout.js";
@@ -0,0 +1,20 @@
1
+ export type CodeBlockProps = {
2
+ id?: string;
3
+ code: string;
4
+ language?: string;
5
+ filename?: string;
6
+ showLineNumbers?: boolean;
7
+ highlightLines?: number[];
8
+ copyable?: boolean;
9
+ className?: string;
10
+ };
11
+ export type CodeBlockViewProps = {
12
+ code: string;
13
+ language?: string;
14
+ filename?: string;
15
+ showLineNumbers?: boolean;
16
+ highlightLines?: number[];
17
+ copyable?: boolean;
18
+ };
19
+ export declare function CodeBlock({ id, code, language, filename, showLineNumbers, highlightLines, copyable, className }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
20
+ export declare function CodeBlockView({ code, language, filename, showLineNumbers, highlightLines, copyable }: CodeBlockViewProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CommentTarget } from "../../interactions/comments/Comments.js";
3
+ import { CodeSurface } from "../code-surface/CodeSurface.js";
4
+ export function CodeBlock({ id, code, language, filename, showLineNumbers = false, highlightLines = [], copyable = false, className }) {
5
+ const title = filename ?? (language ? `${language} code block` : "Code block");
6
+ const targetId = id ?? `code:${slugify(filename ?? language ?? code)}`;
7
+ return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "CodeBlock component", targetId: targetId, title: title, children: _jsx(CodeBlockView, { code: code, copyable: copyable, filename: filename, highlightLines: highlightLines, language: language, showLineNumbers: showLineNumbers }) }));
8
+ }
9
+ export function CodeBlockView({ code, language, filename, showLineNumbers = false, highlightLines = [], copyable = false }) {
10
+ const lines = splitCodeLines(code);
11
+ const highlighted = new Set(highlightLines);
12
+ return (_jsx(CodeSurface, { copyable: copyable, copyText: code, filename: filename, language: language, children: lines.map((line, index) => {
13
+ const lineNumber = index + 1;
14
+ 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));
15
+ }) }));
16
+ }
17
+ function splitCodeLines(code) {
18
+ const normalized = code.endsWith("\n") ? code.slice(0, -1) : code;
19
+ return normalized.split("\n");
20
+ }
21
+ function classNames(...values) {
22
+ return values.filter(Boolean).join(" ");
23
+ }
24
+ function slugify(value) {
25
+ const slug = value
26
+ .toLowerCase()
27
+ .replace(/[`*_~[\]()]/g, "")
28
+ .replace(/[^a-z0-9]+/g, "-")
29
+ .replace(/^-+|-+$/g, "")
30
+ .slice(0, 64);
31
+ return slug || "item";
32
+ }
@@ -0,0 +1,2 @@
1
+ export { CodeBlock, CodeBlockView } from "./CodeBlock";
2
+ export type { CodeBlockProps, CodeBlockViewProps } from "./CodeBlock";
@@ -0,0 +1 @@
1
+ export { CodeBlock, CodeBlockView } from "./CodeBlock.js";
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ export type CodeSurfaceProps = {
3
+ children: ReactNode;
4
+ language?: string;
5
+ filename?: string;
6
+ copyable?: boolean;
7
+ copyText?: string;
8
+ className?: string;
9
+ codeClassName?: string;
10
+ };
11
+ export declare function CodeSurface({ children, language, filename, copyable, copyText, className, codeClassName }: CodeSurfaceProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ export function CodeSurface({ children, language, filename, copyable = false, copyText, className, codeClassName }) {
4
+ const [copied, setCopied] = useState(false);
5
+ const canCopy = copyable && copyText != null;
6
+ async function copyCode() {
7
+ if (copyText == null) {
8
+ return;
9
+ }
10
+ if (navigator.clipboard?.writeText) {
11
+ await navigator.clipboard.writeText(copyText);
12
+ }
13
+ else {
14
+ fallbackCopy(copyText);
15
+ }
16
+ setCopied(true);
17
+ window.setTimeout(() => setCopied(false), 1200);
18
+ }
19
+ return (_jsxs("figure", { className: classNames("ak-code-block", className), children: [(filename || language || canCopy) && (_jsxs("figcaption", { className: "ak-code-header", children: [_jsxs("span", { className: "ak-code-meta", children: [filename && _jsx("span", { className: "ak-code-filename", children: filename }), language && _jsx("span", { className: "ak-code-language", children: language })] }), canCopy ? (_jsx("button", { className: "ak-code-copy", onClick: () => void copyCode(), type: "button", children: copied ? "Copied" : "Copy" })) : null] })), _jsx("pre", { className: "ak-code-pre", children: _jsx("code", { className: classNames(language ? `language-${language}` : undefined, codeClassName), children: children }) })] }));
20
+ }
21
+ function fallbackCopy(value) {
22
+ const textarea = document.createElement("textarea");
23
+ textarea.value = value;
24
+ textarea.setAttribute("readonly", "true");
25
+ textarea.style.position = "fixed";
26
+ textarea.style.left = "-9999px";
27
+ document.body.appendChild(textarea);
28
+ textarea.select();
29
+ document.execCommand("copy");
30
+ document.body.removeChild(textarea);
31
+ }
32
+ function classNames(...values) {
33
+ return values.filter(Boolean).join(" ");
34
+ }
@@ -0,0 +1,2 @@
1
+ export { CodeSurface } from "./CodeSurface";
2
+ export type { CodeSurfaceProps } from "./CodeSurface";
@@ -0,0 +1 @@
1
+ export { CodeSurface } from "./CodeSurface.js";
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CommentTarget } from "../../interactions/comments/Comments.js";
3
+ import { CodeSurface } from "../code-surface/CodeSurface.js";
4
+ const markers = {
5
+ add: "+",
6
+ remove: "-",
7
+ context: " "
8
+ };
9
+ export function DiffBlock({ id, lines, filename, language, className }) {
10
+ const title = filename ?? (language ? `${language} diff block` : "Diff block");
11
+ const targetId = id ?? `diff:${slugify(filename ?? language ?? lines.map((line) => line.content).join("-"))}`;
12
+ return (_jsx(CommentTarget, { className: classNames("ak-comment-target-section", className), description: "DiffBlock component", targetId: targetId, title: title, children: _jsx(CodeSurface, { className: "ak-diff-block", filename: filename, language: language, 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}`))) }) }));
13
+ }
14
+ function classNames(...values) {
15
+ return values.filter(Boolean).join(" ");
16
+ }
17
+ function slugify(value) {
18
+ const slug = value
19
+ .toLowerCase()
20
+ .replace(/[`*_~[\]()]/g, "")
21
+ .replace(/[^a-z0-9]+/g, "-")
22
+ .replace(/^-+|-+$/g, "")
23
+ .slice(0, 64);
24
+ return slug || "item";
25
+ }
@@ -0,0 +1,2 @@
1
+ export { DiffBlock } from "./DiffBlock";
2
+ export type { DiffBlockProps, DiffLine, DiffLineType } from "./DiffBlock";
@@ -0,0 +1 @@
1
+ export { DiffBlock } from "./DiffBlock.js";
@@ -1,9 +1,11 @@
1
+ import type { ReactNode } from "react";
1
2
  export type InlineTextAs = "span" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
2
3
  export type InlineTextVariant = "default" | "title" | "subtitle" | "label" | "caption";
3
4
  export type InlineTextProps = {
4
- text: string;
5
+ text?: string;
6
+ children?: ReactNode;
5
7
  as?: InlineTextAs;
6
8
  variant?: InlineTextVariant;
7
9
  className?: string;
8
10
  };
9
- export declare function InlineText({ text, as: Component, variant, className }: InlineTextProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function InlineText({ text, children, as: Component, variant, className }: InlineTextProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,28 @@
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, children, as: Component = "span", variant = "default", className }) {
14
+ const content = hasRenderableChildren(children) ? children : text;
15
+ if (!hasRenderableChildren(content)) {
16
+ return null;
17
+ }
18
+ return (_jsx(Component, { className: classNames("ak-inline-text", `ak-inline-text--${variant}`, className), children: typeof content === "string" ? _jsx(InlineMarkdown, { text: content }) : content }));
19
+ }
20
+ function InlineMarkdown({ text }) {
21
+ return (_jsx(ReactMarkdown, { allowedElements: inlineAllowedElements, components: inlineComponents, remarkPlugins: [remarkGfm], skipHtml: true, unwrapDisallowed: true, children: text }));
22
+ }
23
+ function classNames(...values) {
24
+ return values.filter(Boolean).join(" ");
25
+ }
26
+ function hasRenderableChildren(children) {
27
+ return children !== undefined && children !== null && children !== false;
28
+ }
@@ -0,0 +1,2 @@
1
+ export { InlineText } from "./InlineText";
2
+ export type { InlineTextAs, InlineTextProps, InlineTextVariant } from "./InlineText";
@@ -0,0 +1 @@
1
+ export { InlineText } from "./InlineText.js";
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ export type MarkdownBodyVariant = "default" | "compact";
3
+ export type MarkdownBodyProps = {
4
+ body?: string;
5
+ children?: ReactNode;
6
+ variant?: MarkdownBodyVariant;
7
+ className?: string;
8
+ };
9
+ export declare function MarkdownBody({ body, children, variant, className }: MarkdownBodyProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,49 @@
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, children, variant = "default", className }) {
29
+ const classNamesValue = classNames("ak-markdown-body", `ak-markdown-body--${variant}`, className);
30
+ if (hasRenderableChildren(children)) {
31
+ if (typeof children === "string") {
32
+ return _jsx(MarkdownBodyFromString, { body: children, className: classNamesValue });
33
+ }
34
+ return _jsx("div", { className: classNamesValue, children: children });
35
+ }
36
+ if (!body?.trim()) {
37
+ return null;
38
+ }
39
+ return _jsx(MarkdownBodyFromString, { body: body, className: classNamesValue });
40
+ }
41
+ function MarkdownBodyFromString({ body, className }) {
42
+ return (_jsx("div", { className: className, children: _jsx(ReactMarkdown, { allowedElements: blockAllowedElements, components: blockComponents, remarkPlugins: [remarkGfm], skipHtml: true, unwrapDisallowed: true, children: body }) }));
43
+ }
44
+ function classNames(...values) {
45
+ return values.filter(Boolean).join(" ");
46
+ }
47
+ function hasRenderableChildren(children) {
48
+ return children !== undefined && children !== null && children !== false;
49
+ }
@@ -0,0 +1,2 @@
1
+ export { MarkdownBody } from "./MarkdownBody";
2
+ export type { MarkdownBodyProps, MarkdownBodyVariant } from "./MarkdownBody";
@@ -0,0 +1 @@
1
+ export { MarkdownBody } from "./MarkdownBody.js";
@@ -0,0 +1,2 @@
1
+ export { SeverityBadge } from "./SeverityBadge";
2
+ export type { SeverityBadgeProps, SeverityLevel } from "./SeverityBadge";
@@ -0,0 +1 @@
1
+ export { SeverityBadge } from "./SeverityBadge.js";
@@ -10,10 +10,20 @@ export type ComponentTypeMeta = {
10
10
  description?: string;
11
11
  fields: ComponentPropMeta[];
12
12
  };
13
+ export type ComponentAuthoringKind = "content-block" | "structured-renderer" | "layout-primitive" | "interactive-data" | "export-editor" | "review-boundary";
14
+ export type ComponentAuthoringMeta = {
15
+ kind: ComponentAuthoringKind;
16
+ guidance: string[];
17
+ };
13
18
  export type ComponentMeta = {
14
19
  name: string;
15
20
  category?: "artifact" | "content" | "layout" | "semantic";
16
21
  stability?: "stable" | "advanced";
22
+ deprecated?: {
23
+ replacement: string;
24
+ guidance: string[];
25
+ };
26
+ authoring?: ComponentAuthoringMeta;
17
27
  description: string;
18
28
  useWhen: string[];
19
29
  props: ComponentPropMeta[];