@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,304 @@
1
+ import { ClockIcon, RefreshIcon, SparkleIcon, WifiIcon, WifiOffIcon } from '@kerf-js/veneer-icons'
2
+ import { announce, connView } from '@kerf-js/veneer-core'
3
+ import { derived, onCleanup, onMount, state, untrack, watch, type State } from '@kerf-js/core'
4
+ import { Button, type ButtonProps } from '../Button'
5
+ import { useCooldown } from './kit'
6
+ import '../styles'
7
+ import '@kerf-js/veneer-core/styles/flows/tokens.css'
8
+ import '@kerf-js/veneer-core/styles/flows/base.css'
9
+ import '@kerf-js/veneer-core/styles/flows/conn.css'
10
+ import '@kerf-js/veneer-core/styles/components/spinner.css'
11
+
12
+ type Live<T> = T | { readonly value: T } | (() => { readonly value: T } | T)
13
+
14
+ const read = <T,>(v: Live<T>): T => {
15
+ const x = typeof v === 'function' ? (v as () => { readonly value: T } | T)() : v
16
+ return x !== null && typeof x === 'object' && 'value' in x ? x.value : x
17
+ }
18
+ /** `online` from @kerf-js/core/browser, its result, or a boolean: a factory is called once. */
19
+ function liveOf<T>(get: () => Live<T>) {
20
+ const src = untrack(get)
21
+ const once = typeof src === 'function' ? untrack(() => (src as () => Live<T>)()) : undefined
22
+ return derived(() => (once !== undefined ? read<T>(once) : read<T>(get())))
23
+ }
24
+
25
+ const RECOVERED_S = 3
26
+ const LATER_MS = 30 * 60 * 1000
27
+
28
+ /** Props for ConnBanner. */
29
+ export interface ConnBannerProps {
30
+ /** `online` from `@kerf-js/core/browser`, its derived, or a boolean. */
31
+ online?: Live<boolean>
32
+ /** The `.live` state (07 §4.4): `live`, `connecting`, `reconnecting`, `offline`. */
33
+ state?: Live<string | undefined>
34
+ /** Schema hash mismatch (§5.4). */
35
+ stale?: Live<boolean | undefined>
36
+ /** A mutation failed because the contract changed: the Banner turns caution. */
37
+ contractFailed?: boolean
38
+ /** Seconds to the next try: Kerf's backoff. */
39
+ retryIn?: number
40
+ /** Adds Retry now, to try before the backoff runs out. */
41
+ onRetry?: () => void
42
+ /** Saved changes waiting to sync. */
43
+ changes?: number
44
+ /** Save drafts, then reload. */
45
+ onReload?: () => void
46
+ /** Later hides the stale banner for 30 minutes. */
47
+ onLater?: () => void
48
+ /** "A new version of {name} is ready". */
49
+ name?: string | undefined
50
+ }
51
+
52
+ const plural = (n: number) => (n === 1 ? '1 change' : `${n} changes`)
53
+
54
+ /**
55
+ * The connection and deploy banner under the shell header (09 §5.3, §5.4): offline with its retry countdown,
56
+ * reconnecting, "Back online" for 3s, a stale deploy with Reload and Later. Takes its state as props. Offline says so
57
+ * assertively once and back online politely once; the countdown itself is never announced. Needs a mounted <Toaster />.
58
+ */
59
+ export function ConnBanner({
60
+ online = true,
61
+ state: conn,
62
+ stale,
63
+ contractFailed,
64
+ retryIn,
65
+ onRetry,
66
+ changes = 0,
67
+ onReload,
68
+ onLater,
69
+ name = 'the app',
70
+ }: ConnBannerProps) {
71
+ const isOn = liveOf<boolean>(() => online)
72
+ const st = liveOf<string | undefined>(() => conn)
73
+ const old = liveOf<boolean | undefined>(() => stale)
74
+ const later = state(false)
75
+ const recovered = state(false)
76
+ const view = derived(() =>
77
+ connView({
78
+ online: isOn.value,
79
+ state: st.value,
80
+ stale: old.value && !later.value,
81
+ recovered: recovered.value,
82
+ }),
83
+ )
84
+ const backIn = useCooldown(
85
+ () => (recovered.value ? RECOVERED_S : undefined),
86
+ () => (recovered.value = false),
87
+ )
88
+ const retry = useCooldown(() => retryIn)
89
+ const postpone = connectionEffects({
90
+ view,
91
+ recovered,
92
+ later,
93
+ name: () => name,
94
+ onLater: () => onLater?.(),
95
+ })
96
+ return (
97
+ <>
98
+ {view.value && (
99
+ <div
100
+ data-scope="conn"
101
+ data-state={view.value === 'stale' && contractFailed ? 'limited' : view.value}
102
+ >
103
+ {view.value === 'offline' && (
104
+ <ConnOffline retryIn={retryIn} retry={retry} onRetry={onRetry} />
105
+ )}
106
+ {view.value === 'reconnecting' && (
107
+ <>
108
+ <span data-scope="spinner" aria-hidden="true"></span>
109
+ <span data-part="msg">
110
+ <b>Reconnecting…</b>{' '}
111
+ {changes > 0
112
+ ? `Sending ${plural(changes)}.`
113
+ : retryIn !== undefined
114
+ ? `Trying again in ${retry.value}s.`
115
+ : ''}
116
+ </span>
117
+ </>
118
+ )}
119
+ {view.value === 'online' && <ConnOnline changes={changes} backIn={backIn} />}
120
+ {view.value === 'stale' && (
121
+ <ConnStale
122
+ name={name}
123
+ contractFailed={contractFailed}
124
+ postpone={postpone}
125
+ onReload={onReload}
126
+ />
127
+ )}
128
+ </div>
129
+ )}
130
+ </>
131
+ )
132
+ }
133
+
134
+ function connectionEffects({
135
+ view,
136
+ recovered,
137
+ later,
138
+ name,
139
+ onLater,
140
+ }: {
141
+ view: { readonly value: ReturnType<typeof connView> }
142
+ recovered: State<boolean>
143
+ later: State<boolean>
144
+ name: () => string
145
+ onLater: () => void
146
+ }) {
147
+ let hide: ReturnType<typeof setTimeout> | undefined
148
+ onCleanup(() => clearTimeout(hide))
149
+ onMount(() => {
150
+ watch(
151
+ () => view.value,
152
+ (v, was) => {
153
+ if (v === 'offline')
154
+ announce(document, "You're offline. Changes are saved on this device.", true)
155
+ if (v === 'stale') announce(document, `A new version of ${untrack(name)} is ready.`)
156
+ if (was === 'offline' || was === 'reconnecting') {
157
+ if (v === undefined || v === 'stale') {
158
+ recovered.value = true
159
+ announce(document, 'Back online.')
160
+ }
161
+ }
162
+ },
163
+ )
164
+ })
165
+ return () => {
166
+ later.value = true
167
+ hide = setTimeout(() => (later.value = false), LATER_MS)
168
+ onLater()
169
+ }
170
+ }
171
+
172
+ /** Props for RateLimited. */
173
+ export interface RateLimitedProps {
174
+ /** Seconds, from the typed `RATE_LIMITED.retryAfter`: never a guess. */
175
+ retryAfter: number
176
+ title?: unknown
177
+ /** "You can run 5 exports a minute." */
178
+ description?: unknown
179
+ /** The action that hit the limit: disabled, labelled "Try again in 20s", and back by itself. */
180
+ trigger?: ButtonProps
181
+ /** Called when the wait is over and the action is back. */
182
+ onDone?: () => void
183
+ }
184
+
185
+ /** Rate limited (09 §5.5): a caution notice in place with a draining rail. Polite at start and end only; the numbers keep counting under reduced motion. */
186
+ export function RateLimited({
187
+ retryAfter,
188
+ title = 'Limit reached.',
189
+ description,
190
+ trigger,
191
+ onDone,
192
+ }: RateLimitedProps) {
193
+ const total = derived(() => retryAfter)
194
+ const left = useCooldown(
195
+ () => total.value,
196
+ () => {
197
+ announce(document, 'You can try again now.')
198
+ onDone?.()
199
+ },
200
+ )
201
+ const hasTrigger = derived(() => !!trigger)
202
+ const on = derived(() => left.value > 0)
203
+ onMount(() =>
204
+ announce(
205
+ document,
206
+ `${untrack(() => (typeof title === 'string' ? title : 'Limit reached.'))} Try again in ${untrack(() => total.value)}s.`,
207
+ ),
208
+ )
209
+ return (
210
+ <div data-scope="stack" style="--_gap:8px">
211
+ {on.value && (
212
+ <div data-scope="conn" data-state="limited">
213
+ <ClockIcon />
214
+ <span data-part="msg">
215
+ <b>{title}</b> {description} Try again in {left.value}s.
216
+ </span>
217
+ <span data-part="rail" data-on="" aria-hidden="true">
218
+ <span data-part="rail-fill" style={`--p:${left.value / total.value}`}></span>
219
+ </span>
220
+ </div>
221
+ )}
222
+ {hasTrigger.value && (
223
+ <div>
224
+ <Button {...trigger} disabled={on.value}>
225
+ {on.value ? `Try again in ${left.value}s` : trigger!.children}
226
+ </Button>
227
+ </div>
228
+ )}
229
+ </div>
230
+ )
231
+ }
232
+
233
+ function ConnOnline({
234
+ changes,
235
+ backIn,
236
+ }: {
237
+ changes: number
238
+ backIn: ReturnType<typeof useCooldown>
239
+ }) {
240
+ return (
241
+ <>
242
+ <WifiIcon />
243
+ <span data-part="msg">
244
+ <b>Back online.</b> {changes > 0 ? `${plural(changes)} synced.` : ''}
245
+ </span>
246
+ <span data-part="rail" data-on="" aria-hidden="true">
247
+ <span data-part="rail-fill" style={`--p:${backIn.value / RECOVERED_S}`}></span>
248
+ </span>
249
+ </>
250
+ )
251
+ }
252
+ function ConnStale({
253
+ name,
254
+ contractFailed,
255
+ postpone,
256
+ onReload,
257
+ }: {
258
+ name: string
259
+ contractFailed: ConnBannerProps['contractFailed']
260
+ postpone: () => void
261
+ onReload: ConnBannerProps['onReload']
262
+ }) {
263
+ return (
264
+ <>
265
+ <SparkleIcon />
266
+ <span data-part="msg">
267
+ <b>A new version of {name} is ready.</b>{' '}
268
+ {contractFailed ? 'Reload to finish saving.' : 'Reload to update; your draft is kept.'}
269
+ </span>
270
+ <Button emphasis="ghost" size="sm" tone="neutral" onClick={postpone}>
271
+ Later
272
+ </Button>
273
+ <Button size="sm" tone="info" onClick={onReload}>
274
+ <RefreshIcon />
275
+ Reload
276
+ </Button>
277
+ </>
278
+ )
279
+ }
280
+
281
+ function ConnOffline({
282
+ retryIn,
283
+ retry,
284
+ onRetry,
285
+ }: {
286
+ retryIn: ConnBannerProps['retryIn']
287
+ retry: ReturnType<typeof useCooldown>
288
+ onRetry: ConnBannerProps['onRetry']
289
+ }) {
290
+ return (
291
+ <>
292
+ <WifiOffIcon />
293
+ <span data-part="msg">
294
+ <b>You're offline.</b> Changes are saved on this device and sync when you reconnect.
295
+ </span>
296
+ {retryIn !== undefined && <span>Retrying in {retry.value}s</span>}
297
+ {onRetry && (
298
+ <Button emphasis="ghost" size="sm" tone="neutral" onClick={onRetry}>
299
+ Retry now
300
+ </Button>
301
+ )}
302
+ </>
303
+ )
304
+ }
@@ -0,0 +1,97 @@
1
+ import { stepFlow } from '@kerf-js/veneer-core'
2
+ import { derived, state, untrack, watch, type State } from '@kerf-js/core'
3
+ import { bindable } from '../Picker'
4
+ import { use } from '@kerf-js/veneer-core/kerf'
5
+ import '../styles'
6
+ import '@kerf-js/veneer-core/styles/flows/tokens.css'
7
+ import '@kerf-js/veneer-core/styles/flows/base.css'
8
+ import '@kerf-js/veneer-core/styles/flows/flow.css'
9
+
10
+ /** One step of a Flow. */
11
+ export interface FlowStep {
12
+ id: string
13
+ /** Announced on arrival ("Step 2 of 4, Shipping"), and the step's accessible name. */
14
+ label: string
15
+ /** The step's content: built when the step is first reached, then kept, so what was typed survives Back. */
16
+ render: () => unknown
17
+ }
18
+
19
+ /** Props for Flow. */
20
+ export interface FlowProps {
21
+ steps: FlowStep[]
22
+ /** The current step's id: a box, a value, or `defaultStep`. */
23
+ step?: State<string> | string
24
+ defaultStep?: string
25
+ onStepChange?: ((id: string) => void) | undefined
26
+ /** Mirror the step in the URL, one history entry a step: `true` for `?step=`, or the parameter's name. */
27
+ history?: boolean | string | undefined
28
+ /** The polite "Step 2 of 4, Shipping" (default true). */
29
+ announce?: boolean | undefined
30
+ [attr: string]: unknown
31
+ }
32
+
33
+ /** Built once, on first arrival: `open` only ever turns true, so nothing is rebuilt as other steps are reached. */
34
+ function Body({ open, render }: { open: boolean; render: () => unknown }) {
35
+ const on = derived(() => open)
36
+ return <>{on.value && render()}</>
37
+ }
38
+
39
+ /**
40
+ * The step machine (09 §1.1): steps stacked in one grid cell, so height follows the content. On a change the old step
41
+ * exits, the new one enters from the side it lies on, focus goes to its `[data-autofocus]` or title, the polite region
42
+ * says where you are, and `history` gives each step a URL. A step is live as soon as it mounts: motion never gates it.
43
+ */
44
+ export function Flow({
45
+ steps,
46
+ step,
47
+ defaultStep,
48
+ onStepChange,
49
+ history,
50
+ announce: speak,
51
+ ...rest
52
+ }: FlowProps) {
53
+ const list = untrack(() => steps)
54
+ const ids = list.map((s) => s.id)
55
+ const at = bindable<string>(
56
+ () => step,
57
+ () => defaultStep,
58
+ ids[0]!,
59
+ () => onStepChange && ((v) => onStepChange(v)),
60
+ )
61
+ const param = derived(() => (history === true ? 'step' : history || undefined))
62
+ const seen = state<ReadonlySet<string>>(new Set([untrack(() => at.value)]))
63
+ watch(
64
+ () => at.value,
65
+ (id) => {
66
+ if (!seen.value.has(id)) seen.value = new Set([...seen.value, id])
67
+ },
68
+ )
69
+ let root: HTMLDivElement | undefined
70
+ use(
71
+ stepFlow,
72
+ () => root,
73
+ () => ({
74
+ step: at.value,
75
+ steps: ids,
76
+ label: (id: string) => list.find((s) => s.id === id)?.label,
77
+ history: param.value,
78
+ announce: speak,
79
+ onStep: (id: string) => at.set(id),
80
+ }),
81
+ )
82
+ return (
83
+ <div ref={(n) => (root = n)} data-scope="flow" data-dir="forward" {...rest}>
84
+ {list.map((s) => (
85
+ <section
86
+ key={s.id}
87
+ data-part="step"
88
+ data-step={s.id}
89
+ data-state={at.value === s.id ? 'active' : undefined}
90
+ aria-label={s.label}
91
+ >
92
+ <Body open={seen.value.has(s.id)} render={s.render} />
93
+ </section>
94
+ ))}
95
+ </div>
96
+ )
97
+ }
@@ -0,0 +1,244 @@
1
+ import { DownloadIcon } from '@kerf-js/veneer-icons'
2
+ import { announce, copyText, mapFlowError } from '@kerf-js/veneer-core'
3
+ import { derived, state, type State } from '@kerf-js/core'
4
+ import { Button } from '../Button'
5
+ import { Checkbox } from '../Choice'
6
+ import { Input } from '../Field'
7
+ import { Modal } from '../Modal'
8
+ import { toast } from '../Toast'
9
+ import { Flow } from './Flow'
10
+ import { TextLink } from './kit'
11
+ import '@kerf-js/veneer-core/styles/layout/row.css'
12
+
13
+ /** Props for MfaSetup. */
14
+ export interface MfaSetupProps {
15
+ open: State<boolean>
16
+ /** The QR code: the app's SVG or image, with its own label. */
17
+ /** Brings its own light plate, like QRCode: a code must stay dark on light in every theme. */
18
+ qr?: unknown
19
+ /** The key for "Can't scan?". */
20
+ secret: string
21
+ /** Checks the code: throw, or resolve false, when it's wrong. */
22
+ onVerify: (code: string) => unknown
23
+ /** Backup codes, shown once verified. */
24
+ codes: string[]
25
+ /** Default: saves `backup-codes.txt`. */
26
+ onDownload?: (codes: string[]) => void
27
+ onDone?: () => void
28
+ }
29
+
30
+ const STEPS = {
31
+ scan: 'Step 1 of 3 · Scan the code with 1Password, Authy or Google Authenticator.',
32
+ verify: 'Step 2 of 3 · Enter the code the app shows now.',
33
+ codes: 'Step 3 of 3 · Save your backup codes.',
34
+ }
35
+
36
+ function save(codes: string[]) {
37
+ const a = document.createElement('a')
38
+ a.href = URL.createObjectURL(new Blob([codes.join('\n')], { type: 'text/plain' }))
39
+ a.download = 'backup-codes.txt'
40
+ a.click()
41
+ URL.revokeObjectURL(a.href)
42
+ }
43
+
44
+ /** MFA setup (09 §9, specimen `mfaSetup`): QR and key, confirm a code, backup codes; one dialog over a Flow. Finish waits for "I saved my backup codes". */
45
+ export function MfaSetup({ open, qr, secret, onVerify, codes, onDownload, onDone }: MfaSetupProps) {
46
+ const step = state<keyof typeof STEPS>('scan')
47
+ const code = state('')
48
+ const problem = state<string | undefined>(undefined)
49
+ const busy = state(false)
50
+ const saved = state(false)
51
+ const next = mfaNext({
52
+ step,
53
+ code,
54
+ problem,
55
+ busy,
56
+ open: () => open,
57
+ onVerify: (value) => onVerify(value()),
58
+ onDone: () => onDone?.(),
59
+ })
60
+ const label = derived(() => (step.value === 'codes' ? 'Finish' : 'Continue'))
61
+ return (
62
+ <Modal
63
+ open={open}
64
+ title="Set up an authenticator app"
65
+ description={STEPS[step.value]}
66
+ footer={
67
+ <>
68
+ <Button emphasis="frame" data-close="">
69
+ Cancel
70
+ </Button>
71
+ <Button
72
+ loading={busy.value}
73
+ disabled={step.value === 'codes' && !saved.value}
74
+ onClick={next}
75
+ >
76
+ {label.value}
77
+ </Button>
78
+ </>
79
+ }
80
+ >
81
+ <Flow
82
+ data-part="mfa"
83
+ step={step}
84
+ steps={[
85
+ {
86
+ id: 'scan',
87
+ label: 'scan',
88
+ render: () => <MfaScan qr={qr} secret={secret} />,
89
+ },
90
+ {
91
+ id: 'verify',
92
+ label: 'confirm',
93
+ render: () => <MfaVerify problem={problem} code={code} next={next} />,
94
+ },
95
+ {
96
+ id: 'codes',
97
+ label: 'backup codes',
98
+ render: () => <MfaCodes codes={codes} saved={saved} onDownload={onDownload} />,
99
+ },
100
+ ]}
101
+ />
102
+ </Modal>
103
+ )
104
+ }
105
+
106
+ async function copy(text: string) {
107
+ await copyText(document, text)
108
+ announce(document, 'Copied')
109
+ }
110
+
111
+ function mfaNext({
112
+ step,
113
+ code,
114
+ problem,
115
+ busy,
116
+ open,
117
+ onVerify,
118
+ onDone,
119
+ }: {
120
+ step: State<keyof typeof STEPS>
121
+ code: State<string>
122
+ problem: State<string | undefined>
123
+ busy: State<boolean>
124
+ open: () => MfaSetupProps['open']
125
+ onVerify: (value: () => string) => unknown
126
+ onDone: () => void
127
+ }) {
128
+ return async () => {
129
+ if (step.value === 'scan') {
130
+ step.value = 'verify'
131
+ return
132
+ }
133
+ if (step.value === 'codes') {
134
+ open().value = false
135
+ onDone()
136
+ return
137
+ }
138
+ if (!/^\d{6}$/.test(code.value)) {
139
+ problem.value = 'Enter the 6 digits from the app.'
140
+ return
141
+ }
142
+ busy.value = true
143
+ try {
144
+ if ((await onVerify(() => code.value)) === false)
145
+ problem.value = "That code didn't match. Use the newest one."
146
+ else {
147
+ problem.value = undefined
148
+ step.value = 'codes'
149
+ }
150
+ } catch (e) {
151
+ const m = mapFlowError(e)
152
+ if (m.surface === 'toast')
153
+ toast.show({ title: m.title, description: m.description, tone: 'critical' })
154
+ else problem.value = m.fields.code ?? m.title
155
+ } finally {
156
+ busy.value = false
157
+ }
158
+ }
159
+ }
160
+ function MfaScan({ qr, secret }: { qr: unknown; secret: string }) {
161
+ return (
162
+ <div data-scope="stack">
163
+ {qr}
164
+ <p>
165
+ Can't scan? Enter this key: <code>{secret}</code>{' '}
166
+ <TextLink onClick={() => copy(secret)}>Copy key</TextLink>
167
+ </p>
168
+ </div>
169
+ )
170
+ }
171
+ function MfaVerify({
172
+ problem,
173
+ code,
174
+ next,
175
+ }: {
176
+ problem: State<string | undefined>
177
+ code: State<string>
178
+ next: () => Promise<void>
179
+ }) {
180
+ return (
181
+ <form
182
+ novalidate
183
+ onSubmit={(e: SubmitEvent) => {
184
+ e.preventDefault()
185
+ void next()
186
+ }}
187
+ >
188
+ <Input
189
+ label="6-digit code from the app"
190
+ name="totp"
191
+ inputmode="numeric"
192
+ autocomplete="one-time-code"
193
+ maxlength="6"
194
+ hint=""
195
+ error={problem.value}
196
+ data-autofocus=""
197
+ onInput={(e) => (code.value = e.currentTarget.value)}
198
+ />
199
+ </form>
200
+ )
201
+ }
202
+ function MfaCodes({
203
+ codes,
204
+ saved,
205
+ onDownload,
206
+ }: {
207
+ codes: string[]
208
+ saved: State<boolean>
209
+ onDownload: MfaSetupProps['onDownload']
210
+ }) {
211
+ return (
212
+ <div data-scope="stack">
213
+ <p>
214
+ Each code works once if you lose your phone. Store them somewhere safe; you won't see them
215
+ again.
216
+ </p>
217
+ <ol data-part="codes" aria-label="Backup codes">
218
+ {codes.map((c) => (
219
+ <li key={c}>
220
+ <code>{c}</code>
221
+ </li>
222
+ ))}
223
+ </ol>
224
+ <div data-scope="row">
225
+ <Button emphasis="frame" size="sm" onClick={() => (onDownload ?? save)(codes)}>
226
+ {() => (
227
+ <>
228
+ <DownloadIcon />
229
+ Download
230
+ </>
231
+ )}
232
+ </Button>
233
+ <Button emphasis="ghost" tone="neutral" size="sm" onClick={() => copy(codes.join('\n'))}>
234
+ Copy all
235
+ </Button>
236
+ </div>
237
+ <Checkbox
238
+ onChange={(e: Event) => (saved.value = (e.currentTarget as HTMLInputElement).checked)}
239
+ >
240
+ I saved my backup codes
241
+ </Checkbox>
242
+ </div>
243
+ )
244
+ }