@x-tech-laboratories/x-app 0.132.0 → 0.133.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/README.md CHANGED
@@ -207,7 +207,7 @@ depends on the agent package alone.
207
207
  | `web/react/forms`, `unit_number`, `day`, `row_actions`, `lookup` | Small pieces lists share: `AddNameForm` adds a typed name from a toolbar, keeping it typed when adding failed, `RenameField` and `use_rename` rename in place (Enter or leaving saves, Escape gives up), `FormButtons` and `DialogButtons` are Save and Cancel; `UnitNumber` is a `NumberField` showing a stored value in the unit shown, such as kilograms as pounds, empty at 0 unless `show_zero`, bare or in a `FormRow` or `SettingRow`; `use_day` keeps a page's day, remembered for the tab's session under a key, with `DayStepper`; `row_actions_column` is a table's Edit, own buttons, History, trailing buttons and Delete column, each labelled with the row's name, and `confirm_delete` asks with a red Delete; `LookupPanel` searches an online source, listing results, each source's failure and an empty line, and hands the picked one over. |
208
208
  | `web/react/toasts`, `dialog`, `menus`, `split` | Toasts with a link or Undo that say how they closed, `undoable` actions that commit or undo exactly once, and `attempt`, which shows a failed call's words as a bad toast, with `attempt_value(work, done?)` giving the answer back (or undefined once the failure is shown), `succeeds(work, done?)` saying whether it went through, and `show_error`; modal dialogs with a subtitle, header actions, a full-window size and a `form` whose submit button sends it, and confirm and text dialogs, openable from anywhere; context menus and popovers worked by keyboard, openable from anywhere, their keep-open items ticking at once; resize handles and splits. `SettingsDialogRow` is a settings row with a name, a short status and an Open button whose dialog holds that group's settings. |
209
209
  | `web/react/page_view` | `PageView`: a full-window page over the app on the Dialog, such as Settings or an item's properties, with a Close button, actions beside it and section tabs that stay put while the body scrolls. |
