@kerf-js/veneer 0.0.0-stage → 0.1.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 (389) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +1338 -2
  3. package/package.json +56 -3
  4. package/plugin.d.mts +187 -0
  5. package/plugin.mjs +399 -0
  6. package/src/Accordion.tsx +98 -0
  7. package/src/Alert.tsx +55 -0
  8. package/src/Badge.tsx +39 -0
  9. package/src/Button.tsx +175 -0
  10. package/src/Calendar-month.tsx +140 -0
  11. package/src/Calendar.tsx +335 -0
  12. package/src/Canvas.tsx +221 -0
  13. package/src/Card.tsx +85 -0
  14. package/src/Chart.tsx +278 -0
  15. package/src/Charts.tsx +158 -0
  16. package/src/Chip.tsx +61 -0
  17. package/src/Choice-checkbox.tsx +53 -0
  18. package/src/Choice-parts.tsx +7 -0
  19. package/src/Choice-radio.tsx +78 -0
  20. package/src/Choice-segmented.tsx +76 -0
  21. package/src/Choice-switch.tsx +51 -0
  22. package/src/Choice.tsx +4 -0
  23. package/src/CloseX.tsx +14 -0
  24. package/src/CodeBlock.tsx +81 -0
  25. package/src/CodeInput.tsx +256 -0
  26. package/src/Combobox.tsx +281 -0
  27. package/src/CommandPalette-controller.ts +314 -0
  28. package/src/CommandPalette-rows.tsx +137 -0
  29. package/src/CommandPalette.tsx +196 -0
  30. package/src/DataGrid-actions.ts +119 -0
  31. package/src/DataGrid-body.tsx +58 -0
  32. package/src/DataGrid-controller.ts +145 -0
  33. package/src/DataGrid-header.tsx +108 -0
  34. package/src/DataGrid-model.ts +248 -0
  35. package/src/DataGrid-pivot.tsx +108 -0
  36. package/src/DataGrid-rows.tsx +296 -0
  37. package/src/DataGrid-toolbar.tsx +127 -0
  38. package/src/DataGrid-tree.ts +149 -0
  39. package/src/DataGrid-viewport.tsx +37 -0
  40. package/src/DataGrid.tsx +145 -0
  41. package/src/DateField-presets.tsx +27 -0
  42. package/src/DateField-range.tsx +370 -0
  43. package/src/DateField.tsx +295 -0
  44. package/src/Dither.tsx +313 -0
  45. package/src/Drawer.tsx +123 -0
  46. package/src/DurationField.tsx +227 -0
  47. package/src/Feed.tsx +78 -0
  48. package/src/Field/view.tsx +147 -0
  49. package/src/Field.tsx +238 -0
  50. package/src/HamburgerMenu.tsx +119 -0
  51. package/src/Icon.tsx +15 -0
  52. package/src/Kbd.tsx +6 -0
  53. package/src/KeyValueEditor/actions.ts +75 -0
  54. package/src/KeyValueEditor/rows.tsx +104 -0
  55. package/src/KeyValueEditor.tsx +112 -0
  56. package/src/Layout.tsx +221 -0
  57. package/src/Markdown.tsx +127 -0
  58. package/src/MentionsInput/actions.ts +161 -0
  59. package/src/MentionsInput/end.tsx +82 -0
  60. package/src/MentionsInput.tsx +103 -0
  61. package/src/Menu.tsx +221 -0
  62. package/src/Modal.tsx +109 -0
  63. package/src/MonthPicker/month.tsx +117 -0
  64. package/src/MonthPicker/period.tsx +197 -0
  65. package/src/MonthPicker/shared.tsx +272 -0
  66. package/src/MonthPicker/week.tsx +103 -0
  67. package/src/MonthPicker.tsx +11 -0
  68. package/src/MultiSelect.tsx +139 -0
  69. package/src/Nav.tsx +36 -0
  70. package/src/NumberField.tsx +156 -0
  71. package/src/Pagination.tsx +335 -0
  72. package/src/PaymentCard.tsx +111 -0
  73. package/src/Picker.tsx +228 -0
  74. package/src/PlaceField.tsx +285 -0
  75. package/src/Popover.tsx +88 -0
  76. package/src/Presence.tsx +37 -0
  77. package/src/Progress.tsx +71 -0
  78. package/src/RecurrenceField.tsx +372 -0
  79. package/src/RichSelect/codes.tsx +94 -0
  80. package/src/RichSelect/list.tsx +380 -0
  81. package/src/RichSelect/phone-view.tsx +114 -0
  82. package/src/RichSelect/phone.tsx +305 -0
  83. package/src/RichSelect/search-keys.ts +28 -0
  84. package/src/RichSelect/timezone.tsx +53 -0
  85. package/src/RichSelect.tsx +13 -0
  86. package/src/RichTextEditor/controller.tsx +305 -0
  87. package/src/RichTextEditor/editor.tsx +61 -0
  88. package/src/RichTextEditor/tools.tsx +132 -0
  89. package/src/RichTextEditor/view.tsx +210 -0
  90. package/src/RichTextEditor.tsx +9 -0
  91. package/src/ScrollGrid/measure.ts +39 -0
  92. package/src/ScrollGrid/parts.tsx +112 -0
  93. package/src/ScrollGrid.tsx +375 -0
  94. package/src/ScrollRail.tsx +114 -0
  95. package/src/ScrollView.tsx +57 -0
  96. package/src/Segments/controller.tsx +148 -0
  97. package/src/Segments/events.ts +99 -0
  98. package/src/Segments/view.tsx +77 -0
  99. package/src/Segments.tsx +2 -0
  100. package/src/Select.tsx +343 -0
  101. package/src/Shape.tsx +41 -0
  102. package/src/Shell/branches.tsx +108 -0
  103. package/src/Shell/button.tsx +33 -0
  104. package/src/Shell/shared.tsx +220 -0
  105. package/src/Shell/shell.tsx +25 -0
  106. package/src/Shell/state.ts +138 -0
  107. package/src/Shell/view.tsx +280 -0
  108. package/src/Shell.tsx +17 -0
  109. package/src/SideNav/sections.tsx +50 -0
  110. package/src/SideNav/state.ts +140 -0
  111. package/src/SideNav.tsx +130 -0
  112. package/src/SideNavTitle.tsx +25 -0
  113. package/src/SignaturePad/state.ts +172 -0
  114. package/src/SignaturePad/view.tsx +69 -0
  115. package/src/SignaturePad.tsx +76 -0
  116. package/src/Skeleton.tsx +46 -0
  117. package/src/Slider.tsx +81 -0
  118. package/src/Spinner.tsx +21 -0
  119. package/src/Stage-director.ts +361 -0
  120. package/src/Stage-look.ts +75 -0
  121. package/src/Stage-poster.tsx +62 -0
  122. package/src/Stage-types.ts +206 -0
  123. package/src/Stage.tsx +147 -0
  124. package/src/TabBar.tsx +114 -0
  125. package/src/Table-actions.tsx +51 -0
  126. package/src/Table-base.ts +70 -0
  127. package/src/Table-body.tsx +84 -0
  128. package/src/Table-columns.tsx +58 -0
  129. package/src/Table-details.tsx +66 -0
  130. package/src/Table-editor.tsx +66 -0
  131. package/src/Table-head.tsx +52 -0
  132. package/src/Table-model.ts +82 -0
  133. package/src/Table-notice.ts +39 -0
  134. package/src/Table-paging.ts +50 -0
  135. package/src/Table-rows.tsx +308 -0
  136. package/src/Table-selection.ts +63 -0
  137. package/src/Table-sortbar.tsx +41 -0
  138. package/src/Table-source.ts +66 -0
  139. package/src/Table-toolbar.tsx +71 -0
  140. package/src/Table-types.ts +115 -0
  141. package/src/Table-view.tsx +87 -0
  142. package/src/Table.tsx +31 -0
  143. package/src/Tabs.tsx +129 -0
  144. package/src/Tag.tsx +40 -0
  145. package/src/Ticker.tsx +42 -0
  146. package/src/TimeField-date-model.ts +77 -0
  147. package/src/TimeField-date-view.tsx +152 -0
  148. package/src/TimeField-model.ts +80 -0
  149. package/src/TimeField-options.tsx +224 -0
  150. package/src/TimeField-slots.tsx +32 -0
  151. package/src/TimeField-types.ts +33 -0
  152. package/src/TimeField-view.tsx +124 -0
  153. package/src/TimeField.tsx +126 -0
  154. package/src/Toast.tsx +143 -0
  155. package/src/Toggle.tsx +75 -0
  156. package/src/Tooltip.tsx +69 -0
  157. package/src/Type.tsx +136 -0
  158. package/src/VirtualList-controls.ts +105 -0
  159. package/src/VirtualList-data.ts +43 -0
  160. package/src/VirtualList-measure.ts +169 -0
  161. package/src/VirtualList-metrics.ts +41 -0
  162. package/src/VirtualList-mount.ts +145 -0
  163. package/src/VirtualList-rows.tsx +91 -0
  164. package/src/VirtualList-types.ts +76 -0
  165. package/src/VirtualList-view.tsx +123 -0
  166. package/src/VirtualList.tsx +81 -0
  167. package/src/admin/ApiKeys-actions.ts +124 -0
  168. package/src/admin/ApiKeys-form.tsx +64 -0
  169. package/src/admin/ApiKeys-view.tsx +101 -0
  170. package/src/admin/ApiKeys.tsx +224 -0
  171. package/src/admin/Audit.tsx +246 -0
  172. package/src/admin/Billing.tsx +307 -0
  173. package/src/admin/Cart.tsx +177 -0
  174. package/src/admin/Checkout-address.tsx +125 -0
  175. package/src/admin/Checkout-cart.tsx +78 -0
  176. package/src/admin/Checkout-coupon.ts +34 -0
  177. package/src/admin/Checkout-done.tsx +31 -0
  178. package/src/admin/Checkout-model.ts +33 -0
  179. package/src/admin/Checkout-navigation.ts +76 -0
  180. package/src/admin/Checkout-payment-view.tsx +49 -0
  181. package/src/admin/Checkout-payment.ts +80 -0
  182. package/src/admin/Checkout-review.tsx +60 -0
  183. package/src/admin/Checkout-shipping.tsx +47 -0
  184. package/src/admin/Checkout-state.ts +122 -0
  185. package/src/admin/Checkout-steps.ts +10 -0
  186. package/src/admin/Checkout-summary.tsx +97 -0
  187. package/src/admin/Checkout-types.ts +60 -0
  188. package/src/admin/Checkout-view.tsx +51 -0
  189. package/src/admin/Checkout.tsx +72 -0
  190. package/src/admin/CsvImport-actions.ts +131 -0
  191. package/src/admin/CsvImport.tsx +379 -0
  192. package/src/admin/Danger.tsx +240 -0
  193. package/src/admin/Integrations/Card.tsx +82 -0
  194. package/src/admin/Integrations/Webhooks.tsx +341 -0
  195. package/src/admin/Integrations.tsx +169 -0
  196. package/src/admin/InviteDialog.tsx +153 -0
  197. package/src/admin/Members/columns.tsx +181 -0
  198. package/src/admin/Members.tsx +316 -0
  199. package/src/admin/Order.tsx +115 -0
  200. package/src/admin/PlainTable.tsx +34 -0
  201. package/src/admin/Plans.tsx +375 -0
  202. package/src/admin/SaveBar/actions.ts +86 -0
  203. package/src/admin/SaveBar.tsx +153 -0
  204. package/src/admin/Secret.tsx +74 -0
  205. package/src/admin/Settings.tsx +145 -0
  206. package/src/admin/StepBar.tsx +66 -0
  207. package/src/admin/TagsInput/actions.ts +60 -0
  208. package/src/admin/TagsInput.tsx +95 -0
  209. package/src/admin/atoms.tsx +73 -0
  210. package/src/admin/index.ts +67 -0
  211. package/src/agent/Actions/reasons.tsx +38 -0
  212. package/src/agent/Actions.tsx +166 -0
  213. package/src/agent/AgentPlan.tsx +86 -0
  214. package/src/agent/ArtifactPanel.tsx +299 -0
  215. package/src/agent/Assistant.tsx +168 -0
  216. package/src/agent/Checkpoint.tsx +19 -0
  217. package/src/agent/Cite.tsx +70 -0
  218. package/src/agent/ContextMeter.tsx +70 -0
  219. package/src/agent/Conversation.tsx +70 -0
  220. package/src/agent/Message.tsx +92 -0
  221. package/src/agent/ModelPicker.tsx +167 -0
  222. package/src/agent/Prompt-model.ts +118 -0
  223. package/src/agent/Prompt-view.tsx +246 -0
  224. package/src/agent/Prompt.tsx +128 -0
  225. package/src/agent/Prose.tsx +118 -0
  226. package/src/agent/Question.tsx +137 -0
  227. package/src/agent/Reasoning.tsx +31 -0
  228. package/src/agent/Shimmer.tsx +11 -0
  229. package/src/agent/Sources.tsx +23 -0
  230. package/src/agent/SpeechInput.tsx +243 -0
  231. package/src/agent/Suggestions.tsx +36 -0
  232. package/src/agent/ToolCall.tsx +219 -0
  233. package/src/agent/TraceViewer.tsx +96 -0
  234. package/src/agent/bits.tsx +88 -0
  235. package/src/agent/index.ts +38 -0
  236. package/src/bind.ts +57 -0
  237. package/src/collab/AutoTrack.tsx +91 -0
  238. package/src/collab/Comments.tsx +204 -0
  239. package/src/collab/Composer/state.ts +125 -0
  240. package/src/collab/Composer/view.tsx +155 -0
  241. package/src/collab/Composer.tsx +141 -0
  242. package/src/collab/ConversationList.tsx +120 -0
  243. package/src/collab/Cursors.tsx +71 -0
  244. package/src/collab/DataIntegrity.tsx +103 -0
  245. package/src/collab/Kanban-card.ts +74 -0
  246. package/src/collab/Kanban.tsx +368 -0
  247. package/src/collab/Lock.tsx +36 -0
  248. package/src/collab/PresenceStack.tsx +176 -0
  249. package/src/collab/ShareDialog.tsx +273 -0
  250. package/src/collab/Status.tsx +101 -0
  251. package/src/collab/SyncedForm.tsx +42 -0
  252. package/src/collab/Thread/Message.tsx +265 -0
  253. package/src/collab/Thread/rows.tsx +56 -0
  254. package/src/collab/Thread.tsx +323 -0
  255. package/src/collab/VersionHistory.tsx +173 -0
  256. package/src/collab/ViewportRail.tsx +73 -0
  257. package/src/collab/index.ts +37 -0
  258. package/src/collab/peer.tsx +42 -0
  259. package/src/fields.ts +5 -0
  260. package/src/flow/AuthScreen.tsx +81 -0
  261. package/src/flow/AuthSteps.tsx +296 -0
  262. package/src/flow/Checklist.tsx +211 -0
  263. package/src/flow/ConnBanner.tsx +304 -0
  264. package/src/flow/Flow.tsx +97 -0
  265. package/src/flow/MfaSetup.tsx +244 -0
  266. package/src/flow/Otp.tsx +243 -0
  267. package/src/flow/ReauthDialog.tsx +79 -0
  268. package/src/flow/ShortcutsOverlay.tsx +121 -0
  269. package/src/flow/SignGate.tsx +184 -0
  270. package/src/flow/SignIn.tsx +136 -0
  271. package/src/flow/SignUp.tsx +149 -0
  272. package/src/flow/Sso.tsx +96 -0
  273. package/src/flow/SystemPage/accounts.tsx +74 -0
  274. package/src/flow/SystemPage/art.tsx +113 -0
  275. package/src/flow/SystemPage.tsx +395 -0
  276. package/src/flow/Tour.tsx +207 -0
  277. package/src/flow/index.ts +29 -0
  278. package/src/flow/kit.tsx +334 -0
  279. package/src/index.ts +237 -0
  280. package/src/layout.css +4 -0
  281. package/src/links.css +4 -0
  282. package/src/live/ActivityFeed.tsx +88 -0
  283. package/src/live/Bell.tsx +108 -0
  284. package/src/live/Connection.tsx +113 -0
  285. package/src/live/Inbox.tsx +113 -0
  286. package/src/live/InboxFeed.tsx +67 -0
  287. package/src/live/InboxGestures.ts +41 -0
  288. package/src/live/InboxHandlers.ts +102 -0
  289. package/src/live/InboxHeader.tsx +81 -0
  290. package/src/live/InboxModel.ts +81 -0
  291. package/src/live/InboxRow.tsx +125 -0
  292. package/src/live/MeetingRoom.tsx +22 -0
  293. package/src/live/MeetingRoomControlBar.tsx +197 -0
  294. package/src/live/MeetingRoomHandlers.ts +53 -0
  295. package/src/live/MeetingRoomLayout.tsx +27 -0
  296. package/src/live/MeetingRoomModel.ts +49 -0
  297. package/src/live/MeetingRoomMount.ts +49 -0
  298. package/src/live/MeetingRoomParts.tsx +178 -0
  299. package/src/live/MeetingRoomPerson.tsx +21 -0
  300. package/src/live/MeetingRoomState.ts +88 -0
  301. package/src/live/MeetingRoomTile.tsx +84 -0
  302. package/src/live/MeetingRoomTypes.ts +68 -0
  303. package/src/live/MeetingRoomView.tsx +36 -0
  304. package/src/live/NotificationPreferences.tsx +99 -0
  305. package/src/live/NotificationPreferencesActions.ts +55 -0
  306. package/src/live/NotificationPreferencesCell.tsx +26 -0
  307. package/src/live/NotificationPreferencesCells.tsx +59 -0
  308. package/src/live/NotificationPreferencesGrid.tsx +129 -0
  309. package/src/live/NotificationPreferencesModel.tsx +91 -0
  310. package/src/live/NotificationPreferencesSave.ts +85 -0
  311. package/src/live/NotificationPreferencesWatch.ts +31 -0
  312. package/src/live/Prejoin.tsx +238 -0
  313. package/src/live/PrejoinMeter.tsx +26 -0
  314. package/src/live/PrejoinPreview.tsx +53 -0
  315. package/src/live/PushSoftAsk.tsx +63 -0
  316. package/src/live/TransportPicker.tsx +341 -0
  317. package/src/live/TransportPickerDetails.tsx +130 -0
  318. package/src/live/index.ts +31 -0
  319. package/src/live/notify.tsx +22 -0
  320. package/src/live/shared.tsx +110 -0
  321. package/src/parts.tsx +199 -0
  322. package/src/plugin/catalog.mjs +129 -0
  323. package/src/plugin/dtcg.mjs +79 -0
  324. package/src/plugin/icons.mjs +7 -0
  325. package/src/plugin/seed.mjs +40 -0
  326. package/src/plugin/theme-context.mjs +44 -0
  327. package/src/plugin/theme-css.mjs +143 -0
  328. package/src/plugin/theme-motion.mjs +43 -0
  329. package/src/plugin/theme-parts.d.mts +41 -0
  330. package/src/plugin/theme-parts.mjs +224 -0
  331. package/src/plugin/theme-text.mjs +93 -0
  332. package/src/plugin/theme-values.mjs +15 -0
  333. package/src/plugin/theme.d.mts +82 -0
  334. package/src/plugin/theme.mjs +316 -0
  335. package/src/schedule/Agenda.tsx +124 -0
  336. package/src/schedule/AgendaActions.ts +31 -0
  337. package/src/schedule/AgendaDay.tsx +124 -0
  338. package/src/schedule/AgendaGestures.ts +27 -0
  339. package/src/schedule/AgendaKeys.ts +52 -0
  340. package/src/schedule/AgendaModel.ts +82 -0
  341. package/src/schedule/AgendaNavigation.ts +38 -0
  342. package/src/schedule/AgendaPage.tsx +39 -0
  343. package/src/schedule/AgendaStrip.tsx +55 -0
  344. package/src/schedule/AvailabilityEditor-actions.ts +146 -0
  345. package/src/schedule/AvailabilityEditor-day.tsx +119 -0
  346. package/src/schedule/AvailabilityEditor-view.tsx +205 -0
  347. package/src/schedule/AvailabilityEditor.tsx +113 -0
  348. package/src/schedule/BookingCalendar.tsx +121 -0
  349. package/src/schedule/BookingCalendarActions.ts +85 -0
  350. package/src/schedule/BookingCalendarModel.ts +86 -0
  351. package/src/schedule/BookingCalendarParts.tsx +87 -0
  352. package/src/schedule/Calendar/AgendaView.tsx +45 -0
  353. package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
  354. package/src/schedule/Calendar/CalendarMain.tsx +47 -0
  355. package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
  356. package/src/schedule/Calendar/Column.tsx +129 -0
  357. package/src/schedule/Calendar/EventBlock.tsx +71 -0
  358. package/src/schedule/Calendar/MiniMonth.tsx +169 -0
  359. package/src/schedule/Calendar/MonthGrid.tsx +296 -0
  360. package/src/schedule/Calendar/TimeGrid.tsx +252 -0
  361. package/src/schedule/Calendar/Timeline.tsx +287 -0
  362. package/src/schedule/Calendar/ZoneChip.tsx +73 -0
  363. package/src/schedule/Calendar/calendar-shell.ts +160 -0
  364. package/src/schedule/Calendar/calendar-state.ts +30 -0
  365. package/src/schedule/Calendar/now-spans.tsx +33 -0
  366. package/src/schedule/Calendar/shared.ts +3 -0
  367. package/src/schedule/Calendar/state-actions.ts +189 -0
  368. package/src/schedule/Calendar/state-base.ts +143 -0
  369. package/src/schedule/Calendar/state-keys.ts +128 -0
  370. package/src/schedule/Calendar/time-fit.ts +84 -0
  371. package/src/schedule/Calendar.tsx +182 -0
  372. package/src/schedule/EventEditor.tsx +267 -0
  373. package/src/schedule/EventPopover.tsx +190 -0
  374. package/src/schedule/MeetingPlanner-model.ts +222 -0
  375. package/src/schedule/MeetingPlanner-view.tsx +310 -0
  376. package/src/schedule/MeetingPlanner.tsx +122 -0
  377. package/src/schedule/MoveSheet.tsx +168 -0
  378. package/src/schedule/YearView-model.ts +164 -0
  379. package/src/schedule/YearView-parts.tsx +147 -0
  380. package/src/schedule/YearView.tsx +100 -0
  381. package/src/schedule/bits.tsx +65 -0
  382. package/src/schedule/index.ts +25 -0
  383. package/src/skeleton-css.ts +4 -0
  384. package/src/styles.ts +13 -0
  385. package/src/type.css +15 -0
  386. package/src/ui.ts +41 -0
  387. package/src/use-ui.ts +10 -0
  388. package/tailwind.css +38 -0
  389. package/tokens/color.mjs +87 -0
