@rytass/bpm-core-react 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -0
- package/dist/chunks/app-navigation-BSkMsEhy.js +268 -0
- package/dist/chunks/app-navigation-BSkMsEhy.js.map +1 -0
- package/dist/chunks/app-navigation-KnlJCUp1.cjs +2 -0
- package/dist/chunks/app-navigation-KnlJCUp1.cjs.map +1 -0
- package/dist/chunks/approval-instance-list-page-CVXgE2K3.cjs +2 -0
- package/dist/chunks/approval-instance-list-page-CVXgE2K3.cjs.map +1 -0
- package/dist/chunks/{approval-instance-list-page-nmzMrj0b.js → approval-instance-list-page-CqNdoZqx.js} +73 -72
- package/dist/chunks/approval-instance-list-page-CqNdoZqx.js.map +1 -0
- package/dist/chunks/builder-CMlJfQHE.cjs +3 -0
- package/dist/chunks/builder-CMlJfQHE.cjs.map +1 -0
- package/dist/chunks/{builder-DqZskyXC.js → builder-D950gct_.js} +492 -491
- package/dist/chunks/builder-D950gct_.js.map +1 -0
- package/dist/chunks/categories-5yEM3p3N.cjs +2 -0
- package/dist/chunks/categories-5yEM3p3N.cjs.map +1 -0
- package/dist/chunks/{categories-DTEl182t.js → categories-BIpOG451.js} +115 -114
- package/dist/chunks/categories-BIpOG451.js.map +1 -0
- package/dist/chunks/dashboard-page-1K_jQXQk.cjs +2 -0
- package/dist/chunks/dashboard-page-1K_jQXQk.cjs.map +1 -0
- package/dist/chunks/dashboard-page-R_T2OEiE.js +122 -0
- package/dist/chunks/dashboard-page-R_T2OEiE.js.map +1 -0
- package/dist/chunks/{delegations-C5PzZ5Kn.js → delegations-B2j-wNEO.js} +193 -192
- package/dist/chunks/delegations-B2j-wNEO.js.map +1 -0
- package/dist/chunks/delegations-CsB9ozLu.cjs +2 -0
- package/dist/chunks/delegations-CsB9ozLu.cjs.map +1 -0
- package/dist/chunks/delegations-CvtwTXNP.cjs +2 -0
- package/dist/chunks/delegations-CvtwTXNP.cjs.map +1 -0
- package/dist/chunks/{delegations-C-ZrwzvU.js → delegations-dKodb0WW.js} +175 -174
- package/dist/chunks/delegations-dKodb0WW.js.map +1 -0
- package/dist/chunks/{detail-CfFyU5zC.js → detail-BcGAqJ_R.js} +465 -464
- package/dist/chunks/detail-BcGAqJ_R.js.map +1 -0
- package/dist/chunks/detail-CqjqLd65.cjs +2 -0
- package/dist/chunks/detail-CqjqLd65.cjs.map +1 -0
- package/dist/chunks/{format-date-time-isOa3e9q.cjs → format-date-time-26_pFvv4.cjs} +2 -2
- package/dist/chunks/{format-date-time-isOa3e9q.cjs.map → format-date-time-26_pFvv4.cjs.map} +1 -1
- package/dist/chunks/notifications-2swRqDPF.js +198 -0
- package/dist/chunks/notifications-2swRqDPF.js.map +1 -0
- package/dist/chunks/notifications-BaYDebFt.cjs +2 -0
- package/dist/chunks/notifications-BaYDebFt.cjs.map +1 -0
- package/dist/chunks/{orgs-xrdhb3hS.js → orgs-CuHxxd_n.js} +608 -607
- package/dist/chunks/orgs-CuHxxd_n.js.map +1 -0
- package/dist/chunks/orgs-YMiVLNvL.cjs +2 -0
- package/dist/chunks/orgs-YMiVLNvL.cjs.map +1 -0
- package/dist/chunks/routes-config-2aKbWq2H.cjs +2 -0
- package/dist/chunks/routes-config-2aKbWq2H.cjs.map +1 -0
- package/dist/chunks/routes-config-dxahImVe.js +43 -0
- package/dist/chunks/routes-config-dxahImVe.js.map +1 -0
- package/dist/chunks/templates-DTkbSgFY.cjs +2 -0
- package/dist/chunks/templates-DTkbSgFY.cjs.map +1 -0
- package/dist/chunks/templates-DoDWM68t.js +384 -0
- package/dist/chunks/templates-DoDWM68t.js.map +1 -0
- package/dist/chunks/users-3ySyUW4u.cjs +2 -0
- package/dist/chunks/users-3ySyUW4u.cjs.map +1 -0
- package/dist/chunks/{users-CY4-NK3j.js → users-sMfrSjRQ.js} +75 -74
- package/dist/chunks/users-sMfrSjRQ.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +101 -99
- package/dist/index.js.map +1 -1
- package/dist/lib/routes-config.d.ts +96 -0
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.ts +1 -0
- package/dist/next/index.js +22 -21
- package/dist/next/index.js.map +1 -1
- package/dist/pages/admin/delegations/index.cjs +1 -1
- package/dist/pages/admin/delegations/index.js +1 -1
- package/dist/pages/admin/orgs/index.cjs +1 -1
- package/dist/pages/admin/orgs/index.js +1 -1
- package/dist/pages/admin/users/index.cjs +1 -1
- package/dist/pages/admin/users/index.js +1 -1
- package/dist/pages/delegations/index.cjs +1 -1
- package/dist/pages/delegations/index.js +1 -1
- package/dist/pages/forms/builder/index.cjs +1 -1
- package/dist/pages/forms/builder/index.js +1 -1
- package/dist/pages/instances/detail/index.cjs +1 -1
- package/dist/pages/instances/detail/index.js +1 -1
- package/dist/pages/settings/notifications/index.cjs +1 -1
- package/dist/pages/settings/notifications/index.js +1 -1
- package/dist/pages/templates/categories/index.cjs +1 -1
- package/dist/pages/templates/categories/index.js +1 -1
- package/dist/pages/templates/index.cjs +1 -1
- package/dist/pages/templates/index.js +1 -1
- package/dist/views/admin/delegations/index.cjs +1 -1
- package/dist/views/admin/delegations/index.js +1 -1
- package/dist/views/admin/index.cjs +1 -1
- package/dist/views/admin/index.js +3 -3
- package/dist/views/admin/orgs/index.cjs +1 -1
- package/dist/views/admin/orgs/index.js +1 -1
- package/dist/views/admin/users/index.cjs +1 -1
- package/dist/views/admin/users/index.js +1 -1
- package/dist/views/cc/index.cjs +1 -1
- package/dist/views/cc/index.js +1 -1
- package/dist/views/dashboard/index.cjs +1 -1
- package/dist/views/dashboard/index.js +1 -1
- package/dist/views/delegations/index.cjs +1 -1
- package/dist/views/delegations/index.js +1 -1
- package/dist/views/forms/builder/index.cjs +1 -1
- package/dist/views/forms/builder/index.js +1 -1
- package/dist/views/forms/index.cjs +1 -1
- package/dist/views/forms/index.cjs.map +1 -1
- package/dist/views/forms/index.js +78 -77
- package/dist/views/forms/index.js.map +1 -1
- package/dist/views/inbox/index.cjs +1 -1
- package/dist/views/inbox/index.cjs.map +1 -1
- package/dist/views/inbox/index.js +106 -105
- package/dist/views/inbox/index.js.map +1 -1
- package/dist/views/instances/detail/index.cjs +1 -1
- package/dist/views/instances/detail/index.js +1 -1
- package/dist/views/instances/new/index.cjs +1 -1
- package/dist/views/instances/new/index.cjs.map +1 -1
- package/dist/views/instances/new/index.js +90 -89
- package/dist/views/instances/new/index.js.map +1 -1
- package/dist/views/search/index.cjs +1 -1
- package/dist/views/search/index.js +1 -1
- package/dist/views/sent/index.cjs +1 -1
- package/dist/views/sent/index.js +1 -1
- package/dist/views/settings/index.cjs +1 -1
- package/dist/views/settings/index.js +1 -1
- package/dist/views/settings/notifications/index.cjs +1 -1
- package/dist/views/settings/notifications/index.js +1 -1
- package/dist/views/templates/categories/index.cjs +1 -1
- package/dist/views/templates/categories/index.js +1 -1
- package/dist/views/templates/designer/index.cjs +6 -6
- package/dist/views/templates/designer/index.cjs.map +1 -1
- package/dist/views/templates/designer/index.js +589 -588
- package/dist/views/templates/designer/index.js.map +1 -1
- package/dist/views/templates/index.cjs +1 -1
- package/dist/views/templates/index.js +2 -2
- package/dist/views/templates/versions/index.cjs +1 -1
- package/dist/views/templates/versions/index.cjs.map +1 -1
- package/dist/views/templates/versions/index.js +44 -43
- package/dist/views/templates/versions/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/app-navigation-C_mbz7jx.cjs +0 -2
- package/dist/chunks/app-navigation-C_mbz7jx.cjs.map +0 -1
- package/dist/chunks/app-navigation-uwbNEw9P.js +0 -262
- package/dist/chunks/app-navigation-uwbNEw9P.js.map +0 -1
- package/dist/chunks/approval-instance-list-page-Mo6wpDPb.cjs +0 -2
- package/dist/chunks/approval-instance-list-page-Mo6wpDPb.cjs.map +0 -1
- package/dist/chunks/approval-instance-list-page-nmzMrj0b.js.map +0 -1
- package/dist/chunks/builder-DPhAH381.cjs +0 -3
- package/dist/chunks/builder-DPhAH381.cjs.map +0 -1
- package/dist/chunks/builder-DqZskyXC.js.map +0 -1
- package/dist/chunks/categories-DEijUOnw.cjs +0 -2
- package/dist/chunks/categories-DEijUOnw.cjs.map +0 -1
- package/dist/chunks/categories-DTEl182t.js.map +0 -1
- package/dist/chunks/dashboard-page-DCmuB0Rw.cjs +0 -2
- package/dist/chunks/dashboard-page-DCmuB0Rw.cjs.map +0 -1
- package/dist/chunks/dashboard-page-Dx5PeEeN.js +0 -117
- package/dist/chunks/dashboard-page-Dx5PeEeN.js.map +0 -1
- package/dist/chunks/delegations-C-ZrwzvU.js.map +0 -1
- package/dist/chunks/delegations-C5PzZ5Kn.js.map +0 -1
- package/dist/chunks/delegations-DOGDvybX.cjs +0 -2
- package/dist/chunks/delegations-DOGDvybX.cjs.map +0 -1
- package/dist/chunks/delegations-DkDBWOQ7.cjs +0 -2
- package/dist/chunks/delegations-DkDBWOQ7.cjs.map +0 -1
- package/dist/chunks/detail-B2gcOPkd.cjs +0 -2
- package/dist/chunks/detail-B2gcOPkd.cjs.map +0 -1
- package/dist/chunks/detail-CfFyU5zC.js.map +0 -1
- package/dist/chunks/notifications-CPQ-nVar.cjs +0 -2
- package/dist/chunks/notifications-CPQ-nVar.cjs.map +0 -1
- package/dist/chunks/notifications-DweexUVy.js +0 -197
- package/dist/chunks/notifications-DweexUVy.js.map +0 -1
- package/dist/chunks/orgs-DgZ0DQ3-.cjs +0 -2
- package/dist/chunks/orgs-DgZ0DQ3-.cjs.map +0 -1
- package/dist/chunks/orgs-xrdhb3hS.js.map +0 -1
- package/dist/chunks/templates-PK_VYvcy.js +0 -383
- package/dist/chunks/templates-PK_VYvcy.js.map +0 -1
- package/dist/chunks/templates-x1OJZmsG.cjs +0 -2
- package/dist/chunks/templates-x1OJZmsG.cjs.map +0 -1
- package/dist/chunks/users-CY4-NK3j.js.map +0 -1
- package/dist/chunks/users-DHnu_056.cjs +0 -2
- package/dist/chunks/users-DHnu_056.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/notifications-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/notifications-BaYDebFt.cjs");exports.SettingsNotificationsView=e.t;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../../../chunks/notifications-
|
|
1
|
+
import { t as e } from "../../../chunks/notifications-2swRqDPF.js";
|
|
2
2
|
export { e as SettingsNotificationsView };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/categories-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/categories-5yEM3p3N.cjs");exports.TemplateCategoriesView=e.t;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../../../chunks/categories-
|
|
1
|
+
import { t as e } from "../../../chunks/categories-BIpOG451.js";
|
|
2
2
|
export { e as TemplateCategoriesView };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/app-navigation-
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../../chunks/app-navigation-KnlJCUp1.cjs"),t=require("../../../chunks/auth-provider-BV8Iiwfb.cjs"),n=require("../../../chunks/routes-config-2aKbWq2H.cjs"),r=require("../../../chunks/admin-pickers-Btvij1at.cjs"),i=require("../../../chunks/bpm-form-field-Bc6k4ZEO.cjs");let a=require("react"),o=require("@mezzanine-ui/react"),s=require("react/jsx-runtime"),c=require("@mezzanine-ui/icons"),l=require("@mezzanine-ui/react/ContentHeader");l=e.o(l,1);let ee=require("@rytass/bpm-core-client/organization"),u=require("@xyflow/react"),d=require("dagre");d=e.o(d,1);let f=require("@rytass/bpm-core-client/template");var te={display:`grid`,gap:16},ne={alignItems:`start`,display:`grid`,gap:16,gridTemplateColumns:`minmax(0, 1fr) 420px`},re={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,height:620,minWidth:0,overflow:`hidden`},ie={alignItems:`center`,boxSizing:`border-box`,color:`var(--mzn-color-text-error)`,display:`flex`,height:26,justifyContent:`center`,lineHeight:0,padding:0,width:26},ae={alignItems:`center`,display:`flex`,height:`100%`,justifyContent:`center`,width:`100%`},p=`workflow-designer-side-panel`,oe=96,se=`
|
|
2
2
|
.${p} .mzn-form-field--stretch .mzn-form-field__label-area,
|
|
3
3
|
.${p} .mzn-form-field--horizontal .mzn-form-field__label-area {
|
|
4
|
-
flex: 0 0 ${
|
|
5
|
-
width: ${
|
|
4
|
+
flex: 0 0 ${oe}px;
|
|
5
|
+
width: ${oe}px;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.${p} .mzn-form-field--stretch .mzn-form-field__data-entry,
|
|
9
9
|
.${p} .mzn-form-field--horizontal .mzn-form-field__data-entry {
|
|
10
10
|
min-width: 0;
|
|
11
11
|
}
|
|
12
|
-
`,
|
|
12
|
+
`,ce=`#2563eb`,m=`#64748b`,le=`var(--mzn-color-text-error, #dc2626)`,ue=`drop-shadow(0 0 3px rgba(0, 87, 255, 0.85)) drop-shadow(0 0 9px rgba(0, 87, 255, 0.36))`,de=`
|
|
13
13
|
.workflow-selection-delete-control.react-flow__controls-button {
|
|
14
14
|
align-items: center !important;
|
|
15
15
|
display: flex !important;
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
.workflow-edge--selected .react-flow__edge-path,
|
|
36
36
|
.react-flow__edge-path.workflow-edge--selected {
|
|
37
|
-
filter: ${
|
|
37
|
+
filter: ${ue};
|
|
38
38
|
opacity: 1 !important;
|
|
39
39
|
stroke: ${m} !important;
|
|
40
40
|
stroke-opacity: 1 !important;
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
--xy-edge-stroke-width: 1.5px;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
`,de={display:`grid`,gap:12},h={display:`grid`,gap:12},fe={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`},me={display:`flex`,flexWrap:`wrap`,gap:8},he={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%`},ge=`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)`,_=64,v=160,_e=20,ve=64,y=180,ye={...g,display:`grid`,gap:8,padding:`10px 12px`},b={...ye,background:`#eff6ff`,border:`1px solid #2563eb`},be={...ye,background:`#f0fdfa`,border:`1px solid #0f766e`},xe={...g,background:`#ffffff`},Se={...g,background:`#ecfdf3`,border:`1px solid #2f855a`},Ce={...g,background:`#fff4ed`,border:`1px solid #c2410c`},x={display:`block`,maxWidth:`100%`,minWidth:0},S={display:`grid`,gap:2,minWidth:0},C=`input`,w=`output`,we={endEvent:`結束`,exclusiveGateway:`條件分流`,parallelGateway:`並行處理`,serviceTask:`系統`,startEvent:`開始`,userTask:`簽核`},Te=[{icon:s.UserIcon,label:`簽核節點`,type:`userTask`},{icon:s.MailIcon,label:`知會節點`,type:`serviceTask`}],Ee=[{icon:s.FilterIcon,label:`條件分流`,type:`exclusiveGateway`}],De=[{id:`AND`,name:`全部前置完成`},{id:`OR`,name:`任一前置完成`}],Oe=[{id:`RESTART`,name:`重新送出後從開始重跑`},{id:`FROM_RETURN_POINT`,name:`重新送出後回到退回節點`}],ke=[{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:`指定職位`}],T=[{id:`1`,name:`直屬主管`,value:1},{id:`2`,name:`第二層主管`,value:2},{id:`3`,name:`第三層主管`,value:3}],Ae=[{id:`NONE`,name:`停止流程並提示`},{id:`DIRECT`,name:`固定改派`}],E=[{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:`未填寫`}],je=[`EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`NOT_EQUALS`],Me=[{id:`NONE`,name:`未設定`},{id:`ALL`,name:`所有人`},{id:`ORG_UNIT`,name:`指定組織`},{id:`ORG_UNIT_POSITION`,name:`指定組織職位`}],Ne={id:`CUSTOM`,name:`既有自訂規則`},Pe=`member-001`,Fe={endEvent:O,exclusiveGateway:O,parallelGateway:O,serviceTask:O,startEvent:O,userTask:O};function D({templateId:d,activeHref:ae=`/templates`}){let se=t.a(),[m,le]=(0,i.useState)(null),[g,ge]=(0,i.useState)(null),[_,v]=(0,i.useState)(et()),[_e,ve]=(0,i.useState)(``),[y,ye]=(0,i.useState)(null),[b,be]=(0,i.useState)(null),[xe,Se]=(0,i.useState)(null),[Ce,x]=(0,i.useState)(null),[S,C]=(0,i.useState)(`start`),[w,E]=(0,i.useState)([]),[je,D]=(0,i.useState)(null),[O,k]=(0,i.useState)(null),[Le,Re]=(0,i.useState)(!0),[ze,A]=(0,i.useState)(!1),[Ve,He]=(0,i.useState)(!1),[j,qe]=(0,i.useState)([]),Je=(0,i.useMemo)(()=>JSON.stringify({formDefinitionVersionId:y,initiatorPolicyCel:b,workflowDefinition:_}),[y,b,_]),M=!!_e&&Je!==_e,[Qe,$e]=(0,i.useState)(!1),[F,I]=(0,i.useState)([]),[L,R]=(0,i.useState)([]),[z,yt]=(0,i.useState)([]),[Ct,Tt]=(0,i.useState)([]),[V,H]=(0,i.useState)(!1),[Ft,It]=(0,i.useState)(!1),[Lt,Rt]=(0,i.useState)(`{}`),[U,Ht]=(0,i.useState)(null),[Ut,Wt]=(0,i.useState)(null),[Gt,Kt]=(0,i.useState)(void 0),W=(0,i.useRef)(null);(0,i.useEffect)(()=>{xn()},[d]),(0,i.useEffect)(()=>{function e(e){M&&(e.preventDefault(),e.returnValue=``)}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[M]),(0,i.useEffect)(()=>{Cn(_)},[_,F]),(0,i.useEffect)(()=>{v(e=>Ke(e))},[_.edges,_.nodes]);function en(){M&&!window.confirm(`目前有尚未儲存的流程草稿,確定要離開嗎?`)||se.push(`/templates`)}let G=(0,i.useMemo)(()=>_.nodes.find(e=>e.id===S)??null,[S,_.nodes]),sn=G?vt(G):!1,cn=w.length>0||sn,un=(0,i.useCallback)(()=>{let e=G&&vt(G)?G.id:null;v(t=>({...t,edges:t.edges.filter(t=>!w.includes(t.id)&&t.source!==e&&t.target!==e),nodes:e?t.nodes.filter(t=>t.id!==e):t.nodes})),E([]),D(null),e&&C(`start`)},[w,G]);(0,i.useEffect)(()=>{if(!cn)return;function e(e){e.key!==`Delete`&&e.key!==`Backspace`||bt(e.target)||(e.preventDefault(),un())}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[cn,un]);let dn=(0,i.useMemo)(()=>_.edges.find(e=>e.id===je)??null,[je,_.edges]),fn=(0,i.useMemo)(()=>w.length===1?_.edges.find(e=>e.id===w[0])??null:null,[w,_.edges]),mn=(0,i.useMemo)(()=>w.map(e=>_.edges.find(t=>t.id===e)??null).filter(e=>!!e),[w,_.edges]),q=(0,i.useMemo)(()=>Ce??ft(b,xe),[b,Ce,xe]),gn=(0,i.useMemo)(()=>_.nodes.map(e=>Be(e,F,L,z,e.id===S,q)),[q,F,L,z,S,_.nodes]),_n=(0,i.useMemo)(()=>_.edges.map(e=>Ue(e,_.nodes,w.includes(e.id))),[w,_.edges,_.nodes]),Y=(0,i.useMemo)(()=>P(j,y)??P(xt(m?.formVersions??[]),y),[y,j,m?.formVersions]),vn=(0,i.useMemo)(()=>Ot(j,Y),[j,Y]),yn=(0,i.useMemo)(()=>Jt(_),[_]),X=(0,i.useMemo)(()=>Yt(_),[_]),bn=(0,i.useMemo)(()=>pt(q),[q]);async function xn(){Re(!0),k(null);try{let[e,t]=await Promise.all([(0,f.readTemplateDesigner)(d),(0,l.readOrganizationDashboard)()]),n=e.versions.find(e=>e.status===`DRAFT`)??null,r=n??e.versions[0]??null;le(e),ge(n),R(t.orgUnits),yt(t.positions),Tt(t.memberships),qe(xt(e.formVersions));let i=r?.workflowDefinition??et(),a=r?.formDefinitionVersionId??e.formVersions[0]?.id??null,o=r?.initiatorPolicyCel??null;v(i),ye(a),be(o),ve(JSON.stringify({formDefinitionVersionId:a,initiatorPolicyCel:o,workflowDefinition:i})),Se(r&&!e.template.currentVersionId&&!r.initiatorPolicyCel&&tt(r.workflowDefinition)?`NONE`:null),x(null),C(r?.workflowDefinition.nodes[0]?.id??`start`),E([]),D(null)}catch(e){k(J(e))}finally{Re(!1)}}async function Sn(e){He(!0),k(null);try{qe(Ot(xt(await(0,f.searchPublishedFormVersionOptions)(e)),Y))}catch(e){k(J(e))}finally{He(!1)}}async function Z(e){$e(!0),k(null);try{let t=await(0,f.searchMemberOptions)(e);I(e=>Bt(e,kt(t)))}catch(e){k(J(e))}finally{$e(!1)}}async function Cn(e){let t=Vt(e).filter(e=>!F.some(t=>t.memberId===e));if(t.length!==0)try{let e=await(0,f.resolveMemberOptions)(t);I(t=>Bt(t,kt(e)))}catch{I(e=>Bt(e,t.map(At)))}}async function wn(){A(!0),k(null);try{let e=Jt(_),t=pt(q);if(e||t){let n=e??t??`流程設定未完成`;throw k(n),Error(n)}let n=await(0,f.updateApprovalTemplateDraft)({formDefinitionVersionId:y,initiatorPolicyCel:b,versionId:(g??await(0,f.forkApprovalTemplate)(d)).id,workflowDefinition:_});return ge(n),await xn(),n}catch(e){throw k(J(e)),e}finally{A(!1)}}async function Tn(){A(!0),k(null);try{await(0,f.publishApprovalTemplateVersion)((await wn()).id),await xn()}catch(e){k(J(e))}finally{A(!1)}}function En(){Rt(JSON.stringify(St(Y),null,2)),Ht(null),Wt(null),H(!0)}function Dn(){Ft||H(!1)}async function On(){It(!0),Wt(null),Ht(null);try{Ht(await(0,f.dryRunApprovalWorkflow)({formData:wt(Lt),initiatorMemberId:Pe,initiatorMetadataSnapshot:Pt(Pe,Ct),workflowDefinition:_}))}catch(e){Wt(J(e))}finally{It(!1)}}function kn(e){let t=(0,u.applyNodeChanges)(e,gn);v(e=>({...e,nodes:e.nodes.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,position:n.position}:e})}))}function An(e){if(!gt(e,_.nodes))return;let t=_.nodes.some(t=>t.id===e.source&&t.type===`exclusiveGateway`),n=N(e.source,e.target,{});v(e=>({...e,edges:[...e.edges,n]})),C(null),E([n.id]),D(t?n.id:null)}function jn(e,t){e.stopPropagation(),E(n=>e.shiftKey||e.metaKey||e.ctrlKey?_t(n,t.id):[t.id]),C(null)}function Mn(){D(null)}function Nn(e){let t=Ze({definition:_,node:Ye(e,Xe(_.nodes,e)),selectedEdgeId:w.length===1?w[0]:null,selectedNodeId:S}),n=nt(t.definition),r=qt(n,W.current);v(n),C(t.selectedNodeId),E(t.selectedEdgeIds),D(t.editingEdgeId),r&&Kt(r)}function Pn(e){G&&$(G.id,t=>We(t,e))}function Q(e){!G||G.type!==`userTask`||$(G.id,t=>t.type===`userTask`?{...t,data:{...t.data,approverResolver:e,decisionPolicy:{type:`SINGLE`}}}:t)}function Fn(e){!G||G.type!==`userTask`||$(G.id,t=>t.type===`userTask`?{...t,data:{...t.data,returnBehavior:{...t.data.returnBehavior,resubmitStrategy:e}}}:t)}function In(e){!G||G.type!==`serviceTask`||$(G.id,t=>t.type===`serviceTask`?{...t,data:{...t.data,action:e}}:t)}function Ln(e){x(e.mode===`ALL`||e.mode===`CUSTOM`?null:e),Se(e.mode===`ALL`||e.mode===`CUSTOM`?null:e.mode),be(mt(e,L))}function Rn(e){!G||G.type===`startEvent`||$(G.id,t=>Ge(t,e))}function $(e,t){v(n=>({...n,nodes:n.nodes.map(n=>n.id===e?t(n):n)}))}function zn(e,t){v(n=>({...n,edges:n.edges.map(n=>n.id===e?t(n):n)}))}function Bn(e,t){v(n=>{let r=n.edges.find(t=>t.id===e);return r?{...n,edges:n.edges.map(e=>t&&e.source===r.source&&e.id!==r.id&&K(e,n.nodes)?{...e,data:{...e.data,isDefault:!1}}:e.id===r.id?{...e,data:{...e.data,isDefault:t}}:e)}:n})}function Vn({edgeId:e,fieldKey:t,operator:n,value:r}){let i=Y?.schema??null;zn(e,e=>{let a=Zt(i,t??e.data.conditionFieldKey??null),o=nn(a,n??e.data.conditionOperator??null),s=rn(a,o,r??e.data.conditionValue??null),c=on(a,o,s);return{...e,data:{...e.data,condition:ln(a,o,s),conditionFieldKey:a?.fieldKey,conditionOperator:o,conditionValue:s,isDefault:!1,label:c}}})}function Hn(){let e=nt(_),t=qt(e,W.current);v(e),t&&Kt(t)}return(0,o.jsxs)(e.t,{activeHref:ae,children:[(0,o.jsx)(`style`,{children:oe}),(0,o.jsx)(a.PageHeader,{children:(0,o.jsxs)(c.default,{description:`${g?`草稿 v${g.version}`:`尚未建立草稿`} ·${m?.template.currentVersionId?` 已發布版本`:` 尚未發布`}`,onBackClick:en,title:m?.template.name??`流程設計器`,children:[(0,o.jsx)(a.Button,{"aria-label":`儲存草稿`,disabled:ze||!!yn||!!bn,icon:s.SaveIcon,iconType:`icon-only`,onClick:()=>void wn(),variant:`base-secondary`,children:`儲存草稿`}),(0,o.jsx)(a.Button,{disabled:Le||!!yn||!!bn,icon:s.EyeIcon,iconType:`leading`,onClick:En,variant:`base-secondary`,children:`試跑流程`}),(0,o.jsx)(a.Button,{disabled:ze||!g||!!yn||!!bn,icon:s.CheckedIcon,iconType:`leading`,onClick:()=>void Tn(),variant:`base-primary`,children:`發布版本`})]})}),(0,o.jsx)(a.SectionGroup,{children:(0,o.jsx)(a.Section,{children:(0,o.jsxs)(`div`,{style:ee,children:[O?(0,o.jsx)(a.Typography,{color:`text-error`,variant:`body`,children:O}):null,yn?(0,o.jsx)(a.Typography,{color:`text-error`,variant:`body`,children:yn}):null,bn?(0,o.jsx)(a.Typography,{color:`text-error`,variant:`body`,children:bn}):null,(0,o.jsx)(`div`,{style:h,children:(0,o.jsx)(r.t,{hintText:X?`已設定條件分流條件。請先移除所有條件,才能更換綁定表單版本。`:void 0,label:`綁定表單版本`,name:`formDefinitionVersionId`,required:!0,children:(0,o.jsx)(a.AutoComplete,{asyncData:!0,disabled:Le||X,disabledOptionsFilter:!0,emptyText:`沒有符合的已發布表單版本`,isForceClearable:!!y&&!X,loading:Ve,loadingText:`搜尋表單版本中...`,mode:`single`,onChange:e=>{X||ye(e?.id??null)},onClear:()=>{X||ye(null)},onSearch:Sn,onVisibilityChange:e=>{e&&!X&&Sn(``)},options:[...vn],placeholder:`選擇已發布表單版本`,searchDebounceTime:300,value:Y})})}),(0,o.jsxs)(`div`,{style:te,children:[(0,o.jsx)(`div`,{ref:W,style:ne,children:(0,o.jsxs)(u.ReactFlow,{connectionMode:u.ConnectionMode.Strict,edges:_n,fitView:!0,isValidConnection:e=>gt(e,_.nodes),nodeTypes:Fe,nodes:gn,deleteKeyCode:null,multiSelectionKeyCode:[`Shift`,`Meta`,`Control`],onConnect:An,onEdgeClick:jn,onNodeClick:(e,t)=>{C(t.id),E([])},onNodesChange:kn,onPaneClick:()=>{C(null),E([])},onViewportChange:Kt,viewport:Gt,children:[(0,o.jsx)(u.Background,{}),(0,o.jsx)(`style`,{children:ue}),(0,o.jsx)(u.Controls,{children:cn?(0,o.jsx)(u.ControlButton,{"aria-label":`刪除選取項目`,className:`workflow-selection-delete-control`,onClick:un,style:re,title:`刪除選取項目`,children:(0,o.jsx)(`span`,{style:ie,children:(0,o.jsx)(a.Icon,{color:`error`,icon:s.TrashIcon,size:16})})}):null}),(0,o.jsx)(Ie,{onApplyAutoLayout:Hn}),(0,o.jsx)(u.MiniMap,{})]})}),(0,o.jsxs)(`div`,{className:p,style:de,children:[(0,o.jsx)(a.Typography,{component:`h2`,variant:`h3`,children:`流程工具`}),(0,o.jsxs)(`div`,{style:he,children:[(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`caption`,children:`動作節點`}),(0,o.jsx)(`div`,{style:me,children:Te.map(e=>(0,o.jsx)(a.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Nn(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,o.jsxs)(`div`,{style:he,children:[(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`caption`,children:`流程控制`}),(0,o.jsx)(`div`,{style:me,children:Ee.map(e=>(0,o.jsx)(a.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Nn(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),mn.length>1?Yn(mn):null,mn.length===1&&fn?Xn(fn):null,mn.length===0&&G?Wn(G):null]})]})]})})}),Zn(dn),Un()]});function Un(){return(0,o.jsx)(a.Modal,{cancelText:`關閉`,confirmText:`執行試跑`,loading:Ft,modalType:`standard`,onCancel:Dn,onClose:Dn,onConfirm:()=>void On(),open:V,showModalFooter:!0,showModalHeader:!0,size:`wide`,supportingText:`使用 ${Pe} 與範例表單資料模擬目前畫布流程,不會建立案件。`,title:`試跑流程`,children:(0,o.jsxs)(`div`,{style:h,children:[(0,o.jsx)(r.t,{label:`表單資料 JSON`,name:`dryRunFormDataJson`,required:!0,children:(0,o.jsx)(a.Textarea,{onChange:e=>Rt(e.target.value),resize:`vertical`,rows:8,value:Lt})}),Ut?(0,o.jsx)(a.Typography,{color:`text-error`,variant:`body`,children:Ut}):null,U?(0,o.jsxs)(`div`,{style:fe,children:[(0,o.jsx)(a.Typography,{color:U.valid?`text-success`:`text-error`,variant:`label-primary-highlight`,children:U.valid?`試跑通過`:`試跑失敗`}),U.errors.map(e=>(0,o.jsx)(a.Typography,{color:`text-error`,variant:`body`,children:e},e)),U.steps.map(e=>(0,o.jsxs)(`div`,{style:pe,children:[(0,o.jsxs)(a.Typography,{variant:`label-primary-highlight`,children:[e.nodeLabel,` · `,Et(e.status)]}),(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`caption`,children:[Dt(e.nodeType),e.assigneeMemberId?` · 處理者:${e.assigneeMemberId}`:``,e.edgeLabel?` · 來源線段:${e.edgeLabel}`:``]}),e.edgeReason?(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`caption`,children:e.edgeReason}):null,e.entryCondition?(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`caption`,children:[`進入條件:`,e.entryConditionMatched?`符合`:`不符合`,` ·`,` `,e.entryCondition]}):null,(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`body`,children:e.message})]},e.id))]}):null]})})}function Wn(e){return(0,o.jsxs)(`div`,{style:h,children:[(0,o.jsx)(a.Typography,{component:`h2`,variant:`h3`,children:`節點屬性`}),(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`body`,children:[we[e.type],` · `,e.id]}),(0,o.jsx)(r.t,{label:`顯示名稱`,name:`nodeLabel`,required:!0,children:(0,o.jsx)(a.Input,{onChange:e=>Pn(e.target.value),value:e.data.label,variant:`base`})}),e.type===`startEvent`?Gn():null,e.type===`startEvent`?null:Kn(e),e.type===`userTask`?qn(e):null,e.type===`serviceTask`?Jn(e):null]})}function Gn(){let e=q.mode===`CUSTOM`?[...Me,Ne]:[...Me],t=q.mode===`ORG_UNIT`||q.mode===`ORG_UNIT_POSITION`?Mt(L,q.orgUnitId??``):null,i=q.mode===`ORG_UNIT_POSITION`?Nt(z,q.positionId??``):null,s=q.mode===`ORG_UNIT_POSITION`?zt({includeDescendants:!!q.includeDescendants,memberships:Ct,orgUnitId:q.orgUnitId??``,orgUnits:L,positions:z}):[];return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.t,{hintText:q.mode===`CUSTOM`?`這是舊版表達式規則;切換成標準選項後會改由 UI 管理。`:void 0,label:`發起權限`,name:`initiatorPolicyMode`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>{if(e?.id===`CUSTOM`){Se(null),x(null);return}let t=dt(e?.id??null),n=ht(t);Se(t===`ALL`?null:t),x(t===`ALL`?null:n),be(mt(n,L))},options:e,placeholder:`選擇誰可以發起`,value:P(e,q.mode)})}),q.mode===`ORG_UNIT`||q.mode===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{label:`組織`,name:`initiatorOrgUnitId`,required:!0,children:(0,o.jsx)(n.n,{name:`initiatorOrgUnitId`,onChange:e=>Ln({...q,orgUnitId:e?.id??``,positionId:``,value:e?.id??``}),orgUnits:L,placeholder:`選擇組織`,value:t})}):null,q.mode===`ORG_UNIT`||q.mode===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{label:`包含下層`,name:`initiatorIncludeDescendants`,children:(0,o.jsx)(a.Toggle,{checked:!!q.includeDescendants,onChange:e=>Ln({...q,includeDescendants:e.target.checked,...q.mode===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,q.mode===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{label:`職位`,name:`initiatorPositionId`,required:!0,children:(0,o.jsx)(n.r,{disabled:!q.orgUnitId?.trim(),name:`initiatorPositionId`,onChange:e=>Ln({...q,positionId:e?.id??``}),placeholder:q.orgUnitId?.trim()?`選擇職位`:`請先選擇組織`,positions:s,value:i})}):null]})}function Kn(e){let t=_.edges.filter(t=>t.target===e.id).length,n=t<2,i=n?`AND`:e.data.triggerMode??`AND`;return(0,o.jsx)(r.t,{hintText:n?`需要至少兩條前置連線,才可切換為任一前置完成。`:t>1?`${t} 條前置連線會依此規則觸發。`:`只有一條前置連線時,兩種設定效果相同。`,label:`前置條件`,name:`triggerMode`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>n?void 0:Rn(rt(e?.id??null)),options:[...De],readOnly:n,value:P(De,i)})})}function qn(e){let t=e.data.approverResolver,i=at(t.type),s=t.type===`DIRECT`?jt(t.memberIds,F):null,c=t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?Mt(L,t.orgUnitId):null,l=t.type===`POSITION`||t.type===`ORG_UNIT_POSITION`?Nt(z,t.positionId):null,u=t.type===`ORG_UNIT_POSITION`?zt({includeDescendants:!!t.includeDescendants,memberships:Ct,orgUnitId:t.orgUnitId,orgUnits:L,positions:z}):[],d=t.type===`ORG_MANAGER`?lt(t.levelsUp):T[0],f=t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?t.fallback??{type:`NONE`}:{type:`NONE`},ee=f.type===`DIRECT`?B(F,f.memberId):null,te=e.data.returnBehavior.resubmitStrategy??`RESTART`;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.t,{label:`簽核來源`,name:`approverResolverType`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>Q(ot(e?.id??null)),options:[...ke],value:P(ke,i)})}),t.type===`DIRECT`?(0,o.jsx)(r.t,{label:`簽核者`,name:`memberId`,required:!0,children:(0,o.jsx)(a.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-search`,spellCheck:!1},loading:Qe,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:s})}):null,t.type===`ORG_MANAGER`?(0,o.jsx)(r.t,{hintText:`依發起人的有效會員歸屬與主管解析規則決定簽核人。`,label:`主管層級`,name:`managerLevelsUp`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>Q({baseFromInitiator:!0,levelsUp:ut(e?.id??null).value,type:`ORG_MANAGER`}),options:[...T],value:d})}):null,t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{hintText:t.type===`ORG_UNIT_MANAGER`?`依指定組織或其上層的主管解析規則決定簽核人。`:`依指定組織目前有效會員歸屬建立候選簽核人。`,label:`組織`,name:`orgUnitId`,required:!0,children:(0,o.jsx)(n.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:c})}):null,t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.t,{hintText:`預設會停止流程並提示;若設定固定人,找不到主管時會改派給該會員。`,label:`無主管時`,name:`approverFallbackMode`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>Q(ct(t,st(e?.id??null)===`DIRECT`?{memberId:``,type:`DIRECT`}:{type:`NONE`})),options:[...Ae],value:P(Ae,f.type)})}),f.type===`DIRECT`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.t,{label:`改派人員`,name:`approverFallbackMemberId`,required:!0,children:(0,o.jsx)(a.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-fallback-search`,spellCheck:!1},loading:Qe,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>Q(ct(t,{allowInitiatorSelfApproval:f.allowInitiatorSelfApproval,memberId:e?.id??``,type:`DIRECT`})),onSearch:Z,onVisibilityChange:e=>{e&&Z(``)},options:[...F],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:ee})}),(0,o.jsx)(r.t,{hintText:`預設禁止申請人簽自己的案件;只有此流程允許自簽時才開啟。`,label:`允許自簽`,name:`allowInitiatorSelfApproval`,children:(0,o.jsx)(a.Toggle,{checked:!!f.allowInitiatorSelfApproval,onChange:e=>Q(ct(t,{allowInitiatorSelfApproval:e.target.checked,memberId:f.memberId,type:`DIRECT`}))})})]}):null]}):null,t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{label:`包含下層`,name:`includeDescendants`,children:(0,o.jsx)(a.Toggle,{checked:!!t.includeDescendants,onChange:e=>Q({...t,includeDescendants:e.target.checked,...t.type===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,t.type===`POSITION`?(0,o.jsx)(r.t,{hintText:`指派給目前有效歸屬中擁有此職位的會員;主要歸屬優先。`,label:`職位`,name:`positionId`,required:!0,children:(0,o.jsx)(n.r,{name:`positionId`,onChange:e=>Q({positionId:e?.id??``,type:`POSITION`}),placeholder:`選擇職位`,positions:z,value:l})}):null,t.type===`ORG_UNIT_POSITION`?(0,o.jsx)(r.t,{hintText:`只納入指定組織範圍內擁有此職位的有效會員。`,label:`職位`,name:`orgUnitPositionId`,required:!0,children:(0,o.jsx)(n.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,o.jsx)(r.t,{hintText:`退回發起人後,重新送出時要從流程開始重跑,或直接回到退回的簽核節點。`,label:`重送策略`,name:`returnResubmitStrategy`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:e=>Fn(it(e?.id??null)),options:[...Oe],value:P(Oe,te)})}):null]})}function Jn(e){let t=hn(e.data.action).map(e=>B(F,e));return(0,o.jsx)(r.t,{label:`知會對象`,name:`notifyMemberIds`,required:!0,children:(0,o.jsx)(a.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,loading:Qe,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>In({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 Yn(e){return(0,o.jsxs)(`div`,{style:h,children:[(0,o.jsx)(a.Typography,{component:`h2`,variant:`h3`,children:`已選取線段`}),(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`body`,children:[`已選取 `,e.length,` 條線段,可使用 Delete 或控制面板刪除。`]})]})}function Xn(e){let t=K(e,_.nodes);return(0,o.jsxs)(`div`,{style:h,children:[(0,o.jsx)(a.Typography,{component:`h2`,variant:`h3`,children:t?`條件設定`:`線段屬性`}),(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`body`,children:[e.source,` → `,e.target]}),t?Qn(e):(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`body`,children:`這條線會直接把流程送到下一個節點。`})]})}function Zn(e){return!e||!K(e,_.nodes)?null:(0,o.jsx)(a.Modal,{cancelText:`取消`,confirmButtonProps:{disabled:!e.data.isDefault&&!e.data.condition},confirmText:`完成`,modalType:`standard`,onCancel:Mn,onClose:Mn,onConfirm:Mn,open:!!je,showModalFooter:!0,showModalHeader:!0,size:`regular`,supportingText:`條件分流的輸出連線需要指定條件,條件會直接顯示在線上。`,title:`條件設定`,children:Qn(e)})}function Qn(e){let t=pn(e,_.nodes),n=Xt(Y?.schema??null),i=Zt(Y?.schema??null,e.data.conditionFieldKey??null),s=Qt(i),c=tn(i),l=P(s,e.data.conditionOperator??null);return(0,o.jsxs)(`div`,{style:h,children:[(0,o.jsxs)(a.Typography,{color:`text-neutral`,variant:`body`,children:[`畫布上的這條線目前會顯示「`,(0,o.jsx)(`span`,{style:{color:!e.data.isDefault&&!e.data.condition?ce:void 0},children:t??`請設定條件`}),`」。`]}),(0,o.jsx)(a.Toggle,{checked:!!e.data.isDefault,label:`其他情況走這條`,onChange:t=>Bn(e.id,t.target.checked)}),e.data.isDefault?(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`body`,children:`其他條件都不符合時,流程會走這條線。`}):(0,o.jsxs)(o.Fragment,{children:[Y?null:(0,o.jsx)(a.Typography,{color:`text-neutral`,variant:`body`,children:`請先綁定表單版本,才能選擇條件欄位。`}),(0,o.jsx)(r.t,{label:`條件欄位`,name:`edgeConditionField`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:t=>Vn({edgeId:e.id,fieldKey:t?.id??null,operator:null,value:null}),options:[...n],placeholder:`選擇條件欄位`,value:P(n,e.data.conditionFieldKey??null)})}),(0,o.jsx)(r.t,{label:`條件判斷`,name:`edgeConditionOperator`,required:!0,children:(0,o.jsx)(a.Select,{clearable:!1,onChange:t=>Vn({edgeId:e.id,operator:$t(t?.id??null),value:null}),options:[...s],placeholder:`選擇判斷方式`,value:l})}),l&&an(l.id)?(0,o.jsx)(r.t,{label:`條件值`,name:`edgeConditionValue`,required:!0,children:c.length>0?(0,o.jsx)(a.Select,{clearable:!1,onChange:t=>Vn({edgeId:e.id,value:t?.id??null}),options:[...c],placeholder:`選擇條件值`,value:P(c,e.data.conditionValue??null)}):(0,o.jsx)(a.Input,{onChange:t=>Vn({edgeId:e.id,value:t.target.value}),placeholder:`輸入要比對的值`,value:e.data.conditionValue??``,variant:`base`})}):null]})]})}}function Ie({onApplyAutoLayout:e}){function t(){e()}return(0,o.jsx)(u.Panel,{position:`top-right`,children:(0,o.jsx)(a.Button,{icon:s.DotGridIcon,iconType:`leading`,onClick:t,size:`sub`,variant:`base-secondary`,children:`自動排版`})})}function O({data:e,selected:t,type:n}){let r=e.approverLines??[e.approverSummary??e.label],i=k(e);return(0,o.jsxs)(`div`,{style:Le(n,t),children:[ze(e),(0,o.jsx)(`div`,{style:S,children:r.map((e,t)=>(0,o.jsx)(a.Typography,{component:`span`,ellipsis:!0,style:x,title:e,variant:`label-primary`,children:e},`${e}_${t}`))}),(0,o.jsx)(a.Typography,{color:`text-neutral`,component:`span`,ellipsis:!0,style:x,title:i,variant:`caption`,children:i})]})}function k(e){return e.nodeKind===`startEvent`?e.initiatorPolicySummary??`所有人`:e.approverSummary||e.approverLines?e.label:e.nodeKind===`exclusiveGateway`?`條件在線上`:e.nodeKind===`parallelGateway`?`多條路徑同時進行`:we[e.nodeKind]}function Le(e,t){let n=Re(e);return t?{...n,border:`1px solid var(--mzn-color-primary, #0057ff)`,boxShadow:ge}:n}function Re(e){return e===`exclusiveGateway`?b:e===`parallelGateway`?be:e===`startEvent`?Se:e===`endEvent`?Ce:e===`userTask`?xe:g}function ze(e){return!e.hasInput&&e.hasOutput?(0,o.jsx)(u.Handle,{id:w,position:u.Position.Right,type:`source`}):e.hasInput&&!e.hasOutput?(0,o.jsx)(u.Handle,{id:C,position:u.Position.Left,type:`target`}):!e.hasInput&&!e.hasOutput?null:[(0,o.jsx)(u.Handle,{id:C,position:u.Position.Left,type:`target`},`target`),(0,o.jsx)(u.Handle,{id:w,position:u.Position.Right,type:`source`},`source`)]}function Be(e,t,n,r,i,a){let o=A(e);return{data:{approverLines:Wt(e,t),approverSummary:Ht(e,t,n,r),hasInput:R(e),hasOutput:z(e),initiatorPolicySummary:e.type===`startEvent`?L(a,n,r):null,label:e.data.label,nodeKind:e.type},height:o.height,handles:Ve(e),id:e.id,initialHeight:o.height,initialWidth:o.width,position:e.position,selected:i,sourcePosition:u.Position.Right,targetPosition:u.Position.Left,type:e.type,width:o.width}}function A(e){return e.type===`exclusiveGateway`||e.type===`parallelGateway`?{height:ve,width:y}:e.type===`serviceTask`?{height:_+(Math.max(1,hn(e.data.action).length)-1)*_e,width:v}:{height:_,width:v}}function Ve(e){let t=A(e);return[...R(e)?[He(t)]:[],...z(e)?[j(t)]:[]]}function He({height:e}){let t=e/2-9/2;return{height:9,id:C,position:u.Position.Left,type:`target`,width:9,x:-9/2,y:t}}function j({height:e,width:t}){let n=e/2-9/2;return{height:9,id:w,position:u.Position.Right,type:`source`,width:9,x:t-9/2,y:n}}function Ue(e,t,n){let r=pn(e,t),i=K(e,t),a=i&&!e.data.isDefault&&!e.data.condition,o=a?ce:i?se:`#475569`,s=a?`#fef2f2`:i?`#eff6ff`:`#ffffff`,c=a?ce:i?se:m;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?le:void 0,opacity:1,stroke:m,strokeOpacity:1,strokeWidth:1.5},target:e.target,targetHandle:e.targetHandle,type:e.type??`smoothstep`}}function We(e,t){return e.type===`startEvent`||e.type===`endEvent`||e.type===`userTask`||e.type===`serviceTask`||e.type,{...e,data:{...e.data,label:t}}}function Ge(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 Ke(e){return Je(qe(e))}function qe(e){let t=new Set(e.nodes.filter(e=>yt(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 Je(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`?Ge(e,`AND`):e);return n.some((t,n)=>t!==e.nodes[n])?{...e,nodes:n}:e}function Ye(e,t){let n={id:`${e}_${t}`,position:{x:260+t*48,y:120+t*42}};return e===`userTask`?{...n,data:{allowAddSigner:!1,allowReject:!0,allowTransfer:!0,approverResolver:{memberIds:[`member-001`],type:`DIRECT`},decisionPolicy:{type:`SINGLE`},label:`簽核節點 ${t}`,returnBehavior:{allowReturn:!0,allowedTargets:`INITIATOR`,resubmitStrategy:`RESTART`},triggerMode:`AND`},type:e}:e===`serviceTask`?{...n,data:{action:{channels:[`IN_APP`],recipients:{memberIds:[`member-001`],type:`DIRECT`},type:`NOTIFY`},label:`知會節點 ${t}`,triggerMode:`AND`},type:e}:{...n,data:{direction:`split`,label:`條件分流 ${t}`,triggerMode:`AND`},type:e}}function Xe(e,t){let n=new Set(e.filter(e=>e.type===t).map(e=>Number(e.id.replace(`${t}_`,``))).filter(e=>Number.isInteger(e)&&e>0));return Array.from({length:e.length+1},(e,t)=>t+1).find(e=>!n.has(e))??e.length+1}function Ze({definition:e,node:t,selectedEdgeId:n,selectedNodeId:r}){let i=n?e.edges.find(e=>e.id===n)??null:null,a=r?e.nodes.find(e=>e.id===r)??null:null;return i?M(e,t,i):a?Qe(e,t,a):{definition:{...e,nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}function M(e,t,n){if(!R(t))return{definition:e,editingEdgeId:null,selectedEdgeIds:[n.id],selectedNodeId:null};if(!z(t)){let r=N(n.source,t.id,{});return{definition:{...e,edges:[...e.edges,r],nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}let r=N(n.source,t.id,n.data),i=N(t.id,n.target,$e(t,n)),a=K(i,[...e.nodes,t]);return{definition:{...e,edges:e.edges.flatMap(e=>e.id===n.id?[r,i]:[e]),nodes:[...e.nodes,t]},editingEdgeId:a?i.id:null,selectedEdgeIds:a?[i.id]:[],selectedNodeId:a?null:t.id}}function Qe(e,t,n){if(!z(n))return{definition:{...e,nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id};let r=e.edges.find(e=>e.source===n.id)??null;if(r&&z(t))return M(e,t,r);let i=e.nodes.find(e=>e.type===`endEvent`);if(i&&n.id!==i.id&&z(t)){let r=N(n.id,t.id,{}),a=N(t.id,i.id,$e(t,r)),o=K(a,[...e.nodes,t]);return{definition:{...e,edges:[...e.edges,r,a],nodes:[...e.nodes,t]},editingEdgeId:o?a.id:null,selectedEdgeIds:o?[a.id]:[],selectedNodeId:o?null:t.id}}let a=N(n.id,t.id,{});return{definition:{...e,edges:[...e.edges,a],nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}function N(e,t,n){return{data:n,id:`edge_${e}_${t}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,source:e,sourceHandle:w,target:t,targetHandle:C,type:`smoothstep`}}function $e(e,t){return e.type===`exclusiveGateway`?{isDefault:!0,label:`其他情況`}:{}}function et(){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 tt(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 nt(e){let t=new d.graphlib.Graph;return t.setDefaultEdgeLabel(()=>({})),t.setGraph({rankdir:`LR`,ranksep:120}),e.nodes.forEach(e=>{t.setNode(e.id,A(e))}),e.edges.forEach(e=>{t.setEdge(e.source,e.target)}),d.layout(t),{...e,nodes:e.nodes.map(e=>{let n=t.node(e.id);return n?{...e,position:{x:n.x-A(e).width/2,y:n.y-A(e).height/2}}:e})}}function P(e,t){return t?e.find(e=>e.id===t)??null:null}function rt(e){return e===`OR`?`OR`:`AND`}function it(e){return e===`FROM_RETURN_POINT`?`FROM_RETURN_POINT`:`RESTART`}function at(e){return e===`ORG_MANAGER`||e===`ORG_UNIT_MANAGER`||e===`ORG_UNIT_MEMBER`||e===`ORG_UNIT_POSITION`||e===`POSITION`?e:`DIRECT`}function ot(e){let t=at(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 st(e){return e===`DIRECT`?`DIRECT`:`NONE`}function ct(e,t){return e.type===`ORG_MANAGER`||e.type===`ORG_UNIT_MANAGER`?{...e,fallback:t}:e}function lt(e){return T.find(t=>t.value===e)??T[0]}function ut(e){return T.find(t=>t.id===e)??T[0]}function dt(e){return e===`ORG_UNIT`||e===`ORG_UNIT_POSITION`||e===`NONE`?e:`ALL`}function F(e){let t=e?.trim();if(!t)return{mode:`ALL`,value:``};let n=I(t,/"([^"]+)" in subject\.orgUnitIds/gu),r=I(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 ft(e,t){let n=F(e);return!t||t===`ALL`||t===`NONE`?t===`ALL`||t===`NONE`?{mode:t,value:``}:n:n.mode===t?n:ht(t)}function pt(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 I(e,t){return[...e.matchAll(t)].map(e=>e[1]).filter(e=>!!e)}function mt(e,t){if(e.mode===`ALL`||e.mode===`NONE`)return null;let n=e.orgUnitId?.trim()??``;if(!n)return null;let r=U(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 L(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 ht(e){return{includeDescendants:!0,mode:e,orgUnitId:``,positionId:``,value:``}}function gt(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===w&&e.targetHandle===C&&!!(n&&z(n))&&!!(r&&R(r))}function _t(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function vt(e){return e.type!==`startEvent`&&e.type!==`endEvent`}function R(e){return e.type!==`startEvent`}function z(e){return e.type!==`endEvent`&&!yt(e)}function yt(e){return e.type===`serviceTask`&&e.data.action.type===`NOTIFY`}function bt(e){return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||!!e.closest(`[contenteditable="true"]`):!1}function xt(e){return e.map(e=>({id:e.id,name:`${e.formName} | v${e.version}`,schema:e.schema}))}function St(e){return(e?.schema.fields??[]).reduce((e,t)=>({...e,[t.fieldKey]:Ct(t)}),{})}function Ct(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 wt(e){let t=JSON.parse(e);if(!Tt(t))throw Error(`表單資料 JSON 必須是物件。`);return t}function Tt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Et(e){return e===`COMPLETED`?`完成`:e===`PASSED`?`通過`:e===`SKIPPED`?`略過`:e===`STOPPED`?`已停止`:e===`WAITING`?`將等待簽核`:e}function Dt(e){return e in we?we[e]:e}function Ot(e,t){return t&&!e.some(e=>e.id===t.id)?[t,...e]:e}function kt(e){return e.map(e=>({displayName:e.name,email:e.email,id:e.memberId,memberId:e.memberId,name:Kt(e.name,e.email)}))}function At(e){return{displayName:`未知會員`,email:``,id:e,memberId:e,name:`未知會員`}}function B(e,t){return e.find(e=>e.memberId===t)??At(t)}function jt(e,t){let n=e[0];return n?B(t,n):null}function Mt(e,t){let r=e.find(e=>e.id===t);return r?n.a(r):null}function Nt(e,t){let r=e.find(e=>e.id===t);return r?n.o(r):null}function V(e,t){return Mt(e,t)?.name??`未指定組織`}function H(e,t){return Nt(e,t)?.name??`未指定職位`}function Pt(e,t){let n=Ft(),r=t.filter(t=>t.memberId===e&&It(t,n)),i=r.reduce((e,t)=>e&&Lt(e,t)<=0?e:t,null);return{customFields:{},managerMemberId:`member-002`,memberId:e,orgCode:`HQ`,orgUnitIds:Rt(r.map(e=>e.orgUnitId)),positionId:i?.positionId??null,positionIds:Rt(r.map(e=>e.positionId)),primaryOrgUnitId:i?.orgUnitId??null,roles:[`manager`]}}function Ft(){return new Date().toISOString().slice(0,10)}function It(e,t){return e.effectiveFrom<=t&&(!e.effectiveTo||e.effectiveTo>=t)}function Lt(e,t){return e.isPrimary===t.isPrimary?t.effectiveFrom.localeCompare(e.effectiveFrom):e.isPrimary?-1:1}function Rt(e){return e.reduce((e,t)=>t&&!e.includes(t)?[...e,t]:e,[])}function zt({includeDescendants:e,memberships:t,orgUnitId:n,orgUnits:r,positions:i}){let a=new Set(U(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 U(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 Bt(e,t){let n=new Set(e.map(e=>e.memberId)),r=t.filter(e=>!n.has(e.memberId));return[...e,...r]}function Vt(e){return[...new Set(e.nodes.flatMap(e=>e.type===`userTask`?e.data.approverResolver.type===`DIRECT`?e.data.approverResolver.memberIds:[]:e.type===`serviceTask`?hn(e.data.action):[]))]}function Ht(e,t,n,r){return e.type===`userTask`?Ut(e.data.approverResolver,t,n,r):null}function Ut(e,t,n,r){return e.type===`DIRECT`?Gt(e.memberIds,t,`未指定簽核者`):e.type===`ORG_MANAGER`?lt(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 Wt(e,t){if(e.type!==`serviceTask`)return null;let n=hn(e.data.action);return n.length===0?[`未指定知會對象`]:n.map(e=>B(t,e).name)}function Gt(e,t,n){let r=e.map(e=>B(t,e).name);return r.length===0?n:r.length<=2?r.join(`、`):`${r.slice(0,2).join(`、`)} 等 ${r.length} 人`}function Kt(e,t){return`${e} (${t})`}function qt(e,t){let n=t?.getBoundingClientRect();if(!n||e.nodes.length===0)return null;let r=e.nodes.reduce((e,t)=>{let n=A(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,u.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 Jt(e){let t=e.nodes.find(e=>e.type===`userTask`&&!!W(e.data.approverResolver)),n=e.nodes.find(e=>e.type===`serviceTask`&&e.data.action.type===`NOTIFY`&&hn(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`?W(t.data.approverResolver):n?`知會節點需要至少一位知會對象。`:r?`條件分流的每條輸出連線都需要先設定條件。`:null}function W(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 Yt(e){return e.edges.some(t=>K(t,e.nodes)&&!!(t.data.condition||t.data.conditionFieldKey||t.data.conditionOperator||t.data.conditionValue))}function Xt(e){return e?.fields.map(e=>({fieldType:e.type,id:e.fieldKey,name:`${e.label} (${e.fieldKey})`}))??[]}function Zt(e,t){return t?e?.fields.find(e=>e.fieldKey===t)??null:null}function Qt(e){if(!e)return[];let t=en(e);return E.filter(e=>t.includes(e.id))}function $t(e){return E.some(t=>t.id===e)?e:null}function en(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 tn(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 nn(e,t){if(!e)return;let n=en(e);return t&&n.includes(t)?t:n[0]}function rn(e,t,n){if(!e||!t||!an(t))return;let r=tn(e);return r.length===0||r.some(e=>e.id===n)?n??void 0:r[0]?.id}function an(e){return je.includes(e)}function on(e,t,n){if(!e||!t)return;let r=G(t);if(!an(t))return`${e.label} ${r}`;if(n)return`${e.label} ${r} ${sn(e,n)}`}function G(e){return E.find(t=>t.id===e)?.name??e}function sn(e,t){return e.type===`boolean`?t===`true`?`是`:`否`:e.type===`checkbox`||e.type===`radio`||e.type===`select`?cn(e.options,t)?.label??t:t}function cn(e,t){return e.find(e=>e.value===t)??null}function ln(e,t,n){if(!e||!t)return;let r=un(e.fieldKey);if(t===`IS_FILLED`)return`${r} != null && ${r} != ""`;if(t===`IS_EMPTY`)return`${r} == null || ${r} == ""`;if(n)return`${r} ${dn(t)} ${fn(e,n)}`}function un(e){return/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)?`form.${e}`:`form[${JSON.stringify(e)}]`}function dn(e){return e===`EQUALS`?`==`:e===`NOT_EQUALS`?`!=`:e===`GREATER_THAN`?`>`:e===`GREATER_THAN_OR_EQUALS`?`>=`:e===`LESS_THAN`?`<`:`<=`}function fn(e,t){return e.type===`boolean`?t===`true`?`true`:`false`:(e.type===`money`||e.type===`number`)&&Number.isFinite(Number(t))?t:JSON.stringify(t)}function pn(e,t){if(e.data.label)return e.data.label;if(K(e,t))return mn(e);if(q(e,t))return`同時進行`}function mn(e){return e.data.isDefault?`其他情況`:`請設定條件`}function K(e,t){return t.some(t=>t.id===e.source&&t.type===`exclusiveGateway`)}function q(e,t){return t.some(t=>t.id===e.source&&t.type===`parallelGateway`)}function hn(e){return e.type===`NOTIFY`&&e.recipients.type===`DIRECT`?e.recipients.memberIds:[]}function J(e){return e instanceof Error?e.message:`發生未知錯誤`}exports.TemplateDesignerView=D;
|
|
50
|
+
`,fe={display:`grid`,gap:12},h={display:`grid`,gap:12},pe={border:`1px solid var(--mzn-color-border-neutral)`,borderRadius:6,display:`grid`,gap:8,maxHeight:360,overflow:`auto`,padding:12},me={borderBottom:`1px solid var(--mzn-color-border-neutral)`,display:`grid`,gap:4,padding:`0 0 8px`},he={display:`flex`,flexWrap:`wrap`,gap:8},ge={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%`},_e=`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)`,_=64,ve=160,v=20,y=64,ye=180,be={...g,display:`grid`,gap:8,padding:`10px 12px`},b={...be,background:`#eff6ff`,border:`1px solid #2563eb`},xe={...be,background:`#f0fdfa`,border:`1px solid #0f766e`},x={...g,background:`#ffffff`},Se={...g,background:`#ecfdf3`,border:`1px solid #2f855a`},Ce={...g,background:`#fff4ed`,border:`1px solid #c2410c`},S={display:`block`,maxWidth:`100%`,minWidth:0},we={display:`grid`,gap:2,minWidth:0},C=`input`,w=`output`,Te={endEvent:`結束`,exclusiveGateway:`條件分流`,parallelGateway:`並行處理`,serviceTask:`系統`,startEvent:`開始`,userTask:`簽核`},Ee=[{icon:c.UserIcon,label:`簽核節點`,type:`userTask`},{icon:c.MailIcon,label:`知會節點`,type:`serviceTask`}],De=[{icon:c.FilterIcon,label:`條件分流`,type:`exclusiveGateway`}],Oe=[{id:`AND`,name:`全部前置完成`},{id:`OR`,name:`任一前置完成`}],ke=[{id:`RESTART`,name:`重新送出後從開始重跑`},{id:`FROM_RETURN_POINT`,name:`重新送出後回到退回節點`}],Ae=[{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:`指定職位`}],T=[{id:`1`,name:`直屬主管`,value:1},{id:`2`,name:`第二層主管`,value:2},{id:`3`,name:`第三層主管`,value:3}],je=[{id:`NONE`,name:`停止流程並提示`},{id:`DIRECT`,name:`固定改派`}],E=[{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:`未填寫`}],D=[`EQUALS`,`GREATER_THAN`,`GREATER_THAN_OR_EQUALS`,`LESS_THAN`,`LESS_THAN_OR_EQUALS`,`NOT_EQUALS`],Me=[{id:`NONE`,name:`未設定`},{id:`ALL`,name:`所有人`},{id:`ORG_UNIT`,name:`指定組織`},{id:`ORG_UNIT_POSITION`,name:`指定組織職位`}],Ne={id:`CUSTOM`,name:`既有自訂規則`},Pe=`member-001`,Fe={endEvent:k,exclusiveGateway:k,parallelGateway:k,serviceTask:k,startEvent:k,userTask:k};function O({templateId:d,activeHref:oe}){let ce=t.a(),m=n.r(),ue=oe??m.templates(),[g,_e]=(0,a.useState)(null),[_,ve]=(0,a.useState)(null),[v,y]=(0,a.useState)($e()),[ye,be]=(0,a.useState)(``),[b,xe]=(0,a.useState)(null),[x,Se]=(0,a.useState)(null),[Ce,S]=(0,a.useState)(null),[we,C]=(0,a.useState)(null),[w,E]=(0,a.useState)(`start`),[D,O]=(0,a.useState)([]),[k,A]=(0,a.useState)(null),[Le,j]=(0,a.useState)(null),[Re,M]=(0,a.useState)(!0),[Be,Ve]=(0,a.useState)(!1),[He,qe]=(0,a.useState)(!1),[N,Ze]=(0,a.useState)([]),Qe=(0,a.useMemo)(()=>JSON.stringify({formDefinitionVersionId:b,initiatorPolicyCel:x,workflowDefinition:v}),[b,x,v]),F=!!ye&&Qe!==ye,[dt,mt]=(0,a.useState)(!1),[L,R]=(0,a.useState)([]),[z,bt]=(0,a.useState)([]),[B,Tt]=(0,a.useState)([]),[H,Pt]=(0,a.useState)([]),[It,Lt]=(0,a.useState)(!1),[Rt,zt]=(0,a.useState)(!1),[Vt,Wt]=(0,a.useState)(`{}`),[U,Gt]=(0,a.useState)(null),[Kt,qt]=(0,a.useState)(null),[Xt,W]=(0,a.useState)(void 0),cn=(0,a.useRef)(null);(0,a.useEffect)(()=>{Cn()},[d]),(0,a.useEffect)(()=>{function e(e){F&&(e.preventDefault(),e.returnValue=``)}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[F]),(0,a.useEffect)(()=>{Tn(v)},[v,L]),(0,a.useEffect)(()=>{y(e=>Ke(e))},[v.edges,v.nodes]);function ln(){F&&!window.confirm(`目前有尚未儲存的流程草稿,確定要離開嗎?`)||ce.push(m.templates())}let G=(0,a.useMemo)(()=>v.nodes.find(e=>e.id===w)??null,[w,v.nodes]),dn=G?yt(G):!1,fn=D.length>0||dn,pn=(0,a.useCallback)(()=>{let e=G&&yt(G)?G.id:null;y(t=>({...t,edges:t.edges.filter(t=>!D.includes(t.id)&&t.source!==e&&t.target!==e),nodes:e?t.nodes.filter(t=>t.id!==e):t.nodes})),O([]),A(null),e&&E(`start`)},[D,G]);(0,a.useEffect)(()=>{if(!fn)return;function e(e){e.key!==`Delete`&&e.key!==`Backspace`||xt(e.target)||(e.preventDefault(),pn())}return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e)}},[fn,pn]);let hn=(0,a.useMemo)(()=>v.edges.find(e=>e.id===k)??null,[k,v.edges]),gn=(0,a.useMemo)(()=>D.length===1?v.edges.find(e=>e.id===D[0])??null:null,[D,v.edges]),_n=(0,a.useMemo)(()=>D.map(e=>v.edges.find(t=>t.id===e)??null).filter(e=>!!e),[D,v.edges]),Y=(0,a.useMemo)(()=>we??ft(x,Ce),[x,we,Ce]),vn=(0,a.useMemo)(()=>v.nodes.map(e=>ze(e,L,z,B,e.id===w,Y)),[Y,L,z,B,w,v.nodes]),yn=(0,a.useMemo)(()=>v.edges.map(e=>Ue(e,v.nodes,D.includes(e.id))),[D,v.edges,v.nodes]),X=(0,a.useMemo)(()=>I(N,b)??I(St(g?.formVersions??[]),b),[b,N,g?.formVersions]),bn=(0,a.useMemo)(()=>Ot(N,X),[N,X]),xn=(0,a.useMemo)(()=>Yt(v),[v]),Z=(0,a.useMemo)(()=>Zt(v),[v]),Sn=(0,a.useMemo)(()=>pt(Y),[Y]);async function Cn(){M(!0),j(null);try{let[e,t]=await Promise.all([(0,f.readTemplateDesigner)(d),(0,ee.readOrganizationDashboard)()]),n=e.versions.find(e=>e.status===`DRAFT`)??null,r=n??e.versions[0]??null;_e(e),ve(n),bt(t.orgUnits),Tt(t.positions),Pt(t.memberships),Ze(St(e.formVersions));let i=r?.workflowDefinition??$e(),a=r?.formDefinitionVersionId??e.formVersions[0]?.id??null,o=r?.initiatorPolicyCel??null;y(i),xe(a),Se(o),be(JSON.stringify({formDefinitionVersionId:a,initiatorPolicyCel:o,workflowDefinition:i})),S(r&&!e.template.currentVersionId&&!r.initiatorPolicyCel&&et(r.workflowDefinition)?`NONE`:null),C(null),E(r?.workflowDefinition.nodes[0]?.id??`start`),O([]),A(null)}catch(e){j(J(e))}finally{M(!1)}}async function wn(e){qe(!0),j(null);try{Ze(Ot(St(await(0,f.searchPublishedFormVersionOptions)(e)),X))}catch(e){j(J(e))}finally{qe(!1)}}async function Q(e){mt(!0),j(null);try{let t=await(0,f.searchMemberOptions)(e);R(e=>Ht(e,kt(t)))}catch(e){j(J(e))}finally{mt(!1)}}async function Tn(e){let t=Ut(e).filter(e=>!L.some(t=>t.memberId===e));if(t.length!==0)try{let e=await(0,f.resolveMemberOptions)(t);R(t=>Ht(t,kt(e)))}catch{R(e=>Ht(e,t.map(At)))}}async function En(){Ve(!0),j(null);try{let e=Yt(v),t=pt(Y);if(e||t){let n=e??t??`流程設定未完成`;throw j(n),Error(n)}let n=await(0,f.updateApprovalTemplateDraft)({formDefinitionVersionId:b,initiatorPolicyCel:x,versionId:(_??await(0,f.forkApprovalTemplate)(d)).id,workflowDefinition:v});return ve(n),await Cn(),n}catch(e){throw j(J(e)),e}finally{Ve(!1)}}async function Dn(){Ve(!0),j(null);try{await(0,f.publishApprovalTemplateVersion)((await En()).id),await Cn()}catch(e){j(J(e))}finally{Ve(!1)}}function On(){Wt(JSON.stringify(Ct(X),null,2)),Gt(null),qt(null),Lt(!0)}function kn(){Rt||Lt(!1)}async function An(){zt(!0),qt(null),Gt(null);try{Gt(await(0,f.dryRunApprovalWorkflow)({formData:wt(Vt),initiatorMemberId:Pe,initiatorMetadataSnapshot:Ft(Pe,H),workflowDefinition:v}))}catch(e){qt(J(e))}finally{zt(!1)}}function jn(e){let t=(0,u.applyNodeChanges)(e,vn);y(e=>({...e,nodes:e.nodes.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,position:n.position}:e})}))}function Mn(e){if(!_t(e,v.nodes))return;let t=v.nodes.some(t=>t.id===e.source&&t.type===`exclusiveGateway`),n=P(e.source,e.target,{});y(e=>({...e,edges:[...e.edges,n]})),E(null),O([n.id]),A(t?n.id:null)}function Nn(e,t){e.stopPropagation(),O(n=>e.shiftKey||e.metaKey||e.ctrlKey?vt(n,t.id):[t.id]),E(null)}function Pn(){A(null)}function Fn(e){let t=Xe({definition:v,node:Je(e,Ye(v.nodes,e)),selectedEdgeId:D.length===1?D[0]:null,selectedNodeId:w}),n=tt(t.definition),r=Jt(n,cn.current);y(n),E(t.selectedNodeId),O(t.selectedEdgeIds),A(t.editingEdgeId),r&&W(r)}function In(e){G&&Vn(G.id,t=>We(t,e))}function $(e){!G||G.type!==`userTask`||Vn(G.id,t=>t.type===`userTask`?{...t,data:{...t.data,approverResolver:e,decisionPolicy:{type:`SINGLE`}}}:t)}function Ln(e){!G||G.type!==`userTask`||Vn(G.id,t=>t.type===`userTask`?{...t,data:{...t.data,returnBehavior:{...t.data.returnBehavior,resubmitStrategy:e}}}:t)}function Rn(e){!G||G.type!==`serviceTask`||Vn(G.id,t=>t.type===`serviceTask`?{...t,data:{...t.data,action:e}}:t)}function zn(e){C(e.mode===`ALL`||e.mode===`CUSTOM`?null:e),S(e.mode===`ALL`||e.mode===`CUSTOM`?null:e.mode),Se(ht(e,z))}function Bn(e){!G||G.type===`startEvent`||Vn(G.id,t=>Ge(t,e))}function Vn(e,t){y(n=>({...n,nodes:n.nodes.map(n=>n.id===e?t(n):n)}))}function Hn(e,t){y(n=>({...n,edges:n.edges.map(n=>n.id===e?t(n):n)}))}function Un(e,t){y(n=>{let r=n.edges.find(t=>t.id===e);return r?{...n,edges:n.edges.map(e=>t&&e.source===r.source&&e.id!==r.id&&K(e,n.nodes)?{...e,data:{...e.data,isDefault:!1}}:e.id===r.id?{...e,data:{...e.data,isDefault:t}}:e)}:n})}function Wn({edgeId:e,fieldKey:t,operator:n,value:r}){let i=X?.schema??null;Hn(e,e=>{let a=$t(i,t??e.data.conditionFieldKey??null),o=rn(a,n??e.data.conditionOperator??null),s=an(a,o,r??e.data.conditionValue??null),c=sn(a,o,s);return{...e,data:{...e.data,condition:un(a,o,s),conditionFieldKey:a?.fieldKey,conditionOperator:o,conditionValue:s,isDefault:!1,label:c}}})}function Gn(){let e=tt(v),t=Jt(e,cn.current);y(e),t&&W(t)}return(0,s.jsxs)(e.t,{activeHref:ue,children:[(0,s.jsx)(`style`,{children:se}),(0,s.jsx)(o.PageHeader,{children:(0,s.jsxs)(l.default,{description:`${_?`草稿 v${_.version}`:`尚未建立草稿`} ·${g?.template.currentVersionId?` 已發布版本`:` 尚未發布`}`,onBackClick:ln,title:g?.template.name??`流程設計器`,children:[(0,s.jsx)(o.Button,{"aria-label":`儲存草稿`,disabled:Be||!!xn||!!Sn,icon:c.SaveIcon,iconType:`icon-only`,onClick:()=>void En(),variant:`base-secondary`,children:`儲存草稿`}),(0,s.jsx)(o.Button,{disabled:Re||!!xn||!!Sn,icon:c.EyeIcon,iconType:`leading`,onClick:On,variant:`base-secondary`,children:`試跑流程`}),(0,s.jsx)(o.Button,{disabled:Be||!_||!!xn||!!Sn,icon:c.CheckedIcon,iconType:`leading`,onClick:()=>void Dn(),variant:`base-primary`,children:`發布版本`})]})}),(0,s.jsx)(o.SectionGroup,{children:(0,s.jsx)(o.Section,{children:(0,s.jsxs)(`div`,{style:te,children:[Le?(0,s.jsx)(o.Typography,{color:`text-error`,variant:`body`,children:Le}):null,xn?(0,s.jsx)(o.Typography,{color:`text-error`,variant:`body`,children:xn}):null,Sn?(0,s.jsx)(o.Typography,{color:`text-error`,variant:`body`,children:Sn}):null,(0,s.jsx)(`div`,{style:h,children:(0,s.jsx)(i.t,{hintText:Z?`已設定條件分流條件。請先移除所有條件,才能更換綁定表單版本。`:void 0,label:`綁定表單版本`,name:`formDefinitionVersionId`,required:!0,children:(0,s.jsx)(o.AutoComplete,{asyncData:!0,disabled:Re||Z,disabledOptionsFilter:!0,emptyText:`沒有符合的已發布表單版本`,isForceClearable:!!b&&!Z,loading:He,loadingText:`搜尋表單版本中...`,mode:`single`,onChange:e=>{Z||xe(e?.id??null)},onClear:()=>{Z||xe(null)},onSearch:wn,onVisibilityChange:e=>{e&&!Z&&wn(``)},options:[...bn],placeholder:`選擇已發布表單版本`,searchDebounceTime:300,value:X})})}),(0,s.jsxs)(`div`,{style:ne,children:[(0,s.jsx)(`div`,{ref:cn,style:re,children:(0,s.jsxs)(u.ReactFlow,{connectionMode:u.ConnectionMode.Strict,edges:yn,fitView:!0,isValidConnection:e=>_t(e,v.nodes),nodeTypes:Fe,nodes:vn,deleteKeyCode:null,multiSelectionKeyCode:[`Shift`,`Meta`,`Control`],onConnect:Mn,onEdgeClick:Nn,onNodeClick:(e,t)=>{E(t.id),O([])},onNodesChange:jn,onPaneClick:()=>{E(null),O([])},onViewportChange:W,viewport:Xt,children:[(0,s.jsx)(u.Background,{}),(0,s.jsx)(`style`,{children:de}),(0,s.jsx)(u.Controls,{children:fn?(0,s.jsx)(u.ControlButton,{"aria-label":`刪除選取項目`,className:`workflow-selection-delete-control`,onClick:pn,style:ie,title:`刪除選取項目`,children:(0,s.jsx)(`span`,{style:ae,children:(0,s.jsx)(o.Icon,{color:`error`,icon:c.TrashIcon,size:16})})}):null}),(0,s.jsx)(Ie,{onApplyAutoLayout:Gn}),(0,s.jsx)(u.MiniMap,{})]})}),(0,s.jsxs)(`div`,{className:p,style:fe,children:[(0,s.jsx)(o.Typography,{component:`h2`,variant:`h3`,children:`流程工具`}),(0,s.jsxs)(`div`,{style:ge,children:[(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`caption`,children:`動作節點`}),(0,s.jsx)(`div`,{style:he,children:Ee.map(e=>(0,s.jsx)(o.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Fn(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),(0,s.jsxs)(`div`,{style:ge,children:[(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`caption`,children:`流程控制`}),(0,s.jsx)(`div`,{style:he,children:De.map(e=>(0,s.jsx)(o.Button,{icon:e.icon,iconType:`leading`,onClick:()=>Fn(e.type),size:`sub`,variant:`base-secondary`,children:e.label},e.type))})]}),_n.length>1?Qn(_n):null,_n.length===1&&gn?$n(gn):null,_n.length===0&&G?qn(G):null]})]})]})})}),er(hn),Kn()]});function Kn(){return(0,s.jsx)(o.Modal,{cancelText:`關閉`,confirmText:`執行試跑`,loading:Rt,modalType:`standard`,onCancel:kn,onClose:kn,onConfirm:()=>void An(),open:It,showModalFooter:!0,showModalHeader:!0,size:`wide`,supportingText:`使用 ${Pe} 與範例表單資料模擬目前畫布流程,不會建立案件。`,title:`試跑流程`,children:(0,s.jsxs)(`div`,{style:h,children:[(0,s.jsx)(i.t,{label:`表單資料 JSON`,name:`dryRunFormDataJson`,required:!0,children:(0,s.jsx)(o.Textarea,{onChange:e=>Wt(e.target.value),resize:`vertical`,rows:8,value:Vt})}),Kt?(0,s.jsx)(o.Typography,{color:`text-error`,variant:`body`,children:Kt}):null,U?(0,s.jsxs)(`div`,{style:pe,children:[(0,s.jsx)(o.Typography,{color:U.valid?`text-success`:`text-error`,variant:`label-primary-highlight`,children:U.valid?`試跑通過`:`試跑失敗`}),U.errors.map(e=>(0,s.jsx)(o.Typography,{color:`text-error`,variant:`body`,children:e},e)),U.steps.map(e=>(0,s.jsxs)(`div`,{style:me,children:[(0,s.jsxs)(o.Typography,{variant:`label-primary-highlight`,children:[e.nodeLabel,` · `,Et(e.status)]}),(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`caption`,children:[Dt(e.nodeType),e.assigneeMemberId?` · 處理者:${e.assigneeMemberId}`:``,e.edgeLabel?` · 來源線段:${e.edgeLabel}`:``]}),e.edgeReason?(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`caption`,children:e.edgeReason}):null,e.entryCondition?(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`caption`,children:[`進入條件:`,e.entryConditionMatched?`符合`:`不符合`,` ·`,` `,e.entryCondition]}):null,(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`body`,children:e.message})]},e.id))]}):null]})})}function qn(e){return(0,s.jsxs)(`div`,{style:h,children:[(0,s.jsx)(o.Typography,{component:`h2`,variant:`h3`,children:`節點屬性`}),(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`body`,children:[Te[e.type],` · `,e.id]}),(0,s.jsx)(i.t,{label:`顯示名稱`,name:`nodeLabel`,required:!0,children:(0,s.jsx)(o.Input,{onChange:e=>In(e.target.value),value:e.data.label,variant:`base`})}),e.type===`startEvent`?Jn():null,e.type===`startEvent`?null:Yn(e),e.type===`userTask`?Xn(e):null,e.type===`serviceTask`?Zn(e):null]})}function Jn(){let e=Y.mode===`CUSTOM`?[...Me,Ne]:[...Me],t=Y.mode===`ORG_UNIT`||Y.mode===`ORG_UNIT_POSITION`?Mt(z,Y.orgUnitId??``):null,n=Y.mode===`ORG_UNIT_POSITION`?Nt(B,Y.positionId??``):null,a=Y.mode===`ORG_UNIT_POSITION`?Bt({includeDescendants:!!Y.includeDescendants,memberships:H,orgUnitId:Y.orgUnitId??``,orgUnits:z,positions:B}):[];return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.t,{hintText:Y.mode===`CUSTOM`?`這是舊版表達式規則;切換成標準選項後會改由 UI 管理。`:void 0,label:`發起權限`,name:`initiatorPolicyMode`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>{if(e?.id===`CUSTOM`){S(null),C(null);return}let t=ut(e?.id??null),n=gt(t);S(t===`ALL`?null:t),C(t===`ALL`?null:n),Se(ht(n,z))},options:e,placeholder:`選擇誰可以發起`,value:I(e,Y.mode)})}),Y.mode===`ORG_UNIT`||Y.mode===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{label:`組織`,name:`initiatorOrgUnitId`,required:!0,children:(0,s.jsx)(r.n,{name:`initiatorOrgUnitId`,onChange:e=>zn({...Y,orgUnitId:e?.id??``,positionId:``,value:e?.id??``}),orgUnits:z,placeholder:`選擇組織`,value:t})}):null,Y.mode===`ORG_UNIT`||Y.mode===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{label:`包含下層`,name:`initiatorIncludeDescendants`,children:(0,s.jsx)(o.Toggle,{checked:!!Y.includeDescendants,onChange:e=>zn({...Y,includeDescendants:e.target.checked,...Y.mode===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,Y.mode===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{label:`職位`,name:`initiatorPositionId`,required:!0,children:(0,s.jsx)(r.r,{disabled:!Y.orgUnitId?.trim(),name:`initiatorPositionId`,onChange:e=>zn({...Y,positionId:e?.id??``}),placeholder:Y.orgUnitId?.trim()?`選擇職位`:`請先選擇組織`,positions:a,value:n})}):null]})}function Yn(e){let t=v.edges.filter(t=>t.target===e.id).length,n=t<2,r=n?`AND`:e.data.triggerMode??`AND`;return(0,s.jsx)(i.t,{hintText:n?`需要至少兩條前置連線,才可切換為任一前置完成。`:t>1?`${t} 條前置連線會依此規則觸發。`:`只有一條前置連線時,兩種設定效果相同。`,label:`前置條件`,name:`triggerMode`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>n?void 0:Bn(nt(e?.id??null)),options:[...Oe],readOnly:n,value:I(Oe,r)})})}function Xn(e){let t=e.data.approverResolver,n=it(t.type),a=t.type===`DIRECT`?jt(t.memberIds,L):null,c=t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?Mt(z,t.orgUnitId):null,l=t.type===`POSITION`||t.type===`ORG_UNIT_POSITION`?Nt(B,t.positionId):null,ee=t.type===`ORG_UNIT_POSITION`?Bt({includeDescendants:!!t.includeDescendants,memberships:H,orgUnitId:t.orgUnitId,orgUnits:z,positions:B}):[],u=t.type===`ORG_MANAGER`?ct(t.levelsUp):T[0],d=t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?t.fallback??{type:`NONE`}:{type:`NONE`},f=d.type===`DIRECT`?V(L,d.memberId):null,te=e.data.returnBehavior.resubmitStrategy??`RESTART`;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.t,{label:`簽核來源`,name:`approverResolverType`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>$(at(e?.id??null)),options:[...Ae],value:I(Ae,n)})}),t.type===`DIRECT`?(0,s.jsx)(i.t,{label:`簽核者`,name:`memberId`,required:!0,children:(0,s.jsx)(o.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-search`,spellCheck:!1},loading:dt,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>$({memberIds:e?.id?[e.id]:[],type:`DIRECT`}),onSearch:Q,onVisibilityChange:e=>{e&&Q(``)},options:[...L],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:a})}):null,t.type===`ORG_MANAGER`?(0,s.jsx)(i.t,{hintText:`依發起人的有效會員歸屬與主管解析規則決定簽核人。`,label:`主管層級`,name:`managerLevelsUp`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>$({baseFromInitiator:!0,levelsUp:lt(e?.id??null).value,type:`ORG_MANAGER`}),options:[...T],value:u})}):null,t.type===`ORG_UNIT_MANAGER`||t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{hintText:t.type===`ORG_UNIT_MANAGER`?`依指定組織或其上層的主管解析規則決定簽核人。`:`依指定組織目前有效會員歸屬建立候選簽核人。`,label:`組織`,name:`orgUnitId`,required:!0,children:(0,s.jsx)(r.n,{name:`orgUnitId`,onChange:e=>$(t.type===`ORG_UNIT_MEMBER`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,type:`ORG_UNIT_MEMBER`}:t.type===`ORG_UNIT_POSITION`?{includeDescendants:t.includeDescendants,orgUnitId:e?.id??``,positionId:``,type:`ORG_UNIT_POSITION`}:{fallback:t.fallback,orgUnitId:e?.id??``,type:`ORG_UNIT_MANAGER`}),orgUnits:z,placeholder:`選擇組織`,value:c})}):null,t.type===`ORG_MANAGER`||t.type===`ORG_UNIT_MANAGER`?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.t,{hintText:`預設會停止流程並提示;若設定固定人,找不到主管時會改派給該會員。`,label:`無主管時`,name:`approverFallbackMode`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>$(st(t,ot(e?.id??null)===`DIRECT`?{memberId:``,type:`DIRECT`}:{type:`NONE`})),options:[...je],value:I(je,d.type)})}),d.type===`DIRECT`?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.t,{label:`改派人員`,name:`approverFallbackMemberId`,required:!0,children:(0,s.jsx)(o.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,inputProps:{autoCapitalize:`none`,autoCorrect:`off`,name:`workflow-approver-fallback-search`,spellCheck:!1},loading:dt,loadingText:`搜尋成員中...`,mode:`single`,onChange:e=>$(st(t,{allowInitiatorSelfApproval:d.allowInitiatorSelfApproval,memberId:e?.id??``,type:`DIRECT`})),onSearch:Q,onVisibilityChange:e=>{e&&Q(``)},options:[...L],placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:f})}),(0,s.jsx)(i.t,{hintText:`預設禁止申請人簽自己的案件;只有此流程允許自簽時才開啟。`,label:`允許自簽`,name:`allowInitiatorSelfApproval`,children:(0,s.jsx)(o.Toggle,{checked:!!d.allowInitiatorSelfApproval,onChange:e=>$(st(t,{allowInitiatorSelfApproval:e.target.checked,memberId:d.memberId,type:`DIRECT`}))})})]}):null]}):null,t.type===`ORG_UNIT_MEMBER`||t.type===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{label:`包含下層`,name:`includeDescendants`,children:(0,s.jsx)(o.Toggle,{checked:!!t.includeDescendants,onChange:e=>$({...t,includeDescendants:e.target.checked,...t.type===`ORG_UNIT_POSITION`?{positionId:``}:{}})})}):null,t.type===`POSITION`?(0,s.jsx)(i.t,{hintText:`指派給目前有效歸屬中擁有此職位的會員;主要歸屬優先。`,label:`職位`,name:`positionId`,required:!0,children:(0,s.jsx)(r.r,{name:`positionId`,onChange:e=>$({positionId:e?.id??``,type:`POSITION`}),placeholder:`選擇職位`,positions:B,value:l})}):null,t.type===`ORG_UNIT_POSITION`?(0,s.jsx)(i.t,{hintText:`只納入指定組織範圍內擁有此職位的有效會員。`,label:`職位`,name:`orgUnitPositionId`,required:!0,children:(0,s.jsx)(r.r,{disabled:!t.orgUnitId.trim(),name:`orgUnitPositionId`,onChange:e=>$({includeDescendants:t.includeDescendants,orgUnitId:t.orgUnitId,positionId:e?.id??``,type:`ORG_UNIT_POSITION`}),placeholder:t.orgUnitId.trim()?`選擇職位`:`請先選擇組織`,positions:ee,value:l})}):null,e.data.returnBehavior.allowReturn?(0,s.jsx)(i.t,{hintText:`退回發起人後,重新送出時要從流程開始重跑,或直接回到退回的簽核節點。`,label:`重送策略`,name:`returnResubmitStrategy`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:e=>Ln(rt(e?.id??null)),options:[...ke],value:I(ke,te)})}):null]})}function Zn(e){let t=q(e.data.action).map(e=>V(L,e));return(0,s.jsx)(i.t,{label:`知會對象`,name:`notifyMemberIds`,required:!0,children:(0,s.jsx)(o.AutoComplete,{asyncData:!0,disabledOptionsFilter:!0,emptyText:`沒有符合的成員`,loading:dt,loadingText:`搜尋成員中...`,mode:`multiple`,onChange:e=>Rn({channels:[`IN_APP`],recipients:{memberIds:e.map(e=>e.id),type:`DIRECT`},type:`NOTIFY`}),onSearch:Q,onVisibilityChange:e=>{e&&Q(``)},options:[...L],overflowStrategy:`wrap`,placeholder:`搜尋姓名或信箱`,searchDebounceTime:300,value:[...t]})})}function Qn(e){return(0,s.jsxs)(`div`,{style:h,children:[(0,s.jsx)(o.Typography,{component:`h2`,variant:`h3`,children:`已選取線段`}),(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`body`,children:[`已選取 `,e.length,` 條線段,可使用 Delete 或控制面板刪除。`]})]})}function $n(e){let t=K(e,v.nodes);return(0,s.jsxs)(`div`,{style:h,children:[(0,s.jsx)(o.Typography,{component:`h2`,variant:`h3`,children:t?`條件設定`:`線段屬性`}),(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`body`,children:[e.source,` → `,e.target]}),t?tr(e):(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`body`,children:`這條線會直接把流程送到下一個節點。`})]})}function er(e){return!e||!K(e,v.nodes)?null:(0,s.jsx)(o.Modal,{cancelText:`取消`,confirmButtonProps:{disabled:!e.data.isDefault&&!e.data.condition},confirmText:`完成`,modalType:`standard`,onCancel:Pn,onClose:Pn,onConfirm:Pn,open:!!k,showModalFooter:!0,showModalHeader:!0,size:`regular`,supportingText:`條件分流的輸出連線需要指定條件,條件會直接顯示在線上。`,title:`條件設定`,children:tr(e)})}function tr(e){let t=mn(e,v.nodes),n=Qt(X?.schema??null),r=$t(X?.schema??null,e.data.conditionFieldKey??null),a=en(r),c=nn(r),l=I(a,e.data.conditionOperator??null);return(0,s.jsxs)(`div`,{style:h,children:[(0,s.jsxs)(o.Typography,{color:`text-neutral`,variant:`body`,children:[`畫布上的這條線目前會顯示「`,(0,s.jsx)(`span`,{style:{color:!e.data.isDefault&&!e.data.condition?le:void 0},children:t??`請設定條件`}),`」。`]}),(0,s.jsx)(o.Toggle,{checked:!!e.data.isDefault,label:`其他情況走這條`,onChange:t=>Un(e.id,t.target.checked)}),e.data.isDefault?(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`body`,children:`其他條件都不符合時,流程會走這條線。`}):(0,s.jsxs)(s.Fragment,{children:[X?null:(0,s.jsx)(o.Typography,{color:`text-neutral`,variant:`body`,children:`請先綁定表單版本,才能選擇條件欄位。`}),(0,s.jsx)(i.t,{label:`條件欄位`,name:`edgeConditionField`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:t=>Wn({edgeId:e.id,fieldKey:t?.id??null,operator:null,value:null}),options:[...n],placeholder:`選擇條件欄位`,value:I(n,e.data.conditionFieldKey??null)})}),(0,s.jsx)(i.t,{label:`條件判斷`,name:`edgeConditionOperator`,required:!0,children:(0,s.jsx)(o.Select,{clearable:!1,onChange:t=>Wn({edgeId:e.id,operator:tn(t?.id??null),value:null}),options:[...a],placeholder:`選擇判斷方式`,value:l})}),l&&on(l.id)?(0,s.jsx)(i.t,{label:`條件值`,name:`edgeConditionValue`,required:!0,children:c.length>0?(0,s.jsx)(o.Select,{clearable:!1,onChange:t=>Wn({edgeId:e.id,value:t?.id??null}),options:[...c],placeholder:`選擇條件值`,value:I(c,e.data.conditionValue??null)}):(0,s.jsx)(o.Input,{onChange:t=>Wn({edgeId:e.id,value:t.target.value}),placeholder:`輸入要比對的值`,value:e.data.conditionValue??``,variant:`base`})}):null]})]})}}function Ie({onApplyAutoLayout:e}){function t(){e()}return(0,s.jsx)(u.Panel,{position:`top-right`,children:(0,s.jsx)(o.Button,{icon:c.DotGridIcon,iconType:`leading`,onClick:t,size:`sub`,variant:`base-secondary`,children:`自動排版`})})}function k({data:e,selected:t,type:n}){let r=e.approverLines??[e.approverSummary??e.label],i=A(e);return(0,s.jsxs)(`div`,{style:Le(n,t),children:[Re(e),(0,s.jsx)(`div`,{style:we,children:r.map((e,t)=>(0,s.jsx)(o.Typography,{component:`span`,ellipsis:!0,style:S,title:e,variant:`label-primary`,children:e},`${e}_${t}`))}),(0,s.jsx)(o.Typography,{color:`text-neutral`,component:`span`,ellipsis:!0,style:S,title:i,variant:`caption`,children:i})]})}function A(e){return e.nodeKind===`startEvent`?e.initiatorPolicySummary??`所有人`:e.approverSummary||e.approverLines?e.label:e.nodeKind===`exclusiveGateway`?`條件在線上`:e.nodeKind===`parallelGateway`?`多條路徑同時進行`:Te[e.nodeKind]}function Le(e,t){let n=j(e);return t?{...n,border:`1px solid var(--mzn-color-primary, #0057ff)`,boxShadow:_e}:n}function j(e){return e===`exclusiveGateway`?b:e===`parallelGateway`?xe:e===`startEvent`?Se:e===`endEvent`?Ce:e===`userTask`?x:g}function Re(e){return!e.hasInput&&e.hasOutput?(0,s.jsx)(u.Handle,{id:w,position:u.Position.Right,type:`source`}):e.hasInput&&!e.hasOutput?(0,s.jsx)(u.Handle,{id:C,position:u.Position.Left,type:`target`}):!e.hasInput&&!e.hasOutput?null:[(0,s.jsx)(u.Handle,{id:C,position:u.Position.Left,type:`target`},`target`),(0,s.jsx)(u.Handle,{id:w,position:u.Position.Right,type:`source`},`source`)]}function ze(e,t,n,r,i,a){let o=M(e);return{data:{approverLines:Gt(e,t),approverSummary:Wt(e,t,n,r),hasInput:R(e),hasOutput:z(e),initiatorPolicySummary:e.type===`startEvent`?L(a,n,r):null,label:e.data.label,nodeKind:e.type},height:o.height,handles:Be(e),id:e.id,initialHeight:o.height,initialWidth:o.width,position:e.position,selected:i,sourcePosition:u.Position.Right,targetPosition:u.Position.Left,type:e.type,width:o.width}}function M(e){return e.type===`exclusiveGateway`||e.type===`parallelGateway`?{height:y,width:ye}:e.type===`serviceTask`?{height:_+(Math.max(1,q(e.data.action).length)-1)*v,width:ve}:{height:_,width:ve}}function Be(e){let t=M(e);return[...R(e)?[Ve(t)]:[],...z(e)?[He(t)]:[]]}function Ve({height:e}){let t=e/2-9/2;return{height:9,id:C,position:u.Position.Left,type:`target`,width:9,x:-9/2,y:t}}function He({height:e,width:t}){let n=e/2-9/2;return{height:9,id:w,position:u.Position.Right,type:`source`,width:9,x:t-9/2,y:n}}function Ue(e,t,n){let r=mn(e,t),i=K(e,t),a=i&&!e.data.isDefault&&!e.data.condition,o=a?le:i?ce:`#475569`,s=a?`#fef2f2`:i?`#eff6ff`:`#ffffff`,c=a?le:i?ce:m;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?ue:void 0,opacity:1,stroke:m,strokeOpacity:1,strokeWidth:1.5},target:e.target,targetHandle:e.targetHandle,type:e.type??`smoothstep`}}function We(e,t){return e.type===`startEvent`||e.type===`endEvent`||e.type===`userTask`||e.type===`serviceTask`||e.type,{...e,data:{...e.data,label:t}}}function Ge(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 Ke(e){return N(qe(e))}function qe(e){let t=new Set(e.nodes.filter(e=>bt(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 N(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`?Ge(e,`AND`):e);return n.some((t,n)=>t!==e.nodes[n])?{...e,nodes:n}:e}function Je(e,t){let n={id:`${e}_${t}`,position:{x:260+t*48,y:120+t*42}};return e===`userTask`?{...n,data:{allowAddSigner:!1,allowReject:!0,allowTransfer:!0,approverResolver:{memberIds:[`member-001`],type:`DIRECT`},decisionPolicy:{type:`SINGLE`},label:`簽核節點 ${t}`,returnBehavior:{allowReturn:!0,allowedTargets:`INITIATOR`,resubmitStrategy:`RESTART`},triggerMode:`AND`},type:e}:e===`serviceTask`?{...n,data:{action:{channels:[`IN_APP`],recipients:{memberIds:[`member-001`],type:`DIRECT`},type:`NOTIFY`},label:`知會節點 ${t}`,triggerMode:`AND`},type:e}:{...n,data:{direction:`split`,label:`條件分流 ${t}`,triggerMode:`AND`},type:e}}function Ye(e,t){let n=new Set(e.filter(e=>e.type===t).map(e=>Number(e.id.replace(`${t}_`,``))).filter(e=>Number.isInteger(e)&&e>0));return Array.from({length:e.length+1},(e,t)=>t+1).find(e=>!n.has(e))??e.length+1}function Xe({definition:e,node:t,selectedEdgeId:n,selectedNodeId:r}){let i=n?e.edges.find(e=>e.id===n)??null:null,a=r?e.nodes.find(e=>e.id===r)??null:null;return i?Ze(e,t,i):a?Qe(e,t,a):{definition:{...e,nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}function Ze(e,t,n){if(!R(t))return{definition:e,editingEdgeId:null,selectedEdgeIds:[n.id],selectedNodeId:null};if(!z(t)){let r=P(n.source,t.id,{});return{definition:{...e,edges:[...e.edges,r],nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}let r=P(n.source,t.id,n.data),i=P(t.id,n.target,F(t,n)),a=K(i,[...e.nodes,t]);return{definition:{...e,edges:e.edges.flatMap(e=>e.id===n.id?[r,i]:[e]),nodes:[...e.nodes,t]},editingEdgeId:a?i.id:null,selectedEdgeIds:a?[i.id]:[],selectedNodeId:a?null:t.id}}function Qe(e,t,n){if(!z(n))return{definition:{...e,nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id};let r=e.edges.find(e=>e.source===n.id)??null;if(r&&z(t))return Ze(e,t,r);let i=e.nodes.find(e=>e.type===`endEvent`);if(i&&n.id!==i.id&&z(t)){let r=P(n.id,t.id,{}),a=P(t.id,i.id,F(t,r)),o=K(a,[...e.nodes,t]);return{definition:{...e,edges:[...e.edges,r,a],nodes:[...e.nodes,t]},editingEdgeId:o?a.id:null,selectedEdgeIds:o?[a.id]:[],selectedNodeId:o?null:t.id}}let a=P(n.id,t.id,{});return{definition:{...e,edges:[...e.edges,a],nodes:[...e.nodes,t]},editingEdgeId:null,selectedEdgeIds:[],selectedNodeId:t.id}}function P(e,t,n){return{data:n,id:`edge_${e}_${t}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,source:e,sourceHandle:w,target:t,targetHandle:C,type:`smoothstep`}}function F(e,t){return e.type===`exclusiveGateway`?{isDefault:!0,label:`其他情況`}:{}}function $e(){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 et(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 tt(e){let t=new d.graphlib.Graph;return t.setDefaultEdgeLabel(()=>({})),t.setGraph({rankdir:`LR`,ranksep:120}),e.nodes.forEach(e=>{t.setNode(e.id,M(e))}),e.edges.forEach(e=>{t.setEdge(e.source,e.target)}),d.layout(t),{...e,nodes:e.nodes.map(e=>{let n=t.node(e.id);return n?{...e,position:{x:n.x-M(e).width/2,y:n.y-M(e).height/2}}:e})}}function I(e,t){return t?e.find(e=>e.id===t)??null:null}function nt(e){return e===`OR`?`OR`:`AND`}function rt(e){return e===`FROM_RETURN_POINT`?`FROM_RETURN_POINT`:`RESTART`}function it(e){return e===`ORG_MANAGER`||e===`ORG_UNIT_MANAGER`||e===`ORG_UNIT_MEMBER`||e===`ORG_UNIT_POSITION`||e===`POSITION`?e:`DIRECT`}function at(e){let t=it(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 ot(e){return e===`DIRECT`?`DIRECT`:`NONE`}function st(e,t){return e.type===`ORG_MANAGER`||e.type===`ORG_UNIT_MANAGER`?{...e,fallback:t}:e}function ct(e){return T.find(t=>t.value===e)??T[0]}function lt(e){return T.find(t=>t.id===e)??T[0]}function ut(e){return e===`ORG_UNIT`||e===`ORG_UNIT_POSITION`||e===`NONE`?e:`ALL`}function dt(e){let t=e?.trim();if(!t)return{mode:`ALL`,value:``};let n=mt(t,/"([^"]+)" in subject\.orgUnitIds/gu),r=mt(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 ft(e,t){let n=dt(e);return!t||t===`ALL`||t===`NONE`?t===`ALL`||t===`NONE`?{mode:t,value:``}:n:n.mode===t?n:gt(t)}function pt(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 mt(e,t){return[...e.matchAll(t)].map(e=>e[1]).filter(e=>!!e)}function ht(e,t){if(e.mode===`ALL`||e.mode===`NONE`)return null;let n=e.orgUnitId?.trim()??``;if(!n)return null;let r=Vt(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 L(e,t,n){return e.mode===`NONE`?`未設定`:e.mode===`ORG_UNIT`?e.orgUnitId?`組織:${H(t,e.orgUnitId)}`:`指定組織`:e.mode===`ORG_UNIT_POSITION`?e.orgUnitId&&e.positionId?`組織職位:${H(t,e.orgUnitId)} / ${Pt(n,e.positionId)}`:`指定組織職位`:e.mode===`CUSTOM`?`既有自訂規則`:`所有人`}function gt(e){return{includeDescendants:!0,mode:e,orgUnitId:``,positionId:``,value:``}}function _t(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===w&&e.targetHandle===C&&!!(n&&z(n))&&!!(r&&R(r))}function vt(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function yt(e){return e.type!==`startEvent`&&e.type!==`endEvent`}function R(e){return e.type!==`startEvent`}function z(e){return e.type!==`endEvent`&&!bt(e)}function bt(e){return e.type===`serviceTask`&&e.data.action.type===`NOTIFY`}function xt(e){return e instanceof HTMLElement?e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||!!e.closest(`[contenteditable="true"]`):!1}function St(e){return e.map(e=>({id:e.id,name:`${e.formName} | v${e.version}`,schema:e.schema}))}function Ct(e){return(e?.schema.fields??[]).reduce((e,t)=>({...e,[t.fieldKey]:B(t)}),{})}function B(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 wt(e){let t=JSON.parse(e);if(!Tt(t))throw Error(`表單資料 JSON 必須是物件。`);return t}function Tt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Et(e){return e===`COMPLETED`?`完成`:e===`PASSED`?`通過`:e===`SKIPPED`?`略過`:e===`STOPPED`?`已停止`:e===`WAITING`?`將等待簽核`:e}function Dt(e){return e in Te?Te[e]:e}function Ot(e,t){return t&&!e.some(e=>e.id===t.id)?[t,...e]:e}function kt(e){return e.map(e=>({displayName:e.name,email:e.email,id:e.memberId,memberId:e.memberId,name:qt(e.name,e.email)}))}function At(e){return{displayName:`未知會員`,email:``,id:e,memberId:e,name:`未知會員`}}function V(e,t){return e.find(e=>e.memberId===t)??At(t)}function jt(e,t){let n=e[0];return n?V(t,n):null}function Mt(e,t){let n=e.find(e=>e.id===t);return n?r.a(n):null}function Nt(e,t){let n=e.find(e=>e.id===t);return n?r.o(n):null}function H(e,t){return Mt(e,t)?.name??`未指定組織`}function Pt(e,t){return Nt(e,t)?.name??`未指定職位`}function Ft(e,t){let n=It(),r=t.filter(t=>t.memberId===e&&Lt(t,n)),i=r.reduce((e,t)=>e&&Rt(e,t)<=0?e:t,null);return{customFields:{},managerMemberId:`member-002`,memberId:e,orgCode:`HQ`,orgUnitIds:zt(r.map(e=>e.orgUnitId)),positionId:i?.positionId??null,positionIds:zt(r.map(e=>e.positionId)),primaryOrgUnitId:i?.orgUnitId??null,roles:[`manager`]}}function It(){return new Date().toISOString().slice(0,10)}function Lt(e,t){return e.effectiveFrom<=t&&(!e.effectiveTo||e.effectiveTo>=t)}function Rt(e,t){return e.isPrimary===t.isPrimary?t.effectiveFrom.localeCompare(e.effectiveFrom):e.isPrimary?-1:1}function zt(e){return e.reduce((e,t)=>t&&!e.includes(t)?[...e,t]:e,[])}function Bt({includeDescendants:e,memberships:t,orgUnitId:n,orgUnits:r,positions:i}){let a=new Set(Vt(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 Vt(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 Ht(e,t){let n=new Set(e.map(e=>e.memberId)),r=t.filter(e=>!n.has(e.memberId));return[...e,...r]}function Ut(e){return[...new Set(e.nodes.flatMap(e=>e.type===`userTask`?e.data.approverResolver.type===`DIRECT`?e.data.approverResolver.memberIds:[]:e.type===`serviceTask`?q(e.data.action):[]))]}function Wt(e,t,n,r){return e.type===`userTask`?U(e.data.approverResolver,t,n,r):null}function U(e,t,n,r){return e.type===`DIRECT`?Kt(e.memberIds,t,`未指定簽核者`):e.type===`ORG_MANAGER`?ct(e.levelsUp).name:e.type===`ORG_UNIT_MANAGER`?`組織主管:${H(n,e.orgUnitId)}`:e.type===`ORG_UNIT_MEMBER`?`組織任一人:${H(n,e.orgUnitId)}`:e.type===`ORG_UNIT_POSITION`?`組織職位:${H(n,e.orgUnitId)} / ${Pt(r,e.positionId)}`:e.type===`POSITION`?`職位:${Pt(r,e.positionId)}`:e.type===`DYNAMIC_FORM`?`表單欄位:${e.formPath||`未設定`}`:`自訂表達式`}function Gt(e,t){if(e.type!==`serviceTask`)return null;let n=q(e.data.action);return n.length===0?[`未指定知會對象`]:n.map(e=>V(t,e).name)}function Kt(e,t,n){let r=e.map(e=>V(t,e).name);return r.length===0?n:r.length<=2?r.join(`、`):`${r.slice(0,2).join(`、`)} 等 ${r.length} 人`}function qt(e,t){return`${e} (${t})`}function Jt(e,t){let n=t?.getBoundingClientRect();if(!n||e.nodes.length===0)return null;let r=e.nodes.reduce((e,t)=>{let n=M(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,u.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 Yt(e){let t=e.nodes.find(e=>e.type===`userTask`&&!!Xt(e.data.approverResolver)),n=e.nodes.find(e=>e.type===`serviceTask`&&e.data.action.type===`NOTIFY`&&q(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`?Xt(t.data.approverResolver):n?`知會節點需要至少一位知會對象。`:r?`條件分流的每條輸出連線都需要先設定條件。`:null}function Xt(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 Zt(e){return e.edges.some(t=>K(t,e.nodes)&&!!(t.data.condition||t.data.conditionFieldKey||t.data.conditionOperator||t.data.conditionValue))}function Qt(e){return e?.fields.map(e=>({fieldType:e.type,id:e.fieldKey,name:`${e.label} (${e.fieldKey})`}))??[]}function $t(e,t){return t?e?.fields.find(e=>e.fieldKey===t)??null:null}function en(e){if(!e)return[];let t=W(e);return E.filter(e=>t.includes(e.id))}function tn(e){return E.some(t=>t.id===e)?e:null}function W(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 nn(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 rn(e,t){if(!e)return;let n=W(e);return t&&n.includes(t)?t:n[0]}function an(e,t,n){if(!e||!t||!on(t))return;let r=nn(e);return r.length===0||r.some(e=>e.id===n)?n??void 0:r[0]?.id}function on(e){return D.includes(e)}function sn(e,t,n){if(!e||!t)return;let r=cn(t);if(!on(t))return`${e.label} ${r}`;if(n)return`${e.label} ${r} ${ln(e,n)}`}function cn(e){return E.find(t=>t.id===e)?.name??e}function ln(e,t){return e.type===`boolean`?t===`true`?`是`:`否`:e.type===`checkbox`||e.type===`radio`||e.type===`select`?G(e.options,t)?.label??t:t}function G(e,t){return e.find(e=>e.value===t)??null}function un(e,t,n){if(!e||!t)return;let r=dn(e.fieldKey);if(t===`IS_FILLED`)return`${r} != null && ${r} != ""`;if(t===`IS_EMPTY`)return`${r} == null || ${r} == ""`;if(n)return`${r} ${fn(t)} ${pn(e,n)}`}function dn(e){return/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)?`form.${e}`:`form[${JSON.stringify(e)}]`}function fn(e){return e===`EQUALS`?`==`:e===`NOT_EQUALS`?`!=`:e===`GREATER_THAN`?`>`:e===`GREATER_THAN_OR_EQUALS`?`>=`:e===`LESS_THAN`?`<`:`<=`}function pn(e,t){return e.type===`boolean`?t===`true`?`true`:`false`:(e.type===`money`||e.type===`number`)&&Number.isFinite(Number(t))?t:JSON.stringify(t)}function mn(e,t){if(e.data.label)return e.data.label;if(K(e,t))return hn(e);if(gn(e,t))return`同時進行`}function hn(e){return e.data.isDefault?`其他情況`:`請設定條件`}function K(e,t){return t.some(t=>t.id===e.source&&t.type===`exclusiveGateway`)}function gn(e,t){return t.some(t=>t.id===e.source&&t.type===`parallelGateway`)}function q(e){return e.type===`NOTIFY`&&e.recipients.type===`DIRECT`?e.recipients.memberIds:[]}function J(e){return e instanceof Error?e.message:`發生未知錯誤`}exports.TemplateDesignerView=O;
|
|
51
51
|
//# sourceMappingURL=index.cjs.map
|