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