@processfocus/runtime-local 0.1.0-next.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 (470) hide show
  1. package/LICENSE.md +28 -0
  2. package/README.md +290 -0
  3. package/dist/authentication-server.mjs +188 -0
  4. package/dist/chunk-2sb4v2sx.js +70 -0
  5. package/dist/chunk-9weqs8n8.js +56031 -0
  6. package/dist/chunk-mvkr77wp.js +54113 -0
  7. package/dist/chunk-tkn4cnc8.js +453 -0
  8. package/dist/chunk-vpsm84e8.js +85 -0
  9. package/dist/dashboard-source/apps/frontend/app/%5Fpf/app-icons/[...path]/route.ts +63 -0
  10. package/dist/dashboard-source/apps/frontend/app/%5Fpf/health/page.tsx +19 -0
  11. package/dist/dashboard-source/apps/frontend/app/%5Fpf/public-form-branding/[...path]/route.ts +95 -0
  12. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +248 -0
  13. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +751 -0
  14. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +46 -0
  15. package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +375 -0
  16. package/dist/dashboard-source/apps/frontend/app/(protected)/client.tsx +14 -0
  17. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +73 -0
  18. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +20 -0
  19. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +22 -0
  20. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
  21. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +11 -0
  22. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +23 -0
  23. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/abandon-execution-dialog.tsx +137 -0
  24. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/execution-card-menu.tsx +233 -0
  25. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +19 -0
  26. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +1549 -0
  27. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-dialog.tsx +91 -0
  28. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-modal-client.tsx +33 -0
  29. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +31 -0
  30. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-route-fallback.tsx +18 -0
  31. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/restart-execution-feedback.tsx +40 -0
  32. package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +129 -0
  33. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +215 -0
  34. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +23 -0
  35. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
  36. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +678 -0
  37. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/loading.tsx +10 -0
  38. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +228 -0
  39. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +147 -0
  40. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +246 -0
  41. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +71 -0
  42. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +22 -0
  43. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +315 -0
  44. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +259 -0
  45. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +46 -0
  46. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +14 -0
  47. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-detail-title.ts +20 -0
  48. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +26 -0
  49. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +20 -0
  50. package/dist/dashboard-source/apps/frontend/app/(protected)/loading.tsx +5 -0
  51. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/org-chart-client.tsx +74 -0
  52. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +120 -0
  53. package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +13 -0
  54. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +188 -0
  55. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +33 -0
  56. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +320 -0
  57. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +152 -0
  58. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +41 -0
  59. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
  60. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +33 -0
  61. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +105 -0
  62. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-submit-button.tsx +81 -0
  63. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +282 -0
  64. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +21 -0
  65. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/lib/mobile-process-catalog.ts +28 -0
  66. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/lib/start-process-actions.ts +13 -0
  67. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/loading.tsx +10 -0
  68. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +5 -0
  69. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +504 -0
  70. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +153 -0
  71. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +39 -0
  72. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/loading.tsx +20 -0
  73. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +131 -0
  74. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/process-documentation.tsx +209 -0
  75. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/use-workflow-auto-refresh.ts +120 -0
  76. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +319 -0
  77. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +98 -0
  78. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/loading.tsx +1 -0
  79. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +100 -0
  80. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/access-handbook.tsx +110 -0
  81. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/authorization-loading.tsx +25 -0
  82. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/authorization-tabs.tsx +47 -0
  83. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +261 -0
  84. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-helpers.ts +17 -0
  85. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-source.tsx +34 -0
  86. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +79 -0
  87. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/evaluate-cedar.ts +43 -0
  88. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +526 -0
  89. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +23 -0
  90. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-cedar.ts +174 -0
  91. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +390 -0
  92. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/org-data.ts +70 -0
  93. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +22 -0
  94. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +594 -0
  95. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-skeleton.tsx +48 -0
  96. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +5 -0
  97. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +186 -0
  98. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +69 -0
  99. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers-table.tsx +48 -0
  100. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles-table.tsx +62 -0
  101. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +244 -0
  102. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +329 -0
  103. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +21 -0
  104. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +39 -0
  105. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +82 -0
  106. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/error.tsx +34 -0
  107. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/not-found.tsx +13 -0
  108. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +84 -0
  109. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/stats-data-fetcher.tsx +93 -0
  110. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +143 -0
  111. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +50 -0
  112. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
  113. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +131 -0
  114. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +50 -0
  115. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +172 -0
  116. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +233 -0
  117. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +26 -0
  118. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +58 -0
  119. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +14 -0
  120. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +154 -0
  121. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +1317 -0
  122. package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +259 -0
  123. package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +127 -0
  124. package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +49 -0
  125. package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +33 -0
  126. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/auth-options/route.ts +79 -0
  127. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/auth-verify/route.ts +142 -0
  128. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/register/route.ts +103 -0
  129. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/register-verify/route.ts +136 -0
  130. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/registration-session/route.ts +129 -0
  131. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +153 -0
  132. package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +122 -0
  133. package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +177 -0
  134. package/dist/dashboard-source/apps/frontend/app/api/dev/import-completed/route.ts +22 -0
  135. package/dist/dashboard-source/apps/frontend/app/api/dev/import-events/route.ts +38 -0
  136. package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +266 -0
  137. package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +118 -0
  138. package/dist/dashboard-source/apps/frontend/app/api/embed/test-host/route.ts +125 -0
  139. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/calendar-slots/route.ts +44 -0
  140. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/complete/route.ts +56 -0
  141. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +61 -0
  142. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/request-fresh-link/route.ts +41 -0
  143. package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +61 -0
  144. package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +100 -0
  145. package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +261 -0
  146. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +393 -0
  147. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/loading.tsx +13 -0
  148. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +51 -0
  149. package/dist/dashboard-source/apps/frontend/app/embed/embedded.css +48 -0
  150. package/dist/dashboard-source/apps/frontend/app/embed/layout.tsx +15 -0
  151. package/dist/dashboard-source/apps/frontend/app/global.css +13 -0
  152. package/dist/dashboard-source/apps/frontend/app/layout.tsx +102 -0
  153. package/dist/dashboard-source/apps/frontend/app/login/layout.tsx +9 -0
  154. package/dist/dashboard-source/apps/frontend/app/login/login-button.tsx +35 -0
  155. package/dist/dashboard-source/apps/frontend/app/login/login-form-content.tsx +117 -0
  156. package/dist/dashboard-source/apps/frontend/app/login/login-form.tsx +30 -0
  157. package/dist/dashboard-source/apps/frontend/app/login/page.tsx +52 -0
  158. package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +226 -0
  159. package/dist/dashboard-source/apps/frontend/app/login/secret-login-form.tsx +91 -0
  160. package/dist/dashboard-source/apps/frontend/app/manifest.ts +7 -0
  161. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/error.tsx +63 -0
  162. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/layout.tsx +34 -0
  163. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/page.tsx +129 -0
  164. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-card.tsx +42 -0
  165. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-context.tsx +27 -0
  166. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-html.tsx +40 -0
  167. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +553 -0
  168. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-state-content.tsx +27 -0
  169. package/dist/dashboard-source/apps/frontend/app/public.css +33 -0
  170. package/dist/dashboard-source/apps/frontend/app/register/passkey/layout.tsx +49 -0
  171. package/dist/dashboard-source/apps/frontend/app/register/passkey/page.tsx +36 -0
  172. package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +292 -0
  173. package/dist/dashboard-source/apps/frontend/app/theme.css +117 -0
  174. package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +693 -0
  175. package/dist/dashboard-source/apps/frontend/components/Header.tsx +481 -0
  176. package/dist/dashboard-source/apps/frontend/components/OrgUnitNode.tsx +41 -0
  177. package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +245 -0
  178. package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +158 -0
  179. package/dist/dashboard-source/apps/frontend/components/collections/collection-table-card.tsx +218 -0
  180. package/dist/dashboard-source/apps/frontend/components/collections/collection-table-header-row.tsx +97 -0
  181. package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +27 -0
  182. package/dist/dashboard-source/apps/frontend/components/copy-button.tsx +40 -0
  183. package/dist/dashboard-source/apps/frontend/components/dashboard-activity.tsx +35 -0
  184. package/dist/dashboard-source/apps/frontend/components/dashboard-skeleton.tsx +17 -0
  185. package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +21 -0
  186. package/dist/dashboard-source/apps/frontend/components/feature-permissions-provider.tsx +28 -0
  187. package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +66 -0
  188. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-host.tsx +27 -0
  189. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-identify.tsx +33 -0
  190. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-provider.tsx +55 -0
  191. package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +378 -0
  192. package/dist/dashboard-source/apps/frontend/components/mobile-home-switchboard.tsx +98 -0
  193. package/dist/dashboard-source/apps/frontend/components/mocks-provider.tsx +27 -0
  194. package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +137 -0
  195. package/dist/dashboard-source/apps/frontend/components/org-settings-provider.tsx +26 -0
  196. package/dist/dashboard-source/apps/frontend/components/process-workflow-link.tsx +36 -0
  197. package/dist/dashboard-source/apps/frontend/components/session-reissue.tsx +48 -0
  198. package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +89 -0
  199. package/dist/dashboard-source/apps/frontend/components/sidebar-stats-views.tsx +65 -0
  200. package/dist/dashboard-source/apps/frontend/components/theme-provider.tsx +132 -0
  201. package/dist/dashboard-source/apps/frontend/components/todo-count-badge.tsx +59 -0
  202. package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +304 -0
  203. package/dist/dashboard-source/apps/frontend/components/ui/checkbox.tsx +31 -0
  204. package/dist/dashboard-source/apps/frontend/components/ui/dialog.tsx +142 -0
  205. package/dist/dashboard-source/apps/frontend/components/ui/dropdown-menu.tsx +256 -0
  206. package/dist/dashboard-source/apps/frontend/components/ui/input.tsx +20 -0
  207. package/dist/dashboard-source/apps/frontend/components/ui/pagination.tsx +59 -0
  208. package/dist/dashboard-source/apps/frontend/components/ui/sheet.tsx +138 -0
  209. package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +741 -0
  210. package/dist/dashboard-source/apps/frontend/components/ui/skeleton.tsx +13 -0
  211. package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +30 -0
  212. package/dist/dashboard-source/apps/frontend/components/ui/table.tsx +115 -0
  213. package/dist/dashboard-source/apps/frontend/components/ui/tooltip.tsx +60 -0
  214. package/dist/dashboard-source/apps/frontend/components/without-waiting-badge.tsx +24 -0
  215. package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +116 -0
  216. package/dist/dashboard-source/apps/frontend/components/workflow/swimlane-node.tsx +46 -0
  217. package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +172 -0
  218. package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +189 -0
  219. package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +79 -0
  220. package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +74 -0
  221. package/dist/dashboard-source/apps/frontend/hooks/use-mobile.ts +27 -0
  222. package/dist/dashboard-source/apps/frontend/hooks/use-notification-preference.ts +246 -0
  223. package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +56 -0
  224. package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +101 -0
  225. package/dist/dashboard-source/apps/frontend/index.d.ts +12 -0
  226. package/dist/dashboard-source/apps/frontend/instrumentation.node.ts +25 -0
  227. package/dist/dashboard-source/apps/frontend/instrumentation.ts +19 -0
  228. package/dist/dashboard-source/apps/frontend/lib/app-icons-metadata.ts +66 -0
  229. package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +128 -0
  230. package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +355 -0
  231. package/dist/dashboard-source/apps/frontend/lib/appsync-events/config.ts +18 -0
  232. package/dist/dashboard-source/apps/frontend/lib/appsync-events/reconnect-registry.ts +34 -0
  233. package/dist/dashboard-source/apps/frontend/lib/auth/act-on-behalf-menu.ts +9 -0
  234. package/dist/dashboard-source/apps/frontend/lib/auth/callback-error.ts +26 -0
  235. package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +32 -0
  236. package/dist/dashboard-source/apps/frontend/lib/auth/client.ts +46 -0
  237. package/dist/dashboard-source/apps/frontend/lib/auth/config.ts +48 -0
  238. package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +62 -0
  239. package/dist/dashboard-source/apps/frontend/lib/auth/issuer.ts +164 -0
  240. package/dist/dashboard-source/apps/frontend/lib/auth/jwt.ts +17 -0
  241. package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +35 -0
  242. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys-menu.ts +9 -0
  243. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +117 -0
  244. package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +52 -0
  245. package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +62 -0
  246. package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +16 -0
  247. package/dist/dashboard-source/apps/frontend/lib/auth/redirect.ts +105 -0
  248. package/dist/dashboard-source/apps/frontend/lib/auth/secret-login-presentation.ts +33 -0
  249. package/dist/dashboard-source/apps/frontend/lib/auth/session-cache-scope.ts +1 -0
  250. package/dist/dashboard-source/apps/frontend/lib/auth/session-role.ts +6 -0
  251. package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +277 -0
  252. package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -0
  253. package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +95 -0
  254. package/dist/dashboard-source/apps/frontend/lib/authorization-tabs.ts +19 -0
  255. package/dist/dashboard-source/apps/frontend/lib/cedar-highlight.ts +116 -0
  256. package/dist/dashboard-source/apps/frontend/lib/client-plugin-error-reporting.ts +28 -0
  257. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +1119 -0
  258. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-scope.ts +48 -0
  259. package/dist/dashboard-source/apps/frontend/lib/collections/database-error-ui.tsx +61 -0
  260. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution-collection-provider.tsx +32 -0
  261. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +161 -0
  262. package/dist/dashboard-source/apps/frontend/lib/collections/execution-collection-provider.tsx +42 -0
  263. package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +215 -0
  264. package/dist/dashboard-source/apps/frontend/lib/collections/graphql-stream.ts +123 -0
  265. package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +30 -0
  266. package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +123 -0
  267. package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +394 -0
  268. package/dist/dashboard-source/apps/frontend/lib/collections/replication-registry.ts +196 -0
  269. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-database-name.ts +19 -0
  270. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-lifecycle.ts +368 -0
  271. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-provider.tsx +577 -0
  272. package/dist/dashboard-source/apps/frontend/lib/collections/todo-collection-provider.tsx +30 -0
  273. package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +133 -0
  274. package/dist/dashboard-source/apps/frontend/lib/current-provider-user.ts +30 -0
  275. package/dist/dashboard-source/apps/frontend/lib/dev/frontend-port-file.ts +41 -0
  276. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-events.ts +21 -0
  277. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-query-invalidation.tsx +62 -0
  278. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-refresh.ts +40 -0
  279. package/dist/dashboard-source/apps/frontend/lib/effect/error-boundary.tsx +84 -0
  280. package/dist/dashboard-source/apps/frontend/lib/effect/index.ts +31 -0
  281. package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +57 -0
  282. package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +17 -0
  283. package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +168 -0
  284. package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +48 -0
  285. package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +206 -0
  286. package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +36 -0
  287. package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +94 -0
  288. package/dist/dashboard-source/apps/frontend/lib/effect/services/index.ts +21 -0
  289. package/dist/dashboard-source/apps/frontend/lib/embed-manifest-store.ts +20 -0
  290. package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +152 -0
  291. package/dist/dashboard-source/apps/frontend/lib/embed-request-origin.ts +39 -0
  292. package/dist/dashboard-source/apps/frontend/lib/errors/get-display-error-message.ts +22 -0
  293. package/dist/dashboard-source/apps/frontend/lib/execution-menu-actions-registry.ts +26 -0
  294. package/dist/dashboard-source/apps/frontend/lib/feature-permissions.ts +13 -0
  295. package/dist/dashboard-source/apps/frontend/lib/frontend-boot-health.tsx +161 -0
  296. package/dist/dashboard-source/apps/frontend/lib/frontend-client-plugin-registry.ts +45 -0
  297. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest-store.ts +214 -0
  298. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +74 -0
  299. package/dist/dashboard-source/apps/frontend/lib/frontend-plugin-loaders.ts +191 -0
  300. package/dist/dashboard-source/apps/frontend/lib/generated/gql/fragment-masking.ts +87 -0
  301. package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +292 -0
  302. package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +443 -0
  303. package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +2 -0
  304. package/dist/dashboard-source/apps/frontend/lib/graphql/client-consumer.tsx +23 -0
  305. package/dist/dashboard-source/apps/frontend/lib/graphql/client-error-reporting.ts +268 -0
  306. package/dist/dashboard-source/apps/frontend/lib/graphql/client-provider.tsx +59 -0
  307. package/dist/dashboard-source/apps/frontend/lib/graphql/dashboard-activity.ts +7 -0
  308. package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +78 -0
  309. package/dist/dashboard-source/apps/frontend/lib/graphql/endpoint.ts +26 -0
  310. package/dist/dashboard-source/apps/frontend/lib/graphql/execution-queries.ts +70 -0
  311. package/dist/dashboard-source/apps/frontend/lib/graphql/file-upload-provider.tsx +82 -0
  312. package/dist/dashboard-source/apps/frontend/lib/graphql/graphql-identifiers.ts +10 -0
  313. package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +327 -0
  314. package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +81 -0
  315. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +63 -0
  316. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-queries.ts +67 -0
  317. package/dist/dashboard-source/apps/frontend/lib/graphql/provider-user-queries.ts +65 -0
  318. package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +80 -0
  319. package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +15 -0
  320. package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +634 -0
  321. package/dist/dashboard-source/apps/frontend/lib/graphql/stats-views-server.ts +16 -0
  322. package/dist/dashboard-source/apps/frontend/lib/graphql/stats-views.ts +33 -0
  323. package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +138 -0
  324. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +54 -0
  325. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +50 -0
  326. package/dist/dashboard-source/apps/frontend/lib/mobile-home-view-model.ts +74 -0
  327. package/dist/dashboard-source/apps/frontend/lib/mobile-shell-policy.ts +124 -0
  328. package/dist/dashboard-source/apps/frontend/lib/mock-data.ts +364 -0
  329. package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +251 -0
  330. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +178 -0
  331. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notifications-runtime.tsx +14 -0
  332. package/dist/dashboard-source/apps/frontend/lib/notifications/use-todo-notifications.tsx +103 -0
  333. package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +50 -0
  334. package/dist/dashboard-source/apps/frontend/lib/org-chart-depth-config.ts +71 -0
  335. package/dist/dashboard-source/apps/frontend/lib/org-chart-layout.ts +149 -0
  336. package/dist/dashboard-source/apps/frontend/lib/org-chart-types.ts +17 -0
  337. package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +57 -0
  338. package/dist/dashboard-source/apps/frontend/lib/organisation-plugin-loaders.ts +13 -0
  339. package/dist/dashboard-source/apps/frontend/lib/organisation-plugin-preparation.ts +2 -0
  340. package/dist/dashboard-source/apps/frontend/lib/plugins-client.tsx +99 -0
  341. package/dist/dashboard-source/apps/frontend/lib/plugins.ts +1 -0
  342. package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +9 -0
  343. package/dist/dashboard-source/apps/frontend/lib/public-todo-graphql-errors.ts +45 -0
  344. package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +200 -0
  345. package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +209 -0
  346. package/dist/dashboard-source/apps/frontend/lib/query-client.ts +41 -0
  347. package/dist/dashboard-source/apps/frontend/lib/restart-execution-action.ts +76 -0
  348. package/dist/dashboard-source/apps/frontend/lib/runtime-config.ts +23 -0
  349. package/dist/dashboard-source/apps/frontend/lib/telemetry/constants.ts +5 -0
  350. package/dist/dashboard-source/apps/frontend/lib/telemetry/otlp-config.ts +16 -0
  351. package/dist/dashboard-source/apps/frontend/lib/telemetry/register-otel.ts +308 -0
  352. package/dist/dashboard-source/apps/frontend/lib/theme.ts +9 -0
  353. package/dist/dashboard-source/apps/frontend/lib/todo-types.ts +64 -0
  354. package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +144 -0
  355. package/dist/dashboard-source/apps/frontend/lib/types/org-identity.ts +7 -0
  356. package/dist/dashboard-source/apps/frontend/lib/utils.ts +16 -0
  357. package/dist/dashboard-source/apps/frontend/lib/workflow/constants.ts +118 -0
  358. package/dist/dashboard-source/apps/frontend/lib/workflow/edge-routing.ts +195 -0
  359. package/dist/dashboard-source/apps/frontend/lib/workflow/form-preview.ts +8 -0
  360. package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +878 -0
  361. package/dist/dashboard-source/apps/frontend/lib/workflow/types.ts +63 -0
  362. package/dist/dashboard-source/apps/frontend/next.config.ts +238 -0
  363. package/dist/dashboard-source/apps/frontend/package.json +71 -0
  364. package/dist/dashboard-source/apps/frontend/postcss.config.mjs +5 -0
  365. package/dist/dashboard-source/apps/frontend/proxy.ts +293 -0
  366. package/dist/dashboard-source/apps/frontend/public/.gitkeep +0 -0
  367. package/dist/dashboard-source/apps/frontend/public/favicon.ico +0 -0
  368. package/dist/dashboard-source/apps/frontend/public/processfocus-embed.js +553 -0
  369. package/dist/dashboard-source/apps/frontend/tsconfig.json +35 -0
  370. package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +7 -0
  371. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +1397 -0
  372. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +18 -0
  373. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +346 -0
  374. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +172 -0
  375. package/dist/dashboard-source/modules/auth-policy/src/index.ts +4 -0
  376. package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +263 -0
  377. package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +34 -0
  378. package/dist/dashboard-source/modules/auth-policy/src/lib/errors.ts +47 -0
  379. package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +595 -0
  380. package/dist/dashboard-source/modules/auth-session/src/index.ts +22 -0
  381. package/dist/dashboard-source/modules/auth-session/src/lib/issuer-url.ts +192 -0
  382. package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +76 -0
  383. package/dist/dashboard-source/modules/auth-session/src/lib/session-cache-scope.ts +24 -0
  384. package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +54 -0
  385. package/dist/dashboard-source/modules/auth-session/src/lib/url.ts +2 -0
  386. package/dist/dashboard-source/modules/aws-common/src/index.ts +3 -0
  387. package/dist/dashboard-source/modules/aws-common/src/lib/acm.ts +50 -0
  388. package/dist/dashboard-source/modules/aws-common/src/lib/otlp-config.ts +66 -0
  389. package/dist/dashboard-source/modules/aws-common/src/lib/runtime-ssm.ts +28 -0
  390. package/dist/dashboard-source/modules/effect-json-logger/src/index.ts +1 -0
  391. package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +65 -0
  392. package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +78 -0
  393. package/dist/dashboard-source/modules/form/src/index.ts +20 -0
  394. package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +152 -0
  395. package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +1421 -0
  396. package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +85 -0
  397. package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +58 -0
  398. package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +34 -0
  399. package/dist/dashboard-source/modules/form/src/lib/walker.tsx +1554 -0
  400. package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +440 -0
  401. package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +13 -0
  402. package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +336 -0
  403. package/dist/dashboard-source/modules/form-rule/src/index.ts +21 -0
  404. package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +531 -0
  405. package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +102 -0
  406. package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +121 -0
  407. package/dist/dashboard-source/modules/form-schema/src/index.ts +8 -0
  408. package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +44 -0
  409. package/dist/dashboard-source/modules/form-schema/src/lib/deferred-value.ts +21 -0
  410. package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +50 -0
  411. package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +82 -0
  412. package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +58 -0
  413. package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +975 -0
  414. package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +60 -0
  415. package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +45 -0
  416. package/dist/dashboard-source/modules/frontend-endpoints/src/endpoint.ts +137 -0
  417. package/dist/dashboard-source/modules/frontend-endpoints/src/index.ts +11 -0
  418. package/dist/dashboard-source/modules/frontend-endpoints/src/port-files.ts +219 -0
  419. package/dist/dashboard-source/modules/frontend-manifest/src/index.ts +2 -0
  420. package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +201 -0
  421. package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +408 -0
  422. package/dist/dashboard-source/modules/frontend-plugin-host/src/index.ts +29 -0
  423. package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +288 -0
  424. package/dist/dashboard-source/modules/openauth/src/client.ts +1045 -0
  425. package/dist/dashboard-source/modules/openauth/src/error.ts +140 -0
  426. package/dist/dashboard-source/modules/openauth/src/pkce.ts +40 -0
  427. package/dist/dashboard-source/modules/openauth/src/random.ts +24 -0
  428. package/dist/dashboard-source/modules/openauth/src/subject.ts +132 -0
  429. package/dist/dashboard-source/modules/openauth/src/util.ts +13 -0
  430. package/dist/dashboard-source/modules/request-time/src/index.ts +1 -0
  431. package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +30 -0
  432. package/dist/dashboard-source/modules/rxdb-collections/generated/draft-process-execution-schema.json +45 -0
  433. package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +217 -0
  434. package/dist/dashboard-source/modules/rxdb-collections/generated/process-schema.json +77 -0
  435. package/dist/dashboard-source/modules/rxdb-collections/generated/todo-schema.json +94 -0
  436. package/dist/dashboard-source/modules/rxdb-collections/src/index.ts +2 -0
  437. package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +181 -0
  438. package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +166 -0
  439. package/dist/dashboard-source/modules/shadcn-components/src/index.ts +60 -0
  440. package/dist/dashboard-source/modules/shadcn-components/src/lib/boolean-field.tsx +73 -0
  441. package/dist/dashboard-source/modules/shadcn-components/src/lib/calendar-slot-field.tsx +808 -0
  442. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +127 -0
  443. package/dist/dashboard-source/modules/shadcn-components/src/lib/field-set.tsx +14 -0
  444. package/dist/dashboard-source/modules/shadcn-components/src/lib/file-field.tsx +321 -0
  445. package/dist/dashboard-source/modules/shadcn-components/src/lib/file-upload-context.tsx +45 -0
  446. package/dist/dashboard-source/modules/shadcn-components/src/lib/form-context.tsx +19 -0
  447. package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +394 -0
  448. package/dist/dashboard-source/modules/shadcn-components/src/lib/radio-field.tsx +96 -0
  449. package/dist/dashboard-source/modules/shadcn-components/src/lib/select-field.tsx +106 -0
  450. package/dist/dashboard-source/modules/shadcn-components/src/lib/text-field.tsx +245 -0
  451. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/button.tsx +63 -0
  452. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/checkbox.tsx +31 -0
  453. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/command.tsx +101 -0
  454. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/field.tsx +275 -0
  455. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/input.tsx +29 -0
  456. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/label.tsx +23 -0
  457. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +31 -0
  458. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/separator.tsx +27 -0
  459. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/textarea.tsx +19 -0
  460. package/dist/dashboard-source/modules/shadcn-components/src/lib/utils/utils.ts +4 -0
  461. package/dist/dashboard-source.json +70 -0
  462. package/dist/graphql-server.mjs +1319 -0
  463. package/dist/job-worker.mjs +989 -0
  464. package/dist/main.mjs +495 -0
  465. package/dist/prepare-dashboard.mjs +35 -0
  466. package/dist/resources/cedar/policies.cedar +315 -0
  467. package/dist/resources/cedar/schema.cedarschema +276 -0
  468. package/dist/resources/graphql-schema/rxdb.graphql +401 -0
  469. package/dist/resources/graphql-schema/system.graphql +1200 -0
  470. package/package.json +98 -0
