@gisce/react-ooui 1.1.15 → 1.1.16

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.
@@ -112,7 +112,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
112
112
  .ant-progress-text {
113
113
  display: none;
114
114
  }
115
- `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx("div",{style:{whiteSpace:"pre-line"},children:e}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:p={},onChangeSort:m,sorter:h,onFetchChildrenForRecord:v,childField:C}=e,[I,g]=React.useState([]),[x,y]=React.useState([]),O=React.useRef(!1),b=React.useRef(null),{t:E}=React.useContext(LocaleContext),w=React.useRef(t);React.useEffect(()=>{b.current=getTree(r);const $=getTableColumns(b.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});y($)},[r]),React.useEffect(()=>{O.current=!1;const $=getTableItems(b.current,a);g($),w.current=t},[a]);const _=(n-1)*w.current+1,S=_-1+I.length,k=o===void 0?null:o===0?E("no_results"):E("summary").replace("{from}",_==null?void 0:_.toString()).replace("{to}",S==null?void 0:S.toString()).replace("{total}",o==null?void 0:o.toString()),N=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:w.current,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:k})]});function M(){var G;const L=b.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!L||L.length===0)return null;let D=[],U=((G=d==null?void 0:d.selectedRowKeys)==null?void 0:G.length)>0?I.filter(z=>d==null?void 0:d.selectedRowKeys.includes(z.id)):I;return L.forEach(z=>{const W=U.reduce((Z,V)=>V[z.field]&&!isNaN(V[z.field])?Z+V[z.field]:Z,0);D.push(`${z.label}: ${Math.round(W*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:D.join(", ")})}let j,B=f;if(b.current!==null){j=calculateColumnsWidth(x,I,600);const L=b.current;f&&L.columns.some(D=>D.sum!==void 0)&&(B=f-30)}return b.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[N(),jsxRuntime.jsx(reactFormigaTable.Table,{height:B,columns:j.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:$=>{if(p[$.id])return{color:p[$.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:m,sorter:h,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),M()]})}function SearchTree(e,n){const{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:p}=e,[m,h]=React.useState(!1),[v,C]=React.useState(!1),I=React.useRef(!1),[g,x]=React.useState(),[y,O]=React.useState(),[b,E]=React.useState(),[w,_]=React.useState(),[S,k]=React.useState(200),N=React.useRef(),{height:M}=useWindowDimensions(),j=React.useContext(ContentRootContext),{processAction:B}=j||{},$=React.useContext(ActionViewContext),{setResults:L=void 0,setCurrentItemIndex:D=void 0,currentId:U=void 0,results:G=void 0,selectedRowItems:z=void 0,setSelectedRowItems:W=void 0,searchParams:Z=[],setSearchParams:V=void 0,searchVisible:H=!0,setSearchVisible:P=void 0,sorter:A=void 0,setSorter:q=void 0,setTotalItems:K=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:F=void 0,searchValues:T={},setSearchValues:Y=void 0,limit:Q=DEFAULT_SEARCH_LIMIT$1,setLimit:te=void 0}=(d?$:{})||{},{submit:J,clear:ee,fetchResults:re,tableRefreshing:ce,searchFilterLoading:ae,searchError:pe,page:he,offset:ie,getResults:de,requestPageChange:ge,changeSort:me,fetchChildrenForRecord:xe,colorsForResults:ve,totalItems:_e}=useSearch({model:g,setSearchTreeNameSearch:X,setSelectedRowItems:W,setSearchParams:V,setSearchValues:Y,searchParams:Z,setSearchVisible:P,setTreeIsLoading:F,nameSearch:s,searchNameGetDoneRef:I,context:f,formView:b,treeView:y,sorter:A,setSorter:q,setCurrentItemIndex:D,setResultsActionView:L,resultsActionView:G,domain:c,currentId:U,setActionViewTotalItems:K,limit:Q,setLimit:te});React.useImperativeHandle(n,()=>({refreshResults:()=>{I.current=!1,re()}})),React.useEffect(()=>{!v||u&&(I.current=!1,re())},[he,ie,v,u,s]);const we=async()=>{C(!1),h(!0),_(void 0),F==null||F(!0);try{await se(),C(!0)}catch(Re){_(Re)}finally{h(!1),F==null||F(!1)}},se=async()=>{x(t);let Re=o;o||(Re=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let Se=r;r||(Se=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),E(Re),O(Se)};React.useEffect(()=>{we()},[t]);const le=Re=>{te==null||te(Re)},Ie=async Re=>{const{id:Se}=Re;N.current||(N.current=await ConnectionProvider.getHandler().treeButOpen({id:y.view_id,model:g,context:f}));const Ee=N.current[0][2];await(B==null?void 0:B({actionData:Ee,fields:y.fields,values:{active_id:Se,...Re},context:f}))},ye=async Re=>{const{id:Se}=Re;if(y!=null&&y.isExpandable){try{await Ie(Re)}catch(Ee){showDialog$8(Ee)}return}a({id:Se,model:g,formView:b,treeView:y})};function Oe(Re){const Se=de().filter(Ee=>Re.includes(Ee.id));W==null||W(Se),p==null||p(Re)}function be(){return y!=null&&y.isExpandable?M-160:M-(S+210)}const Fe=()=>!y||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...y.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,y.search_fields]),onClear:ee,limit:Q,offset:ie,isSearching:ae,onSubmit:J,onLimitChange:le,setSearchFilterHeight:k,searchError:pe,searchVisible:H,searchValues:T}),jsxRuntime.jsx(Tree,{total:_e,limit:Q,page:he,treeView:y,results:de(),onRequestPageChange:ge,loading:ce,onRowClicked:ye,scrollY:l||be(),colorsForResults:ve,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Re=>Re.id),onChange:Oe},sorter:A,onChangeSort:me,onFetchChildrenForRecord:y.isExpandable?xe:void 0,childField:y.field_parent})]}),Te=w||pe;return Te?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Te,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:m?jsxRuntime.jsx(antd.Spin,{}):Fe()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:p}=React.useContext(LocaleContext),[m,h]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},C=async x=>{const{id:y}=x;o([y])};function I(){if(m.length===0){v();return}o(m)}const g=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{h(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:p("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{I()},type:"primary",children:p("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:p("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:p("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:g()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,p]=React.useState(!1),[m,h]=React.useState(!1),[v,C]=React.useState(!1),[I,g]=React.useState(),x=React.useRef(!1),[y,O]=React.useState(""),b=React.useRef(),E=React.useContext(FormContext$1),{domain:w,getValues:_,getFields:S,getContext:k,setOriginalValue:N,elementHasLostFocus:M}=E||{},j=React.useRef([]),[B,$]=React.useState([]),L=n&&n[0]||void 0,D=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&Z(n)},[n]),React.useEffect(()=>{L&&D.length===0?Z(L):L&&D.length>0?O(D):!L&&!D&&O(b.current||"")},[n]);const U=A=>{t==null||t(A),M==null||M()},G=A=>{b.current=A.target.value,U([void 0,""])},z=async()=>{if(!v&&y!==D){if(await new Promise(A=>setTimeout(A,100)),x.current){U([void 0,""]);return}C(!0);try{if(j.current&&j.current.length>0)W(b.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:b.current,context:{...k==null?void 0:k(),...l}});A.length===1?(b.current=void 0,U(A[0])):W(b.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},W=async A=>{if(await V(),j.current&&j.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:j.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});q.length===1?Z(q[0],!0):(g(A),p(!0));return}g(A),p(!0)},Z=async(A,q)=>{C(!0);try{const K=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});U([A,K[0][1]]),q&&N(o.id,[A,K[0][1]])}catch(K){showDialog$3(K)}finally{C(!1)}};async function V(){u&&(j.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:S(),values:_()}),fields:S(),context:k()})),w&&w.length>0&&(j.current=j.current.concat(ooui.transformDomainForChildWidget({domain:w,widgetFieldName:c}))),$(j.current)}async function H(A){A.keyCode===13?(A.preventDefault(),A.stopPropagation(),await z()):A.code==="Backspace"&&L!==void 0&&(A.preventDefault(),A.stopPropagation(),U([void 0,""]))}const P=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(P,{type:"text",value:y,disabled:s,onChange:G,className:d,onBlur:z,onKeyDown:H,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:L,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:L===void 0||D===""||y===void 0,onClick:()=>{h(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,W(D)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:L?void 0:I,onSelectValues:A=>{p(!1),Z(A[0]),x.current=!1,b.current=void 0},onCloseModal:()=>{p(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:m,onSubmitSucceed:A=>{h(!1),Z(A)},onCancel:()=>{h(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
115
+ `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx(interweave.Interweave,{content:e==null?void 0:e.replace(/(?:\r\n|\r|\n)/g,"<br>")}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:p={},onChangeSort:m,sorter:h,onFetchChildrenForRecord:v,childField:C}=e,[I,g]=React.useState([]),[x,y]=React.useState([]),O=React.useRef(!1),b=React.useRef(null),{t:E}=React.useContext(LocaleContext),w=React.useRef(t);React.useEffect(()=>{b.current=getTree(r);const $=getTableColumns(b.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});y($)},[r]),React.useEffect(()=>{O.current=!1;const $=getTableItems(b.current,a);g($),w.current=t},[a]);const _=(n-1)*w.current+1,S=_-1+I.length,k=o===void 0?null:o===0?E("no_results"):E("summary").replace("{from}",_==null?void 0:_.toString()).replace("{to}",S==null?void 0:S.toString()).replace("{total}",o==null?void 0:o.toString()),N=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:w.current,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:k})]});function M(){var G;const L=b.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!L||L.length===0)return null;let D=[],U=((G=d==null?void 0:d.selectedRowKeys)==null?void 0:G.length)>0?I.filter(z=>d==null?void 0:d.selectedRowKeys.includes(z.id)):I;return L.forEach(z=>{const W=U.reduce((Z,V)=>V[z.field]&&!isNaN(V[z.field])?Z+V[z.field]:Z,0);D.push(`${z.label}: ${Math.round(W*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:D.join(", ")})}let j,B=f;if(b.current!==null){j=calculateColumnsWidth(x,I,600);const L=b.current;f&&L.columns.some(D=>D.sum!==void 0)&&(B=f-30)}return b.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[N(),jsxRuntime.jsx(reactFormigaTable.Table,{height:B,columns:j.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:$=>{if(p[$.id])return{color:p[$.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:m,sorter:h,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),M()]})}function SearchTree(e,n){const{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:p}=e,[m,h]=React.useState(!1),[v,C]=React.useState(!1),I=React.useRef(!1),[g,x]=React.useState(),[y,O]=React.useState(),[b,E]=React.useState(),[w,_]=React.useState(),[S,k]=React.useState(200),N=React.useRef(),{height:M}=useWindowDimensions(),j=React.useContext(ContentRootContext),{processAction:B}=j||{},$=React.useContext(ActionViewContext),{setResults:L=void 0,setCurrentItemIndex:D=void 0,currentId:U=void 0,results:G=void 0,selectedRowItems:z=void 0,setSelectedRowItems:W=void 0,searchParams:Z=[],setSearchParams:V=void 0,searchVisible:H=!0,setSearchVisible:P=void 0,sorter:A=void 0,setSorter:q=void 0,setTotalItems:K=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:F=void 0,searchValues:T={},setSearchValues:Y=void 0,limit:Q=DEFAULT_SEARCH_LIMIT$1,setLimit:te=void 0}=(d?$:{})||{},{submit:J,clear:ee,fetchResults:re,tableRefreshing:ce,searchFilterLoading:ae,searchError:pe,page:he,offset:ie,getResults:de,requestPageChange:ge,changeSort:me,fetchChildrenForRecord:xe,colorsForResults:ve,totalItems:_e}=useSearch({model:g,setSearchTreeNameSearch:X,setSelectedRowItems:W,setSearchParams:V,setSearchValues:Y,searchParams:Z,setSearchVisible:P,setTreeIsLoading:F,nameSearch:s,searchNameGetDoneRef:I,context:f,formView:b,treeView:y,sorter:A,setSorter:q,setCurrentItemIndex:D,setResultsActionView:L,resultsActionView:G,domain:c,currentId:U,setActionViewTotalItems:K,limit:Q,setLimit:te});React.useImperativeHandle(n,()=>({refreshResults:()=>{I.current=!1,re()}})),React.useEffect(()=>{!v||u&&(I.current=!1,re())},[he,ie,v,u,s]);const we=async()=>{C(!1),h(!0),_(void 0),F==null||F(!0);try{await se(),C(!0)}catch(Re){_(Re)}finally{h(!1),F==null||F(!1)}},se=async()=>{x(t);let Re=o;o||(Re=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let Se=r;r||(Se=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),E(Re),O(Se)};React.useEffect(()=>{we()},[t]);const le=Re=>{te==null||te(Re)},Ie=async Re=>{const{id:Se}=Re;N.current||(N.current=await ConnectionProvider.getHandler().treeButOpen({id:y.view_id,model:g,context:f}));const Ee=N.current[0][2];await(B==null?void 0:B({actionData:Ee,fields:y.fields,values:{active_id:Se,...Re},context:f}))},ye=async Re=>{const{id:Se}=Re;if(y!=null&&y.isExpandable){try{await Ie(Re)}catch(Ee){showDialog$8(Ee)}return}a({id:Se,model:g,formView:b,treeView:y})};function Oe(Re){const Se=de().filter(Ee=>Re.includes(Ee.id));W==null||W(Se),p==null||p(Re)}function be(){return y!=null&&y.isExpandable?M-160:M-(S+210)}const Fe=()=>!y||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...y.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,y.search_fields]),onClear:ee,limit:Q,offset:ie,isSearching:ae,onSubmit:J,onLimitChange:le,setSearchFilterHeight:k,searchError:pe,searchVisible:H,searchValues:T}),jsxRuntime.jsx(Tree,{total:_e,limit:Q,page:he,treeView:y,results:de(),onRequestPageChange:ge,loading:ce,onRowClicked:ye,scrollY:l||be(),colorsForResults:ve,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Re=>Re.id),onChange:Oe},sorter:A,onChangeSort:me,onFetchChildrenForRecord:y.isExpandable?xe:void 0,childField:y.field_parent})]}),Te=w||pe;return Te?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Te,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:m?jsxRuntime.jsx(antd.Spin,{}):Fe()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:p}=React.useContext(LocaleContext),[m,h]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},C=async x=>{const{id:y}=x;o([y])};function I(){if(m.length===0){v();return}o(m)}const g=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{h(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:p("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{I()},type:"primary",children:p("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:p("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:p("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:g()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,p]=React.useState(!1),[m,h]=React.useState(!1),[v,C]=React.useState(!1),[I,g]=React.useState(),x=React.useRef(!1),[y,O]=React.useState(""),b=React.useRef(),E=React.useContext(FormContext$1),{domain:w,getValues:_,getFields:S,getContext:k,setOriginalValue:N,elementHasLostFocus:M}=E||{},j=React.useRef([]),[B,$]=React.useState([]),L=n&&n[0]||void 0,D=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&Z(n)},[n]),React.useEffect(()=>{L&&D.length===0?Z(L):L&&D.length>0?O(D):!L&&!D&&O(b.current||"")},[n]);const U=A=>{t==null||t(A),M==null||M()},G=A=>{b.current=A.target.value,U([void 0,""])},z=async()=>{if(!v&&y!==D){if(await new Promise(A=>setTimeout(A,100)),x.current){U([void 0,""]);return}C(!0);try{if(j.current&&j.current.length>0)W(b.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:b.current,context:{...k==null?void 0:k(),...l}});A.length===1?(b.current=void 0,U(A[0])):W(b.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},W=async A=>{if(await V(),j.current&&j.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:j.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});q.length===1?Z(q[0],!0):(g(A),p(!0));return}g(A),p(!0)},Z=async(A,q)=>{C(!0);try{const K=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});U([A,K[0][1]]),q&&N(o.id,[A,K[0][1]])}catch(K){showDialog$3(K)}finally{C(!1)}};async function V(){u&&(j.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:S(),values:_()}),fields:S(),context:k()})),w&&w.length>0&&(j.current=j.current.concat(ooui.transformDomainForChildWidget({domain:w,widgetFieldName:c}))),$(j.current)}async function H(A){A.keyCode===13?(A.preventDefault(),A.stopPropagation(),await z()):A.code==="Backspace"&&L!==void 0&&(A.preventDefault(),A.stopPropagation(),U([void 0,""]))}const P=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(P,{type:"text",value:y,disabled:s,onChange:G,className:d,onBlur:z,onKeyDown:H,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:L,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:L===void 0||D===""||y===void 0,onClick:()=>{h(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,W(D)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:L?void 0:I,onSelectValues:A=>{p(!1),Z(A[0]),x.current=!1,b.current=void 0},onCloseModal:()=>{p(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:m,onSubmitSucceed:A=>{h(!1),Z(A)},onCancel:()=>{h(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
116
116
  .ant-input {
117
117
  background-color: ${Config.requiredColor};
118
118
  }