@rytass/bpm-core-react 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +18 -2
  3. package/dist/chunks/FormBuilderView-BPLwAJGv.cjs +3 -0
  4. package/dist/chunks/FormBuilderView-BPLwAJGv.cjs.map +1 -0
  5. package/dist/chunks/FormBuilderView-Do9-MIAe.js +1477 -0
  6. package/dist/chunks/FormBuilderView-Do9-MIAe.js.map +1 -0
  7. package/dist/chunks/FormRendererView-C5POZbWz.js +492 -0
  8. package/dist/chunks/FormRendererView-C5POZbWz.js.map +1 -0
  9. package/dist/chunks/FormRendererView-DNtNodNl.cjs +2 -0
  10. package/dist/chunks/FormRendererView-DNtNodNl.cjs.map +1 -0
  11. package/dist/chunks/{approval-instance-list-page-YZcGGDD8.js → approval-instance-list-page-BjX2kaoF.js} +56 -54
  12. package/dist/chunks/approval-instance-list-page-BjX2kaoF.js.map +1 -0
  13. package/dist/chunks/approval-instance-list-page-C408vxE2.cjs +2 -0
  14. package/dist/chunks/approval-instance-list-page-C408vxE2.cjs.map +1 -0
  15. package/dist/chunks/{categories-DBPoSrsi.js → categories-DGlxuC6X.js} +5 -5
  16. package/dist/chunks/{categories-DBPoSrsi.js.map → categories-DGlxuC6X.js.map} +1 -1
  17. package/dist/chunks/{categories-B6QZKZRt.cjs → categories-DUfldZ_9.cjs} +2 -2
  18. package/dist/chunks/{categories-B6QZKZRt.cjs.map → categories-DUfldZ_9.cjs.map} +1 -1
  19. package/dist/chunks/compose-CULMDsLS.cjs +2 -0
  20. package/dist/chunks/compose-CULMDsLS.cjs.map +1 -0
  21. package/dist/chunks/{compose-CQHDT7vh.js → compose-DJBlA5PD.js} +60 -58
  22. package/dist/chunks/compose-DJBlA5PD.js.map +1 -0
  23. package/dist/chunks/{delegations-DDEk-WI6.cjs → delegations-CGj-tZNO.cjs} +2 -2
  24. package/dist/chunks/{delegations-DDEk-WI6.cjs.map → delegations-CGj-tZNO.cjs.map} +1 -1
  25. package/dist/chunks/{delegations-iVnRi3QE.js → delegations-DLEEFBlH.js} +231 -231
  26. package/dist/chunks/{delegations-iVnRi3QE.js.map → delegations-DLEEFBlH.js.map} +1 -1
  27. package/dist/chunks/{delegations-ZNtodFaD.js → delegations-DqMpI_Nk.js} +168 -167
  28. package/dist/chunks/delegations-DqMpI_Nk.js.map +1 -0
  29. package/dist/chunks/delegations-kbMOSEif.cjs +2 -0
  30. package/dist/chunks/delegations-kbMOSEif.cjs.map +1 -0
  31. package/dist/chunks/{designer-CUbVXEtS.js → designer-BszXJ5RO.js} +1227 -990
  32. package/dist/chunks/designer-BszXJ5RO.js.map +1 -0
  33. package/dist/chunks/designer-CmqAU92b.cjs +65 -0
  34. package/dist/chunks/designer-CmqAU92b.cjs.map +1 -0
  35. package/dist/chunks/detail-CDexqBoU.cjs +2 -0
  36. package/dist/chunks/detail-CDexqBoU.cjs.map +1 -0
  37. package/dist/chunks/{detail-Cts5_gVp.js → detail-DAak2OXS.js} +704 -622
  38. package/dist/chunks/detail-DAak2OXS.js.map +1 -0
  39. package/dist/chunks/notifications--hwl-DR0.cjs +2 -0
  40. package/dist/chunks/{notifications-BKs4--96.cjs.map → notifications--hwl-DR0.cjs.map} +1 -1
  41. package/dist/chunks/{notifications-CSulztkU.js → notifications-DJ5wzCye.js} +7 -7
  42. package/dist/chunks/{notifications-CSulztkU.js.map → notifications-DJ5wzCye.js.map} +1 -1
  43. package/dist/chunks/{orgs-CrNxqlwp.js → orgs-DytLvZ_X.js} +243 -241
  44. package/dist/chunks/{orgs-CrNxqlwp.js.map → orgs-DytLvZ_X.js.map} +1 -1
  45. package/dist/chunks/orgs-Ni22buHs.cjs +2 -0
  46. package/dist/chunks/orgs-Ni22buHs.cjs.map +1 -0
  47. package/dist/chunks/providers-DEqcuXw9.js +506 -0
  48. package/dist/chunks/providers-DEqcuXw9.js.map +1 -0
  49. package/dist/chunks/providers-D_zTbkQH.cjs +2 -0
  50. package/dist/chunks/providers-D_zTbkQH.cjs.map +1 -0
  51. package/dist/chunks/{users-qghSMtLn.cjs → users-0HqlM_VQ.cjs} +2 -2
  52. package/dist/chunks/{users-qghSMtLn.cjs.map → users-0HqlM_VQ.cjs.map} +1 -1
  53. package/dist/chunks/{users-CUY139DF.js → users-FWrb3ehW.js} +5 -5
  54. package/dist/chunks/{users-CUY139DF.js.map → users-FWrb3ehW.js.map} +1 -1
  55. package/dist/components/notification-drawer.d.ts +4 -3
  56. package/dist/index.cjs +1 -1
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.js +21 -428
  59. package/dist/index.js.map +1 -1
  60. package/dist/next/index.cjs +1 -1
  61. package/dist/next/index.cjs.map +1 -1
  62. package/dist/next/index.js +16 -15
  63. package/dist/next/index.js.map +1 -1
  64. package/dist/pages/admin/delegations/index.cjs +1 -1
  65. package/dist/pages/admin/delegations/index.js +1 -1
  66. package/dist/pages/admin/orgs/index.cjs +1 -1
  67. package/dist/pages/admin/orgs/index.js +1 -1
  68. package/dist/pages/admin/users/index.cjs +1 -1
  69. package/dist/pages/admin/users/index.js +1 -1
  70. package/dist/pages/delegations/index.cjs +1 -1
  71. package/dist/pages/delegations/index.js +1 -1
  72. package/dist/pages/instances/detail/index.cjs +1 -1
  73. package/dist/pages/instances/detail/index.js +1 -1
  74. package/dist/pages/settings/notifications/index.cjs +1 -1
  75. package/dist/pages/settings/notifications/index.js +1 -1
  76. package/dist/pages/templates/categories/index.cjs +1 -1
  77. package/dist/pages/templates/categories/index.js +1 -1
  78. package/dist/pages/templates/compose/index.cjs +1 -1
  79. package/dist/pages/templates/compose/index.js +1 -1
  80. package/dist/pages/templates/designer/index.cjs +1 -1
  81. package/dist/pages/templates/designer/index.js +1 -1
  82. package/dist/views/admin/delegations/index.cjs +1 -1
  83. package/dist/views/admin/delegations/index.js +1 -1
  84. package/dist/views/admin/index.cjs +1 -1
  85. package/dist/views/admin/index.js +3 -3
  86. package/dist/views/admin/orgs/index.cjs +1 -1
  87. package/dist/views/admin/orgs/index.js +1 -1
  88. package/dist/views/admin/users/index.cjs +1 -1
  89. package/dist/views/admin/users/index.js +1 -1
  90. package/dist/views/cc/index.cjs +1 -1
  91. package/dist/views/cc/index.js +1 -1
  92. package/dist/views/delegations/index.cjs +1 -1
  93. package/dist/views/delegations/index.js +1 -1
  94. package/dist/views/forms/builder/index.cjs +1 -1
  95. package/dist/views/forms/builder/index.js +1 -1
  96. package/dist/views/forms/renderer/FormRendererView.d.ts +7 -2
  97. package/dist/views/forms/renderer/form-data-source-field.d.ts +34 -0
  98. package/dist/views/forms/renderer/index.cjs +1 -1
  99. package/dist/views/forms/renderer/index.d.ts +1 -0
  100. package/dist/views/forms/renderer/index.js +2 -2
  101. package/dist/views/instances/detail/index.cjs +1 -1
  102. package/dist/views/instances/detail/index.js +1 -1
  103. package/dist/views/instances/detail/sections/InstanceFormSection.d.ts +4 -1
  104. package/dist/views/instances/detail/sections/InstanceTasksSection.d.ts +5 -1
  105. package/dist/views/instances/new/index.cjs +1 -1
  106. package/dist/views/instances/new/index.cjs.map +1 -1
  107. package/dist/views/instances/new/index.js +105 -86
  108. package/dist/views/instances/new/index.js.map +1 -1
  109. package/dist/views/search/index.cjs +1 -1
  110. package/dist/views/search/index.js +1 -1
  111. package/dist/views/sent/index.cjs +1 -1
  112. package/dist/views/sent/index.js +1 -1
  113. package/dist/views/settings/index.cjs +1 -1
  114. package/dist/views/settings/index.js +1 -1
  115. package/dist/views/settings/notifications/index.cjs +1 -1
  116. package/dist/views/settings/notifications/index.js +1 -1
  117. package/dist/views/templates/categories/index.cjs +1 -1
  118. package/dist/views/templates/categories/index.js +1 -1
  119. package/dist/views/templates/compose/TemplateComposeWizardView.d.ts +3 -2
  120. package/dist/views/templates/compose/index.cjs +1 -1
  121. package/dist/views/templates/compose/index.js +1 -1
  122. package/dist/views/templates/designer/index.cjs +1 -1
  123. package/dist/views/templates/designer/index.js +1 -1
  124. package/dist/views/templates/index.cjs +1 -1
  125. package/dist/views/templates/index.cjs.map +1 -1
  126. package/dist/views/templates/index.js +153 -112
  127. package/dist/views/templates/index.js.map +1 -1
  128. package/package.json +56 -11
  129. package/dist/chunks/FormBuilderView-B_KGPjlp.cjs +0 -3
  130. package/dist/chunks/FormBuilderView-B_KGPjlp.cjs.map +0 -1
  131. package/dist/chunks/FormBuilderView-D8DrQOXD.js +0 -1090
  132. package/dist/chunks/FormBuilderView-D8DrQOXD.js.map +0 -1
  133. package/dist/chunks/FormRendererView-BwVsH2eX.cjs +0 -2
  134. package/dist/chunks/FormRendererView-BwVsH2eX.cjs.map +0 -1
  135. package/dist/chunks/FormRendererView-DrHsuSVo.js +0 -220
  136. package/dist/chunks/FormRendererView-DrHsuSVo.js.map +0 -1
  137. package/dist/chunks/approval-instance-list-page-BMUKxzcz.cjs +0 -2
  138. package/dist/chunks/approval-instance-list-page-BMUKxzcz.cjs.map +0 -1
  139. package/dist/chunks/approval-instance-list-page-YZcGGDD8.js.map +0 -1
  140. package/dist/chunks/compose-CQHDT7vh.js.map +0 -1
  141. package/dist/chunks/compose-Ds_cAefe.cjs +0 -2
  142. package/dist/chunks/compose-Ds_cAefe.cjs.map +0 -1
  143. package/dist/chunks/delegations-C2wLWsDQ.cjs +0 -2
  144. package/dist/chunks/delegations-C2wLWsDQ.cjs.map +0 -1
  145. package/dist/chunks/delegations-ZNtodFaD.js.map +0 -1
  146. package/dist/chunks/designer-CQ9hxSdD.cjs +0 -65
  147. package/dist/chunks/designer-CQ9hxSdD.cjs.map +0 -1
  148. package/dist/chunks/designer-CUbVXEtS.js.map +0 -1
  149. package/dist/chunks/detail-B-Q4W-iw.cjs +0 -2
  150. package/dist/chunks/detail-B-Q4W-iw.cjs.map +0 -1
  151. package/dist/chunks/detail-Cts5_gVp.js.map +0 -1
  152. package/dist/chunks/notifications-BKs4--96.cjs +0 -2
  153. package/dist/chunks/orgs-iNJ0QEcK.cjs +0 -2
  154. package/dist/chunks/orgs-iNJ0QEcK.cjs.map +0 -1
