@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
package/src/Drawer.tsx ADDED
@@ -0,0 +1,123 @@
1
+ import { CloseX } from './CloseX'
2
+ import { dialog, sheet, uid, type Detent } from '@kerf-js/veneer-core'
3
+ import { derived, type State, untrack } from '@kerf-js/core'
4
+ import { use } from '@kerf-js/veneer-core/kerf'
5
+ import './styles'
6
+ import '@kerf-js/veneer-core/styles/components/button.css' // the close button's markup
7
+ import '@kerf-js/veneer-core/styles/components/sheet.css'
8
+ import '@kerf-js/veneer-core/styles/components/dialog.css' // the backdrop and the parts a sheet shares with the dialog
9
+
10
+ type DrawerProps = {
11
+ open: State<boolean>
12
+ title: unknown
13
+ description?: unknown
14
+ footer?: unknown
15
+ side?: 'auto' | 'right' | 'left' | 'bottom' | 'top'
16
+ /** A bottom sheet's opening height when its content is taller than half the window: half (the page stays in view) or full. */
17
+ at?: Detent
18
+ /** At the half stop the page behind stays live: a reader can scroll it and tap in it while the sheet waits. */
19
+ peek?: boolean
20
+ /** Drawn open in the page's flow, not over it: no top layer, scrim or focus trap. For docs and previews. */ inline?: boolean
21
+ children?: unknown
22
+ }
23
+
24
+ /** Where `side` puts the sheet now: auto is the bottom under 600px, decided as it opens. */
25
+ const placed = (side: NonNullable<DrawerProps['side']>) =>
26
+ side === 'auto' ? (typeof innerWidth === 'number' && innerWidth < 600 ? 'bottom' : 'right') : side
27
+
28
+ /** The dialog (top layer, focus, Escape) and, at the bottom, the hand that drags it between its stops. */
29
+ function bind(
30
+ props: {
31
+ open: State<boolean>
32
+ side: NonNullable<DrawerProps['side']>
33
+ at: Detent
34
+ peek: boolean
35
+ },
36
+ el: () => HTMLDialogElement | undefined,
37
+ ) {
38
+ const { open, side, at, peek } = props
39
+ use(dialog, el, () => {
40
+ const on = open.value
41
+ const node = el()
42
+ if (on && node) node.dataset.side = placed(side)
43
+ return { open: on, onClose: () => (open.value = false) }
44
+ })
45
+ // a drawer fixed at a side never sits at the bottom: no sheet, and no second run on every open
46
+ if (side !== 'bottom' && side !== 'auto') return
47
+ // registered after dialog, so data-side is set before the sheet measures on opening
48
+ use(sheet, el, () => ({ open: open.value, at, peek, onClose: () => (open.value = false) }))
49
+ }
50
+
51
+ /**
52
+ * A sheet (05 §3 Drawer/Sheet; components.html:1092-1106): on a native <dialog>, at the side on wide screens and from
53
+ * the bottom on phones (`side="auto"`: bottom under 600px, decided when it opens). The handle shows only at the
54
+ * bottom. Initial focus goes to [autofocus], else the title, never the handle. `inline` draws it open in the page's flow,
55
+ * for docs and previews: a non-modal <dialog open> at its side's shape, with no top layer, scrim or focus trap.
56
+ */
57
+ export function Drawer({
58
+ open,
59
+ title,
60
+ description,
61
+ footer,
62
+ side = 'auto',
63
+ at = 'half',
64
+ peek,
65
+ inline,
66
+ children,
67
+ }: DrawerProps) {
68
+ const id = uid('sheet')
69
+ const hasDescription = derived(() => description !== undefined)
70
+ const foot = derived(() => footer) // one build of the footer, however often it is read
71
+ let el: HTMLDialogElement | undefined
72
+ const flat = untrack(() => !!inline)
73
+ if (!flat)
74
+ bind(
75
+ untrack(() => ({ open, side, at, peek: !!peek })),
76
+ () => el,
77
+ )
78
+ const closer = (e: Event) => {
79
+ if (flat && (e.target as Element).closest?.('[data-close]')) open.value = false
80
+ }
81
+ return (
82
+ <dialog
83
+ ref={(n) => (el = n)}
84
+ open={flat ? open.value : undefined}
85
+ data-presentation={flat ? 'inline' : undefined}
86
+ onClick={closer}
87
+ data-scope="sheet"
88
+ aria-labelledby={`${id}-t`}
89
+ aria-describedby={hasDescription.value ? `${id}-d` : undefined}
90
+ data-side={untrack(() => (side === 'auto' ? 'right' : side))}
91
+ >
92
+ <button
93
+ type="button"
94
+ data-part="handle"
95
+ aria-label="Sheet height: tall. Press to shrink."
96
+ ></button>
97
+ <div data-part="header">
98
+ <h2 data-part="title" id={`${id}-t`}>
99
+ {title}
100
+ </h2>
101
+ {hasDescription.value && (
102
+ <p data-part="description" id={`${id}-d`}>
103
+ {description}
104
+ </p>
105
+ )}
106
+ <button
107
+ type="button"
108
+ data-scope="button"
109
+ data-emphasis="ghost"
110
+ data-tone="neutral"
111
+ data-icon-only=""
112
+ aria-label="Close"
113
+ data-part="close"
114
+ data-close=""
115
+ >
116
+ <CloseX />
117
+ </button>
118
+ </div>
119
+ <div data-part="body">{children}</div>
120
+ {foot.value !== undefined && <div data-part="footer">{foot.value}</div>}
121
+ </dialog>
122
+ )
123
+ }
@@ -0,0 +1,227 @@
1
+ import { TimerIcon } from '@kerf-js/veneer-icons'
2
+ import {
3
+ balance,
4
+ formatDuration,
5
+ pad,
6
+ parseDuration,
7
+ totalSeconds,
8
+ type DurationParts,
9
+ type IsoDuration,
10
+ } from '@kerf-js/veneer-core'
11
+ import { derived, state, untrack, type State } from '@kerf-js/core'
12
+ import {
13
+ bindable,
14
+ Composite,
15
+ Hidden,
16
+ usePickerEnv,
17
+ type Bindable,
18
+ type RichFieldProps,
19
+ } from './Picker'
20
+
21
+ type Unit = 'd' | 'h' | 'm' | 's'
22
+ const INTL = { d: 'day', h: 'hour', m: 'minute', s: 'second' } as const
23
+ const NAMES = { d: 'Days', h: 'Hours', m: 'Minutes', s: 'Seconds' } as const
24
+ const SHORT = { d: 'd', h: 'h', m: 'min', s: 's' } as const
25
+ const SIZE = { d: 86400, h: 3600, m: 60, s: 1 } as const
26
+ const MAX = { d: 99, h: 99, m: 59, s: 59 } as const
27
+
28
+ /** Props for DurationField. */
29
+ export type DurationFieldProps = RichFieldProps &
30
+ Bindable<IsoDuration | null> & {
31
+ units?: Unit[]
32
+ max?: IsoDuration | undefined
33
+ step?: Partial<Record<'h' | 'm' | 's', number>>
34
+ balance?: boolean
35
+ }
36
+
37
+ type DurationKeyContext = {
38
+ units: () => Unit[]
39
+ step: () => DurationFieldProps['step']
40
+ carry: () => boolean
41
+ group: () => HTMLDivElement | undefined
42
+ parts: { readonly value: DurationParts }
43
+ buf: State<string>
44
+ write: (next: DurationParts) => void
45
+ }
46
+
47
+ function durationKeys({ units, step, carry, group, parts, buf, write }: DurationKeyContext) {
48
+ return (e: KeyboardEvent) => {
49
+ const el = (e.target as HTMLElement).closest?.<HTMLElement>('[data-u]')
50
+ if (!el) return
51
+ const u = el.dataset.u as Unit
52
+ const at = units().indexOf(u)
53
+ const p = parts.value
54
+ const size = (step()?.[u as 'h'] ?? (u === 'm' ? 5 : 1)) * SIZE[u] * (e.shiftKey ? 3 : 1)
55
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
56
+ e.preventDefault()
57
+ buf.value = ''
58
+ write(balance(totalSeconds(p) + (e.key === 'ArrowUp' ? size : -size), units()))
59
+ } else if (/^\d$/.test(e.key)) {
60
+ e.preventDefault()
61
+ const b = (buf.value + e.key).slice(-2)
62
+ buf.value = b
63
+ const n = +b
64
+ write(n > MAX[u] && !carry() ? p : { ...p, [u]: n })
65
+ if (b.length === 2 && at < units().length - 1) {
66
+ buf.value = ''
67
+ ;(group()!.querySelector(`[data-u="${units()[at + 1]}"]`) as HTMLElement).focus()
68
+ }
69
+ } else if (e.key === 'Backspace') {
70
+ e.preventDefault()
71
+ buf.value = ''
72
+ write({ ...p, [u]: 0 })
73
+ } else if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
74
+ const to = units()[at + (e.key === 'ArrowRight' ? 1 : -1)]
75
+ if (to) {
76
+ e.preventDefault()
77
+ ;(group()!.querySelector(`[data-u="${to}"]`) as HTMLElement).focus()
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ type DurationControlContext = {
84
+ units: () => Unit[]
85
+ disabled: () => boolean | undefined
86
+ required: () => boolean | undefined
87
+ readonly name: string | undefined
88
+ parts: { readonly value: DurationParts }
89
+ buf: State<string>
90
+ onKey: (e: KeyboardEvent) => void
91
+ setGroup: (el: HTMLDivElement) => void
92
+ say: (unit: Unit, value: number) => string
93
+ value: () => IsoDuration | null
94
+ }
95
+
96
+ function durationControl(ctx: DurationControlContext) {
97
+ return (
98
+ <>
99
+ <div
100
+ ref={ctx.setGroup}
101
+ data-part="segments"
102
+ onKeyDown={ctx.onKey}
103
+ onFocusOut={() => (ctx.buf.value = '')}
104
+ >
105
+ {ctx.units().map((u) => {
106
+ const n = derived(() => ctx.parts.value[u])
107
+ return (
108
+ <>
109
+ <span
110
+ key={u}
111
+ data-part="segment"
112
+ data-u={u}
113
+ role="spinbutton"
114
+ tabindex={ctx.disabled() ? undefined : '0'}
115
+ aria-label={NAMES[u]}
116
+ aria-required={ctx.required() ? 'true' : undefined}
117
+ aria-valuemin="0"
118
+ aria-valuemax={MAX[u]}
119
+ aria-valuenow={n.value}
120
+ aria-valuetext={ctx.say(u, n.value)}
121
+ >
122
+ {u === ctx.units()[0] ? n.value : pad(n.value)}
123
+ </span>
124
+ <span data-part="literal" class="unit" aria-hidden="true">
125
+ {SHORT[u]}
126
+ </span>
127
+ </>
128
+ )
129
+ })}
130
+ </div>
131
+ <Hidden name={ctx.name} value={() => ctx.value() ?? ''} />
132
+ </>
133
+ )
134
+ }
135
+
136
+ function sayDuration(locale: string, u: Unit, n: number) {
137
+ return new Intl.NumberFormat(locale, {
138
+ style: 'unit',
139
+ unit: INTL[u],
140
+ unitDisplay: 'long',
141
+ }).format(n)
142
+ }
143
+
144
+ /**
145
+ * DurationField (04 §2): a spinbutton for each allowed unit; ↑/↓ step with carry into the next unit (Shift for three
146
+ * steps), and digits fill. The value is an ISO duration, balanced (`PT90M` → `PT1H30M`) unless `balance: false`.
147
+ */
148
+ export function DurationField({
149
+ value,
150
+ defaultValue,
151
+ onValueChange,
152
+ units = ['h', 'm'],
153
+ max,
154
+ step,
155
+ balance: carry = true,
156
+ locale,
157
+ today,
158
+ name,
159
+ label,
160
+ hint,
161
+ error,
162
+ disabled,
163
+ ...rest
164
+ }: DurationFieldProps) {
165
+ const env = usePickerEnv(
166
+ () => locale,
167
+ () => today,
168
+ )
169
+ const v = bindable<IsoDuration | null>(
170
+ () => value,
171
+ () => defaultValue,
172
+ null,
173
+ () => onValueChange,
174
+ )
175
+ const parts = derived(() => parseDuration(v.value))
176
+ const limit = untrack(() => (max ? totalSeconds(parseDuration(max)) : Infinity))
177
+ const buf = state('')
178
+ let group: HTMLDivElement | undefined
179
+ const say = (u: Unit, n: number) => sayDuration(env.locale.value, u, n)
180
+ const words = derived(() => {
181
+ const p = parts.value
182
+ const on = units.filter((u) => p[u])
183
+ return on.length ? on.map((u) => say(u, p[u])).join(' ') : 'No time'
184
+ })
185
+ const write = (next: DurationParts, reason: 'keyboard' = 'keyboard') => {
186
+ const t = Math.max(0, Math.min(limit, totalSeconds(next)))
187
+ v.set(formatDuration(carry ? balance(t, units) : next), reason)
188
+ }
189
+ const onKey = durationKeys({
190
+ units: () => units,
191
+ step: () => step,
192
+ carry: () => carry,
193
+ group: () => group,
194
+ parts,
195
+ buf,
196
+ write,
197
+ })
198
+ return (
199
+ <Composite
200
+ icon={TimerIcon}
201
+ {...rest}
202
+ label={label}
203
+ hint={hint ?? words.value}
204
+ error={error}
205
+ disabled={disabled}
206
+ bound={v}
207
+ onReset={() => (buf.value = '')}
208
+ filled={totalSeconds(parts.value) > 0}
209
+ control={() =>
210
+ durationControl({
211
+ units: () => units,
212
+ disabled: () => disabled,
213
+ required: () => rest.required,
214
+ get name() {
215
+ return name
216
+ },
217
+ parts,
218
+ buf,
219
+ onKey,
220
+ setGroup: (n) => (group = n),
221
+ say,
222
+ value: () => v.value,
223
+ })
224
+ }
225
+ />
226
+ )
227
+ }
package/src/Feed.tsx ADDED
@@ -0,0 +1,78 @@
1
+ import { untrack } from '@kerf-js/core'
2
+ import { VirtualList, type VirtualControl } from './VirtualList'
3
+ import './styles'
4
+ import '@kerf-js/veneer-core/styles/data/timeline.css'
5
+
6
+ /** One row of a Feed. */
7
+ export interface FeedItem {
8
+ id: string | number
9
+ /** Actor, verb and object: the bold line. */
10
+ what: unknown
11
+ when?: string
12
+ /** The body, measured. */
13
+ detail?: string
14
+ tone?: string | undefined
15
+ }
16
+
17
+ /** Props for Feed. */
18
+ export interface FeedProps<T extends FeedItem> {
19
+ items: readonly T[]
20
+ label: string
21
+ height?: string
22
+ busy?: boolean | undefined
23
+ /** Near the end: load more. */
24
+ onEnd?: () => void
25
+ /** Called when an item's measured height differs from the estimate, with both heights. For tuning. */
26
+ onDrift?: (index: number, predicted: number, actual: number) => void
27
+ /** Hands over a control to scroll to, focus or move between items from outside. */
28
+ control?: (c: VirtualControl) => void
29
+ /** An item's whole content. Default: knot, what, when, detail. */
30
+ children?: (item: () => T) => unknown
31
+ }
32
+
33
+ /** A long activity feed (07 §4): the APG feed pattern on a window. Page Down and Up move between articles. */
34
+ export function Feed<T extends FeedItem>(props: FeedProps<T>) {
35
+ const render = untrack(() => props.children)
36
+ const keys = (e: KeyboardEvent, c: VirtualControl) => {
37
+ if (e.key === 'PageDown' || e.key === 'PageUp') {
38
+ e.preventDefault()
39
+ c.move(e.key === 'PageDown' ? 1 : -1)
40
+ }
41
+ }
42
+ return (
43
+ <VirtualList
44
+ tag="ol"
45
+ inner
46
+ role="feed"
47
+ rowRole="article"
48
+ listScope="timeline"
49
+ label={props.label}
50
+ height={props.height ?? '480px'}
51
+ items={props.items}
52
+ rowKey={(i) => i.id}
53
+ text={(i) => i.detail ?? ''}
54
+ estimate={56}
55
+ busy={props.busy}
56
+ onEnd={props.onEnd}
57
+ onDrift={props.onDrift}
58
+ control={props.control}
59
+ roving
60
+ onRowKey={keys}
61
+ >
62
+ {(item) =>
63
+ render ? (
64
+ render(item)
65
+ ) : (
66
+ <>
67
+ <span data-part="knot" data-tone={item().tone}></span>
68
+ <span data-part="what">{item().what}</span>
69
+ <time data-part="when">{item().when}</time>
70
+ <span data-part="detail" data-measure="">
71
+ {item().detail}
72
+ </span>
73
+ </>
74
+ )
75
+ }
76
+ </VirtualList>
77
+ )
78
+ }
@@ -0,0 +1,147 @@
1
+ import { AlertIcon, XIcon } from '@kerf-js/veneer-icons'
2
+ import { untrack } from '@kerf-js/core'
3
+ import { Icon, type IconRef } from '../Icon'
4
+ import type { Field, Control } from '../Field'
5
+ type Value<T> = { readonly value: T }
6
+ type Model = {
7
+ p: Parameters<typeof Field>[0]
8
+ id: string
9
+ shell: Parameters<Control>[0]
10
+ live: Record<string, unknown>
11
+ problem: Value<unknown>
12
+ glyph: Value<IconRef | undefined>
13
+ message: Value<boolean>
14
+ msg: Value<string | undefined>
15
+ chars: Value<{ c: string; at: number }[]>
16
+ setRoot: (n: HTMLDivElement) => void
17
+ }
18
+
19
+ /** Render the field in its existing owner and original static template. */
20
+ export function fieldView({
21
+ p,
22
+ id,
23
+ problem,
24
+ glyph,
25
+ message,
26
+ msg,
27
+ chars,
28
+ live,
29
+ shell,
30
+ setRoot,
31
+ }: {
32
+ p: Model['p']
33
+ id: Model['id']
34
+ problem: Model['problem']
35
+ glyph: Model['glyph']
36
+ message: Model['message']
37
+ msg: Model['msg']
38
+ chars: Model['chars']
39
+ live: Model['live']
40
+ shell: Model['shell']
41
+ setRoot: Model['setRoot']
42
+ }) {
43
+ return (
44
+ <div
45
+ ref={setRoot}
46
+ data-scope="field"
47
+ data-variant={p.variant}
48
+ data-appearance={p.appearance}
49
+ data-size={p.size === 'md' ? undefined : p.size}
50
+ data-counter={p.counter}
51
+ data-invalid={problem.value ? '' : undefined}
52
+ data-disabled={live.disabled ? '' : undefined}
53
+ data-readonly={live.readonly ? '' : undefined}
54
+ {...p.attrs}
55
+ >
56
+ <div
57
+ data-part="control"
58
+ data-icon={typeof glyph.value === 'string' ? glyph.value : glyph.value ? '' : undefined}
59
+ data-sweep=""
60
+ data-filled={(p.filled ?? live.value) ? '' : undefined}
61
+ data-hold={p.hold ? '' : undefined}
62
+ data-wrap={p.wrap ? '' : undefined}
63
+ >
64
+ <span data-part="sweep-base" aria-hidden="true"></span>
65
+ <span data-part="sweep" aria-hidden="true"></span>
66
+ {glyph.value && fieldIcon(glyph)}
67
+ <label
68
+ data-part="label"
69
+ for={p.group || p.labelled ? undefined : id}
70
+ id={p.group || p.labelled ? `${id}-l` : undefined}
71
+ >
72
+ <span data-part="label-text">{p.label}</span>
73
+ <span data-part="label-chars" aria-hidden="true">
74
+ {chars.value.map((x) => (
75
+ <span key={x.at} data-char data-c={x.c}></span>
76
+ ))}
77
+ </span>
78
+ </label>
79
+ {p.prefix !== undefined && <span data-part="prefix">{p.prefix}</span>}
80
+ {p.group ? fieldBody({ p, id, msg, problem, shell }) : untrack(() => p.control(shell))}
81
+ {p.suffix !== undefined && <span data-part="suffix">{p.suffix}</span>}
82
+ {p.clearable && (
83
+ <button type="button" data-part="clear" tabindex="-1" aria-label={`Clear ${p.label}`}>
84
+ <XIcon />
85
+ </button>
86
+ )}
87
+ {p.end}
88
+ </div>
89
+ {message.value && fieldMessage(p, msg, problem)}
90
+ </div>
91
+ )
92
+ }
93
+
94
+ function fieldIcon(glyph: Model['glyph']) {
95
+ return (
96
+ <span data-part="icon" aria-hidden="true">
97
+ <span data-part="sweep-base">
98
+ <Icon name={glyph.value!} />
99
+ </span>
100
+ <span data-part="sweep">
101
+ <Icon name={glyph.value!} />
102
+ </span>
103
+ </span>
104
+ )
105
+ }
106
+
107
+ function fieldBody({
108
+ p,
109
+ id,
110
+ msg,
111
+ problem,
112
+ shell,
113
+ }: {
114
+ p: Model['p']
115
+ id: Model['id']
116
+ msg: Model['msg']
117
+ problem: Model['problem']
118
+ shell: Model['shell']
119
+ }) {
120
+ return (
121
+ <div
122
+ data-part="body"
123
+ role="group"
124
+ aria-labelledby={`${id}-l`}
125
+ aria-describedby={msg.value}
126
+ aria-invalid={problem.value ? 'true' : undefined}
127
+ >
128
+ {untrack(() => p.control(shell))}
129
+ </div>
130
+ )
131
+ }
132
+
133
+ function fieldMessage(p: Model['p'], msg: Model['msg'], problem: Model['problem']) {
134
+ return (
135
+ <div data-part="message" id={msg.value}>
136
+ {problem.value ? (
137
+ <span data-part="error" role="alert">
138
+ <AlertIcon />
139
+ <span>{problem.value}</span>
140
+ </span>
141
+ ) : (
142
+ p.hint !== undefined && <span data-part="hint">{p.hint}</span>
143
+ )}
144
+ {p.counter !== undefined && <span data-part="counter" aria-live="off"></span>}
145
+ </div>
146
+ )
147
+ }