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,79 @@
1
+ import { DRILL_REASONS } from "derive-dashboards/core";
2
+ // src/drill/words.ts
3
+ const capital = (text) => text.charAt(0).toUpperCase() + text.slice(1);
4
+ const ENGLISH_DRILL = {
5
+ drillTitle: "Analysis",
6
+ drillViews: {
7
+ breakdown: "Breakdown",
8
+ trend: "Over time",
9
+ items: "Items",
10
+ explanation: "Explanation"
11
+ },
12
+ drillBack: "Back",
13
+ drillRoot: (title) => title,
14
+ drillRows: (count) => `${count} rows`,
15
+ drillWith: (rows, operand, without) => `${rows} with ${operand}${without === void 0 ? "" : ` (${without} without)`}`,
16
+ drillShare: (percent, of) => `${percent} of ${of ?? "the total"}`,
17
+ drillMoved: (now, then) => `${now} now, ${then} when the chart loaded`,
18
+ drillRefresh: "Refresh",
19
+ drillYours: (noun) => `Counts include only ${noun} you can see.`,
20
+ drillOmitted: "Part of this link was left out.",
21
+ drillEarlier: (range) => `The period before · ${range}`,
22
+ drillHint: "Click to see what is behind it",
23
+ drillBy: "Break down by",
24
+ drillShowing: (shown, total) => total === void 0 ? `Showing ${String(shown)}` : `Showing ${String(shown)} of ${total}`,
25
+ drillSort: {
26
+ records: "in record order",
27
+ value: "highest first",
28
+ count: "most rows first"
29
+ },
30
+ drillSorted: (field, dir, time) => time ? dir === "desc" ? "newest first" : "oldest first" : `by ${field}`,
31
+ drillList: "List",
32
+ drillTable: "Table",
33
+ drillNoItems: "No items match.",
34
+ drillNoGroups: "Nothing to show here.",
35
+ drillNoMatch: "No values match the search.",
36
+ drillFailed: "Couldn't load.",
37
+ drillRetry: "Try again",
38
+ drillStale: "This view is out of date.",
39
+ drillStaleClose: "Close it",
40
+ drillMark: (label) => `${label}. Open what is behind it.`,
41
+ drillUntitled: (n, noun) => `${noun === void 0 ? "Row" : capital(noun)} ${String(n)}`,
42
+ drillOperands: "Made of",
43
+ drillScope: {
44
+ row: "here",
45
+ total: "of the whole chart",
46
+ bucket: "of this time point",
47
+ previous: "in the period before"
48
+ },
49
+ drillNoun: (n) => n === 1 ? "row" : "rows",
50
+ drillChange: (now, before, change) => `${now}, was ${before}, ${change}`,
51
+ drillVersus: (before, change) => `vs ${before}, ${change}`,
52
+ drillSearch: "Search",
53
+ drillOnly: (numerator, count) => `Only ${numerator} (${count})`,
54
+ drillBefore: (value) => `Before: ${value}`,
55
+ beforeChange: (change, before) => `${change} from ${before}`,
56
+ beforeSame: (before) => `No change from ${before}`,
57
+ drillPeriodBefore: "The period before",
58
+ drillItem: "Item",
59
+ drillCut: "Only the first rows of this answer open; narrow the filters to open the rest.",
60
+ drillNone: (field) => `No ${field.toLowerCase()}`,
61
+ drillOtherOf: (field) => `Other ${field.toLowerCase()}`,
62
+ drillWeekOf: (date) => `Week of ${date}`,
63
+ drillYes: "Yes",
64
+ drillNo: "No",
65
+ drillPercentile: (p, value) => `${String(p)}% are at or below ${value}`,
66
+ drillRange: (from, to) => `${from} to ${to}`,
67
+ drillGrains: {
68
+ hour: "Hour",
69
+ day: "Day",
70
+ week: "Week",
71
+ month: "Month",
72
+ quarter: "Quarter",
73
+ year: "Year"
74
+ },
75
+ drillReasons: { ...DRILL_REASONS },
76
+ drillOpenInBuilder: "Open in builder",
77
+ drillSee: (count) => `See ${count}`
78
+ };
79
+ export { ENGLISH_DRILL };
@@ -1,8 +1,13 @@
1
+ import { ENGLISH_BUILDER } from "./builder/words.mjs";
2
+ import { ENGLISH_DRILL } from "./drill/words.mjs";
3
+ import { relativeLabel } from "./filters/days.mjs";
1
4
  import { ENGLISH_REVIEW } from "./review-words.mjs";
