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,18 @@
1
+ import { AnswerDrill, DrillOrigin, DrillState, DrillView } from "derive-dashboards/core";
2
+ /** Whether a change to the drill is a step a Back button should undo (`push`) or not (`replace`). */
3
+ export type DrillHistory = "push" | "replace";
4
+ /** How a drill tells its host its next state: undefined when it closed. */
5
+ export type DrillChange = (next: DrillState | undefined, history: DrillHistory) => void;
6
+ /**
7
+ * A drill's state from a click on an answer: its origin, the line clicked, the execution the
8
+ * answer ran under, and the clicked row of the sealed answer (none for the whole tile; a row of
9
+ * the comparison period by `{ previous: i }`), which the server answers with a sealed path.
10
+ * Undefined when the answer does not drill, or the row does not.
11
+ */
12
+ export declare function drillFrom(origin: DrillOrigin, drill: AnswerDrill | undefined, at?: {
13
+ row?: number | {
14
+ previous: number;
15
+ };
16
+ entry?: string;
17
+ view?: DrillView;
18
+ }): DrillState | undefined;
@@ -0,0 +1,68 @@
1
+ // src/drill/state.ts
2
+ /** The view a fresh step opens on: the server picks it by its rules (Breakdown with no field). */
3
+ const FIRST = { by: "breakdown" };
4
+ /**
5
+ * A drill's state from a click on an answer: its origin, the line clicked, the execution the
6
+ * answer ran under, and the clicked row of the sealed answer (none for the whole tile; a row of
7
+ * the comparison period by `{ previous: i }`), which the server answers with a sealed path.
8
+ * Undefined when the answer does not drill, or the row does not.
9
+ */
10
+ function drillFrom(origin, drill, at = {}) {
11
+ const path = drill === void 0 || at.row === void 0 ? [] : pick(drill, at.row);
12
+ if (drill === void 0 || path === void 0) return void 0;
13
+ return {
14
+ origin,
15
+ ...at.entry === void 0 ? {} : { entry: at.entry },
16
+ execution: drill.execution,
17
+ path,
18
+ view: at.view ?? FIRST
19
+ };
20
+ }
21
+ /** A row of a sealed answer as a path entry, or undefined when the row does not open. */
22
+ function rowEntry(sealed, row, previous = false) {
23
+ return sealed === void 0 || row < 0 || sealed.closed?.some((c) => c.row === row) === true ? void 0 : `${sealed.answer}#${previous ? "p" : ""}${String(row)}`;
24
+ }
25
+ /** A row's place in the sealed answer as a path of one, or undefined when the row does not open. */
26
+ function pick(drill, row) {
27
+ const entry = typeof row === "number" ? rowEntry(drill, row) : rowEntry(drill.previous, row.previous, true);
28
+ return entry === void 0 ? void 0 : [entry];
29
+ }
30
+ /** One step deeper: a row of a Breakdown or Over time clicked; the view it left is kept for Back. */
31
+ const deeper = (state, selection) => ({
32
+ ...state,
33
+ path: [...state.path, selection],
34
+ view: FIRST,
35
+ views: [...state.views ?? [], state.view]
36
+ });
37
+ /** The drill at an earlier step, as a breadcrumb or Back opens it: with the view that step had. */
38
+ function upTo(state, steps) {
39
+ const views = state.views ?? [];
40
+ const view = views[steps - 1] ?? FIRST;
41
+ const kept = views.slice(0, Math.max(0, steps - 1));
42
+ const { views: _views, ...rest } = state;
43
+ return {
44
+ ...rest,
45
+ path: state.path.slice(0, steps),
46
+ view,
47
+ ...kept.length === 0 ? {} : { views: kept }
48
+ };
49
+ }
50
+ /** Another line of the same tile, from a formula's parts: the same path, opened afresh. */
51
+ function onEntry(state, entry) {
52
+ const { views: _views, ...rest } = state;
53
+ return {
54
+ ...rest,
55
+ entry,
56
+ view: FIRST
57
+ };
58
+ }
59
+ /** A key that names a drill's state exactly, for caching its answer. */
60
+ const drillKey = (state) => JSON.stringify(state);
61
+ /** A key that names a drill's path, whatever its view: one summary serves every view of it. */
62
+ const pathKey = (state) => JSON.stringify([
63
+ state.origin,
64
+ state.execution,
65
+ state.path,
66
+ state.entry ?? null
67
+ ]);
68
+ export { deeper, drillFrom, drillKey, onEntry, pathKey, rowEntry, upTo };
@@ -0,0 +1,46 @@
1
+ import { DrillChange } from "./state.mjs";
2
+ import { DrillAnswer, DrillState, DrillSummary, DrillView } from "derive-dashboards/core";
3
+ export type DrillOptions = {
4
+ state: DrillState | undefined;
5
+ onStateChange: DrillChange;
6
+ };
7
+ /**
8
+ * The drill controller every drill UI sits on, `<DrillPanel>` included: the drill's answer for
9
+ * its state, and the moves a person makes (another view, a step deeper, Back, a breadcrumb,
10
+ * close), each told to the host as the next state with whether Back should undo it. Headless:
11
+ * no markup or styles. The state is the host's (in its URL, say); the controller never writes
12
+ * history itself. Its answers are cached per viewer and client (`viewerKey` on the provider),
13
+ * and a read the person moved on from is aborted.
14
+ */
15
+ export declare function useDrill({ state, onStateChange }: DrillOptions): {
16
+ setView: (view: DrillView) => void;
17
+ open: (selection: string) => void;
18
+ goTo: (steps: number) => void;
19
+ /** Another line of the tile: a formula's part, drilled on its own. */
20
+ openEntry: (entry: string) => void;
21
+ /** A drill the server sealed (a formula's part in its own scope), opened as it is. */
22
+ openState: (next: DrillState) => void;
23
+ /** One step up; at the first step, Back closes the drill. */
24
+ back: () => void;
25
+ close: () => void;
26
+ view: DrillView | undefined;
27
+ items: {
28
+ view: import("derive-dashboards/core").DrillItemsView | undefined;
29
+ moreError?: Error;
30
+ items: import("derive-dashboards/core").DrillItem[];
31
+ more: () => Promise<void>;
32
+ hasMore: boolean;
33
+ loadingMore: boolean;
34
+ };
35
+ status: "ready" | "loading" | "error";
36
+ /** A new view of the same step is loading: the last one stays, its controls with it. */
37
+ updating: boolean;
38
+ error: Error | undefined;
39
+ retry: () => void;
40
+ summary: DrillSummary | undefined;
41
+ path: import("derive-dashboards/core").DrillCrumb[];
42
+ shown: import("derive-dashboards/core").DrillItemsView | import("derive-dashboards/core").DrillGroupedView | import("derive-dashboards/core").DrillExplanationView | undefined;
43
+ state: DrillState | undefined;
44
+ answer: DrillAnswer | undefined;
45
+ };
46
+ export type DrillController = ReturnType<typeof useDrill>;
@@ -0,0 +1,194 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { useMorePages } from "./pages.mjs";
3
+ import { deeper, drillKey, onEntry, pathKey, upTo } from "./state.mjs";
4
+ import { useEffect, useRef } from "react";
5
+ import useSWR, { useSWRConfig } from "swr";
6
+ // src/drill/useDrill.ts
7
+ /** Whether a view needs the summary read with it: to pick the first view, or to explain a formula. */
8
+ const needsSummary = (view) => view.by === "breakdown" && view.member === void 0 || view.by === "explanation";
9
+ /**
10
+ * Reads a drill for one state: each read aborts when the state moves on (the server then
11
+ * cancels its statements), and a path whose summary is known reads its next view without it.
12
+ */
13
+ function useAsk(client, scope, known) {
14
+ const running = useRef(void 0);
15
+ const paging = useRef(void 0);
16
+ const mounted = useRef(false);
17
+ useEffect(() => {
18
+ mounted.current = true;
19
+ return () => {
20
+ mounted.current = false;
21
+ queueMicrotask(() => {
22
+ if (mounted.current) return;
23
+ running.current?.abort();
24
+ paging.current?.abort();
25
+ });
26
+ };
27
+ }, []);
28
+ const begin = (page) => {
29
+ const stop = new AbortController();
30
+ paging.current?.abort();
31
+ if (page === void 0) {
32
+ running.current?.abort();
33
+ running.current = stop;
34
+ } else paging.current = stop;
35
+ return stop;
36
+ };
37
+ return async (state, page) => {
38
+ const stop = begin(page);
39
+ const have = known.get(`${scope}|${pathKey(state)}`);
40
+ const skip = have !== void 0 && (page !== void 0 || !needsSummary(state.view));
41
+ const answer = await client.drill({
42
+ state,
43
+ ...page === void 0 ? {} : { page },
44
+ ...skip ? { summary: false } : {}
45
+ }, stop.signal);
46
+ if (answer.summary !== void 0) known.set(`${scope}|${pathKey(answer.state)}`, answer.summary);
47
+ return answer.summary === void 0 && have !== void 0 ? {
48
+ ...answer,
49
+ summary: have
50
+ } : answer;
51
+ };
52
+ }
53
+ /**
54
+ * When the server normalizes a state (seals a clicked row, picks the first view, drops a step
55
+ * that fixed a field twice), the host is told, and the answer it already has serves the new
56
+ * state too.
57
+ */
58
+ function useNormalized(scope, state, answer, onChange) {
59
+ const { mutate } = useSWRConfig();
60
+ const latest = useRef(onChange);
61
+ latest.current = onChange;
62
+ useEffect(() => {
63
+ if (state === void 0 || answer === void 0) return;
64
+ const normal = drillKey(answer.state);
65
+ if (normal === drillKey(state)) return;
66
+ mutate([
67
+ "dd-drill",
68
+ scope,
69
+ normal
70
+ ], answer, { revalidate: false });
71
+ latest.current(answer.state, "replace");
72
+ }, [
73
+ scope,
74
+ state,
75
+ answer,
76
+ mutate
77
+ ]);
78
+ }
79
+ /** The moves a person makes in a drill, each told to the host as the next state. */
80
+ function movesOf(state, move) {
81
+ const at = (next, history) => {
82
+ if (state !== void 0) move(next(state), history);
83
+ };
84
+ return {
85
+ setView: (view) => {
86
+ at((s) => ({
87
+ ...s,
88
+ view
89
+ }), "replace");
90
+ },
91
+ open: (selection) => {
92
+ at((s) => deeper(s, selection), "push");
93
+ },
94
+ goTo: (steps) => {
95
+ at((s) => upTo(s, steps), "push");
96
+ },
97
+ /** Another line of the tile: a formula's part, drilled on its own. */
98
+ openEntry: (entry) => {
99
+ at((s) => onEntry(s, entry), "push");
100
+ },
101
+ /** A drill the server sealed (a formula's part in its own scope), opened as it is. */
102
+ openState: (next) => {
103
+ move(next, "push");
104
+ },
105
+ /** One step up; at the first step, Back closes the drill. */
106
+ back: () => {
107
+ const steps = state?.path.length ?? 0;
108
+ if (steps > 1) at((s) => upTo(s, steps - 1), "push");
109
+ else move(void 0, "push");
110
+ },
111
+ close: () => {
112
+ move(void 0, "push");
113
+ }
114
+ };
115
+ }
116
+ /** Whether the answer is on its way, here, or failed. */
117
+ function statusOf(asked) {
118
+ if (asked.data !== void 0) return "ready";
119
+ return asked.error === void 0 ? "loading" : "error";
120
+ }
121
+ /**
122
+ * The drill controller every drill UI sits on, `<DrillPanel>` included: the drill's answer for
123
+ * its state, and the moves a person makes (another view, a step deeper, Back, a breadcrumb,
124
+ * close), each told to the host as the next state with whether Back should undo it. Headless:
125
+ * no markup or styles. The state is the host's (in its URL, say); the controller never writes
126
+ * history itself. Its answers are cached per viewer and client (`viewerKey` on the provider),
127
+ * and a read the person moved on from is aborted.
128
+ */
129
+ function useDrill({ state, onStateChange }) {
130
+ const { client, cacheScope } = useDashboards();
131
+ const known = useRef(/* @__PURE__ */ new Map());
132
+ const ask = useAsk(client, cacheScope, known.current);
133
+ const key = state === void 0 ? null : [
134
+ "dd-drill",
135
+ cacheScope,
136
+ drillKey(state)
137
+ ];
138
+ const asked = useSWR(key, () => state === void 0 ? Promise.reject(/* @__PURE__ */ new Error("No drill.")) : ask(state));
139
+ const { answer, updating } = useSteady(state, asked.data);
140
+ useNormalized(cacheScope, state, asked.data, onStateChange);
141
+ const shown = answer?.view;
142
+ const itemsView = shown?.by === "items" ? shown : void 0;
143
+ const pages = useMorePages(`${cacheScope}|${key?.[2] ?? ""}`, state, itemsView, ask);
144
+ return {
145
+ state,
146
+ answer,
147
+ ...answered(answer),
148
+ view: state?.view,
149
+ items: {
150
+ ...pages,
151
+ view: itemsView
152
+ },
153
+ status: updating ? "ready" : statusOf(asked),
154
+ /** A new view of the same step is loading: the last one stays, its controls with it. */
155
+ updating,
156
+ error: asked.error instanceof Error ? asked.error : void 0,
157
+ retry: () => {
158
+ if (state !== void 0) known.current.delete(`${cacheScope}|${pathKey(state)}`);
159
+ asked.mutate();
160
+ },
161
+ ...movesOf(state, onStateChange)
162
+ };
163
+ }
164
+ /** Where a drill stands: its origin and path, not its view. */
165
+ const stepOf = (state) => JSON.stringify([
166
+ state.origin,
167
+ state.execution,
168
+ state.path,
169
+ state.entry ?? null
170
+ ]);
171
+ /**
172
+ * The answer to show: the new one, or while a new view of the same step loads (another field,
173
+ * a search, Only), the last one, so the controls a person is using stay where they are.
174
+ */
175
+ function useSteady(state, fresh) {
176
+ const last = useRef(void 0);
177
+ const step = state === void 0 ? void 0 : stepOf(state);
178
+ if (fresh !== void 0 && step !== void 0) last.current = {
179
+ step,
180
+ answer: fresh
181
+ };
182
+ const held = fresh === void 0 && last.current?.step === step ? last.current?.answer : void 0;
183
+ return {
184
+ answer: fresh ?? held,
185
+ updating: held !== void 0
186
+ };
187
+ }
188
+ /** What an answer shows: its summary, its breadcrumbs, its view. */
189
+ const answered = (answer) => ({
190
+ summary: answer?.summary,
191
+ path: answer?.path ?? [],
192
+ shown: answer?.view
193
+ });
194
+ export { useDrill };
@@ -0,0 +1,98 @@
1
+ import { DrillReason } from "derive-dashboards/core";
2
+ /** Every word the drill panel shows; `ENGLISH_DRILL` holds the defaults. */
3
+ export type DrillMessages = {
4
+ /** The panel's name, over the path. */
5
+ drillTitle: string;
6
+ /** The views. */
7
+ drillViews: Record<"breakdown" | "trend" | "items" | "explanation", string>;
8
+ /** Back one step; at the root, back to the dashboard. */
9
+ drillBack: string;
10
+ /** A breadcrumb that steps back to the tile itself. */
11
+ drillRoot: (title: string) => string;
12
+ /** "36 orders" beside the value, when the rows and the value differ. */
13
+ drillRows: (count: string) => string;
14
+ /** "396 tasks with Hours (57 without)": a value that counts only rows with its field set. */
15
+ drillWith: (rows: string, operand: string, without: string | undefined) => string;
16
+ /** "42% of the total" for a first step, "39% of Open" deeper. */
17
+ drillShare: (percent: string, of: string | undefined) => string;
18
+ /** The value now differs from the one the chart was drawn with (same viewer only). */
19
+ drillMoved: (now: string, then: string) => string;
20
+ /** Reload the drill. */
21
+ drillRefresh: string;
22
+ /** A link drawn by another viewer: the counts are this viewer's own. */
23
+ drillYours: (noun: string) => string;
24
+ /** A link whose step this viewer may not open: never how many rows. */
25
+ drillOmitted: string;
26
+ /** A mark of the period before: "Before · Sep 15 to Oct 14". */
27
+ drillEarlier: (range: string) => string;
28
+ /** Under a mark that opens: what a click does. */
29
+ drillHint: string;
30
+ /** A Breakdown's field picker. */
31
+ drillBy: string;
32
+ /** "Showing 12 of 36", or "Showing 12" when the total is not known. */
33
+ drillShowing: (shown: number, total?: string) => string;
34
+ drillSort: Record<"records" | "value" | "count", string>;
35
+ /** The records order in words: "newest first", "oldest first", "by Priority". */
36
+ drillSorted: (field: string, dir: "asc" | "desc", time: boolean) => string;
37
+ drillList: string;
38
+ drillTable: string;
39
+ /** An empty Items list. */
40
+ drillNoItems: string;
41
+ /** An empty Breakdown or Over time: no group to show. */
42
+ drillNoGroups: string;
43
+ /** A Breakdown search that matched nothing. */
44
+ drillNoMatch: string;
45
+ drillFailed: string;
46
+ drillRetry: string;
47
+ /** The drill's link no longer opens (the server restarted, the dashboard changed). */
48
+ drillStale: string;
49
+ /** Close the out-of-date drill. */
50
+ drillStaleClose: string;
51
+ /** A screen-reader name for a mark that opens: "Open, 36. Open what is behind it." */
52
+ drillMark: (label: string) => string;
53
+ /** A row in a list with no title field: "Task 4123" by its id, else "Task 3" by its place. */
54
+ drillUntitled: (n: number | string, noun?: string) => string;
55
+ /** A formula's parts. */
56
+ drillOperands: string;
57
+ /** Where a part of a formula is read: the row itself, the whole chart, its time point, the period before. */
58
+ drillScope: Record<"row" | "total" | "bucket" | "previous", string>;
59
+ /** A row, or rows, when the source names none: "rows". */
60
+ drillNoun: (n: number) => string;
61
+ /** A group in a Breakdown of the change: "36, was 30, +6". */
62
+ drillChange: (now: string, before: string, change: string) => string;
63
+ /** The header of a Breakdown of the change: "202 vs 169, +33". */
64
+ drillVersus: (before: string, change: string) => string;
65
+ /** The search in a Breakdown's field. */
66
+ drillSearch: string;
67
+ /** A ratio's Items: only the rows its numerator counts, "Only Won (12)". */
68
+ drillOnly: (numerator: string, count: string) => string;
69
+ /** Why a chart's later marks do not open. */
70
+ drillCut: string;
71
+ /** A number's value in the period before: "Before: 30". */
72
+ drillBefore: (value: string) => string;
73
+ /** A step that is the whole of the period before, in the breadcrumb. */
74
+ drillPeriodBefore: string;
75
+ /** The Items table's first column when the source names no noun. */
76
+ drillItem: string;
77
+ /** A group with no value of its field: "No Assignee". */
78
+ drillNone: (field: string) => string;
79
+ /** Other of one field in a breadcrumb: "Other priority". */
80
+ drillOtherOf: (field: string) => string;
81
+ /** A time point in a breadcrumb: "Week of Nov 9". */
82
+ drillWeekOf: (date: string) => string;
83
+ /** A true or false value in a list or table. */
84
+ drillYes: string;
85
+ drillNo: string;
86
+ /** A percentile's marker row: "90% are below 4 h". */
87
+ drillPercentile: (p: number, value: string) => string;
88
+ /** Over time: the range drawn and its grain picker. */
89
+ drillRange: (from: string, to: string) => string;
90
+ drillGrains: Record<"hour" | "day" | "week" | "month" | "quarter" | "year", string>;
91
+ /** Why a view cannot show, by its code. */
92
+ drillReasons: Record<DrillReason, string>;
93
+ /** Open the widget behind the drill in the builder (editing only). */
94
+ drillOpenInBuilder: string;
95
+ /** On a phone, a tap first shows the value and this button. */
96
+ drillSee: (count: string) => string;
97
+ };
98
+ export declare const ENGLISH_DRILL: DrillMessages;
@@ -0,0 +1,77 @@
1
+ import { DRILL_REASONS } from "derive-dashboards/core";
2
+ // src/drill/words.ts
3
+ const capital = (text) => text.charAt(0).toUpperCase() + text.slice(1);
4
+ const ENGLISH_DRILL = {
5
+ drillTitle: "Analysis",
6
+ drillViews: {
7
+ breakdown: "Breakdown",
8
+ trend: "Over time",
9
+ items: "Items",
10
+ explanation: "Explanation"
11
+ },
12
+ drillBack: "Back",
13
+ drillRoot: (title) => title,
14
+ drillRows: (count) => `${count} rows`,
15
+ drillWith: (rows, operand, without) => `${rows} with ${operand}${without === void 0 ? "" : ` (${without} without)`}`,
16
+ drillShare: (percent, of) => `${percent} of ${of ?? "the total"}`,
17
+ drillMoved: (now, then) => `${now} now, ${then} when the chart loaded`,
18
+ drillRefresh: "Refresh",
19
+ drillYours: (noun) => `Counts include only ${noun} you can see.`,
20
+ drillOmitted: "Part of this link was left out.",
21
+ drillEarlier: (range) => `The period before · ${range}`,
22
+ drillHint: "Click to see what is behind it",
23
+ drillBy: "Break down by",
24
+ drillShowing: (shown, total) => total === void 0 ? `Showing ${String(shown)}` : `Showing ${String(shown)} of ${total}`,
25
+ drillSort: {
26
+ records: "in record order",
27
+ value: "highest first",
28
+ count: "most rows first"
29
+ },
30
+ drillSorted: (field, dir, time) => time ? dir === "desc" ? "newest first" : "oldest first" : `by ${field}`,
31
+ drillList: "List",
32
+ drillTable: "Table",
33
+ drillNoItems: "No items match.",
34
+ drillNoGroups: "Nothing to show here.",
35
+ drillNoMatch: "No values match the search.",
36
+ drillFailed: "Couldn't load.",
37
+ drillRetry: "Try again",
38
+ drillStale: "This view is out of date.",
39
+ drillStaleClose: "Close it",
40
+ drillMark: (label) => `${label}. Open what is behind it.`,
41
+ drillUntitled: (n, noun) => `${noun === void 0 ? "Row" : capital(noun)} ${String(n)}`,
42
+ drillOperands: "Made of",
43
+ drillScope: {
44
+ row: "here",
45
+ total: "of the whole chart",
46
+ bucket: "of this time point",
47
+ previous: "in the period before"
48
+ },
49
+ drillNoun: (n) => n === 1 ? "row" : "rows",
50
+ drillChange: (now, before, change) => `${now}, was ${before}, ${change}`,
51
+ drillVersus: (before, change) => `vs ${before}, ${change}`,
52
+ drillSearch: "Search",
53
+ drillOnly: (numerator, count) => `Only ${numerator} (${count})`,
54
+ drillBefore: (value) => `Before: ${value}`,
55
+ drillPeriodBefore: "The period before",
56
+ drillItem: "Item",
57
+ drillCut: "Only the first rows of this answer open; narrow the filters to open the rest.",
58
+ drillNone: (field) => `No ${field.toLowerCase()}`,
59
+ drillOtherOf: (field) => `Other ${field.toLowerCase()}`,
60
+ drillWeekOf: (date) => `Week of ${date}`,
61
+ drillYes: "Yes",
62
+ drillNo: "No",
63
+ drillPercentile: (p, value) => `${String(p)}% are at or below ${value}`,
64
+ drillRange: (from, to) => `${from} to ${to}`,
65
+ drillGrains: {
66
+ hour: "Hour",
67
+ day: "Day",
68
+ week: "Week",
69
+ month: "Month",
70
+ quarter: "Quarter",
71
+ year: "Year"
72
+ },
73
+ drillReasons: { ...DRILL_REASONS },
74
+ drillOpenInBuilder: "Open in builder",
75
+ drillSee: (count) => `See ${count}`
76
+ };
77
+ export { ENGLISH_DRILL };
@@ -1,8 +1,10 @@
1
+ import { ENGLISH_DRILL } from "./drill/words.mjs";
1
2
  import { ENGLISH_REVIEW } from "./review-words.mjs";
