@textui/widgets 0.1.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/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/chart/area-chart.d.ts +4 -0
- package/dist/chart/area-chart.d.ts.map +1 -0
- package/dist/chart/area-chart.js +3 -0
- package/dist/chart/bar-chart.d.ts +32 -0
- package/dist/chart/bar-chart.d.ts.map +1 -0
- package/dist/chart/bar-chart.js +32 -0
- package/dist/chart/gauge.d.ts +26 -0
- package/dist/chart/gauge.d.ts.map +1 -0
- package/dist/chart/gauge.js +26 -0
- package/dist/chart/heatmap.d.ts +13 -0
- package/dist/chart/heatmap.d.ts.map +1 -0
- package/dist/chart/heatmap.js +27 -0
- package/dist/chart/histogram.d.ts +12 -0
- package/dist/chart/histogram.d.ts.map +1 -0
- package/dist/chart/histogram.js +22 -0
- package/dist/chart/index.d.ts +20 -0
- package/dist/chart/index.d.ts.map +1 -0
- package/dist/chart/index.js +32 -0
- package/dist/chart/line-chart.d.ts +7 -0
- package/dist/chart/line-chart.d.ts.map +1 -0
- package/dist/chart/line-chart.js +75 -0
- package/dist/chart/shared.d.ts +34 -0
- package/dist/chart/shared.d.ts.map +1 -0
- package/dist/chart/shared.js +78 -0
- package/dist/chart/sparkline.d.ts +15 -0
- package/dist/chart/sparkline.d.ts.map +1 -0
- package/dist/chart/sparkline.js +22 -0
- package/dist/control/button.d.ts +27 -0
- package/dist/control/button.d.ts.map +1 -0
- package/dist/control/button.js +130 -0
- package/dist/control/checkbox.d.ts +10 -0
- package/dist/control/checkbox.d.ts.map +1 -0
- package/dist/control/checkbox.js +31 -0
- package/dist/control/index.d.ts +20 -0
- package/dist/control/index.d.ts.map +1 -0
- package/dist/control/index.js +36 -0
- package/dist/control/radio-group.d.ts +17 -0
- package/dist/control/radio-group.d.ts.map +1 -0
- package/dist/control/radio-group.js +32 -0
- package/dist/control/search-box.d.ts +7 -0
- package/dist/control/search-box.d.ts.map +1 -0
- package/dist/control/search-box.js +3 -0
- package/dist/control/select.d.ts +42 -0
- package/dist/control/select.d.ts.map +1 -0
- package/dist/control/select.js +166 -0
- package/dist/control/shared.d.ts +41 -0
- package/dist/control/shared.d.ts.map +1 -0
- package/dist/control/shared.js +1 -0
- package/dist/control/slider.d.ts +14 -0
- package/dist/control/slider.d.ts.map +1 -0
- package/dist/control/slider.js +45 -0
- package/dist/control/switch.d.ts +10 -0
- package/dist/control/switch.d.ts.map +1 -0
- package/dist/control/switch.js +32 -0
- package/dist/control/text-area.d.ts +87 -0
- package/dist/control/text-area.d.ts.map +1 -0
- package/dist/control/text-area.js +299 -0
- package/dist/control/text-input.d.ts +10 -0
- package/dist/control/text-input.d.ts.map +1 -0
- package/dist/control/text-input.js +129 -0
- package/dist/data/code-viewer.d.ts +71 -0
- package/dist/data/code-viewer.d.ts.map +1 -0
- package/dist/data/code-viewer.js +232 -0
- package/dist/data/feed.d.ts +43 -0
- package/dist/data/feed.d.ts.map +1 -0
- package/dist/data/feed.js +178 -0
- package/dist/data/index.d.ts +54 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +187 -0
- package/dist/data/list.d.ts +31 -0
- package/dist/data/list.d.ts.map +1 -0
- package/dist/data/list.js +104 -0
- package/dist/data/log-viewer.d.ts +26 -0
- package/dist/data/log-viewer.d.ts.map +1 -0
- package/dist/data/log-viewer.js +69 -0
- package/dist/data/markdown-view.d.ts +31 -0
- package/dist/data/markdown-view.d.ts.map +1 -0
- package/dist/data/markdown-view.js +139 -0
- package/dist/data/pagination.d.ts +9 -0
- package/dist/data/pagination.d.ts.map +1 -0
- package/dist/data/pagination.js +18 -0
- package/dist/data/scroll-thumb.d.ts +15 -0
- package/dist/data/scroll-thumb.d.ts.map +1 -0
- package/dist/data/scroll-thumb.js +32 -0
- package/dist/data/shared.d.ts +12 -0
- package/dist/data/shared.d.ts.map +1 -0
- package/dist/data/shared.js +17 -0
- package/dist/data/tree.d.ts +35 -0
- package/dist/data/tree.d.ts.map +1 -0
- package/dist/data/tree.js +158 -0
- package/dist/decorations.d.ts +88 -0
- package/dist/decorations.d.ts.map +1 -0
- package/dist/decorations.js +135 -0
- package/dist/display/alert.d.ts +8 -0
- package/dist/display/alert.d.ts.map +1 -0
- package/dist/display/alert.js +12 -0
- package/dist/display/badge.d.ts +10 -0
- package/dist/display/badge.d.ts.map +1 -0
- package/dist/display/badge.js +21 -0
- package/dist/display/card.d.ts +8 -0
- package/dist/display/card.d.ts.map +1 -0
- package/dist/display/card.js +12 -0
- package/dist/display/empty-state.d.ts +10 -0
- package/dist/display/empty-state.d.ts.map +1 -0
- package/dist/display/empty-state.js +5 -0
- package/dist/display/error-state.d.ts +9 -0
- package/dist/display/error-state.d.ts.map +1 -0
- package/dist/display/error-state.js +7 -0
- package/dist/display/heading.d.ts +6 -0
- package/dist/display/heading.d.ts.map +1 -0
- package/dist/display/heading.js +8 -0
- package/dist/display/index.d.ts +25 -0
- package/dist/display/index.d.ts.map +1 -0
- package/dist/display/index.js +52 -0
- package/dist/display/key-value.d.ts +14 -0
- package/dist/display/key-value.d.ts.map +1 -0
- package/dist/display/key-value.js +11 -0
- package/dist/display/label.d.ts +6 -0
- package/dist/display/label.d.ts.map +1 -0
- package/dist/display/label.js +3 -0
- package/dist/display/marquee.d.ts +36 -0
- package/dist/display/marquee.d.ts.map +1 -0
- package/dist/display/marquee.js +55 -0
- package/dist/display/progress.d.ts +39 -0
- package/dist/display/progress.d.ts.map +1 -0
- package/dist/display/progress.js +46 -0
- package/dist/display/skeleton.d.ts +20 -0
- package/dist/display/skeleton.d.ts.map +1 -0
- package/dist/display/skeleton.js +20 -0
- package/dist/display/spinner.d.ts +7 -0
- package/dist/display/spinner.d.ts.map +1 -0
- package/dist/display/spinner.js +9 -0
- package/dist/display/status-dot.d.ts +8 -0
- package/dist/display/status-dot.d.ts.map +1 -0
- package/dist/display/status-dot.js +13 -0
- package/dist/display/timeline.d.ts +12 -0
- package/dist/display/timeline.d.ts.map +1 -0
- package/dist/display/timeline.js +22 -0
- package/dist/find.d.ts +74 -0
- package/dist/find.d.ts.map +1 -0
- package/dist/find.js +102 -0
- package/dist/form/danger-zone.d.ts +11 -0
- package/dist/form/danger-zone.d.ts.map +1 -0
- package/dist/form/danger-zone.js +15 -0
- package/dist/form/field.d.ts +19 -0
- package/dist/form/field.d.ts.map +1 -0
- package/dist/form/field.js +35 -0
- package/dist/form/form-actions.d.ts +11 -0
- package/dist/form/form-actions.d.ts.map +1 -0
- package/dist/form/form-actions.js +16 -0
- package/dist/form/form-section.d.ts +7 -0
- package/dist/form/form-section.d.ts.map +1 -0
- package/dist/form/form-section.js +5 -0
- package/dist/form/form.d.ts +7 -0
- package/dist/form/form.d.ts.map +1 -0
- package/dist/form/form.js +3 -0
- package/dist/form/index.d.ts +42 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +140 -0
- package/dist/form/shared.d.ts +25 -0
- package/dist/form/shared.d.ts.map +1 -0
- package/dist/form/shared.js +9 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/layout/center.d.ts +7 -0
- package/dist/layout/center.d.ts.map +1 -0
- package/dist/layout/center.js +8 -0
- package/dist/layout/column.d.ts +3 -0
- package/dist/layout/column.d.ts.map +1 -0
- package/dist/layout/column.js +2 -0
- package/dist/layout/divider.d.ts +11 -0
- package/dist/layout/divider.d.ts.map +1 -0
- package/dist/layout/divider.js +13 -0
- package/dist/layout/grid.d.ts +10 -0
- package/dist/layout/grid.d.ts.map +1 -0
- package/dist/layout/grid.js +22 -0
- package/dist/layout/index.d.ts +19 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +36 -0
- package/dist/layout/panel.d.ts +37 -0
- package/dist/layout/panel.d.ts.map +1 -0
- package/dist/layout/panel.js +71 -0
- package/dist/layout/row.d.ts +7 -0
- package/dist/layout/row.d.ts.map +1 -0
- package/dist/layout/row.js +2 -0
- package/dist/layout/scroll-view.d.ts +27 -0
- package/dist/layout/scroll-view.d.ts.map +1 -0
- package/dist/layout/scroll-view.js +93 -0
- package/dist/layout/splitter.d.ts +10 -0
- package/dist/layout/splitter.d.ts.map +1 -0
- package/dist/layout/splitter.js +9 -0
- package/dist/layout/stack.d.ts +7 -0
- package/dist/layout/stack.d.ts.map +1 -0
- package/dist/layout/stack.js +5 -0
- package/dist/navigation/breadcrumb.d.ts +14 -0
- package/dist/navigation/breadcrumb.d.ts.map +1 -0
- package/dist/navigation/breadcrumb.js +24 -0
- package/dist/navigation/index.d.ts +17 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +30 -0
- package/dist/navigation/key-hints.d.ts +11 -0
- package/dist/navigation/key-hints.d.ts.map +1 -0
- package/dist/navigation/key-hints.js +13 -0
- package/dist/navigation/menu.d.ts +35 -0
- package/dist/navigation/menu.d.ts.map +1 -0
- package/dist/navigation/menu.js +88 -0
- package/dist/navigation/status-bar.d.ts +18 -0
- package/dist/navigation/status-bar.d.ts.map +1 -0
- package/dist/navigation/status-bar.js +12 -0
- package/dist/navigation/tabs.d.ts +20 -0
- package/dist/navigation/tabs.d.ts.map +1 -0
- package/dist/navigation/tabs.js +41 -0
- package/dist/navigation/toolbar.d.ts +14 -0
- package/dist/navigation/toolbar.d.ts.map +1 -0
- package/dist/navigation/toolbar.js +10 -0
- package/dist/navigation/wizard.d.ts +15 -0
- package/dist/navigation/wizard.d.ts.map +1 -0
- package/dist/navigation/wizard.js +17 -0
- package/dist/overlay/command-palette.d.ts +63 -0
- package/dist/overlay/command-palette.d.ts.map +1 -0
- package/dist/overlay/command-palette.js +415 -0
- package/dist/overlay/dialog.d.ts +16 -0
- package/dist/overlay/dialog.d.ts.map +1 -0
- package/dist/overlay/dialog.js +44 -0
- package/dist/overlay/index.d.ts +84 -0
- package/dist/overlay/index.d.ts.map +1 -0
- package/dist/overlay/index.js +157 -0
- package/dist/overlay/layer-scope.d.ts +21 -0
- package/dist/overlay/layer-scope.d.ts.map +1 -0
- package/dist/overlay/layer-scope.js +5 -0
- package/dist/overlay/path-picker.d.ts +14 -0
- package/dist/overlay/path-picker.d.ts.map +1 -0
- package/dist/overlay/path-picker.js +200 -0
- package/dist/overlay/prompt-dialog.d.ts +12 -0
- package/dist/overlay/prompt-dialog.d.ts.map +1 -0
- package/dist/overlay/prompt-dialog.js +29 -0
- package/dist/overlay/shared.d.ts +17 -0
- package/dist/overlay/shared.d.ts.map +1 -0
- package/dist/overlay/shared.js +17 -0
- package/dist/overlay/toast-host.d.ts +8 -0
- package/dist/overlay/toast-host.d.ts.map +1 -0
- package/dist/overlay/toast-host.js +19 -0
- package/dist/overlay/toast.d.ts +9 -0
- package/dist/overlay/toast.d.ts.map +1 -0
- package/dist/overlay/toast.js +20 -0
- package/dist/overlay/tooltip.d.ts +6 -0
- package/dist/overlay/tooltip.d.ts.map +1 -0
- package/dist/overlay/tooltip.js +11 -0
- package/dist/panel/index.d.ts +79 -0
- package/dist/panel/index.d.ts.map +1 -0
- package/dist/panel/index.js +256 -0
- package/dist/panel/resource-panel.d.ts +93 -0
- package/dist/panel/resource-panel.d.ts.map +1 -0
- package/dist/panel/resource-panel.js +213 -0
- package/dist/panel/shared.d.ts +6 -0
- package/dist/panel/shared.d.ts.map +1 -0
- package/dist/panel/shared.js +4 -0
- package/dist/shells/console-shell.d.ts +8 -0
- package/dist/shells/console-shell.d.ts.map +1 -0
- package/dist/shells/console-shell.js +30 -0
- package/dist/shells/index.d.ts +20 -0
- package/dist/shells/index.d.ts.map +1 -0
- package/dist/shells/index.js +61 -0
- package/dist/shells/paper-shell.d.ts +9 -0
- package/dist/shells/paper-shell.d.ts.map +1 -0
- package/dist/shells/paper-shell.js +23 -0
- package/dist/shells/plain-shell.d.ts +3 -0
- package/dist/shells/plain-shell.d.ts.map +1 -0
- package/dist/shells/plain-shell.js +11 -0
- package/dist/shells/shared.d.ts +12 -0
- package/dist/shells/shared.d.ts.map +1 -0
- package/dist/shells/shared.js +21 -0
- package/dist/shells/workbench-shell.d.ts +9 -0
- package/dist/shells/workbench-shell.d.ts.map +1 -0
- package/dist/shells/workbench-shell.js +43 -0
- package/dist/surface/bar-layout.d.ts +4 -0
- package/dist/surface/bar-layout.d.ts.map +1 -0
- package/dist/surface/bar-layout.js +7 -0
- package/dist/surface/index.d.ts +58 -0
- package/dist/surface/index.d.ts.map +1 -0
- package/dist/surface/index.js +48 -0
- package/dist/surface/inline-layout.d.ts +4 -0
- package/dist/surface/inline-layout.d.ts.map +1 -0
- package/dist/surface/inline-layout.js +7 -0
- package/dist/surface/mount-view.d.ts +7 -0
- package/dist/surface/mount-view.d.ts.map +1 -0
- package/dist/surface/mount-view.js +19 -0
- package/dist/surface/rail-layout.d.ts +4 -0
- package/dist/surface/rail-layout.d.ts.map +1 -0
- package/dist/surface/rail-layout.js +19 -0
- package/dist/surface/shared.d.ts +7 -0
- package/dist/surface/shared.d.ts.map +1 -0
- package/dist/surface/shared.js +1 -0
- package/dist/surface/single-layout.d.ts +4 -0
- package/dist/surface/single-layout.d.ts.map +1 -0
- package/dist/surface/single-layout.js +18 -0
- package/dist/surface/split-layout.d.ts +4 -0
- package/dist/surface/split-layout.d.ts.map +1 -0
- package/dist/surface/split-layout.js +7 -0
- package/dist/surface/stack-layout.d.ts +4 -0
- package/dist/surface/stack-layout.d.ts.map +1 -0
- package/dist/surface/stack-layout.js +22 -0
- package/dist/surface/surface-area.d.ts +16 -0
- package/dist/surface/surface-area.d.ts.map +1 -0
- package/dist/surface/surface-area.js +32 -0
- package/dist/surface/tabs-layout.d.ts +4 -0
- package/dist/surface/tabs-layout.d.ts.map +1 -0
- package/dist/surface/tabs-layout.js +24 -0
- package/dist/tone.d.ts +16 -0
- package/dist/tone.d.ts.map +1 -0
- package/dist/tone.js +45 -0
- package/dist/viewport.d.ts +30 -0
- package/dist/viewport.d.ts.map +1 -0
- package/dist/viewport.js +17 -0
- package/package.json +54 -0
- package/src/chart/area-chart.ts +9 -0
- package/src/chart/bar-chart.ts +74 -0
- package/src/chart/gauge.ts +60 -0
- package/src/chart/heatmap.ts +49 -0
- package/src/chart/histogram.ts +36 -0
- package/src/chart/index.ts +36 -0
- package/src/chart/line-chart.ts +100 -0
- package/src/chart/shared.ts +112 -0
- package/src/chart/sparkline.ts +46 -0
- package/src/control/button.ts +184 -0
- package/src/control/checkbox.ts +48 -0
- package/src/control/index.ts +40 -0
- package/src/control/radio-group.ts +60 -0
- package/src/control/search-box.ts +15 -0
- package/src/control/select.ts +230 -0
- package/src/control/shared.ts +41 -0
- package/src/control/slider.ts +63 -0
- package/src/control/switch.ts +39 -0
- package/src/control/text-area.ts +390 -0
- package/src/control/text-input.ts +150 -0
- package/src/data/code-viewer.ts +337 -0
- package/src/data/feed.ts +204 -0
- package/src/data/index.ts +243 -0
- package/src/data/list.ts +149 -0
- package/src/data/log-viewer.ts +105 -0
- package/src/data/markdown-view.ts +182 -0
- package/src/data/pagination.ts +31 -0
- package/src/data/scroll-thumb.ts +40 -0
- package/src/data/shared.ts +23 -0
- package/src/data/tree.ts +215 -0
- package/src/decorations.ts +176 -0
- package/src/display/alert.ts +28 -0
- package/src/display/badge.ts +40 -0
- package/src/display/card.ts +23 -0
- package/src/display/empty-state.ts +21 -0
- package/src/display/error-state.ts +23 -0
- package/src/display/heading.ts +17 -0
- package/src/display/index.ts +55 -0
- package/src/display/key-value.ts +32 -0
- package/src/display/label.ts +11 -0
- package/src/display/marquee.ts +88 -0
- package/src/display/progress.ts +92 -0
- package/src/display/skeleton.ts +34 -0
- package/src/display/spinner.ts +20 -0
- package/src/display/status-dot.ts +24 -0
- package/src/display/timeline.ts +47 -0
- package/src/find.ts +138 -0
- package/src/form/danger-zone.ts +34 -0
- package/src/form/field.ts +61 -0
- package/src/form/form-actions.ts +35 -0
- package/src/form/form-section.ts +16 -0
- package/src/form/form.ts +13 -0
- package/src/form/index.ts +191 -0
- package/src/form/shared.ts +36 -0
- package/src/index.ts +63 -0
- package/src/layout/center.ts +17 -0
- package/src/layout/column.ts +6 -0
- package/src/layout/divider.ts +31 -0
- package/src/layout/grid.ts +34 -0
- package/src/layout/index.ts +39 -0
- package/src/layout/panel.ts +114 -0
- package/src/layout/row.ts +11 -0
- package/src/layout/scroll-view.ts +115 -0
- package/src/layout/splitter.ts +24 -0
- package/src/layout/stack.ts +12 -0
- package/src/navigation/breadcrumb.ts +43 -0
- package/src/navigation/index.ts +33 -0
- package/src/navigation/key-hints.ts +25 -0
- package/src/navigation/menu.ts +134 -0
- package/src/navigation/status-bar.ts +43 -0
- package/src/navigation/tabs.ts +73 -0
- package/src/navigation/toolbar.ts +25 -0
- package/src/navigation/wizard.ts +43 -0
- package/src/overlay/command-palette.ts +485 -0
- package/src/overlay/dialog.ts +65 -0
- package/src/overlay/index.ts +232 -0
- package/src/overlay/layer-scope.ts +26 -0
- package/src/overlay/path-picker.ts +215 -0
- package/src/overlay/prompt-dialog.ts +45 -0
- package/src/overlay/shared.ts +19 -0
- package/src/overlay/toast-host.ts +30 -0
- package/src/overlay/toast.ts +35 -0
- package/src/overlay/tooltip.ts +17 -0
- package/src/panel/index.ts +317 -0
- package/src/panel/resource-panel.ts +304 -0
- package/src/panel/shared.ts +8 -0
- package/src/shells/console-shell.ts +47 -0
- package/src/shells/index.ts +66 -0
- package/src/shells/paper-shell.ts +31 -0
- package/src/shells/plain-shell.ts +19 -0
- package/src/shells/shared.ts +24 -0
- package/src/shells/workbench-shell.ts +62 -0
- package/src/surface/bar-layout.ts +11 -0
- package/src/surface/index.ts +53 -0
- package/src/surface/inline-layout.ts +11 -0
- package/src/surface/mount-view.ts +30 -0
- package/src/surface/rail-layout.ts +27 -0
- package/src/surface/shared.ts +7 -0
- package/src/surface/single-layout.ts +25 -0
- package/src/surface/split-layout.ts +11 -0
- package/src/surface/stack-layout.ts +32 -0
- package/src/surface/surface-area.ts +46 -0
- package/src/surface/tabs-layout.ts +30 -0
- package/src/tone.ts +48 -0
- package/src/viewport.ts +45 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineComponent, h, useRuntime, useStoreSubtree } from '@textui/core';
|
|
2
|
+
/**
|
|
3
|
+
* Render one surface through its active layout.
|
|
4
|
+
*
|
|
5
|
+
* This subscribes to the surface's state and mount list rather than to the
|
|
6
|
+
* whole store, so opening a tab in `main` does not re-render the status bar.
|
|
7
|
+
*/
|
|
8
|
+
export const SurfaceArea = defineComponent('SurfaceArea', (props) => {
|
|
9
|
+
const runtime = useRuntime();
|
|
10
|
+
const { surface, layout: layoutOverride, fallback, ...rest } = props;
|
|
11
|
+
// Subscribing to both paths is what makes a surface reactive.
|
|
12
|
+
useStoreSubtree(`$/layout/surfaces/${surface}`);
|
|
13
|
+
useStoreSubtree(`$/layout/mounts/${surface}`);
|
|
14
|
+
const app = runtime.app();
|
|
15
|
+
if (!app)
|
|
16
|
+
return null;
|
|
17
|
+
const state = app.surfaces.state(surface);
|
|
18
|
+
if (!state.visible || state.collapsed)
|
|
19
|
+
return null;
|
|
20
|
+
const mounts = app.surfaces.mounts(surface);
|
|
21
|
+
if (mounts.length === 0)
|
|
22
|
+
return fallback ? h('box', { ...rest }, fallback) : null;
|
|
23
|
+
const layoutName = layoutOverride ?? state.layout;
|
|
24
|
+
const definition = app.layouts.get(layoutName);
|
|
25
|
+
if (!definition) {
|
|
26
|
+
return h('text', {
|
|
27
|
+
content: `[textui] no layout registered as "${layoutName}"`,
|
|
28
|
+
fg: 'danger',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return h(definition.component, { surface, mounts, state, ...rest });
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs-layout.d.ts","sourceRoot":"","sources":["../../src/surface/tabs-layout.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wCAAwC;AACxC,eAAO,MAAM,UAAU,6DAuBrB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineComponent, h, useRuntime } from '@textui/core';
|
|
2
|
+
import { Tabs } from '../navigation/index.js';
|
|
3
|
+
import { MountView } from './mount-view.js';
|
|
4
|
+
/** A tab strip and the active mount. */
|
|
5
|
+
export const TabsLayout = defineComponent('TabsLayout', (props) => {
|
|
6
|
+
const runtime = useRuntime();
|
|
7
|
+
const { mounts, state, surface, ...rest } = props;
|
|
8
|
+
if (mounts.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
const active = mounts.find((m) => m.key === state.activeKey) ?? mounts[0];
|
|
11
|
+
const app = runtime.app();
|
|
12
|
+
return h('box', { direction: 'column', flex: 1, ...rest }, mounts.length > 1
|
|
13
|
+
? h(Tabs, {
|
|
14
|
+
items: mounts.map((m) => ({
|
|
15
|
+
id: m.key,
|
|
16
|
+
label: m.display?.title ?? m.key,
|
|
17
|
+
icon: m.display?.icon,
|
|
18
|
+
badge: m.display?.badge,
|
|
19
|
+
})),
|
|
20
|
+
activeId: active?.key,
|
|
21
|
+
onChange: (key) => app?.surfaces.activate(surface, key),
|
|
22
|
+
})
|
|
23
|
+
: null, active ? h(MountView, { mount: active, flex: 1 }) : null);
|
|
24
|
+
});
|
package/dist/tone.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SemanticVariant, StyleColor } from '@textui/core';
|
|
2
|
+
/**
|
|
3
|
+
* The two halves of a tone.
|
|
4
|
+
*
|
|
5
|
+
* `TONE` is the colour a tone is drawn *in*; `ON_TONE` is what is written *on*
|
|
6
|
+
* it once it becomes a background. They belong together and are stated once,
|
|
7
|
+
* because a component that pairs `danger` with the wrong foreground produces
|
|
8
|
+
* the one thing a status colour must never be, which is unreadable.
|
|
9
|
+
*
|
|
10
|
+
* The theme states an `on*` token per tone rather than a single "inverted" for
|
|
11
|
+
* all of them: the contrast that works on a green fill is not the one that
|
|
12
|
+
* works on a red one.
|
|
13
|
+
*/
|
|
14
|
+
export declare const TONE: Record<SemanticVariant, StyleColor>;
|
|
15
|
+
export declare const ON_TONE: Record<SemanticVariant, StyleColor>;
|
|
16
|
+
//# sourceMappingURL=tone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tone.d.ts","sourceRoot":"","sources":["../src/tone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,eAAe,EAAE,UAAU,CAUpD,CAAC;AAaF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,eAAe,EAAE,UAAU,CAUvD,CAAC"}
|
package/dist/tone.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two halves of a tone.
|
|
3
|
+
*
|
|
4
|
+
* `TONE` is the colour a tone is drawn *in*; `ON_TONE` is what is written *on*
|
|
5
|
+
* it once it becomes a background. They belong together and are stated once,
|
|
6
|
+
* because a component that pairs `danger` with the wrong foreground produces
|
|
7
|
+
* the one thing a status colour must never be, which is unreadable.
|
|
8
|
+
*
|
|
9
|
+
* The theme states an `on*` token per tone rather than a single "inverted" for
|
|
10
|
+
* all of them: the contrast that works on a green fill is not the one that
|
|
11
|
+
* works on a red one.
|
|
12
|
+
*/
|
|
13
|
+
export const TONE = {
|
|
14
|
+
default: 'text',
|
|
15
|
+
primary: 'primary',
|
|
16
|
+
secondary: 'secondary',
|
|
17
|
+
accent: 'accent',
|
|
18
|
+
success: 'success',
|
|
19
|
+
warning: 'warning',
|
|
20
|
+
danger: 'danger',
|
|
21
|
+
info: 'info',
|
|
22
|
+
muted: 'muted',
|
|
23
|
+
};
|
|
24
|
+
// Adding a tone, or renaming an `on*` token, means three edits and only two of
|
|
25
|
+
// them are checked:
|
|
26
|
+
//
|
|
27
|
+
// 1. this map and its `TONE` pair;
|
|
28
|
+
// 2. every theme in themes/builtin.ts, or the token resolves to nothing;
|
|
29
|
+
// 3. the palette list in docs/themes/tokens.md - which `pnpm docs:check`
|
|
30
|
+
// does NOT catch, because that check reads component prop interfaces and
|
|
31
|
+
// knows nothing about token names.
|
|
32
|
+
//
|
|
33
|
+
// The third is the one that gets missed. `onDefault`, `onSecondary` and
|
|
34
|
+
// `onMuted` were absent from that page until they were added by hand.
|
|
35
|
+
export const ON_TONE = {
|
|
36
|
+
default: 'onDefault',
|
|
37
|
+
primary: 'onPrimary',
|
|
38
|
+
secondary: 'onSecondary',
|
|
39
|
+
accent: 'onAccent',
|
|
40
|
+
success: 'onSuccess',
|
|
41
|
+
warning: 'onWarning',
|
|
42
|
+
danger: 'onDanger',
|
|
43
|
+
info: 'onInfo',
|
|
44
|
+
muted: 'onMuted',
|
|
45
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Rect, Dimension } from '@textui/core';
|
|
2
|
+
/**
|
|
3
|
+
* How many rows a scrolling component should draw.
|
|
4
|
+
*
|
|
5
|
+
* The subtle part is knowing when the measurement means anything. A box that
|
|
6
|
+
* was stretched, flexed or given a height fills what the layout handed it, and
|
|
7
|
+
* measuring tells it how much that was. A box with none of those is sized *by*
|
|
8
|
+
* its own content - measuring it just reports back how many rows it drew last
|
|
9
|
+
* frame, and clamping to that would mean an expanding tree could never grow
|
|
10
|
+
* past the size it had when it was first drawn.
|
|
11
|
+
*
|
|
12
|
+
* So: layout-sized components fill and scroll, content-sized ones draw
|
|
13
|
+
* everything, and which one you get is decided by the props you passed.
|
|
14
|
+
*/
|
|
15
|
+
export interface SizedProps {
|
|
16
|
+
flex?: number;
|
|
17
|
+
height?: Dimension;
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
basis?: Dimension;
|
|
20
|
+
}
|
|
21
|
+
export declare function sizedByLayout(props: SizedProps): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The row count to render: what was asked for, else what fits, else all of it.
|
|
24
|
+
* `reserved` takes off rows the component spends on chrome, like a header.
|
|
25
|
+
*/
|
|
26
|
+
export declare function viewportRows(props: SizedProps, measured: Rect, content: number, options?: {
|
|
27
|
+
requested?: number;
|
|
28
|
+
reserved?: number;
|
|
29
|
+
}): number;
|
|
30
|
+
//# sourceMappingURL=viewport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../src/viewport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAOxD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,IAAI,EACd,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACtD,MAAM,CAIR"}
|
package/dist/viewport.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function sizedByLayout(props) {
|
|
2
|
+
return (props.flex !== undefined ||
|
|
3
|
+
props.height !== undefined ||
|
|
4
|
+
props.maxHeight !== undefined ||
|
|
5
|
+
props.basis !== undefined);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The row count to render: what was asked for, else what fits, else all of it.
|
|
9
|
+
* `reserved` takes off rows the component spends on chrome, like a header.
|
|
10
|
+
*/
|
|
11
|
+
export function viewportRows(props, measured, content, options = {}) {
|
|
12
|
+
if (options.requested !== undefined)
|
|
13
|
+
return Math.max(1, options.requested);
|
|
14
|
+
if (!sizedByLayout(props) || measured.height <= 0)
|
|
15
|
+
return content;
|
|
16
|
+
return Math.max(1, measured.height - (options.reserved ?? 0));
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@textui/widgets",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The TextUI component catalog - layout, display, controls, data, overlays and charts",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"terminal",
|
|
7
|
+
"tui",
|
|
8
|
+
"components",
|
|
9
|
+
"widgets",
|
|
10
|
+
"jsx",
|
|
11
|
+
"ui",
|
|
12
|
+
"catalog",
|
|
13
|
+
"text-ui"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://softov.github.io/textui/",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/softov/textui/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/softov/textui.git",
|
|
22
|
+
"directory": "packages/widgets"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Softov <softov@brbyte.com>",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@textui/core": "^0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.json",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
|
|
52
|
+
"test": "vitest run"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineComponent, h } from '@textui/core';
|
|
2
|
+
import { LineChart } from './line-chart.js';
|
|
3
|
+
import type { LineChartProps } from './shared.js';
|
|
4
|
+
|
|
5
|
+
export type AreaChartProps = LineChartProps;
|
|
6
|
+
|
|
7
|
+
export const AreaChart = defineComponent<AreaChartProps>('AreaChart', (props) =>
|
|
8
|
+
h(LineChart, { area: true, ...props }),
|
|
9
|
+
);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { BoxProps, SemanticVariant } from '@textui/core';
|
|
2
|
+
import { defineComponent, h, stringWidth, useTheme } from '@textui/core';
|
|
3
|
+
import { TONE, VerticalBars } from './shared.js';
|
|
4
|
+
|
|
5
|
+
export interface BarChartProps extends BoxProps {
|
|
6
|
+
data: { label: string; value: number; tone?: SemanticVariant }[];
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Cells the bars occupy, not counting labels. Horizontal only - see below. */
|
|
9
|
+
barWidth?: number;
|
|
10
|
+
showValue?: boolean;
|
|
11
|
+
format?(value: number): string;
|
|
12
|
+
orientation?: 'horizontal' | 'vertical';
|
|
13
|
+
/**
|
|
14
|
+
* How many cells across each bar is, standing up.
|
|
15
|
+
*
|
|
16
|
+
* Vertical only, and one by default - which is what it always was, and is a
|
|
17
|
+
* hairline rather than a bar. Two or three read as bars, and the label under
|
|
18
|
+
* each one grows to match, so `columnWidth: 2` gets two letters instead of
|
|
19
|
+
* an initial.
|
|
20
|
+
*
|
|
21
|
+
* The two axes are named separately on purpose. `barWidth` is how far a
|
|
22
|
+
* horizontal bar runs, which is the *value* axis; this is the thickness of a
|
|
23
|
+
* vertical one, which is the category axis. Lying flat they swap over, and a
|
|
24
|
+
* single prop meaning both would mean neither.
|
|
25
|
+
*/
|
|
26
|
+
columnWidth?: number;
|
|
27
|
+
/** Rows tall, standing up. Vertical only. */
|
|
28
|
+
chartHeight?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const BarChart = defineComponent<BarChartProps>('BarChart', (props) => {
|
|
32
|
+
const theme = useTheme();
|
|
33
|
+
const {
|
|
34
|
+
data, max, barWidth = 20, showValue = true, format,
|
|
35
|
+
orientation = 'horizontal', columnWidth, chartHeight = 8, ...rest
|
|
36
|
+
} = props;
|
|
37
|
+
|
|
38
|
+
const hi = max ?? Math.max(1, ...data.map((d) => d.value));
|
|
39
|
+
const labelWidth = Math.max(0, ...data.map((d) => stringWidth(d.label)));
|
|
40
|
+
|
|
41
|
+
if (orientation === 'vertical') {
|
|
42
|
+
return h(VerticalBars, {
|
|
43
|
+
data,
|
|
44
|
+
max: hi,
|
|
45
|
+
height: chartHeight,
|
|
46
|
+
...(columnWidth === undefined ? {} : { columnWidth }),
|
|
47
|
+
...rest,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const partials = theme.glyphs.progressPartial;
|
|
52
|
+
|
|
53
|
+
return h('box', { direction: 'column', ...rest },
|
|
54
|
+
...data.map((item) => {
|
|
55
|
+
const exact = (item.value / hi) * barWidth;
|
|
56
|
+
const full = Math.floor(exact);
|
|
57
|
+
const rem = exact - full;
|
|
58
|
+
const partial = full < barWidth && rem > 0
|
|
59
|
+
? (partials[Math.floor(rem * partials.length)] ?? '')
|
|
60
|
+
: '';
|
|
61
|
+
|
|
62
|
+
return h('box', { key: item.label, direction: 'row', gap: 1 },
|
|
63
|
+
h('box', { width: labelWidth }, h('text', { content: item.label, fg: 'muted' })),
|
|
64
|
+
h('text', {
|
|
65
|
+
content: theme.glyphs.progressFull.repeat(full) + partial,
|
|
66
|
+
fg: TONE[item.tone ?? 'accent'],
|
|
67
|
+
}),
|
|
68
|
+
showValue
|
|
69
|
+
? h('text', { content: format ? format(item.value) : String(item.value), fg: 'muted' })
|
|
70
|
+
: null,
|
|
71
|
+
);
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BoxProps, SemanticVariant } from '@textui/core';
|
|
2
|
+
import { defineComponent, h, useTheme } from '@textui/core';
|
|
3
|
+
import { TONE } from './shared.js';
|
|
4
|
+
|
|
5
|
+
export interface GaugeProps extends BoxProps {
|
|
6
|
+
value: number;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Bands that colour the reading by range. */
|
|
11
|
+
thresholds?: { at: number; tone: SemanticVariant }[];
|
|
12
|
+
format?(value: number): string;
|
|
13
|
+
gaugeWidth?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Push the gauge away from the label, to the right edge of the row.
|
|
16
|
+
*
|
|
17
|
+
* The label's cell stretches, so it stays at the left and
|
|
18
|
+
* the track ends up hard against the right - which is what makes a column of
|
|
19
|
+
* these read as a table rather than as a ragged stack. Needs a row wider
|
|
20
|
+
* than its contents to have any effect, so the caller has to have given it a
|
|
21
|
+
* width or a `flex`.
|
|
22
|
+
*/
|
|
23
|
+
spacer?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Gauge = defineComponent<GaugeProps>('Gauge', (props) => {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const {
|
|
29
|
+
value, min = 0, max = 100, label, thresholds = [], format, gaugeWidth = 20,
|
|
30
|
+
spacer, ...rest
|
|
31
|
+
} = props;
|
|
32
|
+
|
|
33
|
+
const ratio = Math.max(0, Math.min(1, (value - min) / (max - min || 1)));
|
|
34
|
+
const filled = Math.round(ratio * gaugeWidth);
|
|
35
|
+
|
|
36
|
+
// The highest threshold at or below the value wins.
|
|
37
|
+
const tone = [...thresholds]
|
|
38
|
+
.sort((a, b) => b.at - a.at)
|
|
39
|
+
.find((t) => value >= t.at)?.tone ?? 'accent';
|
|
40
|
+
|
|
41
|
+
return h('box', { direction: 'row', gap: 1, role: 'meter', label, ...rest },
|
|
42
|
+
label !== undefined
|
|
43
|
+
// The label's own cell stretches rather than a `spacer` child going in
|
|
44
|
+
// beside it: a child would be free but its gap would not, and a row
|
|
45
|
+
// sized exactly to its contents would truncate the gauge to fit a space.
|
|
46
|
+
? h('text', { content: label, fg: 'muted', ...(spacer === true ? { flex: 1 } : {}) })
|
|
47
|
+
: spacer === true ? h('spacer', {}) : null,
|
|
48
|
+
h('text', {
|
|
49
|
+
content:
|
|
50
|
+
theme.glyphs.progressFull.repeat(filled) +
|
|
51
|
+
theme.glyphs.progressEmpty.repeat(Math.max(0, gaugeWidth - filled)),
|
|
52
|
+
fg: TONE[tone],
|
|
53
|
+
}),
|
|
54
|
+
h('text', {
|
|
55
|
+
content: format ? format(value) : `${Math.round(ratio * 100)}%`,
|
|
56
|
+
fg: TONE[tone],
|
|
57
|
+
bold: true,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BoxProps } from '@textui/core';
|
|
2
|
+
import { defineComponent, h, stringWidth, useTheme } from '@textui/core';
|
|
3
|
+
import { bounds } from './shared.js';
|
|
4
|
+
|
|
5
|
+
export interface HeatmapProps extends BoxProps {
|
|
6
|
+
/** Rows of values. All rows should be the same length. */
|
|
7
|
+
data: number[][];
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
rowLabels?: string[];
|
|
11
|
+
columnLabels?: string[];
|
|
12
|
+
/** Glyph ramp, lowest to highest. Defaults to the theme's blocks. */
|
|
13
|
+
ramp?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Heatmap = defineComponent<HeatmapProps>('Heatmap', (props) => {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const { data, min, max, rowLabels, columnLabels, ramp, ...rest } = props;
|
|
19
|
+
const glyphs = ramp ?? theme.glyphs.blocks;
|
|
20
|
+
const flat = data.flat();
|
|
21
|
+
const [lo, hi] = bounds(flat, min, max);
|
|
22
|
+
const labelWidth = rowLabels ? Math.max(0, ...rowLabels.map(stringWidth)) : 0;
|
|
23
|
+
|
|
24
|
+
return h('box', { direction: 'column', ...rest },
|
|
25
|
+
columnLabels
|
|
26
|
+
? h('box', { direction: 'row', gap: 0 },
|
|
27
|
+
labelWidth ? h('box', { width: labelWidth + 1 }) : null,
|
|
28
|
+
h('text', {
|
|
29
|
+
content: columnLabels.map((l) => l.slice(0, 1)).join(''),
|
|
30
|
+
fg: 'subtle',
|
|
31
|
+
}))
|
|
32
|
+
: null,
|
|
33
|
+
...data.map((row, y) =>
|
|
34
|
+
h('box', { key: y, direction: 'row', gap: rowLabels ? 1 : 0 },
|
|
35
|
+
rowLabels
|
|
36
|
+
? h('box', { width: labelWidth }, h('text', { content: rowLabels[y] ?? '', fg: 'muted' }))
|
|
37
|
+
: null,
|
|
38
|
+
h('text', {
|
|
39
|
+
content: row
|
|
40
|
+
.map((v) => {
|
|
41
|
+
const ratio = (v - lo) / (hi - lo);
|
|
42
|
+
const index = Math.max(0, Math.min(glyphs.length - 1, Math.round(ratio * (glyphs.length - 1))));
|
|
43
|
+
return glyphs[index] as string;
|
|
44
|
+
})
|
|
45
|
+
.join(''),
|
|
46
|
+
fg: 'accent',
|
|
47
|
+
}))),
|
|
48
|
+
);
|
|
49
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BoxProps, SemanticVariant } from '@textui/core';
|
|
2
|
+
import { defineComponent, h } from '@textui/core';
|
|
3
|
+
import { VerticalBars, bounds } from './shared.js';
|
|
4
|
+
|
|
5
|
+
export interface HistogramProps extends BoxProps {
|
|
6
|
+
values: number[];
|
|
7
|
+
/** Number of buckets. */
|
|
8
|
+
buckets?: number;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
tone?: SemanticVariant;
|
|
12
|
+
chartHeight?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Histogram = defineComponent<HistogramProps>('Histogram', (props) => {
|
|
16
|
+
const { values, buckets = 12, min, max, tone = 'accent', chartHeight = 6, ...rest } = props;
|
|
17
|
+
const [lo, hi] = bounds(values, min, max);
|
|
18
|
+
|
|
19
|
+
const counts = new Array<number>(buckets).fill(0);
|
|
20
|
+
for (const value of values) {
|
|
21
|
+
const ratio = (value - lo) / (hi - lo);
|
|
22
|
+
const index = Math.max(0, Math.min(buckets - 1, Math.floor(ratio * buckets)));
|
|
23
|
+
counts[index] = (counts[index] as number) + 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return h(VerticalBars, {
|
|
27
|
+
data: counts.map((count, i) => ({
|
|
28
|
+
label: String(Math.round(lo + ((hi - lo) * i) / buckets)),
|
|
29
|
+
value: count,
|
|
30
|
+
tone,
|
|
31
|
+
})),
|
|
32
|
+
max: Math.max(1, ...counts),
|
|
33
|
+
height: chartHeight,
|
|
34
|
+
...rest,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ComponentDefinition } from '@textui/core';
|
|
2
|
+
import { AreaChart } from './area-chart.js';
|
|
3
|
+
import { BarChart } from './bar-chart.js';
|
|
4
|
+
import { Gauge } from './gauge.js';
|
|
5
|
+
import { Heatmap } from './heatmap.js';
|
|
6
|
+
import { Histogram } from './histogram.js';
|
|
7
|
+
import { LineChart } from './line-chart.js';
|
|
8
|
+
import { Sparkline } from './sparkline.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Charts.
|
|
12
|
+
*
|
|
13
|
+
* A terminal chart has one cell of resolution vertically and one horizontally,
|
|
14
|
+
* so the honest approach is to pick glyphs that subdivide a cell - eight block
|
|
15
|
+
* levels, four braille dots - rather than to pretend at pixel plotting. Every
|
|
16
|
+
* chart here also states its numbers, because a shape without a scale is
|
|
17
|
+
* decoration.
|
|
18
|
+
*/
|
|
19
|
+
export * from './area-chart.js';
|
|
20
|
+
export * from './bar-chart.js';
|
|
21
|
+
export * from './gauge.js';
|
|
22
|
+
export * from './heatmap.js';
|
|
23
|
+
export * from './histogram.js';
|
|
24
|
+
export * from './line-chart.js';
|
|
25
|
+
export * from './sparkline.js';
|
|
26
|
+
export type { LineChartProps, Series } from './shared.js';
|
|
27
|
+
|
|
28
|
+
export const CHART_COMPONENTS: ComponentDefinition[] = [
|
|
29
|
+
{ component: 'Sparkline', category: 'chart', renderer: { kind: 'function', render: Sparkline }, description: 'One row of block glyphs; eight levels per cell.' },
|
|
30
|
+
{ component: 'BarChart', category: 'chart', renderer: { kind: 'function', render: BarChart }, description: 'Labelled bars, horizontal or vertical.' },
|
|
31
|
+
{ component: 'LineChart', category: 'chart', renderer: { kind: 'function', render: LineChart }, description: 'Braille plot at 2x4 the cell resolution.' },
|
|
32
|
+
{ component: 'AreaChart', category: 'chart', renderer: { kind: 'function', render: AreaChart }, description: 'A line chart, filled.' },
|
|
33
|
+
{ component: 'Histogram', category: 'chart', renderer: { kind: 'function', render: Histogram }, description: 'Bucketed distribution.' },
|
|
34
|
+
{ component: 'Gauge', category: 'chart', renderer: { kind: 'function', render: Gauge }, role: 'meter', description: 'A reading against thresholds.' },
|
|
35
|
+
{ component: 'Heatmap', category: 'chart', renderer: { kind: 'function', render: Heatmap }, description: 'A grid of intensities.' },
|
|
36
|
+
];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PaintSurface, RenderContext } from '@textui/core';
|
|
2
|
+
import { defineComponent, fitTo, h, stringWidth, useTheme } from '@textui/core';
|
|
3
|
+
import type { LineChartProps } from './shared.js';
|
|
4
|
+
import { TONE, bounds, resample } from './shared.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A line chart on a braille canvas: each cell holds a 2x4 dot grid, so a
|
|
8
|
+
* 40x8 chart really has 80x32 plot positions.
|
|
9
|
+
*/
|
|
10
|
+
export const LineChart = defineComponent<LineChartProps>('LineChart', (props) => {
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
const {
|
|
13
|
+
series, min, max, chartWidth, chartHeight = 8,
|
|
14
|
+
axis = true, area = false, format, ...rest
|
|
15
|
+
} = props;
|
|
16
|
+
|
|
17
|
+
const all = series.flatMap((s) => s.values);
|
|
18
|
+
const [lo, hi] = bounds(all, min, max);
|
|
19
|
+
const braille = theme.glyphs.blocks.length > 0 && theme.glyphs.spinner[0] !== '|';
|
|
20
|
+
|
|
21
|
+
const draw = (surface: PaintSurface, ctx: RenderContext): void => {
|
|
22
|
+
const { width, height } = surface.rect;
|
|
23
|
+
if (width <= 0 || height <= 0) return;
|
|
24
|
+
|
|
25
|
+
for (const [index, s] of series.entries()) {
|
|
26
|
+
const color = ctx.color(TONE[s.tone ?? (index === 0 ? 'accent' : 'secondary')]);
|
|
27
|
+
const points = resample(s.values, braille ? width * 2 : width);
|
|
28
|
+
|
|
29
|
+
if (braille) {
|
|
30
|
+
// Accumulate dots per cell, then emit one braille glyph per cell.
|
|
31
|
+
const cells = new Map<string, number>();
|
|
32
|
+
for (let px = 0; px < points.length; px++) {
|
|
33
|
+
const value = points[px] as number;
|
|
34
|
+
const ratio = (value - lo) / (hi - lo);
|
|
35
|
+
const py = Math.round((1 - ratio) * (height * 4 - 1));
|
|
36
|
+
const startY = area ? py : py;
|
|
37
|
+
const endY = area ? height * 4 - 1 : py;
|
|
38
|
+
for (let y = startY; y <= endY; y++) {
|
|
39
|
+
const cx = Math.floor(px / 2);
|
|
40
|
+
const cy = Math.floor(y / 4);
|
|
41
|
+
const key = `${cx},${cy}`;
|
|
42
|
+
cells.set(key, (cells.get(key) ?? 0) | brailleBit(px % 2, y % 4));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const [key, bits] of cells) {
|
|
46
|
+
const [cx, cy] = key.split(',').map(Number) as [number, number];
|
|
47
|
+
surface.put(cx, cy, String.fromCharCode(0x2800 + bits), { fg: color });
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// No braille: fall back to block levels, one column per cell.
|
|
53
|
+
const blocks = theme.glyphs.blocks;
|
|
54
|
+
for (let x = 0; x < points.length && x < width; x++) {
|
|
55
|
+
const ratio = ((points[x] as number) - lo) / (hi - lo);
|
|
56
|
+
const y = Math.round((1 - ratio) * (height - 1));
|
|
57
|
+
const level = blocks[Math.max(0, Math.min(blocks.length - 1, Math.round(ratio * (blocks.length - 1))))] as string;
|
|
58
|
+
surface.put(x, y, level, { fg: color });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const chart = h('canvas', {
|
|
64
|
+
draw,
|
|
65
|
+
flex: 1,
|
|
66
|
+
height: chartHeight,
|
|
67
|
+
...(chartWidth !== undefined ? { width: chartWidth } : {}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (!axis) return h('box', { direction: 'column', ...rest }, chart);
|
|
71
|
+
|
|
72
|
+
const fmt = format ?? ((v: number): string => (Number.isInteger(v) ? String(v) : v.toFixed(1)));
|
|
73
|
+
const axisWidth = Math.max(stringWidth(fmt(hi)), stringWidth(fmt(lo)));
|
|
74
|
+
|
|
75
|
+
return h('box', { direction: 'column', ...rest },
|
|
76
|
+
h('box', { direction: 'row', gap: 1 },
|
|
77
|
+
h('box', { direction: 'column', width: axisWidth, height: chartHeight, justify: 'between' },
|
|
78
|
+
h('text', { content: fitTo(fmt(hi), axisWidth, 'right'), fg: 'subtle' }),
|
|
79
|
+
h('text', { content: fitTo(fmt(lo), axisWidth, 'right'), fg: 'subtle' })),
|
|
80
|
+
chart),
|
|
81
|
+
series.some((s) => s.label)
|
|
82
|
+
? h('box', { direction: 'row', gap: 2 },
|
|
83
|
+
...series.map((s, i) =>
|
|
84
|
+
h('box', { key: i, direction: 'row', gap: 1 },
|
|
85
|
+
h('text', { content: theme.glyphs.bulletFilled, fg: TONE[s.tone ?? (i === 0 ? 'accent' : 'secondary')] }),
|
|
86
|
+
h('text', { content: s.label ?? `series ${i + 1}`, fg: 'muted' }))))
|
|
87
|
+
: null,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
function brailleBit(x: number, y: number): number {
|
|
92
|
+
// Braille dot numbering is column-major and not contiguous; this is the map.
|
|
93
|
+
const MAP = [
|
|
94
|
+
[0x01, 0x08],
|
|
95
|
+
[0x02, 0x10],
|
|
96
|
+
[0x04, 0x20],
|
|
97
|
+
[0x40, 0x80],
|
|
98
|
+
];
|
|
99
|
+
return (MAP[y] as number[])[x] as number;
|
|
100
|
+
}
|