@rytass/bpm-core-react 0.17.5 → 0.17.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +1 -1
  3. package/dist/chunks/{FormBuilderView-aBcA-_tt.cjs → FormBuilderView-CUOyS07f.cjs} +2 -2
  4. package/dist/chunks/{FormBuilderView-aBcA-_tt.cjs.map → FormBuilderView-CUOyS07f.cjs.map} +1 -1
  5. package/dist/chunks/{FormBuilderView-BYL42M0d.js → FormBuilderView-ClLnQ1e_.js} +2 -2
  6. package/dist/chunks/{FormBuilderView-BYL42M0d.js.map → FormBuilderView-ClLnQ1e_.js.map} +1 -1
  7. package/dist/chunks/{FormRendererView-cZGOOjU5.js → FormRendererView-BsTwZkqU.js} +207 -198
  8. package/dist/chunks/FormRendererView-BsTwZkqU.js.map +1 -0
  9. package/dist/chunks/FormRendererView-GpsE03np.cjs +4 -0
  10. package/dist/chunks/FormRendererView-GpsE03np.cjs.map +1 -0
  11. package/dist/chunks/approver-filled-form-D1DmqDVP.cjs +2 -0
  12. package/dist/chunks/approver-filled-form-D1DmqDVP.cjs.map +1 -0
  13. package/dist/chunks/approver-filled-form-DuQGPtNB.js +95 -0
  14. package/dist/chunks/approver-filled-form-DuQGPtNB.js.map +1 -0
  15. package/dist/chunks/{compose-DOEaPfEC.cjs → compose-DjEJi5Dv.cjs} +2 -2
  16. package/dist/chunks/{compose-DOEaPfEC.cjs.map → compose-DjEJi5Dv.cjs.map} +1 -1
  17. package/dist/chunks/{compose-v1Vcw9hE.js → compose-WekGZj74.js} +4 -4
  18. package/dist/chunks/{compose-v1Vcw9hE.js.map → compose-WekGZj74.js.map} +1 -1
  19. package/dist/chunks/{designer-DBBrktom.js → designer-D87ILhjz.js} +1664 -1182
  20. package/dist/chunks/designer-D87ILhjz.js.map +1 -0
  21. package/dist/chunks/designer-DESS0CMl.cjs +65 -0
  22. package/dist/chunks/designer-DESS0CMl.cjs.map +1 -0
  23. package/dist/chunks/detail-D49NuNCn.cjs +2 -0
  24. package/dist/chunks/detail-D49NuNCn.cjs.map +1 -0
  25. package/dist/chunks/{detail-B_bSg31B.js → detail-URwxkcro.js} +1036 -847
  26. package/dist/chunks/detail-URwxkcro.js.map +1 -0
  27. package/dist/chunks/{providers-H_vPRsSN.js → providers-B_d5tbCL.js} +178 -167
  28. package/dist/chunks/providers-B_d5tbCL.js.map +1 -0
  29. package/dist/chunks/providers-chuJvMgv.cjs +2 -0
  30. package/dist/chunks/providers-chuJvMgv.cjs.map +1 -0
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/next/index.cjs +1 -1
  34. package/dist/next/index.js +1 -1
  35. package/dist/next/workflow-chat-route.cjs +1 -0
  36. package/dist/next/workflow-chat-route.cjs.map +1 -1
  37. package/dist/next/workflow-chat-route.d.cts +1 -1
  38. package/dist/next/workflow-chat-route.d.ts +1 -1
  39. package/dist/next/workflow-chat-route.js +1 -1
  40. package/dist/next/workflow-chat-route.js.map +1 -1
  41. package/dist/pages/instances/detail/index.cjs +1 -1
  42. package/dist/pages/instances/detail/index.js +1 -1
  43. package/dist/pages/templates/compose/index.cjs +1 -1
  44. package/dist/pages/templates/compose/index.js +1 -1
  45. package/dist/pages/templates/designer/index.cjs +1 -1
  46. package/dist/pages/templates/designer/index.js +1 -1
  47. package/dist/views/forms/builder/index.cjs +1 -1
  48. package/dist/views/forms/builder/index.js +1 -1
  49. package/dist/views/forms/renderer/FormRendererView.d.cts +16 -1
  50. package/dist/views/forms/renderer/FormRendererView.d.ts +16 -1
  51. package/dist/views/forms/renderer/index.cjs +1 -1
  52. package/dist/views/forms/renderer/index.js +1 -1
  53. package/dist/views/inbox/index.cjs +1 -1
  54. package/dist/views/inbox/index.cjs.map +1 -1
  55. package/dist/views/inbox/index.js +109 -99
  56. package/dist/views/inbox/index.js.map +1 -1
  57. package/dist/views/instances/approver-filled-form.d.cts +76 -0
  58. package/dist/views/instances/approver-filled-form.d.ts +76 -0
  59. package/dist/views/instances/detail/index.cjs +1 -1
  60. package/dist/views/instances/detail/index.js +1 -1
  61. package/dist/views/instances/detail/sections/InstanceFormSection.d.cts +30 -2
  62. package/dist/views/instances/detail/sections/InstanceFormSection.d.ts +30 -2
  63. package/dist/views/instances/detail/sections/InstanceHistorySection.d.cts +4 -1
  64. package/dist/views/instances/detail/sections/InstanceHistorySection.d.ts +4 -1
  65. package/dist/views/instances/detail/sections/InstanceTasksSection.d.cts +21 -0
  66. package/dist/views/instances/detail/sections/InstanceTasksSection.d.ts +21 -0
  67. package/dist/views/instances/detail/sections/container-helpers.d.cts +1 -1
  68. package/dist/views/instances/detail/sections/container-helpers.d.ts +1 -1
  69. package/dist/views/instances/detail/sections/shared.d.cts +11 -2
  70. package/dist/views/instances/detail/sections/shared.d.ts +11 -2
  71. package/dist/views/instances/new/index.cjs +1 -1
  72. package/dist/views/instances/new/index.cjs.map +1 -1
  73. package/dist/views/instances/new/index.js +88 -87
  74. package/dist/views/instances/new/index.js.map +1 -1
  75. package/dist/views/instances/viewer-field-access.d.cts +22 -0
  76. package/dist/views/instances/viewer-field-access.d.ts +22 -0
  77. package/dist/views/templates/compose/index.cjs +1 -1
  78. package/dist/views/templates/compose/index.js +1 -1
  79. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.cts +33 -0
  80. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.ts +33 -0
  81. package/dist/views/templates/designer/field-access-matrix/FieldAccessNodeSection.d.cts +20 -0
  82. package/dist/views/templates/designer/field-access-matrix/FieldAccessNodeSection.d.ts +20 -0
  83. package/dist/views/templates/designer/field-access-matrix/field-access-copy.d.cts +22 -0
  84. package/dist/views/templates/designer/field-access-matrix/field-access-copy.d.ts +22 -0
  85. package/dist/views/templates/designer/index.cjs +1 -1
  86. package/dist/views/templates/designer/index.js +1 -1
  87. package/package.json +3 -3
  88. package/dist/chunks/FormRendererView-DRFi_IH7.cjs +0 -4
  89. package/dist/chunks/FormRendererView-DRFi_IH7.cjs.map +0 -1
  90. package/dist/chunks/FormRendererView-cZGOOjU5.js.map +0 -1
  91. package/dist/chunks/designer-CTXMqCD2.cjs +0 -65
  92. package/dist/chunks/designer-CTXMqCD2.cjs.map +0 -1
  93. package/dist/chunks/designer-DBBrktom.js.map +0 -1
  94. package/dist/chunks/detail-BQSVgVlO.cjs +0 -2
  95. package/dist/chunks/detail-BQSVgVlO.cjs.map +0 -1
  96. package/dist/chunks/detail-B_bSg31B.js.map +0 -1
  97. package/dist/chunks/providers-DP7b0TMN.cjs +0 -2
  98. package/dist/chunks/providers-DP7b0TMN.cjs.map +0 -1
  99. package/dist/chunks/providers-H_vPRsSN.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("./language-provider-Bdnx3Gxl.cjs"),r=require("./routes-config-C1j_vFKo.cjs"),i=require("./bpm-form-field-Bc6k4ZEO.cjs"),a=require("./format-member-label-t7ANTF62.cjs"),o=require("./admin-pickers-BRHk3qKq.cjs"),s=require("./FormRendererView-GpsE03np.cjs");;/* empty css */const c=require("./FormBuilderView-CUOyS07f.cjs");let l=require("react"),u=require("@mezzanine-ui/react"),d=require("react/jsx-runtime"),f=require("@mezzanine-ui/react/Drawer");f=e.t(f,1);let p=require("@mezzanine-ui/react/ContentHeader");p=e.t(p,1);let m=require("@mezzanine-ui/icons"),h=require("ai"),g=require("@rytass/bpm-core-shared"),_=require("@rytass/bpm-core-client/form"),v=require("@rytass/bpm-core-shared/form"),y=require("@rytass/bpm-core-client/organization"),b=require("@xyflow/react"),x=require("dagre");x=e.t(x,1);let S=require("@rytass/bpm-core-client/template"),ee=require("@ai-sdk/react"),te=require("@rytass/bpm-core-shared/workflow"),C=require("@rytass/bpm-core-shared/workflow-graph");var ne=[{id:`SINGLE`,name:`單人簽核`},{id:`PARALLEL_ANY`,name:`任一人同意`},{id:`PARALLEL_ALL`,name:`全部同意`},{id:`SEQUENTIAL`,name:`依序簽核`},{id:`QUORUM`,name:`達到指定門檻`}];function re(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 ie(e){return ne.find(t=>t.id===e)||{id:e,name:`未知決策方式(${e})`}}function ae({directory:e,initialState:t,layout:n,onLayout:r}){let[i,a]=(0,l.useState)(t),o=(0,l.useRef)(t),s=(0,l.useRef)(e);s.current=e;let c=(0,l.useCallback)(e=>{if(!e.changed&&!e.error)return e;let t=e.effects.layout?n(e.state.definition):e.state.definition,i={...e.state,definition:t};return o.current=i,a(i),e.effects.layout&&r?.(t),{...e,state:i}},[n,r]),u=(0,l.useCallback)(e=>c((0,g.applyWorkflowCommand)(o.current,e)),[c]),d=(0,l.useCallback)(e=>c((0,g.applyWorkflowMacroCommand)(o.current,e)),[c]),f=(0,l.useCallback)(async(e,t)=>{let n=await(0,g.executeWorkflowTool)(o.current,e,t,{directory:s.current});if(n.ok&&(n.kind===`mutation`||n.kind===`macro`)){let e=c(n.result);return{...n,result:e,snapshot:(0,g.readWorkflowSnapshot)(e.state)}}return n},[c]),p=(0,l.useCallback)(e=>{let t=typeof e==`function`?e(o.current):e;o.current=t,a(t)},[]),m=(0,l.useCallback)(()=>o.current,[]),h=(0,l.useMemo)(()=>(0,g.readWorkflowSnapshot)(i),[i]);return(0,l.useMemo)(()=>({dispatch:u,dispatchMacro:d,executeTool:f,getState:m,replaceState:p,snapshot:h,state:i,tools:g.WORKFLOW_TOOLSET}),[u,d,f,m,p,h,i])}function oe({controller:e,api:t=`/api/chat`}){let n=(0,l.useMemo)(()=>new h.DefaultChatTransport({api:t}),[t]),r=(0,ee.useChat)({transport:n,sendAutomaticallyWhen:h.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:t}){let n=await e.executeTool(t.toolName,t.input);n.ok?r.addToolOutput({output:n.kind===`query`?n.data:n.snapshot,tool:t.toolName,toolCallId:t.toolCallId}):r.addToolOutput({errorText:n.error,state:`output-error`,tool:t.toolName,toolCallId:t.toolCallId})}});return r}var se=12;function w(){let e=globalThis.LanguageModel;return e&&typeof e==`object`?e:null}var ce={additionalProperties:!1,properties:{action:{enum:[`tool`,`message`],type:`string`},input:{type:`object`},text:{type:`string`},tool:{type:`string`}},required:[`action`],type:`object`};function le(){return`你是「簽核流程設計器」頁面的離線 AI 助理。只能透過下列工具操作這個流程畫布,其他請求一律婉拒並引導回流程設計。
2
+
3
+ 每一步只輸出一個 JSON 決策物件:
4
+ - 呼叫工具:{"action":"tool","tool":"<工具名>","input":{...}}
5
+ - 回覆使用者(完成或詢問):{"action":"message","text":"<繁體中文訊息>"}
6
+
7
+ 規則:先用 get_workflow_snapshot 了解現況再規劃;完成後用 validate_workflow 檢查並以 message 說明做了什麼。
8
+
9
+ 可用工具:
10
+ ${g.WORKFLOW_TOOLSET.map(e=>`- ${e.name}(${JSON.stringify(e.inputSchema.properties??{})}): ${e.description}`).join(`
11
+ `)}`}function ue({controller:e}){let[t,n]=(0,l.useState)(!1),[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(`ready`),s=(0,l.useRef)(0);(0,l.useEffect)(()=>{let e=w();e&&e.availability().then(e=>{n(e!==`unavailable`)}).catch(()=>n(!1))},[]);let c=(0,l.useCallback)((e,t)=>{s.current+=1,i(n=>[...n,{id:`chrome-${s.current}`,parts:[{text:t,type:`text`}],role:e}])},[]);return{available:t,messages:r,send:(0,l.useCallback)(t=>{let n=w();n&&a===`ready`&&(c(`user`,t),o(`submitted`),T({appendMessage:c,controller:e,model:n,userText:t}).then(()=>o(`ready`)).catch(e=>{c(`assistant`,de(e)),o(`error`)}))},[c,e,a]),status:a}}async function T({appendMessage:e,controller:t,model:n,userText:r}){let i=await n.create({initialPrompts:[{content:le(),role:`system`}]});try{let n=`使用者需求:${r}\n目前流程:${JSON.stringify(t.snapshot)}`;for(let r=0;r<se;r+=1){let r=E(await i.prompt(n,{responseConstraint:ce}));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 E(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=oe({api:e,controller:t}),a=ue({controller:t}),[o,s]=(0,l.useState)(`online`),[c,p]=(0,l.useState)(``),m=o===`offline`?{messages:a.messages,send:a.send,status:a.status}:{messages:i.messages,send:e=>{i.sendMessage({text:e})},status:i.status},{messages:h,send:g}=m,_=m.status===`submitted`||m.status===`streaming`,v=(0,l.useCallback)(()=>{let e=c.trim();e&&!_&&(p(``),g(e))},[_,c,g]),y=(0,l.useCallback)(e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),v())},[v]);return(0,d.jsxs)(f.default,{headerTitle:`AI 流程助理`,isHeaderDisplay:!0,onClose:n,open:r,size:`medium`,children:[(0,d.jsx)(`style`,{children:ye}),(0,d.jsxs)(`div`,{style:fe,children:[a.available?(0,d.jsxs)(`div`,{style:me,children:[(0,d.jsx)(u.Button,{onClick:()=>s(`online`),variant:o===`online`?`base-primary`:`base-tertiary`,children:`線上`}),(0,d.jsx)(u.Button,{onClick:()=>s(`offline`),variant:o===`offline`?`base-primary`:`base-tertiary`,children:`離線(裝置內,實驗)`})]}):null,(0,d.jsxs)(`div`,{role:`log`,style:pe,children:[h.length===0?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`用一句話描述你想要的流程,例如:「建立三關簽核:部門主管 → 經理 → 財務,金額大於十萬走財務複核」。我會直接在畫布上幫你繪製。`}):null,h.map(e=>(0,d.jsx)(l.Fragment,{children:we(e)},e.id)),_?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`思考中…`}):null]}),(0,d.jsxs)(`div`,{style:he,children:[(0,d.jsx)(u.Textarea,{className:ve,disabled:_,maxLength:2e3,onChange:e=>p(e.target.value),onKeyDown:y,placeholder:`描述你想要的流程…(Enter 送出,Shift + Enter 換行)`,rows:3,style:_e,value:c}),(0,d.jsx)(`div`,{style:ge,children:(0,d.jsx)(u.Button,{disabled:_||c.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,d.jsx)(`div`,{style:Se(e.role),children:t.text},`${e.id}-${n}`);if(t.type===`dynamic-tool`||(0,h.isToolUIPart)(t)){let r=(0,h.getToolName)(t),i=xe[t.state]??t.state;return(0,d.jsx)(`div`,{style:be,children:`⚙ ${r} · ${i}`},`${e.id}-${n}`)}return null})}var Te={DEFAULT:`預設`,FILL_OPTIONAL:`補填(選填)`,FILL_REQUIRED:`補填(必填)`,HIDE:`隱藏`,SHOW:`顯示`},D={FILL:`填寫`,FILL_OPTIONAL:`補填(選填)`,FILL_REQUIRED:`補填(必填)`,HIDDEN:`隱藏`,NOT_SHOWN:`不顯示`,READ_ONLY:`唯讀`},O={approverFilledFieldDataSource:`選項來自資料來源,不能補填`,approverFilledFieldFileUpload:`檔案上傳欄位不能補填`,approverFilledFieldFormRule:`表單已設定必填、顯示或預設值等規則,不能補填`,approverFilledTableDataSourceColumn:`表格含資料來源欄,不能補填`},k=`開關欄位只能選填補填:開關關著也是答案,不能要求必填。`,A=`「隱藏」只影響這一關的畫面,不是權限:資料查詢仍拿得到值,不能用來保密。`;function j(e){return`關卡 ${e.stage}`}function M(e){let t=(0,g.readNodeFieldAccess)(e);return{fill:t.filter(e=>e.fill!==`NONE`).length,hidden:t.filter(e=>e.fill===`NONE`&&e.display===`HIDE`).length,required:t.filter(e=>e.fill===`REQUIRED`).length}}function Ee(e){let{fill:t,hidden:n}=M(e),r=[...t>0?[`補填 ${t}`]:[],...n>0?[`隱藏 ${n}`]:[]];return r.length?r.join(` · `):null}var De=new Set([`fieldAccessAutoApprove`,`fieldAccessGroupPolicy`,`fieldAccessSkipNode`]);function Oe(e){return De.has(e.code)}var ke={display:`grid`,gap:12,gridTemplateColumns:`minmax(0, 1fr)`,padding:`var(--mzn-spacing-padding-vertical-spacious) var(--mzn-spacing-padding-horizontal-spacious)`},N={display:`grid`,gap:4},Ae={display:`grid`};function je(e){return e.nodes.filter(e=>e.type===`userTask`).flatMap(e=>(0,g.readNodeFieldAccess)(e).filter(g.isFieldAccessEntryValid).map(t=>({...t,nodeId:e.id})))}function Me(e,t,n,r){let i=e.findIndex(e=>e.nodeId===t&&e.fieldKey===n);return i===-1?r===null?e:[...e,r]:e.flatMap((e,t)=>t===i?r===null?[]:[r]:[e])}function P(e,t,n,r){let i=(0,g.readFieldAccessEntryForChoice)(n,r);return Me(e,t,n,i===null?null:{...i,nodeId:t})}function F(e){return`${e.nodeId}\u0000${e.fieldKey}`}function Ne(e,t,n,r){let i=new Map(t.map(e=>[F(e),e])),a=new Map(n.map(e=>[F(e),e]));return[...t,...n].filter((e,t,n)=>n.findIndex(t=>F(t)===F(e))===t&&JSON.stringify(i.get(F(e)))!==JSON.stringify(a.get(F(e)))).reduce((e,t)=>Me(e,t.nodeId,t.fieldKey,a.get(F(t))??null),e).filter(e=>r.has(e.nodeId))}function Pe(e){return new Set(e.nodes.filter(e=>e.type===`userTask`).map(e=>e.id))}function Fe(e,t,n){return(0,g.applyWorkflowCommand)({definition:e,editingEdgeId:null,formDefinitionVersionId:null,formSchema:t,initiatorPolicyCel:null,selectedEdgeIds:[],selectedNodeId:null},{entries:n,type:`setFieldAccessMatrix`}).state.definition}function Ie(e){return e.nodes.every(t=>t.type!==`userTask`||t.data.fieldAccess===void 0||Le(t.data.fieldAccess)===Le(je({...e,nodes:[t]})))}function Le(e){return JSON.stringify(Array.isArray(e)?e.map(Re):e)}function Re(e){if(typeof e!=`object`||!e||Array.isArray(e))return e;let{display:t,fieldKey:n,fill:r}=e;return[t,n,r]}function ze(e,t){return JSON.stringify(e)===JSON.stringify(t)}var Be={columns:[],issues:[],rows:[]};function Ve(e,t){let n=je(e);return{draft:n,initial:n,pinnedFieldKeys:new Set((0,g.readFieldAccessMatrix)(e,t).rows.filter(He).map(e=>e.fieldKey))}}function He(e){return e.cells.some(e=>e.explicit!==null)||e.issues.length>0||e.notices.length>0}function Ue(e){return g.FIELD_ACCESS_CHOICES.filter(t=>t===e.choice||!e.disabledChoices.includes(t)).map(t=>({id:t,name:t===`DEFAULT`&&e.choice===`DEFAULT`?`預設:${D[e.effective]}`:Te[t]}))}function We(e,t){if(e.applicant.effective===`FILL`)return D.FILL;let n=e.fillNodeIds.map(e=>t.find(t=>t.nodeId===e)).filter(e=>!!e).map(j).join(`、`);return`${D.NOT_SHOWN}(${n} 補填)`}function Ge({definition:e,formSchema:t,language:n,onApply:r,onClose:i,open:a}){let[o,s]=(0,l.useState)(null),[c,p]=(0,l.useState)(!0),[m,h]=(0,l.useState)(null);a&&o===null&&(s(Ve(e,t)),p(!0),h(null)),!a&&o!==null&&s(null);let _=(0,l.useMemo)(()=>o===null?null:Ne(je(e),o.initial,o.draft,Pe(e)),[e,o]),v=(0,l.useMemo)(()=>_===null?e:Fe(e,t,_),[e,_,t]),y=(0,l.useMemo)(()=>_===null?Be:(0,g.readFieldAccessMatrix)(v,t),[v,_,t]),b=o?.pinnedFieldKeys??new Set,x=e=>(0,S.readWorkflowLintMessage)(e,v,n),ee=y.rows.filter(e=>!c||b.has(e.fieldKey)||He(e)),te=y.rows.length-ee.length,C=new Set(y.rows.map(e=>e.fieldKey)),ne=y.issues.filter(e=>!e.fieldKeys.some(e=>C.has(e)));function re(e,t,n){h(null),s(r=>r===null?null:{...r,draft:P(r.draft,e,t,n),pinnedFieldKeys:new Set([...r.pinnedFieldKeys,t])})}function ie(){let t=_===null||ze(_,je(e))&&Ie(e)?null:r(_);t===null?i():h(t)}let ae=[{ellipsis:!1,fixed:`start`,key:`field`,render:({row:e})=>(0,d.jsxs)(`div`,{style:Ae,children:[(0,d.jsx)(u.Typography,{variant:`label-primary`,children:e.field.label}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:e.fieldKey})]}),title:`欄位`,width:180},{ellipsis:!1,key:`applicant`,render:({row:e})=>We(e,y.columns),title:`申請人`,width:160},...y.columns.map((e,t)=>({ellipsis:!1,key:`node:${e.nodeId}`,render:({row:n})=>{let r=n.cells[t],i=Ue(r);return(0,d.jsx)(u.Select,{clearable:!1,inputProps:{"aria-label":`${n.field.label} 在${j(e)}的設定`},onChange:t=>re(e.nodeId,n.fieldKey,i.find(e=>e.id===t?.id)?.id??`DEFAULT`),options:[...i],size:`sub`,value:i.find(e=>e.id===r.choice)??null})},title:(0,d.jsxs)(`div`,{style:N,children:[(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[j(e),e.branchLabel?` · 分支:${e.branchLabel}`:``]}),(0,d.jsx)(u.Typography,{variant:`label-primary`,children:e.label})]}),width:224})),{ellipsis:!1,key:`check`,render:({row:e})=>oe(e),title:`檢查`,width:280}];function oe(e){let t=e.issues.map(e=>x(e.message)),n=e.notices.map(e=>{let t=y.columns.find(t=>t.nodeId===e.nodeId);return`${t?j(t):e.nodeId} 會看到空白欄位:這一關之前還沒有人補填。`}),r=e.fillNodeIds.length===0?[...e.fillBlockers.flatMap(e=>{let t=O[e.code];return t?[t]:[]}),...e.field.type===`boolean`?[k]:[]]:[];return t.length+n.length+r.length===0?(0,d.jsx)(u.Badge,{text:`沒有問題`,variant:`dot-success`}):(0,d.jsxs)(`div`,{style:N,children:[t.map(e=>(0,d.jsx)(u.Badge,{text:e,variant:`dot-warning`},`warning:${e}`)),n.map(e=>(0,d.jsx)(u.Badge,{text:e,variant:`dot-info`},`notice:${e}`)),[...new Set(r)].map(e=>(0,d.jsx)(u.Badge,{text:e,variant:`dot-info`},`blocker:${e}`))]})}return(0,d.jsx)(f.default,{bottomGhostActionText:`取消`,bottomOnGhostActionClick:i,bottomOnPrimaryActionClick:ie,bottomPrimaryActionText:`套用`,headerTitle:`欄位與關卡總覽`,isBottomDisplay:!0,isHeaderDisplay:!0,onClose:i,open:a,size:`wide`,children:(0,d.jsxs)(`div`,{style:ke,children:[m===null?null:(0,d.jsxs)(`div`,{style:N,children:[(0,d.jsx)(u.InlineMessage,{content:`無法套用,編輯內容仍保留。`,severity:`error`}),(0,d.jsx)(u.Badge,{text:m,variant:`dot-error`})]}),(0,d.jsxs)(`div`,{style:N,children:[y.issues.length>0?(0,d.jsx)(u.InlineMessage,{content:`有 ${y.issues.length} 個欄位設定問題,處理完才能發布。`,severity:`warning`}):(0,d.jsx)(u.InlineMessage,{content:`補填由該關的簽核人在核准時填寫。`,severity:`info`}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:y.issues.length>0?`問題標示在各欄位的「檢查」欄。`:`申請人送出時看不到補填欄位。${A}發布時還會檢查條件是否在補填前就讀取這些欄位。`}),ne.map(e=>(0,d.jsx)(u.Badge,{text:x(e.message),variant:`dot-warning`},e.message))]}),(0,d.jsx)(u.Toggle,{checked:c,inputProps:{"aria-label":`只看有設定或有問題的欄位`},label:`只看有設定或有問題的欄位`,onChange:e=>p(e.target.checked),size:`sub`}),te>0?(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`已收起 `,te,` 個沒有設定也沒有問題的欄位。`]}):null,t===null?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`尚未綁定表單,沒有可設定的欄位。`}):(0,d.jsx)(u.Table,{columns:ae,dataSource:ee.map(e=>({key:e.fieldKey,row:e})),fullWidth:!0})]})})}var Ke={borderTop:`1px solid var(--mzn-color-border-neutral)`,display:`grid`,gap:8,paddingTop:12},I={alignItems:`center`,display:`flex`,gap:8,justifyContent:`space-between`};function qe({definition:e,language:t,node:n,onOpenMatrix:r,onRemoveLegacy:i,openDisabledReason:a}){let o=M(n),s=(0,g.readNodeFieldAccessIssues)(n).filter(Oe).map(n=>(0,S.readWorkflowLintMessage)(n.message,e,t));return(0,d.jsxs)(`section`,{"aria-label":`欄位顯示與補填`,style:Ke,children:[(0,d.jsxs)(`div`,{style:I,children:[(0,d.jsx)(u.Typography,{component:`h3`,variant:`h3`,children:`欄位顯示與補填`}),(0,d.jsx)(u.Button,{disabled:a!==null,onClick:r,size:`sub`,title:a??void 0,variant:`base-secondary`,children:`開啟欄位總覽`})]}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[`本關補填 `,o.fill,` 個(必填 `,o.required,`)`]}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[`本關隱藏 `,o.hidden,` 個`]}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`其他欄位依預設`}),a?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:a}):null,(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:A}),n.data.fieldPermissions===void 0?null:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(u.InlineMessage,{content:`含已停用的舊欄位權限設定`,severity:`warning`}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`舊設定(fieldPermissions)從未生效,也不會自動轉換;移除後才能發布,需要的設定請在欄位總覽重新指定。`}),(0,d.jsx)(`div`,{children:(0,d.jsx)(u.Button,{onClick:i,size:`sub`,variant:`base-secondary`,children:`移除舊設定`})})]}),s.map(e=>(0,d.jsx)(u.Badge,{text:e,variant:`dot-warning`},e))]})}var Je={en:`An unknown error occurred`,"zh-TW":`發生未知錯誤`},Ye={en:`Webhook settings failed the publish check: `,"zh-TW":`Webhook 設定未通過發布檢查:`};function L(e,t,n){if(!(e instanceof Error))return Je[t];let r=n?(0,S.readWorkflowLintMessage)(e.message,n,t):e.message;return r.includes(`WORKFLOW_WEBHOOK_`)?`${Ye[t]}${r}`:(0,_.readFormSchemaLintMessage)(r,t)}function Xe(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 Ze(e){return e.reduce((e,t)=>Math.max(e,t.level),1)}var Qe={"initiator.memberId":`發起人會員編號`,"instance.id":`案件編號`,"instance.templateId":`模板編號`,"instance.templateVersionId":`模板版本編號`,"instance.title":`案件主旨`,"node.id":`節點編號`,"node.label":`節點名稱`},$e={boolean:`是/否`,json:`JSON`,number:`數字`,string:`文字`,stringArray:`文字清單`};function R(e){return`${e.key}@${e.version}`}function et(e,t){return e.find(e=>e.key===t.key&&e.version===t.version)??null}function z(e){return[`FIELD`,...e===`stringArray`?[]:[`CONSTANT`],...e===`string`||e===`json`?[`CONTEXT`]:[]]}function tt(e,t){return e.filter(e=>(0,C.isFormFieldCompatibleWithWebhookParameter)(e,t))}function nt(e,t,n){return e===`FIELD`?{fieldKey:tt(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 rt=/^-?\d+(\.\d+)?$/;function it(e,t){if(e!==`number`)return t;let n=t.trim();return n?rt.test(n)?Number(n):t:null}function at(e){return!(0,C.readNotifyWebhookStructureIssues)(e).some(e=>ot.has(e.code))}var ot=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 st(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 ct(e,t,n){return{bindings:e.bindings.filter(r=>{let i=t.parameters.find(e=>e.key===r.parameter);return i!==void 0&&!(0,C.readNotifyWebhookTargetCatalogIssues)({endpoint:{parameters:[{...i,required:!1}]},formFields:n,target:{...e,bindings:[r]}}).length}),endpoint:{key:t.key,version:t.version},id:e.id}}function lt({definition:e,endpoints:t,formFields:n}){return e.nodes.flatMap(e=>e.type!==`serviceTask`||e.data.action.type!==`NOTIFY`||(0,C.readNotifyWebhookStructureIssues)(e.data.action.webhooks).length?[]:(0,C.readNotifyWebhookTargets)(e.data.action).flatMap((r,i)=>{let a=et(t,r.endpoint);return(0,C.readNotifyWebhookTargetCatalogIssues)({endpoint:a,formFields:n,target:r}).map(t=>(0,C.readNotifyWebhookCatalogIssueMessage)({endpointLabel:a?.label??R(r.endpoint),issue:t,nodeLabel:e.data.label,targetIndex:i}))}))}var ut={display:`grid`,gap:`var(--mzn-spacing-gap-base)`},dt={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)`},ft={alignItems:`center`,display:`flex`,gap:`var(--mzn-spacing-gap-base)`,justifyContent:`space-between`},pt={display:`grid`,gap:`var(--mzn-spacing-gap-base)`,gridTemplateColumns:`minmax(0, 2fr) minmax(0, 3fr)`},B={id:`NONE`,name:`不傳送`},mt={CONSTANT:{id:`CONSTANT`,name:`固定值`},CONTEXT:{id:`CONTEXT`,name:`案件資訊`},FIELD:{id:`FIELD`,name:`表單欄位`}},ht=[{id:`true`,name:`是`},{id:`false`,name:`否`}],gt=C.NOTIFY_WEBHOOK_CONTEXT_PATHS.map(e=>({id:e,name:Qe[e]}));function _t({catalog:e,catalogState:t,formFields:n,onChange:r,targets:i}){let a=e.filter(e=>!e.deprecated);if(!i.length&&(t===`unavailable`||t===`ready`&&!a.length))return null;function o(e,t){r(i.map((n,r)=>r===e?t:n))}function s(){let[e]=a;e&&r([...i,(0,C.createNotifyWebhookTarget)({key:e.key,version:e.version})])}return(0,d.jsxs)(`div`,{style:ut,children:[(0,d.jsx)(u.Typography,{variant:`label-primary-highlight`,children:`Webhook`}),(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`知會節點抵達時,將指定的表單欄位或案件資訊送到外部系統。`}),t===`loading`?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`正在載入可用的 Webhook 端點…`}):null,t===`unavailable`?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:`目前無法載入 Webhook 端點,已設定的內容會保留,請稍後重試。`}):null,i.map((s,c)=>(0,d.jsx)(vt,{activeEndpoints:a,catalog:e,catalogState:t,formFields:n,index:c,onChange:e=>o(c,e),onRemove:()=>r(i.filter((e,t)=>t!==c)),target:s},s.id)),(0,d.jsx)(`div`,{children:(0,d.jsx)(u.Button,{disabled:t!==`ready`||!a.length||i.length>=C.NOTIFY_WEBHOOK_TARGET_LIMIT,icon:m.PlusIcon,iconType:`leading`,onClick:s,variant:`base-dashed`,children:`新增 Webhook`})}),i.length>=C.NOTIFY_WEBHOOK_TARGET_LIMIT?(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`每個知會節點最多 `,C.NOTIFY_WEBHOOK_TARGET_LIMIT,` 個 Webhook。`]}):null]})}function vt({activeEndpoints:e,catalog:t,catalogState:n,formFields:r,index:a,onChange:o,onRemove:s,target:c}){let l=et(t,c.endpoint),f=R(c.endpoint),p=[...e.map(e=>({id:R(e),name:St(e)})),...l&&!l.deprecated?[]:[{id:f,name:l?St(l):`${f}(找不到端點)`}]],h=new Set((l?.parameters??[]).map(e=>e.key)),g=l?c.bindings.filter(e=>!h.has(e.parameter)):[];return(0,d.jsxs)(`div`,{style:dt,children:[(0,d.jsxs)(`div`,{style:ft,children:[(0,d.jsxs)(u.Typography,{variant:`label-primary`,children:[`第 `,a+1,` 個 Webhook`]}),(0,d.jsx)(u.Button,{icon:m.TrashIcon,iconType:`leading`,onClick:s,variant:`destructive-text-link`,children:`移除`})]}),(0,d.jsx)(i.t,{label:`端點`,name:`webhookEndpoint-${c.id}`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,disabled:n!==`ready`,onChange:t=>{let n=e.find(e=>R(e)===t?.id);n&&o(ct(c,n,r??[]))},options:[...p],placeholder:`選擇端點`,value:p.find(e=>e.id===f)??null})}),n===`ready`&&!l?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`找不到這個端點,設定會保留;請改選其他端點或移除,否則無法發布。`}):null,l?.disabled?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`這個端點已被管理者停用,不會再送出;設定會保留,請改選其他端點,否則無法發布。`}):l?.deprecated?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:`這個端點不建議再使用,設定會保留;請改選其他端點,否則無法發布。`}):null,l?.description?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:l.description}):null,l&&!l.parameters.length?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`這個端點不需要參數。`}):null,(l?.parameters??[]).map(e=>(0,d.jsx)(yt,{formFields:r,onChange:t=>o(st(c,e.key,t)),parameter:e,source:c.bindings.find(t=>t.parameter===e.key)?.from??null,targetId:c.id},e.key)),g.map(e=>(0,d.jsxs)(`div`,{style:ft,children:[(0,d.jsxs)(u.Typography,{color:`text-warning`,variant:`body`,children:[`參數「`,e.parameter,`」已不在端點定義中。`]}),(0,d.jsx)(u.Button,{onClick:()=>o(st(c,e.parameter,null)),variant:`base-text-link`,children:`移除設定`})]},e.parameter))]})}function yt({formFields:e,onChange:t,parameter:n,source:r,targetId:a}){let o=r?.kind===`FIELD`||tt(e??[],n.type).length>0,s=[...n.required?[]:[B],...z(n.type).filter(e=>e!==`FIELD`||o).map(e=>mt[e])],c=$e[n.type];return(0,d.jsx)(i.t,{hintText:[n.key,c,n.description].filter(Boolean).join(` · `),label:n.label,name:`webhookBinding-${a}-${n.key}`,required:n.required,children:(0,d.jsxs)(`div`,{style:pt,children:[(0,d.jsx)(u.Select,{clearable:!1,onChange:r=>{let i=Ct(r?.id??null);t(i?nt(i,n,e??[]):null)},options:[...s],placeholder:`選擇來源`,value:r?mt[r.kind]:n.required?null:B}),r?(0,d.jsx)(bt,{formFields:e,onChange:t,parameter:n,source:r}):null]})})}function bt({formFields:e,onChange:t,parameter:n,source:r}){if(r.kind===`FIELD`){if(!e)return(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`請先綁定表單版本,才能選擇表單欄位。`});let i=tt(e,n.type).map(e=>({id:e.fieldKey,name:`${e.label}(${e.fieldKey})`})),a=r.fieldKey&&!i.some(e=>e.id===r.fieldKey)?[...i,{id:r.fieldKey,name:`${r.fieldKey}(找不到相容欄位)`}]:i;return(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>t({fieldKey:e?.id??``,kind:`FIELD`}),options:[...a],placeholder:a.length?`選擇表單欄位`:`沒有型別相容的欄位`,value:a.find(e=>e.id===r.fieldKey)??null})}return r.kind===`CONTEXT`?(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>{(0,C.isNotifyWebhookContextPath)(e?.id)&&t({kind:`CONTEXT`,path:e.id})},options:[...gt],value:gt.find(e=>e.id===r.path)??null}):n.type===`boolean`?(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>t({kind:`CONSTANT`,value:e?.id===`true`}),options:[...ht],value:typeof r.value==`boolean`?ht.find(e=>e.id===String(r.value))??null:null}):(0,d.jsx)(xt,{onChange:e=>t({kind:`CONSTANT`,value:e}),type:n.type,value:r.value})}function xt({onChange:e,type:t,value:n}){let[r,i]=(0,l.useState)(n===null?``:String(n));return(0,l.useEffect)(()=>{i(e=>it(t,e)===n?e:n===null?``:String(n))},[t,n]),(0,d.jsx)(u.Input,{inputProps:{inputMode:t===`number`?`decimal`:void 0},onChange:n=>{i(n.target.value),e(it(t,n.target.value))},placeholder:t===`number`?`輸入數字`:`輸入固定值`,value:r,variant:`base`})}function St(e){let t=[`v${e.version}`,...e.source===`DATABASE`?[`後台維護`]:[],...e.disabled?[`已停用`]:e.deprecated?[`不建議使用`]:[]];return`${e.label}(${t.join(`,`)})`}function Ct(e){return e===`FIELD`||e===`CONSTANT`||e===`CONTEXT`?e:null}function wt(e){return(e?.fields??[]).reduce((e,t)=>({...e,[t.fieldKey]:Et(t)}),{})}function Tt(e){return`formMember:${e}`}function Et(e){if(e.type===`number`||e.type===`money`)return 1e3;if(e.type===`boolean`)return!0;if(e.type===`member`){let t=Tt(e.fieldKey);return e.multiple?[t]:t}if((0,v.isFormOptionFieldDefinition)(e)){let t=(0,v.isFormStaticOptionFieldDefinition)(e)?e.options[0]?.value:void 0;if((0,v.readFormFieldSelectionMode)(e)===`multiple`)return t===void 0?[]:[t];if((0,v.isFormStaticOptionFieldDefinition)(e))return t??``}return e.type===`date`?`2026-05-08`:e.type===`datetime`?`2026-05-08T09:00:00+08:00`:e.placeholder??e.label}function Dt(e,t){let[n,...r]=e.split(`:`),i=e=>t.orgUnits.find(t=>t.id===e)?.name??e,a=e=>t.positions.find(t=>t.id===e)?.name??e;return n===`position`&&r.length===1&&r[0]?`職位:${a(r[0])}(送出時依當下人員決定)`:n===`orgUnitMember`&&r.length===1&&r[0]?`組織任一人:${i(r[0])}`:n===`orgUnitPosition`&&r.length===2&&r[0]&&r[1]?`組織職位:${i(r[0])}/${a(r[1])}`:n===`orgUnitManager`&&r.length===1&&r[0]?`組織主管:${i(r[0])}`:n===`formMember`&&r.length===1&&r[0]?`表單欄位「${(e=>t.formFields.find(t=>t.fieldKey===e)?.label||e)(r[0])}」選的人(送出時依填寫內容決定)`:n===`orgManagerChain`&&r.length===1&&r[0]?`主管鏈:簽到職等 ${r[0]}(送出時依組織決定實際主管)`:t.memberName(e)??e}var V=`表單中沒有「人員選擇」欄位,請先到表單設計加入`,Ot=`原本指定的欄位已不在表單中,或已不是「人員選擇」欄位,請重新選擇。`,kt=`此欄位非必填`,At=`此欄位可能被條件隱藏`,jt=`此欄位為隱藏欄位,申請人無法填寫`,Mt=`,空白時此關會找不到人員,發佈時會被拒絕;請在表單設計將它設為必填且不隱藏`;function Nt(e){let t=[...e.required?[]:[kt],...e.visibleWhen?.trim()?[At]:[],...e.hidden?[jt]:[]];return t.length>0?`${t.join(`、`)}${Mt}`:void 0}function Pt(e){return`${e.required?``:`(非必填)`}${e.visibleWhen?.trim()?`(可能被條件隱藏)`:``}${e.hidden?`(隱藏欄位)`:``}`}function H(e){return(e?.fields??[]).filter(v.isMemberFieldDefinition).map(e=>{let t=Nt(e);return{id:e.fieldKey,name:`${e.label} (${e.fieldKey})${Pt(e)}`,...t?{warning:t}:{}}})}function Ft(e,t){let n=H(e),r=n.find(e=>e.id===t)??null;if(r)return{options:n,problem:r.warning??null,selected:r};if(t.trim()){let e={id:t,name:`${t}(無效欄位)`};return{options:[...n,e],problem:Ot,selected:e}}return{options:n,problem:n.length===0?V:null,selected:null}}function It(e,t){if(!t.trim())return`依表單欄位:未設定`;let n=e?.fields.find(e=>e.fieldKey===t);return n&&!(0,v.isMemberFieldDefinition)(n)?`依表單欄位:${n.label||t}(非人員選擇欄位)`:`依表單欄位:${n?.label||t}`}function Lt(e){return`${e.draftVersion===null?`尚未建立草稿`:`草稿 v${e.draftVersion}`} · ${e.publishedVersion===null?e.hasPublishedVersion?`已發布版本`:`尚未發布`:`已發布 v${e.publishedVersion}`}`}function Rt(e,t){return`表單:${e} v${t}`}var zt={display:`grid`,gap:16},Bt={alignItems:`start`,display:`grid`,gap:16,gridTemplateColumns:`minmax(0, 1fr) 420px`},Vt={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,height:620,minWidth:0,overflow:`hidden`},Ht={alignItems:`center`,boxSizing:`border-box`,color:`var(--mzn-color-text-error)`,display:`flex`,height:26,justifyContent:`center`,lineHeight:0,padding:0,width:26},Ut={alignItems:`center`,display:`flex`,height:`100%`,justifyContent:`center`,width:`100%`},Wt=`workflow-designer-side-panel`,Gt=96,Kt=`
16
+ .${Wt} .mzn-form-field--stretch .mzn-form-field__label-area,
17
+ .${Wt} .mzn-form-field--horizontal .mzn-form-field__label-area {
18
+ flex: 0 0 ${Gt}px;
19
+ width: ${Gt}px;
20
+ }
21
+
22
+ .${Wt} .mzn-form-field--stretch .mzn-form-field__data-entry,
23
+ .${Wt} .mzn-form-field--horizontal .mzn-form-field__data-entry {
24
+ min-width: 0;
25
+ }
26
+ `,qt=`#2563eb`,U=`#64748b`,Jt=`var(--mzn-color-text-error, #dc2626)`,Yt=`drop-shadow(0 0 3px rgba(0, 87, 255, 0.85)) drop-shadow(0 0 9px rgba(0, 87, 255, 0.36))`,Xt=`
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: ${Yt};
52
+ opacity: 1 !important;
53
+ stroke: ${U} !important;
54
+ stroke-opacity: 1 !important;
55
+ stroke-width: 1.5px !important;
56
+ }
57
+
58
+ .workflow-edge--selected {
59
+ --xy-edge-stroke: ${U};
60
+ --xy-edge-stroke-selected: ${U};
61
+ --xy-edge-stroke-width: 1.5px;
62
+ }
63
+
64
+ `,Zt={display:`grid`,gap:12},W={display:`grid`,gap:12},Qt={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,display:`grid`,gap:8,maxHeight:360,overflow:`auto`,padding:12},$t={borderBottom:`1px solid var(--mzn-color-border-neutral)`,display:`grid`,gap:4,padding:`0 0 8px`},en={display:`flex`,flexWrap:`wrap`,gap:8},tn={alignItems:`center`,display:`flex`,gap:8},nn={flex:`1 1 auto`,minWidth:0},rn={flex:`0 0 auto`},an={display:`grid`,gap:8},G={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%`},on=`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)`,K=64,sn=160,cn=20,ln=24,un=`先綁定表單版本,才能設定欄位在各關的顯示與補填。`,dn=64,q=180,fn={...G,display:`grid`,gap:8,padding:`10px 12px`},pn={...fn,background:`#eff6ff`,border:`1px solid #2563eb`},mn={...fn,background:`#f0fdfa`,border:`1px solid #0f766e`},hn={...G,background:`#ffffff`},gn={...G,background:`#ecfdf3`,border:`1px solid #2f855a`},_n={...G,background:`#fff4ed`,border:`1px solid #c2410c`},vn={display:`block`,maxWidth:`100%`,minWidth:0},yn={display:`grid`,gap:2,minWidth:0},bn=`input`,J=`output`,xn={endEvent:`結束`,exclusiveGateway:`條件分流`,parallelGateway:`並行處理`,serviceTask:`系統`,startEvent:`開始`,userTask:`簽核`},Sn=[{icon:m.UserIcon,label:`簽核節點`,type:`userTask`},{icon:m.MailIcon,label:`知會節點`,type:`serviceTask`}],Cn=[{icon:m.FilterIcon,label:`條件分流`,type:`exclusiveGateway`}],wn=[{id:`AND`,name:`全部前置完成`},{id:`OR`,name:`任一前置完成`}],Tn=[{id:`RESTART`,name:`重新送出後從開始重跑`},{id:`FROM_RETURN_POINT`,name:`重新送出後回到退回節點`}],En=[{id:`NONE`,name:`不提醒`,value:null},{id:`0.5`,name:`過半時提醒`,value:.5},{id:`0.75`,name:`剩四分之一時提醒`,value:.75},{id:`0.9`,name:`剩十分之一時提醒`,value:.9}],Dn=[{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:`指定職位`}],On=[{id:`COUNT`,name:`人數`},{id:`PERCENTAGE`,name:`百分比`}],kn=[{id:`1`,name:`直屬主管`,value:1},{id:`2`,name:`第二層主管`,value:2},{id:`3`,name:`第三層主管`,value:3}],An=[{id:`NONE`,name:`停止流程並提示`},{id:`DIRECT`,name:`固定改派`},{id:`POSITION`,name:`指定職位`}],jn={id:`UNSUPPORTED`,name:`不支援的備援設定`},Mn=[{id:`INITIATOR_MANAGER`,name:`改由申請人的直屬主管簽核`},{id:`SKIP_NODE`,name:`跳過此關`},{id:`FAIL`,name:`停止流程並提示`}],Nn={whenEmpty:`INITIATOR_MANAGER`},Pn=[`EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`NOT_EQUALS`],Fn=[{id:`NONE`,name:`未設定`},{id:`ALL`,name:`所有人`},{id:`ORG_UNIT`,name:`指定組織`},{id:`ORG_UNIT_POSITION`,name:`指定組織職位`}],In={id:`CUSTOM`,name:`既有自訂規則`},Ln=`member-001`,Rn={display:`flex`,flexDirection:`column`,height:`100%`},zn={flex:1,minHeight:0,overflowY:`auto`},Bn={borderTop:`1px solid var(--mzn-color-border-neutral)`,display:`flex`,gap:8,paddingTop:12},Vn={fields:[],schemaVersion:1},Hn={layout:[],schemaVersion:1},Un={endEvent:qn,exclusiveGateway:qn,parallelGateway:qn,serviceTask:qn,startEvent:qn,userTask:qn};function Wn(e,t){return typeof e==`function`?e(t):e}function Gn({aiAssistantAvailable:e=!0,embedded:a=!1,formSchemaOverride:h,initialInitiatorPolicyCel:v,initialWorkflowDefinition:x,onInitiatorPolicyChange:ee,onWorkflowChange:oe,showAiAssistant:se=!1,showDryRun:w=!0,templateId:ce}){let le=t.r(),ue=r.r(),T=n.i(),[E,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),we=(0,l.useRef)([]),Te=(0,l.useRef)([]),D=ae({directory:(0,l.useMemo)(()=>({listOrgUnits:async()=>we.current.map(e=>({id:e.id,name:e.name})),listPositions:async()=>Te.current.map(e=>({id:e.id,name:e.name})),searchMembers:async e=>$r(await(0,S.searchMemberOptions)(e)).map(e=>({email:e.email,id:e.memberId,name:e.name}))}),[]),initialState:{definition:a&&x!=null?ir(x):cr(),editingEdgeId:null,formDefinitionVersionId:null,formSchema:null,initiatorPolicyCel:a&&v!==void 0?v:null,selectedEdgeIds:[],selectedNodeId:a&&x!=null?x.nodes[0]?.id??`start`:`start`},layout:ur,onLayout:e=>{let t=Si(e,be.current);t&&Se(t)}}),O=D.state.definition,k=D.state.formDefinitionVersionId,A=D.state.initiatorPolicyCel,j=D.state.selectedNodeId,M=D.state.selectedEdgeIds,Ee=D.state.editingEdgeId,De=e=>D.replaceState(t=>({...t,definition:Wn(e,t.definition)})),Oe=e=>D.replaceState(t=>({...t,formDefinitionVersionId:Wn(e,t.formDefinitionVersionId)})),ke=e=>D.replaceState(t=>({...t,initiatorPolicyCel:Wn(e,t.initiatorPolicyCel)})),N=e=>D.replaceState(t=>({...t,selectedNodeId:Wn(e,t.selectedNodeId)})),Ae=e=>D.replaceState(t=>({...t,selectedEdgeIds:Wn(e,t.selectedEdgeIds)})),je=e=>D.replaceState(t=>({...t,editingEdgeId:Wn(e,t.editingEdgeId)})),[Me,P]=(0,l.useState)(null),[F,Ne]=(0,l.useState)(null);(0,l.useEffect)(()=>{Ne(null)},[j]);let[Pe,Fe]=(0,l.useState)(!0),[Ie,Le]=(0,l.useState)(!1),[Re,ze]=(0,l.useState)(!1),[Be,Ve]=(0,l.useState)([]),He=(0,l.useMemo)(()=>JSON.stringify({formDefinitionVersionId:k,initiatorPolicyCel:A,workflowDefinition:O}),[k,A,O]),Ue=!!me&&He!==me,[We,Ke]=(0,l.useState)(!1),[I,Je]=(0,l.useState)([]),[Ye,Ze]=(0,l.useState)([]),Qe=(0,l.useRef)(0),$e=(0,l.useRef)(new Set),[R,et]=(0,l.useState)([]),[z,tt]=(0,l.useState)([]),[nt,rt]=(0,l.useState)([]);we.current=R,Te.current=z;let[it,ot]=(0,l.useState)(!1),[st,ct]=(0,l.useState)(!1),[ut,dt]=(0,l.useState)(!1),[ft,pt]=(0,l.useState)(`{}`),[B,mt]=(0,l.useState)(null),[ht,gt]=(0,l.useState)(null),[vt,yt]=(0,l.useState)([]),[bt,xt]=(0,l.useState)(`loading`),[St,Ct]=(0,l.useState)(!1),[Tt,Et]=(0,l.useState)(!1),[V,Ot]=(0,l.useState)(null),[kt,At]=(0,l.useState)(!1),[jt,Mt]=(0,l.useState)(!1),Nt=Ue||kt?`保存並發布`:fe?`發布草稿`:`已發布`;(0,l.useEffect)(()=>{a?vn():yn()},[a,ce]),(0,l.useEffect)(()=>{function e(e){Ue&&(e.preventDefault(),e.returnValue=``)}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[Ue]),(0,l.useEffect)(()=>{Pn(O)},[O,I]),(0,l.useEffect)(()=>{De(e=>ir(e))},[O.edges,O.nodes]);function Pt(){(!Ue||window.confirm(`目前有尚未儲存的流程草稿,確定要離開嗎?`))&&le.push(ue.templates())}let H=(0,l.useMemo)(()=>O.nodes.find(e=>e.id===j)??null,[j,O.nodes]),It=H?Hr(H):!1,Rt=M.length>0||It,Gt=(0,l.useCallback)(()=>{D.getState().selectedEdgeIds.forEach(e=>D.dispatch({edgeId:e,type:`deleteEdge`})),H&&Hr(H)&&D.dispatch({nodeId:H.id,type:`deleteNode`})},[D,H]);(0,l.useEffect)(()=>{if(!Rt)return;function e(e){(e.key===`Delete`||e.key===`Backspace`)&&(Kr(e.target)||(e.preventDefault(),Gt()))}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[Rt,Gt]);let qt=(0,l.useMemo)(()=>O.edges.find(e=>e.id===Ee)??null,[Ee,O.edges]),U=(0,l.useMemo)(()=>M.length===1?O.edges.find(e=>e.id===M[0])??null:null,[M,O.edges]),Yt=(0,l.useMemo)(()=>M.map(e=>O.edges.find(t=>t.id===e)??null).filter(e=>!!e),[M,O.edges]),G=(0,l.useMemo)(()=>ve??Pr(A,ge),[A,ve,ge]),on=(0,l.useMemo)(()=>O.edges.map(e=>nr(e,O.nodes,M.includes(e.id))),[M,O.edges,O.nodes]),K=(0,l.useMemo)(()=>Z(Be,k)??Z(qr(E?.formVersions??[]),k),[k,Be,E?.formVersions]),sn=(0,l.useMemo)(()=>Qr(Be,K),[Be,K]),cn=K?.schema??null,ln=a?h??null:cn;(0,l.useEffect)(()=>{D.getState().formSchema!==ln&&D.replaceState(e=>({...e,formSchema:ln}))},[D,ln]);let dn=(0,l.useMemo)(()=>Ci(O),[O]);(0,l.useEffect)(()=>{let e=!0;return(0,S.listWorkflowWebhookEndpoints)({includeDeprecated:!0}).then(t=>{e&&(yt(t),xt(`ready`))}).catch(()=>{e&&xt(`unavailable`)}),()=>{e=!1}},[]);let q=kt&&V?V.schema:ln,fn=(0,l.useMemo)(()=>bt===`ready`?lt({definition:O,endpoints:vt,formFields:q?.fields??[]})[0]??null:null,[vt,bt,q,O]),pn=(0,l.useMemo)(()=>{let[e]=(0,g.readFieldAccessMatrix)(O,q).issues;return e?(0,S.readWorkflowLintMessage)(e.message,O,T):null},[T,q,O]),mn=fn??pn,hn=(0,l.useMemo)(()=>O.nodes.map(e=>Qn(e,I,R,z,e.id===j,G,q)),[G,I,R,z,j,q,O.nodes]),gn=(0,l.useMemo)(()=>(0,C.hasConfiguredConditionEdges)(O),[O]),_n=(0,l.useMemo)(()=>Fr(G),[G]);(0,l.useEffect)(()=>{a&&oe?.(O)},[a,O]),(0,l.useEffect)(()=>{a&&ee?.(A)},[a,A]);async function vn(){Fe(!0),P(null);try{let e=await(0,y.readOrganizationDirectory)();et(e.orgUnits),tt(e.positions),rt(e.memberships)}catch(e){P(L(e,T))}finally{Fe(!1)}}async function yn(){Fe(!0),P(null),Ne(null);try{let[e,t]=await Promise.all([(0,S.readTemplateDesigner)(ce),(0,y.readOrganizationDirectory)()]),n=e.versions.find(e=>e.status===`DRAFT`)??null,r=n??e.versions[0]??null;de(e),pe(n),et(t.orgUnits),tt(t.positions),rt(t.memberships),Ve(qr(e.formVersions));let i=ir(r?.workflowDefinition??cr()),a=r?.formDefinitionVersionId??e.formVersions[0]?.id??null,o=r?.initiatorPolicyCel??null;De(i),Oe(a),ke(o),he(JSON.stringify({formDefinitionVersionId:a,initiatorPolicyCel:o,workflowDefinition:i})),_e(r&&!e.template.currentVersionId&&!r.initiatorPolicyCel&&lr(r.workflowDefinition)?`NONE`:null),ye(null),N(r?.workflowDefinition.nodes[0]?.id??`start`),Ae([]),je(null),Ot(null),At(!1)}catch(e){P(L(e,T))}finally{Fe(!1)}}async function bn(e){ze(!0),P(null);try{let t=await(0,S.searchPublishedFormVersionOptions)(e);Ve(Qr(qr(t),K))}catch(e){P(L(e,T))}finally{ze(!1)}}async function J(e){Ke(!0),P(null);let t=++Qe.current;try{let n=$r(await(0,S.searchMemberOptions)(e));Je(e=>fi(e,n)),t===Qe.current&&Ze(n)}catch(e){t===Qe.current&&P(L(e,T))}finally{t===Qe.current&&Ke(!1)}}async function Pn(e){let t=mi(e),n=s.n(t.filter(e=>!I.some(t=>t.memberId===e&&!t.unresolved)),$e.current);if(n.length===0)return;let{profiles:r,skippedIds:i}=await s.r(n,S.resolveMemberOptions),a=new Set(r.map(e=>e.memberId)),o=n.filter(e=>!a.has(e)&&!i.includes(e));o.forEach(e=>$e.current.add(e)),Je(e=>fi(e,[...$r(r),...[...o,...i].map(ei)]))}async function Gn(e){Le(!0),P(null);try{let t=Ci(O),n=Fr(G),r=e?mn:null;if(t||n||r){let e=t??n??r??`流程設定未完成`;throw P(e),Error(e)}if(kt&&V!==null)await(0,S.composeApprovalTemplateWithForm)({category:E?.template.category??null,categoryId:E?.template.categoryId??null,formDefinitionId:K?.formDefinitionId??null,formDescription:null,formName:K?.formName??E?.template.name??`表單`,initiatorPolicyCel:A,notificationConfig:null,publish:e,schema:V.schema,slaDefaults:null,templateDescription:null,templateId:ce??null,templateName:E?.template.name??`模板`,uiSchema:V.uiSchema,workflowDefinition:O}),At(!1),Ot(null),await yn();else{let t=fe??await(0,S.forkApprovalTemplate)(ce),n=await(0,S.updateApprovalTemplateDraft)({formDefinitionVersionId:k,initiatorPolicyCel:A,versionId:t.id,workflowDefinition:O});pe(n),e&&await(0,S.publishApprovalTemplateVersion)(n.id),await yn()}}catch(e){P(L(e,T,O))}finally{Le(!1)}}async function qn(){await Gn(!1)}async function Jn(){await Gn(!0)}function Yn(){pt(JSON.stringify(wt(q),null,2)),mt(null),gt(null),ot(!0)}function Xn(){ut||ot(!1)}async function Zn(){dt(!0),gt(null),mt(null);try{let e=Jr(ft),t=await(0,S.dryRunApprovalWorkflow)({formData:e,initiatorMemberId:Ln,initiatorMetadataSnapshot:ai(Ln,nt),workflowDefinition:O});mt(t)}catch(e){gt(L(e,T))}finally{dt(!1)}}async function Y(){if(Et(!0),V!==null)return;let e=K?.formDefinitionId??null;if(!e)Ot({schema:Vn,uiSchema:Hn});else{Mt(!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;Ot({schema:n?.schema??Vn,uiSchema:n?.uiSchema??Hn})}catch(e){P(L(e,T))}finally{Mt(!1)}}}function $n(e){let t=(0,b.applyNodeChanges)(e,hn);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 er(e){Br(e,O.nodes)&&e.source&&e.target&&D.dispatch({source:e.source,target:e.target,type:`connectEdge`})}function tr(e,t){e.stopPropagation(),Ae(n=>e.shiftKey||e.metaKey||e.ctrlKey?Vr(n,t.id):[t.id]),N(null)}function rr(){je(null)}function ar(e){D.dispatch({nodeType:e,type:`addNode`})}function or(e){H&&D.dispatch({label:e,nodeId:H.id,type:`renameNode`})}function X(e){if(!H||H.type!==`userTask`)return;let t=H.id,n=H.data.decisionPolicy;D.dispatch({approverResolver:e,nodeId:t,type:`setUserTaskApprover`}),Ne(null),(0,C.isOrgManagerChainDecisionPolicyInvalid)(e,n)?Ne({message:`主管鏈會依序加入多位主管,簽核方式已改為「依序簽核」。`,nodeId:t,policyType:`SEQUENTIAL`}):(0,C.isDecisionPolicyUnsatisfiable)(n,e)&&Ne({message:`簽核者已變更為 ${(0,C.readDesignTimeApproverCount)(e)} 位,不足原本設定的 ${n?.type===`QUORUM`?n.threshold:0} 位門檻,簽核政策已重設為單人簽核,請重新設定。`,nodeId:t,policyType:`SINGLE`})}function sr(e){H&&H.type===`userTask`&&D.dispatch({nodeId:H.id,resubmitStrategy:e,type:`setUserTaskReturnResubmitStrategy`})}function Tr(e){H&&H.type===`userTask`&&D.dispatch({nodeId:H.id,requireComment:e,type:`setUserTaskReturnRequireComment`})}function Q(e){H&&H.type===`userTask`&&D.dispatch({nodeId:H.id,sla:e,type:`setUserTaskSla`})}function Nr(e){H&&H.type===`userTask`&&D.dispatch({excludeInitiator:e,nodeId:H.id,type:`setUserTaskExcludeInitiator`})}function Ir(e){if(!H||H.type!==`userTask`)return;Ne(null);let t=e.type===`QUORUM`?{...e,threshold:(0,C.composeQuorumThreshold)(e.threshold,e.thresholdType)}:e;D.dispatch({decisionPolicy:t,nodeId:H.id,type:`setUserTaskDecisionPolicy`})}function Rr(e){H&&H.type===`userTask`&&D.dispatch({...e,nodeId:H.id,type:`setUserTaskOptions`})}function Ur(e){H&&H.type===`serviceTask`&&D.dispatch({action:e,nodeId:H.id,type:`setServiceAction`})}function Wr(e){ye(e.mode===`ALL`||e.mode===`CUSTOM`?null:e),_e(e.mode===`ALL`||e.mode===`CUSTOM`?null:e.mode),ke(Lr(e,R))}function Gr(e){H&&H.type!==`startEvent`&&D.dispatch({nodeId:H.id,triggerMode:e,type:`setNodeTriggerMode`})}function Yr(e,t){D.dispatch({edgeId:e,isDefault:t,type:`setEdgeDefault`})}function $({edgeId:e,fieldKey:t,operator:n,value:r}){D.dispatch({edgeId:e,fieldKey:t,operator:n,type:`setEdgeCondition`,value:r})}function ii(){D.dispatch({type:`autoLayout`})}return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`style`,{children:Kt}),a?null:(0,d.jsx)(u.PageHeader,{children:(0,d.jsxs)(p.default,{description:Lt({draftVersion:fe?.version??null,hasPublishedVersion:!!E?.template.currentVersionId,publishedVersion:E?.versions.find(e=>e.id===E.template.currentVersionId)?.version??null}),onBackClick:Pt,title:E?.template.name??`流程設計器`,children:[se?(0,d.jsx)(u.Button,{disabled:!e,onClick:()=>Ct(e=>!e),variant:St?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`}):null,(0,d.jsx)(u.Button,{"aria-label":`儲存草稿`,disabled:Ie||!!dn||!!_n,icon:m.SaveIcon,iconType:`icon-only`,onClick:()=>void qn(),variant:`base-secondary`,children:`儲存草稿`}),w?(0,d.jsx)(u.Button,{disabled:Pe||!!dn||!!_n,icon:m.EyeIcon,iconType:`leading`,onClick:Yn,variant:`base-secondary`,children:`試跑流程`}):null,(0,d.jsx)(u.Button,{disabled:Ie||!fe&&!Ue&&!kt||!!dn||!!_n||!!mn,icon:m.CheckedIcon,iconType:`leading`,onClick:()=>void Jn(),variant:`base-primary`,children:Nt})]})}),(0,d.jsx)(u.SectionGroup,{children:(0,d.jsx)(u.Section,{children:(0,d.jsxs)(`div`,{style:zt,children:[Me?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:Me}):null,F&&F.nodeId===H?.id&&H.type===`userTask`&&(H.data.decisionPolicy?.type??`SINGLE`)===F.policyType?(0,d.jsx)(u.Typography,{color:`text-warning`,variant:`body`,children:F.message}):null,dn?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:dn}):null,_n?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:_n}):null,!dn&&mn?(0,d.jsxs)(u.Typography,{color:`text-error`,variant:`body`,children:[`發布前需修正:`,mn]}):null,a?null:(0,d.jsx)(`div`,{style:W,children:(0,d.jsx)(i.t,{hintText:gn?`已設定條件分流條件。請先移除所有條件,才能更換綁定表單版本。`:void 0,label:`綁定表單版本`,name:`formDefinitionVersionId`,required:!0,children:(0,d.jsxs)(`div`,{style:tn,children:[(0,d.jsx)(`div`,{style:nn,children:(0,d.jsx)(u.AutoComplete,{asyncData:!0,disabled:Pe||gn,disabledOptionsFilter:!0,emptyText:`沒有符合的已發布表單版本`,isForceClearable:!!k&&!gn,loading:Re,loadingText:`搜尋表單版本中...`,mode:`single`,onChange:e=>{gn||Oe(e?.id??null)},onClear:()=>{gn||Oe(null)},onSearch:bn,onVisibilityChange:e=>{e&&!gn&&bn(``)},options:[...sn],placeholder:`選擇已發布表單版本`,searchDebounceTime:300,value:K})}),(0,d.jsx)(u.Button,{disabled:Pe,onClick:()=>{Y()},style:rn,variant:`base-secondary`,children:`編輯表單`})]})})}),(0,d.jsxs)(`div`,{style:Bt,children:[(0,d.jsx)(`div`,{ref:be,style:Vt,children:(0,d.jsxs)(b.ReactFlow,{connectionMode:b.ConnectionMode.Strict,edges:on,fitView:!0,isValidConnection:e=>Br(e,O.nodes),nodeTypes:Un,nodes:hn,deleteKeyCode:null,multiSelectionKeyCode:[`Shift`,`Meta`,`Control`],onConnect:er,onEdgeClick:tr,onNodeClick:(e,t)=>{N(t.id),Ae([])},onNodesChange:$n,onPaneClick:()=>{N(null),Ae([])},onViewportChange:Se,viewport:xe,children:[(0,d.jsx)(b.Background,{}),(0,d.jsx)(`style`,{children:Xt}),(0,d.jsx)(b.Controls,{children:Rt?(0,d.jsx)(b.ControlButton,{"aria-label":`刪除選取項目`,className:`workflow-selection-delete-control`,onClick:Gt,style:Ht,title:`刪除選取項目`,children:(0,d.jsx)(`span`,{style:Ut,children:(0,d.jsx)(u.Icon,{color:`error`,icon:m.TrashIcon,size:16})})}):null}),(0,d.jsx)(Kn,{onApplyAutoLayout:ii}),(0,d.jsx)(b.MiniMap,{})]})}),(0,d.jsxs)(`div`,{className:Wt,style:Zt,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:`流程工具`}),a&&se?(0,d.jsxs)(`div`,{style:an,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`AI 協助`}),(0,d.jsx)(`div`,{style:en,children:(0,d.jsx)(u.Button,{disabled:!e,onClick:()=>Ct(e=>!e),size:`sub`,variant:St?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`})})]}):null,(0,d.jsxs)(`div`,{style:an,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`動作節點`}),(0,d.jsx)(`div`,{style:en,children:Sn.map(e=>(0,d.jsx)(u.Button,{icon:e.icon,iconType:`leading`,onClick:()=>ar(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,d.jsxs)(`div`,{style:an,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`流程控制`}),(0,d.jsx)(`div`,{style:en,children:Cn.map(e=>(0,d.jsx)(u.Button,{icon:e.icon,iconType:`leading`,onClick:()=>ar(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,d.jsxs)(`div`,{style:an,children:[(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`caption`,children:`表單欄位`}),(0,d.jsx)(`div`,{style:en,children:(0,d.jsx)(u.Button,{disabled:q===null,onClick:()=>ct(!0),size:`sub`,title:q===null?un:void 0,variant:`base-secondary`,children:`欄位總覽`})})]}),Yt.length>1?hi(Yt):null,Yt.length===1&&U?_i(U):null,Yt.length===0&&H?si(H):null]})]})]})})}),vi(qt),!a&&w?oi():null,(0,d.jsx)(Ge,{definition:O,formSchema:q,language:T,onApply:e=>D.dispatch({entries:e,type:`setFieldAccessMatrix`}).error,onClose:()=>ct(!1),open:st}),se&&e?(0,d.jsx)(Ce,{controller:D,onClose:()=>Ct(!1),open:St}):null,a?null:(0,d.jsx)(f.default,{headerTitle:`編輯表單`,isHeaderDisplay:!0,onClose:()=>Et(!1),open:Tt,size:`wide`,children:(0,d.jsxs)(`div`,{style:Rn,children:[(0,d.jsx)(`div`,{style:zn,children:jt?(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`載入中…`}):(0,d.jsx)(c.t,{onChange:e=>{Ot(e)},value:V??{schema:Vn,uiSchema:Hn}})}),(0,d.jsxs)(`div`,{style:Bn,children:[(0,d.jsx)(u.Button,{disabled:jt,onClick:()=>{V!==null&&(At(!0),D.replaceState(e=>({...e,formSchema:V.schema}))),Et(!1)},variant:`base-primary`,children:`套用`}),(0,d.jsx)(u.Button,{onClick:()=>Et(!1),variant:`base-secondary`,children:`取消`})]})]})})]});function oi(){let e={formFields:q?.fields??[],memberName:e=>I.find(t=>t.memberId===e&&!t.unresolved)?.displayName??null,orgUnits:R,positions:z};return(0,d.jsx)(u.Modal,{cancelText:`關閉`,confirmText:`執行試跑`,loading:ut,modalType:`standard`,onCancel:Xn,onClose:Xn,onConfirm:()=>void Zn(),open:it,showModalFooter:!0,showModalHeader:!0,size:`wide`,supportingText:`使用 ${Ln} 與範例表單資料模擬目前畫布流程,不會建立案件。`,title:`試跑流程`,children:(0,d.jsxs)(`div`,{style:W,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:ft})}),ht?(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:ht}):null,B?(0,d.jsxs)(`div`,{style:Qt,children:[(0,d.jsx)(u.Typography,{color:B.valid?`text-success`:`text-error`,variant:`label-primary-highlight`,children:B.valid?`試跑通過`:`試跑失敗`}),B.errors.map(e=>(0,d.jsx)(u.Typography,{color:`text-error`,variant:`body`,children:e},e)),B.steps.map(t=>(0,d.jsxs)(`div`,{style:$t,children:[(0,d.jsxs)(u.Typography,{variant:`label-primary-highlight`,children:[t.nodeLabel,` · `,Xr(t.status)]}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[Zr(t.nodeType),t.assigneeMemberId?` · 處理者:${Dt(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`?[]:yi(O,t.nodeId,vt)).map(e=>(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`caption`,children:[`將送出 Webhook:`,e.label]},e.key))]},t.id))]}):null]})})}function si(e){return(0,d.jsxs)(`div`,{style:W,children:[(0,d.jsx)(u.Typography,{component:`h2`,variant:`h3`,children:`節點屬性`}),(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[xn[e.type],` · `,e.id]}),(0,d.jsx)(i.t,{label:`顯示名稱`,name:`nodeLabel`,required:!0,children:(0,d.jsx)(u.Input,{onChange:e=>or(e.target.value),value:e.data.label,variant:`base`})}),e.type===`startEvent`?ci():null,e.type===`startEvent`?null:li(e),e.type===`userTask`?di(e):null,e.type===`serviceTask`?pi(e):null]})}function ci(){let e=G.mode===`CUSTOM`?[...Fn,In]:[...Fn],t=G.mode===`ORG_UNIT`||G.mode===`ORG_UNIT_POSITION`?ni(R,G.orgUnitId??``):null,n=G.mode===`ORG_UNIT_POSITION`?ri(z,G.positionId??``):null,r=G.mode===`ORG_UNIT_POSITION`?ui({includeDescendants:!!G.includeDescendants,memberships:nt,orgUnitId:G.orgUnitId??``,orgUnits:R,positions:z}):[];return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i.t,{hintText:G.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=Mr(e?.id??null),n=zr(t);_e(t===`ALL`?null:t),ye(t===`ALL`?null:n),ke(Lr(n,R))},options:e,placeholder:`選擇誰可以發起`,value:Z(e,G.mode)})}),G.mode===`ORG_UNIT`||G.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`組織`,name:`initiatorOrgUnitId`,required:!0,children:(0,d.jsx)(o.n,{name:`initiatorOrgUnitId`,onChange:e=>Wr({...G,orgUnitId:e?.id??``,positionId:``,value:e?.id??``}),orgUnits:R,placeholder:`選擇組織`,value:t})}):null,G.mode===`ORG_UNIT`||G.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`包含下層`,name:`initiatorIncludeDescendants`,children:(0,d.jsx)(u.Toggle,{checked:!!G.includeDescendants,onChange:e=>Wr({...G,includeDescendants:e.target.checked,...G.mode===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,G.mode===`ORG_UNIT_POSITION`?(0,d.jsx)(i.t,{label:`職位`,name:`initiatorPositionId`,required:!0,children:(0,d.jsx)(o.r,{disabled:!G.orgUnitId?.trim(),name:`initiatorPositionId`,onChange:e=>Wr({...G,positionId:e?.id??``}),placeholder:G.orgUnitId?.trim()?`選擇職位`:`請先選擇組織`,positions:r,value:n})}):null]})}function li(e){let t=O.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:Gr(dr(e?.id??null)),options:[...wn],readOnly:n,value:Z(wn,r)})})}function di(e){let t=e.data.approverResolver,n=Er(t.type),r=t.type===`DIRECT`?t.memberIds.map(e=>ti(I,e)):[],a=t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?ni(R,t.orgUnitId):null,s=t.type===`POSITION`||t.type===`ORG_UNIT_POSITION`?ri(z,t.positionId):null,c=t.type===`ORG_UNIT_POSITION`?ui({includeDescendants:!!t.includeDescendants,memberships:nt,orgUnitId:t.orgUnitId,orgUnits:R,positions:z}):[],l=t.type===`DYNAMIC_FORM`?Ft(q,t.formPath):null,f=t.type===`ORG_MANAGER`?Ar(t.levelsUp):kn[0],p=t.type===`ORG_MANAGER`||t.type===`ORG_MANAGER_CHAIN`||t.type===`ORG_UNIT_MANAGER`?t.fallback??{type:`NONE`}:{type:`NONE`},m=(0,te.readUnsupportedApproverFallbackType)(p),h=m===null?An:[...An,jn],g=t.type===`ORG_MANAGER_CHAIN`?Xe(z,t.minPositionLevel):[],_=p.type===`DIRECT`&&p.memberId?ti(I,p.memberId):null,v=p.type===`POSITION`?ri(z,p.positionId):null,y=e.data.returnBehavior.resubmitStrategy??`RESTART`,b=e.data.sla??null,x=e.data.excludeInitiator??null,S=b?(0,C.readSlaDurationParts)(b.duration):null,ee=S?.unit??`DAY`,ae=br(b?.warningAt??null),oe=Ar(b?.escalateLevelsUp??1),se=pr(e.data.decisionPolicy),w=hr(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=>X(Dr(e?.id??null,z)),options:[...Dn],value:Z(Dn,n)})}),t.type===`DIRECT`?(0,d.jsx)(i.t,{hintText:re(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:We,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>X({memberIds:e.map(e=>e.id),type:`DIRECT`}),onSearch:J,onVisibilityChange:e=>{e&&(Ze([]),J(``))},options:[...fi(r,Ye)],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=>X({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=>X({baseFromInitiator:!0,...t.fallback?{fallback:t.fallback}:{},levelsUp:jr(e?.id??null).value,type:`ORG_MANAGER`}),options:[...kn],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=>X({...t,minPositionLevel:Number(e?.id??t.minPositionLevel)}),options:[...g],value:Z(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=>X(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:R,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=>X({...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`&&X(kr(t,Or(e?.id??null)))},options:[...h],value:m===null?Z(An,p.type):jn})}),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:We,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>X(kr(t,{allowInitiatorSelfApproval:p.allowInitiatorSelfApproval,memberId:e?.id??``,type:`DIRECT`})),onSearch:J,onVisibilityChange:e=>{e&&(Ze([]),J(``))},options:[...fi(Ye,_?[_]:[])],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=>X(kr(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=>X(kr(t,{allowInitiatorSelfApproval:p.allowInitiatorSelfApproval,positionId:e?.id??``,type:`POSITION`})),placeholder:`選擇職位`,positions:z,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=>X(kr(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=>X({...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=>X({positionId:e?.id??``,type:`POSITION`}),placeholder:`選擇職位`,positions:z,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=>X({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=>Ir(mr(t?.id??null,e.data.decisionPolicy)),options:[...ne.filter(e=>t.type!==`ORG_MANAGER_CHAIN`||e.id===`SEQUENTIAL`||e.id===`PARALLEL_ALL`)],value:ie(se)})}),se===`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=>Ir({threshold:w.threshold,thresholdType:gr(e?.id??null),type:`QUORUM`}),options:[...On],value:Z(On,w.thresholdType)})}),(0,d.jsx)(i.t,{hintText:w.thresholdType===`PERCENTAGE`?`達到簽核者總數的這個百分比即通過,換算人數時無條件進位;超過 100 的輸入會自動夾至 100。`:`達到這個同意人數即通過;門檻超過實際簽核者人數時,這一關將永遠無法通過,請勿設定超過實際簽核者人數。`,label:w.thresholdType===`PERCENTAGE`?`門檻百分比`:`門檻人數`,name:`quorumThreshold`,required:!0,children:(0,d.jsx)(u.Input,{id:`quorumThreshold`,inputProps:w.thresholdType===`PERCENTAGE`?{max:100,min:1}:{min:1},inputType:`number`,name:`quorumThreshold`,onChange:e=>Ir({threshold:(0,C.composeQuorumThreshold)(Number(e.target.value),w.thresholdType),thresholdType:w.thresholdType,type:`QUORUM`}),value:String(w.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=>sr(fr(e?.id??null)),options:[...Tn],value:Z(Tn,y)})}):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=>Tr(e.target.checked)})}):null,(0,d.jsx)(i.t,{hintText:`開啟後可設定簽核期限,逾時將依下方設定處理。`,label:`啟用時效`,name:`slaEnabled`,children:(0,d.jsx)(u.Toggle,{checked:!!b,inputProps:{id:`slaEnabled`,name:`slaEnabled`},onChange:e=>Q(e.target.checked?C.DEFAULT_SLA_CONFIG:null)})}),b&&!S?(0,d.jsx)(i.t,{hintText:`此期限混用了日與時,無法在表單中編輯。請改以單一單位設定,或透過 API 維護。`,label:`時效期限`,name:`slaDurationRaw`,children:(0,d.jsx)(u.Input,{disabled:!0,value:b.duration,variant:`base`})}):null,b&&S?(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=>Q(Sr(b,{unit:ee,value:Number(e.target.value)})),value:String(S.value),variant:`base`})}),(0,d.jsx)(i.t,{label:`期限單位`,name:`slaDurationUnit`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Q(Sr(b,{unit:_r(e?.id??null),value:S.value})),options:[...C.SLA_DURATION_UNIT_OPTIONS],value:Z(C.SLA_DURATION_UNIT_OPTIONS,ee)})})]}):null,b&&ee===`DAY`?(0,d.jsx)(i.t,{hintText:`工作日會跳過週末與行事曆上的假日,補班日仍計為工作日;行事曆由系統管理者設定。`,label:`計算方式`,name:`slaCalendar`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Q({...b,calendar:vr(e?.id??null)}),options:[...C.SLA_CALENDAR_MODE_OPTIONS],value:Z(C.SLA_CALENDAR_MODE_OPTIONS,b.calendar??`CALENDAR`)})}):null,b?(0,d.jsx)(i.t,{label:`逾時處理`,name:`slaOnTimeout`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Q(Cr(b,yr(e?.id??null))),options:[...C.SLA_TIMEOUT_ACTION_OPTIONS],value:Z(C.SLA_TIMEOUT_ACTION_OPTIONS,b.onTimeout)})}):null,b?.onTimeout===`ESCALATE`?(0,d.jsx)(i.t,{hintText:`逾時後改派給簽核者的上層主管,只會升級一次。`,label:`升級層級`,name:`slaEscalateLevelsUp`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Q({...b,escalateLevelsUp:jr(e?.id??null).value}),options:[...kn],value:oe})}):null,b?(0,d.jsx)(i.t,{hintText:`在期限到達前先送出一次提醒。`,label:`預警提醒`,name:`slaWarningAt`,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Q(wr(b,xr(e?.id??null).value)),options:[...En],value:ae})}):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=>Rr({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=>Rr({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=>Rr({allowAddSigner:e.target.checked})})}),(0,d.jsx)(i.t,{hintText:`開啟後,申請人本人(含其代理人)不會成為此關的簽核人,也不能被轉簽或加簽到此關。`,label:`申請人不可簽核自己的單`,name:`excludeInitiator`,children:(0,d.jsx)(u.Toggle,{checked:!!x,inputProps:{id:`excludeInitiator`,name:`excludeInitiator`},onChange:e=>Nr(e.target.checked?Nn:null)})}),x?(0,d.jsx)(i.t,{label:`排除後沒有簽核人時`,name:`excludeInitiatorWhenEmpty`,required:!0,children:(0,d.jsx)(u.Select,{clearable:!1,onChange:e=>Nr({whenEmpty:Z(Mn,e?.id??null)?.id??Nn.whenEmpty}),options:[...Mn],value:Z(Mn,x.whenEmpty)})}):null,(0,d.jsx)(qe,{definition:O,language:T,node:e,onOpenMatrix:()=>ct(!0),onRemoveLegacy:()=>{D.dispatch({nodeId:e.id,type:`removeLegacyFieldPermissions`})},openDisabledReason:q===null?un:null})]})}function pi(e){let t=e.data.action,n=Mi(t).map(e=>ti(I,e)),r=t.type===`NOTIFY`&&t.recipients.type!==`DIRECT`?gi(t.recipients,I,R,z,q):null;function a(e){let n={memberIds:[...e],type:`DIRECT`};Ur(t.type===`NOTIFY`?{...t,recipients:n}:{channels:[`IN_APP`],recipients:n,type:`NOTIFY`})}function o(e){t.type===`NOTIFY`&&Ur({...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:We,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>a(e.map(e=>e.id)),onSearch:J,onVisibilityChange:e=>{e&&(Ze([]),J(``))},options:[...fi(n,Ye)],overflowStrategy:`wrap`,placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:[...n]})}),t.type===`NOTIFY`&&!at(t.webhooks)?(0,d.jsxs)(`div`,{style:W,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`&&at(t.webhooks)?(0,d.jsx)(_t,{catalog:vt,catalogState:bt,formFields:q?.fields??null,onChange:o,targets:(0,C.readNotifyWebhookTargets)(t)}):null]})}function hi(e){return(0,d.jsxs)(`div`,{style:W,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 _i(e){let t=Ai(e,O.nodes);return(0,d.jsxs)(`div`,{style:W,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?bi(e):(0,d.jsx)(u.Typography,{color:`text-neutral`,variant:`body`,children:`這條線會直接把流程送到下一個節點。`})]})}function vi(e){return!e||!Ai(e,O.nodes)?null:(0,d.jsx)(u.Modal,{cancelText:`取消`,confirmButtonProps:{disabled:!e.data.isDefault&&!e.data.condition},confirmText:`完成`,modalType:`standard`,onCancel:rr,onClose:rr,onConfirm:rr,open:!!Ee,showModalFooter:!0,showModalHeader:!0,size:`regular`,supportingText:`條件分流的輸出連線需要指定條件,條件會直接顯示在線上。`,title:`條件設定`,children:bi(e)})}function bi(e){let t=Oi(e,O.nodes),n=wi(K?.schema??null),r=Ti(K?.schema??null,e.data.conditionFieldKey??null),a=(0,C.readConditionOperatorOptionsForField)(r),o=Ei(r),s=Z(a,e.data.conditionOperator??null),c=!e.data.isDefault&&!e.data.condition;return(0,d.jsxs)(`div`,{style:W,children:[(0,d.jsxs)(u.Typography,{color:`text-neutral`,variant:`body`,children:[`畫布上的這條線目前會顯示「`,(0,d.jsx)(`span`,{style:{color:c?Jt:void 0},children:t??`請設定條件`}),`」。`]}),(0,d.jsx)(u.Toggle,{checked:!!e.data.isDefault,label:`其他情況走這條`,onChange:t=>Yr(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:[K?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=>$({edgeId:e.id,fieldKey:t?.id??null,operator:null,value:null}),options:[...n],placeholder:`選擇條件欄位`,value:Z(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=>$({edgeId:e.id,operator:(0,C.readConditionOperator)(t?.id??null),value:null}),options:[...a],placeholder:`選擇判斷方式`,value:s})}),s&&Di(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=>$({edgeId:e.id,value:t?.id??null}),options:[...o],placeholder:`選擇條件值`,value:Z(o,e.data.conditionValue??null)}):(0,d.jsx)(u.Input,{onChange:t=>$({edgeId:e.id,value:t.target.value}),placeholder:`輸入要比對的值`,value:e.data.conditionValue??``,variant:`base`})}):null]})]})}}function Kn({onApplyAutoLayout:e}){function t(){e()}return(0,d.jsx)(b.Panel,{position:`top-right`,children:(0,d.jsx)(u.Button,{icon:m.DotGridIcon,iconType:`leading`,onClick:t,size:`sub`,variant:`base-secondary`,children:`自動排版`})})}function qn({data:e,selected:t,type:n}){let r=e.approverLines??[e.approverSummary??e.label],i=Jn(e),a=Yn(n,t);return(0,d.jsxs)(`div`,{style:a,children:[Zn(e),(0,d.jsx)(`div`,{style:yn,children:r.map((e,t)=>(0,d.jsx)(u.Typography,{component:`span`,ellipsis:!0,style:vn,title:e,variant:`label-primary`,children:e},`${e}_${t}`))}),(0,d.jsx)(u.Typography,{color:`text-neutral`,component:`span`,ellipsis:!0,style:vn,title:i,variant:`caption`,children:i}),e.fieldAccessTag?(0,d.jsx)(`span`,{children:(0,d.jsx)(u.Tag,{label:e.fieldAccessTag,readOnly:!0,size:`minor`})}):null]})}function Jn(e){return e.nodeKind===`startEvent`?e.initiatorPolicySummary??`所有人`:e.approverSummary||e.approverLines?e.label:e.nodeKind===`exclusiveGateway`?`條件在線上`:e.nodeKind===`parallelGateway`?`多條路徑同時進行`:xn[e.nodeKind]}function Yn(e,t){let n=Xn(e);return t?{...n,border:`1px solid var(--mzn-color-primary, #0057ff)`,boxShadow:on}:n}function Xn(e){return e===`exclusiveGateway`?pn:e===`parallelGateway`?mn:e===`startEvent`?gn:e===`endEvent`?_n:e===`userTask`?hn:G}function Zn(e){return!e.hasInput&&e.hasOutput?(0,d.jsx)(b.Handle,{id:J,position:b.Position.Right,type:`source`}):e.hasInput&&!e.hasOutput?(0,d.jsx)(b.Handle,{id:bn,position:b.Position.Left,type:`target`}):!e.hasInput&&!e.hasOutput?null:[(0,d.jsx)(b.Handle,{id:bn,position:b.Position.Left,type:`target`},`target`),(0,d.jsx)(b.Handle,{id:J,position:b.Position.Right,type:`source`},`source`)]}function Qn(e,t,n,r,i,a,o){let s=Y(e);return{data:{approverLines:_i(e,t,n,r,o),approverSummary:hi(e,t,n,r,o),fieldAccessTag:e.type===`userTask`?Ee(e):null,hasInput:Ur(e),hasOutput:Wr(e),initiatorPolicySummary:e.type===`startEvent`?Rr(a,n,r):null,label:e.data.label,nodeKind:e.type},height:s.height,handles:$n(e),id:e.id,initialHeight:s.height,initialWidth:s.width,position:e.position,selected:i,sourcePosition:b.Position.Right,targetPosition:b.Position.Left,type:e.type,width:s.width}}function Y(e){return e.type===`exclusiveGateway`||e.type===`parallelGateway`?{height:dn,width:q}:e.type===`serviceTask`?{height:K+(vi(e.data.action)-1)*cn,width:sn}:{height:K+(e.type===`userTask`&&Ee(e)!==null?ln:0),width:sn}}function $n(e){let t=Y(e);return[...Ur(e)?[er(t)]:[],...Wr(e)?[tr(t)]:[]]}function er({height:e}){let t=e/2-9/2;return{height:9,id:bn,position:b.Position.Left,type:`target`,width:9,x:-9/2,y:t}}function tr({height:e,width:t}){let n=e/2-9/2;return{height:9,id:J,position:b.Position.Right,type:`source`,width:9,x:t-9/2,y:n}}function nr(e,t,n){let r=Oi(e,t),i=Ai(e,t),a=i&&!e.data.isDefault&&!e.data.condition,o=a?Jt:i?qt:`#475569`,s=a?`#fef2f2`:i?`#eff6ff`:`#ffffff`,c=a?Jt:i?qt:U;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?Yt:void 0,opacity:1,stroke:U,strokeOpacity:1,strokeWidth:1.5},target:e.target,targetHandle:e.targetHandle,type:e.type??`smoothstep`}}function rr(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 ir(e){return sr(or(X(ar(e))))}function ar(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 or(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 X(e){let t=new Set(e.nodes.filter(e=>Gr(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 sr(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`?rr(e,`AND`):e);return n.some((t,n)=>t!==e.nodes[n])?{...e,nodes:n}:e}function cr(){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 lr(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 ur(e){let t=new x.graphlib.Graph;return t.setDefaultEdgeLabel(()=>({})),t.setGraph({rankdir:`LR`,ranksep:120}),e.nodes.forEach(e=>{t.setNode(e.id,Y(e))}),e.edges.forEach(e=>{t.setEdge(e.source,e.target)}),x.layout(t),{...e,nodes:e.nodes.map(e=>{let n=t.node(e.id);return n?{...e,position:{x:n.x-Y(e).width/2,y:n.y-Y(e).height/2}}:e})}}function Z(e,t){return t?e.find(e=>e.id===t)??null:null}function dr(e){return e===`OR`?`OR`:`AND`}function fr(e){return e===`FROM_RETURN_POINT`?`FROM_RETURN_POINT`:`RESTART`}function pr(e){return e?.type??`SINGLE`}function mr(e,t){return e===`QUORUM`?t?.type===`QUORUM`?t:{threshold:C.DEFAULT_QUORUM_THRESHOLD,thresholdType:`COUNT`,type:`QUORUM`}:e===`PARALLEL_ALL`||e===`PARALLEL_ANY`||e===`SEQUENTIAL`?{type:e}:{type:`SINGLE`}}function hr(e){return e?.type===`QUORUM`?{threshold:Number.isFinite(e.threshold)?e.threshold:C.DEFAULT_QUORUM_THRESHOLD,thresholdType:gr(e.thresholdType??null)}:{threshold:C.DEFAULT_QUORUM_THRESHOLD,thresholdType:`COUNT`}}function gr(e){return e===`PERCENTAGE`?`PERCENTAGE`:`COUNT`}function _r(e){return e===`HOUR`?`HOUR`:`DAY`}function vr(e){return e===`BUSINESS_DAY`?`BUSINESS_DAY`:`CALENDAR`}function yr(e){return C.SLA_TIMEOUT_ACTION_OPTIONS.find(t=>t.id===e)?.id??`REMIND`}function br(e){return En.find(t=>t.value===e)??En[0]}function xr(e){return En.find(t=>t.id===e)??En[0]}function Sr(e,t){let n=Number.isFinite(t.value)?Math.trunc(t.value):1,r=(0,C.composeSlaDuration)({unit:t.unit,value:n});return{...e,calendar:t.unit===`DAY`?e.calendar??`CALENDAR`:`CALENDAR`,duration:r}}function Cr(e,t){return t===`ESCALATE`?{...e,escalateLevelsUp:e.escalateLevelsUp??1,onTimeout:t}:{...Tr(e,`escalateLevelsUp`),onTimeout:t}}function wr(e,t){return t===null?Tr(e,`warningAt`):{...e,warningAt:t}}function Tr(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function Er(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 Dr(e,t){let n=Er(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:Ze(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 Or(e){let t=Q(e);return t===`DIRECT`?{memberId:``,type:`DIRECT`}:t===`POSITION`?{positionId:``,type:`POSITION`}:{type:`NONE`}}function kr(e,t){return e.type===`ORG_MANAGER`||e.type===`ORG_MANAGER_CHAIN`||e.type===`ORG_UNIT_MANAGER`?{...e,fallback:t}:e}function Ar(e){return kn.find(t=>t.value===e)??kn[0]}function jr(e){return kn.find(t=>t.id===e)??kn[0]}function Mr(e){return e===`ORG_UNIT`||e===`ORG_UNIT_POSITION`||e===`NONE`?e:`ALL`}function Nr(e){let t=e?.trim();if(!t)return{mode:`ALL`,value:``};let n=Ir(t,/"([^"]+)" in subject\.orgUnitIds/gu),r=Ir(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 Pr(e,t){let n=Nr(e);return!t||t===`ALL`||t===`NONE`?t===`ALL`||t===`NONE`?{mode:t,value:``}:n:n.mode===t?n:zr(t)}function Fr(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 Ir(e,t){return[...e.matchAll(t)].map(e=>e[1]).filter(e=>!!e)}function Lr(e,t){if(e.mode===`ALL`||e.mode===`NONE`)return null;let n=e.orgUnitId?.trim()??``;if(!n)return null;let r=di(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 Rr(e,t,n){return e.mode===`NONE`?`未設定`:e.mode===`ORG_UNIT`?e.orgUnitId?`組織:${$(t,e.orgUnitId)}`:`指定組織`:e.mode===`ORG_UNIT_POSITION`?e.orgUnitId&&e.positionId?`組織職位:${$(t,e.orgUnitId)} / ${ii(n,e.positionId)}`:`指定組織職位`:e.mode===`CUSTOM`?`既有自訂規則`:`所有人`}function zr(e){return{includeDescendants:!0,mode:e,orgUnitId:``,positionId:``,value:``}}function Br(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===J&&e.targetHandle===bn&&!!(n&&Wr(n))&&!!(r&&Ur(r))}function Vr(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function Hr(e){return e.type!==`startEvent`&&e.type!==`endEvent`}function Ur(e){return e.type!==`startEvent`}function Wr(e){return e.type!==`endEvent`&&!Gr(e)}function Gr(e){return e.type===`serviceTask`&&e.data.action.type===`NOTIFY`}function Kr(e){return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||!!e.closest(`[contenteditable="true"]`):!1}function qr(e){return e.map(e=>({formDefinitionId:e.formDefinitionId,formName:e.formName,id:e.id,name:Rt(e.formName,e.version),schema:e.schema}))}function Jr(e){let t=JSON.parse(e);if(!Yr(t))throw Error(`表單資料 JSON 必須是物件。`);return t}function Yr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Xr(e){return e===`COMPLETED`?`完成`:e===`PASSED`?`通過`:e===`SKIPPED`?`略過`:e===`STOPPED`?`已停止`:e===`WAITING`?`將等待簽核`:e}function Zr(e){return e in xn?xn[e]:e}function Qr(e,t){return t&&!e.some(e=>e.id===t.id)?[t,...e]:e}function $r(e){return e.map(e=>({displayName:e.name,email:e.email,id:e.memberId,memberId:e.memberId,name:xi(e.name,e.email)}))}function ei(e){return{displayName:`未知會員`,email:``,id:e,memberId:e,name:`未知會員`,unresolved:!0}}function ti(e,t){return e.find(e=>e.memberId===t)??ei(t)}function ni(e,t){let n=e.find(e=>e.id===t);return n?o.a(n):null}function ri(e,t){let n=e.find(e=>e.id===t);return n?o.o(n):null}function $(e,t){return ni(e,t)?.name??`未指定組織`}function ii(e,t){return ri(e,t)?.name??`未指定職位`}function ai(e,t){let n=oi(),r=t.filter(t=>t.memberId===e&&si(t,n)),i=r.reduce((e,t)=>e&&ci(e,t)<=0?e:t,null);return{customFields:{},managerMemberId:`member-002`,memberId:e,orgCode:`HQ`,orgUnitIds:li(r.map(e=>e.orgUnitId)),positionId:i?.positionId??null,positionIds:li(r.map(e=>e.positionId)),primaryOrgUnitId:i?.orgUnitId??null,roles:[`manager`]}}function oi(){return new Date().toISOString().slice(0,10)}function si(e,t){return e.effectiveFrom<=t&&(!e.effectiveTo||e.effectiveTo>=t)}function ci(e,t){return e.isPrimary===t.isPrimary?t.effectiveFrom.localeCompare(e.effectiveFrom):e.isPrimary?-1:1}function li(e){return e.reduce((e,t)=>t&&!e.includes(t)?[...e,t]:e,[])}function ui({includeDescendants:e,memberships:t,orgUnitId:n,orgUnits:r,positions:i}){let a=new Set(di(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 di(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 fi(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 pi(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 mi(e){return[...new Set(e.nodes.flatMap(e=>e.type===`userTask`?pi(e.data.approverResolver):e.type===`serviceTask`?Mi(e.data.action):[]))]}function hi(e,t,n,r,i){return e.type===`userTask`?gi(e.data.approverResolver,t,n,r,i):null}function gi(e,t,n,r,i){return e.type===`DIRECT`?bi(e.memberIds,t,`未指定簽核者`):e.type===`ORG_MANAGER`?Ar(e.levelsUp).name:e.type===`ORG_MANAGER_CHAIN`?`主管鏈:簽到職等 ${e.minPositionLevel}`:e.type===`ORG_UNIT_MANAGER`?`組織主管:${$(n,e.orgUnitId)}`:e.type===`ORG_UNIT_MEMBER`?`組織任一人:${$(n,e.orgUnitId)}`:e.type===`ORG_UNIT_POSITION`?`組織職位:${$(n,e.orgUnitId)} / ${ii(r,e.positionId)}`:e.type===`POSITION`?`職位:${ii(r,e.positionId)}`:e.type===`DYNAMIC_FORM`?It(i,e.formPath):`自訂表達式`}function _i(e,t,n,r,i){if(e.type!==`serviceTask`)return null;let a=e.data.action,o=a.type===`NOTIFY`&&a.recipients.type!==`DIRECT`?[gi(a.recipients,t,n,r,i)]:Mi(a).map(e=>ti(t,e).name),s=(0,C.readNotifyWebhookTargets)(a).length,c=[...o,...s?[`Webhook ${s} 個`]:[]];return c.length?c:[`未指定知會對象`]}function vi(e){let t=e.type===`NOTIFY`&&e.recipients.type!==`DIRECT`?1:Mi(e).length,n=+!!(0,C.readNotifyWebhookTargets)(e).length;return Math.max(1,t+n)}function yi(e,t,n){let r=e.nodes.find(e=>e.id===t);return r?.type===`serviceTask`&&r.data.action.type===`NOTIFY`&&at(r.data.action.webhooks)?(0,C.readNotifyWebhookTargets)(r.data.action).map(e=>({key:e.id,label:et(n,e.endpoint)?.label??R(e.endpoint)})):[]}function bi(e,t,n){let r=e.map(e=>ti(t,e).name);return r.length===0?n:r.length<=2?r.join(`、`):`${r.slice(0,2).join(`、`)} 等 ${r.length} 人`}function xi(e,t){return a.t(e,t)}function Si(e,t){let n=t?.getBoundingClientRect();if(!n||e.nodes.length===0)return null;let r=e.nodes.reduce((e,t)=>{let n=Y(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,b.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 Ci(e){let t=e.nodes.find(e=>e.type===`userTask`&&!!(0,C.readApproverResolverIssue)(e.data.approverResolver)),n=e.nodes.find(e=>e.type===`userTask`&&!!(0,C.readExcludeInitiatorIssue)(e.data.excludeInitiator)),r=e.nodes.map(e=>(0,C.readNotifyServiceTaskIssue)(e)).find(e=>e!==null)??null,i=e.edges.find(t=>Ai(t,e.nodes)&&!t.data.isDefault&&!t.data.condition),a=e.nodes.find(e=>e.type===`userTask`&&(0,C.isOrgManagerChainDecisionPolicyInvalid)(e.data.approverResolver,e.data.decisionPolicy));return t&&t.type===`userTask`?(0,C.readApproverResolverIssue)(t.data.approverResolver):a&&a.type===`userTask`?`簽核節點「${a.data.label}」使用「沿主管鏈簽核」時,決策方式必須是「依序簽核或全部同意」,否則任一位主管簽完就會結案。`:n&&n.type===`userTask`?(0,C.readExcludeInitiatorIssue)(n.data.excludeInitiator):r||(i?`條件分流的每條輸出連線都需要先設定條件。`:null)}function wi(e){return e?.fields.map(e=>({fieldType:e.type,id:e.fieldKey,name:`${e.label} (${e.fieldKey})`}))??[]}function Ti(e,t){return t?e?.fields.find(e=>e.fieldKey===t)??null:null}function Ei(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 Di(e){return Pn.includes(e)}function Oi(e,t){if(e.data.label)return e.data.label;if(Ai(e,t))return ki(e);if(ji(e,t))return`同時進行`}function ki(e){return e.data.isDefault?`其他情況`:`請設定條件`}function Ai(e,t){return t.some(t=>t.id===e.source&&t.type===`exclusiveGateway`)}function ji(e,t){return t.some(t=>t.id===e.source&&t.type===`parallelGateway`)}function Mi(e){return e.type===`NOTIFY`&&e.recipients.type===`DIRECT`?e.recipients.memberIds:[]}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Gn}});
65
+ //# sourceMappingURL=designer-DESS0CMl.cjs.map