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
@@ -14,7 +14,7 @@ type Props = {
14
14
  };
15
15
  /**
16
16
  * One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
17
- * on request. It draws again only when one of its props changes.
17
+ * on request (Rows opens its drill on Items). It draws again only when one of its props changes.
18
18
  */
19
19
  export declare const Tile: import("react").MemoExoticComponent<(props: Props) => import("react").JSX.Element>;
20
20
  export {};
@@ -1,12 +1,13 @@
1
1
  import { useDashboards } from "./context.mjs";
2
- import { RecordsPanel } from "./Records.mjs";
3
- import { memo, useState } from "react";
2
+ import { useTileDrill } from "./drill/host.mjs";
3
+ import { formatInstantAt } from "./format.mjs";
4
+ import { memo } from "react";
4
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
6
  // src/Tile.tsx
6
7
  /** Refusals that last only until the dashboard is read again, never shown as errors. */
7
8
  const PASSING = /* @__PURE__ */ new Set(["VERSION_CONFLICT", "TILE_UNKNOWN"]);
8
9
  /** The answer's state when there is nothing to draw yet or instead: waiting, refused, unreadable, empty. */
9
- function TileState({ result, loading }) {
10
+ function TileState({ result, loading, empty }) {
10
11
  const { messages } = useDashboards();
11
12
  if (result === void 0 || "error" in result && PASSING.has(result.error.code)) {
12
13
  const busy = result !== void 0 || loading;
@@ -31,24 +32,30 @@ function TileState({ result, loading }) {
31
32
  });
32
33
  return /* @__PURE__ */ jsx("div", {
33
34
  className: "dd-tile-state",
34
- children: messages.noData
35
+ children: empty
35
36
  });
36
37
  }
37
38
  /** Whether an answer has rows to draw. */
38
39
  const drawable = (result) => result !== void 0 && !("error" in result) && result.unreadable !== true && result.rows.length > 0;
39
40
  /** The answer drawn: a memo of its own, so a change to the tile's buttons or badge never draws the chart again. */
40
- const Body = memo(function Body({ widget, result, loading }) {
41
- const { renderers, locale, messages } = useDashboards();
42
- if (!drawable(result)) return /* @__PURE__ */ jsx(TileState, {
43
- result,
44
- loading
45
- });
41
+ const Body = memo(function Body({ widget, result, loading, drill }) {
42
+ const { renderers, locale, messages, link } = useDashboards();
43
+ if (!drawable(result)) {
44
+ const empty = widget.display?.["empty"];
45
+ return /* @__PURE__ */ jsx(TileState, {
46
+ result,
47
+ loading,
48
+ empty: typeof empty === "string" ? empty : messages.noData
49
+ });
50
+ }
46
51
  const Renderer = renderers[widget.kind] ?? renderers["table"];
47
52
  return Renderer === void 0 ? null : /* @__PURE__ */ jsx(Renderer, {
48
53
  answer: result,
49
54
  widget,
50
55
  messages,
51
- ...locale === void 0 ? {} : { locale }
56
+ ...locale === void 0 ? {} : { locale },
57
+ ...drill === void 0 ? {} : { drill },
58
+ ...link === void 0 ? {} : { link }
52
59
  });
53
60
  });
54
61
  /** Notes under a tile: a viewer's filter that could not apply, or an answer cut at the row cap. */
@@ -56,27 +63,48 @@ function Notes({ result, controlLabels }) {
56
63
  const { messages } = useDashboards();
57
64
  if (result === void 0 || "error" in result) return null;
58
65
  const dropped = result.receipt.coverage.dropped.map((id) => controlLabels?.get(id) ?? id);
59
- return /* @__PURE__ */ jsxs(Fragment, { children: [dropped.length === 0 ? null : /* @__PURE__ */ jsx("p", {
60
- className: "dd-tile-note",
61
- children: messages.notFilteredBy(dropped)
62
- }), result.status === "truncated" ? /* @__PURE__ */ jsx("p", {
63
- className: "dd-tile-note",
64
- children: messages.firstRows(result.rows.length)
65
- }) : null] });
66
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
67
+ dropped.length === 0 ? null : /* @__PURE__ */ jsx("p", {
68
+ className: "dd-tile-note",
69
+ children: messages.notFilteredBy(dropped)
70
+ }),
71
+ result.status === "truncated" ? /* @__PURE__ */ jsx("p", {
72
+ className: "dd-tile-note",
73
+ children: messages.firstRows(result.rows.length)
74
+ }) : null,
75
+ result.drill?.reason === void 0 ? null : /* @__PURE__ */ jsx("p", {
76
+ className: "dd-tile-note",
77
+ children: messages.drillCut
78
+ })
79
+ ] });
66
80
  }
67
81
  /** Whether a tile has rows behind it to show: an answer the viewer can read. */
68
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 }) {
85
+ const format = useDashboards();
86
+ if (result === void 0 || "error" in result) return null;
87
+ const range = result.receipt.range;
88
+ if (range === void 0) return null;
89
+ const zone = result.receipt.calendar.timezone;
90
+ const day = (at) => formatInstantAt(at, "day", format.locale, zone);
91
+ return /* @__PURE__ */ jsx("p", {
92
+ className: "dd-tile-span",
93
+ children: format.messages.drillRange(day(range.from), day(range.to))
94
+ });
95
+ }
69
96
  /**
70
97
  * One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
71
- * on request. It draws again only when one of its props changes.
98
+ * on request (Rows opens its drill on Items). It draws again only when one of its props changes.
72
99
  */
73
100
  const Tile = memo(function Tile(props) {
74
101
  const { messages } = useDashboards();
75
- const [open, setOpen] = useState(false);
102
+ const drill = useTileDrill(props.widgetId, props.result);
76
103
  return /* @__PURE__ */ jsxs("section", {
77
104
  className: "dd-tile",
78
105
  "aria-busy": props.loading,
79
106
  "data-kind": props.widget.kind,
107
+ "data-widget": props.widgetId,
80
108
  children: [
81
109
  /* @__PURE__ */ jsxs("header", {
82
110
  className: "dd-tile-header",
@@ -84,36 +112,32 @@ const Tile = memo(function Tile(props) {
84
112
  /* @__PURE__ */ jsx("h3", {
85
113
  className: "dd-tile-title",
86
114
  title: props.widget.title,
115
+ tabIndex: -1,
87
116
  children: props.widget.title
88
117
  }),
89
118
  props.badge,
90
119
  /* @__PURE__ */ jsxs("span", {
91
120
  className: "dd-tile-actions",
92
- children: [hasRows(props.result) ? /* @__PURE__ */ jsx("button", {
121
+ children: [hasRows(props.result) && drill !== void 0 ? /* @__PURE__ */ jsx("button", {
93
122
  type: "button",
94
123
  className: "dd-tile-rows",
95
124
  "aria-label": messages.rowsBehind(props.widget.title),
96
125
  onClick: () => {
97
- setOpen(true);
126
+ drill.openAll();
98
127
  },
99
128
  children: messages.rows
100
129
  }) : null, props.actions]
101
130
  })
102
131
  ]
103
132
  }),
104
- open ? /* @__PURE__ */ jsx(RecordsPanel, {
105
- widgetId: props.widgetId,
106
- widget: props.widget,
107
- onClose: () => {
108
- setOpen(false);
109
- }
110
- }) : null,
133
+ /* @__PURE__ */ jsx(Span, { result: props.result }),
111
134
  /* @__PURE__ */ jsx("div", {
112
135
  className: "dd-tile-body",
113
136
  children: /* @__PURE__ */ jsx(Body, {
114
137
  widget: props.widget,
115
138
  result: props.result,
116
- loading: props.result === void 0 && props.loading
139
+ loading: props.result === void 0 && props.loading,
140
+ drill
117
141
  })
118
142
  }),
119
143
  /* @__PURE__ */ jsx(Notes, { ...props })
@@ -1,6 +1,6 @@
1
1
  import "./base.mjs";
2
2
  import "./labels.mjs";
3
- import { DateRange, Grain, StoredQuery } from "derive-dashboards/core";
3
+ import { DateRange, Grain, Primitive, StoredQuery } from "derive-dashboards/core";
4
4
  type Time = NonNullable<StoredQuery["time"]>;
5
5
  /** A change to the time part. A grain of "total" is one total; a compare of "none" drops it. */
6
6
  export type TimeChange = {
@@ -20,6 +20,8 @@ export type DashboardsClient = {
20
20
  memberValues(request: BodyOf<"/meta/values">): Answer<"/meta/values">;
21
21
  /** A page of the rows behind a tile, under the same filters as its answer. */
22
22
  records(request: BodyOf<"/dashboards/records">): Answer<"/dashboards/records">;
23
+ /** The rows behind a mark: of a dashboard's tile, or (origin `query`) of a free query. */
24
+ drill(request: BodyOf<"/dashboards/drill">, signal?: AbortSignal): Answer<"/dashboards/drill">;
23
25
  /** The caller's open draft of a dashboard, or a new one from its current version. */
24
26
  startDraft(dashboardId: string): Answer<"/dashboards/draft/start">;
25
27
  /** A draft of a new dashboard, which only its maker sees until they publish it; `requestId` makes a retry create it once. */
@@ -85,6 +85,7 @@ function methods(core) {
85
85
  getDashboard: (dashboardId) => core("/dashboards/get", { dashboardId }),
86
86
  controlValues: (body) => core("/dashboards/control-values", body),
87
87
  records: (body) => core("/dashboards/records", body),
88
+ drill: (body, signal) => body.state.origin.kind === "query" ? core("/query/drill", body, signal) : core("/dashboards/drill", body, signal),
88
89
  queryRun: (query, signal) => core("/query/run", { query }, signal),
89
90
  memberValues: (body) => core("/meta/values", body),
90
91
  startDraft: (dashboardId) => core("/dashboards/draft/start", { dashboardId }),
@@ -1,14 +1,26 @@
1
1
  import { DashboardsClient } from "./client.mjs";
2
2
  import { Messages } from "./messages.mjs";
3
3
  import { TileRenderer } from "./renderers/index.mjs";
4
- import { ReactNode } from "react";
4
+ import { ComponentType, MouseEvent, ReactNode } from "react";
5
5
  import { Author } from "derive-dashboards/core";
6
+ /** The props every link the library draws passes: a router's link component takes them. */
7
+ export type LinkProps = {
8
+ href: string;
9
+ className?: string;
10
+ children: ReactNode;
11
+ onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
12
+ };
13
+ /** A link component, such as Next.js's `Link`; a plain `<a>` by default. */
14
+ export type LinkComponent = ComponentType<LinkProps>;
6
15
  type Value = {
7
16
  client: DashboardsClient;
17
+ link?: LinkComponent;
8
18
  renderers: Record<string, TileRenderer>;
9
19
  locale?: string;
10
20
  messages: Messages;
11
21
  authorName?: (author: Author) => string | undefined;
22
+ /** Who answers and for whom: the viewer's key and the client, so no cache serves another viewer. */
23
+ cacheScope: string;
12
24
  };
13
25
  export type DashboardsProviderProps = {
14
26
  client: DashboardsClient;
@@ -25,6 +37,8 @@ export type DashboardsProviderProps = {
25
37
  viewerKey?: string;
26
38
  /** A person's or agent's name, for the history; without it, versions show only when. */
27
39
  authorName?: (author: Author) => string | undefined;
40
+ /** The link component every link the library draws uses, so they go through your router. */
41
+ link?: LinkComponent;
28
42
  children: ReactNode;
29
43
  };
30
44
  export declare function DashboardsProvider(props: DashboardsProviderProps): import("react").JSX.Element;
@@ -4,13 +4,25 @@ import { createContext, useContext, useMemo } from "react";
4
4
  import { SWRConfig } from "swr";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  // src/context.tsx
7
+ /** A stable number per client, so a new client starts its own caches. */
8
+ const clientIds = /* @__PURE__ */ new WeakMap();
9
+ const counted = { clients: 0 };
10
+ function clientId(client) {
11
+ const known = clientIds.get(client);
12
+ if (known !== void 0) return known;
13
+ counted.clients += 1;
14
+ clientIds.set(client, counted.clients);
15
+ return counted.clients;
16
+ }
7
17
  const Context = createContext(null);
8
18
  /** A cache of the provider's own, so answers never mix with the host's or another viewer's. */
9
19
  const ownCache = { provider: () => /* @__PURE__ */ new Map() };
10
20
  function DashboardsProvider(props) {
11
- const { client, renderers, locale, messages, viewerKey, authorName, children } = props;
21
+ const { client, renderers, locale, messages, viewerKey, authorName, link, children } = props;
22
+ const cacheScope = `${viewerKey ?? ""}:${String(clientId(client))}`;
12
23
  const value = useMemo(() => ({
13
24
  client,
25
+ cacheScope,
14
26
  renderers: {
15
27
  ...BUILTIN_RENDERERS,
16
28
  ...renderers
@@ -20,13 +32,16 @@ function DashboardsProvider(props) {
20
32
  ...ENGLISH,
21
33
  ...messages
22
34
  },
23
- ...authorName === void 0 ? {} : { authorName }
35
+ ...authorName === void 0 ? {} : { authorName },
36
+ ...link === void 0 ? {} : { link }
24
37
  }), [
25
38
  client,
39
+ cacheScope,
26
40
  renderers,
27
41
  locale,
28
42
  messages,
29
- authorName
43
+ authorName,
44
+ link
30
45
  ]);
31
46
  return /* @__PURE__ */ jsx(SWRConfig, {
32
47
  value: ownCache,
@@ -34,7 +49,7 @@ function DashboardsProvider(props) {
34
49
  value,
35
50
  children
36
51
  })
37
- }, viewerKey);
52
+ }, cacheScope);
38
53
  }
39
54
  function useDashboards() {
40
55
  const value = useContext(Context);
@@ -0,0 +1,179 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatBucket, formatCell, plotValue } from "../format.mjs";
3
+ import { rowEntry } from "./state.mjs";
4
+ import { isMark } from "derive-dashboards/core";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ // src/drill/Bars.tsx
7
+ /** A row's name: its time bucket or its group, as the tile names it ("No assignee" for no value). */
8
+ function rowName(view, row, format) {
9
+ const [cell = null] = row;
10
+ const [column] = view.answer.columns;
11
+ return isMark(cell) || cell === null || cell === "" ? markName(cell, column?.label ?? "", format) : valueName(cell, column, format);
12
+ }
13
+ /** Other, Total, or "No assignee" for a group with no value. */
14
+ const markName = (cell, label, format) => isMark(cell) ? cell.mark === "other" ? format.messages.other : format.messages.total : format.messages.drillNone(label);
15
+ /** A group's value as the tile names it: a time bucket at its grain, else the formatted value. */
16
+ function valueName(cell, column, format) {
17
+ if (column?.grain !== void 0 && typeof cell === "string") return formatBucket(cell, column.grain, format.locale);
18
+ return formatCell(cell, column, format);
19
+ }
20
+ /** The line's column: the one named, else the first value column. */
21
+ const lineAt = (view, entry) => {
22
+ const named = view.answer.columns.findIndex((c) => c.id === entry);
23
+ return named >= 0 ? named : view.answer.columns.findIndex((c) => c.id.startsWith("m"));
24
+ };
25
+ /** A change with its sign: "+6" when it went up. */
26
+ const signed = (text, size) => size > 0 && !text.startsWith("+") ? `+${text}` : text;
27
+ const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
28
+ /**
29
+ * Each row as a bar: sized by its value, or for a Breakdown of the change by its change, and
30
+ * read as the value, or as now, before and the change. A total is not drawn.
31
+ */
32
+ function barsOf(view, entry, format) {
33
+ const { columns } = view.answer;
34
+ const at = lineAt(view, entry);
35
+ const before = columns.findIndex((c) => c.id === "c1");
36
+ const rows = view.answer.rows.map((row, i) => ({
37
+ row,
38
+ selection: rowEntry(view.drill, i)
39
+ })).filter(({ row }) => !isAll(row));
40
+ const change = columns.findIndex((c) => c.id === "c2");
41
+ const compared = view.change === true && rows.some(({ row }) => (row[change] ?? null) !== null);
42
+ const sized = compared ? change : at;
43
+ const max = Math.max(0, ...rows.map(({ row }) => Math.abs(plotValue(row[sized] ?? null) ?? 0)));
44
+ const text = (row, i) => formatCell(row[i] ?? null, columns[i], format);
45
+ return rows.map(({ row, selection }) => {
46
+ const size = plotValue(row[sized] ?? null) ?? 0;
47
+ return {
48
+ bar: {
49
+ name: rowName(view, row, format),
50
+ width: max === 0 ? 0 : Math.abs(size) / max * 100,
51
+ negative: size < 0,
52
+ text: compared && (row[before] ?? null) !== null ? format.messages.drillChange(text(row, at), formatCell(row[before] ?? null, columns[at], format), signed(text(row, sized), size)) : text(row, at)
53
+ },
54
+ selection
55
+ };
56
+ });
57
+ }
58
+ /** One bar: its name, its bar to scale, its value; a button when it goes deeper. */
59
+ function BarRow(props) {
60
+ const { bar, selection } = props;
61
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ /* @__PURE__ */ jsx("span", {
63
+ className: "dd-drill-bar-name",
64
+ children: bar.name
65
+ }),
66
+ /* @__PURE__ */ jsx("span", {
67
+ className: "dd-drill-bar-track",
68
+ "aria-hidden": "true",
69
+ children: /* @__PURE__ */ jsx("span", {
70
+ className: "dd-drill-bar",
71
+ "data-negative": bar.negative,
72
+ style: { inlineSize: `${bar.width}%` }
73
+ })
74
+ }),
75
+ /* @__PURE__ */ jsx("span", {
76
+ className: "dd-drill-bar-value",
77
+ children: bar.text
78
+ })
79
+ ] });
80
+ const label = `${bar.name}, ${bar.text}`;
81
+ if (selection === void 0) return /* @__PURE__ */ jsx("div", {
82
+ className: "dd-drill-bar-row",
83
+ children: body
84
+ });
85
+ return /* @__PURE__ */ jsx("button", {
86
+ type: "button",
87
+ className: "dd-drill-bar-row",
88
+ "aria-label": label,
89
+ onClick: () => {
90
+ props.onOpen(selection);
91
+ },
92
+ children: body
93
+ });
94
+ }
95
+ /** A Breakdown of the change's total row and where its before and change sit, when it has one to say. */
96
+ function comparedTotal(view) {
97
+ const total = view.answer.rows.find((row) => isAll(row));
98
+ const { columns } = view.answer;
99
+ const before = columns.findIndex((c) => c.id === "c1");
100
+ const change = columns.findIndex((c) => c.id === "c2");
101
+ if (view.change !== true || total === void 0 || change < 0) return;
102
+ return (total[before] ?? null) === null ? void 0 : {
103
+ total,
104
+ before,
105
+ change
106
+ };
107
+ }
108
+ /** The whole change in a Breakdown of the change: "vs 169, +33", from its total row. */
109
+ function changeLine(view, entry, format) {
110
+ const compared = comparedTotal(view);
111
+ if (compared === void 0) return void 0;
112
+ const { total, before, change } = compared;
113
+ const { columns } = view.answer;
114
+ const at = lineAt(view, entry);
115
+ const size = plotValue(total[change] ?? null) ?? 0;
116
+ return format.messages.drillVersus(formatCell(total[before] ?? null, columns[at], format), signed(formatCell(total[change] ?? null, columns[change], format), size));
117
+ }
118
+ /** Over time as columns, oldest to newest: each bucket a column to scale, a button when it goes deeper. */
119
+ function Columns(props) {
120
+ return /* @__PURE__ */ jsx("ol", {
121
+ className: "dd-drill-columns",
122
+ children: props.bars.map(({ bar, selection }, i) => {
123
+ const label = `${bar.name}, ${bar.text}`;
124
+ const column = /* @__PURE__ */ jsx("span", {
125
+ className: "dd-drill-column",
126
+ "data-negative": bar.negative,
127
+ style: { blockSize: `${Math.max(bar.width, 2)}%` }
128
+ });
129
+ return /* @__PURE__ */ jsx("li", {
130
+ title: label,
131
+ children: selection === void 0 ? /* @__PURE__ */ jsx("span", {
132
+ role: "img",
133
+ "aria-label": label,
134
+ children: column
135
+ }) : /* @__PURE__ */ jsx("button", {
136
+ type: "button",
137
+ "aria-label": label,
138
+ onClick: () => {
139
+ props.onOpen(selection);
140
+ },
141
+ children: column
142
+ })
143
+ }, i);
144
+ })
145
+ });
146
+ }
147
+ /**
148
+ * A Breakdown as a list of bars, or Over time as columns: each group or bucket with its value
149
+ * to scale and, when it drills, a button that goes one step deeper. A total is not drawn; a
150
+ * Breakdown of the change says the whole change first.
151
+ */
152
+ function Bars(props) {
153
+ const format = useDashboards();
154
+ const { view } = props;
155
+ const bars = barsOf(view, props.entry, format);
156
+ if (bars.length === 0) return /* @__PURE__ */ jsx("p", {
157
+ className: "dd-tile-state",
158
+ children: view.search === void 0 ? format.messages.drillNoGroups : format.messages.drillNoMatch
159
+ });
160
+ if (view.by === "trend") return /* @__PURE__ */ jsx(Columns, {
161
+ bars,
162
+ onOpen: props.onOpen
163
+ });
164
+ const change = changeLine(view, props.entry, format);
165
+ return /* @__PURE__ */ jsxs(Fragment, { children: [change === void 0 ? null : /* @__PURE__ */ jsx("p", {
166
+ className: "dd-drill-versus",
167
+ children: change
168
+ }), /* @__PURE__ */ jsx("ul", {
169
+ className: "dd-drill-bars",
170
+ "data-by": view.by,
171
+ "data-change": view.change === true,
172
+ children: bars.map(({ bar, selection }, i) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(BarRow, {
173
+ bar,
174
+ selection,
175
+ onOpen: props.onOpen
176
+ }) }, i))
177
+ })] });
178
+ }
179
+ export { Bars };
@@ -0,0 +1,173 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell, formatInstantAt } from "../format.mjs";
3
+ import { useEffect, useState } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ // src/drill/Controls.tsx
6
+ /** Over time's range in words and its grain picker. */
7
+ function TrendControls({ d }) {
8
+ const format = useDashboards();
9
+ const { messages } = format;
10
+ const shown = d.shown;
11
+ if (shown?.by !== "trend") return null;
12
+ const zone = d.summary?.receipt.calendar.timezone;
13
+ const range = shown.range;
14
+ const day = (text) => formatInstantAt(text, "day", format.locale, zone);
15
+ return /* @__PURE__ */ jsxs("div", {
16
+ className: "dd-drill-controls",
17
+ children: [range === void 0 ? null : /* @__PURE__ */ jsx("span", {
18
+ className: "dd-drill-range",
19
+ children: messages.drillRange(day(range.from), day(range.to))
20
+ }), (shown.grains ?? []).length < 2 ? null : /* @__PURE__ */ jsxs("label", {
21
+ className: "dd-drill-by",
22
+ children: [/* @__PURE__ */ jsx("span", {
23
+ className: "dd-sr-only",
24
+ children: messages.drillViews.trend
25
+ }), /* @__PURE__ */ jsx("select", {
26
+ value: shown.grain ?? "",
27
+ onChange: (e) => {
28
+ d.setView({
29
+ by: "trend",
30
+ grain: e.target.value
31
+ });
32
+ },
33
+ children: (shown.grains ?? []).map((g) => /* @__PURE__ */ jsx("option", {
34
+ value: g,
35
+ children: messages.drillGrains[g]
36
+ }, g))
37
+ })]
38
+ })]
39
+ });
40
+ }
41
+ /** Breakdown's field picker, and a search in a field with more values than it draws; Over time's grain. */
42
+ function FieldPicker({ d }) {
43
+ const { messages } = useDashboards();
44
+ const shown = d.shown;
45
+ if (shown?.by === "trend") return /* @__PURE__ */ jsx(TrendControls, { d });
46
+ if (shown?.by !== "breakdown") return null;
47
+ const member = shown.member ?? "";
48
+ return /* @__PURE__ */ jsxs("div", {
49
+ className: "dd-drill-controls",
50
+ children: [/* @__PURE__ */ jsxs("label", {
51
+ className: "dd-drill-by",
52
+ children: [
53
+ messages.drillBy,
54
+ " ",
55
+ /* @__PURE__ */ jsx("select", {
56
+ value: member,
57
+ onChange: (e) => {
58
+ d.setView({
59
+ by: "breakdown",
60
+ member: e.target.value
61
+ });
62
+ },
63
+ children: shown.offered.map((f) => /* @__PURE__ */ jsx("option", {
64
+ value: f.id,
65
+ children: f.label
66
+ }, f.id))
67
+ })
68
+ ]
69
+ }), shown.searchable === true ? /* @__PURE__ */ jsx(Search, {
70
+ d,
71
+ member,
72
+ text: shown.search ?? ""
73
+ }) : null]
74
+ });
75
+ }
76
+ /** A search in a field's values; it asks again a moment after the person stops typing. */
77
+ function Search({ d, member, text }) {
78
+ const { messages } = useDashboards();
79
+ const [typed, setTyped] = useState(text);
80
+ const { setView } = d;
81
+ useEffect(() => {
82
+ if (typed === text) return;
83
+ const wait = setTimeout(() => {
84
+ setView({
85
+ by: "breakdown",
86
+ member,
87
+ ...typed === "" ? {} : { search: typed }
88
+ });
89
+ }, 300);
90
+ return () => {
91
+ clearTimeout(wait);
92
+ };
93
+ }, [
94
+ typed,
95
+ text,
96
+ member,
97
+ setView
98
+ ]);
99
+ return /* @__PURE__ */ jsx("input", {
100
+ type: "search",
101
+ className: "dd-drill-search",
102
+ "aria-label": messages.drillSearch,
103
+ placeholder: messages.drillSearch,
104
+ value: typed,
105
+ onChange: (e) => {
106
+ setTyped(e.target.value);
107
+ },
108
+ onKeyDown: (e) => {
109
+ if (e.key !== "Escape" || typed === "") return;
110
+ e.stopPropagation();
111
+ setTyped("");
112
+ }
113
+ });
114
+ }
115
+ /** A ratio's Items: a toggle that lists only the rows its numerator counts. */
116
+ function OnlyToggle({ d }) {
117
+ const format = useDashboards();
118
+ const numerator = d.items.view?.numerator;
119
+ if (numerator === void 0) return null;
120
+ const count = numerator.count === void 0 ? "" : formatCell(numerator.count, { type: "int" }, format);
121
+ const only = numerator.only === true;
122
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
123
+ type: "button",
124
+ className: "dd-drill-only",
125
+ "aria-pressed": only,
126
+ onClick: () => {
127
+ d.setView(only ? { by: "items" } : {
128
+ by: "items",
129
+ numerator: true
130
+ });
131
+ },
132
+ children: format.messages.drillOnly(numerator.label, count)
133
+ }), numerator.unmarked === true ? /* @__PURE__ */ jsx("p", {
134
+ className: "dd-tile-note",
135
+ children: format.messages.drillReasons.RATIO_UNMARKED
136
+ }) : null] });
137
+ }
138
+ /** A formula's parts: each measure it reads with its value, each opening its own drill. */
139
+ function Operands({ d }) {
140
+ const format = useDashboards();
141
+ const shown = d.shown;
142
+ if (shown?.by !== "explanation") return null;
143
+ return /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsx("h4", { children: format.messages.drillOperands }), /* @__PURE__ */ jsx("ul", {
144
+ className: "dd-drill-operands",
145
+ children: shown.operands.map((o) => {
146
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
147
+ /* @__PURE__ */ jsxs("span", { children: [
148
+ o.label,
149
+ " ",
150
+ /* @__PURE__ */ jsx("span", {
151
+ className: "dd-drill-scope",
152
+ children: format.messages.drillScope[o.scope]
153
+ })
154
+ ] }),
155
+ " ",
156
+ /* @__PURE__ */ jsx("strong", { children: formatCell(o.value, {}, format) })
157
+ ] });
158
+ const state = o.state;
159
+ return /* @__PURE__ */ jsx("li", { children: state === void 0 || !o.can.ok ? /* @__PURE__ */ jsx("div", {
160
+ className: "dd-drill-bar-row",
161
+ children: body
162
+ }) : /* @__PURE__ */ jsx("button", {
163
+ type: "button",
164
+ className: "dd-drill-bar-row",
165
+ onClick: () => {
166
+ d.openState(state);
167
+ },
168
+ children: body
169
+ }) }, `${o.entry}-${o.scope}`);
170
+ })
171
+ })] });
172
+ }
173
+ export { FieldPicker, OnlyToggle, Operands };
@@ -0,0 +1,18 @@
1
+ import { DashboardDrillProps } from "./board.mjs";
2
+ import { DrillChange } from "./state.mjs";
3
+ import { DrillState, Picks } from "derive-dashboards/core";
4
+ export type DashboardTileProps = DashboardDrillProps & {
5
+ dashboardId: string;
6
+ widgetId: string;
7
+ /** The dashboard's filters, set by the host (a record page's own id, say). */
8
+ picks?: Picks;
9
+ /** The drill open under the tile, when the host keeps it (in its URL, say); its own otherwise. */
10
+ state?: DrillState | undefined;
11
+ /** The drill changed: with `state`, the host keeps the next one. */
12
+ onStateChange?: DrillChange;
13
+ };
14
+ /**
15
+ * One tile of a dashboard on its own, for a record page or a report: drawn as on its dashboard,
16
+ * with the same drill. Unless the host takes a drill (`onDrill`), it opens under the tile.
17
+ */
18
+ export declare function DashboardTile(props: DashboardTileProps): import("react").JSX.Element;