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,58 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell, formatInstantAt } from "../format.mjs";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/drill/Notes.tsx
5
+ /** The value as the line reads it: a ratio as a percent when its column says so. */
6
+ const valueColumn = (summary) => summary.semantics === "ratio" && summary.column?.format === void 0 ? {
7
+ ...summary.column,
8
+ format: "percent",
9
+ fraction: true,
10
+ type: "float"
11
+ } : summary.column;
12
+ /** For the period before: the note that these are its rows, with its dates. */
13
+ function Earlier({ summary }) {
14
+ const format = useDashboards();
15
+ const { messages } = format;
16
+ const { range } = summary;
17
+ if (summary.previous !== true || range === void 0) return null;
18
+ const zone = summary.receipt.calendar.timezone;
19
+ const day = (at) => formatInstantAt(at, "day", format.locale, zone);
20
+ return /* @__PURE__ */ jsx("p", {
21
+ className: "dd-drill-period",
22
+ children: messages.drillEarlier(messages.drillRange(day(range.from), day(range.to)))
23
+ });
24
+ }
25
+ /** The notes under the value: the period before, a moved value (the viewer's own link only), a shared link's limits. */
26
+ function Notes({ summary, value, onRefresh }) {
27
+ const format = useDashboards();
28
+ const { messages } = format;
29
+ const clicked = summary.clicked;
30
+ const moved = summary.foreign !== true && clicked !== void 0 && JSON.stringify(clicked) !== JSON.stringify(summary.value);
31
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ /* @__PURE__ */ jsx(Earlier, { summary }),
33
+ moved ? /* @__PURE__ */ jsxs("p", {
34
+ className: "dd-tile-note",
35
+ role: "status",
36
+ children: [
37
+ messages.drillMoved(value, formatCell(clicked, valueColumn(summary), format)),
38
+ " ",
39
+ /* @__PURE__ */ jsx("button", {
40
+ type: "button",
41
+ className: "dd-button dd-quiet",
42
+ onClick: onRefresh,
43
+ children: messages.drillRefresh
44
+ })
45
+ ]
46
+ }) : null,
47
+ summary.omitted === true ? /* @__PURE__ */ jsx("p", {
48
+ className: "dd-tile-note",
49
+ role: "status",
50
+ children: messages.drillOmitted
51
+ }) : null,
52
+ summary.foreign === true ? /* @__PURE__ */ jsx("p", {
53
+ className: "dd-tile-note",
54
+ children: messages.drillYours(summary.noun?.other ?? messages.drillNoun(2))
55
+ }) : null
56
+ ] });
57
+ }
58
+ export { Notes, valueColumn };
@@ -0,0 +1,74 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell } from "../format.mjs";
3
+ import { Bars } from "./Bars.mjs";
4
+ import { FieldPicker, OnlyToggle, Operands } from "./Controls.mjs";
5
+ import { Items } from "./Items.mjs";
6
+ import { ItemsFoot } from "./ItemsFoot.mjs";
7
+ import { Failed, SeeRows } from "./PanelStates.mjs";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ // src/drill/PanelBody.tsx
10
+ /** What the view shows: bars or columns, items, or a formula's parts. */
11
+ function Body({ d, props }) {
12
+ const shown = d.shown;
13
+ if (shown === void 0) return null;
14
+ if (shown.by === "items") return /* @__PURE__ */ jsx(ItemsBody, {
15
+ d,
16
+ view: shown,
17
+ props
18
+ });
19
+ if (shown.by === "explanation") return /* @__PURE__ */ jsx(Operands, { d });
20
+ return /* @__PURE__ */ jsx(Bars, {
21
+ view: shown,
22
+ ...d.state?.entry === void 0 ? {} : { entry: d.state.entry },
23
+ onOpen: d.open
24
+ });
25
+ }
26
+ /** Items: the Only filter, a percentile's marker row, then the rows. */
27
+ function ItemsBody(a) {
28
+ const format = useDashboards();
29
+ const { d, view, props } = a;
30
+ const p = view.percentile;
31
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ /* @__PURE__ */ jsx(OnlyToggle, { d }),
33
+ p === void 0 || d.summary === void 0 ? null : /* @__PURE__ */ jsx("p", {
34
+ className: "dd-drill-marker",
35
+ children: format.messages.drillPercentile(p, formatCell(d.summary.value, d.summary.column, format))
36
+ }),
37
+ /* @__PURE__ */ jsx(Items, {
38
+ view,
39
+ items: d.items.items,
40
+ options: props,
41
+ noun: d.summary?.noun?.one,
42
+ timeZone: d.summary?.receipt.calendar.timezone,
43
+ Empty: props.components?.Empty
44
+ })
45
+ ] });
46
+ }
47
+ /** A failed read, or the panel loading, or its body. */
48
+ function Main({ d, props, close }) {
49
+ if (d.status === "error") return /* @__PURE__ */ jsx(Failed, {
50
+ d,
51
+ close
52
+ });
53
+ const Loading = props.components?.Loading;
54
+ if (d.status === "loading") return Loading === void 0 ? /* @__PURE__ */ jsx("ul", {
55
+ className: "dd-drill-skeleton",
56
+ "aria-busy": "true",
57
+ children: [
58
+ 0,
59
+ 1,
60
+ 2,
61
+ 3
62
+ ].map((i) => /* @__PURE__ */ jsx("li", {}, i))
63
+ }) : /* @__PURE__ */ jsx(Loading, {});
64
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FieldPicker, { d }), /* @__PURE__ */ jsxs("div", {
65
+ className: "dd-drill-body",
66
+ "aria-busy": d.updating,
67
+ "data-updating": d.updating || void 0,
68
+ children: [/* @__PURE__ */ jsx(Body, {
69
+ d,
70
+ props
71
+ }), /* @__PURE__ */ jsx(ItemsFoot, { d })]
72
+ })] });
73
+ }
74
+ export { Main, SeeRows };
@@ -0,0 +1,37 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { DashboardsError } from "../errors.mjs";
3
+ import { countText } from "./counts.mjs";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/drill/PanelStates.tsx
6
+ /** A failed read in words a person can act on: out of date (close it), or could not load (try again). */
7
+ function Failed({ d, close }) {
8
+ const { messages } = useDashboards();
9
+ const code = d.error instanceof DashboardsError ? d.error.code : void 0;
10
+ const stale = code === "SELECTION_INVALID" || code === "DRILL_STALE";
11
+ return /* @__PURE__ */ jsxs("p", {
12
+ className: "dd-tile-error",
13
+ role: "alert",
14
+ children: [
15
+ stale ? messages.drillStale : messages.drillFailed,
16
+ " ",
17
+ /* @__PURE__ */ jsx("button", {
18
+ type: "button",
19
+ className: "dd-button dd-quiet",
20
+ onClick: stale ? close : d.retry,
21
+ children: stale ? messages.drillStaleClose : messages.drillRetry
22
+ })
23
+ ]
24
+ });
25
+ }
26
+ /** On a phone, before the full page: a button with how many rows there are. */
27
+ function SeeRows({ d, onExpand }) {
28
+ const format = useDashboards();
29
+ const count = d.summary?.itemCount;
30
+ return /* @__PURE__ */ jsx("button", {
31
+ type: "button",
32
+ className: "dd-button dd-drill-see",
33
+ onClick: onExpand,
34
+ children: format.messages.drillSee(count === void 0 ? "" : countText(count, format))
35
+ });
36
+ }
37
+ export { Failed, SeeRows };
@@ -0,0 +1,18 @@
1
+ import "../useBoard.mjs";
2
+ import { ItemOptions } from "./Items.mjs";
3
+ import { ViewChange } from "../view.mjs";
4
+ import { ReactNode } from "react";
5
+ import { DrillState } from "derive-dashboards/core";
6
+ /** A drill about to open: the host may take it (`preventDefault`) and open it its own way. */
7
+ export type DrillEvent = {
8
+ state: DrillState;
9
+ preventDefault: () => void;
10
+ };
11
+ /** What `<Dashboard>` takes for drilling, beside the item options its panel passes on. */
12
+ export type DashboardDrillProps = ItemOptions & {
13
+ /** `false` turns drilling off: no mark opens, no Rows button. */
14
+ drill?: false;
15
+ /** A drill is opening; call `preventDefault` to open it in a page or drawer of your own. */
16
+ onDrill?: (event: DrillEvent) => void;
17
+ };
18
+ export type { ViewChange };
@@ -0,0 +1,91 @@
1
+ import { DrillHostContext } from "./host.mjs";
2
+ import { DrillPanel } from "./lazy.mjs";
3
+ import { useMemo, useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/drill/board.tsx
6
+ function documentOf(source) {
7
+ if (source !== void 0 && "draft" in source) return { draft: true };
8
+ if (source !== void 0 && "at" in source) return { version: source.at };
9
+ }
10
+ /**
11
+ * The dashboard's drill host: where a drill into each tile starts (this dashboard, the picks
12
+ * set, the document shown) and what a click does: tell the host (`onDrill`), then, unless it
13
+ * took the drill, open it beside the dashboard as a step Back undoes. Null when drilling is off.
14
+ */
15
+ function useDrillHost(dashboardId, board, props) {
16
+ const latest = useRef({
17
+ board,
18
+ props
19
+ });
20
+ latest.current = {
21
+ board,
22
+ props
23
+ };
24
+ const source = board.shown?.source;
25
+ const picks = board.view.picks;
26
+ return useMemo(() => {
27
+ if (props.drill === false || source !== void 0 && "merged" in source) return null;
28
+ const document = documentOf(source);
29
+ return {
30
+ origin: (widgetId) => ({
31
+ kind: "dashboard",
32
+ dashboardId,
33
+ widgetId,
34
+ picks,
35
+ ...document === void 0 ? {} : { document }
36
+ }),
37
+ onDrill: (state) => {
38
+ let prevented = false;
39
+ latest.current.props.onDrill?.({
40
+ state,
41
+ preventDefault: () => {
42
+ prevented = true;
43
+ }
44
+ });
45
+ if (prevented) return;
46
+ latest.current.board.panels.close();
47
+ latest.current.board.view.setDrill(state, "push");
48
+ }
49
+ };
50
+ }, [
51
+ dashboardId,
52
+ picks,
53
+ source,
54
+ props.drill
55
+ ]);
56
+ }
57
+ /** The drill open beside the dashboard, in the side slot review and history use. */
58
+ function DrillSide({ board, props }) {
59
+ const { drill } = board.view;
60
+ if (drill === void 0 || drill.origin.kind !== "dashboard") return null;
61
+ const widget = board.shown?.doc.widgets[drill.origin.widgetId];
62
+ return /* @__PURE__ */ jsx(DrillPanel, {
63
+ ...props,
64
+ state: drill,
65
+ title: widget?.title ?? "",
66
+ onStateChange: (next, history) => {
67
+ board.view.setDrill(next, history);
68
+ }
69
+ });
70
+ }
71
+ /**
72
+ * The dashboard's frame, with drilling for its tiles: they open through its host, or not at all
73
+ * when it is off. It says whether a side panel (review, history, a drill) is open, for layout.
74
+ */
75
+ function DrillScope(props) {
76
+ const { board } = props;
77
+ const host = useDrillHost(props.id, board, props.drill);
78
+ const panel = board.panels.panel;
79
+ const drilling = board.view.drill !== void 0;
80
+ return /* @__PURE__ */ jsx(DrillHostContext.Provider, {
81
+ value: board.edit.draft === void 0 ? host : null,
82
+ children: /* @__PURE__ */ jsx("div", {
83
+ className: "dd-dashboard",
84
+ "data-editing": board.edit.draft !== void 0,
85
+ "data-panel": panel !== void 0 || drilling,
86
+ "data-drill": panel === void 0 && drilling,
87
+ children: props.children
88
+ })
89
+ });
90
+ }
91
+ export { DrillScope, DrillSide };
@@ -0,0 +1,14 @@
1
+ import { formatCell } from "../format.mjs";
2
+ // src/drill/counts.ts
3
+ /** A count cell as a number: an exact one from its digits. */
4
+ const countOf = (cell) => typeof cell === "object" && cell !== null ? Number(cell.v) : Number(cell);
5
+ const MANY = 1e4;
6
+ /**
7
+ * A count as a person reads it, the same in the header, the list's footer and the phone's button:
8
+ * past 10,000 it reads "10,000+", since the exact figure past that point tells nothing more. The
9
+ * exact count stays in the answer.
10
+ */
11
+ function countText(cell, format) {
12
+ return countOf(cell) > MANY ? `${formatCell(MANY, { type: "int" }, format)}+` : formatCell(cell, { type: "int" }, format);
13
+ }
14
+ export { countOf, countText };
@@ -0,0 +1,26 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { tileDrill } from "./props.mjs";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ // src/drill/host.tsx
5
+ /** The dashboard's drill host; absent where drilling is off. */
6
+ const DrillHostContext = createContext(null);
7
+ /** A tile's drill for its renderer: absent when drilling is off or the answer does not drill. */
8
+ function useTileDrill(widgetId, result) {
9
+ const host = useContext(DrillHostContext);
10
+ const format = useDashboards();
11
+ return useMemo(() => {
12
+ if (host === null || result === void 0 || "error" in result) return;
13
+ return tileDrill({
14
+ answer: result,
15
+ origin: host.origin(widgetId),
16
+ format,
17
+ onDrill: host.onDrill
18
+ });
19
+ }, [
20
+ host,
21
+ result,
22
+ widgetId,
23
+ format
24
+ ]);
25
+ }
26
+ export { DrillHostContext, useTileDrill };
@@ -0,0 +1,5 @@
1
+ import "../messages.mjs";
2
+ import { RowContent } from "../RowBody.mjs";
3
+ import { DrillItem, DrillItemsView } from "derive-dashboards/core";
4
+ /** What a list row shows of an item: its title, up to three other values, its badge. */
5
+ export type ItemParts = Pick<RowContent, "title" | "meta" | "badge">;
@@ -0,0 +1,76 @@
1
+ import { formatCell, formatInstantAt } from "../format.mjs";
2
+ // src/drill/item-parts.ts
3
+ /** A column's own format for a cell: its type, its unit (a currency) and its time zone. */
4
+ const columnShape = (c) => ({
5
+ type: c.type,
6
+ ...c.unit === void 0 ? {} : { unit: c.unit },
7
+ ...c.format?.unit === void 0 ? {} : { unit: c.format.unit }
8
+ });
9
+ /**
10
+ * One value as a list shows it, labelled so a row reads on its own: a time as "Created Nov 9" in
11
+ * the dashboard's zone, a number with its unit and label, a true field by its name.
12
+ */
13
+ function valueText(cell, column, format) {
14
+ if (cell === null || cell === "") return void 0;
15
+ if (column.type === "time" && typeof cell === "string") return `${column.label} ${formatInstantAt(cell, "day", format.locale, format.timeZone)}`;
16
+ if (typeof cell === "boolean") return cell ? column.label : void 0;
17
+ const text = formatCell(cell, columnShape(column), format);
18
+ return typeof cell === "string" ? text : `${column.label} ${text}`;
19
+ }
20
+ /** An item's own name when no field names it: its id when its key is shown, else its place. */
21
+ const untitled = (item, n, noun, format) => format.messages.drillUntitled(item.key === void 0 ? n : item.id, noun);
22
+ /** An item's parts for a list, by the view's title and badge fields (Rules, section 7). */
23
+ function itemParts(view, item, row, format) {
24
+ const text = (c) => valueText(item.values[c.member] ?? null, c, format);
25
+ const titled = view.columns.find((c) => c.member === view.title);
26
+ const named = titled === void 0 ? null : item.values[titled.member] ?? null;
27
+ const title = titled === void 0 || named === null || named === "" ? untitled(item, row.n, row.noun, format) : formatCell(named, columnShape(titled), format);
28
+ const badgeColumn = view.columns.find((c) => c.member === view.badge?.member);
29
+ const fixed = new Set(view.fixed ?? []);
30
+ const meta = view.columns.filter((c) => c !== titled && c !== badgeColumn && c.member !== view.numerator?.flag && !fixed.has(c.member)).toSorted((a, b) => Number(b.member === view.value) - Number(a.member === view.value)).flatMap((c) => text(c) ?? []).slice(0, 3);
31
+ const badge = badgeOf(view, item, badgeColumn);
32
+ return badge === void 0 ? {
33
+ title,
34
+ meta
35
+ } : {
36
+ title,
37
+ meta,
38
+ badge
39
+ };
40
+ }
41
+ /** A ratio's numerator name, on a row its numerator counts. */
42
+ function numeratorBadge(view, item) {
43
+ const { numerator } = view;
44
+ if (numerator?.flag === void 0 || item.values[numerator.flag] !== true) return;
45
+ return {
46
+ text: numerator.label,
47
+ tone: "positive"
48
+ };
49
+ }
50
+ /** An item's badge: a ratio's numerator name on a row it counts, else its badge field's value. */
51
+ function badgeOf(view, item, column) {
52
+ const counted = numeratorBadge(view, item);
53
+ if (counted !== void 0) return counted;
54
+ const value = item.values[column?.member ?? ""];
55
+ if (typeof value !== "string" || value === "") return;
56
+ const tone = view.badge?.tones?.[value];
57
+ return {
58
+ text: value,
59
+ ...tone === void 0 ? {} : { tone }
60
+ };
61
+ }
62
+ const MODE_KEY = "dd-items-mode:";
63
+ /** The viewer's own choice of list or table for a source, kept in this browser only. */
64
+ function readMode(source) {
65
+ try {
66
+ return globalThis.localStorage?.getItem(`${MODE_KEY}${source}`) === "table" ? "table" : "list";
67
+ } catch {
68
+ return "list";
69
+ }
70
+ }
71
+ function writeMode(source, mode) {
72
+ try {
73
+ globalThis.localStorage?.setItem(`${MODE_KEY}${source}`, mode);
74
+ } catch {}
75
+ }
76
+ export { columnShape, itemParts, readMode, writeMode };
@@ -0,0 +1,26 @@
1
+ import "../index.mjs";
2
+ import { Cell, DrillItem, Primitive } from "derive-dashboards/core";
3
+ /** A source's key as an item carries it: one value per key column. */
4
+ type KeyOf<D> = D extends {
5
+ key: readonly (infer C extends string)[];
6
+ } ? Record<C, Primitive> : Record<string, Primitive>;
7
+ /** One source's items: its name narrows `source`, and with it `key`. */
8
+ type SourceItem<K extends string, D> = {
9
+ source: K;
10
+ id: string;
11
+ key?: KeyOf<D>;
12
+ values: Record<string, Cell>;
13
+ };
14
+ /**
15
+ * The items a server's drills list, typed from its model: one shape per source, so a check of
16
+ * `item.source === "order"` narrows `item.key` to the order key's columns. `S` is the server
17
+ * (what `deriveDashboards` returned); anything else reads as a plain `DrillItem`.
18
+ */
19
+ export type ItemFor<S> = S extends {
20
+ options: {
21
+ model: {
22
+ sources: infer Ss;
23
+ };
24
+ };
25
+ } ? { [K in keyof Ss & string]: SourceItem<K, Ss[K]>; }[keyof Ss & string] : DrillItem;
26
+ export {};
@@ -0,0 +1,7 @@
1
+ // src/drill/item-type.ts
2
+ /**
3
+ * An item from the server as the registered type reads it. The server sends `DrillItem`s; the
4
+ * registered type only names their sources and keys, so the value is the same.
5
+ */
6
+ const asItem = (item) => item;
7
+ export { asItem };
@@ -0,0 +1,6 @@
1
+ import { DrillPanelProps } from "./DrillPanel.mjs";
2
+ /**
3
+ * The drill panel (`DrillPanel` in `./DrillPanel`), loaded on first use: every export of the
4
+ * React entry reaches the panel through here, so no bundler pulls it in with the dashboard.
5
+ */
6
+ export declare function DrillPanel(props: DrillPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,17 @@
1
+ import { Suspense, lazy } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/drill/lazy.tsx
4
+ /** The panel's code, loaded the first time a drill opens: a page that never drills never loads it. */
5
+ const Loaded = lazy(async () => ({ default: (await import("./DrillPanel.mjs")).DrillPanel }));
6
+ /**
7
+ * The drill panel (`DrillPanel` in `./DrillPanel`), loaded on first use: every export of the
8
+ * React entry reaches the panel through here, so no bundler pulls it in with the dashboard.
9
+ */
10
+ function DrillPanel(props) {
11
+ if ((props.controller?.state ?? props.state) === void 0) return null;
12
+ return /* @__PURE__ */ jsx(Suspense, {
13
+ fallback: null,
14
+ children: /* @__PURE__ */ jsx(Loaded, { ...props })
15
+ });
16
+ }
17
+ export { DrillPanel };
@@ -0,0 +1,48 @@
1
+ import { useRef, useState } from "react";
2
+ // src/drill/pages.ts
3
+ /** The pages of Items read past the first, for one drill and one viewer. */
4
+ function useMorePages(key, state, first, ask) {
5
+ const [pages, setPages] = useState({
6
+ key: "",
7
+ views: []
8
+ });
9
+ const [loadingFor, setLoadingFor] = useState();
10
+ const chain = `${key}|${first?.next ?? ""}`;
11
+ const current = useRef(chain);
12
+ current.current = chain;
13
+ const mine = pages.key === chain ? pages : {
14
+ key: chain,
15
+ views: []
16
+ };
17
+ const last = mine.views.at(-1) ?? first;
18
+ const loading = loadingFor === chain;
19
+ const more = async () => {
20
+ if (state === void 0 || last?.next === void 0 || loading) return;
21
+ const at = chain;
22
+ const own = (p) => p.key === at ? p.views : [];
23
+ setLoadingFor(at);
24
+ try {
25
+ const view = (await ask(state, { after: last.next })).view;
26
+ if (view.by === "items" && current.current === at) setPages((p) => ({
27
+ key: at,
28
+ views: [...own(p), view]
29
+ }));
30
+ } catch (error) {
31
+ if (current.current === at) setPages((p) => ({
32
+ key: at,
33
+ views: own(p),
34
+ failed: error instanceof Error ? error : new Error(String(error))
35
+ }));
36
+ } finally {
37
+ setLoadingFor((l) => l === at ? void 0 : l);
38
+ }
39
+ };
40
+ return {
41
+ items: [first, ...mine.views].flatMap((v) => v?.items ?? []),
42
+ more,
43
+ hasMore: last?.next !== void 0,
44
+ loadingMore: loading,
45
+ ...mine.failed === void 0 ? {} : { moreError: mine.failed }
46
+ };
47
+ }
48
+ export { useMorePages };
@@ -0,0 +1,51 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ // src/drill/panel-focus.ts
3
+ /** A phone-sized screen, where the drill is a page of its own. */
4
+ const PHONE = "(max-width: 640px)";
5
+ const onPhone = () => typeof globalThis.matchMedia === "function" && globalThis.matchMedia(PHONE).matches;
6
+ /** The heading of a dashboard's tile, by its widget: where focus goes when what opened the drill is gone. */
7
+ const tileOf = (widgetId) => widgetId === void 0 ? null : document.querySelector(`[data-widget="${CSS.escape(widgetId)}"]`);
8
+ /** Whether focus has moved on purpose outside the panel, to something other than the page. */
9
+ function movedAway(inside) {
10
+ const active = document.activeElement;
11
+ return active !== null && active !== document.body && !(inside?.contains(active) ?? false);
12
+ }
13
+ /** What focus returns to: what opened the drill while it is still there, else its tile's title. */
14
+ function returnTarget(back, widgetId) {
15
+ return back instanceof HTMLElement && back.isConnected && back !== document.body ? back : tileOf(widgetId)?.querySelector(".dd-tile-title");
16
+ }
17
+ /**
18
+ * While the drill is open, its tile is lit; when it closes (Close, Escape, Back at the root),
19
+ * focus goes back to what opened it, or to its tile's heading when that is gone, and on a phone
20
+ * the page scrolls back to the tile instead of its top. A close that moved focus elsewhere on
21
+ * purpose keeps it there.
22
+ */
23
+ function useFocusReturn(panel, widgetId) {
24
+ const opener = useRef(null);
25
+ if (opener.current === null && typeof document !== "undefined") opener.current = document.activeElement;
26
+ useEffect(() => {
27
+ const tile = tileOf(widgetId);
28
+ if (tile) tile.dataset.drilling = "";
29
+ const inside = panel.current;
30
+ return () => {
31
+ if (tile) delete tile.dataset.drilling;
32
+ if (movedAway(inside)) return;
33
+ const target = returnTarget(opener.current, widgetId);
34
+ target?.focus({ preventScroll: true });
35
+ if (onPhone()) requestAnimationFrame(() => {
36
+ (tileOf(widgetId) ?? target)?.scrollIntoView({ block: "center" });
37
+ });
38
+ };
39
+ }, [panel, widgetId]);
40
+ }
41
+ /**
42
+ * On a phone, a tap first shows the value and a button to see the rows (Rules: no hover there),
43
+ * then the full page. Elsewhere the panel opens whole.
44
+ */
45
+ function usePeek() {
46
+ const [peek, setPeek] = useState(onPhone);
47
+ return [peek, () => {
48
+ setPeek(false);
49
+ }];
50
+ }
51
+ export { useFocusReturn, usePeek };
@@ -0,0 +1,25 @@
1
+ import "../messages.mjs";
2
+ import { KeyboardEvent, MouseEvent } from "react";
3
+ import { AnswerDrill, DrillOrigin, DrillState, DrillView, ResultCell, ResultColumn } from "derive-dashboards/core";
4
+ /** What a drillable mark spreads on its element: a button a click or Enter opens. */
5
+ export type DrillMarkProps = {
6
+ role: "button";
7
+ tabIndex: 0;
8
+ "aria-label": string;
9
+ "data-drill": "";
10
+ onClick: (event: MouseEvent) => void;
11
+ onKeyDown: (event: KeyboardEvent) => void;
12
+ };
13
+ /**
14
+ * What a renderer drills its answer with; absent where drilling is off. `props(row, entry)`
15
+ * gives the props a mark spreads, or undefined for a row that does not drill (a comparison, a
16
+ * row the server sealed no selection for). `open(row, entry)` opens it from a chart kit's own
17
+ * event. A row is its index in `answer.rows` or the row itself; `entry` is the line clicked
18
+ * (`m1`), needed when the answer has more than one.
19
+ */
20
+ export type TileDrill = {
21
+ props: (row: number | readonly ResultCell[], entry?: string) => DrillMarkProps | undefined;
22
+ open: (row: number | readonly ResultCell[] | undefined, entry?: string) => void;
23
+ /** The whole tile, as its Rows button opens it: on Items unless another view is named. */
24
+ openAll: (entry?: string, view?: DrillView) => void;
25
+ };
@@ -0,0 +1,72 @@
1
+ import { formatCell } from "../format.mjs";
2
+ import { drillFrom } from "./state.mjs";
3
+ // src/drill/props.ts
4
+ const isLine = (c) => c.id.startsWith("m") || c.id.startsWith("c");
5
+ /** A mark's name for a screen reader: its groups, then its value. */
6
+ function markLabel(answer, row, format, entry) {
7
+ const named = answer.columns.filter(isLine).length > 1 ? entry : void 0;
8
+ const text = answer.columns.map((c, i) => ({
9
+ c,
10
+ cell: row[i] ?? null
11
+ })).filter(({ c }) => named === void 0 || !isLine(c) || c.id === named).map(({ c, cell }) => {
12
+ if (cell === null && !isLine(c)) return format.messages.drillNone(c.label);
13
+ const value = formatCell(cell, c, format);
14
+ return named !== void 0 && isLine(c) ? `${c.label} ${value}` : value;
15
+ }).join(", ");
16
+ return format.messages.drillMark(text);
17
+ }
18
+ /** A row of the answer by its place, or a row of the comparison period, read in that period. */
19
+ function at(answer, row) {
20
+ if (typeof row === "number") return row;
21
+ const own = answer.rows.indexOf(row);
22
+ return own >= 0 ? own : { previous: answer.compare?.rows.indexOf(row) ?? -1 };
23
+ }
24
+ /**
25
+ * A renderer's drill for one answer: each row's sealed selection, opened as a drill state the
26
+ * host receives. Undefined when the answer carries nothing to drill with.
27
+ */
28
+ function tileDrill(a) {
29
+ const { answer } = a;
30
+ if (answer.drill === void 0) return void 0;
31
+ const single = answer.columns.filter(isLine).length <= 1;
32
+ const stateOf = (row, entry, view) => entry === void 0 && !single ? void 0 : drillFrom(a.origin, answer.drill, {
33
+ ...row === void 0 ? {} : { row: at(answer, row) },
34
+ ...entry === void 0 ? {} : { entry },
35
+ ...view === void 0 ? {} : { view }
36
+ });
37
+ const open = (row, entry, view) => {
38
+ const state = stateOf(row, entry, view);
39
+ if (state !== void 0) a.onDrill(state);
40
+ };
41
+ const firstLine = answer.columns.find(isLine)?.id;
42
+ return {
43
+ open: (row, entry) => {
44
+ open(row, entry);
45
+ },
46
+ openAll: (entry, view) => {
47
+ open(void 0, entry ?? (single ? void 0 : firstLine), view ?? ITEMS);
48
+ },
49
+ props: (row, entry) => {
50
+ const cells = typeof row === "number" ? answer.rows[row] : row;
51
+ if (cells === void 0 || stateOf(row, entry) === void 0) return;
52
+ return markProps(markLabel(answer, cells, a.format, entry), () => {
53
+ open(row, entry);
54
+ });
55
+ }
56
+ };
57
+ }
58
+ const ITEMS = { by: "items" };
59
+ /** A mark's props: a button by role, named, that opens on a click, Enter or Space. */
60
+ const markProps = (label, open) => ({
61
+ role: "button",
62
+ tabIndex: 0,
63
+ "aria-label": label,
64
+ "data-drill": "",
65
+ onClick: open,
66
+ onKeyDown: (event) => {
67
+ if (event.key !== "Enter" && event.key !== " ") return;
68
+ event.preventDefault();
69
+ open();
70
+ }
71
+ });
72
+ export { tileDrill };