derive-dashboards 0.1.0 → 0.1.1

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 (301) hide show
  1. package/README.md +4 -3
  2. package/dist/adapter/sql-adapter.mjs +4 -4
  3. package/dist/body.mjs +11 -1
  4. package/dist/cache.d.mts +1 -1
  5. package/dist/cli/check.mjs +14 -1
  6. package/dist/cli/import/dbt-schema.mjs +2 -2
  7. package/dist/cli/import/index.mjs +2 -2
  8. package/dist/core/conformance/cases.d.mts +3 -0
  9. package/dist/core/conformance/cases.mjs +20 -4
  10. package/dist/core/conformance/check.mjs +6 -3
  11. package/dist/core/conformance/drill-cases.mjs +120 -0
  12. package/dist/core/document/view.d.mts +26 -7
  13. package/dist/core/document/view.mjs +42 -11
  14. package/dist/core/engine/index.d.mts +14 -2
  15. package/dist/core/engine/index.mjs +12 -1
  16. package/dist/core/engine/members.mjs +1 -1
  17. package/dist/core/engine/postgres.mjs +1 -1
  18. package/dist/core/engine/record-layout.d.mts +11 -0
  19. package/dist/core/engine/record-layout.mjs +7 -7
  20. package/dist/core/engine/records.d.mts +3 -2
  21. package/dist/core/engine/records.mjs +2 -1
  22. package/dist/core/engine/segmented.mjs +5 -2
  23. package/dist/core/engine/sql-records.mjs +2 -1
  24. package/dist/core/engine/statement.mjs +37 -3
  25. package/dist/core/engine/types.d.mts +3 -0
  26. package/dist/core/engine/version.d.mts +1 -1
  27. package/dist/core/engine/version.mjs +1 -1
  28. package/dist/core/error/codes.d.mts +31 -0
  29. package/dist/core/error/codes.mjs +28 -1
  30. package/dist/core/index.d.mts +9 -5
  31. package/dist/core/index.mjs +5 -3
  32. package/dist/core/model/catalog/check.mjs +1 -1
  33. package/dist/core/model/hints.d.mts +36 -0
  34. package/dist/core/model/member.d.mts +4 -2
  35. package/dist/core/model/member.mjs +16 -3
  36. package/dist/core/model/types.d.mts +8 -6
  37. package/dist/core/model/validate/drill.mjs +70 -0
  38. package/dist/core/model/validate/index.mjs +3 -0
  39. package/dist/core/model/validate/shape.mjs +150 -0
  40. package/dist/core/model/validate/source.mjs +5 -3
  41. package/dist/core/query/alias.mjs +7 -1
  42. package/dist/core/query/drill/compose.d.mts +22 -0
  43. package/dist/core/query/drill/compose.mjs +85 -0
  44. package/dist/core/query/drill/fields.d.mts +21 -0
  45. package/dist/core/query/drill/fields.mjs +91 -0
  46. package/dist/core/query/drill/internal.d.mts +11 -0
  47. package/dist/core/query/drill/items.d.mts +29 -0
  48. package/dist/core/query/drill/items.mjs +98 -0
  49. package/dist/core/query/drill/line.d.mts +31 -0
  50. package/dist/core/query/drill/line.mjs +183 -0
  51. package/dist/core/query/drill/links.d.mts +33 -0
  52. package/dist/core/query/drill/links.mjs +31 -0
  53. package/dist/core/query/drill/operand.mjs +7 -0
  54. package/dist/core/query/drill/scopes.d.mts +22 -0
  55. package/dist/core/query/drill/scopes.mjs +58 -0
  56. package/dist/core/query/drill/selection.d.mts +37 -0
  57. package/dist/core/query/drill/selection.mjs +144 -0
  58. package/dist/core/query/drill/steps.d.mts +14 -0
  59. package/dist/core/query/drill/steps.mjs +35 -0
  60. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  61. package/dist/core/query/drill/synthetic.d.mts +22 -0
  62. package/dist/core/query/drill/synthetic.mjs +165 -0
  63. package/dist/core/query/drill/time.d.mts +11 -0
  64. package/dist/core/query/drill/time.mjs +71 -0
  65. package/dist/core/query/drill/types.d.mts +155 -0
  66. package/dist/core/query/drill/types.mjs +4 -0
  67. package/dist/core/query/drill/views.d.mts +62 -0
  68. package/dist/core/query/drill/views.mjs +257 -0
  69. package/dist/core/query/segments.d.mts +12 -2
  70. package/dist/core/query/segments.mjs +3 -1
  71. package/dist/core/result/columns.mjs +17 -4
  72. package/dist/core/result/types.d.mts +5 -1
  73. package/dist/core/schema/answer-parts.mjs +117 -0
  74. package/dist/core/schema/answers.d.mts +2108 -128
  75. package/dist/core/schema/answers.mjs +10 -113
  76. package/dist/core/schema/commands.d.mts +2 -2
  77. package/dist/core/schema/document.d.mts +1 -1
  78. package/dist/core/schema/drill-answers.mjs +179 -0
  79. package/dist/core/schema/drill.d.mts +260 -0
  80. package/dist/core/schema/drill.mjs +107 -0
  81. package/dist/core/schema/index.d.mts +4 -2
  82. package/dist/core/schema/index.mjs +4 -2
  83. package/dist/core/schema/picks.d.mts +35 -0
  84. package/dist/core/schema/picks.mjs +23 -0
  85. package/dist/core/schema/query.d.mts +1 -1
  86. package/dist/core/schema/tools.mjs +1 -1
  87. package/dist/core/schema/view.d.mts +0 -35
  88. package/dist/core/schema/view.mjs +19 -24
  89. package/dist/core/store/schema.d.mts +5 -0
  90. package/dist/core/store/schema.mjs +10 -0
  91. package/dist/core/types/api.d.mts +15 -1
  92. package/dist/core/types/api.mjs +1 -1
  93. package/dist/core/types/drill-api.d.mts +210 -0
  94. package/dist/core/types/options.d.mts +21 -0
  95. package/dist/core/types/viewer.d.mts +5 -0
  96. package/dist/cursor-seal.d.mts +8 -0
  97. package/dist/cursor-seal.mjs +98 -0
  98. package/dist/dashboard-id.mjs +1 -1
  99. package/dist/drill-access.mjs +93 -0
  100. package/dist/drill-change.mjs +76 -0
  101. package/dist/drill-crumbs.mjs +113 -0
  102. package/dist/drill-distinct.mjs +130 -0
  103. package/dist/drill-explain.mjs +64 -0
  104. package/dist/drill-identity.mjs +35 -0
  105. package/dist/drill-item-id.mjs +35 -0
  106. package/dist/drill-items.mjs +132 -0
  107. package/dist/drill-open.mjs +169 -0
  108. package/dist/drill-seal.mjs +170 -0
  109. package/dist/drill-secret.mjs +14 -0
  110. package/dist/drill-share.mjs +53 -0
  111. package/dist/drill-summary.mjs +158 -0
  112. package/dist/drill-targets.mjs +53 -0
  113. package/dist/drill-totals.mjs +8 -0
  114. package/dist/drill-views.mjs +175 -0
  115. package/dist/drill.mjs +157 -0
  116. package/dist/editing.mjs +2 -2
  117. package/dist/endpoints/dashboards.mjs +11 -3
  118. package/dist/endpoints/drill.mjs +55 -0
  119. package/dist/endpoints/index.d.mts +233 -2
  120. package/dist/endpoints/index.mjs +5 -1
  121. package/dist/endpoints/query.mjs +26 -4
  122. package/dist/execute.d.mts +19 -1
  123. package/dist/execute.mjs +15 -17
  124. package/dist/index.d.mts +3 -1
  125. package/dist/index.mjs +29 -2
  126. package/dist/mcp/drill.mjs +61 -0
  127. package/dist/mcp/format.mjs +27 -3
  128. package/dist/mcp/index.d.mts +15 -4
  129. package/dist/mcp/index.mjs +13 -7
  130. package/dist/mcp/query.d.mts +7 -2
  131. package/dist/mcp/query.mjs +7 -3
  132. package/dist/node-postgres.d.mts +8 -4
  133. package/dist/node-postgres.mjs +29 -6
  134. package/dist/owner.mjs +3 -3
  135. package/dist/postgres-connection.d.mts +8 -2
  136. package/dist/postgres-connection.mjs +2 -1
  137. package/dist/react/Dashboard.d.mts +10 -5
  138. package/dist/react/Dashboard.mjs +51 -23
  139. package/dist/react/DashboardList.mjs +30 -2
  140. package/dist/react/Discard.mjs +7 -2
  141. package/dist/react/Grid.mjs +12 -5
  142. package/dist/react/Header.mjs +9 -0
  143. package/dist/react/Parts.mjs +6 -2
  144. package/dist/react/ReviewPanel.mjs +13 -2
  145. package/dist/react/RowBody.d.mts +19 -0
  146. package/dist/react/RowBody.mjs +55 -0
  147. package/dist/react/Tile.d.mts +1 -1
  148. package/dist/react/Tile.mjs +54 -30
  149. package/dist/react/builder/state.d.mts +1 -1
  150. package/dist/react/client.d.mts +2 -0
  151. package/dist/react/client.mjs +1 -0
  152. package/dist/react/context.d.mts +15 -1
  153. package/dist/react/context.mjs +19 -4
  154. package/dist/react/drill/Bars.mjs +179 -0
  155. package/dist/react/drill/Controls.mjs +173 -0
  156. package/dist/react/drill/DashboardTile.d.mts +18 -0
  157. package/dist/react/drill/DashboardTile.mjs +107 -0
  158. package/dist/react/drill/DrillPanel.d.mts +31 -0
  159. package/dist/react/drill/DrillPanel.mjs +104 -0
  160. package/dist/react/drill/DrillTabs.mjs +52 -0
  161. package/dist/react/drill/Header.mjs +131 -0
  162. package/dist/react/drill/Items.d.mts +22 -0
  163. package/dist/react/drill/Items.mjs +164 -0
  164. package/dist/react/drill/ItemsFoot.mjs +60 -0
  165. package/dist/react/drill/Notes.mjs +58 -0
  166. package/dist/react/drill/PanelBody.mjs +74 -0
  167. package/dist/react/drill/PanelStates.mjs +37 -0
  168. package/dist/react/drill/board.d.mts +18 -0
  169. package/dist/react/drill/board.mjs +91 -0
  170. package/dist/react/drill/counts.mjs +14 -0
  171. package/dist/react/drill/host.mjs +26 -0
  172. package/dist/react/drill/item-parts.d.mts +5 -0
  173. package/dist/react/drill/item-parts.mjs +76 -0
  174. package/dist/react/drill/item-type.d.mts +26 -0
  175. package/dist/react/drill/item-type.mjs +7 -0
  176. package/dist/react/drill/lazy.d.mts +6 -0
  177. package/dist/react/drill/lazy.mjs +17 -0
  178. package/dist/react/drill/pages.mjs +48 -0
  179. package/dist/react/drill/panel-focus.mjs +51 -0
  180. package/dist/react/drill/props.d.mts +25 -0
  181. package/dist/react/drill/props.mjs +72 -0
  182. package/dist/react/drill/state.d.mts +18 -0
  183. package/dist/react/drill/state.mjs +68 -0
  184. package/dist/react/drill/useDrill.d.mts +46 -0
  185. package/dist/react/drill/useDrill.mjs +194 -0
  186. package/dist/react/drill/words.d.mts +98 -0
  187. package/dist/react/drill/words.mjs +77 -0
  188. package/dist/react/english.mjs +9 -1
  189. package/dist/react/format.d.mts +3 -3
  190. package/dist/react/format.mjs +34 -12
  191. package/dist/react/index.d.mts +27 -4
  192. package/dist/react/index.mjs +10 -3
  193. package/dist/react/messages.d.mts +14 -1
  194. package/dist/react/renderers/index.d.mts +10 -2
  195. package/dist/react/renderers/index.mjs +54 -14
  196. package/dist/react/renderers/list.d.mts +22 -0
  197. package/dist/react/renderers/list.mjs +118 -0
  198. package/dist/react/review-words.mjs +1 -1
  199. package/dist/react/review.mjs +2 -2
  200. package/dist/react/scope.mjs +2 -7
  201. package/dist/react/series.d.mts +37 -0
  202. package/dist/react/series.mjs +95 -0
  203. package/dist/react/theme.css +1823 -1296
  204. package/dist/react/theme.css.d.ts +1 -0
  205. package/dist/react/tile-store.mjs +15 -3
  206. package/dist/react/useBoard.d.mts +5 -0
  207. package/dist/react/useBoard.mjs +4 -1
  208. package/dist/react/useDashboard.d.mts +1 -0
  209. package/dist/react/useDashboard.mjs +2 -1
  210. package/dist/react/useTiles.mjs +50 -15
  211. package/dist/react/view.d.mts +9 -0
  212. package/dist/react/view.mjs +22 -10
  213. package/dist/reading.d.mts +2 -0
  214. package/dist/reading.mjs +9 -1
  215. package/dist/recharts/charts.d.mts +0 -1
  216. package/dist/recharts/charts.mjs +128 -34
  217. package/dist/recharts/index.d.mts +2 -2
  218. package/dist/recharts/index.mjs +2 -2
  219. package/dist/recharts/marks.mjs +83 -0
  220. package/dist/recharts/series.d.mts +2 -22
  221. package/dist/recharts/series.mjs +1 -64
  222. package/dist/records-read.mjs +44 -0
  223. package/dist/store/apply.mjs +5 -5
  224. package/dist/store/commands.mjs +4 -4
  225. package/dist/store/discard.mjs +7 -7
  226. package/dist/store/drafts.mjs +5 -5
  227. package/dist/store/editor.mjs +1 -1
  228. package/dist/store/publish.mjs +12 -12
  229. package/dist/store/reader.mjs +41 -22
  230. package/dist/store/review.mjs +16 -16
  231. package/dist/store/rows.mjs +20 -20
  232. package/dist/store/undo.mjs +3 -3
  233. package/dist/store/unpublished.mjs +4 -4
  234. package/dist/store/versions.mjs +14 -14
  235. package/dist/testing/adapter-suite.mjs +4 -4
  236. package/dist/tiles.mjs +37 -3
  237. package/package.json +8 -10
  238. package/dist/react/Records.d.mts +0 -12
  239. package/dist/react/Records.mjs +0 -97
  240. package/src/adapter/sql-adapter.ts +0 -95
  241. package/src/adapter/statement.ts +0 -185
  242. package/src/authorize.ts +0 -73
  243. package/src/body.ts +0 -169
  244. package/src/bounded.ts +0 -43
  245. package/src/cache.ts +0 -192
  246. package/src/checks.ts +0 -170
  247. package/src/custom-source.ts +0 -59
  248. package/src/dashboard-id.ts +0 -36
  249. package/src/dashboards.ts +0 -132
  250. package/src/editing.ts +0 -148
  251. package/src/endpoints/access.ts +0 -41
  252. package/src/endpoints/dashboards.ts +0 -92
  253. package/src/endpoints/drafts.ts +0 -138
  254. package/src/endpoints/index.ts +0 -21
  255. package/src/endpoints/meta.ts +0 -137
  256. package/src/endpoints/query.ts +0 -86
  257. package/src/endpoints/read.ts +0 -92
  258. package/src/endpoints/review.ts +0 -89
  259. package/src/endpoints/values.ts +0 -62
  260. package/src/endpoints/versions.ts +0 -104
  261. package/src/execute.ts +0 -207
  262. package/src/handler.ts +0 -232
  263. package/src/http.ts +0 -66
  264. package/src/index.ts +0 -163
  265. package/src/introspect.ts +0 -205
  266. package/src/mcp/api.ts +0 -59
  267. package/src/mcp/format.ts +0 -67
  268. package/src/mcp/index.ts +0 -151
  269. package/src/mcp/query.ts +0 -153
  270. package/src/mcp/resolve.ts +0 -114
  271. package/src/node-postgres.ts +0 -81
  272. package/src/owner.ts +0 -36
  273. package/src/postgres-connection.ts +0 -143
  274. package/src/postgres-store.ts +0 -82
  275. package/src/principal.ts +0 -39
  276. package/src/reading.ts +0 -56
  277. package/src/request-rows.ts +0 -23
  278. package/src/request.ts +0 -22
  279. package/src/storage.ts +0 -63
  280. package/src/store/apply.ts +0 -129
  281. package/src/store/commands.ts +0 -75
  282. package/src/store/conflicts.ts +0 -98
  283. package/src/store/create-tables.ts +0 -104
  284. package/src/store/discard.ts +0 -42
  285. package/src/store/drafts.ts +0 -133
  286. package/src/store/editor.ts +0 -28
  287. package/src/store/log.ts +0 -28
  288. package/src/store/publish.ts +0 -199
  289. package/src/store/publisher.ts +0 -21
  290. package/src/store/reader.ts +0 -139
  291. package/src/store/review.ts +0 -239
  292. package/src/store/rows.ts +0 -250
  293. package/src/store/tenant.ts +0 -28
  294. package/src/store/undo.ts +0 -56
  295. package/src/store/unpublished.ts +0 -33
  296. package/src/store/versions.ts +0 -106
  297. package/src/store/writer.ts +0 -19
  298. package/src/testing/adapter-suite.ts +0 -239
  299. package/src/testing/index.ts +0 -2
  300. package/src/tile-doc.ts +0 -46
  301. package/src/tiles.ts +0 -120
