derive-dashboards 0.1.1 → 0.2.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.
Files changed (167) hide show
  1. package/README.md +5 -3
  2. package/dist/cli/add.mjs +130 -0
  3. package/dist/cli/cli.mjs +14 -12
  4. package/dist/cli/config.mjs +12 -1
  5. package/dist/cli/doctor.mjs +147 -0
  6. package/dist/cli/init.mjs +3 -2
  7. package/dist/cli/json.mjs +21 -0
  8. package/dist/cli/layers.mjs +33 -0
  9. package/dist/core/document/layout.mjs +1 -1
  10. package/dist/core/document/view-layout.d.mts +14 -0
  11. package/dist/core/document/view-layout.mjs +157 -0
  12. package/dist/core/engine/filter.mjs +2 -2
  13. package/dist/core/engine/leaf.mjs +9 -4
  14. package/dist/core/engine/members.mjs +1 -1
  15. package/dist/core/engine/version.d.mts +1 -1
  16. package/dist/core/engine/version.mjs +1 -1
  17. package/dist/core/error/codes.d.mts +2 -1
  18. package/dist/core/error/codes.mjs +2 -1
  19. package/dist/core/index.d.mts +5 -3
  20. package/dist/core/index.mjs +5 -3
  21. package/dist/core/model/member.mjs +5 -2
  22. package/dist/core/model/types.d.mts +13 -13
  23. package/dist/core/model/validate/members.mjs +7 -4
  24. package/dist/core/policy/bind-query.d.mts +12 -0
  25. package/dist/core/policy/bind-query.mjs +53 -0
  26. package/dist/core/query/filter.d.mts +6 -0
  27. package/dist/core/query/picks.d.mts +8 -2
  28. package/dist/core/query/picks.mjs +11 -4
  29. package/dist/core/query/segments.mjs +2 -1
  30. package/dist/core/result/columns.mjs +6 -3
  31. package/dist/core/schema/aliases.d.mts +7 -0
  32. package/dist/core/schema/aliases.mjs +77 -0
  33. package/dist/core/schema/answers.d.mts +1 -0
  34. package/dist/core/schema/answers.mjs +1 -0
  35. package/dist/core/schema/index.d.mts +3 -2
  36. package/dist/core/schema/index.mjs +3 -2
  37. package/dist/core/schema/query.d.mts +81 -0
  38. package/dist/core/schema/query.mjs +9 -5
  39. package/dist/core/types/api.d.mts +7 -1
  40. package/dist/core/types/api.mjs +1 -1
  41. package/dist/dashboards.mjs +4 -0
  42. package/dist/editing.mjs +2 -2
  43. package/dist/endpoints/dashboards.mjs +17 -2
  44. package/dist/endpoints/index.d.mts +12 -2
  45. package/dist/endpoints/meta.mjs +10 -1
  46. package/dist/execute.mjs +20 -11
  47. package/dist/handler.mjs +5 -1
  48. package/dist/llms.txt +22 -0
  49. package/dist/mcp/format.mjs +42 -8
  50. package/dist/mcp/query.mjs +34 -4
  51. package/dist/postgres-store.mjs +1 -0
  52. package/dist/react/Canvas.mjs +28 -5
  53. package/dist/react/Cell.mjs +2 -1
  54. package/dist/react/Dashboard.mjs +15 -3
  55. package/dist/react/DashboardList.mjs +22 -22
  56. package/dist/react/DashboardListRow.mjs +49 -0
  57. package/dist/react/Discard.mjs +5 -2
  58. package/dist/react/Editing.mjs +19 -5
  59. package/dist/react/FilterBar.d.mts +7 -9
  60. package/dist/react/Grid.mjs +7 -19
  61. package/dist/react/Header.mjs +1 -1
  62. package/dist/react/History.mjs +5 -0
  63. package/dist/react/ReadFailed.mjs +23 -0
  64. package/dist/react/Spaces.mjs +15 -1
  65. package/dist/react/Tile.d.mts +2 -0
  66. package/dist/react/Tile.mjs +35 -7
  67. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  68. package/dist/react/arrange-steps.mjs +16 -13
  69. package/dist/react/arrange.mjs +10 -3
  70. package/dist/react/builder/Calcs.mjs +35 -11
  71. package/dist/react/builder/FilterEditor.mjs +196 -0
  72. package/dist/react/builder/Filters.mjs +172 -116
  73. package/dist/react/builder/Formula.mjs +82 -0
  74. package/dist/react/builder/Groups.mjs +1 -0
  75. package/dist/react/builder/Preview.mjs +1 -1
  76. package/dist/react/builder/RangeEditor.mjs +184 -0
  77. package/dist/react/builder/Sections.mjs +41 -6
  78. package/dist/react/builder/Time.mjs +138 -60
  79. package/dist/react/builder/Values.mjs +85 -0
  80. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  81. package/dist/react/builder/base.d.mts +5 -0
  82. package/dist/react/builder/base.mjs +33 -8
  83. package/dist/react/builder/calc.mjs +15 -1
  84. package/dist/react/builder/escape.d.mts +1 -0
  85. package/dist/react/builder/escape.mjs +62 -0
  86. package/dist/react/builder/filter-tree.d.mts +9 -0
  87. package/dist/react/builder/filter-tree.mjs +186 -0
  88. package/dist/react/builder/formula-parse.d.mts +18 -0
  89. package/dist/react/builder/formula-parse.mjs +136 -0
  90. package/dist/react/builder/labels.d.mts +1 -1
  91. package/dist/react/builder/state.d.mts +2 -1
  92. package/dist/react/builder/state.mjs +23 -37
  93. package/dist/react/builder/useBuilder.d.mts +12 -1
  94. package/dist/react/builder/useBuilder.mjs +6 -3
  95. package/dist/react/builder/words.d.mts +59 -0
  96. package/dist/react/builder/words.mjs +73 -0
  97. package/dist/react/context.d.mts +13 -0
  98. package/dist/react/context.mjs +9 -3
  99. package/dist/react/drill/useDrill.d.mts +1 -1
  100. package/dist/react/drill/words.d.mts +3 -0
  101. package/dist/react/drill/words.mjs +2 -0
  102. package/dist/react/english.mjs +20 -5
  103. package/dist/react/filters/bar.d.mts +12 -0
  104. package/dist/react/filters/bar.mjs +135 -0
  105. package/dist/react/filters/calendar.mjs +193 -0
  106. package/dist/react/filters/chip.mjs +174 -0
  107. package/dist/react/filters/context.d.mts +22 -0
  108. package/dist/react/filters/context.mjs +78 -0
  109. package/dist/react/filters/dates.mjs +89 -0
  110. package/dist/react/filters/days.d.mts +36 -0
  111. package/dist/react/filters/days.mjs +87 -0
  112. package/dist/react/filters/field-step.mjs +81 -0
  113. package/dist/react/filters/hooks.d.mts +34 -0
  114. package/dist/react/filters/hooks.mjs +94 -0
  115. package/dist/react/filters/listbox.mjs +131 -0
  116. package/dist/react/filters/logic.d.mts +59 -0
  117. package/dist/react/filters/logic.mjs +109 -0
  118. package/dist/react/filters/menu-search.mjs +211 -0
  119. package/dist/react/filters/menu.mjs +85 -0
  120. package/dist/react/filters/number.mjs +127 -0
  121. package/dist/react/filters/numbers.d.mts +47 -0
  122. package/dist/react/filters/numbers.mjs +151 -0
  123. package/dist/react/filters/operator.mjs +104 -0
  124. package/dist/react/filters/phone.mjs +104 -0
  125. package/dist/react/filters/popover.d.mts +19 -0
  126. package/dist/react/filters/popover.mjs +153 -0
  127. package/dist/react/filters/rules.d.mts +8 -0
  128. package/dist/react/filters/rules.mjs +55 -0
  129. package/dist/react/filters/sheet.mjs +196 -0
  130. package/dist/react/filters/state.mjs +132 -0
  131. package/dist/react/filters/suggest.d.mts +47 -0
  132. package/dist/react/filters/suggest.mjs +97 -0
  133. package/dist/react/filters/values.mjs +166 -0
  134. package/dist/react/filters/words.d.mts +81 -0
  135. package/dist/react/filters/words.mjs +73 -0
  136. package/dist/react/format.mjs +11 -4
  137. package/dist/react/index.d.mts +11 -5
  138. package/dist/react/index.mjs +8 -4
  139. package/dist/react/messages.d.mts +34 -2
  140. package/dist/react/place.mjs +7 -3
  141. package/dist/react/renderers/index.mjs +65 -3
  142. package/dist/react/renderers/list.mjs +6 -6
  143. package/dist/react/series.d.mts +25 -8
  144. package/dist/react/series.mjs +135 -39
  145. package/dist/react/theme.css +930 -19
  146. package/dist/react/useBoard.d.mts +2 -0
  147. package/dist/react/useDashboard.d.mts +3 -0
  148. package/dist/react/useDashboard.mjs +6 -0
  149. package/dist/react/view-grid.mjs +16 -0
  150. package/dist/recharts/axes.mjs +28 -0
  151. package/dist/recharts/axis.mjs +84 -0
  152. package/dist/recharts/bar.d.mts +7 -0
  153. package/dist/recharts/bar.mjs +140 -0
  154. package/dist/recharts/charts.d.mts +4 -5
  155. package/dist/recharts/charts.mjs +2 -208
  156. package/dist/recharts/index.d.mts +3 -1
  157. package/dist/recharts/index.mjs +4 -1
  158. package/dist/recharts/line.d.mts +2 -0
  159. package/dist/recharts/line.mjs +111 -0
  160. package/dist/recharts/marks.mjs +47 -18
  161. package/dist/recharts/parts.mjs +88 -0
  162. package/dist/recharts/table.mjs +71 -0
  163. package/dist/records-read.mjs +1 -1
  164. package/dist/registry/filter-bar.json +26 -0
  165. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  166. package/package.json +6 -2
  167. package/dist/react/FilterBar.mjs +0 -119