210
- | `web/react/charts` | `LineChart` of readings over time as lines or dots, with dashed limits such as a goal, a scale from zero or fitted around the readings, and dots from a single reading; `moving_average` for its trend line; `BarChart`, naming each bar under it when asked, `StackedBarChart`, `Meters` with ticks and a lighter fill behind, `Donut` with its headline in the middle, `Timeline` of spans and instants per lane, `Sparkline` from zero or fitted to its readings, a pass/fail `Strip`, a `Gauge` ring beside a stat's value that can link like a `Tile`, a `DonutTile`, a stat tile drawn as a full ring with its value in the middle, a `ShareBar` with each part's value in its legend, and a `Treemap` of tiles sized by value on `squarify` that hands back the one clicked: small charts colored from Halon's tokens. |
210
+ | `web/react/charts` | `LineChart` of readings over time as lines or dots, with dashed limits such as a goal, a scale from zero or fitted around the readings, and dots from a single reading; `moving_average` for its trend line; `BarChart`, naming each bar under it when asked, `StackedBarChart`, `Meters` with ticks and a lighter fill behind, `Donut` with its headline in the middle, `Timeline` of spans and instants per lane, `Sparkline` from zero or fitted to its readings, a pass/fail `Strip`, a `Gauge` ring beside a stat's value that can link like a `Tile`, a `DonutTile`, a stat tile drawn as a full ring with its value in the middle, a `ShareBar` with each part's value in its legend, and a `Treemap` of tiles sized by value on `squarify` that hands back the one clicked: small charts colored from Halon's tokens. Line and bar charts lay out at the size they are shown at, so their text stays one size in any card, and inside `ChartFill` take the height of the box they sit in. |
211
211
  | `web/react/graph` | `GraphView`: a graph of nodes and links drawn by force, such as a knowledge graph: each node a shape and colour role by its `kind` (`GraphKind`: Halon's accent, a status or a `--series-*` token, read again when the theme changes), with an optional glyph and drawn faded when asked; each link solid or `dashed`, with an arrow when `directed` and a label shown near the selection or zoomed in. Selecting a node rings it and lights its neighbours; a click selects, a double-click opens (`on_activate`), a link click calls `on_link_select`; dragging pans, the wheel zooms, Fit, + and − in the toolbar beside the app's own `tools`; `focus_id` centres on a node, such as one a search found; a legend of kinds and link styles, an empty state, and every node with its links as a `Tree` under the drawing, so it is all reachable from the keyboard (arrow keys pan the drawing, + and − zoom, 0 fits, Enter opens the selection). On force-graph (MIT), loaded only when a graph is shown, which keeps a few thousand nodes moving on a canvas; X-App adds Halon's colours, the list, the keyboard path and selection. |
212
212
  | `web/react/flow_map` | `FlowMap`: how things flow across columns, such as folders through jobs to repositories or flakes through caches to hosts: boxes in columns, optionally inside group boxes such as a host, joined by curved lines colored by tone, each column ordered by where its lines come from; hovering or focusing a box lights everything upstream and downstream of it, dragging pans and Ctrl or ⌘ with the wheel zooms; `use_flow_map` keeps the zoom across a remount and `FlowMapZoom` draws the zoom and Fit buttons for a section heading. |
213
213
  | `web/react/progress` | `ProgressBar`: a bar with its value out of a max, busy while the amount of work is unknown, and words or the percentage beside it. |
@@ -12,7 +12,7 @@ import { define_bridge } from "../electron/bridge.js";
12
12
  import { define_events } from "../electron/events.js";
13
13
  import { local_mcp_method_names } from "../local_mcp_protocol.js";
14
14
  import { create_settings_store, read_setting, settings_of, write_setting } from "../settings.js";
15
- import { migrate } from "../sql.js";
15
+ import { in_transaction, migrate } from "../sql.js";
16
16
  import { create_sync_engine } from "../sync_engine.js";
17
17
  import { backup_method_names } from "../backups.js";
18
18
  import { peer_listening_method_names, sync_device_method_names } from "../sync_protocol.js";
@@ -113,15 +113,20 @@ export function define_app(options) {
113
113
  if (options.upgrade_layout?.needed(database))
114
114
  options.upgrade_layout.run(database);
115
115
  // Sync's and history's triggers name columns, so they come off while a step reshapes a table; install puts them back.
116
- sync_engine.drop_triggers(database);
117
- for (const history of histories)
118
- history.drop_triggers?.(database);
116
+ // Each group is one transaction: a commit per trigger made opening take seconds where every commit waits on the disk.
117
+ in_transaction(database, () => {
118
+ sync_engine.drop_triggers(database);
119
+ for (const history of histories)
120
+ history.drop_triggers?.(database);
121
+ });
119
122
  // Each feature keeps its own schema version, so features grow apart without renumbering each other's steps.
120
123
  for (const feature of features)
121
124
  migrate(database, feature.migrations, { owner: feature.id });
122
- for (const history of histories)
123
- history.install(database);
124
- sync_engine.install(database);
125
+ in_transaction(database, () => {
126
+ for (const history of histories)
127
+ history.install(database);
128
+ sync_engine.install(database);
129
+ });
125
130
  for (const feature of features)
126
131
  feature.on_open?.(database);
127
132
  // What opening changed, such as rows an upgrade moved, is kept as a change made on this device.
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from "react";
1
2
  export interface Series {
2
3
  label: string;
3
4
  color: string;
@@ -42,6 +43,9 @@ export interface Cell {
42
43
  ok: boolean | null;
43
44
  }
44
45
  type Legend = [label: string, color: string][];
46
+ export declare function ChartFill({ children }: {
47
+ children: ReactNode;
48
+ }): import("react").JSX.Element;
45
49
  interface LineChartProps {
46
50
  title: string;
47
51
  series: Series[];
@@ -1,10 +1,45 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const width = 600;
3
- const height = 160;
2
+ // Small SVG charts: lines or dots over time with a moving average, bars, meters, a donut, a timeline, sparklines, a pass/fail strip, a gauge ring, a donut tile, a share bar and a treemap, colored from Halon's tokens.
3
+ import { createContext, useContext, useLayoutEffect, useRef, useState } from "react";
4
+ // The size a line or bar chart lays out at before it is measured, and its height when it does not fill a box.
5
+ const default_width = 600;
6
+ const default_height = 160;
7
+ // The least height a chart filling a box takes, so a box with no height of its own does not squeeze it flat.
8
+ const least_fill_height = 120;
4
9
  const margin = { left: 64, right: 8, top: 8, bottom: 20 };
10
+ // Whether a chart fills the height of the box it sits in, such as a dashboard card, rather than keeping its own.
11
+ const ChartFillContext = createContext(false);
12
+ export function ChartFill({ children }) {
13
+ return _jsx(ChartFillContext.Provider, { value: true, children: children });
14
+ }
15
+ // The size a chart is drawn at on the page, so it lays out in the page's own pixels and its text stays the size the
16
+ // stylesheet gives it however wide or tall the chart is shown. Until measured, or where nothing can measure it, the
17
+ // default size.
18
+ function use_plot_size() {
19
+ const fill = useContext(ChartFillContext);
20
+ const plot = useRef(null);
21
+ const [size, set_size] = useState({ width: default_width, height: default_height });
22
+ useLayoutEffect(() => {
23
+ const svg = plot.current;
24
+ if (svg === null || typeof ResizeObserver === "undefined")
25
+ return;
26
+ const observer = new ResizeObserver(([entry]) => {
27
+ const box = entry?.contentRect;
28
+ if (box === undefined || box.width < 1)
29
+ return;
30
+ const width = Math.round(box.width);
31
+ const height = fill ? Math.max(least_fill_height, Math.round(box.height)) : default_height;
32
+ set_size((last) => (last.width === width && last.height === height ? last : { width, height }));
33
+ });
34
+ observer.observe(svg);
35
+ return () => observer.disconnect();
36
+ }, [fill]);
37
+ return [plot, size];
38
+ }
5
39
  // Readings over time, a line per series or a dot per reading, with a dashed line per limit such as a goal; dots alone
6
40
  // draw from a single reading, placed in the middle.
7
41
  export function LineChart({ title, series, format, limits = [], scale = "zero", format_time = local_date, empty_message = "Not enough history yet to draw a trend." }) {
42
+ const [plot, { width, height }] = use_plot_size();
8
43
  const readings = (line) => line.points.filter(([, value]) => value !== null);
9
44
  const points = series.flatMap(readings);
10
45
  // A line needs two readings at different times; dots need one.
@@ -18,7 +53,7 @@ export function LineChart({ title, series, format, limits = [], scale = "zero",
18
53
  const inner_width = width - margin.left - margin.right;
19
54
  const x = (epoch) => margin.left + (last === first ? inner_width / 2 : (epoch - first) / (last - first) * inner_width);
20
55
  const y = (value) => height - margin.bottom - (value - low) / (high - low) * (height - margin.top - margin.bottom);
21
- return (_jsx(Figure, { title: title, legend: [...series, ...limits].map((item) => [item.label, item.color]), children: _jsxs("svg", { viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": title, children: [_jsx(AxisLines, {}), _jsx(Tick, { x: margin.left - 6, y: y(ticks[1]), text: format(ticks[1]), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(ticks[0]), anchor: "end" }), _jsx(Tick, { x: margin.left, y: height - 4, text: format_time(first), anchor: "start" }), last > first && _jsx(Tick, { x: width - margin.right, y: height - 4, text: format_time(last), anchor: "end" }), limits.map((limit) => (_jsx("line", { x1: margin.left, y1: y(limit.value).toFixed(1), x2: width - margin.right, y2: y(limit.value).toFixed(1), stroke: limit.color, strokeWidth: 2, strokeDasharray: "6 4", children: _jsx("title", { children: `${limit.label}: ${format(limit.value)}` }) }, limit.label))), series.filter((line) => line.draw !== "dots").map((line) => {
56
+ return (_jsx(Figure, { title: title, legend: [...series, ...limits].map((item) => [item.label, item.color]), children: _jsxs("svg", { ref: plot, viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": title, children: [_jsx(AxisLines, { width: width, height: height }), _jsx(Tick, { x: margin.left - 6, y: y(ticks[1]), text: format(ticks[1]), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(ticks[0]), anchor: "end" }), _jsx(Tick, { x: margin.left, y: height - 4, text: format_time(first), anchor: "start" }), last > first && _jsx(Tick, { x: width - margin.right, y: height - 4, text: format_time(last), anchor: "end" }), limits.map((limit) => (_jsx("line", { x1: margin.left, y1: y(limit.value).toFixed(1), x2: width - margin.right, y2: y(limit.value).toFixed(1), stroke: limit.color, strokeWidth: 2, strokeDasharray: "6 4", children: _jsx("title", { children: `${limit.label}: ${format(limit.value)}` }) }, limit.label))), series.filter((line) => line.draw !== "dots").map((line) => {
22
57
  const path = readings(line).map(([epoch, value], index) => `${index === 0 ? "M" : "L"}${x(epoch).toFixed(1)},${y(value).toFixed(1)}`).join("");
23
58
  return _jsx("path", { d: path, fill: "none", stroke: line.color, strokeWidth: 2, children: _jsx("title", { children: line.label }) }, line.label);
24
59
  }), series.filter((line) => line.draw === "dots").map((line) => (_jsx("g", { fill: line.color, children: readings(line).map(([epoch, value], index) => (_jsx("circle", { cx: x(epoch).toFixed(1), cy: y(value).toFixed(1), r: 3.5, children: _jsx("title", { children: `${format_time(epoch)}: ${format(value)}` }) }, index))) }, line.label)))] }) }));
@@ -55,16 +90,18 @@ export function fitted_label(label, room) {
55
90
  return label.length <= letters ? label : `${label.slice(0, Math.max(1, letters - 1))}…`;
56
91
  }
57
92
  export function BarChart({ title, bars, format, labels = false }) {
93
+ const [plot, { width, height }] = use_plot_size();
58
94
  if (bars.length === 0)
59
95
  return _jsx(EmptyChart, { title: title, message: "Nothing to show yet." });
60
96
  const top = Math.max(...bars.map((bar) => bar.value)) || 1;
61
97
  const slot = (width - margin.left - margin.right) / bars.length;
62
98
  const y = (value) => height - margin.bottom - value / top * (height - margin.top - margin.bottom);
63
99
  const named = labels && slot >= narrowest_named_bar;
64
- return (_jsx(Figure, { title: title, legend: [], children: _jsxs("svg", { viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": title, children: [_jsx(AxisLines, {}), _jsx(Tick, { x: margin.left - 6, y: y(top), text: format(top), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(0), anchor: "end" }), named && bars.map((bar, index) => _jsx(Tick, { x: margin.left + (index + 0.5) * slot, y: height - 4, text: fitted_label(bar.label, slot - 4), anchor: "middle" }, index)), labels && !named && _jsx(Tick, { x: margin.left, y: height - 4, text: bars[0].label, anchor: "start" }), labels && !named && bars.length > 1 && _jsx(Tick, { x: width - margin.right, y: height - 4, text: bars[bars.length - 1].label, anchor: "end" }), bars.map((bar, index) => (_jsx("rect", { x: (margin.left + index * slot + slot * 0.15).toFixed(1), y: y(bar.value).toFixed(1), width: Math.max(1, slot * 0.7).toFixed(1), height: Math.max(1, height - margin.bottom - y(bar.value)).toFixed(1), fill: bar.color, children: _jsx("title", { children: `${bar.label}: ${format(bar.value)}` }) }, index)))] }) }));
100
+ return (_jsx(Figure, { title: title, legend: [], children: _jsxs("svg", { ref: plot, viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": title, children: [_jsx(AxisLines, { width: width, height: height }), _jsx(Tick, { x: margin.left - 6, y: y(top), text: format(top), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(0), anchor: "end" }), named && bars.map((bar, index) => _jsx(Tick, { x: margin.left + (index + 0.5) * slot, y: height - 4, text: fitted_label(bar.label, slot - 4), anchor: "middle" }, index)), labels && !named && _jsx(Tick, { x: margin.left, y: height - 4, text: bars[0].label, anchor: "start" }), labels && !named && bars.length > 1 && _jsx(Tick, { x: width - margin.right, y: height - 4, text: bars[bars.length - 1].label, anchor: "end" }), bars.map((bar, index) => (_jsx("rect", { x: (margin.left + index * slot + slot * 0.15).toFixed(1), y: y(bar.value).toFixed(1), width: Math.max(1, slot * 0.7).toFixed(1), height: Math.max(1, height - margin.bottom - y(bar.value)).toFixed(1), fill: bar.color, children: _jsx("title", { children: `${bar.label}: ${format(bar.value)}` }) }, index)))] }) }));
65
101
  }
66
102
  // One bar per bucket, its parts stacked in order, such as the runs of each hour by outcome.
67
103
  export function StackedBarChart({ title, stacks, legend, format }) {
104
+ const [plot, { width, height }] = use_plot_size();
68
105
  const totals = stacks.map((stack) => stack.parts.reduce((sum, part) => sum + part.value, 0));
69
106
  if (totals.every((total) => total === 0))
70
107
  return _jsx(EmptyChart, { title: title, message: "Nothing ran in this period." });
@@ -79,7 +116,7 @@ export function StackedBarChart({ title, stacks, legend, format }) {
79
116
  return (_jsx("rect", { x: (margin.left + index * slot + slot * 0.15).toFixed(1), y: base.toFixed(1), width: Math.max(1, slot * 0.7).toFixed(1), height: Math.max(1, tall).toFixed(1), fill: part.color, children: _jsx("title", { children: `${stack.label}: ${format(part.value)} ${part.label}` }) }, `${index}-${part.label}`));
80
117
  });
81
118
  });
82
- return (_jsx(Figure, { title: title, legend: legend, children: _jsxs("svg", { viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": `${title}, ${format(totals.reduce((sum, total) => sum + total, 0))} in all`, children: [_jsx(AxisLines, {}), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom - scale(top), text: format(top), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(0), anchor: "end" }), _jsx(Tick, { x: margin.left, y: height - 4, text: stacks[0].label, anchor: "start" }), _jsx(Tick, { x: width - margin.right, y: height - 4, text: stacks[stacks.length - 1].label, anchor: "end" }), rects] }) }));
119
+ return (_jsx(Figure, { title: title, legend: legend, children: _jsxs("svg", { ref: plot, viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": `${title}, ${format(totals.reduce((sum, total) => sum + total, 0))} in all`, children: [_jsx(AxisLines, { width: width, height: height }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom - scale(top), text: format(top), anchor: "end" }), _jsx(Tick, { x: margin.left - 6, y: height - margin.bottom, text: format(0), anchor: "end" }), _jsx(Tick, { x: margin.left, y: height - 4, text: stacks[0].label, anchor: "start" }), _jsx(Tick, { x: width - margin.right, y: height - 4, text: stacks[stacks.length - 1].label, anchor: "end" }), rects] }) }));
83
120
  }
84
121
  // ── Meters ───────────────────────────────────────────────────────────────────
85
122
  // One labeled bar per row with its value beside the label, such as the time since each repository's last backup.
@@ -260,7 +297,7 @@ function Figure({ title, legend, children }) {
260
297
  function EmptyChart({ title, message }) {
261
298
  return _jsxs("figure", { className: "chart", children: [_jsx("figcaption", { children: title }), _jsx("p", { className: "muted", children: message })] });
262
299
  }
263
- function AxisLines() {
300
+ function AxisLines({ width, height }) {
264
301
  return (_jsxs(_Fragment, { children: [_jsx("line", { x1: margin.left, y1: margin.top, x2: margin.left, y2: height - margin.bottom, className: "axis" }), _jsx("line", { x1: margin.left, y1: height - margin.bottom, x2: width - margin.right, y2: height - margin.bottom, className: "axis" })] }));
265
302
  }
266
303
  function Tick({ x, y, text, anchor }) {
@@ -10,7 +10,7 @@ import { ErrorBoundary } from "react-error-boundary";
10
10
  import { card_problem, condition_ops, field_of_set, fitting_views, flat_filter, filter_of, known_values, measure_fields, new_chart_card, new_condition, offered_measures, op_takes_value, periods_needed, run_card, settle_card, since_of, time_buckets, } from "../../dashboard.js";
11
11
  import { format_count } from "../format.js";
12
12
  import { CardGrid, place_cards } from "./card_grid.js";
13
- import { BarChart, Donut, LineChart, Meters, StackedBarChart, Treemap } from "./charts.js";
13
+ import { BarChart, ChartFill, Donut, LineChart, Meters, StackedBarChart, Treemap } from "./charts.js";
14
14
  import { NumberField, Segmented, Select, Switch } from "./controls.js";
15
15
  import { confirm_dialog, Dialog, open_dialog } from "./dialog.js";
16
16
  import { AddIcon, Icon } from "./icons.js";
@@ -404,5 +404,5 @@ function PreviewCard({ card, data_set }) {
404
404
  return (_jsx(CardFrame, { title: title, items: null, children: _jsx(ErrorBoundary, { resetKeys: [card, data.data], fallbackRender: ({ error, resetErrorBoundary }) => _jsx(Failure, { error: error, retry: resetErrorBoundary }), children: data.status === "failed" ? _jsx(Failure, { error: data.error, retry: () => void data.reload() })
405
405
  : data.data === null ? _jsx(Skeleton, {})
406
406
  : card_problem(card, data_set) !== null ? _jsx("p", { className: "muted", children: card_problem(card, data_set) })
407
- : _jsx(ChartView, { card: card, data_set: data_set, rows: data.data.rows, now: data.data.now }) }) }));
407
+ : _jsx(ChartFill, { children: _jsx(ChartView, { card: card, data_set: data_set, rows: data.data.rows, now: data.data.now }) }) }) }));
408
408
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-app",
3
- "version": "0.132.0",
3
+ "version": "0.133.0",
4
4
  "description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {