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,107 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { Tile } from "../Tile.mjs";
3
+ import { useDashboard } from "../useDashboard.mjs";
4
+ import { useTiles } from "../useTiles.mjs";
5
+ import { DrillHostContext } from "./host.mjs";
6
+ import { DrillPanel } from "./lazy.mjs";
7
+ import { useMemo, useRef, useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ // src/drill/DashboardTile.tsx
10
+ const NO_EVENTS = {};
11
+ /** The tile's drill host: drills start at this tile; the host may take one, else it opens here. */
12
+ function useTileHost(props, picks, open) {
13
+ const latest = useRef({
14
+ props,
15
+ open
16
+ });
17
+ latest.current = {
18
+ props,
19
+ open
20
+ };
21
+ const { dashboardId, drill } = props;
22
+ return useMemo(() => drill === false ? null : {
23
+ origin: (id) => ({
24
+ kind: "dashboard",
25
+ dashboardId,
26
+ widgetId: id,
27
+ picks
28
+ }),
29
+ onDrill: (state) => {
30
+ let prevented = false;
31
+ latest.current.props.onDrill?.({
32
+ state,
33
+ preventDefault: () => {
34
+ prevented = true;
35
+ }
36
+ });
37
+ if (!prevented) latest.current.open(state);
38
+ }
39
+ }, [
40
+ dashboardId,
41
+ picks,
42
+ drill
43
+ ]);
44
+ }
45
+ /**
46
+ * One tile of a dashboard on its own, for a record page or a report: drawn as on its dashboard,
47
+ * with the same drill. Unless the host takes a drill (`onDrill`), it opens under the tile.
48
+ */
49
+ function DashboardTile(props) {
50
+ const { messages } = useDashboards();
51
+ const { dashboardId, widgetId } = props;
52
+ const picks = useMemo(() => props.picks ?? {}, [props.picks]);
53
+ const loaded = useDashboard(dashboardId, NO_EVENTS, false);
54
+ const widget = loaded.doc?.widgets[widgetId];
55
+ const tab = {
56
+ id: "tile",
57
+ title: "",
58
+ layout: [{
59
+ widget: widgetId,
60
+ x: 0,
61
+ y: 0,
62
+ w: 12,
63
+ h: 4
64
+ }]
65
+ };
66
+ const tiles = useTiles({
67
+ dashboardId,
68
+ doc: loaded.doc,
69
+ tab,
70
+ picks,
71
+ source: { version: loaded.version },
72
+ onStale: loaded.refresh
73
+ });
74
+ const [own, setOwn] = useState();
75
+ const controlled = "state" in props;
76
+ const drill = controlled ? props.state : own;
77
+ const change = (next, history) => {
78
+ if (!controlled) setOwn(next);
79
+ props.onStateChange?.(next, history);
80
+ };
81
+ const host = useTileHost(props, picks, (state) => {
82
+ change(state, "push");
83
+ });
84
+ if (widget === void 0) return /* @__PURE__ */ jsx("div", {
85
+ className: "dd-tile-state",
86
+ "aria-busy": loaded.error ? void 0 : true,
87
+ children: loaded.error ? messages.dashboardMissing : messages.loading
88
+ });
89
+ return /* @__PURE__ */ jsx(DrillHostContext.Provider, {
90
+ value: host,
91
+ children: /* @__PURE__ */ jsxs("div", {
92
+ className: "dd-dashboard-tile",
93
+ children: [/* @__PURE__ */ jsx(Tile, {
94
+ widgetId,
95
+ widget,
96
+ result: tiles.results.get(widgetId),
97
+ loading: tiles.pending.has(widgetId)
98
+ }), /* @__PURE__ */ jsx(DrillPanel, {
99
+ ...props,
100
+ state: drill,
101
+ title: widget.title,
102
+ onStateChange: change
103
+ })]
104
+ })
105
+ });
106
+ }
107
+ export { DashboardTile };
@@ -0,0 +1,31 @@
1
+ import { ItemOptions } from "./Items.mjs";
2
+ import { DrillChange } from "./state.mjs";
3
+ import { DrillController } from "./useDrill.mjs";
4
+ import { ComponentType, ReactNode } from "react";
5
+ import { DrillState } from "derive-dashboards/core";
6
+ export type PanelOptions = ItemOptions & {
7
+ /** The panel's title: the tile's. */
8
+ title?: string;
9
+ /** Close; by default, the state goes to undefined. */
10
+ onClose?: () => void;
11
+ /** Buttons of the host's own, under the views. */
12
+ actions?: ReactNode;
13
+ /** Replace the states the panel draws. */
14
+ components?: {
15
+ Loading?: ComponentType;
16
+ Empty?: ComponentType;
17
+ };
18
+ };
19
+ /**
20
+ * The panel over a drill state the host keeps (`state`, `onStateChange`), or over a controller it
21
+ * already holds (`controller`, from `useDrill`), which carries the state itself.
22
+ */
23
+ export type DrillPanelProps = PanelOptions & ({
24
+ state: DrillState | undefined;
25
+ onStateChange: DrillChange;
26
+ controller?: undefined;
27
+ } | {
28
+ controller: DrillController;
29
+ state?: undefined;
30
+ onStateChange?: undefined;
31
+ });
@@ -0,0 +1,104 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { Tabs } from "./DrillTabs.mjs";
3
+ import { Crumbs, DrillHead, Value, crumbText } from "./Header.mjs";
4
+ import { Main } from "./PanelBody.mjs";
5
+ import { SeeRows } from "./PanelStates.mjs";
6
+ import { useFocusReturn, usePeek } from "./panel-focus.mjs";
7
+ import { useDrill } from "./useDrill.mjs";
8
+ import { useRef } from "react";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ // src/drill/DrillPanel.tsx
11
+ /** The panel over its own controller. */
12
+ function OwnController(props) {
13
+ const d = useDrill({
14
+ state: props.state,
15
+ onStateChange: props.onStateChange
16
+ });
17
+ return /* @__PURE__ */ jsx(Panel, {
18
+ ...props,
19
+ d
20
+ });
21
+ }
22
+ /** Escape closes the drill; the dashboard's own Escape would close it again, so it stops here. */
23
+ function closeOnEscape(event, close) {
24
+ if (event.key !== "Escape") return;
25
+ event.stopPropagation();
26
+ close();
27
+ }
28
+ /** The step before by name: its value, or the tile's title for its total (a number tile's root). */
29
+ function parentText(parent, title, named) {
30
+ if (parent === void 0) return void 0;
31
+ return parent.kind === "total" ? title : named(parent);
32
+ }
33
+ /** The widget a dashboard's drill opened from: its tile is lit, and focus goes back to it. */
34
+ const widgetOf = (state) => state?.origin.kind === "dashboard" ? state.origin.widgetId : void 0;
35
+ function Panel({ d, ...props }) {
36
+ const format = useDashboards();
37
+ const panel = useRef(null);
38
+ useFocusReturn(panel, widgetOf(d.state));
39
+ const [peek, expand] = usePeek();
40
+ if (d.state === void 0) return null;
41
+ const title = props.title ?? format.messages.drillTitle;
42
+ const close = props.onClose ?? d.close;
43
+ const zone = d.summary?.receipt.calendar.timezone;
44
+ const parent = d.path.at(-2);
45
+ return /* @__PURE__ */ jsxs("aside", {
46
+ ref: panel,
47
+ className: "dd-panel dd-drill",
48
+ "aria-label": title,
49
+ "data-peek": peek,
50
+ onKeyDown: (event) => {
51
+ closeOnEscape(event, close);
52
+ },
53
+ children: [
54
+ /* @__PURE__ */ jsx(DrillHead, {
55
+ title,
56
+ step: JSON.stringify(d.state.path),
57
+ onBack: d.back,
58
+ onClose: close
59
+ }),
60
+ /* @__PURE__ */ jsx(Crumbs, {
61
+ root: title,
62
+ path: d.path,
63
+ timeZone: zone,
64
+ onGoTo: d.goTo
65
+ }),
66
+ d.summary === void 0 ? null : /* @__PURE__ */ jsx(Value, {
67
+ summary: d.summary,
68
+ parent: parentText(parent, title, (c) => crumbText(c, format, zone)),
69
+ onRefresh: d.retry
70
+ }),
71
+ peek ? /* @__PURE__ */ jsx(SeeRows, {
72
+ d,
73
+ onExpand: expand
74
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [
75
+ /* @__PURE__ */ jsx(Tabs, { d }),
76
+ /* @__PURE__ */ jsx(Main, {
77
+ d,
78
+ props,
79
+ close
80
+ }),
81
+ props.actions === void 0 ? null : /* @__PURE__ */ jsx("div", {
82
+ className: "dd-panel-foot",
83
+ children: props.actions
84
+ })
85
+ ] })
86
+ ]
87
+ });
88
+ }
89
+ /**
90
+ * The rows behind a mark, beside the dashboard or wherever the host places it: the path as
91
+ * breadcrumbs, the value and the rows behind it, the views (Breakdown, Over time, Items, and
92
+ * Explanation for a formula), each a click deeper. It sits on `useDrill` (its own, or the
93
+ * host's `controller`); its state is the host's, told back through `onStateChange` with
94
+ * whether Back should undo the change. Closing gives focus back to what opened it.
95
+ */
96
+ function DrillPanel(props) {
97
+ const { controller } = props;
98
+ if (controller !== void 0) return /* @__PURE__ */ jsx(Panel, {
99
+ ...props,
100
+ d: controller
101
+ });
102
+ return /* @__PURE__ */ jsx(OwnController, { ...props });
103
+ }
104
+ export { DrillPanel };
@@ -0,0 +1,52 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/drill/DrillTabs.tsx
4
+ const VIEWS = [
5
+ "breakdown",
6
+ "trend",
7
+ "items",
8
+ "explanation"
9
+ ];
10
+ /** The views as tabs, a roving tab stop moved by the arrow keys; one the drill cannot show is disabled, with its reason. */
11
+ function Tabs({ d }) {
12
+ const { messages } = useDashboards();
13
+ const can = d.summary?.can;
14
+ if (can === void 0) return null;
15
+ const shown = VIEWS.filter((v) => can[v].ok || d.view?.by === v);
16
+ const open = (v) => {
17
+ const first = d.summary?.offered[0]?.id;
18
+ const view = v === "breakdown" && first !== void 0 ? {
19
+ by: v,
20
+ member: first
21
+ } : { by: v };
22
+ d.setView(view);
23
+ };
24
+ const onKey = (event) => {
25
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
26
+ const tabs = [...event.currentTarget.querySelectorAll("[role=tab]:not(:disabled)")];
27
+ const { target } = event;
28
+ tabs[((target instanceof HTMLButtonElement ? tabs.indexOf(target) : -1) + (event.key === "ArrowRight" ? 1 : tabs.length - 1)) % tabs.length]?.focus();
29
+ };
30
+ return /* @__PURE__ */ jsx("div", {
31
+ className: "dd-drill-tabs",
32
+ role: "tablist",
33
+ onKeyDown: onKey,
34
+ children: shown.map((v) => {
35
+ const ok = can[v];
36
+ const selected = d.view?.by === v;
37
+ return /* @__PURE__ */ jsx("button", {
38
+ type: "button",
39
+ role: "tab",
40
+ "aria-selected": selected,
41
+ tabIndex: selected ? 0 : -1,
42
+ disabled: !ok.ok,
43
+ title: ok.ok ? void 0 : messages.drillReasons[ok.code],
44
+ onClick: () => {
45
+ open(v);
46
+ },
47
+ children: messages.drillViews[v]
48
+ }, v);
49
+ })
50
+ });
51
+ }
52
+ export { Tabs };
@@ -0,0 +1,131 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell, formatInstantAt } from "../format.mjs";
3
+ import { countOf, countText } from "./counts.mjs";
4
+ import { Notes, valueColumn } from "./Notes.mjs";
5
+ import { useEffect, useRef } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // src/drill/Header.tsx
8
+ /** A number of rows in words: "36 orders" with the source's noun, else "36 rows". */
9
+ function rowsText(count, summary, format) {
10
+ if (count === void 0) return count;
11
+ const text = countText(count, format);
12
+ const noun = summary.noun;
13
+ if (noun === void 0) return format.messages.drillRows(text);
14
+ return `${text} ${countOf(count) === 1 ? noun.one : noun.other}`;
15
+ }
16
+ /** Whether the line is the row count itself (a count of its rows), so the header says it once. */
17
+ const sameCount = (summary) => summary.counted === true && summary.itemCount !== void 0 && JSON.stringify(summary.itemCount) === JSON.stringify(summary.value);
18
+ /** The source's noun alone, for a count that is its rows: "orders". */
19
+ function nounOnly(summary, format) {
20
+ const n = countOf(summary.value);
21
+ if (summary.noun === void 0) return format.messages.drillNoun(n);
22
+ return n === 1 ? summary.noun.one : summary.noun.other;
23
+ }
24
+ /** The panel's head: Back, its title, Close. The title takes focus whenever the step changes. */
25
+ function DrillHead(props) {
26
+ const { messages } = useDashboards();
27
+ const heading = useRef(null);
28
+ const { step } = props;
29
+ useEffect(() => {
30
+ if (step !== "") heading.current?.focus({ preventScroll: true });
31
+ }, [step]);
32
+ return /* @__PURE__ */ jsxs("header", {
33
+ className: "dd-panel-head dd-drill-head",
34
+ children: [
35
+ /* @__PURE__ */ jsxs("button", {
36
+ type: "button",
37
+ className: "dd-button dd-quiet",
38
+ onClick: props.onBack,
39
+ children: ["‹ ", messages.drillBack]
40
+ }),
41
+ /* @__PURE__ */ jsx("h3", {
42
+ ref: heading,
43
+ tabIndex: -1,
44
+ children: props.title
45
+ }),
46
+ /* @__PURE__ */ jsx("button", {
47
+ type: "button",
48
+ className: "dd-button dd-quiet",
49
+ "aria-keyshortcuts": "Escape",
50
+ onClick: props.onClose,
51
+ children: messages.close
52
+ })
53
+ ]
54
+ });
55
+ }
56
+ /** One breadcrumb's text: a time point at its grain in the dashboard's zone, Other of its field, a missing value by its field. */
57
+ /** A step that is not one value: Other, the whole tile, or a search. */
58
+ function markedText(c, messages) {
59
+ if (c.kind === "other") return messages.drillOtherOf(c.label);
60
+ if (c.kind === "total") return c.previous === true ? messages.drillPeriodBefore : messages.total;
61
+ if (c.kind === "search") return `"${typeof c.value === "string" ? c.value : JSON.stringify(c.value)}"`;
62
+ }
63
+ function crumbText(c, format, timeZone) {
64
+ const { messages } = format;
65
+ if (c.parts !== void 0) return c.parts.filter((p) => p.kind !== "search").map((p) => crumbText(p, format, timeZone)).join(" · ");
66
+ const marked = markedText(c, messages);
67
+ if (marked !== void 0) return marked;
68
+ if (c.value === null) return messages.drillNone(c.label);
69
+ if (c.kind === "time" && typeof c.value === "string") {
70
+ const date = formatInstantAt(c.value, c.grain ?? "day", format.locale, timeZone);
71
+ return c.grain === "week" ? messages.drillWeekOf(date) : date;
72
+ }
73
+ return formatCell(c.value, {}, format);
74
+ }
75
+ /** The path as breadcrumbs: the tile, then each step, each going back to it. */
76
+ function Crumbs(props) {
77
+ const format = useDashboards();
78
+ return /* @__PURE__ */ jsx("nav", {
79
+ className: "dd-drill-crumbs",
80
+ "aria-label": format.messages.drillTitle,
81
+ children: /* @__PURE__ */ jsxs("ol", { children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
82
+ type: "button",
83
+ onClick: () => {
84
+ props.onGoTo(0);
85
+ },
86
+ children: format.messages.drillRoot(props.root)
87
+ }) }), props.path.map((c, i) => c.kind === "total" ? null : /* @__PURE__ */ jsx("li", {
88
+ "aria-current": i === props.path.length - 1 ? "step" : void 0,
89
+ children: i === props.path.length - 1 ? /* @__PURE__ */ jsx("span", { children: crumbText(c, format, props.timeZone) }) : /* @__PURE__ */ jsx("button", {
90
+ type: "button",
91
+ onClick: () => {
92
+ props.onGoTo(i + 1);
93
+ },
94
+ children: crumbText(c, format, props.timeZone)
95
+ })
96
+ }, `${c.label}-${String(i)}`))] })
97
+ });
98
+ }
99
+ /** "396 tasks with Hours (57 without)", or the rows alone. */
100
+ function rowsLine(summary, format) {
101
+ const rows = rowsText(summary.itemCount, summary, format);
102
+ if (rows === void 0 || summary.operand === void 0) return rows;
103
+ const without = summary.rows === void 0 ? void 0 : countOf(summary.rows) - countOf(summary.itemCount);
104
+ const missing = without === void 0 || without <= 0 ? void 0 : formatCell(without, { type: "int" }, format);
105
+ return format.messages.drillWith(rows, summary.operand, missing);
106
+ }
107
+ /** The value, the rows behind it when they differ, its share, and what the viewer should know about it. */
108
+ function Value({ summary, parent, onRefresh }) {
109
+ const format = useDashboards();
110
+ const value = formatCell(summary.value, valueColumn(summary), format);
111
+ const rows = rowsLine(summary, format);
112
+ const share = summary.share === void 0 ? void 0 : new Intl.NumberFormat(format.locale, { style: "percent" }).format(summary.share.value);
113
+ return /* @__PURE__ */ jsxs("div", {
114
+ className: "dd-drill-value",
115
+ children: [/* @__PURE__ */ jsxs("p", { children: [
116
+ /* @__PURE__ */ jsx("strong", { children: value }),
117
+ rows === void 0 ? null : sameCount(summary) ? /* @__PURE__ */ jsxs("span", { children: [" ", nounOnly(summary, format)] }) : /* @__PURE__ */ jsxs("span", { children: [" · ", rows] }),
118
+ share === void 0 ? null : /* @__PURE__ */ jsxs("span", { children: [
119
+ " ",
120
+ "·",
121
+ " ",
122
+ format.messages.drillShare(share, summary.share?.of === "parent" ? parent : void 0)
123
+ ] })
124
+ ] }), /* @__PURE__ */ jsx(Notes, {
125
+ summary,
126
+ value,
127
+ onRefresh
128
+ })]
129
+ });
130
+ }
131
+ export { Crumbs, DrillHead, Value, crumbText };
@@ -0,0 +1,22 @@
1
+ import { Item } from "../index.mjs";
2
+ import { ItemParts } from "./item-parts.mjs";
3
+ import { ComponentType, MouseEvent, ReactNode } from "react";
4
+ import { DrillItem, DrillItemsView, ItemLinks } from "derive-dashboards/core";
5
+ /** What a host's own item row is given: the item's link and parts, and how to open it. */
6
+ export type ItemHelpers = ItemParts & {
7
+ href?: string;
8
+ open?: () => void;
9
+ view: DrillItemsView;
10
+ };
11
+ /** Where an item goes and what a click on it does: the host's, by prop. */
12
+ export type ItemOptions = {
13
+ /** Where each source's items open, by source (typed by source once the server is registered). */
14
+ itemLinks?: ItemLinks;
15
+ /** An item's link; `undefined` means this item has none, even when `itemLinks` has a template. */
16
+ itemHref?: (item: Item) => string | undefined;
17
+ /** A plain left click; Cmd, Ctrl, Shift or a middle click still open the link. */
18
+ onItem?: (item: Item, context: {
19
+ event?: MouseEvent;
20
+ }) => void;
21
+ renderItem?: (item: Item, helpers: ItemHelpers) => ReactNode;
22
+ };
@@ -0,0 +1,164 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell } from "../format.mjs";
3
+ import { RowBody } from "../RowBody.mjs";
4
+ import { columnShape, itemParts, readMode, writeMode } from "./item-parts.mjs";
5
+ import { asItem } from "./item-type.mjs";
6
+ import { useEffect, useRef, useState } from "react";
7
+ import { itemLink } from "derive-dashboards/core";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ // src/drill/Items.tsx
10
+ const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
11
+ /**
12
+ * An item's link: the host's `itemHref` when it gives one (its `undefined` turns the link off),
13
+ * else its source's `itemLinks` template, else the server's. A hidden key never has one.
14
+ */
15
+ const hrefOf = (options, item) => options.itemHref === void 0 ? itemLink(options.itemLinks, item) ?? item.link : options.itemHref(asItem(item));
16
+ /** How an item opens: as a link, a button, or not at all. */
17
+ function Opener(props) {
18
+ const { link: Link = "a" } = useDashboards();
19
+ const { item, options } = props;
20
+ const href = hrefOf(options, item);
21
+ const onItem = options.onItem;
22
+ if (href === void 0 && onItem === void 0) return /* @__PURE__ */ jsx("div", {
23
+ className: props.className,
24
+ children: props.children
25
+ });
26
+ if (href === void 0) return /* @__PURE__ */ jsx("button", {
27
+ type: "button",
28
+ className: props.className,
29
+ onClick: (event) => onItem?.(asItem(item), { event }),
30
+ children: props.children
31
+ });
32
+ const onClick = (event) => {
33
+ if (onItem === void 0 || !plainClick(event)) return;
34
+ event.preventDefault();
35
+ onItem(asItem(item), { event });
36
+ };
37
+ return /* @__PURE__ */ jsx(Link, {
38
+ href,
39
+ className: props.className,
40
+ onClick,
41
+ children: props.children
42
+ });
43
+ }
44
+ /** A noun as a column heading: "task" reads "Task". */
45
+ const headOf = (noun) => noun === void 0 ? void 0 : `${noun.charAt(0).toLocaleUpperCase()}${noun.slice(1)}`;
46
+ /**
47
+ * Every column of the items as a plain table. Its first column names each row as the list does
48
+ * (its title, or "Task 12" when no field names it) and opens the item; the title's own column is
49
+ * not repeated.
50
+ */
51
+ function Table(props) {
52
+ const format = useDashboards();
53
+ const { view } = props;
54
+ const cell = {
55
+ ...format,
56
+ timeZone: props.timeZone
57
+ };
58
+ const rest = view.columns.filter((c) => c.member !== view.title);
59
+ const named = view.columns.find((c) => c.member === view.title);
60
+ return /* @__PURE__ */ jsx("div", {
61
+ className: "dd-records-scroll",
62
+ children: /* @__PURE__ */ jsxs("table", {
63
+ className: "dd-table",
64
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
65
+ scope: "col",
66
+ children: named?.label ?? headOf(props.noun) ?? format.messages.drillItem
67
+ }), rest.map((c) => /* @__PURE__ */ jsx("th", {
68
+ scope: "col",
69
+ children: c.label
70
+ }, c.member))] }) }), /* @__PURE__ */ jsx("tbody", { children: props.items.map((item, i) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
71
+ scope: "row",
72
+ children: /* @__PURE__ */ jsx(Opener, {
73
+ item,
74
+ options: props.options,
75
+ className: "dd-item-cell",
76
+ children: itemParts(view, item, {
77
+ n: i + 1,
78
+ noun: props.noun
79
+ }, cell).title
80
+ })
81
+ }), rest.map((c) => /* @__PURE__ */ jsx("td", { children: formatCell(item.values[c.member] ?? null, columnShape(c), cell) }, c.member))] }, item.id)) })]
82
+ })
83
+ });
84
+ }
85
+ /** One item with the host's own row: its parts, its link, and how to open it. */
86
+ function helpersOf(options, item, base) {
87
+ const href = hrefOf(options, item);
88
+ const onItem = options.onItem;
89
+ return {
90
+ ...base,
91
+ ...href === void 0 ? {} : { href },
92
+ ...onItem === void 0 ? {} : { open: () => {
93
+ onItem(asItem(item), {});
94
+ } }
95
+ };
96
+ }
97
+ /** The items as a list: the default row, or the host's own (`renderItem`). After Show more, the first new row takes focus. */
98
+ function List(props) {
99
+ const format = useDashboards();
100
+ const { view, options } = props;
101
+ const list = useRef(null);
102
+ const seen = useRef(props.items.length);
103
+ useEffect(() => {
104
+ const before = seen.current;
105
+ seen.current = props.items.length;
106
+ if (props.items.length <= before || before === 0) return;
107
+ list.current?.children[before]?.querySelector("a, button, [tabindex]")?.focus();
108
+ }, [props.items.length]);
109
+ const cell = {
110
+ ...format,
111
+ timeZone: props.timeZone
112
+ };
113
+ return /* @__PURE__ */ jsx("ul", {
114
+ className: "dd-items",
115
+ ref: list,
116
+ children: props.items.map((item, i) => {
117
+ const parts = itemParts(view, item, {
118
+ n: i + 1,
119
+ noun: props.noun
120
+ }, cell);
121
+ const render = options.renderItem;
122
+ const opens = hrefOf(options, item) !== void 0 || options.onItem !== void 0;
123
+ return /* @__PURE__ */ jsx("li", { children: render === void 0 ? /* @__PURE__ */ jsx(Opener, {
124
+ item,
125
+ options,
126
+ className: "dd-item",
127
+ children: /* @__PURE__ */ jsx(RowBody, {
128
+ row: {
129
+ ...parts,
130
+ opens
131
+ },
132
+ family: "item"
133
+ })
134
+ }) : render(asItem(item), helpersOf(options, item, {
135
+ ...parts,
136
+ view
137
+ })) }, item.id);
138
+ })
139
+ });
140
+ }
141
+ /** The items as a list (the default) or a table, the choice kept in this browser. */
142
+ function Items(props) {
143
+ const format = useDashboards();
144
+ const { view, Empty } = props;
145
+ const [mode, setMode] = useState(() => readMode(view.source));
146
+ if (props.items.length === 0) return Empty === void 0 ? /* @__PURE__ */ jsx("p", {
147
+ className: "dd-tile-state",
148
+ children: format.messages.drillNoItems
149
+ }) : /* @__PURE__ */ jsx(Empty, {});
150
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("fieldset", {
151
+ className: "dd-drill-modes",
152
+ "aria-label": format.messages.drillViews.items,
153
+ children: ["list", "table"].map((m) => /* @__PURE__ */ jsx("button", {
154
+ type: "button",
155
+ "aria-pressed": mode === m,
156
+ onClick: () => {
157
+ setMode(m);
158
+ writeMode(view.source, m);
159
+ },
160
+ children: m === "list" ? format.messages.drillList : format.messages.drillTable
161
+ }, m))
162
+ }), mode === "table" ? /* @__PURE__ */ jsx(Table, { ...props }) : /* @__PURE__ */ jsx(List, { ...props })] });
163
+ }
164
+ export { Items };
@@ -0,0 +1,60 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { countText } from "./counts.mjs";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/drill/ItemsFoot.tsx
5
+ /**
6
+ * How many items the list holds: under "Only <numerator>" the numerator's rows; a distinct
7
+ * count's list is its distinct values (its value), not the rows behind them; else the rows.
8
+ */
9
+ function listCount(view, summary) {
10
+ if (view.numerator?.only === true) return view.numerator.count;
11
+ return summary.semantics === "distinct" ? summary.value : summary.itemCount;
12
+ }
13
+ /** Items' count and sort, then Show more while there are more, with a retry when a page fails. */
14
+ function ItemsFoot({ d }) {
15
+ const format = useDashboards();
16
+ const { messages } = format;
17
+ const view = d.items.view;
18
+ if (view === void 0 || d.summary === void 0) return null;
19
+ const count = listCount(view, d.summary);
20
+ const total = count === void 0 ? void 0 : countText(count, format);
21
+ const sort = sortText(view, messages);
22
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
23
+ /* @__PURE__ */ jsxs("p", {
24
+ className: "dd-records-count",
25
+ "aria-live": "polite",
26
+ children: [
27
+ messages.drillShowing(d.items.items.length, total),
28
+ " · ",
29
+ sort
30
+ ]
31
+ }),
32
+ d.items.moreError === void 0 ? null : /* @__PURE__ */ jsx("p", {
33
+ className: "dd-tile-error",
34
+ role: "alert",
35
+ children: messages.drillFailed
36
+ }),
37
+ d.items.hasMore ? /* @__PURE__ */ jsx(More, { d }) : null
38
+ ] });
39
+ }
40
+ /** How the Items are sorted, in words: the declared order, or by the value. */
41
+ function sortText(view, messages) {
42
+ if (view.sort !== "records" || view.sorted === void 0) return messages.drillSort[view.sort];
43
+ const field = view.columns.find((c) => c.member === view.sorted?.member)?.label ?? "";
44
+ return messages.drillSorted(field, view.sorted.dir, view.sorted.time);
45
+ }
46
+ /** Show more, or Loading while a page comes, or Try again when the last one failed. */
47
+ function More({ d }) {
48
+ const { messages } = useDashboards();
49
+ const label = d.items.loadingMore ? messages.loading : d.items.moreError === void 0 ? messages.showMore : messages.drillRetry;
50
+ return /* @__PURE__ */ jsx("button", {
51
+ type: "button",
52
+ className: "dd-records-more",
53
+ "aria-disabled": d.items.loadingMore,
54
+ onClick: () => {
55
+ if (!d.items.loadingMore) d.items.more();
56
+ },
57
+ children: label
58
+ });
59
+ }
60
+ export { ItemsFoot };