@@ -0,0 +1,1554 @@
1
+ import React, {
2
+ Suspense,
3
+ use,
4
+ useCallback,
5
+ useEffect,
6
+ useEffectEvent,
7
+ useRef,
8
+ useState,
9
+ } from "react"
10
+ import type {
11
+ CalendarSlotField as CalendarSlotFieldType,
12
+ FormComponent,
13
+ ListField as ListFieldType,
14
+ LookupField as LookupFieldType,
15
+ MetricBreakdown as MetricBreakdownType,
16
+ PluginField,
17
+ ProviderUserField as ProviderUserFieldType,
18
+ TableField as TableFieldType,
19
+ } from "../../../form-client-representation/src/lib/types.ts"
20
+ import { FormComponentType } from "../../../form-client-representation/src/lib/types.ts"
21
+ import {
22
+ BooleanField,
23
+ Button,
24
+ CalendarSlotField,
25
+ type CalendarSlotFieldItem,
26
+ DateField,
27
+ Field,
28
+ FieldDescription,
29
+ FieldLabel,
30
+ FieldSetField,
31
+ FileField,
32
+ LookupField,
33
+ type LookupFieldItem,
34
+ RadioField,
35
+ SelectField,
36
+ TextAreaField,
37
+ TextField,
38
+ useFieldContext,
39
+ useFormContext,
40
+ } from "../../../shadcn-components/src/index.ts"
41
+ import {
42
+ type LookupOptions,
43
+ type LookupService,
44
+ useLookup,
45
+ } from "./lookup-context.tsx"
46
+ import { getPluginRenderer } from "./plugin-registry.ts"
47
+
48
+ // Type alias for forms
49
+ type AnyAppForm = {
50
+ AppField: React.ComponentType<{
51
+ name: string
52
+ children: () => React.JSX.Element
53
+ }>
54
+ }
55
+
56
+ const effectiveReadOnly = (component: FormComponent): boolean | undefined => {
57
+ if (component.disabled === true) return true
58
+ return component.readonly
59
+ }
60
+
61
+ /**
62
+ * Main walker function that processes client representation and emits React components
63
+ *
64
+ * @param form - The Tanstack form instance
65
+ * @param components - The client representation (output of asClientRepresentation)
66
+ * @param isFirstField - Whether this is the first field (for autofocus)
67
+ * @param stepPath - The step path for file upload authorization (required when form has file fields)
68
+ */
69
+ export const walkClientRepresentation = (
70
+ form: AnyAppForm,
71
+ components: Record<string, FormComponent>,
72
+ isFirstField = true,
73
+ stepPath?: string,
74
+ enableProviderUserLookup = true,
75
+ lookupOptions?: LookupOptions,
76
+ ): React.JSX.Element[] => {
77
+ const fields: React.JSX.Element[] = []
78
+ let autoFocusAssigned = false
79
+
80
+ for (const [fieldName, component] of Object.entries(components)) {
81
+ if (component.hidden === true) {
82
+ continue
83
+ }
84
+
85
+ const shouldAutoFocus =
86
+ isFirstField &&
87
+ !autoFocusAssigned &&
88
+ !component.readonly &&
89
+ !component.disabled
90
+ if (shouldAutoFocus) {
91
+ autoFocusAssigned = true
92
+ }
93
+ const field = processComponent(
94
+ form,
95
+ fieldName,
96
+ component,
97
+ shouldAutoFocus,
98
+ stepPath,
99
+ enableProviderUserLookup,
100
+ lookupOptions,
101
+ )
102
+ fields.push(field)
103
+ }
104
+
105
+ return fields
106
+ }
107
+
108
+ /**
109
+ * Process a single component from the client representation
110
+ */
111
+ const processComponent = (
112
+ form: AnyAppForm,
113
+ fieldName: string,
114
+ component: FormComponent,
115
+ shouldAutoFocus: boolean,
116
+ stepPath?: string,
117
+ enableProviderUserLookup = true,
118
+ lookupOptions?: LookupOptions,
119
+ ): React.JSX.Element => {
120
+ const readOnly = effectiveReadOnly(component)
121
+ // descriptionHtml opts into trusted HTML rendering. Form descriptions are
122
+ // admin-authored process-definition content, not end-user supplied input.
123
+ switch (component._tag) {
124
+ case FormComponentType.Text:
125
+ return (
126
+ <form.AppField key={component.field} name={component.field}>
127
+ {() => (
128
+ <TextField
129
+ label={component.label}
130
+ descriptionHtml={component.description}
131
+ autoFocus={shouldAutoFocus}
132
+ autoComplete={component.autoComplete}
133
+ {...(readOnly !== undefined && {
134
+ readOnly,
135
+ })}
136
+ />
137
+ )}
138
+ </form.AppField>
139
+ )
140
+
141
+ case FormComponentType.TextArea:
142
+ return (
143
+ <form.AppField key={component.field} name={component.field}>
144
+ {() => (
145
+ <TextAreaField
146
+ label={component.label}
147
+ descriptionHtml={component.description}
148
+ autoFocus={shouldAutoFocus}
149
+ {...(readOnly !== undefined && {
150
+ readOnly,
151
+ })}
152
+ />
153
+ )}
154
+ </form.AppField>
155
+ )
156
+
157
+ case FormComponentType.Number:
158
+ return (
159
+ <form.AppField key={component.field} name={component.field}>
160
+ {() => (
161
+ <TextField
162
+ inputMode="decimal"
163
+ label={component.label}
164
+ descriptionHtml={component.description}
165
+ autoFocus={shouldAutoFocus}
166
+ autoComplete={component.autoComplete}
167
+ {...(readOnly !== undefined && {
168
+ readOnly,
169
+ })}
170
+ />
171
+ )}
172
+ </form.AppField>
173
+ )
174
+
175
+ case FormComponentType.Date:
176
+ return (
177
+ <form.AppField key={component.field} name={component.field}>
178
+ {() => (
179
+ <DateField
180
+ label={component.label}
181
+ descriptionHtml={component.description}
182
+ autoFocus={shouldAutoFocus}
183
+ {...(readOnly !== undefined && {
184
+ readOnly,
185
+ })}
186
+ />
187
+ )}
188
+ </form.AppField>
189
+ )
190
+
191
+ case FormComponentType.Email:
192
+ return (
193
+ <form.AppField key={component.field} name={component.field}>
194
+ {() => (
195
+ <TextField
196
+ type="email"
197
+ inputMode="email"
198
+ label={component.label}
199
+ descriptionHtml={component.description}
200
+ autoFocus={shouldAutoFocus}
201
+ autoComplete={component.autoComplete}
202
+ {...(readOnly !== undefined && {
203
+ readOnly,
204
+ })}
205
+ />
206
+ )}
207
+ </form.AppField>
208
+ )
209
+
210
+ case FormComponentType.Phone:
211
+ return (
212
+ <form.AppField key={component.field} name={component.field}>
213
+ {() => (
214
+ <TextField
215
+ type="tel"
216
+ inputMode="tel"
217
+ label={component.label}
218
+ descriptionHtml={component.description}
219
+ autoFocus={shouldAutoFocus}
220
+ autoComplete={component.autoComplete}
221
+ {...(readOnly !== undefined && {
222
+ readOnly,
223
+ })}
224
+ />
225
+ )}
226
+ </form.AppField>
227
+ )
228
+
229
+ case FormComponentType.ProviderUser:
230
+ if (!enableProviderUserLookup) {
231
+ return (
232
+ <form.AppField key={component.field} name={component.field}>
233
+ {() => (
234
+ <TextField
235
+ label={component.label}
236
+ descriptionHtml={component.description}
237
+ autoFocus={shouldAutoFocus}
238
+ autoComplete={component.autoComplete}
239
+ {...(readOnly !== undefined && {
240
+ readOnly,
241
+ })}
242
+ />
243
+ )}
244
+ </form.AppField>
245
+ )
246
+ }
247
+
248
+ if (!stepPath) {
249
+ throw new Error(
250
+ `ProviderUserField "${component.field}" requires stepPath for fetching suggestions. ` +
251
+ `Please provide stepPath when calling walkClientRepresentation.`,
252
+ )
253
+ }
254
+ return (
255
+ <form.AppField key={component.field} name={component.field}>
256
+ {() => (
257
+ <IndependentLookupFieldWrapper
258
+ component={component}
259
+ stepPath={stepPath}
260
+ lookupOptions={lookupOptions}
261
+ shouldAutoFocus={shouldAutoFocus}
262
+ />
263
+ )}
264
+ </form.AppField>
265
+ )
266
+
267
+ case FormComponentType.Boolean:
268
+ return (
269
+ <form.AppField key={component.field} name={component.field}>
270
+ {() => (
271
+ <BooleanField
272
+ label={component.label}
273
+ descriptionHtml={component.description}
274
+ {...(readOnly !== undefined && {
275
+ readOnly,
276
+ })}
277
+ />
278
+ )}
279
+ </form.AppField>
280
+ )
281
+
282
+ case FormComponentType.Select:
283
+ return (
284
+ <form.AppField key={component.field} name={component.field}>
285
+ {() => (
286
+ <SelectField
287
+ label={component.label}
288
+ descriptionHtml={component.description}
289
+ options={component.options}
290
+ {...(component.emptyValue !== undefined && {
291
+ emptyValue: component.emptyValue,
292
+ })}
293
+ autoFocus={shouldAutoFocus}
294
+ {...(readOnly !== undefined && {
295
+ readOnly,
296
+ })}
297
+ />
298
+ )}
299
+ </form.AppField>
300
+ )
301
+
302
+ case FormComponentType.Radio:
303
+ return (
304
+ <form.AppField key={component.field} name={component.field}>
305
+ {() => (
306
+ <RadioField
307
+ label={component.label}
308
+ descriptionHtml={component.description}
309
+ options={component.options}
310
+ autoFocus={shouldAutoFocus}
311
+ {...(readOnly !== undefined && {
312
+ readOnly,
313
+ })}
314
+ />
315
+ )}
316
+ </form.AppField>
317
+ )
318
+
319
+ case FormComponentType.Lookup:
320
+ if (!stepPath) {
321
+ throw new Error(
322
+ `LookupField "${component.field}" requires stepPath for fetching suggestions. ` +
323
+ `Please provide stepPath when calling walkClientRepresentation.`,
324
+ )
325
+ }
326
+ return (
327
+ <form.AppField key={component.field} name={component.field}>
328
+ {() => (
329
+ <LookupFieldWrapper
330
+ component={component}
331
+ stepPath={stepPath}
332
+ lookupOptions={lookupOptions}
333
+ shouldAutoFocus={shouldAutoFocus}
334
+ />
335
+ )}
336
+ </form.AppField>
337
+ )
338
+
339
+ case FormComponentType.CalendarSlot:
340
+ if (!stepPath) {
341
+ throw new Error(
342
+ `CalendarSlotField "${component.field}" requires stepPath for fetching slots. ` +
343
+ `Please provide stepPath when calling walkClientRepresentation.`,
344
+ )
345
+ }
346
+ return (
347
+ <form.AppField key={component.field} name={component.field}>
348
+ {() => (
349
+ <CalendarSlotFieldWrapper
350
+ component={component}
351
+ stepPath={stepPath}
352
+ lookupOptions={lookupOptions}
353
+ shouldAutoFocus={shouldAutoFocus}
354
+ />
355
+ )}
356
+ </form.AppField>
357
+ )
358
+
359
+ case FormComponentType.File:
360
+ if (!stepPath) {
361
+ throw new Error(
362
+ `FileField "${component.field}" requires stepPath for authorization. ` +
363
+ `Please provide stepPath when calling walkClientRepresentation.`,
364
+ )
365
+ }
366
+ return (
367
+ <form.AppField key={component.field} name={component.field}>
368
+ {() => (
369
+ <FileField
370
+ label={component.label}
371
+ descriptionHtml={component.description}
372
+ documentStore={component.documentStore}
373
+ stepPath={stepPath}
374
+ {...(component.accept != null && { accept: component.accept })}
375
+ {...(component.maxSize != null && { maxSize: component.maxSize })}
376
+ {...(readOnly !== undefined && {
377
+ readOnly,
378
+ })}
379
+ />
380
+ )}
381
+ </form.AppField>
382
+ )
383
+
384
+ case FormComponentType.FieldSet: {
385
+ const children = walkClientRepresentation(
386
+ form,
387
+ component.children,
388
+ false,
389
+ stepPath,
390
+ enableProviderUserLookup,
391
+ lookupOptions,
392
+ )
393
+ return (
394
+ <FieldSetField key={fieldName} label={component.label}>
395
+ {children}
396
+ </FieldSetField>
397
+ )
398
+ }
399
+
400
+ case FormComponentType.List: {
401
+ return (
402
+ <form.AppField key={component.field} name={component.field}>
403
+ {() => (
404
+ <ListFieldRenderer
405
+ form={form}
406
+ component={component}
407
+ stepPath={stepPath}
408
+ enableProviderUserLookup={enableProviderUserLookup}
409
+ lookupOptions={lookupOptions}
410
+ />
411
+ )}
412
+ </form.AppField>
413
+ )
414
+ }
415
+
416
+ case FormComponentType.Table: {
417
+ return (
418
+ <form.AppField key={component.field} name={component.field}>
419
+ {() => <TableFieldRenderer component={component} />}
420
+ </form.AppField>
421
+ )
422
+ }
423
+
424
+ case FormComponentType.Plugin: {
425
+ return (
426
+ <PluginFieldRenderer
427
+ key={fieldName}
428
+ form={form}
429
+ component={component}
430
+ shouldAutoFocus={shouldAutoFocus}
431
+ {...(stepPath !== undefined && { stepPath })}
432
+ {...(lookupOptions?.todoId !== undefined && {
433
+ todoId: lookupOptions.todoId,
434
+ })}
435
+ />
436
+ )
437
+ }
438
+
439
+ case FormComponentType.Static: {
440
+ return (
441
+ <div key={fieldName} data-slot="static-field" className="space-y-2">
442
+ {component.label && (
443
+ <div
444
+ data-slot="static-field-label"
445
+ className="text-sm font-medium leading-none"
446
+ >
447
+ {component.label}
448
+ </div>
449
+ )}
450
+ <div
451
+ data-slot="static-field-content"
452
+ className="text-sm text-muted-foreground"
453
+ >
454
+ {component.content || component.description}
455
+ </div>
456
+ </div>
457
+ )
458
+ }
459
+
460
+ case FormComponentType.Link: {
461
+ if (component.display === "button") {
462
+ return (
463
+ <div key={fieldName} data-slot="static-link" className="space-y-2">
464
+ <Button
465
+ asChild
466
+ className={
467
+ component.color === "blue"
468
+ ? "bg-blue-600 text-white hover:bg-blue-700"
469
+ : undefined
470
+ }
471
+ >
472
+ <a
473
+ data-slot="static-link-button"
474
+ href={component.url}
475
+ target="_blank"
476
+ rel="noopener noreferrer"
477
+ >
478
+ {component.text}
479
+ </a>
480
+ </Button>
481
+ </div>
482
+ )
483
+ }
484
+
485
+ return (
486
+ <div key={fieldName} data-slot="static-link" className="space-y-2">
487
+ {component.label && (
488
+ <div
489
+ data-slot="static-link-label"
490
+ className="text-sm font-medium leading-none"
491
+ >
492
+ {component.label}
493
+ </div>
494
+ )}
495
+ <a
496
+ data-slot="static-link-anchor"
497
+ href={component.url}
498
+ target="_blank"
499
+ rel="noopener noreferrer"
500
+ className="text-sm text-primary underline-offset-4 hover:underline"
501
+ >
502
+ {component.text}
503
+ </a>
504
+ </div>
505
+ )
506
+ }
507
+
508
+ case FormComponentType.MetricBreakdown: {
509
+ return (
510
+ <MetricBreakdownPluginRenderer
511
+ key={fieldName}
512
+ form={form}
513
+ component={component}
514
+ shouldAutoFocus={shouldAutoFocus}
515
+ />
516
+ )
517
+ }
518
+
519
+ default: {
520
+ const _exhaustive: never = component
521
+ throw new Error(
522
+ `Unhandled component type: ${(_exhaustive as FormComponent)._tag}`,
523
+ )
524
+ }
525
+ }
526
+ }
527
+
528
+ function TableFieldRenderer({ component }: { component: TableFieldType }) {
529
+ const field = useFieldContext<unknown[]>()
530
+ const rows = Array.isArray(field.state.value) ? field.state.value : []
531
+ const columns = Object.entries(component.itemChildren).flatMap(
532
+ ([key, child]) =>
533
+ "field" in child ? [{ key, label: child.label || key }] : [],
534
+ )
535
+
536
+ return (
537
+ <Field>
538
+ <FieldLabel>{component.label}</FieldLabel>
539
+ <div className="overflow-x-auto rounded-md border">
540
+ <table className="w-full min-w-max text-left text-sm">
541
+ <thead className="border-b bg-muted/50 text-muted-foreground">
542
+ <tr>
543
+ {columns.map((column) => (
544
+ <th
545
+ key={column.key}
546
+ scope="col"
547
+ className="px-3 py-2 font-medium"
548
+ >
549
+ {column.label}
550
+ </th>
551
+ ))}
552
+ </tr>
553
+ </thead>
554
+ <tbody>
555
+ {rows.length === 0 ? (
556
+ <tr>
557
+ <td
558
+ className="px-3 py-3 text-muted-foreground"
559
+ colSpan={Math.max(columns.length, 1)}
560
+ >
561
+ No rows.
562
+ </td>
563
+ </tr>
564
+ ) : (
565
+ rows.map((row, index) => (
566
+ <tr
567
+ key={getTableRowKey(row, component.field, index)}
568
+ className="border-b last:border-0"
569
+ >
570
+ {columns.map((column) => (
571
+ <td key={column.key} className="px-3 py-2 align-top">
572
+ {formatTableCellValue(getTableCellValue(row, column.key))}
573
+ </td>
574
+ ))}
575
+ </tr>
576
+ ))
577
+ )}
578
+ </tbody>
579
+ </table>
580
+ </div>
581
+ {component.description && (
582
+ <FieldDescription trustedHtml={component.description} />
583
+ )}
584
+ </Field>
585
+ )
586
+ }
587
+
588
+ const getTableCellValue = (row: unknown, key: string): unknown =>
589
+ typeof row === "object" && row !== null && !Array.isArray(row)
590
+ ? (row as Record<string, unknown>)[key]
591
+ : undefined
592
+
593
+ const getTableRowKey = (row: unknown, field: string, index: number): string => {
594
+ if (typeof row === "object" && row !== null) {
595
+ const explicitKey = (row as Record<string, unknown>)["id"]
596
+ if (typeof explicitKey === "string" || typeof explicitKey === "number") {
597
+ return `${field}-id-${explicitKey}`
598
+ }
599
+ }
600
+
601
+ return `${field}-row-${index}`
602
+ }
603
+
604
+ const formatTableCellValue = (value: unknown): string => {
605
+ if (value === null || value === undefined || value === "") return "-"
606
+ if (typeof value === "string") return value
607
+ if (typeof value === "number" || typeof value === "boolean") {
608
+ return String(value)
609
+ }
610
+ // Keep unexpected table cell shapes visible instead of silently blanking them.
611
+ return JSON.stringify(value)
612
+ }
613
+
614
+ function MetricBreakdownPluginRenderer({
615
+ form,
616
+ component,
617
+ shouldAutoFocus,
618
+ }: {
619
+ readonly form: AnyAppForm
620
+ readonly component: MetricBreakdownType
621
+ readonly shouldAutoFocus: boolean
622
+ }) {
623
+ if (!component.rendererPluginType) {
624
+ return (
625
+ <div className="rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900">
626
+ No renderer plugin configured for metric breakdown "{component.title}".
627
+ </div>
628
+ )
629
+ }
630
+
631
+ const renderer = getPluginRenderer(component.rendererPluginType)
632
+ if (!renderer) {
633
+ return (
634
+ <div className="rounded-md border border-red-300 bg-red-50 p-3 text-sm text-red-800">
635
+ No renderer registered for plugin type: {component.rendererPluginType}
636
+ </div>
637
+ )
638
+ }
639
+
640
+ const pluginComponent: PluginField = {
641
+ _tag: FormComponentType.Plugin,
642
+ field: component.field,
643
+ label: component.label,
644
+ pluginType: component.rendererPluginType,
645
+ pluginData: component,
646
+ readonly: true,
647
+ }
648
+
649
+ return renderer(form, pluginComponent, shouldAutoFocus)
650
+ }
651
+
652
+ /**
653
+ * Wrapper component that fetches lookup suggestions and renders the LookupField UI.
654
+ * Uses the LookupProvider context to make GraphQL calls with debounced search.
655
+ *
656
+ * For dependent lookups (component.dependencies is set), subscribes to dependency
657
+ * field values and calls the typed query. Re-queries and clears invalid selections
658
+ * when dependencies change.
659
+ */
660
+ function LookupFieldWrapper({
661
+ component,
662
+ stepPath,
663
+ lookupOptions,
664
+ shouldAutoFocus,
665
+ }: {
666
+ component: LookupFieldType
667
+ stepPath: string
668
+ lookupOptions: LookupOptions | undefined
669
+ shouldAutoFocus: boolean
670
+ }) {
671
+ const hasDeps =
672
+ component.dependencies &&
673
+ component.dependencies.length > 0 &&
674
+ component.queryName
675
+
676
+ return hasDeps ? (
677
+ <DependentLookupFieldWrapper
678
+ component={component}
679
+ shouldAutoFocus={shouldAutoFocus}
680
+ />
681
+ ) : (
682
+ <IndependentLookupFieldWrapper
683
+ component={component}
684
+ stepPath={stepPath}
685
+ lookupOptions={lookupOptions}
686
+ shouldAutoFocus={shouldAutoFocus}
687
+ />
688
+ )
689
+ }
690
+
691
+ /**
692
+ * Independent lookup — uses the generic lookupSuggestions query.
693
+ */
694
+ function IndependentLookupFieldWrapper({
695
+ component,
696
+ stepPath,
697
+ lookupOptions,
698
+ shouldAutoFocus,
699
+ }: {
700
+ component: LookupFieldType | ProviderUserFieldType
701
+ stepPath: string
702
+ lookupOptions: LookupOptions | undefined
703
+ shouldAutoFocus: boolean
704
+ }) {
705
+ const lookupService = useLookup()
706
+ const readOnly = effectiveReadOnly(component)
707
+ const [items, setItems] = useState<LookupFieldItem[]>([])
708
+ const [loading, setLoading] = useState(false)
709
+ const [error, setError] = useState<string | undefined>(undefined)
710
+ const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
711
+
712
+ // Fetch initial items on mount
713
+ useEffect(() => {
714
+ const fieldName = component.field.includes(".")
715
+ ? (component.field.split(".").pop() ?? component.field)
716
+ : component.field
717
+ lookupService
718
+ .fetchSuggestions(stepPath, fieldName, "", 20, lookupOptions)
719
+ .then((results) => {
720
+ setItems(results)
721
+ setError(undefined)
722
+ })
723
+ .catch((err) => {
724
+ setItems([])
725
+ setError(
726
+ err instanceof Error ? err.message : "Failed to load suggestions",
727
+ )
728
+ })
729
+ }, [stepPath, component.field, lookupService, lookupOptions])
730
+
731
+ const handleSearch = useCallback(
732
+ (filter: string) => {
733
+ if (debounceRef.current) {
734
+ clearTimeout(debounceRef.current)
735
+ }
736
+ debounceRef.current = setTimeout(() => {
737
+ setLoading(true)
738
+ setError(undefined)
739
+ const fieldName = component.field.includes(".")
740
+ ? (component.field.split(".").pop() ?? component.field)
741
+ : component.field
742
+ lookupService
743
+ .fetchSuggestions(stepPath, fieldName, filter, 20, lookupOptions)
744
+ .then((results) => {
745
+ setItems(results)
746
+ setLoading(false)
747
+ })
748
+ .catch((err) => {
749
+ setItems([])
750
+ setLoading(false)
751
+ setError(
752
+ err instanceof Error ? err.message : "Failed to load suggestions",
753
+ )
754
+ })
755
+ }, 300)
756
+ },
757
+ [stepPath, component.field, lookupService, lookupOptions],
758
+ )
759
+
760
+ return (
761
+ <LookupField
762
+ label={component.label}
763
+ descriptionHtml={component.description}
764
+ items={items}
765
+ onSearch={handleSearch}
766
+ loading={loading}
767
+ error={error}
768
+ {...(readOnly !== undefined && {
769
+ readOnly,
770
+ })}
771
+ autoFocus={shouldAutoFocus}
772
+ allowFreeText={getLookupAllowFreeText(component)}
773
+ />
774
+ )
775
+ }
776
+
777
+ const getLookupAllowFreeText = (
778
+ component: LookupFieldType | ProviderUserFieldType,
779
+ ): boolean | undefined =>
780
+ component._tag === FormComponentType.Lookup
781
+ ? component.allowFreeText
782
+ : undefined
783
+
784
+ const calendarSlotResourceCache = new WeakMap<
785
+ LookupService,
786
+ Map<string, Promise<CalendarSlotFieldItem[]>>
787
+ >()
788
+
789
+ // Resource lifetime is tied to the lookup service. Public todo pages create a
790
+ // per-token service, so time-sensitive slot data is discarded on navigation.
791
+
792
+ const calendarSlotResourceKey = (
793
+ stepPath: string,
794
+ fieldName: string,
795
+ lookupOptions: LookupOptions | undefined,
796
+ ) => `${stepPath}\u0000${fieldName}\u0000${lookupOptions?.todoId ?? ""}`
797
+
798
+ const getCalendarSlotResource = (
799
+ lookupService: LookupService,
800
+ stepPath: string,
801
+ fieldName: string,
802
+ lookupOptions: LookupOptions | undefined,
803
+ ) => {
804
+ let serviceCache = calendarSlotResourceCache.get(lookupService)
805
+ if (!serviceCache) {
806
+ serviceCache = new Map<string, Promise<CalendarSlotFieldItem[]>>()
807
+ calendarSlotResourceCache.set(lookupService, serviceCache)
808
+ }
809
+
810
+ const key = calendarSlotResourceKey(stepPath, fieldName, lookupOptions)
811
+ const cached = serviceCache.get(key)
812
+ if (cached) {
813
+ return cached
814
+ }
815
+
816
+ const promise = lookupService.fetchCalendarSlots(
817
+ stepPath,
818
+ fieldName,
819
+ lookupOptions,
820
+ )
821
+ serviceCache.set(key, promise)
822
+ return promise
823
+ }
824
+
825
+ const clearCalendarSlotResource = (
826
+ lookupService: LookupService,
827
+ stepPath: string,
828
+ fieldName: string,
829
+ lookupOptions: LookupOptions | undefined,
830
+ ) => {
831
+ calendarSlotResourceCache
832
+ .get(lookupService)
833
+ ?.delete(calendarSlotResourceKey(stepPath, fieldName, lookupOptions))
834
+ }
835
+
836
+ interface CalendarSlotLoadErrorBoundaryProps {
837
+ readonly children: React.ReactNode
838
+ readonly onReset: () => void
839
+ readonly renderError: (error: unknown, reset: () => void) => React.ReactNode
840
+ readonly resetKey: string
841
+ }
842
+
843
+ interface CalendarSlotLoadErrorBoundaryState {
844
+ readonly error: unknown | null
845
+ readonly resetKey: string
846
+ }
847
+
848
+ class CalendarSlotLoadErrorBoundary extends React.Component<
849
+ CalendarSlotLoadErrorBoundaryProps,
850
+ CalendarSlotLoadErrorBoundaryState
851
+ > {
852
+ override state: CalendarSlotLoadErrorBoundaryState = {
853
+ error: null,
854
+ resetKey: this.props.resetKey,
855
+ }
856
+
857
+ static getDerivedStateFromError(
858
+ error: unknown,
859
+ ): Partial<CalendarSlotLoadErrorBoundaryState> {
860
+ return { error }
861
+ }
862
+
863
+ static getDerivedStateFromProps(
864
+ props: CalendarSlotLoadErrorBoundaryProps,
865
+ state: CalendarSlotLoadErrorBoundaryState,
866
+ ): Partial<CalendarSlotLoadErrorBoundaryState> | null {
867
+ if (props.resetKey !== state.resetKey) {
868
+ return { error: null, resetKey: props.resetKey }
869
+ }
870
+
871
+ return null
872
+ }
873
+
874
+ private readonly reset = () => {
875
+ this.props.onReset()
876
+ this.setState({ error: null })
877
+ }
878
+
879
+ override render() {
880
+ if (this.state.error) {
881
+ return this.props.renderError(this.state.error, this.reset)
882
+ }
883
+
884
+ return this.props.children
885
+ }
886
+ }
887
+
888
+ function CalendarSlotFieldView({
889
+ component,
890
+ error,
891
+ loading,
892
+ onRetry,
893
+ shouldAutoFocus,
894
+ slots,
895
+ }: {
896
+ readonly component: CalendarSlotFieldType
897
+ readonly error?: boolean | undefined
898
+ readonly loading: boolean
899
+ readonly onRetry?: (() => void) | undefined
900
+ readonly shouldAutoFocus: boolean
901
+ readonly slots: CalendarSlotFieldItem[]
902
+ }) {
903
+ const readOnly = effectiveReadOnly(component)
904
+
905
+ return (
906
+ <CalendarSlotField
907
+ label={component.label}
908
+ descriptionHtml={component.description}
909
+ emptyMessageHtml={component.emptyMessageHtml}
910
+ loadErrorMessageHtml={component.loadErrorMessageHtml}
911
+ slots={slots}
912
+ loading={loading}
913
+ error={error}
914
+ autoFocus={shouldAutoFocus}
915
+ timeZone={component.timeZone}
916
+ locale={component.locale}
917
+ onRetry={onRetry}
918
+ {...(readOnly !== undefined && {
919
+ readOnly,
920
+ })}
921
+ {...(component.calendar !== undefined && {
922
+ calendar: component.calendar,
923
+ })}
924
+ />
925
+ )
926
+ }
927
+
928
+ function CalendarSlotFieldContent({
929
+ component,
930
+ fieldName,
931
+ lookupOptions,
932
+ lookupService,
933
+ shouldAutoFocus,
934
+ stepPath,
935
+ }: {
936
+ readonly component: CalendarSlotFieldType
937
+ readonly fieldName: string
938
+ readonly lookupOptions: LookupOptions | undefined
939
+ readonly lookupService: LookupService
940
+ readonly shouldAutoFocus: boolean
941
+ readonly stepPath: string
942
+ }) {
943
+ const slots = use(
944
+ getCalendarSlotResource(lookupService, stepPath, fieldName, lookupOptions),
945
+ )
946
+
947
+ return (
948
+ <CalendarSlotFieldView
949
+ component={component}
950
+ loading={false}
951
+ shouldAutoFocus={shouldAutoFocus}
952
+ slots={slots}
953
+ />
954
+ )
955
+ }
956
+
957
+ function CalendarSlotFieldWrapper({
958
+ component,
959
+ stepPath,
960
+ lookupOptions,
961
+ shouldAutoFocus,
962
+ }: {
963
+ readonly component: CalendarSlotFieldType
964
+ readonly stepPath: string
965
+ readonly lookupOptions: LookupOptions | undefined
966
+ readonly shouldAutoFocus: boolean
967
+ }) {
968
+ const lookupService = useLookup()
969
+ const [clientReady, setClientReady] = useState(false)
970
+ const fieldName = component.field
971
+ const resetKey = calendarSlotResourceKey(stepPath, fieldName, lookupOptions)
972
+
973
+ useEffect(() => {
974
+ setClientReady(true)
975
+ }, [])
976
+
977
+ const fallback = (
978
+ <CalendarSlotFieldView
979
+ component={component}
980
+ loading
981
+ shouldAutoFocus={shouldAutoFocus}
982
+ slots={[]}
983
+ />
984
+ )
985
+
986
+ if (!clientReady) {
987
+ return fallback
988
+ }
989
+
990
+ return (
991
+ <CalendarSlotLoadErrorBoundary
992
+ resetKey={resetKey}
993
+ onReset={() =>
994
+ clearCalendarSlotResource(
995
+ lookupService,
996
+ stepPath,
997
+ fieldName,
998
+ lookupOptions,
999
+ )
1000
+ }
1001
+ renderError={(_error, reset) => (
1002
+ <CalendarSlotFieldView
1003
+ component={component}
1004
+ error
1005
+ loading={false}
1006
+ onRetry={reset}
1007
+ shouldAutoFocus={shouldAutoFocus}
1008
+ slots={[]}
1009
+ />
1010
+ )}
1011
+ >
1012
+ <Suspense fallback={fallback}>
1013
+ <CalendarSlotFieldContent
1014
+ key={resetKey}
1015
+ component={component}
1016
+ fieldName={fieldName}
1017
+ lookupOptions={lookupOptions}
1018
+ lookupService={lookupService}
1019
+ shouldAutoFocus={shouldAutoFocus}
1020
+ stepPath={stepPath}
1021
+ />
1022
+ </Suspense>
1023
+ </CalendarSlotLoadErrorBoundary>
1024
+ )
1025
+ }
1026
+
1027
+ /**
1028
+ * Read current dependency values from the form store.
1029
+ */
1030
+ function readDepValues(
1031
+ // biome-ignore lint/suspicious/noExplicitAny: form API generic variance
1032
+ formCtx: any,
1033
+ dependencies: ReadonlyArray<string>,
1034
+ ): Record<string, string> {
1035
+ const values = formCtx.state.values as Record<string, unknown>
1036
+ const result: Record<string, string> = {}
1037
+ for (const dep of dependencies) {
1038
+ result[dep] = (values[dep] as string) ?? ""
1039
+ }
1040
+ return result
1041
+ }
1042
+
1043
+ /**
1044
+ * Dependent lookup — subscribes to dependency field values via form store,
1045
+ * calls the typed per-lookup query, and clears the field when deps change.
1046
+ */
1047
+ function DependentLookupFieldWrapper({
1048
+ component,
1049
+ shouldAutoFocus,
1050
+ }: {
1051
+ component: LookupFieldType
1052
+ shouldAutoFocus: boolean
1053
+ }) {
1054
+ const lookupService = useLookup()
1055
+ const readOnly = effectiveReadOnly(component)
1056
+ const formCtx = useFormContext()
1057
+ const field = useFieldContext<string>()
1058
+
1059
+ const dependencies = component.dependencies ?? []
1060
+ const queryName = component.queryName ?? ""
1061
+
1062
+ const [items, setItems] = useState<LookupFieldItem[]>([])
1063
+ const [loading, setLoading] = useState(false)
1064
+ const [error, setError] = useState<string | undefined>(undefined)
1065
+ const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
1066
+
1067
+ // Reactive dependency values — updated via form store subscription
1068
+ const [depValues, setDepValues] = useState<Record<string, string>>(() =>
1069
+ readDepValues(formCtx, dependencies),
1070
+ )
1071
+
1072
+ // Subscribe to form store changes to track dependency values
1073
+ useEffect(() => {
1074
+ const unsub = formCtx.store.subscribe(() => {
1075
+ setDepValues((prev) => {
1076
+ const next = readDepValues(formCtx, dependencies)
1077
+ const changed = dependencies.some((d) => prev[d] !== next[d])
1078
+ return changed ? next : prev
1079
+ })
1080
+ })
1081
+ return () => unsub.unsubscribe()
1082
+ }, [formCtx, formCtx.store, dependencies])
1083
+
1084
+ const allDepsFilled = dependencies.every((d) => Boolean(depValues[d]))
1085
+
1086
+ // Stable key for dependency values — triggers re-fetch on change
1087
+ const depKey = dependencies.map((d) => depValues[d] ?? "").join("\0")
1088
+ const prevDepKeyRef = useRef<string | null>(null)
1089
+ const lastFilterRef = useRef("")
1090
+ const clearFieldValue = useEffectEvent(() => {
1091
+ if (field.state.value) {
1092
+ field.setValue("")
1093
+ }
1094
+ })
1095
+ const getCurrentDepValues = useEffectEvent(() =>
1096
+ readDepValues(formCtx, dependencies),
1097
+ )
1098
+
1099
+ // When dependencies change: re-fetch and clear invalid selection
1100
+ useEffect(() => {
1101
+ const isInitialMount = prevDepKeyRef.current === null
1102
+ prevDepKeyRef.current = depKey
1103
+
1104
+ if (!allDepsFilled) {
1105
+ setItems([])
1106
+ return
1107
+ }
1108
+
1109
+ // Clear field value on dep change (not initial mount)
1110
+ if (!isInitialMount) {
1111
+ clearFieldValue()
1112
+ }
1113
+
1114
+ // Fetch with current filter
1115
+ const filter = lastFilterRef.current
1116
+ setLoading(true)
1117
+ setError(undefined)
1118
+
1119
+ const currentDepValues = getCurrentDepValues()
1120
+ const variables: Record<string, unknown> = {
1121
+ input: { filter, ...currentDepValues },
1122
+ limit: 20,
1123
+ }
1124
+
1125
+ lookupService
1126
+ .fetchDependentSuggestions(queryName, variables)
1127
+ .then((results) => {
1128
+ setItems(results)
1129
+ setLoading(false)
1130
+ setError(undefined)
1131
+ })
1132
+ .catch((err) => {
1133
+ console.error("Lookup fetch failed:", err)
1134
+ setItems([])
1135
+ setLoading(false)
1136
+ setError(
1137
+ err instanceof Error ? err.message : "Failed to load suggestions",
1138
+ )
1139
+ })
1140
+ }, [depKey, allDepsFilled, queryName, lookupService])
1141
+
1142
+ // Cleanup debounce timer on unmount
1143
+ useEffect(() => {
1144
+ return () => {
1145
+ if (debounceRef.current) clearTimeout(debounceRef.current)
1146
+ }
1147
+ }, [])
1148
+
1149
+ const handleSearch = (filter: string) => {
1150
+ lastFilterRef.current = filter
1151
+ if (!allDepsFilled) return
1152
+
1153
+ if (debounceRef.current) {
1154
+ clearTimeout(debounceRef.current)
1155
+ }
1156
+ debounceRef.current = setTimeout(() => {
1157
+ setLoading(true)
1158
+ setError(undefined)
1159
+
1160
+ const currentDepValues = readDepValues(formCtx, dependencies)
1161
+ const variables: Record<string, unknown> = {
1162
+ input: { filter, ...currentDepValues },
1163
+ limit: 20,
1164
+ }
1165
+
1166
+ lookupService
1167
+ .fetchDependentSuggestions(queryName, variables)
1168
+ .then((results) => {
1169
+ setItems(results)
1170
+ setLoading(false)
1171
+ })
1172
+ .catch((err) => {
1173
+ console.error("Lookup fetch failed:", err)
1174
+ setItems([])
1175
+ setLoading(false)
1176
+ setError(
1177
+ err instanceof Error ? err.message : "Failed to load suggestions",
1178
+ )
1179
+ })
1180
+ }, 300)
1181
+ }
1182
+
1183
+ return (
1184
+ <LookupField
1185
+ label={component.label}
1186
+ descriptionHtml={component.description}
1187
+ items={items}
1188
+ onSearch={handleSearch}
1189
+ loading={loading}
1190
+ error={error}
1191
+ readOnly={readOnly === true || !allDepsFilled}
1192
+ autoFocus={shouldAutoFocus}
1193
+ />
1194
+ )
1195
+ }
1196
+
1197
+ /**
1198
+ * Create path-indexed copies of itemChildren for a specific array index.
1199
+ * E.g., if field is "students" and itemChildren has "first_name" at path "students",
1200
+ * this produces "first_name" at path "students[0].first_name" for index 0.
1201
+ *
1202
+ * If parentReadOnly is true, all child fields will be marked as readonly.
1203
+ */
1204
+ function indexItemChildren(
1205
+ itemChildren: Record<string, FormComponent>,
1206
+ field: string,
1207
+ index: number,
1208
+ parentReadOnly?: boolean,
1209
+ ): Record<string, FormComponent> {
1210
+ const result: Record<string, FormComponent> = {}
1211
+ for (const [key, child] of Object.entries(itemChildren)) {
1212
+ if ("field" in child) {
1213
+ // Replace the base field path with the indexed version
1214
+ const childFieldName = child.field.startsWith(`${field}.`)
1215
+ ? child.field.slice(field.length + 1)
1216
+ : child.field === field
1217
+ ? key
1218
+ : key
1219
+ result[key] = {
1220
+ ...child,
1221
+ field: `${field}[${index}].${childFieldName}`,
1222
+ // Propagate parent readonly if specified
1223
+ ...(parentReadOnly !== undefined && { readonly: parentReadOnly }),
1224
+ } as FormComponent
1225
+ } else {
1226
+ result[key] = child
1227
+ }
1228
+ }
1229
+ return result
1230
+ }
1231
+
1232
+ /**
1233
+ * Component that renders a list/array field with add/remove functionality.
1234
+ *
1235
+ * Uses TanStack Form's array field API (pushFieldValue, removeFieldValue)
1236
+ * and recursively renders itemChildren for each array item.
1237
+ */
1238
+ function ListFieldRenderer({
1239
+ form,
1240
+ component,
1241
+ stepPath,
1242
+ enableProviderUserLookup,
1243
+ lookupOptions,
1244
+ }: {
1245
+ form: AnyAppForm
1246
+ component: ListFieldType
1247
+ stepPath?: string | undefined
1248
+ enableProviderUserLookup: boolean
1249
+ lookupOptions: LookupOptions | undefined
1250
+ }) {
1251
+ const formCtx = useFormContext()
1252
+ const field = useFieldContext<unknown[]>()
1253
+ const readOnly = effectiveReadOnly(component)
1254
+
1255
+ // Subscribe to the array field value to get the current item count
1256
+ const items = (field.state.value as unknown[]) ?? []
1257
+
1258
+ const [itemKeyState, setItemKeyState] = useState(() => ({
1259
+ keys: Array.from({ length: items.length }, (_, index) => index),
1260
+ nextKey: items.length,
1261
+ }))
1262
+ const warnedProviderUserLookupDisabled = useRef(false)
1263
+
1264
+ useEffect(() => {
1265
+ setItemKeyState((current) => {
1266
+ if (current.keys.length === items.length) return current
1267
+ if (current.keys.length > items.length) {
1268
+ return { ...current, keys: current.keys.slice(0, items.length) }
1269
+ }
1270
+
1271
+ const addedCount = items.length - current.keys.length
1272
+ return {
1273
+ keys: [
1274
+ ...current.keys,
1275
+ ...Array.from(
1276
+ { length: addedCount },
1277
+ (_, index) => current.nextKey + index,
1278
+ ),
1279
+ ],
1280
+ nextKey: current.nextKey + addedCount,
1281
+ }
1282
+ })
1283
+ }, [items.length])
1284
+
1285
+ useEffect(() => {
1286
+ if (enableProviderUserLookup) {
1287
+ warnIfListItemProviderUserLookupDisabled(
1288
+ component.itemChildren,
1289
+ warnedProviderUserLookupDisabled,
1290
+ )
1291
+ }
1292
+ }, [component.itemChildren, enableProviderUserLookup])
1293
+
1294
+ // Build default item value from the itemChildren structure
1295
+ const buildEmptyItem = (): Record<string, unknown> => {
1296
+ const item: Record<string, unknown> = {}
1297
+ for (const [key, child] of Object.entries(component.itemChildren)) {
1298
+ if ("field" in child) {
1299
+ switch (child._tag) {
1300
+ case FormComponentType.Text:
1301
+ case FormComponentType.Email:
1302
+ case FormComponentType.Phone:
1303
+ case FormComponentType.ProviderUser:
1304
+ case FormComponentType.File:
1305
+ case FormComponentType.CalendarSlot:
1306
+ item[key] = ""
1307
+ break
1308
+ case FormComponentType.Number:
1309
+ item[key] = 0
1310
+ break
1311
+ case FormComponentType.Boolean:
1312
+ item[key] = false
1313
+ break
1314
+ default:
1315
+ item[key] = ""
1316
+ }
1317
+ }
1318
+ }
1319
+ return item
1320
+ }
1321
+
1322
+ const handleAdd = () => {
1323
+ setItemKeyState((current) => ({
1324
+ keys: [...current.keys, current.nextKey],
1325
+ nextKey: current.nextKey + 1,
1326
+ }))
1327
+ formCtx.pushFieldValue(component.field as never, buildEmptyItem() as never)
1328
+ }
1329
+
1330
+ const handleRemove = (index: number) => {
1331
+ setItemKeyState((current) => ({
1332
+ ...current,
1333
+ keys: current.keys.filter((_, itemIndex) => itemIndex !== index),
1334
+ }))
1335
+ formCtx.removeFieldValue(component.field as never, index)
1336
+ }
1337
+
1338
+ return (
1339
+ <FieldSetField label={component.label}>
1340
+ {items.map((_, index) => {
1341
+ const itemKey =
1342
+ itemKeyState.keys[index] ??
1343
+ itemKeyState.nextKey + index - itemKeyState.keys.length
1344
+ const indexedChildren = indexItemChildren(
1345
+ component.itemChildren,
1346
+ component.field,
1347
+ index,
1348
+ readOnly,
1349
+ )
1350
+ return (
1351
+ <div
1352
+ key={`${component.field}-item-${itemKey}`}
1353
+ className="flex flex-col gap-4 rounded-md border p-4"
1354
+ >
1355
+ <div className="flex items-center justify-between">
1356
+ <span className="text-sm font-medium text-muted-foreground">
1357
+ {component.label} #{index + 1}
1358
+ </span>
1359
+ {readOnly !== true && (
1360
+ <Button
1361
+ type="button"
1362
+ variant="ghost"
1363
+ size="sm"
1364
+ onClick={() => handleRemove(index)}
1365
+ >
1366
+ Remove
1367
+ </Button>
1368
+ )}
1369
+ </div>
1370
+ {walkClientRepresentation(
1371
+ form,
1372
+ indexedChildren,
1373
+ false,
1374
+ stepPath,
1375
+ false,
1376
+ lookupOptions,
1377
+ )}
1378
+ </div>
1379
+ )
1380
+ })}
1381
+ {readOnly !== true && (
1382
+ <Button type="button" variant="outline" onClick={handleAdd}>
1383
+ {component.addButtonLabel ?? `Add ${component.label.toLowerCase()}`}
1384
+ </Button>
1385
+ )}
1386
+ </FieldSetField>
1387
+ )
1388
+ }
1389
+
1390
+ const warnIfListItemProviderUserLookupDisabled = (
1391
+ children: Record<string, FormComponent>,
1392
+ warned: { current: boolean },
1393
+ ) => {
1394
+ const hasProviderUserField = Object.values(children).some(
1395
+ componentContainsProviderUser,
1396
+ )
1397
+ if (
1398
+ hasProviderUserField &&
1399
+ !warned.current &&
1400
+ process.env["NODE_ENV"] !== "production"
1401
+ ) {
1402
+ warned.current = true
1403
+ console.warn(
1404
+ "ProviderUserField lookup is disabled inside ListField until nested submit-time authorization is supported.",
1405
+ )
1406
+ }
1407
+ }
1408
+
1409
+ const componentContainsProviderUser = (component: FormComponent): boolean => {
1410
+ switch (component._tag) {
1411
+ case FormComponentType.ProviderUser:
1412
+ return true
1413
+ case FormComponentType.FieldSet:
1414
+ return Object.values(component.children).some(
1415
+ componentContainsProviderUser,
1416
+ )
1417
+ case FormComponentType.List:
1418
+ case FormComponentType.Table:
1419
+ return Object.values(component.itemChildren).some(
1420
+ componentContainsProviderUser,
1421
+ )
1422
+ default:
1423
+ return false
1424
+ }
1425
+ }
1426
+
1427
+ // Global map of in-flight script loads keyed by src URL.
1428
+ // Ensures concurrent renders share a single load promise per script.
1429
+ const scriptLoadPromises = new Map<string, Promise<void>>()
1430
+
1431
+ function loadScript(src: string, async: boolean): Promise<void> {
1432
+ const existing = scriptLoadPromises.get(src)
1433
+ if (existing) return existing
1434
+
1435
+ const promise = new Promise<void>((resolve, reject) => {
1436
+ // Script may already be in the DOM from a previous page load
1437
+ if (document.querySelector(`script[src="${src}"]`)) {
1438
+ resolve()
1439
+ return
1440
+ }
1441
+
1442
+ const el = document.createElement("script")
1443
+ el.src = src
1444
+ el.async = async
1445
+ el.onload = () => resolve()
1446
+ el.onerror = () => reject(new Error(`Failed to load script: ${src}`))
1447
+ document.head.appendChild(el)
1448
+ })
1449
+
1450
+ scriptLoadPromises.set(src, promise)
1451
+ return promise
1452
+ }
1453
+
1454
+ /**
1455
+ * Minimal error boundary for plugin renderers.
1456
+ * Catches render errors from lazy-loaded plugin components.
1457
+ */
1458
+ class PluginErrorBoundary extends React.Component<
1459
+ { pluginType: string; children: React.ReactNode },
1460
+ { error: string | null }
1461
+ > {
1462
+ constructor(props: { pluginType: string; children: React.ReactNode }) {
1463
+ super(props)
1464
+ this.state = { error: null }
1465
+ }
1466
+
1467
+ static getDerivedStateFromError(error: Error): { error: string } {
1468
+ return { error: error.message }
1469
+ }
1470
+
1471
+ override render() {
1472
+ if (this.state.error) {
1473
+ return (
1474
+ <div className="rounded-md border border-red-300 bg-red-50 p-3 text-sm text-red-800">
1475
+ Error rendering plugin "{this.props.pluginType}": {this.state.error}
1476
+ </div>
1477
+ )
1478
+ }
1479
+ return this.props.children
1480
+ }
1481
+ }
1482
+
1483
+ /**
1484
+ * Component that loads external scripts before rendering a plugin field.
1485
+ *
1486
+ * Scripts are loaded lazily when the field is first encountered, preventing
1487
+ * unnecessary network requests for plugins not used in the current form.
1488
+ */
1489
+ function PluginFieldRenderer({
1490
+ form,
1491
+ component,
1492
+ shouldAutoFocus,
1493
+ todoId,
1494
+ stepPath,
1495
+ }: {
1496
+ form: AnyAppForm
1497
+ component: PluginField
1498
+ shouldAutoFocus: boolean
1499
+ todoId?: string
1500
+ stepPath?: string
1501
+ }) {
1502
+ const [scriptsLoaded, setScriptsLoaded] = useState(false)
1503
+ const [error, setError] = useState<string | null>(null)
1504
+
1505
+ useEffect(() => {
1506
+ if (!component.scripts || component.scripts.length === 0) {
1507
+ setScriptsLoaded(true)
1508
+ return
1509
+ }
1510
+
1511
+ Promise.all(
1512
+ component.scripts.map((s) => loadScript(s.src, s.async ?? true)),
1513
+ ).then(
1514
+ () => setScriptsLoaded(true),
1515
+ (err) =>
1516
+ setError(err instanceof Error ? err.message : "Failed to load scripts"),
1517
+ )
1518
+ }, [component.scripts])
1519
+
1520
+ if (error) {
1521
+ return (
1522
+ <div className="rounded-md border border-red-300 bg-red-50 p-3 text-sm text-red-800">
1523
+ Error loading plugin: {error}
1524
+ </div>
1525
+ )
1526
+ }
1527
+
1528
+ if (!scriptsLoaded) {
1529
+ return <div>Loading plugin...</div>
1530
+ }
1531
+
1532
+ const renderer = getPluginRenderer(component.pluginType)
1533
+ if (!renderer) {
1534
+ return (
1535
+ <div>No renderer registered for plugin type: {component.pluginType}</div>
1536
+ )
1537
+ }
1538
+
1539
+ return (
1540
+ <PluginErrorBoundary pluginType={component.pluginType}>
1541
+ {renderer(
1542
+ form,
1543
+ component,
1544
+ shouldAutoFocus,
1545
+ todoId !== undefined || stepPath !== undefined
1546
+ ? {
1547
+ ...(todoId !== undefined && { todoId }),
1548
+ ...(stepPath !== undefined && { stepPath }),
1549
+ }
1550
+ : undefined,
1551
+ )}
1552
+ </PluginErrorBoundary>
1553
+ )
1554
+ }