derive-dashboards 0.1.0 → 0.2.0

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 (410) hide show
  1. package/README.md +8 -5
  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/add.mjs +130 -0
  6. package/dist/cli/check.mjs +14 -1
  7. package/dist/cli/cli.mjs +14 -12
  8. package/dist/cli/config.mjs +12 -1
  9. package/dist/cli/doctor.mjs +147 -0
  10. package/dist/cli/import/dbt-schema.mjs +2 -2
  11. package/dist/cli/import/index.mjs +2 -2
  12. package/dist/cli/init.mjs +3 -2
  13. package/dist/cli/json.mjs +21 -0
  14. package/dist/cli/layers.mjs +33 -0
  15. package/dist/core/conformance/cases.d.mts +3 -0
  16. package/dist/core/conformance/cases.mjs +20 -4
  17. package/dist/core/conformance/check.mjs +6 -3
  18. package/dist/core/conformance/drill-cases.mjs +120 -0
  19. package/dist/core/document/layout.mjs +1 -1
  20. package/dist/core/document/view-layout.d.mts +14 -0
  21. package/dist/core/document/view-layout.mjs +157 -0
  22. package/dist/core/document/view.d.mts +26 -7
  23. package/dist/core/document/view.mjs +42 -11
  24. package/dist/core/engine/filter.mjs +2 -2
  25. package/dist/core/engine/index.d.mts +14 -2
  26. package/dist/core/engine/index.mjs +12 -1
  27. package/dist/core/engine/leaf.mjs +9 -4
  28. package/dist/core/engine/members.mjs +2 -2
  29. package/dist/core/engine/postgres.mjs +1 -1
  30. package/dist/core/engine/record-layout.d.mts +11 -0
  31. package/dist/core/engine/record-layout.mjs +7 -7
  32. package/dist/core/engine/records.d.mts +3 -2
  33. package/dist/core/engine/records.mjs +2 -1
  34. package/dist/core/engine/segmented.mjs +5 -2
  35. package/dist/core/engine/sql-records.mjs +2 -1
  36. package/dist/core/engine/statement.mjs +37 -3
  37. package/dist/core/engine/types.d.mts +3 -0
  38. package/dist/core/engine/version.d.mts +1 -1
  39. package/dist/core/engine/version.mjs +1 -1
  40. package/dist/core/error/codes.d.mts +33 -1
  41. package/dist/core/error/codes.mjs +30 -2
  42. package/dist/core/index.d.mts +13 -7
  43. package/dist/core/index.mjs +9 -5
  44. package/dist/core/model/catalog/check.mjs +1 -1
  45. package/dist/core/model/hints.d.mts +36 -0
  46. package/dist/core/model/member.d.mts +4 -2
  47. package/dist/core/model/member.mjs +19 -3
  48. package/dist/core/model/types.d.mts +21 -19
  49. package/dist/core/model/validate/drill.mjs +70 -0
  50. package/dist/core/model/validate/index.mjs +3 -0
  51. package/dist/core/model/validate/members.mjs +7 -4
  52. package/dist/core/model/validate/shape.mjs +150 -0
  53. package/dist/core/model/validate/source.mjs +5 -3
  54. package/dist/core/policy/bind-query.d.mts +12 -0
  55. package/dist/core/policy/bind-query.mjs +53 -0
  56. package/dist/core/query/alias.mjs +7 -1
  57. package/dist/core/query/drill/compose.d.mts +22 -0
  58. package/dist/core/query/drill/compose.mjs +85 -0
  59. package/dist/core/query/drill/fields.d.mts +21 -0
  60. package/dist/core/query/drill/fields.mjs +91 -0
  61. package/dist/core/query/drill/internal.d.mts +11 -0
  62. package/dist/core/query/drill/items.d.mts +29 -0
  63. package/dist/core/query/drill/items.mjs +98 -0
  64. package/dist/core/query/drill/line.d.mts +31 -0
  65. package/dist/core/query/drill/line.mjs +183 -0
  66. package/dist/core/query/drill/links.d.mts +33 -0
  67. package/dist/core/query/drill/links.mjs +31 -0
  68. package/dist/core/query/drill/operand.mjs +7 -0
  69. package/dist/core/query/drill/scopes.d.mts +22 -0
  70. package/dist/core/query/drill/scopes.mjs +58 -0
  71. package/dist/core/query/drill/selection.d.mts +37 -0
  72. package/dist/core/query/drill/selection.mjs +144 -0
  73. package/dist/core/query/drill/steps.d.mts +14 -0
  74. package/dist/core/query/drill/steps.mjs +35 -0
  75. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  76. package/dist/core/query/drill/synthetic.d.mts +22 -0
  77. package/dist/core/query/drill/synthetic.mjs +165 -0
  78. package/dist/core/query/drill/time.d.mts +11 -0
  79. package/dist/core/query/drill/time.mjs +71 -0
  80. package/dist/core/query/drill/types.d.mts +155 -0
  81. package/dist/core/query/drill/types.mjs +4 -0
  82. package/dist/core/query/drill/views.d.mts +62 -0
  83. package/dist/core/query/drill/views.mjs +257 -0
  84. package/dist/core/query/filter.d.mts +6 -0
  85. package/dist/core/query/picks.d.mts +8 -2
  86. package/dist/core/query/picks.mjs +11 -4
  87. package/dist/core/query/segments.d.mts +12 -2
  88. package/dist/core/query/segments.mjs +5 -2
  89. package/dist/core/result/columns.mjs +20 -4
  90. package/dist/core/result/types.d.mts +5 -1
  91. package/dist/core/schema/aliases.d.mts +7 -0
  92. package/dist/core/schema/aliases.mjs +77 -0
  93. package/dist/core/schema/answer-parts.mjs +117 -0
  94. package/dist/core/schema/answers.d.mts +2109 -128
  95. package/dist/core/schema/answers.mjs +11 -113
  96. package/dist/core/schema/commands.d.mts +2 -2
  97. package/dist/core/schema/document.d.mts +1 -1
  98. package/dist/core/schema/drill-answers.mjs +179 -0
  99. package/dist/core/schema/drill.d.mts +260 -0
  100. package/dist/core/schema/drill.mjs +107 -0
  101. package/dist/core/schema/index.d.mts +6 -3
  102. package/dist/core/schema/index.mjs +6 -3
  103. package/dist/core/schema/picks.d.mts +35 -0
  104. package/dist/core/schema/picks.mjs +23 -0
  105. package/dist/core/schema/query.d.mts +82 -1
  106. package/dist/core/schema/query.mjs +9 -5
  107. package/dist/core/schema/tools.mjs +1 -1
  108. package/dist/core/schema/view.d.mts +0 -35
  109. package/dist/core/schema/view.mjs +19 -24
  110. package/dist/core/store/schema.d.mts +5 -0
  111. package/dist/core/store/schema.mjs +10 -0
  112. package/dist/core/types/api.d.mts +21 -1
  113. package/dist/core/types/api.mjs +1 -1
  114. package/dist/core/types/drill-api.d.mts +210 -0
  115. package/dist/core/types/options.d.mts +21 -0
  116. package/dist/core/types/viewer.d.mts +5 -0
  117. package/dist/cursor-seal.d.mts +8 -0
  118. package/dist/cursor-seal.mjs +98 -0
  119. package/dist/dashboard-id.mjs +1 -1
  120. package/dist/dashboards.mjs +4 -0
  121. package/dist/drill-access.mjs +93 -0
  122. package/dist/drill-change.mjs +76 -0
  123. package/dist/drill-crumbs.mjs +113 -0
  124. package/dist/drill-distinct.mjs +130 -0
  125. package/dist/drill-explain.mjs +64 -0
  126. package/dist/drill-identity.mjs +35 -0
  127. package/dist/drill-item-id.mjs +35 -0
  128. package/dist/drill-items.mjs +132 -0
  129. package/dist/drill-open.mjs +169 -0
  130. package/dist/drill-seal.mjs +170 -0
  131. package/dist/drill-secret.mjs +14 -0
  132. package/dist/drill-share.mjs +53 -0
  133. package/dist/drill-summary.mjs +158 -0
  134. package/dist/drill-targets.mjs +53 -0
  135. package/dist/drill-totals.mjs +8 -0
  136. package/dist/drill-views.mjs +175 -0
  137. package/dist/drill.mjs +157 -0
  138. package/dist/editing.mjs +3 -3
  139. package/dist/endpoints/dashboards.mjs +28 -5
  140. package/dist/endpoints/drill.mjs +55 -0
  141. package/dist/endpoints/index.d.mts +245 -4
  142. package/dist/endpoints/index.mjs +5 -1
  143. package/dist/endpoints/meta.mjs +10 -1
  144. package/dist/endpoints/query.mjs +26 -4
  145. package/dist/execute.d.mts +19 -1
  146. package/dist/execute.mjs +34 -27
  147. package/dist/handler.mjs +5 -1
  148. package/dist/index.d.mts +3 -1
  149. package/dist/index.mjs +29 -2
  150. package/dist/llms.txt +22 -0
  151. package/dist/mcp/drill.mjs +61 -0
  152. package/dist/mcp/format.mjs +69 -11
  153. package/dist/mcp/index.d.mts +15 -4
  154. package/dist/mcp/index.mjs +13 -7
  155. package/dist/mcp/query.d.mts +7 -2
  156. package/dist/mcp/query.mjs +40 -6
  157. package/dist/node-postgres.d.mts +8 -4
  158. package/dist/node-postgres.mjs +29 -6
  159. package/dist/owner.mjs +3 -3
  160. package/dist/postgres-connection.d.mts +8 -2
  161. package/dist/postgres-connection.mjs +2 -1
  162. package/dist/postgres-store.mjs +1 -0
  163. package/dist/react/Canvas.mjs +28 -5
  164. package/dist/react/Cell.mjs +2 -1
  165. package/dist/react/Dashboard.d.mts +10 -5
  166. package/dist/react/Dashboard.mjs +62 -22
  167. package/dist/react/DashboardList.mjs +52 -24
  168. package/dist/react/DashboardListRow.mjs +49 -0
  169. package/dist/react/Discard.mjs +12 -4
  170. package/dist/react/Editing.mjs +19 -5
  171. package/dist/react/FilterBar.d.mts +7 -9
  172. package/dist/react/Grid.mjs +19 -24
  173. package/dist/react/Header.mjs +10 -1
  174. package/dist/react/History.mjs +5 -0
  175. package/dist/react/Parts.mjs +6 -2
  176. package/dist/react/ReadFailed.mjs +23 -0
  177. package/dist/react/ReviewPanel.mjs +13 -2
  178. package/dist/react/RowBody.d.mts +19 -0
  179. package/dist/react/RowBody.mjs +55 -0
  180. package/dist/react/Spaces.mjs +15 -1
  181. package/dist/react/Tile.d.mts +3 -1
  182. package/dist/react/Tile.mjs +84 -32
  183. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  184. package/dist/react/arrange-steps.mjs +16 -13
  185. package/dist/react/arrange.mjs +10 -3
  186. package/dist/react/builder/Calcs.mjs +35 -11
  187. package/dist/react/builder/FilterEditor.mjs +196 -0
  188. package/dist/react/builder/Filters.mjs +172 -116
  189. package/dist/react/builder/Formula.mjs +82 -0
  190. package/dist/react/builder/Groups.mjs +1 -0
  191. package/dist/react/builder/Preview.mjs +1 -1
  192. package/dist/react/builder/RangeEditor.mjs +184 -0
  193. package/dist/react/builder/Sections.mjs +41 -6
  194. package/dist/react/builder/Time.mjs +138 -60
  195. package/dist/react/builder/Values.mjs +85 -0
  196. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  197. package/dist/react/builder/base.d.mts +5 -0
  198. package/dist/react/builder/base.mjs +33 -8
  199. package/dist/react/builder/calc.mjs +15 -1
  200. package/dist/react/builder/escape.d.mts +1 -0
  201. package/dist/react/builder/escape.mjs +62 -0
  202. package/dist/react/builder/filter-tree.d.mts +9 -0
  203. package/dist/react/builder/filter-tree.mjs +186 -0
  204. package/dist/react/builder/formula-parse.d.mts +18 -0
  205. package/dist/react/builder/formula-parse.mjs +136 -0
  206. package/dist/react/builder/labels.d.mts +1 -1
  207. package/dist/react/builder/state.d.mts +2 -1
  208. package/dist/react/builder/state.mjs +23 -37
  209. package/dist/react/builder/useBuilder.d.mts +12 -1
  210. package/dist/react/builder/useBuilder.mjs +6 -3
  211. package/dist/react/builder/words.d.mts +59 -0
  212. package/dist/react/builder/words.mjs +73 -0
  213. package/dist/react/client.d.mts +2 -0
  214. package/dist/react/client.mjs +1 -0
  215. package/dist/react/context.d.mts +28 -1
  216. package/dist/react/context.mjs +25 -4
  217. package/dist/react/drill/Bars.mjs +179 -0
  218. package/dist/react/drill/Controls.mjs +173 -0
  219. package/dist/react/drill/DashboardTile.d.mts +18 -0
  220. package/dist/react/drill/DashboardTile.mjs +107 -0
  221. package/dist/react/drill/DrillPanel.d.mts +31 -0
  222. package/dist/react/drill/DrillPanel.mjs +104 -0
  223. package/dist/react/drill/DrillTabs.mjs +52 -0
  224. package/dist/react/drill/Header.mjs +131 -0
  225. package/dist/react/drill/Items.d.mts +22 -0
  226. package/dist/react/drill/Items.mjs +164 -0
  227. package/dist/react/drill/ItemsFoot.mjs +60 -0
  228. package/dist/react/drill/Notes.mjs +58 -0
  229. package/dist/react/drill/PanelBody.mjs +74 -0
  230. package/dist/react/drill/PanelStates.mjs +37 -0
  231. package/dist/react/drill/board.d.mts +18 -0
  232. package/dist/react/drill/board.mjs +91 -0
  233. package/dist/react/drill/counts.mjs +14 -0
  234. package/dist/react/drill/host.mjs +26 -0
  235. package/dist/react/drill/item-parts.d.mts +5 -0
  236. package/dist/react/drill/item-parts.mjs +76 -0
  237. package/dist/react/drill/item-type.d.mts +26 -0
  238. package/dist/react/drill/item-type.mjs +7 -0
  239. package/dist/react/drill/lazy.d.mts +6 -0
  240. package/dist/react/drill/lazy.mjs +17 -0
  241. package/dist/react/drill/pages.mjs +48 -0
  242. package/dist/react/drill/panel-focus.mjs +51 -0
  243. package/dist/react/drill/props.d.mts +25 -0
  244. package/dist/react/drill/props.mjs +72 -0
  245. package/dist/react/drill/state.d.mts +18 -0
  246. package/dist/react/drill/state.mjs +68 -0
  247. package/dist/react/drill/useDrill.d.mts +46 -0
  248. package/dist/react/drill/useDrill.mjs +194 -0
  249. package/dist/react/drill/words.d.mts +101 -0
  250. package/dist/react/drill/words.mjs +79 -0
  251. package/dist/react/english.mjs +29 -6
  252. package/dist/react/filters/bar.d.mts +12 -0
  253. package/dist/react/filters/bar.mjs +135 -0
  254. package/dist/react/filters/calendar.mjs +193 -0
  255. package/dist/react/filters/chip.mjs +174 -0
  256. package/dist/react/filters/context.d.mts +22 -0
  257. package/dist/react/filters/context.mjs +78 -0
  258. package/dist/react/filters/dates.mjs +89 -0
  259. package/dist/react/filters/days.d.mts +36 -0
  260. package/dist/react/filters/days.mjs +87 -0
  261. package/dist/react/filters/field-step.mjs +81 -0
  262. package/dist/react/filters/hooks.d.mts +34 -0
  263. package/dist/react/filters/hooks.mjs +94 -0
  264. package/dist/react/filters/listbox.mjs +131 -0
  265. package/dist/react/filters/logic.d.mts +59 -0
  266. package/dist/react/filters/logic.mjs +109 -0
  267. package/dist/react/filters/menu-search.mjs +211 -0
  268. package/dist/react/filters/menu.mjs +85 -0
  269. package/dist/react/filters/number.mjs +127 -0
  270. package/dist/react/filters/numbers.d.mts +47 -0
  271. package/dist/react/filters/numbers.mjs +151 -0
  272. package/dist/react/filters/operator.mjs +104 -0
  273. package/dist/react/filters/phone.mjs +104 -0
  274. package/dist/react/filters/popover.d.mts +19 -0
  275. package/dist/react/filters/popover.mjs +153 -0
  276. package/dist/react/filters/rules.d.mts +8 -0
  277. package/dist/react/filters/rules.mjs +55 -0
  278. package/dist/react/filters/sheet.mjs +196 -0
  279. package/dist/react/filters/state.mjs +132 -0
  280. package/dist/react/filters/suggest.d.mts +47 -0
  281. package/dist/react/filters/suggest.mjs +97 -0
  282. package/dist/react/filters/values.mjs +166 -0
  283. package/dist/react/filters/words.d.mts +81 -0
  284. package/dist/react/filters/words.mjs +73 -0
  285. package/dist/react/format.d.mts +3 -3
  286. package/dist/react/format.mjs +45 -16
  287. package/dist/react/index.d.mts +34 -5
  288. package/dist/react/index.mjs +15 -4
  289. package/dist/react/messages.d.mts +47 -2
  290. package/dist/react/place.mjs +7 -3
  291. package/dist/react/renderers/index.d.mts +10 -2
  292. package/dist/react/renderers/index.mjs +116 -14
  293. package/dist/react/renderers/list.d.mts +22 -0
  294. package/dist/react/renderers/list.mjs +118 -0
  295. package/dist/react/review-words.mjs +1 -1
  296. package/dist/react/review.mjs +2 -2
  297. package/dist/react/scope.mjs +2 -7
  298. package/dist/react/series.d.mts +54 -0
  299. package/dist/react/series.mjs +191 -0
  300. package/dist/react/theme.css +2734 -1296
  301. package/dist/react/theme.css.d.ts +1 -0
  302. package/dist/react/tile-store.mjs +15 -3
  303. package/dist/react/useBoard.d.mts +7 -0
  304. package/dist/react/useBoard.mjs +4 -1
  305. package/dist/react/useDashboard.d.mts +4 -0
  306. package/dist/react/useDashboard.mjs +8 -1
  307. package/dist/react/useTiles.mjs +50 -15
  308. package/dist/react/view-grid.mjs +16 -0
  309. package/dist/react/view.d.mts +9 -0
  310. package/dist/react/view.mjs +22 -10
  311. package/dist/reading.d.mts +2 -0
  312. package/dist/reading.mjs +9 -1
  313. package/dist/recharts/axes.mjs +28 -0
  314. package/dist/recharts/axis.mjs +84 -0
  315. package/dist/recharts/bar.d.mts +7 -0
  316. package/dist/recharts/bar.mjs +140 -0
  317. package/dist/recharts/charts.d.mts +4 -6
  318. package/dist/recharts/charts.mjs +2 -114
  319. package/dist/recharts/index.d.mts +5 -3
  320. package/dist/recharts/index.mjs +6 -3
  321. package/dist/recharts/line.d.mts +2 -0
  322. package/dist/recharts/line.mjs +111 -0
  323. package/dist/recharts/marks.mjs +112 -0
  324. package/dist/recharts/parts.mjs +88 -0
  325. package/dist/recharts/series.d.mts +2 -22
  326. package/dist/recharts/series.mjs +1 -64
  327. package/dist/recharts/table.mjs +71 -0
  328. package/dist/records-read.mjs +44 -0
  329. package/dist/registry/filter-bar.json +26 -0
  330. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  331. package/dist/store/apply.mjs +5 -5
  332. package/dist/store/commands.mjs +4 -4
  333. package/dist/store/discard.mjs +7 -7
  334. package/dist/store/drafts.mjs +5 -5
  335. package/dist/store/editor.mjs +1 -1
  336. package/dist/store/publish.mjs +12 -12
  337. package/dist/store/reader.mjs +41 -22
  338. package/dist/store/review.mjs +16 -16
  339. package/dist/store/rows.mjs +20 -20
  340. package/dist/store/undo.mjs +3 -3
  341. package/dist/store/unpublished.mjs +4 -4
  342. package/dist/store/versions.mjs +14 -14
  343. package/dist/testing/adapter-suite.mjs +4 -4
  344. package/dist/tiles.mjs +37 -3
  345. package/package.json +12 -10
  346. package/dist/react/FilterBar.mjs +0 -119
  347. package/dist/react/Records.d.mts +0 -12
  348. package/dist/react/Records.mjs +0 -97
  349. package/src/adapter/sql-adapter.ts +0 -95
  350. package/src/adapter/statement.ts +0 -185
  351. package/src/authorize.ts +0 -73
  352. package/src/body.ts +0 -169
  353. package/src/bounded.ts +0 -43
  354. package/src/cache.ts +0 -192
  355. package/src/checks.ts +0 -170
  356. package/src/custom-source.ts +0 -59
  357. package/src/dashboard-id.ts +0 -36
  358. package/src/dashboards.ts +0 -132
  359. package/src/editing.ts +0 -148
  360. package/src/endpoints/access.ts +0 -41
  361. package/src/endpoints/dashboards.ts +0 -92
  362. package/src/endpoints/drafts.ts +0 -138
  363. package/src/endpoints/index.ts +0 -21
  364. package/src/endpoints/meta.ts +0 -137
  365. package/src/endpoints/query.ts +0 -86
  366. package/src/endpoints/read.ts +0 -92
  367. package/src/endpoints/review.ts +0 -89
  368. package/src/endpoints/values.ts +0 -62
  369. package/src/endpoints/versions.ts +0 -104
  370. package/src/execute.ts +0 -207
  371. package/src/handler.ts +0 -232
  372. package/src/http.ts +0 -66
  373. package/src/index.ts +0 -163
  374. package/src/introspect.ts +0 -205
  375. package/src/mcp/api.ts +0 -59
  376. package/src/mcp/format.ts +0 -67
  377. package/src/mcp/index.ts +0 -151
  378. package/src/mcp/query.ts +0 -153
  379. package/src/mcp/resolve.ts +0 -114
  380. package/src/node-postgres.ts +0 -81
  381. package/src/owner.ts +0 -36
  382. package/src/postgres-connection.ts +0 -143
  383. package/src/postgres-store.ts +0 -82
  384. package/src/principal.ts +0 -39
  385. package/src/reading.ts +0 -56
  386. package/src/request-rows.ts +0 -23
  387. package/src/request.ts +0 -22
  388. package/src/storage.ts +0 -63
  389. package/src/store/apply.ts +0 -129
  390. package/src/store/commands.ts +0 -75
  391. package/src/store/conflicts.ts +0 -98
  392. package/src/store/create-tables.ts +0 -104
  393. package/src/store/discard.ts +0 -42
  394. package/src/store/drafts.ts +0 -133
  395. package/src/store/editor.ts +0 -28
  396. package/src/store/log.ts +0 -28
  397. package/src/store/publish.ts +0 -199
  398. package/src/store/publisher.ts +0 -21
  399. package/src/store/reader.ts +0 -139
  400. package/src/store/review.ts +0 -239
  401. package/src/store/rows.ts +0 -250
  402. package/src/store/tenant.ts +0 -28
  403. package/src/store/undo.ts +0 -56
  404. package/src/store/unpublished.ts +0 -33
  405. package/src/store/versions.ts +0 -106
  406. package/src/store/writer.ts +0 -19
  407. package/src/testing/adapter-suite.ts +0 -239
  408. package/src/testing/index.ts +0 -2
  409. package/src/tile-doc.ts +0 -46
  410. package/src/tiles.ts +0 -120
