@processfocus/runtime-local 0.1.0-next.2 → 0.1.0-next.3
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.
- package/README.md +48 -253
- package/dist/authentication-server.mjs +52 -84
- package/dist/{chunk-yhzbn4vx.js → chunk-04r0t2mb.js} +34324 -49067
- package/dist/chunk-727y6qkb.js +156 -0
- package/dist/chunk-bg5r4wpv.js +4755 -0
- package/dist/chunk-cbd36jq1.js +512 -0
- package/dist/chunk-d4ctj079.js +241 -0
- package/dist/{chunk-352j1ayk.js → chunk-r5s2v669.js} +51753 -36263
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +12 -12
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +31 -21
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +1 -12
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/client-layout.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/executions-client.tsx +1637 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +5 -7
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +4 -1589
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +41 -33
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +11 -17
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +145 -19
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +10 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +29 -13
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +22 -28
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-load-error.tsx +49 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-schema-form.tsx +28 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +7 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +4 -6
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +45 -142
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +10 -20
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-process-dialog.tsx +72 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh-provider.tsx +65 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +162 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +4 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +4 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +15 -18
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +12 -6
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +7 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +26 -48
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +4 -7
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client-layout.tsx +28 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +1 -3
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +193 -117
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +7 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +60 -204
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +12 -51
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +27 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +5 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +0 -5
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +26 -19
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +5 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +85 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +12 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +66 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +41 -13
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +442 -365
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +8 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +61 -43
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +6 -67
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +111 -189
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-page.tsx +86 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +141 -256
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +6 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +30 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +2 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +47 -54
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +37 -54
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +4 -25
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +4 -1315
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/to-dos-client.tsx +1282 -0
- package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +81 -65
- package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +8 -2
- package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +0 -1
- package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +10 -5
- package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +1 -3
- package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +0 -1
- package/dist/dashboard-source/apps/frontend/app/api/auth/revalidate-google/route.ts +68 -0
- package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +1 -3
- package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +25 -7
- package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +1 -2
- package/dist/dashboard-source/apps/frontend/app/api/public/start/[address]/route.ts +49 -0
- package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +4 -3
- package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +15 -4
- package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +11 -4
- package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +2 -1
- package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +31 -18
- package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +5 -1
- package/dist/dashboard-source/apps/frontend/app/login/page.tsx +4 -4
- package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +11 -6
- package/dist/dashboard-source/apps/frontend/app/login/passkey-help/page.tsx +67 -0
- package/dist/dashboard-source/apps/frontend/app/mcp/[[...endpoint]]/route.ts +47 -0
- package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +44 -25
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/form/page.tsx +10 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/layout.tsx +32 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-client.tsx +319 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-content.tsx +41 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page.tsx +10 -0
- package/dist/dashboard-source/apps/frontend/app/public.css +1 -1
- package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +17 -0
- package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +9 -15
- package/dist/dashboard-source/apps/frontend/components/Header.tsx +4 -8
- package/dist/dashboard-source/apps/frontend/components/anonymous-page-link.tsx +57 -0
- package/dist/dashboard-source/apps/frontend/components/anonymous-start-form.tsx +24 -0
- package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +21 -7
- package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +12 -7
- package/dist/dashboard-source/apps/frontend/components/browser-only.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +24 -13
- package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +22 -2
- package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +52 -45
- package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +38 -11
- package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +26 -15
- package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +5 -0
- package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +21 -10
- package/dist/dashboard-source/apps/frontend/hooks/use-process-draft.ts +173 -0
- package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +1 -3
- package/dist/dashboard-source/apps/frontend/lib/anonymous-page-form-values.ts +6 -0
- package/dist/dashboard-source/apps/frontend/lib/anonymous-page-server.ts +65 -0
- package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +9 -3
- package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +7 -340
- package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +2 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +9 -7
- package/dist/dashboard-source/apps/frontend/lib/auth/google-revalidation.ts +111 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +28 -30
- package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +10 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +4 -4
- package/dist/dashboard-source/apps/frontend/lib/auth/session-admission.ts +11 -7
- package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +27 -10
- package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -9
- package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +25 -3
- package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +112 -21
- package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +1 -8
- package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +6 -2
- package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +8 -2
- package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +16 -4
- package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/effect/navigation.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/effect/page-runtime.ts +29 -0
- package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +18 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +19 -23
- package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +9 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +12 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +20 -18
- package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +32 -16
- package/dist/dashboard-source/apps/frontend/lib/embed-form-server.ts +35 -0
- package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +10 -103
- package/dist/dashboard-source/apps/frontend/lib/forms/invitation.ts +43 -0
- package/dist/dashboard-source/apps/frontend/lib/forms/provider-user.ts +64 -0
- package/dist/dashboard-source/apps/frontend/lib/frontend-form-loaders.ts +40 -0
- package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +1 -33
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +123 -33
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +169 -30
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/anonymous-page.ts +27 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +34 -29
- package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +82 -10
- package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +2 -5
- package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +25 -4
- package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +11 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +13 -104
- package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +11 -4
- package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +1 -3
- package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/list-detail-selection.ts +54 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/executions.ts +110 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/list-writes.ts +395 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/lists.ts +263 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/oauth.ts +900 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +42 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/processes.ts +436 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/read-tool.ts +72 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/result.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/server.ts +71 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/store.ts +193 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +237 -0
- package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +0 -5
- package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +0 -2
- package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +6 -4
- package/dist/dashboard-source/apps/frontend/lib/organisation-form-loaders.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +39 -139
- package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +17 -16
- package/dist/dashboard-source/apps/frontend/lib/query-client.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +1 -77
- package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +3 -7
- package/dist/dashboard-source/apps/frontend/next.config.ts +33 -13
- package/dist/dashboard-source/apps/frontend/package.json +48 -47
- package/dist/dashboard-source/apps/frontend/proxy.ts +72 -14
- package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +0 -3
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +165 -233
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +4 -3
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +111 -75
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +14 -18
- package/dist/dashboard-source/modules/auth-policy/src/index.ts +1 -0
- package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +19 -37
- package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +33 -29
- package/dist/dashboard-source/modules/auth-policy/src/lib/policy-revision.ts +23 -0
- package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +24 -49
- package/dist/dashboard-source/modules/auth-session/src/index.ts +4 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/project-subscription.ts +13 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +10 -2
- package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +82 -8
- package/dist/dashboard-source/modules/auth-session/src/lib/workload-access.ts +48 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/workload-audit.ts +52 -0
- package/dist/dashboard-source/modules/aws-common/src/index.ts +0 -1
- package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +6 -9
- package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +5 -3
- package/dist/dashboard-source/modules/form/src/index.ts +1 -10
- package/dist/dashboard-source/modules/form/src/lib/effect-schema-form.tsx +1271 -0
- package/dist/dashboard-source/modules/form/src/lib/form-actions.ts +26 -0
- package/dist/dashboard-source/modules/form/src/lib/form-prefill.tsx +79 -0
- package/dist/dashboard-source/modules/form/src/lib/initial-focus.ts +31 -0
- package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +18 -0
- package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +4 -0
- package/dist/dashboard-source/modules/form/src/lib/plugin-scripts.ts +26 -0
- package/dist/dashboard-source/modules/form/src/lib/registered-plugin-field.tsx +57 -0
- package/dist/dashboard-source/modules/form/src/lib/schema-lookup.tsx +124 -0
- package/dist/dashboard-source/modules/form/src/lib/schema-typeahead.tsx +522 -0
- package/dist/dashboard-source/modules/form/src/lib/validation-logic.ts +172 -0
- package/dist/dashboard-source/modules/form-schema/src/index.ts +4 -1
- package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +19 -14
- package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +13 -11
- package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +15 -13
- package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +14 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/form-presentation.ts +33 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +186 -80
- package/dist/dashboard-source/modules/form-schema/src/lib/number-from-string.ts +26 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +8 -7
- package/dist/dashboard-source/modules/form-schema/src/lib/public-completion-correction.ts +7 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/search-lookup-items.ts +27 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/index.ts +5 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/executable-rules.ts +379 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/form-submission-schema.ts +475 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/json-schema.ts +58 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/schema-defaults.ts +158 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/submission-utils.ts +75 -0
- package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +46 -0
- package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +37 -30
- package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +9 -1
- package/dist/dashboard-source/modules/openauth/src/client.ts +25 -17
- package/dist/dashboard-source/modules/openauth/src/util.ts +16 -0
- package/dist/dashboard-source/modules/{aws-common/src/lib/project-balance-admission.ts → project-accounting/src/admission.ts} +4 -8
- package/dist/dashboard-source/modules/realtime-client/src/appsync-client.ts +377 -0
- package/dist/dashboard-source/modules/realtime-client/src/index.ts +5 -0
- package/dist/dashboard-source/modules/realtime-client/src/subscription-presence.ts +163 -0
- package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +6 -24
- package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +28 -21
- package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +25 -18
- package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +60 -10
- package/dist/dashboard-source/modules/shadcn-components/src/index.ts +18 -2
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-calendar.tsx +93 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +147 -48
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-time-display.tsx +272 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/local-date-time-input.tsx +108 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +237 -351
- package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +2 -1
- package/dist/dashboard-source.json +48 -47
- package/dist/graphql-server.mjs +245 -200
- package/dist/job-worker-supervisor.mjs +262 -0
- package/dist/job-worker.mjs +234 -133
- package/dist/main.mjs +23 -4
- package/dist/prepare-dashboard.mjs +8 -8
- package/dist/resources/cedar/policies.cedar +80 -38
- package/dist/resources/cedar/schema.cedarschema +39 -21
- package/dist/resources/graphql-schema/rxdb.graphql +2 -0
- package/dist/resources/graphql-schema/system.graphql +190 -51
- package/package.json +64 -62
- package/dist/chunk-6ntmymmx.js +0 -85
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +0 -20
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +0 -105
- package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +0 -189
- package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +0 -79
- package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +0 -56
- package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +0 -152
- package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +0 -1421
- package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +0 -85
- package/dist/dashboard-source/modules/form/src/lib/walker.tsx +0 -1549
- package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +0 -440
- package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +0 -13
- package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +0 -336
- package/dist/dashboard-source/modules/form-rule/src/index.ts +0 -21
- package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +0 -531
- package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +0 -102
- package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +0 -121
- package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +0 -45
|
@@ -1,1421 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AnyFieldMeta,
|
|
3
|
-
type ValidationLogicProps,
|
|
4
|
-
defaultValidationLogic,
|
|
5
|
-
} from "@tanstack/react-form"
|
|
6
|
-
import type React from "react"
|
|
7
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
8
|
-
import type { ClientFormDefinition } from "../../../form-client-representation/src/lib/client-form-definition.ts"
|
|
9
|
-
import {
|
|
10
|
-
type FormComponent,
|
|
11
|
-
FormComponentType,
|
|
12
|
-
} from "../../../form-client-representation/src/lib/types.ts"
|
|
13
|
-
import { evaluateFormRules } from "../../../form-rule/src/index.ts"
|
|
14
|
-
import { useAppForm } from "../../../shadcn-components/src/index.ts"
|
|
15
|
-
import { useLocalStorage } from "../hooks/use-local-storage.ts"
|
|
16
|
-
import {
|
|
17
|
-
type JsonSchemaRoot,
|
|
18
|
-
createStandardSchemaFromJsonSchema,
|
|
19
|
-
} from "./ajv-standard-schema.ts"
|
|
20
|
-
import { friendlyFormValidationMessage } from "./friendly-validation-message.ts"
|
|
21
|
-
import type { LookupOptions } from "./lookup-context.tsx"
|
|
22
|
-
import { walkClientRepresentation } from "./walker.tsx"
|
|
23
|
-
|
|
24
|
-
type FormComponentRecord = Readonly<Record<string, FormComponent>>
|
|
25
|
-
|
|
26
|
-
type ProjectedTargetState = {
|
|
27
|
-
readonly hidden?: boolean
|
|
28
|
-
readonly disabled?: boolean
|
|
29
|
-
readonly required?: boolean
|
|
30
|
-
readonly label?: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const REQUIRED_FIELD_MESSAGE = "This field is required."
|
|
34
|
-
|
|
35
|
-
const pathKey = (path: readonly (string | number)[]) => JSON.stringify(path)
|
|
36
|
-
|
|
37
|
-
const pathToFieldName = (path: readonly (string | number)[]): string =>
|
|
38
|
-
path.reduce<string>((result, segment) => {
|
|
39
|
-
if (typeof segment === "number") {
|
|
40
|
-
return `${result}[${segment}]`
|
|
41
|
-
}
|
|
42
|
-
return result ? `${result}.${segment}` : segment
|
|
43
|
-
}, "")
|
|
44
|
-
|
|
45
|
-
const fieldNameToPath = (fieldName: string): readonly (string | number)[] => {
|
|
46
|
-
const path: Array<string | number> = []
|
|
47
|
-
const matcher = /([^.[\]]+)|\[(\d+)\]/g
|
|
48
|
-
let match = matcher.exec(fieldName)
|
|
49
|
-
while (match !== null) {
|
|
50
|
-
if (match[1] !== undefined) {
|
|
51
|
-
path.push(match[1])
|
|
52
|
-
} else if (match[2] !== undefined) {
|
|
53
|
-
path.push(Number(match[2]))
|
|
54
|
-
}
|
|
55
|
-
match = matcher.exec(fieldName)
|
|
56
|
-
}
|
|
57
|
-
return path
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const initializeFormValues = (
|
|
61
|
-
defaultValues: Record<string, unknown>,
|
|
62
|
-
savedValues: Record<string, unknown>,
|
|
63
|
-
): Record<string, unknown> => ({ ...defaultValues, ...savedValues })
|
|
64
|
-
|
|
65
|
-
const baseComponentStateEntries = (
|
|
66
|
-
components: FormComponentRecord,
|
|
67
|
-
): Array<{
|
|
68
|
-
readonly path: readonly (string | number)[]
|
|
69
|
-
readonly state: ProjectedTargetState
|
|
70
|
-
}> => {
|
|
71
|
-
const entries: Array<{
|
|
72
|
-
readonly path: readonly (string | number)[]
|
|
73
|
-
readonly state: ProjectedTargetState
|
|
74
|
-
}> = []
|
|
75
|
-
|
|
76
|
-
const visit = (
|
|
77
|
-
key: string,
|
|
78
|
-
component: FormComponent,
|
|
79
|
-
parentPath: readonly (string | number)[],
|
|
80
|
-
) => {
|
|
81
|
-
// Rule targets are authored as form-tree paths. Submitted field names can
|
|
82
|
-
// differ for flattened wrappers, so projection must not key by `field`.
|
|
83
|
-
const path = [...parentPath, key]
|
|
84
|
-
const state = {
|
|
85
|
-
...(component.hidden !== undefined && { hidden: component.hidden }),
|
|
86
|
-
...(component.disabled !== undefined && { disabled: component.disabled }),
|
|
87
|
-
...(component.required !== undefined && { required: component.required }),
|
|
88
|
-
...(component.label !== undefined && { label: component.label }),
|
|
89
|
-
}
|
|
90
|
-
if (Object.keys(state).length > 0) {
|
|
91
|
-
entries.push({ path, state })
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (component._tag === FormComponentType.FieldSet) {
|
|
95
|
-
for (const [childKey, child] of Object.entries(component.children)) {
|
|
96
|
-
visit(childKey, child, path)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
component._tag === FormComponentType.List ||
|
|
102
|
-
component._tag === FormComponentType.Table
|
|
103
|
-
) {
|
|
104
|
-
for (const [childKey, child] of Object.entries(component.itemChildren)) {
|
|
105
|
-
visit(childKey, child, path)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (const [key, component] of Object.entries(components)) {
|
|
111
|
-
visit(key, component, [])
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return entries
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const projectionStateByPath = (
|
|
118
|
-
formDefinition: ClientFormDefinition,
|
|
119
|
-
values: Record<string, unknown>,
|
|
120
|
-
baseValues: Record<string, unknown> = values,
|
|
121
|
-
) => {
|
|
122
|
-
const baseState = baseComponentStateEntries(formDefinition.components)
|
|
123
|
-
const result = evaluateFormRules({
|
|
124
|
-
rules: formDefinition.rules,
|
|
125
|
-
values,
|
|
126
|
-
baseValues,
|
|
127
|
-
baseState,
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
return new Map(
|
|
131
|
-
result.targets.map((entry) => [pathKey(entry.path), entry.state]),
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const withProjectedState = (
|
|
136
|
-
component: FormComponent,
|
|
137
|
-
state:
|
|
138
|
-
| {
|
|
139
|
-
readonly hidden?: boolean
|
|
140
|
-
readonly disabled?: boolean
|
|
141
|
-
readonly required?: boolean
|
|
142
|
-
readonly label?: string
|
|
143
|
-
}
|
|
144
|
-
| undefined,
|
|
145
|
-
): FormComponent =>
|
|
146
|
-
({
|
|
147
|
-
...component,
|
|
148
|
-
...(state?.hidden !== undefined && { hidden: state.hidden }),
|
|
149
|
-
...(state?.disabled !== undefined && { disabled: state.disabled }),
|
|
150
|
-
...(state?.required !== undefined && { required: state.required }),
|
|
151
|
-
...(state?.label !== undefined && { label: state.label }),
|
|
152
|
-
}) as FormComponent
|
|
153
|
-
|
|
154
|
-
const projectFormComponentsWithState = (
|
|
155
|
-
components: FormComponentRecord,
|
|
156
|
-
stateByPath: ReadonlyMap<string, ProjectedTargetState>,
|
|
157
|
-
): FormComponentRecord => {
|
|
158
|
-
const project = (
|
|
159
|
-
key: string,
|
|
160
|
-
component: FormComponent,
|
|
161
|
-
parentPath: readonly (string | number)[],
|
|
162
|
-
inheritedHidden: boolean,
|
|
163
|
-
inheritedDisabled: boolean,
|
|
164
|
-
): FormComponent => {
|
|
165
|
-
const path = [...parentPath, key]
|
|
166
|
-
const projectedState = withProjectedState(
|
|
167
|
-
component,
|
|
168
|
-
stateByPath.get(pathKey(path)),
|
|
169
|
-
)
|
|
170
|
-
const projected = withProjectedState(projectedState, {
|
|
171
|
-
// Apply own rule state first, then let ancestor state win. Structural
|
|
172
|
-
// disabledness intentionally cannot be opted out by child targets.
|
|
173
|
-
...(inheritedHidden ? { hidden: true } : {}),
|
|
174
|
-
...(inheritedDisabled ? { disabled: true } : {}),
|
|
175
|
-
})
|
|
176
|
-
const hidden = projected.hidden === true
|
|
177
|
-
const disabled = projected.disabled === true
|
|
178
|
-
|
|
179
|
-
if (projected._tag === FormComponentType.FieldSet) {
|
|
180
|
-
return {
|
|
181
|
-
...projected,
|
|
182
|
-
children: Object.fromEntries(
|
|
183
|
-
Object.entries(projected.children).map(([childKey, child]) => [
|
|
184
|
-
childKey,
|
|
185
|
-
project(childKey, child, path, hidden, disabled),
|
|
186
|
-
]),
|
|
187
|
-
),
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
projected._tag === FormComponentType.List ||
|
|
193
|
-
projected._tag === FormComponentType.Table
|
|
194
|
-
) {
|
|
195
|
-
return {
|
|
196
|
-
...projected,
|
|
197
|
-
itemChildren: Object.fromEntries(
|
|
198
|
-
Object.entries(projected.itemChildren).map(([childKey, child]) => [
|
|
199
|
-
childKey,
|
|
200
|
-
project(childKey, child, path, hidden, disabled),
|
|
201
|
-
]),
|
|
202
|
-
),
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return projected
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return Object.fromEntries(
|
|
210
|
-
Object.entries(components).map(([key, component]) => [
|
|
211
|
-
key,
|
|
212
|
-
project(key, component, [], false, false),
|
|
213
|
-
]),
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export const projectFormComponents = (
|
|
218
|
-
formDefinition: ClientFormDefinition,
|
|
219
|
-
values: Record<string, unknown>,
|
|
220
|
-
baseValues: Record<string, unknown> = values,
|
|
221
|
-
): FormComponentRecord =>
|
|
222
|
-
projectFormComponentsWithState(
|
|
223
|
-
formDefinition.components,
|
|
224
|
-
projectionStateByPath(formDefinition, values, baseValues),
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Subset of TanStack Form's AnyFieldMeta that we access in validation logic.
|
|
229
|
-
* This provides a stable interface that won't break if TanStack Form's internal
|
|
230
|
-
* types change, while still maintaining type safety.
|
|
231
|
-
*/
|
|
232
|
-
type FieldMetaSubset = Pick<
|
|
233
|
-
AnyFieldMeta,
|
|
234
|
-
"isDirty" | "errors" | "isDefaultValue"
|
|
235
|
-
>
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Runtime type guard to validate that a value conforms to FieldMetaSubset.
|
|
239
|
-
* Used defensively when accessing form.state.fieldMeta to ensure the properties
|
|
240
|
-
* we depend on actually exist at runtime.
|
|
241
|
-
*/
|
|
242
|
-
const isFieldMetaSubset = (meta: unknown): meta is FieldMetaSubset => {
|
|
243
|
-
if (typeof meta !== "object" || meta === null) return false
|
|
244
|
-
const m = meta as Record<string, unknown>
|
|
245
|
-
return (
|
|
246
|
-
"isDirty" in m &&
|
|
247
|
-
typeof m["isDirty"] === "boolean" &&
|
|
248
|
-
"errors" in m &&
|
|
249
|
-
Array.isArray(m["errors"]) &&
|
|
250
|
-
"isDefaultValue" in m &&
|
|
251
|
-
typeof m["isDefaultValue"] === "boolean"
|
|
252
|
-
)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Helper to safely get fieldMeta as a Record of FieldMetaSubset.
|
|
257
|
-
* Returns undefined if fieldMeta is not available or empty.
|
|
258
|
-
*/
|
|
259
|
-
const getFieldMetaRecord = (
|
|
260
|
-
fieldMeta: unknown,
|
|
261
|
-
): Record<string, FieldMetaSubset> | undefined => {
|
|
262
|
-
if (typeof fieldMeta !== "object" || fieldMeta === null) return undefined
|
|
263
|
-
const record = fieldMeta as Record<string, unknown>
|
|
264
|
-
// Filter to only entries that match our expected shape
|
|
265
|
-
const validEntries = Object.entries(record).filter(([, value]) =>
|
|
266
|
-
isFieldMetaSubset(value),
|
|
267
|
-
)
|
|
268
|
-
if (validEntries.length === 0) return undefined
|
|
269
|
-
return Object.fromEntries(validEntries) as Record<string, FieldMetaSubset>
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export const getRenderableFieldNames = (
|
|
273
|
-
components: FormComponentRecord,
|
|
274
|
-
): Set<string> => {
|
|
275
|
-
const fieldNames = new Set<string>()
|
|
276
|
-
|
|
277
|
-
const visit = (component: FormComponent) => {
|
|
278
|
-
switch (component._tag) {
|
|
279
|
-
case FormComponentType.Text:
|
|
280
|
-
case FormComponentType.TextArea:
|
|
281
|
-
case FormComponentType.Number:
|
|
282
|
-
case FormComponentType.Date:
|
|
283
|
-
case FormComponentType.Email:
|
|
284
|
-
case FormComponentType.Phone:
|
|
285
|
-
case FormComponentType.ProviderUser:
|
|
286
|
-
case FormComponentType.Boolean:
|
|
287
|
-
case FormComponentType.Select:
|
|
288
|
-
case FormComponentType.Radio:
|
|
289
|
-
case FormComponentType.File:
|
|
290
|
-
case FormComponentType.Lookup:
|
|
291
|
-
case FormComponentType.CalendarSlot:
|
|
292
|
-
case FormComponentType.List:
|
|
293
|
-
case FormComponentType.Table:
|
|
294
|
-
case FormComponentType.Plugin:
|
|
295
|
-
fieldNames.add(component.field)
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
-
case FormComponentType.FieldSet:
|
|
299
|
-
Object.values(component.children).forEach(visit)
|
|
300
|
-
return
|
|
301
|
-
|
|
302
|
-
case FormComponentType.Static:
|
|
303
|
-
case FormComponentType.Link:
|
|
304
|
-
case FormComponentType.MetricBreakdown:
|
|
305
|
-
return
|
|
306
|
-
|
|
307
|
-
default: {
|
|
308
|
-
const _exhaustive: never = component
|
|
309
|
-
return _exhaustive
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
Object.values(components).forEach(visit)
|
|
315
|
-
return fieldNames
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const getMetricBreakdownFieldNames = (
|
|
319
|
-
components: FormComponentRecord,
|
|
320
|
-
): Set<string> => {
|
|
321
|
-
const fieldNames = new Set<string>()
|
|
322
|
-
|
|
323
|
-
const visit = (component: FormComponent) => {
|
|
324
|
-
switch (component._tag) {
|
|
325
|
-
case FormComponentType.FieldSet:
|
|
326
|
-
Object.values(component.children).forEach(visit)
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
case FormComponentType.MetricBreakdown:
|
|
330
|
-
fieldNames.add(component.field)
|
|
331
|
-
return
|
|
332
|
-
|
|
333
|
-
case FormComponentType.Text:
|
|
334
|
-
case FormComponentType.TextArea:
|
|
335
|
-
case FormComponentType.Number:
|
|
336
|
-
case FormComponentType.Date:
|
|
337
|
-
case FormComponentType.Email:
|
|
338
|
-
case FormComponentType.Phone:
|
|
339
|
-
case FormComponentType.ProviderUser:
|
|
340
|
-
case FormComponentType.Boolean:
|
|
341
|
-
case FormComponentType.Select:
|
|
342
|
-
case FormComponentType.Radio:
|
|
343
|
-
case FormComponentType.File:
|
|
344
|
-
case FormComponentType.Lookup:
|
|
345
|
-
case FormComponentType.CalendarSlot:
|
|
346
|
-
case FormComponentType.List:
|
|
347
|
-
case FormComponentType.Table:
|
|
348
|
-
case FormComponentType.Plugin:
|
|
349
|
-
case FormComponentType.Static:
|
|
350
|
-
case FormComponentType.Link:
|
|
351
|
-
return
|
|
352
|
-
|
|
353
|
-
default: {
|
|
354
|
-
const _exhaustive: never = component
|
|
355
|
-
return _exhaustive
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
Object.values(components).forEach(visit)
|
|
361
|
-
return fieldNames
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export const normalizeSubmitErrors = (
|
|
365
|
-
errors: FieldError[],
|
|
366
|
-
renderableFieldNames: Set<string>,
|
|
367
|
-
hiddenFieldNames: Set<string> = new Set(),
|
|
368
|
-
): FieldError[] =>
|
|
369
|
-
errors.flatMap((error) => {
|
|
370
|
-
if (hiddenFieldNames.has(error.field)) {
|
|
371
|
-
return []
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const message = friendlyFormValidationMessage(error.message)
|
|
375
|
-
|
|
376
|
-
if (error.field === "" || renderableFieldNames.has(error.field)) {
|
|
377
|
-
return [{ ...error, message }]
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return [
|
|
381
|
-
{
|
|
382
|
-
field: "",
|
|
383
|
-
// Preserve the field key for non-rendered fields while still avoiding
|
|
384
|
-
// raw validator wording in the message shown to users.
|
|
385
|
-
message: `${error.field}: ${message}`,
|
|
386
|
-
},
|
|
387
|
-
]
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
const collectHiddenFieldNames = (
|
|
391
|
-
components: FormComponentRecord,
|
|
392
|
-
): Set<string> => {
|
|
393
|
-
const fieldNames = new Set<string>()
|
|
394
|
-
|
|
395
|
-
const visit = (component: FormComponent, inheritedHidden: boolean) => {
|
|
396
|
-
const hidden = inheritedHidden || component.hidden === true
|
|
397
|
-
if ("field" in component && hidden) {
|
|
398
|
-
fieldNames.add(component.field)
|
|
399
|
-
}
|
|
400
|
-
if (component._tag === FormComponentType.FieldSet) {
|
|
401
|
-
for (const child of Object.values(component.children)) {
|
|
402
|
-
visit(child, hidden)
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (
|
|
406
|
-
component._tag === FormComponentType.List ||
|
|
407
|
-
component._tag === FormComponentType.Table
|
|
408
|
-
) {
|
|
409
|
-
for (const child of Object.values(component.itemChildren)) {
|
|
410
|
-
visit(child, hidden)
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
for (const component of Object.values(components)) {
|
|
416
|
-
visit(component, false)
|
|
417
|
-
}
|
|
418
|
-
return fieldNames
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const collectRequiredFieldNames = (
|
|
422
|
-
components: FormComponentRecord,
|
|
423
|
-
): Set<string> => {
|
|
424
|
-
const fieldNames = new Set<string>()
|
|
425
|
-
|
|
426
|
-
const visit = (component: FormComponent, inheritedHidden: boolean) => {
|
|
427
|
-
const hidden = inheritedHidden || component.hidden === true
|
|
428
|
-
if (!hidden && "field" in component && component.required === true) {
|
|
429
|
-
fieldNames.add(component.field)
|
|
430
|
-
}
|
|
431
|
-
if (component._tag === FormComponentType.FieldSet) {
|
|
432
|
-
for (const child of Object.values(component.children)) {
|
|
433
|
-
visit(child, hidden)
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
if (
|
|
437
|
-
component._tag === FormComponentType.List ||
|
|
438
|
-
component._tag === FormComponentType.Table
|
|
439
|
-
) {
|
|
440
|
-
for (const child of Object.values(component.itemChildren)) {
|
|
441
|
-
visit(child, hidden)
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
for (const component of Object.values(components)) {
|
|
447
|
-
visit(component, false)
|
|
448
|
-
}
|
|
449
|
-
return fieldNames
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const collectDisabledFieldNames = (
|
|
453
|
-
components: FormComponentRecord,
|
|
454
|
-
): Set<string> => {
|
|
455
|
-
const renderableFieldNames = getRenderableFieldNames(components)
|
|
456
|
-
const fieldNames = new Set<string>()
|
|
457
|
-
|
|
458
|
-
const visit = (component: FormComponent, inheritedDisabled: boolean) => {
|
|
459
|
-
const disabled = inheritedDisabled || component.disabled === true
|
|
460
|
-
if (
|
|
461
|
-
"field" in component &&
|
|
462
|
-
disabled &&
|
|
463
|
-
renderableFieldNames.has(component.field)
|
|
464
|
-
) {
|
|
465
|
-
fieldNames.add(component.field)
|
|
466
|
-
}
|
|
467
|
-
if (component._tag === FormComponentType.FieldSet) {
|
|
468
|
-
for (const child of Object.values(component.children)) {
|
|
469
|
-
visit(child, disabled)
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
if (
|
|
473
|
-
component._tag === FormComponentType.List ||
|
|
474
|
-
component._tag === FormComponentType.Table
|
|
475
|
-
) {
|
|
476
|
-
for (const child of Object.values(component.itemChildren)) {
|
|
477
|
-
visit(child, disabled)
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
for (const component of Object.values(components)) {
|
|
483
|
-
visit(component, false)
|
|
484
|
-
}
|
|
485
|
-
return fieldNames
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const getSchemaProperties = (
|
|
489
|
-
jsonSchema: JsonSchemaRoot,
|
|
490
|
-
): Record<string, unknown> | undefined =>
|
|
491
|
-
(jsonSchema as { properties?: Record<string, unknown> }).properties
|
|
492
|
-
|
|
493
|
-
const getSchemaRequiredFields = (jsonSchema: JsonSchemaRoot): string[] =>
|
|
494
|
-
Array.isArray(jsonSchema["required"])
|
|
495
|
-
? jsonSchema["required"].filter(
|
|
496
|
-
(field): field is string => typeof field === "string",
|
|
497
|
-
)
|
|
498
|
-
: []
|
|
499
|
-
|
|
500
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
501
|
-
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
502
|
-
|
|
503
|
-
const hasSchemaPropertyForField = (
|
|
504
|
-
jsonSchema: JsonSchemaRoot,
|
|
505
|
-
fieldName: string,
|
|
506
|
-
): boolean => {
|
|
507
|
-
let currentSchema: unknown = jsonSchema
|
|
508
|
-
|
|
509
|
-
for (const segment of fieldNameToPath(fieldName)) {
|
|
510
|
-
if (!isRecord(currentSchema)) return false
|
|
511
|
-
|
|
512
|
-
if (typeof segment === "number") {
|
|
513
|
-
if (currentSchema["type"] !== "array") return false
|
|
514
|
-
currentSchema = currentSchema["items"]
|
|
515
|
-
continue
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (currentSchema["type"] === "array") {
|
|
519
|
-
currentSchema = currentSchema["items"]
|
|
520
|
-
if (!isRecord(currentSchema)) return false
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
const schemaProperties = getSchemaProperties(currentSchema)
|
|
524
|
-
if (!schemaProperties || !Object.hasOwn(schemaProperties, segment)) {
|
|
525
|
-
return false
|
|
526
|
-
}
|
|
527
|
-
currentSchema = schemaProperties[segment]
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return true
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
const cloneFormValue = (value: unknown): unknown => {
|
|
534
|
-
if (Array.isArray(value)) {
|
|
535
|
-
return value.map(cloneFormValue)
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
if (isRecord(value)) {
|
|
539
|
-
return Object.fromEntries(
|
|
540
|
-
Object.entries(value).map(([key, entry]) => [key, cloneFormValue(entry)]),
|
|
541
|
-
)
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
return value
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
const deletePathValue = (
|
|
548
|
-
target: unknown,
|
|
549
|
-
path: readonly (string | number)[],
|
|
550
|
-
): void => {
|
|
551
|
-
if (path.length === 0) return
|
|
552
|
-
const [segment, ...rest] = path
|
|
553
|
-
if (segment === undefined) return
|
|
554
|
-
|
|
555
|
-
if (Array.isArray(target)) {
|
|
556
|
-
if (typeof segment === "number") {
|
|
557
|
-
if (segment >= target.length) return
|
|
558
|
-
if (rest.length === 0) {
|
|
559
|
-
delete target[segment]
|
|
560
|
-
return
|
|
561
|
-
}
|
|
562
|
-
deletePathValue(target[segment], rest)
|
|
563
|
-
return
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
for (const item of target) {
|
|
567
|
-
deletePathValue(item, path)
|
|
568
|
-
}
|
|
569
|
-
return
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (typeof segment === "number" || !isRecord(target)) return
|
|
573
|
-
if (!Object.hasOwn(target, segment)) return
|
|
574
|
-
if (rest.length === 0) {
|
|
575
|
-
delete target[segment]
|
|
576
|
-
return
|
|
577
|
-
}
|
|
578
|
-
deletePathValue(target[segment], rest)
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const setPathValue = (
|
|
582
|
-
target: unknown,
|
|
583
|
-
path: readonly (string | number)[],
|
|
584
|
-
value: unknown,
|
|
585
|
-
): void => {
|
|
586
|
-
if (path.length === 0) return
|
|
587
|
-
const [segment, ...rest] = path
|
|
588
|
-
if (segment === undefined) return
|
|
589
|
-
|
|
590
|
-
if (Array.isArray(target)) {
|
|
591
|
-
if (typeof segment === "number") {
|
|
592
|
-
if (segment >= target.length) return
|
|
593
|
-
if (rest.length === 0) {
|
|
594
|
-
target[segment] = cloneFormValue(value)
|
|
595
|
-
return
|
|
596
|
-
}
|
|
597
|
-
setPathValue(target[segment], rest, value)
|
|
598
|
-
return
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
for (const item of target) {
|
|
602
|
-
setPathValue(item, path, value)
|
|
603
|
-
}
|
|
604
|
-
return
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
if (typeof segment === "number" || !isRecord(target)) return
|
|
608
|
-
if (rest.length === 0) {
|
|
609
|
-
target[segment] = cloneFormValue(value)
|
|
610
|
-
return
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
if (!isRecord(target[segment])) {
|
|
614
|
-
target[segment] = {}
|
|
615
|
-
}
|
|
616
|
-
setPathValue(target[segment], rest, value)
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
const getPathValue = (
|
|
620
|
-
values: Record<string, unknown>,
|
|
621
|
-
path: readonly (string | number)[],
|
|
622
|
-
): unknown => {
|
|
623
|
-
let current: unknown = values
|
|
624
|
-
|
|
625
|
-
for (const segment of path) {
|
|
626
|
-
if (typeof segment === "number") {
|
|
627
|
-
if (!Array.isArray(current) || segment >= current.length) return undefined
|
|
628
|
-
current = current[segment]
|
|
629
|
-
continue
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
if (!isRecord(current) || !Object.hasOwn(current, segment)) {
|
|
633
|
-
return undefined
|
|
634
|
-
}
|
|
635
|
-
current = current[segment]
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return current
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
const issuePathToFieldName = (path: readonly unknown[] | undefined) =>
|
|
642
|
-
path === undefined
|
|
643
|
-
? undefined
|
|
644
|
-
: pathToFieldName(
|
|
645
|
-
path.filter(
|
|
646
|
-
(segment): segment is string | number =>
|
|
647
|
-
typeof segment === "string" || typeof segment === "number",
|
|
648
|
-
),
|
|
649
|
-
)
|
|
650
|
-
|
|
651
|
-
const filterValuesForSchema = (
|
|
652
|
-
values: Record<string, unknown>,
|
|
653
|
-
jsonSchema: JsonSchemaRoot,
|
|
654
|
-
hiddenFieldNames: Set<string>,
|
|
655
|
-
disabledFieldNames: Set<string>,
|
|
656
|
-
baseValues: Record<string, unknown>,
|
|
657
|
-
): Record<string, unknown> => {
|
|
658
|
-
const schemaProperties = getSchemaProperties(jsonSchema)
|
|
659
|
-
if (!schemaProperties) return {}
|
|
660
|
-
|
|
661
|
-
const filtered = Object.fromEntries(
|
|
662
|
-
Object.entries(values)
|
|
663
|
-
.filter(([key]) => key in schemaProperties && !hiddenFieldNames.has(key))
|
|
664
|
-
.map(([key, value]) => [key, cloneFormValue(value)]),
|
|
665
|
-
)
|
|
666
|
-
|
|
667
|
-
// Top-level hidden fields are filtered above; nested and list-item child
|
|
668
|
-
// paths are deleted here after their parent objects/arrays have been cloned.
|
|
669
|
-
for (const hiddenFieldName of hiddenFieldNames) {
|
|
670
|
-
deletePathValue(filtered, fieldNameToPath(hiddenFieldName))
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
for (const disabledFieldName of disabledFieldNames) {
|
|
674
|
-
if (hiddenFieldNames.has(disabledFieldName)) continue
|
|
675
|
-
|
|
676
|
-
const path = fieldNameToPath(disabledFieldName)
|
|
677
|
-
const baseValue = getPathValue(baseValues, path)
|
|
678
|
-
if (baseValue === undefined) {
|
|
679
|
-
deletePathValue(filtered, path)
|
|
680
|
-
} else {
|
|
681
|
-
setPathValue(filtered, path, baseValue)
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
return filtered
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
const schemaWithVisibleRequired = (
|
|
689
|
-
jsonSchema: JsonSchemaRoot,
|
|
690
|
-
hiddenFieldNames: Set<string>,
|
|
691
|
-
requiredFieldNames: Set<string>,
|
|
692
|
-
): JsonSchemaRoot => {
|
|
693
|
-
const baseRequired = getSchemaRequiredFields(jsonSchema)
|
|
694
|
-
// JSON Schema `required` is scoped to the current object, so only top-level
|
|
695
|
-
// fields can be added here. Nested rule-required fields are enforced by the
|
|
696
|
-
// path-aware manual required check below.
|
|
697
|
-
const required = Array.from(
|
|
698
|
-
new Set([...baseRequired, ...requiredFieldNames]),
|
|
699
|
-
).filter(
|
|
700
|
-
(field) =>
|
|
701
|
-
!hiddenFieldNames.has(field) &&
|
|
702
|
-
fieldNameToPath(field).length === 1 &&
|
|
703
|
-
hasSchemaPropertyForField(jsonSchema, field),
|
|
704
|
-
)
|
|
705
|
-
|
|
706
|
-
if (required.length === 0) {
|
|
707
|
-
const { required: _, ...schemaWithoutRequired } = jsonSchema
|
|
708
|
-
return schemaWithoutRequired
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
return { ...jsonSchema, type: "object", required }
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
const isMissingRequiredValue = (value: unknown): boolean =>
|
|
715
|
-
value === undefined ||
|
|
716
|
-
value === null ||
|
|
717
|
-
(typeof value === "string" && value.trim() === "") ||
|
|
718
|
-
(Array.isArray(value) && value.length === 0)
|
|
719
|
-
|
|
720
|
-
export const createRuleAwareValidator = (
|
|
721
|
-
jsonSchema: JsonSchemaRoot,
|
|
722
|
-
formDefinition: ClientFormDefinition,
|
|
723
|
-
baseValues: Record<string, unknown>,
|
|
724
|
-
) => ({
|
|
725
|
-
"~standard": {
|
|
726
|
-
version: 1 as const,
|
|
727
|
-
vendor: "pf-form-rule",
|
|
728
|
-
validate: (value: unknown) => {
|
|
729
|
-
const values =
|
|
730
|
-
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
731
|
-
? (value as Record<string, unknown>)
|
|
732
|
-
: {}
|
|
733
|
-
const stateByPath = projectionStateByPath(
|
|
734
|
-
formDefinition,
|
|
735
|
-
values,
|
|
736
|
-
baseValues,
|
|
737
|
-
)
|
|
738
|
-
const projectedComponents = projectFormComponentsWithState(
|
|
739
|
-
formDefinition.components,
|
|
740
|
-
stateByPath,
|
|
741
|
-
)
|
|
742
|
-
const hiddenFieldNames = collectHiddenFieldNames(projectedComponents)
|
|
743
|
-
const disabledFieldNames = collectDisabledFieldNames(projectedComponents)
|
|
744
|
-
// Required fields are collected after projection so inherited hiddenness
|
|
745
|
-
// can suppress descendants before validation runs.
|
|
746
|
-
const projectedRequiredFieldNames =
|
|
747
|
-
collectRequiredFieldNames(projectedComponents)
|
|
748
|
-
const requiredFieldNames = new Set(
|
|
749
|
-
[
|
|
750
|
-
...getSchemaRequiredFields(jsonSchema),
|
|
751
|
-
...Array.from(projectedRequiredFieldNames).filter((fieldName) =>
|
|
752
|
-
hasSchemaPropertyForField(jsonSchema, fieldName),
|
|
753
|
-
),
|
|
754
|
-
].filter((fieldName) => !hiddenFieldNames.has(fieldName)),
|
|
755
|
-
)
|
|
756
|
-
const visibleValues = filterValuesForSchema(
|
|
757
|
-
values,
|
|
758
|
-
jsonSchema,
|
|
759
|
-
hiddenFieldNames,
|
|
760
|
-
disabledFieldNames,
|
|
761
|
-
baseValues,
|
|
762
|
-
)
|
|
763
|
-
const schemaValidator = createStandardSchemaFromJsonSchema(
|
|
764
|
-
schemaWithVisibleRequired(
|
|
765
|
-
jsonSchema,
|
|
766
|
-
hiddenFieldNames,
|
|
767
|
-
requiredFieldNames,
|
|
768
|
-
),
|
|
769
|
-
)
|
|
770
|
-
const result = schemaValidator["~standard"].validate(visibleValues)
|
|
771
|
-
const issues =
|
|
772
|
-
"issues" in result && result.issues ? [...result.issues] : []
|
|
773
|
-
|
|
774
|
-
for (const fieldName of requiredFieldNames) {
|
|
775
|
-
const fieldPath = fieldNameToPath(fieldName)
|
|
776
|
-
const hasRequiredIssue = issues.some(
|
|
777
|
-
(issue) =>
|
|
778
|
-
issuePathToFieldName(issue.path) === fieldName &&
|
|
779
|
-
issue.message === REQUIRED_FIELD_MESSAGE,
|
|
780
|
-
)
|
|
781
|
-
const fieldValue = getPathValue(visibleValues, fieldPath)
|
|
782
|
-
// JSON Schema checks whether null is allowed. Its `required` keyword
|
|
783
|
-
// requires presence only; an explicit Form Rule may additionally require
|
|
784
|
-
// a nonempty value.
|
|
785
|
-
if (
|
|
786
|
-
fieldValue === null &&
|
|
787
|
-
!projectedRequiredFieldNames.has(fieldName)
|
|
788
|
-
) {
|
|
789
|
-
continue
|
|
790
|
-
}
|
|
791
|
-
if (!hasRequiredIssue && isMissingRequiredValue(fieldValue)) {
|
|
792
|
-
issues.push({
|
|
793
|
-
path: fieldPath,
|
|
794
|
-
message: REQUIRED_FIELD_MESSAGE,
|
|
795
|
-
})
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
return issues.length > 0 ? { issues } : { value: visibleValues }
|
|
800
|
-
},
|
|
801
|
-
},
|
|
802
|
-
})
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* Focus the first field with an error using DOM querySelector
|
|
806
|
-
* @see https://tanstack.com/form/v1/docs/framework/react/guides/focus-management
|
|
807
|
-
*/
|
|
808
|
-
const focusFirstErrorField = (fieldName: string) => {
|
|
809
|
-
// Use requestAnimationFrame to ensure DOM has updated with error state
|
|
810
|
-
// This waits for the next browser paint cycle, which is more reliable than setTimeout
|
|
811
|
-
requestAnimationFrame(() => {
|
|
812
|
-
// Try to find input by name attribute
|
|
813
|
-
const input = document.querySelector<HTMLInputElement>(
|
|
814
|
-
`input[name="${fieldName}"], textarea[name="${fieldName}"], select[name="${fieldName}"]`,
|
|
815
|
-
)
|
|
816
|
-
|
|
817
|
-
if (input) {
|
|
818
|
-
input.focus()
|
|
819
|
-
input.scrollIntoView({ behavior: "smooth", block: "center" })
|
|
820
|
-
}
|
|
821
|
-
})
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
const firstEditableControlSelector = [
|
|
825
|
-
'input:not([type="hidden"]):not([disabled]):not([readonly])',
|
|
826
|
-
"textarea:not([disabled]):not([readonly])",
|
|
827
|
-
"select:not([disabled])",
|
|
828
|
-
'button[role="combobox"]:not([disabled])',
|
|
829
|
-
].join(",")
|
|
830
|
-
|
|
831
|
-
const focusFirstEditableControl = (formElement: HTMLFormElement) => {
|
|
832
|
-
if (formElement.contains(document.activeElement)) return undefined
|
|
833
|
-
|
|
834
|
-
let timerId: number | undefined
|
|
835
|
-
const frameId = requestAnimationFrame(() => {
|
|
836
|
-
timerId = window.setTimeout(() => {
|
|
837
|
-
if (formElement.contains(document.activeElement)) return
|
|
838
|
-
|
|
839
|
-
const control = formElement.querySelector<HTMLElement>(
|
|
840
|
-
firstEditableControlSelector,
|
|
841
|
-
)
|
|
842
|
-
control?.focus()
|
|
843
|
-
}, 0)
|
|
844
|
-
})
|
|
845
|
-
|
|
846
|
-
return () => {
|
|
847
|
-
cancelAnimationFrame(frameId)
|
|
848
|
-
if (timerId !== undefined) {
|
|
849
|
-
window.clearTimeout(timerId)
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// Type alias for forms with our schema validator configuration
|
|
855
|
-
// This didn't really work well as forms and fields start to show up as any
|
|
856
|
-
//type AnyAppForm = AppFieldExtendedReactFormApi<unknown, FormValidateOrFn<unknown> | undefined, StandardSchemaV1<object, object> | undefined, any, any, any, any, any, any, any, any, any, any, any>
|
|
857
|
-
// So we use this, somewhat generic but working well enough.
|
|
858
|
-
type AnyAppForm = ReturnType<typeof useAppForm>
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Custom validation logic for dynamic form fields.
|
|
862
|
-
*
|
|
863
|
-
* Improves UX over revalidateLogic by:
|
|
864
|
-
* - Skipping blur validation on non-dirty fields (prevents errors on tab-through)
|
|
865
|
-
* - Re-validating on change when field already has errors (clears errors as user types)
|
|
866
|
-
* - Always validating on submit
|
|
867
|
-
* - Always validating after first submission attempt (same as revalidateLogic)
|
|
868
|
-
*
|
|
869
|
-
* Type Safety Note:
|
|
870
|
-
* The function is cast to ValidationLogicFn at the end because TanStack Form's type
|
|
871
|
-
* definition declares this as returning void. However, internally TanStack Form's
|
|
872
|
-
* getSyncValidatorArray relies on the return value flowing through from runValidation.
|
|
873
|
-
* This matches the pattern used by revalidateLogic in the TanStack Form source.
|
|
874
|
-
* The cast is necessary to satisfy TypeScript while preserving the runtime behavior
|
|
875
|
-
* that TanStack Form expects.
|
|
876
|
-
*/
|
|
877
|
-
export const customValidationLogic = ((props: ValidationLogicProps) => {
|
|
878
|
-
const { form, validators, event, runValidation } = props
|
|
879
|
-
|
|
880
|
-
const validatorKeys = Object.keys(validators ?? {})
|
|
881
|
-
if (validatorKeys.length === 0) {
|
|
882
|
-
return runValidation({ validators: [], form })
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
type Validator = Parameters<
|
|
886
|
-
ValidationLogicProps["runValidation"]
|
|
887
|
-
>[0]["validators"][number]
|
|
888
|
-
|
|
889
|
-
const validatorFn = event.async
|
|
890
|
-
? validators?.["onDynamicAsync"]
|
|
891
|
-
: validators?.["onDynamic"]
|
|
892
|
-
|
|
893
|
-
if (!validatorFn) {
|
|
894
|
-
return runValidation({ validators: [], form })
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
const dynamicValidator: Validator = {
|
|
898
|
-
fn: validatorFn,
|
|
899
|
-
cause: "dynamic" as const,
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
// Collect default validators from defaultValidationLogic
|
|
903
|
-
let defaultValidators: Validator[] = []
|
|
904
|
-
defaultValidationLogic({
|
|
905
|
-
...props,
|
|
906
|
-
runValidation: (vProps) => {
|
|
907
|
-
defaultValidators = vProps.validators
|
|
908
|
-
},
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
const afterSubmission = form.state.submissionAttempts > 0
|
|
912
|
-
let includeDynamic = false
|
|
913
|
-
|
|
914
|
-
switch (event.type) {
|
|
915
|
-
case "submit": {
|
|
916
|
-
// Always validate on submit
|
|
917
|
-
includeDynamic = true
|
|
918
|
-
break
|
|
919
|
-
}
|
|
920
|
-
case "blur": {
|
|
921
|
-
if (afterSubmission) {
|
|
922
|
-
// After submission: always validate on blur
|
|
923
|
-
includeDynamic = true
|
|
924
|
-
} else {
|
|
925
|
-
// Before submission: only validate if any field has been modified (prevents #1)
|
|
926
|
-
const fieldMeta = getFieldMetaRecord(form.state.fieldMeta)
|
|
927
|
-
includeDynamic = fieldMeta
|
|
928
|
-
? Object.values(fieldMeta).some((m) => m.isDirty)
|
|
929
|
-
: false
|
|
930
|
-
}
|
|
931
|
-
break
|
|
932
|
-
}
|
|
933
|
-
case "change": {
|
|
934
|
-
if (afterSubmission) {
|
|
935
|
-
// After submission: always validate on change
|
|
936
|
-
includeDynamic = true
|
|
937
|
-
} else {
|
|
938
|
-
// Before submission: only re-validate when a dirty field has errors (fixes #4, #5).
|
|
939
|
-
// Fields at their default value may have stale errors from a previous editing cycle;
|
|
940
|
-
// those should not trigger re-validation so the field behaves as untouched.
|
|
941
|
-
const fieldMeta = getFieldMetaRecord(form.state.fieldMeta)
|
|
942
|
-
includeDynamic = fieldMeta
|
|
943
|
-
? Object.values(fieldMeta).some(
|
|
944
|
-
(m) => m.errors.length > 0 && !m.isDefaultValue,
|
|
945
|
-
)
|
|
946
|
-
: false
|
|
947
|
-
}
|
|
948
|
-
break
|
|
949
|
-
}
|
|
950
|
-
default: {
|
|
951
|
-
// mount, server — do not add dynamic validator
|
|
952
|
-
includeDynamic = false
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
if (includeDynamic) {
|
|
957
|
-
return runValidation({
|
|
958
|
-
validators: [...defaultValidators, dynamicValidator],
|
|
959
|
-
form,
|
|
960
|
-
})
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// For blur/change: clear stale onDynamic errors with a no-op validator.
|
|
964
|
-
// This mirrors how defaultValidationLogic clears onServer errors using () => undefined.
|
|
965
|
-
// Without this, errors from a previous validation cycle persist in errorMap.onDynamic.
|
|
966
|
-
if (event.type === "blur" || event.type === "change") {
|
|
967
|
-
const clearDynamic: Validator = {
|
|
968
|
-
fn: () => undefined,
|
|
969
|
-
cause: "dynamic" as const,
|
|
970
|
-
}
|
|
971
|
-
return runValidation({
|
|
972
|
-
validators: [...defaultValidators, clearDynamic],
|
|
973
|
-
form,
|
|
974
|
-
})
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
return runValidation({ validators: defaultValidators, form })
|
|
978
|
-
// Cast: ValidationLogicFn type declares void, but TanStack Form internally
|
|
979
|
-
// relies on the return value. Required to match revalidateLogic pattern.
|
|
980
|
-
}) as (props: ValidationLogicProps) => void
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* Field-level or form-level validation error returned from handleSubmit.
|
|
984
|
-
* Use field: "" (empty string) for form-level errors that apply to the entire form.
|
|
985
|
-
*/
|
|
986
|
-
export interface FieldError {
|
|
987
|
-
field: string
|
|
988
|
-
message: string
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* Context passed to the renderActions callback.
|
|
993
|
-
* Provides form state and utilities for rendering custom action buttons.
|
|
994
|
-
*
|
|
995
|
-
* Note: Submit button should only be disabled during `isSubmitting`.
|
|
996
|
-
* Validation errors are shown inline after the user presses submit,
|
|
997
|
-
* per Web Interface Guidelines: "Submit button stays enabled until
|
|
998
|
-
* request starts; spinner during request."
|
|
999
|
-
*/
|
|
1000
|
-
export interface FormActionsContext {
|
|
1001
|
-
/** Current form state */
|
|
1002
|
-
readonly formState: {
|
|
1003
|
-
readonly values: Record<string, unknown>
|
|
1004
|
-
readonly isSubmitting: boolean
|
|
1005
|
-
readonly isPristine: boolean
|
|
1006
|
-
}
|
|
1007
|
-
/** Clear the session-level localStorage for this form */
|
|
1008
|
-
readonly clearLocalStorage: () => void
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
/**
|
|
1012
|
-
* Properties for the dynamic form component.
|
|
1013
|
-
*
|
|
1014
|
-
* The handleSubmit callback should return:
|
|
1015
|
-
* - undefined/void for successful submission
|
|
1016
|
-
* - FieldError[] for validation errors that should be set on form fields
|
|
1017
|
-
*/
|
|
1018
|
-
export interface FormProperties {
|
|
1019
|
-
/** Unique ID for localStorage session state */
|
|
1020
|
-
readonly draftId: string
|
|
1021
|
-
readonly formDefinition: ClientFormDefinition | null
|
|
1022
|
-
readonly defaultValues: Record<string, unknown> | null
|
|
1023
|
-
readonly handleCancel?: () => void
|
|
1024
|
-
readonly handleSubmit: (
|
|
1025
|
-
values: Record<string, unknown>,
|
|
1026
|
-
) => Promise<FieldError[] | undefined>
|
|
1027
|
-
readonly jsonSchema: JsonSchemaRoot | null
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Render custom action buttons (Discard, Save draft, Submit, etc.)
|
|
1031
|
-
* Called inside form.Subscribe with current form state.
|
|
1032
|
-
*/
|
|
1033
|
-
readonly renderActions: (context: FormActionsContext) => React.ReactNode
|
|
1034
|
-
|
|
1035
|
-
/**
|
|
1036
|
-
* Step path for authenticated field actions.
|
|
1037
|
-
* Required when the form contains file upload fields, lookup fields, or
|
|
1038
|
-
* provider-user fields with enableProviderUserLookup set to true.
|
|
1039
|
-
*/
|
|
1040
|
-
readonly stepPath?: string
|
|
1041
|
-
|
|
1042
|
-
/** Enables authenticated provider-user suggestions. Disable for embeds. */
|
|
1043
|
-
readonly enableProviderUserLookup?: boolean
|
|
1044
|
-
|
|
1045
|
-
/** Optional state context for lookup queries, such as a to-do being completed. */
|
|
1046
|
-
readonly lookupOptions?: LookupOptions | undefined
|
|
1047
|
-
|
|
1048
|
-
/** Debounce for session localStorage draft writes. Defaults to 500ms. */
|
|
1049
|
-
readonly onChangeDebounceMs?: number
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
/**
|
|
1053
|
-
* Simple form for steps with no input fields.
|
|
1054
|
-
* Renders action buttons via renderActions callback.
|
|
1055
|
-
*/
|
|
1056
|
-
const SimpleForm = ({
|
|
1057
|
-
onSubmit,
|
|
1058
|
-
renderActions,
|
|
1059
|
-
}: {
|
|
1060
|
-
onSubmit: (
|
|
1061
|
-
values: Record<string, unknown>,
|
|
1062
|
-
) => Promise<FieldError[] | undefined>
|
|
1063
|
-
renderActions: (context: FormActionsContext) => React.ReactNode
|
|
1064
|
-
}) => {
|
|
1065
|
-
const form = useAppForm({
|
|
1066
|
-
defaultValues: {},
|
|
1067
|
-
onSubmit: async () => {
|
|
1068
|
-
await onSubmit({})
|
|
1069
|
-
},
|
|
1070
|
-
})
|
|
1071
|
-
|
|
1072
|
-
// Form instance is stable across renders
|
|
1073
|
-
const handleFormSubmit = useCallback(
|
|
1074
|
-
(e: React.FormEvent) => {
|
|
1075
|
-
e.preventDefault()
|
|
1076
|
-
form.handleSubmit()
|
|
1077
|
-
},
|
|
1078
|
-
[form],
|
|
1079
|
-
)
|
|
1080
|
-
|
|
1081
|
-
return (
|
|
1082
|
-
<form className="space-y-6" onSubmit={handleFormSubmit}>
|
|
1083
|
-
<form.Subscribe
|
|
1084
|
-
selector={(state) => [state.isSubmitting, state.isPristine] as const}
|
|
1085
|
-
>
|
|
1086
|
-
{([isSubmitting, isPristine]) => {
|
|
1087
|
-
const context: FormActionsContext = {
|
|
1088
|
-
formState: {
|
|
1089
|
-
values: {},
|
|
1090
|
-
isSubmitting,
|
|
1091
|
-
isPristine,
|
|
1092
|
-
},
|
|
1093
|
-
clearLocalStorage: () => {
|
|
1094
|
-
/* no-op for simple forms */
|
|
1095
|
-
},
|
|
1096
|
-
}
|
|
1097
|
-
return renderActions(context)
|
|
1098
|
-
}}
|
|
1099
|
-
</form.Subscribe>
|
|
1100
|
-
</form>
|
|
1101
|
-
)
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* Properties for the full form component (non-null values).
|
|
1106
|
-
*/
|
|
1107
|
-
interface FullFormProperties {
|
|
1108
|
-
readonly draftId: string
|
|
1109
|
-
readonly formDefinition: ClientFormDefinition
|
|
1110
|
-
readonly defaultValues: Record<string, unknown>
|
|
1111
|
-
readonly onSubmit: (
|
|
1112
|
-
values: Record<string, unknown>,
|
|
1113
|
-
) => Promise<FieldError[] | undefined>
|
|
1114
|
-
readonly jsonSchema: JsonSchemaRoot
|
|
1115
|
-
readonly renderActions: (context: FormActionsContext) => React.ReactNode
|
|
1116
|
-
readonly stepPath: string | undefined
|
|
1117
|
-
readonly enableProviderUserLookup: boolean
|
|
1118
|
-
readonly lookupOptions: LookupOptions | undefined
|
|
1119
|
-
readonly onChangeDebounceMs: number
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
/**
|
|
1123
|
-
* Full form component with all hooks.
|
|
1124
|
-
* Only rendered when we have all required data (non-null).
|
|
1125
|
-
*/
|
|
1126
|
-
const FullForm = ({
|
|
1127
|
-
draftId,
|
|
1128
|
-
formDefinition,
|
|
1129
|
-
defaultValues,
|
|
1130
|
-
onSubmit,
|
|
1131
|
-
jsonSchema,
|
|
1132
|
-
renderActions,
|
|
1133
|
-
stepPath,
|
|
1134
|
-
enableProviderUserLookup,
|
|
1135
|
-
lookupOptions,
|
|
1136
|
-
onChangeDebounceMs,
|
|
1137
|
-
}: FullFormProperties) => {
|
|
1138
|
-
const formRef = useRef<HTMLFormElement | null>(null)
|
|
1139
|
-
const hasSubmittedSuccessfully = useRef(false)
|
|
1140
|
-
const [formValues, setFormValues, clearFormValues] = useLocalStorage<
|
|
1141
|
-
Record<string, unknown>
|
|
1142
|
-
>(draftId, {})
|
|
1143
|
-
|
|
1144
|
-
// Snapshot initial values once for this form instance. Saved values take precedence,
|
|
1145
|
-
// and defaultValues may already include draft state from RxDB.
|
|
1146
|
-
const [initialValues] = useState(() =>
|
|
1147
|
-
initializeFormValues(defaultValues, formValues),
|
|
1148
|
-
)
|
|
1149
|
-
|
|
1150
|
-
const baseComponents = formDefinition.components
|
|
1151
|
-
|
|
1152
|
-
// Create Standard Schema validator from JSON Schema if provided
|
|
1153
|
-
const validator = useMemo(
|
|
1154
|
-
() => createRuleAwareValidator(jsonSchema, formDefinition, defaultValues),
|
|
1155
|
-
[jsonSchema, formDefinition, defaultValues],
|
|
1156
|
-
)
|
|
1157
|
-
|
|
1158
|
-
// Track form-level errors (server-returned errors with field: "")
|
|
1159
|
-
const [formLevelErrors, setFormLevelErrors] = useState<string[]>([])
|
|
1160
|
-
const renderableFieldNames = useMemo(
|
|
1161
|
-
() => getRenderableFieldNames(baseComponents),
|
|
1162
|
-
[baseComponents],
|
|
1163
|
-
)
|
|
1164
|
-
const metricBreakdownFieldNames = useMemo(
|
|
1165
|
-
() => getMetricBreakdownFieldNames(baseComponents),
|
|
1166
|
-
[baseComponents],
|
|
1167
|
-
)
|
|
1168
|
-
|
|
1169
|
-
const form = useAppForm({
|
|
1170
|
-
defaultValues: initialValues,
|
|
1171
|
-
validators: {
|
|
1172
|
-
onDynamic: validator,
|
|
1173
|
-
},
|
|
1174
|
-
validationLogic: customValidationLogic,
|
|
1175
|
-
onSubmit: async ({ value }) => {
|
|
1176
|
-
// Clear previous submit errors from all fields and form level
|
|
1177
|
-
setFormLevelErrors([])
|
|
1178
|
-
renderableFieldNames.forEach((fieldName) => {
|
|
1179
|
-
form.setFieldMeta(fieldName, (prev) => ({
|
|
1180
|
-
...prev,
|
|
1181
|
-
errorMap: { ...(prev?.errorMap ?? {}), onSubmit: undefined },
|
|
1182
|
-
}))
|
|
1183
|
-
})
|
|
1184
|
-
|
|
1185
|
-
const projectedComponents = projectFormComponents(
|
|
1186
|
-
formDefinition,
|
|
1187
|
-
value,
|
|
1188
|
-
defaultValues,
|
|
1189
|
-
)
|
|
1190
|
-
const hiddenFieldNames = collectHiddenFieldNames(projectedComponents)
|
|
1191
|
-
const disabledFieldNames = collectDisabledFieldNames(projectedComponents)
|
|
1192
|
-
const filteredValue = filterValuesForSchema(
|
|
1193
|
-
value,
|
|
1194
|
-
jsonSchema,
|
|
1195
|
-
hiddenFieldNames,
|
|
1196
|
-
disabledFieldNames,
|
|
1197
|
-
defaultValues,
|
|
1198
|
-
)
|
|
1199
|
-
|
|
1200
|
-
// Call the user's submit handler and capture any field errors
|
|
1201
|
-
const fieldErrors = await onSubmit(filteredValue)
|
|
1202
|
-
const normalizedFieldErrors = fieldErrors
|
|
1203
|
-
? normalizeSubmitErrors(
|
|
1204
|
-
fieldErrors,
|
|
1205
|
-
renderableFieldNames,
|
|
1206
|
-
hiddenFieldNames,
|
|
1207
|
-
)
|
|
1208
|
-
: undefined
|
|
1209
|
-
|
|
1210
|
-
// If there are errors, separate form-level from field-level
|
|
1211
|
-
if (normalizedFieldErrors && normalizedFieldErrors.length > 0) {
|
|
1212
|
-
const formErrors: string[] = []
|
|
1213
|
-
const fieldSpecificErrors: FieldError[] = []
|
|
1214
|
-
|
|
1215
|
-
for (const error of normalizedFieldErrors) {
|
|
1216
|
-
if (error.field === "") {
|
|
1217
|
-
// Form-level error
|
|
1218
|
-
formErrors.push(error.message)
|
|
1219
|
-
} else {
|
|
1220
|
-
// Field-specific error
|
|
1221
|
-
fieldSpecificErrors.push(error)
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
// Set form-level errors
|
|
1226
|
-
if (formErrors.length > 0) {
|
|
1227
|
-
setFormLevelErrors(formErrors)
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
// Set field-specific errors
|
|
1231
|
-
for (const error of fieldSpecificErrors) {
|
|
1232
|
-
form.setFieldMeta(error.field, (prev) => ({
|
|
1233
|
-
...prev,
|
|
1234
|
-
errorMap: { ...(prev?.errorMap ?? {}), onSubmit: error.message },
|
|
1235
|
-
}))
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
// Focus first field with error (if any)
|
|
1239
|
-
const firstErrorField = fieldSpecificErrors[0]?.field
|
|
1240
|
-
if (firstErrorField) {
|
|
1241
|
-
focusFirstErrorField(firstErrorField)
|
|
1242
|
-
}
|
|
1243
|
-
return
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
// Success - clear the form from localStorage
|
|
1247
|
-
// Note: Caller's handleSubmit should handle RxDB draft cleanup
|
|
1248
|
-
// Debounced listeners can still run while the caller navigates away.
|
|
1249
|
-
hasSubmittedSuccessfully.current = true
|
|
1250
|
-
clearFormValues()
|
|
1251
|
-
},
|
|
1252
|
-
onSubmitInvalid: () => {
|
|
1253
|
-
// Focus first field with validation error so user knows what to fix
|
|
1254
|
-
requestAnimationFrame(() => {
|
|
1255
|
-
const fieldMeta = getFieldMetaRecord(form.state.fieldMeta)
|
|
1256
|
-
if (!fieldMeta) return
|
|
1257
|
-
const firstErrorField = Object.entries(fieldMeta).find(
|
|
1258
|
-
([, meta]) => meta.errors.length > 0,
|
|
1259
|
-
)?.[0]
|
|
1260
|
-
if (firstErrorField) {
|
|
1261
|
-
focusFirstErrorField(firstErrorField)
|
|
1262
|
-
}
|
|
1263
|
-
})
|
|
1264
|
-
},
|
|
1265
|
-
listeners: {
|
|
1266
|
-
// Save form state to localStorage on any change
|
|
1267
|
-
onChange: () => {
|
|
1268
|
-
if (hasSubmittedSuccessfully.current) return
|
|
1269
|
-
setFormValues(form.state.values)
|
|
1270
|
-
},
|
|
1271
|
-
// Debounce to avoid excessive localStorage writes
|
|
1272
|
-
onChangeDebounceMs,
|
|
1273
|
-
},
|
|
1274
|
-
})
|
|
1275
|
-
|
|
1276
|
-
useEffect(() => {
|
|
1277
|
-
for (const fieldName of metricBreakdownFieldNames) {
|
|
1278
|
-
if (fieldName in defaultValues) {
|
|
1279
|
-
form.setFieldValue(fieldName, defaultValues[fieldName])
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
}, [defaultValues, metricBreakdownFieldNames, form.setFieldValue])
|
|
1283
|
-
|
|
1284
|
-
useEffect(() => {
|
|
1285
|
-
const formElement = formRef.current
|
|
1286
|
-
if (!formElement) return
|
|
1287
|
-
return focusFirstEditableControl(formElement)
|
|
1288
|
-
}, [])
|
|
1289
|
-
|
|
1290
|
-
// Form instance is stable across renders (useState), so form.handleSubmit
|
|
1291
|
-
// method reference is also stable.
|
|
1292
|
-
const handleFormSubmit = useCallback(
|
|
1293
|
-
(e: React.FormEvent) => {
|
|
1294
|
-
e.preventDefault()
|
|
1295
|
-
form.handleSubmit()
|
|
1296
|
-
},
|
|
1297
|
-
[form],
|
|
1298
|
-
)
|
|
1299
|
-
|
|
1300
|
-
return (
|
|
1301
|
-
<form ref={formRef} className="space-y-6" onSubmit={handleFormSubmit}>
|
|
1302
|
-
<form.AppForm>
|
|
1303
|
-
{/* Rule projection must respond to every value change so hidden, disabled, and required state stays local and immediate. */}
|
|
1304
|
-
<form.Subscribe selector={(state) => state.values}>
|
|
1305
|
-
{(values) =>
|
|
1306
|
-
walkClientRepresentation(
|
|
1307
|
-
form as unknown as AnyAppForm,
|
|
1308
|
-
projectFormComponents(formDefinition, values, defaultValues),
|
|
1309
|
-
true,
|
|
1310
|
-
stepPath,
|
|
1311
|
-
enableProviderUserLookup,
|
|
1312
|
-
lookupOptions,
|
|
1313
|
-
)
|
|
1314
|
-
}
|
|
1315
|
-
</form.Subscribe>
|
|
1316
|
-
{formLevelErrors.length > 0 && (
|
|
1317
|
-
<div
|
|
1318
|
-
className="rounded-md bg-red-50 p-4 dark:bg-red-900/20"
|
|
1319
|
-
aria-live="polite"
|
|
1320
|
-
>
|
|
1321
|
-
<div className="flex">
|
|
1322
|
-
<div className="flex-shrink-0">
|
|
1323
|
-
<svg
|
|
1324
|
-
className="h-5 w-5 text-red-400"
|
|
1325
|
-
viewBox="0 0 20 20"
|
|
1326
|
-
fill="currentColor"
|
|
1327
|
-
aria-hidden="true"
|
|
1328
|
-
>
|
|
1329
|
-
<path
|
|
1330
|
-
fillRule="evenodd"
|
|
1331
|
-
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
|
|
1332
|
-
clipRule="evenodd"
|
|
1333
|
-
/>
|
|
1334
|
-
</svg>
|
|
1335
|
-
</div>
|
|
1336
|
-
<div className="ml-3">
|
|
1337
|
-
<h3 className="text-sm font-medium text-red-800 dark:text-red-200">
|
|
1338
|
-
{formLevelErrors.length === 1
|
|
1339
|
-
? "An error occurred"
|
|
1340
|
-
: "There were errors with your submission"}
|
|
1341
|
-
</h3>
|
|
1342
|
-
<div className="mt-2 text-sm text-red-700 dark:text-red-300">
|
|
1343
|
-
<ul className="list-disc space-y-1 pl-5">
|
|
1344
|
-
{formLevelErrors.map((error) => (
|
|
1345
|
-
<li key={`form-${error}`}>{error}</li>
|
|
1346
|
-
))}
|
|
1347
|
-
</ul>
|
|
1348
|
-
</div>
|
|
1349
|
-
</div>
|
|
1350
|
-
</div>
|
|
1351
|
-
</div>
|
|
1352
|
-
)}
|
|
1353
|
-
<form.Subscribe
|
|
1354
|
-
selector={(state) =>
|
|
1355
|
-
[state.isSubmitting, state.isPristine, state.values] as const
|
|
1356
|
-
}
|
|
1357
|
-
>
|
|
1358
|
-
{([isSubmitting, isPristine, values]) => {
|
|
1359
|
-
const context: FormActionsContext = {
|
|
1360
|
-
formState: {
|
|
1361
|
-
values,
|
|
1362
|
-
isSubmitting,
|
|
1363
|
-
isPristine,
|
|
1364
|
-
},
|
|
1365
|
-
clearLocalStorage: clearFormValues,
|
|
1366
|
-
}
|
|
1367
|
-
return renderActions(context)
|
|
1368
|
-
}}
|
|
1369
|
-
</form.Subscribe>
|
|
1370
|
-
</form.AppForm>
|
|
1371
|
-
</form>
|
|
1372
|
-
)
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
/**
|
|
1376
|
-
* Main form entry point.
|
|
1377
|
-
*
|
|
1378
|
-
* Client representation-based form that receives pre-computed form structure from server.
|
|
1379
|
-
* Action buttons are rendered via the renderActions callback to allow callers to customize.
|
|
1380
|
-
*
|
|
1381
|
-
* Delegates to SimpleForm for steps with no input fields, or FullForm otherwise.
|
|
1382
|
-
*/
|
|
1383
|
-
export const dynamicForm = (props: FormProperties) => {
|
|
1384
|
-
const {
|
|
1385
|
-
draftId,
|
|
1386
|
-
formDefinition,
|
|
1387
|
-
defaultValues,
|
|
1388
|
-
handleSubmit: onSubmit,
|
|
1389
|
-
jsonSchema,
|
|
1390
|
-
renderActions,
|
|
1391
|
-
stepPath,
|
|
1392
|
-
enableProviderUserLookup = true,
|
|
1393
|
-
lookupOptions,
|
|
1394
|
-
onChangeDebounceMs = 500,
|
|
1395
|
-
} = props
|
|
1396
|
-
|
|
1397
|
-
// Handle steps with no input fields - return simple form
|
|
1398
|
-
if (
|
|
1399
|
-
jsonSchema === null ||
|
|
1400
|
-
formDefinition === null ||
|
|
1401
|
-
defaultValues === null
|
|
1402
|
-
) {
|
|
1403
|
-
return <SimpleForm onSubmit={onSubmit} renderActions={renderActions} />
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
// Render full form with all hooks
|
|
1407
|
-
return (
|
|
1408
|
-
<FullForm
|
|
1409
|
-
draftId={draftId}
|
|
1410
|
-
formDefinition={formDefinition}
|
|
1411
|
-
defaultValues={defaultValues}
|
|
1412
|
-
onSubmit={onSubmit}
|
|
1413
|
-
jsonSchema={jsonSchema}
|
|
1414
|
-
renderActions={renderActions}
|
|
1415
|
-
stepPath={stepPath}
|
|
1416
|
-
enableProviderUserLookup={enableProviderUserLookup}
|
|
1417
|
-
lookupOptions={lookupOptions}
|
|
1418
|
-
onChangeDebounceMs={onChangeDebounceMs}
|
|
1419
|
-
/>
|
|
1420
|
-
)
|
|
1421
|
-
}
|