@@ -15,15 +15,24 @@ function focusOpener(widgetId) {
15
15
  });
16
16
  }
17
17
  /** The dashboard could not be read and there is nothing to show: say so, and offer to try again. */
18
- function LoadFailed({ onRetry }) {
18
+ function LoadFailed({ onRetry, failure }) {
19
19
  const { messages } = useDashboards();
20
+ const refused = failure !== void 0 && failure.status >= 400 && failure.status < 500;
20
21
  return /* @__PURE__ */ jsxs("div", {
21
22
  className: "dd-tile-error",
22
23
  role: "alert",
23
24
  children: [
24
25
  messages.dashboardFailed,
25
26
  " ",
26
- /* @__PURE__ */ jsx("button", {
27
+ refused ? /* @__PURE__ */ jsxs("span", {
28
+ className: "dd-tile-note",
29
+ children: [
30
+ failure.message,
31
+ " (",
32
+ failure.code,
33
+ ")"
34
+ ]
35
+ }) : /* @__PURE__ */ jsx("button", {
27
36
  type: "button",
28
37
  className: "dd-button dd-quiet",
29
38
  onClick: onRetry,
@@ -51,7 +60,10 @@ function Dashboard(props) {
51
60
  className: "dd-tile-state",
52
61
  children: messages.dashboardMissing
53
62
  });
54
- if (error) return /* @__PURE__ */ jsx(LoadFailed, { onRetry: board.refresh });
63
+ if (error) return /* @__PURE__ */ jsx(LoadFailed, {
64
+ onRetry: board.refresh,
65
+ failure: board.failure
66
+ });
55
67
  if (shown?.tab === void 0) return /* @__PURE__ */ jsx("div", {
56
68
  className: "dd-dashboard",
57
69
  "aria-busy": "true"
@@ -1,4 +1,5 @@
1
1
  import { useDashboards } from "./context.mjs";
2
+ import { Row } from "./DashboardListRow.mjs";
2
3
  import { useId, useState } from "react";
3
4
  import useSWR from "swr";
4
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -73,32 +74,31 @@ function Search(props) {
73
74
  }) : null] });
74
75
  }
75
76
  /**
76
- * The dashboards, each a button named for the dashboard that opens it; the viewer's unpublished
77
- * ones say so, as the button's description rather than its name.
77
+ * The dashboards, each named for itself, its description and Draft as its description rather
78
+ * than its name. With `linkFor` each is a link and a published one has Copy link beside it.
78
79
  */
79
80
  function Items({ items, current, onOpen, linkFor }) {
80
81
  const { messages } = useDashboards();
81
82
  const base = useId();
82
- return /* @__PURE__ */ jsx("ul", { children: items.map((d, i) => /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs("button", {
83
- type: "button",
84
- "aria-label": d.title,
85
- "aria-describedby": d.unpublished === true ? `${base}-${String(i)}` : void 0,
86
- "aria-current": d.id === current ? "page" : void 0,
87
- onClick: () => {
88
- onOpen(d.id);
89
- },
90
- children: [/* @__PURE__ */ jsx("span", {
91
- className: "dd-list-name",
92
- children: d.title
93
- }), d.unpublished === true ? /* @__PURE__ */ jsx("em", {
83
+ return /* @__PURE__ */ jsx("ul", { children: items.map((d, i) => /* @__PURE__ */ jsxs("li", { children: [
84
+ /* @__PURE__ */ jsx(Row, {
85
+ d,
86
+ href: linkFor?.(d.id),
87
+ current: d.id === current,
88
+ describedBy: `${base}-${String(i)}`,
89
+ onOpen
90
+ }),
91
+ /* @__PURE__ */ jsx("span", {
92
+ hidden: true,
94
93
  id: `${base}-${String(i)}`,
95
- children: messages.unpublished
96
- }) : null]
97
- }), linkFor === void 0 || d.unpublished === true ? null : /* @__PURE__ */ jsx(CopyLink, {
98
- id: d.id,
99
- title: d.title,
100
- linkFor
101
- })] }, d.id)) });
94
+ children: [d.unpublished === true ? messages.unpublished : void 0, d.description].filter((part) => part !== void 0).join(". ")
95
+ }),
96
+ linkFor === void 0 || d.unpublished === true ? null : /* @__PURE__ */ jsx(CopyLink, {
97
+ id: d.id,
98
+ title: d.title,
99
+ linkFor
100
+ })
101
+ ] }, d.id)) });
102
102
  }
103
103
  /**
104
104
  * The built-in dashboards (`default:` ids) first, under a heading, then the ones made here, when
@@ -140,7 +140,7 @@ function DashboardList({ current, onOpen, linkFor }) {
140
140
  const [search, setSearch] = useState("");
141
141
  const all = list.data?.dashboards ?? [];
142
142
  const words = search.trim().toLocaleLowerCase();
143
- const shown = words === "" ? all : all.filter((d) => d.title.toLocaleLowerCase().includes(words));
143
+ const shown = words === "" ? all : all.filter((d) => `${d.title} ${d.description ?? ""}`.toLocaleLowerCase().includes(words));
144
144
  const { making, error, create } = useCreate(onOpen, async () => {
145
145
  await list.mutate();
146
146
  });
@@ -0,0 +1,49 @@
1
+ import { useDashboards } from "./context.mjs";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ // src/DashboardListRow.tsx
4
+ /** A click a link would follow itself: a modified or middle click opens a new tab as usual. */
5
+ const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
6
+ /**
7
+ * One row: the dashboard's name, Draft for the viewer's unpublished one, and its description.
8
+ * With `href` it is a link, so Cmd-click and middle-click open a new tab while a plain click
9
+ * still goes to `onOpen`; without one it is a button. Draft and the description describe the
10
+ * row; its name stays the dashboard's.
11
+ */
12
+ function Row(props) {
13
+ const { d, href, describedBy, onOpen } = props;
14
+ const { messages } = useDashboards();
15
+ const shared = {
16
+ className: "dd-list-open",
17
+ "aria-label": d.title,
18
+ "aria-describedby": d.unpublished === true || d.description !== void 0 ? describedBy : void 0,
19
+ "aria-current": props.current ? "page" : void 0
20
+ };
21
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("span", {
22
+ className: "dd-list-name",
23
+ children: [/* @__PURE__ */ jsx("span", {
24
+ className: "dd-list-title",
25
+ children: d.title
26
+ }), d.unpublished === true ? /* @__PURE__ */ jsx("em", { children: messages.unpublished }) : null]
27
+ }), d.description === void 0 ? null : /* @__PURE__ */ jsx("span", {
28
+ className: "dd-list-desc",
29
+ children: d.description
30
+ })] });
31
+ return href === void 0 ? /* @__PURE__ */ jsx("button", {
32
+ type: "button",
33
+ ...shared,
34
+ onClick: () => {
35
+ onOpen(d.id);
36
+ },
37
+ children: body
38
+ }) : /* @__PURE__ */ jsx("a", {
39
+ href,
40
+ ...shared,
41
+ onClick: (event) => {
42
+ if (event.defaultPrevented || !plainClick(event)) return;
43
+ event.preventDefault();
44
+ onOpen(d.id);
45
+ },
46
+ children: body
47
+ });
48
+ }
49
+ export { Row };
@@ -21,15 +21,18 @@ function DiscardButton({ edit, isNew = false }) {
21
21
  answered.current = !on;
22
22
  setAsking(on);
23
23
  };
