@rytass/bpm-core-react 0.19.0 → 0.20.1

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 (113) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/chunks/{FormBuilderView-Djlm3y4S.js → FormBuilderView-CFRiw04B.js} +563 -475
  3. package/dist/chunks/FormBuilderView-CFRiw04B.js.map +1 -0
  4. package/dist/chunks/FormBuilderView-CpUgbSbt.cjs +3 -0
  5. package/dist/chunks/FormBuilderView-CpUgbSbt.cjs.map +1 -0
  6. package/dist/chunks/{FormRendererView-DHfVgbo6.js → FormRendererView-GfbVWEGa.js} +386 -297
  7. package/dist/chunks/FormRendererView-GfbVWEGa.js.map +1 -0
  8. package/dist/chunks/FormRendererView-lYSaR8CQ.cjs +6 -0
  9. package/dist/chunks/FormRendererView-lYSaR8CQ.cjs.map +1 -0
  10. package/dist/chunks/{compose-NH6dsFXD.cjs → compose-Bb5bUVFd.cjs} +2 -2
  11. package/dist/chunks/{compose-NH6dsFXD.cjs.map → compose-Bb5bUVFd.cjs.map} +1 -1
  12. package/dist/chunks/{compose-D6zBIc2Z.js → compose-egQlRjuZ.js} +5 -4
  13. package/dist/chunks/{compose-D6zBIc2Z.js.map → compose-egQlRjuZ.js.map} +1 -1
  14. package/dist/chunks/{delegations-BfhCDz5e.js → delegations-9-yvWWws.js} +3 -2
  15. package/dist/chunks/delegations-9-yvWWws.js.map +1 -0
  16. package/dist/chunks/delegations-CVmtpkRn.cjs +2 -0
  17. package/dist/chunks/delegations-CVmtpkRn.cjs.map +1 -0
  18. package/dist/chunks/delegations-CrfjsH94.cjs +2 -0
  19. package/dist/chunks/delegations-CrfjsH94.cjs.map +1 -0
  20. package/dist/chunks/{delegations-DBh5TT6G.js → delegations-CxnNvTCc.js} +3 -2
  21. package/dist/chunks/delegations-CxnNvTCc.js.map +1 -0
  22. package/dist/chunks/designer-CX9bhYJS.cjs +69 -0
  23. package/dist/chunks/designer-CX9bhYJS.cjs.map +1 -0
  24. package/dist/chunks/{designer-uhC_7m2i.js → designer-CZDlQ9Nf.js} +2341 -1584
  25. package/dist/chunks/designer-CZDlQ9Nf.js.map +1 -0
  26. package/dist/chunks/{detail-_GeKqNC-.js → detail-ByZV1XaI.js} +4 -3
  27. package/dist/chunks/detail-ByZV1XaI.js.map +1 -0
  28. package/dist/chunks/{detail-6uw5dmTi.cjs → detail-ChseSF55.cjs} +3 -3
  29. package/dist/chunks/detail-ChseSF55.cjs.map +1 -0
  30. package/dist/chunks/workflow-chat-prompt-B4wCFKPB.js +25 -0
  31. package/dist/chunks/workflow-chat-prompt-B4wCFKPB.js.map +1 -0
  32. package/dist/chunks/workflow-chat-prompt-B803qVdt.cjs +27 -0
  33. package/dist/chunks/workflow-chat-prompt-B803qVdt.cjs.map +1 -0
  34. package/dist/next/workflow-chat-route.cjs +8 -19
  35. package/dist/next/workflow-chat-route.cjs.map +1 -1
  36. package/dist/next/workflow-chat-route.d.cts +92 -4
  37. package/dist/next/workflow-chat-route.d.ts +92 -4
  38. package/dist/next/workflow-chat-route.js +127 -19
  39. package/dist/next/workflow-chat-route.js.map +1 -1
  40. package/dist/pages/admin/delegations/index.cjs +1 -1
  41. package/dist/pages/admin/delegations/index.js +1 -1
  42. package/dist/pages/delegations/index.cjs +1 -1
  43. package/dist/pages/delegations/index.js +1 -1
  44. package/dist/pages/instances/detail/index.cjs +1 -1
  45. package/dist/pages/instances/detail/index.js +1 -1
  46. package/dist/pages/templates/compose/index.cjs +1 -1
  47. package/dist/pages/templates/compose/index.js +1 -1
  48. package/dist/pages/templates/designer/index.cjs +1 -1
  49. package/dist/pages/templates/designer/index.js +1 -1
  50. package/dist/views/admin/delegations/index.cjs +1 -1
  51. package/dist/views/admin/delegations/index.js +1 -1
  52. package/dist/views/admin/index.cjs +1 -1
  53. package/dist/views/admin/index.js +1 -1
  54. package/dist/views/delegations/index.cjs +1 -1
  55. package/dist/views/delegations/index.js +1 -1
  56. package/dist/views/forms/builder/index.cjs +1 -1
  57. package/dist/views/forms/builder/index.js +1 -1
  58. package/dist/views/forms/renderer/FormRendererView.d.cts +1 -1
  59. package/dist/views/forms/renderer/FormRendererView.d.ts +1 -1
  60. package/dist/views/forms/renderer/form-data-source-field.d.cts +9 -1
  61. package/dist/views/forms/renderer/form-data-source-field.d.ts +9 -1
  62. package/dist/views/forms/renderer/index.cjs +1 -1
  63. package/dist/views/forms/renderer/index.js +1 -1
  64. package/dist/views/instances/detail/index.cjs +1 -1
  65. package/dist/views/instances/detail/index.js +1 -1
  66. package/dist/views/instances/detail/sections/InstanceFormSection.d.cts +1 -1
  67. package/dist/views/instances/detail/sections/InstanceFormSection.d.ts +1 -1
  68. package/dist/views/instances/new/index.cjs +1 -1
  69. package/dist/views/instances/new/index.cjs.map +1 -1
  70. package/dist/views/instances/new/index.js +3 -2
  71. package/dist/views/instances/new/index.js.map +1 -1
  72. package/dist/views/templates/compose/index.cjs +1 -1
  73. package/dist/views/templates/compose/index.js +1 -1
  74. package/dist/views/templates/designer/designer-version-labels.d.cts +7 -0
  75. package/dist/views/templates/designer/designer-version-labels.d.ts +7 -0
  76. package/dist/views/templates/designer/expression/DialectUpgradeModal.d.cts +25 -0
  77. package/dist/views/templates/designer/expression/DialectUpgradeModal.d.ts +25 -0
  78. package/dist/views/templates/designer/expression/ExpressionField.d.cts +79 -0
  79. package/dist/views/templates/designer/expression/ExpressionField.d.ts +79 -0
  80. package/dist/views/templates/designer/expression/use-workflow-expression-references.d.cts +22 -0
  81. package/dist/views/templates/designer/expression/use-workflow-expression-references.d.ts +22 -0
  82. package/dist/views/templates/designer/expression/workflow-expression-edits.d.cts +58 -0
  83. package/dist/views/templates/designer/expression/workflow-expression-edits.d.ts +58 -0
  84. package/dist/views/templates/designer/expression/workflow-expression-tools.d.cts +14 -0
  85. package/dist/views/templates/designer/expression/workflow-expression-tools.d.ts +14 -0
  86. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.cts +7 -1
  87. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.ts +7 -1
  88. package/dist/views/templates/designer/index.cjs +1 -1
  89. package/dist/views/templates/designer/index.js +1 -1
  90. package/dist/views/templates/designer/notify-webhook-designer.d.cts +8 -0
  91. package/dist/views/templates/designer/notify-webhook-designer.d.ts +8 -0
  92. package/dist/views/templates/designer/use-workflow-designer-controller.d.cts +8 -2
  93. package/dist/views/templates/designer/use-workflow-designer-controller.d.ts +8 -2
  94. package/dist/views/templates/designer/workflow-chat-prompt.d.cts +18 -0
  95. package/dist/views/templates/designer/workflow-chat-prompt.d.ts +18 -0
  96. package/package.json +3 -3
  97. package/dist/chunks/FormBuilderView-Djlm3y4S.js.map +0 -1
  98. package/dist/chunks/FormBuilderView-G6uRSywl.cjs +0 -3
  99. package/dist/chunks/FormBuilderView-G6uRSywl.cjs.map +0 -1
  100. package/dist/chunks/FormRendererView-DHfVgbo6.js.map +0 -1
  101. package/dist/chunks/FormRendererView-DwfFbaip.cjs +0 -6
  102. package/dist/chunks/FormRendererView-DwfFbaip.cjs.map +0 -1
  103. package/dist/chunks/delegations-BfhCDz5e.js.map +0 -1
  104. package/dist/chunks/delegations-BmFGcuhA.cjs +0 -2
  105. package/dist/chunks/delegations-BmFGcuhA.cjs.map +0 -1
  106. package/dist/chunks/delegations-CcS0SHbf.cjs +0 -2
  107. package/dist/chunks/delegations-CcS0SHbf.cjs.map +0 -1
  108. package/dist/chunks/delegations-DBh5TT6G.js.map +0 -1
  109. package/dist/chunks/designer-Be9UI9Tg.cjs +0 -65
  110. package/dist/chunks/designer-Be9UI9Tg.cjs.map +0 -1
  111. package/dist/chunks/designer-uhC_7m2i.js.map +0 -1
  112. package/dist/chunks/detail-6uw5dmTi.cjs.map +0 -1
  113. package/dist/chunks/detail-_GeKqNC-.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Suspense","useRouterAdapter","useBPMRoutes","useAuth","useState","useFileUploadFieldStates","useMemo","readApplicantFormSchema","useCallback","formatDateTime","listLaunchableTemplates","readErrorMessage","readLaunchContext","readFormDataSourceSubmissionBlockMessage","readApplicantSubmission","buildFormRendererValues","validateFormRendererValuesInWorker","submitApprovalInstance","readFormDataCaseTitle","uploadAttachment","_Fragment","PageHeader","ContentHeader","Button","CheckedIcon","SectionGroup","Section","Typography","FormRenderer","Table","require_rolldown_runtime","require_instance_error_message","require_format_date_time","require_auth_provider","require_router_adapter","require_routes_config","require_FormRendererView","react","_mezzanine_ui_react","react_jsx_runtime","_rytass_bpm_core_client_workflow","_mezzanine_ui_react_ContentHeader","_mezzanine_ui_icons","_rytass_bpm_core_client_form","FORM_SECTION_STYLE","InstanceNewView","NewApprovalInstanceLoading","NewApprovalInstanceContent","props","templateIdProp","router","routes","currentMemberId","member","templateId","context","setContext","formValues","setFormValues","templates","setTemplates","error","setError","formErrors","setFormErrors","loading","setLoading","submitting","setSubmitting","dataSourceStates","setDataSourceStates","fileUploads","applicantSchema","handleDataSourceStateChange","currentState","currentStates","fieldKey","state","refreshContext","refreshTemplates","rows","template","columns","tableActions","record","requestError","nextTemplateId","handleSubmit","dataSourceBlockMessage","submittedValues","validation","instanceId","handleUploadAttachment","field","values"],"sources":["../../../../src/views/instances/new/InstanceNewView.tsx"],"sourcesContent":["'use client';\n\nimport {\n CSSProperties,\n ReactElement,\n Suspense,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n Button,\n PageHeader,\n Section,\n SectionGroup,\n Table,\n Typography,\n} from '@mezzanine-ui/react';\nimport ContentHeader from '@mezzanine-ui/react/ContentHeader';\nimport { CheckedIcon } from '@mezzanine-ui/icons';\nimport type { TableActions, TableColumn } from '@mezzanine-ui/core/table';\nimport { FormFieldDefinition } from '@rytass/bpm-core-shared/form';\nimport {\n buildFormRendererValues,\n focusFormRendererField,\n FormRendererValues,\n validateFormRendererValuesInWorker,\n} from '@rytass/bpm-core-client/form';\nimport {\n LaunchContext,\n LaunchableTemplateRecord,\n listLaunchableTemplates,\n readFormDataCaseTitle,\n readLaunchContext,\n submitApprovalInstance,\n uploadAttachment,\n} from '@rytass/bpm-core-client/workflow';\nimport {\n readApplicantFormSchema,\n readApplicantSubmission,\n} from '../approver-filled-form';\nimport { formatDateTime } from '../../../lib/format-date-time';\nimport { useAuth } from '../../../lib/auth-provider';\nimport { useRouterAdapter } from '../../../lib/router-adapter';\nimport { useBPMRoutes } from '../../../lib/routes-config';\nimport { FormRenderer } from '../../forms/renderer/FormRendererView';\nimport {\n readFormDataSourceSubmissionBlockMessage,\n type FormDataSourceFieldState,\n} from '../../forms/renderer/form-data-source-field';\nimport { useFileUploadFieldStates } from '../../forms/renderer/file-upload-field';\nimport { readErrorMessage } from '../instance-error-message';\n\nconst FORM_SECTION_STYLE: CSSProperties = {\n display: 'grid',\n gap: 16,\n};\n\ntype LaunchableTemplateRow = Readonly<\n Record<string, unknown> &\n LaunchableTemplateRecord & {\n key: string;\n versionLabel: string;\n }\n>;\n\nexport interface InstanceNewViewProps {\n /**\n * Optional template id pre-selected by the host. The Server Component\n * page should read `?templateId=` from its `searchParams` and pass the\n * value through this prop.\n */\n readonly templateId?: string | null;\n}\n\n/**\n * Framework-agnostic view for the BPM \"發起簽核\" launch page. Mechanical port\n * of `apps/client/src/app/instances/new/page.tsx` — picks a launchable\n * template and submits the launch form.\n */\nexport function InstanceNewView(\n props: InstanceNewViewProps = {},\n): ReactElement {\n return (\n <Suspense fallback={<NewApprovalInstanceLoading />}>\n <NewApprovalInstanceContent templateId={props.templateId ?? undefined} />\n </Suspense>\n );\n}\n\nfunction NewApprovalInstanceContent({\n templateId: templateIdProp,\n}: {\n readonly templateId?: string;\n}): ReactElement {\n const router = useRouterAdapter();\n const routes = useBPMRoutes();\n const { member } = useAuth();\n const currentMemberId = member?.memberId ?? null;\n const templateId = templateIdProp ?? null;\n const [context, setContext] = useState<LaunchContext | null>(null);\n const [formValues, setFormValues] = useState<FormRendererValues>({});\n const [templates, setTemplates] = useState<\n readonly LaunchableTemplateRecord[]\n >([]);\n const [error, setError] = useState<string | null>(null);\n const [formErrors, setFormErrors] = useState<\n Readonly<Record<string, string>>\n >({});\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [dataSourceStates, setDataSourceStates] = useState<\n Readonly<\n Record<string, Pick<FormDataSourceFieldState, 'hasValue' | 'status'>>\n >\n >({});\n const fileUploads = useFileUploadFieldStates();\n\n // The form the applicant sees: approver-filled fields are not theirs to fill\n // (the server drops them), so they are left out of everything below.\n const applicantSchema = useMemo(\n () =>\n context\n ? readApplicantFormSchema(\n context.formVersion.schema,\n context.templateVersion.workflowDefinition,\n )\n : null,\n [context],\n );\n\n const handleDataSourceStateChange = useCallback(\n (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'status'\n >,\n ): void => {\n setDataSourceStates((currentStates) => {\n const currentState = currentStates[fieldKey];\n\n if (\n currentState?.hasValue === state.hasValue &&\n currentState.status === state.status\n ) {\n return currentStates;\n }\n\n return {\n ...currentStates,\n [fieldKey]: {\n hasValue: state.hasValue,\n status: state.status,\n },\n };\n });\n },\n [],\n );\n\n useEffect((): void => {\n if (!templateId) {\n void refreshTemplates();\n\n return;\n }\n\n void refreshContext(templateId);\n }, [templateId]);\n\n const rows = useMemo(\n (): LaunchableTemplateRow[] =>\n templates.map((template) => ({\n ...template,\n key: template.id,\n updatedAt: formatDateTime(template.updatedAt),\n versionLabel: `v${template.version}`,\n })),\n [templates],\n );\n const columns = useMemo(\n (): TableColumn<LaunchableTemplateRow>[] => [\n { dataIndex: 'name', key: 'name', title: '模板名稱', width: 240 },\n {\n dataIndex: 'versionLabel',\n key: 'versionLabel',\n title: '發布版本',\n width: 120,\n },\n {\n dataIndex: 'updatedAt',\n key: 'updatedAt',\n title: '更新時間',\n width: 220,\n },\n ],\n [],\n );\n const tableActions = useMemo(\n (): TableActions<LaunchableTemplateRow> => ({\n render: (\n record,\n ): ReturnType<TableActions<LaunchableTemplateRow>['render']> => [\n {\n name: '發起',\n onClick: (): void =>\n router.push(routes.caseNew(record.id)),\n variant: 'base-primary',\n },\n ],\n variant: 'base-secondary',\n width: 88,\n }),\n [router],\n );\n\n async function refreshTemplates(): Promise<void> {\n setLoading(true);\n setError(null);\n setContext(null);\n setDataSourceStates({});\n\n try {\n setTemplates(await listLaunchableTemplates());\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function refreshContext(nextTemplateId: string): Promise<void> {\n setLoading(true);\n setError(null);\n setTemplates([]);\n setDataSourceStates({});\n\n try {\n setContext(await readLaunchContext(nextTemplateId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function handleSubmit(): Promise<void> {\n if (!context || !applicantSchema || !currentMemberId) {\n return;\n }\n\n setSubmitting(true);\n setError(null);\n setFormErrors({});\n\n const dataSourceBlockMessage = readFormDataSourceSubmissionBlockMessage(\n Object.values(dataSourceStates),\n );\n\n if (dataSourceBlockMessage) {\n setError(dataSourceBlockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // A file still uploading, or one that failed, is listed in its field but\n // is not in the value; submitting now would leave it off the case.\n if (fileUploads.blockMessage) {\n setError(fileUploads.blockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // What the renderer shows, not just what has been touched: a table seeds\n // its `minRows` rows and a field can carry a `defaultValue`, and neither\n // reaches this state until the filler edits something. Validating and\n // submitting the raw state would reject a table the user can plainly see\n // rows in — and submit a default the backend never receives.\n const submittedValues = readApplicantSubmission(\n buildFormRendererValues(applicantSchema.fields, formValues),\n context.templateVersion.workflowDefinition,\n );\n // Inside the `try`, so a validation that throws still clears `submitting`\n // and shows its error instead of leaving the button busy for good.\n try {\n // The format patterns run in a worker under the engine's time budget, so\n // a pattern that backtracks cannot freeze the page.\n const validation = await validateFormRendererValuesInWorker({\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n values: submittedValues,\n });\n\n if (!validation.valid) {\n setFormErrors(validation.errors);\n setError('請先修正表單中標示的欄位。');\n\n if (validation.firstInvalidFieldKey) {\n focusFormRendererField(validation.firstInvalidFieldKey);\n }\n\n return;\n }\n\n const instanceId = await submitApprovalInstance({\n formData: submittedValues,\n initiatorMemberId: currentMemberId,\n templateId: context.template.id,\n title: readFormDataCaseTitle({\n fallbackTitle: context.template.name,\n formData: submittedValues,\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n }),\n });\n\n router.push(routes.caseDetail(instanceId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setSubmitting(false);\n }\n }\n\n async function handleUploadAttachment(\n field: FormFieldDefinition,\n file: File,\n ): Promise<{ readonly id: string }> {\n if (!currentMemberId) {\n throw new Error('尚未登入,無法上傳附件');\n }\n\n const attachment = await uploadAttachment({\n file,\n formFieldPath: `form.${field.fieldKey}`,\n });\n\n return { id: attachment.id };\n }\n\n return (\n <>\n <PageHeader>\n <ContentHeader\n description={\n context\n ? `${context.template.name} · 表單 v${context.formVersion.version}`\n : '選擇可發起的已發布模板後填寫表單內容。'\n }\n title=\"發起簽核\"\n >\n {context ? (\n <Button\n disabled={loading || submitting}\n icon={CheckedIcon}\n iconType=\"leading\"\n onClick={handleSubmit}\n variant=\"base-primary\"\n >\n 送出\n </Button>\n ) : null}\n </ContentHeader>\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <div style={FORM_SECTION_STYLE}>\n {error ? (\n <Typography color=\"text-error\" variant=\"body\">\n {error}\n </Typography>\n ) : null}\n\n {loading ? (\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n ) : null}\n\n {context && applicantSchema ? (\n <FormRenderer\n dataSourceContext={{\n kind: 'runtime',\n templateId: context.template.id,\n }}\n errors={formErrors}\n maxWidth={480}\n onChange={(values): void => {\n setFormValues(values);\n setFormErrors({});\n }}\n onDataSourceStateChange={handleDataSourceStateChange}\n onFileUploadStateChange={fileUploads.onFileUploadStateChange}\n onUploadAttachment={handleUploadAttachment}\n schema={applicantSchema}\n singleColumn\n uiSchema={context.formVersion.uiSchema}\n value={formValues}\n />\n ) : null}\n\n {!templateId && !loading ? (\n rows.length > 0 ? (\n <Table\n actions={tableActions}\n columns={columns}\n dataSource={rows}\n fullWidth\n />\n ) : (\n <Typography color=\"text-neutral\" variant=\"body\">\n 目前沒有可發起的已發布模板。\n </Typography>\n )\n ) : null}\n </div>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\nfunction NewApprovalInstanceLoading(): ReactElement {\n return (\n <>\n <PageHeader>\n <ContentHeader\n description=\"選擇可發起的已發布模板後填寫表單內容。\"\n title=\"發起簽核\"\n />\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\n"],"mappings":"A,+vBAsDA,IAAM4C,EAAoC,CACxC,QAAS,OACT,IAAK,EACP,EAwBA,SAAgBC,EACd,EAA8B,CAAC,EACjB,CACd,OACE,EAAAN,EAAA,IAAA,CAACvC,EAAAA,SAAD,CAAU,UAAU,EAAAuC,EAAA,IAAA,CAACO,EAAD,CAA6B,CAAA,EAC/C,UAAA,EAAAP,EAAA,IAAA,CAACQ,EAAD,CAA4B,WAAYC,EAAM,YAAc,IAAA,EAAY,CAAA,CAChE,CAAA,CAEd,CAEA,SAASD,EAA2B,CAClC,WAAYE,GAGG,CACf,IAAMC,EAASjD,EAAAA,EAAiB,EAC1BkD,EAASjD,EAAAA,EAAa,EACtB,CAAE,UAAWC,EAAAA,EAAQ,EACrBiD,EAAkBC,GAAQ,UAAY,KACtCC,EAAaL,GAAkB,KAC/B,CAACM,EAASC,IAAA,EAAcpD,EAAAA,SAAAA,CAA+B,IAAI,EAC3D,CAACqD,EAAYC,IAAA,EAAiBtD,EAAAA,SAAAA,CAA6B,CAAC,CAAC,EAC7D,CAACuD,EAAWC,IAAA,EAAgBxD,EAAAA,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Y,MAAM,eAAe,QAAQ,OAAO,SAAA,gBAEpC,CAAA,EAEZ,IACD,CACE,CAAA,CAAA,CAAA,CACG,CAAA,CACd,CAAA,CAAA,CAER,CAEA,SAASmB,GAA2C,CAClD,OACE,EAAAP,EAAA,KAAA,CAAAnB,EAAAA,SAAA,CAAA,SAAA,EACI,EAAAmB,EAAA,IAAA,CAAClB,EAAAA,WAAD,CAAA,UACE,EAAAkB,EAAA,IAAA,CAACjB,EAAAA,QAAD,CACE,YAAY,sBACZ,MAAM,MACP,CAAA,CACS,CAAA,GAEZ,EAAAiB,EAAA,IAAA,CAACd,EAAAA,aAAD,CAAA,UACE,EAAAc,EAAA,IAAA,CAACb,EAAAA,QAAD,CAAA,UACE,EAAAa,EAAA,IAAA,CAACZ,EAAAA,WAAD,CAAY,MAAM,eAAe,QAAQ,OAAO,SAAA,QAEpC,CAAA,CACL,CAAA,CACG,CAAA,CACd,CAAA,CAAA,CAER,C"}
1
+ {"version":3,"file":"index.cjs","names":["Suspense","useRouterAdapter","useBPMRoutes","useAuth","useState","useFileUploadFieldStates","useMemo","readApplicantFormSchema","useCallback","formatDateTime","listLaunchableTemplates","readErrorMessage","readLaunchContext","readFormDataSourceSubmissionBlockMessage","readApplicantSubmission","buildFormRendererValues","validateFormRendererValuesInWorker","submitApprovalInstance","readFormDataCaseTitle","uploadAttachment","_Fragment","PageHeader","ContentHeader","Button","CheckedIcon","SectionGroup","Section","Typography","FormRenderer","Table","require_rolldown_runtime","require_instance_error_message","require_format_date_time","require_auth_provider","require_router_adapter","require_routes_config","require_FormRendererView","react","_mezzanine_ui_react","react_jsx_runtime","_rytass_bpm_core_client_workflow","_mezzanine_ui_react_ContentHeader","_mezzanine_ui_icons","_rytass_bpm_core_client_form","FORM_SECTION_STYLE","InstanceNewView","NewApprovalInstanceLoading","NewApprovalInstanceContent","props","templateIdProp","router","routes","currentMemberId","member","templateId","context","setContext","formValues","setFormValues","templates","setTemplates","error","setError","formErrors","setFormErrors","loading","setLoading","submitting","setSubmitting","dataSourceStates","setDataSourceStates","fileUploads","applicantSchema","handleDataSourceStateChange","currentState","currentStates","fieldKey","state","refreshContext","refreshTemplates","rows","template","columns","tableActions","record","requestError","nextTemplateId","handleSubmit","dataSourceBlockMessage","submittedValues","validation","instanceId","handleUploadAttachment","field","values"],"sources":["../../../../src/views/instances/new/InstanceNewView.tsx"],"sourcesContent":["'use client';\n\nimport {\n CSSProperties,\n ReactElement,\n Suspense,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n Button,\n PageHeader,\n Section,\n SectionGroup,\n Table,\n Typography,\n} from '@mezzanine-ui/react';\nimport ContentHeader from '@mezzanine-ui/react/ContentHeader';\nimport { CheckedIcon } from '@mezzanine-ui/icons';\nimport type { TableActions, TableColumn } from '@mezzanine-ui/core/table';\nimport { FormFieldDefinition } from '@rytass/bpm-core-shared/form';\nimport {\n buildFormRendererValues,\n focusFormRendererField,\n FormRendererValues,\n validateFormRendererValuesInWorker,\n} from '@rytass/bpm-core-client/form';\nimport {\n LaunchContext,\n LaunchableTemplateRecord,\n listLaunchableTemplates,\n readFormDataCaseTitle,\n readLaunchContext,\n submitApprovalInstance,\n uploadAttachment,\n} from '@rytass/bpm-core-client/workflow';\nimport {\n readApplicantFormSchema,\n readApplicantSubmission,\n} from '../approver-filled-form';\nimport { formatDateTime } from '../../../lib/format-date-time';\nimport { useAuth } from '../../../lib/auth-provider';\nimport { useRouterAdapter } from '../../../lib/router-adapter';\nimport { useBPMRoutes } from '../../../lib/routes-config';\nimport { FormRenderer } from '../../forms/renderer/FormRendererView';\nimport {\n readFormDataSourceSubmissionBlockMessage,\n type FormDataSourceFieldState,\n} from '../../forms/renderer/form-data-source-field';\nimport { useFileUploadFieldStates } from '../../forms/renderer/file-upload-field';\nimport { readErrorMessage } from '../instance-error-message';\n\nconst FORM_SECTION_STYLE: CSSProperties = {\n display: 'grid',\n gap: 16,\n};\n\ntype LaunchableTemplateRow = Readonly<\n Record<string, unknown> &\n LaunchableTemplateRecord & {\n key: string;\n versionLabel: string;\n }\n>;\n\nexport interface InstanceNewViewProps {\n /**\n * Optional template id pre-selected by the host. The Server Component\n * page should read `?templateId=` from its `searchParams` and pass the\n * value through this prop.\n */\n readonly templateId?: string | null;\n}\n\n/**\n * Framework-agnostic view for the BPM \"發起簽核\" launch page. Mechanical port\n * of `apps/client/src/app/instances/new/page.tsx` — picks a launchable\n * template and submits the launch form.\n */\nexport function InstanceNewView(\n props: InstanceNewViewProps = {},\n): ReactElement {\n return (\n <Suspense fallback={<NewApprovalInstanceLoading />}>\n <NewApprovalInstanceContent templateId={props.templateId ?? undefined} />\n </Suspense>\n );\n}\n\nfunction NewApprovalInstanceContent({\n templateId: templateIdProp,\n}: {\n readonly templateId?: string;\n}): ReactElement {\n const router = useRouterAdapter();\n const routes = useBPMRoutes();\n const { member } = useAuth();\n const currentMemberId = member?.memberId ?? null;\n const templateId = templateIdProp ?? null;\n const [context, setContext] = useState<LaunchContext | null>(null);\n const [formValues, setFormValues] = useState<FormRendererValues>({});\n const [templates, setTemplates] = useState<\n readonly LaunchableTemplateRecord[]\n >([]);\n const [error, setError] = useState<string | null>(null);\n const [formErrors, setFormErrors] = useState<\n Readonly<Record<string, string>>\n >({});\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [dataSourceStates, setDataSourceStates] = useState<\n Readonly<\n Record<\n string,\n Pick<FormDataSourceFieldState, 'hasValue' | 'selectionExpired' | 'status'>\n >\n >\n >({});\n const fileUploads = useFileUploadFieldStates();\n\n // The form the applicant sees: approver-filled fields are not theirs to fill\n // (the server drops them), so they are left out of everything below.\n const applicantSchema = useMemo(\n () =>\n context\n ? readApplicantFormSchema(\n context.formVersion.schema,\n context.templateVersion.workflowDefinition,\n )\n : null,\n [context],\n );\n\n const handleDataSourceStateChange = useCallback(\n (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'selectionExpired' | 'status'\n >,\n ): void => {\n setDataSourceStates((currentStates) => {\n const currentState = currentStates[fieldKey];\n\n if (\n currentState?.hasValue === state.hasValue &&\n currentState.selectionExpired === (state.selectionExpired === true) &&\n currentState.status === state.status\n ) {\n return currentStates;\n }\n\n return {\n ...currentStates,\n [fieldKey]: {\n hasValue: state.hasValue,\n selectionExpired: state.selectionExpired === true,\n status: state.status,\n },\n };\n });\n },\n [],\n );\n\n useEffect((): void => {\n if (!templateId) {\n void refreshTemplates();\n\n return;\n }\n\n void refreshContext(templateId);\n }, [templateId]);\n\n const rows = useMemo(\n (): LaunchableTemplateRow[] =>\n templates.map((template) => ({\n ...template,\n key: template.id,\n updatedAt: formatDateTime(template.updatedAt),\n versionLabel: `v${template.version}`,\n })),\n [templates],\n );\n const columns = useMemo(\n (): TableColumn<LaunchableTemplateRow>[] => [\n { dataIndex: 'name', key: 'name', title: '模板名稱', width: 240 },\n {\n dataIndex: 'versionLabel',\n key: 'versionLabel',\n title: '發布版本',\n width: 120,\n },\n {\n dataIndex: 'updatedAt',\n key: 'updatedAt',\n title: '更新時間',\n width: 220,\n },\n ],\n [],\n );\n const tableActions = useMemo(\n (): TableActions<LaunchableTemplateRow> => ({\n render: (\n record,\n ): ReturnType<TableActions<LaunchableTemplateRow>['render']> => [\n {\n name: '發起',\n onClick: (): void =>\n router.push(routes.caseNew(record.id)),\n variant: 'base-primary',\n },\n ],\n variant: 'base-secondary',\n width: 88,\n }),\n [router],\n );\n\n async function refreshTemplates(): Promise<void> {\n setLoading(true);\n setError(null);\n setContext(null);\n setDataSourceStates({});\n\n try {\n setTemplates(await listLaunchableTemplates());\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function refreshContext(nextTemplateId: string): Promise<void> {\n setLoading(true);\n setError(null);\n setTemplates([]);\n setDataSourceStates({});\n\n try {\n setContext(await readLaunchContext(nextTemplateId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function handleSubmit(): Promise<void> {\n if (!context || !applicantSchema || !currentMemberId) {\n return;\n }\n\n setSubmitting(true);\n setError(null);\n setFormErrors({});\n\n const dataSourceBlockMessage = readFormDataSourceSubmissionBlockMessage(\n Object.values(dataSourceStates),\n );\n\n if (dataSourceBlockMessage) {\n setError(dataSourceBlockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // A file still uploading, or one that failed, is listed in its field but\n // is not in the value; submitting now would leave it off the case.\n if (fileUploads.blockMessage) {\n setError(fileUploads.blockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // What the renderer shows, not just what has been touched: a table seeds\n // its `minRows` rows and a field can carry a `defaultValue`, and neither\n // reaches this state until the filler edits something. Validating and\n // submitting the raw state would reject a table the user can plainly see\n // rows in — and submit a default the backend never receives.\n const submittedValues = readApplicantSubmission(\n buildFormRendererValues(applicantSchema.fields, formValues),\n context.templateVersion.workflowDefinition,\n );\n // Inside the `try`, so a validation that throws still clears `submitting`\n // and shows its error instead of leaving the button busy for good.\n try {\n // The format patterns run in a worker under the engine's time budget, so\n // a pattern that backtracks cannot freeze the page.\n const validation = await validateFormRendererValuesInWorker({\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n values: submittedValues,\n });\n\n if (!validation.valid) {\n setFormErrors(validation.errors);\n setError('請先修正表單中標示的欄位。');\n\n if (validation.firstInvalidFieldKey) {\n focusFormRendererField(validation.firstInvalidFieldKey);\n }\n\n return;\n }\n\n const instanceId = await submitApprovalInstance({\n formData: submittedValues,\n initiatorMemberId: currentMemberId,\n templateId: context.template.id,\n title: readFormDataCaseTitle({\n fallbackTitle: context.template.name,\n formData: submittedValues,\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n }),\n });\n\n router.push(routes.caseDetail(instanceId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setSubmitting(false);\n }\n }\n\n async function handleUploadAttachment(\n field: FormFieldDefinition,\n file: File,\n ): Promise<{ readonly id: string }> {\n if (!currentMemberId) {\n throw new Error('尚未登入,無法上傳附件');\n }\n\n const attachment = await uploadAttachment({\n file,\n formFieldPath: `form.${field.fieldKey}`,\n });\n\n return { id: attachment.id };\n }\n\n return (\n <>\n <PageHeader>\n <ContentHeader\n description={\n context\n ? `${context.template.name} · 表單 v${context.formVersion.version}`\n : '選擇可發起的已發布模板後填寫表單內容。'\n }\n title=\"發起簽核\"\n >\n {context ? (\n <Button\n disabled={loading || submitting}\n icon={CheckedIcon}\n iconType=\"leading\"\n onClick={handleSubmit}\n variant=\"base-primary\"\n >\n 送出\n </Button>\n ) : null}\n </ContentHeader>\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <div style={FORM_SECTION_STYLE}>\n {error ? (\n <Typography color=\"text-error\" variant=\"body\">\n {error}\n </Typography>\n ) : null}\n\n {loading ? (\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n ) : null}\n\n {context && applicantSchema ? (\n <FormRenderer\n dataSourceContext={{\n kind: 'runtime',\n templateId: context.template.id,\n }}\n errors={formErrors}\n maxWidth={480}\n onChange={(values): void => {\n setFormValues(values);\n setFormErrors({});\n }}\n onDataSourceStateChange={handleDataSourceStateChange}\n onFileUploadStateChange={fileUploads.onFileUploadStateChange}\n onUploadAttachment={handleUploadAttachment}\n schema={applicantSchema}\n singleColumn\n uiSchema={context.formVersion.uiSchema}\n value={formValues}\n />\n ) : null}\n\n {!templateId && !loading ? (\n rows.length > 0 ? (\n <Table\n actions={tableActions}\n columns={columns}\n dataSource={rows}\n fullWidth\n />\n ) : (\n <Typography color=\"text-neutral\" variant=\"body\">\n 目前沒有可發起的已發布模板。\n </Typography>\n )\n ) : null}\n </div>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\nfunction NewApprovalInstanceLoading(): ReactElement {\n return (\n <>\n <PageHeader>\n <ContentHeader\n description=\"選擇可發起的已發布模板後填寫表單內容。\"\n title=\"發起簽核\"\n />\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\n"],"mappings":"A,+vBAsDA,IAAM4C,EAAoC,CACxC,QAAS,OACT,IAAK,EACP,EAwBA,SAAgBC,EACd,EAA8B,CAAC,EACjB,CACd,OACE,EAAAN,EAAA,IAAA,CAACvC,EAAAA,SAAD,CAAU,UAAU,EAAAuC,EAAA,IAAA,CAACO,EAAD,CAA6B,CAAA,EAC/C,UAAA,EAAAP,EAAA,IAAA,CAACQ,EAAD,CAA4B,WAAYC,EAAM,YAAc,IAAA,EAAY,CAAA,CAChE,CAAA,CAEd,CAEA,SAASD,EAA2B,CAClC,WAAYE,GAGG,CACf,IAAMC,EAASjD,EAAAA,EAAiB,EAC1BkD,EAASjD,EAAAA,EAAa,EACtB,CAAE,UAAWC,EAAAA,EAAQ,EACrBiD,EAAkBC,GAAQ,UAAY,KACtCC,EAAaL,GAAkB,KAC/B,CAACM,EAASC,IAAA,EAAcpD,EAAAA,SAAAA,CAA+B,IAAI,EAC3D,CAACqD,EAAYC,IAAA,EAAiBtD,EAAAA,SAAAA,CAA6B,CAAC,CAAC,EAC7D,CAACuD,EAAWC,IAAA,EAAgBxD,EAAAA,SAAAA,CAEhC,CAAC,CAAC,EACE,CAACyD,EAAOC,IAAA,EAAY1D,EAAAA,SAAAA,CAAwB,IAAI,EAChD,CAAC2D,EAAYC,IAAA,EAAiB5D,EAAAA,SAAAA,CAElC,CAAC,CAAC,EACE,CAAC6D,EAASC,IAAA,EAAc9D,EAAAA,SAAAA,CAAS,EAAI,EACrC,CAAC+D,EAAYC,IAAA,EAAiBhE,EAAAA,SAAAA,CAAS,EAAK,EAC5C,CAACiE,EAAkBC,IAAA,EAAuBlE,EAAAA,SAAAA,CAO9C,CAAC,CAAC,EACEmE,EAAclE,EAAAA,EAAyB,EAIvCmE,GAAA,EAAkBlE,EAAAA,QAAAA,KAEpBiD,EACIhD,EAAAA,EACEgD,EAAQ,YAAY,OACp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E,EAAAc,EAAA,IAAA,CAACb,EAAAA,QAAD,CAAA,UACE,EAAAa,EAAA,IAAA,CAACZ,EAAAA,WAAD,CAAY,MAAM,eAAe,QAAQ,OAAO,SAAA,QAEpC,CAAA,CACL,CAAA,CACG,CAAA,CACd,CAAA,CAAA,CAER,C"}
@@ -4,7 +4,7 @@ import { t as r } from "../../../chunks/format-date-time-B0LdmWg4.js";
4
4
  import { n as i } from "../../../chunks/auth-provider-C2b-5mGt.js";
5
5
  import { r as a } from "../../../chunks/router-adapter-CkxCyzf5.js";
6
6
  import { r as o } from "../../../chunks/routes-config-BcNaWJWJ.js";
7
- import { l as s, o as c, t as l } from "../../../chunks/FormRendererView-DHfVgbo6.js";
7
+ import { l as s, o as c, t as l } from "../../../chunks/FormRendererView-GfbVWEGa.js";
8
8
  import { Suspense as u, useCallback as d, useEffect as f, useMemo as p, useState as m } from "react";
9
9
  import { Button as ee, PageHeader as h, Section as g, SectionGroup as _, Table as v, Typography as y } from "@mezzanine-ui/react";
10
10
  import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
@@ -27,10 +27,11 @@ function j({ templateId: u }) {
27
27
  let A = a(), j = o(), { member: M } = i(), N = M?.memberId ?? null, P = u ?? null, [F, I] = m(null), [L, R] = m({}), [z, B] = m([]), [V, H] = m(null), [U, W] = m({}), [G, K] = m(!0), [q, J] = m(!1), [ae, Y] = m({}), X = c(), Z = p(() => F ? t(F.formVersion.schema, F.templateVersion.workflowDefinition) : null, [F]), oe = d((e, t) => {
28
28
  Y((n) => {
29
29
  let r = n[e];
30
- return r?.hasValue === t.hasValue && r.status === t.status ? n : {
30
+ return r?.hasValue === t.hasValue && r.selectionExpired === (t.selectionExpired === !0) && r.status === t.status ? n : {
31
31
  ...n,
32
32
  [e]: {
33
33
  hasValue: t.hasValue,
34
+ selectionExpired: t.selectionExpired === !0,
34
35
  status: t.status
35
36
  }
36
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Fragment","readApplicantSubmission","readApplicantFormSchema","readErrorMessage","formatDateTime","useAuth","useRouterAdapter","useBPMRoutes","readFormDataSourceSubmissionBlockMessage","useFileUploadFieldStates","FormRenderer","Fragment$1","ContentHeader","FORM_SECTION_STYLE","InstanceNewView","Suspense","NewApprovalInstanceLoading","NewApprovalInstanceContent","props","templateIdProp","router","routes","currentMemberId","member","templateId","context","setContext","useState","formValues","setFormValues","templates","setTemplates","error","setError","formErrors","setFormErrors","loading","setLoading","submitting","setSubmitting","dataSourceStates","setDataSourceStates","fileUploads","applicantSchema","useMemo","handleDataSourceStateChange","useCallback","currentState","currentStates","fieldKey","state","refreshContext","refreshTemplates","rows","template","columns","tableActions","record","listLaunchableTemplates","requestError","readLaunchContext","nextTemplateId","handleSubmit","dataSourceBlockMessage","submittedValues","buildFormRendererValues","validation","validateFormRendererValuesInWorker","focusFormRendererField","instanceId","submitApprovalInstance","readFormDataCaseTitle","handleUploadAttachment","uploadAttachment","field","PageHeader","Button","CheckedIcon","SectionGroup","Section","Typography","values","Table"],"sources":["../../../../src/views/instances/new/InstanceNewView.tsx"],"sourcesContent":["'use client';\n\nimport {\n CSSProperties,\n ReactElement,\n Suspense,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n Button,\n PageHeader,\n Section,\n SectionGroup,\n Table,\n Typography,\n} from '@mezzanine-ui/react';\nimport ContentHeader from '@mezzanine-ui/react/ContentHeader';\nimport { CheckedIcon } from '@mezzanine-ui/icons';\nimport type { TableActions, TableColumn } from '@mezzanine-ui/core/table';\nimport { FormFieldDefinition } from '@rytass/bpm-core-shared/form';\nimport {\n buildFormRendererValues,\n focusFormRendererField,\n FormRendererValues,\n validateFormRendererValuesInWorker,\n} from '@rytass/bpm-core-client/form';\nimport {\n LaunchContext,\n LaunchableTemplateRecord,\n listLaunchableTemplates,\n readFormDataCaseTitle,\n readLaunchContext,\n submitApprovalInstance,\n uploadAttachment,\n} from '@rytass/bpm-core-client/workflow';\nimport {\n readApplicantFormSchema,\n readApplicantSubmission,\n} from '../approver-filled-form';\nimport { formatDateTime } from '../../../lib/format-date-time';\nimport { useAuth } from '../../../lib/auth-provider';\nimport { useRouterAdapter } from '../../../lib/router-adapter';\nimport { useBPMRoutes } from '../../../lib/routes-config';\nimport { FormRenderer } from '../../forms/renderer/FormRendererView';\nimport {\n readFormDataSourceSubmissionBlockMessage,\n type FormDataSourceFieldState,\n} from '../../forms/renderer/form-data-source-field';\nimport { useFileUploadFieldStates } from '../../forms/renderer/file-upload-field';\nimport { readErrorMessage } from '../instance-error-message';\n\nconst FORM_SECTION_STYLE: CSSProperties = {\n display: 'grid',\n gap: 16,\n};\n\ntype LaunchableTemplateRow = Readonly<\n Record<string, unknown> &\n LaunchableTemplateRecord & {\n key: string;\n versionLabel: string;\n }\n>;\n\nexport interface InstanceNewViewProps {\n /**\n * Optional template id pre-selected by the host. The Server Component\n * page should read `?templateId=` from its `searchParams` and pass the\n * value through this prop.\n */\n readonly templateId?: string | null;\n}\n\n/**\n * Framework-agnostic view for the BPM \"發起簽核\" launch page. Mechanical port\n * of `apps/client/src/app/instances/new/page.tsx` — picks a launchable\n * template and submits the launch form.\n */\nexport function InstanceNewView(\n props: InstanceNewViewProps = {},\n): ReactElement {\n return (\n <Suspense fallback={<NewApprovalInstanceLoading />}>\n <NewApprovalInstanceContent templateId={props.templateId ?? undefined} />\n </Suspense>\n );\n}\n\nfunction NewApprovalInstanceContent({\n templateId: templateIdProp,\n}: {\n readonly templateId?: string;\n}): ReactElement {\n const router = useRouterAdapter();\n const routes = useBPMRoutes();\n const { member } = useAuth();\n const currentMemberId = member?.memberId ?? null;\n const templateId = templateIdProp ?? null;\n const [context, setContext] = useState<LaunchContext | null>(null);\n const [formValues, setFormValues] = useState<FormRendererValues>({});\n const [templates, setTemplates] = useState<\n readonly LaunchableTemplateRecord[]\n >([]);\n const [error, setError] = useState<string | null>(null);\n const [formErrors, setFormErrors] = useState<\n Readonly<Record<string, string>>\n >({});\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [dataSourceStates, setDataSourceStates] = useState<\n Readonly<\n Record<string, Pick<FormDataSourceFieldState, 'hasValue' | 'status'>>\n >\n >({});\n const fileUploads = useFileUploadFieldStates();\n\n // The form the applicant sees: approver-filled fields are not theirs to fill\n // (the server drops them), so they are left out of everything below.\n const applicantSchema = useMemo(\n () =>\n context\n ? readApplicantFormSchema(\n context.formVersion.schema,\n context.templateVersion.workflowDefinition,\n )\n : null,\n [context],\n );\n\n const handleDataSourceStateChange = useCallback(\n (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'status'\n >,\n ): void => {\n setDataSourceStates((currentStates) => {\n const currentState = currentStates[fieldKey];\n\n if (\n currentState?.hasValue === state.hasValue &&\n currentState.status === state.status\n ) {\n return currentStates;\n }\n\n return {\n ...currentStates,\n [fieldKey]: {\n hasValue: state.hasValue,\n status: state.status,\n },\n };\n });\n },\n [],\n );\n\n useEffect((): void => {\n if (!templateId) {\n void refreshTemplates();\n\n return;\n }\n\n void refreshContext(templateId);\n }, [templateId]);\n\n const rows = useMemo(\n (): LaunchableTemplateRow[] =>\n templates.map((template) => ({\n ...template,\n key: template.id,\n updatedAt: formatDateTime(template.updatedAt),\n versionLabel: `v${template.version}`,\n })),\n [templates],\n );\n const columns = useMemo(\n (): TableColumn<LaunchableTemplateRow>[] => [\n { dataIndex: 'name', key: 'name', title: '模板名稱', width: 240 },\n {\n dataIndex: 'versionLabel',\n key: 'versionLabel',\n title: '發布版本',\n width: 120,\n },\n {\n dataIndex: 'updatedAt',\n key: 'updatedAt',\n title: '更新時間',\n width: 220,\n },\n ],\n [],\n );\n const tableActions = useMemo(\n (): TableActions<LaunchableTemplateRow> => ({\n render: (\n record,\n ): ReturnType<TableActions<LaunchableTemplateRow>['render']> => [\n {\n name: '發起',\n onClick: (): void =>\n router.push(routes.caseNew(record.id)),\n variant: 'base-primary',\n },\n ],\n variant: 'base-secondary',\n width: 88,\n }),\n [router],\n );\n\n async function refreshTemplates(): Promise<void> {\n setLoading(true);\n setError(null);\n setContext(null);\n setDataSourceStates({});\n\n try {\n setTemplates(await listLaunchableTemplates());\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function refreshContext(nextTemplateId: string): Promise<void> {\n setLoading(true);\n setError(null);\n setTemplates([]);\n setDataSourceStates({});\n\n try {\n setContext(await readLaunchContext(nextTemplateId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function handleSubmit(): Promise<void> {\n if (!context || !applicantSchema || !currentMemberId) {\n return;\n }\n\n setSubmitting(true);\n setError(null);\n setFormErrors({});\n\n const dataSourceBlockMessage = readFormDataSourceSubmissionBlockMessage(\n Object.values(dataSourceStates),\n );\n\n if (dataSourceBlockMessage) {\n setError(dataSourceBlockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // A file still uploading, or one that failed, is listed in its field but\n // is not in the value; submitting now would leave it off the case.\n if (fileUploads.blockMessage) {\n setError(fileUploads.blockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // What the renderer shows, not just what has been touched: a table seeds\n // its `minRows` rows and a field can carry a `defaultValue`, and neither\n // reaches this state until the filler edits something. Validating and\n // submitting the raw state would reject a table the user can plainly see\n // rows in — and submit a default the backend never receives.\n const submittedValues = readApplicantSubmission(\n buildFormRendererValues(applicantSchema.fields, formValues),\n context.templateVersion.workflowDefinition,\n );\n // Inside the `try`, so a validation that throws still clears `submitting`\n // and shows its error instead of leaving the button busy for good.\n try {\n // The format patterns run in a worker under the engine's time budget, so\n // a pattern that backtracks cannot freeze the page.\n const validation = await validateFormRendererValuesInWorker({\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n values: submittedValues,\n });\n\n if (!validation.valid) {\n setFormErrors(validation.errors);\n setError('請先修正表單中標示的欄位。');\n\n if (validation.firstInvalidFieldKey) {\n focusFormRendererField(validation.firstInvalidFieldKey);\n }\n\n return;\n }\n\n const instanceId = await submitApprovalInstance({\n formData: submittedValues,\n initiatorMemberId: currentMemberId,\n templateId: context.template.id,\n title: readFormDataCaseTitle({\n fallbackTitle: context.template.name,\n formData: submittedValues,\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n }),\n });\n\n router.push(routes.caseDetail(instanceId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setSubmitting(false);\n }\n }\n\n async function handleUploadAttachment(\n field: FormFieldDefinition,\n file: File,\n ): Promise<{ readonly id: string }> {\n if (!currentMemberId) {\n throw new Error('尚未登入,無法上傳附件');\n }\n\n const attachment = await uploadAttachment({\n file,\n formFieldPath: `form.${field.fieldKey}`,\n });\n\n return { id: attachment.id };\n }\n\n return (\n <>\n <PageHeader>\n <ContentHeader\n description={\n context\n ? `${context.template.name} · 表單 v${context.formVersion.version}`\n : '選擇可發起的已發布模板後填寫表單內容。'\n }\n title=\"發起簽核\"\n >\n {context ? (\n <Button\n disabled={loading || submitting}\n icon={CheckedIcon}\n iconType=\"leading\"\n onClick={handleSubmit}\n variant=\"base-primary\"\n >\n 送出\n </Button>\n ) : null}\n </ContentHeader>\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <div style={FORM_SECTION_STYLE}>\n {error ? (\n <Typography color=\"text-error\" variant=\"body\">\n {error}\n </Typography>\n ) : null}\n\n {loading ? (\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n ) : null}\n\n {context && applicantSchema ? (\n <FormRenderer\n dataSourceContext={{\n kind: 'runtime',\n templateId: context.template.id,\n }}\n errors={formErrors}\n maxWidth={480}\n onChange={(values): void => {\n setFormValues(values);\n setFormErrors({});\n }}\n onDataSourceStateChange={handleDataSourceStateChange}\n onFileUploadStateChange={fileUploads.onFileUploadStateChange}\n onUploadAttachment={handleUploadAttachment}\n schema={applicantSchema}\n singleColumn\n uiSchema={context.formVersion.uiSchema}\n value={formValues}\n />\n ) : null}\n\n {!templateId && !loading ? (\n rows.length > 0 ? (\n <Table\n actions={tableActions}\n columns={columns}\n dataSource={rows}\n fullWidth\n />\n ) : (\n <Typography color=\"text-neutral\" variant=\"body\">\n 目前沒有可發起的已發布模板。\n </Typography>\n )\n ) : null}\n </div>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\nfunction NewApprovalInstanceLoading(): ReactElement {\n return (\n <>\n <PageHeader>\n <ContentHeader\n description=\"選擇可發起的已發布模板後填寫表單內容。\"\n title=\"發起簽核\"\n />\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,IAAMa,KAAoC;CACxC,SAAS;CACT,KAAK;AACP;AAwBA,SAAgBC,EACd,IAA8B,CAAC,GACjB;CACd,OACE,kBAACC,GAAD;EAAU,UAAU,kBAACC,GAAD,CAA6B,CAAA;EAC/C,UAAA,kBAACC,GAAD,EAA4B,YAAYC,EAAM,cAAc,KAAA,EAAY,CAAA;CAChE,CAAA;AAEd;AAEA,SAASD,EAA2B,EAClC,YAAYE,KAGG;CACf,IAAMC,IAASd,EAAiB,GAC1Be,IAASd,EAAa,GACtB,EAAE,cAAWF,EAAQ,GACrBiB,IAAkBC,GAAQ,YAAY,MACtCC,IAAaL,KAAkB,MAC/B,CAACM,GAASC,KAAcC,EAA+B,IAAI,GAC3D,CAACC,GAAYC,KAAiBF,EAA6B,CAAC,CAAC,GAC7D,CAACG,GAAWC,KAAgBJ,EAEhC,CAAC,CAAC,GACE,CAACK,GAAOC,KAAYN,EAAwB,IAAI,GAChD,CAACO,GAAYC,KAAiBR,EAElC,CAAC,CAAC,GACE,CAACS,GAASC,KAAcV,EAAS,EAAI,GACrC,CAACW,GAAYC,KAAiBZ,EAAS,EAAK,GAC5C,CAACa,IAAkBC,KAAuBd,EAI9C,CAAC,CAAC,GACEe,IAAcjC,EAAyB,G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A,UAAUlB,EAAQ,YAAY;IAC9B,OAAOG;GACR,CAAA,IACC;GAEH,CAACJ,KAAc,CAACY,IACfiB,EAAK,SAAS,IACZ,kBAAC6B,GAAD;IACE,SAAS1B;IACA;IACT,YAAYH;IACZ,WAAA;GACD,CAAA,IAED,kBAAC2B,GAAD;IAAY,OAAM;IAAe,SAAQ;IAAO,UAAA;GAEpC,CAAA,IAEZ;EACD;CACE,CAAA,EAAA,CAAA,EACG,CAAA,CACd,EAAA,CAAA;AAER;AAEA,SAAShE,IAA2C;CAClD,OACE,kBAAAhB,GAAA,EAAA,UAAA,CACI,kBAAC2E,GAAD,EAAA,UACE,kBAAC/D,GAAD;EACE,aAAY;EACZ,OAAM;CACP,CAAA,EACS,CAAA,GAEZ,kBAACkE,GAAD,EAAA,UACE,kBAACC,GAAD,EAAA,UACE,kBAACC,GAAD;EAAY,OAAM;EAAe,SAAQ;EAAO,UAAA;CAEpC,CAAA,EACL,CAAA,EACG,CAAA,CACd,EAAA,CAAA;AAER"}
1
+ {"version":3,"file":"index.js","names":["_Fragment","readApplicantSubmission","readApplicantFormSchema","readErrorMessage","formatDateTime","useAuth","useRouterAdapter","useBPMRoutes","readFormDataSourceSubmissionBlockMessage","useFileUploadFieldStates","FormRenderer","Fragment$1","ContentHeader","FORM_SECTION_STYLE","InstanceNewView","Suspense","NewApprovalInstanceLoading","NewApprovalInstanceContent","props","templateIdProp","router","routes","currentMemberId","member","templateId","context","setContext","useState","formValues","setFormValues","templates","setTemplates","error","setError","formErrors","setFormErrors","loading","setLoading","submitting","setSubmitting","dataSourceStates","setDataSourceStates","fileUploads","applicantSchema","useMemo","handleDataSourceStateChange","useCallback","currentState","currentStates","fieldKey","state","refreshContext","refreshTemplates","rows","template","columns","tableActions","record","listLaunchableTemplates","requestError","readLaunchContext","nextTemplateId","handleSubmit","dataSourceBlockMessage","submittedValues","buildFormRendererValues","validation","validateFormRendererValuesInWorker","focusFormRendererField","instanceId","submitApprovalInstance","readFormDataCaseTitle","handleUploadAttachment","uploadAttachment","field","PageHeader","Button","CheckedIcon","SectionGroup","Section","Typography","values","Table"],"sources":["../../../../src/views/instances/new/InstanceNewView.tsx"],"sourcesContent":["'use client';\n\nimport {\n CSSProperties,\n ReactElement,\n Suspense,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n Button,\n PageHeader,\n Section,\n SectionGroup,\n Table,\n Typography,\n} from '@mezzanine-ui/react';\nimport ContentHeader from '@mezzanine-ui/react/ContentHeader';\nimport { CheckedIcon } from '@mezzanine-ui/icons';\nimport type { TableActions, TableColumn } from '@mezzanine-ui/core/table';\nimport { FormFieldDefinition } from '@rytass/bpm-core-shared/form';\nimport {\n buildFormRendererValues,\n focusFormRendererField,\n FormRendererValues,\n validateFormRendererValuesInWorker,\n} from '@rytass/bpm-core-client/form';\nimport {\n LaunchContext,\n LaunchableTemplateRecord,\n listLaunchableTemplates,\n readFormDataCaseTitle,\n readLaunchContext,\n submitApprovalInstance,\n uploadAttachment,\n} from '@rytass/bpm-core-client/workflow';\nimport {\n readApplicantFormSchema,\n readApplicantSubmission,\n} from '../approver-filled-form';\nimport { formatDateTime } from '../../../lib/format-date-time';\nimport { useAuth } from '../../../lib/auth-provider';\nimport { useRouterAdapter } from '../../../lib/router-adapter';\nimport { useBPMRoutes } from '../../../lib/routes-config';\nimport { FormRenderer } from '../../forms/renderer/FormRendererView';\nimport {\n readFormDataSourceSubmissionBlockMessage,\n type FormDataSourceFieldState,\n} from '../../forms/renderer/form-data-source-field';\nimport { useFileUploadFieldStates } from '../../forms/renderer/file-upload-field';\nimport { readErrorMessage } from '../instance-error-message';\n\nconst FORM_SECTION_STYLE: CSSProperties = {\n display: 'grid',\n gap: 16,\n};\n\ntype LaunchableTemplateRow = Readonly<\n Record<string, unknown> &\n LaunchableTemplateRecord & {\n key: string;\n versionLabel: string;\n }\n>;\n\nexport interface InstanceNewViewProps {\n /**\n * Optional template id pre-selected by the host. The Server Component\n * page should read `?templateId=` from its `searchParams` and pass the\n * value through this prop.\n */\n readonly templateId?: string | null;\n}\n\n/**\n * Framework-agnostic view for the BPM \"發起簽核\" launch page. Mechanical port\n * of `apps/client/src/app/instances/new/page.tsx` — picks a launchable\n * template and submits the launch form.\n */\nexport function InstanceNewView(\n props: InstanceNewViewProps = {},\n): ReactElement {\n return (\n <Suspense fallback={<NewApprovalInstanceLoading />}>\n <NewApprovalInstanceContent templateId={props.templateId ?? undefined} />\n </Suspense>\n );\n}\n\nfunction NewApprovalInstanceContent({\n templateId: templateIdProp,\n}: {\n readonly templateId?: string;\n}): ReactElement {\n const router = useRouterAdapter();\n const routes = useBPMRoutes();\n const { member } = useAuth();\n const currentMemberId = member?.memberId ?? null;\n const templateId = templateIdProp ?? null;\n const [context, setContext] = useState<LaunchContext | null>(null);\n const [formValues, setFormValues] = useState<FormRendererValues>({});\n const [templates, setTemplates] = useState<\n readonly LaunchableTemplateRecord[]\n >([]);\n const [error, setError] = useState<string | null>(null);\n const [formErrors, setFormErrors] = useState<\n Readonly<Record<string, string>>\n >({});\n const [loading, setLoading] = useState(true);\n const [submitting, setSubmitting] = useState(false);\n const [dataSourceStates, setDataSourceStates] = useState<\n Readonly<\n Record<\n string,\n Pick<FormDataSourceFieldState, 'hasValue' | 'selectionExpired' | 'status'>\n >\n >\n >({});\n const fileUploads = useFileUploadFieldStates();\n\n // The form the applicant sees: approver-filled fields are not theirs to fill\n // (the server drops them), so they are left out of everything below.\n const applicantSchema = useMemo(\n () =>\n context\n ? readApplicantFormSchema(\n context.formVersion.schema,\n context.templateVersion.workflowDefinition,\n )\n : null,\n [context],\n );\n\n const handleDataSourceStateChange = useCallback(\n (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'selectionExpired' | 'status'\n >,\n ): void => {\n setDataSourceStates((currentStates) => {\n const currentState = currentStates[fieldKey];\n\n if (\n currentState?.hasValue === state.hasValue &&\n currentState.selectionExpired === (state.selectionExpired === true) &&\n currentState.status === state.status\n ) {\n return currentStates;\n }\n\n return {\n ...currentStates,\n [fieldKey]: {\n hasValue: state.hasValue,\n selectionExpired: state.selectionExpired === true,\n status: state.status,\n },\n };\n });\n },\n [],\n );\n\n useEffect((): void => {\n if (!templateId) {\n void refreshTemplates();\n\n return;\n }\n\n void refreshContext(templateId);\n }, [templateId]);\n\n const rows = useMemo(\n (): LaunchableTemplateRow[] =>\n templates.map((template) => ({\n ...template,\n key: template.id,\n updatedAt: formatDateTime(template.updatedAt),\n versionLabel: `v${template.version}`,\n })),\n [templates],\n );\n const columns = useMemo(\n (): TableColumn<LaunchableTemplateRow>[] => [\n { dataIndex: 'name', key: 'name', title: '模板名稱', width: 240 },\n {\n dataIndex: 'versionLabel',\n key: 'versionLabel',\n title: '發布版本',\n width: 120,\n },\n {\n dataIndex: 'updatedAt',\n key: 'updatedAt',\n title: '更新時間',\n width: 220,\n },\n ],\n [],\n );\n const tableActions = useMemo(\n (): TableActions<LaunchableTemplateRow> => ({\n render: (\n record,\n ): ReturnType<TableActions<LaunchableTemplateRow>['render']> => [\n {\n name: '發起',\n onClick: (): void =>\n router.push(routes.caseNew(record.id)),\n variant: 'base-primary',\n },\n ],\n variant: 'base-secondary',\n width: 88,\n }),\n [router],\n );\n\n async function refreshTemplates(): Promise<void> {\n setLoading(true);\n setError(null);\n setContext(null);\n setDataSourceStates({});\n\n try {\n setTemplates(await listLaunchableTemplates());\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function refreshContext(nextTemplateId: string): Promise<void> {\n setLoading(true);\n setError(null);\n setTemplates([]);\n setDataSourceStates({});\n\n try {\n setContext(await readLaunchContext(nextTemplateId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setLoading(false);\n }\n }\n\n async function handleSubmit(): Promise<void> {\n if (!context || !applicantSchema || !currentMemberId) {\n return;\n }\n\n setSubmitting(true);\n setError(null);\n setFormErrors({});\n\n const dataSourceBlockMessage = readFormDataSourceSubmissionBlockMessage(\n Object.values(dataSourceStates),\n );\n\n if (dataSourceBlockMessage) {\n setError(dataSourceBlockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // A file still uploading, or one that failed, is listed in its field but\n // is not in the value; submitting now would leave it off the case.\n if (fileUploads.blockMessage) {\n setError(fileUploads.blockMessage);\n setSubmitting(false);\n\n return;\n }\n\n // What the renderer shows, not just what has been touched: a table seeds\n // its `minRows` rows and a field can carry a `defaultValue`, and neither\n // reaches this state until the filler edits something. Validating and\n // submitting the raw state would reject a table the user can plainly see\n // rows in — and submit a default the backend never receives.\n const submittedValues = readApplicantSubmission(\n buildFormRendererValues(applicantSchema.fields, formValues),\n context.templateVersion.workflowDefinition,\n );\n // Inside the `try`, so a validation that throws still clears `submitting`\n // and shows its error instead of leaving the button busy for good.\n try {\n // The format patterns run in a worker under the engine's time budget, so\n // a pattern that backtracks cannot freeze the page.\n const validation = await validateFormRendererValuesInWorker({\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n values: submittedValues,\n });\n\n if (!validation.valid) {\n setFormErrors(validation.errors);\n setError('請先修正表單中標示的欄位。');\n\n if (validation.firstInvalidFieldKey) {\n focusFormRendererField(validation.firstInvalidFieldKey);\n }\n\n return;\n }\n\n const instanceId = await submitApprovalInstance({\n formData: submittedValues,\n initiatorMemberId: currentMemberId,\n templateId: context.template.id,\n title: readFormDataCaseTitle({\n fallbackTitle: context.template.name,\n formData: submittedValues,\n schema: applicantSchema,\n uiSchema: context.formVersion.uiSchema,\n }),\n });\n\n router.push(routes.caseDetail(instanceId));\n } catch (requestError: unknown) {\n setError(readErrorMessage(requestError));\n } finally {\n setSubmitting(false);\n }\n }\n\n async function handleUploadAttachment(\n field: FormFieldDefinition,\n file: File,\n ): Promise<{ readonly id: string }> {\n if (!currentMemberId) {\n throw new Error('尚未登入,無法上傳附件');\n }\n\n const attachment = await uploadAttachment({\n file,\n formFieldPath: `form.${field.fieldKey}`,\n });\n\n return { id: attachment.id };\n }\n\n return (\n <>\n <PageHeader>\n <ContentHeader\n description={\n context\n ? `${context.template.name} · 表單 v${context.formVersion.version}`\n : '選擇可發起的已發布模板後填寫表單內容。'\n }\n title=\"發起簽核\"\n >\n {context ? (\n <Button\n disabled={loading || submitting}\n icon={CheckedIcon}\n iconType=\"leading\"\n onClick={handleSubmit}\n variant=\"base-primary\"\n >\n 送出\n </Button>\n ) : null}\n </ContentHeader>\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <div style={FORM_SECTION_STYLE}>\n {error ? (\n <Typography color=\"text-error\" variant=\"body\">\n {error}\n </Typography>\n ) : null}\n\n {loading ? (\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n ) : null}\n\n {context && applicantSchema ? (\n <FormRenderer\n dataSourceContext={{\n kind: 'runtime',\n templateId: context.template.id,\n }}\n errors={formErrors}\n maxWidth={480}\n onChange={(values): void => {\n setFormValues(values);\n setFormErrors({});\n }}\n onDataSourceStateChange={handleDataSourceStateChange}\n onFileUploadStateChange={fileUploads.onFileUploadStateChange}\n onUploadAttachment={handleUploadAttachment}\n schema={applicantSchema}\n singleColumn\n uiSchema={context.formVersion.uiSchema}\n value={formValues}\n />\n ) : null}\n\n {!templateId && !loading ? (\n rows.length > 0 ? (\n <Table\n actions={tableActions}\n columns={columns}\n dataSource={rows}\n fullWidth\n />\n ) : (\n <Typography color=\"text-neutral\" variant=\"body\">\n 目前沒有可發起的已發布模板。\n </Typography>\n )\n ) : null}\n </div>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\nfunction NewApprovalInstanceLoading(): ReactElement {\n return (\n <>\n <PageHeader>\n <ContentHeader\n description=\"選擇可發起的已發布模板後填寫表單內容。\"\n title=\"發起簽核\"\n />\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <Typography color=\"text-neutral\" variant=\"body\">\n 載入中...\n </Typography>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,IAAMa,KAA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AC/D,GAAD;EACE,aAAY;EACZ,OAAM;CACP,CAAA,EACS,CAAA,GAEZ,kBAACkE,GAAD,EAAA,UACE,kBAACC,GAAD,EAAA,UACE,kBAACC,GAAD;EAAY,OAAM;EAAe,SAAQ;EAAO,UAAA;CAEpC,CAAA,EACL,CAAA,EACG,CAAA,CACd,EAAA,CAAA;AAER"}
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/compose-NH6dsFXD.cjs");exports.EMPTY_COMPOSE_FORM_SCHEMA=e.n,exports.EMPTY_COMPOSE_FORM_UI_SCHEMA=e.r,exports.TemplateComposeWizardView=e.t,exports.useTemplateComposeWizard=e.i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/compose-Bb5bUVFd.cjs");exports.EMPTY_COMPOSE_FORM_SCHEMA=e.n,exports.EMPTY_COMPOSE_FORM_UI_SCHEMA=e.r,exports.TemplateComposeWizardView=e.t,exports.useTemplateComposeWizard=e.i;
@@ -1 +1 @@
1
- export { n as EMPTY_COMPOSE_FORM_SCHEMA, r as EMPTY_COMPOSE_FORM_UI_SCHEMA, t as TemplateComposeWizardView, i as useTemplateComposeWizard } from "../../../chunks/compose-D6zBIc2Z.js";
1
+ export { n as EMPTY_COMPOSE_FORM_SCHEMA, r as EMPTY_COMPOSE_FORM_UI_SCHEMA, t as TemplateComposeWizardView, i as useTemplateComposeWizard } from "../../../chunks/compose-egQlRjuZ.js";
@@ -8,5 +8,12 @@ export declare function readTemplateVersionDescription(input: {
8
8
  hasPublishedVersion: boolean;
9
9
  publishedVersion: number | null;
10
10
  }): string;
11
+ /**
12
+ * The designer header's description line: the version line plus the
13
+ * definition's expression dialect. `ContentHeader` drops any child that is not
14
+ * a button, filter or back link, so a dialect `Tag` there never rendered; its
15
+ * `description` string is the slot it does show.
16
+ */
17
+ export declare function readTemplateHeaderDescription(versionDescription: string, expressionDialect: string): string;
11
18
  /** The bound form's version, labelled so it is not mistaken for the template's. */
12
19
  export declare function readFormVersionLabel(formName: string, version: number): string;
@@ -8,5 +8,12 @@ export declare function readTemplateVersionDescription(input: {
8
8
  hasPublishedVersion: boolean;
9
9
  publishedVersion: number | null;
10
10
  }): string;
11
+ /**
12
+ * The designer header's description line: the version line plus the
13
+ * definition's expression dialect. `ContentHeader` drops any child that is not
14
+ * a button, filter or back link, so a dialect `Tag` there never rendered; its
15
+ * `description` string is the slot it does show.
16
+ */
17
+ export declare function readTemplateHeaderDescription(versionDescription: string, expressionDialect: string): string;
11
18
  /** The bound form's version, labelled so it is not mistaken for the template's. */
12
19
  export declare function readFormVersionLabel(formName: string, version: number): string;
@@ -0,0 +1,25 @@
1
+ import { ReactElement } from 'react';
2
+ import { WorkflowDialectUpgradePreviewRecord, WorkflowExpressionsDraft } from '@rytass/bpm-core-client/template';
3
+ export interface DialectUpgradeModalProps {
4
+ /** The draft to check: the designer's current state, saved or not. */
5
+ readonly draft: WorkflowExpressionsDraft;
6
+ readonly onCancel: () => void;
7
+ /** The user confirmed; the host switches the draft to cel-v2. */
8
+ readonly onConfirm: () => void;
9
+ readonly open: boolean;
10
+ /** Injectable for tests and Storybook. */
11
+ readonly preview?: (draft: WorkflowExpressionsDraft) => Promise<WorkflowDialectUpgradePreviewRecord>;
12
+ }
13
+ /** `ok:<json>` / `err:<code>` as the designer reads it. */
14
+ export declare function readDialectOutcomeText(outcome: string): string;
15
+ /** Whether the check lets the user upgrade on it. */
16
+ export declare function canConfirmDialectUpgrade(result: WorkflowDialectUpgradePreviewRecord | null): boolean;
17
+ /**
18
+ * The whole-draft dialect upgrade (Phase 23 P4, docs/24 §1): before a draft
19
+ * moves from cel-legacy to cel-v2 the backend runs every expression under
20
+ * both engines on sample data and lists where the answers differ, e.g.
21
+ * `7 / 2` is 3.5 on legacy and an integer division on cel-v2. Nothing is
22
+ * changed here; confirming hands the decision back to the designer, which
23
+ * sets the dialect on the draft and saves it the usual way.
24
+ */
25
+ export declare function DialectUpgradeModal({ draft, onCancel, onConfirm, open, preview, }: DialectUpgradeModalProps): ReactElement;
@@ -0,0 +1,25 @@
1
+ import { ReactElement } from 'react';
2
+ import { WorkflowDialectUpgradePreviewRecord, WorkflowExpressionsDraft } from '@rytass/bpm-core-client/template';
3
+ export interface DialectUpgradeModalProps {
4
+ /** The draft to check: the designer's current state, saved or not. */
5
+ readonly draft: WorkflowExpressionsDraft;
6
+ readonly onCancel: () => void;
7
+ /** The user confirmed; the host switches the draft to cel-v2. */
8
+ readonly onConfirm: () => void;
9
+ readonly open: boolean;
10
+ /** Injectable for tests and Storybook. */
11
+ readonly preview?: (draft: WorkflowExpressionsDraft) => Promise<WorkflowDialectUpgradePreviewRecord>;
12
+ }
13
+ /** `ok:<json>` / `err:<code>` as the designer reads it. */
14
+ export declare function readDialectOutcomeText(outcome: string): string;
15
+ /** Whether the check lets the user upgrade on it. */
16
+ export declare function canConfirmDialectUpgrade(result: WorkflowDialectUpgradePreviewRecord | null): boolean;
17
+ /**
18
+ * The whole-draft dialect upgrade (Phase 23 P4, docs/24 §1): before a draft
19
+ * moves from cel-legacy to cel-v2 the backend runs every expression under
20
+ * both engines on sample data and lists where the answers differ, e.g.
21
+ * `7 / 2` is 3.5 on legacy and an integer division on cel-v2. Nothing is
22
+ * changed here; confirming hands the decision back to the designer, which
23
+ * sets the dialect on the draft and saves it the usual way.
24
+ */
25
+ export declare function DialectUpgradeModal({ draft, onCancel, onConfirm, open, preview, }: DialectUpgradeModalProps): ReactElement;
@@ -0,0 +1,79 @@
1
+ import { ReactElement } from 'react';
2
+ import { ExpressionUsagePoint } from '@rytass/bpm-core-shared';
3
+ import { WorkflowExpressionDialect } from '@rytass/bpm-core-shared/workflow';
4
+ import { GraphQlRequestOptions } from '@rytass/bpm-core-client';
5
+ import { ExpressionCatalogRecord, ExpressionEvaluationRecord, ExpressionIssueRecord, ExpressionPreviewRecord, PreviewExpressionInput } from '@rytass/bpm-core-client/template';
6
+ /**
7
+ * Where the backend check of one expression stands. `UNAVAILABLE`: the check
8
+ * itself failed (network, 403); the field cannot vouch for the expression.
9
+ */
10
+ export type ExpressionFieldStatus = 'CHECKING' | 'EMPTY' | 'INVALID' | 'UNAVAILABLE' | 'VALID';
11
+ export interface ExpressionFieldLint {
12
+ readonly issues: readonly ExpressionIssueRecord[];
13
+ readonly status: ExpressionFieldStatus;
14
+ }
15
+ /** The backend calls the field makes; injectable for tests and Storybook. */
16
+ export interface ExpressionFieldApi {
17
+ readonly preview: (input: PreviewExpressionInput, options?: GraphQlRequestOptions) => Promise<ExpressionPreviewRecord>;
18
+ readonly readCatalog: (input: Readonly<{
19
+ formDefinitionVersionId?: string | null;
20
+ usagePoint: ExpressionUsagePoint;
21
+ }>, options?: GraphQlRequestOptions) => Promise<ExpressionCatalogRecord>;
22
+ }
23
+ export interface ExpressionFieldProps {
24
+ readonly api?: ExpressionFieldApi;
25
+ /** Lint delay after the last keystroke. */
26
+ readonly debounceMs?: number;
27
+ readonly dialect: WorkflowExpressionDialect;
28
+ readonly disabled?: boolean;
29
+ /** FLOW_CONDITION: the type of the node the edge leaves. */
30
+ readonly edgeSourceNodeType?: string | null;
31
+ /** Offer a sample-data trial run (EVALUATE) under the field. */
32
+ readonly evaluable?: boolean;
33
+ readonly formDefinitionVersionId?: string | null;
34
+ readonly hintText?: string;
35
+ readonly label: string;
36
+ readonly name: string;
37
+ readonly onChange: (value: string) => void;
38
+ /** Every change of the backend check, so a host can block applying. */
39
+ readonly onLintChange?: (lint: ExpressionFieldLint) => void;
40
+ readonly required?: boolean;
41
+ readonly rows?: number;
42
+ /** SERVICE_FORM_FIELD_VALUE: the field the value is written to. */
43
+ readonly targetFieldKey?: string | null;
44
+ readonly usagePoint: ExpressionUsagePoint;
45
+ readonly value: string;
46
+ }
47
+ interface CatalogOption {
48
+ readonly id: string;
49
+ readonly name: string;
50
+ }
51
+ /** Catalog entries as insertable snippets: field paths, then `name(`. */
52
+ export declare function readExpressionCatalogOptions(catalog: ExpressionCatalogRecord | null): readonly CatalogOption[];
53
+ export interface ExpressionCatalogFunctionNote {
54
+ readonly id: string;
55
+ readonly text: string;
56
+ }
57
+ /**
58
+ * What each catalog function does, as plain lines under the picker. The
59
+ * picker's options carry only a name (Mezzanine `DropdownOption` has no
60
+ * secondary text), so a function's `description` was never shown. Functions
61
+ * without one are left out; the text is rendered as text, never as HTML.
62
+ */
63
+ export declare function readExpressionCatalogFunctionNotes(catalog: ExpressionCatalogRecord | null): readonly ExpressionCatalogFunctionNote[];
64
+ /** Appends a snippet, separated by a space unless the text already ends in one. */
65
+ export declare function appendExpressionSnippet(value: string, snippet: string): string;
66
+ /** The status badge copy; the issues themselves are listed underneath. */
67
+ export declare function readExpressionFieldStatusText(status: ExpressionFieldStatus): string | null;
68
+ /** The parsed trial-run sample, or why it cannot be one. */
69
+ export declare function readExpressionSample(json: string): Readonly<Record<string, unknown>> | string;
70
+ /** One trial-run outcome as plain text (rendered as text, never as HTML). */
71
+ export declare function readExpressionEvaluationText(evaluation: ExpressionEvaluationRecord): string;
72
+ /**
73
+ * A CEL expression input (Phase 23 P4, ADR 22 §3.8): Mezzanine Textarea plus
74
+ * a catalog picker, with the backend's lint findings listed underneath. The
75
+ * browser only sends text; parsing, linting and the optional trial run all
76
+ * happen on the backend (`previewExpression`, designer-only).
77
+ */
78
+ export declare function ExpressionField({ api, debounceMs, dialect, disabled, edgeSourceNodeType, evaluable, formDefinitionVersionId, hintText, label, name, onChange, onLintChange, required, rows, targetFieldKey, usagePoint, value, }: ExpressionFieldProps): ReactElement;
79
+ export {};
@@ -0,0 +1,79 @@
1
+ import { ReactElement } from 'react';
2
+ import { ExpressionUsagePoint } from '@rytass/bpm-core-shared';
3
+ import { WorkflowExpressionDialect } from '@rytass/bpm-core-shared/workflow';
4
+ import { GraphQlRequestOptions } from '@rytass/bpm-core-client';
5
+ import { ExpressionCatalogRecord, ExpressionEvaluationRecord, ExpressionIssueRecord, ExpressionPreviewRecord, PreviewExpressionInput } from '@rytass/bpm-core-client/template';
6
+ /**
7
+ * Where the backend check of one expression stands. `UNAVAILABLE`: the check
8
+ * itself failed (network, 403); the field cannot vouch for the expression.
9
+ */
10
+ export type ExpressionFieldStatus = 'CHECKING' | 'EMPTY' | 'INVALID' | 'UNAVAILABLE' | 'VALID';
11
+ export interface ExpressionFieldLint {
12
+ readonly issues: readonly ExpressionIssueRecord[];
13
+ readonly status: ExpressionFieldStatus;
14
+ }
15
+ /** The backend calls the field makes; injectable for tests and Storybook. */
16
+ export interface ExpressionFieldApi {
17
+ readonly preview: (input: PreviewExpressionInput, options?: GraphQlRequestOptions) => Promise<ExpressionPreviewRecord>;
18
+ readonly readCatalog: (input: Readonly<{
19
+ formDefinitionVersionId?: string | null;
20
+ usagePoint: ExpressionUsagePoint;
21
+ }>, options?: GraphQlRequestOptions) => Promise<ExpressionCatalogRecord>;
22
+ }
23
+ export interface ExpressionFieldProps {
24
+ readonly api?: ExpressionFieldApi;
25
+ /** Lint delay after the last keystroke. */
26
+ readonly debounceMs?: number;
27
+ readonly dialect: WorkflowExpressionDialect;
28
+ readonly disabled?: boolean;
29
+ /** FLOW_CONDITION: the type of the node the edge leaves. */
30
+ readonly edgeSourceNodeType?: string | null;
31
+ /** Offer a sample-data trial run (EVALUATE) under the field. */
32
+ readonly evaluable?: boolean;
33
+ readonly formDefinitionVersionId?: string | null;
34
+ readonly hintText?: string;
35
+ readonly label: string;
36
+ readonly name: string;
37
+ readonly onChange: (value: string) => void;
38
+ /** Every change of the backend check, so a host can block applying. */
39
+ readonly onLintChange?: (lint: ExpressionFieldLint) => void;
40
+ readonly required?: boolean;
41
+ readonly rows?: number;
42
+ /** SERVICE_FORM_FIELD_VALUE: the field the value is written to. */
43
+ readonly targetFieldKey?: string | null;
44
+ readonly usagePoint: ExpressionUsagePoint;
45
+ readonly value: string;
46
+ }
47
+ interface CatalogOption {
48
+ readonly id: string;
49
+ readonly name: string;
50
+ }
51
+ /** Catalog entries as insertable snippets: field paths, then `name(`. */
52
+ export declare function readExpressionCatalogOptions(catalog: ExpressionCatalogRecord | null): readonly CatalogOption[];
53
+ export interface ExpressionCatalogFunctionNote {
54
+ readonly id: string;
55
+ readonly text: string;
56
+ }
57
+ /**
58
+ * What each catalog function does, as plain lines under the picker. The
59
+ * picker's options carry only a name (Mezzanine `DropdownOption` has no
60
+ * secondary text), so a function's `description` was never shown. Functions
61
+ * without one are left out; the text is rendered as text, never as HTML.
62
+ */
63
+ export declare function readExpressionCatalogFunctionNotes(catalog: ExpressionCatalogRecord | null): readonly ExpressionCatalogFunctionNote[];
64
+ /** Appends a snippet, separated by a space unless the text already ends in one. */
65
+ export declare function appendExpressionSnippet(value: string, snippet: string): string;
66
+ /** The status badge copy; the issues themselves are listed underneath. */
67
+ export declare function readExpressionFieldStatusText(status: ExpressionFieldStatus): string | null;
68
+ /** The parsed trial-run sample, or why it cannot be one. */
69
+ export declare function readExpressionSample(json: string): Readonly<Record<string, unknown>> | string;
70
+ /** One trial-run outcome as plain text (rendered as text, never as HTML). */
71
+ export declare function readExpressionEvaluationText(evaluation: ExpressionEvaluationRecord): string;
72
+ /**
73
+ * A CEL expression input (Phase 23 P4, ADR 22 §3.8): Mezzanine Textarea plus
74
+ * a catalog picker, with the backend's lint findings listed underneath. The
75
+ * browser only sends text; parsing, linting and the optional trial run all
76
+ * happen on the backend (`previewExpression`, designer-only).
77
+ */
78
+ export declare function ExpressionField({ api, debounceMs, dialect, disabled, edgeSourceNodeType, evaluable, formDefinitionVersionId, hintText, label, name, onChange, onLintChange, required, rows, targetFieldKey, usagePoint, value, }: ExpressionFieldProps): ReactElement;
79
+ export {};
@@ -0,0 +1,22 @@
1
+ import { WorkflowExpressionsDraft, WorkflowExpressionsRecord } from '@rytass/bpm-core-client/template';
2
+ import { GraphQlRequestOptions } from '@rytass/bpm-core-client';
3
+ export interface WorkflowExpressionReferences {
4
+ readonly analysis: WorkflowExpressionsRecord | null;
5
+ /** Field key → labels of the expressions reading it. */
6
+ readonly references: ReadonlyMap<string, readonly string[]>;
7
+ /**
8
+ * The references of the draft as it is now. Answers from the last analysis
9
+ * when it was made for this very draft, otherwise asks the backend at once.
10
+ * Resolves to `null` when the backend cannot answer, so a caller guarding a
11
+ * destructive edit can refuse it instead of letting it through.
12
+ */
13
+ readonly resolveCurrentReferences: () => Promise<ReadonlyMap<string, readonly string[]> | null>;
14
+ }
15
+ /**
16
+ * The backend's reading of the draft's expressions (Phase 23 P4), refreshed a
17
+ * moment after the draft stops changing. Field references come from the
18
+ * backend's AST, never from parsing CEL in the browser. A failed analysis
19
+ * leaves the last answer in place for display; `resolveCurrentReferences`
20
+ * never answers from a stale or missing analysis.
21
+ */
22
+ export declare function useWorkflowExpressionReferences(draft: WorkflowExpressionsDraft, enabled: boolean, analyze?: (draft: WorkflowExpressionsDraft, options?: GraphQlRequestOptions) => Promise<WorkflowExpressionsRecord>, debounceMs?: number): WorkflowExpressionReferences;
@@ -0,0 +1,22 @@
1
+ import { WorkflowExpressionsDraft, WorkflowExpressionsRecord } from '@rytass/bpm-core-client/template';
2
+ import { GraphQlRequestOptions } from '@rytass/bpm-core-client';
3
+ export interface WorkflowExpressionReferences {
4
+ readonly analysis: WorkflowExpressionsRecord | null;
5
+ /** Field key → labels of the expressions reading it. */
6
+ readonly references: ReadonlyMap<string, readonly string[]>;
7
+ /**
8
+ * The references of the draft as it is now. Answers from the last analysis
9
+ * when it was made for this very draft, otherwise asks the backend at once.
10
+ * Resolves to `null` when the backend cannot answer, so a caller guarding a
11
+ * destructive edit can refuse it instead of letting it through.
12
+ */
13
+ readonly resolveCurrentReferences: () => Promise<ReadonlyMap<string, readonly string[]> | null>;
14
+ }
15
+ /**
16
+ * The backend's reading of the draft's expressions (Phase 23 P4), refreshed a
17
+ * moment after the draft stops changing. Field references come from the
18
+ * backend's AST, never from parsing CEL in the browser. A failed analysis
19
+ * leaves the last answer in place for display; `resolveCurrentReferences`
20
+ * never answers from a stale or missing analysis.
21
+ */
22
+ export declare function useWorkflowExpressionReferences(draft: WorkflowExpressionsDraft, enabled: boolean, analyze?: (draft: WorkflowExpressionsDraft, options?: GraphQlRequestOptions) => Promise<WorkflowExpressionsRecord>, debounceMs?: number): WorkflowExpressionReferences;
@@ -0,0 +1,58 @@
1
+ import { WorkflowDefinition, WorkflowEdge, WorkflowNode } from '@rytass/bpm-core-shared/workflow';
2
+ /**
3
+ * Pure designer edits for the free-text expressions the command layer has no
4
+ * primitive for (Phase 23 P4): a node's entry condition and an edge's
5
+ * hand-written CEL condition. The designer applies them through
6
+ * `controller.replaceState`; the assistant cannot reach them (its toolset
7
+ * offers `set_edge_condition`, the structured builder, instead).
8
+ */
9
+ /** Nodes that may carry `entryCondition`. */
10
+ export declare function hasWorkflowEntryCondition(node: WorkflowNode): node is Extract<WorkflowNode, {
11
+ type: 'serviceTask' | 'userTask';
12
+ }>;
13
+ /** Sets (or, for blank text, removes) a node's entry condition. */
14
+ export declare function setWorkflowNodeEntryCondition(definition: WorkflowDefinition, nodeId: string, condition: string): WorkflowDefinition;
15
+ /**
16
+ * An edge whose condition was written by hand rather than by the structured
17
+ * builder (field + operator + value).
18
+ */
19
+ export declare function isWorkflowEdgeExpressionCondition(edge: WorkflowEdge): boolean;
20
+ /**
21
+ * Writes a hand-written condition on an edge, dropping the builder's
22
+ * field / operator / value and the default flag (a conditional edge is not
23
+ * the else path).
24
+ */
25
+ export declare function setWorkflowEdgeExpressionCondition(definition: WorkflowDefinition, edgeId: string, condition: string): WorkflowDefinition;
26
+ /** The type of the node an edge leaves, for the `lastDecision` check. */
27
+ export declare function readWorkflowEdgeSourceNodeType(definition: WorkflowDefinition, edgeId: string): string | null;
28
+ /**
29
+ * Fields a form edit would rename or delete while expressions still read
30
+ * them (docs/24 §1): keys present before the edit, missing after it, and
31
+ * referenced. Each comes with the labels of the expressions reading it.
32
+ */
33
+ export declare function readRemovedExpressionFields(beforeFieldKeys: readonly string[], afterFieldKeys: readonly string[], references: ReadonlyMap<string, readonly string[]>): readonly {
34
+ readonly fieldKey: string;
35
+ readonly labels: readonly string[];
36
+ }[];
37
+ export type FormEditExpressionCheck = {
38
+ readonly kind: 'allowed';
39
+ } | {
40
+ readonly kind: 'blocked';
41
+ readonly fields: readonly {
42
+ readonly fieldKey: string;
43
+ readonly labels: readonly string[];
44
+ }[];
45
+ } | {
46
+ readonly kind: 'unverified';
47
+ readonly fieldKeys: readonly string[];
48
+ };
49
+ /**
50
+ * Whether a form edit may be applied (docs/24 §1: renaming or deleting a
51
+ * field an expression reads is refused). An edit that removes no field needs
52
+ * no answer from the backend. One that does is checked against the references
53
+ * of the draft as it is now; when those cannot be had (analysis not run yet,
54
+ * request failed, 403) the edit is refused as `unverified` rather than let
55
+ * through — cel-legacy's publish lint does not check field existence, so this
56
+ * is the only guard such a template has.
57
+ */
58
+ export declare function checkFormEditExpressionFields(beforeFieldKeys: readonly string[], afterFieldKeys: readonly string[], resolveReferences: () => Promise<ReadonlyMap<string, readonly string[]> | null>): Promise<FormEditExpressionCheck>;