@@ -1,4 +1,5 @@
1
- import { LAST_30_DAYS, cleared, defaultTime, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
1
+ import { DEFAULT_RANGE, cleared, defaultTime, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
2
+ import { addCondition, removeNode, setMode } from "./filter-tree.mjs";
2
3
  import { formulaRefs } from "derive-dashboards/core";
3
4
  // src/builder/state.ts
4
5
  /** The builder's changes to measures, groups, time and filters. Calcs are in `calc.ts`. */
@@ -121,7 +122,7 @@ function timeOf(current, change) {
121
122
  if (dimension === void 0) return void 0;
122
123
  return {
123
124
  dimension,
124
- range: change.range ?? current.range ?? LAST_30_DAYS,
125
+ range: change.range ?? current.range ?? DEFAULT_RANGE,
125
126
  ...grainOf(change.grain ?? current.grain),
126
127
  ...compareOf(change.compare ?? current.compare)
127
128
  };
@@ -156,46 +157,31 @@ function setTime(meta, state, change) {
156
157
  removed: gone.map((c) => c.label ?? c.id)
157
158
  };
158
159
  }
159
- /** The filter's leaves under its one `all`. */
160
- function filterLeaves(filter) {
161
- if (filter === void 0) return [];
162
- return "all" in filter ? [...filter.all] : [filter];
160
+ /** The query with its filter replaced; none when the filter is gone. */
161
+ function withFilter(meta, state, filter) {
162
+ const query = state.query;
163
+ if (query === void 0) return state;
164
+ const { filters: _old, ...without } = query;
165
+ return withQuery(meta, state, filter === void 0 ? without : {
166
+ ...without,
167
+ filters: filter
168
+ });
163
169
  }
164
- /** Keeps rows whose field is (or is not) one of the values. */
170
+ /** Adds a condition: at the top, to a group, or (`group: "new"`) as a new group of one. */
165
171
  function addFilter(meta, state, filter) {
166
172
  const query = state.query;
167
- if (query === void 0 || filter.values.length === 0) return state;
168
- const current = filterLeaves(query.filters);
169
- const taken = new Set(current.map((f) => f.id));
170
- let n = current.length + 1;
171
- while (taken.has(`f${n}`)) n += 1;
172
- const op = filter.negate === true ? "notIn" : "in";
173
- const leaf = {
174
- id: `f${n}`,
175
- member: filter.member,
176
- op,
177
- values: [...filter.values]
178
- };
179
- return withQuery(meta, state, {
180
- ...query,
181
- filters: {
182
- id: "filters",
183
- all: [...current, leaf]
184
- }
185
- });
173
+ if (query === void 0) return state;
174
+ const { group, ...condition } = filter;
175
+ return withFilter(meta, state, addCondition(query.filters, condition, group));
186
176
  }
177
+ /** Removes a condition, a group, or a part the builder keeps as written. */
187
178
  function removeFilter(meta, state, id) {
179
+ return state.query === void 0 ? state : withFilter(meta, state, removeNode(state.query.filters, id));
180
+ }
181
+ /** How the top matches its parts, or (with `group`) how a group matches its conditions. */
182
+ function setFilterMode(meta, state, change) {
188
183
  const query = state.query;
189
184
  if (query === void 0) return state;
190
- const rest = filterLeaves(query.filters).filter((f) => f.id !== id);
191
- const { filters: _old, ...without } = query;
192
- const next = rest.length === 0 ? without : {
193
- ...without,
194
- filters: {
195
- id: "filters",
196
- all: rest
197
- }
198
- };
199
- return withQuery(meta, state, next);
185
+ return withFilter(meta, state, setMode(query.filters, change.mode, change.group));
200
186
  }
201
- export { addFilter, addGroup, addMeasure, cutGroup, filterLeaves, moveGroup, removeFilter, removeGroup, removeMeasure, setTime };
187
+ export { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setFilterMode, setTime };
@@ -1,6 +1,8 @@
1
+ import { GroupMode } from "./filter-tree.mjs";
1
2
  import { BuilderState } from "./base.mjs";
2
3
  import { CalcPreset } from "./calc.mjs";
3
4
  import { TimeChange } from "./state.mjs";
5
+ import "./escape.mjs";
4
6
  import { Widget } from "derive-dashboards/core";
5
7
  /**
6
8
  * The widget builder without its look: the widget being built, the viewer's meta, the live
@@ -25,11 +27,20 @@ export declare function useBuilder(initial?: Widget): {
25
27
  setTime: (change: TimeChange) => void;
26
28
  addFilter: (filter: {
27
29
  member: string;
30
+ op: import("derive-dashboards/core").Op;
28
31
  values: readonly import("derive-dashboards/core").Primitive[];
29
- negate?: boolean;
32
+ group?: string;
33
+ }) => void;
34
+ setFilterMode: (change: {
35
+ mode: GroupMode;
36
+ group?: string;
30
37
  }) => void;
31
38
  removeFilter: (id: string) => void;
32
39
  addCalc: (preset: CalcPreset) => void;
40
+ addFormula: (calc: {
41
+ label: string;
42
+ formula: import("derive-dashboards/core").StoredFormulaNode;
43
+ }) => void;
33
44
  updateCalc: (id: string, change: {
34
45
  label?: string;
35
46
  format?: import("derive-dashboards/core").Format;
@@ -1,10 +1,11 @@
1
1
  import { useDashboards } from "../context.mjs";
2
2
  import { emptyBuilder, setKind, setTitle, widgetOf } from "./base.mjs";
3
- import { addCalc, presetsFor, removeCalc, updateCalc } from "./calc.mjs";
3
+ import { addCalc, addFormula, presetsFor, removeCalc, updateCalc } from "./calc.mjs";
4
4
  import { labelOf } from "./labels.mjs";
5
5
  import { measureHint } from "./options.mjs";
6
- import { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setTime } from "./state.mjs";
6
+ import { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setFilterMode, setTime } from "./state.mjs";
7
7
  import { usePreview } from "./usePreview.mjs";
8
+ import { useEscapeToLeave } from "./escape.mjs";
8
9
  import { useState } from "react";
9
10
  import useSWR from "swr";
10
11
  // src/builder/useBuilder.ts
@@ -34,8 +35,10 @@ function useBuilder(initial) {
34
35
  moveGroup: on(moveGroup),
35
36
  setTime: on(setTime),
36
37
  addFilter: on(addFilter),
38
+ setFilterMode: on(setFilterMode),
37
39
  removeFilter: on(removeFilter),
38
40
  addCalc: on(addCalc),
41
+ addFormula: on(addFormula),
39
42
  updateCalc: on(updateCalc),
40
43
  removeCalc: on(removeCalc),
41
44
  setTitle: on(setTitle),
@@ -57,4 +60,4 @@ function useBuilder(initial) {
57
60
  }
58
61
  };
59
62
  }
60
- export { useBuilder };
63
+ export { useBuilder, useEscapeToLeave };
@@ -0,0 +1,59 @@
1
+ import { GroupMode } from "./filter-tree.mjs";
2
+ import { FormulaProblem } from "./formula-parse.mjs";
3
+ import { Grain, Op } from "derive-dashboards/core";
4
+ /** The units a rolling range counts in. */
5
+ export type RangeUnit = Exclude<Grain, "hour">;
6
+ export type BuilderMessages = {
7
+ /** The chip that opens the custom range editor. */
8
+ customRange: string;
9
+ /** The names of the time row's two selects: how time splits, and which days it covers. */
10
+ timeField: string;
11
+ /** A quick range's short name on its button: "7D", "12M". */
12
+ shortRange: (r: {
13
+ last: number;
14
+ unit: string;
15
+ }) => string;
16
+ /** The labels of a fixed range's first and last day. */
17
+ fromDay: string;
18
+ toDay: string;
19
+ breakdown: string;
20
+ timeRange: string;
21
+ /** A range that moves with today: "Last 6 months". */
22
+ rolling: string;
23
+ /** A range of fixed days. */
24
+ betweenDates: string;
25
+ last: string;
26
+ /** A rolling range's last unit counts so far: "Including today", "Including this month so far". */
27
+ withCurrent: (unit: RangeUnit) => string;
28
+ /** The plural of a unit, for the unit picker: "months". */
29
+ units: Record<RangeUnit, string>;
30
+ /** The unit picker's name, for a screen reader. */
31
+ unit: string;
32
+ rangeTo: string;
33
+ bothDaysIncluded: string;
34
+ endBeforeStart: string;
35
+ /** Each operator as the filter editor offers it: "more than", "doesn't contain". */
36
+ ops: Record<Op, string>;
37
+ /** A condition's test in words: "is done, review", "between 2 and 8", "is empty". */
38
+ filterTest: (op: Op, values: readonly string[]) => string;
39
+ /** How a group or the whole filter matches: all, any or none of its parts. */
40
+ modes: Record<GroupMode, string>;
41
+ /** "Rows matching" … "all" … "of these:". */
42
+ matching: string;
43
+ ofThese: string;
44
+ addGroup: string;
45
+ addToGroup: string;
46
+ removeGroup: string;
47
+ /** A part set in code the builder cannot edit, kept as it is on Save. */
48
+ keptAsWritten: string;
49
+ keptNested: string;
50
+ value: string;
51
+ /** Under between: "Both ends included." */
52
+ bothEnds: string;
53
+ /** The chip that opens a formula of your own. */
54
+ formula: string;
55
+ /** Under a formula that reads: what it uses, and what a division by zero shows. */
56
+ formulaUses: (names: readonly string[]) => string;
57
+ formulaProblem: (problem: FormulaProblem) => string;
58
+ addCalculation: string;
59
+ };
@@ -0,0 +1,73 @@
1
+ // src/builder/words.ts
2
+ const ENGLISH_OPS = {
3
+ equals: "is",
4
+ in: "is",
5
+ notEquals: "is not",
6
+ notIn: "is not",
7
+ contains: "contains",
8
+ notContains: "doesn't contain",
9
+ startsWith: "starts with",
10
+ gt: "more than",
11
+ gte: "at least",
12
+ lt: "less than",
13
+ lte: "at most",
14
+ between: "between",
15
+ set: "has a value",
16
+ notSet: "is empty"
17
+ };
18
+ const ENGLISH_BUILDER = {
19
+ customRange: "Custom",
20
+ timeField: "Field",
21
+ shortRange: (r) => `${String(r.last)}${r.unit.charAt(0).toUpperCase()}`,
22
+ fromDay: "From",
23
+ toDay: "To",
24
+ breakdown: "Breakdown",
25
+ timeRange: "Range",
26
+ rolling: "Rolling",
27
+ betweenDates: "Between dates",
28
+ last: "Last",
29
+ withCurrent: (unit) => unit === "day" ? "Including today" : `Including this ${unit} so far`,
30
+ unit: "Unit",
31
+ units: {
32
+ day: "days",
33
+ week: "weeks",
34
+ month: "months",
35
+ quarter: "quarters",
36
+ year: "years"
37
+ },
38
+ rangeTo: "to",
39
+ bothDaysIncluded: "Both days included, in the dashboard's time zone.",
40
+ endBeforeStart: "The end is before the start.",
41
+ ops: ENGLISH_OPS,
42
+ filterTest: (op, values) => {
43
+ const word = ENGLISH_OPS[op];
44
+ if (op === "set" || op === "notSet") return word;
45
+ if (op === "between") return `between ${values[0] ?? ""} and ${values[1] ?? ""}`;
46
+ return `${word} ${values.join(", ")}`;
47
+ },
48
+ modes: {
49
+ all: "all",
50
+ any: "any",
51
+ none: "none"
52
+ },
53
+ matching: "Rows matching",
54
+ ofThese: "of these:",
55
+ addGroup: "+ Group",
56
+ addToGroup: "+ Add to this group",
57
+ removeGroup: "Remove group",
58
+ keptAsWritten: "set in code, kept as is",
59
+ keptNested: "Conditions set in code, kept as written",
60
+ value: "Value",
61
+ bothEnds: "Both ends included.",
62
+ formula: "Formula",
63
+ formulaUses: (names) => `Uses ${names.join(", ")}. A division by zero shows as empty.`,
64
+ formulaProblem: (p) => {
65
+ if (p.kind === "empty") return "Write a formula, like Hours logged / Tasks.";
66
+ if (p.kind === "unknown") return `"${p.text}" is not a measure here, at character ${String(p.at)}.`;
67
+ if (p.kind === "unclosed") return `The bracket at character ${String(p.at)} is never closed.`;
68
+ if (p.kind === "unopened") return `A closing bracket has no opening one, at character ${String(p.at)}.`;
69
+ return `Expected a number, a measure or a bracket at character ${String(p.at)}.`;
70
+ },
71
+ addCalculation: "Add calculation"
72
+ };
73
+ export { ENGLISH_BUILDER };
@@ -20,6 +20,8 @@ export type DashboardsClient = {
20
20
  memberValues(request: BodyOf<"/meta/values">): Answer<"/meta/values">;
21
21
  /** A page of the rows behind a tile, under the same filters as its answer. */
22
22
  records(request: BodyOf<"/dashboards/records">): Answer<"/dashboards/records">;
23
+ /** The rows behind a mark: of a dashboard's tile, or (origin `query`) of a free query. */
24
+ drill(request: BodyOf<"/dashboards/drill">, signal?: AbortSignal): Answer<"/dashboards/drill">;
23
25
  /** The caller's open draft of a dashboard, or a new one from its current version. */
24
26
  startDraft(dashboardId: string): Answer<"/dashboards/draft/start">;
25
27
  /** A draft of a new dashboard, which only its maker sees until they publish it; `requestId` makes a retry create it once. */
@@ -85,6 +85,7 @@ function methods(core) {
85
85
  getDashboard: (dashboardId) => core("/dashboards/get", { dashboardId }),
86
86
  controlValues: (body) => core("/dashboards/control-values", body),
87
87
  records: (body) => core("/dashboards/records", body),
88
+ drill: (body, signal) => body.state.origin.kind === "query" ? core("/query/drill", body, signal) : core("/dashboards/drill", body, signal),
88
89
  queryRun: (query, signal) => core("/query/run", { query }, signal),
89
90
  memberValues: (body) => core("/meta/values", body),
90
91
  startDraft: (dashboardId) => core("/dashboards/draft/start", { dashboardId }),
@@ -1,14 +1,29 @@
1
1
  import { DashboardsClient } from "./client.mjs";
2
+ import { FilterBarProps } from "./filters/hooks.mjs";
3
+ import "./FilterBar.mjs";
2
4
  import { Messages } from "./messages.mjs";
3
5
  import { TileRenderer } from "./renderers/index.mjs";
4
- import { ReactNode } from "react";
6
+ import { ComponentType, MouseEvent, ReactNode } from "react";
5
7
  import { Author } from "derive-dashboards/core";
8
+ /** The props every link the library draws passes: a router's link component takes them. */
9
+ export type LinkProps = {
10
+ href: string;
11
+ className?: string;
12
+ children: ReactNode;
13
+ onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
14
+ };
15
+ /** A link component, such as Next.js's `Link`; a plain `<a>` by default. */
16
+ export type LinkComponent = ComponentType<LinkProps>;
6
17
  type Value = {
7
18
  client: DashboardsClient;
19
+ components: Components;
20
+ link?: LinkComponent;
8
21
  renderers: Record<string, TileRenderer>;
9
22
  locale?: string;
10
23
  messages: Messages;
11
24
  authorName?: (author: Author) => string | undefined;
25
+ /** Who answers and for whom: the viewer's key and the client, so no cache serves another viewer. */
26
+ cacheScope: string;
12
27
  };
13
28
  export type DashboardsProviderProps = {
14
29
  client: DashboardsClient;
@@ -25,8 +40,20 @@ export type DashboardsProviderProps = {
25
40
  viewerKey?: string;
26
41
  /** A person's or agent's name, for the history; without it, versions show only when. */
27
42
  authorName?: (author: Author) => string | undefined;
43
+ /** The link component every link the library draws uses, so they go through your router. */
44
+ link?: LinkComponent;
45
+ /**
46
+ * Parts of the dashboard you draw yourself, each given the same props as the built-in one:
47
+ * `{ FilterBar }` swaps the filter bar, for example the shadcn one
48
+ * (`npx shadcn@latest add ./node_modules/derive-dashboards/dist/registry/filter-bar.json`).
49
+ */
50
+ components?: Partial<Components>;
28
51
  children: ReactNode;
29
52
  };
53
+ /** The parts a host may draw itself. Each defaults to the library's own. */
54
+ export type Components = {
55
+ FilterBar: ComponentType<FilterBarProps>;
56
+ };
30
57
  export declare function DashboardsProvider(props: DashboardsProviderProps): import("react").JSX.Element;
31
58
  export declare function useDashboards(): Value;
32
59
  export {};
@@ -1,16 +1,29 @@
1
+ import { FilterBar } from "./filters/bar.mjs";
1
2
  import { ENGLISH } from "./english.mjs";
2
3
  import { BUILTIN_RENDERERS } from "./renderers/index.mjs";
3
4
  import { createContext, useContext, useMemo } from "react";
4
5
  import { SWRConfig } from "swr";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  // src/context.tsx
8
+ /** A stable number per client, so a new client starts its own caches. */
9
+ const clientIds = /* @__PURE__ */ new WeakMap();
10
+ const counted = { clients: 0 };
11
+ function clientId(client) {
12
+ const known = clientIds.get(client);
13
+ if (known !== void 0) return known;
14
+ counted.clients += 1;
15
+ clientIds.set(client, counted.clients);
16
+ return counted.clients;
17
+ }
7
18
  const Context = createContext(null);
8
19
  /** A cache of the provider's own, so answers never mix with the host's or another viewer's. */
9
20
  const ownCache = { provider: () => /* @__PURE__ */ new Map() };
10
21
  function DashboardsProvider(props) {
11
- const { client, renderers, locale, messages, viewerKey, authorName, children } = props;
22
+ const { client, renderers, locale, messages, viewerKey, authorName, link, components, children } = props;
23
+ const cacheScope = `${viewerKey ?? ""}:${String(clientId(client))}`;
12
24
  const value = useMemo(() => ({
13
25
  client,
26
+ cacheScope,
14
27
  renderers: {
15
28
  ...BUILTIN_RENDERERS,
16
29
  ...renderers
@@ -20,13 +33,21 @@ function DashboardsProvider(props) {
20
33
  ...ENGLISH,
21
34
  ...messages
22
35
  },
23
- ...authorName === void 0 ? {} : { authorName }
36
+ ...authorName === void 0 ? {} : { authorName },
37
+ ...link === void 0 ? {} : { link },
38
+ components: {
39
+ FilterBar,
40
+ ...components
41
+ }
24
42
  }), [
25
43
  client,
44
+ cacheScope,
26
45
  renderers,
27
46
  locale,
28
47
  messages,
29
- authorName
48
+ authorName,
49
+ link,
50
+ components
30
51
  ]);
31
52
  return /* @__PURE__ */ jsx(SWRConfig, {
32
53
  value: ownCache,
@@ -34,7 +55,7 @@ function DashboardsProvider(props) {
34
55
  value,
35
56
  children
36
57
  })
37
- }, viewerKey);
58
+ }, cacheScope);
38
59
  }
39
60
  function useDashboards() {
40
61
  const value = useContext(Context);
@@ -0,0 +1,179 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatBucket, formatCell, plotValue } from "../format.mjs";
3
+ import { rowEntry } from "./state.mjs";
4
+ import { isMark } from "derive-dashboards/core";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ // src/drill/Bars.tsx
7
+ /** A row's name: its time bucket or its group, as the tile names it ("No assignee" for no value). */
8
+ function rowName(view, row, format) {
9
+ const [cell = null] = row;
10
+ const [column] = view.answer.columns;
11
+ return isMark(cell) || cell === null || cell === "" ? markName(cell, column?.label ?? "", format) : valueName(cell, column, format);
12
+ }
13
+ /** Other, Total, or "No assignee" for a group with no value. */
14
+ const markName = (cell, label, format) => isMark(cell) ? cell.mark === "other" ? format.messages.other : format.messages.total : format.messages.drillNone(label);
15
+ /** A group's value as the tile names it: a time bucket at its grain, else the formatted value. */
16
+ function valueName(cell, column, format) {
17
+ if (column?.grain !== void 0 && typeof cell === "string") return formatBucket(cell, column.grain, format.locale);
18
+ return formatCell(cell, column, format);
19
+ }
20
+ /** The line's column: the one named, else the first value column. */
21
+ const lineAt = (view, entry) => {
22
+ const named = view.answer.columns.findIndex((c) => c.id === entry);
23
+ return named >= 0 ? named : view.answer.columns.findIndex((c) => c.id.startsWith("m"));
24
+ };
25
+ /** A change with its sign: "+6" when it went up. */
26
+ const signed = (text, size) => size > 0 && !text.startsWith("+") ? `+${text}` : text;
27
+ const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
28
+ /**
29
+ * Each row as a bar: sized by its value, or for a Breakdown of the change by its change, and
30
+ * read as the value, or as now, before and the change. A total is not drawn.
31
+ */
32
+ function barsOf(view, entry, format) {
33
+ const { columns } = view.answer;
34
+ const at = lineAt(view, entry);
35
+ const before = columns.findIndex((c) => c.id === "c1");
36
+ const rows = view.answer.rows.map((row, i) => ({
37
+ row,
38
+ selection: rowEntry(view.drill, i)
39
+ })).filter(({ row }) => !isAll(row));
40
+ const change = columns.findIndex((c) => c.id === "c2");
41
+ const compared = view.change === true && rows.some(({ row }) => (row[change] ?? null) !== null);
42
+ const sized = compared ? change : at;
43
+ const max = Math.max(0, ...rows.map(({ row }) => Math.abs(plotValue(row[sized] ?? null) ?? 0)));
44
+ const text = (row, i) => formatCell(row[i] ?? null, columns[i], format);
45
+ return rows.map(({ row, selection }) => {
46
+ const size = plotValue(row[sized] ?? null) ?? 0;
47
+ return {
48
+ bar: {
49
+ name: rowName(view, row, format),
50
+ width: max === 0 ? 0 : Math.abs(size) / max * 100,
51
+ negative: size < 0,
52
+ text: compared && (row[before] ?? null) !== null ? format.messages.drillChange(text(row, at), formatCell(row[before] ?? null, columns[at], format), signed(text(row, sized), size)) : text(row, at)
53
+ },
54
+ selection
55
+ };
56
+ });
57
+ }
58
+ /** One bar: its name, its bar to scale, its value; a button when it goes deeper. */
59
+ function BarRow(props) {
60
+ const { bar, selection } = props;
61
+ const body = /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ /* @__PURE__ */ jsx("span", {
63
+ className: "dd-drill-bar-name",
64
+ children: bar.name
65
+ }),
66
+ /* @__PURE__ */ jsx("span", {
67
+ className: "dd-drill-bar-track",
68
+ "aria-hidden": "true",
69
+ children: /* @__PURE__ */ jsx("span", {
70
+ className: "dd-drill-bar",
71
+ "data-negative": bar.negative,
72
+ style: { inlineSize: `${bar.width}%` }
73
+ })
74
+ }),
75
+ /* @__PURE__ */ jsx("span", {
76
+ className: "dd-drill-bar-value",
77
+ children: bar.text
78
+ })
79
+ ] });
80
+ const label = `${bar.name}, ${bar.text}`;
81
+ if (selection === void 0) return /* @__PURE__ */ jsx("div", {
82
+ className: "dd-drill-bar-row",
83
+ children: body
84
+ });
85
+ return /* @__PURE__ */ jsx("button", {
86
+ type: "button",
87
+ className: "dd-drill-bar-row",
88
+ "aria-label": label,
89
+ onClick: () => {
90
+ props.onOpen(selection);
91
+ },
92
+ children: body
93
+ });
94
+ }
95
+ /** A Breakdown of the change's total row and where its before and change sit, when it has one to say. */
96
+ function comparedTotal(view) {
97
+ const total = view.answer.rows.find((row) => isAll(row));
98
+ const { columns } = view.answer;
99
+ const before = columns.findIndex((c) => c.id === "c1");
100
+ const change = columns.findIndex((c) => c.id === "c2");
101
+ if (view.change !== true || total === void 0 || change < 0) return;
102
+ return (total[before] ?? null) === null ? void 0 : {
103
+ total,
104
+ before,
105
+ change
106
+ };
107
+ }
108
+ /** The whole change in a Breakdown of the change: "vs 169, +33", from its total row. */
109
+ function changeLine(view, entry, format) {
110
+ const compared = comparedTotal(view);
111
+ if (compared === void 0) return void 0;
112
+ const { total, before, change } = compared;
113
+ const { columns } = view.answer;
114
+ const at = lineAt(view, entry);
115
+ const size = plotValue(total[change] ?? null) ?? 0;
116
+ return format.messages.drillVersus(formatCell(total[before] ?? null, columns[at], format), signed(formatCell(total[change] ?? null, columns[change], format), size));
117
+ }
118
+ /** Over time as columns, oldest to newest: each bucket a column to scale, a button when it goes deeper. */
119
+ function Columns(props) {
120
+ return /* @__PURE__ */ jsx("ol", {
121
+ className: "dd-drill-columns",
122
+ children: props.bars.map(({ bar, selection }, i) => {
123
+ const label = `${bar.name}, ${bar.text}`;
124
+ const column = /* @__PURE__ */ jsx("span", {
125
+ className: "dd-drill-column",
126
+ "data-negative": bar.negative,
127
+ style: { blockSize: `${Math.max(bar.width, 2)}%` }
128
+ });
129
+ return /* @__PURE__ */ jsx("li", {
130
+ title: label,
131
+ children: selection === void 0 ? /* @__PURE__ */ jsx("span", {
132
+ role: "img",
133
+ "aria-label": label,
134
+ children: column
135
+ }) : /* @__PURE__ */ jsx("button", {
136
+ type: "button",
137
+ "aria-label": label,
138
+ onClick: () => {
139
+ props.onOpen(selection);
140
+ },
141
+ children: column
142
+ })
143
+ }, i);
144
+ })
145
+ });
146
+ }
147
+ /**
148
+ * A Breakdown as a list of bars, or Over time as columns: each group or bucket with its value
149
+ * to scale and, when it drills, a button that goes one step deeper. A total is not drawn; a
150
+ * Breakdown of the change says the whole change first.
151
+ */
152
+ function Bars(props) {
153
+ const format = useDashboards();
154
+ const { view } = props;
155
+ const bars = barsOf(view, props.entry, format);
156
+ if (bars.length === 0) return /* @__PURE__ */ jsx("p", {
157
+ className: "dd-tile-state",
158
+ children: view.search === void 0 ? format.messages.drillNoGroups : format.messages.drillNoMatch
159
+ });
160
+ if (view.by === "trend") return /* @__PURE__ */ jsx(Columns, {
161
+ bars,
162
+ onOpen: props.onOpen
163
+ });
164
+ const change = changeLine(view, props.entry, format);
165
+ return /* @__PURE__ */ jsxs(Fragment, { children: [change === void 0 ? null : /* @__PURE__ */ jsx("p", {
166
+ className: "dd-drill-versus",
167
+ children: change
168
+ }), /* @__PURE__ */ jsx("ul", {
169
+ className: "dd-drill-bars",
170
+ "data-by": view.by,
171
+ "data-change": view.change === true,
172
+ children: bars.map(({ bar, selection }, i) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(BarRow, {
173
+ bar,
174
+ selection,
175
+ onOpen: props.onOpen
176
+ }) }, i))
177
+ })] });
178
+ }
179
+ export { Bars };