@rytass/bpm-core-react 0.17.4 → 0.17.5

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.
@@ -61,5 +61,5 @@ ${g.WORKFLOW_TOOLSET.map(e=>`- ${e.name}(${JSON.stringify(e.inputSchema.properti
61
61
  --xy-edge-stroke-width: 1.5px;
62
62
  }
63
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
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.readOrganizationDirectory)();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.readOrganizationDirectory)()]),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-CTXMqCD2.cjs.map