@nocobase/client 2.0.39 → 2.0.41

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/lib/index.js CHANGED
@@ -62,7 +62,7 @@
62
62
  width: 100%;
63
63
  }
64
64
  }
65
- `,items:a},n))})},SchemaInitializerSubMenu=e=>{var t;const o=e,{children:r,items:i,title:n,name:l,onOpenChange:a,icon:c}=o,u=te(o,["children","items","title","name","onOpenChange","icon"]),d=useCompile(),m=useSchemaInitializerItem(),p=(0,import_react2.useMemo)(()=>l||(m==null?void 0:m.name)||(0,import_shared.uid)(),[l,m]),h=(t=i||r)==null?void 0:t.filter(_=>_.useVisible?_.useVisible():!0),g=useSchemaInitializerMenuItems(h,l),f=(0,import_react2.useMemo)(()=>[I(x({},u),{key:p,label:d(n),icon:typeof c=="string"?(0,import_jsx_runtime.jsx)(import_icons.default,{type:c}):c,children:g})],[g,d,c,p,u,n]);return(0,import_jsx_runtime.jsx)(SchemaInitializerMenu,{onOpenChange:a,items:f})},SchemaInitializerSubMenuInternal=()=>{const e=useSchemaInitializerItem();return(0,import_jsx_runtime.jsx)(SchemaInitializerSubMenu,x({},e))},useAriaAttributeOfMenuItem=()=>{const{isInMenu:e}=useSchemaInitializerSubMenuContext();return{attribute:(0,import_react2.useMemo)(()=>e?{}:{role:"menuitem"},[e])}},{Paragraph:Paragraph$1,Text:Text$2}=import_antd.Typography,ErrorFallbackModal=e=>{const[t,o]=import_react2.default.useState(!1),r=(0,import_jsx_runtime.jsx)(Paragraph$1,{style:{display:"flex",marginBottom:0},copyable:{text:e.error.message},children:(0,import_jsx_runtime.jsxs)(Text$2,{type:"danger",style:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden",display:"inline-block",maxWidth:"200px"},children:["Error: ",e.error.message]})});return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)("div",{onMouseOver:()=>o(!0),children:e.children||r}),(0,import_jsx_runtime.jsx)(import_antd.Modal,{zIndex:1e4,open:t,footer:null,onCancel:()=>o(!1),width:"60%",children:(0,import_jsx_runtime.jsx)(ErrorFallback,x({},e))})]})},{Paragraph,Text:Text$1,Link}=import_antd.Typography,useDownloadLogs=(e,t={})=>{const o=useLocationNoUpdate(),[r,i]=import_react2.default.useState(!1),n=useAPIClient();return{loading:r,download:()=>L(void 0,null,function*(){i(!0);try{const l=yield n.request({url:"logger:collect",method:"post",responseType:"blob",data:x({error:{message:e.message,stack:e.stack},location:o},t)}),a=window.URL.createObjectURL(new Blob([l.data],{type:"application/gzip"})),c=document.createElement("a");c.setAttribute("href",a),c.setAttribute("download","logs.tar.gz"),c.click(),c.remove()}catch(l){console.log(l)}i(!1)})}},ErrorFallback=({error:e})=>{const t=(0,import_react.useFieldSchema)(),{t:o}=(0,import_react_i18next.useTranslation)(),{loading:r,download:i}=useDownloadLogs(e,{schema:t}),n=(0,import_jsx_runtime.jsxs)(import_react_i18next.Trans,{children:["This is likely a NocoBase internals bug. Please open an issue at ",(0,import_jsx_runtime.jsx)(Link,{href:"https://github.com/nocobase/nocobase/issues",target:"_blank",children:"here"})]});return(0,import_jsx_runtime.jsx)("div",{style:{backgroundColor:"white"},children:(0,import_jsx_runtime.jsx)(import_antd.Result,{style:{maxWidth:"60vw",margin:"auto"},status:"error",title:o("Render Failed"),subTitle:n,extra:[(0,import_jsx_runtime.jsx)(import_antd.Button,{type:"primary",href:"https://github.com/nocobase/nocobase/issues",target:"_blank",children:o("Feedback")},"feedback"),(0,import_jsx_runtime.jsx)(import_antd.Button,{loading:r,onClick:i,children:o("Download logs")},"log")],children:(0,import_jsx_runtime.jsx)(Paragraph,{copyable:{text:e.stack},children:(0,import_jsx_runtime.jsx)(Text$1,{type:"danger",style:{whiteSpace:"pre-line",textAlign:"center"},children:e.stack})})})})};ErrorFallback.Modal=ErrorFallbackModal;const AppNotFound=()=>{const e=(0,import_react_router_dom.useNavigate)(),{t}=(0,import_react_i18next.useTranslation)();return(0,import_jsx_runtime.jsx)(import_antd.Result,{status:"404",title:"404",subTitle:t("Sorry, the page you visited does not exist."),extra:(0,import_jsx_runtime.jsx)(import_antd.Button,{onClick:()=>e("/",{replace:!0}),type:"primary",children:"Back Home"})})};class Plugin{constructor(t,o){this.options=t,this.app=o,this.options=t,this.app=o}get pluginManager(){return this.app.pluginManager}get context(){return this.app.context}get flowEngine(){return this.app.flowEngine}get engine(){return this.app.flowEngine}get ai(){return this.app.aiManager}get pm(){return this.app.pm}get router(){return this.app.router}get pluginSettingsManager(){return this.app.pluginSettingsManager}get pluginSettingsRouter(){return this.app.pluginSettingsManager}get schemaInitializerManager(){return this.app.schemaInitializerManager}get schemaSettingsManager(){return this.app.schemaSettingsManager}get dataSourceManager(){return this.app.dataSourceManager}afterAdd(){return L(this,null,function*(){})}beforeLoad(){return L(this,null,function*(){})}load(){return L(this,null,function*(){})}t(t,o={}){var r;return this.app.i18n.t(t,x({ns:(r=this.options)==null?void 0:r.packageName},o))}}const titleWrapperStyle={display:"flex",alignItems:"center",gap:4},withTooltipComponent=e=>t=>{const{tooltip:o}=t;return o?(0,import_jsx_runtime.jsxs)("div",{style:titleWrapperStyle,children:[(0,import_jsx_runtime.jsx)(e,x({},t)),(0,import_jsx_runtime.jsx)(import_antd.Tooltip,{title:o,children:(0,import_jsx_runtime.jsx)(import_icons.QuestionCircleOutlined,{style:{zIndex:1}})})]}):(0,import_jsx_runtime.jsx)(e,x({},t))},{evaluate}=import_client4.evaluators.get("formula.js"),useEvaluatedExpression=e=>{const t=useVariables$1(),o=useLocalVariables$1(),[r,i]=(0,import_react2.useState)();return(0,import_react2.useEffect)(()=>{L(void 0,null,function*(){if(e==null||e===""){i(void 0);return}const{exp:n,scope:l}=yield replaceVariables(e,{variables:t,localVariables:o});try{const a=evaluate(n,x({now:()=>new Date().toString()},l));i(a)}catch(a){console.error(a)}})},[t.parseVariable,e,o]),r};class SchemaInitializer{constructor(t){R(this,"options"),R(this,"name"),this.options=Object.assign({items:[]},t),this.name=t.name}get items(){return this.options.items}add(t,o){const r=t.split("."),i=r[r.length-1],n=I(x({},o),{name:i}),l=(u,d)=>{const m=this.items.findIndex(p=>p.name===u);m===-1?this.items.push(d):this.items[m]=d};if(r.length===1){l(i,n);return}const a=r.slice(0,-1).join("."),c=this.get(a);if(c){c.children||(c.children=[]);const u=t.replace(`${c.name}.`,""),d=c.children.findIndex(m=>m.name===u);d===-1?c.children.push(n):c.children[d]=n}else l(i,n)}get(t){var o;if(!t)return;const r=t.split(".");let i={children:this.items};for(let n=0;n<r.length;n++){const l=r[n],a=(o=i.children)==null?void 0:o.find(c=>c.name===l);if(a&&(i=a),n===r.length-1)return a}}remove(t){const o=t.split(".");if(o.length===1){const i=this.items.findIndex(n=>n.name===o[0]);i!==-1&&this.items.splice(i,1);return}const r=this.get(o.slice(0,-1).join("."));if(r&&r.children){const i=o[o.length-1],n=r.children.findIndex(l=>l.name===i);n!==-1&&r.children.splice(n,1)}}}var NocoBaseDesktopRouteType=(e=>(e.group="group",e.page="page",e.flowRoute="flowRoute",e.link="link",e.tabs="tabs",e.flowPage="flowPage",e))(NocoBaseDesktopRouteType||{});const useStyles$h=genStyleHook("nb-menu-item",e=>{const{componentCls:t}=e;return{[t]:{paddingLeft:`${e.padding}px !important`,paddingRight:`${e.padding}px !important`}}}),useInsertFlowPageSchema=()=>{const e=useAPIClient();return(0,import_react2.useCallback)(t=>L(void 0,null,function*(){yield e.request({method:"POST",url:"/uiSchemas:insert",data:t})}),[e])},FlowPageMenuItem=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),{theme:o}=useGlobalTheme(),{componentCls:r,hashId:i}=useStyles$h(),n=useParentRoute(),{createRoute:l}=useNocoBaseRoutes(),a=useInsertFlowPageSchema(),c=(0,import_react2.useCallback)(()=>L(void 0,null,function*(){const u=yield FormDialog(e("Add page"),()=>(0,import_jsx_runtime.jsx)(SchemaComponentOptions,{scope:t.scope,components:x({},t.components),children:(0,import_jsx_runtime.jsx)(import_antd_v5.FormLayout,{layout:"vertical",children:(0,import_jsx_runtime.jsx)(zIndexContext.Provider,{value:ICON_POPUP_Z_INDEX,children:(0,import_jsx_runtime.jsx)(SchemaComponent,{schema:{properties:{title:{title:e("Menu item title"),required:!0,"x-component":"Input","x-decorator":"FormItem"},icon:{title:e("Icon"),"x-component":"IconPicker","x-decorator":"FormItem"}}}})})})}),o).open({initialValues:{}}),d=(0,import_shared.uid)(),m=(0,import_shared.uid)(),p=(0,import_shared.uid)(),h=(0,import_shared.uid)();yield l({type:NocoBaseDesktopRouteType.flowPage,title:u.title,icon:u.icon,parentId:n==null?void 0:n.id,schemaUid:m,menuSchemaUid:d,enableTabs:!1,children:[{type:NocoBaseDesktopRouteType.tabs,schemaUid:p,tabSchemaName:h,hidden:!0}]}),a(getFlowPageMenuSchema({pageSchemaUid:m}))}),[l,a,t==null?void 0:t.components,t==null?void 0:t.scope,n==null?void 0:n.id,e,o]);return(0,import_jsx_runtime.jsx)(SchemaInitializerItem,{title:e("Modern page (v2)"),onClick:c,className:`${r} ${i}`})};function getFlowPageMenuSchema({pageSchemaUid:e}){return{type:"void","x-component":"FlowRoute","x-uid":e}}const GroupItem$1=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),{theme:o}=useGlobalTheme(),{componentCls:r,hashId:i}=useStyles$h(),n=useParentRoute(),{createRoute:l}=useNocoBaseRoutes(),a=(0,import_react2.useCallback)(()=>L(void 0,null,function*(){const c=yield FormDialog(e("Add group"),()=>(0,import_jsx_runtime.jsx)(SchemaComponentOptions,{scope:t.scope,components:x({},t.components),children:(0,import_jsx_runtime.jsx)(import_antd_v5.FormLayout,{layout:"vertical",children:(0,import_jsx_runtime.jsx)(zIndexContext.Provider,{value:ICON_POPUP_Z_INDEX,children:(0,import_jsx_runtime.jsx)(SchemaComponent,{schema:{properties:{title:{title:e("Menu item title"),"x-component":"Input","x-decorator":"FormItem",required:!0},icon:{title:e("Icon"),"x-component":"IconPicker","x-decorator":"FormItem"}}}})})})}),o).open({initialValues:{}}),{title:u,icon:d}=c,m=(0,import_shared.uid)();yield l({type:NocoBaseDesktopRouteType.group,title:u,icon:d,parentId:n==null?void 0:n.id,schemaUid:m})}),[t.components,t.scope,e,o]);return(0,import_jsx_runtime.jsx)(SchemaInitializerItem,{title:e("Group"),onClick:a,className:`${r} ${i}`})},useAttach=e=>{const t=(0,import_react2.useRef)(null);return(0,import_react2.useEffect)(()=>(t.current&&e!==t.current&&t.current.onUnmount(),t.current=e,e.onMount(),()=>{e.onUnmount()}),[e]),e},compileCache={},hasVariable=e=>/{{.*?}}/g.test(e),useCompile=({noCache:e}={noCache:!1})=>{const t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),o=(0,import_react2.useContext)(import_react.SchemaExpressionScopeContext);return(r,i)=>{let n=!1,l;if(typeof r=="string"&&r.startsWith("{{")&&(n=!0,l=r),r&&typeof r=="object"&&!(0,import_react2.isValidElement)(r)){try{l=JSON.stringify(r)}catch(a){return console.warn("Failed to stringify:",a),r}if(compileCache[l])return compileCache[l];n=hasVariable(l)}if(Array.isArray(r)){try{l=JSON.stringify(r)}catch(a){return console.warn("Failed to stringify:",a),r}if(compileCache[l])return compileCache[l];n=hasVariable(l)}if(n){const a=x(x(x({},t==null?void 0:t.scope),o),i);if(!l)return import_react.Schema.compile(r,a);try{return e?import_react.Schema.compile(r,a):(compileCache[l]=compileCache[l]||import_react.Schema.compile(r,a),compileCache[l])}catch(c){return console.log("useCompile error",r,c),import_react.Schema.compile(r,a)}}return r}},useComponent=(e,t)=>{const{components:o}=(0,import_react2.useContext)(import_react.SchemaOptionsContext);return e?typeof e!="string"?e:(0,import_lodash.get)(o,e)||t:t},LAZY_COMPONENT_KEY=Symbol("LAZY_COMPONENT_KEY");function lazy(e,...t){if(t.length===0){const o=(0,import_react2.lazy)(()=>e().then(i=>{const n=i.default;return r[LAZY_COMPONENT_KEY]=n,{default:n}})),r=i=>(0,import_jsx_runtime.jsx)(import_react2.default.Suspense,{fallback:(0,import_jsx_runtime.jsx)(import_antd.Spin,{}),children:(0,import_jsx_runtime.jsx)(o,x({},i))});return r}return t.reduce((o,r)=>{const i=(0,import_react2.lazy)(()=>e().then(n=>{const l=(0,import_lodash.get)(n,r);return o[r][LAZY_COMPONENT_KEY]=l,{default:l}}));return o[r]=n=>(0,import_jsx_runtime.jsx)(import_react2.default.Suspense,{fallback:(0,import_jsx_runtime.jsx)(import_antd.Spin,{}),children:(0,import_jsx_runtime.jsx)(i,x({},n))}),o},{})}function useLazy(e,t){const o=typeof t=="function"?t:i=>i[t],r=(0,import_react_imported_component.loadableResource)(e);if(!r.payload)throw new Promise((i,n)=>{r.loadIfNeeded(),r.resolution.then(i).catch(n)});return o(r.payload)}function addAppVersion(e,t){if(e)return e["x-app-version"]||(e["x-app-version"]=t),Object.keys(e.properties||{}).forEach(o=>{var r;addAppVersion((r=e.properties)==null?void 0:r[o],t)}),e}const name="@nocobase/client",version="2.0.39",license="Apache-2.0",main="lib/index.js",module$1="es/index.mjs",types="es/index.d.ts",dependencies={"@ahooksjs/use-url-state":"3.5.1","@ant-design/cssinjs":"^1.11.1","@ant-design/icons":"^5.6.1","@ant-design/pro-layout":"^7.22.1","@antv/g2plot":"^2.4.18","@budibase/handlebars-helpers":"0.14.0","@codemirror/lang-html":"^6.4.10","@codemirror/theme-one-dark":"^6.1.3","@ctrl/tinycolor":"^3.6.0","@dnd-kit/core":"^6.0.0","@dnd-kit/sortable":"^7.0.0","@emotion/css":"^11.7.1","@formily/antd-v5":"1.2.3","@formily/core":"^2.2.27","@formily/grid":"^2.2.27","@formily/json-schema":"^2.2.27","@formily/path":"^2.2.27","@formily/react":"^2.2.27","@formily/reactive":"^2.2.27","@formily/reactive-react":"^2.2.27","@formily/shared":"^2.2.27","@formily/validator":"^2.2.27","@nocobase/evaluators":"2.0.39","@nocobase/flow-engine":"2.0.39","@nocobase/sdk":"2.0.39","@nocobase/utils":"2.0.39","@tanstack/react-table":"^8.21.3","@types/tabulator-tables":"^6.2.6","acorn-jsx":"^5.3.2",ahooks:"^3.7.2",antd:"5.24.2","antd-mobile":"^5.41.1","antd-mobile-icons":"^0.3.0","antd-style":"3.7.1",axios:"^1.7.0","bignumber.js":"^9.1.2",classnames:"^2.3.1",codemirror:"^6.0.2",cronstrue:"^2.11.0","file-saver":"^2.0.5",filesize:"9.0.11",flat:"^5.0.2","html5-qrcode":"^2.3.8",i18next:"^22.4.9","i18next-http-backend":"^2.1.1",ignore:"^5.2.0",json5:"^2.2.3",liquidjs:"^10.0.0",lodash:"^4.17.21","lru-cache":"6.0.0","markdown-it":"14.1.0","markdown-it-highlightjs":"3.3.1",mathjs:"^15.1.0",mermaid:"9.4.3",mime:"^4.0.4","mime-match":"^1.0.2","quill-image-resize-module-react":"^3.0.0","react-beautiful-dnd":"^13.1.0","react-device-detect":"2.2.3","react-drag-listview":"^0.1.9","react-error-boundary":"^4.0.10","react-helmet":"^6.1.0","react-hotkeys-hook":"^3.4.7","react-i18next":"^11.15.1","react-iframe":"~1.8.5","react-image-lightbox":"^5.1.4","react-intersection-observer":"9.14.0","react-js-cron":"^3.1.0","react-quill":"^2.0.0","react-router-dom":"^6.30.1","react-to-print":"^2.14.7","sanitize-html":"2.13.0","tabulator-tables":"^6.3.1","use-deep-compare-effect":"^1.8.1",vditor:"^3.10.3"},peerDependencies={react:">=18.0.0","react-dom":">=18.0.0","react-is":">=18.0.0"},devDependencies={"@testing-library/react":"^14.0.0","@types/markdown-it":"14.1.1","@types/markdown-it-highlightjs":"3.3.1","@types/react-big-calendar":"^1.6.4","axios-mock-adapter":"^1.20.0",dumi:"2.2.14","dumi-theme-nocobase":"^0.2.32"},clientPkg={name,version,license,main,module:module$1,types,dependencies,peerDependencies,devDependencies};function createDesignable(e){return new Designable(e)}const generateUid=e=>{e&&(e["x-uid"]||(e["x-uid"]=(0,import_shared.uid)()),Object.keys(e.properties||{}).forEach(t=>{generateUid(e.properties[t])}))},defaultWrap=e=>e,matchSchema=(e,t)=>{if(!(!e||!t)){for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&t[o]!==(e==null?void 0:e[o]))return!1;return!0}},splitWrapSchema=(e,t)=>{if(e["x-uid"]&&e["x-uid"]===t["x-uid"])return[null,e.toJSON()];const o=e.toJSON(),r=I(x({},o),{properties:{}});let i=null;const n=(l,a)=>{Object.keys(l||{}).forEach(c=>{const u=l[c];if(u["x-uid"]===t["x-uid"]){i=l[c];return}else a.properties[c]=I(x({},u),{properties:{}}),n(u==null?void 0:u.properties,a.properties[c])})};return n(o.properties,r),[r,i]},translate=e=>e;class Designable{constructor(t){R(this,"current"),R(this,"options"),R(this,"appVersion"),R(this,"events",{}),this.options=t,this.current=t.current,this.appVersion=t.appVersion}get model(){return this.options.model}get query(){return this.options.query}loadAPIClientEvents(){const{api:t,t:o=translate}=this.options;if(!t)return;const r=i=>{if(!i)return[];const n=Object.values(i.properties).length,l=[];return i.mapProperties(a=>{a["x-component-props"]=a["x-component-props"]||{},a["x-component-props"].width=100/n,a["x-uid"]&&l.push({"x-uid":a["x-uid"],"x-component-props":a["x-component-props"]})}),i["x-uid"]&&l.length?l:[]};this.on("insertAdjacent",i=>L(this,[i],function*({onSuccess:n,current:l,position:a,schema:c,wrap:u,wrapped:d,removed:m}){var p;let h=[];if((d==null?void 0:d["x-component"])==="Grid.Col"&&(h=h.concat(r(d.parent))),(m==null?void 0:m["x-component"])==="Grid.Col"&&(h=h.concat(r(m.parent))),this.refresh(),!l["x-uid"])return;const g=yield t.request({url:`/uiSchemas:insertAdjacent/${l["x-uid"]}?position=${a}`,method:"post",data:{schema:addAppVersion(c,this.appVersion),wrap:u}});h.length&&(yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:h})),m!=null&&m["x-uid"]&&(yield t.request({url:`/uiSchemas:remove/${m["x-uid"]}`,method:"post"})),n==null||n((p=g==null?void 0:g.data)==null?void 0:p.data),import_antd.message.success(o("Saved successfully"),.2)})),this.on("patch",i=>L(this,[i],function*({schema:n}){this.refresh(),n!=null&&n["x-uid"]&&(yield t.request({url:"/uiSchemas:patch",method:"post",data:x({},n)}),import_antd.message.success(o("Saved successfully"),.2))})),this.on("initializeActionContext",i=>L(this,[i],function*({schema:n}){n!=null&&n["x-uid"]&&(yield t.request({url:"/uiSchemas:initializeActionContext",method:"post",data:x({},n)}))})),this.on("batchPatch",i=>L(this,[i],function*({schemas:n}){this.refresh(),yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:n}),import_antd.message.success(o("Saved successfully"),.2)})),this.on("remove",i=>L(this,[i],function*({removed:n}){let l=[];(n==null?void 0:n["x-component"])==="Grid.Col"&&(l=r(n.parent)),this.refresh(),n!=null&&n["x-uid"]&&(yield t.request({url:`/uiSchemas:remove/${n["x-uid"]}`,method:"post"}),l.length&&(yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:l})),import_antd.message.success(o("Saved successfully"),.2))}))}prepareProperty(t){t.type||(t.type="void"),t.name||(t.name=(0,import_shared.uid)()),this.current["x-uid"]&&generateUid(t)}on(t,o){this.events[t]||(this.events[t]=[]),this.events[t].push(o)}emit(t,...o){return L(this,null,function*(){if(!this.events[t])return;const[r,...i]=o;return Promise.all(this.events[t].map(n=>n.bind(this)(x({current:this.current},r),...i)))})}parentsIn(t){if(!t||!import_react.Schema.isSchemaInstance(t))return!1;let o=this.current;for(;o!=null&&o.parent;){if(o.parent===t)return!0;o=o.parent}return!1}refresh(t){const{refresh:o}=this.options;return o==null?void 0:o(t)}deepMerge(t){const o={title:"title",description:"description",default:"initialValue",readOnly:"readOnly",writeOnly:"editable",enum:"dataSource","x-pattern":"pattern","x-display":"display","x-validator":"validator","x-decorator":"decorator","x-component":"component","x-reactions":"reactions","x-content":"content","x-visible":"visible","x-hidden":"hidden","x-disabled":"disabled","x-editable":"editable","x-read-only":"readOnly"},r={"x-decorator-props":"decoratorProps","x-component-props":"componentProps","x-data":"data"};Object.keys(t).forEach(i=>{o[i]?(this.current[i]=t[i],this.updateModel(o[i],t[i])):r[i]?Object.keys(t[i]).forEach(n=>{(0,import_set.default)(this.current,[i,n],t[i][n]),this.updateModel([r[i],n],t[i][n])}):this.current[i]=t[i]}),this.emit("patch",{schema:t})}getSchemaAttribute(t,o){return(0,import_get.default)(this.current,t,o)}shallowMerge(t){const o={title:"title",description:"description",default:"initialValue",readOnly:"readOnly",writeOnly:"editable",enum:"dataSource","x-pattern":"pattern","x-display":"display","x-validator":"validator","x-decorator":"decorator","x-component":"component","x-reactions":"reactions","x-content":"content","x-visible":"visible","x-hidden":"hidden","x-disabled":"disabled","x-editable":"editable","x-read-only":"readOnly","x-decorator-props":"decoratorProps","x-component-props":"componentProps","x-data":"data"};Object.keys(t).forEach(r=>{this.current[r]=t[r],o[r]&&this.updateModel(o[r],t[r])}),this.emit("patch",{schema:t})}updateModel(t,o){const r=i=>{(0,import_set.default)(i,t,o)};this.model&&r(this.model),this.query&&this.query.take(r)}insertAdjacent(t,o,r={}){switch(t){case"beforeBegin":return this.insertBeforeBegin(o,r);case"afterBegin":return this.insertAfterBegin(o,r);case"beforeEnd":return this.insertBeforeEnd(o,r);case"afterEnd":return this.insertAfterEnd(o,r)}}recursiveRemoveIfNoChildren(t,o){if(!t)return;let r=t,i;const n=o==null?void 0:o.breakRemoveOn;for(;r;){if(typeof n=="function"){if(n(r))break}else if(matchSchema(r,n))break;if(Object.keys(r.properties||{}).length>0)break;r.parent&&(i=r.parent.removeProperty(r.name)),r=r.parent}return i}remove(t,o={}){const{breakRemoveOn:r,removeParentsIfNoChildren:i}=o,n=t||this.current;let l=n.parent.removeProperty(n.name);if(i){const a=this.recursiveRemoveIfNoChildren(n.parent,{breakRemoveOn:r});a&&(l=a)}return this.emit("remove",{removed:l})}removeWithoutEmit(t,o={}){const{breakRemoveOn:r,removeParentsIfNoChildren:i}=o,n=t||this.current;let l=n.parent.removeProperty(n.name);if(i){const a=this.recursiveRemoveIfNoChildren(n.parent,{breakRemoveOn:r});a&&(l=a)}return l}insertBeforeBeginOrAfterEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current)||!import_react.Schema.isSchemaInstance(t)||this.current.parent!==t.parent)return;let r=0,i=0;return this.current.parent.mapProperties((n,l,a)=>{this.current.name===l&&(i=a),t.name===l&&(r=a)}),r>i?this.insertBeforeBegin(t,o):this.insertAfterEnd(t,o)}insertBeforeBegin(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));const a={};let c=!1,u=0,d=0;this.current.parent.mapProperties((f,_)=>{_===this.current.name&&(d=u,c=!0,++u),f["x-index"]=u,++u,c&&(a[_]=f,this.current.parent.removeProperty(_))}),this.prepareProperty(t);const m=i(t),p=this.current.parent.addProperty(m.name||(0,import_shared.uid)(),m);p["x-index"]=d,p.parent=this.current.parent,this.current.parent.setProperties(a);const[h,g]=splitWrapSchema(p,t);this.emit("insertAdjacent",x({position:"beforeBegin",schema:g,wrapped:m,wrap:h},r))}insertAfterBegin(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));const a={};let c=1;this.current.mapProperties((h,g)=>{h["x-index"]=c,++c,a[g]=h}),this.current.properties={},this.prepareProperty(t);const u=i(t),d=this.current.addProperty(u.name||(0,import_shared.uid)(),u);d["x-index"]=0,d.parent=this.current,this.current.setProperties(a);const[m,p]=splitWrapSchema(d,t);this.emit("insertAdjacent",x({position:"afterBegin",schema:p,wrap:m,wrapped:u},r))}insertBeforeEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;delete t["x-index"];const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));this.prepareProperty(t);const a=i(t),c=this.current.addProperty(a.name||(0,import_shared.uid)(),a);c.parent=this.current;const[u,d]=splitWrapSchema(c,t);return this.emit("insertAdjacent",x({position:"beforeEnd",schema:d,wrap:u,wrapped:a},r))}insertAfterEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o==null?void 0:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;let a=0,c=0,u=!1;const d={};if(this.current.parent.mapProperties((f,_)=>{f["x-index"]=a,_===this.current.name&&(++a,c=a,u=!0),++a,u&&_!==this.current.name&&(d[_]=f,this.current.parent.removeProperty(_))}),import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n})),t.parent=null}else t&&(t=(0,import_cloneDeep.default)(t));this.prepareProperty(t);const m=i(t),p=this.current.parent.addProperty(m.name||(0,import_shared.uid)(),m);p.parent=this.current.parent,p["x-index"]=c,this.current.parent.setProperties(d);const[h,g]=splitWrapSchema(p,t);this.emit("insertAdjacent",x({position:"afterEnd",schema:g,wrap:h,wrapped:m},r))}}function useFindComponent(){const e=(0,import_react2.useContext)(import_react.SchemaOptionsContext),t=(0,import_react2.useMemo)(()=>(e==null?void 0:e.components)||{},[e]);return o=>{if(!o)return null;if(typeof o!="string")return o;const r=(0,import_get.default)(t,o);return r||console.error(`[nocobase]: Component "${o}" not found`),r}}function useDesignable(){const{designable:e,setDesignable:t,refresh:o,reset:r}=(0,import_react2.useContext)(SchemaComponentContext),i=(0,import_react2.useContext)(import_react.SchemaOptionsContext),n=(0,import_react2.useMemo)(()=>(i==null?void 0:i.components)||{},[i]),l=(0,import_react2.useMemo)(()=>()=>(0,import_jsx_runtime.jsx)(import_jsx_runtime.Fragment,{}),[]),a=(0,import_ahooks.useUpdate)(),c=useRefreshFieldSchema(),u=useRefreshComponent(),d=(0,import_react2.useCallback)(v=>{o==null||o(),a(),c==null||c(v),u==null||u()},[o,a,c,u]),m=(0,import_react.useField)(),p=(0,import_react.useFieldSchema)(),h=useAPIClient(),{t:g}=(0,import_react_i18next.useTranslation)(),f=(0,import_react2.useMemo)(()=>createDesignable({t:g,api:h,refresh:d,current:p,model:m,appVersion:clientPkg.version}),[g,h,d,p,m]);(0,import_react2.useEffect)(()=>{f.loadAPIClientEvents()},[f]);const{isMobileLayout:_}=useMobileLayout();return{dn:f,designable:_?!1:e,reset:r,refresh:d,setDesignable:t,DesignableBar:l,findComponent:(0,import_react2.useCallback)(v=>{var b;if(!v)return null;if(typeof v!="string")return v;const F=(0,import_get.default)(n,v);return(b=F==null?void 0:F[LAZY_COMPONENT_KEY])!=null?b:F},[import_get.default]),on:f.on.bind(f),patch:(0,import_react2.useCallback)((v,b)=>{const F=y=>{Object.keys(y).forEach(C=>{const S=y[C];C==="title"&&(m.title=S,p.title=S),C==="x-decorator-props"&&(m.decoratorProps||(m.decoratorProps={}),p["x-decorator-props"]||(p["x-decorator-props"]={}),Object.keys(S).forEach(P=>{m.decoratorProps[P]=S[P],p["x-decorator-props"][P]=S[P]})),C==="x-component-props"&&(m.componentProps||(m.componentProps={}),p["x-component-props"]||(p["x-component-props"]={}),Object.keys(S).forEach(P=>{m.componentProps[P]=S[P],p["x-component-props"][P]=S[P]}))})};if(typeof v=="string"){const y={};return(0,import_set.default)(y,v,b),F(y)}F(v),d()},[f]),shallowMerge:(0,import_react2.useCallback)(v=>{f.shallowMerge(v)},[f]),deepMerge:(0,import_react2.useCallback)(v=>{f.deepMerge(v)},[f]),remove:(0,import_react2.useCallback)((v,b)=>{f.remove(v,b)},[f]),insertAdjacent:(0,import_react2.useCallback)((v,b,F)=>{f.insertAdjacent(v,b,F)},[f]),insertBeforeBegin:(0,import_react2.useCallback)(v=>{f.insertBeforeBegin(v)},[f]),insertAfterBegin:(0,import_react2.useCallback)(v=>{f.insertAfterBegin(v)},[f]),insertBeforeEnd:(0,import_react2.useCallback)(v=>{f.insertBeforeEnd(v)},[f]),insertAfterEnd:(0,import_react2.useCallback)(v=>{f.insertAfterEnd(v)},[f])}}const DefaultSchemaToolbar=()=>null;DefaultSchemaToolbar.isNullComponent=!0;const useDesigner=()=>{const{designable:e}=useDesignable(),t=(0,import_react.useFieldSchema)(),o=(0,import_react2.useMemo)(()=>t["x-designer"]||t["x-toolbar"]?t["x-designer"]||t["x-toolbar"]:t["x-settings"]?SchemaToolbar:DefaultSchemaToolbar,[t]),r=useComponent(o);return e&&r||DefaultSchemaToolbar},useFieldProps$1=e=>{const t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),o=(0,import_react2.useContext)(import_react.SchemaExpressionScopeContext),r=(0,import_react2.useRef)();return r.current=o,e.toFieldProps(I(x({},t),{get scope(){return x(x({},t.scope),r.current)}}))};function useSchemaComponentContext(){return(0,import_react2.useContext)(SchemaComponentContext)}const useFieldComponentOptions=()=>{var e;const{getCollectionJoinField:t,getCollection:o}=useCollectionManager_deprecated(),r=(0,import_react.useFieldSchema)(),{getField:i}=useCollection_deprecated(),n=i(r.name)||t(r["x-collection-field"]),{t:l}=(0,import_react_i18next.useTranslation)(),{label:a}=((e=r["x-component-props"])==null?void 0:e.fieldNames)||{};return(0,import_react2.useMemo)(()=>{if(!n||!(n!=null&&n.interface)||!["o2o","oho","obo","o2m","linkTo","m2o","m2m"].includes(n.interface))return;const c=o(n.target);if((c==null?void 0:c.template)==="file")return[{label:l("Record picker"),value:"CollectionField"},{label:l("Select"),value:"AssociationSelect"}];switch(n.interface){case"o2m":return[{label:l("Record picker"),value:"CollectionField"},{label:l("Subtable"),value:"TableField"},{label:l("Select"),value:"AssociationSelect"}];case"m2o":case"m2m":case"linkTo":return[{label:l("Record picker"),value:"CollectionField"},{label:l("Select"),value:"AssociationSelect"}];default:return[{label:l("Record picker"),value:"CollectionField"},{label:l("Subform"),value:"FormField"},{label:l("Select"),value:"AssociationSelect"}]}},[l,n==null?void 0:n.interface,a])},useFieldTitle=()=>{var e;const t=(0,import_react.useField)(),o=(0,import_react.useFieldSchema)(),r=useCollection(),i=useCollectionManager(),n=(r==null?void 0:r.getField(o.name))||(i==null?void 0:i.getCollectionField(o["x-collection-field"])),l=useCompile();(0,import_react2.useEffect)(()=>{var a;t!=null&&t.title||(t.title=l((a=n==null?void 0:n.uiSchema)==null?void 0:a.title))},[(e=n==null?void 0:n.uiSchema)==null?void 0:e.title])},useDef$4=()=>({}),useProps=(e={})=>{const t=e,{useProps:o=useDef$4}=t,r=te(t,["useProps"]);let i=o;typeof o!="function"&&(i=useDef$4);const n=i();return x(x({},r),n)};function useParsedFilter({filterOption:e,onFilterChange:t}){const{parseFilter:o,findVariable:r}=useParseDataScopeFilter(),i=JSON.stringify(e),n=(0,import_react2.useRef)(e),l=(0,import_react2.useRef)(t),[a,c]=(0,import_react2.useState)({}),[u,d]=(0,import_react2.useState)(()=>e?null:i),m=!!e&&u!==i;return n.current=e,l.current=t,(0,import_react2.useEffect)(()=>{const p=n.current;if(!p){c({}),d(i);return}let h=!1;const g=()=>L(this,null,function*(){var v;const b=yield o(p);h||(c(b),d(i),(v=l.current)==null||v.call(l,b))});g();const f=import_lodash.default.debounce(g,DEBOUNCE_WAIT),_=(0,import_reactive.reaction)(()=>(0,import_client.flatten)(p,{breakOn({key:v}){return v.startsWith("$")&&v!=="$and"&&v!=="$or"},transformValue(v){if(!isVariable$1(v))return v;const b=getVariableName(v),F=r(b);let y=null;const C=getPath(v).split(".");return C.forEach((S,P)=>{const j=C.slice(0,P+1).join("."),A=(0,import_client.getValuesByPath)({[b]:(F==null?void 0:F.ctx)||{}},j);import_lodash.default.isEmpty(A)||(y=A)}),y}}),f,{equals:import_lodash.default.isEqual});return()=>{h=!0,f.cancel(),_()}},[i,r,o]),{filter:a,parseVariableLoading:m}}const useParentRecordCommon=e=>{const t=useCollectionRecordData();if(e)return t},useTableBlockDecoratorProps=e=>{var t;const{params:o,parseVariableLoading:r}=useTableBlockParams(e),i=useParentRecordCommon(e.association),n=(t=useDataSourceManager().getDataSource(e.dataSource))==null?void 0:t.collectionManager.getCollection(e.collection);return{params:o,parentRecord:i,parseVariableLoading:r,rowKey:(n==null?void 0:n.filterTargetKey)||"id"}};function useTableBlockParams(e){var t;const o=(0,import_react.useFieldSchema)(),{filter:r,parseVariableLoading:i}=useParsedFilter({filterOption:(t=e.params)==null?void 0:t.filter});return{params:(0,import_react2.useMemo)(()=>{const n=e.params||{},{dragSortBy:l}=(o==null?void 0:o["x-decorator-props"])||{};return e.dragSort&&l&&(n.sort=l),I(x({},n),{filter:r})},[o,r,e.dragSort,e.params]),parseVariableLoading:i}}const key="__isNewRecord__",isNewRecord=e=>(0,import_reactive.untracked)(()=>!!(e!=null&&e[key])),markRecordAsNew=e=>{if(!(0,import_lodash.isObject)(e))throw new Error("markRecordAsNew: record must be an object");return e[key]=!0,e},useDefaultLoading=()=>{var e;return!!((e=useDataBlockRequest())!=null&&e.loading)},withSkeletonComponent=(e,t)=>{const{useLoading:o=useDefaultLoading,displayName:r,SkeletonComponent:i=import_antd.Skeleton}=t||{},n=import_react2.default.memo(l=>{const a=o(),c=(0,import_react2.useRef)(!1),u=(0,import_react2.useDeferredValue)(a);return!c.current&&u?(0,import_jsx_runtime.jsx)(i,{}):(c.current=!0,(0,import_jsx_runtime.jsx)(e,x({},l)))});return n.displayName=r||`${e.displayName}(withSkeletonComponent)`||`${e.name}(withSkeletonComponent)`,n},getActionValue=(e,t)=>{const o=r=>(r==null?void 0:r.mode)==="constant"?r.value:null;switch(!0){case[ActionType.Color,ActionType.BackgroundColor,ActionType.TextAlign,ActionType.FontSize,ActionType.FontWeight,ActionType.FontStyle].includes(e):return o(t);default:return null}},getSatisfiedActions=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield Promise.all(o.filter(l=>!l.disabled).map(l=>L(void 0,null,function*(){return(yield conditionAnalyses({ruleGroup:l.condition,variables:r,localVariables:i,conditionType:l.conditionType},n))?l:null})))).filter(Boolean).map(l=>l.actions).flat()}),getSatisfiedValues=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield getSatisfiedActions({rules:o,variables:r,localVariables:i},n)).map(l=>I(x({},l),{value:getActionValue(l.operator,l.value)}))}),getSatisfiedValueMap=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield getSatisfiedValues({rules:o,variables:r,localVariables:i},n)).reduce((l,a)=>I(x({},l),{[a.operator]:a.value}),{})});function useSatisfiedActionValues({formValues:e,category:t="default",rules:o,schema:r,form:i}){const[n,l]=(0,import_react2.useState)({}),a=(0,import_react.useFieldSchema)(),c=useVariables$1(),u=useLocalVariables$1({currentForm:{values:e}}),d=r??a,m=o??(d[LinkageRuleDataKeyMap[t]]||(d==null?void 0:d.parent[LinkageRuleDataKeyMap[t]])),p=useApp(),h=(0,import_react2.useCallback)(()=>{m&&e&&getSatisfiedValueMap({rules:m,variables:c,localVariables:u},p.jsonLogic).then(g=>{(0,import_lodash.isEmpty)(g)?l({}):l(g)}).catch(g=>{throw new Error(g.message)})},[c,u,m,e]);return(0,import_react2.useEffect)(()=>{if(h(),i){const g=(0,import_shared.uid)();return i.addEffects(g,()=>{(0,import_core.onFormValuesChange)(()=>{h()})}),()=>{i.removeEffects(g)}}},[i,h,e]),{valueMap:n}}const GetStyleRules=import_react2.default.memo(({record:e,schema:t,onStyleChange:o})=>{const{valueMap:r}=useSatisfiedActionValues({formValues:e,category:"style",schema:t});return(0,import_react2.useEffect)(()=>{o(r)},[o,r]),null});GetStyleRules.displayName="GetStyleRules";const opacityStyle={opacity:.5},containerStyle={position:"relative"},spinStyle={display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:0,right:0,height:"100%",maxHeight:400,zIndex:1e3},displayNone$3={display:"none"},HighPerformanceSpin=import_react2.default.memo(e=>(0,import_jsx_runtime.jsxs)("div",{style:containerStyle,children:[(0,import_jsx_runtime.jsx)(import_antd.Spin,I(x({},import_lodash.default.omit(e,"children")),{style:e.spinning?spinStyle:displayNone$3})),(0,import_jsx_runtime.jsx)("div",{style:e.spinning?opacityStyle:null,children:e.children})]}));HighPerformanceSpin.displayName="HighPerformanceSpin";var FilterBlockType=(e=>(e[e.FORM=0]="FORM",e[e.TABLE=1]="TABLE",e[e.TREE=2]="TREE",e[e.COLLAPSE=3]="COLLAPSE",e))(FilterBlockType||{});const mergeFilter=(e,t="$and")=>{const o=e.filter(r=>{if(r&&typeof r=="object"&&!Array.isArray(r))return Object.values(r).filter(i=>i!==void 0).length});return o.length===0?{}:o.length===1?o[0]:{[t]:o}},getSupportFieldsByAssociation=(e,t)=>{var o;return(o=t.associatedFields)==null?void 0:o.filter(r=>e==null?void 0:e.some(i=>i===r.target))},getSupportFieldsByForeignKey=(e,t)=>{var o;return(o=t.foreignKeyFields)==null?void 0:o.filter(r=>e.fields.some(i=>i.type!=="belongsTo"&&i.foreignKey===r.name&&i.target===r.collectionName))},useSupportedBlocks=e=>{const{getDataBlocks:t}=useFilterBlock(),o=(0,import_react.useFieldSchema)(),r=useCollection(),{getAllCollectionsInheritChain:i}=useAllCollectionsInheritChainGetter();if(e===0||e===3)return t().filter(n=>isSameCollection(n.collection,r));if(e===1||e===2)return t().filter(n=>{var l,a;return o["x-uid"]!==n.uid&&(isSameCollection(n.collection,r)||((l=getSupportFieldsByAssociation(i(r.name,r.dataSource),n))==null?void 0:l.length)||((a=getSupportFieldsByForeignKey(r,n))==null?void 0:a.length))})},transformToFilter=(e,t,o,r)=>(e=(0,import_client.flatten)(e,{breakOn({value:i,path:n}){if(["$match","$notMatch","$anyOf","$noneOf","$childIn","$childNotIn","$dateBetween","$in","$notIn"].includes(t[n]))return!0;const l=o(`${r}.${n}`);if(["datetime","datetimeNoTz","date","unixTimestamp","createdAt","updatedAt"].includes(l==null?void 0:l.interface))return!0;if(l!=null&&l.target){if(Array.isArray(i))return!0;const a=l.targetKey||"id";if(i&&i[a]!=null)return!0}return!1}}),{$and:Object.keys(e).map(i=>{let n=import_lodash.default.get(e,i);const l=o(`${r}.${i}`);return l!=null&&l.target&&["hasOne","hasMany","belongsTo","belongsToMany","belongsToArray"].includes(l.type)&&(n=(0,import_client.getValuesByPath)(n,l.targetKey||"id"),i=`${i}.${l.targetKey||"id"}`,(l==null?void 0:l.interface)==="chinaRegion"&&(n=import_lodash.default.last(n))),!n&&n!==0&&n!==!1?null:{[i]:{[t[i]||"$eq"]:n}}}).filter(Boolean)}),useAssociatedFields=()=>{var e;return((e=useCollection())==null?void 0:e.fields.filter(t=>isAssocField(t)))||[]},isAssocField=e=>["o2o","oho","obo","m2o","createdBy","updatedBy","o2m","m2m","linkTo","chinaRegion","mbm"].includes(e==null?void 0:e.interface),isSameCollection=(e,t)=>e.name===t.name&&e.dataSource===t.dataSource,useFilterAPI=()=>{const e=(0,import_react.useFieldSchema)(),{getDataBlocks:t}=useFilterBlock(),{targets:o,uid:r}=findFilterTargets(e),i=t(),[n,l]=(0,import_react2.useState)(()=>o&&o.some(u=>i.some(d=>d.uid===u.uid))),a=Object.keys(o||{});(0,import_react2.useEffect)(()=>{l(o&&o.some(u=>i.some(d=>d.uid===u.uid)))},[a.length,o,i]);const c=(0,import_react2.useCallback)((u,d="id",m="$eq")=>{const p=i.find(h=>h.uid===e.parent["x-uid"]);i.forEach(h=>{var g,f,_,v;let b=d;const F=o.find(P=>P.uid===h.uid);if(!F)return;import_lodash.default.isFunction(u)&&(u=u(F,h,getSourceKey$1(p,F.field))),import_lodash.default.isFunction(d)&&(b=d(F,h)),import_lodash.default.isFunction(m)&&(m=m(F));const y=((g=h.service.params)==null?void 0:g[0])||{},C=((_=(f=h.service.params)==null?void 0:f[1])==null?void 0:_.filters)||{};if(u!=null)C[r]={$and:[{[b]:{[m]:u}}]};else if((v=h.clearSelection)==null||v.call(h),delete C[r],h.dataLoadingMode==="manual")return h.clearData();const S=mergeFilter([...Object.values(C).map(P=>removeNullCondition(P)),h.defaultFilter]);h.doFilter(I(x({},y),{page:1,filter:S}),{filters:C})})},[i,o,r,e]);return{isConnected:n,doFilter:c}},isInFilterFormBlock=e=>{for(;e;){if(e["x-filter-targets"])return e["x-decorator"]==="FilterFormBlockProvider";e=e.parent}return!1};function getSourceKey$1(e,t){var o,r,i;const n=(o=e==null?void 0:e.associatedFields)==null?void 0:o.find(l=>l.foreignKey===t);return(n==null?void 0:n.sourceKey)||((i=(r=t==null?void 0:t.split)==null?void 0:r.call(t,"."))==null?void 0:i[1])}const AssociationFieldContext=(0,import_react2.createContext)({});AssociationFieldContext.displayName="AssociationFieldContext";const useInsertSchema$1=e=>{const t=(0,import_react.useFieldSchema)(),{insertAfterBegin:o}=useDesignable(),{isMobileLayout:r}=useMobileLayout();return(0,import_react2.useCallback)(i=>{r||t.reduceProperties((n,l)=>l["x-component"]==="AssociationField."+e?l:n,null)||o((0,import_cloneDeep.default)(i))},[e,t,o,r])};function useAssociationFieldContext(){return(0,import_react2.useContext)(AssociationFieldContext)}function useServiceOptions$1(e){var t,o,r,i,n,l,a,c,u,d;const{action:m="list",service:p,useOriginalFilter:h}=e,g=(0,import_react.useFieldSchema)(),f=(0,import_react.useField)(),{getField:_}=useCollection_deprecated(),{getCollectionJoinField:v}=useCollectionManager_deprecated(),b=useRecord(),{isNew:F}=useCollectionRecord()||{},y=((0,import_lodash.isString)((r=(o=(t=g==null?void 0:g["x-component-props"])==null?void 0:t.service)==null?void 0:o.params)==null?void 0:r.filter)?(l=(n=(i=f.componentProps)==null?void 0:i.service)==null?void 0:n.params)==null?void 0:l.filter:(u=(c=(a=g==null?void 0:g["x-component-props"])==null?void 0:a.service)==null?void 0:c.params)==null?void 0:u.filter)||((d=p==null?void 0:p.params)==null?void 0:d.filter),{filter:C}=useParsedFilter({filterOption:y,onFilterChange:()=>{F&&f.reset()}}),S=(0,import_react2.useMemo)(()=>_(g.name)||v(g==null?void 0:g["x-collection-field"]),[g]),P=b==null?void 0:b[S==null?void 0:S.sourceKey],j=(0,import_react2.useMemo)(()=>{const A=["oho","o2m"].includes(S==null?void 0:S.interface);return mergeFilter([mergeFilter([A&&!isInFilterFormBlock(g)&&S!=null&&S.foreignKey&&!h?{[S.foreignKey]:{$is:null}}:null,C]),A&&P!==void 0&&P!==null&&!isInFilterFormBlock(g)&&S!=null&&S.foreignKey&&!h?{[S.foreignKey]:{$eq:P}}:null],"$or")},[S==null?void 0:S.interface,S==null?void 0:S.foreignKey,g,C,P,h]);return(0,import_react2.useMemo)(()=>I(x({resource:S==null?void 0:S.target,action:m},p),{params:I(x({},p==null?void 0:p.params),{filter:j})}),[S==null?void 0:S.target,m,j,p])}const useFieldNames$1=(e={})=>{var t,o,r,i,n;const l=(0,import_react.useFieldSchema)(),a=((i=(r=(o=(t=l["x-component-props"])==null?void 0:t.field)==null?void 0:o.uiSchema)==null?void 0:r["x-component-props"])==null?void 0:i.fieldNames)||((n=l["x-component-props"])==null?void 0:n.fieldNames)||e.fieldNames;return x({label:"label",value:"value"},a)},SubFormContext=(0,import_react2.createContext)(null);SubFormContext.displayName="SubFormContext";const SubFormProvider=e=>{const t=(0,import_react2.useContext)(SubFormContext),{value:o,collection:r,fieldSchema:i,parent:n,skip:l}=e.value,a=(0,import_react2.useMemo)(()=>import_lodash.default.omitBy({value:o,collection:r,fieldSchema:i,skip:l,parent:n||(t!=null&&t.skip?t.parent:t)},import_lodash.default.isUndefined),[o,r,i,l,n,t]);return(0,import_jsx_runtime.jsx)(SubFormContext.Provider,{value:a,children:e.children})},useSubFormValue=()=>{const{value:e,collection:t,fieldSchema:o,parent:r}=(0,import_react2.useContext)(SubFormContext)||{};return{formValue:e,collection:t,fieldSchema:o,parent:r}},TableUidContext=(0,import_react2.createContext)(null),useColumnSettings=e=>{const{t}=(0,import_react_i18next.useTranslation)(),o=(0,import_react2.useContext)(TableUidContext),r=`nocobase_table_column_settings_${o}`,i=(0,import_react2.useCallback)(()=>{try{const a=localStorage.getItem(r);return a?JSON.parse(a):null}catch(a){return console.warn("Failed to parse table column settings from localStorage:",a),null}},[r]),n=(0,import_react2.useCallback)(a=>{try{const c=JSON.stringify(a);localStorage.setItem(r,c);const u=new CustomEvent("nocobase-table-settings-changed",{detail:{key:r,tableId:o,settings:a}});window.dispatchEvent(u)}catch(c){console.warn("Failed to save table column settings to localStorage:",c),import_antd.message.error(t("Failed to save table settings"))}},[r,o,t]),l=(0,import_react2.useCallback)(()=>{try{localStorage.removeItem(r);const a=new CustomEvent("nocobase-table-settings-changed",{detail:{key:r,tableId:o,settings:null}});window.dispatchEvent(a)}catch(a){console.warn("Failed to clear table column settings from localStorage:",a),import_antd.message.error(t("Failed to clear table settings"))}},[r,o,t]);return{getSettings:i,saveSettings:n,clearSettings:l}},useTableColumnIntegration=(e,t=!0)=>{const o=(0,import_react2.useContext)(TableUidContext),{getSettings:r}=useColumnSettings(),[i,n]=(0,import_react2.useState)(0);(0,import_react2.useEffect)(()=>{const a=c=>{const{key:u,tableId:d}=c.detail;(u.includes(o)||d===o)&&n(m=>m+1)};return window.addEventListener("nocobase-table-settings-changed",a),()=>{window.removeEventListener("nocobase-table-settings-changed",a)}},[o]);const l=(0,import_react2.useMemo)(()=>r(),[r,i]);return{columns:(0,import_react2.useMemo)(()=>{if(!t||!l||l.length===0)return e;const a=new Map;l.forEach(p=>{a.set(p.key,p)});const c=e.map(p=>{const h=a.get(p.key);if(h){const g=p.columnHidden||!h.visible,f=h.width||p.width,_=h.fixed||p.fixed;return I(x({},p),{columnHidden:g,fixed:_,width:f,_orderIndex:h.order})}return p}),u=[],d=[];c.forEach(p=>{p._orderIndex!==void 0?u.push(p):d.push(p)}),u.sort((p,h)=>(p._orderIndex||0)-(h._orderIndex||0));const m=[...u,...d];return m.forEach(p=>{delete p._orderIndex}),m},[e,l])}},TableSkeleton=({rows:e=5,columns:t=6})=>{const{token:o}=useToken$1(),r=o.controlHeight*2.06,i=o.controlHeight*1.75,n=(0,import_react2.useMemo)(()=>import_css.css`
65
+ `,items:a},n))})},SchemaInitializerSubMenu=e=>{var t;const o=e,{children:r,items:i,title:n,name:l,onOpenChange:a,icon:c}=o,u=te(o,["children","items","title","name","onOpenChange","icon"]),d=useCompile(),m=useSchemaInitializerItem(),p=(0,import_react2.useMemo)(()=>l||(m==null?void 0:m.name)||(0,import_shared.uid)(),[l,m]),h=(t=i||r)==null?void 0:t.filter(_=>_.useVisible?_.useVisible():!0),g=useSchemaInitializerMenuItems(h,l),f=(0,import_react2.useMemo)(()=>[I(x({},u),{key:p,label:d(n),icon:typeof c=="string"?(0,import_jsx_runtime.jsx)(import_icons.default,{type:c}):c,children:g})],[g,d,c,p,u,n]);return(0,import_jsx_runtime.jsx)(SchemaInitializerMenu,{onOpenChange:a,items:f})},SchemaInitializerSubMenuInternal=()=>{const e=useSchemaInitializerItem();return(0,import_jsx_runtime.jsx)(SchemaInitializerSubMenu,x({},e))},useAriaAttributeOfMenuItem=()=>{const{isInMenu:e}=useSchemaInitializerSubMenuContext();return{attribute:(0,import_react2.useMemo)(()=>e?{}:{role:"menuitem"},[e])}},{Paragraph:Paragraph$1,Text:Text$2}=import_antd.Typography,ErrorFallbackModal=e=>{const[t,o]=import_react2.default.useState(!1),r=(0,import_jsx_runtime.jsx)(Paragraph$1,{style:{display:"flex",marginBottom:0},copyable:{text:e.error.message},children:(0,import_jsx_runtime.jsxs)(Text$2,{type:"danger",style:{whiteSpace:"nowrap",textOverflow:"ellipsis",overflow:"hidden",display:"inline-block",maxWidth:"200px"},children:["Error: ",e.error.message]})});return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)("div",{onMouseOver:()=>o(!0),children:e.children||r}),(0,import_jsx_runtime.jsx)(import_antd.Modal,{zIndex:1e4,open:t,footer:null,onCancel:()=>o(!1),width:"60%",children:(0,import_jsx_runtime.jsx)(ErrorFallback,x({},e))})]})},{Paragraph,Text:Text$1,Link}=import_antd.Typography,useDownloadLogs=(e,t={})=>{const o=useLocationNoUpdate(),[r,i]=import_react2.default.useState(!1),n=useAPIClient();return{loading:r,download:()=>L(void 0,null,function*(){i(!0);try{const l=yield n.request({url:"logger:collect",method:"post",responseType:"blob",data:x({error:{message:e.message,stack:e.stack},location:o},t)}),a=window.URL.createObjectURL(new Blob([l.data],{type:"application/gzip"})),c=document.createElement("a");c.setAttribute("href",a),c.setAttribute("download","logs.tar.gz"),c.click(),c.remove()}catch(l){console.log(l)}i(!1)})}},ErrorFallback=({error:e})=>{const t=(0,import_react.useFieldSchema)(),{t:o}=(0,import_react_i18next.useTranslation)(),{loading:r,download:i}=useDownloadLogs(e,{schema:t}),n=(0,import_jsx_runtime.jsxs)(import_react_i18next.Trans,{children:["This is likely a NocoBase internals bug. Please open an issue at ",(0,import_jsx_runtime.jsx)(Link,{href:"https://github.com/nocobase/nocobase/issues",target:"_blank",children:"here"})]});return(0,import_jsx_runtime.jsx)("div",{style:{backgroundColor:"white"},children:(0,import_jsx_runtime.jsx)(import_antd.Result,{style:{maxWidth:"60vw",margin:"auto"},status:"error",title:o("Render Failed"),subTitle:n,extra:[(0,import_jsx_runtime.jsx)(import_antd.Button,{type:"primary",href:"https://github.com/nocobase/nocobase/issues",target:"_blank",children:o("Feedback")},"feedback"),(0,import_jsx_runtime.jsx)(import_antd.Button,{loading:r,onClick:i,children:o("Download logs")},"log")],children:(0,import_jsx_runtime.jsx)(Paragraph,{copyable:{text:e.stack},children:(0,import_jsx_runtime.jsx)(Text$1,{type:"danger",style:{whiteSpace:"pre-line",textAlign:"center"},children:e.stack})})})})};ErrorFallback.Modal=ErrorFallbackModal;const AppNotFound=()=>{const e=(0,import_react_router_dom.useNavigate)(),{t}=(0,import_react_i18next.useTranslation)();return(0,import_jsx_runtime.jsx)(import_antd.Result,{status:"404",title:"404",subTitle:t("Sorry, the page you visited does not exist."),extra:(0,import_jsx_runtime.jsx)(import_antd.Button,{onClick:()=>e("/",{replace:!0}),type:"primary",children:"Back Home"})})};class Plugin{constructor(t,o){this.options=t,this.app=o,this.options=t,this.app=o}get pluginManager(){return this.app.pluginManager}get context(){return this.app.context}get flowEngine(){return this.app.flowEngine}get engine(){return this.app.flowEngine}get ai(){return this.app.aiManager}get pm(){return this.app.pm}get router(){return this.app.router}get pluginSettingsManager(){return this.app.pluginSettingsManager}get pluginSettingsRouter(){return this.app.pluginSettingsManager}get schemaInitializerManager(){return this.app.schemaInitializerManager}get schemaSettingsManager(){return this.app.schemaSettingsManager}get dataSourceManager(){return this.app.dataSourceManager}afterAdd(){return L(this,null,function*(){})}beforeLoad(){return L(this,null,function*(){})}load(){return L(this,null,function*(){})}t(t,o={}){var r;return this.app.i18n.t(t,x({ns:(r=this.options)==null?void 0:r.packageName},o))}}const titleWrapperStyle={display:"flex",alignItems:"center",gap:4},withTooltipComponent=e=>t=>{const{tooltip:o}=t;return o?(0,import_jsx_runtime.jsxs)("div",{style:titleWrapperStyle,children:[(0,import_jsx_runtime.jsx)(e,x({},t)),(0,import_jsx_runtime.jsx)(import_antd.Tooltip,{title:o,children:(0,import_jsx_runtime.jsx)(import_icons.QuestionCircleOutlined,{style:{zIndex:1}})})]}):(0,import_jsx_runtime.jsx)(e,x({},t))},{evaluate}=import_client4.evaluators.get("formula.js"),useEvaluatedExpression=e=>{const t=useVariables$1(),o=useLocalVariables$1(),[r,i]=(0,import_react2.useState)();return(0,import_react2.useEffect)(()=>{L(void 0,null,function*(){if(e==null||e===""){i(void 0);return}const{exp:n,scope:l}=yield replaceVariables(e,{variables:t,localVariables:o});try{const a=evaluate(n,x({now:()=>new Date().toString()},l));i(a)}catch(a){console.error(a)}})},[t.parseVariable,e,o]),r};class SchemaInitializer{constructor(t){R(this,"options"),R(this,"name"),this.options=Object.assign({items:[]},t),this.name=t.name}get items(){return this.options.items}add(t,o){const r=t.split("."),i=r[r.length-1],n=I(x({},o),{name:i}),l=(u,d)=>{const m=this.items.findIndex(p=>p.name===u);m===-1?this.items.push(d):this.items[m]=d};if(r.length===1){l(i,n);return}const a=r.slice(0,-1).join("."),c=this.get(a);if(c){c.children||(c.children=[]);const u=t.replace(`${c.name}.`,""),d=c.children.findIndex(m=>m.name===u);d===-1?c.children.push(n):c.children[d]=n}else l(i,n)}get(t){var o;if(!t)return;const r=t.split(".");let i={children:this.items};for(let n=0;n<r.length;n++){const l=r[n],a=(o=i.children)==null?void 0:o.find(c=>c.name===l);if(a&&(i=a),n===r.length-1)return a}}remove(t){const o=t.split(".");if(o.length===1){const i=this.items.findIndex(n=>n.name===o[0]);i!==-1&&this.items.splice(i,1);return}const r=this.get(o.slice(0,-1).join("."));if(r&&r.children){const i=o[o.length-1],n=r.children.findIndex(l=>l.name===i);n!==-1&&r.children.splice(n,1)}}}var NocoBaseDesktopRouteType=(e=>(e.group="group",e.page="page",e.flowRoute="flowRoute",e.link="link",e.tabs="tabs",e.flowPage="flowPage",e))(NocoBaseDesktopRouteType||{});const useStyles$h=genStyleHook("nb-menu-item",e=>{const{componentCls:t}=e;return{[t]:{paddingLeft:`${e.padding}px !important`,paddingRight:`${e.padding}px !important`}}}),useInsertFlowPageSchema=()=>{const e=useAPIClient();return(0,import_react2.useCallback)(t=>L(void 0,null,function*(){yield e.request({method:"POST",url:"/uiSchemas:insert",data:t})}),[e])},FlowPageMenuItem=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),{theme:o}=useGlobalTheme(),{componentCls:r,hashId:i}=useStyles$h(),n=useParentRoute(),{createRoute:l}=useNocoBaseRoutes(),a=useInsertFlowPageSchema(),c=(0,import_react2.useCallback)(()=>L(void 0,null,function*(){const u=yield FormDialog(e("Add page"),()=>(0,import_jsx_runtime.jsx)(SchemaComponentOptions,{scope:t.scope,components:x({},t.components),children:(0,import_jsx_runtime.jsx)(import_antd_v5.FormLayout,{layout:"vertical",children:(0,import_jsx_runtime.jsx)(zIndexContext.Provider,{value:ICON_POPUP_Z_INDEX,children:(0,import_jsx_runtime.jsx)(SchemaComponent,{schema:{properties:{title:{title:e("Menu item title"),required:!0,"x-component":"Input","x-decorator":"FormItem"},icon:{title:e("Icon"),"x-component":"IconPicker","x-decorator":"FormItem"}}}})})})}),o).open({initialValues:{}}),d=(0,import_shared.uid)(),m=(0,import_shared.uid)(),p=(0,import_shared.uid)(),h=(0,import_shared.uid)();yield l({type:NocoBaseDesktopRouteType.flowPage,title:u.title,icon:u.icon,parentId:n==null?void 0:n.id,schemaUid:m,menuSchemaUid:d,enableTabs:!1,children:[{type:NocoBaseDesktopRouteType.tabs,schemaUid:p,tabSchemaName:h,hidden:!0}]}),a(getFlowPageMenuSchema({pageSchemaUid:m}))}),[l,a,t==null?void 0:t.components,t==null?void 0:t.scope,n==null?void 0:n.id,e,o]);return(0,import_jsx_runtime.jsx)(SchemaInitializerItem,{title:e("Modern page (v2)"),onClick:c,className:`${r} ${i}`})};function getFlowPageMenuSchema({pageSchemaUid:e}){return{type:"void","x-component":"FlowRoute","x-uid":e}}const GroupItem$1=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),{theme:o}=useGlobalTheme(),{componentCls:r,hashId:i}=useStyles$h(),n=useParentRoute(),{createRoute:l}=useNocoBaseRoutes(),a=(0,import_react2.useCallback)(()=>L(void 0,null,function*(){const c=yield FormDialog(e("Add group"),()=>(0,import_jsx_runtime.jsx)(SchemaComponentOptions,{scope:t.scope,components:x({},t.components),children:(0,import_jsx_runtime.jsx)(import_antd_v5.FormLayout,{layout:"vertical",children:(0,import_jsx_runtime.jsx)(zIndexContext.Provider,{value:ICON_POPUP_Z_INDEX,children:(0,import_jsx_runtime.jsx)(SchemaComponent,{schema:{properties:{title:{title:e("Menu item title"),"x-component":"Input","x-decorator":"FormItem",required:!0},icon:{title:e("Icon"),"x-component":"IconPicker","x-decorator":"FormItem"}}}})})})}),o).open({initialValues:{}}),{title:u,icon:d}=c,m=(0,import_shared.uid)();yield l({type:NocoBaseDesktopRouteType.group,title:u,icon:d,parentId:n==null?void 0:n.id,schemaUid:m})}),[t.components,t.scope,e,o]);return(0,import_jsx_runtime.jsx)(SchemaInitializerItem,{title:e("Group"),onClick:a,className:`${r} ${i}`})},useAttach=e=>{const t=(0,import_react2.useRef)(null);return(0,import_react2.useEffect)(()=>(t.current&&e!==t.current&&t.current.onUnmount(),t.current=e,e.onMount(),()=>{e.onUnmount()}),[e]),e},compileCache={},hasVariable=e=>/{{.*?}}/g.test(e),useCompile=({noCache:e}={noCache:!1})=>{const t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),o=(0,import_react2.useContext)(import_react.SchemaExpressionScopeContext);return(r,i)=>{let n=!1,l;if(typeof r=="string"&&r.startsWith("{{")&&(n=!0,l=r),r&&typeof r=="object"&&!(0,import_react2.isValidElement)(r)){try{l=JSON.stringify(r)}catch(a){return console.warn("Failed to stringify:",a),r}if(compileCache[l])return compileCache[l];n=hasVariable(l)}if(Array.isArray(r)){try{l=JSON.stringify(r)}catch(a){return console.warn("Failed to stringify:",a),r}if(compileCache[l])return compileCache[l];n=hasVariable(l)}if(n){const a=x(x(x({},t==null?void 0:t.scope),o),i);if(!l)return import_react.Schema.compile(r,a);try{return e?import_react.Schema.compile(r,a):(compileCache[l]=compileCache[l]||import_react.Schema.compile(r,a),compileCache[l])}catch(c){return console.log("useCompile error",r,c),import_react.Schema.compile(r,a)}}return r}},useComponent=(e,t)=>{const{components:o}=(0,import_react2.useContext)(import_react.SchemaOptionsContext);return e?typeof e!="string"?e:(0,import_lodash.get)(o,e)||t:t},LAZY_COMPONENT_KEY=Symbol("LAZY_COMPONENT_KEY");function lazy(e,...t){if(t.length===0){const o=(0,import_react2.lazy)(()=>e().then(i=>{const n=i.default;return r[LAZY_COMPONENT_KEY]=n,{default:n}})),r=i=>(0,import_jsx_runtime.jsx)(import_react2.default.Suspense,{fallback:(0,import_jsx_runtime.jsx)(import_antd.Spin,{}),children:(0,import_jsx_runtime.jsx)(o,x({},i))});return r}return t.reduce((o,r)=>{const i=(0,import_react2.lazy)(()=>e().then(n=>{const l=(0,import_lodash.get)(n,r);return o[r][LAZY_COMPONENT_KEY]=l,{default:l}}));return o[r]=n=>(0,import_jsx_runtime.jsx)(import_react2.default.Suspense,{fallback:(0,import_jsx_runtime.jsx)(import_antd.Spin,{}),children:(0,import_jsx_runtime.jsx)(i,x({},n))}),o},{})}function useLazy(e,t){const o=typeof t=="function"?t:i=>i[t],r=(0,import_react_imported_component.loadableResource)(e);if(!r.payload)throw new Promise((i,n)=>{r.loadIfNeeded(),r.resolution.then(i).catch(n)});return o(r.payload)}function addAppVersion(e,t){if(e)return e["x-app-version"]||(e["x-app-version"]=t),Object.keys(e.properties||{}).forEach(o=>{var r;addAppVersion((r=e.properties)==null?void 0:r[o],t)}),e}const name="@nocobase/client",version="2.0.41",license="Apache-2.0",main="lib/index.js",module$1="es/index.mjs",types="es/index.d.ts",dependencies={"@ahooksjs/use-url-state":"3.5.1","@ant-design/cssinjs":"^1.11.1","@ant-design/icons":"^5.6.1","@ant-design/pro-layout":"^7.22.1","@antv/g2plot":"^2.4.18","@budibase/handlebars-helpers":"0.14.0","@codemirror/lang-html":"^6.4.10","@codemirror/theme-one-dark":"^6.1.3","@ctrl/tinycolor":"^3.6.0","@dnd-kit/core":"^6.0.0","@dnd-kit/sortable":"^7.0.0","@emotion/css":"^11.7.1","@formily/antd-v5":"1.2.3","@formily/core":"^2.2.27","@formily/grid":"^2.2.27","@formily/json-schema":"^2.2.27","@formily/path":"^2.2.27","@formily/react":"^2.2.27","@formily/reactive":"^2.2.27","@formily/reactive-react":"^2.2.27","@formily/shared":"^2.2.27","@formily/validator":"^2.2.27","@nocobase/evaluators":"2.0.41","@nocobase/flow-engine":"2.0.41","@nocobase/sdk":"2.0.41","@nocobase/utils":"2.0.41","@tanstack/react-table":"^8.21.3","@types/tabulator-tables":"^6.2.6","acorn-jsx":"^5.3.2",ahooks:"^3.7.2",antd:"5.24.2","antd-mobile":"^5.41.1","antd-mobile-icons":"^0.3.0","antd-style":"3.7.1",axios:"^1.7.0","bignumber.js":"^9.1.2",classnames:"^2.3.1",codemirror:"^6.0.2",cronstrue:"^2.11.0","file-saver":"^2.0.5",filesize:"9.0.11",flat:"^5.0.2","html5-qrcode":"^2.3.8",i18next:"^22.4.9","i18next-http-backend":"^2.1.1",ignore:"^5.2.0",json5:"^2.2.3",liquidjs:"^10.0.0",lodash:"^4.17.21","lru-cache":"6.0.0","markdown-it":"14.1.0","markdown-it-highlightjs":"3.3.1",mathjs:"^15.1.0",mermaid:"9.4.3",mime:"^4.0.4","mime-match":"^1.0.2","quill-image-resize-module-react":"^3.0.0","react-beautiful-dnd":"^13.1.0","react-device-detect":"2.2.3","react-drag-listview":"^0.1.9","react-error-boundary":"^4.0.10","react-helmet":"^6.1.0","react-hotkeys-hook":"^3.4.7","react-i18next":"^11.15.1","react-iframe":"~1.8.5","react-image-lightbox":"^5.1.4","react-intersection-observer":"9.14.0","react-js-cron":"^3.1.0","react-quill":"^2.0.0","react-router-dom":"^6.30.1","react-to-print":"^2.14.7","sanitize-html":"2.13.0","tabulator-tables":"^6.3.1","use-deep-compare-effect":"^1.8.1",vditor:"^3.10.3"},peerDependencies={react:">=18.0.0","react-dom":">=18.0.0","react-is":">=18.0.0"},devDependencies={"@testing-library/react":"^14.0.0","@types/markdown-it":"14.1.1","@types/markdown-it-highlightjs":"3.3.1","@types/react-big-calendar":"^1.6.4","axios-mock-adapter":"^1.20.0",dumi:"2.2.14","dumi-theme-nocobase":"^0.2.32"},clientPkg={name,version,license,main,module:module$1,types,dependencies,peerDependencies,devDependencies};function createDesignable(e){return new Designable(e)}const generateUid=e=>{e&&(e["x-uid"]||(e["x-uid"]=(0,import_shared.uid)()),Object.keys(e.properties||{}).forEach(t=>{generateUid(e.properties[t])}))},defaultWrap=e=>e,matchSchema=(e,t)=>{if(!(!e||!t)){for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&t[o]!==(e==null?void 0:e[o]))return!1;return!0}},splitWrapSchema=(e,t)=>{if(e["x-uid"]&&e["x-uid"]===t["x-uid"])return[null,e.toJSON()];const o=e.toJSON(),r=I(x({},o),{properties:{}});let i=null;const n=(l,a)=>{Object.keys(l||{}).forEach(c=>{const u=l[c];if(u["x-uid"]===t["x-uid"]){i=l[c];return}else a.properties[c]=I(x({},u),{properties:{}}),n(u==null?void 0:u.properties,a.properties[c])})};return n(o.properties,r),[r,i]},translate=e=>e;class Designable{constructor(t){R(this,"current"),R(this,"options"),R(this,"appVersion"),R(this,"events",{}),this.options=t,this.current=t.current,this.appVersion=t.appVersion}get model(){return this.options.model}get query(){return this.options.query}loadAPIClientEvents(){const{api:t,t:o=translate}=this.options;if(!t)return;const r=i=>{if(!i)return[];const n=Object.values(i.properties).length,l=[];return i.mapProperties(a=>{a["x-component-props"]=a["x-component-props"]||{},a["x-component-props"].width=100/n,a["x-uid"]&&l.push({"x-uid":a["x-uid"],"x-component-props":a["x-component-props"]})}),i["x-uid"]&&l.length?l:[]};this.on("insertAdjacent",i=>L(this,[i],function*({onSuccess:n,current:l,position:a,schema:c,wrap:u,wrapped:d,removed:m}){var p;let h=[];if((d==null?void 0:d["x-component"])==="Grid.Col"&&(h=h.concat(r(d.parent))),(m==null?void 0:m["x-component"])==="Grid.Col"&&(h=h.concat(r(m.parent))),this.refresh(),!l["x-uid"])return;const g=yield t.request({url:`/uiSchemas:insertAdjacent/${l["x-uid"]}?position=${a}`,method:"post",data:{schema:addAppVersion(c,this.appVersion),wrap:u}});h.length&&(yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:h})),m!=null&&m["x-uid"]&&(yield t.request({url:`/uiSchemas:remove/${m["x-uid"]}`,method:"post"})),n==null||n((p=g==null?void 0:g.data)==null?void 0:p.data),import_antd.message.success(o("Saved successfully"),.2)})),this.on("patch",i=>L(this,[i],function*({schema:n}){this.refresh(),n!=null&&n["x-uid"]&&(yield t.request({url:"/uiSchemas:patch",method:"post",data:x({},n)}),import_antd.message.success(o("Saved successfully"),.2))})),this.on("initializeActionContext",i=>L(this,[i],function*({schema:n}){n!=null&&n["x-uid"]&&(yield t.request({url:"/uiSchemas:initializeActionContext",method:"post",data:x({},n)}))})),this.on("batchPatch",i=>L(this,[i],function*({schemas:n}){this.refresh(),yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:n}),import_antd.message.success(o("Saved successfully"),.2)})),this.on("remove",i=>L(this,[i],function*({removed:n}){let l=[];(n==null?void 0:n["x-component"])==="Grid.Col"&&(l=r(n.parent)),this.refresh(),n!=null&&n["x-uid"]&&(yield t.request({url:`/uiSchemas:remove/${n["x-uid"]}`,method:"post"}),l.length&&(yield t.request({url:"/uiSchemas:batchPatch",method:"post",data:l})),import_antd.message.success(o("Saved successfully"),.2))}))}prepareProperty(t){t.type||(t.type="void"),t.name||(t.name=(0,import_shared.uid)()),this.current["x-uid"]&&generateUid(t)}on(t,o){this.events[t]||(this.events[t]=[]),this.events[t].push(o)}emit(t,...o){return L(this,null,function*(){if(!this.events[t])return;const[r,...i]=o;return Promise.all(this.events[t].map(n=>n.bind(this)(x({current:this.current},r),...i)))})}parentsIn(t){if(!t||!import_react.Schema.isSchemaInstance(t))return!1;let o=this.current;for(;o!=null&&o.parent;){if(o.parent===t)return!0;o=o.parent}return!1}refresh(t){const{refresh:o}=this.options;return o==null?void 0:o(t)}deepMerge(t){const o={title:"title",description:"description",default:"initialValue",readOnly:"readOnly",writeOnly:"editable",enum:"dataSource","x-pattern":"pattern","x-display":"display","x-validator":"validator","x-decorator":"decorator","x-component":"component","x-reactions":"reactions","x-content":"content","x-visible":"visible","x-hidden":"hidden","x-disabled":"disabled","x-editable":"editable","x-read-only":"readOnly"},r={"x-decorator-props":"decoratorProps","x-component-props":"componentProps","x-data":"data"};Object.keys(t).forEach(i=>{o[i]?(this.current[i]=t[i],this.updateModel(o[i],t[i])):r[i]?Object.keys(t[i]).forEach(n=>{(0,import_set.default)(this.current,[i,n],t[i][n]),this.updateModel([r[i],n],t[i][n])}):this.current[i]=t[i]}),this.emit("patch",{schema:t})}getSchemaAttribute(t,o){return(0,import_get.default)(this.current,t,o)}shallowMerge(t){const o={title:"title",description:"description",default:"initialValue",readOnly:"readOnly",writeOnly:"editable",enum:"dataSource","x-pattern":"pattern","x-display":"display","x-validator":"validator","x-decorator":"decorator","x-component":"component","x-reactions":"reactions","x-content":"content","x-visible":"visible","x-hidden":"hidden","x-disabled":"disabled","x-editable":"editable","x-read-only":"readOnly","x-decorator-props":"decoratorProps","x-component-props":"componentProps","x-data":"data"};Object.keys(t).forEach(r=>{this.current[r]=t[r],o[r]&&this.updateModel(o[r],t[r])}),this.emit("patch",{schema:t})}updateModel(t,o){const r=i=>{(0,import_set.default)(i,t,o)};this.model&&r(this.model),this.query&&this.query.take(r)}insertAdjacent(t,o,r={}){switch(t){case"beforeBegin":return this.insertBeforeBegin(o,r);case"afterBegin":return this.insertAfterBegin(o,r);case"beforeEnd":return this.insertBeforeEnd(o,r);case"afterEnd":return this.insertAfterEnd(o,r)}}recursiveRemoveIfNoChildren(t,o){if(!t)return;let r=t,i;const n=o==null?void 0:o.breakRemoveOn;for(;r;){if(typeof n=="function"){if(n(r))break}else if(matchSchema(r,n))break;if(Object.keys(r.properties||{}).length>0)break;r.parent&&(i=r.parent.removeProperty(r.name)),r=r.parent}return i}remove(t,o={}){const{breakRemoveOn:r,removeParentsIfNoChildren:i}=o,n=t||this.current;let l=n.parent.removeProperty(n.name);if(i){const a=this.recursiveRemoveIfNoChildren(n.parent,{breakRemoveOn:r});a&&(l=a)}return this.emit("remove",{removed:l})}removeWithoutEmit(t,o={}){const{breakRemoveOn:r,removeParentsIfNoChildren:i}=o,n=t||this.current;let l=n.parent.removeProperty(n.name);if(i){const a=this.recursiveRemoveIfNoChildren(n.parent,{breakRemoveOn:r});a&&(l=a)}return l}insertBeforeBeginOrAfterEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current)||!import_react.Schema.isSchemaInstance(t)||this.current.parent!==t.parent)return;let r=0,i=0;return this.current.parent.mapProperties((n,l,a)=>{this.current.name===l&&(i=a),t.name===l&&(r=a)}),r>i?this.insertBeforeBegin(t,o):this.insertAfterEnd(t,o)}insertBeforeBegin(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));const a={};let c=!1,u=0,d=0;this.current.parent.mapProperties((f,_)=>{_===this.current.name&&(d=u,c=!0,++u),f["x-index"]=u,++u,c&&(a[_]=f,this.current.parent.removeProperty(_))}),this.prepareProperty(t);const m=i(t),p=this.current.parent.addProperty(m.name||(0,import_shared.uid)(),m);p["x-index"]=d,p.parent=this.current.parent,this.current.parent.setProperties(a);const[h,g]=splitWrapSchema(p,t);this.emit("insertAdjacent",x({position:"beforeBegin",schema:g,wrapped:m,wrap:h},r))}insertAfterBegin(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));const a={};let c=1;this.current.mapProperties((h,g)=>{h["x-index"]=c,++c,a[g]=h}),this.current.properties={},this.prepareProperty(t);const u=i(t),d=this.current.addProperty(u.name||(0,import_shared.uid)(),u);d["x-index"]=0,d.parent=this.current,this.current.setProperties(a);const[m,p]=splitWrapSchema(d,t);this.emit("insertAdjacent",x({position:"afterBegin",schema:p,wrap:m,wrapped:u},r))}insertBeforeEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;delete t["x-index"];const r={onSuccess:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;if(import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n}))}else t&&(t=(0,import_cloneDeep.default)(t));this.prepareProperty(t);const a=i(t),c=this.current.addProperty(a.name||(0,import_shared.uid)(),a);c.parent=this.current;const[u,d]=splitWrapSchema(c,t);return this.emit("insertAdjacent",x({position:"beforeEnd",schema:d,wrap:u,wrapped:a},r))}insertAfterEnd(t,o={}){if(!import_react.Schema.isSchemaInstance(this.current))return;const r={onSuccess:o==null?void 0:o.onSuccess},{wrap:i=defaultWrap,breakRemoveOn:n,removeParentsIfNoChildren:l}=o;let a=0,c=0,u=!1;const d={};if(this.current.parent.mapProperties((f,_)=>{f["x-index"]=a,_===this.current.name&&(++a,c=a,u=!0),++a,u&&_!==this.current.name&&(d[_]=f,this.current.parent.removeProperty(_))}),import_react.Schema.isSchemaInstance(t)){if(this.parentsIn(t)){this.emit("error",{code:"parent_is_not_allowed",schema:t});return}t.parent.removeProperty(t.name),l&&(r.removed=this.recursiveRemoveIfNoChildren(t.parent,{breakRemoveOn:n})),t.parent=null}else t&&(t=(0,import_cloneDeep.default)(t));this.prepareProperty(t);const m=i(t),p=this.current.parent.addProperty(m.name||(0,import_shared.uid)(),m);p.parent=this.current.parent,p["x-index"]=c,this.current.parent.setProperties(d);const[h,g]=splitWrapSchema(p,t);this.emit("insertAdjacent",x({position:"afterEnd",schema:g,wrap:h,wrapped:m},r))}}function useFindComponent(){const e=(0,import_react2.useContext)(import_react.SchemaOptionsContext),t=(0,import_react2.useMemo)(()=>(e==null?void 0:e.components)||{},[e]);return o=>{if(!o)return null;if(typeof o!="string")return o;const r=(0,import_get.default)(t,o);return r||console.error(`[nocobase]: Component "${o}" not found`),r}}function useDesignable(){const{designable:e,setDesignable:t,refresh:o,reset:r}=(0,import_react2.useContext)(SchemaComponentContext),i=(0,import_react2.useContext)(import_react.SchemaOptionsContext),n=(0,import_react2.useMemo)(()=>(i==null?void 0:i.components)||{},[i]),l=(0,import_react2.useMemo)(()=>()=>(0,import_jsx_runtime.jsx)(import_jsx_runtime.Fragment,{}),[]),a=(0,import_ahooks.useUpdate)(),c=useRefreshFieldSchema(),u=useRefreshComponent(),d=(0,import_react2.useCallback)(v=>{o==null||o(),a(),c==null||c(v),u==null||u()},[o,a,c,u]),m=(0,import_react.useField)(),p=(0,import_react.useFieldSchema)(),h=useAPIClient(),{t:g}=(0,import_react_i18next.useTranslation)(),f=(0,import_react2.useMemo)(()=>createDesignable({t:g,api:h,refresh:d,current:p,model:m,appVersion:clientPkg.version}),[g,h,d,p,m]);(0,import_react2.useEffect)(()=>{f.loadAPIClientEvents()},[f]);const{isMobileLayout:_}=useMobileLayout();return{dn:f,designable:_?!1:e,reset:r,refresh:d,setDesignable:t,DesignableBar:l,findComponent:(0,import_react2.useCallback)(v=>{var b;if(!v)return null;if(typeof v!="string")return v;const F=(0,import_get.default)(n,v);return(b=F==null?void 0:F[LAZY_COMPONENT_KEY])!=null?b:F},[import_get.default]),on:f.on.bind(f),patch:(0,import_react2.useCallback)((v,b)=>{const F=y=>{Object.keys(y).forEach(C=>{const S=y[C];C==="title"&&(m.title=S,p.title=S),C==="x-decorator-props"&&(m.decoratorProps||(m.decoratorProps={}),p["x-decorator-props"]||(p["x-decorator-props"]={}),Object.keys(S).forEach(P=>{m.decoratorProps[P]=S[P],p["x-decorator-props"][P]=S[P]})),C==="x-component-props"&&(m.componentProps||(m.componentProps={}),p["x-component-props"]||(p["x-component-props"]={}),Object.keys(S).forEach(P=>{m.componentProps[P]=S[P],p["x-component-props"][P]=S[P]}))})};if(typeof v=="string"){const y={};return(0,import_set.default)(y,v,b),F(y)}F(v),d()},[f]),shallowMerge:(0,import_react2.useCallback)(v=>{f.shallowMerge(v)},[f]),deepMerge:(0,import_react2.useCallback)(v=>{f.deepMerge(v)},[f]),remove:(0,import_react2.useCallback)((v,b)=>{f.remove(v,b)},[f]),insertAdjacent:(0,import_react2.useCallback)((v,b,F)=>{f.insertAdjacent(v,b,F)},[f]),insertBeforeBegin:(0,import_react2.useCallback)(v=>{f.insertBeforeBegin(v)},[f]),insertAfterBegin:(0,import_react2.useCallback)(v=>{f.insertAfterBegin(v)},[f]),insertBeforeEnd:(0,import_react2.useCallback)(v=>{f.insertBeforeEnd(v)},[f]),insertAfterEnd:(0,import_react2.useCallback)(v=>{f.insertAfterEnd(v)},[f])}}const DefaultSchemaToolbar=()=>null;DefaultSchemaToolbar.isNullComponent=!0;const useDesigner=()=>{const{designable:e}=useDesignable(),t=(0,import_react.useFieldSchema)(),o=(0,import_react2.useMemo)(()=>t["x-designer"]||t["x-toolbar"]?t["x-designer"]||t["x-toolbar"]:t["x-settings"]?SchemaToolbar:DefaultSchemaToolbar,[t]),r=useComponent(o);return e&&r||DefaultSchemaToolbar},useFieldProps$1=e=>{const t=(0,import_react2.useContext)(import_react.SchemaOptionsContext),o=(0,import_react2.useContext)(import_react.SchemaExpressionScopeContext),r=(0,import_react2.useRef)();return r.current=o,e.toFieldProps(I(x({},t),{get scope(){return x(x({},t.scope),r.current)}}))};function useSchemaComponentContext(){return(0,import_react2.useContext)(SchemaComponentContext)}const useFieldComponentOptions=()=>{var e;const{getCollectionJoinField:t,getCollection:o}=useCollectionManager_deprecated(),r=(0,import_react.useFieldSchema)(),{getField:i}=useCollection_deprecated(),n=i(r.name)||t(r["x-collection-field"]),{t:l}=(0,import_react_i18next.useTranslation)(),{label:a}=((e=r["x-component-props"])==null?void 0:e.fieldNames)||{};return(0,import_react2.useMemo)(()=>{if(!n||!(n!=null&&n.interface)||!["o2o","oho","obo","o2m","linkTo","m2o","m2m"].includes(n.interface))return;const c=o(n.target);if((c==null?void 0:c.template)==="file")return[{label:l("Record picker"),value:"CollectionField"},{label:l("Select"),value:"AssociationSelect"}];switch(n.interface){case"o2m":return[{label:l("Record picker"),value:"CollectionField"},{label:l("Subtable"),value:"TableField"},{label:l("Select"),value:"AssociationSelect"}];case"m2o":case"m2m":case"linkTo":return[{label:l("Record picker"),value:"CollectionField"},{label:l("Select"),value:"AssociationSelect"}];default:return[{label:l("Record picker"),value:"CollectionField"},{label:l("Subform"),value:"FormField"},{label:l("Select"),value:"AssociationSelect"}]}},[l,n==null?void 0:n.interface,a])},useFieldTitle=()=>{var e;const t=(0,import_react.useField)(),o=(0,import_react.useFieldSchema)(),r=useCollection(),i=useCollectionManager(),n=(r==null?void 0:r.getField(o.name))||(i==null?void 0:i.getCollectionField(o["x-collection-field"])),l=useCompile();(0,import_react2.useEffect)(()=>{var a;t!=null&&t.title||(t.title=l((a=n==null?void 0:n.uiSchema)==null?void 0:a.title))},[(e=n==null?void 0:n.uiSchema)==null?void 0:e.title])},useDef$4=()=>({}),useProps=(e={})=>{const t=e,{useProps:o=useDef$4}=t,r=te(t,["useProps"]);let i=o;typeof o!="function"&&(i=useDef$4);const n=i();return x(x({},r),n)};function useParsedFilter({filterOption:e,onFilterChange:t}){const{parseFilter:o,findVariable:r}=useParseDataScopeFilter(),i=JSON.stringify(e),n=(0,import_react2.useRef)(e),l=(0,import_react2.useRef)(t),[a,c]=(0,import_react2.useState)({}),[u,d]=(0,import_react2.useState)(()=>e?null:i),m=!!e&&u!==i;return n.current=e,l.current=t,(0,import_react2.useEffect)(()=>{const p=n.current;if(!p){c({}),d(i);return}let h=!1;const g=()=>L(this,null,function*(){var v;const b=yield o(p);h||(c(b),d(i),(v=l.current)==null||v.call(l,b))});g();const f=import_lodash.default.debounce(g,DEBOUNCE_WAIT),_=(0,import_reactive.reaction)(()=>(0,import_client.flatten)(p,{breakOn({key:v}){return v.startsWith("$")&&v!=="$and"&&v!=="$or"},transformValue(v){if(!isVariable$1(v))return v;const b=getVariableName(v),F=r(b);let y=null;const C=getPath(v).split(".");return C.forEach((S,P)=>{const j=C.slice(0,P+1).join("."),A=(0,import_client.getValuesByPath)({[b]:(F==null?void 0:F.ctx)||{}},j);import_lodash.default.isEmpty(A)||(y=A)}),y}}),f,{equals:import_lodash.default.isEqual});return()=>{h=!0,f.cancel(),_()}},[i,r,o]),{filter:a,parseVariableLoading:m}}const useParentRecordCommon=e=>{const t=useCollectionRecordData();if(e)return t},useTableBlockDecoratorProps=e=>{var t;const{params:o,parseVariableLoading:r}=useTableBlockParams(e),i=useParentRecordCommon(e.association),n=(t=useDataSourceManager().getDataSource(e.dataSource))==null?void 0:t.collectionManager.getCollection(e.collection);return{params:o,parentRecord:i,parseVariableLoading:r,rowKey:(n==null?void 0:n.filterTargetKey)||"id"}};function useTableBlockParams(e){var t;const o=(0,import_react.useFieldSchema)(),{filter:r,parseVariableLoading:i}=useParsedFilter({filterOption:(t=e.params)==null?void 0:t.filter});return{params:(0,import_react2.useMemo)(()=>{const n=e.params||{},{dragSortBy:l}=(o==null?void 0:o["x-decorator-props"])||{};return e.dragSort&&l&&(n.sort=l),I(x({},n),{filter:r})},[o,r,e.dragSort,e.params]),parseVariableLoading:i}}const key="__isNewRecord__",isNewRecord=e=>(0,import_reactive.untracked)(()=>!!(e!=null&&e[key])),markRecordAsNew=e=>{if(!(0,import_lodash.isObject)(e))throw new Error("markRecordAsNew: record must be an object");return e[key]=!0,e},useDefaultLoading=()=>{var e;return!!((e=useDataBlockRequest())!=null&&e.loading)},withSkeletonComponent=(e,t)=>{const{useLoading:o=useDefaultLoading,displayName:r,SkeletonComponent:i=import_antd.Skeleton}=t||{},n=import_react2.default.memo(l=>{const a=o(),c=(0,import_react2.useRef)(!1),u=(0,import_react2.useDeferredValue)(a);return!c.current&&u?(0,import_jsx_runtime.jsx)(i,{}):(c.current=!0,(0,import_jsx_runtime.jsx)(e,x({},l)))});return n.displayName=r||`${e.displayName}(withSkeletonComponent)`||`${e.name}(withSkeletonComponent)`,n},getActionValue=(e,t)=>{const o=r=>(r==null?void 0:r.mode)==="constant"?r.value:null;switch(!0){case[ActionType.Color,ActionType.BackgroundColor,ActionType.TextAlign,ActionType.FontSize,ActionType.FontWeight,ActionType.FontStyle].includes(e):return o(t);default:return null}},getSatisfiedActions=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield Promise.all(o.filter(l=>!l.disabled).map(l=>L(void 0,null,function*(){return(yield conditionAnalyses({ruleGroup:l.condition,variables:r,localVariables:i,conditionType:l.conditionType},n))?l:null})))).filter(Boolean).map(l=>l.actions).flat()}),getSatisfiedValues=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield getSatisfiedActions({rules:o,variables:r,localVariables:i},n)).map(l=>I(x({},l),{value:getActionValue(l.operator,l.value)}))}),getSatisfiedValueMap=(e,t)=>L(void 0,[e,t],function*({rules:o,variables:r,localVariables:i},n){return(yield getSatisfiedValues({rules:o,variables:r,localVariables:i},n)).reduce((l,a)=>I(x({},l),{[a.operator]:a.value}),{})});function useSatisfiedActionValues({formValues:e,category:t="default",rules:o,schema:r,form:i}){const[n,l]=(0,import_react2.useState)({}),a=(0,import_react.useFieldSchema)(),c=useVariables$1(),u=useLocalVariables$1({currentForm:{values:e}}),d=r??a,m=o??(d[LinkageRuleDataKeyMap[t]]||(d==null?void 0:d.parent[LinkageRuleDataKeyMap[t]])),p=useApp(),h=(0,import_react2.useCallback)(()=>{m&&e&&getSatisfiedValueMap({rules:m,variables:c,localVariables:u},p.jsonLogic).then(g=>{(0,import_lodash.isEmpty)(g)?l({}):l(g)}).catch(g=>{throw new Error(g.message)})},[c,u,m,e]);return(0,import_react2.useEffect)(()=>{if(h(),i){const g=(0,import_shared.uid)();return i.addEffects(g,()=>{(0,import_core.onFormValuesChange)(()=>{h()})}),()=>{i.removeEffects(g)}}},[i,h,e]),{valueMap:n}}const GetStyleRules=import_react2.default.memo(({record:e,schema:t,onStyleChange:o})=>{const{valueMap:r}=useSatisfiedActionValues({formValues:e,category:"style",schema:t});return(0,import_react2.useEffect)(()=>{o(r)},[o,r]),null});GetStyleRules.displayName="GetStyleRules";const opacityStyle={opacity:.5},containerStyle={position:"relative"},spinStyle={display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:0,right:0,height:"100%",maxHeight:400,zIndex:1e3},displayNone$3={display:"none"},HighPerformanceSpin=import_react2.default.memo(e=>(0,import_jsx_runtime.jsxs)("div",{style:containerStyle,children:[(0,import_jsx_runtime.jsx)(import_antd.Spin,I(x({},import_lodash.default.omit(e,"children")),{style:e.spinning?spinStyle:displayNone$3})),(0,import_jsx_runtime.jsx)("div",{style:e.spinning?opacityStyle:null,children:e.children})]}));HighPerformanceSpin.displayName="HighPerformanceSpin";var FilterBlockType=(e=>(e[e.FORM=0]="FORM",e[e.TABLE=1]="TABLE",e[e.TREE=2]="TREE",e[e.COLLAPSE=3]="COLLAPSE",e))(FilterBlockType||{});const mergeFilter=(e,t="$and")=>{const o=e.filter(r=>{if(r&&typeof r=="object"&&!Array.isArray(r))return Object.values(r).filter(i=>i!==void 0).length});return o.length===0?{}:o.length===1?o[0]:{[t]:o}},getSupportFieldsByAssociation=(e,t)=>{var o;return(o=t.associatedFields)==null?void 0:o.filter(r=>e==null?void 0:e.some(i=>i===r.target))},getSupportFieldsByForeignKey=(e,t)=>{var o;return(o=t.foreignKeyFields)==null?void 0:o.filter(r=>e.fields.some(i=>i.type!=="belongsTo"&&i.foreignKey===r.name&&i.target===r.collectionName))},useSupportedBlocks=e=>{const{getDataBlocks:t}=useFilterBlock(),o=(0,import_react.useFieldSchema)(),r=useCollection(),{getAllCollectionsInheritChain:i}=useAllCollectionsInheritChainGetter();if(e===0||e===3)return t().filter(n=>isSameCollection(n.collection,r));if(e===1||e===2)return t().filter(n=>{var l,a;return o["x-uid"]!==n.uid&&(isSameCollection(n.collection,r)||((l=getSupportFieldsByAssociation(i(r.name,r.dataSource),n))==null?void 0:l.length)||((a=getSupportFieldsByForeignKey(r,n))==null?void 0:a.length))})},transformToFilter=(e,t,o,r)=>(e=(0,import_client.flatten)(e,{breakOn({value:i,path:n}){if(["$match","$notMatch","$anyOf","$noneOf","$childIn","$childNotIn","$dateBetween","$in","$notIn"].includes(t[n]))return!0;const l=o(`${r}.${n}`);if(["datetime","datetimeNoTz","date","unixTimestamp","createdAt","updatedAt"].includes(l==null?void 0:l.interface))return!0;if(l!=null&&l.target){if(Array.isArray(i))return!0;const a=l.targetKey||"id";if(i&&i[a]!=null)return!0}return!1}}),{$and:Object.keys(e).map(i=>{let n=import_lodash.default.get(e,i);const l=o(`${r}.${i}`);return l!=null&&l.target&&["hasOne","hasMany","belongsTo","belongsToMany","belongsToArray"].includes(l.type)&&(n=(0,import_client.getValuesByPath)(n,l.targetKey||"id"),i=`${i}.${l.targetKey||"id"}`,(l==null?void 0:l.interface)==="chinaRegion"&&(n=import_lodash.default.last(n))),!n&&n!==0&&n!==!1?null:{[i]:{[t[i]||"$eq"]:n}}}).filter(Boolean)}),useAssociatedFields=()=>{var e;return((e=useCollection())==null?void 0:e.fields.filter(t=>isAssocField(t)))||[]},isAssocField=e=>["o2o","oho","obo","m2o","createdBy","updatedBy","o2m","m2m","linkTo","chinaRegion","mbm"].includes(e==null?void 0:e.interface),isSameCollection=(e,t)=>e.name===t.name&&e.dataSource===t.dataSource,useFilterAPI=()=>{const e=(0,import_react.useFieldSchema)(),{getDataBlocks:t}=useFilterBlock(),{targets:o,uid:r}=findFilterTargets(e),i=t(),[n,l]=(0,import_react2.useState)(()=>o&&o.some(u=>i.some(d=>d.uid===u.uid))),a=Object.keys(o||{});(0,import_react2.useEffect)(()=>{l(o&&o.some(u=>i.some(d=>d.uid===u.uid)))},[a.length,o,i]);const c=(0,import_react2.useCallback)((u,d="id",m="$eq")=>{const p=i.find(h=>h.uid===e.parent["x-uid"]);i.forEach(h=>{var g,f,_,v;let b=d;const F=o.find(P=>P.uid===h.uid);if(!F)return;import_lodash.default.isFunction(u)&&(u=u(F,h,getSourceKey$1(p,F.field))),import_lodash.default.isFunction(d)&&(b=d(F,h)),import_lodash.default.isFunction(m)&&(m=m(F));const y=((g=h.service.params)==null?void 0:g[0])||{},C=((_=(f=h.service.params)==null?void 0:f[1])==null?void 0:_.filters)||{};if(u!=null)C[r]={$and:[{[b]:{[m]:u}}]};else if((v=h.clearSelection)==null||v.call(h),delete C[r],h.dataLoadingMode==="manual")return h.clearData();const S=mergeFilter([...Object.values(C).map(P=>removeNullCondition(P)),h.defaultFilter]);h.doFilter(I(x({},y),{page:1,filter:S}),{filters:C})})},[i,o,r,e]);return{isConnected:n,doFilter:c}},isInFilterFormBlock=e=>{for(;e;){if(e["x-filter-targets"])return e["x-decorator"]==="FilterFormBlockProvider";e=e.parent}return!1};function getSourceKey$1(e,t){var o,r,i;const n=(o=e==null?void 0:e.associatedFields)==null?void 0:o.find(l=>l.foreignKey===t);return(n==null?void 0:n.sourceKey)||((i=(r=t==null?void 0:t.split)==null?void 0:r.call(t,"."))==null?void 0:i[1])}const AssociationFieldContext=(0,import_react2.createContext)({});AssociationFieldContext.displayName="AssociationFieldContext";const useInsertSchema$1=e=>{const t=(0,import_react.useFieldSchema)(),{insertAfterBegin:o}=useDesignable(),{isMobileLayout:r}=useMobileLayout();return(0,import_react2.useCallback)(i=>{r||t.reduceProperties((n,l)=>l["x-component"]==="AssociationField."+e?l:n,null)||o((0,import_cloneDeep.default)(i))},[e,t,o,r])};function useAssociationFieldContext(){return(0,import_react2.useContext)(AssociationFieldContext)}function useServiceOptions$1(e){var t,o,r,i,n,l,a,c,u,d;const{action:m="list",service:p,useOriginalFilter:h}=e,g=(0,import_react.useFieldSchema)(),f=(0,import_react.useField)(),{getField:_}=useCollection_deprecated(),{getCollectionJoinField:v}=useCollectionManager_deprecated(),b=useRecord(),{isNew:F}=useCollectionRecord()||{},y=((0,import_lodash.isString)((r=(o=(t=g==null?void 0:g["x-component-props"])==null?void 0:t.service)==null?void 0:o.params)==null?void 0:r.filter)?(l=(n=(i=f.componentProps)==null?void 0:i.service)==null?void 0:n.params)==null?void 0:l.filter:(u=(c=(a=g==null?void 0:g["x-component-props"])==null?void 0:a.service)==null?void 0:c.params)==null?void 0:u.filter)||((d=p==null?void 0:p.params)==null?void 0:d.filter),{filter:C}=useParsedFilter({filterOption:y,onFilterChange:()=>{F&&f.reset()}}),S=(0,import_react2.useMemo)(()=>_(g.name)||v(g==null?void 0:g["x-collection-field"]),[g]),P=b==null?void 0:b[S==null?void 0:S.sourceKey],j=(0,import_react2.useMemo)(()=>{const A=["oho","o2m"].includes(S==null?void 0:S.interface);return mergeFilter([mergeFilter([A&&!isInFilterFormBlock(g)&&S!=null&&S.foreignKey&&!h?{[S.foreignKey]:{$is:null}}:null,C]),A&&P!==void 0&&P!==null&&!isInFilterFormBlock(g)&&S!=null&&S.foreignKey&&!h?{[S.foreignKey]:{$eq:P}}:null],"$or")},[S==null?void 0:S.interface,S==null?void 0:S.foreignKey,g,C,P,h]);return(0,import_react2.useMemo)(()=>I(x({resource:S==null?void 0:S.target,action:m},p),{params:I(x({},p==null?void 0:p.params),{filter:j})}),[S==null?void 0:S.target,m,j,p])}const useFieldNames$1=(e={})=>{var t,o,r,i,n;const l=(0,import_react.useFieldSchema)(),a=((i=(r=(o=(t=l["x-component-props"])==null?void 0:t.field)==null?void 0:o.uiSchema)==null?void 0:r["x-component-props"])==null?void 0:i.fieldNames)||((n=l["x-component-props"])==null?void 0:n.fieldNames)||e.fieldNames;return x({label:"label",value:"value"},a)},SubFormContext=(0,import_react2.createContext)(null);SubFormContext.displayName="SubFormContext";const SubFormProvider=e=>{const t=(0,import_react2.useContext)(SubFormContext),{value:o,collection:r,fieldSchema:i,parent:n,skip:l}=e.value,a=(0,import_react2.useMemo)(()=>import_lodash.default.omitBy({value:o,collection:r,fieldSchema:i,skip:l,parent:n||(t!=null&&t.skip?t.parent:t)},import_lodash.default.isUndefined),[o,r,i,l,n,t]);return(0,import_jsx_runtime.jsx)(SubFormContext.Provider,{value:a,children:e.children})},useSubFormValue=()=>{const{value:e,collection:t,fieldSchema:o,parent:r}=(0,import_react2.useContext)(SubFormContext)||{};return{formValue:e,collection:t,fieldSchema:o,parent:r}},TableUidContext=(0,import_react2.createContext)(null),useColumnSettings=e=>{const{t}=(0,import_react_i18next.useTranslation)(),o=(0,import_react2.useContext)(TableUidContext),r=`nocobase_table_column_settings_${o}`,i=(0,import_react2.useCallback)(()=>{try{const a=localStorage.getItem(r);return a?JSON.parse(a):null}catch(a){return console.warn("Failed to parse table column settings from localStorage:",a),null}},[r]),n=(0,import_react2.useCallback)(a=>{try{const c=JSON.stringify(a);localStorage.setItem(r,c);const u=new CustomEvent("nocobase-table-settings-changed",{detail:{key:r,tableId:o,settings:a}});window.dispatchEvent(u)}catch(c){console.warn("Failed to save table column settings to localStorage:",c),import_antd.message.error(t("Failed to save table settings"))}},[r,o,t]),l=(0,import_react2.useCallback)(()=>{try{localStorage.removeItem(r);const a=new CustomEvent("nocobase-table-settings-changed",{detail:{key:r,tableId:o,settings:null}});window.dispatchEvent(a)}catch(a){console.warn("Failed to clear table column settings from localStorage:",a),import_antd.message.error(t("Failed to clear table settings"))}},[r,o,t]);return{getSettings:i,saveSettings:n,clearSettings:l}},useTableColumnIntegration=(e,t=!0)=>{const o=(0,import_react2.useContext)(TableUidContext),{getSettings:r}=useColumnSettings(),[i,n]=(0,import_react2.useState)(0);(0,import_react2.useEffect)(()=>{const a=c=>{const{key:u,tableId:d}=c.detail;(u.includes(o)||d===o)&&n(m=>m+1)};return window.addEventListener("nocobase-table-settings-changed",a),()=>{window.removeEventListener("nocobase-table-settings-changed",a)}},[o]);const l=(0,import_react2.useMemo)(()=>r(),[r,i]);return{columns:(0,import_react2.useMemo)(()=>{if(!t||!l||l.length===0)return e;const a=new Map;l.forEach(p=>{a.set(p.key,p)});const c=e.map(p=>{const h=a.get(p.key);if(h){const g=p.columnHidden||!h.visible,f=h.width||p.width,_=h.fixed||p.fixed;return I(x({},p),{columnHidden:g,fixed:_,width:f,_orderIndex:h.order})}return p}),u=[],d=[];c.forEach(p=>{p._orderIndex!==void 0?u.push(p):d.push(p)}),u.sort((p,h)=>(p._orderIndex||0)-(h._orderIndex||0));const m=[...u,...d];return m.forEach(p=>{delete p._orderIndex}),m},[e,l])}},TableSkeleton=({rows:e=5,columns:t=6})=>{const{token:o}=useToken$1(),r=o.controlHeight*2.06,i=o.controlHeight*1.75,n=(0,import_react2.useMemo)(()=>import_css.css`
66
66
  &.skeleton-wrapper {
67
67
  width: 100%;
68
68
  background: ${o.colorBgContainer};
@@ -1693,7 +1693,7 @@ https://requirejs.org/docs/errors.html#`+e);return i.requireType=e,i.requireModu
1693
1693
  -webkit-box-orient: vertical;
1694
1694
  -webkit-line-clamp: 2;
1695
1695
  overflow: hidden;
1696
- `,children:p})})})]})}const PluginCard=e=>{const{data:t}=e,[o,r]=(0,import_react2.useState)(void 0);return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[o&&(0,import_jsx_runtime.jsx)(PluginDetail,{plugin:o,onCancel:()=>r(void 0)}),(0,import_jsx_runtime.jsx)(PluginInfo,{onClick:()=>{r(t)},data:t})]})},PluginAddModal=({onClose:e,isShow:t})=>{const{t:o}=(0,import_react_i18next.useTranslation)(),{theme:r}=useStyles$1(),[i,n]=(0,import_react2.useState)("npm");return(0,import_jsx_runtime.jsxs)(import_antd.Modal,{onCancel:()=>e(),footer:null,destroyOnClose:!0,title:o("Add & Update"),width:580,open:t,children:[(0,import_jsx_runtime.jsx)("div",{style:{marginTop:r.marginLG,marginBottom:r.marginLG},children:(0,import_jsx_runtime.jsxs)(import_antd.Radio.Group,{optionType:"button",defaultValue:i,onChange:l=>n(l.target.value),children:[(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"npm",children:o("Npm package")}),(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"upload",children:o("Upload plugin")}),(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"url",children:o("Compressed file url")})]})}),i==="npm"&&(0,import_jsx_runtime.jsx)(PluginNpmForm,{onClose:e,isUpgrade:!1}),i==="upload"&&(0,import_jsx_runtime.jsx)(PluginUploadForm,{onClose:e,isUpgrade:!1}),i==="url"&&(0,import_jsx_runtime.jsx)(PluginUrlForm,{onClose:e})]})};function hasIntersection(e,t){return!Array.isArray(e)||!Array.isArray(t)?!1:e.some(o=>t.includes(o))}function BulkEnableButton({plugins:e=[]}){const{t}=(0,import_react_i18next.useTranslation)(),o=useAPIClient(),[r,i]=(0,import_react2.useState)(e.filter(u=>!u.enabled)),[n,l]=(0,import_react2.useState)(!1),[a,c]=(0,import_react2.useState)([]);return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)(import_antd.Button,{onClick:()=>l(!0),children:t("Bulk enable")}),(0,import_jsx_runtime.jsxs)(import_antd.Modal,{width:1e3,title:t("Bulk enable"),open:n,onOk:()=>L(this,null,function*(){yield o.request({url:"pm:enable",params:{filterByTk:a}}),l(!1)}),onCancel:()=>{c([]),l(!1)},children:[(0,import_jsx_runtime.jsx)(import_antd.Input,{style:{marginBottom:"1em"},placeholder:t("Search plugin..."),onChange:u=>{i(e.filter(d=>{var m;const p=u.target.value;return!d.enabled&&(d.displayName.toLowerCase().includes(p.toLowerCase())||((m=d.description)==null?void 0:m.toLowerCase().includes(p.toLowerCase())))}))}}),(0,import_jsx_runtime.jsx)(import_antd.Table,{rowSelection:{type:"checkbox",selectedRowKeys:a,onChange(u){const d=r.map(m=>m.name);c(m=>u.length===0?m.filter(p=>!d.includes(p)):u.length===d.length?import_lodash.default.uniq([...m,...u]):m)},onSelect(u){c(d=>d.includes(u.name)?d.filter(m=>m!==u.name):d.concat(u.name))}},rowKey:"name",scroll:{y:"60vh"},size:"small",pagination:!1,columns:[{title:t("Plugin"),dataIndex:"displayName",ellipsis:!0},{title:t("Description"),dataIndex:"description",ellipsis:!0,width:300},{title:t("Package name"),dataIndex:"packageName",width:300,ellipsis:!0}],dataSource:r})]})]})}const LocalPlugins=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),{theme:t}=useStyles$1(),{data:o,loading:r,refresh:i}=useRequest({url:"pm:list"}),n=(0,import_react2.useMemo)(()=>{let F=(o==null?void 0:o.data)||[];return F=F.reverse(),[{type:"All",list:F},{type:"Built-in",list:import_lodash.default.filter(F,y=>y.builtIn)},{type:"Enabled",list:import_lodash.default.filter(F,y=>y.enabled)},{type:"Not enabled",list:import_lodash.default.filter(F,y=>!y.enabled)},{type:"Problematic",list:import_lodash.default.filter(F,y=>!y.isCompatible)}]},[o==null?void 0:o.data]),[l,a]=(0,import_react2.useState)(0),[c,u]=(0,import_react2.useState)(!1),[d,m]=(0,import_react2.useState)(""),[p,h]=(0,import_react2.useState)(null),g=(0,import_ahooks.useDebounce)(d,{wait:100}),f=["Data model tools","Data sources","Collections","Collection fields","Blocks","Actions","Workflow","Users & permissions","AI","Authentication","Notification","System management","Security","Logging and monitoring","Others"],_=(0,import_react2.useMemo)(()=>f.map(F=>{if(F==="Others"){const C=o==null?void 0:o.data.filter(S=>!hasIntersection(S.keywords,f));return{key:F,list:C}}const y=o==null?void 0:o.data.filter(C=>{var S;return(S=C.keywords)==null?void 0:S.includes(F)});return{key:F,list:y}}),[f]),v=(0,import_react2.useMemo)(()=>{var F;let y=((F=n[l])==null?void 0:F.list)||[];!l&&p?y=_.find(S=>S.key===p).list:l&&p&&(y=_.find(S=>S.key===p).list.filter(S=>y.find(P=>P.name===S.name)));const C=g.toLocaleLowerCase().trim();return C&&(y=import_lodash.default.filter(y,S=>String(S.displayName||"").toLocaleLowerCase().includes(C)||String(S.description||"").toLocaleLowerCase().includes(C))),y.sort((S,P)=>S.displayName.localeCompare(P.displayName))},[l,n,g,p]),b=F=>{m(F)};return r?(0,import_jsx_runtime.jsx)(import_antd.Spin,{}):(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)(PluginAddModal,{isShow:c,onClose:F=>{u(!1)}}),(0,import_jsx_runtime.jsxs)("div",{style:{width:"100%"},children:[(0,import_jsx_runtime.jsxs)("div",{style:{marginBottom:t.marginLG},className:import_css.css`
1696
+ `,children:p})})})]})}const PluginCard=e=>{const{data:t}=e,[o,r]=(0,import_react2.useState)(void 0);return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[o&&(0,import_jsx_runtime.jsx)(PluginDetail,{plugin:o,onCancel:()=>r(void 0)}),(0,import_jsx_runtime.jsx)(PluginInfo,{onClick:()=>{r(t)},data:t})]})},PluginAddModal=({onClose:e,isShow:t})=>{const{t:o}=(0,import_react_i18next.useTranslation)(),{theme:r}=useStyles$1(),[i,n]=(0,import_react2.useState)("npm");return(0,import_jsx_runtime.jsxs)(import_antd.Modal,{onCancel:()=>e(),footer:null,destroyOnClose:!0,title:o("Add & Update"),width:580,open:t,children:[(0,import_jsx_runtime.jsx)("div",{style:{marginTop:r.marginLG,marginBottom:r.marginLG},children:(0,import_jsx_runtime.jsxs)(import_antd.Radio.Group,{optionType:"button",defaultValue:i,onChange:l=>n(l.target.value),children:[(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"npm",children:o("Npm package")}),(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"upload",children:o("Upload plugin")}),(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:"url",children:o("Compressed file url")})]})}),i==="npm"&&(0,import_jsx_runtime.jsx)(PluginNpmForm,{onClose:e,isUpgrade:!1}),i==="upload"&&(0,import_jsx_runtime.jsx)(PluginUploadForm,{onClose:e,isUpgrade:!1}),i==="url"&&(0,import_jsx_runtime.jsx)(PluginUrlForm,{onClose:e})]})};function hasIntersection(e,t){return!Array.isArray(e)||!Array.isArray(t)?!1:e.some(o=>t.includes(o))}function BulkEnableButton({plugins:e=[]}){const{t}=(0,import_react_i18next.useTranslation)(),o=useAPIClient(),[r,i]=(0,import_react2.useState)(e.filter(u=>!u.enabled)),[n,l]=(0,import_react2.useState)(!1),[a,c]=(0,import_react2.useState)([]);return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)(import_antd.Button,{onClick:()=>l(!0),children:t("Bulk enable")}),(0,import_jsx_runtime.jsxs)(import_antd.Modal,{width:1e3,title:t("Bulk enable"),open:n,onOk:()=>L(this,null,function*(){yield o.request({url:"pm:enable",params:{filterByTk:a}}),l(!1)}),onCancel:()=>{c([]),l(!1)},children:[(0,import_jsx_runtime.jsx)(import_antd.Input,{style:{marginBottom:"1em"},placeholder:t("Search plugin..."),onChange:u=>{i(e.filter(d=>{var m;const p=u.target.value;return!d.enabled&&(d.displayName.toLowerCase().includes(p.toLowerCase())||((m=d.description)==null?void 0:m.toLowerCase().includes(p.toLowerCase())))}))}}),(0,import_jsx_runtime.jsx)(import_antd.Table,{rowSelection:{type:"checkbox",selectedRowKeys:a,onChange(u){const d=r.map(m=>m.name);c(m=>u.length===0?m.filter(p=>!d.includes(p)):u.length===d.length?import_lodash.default.uniq([...m,...u]):m)},onSelect(u){c(d=>d.includes(u.name)?d.filter(m=>m!==u.name):d.concat(u.name))}},rowKey:"name",scroll:{y:"60vh"},size:"small",pagination:!1,columns:[{title:t("Plugin"),dataIndex:"displayName",ellipsis:!0},{title:t("Description"),dataIndex:"description",ellipsis:!0,width:300},{title:t("Package name"),dataIndex:"packageName",width:300,ellipsis:!0}],dataSource:r})]})]})}const LocalPlugins=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),{theme:t}=useStyles$1(),{data:o,loading:r,refresh:i}=useRequest({url:"pm:list"}),n=(0,import_react2.useMemo)(()=>{let F=(o==null?void 0:o.data)||[];return F=F.reverse(),[{type:"All",list:F},{type:"Built-in",list:import_lodash.default.filter(F,y=>y.builtIn)},{type:"Enabled",list:import_lodash.default.filter(F,y=>y.enabled)},{type:"Not enabled",list:import_lodash.default.filter(F,y=>!y.enabled)},{type:"Problematic",list:import_lodash.default.filter(F,y=>!y.isCompatible)}]},[o==null?void 0:o.data]),[l,a]=(0,import_react2.useState)(0),[c,u]=(0,import_react2.useState)(!1),[d,m]=(0,import_react2.useState)(""),[p,h]=(0,import_react2.useState)(null),g=(0,import_ahooks.useDebounce)(d,{wait:100}),f=["Data model tools","Data sources","Collections","Collection fields","Blocks","Actions","Workflow","Users & permissions","AI","Authentication","Notification","System management","Security","Architecture","Logging and monitoring","Others"],_=(0,import_react2.useMemo)(()=>f.map(F=>{if(F==="Others"){const C=o==null?void 0:o.data.filter(S=>!hasIntersection(S.keywords,f));return{key:F,list:C}}const y=o==null?void 0:o.data.filter(C=>{var S;return(S=C.keywords)==null?void 0:S.includes(F)});return{key:F,list:y}}),[f]),v=(0,import_react2.useMemo)(()=>{var F;let y=((F=n[l])==null?void 0:F.list)||[];!l&&p?y=_.find(S=>S.key===p).list:l&&p&&(y=_.find(S=>S.key===p).list.filter(S=>y.find(P=>P.name===S.name)));const C=g.toLocaleLowerCase().trim();return C&&(y=import_lodash.default.filter(y,S=>String(S.displayName||"").toLocaleLowerCase().includes(C)||String(S.description||"").toLocaleLowerCase().includes(C))),y.sort((S,P)=>S.displayName.localeCompare(P.displayName))},[l,n,g,p]),b=F=>{m(F)};return r?(0,import_jsx_runtime.jsx)(import_antd.Spin,{}):(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[(0,import_jsx_runtime.jsx)(PluginAddModal,{isShow:c,onClose:F=>{u(!1)}}),(0,import_jsx_runtime.jsxs)("div",{style:{width:"100%"},children:[(0,import_jsx_runtime.jsxs)("div",{style:{marginBottom:t.marginLG},className:import_css.css`
1697
1697
  justify-content: space-between;
1698
1698
  display: flex;
1699
1699
  align-items: center;
@@ -1766,7 +1766,7 @@ ${u}`;return clampText(m,MAX_MESSAGE_CHARS)}}const i=e.issues.filter(c=>c.type==
1766
1766
  }
1767
1767
  `,DateFormatCom=e=>{const t=(0,import_dayjs.default)();return(0,import_jsx_runtime.jsxs)("div",{style:{display:"inline-flex"},children:[(0,import_jsx_runtime.jsx)("span",{children:e.format}),(0,import_jsx_runtime.jsx)(DateTimeFormatPreview,{content:t.format(e.format)})]})},DateTimeFormatPreview=({content:e})=>{const{token:t}=import_antd.theme.useToken();return(0,import_jsx_runtime.jsx)("span",{style:{display:"inline-block",background:t.colorBgTextHover,marginLeft:t.marginMD,lineHeight:"1",padding:t.paddingXXS,borderRadius:t.borderRadiusOuter},children:e})},InternalExpiresRadio=e=>{const{onChange:t,defaultValue:o,formats:r,picker:i}=e,[n,{setFalse:l,setTrue:a}]=(0,import_ahooks.useBoolean)(e.value&&!r.includes(e.value)),[c,u]=(0,import_react2.useState)(e.value&&!r.includes(e.value)?e.value:o),[d,m]=(0,import_react2.useState)(c?date.format(c):null),p=h=>{h.target.value==="custom"?(a(),t(c)):(l(),t(h.target.value))};return(0,import_react2.useEffect)(()=>{r.includes(e.value)?l():a(),u(e.value&&!r.includes(e.value)?e.value:o)},[e.value]),(0,import_react2.useEffect)(()=>{m(c?date.format(c):null)},[c]),(0,import_jsx_runtime.jsx)(import_antd.Space,{className:spaceCSS,children:(0,import_jsx_runtime.jsx)(import_antd.Radio.Group,{value:n?"custom":e.value,onChange:p,children:(0,import_jsx_runtime.jsx)(import_antd.Space,{direction:"vertical",children:e.options.map(h=>{if(h.value==="custom")return(0,import_jsx_runtime.jsxs)(import_antd.Radio,{value:h.value,children:[(0,import_jsx_runtime.jsx)(import_antd.Input,{style:{width:"150px"},value:c,onChange:g=>{g.target.value?m(date.format(g.target.value)):m(null),n&&t(g.target.value),u(g.target.value)}}),(0,import_jsx_runtime.jsx)(DateTimeFormatPreview,{content:d})]},h.value);if(!i||i==="date")return(0,import_jsx_runtime.jsx)(import_antd.Radio,{value:h.value,"aria-label":h.value,children:(0,import_jsx_runtime.jsx)("span",{role:"button","aria-label":h.value,children:h.label})},h.value)})})})})},ExpiresRadio=(0,import_react.connect)(InternalExpiresRadio,(0,import_react.mapProps)({dataSource:"options"},e=>x({},e))),BlockPlaceholder=()=>{const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_flow_engine.useFlowModel)(),o=t.context.blockModel.collection,r=o.dataSource,i=(0,import_react2.useMemo)(()=>{const a=`${e(r.displayName||r.key)} > `,c=o?`${e(o.title)||o.name||o.tableName} `:"";return`${a}${c}`},[]),{actionName:n}=t.forbidden,l=(0,import_react2.useMemo)(()=>e(`The current user only has the UI configuration permission, but don't have "{{actionName}}" permission for collection "{{name}}"`,{name:i,actionName:e(import_lodash.default.capitalize(n))}).replaceAll("&gt;",">"),[n,i,e]);return(0,import_jsx_runtime.jsx)(BlockItemCard,{children:(0,import_jsx_runtime.jsx)(import_antd.Result,{status:"403",subTitle:l})})};function BlockDeletePlaceholder(){const{t:e}=(0,import_react_i18next.useTranslation)(),t=(0,import_flow_engine.useFlowModel)(),o=t.dataSource,r=(0,import_react2.useMemo)(()=>{const n=`${e(o.displayName||o.key)} > `,l=t.resource.resourceName;return`${n}${l}`},[]),i=(0,import_react2.useMemo)(()=>e('The {{type}} "{{name}}" may have been deleted. Please remove this {{blockType}}.',{type:e("Collection"),name:r,blockType:e("Block")}).replaceAll("&gt;",">"),[r,e]);return(0,import_jsx_runtime.jsx)(BlockItemCard,{children:(0,import_jsx_runtime.jsx)(import_antd.Result,{status:"404",subTitle:i})})}const BlockSceneEnum={new:"new",one:"one",many:"many",select:"select",filter:"filter",oam:["one","many"],subForm:"subForm",bulkEditForm:"bulkEditForm"};class BlockModel extends import_flow_engine.FlowModel{constructor(){super(...arguments),R(this,"decoratorProps",(0,import_reactive.observable)({})),R(this,"_defaultCustomModelClasses",{}),R(this,"customModelClasses",{}),R(this,"collectionRequired",!1),R(this,"ObservedRenderComponent",null),R(this,"activeFilterSources",new Map)}setFilterActive(t,o){this.activeFilterSources.set(t,o)}hasActiveFilters(){const t=this.resource;if(t&&t.filter&&Object.keys(t.filter).length>0)return!0;for(const[,o]of this.activeFilterSources)if(o)return!0;return!1}removeFilterSource(t){this.activeFilterSources.delete(t)}getDataLoadingMode(){var t;const o=this.getStepParams("dataLoadingModeSettings");return((t=o==null?void 0:o.dataLoadingMode)==null?void 0:t.mode)||"auto"}static _getScene(){return import_lodash.default.castArray(this.scene||[])}static _isScene(t){return this._getScene().includes(t)}getModelClassName(t){return Object.keys(this.customModelClasses).includes(t)?this.customModelClasses[t]:this._defaultCustomModelClasses[t]||t}renderHiddenInConfig(){return this.forbidden?(0,import_jsx_runtime.jsx)(BlockPlaceholder,{}):(0,import_jsx_runtime.jsx)(import_antd.Tooltip,{title:this.context.t("The block is hidden and only visible when the UI Editor is active"),children:(0,import_jsx_runtime.jsx)(BlockItemCard,I(x({ref:this.context.ref},this.decoratorProps),{style:{opacity:"0.3"},children:(0,import_jsx_runtime.jsx)(this.ObservedRenderComponent,{})}))})}onInit(t){super.onInit(t),this.context.defineProperty("blockModel",{value:this}),this.context.defineMethod("getModelClassName",o=>this.getModelClassName(o)),this.ObservedRenderComponent=(0,import_flow_engine.observer)(()=>this.renderComponent(),{displayName:"ObservedRenderComponent"})}setDecoratorProps(t){Object.assign(this.decoratorProps,t)}get title(){return this._title||(this._title=this.defaultBlockTitle()),this._title}defaultBlockTitle(){var t;return`${this.translate(((t=this.constructor.meta)==null?void 0:t.label)||this.constructor.name)}`}renderComponent(){throw new Error("renderComponent method must be implemented in subclasses of BlockModel")}render(){return this.collectionRequired&&!this.context.collection?(0,import_jsx_runtime.jsx)(BlockDeletePlaceholder,{}):(0,import_jsx_runtime.jsx)(BlockItemCard,I(x({ref:this.context.ref},this.decoratorProps),{children:(0,import_jsx_runtime.jsx)(this.ObservedRenderComponent,{})}))}}R(BlockModel,"scene");BlockModel.registerFlow({key:"cardSettings",title:(0,import_flow_engine.tExpr)("Card settings"),steps:{titleDescription:{title:(0,import_flow_engine.tExpr)("Title & description"),uiSchema:{title:{"x-component":"Input","x-decorator":"FormItem",title:(0,import_flow_engine.tExpr)("Title")},description:{"x-component":"Input.TextArea","x-decorator":"FormItem",title:(0,import_flow_engine.tExpr)("Description")}},handler(e,t){const o=e.t(t.title,{ns:"lm-flow-engine"}),r=e.t(t.description,{ns:"lm-flow-engine"});e.model.setDecoratorProps({title:o,description:r})}},linkageRules:{use:"blockLinkageRules"},blockHeight:{use:"blockHeight"}}});BlockModel.define({hide:!0,label:(0,import_flow_engine.tExpr)("Other blocks")});import_flow_engine.FlowModel.registerEvents({beforeRender:{title:(0,import_flow_engine.tExpr)("Before render"),name:"beforeRender",uiSchema:{condition:{type:"object",title:(0,import_flow_engine.tExpr)("Trigger condition"),"x-decorator":"FormItem","x-component":ConditionBuilder}},handler:commonConditionHandler}});class CollectionActionModel extends ActionModel{}CollectionActionModel.define({children:e=>L(void 0,null,function*(){return(yield(0,import_flow_engine.buildSubModelItems)(ActionModel)(e)).filter(t=>e.engine.getModelClass(t.useModel)._isScene(ActionSceneEnum.collection))})});function createDefaultCollectionBlockTitle(e){const{blockLabel:t,dsName:o,dsCount:r,collectionTitle:i,sourceCollectionTitle:n,associationTitle:l}=e,a=r>1&&!!o;let c=i;if(n&&l){const u=`${n} > ${l} (${i})`;c=`${a?`${o} > `:""}${u}`}else c=`${a?`${o} > `:""}${i}`;return`
1768
1768
  ${t}:
1769
- ${c}`}class DataBlockModel extends BlockModel{}DataBlockModel.define({hide:!0,label:(0,import_flow_engine.tExpr)("Data blocks"),children(e){return L(this,null,function*(){const t=yield(0,import_flow_engine.buildSubModelItems)(DataBlockModel)(e),{collectionName:o,filterByTk:r,scene:i}=e.view.inputArgs;return t.filter(n=>{var l,a,c,u,d,m,p;const h=e.engine.getModelClass(n.useModel);return i==="select"?(l=h._isScene)==null?void 0:l.call(h,"select"):i==="subForm"?(a=h._isScene)==null?void 0:a.call(h,"subForm"):i==="bulkEditForm"?(c=h._isScene)==null?void 0:c.call(h,"bulkEditForm"):i==="new"||o&&!r?(u=h._isScene)==null?void 0:u.call(h,"new"):!h._isScene||!((d=h._isScene)!=null&&d.call(h,"select"))&&!((m=h._isScene)!=null&&m.call(h,"subForm"))&&!((p=h._isScene)!=null&&p.call(h,"bulkEditForm"))})})}});class CollectionBlockModel extends DataBlockModel{constructor(){super(...arguments),R(this,"isManualRefresh",!1),R(this,"collectionRequired",!0),R(this,"previousBeforeRenderHash"),R(this,"lastSeenDirtyVersion",null),R(this,"dirtyRefreshing",!1)}onMount(){super.onMount(),this.previousBeforeRenderHash=this.context.location.search}getDirtyTrackingVersion(t,o,r,i){var n;const l=new Set,a=((n=r==null?void 0:r.getResourceName)==null?void 0:n.call(r))||i.associationName||i.collectionName;a&&l.add(String(a)),i.associationName&&l.add(String(i.associationName)),i.collectionName&&l.add(String(i.collectionName));let c=0;for(const u of l)c+=t.getDataSourceDirtyVersion(o,u);return c}onActive(t=!1){if(!this.hidden&&this.previousBeforeRenderHash!==this.context.location.search&&(this.rerender(),!t)||this.hidden)return;const o=this.context.resource;if(!o)return;const r=this.getResourceSettingsInitParams(),i=o.getDataSourceKey()||r.dataSourceKey||"main",n=this.context.engine,l=this.getDirtyTrackingVersion(n,i,o,r);if(t){if(this.dirtyRefreshing)return;this.dirtyRefreshing=!0,o.refresh().then(()=>{this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(n,i,o,r)}).catch(()=>{}).finally(()=>{this.dirtyRefreshing=!1});return}this.isManualRefresh||!(this.lastSeenDirtyVersion===null||l!==this.lastSeenDirtyVersion)||this.dirtyRefreshing||(this.dirtyRefreshing=!0,o.refresh().then(()=>{this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(n,i,o,r)}).catch(()=>{}).finally(()=>{this.dirtyRefreshing=!1}))}static filterCollection(t){return!!t.filterTargetKey}static isCollectionAvailable(t){if(!t)return!1;const o=getBlockCapabilityNamesFromModelClass(this);return areCapabilitiesSupported(t,o)}static defineChildren(t){return L(this,null,function*(){const o=m=>{var p;if(!((p=this.meta)!=null&&p.createModelOptions))return m||{};if(typeof this.meta.createModelOptions=="function"){const h=this.meta.createModelOptions(t);return import_lodash.default.merge({},h,m)}return import_lodash.default.merge({},this.meta.createModelOptions,m)},r=m=>this.name+m,{dataSourceKey:i,collectionName:n,associationName:l,filterByTk:a}=t.view.inputArgs,c=t.dataSourceManager.getDataSources().map(m=>m.getCollections().length===0?null:{key:r(`ds-${m.key}`),label:m.displayName,searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),children:p=>m.getCollections().map(h=>{if(!this.filterCollection(h)||!this.isCollectionAvailable(h))return null;const g={dataSourceKey:h.dataSourceKey,collectionName:h.name};return{key:r(`ds-${m.key}.${h.name}`),label:h.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:g}}})}}).filter(Boolean)}).filter(Boolean),u=m=>c.length===1?c[0].children(m):c;if(!n)return u(t);if(this._isScene("select")){const m={dataSourceKey:i,collectionName:n};l&&(m.associationName=l,m.sourceId="{{ctx.view.inputArgs.sourceId}}");const p=t.dataSourceManager.getCollection(i,n),h=[];return this.isCollectionAvailable(p)&&h.push({key:r("current-collection"),label:"Current collection",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:m}}})}),h.push({key:r("others-collections"),label:"Other collections",children:u(t)}),h}if(this._isScene("new")){const m={dataSourceKey:i,collectionName:n};l&&(m.associationName=l,m.sourceId="{{ctx.view.inputArgs.sourceId}}");const p=[],h=t.dataSourceManager.getCollection(i,n);return this.isCollectionAvailable(h)&&p.push({key:r("current-collection"),label:"Current collection",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:m}}})}),typeof a<"u"&&a!==null&&p.push({key:r("associated"),label:"Associated records",children:()=>t.dataSourceManager.getCollection(i,n).getAssociationFields(this._getScene()).map(g=>{if(!g.targetCollection||g.type==="belongsToArray"||!this.filterCollection(g.targetCollection)||!this.isCollectionAvailable(g.targetCollection))return null;let f=`{{ctx.popup.record.${g.sourceKey||g.collection.filterTargetKey}}}`;g.sourceKey===g.collection.filterTargetKey&&(f="{{ctx.view.inputArgs.filterByTk}}");const _={dataSourceKey:i,collectionName:g.target,associationName:g.resourceName,sourceId:f};return{key:r(`associated-${g.name}`),label:g.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:_}}})}}).filter(Boolean)}),p.push({key:r("others-collections"),label:"Other collections",children:u(t)}),p}const d=[{key:r("associated"),label:"Associated records",children:()=>t.dataSourceManager.getCollection(i,n).getAssociationFields(this._getScene()).map(m=>{if(!m.targetCollection||m.type==="belongsToArray"||!this.filterCollection(m.targetCollection)||!this.isCollectionAvailable(m.targetCollection))return null;let p=`{{ctx.popup.record.${m.sourceKey||m.collection.filterTargetKey}}}`;m.sourceKey===m.collection.filterTargetKey&&(p="{{ctx.view.inputArgs.filterByTk}}");const h={dataSourceKey:i,collectionName:m.target,associationName:m.resourceName,sourceId:p};return{key:r(`associated-${m.name}`),label:m.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:h}}})}}).filter(Boolean)},{key:r("others-records"),label:"Other records",children:u(t)}];if(this._isScene("one")){const m=t.dataSourceManager.getCollection(i,n);if(!m||!this.filterCollection(m)||!this.isCollectionAvailable(m))return d;const p={dataSourceKey:i,collectionName:n,filterByTk:"{{ctx.view.inputArgs.filterByTk}}"};l&&(p.associationName=l,p.sourceId="{{ctx.view.inputArgs.sourceId}}"),d.unshift({key:r("current-record"),label:"Current record",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:p}}})})}return d})}get dataSource(){return this.context.dataSource}get collection(){return this.context.collection}get resource(){return this.context.resource}get association(){return this.context.association}get associationField(){return this.context.association}getAclActionName(){return"view"}getFilterFields(){return L(this,null,function*(){return this.collection.getFields().filter(t=>t.filterable)})}getResourceSettingsInitParams(){return this.getStepParams("resourceSettings","init")}onInit(t){super.onInit(t),this.context.defineProperty("blockModel",{value:this}),this.context.defineProperty("actionName",{get:()=>this.getAclActionName(),cache:!1}),this.context.defineProperty("resourceName",{get:()=>this.resource.getResourceName(),cache:!1}),this.context.defineProperty("dataSource",{get:()=>{const o=this.getResourceSettingsInitParams();return this.context.dataSourceManager.getDataSource(o.dataSourceKey)}}),this.context.defineProperty("collection",{get:()=>{const o=this.getResourceSettingsInitParams();return this.context.dataSourceManager.getCollection(o.dataSourceKey,o.collectionName)}}),this.context.defineProperty("resource",{get:()=>{const o=this.getResourceSettingsInitParams(),r=this.createResource(this.context,o);r.setDataSourceKey(o.dataSourceKey),r.setResourceName(o.associationName||o.collectionName);const i=()=>{var n;const l=this.context.engine;if(!(l!=null&&l.getDataSourceDirtyVersion))return;const a=((n=r.getDataSourceKey)==null?void 0:n.call(r))||o.dataSourceKey||"main";this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(l,a,r,o)};return i(),r.on("refresh",()=>{i(),this.invalidateFlowCache("beforeRender")}),r}}),this.context.defineProperty("association",{get:()=>{const o=this.getResourceSettingsInitParams();if(o.associationName)return this.dataSource.getAssociation(o.associationName)}})}createResource(t,o){throw new Error("createResource method must be implemented in subclasses of CollectionBlockModel")}refresh(){return this.resource?this.resource.refresh():super.refresh()}defaultBlockTitle(){var t,o,r,i,n,l,a;const c=this.translate(((t=this.constructor.meta)==null?void 0:t.label)||this.constructor.name),u=((o=this.dataSource)==null?void 0:o.displayName)||((r=this.dataSource)==null?void 0:r.key),d=((l=(n=(i=this.context)==null?void 0:i.dataSourceManager)==null?void 0:n.getDataSources)==null?void 0:l.call(n).length)||0,m=(a=this.collection)==null?void 0:a.title;if(this.association){const p=this.resource.getResourceName(),h=this.dataSource.getCollection(p.split(".")[0]);return createDefaultCollectionBlockTitle({blockLabel:c,dsName:u,dsCount:d,collectionTitle:m,sourceCollectionTitle:h.title,associationTitle:this.association.title})}return createDefaultCollectionBlockTitle({blockLabel:c,dsName:u,dsCount:d,collectionTitle:m})}addAppends(t,o=!1){var r,i;if(t)if(t.includes(".")){const[n,l]=t.split("."),a=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${this.collection.name}.${n}`);if(!a)return;const c=a.target;if(!c)return;const u=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${c}.${l}`);if(u&&u.isAssociationField()){if(this.resource.addAppends(t),((r=u.targetCollection)==null?void 0:r.template)==="tree"){const d=t.includes(".")?t.slice(t.lastIndexOf(".")+1):t;u.name===d&&this.resource.addAppends(`${t}.parent(recursively=true)`)}o&&this.resource.refresh()}}else{if(!this.collection)return;const n=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${this.collection.name}.${t}`);if(!n)return;n.isAssociationField()&&(this.resource.addAppends(n.name),((i=n.targetCollection)==null?void 0:i.template)==="tree"&&this.resource.addAppends(`${n.name}.parent(recursively=true)`),o&&this.resource.refresh())}}}CollectionBlockModel.registerFlow({key:"resourceSettings",sort:-999,steps:{collectionCheck:{handler(e){e.collection||e.exitAll()}},aclCheck:{use:"aclCheck"},init:{handler(e,t){if(!t.dataSourceKey)throw new Error("dataSourceKey is required");if(!t.collectionName)throw new Error("collectionName is required");Object.keys(t).includes("sourceId")&&e.resource.setSourceId(t.sourceId),Object.keys(t).includes("filterByTk")&&e.resource.setFilterByTk(t.filterByTk)}}}});CollectionBlockModel.registerFlow({key:"refreshSettings",sort:1e4,steps:{refresh:{handler(e){return L(this,null,function*(){const t=e.model,o=e.model.context.filterManager;o&&o.bindToTarget(e.model.uid);const r=t.getDataLoadingMode(),i=t.resource;if(i instanceof import_flow_engine.MultiRecordResource&&r==="manual"&&!t.hasActiveFilters()){i.setData([]),i.setMeta({count:0,hasNext:!1,page:1}),i.loading=!1;return}e.model.isManualRefresh?e.model.resource.loading=!1:yield e.model.resource.refresh()})}}}});CollectionBlockModel.registerFlow({key:"dataLoadingModeSettings",sort:800,title:(0,import_flow_engine.tExpr)("Set data loading mode"),steps:{dataLoadingMode:{use:"dataLoadingMode"}}});CollectionBlockModel.define({hide:!0});class CommonItemModel extends import_flow_engine.FlowModel{}class FieldModel extends import_flow_engine.FlowModel{static resolveUse(t,o,r){var i,n;const l=(n=(i=t==null?void 0:t.stepParams)==null?void 0:i.fieldBinding)==null?void 0:n.use;return l&&l!==(t==null?void 0:t.use)?l:t==null?void 0:t.use}}class FilterBlockModel extends BlockModel{}FilterBlockModel.define({hide:!0,label:"Filter blocks"});class PageModel extends import_flow_engine.FlowModel{constructor(){super(...arguments),R(this,"tabBarExtraContent",{}),R(this,"viewActivatedListener"),R(this,"dataSourceDirtyListener"),R(this,"lastSeenEmitterViewActivatedVersion",0),R(this,"dirtyRefreshScheduled",!1),R(this,"unmounted",!1),R(this,"documentTitleUpdateVersion",0),R(this,"createPageTabModelOptions",()=>{const t=(0,import_shared.uid)();return{uid:t,use:"RootPageTabModel",props:{route:{parentId:this.props.routeId,type:"tabs",schemaUid:t,tabSchemaName:(0,import_shared.uid)(),params:[],hideInMenu:!1,enableTabs:!1}}}})}getActiveTabKey(){var t,o,r,i;const n=(o=(t=this.context.view)==null?void 0:t.navigation)==null?void 0:o.viewParams;return n?n.tabUid||((r=this.getFirstTab())==null?void 0:r.uid):this.props.tabActiveKey||((i=this.getFirstTab())==null?void 0:i.uid)}scheduleActiveLifecycleRefresh(t=!1){this.dirtyRefreshScheduled||(this.dirtyRefreshScheduled=!0,Promise.resolve().then(()=>{if(this.dirtyRefreshScheduled=!1,this.unmounted||(0,import_flow_engine.getPageActive)(this.context)===!1)return;const o=this.getActiveTabKey();o&&this.invokeTabModelLifecycleMethod(o,"onActive",t)}).catch(()=>{}))}onMount(){var t,o,r,i,n,l,a,c,u;super.onMount(),this.unmounted=!1,this.setProps("tabActiveKey",(t=this.context.view.inputArgs)==null?void 0:t.tabUid),(o=this.context)!=null&&o.pageInfo&&(this.context.pageInfo.version="v2"),this.updateDocumentTitle(),this.viewActivatedListener||(this.viewActivatedListener=p=>{const h=this.getActiveTabKey();h&&this.invokeTabModelLifecycleMethod(h,"onActive")},(n=(i=(r=this.flowEngine)==null?void 0:r.emitter)==null?void 0:i.on)==null||n.call(i,import_flow_engine.VIEW_ACTIVATED_EVENT,this.viewActivatedListener));const d=(0,import_flow_engine.getEmitterViewActivatedVersion)((l=this.flowEngine)==null?void 0:l.emitter),m=d>0&&d!==this.lastSeenEmitterViewActivatedVersion;if(this.lastSeenEmitterViewActivatedVersion=d,m&&(0,import_flow_engine.getPageActive)(this.context)!==!1){const p=this.getActiveTabKey();p&&this.invokeTabModelLifecycleMethod(p,"onActive")}this.dataSourceDirtyListener||(this.dataSourceDirtyListener=p=>{this.scheduleActiveLifecycleRefresh()},(u=(c=(a=this.flowEngine)==null?void 0:a.emitter)==null?void 0:c.on)==null||u.call(c,import_flow_engine.DATA_SOURCE_DIRTY_EVENT,this.dataSourceDirtyListener))}onUnmount(){var t,o,r,i,n,l;this.unmounted=!0,this.viewActivatedListener&&((r=(o=(t=this.flowEngine)==null?void 0:t.emitter)==null?void 0:o.off)==null||r.call(o,import_flow_engine.VIEW_ACTIVATED_EVENT,this.viewActivatedListener),this.viewActivatedListener=void 0),this.dataSourceDirtyListener&&((l=(n=(i=this.flowEngine)==null?void 0:i.emitter)==null?void 0:n.off)==null||l.call(n,import_flow_engine.DATA_SOURCE_DIRTY_EVENT,this.dataSourceDirtyListener),this.dataSourceDirtyListener=void 0),super.onUnmount()}invokeTabModelLifecycleMethod(t,o,r=!1){var i,n;o==="onActive"&&(i=this.context)!=null&&i.pageInfo&&(this.context.pageInfo.version="v2");const l=this.flowEngine.getModel(t);if(l){if(l.context.tabActive){const a=(0,import_flow_engine.getPageActive)(l.context)!==!1;l.context.tabActive.value=a&&o==="onActive"}(n=l.subModels.grid)==null||n.mapSubModels("items",a=>{var c;(c=a[o])==null||c.call(a,r)})}o==="onActive"&&this.updateDocumentTitle(t)}updateDocumentTitle(t,o=0){return L(this,null,function*(){var r,i,n,l,a,c,u,d,m,p,h,g,f,_,v,b;if(this.unmounted||(0,import_flow_engine.getPageActive)(this.context)===!1)return;const F=!!((i=(r=this.context)==null?void 0:r.view)!=null&&i.navigation),y=(a=(l=(n=this.context)==null?void 0:n.view)==null?void 0:l.inputArgs)==null?void 0:a.viewUid,C=(d=(u=(c=this.flowEngine)==null?void 0:c.context)==null?void 0:u.route)==null?void 0:d.pathname;if(F&&y&&typeof C=="string"){const A=(m=(0,import_flow_engine.parsePathnameToViewParams)(C).at(-1))==null?void 0:m.viewUid;if(A&&A!==y)return}const S=++this.documentTitleUpdateVersion,P=A=>L(this,null,function*(){var T,N;if(!A||typeof A!="string")return"";try{const D=yield(N=(T=this.context).resolveJsonTemplate)==null?void 0:N.call(T,A);return D==null?"":String(D)}catch{return A}});let j="";if(this.props.enableTabs){const A=t||this.getActiveTabKey(),T=A?this.flowEngine.getModel(A):this.getFirstTab();if(!T&&o<5){window.setTimeout(()=>{this.unmounted||S===this.documentTitleUpdateVersion&&this.updateDocumentTitle(A,o+1)},0);return}j=(yield P((g=(h=(p=T==null?void 0:T.stepParams)==null?void 0:p.pageTabSettings)==null?void 0:h.tab)==null?void 0:g.documentTitle))||((f=T==null?void 0:T.getTabTitle)==null?void 0:f.call(T))||""}else j=(yield P((b=(v=(_=this.stepParams)==null?void 0:_.pageSettings)==null?void 0:v.general)==null?void 0:b.documentTitle))||this.props.title||"";S===this.documentTitleUpdateVersion&&typeof j=="string"&&j!==""&&(document.title=j)})}mapTabs(){return this.mapSubModels("tabs",t=>!this.context.flowSettingsEnabled&&t.hidden?null:{key:t.uid,label:(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:t,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:t,showFlowSettings:{showBackground:!0,showBorder:!1,toolbarPosition:"above",style:{transform:"translateY(8px)"}},extraToolbarItems:[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]})}),children:t.renderChildren()}).filter(Boolean)}getFirstTab(){var t;return(t=this.subModels.tabs)==null?void 0:t[0]}renderFirstTab(){var t;const o=this.getFirstTab();return(t=o==null?void 0:o.renderChildren)==null?void 0:t.call(o)}handleDragEnd(t){return L(this,null,function*(){throw new Error("Method not implemented.")})}renderTabs(){var t,o,r,i,n;const l=(o=(t=this.context.themeToken)==null?void 0:t.paddingLG)!=null?o:16,a=this.tabBarExtraContent.left!==void 0?this.tabBarExtraContent.left:(0,import_jsx_runtime.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:l,height:1}}),c=this.tabBarExtraContent.right!==void 0?this.tabBarExtraContent.right:(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"tabs",items:[{key:"blank",label:this.context.t("Blank tab"),createModelOptions:this.createPageTabModelOptions}],children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.PlusOutlined,{}),children:this.context.t("Add tab")})});return(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{onDragEnd:this.handleDragEnd.bind(this),children:(0,import_jsx_runtime.jsx)(import_antd.Tabs,{activeKey:(i=(r=this.context.view)==null?void 0:r.navigation)!=null&&i.viewParams?this.context.view.navigation.viewParams.tabUid||((n=this.getFirstTab())==null?void 0:n.uid):this.props.tabActiveKey,tabBarStyle:this.props.tabBarStyle,items:this.mapTabs(),onChange:u=>{var d,m;(m=(d=this.context.view.navigation)==null?void 0:d.changeTo)==null||m.call(d,{tabUid:u}),this.invokeTabModelLifecycleMethod(u,"onActive"),this.invokeTabModelLifecycleMethod(this.props.tabActiveKey,"onInactive"),this.setProps("tabActiveKey",u)},tabBarExtraContent:{left:a,right:c}})})}render(){const t=this.context.themeToken,o=x({},this.props.headerStyle);return t&&(o.paddingBlock=t.paddingSM,o.paddingInline=t.paddingLG),this.props.enableTabs&&(o.paddingBottom=0),(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:o}),this.props.enableTabs?this.renderTabs():this.renderFirstTab()]})}}PageModel.registerEvents({close:{title:(0,import_flow_engine.tExpr)("Close"),name:"close",hideInSettings(e){var t;return!!((t=e.view)!=null&&t.preventClose)},uiSchema:{condition:{type:"object",title:(0,import_flow_engine.tExpr)("Trigger condition"),"x-decorator":"FormItem","x-component":ConditionBuilder}},handler:commonConditionHandler}});PageModel.registerFlow({key:"closeGuard",title:(0,import_flow_engine.tExpr)("Close guard"),on:"close",steps:{confirmUnsavedChanges:{title:(0,import_flow_engine.tExpr)("Unsaved changes confirmation"),handler(e){return L(this,null,function*(){var t,o,r,i,n;(o=(t=e.inputArgs)==null?void 0:t.dirty)!=null&&o.hasDirtyForms&&((yield e.modal.confirm({title:e.t("Unsaved changes"),content:e.t("Are you sure you don't want to save?"),okText:e.t("Confirm"),cancelText:e.t("Cancel")}))||((n=(i=(r=e.inputArgs)==null?void 0:r.controller)==null?void 0:i.prevent)==null||n.call(i),e.exitAll()))})}}}});PageModel.registerFlow({key:"pageSettings",title:(0,import_flow_engine.tExpr)("Page settings"),steps:{general:{title:(0,import_flow_engine.tExpr)("Edit page"),uiSchema:{title:{type:"string",title:(0,import_flow_engine.tExpr)("Page title"),"x-decorator":"FormItem","x-component":"Input","x-reactions":{dependencies:["displayTitle"],fulfill:{state:{visible:"{{$deps[0]}}"}}}},documentTitle:{type:"string",title:(0,import_flow_engine.tExpr)("Document title"),description:(0,import_flow_engine.tExpr)("Used as the browser tab title when tabs are disabled. Supports variables. Leave empty to use Page title."),"x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1,maxRows:6}},displayTitle:{type:"boolean",title:(0,import_flow_engine.tExpr)("Display page title"),"x-decorator":"FormItem","x-component":"Switch"},enableTabs:{type:"boolean",title:(0,import_flow_engine.tExpr)("Enable tabs"),"x-decorator":"FormItem","x-component":"Switch"}},defaultParams(e){return{displayTitle:!0,enableTabs:!1}},handler(e,t){return L(this,null,function*(){var o,r;if(e.model.setProps("displayTitle",t.displayTitle),e.model.context.closable)e.model.setProps("title",e.t(t.title,{ns:"lm-desktop-routes"}));else{const i=(r=(o=e.model.context)==null?void 0:o.currentRoute)==null?void 0:r.title;e.model.setProps("title",e.t(t.title||i,{ns:"lm-desktop-routes"}))}e.model.setProps("enableTabs",t.enableTabs),e.view.type==="embed"?(e.model.setProps("headerStyle",{backgroundColor:"var(--colorBgContainer)"}),e.model.setProps("tabBarStyle",{backgroundColor:"var(--colorBgContainer)",marginBottom:0})):(e.model.setProps("headerStyle",{backgroundColor:"var(--colorBgLayout)"}),e.model.setProps("tabBarStyle",{backgroundColor:"var(--colorBgLayout)",marginBottom:0})),e.model.updateDocumentTitle()})}}}});class ChildPageModel extends PageModel{constructor(){super(...arguments),R(this,"tabBarExtraContent",{left:(0,import_jsx_runtime.jsx)(BackButtonUsedInSubPage,{})}),R(this,"createPageTabModelOptions",()=>({use:"ChildPageTabModel"}))}renderBackButtonWhenTabsDisabled(){var t,o,r,i;if(((o=(t=this.context)==null?void 0:t.view)==null?void 0:o.type)!=="embed")return null;const n=(r=this.context)==null?void 0:r.themeToken,l=I(x({},this.props.tabBarStyle),{paddingBlock:(i=n==null?void 0:n.paddingXS)!=null?i:8});return(0,import_jsx_runtime.jsx)("div",{style:l,children:(0,import_jsx_runtime.jsx)(BackButtonUsedInSubPage,{renderSpacerWhenNoBack:!1})})}handleDragEnd(t){return L(this,null,function*(){var o,r;if(!((o=t.active)!=null&&o.id)||!((r=t.over)!=null&&r.id))throw new Error("Invalid drag event");this.flowEngine.moveModel(t.active.id,t.over.id)})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&this.props.title&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.props.enableTabs?this.renderTabs():(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.renderBackButtonWhenTabsDisabled(),this.renderFirstTab()]})]})}}const BackButtonUsedInSubPage=({renderSpacerWhenNoBack:e=!0})=>{var t;const o=(0,import_flow_engine.useFlowContext)(),r=o.themeToken,i=32,n=(t=r==null?void 0:r.paddingLG)!=null?t:16,l=(0,import_react2.useMemo)(()=>({width:"auto",height:"auto",lineHeight:1,padding:r.paddingXS,marginLeft:r.paddingLG,marginRight:i-r.paddingXS}),[r.paddingLG,r.paddingXS]);return o.view.type!=="embed"?e?(0,import_jsx_runtime.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:1}}):null:(0,import_jsx_runtime.jsx)(import_antd.Button,{"aria-label":"back-button",type:"text",icon:(0,import_jsx_runtime.jsx)(import_icons.ArrowLeftOutlined,{}),style:l,onClick:o.view.close})};class OldPageModel extends import_flow_engine.FlowModel{}OldPageModel.registerFlow({key:"pageSettings",title:(0,import_flow_engine.tExpr)("Page settings"),steps:{general:{title:(0,import_flow_engine.tExpr)("General"),uiSchema:{title:{type:"string",title:(0,import_flow_engine.tExpr)("Page title"),"x-decorator":"FormItem","x-component":"Input","x-reactions":{dependencies:["displayTitle"],fulfill:{state:{visible:"{{$deps[0]}}"}}}},displayTitle:{type:"boolean",title:(0,import_flow_engine.tExpr)("Display page title"),"x-decorator":"FormItem","x-component":"Switch"}},defaultParams(e){return{displayTitle:!0,enableTabs:!1}},handler(e,t){return L(this,null,function*(){var o,r;if(e.model.setProps("displayTitle",t.displayTitle),e.model.context.closable)e.model.setProps("title",t.title?e.t(t.title):null);else{const i=(r=(o=e.model.context)==null?void 0:o.currentRoute)==null?void 0:r.title;e.model.setProps("title",e.t(t.title||i))}e.model.setProps("enableTabs",t.enableTabs),e.model.context.closable?(e.model.setProps("headerStyle",{backgroundColor:e.themeToken.colorBgContainer}),e.model.setProps("tabBarStyle",{backgroundColor:e.themeToken.colorBgLayout,paddingInline:16,marginBottom:0})):(e.model.setProps("headerStyle",{backgroundColor:e.themeToken.colorBgContainer}),e.model.setProps("tabBarStyle",{backgroundColor:e.themeToken.colorBgContainer,paddingInline:16,marginBottom:0}))})}}}});class MainPageModel extends OldPageModel{renderFirstTab(){var t;return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels.tabs)==null?void 0:t[0]})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.renderFirstTab()]})}}class RouteModel extends import_flow_engine.FlowModel{}RouteModel.registerFlow({key:"popupSettings",on:"click",steps:{openView:{use:"openView",defaultParams(e){return{mode:"embed",preventClose:!0,pageModelClass:"RootPageModel"}}}}});function resolveViewParamsToViewList(e,t,o){return t.map((r,i)=>{let n,l=r.viewUid;return i===0?(n=o,l=o.uid):n=e.getModel(r.viewUid,!0),{params:r,modelUid:l,model:n,hidden:import_flow_engine.observable.ref(!1),index:i}})}function updateViewListHidden(e){let t=!1;for(let o=e.length-1;o>=0;o--){const r=e[o];getViewType(r)==="embed"&&!t?(t=!0,r.hidden.value=!1):r.hidden.value=t}}function getViewType(e){if(e.model instanceof RouteModel)return"embed";if(!e.model)return"drawer";const t=e.model.getStepParams("popupSettings","openView");return(t==null?void 0:t.mode)||"drawer"}const stableStringify=e=>e==null?"":typeof e=="object"?Array.isArray(e)?"["+e.map(stableStringify).join(",")+"]":"{"+Object.keys(e).sort().map(t=>`${t}:${stableStringify(e[t])}`).join(",")+"}":String(e),getKey=e=>{const{params:t,index:o}=e;return[stableStringify(t.viewUid),stableStringify(t.sourceId),stableStringify(t.filterByTk),String(o)].join("_")};function getViewDiffAndUpdateHidden(e,t){const o=new Map,r=new Map;e.forEach(l=>{const a=getKey(l);o.set(a,l)}),t.forEach(l=>{r.set(getKey(l),l)});const i=[];o.forEach((l,a)=>{r.has(a)?r.get(a).hidden=l.hidden:i.push(l)});const n=[];return r.forEach((l,a)=>{o.has(a)||n.push(l)}),{viewsToClose:i,viewsToOpen:n}}const openViewFlow=(0,import_flow_engine.defineFlow)({key:"popupSettings",title:(0,import_flow_engine.tExpr)("Popup settings"),on:"click",sort:300,steps:{openView:{use:"openView",hideInSettings:e=>L(void 0,null,function*(){var t,o,r,i;const n=(r=(o=(t=e.model).getStepParams)==null?void 0:o.call(t,"displayFieldSettings","clickToOpen"))==null?void 0:r.clickToOpen;return e.collectionField?n===void 0?!((i=e.collectionField)!=null&&i.isAssociationField())||e.disableFieldClickToOpen:n===!1:!1})}},defaultParams:e=>{var t,o,r,i,n,l,a,c;let u,d,m;const p=e.collectionField,h=e.blockModel,g=(o=(t=e.model)==null?void 0:t.parent)==null?void 0:o.associationPathName,f=e.collection||(h==null?void 0:h.collection),_=F=>{var y;return!!((y=F==null?void 0:F.isAssociationField)!=null&&y.call(F))},v=!_(p)&&g?(r=f==null?void 0:f.getFieldByPath)==null?void 0:r.call(f,g):void 0,b=_(p)?p:v;if(_(b)){const F=b.targetCollection;h==null||h.collection,u=F==null?void 0:F.name,d=F==null?void 0:F.dataSourceKey,m=b==null?void 0:b.resourceName}else p?(u=(i=e.collection)==null?void 0:i.name,d=(n=e.collection)==null?void 0:n.dataSourceKey,m=p==null?void 0:p.target):(u=(l=e.collection)==null?void 0:l.name,d=(a=e.collection)==null?void 0:a.dataSourceKey,m=(c=e.association)==null?void 0:c.resourceName);return{openView:{collectionName:u,associationName:m,dataSourceKey:d}}}}),getOpenViewStepParams=e=>e.getStepParams("popupSettings","openView");function InternalFlowPage(e){var t=e,{uid:o}=t,r=te(t,["uid"]);const i=(0,import_flow_engine.useFlowModelById)(o);return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,x({model:i,fallback:(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i!=null&&i.context.isMobileLayout?8:i==null?void 0:i.context.themeToken.marginBlock}}),hideRemoveInSettings:!0,showFlowSettings:{showBackground:!1,showBorder:!1}},r))}const FlowRoute=()=>{const e=(0,import_react2.useRef)(null),t=(0,import_flow_engine.useFlowEngine)(),o=useCurrentRoute(),{refresh:r}=useAllAccessDesktopRoutes(),{isMobileLayout:i}=useMobileLayout(),n=(0,import_react2.useRef)(t.context.route.params.name),l=(0,import_react2.useRef)({}),a=(0,import_react2.useRef)([]),c=(0,import_react2.useRef)(!1),{designable:u}=useDesignable(),{active:d}=useKeepAlive(),m=(0,import_react2.useRef)(!1),p=(0,import_react2.useMemo)(()=>t.createModel({uid:n.current,use:"RouteModel"}),[t]);return(0,import_react2.useEffect)(()=>{p.context.defineProperty("pageActive",{value:import_flow_engine.observable.ref(!1),info:{description:"Whether current page route is active (keep-alive). This is an observable.ref<boolean> (use ctx.pageActive.value to read/write).",detail:"observable.ref<boolean>"}})},[p]),(0,import_react2.useEffect)(()=>{p.context.pageActive.value=d},[d,p]),(0,import_react2.useEffect)(()=>{t.context.defineProperty("isMobileLayout",{get:()=>i,info:{description:"Whether current layout is mobile layout.",detail:"boolean"}}),t.context.defineProperty("deviceType",{get:()=>import_react_device_detect.deviceType==="browser"?"computer":import_react_device_detect.deviceType,cache:!1,meta:{type:"string",title:t.translate("Current device type"),interface:"select",uiSchema:{enum:[{label:t.translate("Computer"),value:"computer"},{label:t.translate("Mobile"),value:"mobile"},{label:t.translate("Tablet"),value:"tablet"},{label:t.translate("SmartTv"),value:"smarttv"},{label:t.translate("Console"),value:"console"},{label:t.translate("Wearable"),value:"wearable"},{label:t.translate("Embedded"),value:"embedded"}],"x-component":"Select"}},info:{description:"Current device type (computer/mobile/tablet/...).",detail:"string"}})},[i,t]),(0,import_react2.useEffect)(()=>{i?t.flowSettings.disable():u&&t.flowSettings.enable()},[u,t,i]),(0,import_react2.useEffect)(()=>{e.current&&(t.context.defineProperty("layoutContentElement",{get:()=>e.current}),p.context.defineProperty("currentRoute",{get:()=>o}),t.context.defineProperty("currentRoute",{get:()=>o}),p.context.defineProperty("refreshDesktopRoutes",{get:()=>r}))},[p,o,r,t]),(0,import_react2.useEffect)(()=>{const h=(0,import_flow_engine.reaction)(()=>t.context.route,g=>{var f;if(g.params.name!==n.current){m.current=!0;return}try{m.current=!1;const _=(0,import_flow_engine.parsePathnameToViewParams)(g.pathname),v=resolveViewParamsToViewList(t,_,p);if(a.current.length===0&&v.length>1&&!c.current){const y=C=>{v[C]&&(C===0?new import_flow_engine.ViewNavigation(t.context,[]).navigateTo(v[C].params,{replace:!0}):new import_flow_engine.ViewNavigation(t.context,v.slice(0,C).map(S=>S.params)).navigateTo(v[C].params),y(C+1))};y(0),c.current=!0;return}const{viewsToClose:b,viewsToOpen:F}=getViewDiffAndUpdateHidden(a.current,v);if(console.log("[NocoBase] FlowRoute view diff:",{viewsToClose:b,viewsToOpen:F}),b.length&&(b.forEach(y=>{var C,S;(S=(C=l.current[getKey(y)])==null?void 0:C.destroy)==null||S.call(C,!0),delete l.current[getKey(y)]}),updateViewListHidden(v)),F.length&&L(void 0,null,function*(){const y=F.filter(S=>!S.model);if(y.length>0&&(yield Promise.all(y.map(S=>L(void 0,null,function*(){try{S.model=yield t.loadModel({uid:S.modelUid})}catch(P){console.error(`[NocoBase] Failed to load model ${S.modelUid}:`,P)}})))),m.current)return;updateViewListHidden(v);const C=S=>{if(!F[S])return;const P=F[S];if(!P.model)return;const j=import_react2.default.createRef(),A=import_react2.default.createRef(),T=getOpenViewStepParams(P.model),N=v.slice(0,P.index).map(w=>w.params.viewUid),D=new import_flow_engine.ViewNavigation(t.context,v.slice(0,P.index+1).map(w=>w.params));P.model.dispatchEvent("click",I(x({target:e.current,collectionName:T==null?void 0:T.collectionName,associationName:T==null?void 0:T.associationName,dataSourceKey:T==null?void 0:T.dataSourceKey,destroyRef:j,updateRef:A,openerUids:N},P.params),{navigation:D,onOpen(){C(S+1)},hidden:P.hidden,isMobileLayout:i,triggerByRouter:!0})),l.current[getKey(P)]={destroy:w=>{var k;return(k=j.current)==null?void 0:k.call(j)},update:w=>{var k;return(k=A.current)==null?void 0:k.call(A,w)},navigation:D}};C(0)}),b.length===0&&F.length===0){const y=v.at(-1);y&&((f=l.current[getKey(y)])==null||f.navigation.setViewStack(v.map(C=>C.params)))}a.current=[...v]}catch(_){console.error("[NocoBase] Failed to resolve view params to view list:",_)}},{fireImmediately:!0});return()=>{h==null||h(),a.current.forEach(g=>{var f;t.removeModelWithSubModels(g.params.viewUid),(f=l.current[getKey(g)])==null||f.destroy()})}},[t,i,p]),(0,import_jsx_runtime.jsx)("div",{ref:e})},FlowPage=import_react2.default.memo(e=>{const t=e,{pageModelClass:o="ChildPageModel",parentId:r,onModelLoaded:i,defaultTabTitle:n}=t,l=te(t,["pageModelClass","parentId","onModelLoaded","defaultTabTitle"]),a=(0,import_flow_engine.useFlowEngine)(),c=(0,import_flow_engine.useFlowViewContext)(),{loading:u,data:d}=(0,import_ahooks.useRequest)(()=>L(void 0,null,function*(){var m;const p={async:!0,parentId:r,subKey:"page",subType:"object",use:o};if(o==="ChildPageModel"){const g=n||((m=a.translate)==null?void 0:m.call(a,"Details"));p.subModels={tabs:[{use:"ChildPageTabModel",stepParams:{pageTabSettings:{tab:{title:g}}}}]},p.stepParams={pageSettings:{general:{displayTitle:!1,enableTabs:!0}}}}const h=yield a.loadOrCreateModel(p,{skipSave:!a.context.flowSettingsEnabled});return h!=null&&h.uid&&i&&(h.context.addDelegate(c),h.removeParentDelegate(),i(h.uid,h)),h}),{refreshDeps:[r]});return u||!(d!=null&&d.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:c!=null&&c.isMobileLayout?8:c==null?void 0:c.themeToken.marginBlock}}):(0,import_jsx_runtime.jsx)(InternalFlowPage,x({uid:d.uid},l))});FlowPage.displayName="FlowPage";const RemoteFlowModelRenderer=e=>{const t=e,{uid:o,parentId:r,subKey:i}=t,n=te(t,["uid","parentId","subKey"]),l=(0,import_flow_engine.useFlowEngine)(),{loading:a,data:c}=(0,import_ahooks.useRequest)(()=>L(void 0,null,function*(){return yield l.loadModel({uid:o,parentId:r,subKey:i})}),{refreshDeps:[o,r,i]});return a||!(c!=null&&c.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:16}}):(0,import_jsx_runtime.jsx)(InternalFlowPage,x({uid:c.uid},n))};function PageTabChildrenRenderer({ctx:e,options:t}){const{data:o,loading:r}=(0,import_ahooks.useRequest)(()=>L(this,null,function*(){const n=yield e.engine.loadOrCreateModel(t,{skipSave:!e.flowSettingsEnabled});return n.context.addDelegate(e),n}),{refreshDeps:[e.model.uid]}),i=e!=null&&e.isMobileLayout?8:e==null?void 0:e.themeToken.marginBlock;return r||!(o!=null&&o.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i}}):(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:o,fallback:(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i}})})}function normalizePersistedRoute(e){if(Array.isArray(e))return e.find(t=>!!t&&typeof t=="object");if(e&&typeof e=="object")return e}class BasePageTabModel extends import_flow_engine.FlowModel{onInit(t){super.onInit(t),this.context.defineProperty("tabActive",{value:import_flow_engine.observable.ref(!0),info:{description:"Whether current tab is active (observable.ref).",detail:"observable.ref<boolean>"}})}getTabTitle(t="Untitled"){var o,r;const i=this.context.t(t,{ns:"client"});return this.context.t((r=(o=this.stepParams.pageTabSettings)==null?void 0:o.tab)==null?void 0:r.title,{ns:"lm-desktop-routes"})||i}getTabIcon(){var t,o;return(o=(t=this.stepParams.pageTabSettings)==null?void 0:t.tab)==null?void 0:o.icon}renderChildren(){return null}renderHiddenInConfig(){return(0,import_jsx_runtime.jsxs)("span",{style:{display:"inline-block",opacity:.5},children:[(0,import_jsx_runtime.jsx)(Icon,{style:{marginRight:8},type:this.getTabIcon()}),this.getTabTitle()]})}render(){return(0,import_jsx_runtime.jsxs)("span",{style:{display:"inline-block"},children:[(0,import_jsx_runtime.jsx)(Icon,{style:{marginRight:8},type:this.getTabIcon()}),this.getTabTitle()]})}}BasePageTabModel.registerFlow({key:"pageTabSettings",title:(0,import_flow_engine.tExpr)("Tab settings"),steps:{tab:{title:(0,import_flow_engine.tExpr)("Edit tab"),preset:!0,uiSchema:{title:{title:(0,import_flow_engine.tExpr)("Tab name"),"x-component":"Input","x-decorator":"FormItem",required:!0},documentTitle:{type:"string",title:(0,import_flow_engine.tExpr)("Document title"),description:(0,import_flow_engine.tExpr)("Used as the browser tab title when this tab is active. Supports variables. Leave empty to use Tab name."),"x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1,maxRows:6}},icon:{title:(0,import_flow_engine.tExpr)("Icon"),"x-decorator":"FormItem","x-component":"IconPicker"}},handler(e,t){return L(this,null,function*(){var o;const r=typeof(e==null?void 0:e.t)=="function"?e.t.bind(e):n=>n;e.model.setProps("title",r(t.title,{ns:"lm-desktop-routes"})),e.model.setProps("icon",t.icon);const i=e.engine.getModel(e.model.parentId);(o=i==null?void 0:i.updateDocumentTitle)==null||o.call(i)})}}}});class RootPageTabModel extends BasePageTabModel{renderChildren(){return(0,import_jsx_runtime.jsx)(PageTabChildrenRenderer,{ctx:this.context,options:{parentId:this.uid,subKey:"grid",async:!0,subType:"object",use:"BlockGridModel"}})}saveStepParams(){return L(this,null,function*(){return this.save()})}save(){return L(this,null,function*(){var t,o,r,i,n;const l=this.serialize(),a=(r=(o=(t=this.stepParams)==null?void 0:t.pageTabSettings)==null?void 0:o.tab)==null?void 0:r.documentTitle,c=yield this.context.api.request({method:"post",url:"desktopRoutes:updateOrCreate",params:{filterKeys:["schemaUid"]},data:I(x({},this.props.route),{title:this.getTabTitle(""),icon:this.getTabIcon(),options:{flowRegistry:l.flowRegistry,documentTitle:a}})}),u=normalizePersistedRoute((i=c==null?void 0:c.data)==null?void 0:i.data);u&&this.setProps("route",I(x(x({},this.props.route),u),{options:x(x({},(n=this.props.route)==null?void 0:n.options),u.options)}))})}destroy(){return L(this,null,function*(){return this.observerDispose(),this.invalidateFlowCache("beforeRender",!0),this.flowEngine.removeModel(this.uid),yield this.context.api.request({method:"post",url:"desktopRoutes:destroy",params:{filter:{schemaUid:this.uid}},data:this.props.route}),!0})}}class ChildPageTabModel extends BasePageTabModel{renderChildren(){return(0,import_jsx_runtime.jsx)(PageTabChildrenRenderer,{ctx:this.context,options:{parentId:this.uid,subKey:"grid",async:!0,subType:"object",use:"BlockGridModel"}})}}class PageTabModel extends import_flow_engine.FlowModel{render(){return(0,import_jsx_runtime.jsx)("div",{children:(0,import_jsx_runtime.jsx)(RemoteFlowModelRenderer,{parentId:this.uid,subKey:"grid",showFlowSettings:!1})})}}class RootPageModel extends PageModel{constructor(){super(...arguments),R(this,"mounted",!1)}ensurePersistedRouteId(t){return L(this,null,function*(){var o,r,i,n;const l=(r=(o=t==null?void 0:t.props)==null?void 0:o.route)==null?void 0:r.id;return l??(typeof(t==null?void 0:t.save)=="function"&&(yield t.save()),(n=(i=t==null?void 0:t.props)==null?void 0:i.route)==null?void 0:n.id)})}onMount(){super.onMount(),(0,import_flow_engine.reaction)(()=>this.context.pageActive.value,()=>{var t,o;if(this.context.pageActive.value&&this.mounted){const r=(t=this.subModels.tabs)==null?void 0:t[0];r&&(this.setProps("tabActiveKey",r.uid),this.invokeTabModelLifecycleMethod(r.uid,"onActive",!0))}if(this.context.pageActive.value===!1)if(this.props.tabActiveKey)this.invokeTabModelLifecycleMethod(this.props.tabActiveKey,"onInactive");else{const r=(o=this.subModels.tabs)==null?void 0:o[0];r&&this.invokeTabModelLifecycleMethod(r.uid,"onInactive")}this.mounted=!0})}saveStepParams(){return L(this,null,function*(){yield $e(RootPageModel.prototype,this,"saveStepParams").call(this),this.stepParams.pageSettings&&this.context.api.request({url:`desktopRoutes:update?filter[id]=${this.props.routeId}`,method:"post",data:{enableTabs:!!this.stepParams.pageSettings.general.enableTabs}})})}handleDragEnd(t){return L(this,null,function*(){var o,r;const i=this.flowEngine.getModel((o=t.active)==null?void 0:o.id),n=this.flowEngine.getModel((r=t.over)==null?void 0:r.id);if(!i||!n||i.uid===n.uid)return;const[l,a]=yield Promise.all([this.ensurePersistedRouteId(i),this.ensurePersistedRouteId(n)]);l==null||a==null||(yield this.context.api.request({url:"desktopRoutes:move",method:"post",params:{sourceId:l,targetId:a,sortField:"sort"}}),this.flowEngine.moveModel(i.uid,n.uid,{persist:!1}))})}}RootPageModel.registerFlow({key:"rootPageSettings",steps:{init:{handler(e,t){return L(this,null,function*(){var o,r;if(e.model.hasSubModel("tabs"))return;const i=e.routeRepository.getRouteBySchemaUid(e.model.parentId);e.model.setProps("routeId",i==null?void 0:i.id);const n=import_lodash.default.castArray(i==null?void 0:i.children);for(const l of n.sort((a,c)=>a.sort-c.sort)){if(l.hideInMenu)continue;const a=e.engine.createModel({parentId:e.model.uid,uid:l.schemaUid,subKey:"tabs",subType:"array",use:"RootPageTabModel",sortIndex:l.sort,props:{route:l},flowRegistry:(o=l.options)==null?void 0:o.flowRegistry,stepParams:{pageTabSettings:{tab:{title:l.title,icon:l.icon,documentTitle:(r=l.options)==null?void 0:r.documentTitle}}}});e.model.addSubModel("tabs",a)}})}}}});class SubPageModel extends OldPageModel{renderFirstTab(){var t;return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels.tabs)==null?void 0:t[0]})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.renderFirstTab()]})}}class PopupActionModel extends ActionModel{constructor(){super(...arguments),R(this,"defaultProps",{title:(0,import_flow_engine.tExpr)("Popup"),icon:"ExportOutlined"})}}PopupActionModel.define({label:(0,import_flow_engine.tExpr)("Popup")});PopupActionModel.registerFlow(openViewFlow);class RecordActionModel extends ActionModel{}RecordActionModel.define({children:e=>L(void 0,null,function*(){return(yield(0,import_flow_engine.buildSubModelItems)(ActionModel)(e)).filter(t=>e.engine.getModelClass(t.useModel)._isScene(ActionSceneEnum.record))})});class InputFieldModel extends FieldModel{render(){return(0,import_jsx_runtime.jsx)(import_antd.Input,x({},this.props))}}InputFieldModel.registerFlow({key:"defaultValueForNanoid",steps:{generateNanoid:{handler(e,t){var o,r;(r=(o=e.blockModel)==null?void 0:o.emitter)==null||r.on("onFieldReset",()=>{if(e.collectionField.interface==="nanoid"&&e.collectionField.options.autoFill!==!1){const{size:i,customAlphabet:n}=e.collectionField.options||{size:21};e.model.props.onChange((0,import_nanoid.customAlphabet)(n,i)())}})}}}});InputFieldModel.define({label:(0,import_flow_engine.tExpr)("Input")});import_flow_engine.EditableItemModel.bindModelToInterface("InputFieldModel",["input","email","phone","uuid","url","nanoid"],{isDefault:!0});import_flow_engine.FilterableItemModel.bindModelToInterface("InputFieldModel",["input","email","phone","uuid","url","nanoid","textarea","markdown","vditor","richText","password","color"],{isDefault:!0});const ARRAY_VALUE_OPERATORS=new Set(["$match","$notMatch","$anyOf","$noneOf","$childIn","$childNotIn","$in","$notIn"]);function isObjectWithType(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&"type"in e}function isEmptyScalar(e){return e===null||typeof e>"u"||typeof e=="string"&&e.trim()===""}function normalizeFilterValueByOperator(e,t){if(!e)return t;if(e==="$dateBetween"){if(t===null||typeof t>"u"||isObjectWithType(t))return t;if(Array.isArray(t)){if(t.length===0)return t;const o=t[0],r=t.length>1?t[1]:void 0,i=isEmptyScalar(o),n=isEmptyScalar(r);return t.length===1&&!i?[o,o]:!i&&n?[o,o]:i&&!n?[r,r]:t}return[t,t]}return ARRAY_VALUE_OPERATORS.has(e)?t===null||typeof t>"u"||Array.isArray(t)?t:typeof t=="string"&&t.trim()===""?[]:[t]:t}const stripTimeFromFormat=e=>e&&e.replace(/\s*HH?:mm(?::ss)?(?:\.SSS)?/g,"").trim();function getRawSingleValue(e,t){if(!t)return e;if(Array.isArray(e))return e[0]}function inferPickerFromRawValue(e,t){return typeof e=="string"?inferPickerType(e,t):t}function parseDateByFormat$1(e,t){const o=String(e||"").trim();if(!o)return null;if(/(?:Z|[+-]\d{2}:\d{2})$/i.test(o)){const i=(0,import_client.dayjs)(o);if(i.isValid())return i}if(t){const i=(0,import_client.dayjs)(o,t,!0);if(i.isValid())return i}const r=(0,import_client.dayjs)(o);if(r.isValid())return r;if(t){const i=(0,import_client.dayjs)(o,t);if(i.isValid())return i}return null}function parseDateFromRawValue$1(e,t){if(import_client.dayjs.isDayjs(e))return e;if(e instanceof Date){const o=(0,import_client.dayjs)(e);return o.isValid()?o:null}return typeof e=="string"?parseDateByFormat$1(e,t):null}function parseRangeValue(e,t){if(!Array.isArray(e))return null;const o=parseDateFromRawValue$1(e[0],t),r=parseDateFromRawValue$1(e[1],t);return!o||!r?null:[o,r]}const FieldAssignExactDatePicker=e=>{const{picker:t="date",format:o,showTime:r,timeFormat:i,value:n,isRange:l=!1,onChange:a,style:c}=e,u=(0,import_flow_engine.useFlowContext)(),d=u.model.translate.bind(u.model),m=(0,import_react2.useMemo)(()=>getRawSingleValue(n,l),[l,n]),[p,h]=(0,import_react2.useState)(()=>inferPickerFromRawValue(m,t)),g=S=>{const P=S===t&&o?o:(0,import_client.getPickerFormat)(S),j=S==="date"?stripTimeFromFormat(P):P;return(0,import_client.getDateTimeFormat)(S,j,r,i)},f=(0,import_react2.useMemo)(()=>g(p),[p,o,t,r,i]),_=(0,import_react2.useMemo)(()=>l?null:parseDateFromRawValue$1(n,f),[l,n,f]),v=(0,import_react2.useMemo)(()=>l?parseRangeValue(n,f):null,[l,n,f]),b=(0,import_react2.useMemo)(()=>[{label:d("Date"),value:"date"},{label:d("Month"),value:"month"},{label:d("Quarter"),value:"quarter"},{label:d("Year"),value:"year"}],[d]),F=S=>{if(h(S),!!a){if(l){v&&a(v);return}_&&a(_)}},y={utc:!0,underFilter:!0,format:f,picker:p,inputReadOnly:u.isMobileLayout,showTime:r?{defaultValue:(0,import_client.dayjs)("00:00:00","HH:mm:ss")}:!1,value:_,onChange:S=>{if(S&&import_client.dayjs.isDayjs(S)){a==null||a(S);return}a==null||a(null)},style:{flex:1}},C={utc:!0,underFilter:!0,format:f,picker:p,inputReadOnly:u.isMobileLayout,showTime:r?{defaultValue:[(0,import_client.dayjs)("00:00:00","HH:mm:ss"),(0,import_client.dayjs)("23:59:59","HH:mm:ss")]}:!1,value:v,onChange:S=>{if(Array.isArray(S)&&S[0]&&S[1]){a==null||a([S[0],S[1]]);return}a==null||a(null)},style:{flex:1}};return(0,import_jsx_runtime.jsxs)(import_antd.Space.Compact,{style:x({width:"100%"},c||{}),children:[(0,import_jsx_runtime.jsx)(import_antd.Select,{style:{width:100},popupMatchSelectWidth:!1,value:p,options:b,onChange:F}),l?(0,import_jsx_runtime.jsx)(import_antd.DatePicker.RangePicker,x({},C)):(0,import_jsx_runtime.jsx)(import_antd.DatePicker,x({},y))]})},DATE_FIELD_INTERFACES=new Set(["date","datetime","datetimeNoTz","createdAt","updatedAt","unixTimestamp"]),TZ_AWARE_DATE_INTERFACES=new Set(["datetime","createdAt","updatedAt","unixTimestamp"]),DATE_ONLY_OUTPUT_FORMAT="YYYY-MM-DD",DATETIME_NO_TZ_OUTPUT_FORMAT="YYYY-MM-DD HH:mm:ss",DATE_DYNAMIC_OPTION_KEYS=["exact","past","next","today","yesterday","tomorrow","thisWeek","lastWeek","nextWeek","thisMonth","lastMonth","nextMonth","thisQuarter","lastQuarter","nextQuarter","thisYear","lastYear","nextYear"],DATE_DYNAMIC_OPTION_LABELS={exact:"Exact day",past:"Past",next:"Next",today:"Today",yesterday:"Yesterday",tomorrow:"Tomorrow",thisWeek:"This Week",lastWeek:"Last Week",nextWeek:"Next Week",thisMonth:"This Month",lastMonth:"Last Month",nextMonth:"Next Month",thisQuarter:"This Quarter",lastQuarter:"Last Quarter",nextQuarter:"Next Quarter",thisYear:"This Year",lastYear:"Last Year",nextYear:"Next Year"};function buildDateDynamicOptions(e,t=!1){var o;const r=DATE_DYNAMIC_OPTION_KEYS.map(i=>{var n;return{value:i,label:(n=e==null?void 0:e(DATE_DYNAMIC_OPTION_LABELS[i]))!=null?n:DATE_DYNAMIC_OPTION_LABELS[i]}});return t&&r.splice(3,0,{value:"now",label:(o=e==null?void 0:e("Now"))!=null?o:"Now"}),r}function parseDateByFormat(e,t){const o=String(e||"").trim();if(!o)return null;if(/(?:Z|[+-]\d{2}:\d{2})$/i.test(o)){const i=(0,import_client.dayjs)(o);if(i.isValid())return i}if(t){const i=(0,import_client.dayjs)(o,t,!0);if(i.isValid())return i}const r=(0,import_client.dayjs)(o);if(r.isValid())return r;if(t){const i=(0,import_client.dayjs)(o,t);if(i.isValid())return i}return null}function parseDateFromRawValue(e,t){if(import_client.dayjs.isDayjs(e))return e;if(e instanceof Date){const o=(0,import_client.dayjs)(e);return o.isValid()?o:null}return typeof e=="string"?parseDateByFormat(e,t):null}function normalizeExactDateValue(e,t){const o=parseDateFromRawValue(e,t.format);if(!(o!=null&&o.isValid()))return e;switch(t.exactNormalizeMode){case"date":return o.format(DATE_ONLY_OUTPUT_FORMAT);case"datetimeNoTz":return o.format(t.showTime?DATETIME_NO_TZ_OUTPUT_FORMAT:DATE_ONLY_OUTPUT_FORMAT);case"iso":return o.toISOString();default:return e}}function toExactPickerSingleValue(e,t){const o=parseDateFromRawValue(e,t);return o!=null&&o.isValid()?o:null}function toExactPickerRangeValue(e,t){if(!Array.isArray(e))return null;const o=toExactPickerSingleValue(e[0],t),r=toExactPickerSingleValue(e[1],t);return!o||!r?null:[o,r]}function toExactPickerDisplayValue(e,t){return t.isRange?toExactPickerRangeValue(e,t.format):toExactPickerSingleValue(e,t.format)}function getDateVariableExactNormalizeMode(e){return e==="date"?"date":e==="datetimeNoTz"?"datetimeNoTz":TZ_AWARE_DATE_INTERFACES.has(e)?"iso":"none"}function normalizeDateVariableExactValue(e,t){return t.exactNormalizeMode==="none"?e:typeof e=="string"||import_client.dayjs.isDayjs(e)||e instanceof Date?normalizeExactDateValue(e,t):Array.isArray(e)?e.map(o=>typeof o=="string"||import_client.dayjs.isDayjs(o)||o instanceof Date?normalizeExactDateValue(o,t):o):e}function normalizeExactDatePickerMode(e){return e==="year"||e==="quarter"||e==="month"||e==="date"?e:"date"}const DEFAULT_DATE_VARIABLE_COMPONENT_PROPS={picker:"date",showTime:!1,timeFormat:"HH:mm:ss",format:"YYYY-MM-DD",exactNormalizeMode:"none"};function getFieldInterface(e){return typeof(e==null?void 0:e.interface)=="string"?e.interface:""}function getFieldComponentProps(e){var t;return(typeof(e==null?void 0:e.getComponentProps)=="function"?e.getComponentProps():null)||((t=e==null?void 0:e.uiSchema)==null?void 0:t["x-component-props"])||{}}function normalizeDateVariableOutput(e,t){if(e===null||(0,import_flow_engine.isRunJSValue)(e)||typeof e=="string"&&(0,import_flow_engine.isVariableExpression)(e)&&!(0,import_flow_engine.isCtxDateExpression)(e))return e;if(e===""||typeof e>"u")return"";const o=normalizeDateVariableExactValue(e,{exactNormalizeMode:t.exactNormalizeMode,format:t.format||"YYYY-MM-DD HH:mm:ss",showTime:t.showTime});return(0,import_flow_engine.serializeCtxDateValue)(o)||o}function isPlainObject$1(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function pickStyle(e){return isPlainObject$1(e)?e:void 0}function withFullWidthStyle(e){return I(x({},e),{width:"100%",minWidth:0})}function rewrapReactiveRender$1(e){var t;e&&(e._reactiveWrapperCache=void 0,(t=e.setupReactiveRender)==null||t.call(e))}function remapMetaTreePaths(e,t,o){const r=Array.isArray(e==null?void 0:e.paths)?e.paths.map(l=>String(l)):[];let i=r;t.length&&r.length>=t.length&&t.every((l,a)=>r[a]===l)&&(i=[...o,...r.slice(t.length)]);const n=l=>Array.isArray(l)?l.map(a=>remapMetaTreePaths(a,t,o)):typeof l=="function"?()=>L(this,null,function*(){const a=yield l();return Array.isArray(a)?a.map(c=>remapMetaTreePaths(c,t,o)):[]}):l;return I(x({},e),{paths:i,children:e!=null&&e.children?n(e.children):void 0})}function attachBaseItemAsParent(e,t){var o;if(!t)return e;const r=remapMetaTreePaths(t,["item"],["item","parentItem"]),i=I(x({},r),{name:"parentItem",title:((o=r.title)==null?void 0:o.replace("Current item","Parent item"))||"Parent item"}),n=l=>{const a=Array.isArray(l.children)?l.children:[];if(!a.some(u=>(u==null?void 0:u.name)==="parentItem"))return I(x({},l),{children:[...a,i]});const c=a.map(u=>(u==null?void 0:u.name)!=="parentItem"?u:n(u));return I(x({},l),{children:c})};return n(e)}function mergeItemMetaTreeForAssignValue(e,t){const o=Array.isArray(e)?e:[],r=Array.isArray(t)?t:[];if(!r.length)return o;const i=o.find(u=>(u==null?void 0:u.name)==="item"),n=r.find(u=>(u==null?void 0:u.name)==="item");if(!n)return o;const l=attachBaseItemAsParent(n,i),a=[];let c=!1;for(const u of o){if(!c&&(u==null?void 0:u.name)==="item"){a.push(l),c=!0;continue}a.push(u)}return c||a.push(l),a}function resolveAssignValueFieldPath(e){var t;if(!e)return;const o=((t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"fieldSettings","init"))||{};return(o==null?void 0:o.fieldPath)||getFormItemPreferredFieldPath(e)}function getAssignValueSubField(e){var t;const o=(t=e==null?void 0:e.subModels)==null?void 0:t.field;return o&&!Array.isArray(o)?o:void 0}const ASSIGN_VALUE_IGNORED_PROP_KEYS=new Set(["value","defaultValue","onChange","onClick","open","searchText","dropdownRender","popupRender","optionRender"]),ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE="RecordSelectFieldModel",ASSIGN_VALUE_ASSOCIATION_WRAPPER_MODEL_USES=new Set(["FieldModel","SubFormFieldModel","SubFormListFieldModel","SubTableFieldModel","PopupSubTableFieldModel","RecordPickerFieldModel"]);function getAssignValueOriginFieldModel(e){return(e==null?void 0:e.customFieldModelInstance)||getAssignValueSubField(e)}function pickAssignValueString(...e){return e.find(t=>typeof t=="string"&&!!t)}function pickAssignValueBoolean(...e){return e.find(t=>typeof t=="boolean")}function isAssignValueAssociationWrapperModelUse(e){return!!e&&ASSIGN_VALUE_ASSOCIATION_WRAPPER_MODEL_USES.has(e)}function isAssignValueAssociationSelectModelUse(e){var t;return(t=e==null?void 0:e.endsWith("RecordSelectFieldModel"))!=null?t:!1}function resolveAssignValueFieldSource(e){var t,o,r,i,n,l,a,c,u,d,m,p,h;const g=getAssignValueSubField(e),f=(o=(t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"formItemSettings","fieldSettings"))!=null?o:{},_=getAssignValueOriginFieldModel(e),v=(r=_==null?void 0:_.props)!=null?r:{},b=(n=(i=e==null?void 0:e.customFieldProps)!=null?i:f==null?void 0:f.fieldModelProps)!=null?n:{};return{originFieldModel:_,originProps:v,customFieldName:pickAssignValueString(f==null?void 0:f.name),customFieldProps:b,currentAllowMultiple:pickAssignValueBoolean((a=(l=_==null?void 0:_.getStepParams)==null?void 0:l.call(_,"selectSettings","allowMultiple"))==null?void 0:a.allowMultiple,(d=(u=(c=_==null?void 0:_.stepParams)==null?void 0:c.selectSettings)==null?void 0:u.allowMultiple)==null?void 0:d.allowMultiple,v==null?void 0:v.allowMultiple,v==null?void 0:v.multiple,b==null?void 0:b.allowMultiple,b==null?void 0:b.multiple),currentFieldModelUse:pickAssignValueString((p=(m=g==null?void 0:g.stepParams)==null?void 0:m.fieldBinding)==null?void 0:p.use,g==null?void 0:g.use,f==null?void 0:f.fieldModel,(h=e==null?void 0:e.customFieldModelInstance)==null?void 0:h.use)}}function resolveAssignValueFieldSettingsInit(e){const{collection:t,customFieldName:o,fieldPath:r,fieldName:i}=e;if(!(t!=null&&t.name)||!r)return;const n=r.startsWith(`${CUSTOM_FIELD_TARGET_PATH_PREFIX}:`)&&(o||i)||r;return{dataSourceKey:t.dataSourceKey,collectionName:t.name,fieldPath:n}}function sanitizeAssignValueInheritedProps(e){const t={};for(const[o,r]of Object.entries(e??{}))ASSIGN_VALUE_IGNORED_PROP_KEYS.has(o)||/^on[A-Z]/.test(o)||(t[o]=r);return t}function resolveAssignValueFieldProps(e){var t;const{placeholder:o,originProps:r,customFieldProps:i,collectionField:n}=e,l=sanitizeAssignValueInheritedProps(r),a=sanitizeAssignValueInheritedProps(i),c=x(x({placeholder:o},l),a);return(t=n==null?void 0:n.isAssociationField)!=null&&t.call(n)&&(delete c.mode,c.quickCreate="none"),c}function normalizeAssignValueAssociationFieldModelUse(e){return isAssignValueAssociationWrapperModelUse(e)?void 0:e}function resolveAssignValueAssociationFieldModelUse(e){var t,o;const{currentFieldModelUse:r,defaultBindingUse:i,preferFormItemFieldModel:n}=e,l=normalizeAssignValueAssociationFieldModelUse(r),a=normalizeAssignValueAssociationFieldModelUse(i);return isAssignValueAssociationWrapperModelUse(r)?a??ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE:n?(t=l??a)!=null?t:ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE:(o=a??l)!=null?o:ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE}function resolveAssignValueFieldMode(e){var t,o,r;const{fieldModelUse:i,collectionField:n}=e,l=(o=(t=n==null?void 0:n.uiSchema)==null?void 0:t["x-component-props"])==null?void 0:o.mode;return(r=n==null?void 0:n.isAssociationField)!=null&&r.call(n)&&isAssignValueAssociationSelectModelUse(i)?"Select":(n==null?void 0:n.interface)==="multipleSelect"?l??"multiple":l}function resolveAssignValueFieldModelConfig(e){var t,o,r,i;const{itemModel:n,defaultBindingUse:l,collectionField:a,preferFormItemFieldModel:c,fieldSettingsInit:u}=e,d=(t=e.fieldSource)!=null?t:resolveAssignValueFieldSource(n),{currentFieldModelUse:m,originFieldModel:p}=d,h=(o=a==null?void 0:a.isAssociationField)!=null&&o.call(a)?resolveAssignValueAssociationFieldModelUse({currentFieldModelUse:m,defaultBindingUse:l,preferFormItemFieldModel:c}):c?m??l:l??m,g=(r=p==null?void 0:p.stepParams)!=null?r:{},f=te(g,["fieldBinding"]),_=x({},f);return u&&(_.fieldSettings=I(x({},_.fieldSettings),{init:x(x({},(i=_.fieldSettings)==null?void 0:i.init),u)})),{use:h,stepParams:_}}const FieldAssignValueInput=({targetPath:e,value:t,onChange:o,placeholder:r,extraMetaTree:i,operator:n,operatorMetaList:l,preferFormItemFieldModel:a,associationFieldNamesOverride:c,enableDateVariableAsConstant:u=!1})=>{var d,m,p,h;const g=(0,import_flow_engine.useFlowContext)(),f=import_react2.default.useCallback(G=>{if(!G||typeof G!="object"||!("target"in G))return G;const X=G.target;return!X||typeof X!="object"||!("value"in X)?G:X.value},[]),_=import_react2.default.useRef(i);import_react2.default.useEffect(()=>{_.current=i},[i]);const v=import_react2.default.useMemo(()=>e?findFormItemModelByFieldPath(g.model,e):null,[g.model,e]),b=import_react2.default.useCallback((G,X)=>{var ie;if(!G||typeof X!="string"||!X.includes("."))return null;const ee=X.split(".").filter(Boolean);if(ee.length<2)return null;let ne=G;for(let le=0;le<ee.length;le++){const me=ee[le],he=le===ee.length-1,ae=typeof(ne==null?void 0:ne.getField)=="function"?ne.getField(me):void 0;if(!ae)return null;if(he)return{collection:ne,fieldName:me,collectionField:ae};if(!((ie=ae==null?void 0:ae.isAssociationField)!=null&&ie.call(ae))||!(ae!=null&&ae.targetCollection))return null;ne=ae.targetCollection}return null},[]),F=import_react2.default.useMemo(()=>{var G,X,ie,ee,ne,le,me,he,ae,xe,ge,ve,de,ce,se,ue,pe,_e;if(v){const Se=v,Ne=v.context,{collection:De,dataSource:Le,blockModel:Re}=Ne,Me=((G=v==null?void 0:v.getStepParams)==null?void 0:G.call(v,"fieldSettings","init"))||{},Te=((X=v==null?void 0:v.context)==null?void 0:X.dataSourceManager)||((ee=(ie=g.model)==null?void 0:ie.context)==null?void 0:ee.dataSourceManager),Je=getCollectionFromModel(g.model),Oe=De||(Me!=null&&Me.dataSourceKey&&Me!=null&&Me.collectionName?(ne=Te==null?void 0:Te.getCollection)==null?void 0:ne.call(Te,Me.dataSourceKey,Me.collectionName):void 0)||Je,rt=Le||(Me!=null&&Me.dataSourceKey?(le=Te==null?void 0:Te.getDataSource)==null?void 0:le.call(Te,Me.dataSourceKey):void 0)||(Oe!=null&&Oe.dataSourceKey?(me=Te==null?void 0:Te.getDataSource)==null?void 0:me.call(Te,Oe.dataSourceKey):void 0),Ue=resolveAssignValueFieldPath(v),ze=Ue==null?void 0:Ue.split(".").slice(-1)[0],Ke=ze?(he=Oe==null?void 0:Oe.getField)==null?void 0:he.call(Oe,ze):void 0,We=(xe=(ae=Se==null?void 0:Se.customFieldModelInstance)==null?void 0:ae.context)==null?void 0:xe.collectionField;return{itemModel:v,collection:Oe||null,dataSource:rt||null,blockModel:Re,fieldPath:Ue||null,fieldName:ze||null,collectionField:Ke||We||null}}const fe=getCollectionFromModel(g.model),Ce=((ve=(ge=g.model)==null?void 0:ge.context)==null?void 0:ve.blockModel)||g.model,Ie={itemModel:null,collection:null,dataSource:null,blockModel:Ce,fieldPath:null,fieldName:null,collectionField:null},je=typeof(fe==null?void 0:fe.getField)=="function"?fe.getField(e):null;if(je){const Se=String((je==null?void 0:je.name)||e||""),Ne=(ce=(de=g.model)==null?void 0:de.context)==null?void 0:ce.dataSourceManager,De=(fe!=null&&fe.dataSourceKey?(se=Ne==null?void 0:Ne.getDataSource)==null?void 0:se.call(Ne,fe.dataSourceKey):void 0)||null;return I(x({},Ie),{collection:fe,dataSource:De,blockModel:Ce,fieldPath:Se,fieldName:Se,collectionField:je||null})}const ke=b(fe,e);if(!ke)return Ie;const we=ke.collection,ye=ke.fieldName,be=(pe=(ue=g.model)==null?void 0:ue.context)==null?void 0:pe.dataSourceManager,Ae=(we!=null&&we.dataSourceKey?(_e=be==null?void 0:be.getDataSource)==null?void 0:_e.call(be,we.dataSourceKey):void 0)||null;return I(x({},Ie),{collection:we,dataSource:Ae,blockModel:Ce,fieldPath:ye,fieldName:ye,collectionField:ke.collectionField||null})},[g.model,v,b,e]),{collection:y,dataSource:C,blockModel:S,fieldPath:P,fieldName:j,collectionField:A}=F,T=(m=(d=F==null?void 0:F.itemModel)==null?void 0:d.context)==null?void 0:m.collectionField,N=import_react2.default.useMemo(()=>resolveAssignValueFieldSource(v),[v]),D=import_react2.default.useMemo(()=>{var G;const X=A||T||null;if(!(!((G=X==null?void 0:X.isAssociationField)!=null&&G.call(X))||!isToManyAssociationField(X)))return N.currentAllowMultiple},[A,N.currentAllowMultiple,T]),w=import_react2.default.useMemo(()=>getFieldInterface(A)||getFieldInterface(T),[A,T]),k=A||T,B=import_react2.default.useMemo(()=>{var G,X,ie;if((G=A==null?void 0:A.isAssociationField)!=null&&G.call(A)||(X=T==null?void 0:T.isAssociationField)!=null&&X.call(T)){const ne=A||T||null;if(ne&&isToManyAssociationField(ne))return D??!0}const ee=getFieldInterface(A);return ee==="multipleSelect"||ee==="checkboxGroup"||((ie=A==null?void 0:A.uiSchema)==null?void 0:ie.type)==="array"},[A,D,T]),E=import_react2.default.useMemo(()=>{if(w&&DATE_FIELD_INTERFACES.has(w))return!0;const G=typeof j=="string"&&j||(typeof e=="string"?e.split(".").filter(Boolean).slice(-1)[0]:"");return G==="createdAt"||G==="updatedAt"},[j,w,e]),M=u&&E,O=import_react2.default.useMemo(()=>{if(!M)return DEFAULT_DATE_VARIABLE_COMPONENT_PROPS;const G=getFieldComponentProps(k),X=normalizeExactDatePickerMode(G==null?void 0:G.picker),ie=["datetime","datetimeNoTz","createdAt","updatedAt","unixTimestamp"].includes(w),ee=typeof(G==null?void 0:G.showTime)=="boolean"?G.showTime:ie,ne=typeof(G==null?void 0:G.dateFormat)=="string"&&G.dateFormat?G.dateFormat:typeof(G==null?void 0:G.format)=="string"&&G.format?G.format.split(" ")[0]:"YYYY-MM-DD",le=typeof(G==null?void 0:G.timeFormat)=="string"&&G.timeFormat?G.timeFormat:"HH:mm:ss",me=typeof(G==null?void 0:G.format)=="string"&&G.format?G.format:ee?`${ne} ${le}`:ne;return{picker:X,showTime:ee,timeFormat:le,format:me,exactNormalizeMode:getDateVariableExactNormalizeMode(w)}},[k,w,M]),q=import_react2.default.useMemo(()=>te(O,["exactNormalizeMode"]),[O]),$=import_react2.default.useRef(q);$.current=q;const V=import_react2.default.useRef(g.t);V.current=g.t;const U=import_react2.default.useCallback(G=>{let X=G;if(n&&(X=normalizeFilterValueByOperator(n,X)),B){if(X==null||X==="")return[];if(!Array.isArray(X))return[X]}return X},[B,n]),[z,K]=import_react2.default.useState(null);import_react2.default.useEffect(()=>{var G,X,ie,ee,ne,le,me,he,ae,xe,ge,ve,de,ce,se,ue,pe,_e,fe,Ce,Ie,je,ke,we,ye,be,Ae,Se,Ne,De,Le,Re,Me,Te,Je,Oe,rt,Ue;if(!P||!j)return;const ze=v,Ke=((X=(G=F==null?void 0:F.itemModel)==null?void 0:G.context)==null?void 0:X.engine)||((ee=(ie=g.model)==null?void 0:ie.context)==null?void 0:ee.engine);if(!Ke)return;const We=((ne=ze==null?void 0:ze.context)==null?void 0:ne.dataSourceManager)||((me=(le=g.model)==null?void 0:le.context)==null?void 0:me.dataSourceManager),Ee=y||getCollectionFromModel(ze)||getCollectionFromModel(g.model),{customFieldName:Ft,customFieldProps:Pt,currentAllowMultiple:ut,originFieldModel:dt,originProps:It}=N,kt=(he=dt==null?void 0:dt.context)==null?void 0:he.collectionField,Fe=A||kt||void 0,mt=C||(Ee!=null&&Ee.dataSourceKey?(ae=We==null?void 0:We.getDataSource)==null?void 0:ae.call(We,Ee.dataSourceKey):null),pt=(typeof(Ee==null?void 0:Ee.getFields)=="function"?Ee.getFields()||[]:[]).find(Ve=>(Ve==null?void 0:Ve.name)===j)||(typeof(Ee==null?void 0:Ee.getField)=="function"?Ee.getField(j):void 0)||Fe,ht=pt?import_flow_engine.EditableItemModel.getDefaultBindingByField(((xe=F==null?void 0:F.itemModel)==null?void 0:xe.context)||((ge=g.model)==null?void 0:ge.context),pt):null,At=ht==null?void 0:ht.modelName,Bt=resolveAssignValueFieldSettingsInit({collection:Ee,customFieldName:Ft,fieldPath:P,fieldName:j}),{use:it,stepParams:Nt}=resolveAssignValueFieldModelConfig({itemModel:v,defaultBindingUse:At,collectionField:Fe,fieldSource:N,preferFormItemFieldModel:a,fieldSettingsInit:Bt});if(!it)return;const Lt=resolveAssignValueFieldProps({placeholder:r,originProps:It,customFieldProps:Pt,collectionField:Fe}),Be=(ve=Ke==null?void 0:Ke.createModel)==null?void 0:ve.call(Ke,{use:"VariableFieldFormModel",subModels:{fields:[{use:it,stepParams:Nt,props:Lt}]}});if(!Be)return;Ee&&((ce=(de=Be.context)==null?void 0:de.defineProperty)==null||ce.call(de,"collection",{value:Ee})),mt&&((ue=(se=Be.context)==null?void 0:se.defineProperty)==null||ue.call(se,"dataSource",{value:mt})),Fe&&((_e=(pe=Be.context)==null?void 0:pe.defineProperty)==null||_e.call(pe,"collectionField",{value:Fe})),S&&((Ce=(fe=Be.context)==null?void 0:fe.defineProperty)==null||Ce.call(fe,"blockModel",{value:S})),Be.context&&Object.defineProperty(Be.context,"resource",{configurable:!0,enumerable:!0,get:()=>S==null?void 0:S.resource});const Pe=(je=(Ie=Be==null?void 0:Be.subModels)==null?void 0:Ie.fields)==null?void 0:je[0],nt=(ke=Fe==null?void 0:Fe.isAssociationField)!=null&&ke.call(Fe)&&isToManyAssociationField(Fe)?ut??!0:void 0,gt=nt??((we=Fe==null?void 0:Fe.isAssociationField)!=null&&we.call(Fe)?isToManyAssociationField(Fe):void 0),Ot=withFullWidthStyle(pickStyle((ye=Pe==null?void 0:Pe.props)==null?void 0:ye.style)),ft=c==null?void 0:c.label;ft&&typeof(Pe==null?void 0:Pe.setStepParams)=="function"&&Pe.setStepParams("selectSettings","fieldNames",{label:ft}),(be=Pe==null?void 0:Pe.setProps)==null||be.call(Pe,x(x({disabled:!1,readPretty:!1,pattern:"editable",updateAssociation:!1,style:Ot},gt!==void 0?{multiple:gt}:{}),nt!==void 0?{allowMultiple:nt}:{})),(Ae=Pe==null?void 0:Pe.dispatchEvent)==null||Ae.call(Pe,"beforeRender",void 0,{sequential:!0,useCache:!0}),ensureOptionsFromUiSchemaEnumIfAbsent(Pe,Fe);const xt=resolveAssignValueFieldMode({fieldModelUse:it,collectionField:Fe});if(((Se=Fe==null?void 0:Fe.isAssociationField)!=null&&Se.call(Fe)&&isAssignValueAssociationSelectModelUse(it)||((Ne=Pe==null?void 0:Pe.props)==null?void 0:Ne.mode)===void 0)&&xt&&((De=Pe==null?void 0:Pe.setProps)==null||De.call(Pe,{mode:xt})),Fe!=null&&Fe.targetCollection){const Ve=Fe.targetCollection,qe=((Le=Pe==null?void 0:Pe.props)==null?void 0:Le.fieldNames)||{},lt=(Je=(Te=(Me=(Re=c==null?void 0:c.value)!=null?Re:qe==null?void 0:qe.value)!=null?Me:Fe==null?void 0:Fe.targetKey)!=null?Te:Ve==null?void 0:Ve.filterTargetKey)!=null?Je:"id",_t=(rt=(Oe=c==null?void 0:c.label)!=null?Oe:qe==null?void 0:qe.label)!=null?rt:Fe==null?void 0:Fe.targetCollectionTitleFieldName;(Ue=Pe==null?void 0:Pe.setProps)==null||Ue.call(Pe,{fieldNames:I(x(x({},qe),_t?{label:_t}:{}),{value:lt})})}return K(Be),()=>{var Ve,qe;(qe=(Ve=Be.subModels.fields).forEach)==null||qe.call(Ve,lt=>lt.remove()),Be.remove()}},[y,C,S,P,j,g,r,F,A,v,N,a,c==null?void 0:c.label,c==null?void 0:c.value]),import_react2.default.useEffect(()=>{var G,X,ie,ee,ne,le,me,he;const ae=(X=(G=z==null?void 0:z.subModels)==null?void 0:G.fields)==null?void 0:X[0];if(!ae||!n||!Array.isArray(l)||l.length===0)return;const xe=l.find(ce=>(ce==null?void 0:ce.value)===n),ge=(ie=xe==null?void 0:xe.schema)==null?void 0:ie["x-component-props"];if(ge&&typeof(ae==null?void 0:ae.setProps)=="function"){const ce=withFullWidthStyle(pickStyle(ge==null?void 0:ge.style)||pickStyle((ee=ae==null?void 0:ae.props)==null?void 0:ee.style));ae.setProps(I(x({},ge),{style:ce}))}const ve=((le=(ne=F==null?void 0:F.itemModel)==null?void 0:ne.context)==null?void 0:le.app)||((he=(me=g==null?void 0:g.model)==null?void 0:me.context)==null?void 0:he.app),de=resolveOperatorComponent(ve,n,l);if(de&&ae instanceof InputFieldModel){const ce=ae.__originalRender||ae.render;ae.__originalRender=ce;const{Comp:se,props:ue}=de;ae.render=()=>{var pe;return(0,import_jsx_runtime.jsx)(se,I(x(x({},ae.props),ue),{style:x(x({width:"100%"},(pe=ae.props)==null?void 0:pe.style),ue==null?void 0:ue.style)}))},rewrapReactiveRender$1(ae)}else typeof ae.__originalRender=="function"&&(ae.render=ae.__originalRender,rewrapReactiveRender$1(ae))},[n,l,z,g,F]);const W=import_react2.default.useMemo(()=>G=>{const X=pickStyle(G==null?void 0:G.style);return import_react2.default.useEffect(()=>{var ie,ee,ne,le;const me=U(G==null?void 0:G.value),he=xe=>{var ge,ve,de,ce,se;const ue=f(xe),pe=n?normalizeFilterValueByOperator(n,ue):ue,_e=U(pe);(ge=z==null?void 0:z.setProps)==null||ge.call(z,{value:_e});const fe=(de=(ve=z==null?void 0:z.subModels)==null?void 0:ve.fields)==null?void 0:de[0];(ce=fe==null?void 0:fe.setProps)==null||ce.call(fe,{value:_e}),(se=G==null?void 0:G.onChange)==null||se.call(G,pe)},ae=(ee=(ie=z==null?void 0:z.subModels)==null?void 0:ie.fields)==null?void 0:ee[0];(ne=ae==null?void 0:ae.setProps)==null||ne.call(ae,{value:me,onChange:he,onCompositionStart:G==null?void 0:G.onCompositionStart,onCompositionUpdate:G==null?void 0:G.onCompositionUpdate,onCompositionEnd:G==null?void 0:G.onCompositionEnd}),(le=z==null?void 0:z.setProps)==null||le.call(z,I(x({},G),{value:me,onChange:he}))},[G]),z?(0,import_jsx_runtime.jsx)("div",{style:I(x({},withFullWidthStyle(X)),{flex:1}),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:z,showFlowSettings:!1})}):(0,import_jsx_runtime.jsx)(import_antd.Input,{value:G==null?void 0:G.value,onChange:ie=>{var ee;return(ee=G==null?void 0:G.onChange)==null?void 0:ee.call(G,f(ie))},placeholder:r,style:withFullWidthStyle(X)})},[r,z,U,f]),Y=import_react2.default.useMemo(()=>G=>{var X,ie,ee,ne;const le=pickStyle(G==null?void 0:G.style),me=G==null?void 0:G.value,he=(0,import_flow_engine.isCtxDateExpression)(me)?(0,import_flow_engine.parseCtxDateExpression)(me):me,ae=typeof he>"u"?void 0:he,{token:xe}=import_antd.theme.useToken(),[ge,ve]=import_react2.default.useState(!1),de=V.current,ce=$.current,se=import_react2.default.useMemo(()=>buildDateDynamicOptions(de,!0),[de]),ue=ae&&typeof ae=="object"&&!Array.isArray(ae)?ae==null?void 0:ae.type:void 0,pe=typeof ue=="string"&&ue?ue:"exact",_e=Array.isArray(ae),fe=toExactPickerDisplayValue(ae,{format:ce.format,isRange:!1}),Ce=toExactPickerDisplayValue(ae,{format:ce.format,isRange:!0}),Ie=ye=>{var be,Ae;if(ve(!1),ye==="exact"){(be=G==null?void 0:G.onChange)==null||be.call(G,"");return}const Se={type:ye};(ye==="past"||ye==="next")&&(Se.number=1,Se.unit="day"),(Ae=G==null?void 0:G.onChange)==null||Ae.call(G,Se)},je=ye=>{var be;(be=G==null?void 0:G.onChange)==null||be.call(G,ye||"")},ke=ye=>{var be;(be=G==null?void 0:G.onChange)==null||be.call(G,ye||"")},we=()=>{const ye=se.slice(0,3),be=se.slice(3),Ae=import_css.css`
1769
+ ${c}`}class DataBlockModel extends BlockModel{}DataBlockModel.define({hide:!0,label:(0,import_flow_engine.tExpr)("Data blocks"),children(e){return L(this,null,function*(){const t=yield(0,import_flow_engine.buildSubModelItems)(DataBlockModel)(e),{collectionName:o,filterByTk:r,scene:i}=e.view.inputArgs;return t.filter(n=>{var l,a,c,u,d,m,p;const h=e.engine.getModelClass(n.useModel);return i==="select"?(l=h._isScene)==null?void 0:l.call(h,"select"):i==="subForm"?(a=h._isScene)==null?void 0:a.call(h,"subForm"):i==="bulkEditForm"?(c=h._isScene)==null?void 0:c.call(h,"bulkEditForm"):i==="new"||o&&!r?(u=h._isScene)==null?void 0:u.call(h,"new"):!h._isScene||!((d=h._isScene)!=null&&d.call(h,"select"))&&!((m=h._isScene)!=null&&m.call(h,"subForm"))&&!((p=h._isScene)!=null&&p.call(h,"bulkEditForm"))})})}});class CollectionBlockModel extends DataBlockModel{constructor(){super(...arguments),R(this,"isManualRefresh",!1),R(this,"collectionRequired",!0),R(this,"previousBeforeRenderHash"),R(this,"lastSeenDirtyVersion",null),R(this,"dirtyRefreshing",!1)}onMount(){super.onMount(),this.previousBeforeRenderHash=this.context.location.search}getDirtyTrackingVersion(t,o,r,i){var n;const l=new Set,a=((n=r==null?void 0:r.getResourceName)==null?void 0:n.call(r))||i.associationName||i.collectionName;a&&l.add(String(a)),i.associationName&&l.add(String(i.associationName)),i.collectionName&&l.add(String(i.collectionName));let c=0;for(const u of l)c+=t.getDataSourceDirtyVersion(o,u);return c}onActive(t=!1){if(!this.hidden&&this.previousBeforeRenderHash!==this.context.location.search&&(this.rerender(),!t)||this.hidden)return;const o=this.context.resource;if(!o)return;const r=this.getResourceSettingsInitParams(),i=o.getDataSourceKey()||r.dataSourceKey||"main",n=this.context.engine,l=this.getDirtyTrackingVersion(n,i,o,r);if(t){if(this.dirtyRefreshing)return;this.dirtyRefreshing=!0,o.refresh().then(()=>{this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(n,i,o,r)}).catch(()=>{}).finally(()=>{this.dirtyRefreshing=!1});return}this.isManualRefresh||!(this.lastSeenDirtyVersion===null||l!==this.lastSeenDirtyVersion)||this.dirtyRefreshing||(this.dirtyRefreshing=!0,o.refresh().then(()=>{this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(n,i,o,r)}).catch(()=>{}).finally(()=>{this.dirtyRefreshing=!1}))}static filterCollection(t){return!!t.filterTargetKey}static isCollectionAvailable(t){if(!t)return!1;const o=getBlockCapabilityNamesFromModelClass(this);return areCapabilitiesSupported(t,o)}static defineChildren(t){return L(this,null,function*(){const o=m=>{var p;if(!((p=this.meta)!=null&&p.createModelOptions))return m||{};if(typeof this.meta.createModelOptions=="function"){const h=this.meta.createModelOptions(t);return import_lodash.default.merge({},h,m)}return import_lodash.default.merge({},this.meta.createModelOptions,m)},r=m=>this.name+m,{dataSourceKey:i,collectionName:n,associationName:l,filterByTk:a}=t.view.inputArgs,c=t.dataSourceManager.getDataSources().map(m=>m.getCollections().length===0?null:{key:r(`ds-${m.key}`),label:m.displayName,searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),children:p=>m.getCollections().map(h=>{if(!this.filterCollection(h)||!this.isCollectionAvailable(h))return null;const g={dataSourceKey:h.dataSourceKey,collectionName:h.name};return{key:r(`ds-${m.key}.${h.name}`),label:h.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:g}}})}}).filter(Boolean)}).filter(Boolean),u=m=>c.length===1?c[0].children(m):c;if(!n)return u(t);if(this._isScene("select")){const m={dataSourceKey:i,collectionName:n};l&&(m.associationName=l,m.sourceId="{{ctx.view.inputArgs.sourceId}}");const p=t.dataSourceManager.getCollection(i,n),h=[];return this.isCollectionAvailable(p)&&h.push({key:r("current-collection"),label:"Current collection",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:m}}})}),h.push({key:r("others-collections"),label:"Other collections",children:u(t)}),h}if(this._isScene("new")){const m={dataSourceKey:i,collectionName:n};l&&(m.associationName=l,m.sourceId="{{ctx.view.inputArgs.sourceId}}");const p=[],h=t.dataSourceManager.getCollection(i,n);return this.isCollectionAvailable(h)&&p.push({key:r("current-collection"),label:"Current collection",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:m}}})}),typeof a<"u"&&a!==null&&p.push({key:r("associated"),label:"Associated records",children:()=>t.dataSourceManager.getCollection(i,n).getAssociationFields(this._getScene()).map(g=>{if(!g.targetCollection||g.type==="belongsToArray"||!this.filterCollection(g.targetCollection)||!this.isCollectionAvailable(g.targetCollection))return null;let f=`{{ctx.popup.record.${g.sourceKey||g.collection.filterTargetKey}}}`;g.sourceKey===g.collection.filterTargetKey&&(f="{{ctx.view.inputArgs.filterByTk}}");const _={dataSourceKey:i,collectionName:g.target,associationName:g.resourceName,sourceId:f};return{key:r(`associated-${g.name}`),label:g.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:_}}})}}).filter(Boolean)}),p.push({key:r("others-collections"),label:"Other collections",children:u(t)}),p}const d=[{key:r("associated"),label:"Associated records",children:()=>t.dataSourceManager.getCollection(i,n).getAssociationFields(this._getScene()).map(m=>{if(!m.targetCollection||m.type==="belongsToArray"||!this.filterCollection(m.targetCollection)||!this.isCollectionAvailable(m.targetCollection))return null;let p=`{{ctx.popup.record.${m.sourceKey||m.collection.filterTargetKey}}}`;m.sourceKey===m.collection.filterTargetKey&&(p="{{ctx.view.inputArgs.filterByTk}}");const h={dataSourceKey:i,collectionName:m.target,associationName:m.resourceName,sourceId:p};return{key:r(`associated-${m.name}`),label:m.title,useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:h}}})}}).filter(Boolean)},{key:r("others-records"),label:"Other records",children:u(t)}];if(this._isScene("one")){const m=t.dataSourceManager.getCollection(i,n);if(!m||!this.filterCollection(m)||!this.isCollectionAvailable(m))return d;const p={dataSourceKey:i,collectionName:n,filterByTk:"{{ctx.view.inputArgs.filterByTk}}"};l&&(p.associationName=l,p.sourceId="{{ctx.view.inputArgs.sourceId}}"),d.unshift({key:r("current-record"),label:"Current record",useModel:this.name,createModelOptions:o({stepParams:{resourceSettings:{init:p}}})})}return d})}get dataSource(){return this.context.dataSource}get collection(){return this.context.collection}get resource(){return this.context.resource}get association(){return this.context.association}get associationField(){return this.context.association}getAclActionName(){return"view"}getFilterFields(){return L(this,null,function*(){return this.collection.getFields().filter(t=>t.filterable)})}getResourceSettingsInitParams(){return this.getStepParams("resourceSettings","init")}onInit(t){super.onInit(t),this.context.defineProperty("blockModel",{value:this}),this.context.defineProperty("actionName",{get:()=>this.getAclActionName(),cache:!1}),this.context.defineProperty("resourceName",{get:()=>this.resource.getResourceName(),cache:!1}),this.context.defineProperty("dataSource",{get:()=>{const o=this.getResourceSettingsInitParams();return this.context.dataSourceManager.getDataSource(o.dataSourceKey)}}),this.context.defineProperty("collection",{get:()=>{const o=this.getResourceSettingsInitParams();return this.context.dataSourceManager.getCollection(o.dataSourceKey,o.collectionName)}}),this.context.defineProperty("resource",{get:()=>{const o=this.getResourceSettingsInitParams(),r=this.createResource(this.context,o);r.setDataSourceKey(o.dataSourceKey),r.setResourceName(o.associationName||o.collectionName);const i=()=>{var n;const l=this.context.engine;if(!(l!=null&&l.getDataSourceDirtyVersion))return;const a=((n=r.getDataSourceKey)==null?void 0:n.call(r))||o.dataSourceKey||"main";this.lastSeenDirtyVersion=this.getDirtyTrackingVersion(l,a,r,o)};return i(),r.on("refresh",()=>{i(),this.invalidateFlowCache("beforeRender")}),r}}),this.context.defineProperty("association",{get:()=>{const o=this.getResourceSettingsInitParams();if(o.associationName)return this.dataSource.getAssociation(o.associationName)}})}createResource(t,o){throw new Error("createResource method must be implemented in subclasses of CollectionBlockModel")}refresh(){return this.resource?this.resource.refresh():super.refresh()}defaultBlockTitle(){var t,o,r,i,n,l,a;const c=this.translate(((t=this.constructor.meta)==null?void 0:t.label)||this.constructor.name),u=((o=this.dataSource)==null?void 0:o.displayName)||((r=this.dataSource)==null?void 0:r.key),d=((l=(n=(i=this.context)==null?void 0:i.dataSourceManager)==null?void 0:n.getDataSources)==null?void 0:l.call(n).length)||0,m=(a=this.collection)==null?void 0:a.title;if(this.association){const p=this.resource.getResourceName(),h=this.dataSource.getCollection(p.split(".")[0]);return createDefaultCollectionBlockTitle({blockLabel:c,dsName:u,dsCount:d,collectionTitle:m,sourceCollectionTitle:h.title,associationTitle:this.association.title})}return createDefaultCollectionBlockTitle({blockLabel:c,dsName:u,dsCount:d,collectionTitle:m})}addAppends(t,o=!1){var r,i;if(t)if(t.includes(".")){const[n,l]=t.split("."),a=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${this.collection.name}.${n}`);if(!a)return;const c=a.target;if(!c)return;const u=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${c}.${l}`);if(u&&u.isAssociationField()){if(this.resource.addAppends(t),((r=u.targetCollection)==null?void 0:r.template)==="tree"){const d=t.includes(".")?t.slice(t.lastIndexOf(".")+1):t;u.name===d&&this.resource.addAppends(`${t}.parent(recursively=true)`)}o&&this.resource.refresh()}}else{if(!this.collection)return;const n=this.context.dataSourceManager.getCollectionField(`${this.collection.dataSourceKey}.${this.collection.name}.${t}`);if(!n)return;n.isAssociationField()&&(this.resource.addAppends(n.name),((i=n.targetCollection)==null?void 0:i.template)==="tree"&&this.resource.addAppends(`${n.name}.parent(recursively=true)`),o&&this.resource.refresh())}}}CollectionBlockModel.registerFlow({key:"resourceSettings",sort:-999,steps:{collectionCheck:{handler(e){e.collection||e.exitAll()}},aclCheck:{use:"aclCheck"},init:{handler(e,t){if(!t.dataSourceKey)throw new Error("dataSourceKey is required");if(!t.collectionName)throw new Error("collectionName is required");Object.keys(t).includes("sourceId")&&e.resource.setSourceId(t.sourceId),Object.keys(t).includes("filterByTk")&&e.resource.setFilterByTk(t.filterByTk)}}}});CollectionBlockModel.registerFlow({key:"refreshSettings",sort:1e4,steps:{refresh:{handler(e){return L(this,null,function*(){const t=e.model,o=e.model.context.filterManager;o&&o.bindToTarget(e.model.uid);const r=t.getDataLoadingMode(),i=t.resource;if(i instanceof import_flow_engine.MultiRecordResource&&r==="manual"&&!t.hasActiveFilters()){i.setData([]),i.setMeta({count:0,hasNext:!1,page:1}),i.loading=!1;return}e.model.isManualRefresh?e.model.resource.loading=!1:yield e.model.resource.refresh()})}}}});CollectionBlockModel.registerFlow({key:"dataLoadingModeSettings",sort:800,title:(0,import_flow_engine.tExpr)("Set data loading mode"),steps:{dataLoadingMode:{use:"dataLoadingMode"}}});CollectionBlockModel.define({hide:!0});class CommonItemModel extends import_flow_engine.FlowModel{}class FieldModel extends import_flow_engine.FlowModel{static resolveUse(t,o,r){var i,n;const l=(n=(i=t==null?void 0:t.stepParams)==null?void 0:i.fieldBinding)==null?void 0:n.use;return l&&l!==(t==null?void 0:t.use)?l:t==null?void 0:t.use}}class FilterBlockModel extends BlockModel{}FilterBlockModel.define({hide:!0,label:"Filter blocks"});class PageModel extends import_flow_engine.FlowModel{constructor(){super(...arguments),R(this,"tabBarExtraContent",{}),R(this,"viewActivatedListener"),R(this,"dataSourceDirtyListener"),R(this,"lastSeenEmitterViewActivatedVersion",0),R(this,"dirtyRefreshScheduled",!1),R(this,"unmounted",!1),R(this,"documentTitleUpdateVersion",0),R(this,"createPageTabModelOptions",()=>{const t=(0,import_shared.uid)();return{uid:t,use:"RootPageTabModel",props:{route:{parentId:this.props.routeId,type:"tabs",schemaUid:t,tabSchemaName:(0,import_shared.uid)(),params:[],hideInMenu:!1,enableTabs:!1}}}})}getActiveTabKey(){var t,o,r,i;const n=(o=(t=this.context.view)==null?void 0:t.navigation)==null?void 0:o.viewParams;return n?n.tabUid||((r=this.getFirstTab())==null?void 0:r.uid):this.props.tabActiveKey||((i=this.getFirstTab())==null?void 0:i.uid)}scheduleActiveLifecycleRefresh(t=!1){this.dirtyRefreshScheduled||(this.dirtyRefreshScheduled=!0,Promise.resolve().then(()=>{if(this.dirtyRefreshScheduled=!1,this.unmounted||(0,import_flow_engine.getPageActive)(this.context)===!1)return;const o=this.getActiveTabKey();o&&this.invokeTabModelLifecycleMethod(o,"onActive",t)}).catch(()=>{}))}onMount(){var t,o,r,i,n,l,a,c,u;super.onMount(),this.unmounted=!1,this.setProps("tabActiveKey",(t=this.context.view.inputArgs)==null?void 0:t.tabUid),(o=this.context)!=null&&o.pageInfo&&(this.context.pageInfo.version="v2"),this.updateDocumentTitle(),this.viewActivatedListener||(this.viewActivatedListener=p=>{const h=this.getActiveTabKey();h&&this.invokeTabModelLifecycleMethod(h,"onActive")},(n=(i=(r=this.flowEngine)==null?void 0:r.emitter)==null?void 0:i.on)==null||n.call(i,import_flow_engine.VIEW_ACTIVATED_EVENT,this.viewActivatedListener));const d=(0,import_flow_engine.getEmitterViewActivatedVersion)((l=this.flowEngine)==null?void 0:l.emitter),m=d>0&&d!==this.lastSeenEmitterViewActivatedVersion;if(this.lastSeenEmitterViewActivatedVersion=d,m&&(0,import_flow_engine.getPageActive)(this.context)!==!1){const p=this.getActiveTabKey();p&&this.invokeTabModelLifecycleMethod(p,"onActive")}this.dataSourceDirtyListener||(this.dataSourceDirtyListener=p=>{this.scheduleActiveLifecycleRefresh()},(u=(c=(a=this.flowEngine)==null?void 0:a.emitter)==null?void 0:c.on)==null||u.call(c,import_flow_engine.DATA_SOURCE_DIRTY_EVENT,this.dataSourceDirtyListener))}onUnmount(){var t,o,r,i,n,l;this.unmounted=!0,this.viewActivatedListener&&((r=(o=(t=this.flowEngine)==null?void 0:t.emitter)==null?void 0:o.off)==null||r.call(o,import_flow_engine.VIEW_ACTIVATED_EVENT,this.viewActivatedListener),this.viewActivatedListener=void 0),this.dataSourceDirtyListener&&((l=(n=(i=this.flowEngine)==null?void 0:i.emitter)==null?void 0:n.off)==null||l.call(n,import_flow_engine.DATA_SOURCE_DIRTY_EVENT,this.dataSourceDirtyListener),this.dataSourceDirtyListener=void 0),super.onUnmount()}invokeTabModelLifecycleMethod(t,o,r=!1){var i,n;o==="onActive"&&(i=this.context)!=null&&i.pageInfo&&(this.context.pageInfo.version="v2");const l=this.flowEngine.getModel(t);if(l){if(l.context.tabActive){const a=(0,import_flow_engine.getPageActive)(l.context)!==!1;l.context.tabActive.value=a&&o==="onActive"}(n=l.subModels.grid)==null||n.mapSubModels("items",a=>{var c;(c=a[o])==null||c.call(a,r)})}o==="onActive"&&this.updateDocumentTitle(t)}updateDocumentTitle(t,o=0){return L(this,null,function*(){var r,i,n,l,a,c,u,d,m,p,h,g,f,_,v,b;if(this.unmounted||(0,import_flow_engine.getPageActive)(this.context)===!1)return;const F=!!((i=(r=this.context)==null?void 0:r.view)!=null&&i.navigation),y=(a=(l=(n=this.context)==null?void 0:n.view)==null?void 0:l.inputArgs)==null?void 0:a.viewUid,C=(d=(u=(c=this.flowEngine)==null?void 0:c.context)==null?void 0:u.route)==null?void 0:d.pathname;if(F&&y&&typeof C=="string"){const A=(m=(0,import_flow_engine.parsePathnameToViewParams)(C).at(-1))==null?void 0:m.viewUid;if(A&&A!==y)return}const S=++this.documentTitleUpdateVersion,P=A=>L(this,null,function*(){var T,N;if(!A||typeof A!="string")return"";try{const D=yield(N=(T=this.context).resolveJsonTemplate)==null?void 0:N.call(T,A);return D==null?"":String(D)}catch{return A}});let j="";if(this.props.enableTabs){const A=t||this.getActiveTabKey(),T=A?this.flowEngine.getModel(A):this.getFirstTab();if(!T&&o<5){window.setTimeout(()=>{this.unmounted||S===this.documentTitleUpdateVersion&&this.updateDocumentTitle(A,o+1)},0);return}j=(yield P((g=(h=(p=T==null?void 0:T.stepParams)==null?void 0:p.pageTabSettings)==null?void 0:h.tab)==null?void 0:g.documentTitle))||((f=T==null?void 0:T.getTabTitle)==null?void 0:f.call(T))||""}else j=(yield P((b=(v=(_=this.stepParams)==null?void 0:_.pageSettings)==null?void 0:v.general)==null?void 0:b.documentTitle))||this.props.title||"";S===this.documentTitleUpdateVersion&&typeof j=="string"&&j!==""&&(document.title=j)})}mapTabs(){return this.mapSubModels("tabs",t=>!this.context.flowSettingsEnabled&&t.hidden?null:{key:t.uid,label:(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:t,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:t,showFlowSettings:{showBackground:!0,showBorder:!1,toolbarPosition:"above",style:{transform:"translateY(8px)"}},extraToolbarItems:[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]})}),children:t.renderChildren()}).filter(Boolean)}getFirstTab(){var t;return(t=this.subModels.tabs)==null?void 0:t[0]}renderFirstTab(){var t;const o=this.getFirstTab();return(t=o==null?void 0:o.renderChildren)==null?void 0:t.call(o)}handleDragEnd(t){return L(this,null,function*(){throw new Error("Method not implemented.")})}renderTabs(){var t,o,r,i,n;const l=(o=(t=this.context.themeToken)==null?void 0:t.paddingLG)!=null?o:16,a=this.tabBarExtraContent.left!==void 0?this.tabBarExtraContent.left:(0,import_jsx_runtime.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:l,height:1}}),c=this.tabBarExtraContent.right!==void 0?this.tabBarExtraContent.right:(0,import_jsx_runtime.jsx)("span",{style:{display:"inline-flex",marginInlineEnd:l},children:(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"tabs",items:[{key:"blank",label:this.context.t("Blank tab"),createModelOptions:this.createPageTabModelOptions}],children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.PlusOutlined,{}),children:this.context.t("Add tab")})})});return(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{onDragEnd:this.handleDragEnd.bind(this),children:(0,import_jsx_runtime.jsx)(import_antd.Tabs,{activeKey:(i=(r=this.context.view)==null?void 0:r.navigation)!=null&&i.viewParams?this.context.view.navigation.viewParams.tabUid||((n=this.getFirstTab())==null?void 0:n.uid):this.props.tabActiveKey,tabBarStyle:this.props.tabBarStyle,items:this.mapTabs(),onChange:u=>{var d,m;(m=(d=this.context.view.navigation)==null?void 0:d.changeTo)==null||m.call(d,{tabUid:u}),this.invokeTabModelLifecycleMethod(u,"onActive"),this.invokeTabModelLifecycleMethod(this.props.tabActiveKey,"onInactive"),this.setProps("tabActiveKey",u)},tabBarExtraContent:{left:a,right:c}})})}render(){const t=this.context.themeToken,o=x({},this.props.headerStyle);return t&&(o.paddingBlock=t.paddingSM,o.paddingInline=t.paddingLG),this.props.enableTabs&&(o.paddingBottom=0),(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:o}),this.props.enableTabs?this.renderTabs():this.renderFirstTab()]})}}PageModel.registerEvents({close:{title:(0,import_flow_engine.tExpr)("Close"),name:"close",hideInSettings(e){var t;return!!((t=e.view)!=null&&t.preventClose)},uiSchema:{condition:{type:"object",title:(0,import_flow_engine.tExpr)("Trigger condition"),"x-decorator":"FormItem","x-component":ConditionBuilder}},handler:commonConditionHandler}});PageModel.registerFlow({key:"closeGuard",title:(0,import_flow_engine.tExpr)("Close guard"),on:"close",steps:{confirmUnsavedChanges:{title:(0,import_flow_engine.tExpr)("Unsaved changes confirmation"),handler(e){return L(this,null,function*(){var t,o,r,i,n;(o=(t=e.inputArgs)==null?void 0:t.dirty)!=null&&o.hasDirtyForms&&((yield e.modal.confirm({title:e.t("Unsaved changes"),content:e.t("Are you sure you don't want to save?"),okText:e.t("Confirm"),cancelText:e.t("Cancel")}))||((n=(i=(r=e.inputArgs)==null?void 0:r.controller)==null?void 0:i.prevent)==null||n.call(i),e.exitAll()))})}}}});PageModel.registerFlow({key:"pageSettings",title:(0,import_flow_engine.tExpr)("Page settings"),steps:{general:{title:(0,import_flow_engine.tExpr)("Edit page"),uiSchema:{title:{type:"string",title:(0,import_flow_engine.tExpr)("Page title"),"x-decorator":"FormItem","x-component":"Input","x-reactions":{dependencies:["displayTitle"],fulfill:{state:{visible:"{{$deps[0]}}"}}}},documentTitle:{type:"string",title:(0,import_flow_engine.tExpr)("Document title"),description:(0,import_flow_engine.tExpr)("Used as the browser tab title when tabs are disabled. Supports variables. Leave empty to use Page title."),"x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1,maxRows:6}},displayTitle:{type:"boolean",title:(0,import_flow_engine.tExpr)("Display page title"),"x-decorator":"FormItem","x-component":"Switch"},enableTabs:{type:"boolean",title:(0,import_flow_engine.tExpr)("Enable tabs"),"x-decorator":"FormItem","x-component":"Switch"}},defaultParams(e){return{displayTitle:!0,enableTabs:!1}},handler(e,t){return L(this,null,function*(){var o,r;if(e.model.setProps("displayTitle",t.displayTitle),e.model.context.closable)e.model.setProps("title",e.t(t.title,{ns:"lm-desktop-routes"}));else{const i=(r=(o=e.model.context)==null?void 0:o.currentRoute)==null?void 0:r.title;e.model.setProps("title",e.t(t.title||i,{ns:"lm-desktop-routes"}))}e.model.setProps("enableTabs",t.enableTabs),e.view.type==="embed"?(e.model.setProps("headerStyle",{backgroundColor:"var(--colorBgContainer)"}),e.model.setProps("tabBarStyle",{backgroundColor:"var(--colorBgContainer)",marginBottom:0})):(e.model.setProps("headerStyle",{backgroundColor:"var(--colorBgLayout)"}),e.model.setProps("tabBarStyle",{backgroundColor:"var(--colorBgLayout)",marginBottom:0})),e.model.updateDocumentTitle()})}}}});class ChildPageModel extends PageModel{constructor(){super(...arguments),R(this,"tabBarExtraContent",{left:(0,import_jsx_runtime.jsx)(BackButtonUsedInSubPage,{})}),R(this,"createPageTabModelOptions",()=>({use:"ChildPageTabModel"}))}renderBackButtonWhenTabsDisabled(){var t,o,r,i;if(((o=(t=this.context)==null?void 0:t.view)==null?void 0:o.type)!=="embed")return null;const n=(r=this.context)==null?void 0:r.themeToken,l=I(x({},this.props.tabBarStyle),{paddingBlock:(i=n==null?void 0:n.paddingXS)!=null?i:8});return(0,import_jsx_runtime.jsx)("div",{style:l,children:(0,import_jsx_runtime.jsx)(BackButtonUsedInSubPage,{renderSpacerWhenNoBack:!1})})}handleDragEnd(t){return L(this,null,function*(){var o,r;if(!((o=t.active)!=null&&o.id)||!((r=t.over)!=null&&r.id))throw new Error("Invalid drag event");this.flowEngine.moveModel(t.active.id,t.over.id)})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&this.props.title&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.props.enableTabs?this.renderTabs():(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.renderBackButtonWhenTabsDisabled(),this.renderFirstTab()]})]})}}const BackButtonUsedInSubPage=({renderSpacerWhenNoBack:e=!0})=>{var t;const o=(0,import_flow_engine.useFlowContext)(),r=o.themeToken,i=32,n=(t=r==null?void 0:r.paddingLG)!=null?t:16,l=(0,import_react2.useMemo)(()=>({width:"auto",height:"auto",lineHeight:1,padding:r.paddingXS,marginLeft:r.paddingLG,marginRight:i-r.paddingXS}),[r.paddingLG,r.paddingXS]);return o.view.type!=="embed"?e?(0,import_jsx_runtime.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:1}}):null:(0,import_jsx_runtime.jsx)(import_antd.Button,{"aria-label":"back-button",type:"text",icon:(0,import_jsx_runtime.jsx)(import_icons.ArrowLeftOutlined,{}),style:l,onClick:o.view.close})};class OldPageModel extends import_flow_engine.FlowModel{}OldPageModel.registerFlow({key:"pageSettings",title:(0,import_flow_engine.tExpr)("Page settings"),steps:{general:{title:(0,import_flow_engine.tExpr)("General"),uiSchema:{title:{type:"string",title:(0,import_flow_engine.tExpr)("Page title"),"x-decorator":"FormItem","x-component":"Input","x-reactions":{dependencies:["displayTitle"],fulfill:{state:{visible:"{{$deps[0]}}"}}}},displayTitle:{type:"boolean",title:(0,import_flow_engine.tExpr)("Display page title"),"x-decorator":"FormItem","x-component":"Switch"}},defaultParams(e){return{displayTitle:!0,enableTabs:!1}},handler(e,t){return L(this,null,function*(){var o,r;if(e.model.setProps("displayTitle",t.displayTitle),e.model.context.closable)e.model.setProps("title",t.title?e.t(t.title):null);else{const i=(r=(o=e.model.context)==null?void 0:o.currentRoute)==null?void 0:r.title;e.model.setProps("title",e.t(t.title||i))}e.model.setProps("enableTabs",t.enableTabs),e.model.context.closable?(e.model.setProps("headerStyle",{backgroundColor:e.themeToken.colorBgContainer}),e.model.setProps("tabBarStyle",{backgroundColor:e.themeToken.colorBgLayout,paddingInline:16,marginBottom:0})):(e.model.setProps("headerStyle",{backgroundColor:e.themeToken.colorBgContainer}),e.model.setProps("tabBarStyle",{backgroundColor:e.themeToken.colorBgContainer,paddingInline:16,marginBottom:0}))})}}}});class MainPageModel extends OldPageModel{renderFirstTab(){var t;return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels.tabs)==null?void 0:t[0]})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.renderFirstTab()]})}}class RouteModel extends import_flow_engine.FlowModel{}RouteModel.registerFlow({key:"popupSettings",on:"click",steps:{openView:{use:"openView",defaultParams(e){return{mode:"embed",preventClose:!0,pageModelClass:"RootPageModel"}}}}});function resolveViewParamsToViewList(e,t,o){return t.map((r,i)=>{let n,l=r.viewUid;return i===0?(n=o,l=o.uid):n=e.getModel(r.viewUid,!0),{params:r,modelUid:l,model:n,hidden:import_flow_engine.observable.ref(!1),index:i}})}function updateViewListHidden(e){let t=!1;for(let o=e.length-1;o>=0;o--){const r=e[o];getViewType(r)==="embed"&&!t?(t=!0,r.hidden.value=!1):r.hidden.value=t}}function getViewType(e){if(e.model instanceof RouteModel)return"embed";if(!e.model)return"drawer";const t=e.model.getStepParams("popupSettings","openView");return(t==null?void 0:t.mode)||"drawer"}const stableStringify=e=>e==null?"":typeof e=="object"?Array.isArray(e)?"["+e.map(stableStringify).join(",")+"]":"{"+Object.keys(e).sort().map(t=>`${t}:${stableStringify(e[t])}`).join(",")+"}":String(e),getKey=e=>{const{params:t,index:o}=e;return[stableStringify(t.viewUid),stableStringify(t.sourceId),stableStringify(t.filterByTk),String(o)].join("_")};function getViewDiffAndUpdateHidden(e,t){const o=new Map,r=new Map;e.forEach(l=>{const a=getKey(l);o.set(a,l)}),t.forEach(l=>{r.set(getKey(l),l)});const i=[];o.forEach((l,a)=>{r.has(a)?r.get(a).hidden=l.hidden:i.push(l)});const n=[];return r.forEach((l,a)=>{o.has(a)||n.push(l)}),{viewsToClose:i,viewsToOpen:n}}const openViewFlow=(0,import_flow_engine.defineFlow)({key:"popupSettings",title:(0,import_flow_engine.tExpr)("Popup settings"),on:"click",sort:300,steps:{openView:{use:"openView",hideInSettings:e=>L(void 0,null,function*(){var t,o,r,i;const n=(r=(o=(t=e.model).getStepParams)==null?void 0:o.call(t,"displayFieldSettings","clickToOpen"))==null?void 0:r.clickToOpen;return e.collectionField?n===void 0?!((i=e.collectionField)!=null&&i.isAssociationField())||e.disableFieldClickToOpen:n===!1:!1})}},defaultParams:e=>{var t,o,r,i,n,l,a,c;let u,d,m;const p=e.collectionField,h=e.blockModel,g=(o=(t=e.model)==null?void 0:t.parent)==null?void 0:o.associationPathName,f=e.collection||(h==null?void 0:h.collection),_=F=>{var y;return!!((y=F==null?void 0:F.isAssociationField)!=null&&y.call(F))},v=!_(p)&&g?(r=f==null?void 0:f.getFieldByPath)==null?void 0:r.call(f,g):void 0,b=_(p)?p:v;if(_(b)){const F=b.targetCollection;h==null||h.collection,u=F==null?void 0:F.name,d=F==null?void 0:F.dataSourceKey,m=b==null?void 0:b.resourceName}else p?(u=(i=e.collection)==null?void 0:i.name,d=(n=e.collection)==null?void 0:n.dataSourceKey,m=p==null?void 0:p.target):(u=(l=e.collection)==null?void 0:l.name,d=(a=e.collection)==null?void 0:a.dataSourceKey,m=(c=e.association)==null?void 0:c.resourceName);return{openView:{collectionName:u,associationName:m,dataSourceKey:d}}}}),getOpenViewStepParams=e=>e.getStepParams("popupSettings","openView");function InternalFlowPage(e){var t=e,{uid:o}=t,r=te(t,["uid"]);const i=(0,import_flow_engine.useFlowModelById)(o);return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,x({model:i,fallback:(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i!=null&&i.context.isMobileLayout?8:i==null?void 0:i.context.themeToken.marginBlock}}),hideRemoveInSettings:!0,showFlowSettings:{showBackground:!1,showBorder:!1}},r))}const FlowRoute=()=>{const e=(0,import_react2.useRef)(null),t=(0,import_flow_engine.useFlowEngine)(),o=useCurrentRoute(),{refresh:r}=useAllAccessDesktopRoutes(),{isMobileLayout:i}=useMobileLayout(),n=(0,import_react2.useRef)(t.context.route.params.name),l=(0,import_react2.useRef)({}),a=(0,import_react2.useRef)([]),c=(0,import_react2.useRef)(!1),{designable:u}=useDesignable(),{active:d}=useKeepAlive(),m=(0,import_react2.useRef)(!1),p=(0,import_react2.useMemo)(()=>t.createModel({uid:n.current,use:"RouteModel"}),[t]);return(0,import_react2.useEffect)(()=>{p.context.defineProperty("pageActive",{value:import_flow_engine.observable.ref(!1),info:{description:"Whether current page route is active (keep-alive). This is an observable.ref<boolean> (use ctx.pageActive.value to read/write).",detail:"observable.ref<boolean>"}})},[p]),(0,import_react2.useEffect)(()=>{p.context.pageActive.value=d},[d,p]),(0,import_react2.useEffect)(()=>{t.context.defineProperty("isMobileLayout",{get:()=>i,info:{description:"Whether current layout is mobile layout.",detail:"boolean"}}),t.context.defineProperty("deviceType",{get:()=>import_react_device_detect.deviceType==="browser"?"computer":import_react_device_detect.deviceType,cache:!1,meta:{type:"string",title:t.translate("Current device type"),interface:"select",uiSchema:{enum:[{label:t.translate("Computer"),value:"computer"},{label:t.translate("Mobile"),value:"mobile"},{label:t.translate("Tablet"),value:"tablet"},{label:t.translate("SmartTv"),value:"smarttv"},{label:t.translate("Console"),value:"console"},{label:t.translate("Wearable"),value:"wearable"},{label:t.translate("Embedded"),value:"embedded"}],"x-component":"Select"}},info:{description:"Current device type (computer/mobile/tablet/...).",detail:"string"}})},[i,t]),(0,import_react2.useEffect)(()=>{i?t.flowSettings.disable():u&&t.flowSettings.enable()},[u,t,i]),(0,import_react2.useEffect)(()=>{e.current&&(t.context.defineProperty("layoutContentElement",{get:()=>e.current}),p.context.defineProperty("currentRoute",{get:()=>o}),t.context.defineProperty("currentRoute",{get:()=>o}),p.context.defineProperty("refreshDesktopRoutes",{get:()=>r}))},[p,o,r,t]),(0,import_react2.useEffect)(()=>{const h=(0,import_flow_engine.reaction)(()=>t.context.route,g=>{var f;if(g.params.name!==n.current){m.current=!0;return}try{m.current=!1;const _=(0,import_flow_engine.parsePathnameToViewParams)(g.pathname),v=resolveViewParamsToViewList(t,_,p);if(a.current.length===0&&v.length>1&&!c.current){const y=C=>{v[C]&&(C===0?new import_flow_engine.ViewNavigation(t.context,[]).navigateTo(v[C].params,{replace:!0}):new import_flow_engine.ViewNavigation(t.context,v.slice(0,C).map(S=>S.params)).navigateTo(v[C].params),y(C+1))};y(0),c.current=!0;return}const{viewsToClose:b,viewsToOpen:F}=getViewDiffAndUpdateHidden(a.current,v);if(console.log("[NocoBase] FlowRoute view diff:",{viewsToClose:b,viewsToOpen:F}),b.length&&(b.forEach(y=>{var C,S;(S=(C=l.current[getKey(y)])==null?void 0:C.destroy)==null||S.call(C,!0),delete l.current[getKey(y)]}),updateViewListHidden(v)),F.length&&L(void 0,null,function*(){const y=F.filter(S=>!S.model);if(y.length>0&&(yield Promise.all(y.map(S=>L(void 0,null,function*(){try{S.model=yield t.loadModel({uid:S.modelUid})}catch(P){console.error(`[NocoBase] Failed to load model ${S.modelUid}:`,P)}})))),m.current)return;updateViewListHidden(v);const C=S=>{if(!F[S])return;const P=F[S];if(!P.model)return;const j=import_react2.default.createRef(),A=import_react2.default.createRef(),T=getOpenViewStepParams(P.model),N=v.slice(0,P.index).map(w=>w.params.viewUid),D=new import_flow_engine.ViewNavigation(t.context,v.slice(0,P.index+1).map(w=>w.params));P.model.dispatchEvent("click",I(x({target:e.current,collectionName:T==null?void 0:T.collectionName,associationName:T==null?void 0:T.associationName,dataSourceKey:T==null?void 0:T.dataSourceKey,destroyRef:j,updateRef:A,openerUids:N},P.params),{navigation:D,onOpen(){C(S+1)},hidden:P.hidden,isMobileLayout:i,triggerByRouter:!0})),l.current[getKey(P)]={destroy:w=>{var k;return(k=j.current)==null?void 0:k.call(j)},update:w=>{var k;return(k=A.current)==null?void 0:k.call(A,w)},navigation:D}};C(0)}),b.length===0&&F.length===0){const y=v.at(-1);y&&((f=l.current[getKey(y)])==null||f.navigation.setViewStack(v.map(C=>C.params)))}a.current=[...v]}catch(_){console.error("[NocoBase] Failed to resolve view params to view list:",_)}},{fireImmediately:!0});return()=>{h==null||h(),a.current.forEach(g=>{var f;t.removeModelWithSubModels(g.params.viewUid),(f=l.current[getKey(g)])==null||f.destroy()})}},[t,i,p]),(0,import_jsx_runtime.jsx)("div",{ref:e})},FlowPage=import_react2.default.memo(e=>{const t=e,{pageModelClass:o="ChildPageModel",parentId:r,onModelLoaded:i,defaultTabTitle:n}=t,l=te(t,["pageModelClass","parentId","onModelLoaded","defaultTabTitle"]),a=(0,import_flow_engine.useFlowEngine)(),c=(0,import_flow_engine.useFlowViewContext)(),{loading:u,data:d}=(0,import_ahooks.useRequest)(()=>L(void 0,null,function*(){var m;const p={async:!0,parentId:r,subKey:"page",subType:"object",use:o};if(o==="ChildPageModel"){const g=n||((m=a.translate)==null?void 0:m.call(a,"Details"));p.subModels={tabs:[{use:"ChildPageTabModel",stepParams:{pageTabSettings:{tab:{title:g}}}}]},p.stepParams={pageSettings:{general:{displayTitle:!1,enableTabs:!0}}}}const h=yield a.loadOrCreateModel(p,{skipSave:!a.context.flowSettingsEnabled});return h!=null&&h.uid&&i&&(h.context.addDelegate(c),h.removeParentDelegate(),i(h.uid,h)),h}),{refreshDeps:[r]});return u||!(d!=null&&d.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:c!=null&&c.isMobileLayout?8:c==null?void 0:c.themeToken.marginBlock}}):(0,import_jsx_runtime.jsx)(InternalFlowPage,x({uid:d.uid},l))});FlowPage.displayName="FlowPage";const RemoteFlowModelRenderer=e=>{const t=e,{uid:o,parentId:r,subKey:i}=t,n=te(t,["uid","parentId","subKey"]),l=(0,import_flow_engine.useFlowEngine)(),{loading:a,data:c}=(0,import_ahooks.useRequest)(()=>L(void 0,null,function*(){return yield l.loadModel({uid:o,parentId:r,subKey:i})}),{refreshDeps:[o,r,i]});return a||!(c!=null&&c.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:16}}):(0,import_jsx_runtime.jsx)(InternalFlowPage,x({uid:c.uid},n))};function PageTabChildrenRenderer({ctx:e,options:t}){const{data:o,loading:r}=(0,import_ahooks.useRequest)(()=>L(this,null,function*(){const n=yield e.engine.loadOrCreateModel(t,{skipSave:!e.flowSettingsEnabled});return n.context.addDelegate(e),n}),{refreshDeps:[e.model.uid]}),i=e!=null&&e.isMobileLayout?8:e==null?void 0:e.themeToken.marginBlock;return r||!(o!=null&&o.uid)?(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i}}):(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:o,fallback:(0,import_jsx_runtime.jsx)(SkeletonFallback,{style:{margin:i}})})}function normalizePersistedRoute(e){if(Array.isArray(e))return e.find(t=>!!t&&typeof t=="object");if(e&&typeof e=="object")return e}class BasePageTabModel extends import_flow_engine.FlowModel{onInit(t){super.onInit(t),this.context.defineProperty("tabActive",{value:import_flow_engine.observable.ref(!0),info:{description:"Whether current tab is active (observable.ref).",detail:"observable.ref<boolean>"}})}getTabTitle(t="Untitled"){var o,r;const i=this.context.t(t,{ns:"client"});return this.context.t((r=(o=this.stepParams.pageTabSettings)==null?void 0:o.tab)==null?void 0:r.title,{ns:"lm-desktop-routes"})||i}getTabIcon(){var t,o;return(o=(t=this.stepParams.pageTabSettings)==null?void 0:t.tab)==null?void 0:o.icon}renderChildren(){return null}renderHiddenInConfig(){return(0,import_jsx_runtime.jsxs)("span",{style:{display:"inline-block",opacity:.5},children:[(0,import_jsx_runtime.jsx)(Icon,{style:{marginRight:8},type:this.getTabIcon()}),this.getTabTitle()]})}render(){return(0,import_jsx_runtime.jsxs)("span",{style:{display:"inline-block"},children:[(0,import_jsx_runtime.jsx)(Icon,{style:{marginRight:8},type:this.getTabIcon()}),this.getTabTitle()]})}}BasePageTabModel.registerFlow({key:"pageTabSettings",title:(0,import_flow_engine.tExpr)("Tab settings"),steps:{tab:{title:(0,import_flow_engine.tExpr)("Edit tab"),preset:!0,uiSchema:{title:{title:(0,import_flow_engine.tExpr)("Tab name"),"x-component":"Input","x-decorator":"FormItem",required:!0},documentTitle:{type:"string",title:(0,import_flow_engine.tExpr)("Document title"),description:(0,import_flow_engine.tExpr)("Used as the browser tab title when this tab is active. Supports variables. Leave empty to use Tab name."),"x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1,maxRows:6}},icon:{title:(0,import_flow_engine.tExpr)("Icon"),"x-decorator":"FormItem","x-component":"IconPicker"}},handler(e,t){return L(this,null,function*(){var o;const r=typeof(e==null?void 0:e.t)=="function"?e.t.bind(e):n=>n;e.model.setProps("title",r(t.title,{ns:"lm-desktop-routes"})),e.model.setProps("icon",t.icon);const i=e.engine.getModel(e.model.parentId);(o=i==null?void 0:i.updateDocumentTitle)==null||o.call(i)})}}}});class RootPageTabModel extends BasePageTabModel{renderChildren(){return(0,import_jsx_runtime.jsx)(PageTabChildrenRenderer,{ctx:this.context,options:{parentId:this.uid,subKey:"grid",async:!0,subType:"object",use:"BlockGridModel"}})}saveStepParams(){return L(this,null,function*(){return this.save()})}save(){return L(this,null,function*(){var t,o,r,i,n;const l=this.serialize(),a=(r=(o=(t=this.stepParams)==null?void 0:t.pageTabSettings)==null?void 0:o.tab)==null?void 0:r.documentTitle,c=yield this.context.api.request({method:"post",url:"desktopRoutes:updateOrCreate",params:{filterKeys:["schemaUid"]},data:I(x({},this.props.route),{title:this.getTabTitle(""),icon:this.getTabIcon(),options:{flowRegistry:l.flowRegistry,documentTitle:a}})}),u=normalizePersistedRoute((i=c==null?void 0:c.data)==null?void 0:i.data);u&&this.setProps("route",I(x(x({},this.props.route),u),{options:x(x({},(n=this.props.route)==null?void 0:n.options),u.options)}))})}destroy(){return L(this,null,function*(){return this.observerDispose(),this.invalidateFlowCache("beforeRender",!0),this.flowEngine.removeModel(this.uid),yield this.context.api.request({method:"post",url:"desktopRoutes:destroy",params:{filter:{schemaUid:this.uid}},data:this.props.route}),!0})}}class ChildPageTabModel extends BasePageTabModel{renderChildren(){return(0,import_jsx_runtime.jsx)(PageTabChildrenRenderer,{ctx:this.context,options:{parentId:this.uid,subKey:"grid",async:!0,subType:"object",use:"BlockGridModel"}})}}class PageTabModel extends import_flow_engine.FlowModel{render(){return(0,import_jsx_runtime.jsx)("div",{children:(0,import_jsx_runtime.jsx)(RemoteFlowModelRenderer,{parentId:this.uid,subKey:"grid",showFlowSettings:!1})})}}class RootPageModel extends PageModel{constructor(){super(...arguments),R(this,"mounted",!1)}ensurePersistedRouteId(t){return L(this,null,function*(){var o,r,i,n;const l=(r=(o=t==null?void 0:t.props)==null?void 0:o.route)==null?void 0:r.id;return l??(typeof(t==null?void 0:t.save)=="function"&&(yield t.save()),(n=(i=t==null?void 0:t.props)==null?void 0:i.route)==null?void 0:n.id)})}onMount(){super.onMount(),(0,import_flow_engine.reaction)(()=>this.context.pageActive.value,()=>{var t,o;if(this.context.pageActive.value&&this.mounted){const r=(t=this.subModels.tabs)==null?void 0:t[0];r&&(this.setProps("tabActiveKey",r.uid),this.invokeTabModelLifecycleMethod(r.uid,"onActive",!0))}if(this.context.pageActive.value===!1)if(this.props.tabActiveKey)this.invokeTabModelLifecycleMethod(this.props.tabActiveKey,"onInactive");else{const r=(o=this.subModels.tabs)==null?void 0:o[0];r&&this.invokeTabModelLifecycleMethod(r.uid,"onInactive")}this.mounted=!0})}saveStepParams(){return L(this,null,function*(){yield $e(RootPageModel.prototype,this,"saveStepParams").call(this),this.stepParams.pageSettings&&this.context.api.request({url:`desktopRoutes:update?filter[id]=${this.props.routeId}`,method:"post",data:{enableTabs:!!this.stepParams.pageSettings.general.enableTabs}})})}handleDragEnd(t){return L(this,null,function*(){var o,r;const i=this.flowEngine.getModel((o=t.active)==null?void 0:o.id),n=this.flowEngine.getModel((r=t.over)==null?void 0:r.id);if(!i||!n||i.uid===n.uid)return;const[l,a]=yield Promise.all([this.ensurePersistedRouteId(i),this.ensurePersistedRouteId(n)]);l==null||a==null||(yield this.context.api.request({url:"desktopRoutes:move",method:"post",params:{sourceId:l,targetId:a,sortField:"sort"}}),this.flowEngine.moveModel(i.uid,n.uid,{persist:!1}))})}}RootPageModel.registerFlow({key:"rootPageSettings",steps:{init:{handler(e,t){return L(this,null,function*(){var o,r;if(e.model.hasSubModel("tabs"))return;const i=e.routeRepository.getRouteBySchemaUid(e.model.parentId);e.model.setProps("routeId",i==null?void 0:i.id);const n=import_lodash.default.castArray(i==null?void 0:i.children);for(const l of n.sort((a,c)=>a.sort-c.sort)){if(l.hideInMenu)continue;const a=e.engine.createModel({parentId:e.model.uid,uid:l.schemaUid,subKey:"tabs",subType:"array",use:"RootPageTabModel",sortIndex:l.sort,props:{route:l},flowRegistry:(o=l.options)==null?void 0:o.flowRegistry,stepParams:{pageTabSettings:{tab:{title:l.title,icon:l.icon,documentTitle:(r=l.options)==null?void 0:r.documentTitle}}}});e.model.addSubModel("tabs",a)}})}}}});class SubPageModel extends OldPageModel{renderFirstTab(){var t;return(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels.tabs)==null?void 0:t[0]})}render(){return(0,import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment,{children:[this.props.displayTitle&&(0,import_jsx_runtime.jsx)(import_pro_layout.PageHeader,{title:this.props.title,style:this.props.headerStyle}),this.renderFirstTab()]})}}class PopupActionModel extends ActionModel{constructor(){super(...arguments),R(this,"defaultProps",{title:(0,import_flow_engine.tExpr)("Popup"),icon:"ExportOutlined"})}}PopupActionModel.define({label:(0,import_flow_engine.tExpr)("Popup")});PopupActionModel.registerFlow(openViewFlow);class RecordActionModel extends ActionModel{}RecordActionModel.define({children:e=>L(void 0,null,function*(){return(yield(0,import_flow_engine.buildSubModelItems)(ActionModel)(e)).filter(t=>e.engine.getModelClass(t.useModel)._isScene(ActionSceneEnum.record))})});class InputFieldModel extends FieldModel{render(){return(0,import_jsx_runtime.jsx)(import_antd.Input,x({},this.props))}}InputFieldModel.registerFlow({key:"defaultValueForNanoid",steps:{generateNanoid:{handler(e,t){var o,r;(r=(o=e.blockModel)==null?void 0:o.emitter)==null||r.on("onFieldReset",()=>{if(e.collectionField.interface==="nanoid"&&e.collectionField.options.autoFill!==!1){const{size:i,customAlphabet:n}=e.collectionField.options||{size:21};e.model.props.onChange((0,import_nanoid.customAlphabet)(n,i)())}})}}}});InputFieldModel.define({label:(0,import_flow_engine.tExpr)("Input")});import_flow_engine.EditableItemModel.bindModelToInterface("InputFieldModel",["input","email","phone","uuid","url","nanoid"],{isDefault:!0});import_flow_engine.FilterableItemModel.bindModelToInterface("InputFieldModel",["input","email","phone","uuid","url","nanoid","textarea","markdown","vditor","richText","password","color"],{isDefault:!0});const ARRAY_VALUE_OPERATORS=new Set(["$match","$notMatch","$anyOf","$noneOf","$childIn","$childNotIn","$in","$notIn"]);function isObjectWithType(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&"type"in e}function isEmptyScalar(e){return e===null||typeof e>"u"||typeof e=="string"&&e.trim()===""}function normalizeFilterValueByOperator(e,t){if(!e)return t;if(e==="$dateBetween"){if(t===null||typeof t>"u"||isObjectWithType(t))return t;if(Array.isArray(t)){if(t.length===0)return t;const o=t[0],r=t.length>1?t[1]:void 0,i=isEmptyScalar(o),n=isEmptyScalar(r);return t.length===1&&!i?[o,o]:!i&&n?[o,o]:i&&!n?[r,r]:t}return[t,t]}return ARRAY_VALUE_OPERATORS.has(e)?t===null||typeof t>"u"||Array.isArray(t)?t:typeof t=="string"&&t.trim()===""?[]:[t]:t}const stripTimeFromFormat=e=>e&&e.replace(/\s*HH?:mm(?::ss)?(?:\.SSS)?/g,"").trim();function getRawSingleValue(e,t){if(!t)return e;if(Array.isArray(e))return e[0]}function inferPickerFromRawValue(e,t){return typeof e=="string"?inferPickerType(e,t):t}function parseDateByFormat$1(e,t){const o=String(e||"").trim();if(!o)return null;if(/(?:Z|[+-]\d{2}:\d{2})$/i.test(o)){const i=(0,import_client.dayjs)(o);if(i.isValid())return i}if(t){const i=(0,import_client.dayjs)(o,t,!0);if(i.isValid())return i}const r=(0,import_client.dayjs)(o);if(r.isValid())return r;if(t){const i=(0,import_client.dayjs)(o,t);if(i.isValid())return i}return null}function parseDateFromRawValue$1(e,t){if(import_client.dayjs.isDayjs(e))return e;if(e instanceof Date){const o=(0,import_client.dayjs)(e);return o.isValid()?o:null}return typeof e=="string"?parseDateByFormat$1(e,t):null}function parseRangeValue(e,t){if(!Array.isArray(e))return null;const o=parseDateFromRawValue$1(e[0],t),r=parseDateFromRawValue$1(e[1],t);return!o||!r?null:[o,r]}const FieldAssignExactDatePicker=e=>{const{picker:t="date",format:o,showTime:r,timeFormat:i,value:n,isRange:l=!1,onChange:a,style:c}=e,u=(0,import_flow_engine.useFlowContext)(),d=u.model.translate.bind(u.model),m=(0,import_react2.useMemo)(()=>getRawSingleValue(n,l),[l,n]),[p,h]=(0,import_react2.useState)(()=>inferPickerFromRawValue(m,t)),g=S=>{const P=S===t&&o?o:(0,import_client.getPickerFormat)(S),j=S==="date"?stripTimeFromFormat(P):P;return(0,import_client.getDateTimeFormat)(S,j,r,i)},f=(0,import_react2.useMemo)(()=>g(p),[p,o,t,r,i]),_=(0,import_react2.useMemo)(()=>l?null:parseDateFromRawValue$1(n,f),[l,n,f]),v=(0,import_react2.useMemo)(()=>l?parseRangeValue(n,f):null,[l,n,f]),b=(0,import_react2.useMemo)(()=>[{label:d("Date"),value:"date"},{label:d("Month"),value:"month"},{label:d("Quarter"),value:"quarter"},{label:d("Year"),value:"year"}],[d]),F=S=>{if(h(S),!!a){if(l){v&&a(v);return}_&&a(_)}},y={utc:!0,underFilter:!0,format:f,picker:p,inputReadOnly:u.isMobileLayout,showTime:r?{defaultValue:(0,import_client.dayjs)("00:00:00","HH:mm:ss")}:!1,value:_,onChange:S=>{if(S&&import_client.dayjs.isDayjs(S)){a==null||a(S);return}a==null||a(null)},style:{flex:1}},C={utc:!0,underFilter:!0,format:f,picker:p,inputReadOnly:u.isMobileLayout,showTime:r?{defaultValue:[(0,import_client.dayjs)("00:00:00","HH:mm:ss"),(0,import_client.dayjs)("23:59:59","HH:mm:ss")]}:!1,value:v,onChange:S=>{if(Array.isArray(S)&&S[0]&&S[1]){a==null||a([S[0],S[1]]);return}a==null||a(null)},style:{flex:1}};return(0,import_jsx_runtime.jsxs)(import_antd.Space.Compact,{style:x({width:"100%"},c||{}),children:[(0,import_jsx_runtime.jsx)(import_antd.Select,{style:{width:100},popupMatchSelectWidth:!1,value:p,options:b,onChange:F}),l?(0,import_jsx_runtime.jsx)(import_antd.DatePicker.RangePicker,x({},C)):(0,import_jsx_runtime.jsx)(import_antd.DatePicker,x({},y))]})},DATE_FIELD_INTERFACES=new Set(["date","datetime","datetimeNoTz","createdAt","updatedAt","unixTimestamp"]),TZ_AWARE_DATE_INTERFACES=new Set(["datetime","createdAt","updatedAt","unixTimestamp"]),DATE_ONLY_OUTPUT_FORMAT="YYYY-MM-DD",DATETIME_NO_TZ_OUTPUT_FORMAT="YYYY-MM-DD HH:mm:ss",DATE_DYNAMIC_OPTION_KEYS=["exact","past","next","today","yesterday","tomorrow","thisWeek","lastWeek","nextWeek","thisMonth","lastMonth","nextMonth","thisQuarter","lastQuarter","nextQuarter","thisYear","lastYear","nextYear"],DATE_DYNAMIC_OPTION_LABELS={exact:"Exact day",past:"Past",next:"Next",today:"Today",yesterday:"Yesterday",tomorrow:"Tomorrow",thisWeek:"This Week",lastWeek:"Last Week",nextWeek:"Next Week",thisMonth:"This Month",lastMonth:"Last Month",nextMonth:"Next Month",thisQuarter:"This Quarter",lastQuarter:"Last Quarter",nextQuarter:"Next Quarter",thisYear:"This Year",lastYear:"Last Year",nextYear:"Next Year"};function buildDateDynamicOptions(e,t=!1){var o;const r=DATE_DYNAMIC_OPTION_KEYS.map(i=>{var n;return{value:i,label:(n=e==null?void 0:e(DATE_DYNAMIC_OPTION_LABELS[i]))!=null?n:DATE_DYNAMIC_OPTION_LABELS[i]}});return t&&r.splice(3,0,{value:"now",label:(o=e==null?void 0:e("Now"))!=null?o:"Now"}),r}function parseDateByFormat(e,t){const o=String(e||"").trim();if(!o)return null;if(/(?:Z|[+-]\d{2}:\d{2})$/i.test(o)){const i=(0,import_client.dayjs)(o);if(i.isValid())return i}if(t){const i=(0,import_client.dayjs)(o,t,!0);if(i.isValid())return i}const r=(0,import_client.dayjs)(o);if(r.isValid())return r;if(t){const i=(0,import_client.dayjs)(o,t);if(i.isValid())return i}return null}function parseDateFromRawValue(e,t){if(import_client.dayjs.isDayjs(e))return e;if(e instanceof Date){const o=(0,import_client.dayjs)(e);return o.isValid()?o:null}return typeof e=="string"?parseDateByFormat(e,t):null}function normalizeExactDateValue(e,t){const o=parseDateFromRawValue(e,t.format);if(!(o!=null&&o.isValid()))return e;switch(t.exactNormalizeMode){case"date":return o.format(DATE_ONLY_OUTPUT_FORMAT);case"datetimeNoTz":return o.format(t.showTime?DATETIME_NO_TZ_OUTPUT_FORMAT:DATE_ONLY_OUTPUT_FORMAT);case"iso":return o.toISOString();default:return e}}function toExactPickerSingleValue(e,t){const o=parseDateFromRawValue(e,t);return o!=null&&o.isValid()?o:null}function toExactPickerRangeValue(e,t){if(!Array.isArray(e))return null;const o=toExactPickerSingleValue(e[0],t),r=toExactPickerSingleValue(e[1],t);return!o||!r?null:[o,r]}function toExactPickerDisplayValue(e,t){return t.isRange?toExactPickerRangeValue(e,t.format):toExactPickerSingleValue(e,t.format)}function getDateVariableExactNormalizeMode(e){return e==="date"?"date":e==="datetimeNoTz"?"datetimeNoTz":TZ_AWARE_DATE_INTERFACES.has(e)?"iso":"none"}function normalizeDateVariableExactValue(e,t){return t.exactNormalizeMode==="none"?e:typeof e=="string"||import_client.dayjs.isDayjs(e)||e instanceof Date?normalizeExactDateValue(e,t):Array.isArray(e)?e.map(o=>typeof o=="string"||import_client.dayjs.isDayjs(o)||o instanceof Date?normalizeExactDateValue(o,t):o):e}function normalizeExactDatePickerMode(e){return e==="year"||e==="quarter"||e==="month"||e==="date"?e:"date"}const DEFAULT_DATE_VARIABLE_COMPONENT_PROPS={picker:"date",showTime:!1,timeFormat:"HH:mm:ss",format:"YYYY-MM-DD",exactNormalizeMode:"none"};function getFieldInterface(e){return typeof(e==null?void 0:e.interface)=="string"?e.interface:""}function getFieldComponentProps(e){var t;return(typeof(e==null?void 0:e.getComponentProps)=="function"?e.getComponentProps():null)||((t=e==null?void 0:e.uiSchema)==null?void 0:t["x-component-props"])||{}}function normalizeDateVariableOutput(e,t){if(e===null||(0,import_flow_engine.isRunJSValue)(e)||typeof e=="string"&&(0,import_flow_engine.isVariableExpression)(e)&&!(0,import_flow_engine.isCtxDateExpression)(e))return e;if(e===""||typeof e>"u")return"";const o=normalizeDateVariableExactValue(e,{exactNormalizeMode:t.exactNormalizeMode,format:t.format||"YYYY-MM-DD HH:mm:ss",showTime:t.showTime});return(0,import_flow_engine.serializeCtxDateValue)(o)||o}function isPlainObject$1(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function pickStyle(e){return isPlainObject$1(e)?e:void 0}function withFullWidthStyle(e){return I(x({},e),{width:"100%",minWidth:0})}function rewrapReactiveRender$1(e){var t;e&&(e._reactiveWrapperCache=void 0,(t=e.setupReactiveRender)==null||t.call(e))}function remapMetaTreePaths(e,t,o){const r=Array.isArray(e==null?void 0:e.paths)?e.paths.map(l=>String(l)):[];let i=r;t.length&&r.length>=t.length&&t.every((l,a)=>r[a]===l)&&(i=[...o,...r.slice(t.length)]);const n=l=>Array.isArray(l)?l.map(a=>remapMetaTreePaths(a,t,o)):typeof l=="function"?()=>L(this,null,function*(){const a=yield l();return Array.isArray(a)?a.map(c=>remapMetaTreePaths(c,t,o)):[]}):l;return I(x({},e),{paths:i,children:e!=null&&e.children?n(e.children):void 0})}function attachBaseItemAsParent(e,t){var o;if(!t)return e;const r=remapMetaTreePaths(t,["item"],["item","parentItem"]),i=I(x({},r),{name:"parentItem",title:((o=r.title)==null?void 0:o.replace("Current item","Parent item"))||"Parent item"}),n=l=>{const a=Array.isArray(l.children)?l.children:[];if(!a.some(u=>(u==null?void 0:u.name)==="parentItem"))return I(x({},l),{children:[...a,i]});const c=a.map(u=>(u==null?void 0:u.name)!=="parentItem"?u:n(u));return I(x({},l),{children:c})};return n(e)}function mergeItemMetaTreeForAssignValue(e,t){const o=Array.isArray(e)?e:[],r=Array.isArray(t)?t:[];if(!r.length)return o;const i=o.find(u=>(u==null?void 0:u.name)==="item"),n=r.find(u=>(u==null?void 0:u.name)==="item");if(!n)return o;const l=attachBaseItemAsParent(n,i),a=[];let c=!1;for(const u of o){if(!c&&(u==null?void 0:u.name)==="item"){a.push(l),c=!0;continue}a.push(u)}return c||a.push(l),a}function resolveAssignValueFieldPath(e){var t;if(!e)return;const o=((t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"fieldSettings","init"))||{};return(o==null?void 0:o.fieldPath)||getFormItemPreferredFieldPath(e)}function getAssignValueSubField(e){var t;const o=(t=e==null?void 0:e.subModels)==null?void 0:t.field;return o&&!Array.isArray(o)?o:void 0}const ASSIGN_VALUE_IGNORED_PROP_KEYS=new Set(["value","defaultValue","onChange","onClick","open","searchText","dropdownRender","popupRender","optionRender"]),ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE="RecordSelectFieldModel",ASSIGN_VALUE_ASSOCIATION_WRAPPER_MODEL_USES=new Set(["FieldModel","SubFormFieldModel","SubFormListFieldModel","SubTableFieldModel","PopupSubTableFieldModel","RecordPickerFieldModel"]);function getAssignValueOriginFieldModel(e){return(e==null?void 0:e.customFieldModelInstance)||getAssignValueSubField(e)}function pickAssignValueString(...e){return e.find(t=>typeof t=="string"&&!!t)}function pickAssignValueBoolean(...e){return e.find(t=>typeof t=="boolean")}function isAssignValueAssociationWrapperModelUse(e){return!!e&&ASSIGN_VALUE_ASSOCIATION_WRAPPER_MODEL_USES.has(e)}function isAssignValueAssociationSelectModelUse(e){var t;return(t=e==null?void 0:e.endsWith("RecordSelectFieldModel"))!=null?t:!1}function resolveAssignValueFieldSource(e){var t,o,r,i,n,l,a,c,u,d,m,p,h;const g=getAssignValueSubField(e),f=(o=(t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"formItemSettings","fieldSettings"))!=null?o:{},_=getAssignValueOriginFieldModel(e),v=(r=_==null?void 0:_.props)!=null?r:{},b=(n=(i=e==null?void 0:e.customFieldProps)!=null?i:f==null?void 0:f.fieldModelProps)!=null?n:{};return{originFieldModel:_,originProps:v,customFieldName:pickAssignValueString(f==null?void 0:f.name),customFieldProps:b,currentAllowMultiple:pickAssignValueBoolean((a=(l=_==null?void 0:_.getStepParams)==null?void 0:l.call(_,"selectSettings","allowMultiple"))==null?void 0:a.allowMultiple,(d=(u=(c=_==null?void 0:_.stepParams)==null?void 0:c.selectSettings)==null?void 0:u.allowMultiple)==null?void 0:d.allowMultiple,v==null?void 0:v.allowMultiple,v==null?void 0:v.multiple,b==null?void 0:b.allowMultiple,b==null?void 0:b.multiple),currentFieldModelUse:pickAssignValueString((p=(m=g==null?void 0:g.stepParams)==null?void 0:m.fieldBinding)==null?void 0:p.use,g==null?void 0:g.use,f==null?void 0:f.fieldModel,(h=e==null?void 0:e.customFieldModelInstance)==null?void 0:h.use)}}function resolveAssignValueFieldSettingsInit(e){const{collection:t,customFieldName:o,fieldPath:r,fieldName:i}=e;if(!(t!=null&&t.name)||!r)return;const n=r.startsWith(`${CUSTOM_FIELD_TARGET_PATH_PREFIX}:`)&&(o||i)||r;return{dataSourceKey:t.dataSourceKey,collectionName:t.name,fieldPath:n}}function sanitizeAssignValueInheritedProps(e){const t={};for(const[o,r]of Object.entries(e??{}))ASSIGN_VALUE_IGNORED_PROP_KEYS.has(o)||/^on[A-Z]/.test(o)||(t[o]=r);return t}function resolveAssignValueFieldProps(e){var t;const{placeholder:o,originProps:r,customFieldProps:i,collectionField:n}=e,l=sanitizeAssignValueInheritedProps(r),a=sanitizeAssignValueInheritedProps(i),c=x(x({placeholder:o},l),a);return(t=n==null?void 0:n.isAssociationField)!=null&&t.call(n)&&(delete c.mode,c.quickCreate="none"),c}function normalizeAssignValueAssociationFieldModelUse(e){return isAssignValueAssociationWrapperModelUse(e)?void 0:e}function resolveAssignValueAssociationFieldModelUse(e){var t,o;const{currentFieldModelUse:r,defaultBindingUse:i,preferFormItemFieldModel:n}=e,l=normalizeAssignValueAssociationFieldModelUse(r),a=normalizeAssignValueAssociationFieldModelUse(i);return isAssignValueAssociationWrapperModelUse(r)?a??ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE:n?(t=l??a)!=null?t:ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE:(o=a??l)!=null?o:ASSIGN_VALUE_ASSOCIATION_FIELD_MODEL_USE}function resolveAssignValueFieldMode(e){var t,o,r;const{fieldModelUse:i,collectionField:n}=e,l=(o=(t=n==null?void 0:n.uiSchema)==null?void 0:t["x-component-props"])==null?void 0:o.mode;return(r=n==null?void 0:n.isAssociationField)!=null&&r.call(n)&&isAssignValueAssociationSelectModelUse(i)?"Select":(n==null?void 0:n.interface)==="multipleSelect"?l??"multiple":l}function resolveAssignValueFieldModelConfig(e){var t,o,r,i;const{itemModel:n,defaultBindingUse:l,collectionField:a,preferFormItemFieldModel:c,fieldSettingsInit:u}=e,d=(t=e.fieldSource)!=null?t:resolveAssignValueFieldSource(n),{currentFieldModelUse:m,originFieldModel:p}=d,h=(o=a==null?void 0:a.isAssociationField)!=null&&o.call(a)?resolveAssignValueAssociationFieldModelUse({currentFieldModelUse:m,defaultBindingUse:l,preferFormItemFieldModel:c}):c?m??l:l??m,g=(r=p==null?void 0:p.stepParams)!=null?r:{},f=te(g,["fieldBinding"]),_=x({},f);return u&&(_.fieldSettings=I(x({},_.fieldSettings),{init:x(x({},(i=_.fieldSettings)==null?void 0:i.init),u)})),{use:h,stepParams:_}}const FieldAssignValueInput=({targetPath:e,value:t,onChange:o,placeholder:r,extraMetaTree:i,operator:n,operatorMetaList:l,preferFormItemFieldModel:a,associationFieldNamesOverride:c,enableDateVariableAsConstant:u=!1})=>{var d,m,p,h;const g=(0,import_flow_engine.useFlowContext)(),f=import_react2.default.useCallback(G=>{if(!G||typeof G!="object"||!("target"in G))return G;const X=G.target;return!X||typeof X!="object"||!("value"in X)?G:X.value},[]),_=import_react2.default.useRef(i);import_react2.default.useEffect(()=>{_.current=i},[i]);const v=import_react2.default.useMemo(()=>e?findFormItemModelByFieldPath(g.model,e):null,[g.model,e]),b=import_react2.default.useCallback((G,X)=>{var ie;if(!G||typeof X!="string"||!X.includes("."))return null;const ee=X.split(".").filter(Boolean);if(ee.length<2)return null;let ne=G;for(let le=0;le<ee.length;le++){const me=ee[le],he=le===ee.length-1,ae=typeof(ne==null?void 0:ne.getField)=="function"?ne.getField(me):void 0;if(!ae)return null;if(he)return{collection:ne,fieldName:me,collectionField:ae};if(!((ie=ae==null?void 0:ae.isAssociationField)!=null&&ie.call(ae))||!(ae!=null&&ae.targetCollection))return null;ne=ae.targetCollection}return null},[]),F=import_react2.default.useMemo(()=>{var G,X,ie,ee,ne,le,me,he,ae,xe,ge,ve,de,ce,se,ue,pe,_e;if(v){const Se=v,Ne=v.context,{collection:De,dataSource:Le,blockModel:Re}=Ne,Me=((G=v==null?void 0:v.getStepParams)==null?void 0:G.call(v,"fieldSettings","init"))||{},Te=((X=v==null?void 0:v.context)==null?void 0:X.dataSourceManager)||((ee=(ie=g.model)==null?void 0:ie.context)==null?void 0:ee.dataSourceManager),Je=getCollectionFromModel(g.model),Oe=De||(Me!=null&&Me.dataSourceKey&&Me!=null&&Me.collectionName?(ne=Te==null?void 0:Te.getCollection)==null?void 0:ne.call(Te,Me.dataSourceKey,Me.collectionName):void 0)||Je,rt=Le||(Me!=null&&Me.dataSourceKey?(le=Te==null?void 0:Te.getDataSource)==null?void 0:le.call(Te,Me.dataSourceKey):void 0)||(Oe!=null&&Oe.dataSourceKey?(me=Te==null?void 0:Te.getDataSource)==null?void 0:me.call(Te,Oe.dataSourceKey):void 0),Ue=resolveAssignValueFieldPath(v),ze=Ue==null?void 0:Ue.split(".").slice(-1)[0],Ke=ze?(he=Oe==null?void 0:Oe.getField)==null?void 0:he.call(Oe,ze):void 0,We=(xe=(ae=Se==null?void 0:Se.customFieldModelInstance)==null?void 0:ae.context)==null?void 0:xe.collectionField;return{itemModel:v,collection:Oe||null,dataSource:rt||null,blockModel:Re,fieldPath:Ue||null,fieldName:ze||null,collectionField:Ke||We||null}}const fe=getCollectionFromModel(g.model),Ce=((ve=(ge=g.model)==null?void 0:ge.context)==null?void 0:ve.blockModel)||g.model,Ie={itemModel:null,collection:null,dataSource:null,blockModel:Ce,fieldPath:null,fieldName:null,collectionField:null},je=typeof(fe==null?void 0:fe.getField)=="function"?fe.getField(e):null;if(je){const Se=String((je==null?void 0:je.name)||e||""),Ne=(ce=(de=g.model)==null?void 0:de.context)==null?void 0:ce.dataSourceManager,De=(fe!=null&&fe.dataSourceKey?(se=Ne==null?void 0:Ne.getDataSource)==null?void 0:se.call(Ne,fe.dataSourceKey):void 0)||null;return I(x({},Ie),{collection:fe,dataSource:De,blockModel:Ce,fieldPath:Se,fieldName:Se,collectionField:je||null})}const ke=b(fe,e);if(!ke)return Ie;const we=ke.collection,ye=ke.fieldName,be=(pe=(ue=g.model)==null?void 0:ue.context)==null?void 0:pe.dataSourceManager,Ae=(we!=null&&we.dataSourceKey?(_e=be==null?void 0:be.getDataSource)==null?void 0:_e.call(be,we.dataSourceKey):void 0)||null;return I(x({},Ie),{collection:we,dataSource:Ae,blockModel:Ce,fieldPath:ye,fieldName:ye,collectionField:ke.collectionField||null})},[g.model,v,b,e]),{collection:y,dataSource:C,blockModel:S,fieldPath:P,fieldName:j,collectionField:A}=F,T=(m=(d=F==null?void 0:F.itemModel)==null?void 0:d.context)==null?void 0:m.collectionField,N=import_react2.default.useMemo(()=>resolveAssignValueFieldSource(v),[v]),D=import_react2.default.useMemo(()=>{var G;const X=A||T||null;if(!(!((G=X==null?void 0:X.isAssociationField)!=null&&G.call(X))||!isToManyAssociationField(X)))return N.currentAllowMultiple},[A,N.currentAllowMultiple,T]),w=import_react2.default.useMemo(()=>getFieldInterface(A)||getFieldInterface(T),[A,T]),k=A||T,B=import_react2.default.useMemo(()=>{var G,X,ie;if((G=A==null?void 0:A.isAssociationField)!=null&&G.call(A)||(X=T==null?void 0:T.isAssociationField)!=null&&X.call(T)){const ne=A||T||null;if(ne&&isToManyAssociationField(ne))return D??!0}const ee=getFieldInterface(A);return ee==="multipleSelect"||ee==="checkboxGroup"||((ie=A==null?void 0:A.uiSchema)==null?void 0:ie.type)==="array"},[A,D,T]),E=import_react2.default.useMemo(()=>{if(w&&DATE_FIELD_INTERFACES.has(w))return!0;const G=typeof j=="string"&&j||(typeof e=="string"?e.split(".").filter(Boolean).slice(-1)[0]:"");return G==="createdAt"||G==="updatedAt"},[j,w,e]),M=u&&E,O=import_react2.default.useMemo(()=>{if(!M)return DEFAULT_DATE_VARIABLE_COMPONENT_PROPS;const G=getFieldComponentProps(k),X=normalizeExactDatePickerMode(G==null?void 0:G.picker),ie=["datetime","datetimeNoTz","createdAt","updatedAt","unixTimestamp"].includes(w),ee=typeof(G==null?void 0:G.showTime)=="boolean"?G.showTime:ie,ne=typeof(G==null?void 0:G.dateFormat)=="string"&&G.dateFormat?G.dateFormat:typeof(G==null?void 0:G.format)=="string"&&G.format?G.format.split(" ")[0]:"YYYY-MM-DD",le=typeof(G==null?void 0:G.timeFormat)=="string"&&G.timeFormat?G.timeFormat:"HH:mm:ss",me=typeof(G==null?void 0:G.format)=="string"&&G.format?G.format:ee?`${ne} ${le}`:ne;return{picker:X,showTime:ee,timeFormat:le,format:me,exactNormalizeMode:getDateVariableExactNormalizeMode(w)}},[k,w,M]),q=import_react2.default.useMemo(()=>te(O,["exactNormalizeMode"]),[O]),$=import_react2.default.useRef(q);$.current=q;const V=import_react2.default.useRef(g.t);V.current=g.t;const U=import_react2.default.useCallback(G=>{let X=G;if(n&&(X=normalizeFilterValueByOperator(n,X)),B){if(X==null||X==="")return[];if(!Array.isArray(X))return[X]}return X},[B,n]),[z,K]=import_react2.default.useState(null);import_react2.default.useEffect(()=>{var G,X,ie,ee,ne,le,me,he,ae,xe,ge,ve,de,ce,se,ue,pe,_e,fe,Ce,Ie,je,ke,we,ye,be,Ae,Se,Ne,De,Le,Re,Me,Te,Je,Oe,rt,Ue;if(!P||!j)return;const ze=v,Ke=((X=(G=F==null?void 0:F.itemModel)==null?void 0:G.context)==null?void 0:X.engine)||((ee=(ie=g.model)==null?void 0:ie.context)==null?void 0:ee.engine);if(!Ke)return;const We=((ne=ze==null?void 0:ze.context)==null?void 0:ne.dataSourceManager)||((me=(le=g.model)==null?void 0:le.context)==null?void 0:me.dataSourceManager),Ee=y||getCollectionFromModel(ze)||getCollectionFromModel(g.model),{customFieldName:Ft,customFieldProps:Pt,currentAllowMultiple:ut,originFieldModel:dt,originProps:It}=N,kt=(he=dt==null?void 0:dt.context)==null?void 0:he.collectionField,Fe=A||kt||void 0,mt=C||(Ee!=null&&Ee.dataSourceKey?(ae=We==null?void 0:We.getDataSource)==null?void 0:ae.call(We,Ee.dataSourceKey):null),pt=(typeof(Ee==null?void 0:Ee.getFields)=="function"?Ee.getFields()||[]:[]).find(Ve=>(Ve==null?void 0:Ve.name)===j)||(typeof(Ee==null?void 0:Ee.getField)=="function"?Ee.getField(j):void 0)||Fe,ht=pt?import_flow_engine.EditableItemModel.getDefaultBindingByField(((xe=F==null?void 0:F.itemModel)==null?void 0:xe.context)||((ge=g.model)==null?void 0:ge.context),pt):null,At=ht==null?void 0:ht.modelName,Bt=resolveAssignValueFieldSettingsInit({collection:Ee,customFieldName:Ft,fieldPath:P,fieldName:j}),{use:it,stepParams:Nt}=resolveAssignValueFieldModelConfig({itemModel:v,defaultBindingUse:At,collectionField:Fe,fieldSource:N,preferFormItemFieldModel:a,fieldSettingsInit:Bt});if(!it)return;const Lt=resolveAssignValueFieldProps({placeholder:r,originProps:It,customFieldProps:Pt,collectionField:Fe}),Be=(ve=Ke==null?void 0:Ke.createModel)==null?void 0:ve.call(Ke,{use:"VariableFieldFormModel",subModels:{fields:[{use:it,stepParams:Nt,props:Lt}]}});if(!Be)return;Ee&&((ce=(de=Be.context)==null?void 0:de.defineProperty)==null||ce.call(de,"collection",{value:Ee})),mt&&((ue=(se=Be.context)==null?void 0:se.defineProperty)==null||ue.call(se,"dataSource",{value:mt})),Fe&&((_e=(pe=Be.context)==null?void 0:pe.defineProperty)==null||_e.call(pe,"collectionField",{value:Fe})),S&&((Ce=(fe=Be.context)==null?void 0:fe.defineProperty)==null||Ce.call(fe,"blockModel",{value:S})),Be.context&&Object.defineProperty(Be.context,"resource",{configurable:!0,enumerable:!0,get:()=>S==null?void 0:S.resource});const Pe=(je=(Ie=Be==null?void 0:Be.subModels)==null?void 0:Ie.fields)==null?void 0:je[0],nt=(ke=Fe==null?void 0:Fe.isAssociationField)!=null&&ke.call(Fe)&&isToManyAssociationField(Fe)?ut??!0:void 0,gt=nt??((we=Fe==null?void 0:Fe.isAssociationField)!=null&&we.call(Fe)?isToManyAssociationField(Fe):void 0),Ot=withFullWidthStyle(pickStyle((ye=Pe==null?void 0:Pe.props)==null?void 0:ye.style)),ft=c==null?void 0:c.label;ft&&typeof(Pe==null?void 0:Pe.setStepParams)=="function"&&Pe.setStepParams("selectSettings","fieldNames",{label:ft}),(be=Pe==null?void 0:Pe.setProps)==null||be.call(Pe,x(x({disabled:!1,readPretty:!1,pattern:"editable",updateAssociation:!1,style:Ot},gt!==void 0?{multiple:gt}:{}),nt!==void 0?{allowMultiple:nt}:{})),(Ae=Pe==null?void 0:Pe.dispatchEvent)==null||Ae.call(Pe,"beforeRender",void 0,{sequential:!0,useCache:!0}),ensureOptionsFromUiSchemaEnumIfAbsent(Pe,Fe);const xt=resolveAssignValueFieldMode({fieldModelUse:it,collectionField:Fe});if(((Se=Fe==null?void 0:Fe.isAssociationField)!=null&&Se.call(Fe)&&isAssignValueAssociationSelectModelUse(it)||((Ne=Pe==null?void 0:Pe.props)==null?void 0:Ne.mode)===void 0)&&xt&&((De=Pe==null?void 0:Pe.setProps)==null||De.call(Pe,{mode:xt})),Fe!=null&&Fe.targetCollection){const Ve=Fe.targetCollection,qe=((Le=Pe==null?void 0:Pe.props)==null?void 0:Le.fieldNames)||{},lt=(Je=(Te=(Me=(Re=c==null?void 0:c.value)!=null?Re:qe==null?void 0:qe.value)!=null?Me:Fe==null?void 0:Fe.targetKey)!=null?Te:Ve==null?void 0:Ve.filterTargetKey)!=null?Je:"id",_t=(rt=(Oe=c==null?void 0:c.label)!=null?Oe:qe==null?void 0:qe.label)!=null?rt:Fe==null?void 0:Fe.targetCollectionTitleFieldName;(Ue=Pe==null?void 0:Pe.setProps)==null||Ue.call(Pe,{fieldNames:I(x(x({},qe),_t?{label:_t}:{}),{value:lt})})}return K(Be),()=>{var Ve,qe;(qe=(Ve=Be.subModels.fields).forEach)==null||qe.call(Ve,lt=>lt.remove()),Be.remove()}},[y,C,S,P,j,g,r,F,A,v,N,a,c==null?void 0:c.label,c==null?void 0:c.value]),import_react2.default.useEffect(()=>{var G,X,ie,ee,ne,le,me,he;const ae=(X=(G=z==null?void 0:z.subModels)==null?void 0:G.fields)==null?void 0:X[0];if(!ae||!n||!Array.isArray(l)||l.length===0)return;const xe=l.find(ce=>(ce==null?void 0:ce.value)===n),ge=(ie=xe==null?void 0:xe.schema)==null?void 0:ie["x-component-props"];if(ge&&typeof(ae==null?void 0:ae.setProps)=="function"){const ce=withFullWidthStyle(pickStyle(ge==null?void 0:ge.style)||pickStyle((ee=ae==null?void 0:ae.props)==null?void 0:ee.style));ae.setProps(I(x({},ge),{style:ce}))}const ve=((le=(ne=F==null?void 0:F.itemModel)==null?void 0:ne.context)==null?void 0:le.app)||((he=(me=g==null?void 0:g.model)==null?void 0:me.context)==null?void 0:he.app),de=resolveOperatorComponent(ve,n,l);if(de&&ae instanceof InputFieldModel){const ce=ae.__originalRender||ae.render;ae.__originalRender=ce;const{Comp:se,props:ue}=de;ae.render=()=>{var pe;return(0,import_jsx_runtime.jsx)(se,I(x(x({},ae.props),ue),{style:x(x({width:"100%"},(pe=ae.props)==null?void 0:pe.style),ue==null?void 0:ue.style)}))},rewrapReactiveRender$1(ae)}else typeof ae.__originalRender=="function"&&(ae.render=ae.__originalRender,rewrapReactiveRender$1(ae))},[n,l,z,g,F]);const W=import_react2.default.useMemo(()=>G=>{const X=pickStyle(G==null?void 0:G.style);return import_react2.default.useEffect(()=>{var ie,ee,ne,le;const me=U(G==null?void 0:G.value),he=xe=>{var ge,ve,de,ce,se;const ue=f(xe),pe=n?normalizeFilterValueByOperator(n,ue):ue,_e=U(pe);(ge=z==null?void 0:z.setProps)==null||ge.call(z,{value:_e});const fe=(de=(ve=z==null?void 0:z.subModels)==null?void 0:ve.fields)==null?void 0:de[0];(ce=fe==null?void 0:fe.setProps)==null||ce.call(fe,{value:_e}),(se=G==null?void 0:G.onChange)==null||se.call(G,pe)},ae=(ee=(ie=z==null?void 0:z.subModels)==null?void 0:ie.fields)==null?void 0:ee[0];(ne=ae==null?void 0:ae.setProps)==null||ne.call(ae,{value:me,onChange:he,onCompositionStart:G==null?void 0:G.onCompositionStart,onCompositionUpdate:G==null?void 0:G.onCompositionUpdate,onCompositionEnd:G==null?void 0:G.onCompositionEnd}),(le=z==null?void 0:z.setProps)==null||le.call(z,I(x({},G),{value:me,onChange:he}))},[G]),z?(0,import_jsx_runtime.jsx)("div",{style:I(x({},withFullWidthStyle(X)),{flex:1}),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:z,showFlowSettings:!1})}):(0,import_jsx_runtime.jsx)(import_antd.Input,{value:G==null?void 0:G.value,onChange:ie=>{var ee;return(ee=G==null?void 0:G.onChange)==null?void 0:ee.call(G,f(ie))},placeholder:r,style:withFullWidthStyle(X)})},[r,z,U,f]),Y=import_react2.default.useMemo(()=>G=>{var X,ie,ee,ne;const le=pickStyle(G==null?void 0:G.style),me=G==null?void 0:G.value,he=(0,import_flow_engine.isCtxDateExpression)(me)?(0,import_flow_engine.parseCtxDateExpression)(me):me,ae=typeof he>"u"?void 0:he,{token:xe}=import_antd.theme.useToken(),[ge,ve]=import_react2.default.useState(!1),de=V.current,ce=$.current,se=import_react2.default.useMemo(()=>buildDateDynamicOptions(de,!0),[de]),ue=ae&&typeof ae=="object"&&!Array.isArray(ae)?ae==null?void 0:ae.type:void 0,pe=typeof ue=="string"&&ue?ue:"exact",_e=Array.isArray(ae),fe=toExactPickerDisplayValue(ae,{format:ce.format,isRange:!1}),Ce=toExactPickerDisplayValue(ae,{format:ce.format,isRange:!0}),Ie=ye=>{var be,Ae;if(ve(!1),ye==="exact"){(be=G==null?void 0:G.onChange)==null||be.call(G,"");return}const Se={type:ye};(ye==="past"||ye==="next")&&(Se.number=1,Se.unit="day"),(Ae=G==null?void 0:G.onChange)==null||Ae.call(G,Se)},je=ye=>{var be;(be=G==null?void 0:G.onChange)==null||be.call(G,ye||"")},ke=ye=>{var be;(be=G==null?void 0:G.onChange)==null||be.call(G,ye||"")},we=()=>{const ye=se.slice(0,3),be=se.slice(3),Ae=import_css.css`
1770
1770
  padding: 3px 10px;
1771
1771
  cursor: pointer;
1772
1772
  white-space: nowrap;
@@ -1825,7 +1825,7 @@ if (!ctx.record) {
1825
1825
  flex-shrink: 0;
1826
1826
  flex: 1;
1827
1827
  }
1828
- `},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},"x-reactions":{dependencies:["mode"],fulfill:{state:{hidden:'{{$deps[0] === "html"}}'}}},properties:{add:{type:"void",title:'{{t("Add parameter")}}',"x-component":"ArrayItems.Addition"}}},openInNewWindow:{type:"boolean","x-content":t("Open in new window"),"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:["mode"],fulfill:{state:{hidden:'{{$deps[0] === "html"}}'}}}}}},handler(e,t){e.model.setProps({url:t.url,searchParams:t.searchParams,openInNewWindow:t.openInNewWindow})}}}});class ExpandCollapseActionModel extends ActionModel{constructor(){super(...arguments),R(this,"expandFlag"),R(this,"defaultProps",{type:"default",icon:"DownOutlined"})}setTitle(t){this.setProps({title:t})}setExpandFlag(t){this.expandFlag=t}getTitle(){return this.expandFlag?this.context.t("Collapse all"):this.context.t("Expand all")}getIcon(){return this.expandFlag?"NodeCollapseOutlined":"NodeExpandOutlined"}}R(ExpandCollapseActionModel,"scene",ActionSceneEnum.collection);function getIdsWithChildren(e,{idKey:t="id",childrenKey:o="children"}={}){const r=[];function i(n){if(Array.isArray(n))for(const l of n){const a=l[o];r.push(l[t]),Array.isArray(a)&&a.length>0&&i(a)}}return i(e),r}const allIncludesChildren=e=>getIdsWithChildren(e);ExpandCollapseActionModel.registerFlow({key:"expandCollapseSettingsInit",sort:200,steps:{init:{handler(e,t){e.blockModel.props.defaultExpandAllRows?e.model.setExpandFlag(!0):e.model.setExpandFlag(!1)}}}});ExpandCollapseActionModel.registerFlow({key:"expandCollapseSettings",on:"click",steps:{expandCollapse:{handler(e,t){return L(this,null,function*(){var o;if(!((o=e.blockModel)!=null&&o.resource))return;const r=e.blockModel.resource,{treeTable:i}=e.blockModel.props;if(i)if(e.model.expandFlag)e.blockModel.setProps({expandedRowKeys:[]}),e.model.setExpandFlag(!1);else{const n=allIncludesChildren(r.getData());e.blockModel.setProps({expandedRowKeys:n}),e.model.setExpandFlag(!0)}})}}}});ExpandCollapseActionModel.define({label:(0,import_flow_engine.escapeT)("Expand/Collapse"),hide(e){var t;return((t=e.collection)==null?void 0:t.template)!=="tree"||e.model.props.treeTable===!1}});class AddChildActionModel extends PopupActionModel{constructor(){super(...arguments),R(this,"defaultProps",{type:"link",title:(0,import_flow_engine.tExpr)("Add child"),icon:"PlusOutlined"})}getAclActionName(){return"create"}onInit(t){super.onInit(t),this.context.defineProperty("association",{get:()=>this.context.blockModel.dataSource.getAssociation(`${this.context.blockModel.collection.name}.children`)})}}R(AddChildActionModel,"capabilityActionName",null);AddChildActionModel.registerFlow({key:"addChildSettingsInit",steps:{addChildInit:{handler(e,t){return L(this,null,function*(){e.model.onClick=o=>{e.model.dispatchEvent("click",I(x({event:o},e.inputArgs),{sourceId:e.record.id,filterByTk:null}),{debounce:!0})}})}}}});AddChildActionModel.define({label:(0,import_flow_engine.tExpr)("Add child"),hide(e){var t;return((t=e.collection)==null?void 0:t.template)!=="tree"||e.blockModel.props.treeTable===!1}});RecordActionGroupModel.registerActionModels({AddChildActionModel});const SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG="__saveStepParamsWithSubModels";function markSaveStepParamsWithSubModels(e){if(!e||typeof e!="object"&&typeof e!="function")throw new Error("[saveStepParamsWithSubModels] model is not an object");e[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]=!0}function saveStepParamsWithSubModelsIfNeeded(e,t){return L(this,null,function*(){if(!e||typeof e!="object"&&typeof e!="function")throw new Error("[saveStepParamsWithSubModels] model is not an object");const o=e;if(o[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]!==!0)return yield t();if(typeof o.save!="function")throw new Error("[saveStepParamsWithSubModels] model.save is not a function");try{return yield o.save()}finally{delete o[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]}})}function evaluateCondition(e,t){const o=(r,i,n)=>{var l,a,c;return i?(c=(a=(l=e==null?void 0:e.app)==null?void 0:l.jsonLogic)==null?void 0:a.apply)==null?void 0:c.call(a,{[i]:[r,n]}):!0};try{return(0,import_client.evaluateConditions)((0,import_client.removeInvalidFilterItems)(t),o)}catch{return!1}}function parsePathString(e){const t=[];let o=0;const r=e.length,i=()=>{const n=o;for(;o<r&&e[o]!=="."&&e[o]!=="[";)o++;const l=e.slice(n,o);l&&t.push(l)};for(;o<r;){const n=e[o];if(n==="."){o++;continue}if(n==="["){o++;const l=o;for(;o<r&&e[o]!=="]";)o++;const a=e.slice(l,o);o++,/^\d+$/.test(a)?t.push(Number(a)):a&&t.push({placeholder:a});continue}i()}return t}function parseFieldIndexEntries(e){const t=Array.isArray(e)?e:[],o=[];for(const r of t){if(typeof r!="string")continue;const[i,n]=r.split(":"),l=Number(n);!i||Number.isNaN(l)||o.push({name:i,index:l})}return o}function resolveDynamicNamePath(e,t){const o=Array.isArray(e)?[...e]:parsePathString(e),r=parseFieldIndexEntries(t),i=[];let n=0;for(let l=0;l<o.length;l++){const a=o[l];if(typeof a=="object"&&a&&"placeholder"in a){const c=i[i.length-1],u=typeof c=="string"?c:void 0;if(!u)return null;for(;n<r.length&&r[n].name!==u;)n++;if(n>=r.length)return null;i.push(r[n].index),n++;continue}if(i.push(a),typeof a=="string"&&n<r.length&&r[n].name===a){const c=o[l+1];typeof c=="number"?n++:typeof c=="object"&&c&&"placeholder"in c||(i.push(r[n].index),n++)}}return i}function namePathToPathKey(e){let t="";for(const o of e){if(typeof o=="number"){t+=`[${o}]`;continue}t?t+=`.${o}`:t=o}return t}function pathKeyToNamePath(e){return parsePathString(e).filter(t=>typeof t!="object")}function buildAncestorKeys(e){const t=[],o=[];for(const r of e)o.push(r),t.push(namePathToPathKey(o));return t}function shouldProxyObjectValue(e){return!e||typeof e!="object"?!1:Array.isArray(e)||import_lodash.default.isPlainObject(e)}function recordDep(e,t){if(t)for(const o of buildAncestorKeys(e))t.deps.add(`fv:${o}`)}function createFormValuesProxy(e){const{valuesMirror:t,collector:o,basePath:r,getFormValuesSnapshot:i,getFormValueAtPath:n}=e,l=()=>r.length?import_lodash.default.get(t,r):t,a=l(),c=a&&(typeof a=="object"||typeof a=="function")?a:Array.isArray(a)?[]:{},u=d=>createFormValuesProxy({valuesMirror:t,basePath:d,collector:o,getFormValuesSnapshot:i,getFormValueAtPath:n});return new Proxy(c,{get(d,m){if(m==="toJSON")return o&&(o.wildcard=!0),r.length===0?()=>i():()=>(0,import_reactive.toJS)(l());if(typeof m=="symbol"){o&&(o.wildcard=!0);const b=l();return b==null?void 0:b[m]}const p=l();if(p==null)return;if(m==="__raw")return p;if(m==="__proto__"||m==="prototype"||m==="constructor"){o&&(o.wildcard=!0);return}const h=Array.isArray(p),g=h&&(typeof m=="number"&&Number.isInteger(m)||typeof m=="string"&&/^\d+$/.test(m));if(h&&!g){o&&(o.wildcard=!0);const b=p[m];return typeof b=="function"?b.bind(p):b}const f=g?Number(m):m,_=[...r,f];recordDep(_,o);let v=p[m];if(typeof v>"u"){const b=n(_);import_lodash.default.isEqual(b,v)||(import_lodash.default.set(t,_,b),v=b)}return v==null||typeof v!="object"?v:shouldProxyObjectValue(v)?u(_):v},ownKeys(){o&&(o.wildcard=!0);const d=l();return d?Reflect.ownKeys(d):[]},getOwnPropertyDescriptor(d,m){const p=l();if(p)return Object.getOwnPropertyDescriptor(p,m)},has(d,m){const p=l();return p?m in p:!1}})}function collectStaticDepsFromTemplateValue(e,t){try{const o=(0,import_flow_engine.extractUsedVariablePaths)(e)||{};for(const[r,i]of Object.entries(o)){const n=Array.isArray(i)?i:[],l=n.length?n:[""];for(const a of l){if(r==="formValues"){if(!a){t.wildcard=!0;continue}const u=parsePathString(String(a)).filter(d=>typeof d!="object");recordDep(u,t);continue}const c=a?`ctx:${r}:${String(a)}`:`ctx:${r}`;t.deps.add(c)}}}catch{}}function collectStaticDepsFromRunJSValue(e,t){if((0,import_flow_engine.isRunJSValue)(e))try{const o=(0,import_flow_engine.extractUsedVariablePathsFromRunJS)(e.code)||{};for(const[r,i]of Object.entries(o)){const n=Array.isArray(i)?i:[],l=n.length?n:[""];for(const a of l){if(r==="formValues"){if(!a){t.wildcard=!0;continue}const u=parsePathString(String(a)).filter(d=>typeof d!="object");recordDep(u,t);continue}const c=a?`ctx:${r}:${String(a)}`:`ctx:${r}`;t.deps.add(c)}}}catch{}}function createFormPatcher(e){let t,o,r;const i=()=>{const n=t;n&&(o&&(n.setFieldValue=o),r&&(n.setFieldsValue=r),t=void 0,o=void 0,r=void 0)};return{patch:n=>{if(t===n)return;i();const l=typeof(n==null?void 0:n.setFieldValue)=="function"?n.setFieldValue.bind(n):void 0,a=typeof(n==null?void 0:n.setFieldsValue)=="function"?n.setFieldsValue.bind(n):void 0;t=n,o=l,r=a,l&&(n.setFieldValue=(c,u)=>{if(e.isSuppressed()){l(c,u);return}e.setFormValues(e.getCallerContext(),[{path:c,value:u}],{source:"system"}).catch(()=>{})}),a&&(n.setFieldsValue=c=>{if(e.isSuppressed()){a(c);return}e.setFormValues(e.getCallerContext(),c,{source:"system"}).catch(()=>{})})},restore:i}}const MAX_WRITES_PER_PATH_PER_TX=20;function isEmptyValue(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:import_lodash.default.isPlainObject(e)?Object.keys(e).length===0:!1}function createTxId(){return`${Date.now()}-${Math.random().toString(16).slice(2)}`}const SKIP_RULE_VALUE=Symbol("SKIP_RULE_VALUE"),UNRESOLVED_ASSOCIATION_IDENTITY=Symbol("UNRESOLVED_ASSOCIATION_IDENTITY"),LINKAGE_DEFAULT_RULE_PRIORITY=1e3;class RuleEngine{constructor(t){R(this,"options"),R(this,"rules",new Map),R(this,"lastRuleWriteByTargetKey",new Map),R(this,"assignTemplatesByTargetPath",new Map),R(this,"formItemTargetPaths",new Set),R(this,"updateAssociationByTargetPath",new Map),R(this,"pendingRuleIds",new Set),R(this,"ruleDebounceUntilById",new Map),R(this,"ruleDebounceTimersById",new Map),R(this,"defaultRuleIdsByMasterUid",new Map),R(this,"defaultRuleMasterDisposers",new Map),R(this,"runningRules",!1),R(this,"rulesEnabled",!1),R(this,"currentRuleTxId",null),this.options=t}getAssignRuleBlockId(t){return`form-assign:${t}:block`}removeAssignRuleBlockInstance(t){const o=this.getAssignRuleBlockId(t);this.rules.has(o)&&this.removeRule(o)}removeRowGridAssignRuleInstances(t){var o,r;const i=`form-assign:${t}:`,n=this.getAssignRuleBlockId(t),l=[];for(const[a,c]of this.rules.entries()){if(!a.startsWith(i)||a===n)continue;const u=(r=(o=c==null?void 0:c.rule)==null?void 0:o.getContext)==null?void 0:r.call(o),d=u==null?void 0:u.model;d&&this.isRowGridModel(d)&&l.push(a)}for(const a of l)this.removeRule(a)}hasAnyNonBlockAssignRuleInstance(t){const o=`form-assign:${t}:`,r=this.getAssignRuleBlockId(t);for(const i of this.rules.keys())if(i.startsWith(o)&&i!==r)return!0;return!1}ensureBlockAssignRuleInstancesForTargetPath(t){if(this.options.isDisposed()||!t||!this.shouldCreateBlockLevelAssignRule(t))return;const o=this.assignTemplatesByTargetPath.get(t)||[];if(o.length)for(const r of o){const i=r!=null&&r.__key?String(r.__key):"";if(!i||this.hasAnyNonBlockAssignRuleInstance(i))continue;const n=((r==null?void 0:r.mode)==="default"?"default":"assign")=="default"?"default":"system",l=(r==null?void 0:r.enable)!==!1,a=this.getAssignRuleBlockId(i);if(this.rules.has(a))continue;const c={id:a,source:n,priority:10+(r.__order||0),debounceMs:0,getEnabled:()=>l&&!!t,getTarget:()=>t,getValue:()=>r==null?void 0:r.value,getCondition:()=>r==null?void 0:r.condition,getContext:()=>this.options.getBlockContext()};this.rules.set(a,{rule:c,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(a)}}getCollectionFromContext(t){var o,r,i;return(i=t==null?void 0:t.collection)!=null?i:(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.collection}getRootCollection(){const t=this.options.getBlockContext();return this.getCollectionFromContext(t)}shouldCreateBlockLevelAssignRule(t){var o,r;const i=this.options.getBlockContext();let n=this.getCollectionFromContext(i);if(!(n!=null&&n.getField))return!0;const l=parsePathString(t).filter(a=>typeof a!="object");if(l.length<=1)return!0;for(let a=0;a<l.length-1;a++){const c=l[a];if(typeof c!="string")continue;const u=(o=n==null?void 0:n.getField)==null?void 0:o.call(n,c);if(!((r=u==null?void 0:u.isAssociationField)!=null&&r.call(u)))break;if(isToManyAssociationField(u)){if(typeof l[a+1]!="number")return!1;a+=1}if(n=u==null?void 0:u.targetCollection,!(n!=null&&n.getField))break}return!0}collectAssociationPrefixPaths(t,o){var r,i;const n=[];let l=this.getRootCollection()||this.getCollectionFromContext(t);if(!(l!=null&&l.getField))return n;const a=[];for(let c=0;c<o.length-1;c++){const u=o[c];if(typeof u!="string")break;const d=(r=l==null?void 0:l.getField)==null?void 0:r.call(l,u);if(!((i=d==null?void 0:d.isAssociationField)!=null&&i.call(d)))break;if(a.push(u),isToManyAssociationField(d)){const m=o[c+1];if(typeof m!="number")break;a.push(m),c+=1}if(n.push([...a]),l=d==null?void 0:d.targetCollection,!(l!=null&&l.getField))break}return n}shouldSkipToManyAssociationWriteWithoutIndex(t,o){var r,i;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return!1;for(let l=0;l<o.length-1;l++){const a=o[l];if(typeof a!="string")continue;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c)))break;if(isToManyAssociationField(c)){if(typeof o[l+1]!="number")return!0;l+=1}if(n=c==null?void 0:c.targetCollection,!(n!=null&&n.getField))break}return!1}shouldSkipAssociationNestedWrite(t,o){const r=this.collectAssociationPrefixPaths(t,o);if(!r.length)return!1;for(const i of r){const n=this.options.getFormValueAtPath(i);if(n==null){const l=i.filter(a=>typeof a=="string").join(".");if(l&&this.getUpdateAssociationForTargetPath(l)||this.isAssociationTargetKeyWrite(t,o,i))continue;return!0}if(typeof n!="object")return!0}return!1}getAssociationTargetKeyFields(t){var o,r,i,n,l;const a=(l=(n=(r=t==null?void 0:t.targetKey)!=null?r:(o=t==null?void 0:t.targetCollection)==null?void 0:o.filterTargetKey)!=null?n:(i=t==null?void 0:t.targetCollection)==null?void 0:i.filterByTk)!=null?l:"id";return Array.isArray(a)?a.filter(c=>typeof c=="string"&&!!c):typeof a=="string"&&a?[a]:["id"]}resolveAssociationFieldByPrefixPath(t,o){var r,i;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return null;let l=null;for(const a of o){if(typeof a=="number")continue;if(typeof a!="string"||!a)break;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c))||(l=c,n=c==null?void 0:c.targetCollection,!(n!=null&&n.getField)))break}return l}isAssociationTargetKeyWrite(t,o,r){var i;if(!Array.isArray(o)||!Array.isArray(r)||o.length!==r.length+1)return!1;const n=o[r.length];if(typeof n!="string"||!n)return!1;const l=this.resolveAssociationFieldByPrefixPath(t,r);return!((i=l==null?void 0:l.isAssociationField)!=null&&i.call(l))||isToManyAssociationField(l)?!1:this.getAssociationTargetKeyFields(l).includes(n)}collectUpdateAssociationInitPatches(t,o){const r=this.collectAssociationPrefixPaths(t,o);if(!r.length)return[];const i=[];for(const l of r){const a=this.options.getFormValueAtPath(l);if(a==null){const c=l.filter(u=>typeof u=="string").join(".");if(!c)return null;if(this.getUpdateAssociationForTargetPath(c)){i.push({path:[...l,"__is_new__"],value:!0});continue}if(this.isAssociationTargetKeyWrite(t,o,l)){i.push({path:[...l],value:{}});continue}return null}if(typeof a!="object")return null}const n=new Map;for(const l of i){const a=namePathToPathKey(l.path);n.has(a)||n.set(a,l)}return Array.from(n.values())}dispose(){for(const{state:t}of this.rules.values())t.depDisposers.forEach(o=>o());this.rules.clear(),this.pendingRuleIds.clear(),this.assignTemplatesByTargetPath.clear();for(const t of this.defaultRuleMasterDisposers.values())t();this.defaultRuleMasterDisposers.clear(),this.defaultRuleIdsByMasterUid.clear();for(const t of this.ruleDebounceTimersById.values())clearTimeout(t);this.ruleDebounceTimersById.clear(),this.ruleDebounceUntilById.clear()}enable(){this.rulesEnabled=!0,this.pendingRuleIds.size&&!this.runningRules&&this.flushRules()}syncAssignRules(t){if(this.options.isDisposed())return;const o=(Array.isArray(t)?t:[]).map((a,c)=>I(x({},a),{key:a!=null&&a.key?String(a.key):`idx:${c}`})),r="form-assign:";for(const a of Array.from(this.rules.keys()))a.startsWith(r)&&this.removeRule(a);this.assignTemplatesByTargetPath.clear(),this.formItemTargetPaths.clear(),this.updateAssociationByTargetPath.clear();let i=0;for(const a of o){const c=a!=null&&a.targetPath?String(a.targetPath):"";if(!c)continue;const u=this.assignTemplatesByTargetPath.get(c)||[];i+=1,u.push(I(x({},a),{__key:String(a.key),__order:i})),this.assignTemplatesByTargetPath.set(c,u)}const n=this.options.getEngine(),l=new Set;if(n!=null&&n.forEachModel){n.forEachModel(c=>{var u;if(!this.isModelInThisForm(c)||!((u=c==null?void 0:c.subModels)!=null&&u.field))return;const d=this.getModelTargetPath(c);d&&this.formItemTargetPaths.add(d),this.cacheUpdateAssociationForModel(c)});const a=c=>{this.cacheUpdateAssociationForModel(c),this.tryRegisterAssignRuleInstancesForModel(c,l);const u=c==null?void 0:c.forks;u&&typeof u.forEach=="function"&&u.forEach(d=>{!d||d!=null&&d.disposed||this.tryRegisterAssignRuleInstancesForModel(d,l)})};n.forEachModel(c=>{a(c)})}for(const[a,c]of this.assignTemplatesByTargetPath.entries())if(!l.has(a)&&this.shouldCreateBlockLevelAssignRule(a))for(const u of c){const d=((u==null?void 0:u.mode)==="default"?"default":"assign")=="default"?"default":"system",m=(u==null?void 0:u.enable)!==!1,p=`${r}${u.__key}:block`;this.rules.has(p)&&this.removeRule(p);const h={id:p,source:d,priority:10+(u.__order||0),debounceMs:0,getEnabled:()=>m&&!!a,getTarget:()=>a,getValue:()=>u==null?void 0:u.value,getCondition:()=>u==null?void 0:u.condition,getContext:()=>this.options.getBlockContext()};this.rules.set(p,{rule:h,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(p)}for(const a of Array.from(this.rules.keys()))a.startsWith("default:")&&this.scheduleRule(a)}onModelMounted(t){var o;if(this.isModelInThisForm(t)&&!(t!=null&&t.isFork)&&(o=t==null?void 0:t.subModels)!=null&&o.field){const r=this.getModelTargetPath(t);r&&this.formItemTargetPaths.add(r),this.cacheUpdateAssociationForModel(t)}this.tryRegisterDefaultRuleInstance(t),this.tryRegisterAssignRuleInstancesForModel(t)}onModelUnmounted(t){var o;if(this.tryUnregisterDefaultRuleInstance(t),this.tryUnregisterAssignRuleInstancesForModel(t),this.isModelInThisForm(t)&&(o=t==null?void 0:t.subModels)!=null&&o.field){const r=this.getModelTargetPath(t);if(r&&(this.ensureBlockAssignRuleInstancesForTargetPath(r),!(t!=null&&t.isFork))){this.updateAssociationByTargetPath.delete(r),this.formItemTargetPaths.delete(r);const i=`${r}.`;for(const l of this.assignTemplatesByTargetPath.keys())l.startsWith(i)&&this.ensureBlockAssignRuleInstancesForTargetPath(l);const n=this.options.getEngine();if(n!=null&&n.forEachModel){const l=a=>{this.tryRegisterAssignRuleInstancesForModel(a);const c=a==null?void 0:a.forks;c&&typeof c.forEach=="function"&&c.forEach(u=>{!u||u!=null&&u.disposed||this.tryRegisterAssignRuleInstancesForModel(u)})};n.forEachModel(a=>l(a))}}}}isModelInThisForm(t){var o;const r=(o=t==null?void 0:t.context)==null?void 0:o.blockModel;return r?String(r.uid)===String(this.options.getBlockModelUid()):!1}cacheUpdateAssociationForModel(t){var o,r;if(this.options.isDisposed()||!this.isModelInThisForm(t)||!t||typeof t!="object"||t!=null&&t.isFork||!((o=t==null?void 0:t.subModels)!=null&&o.field))return;const i=this.getModelTargetPath(t);if(!i)return;const n=(r=t==null?void 0:t.subModels)==null?void 0:r.field,l=!!(n!=null&&n.updateAssociation);this.updateAssociationByTargetPath.get(i)!==!0&&this.updateAssociationByTargetPath.set(i,l)}getUpdateAssociationForTargetPath(t){const o=String(t||"");if(!o)return!1;if(this.updateAssociationByTargetPath.has(o))return!!this.updateAssociationByTargetPath.get(o);const r=this.options.getEngine();return r!=null&&r.forEachModel&&r.forEachModel(i=>{this.cacheUpdateAssociationForModel(i)}),this.updateAssociationByTargetPath.has(o)?!!this.updateAssociationByTargetPath.get(o):(this.updateAssociationByTargetPath.set(o,!1),!1)}getDefaultRuleId(t){var o;const r=t!=null&&t.isFork?String((o=t==null?void 0:t.forkId)!=null?o:"fork"):"master";return`default:${t!=null&&t.uid?String(t.uid):String(t)}:${r}`}getModelTargetNamePath(t){var o;const r=(o=t==null?void 0:t.context)==null?void 0:o.fieldPathArray;if(Array.isArray(r)&&r.length)return r;const i=typeof(t==null?void 0:t.getProps)=="function"?t.getProps():t==null?void 0:t.props,n=i==null?void 0:i.name;return Array.isArray(n)?n:typeof n=="string"?n.includes(".")?n.split("."):[n]:null}getAssignTemplateTargetPathForModel(t){const o=this.getModelTargetPath(t);if(o)return o;const r=this.getModelTargetNamePath(t);if(!(r!=null&&r.length))return"";const i=r.filter(n=>typeof n!="number");return i.length?namePathToPathKey(i):""}hasAssignTemplateForTargetPath(t){const o=String(t||"");return o?this.assignTemplatesByTargetPath.has(o):!1}tryRegisterDefaultRuleInstance(t){if(this.options.isDisposed()||!this.isModelInThisForm(t)||!t||typeof t!="object")return;const o=typeof t.getProps=="function"?t.getProps():t.props;if(!o||typeof o!="object")return;const r=this.getModelTargetNamePath(t);if(!r)return;const i=this.getDefaultRuleId(t);if(this.rules.has(i))return;const n=t.master||t,l=this.getAssignTemplateTargetPathForModel(t);this.bindMasterInitialValue(n,i);const a=()=>{var g,f;const _=(f=(g=n==null?void 0:n.getProps)==null?void 0:g.call(n))!=null?f:n==null?void 0:n.props;return _==null?void 0:_.initialValue},c=a();let u=!1;const d=()=>{const g=a();if(!u&&!import_lodash.default.isEqual(g,c)&&(u=!0),!this.hasAssignTemplateForTargetPath(l)||u||typeof c>"u")return g},m=()=>typeof d()<"u"?LINKAGE_DEFAULT_RULE_PRIORITY:0,p=()=>{var g,f,_,v;if(!this.hasAssignTemplateForTargetPath(l))try{const b=(f=(g=n==null?void 0:n.getStepParams)==null?void 0:g.call(n,"editItemSettings","initialValue"))==null?void 0:f.defaultValue;if(typeof b<"u")return b;const F=(v=(_=n==null?void 0:n.getStepParams)==null?void 0:_.call(n,"formItemSettings","initialValue"))==null?void 0:v.defaultValue;if(typeof F<"u")return F}catch{}},h={id:i,source:"default",priority:m(),debounceMs:0,getEnabled:()=>typeof d()<"u"?!0:typeof p()<"u",getTarget:()=>this.getModelTargetNamePath(t)||r,getValue:()=>{const g=d();return typeof g<"u"?g:p()},getContext:()=>t==null?void 0:t.context};this.rules.set(i,{rule:h,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(i)}getModelTargetPath(t){var o;try{const n=(o=t==null?void 0:t.getStepParams)==null?void 0:o.call(t,"fieldSettings","init"),l=n==null?void 0:n.fieldPath;if(l)return String(l)}catch{}const r=t==null?void 0:t.fieldPath;if(r)return String(r);const i=this.getModelTargetNamePath(t);return i!=null&&i.length&&i.filter(n=>typeof n=="string").join(".")||null}getAssignRuleInstanceId(t,o){var r;const i=o!=null&&o.isFork?String((r=o==null?void 0:o.forkId)!=null?r:"fork"):"master",n=o!=null&&o.uid?String(o.uid):String(o);return`form-assign:${t}:${n}:${i}`}getDeepestFieldIndexKey(t){var o,r,i;const n=(i=(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.fieldIndex)!=null?i:t==null?void 0:t.fieldIndex,l=Array.isArray(n)?n:[];if(!l.length)return null;const a=l[l.length-1];if(typeof a!="string")return null;const[c,u]=a.split(":");if(!c)return null;const d=Number(u);return Number.isNaN(d)?null:c}getDeepestToManyAssociationKey(t){var o,r;const i=this.getRootCollection();if(!(i!=null&&i.getField))return null;const n=parsePathString(String(t||"")).filter(c=>typeof c!="object");if(n.length<2)return null;let l=i,a=null;for(let c=0;c<n.length-1;c++){const u=n[c];if(typeof u!="string")continue;const d=(o=l==null?void 0:l.getField)==null?void 0:o.call(l,u);if(!((r=d==null?void 0:d.isAssociationField)!=null&&r.call(d)))break;const m=isToManyAssociationField(d);if(m&&(a=u),m&&typeof n[c+1]=="number"&&(c+=1),l=d==null?void 0:d.targetCollection,!(l!=null&&l.getField))break}return a}isRowGridModel(t){var o,r;if(!t||typeof t!="object"||(o=t==null?void 0:t.subModels)!=null&&o.field||!((r=t==null?void 0:t.subModels)!=null&&r.items))return!1;const i=t==null?void 0:t.context;return!!this.getDeepestFieldIndexKey(i)}tryRegisterAssignRuleInstancesForModel(t,o){var r,i,n,l;if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const a=(g,f)=>{var _;if(!(!f||f.length===0)){o==null||o.add(g);for(const v of f){this.removeAssignRuleBlockInstance(v.__key),(_=t==null?void 0:t.subModels)!=null&&_.field&&this.removeRowGridAssignRuleInstances(v.__key);const b=((v==null?void 0:v.mode)==="default"?"default":"assign")=="default"?"default":"system",F=(v==null?void 0:v.enable)!==!1,y=this.getAssignRuleInstanceId(v.__key,t);this.rules.has(y)&&this.removeRule(y);const C={id:y,source:b,priority:10+(v.__order||0),debounceMs:0,getEnabled:()=>F&&!!g,getTarget:()=>g,getValue:()=>v==null?void 0:v.value,getCondition:()=>v==null?void 0:v.condition,getContext:()=>t==null?void 0:t.context};this.rules.set(y,{rule:C,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(y)}}};if(this.isRowGridModel(t)){const g=t==null?void 0:t.context,f=this.getDeepestFieldIndexKey(g);if(f)for(const[_,v]of this.assignTemplatesByTargetPath.entries()){if(this.formItemTargetPaths.has(_))continue;const b=this.getDeepestToManyAssociationKey(_);!b||b!==f||a(_,v)}return}if(!((r=t==null?void 0:t.subModels)!=null&&r.field))return;const c=this.getModelTargetPath(t);if(!c)return;const u=this.assignTemplatesByTargetPath.get(c)||[];u.length&&a(c,u);const d=(i=t==null?void 0:t.subModels)==null?void 0:i.field,m=(n=d==null?void 0:d.context)==null?void 0:n.collectionField,p=!!((l=m==null?void 0:m.isAssociationField)!=null&&l.call(m)),h=isToManyAssociationField(m);if(p&&!h){const g=`${c}.`;for(const[f,_]of this.assignTemplatesByTargetPath.entries())!f||typeof f!="string"||f.startsWith(g)&&a(f,_)}}tryUnregisterAssignRuleInstancesForModel(t){var o,r,i,n;if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const l=h=>{for(const g of h||[]){const f=this.getAssignRuleInstanceId(g.__key,t);this.rules.has(f)&&this.removeRule(f)}};if(this.isRowGridModel(t)){const h=t==null?void 0:t.context,g=this.getDeepestFieldIndexKey(h);if(!g)return;for(const[f,_]of this.assignTemplatesByTargetPath.entries()){if(this.formItemTargetPaths.has(f))continue;const v=this.getDeepestToManyAssociationKey(f);!v||v!==g||l(_)}return}if(!((o=t==null?void 0:t.subModels)!=null&&o.field))return;const a=this.getModelTargetPath(t);if(!a)return;const c=this.assignTemplatesByTargetPath.get(a)||[];c.length&&l(c);const u=(r=t==null?void 0:t.subModels)==null?void 0:r.field,d=(i=u==null?void 0:u.context)==null?void 0:i.collectionField,m=!!((n=d==null?void 0:d.isAssociationField)!=null&&n.call(d)),p=isToManyAssociationField(d);if(m&&!p){const h=`${a}.`;for(const[g,f]of this.assignTemplatesByTargetPath.entries())!g||typeof g!="string"||g.startsWith(h)&&l(f)}}tryUnregisterDefaultRuleInstance(t){if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const o=this.getDefaultRuleId(t);this.rules.has(o)&&this.removeRule(o)}bindMasterInitialValue(t,o){const r=t!=null&&t.uid?String(t.uid):o,i=this.defaultRuleIdsByMasterUid.get(r)||new Set;if(i.add(o),this.defaultRuleIdsByMasterUid.set(r,i),this.defaultRuleMasterDisposers.has(r))return;const n=(0,import_reactive.reaction)(()=>{var l,a;const c=(a=(l=t==null?void 0:t.getProps)==null?void 0:l.call(t))!=null?a:t==null?void 0:t.props;return c==null?void 0:c.initialValue},(l,a)=>{var c,u;if(import_lodash.default.isEqual(l,a))return;const d=this.defaultRuleIdsByMasterUid.get(r);if(!d)return;const m=(u=(c=t==null?void 0:t.getProps)==null?void 0:c.call(t))!=null?u:t==null?void 0:t.props,p=typeof(m==null?void 0:m.initialValue)<"u"?LINKAGE_DEFAULT_RULE_PRIORITY:0;for(const h of d){const g=this.rules.get(h);g&&(g.rule.priority=p),this.scheduleRule(h)}});this.defaultRuleMasterDisposers.set(r,n)}removeRule(t){const o=this.rules.get(t);if(!o)return;try{const i=o.rule.getContext(),n=o.rule.getTarget(),l=this.options.tryResolveNamePath(i,n);if(l){const a=namePathToPathKey(l),c=this.options.observableBindings.get(a);c&&c.source===o.rule.source&&(c.dispose(),this.options.observableBindings.delete(a))}}catch{}o.state.depDisposers.forEach(i=>i()),this.rules.delete(t),this.pendingRuleIds.delete(t);const r=this.ruleDebounceTimersById.get(t);r&&clearTimeout(r),this.ruleDebounceTimersById.delete(t),this.ruleDebounceUntilById.delete(t);for(const[i,n]of this.defaultRuleIdsByMasterUid.entries()){if(!n.has(t)||(n.delete(t),n.size>0))continue;this.defaultRuleIdsByMasterUid.delete(i);const l=this.defaultRuleMasterDisposers.get(i);l&&l(),this.defaultRuleMasterDisposers.delete(i)}}scheduleRule(t){var o;if(this.options.isDisposed())return;const r=this.rules.get(t);if(!r)return;const{rule:i,state:n}=r;n.scheduledAtWriteSeq=this.options.getWriteSeq();const l=(o=i==null?void 0:i.debounceMs)!=null?o:0;if(this.pendingRuleIds.add(t),l>0){const a=Date.now()+l,c=this.ruleDebounceUntilById.get(t)||0;a>c&&this.ruleDebounceUntilById.set(t,a);const u=this.ruleDebounceTimersById.get(t);u&&clearTimeout(u);const d=setTimeout(()=>{this.ruleDebounceTimersById.delete(t),this.rulesEnabled&&(this.runningRules||this.pendingRuleIds.has(t)&&this.flushRules())},l);this.ruleDebounceTimersById.set(t,d)}else{const a=this.ruleDebounceTimersById.get(t);a&&clearTimeout(a),this.ruleDebounceTimersById.delete(t),this.ruleDebounceUntilById.delete(t)}this.rulesEnabled&&(this.runningRules||this.flushRules())}flushRules(){return L(this,null,function*(){if(this.runningRules)return;this.runningRules=!0;const t=this.currentRuleTxId||createTxId();this.currentRuleTxId=t;try{for(;this.pendingRuleIds.size;){const o=Date.now(),r=[];for(const i of this.pendingRuleIds)(this.ruleDebounceUntilById.get(i)||0)>o||r.push(i);if(!r.length)break;for(const i of r)this.pendingRuleIds.delete(i),this.ruleDebounceUntilById.delete(i);r.sort((i,n)=>{var l,a,c,u;const d=(l=this.rules.get(i))==null?void 0:l.rule,m=(a=this.rules.get(n))==null?void 0:a.rule,p=(c=d==null?void 0:d.priority)!=null?c:0,h=(u=m==null?void 0:m.priority)!=null?u:0;return p!==h?p-h:i.localeCompare(n)});for(const i of r)yield this.runRule(i)}}finally{this.runningRules=!1,this.currentRuleTxId=null,this.options.txWriteCounts.delete(t)}})}runRule(t){return L(this,null,function*(){var o,r;const i=this.rules.get(t);if(!i)return;const{rule:n,state:l}=i;l.runSeq+=1;const a=l.runSeq,c=l.scheduledAtWriteSeq,u=this.prepareRuleContext(n),{baseCtx:d,targetNamePath:m,targetKey:p,clearDeps:h,disposeBinding:g}=u;if(!this.shouldRunRule(n,m,p,d)){h(l),g();return}if(!m||!p){h(l),g();return}const f=m,_=p,{collector:v,evalCtx:b}=this.createRuleCollectorAndContext(n,u);if(n.getCondition&&!(yield this.evaluateRuleCondition(n,l,a,b,v)))return;const F=yield this.resolveRuleValue(n,l,a,b,v);if(F===SKIP_RULE_VALUE||a!==l.runSeq)return;this.commitRuleDeps(n,l,v);const y=this.normalizeResolvedValueForTarget(d,F),C=this.normalizeResolvedValueForAssociationTarget(d,f,y);if(n.source==="default"&&!this.checkDefaultRuleCanApply(C,f,_,h,g,l))return;if(n.source==="default"){const N=this.lastRuleWriteByTargetKey.get(_);if((N==null?void 0:N.source)==="default"&&N.priority>n.priority&&N.writeSeq>=c){g();return}}if(n.source==="system"){const N=this.options.lastWriteMetaByPathKey.get(_);if((N==null?void 0:N.source)==="linkage"&&N.writeSeq>=c){g();return}}if(this.shouldSkipAssociationNestedWrite(d,f)||this.shouldSkipToManyAssociationWriteWithoutIndex(d,f))return;const S=C;if(this.isAssociationTargetSemanticallyEqual(d,f,this.options.getFormValueAtPath(f),S))return;const P=this.collectUpdateAssociationInitPatches(d,f);if(P==null)return;if(n.source==="system"||n.source==="default"){const N=d==null?void 0:d.model,D=(o=N==null?void 0:N.subModels)==null?void 0:o.field;if(D){const w=this.getModelTargetNamePath(N);w&&namePathToPathKey(w)===_&&(N.setProps({value:C}),(r=D.setProps)==null||r.call(D,{value:C}))}}const j=this.options.getWriteSeq(),A=[...P,{path:f,value:C}];yield this.options.setFormValues(b,A,{source:n.source,txId:this.currentRuleTxId||void 0});const T=this.options.getWriteSeq();T!==j&&this.lastRuleWriteByTargetKey.set(_,{source:n.source,priority:n.priority,writeSeq:T})})}isTzAwareTargetInterface(t){return typeof t!="string"?!1:["datetime","createdAt","updatedAt","unixTimestamp"].includes(t)}normalizeDateOnlyToStartOfDayIso(t){const o=String(t||"").trim();if(!o||!/^\d{4}-\d{2}-\d{2}$/.test(o))return t;const r=(0,import_client.dayjs)(o,"YYYY-MM-DD",!0);return r.isValid()?r.startOf("day").toISOString():t}normalizeResolvedValueForTarget(t,o){var r,i,n;const l=(n=(i=(r=t==null?void 0:t.model)==null?void 0:r.context)==null?void 0:i.collectionField)==null?void 0:n.interface;return this.isTzAwareTargetInterface(l)?typeof o=="string"?this.normalizeDateOnlyToStartOfDayIso(o):Array.isArray(o)?o.map(a=>typeof a=="string"?this.normalizeDateOnlyToStartOfDayIso(a):a):o:o}isPrimitiveAssociationTargetValue(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}extractAssociationIdentity(t,o){const r=this.getAssociationTargetKeyFields(t),i=r.length===1?r[0]:null,n=a=>{if(a==null)return a;if(this.isPrimitiveAssociationTargetValue(a))return i?a:UNRESOLVED_ASSOCIATION_IDENTITY;if(!a||typeof a!="object")return UNRESOLVED_ASSOCIATION_IDENTITY;if(i)return typeof a[i]>"u"?UNRESOLVED_ASSOCIATION_IDENTITY:a[i];const c={};for(const u of r){if(typeof a[u]>"u")return UNRESOLVED_ASSOCIATION_IDENTITY;c[u]=a[u]}return c};if(isToManyAssociationField(t)){const a=Array.isArray(o)?o:[o],c=[];for(const u of a){if(u==null)continue;const d=n(u);if(d===UNRESOLVED_ASSOCIATION_IDENTITY)return UNRESOLVED_ASSOCIATION_IDENTITY;c.push(d)}return c}const l=Array.isArray(o)?o.find(a=>a!=null):o;return l==null?l:n(l)}isAssociationTargetSemanticallyEqual(t,o,r,i){var n;const l=this.resolveCollectionFieldByNamePath(t,o);if(!((n=l==null?void 0:l.isAssociationField)!=null&&n.call(l)))return import_lodash.default.isEqual(r,i);const a=this.extractAssociationIdentity(l,r),c=this.extractAssociationIdentity(l,i);return a===UNRESOLVED_ASSOCIATION_IDENTITY||c===UNRESOLVED_ASSOCIATION_IDENTITY?import_lodash.default.isEqual(r,i):import_lodash.default.isEqual(a,c)}resolveCollectionFieldByNamePath(t,o){var r,i;if(!Array.isArray(o)||!o.length)return null;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return null;for(let l=0;l<o.length;l++){const a=o[l];if(typeof a!="string"||!a)return null;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!c)return null;if(l===o.length-1)return c;if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c))||!(c!=null&&c.targetCollection))return null;if(isToManyAssociationField(c)){if(typeof o[l+1]!="number")return null;l+=1}if(n=c.targetCollection,!(n!=null&&n.getField))return null}return null}normalizeResolvedValueForAssociationTarget(t,o,r){var i;const n=this.resolveCollectionFieldByNamePath(t,o);if(!((i=n==null?void 0:n.isAssociationField)!=null&&i.call(n)))return r;const l=this.getAssociationTargetKeyFields(n),a=l.length===1?l[0]:null,c=d=>{if(d!=null)return a&&this.isPrimitiveAssociationTargetValue(d)?{[a]:d}:d};if(isToManyAssociationField(n))return(Array.isArray(r)?r:[r]).map(d=>c(d)).filter(d=>typeof d<"u"&&d!==null);const u=Array.isArray(r)?r.find(d=>d!=null):r;return u==null?u:c(u)}prepareRuleContext(t){const o=t.getContext(),r=t.getTarget(),i=this.options.tryResolveNamePath(o,r),n=i?namePathToPathKey(i):null;return{baseCtx:o,targetNamePath:i,targetKey:n,clearDeps:l=>{l.depDisposers.forEach(a=>a()),l.depDisposers=[],l.deps=new Set},disposeBinding:()=>{if(!n)return;const l=this.options.observableBindings.get(n);l&&l.source===t.source&&(l.dispose(),this.options.observableBindings.delete(n))}}}shouldApplyDefaultRuleInCurrentState(t){var o,r;if(((r=(o=this.options).getActionName)==null?void 0:r.call(o))!=="update")return!0;let i;try{i=t==null?void 0:t.item}catch{i=void 0}return!i||typeof i!="object"?!1:i.__is_new__===!0}shouldRunRule(t,o,r,i){return!(!t.getEnabled()||!o||!r||t.source==="default"&&(!this.shouldApplyDefaultRuleInCurrentState(i)||this.options.findExplicitHit(r)))}createRuleCollectorAndContext(t,o){const{baseCtx:r,targetNamePath:i}=o,n=t.getValue(),l=(0,import_flow_engine.isRunJSValue)(n),a={deps:new Set,wildcard:!1};if(t.getCondition&&collectStaticDepsFromTemplateValue(t.getCondition(),a),l?collectStaticDepsFromRunJSValue(n,a):collectStaticDepsFromTemplateValue(n,a),i){recordDep(i,a);for(const u of this.collectAssociationPrefixPaths(r,i))recordDep(u,a)}const c=this.createRuleEvaluationContext(r,a,i);return{collector:a,evalCtx:c,rawValue:n,isRunJS:l}}evaluateRuleCondition(t,o,r,i,n){return L(this,null,function*(){var l;const a=t.getCondition;if(!a)return!0;const c=a();let u=c;if(c)try{u=yield(l=i==null?void 0:i.resolveJsonTemplate)==null?void 0:l.call(i,c)}catch{u=c}return r!==o.runSeq?!1:c&&!evaluateCondition(i,u)?(this.commitRuleDeps(t,o,n),!1):!0})}resolveRuleValue(t,o,r,i,n){return L(this,null,function*(){const l=t.getValue();return(0,import_flow_engine.isRunJSValue)(l)?this.resolveRunJSValue(l,o,r,i,n,t):this.resolveTemplateValue(l,o,r,i,n,t)})}resolveRunJSValue(t,o,r,i,n,l){return L(this,null,function*(){try{const{code:a,version:c}=(0,import_flow_engine.normalizeRunJSValue)(t),u=yield(0,import_flow_engine.runjsWithSafeGlobals)(i,a,{version:c});return u!=null&&u.success?u.value:(r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE)}catch{return r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE}})}resolveTemplateValue(t,o,r,i,n,l){return L(this,null,function*(){var a;try{return yield(a=i==null?void 0:i.resolveJsonTemplate)==null?void 0:a.call(i,t)}catch{return r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE}})}commitRuleDeps(t,o,r){const i=new Set(r.deps);r.wildcard&&i.add("fv:*"),this.updateRuleDeps(t,o,i)}checkDefaultRuleCanApply(t,o,r,i,n,l){if(typeof t>"u")return!1;if(this.options.findExplicitHit(r))return i(l),n(),!1;const a=this.options.getFormValueAtPath(o),c=this.options.lastDefaultValueByPathKey.get(r),u=isEmptyValue(a)||typeof c<"u"&&import_lodash.default.isEqual(a,c),d=(0,import_reactive.isObservable)(t)?(0,import_reactive.toJS)(t):t;return!u&&import_lodash.default.isEqual(a,d)?(this.options.lastDefaultValueByPathKey.set(r,d),!1):u}createRuleEvaluationContext(t,o,r){var i;const n=this.options.createTrackingFormValues(o),l=new import_flow_engine.FlowContext;try{l.delegate(t)}catch{}const a=(i=t==null?void 0:t.getPropertyOptions)==null?void 0:i.call(t,"formValues");a&&typeof a=="object"?l.defineProperty("formValues",I(x({},a),{get:()=>n,cache:!1})):l.defineProperty("formValues",{get:()=>n,cache:!1});let c,u=!1;const d=()=>{if(!u){const m=this.buildItemChainValue(t,n,r);c=m??(t==null?void 0:t.item),u=!0}return c};return l.defineProperty("item",{get:d,cache:!1}),l}buildItemChainValue(t,o,r){var i,n;const l=this.getRootCollection()||this.getCollectionFromContext(t),a=(h,g,f,_)=>({index:g,length:f,__is_new__:h==null?void 0:h.__is_new__,__is_stored__:h==null?void 0:h.__is_stored__,value:h,parentItem:_}),c=a(o,void 0,void 0,void 0);if(!r||!Array.isArray(r)||!r.length||!(l!=null&&l.getField))return;const u=[],d=[];let m=l;for(let h=0;h<r.length-1;h++){const g=r[h];if(typeof g!="string")break;const f=(i=m==null?void 0:m.getField)==null?void 0:i.call(m,g);if(!((n=f==null?void 0:f.isAssociationField)!=null&&n.call(f)))break;const _=isToManyAssociationField(f);if(d.push(g),_){const b=r[h+1];if(typeof b!="number")break;d.push(b),h+=1}const v=f==null?void 0:f.targetCollection;if(!v)break;u.push({path:[...d],toMany:_}),m=v}const p=h=>{if(h<0)return c;const g=u[h],f=import_lodash.default.get(o,g.path),_=g.path[g.path.length-1],v=g.toMany&&typeof _=="number"?_:void 0,b=(()=>{if(!g.toMany)return;const F=g.path.slice(0,-1),y=import_lodash.default.get(o,F);return Array.isArray(y)?y.length:void 0})();return a(f,v,b,p(h-1))};return u.length?p(u.length-1):void 0}getFieldIndexSignature(t){var o,r,i;const n=(i=(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.fieldIndex)!=null?i:t==null?void 0:t.fieldIndex;return(Array.isArray(n)?n:[]).filter(l=>typeof l=="string").join("|")}updateRuleDeps(t,o,r){if(o.depDisposers.forEach(n=>n()),o.depDisposers=[],o.deps=r,r.has("fv:*")){const n=(0,import_reactive.reaction)(()=>this.options.changeTick.value,()=>this.scheduleRule(t.id));o.depDisposers.push(n)}const i=(()=>{try{return t.getContext()}catch{return}})();for(const n of r){if(n==="fv:*")continue;if(!n.startsWith("fv:")&&!n.startsWith("ctx:")){const p=pathKeyToNamePath(n),h=(0,import_reactive.reaction)(()=>import_lodash.default.get(this.options.valuesMirror,p),()=>this.scheduleRule(t.id));o.depDisposers.push(h);continue}if(n.startsWith("fv:")){const p=n.slice(3),h=pathKeyToNamePath(p),g=(0,import_reactive.reaction)(()=>import_lodash.default.get(this.options.valuesMirror,h),()=>this.scheduleRule(t.id));o.depDisposers.push(g);continue}const l=n.slice(4),a=l.indexOf(":"),c=a>=0?l.slice(0,a):l,u=a>=0?l.slice(a+1):"",d=u?parsePathString(u).filter(p=>typeof p!="object"):[];if(c==="item"){const p=(0,import_reactive.reaction)(()=>this.getFieldIndexSignature(i),()=>this.scheduleRule(t.id));if(o.depDisposers.push(p),d.length){const h=this.options.createTrackingFormValues({deps:new Set,wildcard:!1}),g=(0,import_reactive.reaction)(()=>{var f,_;const v=(f=t.getTarget)==null?void 0:f.call(t),b=v?this.options.tryResolveNamePath(i,v):null,F=(_=this.buildItemChainValue(i,h,b))!=null?_:i==null?void 0:i.item;return import_lodash.default.get(F,d)},()=>this.scheduleRule(t.id));o.depDisposers.push(g)}continue}const m=(0,import_reactive.reaction)(()=>{const p=i?i[c]:void 0;return d.length?import_lodash.default.get(p,d):p},()=>this.scheduleRule(t.id));o.depDisposers.push(m)}}}class FormValueRuntime{constructor(t){R(this,"model"),R(this,"getForm"),R(this,"valuesMirror",(0,import_reactive.observable)({})),R(this,"explicitSet",new Set),R(this,"lastDefaultValueByPathKey",new Map),R(this,"lastWriteMetaByPathKey",new Map),R(this,"observableBindings",new Map),R(this,"changeTick",import_reactive.observable.ref(0)),R(this,"txWriteCounts",new Map),R(this,"writeSeq",0),R(this,"disposed",!1),R(this,"suppressFormCallbackDepth",0),R(this,"lastObservedChangedPaths",null),R(this,"lastObservedSource",null),R(this,"lastObservedToken",0),R(this,"formValuesProxy"),R(this,"mountedListener"),R(this,"unmountedListener"),R(this,"formPatcher"),R(this,"ruleEngine"),this.model=t.model,this.getForm=t.getForm,this.formPatcher=createFormPatcher({isSuppressed:()=>this.isSuppressed(),getCallerContext:()=>{var o;return(o=this.model)==null?void 0:o.context},setFormValues:this.setFormValues.bind(this)}),this.ruleEngine=new RuleEngine({getBlockModelUid:()=>{var o;return String((o=this.model)==null?void 0:o.uid)},getActionName:()=>{var o,r,i,n,l;return(l=(r=(o=this.model)==null?void 0:o.getAclActionName)==null?void 0:r.call(o))!=null?l:(n=(i=this.model)==null?void 0:i.context)==null?void 0:n.actionName},getBlockContext:()=>{var o;return(o=this.model)==null?void 0:o.context},getEngine:()=>{var o,r;return(r=(o=this.model)==null?void 0:o.context)==null?void 0:r.engine},getEngineModel:o=>{var r,i,n,l,a;return(a=(l=(n=(i=(r=this.model)==null?void 0:r.context)==null?void 0:i.engine)==null?void 0:n.getModel)==null?void 0:l.call(n,o))!=null?a:null},isDisposed:()=>this.disposed,valuesMirror:this.valuesMirror,changeTick:this.changeTick,getWriteSeq:()=>this.writeSeq,txWriteCounts:this.txWriteCounts,createTrackingFormValues:o=>createFormValuesProxy({valuesMirror:this.valuesMirror,basePath:[],collector:o,getFormValuesSnapshot:()=>this.getFormValuesSnapshot(),getFormValueAtPath:r=>this.getFormValueAtPath(r)}),tryResolveNamePath:(o,r)=>this.tryResolveNamePath(o,r),getFormValueAtPath:o=>this.getFormValueAtPath(o),setFormValues:(o,r,i)=>this.setFormValues(o,r,i),findExplicitHit:o=>this.findExplicitHit(o),lastDefaultValueByPathKey:this.lastDefaultValueByPathKey,lastWriteMetaByPathKey:this.lastWriteMetaByPathKey,observableBindings:this.observableBindings}),this.formValuesProxy=createFormValuesProxy({valuesMirror:this.valuesMirror,basePath:[],getFormValuesSnapshot:()=>this.getFormValuesSnapshot(),getFormValueAtPath:o=>this.getFormValueAtPath(o)})}syncAssignRules(t){this.ruleEngine.syncAssignRules(t)}get formValues(){return this.disposed||this.formPatcher.patch(this.getForm()),this.formValuesProxy}getFormValuesSnapshot(){if(!this.disposed){const t=this.getForm();this.formPatcher.patch(t)}return this.getForm().getFieldsValue(!0)}getFormValueAtPath(t){var o;const r=(o=this.getForm)==null?void 0:o.call(this);if(r&&typeof r.getFieldValue=="function")return r.getFieldValue(t);if(r&&typeof r.getFieldsValue=="function"){const i=r.getFieldsValue(!0);return import_lodash.default.get(i,t)}}mount(t){var o,r;if(this.disposed)return;this.formPatcher.patch(this.getForm());const i=(r=(o=this.model)==null?void 0:o.flowEngine)==null?void 0:r.emitter;if(i&&(!this.mountedListener&&!this.unmountedListener&&(this.mountedListener=({model:n})=>{this.ruleEngine.onModelMounted(n)},this.unmountedListener=({model:n})=>{this.ruleEngine.onModelUnmounted(n)},i.on("model:mounted",this.mountedListener),i.on("model:unmounted",this.unmountedListener)),t!=null&&t.sync)){const n=this.getFormValuesSnapshot();n&&typeof n=="object"&&(import_lodash.default.merge(this.valuesMirror,n),this.bumpChangeTick()),this.ruleEngine.enable()}}dispose(){var t,o;if(this.disposed)return;this.disposed=!0,this.formPatcher.restore();const r=(o=(t=this.model)==null?void 0:t.flowEngine)==null?void 0:o.emitter;r&&this.mountedListener&&this.unmountedListener&&(r.off("model:mounted",this.mountedListener),r.off("model:unmounted",this.unmountedListener)),this.ruleEngine.dispose();for(const i of this.observableBindings.values())i.dispose();this.observableBindings.clear(),this.txWriteCounts.clear()}isSuppressed(){return this.suppressFormCallbackDepth>0}handleFormFieldsChange(t){if(this.disposed)return;const o=this.getForm();if(!o.getFieldValue)return;const r=[],i=new Set;let n=!1;for(const d of t||[]){const m=d==null?void 0:d.name,p=Array.isArray(m)?m:typeof m=="string"||typeof m=="number"?[m]:null;if(!(p!=null&&p.length))continue;const h=o.getFieldValue(p),g=import_lodash.default.get(this.valuesMirror,p);import_lodash.default.isEqual(h,g)||(n||(this.writeSeq+=1,n=!0),import_lodash.default.set(this.valuesMirror,p,h),r.push(p),(d==null?void 0:d.touched)===!0&&i.add(namePathToPathKey(p)))}if(!r.length)return;const l=this.isSuppressed();if(!l&&i.size)for(const d of i)this.markExplicit(d);if(this.bumpChangeTick(),l)return;const a=t.some(d=>(d==null?void 0:d.touched)===!0)?"user":"system",c=this.writeSeq;for(const d of r)this.lastWriteMetaByPathKey.set(namePathToPathKey(d),{source:a,writeSeq:c});this.lastObservedChangedPaths=r,this.lastObservedSource=a;const u=++this.lastObservedToken;queueMicrotask(()=>{this.disposed||this.lastObservedToken===u&&(this.lastObservedChangedPaths=null,this.lastObservedSource=null)})}handleFormValuesChange(t,o){var r;if(this.disposed||this.isSuppressed())return;const i=this.lastObservedChangedPaths&&this.lastObservedChangedPaths.length?this.lastObservedChangedPaths:Object.keys(t||{}).map(p=>[p]),n=(r=this.lastObservedSource)!=null?r:"user";this.lastObservedChangedPaths=null,this.lastObservedSource=null;const l=o&&typeof o=="object"?o:this.getFormValuesSnapshot(),a=this.deriveExplicitPaths(i,l,this.valuesMirror);let c=!1,u=!1;const d=[];for(const p of i){if(!(p!=null&&p.length))continue;const h=import_lodash.default.get(l,p),g=import_lodash.default.get(this.valuesMirror,p);import_lodash.default.isEqual(g,h)||(u||(this.writeSeq+=1,u=!0),import_lodash.default.set(this.valuesMirror,p,h),c=!0,d.push(p))}c&&this.bumpChangeTick();for(const p of a)this.markExplicit(namePathToPathKey(p));if(c){const p=this.writeSeq;for(const h of d)h!=null&&h.length&&this.lastWriteMetaByPathKey.set(namePathToPathKey(h),{source:n,writeSeq:p})}const m=createTxId();this.emitFormValuesChange({source:n,txId:m,changedPaths:i,changedValues:t,allValues:l,allValuesSnapshot:l})}deriveExplicitPaths(t,o,r){const i=[],n=new Set;for(const l of t||[]){if(!(l!=null&&l.length))continue;const a=import_lodash.default.get(r,l),c=import_lodash.default.get(o,l);this.collectExplicitDiffPaths(a,c,l,i,n)}return i}collectExplicitDiffPaths(t,o,r,i,n){if(import_lodash.default.isEqual(t,o))return 0;const l=Array.isArray(t),a=Array.isArray(o);if(l||a){if(l&&a){const d=Math.min(t.length,o.length);let m=0;for(let p=0;p<d;p++)m+=this.collectExplicitDiffPaths(t[p],o[p],[...r,p],i,n);return m}return this.pushExplicitPath(r,i,n)?1:0}const c=this.isPlainObjectValue(t),u=this.isPlainObjectValue(o);if(c||u){if(c&&u){const d=new Set([...Object.keys(t),...Object.keys(o)]);let m=0;for(const p of d)m+=this.collectExplicitDiffPaths(t[p],o[p],[...r,p],i,n);return m===0&&this.isObjectCleared(t,o)?this.pushExplicitPath(r,i,n)?1:0:m}return this.isObjectCleared(t,o)?this.pushExplicitPath(r,i,n)?1:0:this.pushExplicitPath(r,i,n)?1:0}return this.pushExplicitPath(r,i,n)?1:0}pushExplicitPath(t,o,r){if(!(t!=null&&t.length))return!1;const i=namePathToPathKey(t);return!i||r.has(i)?!1:(r.add(i),o.push([...t]),!0)}isPlainObjectValue(t){return import_lodash.default.isPlainObject(t)}isObjectCleared(t,o){return this.isPlainObjectValue(t)?!!(o==null||this.isPlainObjectValue(o)&&Object.keys(o).length===0):!1}setFormValues(t,o,r){return L(this,null,function*(){var i,n,l,a,c,u;if(this.disposed)return;const d=(i=this.getForm)==null?void 0:i.call(this);if(!d)return;const m=(n=r==null?void 0:r.source)!=null?n:"system",p=(r==null?void 0:r.triggerEvent)!==!1,h=(l=r==null?void 0:r.txId)!=null?l:createTxId(),g=(a=r==null?void 0:r.markExplicit)!=null?a:m!=="default",f=typeof(r==null?void 0:r.txId)>"u",_=m==="linkage"&&Number.isFinite(Number(r==null?void 0:r.linkageScopeDepth))?Number(r==null?void 0:r.linkageScopeDepth):0,v=m==="linkage"&&typeof(r==null?void 0:r.linkageTxId)=="string"&&r.linkageTxId?String(r.linkageTxId):void 0,b=C=>{if(m!=="linkage"||!v)return!1;const S=this.lastWriteMetaByPathKey.get(C);return!S||S.source!=="linkage"||!S.linkageTxId||S.linkageTxId!==v?!1:(Number.isFinite(Number(S.linkageScopeDepth))?Number(S.linkageScopeDepth):0)>_},F=C=>m==="linkage"?{source:m,writeSeq:C,linkageScopeDepth:_,linkageTxId:v}:{source:m,writeSeq:C},y=C=>m==="linkage"&&v?I(x({},C),{linkageTxId:v}):C;try{const C=[];if(!Array.isArray(o)){const D=Object.entries(o||{}).filter(([E])=>!b(E)),w=Object.fromEntries(D),k=D.map(([E])=>E);if(!k.length)return;k.length&&(this.writeSeq+=1),this.suppressFormCallbackDepth++;try{(c=d.setFieldsValue)==null||c.call(d,w),import_lodash.default.merge(this.valuesMirror,w),this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}const B=this.writeSeq;for(const E of k)this.lastWriteMetaByPathKey.set(E,F(B));if(g)for(const E of k)this.markExplicit(E);if(p){const E=this.getFormValuesSnapshot();this.emitFormValuesChange(y({source:m,txId:h,changedPaths:k.map(M=>[M]),changedValues:w,allValues:E,allValuesSnapshot:E}))}return}const S=new Map;let P=0;for(const D of o){const w=D==null?void 0:D.condition;if(w&&!evaluateCondition(t,w))continue;const k=this.resolveNamePath(t,D.path),B=namePathToPathKey(k),E=D.value,M=(0,import_reactive.isObservable)(E)?(0,import_reactive.toJS)(E):E;if(b(B))continue;const O=this.getFormValueAtPath(k);import_lodash.default.isEqual(O,M)||(P+=1,S.set(B,{order:P,namePath:k,value:M,rawValue:E,pathKey:B}))}const j=Array.from(S.values()).sort((D,w)=>D.order-w.order).map(D=>({namePath:D.namePath,value:D.value,rawValue:D.rawValue,pathKey:D.pathKey}));if(!j.length)return;const A=this.txWriteCounts.get(h)||new Map;this.txWriteCounts.set(h,A);const T=[];for(const D of j){const w=(A.get(D.pathKey)||0)+1;A.set(D.pathKey,w),!(w>MAX_WRITES_PER_PATH_PER_TX)&&T.push(D)}if(!T.length)return;this.writeSeq+=1;const N=this.writeSeq;for(const{pathKey:D,rawValue:w}of T)if(!(0,import_reactive.isObservable)(w)){const k=this.observableBindings.get(D);k&&(k.dispose(),this.observableBindings.delete(D))}this.suppressFormCallbackDepth++;try{for(const{namePath:D,value:w}of T)(u=d.setFieldValue)==null||u.call(d,D,w),import_lodash.default.set(this.valuesMirror,D,w),C.push(D);this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}for(const{pathKey:D}of T)this.lastWriteMetaByPathKey.set(D,F(N));if(g)for(const{pathKey:D}of T)this.markExplicit(D);if(m==="default")for(const{namePath:D,pathKey:w}of T){const k=this.getFormValueAtPath(D);this.lastDefaultValueByPathKey.set(w,k)}for(const{namePath:D,rawValue:w,pathKey:k}of T){if(!(0,import_reactive.isObservable)(w))continue;const B=w,E=(0,import_reactive.observe)(B,()=>{this.applyBoundValue(t,D,k,(0,import_reactive.toJS)(B),m,_,v)}),M=this.observableBindings.get(k);M&&M.dispose(),this.observableBindings.set(k,{source:m,dispose:E})}if(p){const D=this.getFormValuesSnapshot();this.emitFormValuesChange(y({source:m,txId:h,changedPaths:C,changedValues:{},allValues:D,allValuesSnapshot:D}))}}finally{f&&this.txWriteCounts.delete(h)}})}applyBoundValue(t,o,r,i,n,l,a){var c,u;if(this.disposed)return;const d=(c=this.getForm)==null?void 0:c.call(this);if(!d)return;const m=import_lodash.default.get(this.valuesMirror,o);if(import_lodash.default.isEqual(m,i))return;this.writeSeq+=1;const p=this.writeSeq;this.suppressFormCallbackDepth++;try{(u=d.setFieldValue)==null||u.call(d,o,i),import_lodash.default.set(this.valuesMirror,o,i),this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}const h=n==="linkage"?{source:n,writeSeq:p,linkageScopeDepth:Number.isFinite(Number(l))?Number(l):0,linkageTxId:typeof a=="string"&&a?a:void 0}:{source:n,writeSeq:p};this.lastWriteMetaByPathKey.set(r,h);const g=createTxId(),f=this.getFormValuesSnapshot(),_={source:n,txId:g,changedPaths:[o],changedValues:{},allValues:f,allValuesSnapshot:f};if(n==="linkage"&&a&&(_.linkageTxId=a),this.emitFormValuesChange(_),n==="default"&&this.isExplicit(r)){const v=this.observableBindings.get(r);v&&(v.dispose(),this.observableBindings.delete(r))}n==="default"&&this.lastDefaultValueByPathKey.set(r,this.getFormValueAtPath(o))}resolveNamePath(t,o){const r=this.tryResolveNamePath(t,o);if(!r)throw new Error(`Failed to resolve path '${String(o)}'`);return r}tryResolveNamePath(t,o){var r,i,n;const l=(n=(i=(r=t==null?void 0:t.model)==null?void 0:r.context)==null?void 0:i.fieldIndex)!=null?n:t==null?void 0:t.fieldIndex;return resolveDynamicNamePath(o,l)}bumpChangeTick(){this.changeTick.value+=1}emitFormValuesChange(t){var o,r,i,n;(r=(o=this.model).dispatchEvent)==null||r.call(o,"formValuesChange",t,{debounce:!0}),(n=(i=this.model.emitter)==null?void 0:i.emit)==null||n.call(i,"formValuesChange",t)}markExplicit(t){if(!this.explicitSet.has(t)){this.explicitSet.add(t);for(const o of Array.from(this.lastDefaultValueByPathKey.keys()))(o===t||o.startsWith(`${t}.`)||o.startsWith(`${t}[`))&&this.lastDefaultValueByPathKey.delete(o);for(const[o,r]of Array.from(this.observableBindings.entries()))r.source==="default"&&this.isExplicit(o)&&(r.dispose(),this.observableBindings.delete(o))}}isExplicit(t){return!!this.findExplicitHit(t)}findExplicitHit(t){if(this.explicitSet.has(t))return t;const o=pathKeyToNamePath(t),r=[];for(let i=0;i<o.length;i++){r.push(o[i]);const n=namePathToPathKey(r);if(!(!this.explicitSet.has(n)||typeof o[i+1]=="number"))return n}return null}}function collectUpdateAssociationValuesFromAssignRules(e,t){const o=Array.isArray(e)?e:[],r=new Set,i=n=>{var l,a,c,u,d;if(!t||typeof t.getField!="function"||typeof n!="string"||!n.includes("."))return null;const m=n.split(".").filter(Boolean);if(m.length<2)return null;let p=t;const h=[];let g=null,f=null;for(let _=0;_<m.length-1;_++){const v=m[_],b=(l=p==null?void 0:p.getField)==null?void 0:l.call(p,v);if(!((a=b==null?void 0:b.isAssociationField)!=null&&a.call(b))||!(b!=null&&b.targetCollection))break;h.push(v),g=h.join("."),f=b,p=b.targetCollection}if(g&&f){const _=m[m.length-1],v=(d=(u=f==null?void 0:f.targetKey)!=null?u:(c=f==null?void 0:f.targetCollection)==null?void 0:c.filterTargetKey)!=null?d:"id",b=Array.isArray(v)?v.filter(F=>typeof F=="string"&&!!F):typeof v=="string"&&v?[v]:["id"];if(typeof _=="string"&&b.includes(_))return null}return g};for(const n of o){const l=n!=null&&n.targetPath?String(n.targetPath):"";if(!l)continue;const a=i(l);a&&r.add(a)}return Array.from(r)}function createEmptyCondition(){return{logic:"$and",items:[]}}function getPropsInitialValue(e){if(!e)return;const t=typeof e.getProps=="function"?e.getProps():e.props;if(t&&typeof t.initialValue<"u")return t.initialValue}function getStepParamsInitialValue(e,t){var o,r;if(e)return(r=(o=e.getStepParams)==null?void 0:o.call(e,t,"initialValue"))==null?void 0:r.defaultValue}function createLegacyValueExtractor(e){return t=>{if(!t)return;const o=getPropsInitialValue(t);if(typeof o<"u")return o;for(const r of e){const i=getStepParamsInitialValue(t,r);if(typeof i<"u")return i}}}function deleteStepParams(e,t,o){var r,i,n;if(!((r=e==null?void 0:e.stepParams)!=null&&r[t]))return;const l=e.stepParams[t];!l||typeof l!="object"||Object.prototype.hasOwnProperty.call(l,o)&&(delete l[o],import_lodash.default.isEmpty(l)&&delete e.stepParams[t],(n=(i=e.emitter)==null?void 0:i.emit)==null||n.call(i,"onStepParamsChanged"))}function createLegacyClearer(e){return t=>{var o;if(t){(o=t.setProps)==null||o.call(t,{initialValue:void 0}),t.props&&Object.prototype.hasOwnProperty.call(t.props,"initialValue")&&delete t.props.initialValue;for(const r of e)deleteStepParams(t,r,"initialValue")}}}function collectLegacyDefaultValueRules(e,t){var o,r,i,n,l;const a=(i=(r=(o=e==null?void 0:e.subModels)==null?void 0:o.grid)==null?void 0:r.subModels)==null?void 0:i.items,c=Array.isArray(a)?a:[],u=[];for(const d of c){const m=((l=(n=d==null?void 0:d.getStepParams)==null?void 0:n.call(d,"fieldSettings","init"))==null?void 0:l.fieldPath)||(d==null?void 0:d.fieldPath),p=m?String(m):"";if(!p)continue;const h=t(d);typeof h<"u"&&u.push({key:`legacy-default:${p}`,enable:!0,targetPath:p,mode:"default",condition:createEmptyCondition(),value:h})}return u}function mergeAssignRulesWithLegacyDefaults(e,t){var o,r;const i=Array.isArray(e)?e:[],n=Array.isArray(t)?t:[];if(!n.length)return i;const l=new Set;for(const u of i){if(!u||typeof u!="object")continue;const d=u.targetPath?String(u.targetPath):"";if(d){if(u.mode==="default"){l.add(d);continue}String((o=u.key)!=null?o:"").startsWith("legacy-default:")&&l.add(d)}}const a=new Set(i.map(u=>{var d;return String((d=u.key)!=null?d:"")})),c=[];for(const u of n){const d=u.targetPath?String(u.targetPath):"";if(!d||l.has(d))continue;const m=x({},u),p=String((r=m.key)!=null?r:"");p&&a.has(p)&&(m.key=`${p}:${d}`),c.push(m)}return c.length?[...i,...c]:i}function clearLegacyDefaultValues(e,t,o){var r,i,n;const l=(n=(i=(r=e==null?void 0:e.subModels)==null?void 0:r.grid)==null?void 0:i.subModels)==null?void 0:n.items,a=Array.isArray(l)?l:[],c=[];for(const u of a)typeof t(u)<"u"&&(o(u),c.push(u));return c}const FORM_FLOW_KEYS=["editItemSettings","formItemSettings"],getLegacyFieldInitialValue=createLegacyValueExtractor(FORM_FLOW_KEYS),clearLegacyFieldInitialValue=createLegacyClearer(FORM_FLOW_KEYS);function collectLegacyDefaultValueRulesFromFormModel(e){return collectLegacyDefaultValueRules(e,getLegacyFieldInitialValue)}function clearLegacyDefaultValuesFromFormModel(e){return clearLegacyDefaultValues(e,getLegacyFieldInitialValue,clearLegacyFieldInitialValue)}const GRID_DELEGATED_STEP_KEYS={formModelSettings:new Set(["layout","assignRules"]),eventSettings:new Set(["linkageRules"])},FLOW_KEEP_MOBILE_HORIZONTAL_CLASS="nb-flow-keep-mobile-horizontal",flowKeepMobileHorizontalClassName=import_css.css`
1828
+ `},properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Name")}}'}},value:{type:"string","x-decorator":"FormItem","x-component":TextAreaWithContextSelector,"x-component-props":{rows:1}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},"x-reactions":{dependencies:["mode"],fulfill:{state:{hidden:'{{$deps[0] === "html"}}'}}},properties:{add:{type:"void",title:'{{t("Add parameter")}}',"x-component":"ArrayItems.Addition"}}},openInNewWindow:{type:"boolean","x-content":t("Open in new window"),"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:["mode"],fulfill:{state:{hidden:'{{$deps[0] === "html"}}'}}}}}},handler(e,t){e.model.setProps({url:t.url,searchParams:t.searchParams,openInNewWindow:t.openInNewWindow})}}}});class ExpandCollapseActionModel extends ActionModel{constructor(){super(...arguments),R(this,"expandFlag"),R(this,"defaultProps",{type:"default",icon:"DownOutlined"})}setTitle(t){this.setProps({title:t})}setExpandFlag(t){this.expandFlag=t}getTitle(){return this.expandFlag?this.context.t("Collapse all"):this.context.t("Expand all")}getIcon(){return this.expandFlag?"NodeCollapseOutlined":"NodeExpandOutlined"}}R(ExpandCollapseActionModel,"scene",ActionSceneEnum.collection);function getIdsWithChildren(e,{idKey:t="id",childrenKey:o="children"}={}){const r=[];function i(n){if(Array.isArray(n))for(const l of n){const a=l[o];r.push(l[t]),Array.isArray(a)&&a.length>0&&i(a)}}return i(e),r}const allIncludesChildren=e=>getIdsWithChildren(e);ExpandCollapseActionModel.registerFlow({key:"expandCollapseSettingsInit",sort:200,steps:{init:{handler(e,t){e.blockModel.props.defaultExpandAllRows?e.model.setExpandFlag(!0):e.model.setExpandFlag(!1)}}}});ExpandCollapseActionModel.registerFlow({key:"expandCollapseSettings",on:"click",steps:{expandCollapse:{handler(e,t){return L(this,null,function*(){var o;if(!((o=e.blockModel)!=null&&o.resource))return;const r=e.blockModel.resource,{treeTable:i}=e.blockModel.props;if(i)if(e.model.expandFlag)e.blockModel.setProps({expandedRowKeys:[]}),e.model.setExpandFlag(!1);else{const n=allIncludesChildren(r.getData());e.blockModel.setProps({expandedRowKeys:n}),e.model.setExpandFlag(!0)}})}}}});ExpandCollapseActionModel.define({label:(0,import_flow_engine.escapeT)("Expand/Collapse"),hide(e){var t;return((t=e.collection)==null?void 0:t.template)!=="tree"||e.model.props.treeTable===!1}});class AddChildActionModel extends PopupActionModel{constructor(){super(...arguments),R(this,"defaultProps",{type:"link",title:(0,import_flow_engine.tExpr)("Add child"),icon:"PlusOutlined"})}getAclActionName(){return"create"}onInit(t){super.onInit(t),this.context.defineProperty("association",{get:()=>this.context.blockModel.dataSource.getAssociation(`${this.context.blockModel.collection.name}.children`)})}}R(AddChildActionModel,"capabilityActionName",null);AddChildActionModel.registerFlow({key:"addChildSettingsInit",steps:{addChildInit:{handler(e,t){return L(this,null,function*(){e.model.onClick=o=>{e.model.dispatchEvent("click",I(x({event:o},e.inputArgs),{sourceId:e.record.id,filterByTk:null}),{debounce:!0})}})}}}});AddChildActionModel.define({label:(0,import_flow_engine.tExpr)("Add child"),hide(e){var t;return((t=e.collection)==null?void 0:t.template)!=="tree"||e.blockModel.props.treeTable===!1}});RecordActionGroupModel.registerActionModels({AddChildActionModel});const SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG="__saveStepParamsWithSubModels";function markSaveStepParamsWithSubModels(e){if(!e||typeof e!="object"&&typeof e!="function")throw new Error("[saveStepParamsWithSubModels] model is not an object");e[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]=!0}function saveStepParamsWithSubModelsIfNeeded(e,t){return L(this,null,function*(){if(!e||typeof e!="object"&&typeof e!="function")throw new Error("[saveStepParamsWithSubModels] model is not an object");const o=e;if(o[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]!==!0)return yield t();if(typeof o.save!="function")throw new Error("[saveStepParamsWithSubModels] model.save is not a function");try{return yield o.save()}finally{delete o[SAVE_STEP_PARAMS_WITH_SUB_MODELS_FLAG]}})}function evaluateCondition(e,t){const o=(r,i,n)=>{var l,a,c;return i?(c=(a=(l=e==null?void 0:e.app)==null?void 0:l.jsonLogic)==null?void 0:a.apply)==null?void 0:c.call(a,{[i]:[r,n]}):!0};try{return(0,import_client.evaluateConditions)((0,import_client.removeInvalidFilterItems)(t),o)}catch{return!1}}function parsePathString(e){const t=[];let o=0;const r=e.length,i=()=>{const n=o;for(;o<r&&e[o]!=="."&&e[o]!=="[";)o++;const l=e.slice(n,o);l&&t.push(l)};for(;o<r;){const n=e[o];if(n==="."){o++;continue}if(n==="["){o++;const l=o;for(;o<r&&e[o]!=="]";)o++;const a=e.slice(l,o);o++,/^\d+$/.test(a)?t.push(Number(a)):a&&t.push({placeholder:a});continue}i()}return t}function parseFieldIndexEntries(e){const t=Array.isArray(e)?e:[],o=[];for(const r of t){if(typeof r!="string")continue;const[i,n]=r.split(":"),l=Number(n);!i||Number.isNaN(l)||o.push({name:i,index:l})}return o}function resolveDynamicNamePath(e,t){const o=Array.isArray(e)?[...e]:parsePathString(e),r=parseFieldIndexEntries(t),i=[];let n=0;for(let l=0;l<o.length;l++){const a=o[l];if(typeof a=="object"&&a&&"placeholder"in a){const c=i[i.length-1],u=typeof c=="string"?c:void 0;if(!u)return null;for(;n<r.length&&r[n].name!==u;)n++;if(n>=r.length)return null;i.push(r[n].index),n++;continue}if(i.push(a),typeof a=="string"&&n<r.length&&r[n].name===a){const c=o[l+1];typeof c=="number"?n++:typeof c=="object"&&c&&"placeholder"in c||(i.push(r[n].index),n++)}}return i}function namePathToPathKey(e){let t="";for(const o of e){if(typeof o=="number"){t+=`[${o}]`;continue}t?t+=`.${o}`:t=o}return t}function pathKeyToNamePath(e){return parsePathString(e).filter(t=>typeof t!="object")}function buildAncestorKeys(e){const t=[],o=[];for(const r of e)o.push(r),t.push(namePathToPathKey(o));return t}function shouldProxyObjectValue(e){return!e||typeof e!="object"?!1:Array.isArray(e)||import_lodash.default.isPlainObject(e)}function recordDep(e,t){if(t)for(const o of buildAncestorKeys(e))t.deps.add(`fv:${o}`)}function createFormValuesProxy(e){const{valuesMirror:t,collector:o,basePath:r,getFormValuesSnapshot:i,getFormValueAtPath:n}=e,l=()=>r.length?import_lodash.default.get(t,r):t,a=l(),c=a&&(typeof a=="object"||typeof a=="function")?a:Array.isArray(a)?[]:{},u=d=>createFormValuesProxy({valuesMirror:t,basePath:d,collector:o,getFormValuesSnapshot:i,getFormValueAtPath:n});return new Proxy(c,{get(d,m){if(m==="toJSON")return o&&(o.wildcard=!0),r.length===0?()=>i():()=>(0,import_reactive.toJS)(l());if(typeof m=="symbol"){o&&(o.wildcard=!0);const b=l();return b==null?void 0:b[m]}const p=l();if(p==null)return;if(m==="__raw")return p;if(m==="__proto__"||m==="prototype"||m==="constructor"){o&&(o.wildcard=!0);return}const h=Array.isArray(p),g=h&&(typeof m=="number"&&Number.isInteger(m)||typeof m=="string"&&/^\d+$/.test(m));if(h&&!g){o&&(o.wildcard=!0);const b=p[m];return typeof b=="function"?b.bind(p):b}const f=g?Number(m):m,_=[...r,f];recordDep(_,o);let v=p[m];if(typeof v>"u"){const b=n(_);import_lodash.default.isEqual(b,v)||(import_lodash.default.set(t,_,b),v=b)}return v==null||typeof v!="object"?v:shouldProxyObjectValue(v)?u(_):v},ownKeys(){o&&(o.wildcard=!0);const d=l();return d?Reflect.ownKeys(d):[]},getOwnPropertyDescriptor(d,m){const p=l();if(p)return Object.getOwnPropertyDescriptor(p,m)},has(d,m){const p=l();return p?m in p:!1}})}function collectStaticDepsFromTemplateValue(e,t){try{const o=(0,import_flow_engine.extractUsedVariablePaths)(e)||{};for(const[r,i]of Object.entries(o)){const n=Array.isArray(i)?i:[],l=n.length?n:[""];for(const a of l){if(r==="formValues"){if(!a){t.wildcard=!0;continue}const u=parsePathString(String(a)).filter(d=>typeof d!="object");recordDep(u,t);continue}const c=a?`ctx:${r}:${String(a)}`:`ctx:${r}`;t.deps.add(c)}}}catch{}}function collectStaticDepsFromRunJSValue(e,t){if((0,import_flow_engine.isRunJSValue)(e))try{const o=(0,import_flow_engine.extractUsedVariablePathsFromRunJS)(e.code)||{};for(const[r,i]of Object.entries(o)){const n=Array.isArray(i)?i:[],l=n.length?n:[""];for(const a of l){if(r==="formValues"){if(!a){t.wildcard=!0;continue}const u=parsePathString(String(a)).filter(d=>typeof d!="object");recordDep(u,t);continue}const c=a?`ctx:${r}:${String(a)}`:`ctx:${r}`;t.deps.add(c)}}}catch{}}function createFormPatcher(e){let t,o,r;const i=()=>{const n=t;n&&(o&&(n.setFieldValue=o),r&&(n.setFieldsValue=r),t=void 0,o=void 0,r=void 0)};return{patch:n=>{if(t===n)return;i();const l=typeof(n==null?void 0:n.setFieldValue)=="function"?n.setFieldValue.bind(n):void 0,a=typeof(n==null?void 0:n.setFieldsValue)=="function"?n.setFieldsValue.bind(n):void 0;t=n,o=l,r=a,l&&(n.setFieldValue=(c,u)=>{if(e.isSuppressed()){l(c,u);return}e.setFormValues(e.getCallerContext(),[{path:c,value:u}],{source:"system"}).catch(()=>{})}),a&&(n.setFieldsValue=c=>{if(e.isSuppressed()){a(c);return}e.setFormValues(e.getCallerContext(),c,{source:"system"}).catch(()=>{})})},restore:i}}const MAX_WRITES_PER_PATH_PER_TX=20;function isEmptyValue(e){return e==null?!0:typeof e=="string"||Array.isArray(e)?e.length===0:import_lodash.default.isPlainObject(e)?Object.keys(e).length===0:!1}function createTxId(){return`${Date.now()}-${Math.random().toString(16).slice(2)}`}const SKIP_RULE_VALUE=Symbol("SKIP_RULE_VALUE"),UNRESOLVED_ASSOCIATION_IDENTITY=Symbol("UNRESOLVED_ASSOCIATION_IDENTITY"),LINKAGE_DEFAULT_RULE_PRIORITY=1e3;class RuleEngine{constructor(t){R(this,"options"),R(this,"rules",new Map),R(this,"lastRuleWriteByTargetKey",new Map),R(this,"assignTemplatesByTargetPath",new Map),R(this,"formItemTargetPaths",new Set),R(this,"updateAssociationByTargetPath",new Map),R(this,"pendingRuleIds",new Set),R(this,"ruleDebounceUntilById",new Map),R(this,"ruleDebounceTimersById",new Map),R(this,"defaultRuleIdsByMasterUid",new Map),R(this,"defaultRuleMasterDisposers",new Map),R(this,"runningRules",!1),R(this,"rulesEnabled",!1),R(this,"currentRuleTxId",null),this.options=t}getAssignRuleBlockId(t){return`form-assign:${t}:block`}removeAssignRuleBlockInstance(t){const o=this.getAssignRuleBlockId(t);this.rules.has(o)&&this.removeRule(o)}removeRowGridAssignRuleInstances(t){var o,r;const i=`form-assign:${t}:`,n=this.getAssignRuleBlockId(t),l=[];for(const[a,c]of this.rules.entries()){if(!a.startsWith(i)||a===n)continue;const u=(r=(o=c==null?void 0:c.rule)==null?void 0:o.getContext)==null?void 0:r.call(o),d=u==null?void 0:u.model;d&&this.isRowGridModel(d)&&l.push(a)}for(const a of l)this.removeRule(a)}hasAnyNonBlockAssignRuleInstance(t){const o=`form-assign:${t}:`,r=this.getAssignRuleBlockId(t);for(const i of this.rules.keys())if(i.startsWith(o)&&i!==r)return!0;return!1}ensureBlockAssignRuleInstancesForTargetPath(t){if(this.options.isDisposed()||!t||!this.shouldCreateBlockLevelAssignRule(t))return;const o=this.assignTemplatesByTargetPath.get(t)||[];if(o.length)for(const r of o){const i=r!=null&&r.__key?String(r.__key):"";if(!i||this.hasAnyNonBlockAssignRuleInstance(i))continue;const n=((r==null?void 0:r.mode)==="default"?"default":"assign")=="default"?"default":"system",l=(r==null?void 0:r.enable)!==!1,a=this.getAssignRuleBlockId(i);if(this.rules.has(a))continue;const c={id:a,source:n,priority:10+(r.__order||0),debounceMs:0,getEnabled:()=>l&&!!t,getTarget:()=>t,getValue:()=>r==null?void 0:r.value,getCondition:()=>r==null?void 0:r.condition,getContext:()=>this.options.getBlockContext()};this.rules.set(a,{rule:c,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(a)}}getCollectionFromContext(t){var o,r,i;return(i=t==null?void 0:t.collection)!=null?i:(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.collection}getRootCollection(){const t=this.options.getBlockContext();return this.getCollectionFromContext(t)}shouldCreateBlockLevelAssignRule(t){var o,r;const i=this.options.getBlockContext();let n=this.getCollectionFromContext(i);if(!(n!=null&&n.getField))return!0;const l=parsePathString(t).filter(a=>typeof a!="object");if(l.length<=1)return!0;for(let a=0;a<l.length-1;a++){const c=l[a];if(typeof c!="string")continue;const u=(o=n==null?void 0:n.getField)==null?void 0:o.call(n,c);if(!((r=u==null?void 0:u.isAssociationField)!=null&&r.call(u)))break;if(isToManyAssociationField(u)){if(typeof l[a+1]!="number")return!1;a+=1}if(n=u==null?void 0:u.targetCollection,!(n!=null&&n.getField))break}return!0}collectAssociationPrefixPaths(t,o){var r,i;const n=[];let l=this.getRootCollection()||this.getCollectionFromContext(t);if(!(l!=null&&l.getField))return n;const a=[];for(let c=0;c<o.length-1;c++){const u=o[c];if(typeof u!="string")break;const d=(r=l==null?void 0:l.getField)==null?void 0:r.call(l,u);if(!((i=d==null?void 0:d.isAssociationField)!=null&&i.call(d)))break;if(a.push(u),isToManyAssociationField(d)){const m=o[c+1];if(typeof m!="number")break;a.push(m),c+=1}if(n.push([...a]),l=d==null?void 0:d.targetCollection,!(l!=null&&l.getField))break}return n}shouldSkipToManyAssociationWriteWithoutIndex(t,o){var r,i;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return!1;for(let l=0;l<o.length-1;l++){const a=o[l];if(typeof a!="string")continue;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c)))break;if(isToManyAssociationField(c)){if(typeof o[l+1]!="number")return!0;l+=1}if(n=c==null?void 0:c.targetCollection,!(n!=null&&n.getField))break}return!1}shouldSkipAssociationNestedWrite(t,o){const r=this.collectAssociationPrefixPaths(t,o);if(!r.length)return!1;for(const i of r){const n=this.options.getFormValueAtPath(i);if(n==null){const l=i.filter(a=>typeof a=="string").join(".");if(l&&this.getUpdateAssociationForTargetPath(l)||this.isAssociationTargetKeyWrite(t,o,i))continue;return!0}if(typeof n!="object")return!0}return!1}getAssociationTargetKeyFields(t){var o,r,i,n,l;const a=(l=(n=(r=t==null?void 0:t.targetKey)!=null?r:(o=t==null?void 0:t.targetCollection)==null?void 0:o.filterTargetKey)!=null?n:(i=t==null?void 0:t.targetCollection)==null?void 0:i.filterByTk)!=null?l:"id";return Array.isArray(a)?a.filter(c=>typeof c=="string"&&!!c):typeof a=="string"&&a?[a]:["id"]}resolveAssociationFieldByPrefixPath(t,o){var r,i;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return null;let l=null;for(const a of o){if(typeof a=="number")continue;if(typeof a!="string"||!a)break;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c))||(l=c,n=c==null?void 0:c.targetCollection,!(n!=null&&n.getField)))break}return l}isAssociationTargetKeyWrite(t,o,r){var i;if(!Array.isArray(o)||!Array.isArray(r)||o.length!==r.length+1)return!1;const n=o[r.length];if(typeof n!="string"||!n)return!1;const l=this.resolveAssociationFieldByPrefixPath(t,r);return!((i=l==null?void 0:l.isAssociationField)!=null&&i.call(l))||isToManyAssociationField(l)?!1:this.getAssociationTargetKeyFields(l).includes(n)}collectUpdateAssociationInitPatches(t,o){const r=this.collectAssociationPrefixPaths(t,o);if(!r.length)return[];const i=[];for(const l of r){const a=this.options.getFormValueAtPath(l);if(a==null){const c=l.filter(u=>typeof u=="string").join(".");if(!c)return null;if(this.getUpdateAssociationForTargetPath(c)){i.push({path:[...l,"__is_new__"],value:!0});continue}if(this.isAssociationTargetKeyWrite(t,o,l)){i.push({path:[...l],value:{}});continue}return null}if(typeof a!="object")return null}const n=new Map;for(const l of i){const a=namePathToPathKey(l.path);n.has(a)||n.set(a,l)}return Array.from(n.values())}dispose(){for(const{state:t}of this.rules.values())t.depDisposers.forEach(o=>o());this.rules.clear(),this.pendingRuleIds.clear(),this.assignTemplatesByTargetPath.clear();for(const t of this.defaultRuleMasterDisposers.values())t();this.defaultRuleMasterDisposers.clear(),this.defaultRuleIdsByMasterUid.clear();for(const t of this.ruleDebounceTimersById.values())clearTimeout(t);this.ruleDebounceTimersById.clear(),this.ruleDebounceUntilById.clear()}enable(){this.rulesEnabled=!0,this.pendingRuleIds.size&&!this.runningRules&&this.flushRules()}syncAssignRules(t){if(this.options.isDisposed())return;const o=(Array.isArray(t)?t:[]).map((a,c)=>I(x({},a),{key:a!=null&&a.key?String(a.key):`idx:${c}`})),r="form-assign:";for(const a of Array.from(this.rules.keys()))a.startsWith(r)&&this.removeRule(a);this.assignTemplatesByTargetPath.clear(),this.formItemTargetPaths.clear(),this.updateAssociationByTargetPath.clear();let i=0;for(const a of o){const c=a!=null&&a.targetPath?String(a.targetPath):"";if(!c)continue;const u=this.assignTemplatesByTargetPath.get(c)||[];i+=1,u.push(I(x({},a),{__key:String(a.key),__order:i})),this.assignTemplatesByTargetPath.set(c,u)}const n=this.options.getEngine(),l=new Set;if(n!=null&&n.forEachModel){n.forEachModel(c=>{var u;if(!this.isModelInThisForm(c)||!((u=c==null?void 0:c.subModels)!=null&&u.field))return;const d=this.getModelTargetPath(c);d&&this.formItemTargetPaths.add(d),this.cacheUpdateAssociationForModel(c)});const a=c=>{this.cacheUpdateAssociationForModel(c),this.tryRegisterAssignRuleInstancesForModel(c,l);const u=c==null?void 0:c.forks;u&&typeof u.forEach=="function"&&u.forEach(d=>{!d||d!=null&&d.disposed||this.tryRegisterAssignRuleInstancesForModel(d,l)})};n.forEachModel(c=>{a(c)})}for(const[a,c]of this.assignTemplatesByTargetPath.entries())if(!l.has(a)&&this.shouldCreateBlockLevelAssignRule(a))for(const u of c){const d=((u==null?void 0:u.mode)==="default"?"default":"assign")=="default"?"default":"system",m=(u==null?void 0:u.enable)!==!1,p=`${r}${u.__key}:block`;this.rules.has(p)&&this.removeRule(p);const h={id:p,source:d,priority:10+(u.__order||0),debounceMs:0,getEnabled:()=>m&&!!a,getTarget:()=>a,getValue:()=>u==null?void 0:u.value,getCondition:()=>u==null?void 0:u.condition,getContext:()=>this.options.getBlockContext()};this.rules.set(p,{rule:h,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(p)}for(const a of Array.from(this.rules.keys()))a.startsWith("default:")&&this.scheduleRule(a)}onModelMounted(t){var o;if(this.isModelInThisForm(t)&&!(t!=null&&t.isFork)&&(o=t==null?void 0:t.subModels)!=null&&o.field){const r=this.getModelTargetPath(t);r&&this.formItemTargetPaths.add(r),this.cacheUpdateAssociationForModel(t)}this.tryRegisterDefaultRuleInstance(t),this.tryRegisterAssignRuleInstancesForModel(t)}onModelUnmounted(t){var o;if(this.tryUnregisterDefaultRuleInstance(t),this.tryUnregisterAssignRuleInstancesForModel(t),this.isModelInThisForm(t)&&(o=t==null?void 0:t.subModels)!=null&&o.field){const r=this.getModelTargetPath(t);if(r&&(this.ensureBlockAssignRuleInstancesForTargetPath(r),!(t!=null&&t.isFork))){this.updateAssociationByTargetPath.delete(r),this.formItemTargetPaths.delete(r);const i=`${r}.`;for(const l of this.assignTemplatesByTargetPath.keys())l.startsWith(i)&&this.ensureBlockAssignRuleInstancesForTargetPath(l);const n=this.options.getEngine();if(n!=null&&n.forEachModel){const l=a=>{this.tryRegisterAssignRuleInstancesForModel(a);const c=a==null?void 0:a.forks;c&&typeof c.forEach=="function"&&c.forEach(u=>{!u||u!=null&&u.disposed||this.tryRegisterAssignRuleInstancesForModel(u)})};n.forEachModel(a=>l(a))}}}}isModelInThisForm(t){var o;const r=(o=t==null?void 0:t.context)==null?void 0:o.blockModel;return r?String(r.uid)===String(this.options.getBlockModelUid()):!1}cacheUpdateAssociationForModel(t){var o,r;if(this.options.isDisposed()||!this.isModelInThisForm(t)||!t||typeof t!="object"||t!=null&&t.isFork||!((o=t==null?void 0:t.subModels)!=null&&o.field))return;const i=this.getModelTargetPath(t);if(!i)return;const n=(r=t==null?void 0:t.subModels)==null?void 0:r.field,l=!!(n!=null&&n.updateAssociation);this.updateAssociationByTargetPath.get(i)!==!0&&this.updateAssociationByTargetPath.set(i,l)}getUpdateAssociationForTargetPath(t){const o=String(t||"");if(!o)return!1;if(this.updateAssociationByTargetPath.has(o))return!!this.updateAssociationByTargetPath.get(o);const r=this.options.getEngine();return r!=null&&r.forEachModel&&r.forEachModel(i=>{this.cacheUpdateAssociationForModel(i)}),this.updateAssociationByTargetPath.has(o)?!!this.updateAssociationByTargetPath.get(o):(this.updateAssociationByTargetPath.set(o,!1),!1)}getDefaultRuleId(t){var o;const r=t!=null&&t.isFork?String((o=t==null?void 0:t.forkId)!=null?o:"fork"):"master";return`default:${t!=null&&t.uid?String(t.uid):String(t)}:${r}`}getModelTargetNamePath(t){var o;const r=(o=t==null?void 0:t.context)==null?void 0:o.fieldPathArray;if(Array.isArray(r)&&r.length)return r;const i=typeof(t==null?void 0:t.getProps)=="function"?t.getProps():t==null?void 0:t.props,n=i==null?void 0:i.name;return Array.isArray(n)?n:typeof n=="string"?n.includes(".")?n.split("."):[n]:null}getAssignTemplateTargetPathForModel(t){const o=this.getModelTargetPath(t);if(o)return o;const r=this.getModelTargetNamePath(t);if(!(r!=null&&r.length))return"";const i=r.filter(n=>typeof n!="number");return i.length?namePathToPathKey(i):""}hasAssignTemplateForTargetPath(t){const o=String(t||"");return o?this.assignTemplatesByTargetPath.has(o):!1}tryRegisterDefaultRuleInstance(t){if(this.options.isDisposed()||!this.isModelInThisForm(t)||!t||typeof t!="object")return;const o=typeof t.getProps=="function"?t.getProps():t.props;if(!o||typeof o!="object")return;const r=this.getModelTargetNamePath(t);if(!r)return;const i=this.getDefaultRuleId(t);if(this.rules.has(i))return;const n=t.master||t,l=this.getAssignTemplateTargetPathForModel(t);this.bindMasterInitialValue(n,i);const a=()=>{var g,f;const _=(f=(g=n==null?void 0:n.getProps)==null?void 0:g.call(n))!=null?f:n==null?void 0:n.props;return _==null?void 0:_.initialValue},c=a();let u=!1;const d=()=>{const g=a();if(!u&&!import_lodash.default.isEqual(g,c)&&(u=!0),!this.hasAssignTemplateForTargetPath(l)||u||typeof c>"u")return g},m=()=>typeof d()<"u"?LINKAGE_DEFAULT_RULE_PRIORITY:0,p=()=>{var g,f,_,v;if(!this.hasAssignTemplateForTargetPath(l))try{const b=(f=(g=n==null?void 0:n.getStepParams)==null?void 0:g.call(n,"editItemSettings","initialValue"))==null?void 0:f.defaultValue;if(typeof b<"u")return b;const F=(v=(_=n==null?void 0:n.getStepParams)==null?void 0:_.call(n,"formItemSettings","initialValue"))==null?void 0:v.defaultValue;if(typeof F<"u")return F}catch{}},h={id:i,source:"default",priority:m(),debounceMs:0,getEnabled:()=>typeof d()<"u"?!0:typeof p()<"u",getTarget:()=>this.getModelTargetNamePath(t)||r,getValue:()=>{const g=d();return typeof g<"u"?g:p()},getContext:()=>t==null?void 0:t.context};this.rules.set(i,{rule:h,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(i)}getModelTargetPath(t){var o;try{const n=(o=t==null?void 0:t.getStepParams)==null?void 0:o.call(t,"fieldSettings","init"),l=n==null?void 0:n.fieldPath;if(l)return String(l)}catch{}const r=t==null?void 0:t.fieldPath;if(r)return String(r);const i=this.getModelTargetNamePath(t);return i!=null&&i.length&&i.filter(n=>typeof n=="string").join(".")||null}getAssignRuleInstanceId(t,o){var r;const i=o!=null&&o.isFork?String((r=o==null?void 0:o.forkId)!=null?r:"fork"):"master",n=o!=null&&o.uid?String(o.uid):String(o);return`form-assign:${t}:${n}:${i}`}getDeepestFieldIndexKey(t){var o,r,i;const n=(i=(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.fieldIndex)!=null?i:t==null?void 0:t.fieldIndex,l=Array.isArray(n)?n:[];if(!l.length)return null;const a=l[l.length-1];if(typeof a!="string")return null;const[c,u]=a.split(":");if(!c)return null;const d=Number(u);return Number.isNaN(d)?null:c}getDeepestToManyAssociationKey(t){var o,r;const i=this.getRootCollection();if(!(i!=null&&i.getField))return null;const n=parsePathString(String(t||"")).filter(c=>typeof c!="object");if(n.length<2)return null;let l=i,a=null;for(let c=0;c<n.length-1;c++){const u=n[c];if(typeof u!="string")continue;const d=(o=l==null?void 0:l.getField)==null?void 0:o.call(l,u);if(!((r=d==null?void 0:d.isAssociationField)!=null&&r.call(d)))break;const m=isToManyAssociationField(d);if(m&&(a=u),m&&typeof n[c+1]=="number"&&(c+=1),l=d==null?void 0:d.targetCollection,!(l!=null&&l.getField))break}return a}isRowGridModel(t){var o,r;if(!t||typeof t!="object"||(o=t==null?void 0:t.subModels)!=null&&o.field||!((r=t==null?void 0:t.subModels)!=null&&r.items))return!1;const i=t==null?void 0:t.context;return!!this.getDeepestFieldIndexKey(i)}tryRegisterAssignRuleInstancesForModel(t,o){var r,i,n,l;if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const a=(g,f)=>{var _;if(!(!f||f.length===0)){o==null||o.add(g);for(const v of f){this.removeAssignRuleBlockInstance(v.__key),(_=t==null?void 0:t.subModels)!=null&&_.field&&this.removeRowGridAssignRuleInstances(v.__key);const b=((v==null?void 0:v.mode)==="default"?"default":"assign")=="default"?"default":"system",F=(v==null?void 0:v.enable)!==!1,y=this.getAssignRuleInstanceId(v.__key,t);this.rules.has(y)&&this.removeRule(y);const C={id:y,source:b,priority:10+(v.__order||0),debounceMs:0,getEnabled:()=>F&&!!g,getTarget:()=>g,getValue:()=>v==null?void 0:v.value,getCondition:()=>v==null?void 0:v.condition,getContext:()=>t==null?void 0:t.context};this.rules.set(y,{rule:C,state:{deps:new Set,depDisposers:[],runSeq:0,scheduledAtWriteSeq:0}}),this.scheduleRule(y)}}};if(this.isRowGridModel(t)){const g=t==null?void 0:t.context,f=this.getDeepestFieldIndexKey(g);if(f)for(const[_,v]of this.assignTemplatesByTargetPath.entries()){if(this.formItemTargetPaths.has(_))continue;const b=this.getDeepestToManyAssociationKey(_);!b||b!==f||a(_,v)}return}if(!((r=t==null?void 0:t.subModels)!=null&&r.field))return;const c=this.getModelTargetPath(t);if(!c)return;const u=this.assignTemplatesByTargetPath.get(c)||[];u.length&&a(c,u);const d=(i=t==null?void 0:t.subModels)==null?void 0:i.field,m=(n=d==null?void 0:d.context)==null?void 0:n.collectionField,p=!!((l=m==null?void 0:m.isAssociationField)!=null&&l.call(m)),h=isToManyAssociationField(m);if(p&&!h){const g=`${c}.`;for(const[f,_]of this.assignTemplatesByTargetPath.entries())!f||typeof f!="string"||f.startsWith(g)&&a(f,_)}}tryUnregisterAssignRuleInstancesForModel(t){var o,r,i,n;if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const l=h=>{for(const g of h||[]){const f=this.getAssignRuleInstanceId(g.__key,t);this.rules.has(f)&&this.removeRule(f)}};if(this.isRowGridModel(t)){const h=t==null?void 0:t.context,g=this.getDeepestFieldIndexKey(h);if(!g)return;for(const[f,_]of this.assignTemplatesByTargetPath.entries()){if(this.formItemTargetPaths.has(f))continue;const v=this.getDeepestToManyAssociationKey(f);!v||v!==g||l(_)}return}if(!((o=t==null?void 0:t.subModels)!=null&&o.field))return;const a=this.getModelTargetPath(t);if(!a)return;const c=this.assignTemplatesByTargetPath.get(a)||[];c.length&&l(c);const u=(r=t==null?void 0:t.subModels)==null?void 0:r.field,d=(i=u==null?void 0:u.context)==null?void 0:i.collectionField,m=!!((n=d==null?void 0:d.isAssociationField)!=null&&n.call(d)),p=isToManyAssociationField(d);if(m&&!p){const h=`${a}.`;for(const[g,f]of this.assignTemplatesByTargetPath.entries())!g||typeof g!="string"||g.startsWith(h)&&l(f)}}tryUnregisterDefaultRuleInstance(t){if(this.options.isDisposed()||!this.isModelInThisForm(t))return;const o=this.getDefaultRuleId(t);this.rules.has(o)&&this.removeRule(o)}bindMasterInitialValue(t,o){const r=t!=null&&t.uid?String(t.uid):o,i=this.defaultRuleIdsByMasterUid.get(r)||new Set;if(i.add(o),this.defaultRuleIdsByMasterUid.set(r,i),this.defaultRuleMasterDisposers.has(r))return;const n=(0,import_reactive.reaction)(()=>{var l,a;const c=(a=(l=t==null?void 0:t.getProps)==null?void 0:l.call(t))!=null?a:t==null?void 0:t.props;return c==null?void 0:c.initialValue},(l,a)=>{var c,u;if(import_lodash.default.isEqual(l,a))return;const d=this.defaultRuleIdsByMasterUid.get(r);if(!d)return;const m=(u=(c=t==null?void 0:t.getProps)==null?void 0:c.call(t))!=null?u:t==null?void 0:t.props,p=typeof(m==null?void 0:m.initialValue)<"u"?LINKAGE_DEFAULT_RULE_PRIORITY:0;for(const h of d){const g=this.rules.get(h);g&&(g.rule.priority=p),this.scheduleRule(h)}});this.defaultRuleMasterDisposers.set(r,n)}removeRule(t){const o=this.rules.get(t);if(!o)return;try{const i=o.rule.getContext(),n=o.rule.getTarget(),l=this.options.tryResolveNamePath(i,n);if(l){const a=namePathToPathKey(l),c=this.options.observableBindings.get(a);c&&c.source===o.rule.source&&(c.dispose(),this.options.observableBindings.delete(a))}}catch{}o.state.depDisposers.forEach(i=>i()),this.rules.delete(t),this.pendingRuleIds.delete(t);const r=this.ruleDebounceTimersById.get(t);r&&clearTimeout(r),this.ruleDebounceTimersById.delete(t),this.ruleDebounceUntilById.delete(t);for(const[i,n]of this.defaultRuleIdsByMasterUid.entries()){if(!n.has(t)||(n.delete(t),n.size>0))continue;this.defaultRuleIdsByMasterUid.delete(i);const l=this.defaultRuleMasterDisposers.get(i);l&&l(),this.defaultRuleMasterDisposers.delete(i)}}rescheduleAllRules(){if(!this.options.isDisposed()){this.lastRuleWriteByTargetKey.clear();for(const t of this.rules.values())t.state.runSeq+=1;for(const t of this.rules.keys())this.scheduleRule(t)}}scheduleRule(t){var o;if(this.options.isDisposed())return;const r=this.rules.get(t);if(!r)return;const{rule:i,state:n}=r;n.scheduledAtWriteSeq=this.options.getWriteSeq();const l=(o=i==null?void 0:i.debounceMs)!=null?o:0;if(this.pendingRuleIds.add(t),l>0){const a=Date.now()+l,c=this.ruleDebounceUntilById.get(t)||0;a>c&&this.ruleDebounceUntilById.set(t,a);const u=this.ruleDebounceTimersById.get(t);u&&clearTimeout(u);const d=setTimeout(()=>{this.ruleDebounceTimersById.delete(t),this.rulesEnabled&&(this.runningRules||this.pendingRuleIds.has(t)&&this.flushRules())},l);this.ruleDebounceTimersById.set(t,d)}else{const a=this.ruleDebounceTimersById.get(t);a&&clearTimeout(a),this.ruleDebounceTimersById.delete(t),this.ruleDebounceUntilById.delete(t)}this.rulesEnabled&&(this.runningRules||this.flushRules())}flushRules(){return L(this,null,function*(){if(this.runningRules)return;this.runningRules=!0;const t=this.currentRuleTxId||createTxId();this.currentRuleTxId=t;try{for(;this.pendingRuleIds.size;){const o=Date.now(),r=[];for(const i of this.pendingRuleIds)(this.ruleDebounceUntilById.get(i)||0)>o||r.push(i);if(!r.length)break;for(const i of r)this.pendingRuleIds.delete(i),this.ruleDebounceUntilById.delete(i);r.sort((i,n)=>{var l,a,c,u;const d=(l=this.rules.get(i))==null?void 0:l.rule,m=(a=this.rules.get(n))==null?void 0:a.rule,p=(c=d==null?void 0:d.priority)!=null?c:0,h=(u=m==null?void 0:m.priority)!=null?u:0;return p!==h?p-h:i.localeCompare(n)});for(const i of r)yield this.runRule(i)}}finally{this.runningRules=!1,this.currentRuleTxId=null,this.options.txWriteCounts.delete(t)}})}runRule(t){return L(this,null,function*(){var o,r;const i=this.rules.get(t);if(!i)return;const{rule:n,state:l}=i;l.runSeq+=1;const a=l.runSeq,c=l.scheduledAtWriteSeq,u=this.prepareRuleContext(n),{baseCtx:d,targetNamePath:m,targetKey:p,clearDeps:h,disposeBinding:g}=u;if(!this.shouldRunRule(n,m,p,d)){h(l),g();return}if(!m||!p){h(l),g();return}const f=m,_=p,{collector:v,evalCtx:b}=this.createRuleCollectorAndContext(n,u);if(n.getCondition&&!(yield this.evaluateRuleCondition(n,l,a,b,v)))return;const F=yield this.resolveRuleValue(n,l,a,b,v);if(F===SKIP_RULE_VALUE||a!==l.runSeq)return;this.commitRuleDeps(n,l,v);const y=this.normalizeResolvedValueForTarget(d,F),C=this.normalizeResolvedValueForAssociationTarget(d,f,y);if(n.source==="default"&&!this.checkDefaultRuleCanApply(C,f,_,h,g,l))return;if(n.source==="default"){const N=this.lastRuleWriteByTargetKey.get(_);if((N==null?void 0:N.source)==="default"&&N.priority>n.priority&&N.writeSeq>=c){g();return}}if(n.source==="system"){const N=this.options.lastWriteMetaByPathKey.get(_);if((N==null?void 0:N.source)==="linkage"&&N.writeSeq>=c){g();return}}if(this.shouldSkipAssociationNestedWrite(d,f)||this.shouldSkipToManyAssociationWriteWithoutIndex(d,f))return;const S=C;if(this.isAssociationTargetSemanticallyEqual(d,f,this.options.getFormValueAtPath(f),S))return;const P=this.collectUpdateAssociationInitPatches(d,f);if(P==null)return;if(n.source==="system"||n.source==="default"){const N=d==null?void 0:d.model,D=(o=N==null?void 0:N.subModels)==null?void 0:o.field;if(D){const w=this.getModelTargetNamePath(N);w&&namePathToPathKey(w)===_&&(N.setProps({value:C}),(r=D.setProps)==null||r.call(D,{value:C}))}}const j=this.options.getWriteSeq(),A=[...P,{path:f,value:C}];yield this.options.setFormValues(b,A,{source:n.source,txId:this.currentRuleTxId||void 0});const T=this.options.getWriteSeq();T!==j&&this.lastRuleWriteByTargetKey.set(_,{source:n.source,priority:n.priority,writeSeq:T})})}isTzAwareTargetInterface(t){return typeof t!="string"?!1:["datetime","createdAt","updatedAt","unixTimestamp"].includes(t)}normalizeDateOnlyToStartOfDayIso(t){const o=String(t||"").trim();if(!o||!/^\d{4}-\d{2}-\d{2}$/.test(o))return t;const r=(0,import_client.dayjs)(o,"YYYY-MM-DD",!0);return r.isValid()?r.startOf("day").toISOString():t}normalizeResolvedValueForTarget(t,o){var r,i,n;const l=(n=(i=(r=t==null?void 0:t.model)==null?void 0:r.context)==null?void 0:i.collectionField)==null?void 0:n.interface;return this.isTzAwareTargetInterface(l)?typeof o=="string"?this.normalizeDateOnlyToStartOfDayIso(o):Array.isArray(o)?o.map(a=>typeof a=="string"?this.normalizeDateOnlyToStartOfDayIso(a):a):o:o}isPrimitiveAssociationTargetValue(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}extractAssociationIdentity(t,o){const r=this.getAssociationTargetKeyFields(t),i=r.length===1?r[0]:null,n=a=>{if(a==null)return a;if(this.isPrimitiveAssociationTargetValue(a))return i?a:UNRESOLVED_ASSOCIATION_IDENTITY;if(!a||typeof a!="object")return UNRESOLVED_ASSOCIATION_IDENTITY;if(i)return typeof a[i]>"u"?UNRESOLVED_ASSOCIATION_IDENTITY:a[i];const c={};for(const u of r){if(typeof a[u]>"u")return UNRESOLVED_ASSOCIATION_IDENTITY;c[u]=a[u]}return c};if(isToManyAssociationField(t)){const a=Array.isArray(o)?o:[o],c=[];for(const u of a){if(u==null)continue;const d=n(u);if(d===UNRESOLVED_ASSOCIATION_IDENTITY)return UNRESOLVED_ASSOCIATION_IDENTITY;c.push(d)}return c}const l=Array.isArray(o)?o.find(a=>a!=null):o;return l==null?l:n(l)}isAssociationTargetSemanticallyEqual(t,o,r,i){var n;const l=this.resolveCollectionFieldByNamePath(t,o);if(!((n=l==null?void 0:l.isAssociationField)!=null&&n.call(l)))return import_lodash.default.isEqual(r,i);const a=this.extractAssociationIdentity(l,r),c=this.extractAssociationIdentity(l,i);return a===UNRESOLVED_ASSOCIATION_IDENTITY||c===UNRESOLVED_ASSOCIATION_IDENTITY?import_lodash.default.isEqual(r,i):import_lodash.default.isEqual(a,c)}resolveCollectionFieldByNamePath(t,o){var r,i;if(!Array.isArray(o)||!o.length)return null;let n=this.getRootCollection()||this.getCollectionFromContext(t);if(!(n!=null&&n.getField))return null;for(let l=0;l<o.length;l++){const a=o[l];if(typeof a!="string"||!a)return null;const c=(r=n==null?void 0:n.getField)==null?void 0:r.call(n,a);if(!c)return null;if(l===o.length-1)return c;if(!((i=c==null?void 0:c.isAssociationField)!=null&&i.call(c))||!(c!=null&&c.targetCollection))return null;if(isToManyAssociationField(c)){if(typeof o[l+1]!="number")return null;l+=1}if(n=c.targetCollection,!(n!=null&&n.getField))return null}return null}normalizeResolvedValueForAssociationTarget(t,o,r){var i;const n=this.resolveCollectionFieldByNamePath(t,o);if(!((i=n==null?void 0:n.isAssociationField)!=null&&i.call(n)))return r;const l=this.getAssociationTargetKeyFields(n),a=l.length===1?l[0]:null,c=d=>{if(d!=null)return a&&this.isPrimitiveAssociationTargetValue(d)?{[a]:d}:d};if(isToManyAssociationField(n))return(Array.isArray(r)?r:[r]).map(d=>c(d)).filter(d=>typeof d<"u"&&d!==null);const u=Array.isArray(r)?r.find(d=>d!=null):r;return u==null?u:c(u)}prepareRuleContext(t){const o=t.getContext(),r=t.getTarget(),i=this.options.tryResolveNamePath(o,r),n=i?namePathToPathKey(i):null;return{baseCtx:o,targetNamePath:i,targetKey:n,clearDeps:l=>{l.depDisposers.forEach(a=>a()),l.depDisposers=[],l.deps=new Set},disposeBinding:()=>{if(!n)return;const l=this.options.observableBindings.get(n);l&&l.source===t.source&&(l.dispose(),this.options.observableBindings.delete(n))}}}shouldApplyDefaultRuleInCurrentState(t){var o,r;if(((r=(o=this.options).getActionName)==null?void 0:r.call(o))!=="update")return!0;let i;try{i=t==null?void 0:t.item}catch{i=void 0}return!i||typeof i!="object"?!1:i.__is_new__===!0}shouldRunRule(t,o,r,i){return!(!t.getEnabled()||!o||!r||t.source==="default"&&(!this.shouldApplyDefaultRuleInCurrentState(i)||this.options.findExplicitHit(r)))}createRuleCollectorAndContext(t,o){const{baseCtx:r,targetNamePath:i}=o,n=t.getValue(),l=(0,import_flow_engine.isRunJSValue)(n),a={deps:new Set,wildcard:!1};if(t.getCondition&&collectStaticDepsFromTemplateValue(t.getCondition(),a),l?collectStaticDepsFromRunJSValue(n,a):collectStaticDepsFromTemplateValue(n,a),i){recordDep(i,a);for(const u of this.collectAssociationPrefixPaths(r,i))recordDep(u,a)}const c=this.createRuleEvaluationContext(r,a,i);return{collector:a,evalCtx:c,rawValue:n,isRunJS:l}}evaluateRuleCondition(t,o,r,i,n){return L(this,null,function*(){var l;const a=t.getCondition;if(!a)return!0;const c=a();let u=c;if(c)try{u=yield(l=i==null?void 0:i.resolveJsonTemplate)==null?void 0:l.call(i,c)}catch{u=c}return r!==o.runSeq?!1:c&&!evaluateCondition(i,u)?(this.commitRuleDeps(t,o,n),!1):!0})}resolveRuleValue(t,o,r,i,n){return L(this,null,function*(){const l=t.getValue();return(0,import_flow_engine.isRunJSValue)(l)?this.resolveRunJSValue(l,o,r,i,n,t):this.resolveTemplateValue(l,o,r,i,n,t)})}resolveRunJSValue(t,o,r,i,n,l){return L(this,null,function*(){try{const{code:a,version:c}=(0,import_flow_engine.normalizeRunJSValue)(t),u=yield(0,import_flow_engine.runjsWithSafeGlobals)(i,a,{version:c});return u!=null&&u.success?u.value:(r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE)}catch{return r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE}})}resolveTemplateValue(t,o,r,i,n,l){return L(this,null,function*(){var a;try{return yield(a=i==null?void 0:i.resolveJsonTemplate)==null?void 0:a.call(i,t)}catch{return r!==o.runSeq||this.commitRuleDeps(l,o,n),SKIP_RULE_VALUE}})}commitRuleDeps(t,o,r){const i=new Set(r.deps);r.wildcard&&i.add("fv:*"),this.updateRuleDeps(t,o,i)}checkDefaultRuleCanApply(t,o,r,i,n,l){if(typeof t>"u")return!1;if(this.options.findExplicitHit(r))return i(l),n(),!1;const a=this.options.getFormValueAtPath(o),c=this.options.lastDefaultValueByPathKey.get(r),u=isEmptyValue(a)||typeof c<"u"&&import_lodash.default.isEqual(a,c),d=(0,import_reactive.isObservable)(t)?(0,import_reactive.toJS)(t):t;return!u&&import_lodash.default.isEqual(a,d)?(this.options.lastDefaultValueByPathKey.set(r,d),!1):u}createRuleEvaluationContext(t,o,r){var i;const n=this.options.createTrackingFormValues(o),l=new import_flow_engine.FlowContext;try{l.delegate(t)}catch{}const a=(i=t==null?void 0:t.getPropertyOptions)==null?void 0:i.call(t,"formValues");a&&typeof a=="object"?l.defineProperty("formValues",I(x({},a),{get:()=>n,cache:!1})):l.defineProperty("formValues",{get:()=>n,cache:!1});let c,u=!1;const d=()=>{if(!u){const m=this.buildItemChainValue(t,n,r);c=m??(t==null?void 0:t.item),u=!0}return c};return l.defineProperty("item",{get:d,cache:!1}),l}buildItemChainValue(t,o,r){var i,n;const l=this.getRootCollection()||this.getCollectionFromContext(t),a=(h,g,f,_)=>({index:g,length:f,__is_new__:h==null?void 0:h.__is_new__,__is_stored__:h==null?void 0:h.__is_stored__,value:h,parentItem:_}),c=a(o,void 0,void 0,void 0);if(!r||!Array.isArray(r)||!r.length||!(l!=null&&l.getField))return;const u=[],d=[];let m=l;for(let h=0;h<r.length-1;h++){const g=r[h];if(typeof g!="string")break;const f=(i=m==null?void 0:m.getField)==null?void 0:i.call(m,g);if(!((n=f==null?void 0:f.isAssociationField)!=null&&n.call(f)))break;const _=isToManyAssociationField(f);if(d.push(g),_){const b=r[h+1];if(typeof b!="number")break;d.push(b),h+=1}const v=f==null?void 0:f.targetCollection;if(!v)break;u.push({path:[...d],toMany:_}),m=v}const p=h=>{if(h<0)return c;const g=u[h],f=import_lodash.default.get(o,g.path),_=g.path[g.path.length-1],v=g.toMany&&typeof _=="number"?_:void 0,b=(()=>{if(!g.toMany)return;const F=g.path.slice(0,-1),y=import_lodash.default.get(o,F);return Array.isArray(y)?y.length:void 0})();return a(f,v,b,p(h-1))};return u.length?p(u.length-1):void 0}getFieldIndexSignature(t){var o,r,i;const n=(i=(r=(o=t==null?void 0:t.model)==null?void 0:o.context)==null?void 0:r.fieldIndex)!=null?i:t==null?void 0:t.fieldIndex;return(Array.isArray(n)?n:[]).filter(l=>typeof l=="string").join("|")}updateRuleDeps(t,o,r){if(o.depDisposers.forEach(n=>n()),o.depDisposers=[],o.deps=r,r.has("fv:*")){const n=(0,import_reactive.reaction)(()=>this.options.changeTick.value,()=>this.scheduleRule(t.id));o.depDisposers.push(n)}const i=(()=>{try{return t.getContext()}catch{return}})();for(const n of r){if(n==="fv:*")continue;if(!n.startsWith("fv:")&&!n.startsWith("ctx:")){const p=pathKeyToNamePath(n),h=(0,import_reactive.reaction)(()=>import_lodash.default.get(this.options.valuesMirror,p),()=>this.scheduleRule(t.id));o.depDisposers.push(h);continue}if(n.startsWith("fv:")){const p=n.slice(3),h=pathKeyToNamePath(p),g=(0,import_reactive.reaction)(()=>import_lodash.default.get(this.options.valuesMirror,h),()=>this.scheduleRule(t.id));o.depDisposers.push(g);continue}const l=n.slice(4),a=l.indexOf(":"),c=a>=0?l.slice(0,a):l,u=a>=0?l.slice(a+1):"",d=u?parsePathString(u).filter(p=>typeof p!="object"):[];if(c==="item"){const p=(0,import_reactive.reaction)(()=>this.getFieldIndexSignature(i),()=>this.scheduleRule(t.id));if(o.depDisposers.push(p),d.length){const h=this.options.createTrackingFormValues({deps:new Set,wildcard:!1}),g=(0,import_reactive.reaction)(()=>{var f,_;const v=(f=t.getTarget)==null?void 0:f.call(t),b=v?this.options.tryResolveNamePath(i,v):null,F=(_=this.buildItemChainValue(i,h,b))!=null?_:i==null?void 0:i.item;return import_lodash.default.get(F,d)},()=>this.scheduleRule(t.id));o.depDisposers.push(g)}continue}const m=(0,import_reactive.reaction)(()=>{const p=i?i[c]:void 0;return d.length?import_lodash.default.get(p,d):p},()=>this.scheduleRule(t.id));o.depDisposers.push(m)}}}class FormValueRuntime{constructor(t){R(this,"model"),R(this,"getForm"),R(this,"valuesMirror",(0,import_reactive.observable)({})),R(this,"explicitSet",new Set),R(this,"lastDefaultValueByPathKey",new Map),R(this,"lastWriteMetaByPathKey",new Map),R(this,"observableBindings",new Map),R(this,"changeTick",import_reactive.observable.ref(0)),R(this,"txWriteCounts",new Map),R(this,"writeSeq",0),R(this,"disposed",!1),R(this,"suppressFormCallbackDepth",0),R(this,"lastObservedChangedPaths",null),R(this,"lastObservedSource",null),R(this,"lastObservedToken",0),R(this,"formValuesProxy"),R(this,"mountedListener"),R(this,"unmountedListener"),R(this,"formPatcher"),R(this,"ruleEngine"),this.model=t.model,this.getForm=t.getForm,this.formPatcher=createFormPatcher({isSuppressed:()=>this.isSuppressed(),getCallerContext:()=>{var o;return(o=this.model)==null?void 0:o.context},setFormValues:this.setFormValues.bind(this)}),this.ruleEngine=new RuleEngine({getBlockModelUid:()=>{var o;return String((o=this.model)==null?void 0:o.uid)},getActionName:()=>{var o,r,i,n,l;return(l=(r=(o=this.model)==null?void 0:o.getAclActionName)==null?void 0:r.call(o))!=null?l:(n=(i=this.model)==null?void 0:i.context)==null?void 0:n.actionName},getBlockContext:()=>{var o;return(o=this.model)==null?void 0:o.context},getEngine:()=>{var o,r;return(r=(o=this.model)==null?void 0:o.context)==null?void 0:r.engine},getEngineModel:o=>{var r,i,n,l,a;return(a=(l=(n=(i=(r=this.model)==null?void 0:r.context)==null?void 0:i.engine)==null?void 0:n.getModel)==null?void 0:l.call(n,o))!=null?a:null},isDisposed:()=>this.disposed,valuesMirror:this.valuesMirror,changeTick:this.changeTick,getWriteSeq:()=>this.writeSeq,txWriteCounts:this.txWriteCounts,createTrackingFormValues:o=>createFormValuesProxy({valuesMirror:this.valuesMirror,basePath:[],collector:o,getFormValuesSnapshot:()=>this.getFormValuesSnapshot(),getFormValueAtPath:r=>this.getFormValueAtPath(r)}),tryResolveNamePath:(o,r)=>this.tryResolveNamePath(o,r),getFormValueAtPath:o=>this.getFormValueAtPath(o),setFormValues:(o,r,i)=>this.setFormValues(o,r,i),findExplicitHit:o=>this.findExplicitHit(o),lastDefaultValueByPathKey:this.lastDefaultValueByPathKey,lastWriteMetaByPathKey:this.lastWriteMetaByPathKey,observableBindings:this.observableBindings}),this.formValuesProxy=createFormValuesProxy({valuesMirror:this.valuesMirror,basePath:[],getFormValuesSnapshot:()=>this.getFormValuesSnapshot(),getFormValueAtPath:o=>this.getFormValueAtPath(o)})}syncAssignRules(t){this.ruleEngine.syncAssignRules(t)}get formValues(){return this.disposed||this.formPatcher.patch(this.getForm()),this.formValuesProxy}getFormValuesSnapshot(){if(!this.disposed){const t=this.getForm();this.formPatcher.patch(t)}return this.getForm().getFieldsValue(!0)}getFormValueAtPath(t){var o;const r=(o=this.getForm)==null?void 0:o.call(this);if(r&&typeof r.getFieldValue=="function")return r.getFieldValue(t);if(r&&typeof r.getFieldsValue=="function"){const i=r.getFieldsValue(!0);return import_lodash.default.get(i,t)}}mount(t){var o,r;if(this.disposed)return;this.formPatcher.patch(this.getForm());const i=(r=(o=this.model)==null?void 0:o.flowEngine)==null?void 0:r.emitter;if(i&&(!this.mountedListener&&!this.unmountedListener&&(this.mountedListener=({model:n})=>{this.ruleEngine.onModelMounted(n)},this.unmountedListener=({model:n})=>{this.ruleEngine.onModelUnmounted(n)},i.on("model:mounted",this.mountedListener),i.on("model:unmounted",this.unmountedListener)),t!=null&&t.sync)){const n=this.getFormValuesSnapshot();n&&typeof n=="object"&&(import_lodash.default.merge(this.valuesMirror,n),this.bumpChangeTick()),this.ruleEngine.enable()}}dispose(){var t,o;if(this.disposed)return;this.disposed=!0,this.formPatcher.restore();const r=(o=(t=this.model)==null?void 0:t.flowEngine)==null?void 0:o.emitter;r&&this.mountedListener&&this.unmountedListener&&(r.off("model:mounted",this.mountedListener),r.off("model:unmounted",this.unmountedListener)),this.ruleEngine.dispose();for(const i of this.observableBindings.values())i.dispose();this.observableBindings.clear(),this.txWriteCounts.clear()}resetAfterFormReset(){if(this.disposed)return;this.explicitSet.clear(),this.lastDefaultValueByPathKey.clear(),this.lastWriteMetaByPathKey.clear(),this.txWriteCounts.clear(),this.lastObservedChangedPaths=null,this.lastObservedSource=null,this.lastObservedToken+=1;for(const o of this.observableBindings.values())o.dispose();this.observableBindings.clear();const t=this.getFormValuesSnapshot();for(const o of Object.keys(this.valuesMirror))delete this.valuesMirror[o];t&&typeof t=="object"&&import_lodash.default.merge(this.valuesMirror,t),this.writeSeq+=1,this.bumpChangeTick(),this.ruleEngine.rescheduleAllRules()}isSuppressed(){return this.suppressFormCallbackDepth>0}handleFormFieldsChange(t){if(this.disposed)return;const o=this.getForm();if(!o.getFieldValue)return;const r=[],i=new Set;let n=!1;for(const d of t||[]){const m=d==null?void 0:d.name,p=Array.isArray(m)?m:typeof m=="string"||typeof m=="number"?[m]:null;if(!(p!=null&&p.length))continue;const h=o.getFieldValue(p),g=import_lodash.default.get(this.valuesMirror,p);import_lodash.default.isEqual(h,g)||(n||(this.writeSeq+=1,n=!0),import_lodash.default.set(this.valuesMirror,p,h),r.push(p),(d==null?void 0:d.touched)===!0&&i.add(namePathToPathKey(p)))}if(!r.length)return;const l=this.isSuppressed();if(!l&&i.size)for(const d of i)this.markExplicit(d);if(this.bumpChangeTick(),l)return;const a=t.some(d=>(d==null?void 0:d.touched)===!0)?"user":"system",c=this.writeSeq;for(const d of r)this.lastWriteMetaByPathKey.set(namePathToPathKey(d),{source:a,writeSeq:c});this.lastObservedChangedPaths=r,this.lastObservedSource=a;const u=++this.lastObservedToken;queueMicrotask(()=>{this.disposed||this.lastObservedToken===u&&(this.lastObservedChangedPaths=null,this.lastObservedSource=null)})}handleFormValuesChange(t,o){var r;if(this.disposed||this.isSuppressed())return;const i=this.lastObservedChangedPaths&&this.lastObservedChangedPaths.length?this.lastObservedChangedPaths:Object.keys(t||{}).map(p=>[p]),n=(r=this.lastObservedSource)!=null?r:"user";this.lastObservedChangedPaths=null,this.lastObservedSource=null;const l=o&&typeof o=="object"?o:this.getFormValuesSnapshot(),a=this.deriveExplicitPaths(i,l,this.valuesMirror);let c=!1,u=!1;const d=[];for(const p of i){if(!(p!=null&&p.length))continue;const h=import_lodash.default.get(l,p),g=import_lodash.default.get(this.valuesMirror,p);import_lodash.default.isEqual(g,h)||(u||(this.writeSeq+=1,u=!0),import_lodash.default.set(this.valuesMirror,p,h),c=!0,d.push(p))}c&&this.bumpChangeTick();for(const p of a)this.markExplicit(namePathToPathKey(p));if(c){const p=this.writeSeq;for(const h of d)h!=null&&h.length&&this.lastWriteMetaByPathKey.set(namePathToPathKey(h),{source:n,writeSeq:p})}const m=createTxId();this.emitFormValuesChange({source:n,txId:m,changedPaths:i,changedValues:t,allValues:l,allValuesSnapshot:l})}deriveExplicitPaths(t,o,r){const i=[],n=new Set;for(const l of t||[]){if(!(l!=null&&l.length))continue;const a=import_lodash.default.get(r,l),c=import_lodash.default.get(o,l);this.collectExplicitDiffPaths(a,c,l,i,n)}return i}collectExplicitDiffPaths(t,o,r,i,n){if(import_lodash.default.isEqual(t,o))return 0;const l=Array.isArray(t),a=Array.isArray(o);if(l||a){if(l&&a){const d=Math.min(t.length,o.length);let m=0;for(let p=0;p<d;p++)m+=this.collectExplicitDiffPaths(t[p],o[p],[...r,p],i,n);return m}return this.pushExplicitPath(r,i,n)?1:0}const c=this.isPlainObjectValue(t),u=this.isPlainObjectValue(o);if(c||u){if(c&&u){const d=new Set([...Object.keys(t),...Object.keys(o)]);let m=0;for(const p of d)m+=this.collectExplicitDiffPaths(t[p],o[p],[...r,p],i,n);return m===0&&this.isObjectCleared(t,o)?this.pushExplicitPath(r,i,n)?1:0:m}return this.isObjectCleared(t,o)?this.pushExplicitPath(r,i,n)?1:0:this.pushExplicitPath(r,i,n)?1:0}return this.pushExplicitPath(r,i,n)?1:0}pushExplicitPath(t,o,r){if(!(t!=null&&t.length))return!1;const i=namePathToPathKey(t);return!i||r.has(i)?!1:(r.add(i),o.push([...t]),!0)}isPlainObjectValue(t){return import_lodash.default.isPlainObject(t)}isObjectCleared(t,o){return this.isPlainObjectValue(t)?!!(o==null||this.isPlainObjectValue(o)&&Object.keys(o).length===0):!1}setFormValues(t,o,r){return L(this,null,function*(){var i,n,l,a,c,u;if(this.disposed)return;const d=(i=this.getForm)==null?void 0:i.call(this);if(!d)return;const m=(n=r==null?void 0:r.source)!=null?n:"system",p=(r==null?void 0:r.triggerEvent)!==!1,h=(l=r==null?void 0:r.txId)!=null?l:createTxId(),g=(a=r==null?void 0:r.markExplicit)!=null?a:m!=="default",f=typeof(r==null?void 0:r.txId)>"u",_=m==="linkage"&&Number.isFinite(Number(r==null?void 0:r.linkageScopeDepth))?Number(r==null?void 0:r.linkageScopeDepth):0,v=m==="linkage"&&typeof(r==null?void 0:r.linkageTxId)=="string"&&r.linkageTxId?String(r.linkageTxId):void 0,b=C=>{if(m!=="linkage"||!v)return!1;const S=this.lastWriteMetaByPathKey.get(C);return!S||S.source!=="linkage"||!S.linkageTxId||S.linkageTxId!==v?!1:(Number.isFinite(Number(S.linkageScopeDepth))?Number(S.linkageScopeDepth):0)>_},F=C=>m==="linkage"?{source:m,writeSeq:C,linkageScopeDepth:_,linkageTxId:v}:{source:m,writeSeq:C},y=C=>m==="linkage"&&v?I(x({},C),{linkageTxId:v}):C;try{const C=[];if(!Array.isArray(o)){const D=Object.entries(o||{}).filter(([E])=>!b(E)),w=Object.fromEntries(D),k=D.map(([E])=>E);if(!k.length)return;k.length&&(this.writeSeq+=1),this.suppressFormCallbackDepth++;try{for(const[E,M]of D){const O=(0,import_reactive.isObservable)(M)?(0,import_reactive.toJS)(M):M;typeof d.setFieldValue=="function"?d.setFieldValue(E,O):typeof d.setFields=="function"?d.setFields([{name:E,value:O}]):(c=d.setFieldsValue)==null||c.call(d,{[E]:O}),import_lodash.default.set(this.valuesMirror,[E],O)}this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}const B=this.writeSeq;for(const E of k)this.lastWriteMetaByPathKey.set(E,F(B));if(g)for(const E of k)this.markExplicit(E);if(p){const E=this.getFormValuesSnapshot();this.emitFormValuesChange(y({source:m,txId:h,changedPaths:k.map(M=>[M]),changedValues:w,allValues:E,allValuesSnapshot:E}))}return}const S=new Map;let P=0;for(const D of o){const w=D==null?void 0:D.condition;if(w&&!evaluateCondition(t,w))continue;const k=this.resolveNamePath(t,D.path),B=namePathToPathKey(k),E=D.value,M=(0,import_reactive.isObservable)(E)?(0,import_reactive.toJS)(E):E;if(b(B))continue;const O=this.getFormValueAtPath(k);import_lodash.default.isEqual(O,M)||(P+=1,S.set(B,{order:P,namePath:k,value:M,rawValue:E,pathKey:B}))}const j=Array.from(S.values()).sort((D,w)=>D.order-w.order).map(D=>({namePath:D.namePath,value:D.value,rawValue:D.rawValue,pathKey:D.pathKey}));if(!j.length)return;const A=this.txWriteCounts.get(h)||new Map;this.txWriteCounts.set(h,A);const T=[];for(const D of j){const w=(A.get(D.pathKey)||0)+1;A.set(D.pathKey,w),!(w>MAX_WRITES_PER_PATH_PER_TX)&&T.push(D)}if(!T.length)return;this.writeSeq+=1;const N=this.writeSeq;for(const{pathKey:D,rawValue:w}of T)if(!(0,import_reactive.isObservable)(w)){const k=this.observableBindings.get(D);k&&(k.dispose(),this.observableBindings.delete(D))}this.suppressFormCallbackDepth++;try{for(const{namePath:D,value:w}of T)(u=d.setFieldValue)==null||u.call(d,D,w),import_lodash.default.set(this.valuesMirror,D,w),C.push(D);this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}for(const{pathKey:D}of T)this.lastWriteMetaByPathKey.set(D,F(N));if(g)for(const{pathKey:D}of T)this.markExplicit(D);if(m==="default")for(const{namePath:D,pathKey:w}of T){const k=this.getFormValueAtPath(D);this.lastDefaultValueByPathKey.set(w,k)}for(const{namePath:D,rawValue:w,pathKey:k}of T){if(!(0,import_reactive.isObservable)(w))continue;const B=w,E=(0,import_reactive.observe)(B,()=>{this.applyBoundValue(t,D,k,(0,import_reactive.toJS)(B),m,_,v)}),M=this.observableBindings.get(k);M&&M.dispose(),this.observableBindings.set(k,{source:m,dispose:E})}if(p){const D=this.getFormValuesSnapshot();this.emitFormValuesChange(y({source:m,txId:h,changedPaths:C,changedValues:{},allValues:D,allValuesSnapshot:D}))}}finally{f&&this.txWriteCounts.delete(h)}})}applyBoundValue(t,o,r,i,n,l,a){var c,u;if(this.disposed)return;const d=(c=this.getForm)==null?void 0:c.call(this);if(!d)return;const m=import_lodash.default.get(this.valuesMirror,o);if(import_lodash.default.isEqual(m,i))return;this.writeSeq+=1;const p=this.writeSeq;this.suppressFormCallbackDepth++;try{(u=d.setFieldValue)==null||u.call(d,o,i),import_lodash.default.set(this.valuesMirror,o,i),this.bumpChangeTick()}finally{this.suppressFormCallbackDepth--}const h=n==="linkage"?{source:n,writeSeq:p,linkageScopeDepth:Number.isFinite(Number(l))?Number(l):0,linkageTxId:typeof a=="string"&&a?a:void 0}:{source:n,writeSeq:p};this.lastWriteMetaByPathKey.set(r,h);const g=createTxId(),f=this.getFormValuesSnapshot(),_={source:n,txId:g,changedPaths:[o],changedValues:{},allValues:f,allValuesSnapshot:f};if(n==="linkage"&&a&&(_.linkageTxId=a),this.emitFormValuesChange(_),n==="default"&&this.isExplicit(r)){const v=this.observableBindings.get(r);v&&(v.dispose(),this.observableBindings.delete(r))}n==="default"&&this.lastDefaultValueByPathKey.set(r,this.getFormValueAtPath(o))}resolveNamePath(t,o){const r=this.tryResolveNamePath(t,o);if(!r)throw new Error(`Failed to resolve path '${String(o)}'`);return r}tryResolveNamePath(t,o){var r,i,n;const l=(n=(i=(r=t==null?void 0:t.model)==null?void 0:r.context)==null?void 0:i.fieldIndex)!=null?n:t==null?void 0:t.fieldIndex;return resolveDynamicNamePath(o,l)}bumpChangeTick(){this.changeTick.value+=1}emitFormValuesChange(t){var o,r,i,n;(r=(o=this.model).dispatchEvent)==null||r.call(o,"formValuesChange",t,{debounce:!0}),(n=(i=this.model.emitter)==null?void 0:i.emit)==null||n.call(i,"formValuesChange",t)}markExplicit(t){if(!this.explicitSet.has(t)){this.explicitSet.add(t);for(const o of Array.from(this.lastDefaultValueByPathKey.keys()))(o===t||o.startsWith(`${t}.`)||o.startsWith(`${t}[`))&&this.lastDefaultValueByPathKey.delete(o);for(const[o,r]of Array.from(this.observableBindings.entries()))r.source==="default"&&this.isExplicit(o)&&(r.dispose(),this.observableBindings.delete(o))}}isExplicit(t){return!!this.findExplicitHit(t)}findExplicitHit(t){if(this.explicitSet.has(t))return t;const o=pathKeyToNamePath(t),r=[];for(let i=0;i<o.length;i++){r.push(o[i]);const n=namePathToPathKey(r);if(!(!this.explicitSet.has(n)||typeof o[i+1]=="number"))return n}return null}}function collectUpdateAssociationValuesFromAssignRules(e,t){const o=Array.isArray(e)?e:[],r=new Set,i=n=>{var l,a,c,u,d;if(!t||typeof t.getField!="function"||typeof n!="string"||!n.includes("."))return null;const m=n.split(".").filter(Boolean);if(m.length<2)return null;let p=t;const h=[];let g=null,f=null;for(let _=0;_<m.length-1;_++){const v=m[_],b=(l=p==null?void 0:p.getField)==null?void 0:l.call(p,v);if(!((a=b==null?void 0:b.isAssociationField)!=null&&a.call(b))||!(b!=null&&b.targetCollection))break;h.push(v),g=h.join("."),f=b,p=b.targetCollection}if(g&&f){const _=m[m.length-1],v=(d=(u=f==null?void 0:f.targetKey)!=null?u:(c=f==null?void 0:f.targetCollection)==null?void 0:c.filterTargetKey)!=null?d:"id",b=Array.isArray(v)?v.filter(F=>typeof F=="string"&&!!F):typeof v=="string"&&v?[v]:["id"];if(typeof _=="string"&&b.includes(_))return null}return g};for(const n of o){const l=n!=null&&n.targetPath?String(n.targetPath):"";if(!l)continue;const a=i(l);a&&r.add(a)}return Array.from(r)}function createEmptyCondition(){return{logic:"$and",items:[]}}function getPropsInitialValue(e){if(!e)return;const t=typeof e.getProps=="function"?e.getProps():e.props;if(t&&typeof t.initialValue<"u")return t.initialValue}function getStepParamsInitialValue(e,t){var o,r;if(e)return(r=(o=e.getStepParams)==null?void 0:o.call(e,t,"initialValue"))==null?void 0:r.defaultValue}function createLegacyValueExtractor(e){return t=>{if(!t)return;const o=getPropsInitialValue(t);if(typeof o<"u")return o;for(const r of e){const i=getStepParamsInitialValue(t,r);if(typeof i<"u")return i}}}function deleteStepParams(e,t,o){var r,i,n;if(!((r=e==null?void 0:e.stepParams)!=null&&r[t]))return;const l=e.stepParams[t];!l||typeof l!="object"||Object.prototype.hasOwnProperty.call(l,o)&&(delete l[o],import_lodash.default.isEmpty(l)&&delete e.stepParams[t],(n=(i=e.emitter)==null?void 0:i.emit)==null||n.call(i,"onStepParamsChanged"))}function createLegacyClearer(e){return t=>{var o;if(t){(o=t.setProps)==null||o.call(t,{initialValue:void 0}),t.props&&Object.prototype.hasOwnProperty.call(t.props,"initialValue")&&delete t.props.initialValue;for(const r of e)deleteStepParams(t,r,"initialValue")}}}function collectLegacyDefaultValueRules(e,t){var o,r,i,n,l;const a=(i=(r=(o=e==null?void 0:e.subModels)==null?void 0:o.grid)==null?void 0:r.subModels)==null?void 0:i.items,c=Array.isArray(a)?a:[],u=[];for(const d of c){const m=((l=(n=d==null?void 0:d.getStepParams)==null?void 0:n.call(d,"fieldSettings","init"))==null?void 0:l.fieldPath)||(d==null?void 0:d.fieldPath),p=m?String(m):"";if(!p)continue;const h=t(d);typeof h<"u"&&u.push({key:`legacy-default:${p}`,enable:!0,targetPath:p,mode:"default",condition:createEmptyCondition(),value:h})}return u}function mergeAssignRulesWithLegacyDefaults(e,t){var o,r;const i=Array.isArray(e)?e:[],n=Array.isArray(t)?t:[];if(!n.length)return i;const l=new Set;for(const u of i){if(!u||typeof u!="object")continue;const d=u.targetPath?String(u.targetPath):"";if(d){if(u.mode==="default"){l.add(d);continue}String((o=u.key)!=null?o:"").startsWith("legacy-default:")&&l.add(d)}}const a=new Set(i.map(u=>{var d;return String((d=u.key)!=null?d:"")})),c=[];for(const u of n){const d=u.targetPath?String(u.targetPath):"";if(!d||l.has(d))continue;const m=x({},u),p=String((r=m.key)!=null?r:"");p&&a.has(p)&&(m.key=`${p}:${d}`),c.push(m)}return c.length?[...i,...c]:i}function clearLegacyDefaultValues(e,t,o){var r,i,n;const l=(n=(i=(r=e==null?void 0:e.subModels)==null?void 0:r.grid)==null?void 0:i.subModels)==null?void 0:n.items,a=Array.isArray(l)?l:[],c=[];for(const u of a)typeof t(u)<"u"&&(o(u),c.push(u));return c}const FORM_FLOW_KEYS=["editItemSettings","formItemSettings"],getLegacyFieldInitialValue=createLegacyValueExtractor(FORM_FLOW_KEYS),clearLegacyFieldInitialValue=createLegacyClearer(FORM_FLOW_KEYS);function collectLegacyDefaultValueRulesFromFormModel(e){return collectLegacyDefaultValueRules(e,getLegacyFieldInitialValue)}function clearLegacyDefaultValuesFromFormModel(e){return clearLegacyDefaultValues(e,getLegacyFieldInitialValue,clearLegacyFieldInitialValue)}const GRID_DELEGATED_STEP_KEYS={formModelSettings:new Set(["layout","assignRules"]),eventSettings:new Set(["linkageRules"])},FLOW_KEEP_MOBILE_HORIZONTAL_CLASS="nb-flow-keep-mobile-horizontal",flowKeepMobileHorizontalClassName=import_css.css`
1829
1829
  &.${FLOW_KEEP_MOBILE_HORIZONTAL_CLASS} {
1830
1830
  @media (max-width: 575px) {
1831
1831
  .ant-form-item {
@@ -1844,7 +1844,7 @@ if (!ctx.record) {
1844
1844
  }
1845
1845
  }
1846
1846
  }
1847
- `;function isGridDelegatedStep(e,t){var o;return!!((o=GRID_DELEGATED_STEP_KEYS[e])!=null&&o.has(t))}class FormBlockModel extends CollectionBlockModel{constructor(){super(...arguments),R(this,"formValueRuntime"),R(this,"userModifiedTopLevelFields",new Set),R(this,"_defaultCustomModelClasses",{FormActionGroupModel:"FormActionGroupModel",FormItemModel:"FormItemModel",FormAssociationFieldGroupModel:"FormAssociationFieldGroupModel"}),R(this,"customModelClasses",{})}get form(){return this.context.form}syncRuntimeAssignRules(t="unknown"){var o,r,i;const n=this.getStepParams("formModelSettings","assignRules"),l=(n==null?void 0:n.value)||[];(r=(o=this.formValueRuntime)==null?void 0:o.syncAssignRules)==null||r.call(o,Array.isArray(l)?l:[]);const a=(i=this.context)==null?void 0:i.resource,c=collectUpdateAssociationValuesFromAssignRules(l,this.collection);a!=null&&a.addUpdateAssociationValues&&c.length&&a.addUpdateAssociationValues(c)}renderConfigureActions(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"actions",subModelBaseClass:this.getModelClassName("FormActionGroupModel"),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Actions")})})}setFieldsValue(t){const o=this.context;if(typeof o.setFormValues=="function"){o.setFormValues(t,{source:"system"}).catch(r=>{console.warn("[FormBlockModel] Failed to set form values via ctx.setFormValues",r)});return}this.form.setFieldsValue(t)}setFieldValue(t,o){const r=this.context;if(typeof r.setFormValue=="function"){r.setFormValue(t,o,{source:"system"}).catch(i=>{console.warn("[FormBlockModel] Failed to set form value via ctx.setFormValue",i)});return}this.form.setFieldValue(t,o)}markUserModifiedFields(t){if(!(!t||typeof t!="object")&&!Array.isArray(t))for(const o of Object.keys(t))o&&this.userModifiedTopLevelFields.add(o)}getUserModifiedFields(){return this.userModifiedTopLevelFields}resetUserModifiedFields(){this.userModifiedTopLevelFields.clear()}onDispatchEventStart(t,o,r){return L(this,null,function*(){var i;if(t==="beforeRender"){const n=this.subModels.grid;n&&(yield n.dispatchEvent("beforeRender",r,{useCache:o==null?void 0:o.useCache}))}yield(i=$e(FormBlockModel.prototype,this,"onDispatchEventStart"))==null?void 0:i.call(this,t,o,r)})}getStepParams(t,o){const r=this.subModels.grid;if(t&&o&&isGridDelegatedStep(t,o)&&r){const i=r.getStepParams(t,o);return typeof i<"u"?i:super.getStepParams(t,o)}if(t&&!o&&GRID_DELEGATED_STEP_KEYS[t]&&r){const i=super.getStepParams(t)||{},n=r.getStepParams(t)||{};for(const l of GRID_DELEGATED_STEP_KEYS[t])Object.prototype.hasOwnProperty.call(n,l)&&typeof n[l]<"u"&&(i[l]=n[l]);return i}return super.getStepParams(t,o)}setStepParams(t,o,r){const i=this.subModels.grid,n=(l,a)=>{const c=GRID_DELEGATED_STEP_KEYS[l];if(!c||!i)return a;const u={};for(const[d,m]of Object.entries(a))c.has(d)?i.setStepParams(l,d,m):u[d]=m;return u};if(typeof t=="string"&&typeof o=="string"&&r!==void 0){isGridDelegatedStep(t,o)&&i?i.setStepParams(t,o,r):super.setStepParams(t,o,r);return}if(typeof t=="string"&&typeof o=="object"&&o!==null){const l=n(t,o);Object.keys(l).length>0&&super.setStepParams(t,l);return}if(typeof t=="object"&&t!==null){const l={};for(const[a,c]of Object.entries(t)){if(typeof c!="object"||c===null){l[a]=c;continue}const u=n(a,c);Object.keys(u).length>0&&(l[a]=u)}Object.keys(l).length>0&&super.setStepParams(l)}}saveStepParams(){return L(this,null,function*(){return yield saveStepParamsWithSubModelsIfNeeded(this,()=>L(this,null,function*(){const t=yield $e(FormBlockModel.prototype,this,"saveStepParams").call(this),o=this.subModels.grid;return yield o==null?void 0:o.saveStepParams(),t}))})}createFormValuesMetaFactory(){return(0,import_flow_engine.createAssociationAwareObjectMetaFactory)(()=>this.collection,this.translate("Current form"),()=>{var t,o;return((o=(t=this.form)==null?void 0:t.getFieldsValue)==null?void 0:o.call(t))||{}})}useHooksBeforeRender(){const[t]=import_antd.Form.useForm();this.context.defineProperty("form",{get:()=>t}),this.formValueRuntime||(this.formValueRuntime=new FormValueRuntime({model:this,getForm:()=>this.context.form}));const o=this.formValueRuntime;o.mount();const r=this.createFormValuesMetaFactory();this.context.defineProperty("formValues",{get:()=>o.formValues,cache:!1,meta:r,resolveOnServer:i=>{var n,l,a,c,u,d,m,p,h,g,f,_,v,b,F;if(!i)return!1;const y=(C=>{const S=String(C||"").match(/^([^.[]+)/);return S==null?void 0:S[1]})(i);if(!y||!((l=(n=this.collection)==null?void 0:n.getField)!=null&&l.call(n,y)))return!1;if((()=>{var C,S,P,j,A;const T=(P=(S=(C=this.subModels.grid)==null?void 0:C.subModels)==null?void 0:S.items)!=null?P:[],N=new Set;for(const D of T){const w=(A=(j=D==null?void 0:D.getStepParams)==null?void 0:j.call(D,"fieldSettings","init"))==null?void 0:A.fieldPath,k=w==null?void 0:w.toString().split(".")[0];k&&N.add(k)}return N})().has(y)){const C=(c=(a=this.form)==null?void 0:a.getFieldValue)==null?void 0:c.call(a,y);if(C==null||Array.isArray(C)&&C.length===0)return!1;const S=o.getFormValuesSnapshot();return S&&typeof S=="object"&&typeof(0,import_shared2.getValuesByPath)(S,i)<"u"?!1:(0,import_flow_engine.createAssociationSubpathResolver)(()=>this.collection,()=>o.getFormValuesSnapshot())(i)}try{const C=(F=(f=(m=(d=(u=this.context)==null?void 0:u.resource)==null?void 0:d.getMeta)==null?void 0:m.call(d,"currentFilterByTk"))!=null?f:(g=(h=(p=this.context)==null?void 0:p.resource)==null?void 0:h.getFilterByTk)==null?void 0:g.call(h))!=null?F:(b=(_=this.collection)==null?void 0:_.getFilterByTK)==null?void 0:b.call(_,(v=this.context)==null?void 0:v.record);if(typeof C>"u"||C===null)return!1}catch{return!1}return!0},serverOnlyWhenContextParams:!0}),this.context.defineMethod("getFormValues",function(){return o.getFormValuesSnapshot()}),this.context.defineMethod("setFormValues",function(i,n){return o.setFormValues(this,i,n)}),this.context.defineMethod("setFormValue",function(i,n,l){return o.setFormValues(this,[{path:i,value:n}],l)})}onInit(t){super.onInit(t),this.emitter.on("onSubModelAdded",o=>{o===this.subModels.grid&&queueMicrotask(()=>this.syncRuntimeAssignRules("onSubModelAdded:grid"))}),this.context.defineProperty("record",{get:()=>this.getCurrentRecord(),cache:!1}),this.context.resource.on("saved",()=>{this.dispatchEvent("formSubmitSuccess",{})})}onMount(){var t;super.onMount(),(t=this.formValueRuntime)==null||t.mount({sync:!0}),this.syncRuntimeAssignRules("onMount"),setTimeout(()=>{this.applyFlow("eventSettings")},100)}onUnmount(){var t;(t=this.formValueRuntime)==null||t.dispose(),this.formValueRuntime=void 0,super.onUnmount()}getCurrentRecord(){return{}}renderComponent(){throw new Error("renderComponent method must be implemented in subclasses of FormModel")}}function FormComponent(e){var t=e,{model:o,children:r,layoutProps:i={},initialValues:n}=t,l=te(t,["model","children","layoutProps","initialValues"]),a,c,u,d;const m=!!((a=o==null?void 0:o.context)!=null&&a.isMobileLayout&&(i==null?void 0:i.layout)==="horizontal"),p=[l.className,m?FLOW_KEEP_MOBILE_HORIZONTAL_CLASS:"",m?flowKeepMobileHorizontalClassName:""].filter(Boolean).join(" ");return(0,import_jsx_runtime.jsx)(import_antd.Form,I(x(I(x({form:o.form,initialValues:((d=(u=(c=o.context)==null?void 0:c.view)==null?void 0:u.inputArgs)==null?void 0:d.formData)||o.context.record||n},(0,import_lodash.omit)(i,"labelWidth")),{labelCol:{style:{width:i==null?void 0:i.labelWidth}},onFieldsChange:h=>{const g=o.formValueRuntime;g&&g.handleFormFieldsChange(h)},onValuesChange:(h,g)=>{var f;(f=o.markUserModifiedFields)==null||f.call(o,h);const _=o.formValueRuntime;if(_){_.handleFormValuesChange(h,g);return}o.dispatchEvent("formValuesChange",{changedValues:h,allValues:g},{debounce:!0}),o.emitter.emit("formValuesChange",{changedValues:h,allValues:g})}}),l),{className:p||void 0,children:r}))}const getOuterHeight$1=e=>{if(!e)return 0;const t=e.getBoundingClientRect(),o=window.getComputedStyle(e),r=parseFloat(o.marginTop)||0,i=parseFloat(o.marginBottom)||0;return t.height+r+i},normalizeCssSize=e=>{if(!(e==null||e===""))return typeof e=="number"?`${e}px`:/^\d+(\.\d+)?$/.test(e)?`${e}px`:e},useFormGridHeight=({heightMode:e,containerRef:t,actionsRef:o,footerRef:r,deps:i=[]})=>{const[n,l]=(0,import_react2.useState)(),a=(0,import_react2.useCallback)(()=>{if(e!=="specifyValue"&&e!=="fullHeight"){l(h=>h===void 0?h:void 0);return}const c=t.current;if(!c)return;const u=c.getBoundingClientRect().height;if(!u)return;const d=getOuterHeight$1((o==null?void 0:o.current)||null),m=getOuterHeight$1((r==null?void 0:r.current)||null),p=Math.max(0,Math.floor(u-d-m));l(h=>h===p?h:p)},[e,t,o,r]);return(0,import_react2.useLayoutEffect)(()=>{a()},[a,...i]),(0,import_react2.useEffect)(()=>{if(!t.current||typeof ResizeObserver>"u")return;const c=t.current,u=(o==null?void 0:o.current)||null,d=(r==null?void 0:r.current)||null,m=new ResizeObserver(()=>a());return m.observe(c),u&&m.observe(u),d&&m.observe(d),()=>m.disconnect()},[a,t,o,r,...i]),n},FormBlockContent=({model:e,gridModel:t,layoutProps:o,onFinish:r,grid:i,actions:n,footer:l,heightMode:a,height:c})=>{var u,d;const m=(0,import_react2.useRef)(null),p=(0,import_react2.useRef)(null),h=(0,import_react2.useRef)(null),g=a==="specifyValue"||a==="fullHeight",f={paddingTop:(d=(u=e.context)==null?void 0:u.themeToken)==null?void 0:d.padding},_=(o==null?void 0:o.layout)==="horizontal"?normalizeCssSize(o==null?void 0:o.labelWidth):void 0;_&&(f.marginInlineStart=_);const v=useFormGridHeight({heightMode:a,containerRef:m,actionsRef:n?p:void 0,footerRef:l?h:void 0,deps:[c]});return(0,import_react2.useEffect)(()=>{var b;if(!t)return;const F=g?v:void 0;((b=t.props)==null?void 0:b.height)!==F&&t.setProps({height:F})},[t,v,g]),(0,import_jsx_runtime.jsx)(FormComponent,{model:e,layoutProps:o,onFinish:r,style:g?{display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:void 0,children:(0,import_jsx_runtime.jsxs)("div",{ref:m,style:g?{display:"flex",flexDirection:"column",minHeight:0,flex:1}:void 0,children:[i,n?(0,import_jsx_runtime.jsx)("div",{style:f,ref:p,children:n}):null,l?(0,import_jsx_runtime.jsx)("div",{ref:h,children:l}):null]})})};FormBlockModel.define({hide:!0});FormBlockModel.registerFlow({key:"formModelSettings",title:(0,import_flow_engine.tExpr)("Form settings"),steps:{layout:{use:"layout",title:(0,import_flow_engine.tExpr)("Layout")},assignRules:{use:"formAssignRules",title:(0,import_flow_engine.tExpr)("Field values"),beforeParamsSave(e){const t=clearLegacyDefaultValuesFromFormModel(e.model);Array.isArray(t)&&t.length&&markSaveStepParamsWithSubModels(e.model)},afterParamsSave(e){var t,o,r,i,n,l;const a=e.model.getStepParams("formModelSettings","assignRules"),c=(a==null?void 0:a.value)||[];(r=(o=(t=e.model)==null?void 0:t.formValueRuntime)==null?void 0:o.syncAssignRules)==null||r.call(o,Array.isArray(c)?c:[]);const u=(n=(i=e.model)==null?void 0:i.context)==null?void 0:n.resource,d=collectUpdateAssociationValuesFromAssignRules(c,(l=e.model)==null?void 0:l.collection);u!=null&&u.addUpdateAssociationValues&&d.length&&u.addUpdateAssociationValues(d)}}}});FormBlockModel.registerFlow({key:"eventSettings",title:(0,import_flow_engine.tExpr)("Event settings"),on:"formValuesChange",steps:{linkageRules:{use:"fieldLinkageRules",afterParamsSave(e){var t;e.model.applyFlow("eventSettings",{changedValues:{},allValues:(t=e.form)==null?void 0:t.getFieldsValue(!0)})}}}});FormBlockModel.registerEvents({formValuesChange:{title:(0,import_flow_engine.tExpr)("Form values change"),name:"formValuesChange",uiSchema:{condition:{type:"object",title:(0,import_flow_engine.tExpr)("Trigger condition"),"x-decorator":"FormItem","x-component":ConditionBuilder}},handler:commonConditionHandler}});class FormModel extends FormBlockModel{}FormModel.define({hide:!0});class AssignFormModel extends FormBlockModel{useHooksBeforeRender(){const[t]=import_antd.Form.useForm();this.context.defineProperty("form",{get:()=>t})}onInit(t){super.onInit(t);const o=(0,import_flow_engine.createCurrentRecordMetaFactory)(this.context,()=>this.collection);this.context.defineProperty("record",{get:()=>{var r;return(r=this.getCurrentRecord)==null?void 0:r.call(this)},cache:!1,resolveOnServer:(0,import_flow_engine.createRecordResolveOnServerWithLocal)(()=>this.collection,()=>{var r;return(r=this.getCurrentRecord)==null?void 0:r.call(this)}),meta:o}),this.context.defineProperty("filterManager",{once:!0,get:()=>new FilterManager(this,t==null?void 0:t.filterManager)}),this.isManualRefresh=!0}createResource(t,o){const r=this.context.createResource(import_flow_engine.SingleRecordResource);return r.isNewRecord=!0,r}renderComponent(){var t;const{colon:o,labelAlign:r,labelWidth:i,labelWrap:n,layout:l}=this.props;return(0,import_jsx_runtime.jsx)(FormComponent,{model:this,layoutProps:{colon:o,labelAlign:r,labelWidth:i,labelWrap:n,layout:l},children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels)==null?void 0:t.grid,showFlowSettings:!1})})}setInitialAssignedValues(t){var o;const r=(o=this.subModels)==null?void 0:o.grid;Object.entries(t||{}).forEach(([i,n])=>{r.addOrEnsureItem(i,n)})}getAssignedValues(){return this.subModels.grid.getAssignedValues()||{}}}AssignFormModel.define({label:(0,import_flow_engine.tExpr)("Field assignments"),hide:!0,createModelOptions:{use:"AssignFormModel",subModels:{grid:{use:"AssignFormGridModel"}}}});class FormGridModel extends GridModel{constructor(){super(...arguments),R(this,"itemFallback",(0,import_jsx_runtime.jsx)(import_antd.Skeleton.Input,{block:!0,size:"small",style:{marginBottom:"0.5rem"}})),R(this,"itemSettingsMenuLevel",2),R(this,"itemFlowSettings",{showBackground:!0,style:{top:-6,left:-6,right:-6,bottom:-6}}),R(this,"dragOverlayConfig",{columnInsert:{before:{offsetTop:-12,height:24},after:{offsetTop:7,height:24}},columnEdge:{left:{offsetLeft:-5,width:24},right:{offsetLeft:8,width:24}},rowGap:{above:{offsetTop:0,height:24},below:{offsetTop:-14,height:24}}})}renderAddSubModelButton(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{subModelKey:"items",subModelBaseClasses:[this.context.getModelClassName("FormItemModel"),this.context.getModelClassName("FormAssociationFieldGroupModel"),this.context.getModelClassName("FormCustomItemModel"),this.context.getModelClassName("FormJSFieldItemModel")].filter(Boolean),model:this,keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})})}render(){var t,o;const r=(t=this.props)==null?void 0:t.height,i=(o=this.props)==null?void 0:o.heightModel,n=this.context.themeToken,l=super.render();return i==="defaultHeight"?l:(0,import_jsx_runtime.jsx)("div",{style:{height:r,overflowY:"auto",marginLeft:`-${n.marginLG}px`,marginRight:`-${n.marginLG}px`,paddingLeft:`${n.marginLG}px`,paddingRight:`${n.marginLG}px`,paddingTop:5},children:l})}}FormGridModel.registerFlow({key:"formFieldGridSettings",steps:{grid:{handler(e,t){e.model.setProps("rowGap",0),e.model.setProps("colGap",16)}}}});class AssignFormGridModel extends FormGridModel{renderAddSubModelButton(){var t,o;const r=(t=this.context)==null?void 0:t.collection,i=((o=r==null?void 0:r.getFields)==null?void 0:o.call(r))||[],n=typeof(r==null?void 0:r.getPrimaryKey)=="function"?r.getPrimaryKey():void 0,l=r==null?void 0:r.filterTargetKey,a=u=>u?!!(n&&u===n||typeof l=="string"&&u===l||Array.isArray(l)&&l.includes(u)):!1,c=i.filter(u=>!a(u==null?void 0:u.name)).map(u=>{const d=u.name,m=u.title||u.name,p=import_flow_engine.EditableItemModel.getDefaultBindingByField(this.context,u);if(!p)return;const h=p.modelName;return{key:d,label:m,toggleable:g=>{const f=g.getStepParams("fieldSettings","init")||{};return(f==null?void 0:f.fieldPath)===d},useModel:"AssignFormItemModel",createModelOptions:()=>({use:"AssignFormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:r==null?void 0:r.dataSourceKey,collectionName:r==null?void 0:r.name,fieldPath:d}}},subModels:{field:{use:h,stepParams:{fieldSettings:{init:{dataSourceKey:r==null?void 0:r.dataSourceKey,collectionName:r==null?void 0:r.name,fieldPath:d}}}}}})}}).filter(Boolean);return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{subModelKey:"items",model:this,items:c,keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})})}addOrEnsureItem(t,o){var r,i,n;const l=(r=this.context)==null?void 0:r.collection,a=(((i=this.subModels)==null?void 0:i.items)||[]).find(p=>{try{const h=typeof(p==null?void 0:p.getStepParams)=="function"?p.getStepParams("fieldSettings","init"):null;return(h==null?void 0:h.fieldPath)===t}catch{return!1}});if(a){typeof(a==null?void 0:a.setStepParams)=="function"&&a.setStepParams("fieldSettings","assignValue",{value:o}),a.assignValue=o;return}const c=(((n=l==null?void 0:l.getFields)==null?void 0:n.call(l))||[]).find(p=>p.name===t),u=import_flow_engine.EditableItemModel.getDefaultBindingByField(this.context,c);if(!u)return;const d=u.modelName,m=this.flowEngine.createModel({use:"AssignFormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:l==null?void 0:l.dataSourceKey,collectionName:l==null?void 0:l.name,fieldPath:t},assignValue:{value:o}}},subModels:{field:{use:d,stepParams:{fieldSettings:{init:{dataSourceKey:l==null?void 0:l.dataSourceKey,collectionName:l==null?void 0:l.name,fieldPath:t}}}}},parentId:this.uid,subKey:"items"});m.assignValue=o}getAssignedValues(){var t;const o=((t=this.subModels)==null?void 0:t.items)||[],r={};for(const i of o){const n=typeof i.getAssignedEntry=="function"?i.getAssignedEntry():null;n&&Array.isArray(n)&&(r[n[0]]=n[1])}return r}}AssignFormGridModel.define({label:(0,import_flow_engine.tExpr)("Assign grid")});function getFieldBindingUse(e){var t,o;const r=(o=(t=e==null?void 0:e.stepParams)==null?void 0:t.fieldBinding)==null?void 0:o.use;return typeof r=="string"?r:void 0}function rebuildFieldSubModel(e){return L(this,arguments,function*({parentModel:t,targetUse:o,defaultProps:r,pattern:i,fieldSettingsInit:n}){var l,a,c;const u=t.subModels.field,d=u==null?void 0:u.uid,m=(a=(l=u==null?void 0:u.serialize)==null?void 0:l.call(u))==null?void 0:a.subModels;for(const _ in m)m[_].delegateToParent===!1&&delete m[_];const p=(u==null?void 0:u.stepParams)||{},h=n??((c=t.getFieldSettingsInitParams)==null?void 0:c.call(t)),g=I(x({},p),{fieldBinding:I(x({},p.fieldBinding),{use:o}),fieldSettings:{init:h}}),f=t.flowEngine;d&&(u==null||u.invalidateFlowCache("beforeRender",!0),f.removeModelWithSubModels(d)),yield t.setSubModel("field",{uid:d,use:FieldModel,props:x(x({},r||{}),i?{pattern:i}:{}),stepParams:g,subModels:m}).dispatchEvent("beforeRender",void 0,{useCache:!1}),yield t.save()})}function getValueWithIndex(e,t,o){const r=(0,import_lodash.castArray)(o).filter(n=>typeof n=="string"),i=t.split(".");if(r!=null&&r.length){const n=[];let l=0,a=0;for(;l<i.length;){const c=i[l];if(n.push(c),a<r.length){const[u,d]=r[a].split(":");u===c&&(n.push(Number(d)),a++)}l++}return(0,import_lodash.get)(e,n)}return(0,import_lodash.get)(e,i)}function getDetailsItemValue(e){const{record:t,currentObject:o,fieldPath:r,prefixFieldPath:i,idx:n}=e,l=getValueWithIndex(t,r,n);if(l!==void 0||o==null)return l;if(i&&r===i)return o;const a=i&&r.startsWith(`${i}.`)?r.slice(i.length+1):r;return a?(0,import_lodash.get)(o,a):o}function normalizeDetailsAssociationValue(e,t){return!isToManyAssociationField(e)||Array.isArray(t)?t:t&&typeof t=="object"&&Array.isArray(t.rows)?t.rows:t==null?[]:[t]}class DetailsItemModel extends import_flow_engine.DisplayItemModel{static defineChildren(t){const o=t.collection;return o.getFields().map(r=>{const i=this.getDefaultBindingByField(t,r,{fallbackToTargetTitleField:!0});if(!i)return null;const n=i.modelName,l=t.prefixFieldPath?`${t.prefixFieldPath}.${r.name}`:r.name;return{key:l,label:r.title,refreshTargets:["DetailsCustomItemModel/DetailsJSFieldItemModel"],toggleable:a=>{var c;return((c=a.getStepParams("fieldSettings","init"))==null?void 0:c.fieldPath)===l},useModel:"DetailsItemModel",createModelOptions:()=>({use:"DetailsItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:o.dataSourceKey,collectionName:t.model.context.blockModel.collection.name,fieldPath:l}}},subModels:{field:{use:n,props:typeof i.defaultProps=="function"?i.defaultProps(t,r):i.defaultProps}}})}}).filter(Boolean)}onInit(t){super.onInit(t),this.context.defineProperty("actionName",{get:()=>"view",cache:!1})}renderItem(){const t=this.subModels.field,o=this.context.fieldIndex,r=this.context.record,i=this.context.currentObject,n=this.context.item,l=this.context.getPropertyOptions("item"),a=this.context.prefixFieldPath,c=o!=null?(()=>{const m=t.createFork({},`${o}`);m.context.defineProperty("fieldIndex",{get:()=>o}),m.context.defineProperty("record",{get:()=>r,cache:!1}),m.context.defineProperty("currentObject",{get:()=>i,cache:!1});const p=l||{},h=te(p,["value"]);return m.context.defineProperty("item",I(x({},h),{get:()=>n,cache:!1})),this.context.pattern&&m.context.defineProperty("pattern",{get:()=>this.context.pattern}),m})():t,u=this.context.pattern?I(x(x({},this.context.blockModel.props),this.props),{pattern:this.context.pattern,disabled:this.context.pattern==="readPretty"}):x(x({},this.context.blockModel.props),this.props),d=normalizeDetailsAssociationValue(this.collectionField,getDetailsItemValue({record:r,currentObject:i,fieldPath:this.fieldPath,prefixFieldPath:a,idx:o}));return(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},u),{value:d,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FieldModelRenderer,{model:c})}))}}DetailsItemModel.define({label:(0,import_flow_engine.tExpr)("Display fields"),sort:100});DetailsItemModel.registerFlow({key:"detailItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Detail item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({title:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>{var t;return{title:(t=e.collectionField)==null?void 0:t.title}},handler(e,t){var o;const r={ns:"lm-flow-engine",compareWith:(o=e.collectionField)==null?void 0:o.title};e.model.setProps({label:e.t(t.title,r)})}},aclCheck:{use:"aclCheck"},init:{handler(e){return L(this,null,function*(){const{collectionField:t}=e.model;t&&e.model.setProps(t.getComponentProps())})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},model:{title:(0,import_flow_engine.tExpr)("Field component"),use:"displayFieldComponent"},fieldNames:{use:"titleField",title:(0,import_flow_engine.tExpr)("Title field"),beforeParamsSave:(e,t,o)=>L(void 0,null,function*(){var r,i;if(!e.collectionField||!e.collectionField.isAssociationField())return null;if(t.label!==o.label){e.model.setProps(x({titleField:t.label},(i=(r=e.collectionField.targetCollection)==null?void 0:r.getField(t.label))==null?void 0:i.getComponentProps()));const n=e.collectionField.targetCollection.getField(t.label),l=import_flow_engine.DisplayItemModel.getDefaultBindingByField(e,n),a=l.modelName;yield rebuildFieldSubModel({parentModel:e.model,targetUse:a,defaultProps:typeof(l==null?void 0:l.defaultProps)=="function"?l.defaultProps(e,e.collectionField):l==null?void 0:l.defaultProps,pattern:e.model.getProps().pattern})}}),handler(e,t){return L(this,null,function*(){var o,r;if(!e.collectionField||e.model.subModels.field.disableTitleField)return;e.model.setProps(x({titleField:t.label},(r=(o=e.collectionField.targetCollection)==null?void 0:o.getField(t.label))==null?void 0:r.getComponentProps()));const i=e.collectionField.targetCollection;if(i){const n=i.getField(t.label),l=import_flow_engine.DisplayItemModel.getDefaultBindingByField(e,n).modelName,a=e.model.subModels.field.use;l!==a&&e.model.setStepParams(e.flowKey,"model",{use:l})}})},hideInSettings:e=>L(void 0,null,function*(){return!e.collectionField||!e.collectionField.isAssociationField()||e.model.subModels.field.disableTitleField})}}});DetailsItemModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{aclCheckRefresh:{use:"aclCheckRefresh"}}});function isInSameBlock(e,t){var o,r;const i=(r=(o=e==null?void 0:e.context)==null?void 0:o.blockModel)==null?void 0:r.uid,n=t==null?void 0:t.uid;return!i||!n?!1:String(i)===String(n)}function tryGetModelTargetPathCandidate(e){var t,o;const r=(t=e==null?void 0:e.context)==null?void 0:t.fieldPathArray;if(Array.isArray(r)&&r.length)return r;try{const a=(o=e==null?void 0:e.getStepParams)==null?void 0:o.call(e,"fieldSettings","init"),c=a==null?void 0:a.fieldPath;if(typeof c=="string"&&c)return c}catch{}const i=e==null?void 0:e.fieldPath;if(typeof i=="string"&&i)return i;const n=typeof(e==null?void 0:e.getProps)=="function"?e.getProps():e==null?void 0:e.props,l=n==null?void 0:n.name;return typeof l=="string"&&l||Array.isArray(l)&&l.length?l:null}function normalizeResolvedNamePath(e){return!Array.isArray(e)||!e.length||typeof e[0]!="string"?null:e}function resolveModelNamePath(e){var t;const o=tryGetModelTargetPathCandidate(e);if(!o)return null;const r=resolveDynamicNamePath(o,(t=e==null?void 0:e.context)==null?void 0:t.fieldIndex);return normalizeResolvedNamePath(r)}function cleanupEmptyPlainObjectAncestors(e,t){if(!(!e||typeof e!="object")&&!(!Array.isArray(t)||t.length<2))for(let o=t.length-1;o>=1;o--){const r=t.slice(0,o);if(typeof r[r.length-1]=="number")continue;const i=import_lodash.default.get(e,r);import_lodash.default.isPlainObject(i)&&Object.keys(i).length===0&&import_lodash.default.unset(e,r)}}function forEachModelIncludingForks(e,t){e!=null&&e.forEachModel&&e.forEachModel(o=>{t(o);const r=o==null?void 0:o.forks;r&&typeof r.forEach=="function"&&r.forEach(i=>t(i))})}function collectHiddenModelNamePaths(e){const t=e==null?void 0:e.flowEngine;if(!(t!=null&&t.forEachModel))return[];const o=[],r=new Set;return forEachModelIncludingForks(t,i=>{if(!i||typeof i!="object"||!i.hidden||!isInSameBlock(i,e))return;const n=resolveModelNamePath(i);if(!n)return;const l=JSON.stringify(n);r.has(l)||(r.add(l),o.push(n))}),o}function normalizeFormNamePath(e){return typeof e=="string"?e?[e]:null:Array.isArray(e)?normalizeResolvedNamePath(e):null}function isNamePathPrefix(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length>t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}function getValidationNamePathsExcludingHiddenModels(e){const t=e==null?void 0:e.form;if(!t||typeof t.getFieldsError!="function")return null;const o=t.getFieldsError();if(!Array.isArray(o))return null;const r=[],i=new Set;for(const l of o){const a=normalizeFormNamePath(l==null?void 0:l.name);if(!a)continue;const c=JSON.stringify(a);i.has(c)||(i.add(c),r.push(a))}if(!r.length)return null;const n=collectHiddenModelNamePaths(e);return n.length?r.filter(l=>!n.some(a=>isNamePathPrefix(a,l))):r}function shouldSkipSubmitValidation(e){var t,o;return((o=(t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"submitSettings","skipRequiredValidation"))==null?void 0:o.skipValidator)===!0}function validateSubmitForm(e){return L(this,null,function*(){const{form:t,blockModel:o,flowSettingsEnabled:r,skipValidator:i}=e;if(i||!t||typeof t.validateFields!="function")return;const n=r&&o?getValidationNamePathsExcludingHiddenModels(o):null;if(Array.isArray(n)){n.length&&(yield t.validateFields(n));return}yield t.validateFields()})}function omitHiddenModelValuesFromSubmit(e,t){if(!e||typeof e!="object")return e;const o=collectHiddenModelNamePaths(t);if(!o.length)return e;const r=import_lodash.default.cloneDeep(e);for(const i of o)import_lodash.default.unset(r,i),cleanupEmptyPlainObjectAncestors(r,i);return r}function submitHandler(e,t,o){return L(this,null,function*(){var r,i,n;const l=e.resource,a=e.blockModel;yield validateSubmitForm({form:a==null?void 0:a.form,blockModel:a,flowSettingsEnabled:e==null?void 0:e.flowSettingsEnabled,skipValidator:shouldSkipSubmitValidation(e==null?void 0:e.model)});const c=a.form.getFieldsValue(!0),u=omitHiddenModelValuesFromSubmit(c,a);if(l instanceof import_flow_engine.SingleRecordResource){if(a instanceof EditFormModel){const m=l.getMeta("currentFilterByTk");m?l.setFilterByTk(m):l.isNewRecord=!0}const d=o?yield o(u):yield l.save(u,t.requestConfig);a instanceof EditFormModel?(l.isNewRecord=!1,(r=a.resetUserModifiedFields)==null||r.call(a),yield l.refresh()):(a.form.resetFields(),a.emitter.emit("onFieldReset"),(i=a.resetUserModifiedFields)==null||i.call(a),e.view.inputArgs.collectionName===a.collection.name&&e.view.inputArgs.onChange&&e.view.inputArgs.onChange(d==null?void 0:d.data))}else if(l instanceof import_flow_engine.MultiRecordResource){const d=l.getMeta("currentFilterByTk");if(!d){e.message.error(e.t("No filterByTk found for multi-record resource."));return}(yield o)?yield o(u,d):yield l.update(d,u,t.requestConfig),(n=a.resetUserModifiedFields)==null||n.call(a)}})}class EditFormModel extends FormBlockModel{constructor(){super(...arguments),R(this,"actionFlowSettings",{showBackground:!1,showBorder:!1,toolbarPosition:"above"}),R(this,"actionExtraToolbarItems",[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]),R(this,"handlePageChange",t=>L(this,null,function*(){if(this.resource instanceof import_flow_engine.MultiRecordResource){const o=this.resource;o.setPage(t),o.loading=!0,yield o.refresh(),yield dispatchEventDeep(this,"paginationChange")}}))}createResource(t,o){var r,i;if(((r=this.association)==null?void 0:r.type)==="hasOne"||((i=this.association)==null?void 0:i.type)==="belongsTo"){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}if(Object.keys(o).includes("filterByTk")){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}const n=this.context.createResource(import_flow_engine.MultiRecordResource);return n.setPageSize(1),n}isMultiRecordResource(){return this.resource instanceof import_flow_engine.MultiRecordResource}getCurrentRecord(){const t=this.resource.getData();return Array.isArray(t)?t[0]:t}hasAvailableData(){return this.resource.hasData()}getAclActionName(){return"update"}submitHandler(t,o,r){return L(this,null,function*(){yield submitHandler(t,o,r)})}submit(){return L(this,arguments,function*(t={},o){yield submitHandler(this.context,t,o)})}renderComponent(){var t,o;const{colon:r,labelAlign:i,labelWidth:n,labelWrap:l,layout:a}=this.props,c=!!this.context.flowSettingsEnabled,u=this.hasAvailableData(),d=!c&&!u,{heightMode:m,height:p}=this.decoratorProps,h=!this.resource.loading&&!u?(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",marginTop:16,color:(o=(t=this.context)==null?void 0:t.themeToken)==null?void 0:o.colorTextDescription},children:this.translate("No available data currently")}):this.isMultiRecordResource()&&this.resource.getMeta("count")>1?(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",marginTop:16},children:(0,import_jsx_runtime.jsx)(import_antd.Pagination,{simple:!0,pageSize:1,showSizeChanger:!1,defaultCurrent:this.resource.getPage(),total:this.resource.getTotalPage(),onChange:this.handlePageChange,style:{display:"inline-block"}})}):null;return(0,import_jsx_runtime.jsx)(FormBlockContent,{model:this,gridModel:this.subModels.grid,layoutProps:{colon:r,labelAlign:i,labelWidth:n,labelWrap:l,layout:a},heightMode:m,height:p,grid:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:this.subModels.grid,showFlowSettings:!1}),actions:(0,import_jsx_runtime.jsx)("div",{style:d?{pointerEvents:"none",opacity:.45}:void 0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{children:(0,import_jsx_runtime.jsxs)(import_antd.Space,{wrap:!0,children:[this.mapSubModels("actions",g=>{if(!(g.hidden&&!c))return(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:g,children:(0,import_jsx_runtime.jsx)(import_flow_engine.MemoFlowModelRenderer,{model:g,showFlowSettings:this.context.flowSettingsEnabled?this.actionFlowSettings:!1,extraToolbarItems:this.actionExtraToolbarItems},g.uid)},g.uid)}),this.renderConfigureActions()]})})}),footer:h})}}R(EditFormModel,"scene",BlockSceneEnum.oam),R(EditFormModel,"blockCapabilityActionName","update");EditFormModel.registerFlow({key:"formSettings",title:(0,import_flow_engine.tExpr)("Edit form settings"),steps:{init:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized");e.resource.on("refresh",()=>L(this,null,function*(){var t,o,r,i,n,l;const a=e.resource.getMeta("currentFilterByTk"),c=x({},e.model.getCurrentRecord());if(!c)return;const u=(t=e.association)==null?void 0:t.targetKey;if(u&&((o=e.association)==null?void 0:o.interface)!=="m2m"?e.resource.setMeta({currentFilterByTk:c==null?void 0:c[u]}):e.resource.setMeta({currentFilterByTk:e.collection.getFilterByTK(c)}),!e.form)return;const d=e.resource.getMeta("currentFilterByTk"),m=!(0,import_lodash.isEqual)(a,d),p=(i=(r=e.model).getUserModifiedFields)==null?void 0:i.call(r),h=!!(p!=null&&p.size),g=()=>{if(!(p!=null&&p.size))return;const f=_=>_!==null&&typeof _=="object";for(const _ of Array.from(p)){const v=e.form.getFieldValue(_),b=c==null?void 0:c[_];(Object.is(v,b)||f(v)&&f(b)&&(0,import_lodash.isEqual)(v,b))&&p.delete(_)}};if(!m&&h){const f=x({},c);for(const _ of p)f[_]=e.form.getFieldValue(_);e.form.setFieldsValue(f),g();return}m&&((l=(n=e.model).resetUserModifiedFields)==null||l.call(n)),e.form.setFieldsValue(c),g()}))})}},dataScope:{use:"dataScope"},refresh:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized")})}}}});EditFormModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{blockLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"blockLinkageRules",flowKey:"cardSettings",stepKey:"linkageRules"}},fieldsLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"fieldLinkageRules",flowKey:"eventSettings",stepKey:"linkageRules"}}}});EditFormModel.define({label:(0,import_flow_engine.tExpr)("Form (Edit)"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),createModelOptions:{use:"EditFormModel",subModels:{grid:{use:"FormGridModel"}}},sort:340});function isToManyAssociation(e){if(!e)return!1;const t=e==null?void 0:e.type;return t==="belongsToMany"||t==="hasMany"||t==="belongsToArray"}function coerceForToOneField(e,t){var o;const r=!!((o=e==null?void 0:e.isAssociationField)!=null&&o.call(e)),i=isToManyAssociation(e);return r&&!i&&Array.isArray(t)?t.length?t[0]:void 0:t}function buildDynamicNamePath(e,t){if(!(t!=null&&t.length))return e;const o=t[t.length-1],[r,i]=String(o).split(":"),n=Number(i);if(!r||!Number.isFinite(n))return e;let l=0;for(const u of t){const[d]=String(u).split(":");d===r&&(l+=1)}let a=-1,c=0;for(let u=0;u<e.length;u++)if(String(e[u])===r&&(c+=1,c===l)){a=u;break}if(a===-1){for(let u=e.length-1;u>=0;u--)if(String(e[u])===r){a=u;break}}return a===-1?e:[n,...e.slice(a+1)]}const interfacesOfUnsupportedDefaultValue=["o2o","oho","obo","o2m","attachment","expression","point","lineString","circle","polygon","sequence","formula"];class FormItemModel extends import_flow_engine.EditableItemModel{static defineChildren(t){const o=t.collection;return o.getFields().map(r=>{const i=this.getDefaultBindingByField(t,r);if(!i)return;const n=i.modelName,l=t.prefixFieldPath?`${t.prefixFieldPath}.${r.name}`:r.name;return{key:l,label:r.title,refreshTargets:["FormItemModel/FormJSFieldItemModel"],toggleable:a=>{var c;return((c=a.getStepParams("fieldSettings","init"))==null?void 0:c.fieldPath)===l},useModel:"FormItemModel",createModelOptions:()=>({use:"FormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:o.dataSourceKey,collectionName:t.model.context.blockModel.collection.name,fieldPath:l}}},subModels:{field:{use:n,props:typeof i.defaultProps=="function"?i.defaultProps(t,r):i.defaultProps}}})}}).filter(Boolean)}onInit(t){super.onInit(t),this.emitter.on("onSubModelAdded",o=>{if(this.collectionField){const r=this.collectionField.getComponentProps();o.setProps(r),this.setProps(x({},import_lodash.default.pick(r,"rules")||{}))}})}renderItem(){var t,o;const r=this.subModels.field,i=this.context.fieldIndex,n=this.context.fieldKey,l=((t=this.parent)==null?void 0:t.context.fieldPathArray)||[],a=i!=null?(()=>{const p=r.createFork({},`${n}`);p.context.defineProperty("fieldIndex",{get:()=>i}),p.context.defineProperty("fieldKey",{get:()=>n}),this.context.currentObject&&p.context.defineProperty("currentObject",{get:()=>this.context.currentObject});const h=this.context.getPropertyOptions("item");if(this.context.item){const g=h||{},f=te(g,["value"]);p.context.defineProperty("item",I(x({},f),{get:()=>this.context.item,cache:!1}))}return this.context.pattern&&p.context.defineProperty("pattern",{get:()=>this.context.pattern}),p})():r,c=this.context.pattern?I(x({},this.props),{pattern:this.context.pattern}):this.props,u=te(c,["initialValue"]),d=buildDynamicNamePath(this.props.name,i);this.context.defineProperty("fieldPathArray",{value:[...l,...import_lodash.default.castArray(d)]});const m=((o=this.context.item)==null?void 0:o.value)||this.context.record;return(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},u),{name:d,validateFirst:!0,disabled:this.props.disabled||!import_lodash.default.isEmpty(m)&&!m.__is_new__&&this.props.aclDisabled||!import_lodash.default.isEmpty(m)&&m.__is_new__&&this.props.aclCreateDisabled,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FieldModelRenderer,{model:a,name:d})}))}}FormItemModel.define({label:(0,import_flow_engine.tExpr)("Display fields"),sort:100});FormItemModel.registerFlow({key:"editItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Form item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({label:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>{var t;return{label:(t=e.collectionField)==null?void 0:t.title}},handler(e,t){var o;const r={ns:"lm-flow-engine",compareWith:(o=e.collectionField)==null?void 0:o.title};e.model.setProps({label:e.t(t.label,r)})}},aclCheck:{use:"aclCheck",handler(e,t){return L(this,null,function*(){var o,r,i,n,l,a,c,u,d,m,p,h,g,f,_;if(!e.collectionField||!e.blockModel)return;const v=e.blockModel.context.actionName,b=yield e.aclCheck({dataSourceKey:(o=e.dataSource)==null?void 0:o.key,resourceName:(r=e.collectionField)==null?void 0:r.collectionName,fields:[(i=e.collectionField)==null?void 0:i.name],actionName:v});if(v==="update"){const F=yield e.aclCheck({dataSourceKey:(n=e.dataSource)==null?void 0:n.key,resourceName:(l=e.collectionField)==null?void 0:l.collectionName,fields:[e.collectionField.name],actionName:"view"});e.prefixFieldPath&&e.item&&((yield e.aclCheck({dataSourceKey:(a=e.dataSource)==null?void 0:a.key,resourceName:(c=e.collectionField)==null?void 0:c.collectionName,fields:[e.collectionField.name],actionName:"create"}))||e.model.setProps({aclCreateDisabled:!0}));const y=(d=(u=e.item)==null?void 0:u.__is_new__)!=null?d:!1;!F&&!y&&(e.model.hidden=!0,e.model.forbidden={actionName:"view"},e.exitAll()),b||e.model.setProps({aclDisabled:!0})}else if(v==="create"){const F=yield e.aclCheck({dataSourceKey:(m=e.dataSource)==null?void 0:m.key,resourceName:(p=e.collectionField)==null?void 0:p.collectionName,actionName:"update"}),y=yield e.aclCheck({dataSourceKey:(h=e.dataSource)==null?void 0:h.key,resourceName:(g=e.collectionField)==null?void 0:g.collectionName,fields:[e.collectionField.name],actionName:"update"}),C=(_=(f=e.item)==null?void 0:f.__is_stored__)!=null?_:!1;!b&&!C&&(e.model.hidden=!0,e.model.forbidden={actionName:v},e.exitAll()),(!F||!y)&&e.model.setProps({aclDisabled:!0})}})}},init:{handler(e){return L(this,null,function*(){const t=e.model.fieldPath,o=t.includes(".")?t.split("."):t;e.model.setProps({name:o})})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem","x-component-props":{autoSize:!0}}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},initialValue:{title:(0,import_flow_engine.tExpr)("Default value"),disabledInSettings:!0,disabledReasonInSettings:e=>`${e.t("This setting has been moved to")}: ${e.t("Form block settings")} > ${e.t("Field values")}`,uiSchema:e=>{var t,o,r,i;if(e.model.parent.parent instanceof EditFormModel||(o=(t=e.model.subModels)==null?void 0:t.field)!=null&&o.updateAssociation)return;const n=(r=e.model.collectionField)==null?void 0:r.interface;if(!((i=interfacesOfUnsupportedDefaultValue==null?void 0:interfacesOfUnsupportedDefaultValue.includes)!=null&&i.call(interfacesOfUnsupportedDefaultValue,n)))return{defaultValue:{"x-component":"DefaultValue","x-decorator":"FormItem"}}},defaultParams:e=>{const t=e.model.collectionField;if(t.interface==="nanoid"&&t.options.autoFill!==!1){const{size:o,customAlphabet:r}=t.options||{size:21};return{defaultValue:(0,import_nanoid.customAlphabet)(r,o)()}}return{defaultValue:t.defaultValue}},handler(e,t){var o,r;const i=(o=e.model.collectionField)==null?void 0:o.interface;if((r=interfacesOfUnsupportedDefaultValue==null?void 0:interfacesOfUnsupportedDefaultValue.includes)!=null&&r.call(interfacesOfUnsupportedDefaultValue,i))return;const n=e.model.collectionField,l=coerceForToOneField(n,t.defaultValue);e.model.setProps({initialValue:l})}},validation:{title:(0,import_flow_engine.tExpr)("Validation"),use:"validation"},required:{title:(0,import_flow_engine.tExpr)("Required"),use:"required"},model:{use:"fieldComponent",title:(0,import_flow_engine.tExpr)("Field component")},pattern:{use:"pattern"},titleField:{use:"titleField",hideInSettings(e){return!e.collectionField||!e.collectionField.isAssociationField()||!(e.collectionField.isAssociationField()&&e.model.getProps().pattern==="readPretty")},defaultParams:e=>({titleField:e.model.props.titleField||e.model.context.collectionField.targetCollectionTitleFieldName}),beforeParamsSave:(e,t,o)=>L(void 0,null,function*(){if(!(e.collectionField.isAssociationField()&&e.model.getProps().pattern==="readPretty"))return null;const r=t.titleField||t.label;if(r!==o.titleField){const i=e.collectionField.targetCollection,n=i.getField(r),l=DetailsItemModel.getDefaultBindingByField(e,n);if(l.modelName!==e.model.subModels.field.use){const a=e.model.subModels.field.uid;yield e.engine.destroyModel(a),yield e.model.setSubModel("field",{use:l.modelName,stepParams:{fieldSettings:{init:{dataSourceKey:e.model.collectionField.dataSourceKey,collectionName:i.name,fieldPath:r}}}}).save()}e.model.setProps(e.collectionField.targetCollection.getField(r).getComponentProps())}}),handler(e,t){return L(this,null,function*(){e.model.props.pattern==="readPretty"?e.model.setProps({titleField:t==null?void 0:t.label}):e.model.setProps({titleField:t.titleField})})}}}});FormItemModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{aclCheckRefresh:{use:"aclCheckRefresh",defaultParams:{strategy:"formItem"}}}});class AssignFormItemModel extends FormItemModel{constructor(t){super(t),R(this,"assignValue"),(0,import_reactive.define)(this,{assignValue:import_reactive.observable})}onInit(t){var o,r,i,n,l,a,c;const u=(o=this.getStepParams("fieldSettings","assignValue"))==null?void 0:o.value;typeof u<"u"&&(this.assignValue=u),this.context.defineProperty("collectionField",{get:()=>{var f,_;const v=this.getStepParams("fieldSettings","init")||{},b=`${v==null?void 0:v.dataSourceKey}.${v==null?void 0:v.collectionName}.${v==null?void 0:v.fieldPath}`,F=(f=this.context)==null?void 0:f.dataSourceManager;return(_=F==null?void 0:F.getCollectionField)==null?void 0:_.call(F,b)}});const d=this.context,m=d==null?void 0:d.collection,p=this.fieldInit;if(!((r=this.subModels)!=null&&r.field)&&m!=null&&m.getFields){const f=(m.getFields()||[]).find(b=>(b==null?void 0:b.name)===(p==null?void 0:p.fieldPath));(i=m==null?void 0:m.getField)==null||i.call(m,p==null?void 0:p.fieldPath);const _=import_flow_engine.EditableItemModel.getDefaultBindingByField(d,f);if(!_)return;const v=_.modelName;(l=(n=d==null?void 0:d.engine)==null?void 0:n.createModel)==null||l.call(n,{use:v,stepParams:{fieldSettings:{init:p}},parentId:this.uid,subKey:"field"})}const h=(a=this.context)==null?void 0:a.collection,g=this.fieldPath;if(g){const f=(c=h==null?void 0:h.getField)==null?void 0:c.call(h,g),_=(f==null?void 0:f.title)||g,v=g.includes(".")?g.split("."):[g];this.setProps({label:_,name:v})}}get fieldInit(){return this.getStepParams("fieldSettings","init")||{}}get fieldPath(){var t;return(t=this.fieldInit)==null?void 0:t.fieldPath}getAssignedEntry(){const t=this.fieldPath;return t?[t,this.assignValue]:null}render(){var t;const o=this.context,r=o.collection,i=this.fieldInit,n=((t=this.props)==null?void 0:t.name)||(this.fieldPath?[this.fieldPath]:void 0),l=this.fieldPath;return(0,import_jsx_runtime.jsx)(()=>{var a,c,u,d,m,p,h;const[g,f]=import_react2.default.useState(null);import_react2.default.useEffect(()=>{var P,j,A,T,N,D,w,k,B,E,M,O,q,$,V,U,z,K,W,Y,Q;if(!l)return;const H=(((P=r==null?void 0:r.getFields)==null?void 0:P.call(r))||[]).find(ae=>(ae==null?void 0:ae.name)===l);r.getField(l);const J=import_flow_engine.EditableItemModel.getDefaultBindingByField(o,H);if(!J)return;const Z=J.modelName,re=(A=(j=o==null?void 0:o.engine)==null?void 0:j.createModel)==null?void 0:A.call(j,{use:"VariableFieldFormModel",subModels:{fields:[{use:Z,stepParams:{fieldSettings:{init:i}}}]}});if(!re)return;(N=(T=re.context)==null?void 0:T.defineProperty)==null||N.call(T,"collection",{value:r});const oe=o==null?void 0:o.dataSource;oe&&((w=(D=re.context)==null?void 0:D.defineProperty)==null||w.call(D,"dataSource",{value:oe}));const G=(k=r==null?void 0:r.getField)==null?void 0:k.call(r,i==null?void 0:i.fieldPath);G&&((E=(B=re.context)==null?void 0:B.defineProperty)==null||E.call(B,"collectionField",{value:G}));const X=o==null?void 0:o.blockModel;X&&((O=(M=re.context)==null?void 0:M.defineProperty)==null||O.call(M,"blockModel",{value:X}));const ie=o.form;ie&&(($=(q=re.context)==null?void 0:q.defineProperty)==null||$.call(q,"form",{value:ie})),re.context&&Object.defineProperty(re.context,"resource",{configurable:!0,enumerable:!0,get:()=>X==null?void 0:X.resource});const ee=(U=(V=re==null?void 0:re.subModels)==null?void 0:V.fields)==null?void 0:U[0],ne=(z=r==null?void 0:r.getField)==null?void 0:z.call(r,i==null?void 0:i.fieldPath),le=ne==null?void 0:ne.type,me=ne==null?void 0:ne.interface,he=le==="belongsToMany"||le==="hasMany"||le==="belongsToArray"||me==="m2m"||me==="o2m"||me==="mbm";if((K=ee==null?void 0:ee.setProps)==null||K.call(ee,{disabled:!1,readPretty:!1,pattern:"editable",updateAssociation:!1,multiple:he}),(W=ee==null?void 0:ee.dispatchEvent)==null||W.call(ee,"beforeRender",void 0,{sequential:!0,useCache:!0}),ensureOptionsFromUiSchemaEnumIfAbsent(ee,ne),!((Y=ee==null?void 0:ee.props)!=null&&Y.fieldNames)&&ne!=null&&ne.targetCollection){const ae=ne.targetCollection,xe=(ne==null?void 0:ne.targetKey)||(ae==null?void 0:ae.filterTargetKey)||"id";(Q=ee==null?void 0:ee.setProps)==null||Q.call(ee,{fieldNames:{label:ae==null?void 0:ae.titleField,value:xe}})}return f(re),()=>{var ae,xe,ge,ve;(ge=(xe=(ae=re==null?void 0:re.subModels)==null?void 0:ae.fields)==null?void 0:xe.forEach)==null||ge.call(xe,de=>{var ce;return(ce=de==null?void 0:de.remove)==null?void 0:ce.call(de)}),(ve=re==null?void 0:re.remove)==null||ve.call(re)}},[]);const _=P=>(import_react2.default.useEffect(()=>{var j,A,T,N;if(!g)return;(j=g.setProps)==null||j.call(g,x({},P));const D=(T=(A=g==null?void 0:g.subModels)==null?void 0:A.fields)==null?void 0:T[0];D&&((N=D.setProps)==null||N.call(D,{value:P==null?void 0:P.value,onChange:(...w)=>{var k;const B=w&&w.length?w[0]:void 0;(k=P==null?void 0:P.onChange)==null||k.call(P,B)}}))},[P]),g?(0,import_jsx_runtime.jsx)("div",{style:{width:"100%"},children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:g,showFlowSettings:!1})}):null),v=()=>(0,import_jsx_runtime.jsx)(import_antd.Input,{placeholder:"<Null>",readOnly:!0,style:{width:"100%"}}),b=P=>(0,import_jsx_runtime.jsx)(RunJSValueEditor,{t:this.context.t,value:P==null?void 0:P.value,onChange:P==null?void 0:P.onChange,containerStyle:{width:"100%"}}),F={renderInputComponent:P=>{var j;const A=(j=P==null?void 0:P.paths)==null?void 0:j[0];if(A==="constant")return _;if(A==="null")return v;if(A==="runjs")return b},resolveValueFromPath:P=>{var j;const A=(j=P==null?void 0:P.paths)==null?void 0:j[0];if(A==="constant")return"";if(A==="null")return null;if(A==="runjs")return{code:"",version:"v2"}},resolvePathFromValue:P=>P===null?["null"]:(0,import_flow_engine.isRunJSValue)(P)?["runjs"]:(0,import_flow_engine.isVariableExpression)(P)?(0,import_flow_engine.parseValueToPath)(P):["constant"]},y=()=>L(this,null,function*(){var P;const j=(P=this.context)==null?void 0:P.getPropertyMetaTree,A=typeof j=="function"?yield j():[];return[{title:(0,import_flow_engine.tExpr)("Constant"),name:"constant",type:"string",paths:["constant"],render:_},{title:(0,import_flow_engine.tExpr)("Null"),name:"null",type:"object",paths:["null"],render:v},{title:(0,import_flow_engine.tExpr)("RunJS"),name:"runjs",type:"object",paths:["runjs"],render:b},...A]});let C=(u=(c=(a=this.props)==null?void 0:a.label)!=null?c:this.fieldPath)!=null?u:"";const S=(d=r==null?void 0:r.getField)==null?void 0:d.call(r,this.fieldPath);return C=(h=(p=(m=this.props)==null?void 0:m.label)!=null?p:S==null?void 0:S.title)!=null?h:C,(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},this.props),{label:C,name:n,initialValue:this.assignValue,valuePropName:"__assign_value__",trigger:"__assign_trigger__",validateTrigger:"__assign_trigger__",children:import_react2.default.createElement(P=>{const j=P==null?void 0:P.__assign_value__,A=typeof j>"u"?this.assignValue:j;return(0,import_jsx_runtime.jsx)(import_flow_engine.VariableInput,{value:A,onChange:T=>{var N;this.assignValue=T,(N=P==null?void 0:P.__assign_trigger__)==null||N.call(P,T)},metaTree:y,converters:F,clearValue:""})})}))},{})}}AssignFormItemModel.define({label:(0,import_flow_engine.tExpr)("Assign field")});AssignFormItemModel.registerFlow({key:"editItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Form item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({label:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>({label:e.model.collectionField.title}),handler(e,t){var o;t.label&&t.label===((o=e.model.collectionField)==null?void 0:o.title)?e.model.setProps({label:t.label}):e.model.setProps({label:e.t(t.label,{ns:"lm-flow-engine"})})}},init:{handler(e){return L(this,null,function*(){const t=e.model.collectionField;t&&e.model.setProps(t.getComponentProps());const o=e.model.fieldPath,r=o.includes(".")?o.split("."):o;e.model.setProps({name:r})})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},validation:{title:(0,import_flow_engine.tExpr)("Validation"),use:"validation"},required:{title:(0,import_flow_engine.tExpr)("Required"),use:"required"}}});class DetailsAssociationFieldGroupModel extends AssociationFieldGroupModel{}R(DetailsAssociationFieldGroupModel,"itemModelName","DetailsItemModel");DetailsAssociationFieldGroupModel.define({label:'{{t("Display association fields")}}'});const getOuterHeight=e=>{if(!e)return 0;const t=e.getBoundingClientRect(),o=window.getComputedStyle(e),r=parseFloat(o.marginTop)||0,i=parseFloat(o.marginBottom)||0;return t.height+r+i},useDetailsGridHeight=({heightMode:e,containerRef:t,actionsRef:o,paginationRef:r,deps:i=[]})=>{const[n,l]=(0,import_react2.useState)(),a=(0,import_react2.useCallback)(()=>{if(e!=="specifyValue"&&e!=="fullHeight"){l(h=>h===void 0?h:void 0);return}const c=t.current;if(!c)return;const u=c.getBoundingClientRect().height;if(!u)return;const d=getOuterHeight(o.current),m=getOuterHeight(r.current),p=Math.max(0,Math.floor(u-d-m));l(h=>h===p?h:p)},[e,t,o,r]);return(0,import_react2.useLayoutEffect)(()=>{a()},[a,...i]),(0,import_react2.useEffect)(()=>{if(!t.current||typeof ResizeObserver>"u")return;const c=t.current,u=o.current,d=r.current,m=new ResizeObserver(()=>a());return m.observe(c),u&&m.observe(u),d&&m.observe(d),()=>m.disconnect()},[a,t,o,r,...i]),n};class DetailsBlockModel extends CollectionBlockModel{constructor(){super(...arguments),R(this,"hadSingleRecordData",!1),R(this,"hasMultiRefreshDispatched",!1),R(this,"_defaultCustomModelClasses",{RecordActionGroupModel:"RecordActionGroupModel",DetailsItemModel:"DetailsItemModel",DetailsAssociationFieldGroupModel:"DetailsAssociationFieldGroupModel",DetailsCustomItemModel:"DetailsCustomItemModel"}),R(this,"customModelClasses",{}),R(this,"handlePageChange",t=>L(this,null,function*(){if(this.resource instanceof import_flow_engine.MultiRecordResource){const o=this.resource;o.setPage(t),o.loading=!0,yield this.refresh()}}))}createResource(t,o){var r,i;if(((r=this.association)==null?void 0:r.type)==="hasOne"||((i=this.association)==null?void 0:i.type)==="belongsTo"){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}if(Object.keys(o).includes("filterByTk")){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}const n=this.context.createResource(import_flow_engine.MultiRecordResource);return n.setPageSize(1),n}onInit(t){var o,r,i;super.onInit(t),this.hadSingleRecordData=(i=(r=(o=this.resource)==null?void 0:o.hasData)==null?void 0:r.call(o))!=null?i:!1,this.hasMultiRefreshDispatched=!1;const n=(0,import_flow_engine.createCurrentRecordMetaFactory)(this.context,()=>this.collection);this.context.defineProperty("record",{get:()=>this.getCurrentRecord(),cache:!1,resolveOnServer:(0,import_flow_engine.createRecordResolveOnServerWithLocal)(()=>this.collection,()=>this.getCurrentRecord()),meta:n}),this.resource.on("refresh",()=>{var l,a,c;if(this.isMultiRecordResource()){this.hasMultiRefreshDispatched=!0,dispatchEventDeep(this,"paginationChange");return}const u=this.hadSingleRecordData;this.hadSingleRecordData=(c=(a=(l=this.resource)==null?void 0:l.hasData)==null?void 0:a.call(l))!=null?c:!1,u&&dispatchEventDeep(this,"paginationChange")})}isMultiRecordResource(){return this.resource instanceof import_flow_engine.MultiRecordResource}hasDispatchedMultiRefresh(){return this.hasMultiRefreshDispatched}getCurrentRecord(){const t=this.resource.getData();return Array.isArray(t)?t[0]:t}hasAvailableData(){return this.resource.hasData()}refresh(){return L(this,null,function*(){yield this.resource.refresh()})}renderPagination(){var t,o;if(!this.resource.loading&&!this.hasAvailableData())return(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",color:(o=(t=this.context)==null?void 0:t.themeToken)==null?void 0:o.colorTextDescription},children:this.translate("No available data currently")});const r=this.resource;return!this.isMultiRecordResource()||!r.getPage()||this.resource.getMeta("count")<=1?null:(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center"},children:(0,import_jsx_runtime.jsx)(import_antd.Pagination,{simple:!0,pageSize:1,showSizeChanger:!1,defaultCurrent:r.getPage(),total:r.getTotalPage(),onChange:this.handlePageChange,style:{display:"inline-block"}})})}renderConfigureActions(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"actions",subModelBaseClass:this.getModelClassName("RecordActionGroupModel"),afterSubModelInit:t=>L(this,null,function*(){t.setStepParams("buttonSettings","general",{type:"default"})}),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Actions")})},"details-actions-add")}renderComponent(){const{colon:t,labelAlign:o,labelWidth:r,labelWrap:i,layout:n}=this.props,l=!!this.context.flowSettingsEnabled,a=!l&&!this.hasAvailableData(),{heightMode:c,height:u}=this.decoratorProps;return(0,import_jsx_runtime.jsx)(DetailsBlockContent,{model:this,gridModel:this.subModels.grid,isConfigMode:l,heightMode:c,height:u,layoutProps:{colon:t,labelAlign:o,labelWidth:r,labelWrap:i,layout:n},actions:(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{children:(0,import_jsx_runtime.jsx)("div",{style:a?{pointerEvents:"none",opacity:.45}:void 0,children:(0,import_jsx_runtime.jsxs)(import_antd.Space,{wrap:!0,children:[this.mapSubModels("actions",d=>{if(!(d.hidden&&!l))return(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:d,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:d,showFlowSettings:{showBackground:!1,showBorder:!1,toolbarPosition:"above"},extraToolbarItems:[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]})},d.uid)}),this.renderConfigureActions()]})})})})}}R(DetailsBlockModel,"scene",BlockSceneEnum.oam);const DetailsBlockContent=({model:e,gridModel:t,isConfigMode:o,heightMode:r,height:i,layoutProps:n,actions:l})=>{const a=(0,import_react2.useRef)(null),c=(0,import_react2.useRef)(null),u=(0,import_react2.useRef)(null),d=r==="specifyValue"||r==="fullHeight",m=useDetailsGridHeight({heightMode:r,containerRef:a,actionsRef:c,paginationRef:u,deps:[i]});return(0,import_react2.useEffect)(()=>{var p,h;if(!t)return;const g=d?m:void 0;((p=t.props)==null?void 0:p.height)===g&&((h=t.props)==null?void 0:h.heightMode)===r||t.setProps({height:g,heightMode:r})},[t,m,d,r]),(0,import_jsx_runtime.jsx)(FormComponent,{model:e,layoutProps:n,style:d?{display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:void 0,children:(0,import_jsx_runtime.jsxs)("div",{ref:a,style:d?{display:"flex",flexDirection:"column",minHeight:0,flex:1}:void 0,children:[(0,import_jsx_runtime.jsx)("div",{ref:c,style:{textAlign:"right",lineHeight:"0px",paddingBottom:o&&e.context.themeToken.padding},children:l}),(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:t,showFlowSettings:!1},`${(t==null?void 0:t.uid)||"details-grid"}:${o?"design":"runtime"}`),(0,import_jsx_runtime.jsx)("div",{ref:u,children:e.renderPagination()})]})})};DetailsBlockModel.registerFlow({key:"detailsSettings",title:(0,import_flow_engine.tExpr)("Details settings"),sort:150,steps:{refresh:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized");yield e.model.applySubModelsBeforeRenderFlows("grid")})}},layout:{use:"layout",title:(0,import_flow_engine.tExpr)("Layout")},dataScope:{use:"dataScope"},defaultSorting:{use:"sortingRule",title:(0,import_flow_engine.tExpr)("Default sorting")},linkageRules:{use:"detailsFieldLinkageRules"}}});DetailsBlockModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{blockLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"blockLinkageRules",flowKey:"cardSettings",stepKey:"linkageRules"}},fieldslinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"detailsFieldLinkageRules",flowKey:"detailsSettings",stepKey:"linkageRules"}}}});DetailsBlockModel.registerFlow({key:"initialPaginationChangeRefresh",sort:10001,steps:{refreshPaginationRelatedStates:{handler(e){return L(this,null,function*(){var t;if(e.model.hidden||!e.model.isMultiRecordResource()||e.model.hasDispatchedMultiRefresh())return;const o=e.model.resource;if(!o)return;const r=((t=o.dataLoadingMode)!=null?t:o.loadingMode)==="manual",i=typeof o.hasActiveFilters=="function"?o.hasActiveFilters():!1;!r||i||(yield dispatchEventDeep(e.model,"paginationChange"))})}}}});DetailsBlockModel.define({label:(0,import_flow_engine.tExpr)("Details"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),createModelOptions:{use:"DetailsBlockModel",subModels:{grid:{use:"DetailsGridModel"}}},sort:350});class DetailsCustomItemModel extends import_flow_engine.FlowModel{static defineChildren(t){const o=t.engine.filterModelClassByParent("CommonItemModel"),r=t.engine.filterModelClassByParent("DetailsCustomItemModel"),i=n=>Array.from(n.entries()).map(([l,a])=>{var c,u,d,m,p,h;const g=typeof a.defineChildren=="function"||!!((c=a.meta)!=null&&c.children),f={key:l,label:t.t(a.meta.label),sort:(u=a.meta.sort)!=null?u:999,searchable:!!((d=a.meta)!=null&&d.searchable),searchPlaceholder:(m=a.meta)==null?void 0:m.searchPlaceholder,hide:(p=a.meta)==null?void 0:p.hide};return g?f.children=_=>{var v;return typeof a.defineChildren=="function"?a.defineChildren(_):((v=a.meta)==null?void 0:v.children)||[]}:f.createModelOptions=((h=a.meta)==null?void 0:h.createModelOptions)||{use:l},f});return import_lodash.default.sortBy([...i(o),...i(r)],"sort")}}R(DetailsCustomItemModel,"renderMode",import_flow_engine.ModelRenderMode.RenderFunction);DetailsCustomItemModel.define({hide:!0,label:(0,import_flow_engine.tExpr)("Others")});class DetailsGridModel extends GridModel{constructor(){super(...arguments),R(this,"itemFallback",(0,import_jsx_runtime.jsx)(import_antd.Skeleton.Input,{block:!0,size:"small",style:{marginBottom:"0.5rem"}})),R(this,"itemSettingsMenuLevel",2),R(this,"itemFlowSettings",{showBackground:!0,style:{top:-6,left:-6,right:-6,bottom:-6}}),R(this,"dragOverlayConfig",{columnInsert:{before:{offsetTop:-12,height:24},after:{offsetTop:7,height:24}},columnEdge:{left:{offsetLeft:-5,width:24},right:{offsetLeft:8,width:24}},rowGap:{above:{offsetTop:0,height:24},below:{offsetTop:-14,height:24}}})}renderAddSubModelButton(){return this.context.flowSettingsEnabled?(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"items",subModelBaseClasses:[this.context.getModelClassName("DetailsItemModel"),this.context.getModelClassName("DetailsAssociationFieldGroupModel"),this.context.getModelClassName("DetailsCustomItemModel")].filter(Boolean),keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})}):null}render(){var t,o;const r=(t=this.props)==null?void 0:t.height,i=(o=this.props)==null?void 0:o.heightMode,n=this.context.themeToken,l=super.render();return i==="defaultHeight"?l:(0,import_jsx_runtime.jsx)("div",{style:{height:r,overflowY:"auto",marginLeft:`-${n.marginLG}px`,marginRight:`-${n.marginLG}px`,paddingLeft:`${n.marginLG}px`,paddingRight:`${n.marginLG}px`},children:l})}}DetailsGridModel.registerFlow({key:"detailFieldGridSettings",steps:{grid:{handler(e,t){e.model.setProps("rowGap",0),e.model.setProps("colGap",16)}}}});function transformChildrenToJS(e,t){const{fieldUseModel:o,refreshTargets:r}=t,i=n=>Array.isArray(n)?n.map(l=>{const a=x({},l);if(a.children)if(typeof a.children=="function"){const c=a.children;a.children=u=>L(this,null,function*(){const d=yield c(u);return i(d)})}else Array.isArray(a.children)&&(a.children=i(a.children));if(a.createModelOptions){const c=a.createModelOptions;a.createModelOptions=(u,d)=>L(this,null,function*(){const m=yield typeof c=="function"?c(u,d):c;return m.subModels=m.subModels||{},m.subModels.field=I(x({},m.subModels.field||{}),{use:o}),m}),a.refreshTargets=a.refreshTargets||r}return a}):[];return i(e)}function buildAssociationJSGroup(e,t,o){var r,i,n,l;const{fieldUseModel:a,refreshTargets:c}=o,u=(r=o.key)!=null?r:"js-association-fields",d=(i=o.label)!=null?i:(0,import_flow_engine.tExpr)("Display association fields"),m=(n=o.searchable)!=null?n:!0,p=(l=o.searchPlaceholder)!=null?l:(0,import_flow_engine.tExpr)("Search fields");return{key:u,type:"group",label:d,searchable:m,searchPlaceholder:p,children:h=>L(this,null,function*(){const g=yield t(h);return transformChildrenToJS(g,{fieldUseModel:a,refreshTargets:c})})}}function buildJSFieldMenuChildren(e,t){return L(this,null,function*(){var o;const{useModel:r,fieldUseModel:i,refreshTargets:n,associationPathName:l,associationProvider:a}=t,c=(0,import_flow_engine.buildWrapperFieldChildren)(e,{useModel:r,fieldUseModel:i,associationPathName:l,refreshTargets:n});let u=[];const d=(o=c==null?void 0:c[0])==null?void 0:o.children;if(Array.isArray(d)&&(u=d),!a)return u;const m=yield a(e);if(!Array.isArray(m)||m.length===0)return u;const p=buildAssociationJSGroup(e,a,{fieldUseModel:i,refreshTargets:n});return[...u,p]})}class DetailsJSFieldItemModel extends DetailsCustomItemModel{static defineChildren(t){return buildJSFieldMenuChildren(t,{useModel:"DetailsItemModel",fieldUseModel:"JSFieldModel",refreshTargets:["DetailsItemModel"],associationProvider:o=>DetailsAssociationFieldGroupModel.defineChildren(o)})}}DetailsJSFieldItemModel.define({label:(0,import_flow_engine.tExpr)("JS field"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search fields"),sort:110});class FilterFormFieldModel extends FieldModel{}class AssociationFieldModel extends FieldModel{constructor(){super(...arguments),R(this,"operator","$eq"),R(this,"updateAssociation",!0)}}AssociationFieldModel.registerFlow({key:"AssociationFieldInit",sort:800,steps:{init:{handler(e,t){return L(this,null,function*(){var o,r;if(e.model.updateAssociation){const i=e.model.context.blockModel,n=(o=i==null?void 0:i.context)==null?void 0:o.resource,l=(r=e.model.parent)==null?void 0:r.fieldPath;if(!n||!l)return;n.addUpdateAssociationValues(l)}})}},allowCreateCheck:{handler(e){return L(this,null,function*(){var t;const o=yield e.aclCheck({dataSourceKey:e.collectionField.dataSourceKey,resourceName:(t=e.collectionField)==null?void 0:t.target,actionName:"create"});e.model.setProps({allowCreate:!!o})})}}}});const isPlaceholderFieldName=(e,t)=>e===t,unwrapAssociationOptionRecord=e=>{if(e&&typeof e=="object"){const t=e.data;return t&&typeof t=="object"?t:e}};function normalizeFilterTargetKey$1(e){if(typeof e=="string"&&e)return e;if(Array.isArray(e)&&e.length===1&&typeof e[0]=="string")return e[0]}function normalizeAssociationFieldNames(e,t){var o;const r=typeof((o=t==null?void 0:t.titleCollectionField)==null?void 0:o.name)=="string"?t.titleCollectionField.name:void 0,i=normalizeFilterTargetKey$1(t==null?void 0:t.filterTargetKey)||"id",n=typeof(e==null?void 0:e.value)=="string"&&e.value&&!isPlaceholderFieldName(e.value,"value")?e.value:void 0,l=typeof(e==null?void 0:e.label)=="string"&&e.label&&!isPlaceholderFieldName(e.label,"label")?e.label:void 0,a=n||i;return{label:l||r||a,value:a}}function buildOpenerUids(e,t={}){var o,r,i,n,l,a;const c=!!t.navigation,u=_=>{if(Array.isArray(_))return _.filter(v=>typeof v=="string"&&!!v)},d=u((r=(o=e.view)==null?void 0:o.inputArgs)==null?void 0:r.openerUids),m=u(t.openerUids),p=d||m||[];if(c)return(m||p).filter(Boolean);const h=(n=(i=e.view)==null?void 0:i.inputArgs)==null?void 0:n.viewUid,g=(a=(l=e.model.context)==null?void 0:l.inputArgs)==null?void 0:a.viewUid,f=typeof h=="string"&&h?h:typeof g=="string"&&g?g:e.model.uid;return[...p,f].filter(Boolean)}function toSafeDisplayLabel(e){var t;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e)){const o=e.map(r=>{var i;if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r&&typeof r=="object"){const n=(i=r.label)!=null?i:r.name;if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n}}).filter(r=>r!==void 0);return o.length?o.map(String).join(", "):void 0}if(e&&typeof e=="object"){const o=(t=e.label)!=null?t:e.name;if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o}}function LabelByField(e){var t,o,r,i,n,l,a;const{option:c,fieldNames:u}=e,d=(0,import_flow_engine.useFlowModel)(),m=unwrapAssociationOptionRecord(c),p=normalizeAssociationFieldNames(u,(t=d.context.collectionField)==null?void 0:t.targetCollection),h=d.subModels.field,g=(r=(o=toSafeDisplayLabel(m==null?void 0:m[p.label]))!=null?o:toSafeDisplayLabel(m==null?void 0:m.label))!=null?r:toSafeDisplayLabel(m==null?void 0:m[p.value]);if(!h)return(0,import_jsx_runtime.jsx)("span",{children:g??"N/A"});const f=String((n=(i=m==null?void 0:m[p.value])!=null?i:g)!=null?n:"association-option"),_=h.createFork({},f);_.context.defineProperty("record",{get:()=>m,cache:!1,meta:(0,import_flow_engine.createCurrentRecordMetaFactory)(_.context,()=>_.context.collection)});const v=(a=(l=d.context.collectionField.targetCollection)==null?void 0:l.getField)==null?void 0:a.call(l,p.label),b=v&&typeof v.getComponentProps=="function"?v.getComponentProps():{};_.setProps(x({value:g,clickToOpen:!1},b));const F=g!==null&&typeof g<"u"&&g!==""?_.render():"N/A";return(0,import_jsx_runtime.jsx)("span",{style:{pointerEvents:"none"},children:F})}function toSelectValue(e,t,o=!1,r="record",i=[]){if(!e)return o?[]:void 0;const{value:n}=t||{},l=c=>typeof c=="object"&&c!==null,a=c=>{if(l(c))return{label:(0,import_jsx_runtime.jsx)(LabelByField,{option:c,fieldNames:t}),value:c[n]}};if(r==="value"){const c=u=>{if(typeof u=="object"&&u!==null)return a(u);const d=i.find(m=>(m==null?void 0:m[n])===u);return d?a(d):{label:String(u),value:u}};return o?Array.isArray(e)?e.map(u=>c(u)).filter(Boolean):[]:Array.isArray(e)?c(e[0]):c(e)}if(o)return Array.isArray(e)?e.filter(l).map(a).filter(Boolean):[];if(Array.isArray(e)){const c=e[0];return l(c)?a(c):void 0}return l(e)?a(e):void 0}function resolveOptions(e,t,o){return e!=null&&e.length?e.map(r=>(0,import_lodash.omit)(r,"disabled","options","style")):o?Array.isArray(t)?t.filter(r=>typeof r=="object"&&r!==null):[]:t&&typeof t=="object"?[t]:[]}const labelClassName=import_css.css`
1847
+ `;function isGridDelegatedStep(e,t){var o;return!!((o=GRID_DELEGATED_STEP_KEYS[e])!=null&&o.has(t))}class FormBlockModel extends CollectionBlockModel{constructor(){super(...arguments),R(this,"formValueRuntime"),R(this,"userModifiedTopLevelFields",new Set),R(this,"_defaultCustomModelClasses",{FormActionGroupModel:"FormActionGroupModel",FormItemModel:"FormItemModel",FormAssociationFieldGroupModel:"FormAssociationFieldGroupModel"}),R(this,"customModelClasses",{})}get form(){return this.context.form}syncRuntimeAssignRules(t="unknown"){var o,r,i;const n=this.getStepParams("formModelSettings","assignRules"),l=(n==null?void 0:n.value)||[];(r=(o=this.formValueRuntime)==null?void 0:o.syncAssignRules)==null||r.call(o,Array.isArray(l)?l:[]);const a=(i=this.context)==null?void 0:i.resource,c=collectUpdateAssociationValuesFromAssignRules(l,this.collection);a!=null&&a.addUpdateAssociationValues&&c.length&&a.addUpdateAssociationValues(c)}renderConfigureActions(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"actions",subModelBaseClass:this.getModelClassName("FormActionGroupModel"),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Actions")})})}setFieldsValue(t){const o=this.context;if(typeof o.setFormValues=="function"){o.setFormValues(t,{source:"system"}).catch(r=>{console.warn("[FormBlockModel] Failed to set form values via ctx.setFormValues",r)});return}this.form.setFieldsValue(t)}setFieldValue(t,o){const r=this.context;if(typeof r.setFormValue=="function"){r.setFormValue(t,o,{source:"system"}).catch(i=>{console.warn("[FormBlockModel] Failed to set form value via ctx.setFormValue",i)});return}this.form.setFieldValue(t,o)}markUserModifiedFields(t){if(!(!t||typeof t!="object")&&!Array.isArray(t))for(const o of Object.keys(t))o&&this.userModifiedTopLevelFields.add(o)}getUserModifiedFields(){return this.userModifiedTopLevelFields}resetUserModifiedFields(){this.userModifiedTopLevelFields.clear()}onDispatchEventStart(t,o,r){return L(this,null,function*(){var i;if(t==="beforeRender"){const n=this.subModels.grid;n&&(yield n.dispatchEvent("beforeRender",r,{useCache:o==null?void 0:o.useCache}))}yield(i=$e(FormBlockModel.prototype,this,"onDispatchEventStart"))==null?void 0:i.call(this,t,o,r)})}getStepParams(t,o){const r=this.subModels.grid;if(t&&o&&isGridDelegatedStep(t,o)&&r){const i=r.getStepParams(t,o);return typeof i<"u"?i:super.getStepParams(t,o)}if(t&&!o&&GRID_DELEGATED_STEP_KEYS[t]&&r){const i=super.getStepParams(t)||{},n=r.getStepParams(t)||{};for(const l of GRID_DELEGATED_STEP_KEYS[t])Object.prototype.hasOwnProperty.call(n,l)&&typeof n[l]<"u"&&(i[l]=n[l]);return i}return super.getStepParams(t,o)}setStepParams(t,o,r){const i=this.subModels.grid,n=(l,a)=>{const c=GRID_DELEGATED_STEP_KEYS[l];if(!c||!i)return a;const u={};for(const[d,m]of Object.entries(a))c.has(d)?i.setStepParams(l,d,m):u[d]=m;return u};if(typeof t=="string"&&typeof o=="string"&&r!==void 0){isGridDelegatedStep(t,o)&&i?i.setStepParams(t,o,r):super.setStepParams(t,o,r);return}if(typeof t=="string"&&typeof o=="object"&&o!==null){const l=n(t,o);Object.keys(l).length>0&&super.setStepParams(t,l);return}if(typeof t=="object"&&t!==null){const l={};for(const[a,c]of Object.entries(t)){if(typeof c!="object"||c===null){l[a]=c;continue}const u=n(a,c);Object.keys(u).length>0&&(l[a]=u)}Object.keys(l).length>0&&super.setStepParams(l)}}saveStepParams(){return L(this,null,function*(){return yield saveStepParamsWithSubModelsIfNeeded(this,()=>L(this,null,function*(){const t=yield $e(FormBlockModel.prototype,this,"saveStepParams").call(this),o=this.subModels.grid;return yield o==null?void 0:o.saveStepParams(),t}))})}createFormValuesMetaFactory(){return(0,import_flow_engine.createAssociationAwareObjectMetaFactory)(()=>this.collection,this.translate("Current form"),()=>{var t,o;return((o=(t=this.form)==null?void 0:t.getFieldsValue)==null?void 0:o.call(t))||{}})}useHooksBeforeRender(){const[t]=import_antd.Form.useForm();this.context.defineProperty("form",{get:()=>t}),this.formValueRuntime||(this.formValueRuntime=new FormValueRuntime({model:this,getForm:()=>this.context.form}));const o=this.formValueRuntime;o.mount();const r=this.createFormValuesMetaFactory();this.context.defineProperty("formValues",{get:()=>o.formValues,cache:!1,meta:r,resolveOnServer:i=>{var n,l,a,c,u,d,m,p,h,g,f,_,v,b,F;if(!i)return!1;const y=(C=>{const S=String(C||"").match(/^([^.[]+)/);return S==null?void 0:S[1]})(i);if(!y||!((l=(n=this.collection)==null?void 0:n.getField)!=null&&l.call(n,y)))return!1;if((()=>{var C,S,P,j,A;const T=(P=(S=(C=this.subModels.grid)==null?void 0:C.subModels)==null?void 0:S.items)!=null?P:[],N=new Set;for(const D of T){const w=(A=(j=D==null?void 0:D.getStepParams)==null?void 0:j.call(D,"fieldSettings","init"))==null?void 0:A.fieldPath,k=w==null?void 0:w.toString().split(".")[0];k&&N.add(k)}return N})().has(y)){const C=(c=(a=this.form)==null?void 0:a.getFieldValue)==null?void 0:c.call(a,y);if(C==null||Array.isArray(C)&&C.length===0)return!1;const S=o.getFormValuesSnapshot();return S&&typeof S=="object"&&typeof(0,import_shared2.getValuesByPath)(S,i)<"u"?!1:(0,import_flow_engine.createAssociationSubpathResolver)(()=>this.collection,()=>o.getFormValuesSnapshot())(i)}try{const C=(F=(f=(m=(d=(u=this.context)==null?void 0:u.resource)==null?void 0:d.getMeta)==null?void 0:m.call(d,"currentFilterByTk"))!=null?f:(g=(h=(p=this.context)==null?void 0:p.resource)==null?void 0:h.getFilterByTk)==null?void 0:g.call(h))!=null?F:(b=(_=this.collection)==null?void 0:_.getFilterByTK)==null?void 0:b.call(_,(v=this.context)==null?void 0:v.record);if(typeof C>"u"||C===null)return!1}catch{return!1}return!0},serverOnlyWhenContextParams:!0}),this.context.defineMethod("getFormValues",function(){return o.getFormValuesSnapshot()}),this.context.defineMethod("setFormValues",function(i,n){return o.setFormValues(this,i,n)}),this.context.defineMethod("setFormValue",function(i,n,l){return o.setFormValues(this,[{path:i,value:n}],l)})}onInit(t){super.onInit(t),this.emitter.on("onSubModelAdded",o=>{o===this.subModels.grid&&queueMicrotask(()=>this.syncRuntimeAssignRules("onSubModelAdded:grid"))}),this.context.defineProperty("record",{get:()=>this.getCurrentRecord(),cache:!1}),this.context.resource.on("saved",()=>{this.dispatchEvent("formSubmitSuccess",{})})}onMount(){var t;super.onMount(),(t=this.formValueRuntime)==null||t.mount({sync:!0}),this.syncRuntimeAssignRules("onMount"),setTimeout(()=>{this.applyFlow("eventSettings")},100)}onUnmount(){var t;(t=this.formValueRuntime)==null||t.dispose(),this.formValueRuntime=void 0,super.onUnmount()}getCurrentRecord(){return{}}renderComponent(){throw new Error("renderComponent method must be implemented in subclasses of FormModel")}}function FormComponent(e){var t=e,{model:o,children:r,layoutProps:i={},initialValues:n}=t,l=te(t,["model","children","layoutProps","initialValues"]),a,c,u,d;const m=!!((a=o==null?void 0:o.context)!=null&&a.isMobileLayout&&(i==null?void 0:i.layout)==="horizontal"),p=[l.className,m?FLOW_KEEP_MOBILE_HORIZONTAL_CLASS:"",m?flowKeepMobileHorizontalClassName:""].filter(Boolean).join(" ");return(0,import_jsx_runtime.jsx)(import_antd.Form,I(x(I(x({form:o.form,initialValues:((d=(u=(c=o.context)==null?void 0:c.view)==null?void 0:u.inputArgs)==null?void 0:d.formData)||o.context.record||n},(0,import_lodash.omit)(i,"labelWidth")),{labelCol:{style:{width:i==null?void 0:i.labelWidth}},onFieldsChange:h=>{const g=o.formValueRuntime;g&&g.handleFormFieldsChange(h)},onValuesChange:(h,g)=>{var f;(f=o.markUserModifiedFields)==null||f.call(o,h);const _=o.formValueRuntime;if(_){_.handleFormValuesChange(h,g);return}o.dispatchEvent("formValuesChange",{changedValues:h,allValues:g},{debounce:!0}),o.emitter.emit("formValuesChange",{changedValues:h,allValues:g})}}),l),{className:p||void 0,children:r}))}const getOuterHeight$1=e=>{if(!e)return 0;const t=e.getBoundingClientRect(),o=window.getComputedStyle(e),r=parseFloat(o.marginTop)||0,i=parseFloat(o.marginBottom)||0;return t.height+r+i},normalizeCssSize=e=>{if(!(e==null||e===""))return typeof e=="number"?`${e}px`:/^\d+(\.\d+)?$/.test(e)?`${e}px`:e},useFormGridHeight=({heightMode:e,containerRef:t,actionsRef:o,footerRef:r,deps:i=[]})=>{const[n,l]=(0,import_react2.useState)(),a=(0,import_react2.useCallback)(()=>{if(e!=="specifyValue"&&e!=="fullHeight"){l(h=>h===void 0?h:void 0);return}const c=t.current;if(!c)return;const u=c.getBoundingClientRect().height;if(!u)return;const d=getOuterHeight$1((o==null?void 0:o.current)||null),m=getOuterHeight$1((r==null?void 0:r.current)||null),p=Math.max(0,Math.floor(u-d-m));l(h=>h===p?h:p)},[e,t,o,r]);return(0,import_react2.useLayoutEffect)(()=>{a()},[a,...i]),(0,import_react2.useEffect)(()=>{if(!t.current||typeof ResizeObserver>"u")return;const c=t.current,u=(o==null?void 0:o.current)||null,d=(r==null?void 0:r.current)||null,m=new ResizeObserver(()=>a());return m.observe(c),u&&m.observe(u),d&&m.observe(d),()=>m.disconnect()},[a,t,o,r,...i]),n},FormBlockContent=({model:e,gridModel:t,layoutProps:o,onFinish:r,grid:i,actions:n,footer:l,heightMode:a,height:c})=>{var u,d;const m=(0,import_react2.useRef)(null),p=(0,import_react2.useRef)(null),h=(0,import_react2.useRef)(null),g=a==="specifyValue"||a==="fullHeight",f={paddingTop:(d=(u=e.context)==null?void 0:u.themeToken)==null?void 0:d.padding},_=(o==null?void 0:o.layout)==="horizontal"?normalizeCssSize(o==null?void 0:o.labelWidth):void 0;_&&(f.marginInlineStart=_);const v=useFormGridHeight({heightMode:a,containerRef:m,actionsRef:n?p:void 0,footerRef:l?h:void 0,deps:[c]});return(0,import_react2.useEffect)(()=>{var b;if(!t)return;const F=g?v:void 0;((b=t.props)==null?void 0:b.height)!==F&&t.setProps({height:F})},[t,v,g]),(0,import_jsx_runtime.jsx)(FormComponent,{model:e,layoutProps:o,onFinish:r,style:g?{display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:void 0,children:(0,import_jsx_runtime.jsxs)("div",{ref:m,style:g?{display:"flex",flexDirection:"column",minHeight:0,flex:1}:void 0,children:[i,n?(0,import_jsx_runtime.jsx)("div",{style:f,ref:p,children:n}):null,l?(0,import_jsx_runtime.jsx)("div",{ref:h,children:l}):null]})})};FormBlockModel.define({hide:!0});FormBlockModel.registerFlow({key:"formModelSettings",title:(0,import_flow_engine.tExpr)("Form settings"),steps:{layout:{use:"layout",title:(0,import_flow_engine.tExpr)("Layout")},assignRules:{use:"formAssignRules",title:(0,import_flow_engine.tExpr)("Field values"),beforeParamsSave(e){const t=clearLegacyDefaultValuesFromFormModel(e.model);Array.isArray(t)&&t.length&&markSaveStepParamsWithSubModels(e.model)},afterParamsSave(e){var t,o,r,i,n,l;const a=e.model.getStepParams("formModelSettings","assignRules"),c=(a==null?void 0:a.value)||[];(r=(o=(t=e.model)==null?void 0:t.formValueRuntime)==null?void 0:o.syncAssignRules)==null||r.call(o,Array.isArray(c)?c:[]);const u=(n=(i=e.model)==null?void 0:i.context)==null?void 0:n.resource,d=collectUpdateAssociationValuesFromAssignRules(c,(l=e.model)==null?void 0:l.collection);u!=null&&u.addUpdateAssociationValues&&d.length&&u.addUpdateAssociationValues(d)}}}});FormBlockModel.registerFlow({key:"eventSettings",title:(0,import_flow_engine.tExpr)("Event settings"),on:"formValuesChange",steps:{linkageRules:{use:"fieldLinkageRules",afterParamsSave(e){var t;e.model.applyFlow("eventSettings",{changedValues:{},allValues:(t=e.form)==null?void 0:t.getFieldsValue(!0)})}}}});FormBlockModel.registerEvents({formValuesChange:{title:(0,import_flow_engine.tExpr)("Form values change"),name:"formValuesChange",uiSchema:{condition:{type:"object",title:(0,import_flow_engine.tExpr)("Trigger condition"),"x-decorator":"FormItem","x-component":ConditionBuilder}},handler:commonConditionHandler}});class FormModel extends FormBlockModel{}FormModel.define({hide:!0});class AssignFormModel extends FormBlockModel{useHooksBeforeRender(){const[t]=import_antd.Form.useForm();this.context.defineProperty("form",{get:()=>t})}onInit(t){super.onInit(t);const o=(0,import_flow_engine.createCurrentRecordMetaFactory)(this.context,()=>this.collection);this.context.defineProperty("record",{get:()=>{var r;return(r=this.getCurrentRecord)==null?void 0:r.call(this)},cache:!1,resolveOnServer:(0,import_flow_engine.createRecordResolveOnServerWithLocal)(()=>this.collection,()=>{var r;return(r=this.getCurrentRecord)==null?void 0:r.call(this)}),meta:o}),this.context.defineProperty("filterManager",{once:!0,get:()=>new FilterManager(this,t==null?void 0:t.filterManager)}),this.isManualRefresh=!0}createResource(t,o){const r=this.context.createResource(import_flow_engine.SingleRecordResource);return r.isNewRecord=!0,r}renderComponent(){var t;const{colon:o,labelAlign:r,labelWidth:i,labelWrap:n,layout:l}=this.props;return(0,import_jsx_runtime.jsx)(FormComponent,{model:this,layoutProps:{colon:o,labelAlign:r,labelWidth:i,labelWrap:n,layout:l},children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:(t=this.subModels)==null?void 0:t.grid,showFlowSettings:!1})})}setInitialAssignedValues(t){var o;const r=(o=this.subModels)==null?void 0:o.grid;Object.entries(t||{}).forEach(([i,n])=>{r.addOrEnsureItem(i,n)})}getAssignedValues(){return this.subModels.grid.getAssignedValues()||{}}}AssignFormModel.define({label:(0,import_flow_engine.tExpr)("Field assignments"),hide:!0,createModelOptions:{use:"AssignFormModel",subModels:{grid:{use:"AssignFormGridModel"}}}});class FormGridModel extends GridModel{constructor(){super(...arguments),R(this,"itemFallback",(0,import_jsx_runtime.jsx)(import_antd.Skeleton.Input,{block:!0,size:"small",style:{marginBottom:"0.5rem"}})),R(this,"itemSettingsMenuLevel",2),R(this,"itemFlowSettings",{showBackground:!0,style:{top:-6,left:-6,right:-6,bottom:-6}}),R(this,"dragOverlayConfig",{columnInsert:{before:{offsetTop:-12,height:24},after:{offsetTop:7,height:24}},columnEdge:{left:{offsetLeft:-5,width:24},right:{offsetLeft:8,width:24}},rowGap:{above:{offsetTop:0,height:24},below:{offsetTop:-14,height:24}}})}renderAddSubModelButton(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{subModelKey:"items",subModelBaseClasses:[this.context.getModelClassName("FormItemModel"),this.context.getModelClassName("FormAssociationFieldGroupModel"),this.context.getModelClassName("FormCustomItemModel"),this.context.getModelClassName("FormJSFieldItemModel")].filter(Boolean),model:this,keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})})}render(){var t,o;const r=(t=this.props)==null?void 0:t.height,i=(o=this.props)==null?void 0:o.heightModel,n=this.context.themeToken,l=super.render();return i==="defaultHeight"?l:(0,import_jsx_runtime.jsx)("div",{style:{height:r,overflowY:"auto",marginLeft:`-${n.marginLG}px`,marginRight:`-${n.marginLG}px`,paddingLeft:`${n.marginLG}px`,paddingRight:`${n.marginLG}px`,paddingTop:5},children:l})}}FormGridModel.registerFlow({key:"formFieldGridSettings",steps:{grid:{handler(e,t){e.model.setProps("rowGap",0),e.model.setProps("colGap",16)}}}});class AssignFormGridModel extends FormGridModel{renderAddSubModelButton(){var t,o;const r=(t=this.context)==null?void 0:t.collection,i=((o=r==null?void 0:r.getFields)==null?void 0:o.call(r))||[],n=typeof(r==null?void 0:r.getPrimaryKey)=="function"?r.getPrimaryKey():void 0,l=r==null?void 0:r.filterTargetKey,a=u=>u?!!(n&&u===n||typeof l=="string"&&u===l||Array.isArray(l)&&l.includes(u)):!1,c=i.filter(u=>!a(u==null?void 0:u.name)).map(u=>{const d=u.name,m=u.title||u.name,p=import_flow_engine.EditableItemModel.getDefaultBindingByField(this.context,u);if(!p)return;const h=p.modelName;return{key:d,label:m,toggleable:g=>{const f=g.getStepParams("fieldSettings","init")||{};return(f==null?void 0:f.fieldPath)===d},useModel:"AssignFormItemModel",createModelOptions:()=>({use:"AssignFormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:r==null?void 0:r.dataSourceKey,collectionName:r==null?void 0:r.name,fieldPath:d}}},subModels:{field:{use:h,stepParams:{fieldSettings:{init:{dataSourceKey:r==null?void 0:r.dataSourceKey,collectionName:r==null?void 0:r.name,fieldPath:d}}}}}})}}).filter(Boolean);return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{subModelKey:"items",model:this,items:c,keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})})}addOrEnsureItem(t,o){var r,i,n;const l=(r=this.context)==null?void 0:r.collection,a=(((i=this.subModels)==null?void 0:i.items)||[]).find(p=>{try{const h=typeof(p==null?void 0:p.getStepParams)=="function"?p.getStepParams("fieldSettings","init"):null;return(h==null?void 0:h.fieldPath)===t}catch{return!1}});if(a){typeof(a==null?void 0:a.setStepParams)=="function"&&a.setStepParams("fieldSettings","assignValue",{value:o}),a.assignValue=o;return}const c=(((n=l==null?void 0:l.getFields)==null?void 0:n.call(l))||[]).find(p=>p.name===t),u=import_flow_engine.EditableItemModel.getDefaultBindingByField(this.context,c);if(!u)return;const d=u.modelName,m=this.flowEngine.createModel({use:"AssignFormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:l==null?void 0:l.dataSourceKey,collectionName:l==null?void 0:l.name,fieldPath:t},assignValue:{value:o}}},subModels:{field:{use:d,stepParams:{fieldSettings:{init:{dataSourceKey:l==null?void 0:l.dataSourceKey,collectionName:l==null?void 0:l.name,fieldPath:t}}}}},parentId:this.uid,subKey:"items"});m.assignValue=o}getAssignedValues(){var t;const o=((t=this.subModels)==null?void 0:t.items)||[],r={};for(const i of o){const n=typeof i.getAssignedEntry=="function"?i.getAssignedEntry():null;n&&Array.isArray(n)&&(r[n[0]]=n[1])}return r}}AssignFormGridModel.define({label:(0,import_flow_engine.tExpr)("Assign grid")});function getFieldBindingUse(e){var t,o;const r=(o=(t=e==null?void 0:e.stepParams)==null?void 0:t.fieldBinding)==null?void 0:o.use;return typeof r=="string"?r:void 0}function rebuildFieldSubModel(e){return L(this,arguments,function*({parentModel:t,targetUse:o,defaultProps:r,pattern:i,fieldSettingsInit:n}){var l,a,c;const u=t.subModels.field,d=u==null?void 0:u.uid,m=(a=(l=u==null?void 0:u.serialize)==null?void 0:l.call(u))==null?void 0:a.subModels;for(const _ in m)m[_].delegateToParent===!1&&delete m[_];const p=(u==null?void 0:u.stepParams)||{},h=n??((c=t.getFieldSettingsInitParams)==null?void 0:c.call(t)),g=I(x({},p),{fieldBinding:I(x({},p.fieldBinding),{use:o}),fieldSettings:{init:h}}),f=t.flowEngine;d&&(u==null||u.invalidateFlowCache("beforeRender",!0),f.removeModelWithSubModels(d)),yield t.setSubModel("field",{uid:d,use:FieldModel,props:x(x({},r||{}),i?{pattern:i}:{}),stepParams:g,subModels:m}).dispatchEvent("beforeRender",void 0,{useCache:!1}),yield t.save()})}function getValueWithIndex(e,t,o){const r=(0,import_lodash.castArray)(o).filter(n=>typeof n=="string"),i=t.split(".");if(r!=null&&r.length){const n=[];let l=0,a=0;for(;l<i.length;){const c=i[l];if(n.push(c),a<r.length){const[u,d]=r[a].split(":");u===c&&(n.push(Number(d)),a++)}l++}return(0,import_lodash.get)(e,n)}return(0,import_lodash.get)(e,i)}function getDetailsItemValue(e){const{record:t,currentObject:o,fieldPath:r,prefixFieldPath:i,idx:n}=e,l=getValueWithIndex(t,r,n);if(l!==void 0||o==null)return l;if(i&&r===i)return o;const a=i&&r.startsWith(`${i}.`)?r.slice(i.length+1):r;return a?(0,import_lodash.get)(o,a):o}function normalizeDetailsAssociationValue(e,t){return!isToManyAssociationField(e)||Array.isArray(t)?t:t&&typeof t=="object"&&Array.isArray(t.rows)?t.rows:t==null?[]:[t]}class DetailsItemModel extends import_flow_engine.DisplayItemModel{static defineChildren(t){const o=t.collection;return o.getFields().map(r=>{const i=this.getDefaultBindingByField(t,r,{fallbackToTargetTitleField:!0});if(!i)return null;const n=i.modelName,l=t.prefixFieldPath?`${t.prefixFieldPath}.${r.name}`:r.name;return{key:l,label:r.title,refreshTargets:["DetailsCustomItemModel/DetailsJSFieldItemModel"],toggleable:a=>{var c;return((c=a.getStepParams("fieldSettings","init"))==null?void 0:c.fieldPath)===l},useModel:"DetailsItemModel",createModelOptions:()=>({use:"DetailsItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:o.dataSourceKey,collectionName:t.model.context.blockModel.collection.name,fieldPath:l}}},subModels:{field:{use:n,props:typeof i.defaultProps=="function"?i.defaultProps(t,r):i.defaultProps}}})}}).filter(Boolean)}onInit(t){super.onInit(t),this.context.defineProperty("actionName",{get:()=>"view",cache:!1})}renderItem(){const t=this.subModels.field,o=this.context.fieldIndex,r=this.context.record,i=this.context.currentObject,n=this.context.item,l=this.context.getPropertyOptions("item"),a=this.context.prefixFieldPath,c=o!=null?(()=>{const m=t.createFork({},`${o}`);m.context.defineProperty("fieldIndex",{get:()=>o}),m.context.defineProperty("record",{get:()=>r,cache:!1}),m.context.defineProperty("currentObject",{get:()=>i,cache:!1});const p=l||{},h=te(p,["value"]);return m.context.defineProperty("item",I(x({},h),{get:()=>n,cache:!1})),this.context.pattern&&m.context.defineProperty("pattern",{get:()=>this.context.pattern}),m})():t,u=this.context.pattern?I(x(x({},this.context.blockModel.props),this.props),{pattern:this.context.pattern,disabled:this.context.pattern==="readPretty"}):x(x({},this.context.blockModel.props),this.props),d=normalizeDetailsAssociationValue(this.collectionField,getDetailsItemValue({record:r,currentObject:i,fieldPath:this.fieldPath,prefixFieldPath:a,idx:o}));return(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},u),{value:d,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FieldModelRenderer,{model:c})}))}}DetailsItemModel.define({label:(0,import_flow_engine.tExpr)("Display fields"),sort:100});DetailsItemModel.registerFlow({key:"detailItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Detail item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({title:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>{var t;return{title:(t=e.collectionField)==null?void 0:t.title}},handler(e,t){var o;const r={ns:"lm-flow-engine",compareWith:(o=e.collectionField)==null?void 0:o.title};e.model.setProps({label:e.t(t.title,r)})}},aclCheck:{use:"aclCheck"},init:{handler(e){return L(this,null,function*(){const{collectionField:t}=e.model;t&&e.model.setProps(t.getComponentProps())})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},model:{title:(0,import_flow_engine.tExpr)("Field component"),use:"displayFieldComponent"},fieldNames:{use:"titleField",title:(0,import_flow_engine.tExpr)("Title field"),beforeParamsSave:(e,t,o)=>L(void 0,null,function*(){var r,i;if(!e.collectionField||!e.collectionField.isAssociationField())return null;if(t.label!==o.label){e.model.setProps(x({titleField:t.label},(i=(r=e.collectionField.targetCollection)==null?void 0:r.getField(t.label))==null?void 0:i.getComponentProps()));const n=e.collectionField.targetCollection.getField(t.label),l=import_flow_engine.DisplayItemModel.getDefaultBindingByField(e,n),a=l.modelName;yield rebuildFieldSubModel({parentModel:e.model,targetUse:a,defaultProps:typeof(l==null?void 0:l.defaultProps)=="function"?l.defaultProps(e,e.collectionField):l==null?void 0:l.defaultProps,pattern:e.model.getProps().pattern})}}),handler(e,t){return L(this,null,function*(){var o,r;if(!e.collectionField||e.model.subModels.field.disableTitleField)return;e.model.setProps(x({titleField:t.label},(r=(o=e.collectionField.targetCollection)==null?void 0:o.getField(t.label))==null?void 0:r.getComponentProps()));const i=e.collectionField.targetCollection;if(i){const n=i.getField(t.label),l=import_flow_engine.DisplayItemModel.getDefaultBindingByField(e,n).modelName,a=e.model.subModels.field.use;l!==a&&e.model.setStepParams(e.flowKey,"model",{use:l})}})},hideInSettings:e=>L(void 0,null,function*(){return!e.collectionField||!e.collectionField.isAssociationField()||e.model.subModels.field.disableTitleField})}}});DetailsItemModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{aclCheckRefresh:{use:"aclCheckRefresh"}}});function isInSameBlock(e,t){var o,r;const i=(r=(o=e==null?void 0:e.context)==null?void 0:o.blockModel)==null?void 0:r.uid,n=t==null?void 0:t.uid;return!i||!n?!1:String(i)===String(n)}function tryGetModelTargetPathCandidate(e){var t,o;const r=(t=e==null?void 0:e.context)==null?void 0:t.fieldPathArray;if(Array.isArray(r)&&r.length)return r;try{const a=(o=e==null?void 0:e.getStepParams)==null?void 0:o.call(e,"fieldSettings","init"),c=a==null?void 0:a.fieldPath;if(typeof c=="string"&&c)return c}catch{}const i=e==null?void 0:e.fieldPath;if(typeof i=="string"&&i)return i;const n=typeof(e==null?void 0:e.getProps)=="function"?e.getProps():e==null?void 0:e.props,l=n==null?void 0:n.name;return typeof l=="string"&&l||Array.isArray(l)&&l.length?l:null}function normalizeResolvedNamePath(e){return!Array.isArray(e)||!e.length||typeof e[0]!="string"?null:e}function resolveModelNamePath(e){var t;const o=tryGetModelTargetPathCandidate(e);if(!o)return null;const r=resolveDynamicNamePath(o,(t=e==null?void 0:e.context)==null?void 0:t.fieldIndex);return normalizeResolvedNamePath(r)}function cleanupEmptyPlainObjectAncestors(e,t){if(!(!e||typeof e!="object")&&!(!Array.isArray(t)||t.length<2))for(let o=t.length-1;o>=1;o--){const r=t.slice(0,o);if(typeof r[r.length-1]=="number")continue;const i=import_lodash.default.get(e,r);import_lodash.default.isPlainObject(i)&&Object.keys(i).length===0&&import_lodash.default.unset(e,r)}}function forEachModelIncludingForks(e,t){e!=null&&e.forEachModel&&e.forEachModel(o=>{t(o);const r=o==null?void 0:o.forks;r&&typeof r.forEach=="function"&&r.forEach(i=>t(i))})}function collectHiddenModelNamePaths(e){const t=e==null?void 0:e.flowEngine;if(!(t!=null&&t.forEachModel))return[];const o=[],r=new Set;return forEachModelIncludingForks(t,i=>{if(!i||typeof i!="object"||!i.hidden||!isInSameBlock(i,e))return;const n=resolveModelNamePath(i);if(!n)return;const l=JSON.stringify(n);r.has(l)||(r.add(l),o.push(n))}),o}function normalizeFormNamePath(e){return typeof e=="string"?e?[e]:null:Array.isArray(e)?normalizeResolvedNamePath(e):null}function isNamePathPrefix(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length>t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}function getValidationNamePathsExcludingHiddenModels(e){const t=e==null?void 0:e.form;if(!t||typeof t.getFieldsError!="function")return null;const o=t.getFieldsError();if(!Array.isArray(o))return null;const r=[],i=new Set;for(const l of o){const a=normalizeFormNamePath(l==null?void 0:l.name);if(!a)continue;const c=JSON.stringify(a);i.has(c)||(i.add(c),r.push(a))}if(!r.length)return null;const n=collectHiddenModelNamePaths(e);return n.length?r.filter(l=>!n.some(a=>isNamePathPrefix(a,l))):r}function shouldSkipSubmitValidation(e){var t,o;return((o=(t=e==null?void 0:e.getStepParams)==null?void 0:t.call(e,"submitSettings","skipRequiredValidation"))==null?void 0:o.skipValidator)===!0}function validateSubmitForm(e){return L(this,null,function*(){const{form:t,blockModel:o,flowSettingsEnabled:r,skipValidator:i}=e;if(i||!t||typeof t.validateFields!="function")return;const n=r&&o?getValidationNamePathsExcludingHiddenModels(o):null;if(Array.isArray(n)){n.length&&(yield t.validateFields(n));return}yield t.validateFields()})}function omitHiddenModelValuesFromSubmit(e,t){if(!e||typeof e!="object")return e;const o=collectHiddenModelNamePaths(t);if(!o.length)return e;const r=import_lodash.default.cloneDeep(e);for(const i of o)import_lodash.default.unset(r,i),cleanupEmptyPlainObjectAncestors(r,i);return r}function submitHandler(e,t,o){return L(this,null,function*(){var r,i,n,l,a;const c=e.resource,u=e.blockModel;yield validateSubmitForm({form:u==null?void 0:u.form,blockModel:u,flowSettingsEnabled:e==null?void 0:e.flowSettingsEnabled,skipValidator:shouldSkipSubmitValidation(e==null?void 0:e.model)});const d=u.form.getFieldsValue(!0),m=omitHiddenModelValuesFromSubmit(d,u);if(c instanceof import_flow_engine.SingleRecordResource){if(u instanceof EditFormModel){const h=c.getMeta("currentFilterByTk");h?c.setFilterByTk(h):c.isNewRecord=!0}const p=o?yield o(m):yield c.save(m,t.requestConfig);u instanceof EditFormModel?(c.isNewRecord=!1,(r=u.resetUserModifiedFields)==null||r.call(u),yield c.refresh()):(u.form.resetFields(),u.emitter.emit("onFieldReset"),(i=u.resetUserModifiedFields)==null||i.call(u),(l=(n=u.formValueRuntime)==null?void 0:n.resetAfterFormReset)==null||l.call(n),e.view.inputArgs.collectionName===u.collection.name&&e.view.inputArgs.onChange&&e.view.inputArgs.onChange(p==null?void 0:p.data))}else if(c instanceof import_flow_engine.MultiRecordResource){const p=c.getMeta("currentFilterByTk");if(!p){e.message.error(e.t("No filterByTk found for multi-record resource."));return}(yield o)?yield o(m,p):yield c.update(p,m,t.requestConfig),(a=u.resetUserModifiedFields)==null||a.call(u)}})}class EditFormModel extends FormBlockModel{constructor(){super(...arguments),R(this,"actionFlowSettings",{showBackground:!1,showBorder:!1,toolbarPosition:"above"}),R(this,"actionExtraToolbarItems",[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]),R(this,"handlePageChange",t=>L(this,null,function*(){if(this.resource instanceof import_flow_engine.MultiRecordResource){const o=this.resource;o.setPage(t),o.loading=!0,yield o.refresh(),yield dispatchEventDeep(this,"paginationChange")}}))}createResource(t,o){var r,i;if(((r=this.association)==null?void 0:r.type)==="hasOne"||((i=this.association)==null?void 0:i.type)==="belongsTo"){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}if(Object.keys(o).includes("filterByTk")){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}const n=this.context.createResource(import_flow_engine.MultiRecordResource);return n.setPageSize(1),n}isMultiRecordResource(){return this.resource instanceof import_flow_engine.MultiRecordResource}getCurrentRecord(){const t=this.resource.getData();return Array.isArray(t)?t[0]:t}hasAvailableData(){return this.resource.hasData()}getAclActionName(){return"update"}submitHandler(t,o,r){return L(this,null,function*(){yield submitHandler(t,o,r)})}submit(){return L(this,arguments,function*(t={},o){yield submitHandler(this.context,t,o)})}renderComponent(){var t,o;const{colon:r,labelAlign:i,labelWidth:n,labelWrap:l,layout:a}=this.props,c=!!this.context.flowSettingsEnabled,u=this.hasAvailableData(),d=!c&&!u,{heightMode:m,height:p}=this.decoratorProps,h=!this.resource.loading&&!u?(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",marginTop:16,color:(o=(t=this.context)==null?void 0:t.themeToken)==null?void 0:o.colorTextDescription},children:this.translate("No available data currently")}):this.isMultiRecordResource()&&this.resource.getMeta("count")>1?(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",marginTop:16},children:(0,import_jsx_runtime.jsx)(import_antd.Pagination,{simple:!0,pageSize:1,showSizeChanger:!1,defaultCurrent:this.resource.getPage(),total:this.resource.getTotalPage(),onChange:this.handlePageChange,style:{display:"inline-block"}})}):null;return(0,import_jsx_runtime.jsx)(FormBlockContent,{model:this,gridModel:this.subModels.grid,layoutProps:{colon:r,labelAlign:i,labelWidth:n,labelWrap:l,layout:a},heightMode:m,height:p,grid:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:this.subModels.grid,showFlowSettings:!1}),actions:(0,import_jsx_runtime.jsx)("div",{style:d?{pointerEvents:"none",opacity:.45}:void 0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{children:(0,import_jsx_runtime.jsxs)(import_antd.Space,{wrap:!0,children:[this.mapSubModels("actions",g=>{if(!(g.hidden&&!c))return(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:g,children:(0,import_jsx_runtime.jsx)(import_flow_engine.MemoFlowModelRenderer,{model:g,showFlowSettings:this.context.flowSettingsEnabled?this.actionFlowSettings:!1,extraToolbarItems:this.actionExtraToolbarItems},g.uid)},g.uid)}),this.renderConfigureActions()]})})}),footer:h})}}R(EditFormModel,"scene",BlockSceneEnum.oam),R(EditFormModel,"blockCapabilityActionName","update");EditFormModel.registerFlow({key:"formSettings",title:(0,import_flow_engine.tExpr)("Edit form settings"),steps:{init:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized");e.resource.on("refresh",()=>L(this,null,function*(){var t,o,r,i,n,l;const a=e.resource.getMeta("currentFilterByTk"),c=x({},e.model.getCurrentRecord());if(!c)return;const u=(t=e.association)==null?void 0:t.targetKey;if(u&&((o=e.association)==null?void 0:o.interface)!=="m2m"?e.resource.setMeta({currentFilterByTk:c==null?void 0:c[u]}):e.resource.setMeta({currentFilterByTk:e.collection.getFilterByTK(c)}),!e.form)return;const d=e.resource.getMeta("currentFilterByTk"),m=!(0,import_lodash.isEqual)(a,d),p=(i=(r=e.model).getUserModifiedFields)==null?void 0:i.call(r),h=!!(p!=null&&p.size),g=()=>{if(!(p!=null&&p.size))return;const f=_=>_!==null&&typeof _=="object";for(const _ of Array.from(p)){const v=e.form.getFieldValue(_),b=c==null?void 0:c[_];(Object.is(v,b)||f(v)&&f(b)&&(0,import_lodash.isEqual)(v,b))&&p.delete(_)}};if(!m&&h){const f=x({},c);for(const _ of p)f[_]=e.form.getFieldValue(_);e.form.setFieldsValue(f),g();return}m&&((l=(n=e.model).resetUserModifiedFields)==null||l.call(n)),e.form.setFieldsValue(c),g()}))})}},dataScope:{use:"dataScope"},refresh:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized")})}}}});EditFormModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{blockLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"blockLinkageRules",flowKey:"cardSettings",stepKey:"linkageRules"}},fieldsLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"fieldLinkageRules",flowKey:"eventSettings",stepKey:"linkageRules"}}}});EditFormModel.define({label:(0,import_flow_engine.tExpr)("Form (Edit)"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),createModelOptions:{use:"EditFormModel",subModels:{grid:{use:"FormGridModel"}}},sort:340});function isToManyAssociation(e){if(!e)return!1;const t=e==null?void 0:e.type;return t==="belongsToMany"||t==="hasMany"||t==="belongsToArray"}function coerceForToOneField(e,t){var o;const r=!!((o=e==null?void 0:e.isAssociationField)!=null&&o.call(e)),i=isToManyAssociation(e);return r&&!i&&Array.isArray(t)?t.length?t[0]:void 0:t}function buildDynamicNamePath(e,t){if(!(t!=null&&t.length))return e;const o=t[t.length-1],[r,i]=String(o).split(":"),n=Number(i);if(!r||!Number.isFinite(n))return e;let l=0;for(const u of t){const[d]=String(u).split(":");d===r&&(l+=1)}let a=-1,c=0;for(let u=0;u<e.length;u++)if(String(e[u])===r&&(c+=1,c===l)){a=u;break}if(a===-1){for(let u=e.length-1;u>=0;u--)if(String(e[u])===r){a=u;break}}return a===-1?e:[n,...e.slice(a+1)]}const interfacesOfUnsupportedDefaultValue=["o2o","oho","obo","o2m","attachment","expression","point","lineString","circle","polygon","sequence","formula"];class FormItemModel extends import_flow_engine.EditableItemModel{static defineChildren(t){const o=t.collection;return o.getFields().map(r=>{const i=this.getDefaultBindingByField(t,r);if(!i)return;const n=i.modelName,l=t.prefixFieldPath?`${t.prefixFieldPath}.${r.name}`:r.name;return{key:l,label:r.title,refreshTargets:["FormItemModel/FormJSFieldItemModel"],toggleable:a=>{var c;return((c=a.getStepParams("fieldSettings","init"))==null?void 0:c.fieldPath)===l},useModel:"FormItemModel",createModelOptions:()=>({use:"FormItemModel",stepParams:{fieldSettings:{init:{dataSourceKey:o.dataSourceKey,collectionName:t.model.context.blockModel.collection.name,fieldPath:l}}},subModels:{field:{use:n,props:typeof i.defaultProps=="function"?i.defaultProps(t,r):i.defaultProps}}})}}).filter(Boolean)}onInit(t){super.onInit(t),this.emitter.on("onSubModelAdded",o=>{if(this.collectionField){const r=this.collectionField.getComponentProps();o.setProps(r),this.setProps(x({},import_lodash.default.pick(r,"rules")||{}))}})}renderItem(){var t,o;const r=this.subModels.field,i=this.context.fieldIndex,n=this.context.fieldKey,l=((t=this.parent)==null?void 0:t.context.fieldPathArray)||[],a=i!=null?(()=>{const p=r.createFork({},`${n}`);p.context.defineProperty("fieldIndex",{get:()=>i}),p.context.defineProperty("fieldKey",{get:()=>n}),this.context.currentObject&&p.context.defineProperty("currentObject",{get:()=>this.context.currentObject});const h=this.context.getPropertyOptions("item");if(this.context.item){const g=h||{},f=te(g,["value"]);p.context.defineProperty("item",I(x({},f),{get:()=>this.context.item,cache:!1}))}return this.context.pattern&&p.context.defineProperty("pattern",{get:()=>this.context.pattern}),p})():r,c=this.context.pattern?I(x({},this.props),{pattern:this.context.pattern}):this.props,u=te(c,["initialValue"]),d=buildDynamicNamePath(this.props.name,i);this.context.defineProperty("fieldPathArray",{value:[...l,...import_lodash.default.castArray(d)]});const m=((o=this.context.item)==null?void 0:o.value)||this.context.record;return(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},u),{name:d,validateFirst:!0,disabled:this.props.disabled||!import_lodash.default.isEmpty(m)&&!m.__is_new__&&this.props.aclDisabled||!import_lodash.default.isEmpty(m)&&m.__is_new__&&this.props.aclCreateDisabled,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FieldModelRenderer,{model:a,name:d})}))}}FormItemModel.define({label:(0,import_flow_engine.tExpr)("Display fields"),sort:100});FormItemModel.registerFlow({key:"editItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Form item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({label:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>{var t;return{label:(t=e.collectionField)==null?void 0:t.title}},handler(e,t){var o;const r={ns:"lm-flow-engine",compareWith:(o=e.collectionField)==null?void 0:o.title};e.model.setProps({label:e.t(t.label,r)})}},aclCheck:{use:"aclCheck",handler(e,t){return L(this,null,function*(){var o,r,i,n,l,a,c,u,d,m,p,h,g,f,_;if(!e.collectionField||!e.blockModel)return;const v=e.blockModel.context.actionName,b=yield e.aclCheck({dataSourceKey:(o=e.dataSource)==null?void 0:o.key,resourceName:(r=e.collectionField)==null?void 0:r.collectionName,fields:[(i=e.collectionField)==null?void 0:i.name],actionName:v});if(v==="update"){const F=yield e.aclCheck({dataSourceKey:(n=e.dataSource)==null?void 0:n.key,resourceName:(l=e.collectionField)==null?void 0:l.collectionName,fields:[e.collectionField.name],actionName:"view"});e.prefixFieldPath&&e.item&&((yield e.aclCheck({dataSourceKey:(a=e.dataSource)==null?void 0:a.key,resourceName:(c=e.collectionField)==null?void 0:c.collectionName,fields:[e.collectionField.name],actionName:"create"}))||e.model.setProps({aclCreateDisabled:!0}));const y=(d=(u=e.item)==null?void 0:u.__is_new__)!=null?d:!1;!F&&!y&&(e.model.hidden=!0,e.model.forbidden={actionName:"view"},e.exitAll()),b||e.model.setProps({aclDisabled:!0})}else if(v==="create"){const F=yield e.aclCheck({dataSourceKey:(m=e.dataSource)==null?void 0:m.key,resourceName:(p=e.collectionField)==null?void 0:p.collectionName,actionName:"update"}),y=yield e.aclCheck({dataSourceKey:(h=e.dataSource)==null?void 0:h.key,resourceName:(g=e.collectionField)==null?void 0:g.collectionName,fields:[e.collectionField.name],actionName:"update"}),C=(_=(f=e.item)==null?void 0:f.__is_stored__)!=null?_:!1;!b&&!C&&(e.model.hidden=!0,e.model.forbidden={actionName:v},e.exitAll()),(!F||!y)&&e.model.setProps({aclDisabled:!0})}})}},init:{handler(e){return L(this,null,function*(){const t=e.model.fieldPath,o=t.includes(".")?t.split("."):t;e.model.setProps({name:o})})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem","x-component-props":{autoSize:!0}}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},initialValue:{title:(0,import_flow_engine.tExpr)("Default value"),disabledInSettings:!0,disabledReasonInSettings:e=>`${e.t("This setting has been moved to")}: ${e.t("Form block settings")} > ${e.t("Field values")}`,uiSchema:e=>{var t,o,r,i;if(e.model.parent.parent instanceof EditFormModel||(o=(t=e.model.subModels)==null?void 0:t.field)!=null&&o.updateAssociation)return;const n=(r=e.model.collectionField)==null?void 0:r.interface;if(!((i=interfacesOfUnsupportedDefaultValue==null?void 0:interfacesOfUnsupportedDefaultValue.includes)!=null&&i.call(interfacesOfUnsupportedDefaultValue,n)))return{defaultValue:{"x-component":"DefaultValue","x-decorator":"FormItem"}}},defaultParams:e=>{const t=e.model.collectionField;if(t.interface==="nanoid"&&t.options.autoFill!==!1){const{size:o,customAlphabet:r}=t.options||{size:21};return{defaultValue:(0,import_nanoid.customAlphabet)(r,o)()}}return{defaultValue:t.defaultValue}},handler(e,t){var o,r;const i=(o=e.model.collectionField)==null?void 0:o.interface;if((r=interfacesOfUnsupportedDefaultValue==null?void 0:interfacesOfUnsupportedDefaultValue.includes)!=null&&r.call(interfacesOfUnsupportedDefaultValue,i))return;const n=e.model.collectionField,l=coerceForToOneField(n,t.defaultValue);e.model.setProps({initialValue:l})}},validation:{title:(0,import_flow_engine.tExpr)("Validation"),use:"validation"},required:{title:(0,import_flow_engine.tExpr)("Required"),use:"required"},model:{use:"fieldComponent",title:(0,import_flow_engine.tExpr)("Field component")},pattern:{use:"pattern"},titleField:{use:"titleField",hideInSettings(e){return!e.collectionField||!e.collectionField.isAssociationField()||!(e.collectionField.isAssociationField()&&e.model.getProps().pattern==="readPretty")},defaultParams:e=>({titleField:e.model.props.titleField||e.model.context.collectionField.targetCollectionTitleFieldName}),beforeParamsSave:(e,t,o)=>L(void 0,null,function*(){if(!(e.collectionField.isAssociationField()&&e.model.getProps().pattern==="readPretty"))return null;const r=t.titleField||t.label;if(r!==o.titleField){const i=e.collectionField.targetCollection,n=i.getField(r),l=DetailsItemModel.getDefaultBindingByField(e,n);if(l.modelName!==e.model.subModels.field.use){const a=e.model.subModels.field.uid;yield e.engine.destroyModel(a),yield e.model.setSubModel("field",{use:l.modelName,stepParams:{fieldSettings:{init:{dataSourceKey:e.model.collectionField.dataSourceKey,collectionName:i.name,fieldPath:r}}}}).save()}e.model.setProps(e.collectionField.targetCollection.getField(r).getComponentProps())}}),handler(e,t){return L(this,null,function*(){e.model.props.pattern==="readPretty"?e.model.setProps({titleField:t==null?void 0:t.label}):e.model.setProps({titleField:t.titleField})})}}}});FormItemModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{aclCheckRefresh:{use:"aclCheckRefresh",defaultParams:{strategy:"formItem"}}}});class AssignFormItemModel extends FormItemModel{constructor(t){super(t),R(this,"assignValue"),(0,import_reactive.define)(this,{assignValue:import_reactive.observable})}onInit(t){var o,r,i,n,l,a,c;const u=(o=this.getStepParams("fieldSettings","assignValue"))==null?void 0:o.value;typeof u<"u"&&(this.assignValue=u),this.context.defineProperty("collectionField",{get:()=>{var f,_;const v=this.getStepParams("fieldSettings","init")||{},b=`${v==null?void 0:v.dataSourceKey}.${v==null?void 0:v.collectionName}.${v==null?void 0:v.fieldPath}`,F=(f=this.context)==null?void 0:f.dataSourceManager;return(_=F==null?void 0:F.getCollectionField)==null?void 0:_.call(F,b)}});const d=this.context,m=d==null?void 0:d.collection,p=this.fieldInit;if(!((r=this.subModels)!=null&&r.field)&&m!=null&&m.getFields){const f=(m.getFields()||[]).find(b=>(b==null?void 0:b.name)===(p==null?void 0:p.fieldPath));(i=m==null?void 0:m.getField)==null||i.call(m,p==null?void 0:p.fieldPath);const _=import_flow_engine.EditableItemModel.getDefaultBindingByField(d,f);if(!_)return;const v=_.modelName;(l=(n=d==null?void 0:d.engine)==null?void 0:n.createModel)==null||l.call(n,{use:v,stepParams:{fieldSettings:{init:p}},parentId:this.uid,subKey:"field"})}const h=(a=this.context)==null?void 0:a.collection,g=this.fieldPath;if(g){const f=(c=h==null?void 0:h.getField)==null?void 0:c.call(h,g),_=(f==null?void 0:f.title)||g,v=g.includes(".")?g.split("."):[g];this.setProps({label:_,name:v})}}get fieldInit(){return this.getStepParams("fieldSettings","init")||{}}get fieldPath(){var t;return(t=this.fieldInit)==null?void 0:t.fieldPath}getAssignedEntry(){const t=this.fieldPath;return t?[t,this.assignValue]:null}render(){var t;const o=this.context,r=o.collection,i=this.fieldInit,n=((t=this.props)==null?void 0:t.name)||(this.fieldPath?[this.fieldPath]:void 0),l=this.fieldPath;return(0,import_jsx_runtime.jsx)(()=>{var a,c,u,d,m,p,h;const[g,f]=import_react2.default.useState(null);import_react2.default.useEffect(()=>{var P,j,A,T,N,D,w,k,B,E,M,O,q,$,V,U,z,K,W,Y,Q;if(!l)return;const H=(((P=r==null?void 0:r.getFields)==null?void 0:P.call(r))||[]).find(ae=>(ae==null?void 0:ae.name)===l);r.getField(l);const J=import_flow_engine.EditableItemModel.getDefaultBindingByField(o,H);if(!J)return;const Z=J.modelName,re=(A=(j=o==null?void 0:o.engine)==null?void 0:j.createModel)==null?void 0:A.call(j,{use:"VariableFieldFormModel",subModels:{fields:[{use:Z,stepParams:{fieldSettings:{init:i}}}]}});if(!re)return;(N=(T=re.context)==null?void 0:T.defineProperty)==null||N.call(T,"collection",{value:r});const oe=o==null?void 0:o.dataSource;oe&&((w=(D=re.context)==null?void 0:D.defineProperty)==null||w.call(D,"dataSource",{value:oe}));const G=(k=r==null?void 0:r.getField)==null?void 0:k.call(r,i==null?void 0:i.fieldPath);G&&((E=(B=re.context)==null?void 0:B.defineProperty)==null||E.call(B,"collectionField",{value:G}));const X=o==null?void 0:o.blockModel;X&&((O=(M=re.context)==null?void 0:M.defineProperty)==null||O.call(M,"blockModel",{value:X}));const ie=o.form;ie&&(($=(q=re.context)==null?void 0:q.defineProperty)==null||$.call(q,"form",{value:ie})),re.context&&Object.defineProperty(re.context,"resource",{configurable:!0,enumerable:!0,get:()=>X==null?void 0:X.resource});const ee=(U=(V=re==null?void 0:re.subModels)==null?void 0:V.fields)==null?void 0:U[0],ne=(z=r==null?void 0:r.getField)==null?void 0:z.call(r,i==null?void 0:i.fieldPath),le=ne==null?void 0:ne.type,me=ne==null?void 0:ne.interface,he=le==="belongsToMany"||le==="hasMany"||le==="belongsToArray"||me==="m2m"||me==="o2m"||me==="mbm";if((K=ee==null?void 0:ee.setProps)==null||K.call(ee,{disabled:!1,readPretty:!1,pattern:"editable",updateAssociation:!1,multiple:he}),(W=ee==null?void 0:ee.dispatchEvent)==null||W.call(ee,"beforeRender",void 0,{sequential:!0,useCache:!0}),ensureOptionsFromUiSchemaEnumIfAbsent(ee,ne),!((Y=ee==null?void 0:ee.props)!=null&&Y.fieldNames)&&ne!=null&&ne.targetCollection){const ae=ne.targetCollection,xe=(ne==null?void 0:ne.targetKey)||(ae==null?void 0:ae.filterTargetKey)||"id";(Q=ee==null?void 0:ee.setProps)==null||Q.call(ee,{fieldNames:{label:ae==null?void 0:ae.titleField,value:xe}})}return f(re),()=>{var ae,xe,ge,ve;(ge=(xe=(ae=re==null?void 0:re.subModels)==null?void 0:ae.fields)==null?void 0:xe.forEach)==null||ge.call(xe,de=>{var ce;return(ce=de==null?void 0:de.remove)==null?void 0:ce.call(de)}),(ve=re==null?void 0:re.remove)==null||ve.call(re)}},[]);const _=P=>(import_react2.default.useEffect(()=>{var j,A,T,N;if(!g)return;(j=g.setProps)==null||j.call(g,x({},P));const D=(T=(A=g==null?void 0:g.subModels)==null?void 0:A.fields)==null?void 0:T[0];D&&((N=D.setProps)==null||N.call(D,{value:P==null?void 0:P.value,onChange:(...w)=>{var k;const B=w&&w.length?w[0]:void 0;(k=P==null?void 0:P.onChange)==null||k.call(P,B)}}))},[P]),g?(0,import_jsx_runtime.jsx)("div",{style:{width:"100%"},children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:g,showFlowSettings:!1})}):null),v=()=>(0,import_jsx_runtime.jsx)(import_antd.Input,{placeholder:"<Null>",readOnly:!0,style:{width:"100%"}}),b=P=>(0,import_jsx_runtime.jsx)(RunJSValueEditor,{t:this.context.t,value:P==null?void 0:P.value,onChange:P==null?void 0:P.onChange,containerStyle:{width:"100%"}}),F={renderInputComponent:P=>{var j;const A=(j=P==null?void 0:P.paths)==null?void 0:j[0];if(A==="constant")return _;if(A==="null")return v;if(A==="runjs")return b},resolveValueFromPath:P=>{var j;const A=(j=P==null?void 0:P.paths)==null?void 0:j[0];if(A==="constant")return"";if(A==="null")return null;if(A==="runjs")return{code:"",version:"v2"}},resolvePathFromValue:P=>P===null?["null"]:(0,import_flow_engine.isRunJSValue)(P)?["runjs"]:(0,import_flow_engine.isVariableExpression)(P)?(0,import_flow_engine.parseValueToPath)(P):["constant"]},y=()=>L(this,null,function*(){var P;const j=(P=this.context)==null?void 0:P.getPropertyMetaTree,A=typeof j=="function"?yield j():[];return[{title:(0,import_flow_engine.tExpr)("Constant"),name:"constant",type:"string",paths:["constant"],render:_},{title:(0,import_flow_engine.tExpr)("Null"),name:"null",type:"object",paths:["null"],render:v},{title:(0,import_flow_engine.tExpr)("RunJS"),name:"runjs",type:"object",paths:["runjs"],render:b},...A]});let C=(u=(c=(a=this.props)==null?void 0:a.label)!=null?c:this.fieldPath)!=null?u:"";const S=(d=r==null?void 0:r.getField)==null?void 0:d.call(r,this.fieldPath);return C=(h=(p=(m=this.props)==null?void 0:m.label)!=null?p:S==null?void 0:S.title)!=null?h:C,(0,import_jsx_runtime.jsx)(import_flow_engine.FormItem,I(x({},this.props),{label:C,name:n,initialValue:this.assignValue,valuePropName:"__assign_value__",trigger:"__assign_trigger__",validateTrigger:"__assign_trigger__",children:import_react2.default.createElement(P=>{const j=P==null?void 0:P.__assign_value__,A=typeof j>"u"?this.assignValue:j;return(0,import_jsx_runtime.jsx)(import_flow_engine.VariableInput,{value:A,onChange:T=>{var N;this.assignValue=T,(N=P==null?void 0:P.__assign_trigger__)==null||N.call(P,T)},metaTree:y,converters:F,clearValue:""})})}))},{})}}AssignFormItemModel.define({label:(0,import_flow_engine.tExpr)("Assign field")});AssignFormItemModel.registerFlow({key:"editItemSettings",sort:300,title:(0,import_flow_engine.tExpr)("Form item settings"),steps:{showLabel:{title:(0,import_flow_engine.tExpr)("Show label"),uiMode:{type:"switch",key:"showLabel"},defaultParams:{showLabel:!0},handler(e,t){e.model.setProps({showLabel:t.showLabel})}},label:{title:(0,import_flow_engine.tExpr)("Label"),uiSchema:e=>({label:{"x-component":"Input","x-decorator":"FormItem","x-reactions":t=>{var o;const r=e.model,i=(o=r.collectionField)==null?void 0:o.title;t.decoratorProps=I(x({},t.decoratorProps),{extra:r.context.t("Original field title: ")+i})}}}),defaultParams:e=>({label:e.model.collectionField.title}),handler(e,t){var o;t.label&&t.label===((o=e.model.collectionField)==null?void 0:o.title)?e.model.setProps({label:t.label}):e.model.setProps({label:e.t(t.label,{ns:"lm-flow-engine"})})}},init:{handler(e){return L(this,null,function*(){const t=e.model.collectionField;t&&e.model.setProps(t.getComponentProps());const o=e.model.fieldPath,r=o.includes(".")?o.split("."):o;e.model.setProps({name:r})})}},tooltip:{title:(0,import_flow_engine.tExpr)("Tooltip"),uiSchema:{tooltip:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({tooltip:e.t(t.tooltip,{ns:"lm-flow-engine"})})}},description:{title:(0,import_flow_engine.tExpr)("Description"),uiSchema:{description:{"x-component":"Input.TextArea","x-decorator":"FormItem"}},handler(e,t){e.model.setProps({extra:e.t(t.description,{ns:"lm-flow-engine"})})}},validation:{title:(0,import_flow_engine.tExpr)("Validation"),use:"validation"},required:{title:(0,import_flow_engine.tExpr)("Required"),use:"required"}}});class DetailsAssociationFieldGroupModel extends AssociationFieldGroupModel{}R(DetailsAssociationFieldGroupModel,"itemModelName","DetailsItemModel");DetailsAssociationFieldGroupModel.define({label:'{{t("Display association fields")}}'});const getOuterHeight=e=>{if(!e)return 0;const t=e.getBoundingClientRect(),o=window.getComputedStyle(e),r=parseFloat(o.marginTop)||0,i=parseFloat(o.marginBottom)||0;return t.height+r+i},useDetailsGridHeight=({heightMode:e,containerRef:t,actionsRef:o,paginationRef:r,deps:i=[]})=>{const[n,l]=(0,import_react2.useState)(),a=(0,import_react2.useCallback)(()=>{if(e!=="specifyValue"&&e!=="fullHeight"){l(h=>h===void 0?h:void 0);return}const c=t.current;if(!c)return;const u=c.getBoundingClientRect().height;if(!u)return;const d=getOuterHeight(o.current),m=getOuterHeight(r.current),p=Math.max(0,Math.floor(u-d-m));l(h=>h===p?h:p)},[e,t,o,r]);return(0,import_react2.useLayoutEffect)(()=>{a()},[a,...i]),(0,import_react2.useEffect)(()=>{if(!t.current||typeof ResizeObserver>"u")return;const c=t.current,u=o.current,d=r.current,m=new ResizeObserver(()=>a());return m.observe(c),u&&m.observe(u),d&&m.observe(d),()=>m.disconnect()},[a,t,o,r,...i]),n};class DetailsBlockModel extends CollectionBlockModel{constructor(){super(...arguments),R(this,"hadSingleRecordData",!1),R(this,"hasMultiRefreshDispatched",!1),R(this,"_defaultCustomModelClasses",{RecordActionGroupModel:"RecordActionGroupModel",DetailsItemModel:"DetailsItemModel",DetailsAssociationFieldGroupModel:"DetailsAssociationFieldGroupModel",DetailsCustomItemModel:"DetailsCustomItemModel"}),R(this,"customModelClasses",{}),R(this,"handlePageChange",t=>L(this,null,function*(){if(this.resource instanceof import_flow_engine.MultiRecordResource){const o=this.resource;o.setPage(t),o.loading=!0,yield this.refresh()}}))}createResource(t,o){var r,i;if(((r=this.association)==null?void 0:r.type)==="hasOne"||((i=this.association)==null?void 0:i.type)==="belongsTo"){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}if(Object.keys(o).includes("filterByTk")){const l=this.context.createResource(import_flow_engine.SingleRecordResource);return l.isNewRecord=!1,l}const n=this.context.createResource(import_flow_engine.MultiRecordResource);return n.setPageSize(1),n}onInit(t){var o,r,i;super.onInit(t),this.hadSingleRecordData=(i=(r=(o=this.resource)==null?void 0:o.hasData)==null?void 0:r.call(o))!=null?i:!1,this.hasMultiRefreshDispatched=!1;const n=(0,import_flow_engine.createCurrentRecordMetaFactory)(this.context,()=>this.collection);this.context.defineProperty("record",{get:()=>this.getCurrentRecord(),cache:!1,resolveOnServer:(0,import_flow_engine.createRecordResolveOnServerWithLocal)(()=>this.collection,()=>this.getCurrentRecord()),meta:n}),this.resource.on("refresh",()=>{var l,a,c;if(this.isMultiRecordResource()){this.hasMultiRefreshDispatched=!0,dispatchEventDeep(this,"paginationChange");return}const u=this.hadSingleRecordData;this.hadSingleRecordData=(c=(a=(l=this.resource)==null?void 0:l.hasData)==null?void 0:a.call(l))!=null?c:!1,u&&dispatchEventDeep(this,"paginationChange")})}isMultiRecordResource(){return this.resource instanceof import_flow_engine.MultiRecordResource}hasDispatchedMultiRefresh(){return this.hasMultiRefreshDispatched}getCurrentRecord(){const t=this.resource.getData();return Array.isArray(t)?t[0]:t}hasAvailableData(){return this.resource.hasData()}refresh(){return L(this,null,function*(){yield this.resource.refresh()})}renderPagination(){var t,o;if(!this.resource.loading&&!this.hasAvailableData())return(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center",color:(o=(t=this.context)==null?void 0:t.themeToken)==null?void 0:o.colorTextDescription},children:this.translate("No available data currently")});const r=this.resource;return!this.isMultiRecordResource()||!r.getPage()||this.resource.getMeta("count")<=1?null:(0,import_jsx_runtime.jsx)("div",{style:{textAlign:"center"},children:(0,import_jsx_runtime.jsx)(import_antd.Pagination,{simple:!0,pageSize:1,showSizeChanger:!1,defaultCurrent:r.getPage(),total:r.getTotalPage(),onChange:this.handlePageChange,style:{display:"inline-block"}})})}renderConfigureActions(){return(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"actions",subModelBaseClass:this.getModelClassName("RecordActionGroupModel"),afterSubModelInit:t=>L(this,null,function*(){t.setStepParams("buttonSettings","general",{type:"default"})}),children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Actions")})},"details-actions-add")}renderComponent(){const{colon:t,labelAlign:o,labelWidth:r,labelWrap:i,layout:n}=this.props,l=!!this.context.flowSettingsEnabled,a=!l&&!this.hasAvailableData(),{heightMode:c,height:u}=this.decoratorProps;return(0,import_jsx_runtime.jsx)(DetailsBlockContent,{model:this,gridModel:this.subModels.grid,isConfigMode:l,heightMode:c,height:u,layoutProps:{colon:t,labelAlign:o,labelWidth:r,labelWrap:i,layout:n},actions:(0,import_jsx_runtime.jsx)(import_flow_engine.DndProvider,{children:(0,import_jsx_runtime.jsx)("div",{style:a?{pointerEvents:"none",opacity:.45}:void 0,children:(0,import_jsx_runtime.jsxs)(import_antd.Space,{wrap:!0,children:[this.mapSubModels("actions",d=>{if(!(d.hidden&&!l))return(0,import_jsx_runtime.jsx)(import_flow_engine.Droppable,{model:d,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:d,showFlowSettings:{showBackground:!1,showBorder:!1,toolbarPosition:"above"},extraToolbarItems:[{key:"drag-handler",component:import_flow_engine.DragHandler,sort:1}]})},d.uid)}),this.renderConfigureActions()]})})})})}}R(DetailsBlockModel,"scene",BlockSceneEnum.oam);const DetailsBlockContent=({model:e,gridModel:t,isConfigMode:o,heightMode:r,height:i,layoutProps:n,actions:l})=>{const a=(0,import_react2.useRef)(null),c=(0,import_react2.useRef)(null),u=(0,import_react2.useRef)(null),d=r==="specifyValue"||r==="fullHeight",m=useDetailsGridHeight({heightMode:r,containerRef:a,actionsRef:c,paginationRef:u,deps:[i]});return(0,import_react2.useEffect)(()=>{var p,h;if(!t)return;const g=d?m:void 0;((p=t.props)==null?void 0:p.height)===g&&((h=t.props)==null?void 0:h.heightMode)===r||t.setProps({height:g,heightMode:r})},[t,m,d,r]),(0,import_jsx_runtime.jsx)(FormComponent,{model:e,layoutProps:n,style:d?{display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:void 0,children:(0,import_jsx_runtime.jsxs)("div",{ref:a,style:d?{display:"flex",flexDirection:"column",minHeight:0,flex:1}:void 0,children:[(0,import_jsx_runtime.jsx)("div",{ref:c,style:{textAlign:"right",lineHeight:"0px",paddingBottom:o&&e.context.themeToken.padding},children:l}),(0,import_jsx_runtime.jsx)(import_flow_engine.FlowModelRenderer,{model:t,showFlowSettings:!1},`${(t==null?void 0:t.uid)||"details-grid"}:${o?"design":"runtime"}`),(0,import_jsx_runtime.jsx)("div",{ref:u,children:e.renderPagination()})]})})};DetailsBlockModel.registerFlow({key:"detailsSettings",title:(0,import_flow_engine.tExpr)("Details settings"),sort:150,steps:{refresh:{handler(e){return L(this,null,function*(){if(!e.resource)throw new Error("Resource is not initialized");yield e.model.applySubModelsBeforeRenderFlows("grid")})}},layout:{use:"layout",title:(0,import_flow_engine.tExpr)("Layout")},dataScope:{use:"dataScope"},defaultSorting:{use:"sortingRule",title:(0,import_flow_engine.tExpr)("Default sorting")},linkageRules:{use:"detailsFieldLinkageRules"}}});DetailsBlockModel.registerFlow({key:"paginationChange",on:"paginationChange",steps:{blockLinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"blockLinkageRules",flowKey:"cardSettings",stepKey:"linkageRules"}},fieldslinkageRulesRefresh:{use:"linkageRulesRefresh",defaultParams:{actionName:"detailsFieldLinkageRules",flowKey:"detailsSettings",stepKey:"linkageRules"}}}});DetailsBlockModel.registerFlow({key:"initialPaginationChangeRefresh",sort:10001,steps:{refreshPaginationRelatedStates:{handler(e){return L(this,null,function*(){var t;if(e.model.hidden||!e.model.isMultiRecordResource()||e.model.hasDispatchedMultiRefresh())return;const o=e.model.resource;if(!o)return;const r=((t=o.dataLoadingMode)!=null?t:o.loadingMode)==="manual",i=typeof o.hasActiveFilters=="function"?o.hasActiveFilters():!1;!r||i||(yield dispatchEventDeep(e.model,"paginationChange"))})}}}});DetailsBlockModel.define({label:(0,import_flow_engine.tExpr)("Details"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search"),createModelOptions:{use:"DetailsBlockModel",subModels:{grid:{use:"DetailsGridModel"}}},sort:350});class DetailsCustomItemModel extends import_flow_engine.FlowModel{static defineChildren(t){const o=t.engine.filterModelClassByParent("CommonItemModel"),r=t.engine.filterModelClassByParent("DetailsCustomItemModel"),i=n=>Array.from(n.entries()).map(([l,a])=>{var c,u,d,m,p,h;const g=typeof a.defineChildren=="function"||!!((c=a.meta)!=null&&c.children),f={key:l,label:t.t(a.meta.label),sort:(u=a.meta.sort)!=null?u:999,searchable:!!((d=a.meta)!=null&&d.searchable),searchPlaceholder:(m=a.meta)==null?void 0:m.searchPlaceholder,hide:(p=a.meta)==null?void 0:p.hide};return g?f.children=_=>{var v;return typeof a.defineChildren=="function"?a.defineChildren(_):((v=a.meta)==null?void 0:v.children)||[]}:f.createModelOptions=((h=a.meta)==null?void 0:h.createModelOptions)||{use:l},f});return import_lodash.default.sortBy([...i(o),...i(r)],"sort")}}R(DetailsCustomItemModel,"renderMode",import_flow_engine.ModelRenderMode.RenderFunction);DetailsCustomItemModel.define({hide:!0,label:(0,import_flow_engine.tExpr)("Others")});class DetailsGridModel extends GridModel{constructor(){super(...arguments),R(this,"itemFallback",(0,import_jsx_runtime.jsx)(import_antd.Skeleton.Input,{block:!0,size:"small",style:{marginBottom:"0.5rem"}})),R(this,"itemSettingsMenuLevel",2),R(this,"itemFlowSettings",{showBackground:!0,style:{top:-6,left:-6,right:-6,bottom:-6}}),R(this,"dragOverlayConfig",{columnInsert:{before:{offsetTop:-12,height:24},after:{offsetTop:7,height:24}},columnEdge:{left:{offsetLeft:-5,width:24},right:{offsetLeft:8,width:24}},rowGap:{above:{offsetTop:0,height:24},below:{offsetTop:-14,height:24}}})}renderAddSubModelButton(){return this.context.flowSettingsEnabled?(0,import_jsx_runtime.jsx)(import_flow_engine.AddSubModelButton,{model:this,subModelKey:"items",subModelBaseClasses:[this.context.getModelClassName("DetailsItemModel"),this.context.getModelClassName("DetailsAssociationFieldGroupModel"),this.context.getModelClassName("DetailsCustomItemModel")].filter(Boolean),keepDropdownOpen:!0,children:(0,import_jsx_runtime.jsx)(import_flow_engine.FlowSettingsButton,{icon:(0,import_jsx_runtime.jsx)(import_icons.SettingOutlined,{}),children:this.translate("Fields")})}):null}render(){var t,o;const r=(t=this.props)==null?void 0:t.height,i=(o=this.props)==null?void 0:o.heightMode,n=this.context.themeToken,l=super.render();return i==="defaultHeight"?l:(0,import_jsx_runtime.jsx)("div",{style:{height:r,overflowY:"auto",marginLeft:`-${n.marginLG}px`,marginRight:`-${n.marginLG}px`,paddingLeft:`${n.marginLG}px`,paddingRight:`${n.marginLG}px`},children:l})}}DetailsGridModel.registerFlow({key:"detailFieldGridSettings",steps:{grid:{handler(e,t){e.model.setProps("rowGap",0),e.model.setProps("colGap",16)}}}});function transformChildrenToJS(e,t){const{fieldUseModel:o,refreshTargets:r}=t,i=n=>Array.isArray(n)?n.map(l=>{const a=x({},l);if(a.children)if(typeof a.children=="function"){const c=a.children;a.children=u=>L(this,null,function*(){const d=yield c(u);return i(d)})}else Array.isArray(a.children)&&(a.children=i(a.children));if(a.createModelOptions){const c=a.createModelOptions;a.createModelOptions=(u,d)=>L(this,null,function*(){const m=yield typeof c=="function"?c(u,d):c;return m.subModels=m.subModels||{},m.subModels.field=I(x({},m.subModels.field||{}),{use:o}),m}),a.refreshTargets=a.refreshTargets||r}return a}):[];return i(e)}function buildAssociationJSGroup(e,t,o){var r,i,n,l;const{fieldUseModel:a,refreshTargets:c}=o,u=(r=o.key)!=null?r:"js-association-fields",d=(i=o.label)!=null?i:(0,import_flow_engine.tExpr)("Display association fields"),m=(n=o.searchable)!=null?n:!0,p=(l=o.searchPlaceholder)!=null?l:(0,import_flow_engine.tExpr)("Search fields");return{key:u,type:"group",label:d,searchable:m,searchPlaceholder:p,children:h=>L(this,null,function*(){const g=yield t(h);return transformChildrenToJS(g,{fieldUseModel:a,refreshTargets:c})})}}function buildJSFieldMenuChildren(e,t){return L(this,null,function*(){var o;const{useModel:r,fieldUseModel:i,refreshTargets:n,associationPathName:l,associationProvider:a}=t,c=(0,import_flow_engine.buildWrapperFieldChildren)(e,{useModel:r,fieldUseModel:i,associationPathName:l,refreshTargets:n});let u=[];const d=(o=c==null?void 0:c[0])==null?void 0:o.children;if(Array.isArray(d)&&(u=d),!a)return u;const m=yield a(e);if(!Array.isArray(m)||m.length===0)return u;const p=buildAssociationJSGroup(e,a,{fieldUseModel:i,refreshTargets:n});return[...u,p]})}class DetailsJSFieldItemModel extends DetailsCustomItemModel{static defineChildren(t){return buildJSFieldMenuChildren(t,{useModel:"DetailsItemModel",fieldUseModel:"JSFieldModel",refreshTargets:["DetailsItemModel"],associationProvider:o=>DetailsAssociationFieldGroupModel.defineChildren(o)})}}DetailsJSFieldItemModel.define({label:(0,import_flow_engine.tExpr)("JS field"),searchable:!0,searchPlaceholder:(0,import_flow_engine.tExpr)("Search fields"),sort:110});class FilterFormFieldModel extends FieldModel{}class AssociationFieldModel extends FieldModel{constructor(){super(...arguments),R(this,"operator","$eq"),R(this,"updateAssociation",!0)}}AssociationFieldModel.registerFlow({key:"AssociationFieldInit",sort:800,steps:{init:{handler(e,t){return L(this,null,function*(){var o,r;if(e.model.updateAssociation){const i=e.model.context.blockModel,n=(o=i==null?void 0:i.context)==null?void 0:o.resource,l=(r=e.model.parent)==null?void 0:r.fieldPath;if(!n||!l)return;n.addUpdateAssociationValues(l)}})}},allowCreateCheck:{handler(e){return L(this,null,function*(){var t;const o=yield e.aclCheck({dataSourceKey:e.collectionField.dataSourceKey,resourceName:(t=e.collectionField)==null?void 0:t.target,actionName:"create"});e.model.setProps({allowCreate:!!o})})}}}});const isPlaceholderFieldName=(e,t)=>e===t,unwrapAssociationOptionRecord=e=>{if(e&&typeof e=="object"){const t=e.data;return t&&typeof t=="object"?t:e}};function normalizeFilterTargetKey$1(e){if(typeof e=="string"&&e)return e;if(Array.isArray(e)&&e.length===1&&typeof e[0]=="string")return e[0]}function normalizeAssociationFieldNames(e,t){var o;const r=typeof((o=t==null?void 0:t.titleCollectionField)==null?void 0:o.name)=="string"?t.titleCollectionField.name:void 0,i=normalizeFilterTargetKey$1(t==null?void 0:t.filterTargetKey)||"id",n=typeof(e==null?void 0:e.value)=="string"&&e.value&&!isPlaceholderFieldName(e.value,"value")?e.value:void 0,l=typeof(e==null?void 0:e.label)=="string"&&e.label&&!isPlaceholderFieldName(e.label,"label")?e.label:void 0,a=n||i;return{label:l||r||a,value:a}}function buildOpenerUids(e,t={}){var o,r,i,n,l,a;const c=!!t.navigation,u=_=>{if(Array.isArray(_))return _.filter(v=>typeof v=="string"&&!!v)},d=u((r=(o=e.view)==null?void 0:o.inputArgs)==null?void 0:r.openerUids),m=u(t.openerUids),p=d||m||[];if(c)return(m||p).filter(Boolean);const h=(n=(i=e.view)==null?void 0:i.inputArgs)==null?void 0:n.viewUid,g=(a=(l=e.model.context)==null?void 0:l.inputArgs)==null?void 0:a.viewUid,f=typeof h=="string"&&h?h:typeof g=="string"&&g?g:e.model.uid;return[...p,f].filter(Boolean)}function toSafeDisplayLabel(e){var t;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e)){const o=e.map(r=>{var i;if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r&&typeof r=="object"){const n=(i=r.label)!=null?i:r.name;if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n}}).filter(r=>r!==void 0);return o.length?o.map(String).join(", "):void 0}if(e&&typeof e=="object"){const o=(t=e.label)!=null?t:e.name;if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o}}function LabelByField(e){var t,o,r,i,n,l,a;const{option:c,fieldNames:u}=e,d=(0,import_flow_engine.useFlowModel)(),m=unwrapAssociationOptionRecord(c),p=normalizeAssociationFieldNames(u,(t=d.context.collectionField)==null?void 0:t.targetCollection),h=d.subModels.field,g=(r=(o=toSafeDisplayLabel(m==null?void 0:m[p.label]))!=null?o:toSafeDisplayLabel(m==null?void 0:m.label))!=null?r:toSafeDisplayLabel(m==null?void 0:m[p.value]);if(!h)return(0,import_jsx_runtime.jsx)("span",{children:g??"N/A"});const f=String((n=(i=m==null?void 0:m[p.value])!=null?i:g)!=null?n:"association-option"),_=h.createFork({},f);_.context.defineProperty("record",{get:()=>m,cache:!1,meta:(0,import_flow_engine.createCurrentRecordMetaFactory)(_.context,()=>_.context.collection)});const v=(a=(l=d.context.collectionField.targetCollection)==null?void 0:l.getField)==null?void 0:a.call(l,p.label),b=v&&typeof v.getComponentProps=="function"?v.getComponentProps():{};_.setProps(x({value:g,clickToOpen:!1},b));const F=g!==null&&typeof g<"u"&&g!==""?_.render():"N/A";return(0,import_jsx_runtime.jsx)("span",{style:{pointerEvents:"none"},children:F})}function toSelectValue(e,t,o=!1,r="record",i=[]){if(!e)return o?[]:void 0;const{value:n}=t||{},l=c=>typeof c=="object"&&c!==null,a=c=>{if(l(c))return{label:(0,import_jsx_runtime.jsx)(LabelByField,{option:c,fieldNames:t}),value:c[n]}};if(r==="value"){const c=u=>{if(typeof u=="object"&&u!==null)return a(u);const d=i.find(m=>(m==null?void 0:m[n])===u);return d?a(d):{label:String(u),value:u}};return o?Array.isArray(e)?e.map(u=>c(u)).filter(Boolean):[]:Array.isArray(e)?c(e[0]):c(e)}if(o)return Array.isArray(e)?e.filter(l).map(a).filter(Boolean):[];if(Array.isArray(e)){const c=e[0];return l(c)?a(c):void 0}return l(e)?a(e):void 0}function resolveOptions(e,t,o){return e!=null&&e.length?e.map(r=>(0,import_lodash.omit)(r,"disabled","options","style")):o?Array.isArray(t)?t.filter(r=>typeof r=="object"&&r!==null):[]:t&&typeof t=="object"?[t]:[]}const labelClassName=import_css.css`
1848
1848
  div {
1849
1849
  white-space: nowrap !important;
1850
1850
  overflow: hidden;