@@ -0,0 +1,145 @@
1
+ import type { Aggregate, GridFilter } from '@kerf-js/veneer-core'
2
+ import { untrack, type State } from '@kerf-js/core'
3
+ import { gridController } from './DataGrid-controller'
4
+ import { GridToolbar } from './DataGrid-toolbar'
5
+ import { GridViewport } from './DataGrid-viewport'
6
+ import { PaginationBar } from './Pagination'
7
+ import type { Column, TableSort } from './Table'
8
+ import '@kerf-js/veneer-core/styles/data/chips.css'
9
+ import '@kerf-js/veneer-core/styles/data/chip.css'
10
+
11
+ /** A Table column with what the grid adds: a filter, aggregates and formatted text. */
12
+ export interface GridColumn<T> extends Column<T> {
13
+ /** A control in the filter row: contains, one of `options`, or at least. */
14
+ filter?: GridFilter
15
+ options?: string[] | undefined
16
+ /** What the footer, a group's subtotal and a parent's roll-up show for this column. */
17
+ aggregate?: Aggregate | ((rows: T[]) => unknown)
18
+ /** Text for an aggregate, and for the cell when it has no `cell`. */
19
+ format?: ((value: unknown) => string) | undefined
20
+ }
21
+
22
+ /** A saved view (06 §6). */
23
+ export type GridView = {
24
+ order: string[]
25
+ hidden: string[]
26
+ filters: Record<string, string>
27
+ sort?: TableSort
28
+ group?: boolean | undefined
29
+ }
30
+
31
+ /** How the grid reads a hierarchy, and loads a branch on demand. */
32
+ export interface GridTree<T> {
33
+ /** What's already here under a row. Default `row.kids`. */
34
+ kids?: (row: T) => readonly T[] | undefined
35
+ /** Fetch a branch on its first open. The filter's query goes along for the server to apply. */
36
+ load?: (row: T, query: string) => Promise<readonly T[]>
37
+ /** Has it children, loaded or not? Default: any in `kids`, or `row.hasChildren`. */
38
+ branch?: ((row: T) => boolean) | undefined
39
+ /** The server's aggregate for a branch that hasn't loaded. */
40
+ rollup?: (row: T, column: string) => unknown
41
+ }
42
+
43
+ /** One cell of a paste, for the grid to accept or refuse. */
44
+ export interface GridPaste<T> {
45
+ row: T
46
+ column: string
47
+ value: unknown
48
+ }
49
+
50
+ /** Props for DataGrid. */
51
+ export interface DataGridProps<T> {
52
+ /** The rows, as an array or a State of one. */
53
+ rows: readonly T[] | State<readonly T[]>
54
+ /** The columns, in order: as in Table, plus `filter`, `options`, `aggregate` and `format`. */
55
+ columns: GridColumn<T>[]
56
+ /** Names the grid (required). It stays in the accessibility tree when `captionHidden`. */
57
+ caption: string
58
+ /** Hides the caption on screen. Screen readers still hear it as the grid's name. */
59
+ captionHidden?: boolean | undefined
60
+ /** The field that identifies a row, or a function that returns it. Keys a row's selection, edits and saved state. Default `id`. */
61
+ rowKey?: (string | ((row: T) => string)) | undefined
62
+ /** Row height and cell padding: `compact` fits the most rows, `comfortable` reads easiest. Default `cozy`. */
63
+ density?: 'compact' | 'cozy' | 'comfortable' | undefined
64
+ /** The named views in the select. */
65
+ views?: Record<string, GridView> | undefined
66
+ /** Starts on this view. */
67
+ view?: string | undefined
68
+ /** Save view pressed: the new view's name (`My view 1`) and its columns, filters, sort and grouping, for you to keep. */
69
+ onSaveView?: ((name: string, view: GridView) => void) | undefined
70
+ /** The Group toggle groups by this column. */
71
+ groupBy?: string | undefined
72
+ /** role=treegrid over hierarchical rows. */
73
+ tree?: GridTree<T> | undefined
74
+ /** Show the tree's filter field, labelled this. */
75
+ filter?: string | undefined
76
+ /** A cell edit committed: the row, the column's id and the new value. A column takes edits when it has `edit`. */
77
+ onEdit?: ((row: T, column: string, value: unknown) => void) | undefined
78
+ /** A validated paste, as one change. Default each cell through `onEdit`. */
79
+ onPaste?: ((changes: GridPaste<T>[]) => void) | undefined
80
+ /** A row's details, under it. */
81
+ expand?: ((row: T) => unknown) | undefined
82
+ /** The bulk bar's actions, over the rows in the range. */
83
+ bulk?: ((rows: string[]) => unknown) | undefined
84
+ /** Shows `size` rows at a time, with a pagination bar under them. */
85
+ page?: { size: number } | undefined
86
+ /** The CSV's name; `false` drops Export. */
87
+ exportName?: string | false | undefined
88
+ /** Your own controls in the toolbar, before Filters, Group, Columns and Export. */
89
+ actions?: unknown
90
+ /** A CSS height past which the rows scroll under a sticky header, such as `480px`. */
91
+ maxHeight?: string | undefined
92
+ }
93
+
94
+ const REORDER = 'Alt plus left or right arrow moves this column.'
95
+
96
+ /**
97
+ * The data grid (06 §6; data.html:1643-1787, treegrid 2482): a Table's parts as role=grid, or treegrid when grouped or
98
+ * hierarchical, with one tab stop. Arrows move the cell, Shift extends a range, ⌘/Ctrl C copies it as TSV, Enter or F2
99
+ * edits and an invalid value never commits. Headers reorder by dragging or Alt + ←/→. A filter row with applied chips,
100
+ * group and aggregate rows, saved views, CSV, a bulk bar and details. Rows and cells are keyed, so a reorder moves nodes.
101
+ */
102
+ export function DataGrid<T>(props: DataGridProps<T>) {
103
+ const model = gridController(untrack(() => props))
104
+ return (
105
+ <div
106
+ ref={(n) => (model.refs.el = n)}
107
+ data-scope="table"
108
+ data-phone="columns"
109
+ data-density={props.density}
110
+ data-tree={props.tree ? '' : undefined}
111
+ id={model.id}
112
+ >
113
+ <GridToolbar model={model} props={props} />
114
+ {props.bulk && (
115
+ <div
116
+ data-part="bulk"
117
+ hidden={model.chosen().length === 0}
118
+ role="region"
119
+ aria-label="Bulk actions"
120
+ >
121
+ <b>{model.chosen().length} selected</b>
122
+ {props.bulk(model.chosen())}
123
+ </div>
124
+ )}
125
+ <GridViewport model={model} props={props} />
126
+ <div data-part="footer">
127
+ <span id={`${model.id}-hint`}>{model.hint()}</span>
128
+ <span aria-live="polite">{model.status.value}</span>
129
+ </div>
130
+ {model.paged.value && (
131
+ <PaginationBar
132
+ total={model.ordered.value.length}
133
+ page={model.at}
134
+ size={props.page!.size}
135
+ sizes={[props.page!.size]}
136
+ />
137
+ )}
138
+ <span data-part="sr-only" id={`${model.id}-move`}>
139
+ {REORDER}
140
+ </span>
141
+ </div>
142
+ )
143
+ }
144
+
145
+ export { PivotTable, type PivotMeasure } from './DataGrid-pivot'
@@ -0,0 +1,27 @@
1
+ // The preset rail in the range picker.
2
+ import type { RangeDateModel } from './DateField-range'
3
+
4
+ export function RangeDatePresets({ field }: { field: RangeDateModel }) {
5
+ const { narrow, list, onRail, chosen, applyPreset } = field
6
+ return (
7
+ <ul
8
+ role="listbox"
9
+ aria-label="Presets"
10
+ aria-orientation={narrow.value ? 'horizontal' : 'vertical'}
11
+ onKeyDown={onRail}
12
+ >
13
+ {list.value.map((p) => (
14
+ <li
15
+ key={p.id}
16
+ role="option"
17
+ data-id={p.id}
18
+ tabindex={p.id === (chosen.value ?? list.value[0]!.id) ? '0' : '-1'}
19
+ aria-selected={p.id === chosen.value ? 'true' : 'false'}
20
+ onClick={() => applyPreset(p)}
21
+ >
22
+ {p.label}
23
+ </li>
24
+ ))}
25
+ </ul>
26
+ )
27
+ }
@@ -0,0 +1,370 @@
1
+ import { CalendarIcon } from '@kerf-js/veneer-icons'
2
+ import {
3
+ addDays,
4
+ daysIn,
5
+ fmt,
6
+ fmtRange,
7
+ isoOf,
8
+ pickRange,
9
+ readDate,
10
+ daysBetween,
11
+ defaultPresets,
12
+ listKey,
13
+ weekStart,
14
+ type ChangeReason,
15
+ type DateRange,
16
+ type IsoDate,
17
+ type RangePreset,
18
+ type SegmentPart,
19
+ } from '@kerf-js/veneer-core'
20
+ import { derived, state, untrack } from '@kerf-js/core'
21
+ import { Button } from './Button'
22
+ import { CalendarGrid } from './Calendar'
23
+ import { RangeDatePresets } from './DateField-presets'
24
+ import {
25
+ Composite,
26
+ Hidden,
27
+ isSheet,
28
+ messages,
29
+ Panel,
30
+ Trigger,
31
+ bindable,
32
+ useOpen,
33
+ usePickerEnv,
34
+ type Bindable,
35
+ type Openable,
36
+ type RichFieldProps,
37
+ } from './Picker'
38
+ import { Segments, type SegmentState } from './Segments'
39
+
40
+ /** A comparison period shown beside a date range. */
41
+ export type RangeCompare = 'previous-period' | 'previous-year' | DateRange
42
+ /** Props for DateRangeField. */
43
+ export type DateRangeFieldProps = RichFieldProps &
44
+ Bindable<DateRange> &
45
+ Openable & {
46
+ presets?: RangePreset[] | 'default' | false
47
+ /** The id of the chosen preset, such as "Last 7 days". Null when the dates were picked by hand. */
48
+ preset?: string | null
49
+ /** Called with the preset's id when one is picked, and null when the dates are changed by hand. */
50
+ onPresetChange?: (id: string | null) => void
51
+ min?: IsoDate | undefined
52
+ max?: IsoDate | undefined
53
+ maxDays?: number
54
+ /** Return true for a day that can't start or end the range: it shows struck through. */
55
+ isDateUnavailable?: (d: IsoDate) => boolean
56
+ months?: 1 | 2 | 'auto'
57
+ compare?: RangeCompare | null | undefined
58
+ }
59
+
60
+ /** The comparison range of a selection, for a dashboard's "vs" (04 DateRangeField). */
61
+ export function compareRange(v: DateRange, c: RangeCompare | null | undefined): DateRange | null {
62
+ if (!c || !v.start || !v.end) return typeof c === 'object' ? c : null
63
+ if (typeof c === 'object') return c
64
+ if (c === 'previous-year')
65
+ return {
66
+ start: `${+v.start.slice(0, 4) - 1}${v.start.slice(4)}` as IsoDate,
67
+ end: `${+v.end.slice(0, 4) - 1}${v.end.slice(4)}` as IsoDate,
68
+ }
69
+ const n = daysBetween(v.start, v.end) + 1
70
+ return { start: addDays(v.start, -n), end: addDays(v.start, -1) }
71
+ }
72
+
73
+ function rangeDateState(props: DateRangeFieldProps) {
74
+ const env = usePickerEnv(
75
+ () => props.locale,
76
+ () => props.today,
77
+ )
78
+ const v = bindable<DateRange>(
79
+ () => props.value,
80
+ () => props.defaultValue,
81
+ { start: null, end: null },
82
+ () => props.onValueChange,
83
+ )
84
+ const pop = useOpen(
85
+ () => props.open,
86
+ () => props.defaultOpen,
87
+ () => props.onOpenChange,
88
+ )
89
+ const chosen = state<string | null>(untrack(() => props.preset) ?? null)
90
+ const jump = state<string | null>(null)
91
+ const started = state(false)
92
+ const narrow = state(false)
93
+ const t = derived(() => messages(env.locale.value))
94
+ const list = derived(() => {
95
+ const presets = props.presets === undefined ? 'default' : props.presets
96
+ return presets === false
97
+ ? []
98
+ : presets === 'default'
99
+ ? defaultPresets(env.locale.value)
100
+ : presets
101
+ })
102
+ const count = derived(() => {
103
+ const months = props.months === undefined ? 'auto' : props.months
104
+ return months === 'auto' ? (narrow.value ? 1 : 2) : months
105
+ })
106
+ const compared = derived(() => compareRange(v.value, props.compare))
107
+ const trouble = derived(() => {
108
+ const r = v.value
109
+ if (r.start && r.end && r.end < r.start) return 'The end is before the start.'
110
+ if (r.start && r.end && props.maxDays && daysBetween(r.start, r.end) + 1 > props.maxDays)
111
+ return `Choose at most ${props.maxDays} days.`
112
+ return undefined
113
+ })
114
+ const human = (d: string) => fmt(d, { dateStyle: 'medium' }, env.locale.value)
115
+ const summary = derived(() => {
116
+ const r = v.value
117
+ if (!r.start) return 'Pick a start date'
118
+ if (!r.end) return 'Pick an end date'
119
+ const n = daysBetween(r.start, r.end) + 1
120
+ return `${r.start > r.end ? `${human(r.start)} – ${human(r.end)}` : fmtRange(r.start, r.end, env.locale.value)} · ${new Intl.NumberFormat(env.locale.value, { style: 'unit', unit: 'day', unitDisplay: 'long' }).format(n)}`
121
+ })
122
+ const said = state('')
123
+ return {
124
+ env,
125
+ v,
126
+ pop,
127
+ chosen,
128
+ jump,
129
+ started,
130
+ narrow,
131
+ t,
132
+ list,
133
+ count,
134
+ compared,
135
+ trouble,
136
+ summary,
137
+ said,
138
+ }
139
+ }
140
+
141
+ function rangeDateActions(
142
+ props: DateRangeFieldProps,
143
+ getTrigger: () => HTMLButtonElement | undefined,
144
+ base: ReturnType<typeof rangeDateState>,
145
+ ) {
146
+ const { env, v, pop, chosen, jump, started, narrow, list, summary, said } = base
147
+ const set = (r: DateRange, reason: ChangeReason, id: string | null = null) => {
148
+ chosen.value = id
149
+ props.onPresetChange?.(id)
150
+ v.set(r, reason)
151
+ }
152
+ const edit = (which: 'start' | 'end') => (st: SegmentState, parts: SegmentPart[]) => {
153
+ started.value = st !== 'empty' || !!(which === 'start' ? v.value.end : v.value.start)
154
+ if (st === 'empty') return set({ ...v.value, [which]: null }, 'keyboard')
155
+ if (st !== 'complete') return
156
+ const d = readDate(parts)
157
+ if (d.day! <= daysIn(d.year!, d.month!)) set({ ...v.value, [which]: isoOf(d) }, 'keyboard')
158
+ }
159
+ const editStart = edit('start'),
160
+ editEnd = edit('end')
161
+ const applyPreset = (p: RangePreset) => {
162
+ const r = p.range(env.today.value as IsoDate, weekStart(env.locale.value))
163
+ set(r, 'pointer', p.id)
164
+ jump.value = r.end
165
+ said.value = `${p.label}: ${summary.value}`
166
+ }
167
+ const onRail = (e: KeyboardEvent) => {
168
+ const opts = list.value
169
+ const at = opts.findIndex((p) => p.id === (e.target as HTMLElement).dataset.id)
170
+ if (at < 0) return
171
+ const step = narrow.value
172
+ ? (({ ArrowRight: 'ArrowDown', ArrowLeft: 'ArrowUp' } as Record<string, string>)[e.key] ??
173
+ e.key)
174
+ : e.key
175
+ const m = listKey(step, at, opts.length)
176
+ if (!m.handled) return
177
+ e.preventDefault()
178
+ if (m.pick) return applyPreset(opts[at]!)
179
+ ;(e.currentTarget as HTMLElement)
180
+ .querySelector<HTMLElement>(`[data-id="${opts[m.to]!.id}"]`)
181
+ ?.focus()
182
+ }
183
+ const toggle = () => {
184
+ narrow.value =
185
+ isSheet(getTrigger()!, props.presentation) ||
186
+ (getTrigger()!.ownerDocument.defaultView?.innerWidth ?? 1024) < 640
187
+ pop.set(!pop.value)
188
+ }
189
+ return { set, editStart, editEnd, applyPreset, onRail, toggle }
190
+ }
191
+
192
+ function rangeDateController(
193
+ props: DateRangeFieldProps,
194
+ getTrigger: () => HTMLButtonElement | undefined,
195
+ ) {
196
+ const base = rangeDateState(props)
197
+ return { ...base, ...rangeDateActions(props, getTrigger, base) }
198
+ }
199
+
200
+ function RangeDateControl({
201
+ field,
202
+ props,
203
+ setTrigger,
204
+ }: {
205
+ field: ReturnType<typeof rangeDateController>
206
+ props: DateRangeFieldProps
207
+ setTrigger: (node: HTMLButtonElement) => void
208
+ }) {
209
+ const { env, v, pop, t, summary, editStart, editEnd, toggle } = field
210
+ return (
211
+ <>
212
+ <Segments
213
+ required={props.required}
214
+ kind="date"
215
+ label="Start"
216
+ locale={env.locale.value}
217
+ value={v.value.start}
218
+ today={env.today.value}
219
+ disabled={props.disabled}
220
+ readonly={props.readonly}
221
+ onEdit={editStart}
222
+ />
223
+ <span data-part="range-sep" aria-hidden="true">
224
+ –
225
+ </span>
226
+ <Segments
227
+ required={props.required}
228
+ kind="date"
229
+ label="End"
230
+ locale={env.locale.value}
231
+ value={v.value.end}
232
+ today={env.today.value}
233
+ disabled={props.disabled}
234
+ readonly={props.readonly}
235
+ onEdit={editEnd}
236
+ />
237
+ <Trigger
238
+ ref={setTrigger}
239
+ icon={CalendarIcon}
240
+ label={t.value.chooseRange + (v.value.start && v.value.end ? `, ${summary.value}` : '')}
241
+ open={pop.value}
242
+ disabled={props.disabled}
243
+ onToggle={toggle}
244
+ />
245
+ <Hidden
246
+ name={props.name}
247
+ value={() => (v.value.start && v.value.end ? `${v.value.start}/${v.value.end}` : '')}
248
+ />
249
+ </>
250
+ )
251
+ }
252
+
253
+ function RangeDatePanel({
254
+ field,
255
+ props,
256
+ trigger,
257
+ }: {
258
+ field: ReturnType<typeof rangeDateController>
259
+ props: DateRangeFieldProps
260
+ trigger: () => HTMLElement
261
+ }) {
262
+ const { env, v, pop, jump, narrow, t, list, count, compared, summary, said, set } = field
263
+ return (
264
+ <Panel
265
+ label={t.value.chooseRange}
266
+ open={pop}
267
+ trigger={trigger}
268
+ presentation={props.presentation}
269
+ >
270
+ {() => (
271
+ <div data-scope="range-panel" data-narrow={narrow.value ? '' : undefined}>
272
+ {list.value.length > 0 && <RangeDatePresets field={field} />}
273
+ <div>
274
+ <CalendarGrid
275
+ mode="range"
276
+ months={count.value}
277
+ value={() => v.value}
278
+ compare={() => compared.value}
279
+ goTo={() => jump.value}
280
+ locale={env.locale.value}
281
+ today={env.today.value}
282
+ min={props.min}
283
+ max={props.max}
284
+ isDateUnavailable={props.isDateUnavailable}
285
+ autofocus
286
+ onPick={(iso, r) => set(pickRange(v.value, iso), r)}
287
+ >
288
+ <div data-part="foot">
289
+ <span aria-live="polite">{summary.value}</span>
290
+ <Button
291
+ emphasis="ghost"
292
+ size="sm"
293
+ onClick={() => set({ start: null, end: null }, 'pointer')}
294
+ >
295
+ {t.value.clear}
296
+ </Button>
297
+ </div>
298
+ </CalendarGrid>
299
+ </div>
300
+ <span class="sr" role="status">
301
+ {said.value}
302
+ </span>
303
+ </div>
304
+ )}
305
+ </Panel>
306
+ )
307
+ }
308
+
309
+ export type RangeDateModel = ReturnType<typeof rangeDateController>
310
+
311
+ /**
312
+ * DateRangeField (04 §2): two segment groups and one trigger; the popover shows two months (one when narrow) beside a
313
+ * preset rail. The chosen preset is kept apart from the frozen dates, so a dashboard's "Last 7 days" can roll forward.
314
+ */
315
+ export function DateRangeField(props: DateRangeFieldProps) {
316
+ const {
317
+ value: _value,
318
+ defaultValue: _defaultValue,
319
+ onValueChange: _onValueChange,
320
+ open: _open,
321
+ defaultOpen: _defaultOpen,
322
+ onOpenChange: _onOpenChange,
323
+ presets: _presets = 'default',
324
+ preset,
325
+ onPresetChange: _onPresetChange,
326
+ min: _min,
327
+ max: _max,
328
+ maxDays: _maxDays,
329
+ isDateUnavailable: _isDateUnavailable,
330
+ months: _months = 'auto',
331
+ compare: _compare,
332
+ locale: _locale,
333
+ today: _today,
334
+ name: _name,
335
+ presentation: _presentation,
336
+ label,
337
+ hint,
338
+ error,
339
+ disabled,
340
+ readonly,
341
+ ...rest
342
+ } = props
343
+ let trigger: HTMLButtonElement | undefined
344
+ const field = rangeDateController(
345
+ untrack(() => props),
346
+ () => trigger,
347
+ )
348
+ const { v, pop, chosen, started, trouble } = field
349
+ return (
350
+ <Composite
351
+ {...rest}
352
+ label={label}
353
+ hint={hint}
354
+ error={error ?? trouble.value}
355
+ disabled={disabled}
356
+ readonly={readonly}
357
+ bound={v}
358
+ onReset={() => {
359
+ started.value = false
360
+ chosen.value = untrack(() => preset) ?? null
361
+ }}
362
+ filled={!!(v.value.start || v.value.end) || started.value}
363
+ hold={pop.value}
364
+ control={() => (
365
+ <RangeDateControl field={field} props={props} setTrigger={(n) => (trigger = n)} />
366
+ )}
367
+ end={<RangeDatePanel field={field} props={props} trigger={() => trigger!} />}
368
+ />
369
+ )
370
+ }