2
3
  // src/english.ts
3
4
  /** Every word the built-in components show, in English: the default `messages`. */
4
5
  const ENGLISH = {
5
6
  ...ENGLISH_REVIEW,
7
+ ...ENGLISH_DRILL,
6
8
  other: "Other",
7
9
  total: "Total",
8
10
  empty: "None",
@@ -12,11 +14,13 @@ const ENGLISH = {
12
14
  noData: "No data for this range",
13
15
  noRows: "No rows",
14
16
  dashboardFailed: "This dashboard could not be loaded.",
17
+ dashboardUnreachable: "Can't reach the server. Showing what was last loaded; it updates when the connection is back.",
15
18
  dashboardMissing: "This dashboard isn't here. It may not be published yet, or it was removed.",
16
19
  rowsFailed: "These rows could not be loaded.",
17
20
  rows: "Rows",
18
21
  close: "Close",
19
22
  showMore: "Show more",
23
+ rowsShowing: (n, more) => `Showing ${String(n)} ${n === 1 ? "row" : "rows"}${more ? ", more to load" : ""}`,
20
24
  reset: "Reset",
21
25
  rowsBehind: (title) => `Rows behind ${title}`,
22
26
  notFilteredBy: (controls) => `Not filtered by ${controls.join(", ")}`,
@@ -54,7 +58,8 @@ const ENGLISH = {
54
58
  number: "Number",
55
59
  line: "Line",
56
60
  bar: "Bar",
57
- table: "Table"
61
+ table: "Table",
62
+ list: "List"
58
63
  },
59
64
  topValues: (n) => `top ${n}`,
60
65
  keepTop: "Keep the top",
@@ -123,6 +128,7 @@ const ENGLISH = {
123
128
  deleteNewConfirm: "Delete dashboard",
124
129
  keepEditing: "Keep editing",
125
130
  unreachable: "Can't reach the server. Your draft is safe as last saved; try again.",
131
+ removedTile: (title) => `Removed “${title}”. Undo brings it back.`,
126
132
  tileUnreachable: "Couldn't load this tile. Check the connection and reload.",
127
133
  changesDiscarded: "Changes discarded",
128
134
  draftChanged: "Your draft changed in another tab. It has been reloaded; make that change again.",
@@ -132,6 +138,8 @@ const ENGLISH = {
132
138
  newDashboard: "+ New dashboard",
133
139
  untitledDashboard: "Untitled dashboard",
134
140
  unpublished: "Draft",
141
+ builtIn: "Built in",
142
+ madeHere: "Made here",
135
143
  dashboardTitle: "Dashboard title",
136
144
  history: "History",
137
145
  noHistory: "Nothing published yet. Publishing makes the first version.",
@@ -6,7 +6,7 @@ import { Grain, ResultCell, ResultColumn } from "derive-dashboards/core";
6
6
  */
7
7
  export declare function plotValue(cell: ResultCell): number | null;
8
8
  /** What formatting reads of a column: its type, and a time bucket's grain or a money unit. */
9
- type Shape = Pick<ResultColumn, "type" | "grain" | "unit" | "format" | "signed">;
9
+ type Shape = Pick<ResultColumn, "type" | "grain" | "unit" | "format" | "signed" | "fraction">;
10
10
  /**
11
11
  * A cell as text for a person, in their locale and words. A renderer can pass its own props as
12
12
  * `format`: they carry both.
@@ -20,6 +20,6 @@ export declare function formatTick(value: number, column?: ResultColumn, locale?
20
20
  * not as an instant in any zone. Hour labels stay as sent.
21
21
  */
22
22
  export declare function formatBucket(label: string, grain: Grain, locale?: string): string;
23
- /** An instant (text time to the microsecond) as a date and time in the viewer's own zone. */
24
- export declare function formatInstant(text: string, locale?: string): string;
23
+ /** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
24
+ export declare function formatInstant(text: string, locale?: string, timeZone?: string): string;
25
25
  export {};
@@ -22,13 +22,16 @@ function formatCell(cell, column, format = {}) {
22
22
  const { locale, messages = ENGLISH } = format;
23
23
  if (cell === null) return messages.noValue;
24
24
  if (isMark(cell)) return cell.mark === "all" ? messages.total : messages.other;
25
- if (typeof cell === "string") return formatText(cell, column, locale);
26
- if (typeof cell === "boolean") return String(cell);
25
+ if (typeof cell === "string") return formatText(cell, column, locale, format.timeZone);
26
+ if (typeof cell === "boolean") return cell ? messages.drillYes : messages.drillNo;
27
27
  return numberText(cell, column, locale);
28
28
  }
29
29
  /** A number by its column's format: a percent, a duration, money or a plain number. */
30
30
  function numberText(cell, column, locale) {
31
- if (column?.format === "percent") return percentText(cell, column.signed === true, locale);
31
+ if (column?.format === "percent") return percentText(cell, {
32
+ signed: column.signed === true,
33
+ fraction: column.fraction === true
34
+ }, locale);
32
35
  if (column?.format === "duration") return durationText(typeof cell === "number" ? cell : Number(cell.v), locale);
33
36
  const currency = currencyOf(column?.unit);
34
37
  const style = currency === void 0 ? {} : {
@@ -45,15 +48,17 @@ function numberText(cell, column, locale) {
45
48
  * A value in percent points (42.5) as a percent (42.5%). Exact digits move two places as text,
46
49
  * so Intl formats them without a float.
47
50
  */
48
- function percentText(cell, signed, locale) {
51
+ function percentText(cell, how, locale) {
52
+ const { signed } = how;
53
+ const shift = how.fraction ? "" : "E-2";
49
54
  const style = {
50
55
  style: "percent",
51
56
  minimumFractionDigits: 2,
52
57
  maximumFractionDigits: 2,
53
58
  signDisplay: signed ? "exceptZero" : "auto"
54
59
  };
55
- if (typeof cell === "number") return new Intl.NumberFormat(locale, style).format(cell / 100);
56
- return new Intl.NumberFormat(locale, style).format(`${cell.v}E-2`);
60
+ if (typeof cell === "number") return new Intl.NumberFormat(locale, style).format(how.fraction ? cell : cell / 100);
61
+ return new Intl.NumberFormat(locale, style).format(`${cell.v}${shift}`);
57
62
  }
58
63
  const DURATION_UNITS = [
59
64
  ["day", 86400],
@@ -72,10 +77,10 @@ function durationText(seconds, locale) {
72
77
  maximumFractionDigits: 1
73
78
  }).format(seconds / per);
74
79
  }
75
- /** A text cell: a time bucket's label, an instant, or the text itself. */
76
- function formatText(text, column, locale) {
80
+ /** A text cell: a time bucket's label, an instant (in the dashboard's zone when given), or the text itself. */
81
+ function formatText(text, column, locale, timeZone) {
77
82
  if (column?.grain !== void 0) return formatBucket(text, column.grain, locale);
78
- return column?.type === "time" ? formatInstant(text, locale) : text;
83
+ return column?.type === "time" ? formatInstant(text, locale, timeZone) : text;
79
84
  }
80
85
  /** Decimal text in the viewer's locale, exactly: Intl formats the digits, never a float. */
81
86
  function exactText(text, currency, locale) {
@@ -141,13 +146,30 @@ function formatBucket(label, grain, locale) {
141
146
  timeZone: "UTC"
142
147
  }).format(date);
143
148
  }
144
- /** An instant (text time to the microsecond) as a date and time in the viewer's own zone. */
145
- function formatInstant(text, locale) {
149
+ /** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
150
+ function formatInstant(text, locale, timeZone) {
146
151
  const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
147
152
  if (Number.isNaN(date.getTime())) return text;
148
153
  return new Intl.DateTimeFormat(locale, {
154
+ dateStyle: "medium",
155
+ timeStyle: "short",
156
+ ...timeZone === void 0 ? {} : { timeZone }
157
+ }).format(date);
158
+ }
159
+ /**
160
+ * The bucket an instant starts, named at its grain in a zone, as the chart names it: a drill's
161
+ * time step ("Nov 9" for a day or week, "Jul 2026" for a month), never a clock time.
162
+ */
163
+ function formatInstantAt(text, grain, locale, timeZone) {
164
+ const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
165
+ if (Number.isNaN(date.getTime())) return text;
166
+ const options = grain === "hour" ? {
149
167
  dateStyle: "medium",
150
168
  timeStyle: "short"
169
+ } : BUCKET_FORMATS[grain];
170
+ return new Intl.DateTimeFormat(locale, {
171
+ ...options,
172
+ ...timeZone === void 0 ? {} : { timeZone }
151
173
  }).format(date);
152
174
  }
153
- export { formatBucket, formatCell, formatInstant, formatTick, plotValue };
175
+ export { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue };