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,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `basalt init` / `basalt sync` scaffold behavior:
|
|
3
|
+
* - the `.oxfmtrc.json` scaffold filename (oxfmt auto-discovers this name, not `oxfmt.json`)
|
|
4
|
+
* - the legacy `oxfmt.json` → `.oxfmtrc.json` manifest/file migration
|
|
5
|
+
* - the `basalt doctor` CLI-vs-installed version-mismatch warning
|
|
6
|
+
* - the `basalt init` first-run hint to run `check-theme` and tune per-rule config
|
|
7
|
+
*/
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
|
|
9
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { join, resolve } from 'node:path'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
|
|
14
|
+
import { doctor, init, MANIFEST_PATH, sync } from './index.ts'
|
|
15
|
+
|
|
16
|
+
const PKG_ROOT = fileURLToPath(new URL('../../', import.meta.url))
|
|
17
|
+
const SHIPPED_OXFMT = readFileSync(resolve(PKG_ROOT, 'configs/oxfmt.json'), 'utf8')
|
|
18
|
+
|
|
19
|
+
let dir: string
|
|
20
|
+
|
|
21
|
+
function writeFixture(relPath: string, content: string): void {
|
|
22
|
+
const abs = join(dir, relPath)
|
|
23
|
+
mkdirSync(resolve(abs, '..'), { recursive: true })
|
|
24
|
+
writeFileSync(abs, content, 'utf8')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Captures both console.log and console.error — doctor()/init() pick one or the other by outcome. */
|
|
28
|
+
function capture(fn: () => number): { code: number; log: string } {
|
|
29
|
+
const originalLog = console.log
|
|
30
|
+
const originalError = console.error
|
|
31
|
+
let log = ''
|
|
32
|
+
console.log = (...args: unknown[]) => {
|
|
33
|
+
log += `${args.join(' ')}\n`
|
|
34
|
+
}
|
|
35
|
+
console.error = (...args: unknown[]) => {
|
|
36
|
+
log += `${args.join(' ')}\n`
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return { code: fn(), log }
|
|
40
|
+
} finally {
|
|
41
|
+
console.log = originalLog
|
|
42
|
+
console.error = originalError
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
dir = mkdtempSync(resolve(tmpdir(), 'basalt-init-sync-'))
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
rmSync(dir, { recursive: true, force: true })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('oxfmt scaffold filename', () => {
|
|
55
|
+
it('init writes .oxfmtrc.json, not oxfmt.json', () => {
|
|
56
|
+
writeFixture('package.json', JSON.stringify({ name: 'fixture' }))
|
|
57
|
+
init(dir)
|
|
58
|
+
expect(existsSync(resolve(dir, '.oxfmtrc.json'))).toBe(true)
|
|
59
|
+
expect(existsSync(resolve(dir, 'oxfmt.json'))).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('sync migrates an untouched legacy oxfmt.json: deletes the stale file, drops the manifest key, writes .oxfmtrc.json', () => {
|
|
63
|
+
writeFixture('package.json', JSON.stringify({ name: 'fixture' }))
|
|
64
|
+
writeFixture('oxfmt.json', SHIPPED_OXFMT)
|
|
65
|
+
writeFixture(
|
|
66
|
+
MANIFEST_PATH,
|
|
67
|
+
JSON.stringify({ version: 1, files: { 'oxfmt.json': 'irrelevant-legacy-hash' } }, null, 2),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
sync({}, dir)
|
|
71
|
+
|
|
72
|
+
expect(existsSync(resolve(dir, 'oxfmt.json'))).toBe(false)
|
|
73
|
+
expect(existsSync(resolve(dir, '.oxfmtrc.json'))).toBe(true)
|
|
74
|
+
expect(readFileSync(resolve(dir, '.oxfmtrc.json'), 'utf8')).toBe(SHIPPED_OXFMT)
|
|
75
|
+
|
|
76
|
+
const manifest = JSON.parse(readFileSync(resolve(dir, MANIFEST_PATH), 'utf8')) as {
|
|
77
|
+
files: Record<string, string>
|
|
78
|
+
}
|
|
79
|
+
expect(manifest.files['oxfmt.json']).toBeUndefined()
|
|
80
|
+
expect(manifest.files['.oxfmtrc.json']).toBeDefined()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('sync preserves a locally-edited legacy oxfmt.json but still drops the manifest key and scaffolds .oxfmtrc.json', () => {
|
|
84
|
+
writeFixture('package.json', JSON.stringify({ name: 'fixture' }))
|
|
85
|
+
writeFixture('oxfmt.json', '{\n "printWidth": 120\n}\n')
|
|
86
|
+
writeFixture(
|
|
87
|
+
MANIFEST_PATH,
|
|
88
|
+
JSON.stringify({ version: 1, files: { 'oxfmt.json': 'irrelevant-legacy-hash' } }, null, 2),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
sync({}, dir)
|
|
92
|
+
|
|
93
|
+
// Locally-edited file is left in place — never silently discarded.
|
|
94
|
+
expect(existsSync(resolve(dir, 'oxfmt.json'))).toBe(true)
|
|
95
|
+
expect(readFileSync(resolve(dir, 'oxfmt.json'), 'utf8')).toBe('{\n "printWidth": 120\n}\n')
|
|
96
|
+
// The new scaffold is created independently, so no dead duplicate keeps being managed forever.
|
|
97
|
+
expect(existsSync(resolve(dir, '.oxfmtrc.json'))).toBe(true)
|
|
98
|
+
|
|
99
|
+
const manifest = JSON.parse(readFileSync(resolve(dir, MANIFEST_PATH), 'utf8')) as {
|
|
100
|
+
files: Record<string, string>
|
|
101
|
+
}
|
|
102
|
+
expect(manifest.files['oxfmt.json']).toBeUndefined()
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('sync is a no-op for the legacy dest when there is no manifest entry (fresh consumer)', () => {
|
|
106
|
+
writeFixture('package.json', JSON.stringify({ name: 'fixture' }))
|
|
107
|
+
writeFixture(MANIFEST_PATH, JSON.stringify({ version: 1, files: {} }, null, 2))
|
|
108
|
+
|
|
109
|
+
sync({}, dir)
|
|
110
|
+
|
|
111
|
+
expect(existsSync(resolve(dir, 'oxfmt.json'))).toBe(false)
|
|
112
|
+
expect(existsSync(resolve(dir, '.oxfmtrc.json'))).toBe(true)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('doctor — CLI vs installed basalt-ui version', () => {
|
|
117
|
+
const cliVersion = (
|
|
118
|
+
JSON.parse(readFileSync(resolve(PKG_ROOT, 'package.json'), 'utf8')) as { version: string }
|
|
119
|
+
).version
|
|
120
|
+
|
|
121
|
+
it('warns when node_modules/basalt-ui version differs from the running CLI', () => {
|
|
122
|
+
writeFixture(
|
|
123
|
+
'node_modules/basalt-ui/package.json',
|
|
124
|
+
JSON.stringify({ name: 'basalt-ui', version: '0.4.2' }),
|
|
125
|
+
)
|
|
126
|
+
const { code, log } = capture(() => doctor(dir))
|
|
127
|
+
// Only a warning — doctor's exit code is driven by hard failures (manifest missing here too,
|
|
128
|
+
// so exit is 1 regardless; assert on the message rather than the code).
|
|
129
|
+
expect(code).toBe(1)
|
|
130
|
+
expect(log).toContain(cliVersion)
|
|
131
|
+
expect(log).toContain('0.4.2')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('passes when node_modules/basalt-ui version matches the running CLI', () => {
|
|
135
|
+
writeFixture(MANIFEST_PATH, JSON.stringify({ version: 1, files: {} }, null, 2))
|
|
136
|
+
writeFixture(
|
|
137
|
+
'node_modules/basalt-ui/package.json',
|
|
138
|
+
JSON.stringify({ name: 'basalt-ui', version: cliVersion }),
|
|
139
|
+
)
|
|
140
|
+
const { code, log } = capture(() => doctor(dir))
|
|
141
|
+
expect(code).toBe(0)
|
|
142
|
+
expect(log).toContain('matches the installed basalt-ui')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('is silent (no node_modules/basalt-ui present) when the package cannot be resolved', () => {
|
|
146
|
+
writeFixture(MANIFEST_PATH, JSON.stringify({ version: 1, files: {} }, null, 2))
|
|
147
|
+
const { log } = capture(() => doctor(dir))
|
|
148
|
+
expect(log).not.toContain('differs from the installed basalt-ui')
|
|
149
|
+
expect(log).not.toContain('matches the installed basalt-ui')
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe('init — first-run hint', () => {
|
|
154
|
+
it('prints a hint to run check-theme and tune per-rule config', () => {
|
|
155
|
+
writeFixture('package.json', JSON.stringify({ name: 'fixture' }))
|
|
156
|
+
const { log } = capture(() => init(dir))
|
|
157
|
+
expect(log).toContain('check-theme')
|
|
158
|
+
expect(log.toLowerCase()).toContain('basalt.*')
|
|
159
|
+
})
|
|
160
|
+
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShortcutsHelp — renders a keyboard shortcut reference list grouped by command group.
|
|
3
|
+
*
|
|
4
|
+
* Reads from the active command registry at render time via `toShortcutList()`. The same
|
|
5
|
+
* Command.shortcut field also drives live key binding via useCommandHotkeys().
|
|
6
|
+
*
|
|
7
|
+
* Platform-aware label: 'Mod' → '⌘' on mac, 'Ctrl' elsewhere.
|
|
8
|
+
* Platform detection defers to post-mount (useEffect) to avoid SSR/client hydration mismatch.
|
|
9
|
+
* Server and first client render both use non-mac glyphs; the client updates after mount.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { ShortcutsHelp } from 'basalt-ui/commands'
|
|
13
|
+
*
|
|
14
|
+
* // In a help modal or settings panel:
|
|
15
|
+
* <ShortcutsHelp />
|
|
16
|
+
*
|
|
17
|
+
* // With a custom title and max width:
|
|
18
|
+
* <ShortcutsHelp title="Keyboard shortcuts" maw={480} />
|
|
19
|
+
*/
|
|
20
|
+
import { useEffect, useState } from 'react'
|
|
21
|
+
import { Box, Group, Kbd, Stack, Text, Title } from '@mantine/core'
|
|
22
|
+
import { toShortcutList } from './projectors'
|
|
23
|
+
import { detectMac, parseShortcut } from './shortcut-format'
|
|
24
|
+
import { VX } from '../tokens'
|
|
25
|
+
|
|
26
|
+
// ── ShortcutsHelpProps ────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
export type ShortcutsHelpProps = {
|
|
29
|
+
/** Section title. Default: 'Keyboard shortcuts'. */
|
|
30
|
+
title?: string
|
|
31
|
+
/** Max-width passthrough (Mantine style prop). */
|
|
32
|
+
maw?: number | string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── ShortcutRow ───────────────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
function ShortcutRow({
|
|
38
|
+
label,
|
|
39
|
+
shortcut,
|
|
40
|
+
isMac,
|
|
41
|
+
}: {
|
|
42
|
+
label: string
|
|
43
|
+
shortcut: string
|
|
44
|
+
isMac: boolean
|
|
45
|
+
}) {
|
|
46
|
+
const keys = parseShortcut(shortcut, isMac)
|
|
47
|
+
return (
|
|
48
|
+
<Group justify="space-between" gap="xs" py={2}>
|
|
49
|
+
<Text size="sm">{label}</Text>
|
|
50
|
+
<Group gap={4}>
|
|
51
|
+
{keys.map((key, i) => (
|
|
52
|
+
<Kbd key={i} size="xs">
|
|
53
|
+
{key}
|
|
54
|
+
</Kbd>
|
|
55
|
+
))}
|
|
56
|
+
</Group>
|
|
57
|
+
</Group>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── ShortcutsHelp ─────────────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Renders all registered commands that have a `shortcut` field, grouped by `group`.
|
|
65
|
+
* Commands with no `group` are rendered under an implicit ungrouped section.
|
|
66
|
+
*
|
|
67
|
+
* Returns `null` when no commands have shortcuts registered.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* <ShortcutsHelp title="Keyboard shortcuts" />
|
|
71
|
+
*/
|
|
72
|
+
export function ShortcutsHelp({ title = 'Keyboard shortcuts', maw }: ShortcutsHelpProps) {
|
|
73
|
+
// Default false — SSR and first client render produce non-mac glyphs (no hydration mismatch).
|
|
74
|
+
// Post-mount effect flips to true on macOS, triggering a single client-only re-render.
|
|
75
|
+
const [isMac, setIsMac] = useState(false)
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
setIsMac(detectMac())
|
|
78
|
+
}, [])
|
|
79
|
+
|
|
80
|
+
const shortcuts = toShortcutList()
|
|
81
|
+
|
|
82
|
+
if (shortcuts.length === 0) return null
|
|
83
|
+
|
|
84
|
+
// Group shortcuts by group name; ungrouped go under the empty-string key
|
|
85
|
+
const grouped = new Map<string, typeof shortcuts>()
|
|
86
|
+
for (const entry of shortcuts) {
|
|
87
|
+
const key = entry.group ?? ''
|
|
88
|
+
const bucket = grouped.get(key)
|
|
89
|
+
if (bucket !== undefined) {
|
|
90
|
+
bucket.push(entry)
|
|
91
|
+
} else {
|
|
92
|
+
grouped.set(key, [entry])
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Box maw={maw}>
|
|
98
|
+
<Title order={5} mb="sm">
|
|
99
|
+
{title}
|
|
100
|
+
</Title>
|
|
101
|
+
<Stack gap="md">
|
|
102
|
+
{[...grouped.entries()].map(([group, entries]) => (
|
|
103
|
+
<Stack key={group} gap={2}>
|
|
104
|
+
{group !== '' && (
|
|
105
|
+
<Text
|
|
106
|
+
ff="monospace"
|
|
107
|
+
tt="uppercase"
|
|
108
|
+
fw={500}
|
|
109
|
+
c="var(--vx-faint)"
|
|
110
|
+
mb={4}
|
|
111
|
+
style={{ fontSize: VX.text.micro, letterSpacing: '0.06em' }}
|
|
112
|
+
>
|
|
113
|
+
{group}
|
|
114
|
+
</Text>
|
|
115
|
+
)}
|
|
116
|
+
{entries.map((entry) => (
|
|
117
|
+
<ShortcutRow
|
|
118
|
+
key={entry.id}
|
|
119
|
+
label={entry.label}
|
|
120
|
+
shortcut={entry.shortcut}
|
|
121
|
+
isMac={isMac}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
</Stack>
|
|
125
|
+
))}
|
|
126
|
+
</Stack>
|
|
127
|
+
</Box>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* define-commands — const-generic factory for typed command registries.
|
|
3
|
+
*
|
|
4
|
+
* Consumer defines their commands with defineCommands, augments BasaltRegister.commands, then uses
|
|
5
|
+
* runCommand — unknown ids are tsc errors. The type slot gives the compile-time id union; the
|
|
6
|
+
* module-level stash gives the runtime values (type augmentation is erased at runtime).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // commands.ts (app-side)
|
|
10
|
+
* import { defineCommands } from 'basalt-ui/commands'
|
|
11
|
+
* export const COMMANDS = defineCommands({
|
|
12
|
+
* 'file:save': { label: 'Save file', group: 'File', shortcut: 'Mod+S', run: () => save() },
|
|
13
|
+
* 'file:open': { label: 'Open file', group: 'File', shortcut: 'Mod+O', run: () => open() },
|
|
14
|
+
* 'help:docs': { label: 'Open docs', group: 'Help', run: () => window.open('/docs') },
|
|
15
|
+
* })
|
|
16
|
+
* declare module 'basalt-ui' {
|
|
17
|
+
* interface BasaltRegister { commands: typeof COMMANDS }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // usage.ts
|
|
21
|
+
* import { runCommand } from 'basalt-ui/commands'
|
|
22
|
+
* runCommand('file:save') // ✓ typed
|
|
23
|
+
* runCommand('nonexistent') // ✗ tsc error
|
|
24
|
+
*/
|
|
25
|
+
import type { ReactNode } from 'react'
|
|
26
|
+
import type { Slot } from '../register'
|
|
27
|
+
|
|
28
|
+
// ── Context ───────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Context passed to a command's run function. Minimal for 1.0; extend via BasaltRegister in 1.x.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* defineCommands({
|
|
35
|
+
* 'palette:close': { label: 'Close palette', run: ({ close }) => close?.() },
|
|
36
|
+
* })
|
|
37
|
+
*/
|
|
38
|
+
export type CommandRunContext = {
|
|
39
|
+
/** Close the command palette (if open) before executing. Injected by BasaltOverlays. */
|
|
40
|
+
close?: () => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ── Command + CommandMap ──────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A single registered command. All fields except `label` and `run` are optional.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const cmd: Command = {
|
|
50
|
+
* label: 'Save file',
|
|
51
|
+
* group: 'File',
|
|
52
|
+
* shortcut: 'Mod+S',
|
|
53
|
+
* when: () => document.hasFocus(),
|
|
54
|
+
* run: () => save(),
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
export type Command = {
|
|
58
|
+
/** Display label shown in the command palette and shortcuts-help. */
|
|
59
|
+
label: string
|
|
60
|
+
/** Optional group name for grouping in the palette and shortcuts display. */
|
|
61
|
+
group?: string
|
|
62
|
+
/** Optional icon (ReactNode — no @tabler/icons dependency per house rules). */
|
|
63
|
+
icon?: ReactNode
|
|
64
|
+
/**
|
|
65
|
+
* Optional keyboard shortcut string. Drives BOTH the ShortcutsHelp display AND live key
|
|
66
|
+
* binding via useCommandHotkeys() (which registers with @tanstack/react-hotkeys optional peer).
|
|
67
|
+
* Convention: 'Mod+S' (Mod = Cmd on mac, Ctrl elsewhere), 'Shift+Mod+P', etc.
|
|
68
|
+
*/
|
|
69
|
+
shortcut?: string
|
|
70
|
+
/**
|
|
71
|
+
* Optional predicate — when() returning false hides the command from the palette.
|
|
72
|
+
* Useful for context-sensitive commands (e.g. "save" only when a form is dirty).
|
|
73
|
+
*/
|
|
74
|
+
when?: () => boolean
|
|
75
|
+
/** The command handler. May be async. */
|
|
76
|
+
run: (ctx?: CommandRunContext) => void | Promise<void>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The map of command id → Command that a consumer registers.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const map: CommandMap = {
|
|
84
|
+
* 'file:save': { label: 'Save', run: () => save() },
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
export type CommandMap = Record<string, Command>
|
|
88
|
+
|
|
89
|
+
// ── Slot extraction (mirror of SeriesKey pattern in register.ts) ──────────────
|
|
90
|
+
|
|
91
|
+
/** The consumer's registered command map, or `{}` when un-augmented. */
|
|
92
|
+
type Commands = Slot<'commands', CommandMap>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The legal command id keys.
|
|
96
|
+
* Extract<…, string> drops symbol/number members that `keyof` always includes.
|
|
97
|
+
* Un-augmented: `never` (slot is `{}`, keyof is never).
|
|
98
|
+
* Augmented: the exact string literal union of the registered command ids.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* // After augmenting BasaltRegister.commands:
|
|
102
|
+
* const id: CommandId = 'file:save' // ✓
|
|
103
|
+
* const bad: CommandId = 'bad-id' // ✗ tsc error
|
|
104
|
+
*/
|
|
105
|
+
export type CommandId = Extract<keyof Commands, string>
|
|
106
|
+
|
|
107
|
+
// ── Runtime stash ─────────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Module-level runtime registry. The BasaltRegister type-slot gives the compile-time id union,
|
|
111
|
+
* but the augmentation is erased at runtime — so defineCommands also stashes the runtime map here
|
|
112
|
+
* for runCommand and the projectors to resolve Command objects. Call defineCommands once (the
|
|
113
|
+
* app's single command registry); the last call wins.
|
|
114
|
+
*/
|
|
115
|
+
let activeCommands: CommandMap = {}
|
|
116
|
+
|
|
117
|
+
// ── defineCommands ────────────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Define a typed command map. Const-generic identity passthrough — preserves the exact literal
|
|
121
|
+
* keys so `runCommand('nonexistent')` is a tsc error after augmenting BasaltRegister.
|
|
122
|
+
*
|
|
123
|
+
* Stashes the runtime map so `runCommand` and `toSpotlightActions` resolve correctly at runtime
|
|
124
|
+
* (type augmentation is erased; the stash is the live source).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* export const COMMANDS = defineCommands({
|
|
128
|
+
* 'file:save': { label: 'Save file', group: 'File', shortcut: 'Mod+S', run: () => save() },
|
|
129
|
+
* })
|
|
130
|
+
* declare module 'basalt-ui' {
|
|
131
|
+
* interface BasaltRegister { commands: typeof COMMANDS }
|
|
132
|
+
* }
|
|
133
|
+
*/
|
|
134
|
+
export function defineCommands<const T extends CommandMap>(spec: T): T {
|
|
135
|
+
activeCommands = spec
|
|
136
|
+
return spec
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ── defineCommand (single-command helper) ─────────────────────────────────────
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Convenience helper to type a single Command object with full inference.
|
|
143
|
+
* Useful when splitting commands across files before merging into defineCommands.
|
|
144
|
+
*
|
|
145
|
+
* WARNING: defineCommand only TYPES a command — it does NOT register it into the runtime stash.
|
|
146
|
+
* Only defineCommands(map) registers commands. Calling defineCommand alone means the command will
|
|
147
|
+
* never appear in the palette or be reachable via runCommand.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const saveCmd = defineCommand({ label: 'Save', shortcut: 'Mod+S', run: () => save() })
|
|
151
|
+
* // Then include saveCmd in a defineCommands({ 'file:save': saveCmd }) call to register it.
|
|
152
|
+
*/
|
|
153
|
+
export function defineCommand(cmd: Command): Command {
|
|
154
|
+
return cmd
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── runCommand ────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Run a registered command by id. The id must be a key of the consumer's registered
|
|
161
|
+
* `BasaltRegister.commands` map — any other string is a tsc error.
|
|
162
|
+
*
|
|
163
|
+
* Resolves the command's run function from the runtime stash (NOT from the type slot — that is
|
|
164
|
+
* erased). Un-augmented (Commands = {}): CommandId = never → `runCommand` is effectively
|
|
165
|
+
* uncallable. Augmented: only the registered keys are accepted.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* runCommand('file:save')
|
|
169
|
+
* await runCommand('data:sync', { close: () => closeModal() })
|
|
170
|
+
*/
|
|
171
|
+
export function runCommand(id: CommandId, ctx?: CommandRunContext): void | Promise<void> {
|
|
172
|
+
const cmd = activeCommands[id as string]
|
|
173
|
+
if (cmd === undefined) {
|
|
174
|
+
if (process.env['NODE_ENV'] !== 'production')
|
|
175
|
+
console.warn(`[basalt] runCommand: no command registered for "${id}"`)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
return cmd.run(ctx)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @internal — exposed for projectors.ts to iterate the runtime stash. Returns a readonly view. */
|
|
182
|
+
export function getActiveCommands(): Readonly<CommandMap> {
|
|
183
|
+
return activeCommands
|
|
184
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* define-overlays — const-generic factory for typed overlay registries.
|
|
3
|
+
*
|
|
4
|
+
* Consumer defines overlays with defineOverlays, augments BasaltRegister.overlays, then uses the
|
|
5
|
+
* `overlays` imperative controller — unknown keys are tsc errors. The type slot gives the
|
|
6
|
+
* compile-time key union; the module-level stash gives the runtime values.
|
|
7
|
+
*
|
|
8
|
+
* Uses @mantine/modals under the hood. ModalsProvider must be mounted (BasaltOverlays does this).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // overlays.ts (app-side)
|
|
12
|
+
* import { defineOverlays } from 'basalt-ui/commands'
|
|
13
|
+
* export const OVERLAYS = defineOverlays({
|
|
14
|
+
* 'confirm:delete': {
|
|
15
|
+
* title: 'Delete item?',
|
|
16
|
+
* render: (p: { name: string }) => <Text>Delete "{p.name}"?</Text>,
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
* declare module 'basalt-ui' {
|
|
20
|
+
* interface BasaltRegister { overlays: typeof OVERLAYS }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // usage.ts
|
|
24
|
+
* import { overlays } from 'basalt-ui/commands'
|
|
25
|
+
* overlays.open('confirm:delete', { name: 'photo.jpg' }) // ✓ typed
|
|
26
|
+
* overlays.open('nonexistent', {}) // ✗ tsc error
|
|
27
|
+
*/
|
|
28
|
+
import type { ReactNode } from 'react'
|
|
29
|
+
import type { Slot } from '../register'
|
|
30
|
+
|
|
31
|
+
// ── Lazy @mantine/modals resolution ───────────────────────────────────────────
|
|
32
|
+
// @mantine/modals is an OPTIONAL peer — never imported at module evaluation time, so importing
|
|
33
|
+
// this module (and the ./commands barrel that re-exports it) does not require the peer. Resolves
|
|
34
|
+
// to undefined when the peer is absent — overlays.open/close then degrade to a no-op.
|
|
35
|
+
|
|
36
|
+
type ModalsModule = typeof import('@mantine/modals')
|
|
37
|
+
type ModalsSingleton = ModalsModule['modals']
|
|
38
|
+
|
|
39
|
+
let modalsPromise: Promise<ModalsSingleton | undefined> | undefined
|
|
40
|
+
|
|
41
|
+
function loadModals(): Promise<ModalsSingleton | undefined> {
|
|
42
|
+
modalsPromise ??= import('@mantine/modals').then((m) => m.modals).catch(() => undefined)
|
|
43
|
+
return modalsPromise
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── Overlay + OverlayMap ──────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A single registered overlay. The per-overlay props type P is the consumer's own payload.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const overlay: Overlay<{ name: string }> = {
|
|
53
|
+
* title: 'Delete item?',
|
|
54
|
+
* render: ({ name }) => <Text>Delete "{name}"?</Text>,
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
// Default is Record<string, unknown> so a bare Overlay (no type arg) doesn't silently become any
|
|
58
|
+
export type Overlay<P = Record<string, unknown>> = {
|
|
59
|
+
/** Optional modal title (ReactNode for rich headers). */
|
|
60
|
+
title?: ReactNode
|
|
61
|
+
/** Render the modal body for a given payload. */
|
|
62
|
+
render: (props: P) => ReactNode
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The map of overlay key → Overlay that a consumer registers.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const map: OverlayMap = {
|
|
70
|
+
* 'confirm:delete': { title: 'Confirm', render: (p: { name: string }) => <span>{p.name}</span> },
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- load-bearing contravariant overlay map
|
|
74
|
+
export type OverlayMap = Record<string, Overlay<any>>
|
|
75
|
+
|
|
76
|
+
// ── Slot extraction ───────────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
/** The consumer's registered overlay map, or `{}` when un-augmented. */
|
|
79
|
+
type Overlays = Slot<'overlays', OverlayMap>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The legal overlay keys.
|
|
83
|
+
* Extract<…, string> drops symbol/number members that `keyof` always includes.
|
|
84
|
+
* Un-augmented: `never`. Augmented: the exact string literal union.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const key: OverlayKey = 'confirm:delete' // ✓ after augmenting
|
|
88
|
+
* const bad: OverlayKey = 'no-such-key' // ✗ tsc error
|
|
89
|
+
*/
|
|
90
|
+
export type OverlayKey = Extract<keyof Overlays, string>
|
|
91
|
+
|
|
92
|
+
// ── Runtime stash ─────────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Module-level runtime registry. Type augmentation is erased at runtime — the stash is the
|
|
96
|
+
* live source for overlays.open to resolve the Overlay spec. Call defineOverlays once; the
|
|
97
|
+
* last call wins.
|
|
98
|
+
*/
|
|
99
|
+
let activeOverlays: OverlayMap = {}
|
|
100
|
+
|
|
101
|
+
// ── defineOverlays ────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Define a typed overlay map. Const-generic identity passthrough — preserves the exact literal
|
|
105
|
+
* keys so `overlays.open('nonexistent', …)` is a tsc error after augmenting BasaltRegister.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* export const OVERLAYS = defineOverlays({
|
|
109
|
+
* 'user:edit': { title: 'Edit user', render: (p: { id: string }) => <UserEditForm id={p.id} /> },
|
|
110
|
+
* })
|
|
111
|
+
* declare module 'basalt-ui' {
|
|
112
|
+
* interface BasaltRegister { overlays: typeof OVERLAYS }
|
|
113
|
+
* }
|
|
114
|
+
*/
|
|
115
|
+
export function defineOverlays<const T extends OverlayMap>(spec: T): T {
|
|
116
|
+
activeOverlays = spec
|
|
117
|
+
return spec
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── defineOverlay (single-overlay helper) ─────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Convenience helper to type a single Overlay object with full inference.
|
|
124
|
+
* Useful when splitting overlays across files before merging into defineOverlays.
|
|
125
|
+
*
|
|
126
|
+
* WARNING: defineOverlay only TYPES an overlay — it does NOT register it into the runtime stash.
|
|
127
|
+
* Only defineOverlays(map) registers overlays. Calling defineOverlay alone means the overlay will
|
|
128
|
+
* never be reachable via overlays.open().
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const deleteOverlay = defineOverlay<{ name: string }>({
|
|
132
|
+
* title: 'Confirm delete',
|
|
133
|
+
* render: ({ name }) => <Text>Delete "{name}"?</Text>,
|
|
134
|
+
* })
|
|
135
|
+
* // Then include it in a defineOverlays({ 'confirm:delete': deleteOverlay }) call to register it.
|
|
136
|
+
*/
|
|
137
|
+
export function defineOverlay<P = Record<string, unknown>>(overlay: Overlay<P>): Overlay<P> {
|
|
138
|
+
return overlay
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ── overlays controller ───────────────────────────────────────────────────────
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Extract the props type for a registered overlay key.
|
|
145
|
+
* When Overlays is un-augmented ({}) this resolves to `never` so open() is uncallable.
|
|
146
|
+
* _K is the mapped key variable; V is the inferred props type — kept distinct to avoid shadowing.
|
|
147
|
+
*/
|
|
148
|
+
type OverlayProps<K extends OverlayKey> = Overlays extends { [_K in K]: Overlay<infer V> }
|
|
149
|
+
? V
|
|
150
|
+
: never
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Imperative overlay controller. Resolves the overlay spec from the runtime stash and delegates
|
|
154
|
+
* to @mantine/modals. Use this for ephemeral, non-route-addressable overlays (confirm dialogs,
|
|
155
|
+
* quick-edit panels). For shareable/back-button/refreshable overlays use route masks via
|
|
156
|
+
* ./router-tanstack.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* overlays.open('confirm:delete', { name: 'photo.jpg' })
|
|
160
|
+
* overlays.close()
|
|
161
|
+
*/
|
|
162
|
+
export const overlays = {
|
|
163
|
+
/**
|
|
164
|
+
* Open a registered overlay by key. Resolves the Overlay spec from the runtime stash and calls
|
|
165
|
+
* modals.open() with the rendered body. The props type is inferred from the registered overlay.
|
|
166
|
+
*
|
|
167
|
+
* `overlays.open('nonexistent', …)` is a tsc error when BasaltRegister.overlays is augmented.
|
|
168
|
+
* Un-augmented: OverlayKey = never → effectively uncallable.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* overlays.open('user:edit', { id: '42' })
|
|
172
|
+
*/
|
|
173
|
+
open<K extends OverlayKey>(key: K, props: OverlayProps<K>): void {
|
|
174
|
+
const spec = activeOverlays[key as string]
|
|
175
|
+
if (spec === undefined) {
|
|
176
|
+
if (process.env['NODE_ENV'] !== 'production')
|
|
177
|
+
console.warn(`[basalt] overlays.open: no overlay registered for "${String(key)}"`)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
void loadModals().then((modals) =>
|
|
181
|
+
modals?.open({
|
|
182
|
+
title: spec.title,
|
|
183
|
+
children: spec.render(props),
|
|
184
|
+
}),
|
|
185
|
+
)
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Close all open overlays (delegates to modals.closeAll()).
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* overlays.close()
|
|
193
|
+
*/
|
|
194
|
+
close(): void {
|
|
195
|
+
void loadModals().then((modals) => modals?.closeAll())
|
|
196
|
+
},
|
|
197
|
+
}
|