@@ -0,0 +1 @@
1
+ export {};
@@ -19,11 +19,17 @@ function nextFrame(run) {
19
19
  function createTileStore(onDraw) {
20
20
  const answers = /* @__PURE__ */ new Map();
21
21
  const last = /* @__PURE__ */ new Map();
22
+ const failed = /* @__PURE__ */ new Map();
22
23
  const queued = /* @__PURE__ */ new Map();
23
24
  let cancel;
24
25
  const draw = () => {
25
26
  cancel = void 0;
26
27
  for (const [key, { widgetId, result }] of queued) {
28
+ if ("error" in result && result.error.code === "TILES_FAILED") {
29
+ failed.set(key, result);
30
+ continue;
31
+ }
32
+ failed.delete(key);
27
33
  answers.set(key, result);
28
34
  last.set(widgetId, result);
29
35
  }
@@ -32,8 +38,8 @@ function createTileStore(onDraw) {
32
38
  };
33
39
  return {
34
40
  /** The answer for a key, or else the last one the widget had, while its new one loads. */
35
- shown: (widgetId, key) => answers.get(key) ?? last.get(widgetId),
36
- answered: (key) => answers.has(key),
41
+ shown: (widgetId, key) => answers.get(key) ?? last.get(widgetId) ?? failed.get(key),
42
+ answered: (key) => answers.has(key) || failed.has(key),
37
43
  put: (widgetId, key, result) => {
38
44
  queued.set(key, {
39
45
  widgetId,
@@ -41,7 +47,13 @@ function createTileStore(onDraw) {
41
47
  });
42
48
  cancel ??= nextFrame(draw);
43
49
  },
44
- has: (key) => answers.has(key) || queued.has(key),
50
+ has: (key) => answers.has(key) || queued.has(key) || failed.has(key),
51
+ /** Whether any tile's request never reached the server. */
52
+ hasFailed: () => failed.size > 0,
53
+ /** Forgets the requests that never arrived, so the next refresh asks for them again. */
54
+ retry: () => {
55
+ failed.clear();
56
+ },
45
57
  /** Forgets answers no tile wants any more; each widget's last answer stays to show. */
46
58
  keepOnly: (wanted) => {
47
59
  for (const key of answers.keys()) if (!wanted.has(key)) answers.delete(key);
@@ -1,6 +1,8 @@
1
1
  import { Moved } from "./review.mjs";
2
2
  import { PanelName, Showing } from "./board.mjs";
3
+ import "./index.mjs";
3
4
  import { Attempt, DraftStatus } from "./draft.mjs";
5
+ import { DrillHistory } from "./drill/state.mjs";
4
6
  import { DashboardProps } from "./Dashboard.mjs";
5
7
  import { JustPublished } from "./Notice.mjs";
6
8
  /** Everything the dashboard shows at once, gathered from its hooks. */
@@ -31,9 +33,11 @@ export declare function useBoard(props: DashboardProps): {
31
33
  view: {
32
34
  tab: string | undefined;
33
35
  picks: import("derive-dashboards/core").Picks;
36
+ drill: import("derive-dashboards/core").DrillState | undefined;
34
37
  dropped: string[];
35
38
  setTab: (tab: string) => void;
36
39
  setPicks: (picks: import("derive-dashboards/core").Picks) => void;
40
+ setDrill: (drill: import("derive-dashboards/core").DrillState | undefined, history: DrillHistory) => void;
37
41
  current: import("derive-dashboards/core").ViewState;
38
42
  };
39
43
  shown: (Showing & {
@@ -75,6 +79,7 @@ export declare function useBoard(props: DashboardProps): {
75
79
  waiting: boolean;
76
80
  unpublished: boolean;
77
81
  error: boolean;
82
+ unreachable: boolean;
78
83
  missing: boolean;
79
84
  doc: import("derive-dashboards/core").Doc | undefined;
80
85
  };
@@ -37,7 +37,10 @@ function useBoard(props) {
37
37
  useShortcuts({
38
38
  edit,
39
39
  onReview: panels.openReview,
40
- onEscape: panels.close
40
+ onEscape: () => {
41
+ panels.close();
42
+ if (view.drill !== void 0) view.setDrill(void 0, "push");
43
+ }
41
44
  });
42
45
  return {
43
46
  ...loaded,
@@ -45,6 +45,7 @@ export declare function useDashboard(id: string, events: DashboardEvents, editab
45
45
  /** Made by this viewer and never published: discarding its draft deletes it. */
46
46
  unpublished: boolean;
47
47
  error: boolean;
48
+ unreachable: boolean;
48
49
  /** The dashboard is not there for this viewer: not published yet, removed, or not theirs. */
49
50
  missing: boolean;
50
51
  doc: import("derive-dashboards/core").Doc | undefined;
@@ -44,7 +44,8 @@ function useDashboard(id, events, editable, onClosed) {
44
44
  });
45
45
  useOpenOnce(editable && loaded.data?.unpublished === true, edit.start);
46
46
  return {
47
- error: loaded.error !== void 0,
47
+ error: loaded.error !== void 0 && loaded.data === void 0,
48
+ unreachable: loaded.error !== void 0 && loaded.data !== void 0,
48
49
  /** The dashboard is not there for this viewer: not published yet, removed, or not theirs. */
49
50
  missing: loaded.error instanceof DashboardsError && loaded.error.code === "NOT_FOUND",
50
51
  doc: edit.draft?.doc ?? loaded.data?.document,
@@ -21,6 +21,24 @@ function refresh(a) {
21
21
  const missing = [...a.keys].filter(([, key]) => !a.store.has(key) && !flying.has(key));
22
22
  if (missing.length > 0) a.flights.add(a.start(missing));
23
23
  }
24
+ /** Asks for the wanted tiles that have no answer, as the latest keys and body say. */
25
+ function refreshNow(a) {
26
+ const onEnd = (flight) => {
27
+ a.flights.delete(flight);
28
+ };
29
+ refresh({
30
+ keys: a.keys,
31
+ flights: a.flights,
32
+ store: a.store,
33
+ start: (wanted) => launch({
34
+ client: a.client,
35
+ body: a.body,
36
+ wanted,
37
+ store: a.store,
38
+ onEnd
39
+ })
40
+ });
41
+ }
24
42
  /** Each widget's answer to show, and which are still on their way. */
25
43
  function collect(keys, store) {
26
44
  const results = /* @__PURE__ */ new Map();
@@ -35,6 +53,30 @@ function collect(keys, store) {
35
53
  pending
36
54
  };
37
55
  }
56
+ /**
57
+ * Tiles whose request never reached the server ask again when the browser is back online, when
58
+ * the window is focused, and every 15 seconds while any is still failing: a dropped connection
59
+ * heals without a reload.
60
+ */
61
+ function useRetry(store, again) {
62
+ const latest = useRef(again);
63
+ latest.current = again;
64
+ useEffect(() => {
65
+ const retry = () => {
66
+ if (!store.hasFailed()) return;
67
+ store.retry();
68
+ latest.current();
69
+ };
70
+ globalThis.addEventListener("online", retry);
71
+ globalThis.addEventListener("focus", retry);
72
+ const timer = setInterval(retry, 15e3);
73
+ return () => {
74
+ globalThis.removeEventListener("online", retry);
75
+ globalThis.removeEventListener("focus", retry);
76
+ clearInterval(timer);
77
+ };
78
+ }, [store]);
79
+ }
38
80
  /** Once per set of wanted answers: a version conflict means the document shown is behind. */
39
81
  function useStaleCheck(results, signature, onStale) {
40
82
  const stale = [...results.values()].some((r) => "error" in r && r.error.code === "VERSION_CONFLICT");
@@ -92,24 +134,16 @@ function useTiles(a) {
92
134
  }
93
135
  };
94
136
  const signature = [...keys.values()].toSorted().join("\0");
95
- useEffect(() => {
96
- const { keys: now, body } = latest.current;
97
- const onEnd = (flight) => {
98
- flights.current.delete(flight);
99
- };
100
- const start = (wanted) => launch({
137
+ const again = () => {
138
+ refreshNow({
139
+ ...latest.current,
101
140
  client,
102
- body,
103
- wanted,
104
141
  store,
105
- onEnd
106
- });
107
- refresh({
108
- keys: now,
109
- flights: flights.current,
110
- store,
111
- start
142
+ flights: flights.current
112
143
  });
144
+ };
145
+ useEffect(() => {
146
+ again();
113
147
  }, [
114
148
  signature,
115
149
  client,
@@ -123,6 +157,7 @@ function useTiles(a) {
123
157
  store.stop();
124
158
  };
125
159
  }, [store]);
160
+ useRetry(store, again);
126
161
  const { results, pending } = collect(keys, store);
127
162
  useStaleCheck(results, signature, a.onStale);
128
163
  return {
@@ -0,0 +1,9 @@
1
+ import { DrillHistory } from "./drill/state.mjs";
2
+ import { Doc, DrillState, Picks, ViewState } from "derive-dashboards/core";
3
+ /**
4
+ * How a view changed: `push` for a step Back should undo (a drill opened or a step deeper),
5
+ * `replace` for the rest. The library never writes history itself; the host decides.
6
+ */
7
+ export type ViewChange = {
8
+ history: DrillHistory;
9
+ };
@@ -2,44 +2,56 @@ import { useState } from "react";
2
2
  import { VIEW_PREFIX, encodeView, viewFor } from "derive-dashboards/core";
3
3
  // src/view.ts
4
4
  /**
5
- * The tab open and the filters set: the host's, when it passes `view` and `onViewChange` (to
6
- * keep them in its URL), else the dashboard's own. A view naming a tab or filter the dashboard
7
- * does not have keeps the rest, and `dropped` names what was left out.
5
+ * The tab open, the filters set and the drill open: the host's, when it passes `view` and
6
+ * `onViewChange` (to keep them in its URL), else the dashboard's own. A host view without a
7
+ * `drill` key keeps the dashboard's own drill. A view naming a tab,
8
+ * filter or widget the dashboard does not have keeps the rest, and `dropped` names what was left out.
8
9
  */
9
10
  function useView(doc, view, onViewChange, linkDropped = []) {
10
11
  const [own, setOwn] = useState({ picks: {} });
11
- const wanted = view ?? own;
12
+ const wanted = view === void 0 ? own : "drill" in view || own.drill === void 0 ? view : {
13
+ ...view,
14
+ drill: own.drill
15
+ };
12
16
  const kept = doc === void 0 ? {
13
17
  view: wanted,
14
18
  dropped: []
15
19
  } : viewFor(doc, wanted);
16
- const set = (next) => {
20
+ const set = (next, history = "replace") => {
17
21
  setOwn(next);
18
- onViewChange?.(next);
22
+ onViewChange?.(next, { history });
19
23
  };
24
+ const { drill: _drill, ...base } = kept.view;
20
25
  return {
21
26
  tab: kept.view.tab,
22
27
  picks: kept.view.picks,
28
+ drill: kept.view.drill,
23
29
  dropped: [...linkDropped, ...kept.dropped],
24
30
  setTab: (tab) => {
25
31
  set({
26
- ...kept.view,
32
+ ...base,
27
33
  tab
28
34
  });
29
35
  },
30
36
  setPicks: (picks) => {
31
37
  set({
32
- ...kept.view,
38
+ ...base,
33
39
  picks
34
40
  });
35
41
  },
42
+ setDrill: (drill, history) => {
43
+ set(drill === void 0 ? base : {
44
+ ...base,
45
+ drill
46
+ }, history);
47
+ },
36
48
  current: kept.view
37
49
  };
38
50
  }
39
51
  /**
40
52
  * A link to this view: the host's `linkFor`, or the page's own address with the view's
41
- * parameters in place of any it had. A link carries only the tab and filters; the person who
42
- * opens it sees what their own access allows.
53
+ * parameters in place of any it had. A link carries the tab, the filters and the drill; the
54
+ * person who opens it sees what their own access allows.
43
55
  */
44
56
  function linkTo(view, linkFor) {
45
57
  if (linkFor !== void 0) return linkFor(view);
@@ -0,0 +1,2 @@
1
+ import { CustomSource, DashOptions } from "derive-dashboards/core";
2
+ import "derive-dashboards/core/engine";
package/dist/reading.mjs CHANGED
@@ -15,6 +15,14 @@ function connectionOf(at) {
15
15
  if (!isSource(handle)) throw new Error(`\`connections.${connection}\` gave no connection for this request. It must return postgresConnection({ run, transaction }) or customSource({ answer }).`);
16
16
  return handle;
17
17
  }
18
+ /** Whether a source's connection serves the rows behind an answer: a database does, a host's data layer when it gives `records`. */
19
+ function servesRecords(at) {
20
+ const handle = connectionOf({
21
+ ...at,
22
+ maxRows: 0
23
+ });
24
+ return !isCustomSource(handle) || handle.records !== void 0;
25
+ }
18
26
  /**
19
27
  * Runs `fn` with a reader for the source's connection, under the request's deadline and abort:
20
28
  * in one read-only session of a database, or through the host's custom source, each of its
@@ -40,4 +48,4 @@ async function withReader(at, fn) {
40
48
  custom: false
41
49
  };
42
50
  }
43
- export { isSource, withReader };
51
+ export { isSource, servesRecords, withReader };
@@ -1,5 +1,4 @@
1
1
  import { TileRendererProps } from "derive-dashboards/react";
2
- /** A line per series over the x axis, usually time buckets. */
3
2
  export declare function LineTile(props: TileRendererProps): import("react").JSX.Element;
4
3
  /** Bars per x value; when a second field splits them, its values stack, Other on top. */
5
4
  export declare function BarTile(props: TileRendererProps): import("react").JSX.Element;
@@ -1,10 +1,26 @@
1
- import { toSeries } from "./series.mjs";
1
+ import { Marks, openPoint } from "./marks.mjs";
2
+ import { OTHER_KEY, toSeries } from "./series.mjs";
2
3
  import { formatCell, formatTick } from "derive-dashboards/react";
3
- import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
4
+ import { useState } from "react";
5
+ import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, Rectangle, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
4
6
  import { jsx, jsxs } from "react/jsx-runtime";
5
7
  // src/charts.tsx
6
8
  /** A series' colour: the palette in order, and Other always the quiet grey. */
7
- const color = (s, i) => s.key === "other" ? "var(--dd-other)" : `var(--dd-series-${i % 6 + 1})`;
9
+ /** Legend words in the text color: a series' hue marks its swatch, never its name. */
10
+ const legendText = (value) => /* @__PURE__ */ jsx("span", {
11
+ className: "dd-chart-legend",
12
+ children: value
13
+ });
14
+ /** A widget's own colors by series label (`display.colors`), else the palette in order. */
15
+ const colorsOf = (props) => {
16
+ const colors = props.widget.display?.["colors"];
17
+ return typeof colors === "object" && colors !== null ? new Map(Object.entries(colors)) : /* @__PURE__ */ new Map();
18
+ };
19
+ const color = (props, s, i) => {
20
+ const own = colorsOf(props).get(s.label);
21
+ if (typeof own === "string") return own;
22
+ return s.key === OTHER_KEY ? "var(--dd-other)" : `var(--dd-series-${i % 6 + 1})`;
23
+ };
8
24
  function axisFormat(series, locale) {
9
25
  const column = series[0]?.column;
10
26
  return (value) => formatTick(value, column, locale);
@@ -13,20 +29,69 @@ function tooltipFormat(series, format) {
13
29
  const column = series[0]?.column;
14
30
  return (value) => typeof value === "number" ? formatCell(value, column, format) : String(value);
15
31
  }
32
+ /** A tooltip's title, with what a click does when the chart drills. */
33
+ const tooltipLabel = (props) => (label) => props.drill === void 0 ? String(label) : `${String(label)} · ${props.messages.drillHint}`;
34
+ /** A click on a bar opens the row behind it, with its series' line. */
35
+ const barClick = (drill, drawn, s) => drill === void 0 ? {} : { onClick: (_bar, point) => {
36
+ openPoint(drill, drawn, {
37
+ point,
38
+ series: s
39
+ });
40
+ } };
41
+ /** A bar's shape: outlined when the keyboard is on it. */
42
+ const barShape = (focused, key) => (props) => /* @__PURE__ */ jsx(Rectangle, {
43
+ ...props,
44
+ ...focused?.key === key && focused.point === props.index ? {
45
+ className: "dd-chart-focus",
46
+ stroke: "var(--dd-ink)",
47
+ strokeWidth: 2
48
+ } : {}
49
+ });
50
+ /** A line's dots: only the one the keyboard is on, ringed. */
51
+ const lineDot = (focused, key) => focused?.key === key ? (dot) => dot.index === focused.point ? /* @__PURE__ */ jsx("circle", {
52
+ className: "dd-chart-focus",
53
+ cx: dot.cx,
54
+ cy: dot.cy,
55
+ r: 5
56
+ }, dot.index) : /* @__PURE__ */ jsx("g", {}, dot.index) : false;
57
+ /** A click on a single line opens the point under it; with several, each opens from its own list. */
58
+ function lineClick(drill, drawn) {
59
+ const [only] = drawn.series;
60
+ return (state) => {
61
+ const point = Number(state.activeTooltipIndex);
62
+ if (only !== void 0 && drawn.series.length === 1 && Number.isInteger(point)) openPoint(drill, drawn, {
63
+ point,
64
+ series: only
65
+ });
66
+ };
67
+ }
16
68
  /** A line per series over the x axis, usually time buckets. */
69
+ /**
70
+ * What every chart is drawn with: the marks list is the keyboard path, so the chart itself is
71
+ * not a second, empty tab stop (Recharts' own layer).
72
+ */
73
+ const CHART = {
74
+ accessibilityLayer: false,
75
+ margin: {
76
+ top: 4,
77
+ right: 8,
78
+ bottom: 0,
79
+ left: 0
80
+ }
81
+ };
17
82
  function LineTile(props) {
18
- const { answer, locale } = props;
19
- const { points, series } = toSeries(answer, props);
20
- return /* @__PURE__ */ jsx("div", {
83
+ const { answer, locale, drill } = props;
84
+ const [focused, setFocused] = useState(null);
85
+ const drawn = toSeries(answer, props);
86
+ const { points, series } = drawn;
87
+ const onClick = lineClick(drill, drawn);
88
+ return /* @__PURE__ */ jsxs("div", {
21
89
  className: "dd-chart",
22
- children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(LineChart, {
90
+ "data-drillable": drill !== void 0,
91
+ children: [/* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(LineChart, {
92
+ ...CHART,
23
93
  data: points,
24
- margin: {
25
- top: 4,
26
- right: 8,
27
- bottom: 0,
28
- left: 0
29
- },
94
+ ...drill === void 0 ? {} : { onClick },
30
95
  children: [
31
96
  /* @__PURE__ */ jsx(CartesianGrid, {
32
97
  stroke: "var(--dd-line)",
@@ -46,34 +111,45 @@ function LineTile(props) {
46
111
  width: 56,
47
112
  tickFormatter: axisFormat(series, locale)
48
113
  }),
49
- /* @__PURE__ */ jsx(Tooltip, { formatter: tooltipFormat(series, props) }),
50
- series.length > 1 ? /* @__PURE__ */ jsx(Legend, { itemSorter: null }) : null,
114
+ /* @__PURE__ */ jsx(Tooltip, {
115
+ separator: ": ",
116
+ formatter: tooltipFormat(series, props),
117
+ labelFormatter: tooltipLabel(props)
118
+ }),
119
+ series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
120
+ itemSorter: null,
121
+ formatter: legendText
122
+ }) : null,
51
123
  series.map((s, i) => /* @__PURE__ */ jsx(Line, {
52
124
  dataKey: s.key,
53
125
  name: s.label,
54
- stroke: color(s, i),
126
+ stroke: color(props, s, i),
55
127
  strokeWidth: 2,
56
- dot: false,
128
+ dot: lineDot(focused, s.key),
57
129
  isAnimationActive: false
58
130
  }, s.key))
59
131
  ]
60
- }) })
132
+ }) }), /* @__PURE__ */ jsx(Marks, {
133
+ drill,
134
+ drawn,
135
+ rows: answer.rows.length,
136
+ onFocusMark: setFocused
137
+ })]
61
138
  });
62
139
  }
63
140
  /** Bars per x value; when a second field splits them, its values stack, Other on top. */
64
141
  function BarTile(props) {
65
- const { answer, locale } = props;
66
- const { points, series, split } = toSeries(answer, props);
67
- return /* @__PURE__ */ jsx("div", {
142
+ const { answer, locale, drill } = props;
143
+ const [focused, setFocused] = useState(null);
144
+ const drawn = toSeries(answer, props);
145
+ const { points, series, split } = drawn;
146
+ return /* @__PURE__ */ jsxs("div", {
68
147
  className: "dd-chart",
69
- children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(BarChart, {
148
+ "data-drillable": drill !== void 0,
149
+ children: [/* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(BarChart, {
150
+ ...CHART,
70
151
  data: points,
71
- margin: {
72
- top: 4,
73
- right: 8,
74
- bottom: 0,
75
- left: 0
76
- },
152
+ maxBarSize: 56,
77
153
  children: [
78
154
  /* @__PURE__ */ jsx(CartesianGrid, {
79
155
  stroke: "var(--dd-line)",
@@ -94,23 +170,41 @@ function BarTile(props) {
94
170
  width: 56,
95
171
  tickFormatter: axisFormat(series, locale)
96
172
  }),
97
- /* @__PURE__ */ jsx(Tooltip, { formatter: tooltipFormat(series, props) }),
98
- series.length > 1 ? /* @__PURE__ */ jsx(Legend, { itemSorter: null }) : null,
173
+ /* @__PURE__ */ jsx(Tooltip, {
174
+ separator: ": ",
175
+ formatter: tooltipFormat(series, props),
176
+ labelFormatter: tooltipLabel(props)
177
+ }),
178
+ series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
179
+ itemSorter: null,
180
+ formatter: legendText
181
+ }) : null,
99
182
  series.map((s, i) => /* @__PURE__ */ jsx(Bar, {
100
183
  dataKey: s.key,
101
184
  name: s.label,
102
- fill: color(s, i),
103
- ...split ? { stackId: "split" } : {},
185
+ fill: color(props, s, i),
186
+ ...split ? {
187
+ stackId: "split",
188
+ stroke: "var(--dd-surface)",
189
+ strokeWidth: 2
190
+ } : {},
104
191
  radius: split && i < series.length - 1 ? 0 : [
105
192
  4,
106
193
  4,
107
194
  0,
108
195
  0
109
196
  ],
110
- isAnimationActive: false
197
+ isAnimationActive: false,
198
+ ...barClick(drill, drawn, s),
199
+ shape: barShape(focused, s.key)
111
200
  }, s.key))
112
201
  ]
113
- }) })
202
+ }) }), /* @__PURE__ */ jsx(Marks, {
203
+ drill,
204
+ drawn,
205
+ rows: answer.rows.length,
206
+ onFocusMark: setFocused
207
+ })]
114
208
  });
115
209
  }
116
210
  /** Register with `<DashboardsProvider renderers={RECHARTS_RENDERERS}>`. */
@@ -1,3 +1,3 @@
1
1
  import { BarTile, LineTile, RECHARTS_RENDERERS } from "./charts.mjs";
2
- import { Point, Series, toSeries } from "./series.mjs";
3
- export { BarTile, LineTile, type Point, RECHARTS_RENDERERS, type Series, toSeries };
2
+ import { Drawn, Point, Series, rowAt, toSeries } from "./series.mjs";
3
+ export { BarTile, type Drawn, LineTile, type Point, RECHARTS_RENDERERS, type Series, rowAt, toSeries };
@@ -1,3 +1,3 @@
1
1
  import { BarTile, LineTile, RECHARTS_RENDERERS } from "./charts.mjs";
2
- import { toSeries } from "./series.mjs";
3
- export { BarTile, LineTile, RECHARTS_RENDERERS, toSeries };
2
+ import { rowAt, toSeries } from "./series.mjs";
3
+ export { BarTile, LineTile, RECHARTS_RENDERERS, rowAt, toSeries };
@@ -0,0 +1,83 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/marks.tsx
4
+ /** The line a series draws: its own column, or for a split chart the value it splits. */
5
+ const entryOf = (s) => s.column.id;
6
+ /** Opens the drill of the row behind a point of a series, if a row stands behind it. */
7
+ function openPoint(drill, drawn, at) {
8
+ const row = drawn.rowAt(at.point, at.series.key);
9
+ if (drill !== void 0 && row !== void 0) drill.open(row, entryOf(at.series));
10
+ }
11
+ /**
12
+ * Whether a pointer is down, read when a mark loses focus: a blur from a press waits for the
13
+ * click to land before the chart redraws, since a redraw between press and release would swallow
14
+ * the click on the bar pressed. A blur from the keyboard clears at once.
15
+ */
16
+ function usePressing() {
17
+ const pressing = useRef(false);
18
+ useEffect(() => {
19
+ const down = () => {
20
+ pressing.current = true;
21
+ };
22
+ const up = () => {
23
+ queueMicrotask(() => {
24
+ pressing.current = false;
25
+ });
26
+ };
27
+ globalThis.addEventListener("pointerdown", down, true);
28
+ globalThis.addEventListener("pointerup", up, true);
29
+ return () => {
30
+ globalThis.removeEventListener("pointerdown", down, true);
31
+ globalThis.removeEventListener("pointerup", up, true);
32
+ };
33
+ }, []);
34
+ return (clear) => {
35
+ if (!pressing.current) {
36
+ clear();
37
+ return;
38
+ }
39
+ globalThis.addEventListener("click", clear, { once: true });
40
+ globalThis.addEventListener("pointercancel", clear, { once: true });
41
+ };
42
+ }
43
+ /**
44
+ * Every mark that opens, as a list of buttons a keyboard reaches, so the chart opens without a
45
+ * pointer. The list stays visually hidden and out of the chart's layout; the chart outlines the
46
+ * mark that has focus (`onFocusMark`). Each says its group and value, as a screen reader reads
47
+ * it. Nothing when drilling is off.
48
+ */
49
+ function Marks({ drill, drawn, rows, onFocusMark }) {
50
+ const clearAfterClick = usePressing();
51
+ if (drill === void 0) return null;
52
+ const marks = drawn.points.flatMap((_p, i) => drawn.series.flatMap((s) => {
53
+ const row = drawn.rowAt(i, s.key);
54
+ const props = row === void 0 || row >= rows ? void 0 : drill.props(row, entryOf(s));
55
+ return props === void 0 ? [] : [{
56
+ key: `${String(i)}-${s.key}`,
57
+ point: i,
58
+ series: s.key,
59
+ props
60
+ }];
61
+ }));
62
+ if (marks.length === 0) return null;
63
+ return /* @__PURE__ */ jsx("ul", {
64
+ className: "dd-chart-marks",
65
+ children: marks.map(({ key, point, series, props: { role: _role, tabIndex: _tab, ...props } }) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
66
+ type: "button",
67
+ ...props,
68
+ onFocus: () => {
69
+ onFocusMark({
70
+ point,
71
+ key: series
72
+ });
73
+ },
74
+ onBlur: () => {
75
+ clearAfterClick(() => {
76
+ onFocusMark(null);
77
+ });
78
+ },
79
+ children: props["aria-label"]
80
+ }) }, key))
81
+ });
82
+ }
83
+ export { Marks, openPoint };
@@ -1,22 +1,2 @@
1
- import { CellFormat } from "derive-dashboards/react";
2
- import { ResultColumn, TileAnswer } from "derive-dashboards/core";
3
- /** One point of a chart: its x label and a number per series key. */
4
- export type Point = {
5
- x: string;
6
- } & Record<string, number | string | null>;
7
- export type Series = {
8
- key: string;
9
- label: string;
10
- column: ResultColumn;
11
- };
12
- /**
13
- * Chart data from an answer. The first non-value column is the x axis (the time bucket when
14
- * there is one). With a second key column, the first value is split into one series per
15
- * value of it, and Other in that column is one more series; otherwise every value column is
16
- * its own series. Other on the x axis is one more point; totals are not drawn.
17
- */
18
- export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): {
19
- points: Point[];
20
- series: Series[];
21
- split: boolean;
22
- };
1
+ import { Drawn, Point, Series, rowAt, toSeries } from "derive-dashboards/react";
2
+ export { type Drawn, type Point, type Series, rowAt, toSeries };