@@ -1,65 +0,0 @@
1
- "use client";require('../style.css');const e=require("./chunk-CMqjfN_6.cjs"),t=require("./router-adapter--gYs13E8.cjs"),n=require("./routes-config-fDVHmvXi.cjs"),r=require("./admin-pickers-Btvij1at.cjs"),i=require("./bpm-form-field-Bc6k4ZEO.cjs");;/* empty css */const a=require("./FormBuilderView-B_KGPjlp.cjs");let o=require("react"),s=require("@mezzanine-ui/react"),c=require("react/jsx-runtime"),l=require("@mezzanine-ui/react/Drawer");l=e.t(l,1);let u=require("@mezzanine-ui/react/ContentHeader");u=e.t(u,1);let d=require("@mezzanine-ui/icons"),f=require("ai"),p=require("@rytass/bpm-core-shared"),m=require("@rytass/bpm-core-client/form"),h=require("@rytass/bpm-core-client/organization"),g=require("@xyflow/react"),_=require("dagre");_=e.t(_,1);let v=require("@rytass/bpm-core-client/template"),y=require("@ai-sdk/react"),b=require("@rytass/bpm-core-shared/workflow-graph");function ee({directory:e,initialState:t,layout:n,onLayout:r}){let[i,a]=(0,o.useState)(t),s=(0,o.useRef)(t),c=(0,o.useRef)(e);c.current=e;let l=(0,o.useCallback)(e=>{if(!e.changed&&!e.error)return e;let t=e.effects.layout?n(e.state.definition):e.state.definition,i={...e.state,definition:t};return s.current=i,a(i),e.effects.layout&&r?.(t),{...e,state:i}},[n,r]),u=(0,o.useCallback)(e=>l((0,p.applyWorkflowCommand)(s.current,e)),[l]),d=(0,o.useCallback)(e=>l((0,p.applyWorkflowMacroCommand)(s.current,e)),[l]),f=(0,o.useCallback)(async(e,t)=>{let n=await(0,p.executeWorkflowTool)(s.current,e,t,{directory:c.current});if(n.ok&&(n.kind===`mutation`||n.kind===`macro`)){let e=l(n.result);return{...n,result:e,snapshot:(0,p.readWorkflowSnapshot)(e.state)}}return n},[l]),m=(0,o.useCallback)(e=>{let t=typeof e==`function`?e(s.current):e;s.current=t,a(t)},[]),h=(0,o.useCallback)(()=>s.current,[]),g=(0,o.useMemo)(()=>(0,p.readWorkflowSnapshot)(i),[i]);return(0,o.useMemo)(()=>({dispatch:u,dispatchMacro:d,executeTool:f,getState:h,replaceState:m,snapshot:g,state:i,tools:p.WORKFLOW_TOOLSET}),[u,d,f,h,m,g,i])}function te({controller:e,api:t=`/api/chat`}){let n=(0,y.useChat)({transport:(0,o.useMemo)(()=>new f.DefaultChatTransport({api:t}),[t]),sendAutomaticallyWhen:f.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:t}){let r=await e.executeTool(t.toolName,t.input);if(r.ok){n.addToolOutput({output:r.kind===`query`?r.data:r.snapshot,tool:t.toolName,toolCallId:t.toolCallId});return}n.addToolOutput({errorText:r.error,state:`output-error`,tool:t.toolName,toolCallId:t.toolCallId})}});return n}var ne=12;function re(){let e=globalThis.LanguageModel;return e&&typeof e==`object`?e:null}var ie={additionalProperties:!1,properties:{action:{enum:[`tool`,`message`],type:`string`},input:{type:`object`},text:{type:`string`},tool:{type:`string`}},required:[`action`],type:`object`};function ae(){return`你是「簽核流程設計器」頁面的離線 AI 助理。只能透過下列工具操作這個流程畫布,其他請求一律婉拒並引導回流程設計。
2
-
3
- 每一步只輸出一個 JSON 決策物件:
4
- - 呼叫工具:{"action":"tool","tool":"<工具名>","input":{...}}
5
- - 回覆使用者(完成或詢問):{"action":"message","text":"<繁體中文訊息>"}
6
-
7
- 規則:先用 get_workflow_snapshot 了解現況再規劃;完成後用 validate_workflow 檢查並以 message 說明做了什麼。
8
-
9
- 可用工具:
10
- ${p.WORKFLOW_TOOLSET.map(e=>`- ${e.name}(${JSON.stringify(e.inputSchema.properties??{})}): ${e.description}`).join(`
11
- `)}`}function oe({controller:e}){let[t,n]=(0,o.useState)(!1),[r,i]=(0,o.useState)([]),[a,s]=(0,o.useState)(`ready`),c=(0,o.useRef)(0);(0,o.useEffect)(()=>{let e=re();e&&e.availability().then(e=>{n(e!==`unavailable`)}).catch(()=>n(!1))},[]);let l=(0,o.useCallback)((e,t)=>{c.current+=1,i(n=>[...n,{id:`chrome-${c.current}`,parts:[{text:t,type:`text`}],role:e}])},[]);return{available:t,messages:r,send:(0,o.useCallback)(t=>{let n=re();!n||a!==`ready`||(l(`user`,t),s(`submitted`),se({appendMessage:l,controller:e,model:n,userText:t}).then(()=>s(`ready`)).catch(e=>{l(`assistant`,ce(e)),s(`error`)}))},[l,e,a]),status:a}}async function se({appendMessage:e,controller:t,model:n,userText:r}){let i=await n.create({initialPrompts:[{content:ae(),role:`system`}]});try{let n=`使用者需求:${r}\n目前流程:${JSON.stringify(t.snapshot)}`;for(let r=0;r<ne;r+=1){let r=x(await i.prompt(n,{responseConstraint:ie}));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 x(e){try{let t=JSON.parse(e);return typeof t==`object`&&t&&t.action!==void 0?t:null}catch{return null}}function ce(e){return e instanceof Error?`離線模式發生錯誤:${e.message}`:`離線模式發生未知錯誤。`}var le={display:`flex`,flexDirection:`column`,gap:12,height:`100%`},ue={display:`flex`,flex:1,flexDirection:`column`,gap:12,minHeight:0,overflowY:`auto`},de={display:`flex`,gap:8,paddingBottom:4},fe={borderTop:`1px solid var(--mzn-color-border-neutral, #e5e7eb)`,display:`flex`,flexDirection:`column`,gap:8,paddingTop:12},pe={display:`flex`,justifyContent:`flex-end`},me={width:`100%`},he=`workflow-chat-input-field`,ge=`
12
- .${he}.mzn-text-field {
13
- width: 100%;
14
- }
15
- `,_e={color:`var(--mzn-color-text-secondary, #6b7280)`,fontSize:12,padding:`2px 0`},ve={"input-available":`執行中…`,"input-streaming":`準備中…`,"output-available":`完成`,"output-error":`失敗`};function ye(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 be({api:e,controller:t,onClose:n,open:r}){let i=te({api:e,controller:t}),a=oe({controller:t}),[u,d]=(0,o.useState)(`online`),[f,p]=(0,o.useState)(``),m=u===`offline`?{messages:a.messages,send:a.send,status:a.status}:{messages:i.messages,send:e=>{i.sendMessage({text:e})},status:i.status},{messages:h,send:g}=m,_=m.status===`submitted`||m.status===`streaming`,v=(0,o.useCallback)(()=>{let e=f.trim();!e||_||(p(``),g(e))},[_,f,g]),y=(0,o.useCallback)(e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),v())},[v]);return(0,c.jsxs)(l.default,{headerTitle:`AI 流程助理`,isHeaderDisplay:!0,onClose:n,open:r,size:`medium`,children:[(0,c.jsx)(`style`,{children:ge}),(0,c.jsxs)(`div`,{style:le,children:[a.available?(0,c.jsxs)(`div`,{style:de,children:[(0,c.jsx)(s.Button,{onClick:()=>d(`online`),variant:u===`online`?`base-primary`:`base-tertiary`,children:`線上`}),(0,c.jsx)(s.Button,{onClick:()=>d(`offline`),variant:u===`offline`?`base-primary`:`base-tertiary`,children:`離線(裝置內,實驗)`})]}):null,(0,c.jsxs)(`div`,{role:`log`,style:ue,children:[h.length===0?(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`用一句話描述你想要的流程,例如:「建立三關簽核:部門主管 → 經理 → 財務,金額大於十萬走財務複核」。我會直接在畫布上幫你繪製。`}):null,h.map(e=>(0,c.jsx)(o.Fragment,{children:xe(e)},e.id)),_?(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`思考中…`}):null]}),(0,c.jsxs)(`div`,{style:fe,children:[(0,c.jsx)(s.Textarea,{className:he,disabled:_,maxLength:2e3,onChange:e=>p(e.target.value),onKeyDown:y,placeholder:`描述你想要的流程…(Enter 送出,Shift + Enter 換行)`,rows:3,style:me,value:f}),(0,c.jsx)(`div`,{style:pe,children:(0,c.jsx)(s.Button,{disabled:_||f.trim().length===0,loading:_,onClick:v,type:`button`,variant:`base-primary`,children:`送出`})})]})]})]})}function xe(e){return e.parts.map((t,n)=>t.type===`text`?(0,c.jsx)(`div`,{style:ye(e.role),children:t.text},`${e.id}-${n}`):t.type===`dynamic-tool`||(0,f.isToolUIPart)(t)?(0,c.jsx)(`div`,{style:_e,children:`⚙ ${(0,f.getToolName)(t)} · ${ve[t.state]??t.state}`},`${e.id}-${n}`):null)}var Se={display:`grid`,gap:16},Ce={alignItems:`start`,display:`grid`,gap:16,gridTemplateColumns:`minmax(0, 1fr) 420px`},we={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,height:620,minWidth:0,overflow:`hidden`},Te={alignItems:`center`,boxSizing:`border-box`,color:`var(--mzn-color-text-error)`,display:`flex`,height:26,justifyContent:`center`,lineHeight:0,padding:0,width:26},Ee={alignItems:`center`,display:`flex`,height:`100%`,justifyContent:`center`,width:`100%`},De=`workflow-designer-side-panel`,Oe=96,ke=`
16
- .${De} .mzn-form-field--stretch .mzn-form-field__label-area,
17
- .${De} .mzn-form-field--horizontal .mzn-form-field__label-area {
18
- flex: 0 0 ${Oe}px;
19
- width: ${Oe}px;
20
- }
21
-
22
- .${De} .mzn-form-field--stretch .mzn-form-field__data-entry,
23
- .${De} .mzn-form-field--horizontal .mzn-form-field__data-entry {
24
- min-width: 0;
25
- }
26
- `,S=`#2563eb`,C=`#64748b`,Ae=`var(--mzn-color-text-error, #dc2626)`,w=`drop-shadow(0 0 3px rgba(0, 87, 255, 0.85)) drop-shadow(0 0 9px rgba(0, 87, 255, 0.36))`,je=`
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: ${w};
52
- opacity: 1 !important;
53
- stroke: ${C} !important;
54
- stroke-opacity: 1 !important;
55
- stroke-width: 1.5px !important;
56
- }
57
-
58
- .workflow-edge--selected {
59
- --xy-edge-stroke: ${C};
60
- --xy-edge-stroke-selected: ${C};
61
- --xy-edge-stroke-width: 1.5px;
62
- }
63
-
64
- `,Me={display:`grid`,gap:12},T={display:`grid`,gap:12},Ne={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,display:`grid`,gap:8,maxHeight:360,overflow:`auto`,padding:12},Pe={borderBottom:`1px solid var(--mzn-color-border-neutral)`,display:`grid`,gap:4,padding:`0 0 8px`},Fe={display:`flex`,flexWrap:`wrap`,gap:8},Ie={alignItems:`center`,display:`flex`,gap:8},Le={flex:`1 1 auto`,minWidth:0},Re={flex:`0 0 auto`},ze={display:`grid`,gap:8},E={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%`},Be=`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)`,D=64,Ve=160,He=20,Ue=64,We=180,O={...E,display:`grid`,gap:8,padding:`10px 12px`},Ge={...O,background:`#eff6ff`,border:`1px solid #2563eb`},Ke={...O,background:`#f0fdfa`,border:`1px solid #0f766e`},qe={...E,background:`#ffffff`},k={...E,background:`#ecfdf3`,border:`1px solid #2f855a`},Je={...E,background:`#fff4ed`,border:`1px solid #c2410c`},A={display:`block`,maxWidth:`100%`,minWidth:0},Ye={display:`grid`,gap:2,minWidth:0},j=`input`,Xe=`output`,Ze={endEvent:`結束`,exclusiveGateway:`條件分流`,parallelGateway:`並行處理`,serviceTask:`系統`,startEvent:`開始`,userTask:`簽核`},Qe=[{icon:d.UserIcon,label:`簽核節點`,type:`userTask`},{icon:d.MailIcon,label:`知會節點`,type:`serviceTask`}],$e=[{icon:d.FilterIcon,label:`條件分流`,type:`exclusiveGateway`}],et=[{id:`AND`,name:`全部前置完成`},{id:`OR`,name:`任一前置完成`}],tt=[{id:`RESTART`,name:`重新送出後從開始重跑`},{id:`FROM_RETURN_POINT`,name:`重新送出後回到退回節點`}],nt=[{id:`NONE`,name:`不提醒`,value:null},{id:`0.5`,name:`過半時提醒`,value:.5},{id:`0.75`,name:`剩四分之一時提醒`,value:.75},{id:`0.9`,name:`剩十分之一時提醒`,value:.9}],rt=[{id:`DIRECT`,name:`指定會員`},{id:`ORG_MANAGER`,name:`發起人主管`},{id:`ORG_UNIT_MANAGER`,name:`指定組織主管`},{id:`ORG_UNIT_MEMBER`,name:`組織任一人`},{id:`ORG_UNIT_POSITION`,name:`組織特定職位`},{id:`POSITION`,name:`指定職位`}],M=[{id:`1`,name:`直屬主管`,value:1},{id:`2`,name:`第二層主管`,value:2},{id:`3`,name:`第三層主管`,value:3}],it=[{id:`NONE`,name:`停止流程並提示`},{id:`DIRECT`,name:`固定改派`}],at=[{id:`EQUALS`,name:`等於`},{id:`NOT_EQUALS`,name:`不等於`},{id:`GREATER_THAN`,name:`大於`},{id:`GREATER_THAN_OR_EQUALS`,name:`大於等於`},{id:`LESS_THAN`,name:`小於`},{id:`LESS_THAN_OR_EQUALS`,name:`小於等於`},{id:`IS_FILLED`,name:`已填寫`},{id:`IS_EMPTY`,name:`未填寫`}],ot=[`EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`NOT_EQUALS`],st=[{id:`NONE`,name:`未設定`},{id:`ALL`,name:`所有人`},{id:`ORG_UNIT`,name:`指定組織`},{id:`ORG_UNIT_POSITION`,name:`指定組織職位`}],ct={id:`CUSTOM`,name:`既有自訂規則`},lt=`member-001`,ut={display:`flex`,flexDirection:`column`,height:`100%`},dt={flex:1,minHeight:0,overflowY:`auto`},ft={borderTop:`1px solid var(--mzn-color-border-neutral)`,display:`flex`,gap:8,paddingTop:12},pt={fields:[],schemaVersion:1},mt={layout:[],schemaVersion:1},ht={endEvent:P,exclusiveGateway:P,parallelGateway:P,serviceTask:P,startEvent:P,userTask:P};function N(e,t){return typeof e==`function`?e(t):e}function gt({aiAssistantAvailable:e=!0,embedded:f=!1,formSchemaOverride:p,initialInitiatorPolicyCel:_,initialWorkflowDefinition:y,onInitiatorPolicyChange:te,onWorkflowChange:ne,showAiAssistant:re=!1,showDryRun:ie=!0,templateId:ae}){let oe=t.r(),se=n.r(),[x,ce]=(0,o.useState)(null),[le,ue]=(0,o.useState)(null),[de,fe]=(0,o.useState)(``),[pe,me]=(0,o.useState)(null),[he,ge]=(0,o.useState)(null),_e=(0,o.useRef)(null),[ve,ye]=(0,o.useState)(void 0),xe=(0,o.useRef)([]),Oe=(0,o.useRef)([]),S=ee({directory:(0,o.useMemo)(()=>({listOrgUnits:async()=>xe.current.map(e=>({id:e.id,name:e.name})),listPositions:async()=>Oe.current.map(e=>({id:e.id,name:e.name})),searchMembers:async e=>_n(await(0,v.searchMemberOptions)(e)).map(e=>({email:e.email,id:e.memberId,name:e.name}))}),[]),initialState:{definition:f&&y!=null?y:Ot(),editingEdgeId:null,formDefinitionVersionId:null,formSchema:null,initiatorPolicyCel:f&&_!==void 0?_:null,selectedEdgeIds:[],selectedNodeId:f&&y!=null?y.nodes[0]?.id??`start`:`start`},layout:At,onLayout:e=>{let t=Fn(e,_e.current);t&&ye(t)}}),C=S.state.definition,w=S.state.formDefinitionVersionId,E=S.state.initiatorPolicyCel,Be=S.state.selectedNodeId,D=S.state.selectedEdgeIds,Ve=S.state.editingEdgeId,He=e=>S.replaceState(t=>({...t,definition:N(e,t.definition)})),Ue=e=>S.replaceState(t=>({...t,formDefinitionVersionId:N(e,t.formDefinitionVersionId)})),We=e=>S.replaceState(t=>({...t,initiatorPolicyCel:N(e,t.initiatorPolicyCel)})),O=e=>S.replaceState(t=>({...t,selectedNodeId:N(e,t.selectedNodeId)})),Ge=e=>S.replaceState(t=>({...t,selectedEdgeIds:N(e,t.selectedEdgeIds)})),Ke=e=>S.replaceState(t=>({...t,editingEdgeId:N(e,t.editingEdgeId)})),[qe,k]=(0,o.useState)(null),[Je,A]=(0,o.useState)(!0),[Ye,j]=(0,o.useState)(!1),[Xe,at]=(0,o.useState)(!1),[ot,gt]=(0,o.useState)([]),P=(0,o.useMemo)(()=>JSON.stringify({formDefinitionVersionId:w,initiatorPolicyCel:E,workflowDefinition:C}),[w,E,C]),vt=!!de&&P!==de,[yt,bt]=(0,o.useState)(!1),[F,I]=(0,o.useState)([]),[L,St]=(0,o.useState)([]),[R,wt]=(0,o.useState)([]),[Et,Dt]=(0,o.useState)([]);xe.current=L,Oe.current=R;let[Vt,Yt]=(0,o.useState)(!1),[Qt,en]=(0,o.useState)(!1),[on,sn]=(0,o.useState)(`{}`),[B,dn]=(0,o.useState)(null),[pn,V]=(0,o.useState)(null),[H,wn]=(0,o.useState)(!1),[Tn,En]=(0,o.useState)(!1),[U,W]=(0,o.useState)(null),[An,jn]=(0,o.useState)(!1),[Mn,Nn]=(0,o.useState)(!1),Pn=vt||An?`保存並發布`:le?`發布草稿`:`已發布`;(0,o.useEffect)(()=>{f?or():sr()},[f,ae]),(0,o.useEffect)(()=>{function e(e){vt&&(e.preventDefault(),e.returnValue=``)}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[vt]),(0,o.useEffect)(()=>{lr(C)},[C,F]),(0,o.useEffect)(()=>{He(e=>Tt(e))},[C.edges,C.nodes]);function Ln(){vt&&!window.confirm(`目前有尚未儲存的流程草稿,確定要離開嗎?`)||oe.push(se.templates())}let G=(0,o.useMemo)(()=>C.nodes.find(e=>e.id===Be)??null,[Be,C.nodes]),Kn=G?an(G):!1,qn=D.length>0||Kn,Yn=(0,o.useCallback)(()=>{S.getState().selectedEdgeIds.forEach(e=>S.dispatch({edgeId:e,type:`deleteEdge`})),G&&an(G)&&S.dispatch({nodeId:G.id,type:`deleteNode`})},[S,G]);(0,o.useEffect)(()=>{if(!qn)return;function e(e){e.key!==`Delete`&&e.key!==`Backspace`||cn(e.target)||(e.preventDefault(),Yn())}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[qn,Yn]);let Xn=(0,o.useMemo)(()=>C.edges.find(e=>e.id===Ve)??null,[Ve,C.edges]),Zn=(0,o.useMemo)(()=>D.length===1?C.edges.find(e=>e.id===D[0])??null:null,[D,C.edges]),Qn=(0,o.useMemo)(()=>D.map(e=>C.edges.find(t=>t.id===e)??null).filter(e=>!!e),[D,C.edges]),J=(0,o.useMemo)(()=>he??Xt(E,pe),[E,he,pe]),$n=(0,o.useMemo)(()=>C.nodes.map(e=>xt(e,F,L,R,e.id===Be,J)),[J,F,L,R,Be,C.nodes]),er=(0,o.useMemo)(()=>C.edges.map(e=>Ct(e,C.nodes,D.includes(e.id))),[D,C.edges,C.nodes]),Y=(0,o.useMemo)(()=>z(ot,w)??z(ln(x?.formVersions??[]),w),[w,ot,x?.formVersions]),tr=(0,o.useMemo)(()=>gn(ot,Y),[ot,Y]),nr=Y?.schema??null,rr=f?p??null:nr;(0,o.useEffect)(()=>{S.getState().formSchema!==rr&&S.replaceState(e=>({...e,formSchema:rr}))},[S,rr]);let ir=(0,o.useMemo)(()=>In(C),[C]),X=(0,o.useMemo)(()=>Rn(C),[C]),ar=(0,o.useMemo)(()=>Zt(J),[J]);(0,o.useEffect)(()=>{f&&ne?.(C)},[f,C]),(0,o.useEffect)(()=>{f&&te?.(E)},[f,E]);async function or(){A(!0),k(null);try{let e=await(0,h.readOrganizationDashboard)();St(e.orgUnits),wt(e.positions),Dt(e.memberships)}catch(e){k(q(e))}finally{A(!1)}}async function sr(){A(!0),k(null);try{let[e,t]=await Promise.all([(0,v.readTemplateDesigner)(ae),(0,h.readOrganizationDashboard)()]),n=e.versions.find(e=>e.status===`DRAFT`)??null,r=n??e.versions[0]??null;ce(e),ue(n),St(t.orgUnits),wt(t.positions),Dt(t.memberships),gt(ln(e.formVersions));let i=r?.workflowDefinition??Ot(),a=r?.formDefinitionVersionId??e.formVersions[0]?.id??null,o=r?.initiatorPolicyCel??null;He(i),Ue(a),We(o),fe(JSON.stringify({formDefinitionVersionId:a,initiatorPolicyCel:o,workflowDefinition:i})),me(r&&!e.template.currentVersionId&&!r.initiatorPolicyCel&&kt(r.workflowDefinition)?`NONE`:null),ge(null),O(r?.workflowDefinition.nodes[0]?.id??`start`),Ge([]),Ke(null),W(null),jn(!1)}catch(e){k(q(e))}finally{A(!1)}}async function cr(e){at(!0),k(null);try{gt(gn(ln(await(0,v.searchPublishedFormVersionOptions)(e)),Y))}catch(e){k(q(e))}finally{at(!1)}}async function Z(e){bt(!0),k(null);try{let t=await(0,v.searchMemberOptions)(e);I(e=>On(e,_n(t)))}catch(e){k(q(e))}finally{bt(!1)}}async function lr(e){let t=kn(e).filter(e=>!F.some(t=>t.memberId===e));if(t.length!==0)try{let e=await(0,v.resolveMemberOptions)(t);I(t=>On(t,_n(e)))}catch{I(e=>On(e,t.map(vn)))}}async function ur(e){j(!0),k(null);try{let t=In(C),n=Zt(J);if(t||n){let e=t??n??`流程設定未完成`;throw k(e),Error(e)}if(An&&U!==null)await(0,v.composeApprovalTemplateWithForm)({category:x?.template.category??null,categoryId:x?.template.categoryId??null,formDefinitionId:Y?.formDefinitionId??null,formDescription:null,formName:Y?.formName??x?.template.name??`表單`,initiatorPolicyCel:E,notificationConfig:null,publish:e,schema:U.schema,slaDefaults:null,templateDescription:null,templateId:ae??null,templateName:x?.template.name??`模板`,uiSchema:U.uiSchema,workflowDefinition:C}),jn(!1),W(null),await sr();else{let t=await(0,v.updateApprovalTemplateDraft)({formDefinitionVersionId:w,initiatorPolicyCel:E,versionId:(le??await(0,v.forkApprovalTemplate)(ae)).id,workflowDefinition:C});ue(t),e&&await(0,v.publishApprovalTemplateVersion)(t.id),await sr()}}catch(e){throw k(q(e)),e}finally{j(!1)}}async function dr(){await ur(!1)}async function fr(){await ur(!0)}function pr(){sn(JSON.stringify(un(Y),null,2)),dn(null),V(null),Yt(!0)}function mr(){Qt||Yt(!1)}async function hr(){en(!0),V(null),dn(null);try{dn(await(0,v.dryRunApprovalWorkflow)({formData:fn(on),initiatorMemberId:lt,initiatorMetadataSnapshot:Cn(lt,Et),workflowDefinition:C}))}catch(e){V(q(e))}finally{en(!1)}}async function gr(){if(En(!0),U!==null)return;let e=Y?.formDefinitionId??null;if(!e){W({schema:pt,uiSchema:mt});return}Nn(!0);try{let t=await(0,m.readFormBuilder)(e),n=t.versions.find(e=>e.status===`DRAFT`)??t.versions.find(e=>e.id===t.definition.currentVersionId)??t.versions[0]??null;W({schema:n?.schema??pt,uiSchema:n?.uiSchema??mt})}catch(e){k(q(e))}finally{Nn(!1)}}function _r(e){let t=(0,g.applyNodeChanges)(e,$n);He(e=>({...e,nodes:e.nodes.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,position:n.position}:e})}))}function vr(e){!nn(e,C.nodes)||!e.source||!e.target||S.dispatch({source:e.source,target:e.target,type:`connectEdge`})}function yr(e,t){e.stopPropagation(),Ge(n=>e.shiftKey||e.metaKey||e.ctrlKey?rn(n,t.id):[t.id]),O(null)}function br(){Ke(null)}function xr(e){S.dispatch({nodeType:e,type:`addNode`})}function Sr(e){G&&S.dispatch({label:e,nodeId:G.id,type:`renameNode`})}function Q(e){!G||G.type!==`userTask`||S.dispatch({approverResolver:e,nodeId:G.id,type:`setUserTaskApprover`})}function Cr(e){!G||G.type!==`userTask`||S.dispatch({nodeId:G.id,resubmitStrategy:e,type:`setUserTaskReturnResubmitStrategy`})}function wr(e){!G||G.type!==`userTask`||S.dispatch({nodeId:G.id,requireComment:e,type:`setUserTaskReturnRequireComment`})}function $(e){!G||G.type!==`userTask`||S.dispatch({nodeId:G.id,sla:e,type:`setUserTaskSla`})}function Tr(e){!G||G.type!==`serviceTask`||S.dispatch({action:e,nodeId:G.id,type:`setServiceAction`})}function Er(e){ge(e.mode===`ALL`||e.mode===`CUSTOM`?null:e),me(e.mode===`ALL`||e.mode===`CUSTOM`?null:e.mode),We($t(e,L))}function Dr(e){!G||G.type===`startEvent`||S.dispatch({nodeId:G.id,triggerMode:e,type:`setNodeTriggerMode`})}function Or(e,t){S.dispatch({edgeId:e,isDefault:t,type:`setEdgeDefault`})}function kr({edgeId:e,fieldKey:t,operator:n,value:r}){S.dispatch({edgeId:e,fieldKey:t,operator:n,type:`setEdgeCondition`,value:r})}function Ar(){S.dispatch({type:`autoLayout`})}return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`style`,{children:ke}),f?null:(0,c.jsx)(s.PageHeader,{children:(0,c.jsxs)(u.default,{description:`${le?`草稿 v${le.version}`:`尚未建立草稿`} ·${x?.template.currentVersionId?` 已發布版本`:` 尚未發布`}`,onBackClick:Ln,title:x?.template.name??`流程設計器`,children:[re?(0,c.jsx)(s.Button,{disabled:!e,onClick:()=>wn(e=>!e),variant:H?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`}):null,(0,c.jsx)(s.Button,{"aria-label":`儲存草稿`,disabled:Ye||!!ir||!!ar,icon:d.SaveIcon,iconType:`icon-only`,onClick:()=>void dr(),variant:`base-secondary`,children:`儲存草稿`}),ie?(0,c.jsx)(s.Button,{disabled:Je||!!ir||!!ar,icon:d.EyeIcon,iconType:`leading`,onClick:pr,variant:`base-secondary`,children:`試跑流程`}):null,(0,c.jsx)(s.Button,{disabled:Ye||!le&&!vt&&!An||!!ir||!!ar,icon:d.CheckedIcon,iconType:`leading`,onClick:()=>void fr(),variant:`base-primary`,children:Pn})]})}),(0,c.jsx)(s.SectionGroup,{children:(0,c.jsx)(s.Section,{children:(0,c.jsxs)(`div`,{style:Se,children:[qe?(0,c.jsx)(s.Typography,{color:`text-error`,variant:`body`,children:qe}):null,ir?(0,c.jsx)(s.Typography,{color:`text-error`,variant:`body`,children:ir}):null,ar?(0,c.jsx)(s.Typography,{color:`text-error`,variant:`body`,children:ar}):null,f?null:(0,c.jsx)(`div`,{style:T,children:(0,c.jsx)(i.t,{hintText:X?`已設定條件分流條件。請先移除所有條件,才能更換綁定表單版本。`:void 0,label:`綁定表單版本`,name:`formDefinitionVersionId`,required:!0,children:(0,c.jsxs)(`div`,{style:Ie,children:[(0,c.jsx)(`div`,{style:Le,children:(0,c.jsx)(s.AutoComplete,{asyncData:!0,disabled:Je||X,disabledOptionsFilter:!0,emptyText:`沒有符合的已發布表單版本`,isForceClearable:!!w&&!X,loading:Xe,loadingText:`搜尋表單版本中...`,mode:`single`,onChange:e=>{X||Ue(e?.id??null)},onClear:()=>{X||Ue(null)},onSearch:cr,onVisibilityChange:e=>{e&&!X&&cr(``)},options:[...tr],placeholder:`選擇已發布表單版本`,searchDebounceTime:300,value:Y})}),(0,c.jsx)(s.Button,{disabled:Je,onClick:()=>{gr()},style:Re,variant:`base-secondary`,children:`編輯表單`})]})})}),(0,c.jsxs)(`div`,{style:Ce,children:[(0,c.jsx)(`div`,{ref:_e,style:we,children:(0,c.jsxs)(g.ReactFlow,{connectionMode:g.ConnectionMode.Strict,edges:er,fitView:!0,isValidConnection:e=>nn(e,C.nodes),nodeTypes:ht,nodes:$n,deleteKeyCode:null,multiSelectionKeyCode:[`Shift`,`Meta`,`Control`],onConnect:vr,onEdgeClick:yr,onNodeClick:(e,t)=>{O(t.id),Ge([])},onNodesChange:_r,onPaneClick:()=>{O(null),Ge([])},onViewportChange:ye,viewport:ve,children:[(0,c.jsx)(g.Background,{}),(0,c.jsx)(`style`,{children:je}),(0,c.jsx)(g.Controls,{children:qn?(0,c.jsx)(g.ControlButton,{"aria-label":`刪除選取項目`,className:`workflow-selection-delete-control`,onClick:Yn,style:Te,title:`刪除選取項目`,children:(0,c.jsx)(`span`,{style:Ee,children:(0,c.jsx)(s.Icon,{color:`error`,icon:d.TrashIcon,size:16})})}):null}),(0,c.jsx)(_t,{onApplyAutoLayout:Ar}),(0,c.jsx)(g.MiniMap,{})]})}),(0,c.jsxs)(`div`,{className:De,style:Me,children:[(0,c.jsx)(s.Typography,{component:`h2`,variant:`h3`,children:`流程工具`}),f&&re?(0,c.jsxs)(`div`,{style:ze,children:[(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`caption`,children:`AI 協助`}),(0,c.jsx)(`div`,{style:Fe,children:(0,c.jsx)(s.Button,{disabled:!e,onClick:()=>wn(e=>!e),size:`sub`,variant:H?`base-primary`:`base-secondary`,children:e?`AI 助理`:`AI 助理(未設定)`})})]}):null,(0,c.jsxs)(`div`,{style:ze,children:[(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`caption`,children:`動作節點`}),(0,c.jsx)(`div`,{style:Fe,children:Qe.map(e=>(0,c.jsx)(s.Button,{icon:e.icon,iconType:`leading`,onClick:()=>xr(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,c.jsxs)(`div`,{style:ze,children:[(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`caption`,children:`流程控制`}),(0,c.jsx)(`div`,{style:Fe,children:$e.map(e=>(0,c.jsx)(s.Button,{icon:e.icon,iconType:`leading`,onClick:()=>xr(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),Qn.length>1?Lr(Qn):null,Qn.length===1&&Zn?Rr(Zn):null,Qn.length===0&&G?Mr(G):null]})]})]})})}),zr(Xn),!f&&ie?jr():null,re&&e?(0,c.jsx)(be,{controller:S,onClose:()=>wn(!1),open:H}):null,f?null:(0,c.jsx)(l.default,{headerTitle:`編輯表單`,isHeaderDisplay:!0,onClose:()=>En(!1),open:Tn,size:`wide`,children:(0,c.jsxs)(`div`,{style:ut,children:[(0,c.jsx)(`div`,{style:dt,children:Mn?(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`載入中…`}):(0,c.jsx)(a.t,{onChange:e=>{W(e)},value:U??{schema:pt,uiSchema:mt}})}),(0,c.jsxs)(`div`,{style:ft,children:[(0,c.jsx)(s.Button,{disabled:Mn,onClick:()=>{U!==null&&(jn(!0),S.replaceState(e=>({...e,formSchema:U.schema}))),En(!1)},variant:`base-primary`,children:`套用`}),(0,c.jsx)(s.Button,{onClick:()=>En(!1),variant:`base-secondary`,children:`取消`})]})]})})]});function jr(){return(0,c.jsx)(s.Modal,{cancelText:`關閉`,confirmText:`執行試跑`,loading:Qt,modalType:`standard`,onCancel:mr,onClose:mr,onConfirm:()=>void hr(),open:Vt,showModalFooter:!0,showModalHeader:!0,size:`wide`,supportingText:`使用 ${lt} 與範例表單資料模擬目前畫布流程,不會建立案件。`,title:`試跑流程`,children:(0,c.jsxs)(`div`,{style:T,children:[(0,c.jsx)(i.t,{label:`表單資料 JSON`,name:`dryRunFormDataJson`,required:!0,children:(0,c.jsx)(s.Textarea,{onChange:e=>sn(e.target.value),resize:`vertical`,rows:8,value:on})}),pn?(0,c.jsx)(s.Typography,{color:`text-error`,variant:`body`,children:pn}):null,B?(0,c.jsxs)(`div`,{style:Ne,children:[(0,c.jsx)(s.Typography,{color:B.valid?`text-success`:`text-error`,variant:`label-primary-highlight`,children:B.valid?`試跑通過`:`試跑失敗`}),B.errors.map(e=>(0,c.jsx)(s.Typography,{color:`text-error`,variant:`body`,children:e},e)),B.steps.map(e=>(0,c.jsxs)(`div`,{style:Pe,children:[(0,c.jsxs)(s.Typography,{variant:`label-primary-highlight`,children:[e.nodeLabel,` · `,mn(e.status)]}),(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`caption`,children:[hn(e.nodeType),e.assigneeMemberId?` · 處理者:${e.assigneeMemberId}`:``,e.edgeLabel?` · 來源線段:${e.edgeLabel}`:``]}),e.edgeReason?(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`caption`,children:e.edgeReason}):null,e.entryCondition?(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`caption`,children:[`進入條件:`,e.entryConditionMatched?`符合`:`不符合`,` ·`,` `,e.entryCondition]}):null,(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:e.message})]},e.id))]}):null]})})}function Mr(e){return(0,c.jsxs)(`div`,{style:T,children:[(0,c.jsx)(s.Typography,{component:`h2`,variant:`h3`,children:`節點屬性`}),(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`body`,children:[Ze[e.type],` · `,e.id]}),(0,c.jsx)(i.t,{label:`顯示名稱`,name:`nodeLabel`,required:!0,children:(0,c.jsx)(s.Input,{onChange:e=>Sr(e.target.value),value:e.data.label,variant:`base`})}),e.type===`startEvent`?Nr():null,e.type===`startEvent`?null:Pr(e),e.type===`userTask`?Fr(e):null,e.type===`serviceTask`?Ir(e):null]})}function Nr(){let e=J.mode===`CUSTOM`?[...st,ct]:[...st],t=J.mode===`ORG_UNIT`||J.mode===`ORG_UNIT_POSITION`?xn(L,J.orgUnitId??``):null,n=J.mode===`ORG_UNIT_POSITION`?Sn(R,J.positionId??``):null,a=J.mode===`ORG_UNIT_POSITION`?Dn({includeDescendants:!!J.includeDescendants,memberships:Et,orgUnitId:J.orgUnitId??``,orgUnits:L,positions:R}):[];return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.t,{hintText:J.mode===`CUSTOM`?`這是舊版表達式規則;切換成標準選項後會改由 UI 管理。`:void 0,label:`發起權限`,name:`initiatorPolicyMode`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>{if(e?.id===`CUSTOM`){me(null),ge(null);return}let t=Jt(e?.id??null),n=tn(t);me(t===`ALL`?null:t),ge(t===`ALL`?null:n),We($t(n,L))},options:e,placeholder:`選擇誰可以發起`,value:z(e,J.mode)})}),J.mode===`ORG_UNIT`||J.mode===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{label:`組織`,name:`initiatorOrgUnitId`,required:!0,children:(0,c.jsx)(r.n,{name:`initiatorOrgUnitId`,onChange:e=>Er({...J,orgUnitId:e?.id??``,positionId:``,value:e?.id??``}),orgUnits:L,placeholder:`選擇組織`,value:t})}):null,J.mode===`ORG_UNIT`||J.mode===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{label:`包含下層`,name:`initiatorIncludeDescendants`,children:(0,c.jsx)(s.Toggle,{checked:!!J.includeDescendants,onChange:e=>Er({...J,includeDescendants:e.target.checked,...J.mode===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,J.mode===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{label:`職位`,name:`initiatorPositionId`,required:!0,children:(0,c.jsx)(r.r,{disabled:!J.orgUnitId?.trim(),name:`initiatorPositionId`,onChange:e=>Er({...J,positionId:e?.id??``}),placeholder:J.orgUnitId?.trim()?`選擇職位`:`請先選擇組織`,positions:a,value:n})}):null]})}function Pr(e){let t=C.edges.filter(t=>t.target===e.id).length,n=t<2,r=n?`AND`:e.data.triggerMode??`AND`;return(0,c.jsx)(i.t,{hintText:n?`需要至少兩條前置連線,才可切換為任一前置完成。`:t>1?`${t} 條前置連線會依此規則觸發。`:`只有一條前置連線時,兩種設定效果相同。`,label:`前置條件`,name:`triggerMode`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>n?void 0:Dr(jt(e?.id??null)),options:[...et],readOnly:n,value:z(et,r)})})}function Fr(e){let t=e.data.approverResolver,n=Ht(t.type),a=t.type===`DIRECT`?bn(t.memberIds,F):null,o=t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?xn(L,t.orgUnitId):null,l=t.type===`POSITION`||t.type===`ORG_UNIT_POSITION`?Sn(R,t.positionId):null,u=t.type===`ORG_UNIT_POSITION`?Dn({includeDescendants:!!t.includeDescendants,memberships:Et,orgUnitId:t.orgUnitId,orgUnits:L,positions:R}):[],d=t.type===`ORG_MANAGER`?Kt(t.levelsUp):M[0],f=t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?t.fallback??{type:`NONE`}:{type:`NONE`},p=f.type===`DIRECT`?yn(F,f.memberId):null,m=e.data.returnBehavior.resubmitStrategy??`RESTART`,h=e.data.sla??null,g=h?(0,b.readSlaDurationParts)(h.duration):null,_=g?.unit??`DAY`,v=It(h?.warningAt??null),y=Kt(h?.escalateLevelsUp??1);return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.t,{label:`簽核來源`,name:`approverResolverType`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>Q(Ut(e?.id??null)),options:[...rt],value:z(rt,n)})}),t.type===`DIRECT`?(0,c.jsx)(i.t,{label:`簽核者`,name:`memberId`,required:!0,children:(0,c.jsx)(s.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-search`,spellCheck:!1},loading:yt,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>Q({memberIds:e?.id?[e.id]:[],type:`DIRECT`}),onSearch:Z,onVisibilityChange:e=>{e&&Z(``)},options:[...F],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:a})}):null,t.type===`ORG_MANAGER`?(0,c.jsx)(i.t,{hintText:`依發起人的有效會員歸屬與主管解析規則決定簽核人。`,label:`主管層級`,name:`managerLevelsUp`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>Q({baseFromInitiator:!0,levelsUp:qt(e?.id??null).value,type:`ORG_MANAGER`}),options:[...M],value:d})}):null,t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{hintText:t.type===`ORG_UNIT_MANAGER`?`依指定組織或其上層的主管解析規則決定簽核人。`:`依指定組織目前有效會員歸屬建立候選簽核人。`,label:`組織`,name:`orgUnitId`,required:!0,children:(0,c.jsx)(r.n,{name:`orgUnitId`,onChange:e=>Q(t.type===`ORG_UNIT_MEMBER`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,type:`ORG_UNIT_MEMBER`}:t.type===`ORG_UNIT_POSITION`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,positionId:``,type:`ORG_UNIT_POSITION`}:{fallback:t.fallback,orgUnitId:e?.id??``,type:`ORG_UNIT_MANAGER`}),orgUnits:L,placeholder:`選擇組織`,value:o})}):null,t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.t,{hintText:`預設會停止流程並提示;若設定固定人,找不到主管時會改派給該會員。`,label:`無主管時`,name:`approverFallbackMode`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>Q(Gt(t,Wt(e?.id??null)===`DIRECT`?{memberId:``,type:`DIRECT`}:{type:`NONE`})),options:[...it],value:z(it,f.type)})}),f.type===`DIRECT`?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.t,{label:`改派人員`,name:`approverFallbackMemberId`,required:!0,children:(0,c.jsx)(s.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-fallback-search`,spellCheck:!1},loading:yt,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>Q(Gt(t,{allowInitiatorSelfApproval:f.allowInitiatorSelfApproval,memberId:e?.id??``,type:`DIRECT`})),onSearch:Z,onVisibilityChange:e=>{e&&Z(``)},options:[...F],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:p})}),(0,c.jsx)(i.t,{hintText:`預設禁止申請人簽自己的案件;只有此流程允許自簽時才開啟。`,label:`允許自簽`,name:`allowInitiatorSelfApproval`,children:(0,c.jsx)(s.Toggle,{checked:!!f.allowInitiatorSelfApproval,inputProps:{id:`allowInitiatorSelfApproval`,name:`allowInitiatorSelfApproval`},onChange:e=>Q(Gt(t,{allowInitiatorSelfApproval:e.target.checked,memberId:f.memberId,type:`DIRECT`}))})})]}):null]}):null,t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{label:`包含下層`,name:`includeDescendants`,children:(0,c.jsx)(s.Toggle,{checked:!!t.includeDescendants,inputProps:{id:`includeDescendants`,name:`includeDescendants`},onChange:e=>Q({...t,includeDescendants:e.target.checked,...t.type===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,t.type===`POSITION`?(0,c.jsx)(i.t,{hintText:`指派給目前有效歸屬中擁有此職位的會員;主要歸屬優先。`,label:`職位`,name:`positionId`,required:!0,children:(0,c.jsx)(r.r,{name:`positionId`,onChange:e=>Q({positionId:e?.id??``,type:`POSITION`}),placeholder:`選擇職位`,positions:R,value:l})}):null,t.type===`ORG_UNIT_POSITION`?(0,c.jsx)(i.t,{hintText:`只納入指定組織範圍內擁有此職位的有效會員。`,label:`職位`,name:`orgUnitPositionId`,required:!0,children:(0,c.jsx)(r.r,{disabled:!t.orgUnitId.trim(),name:`orgUnitPositionId`,onChange:e=>Q({includeDescendants:t.includeDescendants,orgUnitId:t.orgUnitId,positionId:e?.id??``,type:`ORG_UNIT_POSITION`}),placeholder:t.orgUnitId.trim()?`選擇職位`:`請先選擇組織`,positions:u,value:l})}):null,e.data.returnBehavior.allowReturn?(0,c.jsx)(i.t,{hintText:`退回發起人後,重新送出時要從流程開始重跑,或直接回到退回的簽核節點。`,label:`重送策略`,name:`returnResubmitStrategy`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>Cr(Mt(e?.id??null)),options:[...tt],value:z(tt,m)})}):null,e.data.returnBehavior.allowReturn?(0,c.jsx)(i.t,{hintText:`開啟後,簽核者按下退回時必須填寫意見,未填寫會被擋下。`,label:`退回時意見必填`,name:`returnRequireComment`,children:(0,c.jsx)(s.Toggle,{checked:e.data.returnBehavior.requireComment===!0,inputProps:{id:`returnRequireComment`,name:`returnRequireComment`},onChange:e=>wr(e.target.checked)})}):null,(0,c.jsx)(i.t,{hintText:`開啟後可設定簽核期限,逾時將依下方設定處理。`,label:`啟用時效`,name:`slaEnabled`,children:(0,c.jsx)(s.Toggle,{checked:!!h,inputProps:{id:`slaEnabled`,name:`slaEnabled`},onChange:e=>$(e.target.checked?b.DEFAULT_SLA_CONFIG:null)})}),h&&!g?(0,c.jsx)(i.t,{hintText:`此期限混用了日與時,無法在表單中編輯。請改以單一單位設定,或透過 API 維護。`,label:`時效期限`,name:`slaDurationRaw`,children:(0,c.jsx)(s.Input,{disabled:!0,value:h.duration,variant:`base`})}):null,h&&g?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.t,{label:`時效期限`,name:`slaDurationValue`,required:!0,children:(0,c.jsx)(s.Input,{id:`slaDurationValue`,inputProps:{min:1},inputType:`number`,name:`slaDurationValue`,onChange:e=>$(Rt(h,{unit:_,value:Number(e.target.value)})),value:String(g.value),variant:`base`})}),(0,c.jsx)(i.t,{label:`期限單位`,name:`slaDurationUnit`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>$(Rt(h,{unit:Nt(e?.id??null),value:g.value})),options:[...b.SLA_DURATION_UNIT_OPTIONS],value:z(b.SLA_DURATION_UNIT_OPTIONS,_)})})]}):null,h&&_===`DAY`?(0,c.jsx)(i.t,{hintText:`工作日會跳過週末與行事曆上的假日,補班日仍計為工作日;行事曆由系統管理者設定。`,label:`計算方式`,name:`slaCalendar`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>$({...h,calendar:Pt(e?.id??null)}),options:[...b.SLA_CALENDAR_MODE_OPTIONS],value:z(b.SLA_CALENDAR_MODE_OPTIONS,h.calendar??`CALENDAR`)})}):null,h?(0,c.jsx)(i.t,{label:`逾時處理`,name:`slaOnTimeout`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>$(zt(h,Ft(e?.id??null))),options:[...b.SLA_TIMEOUT_ACTION_OPTIONS],value:z(b.SLA_TIMEOUT_ACTION_OPTIONS,h.onTimeout)})}):null,h?.onTimeout===`ESCALATE`?(0,c.jsx)(i.t,{hintText:`逾時後改派給簽核者的上層主管,只會升級一次。`,label:`升級層級`,name:`slaEscalateLevelsUp`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>$({...h,escalateLevelsUp:qt(e?.id??null).value}),options:[...M],value:y})}):null,h?(0,c.jsx)(i.t,{hintText:`在期限到達前先送出一次提醒。`,label:`預警提醒`,name:`slaWarningAt`,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:e=>$(Bt(h,Lt(e?.id??null).value)),options:[...nt],value:v})}):null]})}function Ir(e){let t=Jn(e.data.action).map(e=>yn(F,e));return(0,c.jsx)(i.t,{label:`知會對象`,name:`notifyMemberIds`,required:!0,children:(0,c.jsx)(s.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,loading:yt,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>Tr({channels:[`IN_APP`],recipients:{memberIds:e.map(e=>e.id),type:`DIRECT`},type:`NOTIFY`}),onSearch:Z,onVisibilityChange:e=>{e&&Z(``)},options:[...F],overflowStrategy:`wrap`,placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:[...t]})})}function Lr(e){return(0,c.jsxs)(`div`,{style:T,children:[(0,c.jsx)(s.Typography,{component:`h2`,variant:`h3`,children:`已選取線段`}),(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`body`,children:[`已選取 `,e.length,` 條線段,可使用 Delete 或控制面板刪除。`]})]})}function Rr(e){let t=K(e,C.nodes);return(0,c.jsxs)(`div`,{style:T,children:[(0,c.jsx)(s.Typography,{component:`h2`,variant:`h3`,children:t?`條件設定`:`線段屬性`}),(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`body`,children:[e.source,` → `,e.target]}),t?Br(e):(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`這條線會直接把流程送到下一個節點。`})]})}function zr(e){return!e||!K(e,C.nodes)?null:(0,c.jsx)(s.Modal,{cancelText:`取消`,confirmButtonProps:{disabled:!e.data.isDefault&&!e.data.condition},confirmText:`完成`,modalType:`standard`,onCancel:br,onClose:br,onConfirm:br,open:!!Ve,showModalFooter:!0,showModalHeader:!0,size:`regular`,supportingText:`條件分流的輸出連線需要指定條件,條件會直接顯示在線上。`,title:`條件設定`,children:Br(e)})}function Br(e){let t=Gn(e,C.nodes),n=zn(Y?.schema??null),r=Bn(Y?.schema??null,e.data.conditionFieldKey??null),a=Vn(r),o=Un(r),l=z(a,e.data.conditionOperator??null);return(0,c.jsxs)(`div`,{style:T,children:[(0,c.jsxs)(s.Typography,{color:`text-neutral`,variant:`body`,children:[`畫布上的這條線目前會顯示「`,(0,c.jsx)(`span`,{style:{color:!e.data.isDefault&&!e.data.condition?Ae:void 0},children:t??`請設定條件`}),`」。`]}),(0,c.jsx)(s.Toggle,{checked:!!e.data.isDefault,label:`其他情況走這條`,onChange:t=>Or(e.id,t.target.checked)}),e.data.isDefault?(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`其他條件都不符合時,流程會走這條線。`}):(0,c.jsxs)(c.Fragment,{children:[Y?null:(0,c.jsx)(s.Typography,{color:`text-neutral`,variant:`body`,children:`請先綁定表單版本,才能選擇條件欄位。`}),(0,c.jsx)(i.t,{label:`條件欄位`,name:`edgeConditionField`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:t=>kr({edgeId:e.id,fieldKey:t?.id??null,operator:null,value:null}),options:[...n],placeholder:`選擇條件欄位`,value:z(n,e.data.conditionFieldKey??null)})}),(0,c.jsx)(i.t,{label:`條件判斷`,name:`edgeConditionOperator`,required:!0,children:(0,c.jsx)(s.Select,{clearable:!1,onChange:t=>kr({edgeId:e.id,operator:Hn(t?.id??null),value:null}),options:[...a],placeholder:`選擇判斷方式`,value:l})}),l&&Wn(l.id)?(0,c.jsx)(i.t,{label:`條件值`,name:`edgeConditionValue`,required:!0,children:o.length>0?(0,c.jsx)(s.Select,{clearable:!1,onChange:t=>kr({edgeId:e.id,value:t?.id??null}),options:[...o],placeholder:`選擇條件值`,value:z(o,e.data.conditionValue??null)}):(0,c.jsx)(s.Input,{onChange:t=>kr({edgeId:e.id,value:t.target.value}),placeholder:`輸入要比對的值`,value:e.data.conditionValue??``,variant:`base`})}):null]})]})}}function _t({onApplyAutoLayout:e}){function t(){e()}return(0,c.jsx)(g.Panel,{position:`top-right`,children:(0,c.jsx)(s.Button,{icon:d.DotGridIcon,iconType:`leading`,onClick:t,size:`sub`,variant:`base-secondary`,children:`自動排版`})})}function P({data:e,selected:t,type:n}){let r=e.approverLines??[e.approverSummary??e.label],i=vt(e);return(0,c.jsxs)(`div`,{style:yt(n,t),children:[F(e),(0,c.jsx)(`div`,{style:Ye,children:r.map((e,t)=>(0,c.jsx)(s.Typography,{component:`span`,ellipsis:!0,style:A,title:e,variant:`label-primary`,children:e},`${e}_${t}`))}),(0,c.jsx)(s.Typography,{color:`text-neutral`,component:`span`,ellipsis:!0,style:A,title:i,variant:`caption`,children:i})]})}function vt(e){return e.nodeKind===`startEvent`?e.initiatorPolicySummary??`所有人`:e.approverSummary||e.approverLines?e.label:e.nodeKind===`exclusiveGateway`?`條件在線上`:e.nodeKind===`parallelGateway`?`多條路徑同時進行`:Ze[e.nodeKind]}function yt(e,t){let n=bt(e);return t?{...n,border:`1px solid var(--mzn-color-primary, #0057ff)`,boxShadow:Be}:n}function bt(e){return e===`exclusiveGateway`?Ge:e===`parallelGateway`?Ke:e===`startEvent`?k:e===`endEvent`?Je:e===`userTask`?qe:E}function F(e){return!e.hasInput&&e.hasOutput?(0,c.jsx)(g.Handle,{id:Xe,position:g.Position.Right,type:`source`}):e.hasInput&&!e.hasOutput?(0,c.jsx)(g.Handle,{id:j,position:g.Position.Left,type:`target`}):!e.hasInput&&!e.hasOutput?null:[(0,c.jsx)(g.Handle,{id:j,position:g.Position.Left,type:`target`},`target`),(0,c.jsx)(g.Handle,{id:Xe,position:g.Position.Right,type:`source`},`source`)]}function xt(e,t,n,r,i,a){let o=I(e);return{data:{approverLines:Mn(e,t),approverSummary:An(e,t,n,r),hasInput:on(e),hasOutput:sn(e),initiatorPolicySummary:e.type===`startEvent`?en(a,n,r):null,label:e.data.label,nodeKind:e.type},height:o.height,handles:L(e),id:e.id,initialHeight:o.height,initialWidth:o.width,position:e.position,selected:i,sourcePosition:g.Position.Right,targetPosition:g.Position.Left,type:e.type,width:o.width}}function I(e){return e.type===`exclusiveGateway`||e.type===`parallelGateway`?{height:Ue,width:We}:e.type===`serviceTask`?{height:D+(Math.max(1,Jn(e.data.action).length)-1)*He,width:Ve}:{height:D,width:Ve}}function L(e){let t=I(e);return[...on(e)?[St(t)]:[],...sn(e)?[R(t)]:[]]}function St({height:e}){let t=e/2-9/2;return{height:9,id:j,position:g.Position.Left,type:`target`,width:9,x:-9/2,y:t}}function R({height:e,width:t}){let n=e/2-9/2;return{height:9,id:Xe,position:g.Position.Right,type:`source`,width:9,x:t-9/2,y:n}}function Ct(e,t,n){let r=Gn(e,t),i=K(e,t),a=i&&!e.data.isDefault&&!e.data.condition,o=a?Ae:i?S:`#475569`,s=a?`#fef2f2`:i?`#eff6ff`:`#ffffff`,c=a?Ae:i?S:C;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?w:void 0,opacity:1,stroke:C,strokeOpacity:1,strokeWidth:1.5},target:e.target,targetHandle:e.targetHandle,type:e.type??`smoothstep`}}function wt(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 Tt(e){return Dt(Et(e))}function Et(e){let t=new Set(e.nodes.filter(e=>B(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 Dt(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`?wt(e,`AND`):e);return n.some((t,n)=>t!==e.nodes[n])?{...e,nodes:n}:e}function Ot(){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 kt(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 At(e){let t=new _.graphlib.Graph;return t.setDefaultEdgeLabel(()=>({})),t.setGraph({rankdir:`LR`,ranksep:120}),e.nodes.forEach(e=>{t.setNode(e.id,I(e))}),e.edges.forEach(e=>{t.setEdge(e.source,e.target)}),_.layout(t),{...e,nodes:e.nodes.map(e=>{let n=t.node(e.id);return n?{...e,position:{x:n.x-I(e).width/2,y:n.y-I(e).height/2}}:e})}}function z(e,t){return t?e.find(e=>e.id===t)??null:null}function jt(e){return e===`OR`?`OR`:`AND`}function Mt(e){return e===`FROM_RETURN_POINT`?`FROM_RETURN_POINT`:`RESTART`}function Nt(e){return e===`HOUR`?`HOUR`:`DAY`}function Pt(e){return e===`BUSINESS_DAY`?`BUSINESS_DAY`:`CALENDAR`}function Ft(e){return b.SLA_TIMEOUT_ACTION_OPTIONS.find(t=>t.id===e)?.id??`REMIND`}function It(e){return nt.find(t=>t.value===e)??nt[0]}function Lt(e){return nt.find(t=>t.id===e)??nt[0]}function Rt(e,t){let n=Number.isFinite(t.value)?Math.trunc(t.value):1,r=(0,b.composeSlaDuration)({unit:t.unit,value:n});return{...e,calendar:t.unit===`DAY`?e.calendar??`CALENDAR`:`CALENDAR`,duration:r}}function zt(e,t){return t===`ESCALATE`?{...e,escalateLevelsUp:e.escalateLevelsUp??1,onTimeout:t}:{...Vt(e,`escalateLevelsUp`),onTimeout:t}}function Bt(e,t){return t===null?Vt(e,`warningAt`):{...e,warningAt:t}}function Vt(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function Ht(e){return e===`ORG_MANAGER`||e===`ORG_UNIT_MANAGER`||e===`ORG_UNIT_MEMBER`||e===`ORG_UNIT_POSITION`||e===`POSITION`?e:`DIRECT`}function Ut(e){let t=Ht(e??`DIRECT`);return t===`ORG_MANAGER`?{baseFromInitiator:!0,levelsUp:1,type:`ORG_MANAGER`}:t===`ORG_UNIT_MANAGER`?{orgUnitId:``,type:`ORG_UNIT_MANAGER`}:t===`ORG_UNIT_MEMBER`?{includeDescendants:!1,orgUnitId:``,type:`ORG_UNIT_MEMBER`}:t===`ORG_UNIT_POSITION`?{includeDescendants:!1,orgUnitId:``,positionId:``,type:`ORG_UNIT_POSITION`}:t===`POSITION`?{positionId:``,type:`POSITION`}:{memberIds:[],type:`DIRECT`}}function Wt(e){return e===`DIRECT`?`DIRECT`:`NONE`}function Gt(e,t){return e.type===`ORG_MANAGER`||e.type===`ORG_UNIT_MANAGER`?{...e,fallback:t}:e}function Kt(e){return M.find(t=>t.value===e)??M[0]}function qt(e){return M.find(t=>t.id===e)??M[0]}function Jt(e){return e===`ORG_UNIT`||e===`ORG_UNIT_POSITION`||e===`NONE`?e:`ALL`}function Yt(e){let t=e?.trim();if(!t)return{mode:`ALL`,value:``};let n=Qt(t,/"([^"]+)" in subject\.orgUnitIds/gu),r=Qt(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 Xt(e,t){let n=Yt(e);return!t||t===`ALL`||t===`NONE`?t===`ALL`||t===`NONE`?{mode:t,value:``}:n:n.mode===t?n:tn(t)}function Zt(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 Qt(e,t){return[...e.matchAll(t)].map(e=>e[1]).filter(e=>!!e)}function $t(e,t){if(e.mode===`ALL`||e.mode===`NONE`)return null;let n=e.orgUnitId?.trim()??``;if(!n)return null;let r=W(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 en(e,t,n){return e.mode===`NONE`?`未設定`:e.mode===`ORG_UNIT`?e.orgUnitId?`組織:${V(t,e.orgUnitId)}`:`指定組織`:e.mode===`ORG_UNIT_POSITION`?e.orgUnitId&&e.positionId?`組織職位:${V(t,e.orgUnitId)} / ${H(n,e.positionId)}`:`指定組織職位`:e.mode===`CUSTOM`?`既有自訂規則`:`所有人`}function tn(e){return{includeDescendants:!0,mode:e,orgUnitId:``,positionId:``,value:``}}function nn(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===Xe&&e.targetHandle===j&&!!(n&&sn(n))&&!!(r&&on(r))}function rn(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function an(e){return e.type!==`startEvent`&&e.type!==`endEvent`}function on(e){return e.type!==`startEvent`}function sn(e){return e.type!==`endEvent`&&!B(e)}function B(e){return e.type===`serviceTask`&&e.data.action.type===`NOTIFY`}function cn(e){return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||!!e.closest(`[contenteditable="true"]`):!1}function ln(e){return e.map(e=>({formDefinitionId:e.formDefinitionId,formName:e.formName,id:e.id,name:`${e.formName} | v${e.version}`,schema:e.schema}))}function un(e){return(e?.schema.fields??[]).reduce((e,t)=>({...e,[t.fieldKey]:dn(t)}),{})}function dn(e){return e.type===`number`?1e3:e.type===`boolean`?!0:e.type===`select`?e.options[0]?.value??``:e.type===`checkbox`?e.options[0]?[e.options[0].value]:[]:e.type===`date`?`2026-05-08`:e.type===`datetime`?`2026-05-08T09:00:00+08:00`:e.placeholder??e.label}function fn(e){let t=JSON.parse(e);if(!pn(t))throw Error(`表單資料 JSON 必須是物件。`);return t}function pn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function mn(e){return e===`COMPLETED`?`完成`:e===`PASSED`?`通過`:e===`SKIPPED`?`略過`:e===`STOPPED`?`已停止`:e===`WAITING`?`將等待簽核`:e}function hn(e){return e in Ze?Ze[e]:e}function gn(e,t){return t&&!e.some(e=>e.id===t.id)?[t,...e]:e}function _n(e){return e.map(e=>({displayName:e.name,email:e.email,id:e.memberId,memberId:e.memberId,name:Pn(e.name,e.email)}))}function vn(e){return{displayName:`未知會員`,email:``,id:e,memberId:e,name:`未知會員`}}function yn(e,t){return e.find(e=>e.memberId===t)??vn(t)}function bn(e,t){let n=e[0];return n?yn(t,n):null}function xn(e,t){let n=e.find(e=>e.id===t);return n?r.a(n):null}function Sn(e,t){let n=e.find(e=>e.id===t);return n?r.o(n):null}function V(e,t){return xn(e,t)?.name??`未指定組織`}function H(e,t){return Sn(e,t)?.name??`未指定職位`}function Cn(e,t){let n=wn(),r=t.filter(t=>t.memberId===e&&Tn(t,n)),i=r.reduce((e,t)=>e&&En(e,t)<=0?e:t,null);return{customFields:{},managerMemberId:`member-002`,memberId:e,orgCode:`HQ`,orgUnitIds:U(r.map(e=>e.orgUnitId)),positionId:i?.positionId??null,positionIds:U(r.map(e=>e.positionId)),primaryOrgUnitId:i?.orgUnitId??null,roles:[`manager`]}}function wn(){return new Date().toISOString().slice(0,10)}function Tn(e,t){return e.effectiveFrom<=t&&(!e.effectiveTo||e.effectiveTo>=t)}function En(e,t){return e.isPrimary===t.isPrimary?t.effectiveFrom.localeCompare(e.effectiveFrom):e.isPrimary?-1:1}function U(e){return e.reduce((e,t)=>t&&!e.includes(t)?[...e,t]:e,[])}function Dn({includeDescendants:e,memberships:t,orgUnitId:n,orgUnits:r,positions:i}){let a=new Set(W(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 W(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 On(e,t){let n=new Set(e.map(e=>e.memberId)),r=t.filter(e=>!n.has(e.memberId));return[...e,...r]}function kn(e){return[...new Set(e.nodes.flatMap(e=>e.type===`userTask`?e.data.approverResolver.type===`DIRECT`?e.data.approverResolver.memberIds:[]:e.type===`serviceTask`?Jn(e.data.action):[]))]}function An(e,t,n,r){return e.type===`userTask`?jn(e.data.approverResolver,t,n,r):null}function jn(e,t,n,r){return e.type===`DIRECT`?Nn(e.memberIds,t,`未指定簽核者`):e.type===`ORG_MANAGER`?Kt(e.levelsUp).name:e.type===`ORG_UNIT_MANAGER`?`組織主管:${V(n,e.orgUnitId)}`:e.type===`ORG_UNIT_MEMBER`?`組織任一人:${V(n,e.orgUnitId)}`:e.type===`ORG_UNIT_POSITION`?`組織職位:${V(n,e.orgUnitId)} / ${H(r,e.positionId)}`:e.type===`POSITION`?`職位:${H(r,e.positionId)}`:e.type===`DYNAMIC_FORM`?`表單欄位:${e.formPath||`未設定`}`:`自訂表達式`}function Mn(e,t){if(e.type!==`serviceTask`)return null;let n=Jn(e.data.action);return n.length===0?[`未指定知會對象`]:n.map(e=>yn(t,e).name)}function Nn(e,t,n){let r=e.map(e=>yn(t,e).name);return r.length===0?n:r.length<=2?r.join(`、`):`${r.slice(0,2).join(`、`)} 等 ${r.length} 人`}function Pn(e,t){return`${e} (${t})`}function Fn(e,t){let n=t?.getBoundingClientRect();if(!n||e.nodes.length===0)return null;let r=e.nodes.reduce((e,t)=>{let n=I(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,g.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 In(e){let t=e.nodes.find(e=>e.type===`userTask`&&!!Ln(e.data.approverResolver)),n=e.nodes.find(e=>e.type===`serviceTask`&&e.data.action.type===`NOTIFY`&&Jn(e.data.action).length===0),r=e.edges.find(t=>K(t,e.nodes)&&!t.data.isDefault&&!t.data.condition);return t&&t.type===`userTask`?Ln(t.data.approverResolver):n?`知會節點需要至少一位知會對象。`:r?`條件分流的每條輸出連線都需要先設定條件。`:null}function Ln(e){return e.type===`DIRECT`&&e.memberIds.length===0?`簽核節點需要指定簽核會員。`:e.type===`ORG_MANAGER`&&e.levelsUp<1?`簽核節點需要指定有效的主管層級。`:e.type===`ORG_UNIT_MANAGER`&&!e.orgUnitId.trim()||e.type===`ORG_UNIT_MEMBER`&&!e.orgUnitId.trim()?`簽核節點需要指定組織。`:e.type===`ORG_UNIT_POSITION`&&(!e.orgUnitId.trim()||!e.positionId.trim())?`簽核節點需要指定組織與職位。`:(e.type===`ORG_MANAGER`||e.type===`ORG_UNIT_MANAGER`)&&e.fallback?.type===`DIRECT`&&!e.fallback.memberId.trim()?`簽核節點需要指定改派固定人。`:e.type===`POSITION`&&!e.positionId.trim()?`簽核節點需要指定職位。`:null}function Rn(e){return e.edges.some(t=>K(t,e.nodes)&&!!(t.data.condition||t.data.conditionFieldKey||t.data.conditionOperator||t.data.conditionValue))}function zn(e){return e?.fields.map(e=>({fieldType:e.type,id:e.fieldKey,name:`${e.label} (${e.fieldKey})`}))??[]}function Bn(e,t){return t?e?.fields.find(e=>e.fieldKey===t)??null:null}function Vn(e){if(!e)return[];let t=G(e);return at.filter(e=>t.includes(e.id))}function Hn(e){return at.some(t=>t.id===e)?e:null}function G(e){return e.type===`file_upload`?[`IS_FILLED`,`IS_EMPTY`]:e.type===`boolean`?[`EQUALS`,`NOT_EQUALS`,`IS_FILLED`,`IS_EMPTY`]:e.type===`date`||e.type===`datetime`||e.type===`money`||e.type===`number`?[`EQUALS`,`NOT_EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`IS_FILLED`,`IS_EMPTY`]:[`EQUALS`,`NOT_EQUALS`,`IS_FILLED`,`IS_EMPTY`]}function Un(e){return e?e.type===`boolean`?[{id:`true`,name:`是`},{id:`false`,name:`否`}]:e.type===`checkbox`||e.type===`radio`||e.type===`select`?e.options.map(e=>({id:e.value,name:e.label})):[]:[]}function Wn(e){return ot.includes(e)}function Gn(e,t){if(e.data.label)return e.data.label;if(K(e,t))return Kn(e);if(qn(e,t))return`同時進行`}function Kn(e){return e.data.isDefault?`其他情況`:`請設定條件`}function K(e,t){return t.some(t=>t.id===e.source&&t.type===`exclusiveGateway`)}function qn(e,t){return t.some(t=>t.id===e.source&&t.type===`parallelGateway`)}function Jn(e){return e.type===`NOTIFY`&&e.recipients.type===`DIRECT`?e.recipients.memberIds:[]}function q(e){return e instanceof Error?e.message:`發生未知錯誤`}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return gt}});
65
- //# sourceMappingURL=designer-CQ9hxSdD.cjs.map