24
+ const untouched = !isNew && (edit.draft?.changes.filter((c) => !isShifted(c)).length ?? 0) === 0;
24
25
  if (!asking) return /* @__PURE__ */ jsx("button", {
25
26
  ref: discard,
26
27
  type: "button",
27
28
  className: "dd-button dd-quiet",
28
29
  "aria-disabled": edit.busy,
29
30
  onClick: () => {
30
- if (!edit.busy) ask(true);
31
+ if (edit.busy) return;
32
+ if (untouched) edit.discard();
33
+ else ask(true);
31
34
  },
32
- children: messages.discard
35
+ children: untouched ? messages.doneEditing : messages.discard
33
36
  });
34
37
  return /* @__PURE__ */ jsx(DiscardAsk, {
35
38
  edit,
@@ -81,14 +81,14 @@ function saveCommands(doc, tab, widget, widgetId) {
81
81
  at: placeFor(tab, widget)
82
82
  }];
83
83
  const before = doc.widgets[widgetId];
84
- const query = widget.queries["main"];
84
+ const query = widget.queries.main;
85
85
  return [{
86
86
  type: "widget.update",
87
87
  id: widgetId,
88
88
  title: widget.title,
89
89
  kind: widget.kind,
90
90
  ...widget.display === void 0 ? {} : { display: widget.display }
91
- }, ...query === void 0 || before?.queries["main"] === query ? [] : [{
91
+ }, ...query === void 0 || before?.queries.main === query ? [] : [{
92
92
  type: "widget.setQuery",
93
93
  id: widgetId,
94
94
  name: "main",
@@ -103,6 +103,22 @@ function BuildPage({ doc, tab, edit, widgetId, onDone }) {
103
103
  const { messages } = useDashboards();
104
104
  const [id] = useState(() => widgetId ?? `w${crypto.randomUUID().slice(0, 8)}`);
105
105
  const initial = widgetId === void 0 ? void 0 : doc.widgets[widgetId];
106
+ const cancel = () => {
107
+ onDone();
108
+ };
109
+ if (initial !== void 0 && initial.queries["main"] === void 0) return /* @__PURE__ */ jsxs("div", {
110
+ className: "dd-builder",
111
+ children: [/* @__PURE__ */ jsxs("button", {
112
+ type: "button",
113
+ className: "dd-back",
114
+ onClick: cancel,
115
+ children: ["‹ ", doc.meta.title]
116
+ }), /* @__PURE__ */ jsx("p", {
117
+ className: "dd-builder-error",
118
+ role: "alert",
119
+ children: messages.noMainQuery(initial.title)
120
+ })]
121
+ });
106
122
  return /* @__PURE__ */ jsx(WidgetBuilder, {
107
123
  ...initial === void 0 ? {} : { initial },
108
124
  backLabel: doc.meta.title,
@@ -110,9 +126,7 @@ function BuildPage({ doc, tab, edit, widgetId, onDone }) {
110
126
  saveLabel: widgetId === void 0 ? messages.addToDashboard : messages.save,
111
127
  saving: edit.busy,
112
128
  ...edit.error === void 0 ? {} : { error: edit.error },
113
- onCancel: () => {
114
- onDone();
115
- },
129
+ onCancel: cancel,
116
130
  onSave: (widget) => {
117
131
  const save = async () => {
118
132
  if (await edit.apply(saveCommands(doc, tab, widget, id))) onDone(id);
@@ -1,9 +1,7 @@
1
- import { Control, Picks } from "derive-dashboards/core";
2
- type Props = {
3
- controls: readonly Control[];
4
- picks: Picks;
5
- onChange: (picks: Picks) => void;
6
- };
7
- /** The dashboard's controls as toggles. A viewer's choices are picks; the server checks each one. */
8
- export declare function FilterBar({ controls, picks, onChange }: Props): import("react").JSX.Element | null;
9
- export {};
1
+ import { ENGLISH_FILTERS, FilterWords } from "./filters/words.mjs";
2
+ import { FilterBar } from "./filters/bar.mjs";
3
+ import { FilterBarOptions, FilterIcon } from "./filters/context.mjs";
4
+ import { FilterBarProps, fieldOf, useControlValues, useFilterFields } from "./filters/hooks.mjs";
5
+ import { Popover } from "./filters/popover.mjs";
6
+ import { rules_d_exports } from "./filters/rules.mjs";
7
+ export { ENGLISH_FILTERS, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, Popover, fieldOf, rules_d_exports as filterRules, useControlValues, useFilterFields };
@@ -1,31 +1,17 @@
1
1
  import { useArrange } from "./arrange.mjs";
2
2
  import { Cell as Cell$1 } from "./Cell.mjs";
3
3
  import { useDashboards } from "./context.mjs";
4
- import { placeOf } from "./place.mjs";
5
- import { Spaces } from "./Spaces.mjs";
4
+ import { Drop, Spaces } from "./Spaces.mjs";
6
5
  import { useSameWidgets, useStable } from "./stable.mjs";
6
+ import { useViewGrid } from "./view-grid.mjs";
7
7
  import { useMemo, useRef } from "react";
8
8
  import { readingOrder, stepCommands } from "derive-dashboards/core";
9
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
10
  // src/Grid.tsx
11
11
  /** Each filter control's label by id, made once per set of controls rather than per tile. */
12
12
  function useControlLabels(controls) {
13
13
  return useMemo(() => new Map(controls.map((c) => [c.id, c.label])), [controls]);
14
14
  }
15
- /**
16
- * The outline where a dragged tile will land, and where one moved by the keyboard is now, said
17
- * to a screen reader (`arrange` writes it).
18
- */
19
- function Drop({ at }) {
20
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
21
- className: "dd-placed dd-sr",
22
- role: "status"
23
- }), at === void 0 ? null : /* @__PURE__ */ jsx("div", {
24
- className: "dd-drop",
25
- "aria-hidden": "true",
26
- style: placeOf(at)
27
- })] });
28
- }
29
15
  /** Focuses the first of `selectors` that matches in a widget's cell, once it is drawn. */
30
16
  function focusIn(widget, ...selectors) {
31
17
  requestAnimationFrame(() => {
@@ -99,7 +85,8 @@ function Grid(props) {
99
85
  const widgets = useSameWidgets(doc.widgets);
100
86
  const { onEdit, onRemove, onStep } = useTileCalls(edit, props);
101
87
  const editing = edit.draft !== void 0 && arrangeable;
102
- const cells = useReadingOrder(props.tab.layout, arrange.layout);
88
+ const view = useViewGrid(props.tab.layout, widgets, props.results);
89
+ const cells = useReadingOrder(props.tab.layout, editing ? arrange.layout : view.layout);
103
90
  return /* @__PURE__ */ jsxs("div", {
104
91
  ref: arrange.gridRef,
105
92
  className: "dd-grid",
@@ -131,7 +118,8 @@ function Grid(props) {
131
118
  onRemove,
132
119
  onStep,
133
120
  first: cells[0]?.widget === item.widget,
134
- last: cells.at(-1)?.widget === item.widget
121
+ last: cells.at(-1)?.widget === item.widget,
122
+ sharedSpan: view.sharedSpan
135
123
  }, item.widget);
136
124
  })
137
125
  ]
@@ -91,7 +91,7 @@ function Header(props) {
91
91
  }), /* @__PURE__ */ jsxs("div", {
92
92
  className: "dd-header-actions",
93
93
  children: [
94
- props.unpublished === true ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
94
+ props.unpublished === true || editing ? null : /* @__PURE__ */ jsx(ShareButton, { link: props.link }),
95
95
  editing || version === 0 ? null : /* @__PURE__ */ jsx("button", {
96
96
  type: "button",
97
97
  className: "dd-button dd-quiet",
@@ -3,6 +3,7 @@ import { useDashboards } from "./context.mjs";
3
3
  import { LIST_KEY } from "./DashboardList.mjs";
4
4
  import { formatInstant } from "./format.mjs";
5
5
  import { Panel } from "./Panel.mjs";
6
+ import { ReadFailed } from "./ReadFailed.mjs";
6
7
  import { useState } from "react";
7
8
  import { useSWRConfig } from "swr";
8
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -82,6 +83,10 @@ function HistoryPanel(props) {
82
83
  className: "dd-tile-note",
83
84
  children: messages.noHistory
84
85
  }) : null,
86
+ /* @__PURE__ */ jsx(ReadFailed, {
87
+ error: history.error,
88
+ retry: () => void history.mutate()
89
+ }),
85
90
  /* @__PURE__ */ jsx("ol", {
86
91
  className: "dd-timeline",
87
92
  children: entries.map((entry) => /* @__PURE__ */ jsx(Entry, {
@@ -0,0 +1,23 @@
1
+ import { useDashboards } from "./context.mjs";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ // src/ReadFailed.tsx
4
+ /** A list that could not be read (the history, a page of it): said, with a way to try again. */
5
+ function ReadFailed({ error, retry }) {
6
+ const { messages } = useDashboards();
7
+ if (error === void 0) return null;
8
+ return /* @__PURE__ */ jsxs("p", {
9
+ className: "dd-tile-error",
10
+ role: "alert",
11
+ children: [
12
+ messages.readFailed,
13
+ " ",
14
+ /* @__PURE__ */ jsx("button", {
15
+ type: "button",
16
+ className: "dd-button dd-quiet",
17
+ onClick: retry,
18
+ children: messages.drillRetry
19
+ })
20
+ ]
21
+ });
22
+ }
23
+ export { ReadFailed };
@@ -105,4 +105,18 @@ function Spaces(props) {
105
105
  }) : null
106
106
  }, `${gap.widget}-gap`))] });
107
107
  }
108
- export { Spaces, ghostPlaces };
108
+ /**
109
+ * The outline where a dragged tile will land, and where one moved by the keyboard is now, said
110
+ * to a screen reader (`arrange` writes it).
111
+ */
112
+ function Drop({ at }) {
113
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
114
+ className: "dd-placed dd-sr",
115
+ role: "status"
116
+ }), at === void 0 ? null : /* @__PURE__ */ jsx("div", {
117
+ className: "dd-drop",
118
+ "aria-hidden": "true",
119
+ style: placeOf(at)
120
+ })] });
121
+ }
122
+ export { Drop, Spaces, ghostPlaces };
@@ -11,6 +11,8 @@ type Props = {
11
11
  actions?: ReactNode;
12
12
  /** What changed about it, beside its title: New, Edited, Moved, or a preview's mark. */
13
13
  badge?: ReactNode;
14
+ /** The span most tiles cover (`spanKey`), said once for the dashboard, not on each tile. */
15
+ sharedSpan?: string | undefined;
14
16
  };
15
17
  /**
16
18
  * One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
@@ -41,14 +41,14 @@ const drawable = (result) => result !== void 0 && !("error" in result) && result
41
41
  const Body = memo(function Body({ widget, result, loading, drill }) {
42
42
  const { renderers, locale, messages, link } = useDashboards();
43
43
  if (!drawable(result)) {
44
- const empty = widget.display?.["empty"];
44
+ const empty = widget.display?.empty;
45
45
  return /* @__PURE__ */ jsx(TileState, {
46
46
  result,
47
47
  loading,
48
48
  empty: typeof empty === "string" ? empty : messages.noData
49
49
  });
50
50
  }
51
- const Renderer = renderers[widget.kind] ?? renderers["table"];
51
+ const Renderer = renderers[widget.kind] ?? renderers.table;
52
52
  return Renderer === void 0 ? null : /* @__PURE__ */ jsx(Renderer, {
53
53
  answer: result,
54
54
  widget,
@@ -80,12 +80,21 @@ function Notes({ result, controlLabels }) {
80
80
  }
81
81
  /** Whether a tile has rows behind it to show: an answer the viewer can read. */
82
82
  const hasRows = (result) => result !== void 0 && !("error" in result) && result.unreadable !== true && result.rows.length > 0;
83
- /** The time a tile's answer covers, as it read it ("Oct 15, 2026 to Nov 14, 2026"), so a reader knows its window. */
84
- function Span({ result }) {
83
+ /** The time a tile's answer covers, as a key two tiles share when they cover the same days. */
84
+ const spanKey = (result) => {
85
+ if (result === void 0 || "error" in result) return void 0;
86
+ const range = result.receipt.range;
87
+ return range === void 0 ? void 0 : `${range.from}|${range.to}`;
88
+ };
89
+ /**
90
+ * The time a tile's answer covers, as it read it ("Oct 15 to Nov 14"), so a reader knows its
91
+ * window. A tile covering the span most tiles do leaves it to the dashboard, which says it once.
92
+ */
93
+ function Span({ result, shared }) {
85
94
  const format = useDashboards();
86
95
  if (result === void 0 || "error" in result) return null;
87
96
  const range = result.receipt.range;
88
- if (range === void 0) return null;
97
+ if (range === void 0 || shared !== void 0 && spanKey(result) === shared) return null;
89
98
  const zone = result.receipt.calendar.timezone;
90
99
  const day = (at) => formatInstantAt(at, "day", format.locale, zone);
91
100
  return /* @__PURE__ */ jsx("p", {
@@ -94,6 +103,22 @@ function Span({ result }) {
94
103
  });
95
104
  }
96
105
  /**
106
+ * The span most of the tiles cover, when at least two do and they are most of them: the
107
+ * dashboard says it once and those tiles leave it out. None when the tiles disagree.
108
+ */
109
+ function sharedSpan(results) {
110
+ const counts = /* @__PURE__ */ new Map();
111
+ let spans = 0;
112
+ for (const result of results.values()) {
113
+ const key = spanKey(result);
114
+ if (key === void 0) continue;
115
+ spans += 1;
116
+ counts.set(key, (counts.get(key) ?? 0) + 1);
117
+ }
118
+ const [top] = [...counts].toSorted((a, b) => b[1] - a[1]);
119
+ return top !== void 0 && top[1] >= 2 && top[1] * 2 > spans ? top[0] : void 0;
120
+ }
121
+ /**
97
122
  * One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
98
123
  * on request (Rows opens its drill on Items). It draws again only when one of its props changes.
99
124
  */
@@ -130,7 +155,10 @@ const Tile = memo(function Tile(props) {
130
155
  })
131
156
  ]
132
157
  }),
133
- /* @__PURE__ */ jsx(Span, { result: props.result }),
158
+ /* @__PURE__ */ jsx(Span, {
159
+ result: props.result,
160
+ shared: props.sharedSpan
161
+ }),
134
162
  /* @__PURE__ */ jsx("div", {
135
163
  className: "dd-tile-body",
136
164
  children: /* @__PURE__ */ jsx(Body, {
@@ -144,4 +172,4 @@ const Tile = memo(function Tile(props) {
144
172
  ]
145
173
  });
146
174
  });
147
- export { Tile };
175
+ export { Span, Tile, sharedSpan, spanKey };
@@ -0,0 +1,12 @@
1
+ // \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ export { __exportAll };
@@ -39,41 +39,44 @@ function stepOf(grid) {
39
39
  y: row + rowGap
40
40
  };
41
41
  }
42
- /** The smallest a person can resize a tile to: room for its title, its buttons and a number. */
43
- const SMALLEST = {
44
- w: 2,
45
- h: 2
46
- };
47
42
  /**
48
43
  * The item moved or resized by whole cells: a move keeps the size; a resize keeps the top left,
49
- * stops at the grid's edge, and never makes a tile smaller than it can be read (one already
50
- * smaller stays as it is).
44
+ * stops at the grid's edge, and never makes a tile smaller than its kind reads at (core's
45
+ * `smallestFor`; one already smaller stays as it is).
51
46
  */
52
- function shifted(item, mode, dx, dy) {
47
+ function shifted(item, how, by) {
48
+ const { mode, least } = how;
49
+ const { dx, dy } = by;
53
50
  return mode === "move" ? {
54
51
  ...item,
55
52
  x: Math.max(0, item.x + dx),
56
53
  y: Math.max(0, item.y + dy)
57
54
  } : {
58
55
  ...item,
59
- w: Math.min(Math.max(Math.min(SMALLEST.w, item.w), item.w + dx), GRID_COLUMNS - item.x),
60
- h: Math.max(Math.min(SMALLEST.h, item.h), item.h + dy)
56
+ w: Math.min(Math.max(Math.min(least.w, item.w), item.w + dx), GRID_COLUMNS - item.x),
57
+ h: Math.max(Math.min(least.h, item.h), item.h + dy)
61
58
  };
62
59
  }
63
60
  /** Where a drag puts the item: whole cells from where the pointer went down. */
64
61
  function dragged(d, event) {
65
62
  const dx = Math.round((event.clientX - d.x0) / d.step.x);
66
63
  const dy = Math.round((event.clientY - d.y0) / d.step.y);
67
- return shifted(d.start, d.mode, dx, dy);
64
+ return shifted(d.start, d, {
65
+ dx,
66
+ dy
67
+ });
68
68
  }
69
69
  /**
70
70
  * One arrow key's move: the nearest place in that direction where the layout really changes,
71
71
  * so moving down past a tile takes one press, not as many as it is tall.
72
72
  */
73
- function nextStep(tab, item, mode, key) {
73
+ function nextStep(tab, item, how, key) {
74
74
  const before = JSON.stringify(placeItem(tab.layout, item));
75
75
  for (let n = 1; n <= 48; n += 1) {
76
- const next = shifted(item, mode, key.dx * n, key.dy * n);
76
+ const next = shifted(item, how, {
77
+ dx: key.dx * n,
78
+ dy: key.dy * n
79
+ });
77
80
  if (JSON.stringify(placeItem(tab.layout, next)) !== before) return next;
78
81
  }
79
82
  return item;
@@ -2,7 +2,7 @@ import { KEYS, commit, dragged, follow, nextStep, same, stepOf } from "./arrange
2
2
  import { useDashboards } from "./context.mjs";
3
3
  import { useStable } from "./stable.mjs";
4
4
  import { useMemo, useRef, useState } from "react";
5
- import { placeItem } from "derive-dashboards/core";
5
+ import { placeItem, smallestFor } from "derive-dashboards/core";
6
6
  // src/arrange.ts
7
7
  /**
8
8
  * A preview that only changes when its place does: a pointer moving inside one grid cell
@@ -25,12 +25,18 @@ function usePreview() {
25
25
  show: useStable(show)
26
26
  };
27
27
  }
28
+ /** The smallest the tile's kind reads at, from the draft's own widget. */
29
+ const leastOf = (a, item) => smallestFor(a.edit().draft?.doc.widgets[item.widget]?.kind);
28
30
  /** An arrow key on a handle: a cell's move (or with Shift, a resize), then where the tile is now. */
29
31
  const onKey = (a, send, item, mode) => (event) => {
30
32
  const key = KEYS[event.key];
31
33
  if (key === void 0 || a.edit().busy) return;
32
34
  event.preventDefault();
33
- const wanted = nextStep(a.tab(), item, event.shiftKey ? "resize" : mode, key);
35
+ const how = {
36
+ mode: event.shiftKey ? "resize" : mode,
37
+ least: leastOf(a, item)
38
+ };
39
+ const wanted = nextStep(a.tab(), item, how, key);
34
40
  const said = async () => {
35
41
  await send(wanted);
36
42
  requestAnimationFrame(() => {
@@ -67,7 +73,8 @@ function handlers(a, drag, show) {
67
73
  last: {
68
74
  clientX: x0,
69
75
  clientY: y0
70
- }
76
+ },
77
+ least: leastOf(a, item)
71
78
  };
72
79
  show(item, mode === "move" ? item : void 0);
73
80
  },
@@ -1,4 +1,5 @@
1
1
  import { useDashboards } from "../context.mjs";
2
+ import { FormulaEditor } from "./Formula.mjs";
2
3
  import { formulaText } from "./labels.mjs";
3
4
  import { Chip, Entry, Section } from "./Sections.mjs";
4
5
  import { useState } from "react";
@@ -43,14 +44,36 @@ function CalcEditor({ b, calc }) {
43
44
  ]
44
45
  });
45
46
  }
47
+ /** The presets that fit, and Formula, to add a calculation. */
48
+ function AddChips({ b, onFormula }) {
49
+ const { messages } = useDashboards();
50
+ return /* @__PURE__ */ jsxs("div", {
51
+ className: "dd-chips",
52
+ children: [b.presets.map((p) => /* @__PURE__ */ jsx(Chip, {
53
+ add: true,
54
+ on: false,
55
+ label: messages.presets[p],
56
+ onClick: () => {
57
+ b.addCalc(p);
58
+ }
59
+ }, p)), /* @__PURE__ */ jsx(Chip, {
60
+ add: true,
61
+ on: false,
62
+ label: messages.formula,
63
+ onClick: onFormula
64
+ })]
65
+ });
66
+ }
46
67
  /** Calculations: the ones added, each editable in place, and the presets that fit. */
47
68
  function CalcSection({ b }) {
48
69
  const { messages } = useDashboards();
49
70
  const [open, setOpen] = useState();
71
+ const [writing, setWriting] = useState(false);
50
72
  const calcs = b.state.query?.calc ?? [];
51
73
  if (b.state.query === void 0) return null;
52
74
  return /* @__PURE__ */ jsxs(Section, {
53
75
  title: messages.calculations,
76
+ summary: calcs.length === 0 ? messages.noCalculations : calcs.map((c) => c.label ?? c.id).join(", "),
54
77
  children: [
55
78
  calcs.length === 0 ? /* @__PURE__ */ jsx("p", {
56
79
  className: "dd-muted",
@@ -70,17 +93,18 @@ function CalcSection({ b }) {
70
93
  b,
71
94
  calc: c
72
95
  }) : null] }, c.id)),
73
- /* @__PURE__ */ jsx("div", {
74
- className: "dd-chips",
75
- children: b.presets.map((p) => /* @__PURE__ */ jsx(Chip, {
76
- add: true,
77
- on: false,
78
- label: messages.presets[p],
79
- onClick: () => {
80
- b.addCalc(p);
81
- }
82
- }, p))
83
- })
96
+ /* @__PURE__ */ jsx(AddChips, {
97
+ b,
98
+ onFormula: () => {
99
+ setWriting(true);
100
+ }
101
+ }),
102
+ writing ? /* @__PURE__ */ jsx(FormulaEditor, {
103
+ b,
104
+ onDone: () => {
105
+ setWriting(false);
106
+ }
107
+ }) : null
84
108
  ]
85
109
  });
86
110
  }