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,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./data — TanStack Table + Virtual adapter battery for basalt-ui apps.
|
|
3
|
+
*
|
|
4
|
+
* Provides a sortable data table (BasaltDataTable — with opt-in search/facet toolbar, pagination,
|
|
5
|
+
* and column pinning) and a windowed virtual list (BasaltVirtualList), both rendered with Mantine
|
|
6
|
+
* primitives over headless TanStack logic.
|
|
7
|
+
*
|
|
8
|
+
* Optional peers:
|
|
9
|
+
* - @tanstack/react-table >=8 <9 (BasaltDataTable)
|
|
10
|
+
* - @tanstack/react-virtual >=3 <4 (BasaltVirtualList)
|
|
11
|
+
*
|
|
12
|
+
* Install with:
|
|
13
|
+
* bun add @tanstack/react-table @tanstack/react-virtual
|
|
14
|
+
*
|
|
15
|
+
* Convenience barrel — pulls both peer groups. Use the fine subpaths
|
|
16
|
+
* (`basalt-ui/data/table`, `basalt-ui/data/virtual`) for per-feature opt-in.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Data table:
|
|
20
|
+
* import { BasaltDataTable, createColumnHelper } from 'basalt-ui/data'
|
|
21
|
+
* type Row = { name: string; score: number }
|
|
22
|
+
* const col = createColumnHelper<Row>()
|
|
23
|
+
* const columns = [col.accessor('name', { header: 'Name' }), col.accessor('score', { header: 'Score' })]
|
|
24
|
+
* <BasaltDataTable data={rows} columns={columns} />
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Virtual list:
|
|
28
|
+
* import { BasaltVirtualList } from 'basalt-ui/data'
|
|
29
|
+
* const items = Array.from({ length: 10_000 }, (_, i) => ({ id: i, label: `Row ${i}` }))
|
|
30
|
+
* <BasaltVirtualList items={items} height={400} renderItem={(item) => <div>{item.label}</div>} />
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// ── BasaltDataTable (+ @tanstack/react-table re-exports) ──────────────────────
|
|
34
|
+
export * from './table'
|
|
35
|
+
|
|
36
|
+
// ── BasaltVirtualList ─────────────────────────────────────────────────────────
|
|
37
|
+
export * from './virtual'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./data/table — BasaltDataTable: a sortable data table over @tanstack/react-table, rendered
|
|
3
|
+
* with Mantine primitives. Opt-in chrome: a search/facet toolbar, a pagination bar (client-side
|
|
4
|
+
* or server-driven), and sticky column pinning — see `BasaltDataTableProps` for the full surface.
|
|
5
|
+
*
|
|
6
|
+
* Optional peer: @tanstack/react-table >=8 <9.
|
|
7
|
+
*
|
|
8
|
+
* Use this fine subpath instead of the `./data` barrel when your app only needs the table — it
|
|
9
|
+
* does NOT value-import @tanstack/react-virtual, so the virtual-list peer is never required.
|
|
10
|
+
*
|
|
11
|
+
* Install with:
|
|
12
|
+
* bun add @tanstack/react-table
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { BasaltDataTable, createColumnHelper } from 'basalt-ui/data/table'
|
|
16
|
+
* type Row = { name: string; score: number }
|
|
17
|
+
* const col = createColumnHelper<Row>()
|
|
18
|
+
* const columns = [col.accessor('name', { header: 'Name' }), col.accessor('score', { header: 'Score' })]
|
|
19
|
+
* <BasaltDataTable data={rows} columns={columns} enableGlobalFilter enablePagination />
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// ── BasaltDataTable ───────────────────────────────────────────────────────────
|
|
23
|
+
export { BasaltDataTable } from './data-table'
|
|
24
|
+
export type { BasaltDataTableProps, DataTableFacet, DataTableFacetOption } from './data-table'
|
|
25
|
+
|
|
26
|
+
// ── @tanstack/react-table convenience re-exports ──────────────────────────────
|
|
27
|
+
// These are the handful of table primitives a consumer needs at the call site;
|
|
28
|
+
// importing them from basalt-ui/data/table avoids a separate @tanstack/react-table import.
|
|
29
|
+
// useReactTable + flexRender + the row-model builders (getCoreRowModel/getSortedRowModel/
|
|
30
|
+
// getFilteredRowModel/getPaginationRowModel) are the raw escape hatch: a bespoke, fully custom
|
|
31
|
+
// table can be built from this subpath alone, with no direct @tanstack/react-table import in
|
|
32
|
+
// consumer code.
|
|
33
|
+
export {
|
|
34
|
+
createColumnHelper,
|
|
35
|
+
useReactTable,
|
|
36
|
+
flexRender,
|
|
37
|
+
getCoreRowModel,
|
|
38
|
+
getSortedRowModel,
|
|
39
|
+
getFilteredRowModel,
|
|
40
|
+
getPaginationRowModel,
|
|
41
|
+
type ColumnDef,
|
|
42
|
+
type SortingState,
|
|
43
|
+
type ColumnHelper,
|
|
44
|
+
type PaginationState,
|
|
45
|
+
type ColumnPinningState,
|
|
46
|
+
} from '@tanstack/react-table'
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./data — BasaltVirtualList: a windowed virtual list over @tanstack/react-virtual,
|
|
3
|
+
* rendered with a Mantine Box scroll container.
|
|
4
|
+
* Optional peer: @tanstack/react-virtual >=3 <4.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { BasaltVirtualList } from 'basalt-ui/data'
|
|
8
|
+
*
|
|
9
|
+
* const items = Array.from({ length: 10_000 }, (_, i) => ({ id: i, label: `Row ${i}` }))
|
|
10
|
+
* <BasaltVirtualList
|
|
11
|
+
* items={items}
|
|
12
|
+
* height={400}
|
|
13
|
+
* renderItem={(item) => <div>{item.label}</div>}
|
|
14
|
+
* getItemKey={(item) => item.id}
|
|
15
|
+
* />
|
|
16
|
+
*/
|
|
17
|
+
import { Box, Skeleton } from '@mantine/core'
|
|
18
|
+
import { useVirtualizer } from '@tanstack/react-virtual'
|
|
19
|
+
import { useRef } from 'react'
|
|
20
|
+
import type { ReactNode } from 'react'
|
|
21
|
+
|
|
22
|
+
// ── Props ─────────────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Props for {@link BasaltVirtualList}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const props: BasaltVirtualListProps<{ id: number; label: string }> = {
|
|
29
|
+
* items: rows,
|
|
30
|
+
* height: 400,
|
|
31
|
+
* estimateSize: 48,
|
|
32
|
+
* overscan: 5,
|
|
33
|
+
* renderItem: (item, index) => <div key={item.id}>{index}: {item.label}</div>,
|
|
34
|
+
* getItemKey: (item) => item.id,
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
export type BasaltVirtualListProps<T> = {
|
|
38
|
+
/** All items in the list (unsliced — virtualization is handled internally). */
|
|
39
|
+
items: T[]
|
|
40
|
+
/** Height of the scroll container. Accepts a CSS value ('400px', '60vh') or a number in px. */
|
|
41
|
+
height: number | string
|
|
42
|
+
/**
|
|
43
|
+
* Estimated row height in px (used for virtual layout before measure).
|
|
44
|
+
* @default 40
|
|
45
|
+
*/
|
|
46
|
+
estimateSize?: number
|
|
47
|
+
/**
|
|
48
|
+
* Number of items rendered beyond the visible viewport (above + below) to reduce flicker.
|
|
49
|
+
* @default 5
|
|
50
|
+
*/
|
|
51
|
+
overscan?: number
|
|
52
|
+
/**
|
|
53
|
+
* Render function for a single item. Receives the item and its list index.
|
|
54
|
+
* The returned node is placed inside an absolutely-positioned row container.
|
|
55
|
+
*/
|
|
56
|
+
renderItem: (item: T, index: number) => ReactNode
|
|
57
|
+
/**
|
|
58
|
+
* Stable key for each item. Falls back to the numeric list index when omitted.
|
|
59
|
+
* Providing a stable key prevents react reconciliation churn on scroll.
|
|
60
|
+
*/
|
|
61
|
+
getItemKey?: (item: T, index: number) => string | number
|
|
62
|
+
/**
|
|
63
|
+
* When true, renders skeleton placeholder rows at the given height instead of the virtual item
|
|
64
|
+
* list. The scroll container is still rendered at the specified `height`. Use while async data
|
|
65
|
+
* is loading.
|
|
66
|
+
*/
|
|
67
|
+
isLoading?: boolean
|
|
68
|
+
/**
|
|
69
|
+
* Number of skeleton rows to render when `isLoading` is true.
|
|
70
|
+
* @default 5
|
|
71
|
+
*/
|
|
72
|
+
skeletonRows?: number
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── Component ─────────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A windowed virtual list backed by TanStack Virtual, rendered inside a Mantine `Box` scroll
|
|
79
|
+
* container. Only the visible rows (+`overscan`) are in the DOM at any time.
|
|
80
|
+
*
|
|
81
|
+
* Important: `useFlushSync: false` is set explicitly to silence a React 19 scroll warning
|
|
82
|
+
* (TanStack Virtual internally calls the deprecated `flushSync` on scroll events; this opt-out
|
|
83
|
+
* disables that path and is the correct setting for React 19+ apps).
|
|
84
|
+
*
|
|
85
|
+
* Render pattern: scroll container (fixed height, overflow auto) → inner sizer div (total height,
|
|
86
|
+
* position relative) → absolutely-positioned virtual rows via `transform: translateY(vi.start)`.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const items = Array.from({ length: 5_000 }, (_, i) => ({ id: i, name: `User ${i}` }))
|
|
90
|
+
* <BasaltVirtualList
|
|
91
|
+
* items={items}
|
|
92
|
+
* height={300}
|
|
93
|
+
* estimateSize={40}
|
|
94
|
+
* renderItem={(item) => <div style={{ padding: '8px 12px' }}>{item.name}</div>}
|
|
95
|
+
* getItemKey={(item) => item.id}
|
|
96
|
+
* />
|
|
97
|
+
*/
|
|
98
|
+
export function BasaltVirtualList<T>({
|
|
99
|
+
items,
|
|
100
|
+
height,
|
|
101
|
+
estimateSize = 40,
|
|
102
|
+
overscan = 5,
|
|
103
|
+
renderItem,
|
|
104
|
+
getItemKey,
|
|
105
|
+
isLoading = false,
|
|
106
|
+
skeletonRows = 5,
|
|
107
|
+
}: BasaltVirtualListProps<T>) {
|
|
108
|
+
const parentRef = useRef<HTMLDivElement>(null)
|
|
109
|
+
|
|
110
|
+
const rowVirtualizer = useVirtualizer({
|
|
111
|
+
count: items.length,
|
|
112
|
+
getScrollElement: () => parentRef.current,
|
|
113
|
+
estimateSize: () => estimateSize,
|
|
114
|
+
overscan,
|
|
115
|
+
// Silences a React 19 deprecation warning: TanStack Virtual calls flushSync on scroll;
|
|
116
|
+
// setting this to false opts out of that path entirely.
|
|
117
|
+
useFlushSync: false,
|
|
118
|
+
...(getItemKey !== undefined && {
|
|
119
|
+
getItemKey: (index: number) => {
|
|
120
|
+
const item = items[index]
|
|
121
|
+
return item !== undefined ? getItemKey(item, index) : index
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (isLoading) {
|
|
127
|
+
return (
|
|
128
|
+
// theme-allow — matches the virtualizer's own scroll box below, so the skeleton doesn't reflow.
|
|
129
|
+
<Box style={{ height, overflow: 'auto' }}>
|
|
130
|
+
{Array.from({ length: skeletonRows }, (_, i) => (
|
|
131
|
+
<div
|
|
132
|
+
key={`skeleton-${i}`}
|
|
133
|
+
style={{ height: estimateSize, padding: '8px 12px', boxSizing: 'border-box' }}
|
|
134
|
+
>
|
|
135
|
+
<Skeleton height={estimateSize - 16} radius="sm" />
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
</Box>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Box
|
|
144
|
+
ref={parentRef}
|
|
145
|
+
style={{
|
|
146
|
+
height,
|
|
147
|
+
// theme-allow — TanStack Virtual measures this element as the scroll container.
|
|
148
|
+
overflow: 'auto',
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{/* Inner sizer — defines total scroll height for the virtualizer */}
|
|
152
|
+
<div
|
|
153
|
+
style={{
|
|
154
|
+
height: rowVirtualizer.getTotalSize(),
|
|
155
|
+
position: 'relative',
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
{rowVirtualizer.getVirtualItems().map((virtualItem) => {
|
|
159
|
+
const item = items[virtualItem.index]
|
|
160
|
+
if (item === undefined) return null
|
|
161
|
+
return (
|
|
162
|
+
<div
|
|
163
|
+
key={virtualItem.key}
|
|
164
|
+
style={{
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
top: 0,
|
|
167
|
+
left: 0,
|
|
168
|
+
width: '100%',
|
|
169
|
+
height: virtualItem.size,
|
|
170
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{renderItem(item, virtualItem.index)}
|
|
174
|
+
</div>
|
|
175
|
+
)
|
|
176
|
+
})}
|
|
177
|
+
</div>
|
|
178
|
+
</Box>
|
|
179
|
+
)
|
|
180
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./data/virtual — BasaltVirtualList: a windowed virtual list over @tanstack/react-virtual,
|
|
3
|
+
* rendered with a Mantine Box scroll container.
|
|
4
|
+
*
|
|
5
|
+
* Optional peer: @tanstack/react-virtual >=3 <4.
|
|
6
|
+
*
|
|
7
|
+
* Use this fine subpath instead of the `./data` barrel when your app only needs the virtual list
|
|
8
|
+
* — it does NOT value-import @tanstack/react-table, so the data-table peer is never required.
|
|
9
|
+
*
|
|
10
|
+
* Install with:
|
|
11
|
+
* bun add @tanstack/react-virtual
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { BasaltVirtualList } from 'basalt-ui/data/virtual'
|
|
15
|
+
* const items = Array.from({ length: 10_000 }, (_, i) => ({ id: i, label: `Row ${i}` }))
|
|
16
|
+
* <BasaltVirtualList items={items} height={400} renderItem={(item) => <div>{item.label}</div>} />
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// ── BasaltVirtualList ─────────────────────────────────────────────────────────
|
|
20
|
+
export { BasaltVirtualList } from './virtual-list'
|
|
21
|
+
export type { BasaltVirtualListProps } from './virtual-list'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./forms — FormErrorSummary: accessible error-summary component for long forms.
|
|
3
|
+
* Mantine-coupled. Optional peer: @mantine/form.
|
|
4
|
+
*/
|
|
5
|
+
import { Alert, List, Text } from '@mantine/core'
|
|
6
|
+
import type { UseFormReturnType } from '@mantine/form'
|
|
7
|
+
import { alpha, VX } from '../tokens'
|
|
8
|
+
|
|
9
|
+
// ── FormErrorSummary ──────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
/** Props for FormErrorSummary. */
|
|
12
|
+
export type FormErrorSummaryProps<Values extends Record<string, unknown>> = {
|
|
13
|
+
form: UseFormReturnType<Values>
|
|
14
|
+
/** Accessible heading shown above the error list. Defaults to "Please fix the following errors". */
|
|
15
|
+
title?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Renders an accessible error summary list for long forms and screen readers.
|
|
20
|
+
* Follows the WCAG error-summary pattern — a single `role="alert"` container that
|
|
21
|
+
* lists all field errors, placed at the top of the form so AT announces it on submit.
|
|
22
|
+
*
|
|
23
|
+
* Returns `null` when the form has no errors (renders nothing when the form is clean).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import { FormErrorSummary, useBasaltForm } from 'basalt-ui/forms'
|
|
27
|
+
*
|
|
28
|
+
* function MyForm() {
|
|
29
|
+
* const form = useBasaltForm({ initialValues: { email: '' } })
|
|
30
|
+
* return (
|
|
31
|
+
* <form onSubmit={form.onSubmit(console.log)}>
|
|
32
|
+
* <FormErrorSummary form={form} title="Fix these before submitting" />
|
|
33
|
+
* <TextInput {...field(form, 'email')} label="Email" />
|
|
34
|
+
* </form>
|
|
35
|
+
* )
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export function FormErrorSummary<Values extends Record<string, unknown>>({
|
|
39
|
+
form,
|
|
40
|
+
title = 'Please fix the following errors',
|
|
41
|
+
}: FormErrorSummaryProps<Values>) {
|
|
42
|
+
const errorEntries = Object.entries(form.errors)
|
|
43
|
+
if (errorEntries.length === 0) return null
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Alert
|
|
47
|
+
role="alert"
|
|
48
|
+
radius={6}
|
|
49
|
+
title={<Text fw={600}>{title}</Text>}
|
|
50
|
+
styles={{
|
|
51
|
+
root: {
|
|
52
|
+
backgroundColor: alpha(VX.status.bad, 0.13),
|
|
53
|
+
color: VX.status.bad,
|
|
54
|
+
},
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<List size="sm" mt={4}>
|
|
58
|
+
{errorEntries.map(([path, message]) => (
|
|
59
|
+
<List.Item key={path}>{String(message)}</List.Item>
|
|
60
|
+
))}
|
|
61
|
+
</List>
|
|
62
|
+
</Alert>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./forms — useBasaltForm: typed useForm wrapper applying basalt defaults.
|
|
3
|
+
* Mantine-coupled. Optional peer: @mantine/form.
|
|
4
|
+
*/
|
|
5
|
+
import { schemaResolver, useForm } from '@mantine/form'
|
|
6
|
+
import type { UseFormInput, UseFormReturnType } from '@mantine/form'
|
|
7
|
+
import type { StandardSchemaV1 } from '../register'
|
|
8
|
+
|
|
9
|
+
// ── useBasaltForm ─────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
/** Options for useBasaltForm — a typed useForm wrapper that applies basalt defaults. */
|
|
12
|
+
export type UseBasaltFormOptions<Values extends Record<string, unknown>> = Omit<
|
|
13
|
+
UseFormInput<Values>,
|
|
14
|
+
'validate'
|
|
15
|
+
> & {
|
|
16
|
+
/** Standard Schema (Valibot, Zod 4, ArkType) for field-level validation. */
|
|
17
|
+
schema?: StandardSchemaV1<unknown, Values>
|
|
18
|
+
/** @default 'uncontrolled' */
|
|
19
|
+
mode?: 'controlled' | 'uncontrolled'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Typed useForm wrapper that applies basalt defaults:
|
|
24
|
+
* - `mode: 'uncontrolled'` by default (avoids per-keystroke re-renders)
|
|
25
|
+
* - `validate: schemaResolver(schema, { sync: true })` when `schema` is provided
|
|
26
|
+
*
|
|
27
|
+
* Call this inside a React component or custom hook — it is a hook wrapper.
|
|
28
|
+
* All useForm options are forwarded unchanged.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import * as v from 'valibot'
|
|
32
|
+
* import { useBasaltForm, field } from 'basalt-ui/forms'
|
|
33
|
+
*
|
|
34
|
+
* const Schema = v.object({ name: v.pipe(v.string(), v.minLength(2)), email: v.string() })
|
|
35
|
+
* type Values = v.InferOutput<typeof Schema>
|
|
36
|
+
*
|
|
37
|
+
* function MyForm() {
|
|
38
|
+
* const form = useBasaltForm({ initialValues: { name: '', email: '' }, schema: Schema })
|
|
39
|
+
* return <TextInput {...field(form, 'name')} label="Name" />
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
export function useBasaltForm<Values extends Record<string, unknown>>(
|
|
43
|
+
opts: UseBasaltFormOptions<Values>,
|
|
44
|
+
): UseFormReturnType<Values> {
|
|
45
|
+
const { schema, mode = 'uncontrolled', ...rest } = opts
|
|
46
|
+
return useForm<Values>({
|
|
47
|
+
mode,
|
|
48
|
+
...rest,
|
|
49
|
+
// schemaResolver is provided by @mantine/form and implements the Standard Schema spec.
|
|
50
|
+
// { sync: true } keeps validate/isValid synchronous for sync schemas (Valibot, Zod 4, ArkType).
|
|
51
|
+
...(schema !== undefined && {
|
|
52
|
+
// A real Valibot/Zod schema is structurally assignable to StandardSchemaV1, which is
|
|
53
|
+
// assignable to the resolver's expectation. One narrow cast here, nowhere else.
|
|
54
|
+
validate: schemaResolver(schema as Parameters<typeof schemaResolver>[0], { sync: true }),
|
|
55
|
+
}),
|
|
56
|
+
})
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./forms — field: DX helper for Mantine v9 uncontrolled fields.
|
|
3
|
+
* Mantine-coupled. Optional peer: @mantine/form.
|
|
4
|
+
*/
|
|
5
|
+
import type { LooseKeys, UseFormReturnType } from '@mantine/form'
|
|
6
|
+
|
|
7
|
+
// ── field ─────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Bundles the two props every Mantine v9 uncontrolled field needs — `getInputProps` spread
|
|
11
|
+
* plus the reconciler `key` — into a single object. Eliminates the two-call boilerplate at
|
|
12
|
+
* every field site.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { useBasaltForm, field } from 'basalt-ui/forms'
|
|
16
|
+
*
|
|
17
|
+
* function MyForm() {
|
|
18
|
+
* const form = useBasaltForm({ initialValues: { email: '' } })
|
|
19
|
+
* return <TextInput {...field(form, 'email')} label="Email" />
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export function field<Values extends Record<string, unknown>, Path extends LooseKeys<Values>>(
|
|
23
|
+
form: UseFormReturnType<Values>,
|
|
24
|
+
path: Path,
|
|
25
|
+
): ReturnType<UseFormReturnType<Values>['getInputProps']> & { key: string } {
|
|
26
|
+
return {
|
|
27
|
+
...form.getInputProps(path),
|
|
28
|
+
key: form.key(path),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./forms — Mantine form adapter battery.
|
|
3
|
+
* Provides useBasaltForm, field, FormErrorSummary, and useFormDraft on top of @mantine/form.
|
|
4
|
+
* Optional peer: @mantine/form ^9.3.0.
|
|
5
|
+
*
|
|
6
|
+
* Install with: bun add @mantine/form
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ── useBasaltForm ─────────────────────────────────────────────────────────────
|
|
10
|
+
export { useBasaltForm } from './create-form'
|
|
11
|
+
export type { UseBasaltFormOptions } from './create-form'
|
|
12
|
+
|
|
13
|
+
// ── field ─────────────────────────────────────────────────────────────────────
|
|
14
|
+
export { field } from './field'
|
|
15
|
+
|
|
16
|
+
// ── FormErrorSummary ──────────────────────────────────────────────────────────
|
|
17
|
+
export { FormErrorSummary } from './FormErrorSummary'
|
|
18
|
+
export type { FormErrorSummaryProps } from './FormErrorSummary'
|
|
19
|
+
|
|
20
|
+
// ── useFormDraft ──────────────────────────────────────────────────────────────
|
|
21
|
+
export { useFormDraft } from './use-form-draft'
|
|
22
|
+
export type { UseFormDraftOptions, UseFormDraftReturn } from './use-form-draft'
|
|
23
|
+
|
|
24
|
+
// ── @mantine/form re-exports (convenience) ────────────────────────────────────
|
|
25
|
+
export { useForm, schemaResolver } from '@mantine/form'
|
|
26
|
+
export type { UseFormReturnType, UseFormInput } from '@mantine/form'
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ./forms — useFormDraft: autosave/restore/clear draft persistence via createPersistedState.
|
|
3
|
+
* Mantine-coupled (reads from UseFormReturnType). Optional peer: @mantine/form.
|
|
4
|
+
*
|
|
5
|
+
* AUTOSAVE NOTE: @mantine/form v9 has no whole-form subscription hook on an existing form
|
|
6
|
+
* instance — `form.watch` is per-path only. The cleanest autosave path is to thread
|
|
7
|
+
* `onValuesChange` through useBasaltForm at creation time (the consumer passes the callback
|
|
8
|
+
* there). useFormDraft therefore exposes an explicit `saveDraft()` that the consumer calls
|
|
9
|
+
* at field blur / form change events. Wire it via useBasaltForm's `onValuesChange` prop for
|
|
10
|
+
* fully-automatic autosave:
|
|
11
|
+
*
|
|
12
|
+
* @example (manual blur-based autosave)
|
|
13
|
+
* const form = useBasaltForm({ initialValues, schema })
|
|
14
|
+
* const { clearDraft, saveDraft } = useFormDraft(form, { key: 'my-form', version: 1 })
|
|
15
|
+
* <TextInput {...field(form, 'name')} onBlur={saveDraft} />
|
|
16
|
+
*
|
|
17
|
+
* @example (automatic via onValuesChange in useBasaltForm — use saveDraft ref pattern)
|
|
18
|
+
* const saveDraftRef = useRef<(() => void) | null>(null)
|
|
19
|
+
* const form = useBasaltForm({ initialValues, schema, onValuesChange: () => saveDraftRef.current?.() })
|
|
20
|
+
* const { clearDraft, saveDraft } = useFormDraft(form, { key: 'my-form', version: 1 })
|
|
21
|
+
* saveDraftRef.current = saveDraft
|
|
22
|
+
* // NOTE: the ref pattern avoids the init-order problem — form is created first, the ref
|
|
23
|
+
* // is populated after useFormDraft runs (hooks run top-to-bottom), so by the time
|
|
24
|
+
* // onValuesChange fires on user interaction the ref is always populated.
|
|
25
|
+
*/
|
|
26
|
+
import { useEffect, useRef } from 'react'
|
|
27
|
+
import type { UseFormReturnType } from '@mantine/form'
|
|
28
|
+
import { createPersistedState } from '../state'
|
|
29
|
+
import type { StandardSchemaV1 } from '../register'
|
|
30
|
+
|
|
31
|
+
// ── Types ────────────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
/** Options for useFormDraft. */
|
|
34
|
+
export type UseFormDraftOptions<Values> = {
|
|
35
|
+
/**
|
|
36
|
+
* Stable localStorage key for the draft. Must not change between renders —
|
|
37
|
+
* changing the key recreates the storage instance and loses the draft.
|
|
38
|
+
* Will be stored under `basalt:form:<key>`.
|
|
39
|
+
*/
|
|
40
|
+
key: string
|
|
41
|
+
/** Envelope version — increment when the values shape changes to discard stale drafts. */
|
|
42
|
+
version: number
|
|
43
|
+
/** Optional Standard Schema to validate the persisted draft before restoring. */
|
|
44
|
+
schema?: StandardSchemaV1<unknown, Values>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Return value of useFormDraft. */
|
|
48
|
+
export type UseFormDraftReturn = {
|
|
49
|
+
/** True when a draft different from the initial values is persisted. */
|
|
50
|
+
hasDraft: boolean
|
|
51
|
+
/** Persist the current form values to localStorage. Call on blur, onValuesChange, or submit failure. */
|
|
52
|
+
saveDraft: () => void
|
|
53
|
+
/** Clear the persisted draft (call in onSubmit success). */
|
|
54
|
+
clearDraft: () => void
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ── useFormDraft ─────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Autosave/restore/clear-on-submit draft persistence for Mantine forms.
|
|
61
|
+
* Backed by `createPersistedState` (versioned, SSR-safe, cross-tab).
|
|
62
|
+
*
|
|
63
|
+
* MUST-HAVES:
|
|
64
|
+
* - Restores the draft once on mount if a draft is persisted.
|
|
65
|
+
* - `clearDraft()` removes the persisted draft (call in onSubmit success).
|
|
66
|
+
* - `saveDraft()` snapshots current form values (call onBlur or wire into useBasaltForm's `onValuesChange`).
|
|
67
|
+
*
|
|
68
|
+
* AUTOSAVE: @mantine/form has no whole-form change subscription on an existing form.
|
|
69
|
+
* The cleanest path is to pass `saveDraft` to `useBasaltForm({ onValuesChange: () => saveDraft() })`.
|
|
70
|
+
* For forms not created via useBasaltForm, call `saveDraft` manually on blur.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import * as v from 'valibot'
|
|
74
|
+
* import { useBasaltForm, field, FormErrorSummary, useFormDraft } from 'basalt-ui/forms'
|
|
75
|
+
*
|
|
76
|
+
* const Schema = v.object({ name: v.pipe(v.string(), v.minLength(2)), amount: v.number() })
|
|
77
|
+
* type Values = v.InferOutput<typeof Schema>
|
|
78
|
+
* const INITIAL: Values = { name: '', amount: 0 }
|
|
79
|
+
*
|
|
80
|
+
* function MyForm() {
|
|
81
|
+
* const form = useBasaltForm({ initialValues: INITIAL, schema: Schema, mode: 'uncontrolled' })
|
|
82
|
+
* const { clearDraft, saveDraft, hasDraft } = useFormDraft(form, { key: 'my-form', version: 1 })
|
|
83
|
+
* // Wire saveDraft into onValuesChange after form creation via a ref or external callback:
|
|
84
|
+
* // form is created above; wire via onBlur as the safe fallback shown here.
|
|
85
|
+
* return (
|
|
86
|
+
* <form onSubmit={form.onSubmit((values) => { submit(values); clearDraft() })}>
|
|
87
|
+
* <FormErrorSummary form={form} />
|
|
88
|
+
* <TextInput {...field(form, 'name')} onBlur={saveDraft} />
|
|
89
|
+
* {hasDraft && <Button onClick={clearDraft}>Clear draft</Button>}
|
|
90
|
+
* </form>
|
|
91
|
+
* )
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
export function useFormDraft<Values extends Record<string, unknown>>(
|
|
95
|
+
form: UseFormReturnType<Values>,
|
|
96
|
+
opts: UseFormDraftOptions<Values>,
|
|
97
|
+
): UseFormDraftReturn {
|
|
98
|
+
const { key, version, schema } = opts
|
|
99
|
+
|
|
100
|
+
// Create ONE stable store instance per key. useRef + lazy init so it is never
|
|
101
|
+
// recreated on re-render. `key` MUST be stable (document this invariant above).
|
|
102
|
+
// The storage key becomes `basalt:form:<key>` (createPersistedState auto-namespaces `basalt:*`).
|
|
103
|
+
type DraftEnvelope = { values: Values } | null
|
|
104
|
+
const storeRef = useRef<ReturnType<typeof createPersistedState<DraftEnvelope>> | null>(null)
|
|
105
|
+
if (storeRef.current === null) {
|
|
106
|
+
// Wrap the Values schema into a DraftEnvelope schema using the ~standard interface.
|
|
107
|
+
// We validate the inner `values` field so stale/invalid drafts fall back to null.
|
|
108
|
+
// Only created when schema is provided — exactOptionalPropertyTypes forbids `schema: undefined`.
|
|
109
|
+
const envelopeSchema: StandardSchemaV1<unknown, DraftEnvelope> | undefined =
|
|
110
|
+
schema !== undefined
|
|
111
|
+
? {
|
|
112
|
+
'~standard': {
|
|
113
|
+
version: 1 as const,
|
|
114
|
+
vendor: 'basalt-form-draft',
|
|
115
|
+
validate: (raw: unknown) => {
|
|
116
|
+
if (typeof raw !== 'object' || raw === null || !('values' in raw)) {
|
|
117
|
+
return { value: null }
|
|
118
|
+
}
|
|
119
|
+
const result = schema['~standard'].validate((raw as { values: unknown }).values)
|
|
120
|
+
if (result instanceof Promise) return { value: null }
|
|
121
|
+
if (result.issues !== undefined) return { value: null }
|
|
122
|
+
return { value: { values: result.value } }
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
: undefined
|
|
127
|
+
|
|
128
|
+
storeRef.current = createPersistedState<DraftEnvelope>({
|
|
129
|
+
key: `form:${key}`,
|
|
130
|
+
version,
|
|
131
|
+
initial: null,
|
|
132
|
+
...(envelopeSchema !== undefined && { schema: envelopeSchema }),
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const useDraft = storeRef.current
|
|
137
|
+
const [draft, setDraft] = useDraft()
|
|
138
|
+
|
|
139
|
+
// Track whether a draft exists — differs from null initial
|
|
140
|
+
const hasDraft = draft !== null
|
|
141
|
+
|
|
142
|
+
// RESTORE: once on mount, if a draft exists, restore it into the form.
|
|
143
|
+
// useEffect runs once (empty dep array); `form` and `draft` captured via ref to avoid
|
|
144
|
+
// re-running on subsequent renders. This is intentionally mount-only.
|
|
145
|
+
const restoredRef = useRef(false)
|
|
146
|
+
const formRef = useRef(form)
|
|
147
|
+
formRef.current = form
|
|
148
|
+
const draftOnMountRef = useRef(draft)
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (restoredRef.current) return
|
|
152
|
+
restoredRef.current = true
|
|
153
|
+
const mountDraft = draftOnMountRef.current
|
|
154
|
+
if (mountDraft !== null) {
|
|
155
|
+
formRef.current.setValues(mountDraft.values as Partial<Values>)
|
|
156
|
+
}
|
|
157
|
+
// Intentionally empty deps — restore happens once on mount only.
|
|
158
|
+
}, [])
|
|
159
|
+
|
|
160
|
+
const saveDraft = (): void => {
|
|
161
|
+
const values = formRef.current.getValues()
|
|
162
|
+
setDraft({ values })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const clearDraft = (): void => {
|
|
166
|
+
setDraft(null)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return { hasDraft, saveDraft, clearDraft }
|
|
170
|
+
}
|