@processfocus/runtime-local 0.1.0-next.2 → 0.1.0-next.4

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 (332) hide show
  1. package/README.md +51 -253
  2. package/dist/authentication-server.mjs +52 -84
  3. package/dist/chunk-3wzp2sax.js +4806 -0
  4. package/dist/chunk-5kjvzbwr.js +512 -0
  5. package/dist/chunk-egeb4821.js +156 -0
  6. package/dist/chunk-q5v72erd.js +241 -0
  7. package/dist/{chunk-yhzbn4vx.js → chunk-wvbz0nmd.js} +19485 -34180
  8. package/dist/{chunk-352j1ayk.js → chunk-y8fnwbx0.js} +51781 -36259
  9. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +12 -12
  10. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +31 -21
  11. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +3 -0
  12. package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +1 -12
  13. package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/disconnect-form.tsx +57 -0
  14. package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/page.tsx +97 -0
  15. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +1 -1
  16. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +2 -0
  17. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +2 -0
  18. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
  19. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +3 -1
  20. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +2 -0
  21. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/client-layout.tsx +19 -0
  22. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/default.tsx +6 -0
  23. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/executions-client.tsx +1637 -0
  24. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +5 -7
  25. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +4 -1589
  26. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +1 -1
  27. package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +41 -33
  28. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +11 -17
  29. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +2 -0
  30. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
  31. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +169 -18
  32. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +21 -14
  33. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +36 -18
  34. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +22 -28
  35. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-load-error.tsx +49 -0
  36. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-schema-form.tsx +28 -0
  37. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/default.tsx +6 -0
  38. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +7 -16
  39. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +4 -6
  40. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +45 -142
  41. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +10 -20
  42. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +2 -0
  43. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +3 -0
  44. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-process-dialog.tsx +72 -0
  45. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh-provider.tsx +65 -0
  46. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +162 -16
  47. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.tsx +19 -0
  48. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +4 -9
  49. package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +4 -0
  50. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +15 -18
  51. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +12 -6
  52. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +7 -16
  53. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +26 -48
  54. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +4 -7
  55. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
  56. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client-layout.tsx +28 -0
  57. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +1 -3
  58. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +193 -117
  59. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/default.tsx +6 -0
  60. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +7 -9
  61. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +3 -0
  62. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +60 -204
  63. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +12 -51
  64. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +27 -4
  65. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +5 -4
  66. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +0 -5
  67. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +26 -19
  68. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +5 -2
  69. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +85 -9
  70. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +12 -1
  71. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +66 -4
  72. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +3 -0
  73. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +41 -13
  74. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +2 -0
  75. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +442 -365
  76. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +8 -2
  77. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/page.tsx +7 -0
  78. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +61 -43
  79. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +6 -67
  80. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers/page.tsx +7 -0
  81. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles/page.tsx +7 -0
  82. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +111 -189
  83. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-page.tsx +86 -0
  84. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +141 -256
  85. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +2 -0
  86. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +2 -0
  87. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/page.tsx +7 -0
  88. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +6 -4
  89. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +3 -0
  90. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +30 -9
  91. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +3 -1
  92. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
  93. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +2 -4
  94. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +3 -1
  95. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +47 -54
  96. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +37 -54
  97. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +1 -1
  98. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +3 -1
  99. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/default.tsx +6 -0
  100. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +3 -0
  101. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +4 -25
  102. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +4 -1315
  103. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/to-dos-client.tsx +1282 -0
  104. package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +81 -65
  105. package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +8 -2
  106. package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +0 -1
  107. package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +10 -5
  108. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +1 -3
  109. package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +0 -1
  110. package/dist/dashboard-source/apps/frontend/app/api/auth/revalidate-google/route.ts +68 -0
  111. package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +1 -3
  112. package/dist/dashboard-source/apps/frontend/app/api/dev/import-events/route.ts +69 -1
  113. package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +25 -7
  114. package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +1 -2
  115. package/dist/dashboard-source/apps/frontend/app/api/public/start/[address]/route.ts +49 -0
  116. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +4 -3
  117. package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +15 -4
  118. package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +14 -6
  119. package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +2 -1
  120. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +31 -18
  121. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +5 -1
  122. package/dist/dashboard-source/apps/frontend/app/login/page.tsx +4 -4
  123. package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +11 -6
  124. package/dist/dashboard-source/apps/frontend/app/login/passkey-help/page.tsx +67 -0
  125. package/dist/dashboard-source/apps/frontend/app/mcp/[[...endpoint]]/route.ts +44 -0
  126. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +44 -25
  127. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/form/page.tsx +10 -0
  128. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/layout.tsx +32 -0
  129. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-client.tsx +319 -0
  130. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-content.tsx +41 -0
  131. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page.tsx +10 -0
  132. package/dist/dashboard-source/apps/frontend/app/public.css +1 -1
  133. package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +17 -0
  134. package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +9 -15
  135. package/dist/dashboard-source/apps/frontend/components/Header.tsx +14 -8
  136. package/dist/dashboard-source/apps/frontend/components/anonymous-page-link.tsx +57 -0
  137. package/dist/dashboard-source/apps/frontend/components/anonymous-start-form.tsx +24 -0
  138. package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +21 -7
  139. package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +12 -7
  140. package/dist/dashboard-source/apps/frontend/components/browser-only.tsx +19 -0
  141. package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +0 -1
  142. package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +24 -13
  143. package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +22 -2
  144. package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +52 -45
  145. package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +0 -1
  146. package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +0 -1
  147. package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +38 -11
  148. package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +0 -1
  149. package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +26 -15
  150. package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +0 -1
  151. package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +5 -0
  152. package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +21 -10
  153. package/dist/dashboard-source/apps/frontend/hooks/use-process-draft.ts +173 -0
  154. package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +1 -3
  155. package/dist/dashboard-source/apps/frontend/lib/anonymous-page-form-values.ts +6 -0
  156. package/dist/dashboard-source/apps/frontend/lib/anonymous-page-server.ts +65 -0
  157. package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +9 -3
  158. package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +7 -340
  159. package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +2 -0
  160. package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +9 -7
  161. package/dist/dashboard-source/apps/frontend/lib/auth/google-revalidation.ts +111 -0
  162. package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +1 -1
  163. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +28 -30
  164. package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +10 -0
  165. package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +1 -0
  166. package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +4 -4
  167. package/dist/dashboard-source/apps/frontend/lib/auth/session-admission.ts +11 -7
  168. package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +27 -10
  169. package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -9
  170. package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +25 -3
  171. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +115 -23
  172. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +1 -8
  173. package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +6 -2
  174. package/dist/dashboard-source/apps/frontend/lib/collections/graphql-stream.ts +21 -1
  175. package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +3 -0
  176. package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +8 -2
  177. package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +16 -4
  178. package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +1 -1
  179. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-query-invalidation.tsx +66 -9
  180. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-refresh.ts +10 -6
  181. package/dist/dashboard-source/apps/frontend/lib/effect/navigation.ts +4 -0
  182. package/dist/dashboard-source/apps/frontend/lib/effect/page-runtime.ts +29 -0
  183. package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +18 -12
  184. package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +1 -1
  185. package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +19 -23
  186. package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +9 -12
  187. package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +12 -12
  188. package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +20 -18
  189. package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +32 -16
  190. package/dist/dashboard-source/apps/frontend/lib/embed-form-server.ts +35 -0
  191. package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +10 -103
  192. package/dist/dashboard-source/apps/frontend/lib/forms/invitation.ts +43 -0
  193. package/dist/dashboard-source/apps/frontend/lib/forms/provider-user.ts +64 -0
  194. package/dist/dashboard-source/apps/frontend/lib/frontend-form-loaders.ts +40 -0
  195. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +1 -33
  196. package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +123 -33
  197. package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +168 -30
  198. package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +1 -0
  199. package/dist/dashboard-source/apps/frontend/lib/graphql/anonymous-page.ts +27 -0
  200. package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +1 -0
  201. package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +34 -29
  202. package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +82 -10
  203. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +2 -5
  204. package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +25 -4
  205. package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +11 -0
  206. package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +13 -104
  207. package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +11 -4
  208. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +1 -3
  209. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +1 -0
  210. package/dist/dashboard-source/apps/frontend/lib/list-detail-selection.ts +54 -0
  211. package/dist/dashboard-source/apps/frontend/lib/mcp/executions.ts +110 -0
  212. package/dist/dashboard-source/apps/frontend/lib/mcp/list-writes.ts +395 -0
  213. package/dist/dashboard-source/apps/frontend/lib/mcp/lists.ts +263 -0
  214. package/dist/dashboard-source/apps/frontend/lib/mcp/oauth.ts +889 -0
  215. package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +50 -0
  216. package/dist/dashboard-source/apps/frontend/lib/mcp/processes.ts +436 -0
  217. package/dist/dashboard-source/apps/frontend/lib/mcp/read-tool.ts +72 -0
  218. package/dist/dashboard-source/apps/frontend/lib/mcp/result.ts +4 -0
  219. package/dist/dashboard-source/apps/frontend/lib/mcp/server.ts +71 -0
  220. package/dist/dashboard-source/apps/frontend/lib/mcp/store.ts +107 -0
  221. package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +260 -0
  222. package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +0 -1
  223. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +0 -5
  224. package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +0 -2
  225. package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +6 -4
  226. package/dist/dashboard-source/apps/frontend/lib/organisation-form-loaders.ts +4 -0
  227. package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +0 -1
  228. package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +39 -139
  229. package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +17 -16
  230. package/dist/dashboard-source/apps/frontend/lib/query-client.ts +0 -1
  231. package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +1 -77
  232. package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +3 -7
  233. package/dist/dashboard-source/apps/frontend/next.config.ts +33 -13
  234. package/dist/dashboard-source/apps/frontend/package.json +47 -47
  235. package/dist/dashboard-source/apps/frontend/proxy.ts +72 -14
  236. package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +0 -3
  237. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +165 -233
  238. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +4 -3
  239. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +111 -75
  240. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +14 -18
  241. package/dist/dashboard-source/modules/auth-policy/src/index.ts +1 -0
  242. package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +19 -37
  243. package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +33 -29
  244. package/dist/dashboard-source/modules/auth-policy/src/lib/policy-revision.ts +23 -0
  245. package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +24 -49
  246. package/dist/dashboard-source/modules/auth-session/src/index.ts +4 -0
  247. package/dist/dashboard-source/modules/auth-session/src/lib/project-subscription.ts +13 -0
  248. package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +10 -2
  249. package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +82 -8
  250. package/dist/dashboard-source/modules/auth-session/src/lib/workload-access.ts +48 -0
  251. package/dist/dashboard-source/modules/auth-session/src/lib/workload-audit.ts +52 -0
  252. package/dist/dashboard-source/modules/aws-common/src/index.ts +0 -1
  253. package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +6 -9
  254. package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +5 -3
  255. package/dist/dashboard-source/modules/form/src/index.ts +1 -10
  256. package/dist/dashboard-source/modules/form/src/lib/effect-schema-form.tsx +1271 -0
  257. package/dist/dashboard-source/modules/form/src/lib/form-actions.ts +26 -0
  258. package/dist/dashboard-source/modules/form/src/lib/form-prefill.tsx +79 -0
  259. package/dist/dashboard-source/modules/form/src/lib/initial-focus.ts +31 -0
  260. package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +18 -0
  261. package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +4 -0
  262. package/dist/dashboard-source/modules/form/src/lib/plugin-scripts.ts +26 -0
  263. package/dist/dashboard-source/modules/form/src/lib/registered-plugin-field.tsx +57 -0
  264. package/dist/dashboard-source/modules/form/src/lib/schema-lookup.tsx +124 -0
  265. package/dist/dashboard-source/modules/form/src/lib/schema-typeahead.tsx +522 -0
  266. package/dist/dashboard-source/modules/form/src/lib/validation-logic.ts +172 -0
  267. package/dist/dashboard-source/modules/form-schema/src/index.ts +4 -1
  268. package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +19 -14
  269. package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +13 -11
  270. package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +15 -13
  271. package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +14 -0
  272. package/dist/dashboard-source/modules/form-schema/src/lib/form-presentation.ts +33 -0
  273. package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +186 -80
  274. package/dist/dashboard-source/modules/form-schema/src/lib/number-from-string.ts +26 -0
  275. package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +8 -7
  276. package/dist/dashboard-source/modules/form-schema/src/lib/public-completion-correction.ts +7 -0
  277. package/dist/dashboard-source/modules/form-schema/src/lib/search-lookup-items.ts +27 -0
  278. package/dist/dashboard-source/modules/form-submission-schema/src/index.ts +5 -0
  279. package/dist/dashboard-source/modules/form-submission-schema/src/lib/executable-rules.ts +379 -0
  280. package/dist/dashboard-source/modules/form-submission-schema/src/lib/form-submission-schema.ts +475 -0
  281. package/dist/dashboard-source/modules/form-submission-schema/src/lib/json-schema.ts +58 -0
  282. package/dist/dashboard-source/modules/form-submission-schema/src/lib/schema-defaults.ts +158 -0
  283. package/dist/dashboard-source/modules/form-submission-schema/src/lib/submission-utils.ts +75 -0
  284. package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +46 -0
  285. package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +37 -30
  286. package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +9 -1
  287. package/dist/dashboard-source/modules/openauth/src/client.ts +25 -17
  288. package/dist/dashboard-source/modules/openauth/src/util.ts +16 -0
  289. package/dist/dashboard-source/modules/{aws-common/src/lib/project-balance-admission.ts → project-accounting/src/admission.ts} +4 -8
  290. package/dist/dashboard-source/modules/realtime-client/src/appsync-client.ts +377 -0
  291. package/dist/dashboard-source/modules/realtime-client/src/index.ts +5 -0
  292. package/dist/dashboard-source/modules/realtime-client/src/subscription-presence.ts +163 -0
  293. package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +6 -24
  294. package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +28 -21
  295. package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +25 -18
  296. package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +60 -10
  297. package/dist/dashboard-source/modules/shadcn-components/src/index.ts +18 -2
  298. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-calendar.tsx +93 -0
  299. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +147 -48
  300. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-time-display.tsx +273 -0
  301. package/dist/dashboard-source/modules/shadcn-components/src/lib/local-date-time-input.tsx +108 -0
  302. package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +237 -351
  303. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +2 -1
  304. package/dist/dashboard-source.json +47 -47
  305. package/dist/graphql-server.mjs +272 -200
  306. package/dist/job-worker-supervisor.mjs +262 -0
  307. package/dist/job-worker.mjs +234 -133
  308. package/dist/main.mjs +30 -6
  309. package/dist/prepare-dashboard.mjs +8 -8
  310. package/dist/resources/cedar/policies.cedar +80 -38
  311. package/dist/resources/cedar/schema.cedarschema +39 -21
  312. package/dist/resources/graphql-schema/rxdb.graphql +2 -0
  313. package/dist/resources/graphql-schema/system.graphql +191 -51
  314. package/package.json +63 -62
  315. package/dist/chunk-6ntmymmx.js +0 -85
  316. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +0 -20
  317. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +0 -105
  318. package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +0 -189
  319. package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +0 -79
  320. package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +0 -56
  321. package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +0 -152
  322. package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +0 -1421
  323. package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +0 -85
  324. package/dist/dashboard-source/modules/form/src/lib/walker.tsx +0 -1549
  325. package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +0 -440
  326. package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +0 -13
  327. package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +0 -336
  328. package/dist/dashboard-source/modules/form-rule/src/index.ts +0 -21
  329. package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +0 -531
  330. package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +0 -102
  331. package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +0 -121
  332. package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +0 -45
