@rytass/bpm-core-react 0.17.3 → 0.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ "use client";const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./router-adapter--gYs13E8.cjs"),n=require("./language-provider-Bdnx3Gxl.cjs"),r=require("./routes-config-C1j_vFKo.cjs"),i=require("./FormRendererView-DRFi_IH7.cjs"),a=require("./FormBuilderView-aBcA-_tt.cjs"),o=require("./designer-CbOCuXHH.cjs");let s=require("react"),c=require("@mezzanine-ui/react"),l=require("react/jsx-runtime"),u=require("@mezzanine-ui/core/form"),d=require("@mezzanine-ui/react/ContentHeader");d=e.t(d,1);let f=require("@rytass/bpm-core-client/template");var p={id:`UNCATEGORIZED`,name:`未分類`},m=100;function h({categoryId:e,formSchema:t,formUiSchema:n,name:r,onCategoryIdChange:i,onFormChange:o,onNameChange:d}){let[h,_]=(0,s.useState)([]);(0,s.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await(0,f.listApprovalTemplateCategoriesPage)({page:1,pageSize:m,searchText:``,status:`ACTIVE`});e&&_(t.categories)}catch{e&&_([])}})(),()=>{e=!1}},[]);let v=[p,...h.map(e=>({id:e.id,name:e.name}))],y=v.find(t=>t.id===e)??p;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:g,children:[(0,l.jsx)(c.FormField,{label:`名稱`,layout:u.FormFieldLayout.VERTICAL,name:`composeName`,children:(0,l.jsx)(c.Input,{fullWidth:!0,onChange:e=>d(e.target.value),placeholder:`例如:請款簽核`,value:r})}),(0,l.jsx)(c.FormField,{label:`分類(選填)`,layout:u.FormFieldLayout.VERTICAL,name:`composeCategory`,children:(0,l.jsx)(c.Select,{clearable:!1,fullWidth:!0,onChange:e=>i(e&&e.id!==p.id?e.id:null),options:v,placeholder:`未分類`,value:y})})]}),(0,l.jsx)(c.Typography,{color:`text-neutral`,variant:`caption`,children:`先設計表單欄位,下一步的流程條件分流即可直接引用這些欄位。`}),(0,l.jsx)(a.t,{onChange:o,value:{schema:t,uiSchema:n}})]})}var g={display:`grid`,gap:16,gridTemplateColumns:`repeat(auto-fit, minmax(220px, 1fr))`};function _({formSchema:e,formUiSchema:t,initiatorPolicyCel:n,name:r,publishError:a,workflowDefinition:o}){let s=o?.nodes??[],u=o?.edges??[],d=e.fields.length,f=new Map(s.map(e=>[e.id,e.data.label])),p=s.map(e=>({detail:x(e)??`—`,key:e.id,label:e.data.label,typeLabel:b(e)})),m=u.filter(e=>!!e.data.condition).map(e=>({condition:e.data.condition??``,key:e.id,source:f.get(e.source)??e.source,target:f.get(e.target)??e.target}));return(0,l.jsxs)(`div`,{style:S,children:[(0,l.jsx)(c.Typography,{component:`h2`,style:C,variant:`h2`,children:r||`(未命名)`}),(0,l.jsxs)(`div`,{style:S,children:[(0,l.jsx)(c.Typography,{variant:`h3`,children:`表單預覽`}),d>0?(0,l.jsx)(i.t,{dataSourceContext:{kind:`preview`},readonly:!0,schema:e,uiSchema:t}):(0,l.jsx)(c.Empty,{title:`尚未設計表單欄位`})]}),(0,l.jsxs)(`div`,{style:S,children:[(0,l.jsx)(c.Typography,{variant:`h3`,children:`流程概覽`}),s.length>0?(0,l.jsx)(c.Table,{columns:v,dataSource:p,fullWidth:!0}):(0,l.jsx)(c.Empty,{title:`尚未設計流程節點`}),m.length>0?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.Typography,{color:`text-neutral`,variant:`caption`,children:`條件分流`}),(0,l.jsx)(c.Table,{columns:y,dataSource:m,fullWidth:!0})]}):null,n?(0,l.jsxs)(c.Typography,{color:`text-neutral`,variant:`caption`,children:[`發起權限:`,n]}):null]}),a?(0,l.jsx)(c.Typography,{color:`text-error`,variant:`body`,children:a}):null]})}var v=[{key:`type`,render:e=>(0,l.jsx)(c.Tag,{label:e.typeLabel,size:`sub`,type:`static`}),title:`類型`,width:130},{dataIndex:`label`,key:`label`,title:`節點`},{dataIndex:`detail`,key:`detail`,title:`簽核方式`,width:160}],y=[{dataIndex:`source`,key:`source`,title:`來源`,width:180},{dataIndex:`target`,key:`target`,title:`目標`,width:180},{dataIndex:`condition`,key:`condition`,title:`條件`}];function b(e){switch(e.type){case`startEvent`:return`開始`;case`endEvent`:return e.data.endState===`REJECTED`?`結束(駁回)`:`結束(核准)`;case`userTask`:return`簽核`;case`serviceTask`:return`服務`;case`exclusiveGateway`:return`條件閘道`;case`parallelGateway`:return`平行閘道`;default:return`節點`}}function x(e){if(e.type!==`userTask`)return null;switch(e.data.approverResolver.type){case`DIRECT`:return`指定成員`;case`POSITION`:return`指定職位`;case`ORG_UNIT_MEMBER`:return`單位成員`;case`ORG_UNIT_POSITION`:return`單位職位`;case`ORG_MANAGER`:return`主管`;case`ORG_MANAGER_CHAIN`:return`主管鏈`;case`ORG_UNIT_MANAGER`:return`單位主管`;case`DYNAMIC_FORM`:return`依表單欄位指定`;case`EXPRESSION`:return`運算式`;default:return`簽核人`}}var S={display:`grid`,gap:12},C={marginTop:`var(--mzn-spacing-padding-vertical-spacious)`};function w({aiAssistantAvailable:e=!1,formSchema:t,initiatorPolicyCel:n,onInitiatorPolicyChange:r,onWorkflowChange:i,showAiAssistant:a=!1,workflowDefinition:s}){return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.Typography,{color:`text-neutral`,variant:`caption`,children:`設計簽核節點與條件分流;條件可直接引用上一步設計的表單欄位。`}),(0,l.jsx)(o.t,{aiAssistantAvailable:e,embedded:!0,formSchemaOverride:t,initialInitiatorPolicyCel:n,initialWorkflowDefinition:s??void 0,onInitiatorPolicyChange:r,onWorkflowChange:i,showAiAssistant:a})]})}var T={fields:[],schemaVersion:1},E={layout:[],schemaVersion:1};function D(){let e=n.i(),[t,r]=(0,s.useState)(0),[i,a]=(0,s.useState)(``),[c,l]=(0,s.useState)(null),[u,d]=(0,s.useState)(T),[p,m]=(0,s.useState)(E),[h,g]=(0,s.useState)(null),[_,v]=(0,s.useState)(null),[y,b]=(0,s.useState)(`idle`),[x,S]=(0,s.useState)(null),C=i.trim().length>0&&u.fields.length>0,w=(0,s.useCallback)(e=>{r(e)},[]),D=(0,s.useCallback)(()=>{r(e=>e<2?e+1:e)},[]),k=(0,s.useCallback)(()=>{r(e=>e>0?e-1:e)},[]),A=(0,s.useCallback)(e=>{d(e.schema),m(e.uiSchema)},[]),j=(0,s.useCallback)(e=>{g(e)},[]),M=(0,s.useCallback)(e=>{v(e)},[]);return{canLeaveBasics:C,categoryId:c,currentStep:t,formSchema:u,formUiSchema:p,goBack:k,goNext:D,goToStep:w,initiatorPolicyCel:_,name:i,publish:(0,s.useCallback)(async()=>{b(`submitting`),S(null);let t=h??O;try{let e=await(0,f.composeApprovalTemplateWithForm)({category:null,categoryId:c,formDefinitionId:null,formDescription:null,formName:i,initiatorPolicyCel:_,notificationConfig:null,publish:!0,schema:u,slaDefaults:null,templateDescription:null,templateId:null,templateName:i,uiSchema:p,workflowDefinition:t});return b(`success`),e}catch(n){return S(o.n(n,e,t)),b(`error`),null}},[c,u,p,_,e,i,h]),publishError:x,publishPhase:y,setCategoryId:l,setFormValue:A,setInitiatorPolicyCel:M,setName:a,setWorkflowDefinition:j,workflowDefinition:h}}var O={edges:[],meta:{schemaVersion:1},nodes:[{data:{label:`開始`},id:`start`,position:{x:80,y:160},type:`startEvent`},{data:{endState:`APPROVED`,label:`完成`,triggerMode:`AND`},id:`end`,position:{x:560,y:160},type:`endEvent`}]};function k({aiAssistantAvailable:e=!1,showAiAssistant:n=!1}={}){let i=t.r(),a=r.r(),o=D(),s=o.publishPhase===`submitting`;async function u(){let e=await o.publish();e&&i.push(a.templateDesigner(e.templateId))}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.PageHeader,{children:(0,l.jsx)(d.default,{description:`一次完成表單與流程設計,發佈後即可直接發起。`,title:`建立模板(表單 + 流程)`,children:(0,l.jsx)(c.Button,{disabled:s,onClick:()=>i.push(a.templates()),variant:`base-secondary`,children:`返回模板列表`})})}),(0,l.jsx)(c.SectionGroup,{children:(0,l.jsxs)(c.Section,{children:[(0,l.jsxs)(c.Stepper,{currentStep:o.currentStep,children:[(0,l.jsx)(c.Step,{description:`設計欄位與版面`,title:`表單設計`}),(0,l.jsx)(c.Step,{description:`設計簽核節點與條件`,title:`流程設計`}),(0,l.jsx)(c.Step,{description:`確認後發佈`,title:`檢視並發佈`})]}),o.currentStep===0?(0,l.jsx)(h,{categoryId:o.categoryId,formSchema:o.formSchema,formUiSchema:o.formUiSchema,name:o.name,onCategoryIdChange:o.setCategoryId,onFormChange:o.setFormValue,onNameChange:o.setName}):null,o.currentStep===1?(0,l.jsx)(w,{aiAssistantAvailable:e,formSchema:o.formSchema,initiatorPolicyCel:o.initiatorPolicyCel,onInitiatorPolicyChange:o.setInitiatorPolicyCel,onWorkflowChange:o.setWorkflowDefinition,showAiAssistant:n,workflowDefinition:o.workflowDefinition}):null,o.currentStep===2?(0,l.jsx)(_,{formSchema:o.formSchema,formUiSchema:o.formUiSchema,initiatorPolicyCel:o.initiatorPolicyCel,name:o.name,publishError:o.publishError,workflowDefinition:o.workflowDefinition}):null,(0,l.jsxs)(`div`,{style:A,children:[o.currentStep===0&&!o.canLeaveBasics?(0,l.jsx)(c.Typography,{color:`text-neutral`,variant:`caption`,children:`請填寫模板名稱、表單名稱,並至少新增一個表單欄位。`}):(0,l.jsx)(`span`,{}),(0,l.jsxs)(`div`,{style:j,children:[(0,l.jsx)(c.Button,{disabled:o.currentStep===0||s,onClick:o.goBack,variant:`base-secondary`,children:`上一步`}),o.currentStep<2?(0,l.jsx)(c.Button,{disabled:o.currentStep===0&&!o.canLeaveBasics,onClick:o.goNext,variant:`base-primary`,children:`下一步`}):(0,l.jsx)(c.Button,{disabled:s,loading:s,onClick:()=>{u()},variant:`base-primary`,children:`發佈`})]})]})]})})]})}var A={alignItems:`center`,display:`flex`,marginTop:`var(--mzn-spacing-padding-vertical-spacious)`,justifyContent:`space-between`,gap:16},j={display:`flex`,gap:8};Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return k}});
2
+ //# sourceMappingURL=compose-fdwBNiyg.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose-fdwBNiyg.cjs","names":["useState","listApprovalTemplateCategoriesPage","_Fragment","FormField","FormFieldLayout","Input","Select","Typography","FormBuilderView","Typography","FormRenderer","Empty","Table","_Fragment","Tag","_Fragment","Typography","TemplateDesignerView","useBPMLanguage","useState","useCallback","composeApprovalTemplateWithForm","readTemplateErrorMessage","useRouterAdapter","useBPMRoutes","_Fragment","PageHeader","ContentHeader","Button","SectionGroup","Section","Stepper","Step","Typography","require_rolldown_runtime","require_router_adapter","require_language_provider","require_routes_config","require_FormRendererView","require_FormBuilderView","require_designer","react","_mezzanine_ui_react","react_jsx_runtime","_mezzanine_ui_core_form","_mezzanine_ui_react_ContentHeader","_rytass_bpm_core_client_template","UNCATEGORIZED_OPTION","CATEGORY_PAGE_SIZE","ComposeFormStep","categoryOptions","setCategoryOptions","active","result","selectOptions","category","selectedOption","option","categoryId","BASICS_GRID_STYLE","onNameChange","event","name","onCategoryIdChange","onFormChange","formSchema","formUiSchema","ComposeReviewStep","nodes","workflowDefinition","edges","fieldCount","nodeLabelById","node","nodeRows","readNodeDetail","readNodeTypeLabel","branchRows","edge","STACK_STYLE","TITLE_STYLE","NODE_COLUMNS","BRANCH_COLUMNS","initiatorPolicyCel","publishError","record","ComposeWorkflowStep","EMPTY_COMPOSE_FORM_SCHEMA","EMPTY_COMPOSE_FORM_UI_SCHEMA","useTemplateComposeWizard","language","currentStep","setCurrentStep","setName","setCategoryId","setFormSchema","setFormUiSchema","setWorkflowDefinitionState","setInitiatorPolicyCelState","publishPhase","setPublishPhase","setPublishError","canLeaveBasics","goToStep","step","goNext","goBack","setFormValue","next","setWorkflowDefinition","definition","setInitiatorPolicyCel","cel","submittedDefinition","EMPTY_WORKFLOW_DEFINITION","requestError","TemplateComposeWizardView","router","routes","wizard","submitting","handlePublish","FOOTER_STYLE","FOOTER_ACTIONS_STYLE"],"sources":["../../src/views/templates/compose/steps/ComposeFormStep.tsx","../../src/views/templates/compose/steps/ComposeReviewStep.tsx","../../src/views/templates/compose/steps/ComposeWorkflowStep.tsx","../../src/views/templates/compose/use-template-compose-wizard.ts","../../src/views/templates/compose/TemplateComposeWizardView.tsx"],"sourcesContent":["'use client';\n\nimport type { ChangeEvent, ReactElement } from 'react';\nimport { useEffect, useState } from 'react';\nimport { FormField, Input, Select, Typography } from '@mezzanine-ui/react';\nimport { FormFieldLayout } from '@mezzanine-ui/core/form';\nimport type { SelectValue } from '@mezzanine-ui/react/Select';\nimport type {\n FormDefinitionSchema,\n FormUiSchema,\n} from '@rytass/bpm-core-shared/form';\nimport {\n ApprovalTemplateCategoryRecord,\n listApprovalTemplateCategoriesPage,\n} from '@rytass/bpm-core-client/template';\nimport { FormBuilderView } from '../../../forms/builder';\n\nconst UNCATEGORIZED_OPTION: SelectValue = {\n id: 'UNCATEGORIZED',\n name: '未分類',\n};\n\nconst CATEGORY_PAGE_SIZE = 100;\n\nexport interface ComposeFormStepProps {\n readonly name: string;\n readonly categoryId: string | null;\n readonly formSchema: FormDefinitionSchema;\n readonly formUiSchema: FormUiSchema;\n readonly onNameChange: (value: string) => void;\n readonly onCategoryIdChange: (value: string | null) => void;\n readonly onFormChange: (next: {\n readonly schema: FormDefinitionSchema;\n readonly uiSchema: FormUiSchema;\n }) => void;\n}\n\nexport function ComposeFormStep({\n categoryId,\n formSchema,\n formUiSchema,\n name,\n onCategoryIdChange,\n onFormChange,\n onNameChange,\n}: ComposeFormStepProps): ReactElement {\n const [categoryOptions, setCategoryOptions] = useState<\n readonly ApprovalTemplateCategoryRecord[]\n >([]);\n\n useEffect((): (() => void) => {\n let active = true;\n\n void (async (): Promise<void> => {\n try {\n const result = await listApprovalTemplateCategoriesPage({\n page: 1,\n pageSize: CATEGORY_PAGE_SIZE,\n searchText: '',\n status: 'ACTIVE',\n });\n\n if (active) {\n setCategoryOptions(result.categories);\n }\n } catch {\n if (active) {\n setCategoryOptions([]);\n }\n }\n })();\n\n return (): void => {\n active = false;\n };\n }, []);\n\n const selectOptions: SelectValue[] = [\n UNCATEGORIZED_OPTION,\n ...categoryOptions.map((category) => ({\n id: category.id,\n name: category.name,\n })),\n ];\n const selectedOption =\n selectOptions.find((option) => option.id === categoryId) ??\n UNCATEGORIZED_OPTION;\n\n return (\n <>\n <div style={BASICS_GRID_STYLE}>\n <FormField\n label=\"名稱\"\n layout={FormFieldLayout.VERTICAL}\n name=\"composeName\"\n >\n <Input\n fullWidth\n onChange={(event: ChangeEvent<HTMLInputElement>): void =>\n onNameChange(event.target.value)\n }\n placeholder=\"例如:請款簽核\"\n value={name}\n />\n </FormField>\n <FormField\n label=\"分類(選填)\"\n layout={FormFieldLayout.VERTICAL}\n name=\"composeCategory\"\n >\n <Select\n clearable={false}\n fullWidth\n onChange={(option): void =>\n onCategoryIdChange(\n option && option.id !== UNCATEGORIZED_OPTION.id\n ? option.id\n : null,\n )\n }\n options={selectOptions}\n placeholder=\"未分類\"\n value={selectedOption}\n />\n </FormField>\n </div>\n <Typography color=\"text-neutral\" variant=\"caption\">\n 先設計表單欄位,下一步的流程條件分流即可直接引用這些欄位。\n </Typography>\n <FormBuilderView\n onChange={onFormChange}\n value={{ schema: formSchema, uiSchema: formUiSchema }}\n />\n </>\n );\n}\n\nconst BASICS_GRID_STYLE = {\n display: 'grid',\n gap: 16,\n gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',\n} as const;\n","'use client';\n\nimport type { CSSProperties, ReactElement } from 'react';\nimport { Empty, Table, Tag, Typography } from '@mezzanine-ui/react';\nimport type { TableColumn } from '@mezzanine-ui/core/table';\nimport type {\n FormDefinitionSchema,\n FormUiSchema,\n} from '@rytass/bpm-core-shared/form';\nimport type {\n WorkflowDefinition,\n WorkflowNode,\n} from '@rytass/bpm-core-shared/workflow';\nimport { FormRenderer } from '../../../forms/renderer/FormRendererView';\n\ntype FlowNodeRow = Readonly<\n Record<string, unknown> & {\n detail: string;\n key: string;\n label: string;\n typeLabel: string;\n }\n>;\n\ntype BranchRow = Readonly<\n Record<string, unknown> & {\n condition: string;\n key: string;\n source: string;\n target: string;\n }\n>;\n\nexport interface ComposeReviewStepProps {\n readonly name: string;\n readonly formSchema: FormDefinitionSchema;\n readonly formUiSchema: FormUiSchema;\n readonly workflowDefinition: WorkflowDefinition | null;\n readonly initiatorPolicyCel: string | null;\n readonly publishError: string | null;\n}\n\nexport function ComposeReviewStep({\n formSchema,\n formUiSchema,\n initiatorPolicyCel,\n name,\n publishError,\n workflowDefinition,\n}: ComposeReviewStepProps): ReactElement {\n const nodes = workflowDefinition?.nodes ?? [];\n const edges = workflowDefinition?.edges ?? [];\n const fieldCount = formSchema.fields.length;\n const nodeLabelById = new Map(\n nodes.map((node) => [node.id, node.data.label] as const),\n );\n const nodeRows: FlowNodeRow[] = nodes.map((node) => ({\n detail: readNodeDetail(node) ?? '—',\n key: node.id,\n label: node.data.label,\n typeLabel: readNodeTypeLabel(node),\n }));\n const branchRows: BranchRow[] = edges\n .filter((edge) => Boolean(edge.data.condition))\n .map((edge) => ({\n condition: edge.data.condition ?? '',\n key: edge.id,\n source: nodeLabelById.get(edge.source) ?? edge.source,\n target: nodeLabelById.get(edge.target) ?? edge.target,\n }));\n\n return (\n <div style={STACK_STYLE}>\n <Typography component=\"h2\" style={TITLE_STYLE} variant=\"h2\">\n {name || '(未命名)'}\n </Typography>\n\n <div style={STACK_STYLE}>\n <Typography variant=\"h3\">表單預覽</Typography>\n {fieldCount > 0 ? (\n <FormRenderer\n dataSourceContext={{ kind: 'preview' }}\n readonly\n schema={formSchema}\n uiSchema={formUiSchema}\n />\n ) : (\n <Empty title=\"尚未設計表單欄位\" />\n )}\n </div>\n\n <div style={STACK_STYLE}>\n <Typography variant=\"h3\">流程概覽</Typography>\n {nodes.length > 0 ? (\n <Table columns={NODE_COLUMNS} dataSource={nodeRows} fullWidth />\n ) : (\n <Empty title=\"尚未設計流程節點\" />\n )}\n {branchRows.length > 0 ? (\n <>\n <Typography color=\"text-neutral\" variant=\"caption\">\n 條件分流\n </Typography>\n <Table columns={BRANCH_COLUMNS} dataSource={branchRows} fullWidth />\n </>\n ) : null}\n {initiatorPolicyCel ? (\n <Typography color=\"text-neutral\" variant=\"caption\">\n 發起權限:{initiatorPolicyCel}\n </Typography>\n ) : null}\n </div>\n\n {publishError ? (\n <Typography color=\"text-error\" variant=\"body\">\n {publishError}\n </Typography>\n ) : null}\n </div>\n );\n}\n\nconst NODE_COLUMNS: TableColumn<FlowNodeRow>[] = [\n {\n key: 'type',\n render: (record: FlowNodeRow): ReactElement => (\n <Tag label={record.typeLabel} size=\"sub\" type=\"static\" />\n ),\n title: '類型',\n width: 130,\n },\n { dataIndex: 'label', key: 'label', title: '節點' },\n { dataIndex: 'detail', key: 'detail', title: '簽核方式', width: 160 },\n];\n\nconst BRANCH_COLUMNS: TableColumn<BranchRow>[] = [\n { dataIndex: 'source', key: 'source', title: '來源', width: 180 },\n { dataIndex: 'target', key: 'target', title: '目標', width: 180 },\n { dataIndex: 'condition', key: 'condition', title: '條件' },\n];\n\nfunction readNodeTypeLabel(node: WorkflowNode): string {\n switch (node.type) {\n case 'startEvent':\n return '開始';\n case 'endEvent':\n return node.data.endState === 'REJECTED' ? '結束(駁回)' : '結束(核准)';\n case 'userTask':\n return '簽核';\n case 'serviceTask':\n return '服務';\n case 'exclusiveGateway':\n return '條件閘道';\n case 'parallelGateway':\n return '平行閘道';\n default:\n return '節點';\n }\n}\n\nfunction readNodeDetail(node: WorkflowNode): string | null {\n if (node.type !== 'userTask') {\n return null;\n }\n\n switch (node.data.approverResolver.type) {\n case 'DIRECT':\n return '指定成員';\n case 'POSITION':\n return '指定職位';\n case 'ORG_UNIT_MEMBER':\n return '單位成員';\n case 'ORG_UNIT_POSITION':\n return '單位職位';\n case 'ORG_MANAGER':\n return '主管';\n case 'ORG_MANAGER_CHAIN':\n return '主管鏈';\n case 'ORG_UNIT_MANAGER':\n return '單位主管';\n case 'DYNAMIC_FORM':\n return '依表單欄位指定';\n case 'EXPRESSION':\n return '運算式';\n default:\n return '簽核人';\n }\n}\n\nconst STACK_STYLE: CSSProperties = {\n display: 'grid',\n gap: 12,\n};\n\n// Match the breathing room between the stepper and the PageHeader, which is the\n// Section's top padding token.\nconst TITLE_STYLE: CSSProperties = {\n marginTop: 'var(--mzn-spacing-padding-vertical-spacious)',\n};\n","'use client';\n\nimport type { ReactElement } from 'react';\nimport { Typography } from '@mezzanine-ui/react';\nimport type { FormDefinitionSchema } from '@rytass/bpm-core-shared/form';\nimport type { WorkflowDefinition } from '@rytass/bpm-core-shared/workflow';\nimport { TemplateDesignerView } from '../../designer';\n\nexport interface ComposeWorkflowStepProps {\n readonly formSchema: FormDefinitionSchema;\n readonly workflowDefinition: WorkflowDefinition | null;\n readonly initiatorPolicyCel: string | null;\n readonly onWorkflowChange: (definition: WorkflowDefinition) => void;\n readonly onInitiatorPolicyChange: (cel: string | null) => void;\n /**\n * Show the AI assistant button inside the embedded designer's side panel.\n * Follows the same opt-in contract as the standalone designer page; default\n * hidden. Wired up the stack from the server page's `BPM_AI_ASSISTANT_ENABLED`.\n */\n readonly showAiAssistant?: boolean;\n /**\n * Whether the LLM backend is configured (host has an API key). When `false`\n * the AI button shows disabled as a placeholder. Default `false`.\n */\n readonly aiAssistantAvailable?: boolean;\n}\n\nexport function ComposeWorkflowStep({\n aiAssistantAvailable = false,\n formSchema,\n initiatorPolicyCel,\n onInitiatorPolicyChange,\n onWorkflowChange,\n showAiAssistant = false,\n workflowDefinition,\n}: ComposeWorkflowStepProps): ReactElement {\n return (\n <>\n <Typography color=\"text-neutral\" variant=\"caption\">\n 設計簽核節點與條件分流;條件可直接引用上一步設計的表單欄位。\n </Typography>\n <TemplateDesignerView\n aiAssistantAvailable={aiAssistantAvailable}\n embedded\n formSchemaOverride={formSchema}\n initialInitiatorPolicyCel={initiatorPolicyCel}\n initialWorkflowDefinition={workflowDefinition ?? undefined}\n onInitiatorPolicyChange={onInitiatorPolicyChange}\n onWorkflowChange={onWorkflowChange}\n showAiAssistant={showAiAssistant}\n />\n </>\n );\n}\n","'use client';\n\nimport { useCallback, useState } from 'react';\nimport type {\n FormDefinitionSchema,\n FormUiSchema,\n} from '@rytass/bpm-core-shared/form';\nimport type { WorkflowDefinition } from '@rytass/bpm-core-shared/workflow';\nimport { useBPMLanguage } from '../../../lib/language-provider';\nimport {\n ComposeApprovalTemplateWithFormResult,\n composeApprovalTemplateWithForm,\n} from '@rytass/bpm-core-client/template';\nimport { readTemplateErrorMessage } from '../template-error-message';\n\nexport type ComposeWizardStep = 0 | 1 | 2;\n\nexport type ComposePublishPhase = 'error' | 'idle' | 'submitting' | 'success';\n\nexport const EMPTY_COMPOSE_FORM_SCHEMA: FormDefinitionSchema = {\n fields: [],\n schemaVersion: 1,\n};\n\nexport const EMPTY_COMPOSE_FORM_UI_SCHEMA: FormUiSchema = {\n layout: [],\n schemaVersion: 1,\n};\n\nexport interface TemplateComposeWizard {\n readonly currentStep: ComposeWizardStep;\n /**\n * Single user-facing name. Persisted to both the template and the form\n * (`templateName` / `formName`) at the `composeApprovalTemplateWithForm`\n * boundary — the DB keeps two columns, the UI keeps one field.\n */\n readonly name: string;\n readonly categoryId: string | null;\n readonly formSchema: FormDefinitionSchema;\n readonly formUiSchema: FormUiSchema;\n readonly workflowDefinition: WorkflowDefinition | null;\n readonly initiatorPolicyCel: string | null;\n readonly publishPhase: ComposePublishPhase;\n readonly publishError: string | null;\n readonly canLeaveBasics: boolean;\n readonly goToStep: (step: ComposeWizardStep) => void;\n readonly goNext: () => void;\n readonly goBack: () => void;\n readonly setName: (value: string) => void;\n readonly setCategoryId: (value: string | null) => void;\n readonly setFormValue: (next: {\n readonly schema: FormDefinitionSchema;\n readonly uiSchema: FormUiSchema;\n }) => void;\n readonly setWorkflowDefinition: (definition: WorkflowDefinition) => void;\n readonly setInitiatorPolicyCel: (cel: string | null) => void;\n readonly publish: () => Promise<ComposeApprovalTemplateWithFormResult | null>;\n}\n\n/**\n * Owns the cross-step state for the unified \"form + flow\" template wizard.\n *\n * Step 0 (表單) edits `formSchema`/`formUiSchema`; that same in-memory schema\n * feeds Step 1 (流程) as the field source for condition branches, so the\n * embedded designer never needs a published form version. Step 2 (檢視發佈)\n * submits everything through the atomic `composeApprovalTemplateWithForm`\n * mutation.\n */\nexport function useTemplateComposeWizard(): TemplateComposeWizard {\n const language = useBPMLanguage();\n const [currentStep, setCurrentStep] = useState<ComposeWizardStep>(0);\n const [name, setName] = useState('');\n const [categoryId, setCategoryId] = useState<string | null>(null);\n const [formSchema, setFormSchema] = useState<FormDefinitionSchema>(\n EMPTY_COMPOSE_FORM_SCHEMA,\n );\n const [formUiSchema, setFormUiSchema] = useState<FormUiSchema>(\n EMPTY_COMPOSE_FORM_UI_SCHEMA,\n );\n const [workflowDefinition, setWorkflowDefinitionState] =\n useState<WorkflowDefinition | null>(null);\n const [initiatorPolicyCel, setInitiatorPolicyCelState] = useState<\n string | null\n >(null);\n const [publishPhase, setPublishPhase] = useState<ComposePublishPhase>('idle');\n const [publishError, setPublishError] = useState<string | null>(null);\n\n const canLeaveBasics = name.trim().length > 0 && formSchema.fields.length > 0;\n\n const goToStep = useCallback((step: ComposeWizardStep): void => {\n setCurrentStep(step);\n }, []);\n\n const goNext = useCallback((): void => {\n setCurrentStep((step) =>\n step < 2 ? ((step + 1) as ComposeWizardStep) : step,\n );\n }, []);\n\n const goBack = useCallback((): void => {\n setCurrentStep((step) =>\n step > 0 ? ((step - 1) as ComposeWizardStep) : step,\n );\n }, []);\n\n const setFormValue = useCallback(\n (next: {\n readonly schema: FormDefinitionSchema;\n readonly uiSchema: FormUiSchema;\n }): void => {\n setFormSchema(next.schema);\n setFormUiSchema(next.uiSchema);\n },\n [],\n );\n\n const setWorkflowDefinition = useCallback(\n (definition: WorkflowDefinition): void => {\n setWorkflowDefinitionState(definition);\n },\n [],\n );\n\n const setInitiatorPolicyCel = useCallback((cel: string | null): void => {\n setInitiatorPolicyCelState(cel);\n }, []);\n\n const publish =\n useCallback(async (): Promise<ComposeApprovalTemplateWithFormResult | null> => {\n setPublishPhase('submitting');\n setPublishError(null);\n\n const submittedDefinition =\n workflowDefinition ?? EMPTY_WORKFLOW_DEFINITION;\n\n try {\n const result = await composeApprovalTemplateWithForm({\n category: null,\n categoryId,\n formDefinitionId: null,\n formDescription: null,\n // One UI name fans out to both persisted columns.\n formName: name,\n initiatorPolicyCel,\n notificationConfig: null,\n publish: true,\n schema: formSchema,\n slaDefaults: null,\n templateDescription: null,\n templateId: null,\n templateName: name,\n uiSchema: formUiSchema,\n workflowDefinition: submittedDefinition,\n });\n\n setPublishPhase('success');\n\n return result;\n } catch (requestError: unknown) {\n setPublishError(\n readTemplateErrorMessage(requestError, language, submittedDefinition),\n );\n setPublishPhase('error');\n\n return null;\n }\n }, [\n categoryId,\n formSchema,\n formUiSchema,\n initiatorPolicyCel,\n language,\n name,\n workflowDefinition,\n ]);\n\n return {\n canLeaveBasics,\n categoryId,\n currentStep,\n formSchema,\n formUiSchema,\n goBack,\n goNext,\n goToStep,\n initiatorPolicyCel,\n name,\n publish,\n publishError,\n publishPhase,\n setCategoryId,\n setFormValue,\n setInitiatorPolicyCel,\n setName,\n setWorkflowDefinition,\n workflowDefinition,\n };\n}\n\nconst EMPTY_WORKFLOW_DEFINITION: WorkflowDefinition = {\n edges: [],\n meta: { schemaVersion: 1 },\n nodes: [\n {\n data: { label: '開始' },\n id: 'start',\n position: { x: 80, y: 160 },\n type: 'startEvent',\n },\n {\n data: { endState: 'APPROVED', label: '完成', triggerMode: 'AND' },\n id: 'end',\n position: { x: 560, y: 160 },\n type: 'endEvent',\n },\n ],\n};\n","'use client';\n\nimport type { ReactElement } from 'react';\nimport {\n Button,\n PageHeader,\n Section,\n SectionGroup,\n Step,\n Stepper,\n Typography,\n} from '@mezzanine-ui/react';\nimport ContentHeader from '@mezzanine-ui/react/ContentHeader';\nimport { useRouterAdapter } from '../../../lib/router-adapter';\nimport { useBPMRoutes } from '../../../lib/routes-config';\nimport { ComposeFormStep } from './steps/ComposeFormStep';\nimport { ComposeReviewStep } from './steps/ComposeReviewStep';\nimport { ComposeWorkflowStep } from './steps/ComposeWorkflowStep';\nimport { useTemplateComposeWizard } from './use-template-compose-wizard';\n\nexport interface TemplateComposeWizardViewProps {\n /**\n * Show the workflow designer AI assistant inside Step 1 (流程設計). Opt-in,\n * default hidden — the server page maps `BPM_AI_ASSISTANT_ENABLED` to it.\n */\n readonly showAiAssistant?: boolean;\n /**\n * Whether the LLM backend is configured (host has an API key). When `false`\n * the AI button shows disabled as a placeholder. Default `false`.\n */\n readonly aiAssistantAvailable?: boolean;\n}\n\n/**\n * Unified \"form + flow\" template creation wizard. Walks the user through\n * Step 0 表單設計 → Step 1 流程設計 → Step 2 檢視並發佈, then commits both\n * sides atomically through `composeApprovalTemplateWithForm`. This is the\n * template entry point; the form builder is intentionally controlled here\n * instead of exposed as a standalone `/forms` page.\n */\nexport function TemplateComposeWizardView({\n aiAssistantAvailable = false,\n showAiAssistant = false,\n}: TemplateComposeWizardViewProps = {}): ReactElement {\n const router = useRouterAdapter();\n const routes = useBPMRoutes();\n const wizard = useTemplateComposeWizard();\n const submitting = wizard.publishPhase === 'submitting';\n\n async function handlePublish(): Promise<void> {\n const result = await wizard.publish();\n\n if (result) {\n router.push(routes.templateDesigner(result.templateId));\n }\n }\n\n return (\n <>\n <PageHeader>\n <ContentHeader\n description=\"一次完成表單與流程設計,發佈後即可直接發起。\"\n title=\"建立模板(表單 + 流程)\"\n >\n <Button\n disabled={submitting}\n onClick={(): void => router.push(routes.templates())}\n variant=\"base-secondary\"\n >\n 返回模板列表\n </Button>\n </ContentHeader>\n </PageHeader>\n\n <SectionGroup>\n <Section>\n <Stepper currentStep={wizard.currentStep}>\n <Step description=\"設計欄位與版面\" title=\"表單設計\" />\n <Step description=\"設計簽核節點與條件\" title=\"流程設計\" />\n <Step description=\"確認後發佈\" title=\"檢視並發佈\" />\n </Stepper>\n\n {wizard.currentStep === 0 ? (\n <ComposeFormStep\n categoryId={wizard.categoryId}\n formSchema={wizard.formSchema}\n formUiSchema={wizard.formUiSchema}\n name={wizard.name}\n onCategoryIdChange={wizard.setCategoryId}\n onFormChange={wizard.setFormValue}\n onNameChange={wizard.setName}\n />\n ) : null}\n\n {wizard.currentStep === 1 ? (\n <ComposeWorkflowStep\n aiAssistantAvailable={aiAssistantAvailable}\n formSchema={wizard.formSchema}\n initiatorPolicyCel={wizard.initiatorPolicyCel}\n onInitiatorPolicyChange={wizard.setInitiatorPolicyCel}\n onWorkflowChange={wizard.setWorkflowDefinition}\n showAiAssistant={showAiAssistant}\n workflowDefinition={wizard.workflowDefinition}\n />\n ) : null}\n\n {wizard.currentStep === 2 ? (\n <ComposeReviewStep\n formSchema={wizard.formSchema}\n formUiSchema={wizard.formUiSchema}\n initiatorPolicyCel={wizard.initiatorPolicyCel}\n name={wizard.name}\n publishError={wizard.publishError}\n workflowDefinition={wizard.workflowDefinition}\n />\n ) : null}\n\n <div style={FOOTER_STYLE}>\n {wizard.currentStep === 0 && !wizard.canLeaveBasics ? (\n <Typography color=\"text-neutral\" variant=\"caption\">\n 請填寫模板名稱、表單名稱,並至少新增一個表單欄位。\n </Typography>\n ) : (\n <span />\n )}\n <div style={FOOTER_ACTIONS_STYLE}>\n <Button\n disabled={wizard.currentStep === 0 || submitting}\n onClick={wizard.goBack}\n variant=\"base-secondary\"\n >\n 上一步\n </Button>\n {wizard.currentStep < 2 ? (\n <Button\n disabled={wizard.currentStep === 0 && !wizard.canLeaveBasics}\n onClick={wizard.goNext}\n variant=\"base-primary\"\n >\n 下一步\n </Button>\n ) : (\n <Button\n disabled={submitting}\n loading={submitting}\n onClick={(): void => {\n void handlePublish();\n }}\n variant=\"base-primary\"\n >\n 發佈\n </Button>\n )}\n </div>\n </div>\n </Section>\n </SectionGroup>\n </>\n );\n}\n\nconst FOOTER_STYLE = {\n alignItems: 'center',\n display: 'flex',\n // Match the breathing room used elsewhere (the Section's top padding token).\n marginTop: 'var(--mzn-spacing-padding-vertical-spacious)',\n justifyContent: 'space-between',\n gap: 16,\n} as const;\n\nconst FOOTER_ACTIONS_STYLE = {\n display: 'flex',\n gap: 8,\n} as const;\n"],"mappings":"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"}
@@ -0,0 +1,65 @@
1
+ "use client";require('../style.css');const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./router-adapter--gYs13E8.cjs"),n=require("./language-provider-Bdnx3Gxl.cjs"),r=require("./routes-config-C1j_vFKo.cjs"),i=require("./bpm-form-field-Bc6k4ZEO.cjs"),a=require("./format-member-label-t7ANTF62.cjs"),o=require("./admin-pickers-BRHk3qKq.cjs"),s=require("./FormRendererView-DRFi_IH7.cjs");;/* empty css */const c=require("./FormBuilderView-aBcA-_tt.cjs");let l=require("react"),u=require("@mezzanine-ui/react"),d=require("react/jsx-runtime"),f=require("@mezzanine-ui/react/Drawer");f=e.t(f,1);let p=require("@mezzanine-ui/react/ContentHeader");p=e.t(p,1);let m=require("@mezzanine-ui/icons"),h=require("ai"),g=require("@rytass/bpm-core-shared"),_=require("@rytass/bpm-core-client/form"),v=require("@rytass/bpm-core-shared/form"),ee=require("@rytass/bpm-core-client/organization"),y=require("@xyflow/react"),b=require("dagre");b=e.t(b,1);let x=require("@rytass/bpm-core-client/template"),te=require("@ai-sdk/react"),ne=require("@rytass/bpm-core-shared/workflow"),S=require("@rytass/bpm-core-shared/workflow-graph");var re=[{id:`SINGLE`,name:`單人簽核`},{id:`PARALLEL_ANY`,name:`任一人同意`},{id:`PARALLEL_ALL`,name:`全部同意`},{id:`SEQUENTIAL`,name:`依序簽核`},{id:`QUORUM`,name:`達到指定門檻`}];function ie(e){if(!e||e.type===`SINGLE`||e.type===`PARALLEL_ANY`)return`可指定多位;多位時所有人都會收到待辦,任一人同意即可通過。`;if(e.type===`PARALLEL_ALL`)return`可指定多位;多位時所有人都會收到待辦,全部同意後才會通過。`;if(e.type===`SEQUENTIAL`)return`依簽核人順序一次開放一位,前一位核准後才輪到下一位;任一位拒絕或退回即結束此關。`;let t=e.thresholdType===`PERCENTAGE`?`%`:` 位簽核者`;return`可指定多位;需達到 ${e.threshold}${t} 才會通過。`}function ae(e){return re.find(t=>t.id===e)||{id:e,name:`未知決策方式(${e})`}}function oe({directory:e,initialState:t,layout:n,onLayout:r}){let[i,a]=(0,l.useState)(t),o=(0,l.useRef)(t),s=(0,l.useRef)(e);s.current=e;let c=(0,l.useCallback)(e=>{if(!e.changed&&!e.error)return e;let t=e.effects.layout?n(e.state.definition):e.state.definition,i={...e.state,definition:t};return o.current=i,a(i),e.effects.layout&&r?.(t),{...e,state:i}},[n,r]),u=(0,l.useCallback)(e=>c((0,g.applyWorkflowCommand)(o.current,e)),[c]),d=(0,l.useCallback)(e=>c((0,g.applyWorkflowMacroCommand)(o.current,e)),[c]),f=(0,l.useCallback)(async(e,t)=>{let n=await(0,g.executeWorkflowTool)(o.current,e,t,{directory:s.current});if(n.ok&&(n.kind===`mutation`||n.kind===`macro`)){let e=c(n.result);return{...n,result:e,snapshot:(0,g.readWorkflowSnapshot)(e.state)}}return n},[c]),p=(0,l.useCallback)(e=>{let t=typeof e==`function`?e(o.current):e;o.current=t,a(t)},[]),m=(0,l.useCallback)(()=>o.current,[]),h=(0,l.useMemo)(()=>(0,g.readWorkflowSnapshot)(i),[i]);return(0,l.useMemo)(()=>({dispatch:u,dispatchMacro:d,executeTool:f,getState:m,replaceState:p,snapshot:h,state:i,tools:g.WORKFLOW_TOOLSET}),[u,d,f,m,p,h,i])}function se({controller:e,api:t=`/api/chat`}){let n=(0,l.useMemo)(()=>new h.DefaultChatTransport({api:t}),[t]),r=(0,te.useChat)({transport:n,sendAutomaticallyWhen:h.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:t}){let n=await e.executeTool(t.toolName,t.input);n.ok?r.addToolOutput({output:n.kind===`query`?n.data:n.snapshot,tool:t.toolName,toolCallId:t.toolCallId}):r.addToolOutput({errorText:n.error,state:`output-error`,tool:t.toolName,toolCallId:t.toolCallId})}});return r}var ce=12;function C(){let e=globalThis.LanguageModel;return e&&typeof e==`object`?e:null}var le={additionalProperties:!1,properties:{action:{enum:[`tool`,`message`],type:`string`},input:{type:`object`},text:{type:`string`},tool:{type:`string`}},required:[`action`],type:`object`};function ue(){return`你是「簽核流程設計器」頁面的離線 AI 助理。只能透過下列工具操作這個流程畫布,其他請求一律婉拒並引導回流程設計。
2
+
3
+ 每一步只輸出一個 JSON 決策物件:
4
+ - 呼叫工具:{"action":"tool","tool":"<工具名>","input":{...}}
5
+ - 回覆使用者(完成或詢問):{"action":"message","text":"<繁體中文訊息>"}
6
+
7
+ 規則:先用 get_workflow_snapshot 了解現況再規劃;完成後用 validate_workflow 檢查並以 message 說明做了什麼。
8
+
9
+ 可用工具:
10
+ ${g.WORKFLOW_TOOLSET.map(e=>`- ${e.name}(${JSON.stringify(e.inputSchema.properties??{})}): ${e.description}`).join(`
11
+ `)}`}function w({controller:e}){let[t,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(`ready`),s=(0,l.useRef)(0);(0,l.useEffect)(()=>{let e=C();e&&e.availability().then(e=>{n(e!==`unavailable`)}).catch(()=>n(!1))},[]);let c=(0,l.useCallback)((e,t)=>{s.current+=1,i(n=>[...n,{id:`chrome-${s.current}`,parts:[{text:t,type:`text`}],role:e}])},[]);return{available:t,messages:r,send:(0,l.useCallback)(t=>{let n=C();n&&a===`ready`&&(c(`user`,t),o(`submitted`),T({appendMessage:c,controller:e,model:n,userText:t}).then(()=>o(`ready`)).catch(e=>{c(`assistant`,fe(e)),o(`error`)}))},[c,e,a]),status:a}}async function T({appendMessage:e,controller:t,model:n,userText:r}){let i=await n.create({initialPrompts:[{content:ue(),role:`system`}]});try{let n=`使用者需求:${r}\n目前流程:${JSON.stringify(t.snapshot)}`;for(let r=0;r<ce;r+=1){let r=de(await i.prompt(n,{responseConstraint:le}));if(!r||r.action===`message`){e(`assistant`,r?.text??`我已完成可處理的部分。`);return}if(!r.tool){e(`assistant`,`我已完成可處理的部分。`);return}let a=await t.executeTool(r.tool,r.input??{});if(a.ok){let t=a.kind===`query`?a.data:a.snapshot;e(`assistant`,`⚙ ${r.tool}`),n=`工具 ${r.tool} 已執行。最新流程:${JSON.stringify(t)}\n請決定下一步。`}else n=`工具 ${r.tool} 失敗:${a.error}\n請改用其他方式或回覆使用者。`}e(`assistant`,`已達到單次操作步數上限,請告訴我下一步。`)}finally{i.destroy()}}function de(e){try{let t=JSON.parse(e);return typeof t==`object`&&t&&t.action!==void 0?t:null}catch{return null}}function fe(e){return e instanceof Error?`離線模式發生錯誤:${e.message}`:`離線模式發生未知錯誤。`}var pe={display:`flex`,flexDirection:`column`,gap:12,height:`100%`},me={display:`flex`,flex:1,flexDirection:`column`,gap:12,minHeight:0,overflowY:`auto`},he={display:`flex`,gap:8,paddingBottom:4},ge={borderTop:`1px solid var(--mzn-color-border-neutral, #e5e7eb)`,display:`flex`,flexDirection:`column`,gap:8,paddingTop:12},_e={display:`flex`,justifyContent:`flex-end`},ve={width:`100%`},ye=`workflow-chat-input-field`,be=`
12
+ .${ye}.mzn-text-field {
13
+ width: 100%;
14
+ }
15
+ `,xe={color:`var(--mzn-color-text-secondary, #6b7280)`,fontSize:12,padding:`2px 0`},Se={"input-available":`執行中…`,"input-streaming":`準備中…`,"output-available":`完成`,"output-error":`失敗`};function Ce(e){let t=e===`user`;return{alignSelf:t?`flex-end`:`flex-start`,background:t?`var(--mzn-color-primary, #2563eb)`:`var(--mzn-color-surface, #f3f4f6)`,borderRadius:10,color:t?`#fff`:`var(--mzn-color-text-primary, #111827)`,maxWidth:`85%`,padding:`8px 12px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`}}function we({api:e,controller:t,onClose:n,open:r}){let i=se({api:e,controller:t}),a=w({controller:t}),[o,s]=(0,l.useState)(`online`),[c,p]=(0,l.useState)(``),m=o===`offline`?{messages:a.messages,send:a.send,status:a.status}:{messages:i.messages,send:e=>{i.sendMessage({text:e})},status:i.status},{messages:h,send:g}=m,_=m.status===`submitted`||m.status===`streaming`,v=(0,l.useCallback)(()=>{let e=c.trim();e&&!_&&(p(``),g(e))},[_,c,g]),ee=(0,l.useCallback)(e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),v())},[v]);return(0,d.jsxs)(f.default,{headerTitle:`AI 流程助理`,isHeaderDisplay:!0,onClose:n,open:r,size:`medium`,children:[(0,d.jsx)(`style`,{children:be}),(0,d.jsxs)(`div`,{style:pe,children:[a.available?(0,d.jsxs)(`div`,{style:he,children:[(0,d.jsx)(u.Button,{onClick:()=>s(`online`),variant:o===`online`?`base-primary`:`base-tertiary`,children:`線上`}),(0,d.jsx)(u.Button,{onClick:()=>s(`offline`),variant:o===`offline`?`base-primary`:`base-tertiary`,children:`離線(裝置內,實驗)`})]}):null,(0,d.jsxs)(`div`,{role:`log`,style:me,children:[h.length===0?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`用一句話描述你想要的流程,例如:「建立三關簽核:部門主管 → 經理 → 財務,金額大於十萬走財務複核」。我會直接在畫布上幫你繪製。`}):null,h.map(e=>(0,d.jsx)(l.Fragment,{children:Te(e)},e.id)),_?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`思考中…`}):null]}),(0,d.jsxs)(`div`,{style:ge,children:[(0,d.jsx)(u.Textarea,{className:ye,disabled:_,maxLength:2e3,onChange:e=>p(e.target.value),onKeyDown:ee,placeholder:`描述你想要的流程…(Enter 送出,Shift + Enter 換行)`,rows:3,style:ve,value:c}),(0,d.jsx)(`div`,{style:_e,children:(0,d.jsx)(u.Button,{disabled:_||c.trim().length===0,loading:_,onClick:v,type:`button`,variant:`base-primary`,children:`送出`})})]})]})]})}function Te(e){return e.parts.map((t,n)=>{if(t.type===`text`)return(0,d.jsx)(`div`,{style:Ce(e.role),children:t.text},`${e.id}-${n}`);if(t.type===`dynamic-tool`||(0,h.isToolUIPart)(t)){let r=(0,h.getToolName)(t),i=Se[t.state]??t.state;return(0,d.jsx)(`div`,{style:xe,children:`⚙ ${r} · ${i}`},`${e.id}-${n}`)}return null})}var E={en:`An unknown error occurred`,"zh-TW":`發生未知錯誤`},D={en:`Webhook settings failed the publish check: `,"zh-TW":`Webhook 設定未通過發布檢查:`};function O(e,t,n){if(!(e instanceof Error))return E[t];let r=n?(0,x.readWorkflowLintMessage)(e.message,n,t):e.message;return r.includes(`WORKFLOW_WEBHOOK_`)?`${D[t]}${r}`:(0,_.readFormSchemaLintMessage)(r,t)}function Ee(e,t){let n=[...new Set(e.map(e=>e.level))];return[...n.includes(t)?n:[...n,t]].sort((e,t)=>t-e).map(t=>{let n=e.filter(e=>e.level===t).map(e=>e.name);return{id:String(t),name:n.length>0?`職等 ${t}(${n.join(`、`)})`:`職等 ${t}`,value:t}})}function k(e){return e.reduce((e,t)=>Math.max(e,t.level),1)}var A={"initiator.memberId":`發起人會員編號`,"instance.id":`案件編號`,"instance.templateId":`模板編號`,"instance.templateVersionId":`模板版本編號`,"instance.title":`案件主旨`,"node.id":`節點編號`,"node.label":`節點名稱`},De={boolean:`是/否`,json:`JSON`,number:`數字`,string:`文字`,stringArray:`文字清單`};function j(e){return`${e.key}@${e.version}`}function Oe(e,t){return e.find(e=>e.key===t.key&&e.version===t.version)??null}function ke(e){return[`FIELD`,...e===`stringArray`?[]:[`CONSTANT`],...e===`string`||e===`json`?[`CONTEXT`]:[]]}function Ae(e,t){return e.filter(e=>(0,S.isFormFieldCompatibleWithWebhookParameter)(e,t))}function je(e,t,n){return e===`FIELD`?{fieldKey:Ae(n,t.type)[0]?.fieldKey??``,kind:`FIELD`}:e===`CONTEXT`?{kind:`CONTEXT`,path:`instance.title`}:{kind:`CONSTANT`,value:t.type===`boolean`?!0:t.type===`number`?null:``}}var Me=/^-?\d+(\.\d+)?$/;function Ne(e,t){if(e!==`number`)return t;let n=t.trim();return n?Me.test(n)?Number(n):t:null}function Pe(e){return!(0,S.readNotifyWebhookStructureIssues)(e).some(e=>Fe.has(e.code))}var Fe=new Set([`BINDING_INVALID`,`BINDING_SOURCE_INVALID`,`BINDINGS_NOT_ARRAY`,`ENDPOINT_KEY_REQUIRED`,`ENDPOINT_VERSION_INVALID`,`TARGET_ID_REQUIRED`,`TARGET_INVALID`,`WEBHOOKS_NOT_ARRAY`]);function Ie(e,t,n){let r=e.bindings.filter(e=>e.parameter!==t),i=e.bindings.findIndex(e=>e.parameter===t);if(!n)return{...e,bindings:r};let a={from:n,parameter:t};return{...e,bindings:i===-1?[...e.bindings,a]:e.bindings.map((e,t)=>t===i?a:e)}}function M(e,t,n){return{bindings:e.bindings.filter(r=>{let i=t.parameters.find(e=>e.key===r.parameter);return i!==void 0&&!(0,S.readNotifyWebhookTargetCatalogIssues)({endpoint:{parameters:[{...i,required:!1}]},formFields:n,target:{...e,bindings:[r]}}).length}),endpoint:{key:t.key,version:t.version},id:e.id}}function Le({definition:e,endpoints:t,formFields:n}){return e.nodes.flatMap(e=>e.type!==`serviceTask`||e.data.action.type!==`NOTIFY`||(0,S.readNotifyWebhookStructureIssues)(e.data.action.webhooks).length?[]:(0,S.readNotifyWebhookTargets)(e.data.action).flatMap((r,i)=>{let a=Oe(t,r.endpoint);return(0,S.readNotifyWebhookTargetCatalogIssues)({endpoint:a,formFields:n,target:r}).map(t=>(0,S.readNotifyWebhookCatalogIssueMessage)({endpointLabel:a?.label??j(r.endpoint),issue:t,nodeLabel:e.data.label,targetIndex:i}))}))}var Re={display:`grid`,gap:`var(--mzn-spacing-gap-base)`},N={borderColor:`var(--mzn-color-border-neutral)`,borderRadius:`var(--mzn-radius-base)`,borderStyle:`solid`,borderWidth:1,display:`grid`,gap:`var(--mzn-spacing-gap-base)`,padding:`var(--mzn-spacing-padding-horizontal-base)`},ze={alignItems:`center`,display:`flex`,gap:`var(--mzn-spacing-gap-base)`,justifyContent:`space-between`},Be={display:`grid`,gap:`var(--mzn-spacing-gap-base)`,gridTemplateColumns:`minmax(0, 2fr) minmax(0, 3fr)`},Ve={id:`NONE`,name:`不傳送`},He={CONSTANT:{id:`CONSTANT`,name:`固定值`},CONTEXT:{id:`CONTEXT`,name:`案件資訊`},FIELD:{id:`FIELD`,name:`表單欄位`}},Ue=[{id:`true`,name:`是`},{id:`false`,name:`否`}],We=S.NOTIFY_WEBHOOK_CONTEXT_PATHS.map(e=>({id:e,name:A[e]}));function Ge({catalog:e,catalogState:t,formFields:n,onChange:r,targets:i}){let a=e.filter(e=>!e.deprecated);if(!i.length&&(t===`unavailable`||t===`ready`&&!a.length))return null;function o(e,t){r(i.map((n,r)=>r===e?t:n))}function s(){let[e]=a;e&&r([...i,(0,S.createNotifyWebhookTarget)({key:e.key,version:e.version})])}return(0,d.jsxs)(`div`,{style:Re,children:[(0,d.jsx)(u.Typography,{variant:`label-primary-highlight`,children:`Webhook`}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`知會節點抵達時,將指定的表單欄位或案件資訊送到外部系統。`}),t===`loading`?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`正在載入可用的 Webhook 端點…`}):null,t===`unavailable`?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:`目前無法載入 Webhook 端點,已設定的內容會保留,請稍後重試。`}):null,i.map((s,c)=>(0,d.jsx)(Ke,{activeEndpoints:a,catalog:e,catalogState:t,formFields:n,index:c,onChange:e=>o(c,e),onRemove:()=>r(i.filter((e,t)=>t!==c)),target:s},s.id)),(0,d.jsx)(`div`,{children:(0,d.jsx)(u.Button,{disabled:t!==`ready`||!a.length||i.length>=S.NOTIFY_WEBHOOK_TARGET_LIMIT,icon:m.PlusIcon,iconType:`leading`,onClick:s,variant:`base-dashed`,children:`新增 Webhook`})}),i.length>=S.NOTIFY_WEBHOOK_TARGET_LIMIT?(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`每個知會節點最多 `,S.NOTIFY_WEBHOOK_TARGET_LIMIT,` 個 Webhook。`]}):null]})}function Ke({activeEndpoints:e,catalog:t,catalogState:n,formFields:r,index:a,onChange:o,onRemove:s,target:c}){let l=Oe(t,c.endpoint),f=j(c.endpoint),p=[...e.map(e=>({id:j(e),name:Xe(e)})),...l&&!l.deprecated?[]:[{id:f,name:l?Xe(l):`${f}(找不到端點)`}]],h=new Set((l?.parameters??[]).map(e=>e.key)),g=l?c.bindings.filter(e=>!h.has(e.parameter)):[];return(0,d.jsxs)(`div`,{style:N,children:[(0,d.jsxs)(`div`,{style:ze,children:[(0,d.jsxs)(u.Typography,{variant:`label-primary`,children:[`第 `,a+1,` 個 Webhook`]}),(0,d.jsx)(u.Button,{icon:m.TrashIcon,iconType:`leading`,onClick:s,variant:`destructive-text-link`,children:`移除`})]}),(0,d.jsx)(i.t,{label:`端點`,name:`webhookEndpoint-${c.id}`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,disabled:n!==`ready`,onChange:t=>{let n=e.find(e=>j(e)===t?.id);n&&o(M(c,n,r??[]))},options:[...p],placeholder:`選擇端點`,value:p.find(e=>e.id===f)??null})}),n===`ready`&&!l?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`找不到這個端點,設定會保留;請改選其他端點或移除,否則無法發布。`}):null,l?.disabled?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`這個端點已被管理者停用,不會再送出;設定會保留,請改選其他端點,否則無法發布。`}):l?.deprecated?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`這個端點不建議再使用,設定會保留;請改選其他端點,否則無法發布。`}):null,l?.description?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:l.description}):null,l&&!l.parameters.length?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`這個端點不需要參數。`}):null,(l?.parameters??[]).map(e=>(0,d.jsx)(qe,{formFields:r,onChange:t=>o(Ie(c,e.key,t)),parameter:e,source:c.bindings.find(t=>t.parameter===e.key)?.from??null,targetId:c.id},e.key)),g.map(e=>(0,d.jsxs)(`div`,{style:ze,children:[(0,d.jsxs)(u.Typography,{color:`text-warning`,variant:`body`,children:[`參數「`,e.parameter,`」已不在端點定義中。`]}),(0,d.jsx)(u.Button,{onClick:()=>o(Ie(c,e.parameter,null)),variant:`base-text-link`,children:`移除設定`})]},e.parameter))]})}function qe({formFields:e,onChange:t,parameter:n,source:r,targetId:a}){let o=r?.kind===`FIELD`||Ae(e??[],n.type).length>0,s=[...n.required?[]:[Ve],...ke(n.type).filter(e=>e!==`FIELD`||o).map(e=>He[e])],c=De[n.type];return(0,d.jsx)(i.t,{hintText:[n.key,c,n.description].filter(Boolean).join(` · `),label:n.label,name:`webhookBinding-${a}-${n.key}`,required:n.required,children:(0,d.jsxs)(`div`,{style:Be,children:[(0,d.jsx)(u.Select,{clearable:!1,onChange:r=>{let i=Ze(r?.id??null);t(i?je(i,n,e??[]):null)},options:[...s],placeholder:`選擇來源`,value:r?He[r.kind]:n.required?null:Ve}),r?(0,d.jsx)(Je,{formFields:e,onChange:t,parameter:n,source:r}):null]})})}function Je({formFields:e,onChange:t,parameter:n,source:r}){if(r.kind===`FIELD`){if(!e)return(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`請先綁定表單版本,才能選擇表單欄位。`});let i=Ae(e,n.type).map(e=>({id:e.fieldKey,name:`${e.label}(${e.fieldKey})`})),a=r.fieldKey&&!i.some(e=>e.id===r.fieldKey)?[...i,{id:r.fieldKey,name:`${r.fieldKey}(找不到相容欄位)`}]:i;return(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>t({fieldKey:e?.id??``,kind:`FIELD`}),options:[...a],placeholder:a.length?`選擇表單欄位`:`沒有型別相容的欄位`,value:a.find(e=>e.id===r.fieldKey)??null})}return r.kind===`CONTEXT`?(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>{(0,S.isNotifyWebhookContextPath)(e?.id)&&t({kind:`CONTEXT`,path:e.id})},options:[...We],value:We.find(e=>e.id===r.path)??null}):n.type===`boolean`?(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>t({kind:`CONSTANT`,value:e?.id===`true`}),options:[...Ue],value:typeof r.value==`boolean`?Ue.find(e=>e.id===String(r.value))??null:null}):(0,d.jsx)(Ye,{onChange:e=>t({kind:`CONSTANT`,value:e}),type:n.type,value:r.value})}function Ye({onChange:e,type:t,value:n}){let[r,i]=(0,l.useState)(n===null?``:String(n));return(0,l.useEffect)(()=>{i(e=>Ne(t,e)===n?e:n===null?``:String(n))},[t,n]),(0,d.jsx)(u.Input,{inputProps:{inputMode:t===`number`?`decimal`:void 0},onChange:n=>{i(n.target.value),e(Ne(t,n.target.value))},placeholder:t===`number`?`輸入數字`:`輸入固定值`,value:r,variant:`base`})}function Xe(e){let t=[`v${e.version}`,...e.source===`DATABASE`?[`後台維護`]:[],...e.disabled?[`已停用`]:e.deprecated?[`不建議使用`]:[]];return`${e.label}(${t.join(`,`)})`}function Ze(e){return e===`FIELD`||e===`CONSTANT`||e===`CONTEXT`?e:null}function Qe(e){return(e?.fields??[]).reduce((e,t)=>({...e,[t.fieldKey]:$e(t)}),{})}function P(e){return`formMember:${e}`}function $e(e){if(e.type===`number`||e.type===`money`)return 1e3;if(e.type===`boolean`)return!0;if(e.type===`member`){let t=P(e.fieldKey);return e.multiple?[t]:t}if((0,v.isFormOptionFieldDefinition)(e)){let t=(0,v.isFormStaticOptionFieldDefinition)(e)?e.options[0]?.value:void 0;if((0,v.readFormFieldSelectionMode)(e)===`multiple`)return t===void 0?[]:[t];if((0,v.isFormStaticOptionFieldDefinition)(e))return t??``}return e.type===`date`?`2026-05-08`:e.type===`datetime`?`2026-05-08T09:00:00+08:00`:e.placeholder??e.label}function et(e,t){let[n,...r]=e.split(`:`),i=e=>t.orgUnits.find(t=>t.id===e)?.name??e,a=e=>t.positions.find(t=>t.id===e)?.name??e;return n===`position`&&r.length===1&&r[0]?`職位:${a(r[0])}(送出時依當下人員決定)`:n===`orgUnitMember`&&r.length===1&&r[0]?`組織任一人:${i(r[0])}`:n===`orgUnitPosition`&&r.length===2&&r[0]&&r[1]?`組織職位:${i(r[0])}/${a(r[1])}`:n===`orgUnitManager`&&r.length===1&&r[0]?`組織主管:${i(r[0])}`:n===`formMember`&&r.length===1&&r[0]?`表單欄位「${(e=>t.formFields.find(t=>t.fieldKey===e)?.label||e)(r[0])}」選的人(送出時依填寫內容決定)`:n===`orgManagerChain`&&r.length===1&&r[0]?`主管鏈:簽到職等 ${r[0]}(送出時依組織決定實際主管)`:t.memberName(e)??e}var tt=`表單中沒有「人員選擇」欄位,請先到表單設計加入`,nt=`原本指定的欄位已不在表單中,或已不是「人員選擇」欄位,請重新選擇。`,rt=`此欄位非必填`,it=`此欄位可能被條件隱藏`,F=`此欄位為隱藏欄位,申請人無法填寫`,at=`,空白時此關會找不到人員,發佈時會被拒絕;請在表單設計將它設為必填且不隱藏`;function I(e){let t=[...e.required?[]:[rt],...e.visibleWhen?.trim()?[it]:[],...e.hidden?[F]:[]];return t.length>0?`${t.join(`、`)}${at}`:void 0}function ot(e){return`${e.required?``:`(非必填)`}${e.visibleWhen?.trim()?`(可能被條件隱藏)`:``}${e.hidden?`(隱藏欄位)`:``}`}function st(e){return(e?.fields??[]).filter(v.isMemberFieldDefinition).map(e=>{let t=I(e);return{id:e.fieldKey,name:`${e.label} (${e.fieldKey})${ot(e)}`,...t?{warning:t}:{}}})}function ct(e,t){let n=st(e),r=n.find(e=>e.id===t)??null;if(r)return{options:n,problem:r.warning??null,selected:r};if(t.trim()){let e={id:t,name:`${t}(無效欄位)`};return{options:[...n,e],problem:nt,selected:e}}return{options:n,problem:n.length===0?tt:null,selected:null}}function lt(e,t){if(!t.trim())return`依表單欄位:未設定`;let n=e?.fields.find(e=>e.fieldKey===t);return n&&!(0,v.isMemberFieldDefinition)(n)?`依表單欄位:${n.label||t}(非人員選擇欄位)`:`依表單欄位:${n?.label||t}`}function ut(e){return`${e.draftVersion===null?`尚未建立草稿`:`草稿 v${e.draftVersion}`} · ${e.publishedVersion===null?e.hasPublishedVersion?`已發布版本`:`尚未發布`:`已發布 v${e.publishedVersion}`}`}function dt(e,t){return`表單:${e} v${t}`}var ft={display:`grid`,gap:16},pt={alignItems:`start`,display:`grid`,gap:16,gridTemplateColumns:`minmax(0, 1fr) 420px`},mt={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,height:620,minWidth:0,overflow:`hidden`},ht={alignItems:`center`,boxSizing:`border-box`,color:`var(--mzn-color-text-error)`,display:`flex`,height:26,justifyContent:`center`,lineHeight:0,padding:0,width:26},gt={alignItems:`center`,display:`flex`,height:`100%`,justifyContent:`center`,width:`100%`},_t=`workflow-designer-side-panel`,vt=96,yt=`
16
+ .${_t} .mzn-form-field--stretch .mzn-form-field__label-area,
17
+ .${_t} .mzn-form-field--horizontal .mzn-form-field__label-area {
18
+ flex: 0 0 ${vt}px;
19
+ width: ${vt}px;
20
+ }
21
+
22
+ .${_t} .mzn-form-field--stretch .mzn-form-field__data-entry,
23
+ .${_t} .mzn-form-field--horizontal .mzn-form-field__data-entry {
24
+ min-width: 0;
25
+ }
26
+ `,bt=`#2563eb`,xt=`#64748b`,St=`var(--mzn-color-text-error, #dc2626)`,Ct=`drop-shadow(0 0 3px rgba(0, 87, 255, 0.85)) drop-shadow(0 0 9px rgba(0, 87, 255, 0.36))`,wt=`
27
+ .workflow-selection-delete-control.react-flow__controls-button {
28
+ align-items: center !important;
29
+ display: flex !important;
30
+ height: 26px !important;
31
+ justify-content: center !important;
32
+ padding: 0 !important;
33
+ width: 26px !important;
34
+ }
35
+
36
+ .workflow-selection-delete-control .mzn-icon {
37
+ align-items: center;
38
+ display: flex;
39
+ justify-content: center;
40
+ }
41
+
42
+ .workflow-selection-delete-control .mzn-icon svg {
43
+ height: 16px !important;
44
+ max-height: none !important;
45
+ max-width: none !important;
46
+ width: 16px !important;
47
+ }
48
+
49
+ .workflow-edge--selected .react-flow__edge-path,
50
+ .react-flow__edge-path.workflow-edge--selected {
51
+ filter: ${Ct};
52
+ opacity: 1 !important;
53
+ stroke: ${xt} !important;
54
+ stroke-opacity: 1 !important;
55
+ stroke-width: 1.5px !important;
56
+ }
57
+
58
+ .workflow-edge--selected {
59
+ --xy-edge-stroke: ${xt};
60
+ --xy-edge-stroke-selected: ${xt};
61
+ --xy-edge-stroke-width: 1.5px;
62
+ }
63
+
64
+ `,Tt={display:`grid`,gap:12},Et={display:`grid`,gap:12},Dt={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,display:`grid`,gap:8,maxHeight:360,overflow:`auto`,padding:12},Ot={borderBottom:`1px solid var(--mzn-color-border-neutral)`,display:`grid`,gap:4,padding:`0 0 8px`},kt={display:`flex`,flexWrap:`wrap`,gap:8},At={alignItems:`center`,display:`flex`,gap:8},jt={flex:`1 1 auto`,minWidth:0},Mt={flex:`0 0 auto`},Nt={display:`grid`,gap:8},Pt={alignContent:`center`,background:`var(--mzn-color-bg-surface)`,border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,boxShadow:`0 8px 20px rgba(15, 23, 42, 0.08)`,boxSizing:`border-box`,display:`grid`,gap:4,height:`100%`,minWidth:132,overflow:`visible`,padding:`10px 12px`,textAlign:`center`,width:`100%`},Ft=`0 8px 20px rgba(15, 23, 42, 0.08), 0 0 0 1px var(--mzn-color-primary, #0057ff), 0 0 10px rgba(0, 87, 255, 0.3)`,It=64,Lt=160,Rt=20,zt=64,Bt=180,Vt={...Pt,display:`grid`,gap:8,padding:`10px 12px`},Ht={...Vt,background:`#eff6ff`,border:`1px solid #2563eb`},Ut={...Vt,background:`#f0fdfa`,border:`1px solid #0f766e`},Wt={...Pt,background:`#ffffff`},Gt={...Pt,background:`#ecfdf3`,border:`1px solid #2f855a`},Kt={...Pt,background:`#fff4ed`,border:`1px solid #c2410c`},L={display:`block`,maxWidth:`100%`,minWidth:0},qt={display:`grid`,gap:2,minWidth:0},R=`input`,z=`output`,Jt={endEvent:`結束`,exclusiveGateway:`條件分流`,parallelGateway:`並行處理`,serviceTask:`系統`,startEvent:`開始`,userTask:`簽核`},Yt=[{icon:m.UserIcon,label:`簽核節點`,type:`userTask`},{icon:m.MailIcon,label:`知會節點`,type:`serviceTask`}],Xt=[{icon:m.FilterIcon,label:`條件分流`,type:`exclusiveGateway`}],Zt=[{id:`AND`,name:`全部前置完成`},{id:`OR`,name:`任一前置完成`}],Qt=[{id:`RESTART`,name:`重新送出後從開始重跑`},{id:`FROM_RETURN_POINT`,name:`重新送出後回到退回節點`}],$t=[{id:`NONE`,name:`不提醒`,value:null},{id:`0.5`,name:`過半時提醒`,value:.5},{id:`0.75`,name:`剩四分之一時提醒`,value:.75},{id:`0.9`,name:`剩十分之一時提醒`,value:.9}],en=[{id:`DIRECT`,name:`指定會員`},{id:`DYNAMIC_FORM`,name:`依表單欄位指定`},{id:`ORG_MANAGER`,name:`發起人主管`},{id:`ORG_MANAGER_CHAIN`,name:`主管鏈(簽到指定職等)`},{id:`ORG_UNIT_MANAGER`,name:`指定組織主管`},{id:`ORG_UNIT_MEMBER`,name:`組織任一人`},{id:`ORG_UNIT_POSITION`,name:`組織特定職位`},{id:`POSITION`,name:`指定職位`}],tn=[{id:`COUNT`,name:`人數`},{id:`PERCENTAGE`,name:`百分比`}],B=[{id:`1`,name:`直屬主管`,value:1},{id:`2`,name:`第二層主管`,value:2},{id:`3`,name:`第三層主管`,value:3}],nn=[{id:`NONE`,name:`停止流程並提示`},{id:`DIRECT`,name:`固定改派`},{id:`POSITION`,name:`指定職位`}],rn={id:`UNSUPPORTED`,name:`不支援的備援設定`},an=[{id:`INITIATOR_MANAGER`,name:`改由申請人的直屬主管簽核`},{id:`SKIP_NODE`,name:`跳過此關`},{id:`FAIL`,name:`停止流程並提示`}],on={whenEmpty:`INITIATOR_MANAGER`},sn=[`EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`NOT_EQUALS`],cn=[{id:`NONE`,name:`未設定`},{id:`ALL`,name:`所有人`},{id:`ORG_UNIT`,name:`指定組織`},{id:`ORG_UNIT_POSITION`,name:`指定組織職位`}],ln={id:`CUSTOM`,name:`既有自訂規則`},un=`member-001`,dn={display:`flex`,flexDirection:`column`,height:`100%`},fn={flex:1,minHeight:0,overflowY:`auto`},pn={borderTop:`1px solid var(--mzn-color-border-neutral)`,display:`flex`,gap:8,paddingTop:12},mn={fields:[],schemaVersion:1},hn={layout:[],schemaVersion:1},gn={endEvent:V,exclusiveGateway:V,parallelGateway:V,serviceTask:V,startEvent:V,userTask:V};function _n(e,t){return typeof e==`function`?e(t):e}function vn({aiAssistantAvailable:e=!0,embedded:a=!1,formSchemaOverride:h,initialInitiatorPolicyCel:g,initialWorkflowDefinition:v,onInitiatorPolicyChange:b,onWorkflowChange:te,showAiAssistant:se=!1,showDryRun:ce=!0,templateId:C}){let le=t.r(),ue=r.r(),w=n.i(),[T,de]=(0,l.useState)(null),[fe,pe]=(0,l.useState)(null),[me,he]=(0,l.useState)(``),[ge,_e]=(0,l.useState)(null),[ve,ye]=(0,l.useState)(null),be=(0,l.useRef)(null),[xe,Se]=(0,l.useState)(void 0),Ce=(0,l.useRef)([]),Te=(0,l.useRef)([]),E=oe({directory:(0,l.useMemo)(()=>({listOrgUnits:async()=>Ce.current.map(e=>({id:e.id,name:e.name})),listPositions:async()=>Te.current.map(e=>({id:e.id,name:e.name})),searchMembers:async e=>br(await(0,x.searchMemberOptions)(e)).map(e=>({email:e.email,id:e.memberId,name:e.name}))}),[]),initialState:{definition:a&&v!=null?On(v):Mn(),editingEdgeId:null,formDefinitionVersionId:null,formSchema:null,initiatorPolicyCel:a&&g!==void 0?g:null,selectedEdgeIds:[],selectedNodeId:a&&v!=null?v.nodes[0]?.id??`start`:`start`},layout:Pn,onLayout:e=>{let t=Hr(e,be.current);t&&Se(t)}}),D=E.state.definition,k=E.state.formDefinitionVersionId,A=E.state.initiatorPolicyCel,De=E.state.selectedNodeId,j=E.state.selectedEdgeIds,Oe=E.state.editingEdgeId,ke=e=>E.replaceState(t=>({...t,definition:_n(e,t.definition)})),Ae=e=>E.replaceState(t=>({...t,formDefinitionVersionId:_n(e,t.formDefinitionVersionId)})),je=e=>E.replaceState(t=>({...t,initiatorPolicyCel:_n(e,t.initiatorPolicyCel)})),Me=e=>E.replaceState(t=>({...t,selectedNodeId:_n(e,t.selectedNodeId)})),Ne=e=>E.replaceState(t=>({...t,selectedEdgeIds:_n(e,t.selectedEdgeIds)})),Fe=e=>E.replaceState(t=>({...t,editingEdgeId:_n(e,t.editingEdgeId)})),[Ie,M]=(0,l.useState)(null),[Re,N]=(0,l.useState)(null);(0,l.useEffect)(()=>{N(null)},[De]);let[ze,Be]=(0,l.useState)(!0),[Ve,He]=(0,l.useState)(!1),[Ue,We]=(0,l.useState)(!1),[Ke,qe]=(0,l.useState)([]),Je=(0,l.useMemo)(()=>JSON.stringify({formDefinitionVersionId:k,initiatorPolicyCel:A,workflowDefinition:D}),[k,A,D]),Ye=!!me&&Je!==me,[Xe,Ze]=(0,l.useState)(!1),[P,$e]=(0,l.useState)([]),[tt,nt]=(0,l.useState)([]),rt=(0,l.useRef)(0),it=(0,l.useRef)(new Set),[F,at]=(0,l.useState)([]),[I,ot]=(0,l.useState)([]),[st,lt]=(0,l.useState)([]);Ce.current=F,Te.current=I;let[dt,vt]=(0,l.useState)(!1),[bt,xt]=(0,l.useState)(!1),[Ct,Pt]=(0,l.useState)(`{}`),[Ft,It]=(0,l.useState)(null),[Lt,Rt]=(0,l.useState)(null),[zt,Bt]=(0,l.useState)([]),[Vt,Ht]=(0,l.useState)(`loading`),[Ut,Wt]=(0,l.useState)(!1),[Gt,Kt]=(0,l.useState)(!1),[L,qt]=(0,l.useState)(null),[R,z]=(0,l.useState)(!1),[sn,vn]=(0,l.useState)(!1),V=Ye||R?`保存並發布`:fe?`發布草稿`:`已發布`;(0,l.useEffect)(()=>{a?fr():gr()},[a,C]),(0,l.useEffect)(()=>{function e(e){Ye&&(e.preventDefault(),e.returnValue=``)}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[Ye]),(0,l.useEffect)(()=>{Er(D)},[D,P]),(0,l.useEffect)(()=>{ke(e=>On(e))},[D.edges,D.nodes]);function bn(){(!Ye||window.confirm(`目前有尚未儲存的流程草稿,確定要離開嗎?`))&&le.push(ue.templates())}let H=(0,l.useMemo)(()=>D.nodes.find(e=>e.id===De)??null,[De,D.nodes]),xn=H?dr(H):!1,Sn=j.length>0||xn,U=(0,l.useCallback)(()=>{E.getState().selectedEdgeIds.forEach(e=>E.dispatch({edgeId:e,type:`deleteEdge`})),H&&dr(H)&&E.dispatch({nodeId:H.id,type:`deleteNode`})},[E,H]);(0,l.useEffect)(()=>{if(!Sn)return;function e(e){(e.key===`Delete`||e.key===`Backspace`)&&(pr(e.target)||(e.preventDefault(),U()))}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[Sn,U]);let wn=(0,l.useMemo)(()=>D.edges.find(e=>e.id===Oe)??null,[Oe,D.edges]),Tn=(0,l.useMemo)(()=>j.length===1?D.edges.find(e=>e.id===j[0])??null:null,[j,D.edges]),En=(0,l.useMemo)(()=>j.map(e=>D.edges.find(t=>t.id===e)??null).filter(e=>!!e),[j,D.edges]),W=(0,l.useMemo)(()=>ve??rr(A,ge),[A,ve,ge]),kn=(0,l.useMemo)(()=>D.edges.map(e=>Dn(e,D.nodes,j.includes(e.id))),[j,D.edges,D.nodes]),G=(0,l.useMemo)(()=>K(Ke,k)??K(mr(T?.formVersions??[]),k),[k,Ke,T?.formVersions]),An=(0,l.useMemo)(()=>yr(Ke,G),[Ke,G]),jn=G?.schema??null,Yn=a?h??null:jn;(0,l.useEffect)(()=>{E.getState().formSchema!==Yn&&E.replaceState(e=>({...e,formSchema:Yn}))},[E,Yn]);let q=(0,l.useMemo)(()=>Ur(D),[D]);(0,l.useEffect)(()=>{let e=!0;return(0,x.listWorkflowWebhookEndpoints)({includeDeprecated:!0}).then(t=>{e&&(Bt(t),Ht(`ready`))}).catch(()=>{e&&Ht(`unavailable`)}),()=>{e=!1}},[]);let J=R&&L?L.schema:Yn,ar=(0,l.useMemo)(()=>Vt===`ready`?Le({definition:D,endpoints:zt,formFields:J?.fields??[]})[0]??null:null,[zt,Vt,J,D]),sr=(0,l.useMemo)(()=>D.nodes.map(e=>Cn(e,P,F,I,e.id===De,W,J)),[W,P,F,I,De,J,D.nodes]),Y=(0,l.useMemo)(()=>(0,S.hasConfiguredConditionEdges)(D),[D]),X=(0,l.useMemo)(()=>ir(W),[W]);(0,l.useEffect)(()=>{a&&te?.(D)},[a,D]),(0,l.useEffect)(()=>{a&&b?.(A)},[a,A]);async function fr(){Be(!0),M(null);try{let e=await(0,ee.readOrganizationDashboard)();at(e.orgUnits),ot(e.positions),lt(e.memberships)}catch(e){M(O(e,w))}finally{Be(!1)}}async function gr(){Be(!0),M(null),N(null);try{let[e,t]=await Promise.all([(0,x.readTemplateDesigner)(C),(0,ee.readOrganizationDashboard)()]),n=e.versions.find(e=>e.status===`DRAFT`)??null,r=n??e.versions[0]??null;de(e),pe(n),at(t.orgUnits),ot(t.positions),lt(t.memberships),qe(mr(e.formVersions));let i=On(r?.workflowDefinition??Mn()),a=r?.formDefinitionVersionId??e.formVersions[0]?.id??null,o=r?.initiatorPolicyCel??null;ke(i),Ae(a),je(o),he(JSON.stringify({formDefinitionVersionId:a,initiatorPolicyCel:o,workflowDefinition:i})),_e(r&&!e.template.currentVersionId&&!r.initiatorPolicyCel&&Nn(r.workflowDefinition)?`NONE`:null),ye(null),Me(r?.workflowDefinition.nodes[0]?.id??`start`),Ne([]),Fe(null),qt(null),z(!1)}catch(e){M(O(e,w))}finally{Be(!1)}}async function Z(e){We(!0),M(null);try{let t=await(0,x.searchPublishedFormVersionOptions)(e);qe(yr(mr(t),G))}catch(e){M(O(e,w))}finally{We(!1)}}async function Q(e){Ze(!0),M(null);let t=++rt.current;try{let n=br(await(0,x.searchMemberOptions)(e));$e(e=>Mr(e,n)),t===rt.current&&nt(n)}catch(e){t===rt.current&&M(O(e,w))}finally{t===rt.current&&Ze(!1)}}async function Er(e){let t=Pr(e),n=s.n(t.filter(e=>!P.some(t=>t.memberId===e&&!t.unresolved)),it.current);if(n.length===0)return;let{profiles:r,skippedIds:i}=await s.r(n,x.resolveMemberOptions),a=new Set(r.map(e=>e.memberId)),o=n.filter(e=>!a.has(e)&&!i.includes(e));o.forEach(e=>it.current.add(e)),$e(e=>Mr(e,[...br(r),...[...o,...i].map(xr)]))}async function Dr(e){He(!0),M(null);try{let t=Ur(D),n=ir(W),r=e?ar:null;if(t||n||r){let e=t??n??r??`流程設定未完成`;throw M(e),Error(e)}if(R&&L!==null)await(0,x.composeApprovalTemplateWithForm)({category:T?.template.category??null,categoryId:T?.template.categoryId??null,formDefinitionId:G?.formDefinitionId??null,formDescription:null,formName:G?.formName??T?.template.name??`表單`,initiatorPolicyCel:A,notificationConfig:null,publish:e,schema:L.schema,slaDefaults:null,templateDescription:null,templateId:C??null,templateName:T?.template.name??`模板`,uiSchema:L.uiSchema,workflowDefinition:D}),z(!1),qt(null),await gr();else{let t=fe??await(0,x.forkApprovalTemplate)(C),n=await(0,x.updateApprovalTemplateDraft)({formDefinitionVersionId:k,initiatorPolicyCel:A,versionId:t.id,workflowDefinition:D});pe(n),e&&await(0,x.publishApprovalTemplateVersion)(n.id),await gr()}}catch(e){throw M(O(e,w,D)),e}finally{He(!1)}}async function Or(){await Dr(!1)}async function kr(){await Dr(!0)}function jr(){Pt(JSON.stringify(Qe(J),null,2)),It(null),Rt(null),vt(!0)}function Nr(){bt||vt(!1)}async function Fr(){xt(!0),Rt(null),It(null);try{let e=hr(Ct),t=await(0,x.dryRunApprovalWorkflow)({formData:e,initiatorMemberId:un,initiatorMetadataSnapshot:Tr(un,st),workflowDefinition:D});It(t)}catch(e){Rt(O(e,w))}finally{xt(!1)}}async function Lr(){if(Kt(!0),L!==null)return;let e=G?.formDefinitionId??null;if(!e)qt({schema:mn,uiSchema:hn});else{vn(!0);try{let t=await(0,_.readFormBuilder)(e),n=t.versions.find(e=>e.status===`DRAFT`)??t.versions.find(e=>e.id===t.definition.currentVersionId)??t.versions[0]??null;qt({schema:n?.schema??mn,uiSchema:n?.uiSchema??hn})}catch(e){M(O(e,w))}finally{vn(!1)}}}function Rr(e){let t=(0,y.applyNodeChanges)(e,sr);ke(e=>({...e,nodes:e.nodes.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,position:n.position}:e})}))}function Br(e){lr(e,D.nodes)&&e.source&&e.target&&E.dispatch({source:e.source,target:e.target,type:`connectEdge`})}function Vr(e,t){e.stopPropagation(),Ne(n=>e.shiftKey||e.metaKey||e.ctrlKey?ur(n,t.id):[t.id]),Me(null)}function Yr(){Fe(null)}function Zr(e){E.dispatch({nodeType:e,type:`addNode`})}function $r(e){H&&E.dispatch({label:e,nodeId:H.id,type:`renameNode`})}function $(e){if(!H||H.type!==`userTask`)return;let t=H.id,n=H.data.decisionPolicy;E.dispatch({approverResolver:e,nodeId:t,type:`setUserTaskApprover`}),N(null),(0,S.isOrgManagerChainDecisionPolicyInvalid)(e,n)?N({message:`主管鏈會依序加入多位主管,簽核方式已改為「依序簽核」。`,nodeId:t,policyType:`SEQUENTIAL`}):(0,S.isDecisionPolicyUnsatisfiable)(n,e)&&N({message:`簽核者已變更為 ${(0,S.readDesignTimeApproverCount)(e)} 位,不足原本設定的 ${n?.type===`QUORUM`?n.threshold:0} 位門檻,簽核政策已重設為單人簽核,請重新設定。`,nodeId:t,policyType:`SINGLE`})}function ei(e){H&&H.type===`userTask`&&E.dispatch({nodeId:H.id,resubmitStrategy:e,type:`setUserTaskReturnResubmitStrategy`})}function ti(e){H&&H.type===`userTask`&&E.dispatch({nodeId:H.id,requireComment:e,type:`setUserTaskReturnRequireComment`})}function ni(e){H&&H.type===`userTask`&&E.dispatch({nodeId:H.id,sla:e,type:`setUserTaskSla`})}function ri(e){H&&H.type===`userTask`&&E.dispatch({excludeInitiator:e,nodeId:H.id,type:`setUserTaskExcludeInitiator`})}function ii(e){if(!H||H.type!==`userTask`)return;N(null);let t=e.type===`QUORUM`?{...e,threshold:(0,S.composeQuorumThreshold)(e.threshold,e.thresholdType)}:e;E.dispatch({decisionPolicy:t,nodeId:H.id,type:`setUserTaskDecisionPolicy`})}function ai(e){H&&H.type===`userTask`&&E.dispatch({...e,nodeId:H.id,type:`setUserTaskOptions`})}function oi(e){H&&H.type===`serviceTask`&&E.dispatch({action:e,nodeId:H.id,type:`setServiceAction`})}function si(e){ye(e.mode===`ALL`||e.mode===`CUSTOM`?null:e),_e(e.mode===`ALL`||e.mode===`CUSTOM`?null:e.mode),je(or(e,F))}function ci(e){H&&H.type!==`startEvent`&&E.dispatch({nodeId:H.id,triggerMode:e,type:`setNodeTriggerMode`})}function li(e,t){E.dispatch({edgeId:e,isDefault:t,type:`setEdgeDefault`})}function ui({edgeId:e,fieldKey:t,operator:n,value:r}){E.dispatch({edgeId:e,fieldKey:t,operator:n,type:`setEdgeCondition`,value:r})}function di(){E.dispatch({type:`autoLayout`})}return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`style`,{children:yt}),a?null:(0,d.jsx)(u.PageHeader,{children:(0,d.jsxs)(p.default,{description:ut({draftVersion:fe?.version??null,hasPublishedVersion:!!T?.template.currentVersionId,publishedVersion:T?.versions.find(e=>e.id===T.template.currentVersionId)?.version??null}),onBackClick:bn,title:T?.template.name??`流程設計器`,children:[se?(0,d.jsx)(u.Button,{disabled:!e,onClick:()=>Wt(e=>!e),variant:Ut?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`}):null,(0,d.jsx)(u.Button,{"aria-label":`儲存草稿`,disabled:Ve||!!q||!!X,icon:m.SaveIcon,iconType:`icon-only`,onClick:()=>void Or(),variant:`base-secondary`,children:`儲存草稿`}),ce?(0,d.jsx)(u.Button,{disabled:ze||!!q||!!X,icon:m.EyeIcon,iconType:`leading`,onClick:jr,variant:`base-secondary`,children:`試跑流程`}):null,(0,d.jsx)(u.Button,{disabled:Ve||!fe&&!Ye&&!R||!!q||!!X||!!ar,icon:m.CheckedIcon,iconType:`leading`,onClick:()=>void kr(),variant:`base-primary`,children:V})]})}),(0,d.jsx)(u.SectionGroup,{children:(0,d.jsx)(u.Section,{children:(0,d.jsxs)(`div`,{style:ft,children:[Ie?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:Ie}):null,Re&&Re.nodeId===H?.id&&H.type===`userTask`&&(H.data.decisionPolicy?.type??`SINGLE`)===Re.policyType?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:Re.message}):null,q?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:q}):null,X?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:X}):null,!q&&ar?(0,d.jsxs)(u.Typography,{color:`text-error`,variant:`body`,children:[`發布前需修正:`,ar]}):null,a?null:(0,d.jsx)(`div`,{style:Et,children:(0,d.jsx)(i.t,{hintText:Y?`已設定條件分流條件。請先移除所有條件,才能更換綁定表單版本。`:void 0,label:`綁定表單版本`,name:`formDefinitionVersionId`,required:!0,children:(0,d.jsxs)(`div`,{style:At,children:[(0,d.jsx)(`div`,{style:jt,children:(0,d.jsx)(u.AutoComplete,{asyncData:!0,disabled:ze||Y,disabledOptionsFilter:!0,emptyText:`沒有符合的已發布表單版本`,isForceClearable:!!k&&!Y,loading:Ue,loadingText:`搜尋表單版本中...`,mode:`single`,onChange:e=>{Y||Ae(e?.id??null)},onClear:()=>{Y||Ae(null)},onSearch:Z,onVisibilityChange:e=>{e&&!Y&&Z(``)},options:[...An],placeholder:`選擇已發布表單版本`,searchDebounceTime:300,value:G})}),(0,d.jsx)(u.Button,{disabled:ze,onClick:()=>{Lr()},style:Mt,variant:`base-secondary`,children:`編輯表單`})]})})}),(0,d.jsxs)(`div`,{style:pt,children:[(0,d.jsx)(`div`,{ref:be,style:mt,children:(0,d.jsxs)(y.ReactFlow,{connectionMode:y.ConnectionMode.Strict,edges:kn,fitView:!0,isValidConnection:e=>lr(e,D.nodes),nodeTypes:gn,nodes:sr,deleteKeyCode:null,multiSelectionKeyCode:[`Shift`,`Meta`,`Control`],onConnect:Br,onEdgeClick:Vr,onNodeClick:(e,t)=>{Me(t.id),Ne([])},onNodesChange:Rr,onPaneClick:()=>{Me(null),Ne([])},onViewportChange:Se,viewport:xe,children:[(0,d.jsx)(y.Background,{}),(0,d.jsx)(`style`,{children:wt}),(0,d.jsx)(y.Controls,{children:Sn?(0,d.jsx)(y.ControlButton,{"aria-label":`刪除選取項目`,className:`workflow-selection-delete-control`,onClick:U,style:ht,title:`刪除選取項目`,children:(0,d.jsx)(`span`,{style:gt,children:(0,d.jsx)(u.Icon,{color:`error`,icon:m.TrashIcon,size:16})})}):null}),(0,d.jsx)(yn,{onApplyAutoLayout:di}),(0,d.jsx)(y.MiniMap,{})]})}),(0,d.jsxs)(`div`,{className:_t,style:Tt,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:`流程工具`}),a&&se?(0,d.jsxs)(`div`,{style:Nt,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`AI 協助`}),(0,d.jsx)(`div`,{style:kt,children:(0,d.jsx)(u.Button,{disabled:!e,onClick:()=>Wt(e=>!e),size:`sub`,variant:Ut?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`})})]}):null,(0,d.jsxs)(`div`,{style:Nt,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`動作節點`}),(0,d.jsx)(`div`,{style:kt,children:Yt.map(e=>(0,d.jsx)(u.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Zr(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,d.jsxs)(`div`,{style:Nt,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`流程控制`}),(0,d.jsx)(`div`,{style:kt,children:Xt.map(e=>(0,d.jsx)(u.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Zr(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),En.length>1?vi(En):null,En.length===1&&Tn?yi(Tn):null,En.length===0&&H?pi(H):null]})]})]})})}),bi(wn),!a&&ce?fi():null,se&&e?(0,d.jsx)(we,{controller:E,onClose:()=>Wt(!1),open:Ut}):null,a?null:(0,d.jsx)(f.default,{headerTitle:`編輯表單`,isHeaderDisplay:!0,onClose:()=>Kt(!1),open:Gt,size:`wide`,children:(0,d.jsxs)(`div`,{style:dn,children:[(0,d.jsx)(`div`,{style:fn,children:sn?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`載入中…`}):(0,d.jsx)(c.t,{onChange:e=>{qt(e)},value:L??{schema:mn,uiSchema:hn}})}),(0,d.jsxs)(`div`,{style:pn,children:[(0,d.jsx)(u.Button,{disabled:sn,onClick:()=>{L!==null&&(z(!0),E.replaceState(e=>({...e,formSchema:L.schema}))),Kt(!1)},variant:`base-primary`,children:`套用`}),(0,d.jsx)(u.Button,{onClick:()=>Kt(!1),variant:`base-secondary`,children:`取消`})]})]})})]});function fi(){let e={formFields:J?.fields??[],memberName:e=>P.find(t=>t.memberId===e&&!t.unresolved)?.displayName??null,orgUnits:F,positions:I};return(0,d.jsx)(u.Modal,{cancelText:`關閉`,confirmText:`執行試跑`,loading:bt,modalType:`standard`,onCancel:Nr,onClose:Nr,onConfirm:()=>void Fr(),open:dt,showModalFooter:!0,showModalHeader:!0,size:`wide`,supportingText:`使用 ${un} 與範例表單資料模擬目前畫布流程,不會建立案件。`,title:`試跑流程`,children:(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsx)(i.t,{label:`表單資料 JSON`,name:`dryRunFormDataJson`,required:!0,children:(0,d.jsx)(u.Textarea,{onChange:e=>Pt(e.target.value),resize:`vertical`,rows:8,value:Ct})}),Lt?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:Lt}):null,Ft?(0,d.jsxs)(`div`,{style:Dt,children:[(0,d.jsx)(u.Typography,{color:Ft.valid?`text-success`:`text-error`,variant:`label-primary-highlight`,children:Ft.valid?`試跑通過`:`試跑失敗`}),Ft.errors.map(e=>(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:e},e)),Ft.steps.map(t=>(0,d.jsxs)(`div`,{style:Ot,children:[(0,d.jsxs)(u.Typography,{variant:`label-primary-highlight`,children:[t.nodeLabel,` · `,_r(t.status)]}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[vr(t.nodeType),t.assigneeMemberId?` · 處理者:${et(t.assigneeMemberId,e)}`:``,t.edgeLabel?` · 來源線段:${t.edgeLabel}`:``]}),t.edgeReason?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:t.edgeReason}):null,t.entryCondition?(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`進入條件:`,t.entryConditionMatched?`符合`:`不符合`,` ·`,` `,t.entryCondition]}):null,(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:t.message}),(t.status===`SKIPPED`?[]:zr(D,t.nodeId,zt)).map(e=>(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`將送出 Webhook:`,e.label]},e.key))]},t.id))]}):null]})})}function pi(e){return(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:`節點屬性`}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[Jt[e.type],` · `,e.id]}),(0,d.jsx)(i.t,{label:`顯示名稱`,name:`nodeLabel`,required:!0,children:(0,d.jsx)(u.Input,{onChange:e=>$r(e.target.value),value:e.data.label,variant:`base`})}),e.type===`startEvent`?mi():null,e.type===`startEvent`?null:hi(e),e.type===`userTask`?gi(e):null,e.type===`serviceTask`?_i(e):null]})}function mi(){let e=W.mode===`CUSTOM`?[...cn,ln]:[...cn],t=W.mode===`ORG_UNIT`||W.mode===`ORG_UNIT_POSITION`?Cr(F,W.orgUnitId??``):null,n=W.mode===`ORG_UNIT_POSITION`?wr(I,W.positionId??``):null,r=W.mode===`ORG_UNIT_POSITION`?Ar({includeDescendants:!!W.includeDescendants,memberships:st,orgUnitId:W.orgUnitId??``,orgUnits:F,positions:I}):[];return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{hintText:W.mode===`CUSTOM`?`這是舊版表達式規則;切換成標準選項後會改由 UI 管理。`:void 0,label:`發起權限`,name:`initiatorPolicyMode`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>{if(e?.id===`CUSTOM`){_e(null),ye(null);return}let t=nr(e?.id??null),n=cr(t);_e(t===`ALL`?null:t),ye(t===`ALL`?null:n),je(or(n,F))},options:e,placeholder:`選擇誰可以發起`,value:K(e,W.mode)})}),W.mode===`ORG_UNIT`||W.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`組織`,name:`initiatorOrgUnitId`,required:!0,children:(0,d.jsx)(o.n,{name:`initiatorOrgUnitId`,onChange:e=>si({...W,orgUnitId:e?.id??``,positionId:``,value:e?.id??``}),orgUnits:F,placeholder:`選擇組織`,value:t})}):null,W.mode===`ORG_UNIT`||W.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`包含下層`,name:`initiatorIncludeDescendants`,children:(0,d.jsx)(u.Toggle,{checked:!!W.includeDescendants,onChange:e=>si({...W,includeDescendants:e.target.checked,...W.mode===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,W.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`職位`,name:`initiatorPositionId`,required:!0,children:(0,d.jsx)(o.r,{disabled:!W.orgUnitId?.trim(),name:`initiatorPositionId`,onChange:e=>si({...W,positionId:e?.id??``}),placeholder:W.orgUnitId?.trim()?`選擇職位`:`請先選擇組織`,positions:r,value:n})}):null]})}function hi(e){let t=D.edges.filter(t=>t.target===e.id).length,n=t<2,r=n?`AND`:e.data.triggerMode??`AND`;return(0,d.jsx)(i.t,{hintText:n?`需要至少兩條前置連線,才可切換為任一前置完成。`:t>1?`${t} 條前置連線會依此規則觸發。`:`只有一條前置連線時,兩種設定效果相同。`,label:`前置條件`,name:`triggerMode`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>n?void 0:ci(Fn(e?.id??null)),options:[...Zt],readOnly:n,value:K(Zt,r)})})}function gi(e){let t=e.data.approverResolver,n=Xn(t.type),r=t.type===`DIRECT`?t.memberIds.map(e=>Sr(P,e)):[],a=t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?Cr(F,t.orgUnitId):null,s=t.type===`POSITION`||t.type===`ORG_UNIT_POSITION`?wr(I,t.positionId):null,c=t.type===`ORG_UNIT_POSITION`?Ar({includeDescendants:!!t.includeDescendants,memberships:st,orgUnitId:t.orgUnitId,orgUnits:F,positions:I}):[],l=t.type===`DYNAMIC_FORM`?ct(J,t.formPath):null,f=t.type===`ORG_MANAGER`?er(t.levelsUp):B[0],p=t.type===`ORG_MANAGER`||t.type===`ORG_MANAGER_CHAIN`||t.type===`ORG_UNIT_MANAGER`?t.fallback??{type:`NONE`}:{type:`NONE`},m=(0,ne.readUnsupportedApproverFallbackType)(p),h=m===null?nn:[...nn,rn],g=t.type===`ORG_MANAGER_CHAIN`?Ee(I,t.minPositionLevel):[],_=p.type===`DIRECT`&&p.memberId?Sr(P,p.memberId):null,v=p.type===`POSITION`?wr(I,p.positionId):null,ee=e.data.returnBehavior.resubmitStrategy??`RESTART`,y=e.data.sla??null,b=e.data.excludeInitiator??null,x=y?(0,S.readSlaDurationParts)(y.duration):null,te=x?.unit??`DAY`,oe=Wn(y?.warningAt??null),se=er(y?.escalateLevelsUp??1),ce=Ln(e.data.decisionPolicy),C=zn(e.data.decisionPolicy);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{label:`簽核來源`,name:`approverResolverType`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>$(Zn(e?.id??null,I)),options:[...en],value:K(en,n)})}),t.type===`DIRECT`?(0,d.jsx)(i.t,{hintText:ie(e.data.decisionPolicy),label:`簽核者`,name:`memberId`,required:!0,children:(0,d.jsx)(u.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-search`,spellCheck:!1},loading:Xe,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>$({memberIds:e.map(e=>e.id),type:`DIRECT`}),onSearch:Q,onVisibilityChange:e=>{e&&(nt([]),Q(``))},options:[...Mr(r,tt)],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:r})}):null,t.type===`DYNAMIC_FORM`?(0,d.jsx)(i.t,{hintText:l?.problem??`簽核人取自申請人送出表單時在該欄位選的人員。`,label:`表單欄位`,name:`approverFormPath`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>$({formPath:e?.id??``,type:`DYNAMIC_FORM`}),options:[...l?.options??[]],placeholder:`選擇人員選擇欄位`,value:l?.selected??void 0})}):null,t.type===`ORG_MANAGER`?(0,d.jsx)(i.t,{hintText:`依發起人的有效會員歸屬與主管解析規則決定簽核人。`,label:`主管層級`,name:`managerLevelsUp`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>$({baseFromInitiator:!0,...t.fallback?{fallback:t.fallback}:{},levelsUp:tr(e?.id??null).value,type:`ORG_MANAGER`}),options:[...B],value:f})}):null,t.type===`ORG_MANAGER_CHAIN`?(0,d.jsx)(i.t,{hintText:`從發起人的直屬主管開始往上,職等比前一位高的主管依序加入,簽到職等達此值的主管為止。沒有職位的主管會略過。`,label:`簽到職等`,name:`minPositionLevel`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>$({...t,minPositionLevel:Number(e?.id??t.minPositionLevel)}),options:[...g],value:K(g,String(t.minPositionLevel))})}):null,t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{hintText:t.type===`ORG_UNIT_MANAGER`?`依指定組織或其上層的主管解析規則決定簽核人。`:`依指定組織目前有效會員歸屬建立候選簽核人。`,label:`組織`,name:`orgUnitId`,required:!0,children:(0,d.jsx)(o.n,{name:`orgUnitId`,onChange:e=>$(t.type===`ORG_UNIT_MEMBER`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,type:`ORG_UNIT_MEMBER`}:t.type===`ORG_UNIT_POSITION`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,positionId:``,type:`ORG_UNIT_POSITION`}:{fallback:t.fallback,orgUnitId:e?.id??``,type:`ORG_UNIT_MANAGER`}),orgUnits:F,placeholder:`選擇組織`,value:a})}):null,t.type===`ORG_MANAGER`||t.type===`ORG_MANAGER_CHAIN`||t.type===`ORG_UNIT_MANAGER`?(0,d.jsxs)(d.Fragment,{children:[t.type===`ORG_MANAGER_CHAIN`?null:(0,d.jsx)(i.t,{hintText:`開啟後只取離該員最近一層的主管規則;掛在上層單位、涵蓋範圍較大的規則不會再一併加入簽核人。`,label:`只取最近一層主管`,name:`preferClosestOrgUnit`,children:(0,d.jsx)(u.Toggle,{checked:!!t.preferClosestOrgUnit,inputProps:{id:`preferClosestOrgUnit`,name:`preferClosestOrgUnit`},onChange:e=>$({...t,preferClosestOrgUnit:e.target.checked})})}),(0,d.jsx)(i.t,{hintText:m===null?t.type===`ORG_MANAGER_CHAIN`?`預設會停止流程並提示;若設定固定人,主管鏈在達到簽核職等前就結束時,會再加上該會員作為最後一關。`:`預設會停止流程並提示;若設定固定人,找不到主管時會改派給該會員。`:`此改派設定來自較新版本的 BPMCore,本版本無法執行也無法編輯;請升級後再編輯。這裡選擇其他模式會覆寫原設定。`,label:`無主管時`,name:`approverFallbackMode`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>{e?.id!==`UNSUPPORTED`&&$($n(t,Qn(e?.id??null)))},options:[...h],value:m===null?K(nn,p.type):rn})}),p.type===`DIRECT`?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{label:`改派人員`,name:`approverFallbackMemberId`,required:!0,children:(0,d.jsx)(u.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-fallback-search`,spellCheck:!1},loading:Xe,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>$($n(t,{allowInitiatorSelfApproval:p.allowInitiatorSelfApproval,memberId:e?.id??``,type:`DIRECT`})),onSearch:Q,onVisibilityChange:e=>{e&&(nt([]),Q(``))},options:[...Mr(tt,_?[_]:[])],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:_})}),(0,d.jsx)(i.t,{hintText:`預設禁止申請人簽自己的案件;只有此流程允許自簽時才開啟。`,label:`允許自簽`,name:`allowInitiatorSelfApproval`,children:(0,d.jsx)(u.Toggle,{checked:!!p.allowInitiatorSelfApproval,inputProps:{id:`allowInitiatorSelfApproval`,name:`allowInitiatorSelfApproval`},onChange:e=>$($n(t,{allowInitiatorSelfApproval:e.target.checked,memberId:p.memberId,type:`DIRECT`}))})})]}):null,p.type===`POSITION`?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{hintText:`指派給目前有效歸屬中擁有此職位的會員;主要歸屬優先。多人時全部成為簽核人,依上方的決策政策處理。`,label:`改派職位`,name:`approverFallbackPositionId`,required:!0,children:(0,d.jsx)(o.r,{name:`approverFallbackPositionId`,onChange:e=>$($n(t,{allowInitiatorSelfApproval:p.allowInitiatorSelfApproval,positionId:e?.id??``,type:`POSITION`})),placeholder:`選擇職位`,positions:I,value:v})}),(0,d.jsx)(i.t,{hintText:`預設禁止申請人簽自己的案件;只有此流程允許自簽時才開啟。`,label:`允許自簽`,name:`allowInitiatorSelfApproval`,children:(0,d.jsx)(u.Toggle,{checked:!!p.allowInitiatorSelfApproval,inputProps:{id:`allowInitiatorSelfApproval`,name:`allowInitiatorSelfApproval`},onChange:e=>$($n(t,{allowInitiatorSelfApproval:e.target.checked,positionId:p.positionId,type:`POSITION`}))})})]}):null]}):null,t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`包含下層`,name:`includeDescendants`,children:(0,d.jsx)(u.Toggle,{checked:!!t.includeDescendants,inputProps:{id:`includeDescendants`,name:`includeDescendants`},onChange:e=>$({...t,includeDescendants:e.target.checked,...t.type===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,t.type===`POSITION`?(0,d.jsx)(i.t,{hintText:`指派給目前有效歸屬中擁有此職位的會員;主要歸屬優先。`,label:`職位`,name:`positionId`,required:!0,children:(0,d.jsx)(o.r,{name:`positionId`,onChange:e=>$({positionId:e?.id??``,type:`POSITION`}),placeholder:`選擇職位`,positions:I,value:s})}):null,t.type===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{hintText:`只納入指定組織範圍內擁有此職位的有效會員。`,label:`職位`,name:`orgUnitPositionId`,required:!0,children:(0,d.jsx)(o.r,{disabled:!t.orgUnitId.trim(),name:`orgUnitPositionId`,onChange:e=>$({includeDescendants:t.includeDescendants,orgUnitId:t.orgUnitId,positionId:e?.id??``,type:`ORG_UNIT_POSITION`}),placeholder:t.orgUnitId.trim()?`選擇職位`:`請先選擇組織`,positions:c,value:s})}):null,(0,d.jsx)(i.t,{hintText:`決定這一關要幾位簽核者同意才會通過;單人簽核與任一人同意的效果完全相同,皆為其中一人同意即通過。`,label:`決策方式`,name:`decisionPolicy`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:t=>ii(Rn(t?.id??null,e.data.decisionPolicy)),options:[...re.filter(e=>t.type!==`ORG_MANAGER_CHAIN`||e.id===`SEQUENTIAL`||e.id===`PARALLEL_ALL`)],value:ae(ce)})}),ce===`QUORUM`?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{label:`門檻計算方式`,name:`quorumThresholdType`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ii({threshold:C.threshold,thresholdType:Bn(e?.id??null),type:`QUORUM`}),options:[...tn],value:K(tn,C.thresholdType)})}),(0,d.jsx)(i.t,{hintText:C.thresholdType===`PERCENTAGE`?`達到簽核者總數的這個百分比即通過,換算人數時無條件進位;超過 100 的輸入會自動夾至 100。`:`達到這個同意人數即通過;門檻超過實際簽核者人數時,這一關將永遠無法通過,請勿設定超過實際簽核者人數。`,label:C.thresholdType===`PERCENTAGE`?`門檻百分比`:`門檻人數`,name:`quorumThreshold`,required:!0,children:(0,d.jsx)(u.Input,{id:`quorumThreshold`,inputProps:C.thresholdType===`PERCENTAGE`?{max:100,min:1}:{min:1},inputType:`number`,name:`quorumThreshold`,onChange:e=>ii({threshold:(0,S.composeQuorumThreshold)(Number(e.target.value),C.thresholdType),thresholdType:C.thresholdType,type:`QUORUM`}),value:String(C.threshold),variant:`base`})})]}):null,e.data.returnBehavior.allowReturn?(0,d.jsx)(i.t,{hintText:`退回發起人後,重新送出時要從流程開始重跑,或直接回到退回的簽核節點。`,label:`重送策略`,name:`returnResubmitStrategy`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ei(In(e?.id??null)),options:[...Qt],value:K(Qt,ee)})}):null,e.data.returnBehavior.allowReturn?(0,d.jsx)(i.t,{hintText:`開啟後,簽核者按下退回時必須填寫意見,未填寫會被擋下。`,label:`退回時意見必填`,name:`returnRequireComment`,children:(0,d.jsx)(u.Toggle,{checked:e.data.returnBehavior.requireComment===!0,inputProps:{id:`returnRequireComment`,name:`returnRequireComment`},onChange:e=>ti(e.target.checked)})}):null,(0,d.jsx)(i.t,{hintText:`開啟後可設定簽核期限,逾時將依下方設定處理。`,label:`啟用時效`,name:`slaEnabled`,children:(0,d.jsx)(u.Toggle,{checked:!!y,inputProps:{id:`slaEnabled`,name:`slaEnabled`},onChange:e=>ni(e.target.checked?S.DEFAULT_SLA_CONFIG:null)})}),y&&!x?(0,d.jsx)(i.t,{hintText:`此期限混用了日與時,無法在表單中編輯。請改以單一單位設定,或透過 API 維護。`,label:`時效期限`,name:`slaDurationRaw`,children:(0,d.jsx)(u.Input,{disabled:!0,value:y.duration,variant:`base`})}):null,y&&x?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{label:`時效期限`,name:`slaDurationValue`,required:!0,children:(0,d.jsx)(u.Input,{id:`slaDurationValue`,inputProps:{min:1},inputType:`number`,name:`slaDurationValue`,onChange:e=>ni(Kn(y,{unit:te,value:Number(e.target.value)})),value:String(x.value),variant:`base`})}),(0,d.jsx)(i.t,{label:`期限單位`,name:`slaDurationUnit`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ni(Kn(y,{unit:Vn(e?.id??null),value:x.value})),options:[...S.SLA_DURATION_UNIT_OPTIONS],value:K(S.SLA_DURATION_UNIT_OPTIONS,te)})})]}):null,y&&te===`DAY`?(0,d.jsx)(i.t,{hintText:`工作日會跳過週末與行事曆上的假日,補班日仍計為工作日;行事曆由系統管理者設定。`,label:`計算方式`,name:`slaCalendar`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ni({...y,calendar:Hn(e?.id??null)}),options:[...S.SLA_CALENDAR_MODE_OPTIONS],value:K(S.SLA_CALENDAR_MODE_OPTIONS,y.calendar??`CALENDAR`)})}):null,y?(0,d.jsx)(i.t,{label:`逾時處理`,name:`slaOnTimeout`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ni(qn(y,Un(e?.id??null))),options:[...S.SLA_TIMEOUT_ACTION_OPTIONS],value:K(S.SLA_TIMEOUT_ACTION_OPTIONS,y.onTimeout)})}):null,y?.onTimeout===`ESCALATE`?(0,d.jsx)(i.t,{hintText:`逾時後改派給簽核者的上層主管,只會升級一次。`,label:`升級層級`,name:`slaEscalateLevelsUp`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ni({...y,escalateLevelsUp:tr(e?.id??null).value}),options:[...B],value:se})}):null,y?(0,d.jsx)(i.t,{hintText:`在期限到達前先送出一次提醒。`,label:`預警提醒`,name:`slaWarningAt`,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ni(Jn(y,Gn(e?.id??null).value)),options:[...$t],value:oe})}):null,(0,d.jsx)(i.t,{hintText:`關閉後,簽核者在此關卡看不到「拒絕」按鈕。`,label:`允許拒絕`,name:`allowReject`,children:(0,d.jsx)(u.Toggle,{checked:e.data.allowReject,inputProps:{id:`allowReject`,name:`allowReject`},onChange:e=>ai({allowReject:e.target.checked})})}),(0,d.jsx)(i.t,{hintText:`關閉後,簽核者無法把此關卡的任務轉派給其他人。`,label:`允許轉派`,name:`allowTransfer`,children:(0,d.jsx)(u.Toggle,{checked:e.data.allowTransfer,inputProps:{id:`allowTransfer`,name:`allowTransfer`},onChange:e=>ai({allowTransfer:e.target.checked})})}),(0,d.jsx)(i.t,{hintText:`開啟後,簽核者可在此關卡臨時加入其他簽核人;會簽為平行處理,加簽則需等加入者簽完才往下。`,label:`允許加簽`,name:`allowAddSigner`,children:(0,d.jsx)(u.Toggle,{checked:e.data.allowAddSigner,inputProps:{id:`allowAddSigner`,name:`allowAddSigner`},onChange:e=>ai({allowAddSigner:e.target.checked})})}),(0,d.jsx)(i.t,{hintText:`開啟後,申請人本人(含其代理人)不會成為此關的簽核人,也不能被轉簽或加簽到此關。`,label:`申請人不可簽核自己的單`,name:`excludeInitiator`,children:(0,d.jsx)(u.Toggle,{checked:!!b,inputProps:{id:`excludeInitiator`,name:`excludeInitiator`},onChange:e=>ri(e.target.checked?on:null)})}),b?(0,d.jsx)(i.t,{label:`排除後沒有簽核人時`,name:`excludeInitiatorWhenEmpty`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>ri({whenEmpty:K(an,e?.id??null)?.id??on.whenEmpty}),options:[...an],value:K(an,b.whenEmpty)})}):null]})}function _i(e){let t=e.data.action,n=Qr(t).map(e=>Sr(P,e)),r=t.type===`NOTIFY`&&t.recipients.type!==`DIRECT`?Ir(t.recipients,P,F,I,J):null;function a(e){let n={memberIds:[...e],type:`DIRECT`};oi(t.type===`NOTIFY`?{...t,recipients:n}:{channels:[`IN_APP`],recipients:n,type:`NOTIFY`})}function o(e){t.type===`NOTIFY`&&oi({...t,webhooks:e})}return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{hintText:r?`目前知會對象為「${r}」;在此選擇成員會改為指定成員。`:t.type===`NOTIFY`?`可只設定 Webhook,不指定知會對象。`:void 0,label:`知會對象`,name:`notifyMemberIds`,children:(0,d.jsx)(u.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,loading:Xe,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>a(e.map(e=>e.id)),onSearch:Q,onVisibilityChange:e=>{e&&(nt([]),Q(``))},options:[...Mr(n,tt)],overflowStrategy:`wrap`,placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:[...n]})}),t.type===`NOTIFY`&&!Pe(t.webhooks)?(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`這個節點的 Webhook 設定格式錯誤,無法在此編輯。清除後可重新新增。`}),(0,d.jsx)(`div`,{children:(0,d.jsx)(u.Button,{onClick:()=>o([]),variant:`destructive-secondary`,children:`清除 Webhook 設定`})})]}):null,t.type===`NOTIFY`&&Pe(t.webhooks)?(0,d.jsx)(Ge,{catalog:zt,catalogState:Vt,formFields:J?.fields??null,onChange:o,targets:(0,S.readNotifyWebhookTargets)(t)}):null]})}function vi(e){return(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:`已選取線段`}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[`已選取 `,e.length,` 條線段,可使用 Delete 或控制面板刪除。`]})]})}function yi(e){let t=Xr(e,D.nodes);return(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:t?`條件設定`:`線段屬性`}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[e.source,` → `,e.target]}),t?xi(e):(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`這條線會直接把流程送到下一個節點。`})]})}function bi(e){return!e||!Xr(e,D.nodes)?null:(0,d.jsx)(u.Modal,{cancelText:`取消`,confirmButtonProps:{disabled:!e.data.isDefault&&!e.data.condition},confirmText:`完成`,modalType:`standard`,onCancel:Yr,onClose:Yr,onConfirm:Yr,open:!!Oe,showModalFooter:!0,showModalHeader:!0,size:`regular`,supportingText:`條件分流的輸出連線需要指定條件,條件會直接顯示在線上。`,title:`條件設定`,children:xi(e)})}function xi(e){let t=Jr(e,D.nodes),n=Wr(G?.schema??null),r=Gr(G?.schema??null,e.data.conditionFieldKey??null),a=(0,S.readConditionOperatorOptionsForField)(r),o=Kr(r),s=K(a,e.data.conditionOperator??null),c=!e.data.isDefault&&!e.data.condition;return(0,d.jsxs)(`div`,{style:Et,children:[(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[`畫布上的這條線目前會顯示「`,(0,d.jsx)(`span`,{style:{color:c?St:void 0},children:t??`請設定條件`}),`」。`]}),(0,d.jsx)(u.Toggle,{checked:!!e.data.isDefault,label:`其他情況走這條`,onChange:t=>li(e.id,t.target.checked)}),e.data.isDefault?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`其他條件都不符合時,流程會走這條線。`}):(0,d.jsxs)(d.Fragment,{children:[G?null:(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`請先綁定表單版本,才能選擇條件欄位。`}),(0,d.jsx)(i.t,{label:`條件欄位`,name:`edgeConditionField`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:t=>ui({edgeId:e.id,fieldKey:t?.id??null,operator:null,value:null}),options:[...n],placeholder:`選擇條件欄位`,value:K(n,e.data.conditionFieldKey??null)})}),(0,d.jsx)(i.t,{label:`條件判斷`,name:`edgeConditionOperator`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:t=>ui({edgeId:e.id,operator:(0,S.readConditionOperator)(t?.id??null),value:null}),options:[...a],placeholder:`選擇判斷方式`,value:s})}),s&&qr(s.id)?(0,d.jsx)(i.t,{label:`條件值`,name:`edgeConditionValue`,required:!0,children:o.length>0?(0,d.jsx)(u.Select,{clearable:!1,onChange:t=>ui({edgeId:e.id,value:t?.id??null}),options:[...o],placeholder:`選擇條件值`,value:K(o,e.data.conditionValue??null)}):(0,d.jsx)(u.Input,{onChange:t=>ui({edgeId:e.id,value:t.target.value}),placeholder:`輸入要比對的值`,value:e.data.conditionValue??``,variant:`base`})}):null]})]})}}function yn({onApplyAutoLayout:e}){function t(){e()}return(0,d.jsx)(y.Panel,{position:`top-right`,children:(0,d.jsx)(u.Button,{icon:m.DotGridIcon,iconType:`leading`,onClick:t,size:`sub`,variant:`base-secondary`,children:`自動排版`})})}function V({data:e,selected:t,type:n}){let r=e.approverLines??[e.approverSummary??e.label],i=bn(e),a=H(n,t);return(0,d.jsxs)(`div`,{style:a,children:[Sn(e),(0,d.jsx)(`div`,{style:qt,children:r.map((e,t)=>(0,d.jsx)(u.Typography,{component:`span`,ellipsis:!0,style:L,title:e,variant:`label-primary`,children:e},`${e}_${t}`))}),(0,d.jsx)(u.Typography,{color:`text-neutral`,component:`span`,ellipsis:!0,style:L,title:i,variant:`caption`,children:i})]})}function bn(e){return e.nodeKind===`startEvent`?e.initiatorPolicySummary??`所有人`:e.approverSummary||e.approverLines?e.label:e.nodeKind===`exclusiveGateway`?`條件在線上`:e.nodeKind===`parallelGateway`?`多條路徑同時進行`:Jt[e.nodeKind]}function H(e,t){let n=xn(e);return t?{...n,border:`1px solid var(--mzn-color-primary, #0057ff)`,boxShadow:Ft}:n}function xn(e){return e===`exclusiveGateway`?Ht:e===`parallelGateway`?Ut:e===`startEvent`?Gt:e===`endEvent`?Kt:e===`userTask`?Wt:Pt}function Sn(e){return!e.hasInput&&e.hasOutput?(0,d.jsx)(y.Handle,{id:z,position:y.Position.Right,type:`source`}):e.hasInput&&!e.hasOutput?(0,d.jsx)(y.Handle,{id:R,position:y.Position.Left,type:`target`}):!e.hasInput&&!e.hasOutput?null:[(0,d.jsx)(y.Handle,{id:R,position:y.Position.Left,type:`target`},`target`),(0,d.jsx)(y.Handle,{id:z,position:y.Position.Right,type:`source`},`source`)]}function Cn(e,t,n,r,i,a,o){let s=U(e);return{data:{approverLines:Lr(e,t,n,r,o),approverSummary:Fr(e,t,n,r,o),hasInput:Y(e),hasOutput:X(e),initiatorPolicySummary:e.type===`startEvent`?sr(a,n,r):null,label:e.data.label,nodeKind:e.type},height:s.height,handles:wn(e),id:e.id,initialHeight:s.height,initialWidth:s.width,position:e.position,selected:i,sourcePosition:y.Position.Right,targetPosition:y.Position.Left,type:e.type,width:s.width}}function U(e){return e.type===`exclusiveGateway`||e.type===`parallelGateway`?{height:zt,width:Bt}:e.type===`serviceTask`?{height:It+(Rr(e.data.action)-1)*Rt,width:Lt}:{height:It,width:Lt}}function wn(e){let t=U(e);return[...Y(e)?[Tn(t)]:[],...X(e)?[En(t)]:[]]}function Tn({height:e}){let t=e/2-9/2;return{height:9,id:R,position:y.Position.Left,type:`target`,width:9,x:-9/2,y:t}}function En({height:e,width:t}){let n=e/2-9/2;return{height:9,id:z,position:y.Position.Right,type:`source`,width:9,x:t-9/2,y:n}}function Dn(e,t,n){let r=Jr(e,t),i=Xr(e,t),a=i&&!e.data.isDefault&&!e.data.condition,o=a?St:i?bt:`#475569`,s=a?`#fef2f2`:i?`#eff6ff`:`#ffffff`,c=a?St:i?bt:xt;return{className:n?`workflow-edge--selected`:void 0,data:e.data,id:e.id,label:r,labelBgBorderRadius:6,labelBgPadding:[8,4],labelBgStyle:{fill:s,stroke:c,strokeWidth:1},labelShowBg:!!r,labelStyle:{fill:o,fontSize:12,fontWeight:600},selected:n,source:e.source,sourceHandle:e.sourceHandle,style:{filter:n?Ct:void 0,opacity:1,stroke:xt,strokeOpacity:1,strokeWidth:1.5},target:e.target,targetHandle:e.targetHandle,type:e.type??`smoothstep`}}function W(e,t){return e.type===`startEvent`?e:(e.type===`endEvent`||e.type===`userTask`||e.type===`serviceTask`||e.type,{...e,data:{...e.data,triggerMode:t}})}function On(e){return jn(G(An(kn(e))))}function kn(e){let t=e.edges.map(e=>{let t=e.data??{};return e.data===t?e:{...e,data:t}});return t.some((t,n)=>t!==e.edges[n])?{...e,edges:t}:e}function G(e){let t=e.nodes.map(e=>{if(e.type!==`userTask`)return e;let t=e.data.allowAddSigner??!1,n=e.data.allowReject??!0,r=e.data.allowTransfer??!0,i=!e.data.decisionPolicy;return e.data.allowAddSigner===t&&e.data.allowReject===n&&e.data.allowTransfer===r&&!i?e:{...e,data:{...e.data,allowAddSigner:t,allowReject:n,allowTransfer:r,decisionPolicy:e.data.decisionPolicy??{type:`SINGLE`}}}});return t.some((t,n)=>t!==e.nodes[n])?{...e,nodes:t}:e}function An(e){let t=new Set(e.nodes.filter(e=>fr(e)).map(e=>e.id)),n=e.edges.filter(e=>!t.has(e.source));return n.length===e.edges.length?e:{...e,edges:n}}function jn(e){let t=e.edges.reduce((e,t)=>({...e,[t.target]:(e[t.target]??0)+1}),{}),n=e.nodes.map(e=>e.type===`startEvent`?e:(t[e.id]??0)<2&&e.data.triggerMode!==`AND`?W(e,`AND`):e);return n.some((t,n)=>t!==e.nodes[n])?{...e,nodes:n}:e}function Mn(){return{edges:[],meta:{schemaVersion:1},nodes:[{data:{label:`開始`},id:`start`,position:{x:80,y:160},type:`startEvent`},{data:{endState:`APPROVED`,label:`完成`,triggerMode:`AND`},id:`end`,position:{x:560,y:160},type:`endEvent`}]}}function Nn(e){return e.edges.length===0&&e.nodes.length===2&&e.nodes.some(e=>e.type===`startEvent`)&&e.nodes.some(e=>e.type===`endEvent`)}function Pn(e){let t=new b.graphlib.Graph;return t.setDefaultEdgeLabel(()=>({})),t.setGraph({rankdir:`LR`,ranksep:120}),e.nodes.forEach(e=>{t.setNode(e.id,U(e))}),e.edges.forEach(e=>{t.setEdge(e.source,e.target)}),b.layout(t),{...e,nodes:e.nodes.map(e=>{let n=t.node(e.id);return n?{...e,position:{x:n.x-U(e).width/2,y:n.y-U(e).height/2}}:e})}}function K(e,t){return t?e.find(e=>e.id===t)??null:null}function Fn(e){return e===`OR`?`OR`:`AND`}function In(e){return e===`FROM_RETURN_POINT`?`FROM_RETURN_POINT`:`RESTART`}function Ln(e){return e?.type??`SINGLE`}function Rn(e,t){return e===`QUORUM`?t?.type===`QUORUM`?t:{threshold:S.DEFAULT_QUORUM_THRESHOLD,thresholdType:`COUNT`,type:`QUORUM`}:e===`PARALLEL_ALL`||e===`PARALLEL_ANY`||e===`SEQUENTIAL`?{type:e}:{type:`SINGLE`}}function zn(e){return e?.type===`QUORUM`?{threshold:Number.isFinite(e.threshold)?e.threshold:S.DEFAULT_QUORUM_THRESHOLD,thresholdType:Bn(e.thresholdType??null)}:{threshold:S.DEFAULT_QUORUM_THRESHOLD,thresholdType:`COUNT`}}function Bn(e){return e===`PERCENTAGE`?`PERCENTAGE`:`COUNT`}function Vn(e){return e===`HOUR`?`HOUR`:`DAY`}function Hn(e){return e===`BUSINESS_DAY`?`BUSINESS_DAY`:`CALENDAR`}function Un(e){return S.SLA_TIMEOUT_ACTION_OPTIONS.find(t=>t.id===e)?.id??`REMIND`}function Wn(e){return $t.find(t=>t.value===e)??$t[0]}function Gn(e){return $t.find(t=>t.id===e)??$t[0]}function Kn(e,t){let n=Number.isFinite(t.value)?Math.trunc(t.value):1,r=(0,S.composeSlaDuration)({unit:t.unit,value:n});return{...e,calendar:t.unit===`DAY`?e.calendar??`CALENDAR`:`CALENDAR`,duration:r}}function qn(e,t){return t===`ESCALATE`?{...e,escalateLevelsUp:e.escalateLevelsUp??1,onTimeout:t}:{...Yn(e,`escalateLevelsUp`),onTimeout:t}}function Jn(e,t){return t===null?Yn(e,`warningAt`):{...e,warningAt:t}}function Yn(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function Xn(e){return e===`DYNAMIC_FORM`||e===`ORG_MANAGER`||e===`ORG_MANAGER_CHAIN`||e===`ORG_UNIT_MANAGER`||e===`ORG_UNIT_MEMBER`||e===`ORG_UNIT_POSITION`||e===`POSITION`?e:`DIRECT`}function Zn(e,t){let n=Xn(e??`DIRECT`);return n===`DYNAMIC_FORM`?{formPath:``,type:`DYNAMIC_FORM`}:n===`ORG_MANAGER`?{baseFromInitiator:!0,levelsUp:1,type:`ORG_MANAGER`}:n===`ORG_MANAGER_CHAIN`?{minPositionLevel:k(t),type:`ORG_MANAGER_CHAIN`}:n===`ORG_UNIT_MANAGER`?{orgUnitId:``,type:`ORG_UNIT_MANAGER`}:n===`ORG_UNIT_MEMBER`?{includeDescendants:!1,orgUnitId:``,type:`ORG_UNIT_MEMBER`}:n===`ORG_UNIT_POSITION`?{includeDescendants:!1,orgUnitId:``,positionId:``,type:`ORG_UNIT_POSITION`}:n===`POSITION`?{positionId:``,type:`POSITION`}:{memberIds:[],type:`DIRECT`}}function q(e){return e===`DIRECT`||e===`POSITION`?e:`NONE`}function Qn(e){let t=q(e);return t===`DIRECT`?{memberId:``,type:`DIRECT`}:t===`POSITION`?{positionId:``,type:`POSITION`}:{type:`NONE`}}function $n(e,t){return e.type===`ORG_MANAGER`||e.type===`ORG_MANAGER_CHAIN`||e.type===`ORG_UNIT_MANAGER`?{...e,fallback:t}:e}function er(e){return B.find(t=>t.value===e)??B[0]}function tr(e){return B.find(t=>t.id===e)??B[0]}function nr(e){return e===`ORG_UNIT`||e===`ORG_UNIT_POSITION`||e===`NONE`?e:`ALL`}function J(e){let t=e?.trim();if(!t)return{mode:`ALL`,value:``};let n=ar(t,/"([^"]+)" in subject\.orgUnitIds/gu),r=ar(t,/"([^"]+)" in subject\.positionIds/gu);return n.length>0&&r.length>0?{includeDescendants:n.length>1,mode:`ORG_UNIT_POSITION`,orgUnitId:n[0],positionId:r[0],value:n[0]??``}:n.length>0?{includeDescendants:n.length>1,mode:`ORG_UNIT`,orgUnitId:n[0],value:n[0]??``}:{mode:`CUSTOM`,value:t}}function rr(e,t){let n=J(e);return!t||t===`ALL`||t===`NONE`?t===`ALL`||t===`NONE`?{mode:t,value:``}:n:n.mode===t?n:cr(t)}function ir(e){return e.mode===`NONE`?`發起權限需要選擇誰可以發起。`:(e.mode===`ORG_UNIT`||e.mode===`ORG_UNIT_POSITION`)&&!e.orgUnitId?.trim()?`指定組織發起時,需要選擇組織。`:e.mode===`ORG_UNIT_POSITION`&&!e.positionId?.trim()?`指定組織職位發起時,需要選擇職位。`:null}function ar(e,t){return[...e.matchAll(t)].map(e=>e[1]).filter(e=>!!e)}function or(e,t){if(e.mode===`ALL`||e.mode===`NONE`)return null;let n=e.orgUnitId?.trim()??``;if(!n)return null;let r=jr(t,n,!!e.includeDescendants).map(e=>`${JSON.stringify(e)} in subject.orgUnitIds`).join(` || `);if(e.mode===`ORG_UNIT`)return r?`(${r})`:null;let i=e.positionId?.trim()??``;return i&&r?`(${r}) && ${JSON.stringify(i)} in subject.positionIds`:null}function sr(e,t,n){return e.mode===`NONE`?`未設定`:e.mode===`ORG_UNIT`?e.orgUnitId?`組織:${Z(t,e.orgUnitId)}`:`指定組織`:e.mode===`ORG_UNIT_POSITION`?e.orgUnitId&&e.positionId?`組織職位:${Z(t,e.orgUnitId)} / ${Q(n,e.positionId)}`:`指定組織職位`:e.mode===`CUSTOM`?`既有自訂規則`:`所有人`}function cr(e){return{includeDescendants:!0,mode:e,orgUnitId:``,positionId:``,value:``}}function lr(e,t){let n=e.source?t.find(t=>t.id===e.source)??null:null,r=e.target?t.find(t=>t.id===e.target)??null:null;return!!n&&!!r&&e.source!==e.target&&e.sourceHandle===z&&e.targetHandle===R&&!!(n&&X(n))&&!!(r&&Y(r))}function ur(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function dr(e){return e.type!==`startEvent`&&e.type!==`endEvent`}function Y(e){return e.type!==`startEvent`}function X(e){return e.type!==`endEvent`&&!fr(e)}function fr(e){return e.type===`serviceTask`&&e.data.action.type===`NOTIFY`}function pr(e){return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||!!e.closest(`[contenteditable="true"]`):!1}function mr(e){return e.map(e=>({formDefinitionId:e.formDefinitionId,formName:e.formName,id:e.id,name:dt(e.formName,e.version),schema:e.schema}))}function hr(e){let t=JSON.parse(e);if(!gr(t))throw Error(`表單資料 JSON 必須是物件。`);return t}function gr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _r(e){return e===`COMPLETED`?`完成`:e===`PASSED`?`通過`:e===`SKIPPED`?`略過`:e===`STOPPED`?`已停止`:e===`WAITING`?`將等待簽核`:e}function vr(e){return e in Jt?Jt[e]:e}function yr(e,t){return t&&!e.some(e=>e.id===t.id)?[t,...e]:e}function br(e){return e.map(e=>({displayName:e.name,email:e.email,id:e.memberId,memberId:e.memberId,name:Vr(e.name,e.email)}))}function xr(e){return{displayName:`未知會員`,email:``,id:e,memberId:e,name:`未知會員`,unresolved:!0}}function Sr(e,t){return e.find(e=>e.memberId===t)??xr(t)}function Cr(e,t){let n=e.find(e=>e.id===t);return n?o.a(n):null}function wr(e,t){let n=e.find(e=>e.id===t);return n?o.o(n):null}function Z(e,t){return Cr(e,t)?.name??`未指定組織`}function Q(e,t){return wr(e,t)?.name??`未指定職位`}function Tr(e,t){let n=Er(),r=t.filter(t=>t.memberId===e&&Dr(t,n)),i=r.reduce((e,t)=>e&&Or(e,t)<=0?e:t,null);return{customFields:{},managerMemberId:`member-002`,memberId:e,orgCode:`HQ`,orgUnitIds:kr(r.map(e=>e.orgUnitId)),positionId:i?.positionId??null,positionIds:kr(r.map(e=>e.positionId)),primaryOrgUnitId:i?.orgUnitId??null,roles:[`manager`]}}function Er(){return new Date().toISOString().slice(0,10)}function Dr(e,t){return e.effectiveFrom<=t&&(!e.effectiveTo||e.effectiveTo>=t)}function Or(e,t){return e.isPrimary===t.isPrimary?t.effectiveFrom.localeCompare(e.effectiveFrom):e.isPrimary?-1:1}function kr(e){return e.reduce((e,t)=>t&&!e.includes(t)?[...e,t]:e,[])}function Ar({includeDescendants:e,memberships:t,orgUnitId:n,orgUnits:r,positions:i}){let a=new Set(jr(r,n,e)),o=new Set(t.filter(e=>a.has(e.orgUnitId)).map(e=>e.positionId).filter(e=>!!e));return i.filter(e=>o.has(e.id))}function jr(e,t,n){let r=e.find(e=>e.id===t);return r?n?e.filter(e=>e.id===r.id||e.path.startsWith(`${r.path}.`)).map(e=>e.id):[r.id]:t.trim()?[t]:[]}function Mr(e,t){let n=new Map(t.filter(e=>!e.unresolved).map(e=>[e.memberId,e])),r=new Set(e.map(e=>e.memberId)),i=t.filter(e=>!r.has(e.memberId)),a=e.map(e=>(e.unresolved?n.get(e.memberId):null)??e);return i.length>0||a.some((t,n)=>t!==e[n])?[...a,...i]:e}function Nr(e){return e.type===`DIRECT`?e.memberIds:(e.type===`ORG_MANAGER`||e.type===`ORG_MANAGER_CHAIN`||e.type===`ORG_UNIT_MANAGER`)&&e.fallback?.type===`DIRECT`&&e.fallback.memberId?[e.fallback.memberId]:[]}function Pr(e){return[...new Set(e.nodes.flatMap(e=>e.type===`userTask`?Nr(e.data.approverResolver):e.type===`serviceTask`?Qr(e.data.action):[]))]}function Fr(e,t,n,r,i){return e.type===`userTask`?Ir(e.data.approverResolver,t,n,r,i):null}function Ir(e,t,n,r,i){return e.type===`DIRECT`?Br(e.memberIds,t,`未指定簽核者`):e.type===`ORG_MANAGER`?er(e.levelsUp).name:e.type===`ORG_MANAGER_CHAIN`?`主管鏈:簽到職等 ${e.minPositionLevel}`:e.type===`ORG_UNIT_MANAGER`?`組織主管:${Z(n,e.orgUnitId)}`:e.type===`ORG_UNIT_MEMBER`?`組織任一人:${Z(n,e.orgUnitId)}`:e.type===`ORG_UNIT_POSITION`?`組織職位:${Z(n,e.orgUnitId)} / ${Q(r,e.positionId)}`:e.type===`POSITION`?`職位:${Q(r,e.positionId)}`:e.type===`DYNAMIC_FORM`?lt(i,e.formPath):`自訂表達式`}function Lr(e,t,n,r,i){if(e.type!==`serviceTask`)return null;let a=e.data.action,o=a.type===`NOTIFY`&&a.recipients.type!==`DIRECT`?[Ir(a.recipients,t,n,r,i)]:Qr(a).map(e=>Sr(t,e).name),s=(0,S.readNotifyWebhookTargets)(a).length,c=[...o,...s?[`Webhook ${s} 個`]:[]];return c.length?c:[`未指定知會對象`]}function Rr(e){let t=e.type===`NOTIFY`&&e.recipients.type!==`DIRECT`?1:Qr(e).length,n=+!!(0,S.readNotifyWebhookTargets)(e).length;return Math.max(1,t+n)}function zr(e,t,n){let r=e.nodes.find(e=>e.id===t);return r?.type===`serviceTask`&&r.data.action.type===`NOTIFY`&&Pe(r.data.action.webhooks)?(0,S.readNotifyWebhookTargets)(r.data.action).map(e=>({key:e.id,label:Oe(n,e.endpoint)?.label??j(e.endpoint)})):[]}function Br(e,t,n){let r=e.map(e=>Sr(t,e).name);return r.length===0?n:r.length<=2?r.join(`、`):`${r.slice(0,2).join(`、`)} 等 ${r.length} 人`}function Vr(e,t){return a.t(e,t)}function Hr(e,t){let n=t?.getBoundingClientRect();if(!n||e.nodes.length===0)return null;let r=e.nodes.reduce((e,t)=>{let n=U(t);return{maxX:Math.max(e.maxX,t.position.x+n.width),maxY:Math.max(e.maxY,t.position.y+n.height),minX:Math.min(e.minX,t.position.x),minY:Math.min(e.minY,t.position.y)}},{maxX:-1/0,maxY:-1/0,minX:1/0,minY:1/0});return(0,y.getViewportForBounds)({height:r.maxY-r.minY,width:r.maxX-r.minX,x:r.minX,y:r.minY},n.width,n.height,.1,1,.2)}function Ur(e){let t=e.nodes.find(e=>e.type===`userTask`&&!!(0,S.readApproverResolverIssue)(e.data.approverResolver)),n=e.nodes.find(e=>e.type===`userTask`&&!!(0,S.readExcludeInitiatorIssue)(e.data.excludeInitiator)),r=e.nodes.map(e=>(0,S.readNotifyServiceTaskIssue)(e)).find(e=>e!==null)??null,i=e.edges.find(t=>Xr(t,e.nodes)&&!t.data.isDefault&&!t.data.condition),a=e.nodes.find(e=>e.type===`userTask`&&(0,S.isOrgManagerChainDecisionPolicyInvalid)(e.data.approverResolver,e.data.decisionPolicy));return t&&t.type===`userTask`?(0,S.readApproverResolverIssue)(t.data.approverResolver):a&&a.type===`userTask`?`簽核節點「${a.data.label}」使用「沿主管鏈簽核」時,決策方式必須是「依序簽核或全部同意」,否則任一位主管簽完就會結案。`:n&&n.type===`userTask`?(0,S.readExcludeInitiatorIssue)(n.data.excludeInitiator):r||(i?`條件分流的每條輸出連線都需要先設定條件。`:null)}function Wr(e){return e?.fields.map(e=>({fieldType:e.type,id:e.fieldKey,name:`${e.label} (${e.fieldKey})`}))??[]}function Gr(e,t){return t?e?.fields.find(e=>e.fieldKey===t)??null:null}function Kr(e){return e?e.type===`boolean`?[{id:`true`,name:`是`},{id:`false`,name:`否`}]:(0,v.isFormStaticOptionFieldDefinition)(e)?e.options.map(e=>({id:e.value,name:e.label})):[]:[]}function qr(e){return sn.includes(e)}function Jr(e,t){if(e.data.label)return e.data.label;if(Xr(e,t))return Yr(e);if(Zr(e,t))return`同時進行`}function Yr(e){return e.data.isDefault?`其他情況`:`請設定條件`}function Xr(e,t){return t.some(t=>t.id===e.source&&t.type===`exclusiveGateway`)}function Zr(e,t){return t.some(t=>t.id===e.source&&t.type===`parallelGateway`)}function Qr(e){return e.type===`NOTIFY`&&e.recipients.type===`DIRECT`?e.recipients.memberIds:[]}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return vn}});
65
+ //# sourceMappingURL=designer-CbOCuXHH.cjs.map