basalt-ui 0.3.0 → 1.0.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.
- package/AGENTS.md +70 -0
- package/CHANGELOG.md +216 -26
- package/LICENSE +201 -0
- package/README.md +434 -160
- package/agent/rules/basalt-agent.md +395 -0
- package/agent/rules/basalt-charts.md +170 -0
- package/agent/rules/basalt-commands.md +320 -0
- package/agent/rules/basalt-content.md +390 -0
- package/agent/rules/basalt-data.md +237 -0
- package/agent/rules/basalt-forms.md +186 -0
- package/agent/rules/basalt-mantine.md +327 -0
- package/agent/rules/basalt-notifications.md +264 -0
- package/agent/rules/basalt-query.md +130 -0
- package/agent/rules/basalt-router.md +173 -0
- package/agent/rules/basalt-state.md +99 -0
- package/agent/rules/basalt-tokens.md +148 -0
- package/agent/templates/CLAUDE-block.md.tpl +35 -0
- package/agent/templates/DESIGN.md.tpl +71 -0
- package/agent/templates/__root.tpl +31 -0
- package/agent/templates/query-client.ts.tpl +12 -0
- package/bin/basalt.mjs +14 -0
- package/configs/check.yml +29 -0
- package/configs/lefthook.yml +21 -0
- package/configs/oxfmt.json +8 -0
- package/configs/oxlint-plugin.js +269 -0
- package/configs/oxlint-plugin.test.ts +107 -0
- package/configs/oxlint.json +116 -0
- package/configs/tsconfig.base.json +20 -0
- package/configs/tsconfig.node.json +8 -0
- package/configs/tsconfig.react-app.json +8 -0
- package/dist/agent/ai-sdk-transport.d.ts +85 -0
- package/dist/agent/ai-sdk-transport.d.ts.map +1 -0
- package/dist/agent/ai-sdk-transport.js +109 -0
- package/dist/agent/history.d.ts +55 -0
- package/dist/agent/history.d.ts.map +1 -0
- package/dist/agent/history.js +32 -0
- package/dist/agent/index.d.ts +53 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +23 -0
- package/dist/agent/outcome.d.ts +71 -0
- package/dist/agent/outcome.d.ts.map +1 -0
- package/dist/agent/outcome.js +30 -0
- package/dist/agent/part-list.d.ts +75 -0
- package/dist/agent/part-list.d.ts.map +1 -0
- package/dist/agent/part-list.js +127 -0
- package/dist/agent/parts.d.ts +91 -0
- package/dist/agent/parts.d.ts.map +1 -0
- package/dist/agent/parts.js +49 -0
- package/dist/agent/stick-to-bottom.d.ts +23 -0
- package/dist/agent/stick-to-bottom.d.ts.map +1 -0
- package/dist/agent/stick-to-bottom.js +73 -0
- package/dist/agent/thread.d.ts +124 -0
- package/dist/agent/thread.d.ts.map +1 -0
- package/dist/agent/thread.js +131 -0
- package/dist/agent/transport.d.ts +87 -0
- package/dist/agent/transport.d.ts.map +1 -0
- package/dist/agent/transport.js +21 -0
- package/dist/agent/use-agent-stream.d.ts +34 -0
- package/dist/agent/use-agent-stream.d.ts.map +1 -0
- package/dist/agent/use-agent-stream.js +56 -0
- package/dist/agent/use-agent-thread-runs.d.ts +72 -0
- package/dist/agent/use-agent-thread-runs.d.ts.map +1 -0
- package/dist/agent/use-agent-thread-runs.js +217 -0
- package/dist/agent-chat/composer.d.ts +18 -0
- package/dist/agent-chat/composer.d.ts.map +1 -0
- package/dist/agent-chat/composer.js +86 -0
- package/dist/agent-chat/index.d.ts +24 -0
- package/dist/agent-chat/index.d.ts.map +1 -0
- package/dist/agent-chat/index.js +15 -0
- package/dist/agent-chat/thread-detail-panel.d.ts +27 -0
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -0
- package/dist/agent-chat/thread-detail-panel.js +108 -0
- package/dist/agent-chat/thread-feed.d.ts +18 -0
- package/dist/agent-chat/thread-feed.d.ts.map +1 -0
- package/dist/agent-chat/thread-feed.js +42 -0
- package/dist/agent-chat/thread-message.d.ts +31 -0
- package/dist/agent-chat/thread-message.d.ts.map +1 -0
- package/dist/agent-chat/thread-message.js +128 -0
- package/dist/agent-chat/thread-outcome-card.d.ts +19 -0
- package/dist/agent-chat/thread-outcome-card.d.ts.map +1 -0
- package/dist/agent-chat/thread-outcome-card.js +120 -0
- package/dist/agent-chat/thread-workspace.d.ts +27 -0
- package/dist/agent-chat/thread-workspace.d.ts.map +1 -0
- package/dist/agent-chat/thread-workspace.js +95 -0
- package/dist/charts/hooks/useChartSize.d.ts +25 -0
- package/dist/charts/hooks/useChartSize.d.ts.map +1 -0
- package/dist/charts/hooks/useChartSize.js +8 -0
- package/dist/charts/hooks/useChartTooltip.d.ts +13 -0
- package/dist/charts/hooks/useChartTooltip.d.ts.map +1 -0
- package/dist/charts/hooks/useChartTooltip.js +26 -0
- package/dist/charts/hooks/useHoverSync.d.ts +30 -0
- package/dist/charts/hooks/useHoverSync.d.ts.map +1 -0
- package/dist/charts/hooks/useHoverSync.js +70 -0
- package/dist/charts/hover-context.d.ts +21 -0
- package/dist/charts/hover-context.d.ts.map +1 -0
- package/dist/charts/hover-context.js +12 -0
- package/dist/charts/hover-sync.d.ts +14 -0
- package/dist/charts/hover-sync.d.ts.map +1 -0
- package/dist/charts/hover-sync.js +17 -0
- package/dist/charts/index.d.ts +47 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/index.js +129 -0
- package/dist/charts/kinds/Bars.d.ts +129 -0
- package/dist/charts/kinds/Bars.d.ts.map +1 -0
- package/dist/charts/kinds/Bars.js +467 -0
- package/dist/charts/kinds/Donut.d.ts +65 -0
- package/dist/charts/kinds/Donut.d.ts.map +1 -0
- package/dist/charts/kinds/Donut.js +158 -0
- package/dist/charts/kinds/DualPanel.d.ts +67 -0
- package/dist/charts/kinds/DualPanel.d.ts.map +1 -0
- package/dist/charts/kinds/DualPanel.js +326 -0
- package/dist/charts/kinds/Heatmap.d.ts +59 -0
- package/dist/charts/kinds/Heatmap.d.ts.map +1 -0
- package/dist/charts/kinds/Heatmap.js +175 -0
- package/dist/charts/kinds/MultiLine.d.ts +73 -0
- package/dist/charts/kinds/MultiLine.d.ts.map +1 -0
- package/dist/charts/kinds/MultiLine.js +275 -0
- package/dist/charts/kinds/StackedArea.d.ts +35 -0
- package/dist/charts/kinds/StackedArea.d.ts.map +1 -0
- package/dist/charts/kinds/StackedArea.js +151 -0
- package/dist/charts/kinds/ZonedLine.d.ts +94 -0
- package/dist/charts/kinds/ZonedLine.d.ts.map +1 -0
- package/dist/charts/kinds/ZonedLine.js +218 -0
- package/dist/charts/primitives/AreaGradient.d.ts +18 -0
- package/dist/charts/primitives/AreaGradient.d.ts.map +1 -0
- package/dist/charts/primitives/AreaGradient.js +13 -0
- package/dist/charts/primitives/Axes.d.ts +22 -0
- package/dist/charts/primitives/Axes.d.ts.map +1 -0
- package/dist/charts/primitives/Axes.js +79 -0
- package/dist/charts/primitives/ChartCard.d.ts +14 -0
- package/dist/charts/primitives/ChartCard.d.ts.map +1 -0
- package/dist/charts/primitives/ChartCard.js +144 -0
- package/dist/charts/primitives/ChartFrame.d.ts +70 -0
- package/dist/charts/primitives/ChartFrame.d.ts.map +1 -0
- package/dist/charts/primitives/ChartFrame.js +77 -0
- package/dist/charts/primitives/ChartLegend.d.ts +36 -0
- package/dist/charts/primitives/ChartLegend.d.ts.map +1 -0
- package/dist/charts/primitives/ChartLegend.js +234 -0
- package/dist/charts/primitives/ChartTooltip.d.ts +34 -0
- package/dist/charts/primitives/ChartTooltip.d.ts.map +1 -0
- package/dist/charts/primitives/ChartTooltip.js +134 -0
- package/dist/charts/primitives/Crosshair.d.ts +23 -0
- package/dist/charts/primitives/Crosshair.d.ts.map +1 -0
- package/dist/charts/primitives/Crosshair.js +21 -0
- package/dist/charts/primitives/HoverOverlay.d.ts +9 -0
- package/dist/charts/primitives/HoverOverlay.d.ts.map +1 -0
- package/dist/charts/primitives/HoverOverlay.js +21 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts +45 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts.map +1 -0
- package/dist/charts/primitives/ResponsiveChart.js +24 -0
- package/dist/charts/primitives/ZoneRects.d.ts +38 -0
- package/dist/charts/primitives/ZoneRects.d.ts.map +1 -0
- package/dist/charts/primitives/ZoneRects.js +30 -0
- package/dist/charts/series.d.ts +99 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +55 -0
- package/dist/charts/sparklines/BarSparkline.d.ts +13 -0
- package/dist/charts/sparklines/BarSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/BarSparkline.js +33 -0
- package/dist/charts/sparklines/LineSparkline.d.ts +15 -0
- package/dist/charts/sparklines/LineSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/LineSparkline.js +39 -0
- package/dist/charts/sparklines/index.d.ts +3 -0
- package/dist/charts/sparklines/index.d.ts.map +1 -0
- package/dist/charts/sparklines/index.js +6 -0
- package/dist/charts/theme.d.ts +21 -0
- package/dist/charts/theme.d.ts.map +1 -0
- package/dist/charts/theme.js +30 -0
- package/dist/charts/utils/domain.d.ts +20 -0
- package/dist/charts/utils/domain.d.ts.map +1 -0
- package/dist/charts/utils/domain.js +7 -0
- package/dist/charts/utils/format.d.ts +5 -0
- package/dist/charts/utils/format.d.ts.map +1 -0
- package/dist/charts/utils/format.js +27 -0
- package/dist/charts/utils/ticks.d.ts +5 -0
- package/dist/charts/utils/ticks.d.ts.map +1 -0
- package/dist/charts/utils/ticks.js +18 -0
- package/dist/cli/index.d.ts +273 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +907 -0
- package/dist/commands/ShortcutsHelp.d.ts +17 -0
- package/dist/commands/ShortcutsHelp.d.ts.map +1 -0
- package/dist/commands/ShortcutsHelp.js +64 -0
- package/dist/commands/define-commands.d.ts +140 -0
- package/dist/commands/define-commands.d.ts.map +1 -0
- package/dist/commands/define-commands.js +26 -0
- package/dist/commands/define-overlays.d.ts +134 -0
- package/dist/commands/define-overlays.d.ts.map +1 -0
- package/dist/commands/define-overlays.js +53 -0
- package/dist/commands/index.d.ts +42 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +46 -0
- package/dist/commands/overlays-mount.d.ts +117 -0
- package/dist/commands/overlays-mount.d.ts.map +1 -0
- package/dist/commands/overlays-mount.js +116 -0
- package/dist/commands/projectors.d.ts +152 -0
- package/dist/commands/projectors.d.ts.map +1 -0
- package/dist/commands/projectors.js +87 -0
- package/dist/commands/shortcut-format.d.ts +48 -0
- package/dist/commands/shortcut-format.d.ts.map +1 -0
- package/dist/commands/shortcut-format.js +33 -0
- package/dist/commands/useCommandHotkeys.d.ts +14 -0
- package/dist/commands/useCommandHotkeys.d.ts.map +1 -0
- package/dist/commands/useCommandHotkeys.js +45 -0
- package/dist/connectivity/connectivity-indicator.d.ts +8 -0
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -0
- package/dist/connectivity/connectivity-indicator.js +203 -0
- package/dist/connectivity/connectivity-provider.d.ts +7 -0
- package/dist/connectivity/connectivity-provider.d.ts.map +1 -0
- package/dist/connectivity/connectivity-provider.js +125 -0
- package/dist/connectivity/index.d.ts +13 -0
- package/dist/connectivity/index.d.ts.map +1 -0
- package/dist/connectivity/index.js +8 -0
- package/dist/connectivity/types.d.ts +36 -0
- package/dist/connectivity/types.d.ts.map +1 -0
- package/dist/connectivity/types.js +0 -0
- package/dist/connectivity/use-connectivity.d.ts +3 -0
- package/dist/connectivity/use-connectivity.d.ts.map +1 -0
- package/dist/connectivity/use-connectivity.js +14 -0
- package/dist/content/article-actions.d.ts +39 -0
- package/dist/content/article-actions.d.ts.map +1 -0
- package/dist/content/article-actions.js +28 -0
- package/dist/content/article-card.d.ts +58 -0
- package/dist/content/article-card.d.ts.map +1 -0
- package/dist/content/article-card.js +76 -0
- package/dist/content/article-card.module.css +109 -0
- package/dist/content/article-card.module.css.d.ts +16 -0
- package/dist/content/article-filter-bar.d.ts +40 -0
- package/dist/content/article-filter-bar.d.ts.map +1 -0
- package/dist/content/article-filter-bar.js +56 -0
- package/dist/content/article-layout.d.ts +61 -0
- package/dist/content/article-layout.d.ts.map +1 -0
- package/dist/content/article-layout.js +71 -0
- package/dist/content/article-layout.module.css +131 -0
- package/dist/content/article-layout.module.css.d.ts +20 -0
- package/dist/content/article-model.d.ts +62 -0
- package/dist/content/article-model.d.ts.map +1 -0
- package/dist/content/article-model.js +41 -0
- package/dist/content/block-split.d.ts +24 -0
- package/dist/content/block-split.d.ts.map +1 -0
- package/dist/content/block-split.js +63 -0
- package/dist/content/callout-alert.d.ts +27 -0
- package/dist/content/callout-alert.d.ts.map +1 -0
- package/dist/content/callout-alert.js +59 -0
- package/dist/content/callout.d.ts +24 -0
- package/dist/content/callout.d.ts.map +1 -0
- package/dist/content/callout.js +59 -0
- package/dist/content/callout.module.css +77 -0
- package/dist/content/callout.module.css.d.ts +16 -0
- package/dist/content/code-block.d.ts +26 -0
- package/dist/content/code-block.d.ts.map +1 -0
- package/dist/content/code-block.js +41 -0
- package/dist/content/code-block.module.css +86 -0
- package/dist/content/code-block.module.css.d.ts +14 -0
- package/dist/content/copy-action.d.ts +29 -0
- package/dist/content/copy-action.d.ts.map +1 -0
- package/dist/content/copy-action.js +46 -0
- package/dist/content/fence-block.d.ts +19 -0
- package/dist/content/fence-block.d.ts.map +1 -0
- package/dist/content/fence-block.js +23 -0
- package/dist/content/glyphs.d.ts +18 -0
- package/dist/content/glyphs.d.ts.map +1 -0
- package/dist/content/glyphs.js +43 -0
- package/dist/content/guide.d.ts +47 -0
- package/dist/content/guide.d.ts.map +1 -0
- package/dist/content/guide.js +110 -0
- package/dist/content/guide.module.css +62 -0
- package/dist/content/guide.module.css.d.ts +13 -0
- package/dist/content/heading-anchor.d.ts +8 -0
- package/dist/content/heading-anchor.d.ts.map +1 -0
- package/dist/content/heading-anchor.js +23 -0
- package/dist/content/heading-components.d.ts +5 -0
- package/dist/content/heading-components.d.ts.map +1 -0
- package/dist/content/heading-components.js +41 -0
- package/dist/content/highlighter.d.ts +8 -0
- package/dist/content/highlighter.d.ts.map +1 -0
- package/dist/content/highlighter.js +85 -0
- package/dist/content/index.d.ts +45 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +43 -0
- package/dist/content/markdown-hast.d.ts +23 -0
- package/dist/content/markdown-hast.d.ts.map +1 -0
- package/dist/content/markdown-hast.js +48 -0
- package/dist/content/markdown.d.ts +68 -0
- package/dist/content/markdown.d.ts.map +1 -0
- package/dist/content/markdown.js +180 -0
- package/dist/content/mdx.d.ts +20 -0
- package/dist/content/mdx.d.ts.map +1 -0
- package/dist/content/mdx.js +64 -0
- package/dist/content/mermaid.d.ts +32 -0
- package/dist/content/mermaid.d.ts.map +1 -0
- package/dist/content/mermaid.js +70 -0
- package/dist/content/mermaid.module.css +20 -0
- package/dist/content/mermaid.module.css.d.ts +8 -0
- package/dist/content/prose.d.ts +29 -0
- package/dist/content/prose.d.ts.map +1 -0
- package/dist/content/prose.js +24 -0
- package/dist/content/prose.module.css +330 -0
- package/dist/content/prose.module.css.d.ts +12 -0
- package/dist/content/reading-progress.d.ts +20 -0
- package/dist/content/reading-progress.d.ts.map +1 -0
- package/dist/content/reading-progress.js +38 -0
- package/dist/content/reading-progress.module.css +22 -0
- package/dist/content/reading-progress.module.css.d.ts +9 -0
- package/dist/content/slug.d.ts +28 -0
- package/dist/content/slug.d.ts.map +1 -0
- package/dist/content/slug.js +28 -0
- package/dist/content/toc.d.ts +37 -0
- package/dist/content/toc.d.ts.map +1 -0
- package/dist/content/toc.js +134 -0
- package/dist/content/toc.module.css +51 -0
- package/dist/content/toc.module.css.d.ts +13 -0
- package/dist/content/url-hardening.d.ts +23 -0
- package/dist/content/url-hardening.d.ts.map +1 -0
- package/dist/content/url-hardening.js +23 -0
- package/dist/dashboard/delta-badge.d.ts +13 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -0
- package/dist/dashboard/delta-badge.js +45 -0
- package/dist/dashboard/empty-state.d.ts +15 -0
- package/dist/dashboard/empty-state.d.ts.map +1 -0
- package/dist/dashboard/empty-state.js +56 -0
- package/dist/dashboard/index.d.ts +5 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +16 -0
- package/dist/dashboard/settings-section.d.ts +24 -0
- package/dist/dashboard/settings-section.d.ts.map +1 -0
- package/dist/dashboard/settings-section.js +61 -0
- package/dist/dashboard/settings-section.module.css +23 -0
- package/dist/dashboard/settings-section.module.css.d.ts +10 -0
- package/dist/dashboard/stat-card.d.ts +18 -0
- package/dist/dashboard/stat-card.d.ts.map +1 -0
- package/dist/dashboard/stat-card.js +74 -0
- package/dist/data/data-table.d.ts +198 -0
- package/dist/data/data-table.d.ts.map +1 -0
- package/dist/data/data-table.js +342 -0
- package/dist/data/index.d.ts +34 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +2 -0
- package/dist/data/table.d.ts +24 -0
- package/dist/data/table.d.ts.map +1 -0
- package/dist/data/table.js +20 -0
- package/dist/data/virtual-list.d.ts +74 -0
- package/dist/data/virtual-list.d.ts.map +1 -0
- package/dist/data/virtual-list.js +86 -0
- package/dist/data/virtual.d.ts +20 -0
- package/dist/data/virtual.d.ts.map +1 -0
- package/dist/data/virtual.js +4 -0
- package/dist/forms/FormErrorSummary.d.ts +29 -0
- package/dist/forms/FormErrorSummary.d.ts.map +1 -0
- package/dist/forms/FormErrorSummary.js +28 -0
- package/dist/forms/create-form.d.ts +31 -0
- package/dist/forms/create-form.d.ts.map +1 -0
- package/dist/forms/create-form.js +18 -0
- package/dist/forms/field.d.ts +22 -0
- package/dist/forms/field.d.ts.map +1 -0
- package/dist/forms/field.js +9 -0
- package/dist/forms/index.d.ts +17 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/index.js +13 -0
- package/dist/forms/use-form-draft.d.ts +61 -0
- package/dist/forms/use-form-draft.d.ts.map +1 -0
- package/dist/forms/use-form-draft.js +55 -0
- package/dist/guard/guard-hook.d.ts +40 -0
- package/dist/guard/guard-hook.d.ts.map +1 -0
- package/dist/guard/guard-hook.js +55 -0
- package/dist/guard/index.d.ts +144 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +315 -0
- package/dist/guard/types.d.ts +97 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +0 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/motion/index.d.ts +29 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +12 -0
- package/dist/notifications/bell.d.ts +12 -0
- package/dist/notifications/bell.d.ts.map +1 -0
- package/dist/notifications/bell.js +84 -0
- package/dist/notifications/center.d.ts +20 -0
- package/dist/notifications/center.d.ts.map +1 -0
- package/dist/notifications/center.js +144 -0
- package/dist/notifications/define-notifications.d.ts +97 -0
- package/dist/notifications/define-notifications.d.ts.map +1 -0
- package/dist/notifications/define-notifications.js +27 -0
- package/dist/notifications/index.d.ts +36 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +52 -0
- package/dist/notifications/notify.d.ts +92 -0
- package/dist/notifications/notify.d.ts.map +1 -0
- package/dist/notifications/notify.js +127 -0
- package/dist/notifications/overlay.d.ts +20 -0
- package/dist/notifications/overlay.d.ts.map +1 -0
- package/dist/notifications/overlay.js +12 -0
- package/dist/notifications/store.d.ts +120 -0
- package/dist/notifications/store.d.ts.map +1 -0
- package/dist/notifications/store.js +113 -0
- package/dist/provider/index.d.ts +93 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +106 -0
- package/dist/query/devtools.d.ts +21 -0
- package/dist/query/devtools.d.ts.map +1 -0
- package/dist/query/devtools.js +12 -0
- package/dist/query/index.d.ts +65 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +68 -0
- package/dist/register.d.ts +139 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +6 -0
- package/dist/router-tanstack/index.d.ts +74 -0
- package/dist/router-tanstack/index.d.ts.map +1 -0
- package/dist/router-tanstack/index.js +29 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts +78 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/multi-search-param-store.js +35 -0
- package/dist/router-tanstack/search-param-store.d.ts +92 -0
- package/dist/router-tanstack/search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/search-param-store.js +26 -0
- package/dist/shell/account-types.d.ts +118 -0
- package/dist/shell/account-types.d.ts.map +1 -0
- package/dist/shell/account-types.js +0 -0
- package/dist/shell/app-breadcrumbs.d.ts +17 -0
- package/dist/shell/app-breadcrumbs.d.ts.map +1 -0
- package/dist/shell/app-breadcrumbs.js +39 -0
- package/dist/shell/app-header.module.css +73 -0
- package/dist/shell/app-header.module.css.d.ts +11 -0
- package/dist/shell/app-mobile-nav.d.ts +26 -0
- package/dist/shell/app-mobile-nav.d.ts.map +1 -0
- package/dist/shell/app-mobile-nav.js +106 -0
- package/dist/shell/app-mobile-nav.module.css +100 -0
- package/dist/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/dist/shell/app-sidebar-account.d.ts +3 -0
- package/dist/shell/app-sidebar-account.d.ts.map +1 -0
- package/dist/shell/app-sidebar-account.js +84 -0
- package/dist/shell/app-sidebar.d.ts +56 -0
- package/dist/shell/app-sidebar.d.ts.map +1 -0
- package/dist/shell/app-sidebar.js +455 -0
- package/dist/shell/app-sidebar.module.css +414 -0
- package/dist/shell/app-sidebar.module.css.d.ts +34 -0
- package/dist/shell/index.d.ts +123 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +179 -0
- package/dist/shell/page-header.d.ts +13 -0
- package/dist/shell/page-header.d.ts.map +1 -0
- package/dist/shell/page-header.js +23 -0
- package/dist/shell/sidebar-search.d.ts +12 -0
- package/dist/shell/sidebar-search.d.ts.map +1 -0
- package/dist/shell/sidebar-search.js +62 -0
- package/dist/shell/sidebar-search.module.css +62 -0
- package/dist/shell/sidebar-search.module.css.d.ts +11 -0
- package/dist/state.d.ts +62 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +124 -0
- package/dist/styles.css +166 -0
- package/dist/surfaces.d.ts +376 -0
- package/dist/surfaces.d.ts.map +1 -0
- package/dist/surfaces.js +306 -0
- package/dist/theme/controls.module.css +143 -0
- package/dist/theme/controls.module.css.d.ts +17 -0
- package/dist/theme/floating.module.css +35 -0
- package/dist/theme/floating.module.css.d.ts +9 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +733 -0
- package/dist/theme/nav-link.module.css +67 -0
- package/dist/theme/nav-link.module.css.d.ts +8 -0
- package/dist/theme/segmented-control.module.css +14 -0
- package/dist/theme/segmented-control.module.css.d.ts +8 -0
- package/dist/theme/timeline.module.css +29 -0
- package/dist/theme/timeline.module.css.d.ts +9 -0
- package/dist/theme-lab/index.d.ts +59 -0
- package/dist/theme-lab/index.d.ts.map +1 -0
- package/dist/theme-lab/index.js +263 -0
- package/dist/theme-toggle/index.d.ts +8 -0
- package/dist/theme-toggle/index.d.ts.map +1 -0
- package/dist/theme-toggle/index.js +155 -0
- package/dist/tokens/index.d.ts +151 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +246 -0
- package/dist/tokens/palette.d.ts +304 -0
- package/dist/tokens/palette.d.ts.map +1 -0
- package/dist/tokens/palette.js +186 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +68 -0
- package/llms.txt +149 -0
- package/package.json +246 -37
- package/src/agent/ai-sdk-transport.ts +280 -0
- package/src/agent/history.ts +128 -0
- package/src/agent/index.ts +92 -0
- package/src/agent/outcome.ts +120 -0
- package/src/agent/part-list.tsx +292 -0
- package/src/agent/parts.ts +136 -0
- package/src/agent/stick-to-bottom.tsx +154 -0
- package/src/agent/thread.ts +312 -0
- package/src/agent/transport.ts +114 -0
- package/src/agent/use-agent-stream.ts +141 -0
- package/src/agent/use-agent-thread-runs.ts +440 -0
- package/src/agent-chat/composer.tsx +131 -0
- package/src/agent-chat/index.ts +35 -0
- package/src/agent-chat/thread-detail-panel.tsx +192 -0
- package/src/agent-chat/thread-feed.tsx +81 -0
- package/src/agent-chat/thread-message.tsx +251 -0
- package/src/agent-chat/thread-outcome-card.tsx +196 -0
- package/src/agent-chat/thread-workspace.tsx +179 -0
- package/src/charts/hooks/useChartSize.ts +31 -0
- package/src/charts/hooks/useChartTooltip.ts +31 -0
- package/src/charts/hooks/useHoverSync.ts +116 -0
- package/src/charts/hover-context.ts +28 -0
- package/src/charts/hover-sync.tsx +37 -0
- package/src/charts/index.ts +118 -0
- package/src/charts/kinds/Bars.tsx +634 -0
- package/src/charts/kinds/Donut.tsx +233 -0
- package/src/charts/kinds/DualPanel.tsx +432 -0
- package/src/charts/kinds/Heatmap.tsx +255 -0
- package/src/charts/kinds/MultiLine.tsx +376 -0
- package/src/charts/kinds/StackedArea.tsx +218 -0
- package/src/charts/kinds/ZonedLine.tsx +346 -0
- package/src/charts/primitives/AreaGradient.tsx +26 -0
- package/src/charts/primitives/Axes.tsx +97 -0
- package/src/charts/primitives/ChartCard.tsx +180 -0
- package/src/charts/primitives/ChartFrame.tsx +157 -0
- package/src/charts/primitives/ChartLegend.tsx +302 -0
- package/src/charts/primitives/ChartTooltip.tsx +158 -0
- package/src/charts/primitives/Crosshair.tsx +40 -0
- package/src/charts/primitives/HoverOverlay.tsx +24 -0
- package/src/charts/primitives/ResponsiveChart.tsx +64 -0
- package/src/charts/primitives/ZoneRects.tsx +67 -0
- package/src/charts/series.ts +163 -0
- package/src/charts/sparklines/BarSparkline.tsx +48 -0
- package/src/charts/sparklines/LineSparkline.tsx +57 -0
- package/src/charts/sparklines/index.ts +2 -0
- package/src/charts/theme.tsx +53 -0
- package/src/charts/utils/domain.test.ts +24 -0
- package/src/charts/utils/domain.ts +22 -0
- package/src/charts/utils/format.ts +27 -0
- package/src/charts/utils/ticks.ts +18 -0
- package/src/cli/check-theme.test.ts +658 -0
- package/src/cli/index.ts +1497 -0
- package/src/cli/init-sync.test.ts +160 -0
- package/src/commands/ShortcutsHelp.tsx +129 -0
- package/src/commands/define-commands.ts +184 -0
- package/src/commands/define-overlays.ts +197 -0
- package/src/commands/index.ts +86 -0
- package/src/commands/overlays-mount.tsx +301 -0
- package/src/commands/projectors.ts +267 -0
- package/src/commands/shortcut-format.ts +83 -0
- package/src/commands/useCommandHotkeys.ts +114 -0
- package/src/connectivity/connectivity-indicator.tsx +249 -0
- package/src/connectivity/connectivity-provider.tsx +186 -0
- package/src/connectivity/index.ts +18 -0
- package/src/connectivity/types.ts +39 -0
- package/src/connectivity/use-connectivity.ts +25 -0
- package/src/content/article-actions.test.ts +78 -0
- package/src/content/article-actions.ts +72 -0
- package/src/content/article-card.module.css +109 -0
- package/src/content/article-card.module.css.d.ts +16 -0
- package/src/content/article-card.tsx +173 -0
- package/src/content/article-filter-bar.tsx +88 -0
- package/src/content/article-layout.module.css +131 -0
- package/src/content/article-layout.module.css.d.ts +20 -0
- package/src/content/article-layout.tsx +167 -0
- package/src/content/article-model.test.ts +119 -0
- package/src/content/article-model.ts +110 -0
- package/src/content/block-split.test.ts +75 -0
- package/src/content/block-split.ts +102 -0
- package/src/content/callout-alert.ts +88 -0
- package/src/content/callout.module.css +77 -0
- package/src/content/callout.module.css.d.ts +16 -0
- package/src/content/callout.tsx +96 -0
- package/src/content/code-block.module.css +86 -0
- package/src/content/code-block.module.css.d.ts +14 -0
- package/src/content/code-block.tsx +82 -0
- package/src/content/copy-action.tsx +79 -0
- package/src/content/fence-block.tsx +39 -0
- package/src/content/glyphs.tsx +53 -0
- package/src/content/guide.module.css +62 -0
- package/src/content/guide.module.css.d.ts +13 -0
- package/src/content/guide.tsx +174 -0
- package/src/content/heading-anchor.tsx +54 -0
- package/src/content/heading-components.tsx +62 -0
- package/src/content/highlighter.ts +123 -0
- package/src/content/index.ts +60 -0
- package/src/content/markdown-hast.ts +80 -0
- package/src/content/markdown.tsx +346 -0
- package/src/content/mdx.tsx +127 -0
- package/src/content/mermaid.module.css +20 -0
- package/src/content/mermaid.module.css.d.ts +8 -0
- package/src/content/mermaid.tsx +124 -0
- package/src/content/prose.module.css +330 -0
- package/src/content/prose.module.css.d.ts +12 -0
- package/src/content/prose.tsx +53 -0
- package/src/content/reading-progress.module.css +22 -0
- package/src/content/reading-progress.module.css.d.ts +9 -0
- package/src/content/reading-progress.tsx +67 -0
- package/src/content/slug.test.ts +62 -0
- package/src/content/slug.ts +57 -0
- package/src/content/toc.module.css +51 -0
- package/src/content/toc.module.css.d.ts +13 -0
- package/src/content/toc.tsx +226 -0
- package/src/content/url-hardening.ts +46 -0
- package/src/dashboard/delta-badge.tsx +70 -0
- package/src/dashboard/empty-state.tsx +80 -0
- package/src/dashboard/index.ts +11 -0
- package/src/dashboard/settings-section.module.css +23 -0
- package/src/dashboard/settings-section.module.css.d.ts +10 -0
- package/src/dashboard/settings-section.tsx +118 -0
- package/src/dashboard/stat-card.tsx +105 -0
- package/src/data/data-table.tsx +695 -0
- package/src/data/index.ts +37 -0
- package/src/data/table.ts +46 -0
- package/src/data/virtual-list.tsx +180 -0
- package/src/data/virtual.ts +21 -0
- package/src/forms/FormErrorSummary.tsx +64 -0
- package/src/forms/create-form.ts +57 -0
- package/src/forms/field.ts +30 -0
- package/src/forms/index.ts +26 -0
- package/src/forms/use-form-draft.ts +170 -0
- package/src/guard/check-source.test.ts +834 -0
- package/src/guard/guard-hook.test.ts +173 -0
- package/src/guard/guard-hook.ts +122 -0
- package/src/guard/index.ts +510 -0
- package/src/guard/types.ts +117 -0
- package/src/index.ts +139 -0
- package/src/motion/index.ts +26 -0
- package/src/notifications/bell.tsx +108 -0
- package/src/notifications/center.tsx +245 -0
- package/src/notifications/define-notifications.ts +162 -0
- package/src/notifications/index.ts +79 -0
- package/src/notifications/notify.tsx +260 -0
- package/src/notifications/overlay.tsx +64 -0
- package/src/notifications/store.ts +287 -0
- package/src/provider/index.tsx +234 -0
- package/src/query/devtools.tsx +38 -0
- package/src/query/index.ts +129 -0
- package/src/register.ts +158 -0
- package/src/router-tanstack/index.ts +111 -0
- package/src/router-tanstack/multi-search-param-store.test.ts +56 -0
- package/src/router-tanstack/multi-search-param-store.ts +122 -0
- package/src/router-tanstack/search-param-store.ts +125 -0
- package/src/shell/account-types.ts +119 -0
- package/src/shell/app-breadcrumbs.tsx +90 -0
- package/src/shell/app-header.module.css +73 -0
- package/src/shell/app-header.module.css.d.ts +11 -0
- package/src/shell/app-mobile-nav.module.css +100 -0
- package/src/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/src/shell/app-mobile-nav.tsx +146 -0
- package/src/shell/app-sidebar-account.tsx +142 -0
- package/src/shell/app-sidebar.module.css +414 -0
- package/src/shell/app-sidebar.module.css.d.ts +34 -0
- package/src/shell/app-sidebar.tsx +632 -0
- package/src/shell/index.tsx +343 -0
- package/src/shell/page-header.tsx +35 -0
- package/src/shell/sidebar-search.module.css +62 -0
- package/src/shell/sidebar-search.module.css.d.ts +11 -0
- package/src/shell/sidebar-search.tsx +80 -0
- package/src/state.ts +246 -0
- package/src/styles.css +166 -0
- package/src/styles.floor.test.ts +36 -0
- package/src/surfaces.ts +489 -0
- package/src/theme/border-coverage.test.ts +272 -0
- package/src/theme/contrast.test.ts +306 -0
- package/src/theme/controls.module.css +143 -0
- package/src/theme/controls.module.css.d.ts +17 -0
- package/src/theme/floating.module.css +35 -0
- package/src/theme/floating.module.css.d.ts +9 -0
- package/src/theme/index.ts +933 -0
- package/src/theme/nav-link.module.css +67 -0
- package/src/theme/nav-link.module.css.d.ts +8 -0
- package/src/theme/segmented-control.module.css +14 -0
- package/src/theme/segmented-control.module.css.d.ts +8 -0
- package/src/theme/shadow-surfaces.test.ts +421 -0
- package/src/theme/timeline.module.css +29 -0
- package/src/theme/timeline.module.css.d.ts +9 -0
- package/src/theme-lab/index.tsx +359 -0
- package/src/theme-lab/theme-lab.test.ts +60 -0
- package/src/theme-toggle/index.tsx +180 -0
- package/src/tokens/index.ts +363 -0
- package/src/tokens/palette.ts +288 -0
- package/src/vite.ts +122 -0
- package/src/index.css +0 -986
- package/src/starlight.css +0 -308
- package/tailwind.config.js +0 -78
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown — react-markdown over `Prose`, with a streaming-repair pipeline for AI-streamed output
|
|
3
|
+
* (docs/CONTENT-SPEC.md §2/§3/§6). This is the package's ONLY markdown renderer — pass
|
|
4
|
+
* `streaming density="chat"` to render agent/chat text (see `agent/rules/basalt-content.md`);
|
|
5
|
+
* `agent/**` deliberately ships no renderer of its own, since `agent/** -> content` is
|
|
6
|
+
* lint-blocked by design.
|
|
7
|
+
*
|
|
8
|
+
* LAZY-LOADED: react-markdown and remark-gfm are OPTIONAL peers, loaded via `React.lazy` + dynamic
|
|
9
|
+
* `import()` (mirrors `agent/streaming-markdown.tsx` and `./highlighter`) — importing
|
|
10
|
+
* `basalt-ui/content` never eagerly resolves them. Without them installed, `Markdown` renders the
|
|
11
|
+
* raw string as plain text.
|
|
12
|
+
*
|
|
13
|
+
* Default element overrides:
|
|
14
|
+
* - `h1`..`h6` — slugged + hover-anchored (`./heading-components`).
|
|
15
|
+
* - fenced code (`pre`) — `CodeBlock`, or `MermaidDiagram` for a settled ` ```mermaid ` fence
|
|
16
|
+
* (`./fence-block`).
|
|
17
|
+
* - `blockquote` — a GFM alert marker (`[!NOTE]` etc.) renders as `Callout`; otherwise passes
|
|
18
|
+
* through (`./callout-alert`).
|
|
19
|
+
* - `a`/`img` — hardened via `allowedLinkPrefixes`/`allowedImagePrefixes`/`defaultOrigin`
|
|
20
|
+
* (`./url-hardening`); a disallowed URL (including remend's `streamdown:incomplete-link`
|
|
21
|
+
* sentinel) drops the `href`/`src`, and the component renders an unlinked span / nothing.
|
|
22
|
+
*
|
|
23
|
+
* Streaming mode (`streaming`): `blockSplit` splits `children` into top-level blocks. Every block
|
|
24
|
+
* except the last renders through a memoized renderer (`React.memo`, referentially stable
|
|
25
|
+
* `components`/`urlTransform`) — only the in-flight tail block, repaired via `remend`, re-renders
|
|
26
|
+
* per streamed token. Heading ids: the tail block (and, once it settles, the block it becomes) get
|
|
27
|
+
* their OWN `SlugTracker` rather than sharing one document-wide tracker — a duplicate heading text
|
|
28
|
+
* across two DIFFERENT blocks will not get a deduped `-1` suffix in streaming mode. Streamed chat
|
|
29
|
+
* content doesn't drive a `TableOfContents`, so this is an accepted tradeoff, not a bug.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { Markdown } from 'basalt-ui/content'
|
|
33
|
+
*
|
|
34
|
+
* <Markdown>{articleMarkdown}</Markdown>
|
|
35
|
+
* <Markdown density="chat" streaming allowedLinkPrefixes={['https://']}>{streamedText}</Markdown>
|
|
36
|
+
*/
|
|
37
|
+
import type { CSSProperties, JSX } from 'react'
|
|
38
|
+
import { lazy, memo, Suspense, useMemo } from 'react'
|
|
39
|
+
import remend from 'remend'
|
|
40
|
+
import type {
|
|
41
|
+
Components,
|
|
42
|
+
ExtraProps,
|
|
43
|
+
Options as ReactMarkdownOptions,
|
|
44
|
+
UrlTransform,
|
|
45
|
+
} from 'react-markdown'
|
|
46
|
+
import { ALERT_CALLOUT_KIND, ALERT_TITLE, detectAlert, stripAlertMarker } from './callout-alert'
|
|
47
|
+
import { FenceBlock } from './fence-block'
|
|
48
|
+
import { createHeadingComponents } from './heading-components'
|
|
49
|
+
import { Callout } from './callout'
|
|
50
|
+
import { Prose } from './prose'
|
|
51
|
+
import type { ProseDensity } from './prose'
|
|
52
|
+
import { SlugTracker } from './slug'
|
|
53
|
+
import { blockSplit } from './block-split'
|
|
54
|
+
import { createUrlTransform } from './url-hardening'
|
|
55
|
+
|
|
56
|
+
// ── Public types ───────────────────────────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export type MarkdownComponents = Components
|
|
59
|
+
|
|
60
|
+
export type MarkdownProps = {
|
|
61
|
+
/** The markdown string to render. Safe to update on every character during streaming. */
|
|
62
|
+
readonly children: string
|
|
63
|
+
/** Typography density passed through to `Prose`. Default `'article'`. */
|
|
64
|
+
readonly density?: ProseDensity
|
|
65
|
+
/** `Prose`'s measure cap. Defaults to `true` for `'article'` density, `false` for `'chat'`. */
|
|
66
|
+
readonly measure?: boolean
|
|
67
|
+
/** AI-stream mode — block-split + memoize + `remend`-repair the in-flight tail. Default `false`. */
|
|
68
|
+
readonly streaming?: boolean
|
|
69
|
+
/** Per-element overrides merged OVER the defaults (only the keys you supply are replaced). */
|
|
70
|
+
readonly components?: MarkdownComponents
|
|
71
|
+
/** Allowed `href` prefixes. Default `['https://', 'mailto:', '#', '/']`. */
|
|
72
|
+
readonly allowedLinkPrefixes?: readonly string[]
|
|
73
|
+
/** Allowed `img src` prefixes. Default `['https://', '/']`; in `streaming` mode `['/']`
|
|
74
|
+
* (same-origin only) — auto-fetched images are the classic prompt-injection exfiltration
|
|
75
|
+
* channel, so remote origins must be opted in explicitly for model-generated content. */
|
|
76
|
+
readonly allowedImagePrefixes?: readonly string[]
|
|
77
|
+
/** Resolves a relative `href`/`src` to an absolute URL before the allowlist check's result is used. */
|
|
78
|
+
readonly defaultOrigin?: string
|
|
79
|
+
/** Escape hatch — appended after `remark-gfm`. */
|
|
80
|
+
readonly remarkPlugins?: readonly unknown[]
|
|
81
|
+
/** Escape hatch — appended after react-markdown's defaults. */
|
|
82
|
+
readonly rehypePlugins?: readonly unknown[]
|
|
83
|
+
readonly className?: string
|
|
84
|
+
readonly style?: CSSProperties
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ── Default element overrides ─────────────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
type LinkProps = JSX.IntrinsicElements['a'] & ExtraProps
|
|
90
|
+
type ImgProps = JSX.IntrinsicElements['img'] & ExtraProps
|
|
91
|
+
type BlockquoteProps = JSX.IntrinsicElements['blockquote'] & ExtraProps
|
|
92
|
+
type PreProps = JSX.IntrinsicElements['pre'] & ExtraProps
|
|
93
|
+
|
|
94
|
+
function LinkRenderer({ href, children }: LinkProps) {
|
|
95
|
+
if (href === undefined) return <span>{children}</span>
|
|
96
|
+
const external = href.startsWith('http://') || href.startsWith('https://')
|
|
97
|
+
return (
|
|
98
|
+
<a href={href} {...(external && { target: '_blank', rel: 'noreferrer noopener' })}>
|
|
99
|
+
{children}
|
|
100
|
+
</a>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function ImageRenderer({ src, alt }: ImgProps) {
|
|
105
|
+
// A blocked src arrives as undefined OR '' depending on how urlTransform dropped it — an
|
|
106
|
+
// `<img src="">` renders the broken-image glyph, so both cases must skip the element entirely.
|
|
107
|
+
if (typeof src !== 'string' || src === '') return <span aria-label={alt} />
|
|
108
|
+
return <img src={src} alt={alt ?? ''} loading="lazy" />
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function BlockquoteRenderer({ children }: BlockquoteProps) {
|
|
112
|
+
const alert = detectAlert(children)
|
|
113
|
+
if (!alert) return <blockquote>{children}</blockquote>
|
|
114
|
+
return (
|
|
115
|
+
<Callout kind={ALERT_CALLOUT_KIND[alert.kind]} title={ALERT_TITLE[alert.kind]}>
|
|
116
|
+
{stripAlertMarker(children, alert.marker)}
|
|
117
|
+
</Callout>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function createPreRenderer(settled: boolean) {
|
|
122
|
+
return function PreRenderer({ node }: PreProps) {
|
|
123
|
+
return <FenceBlock settled={settled} {...(node !== undefined && { node })} />
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function buildMarkdownComponents(tracker: SlugTracker, settled: boolean): Components {
|
|
128
|
+
return {
|
|
129
|
+
...createHeadingComponents(tracker),
|
|
130
|
+
pre: createPreRenderer(settled),
|
|
131
|
+
blockquote: BlockquoteRenderer,
|
|
132
|
+
a: LinkRenderer,
|
|
133
|
+
img: ImageRenderer,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── Lazy-loaded react-markdown + remark-gfm ───────────────────────────────────────────────────
|
|
138
|
+
|
|
139
|
+
type RemarkPluginList = NonNullable<ReactMarkdownOptions['remarkPlugins']>
|
|
140
|
+
type RehypePluginList = NonNullable<ReactMarkdownOptions['rehypePlugins']>
|
|
141
|
+
|
|
142
|
+
type BridgeProps = {
|
|
143
|
+
readonly text: string
|
|
144
|
+
readonly components: Components
|
|
145
|
+
readonly urlTransform: UrlTransform
|
|
146
|
+
readonly remarkPlugins?: readonly unknown[]
|
|
147
|
+
readonly rehypePlugins?: readonly unknown[]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function PlainTextFallback({ text }: { text: string }) {
|
|
151
|
+
return <span style={{ whiteSpace: 'pre-wrap' }}>{text}</span>
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The dynamic import chain loads react-markdown + remark-gfm only at render time. If either peer
|
|
155
|
+
// is absent the import fails — `.catch` resolves to the plain-text fallback (no unhandled
|
|
156
|
+
// rejection, no crash), the same optional-peer contract as `agent/streaming-markdown.tsx`.
|
|
157
|
+
const LazyReactMarkdown = lazy(() =>
|
|
158
|
+
Promise.all([import('react-markdown'), import('remark-gfm')])
|
|
159
|
+
.then(([{ default: ReactMarkdown }, { default: remarkGfm }]) => {
|
|
160
|
+
function Bridge({
|
|
161
|
+
text,
|
|
162
|
+
components,
|
|
163
|
+
urlTransform,
|
|
164
|
+
remarkPlugins,
|
|
165
|
+
rehypePlugins,
|
|
166
|
+
}: BridgeProps) {
|
|
167
|
+
const remarkPluginsList: RemarkPluginList = [
|
|
168
|
+
remarkGfm,
|
|
169
|
+
...((remarkPlugins ?? []) as RemarkPluginList),
|
|
170
|
+
]
|
|
171
|
+
return (
|
|
172
|
+
<ReactMarkdown
|
|
173
|
+
components={components}
|
|
174
|
+
urlTransform={urlTransform}
|
|
175
|
+
remarkPlugins={remarkPluginsList}
|
|
176
|
+
{...(rehypePlugins !== undefined && {
|
|
177
|
+
rehypePlugins: rehypePlugins as RehypePluginList,
|
|
178
|
+
})}
|
|
179
|
+
>
|
|
180
|
+
{text}
|
|
181
|
+
</ReactMarkdown>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
return { default: Bridge }
|
|
185
|
+
})
|
|
186
|
+
.catch(() => ({ default: ({ text }: BridgeProps) => <PlainTextFallback text={text} /> })),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
// ── Streaming block rendering ──────────────────────────────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
type BlockProps = {
|
|
192
|
+
readonly text: string
|
|
193
|
+
readonly settled: boolean
|
|
194
|
+
readonly components?: MarkdownComponents
|
|
195
|
+
readonly urlTransform: UrlTransform
|
|
196
|
+
readonly remarkPlugins?: readonly unknown[]
|
|
197
|
+
readonly rehypePlugins?: readonly unknown[]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// A fresh SlugTracker per block (not shared across blocks) — see the module JSDoc's streaming-mode
|
|
201
|
+
// heading-id tradeoff. Recreated only when `text` changes, so a memoized (settled) block's tracker
|
|
202
|
+
// is created exactly once.
|
|
203
|
+
function BlockRenderer({
|
|
204
|
+
text,
|
|
205
|
+
settled,
|
|
206
|
+
components,
|
|
207
|
+
urlTransform,
|
|
208
|
+
remarkPlugins,
|
|
209
|
+
rehypePlugins,
|
|
210
|
+
}: BlockProps) {
|
|
211
|
+
// `text` isn't read in the factory below — it's the reset KEY, forcing a fresh tracker per block.
|
|
212
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
213
|
+
const tracker = useMemo(() => new SlugTracker(), [text])
|
|
214
|
+
const componentsMap = useMemo(
|
|
215
|
+
() => ({ ...buildMarkdownComponents(tracker, settled), ...components }),
|
|
216
|
+
[tracker, settled, components],
|
|
217
|
+
)
|
|
218
|
+
return (
|
|
219
|
+
<LazyReactMarkdown
|
|
220
|
+
text={text}
|
|
221
|
+
components={componentsMap}
|
|
222
|
+
urlTransform={urlTransform}
|
|
223
|
+
{...(remarkPlugins !== undefined && { remarkPlugins })}
|
|
224
|
+
{...(rehypePlugins !== undefined && { rehypePlugins })}
|
|
225
|
+
/>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Referential stability of `components`/`urlTransform` (both memoized by the caller) is what makes
|
|
230
|
+
// this memo skip re-rendering an unchanged settled block — see the module JSDoc.
|
|
231
|
+
const MemoizedBlock = memo(BlockRenderer)
|
|
232
|
+
|
|
233
|
+
function StreamingTailBlock(props: Omit<BlockProps, 'settled'>) {
|
|
234
|
+
const repaired = useMemo(() => remend(props.text), [props.text])
|
|
235
|
+
return <BlockRenderer {...props} text={repaired} settled={false} />
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
type BodyProps = {
|
|
239
|
+
readonly text: string
|
|
240
|
+
readonly components?: MarkdownComponents
|
|
241
|
+
readonly urlTransform: UrlTransform
|
|
242
|
+
readonly remarkPlugins?: readonly unknown[]
|
|
243
|
+
readonly rehypePlugins?: readonly unknown[]
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function SettledBody({ text, components, urlTransform, remarkPlugins, rehypePlugins }: BodyProps) {
|
|
247
|
+
return (
|
|
248
|
+
<Suspense fallback={<PlainTextFallback text={text} />}>
|
|
249
|
+
<BlockRenderer
|
|
250
|
+
text={text}
|
|
251
|
+
settled
|
|
252
|
+
urlTransform={urlTransform}
|
|
253
|
+
{...(components !== undefined && { components })}
|
|
254
|
+
{...(remarkPlugins !== undefined && { remarkPlugins })}
|
|
255
|
+
{...(rehypePlugins !== undefined && { rehypePlugins })}
|
|
256
|
+
/>
|
|
257
|
+
</Suspense>
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function StreamingBody({
|
|
262
|
+
text,
|
|
263
|
+
components,
|
|
264
|
+
urlTransform,
|
|
265
|
+
remarkPlugins,
|
|
266
|
+
rehypePlugins,
|
|
267
|
+
}: BodyProps) {
|
|
268
|
+
const blocks = useMemo(() => blockSplit(text), [text])
|
|
269
|
+
const lastIndex = blocks.length - 1
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<Suspense fallback={<PlainTextFallback text={text} />}>
|
|
273
|
+
{blocks.map((block, index) => {
|
|
274
|
+
const shared = {
|
|
275
|
+
text: block,
|
|
276
|
+
urlTransform,
|
|
277
|
+
...(components !== undefined && { components }),
|
|
278
|
+
...(remarkPlugins !== undefined && { remarkPlugins }),
|
|
279
|
+
...(rehypePlugins !== undefined && { rehypePlugins }),
|
|
280
|
+
}
|
|
281
|
+
// Block positions are stable during a stream (only the tail is ever replaced in place),
|
|
282
|
+
// so the array index is a safe, stable `key` here.
|
|
283
|
+
return index === lastIndex ? (
|
|
284
|
+
<StreamingTailBlock key={index} {...shared} />
|
|
285
|
+
) : (
|
|
286
|
+
<MemoizedBlock key={index} {...shared} settled />
|
|
287
|
+
)
|
|
288
|
+
})}
|
|
289
|
+
</Suspense>
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ── Markdown ───────────────────────────────────────────────────────────────────────────────────
|
|
294
|
+
|
|
295
|
+
const DEFAULT_LINK_PREFIXES: readonly string[] = ['https://', 'mailto:', '#', '/']
|
|
296
|
+
const DEFAULT_IMAGE_PREFIXES: readonly string[] = ['https://', '/']
|
|
297
|
+
/* Streamed (model-generated) markdown: images auto-fetch, so an open `https://` default is a
|
|
298
|
+
* prompt-injection exfiltration channel (``). Same-origin only
|
|
299
|
+
* unless the consumer opts specific origins in. Links stay clickable — navigation is user-initiated. */
|
|
300
|
+
const STREAMING_IMAGE_PREFIXES: readonly string[] = ['/']
|
|
301
|
+
|
|
302
|
+
export function Markdown({
|
|
303
|
+
children,
|
|
304
|
+
density = 'article',
|
|
305
|
+
measure,
|
|
306
|
+
streaming = false,
|
|
307
|
+
components,
|
|
308
|
+
allowedLinkPrefixes = DEFAULT_LINK_PREFIXES,
|
|
309
|
+
allowedImagePrefixes = streaming ? STREAMING_IMAGE_PREFIXES : DEFAULT_IMAGE_PREFIXES,
|
|
310
|
+
defaultOrigin,
|
|
311
|
+
remarkPlugins,
|
|
312
|
+
rehypePlugins,
|
|
313
|
+
className,
|
|
314
|
+
style,
|
|
315
|
+
}: MarkdownProps) {
|
|
316
|
+
const resolvedMeasure = measure ?? density === 'article'
|
|
317
|
+
|
|
318
|
+
const urlTransform = useMemo<UrlTransform>(
|
|
319
|
+
() =>
|
|
320
|
+
createUrlTransform({
|
|
321
|
+
allowedLinkPrefixes,
|
|
322
|
+
allowedImagePrefixes,
|
|
323
|
+
...(defaultOrigin !== undefined && { defaultOrigin }),
|
|
324
|
+
}),
|
|
325
|
+
[allowedLinkPrefixes, allowedImagePrefixes, defaultOrigin],
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
const bodyProps: BodyProps = {
|
|
329
|
+
text: children,
|
|
330
|
+
urlTransform,
|
|
331
|
+
...(components !== undefined && { components }),
|
|
332
|
+
...(remarkPlugins !== undefined && { remarkPlugins }),
|
|
333
|
+
...(rehypePlugins !== undefined && { rehypePlugins }),
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return (
|
|
337
|
+
<Prose
|
|
338
|
+
density={density}
|
|
339
|
+
measure={resolvedMeasure}
|
|
340
|
+
{...(className !== undefined && { className })}
|
|
341
|
+
{...(style !== undefined && { style })}
|
|
342
|
+
>
|
|
343
|
+
{streaming ? <StreamingBody {...bodyProps} /> : <SettledBody {...bodyProps} />}
|
|
344
|
+
</Prose>
|
|
345
|
+
)
|
|
346
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mdxComponents / createMdxComponents — the element map for MDX runtimes (docs/CONTENT-SPEC.md
|
|
3
|
+
* §2 decision 7 / §3). Wires an MDX pipeline's compiled output (`@content-collections/mdx/react`'s
|
|
4
|
+
* `MDXContent components={...}`, or any `useMDXComponents`) onto the SAME basalt primitives
|
|
5
|
+
* `Markdown` uses: slugged + anchored headings (`./heading-components`, shared — not duplicated),
|
|
6
|
+
* `CodeBlock`/`MermaidDiagram` fenced code, and GFM-alert-aware `Callout` blockquotes
|
|
7
|
+
* (`./callout-alert`, also shared).
|
|
8
|
+
*
|
|
9
|
+
* Unlike `Markdown`, links/images are NOT hardened here — MDX is authored content compiled at
|
|
10
|
+
* build time, not untrusted streamed text, so `a` only gets the external-link `target`/`rel`
|
|
11
|
+
* treatment. `img`, `table`, and every other tag pass through untouched (`Prose`'s CSS already
|
|
12
|
+
* styles them).
|
|
13
|
+
*
|
|
14
|
+
* MDX compiles a fenced code block to `<pre><code className="language-x">…</code></pre>` — there
|
|
15
|
+
* is no hast `node` prop available here the way react-markdown provides one (`./markdown-hast`),
|
|
16
|
+
* so extraction reads the compiled `code` element's `className`/`children` directly instead. A
|
|
17
|
+
* consequence: unlike `Markdown`, an MDX fence's ` ```ts title="…" ` meta string is NOT recovered
|
|
18
|
+
* (MDX's own compiler drops it without an extra rehype plugin) — only the language is.
|
|
19
|
+
*
|
|
20
|
+
* MDX pages must be wrapped in `<Prose>` by the consumer, or via `ArticleLayout` (the docs-page
|
|
21
|
+
* frame) — this module ships element overrides only, not a layout.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { mdxComponents } from 'basalt-ui/content'
|
|
25
|
+
* import { MDXContent } from '@content-collections/mdx/react'
|
|
26
|
+
*
|
|
27
|
+
* <Prose><MDXContent code={article.mdx} components={mdxComponents} /></Prose>
|
|
28
|
+
*/
|
|
29
|
+
import type { JSX, ReactNode } from 'react'
|
|
30
|
+
import { isValidElement } from 'react'
|
|
31
|
+
import type { Components, ExtraProps } from 'react-markdown'
|
|
32
|
+
import { ALERT_CALLOUT_KIND, ALERT_TITLE, detectAlert, stripAlertMarker } from './callout-alert'
|
|
33
|
+
import { Callout } from './callout'
|
|
34
|
+
import { CodeBlock } from './code-block'
|
|
35
|
+
import { createHeadingComponents } from './heading-components'
|
|
36
|
+
import { MermaidDiagram } from './mermaid'
|
|
37
|
+
import { SlugTracker } from './slug'
|
|
38
|
+
|
|
39
|
+
type MdxPreProps = JSX.IntrinsicElements['pre'] & ExtraProps
|
|
40
|
+
type MdxBlockquoteProps = JSX.IntrinsicElements['blockquote'] & ExtraProps
|
|
41
|
+
type MdxLinkProps = JSX.IntrinsicElements['a'] & ExtraProps
|
|
42
|
+
type MdxCodeProps = { className?: string; children?: ReactNode }
|
|
43
|
+
|
|
44
|
+
function nodeToText(node: ReactNode): string {
|
|
45
|
+
if (typeof node === 'string') return node
|
|
46
|
+
if (typeof node === 'number') return String(node)
|
|
47
|
+
if (Array.isArray(node)) return node.map(nodeToText).join('')
|
|
48
|
+
if (isValidElement(node)) return nodeToText((node.props as { children?: ReactNode }).children)
|
|
49
|
+
return ''
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type MdxFence = { readonly code: string; readonly language?: string }
|
|
53
|
+
|
|
54
|
+
function extractMdxFence(preChildren: ReactNode): MdxFence | undefined {
|
|
55
|
+
const codeElement = Array.isArray(preChildren) ? preChildren[0] : preChildren
|
|
56
|
+
if (!isValidElement(codeElement)) return undefined
|
|
57
|
+
|
|
58
|
+
const props = codeElement.props as MdxCodeProps
|
|
59
|
+
const language = props.className
|
|
60
|
+
?.split(/\s+/)
|
|
61
|
+
.find((name) => name.startsWith('language-'))
|
|
62
|
+
?.slice('language-'.length)
|
|
63
|
+
|
|
64
|
+
return { code: nodeToText(props.children), ...(language !== undefined && { language }) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function MdxPre({ children }: MdxPreProps) {
|
|
68
|
+
const fence = extractMdxFence(children)
|
|
69
|
+
if (!fence) return <pre>{children}</pre>
|
|
70
|
+
if (fence.language === 'mermaid') return <MermaidDiagram code={fence.code} />
|
|
71
|
+
return (
|
|
72
|
+
<CodeBlock
|
|
73
|
+
code={fence.code}
|
|
74
|
+
{...(fence.language !== undefined && { language: fence.language })}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function MdxBlockquote({ children }: MdxBlockquoteProps) {
|
|
80
|
+
const alert = detectAlert(children)
|
|
81
|
+
if (!alert) return <blockquote>{children}</blockquote>
|
|
82
|
+
return (
|
|
83
|
+
<Callout kind={ALERT_CALLOUT_KIND[alert.kind]} title={ALERT_TITLE[alert.kind]}>
|
|
84
|
+
{stripAlertMarker(children, alert.marker)}
|
|
85
|
+
</Callout>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function MdxLink({ href, children }: MdxLinkProps) {
|
|
90
|
+
const external = href !== undefined && /^https?:\/\//.test(href)
|
|
91
|
+
return (
|
|
92
|
+
<a
|
|
93
|
+
{...(href !== undefined && { href })}
|
|
94
|
+
{...(external && { target: '_blank', rel: 'noreferrer noopener' })}
|
|
95
|
+
>
|
|
96
|
+
{children}
|
|
97
|
+
</a>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type CreateMdxComponentsOptions = {
|
|
102
|
+
/** Reuse an existing tracker — e.g. to share heading ids with a `TableOfContents` collecting
|
|
103
|
+
* over the same rendered document. Omit for a fresh, page-scoped tracker. */
|
|
104
|
+
readonly slugTracker?: SlugTracker
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Builds the MDX element map (slugged/anchored headings, code/mermaid fences, alert-aware
|
|
108
|
+
* blockquotes, external-link treatment). Pass `slugTracker` to share ids across components
|
|
109
|
+
* rendering the same document; omit it to get a fresh tracker per call. */
|
|
110
|
+
export function createMdxComponents(options: CreateMdxComponentsOptions = {}): Components {
|
|
111
|
+
const tracker = options.slugTracker ?? new SlugTracker()
|
|
112
|
+
return {
|
|
113
|
+
...createHeadingComponents(tracker),
|
|
114
|
+
pre: MdxPre,
|
|
115
|
+
blockquote: MdxBlockquote,
|
|
116
|
+
a: MdxLink,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A ready-to-use element map for simple cases. Built ONCE at module scope with its own
|
|
122
|
+
* `SlugTracker` — every consumer of this constant shares that single tracker for the lifetime of
|
|
123
|
+
* the app, so a heading text repeated across two DIFFERENT MDX documents will get a `-1`-suffixed
|
|
124
|
+
* id on the second document, not a fresh `overview` on both. Reach for `createMdxComponents()`
|
|
125
|
+
* (called per document/render) instead when that matters — e.g. a multi-document docs site.
|
|
126
|
+
*/
|
|
127
|
+
export const mdxComponents: Components = createMdxComponents()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MermaidDiagram chrome — mirrors the CodeBlock surface idiom (docs/CONTENT-SPEC.md §2 decision 4):
|
|
3
|
+
* a subtle ink-tinted panel the SVG sits on, X-axis scroll as the sanctioned overflow exception for
|
|
4
|
+
* a diagram wider than its column. Block rhythm (the outer margin) is Prose's to own, not ours —
|
|
5
|
+
* see `prose.module.css`, which spaces every block object on one ladder.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.container {
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
border-radius: 8px;
|
|
12
|
+
background-color: color-mix(in srgb, var(--vx-ink) 6%, transparent);
|
|
13
|
+
padding: 16px;
|
|
14
|
+
overflow-x: auto;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.container :global(svg) {
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
height: auto;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
|
|
3
|
+
* signature — so dot access stays verbatim under the package's strict flags.
|
|
4
|
+
*/
|
|
5
|
+
declare const classes: {
|
|
6
|
+
readonly container: string
|
|
7
|
+
}
|
|
8
|
+
export default classes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MermaidDiagram — beautiful-mermaid (OPTIONAL PEER), `--vx-*` themed, streaming-safe
|
|
3
|
+
* (docs/CONTENT-SPEC.md §2 decision 4).
|
|
4
|
+
*
|
|
5
|
+
* Lazy dynamic `import('beautiful-mermaid')` behind a module-level singleton promise, mirroring
|
|
6
|
+
* the `./highlighter` optional-peer pattern: no unhandled rejection, no crash. Without the peer
|
|
7
|
+
* installed — or on a mermaid parse error with no previously-rendered diagram — it degrades to a
|
|
8
|
+
* plain `CodeBlock language="mermaid"` (or the `fallback` prop, if supplied).
|
|
9
|
+
*
|
|
10
|
+
* Theming passes `var(--vx-*)` strings straight through as the render options: the emitted SVG
|
|
11
|
+
* references those custom properties via presentation attributes, so a Mantine scheme flip is
|
|
12
|
+
* pure CSS — the SVG never needs to be re-rendered on a color-scheme change.
|
|
13
|
+
*
|
|
14
|
+
* Supported diagram types: flowchart, state, sequence, class, ER, XY chart. Full-grammar `mermaid`
|
|
15
|
+
* stays a consumer escape hatch (`agent/rules/basalt-content.md`).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { MermaidDiagram } from 'basalt-ui/content'
|
|
19
|
+
*
|
|
20
|
+
* <MermaidDiagram code={'graph TD\n A --> B'} />
|
|
21
|
+
*/
|
|
22
|
+
import type { CSSProperties, ReactNode } from 'react'
|
|
23
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
24
|
+
import { CodeBlock } from './code-block'
|
|
25
|
+
import classes from './mermaid.module.css'
|
|
26
|
+
|
|
27
|
+
// Import the type only — erased at runtime (verbatimModuleSyntax safe). `beautiful-mermaid` is a
|
|
28
|
+
// devDependency purely so this type resolves; the runtime import below is fully dynamic.
|
|
29
|
+
import type { RenderOptions } from 'beautiful-mermaid'
|
|
30
|
+
|
|
31
|
+
type MermaidModule = {
|
|
32
|
+
renderMermaidSVG: (text: string, options?: RenderOptions) => string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Static theme mapping onto the `--vx-*` token layer — every value is a `var(--vx-*)` string, so
|
|
37
|
+
* this object never changes across renders/schemes and can live at module scope.
|
|
38
|
+
*/
|
|
39
|
+
const MERMAID_THEME_OPTIONS: RenderOptions = {
|
|
40
|
+
bg: 'var(--vx-surface-panel)',
|
|
41
|
+
fg: 'var(--vx-ink)',
|
|
42
|
+
line: 'var(--vx-line)',
|
|
43
|
+
accent: 'var(--vx-accent)',
|
|
44
|
+
muted: 'var(--vx-muted)',
|
|
45
|
+
surface: 'var(--vx-surface-panel)',
|
|
46
|
+
border: 'var(--vx-surface-border)',
|
|
47
|
+
font: 'var(--basalt-font-sans)',
|
|
48
|
+
transparent: true,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let modulePromise: Promise<MermaidModule | null> | null = null
|
|
52
|
+
|
|
53
|
+
/** Module-level singleton — resolves once; every caller shares the same load attempt. */
|
|
54
|
+
function loadMermaidModule(): Promise<MermaidModule | null> {
|
|
55
|
+
modulePromise ??= import('beautiful-mermaid').catch(() => null)
|
|
56
|
+
return modulePromise
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type MermaidDiagramProps = {
|
|
60
|
+
/** Raw mermaid source (the fence body, without the surrounding ``` marks). */
|
|
61
|
+
readonly code: string
|
|
62
|
+
readonly className?: string
|
|
63
|
+
readonly style?: CSSProperties
|
|
64
|
+
/** Rendered instead of the default `CodeBlock language="mermaid"` degrade. */
|
|
65
|
+
readonly fallback?: ReactNode
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function MermaidDiagram({ code, className, style, fallback }: MermaidDiagramProps) {
|
|
69
|
+
const [mod, setMod] = useState<MermaidModule | null | undefined>(undefined)
|
|
70
|
+
const lastGoodRef = useRef<string | null>(null)
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
let cancelled = false
|
|
74
|
+
loadMermaidModule().then((loaded) => {
|
|
75
|
+
if (!cancelled) setMod(loaded)
|
|
76
|
+
return undefined
|
|
77
|
+
})
|
|
78
|
+
return () => {
|
|
79
|
+
cancelled = true
|
|
80
|
+
}
|
|
81
|
+
}, [])
|
|
82
|
+
|
|
83
|
+
// Pure and synchronous once `mod` is resolved — parse errors keep the last successfully
|
|
84
|
+
// rendered SVG (docs/CONTENT-SPEC.md §2 decision 4) instead of blanking a settled diagram.
|
|
85
|
+
const html = useMemo(() => {
|
|
86
|
+
if (!mod) return null
|
|
87
|
+
try {
|
|
88
|
+
const svg = mod.renderMermaidSVG(code, MERMAID_THEME_OPTIONS)
|
|
89
|
+
lastGoodRef.current = svg
|
|
90
|
+
return svg
|
|
91
|
+
} catch {
|
|
92
|
+
return lastGoodRef.current
|
|
93
|
+
}
|
|
94
|
+
}, [mod, code])
|
|
95
|
+
|
|
96
|
+
if (html === null) {
|
|
97
|
+
return (
|
|
98
|
+
fallback ?? (
|
|
99
|
+
<CodeBlock
|
|
100
|
+
language="mermaid"
|
|
101
|
+
code={code}
|
|
102
|
+
{...(className !== undefined && { className })}
|
|
103
|
+
{...(style !== undefined && { style })}
|
|
104
|
+
/>
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const firstLine = code.split('\n')[0]?.trim() || 'Diagram'
|
|
110
|
+
const containerClass = [classes.container, className].filter(Boolean).join(' ')
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
className={containerClass}
|
|
115
|
+
// a real <img> can't host inline SVG markup — `role="img"` on the wrapping div is the
|
|
116
|
+
// standard WAI-ARIA pattern for this.
|
|
117
|
+
// oxlint-disable-next-line jsx-a11y/prefer-tag-over-role
|
|
118
|
+
role="img"
|
|
119
|
+
aria-label={firstLine}
|
|
120
|
+
{...(style !== undefined && { style })}
|
|
121
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
122
|
+
/>
|
|
123
|
+
)
|
|
124
|
+
}
|