2
5
  // src/english.ts
3
6
  /** Every word the built-in components show, in English: the default `messages`. */
4
7
  const ENGLISH = {
5
8
  ...ENGLISH_REVIEW,
9
+ ...ENGLISH_DRILL,
10
+ ...ENGLISH_BUILDER,
6
11
  other: "Other",
7
12
  total: "Total",
8
13
  empty: "None",
@@ -11,21 +16,20 @@ const ENGLISH = {
11
16
  noAccess: "You don't have access to this data",
12
17
  noData: "No data for this range",
13
18
  noRows: "No rows",
19
+ soFar: "so far",
14
20
  dashboardFailed: "This dashboard could not be loaded.",
21
+ dashboardUnreachable: "Can't reach the server. Showing what was last loaded; it updates when the connection is back.",
15
22
  dashboardMissing: "This dashboard isn't here. It may not be published yet, or it was removed.",
16
23
  rowsFailed: "These rows could not be loaded.",
17
24
  rows: "Rows",
18
25
  close: "Close",
19
26
  showMore: "Show more",
27
+ rowsShowing: (n, more) => `Showing ${String(n)} ${n === 1 ? "row" : "rows"}${more ? ", more to load" : ""}`,
20
28
  reset: "Reset",
21
29
  rowsBehind: (title) => `Rows behind ${title}`,
22
30
  notFilteredBy: (controls) => `Not filtered by ${controls.join(", ")}`,
23
31
  firstRows: (count) => `Showing the first ${count} rows`,
24
- range: ({ last, unit, includeCurrent }) => {
25
- if (last === 1 && includeCurrent) return `This ${unit}`;
26
- const plural = last === 1 ? unit : `${unit}s`;
27
- return `Last ${last} ${includeCurrent ? "" : "complete "}${plural}`;
28
- },
32
+ range: relativeLabel,
29
33
  untitledWidget: "Untitled widget",
30
34
  save: "Save",
31
35
  cancel: "Cancel",
@@ -54,7 +58,8 @@ const ENGLISH = {
54
58
  number: "Number",
55
59
  line: "Line",
56
60
  bar: "Bar",
57
- table: "Table"
61
+ table: "Table",
62
+ list: "List"
58
63
  },
59
64
  topValues: (n) => `top ${n}`,
60
65
  keepTop: "Keep the top",
@@ -98,6 +103,17 @@ const ENGLISH = {
98
103
  previous: "previous period"
99
104
  },
100
105
  removedCalcs: (names) => `Removed ${names.join(", ")}: a change compares the whole range with the one before, so it needs no breakdown and a comparison.`,
106
+ noMainQuery: (title) => `${title} has no main query, so the builder cannot edit it. Change it where it was made (in code, or by its plugin).`,
107
+ notDrawn: (labels) => `Not drawn here: ${labels.join(", ")}. Show it as a table to see ${labels.length === 1 ? "it" : "them"}.`,
108
+ chartTable: ({ title, kind, points }) => `${title}, a ${kind} chart of ${String(points)} ${points === 1 ? "point" : "points"}`,
109
+ chartPoints: "Points to open (arrow keys move between them)",
110
+ keptAside: ({ display, queries, fields }) => {
111
+ return `Kept as they are: ${[
112
+ ...display ? ["its display settings"] : [],
113
+ ...fields.length === 0 ? [] : [`its own ${fields.join(", ")}`],
114
+ ...queries.length === 0 ? [] : [`its ${queries.map((q) => `"${q}"`).join(", ")} ${queries.length === 1 ? "query" : "queries"}`]
115
+ ].join(" and ")}. This builder edits the title, the chart and the main query.`;
116
+ },
101
117
  followsFilters: (labels) => labels.length === 0 ? "On the dashboard: no dashboard filter applies to it." : `On the dashboard: follows its ${labels.join(", ")} ${labels.length === 1 ? "filter" : "filters"}.`,
102
118
  reorder: "Drag, or use the arrow keys, to reorder",
103
119
  edit: "Edit",
@@ -105,6 +121,7 @@ const ENGLISH = {
105
121
  editing: "Editing. Only you see these changes until you publish.",
106
122
  publish: "Publish",
107
123
  discard: "Discard",
124
+ doneEditing: "Done",
108
125
  addWidget: "+ Add widget",
109
126
  addToDashboard: "Add to dashboard",
110
127
  editWidget: (title) => `Edit ${title}`,
@@ -123,7 +140,11 @@ const ENGLISH = {
123
140
  deleteNewConfirm: "Delete dashboard",
124
141
  keepEditing: "Keep editing",
125
142
  unreachable: "Can't reach the server. Your draft is safe as last saved; try again.",
143
+ removedTile: (title) => `Removed “${title}”. Undo brings it back.`,
126
144
  tileUnreachable: "Couldn't load this tile. Check the connection and reload.",
145
+ readFailed: "Could not load this list.",
146
+ noValues: "No values to pick.",
147
+ copyByHand: "The browser would not copy it. Select the text below and copy it.",
127
148
  changesDiscarded: "Changes discarded",
128
149
  draftChanged: "Your draft changed in another tab. It has been reloaded; make that change again.",
129
150
  draftClosed: "This draft was closed. Start editing again.",
@@ -132,6 +153,8 @@ const ENGLISH = {
132
153
  newDashboard: "+ New dashboard",
133
154
  untitledDashboard: "Untitled dashboard",
134
155
  unpublished: "Draft",
156
+ builtIn: "Built in",
157
+ madeHere: "Made here",
135
158
  dashboardTitle: "Dashboard title",
136
159
  history: "History",
137
160
  noHistory: "Nothing published yet. Publishing makes the first version.",
@@ -0,0 +1,12 @@
1
+ import { FilterBarOptions } from "./context.mjs";
2
+ import { FilterBarProps } from "./hooks.mjs";
3
+ /**
4
+ * The dashboard's filter bar, built in: one chip per filter, F to add one with typed suggestions,
5
+ * Shift+F to remove the last, Undo, Reset. Unset filters past the first `pinned` wait in the
6
+ * Filter menu, so a dashboard with many filters keeps one calm row; on a phone everything moves
7
+ * into a sheet. It reads field types, tones, buckets and units from the model.
8
+ *
9
+ * Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
10
+ * CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
11
+ */
12
+ export declare function FilterBar({ controls, picks, onChange, timezone, ...options }: FilterBarProps & FilterBarOptions): import("react").JSX.Element | null;
@@ -0,0 +1,135 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { Chip } from "./chip.mjs";
3
+ import { BarContext, useBar, useWords } from "./context.mjs";
4
+ import { useFilterFields } from "./hooks.mjs";
5
+ import { FilterMenu } from "./menu.mjs";
6
+ import { PhoneBar } from "./phone.mjs";
7
+ import { useBarPicks, useFromLink, useNarrow, useShortcuts, useShown } from "./state.mjs";
8
+ import { useState } from "react";
9
+ import { createPortal } from "react-dom";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ // src/filters/bar.tsx
12
+ const PINNED = 4;
13
+ /** "Your view · Reset", or "From a link · Reset" while the picks are still the link's. */
14
+ function Status({ linked, onReset }) {
15
+ const words = useWords();
16
+ const { messages } = useDashboards();
17
+ const { picks } = useBar();
18
+ if (Object.keys(picks).length === 0) return null;
19
+ return /* @__PURE__ */ jsxs("div", {
20
+ className: "dd-fb-status",
21
+ children: [/* @__PURE__ */ jsx("span", {
22
+ className: "dd-fb-quiet",
23
+ children: linked ? words.fromLink : words.yourView
24
+ }), /* @__PURE__ */ jsx("button", {
25
+ type: "button",
26
+ className: "dd-fb-link",
27
+ onClick: onReset,
28
+ children: messages.reset
29
+ })]
30
+ });
31
+ }
32
+ /** "Status filter removed · Undo", for a few seconds after a removal. */
33
+ function UndoToast({ undo, onUndo }) {
34
+ const words = useWords();
35
+ if (undo === null) return null;
36
+ return createPortal(/* @__PURE__ */ jsxs("div", {
37
+ className: "dd-fb dd-fb-toast",
38
+ role: "status",
39
+ "aria-live": "polite",
40
+ children: [undo.cleared ? words.cleared : words.removed(undo.labels), /* @__PURE__ */ jsx("button", {
41
+ type: "button",
42
+ className: "dd-fb-toast-action",
43
+ onClick: () => {
44
+ onUndo(undo);
45
+ },
46
+ children: words.undo
47
+ })]
48
+ }), document.body);
49
+ }
50
+ /** On a wider screen: the date chip, the shown filters' chips, Filter, and the status. */
51
+ function DesktopBar({ controls, pinned, linked, removeLast, onReset }) {
52
+ const words = useWords();
53
+ const { picks } = useBar();
54
+ const [menu, setMenu] = useState(false);
55
+ const [openId, setOpenId] = useState(null);
56
+ const { visible, hidden } = useShown(controls, picks, pinned);
57
+ const openMenu = () => {
58
+ setMenu(true);
59
+ };
60
+ useShortcuts(openMenu, removeLast);
61
+ const date = controls.find((c) => c.kind === "date_range");
62
+ const setOpen = (id) => (o) => {
63
+ setOpenId(o ? id : null);
64
+ };
65
+ const chip = (c) => /* @__PURE__ */ jsx(Chip, {
66
+ control: c,
67
+ open: openId === c.id,
68
+ setOpen: setOpen(c.id)
69
+ }, c.id);
70
+ const last = visible.at(-1);
71
+ return /* @__PURE__ */ jsxs("div", {
72
+ className: "dd-fb dd-fb-bar",
73
+ role: "toolbar",
74
+ "aria-label": words.filters(0),
75
+ children: [
76
+ date === void 0 ? null : chip(date),
77
+ visible.slice(0, -1).map((c) => chip(c)),
78
+ /* @__PURE__ */ jsxs("span", {
79
+ className: "dd-fb-keep",
80
+ children: [last === void 0 ? null : chip(last), /* @__PURE__ */ jsx(FilterMenu, {
81
+ controls,
82
+ open: menu,
83
+ setOpen: setMenu,
84
+ openChip: setOpenId,
85
+ hidden
86
+ })]
87
+ }),
88
+ /* @__PURE__ */ jsx(Status, {
89
+ linked,
90
+ onReset
91
+ })
92
+ ]
93
+ });
94
+ }
95
+ /**
96
+ * The dashboard's filter bar, built in: one chip per filter, F to add one with typed suggestions,
97
+ * Shift+F to remove the last, Undo, Reset. Unset filters past the first `pinned` wait in the
98
+ * Filter menu, so a dashboard with many filters keeps one calm row; on a phone everything moves
99
+ * into a sheet. It reads field types, tones, buckets and units from the model.
100
+ *
101
+ * Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
102
+ * CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
103
+ */
104
+ function FilterBar({ controls, picks, onChange, timezone, ...options }) {
105
+ const fields = useFilterFields(controls);
106
+ const narrow = useNarrow();
107
+ const { setPick, removeLast, reset, undo, takeBack } = useBarPicks(controls, picks, onChange);
108
+ const linked = useFromLink(picks);
109
+ if (controls.length === 0) return null;
110
+ const bar = {
111
+ fields,
112
+ options,
113
+ timezone,
114
+ picks,
115
+ setPick
116
+ };
117
+ return /* @__PURE__ */ jsxs(BarContext.Provider, {
118
+ value: bar,
119
+ children: [narrow ? /* @__PURE__ */ jsx(PhoneBar, {
120
+ controls,
121
+ removeLast,
122
+ onReset: reset
123
+ }) : /* @__PURE__ */ jsx(DesktopBar, {
124
+ controls,
125
+ pinned: options.pinned ?? PINNED,
126
+ linked,
127
+ removeLast,
128
+ onReset: reset
129
+ }), /* @__PURE__ */ jsx(UndoToast, {
130
+ undo,
131
+ onUndo: takeBack
132
+ })]
133
+ });
134
+ }
135
+ export { FilterBar };
@@ -0,0 +1,193 @@
1
+ import { useBar, useLocale, useWords } from "./context.mjs";
2
+ import { addDays, dateFormat, isoDay, monthEnd, monthStart, sameDay, todayIn, weekday } from "./days.mjs";
3
+ import { useState } from "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/filters/calendar.tsx
6
+ /** A month's days in weeks from Monday, with empty cells before the first. */
7
+ function weeksOf(month) {
8
+ const first = monthStart(month);
9
+ const cells = [...Array.from({ length: weekday(first) }, () => null), ...Array.from({ length: monthEnd(month).getDate() }, (_, i) => addDays(first, i))];
10
+ return Array.from({ length: Math.ceil(cells.length / 7) }, (_, w) => cells.slice(w * 7, w * 7 + 7));
11
+ }
12
+ const STEPS = {
13
+ ArrowLeft: -1,
14
+ ArrowRight: 1,
15
+ ArrowUp: -7,
16
+ ArrowDown: 7
17
+ };
18
+ /** Where a key moves focus from a day: arrows by a day or a week, Home and End to the week's ends. */
19
+ function moved(key, d) {
20
+ const by = STEPS[key];
21
+ if (by !== void 0) return addDays(d, by);
22
+ if (key === "Home") return addDays(d, -weekday(d));
23
+ return key === "End" ? addDays(d, 6 - weekday(d)) : void 0;
24
+ }
25
+ /** How a day looks: an edge of the range, between them, today. */
26
+ function inRange(d, from, to) {
27
+ return {
28
+ edge: from !== void 0 && sameDay(d, from) || to !== void 0 && sameDay(d, to),
29
+ between: from !== void 0 && to !== void 0 && d > from && d < to
30
+ };
31
+ }
32
+ function dayMarks(d, days) {
33
+ const { edge, between } = inRange(d, days.from, days.to);
34
+ return {
35
+ edge,
36
+ cell: { "data-in-range": edge || between || void 0 },
37
+ day: {
38
+ "data-edge": edge || void 0,
39
+ "data-between": between || void 0,
40
+ "data-today": sameDay(d, days.today) || void 0
41
+ }
42
+ };
43
+ }
44
+ function Day({ d, days }) {
45
+ const marks = dayMarks(d, days);
46
+ const focused = sameDay(d, days.focus);
47
+ const onKey = (e) => {
48
+ const next = moved(e.key, d);
49
+ if (next === void 0) return;
50
+ e.preventDefault();
51
+ days.onFocus(next);
52
+ };
53
+ return /* @__PURE__ */ jsx("td", {
54
+ ...marks.cell,
55
+ children: /* @__PURE__ */ jsx("button", {
56
+ type: "button",
57
+ className: "dd-fb-day",
58
+ ...marks.day,
59
+ "aria-pressed": marks.edge,
60
+ tabIndex: focused ? 0 : -1,
61
+ "aria-label": dateFormat(days.locale, { dateStyle: "full" }).format(d),
62
+ ref: (el) => {
63
+ if (focused && el?.ownerDocument.activeElement?.closest(".dd-fb-cal")) el.focus();
64
+ },
65
+ onKeyDown: onKey,
66
+ onClick: () => {
67
+ days.onPick(d);
68
+ },
69
+ children: d.getDate()
70
+ })
71
+ });
72
+ }
73
+ /** One month of days, Monday first. */
74
+ function Month({ month, days }) {
75
+ const title = dateFormat(days.locale, {
76
+ month: "long",
77
+ year: "numeric"
78
+ }).format(month);
79
+ const dayName = dateFormat(days.locale, { weekday: "narrow" });
80
+ const monday = addDays(monthStart(month), -weekday(monthStart(month)));
81
+ return /* @__PURE__ */ jsxs("div", {
82
+ className: "dd-fb-month",
83
+ children: [/* @__PURE__ */ jsx("div", {
84
+ className: "dd-fb-month-title",
85
+ children: title
86
+ }), /* @__PURE__ */ jsxs("table", {
87
+ "aria-label": title,
88
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: Array.from({ length: 7 }, (_, i) => {
89
+ const name = dayName.format(addDays(monday, i));
90
+ return /* @__PURE__ */ jsx("th", {
91
+ scope: "col",
92
+ abbr: name,
93
+ children: name
94
+ }, String(i));
95
+ }) }) }), /* @__PURE__ */ jsx("tbody", { children: weeksOf(month).map((week, w) => /* @__PURE__ */ jsx("tr", { children: week.map((d, i) => d === null ? /* @__PURE__ */ jsx("td", {}, String(i)) : /* @__PURE__ */ jsx(Day, {
96
+ d,
97
+ days
98
+ }, isoDay(d))) }, String(w))) })]
99
+ })]
100
+ });
101
+ }
102
+ /** The calendar's state: the range so far (first click, then second), the month shown, focus. */
103
+ /** The same day of the month in another month, the last day when it has fewer. */
104
+ const sameDayIn = (d, month) => new Date(month.getFullYear(), month.getMonth(), Math.min(d.getDate(), monthEnd(month).getDate()), 12);
105
+ function useRange(initial, narrow) {
106
+ const today = todayIn(useBar().timezone);
107
+ const [range, setRange] = useState(initial ?? {});
108
+ const [month, setMonth] = useState(() => monthStart(initial?.from ?? today, initial === void 0 && !narrow ? -1 : 0));
109
+ const [focus, setFocus] = useState(initial?.from ?? today);
110
+ const shown = narrow ? [month] : [month, monthStart(month, 1)];
111
+ const onFocus = (d) => {
112
+ setFocus(d);
113
+ if (d < month) setMonth(monthStart(month, -1));
114
+ else if (d > monthEnd(shown.at(-1) ?? month)) setMonth(monthStart(month, 1));
115
+ };
116
+ const pickDay = (d) => {
117
+ setFocus(d);
118
+ const { from, to } = range;
119
+ const next = from === void 0 || to !== void 0 ? { from: d } : d < from ? {
120
+ from: d,
121
+ to: from
122
+ } : {
123
+ from,
124
+ to: d
125
+ };
126
+ setRange(next);
127
+ return next;
128
+ };
129
+ const turn = (by) => {
130
+ setMonth(monthStart(month, by));
131
+ setFocus(sameDayIn(focus, monthStart(focus, by)));
132
+ };
133
+ return {
134
+ today,
135
+ range,
136
+ month,
137
+ turn,
138
+ focus,
139
+ shown,
140
+ onFocus,
141
+ pickDay
142
+ };
143
+ }
144
+ function MonthNav({ onTurn }) {
145
+ const words = useWords();
146
+ return /* @__PURE__ */ jsxs("div", {
147
+ className: "dd-fb-cal-nav",
148
+ children: [/* @__PURE__ */ jsx("button", {
149
+ type: "button",
150
+ className: "dd-fb-icon-button",
151
+ "aria-label": words.previousMonth,
152
+ onClick: () => {
153
+ onTurn(-1);
154
+ },
155
+ children: "‹"
156
+ }), /* @__PURE__ */ jsx("button", {
157
+ type: "button",
158
+ className: "dd-fb-icon-button",
159
+ "aria-label": words.nextMonth,
160
+ onClick: () => {
161
+ onTurn(1);
162
+ },
163
+ children: "›"
164
+ })]
165
+ });
166
+ }
167
+ /** A two-month calendar (one on a phone) for a range of whole days. */
168
+ function Calendar({ initial, narrow, onChange }) {
169
+ const locale = useLocale();
170
+ const cal = useRange(initial, narrow);
171
+ const days = {
172
+ from: cal.range.from,
173
+ to: cal.range.to,
174
+ focus: cal.focus,
175
+ today: cal.today,
176
+ locale,
177
+ onFocus: cal.onFocus,
178
+ onPick: (d) => {
179
+ onChange(cal.pickDay(d));
180
+ }
181
+ };
182
+ return /* @__PURE__ */ jsxs("div", {
183
+ className: "dd-fb-cal",
184
+ children: [/* @__PURE__ */ jsx(MonthNav, { onTurn: cal.turn }), /* @__PURE__ */ jsx("div", {
185
+ className: "dd-fb-months",
186
+ children: cal.shown.map((m) => /* @__PURE__ */ jsx(Month, {
187
+ month: m,
188
+ days
189
+ }, isoDay(m)))
190
+ })]
191
+ });
192
+ }
193
+ export { Calendar };
@@ -0,0 +1,174 @@
1
+ import { rangeOf, useBar, useSummary, useWords, valuePickOf } from "./context.mjs";
2
+ import { DatePicker } from "./dates.mjs";
3
+ import { chosenOf, flipped, isNumber, toggled } from "./logic.mjs";
4
+ import { NumberPicker } from "./number.mjs";
5
+ import { OperatorMenu } from "./operator.mjs";
6
+ import { Popover } from "./popover.mjs";
7
+ import { ValueList, ValuesSummary } from "./values.mjs";
8
+ import { useRef } from "react";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ // src/filters/chip.tsx
11
+ /** A control's icon from the host, if any. */
12
+ function Icon({ control }) {
13
+ const Own = useBar().options.icons?.[control.id];
14
+ return Own === void 0 ? null : /* @__PURE__ */ jsx(Own, {
15
+ className: "dd-fb-icon",
16
+ "aria-hidden": true
17
+ });
18
+ }
19
+ /** The picker for one control: values, a number range, or dates. Picking a range closes it. */
20
+ function Picker({ control, narrow, close }) {
21
+ const { fields, picks, setPick } = useBar();
22
+ const done = (pick) => {
23
+ setPick(control.id, pick);
24
+ close();
25
+ };
26
+ if (control.kind === "date_range") return /* @__PURE__ */ jsx(DatePicker, {
27
+ control,
28
+ pick: rangeOf(picks, control.id),
29
+ narrow,
30
+ onPick: done
31
+ });
32
+ if (control.kind !== "filter") return null;
33
+ const pick = valuePickOf(picks, control.id);
34
+ if (isNumber(control, fields)) return /* @__PURE__ */ jsx(NumberPicker, {
35
+ control,
36
+ pick,
37
+ onPick: done
38
+ });
39
+ return /* @__PURE__ */ jsx(ValueList, {
40
+ control,
41
+ pick,
42
+ onToggle: (v) => {
43
+ setPick(control.id, toggled(control, pick, v));
44
+ if (!control.multi) close();
45
+ },
46
+ onClear: () => {
47
+ setPick(control.id, void 0);
48
+ }
49
+ });
50
+ }
51
+ /** What a chip's value segment shows: the chosen values with their marks, or the pick in words. */
52
+ function ChipValue({ control, said }) {
53
+ const { fields, picks } = useBar();
54
+ const words = useWords();
55
+ const pick = valuePickOf(picks, control.id);
56
+ if (control.kind === "filter" && pick !== void 0 && !isNumber(control, fields)) return /* @__PURE__ */ jsx(ValuesSummary, {
57
+ control,
58
+ values: chosenOf(pick)
59
+ });
60
+ return /* @__PURE__ */ jsx(Fragment, { children: said ?? words.widgetDates });
61
+ }
62
+ function FieldSegment({ control, open, toggle }) {
63
+ const words = useWords();
64
+ return /* @__PURE__ */ jsxs("button", {
65
+ type: "button",
66
+ className: "dd-fb-seg dd-fb-field",
67
+ "aria-haspopup": "dialog",
68
+ "aria-expanded": open,
69
+ "aria-label": words.field(control.label),
70
+ onClick: toggle,
71
+ children: [/* @__PURE__ */ jsx(Icon, { control }), control.label]
72
+ });
73
+ }
74
+ function RemoveSegment({ control }) {
75
+ const words = useWords();
76
+ const { setPick } = useBar();
77
+ return /* @__PURE__ */ jsx("button", {
78
+ type: "button",
79
+ className: "dd-fb-seg dd-fb-remove",
80
+ "aria-label": words.remove(control.label),
81
+ onClick: () => {
82
+ setPick(control.id, void 0);
83
+ },
84
+ children: /* @__PURE__ */ jsx("span", {
85
+ "aria-hidden": true,
86
+ children: "×"
87
+ })
88
+ });
89
+ }
90
+ /** A set filter (or the date control, set or not): field, operator, values, remove. */
91
+ function SetChip({ control, said, open, toggle }) {
92
+ const words = useWords();
93
+ const { fields, picks, setPick } = useBar();
94
+ const pick = valuePickOf(picks, control.id);
95
+ const operator = control.kind === "filter" && pick !== void 0 && !isNumber(control, fields);
96
+ const now = said ?? words.widgetDates;
97
+ return /* @__PURE__ */ jsxs("fieldset", {
98
+ className: "dd-fb-chip",
99
+ "aria-label": `${control.label} ${now}`,
100
+ children: [
101
+ /* @__PURE__ */ jsx(FieldSegment, {
102
+ control,
103
+ open,
104
+ toggle
105
+ }),
106
+ operator ? /* @__PURE__ */ jsx(OperatorMenu, {
107
+ control,
108
+ pick,
109
+ onChange: (neg) => {
110
+ setPick(control.id, flipped(control, pick, neg));
111
+ }
112
+ }) : null,
113
+ /* @__PURE__ */ jsx("button", {
114
+ type: "button",
115
+ className: "dd-fb-seg dd-fb-value",
116
+ "data-unset": said === void 0 || void 0,
117
+ "aria-haspopup": "dialog",
118
+ "aria-expanded": open,
119
+ "aria-label": words.changeValues(control.label, now),
120
+ onClick: toggle,
121
+ children: /* @__PURE__ */ jsx(ChipValue, {
122
+ control,
123
+ said
124
+ })
125
+ }),
126
+ said === void 0 ? null : /* @__PURE__ */ jsx(RemoveSegment, { control })
127
+ ]
128
+ });
129
+ }
130
+ /**
131
+ * A control on the bar: a quiet button while nothing is set, a chip once it is. Both share one
132
+ * anchor and one panel, so the picker keeps its search, order and place when the first value
133
+ * turns one into the other.
134
+ */
135
+ function Chip({ control, open, setOpen }) {
136
+ const words = useWords();
137
+ const said = useSummary()(control);
138
+ const anchor = useRef(null);
139
+ const toggle = () => {
140
+ setOpen(!open);
141
+ };
142
+ const close = () => {
143
+ setOpen(false);
144
+ };
145
+ return /* @__PURE__ */ jsxs("div", {
146
+ ref: anchor,
147
+ className: "dd-fb-slot",
148
+ children: [said === void 0 && control.kind !== "date_range" ? /* @__PURE__ */ jsxs("button", {
149
+ type: "button",
150
+ className: "dd-fb-unset",
151
+ "aria-haspopup": "dialog",
152
+ "aria-expanded": open,
153
+ "aria-label": words.filterBy(control.label),
154
+ onClick: toggle,
155
+ children: [/* @__PURE__ */ jsx(Icon, { control }), control.label]
156
+ }) : /* @__PURE__ */ jsx(SetChip, {
157
+ control,
158
+ said,
159
+ open,
160
+ toggle
161
+ }), /* @__PURE__ */ jsx(Popover, {
162
+ anchor,
163
+ open,
164
+ onClose: close,
165
+ label: control.label,
166
+ children: /* @__PURE__ */ jsx(Picker, {
167
+ control,
168
+ narrow: false,
169
+ close
170
+ })
171
+ })]
172
+ });
173
+ }
174
+ export { Chip, Icon, Picker };