@@ -0,0 +1,1271 @@
1
+ "use client"
2
+
3
+ import type { StandardSchemaV1 } from "@standard-schema/spec"
4
+ import { useStore } from "@tanstack/react-form"
5
+ import { Schema, SchemaAST } from "effect"
6
+ import {
7
+ type ReactNode,
8
+ type RefObject,
9
+ useCallback,
10
+ useEffect,
11
+ useMemo,
12
+ useRef,
13
+ useState,
14
+ } from "react"
15
+ import {
16
+ type CalendarSlotCalendarMetadata,
17
+ FormAutoFocus,
18
+ FormCalendarSlotInput,
19
+ FormCheckboxGroupInput,
20
+ FormComponentPluginType,
21
+ FormDateInput,
22
+ FormDescription,
23
+ FormEmailInput,
24
+ FormLabel,
25
+ FormListInput,
26
+ FormLocalDateTimeInput,
27
+ FormLookupInput,
28
+ FormNumberInput,
29
+ FormPluginData,
30
+ FormRadioInput,
31
+ type FormRequestData,
32
+ FormStaticText,
33
+ FormSuggestionInput,
34
+ FormTextAreaInput,
35
+ LINK_TEXT_SYMBOL,
36
+ LINK_URL_SYMBOL,
37
+ STRUCTURAL_TYPE_SYMBOL,
38
+ TEXTBLOCK_CONTENT_SYMBOL,
39
+ fieldAnnotation,
40
+ hasFlattenAnnotation,
41
+ hasStructuralOnlyAnnotation,
42
+ isListFieldMetadata,
43
+ isReadOnlyField,
44
+ } from "../../../form-schema/src/index.ts"
45
+ import {
46
+ executableFields,
47
+ getSchemaDefaults,
48
+ prepareExecutableSubmission,
49
+ submissionSchemaSync,
50
+ } from "../../../form-submission-schema/src/index.ts"
51
+ import {
52
+ CalendarSlotField,
53
+ type CalendarSlotFieldItem,
54
+ DateField,
55
+ LocalDateTimeInput,
56
+ fieldContext,
57
+ formContext,
58
+ normalizeDateFieldValue,
59
+ useAppForm,
60
+ validateDateField,
61
+ } from "../../../shadcn-components/src/index.ts"
62
+ import { useLocalStorage } from "../hooks/use-local-storage.ts"
63
+ import type { FormActionsContext } from "./form-actions.ts"
64
+ import { FormPrefill } from "./form-prefill.tsx"
65
+ import { focusFirstEditableControl } from "./initial-focus.ts"
66
+ import { type LookupOptions, useLookup } from "./lookup-context.tsx"
67
+ import { RegisteredPluginField } from "./registered-plugin-field.tsx"
68
+ import { SchemaLookup } from "./schema-lookup.tsx"
69
+ import { type LocalLookupCache, SchemaTypeahead } from "./schema-typeahead.tsx"
70
+ import { customValidationLogic } from "./validation-logic.ts"
71
+
72
+ export type BrowserFormSchema = Schema.Struct<
73
+ Record<string, Schema.Codec<unknown, unknown>>
74
+ >
75
+ const literalChoices = (ast: SchemaAST.AST): string[] =>
76
+ ast._tag === "Union"
77
+ ? ast.types.flatMap(literalChoices)
78
+ : ast._tag === "Literal" && typeof ast.literal === "string"
79
+ ? [ast.literal]
80
+ : []
81
+
82
+ type SubmissionError = { readonly field: string; readonly message: string }
83
+
84
+ export function EffectSchemaForm({
85
+ schema,
86
+ stepPath,
87
+ lookupOptions,
88
+ requestData,
89
+ draftId,
90
+ defaultValues,
91
+ readOnlyCheckboxFields,
92
+ pluginConfiguration = {},
93
+ onDraftChange,
94
+ onSubmit,
95
+ children,
96
+ }: {
97
+ stepPath?: string | undefined
98
+ lookupOptions?: LookupOptions | undefined
99
+ schema: BrowserFormSchema
100
+ requestData?: FormRequestData | null | undefined
101
+ draftId?: string | undefined
102
+ pluginConfiguration?: Readonly<Record<string, unknown>>
103
+ defaultValues: Record<string, unknown>
104
+ readOnlyCheckboxFields?: readonly string[]
105
+ onDraftChange?: (
106
+ values: Record<string, unknown>,
107
+ clearLocalStorage: () => void,
108
+ ) => void
109
+ onSubmit: (
110
+ values: Record<string, unknown>,
111
+ ) => Promise<ReadonlyArray<SubmissionError> | undefined>
112
+ children: (
113
+ context: FormActionsContext,
114
+ validator: StandardSchemaV1,
115
+ ) => ReactNode
116
+ }) {
117
+ const [prefillReady, setPrefillReady] = useState<string | undefined>()
118
+ const readyRef = useRef<string | undefined>(undefined)
119
+ const onReady = useCallback((value: string | undefined) => {
120
+ readyRef.current = value
121
+ setPrefillReady(value)
122
+ }, [])
123
+ const formRef = useRef<HTMLFormElement>(null)
124
+ const unmatchedLookups = useRef(new Set<string>())
125
+ const localLookupCache = useRef<LocalLookupCache>(new Map())
126
+ const [lookupRevision, setLookupRevision] = useState(0)
127
+ const autoFocus = fieldAnnotation(schema.ast, FormAutoFocus) !== false
128
+ useEffect(() => {
129
+ const formElement = formRef.current
130
+ if (!formElement) return
131
+ return focusFirstEditableControl(formElement)
132
+ }, [])
133
+ const hasSubmittedSuccessfully = useRef(false)
134
+ const [savedValues, setSavedValues, clearLocalStorage] = useLocalStorage<
135
+ Record<string, unknown>
136
+ >(draftId, {})
137
+ const [initialValues] = useState(() => {
138
+ const schemaDefaults: Record<string, unknown> = getSchemaDefaults(
139
+ schema.fields,
140
+ )
141
+ return Object.fromEntries(
142
+ Object.entries({ ...defaultValues, ...savedValues }).map(
143
+ ([key, value]) => {
144
+ // Older defaults stored untouched checkboxes as empty strings.
145
+ if (value === "" && schemaDefaults[key] === false) {
146
+ const fallback = defaultValues[key]
147
+ return [key, typeof fallback === "boolean" ? fallback : false]
148
+ }
149
+ return [
150
+ key,
151
+ schema.fields[key] &&
152
+ fieldAnnotation(schema.fields[key].ast, FormDateInput) !== undefined
153
+ ? normalizeDateFieldValue(value)
154
+ : value,
155
+ ]
156
+ },
157
+ ),
158
+ )
159
+ })
160
+ const focusFirstError = () => {
161
+ requestAnimationFrame(() => {
162
+ const input = formRef.current?.querySelector<HTMLElement>(
163
+ '[aria-invalid="true"], [data-invalid-plugin="true"] :is(input:not([type="hidden"]):not([readonly]), textarea:not([readonly]), select, button, [tabindex]):not([disabled]):not([tabindex="-1"])',
164
+ )
165
+ input?.focus()
166
+ input?.scrollIntoView({ behavior: "smooth", block: "center" })
167
+ })
168
+ }
169
+ const validator = useMemo((): StandardSchemaV1<
170
+ Record<string, unknown>,
171
+ Record<string, unknown>
172
+ > => {
173
+ const base = Schema.toStandardSchemaV1(submissionSchemaSync(schema))
174
+ return {
175
+ "~standard": {
176
+ version: 1,
177
+ vendor: "processfocus",
178
+ validate: (input) => {
179
+ if (
180
+ typeof input !== "object" ||
181
+ input === null ||
182
+ Array.isArray(input)
183
+ )
184
+ return { issues: [{ message: "Expected form values" }] }
185
+ const values = Object.fromEntries(Object.entries(input))
186
+ const prepared = prepareExecutableSubmission(
187
+ schema,
188
+ values,
189
+ requestData?.originalValues ?? {},
190
+ requestData?.inaccessible,
191
+ )
192
+ const result = base["~standard"].validate(prepared.values)
193
+ if (result instanceof Promise)
194
+ throw new Error("Browser form checks must be synchronous")
195
+ const hidden = [
196
+ ...(requestData?.inaccessible ?? []),
197
+ ...executableFields(schema, values, requestData?.inaccessible)
198
+ .filter((field) => field.state.hidden)
199
+ .map((field) => field.path.join(".")),
200
+ ]
201
+ const issues = [
202
+ ...prepared.errors.map((error) => ({
203
+ message: error.message,
204
+ path: error.field.split("."),
205
+ })),
206
+ ...(result.issues ?? []).filter(
207
+ (issue) =>
208
+ !hidden.some((path) => {
209
+ const field = issue.path
210
+ ?.map((segment) =>
211
+ typeof segment === "object" ? segment.key : segment,
212
+ )
213
+ .join(".")
214
+ return field === path || field?.startsWith(`${path}.`)
215
+ }),
216
+ ),
217
+ ]
218
+ return issues.length ? { issues } : { value: prepared.values }
219
+ },
220
+ },
221
+ }
222
+ }, [schema, requestData?.originalValues, requestData?.inaccessible])
223
+ const [serverErrors, setServerErrors] = useState<
224
+ ReadonlyArray<SubmissionError>
225
+ >([])
226
+ const form = useAppForm({
227
+ defaultValues: initialValues,
228
+ validators: { onDynamic: validator },
229
+ validationLogic: customValidationLogic,
230
+ onSubmit: async ({ value }) => {
231
+ if (
232
+ requestData?.prefill &&
233
+ readyRef.current !== value[requestData.prefill.dependency]
234
+ ) {
235
+ setServerErrors([
236
+ { field: "", message: "Load the saved values before submitting." },
237
+ ])
238
+ return
239
+ }
240
+ // TanStack retains input values; Standard Schema's decoded output is validation only.
241
+ const prepared = prepareExecutableSubmission(
242
+ schema,
243
+ value,
244
+ requestData?.originalValues ?? {},
245
+ requestData?.inaccessible,
246
+ )
247
+ for (const field of requestData?.inaccessible ?? [])
248
+ delete prepared.values[field]
249
+ const errors = (await onSubmit(prepared.values)) ?? []
250
+ setServerErrors(errors)
251
+ for (const error of errors) {
252
+ if (error.field)
253
+ form.setFieldMeta(error.field, (meta) => ({
254
+ ...meta,
255
+ errorMap: { ...meta.errorMap, onSubmit: error.message },
256
+ }))
257
+ }
258
+ if (errors.length > 0) {
259
+ setLookupRevision((revision) => revision + 1)
260
+ focusFirstError()
261
+ } else {
262
+ hasSubmittedSuccessfully.current = true
263
+ clearLocalStorage()
264
+ }
265
+ },
266
+ onSubmitInvalid: focusFirstError,
267
+ listeners: {
268
+ onChange: ({ formApi }) => {
269
+ setServerErrors([])
270
+ if (!hasSubmittedSuccessfully.current) {
271
+ setSavedValues(formApi.state.values)
272
+ onDraftChange?.(formApi.state.values, clearLocalStorage)
273
+ }
274
+ },
275
+ },
276
+ })
277
+
278
+ const submissionAttempts = useStore(
279
+ form.store,
280
+ (state) => state.submissionAttempts,
281
+ )
282
+
283
+ const renderFields = (
284
+ ast: SchemaAST.AST,
285
+ values: Record<string, unknown>,
286
+ prefix = "",
287
+ targetPrefix = "",
288
+ inheritedDisabled = false,
289
+ ): ReactNode => {
290
+ const states = executableFields(schema, values, requestData?.inaccessible)
291
+ if (ast._tag !== "Objects")
292
+ throw new Error("Browser form groups must be structs")
293
+ return ast.propertySignatures.map((property) => {
294
+ const fieldSchema = Schema.make(property.type)
295
+ const path = prefix
296
+ ? `${prefix}.${String(property.name)}`
297
+ : String(property.name)
298
+ const target = targetPrefix
299
+ ? `${targetPrefix}.${String(property.name)}`
300
+ : String(property.name)
301
+ const state = states.find(
302
+ (field) => field.target.join(".") === target,
303
+ )?.state
304
+ if (
305
+ state?.hidden ||
306
+ requestData?.inaccessible.some(
307
+ (field) => path === field || path.startsWith(`${field}.`),
308
+ )
309
+ )
310
+ return null
311
+ const presentation = requestData?.presentation[target]
312
+ if (requestData?.prefill?.concealed.includes(path)) return null
313
+ const labelAnnotation =
314
+ presentation?.label ??
315
+ fieldAnnotation(property.type, FormLabel) ??
316
+ fieldAnnotation(property.type, "title")
317
+ const label =
318
+ state?.label ??
319
+ (typeof labelAnnotation === "string"
320
+ ? labelAnnotation
321
+ : (SchemaAST.resolveTitle(property.type) ?? String(property.name)))
322
+ const description =
323
+ presentation?.description ??
324
+ fieldAnnotation(property.type, FormDescription) ??
325
+ fieldAnnotation(property.type, "description")
326
+ if (hasStructuralOnlyAnnotation(fieldSchema)) {
327
+ const text =
328
+ presentation?.text ??
329
+ fieldAnnotation(property.type, FormStaticText) ??
330
+ fieldAnnotation(property.type, TEXTBLOCK_CONTENT_SYMBOL) ??
331
+ fieldAnnotation(property.type, LINK_TEXT_SYMBOL)
332
+ const href =
333
+ presentation?.href ?? fieldAnnotation(property.type, LINK_URL_SYMBOL)
334
+ if (
335
+ fieldAnnotation(property.type, STRUCTURAL_TYPE_SYMBOL) === "text-list"
336
+ ) {
337
+ if (typeof text !== "string" || !text.trim()) return null
338
+ const items = text.trim().split(/\r?\n\r?\n/)
339
+ return (
340
+ <section key={path} className="space-y-2">
341
+ <h3 className="font-semibold">{label}</h3>
342
+ <ul className="list-disc space-y-2 ps-5">
343
+ {items.map((item, index) => (
344
+ // biome-ignore lint/suspicious/noArrayIndexKey: static display items
345
+ <li key={index} className="whitespace-pre-line break-words">
346
+ {item}
347
+ </li>
348
+ ))}
349
+ </ul>
350
+ </section>
351
+ )
352
+ }
353
+ return typeof text === "string" ? (
354
+ typeof href === "string" && href ? (
355
+ <a key={path} href={href}>
356
+ {text}
357
+ </a>
358
+ ) : (
359
+ <p key={path}>{text}</p>
360
+ )
361
+ ) : null
362
+ }
363
+ const plugin = fieldAnnotation(property.type, FormComponentPluginType)
364
+ if (
365
+ typeof plugin === "object" &&
366
+ plugin !== null &&
367
+ "type" in plugin &&
368
+ typeof plugin.type === "string"
369
+ ) {
370
+ const pluginType = plugin.type
371
+ const staticData = fieldAnnotation(property.type, FormPluginData)
372
+ const runtimeData = pluginConfiguration[path]
373
+ const pluginData = {
374
+ ...(typeof staticData === "object" && staticData !== null
375
+ ? staticData
376
+ : {}),
377
+ ...(typeof runtimeData === "object" && runtimeData !== null
378
+ ? runtimeData
379
+ : {}),
380
+ }
381
+ return (
382
+ <form.Field key={path} name={path}>
383
+ {(field) => {
384
+ const showErrors =
385
+ submissionAttempts > 0 ||
386
+ (field.state.meta.isTouched && !field.state.meta.isDefaultValue)
387
+ const errors = !showErrors
388
+ ? []
389
+ : [
390
+ ...field.state.meta.errors.map((error) =>
391
+ typeof error === "string"
392
+ ? error
393
+ : (error?.message ?? "Invalid value"),
394
+ ),
395
+ ...serverErrors
396
+ .filter((error) => error.field === path)
397
+ .map((error) => error.message),
398
+ ]
399
+ return (
400
+ <div data-invalid-plugin={errors.length > 0}>
401
+ <RegisteredPluginField
402
+ form={{ AppField: form.Field, Subscribe: form.Subscribe }}
403
+ field={{
404
+ _tag: "plugin",
405
+ field: path,
406
+ label,
407
+ pluginType,
408
+ readonly: isReadOnlyField(fieldSchema),
409
+ ...(typeof description === "string" && { description }),
410
+ pluginData,
411
+ }}
412
+ options={stepPath === undefined ? {} : { stepPath }}
413
+ />
414
+ <div role="alert" className="text-sm text-rose-600">
415
+ {errors.join(" ")}
416
+ </div>
417
+ </div>
418
+ )
419
+ }}
420
+ </form.Field>
421
+ )
422
+ }
423
+ const checkboxAnnotation = fieldAnnotation(
424
+ property.type,
425
+ FormCheckboxGroupInput,
426
+ )
427
+ if (checkboxAnnotation !== undefined) {
428
+ const metadata = Schema.decodeUnknownSync(
429
+ Schema.Struct({
430
+ options: Schema.Array(
431
+ Schema.Struct({
432
+ value: Schema.String,
433
+ label: Schema.String,
434
+ description: Schema.optional(Schema.String),
435
+ }),
436
+ ),
437
+ }),
438
+ )(checkboxAnnotation)
439
+ return (
440
+ <form.Field key={path} name={path}>
441
+ {(field) => {
442
+ const selected = Schema.decodeUnknownSync(
443
+ Schema.Array(Schema.String),
444
+ )(field.state.value ?? [])
445
+ const options = [
446
+ ...new Map(
447
+ metadata.options.map((option) => [option.value, option]),
448
+ ).values(),
449
+ ]
450
+ const unavailable = [...new Set(selected)].filter(
451
+ (value) => !options.some((option) => option.value === value),
452
+ )
453
+ const errors =
454
+ submissionAttempts > 0 ||
455
+ (field.state.meta.isTouched && !field.state.meta.isDefaultValue)
456
+ ? field.state.meta.errors.map((error) =>
457
+ typeof error === "string"
458
+ ? error
459
+ : (error?.message ?? "Invalid value"),
460
+ )
461
+ : []
462
+ return (
463
+ <fieldset
464
+ className="space-y-2"
465
+ tabIndex={
466
+ options.length + unavailable.length === 0 ? -1 : undefined
467
+ }
468
+ aria-invalid={
469
+ options.length + unavailable.length === 0 &&
470
+ errors.length > 0
471
+ ? true
472
+ : undefined
473
+ }
474
+ disabled={
475
+ inheritedDisabled ||
476
+ state?.disabled === true ||
477
+ isReadOnlyField(fieldSchema) ||
478
+ Boolean(
479
+ requestData?.prefill?.fields.includes(path) &&
480
+ prefillReady !== values[requestData.prefill.dependency],
481
+ )
482
+ }
483
+ >
484
+ <legend className="text-sm font-medium">{label}</legend>
485
+ <p
486
+ id={`${path}-description`}
487
+ className="text-sm text-slate-500"
488
+ >
489
+ {typeof description === "string" ? description : null}
490
+ </p>
491
+ {[
492
+ ...options,
493
+ ...unavailable.map((value) => ({
494
+ value,
495
+ label: `${value} (unavailable)`,
496
+ description:
497
+ "This selection is no longer available. Uncheck to remove it.",
498
+ })),
499
+ ].map((option) => (
500
+ <label
501
+ key={option.value}
502
+ className="flex items-start gap-2"
503
+ >
504
+ <input
505
+ type="checkbox"
506
+ name={path}
507
+ value={option.value}
508
+ checked={selected.includes(option.value)}
509
+ aria-invalid={errors.length > 0}
510
+ aria-describedby={`${path}-description ${path}-errors`}
511
+ onBlur={field.handleBlur}
512
+ onChange={(event) => {
513
+ setServerErrors([])
514
+ field.handleChange(
515
+ event.target.checked
516
+ ? [...new Set([...selected, option.value])]
517
+ : selected.filter(
518
+ (value) => value !== option.value,
519
+ ),
520
+ )
521
+ }}
522
+ />
523
+ <span>
524
+ <span className="block font-medium">
525
+ {option.label}
526
+ </span>
527
+ <span className="block text-sm text-slate-500">
528
+ {option.description}
529
+ </span>
530
+ </span>
531
+ </label>
532
+ ))}
533
+ <div
534
+ id={`${path}-errors`}
535
+ role="alert"
536
+ className="text-sm text-rose-600"
537
+ >
538
+ {errors.join(" ")}
539
+ </div>
540
+ </fieldset>
541
+ )
542
+ }}
543
+ </form.Field>
544
+ )
545
+ }
546
+ const boolean =
547
+ property.type._tag === "Boolean" ||
548
+ (property.type._tag === "Union" &&
549
+ property.type.types.some((member) => member._tag === "Boolean"))
550
+ const readOnly = isReadOnlyField(fieldSchema)
551
+ if (readOnly && !(boolean && readOnlyCheckboxFields?.includes(path))) {
552
+ let value: unknown = defaultValues
553
+ for (const part of path.split("."))
554
+ value =
555
+ typeof value === "object" && value !== null
556
+ ? Reflect.get(value, part)
557
+ : undefined
558
+ return (
559
+ <fieldset
560
+ key={path}
561
+ className={
562
+ Array.isArray(value) || label === ""
563
+ ? "space-y-1"
564
+ : "grid grid-cols-[minmax(0,9rem)_minmax(0,1fr)] items-baseline gap-x-4"
565
+ }
566
+ >
567
+ {label !== "" && (
568
+ <label
569
+ htmlFor={path}
570
+ className="font-medium text-muted-foreground"
571
+ >
572
+ {label}
573
+ </label>
574
+ )}
575
+ {Array.isArray(value) ? (
576
+ value.length === 0 ? (
577
+ <p className="text-slate-400 dark:text-slate-500">&mdash;</p>
578
+ ) : (
579
+ <ul className="divide-y divide-slate-100 dark:divide-slate-800">
580
+ {value.map((item, index) => (
581
+ // Read-only display rows never reorder; the position is
582
+ // the only stable identity for repeated line entries.
583
+ // biome-ignore lint/suspicious/noArrayIndexKey: static rows
584
+ <li key={index} className="whitespace-pre-wrap py-1">
585
+ {String(item ?? "")}
586
+ </li>
587
+ ))}
588
+ </ul>
589
+ )
590
+ ) : fieldAnnotation(property.type, FormTextAreaInput) ? (
591
+ <p id={path} className="whitespace-pre-line break-words">
592
+ {String(value ?? "")}
593
+ </p>
594
+ ) : (
595
+ <input
596
+ id={path}
597
+ readOnly
598
+ value={String(value ?? "")}
599
+ className="min-w-0 w-full border-0 bg-transparent"
600
+ />
601
+ )}
602
+ </fieldset>
603
+ )
604
+ }
605
+ if (property.type._tag === "Objects") {
606
+ return (
607
+ <fieldset key={path} className="space-y-4">
608
+ {typeof labelAnnotation === "string" && (
609
+ <legend className="font-semibold">{label}</legend>
610
+ )}
611
+ {renderFields(
612
+ property.type,
613
+ values,
614
+ hasFlattenAnnotation(fieldSchema) ? prefix : path,
615
+ target,
616
+ inheritedDisabled || state?.disabled === true,
617
+ )}
618
+ </fieldset>
619
+ )
620
+ }
621
+ if (property.type._tag === "Arrays") {
622
+ const item = property.type.rest[0]
623
+ if (item?._tag !== "Objects")
624
+ throw new Error("Browser form lists must contain structs")
625
+ const metadata = fieldAnnotation(property.type, FormListInput)
626
+ const emptyItem = () =>
627
+ getSchemaDefaults(
628
+ Object.fromEntries(
629
+ item.propertySignatures.map((property) => [
630
+ String(property.name),
631
+ Schema.make(property.type),
632
+ ]),
633
+ ),
634
+ )
635
+ return (
636
+ <form.Field key={path} name={path} mode="array">
637
+ {(field) => (
638
+ <ExecutableList
639
+ label={label}
640
+ addButtonLabel={
641
+ isListFieldMetadata(metadata)
642
+ ? metadata.addButtonLabel
643
+ : undefined
644
+ }
645
+ count={
646
+ Array.isArray(field.state.value)
647
+ ? field.state.value.length
648
+ : 0
649
+ }
650
+ disabled={inheritedDisabled || state?.disabled === true}
651
+ onAdd={() =>
652
+ field.handleChange([
653
+ ...(Array.isArray(field.state.value)
654
+ ? field.state.value
655
+ : []),
656
+ emptyItem(),
657
+ ])
658
+ }
659
+ onRemove={(index) => field.removeValue(index)}
660
+ renderItem={(index) =>
661
+ renderFields(
662
+ item,
663
+ values,
664
+ `${path}[${index}]`,
665
+ target,
666
+ inheritedDisabled || state?.disabled === true,
667
+ )
668
+ }
669
+ />
670
+ )}
671
+ </form.Field>
672
+ )
673
+ }
674
+ const encoded = SchemaAST.toEncoded(property.type)
675
+ const choices = literalChoices(encoded)
676
+ const calendarAnnotation = fieldAnnotation(
677
+ property.type,
678
+ FormCalendarSlotInput,
679
+ )
680
+ const calendar =
681
+ calendarAnnotation === undefined
682
+ ? undefined
683
+ : Schema.decodeUnknownSync(
684
+ Schema.Struct({
685
+ timeZone: Schema.String,
686
+ locale: Schema.String,
687
+ emptyMessageHtml: Schema.optional(Schema.String),
688
+ loadErrorMessageHtml: Schema.optional(Schema.String),
689
+ calendar: Schema.optional(
690
+ Schema.Struct({
691
+ weekStartsOn: Schema.optional(
692
+ Schema.Literals([0, 1, 2, 3, 4, 5, 6]),
693
+ ),
694
+ businessDays: Schema.optional(
695
+ Schema.Array(Schema.Literals([0, 1, 2, 3, 4, 5, 6])),
696
+ ),
697
+ }),
698
+ ),
699
+ }),
700
+ )(calendarAnnotation)
701
+ const radioAnnotation = fieldAnnotation(property.type, FormRadioInput)
702
+ const radio =
703
+ radioAnnotation === undefined
704
+ ? undefined
705
+ : Schema.decodeUnknownSync(
706
+ Schema.Struct({
707
+ options: Schema.Array(
708
+ Schema.Struct({ value: Schema.String, label: Schema.String }),
709
+ ),
710
+ }),
711
+ )(radioAnnotation)
712
+ const numeric =
713
+ fieldAnnotation(property.type, FormNumberInput) !== undefined
714
+ const lookup =
715
+ fieldAnnotation(property.type, FormLookupInput) !== undefined
716
+ const date = fieldAnnotation(property.type, FormDateInput) !== undefined
717
+ const localDateTime =
718
+ fieldAnnotation(property.type, FormLocalDateTimeInput) === true
719
+ const email = fieldAnnotation(property.type, FormEmailInput) !== undefined
720
+ const textArea =
721
+ fieldAnnotation(property.type, FormTextAreaInput) !== undefined
722
+ const disabled =
723
+ inheritedDisabled ||
724
+ state?.disabled === true ||
725
+ Boolean(
726
+ requestData?.prefill?.fields.includes(path) &&
727
+ prefillReady !== values[requestData.prefill.dependency],
728
+ )
729
+ if (date) {
730
+ return (
731
+ <form.AppField
732
+ key={path}
733
+ name={path}
734
+ validators={{
735
+ onDynamic: ({ value }) =>
736
+ disabled ? undefined : validateDateField({ value }),
737
+ }}
738
+ >
739
+ {() => <DateField label={label} readOnly={disabled} />}
740
+ </form.AppField>
741
+ )
742
+ }
743
+ const lookupField = prefix.includes("[") ? String(property.name) : path
744
+ const lookupMetadata = fieldAnnotation(property.type, FormLookupInput)
745
+ if (
746
+ lookup &&
747
+ stepPath &&
748
+ typeof lookupMetadata === "object" &&
749
+ lookupMetadata !== null &&
750
+ "mode" in lookupMetadata &&
751
+ (lookupMetadata.mode === "server" || lookupMetadata.mode === "local")
752
+ ) {
753
+ return (
754
+ <form.AppField
755
+ key={path}
756
+ name={path}
757
+ validators={{
758
+ onDynamic: () =>
759
+ !disabled && unmatchedLookups.current.has(path)
760
+ ? { message: "Select an option from the suggestions." }
761
+ : undefined,
762
+ }}
763
+ >
764
+ {() => (
765
+ <SchemaTypeahead
766
+ stepPath={stepPath}
767
+ field={lookupField}
768
+ label={label}
769
+ disabled={disabled}
770
+ options={lookupOptions}
771
+ binding={requestData?.lookups?.[path]}
772
+ values={values}
773
+ local={
774
+ lookupMetadata.mode === "local" &&
775
+ "maxItems" in lookupMetadata &&
776
+ typeof lookupMetadata.maxItems === "number"
777
+ ? {
778
+ maxItems: lookupMetadata.maxItems,
779
+ cache: localLookupCache.current,
780
+ revision: lookupRevision,
781
+ }
782
+ : undefined
783
+ }
784
+ emptyValue={
785
+ property.type.context?.isOptional
786
+ ? undefined
787
+ : encoded._tag === "Union" &&
788
+ encoded.types.some((member) => member._tag === "Null")
789
+ ? null
790
+ : ""
791
+ }
792
+ onUnmatchedChange={(unmatched) => {
793
+ if (unmatched) unmatchedLookups.current.add(path)
794
+ else unmatchedLookups.current.delete(path)
795
+ }}
796
+ />
797
+ )}
798
+ </form.AppField>
799
+ )
800
+ }
801
+ if (lookup && stepPath) {
802
+ const freeText =
803
+ fieldAnnotation(property.type, FormSuggestionInput) === true
804
+ const emptyValue = property.type.context?.isOptional
805
+ ? undefined
806
+ : encoded._tag === "Union" &&
807
+ encoded.types.some((member) => member._tag === "Null")
808
+ ? null
809
+ : ""
810
+ return (
811
+ <form.AppField
812
+ key={path}
813
+ name={path}
814
+ validators={{
815
+ onDynamic: ({ value }) =>
816
+ !disabled &&
817
+ !freeText &&
818
+ (unmatchedLookups.current.has(path) ||
819
+ (emptyValue === "" && !value))
820
+ ? { message: "Select an option from the suggestions." }
821
+ : undefined,
822
+ }}
823
+ >
824
+ {() => (
825
+ <SchemaLookup
826
+ stepPath={stepPath}
827
+ field={lookupField}
828
+ allowFreeText={freeText}
829
+ emptyValue={emptyValue}
830
+ onUnmatchedChange={(unmatched) => {
831
+ if (unmatched) unmatchedLookups.current.add(path)
832
+ else unmatchedLookups.current.delete(path)
833
+ }}
834
+ binding={requestData?.lookups?.[path]}
835
+ values={values}
836
+ options={lookupOptions}
837
+ label={label}
838
+ disabled={disabled}
839
+ />
840
+ )}
841
+ </form.AppField>
842
+ )
843
+ }
844
+ return (
845
+ <form.Field key={path} name={path}>
846
+ {(field) => {
847
+ const showErrors =
848
+ submissionAttempts > 0 ||
849
+ (field.state.meta.isTouched && !field.state.meta.isDefaultValue)
850
+ const errors = !showErrors
851
+ ? []
852
+ : [
853
+ ...field.state.meta.errors.map((error) =>
854
+ choices.length > 0 && field.state.value === ""
855
+ ? "This field is required."
856
+ : typeof error === "string"
857
+ ? error
858
+ : (error?.message ?? "Invalid value"),
859
+ ),
860
+ ]
861
+ return (
862
+ <div className="space-y-1">
863
+ {!calendar && !boolean && !localDateTime && (
864
+ <label htmlFor={path} className="block text-sm font-medium">
865
+ {label}
866
+ </label>
867
+ )}
868
+ {calendar && stepPath ? (
869
+ <formContext.Provider value={form}>
870
+ <fieldContext.Provider value={field}>
871
+ <ExecutableCalendar
872
+ formRef={formRef}
873
+ stepPath={stepPath}
874
+ path={path}
875
+ options={lookupOptions}
876
+ metadata={calendar}
877
+ label={label}
878
+ description={
879
+ typeof description === "string"
880
+ ? description
881
+ : undefined
882
+ }
883
+ disabled={disabled}
884
+ />
885
+ </fieldContext.Provider>
886
+ </formContext.Provider>
887
+ ) : localDateTime ? (
888
+ <LocalDateTimeInput
889
+ id={path}
890
+ label={label}
891
+ value={
892
+ typeof field.state.value === "string"
893
+ ? field.state.value
894
+ : ""
895
+ }
896
+ disabled={disabled}
897
+ required={state?.required === true}
898
+ invalid={errors.length > 0}
899
+ describedBy={`${path}-description ${path}-errors`}
900
+ onBlur={field.handleBlur}
901
+ onChange={field.handleChange}
902
+ />
903
+ ) : radio ? (
904
+ <div
905
+ role="radiogroup"
906
+ aria-label={label}
907
+ aria-describedby={`${path}-description ${path}-errors`}
908
+ >
909
+ {radio.options.map((option) => (
910
+ <label
911
+ key={option.value}
912
+ className="flex items-center gap-2"
913
+ >
914
+ <input
915
+ type="radio"
916
+ name={path}
917
+ value={option.value}
918
+ checked={field.state.value === option.value}
919
+ disabled={disabled}
920
+ aria-invalid={errors.length > 0}
921
+ onBlur={field.handleBlur}
922
+ onChange={() => {
923
+ setServerErrors([])
924
+ field.handleChange(option.value)
925
+ }}
926
+ />
927
+ {option.label}
928
+ </label>
929
+ ))}
930
+ </div>
931
+ ) : choices.length > 0 ? (
932
+ <select
933
+ id={path}
934
+ name={path}
935
+ disabled={disabled}
936
+ aria-required={state?.required}
937
+ className="w-full rounded-md border bg-transparent px-3 py-2"
938
+ value={
939
+ typeof field.state.value === "string"
940
+ ? field.state.value
941
+ : ""
942
+ }
943
+ onBlur={field.handleBlur}
944
+ onChange={(event) => {
945
+ setServerErrors([])
946
+ field.handleChange(
947
+ event.target.value === ""
948
+ ? property.type.context?.isOptional
949
+ ? undefined
950
+ : encoded._tag === "Union" &&
951
+ encoded.types.some(
952
+ (member) =>
953
+ member._tag === "Literal" &&
954
+ member.literal === null,
955
+ )
956
+ ? null
957
+ : ""
958
+ : event.target.value,
959
+ )
960
+ }}
961
+ aria-invalid={errors.length > 0}
962
+ aria-describedby={`${path}-errors`}
963
+ >
964
+ <option value="">Select an option</option>
965
+ {choices.map((choice) => (
966
+ <option key={choice} value={choice}>
967
+ {choice}
968
+ </option>
969
+ ))}
970
+ </select>
971
+ ) : textArea ? (
972
+ <textarea
973
+ id={path}
974
+ name={path}
975
+ disabled={disabled}
976
+ aria-required={state?.required}
977
+ className="min-h-24 w-full rounded-md border border-slate-300 bg-transparent px-3 py-2 dark:border-slate-600"
978
+ value={
979
+ typeof field.state.value === "string"
980
+ ? field.state.value
981
+ : ""
982
+ }
983
+ onBlur={field.handleBlur}
984
+ onChange={(event) => {
985
+ setServerErrors([])
986
+ field.handleChange(event.target.value)
987
+ }}
988
+ aria-invalid={errors.length > 0}
989
+ aria-describedby={`${path}-description ${path}-errors`}
990
+ />
991
+ ) : boolean ? (
992
+ <div className="flex items-start gap-2">
993
+ <input
994
+ id={path}
995
+ name={path}
996
+ type="checkbox"
997
+ className={
998
+ "peer mt-0.5 size-4 shrink-0 " +
999
+ "disabled:grid disabled:appearance-none disabled:place-content-center disabled:rounded-[4px] disabled:border disabled:border-muted-foreground disabled:bg-muted disabled:text-muted-foreground disabled:cursor-not-allowed " +
1000
+ "disabled:checked:before:h-2 disabled:checked:before:w-1 disabled:checked:before:-translate-y-px disabled:checked:before:rotate-45 disabled:checked:before:border-r-2 disabled:checked:before:border-b-2 disabled:checked:before:border-current " +
1001
+ "forced-colors:disabled:appearance-auto forced-colors:disabled:checked:before:hidden"
1002
+ }
1003
+ disabled={readOnly || disabled}
1004
+ aria-required={state?.required}
1005
+ checked={field.state.value === true}
1006
+ onBlur={field.handleBlur}
1007
+ onChange={(event) => {
1008
+ setServerErrors([])
1009
+ field.handleChange(event.target.checked)
1010
+ }}
1011
+ aria-invalid={errors.length > 0}
1012
+ aria-describedby={`${path}-description ${path}-errors`}
1013
+ />
1014
+ <label
1015
+ htmlFor={path}
1016
+ className="min-w-0 text-sm font-medium peer-disabled:text-muted-foreground"
1017
+ >
1018
+ {label}
1019
+ </label>
1020
+ </div>
1021
+ ) : (
1022
+ <input
1023
+ id={path}
1024
+ name={path}
1025
+ type={email ? "email" : "text"}
1026
+ disabled={disabled}
1027
+ aria-required={state?.required}
1028
+ inputMode={numeric ? "decimal" : "text"}
1029
+ className="w-full rounded-md border border-slate-300 bg-transparent px-3 py-2 dark:border-slate-600"
1030
+ value={
1031
+ typeof field.state.value === "string" ||
1032
+ typeof field.state.value === "number"
1033
+ ? field.state.value
1034
+ : ""
1035
+ }
1036
+ onBlur={field.handleBlur}
1037
+ onChange={(event) => {
1038
+ setServerErrors([])
1039
+ field.handleChange(event.target.value)
1040
+ }}
1041
+ aria-invalid={errors.length > 0}
1042
+ aria-describedby={`${path}-description ${path}-errors`}
1043
+ />
1044
+ )}
1045
+ {!calendar && (
1046
+ <p
1047
+ id={`${path}-description`}
1048
+ className="text-sm text-slate-500"
1049
+ >
1050
+ {typeof description === "string" ? description : null}
1051
+ </p>
1052
+ )}
1053
+ <div
1054
+ id={`${path}-errors`}
1055
+ role="alert"
1056
+ className="text-sm text-rose-600"
1057
+ >
1058
+ {errors.join(" ")}
1059
+ </div>
1060
+ </div>
1061
+ )
1062
+ }}
1063
+ </form.Field>
1064
+ )
1065
+ })
1066
+ }
1067
+
1068
+ return (
1069
+ <form.AppForm>
1070
+ <form
1071
+ ref={formRef}
1072
+ // Shared with deferred calendar focus after its slots load.
1073
+ data-autofocus={autoFocus ? undefined : "false"}
1074
+ className="space-y-6"
1075
+ onSubmit={(event) => {
1076
+ event.preventDefault()
1077
+ event.stopPropagation()
1078
+ void form.handleSubmit()
1079
+ }}
1080
+ >
1081
+ {requestData?.prefill && (
1082
+ <form.Subscribe
1083
+ selector={(state) =>
1084
+ state.values[requestData.prefill?.dependency ?? ""]
1085
+ }
1086
+ >
1087
+ {(value) =>
1088
+ requestData.prefill && (
1089
+ <FormPrefill
1090
+ form={form}
1091
+ config={requestData.prefill}
1092
+ value={value}
1093
+ onReady={onReady}
1094
+ />
1095
+ )
1096
+ }
1097
+ </form.Subscribe>
1098
+ )}
1099
+ <form.Subscribe
1100
+ selector={(state) =>
1101
+ [
1102
+ state.values,
1103
+ state.submissionAttempts,
1104
+ state.isSubmitting,
1105
+ ] as const
1106
+ }
1107
+ >
1108
+ {([values, , isSubmitting]) => (
1109
+ <fieldset disabled={isSubmitting} className="space-y-6">
1110
+ {renderFields(schema.ast, values)}
1111
+ </fieldset>
1112
+ )}
1113
+ </form.Subscribe>
1114
+ {serverErrors
1115
+ .filter((error) => !error.field)
1116
+ .map((error) => (
1117
+ <p
1118
+ key={error.message}
1119
+ role="alert"
1120
+ className="text-sm text-rose-600"
1121
+ >
1122
+ {error.message}
1123
+ </p>
1124
+ ))}
1125
+ <form.Subscribe selector={(state) => state}>
1126
+ {(state) =>
1127
+ children(
1128
+ {
1129
+ formState: {
1130
+ isSubmittingRequest: state.isSubmitting,
1131
+ isSubmitting:
1132
+ state.isSubmitting ||
1133
+ Boolean(
1134
+ requestData?.prefill &&
1135
+ (!prefillReady ||
1136
+ prefillReady !==
1137
+ state.values[requestData.prefill.dependency]),
1138
+ ),
1139
+ isPristine: state.isPristine,
1140
+ values: state.values,
1141
+ },
1142
+ clearLocalStorage,
1143
+ },
1144
+ validator,
1145
+ )
1146
+ }
1147
+ </form.Subscribe>
1148
+ </form>
1149
+ </form.AppForm>
1150
+ )
1151
+ }
1152
+
1153
+ /** Stable row identities keep lookup state with its student when earlier rows are removed. */
1154
+ function ExecutableList({
1155
+ label,
1156
+ addButtonLabel,
1157
+ count,
1158
+ disabled,
1159
+ onAdd,
1160
+ onRemove,
1161
+ renderItem,
1162
+ }: {
1163
+ label: string
1164
+ addButtonLabel: string | undefined
1165
+ count: number
1166
+ disabled: boolean
1167
+ onAdd: () => void
1168
+ onRemove: (index: number) => void
1169
+ renderItem: (index: number) => ReactNode
1170
+ }) {
1171
+ const [keys, setKeys] = useState(() =>
1172
+ Array.from({ length: count }, (_, index) => index),
1173
+ )
1174
+ const nextKey = useRef(count)
1175
+ return (
1176
+ <fieldset disabled={disabled} className="space-y-4">
1177
+ <legend className="font-semibold">{label}</legend>
1178
+ {Array.from({ length: count }, (_, index) => (
1179
+ <div key={keys[index]} className="space-y-4 rounded-md border p-4">
1180
+ {renderItem(index)}
1181
+ <button
1182
+ type="button"
1183
+ onClick={() => {
1184
+ setKeys((keys) => keys.filter((_, row) => row !== index))
1185
+ onRemove(index)
1186
+ }}
1187
+ >
1188
+ Remove
1189
+ </button>
1190
+ </div>
1191
+ ))}
1192
+ <button
1193
+ type="button"
1194
+ onClick={() => {
1195
+ const key = nextKey.current++
1196
+ setKeys((keys) => [...keys, key])
1197
+ onAdd()
1198
+ }}
1199
+ >
1200
+ {addButtonLabel ?? `Add ${label.toLowerCase()}`}
1201
+ </button>
1202
+ </fieldset>
1203
+ )
1204
+ }
1205
+
1206
+ function ExecutableCalendar({
1207
+ formRef,
1208
+ stepPath,
1209
+ path,
1210
+ options,
1211
+ metadata,
1212
+ label,
1213
+ description,
1214
+ disabled,
1215
+ }: {
1216
+ formRef: RefObject<HTMLFormElement | null>
1217
+ stepPath: string
1218
+ path: string
1219
+ options: LookupOptions | undefined
1220
+ metadata: {
1221
+ readonly timeZone: string
1222
+ readonly locale: string
1223
+ readonly emptyMessageHtml?: string | undefined
1224
+ readonly loadErrorMessageHtml?: string | undefined
1225
+ readonly calendar?: CalendarSlotCalendarMetadata | undefined
1226
+ }
1227
+ label: string
1228
+ description: string | undefined
1229
+ disabled: boolean
1230
+ }) {
1231
+ const service = useLookup()
1232
+ const [slots, setSlots] = useState<CalendarSlotFieldItem[]>([])
1233
+ const [status, setStatus] = useState<"loading" | "ready" | "error">("loading")
1234
+ const [attempt, retry] = useState(0)
1235
+ useEffect(() => {
1236
+ if (status !== "ready" || !formRef.current) return
1237
+ return focusFirstEditableControl(formRef.current)
1238
+ }, [status, formRef])
1239
+ useEffect(() => {
1240
+ let active = true
1241
+ void attempt // A retry intentionally repeats the token-scoped request.
1242
+ if (disabled) return
1243
+ setStatus("loading")
1244
+ service
1245
+ .fetchCalendarSlots(stepPath, path, options)
1246
+ .then((items) => {
1247
+ if (active) {
1248
+ setSlots(items)
1249
+ setStatus("ready")
1250
+ }
1251
+ })
1252
+ .catch(() => {
1253
+ if (active) setStatus("error")
1254
+ })
1255
+ return () => {
1256
+ active = false
1257
+ }
1258
+ }, [service, stepPath, path, options, attempt, disabled])
1259
+ return (
1260
+ <CalendarSlotField
1261
+ {...metadata}
1262
+ label={label}
1263
+ descriptionHtml={description}
1264
+ slots={slots}
1265
+ loading={status === "loading"}
1266
+ error={status === "error"}
1267
+ readOnly={disabled}
1268
+ onRetry={() => retry((value) => value + 1)}
1269
+ />
1270
+ )
1271
+ }