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
@@ -0,0 +1,164 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { formatCell } from "../format.mjs";
3
+ import { RowBody } from "../RowBody.mjs";
4
+ import { columnShape, itemParts, readMode, writeMode } from "./item-parts.mjs";
5
+ import { asItem } from "./item-type.mjs";
6
+ import { useEffect, useRef, useState } from "react";
7
+ import { itemLink } from "derive-dashboards/core";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ // src/drill/Items.tsx
10
+ const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
11
+ /**
12
+ * An item's link: the host's `itemHref` when it gives one (its `undefined` turns the link off),
13
+ * else its source's `itemLinks` template, else the server's. A hidden key never has one.
14
+ */
15
+ const hrefOf = (options, item) => options.itemHref === void 0 ? itemLink(options.itemLinks, item) ?? item.link : options.itemHref(asItem(item));
16
+ /** How an item opens: as a link, a button, or not at all. */
17
+ function Opener(props) {
18
+ const { link: Link = "a" } = useDashboards();
19
+ const { item, options } = props;
20
+ const href = hrefOf(options, item);
21
+ const onItem = options.onItem;
22
+ if (href === void 0 && onItem === void 0) return /* @__PURE__ */ jsx("div", {
23
+ className: props.className,
24
+ children: props.children
25
+ });
26
+ if (href === void 0) return /* @__PURE__ */ jsx("button", {
27
+ type: "button",
28
+ className: props.className,
29
+ onClick: (event) => onItem?.(asItem(item), { event }),
30
+ children: props.children
31
+ });
32
+ const onClick = (event) => {
33
+ if (onItem === void 0 || !plainClick(event)) return;
34
+ event.preventDefault();
35
+ onItem(asItem(item), { event });
36
+ };
37
+ return /* @__PURE__ */ jsx(Link, {
38
+ href,
39
+ className: props.className,
40
+ onClick,
41
+ children: props.children
42
+ });
43
+ }
44
+ /** A noun as a column heading: "task" reads "Task". */
45
+ const headOf = (noun) => noun === void 0 ? void 0 : `${noun.charAt(0).toLocaleUpperCase()}${noun.slice(1)}`;
46
+ /**
47
+ * Every column of the items as a plain table. Its first column names each row as the list does
48
+ * (its title, or "Task 12" when no field names it) and opens the item; the title's own column is
49
+ * not repeated.
50
+ */
51
+ function Table(props) {
52
+ const format = useDashboards();
53
+ const { view } = props;
54
+ const cell = {
55
+ ...format,
56
+ timeZone: props.timeZone
57
+ };
58
+ const rest = view.columns.filter((c) => c.member !== view.title);
59
+ const named = view.columns.find((c) => c.member === view.title);
60
+ return /* @__PURE__ */ jsx("div", {
61
+ className: "dd-records-scroll",
62
+ children: /* @__PURE__ */ jsxs("table", {
63
+ className: "dd-table",
64
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
65
+ scope: "col",
66
+ children: named?.label ?? headOf(props.noun) ?? format.messages.drillItem
67
+ }), rest.map((c) => /* @__PURE__ */ jsx("th", {
68
+ scope: "col",
69
+ children: c.label
70
+ }, c.member))] }) }), /* @__PURE__ */ jsx("tbody", { children: props.items.map((item, i) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
71
+ scope: "row",
72
+ children: /* @__PURE__ */ jsx(Opener, {
73
+ item,
74
+ options: props.options,
75
+ className: "dd-item-cell",
76
+ children: itemParts(view, item, {
77
+ n: i + 1,
78
+ noun: props.noun
79
+ }, cell).title
80
+ })
81
+ }), rest.map((c) => /* @__PURE__ */ jsx("td", { children: formatCell(item.values[c.member] ?? null, columnShape(c), cell) }, c.member))] }, item.id)) })]
82
+ })
83
+ });
84
+ }
85
+ /** One item with the host's own row: its parts, its link, and how to open it. */
86
+ function helpersOf(options, item, base) {
87
+ const href = hrefOf(options, item);
88
+ const onItem = options.onItem;
89
+ return {
90
+ ...base,
91
+ ...href === void 0 ? {} : { href },
92
+ ...onItem === void 0 ? {} : { open: () => {
93
+ onItem(asItem(item), {});
94
+ } }
95
+ };
96
+ }
97
+ /** The items as a list: the default row, or the host's own (`renderItem`). After Show more, the first new row takes focus. */
98
+ function List(props) {
99
+ const format = useDashboards();
100
+ const { view, options } = props;
101
+ const list = useRef(null);
102
+ const seen = useRef(props.items.length);
103
+ useEffect(() => {
104
+ const before = seen.current;
105
+ seen.current = props.items.length;
106
+ if (props.items.length <= before || before === 0) return;
107
+ list.current?.children[before]?.querySelector("a, button, [tabindex]")?.focus();
108
+ }, [props.items.length]);
109
+ const cell = {
110
+ ...format,
111
+ timeZone: props.timeZone
112
+ };
113
+ return /* @__PURE__ */ jsx("ul", {
114
+ className: "dd-items",
115
+ ref: list,
116
+ children: props.items.map((item, i) => {
117
+ const parts = itemParts(view, item, {
118
+ n: i + 1,
119
+ noun: props.noun
120
+ }, cell);
121
+ const render = options.renderItem;
122
+ const opens = hrefOf(options, item) !== void 0 || options.onItem !== void 0;
123
+ return /* @__PURE__ */ jsx("li", { children: render === void 0 ? /* @__PURE__ */ jsx(Opener, {
124
+ item,
125
+ options,
126
+ className: "dd-item",
127
+ children: /* @__PURE__ */ jsx(RowBody, {
128
+ row: {
129
+ ...parts,
130
+ opens
131
+ },
132
+ family: "item"
133
+ })
134
+ }) : render(asItem(item), helpersOf(options, item, {
135
+ ...parts,
136
+ view
137
+ })) }, item.id);
138
+ })
139
+ });
140
+ }
141
+ /** The items as a list (the default) or a table, the choice kept in this browser. */
142
+ function Items(props) {
143
+ const format = useDashboards();
144
+ const { view, Empty } = props;
145
+ const [mode, setMode] = useState(() => readMode(view.source));
146
+ if (props.items.length === 0) return Empty === void 0 ? /* @__PURE__ */ jsx("p", {
147
+ className: "dd-tile-state",
148
+ children: format.messages.drillNoItems
149
+ }) : /* @__PURE__ */ jsx(Empty, {});
150
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("fieldset", {
151
+ className: "dd-drill-modes",
152
+ "aria-label": format.messages.drillViews.items,
153
+ children: ["list", "table"].map((m) => /* @__PURE__ */ jsx("button", {
154
+ type: "button",
155
+ "aria-pressed": mode === m,
156
+ onClick: () => {
157
+ setMode(m);
158
+ writeMode(view.source, m);
159
+ },
160
+ children: m === "list" ? format.messages.drillList : format.messages.drillTable
161
+ }, m))
162
+ }), mode === "table" ? /* @__PURE__ */ jsx(Table, { ...props }) : /* @__PURE__ */ jsx(List, { ...props })] });
163
+ }
164
+ export { Items };
@@ -0,0 +1,60 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { countText } from "./counts.mjs";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ // src/drill/ItemsFoot.tsx
5
+ /**
6
+ * How many items the list holds: under "Only <numerator>" the numerator's rows; a distinct
7
+ * count's list is its distinct values (its value), not the rows behind them; else the rows.
8
+ */
9
+ function listCount(view, summary) {
10
+ if (view.numerator?.only === true) return view.numerator.count;
11
+ return summary.semantics === "distinct" ? summary.value : summary.itemCount;
12
+ }
13
+ /** Items' count and sort, then Show more while there are more, with a retry when a page fails. */
14
+ function ItemsFoot({ d }) {
15
+ const format = useDashboards();
16
+ const { messages } = format;
17
+ const view = d.items.view;
18
+ if (view === void 0 || d.summary === void 0) return null;
19
+ const count = listCount(view, d.summary);
20
+ const total = count === void 0 ? void 0 : countText(count, format);
21
+ const sort = sortText(view, messages);
22
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
23
+ /* @__PURE__ */ jsxs("p", {
24
+ className: "dd-records-count",
25
+ "aria-live": "polite",
26
+ children: [
27
+ messages.drillShowing(d.items.items.length, total),
28
+ " · ",
29
+ sort
30
+ ]
31
+ }),
32
+ d.items.moreError === void 0 ? null : /* @__PURE__ */ jsx("p", {
33
+ className: "dd-tile-error",
34
+ role: "alert",
35
+ children: messages.drillFailed
36
+ }),
37
+ d.items.hasMore ? /* @__PURE__ */ jsx(More, { d }) : null
38
+ ] });
39
+ }
40
+ /** How the Items are sorted, in words: the declared order, or by the value. */
41
+ function sortText(view, messages) {
42
+ if (view.sort !== "records" || view.sorted === void 0) return messages.drillSort[view.sort];
43
+ const field = view.columns.find((c) => c.member === view.sorted?.member)?.label ?? "";
44
+ return messages.drillSorted(field, view.sorted.dir, view.sorted.time);
45
+ }
46
+ /** Show more, or Loading while a page comes, or Try again when the last one failed. */
47
+ function More({ d }) {
48
+ const { messages } = useDashboards();
49
+ const label = d.items.loadingMore ? messages.loading : d.items.moreError === void 0 ? messages.showMore : messages.drillRetry;
50
+ return /* @__PURE__ */ jsx("button", {
51
+ type: "button",
52
+ className: "dd-records-more",
53
+ "aria-disabled": d.items.loadingMore,
54
+ onClick: () => {
55
+ if (!d.items.loadingMore) d.items.more();
56
+ },
57
+ children: label
58
+ });
59
+ }
60
+ export { ItemsFoot };
@@ -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;