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,20 @@
|
|
|
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 root: string
|
|
7
|
+
readonly noToc: string
|
|
8
|
+
readonly header: string
|
|
9
|
+
readonly title: string
|
|
10
|
+
readonly description: string
|
|
11
|
+
readonly metaRow: string
|
|
12
|
+
readonly content: string
|
|
13
|
+
readonly tocRail: string
|
|
14
|
+
readonly footer: string
|
|
15
|
+
readonly navCell: string
|
|
16
|
+
readonly navCellNext: string
|
|
17
|
+
readonly navLabel: string
|
|
18
|
+
readonly navTarget: string
|
|
19
|
+
}
|
|
20
|
+
export default classes
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArticleLayout — the docs-page frame (docs/CONTENT-SPEC.md §3/§7): a centered content column, an
|
|
3
|
+
* optional sticky scroll-spy TOC rail, a title/description/date/reading-time meta header, and a
|
|
4
|
+
* prev/next pagination footer. Composes stage 1/2 primitives (`Prose`, `TableOfContents`,
|
|
5
|
+
* `ReadingProgress`) — it does not reimplement them.
|
|
6
|
+
*
|
|
7
|
+
* The header/content/footer all align to the SAME grid column, so the article body reads as one
|
|
8
|
+
* consistent width whether or not the TOC rail is visible (hidden below the 1200px breakpoint,
|
|
9
|
+
* where the content column takes the full centered width instead).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { ArticleLayout } from 'basalt-ui/content'
|
|
13
|
+
* import { Link } from '@tanstack/react-router'
|
|
14
|
+
*
|
|
15
|
+
* <ArticleLayout
|
|
16
|
+
* meta={{ title: 'Reading dashboards', description: '…', date: '2026-07-16', readingTime: 6 }}
|
|
17
|
+
* readingProgress
|
|
18
|
+
* next={{ label: 'Chart guide', href: '/guides/charts' }}
|
|
19
|
+
* renderLink={(target, node) => <Link to={target.href}>{node}</Link>}
|
|
20
|
+
* >
|
|
21
|
+
* <h2 id="setup">Setup</h2>
|
|
22
|
+
* <p>…</p>
|
|
23
|
+
* </ArticleLayout>
|
|
24
|
+
*/
|
|
25
|
+
import type { CSSProperties, ReactNode } from 'react'
|
|
26
|
+
import { useRef } from 'react'
|
|
27
|
+
import { ScrollArea } from '@mantine/core'
|
|
28
|
+
import classes from './article-layout.module.css'
|
|
29
|
+
import { formatArticleDate } from './article-model'
|
|
30
|
+
import type { ProseDensity } from './prose'
|
|
31
|
+
import { Prose } from './prose'
|
|
32
|
+
import { ReadingProgress } from './reading-progress'
|
|
33
|
+
import { TableOfContents } from './toc'
|
|
34
|
+
|
|
35
|
+
export type ArticleLayoutMeta = {
|
|
36
|
+
readonly title: string
|
|
37
|
+
readonly description?: string
|
|
38
|
+
/** ISO 8601 — rendered via `formatArticleDate`. No date library: `Intl` is a native API. */
|
|
39
|
+
readonly date?: string
|
|
40
|
+
/** Minutes; rendered as `"N min read"`. */
|
|
41
|
+
readonly readingTime?: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ArticleNavTarget = {
|
|
45
|
+
readonly label: string
|
|
46
|
+
readonly href: string
|
|
47
|
+
readonly description?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ArticleLayoutProps = {
|
|
51
|
+
/** The article body — typically `Prose`/`Markdown`/`MDXContent` output. */
|
|
52
|
+
readonly children: ReactNode
|
|
53
|
+
readonly meta?: ArticleLayoutMeta
|
|
54
|
+
/** Sticky scroll-spy TOC rail, auto-collected from the article body. Default `true`. */
|
|
55
|
+
readonly toc?: boolean
|
|
56
|
+
/** Scroll-driven top progress bar tracking the article body. Default `false` (opt-in). */
|
|
57
|
+
readonly readingProgress?: boolean
|
|
58
|
+
readonly prev?: ArticleNavTarget
|
|
59
|
+
readonly next?: ArticleNavTarget
|
|
60
|
+
/** Router bridge for the prev/next footer cells. Default renders a plain `<a href>`. */
|
|
61
|
+
readonly renderLink?: (target: ArticleNavTarget, node: ReactNode) => ReactNode
|
|
62
|
+
/** `Prose` density passthrough. Default `'article'`. */
|
|
63
|
+
readonly density?: ProseDensity
|
|
64
|
+
/** Locale passed to `formatArticleDate` for `meta.date`. Default `'en-US'` — see its JSDoc for
|
|
65
|
+
* why this is pinned rather than defaulting to the runtime locale. */
|
|
66
|
+
readonly locale?: string
|
|
67
|
+
readonly className?: string
|
|
68
|
+
readonly style?: CSSProperties
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function defaultRenderLink(target: ArticleNavTarget, node: ReactNode): ReactNode {
|
|
72
|
+
return <a href={target.href}>{node}</a>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function NavCell({
|
|
76
|
+
target,
|
|
77
|
+
side,
|
|
78
|
+
renderLink,
|
|
79
|
+
}: {
|
|
80
|
+
readonly target: ArticleNavTarget
|
|
81
|
+
readonly side: 'prev' | 'next'
|
|
82
|
+
readonly renderLink: (target: ArticleNavTarget, node: ReactNode) => ReactNode
|
|
83
|
+
}) {
|
|
84
|
+
const arrow = side === 'prev' ? '←' : '→'
|
|
85
|
+
const cellClass = [classes.navCell, side === 'next' && classes.navCellNext]
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.join(' ')
|
|
88
|
+
|
|
89
|
+
return renderLink(
|
|
90
|
+
target,
|
|
91
|
+
<span className={cellClass}>
|
|
92
|
+
<span className={classes.navLabel}>{side === 'prev' ? 'Previous' : 'Next'}</span>
|
|
93
|
+
<span className={classes.navTarget}>
|
|
94
|
+
{side === 'prev' && <span aria-hidden>{arrow}</span>}
|
|
95
|
+
<span>{target.label}</span>
|
|
96
|
+
{side === 'next' && <span aria-hidden>{arrow}</span>}
|
|
97
|
+
</span>
|
|
98
|
+
</span>,
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function ArticleLayout({
|
|
103
|
+
children,
|
|
104
|
+
meta,
|
|
105
|
+
toc = true,
|
|
106
|
+
readingProgress = false,
|
|
107
|
+
prev,
|
|
108
|
+
next,
|
|
109
|
+
renderLink = defaultRenderLink,
|
|
110
|
+
density = 'article',
|
|
111
|
+
locale = 'en-US',
|
|
112
|
+
className,
|
|
113
|
+
style,
|
|
114
|
+
}: ArticleLayoutProps) {
|
|
115
|
+
const articleRef = useRef<HTMLDivElement>(null)
|
|
116
|
+
const rootClass = [classes.root, !toc && classes.noToc, className].filter(Boolean).join(' ')
|
|
117
|
+
const hasMetaRow = meta?.date !== undefined || meta?.readingTime !== undefined
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div className={rootClass} {...(style !== undefined && { style })}>
|
|
121
|
+
{readingProgress && <ReadingProgress target={articleRef} />}
|
|
122
|
+
|
|
123
|
+
{meta !== undefined && (
|
|
124
|
+
<header className={classes.header}>
|
|
125
|
+
<h1 className={classes.title}>{meta.title}</h1>
|
|
126
|
+
{meta.description !== undefined && (
|
|
127
|
+
<p className={classes.description}>{meta.description}</p>
|
|
128
|
+
)}
|
|
129
|
+
{hasMetaRow && (
|
|
130
|
+
<div className={classes.metaRow}>
|
|
131
|
+
{meta.date !== undefined && <span>{formatArticleDate(meta.date, locale)}</span>}
|
|
132
|
+
{meta.date !== undefined && meta.readingTime !== undefined && <span>·</span>}
|
|
133
|
+
{meta.readingTime !== undefined && <span>{meta.readingTime} min read</span>}
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
</header>
|
|
137
|
+
)}
|
|
138
|
+
|
|
139
|
+
<div className={classes.content} ref={articleRef}>
|
|
140
|
+
<Prose density={density}>{children}</Prose>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
{toc && (
|
|
144
|
+
<div className={classes.tocRail}>
|
|
145
|
+
<ScrollArea.Autosize mah="calc(100vh - 108px)" type="hover">
|
|
146
|
+
<TableOfContents containerRef={articleRef} />
|
|
147
|
+
</ScrollArea.Autosize>
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
|
|
151
|
+
{(prev !== undefined || next !== undefined) && (
|
|
152
|
+
<footer className={classes.footer}>
|
|
153
|
+
{prev !== undefined ? (
|
|
154
|
+
<NavCell target={prev} side="prev" renderLink={renderLink} />
|
|
155
|
+
) : (
|
|
156
|
+
<span />
|
|
157
|
+
)}
|
|
158
|
+
{next !== undefined ? (
|
|
159
|
+
<NavCell target={next} side="next" renderLink={renderLink} />
|
|
160
|
+
) : (
|
|
161
|
+
<span />
|
|
162
|
+
)}
|
|
163
|
+
</footer>
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { filterArticles, formatArticleDate, sortArticles } from './article-model'
|
|
3
|
+
import type { Article } from './article-model'
|
|
4
|
+
|
|
5
|
+
function article(overrides: Partial<Article>): Article {
|
|
6
|
+
return { slug: 'x', title: 'Untitled', ...overrides }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('sortArticles', () => {
|
|
10
|
+
test('date-desc orders newest first (the default)', () => {
|
|
11
|
+
const articles = [
|
|
12
|
+
article({ slug: 'a', date: '2026-01-01' }),
|
|
13
|
+
article({ slug: 'b', date: '2026-06-01' }),
|
|
14
|
+
article({ slug: 'c', date: '2026-03-01' }),
|
|
15
|
+
]
|
|
16
|
+
expect(sortArticles(articles).map((a) => a.slug)).toEqual(['b', 'c', 'a'])
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('date-asc orders oldest first', () => {
|
|
20
|
+
const articles = [
|
|
21
|
+
article({ slug: 'a', date: '2026-01-01' }),
|
|
22
|
+
article({ slug: 'b', date: '2026-06-01' }),
|
|
23
|
+
article({ slug: 'c', date: '2026-03-01' }),
|
|
24
|
+
]
|
|
25
|
+
expect(sortArticles(articles, 'date-asc').map((a) => a.slug)).toEqual(['a', 'c', 'b'])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('title sorts locale-aware, pinned to en-US regardless of runtime default', () => {
|
|
29
|
+
const articles = [
|
|
30
|
+
article({ slug: 'a', title: 'Zebra' }),
|
|
31
|
+
article({ slug: 'b', title: 'apple' }),
|
|
32
|
+
article({ slug: 'c', title: 'Mango' }),
|
|
33
|
+
]
|
|
34
|
+
expect(sortArticles(articles, 'title').map((a) => a.slug)).toEqual(['b', 'c', 'a'])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('is stable on equal dates — input order preserved', () => {
|
|
38
|
+
const articles = [
|
|
39
|
+
article({ slug: 'a', date: '2026-01-01' }),
|
|
40
|
+
article({ slug: 'b', date: '2026-01-01' }),
|
|
41
|
+
article({ slug: 'c', date: '2026-01-01' }),
|
|
42
|
+
]
|
|
43
|
+
expect(sortArticles(articles, 'date-desc').map((a) => a.slug)).toEqual(['a', 'b', 'c'])
|
|
44
|
+
expect(sortArticles(articles, 'date-asc').map((a) => a.slug)).toEqual(['a', 'b', 'c'])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('articles without a date sort last, in both date orders', () => {
|
|
48
|
+
const articles = [
|
|
49
|
+
article({ slug: 'no-date' }),
|
|
50
|
+
article({ slug: 'newer', date: '2026-06-01' }),
|
|
51
|
+
article({ slug: 'older', date: '2026-01-01' }),
|
|
52
|
+
]
|
|
53
|
+
expect(sortArticles(articles, 'date-desc').map((a) => a.slug)).toEqual([
|
|
54
|
+
'newer',
|
|
55
|
+
'older',
|
|
56
|
+
'no-date',
|
|
57
|
+
])
|
|
58
|
+
expect(sortArticles(articles, 'date-asc').map((a) => a.slug)).toEqual([
|
|
59
|
+
'older',
|
|
60
|
+
'newer',
|
|
61
|
+
'no-date',
|
|
62
|
+
])
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('does not mutate the input array', () => {
|
|
66
|
+
const articles = [
|
|
67
|
+
article({ slug: 'b', date: '2026-06-01' }),
|
|
68
|
+
article({ slug: 'a', date: '2026-01-01' }),
|
|
69
|
+
]
|
|
70
|
+
const snapshot = [...articles]
|
|
71
|
+
sortArticles(articles, 'date-asc')
|
|
72
|
+
expect(articles).toEqual(snapshot)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('filterArticles', () => {
|
|
77
|
+
const articles = [
|
|
78
|
+
article({ slug: 'a', category: 'guide', tags: ['api', 'design'] }),
|
|
79
|
+
article({ slug: 'b', category: 'reference', tags: ['api'] }),
|
|
80
|
+
article({ slug: 'c', category: 'guide', tags: ['ux'] }),
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
test('category is an exact match', () => {
|
|
84
|
+
expect(filterArticles(articles, { category: 'guide' }).map((a) => a.slug)).toEqual(['a', 'c'])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('tags are ANY-OF (OR)', () => {
|
|
88
|
+
expect(filterArticles(articles, { tags: ['design', 'ux'] }).map((a) => a.slug)).toEqual([
|
|
89
|
+
'a',
|
|
90
|
+
'c',
|
|
91
|
+
])
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('category AND tags — AND between axes, OR within tags', () => {
|
|
95
|
+
expect(
|
|
96
|
+
filterArticles(articles, { category: 'guide', tags: ['ux'] }).map((a) => a.slug),
|
|
97
|
+
).toEqual(['c'])
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('an empty query returns the input unchanged', () => {
|
|
101
|
+
expect(filterArticles(articles, {})).toBe(articles)
|
|
102
|
+
expect(filterArticles(articles, { category: '', tags: [] })).toBe(articles)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('formatArticleDate', () => {
|
|
107
|
+
test('formats a known ISO date', () => {
|
|
108
|
+
expect(formatArticleDate('2026-07-16')).toBe('Jul 16, 2026')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('returns invalid input unchanged, never throws', () => {
|
|
112
|
+
expect(formatArticleDate('not-a-date')).toBe('not-a-date')
|
|
113
|
+
expect(formatArticleDate('')).toBe('')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('an explicit locale override changes the output', () => {
|
|
117
|
+
expect(formatArticleDate('2026-07-16', 'de-DE')).toBe('16. Juli 2026')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Article — the structured data model behind `ArticleCard`/`ArticleLayout` (docs/CONTENT-SPEC.md).
|
|
3
|
+
* Pure data + pure functions: no React, no `@mantine/*`. Sortable/filterable article metadata
|
|
4
|
+
* replaces the old preformatted `meta` string so a consumer can build a filter bar or a Spotlight
|
|
5
|
+
* projector on top of it (both are a later stage — this module only ships the model).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type Article<C extends string = string, T extends string = string> = {
|
|
9
|
+
readonly slug: string
|
|
10
|
+
readonly title: string
|
|
11
|
+
readonly description?: string
|
|
12
|
+
/** ISO 8601 — sortable. Articles without a date sort last regardless of `ArticleOrder`. */
|
|
13
|
+
readonly date?: string
|
|
14
|
+
readonly category?: C
|
|
15
|
+
readonly tags?: readonly T[]
|
|
16
|
+
/** Minutes. */
|
|
17
|
+
readonly readingTime?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ArticleOrder = 'date-desc' | 'date-asc' | 'title'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sorts articles. Pure — never mutates `articles`, always returns a new array.
|
|
24
|
+
*
|
|
25
|
+
* - `'date-desc'` (default) / `'date-asc'` — compares `date` lexicographically (ISO 8601 sorts
|
|
26
|
+
* chronologically as a string, so no `Date` parsing is needed). Articles missing a `date` sort
|
|
27
|
+
* LAST in both directions — a missing date is not "oldest", it's unranked.
|
|
28
|
+
* - `'title'` — `localeCompare` with a PINNED `'en-US'` locale, not the runtime default, so sort
|
|
29
|
+
* order doesn't drift between environments.
|
|
30
|
+
*
|
|
31
|
+
* Stable: articles that compare equal keep their input order (native `toSorted` is a stable sort).
|
|
32
|
+
*/
|
|
33
|
+
export function sortArticles<A extends Article>(
|
|
34
|
+
articles: readonly A[],
|
|
35
|
+
order: ArticleOrder = 'date-desc',
|
|
36
|
+
): readonly A[] {
|
|
37
|
+
if (order === 'title') {
|
|
38
|
+
return articles.toSorted((a, b) => a.title.localeCompare(b.title, 'en-US'))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const direction = order === 'date-asc' ? 1 : -1
|
|
42
|
+
return articles.toSorted((a, b) => {
|
|
43
|
+
if (a.date === undefined && b.date === undefined) return 0
|
|
44
|
+
if (a.date === undefined) return 1
|
|
45
|
+
if (b.date === undefined) return -1
|
|
46
|
+
if (a.date === b.date) return 0
|
|
47
|
+
return a.date < b.date ? -direction : direction
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type ArticleFilterQuery = {
|
|
52
|
+
readonly category?: string
|
|
53
|
+
readonly tags?: readonly string[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Filters articles. Pure — never mutates `articles`.
|
|
58
|
+
*
|
|
59
|
+
* - `category` — exact match. `undefined`/`''` applies no constraint.
|
|
60
|
+
* - `tags` — ANY-OF (OR): an article matches if it carries at least one queried tag.
|
|
61
|
+
* `undefined`/`[]` applies no constraint.
|
|
62
|
+
* - Both axes given: AND between category and tags, OR within tags — matches the multi-facet
|
|
63
|
+
* `filterFn` semantics in `data/data-table.tsx`.
|
|
64
|
+
*
|
|
65
|
+
* An empty query (`{}`, or a query where both axes are unset) returns `articles` unchanged.
|
|
66
|
+
*/
|
|
67
|
+
export function filterArticles<A extends Article>(
|
|
68
|
+
articles: readonly A[],
|
|
69
|
+
query: ArticleFilterQuery,
|
|
70
|
+
): readonly A[] {
|
|
71
|
+
const { category, tags } = query
|
|
72
|
+
const hasCategory = category !== undefined && category !== ''
|
|
73
|
+
const hasTags = tags !== undefined && tags.length > 0
|
|
74
|
+
|
|
75
|
+
if (!hasCategory && !hasTags) return articles
|
|
76
|
+
|
|
77
|
+
return articles.filter((article) => {
|
|
78
|
+
if (hasCategory && article.category !== category) return false
|
|
79
|
+
if (hasTags && tags !== undefined && !tags.some((tag) => article.tags?.includes(tag))) {
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
return true
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Formats an ISO 8601 date string via `Intl.DateTimeFormat` → `'Jul 16, 2026'`.
|
|
88
|
+
*
|
|
89
|
+
* Two things are PINNED, both load-bearing for SSR/client parity:
|
|
90
|
+
* - `locale` defaults to `'en-US'`, not the runtime default — the runtime default can differ
|
|
91
|
+
* between the server and the browser, which would render a different string on each side and
|
|
92
|
+
* trip a React hydration mismatch.
|
|
93
|
+
* - `timeZone` is pinned to `'UTC'` — a date-only ISO string (`'2026-07-16'`) parses as UTC
|
|
94
|
+
* midnight; formatting it in the server/browser's LOCAL zone can shift it a day either way
|
|
95
|
+
* depending on the runtime's offset, which is the same hydration-mismatch failure mode as an
|
|
96
|
+
* unpinned locale, just on the date instead of the string shape.
|
|
97
|
+
*
|
|
98
|
+
* Invalid/unparseable input is returned unchanged — never throws, never renders `'Invalid Date'`.
|
|
99
|
+
*/
|
|
100
|
+
export function formatArticleDate(iso: string, locale = 'en-US'): string {
|
|
101
|
+
const date = new Date(iso)
|
|
102
|
+
if (Number.isNaN(date.getTime())) return iso
|
|
103
|
+
|
|
104
|
+
return new Intl.DateTimeFormat(locale, {
|
|
105
|
+
year: 'numeric',
|
|
106
|
+
month: 'short',
|
|
107
|
+
day: 'numeric',
|
|
108
|
+
timeZone: 'UTC',
|
|
109
|
+
}).format(date)
|
|
110
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { blockSplit } from './block-split'
|
|
3
|
+
|
|
4
|
+
describe('blockSplit', () => {
|
|
5
|
+
test('returns an empty array for an empty string', () => {
|
|
6
|
+
expect(blockSplit('')).toEqual([])
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('join invariant holds for arbitrary input', () => {
|
|
10
|
+
const input = `# Title
|
|
11
|
+
|
|
12
|
+
Paragraph one.
|
|
13
|
+
|
|
14
|
+
- item one
|
|
15
|
+
- item two
|
|
16
|
+
|
|
17
|
+
\`\`\`ts
|
|
18
|
+
const x = 1
|
|
19
|
+
|
|
20
|
+
const y = 2
|
|
21
|
+
\`\`\`
|
|
22
|
+
|
|
23
|
+
Trailing paragraph.
|
|
24
|
+
`
|
|
25
|
+
expect(blockSplit(input).join('')).toBe(input)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('splits simple paragraphs on blank-line boundaries', () => {
|
|
29
|
+
const input = 'First paragraph.\n\nSecond paragraph.\n'
|
|
30
|
+
const blocks = blockSplit(input)
|
|
31
|
+
expect(blocks).toEqual(['First paragraph.\n\n', 'Second paragraph.\n'])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('keeps a fenced code block containing blank lines as one block', () => {
|
|
35
|
+
const input = '```ts\nconst x = 1\n\nconst y = 2\n```\n\nAfter.\n'
|
|
36
|
+
const blocks = blockSplit(input)
|
|
37
|
+
expect(blocks).toEqual(['```ts\nconst x = 1\n\nconst y = 2\n```\n\n', 'After.\n'])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('an unterminated fence at EOF stays one block', () => {
|
|
41
|
+
const input = 'Intro.\n\n```ts\nconst x = 1\n\nstill inside'
|
|
42
|
+
const blocks = blockSplit(input)
|
|
43
|
+
expect(blocks).toEqual(['Intro.\n\n', '```ts\nconst x = 1\n\nstill inside'])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('a tilde fence is not closed by a backtick run of the same length', () => {
|
|
47
|
+
const input = '~~~\ncode\n```\nstill inside\n~~~\n\nAfter.\n'
|
|
48
|
+
const blocks = blockSplit(input)
|
|
49
|
+
expect(blocks).toEqual(['~~~\ncode\n```\nstill inside\n~~~\n\n', 'After.\n'])
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('keeps blank-line-separated list items in one block', () => {
|
|
53
|
+
const input = '- item one\n\n- item two\n\n- item three\n\nNew paragraph.\n'
|
|
54
|
+
const blocks = blockSplit(input)
|
|
55
|
+
expect(blocks).toEqual(['- item one\n\n- item two\n\n- item three\n\n', 'New paragraph.\n'])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('keeps an indented continuation line attached to its list item', () => {
|
|
59
|
+
const input = '- item one\n\n continuation text\n\nNew paragraph.\n'
|
|
60
|
+
const blocks = blockSplit(input)
|
|
61
|
+
expect(blocks).toEqual(['- item one\n\n continuation text\n\n', 'New paragraph.\n'])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('keeps consecutive table lines together with no blank line to split on', () => {
|
|
65
|
+
const input = '| a | b |\n| - | - |\n| 1 | 2 |\n\nAfter.\n'
|
|
66
|
+
const blocks = blockSplit(input)
|
|
67
|
+
expect(blocks).toEqual(['| a | b |\n| - | - |\n| 1 | 2 |\n\n', 'After.\n'])
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('keeps consecutive blockquote lines together', () => {
|
|
71
|
+
const input = '> line one\n> line two\n\nAfter.\n'
|
|
72
|
+
const blocks = blockSplit(input)
|
|
73
|
+
expect(blocks).toEqual(['> line one\n> line two\n\n', 'After.\n'])
|
|
74
|
+
})
|
|
75
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blockSplit — a pure, fence-aware, blank-line block lexer (docs/CONTENT-SPEC.md §2/§6).
|
|
3
|
+
*
|
|
4
|
+
* Splits a markdown string into top-level blocks for streaming memoization: every block except
|
|
5
|
+
* the last is referentially stable across re-renders (`React.memo` skips them), so only the
|
|
6
|
+
* in-flight tail block re-renders per streamed token (see `./markdown.tsx`).
|
|
7
|
+
*
|
|
8
|
+
* Rules (deliberately pragmatic, not a full CommonMark tokenizer):
|
|
9
|
+
* - Split on blank-line boundaries.
|
|
10
|
+
* - Never split inside a fenced code block (``` or ~~~, any info string). A fence closes at a
|
|
11
|
+
* line starting with at least as many of the SAME fence character as opened it (CommonMark's
|
|
12
|
+
* closing-fence length rule, without validating the rest of the line).
|
|
13
|
+
* - List continuation: a blank line followed by an indented line (≥2 spaces) or a line starting
|
|
14
|
+
* a list item (`-`/`*`/`1.`) does NOT split — the blank line(s) stay attached to the block
|
|
15
|
+
* that is still accumulating, so a list with blank-line-separated items stays one block.
|
|
16
|
+
* - Every other consecutive non-blank line (tables, blockquotes, paragraphs) stays together
|
|
17
|
+
* automatically — there is no blank line to trigger a split.
|
|
18
|
+
*
|
|
19
|
+
* Blocks retain their raw text verbatim (including blank/trailing lines), so
|
|
20
|
+
* `blockSplit(input).join('') === input` always holds.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const FENCE_OPEN_RE = /^ {0,3}(`{3,}|~{3,})/
|
|
24
|
+
const LIST_CONTINUATION_RE = /^(?: {2,}|[-*]\s|\d+[.)]\s)/
|
|
25
|
+
|
|
26
|
+
type FenceOpen = { char: string; len: number }
|
|
27
|
+
|
|
28
|
+
function matchFenceOpen(line: string): FenceOpen | null {
|
|
29
|
+
const match = FENCE_OPEN_RE.exec(line)
|
|
30
|
+
if (!match?.[1]) return null
|
|
31
|
+
const marker = match[1]
|
|
32
|
+
return { char: marker[0] as string, len: marker.length }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closesFence(line: string, fence: FenceOpen): boolean {
|
|
36
|
+
const trimmed = line.replace(/^ {0,3}/, '')
|
|
37
|
+
const runRe = fence.char === '`' ? /^`+/ : /^~+/
|
|
38
|
+
const run = runRe.exec(trimmed)?.[0]
|
|
39
|
+
return run !== undefined && run.length >= fence.len
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isBlank(line: string): boolean {
|
|
43
|
+
return line.trim() === ''
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Splits `markdown` into top-level blocks. See module doc for the rules. */
|
|
47
|
+
export function blockSplit(markdown: string): string[] {
|
|
48
|
+
if (markdown === '') return []
|
|
49
|
+
|
|
50
|
+
// Split AFTER every newline so each entry keeps its own line terminator — reconstructing via
|
|
51
|
+
// `.join('')` is then lossless by construction, which is what the join-invariant test asserts.
|
|
52
|
+
const lines = markdown.split(/(?<=\n)/)
|
|
53
|
+
const blocks: string[] = []
|
|
54
|
+
let current: string[] = []
|
|
55
|
+
let fence: FenceOpen | null = null
|
|
56
|
+
|
|
57
|
+
let i = 0
|
|
58
|
+
while (i < lines.length) {
|
|
59
|
+
const line = lines[i] as string
|
|
60
|
+
|
|
61
|
+
if (fence !== null) {
|
|
62
|
+
current.push(line)
|
|
63
|
+
if (closesFence(line, fence)) fence = null
|
|
64
|
+
i++
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const fenceOpen = matchFenceOpen(line)
|
|
69
|
+
if (fenceOpen) {
|
|
70
|
+
current.push(line)
|
|
71
|
+
fence = fenceOpen
|
|
72
|
+
i++
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isBlank(line)) {
|
|
77
|
+
let j = i
|
|
78
|
+
while (j < lines.length && isBlank(lines[j] as string)) j++
|
|
79
|
+
const blankLines = lines.slice(i, j)
|
|
80
|
+
const nextLine = j < lines.length ? (lines[j] as string) : undefined
|
|
81
|
+
|
|
82
|
+
current.push(...blankLines)
|
|
83
|
+
if (nextLine !== undefined && LIST_CONTINUATION_RE.test(nextLine)) {
|
|
84
|
+
// Continuation — keep accumulating into the same block.
|
|
85
|
+
i = j
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Boundary — trailing blank line(s) close out the block that was accumulating.
|
|
90
|
+
blocks.push(current.join(''))
|
|
91
|
+
current = []
|
|
92
|
+
i = j
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
current.push(line)
|
|
97
|
+
i++
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (current.length > 0) blocks.push(current.join(''))
|
|
101
|
+
return blocks
|
|
102
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GFM alert detection (`> [!NOTE]` etc.) shared by `./markdown` and `./mdx` (docs/CONTENT-SPEC.md
|
|
3
|
+
* §3). Operates on RENDERED React children rather than the hast tree — react-markdown's
|
|
4
|
+
* blockquote override and MDX's compiled `<blockquote><p>…</p></blockquote>` output share the
|
|
5
|
+
* same shape, so one implementation covers both without needing a hast node (which MDX never
|
|
6
|
+
* provides to its component overrides).
|
|
7
|
+
*
|
|
8
|
+
* Not part of the public surface — the `blockquote` renderers in `./markdown`/`./mdx` are the only
|
|
9
|
+
* consumers.
|
|
10
|
+
*/
|
|
11
|
+
import type { ReactNode } from 'react'
|
|
12
|
+
import { cloneElement, isValidElement } from 'react'
|
|
13
|
+
import type { CalloutKind } from './callout'
|
|
14
|
+
|
|
15
|
+
export type AlertKind = 'NOTE' | 'TIP' | 'IMPORTANT' | 'WARNING' | 'CAUTION'
|
|
16
|
+
|
|
17
|
+
const ALERT_MARKER_RE = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/
|
|
18
|
+
|
|
19
|
+
/** GitHub's alert→severity mapping (NOTE/IMPORTANT read as informational, TIP as positive). */
|
|
20
|
+
export const ALERT_CALLOUT_KIND: Record<AlertKind, CalloutKind> = {
|
|
21
|
+
NOTE: 'info',
|
|
22
|
+
IMPORTANT: 'info',
|
|
23
|
+
TIP: 'good',
|
|
24
|
+
WARNING: 'warn',
|
|
25
|
+
CAUTION: 'bad',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const ALERT_TITLE: Record<AlertKind, string> = {
|
|
29
|
+
NOTE: 'Note',
|
|
30
|
+
TIP: 'Tip',
|
|
31
|
+
IMPORTANT: 'Important',
|
|
32
|
+
WARNING: 'Warning',
|
|
33
|
+
CAUTION: 'Caution',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type AlertMatch = {
|
|
37
|
+
readonly kind: AlertKind
|
|
38
|
+
/** The exact matched marker text (including trailing whitespace) — pass to `stripAlertMarker`. */
|
|
39
|
+
readonly marker: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Inter-element whitespace (react-markdown emits `['\n', <p>…</p>, '\n']` blockquote children)
|
|
43
|
+
* — never the marker carrier, so traversal skips it. */
|
|
44
|
+
function isSkippable(node: ReactNode): boolean {
|
|
45
|
+
return node === null || node === undefined || (typeof node === 'string' && node.trim() === '')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Follows the first SUBSTANTIVE child at every level — mirrors "the first paragraph's first text
|
|
49
|
+
* child" from docs/CONTENT-SPEC.md §3, and keeps this symmetric with `stripAlertMarker` below. */
|
|
50
|
+
function firstText(node: ReactNode): string | undefined {
|
|
51
|
+
if (typeof node === 'string') return node
|
|
52
|
+
if (Array.isArray(node)) {
|
|
53
|
+
const first = node.find((child) => !isSkippable(child))
|
|
54
|
+
return first === undefined ? undefined : firstText(first as ReactNode)
|
|
55
|
+
}
|
|
56
|
+
if (isValidElement(node)) return firstText((node.props as { children?: ReactNode }).children)
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Detects a GFM alert marker as the blockquote's first paragraph's first text child. */
|
|
61
|
+
export function detectAlert(children: ReactNode): AlertMatch | undefined {
|
|
62
|
+
const text = firstText(children)
|
|
63
|
+
if (text === undefined) return undefined
|
|
64
|
+
const match = ALERT_MARKER_RE.exec(text)
|
|
65
|
+
const kind = match?.[1]
|
|
66
|
+
if (!kind) return undefined
|
|
67
|
+
return { kind: kind as AlertKind, marker: match[0] }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Strips `marker` off the very first text child found via the same first-child traversal
|
|
71
|
+
* `detectAlert` used to find it — the marker is guaranteed to be its leading substring. */
|
|
72
|
+
export function stripAlertMarker(node: ReactNode, marker: string): ReactNode {
|
|
73
|
+
if (typeof node === 'string') {
|
|
74
|
+
return node.startsWith(marker) ? node.slice(marker.length) : node
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(node)) {
|
|
77
|
+
const index = node.findIndex((child) => !isSkippable(child as ReactNode))
|
|
78
|
+
if (index === -1) return node
|
|
79
|
+
const copy = [...node]
|
|
80
|
+
copy[index] = stripAlertMarker(copy[index] as ReactNode, marker)
|
|
81
|
+
return copy
|
|
82
|
+
}
|
|
83
|
+
if (isValidElement(node)) {
|
|
84
|
+
const props = node.props as { children?: ReactNode }
|
|
85
|
+
return cloneElement(node, undefined, stripAlertMarker(props.children, marker))
|
|
86
|
+
}
|
|
87
|
+
return node
|
|
88
|
+
}
|