@object-ui/console 1.0.0
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/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/assets/AdvancedChartImpl-DAS1mU9o.js +7 -0
- package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.br +0 -0
- package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.gz +0 -0
- package/dist/assets/AuditLogPage-BQW_Xbnm.js +1 -0
- package/dist/assets/AuditLogPage-BQW_Xbnm.js.br +0 -0
- package/dist/assets/AuditLogPage-BQW_Xbnm.js.gz +0 -0
- package/dist/assets/ChartImpl-2ivTljUi.js +1 -0
- package/dist/assets/ChartImpl-2ivTljUi.js.br +0 -0
- package/dist/assets/ChartImpl-2ivTljUi.js.gz +0 -0
- package/dist/assets/DashboardView-Dt-4VhH6.js +1 -0
- package/dist/assets/DashboardView-Dt-4VhH6.js.br +0 -0
- package/dist/assets/DashboardView-Dt-4VhH6.js.gz +0 -0
- package/dist/assets/ForgotPasswordPage-zr9S5vrE.js +1 -0
- package/dist/assets/KanbanEnhanced-BlGp--J7.js +1 -0
- package/dist/assets/KanbanEnhanced-BlGp--J7.js.br +0 -0
- package/dist/assets/KanbanEnhanced-BlGp--J7.js.gz +0 -0
- package/dist/assets/KanbanImpl-B5wWMXrJ.js +1 -0
- package/dist/assets/KanbanImpl-B5wWMXrJ.js.br +0 -0
- package/dist/assets/KanbanImpl-B5wWMXrJ.js.gz +0 -0
- package/dist/assets/LoginPage-H688gsah.js +1 -0
- package/dist/assets/MarkdownImpl-BshtTFK2.js +29 -0
- package/dist/assets/MarkdownImpl-BshtTFK2.js.br +0 -0
- package/dist/assets/MarkdownImpl-BshtTFK2.js.gz +0 -0
- package/dist/assets/OrgManagementPage-x3qIkxHL.js +1 -0
- package/dist/assets/OrgManagementPage-x3qIkxHL.js.br +0 -0
- package/dist/assets/OrgManagementPage-x3qIkxHL.js.gz +0 -0
- package/dist/assets/PageView-BRN1h8QD.js +1 -0
- package/dist/assets/PageView-BRN1h8QD.js.br +0 -0
- package/dist/assets/PageView-BRN1h8QD.js.gz +0 -0
- package/dist/assets/ProfilePage-DjAiGvFb.js +1 -0
- package/dist/assets/ProfilePage-DjAiGvFb.js.br +0 -0
- package/dist/assets/ProfilePage-DjAiGvFb.js.gz +0 -0
- package/dist/assets/RecordDetailView-Bfu7541n.js +1 -0
- package/dist/assets/RecordDetailView-Bfu7541n.js.br +0 -0
- package/dist/assets/RecordDetailView-Bfu7541n.js.gz +0 -0
- package/dist/assets/RegisterPage-CR91Lc7x.js +1 -0
- package/dist/assets/ReportView-CwWsv2yl.js +1 -0
- package/dist/assets/ReportView-CwWsv2yl.js.br +0 -0
- package/dist/assets/ReportView-CwWsv2yl.js.gz +0 -0
- package/dist/assets/RoleManagementPage-DnWuzxKJ.js +1 -0
- package/dist/assets/RoleManagementPage-DnWuzxKJ.js.br +0 -0
- package/dist/assets/RoleManagementPage-DnWuzxKJ.js.gz +0 -0
- package/dist/assets/SearchResultsPage-DBpjAlh2.js +1 -0
- package/dist/assets/SearchResultsPage-DBpjAlh2.js.br +0 -0
- package/dist/assets/SearchResultsPage-DBpjAlh2.js.gz +0 -0
- package/dist/assets/UserManagementPage-o0_K0dzR.js +1 -0
- package/dist/assets/UserManagementPage-o0_K0dzR.js.br +0 -0
- package/dist/assets/UserManagementPage-o0_K0dzR.js.gz +0 -0
- package/dist/assets/ViewDesignerPage-BbwrZa9D.js +1 -0
- package/dist/assets/ViewDesignerPage-BbwrZa9D.js.br +0 -0
- package/dist/assets/ViewDesignerPage-BbwrZa9D.js.gz +0 -0
- package/dist/assets/data-adapter-Cn800k4a.js +1 -0
- package/dist/assets/data-adapter-Cn800k4a.js.br +0 -0
- package/dist/assets/data-adapter-Cn800k4a.js.gz +0 -0
- package/dist/assets/framework-mHWN965c.js +10 -0
- package/dist/assets/framework-mHWN965c.js.br +0 -0
- package/dist/assets/framework-mHWN965c.js.gz +0 -0
- package/dist/assets/index-BjEGJcpx.js +56 -0
- package/dist/assets/index-BjEGJcpx.js.br +0 -0
- package/dist/assets/index-BjEGJcpx.js.gz +0 -0
- package/dist/assets/index-CUnVdETN.css +1 -0
- package/dist/assets/index-CUnVdETN.css.br +0 -0
- package/dist/assets/index-CUnVdETN.css.gz +0 -0
- package/dist/assets/infrastructure-aS2LF8OZ.js +1 -0
- package/dist/assets/infrastructure-aS2LF8OZ.js.br +0 -0
- package/dist/assets/infrastructure-aS2LF8OZ.js.gz +0 -0
- package/dist/assets/maplibre-gl-D2AsLM0J.js +811 -0
- package/dist/assets/maplibre-gl-D2AsLM0J.js.br +0 -0
- package/dist/assets/maplibre-gl-D2AsLM0J.js.gz +0 -0
- package/dist/assets/plugins-core-CcBSZCjG.js +4 -0
- package/dist/assets/plugins-core-CcBSZCjG.js.br +0 -0
- package/dist/assets/plugins-core-CcBSZCjG.js.gz +0 -0
- package/dist/assets/plugins-views-DQwkCaaO.js +60 -0
- package/dist/assets/plugins-views-DQwkCaaO.js.br +0 -0
- package/dist/assets/plugins-views-DQwkCaaO.js.gz +0 -0
- package/dist/assets/plugins-views-P3eB-els.css +1 -0
- package/dist/assets/plugins-views-P3eB-els.css.br +0 -0
- package/dist/assets/plugins-views-P3eB-els.css.gz +0 -0
- package/dist/assets/systemObjects-DSpePIIy.js +1 -0
- package/dist/assets/systemObjects-DSpePIIy.js.br +2 -0
- package/dist/assets/systemObjects-DSpePIIy.js.gz +0 -0
- package/dist/assets/ui-components-DVonQS7H.js +31 -0
- package/dist/assets/ui-components-DVonQS7H.js.br +0 -0
- package/dist/assets/ui-components-DVonQS7H.js.gz +0 -0
- package/dist/assets/ui-components-GrNdJOi1.css +1 -0
- package/dist/assets/ui-components-GrNdJOi1.css.br +0 -0
- package/dist/assets/ui-components-GrNdJOi1.css.gz +0 -0
- package/dist/assets/ui-layout-BENIRxAF.js +1 -0
- package/dist/assets/ui-layout-BENIRxAF.js.br +0 -0
- package/dist/assets/ui-layout-BENIRxAF.js.gz +0 -0
- package/dist/assets/vendor-charts-CSvoW-yB.js +65 -0
- package/dist/assets/vendor-charts-CSvoW-yB.js.br +0 -0
- package/dist/assets/vendor-charts-CSvoW-yB.js.gz +0 -0
- package/dist/assets/vendor-dndkit-DRGpK6sP.js +5 -0
- package/dist/assets/vendor-dndkit-DRGpK6sP.js.br +0 -0
- package/dist/assets/vendor-dndkit-DRGpK6sP.js.gz +0 -0
- package/dist/assets/vendor-i18n-D5KbMT7w.js +9 -0
- package/dist/assets/vendor-i18n-D5KbMT7w.js.br +0 -0
- package/dist/assets/vendor-i18n-D5KbMT7w.js.gz +0 -0
- package/dist/assets/vendor-icons-CQ8b-fGy.js +8671 -0
- package/dist/assets/vendor-icons-CQ8b-fGy.js.br +0 -0
- package/dist/assets/vendor-icons-CQ8b-fGy.js.gz +0 -0
- package/dist/assets/vendor-objectstack-DqojdwYW.js +37 -0
- package/dist/assets/vendor-objectstack-DqojdwYW.js.br +0 -0
- package/dist/assets/vendor-objectstack-DqojdwYW.js.gz +0 -0
- package/dist/assets/vendor-radix-BbeYj_o4.js +56 -0
- package/dist/assets/vendor-radix-BbeYj_o4.js.br +0 -0
- package/dist/assets/vendor-radix-BbeYj_o4.js.gz +0 -0
- package/dist/assets/vendor-react-Dy_xkBQQ.js +60 -0
- package/dist/assets/vendor-react-Dy_xkBQQ.js.br +0 -0
- package/dist/assets/vendor-react-Dy_xkBQQ.js.gz +0 -0
- package/dist/assets/vendor-ui-utils-h6yAcIi9.js +1 -0
- package/dist/assets/vendor-ui-utils-h6yAcIi9.js.br +0 -0
- package/dist/assets/vendor-ui-utils-h6yAcIi9.js.gz +0 -0
- package/dist/assets/vendor-zod-Dpl-cylz.js +39 -0
- package/dist/assets/vendor-zod-Dpl-cylz.js.br +0 -0
- package/dist/assets/vendor-zod-Dpl-cylz.js.gz +0 -0
- package/dist/index.html +49 -0
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/manifest.json +19 -0
- package/dist/mockServiceWorker.js +349 -0
- package/dist/mockServiceWorker.js.br +0 -0
- package/dist/mockServiceWorker.js.gz +0 -0
- package/dist/stats.html +4949 -0
- package/package.json +98 -0
- package/plugin.ts +177 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./vendor-react-Dy_xkBQQ.js";import{u as i}from"./infrastructure-aS2LF8OZ.js";import{B as c,Y as d,Z as o,a1 as x}from"./ui-components-DVonQS7H.js";import"./framework-mHWN965c.js";import"./vendor-ui-utils-h6yAcIi9.js";import{s as p}from"./systemObjects-DSpePIIy.js";import{bu as a,m as h}from"./vendor-icons-CQ8b-fGy.js";import"./vendor-i18n-D5KbMT7w.js";import"./vendor-radix-BbeYj_o4.js";import"./vendor-charts-CSvoW-yB.js";const r=p.find(s=>s.name==="sys_user");function k(){const{user:s}=i(),m=s?.role==="admin";return e.jsxs("div",{className:"flex flex-col gap-4 sm:gap-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"bg-primary/10 p-2 rounded-md shrink-0",children:e.jsx(a,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"User Management"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Manage system users and their roles"})]})]}),m&&e.jsxs(c,{size:"sm",className:"shrink-0 gap-2",children:[e.jsx(h,{className:"h-4 w-4"}),"Add User"]})]}),e.jsx(d,{children:e.jsx(o,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b bg-muted/50",children:r.views[0].columns.map(t=>{const n=r.fields.find(l=>l.name===t);return e.jsx("th",{className:"h-10 px-3 sm:px-4 text-left font-medium text-muted-foreground whitespace-nowrap",children:n?.label??t},t)})})}),e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{className:"p-4 sm:p-6 text-center text-sm text-muted-foreground",colSpan:r.views[0].columns.length,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[e.jsx(a,{className:"h-8 w-8 text-muted-foreground/50"}),e.jsx("p",{children:"Connect to ObjectStack server to load users."}),e.jsx(x,{variant:"secondary",className:"text-xs",children:"plugin-grid powered"})]})})})})]})})})})]})}export{k as UserManagementPage};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as l,i as it,h as ot,j as Ae}from"./vendor-react-Dy_xkBQQ.js";import{C as we}from"./framework-mHWN965c.js";import{d as ue,c as pe,b as dt}from"./vendor-ui-utils-h6yAcIi9.js";import{aQ as ct,aR as je,aS as Ne,aT as Ce,aU as ke,aV as ut,ar as pt,ap as ce,aW as mt,aX as xt,aY as Be,aj as ht,ak as bt,aZ as gt,a_ as qe,a$ as ft,b0 as _e,b1 as yt,b2 as vt,b3 as Je,b4 as wt,aq as de,b5 as jt,b6 as Nt,b7 as Ct,b8 as kt,b9 as Ue,an as St,ba as He,bb as Qe,bc as et,bd as tt,be as Dt,bf as Tt,bg as Ft,bh as Re,bi as Ge,bj as It,bk as Pt,bl as Et,bm as $t,bn as Ve,bo as Ot,bp as zt,bq as At,br as Mt,bs as Rt,bt as Gt}from"./vendor-icons-CQ8b-fGy.js";var Xe={exports:{}},ye={},Ke;function Ut(){if(Ke)return ye;Ke=1;var o=Symbol.for("react.transitional.element"),A=Symbol.for("react.fragment");function F(C,b,$){var f=null;if($!==void 0&&(f=""+$),b.key!==void 0&&(f=""+b.key),"key"in b){$={};for(var g in b)g!=="key"&&($[g]=b[g])}else $=b;return b=$.ref,{$$typeof:o,type:C,key:f,ref:b!==void 0?b:null,props:$}}return ye.Fragment=A,ye.jsx=F,ye.jsxs=F,ye}var Ye;function Lt(){return Ye||(Ye=1,Xe.exports=Ut()),Xe.exports}var e=Lt();function Se(o,A={}){const{maxHistory:F=50}=A,[C,b]=l.useState(o),$=l.useRef([]),f=l.useRef([]),g=l.useCallback(c=>{b(d=>($.current=[...$.current.slice(-(F-1)),d],f.current=[],c))},[F]),v=l.useCallback(()=>{$.current.length!==0&&b(c=>{const d=[...$.current],j=d.pop();return $.current=d,f.current=[c,...f.current],j})},[]),s=l.useCallback(()=>{f.current.length!==0&&b(c=>{const d=[...f.current],j=d.shift();return f.current=d,$.current=[...$.current,c],j})},[]),y=l.useCallback(c=>{$.current=[],f.current=[],b(c)},[]);return{current:C,canUndo:$.current.length>0,canRedo:f.current.length>0,undoCount:$.current.length,redoCount:f.current.length,push:g,undo:v,redo:s,reset:y}}function De(){const[o,A]=l.useState(!1),[F,C]=l.useState(""),[b,$]=l.useState(""),f=l.useRef(null),g=l.useCallback((y,c)=>(C(y),$(c),A(!0),new Promise(d=>{f.current=d})),[]),v=l.useCallback(()=>{A(!1),f.current?.(!0),f.current=null},[]),s=l.useCallback(()=>{A(!1),f.current?.(!1),f.current=null},[]);return{isOpen:o,title:F,message:b,confirm:g,onConfirm:v,onCancel:s}}function $e(){const[o,A]=l.useState(new Set),F=l.useCallback((g,v=!1)=>{A(s=>{const y=new Set(v?s:[]);return s.has(g)&&v?y.delete(g):y.add(g),y})},[]),C=l.useCallback(g=>{A(new Set([g]))},[]),b=l.useCallback(g=>{A(new Set(g))},[]),$=l.useCallback(()=>{A(new Set)},[]),f=l.useCallback(g=>o.has(g),[o]);return{selectedIds:o,toggle:F,selectOne:C,selectMany:b,clearSelection:$,isSelected:f,count:o.size}}function Te(){const[o,A]=l.useState(null),F=l.useCallback(b=>{A(structuredClone(b))},[]),C=l.useCallback(()=>o?structuredClone(o):null,[o]);return{clipboard:o,copy:F,paste:C,hasContent:o!==null}}function Le(o={}){const{minZoom:A=.25,maxZoom:F=3,zoomStep:C=.1,initialZoom:b=1}=o,[$,f]=l.useState(b),[g,v]=l.useState({x:0,y:0}),s=l.useRef(!1),y=l.useRef({x:0,y:0}),c=l.useCallback(k=>Math.min(F,Math.max(A,+k.toFixed(2))),[A,F]),d=l.useCallback(()=>f(k=>c(k+C)),[c,C]),j=l.useCallback(()=>f(k=>c(k-C)),[c,C]),p=l.useCallback(()=>{f(1),v({x:0,y:0})},[]),x=l.useCallback(k=>f(c(k)),[c]),I=l.useCallback(k=>{if(k.ctrlKey||k.metaKey){k.preventDefault();const E=k.deltaY>0?-C:C;f(N=>c(N+E))}},[c,C]),P=l.useCallback(k=>{if(k.button===1||k.button===0&&k.altKey){k.preventDefault(),s.current=!0,y.current={x:k.clientX,y:k.clientY};const E=L=>{if(!s.current)return;const H=L.clientX-y.current.x,G=L.clientY-y.current.y;y.current={x:L.clientX,y:L.clientY},v(Z=>({x:Z.x+H,y:Z.y+G}))},N=()=>{s.current=!1,document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",N)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",N)}},[]),O={transform:`translate(${g.x}px, ${g.y}px) scale(${$})`,transformOrigin:"0 0"};return{zoom:$,panOffset:g,zoomIn:d,zoomOut:j,resetZoom:p,setZoom:x,handleWheel:I,startPan:P,transformStyle:O}}function Zt(...o){return ue(pe(o))}function Fe({isOpen:o,title:A,message:F,confirmLabel:C="Delete",cancelLabel:b="Cancel",destructive:$=!0,onConfirm:f,onCancel:g}){const v=l.useRef(null);return l.useEffect(()=>{const s=v.current;s&&(o&&!s.open?s.showModal():!o&&s.open&&s.close())},[o]),o?e.jsx("dialog",{ref:v,className:"fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50",onClose:g,"aria-labelledby":"confirm-title","aria-describedby":"confirm-message",children:e.jsxs("div",{className:"w-80 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[$&&e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(jt,{className:"h-5 w-5 text-destructive"})}),e.jsx("h2",{id:"confirm-title",className:"text-lg font-semibold",children:A})]}),e.jsx("p",{id:"confirm-message",className:"text-sm text-muted-foreground mb-6",children:F}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:g,className:"px-4 py-2 text-sm rounded-md border hover:bg-accent",children:b}),e.jsx("button",{onClick:f,className:Zt("px-4 py-2 text-sm rounded-md font-medium",$?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"),autoFocus:!0,children:C})]})]})}):null}function Ht(...o){return ue(pe(o))}function Oe({title:o="Properties",fields:A,onChange:F,className:C}){const[b,$]=l.useState(new Set),f=l.useCallback(v=>{$(s=>{const y=new Set(s);return y.has(v)?y.delete(v):y.add(v),y})},[]),g=A.reduce((v,s)=>{const y=s.group??"General";return v[y]||(v[y]=[]),v[y].push(s),v},{});return e.jsxs("div",{className:Ht("flex flex-col",C),role:"region","aria-label":o,children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:o}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Object.entries(g).map(([v,s])=>e.jsxs("div",{className:"border-b last:border-b-0",children:[e.jsxs("button",{onClick:()=>f(v),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50",children:[b.has(v)?e.jsx(Ge,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"}),v]}),!b.has(v)&&e.jsx("div",{className:"px-3 pb-2 space-y-2",children:s.map(y=>e.jsx(Vt,{field:y,onChange:F},y.name))})]},v)),A.length===0&&e.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"Select an element to edit its properties"})]})]})}function Vt({field:o,onChange:A}){const F=C=>{A(o.name,C)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:o.label}),o.type==="text"&&e.jsx("input",{type:"text",value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="number"&&e.jsx("input",{type:"number",value:Number(o.value??0),onChange:C=>F(Number(C.target.value)),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="boolean"&&e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!o.value,onChange:C=>F(C.target.checked),className:"rounded"}),e.jsx("span",{className:"text-xs",children:o.value?"Yes":"No"})]}),o.type==="select"&&e.jsx("select",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background",children:o.options?.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))}),o.type==="color"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:String(o.value??"#000000"),onChange:C=>F(C.target.value),className:"h-6 w-6 rounded border cursor-pointer"}),e.jsx("span",{className:"text-xs font-mono",children:String(o.value??"#000000")})]}),o.type==="textarea"&&e.jsx("textarea",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background resize-y",rows:3}),o.description&&e.jsx("p",{className:"text-[0.65rem] text-muted-foreground/70",children:o.description})]})}function Xt(...o){return ue(pe(o))}function Ze({items:o,canvasWidth:A,canvasHeight:F,position:C="bottom-right",size:b=150,className:$}){const f=Math.min(b/A,b/F),g=A*f,v=F*f,s={"top-left":"top-2 left-2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-2","bottom-right":"bottom-2 right-2"};return e.jsx("div",{className:Xt("absolute border rounded bg-background/90 shadow-sm overflow-hidden",s[C],$),role:"img","aria-label":"Canvas minimap",children:e.jsxs("svg",{width:g,height:v,viewBox:`0 0 ${A} ${F}`,children:[e.jsx("rect",{width:A,height:F,fill:"hsl(var(--muted))",opacity:"0.3"}),o.map(y=>e.jsx("rect",{x:y.x,y:y.y,width:y.width,height:y.height,fill:y.selected?"hsl(var(--primary))":y.color??"hsl(var(--foreground) / 0.3)",rx:"2"},y.id))]})})}const at=l.createContext(null);at.displayName="CollaborationContext";function Ie(){return l.useContext(at)}function te(...o){return ue(pe(o))}function Kt({canvas:o={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:A=[],palette:F=Yt,showComponentTree:C=!0,undoRedo:b=!0,propertyEditor:$=!0,readOnly:f=!1,showMinimap:g=!1,onChange:v,className:s}){const y=Se(A),c=y.current,d=l.useCallback(n=>{y.push(n),v?.(n)},[y,v]),j=Le({initialZoom:o.zoom??1}),{zoom:p}=j,x=$e(),I=l.useMemo(()=>{const n=Array.from(x.selectedIds);return n.length>0?n[0]:null},[x.selectedIds]),P=l.useMemo(()=>c.find(n=>n.id===I),[c,I]),O=Te(),k=De(),E=Ie(),N=l.useCallback(n=>{E&&E.sendOperation({...n,userId:E.currentUserId??""})},[E]),[L,H]=l.useState(!0),[G,Z]=l.useState(!0),[Q,Y]=l.useState(g),V=l.useRef(null),q=l.useRef(null),J=l.useCallback(n=>!o.snapToGrid||!o.gridSize?n:Math.round(n/o.gridSize)*o.gridSize,[o.snapToGrid,o.gridSize]),ae=l.useCallback((n,a)=>{if(f)return;const r=F.flatMap(T=>T.items).find(T=>T.type===n),t=r?.defaultSize,i={id:`comp-${Date.now()}`,type:n,label:a,position:{x:100,y:100,width:t?.width??200,height:t?.height??100},props:r?.defaultProps??{}},h=[...c,i];d(h),x.selectOne(i.id),N({type:"insert",elementId:i.id,data:{component:i}})},[c,f,F,d,x,N]),ee=l.useCallback(n=>{if(f)return;const a=c.filter(r=>r.id!==n);d(a),x.isSelected(n)&&x.clearSelection(),N({type:"delete",elementId:n,data:{}})},[c,f,d,x,N]),B=l.useCallback(async()=>{if(f||x.count===0||!await k.confirm("Delete components",`Are you sure you want to delete ${x.count} component${x.count>1?"s":""}?`))return;const n=x.selectedIds,a=c.filter(r=>!n.has(r.id));d(a),x.clearSelection(),n.forEach(r=>{N({type:"delete",elementId:r,data:{}})})},[f,x,k,c,d,N]),le=l.useCallback((n,a)=>{if(f||!I)return;const r=c.map(t=>t.id!==I?t:n==="label"?{...t,label:String(a)}:n==="x"?{...t,position:{...t.position,x:Number(a)}}:n==="y"?{...t,position:{...t.position,y:Number(a)}}:n==="width"?{...t,position:{...t.position,width:Number(a)}}:n==="height"?{...t,position:{...t.position,height:Number(a)}}:{...t,props:{...t.props,[n]:a}});d(r),N({type:"update",elementId:I,data:{[n]:a}})},[f,I,c,d,N]),se=l.useCallback(()=>{const n=x.selectedIds;if(n.size===0)return;const a=c.filter(r=>n.has(r.id));O.copy(a)},[x,c,O]),_=l.useCallback(()=>{if(f)return;const n=O.paste();if(!n||n.length===0)return;let a=0;const r=n.map(i=>({...i,id:`comp-${Date.now()}-${++a}-${Math.random().toString(36).slice(2,7)}`,position:{...i.position,x:i.position.x+20,y:i.position.y+20}})),t=[...c,...r];d(t),x.selectMany(r.map(i=>i.id)),r.forEach(i=>{N({type:"insert",elementId:i.id,data:{component:i}})})},[f,O,c,d,x,N]),ne=l.useCallback((n,a)=>{f||(V.current={id:a.id,startX:n.clientX,startY:n.clientY},n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",a.id))},[f]),re=l.useCallback(n=>{n.preventDefault(),n.dataTransfer.dropEffect="move"},[]),w=l.useCallback(n=>{n.preventDefault();const a=V.current;if(!a||f)return;const r=(n.clientX-a.startX)/p,t=(n.clientY-a.startY)/p,i=c.map(h=>h.id!==a.id?h:{...h,position:{...h.position,x:J(h.position.x+r),y:J(h.position.y+t)}});d(i),N({type:"move",elementId:a.id,data:{}}),V.current=null},[f,p,c,d,J,N]),M=l.useMemo(()=>P?[{name:"label",label:"Label",type:"text",value:P.label??"",group:"General"},{name:"x",label:"X",type:"number",value:P.position.x,group:"Position"},{name:"y",label:"Y",type:"number",value:P.position.y,group:"Position"},{name:"width",label:"Width",type:"number",value:P.position.width,group:"Size"},{name:"height",label:"Height",type:"number",value:P.position.height,group:"Size"}]:[],[P]),m=l.useMemo(()=>c.map(n=>({id:n.id,x:n.position.x,y:n.position.y,width:typeof n.position.width=="number"?n.position.width:100,height:typeof n.position.height=="number"?n.position.height:50,selected:x.isSelected(n.id)})),[c,x]);return l.useEffect(()=>{const n=q.current;if(!n)return;const a=r=>{const t=["INPUT","TEXTAREA","SELECT"].includes(r.target.tagName),i=r.ctrlKey||r.metaKey;if((r.key==="Delete"||r.key==="Backspace")&&x.count>0&&!t){r.preventDefault(),B();return}if(r.key==="Escape"){x.clearSelection();return}if(!t){if(i&&r.key==="z"&&!r.shiftKey&&b&&!f){r.preventDefault(),y.undo();return}if(i&&(r.key==="z"&&r.shiftKey||r.key==="y")&&b&&!f){r.preventDefault(),y.redo();return}if(i&&r.key==="c"){r.preventDefault(),se();return}if(i&&r.key==="v"&&!f){r.preventDefault(),_();return}if(i&&r.key==="a"){r.preventDefault(),x.selectMany(c.map(h=>h.id));return}}};return n.addEventListener("keydown",a),()=>n.removeEventListener("keydown",a)},[x,B,b,f,y,se,_,c]),e.jsxs("div",{ref:q,tabIndex:0,className:te("flex h-full w-full border rounded-lg overflow-hidden bg-background",s),children:[!f&&e.jsx("div",{className:te("border-r bg-muted/30 flex flex-col transition-[width] duration-200",L?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component palette",children:L&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:"Components"}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:F.map(n=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1 uppercase",children:n.label}),n.items.map(a=>e.jsxs("button",{onClick:()=>ae(a.type,a.label),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left",children:[e.jsx(ce,{className:"h-3 w-3"}),a.label]},a.type))]},n.name))})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Designer toolbar",children:[!f&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:L?"Collapse palette":"Expand palette","aria-label":L?"Collapse palette":"Expand palette",onClick:()=>H(n=>!n),children:e.jsx(Nt,{className:te("h-4 w-4",!L&&"rotate-180")})}),b&&!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canUndo&&"opacity-40 pointer-events-none"),title:"Undo (Ctrl+Z)","aria-label":"Undo",disabled:!y.canUndo,onClick:()=>y.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canRedo&&"opacity-40 pointer-events-none"),title:"Redo (Ctrl+Shift+Z)","aria-label":"Redo",disabled:!y.canRedo,onClick:()=>y.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Copy (Ctrl+C)","aria-label":"Copy",disabled:x.count===0,onClick:se,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!O.hasContent&&"opacity-40 pointer-events-none"),title:"Paste (Ctrl+V)","aria-label":"Paste",disabled:!O.hasContent,onClick:_,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Delete selected","aria-label":"Delete selected",disabled:x.count===0,onClick:B,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:"Preview","aria-label":"Preview",children:e.jsx(Je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",Q&&"bg-accent"),title:"Toggle minimap","aria-label":"Toggle minimap",onClick:()=>Y(n=>!n),children:e.jsx(qe,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom out",onClick:j.zoomOut,children:e.jsx(Ct,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-center",children:[Math.round(p*100),"%"]}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom in",onClick:j.zoomIn,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Reset zoom",onClick:j.resetZoom,children:e.jsx(kt,{className:"h-3 w-3"})})]}),C&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:G?"Collapse panel":"Expand panel","aria-label":G?"Collapse panel":"Expand panel",onClick:()=>Z(n=>!n),children:e.jsx(Ue,{className:te("h-4 w-4",!G&&"rotate-180")})})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4 relative",role:"region","aria-label":"Design canvas",onWheel:j.handleWheel,onMouseDown:j.startPan,onDragOver:re,onDrop:w,children:e.jsxs("div",{className:"relative bg-background border rounded shadow-sm mx-auto",style:{width:o.width*p,height:o.height*p,transform:`translate(${j.panOffset.x}px, ${j.panOffset.y}px)`,backgroundImage:o.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:o.showGrid&&o.gridSize?`${o.gridSize*p}px ${o.gridSize*p}px`:void 0},children:[c.map(n=>{const a=x.isSelected(n.id);return e.jsxs("div",{draggable:!f,onDragStart:r=>ne(r,n),className:te("absolute border rounded cursor-move select-none transition-shadow",a?"border-primary ring-2 ring-primary/20 shadow-md":"border-border hover:border-primary/50"),style:{left:n.position.x*p,top:n.position.y*p,width:typeof n.position.width=="number"?n.position.width*p:n.position.width,height:typeof n.position.height=="number"?n.position.height*p:n.position.height},onClick:r=>x.toggle(n.id,r.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b",children:[e.jsx(_e,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:n.label??n.type}),!f&&e.jsx("button",{onClick:r=>{r.stopPropagation(),ee(n.id)},className:"ml-auto p-0.5 rounded hover:bg-destructive/10","aria-label":`Delete ${n.label??n.type}`,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"p-2 text-xs text-muted-foreground",children:n.type})]},n.id)}),Q&&e.jsx(Ze,{items:m,canvasWidth:o.width,canvasHeight:o.height})]})})]}),C&&e.jsx("div",{className:te("border-l bg-muted/30 flex flex-col transition-[width] duration-200",G?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component tree",children:G&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b font-medium text-sm flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4"}),"Component Tree"]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c.length===0?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:"No components added yet. Click a component in the palette to add it to the canvas."}):c.map(n=>e.jsx("button",{onClick:a=>x.toggle(n.id,a.shiftKey),className:te("w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left",x.isSelected(n.id)?"bg-accent":"hover:bg-accent/50"),children:e.jsx("span",{className:"truncate",children:n.label??n.type})},n.id))}),$&&P?e.jsx("div",{className:"border-t",children:e.jsx(Oe,{title:`Properties – ${P.label??P.type}`,fields:M,onChange:le})}):P&&e.jsxs("div",{className:"border-t p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Properties"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:["Type: ",P.type]}),e.jsxs("div",{children:["ID: ",P.id]}),e.jsxs("div",{children:["Position: ",P.position.x,","," ",P.position.y]}),e.jsxs("div",{children:["Size: ",P.position.width," ×"," ",P.position.height]})]})]})]})}),e.jsx(Fe,{isOpen:k.isOpen,title:k.title,message:k.message,onConfirm:k.onConfirm,onCancel:k.onCancel})]})}const Yt=[{name:"layout",label:"Layout",items:[{type:"container",label:"Container",defaultSize:{width:400,height:300}},{type:"flex",label:"Flex",defaultSize:{width:400,height:200}},{type:"grid",label:"Grid",defaultSize:{width:400,height:300}},{type:"card",label:"Card",defaultSize:{width:300,height:200}},{type:"tabs",label:"Tabs",defaultSize:{width:400,height:300}}]},{name:"form",label:"Form",items:[{type:"input",label:"Input",defaultSize:{width:300,height:60}},{type:"textarea",label:"Textarea",defaultSize:{width:300,height:120}},{type:"select",label:"Select",defaultSize:{width:300,height:60}},{type:"checkbox",label:"Checkbox",defaultSize:{width:200,height:40}},{type:"button",label:"Button",defaultSize:{width:120,height:40}}]},{name:"data",label:"Data",items:[{type:"table",label:"Table",defaultSize:{width:600,height:400}},{type:"chart",label:"Chart",defaultSize:{width:400,height:300}},{type:"list",label:"List",defaultSize:{width:300,height:400}},{type:"statistic",label:"Statistic",defaultSize:{width:200,height:100}}]}];function Me(...o){return ue(pe(o))}function Wt(o,A=4,F=280,C=250,b=50,$=50){return o.map((f,g)=>({...f,position:{x:b+g%A*F,y:$+Math.floor(g/A)*C}}))}function Bt({entities:o=[],relationships:A=[],canvas:F={width:1200,height:800,showGrid:!0},showRelationshipLabels:C=!0,readOnly:b=!1,onEntitiesChange:$,onRelationshipsChange:f,className:g}){const v=l.useRef(null),s=Se({entities:o,relationships:A},{maxHistory:50}),{entities:y,relationships:c}=s.current,d=l.useCallback(t=>{s.push(t),$?.(t.entities),f?.(t.relationships)},[s,$,f]),j=De(),p=$e(),x=p.count>0?Array.from(p.selectedIds)[0]:null,I=Te(),P=Le({minZoom:.25,maxZoom:3,zoomStep:.1}),O=Ie(),[k,E]=l.useState(!0),[N,L]=l.useState(!0),[H,G]=l.useState(null),[Z,Q]=l.useState(""),Y=l.useRef(null),V=l.useCallback(()=>{if(b)return;const t=s.current,i={id:`entity-${Date.now()}`,name:`new_entity_${t.entities.length+1}`,label:`New Entity ${t.entities.length+1}`,fields:[{name:"id",type:"uuid",primaryKey:!0,required:!0},{name:"created_at",type:"datetime",required:!0},{name:"updated_at",type:"datetime",required:!0}],position:{x:50+t.entities.length%4*280,y:50+Math.floor(t.entities.length/4)*250}},h={entities:[...t.entities,i],relationships:t.relationships};d(h),p.selectOne(i.id),O?.sendOperation({type:"insert",userId:O?.currentUserId??"",elementId:i.id,data:{name:i.name,label:i.label}})},[b,s,d,p,O]),q=l.useCallback(async t=>{if(b)return;const i=y.find(R=>R.id===t);if(!await j.confirm("Delete Entity",`Are you sure you want to delete "${i?.label??t}"? This action cannot be undone.`))return;const h=s.current,T={entities:h.entities.filter(R=>R.id!==t),relationships:h.relationships.filter(R=>R.sourceEntity!==t&&R.targetEntity!==t)};d(T),p.isSelected(t)&&p.clearSelection(),O?.sendOperation({type:"delete",userId:O?.currentUserId??"",elementId:t,data:{}})},[b,y,j,s,d,p,O]),J=l.useCallback(async()=>{if(b||p.count===0)return;const t=Array.from(p.selectedIds);if(!await j.confirm("Delete Entities",`Are you sure you want to delete ${t.length} selected entity(s)? This action cannot be undone.`))return;const i=s.current,h=new Set(t),T={entities:i.entities.filter(R=>!h.has(R.id)),relationships:i.relationships.filter(R=>!h.has(R.sourceEntity)&&!h.has(R.targetEntity))};d(T),p.clearSelection()},[b,p,j,s,d]),ae=l.useCallback(()=>{if(b)return;const t=s.current,i={entities:Wt(t.entities),relationships:t.relationships};d(i)},[b,s,d]),ee=l.useCallback(()=>{const t=y.filter(i=>p.isSelected(i.id));t.length>0&&I.copy(t)},[y,p,I]),B=l.useCallback(()=>{if(b)return;const t=I.paste();if(!t||t.length===0)return;const i=s.current,h=t.map((R,ie)=>({...R,id:`entity-${Date.now()}-${ie}`,name:`${R.name}_copy`,label:`${R.label} (Copy)`,position:{x:R.position.x+30,y:R.position.y+30}})),T={entities:[...i.entities,...h],relationships:i.relationships};d(T),p.selectMany(h.map(R=>R.id))},[b,I,s,d,p]),le=l.useCallback(t=>{if(b)return;const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==t)return T;const R={name:`field_${T.fields.length+1}`,type:"text",required:!1};return{...T,fields:[...T.fields,R]}}),relationships:i.relationships};d(h)},[b,s,d]),se=l.useCallback((t,i,h)=>{b||(G({entityId:t,fieldIndex:i}),Q(h))},[b]),_=l.useCallback(()=>{if(!H)return;const t=Z.trim();if(t===""){G(null);return}const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==H.entityId)return T;const R=T.fields.map((ie,ge)=>ge===H.fieldIndex?{...ie,name:t}:ie);return{...T,fields:R}}),relationships:i.relationships};d(h),G(null)},[H,Z,s,d]),ne=l.useCallback(()=>{G(null)},[]),re=l.useCallback((t,i)=>{if(b||!y.find(T=>T.id===i))return;const h=t.target.getBoundingClientRect();Y.current={entityId:i,offsetX:t.clientX-h.left,offsetY:t.clientY-h.top},t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",i)},[b,y]),w=l.useCallback(t=>{t.preventDefault(),t.dataTransfer.dropEffect="move"},[]),M=l.useCallback(t=>{if(t.preventDefault(),!Y.current)return;const i=t.currentTarget.getBoundingClientRect(),h=P.zoom,T=(t.clientX-i.left-P.panOffset.x)/h-Y.current.offsetX,R=(t.clientY-i.top-P.panOffset.y)/h-Y.current.offsetY,ie=s.current,ge={entities:ie.entities.map(fe=>fe.id===Y.current.entityId?{...fe,position:{x:Math.max(0,Math.round(T)),y:Math.max(0,Math.round(R))}}:fe),relationships:ie.relationships};d(ge),Y.current=null},[P.zoom,P.panOffset,s,d]),m=x?y.find(t=>t.id===x):null,n=m?[{name:"name",label:"Name",type:"text",value:m.name,group:"General"},{name:"label",label:"Label",type:"text",value:m.label,group:"General"},{name:"description",label:"Description",type:"textarea",value:m.description??"",group:"General"},{name:"color",label:"Color",type:"color",value:m.color??"#3b82f6",group:"Appearance"},{name:"position.x",label:"X Position",type:"number",value:m.position.x,group:"Position"},{name:"position.y",label:"Y Position",type:"number",value:m.position.y,group:"Position"}]:[],a=l.useCallback((t,i)=>{if(!x)return;const h=s.current,T={entities:h.entities.map(R=>R.id!==x?R:t==="position.x"?{...R,position:{...R.position,x:Number(i)}}:t==="position.y"?{...R,position:{...R.position,y:Number(i)}}:{...R,[t]:i}),relationships:h.relationships};d(T)},[x,s,d]);l.useEffect(()=>{const t=v.current;if(!t)return;const i=h=>{const T=h.target.tagName;if(T==="INPUT"||T==="TEXTAREA"||T==="SELECT")return;const R=h.ctrlKey||h.metaKey;R&&h.key==="z"?(h.preventDefault(),s.undo()):R&&(h.key==="y"||h.shiftKey&&h.key==="Z")?(h.preventDefault(),s.redo()):R&&h.key==="c"?(h.preventDefault(),ee()):R&&h.key==="v"?(h.preventDefault(),B()):(h.key==="Delete"||h.key==="Backspace")&&p.count>0?(h.preventDefault(),J()):h.key==="Escape"&&(p.clearSelection(),G(null))};return t.addEventListener("keydown",i),()=>t.removeEventListener("keydown",i)},[s,ee,B,J,p]);const r=y.map(t=>({id:t.id,x:t.position.x,y:t.position.y,width:240,height:40+t.fields.length*24,color:t.color,selected:p.isSelected(t.id)}));return e.jsxs("div",{ref:v,tabIndex:0,className:Me("flex h-full w-full border rounded-lg overflow-hidden bg-background",g),children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{role:"toolbar","aria-label":"Designer toolbar",className:"flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap",children:[e.jsx(He,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:"Data Model Designer"}),e.jsxs("div",{className:"flex items-center gap-1 ml-2 border-l pl-2",children:[e.jsx("button",{onClick:()=>s.undo(),disabled:!s.canUndo,"aria-label":"Undo",title:"Undo (Ctrl+Z)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>s.redo(),disabled:!s.canRedo,"aria-label":"Redo",title:"Redo (Ctrl+Y)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:P.zoomOut,"aria-label":"Zoom Out",title:"Zoom Out",className:"p-1 rounded hover:bg-accent",children:e.jsx(Qe,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"text-xs tabular-nums w-10 text-center",children:[Math.round(P.zoom*100),"%"]}),e.jsx("button",{onClick:P.zoomIn,"aria-label":"Zoom In",title:"Zoom In",className:"p-1 rounded hover:bg-accent",children:e.jsx(et,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:P.resetZoom,"aria-label":"Reset Zoom",title:"Reset Zoom",className:"p-1 rounded hover:bg-accent",children:e.jsx(tt,{className:"h-3 w-3"})})]}),!b&&e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:ee,disabled:p.count===0,"aria-label":"Copy",title:"Copy (Ctrl+C)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:B,disabled:!I.hasContent,"aria-label":"Paste",title:"Paste (Ctrl+V)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(ke,{className:"h-3.5 w-3.5"})})]}),!b&&e.jsxs("button",{onClick:ae,"aria-label":"Auto Layout",title:"Auto Layout",className:"flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent",children:[e.jsx(Dt,{className:"h-3 w-3"})," Auto Layout"]}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx(Tt,{className:"h-3 w-3"}),e.jsxs("span",{children:[O.users.length," user",O.users.length!==1?"s":""]})]}),p.count>1&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.count," selected"]}),!b&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:V,"aria-label":"Add Entity",className:"flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(ce,{className:"h-3 w-3"})," Add Entity"]}),e.jsxs("button",{"aria-label":"Add Relationship",title:"Add Relationship (coming soon)",className:"flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80",children:[e.jsx(Ft,{className:"h-3 w-3"})," Add Relationship"]})]})]}),e.jsxs("div",{role:"region","aria-label":"Canvas",className:"flex-1 overflow-auto bg-muted/10 p-4 relative",onWheel:P.handleWheel,onMouseDown:P.startPan,onDragOver:w,onDrop:M,children:[e.jsxs("div",{className:"relative",style:{width:F.width,minHeight:F.height,...P.transformStyle,backgroundImage:F.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:F.showGrid?"20px 20px":void 0},children:[e.jsx("svg",{className:"absolute inset-0 pointer-events-none",width:F.width,height:F.height,children:c.map(t=>{const i=y.find(T=>T.id===t.sourceEntity),h=y.find(T=>T.id===t.targetEntity);return!i||!h?null:e.jsxs("g",{children:[e.jsx("line",{x1:i.position.x+120,y1:i.position.y+50,x2:h.position.x+120,y2:h.position.y+50,stroke:"hsl(var(--primary))",strokeWidth:"2",strokeDasharray:t.type==="many-to-many"?"5,5":void 0}),C&&t.label&&e.jsx("text",{x:(i.position.x+h.position.x)/2+120,y:(i.position.y+h.position.y)/2+50-8,textAnchor:"middle",className:"text-xs fill-muted-foreground",children:t.label})]},t.id)})}),y.length===0&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-muted-foreground text-sm",children:"No entities in the model. Click 'Add Entity' to create your first entity."}),y.map(t=>e.jsxs("div",{role:"group","aria-label":t.label,draggable:!b,onDragStart:i=>re(i,t.id),className:Me("absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing",p.isSelected(t.id)?"border-primary ring-2 ring-primary/20":"border-border hover:border-primary/50"),style:{left:t.position.x,top:t.position.y},onClick:i=>p.toggle(t.id,i.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm",style:{backgroundColor:t.color??"hsl(var(--primary) / 0.1)"},children:[e.jsx(He,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"truncate",children:t.label}),!b&&e.jsx("button",{onClick:i=>{i.stopPropagation(),q(t.id)},"aria-label":`Delete ${t.label}`,className:"ml-auto p-0.5 rounded hover:bg-destructive/20",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"px-3 py-1 divide-y",children:t.fields.map((i,h)=>e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs",children:[H&&H.entityId===t.id&&H.fieldIndex===h?e.jsx("input",{type:"text",value:Z,onChange:T=>Q(T.target.value),onBlur:_,onKeyDown:T=>{T.key==="Enter"&&_(),T.key==="Escape"&&ne()},className:"font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0,onClick:T=>T.stopPropagation()}):e.jsxs("span",{className:Me("font-mono cursor-text",i.primaryKey&&"font-bold text-primary"),onClick:T=>{T.stopPropagation(),se(t.id,h,i.name)},title:"Click to edit field name",children:[i.primaryKey&&e.jsx("span",{className:"text-[0.65rem] font-semibold text-primary mr-0.5",children:"PK"}),i.name]}),e.jsx("span",{className:"text-muted-foreground ml-auto",children:i.type}),i.required&&e.jsx("span",{className:"text-destructive",children:"*"})]},`${i.name}-${h}`))}),!b&&e.jsx("div",{className:"px-3 py-1 border-t",children:e.jsxs("button",{onClick:i=>{i.stopPropagation(),le(t.id)},"aria-label":`Add field to ${t.label}`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5",children:[e.jsx(ce,{className:"h-3 w-3"})," Add Field"]})})]},t.id))]}),N&&y.length>0&&e.jsx(Ze,{items:r,canvasWidth:F.width,canvasHeight:F.height,position:"bottom-right",size:150})]})]}),e.jsxs("div",{className:"w-64 border-l flex flex-col bg-background shrink-0",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("button",{onClick:()=>E(t=>!t),className:"flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b","aria-expanded":k,"aria-controls":"property-editor-panel",children:[k?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Properties"]}),k&&e.jsx("div",{id:"property-editor-panel",className:"flex-1 overflow-y-auto",children:e.jsx(Oe,{title:m?m.label:"Properties",fields:n,onChange:a})})]}),e.jsx("div",{className:"border-t",children:e.jsxs("button",{onClick:()=>L(t=>!t),className:"flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full","aria-expanded":N,children:[N?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Minimap"]})})]}),e.jsx(Fe,{isOpen:j.isOpen,title:j.title,message:j.message,onConfirm:j.onConfirm,onCancel:j.onCancel,destructive:!0})]})}function Pe(...o){return ue(pe(o))}const be=120,ve=50;function qt(o,A){if(o.length===0)return o;const F=200,C=100,b=new Map,$=new Map;for(const c of o)b.set(c.id,0),$.set(c.id,[]);for(const c of A)b.set(c.target,(b.get(c.target)??0)+1),$.get(c.source)?.push(c.target);const f=[],g=new Set;let v=o.filter(c=>(b.get(c.id)??0)===0).map(c=>c.id);for(v.length===0&&(v=[o[0].id]);v.length>0;){f.push(v);for(const d of v)g.add(d);const c=new Set;for(const d of v)for(const j of $.get(d)??[])g.has(j)||c.add(j);v=Array.from(c)}const s=o.filter(c=>!g.has(c.id)).map(c=>c.id);s.length>0&&f.push(s);const y=new Map;for(let c=0;c<f.length;c++){const d=f[c];for(let j=0;j<d.length;j++)y.set(d[j],{x:80+c*F,y:80+j*C})}return o.map(c=>({...c,position:y.get(c.id)??c.position}))}function _t({processName:o="New Process",nodes:A=[],edges:F=[],lanes:C,canvas:b={width:1400,height:800,showGrid:!0},showMinimap:$=!0,showToolbar:f=!0,readOnly:g=!1,onNodesChange:v,onEdgesChange:s,className:y}){const c=Se({nodes:A,edges:F},{maxHistory:50}),d=c.current.nodes,j=c.current.edges,p=l.useCallback((u,U)=>{c.push({nodes:u,edges:U}),v?.(u),s?.(U)},[c,v,s]),x=De(),I=$e(),P=Te(),O=Le({initialZoom:1}),k=Ie(),[E,N]=l.useState(null),[L,H]=l.useState(!1),[G,Z]=l.useState(null),[Q,Y]=l.useState(null),[V,q]=l.useState(!0),[J,ae]=l.useState(null),[ee,B]=l.useState({x:0,y:0}),le=l.useRef(null),se=l.useRef(v),_=l.useRef(s);se.current=v,_.current=s,l.useEffect(()=>{se.current?.(d),_.current?.(j)},[c.current]);const ne=l.useCallback((u,U)=>{if(g)return;const z={id:`node-${Date.now()}`,type:u,label:U,position:{x:200+d.length*160,y:200}},X=[...d,z];p(X,j),N(z.id),I.selectOne(z.id),k?.sendOperation({type:"insert",elementId:z.id,data:{label:U},userId:k.currentUserId??""})},[d,j,g,p,I,k]),re=l.useCallback(async u=>{if(g)return;const U=d.find(K=>K.id===u);if(!await x.confirm("Delete Node",`Are you sure you want to delete "${U?.label??u}"? This will also remove all connected edges.`))return;const z=d.filter(K=>K.id!==u),X=j.filter(K=>K.source!==u&&K.target!==u);p(z,X),E===u&&N(null),I.clearSelection(),k?.sendOperation({type:"delete",elementId:u,data:{},userId:k.currentUserId??""})},[d,j,E,g,p,x,I,k]),w=l.useCallback(async()=>{if(g||I.count===0||!await x.confirm("Delete Selected Nodes",`Are you sure you want to delete ${I.count} selected node(s) and their connected edges?`))return;const u=I.selectedIds,U=d.filter(X=>!u.has(X.id)),z=j.filter(X=>!u.has(X.source)&&!u.has(X.target));p(U,z),N(null),I.clearSelection()},[d,j,g,p,x,I]),M=l.useCallback(()=>{const u=I.count>0?I.selectedIds:E?new Set([E]):new Set;if(u.size===0)return;const U=d.filter(z=>u.has(z.id));P.copy(U)},[d,E,I,P]),m=l.useCallback(()=>{if(g)return;const u=P.paste();if(!u||u.length===0)return;const U=40,z=u.map(K=>({...K,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:K.position.x+U,y:K.position.y+U}})),X=[...d,...z];p(X,j),I.selectMany(z.map(K=>K.id)),N(z[0].id)},[g,d,j,P,p,I]),n=l.useCallback(()=>{H(u=>u?(Z(null),!1):!0)},[]),a=l.useCallback(u=>{if(!L)return!1;if(!G)return Z(u),!0;if(G===u)return!0;const U={id:`edge-${Date.now()}`,source:G,target:u},z=[...j,U];return p(d,z),Z(null),H(!1),k?.sendOperation({type:"insert",elementId:U.id,data:{source:G,target:u},userId:k.currentUserId??""}),!0},[L,G,d,j,p,k]),r=l.useCallback(()=>{if(g||d.length===0)return;const u=qt(d,j);p(u,j)},[d,j,g,p]),t=l.useCallback((u,U)=>{if(g||!d.find(X=>X.id===U))return;ae(U);const z=u.target.getBoundingClientRect();B({x:u.clientX-z.left,y:u.clientY-z.top}),u.dataTransfer.effectAllowed="move",u.dataTransfer.setData("text/plain",U)},[g,d]),i=l.useCallback(u=>{if(u.preventDefault(),g||!J)return;const U=u.currentTarget.getBoundingClientRect(),z=O.zoom,X=(u.clientX-U.left-O.panOffset.x)/z-ee.x,K=(u.clientY-U.top-O.panOffset.y)/z-ee.y,W=Math.max(0,Math.round(X/20)*20),xe=Math.max(0,Math.round(K/20)*20),he=d.map(me=>me.id===J?{...me,position:{x:W,y:xe}}:me);p(he,j),ae(null)},[g,J,ee,d,j,O.zoom,O.panOffset,p]),h=l.useCallback(u=>{u.preventDefault(),u.dataTransfer.dropEffect="move"},[]),T=l.useMemo(()=>d.find(u=>u.id===E)??null,[d,E]),R=l.useMemo(()=>T?[{name:"label",label:"Name",type:"text",value:T.label,group:"General"},{name:"type",label:"Type",type:"select",value:T.type,options:[{label:"Start Event",value:"start-event"},{label:"End Event",value:"end-event"},{label:"User Task",value:"user-task"},{label:"Service Task",value:"service-task"},{label:"Script Task",value:"script-task"},{label:"Exclusive Gateway",value:"exclusive-gateway"},{label:"Parallel Gateway",value:"parallel-gateway"},{label:"Inclusive Gateway",value:"inclusive-gateway"}],group:"General"},{name:"description",label:"Description",type:"textarea",value:T.description??"",group:"General"}]:[],[T]),ie=l.useCallback((u,U)=>{if(g||!E)return;const z=d.map(X=>X.id===E?{...X,[u]:U}:X);p(z,j)},[g,E,d,j,p]),ge=u=>{switch(u){case"start-event":return"rounded-full bg-green-100 border-green-500 text-green-700";case"end-event":return"rounded-full bg-red-100 border-red-500 text-red-700";case"exclusive-gateway":case"parallel-gateway":case"inclusive-gateway":case"event-based-gateway":return"rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700";case"user-task":return"rounded bg-blue-100 border-blue-500 text-blue-700";case"service-task":case"script-task":return"rounded bg-purple-100 border-purple-500 text-purple-700";default:return"rounded bg-gray-100 border-gray-500 text-gray-700"}},fe=l.useMemo(()=>d.map(u=>({id:u.id,x:u.position.x,y:u.position.y,width:be,height:ve,selected:I.isSelected(u.id)||u.id===E})),[d,I,E]);l.useEffect(()=>{const u=le.current;if(!u)return;const U=z=>{const X=z.target?.tagName;if(X==="INPUT"||X==="TEXTAREA"||X==="SELECT")return;const K=z.ctrlKey||z.metaKey;if(K&&z.key==="z"&&!z.shiftKey){z.preventDefault(),c.undo();return}if(K&&z.key==="y"||K&&z.key==="z"&&z.shiftKey){z.preventDefault(),c.redo();return}if(K&&z.key==="c"){z.preventDefault(),M();return}if(K&&z.key==="v"){z.preventDefault(),m();return}if(z.key==="Delete"||z.key==="Backspace"){I.count>0?(z.preventDefault(),w()):E&&(z.preventDefault(),re(E));return}if(z.key==="Escape"){L?(H(!1),Z(null)):(N(null),I.clearSelection());return}};return u.addEventListener("keydown",U),()=>u.removeEventListener("keydown",U)},[E,L,I,c,M,m,re,w]);const st=l.useCallback(u=>{u.target===u.currentTarget&&(N(null),I.clearSelection(),L&&(H(!1),Z(null)))},[L,I]);return e.jsxs("div",{ref:le,tabIndex:0,className:Pe("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsx(Fe,{isOpen:x.isOpen,title:x.title,message:x.message,onConfirm:x.onConfirm,onCancel:x.onCancel,destructive:!0}),f&&e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Process toolbar",children:[e.jsx(It,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm","aria-label":"Process name",children:o}),k?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),k.users.length," user",k.users.length!==1?"s":""]}),e.jsx("div",{className:"flex-1"}),!g&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>c.undo(),disabled:!c.canUndo,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Undo (Ctrl+Z)","aria-label":"Undo",children:e.jsx(je,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>c.redo(),disabled:!c.canRedo,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Redo (Ctrl+Y)","aria-label":"Redo",children:e.jsx(Ne,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:M,disabled:I.count===0&&!E,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Copy (Ctrl+C)","aria-label":"Copy",children:e.jsx(Ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:m,disabled:!P.hasContent,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Paste (Ctrl+V)","aria-label":"Paste",children:e.jsx(ke,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:n,className:Pe("flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",L&&"bg-primary text-primary-foreground"),title:"Connect nodes","aria-label":"Connect nodes","aria-pressed":L,children:[e.jsx(Pt,{className:"h-3 w-3"})," Connect"]}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Auto layout","aria-label":"Auto layout",children:[e.jsx(Et,{className:"h-3 w-3"})," Layout"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:O.zoomIn,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Zoom in","aria-label":"Zoom in",children:e.jsx(et,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs tabular-nums min-w-[3ch] text-center","aria-label":"Zoom level",children:[Math.round(O.zoom*100),"%"]}),e.jsx("button",{onClick:O.zoomOut,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Zoom out","aria-label":"Zoom out",children:e.jsx(Qe,{className:"h-3 w-3"})}),e.jsx("button",{onClick:O.resetZoom,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Reset zoom","aria-label":"Reset zoom",children:e.jsx(tt,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:()=>ne("start-event","Start"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add Start Event","aria-label":"Add Start Event",children:[e.jsx($t,{className:"h-3 w-3 text-green-600"})," Start"]}),e.jsxs("button",{onClick:()=>ne("user-task","User Task"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add User Task","aria-label":"Add User Task",children:[e.jsx(Ve,{className:"h-3 w-3 text-blue-600"})," Task"]}),e.jsxs("button",{onClick:()=>ne("exclusive-gateway","Decision"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add Gateway","aria-label":"Add Gateway",children:[e.jsx(Ot,{className:"h-3 w-3 text-yellow-600"})," Gateway"]}),e.jsxs("button",{onClick:()=>ne("end-event","End"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add End Event","aria-label":"Add End Event",children:[e.jsx(Ve,{className:"h-3 w-3 text-red-600"})," End"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:()=>q(u=>!u),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:V?"Hide properties":"Show properties","aria-label":V?"Hide property panel":"Show property panel","aria-expanded":V,children:V?e.jsx(Ue,{className:"h-3 w-3"}):e.jsx(zt,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4",role:"region","aria-label":"Process canvas",onWheel:O.handleWheel,onMouseDown:O.startPan,children:e.jsxs("div",{className:"relative",style:{...O.transformStyle,width:b.width,minHeight:b.height,backgroundImage:b.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:b.showGrid?"20px 20px":void 0},onClick:st,onDrop:i,onDragOver:h,children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:b.width,height:b.height,children:[e.jsx("defs",{children:e.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground))"})})}),j.map(u=>{const U=d.find(ze=>ze.id===u.source),z=d.find(ze=>ze.id===u.target);if(!U||!z)return null;U.position.x+be/2;const X=U.position.y+ve/2;z.position.x+be/2;const K=z.position.y+ve/2,W=U.position.x+be,xe=X,he=z.position.x,me=K,nt=(W+he)/2,rt=`M ${W} ${xe} Q ${nt} ${xe}, ${(W+he)/2} ${(xe+me)/2} T ${he} ${me}`;return e.jsxs("g",{children:[e.jsx("path",{d:rt,fill:"none",stroke:"hsl(var(--foreground) / 0.5)",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),u.label&&e.jsx("text",{x:(W+he)/2,y:(xe+me)/2-8,textAnchor:"middle",className:"text-[10px] fill-muted-foreground",children:u.label})]},u.id)})]}),d.length===0&&e.jsx("div",{className:"flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm",children:"No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events."}),d.map(u=>{const U=I.isSelected(u.id)||E===u.id,z=G===u.id,X=Q===u.id,K=L||X;return e.jsxs("div",{className:"absolute select-none",style:{left:u.position.x,top:u.position.y},role:"group","aria-label":u.label,draggable:!g&&!L,onDragStart:W=>t(W,u.id),onMouseEnter:()=>Y(u.id),onMouseLeave:()=>Y(null),onClick:W=>{a(u.id)||(W.shiftKey?I.toggle(u.id,!0):(N(u.id),I.selectOne(u.id)))},children:[e.jsx("div",{className:Pe("flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow",ge(u.type),U&&"ring-2 ring-primary shadow-md",z&&"ring-2 ring-blue-400 shadow-lg",L&&!z&&"cursor-crosshair"),children:e.jsx("span",{className:Pe("text-xs font-medium",(u.type==="exclusive-gateway"||u.type==="parallel-gateway"||u.type==="inclusive-gateway"||u.type==="event-based-gateway")&&"-rotate-45"),children:u.label})}),K&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{left:-6,top:ve/2-6},title:"Input port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{right:-6,top:ve/2-6},title:"Output port",onClick:W=>{W.stopPropagation(),L?a(u.id):(H(!0),Z(u.id))}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,top:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,bottom:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}})]}),!g&&U&&!L&&e.jsx("button",{onClick:W=>{W.stopPropagation(),re(u.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":"Delete node",children:e.jsx(de,{className:"h-3 w-3"})})]},u.id)}),$&&d.length>0&&e.jsx(Ze,{items:fe,canvasWidth:b.width??1400,canvasHeight:b.height??800,position:"bottom-right"})]})}),V&&!g&&e.jsx("div",{className:"w-64 border-l bg-background overflow-y-auto flex-shrink-0",role:"complementary","aria-label":"Property panel",children:e.jsx(Oe,{title:T?`Properties: ${T.label}`:"Properties",fields:R,onChange:ie})})]})]})}function oe(...o){return ue(pe(o))}const S={untitledReport:"Untitled Report",reportCanvas:"Report canvas",properties:"Properties",propertiesPanel:"Properties panel",designerToolbar:"Report designer toolbar",selectElementPrompt:"Select an element to edit its properties",addElementsPrompt:"Add elements using the buttons above",addText:"Add Text",addField:"Add Field",addImage:"Add Image",addChart:"Add Chart",addTable:"Add Table",undo:"Undo",undoShortcut:"Undo (Ctrl+Z)",redo:"Redo",redoShortcut:"Redo (Ctrl+Shift+Z)",copy:"Copy",copyShortcut:"Copy (Ctrl+C)",paste:"Paste",pasteShortcut:"Paste (Ctrl+V)",deleteSelected:"Delete selected",deleteElement:"Delete element",deleteElementsTitle:"Delete elements",deleteElementMessage:o=>`Are you sure you want to delete ${o} element${o>1?"s":""}?`,collapsePanel:"Collapse panel",expandPanel:"Expand panel",collaborationConnected:"Connected",sectionHeader:"Report Header",sectionPageHeader:"Page Header",sectionGroupHeader:"Group Header",sectionDetail:"Detail",sectionGroupFooter:"Group Footer",sectionPageFooter:"Page Footer",sectionFooter:"Report Footer",elementText:"Text",elementImage:"🖼 Image",elementChart:"📊 Chart",elementTable:"📋 Table",propLabel:"Label",propX:"X",propY:"Y",propWidth:"Width",propHeight:"Height",propText:"Text",propField:"Field",groupPosition:"Position",groupSize:"Size",groupContent:"Content",groupGeneral:"General"},Jt={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},Qt=[{type:"header",height:80,elements:[]},{type:"detail",height:400,elements:[],repeat:!0},{type:"footer",height:60,elements:[]}];function ea({reportName:o=S.untitledReport,objectName:A,pageSize:F="A4",orientation:C="portrait",margins:b={top:40,right:40,bottom:40,left:40},sections:$=[],showToolbar:f=!0,showPropertyPanel:g=!0,readOnly:v=!1,onSectionsChange:s,className:y}){const c=Se($.length>0?$:Qt),d=c.current,j=l.useCallback(w=>{c.push(w),s?.(w)},[c,s]),p=$e(),x=l.useMemo(()=>{const w=Array.from(p.selectedIds);return w.length>0?w[0]:null},[p.selectedIds]),I=Te(),P=De(),O=Ie(),k=l.useCallback(w=>{O&&O.sendOperation({...w,userId:O.currentUserId??""})},[O]),[E,N]=l.useState(!0),L=l.useRef(null),H=l.useRef(null),G=Jt[F],Z=C==="landscape"?G.height:G.width,Q=C==="landscape"?G.width:G.height,Y=w=>{switch(w){case"header":return S.sectionHeader;case"page-header":return S.sectionPageHeader;case"group-header":return S.sectionGroupHeader;case"detail":return S.sectionDetail;case"group-footer":return S.sectionGroupFooter;case"page-footer":return S.sectionPageFooter;case"footer":return S.sectionFooter;default:return w}},V=l.useMemo(()=>x?d.flatMap(w=>w.elements).find(w=>w.id===x):null,[x,d]),q=l.useCallback((w,M)=>{if(v)return;const m={id:`elem-${Date.now()}`,type:M,position:{x:b.left,y:10,width:200,height:30},properties:{text:M==="text"?"New Text":void 0,field:M==="field"?"field_name":void 0}},n=d.map((a,r)=>r===w?{...a,elements:[...a.elements,m]}:a);j(n),p.selectOne(m.id),k({type:"insert",elementId:m.id,data:{element:m}})},[d,b.left,v,j,p,k]),J=l.useCallback(w=>{if(v)return;const M=d.map(m=>({...m,elements:m.elements.filter(n=>n.id!==w)}));j(M),p.isSelected(w)&&p.clearSelection(),k({type:"delete",elementId:w,data:{}})},[d,v,j,p,k]),ae=l.useCallback(async()=>{if(v||p.count===0||!await P.confirm(S.deleteElementsTitle,S.deleteElementMessage(p.count)))return;const w=p.selectedIds,M=d.map(m=>({...m,elements:m.elements.filter(n=>!w.has(n.id))}));j(M),p.clearSelection(),w.forEach(m=>{k({type:"delete",elementId:m,data:{}})})},[v,p,P,d,j,k]),ee=l.useCallback((w,M)=>{if(v||!x)return;const m=d.map(n=>({...n,elements:n.elements.map(a=>a.id!==x?a:w==="x"?{...a,position:{...a.position,x:Number(M)}}:w==="y"?{...a,position:{...a.position,y:Number(M)}}:w==="width"?{...a,position:{...a.position,width:Number(M)}}:w==="height"?{...a,position:{...a.position,height:Number(M)}}:{...a,properties:{...a.properties,[w]:M}})}));j(m),k({type:"update",elementId:x,data:{[w]:M}})},[v,x,d,j,k]),B=l.useCallback(()=>{const w=p.selectedIds;if(w.size===0)return;const M=d.flatMap(m=>m.elements).filter(m=>w.has(m.id));I.copy(M)},[p,d,I]),le=l.useCallback(()=>{if(v)return;const w=I.paste();if(!w||w.length===0)return;let M=0;const m=w.map(t=>({...t,id:`elem-${Date.now()}-${++M}-${Math.random().toString(36).slice(2,7)}`,position:{...t.position,x:t.position.x+20,y:t.position.y+20}})),n=d.findIndex(t=>t.type==="detail"),a=n>=0?n:0,r=d.map((t,i)=>i===a?{...t,elements:[...t.elements,...m]}:t);j(r),p.selectMany(m.map(t=>t.id)),m.forEach(t=>{k({type:"insert",elementId:t.id,data:{element:t}})})},[v,I,d,j,p,k]),se=l.useCallback((w,M,m)=>{v||(L.current={id:M.id,sectionIndex:m,startX:w.clientX,startY:w.clientY},w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",M.id))},[v]),_=l.useCallback(w=>{w.preventDefault(),w.dataTransfer.dropEffect="move"},[]),ne=l.useCallback((w,M)=>{w.preventDefault();const m=L.current;if(!m||v)return;const n=w.clientX-m.startX,a=w.clientY-m.startY;if(m.sectionIndex===M){const r=d.map((t,i)=>i!==M?t:{...t,elements:t.elements.map(h=>h.id!==m.id?h:{...h,position:{...h.position,x:Math.max(0,h.position.x+n),y:Math.max(0,(typeof h.position.y=="number"?h.position.y:0)+a)}})});j(r)}else{let r=null;const t=d.map((i,h)=>{if(h!==m.sectionIndex)return i;const T=i.elements.find(R=>R.id===m.id);return T&&(r={...T,position:{...T.position,x:Math.max(0,T.position.x+n),y:Math.max(0,10)}}),{...i,elements:i.elements.filter(R=>R.id!==m.id)}});if(r){const i=t.map((h,T)=>T!==M?h:{...h,elements:[...h.elements,r]});j(i)}}k({type:"move",elementId:m.id,data:{}}),L.current=null},[v,d,j,k]),re=l.useMemo(()=>{if(!V)return[];const w=[{name:"x",label:S.propX,type:"number",value:V.position.x,group:S.groupPosition},{name:"y",label:S.propY,type:"number",value:V.position.y,group:S.groupPosition},{name:"width",label:S.propWidth,type:"number",value:V.position.width,group:S.groupSize},{name:"height",label:S.propHeight,type:"number",value:V.position.height,group:S.groupSize}];return V.type==="text"&&w.push({name:"text",label:S.propText,type:"text",value:V.properties.text??"",group:S.groupContent}),V.type==="field"&&w.push({name:"field",label:S.propField,type:"text",value:V.properties.field??"",group:S.groupContent}),w},[V]);return l.useEffect(()=>{const w=H.current;if(!w)return;const M=m=>{const n=["INPUT","TEXTAREA","SELECT"].includes(m.target.tagName),a=m.ctrlKey||m.metaKey;if((m.key==="Delete"||m.key==="Backspace")&&p.count>0&&!n){m.preventDefault(),ae();return}if(m.key==="Escape"){p.clearSelection();return}if(!n){if(a&&m.key==="z"&&!m.shiftKey&&!v){m.preventDefault(),c.undo();return}if(a&&(m.key==="z"&&m.shiftKey||m.key==="y")&&!v){m.preventDefault(),c.redo();return}if(a&&m.key==="c"){m.preventDefault(),B();return}if(a&&m.key==="v"&&!v){m.preventDefault(),le();return}if(a&&m.key==="a"){m.preventDefault();const r=d.flatMap(t=>t.elements).map(t=>t.id);p.selectMany(r);return}}};return w.addEventListener("keydown",M),()=>w.removeEventListener("keydown",M)},[p,ae,v,c,B,le,d]),e.jsxs("div",{ref:H,tabIndex:0,className:oe("flex h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[f&&e.jsxs("div",{role:"toolbar","aria-label":S.designerToolbar,className:"flex items-center gap-2 p-2 border-b bg-muted/20",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:o}),A&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",A,")"]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canUndo&&"opacity-40 pointer-events-none"),title:S.undoShortcut,"aria-label":S.undo,disabled:!c.canUndo,onClick:()=>c.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canRedo&&"opacity-40 pointer-events-none"),title:S.redoShortcut,"aria-label":S.redo,disabled:!c.canRedo,onClick:()=>c.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.copyShortcut,"aria-label":S.copy,disabled:p.count===0,onClick:B,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!I.hasContent&&"opacity-40 pointer-events-none"),title:S.pasteShortcut,"aria-label":S.paste,disabled:!I.hasContent,onClick:le,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.deleteSelected,"aria-label":S.deleteSelected,disabled:p.count===0,onClick:ae,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),S.collaborationConnected,O.users.length>1&&` (${O.users.length})`]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[F," ",C]}),g&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:E?S.collapsePanel:S.expandPanel,"aria-label":E?S.collapsePanel:S.expandPanel,onClick:()=>N(w=>!w),children:e.jsx(Ue,{className:oe("h-4 w-4",!E&&"rotate-180")})})]}),e.jsx("div",{role:"region","aria-label":S.reportCanvas,className:"flex-1 overflow-auto bg-muted/10 p-4 flex justify-center",children:e.jsx("div",{className:"bg-white shadow-lg border",style:{width:Z,minHeight:Q},children:d.map((w,M)=>e.jsxs("div",{className:"relative border-b border-dashed border-gray-300",style:{minHeight:w.height},onDragOver:_,onDrop:m=>ne(m,M),children:[e.jsxs("div",{className:"absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br",children:[Y(w.type),w.repeat&&" ↻"]}),!v&&e.jsxs("div",{className:"absolute right-1 top-0 flex items-center gap-0.5",children:[e.jsx("button",{onClick:()=>q(M,"text"),className:"p-0.5 rounded hover:bg-accent",title:S.addText,"aria-label":S.addText,children:e.jsx(Mt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"field"),className:"p-0.5 rounded hover:bg-accent",title:S.addField,"aria-label":S.addField,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"image"),className:"p-0.5 rounded hover:bg-accent",title:S.addImage,"aria-label":S.addImage,children:e.jsx(Be,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"chart"),className:"p-0.5 rounded hover:bg-accent",title:S.addChart,"aria-label":S.addChart,children:e.jsx(Rt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"table"),className:"p-0.5 rounded hover:bg-accent",title:S.addTable,"aria-label":S.addTable,children:e.jsx(Gt,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"relative",style:{minHeight:w.height,paddingTop:24},children:[w.elements.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground text-center pt-4",children:S.addElementsPrompt}),w.elements.map(m=>{const n=p.isSelected(m.id);return e.jsxs("div",{draggable:!v,onDragStart:a=>se(a,m,M),className:oe("absolute border rounded px-2 py-1 text-xs cursor-pointer",n?"border-primary ring-1 ring-primary/30 bg-primary/5":"border-dashed border-gray-400 hover:border-primary/50"),style:{left:m.position.x,top:(typeof m.position.y=="number"?m.position.y:0)+24,width:m.position.width,height:m.position.height},onClick:a=>p.toggle(m.id,a.shiftKey),children:[e.jsxs("span",{className:"text-muted-foreground",children:[m.type==="text"&&(m.properties.text??S.elementText),m.type==="field"&&`{${m.properties.field??"field"}}`,m.type==="image"&&S.elementImage,m.type==="chart"&&S.elementChart,m.type==="table"&&S.elementTable]}),!v&&n&&e.jsx("button",{onClick:a=>{a.stopPropagation(),J(m.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":S.deleteElement,children:e.jsx(de,{className:"h-2.5 w-2.5"})})]},m.id)})]})]},`${w.type}-${M}`))})})]}),g&&e.jsx("div",{role:"region","aria-label":S.propertiesPanel,className:oe("border-l bg-muted/30 flex flex-col transition-[width] duration-200",E?"w-56":"w-0 overflow-hidden"),children:E&&(x&&V?e.jsx(Oe,{title:`${S.properties} – ${V.type}`,fields:re,onChange:ee}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:S.properties}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:S.selectElementPrompt})})]}))}),e.jsx(Fe,{isOpen:P.isOpen,title:P.title,message:P.message,onConfirm:P.onConfirm,onCancel:P.onCancel})]})}function Ee(...o){return ue(pe(o))}const D={title:"View Designer",saveView:"Save View",cancel:"Cancel",availableFields:"Available Fields",allFieldsAdded:"All fields added",noColumnsTitle:"No columns added yet. Select fields from the palette to add columns.",columnsCount:o=>`Columns (${o})`,viewType:"View Type",viewName:"View Name",viewNamePlaceholder:"Enter view name...",columnProperties:"Column Properties",selectColumnPrompt:"Select a column to edit its properties",labelField:"Label",widthField:"Width",widthPlaceholder:"auto",fieldLabel:"Field:",addFilter:"Add Filter",addSort:"Add Sort",valuePlaceholder:"Value",asc:"Asc",desc:"Desc",selectField:"Select field...",moveUp:"Move up",moveDown:"Move down",moveColumnUp:"Move column up",moveColumnDown:"Move column down",hideColumn:"Hide column",showColumn:"Show column",toggleVisibility:"Toggle column visibility",removeColumn:"Remove column",copyColumn:"Copy column",pasteColumn:"Paste column",deleteColumnTitle:"Delete Column",deleteColumnMessage:o=>`Are you sure you want to delete the column "${o}"? This action cannot be undone.`,undo:"Undo (Ctrl+Z)",redo:"Redo (Ctrl+Y)",gridOptionsHint:"Grid view uses the columns configured above.",groupByField:"Group By Field",startDateField:"Start Date Field",titleField:"Title Field",latitudeField:"Latitude Field",longitudeField:"Longitude Field",imageField:"Image Field",dateField:"Date Field"},We=[{type:"grid",label:"Grid",icon:mt},{type:"kanban",label:"Kanban",icon:xt},{type:"gallery",label:"Gallery",icon:Be},{type:"calendar",label:"Calendar",icon:ht},{type:"timeline",label:"Timeline",icon:bt},{type:"gantt",label:"Gantt",icon:gt},{type:"map",label:"Map",icon:qe}],ta=[{value:"equals",label:"="},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:">="},{value:"lte",label:"<="},{value:"ne",label:"!="}];function lt({objectName:o,viewId:A,viewLabel:F="",viewType:C="grid",columns:b=[],filters:$=[],sort:f=[],availableFields:g=[],options:v={},readOnly:s=!1,onSave:y,onCancel:c,className:d}){const j=l.useRef(null),p=Se({columns:b,filters:$,sort:f,viewType:C,viewLabel:F,options:v}),{columns:x,filters:I,sort:P,viewType:O,viewLabel:k,options:E}=p.current,N=l.useCallback(a=>{p.push({...p.current,...a})},[p]),L=Te(),H=De(),G=Ie(),[Z,Q]=l.useState(null),[Y,V]=l.useState("columns"),q=l.useMemo(()=>{const a=new Set(x.map(r=>r.field));return g.filter(r=>!a.has(r.name))},[g,x]),J=l.useCallback(a=>{if(s)return;const r=g.find(i=>i.name===a),t={field:a,label:r?.label??a,visible:!0,order:x.length};N({columns:[...x,t]}),G?.sendOperation({type:"insert",userId:G.currentUserId??"",elementId:a,data:{column:t}})},[g,x,s,N,G]),ae=l.useCallback(async a=>{if(s)return;const r=x[a];!r||!await H.confirm(D.deleteColumnTitle,D.deleteColumnMessage(r.label||r.field))||(N({columns:x.filter((t,i)=>i!==a)}),Z===a&&Q(null),G?.sendOperation({type:"delete",userId:G.currentUserId??"",elementId:r.field,data:{}}))},[s,x,H,N,Z,G]),ee=l.useCallback(a=>{s||N({columns:x.map((r,t)=>t===a?{...r,visible:!r.visible}:r)})},[s,x,N]),B=l.useCallback((a,r)=>{if(s)return;const t=r==="up"?a-1:a+1;if(t<0||t>=x.length)return;const i=[...x],h=i[a];i[a]=i[t],i[t]=h,N({columns:i}),Q(t)},[s,x,N]),le=l.useCallback(()=>{s||g.length===0||N({filters:[...I,{field:g[0].name,operator:"equals",value:""}]})},[s,g,I,N]),se=l.useCallback(a=>{s||N({filters:I.filter((r,t)=>t!==a)})},[s,I,N]),_=l.useCallback((a,r)=>{s||N({filters:I.map((t,i)=>i===a?{...t,...r}:t)})},[s,I,N]),ne=l.useCallback(()=>{s||g.length===0||N({sort:[...P,{field:g[0].name,direction:"asc"}]})},[s,g,P,N]),re=l.useCallback(a=>{s||N({sort:P.filter((r,t)=>t!==a)})},[s,P,N]),w=l.useCallback((a,r)=>{s||N({sort:P.map((t,i)=>i===a?{...t,...r}:t)})},[s,P,N]),M=l.useCallback(()=>{Z===null||!x[Z]||L.copy(x[Z])},[Z,x,L]),m=l.useCallback(()=>{if(s)return;const a=L.paste();if(!a)return;const r={...a,field:`${a.field}_copy`,label:`${a.label||a.field} (Copy)`,order:x.length};N({columns:[...x,r]})},[s,L,x,N]),n=l.useCallback(()=>{y?.({viewId:A,viewLabel:k||`${o} View`,viewType:O,columns:x,filters:I,sort:P,options:E})},[y,A,k,o,O,x,I,P,E]);return l.useEffect(()=>{const a=j.current;if(!a)return;const r=t=>{const i=["INPUT","TEXTAREA","SELECT"].includes(t.target.tagName),h=t.ctrlKey||t.metaKey;if(!i){if(h&&t.key==="z"&&!t.shiftKey&&!s){t.preventDefault(),p.undo();return}if(h&&(t.key==="z"&&t.shiftKey||t.key==="y")&&!s){t.preventDefault(),p.redo();return}if(h&&t.key==="c"){t.preventDefault(),M();return}if(h&&t.key==="v"&&!s){t.preventDefault(),m();return}}};return a.addEventListener("keydown",r),()=>a.removeEventListener("keydown",r)},[s,p,M,m]),e.jsxs("div",{ref:j,tabIndex:-1,className:Ee("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",d),children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20 shrink-0",role:"toolbar",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-sm",children:D.title}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["— ",o]}),G?.isConnected&&G.users.length>1&&e.jsxs("div",{className:"flex items-center gap-1 ml-2",role:"status","aria-label":"Active collaborators",children:[G.users.slice(0,3).map(a=>e.jsx("div",{className:"h-5 w-5 rounded-full text-[10px] font-bold flex items-center justify-center text-white",style:{backgroundColor:a.color},title:a.userName,children:a.userName.charAt(0).toUpperCase()},a.userId)),G.users.length>3&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",G.users.length-3]})]}),e.jsx("div",{className:"flex-1"}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:p.undo,disabled:!p.canUndo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.undo,"aria-label":D.undo,"data-testid":"view-designer-undo",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:p.redo,disabled:!p.canRedo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.redo,"aria-label":D.redo,"data-testid":"view-designer-redo",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:M,disabled:Z===null,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.copyColumn,"aria-label":D.copyColumn,"data-testid":"view-designer-copy",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:m,disabled:!L.hasContent,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.pasteColumn,"aria-label":D.pasteColumn,"data-testid":"view-designer-paste",children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[c&&e.jsxs("button",{onClick:c,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border hover:bg-accent","data-testid":"view-designer-cancel",children:[e.jsx(ut,{className:"h-3 w-3"})," ",D.cancel]}),e.jsxs("button",{onClick:n,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90","data-testid":"view-designer-save",children:[e.jsx(pt,{className:"h-3 w-3"})," ",D.saveView]})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[!s&&e.jsxs("div",{className:"w-56 border-r bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:D.availableFields}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:q.length===0?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.allFieldsAdded}):q.map(a=>e.jsxs("button",{onClick:()=>J(a.name),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left","data-testid":`field-${a.name}`,children:[e.jsx(ce,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:a.label||a.name}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:a.type})]},a.name))})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-3 border-b space-y-3 shrink-0 bg-muted/10",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewType}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:We.map(({type:a,label:r,icon:t})=>e.jsxs("button",{onClick:()=>!s&&N({viewType:a}),className:Ee("flex items-center gap-2 px-3 py-2 text-sm rounded-md border-2 transition-all font-medium",O===a?"border-primary bg-primary text-primary-foreground shadow-sm":"border-border bg-background hover:border-primary/50 hover:bg-accent"),"data-testid":`view-type-${a}`,children:[e.jsx(t,{className:"h-4 w-4"}),r]},a))})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewName}),e.jsx("input",{type:"text",value:k,onChange:a=>!s&&N({viewLabel:a.target.value}),placeholder:D.viewNamePlaceholder,className:"px-3 py-2 text-sm border-2 rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary",readOnly:s,"data-testid":"view-label-input"})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-3",children:x.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ft,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:D.noColumnsTitle})]})}):e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:D.columnsCount(x.length)}),x.map((a,r)=>e.jsxs("div",{className:Ee("flex items-center gap-2 px-3 py-2 rounded border transition-colors cursor-pointer",Z===r?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border hover:border-primary/50",!a.visible&&"opacity-50"),onClick:()=>Q(r),"data-testid":`column-${a.field}`,children:[e.jsx(_e,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm font-medium truncate flex-1",children:a.label||a.field}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.field}),!s&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"up")},disabled:r===0,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveUp,"aria-label":D.moveColumnUp,children:e.jsx(yt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"down")},disabled:r===x.length-1,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveDown,"aria-label":D.moveColumnDown,children:e.jsx(vt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ee(r)},className:"p-0.5 rounded hover:bg-accent",title:a.visible!==!1?D.hideColumn:D.showColumn,"aria-label":D.toggleVisibility,children:a.visible!==!1?e.jsx(Je,{className:"h-3 w-3"}):e.jsx(wt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ae(r)},className:"p-0.5 rounded hover:bg-destructive/10",title:D.removeColumn,"aria-label":D.removeColumn,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]})]},`${a.field}-${r}`))]})})]}),e.jsxs("div",{className:"w-64 border-l bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"flex border-b shrink-0",role:"tablist",children:["columns","filters","sort","options"].map(a=>e.jsx("button",{onClick:()=>V(a),role:"tab","aria-selected":Y===a,className:Ee("flex-1 px-2 py-2 text-xs font-medium capitalize transition-colors",Y===a?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"),children:a},a))}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[Y==="columns"&&e.jsx("div",{children:Z!==null&&x[Z]?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium",children:D.columnProperties}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.labelField}),e.jsx("input",{type:"text",value:x[Z].label??"",onChange:a=>{if(s)return;const r=Z;N({columns:x.map((t,i)=>i===r?{...t,label:a.target.value}:t)})},className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-label-input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.widthField}),e.jsx("input",{type:"text",value:x[Z].width??"",onChange:a=>{if(s)return;const r=Z,t=a.target.value;N({columns:x.map((i,h)=>h===r?{...i,width:/^\d+$/.test(t)?Number(t):t}:i)})},placeholder:D.widthPlaceholder,className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-width-input"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[D.fieldLabel," ",e.jsx("span",{className:"font-mono",children:x[Z].field})]})]}):e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.selectColumnPrompt})}),Y==="filters"&&e.jsxs("div",{className:"space-y-2",children:[I.map((a,r)=>e.jsxs("div",{className:"space-y-1 p-2 border rounded bg-background","data-testid":`filter-${r}`,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.field,onChange:t=>_(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),!s&&e.jsx("button",{onClick:()=>se(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.operator,onChange:t=>_(r,{operator:t.target.value}),className:"w-24 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:ta.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("input",{type:"text",value:a.value??"",onChange:t=>_(r,{value:t.target.value}),placeholder:D.valuePlaceholder,className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",readOnly:s})]})]},r)),!s&&e.jsxs("button",{onClick:le,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-filter","aria-label":D.addFilter,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addFilter]})]}),Y==="sort"&&e.jsxs("div",{className:"space-y-2",children:[P.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-1 p-2 border rounded bg-background","data-testid":`sort-${r}`,children:[e.jsx("select",{value:a.field,onChange:t=>w(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),e.jsxs("select",{value:a.direction,onChange:t=>w(r,{direction:t.target.value}),className:"w-16 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:[e.jsx("option",{value:"asc",children:D.asc}),e.jsx("option",{value:"desc",children:D.desc})]}),!s&&e.jsx("button",{onClick:()=>re(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]},r)),!s&&e.jsxs("button",{onClick:ne,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-sort","aria-label":D.addSort,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addSort]})]}),Y==="options"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs font-medium",children:[We.find(a=>a.type===O)?.label??O," Options"]}),O==="kanban"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.groupByField}),e.jsxs("select",{value:E.groupBy??"",onChange:a=>!s&&N({options:{...E,groupBy:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"kanban-group-by",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),O==="calendar"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.startDateField}),e.jsxs("select",{value:E.startDateField??"",onChange:a=>!s&&N({options:{...E,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-start-date",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-title-field",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="map"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.latitudeField}),e.jsxs("select",{value:E.latitudeField??"",onChange:a=>!s&&N({options:{...E,latitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.longitudeField}),e.jsxs("select",{value:E.longitudeField??"",onChange:a=>!s&&N({options:{...E,longitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="gallery"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.imageField}),e.jsxs("select",{value:E.imageField??"",onChange:a=>!s&&N({options:{...E,imageField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),(O==="timeline"||O==="gantt")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.dateField}),e.jsxs("select",{value:E.dateField??E.startDateField??"",onChange:a=>!s&&N({options:{...E,dateField:a.target.value,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="grid"&&e.jsx("div",{className:"text-xs text-muted-foreground text-center py-2",children:D.gridOptionsHint})]})]})]})]}),e.jsx(Fe,{isOpen:H.isOpen,title:H.title,message:H.message,onConfirm:H.onConfirm,onCancel:H.onCancel})]})}we.register("page-designer",Kt,{label:"Page Designer",category:"Designer",inputs:[{name:"canvas",type:"code",label:"Canvas Configuration"},{name:"components",type:"code",label:"Components"},{name:"showComponentTree",type:"boolean",label:"Show Component Tree",defaultValue:!0},{name:"undoRedo",type:"boolean",label:"Undo/Redo",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});we.register("data-model-designer",Bt,{label:"Data Model Designer",category:"Designer",inputs:[{name:"entities",type:"code",label:"Entities"},{name:"relationships",type:"code",label:"Relationships"},{name:"autoLayout",type:"boolean",label:"Auto Layout",defaultValue:!1},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});we.register("process-designer",_t,{label:"Process Designer (BPMN)",category:"Designer",inputs:[{name:"processName",type:"string",label:"Process Name"},{name:"nodes",type:"code",label:"Nodes"},{name:"edges",type:"code",label:"Edges"},{name:"showMinimap",type:"boolean",label:"Show Minimap",defaultValue:!1},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});we.register("report-designer",ea,{label:"Report Designer",category:"Designer",inputs:[{name:"reportName",type:"string",label:"Report Name"},{name:"objectName",type:"string",label:"Data Source Object"},{name:"sections",type:"code",label:"Sections"},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"showPropertyPanel",type:"boolean",label:"Show Property Panel",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});we.register("view-designer",lt,{label:"View Designer",category:"Designer",inputs:[{name:"objectName",type:"string",label:"Object Name"},{name:"viewId",type:"string",label:"View ID"},{name:"viewLabel",type:"string",label:"View Label"},{name:"viewType",type:"string",label:"View Type",defaultValue:"grid"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});function ra({objects:o}){const A=it(),{objectName:F,viewId:C}=ot(),b=o.find(s=>s.name===F),$=l.useMemo(()=>{if(!b?.fields)return[];const s=b.fields;return Array.isArray(s)?s.map(y=>typeof y=="string"?{name:y,label:y,type:"text"}:{name:y.name,label:y.label||y.name,type:y.type||"text"}):Object.entries(s).map(([y,c])=>({name:y,label:c.label||y,type:c.type||"text"}))},[b]),f=l.useMemo(()=>!C||C==="new"||!b?.list_views?null:b.list_views[C]||null,[C,b]),g=l.useCallback(s=>{console.log("[ViewDesigner] Save view config:",s),dt.success(f?`View "${s.viewLabel}" updated`:`View "${s.viewLabel}" created`),A(-1)},[f,A]),v=l.useCallback(()=>{A(-1)},[A]);return b?Ae.jsx("div",{className:"h-full flex flex-col",children:Ae.jsx(lt,{objectName:b.name,viewId:C==="new"?void 0:C,viewLabel:f?.label??"",viewType:f?.type??"grid",columns:f?.columns?f.columns.map((s,y)=>({field:s,label:$.find(c=>c.name===s)?.label??s,visible:!0,order:y})):[],filters:f?.filter??[],sort:f?.sort?.map(s=>({field:s.field,direction:s.order||s.direction||"asc"}))??[],availableFields:$,options:f?.options??{},onSave:g,onCancel:v,className:"flex-1"})}):Ae.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:['Object "',F,'" not found']})}export{ra as ViewDesignerPage};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{O}from"./vendor-objectstack-DqojdwYW.js";import{h as C}from"./framework-mHWN965c.js";class ${cache;maxSize;ttl;stats;constructor(t={}){this.cache=new Map,this.maxSize=t.maxSize||100,this.ttl=t.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0}}async get(t,e){const s=Date.now(),n=this.cache.get(t);if(n){if(s-n.timestamp<this.ttl)return n.accessCount++,n.lastAccessed=s,this.stats.hits++,this.cache.delete(t),this.cache.set(t,n),n.data;this.cache.delete(t)}this.stats.misses++;const a=await e();return this.set(t,a),a}set(t,e){const s=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(t)&&this.evictLRU(),this.cache.set(t,{data:e,timestamp:s,accessCount:1,lastAccessed:s})}evictLRU(){const t=this.cache.keys().next().value;t!==void 0&&(this.cache.delete(t),this.stats.evictions++)}invalidate(t){t?this.cache.delete(t):this.cache.clear()}clear(){this.cache.clear(),this.stats={hits:0,misses:0,evictions:0}}getStats(){const t=this.stats.hits+this.stats.misses,e=t>0?this.stats.hits/t:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,hitRate:e}}getCachedSync(t){const e=this.cache.get(t);if(e){if(this.ttl>0&&Date.now()-e.timestamp>this.ttl){this.cache.delete(t);return}return this.cache.delete(t),this.cache.set(t,e),this.stats.hits++,e.data}}has(t){const e=this.cache.get(t);return e?Date.now()-e.timestamp>=this.ttl?(this.cache.delete(t),!1):!0:!1}}class h extends Error{constructor(t,e,s,n){super(t),this.code=e,this.statusCode=s,this.details=n,this.name="ObjectStackError",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}}class y extends h{constructor(t,e){super(`Metadata not found for object: ${t}`,"METADATA_NOT_FOUND",404,{objectName:t,...e}),this.name="MetadataNotFoundError"}}class g extends h{constructor(t,e,s,n,a){super(`Bulk ${t} operation failed: ${e} succeeded, ${s} failed`,"BULK_OPERATION_ERROR",500,{operation:t,successCount:e,failureCount:s,errors:n,...a}),this.successCount=e,this.failureCount=s,this.errors=n,this.name="BulkOperationError"}getSummary(){const t=this.successCount+this.failureCount,e=t>0?this.failureCount/t:0;return{operation:this.details?.operation,total:t,successful:this.successCount,failed:this.failureCount,failureRate:e,errors:this.errors}}}class w extends h{constructor(t,e,s,n){super(`Connection error: ${t}`,"CONNECTION_ERROR",n||503,{url:e,...s}),this.url=e,this.name="ConnectionError"}}class p extends h{constructor(t="Authentication failed",e,s){super(t,"AUTHENTICATION_ERROR",s||401,e),this.name="AuthenticationError"}}class E extends h{constructor(t,e,s,n){super(t,"VALIDATION_ERROR",400,{field:e,validationErrors:s,...n}),this.field=e,this.validationErrors=s,this.name="ValidationError"}getValidationErrors(){return this.validationErrors||[]}}function R(i,t){const e=i?.status||i?.statusCode||500,s=i?.message||i?.statusText||"Unknown error",n={context:t,response:{status:e,data:i?.data,headers:i?.headers}};switch(e){case 401:return new p(s,n,401);case 403:return new p(s,n,403);case 404:if(t?.includes("metadata")||t?.includes("schema")||t?.includes("getObjectSchema")){const a=A(t);return new y(a,n)}return new h(s,"NOT_FOUND",404,n);case 400:return new E(s,void 0,i?.data?.errors,n);case 503:return new w(s,i?.config?.url,n,503);case 504:return new w(s,i?.config?.url,n,504);default:return new h(s,"UNKNOWN_ERROR",e,n)}}function A(i){if(!i)return"unknown";const t=i.match(/\(([^)]+)\)/);return t?t[1]:"unknown"}class N{client;connected=!1;metadataCache;connectionState="disconnected";connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;constructor(t){this.client=new O(t),this.metadataCache=new $(t.cache),this.autoReconnect=t.autoReconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??3,this.reconnectDelay=t.reconnectDelay??1e3,this.baseUrl=t.baseUrl,this.token=t.token}async connect(){if(!this.connected){this.setConnectionState("connecting");try{await this.client.connect(),this.connected=!0,this.reconnectAttempts=0,this.setConnectionState("connected")}catch(t){const e=t instanceof Error?t.message:"Failed to connect to ObjectStack server",s=new w(e,void 0,{originalError:t});if(this.setConnectionState("error",s),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw s}}}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState("reconnecting");const t=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);await new Promise(e=>setTimeout(e,t)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState==="connected"}onConnectionStateChange(t){return this.connectionStateListeners.push(t),()=>{const e=this.connectionStateListeners.indexOf(t);e>-1&&this.connectionStateListeners.splice(e,1)}}onBatchProgress(t){return this.batchProgressListeners.push(t),()=>{const e=this.batchProgressListeners.indexOf(t);e>-1&&this.batchProgressListeners.splice(e,1)}}setConnectionState(t,e){this.connectionState=t;const s={state:t,timestamp:Date.now(),error:e};this.connectionStateListeners.forEach(n=>{try{n(s)}catch(a){console.error("Error in connection state listener:",a)}})}emitBatchProgress(t){this.batchProgressListeners.forEach(e=>{try{e(t)}catch(s){console.error("Error in batch progress listener:",s)}})}async find(t,e){await this.connect();const s=this.convertQueryParams(e),n=await this.client.data.find(t,s);if(Array.isArray(n))return{data:n,total:n.length,page:1,pageSize:n.length,hasMore:!1};const a=n,r=a.records||a.value||[],o=a.total??a.count??r.length;return{data:r,total:o,page:e?.$skip&&e.$top?Math.floor(e.$skip/e.$top)+1:1,pageSize:e?.$top,hasMore:e?.$top?r.length===e.$top:!1}}async findOne(t,e,s){await this.connect();try{return(await this.client.data.get(t,String(e))).record}catch(n){if(n?.status===404)return null;throw n}}async create(t,e){return await this.connect(),(await this.client.data.create(t,e)).record}async update(t,e,s){return await this.connect(),(await this.client.data.update(t,String(e),s)).record}async delete(t,e){return await this.connect(),(await this.client.data.delete(t,String(e))).deleted}async bulk(t,e,s){if(await this.connect(),!s||s.length===0)return[];const n=s.length;let a=0,r=0;const o=()=>{this.emitBatchProgress({operation:e,total:n,completed:a,failed:r,percentage:n>0?(a+r)/n*100:0})};try{switch(e){case"create":{o();const c=await this.client.data.createMany(t,s);return a=c.length,r=n-a,o(),c}case"delete":{const c=s.map(l=>l.id).filter(Boolean);if(c.length===0){const l=s.map((u,d)=>({index:d,error:`Missing ID for item at index ${d}`}));throw r=s.length,o(),new g("delete",0,s.length,l)}return o(),await this.client.data.deleteMany(t,c),a=c.length,r=n-a,o(),[]}case"update":{if(typeof this.client.data.updateMany=="function")try{o();const u=this.client.data.updateMany,d=await u(t,s);return a=d.length,r=n-a,o(),d}catch{}const c=[],l=[];for(let u=0;u<s.length;u++){const d=s[u],m=d.id;if(!m){l.push({index:u,error:"Missing ID"}),r++,o();continue}try{const f=await this.client.data.update(t,String(m),d);c.push(f.record),a++,o()}catch(f){const S=f instanceof Error?f.message:String(f);l.push({index:u,error:S}),r++,o()}}if(l.length>0)throw new g("update",c.length,l.length,l,{resource:t,totalRecords:s.length});return c}default:throw new h(`Unsupported bulk operation: ${e}`,"UNSUPPORTED_OPERATION",400)}}catch(c){if(o(),c instanceof g||c instanceof h)throw c;const l=c instanceof Error?c.message:String(c),u=s.map((d,m)=>({index:m,error:l}));throw new g(e,0,s.length,u,{resource:t,originalError:c})}}convertQueryParams(t){if(!t)return{};const e={};if(t.$select&&(e.select=t.$select),t.$filter&&(Array.isArray(t.$filter)?e.filters=t.$filter:e.filters=C(t.$filter)),t.$orderby)if(Array.isArray(t.$orderby))e.sort=t.$orderby.map(s=>{if(typeof s=="string")return s;const n=s.field;return(s.order||"asc")==="desc"?`-${n}`:n});else{const s=Object.entries(t.$orderby).map(([n,a])=>a==="desc"?`-${n}`:n);e.sort=s}return t.$skip!==void 0&&(e.skip=t.$skip),t.$top!==void 0&&(e.top=t.$top),e}async getObjectSchema(t){await this.connect();try{return await this.metadataCache.get(t,async()=>{const s=await this.client.meta.getItem("object",t);return s&&s.item?s.item:s})}catch(e){const s=e;throw s?.status===404||s?.statusCode===404?new y(t,{originalError:e}):e instanceof h?e:R(s,`getObjectSchema(${t})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(t,e){await this.connect();try{const s=`view:${t}:${e}`;return await this.metadataCache.get(s,async()=>{const n=await this.client.meta.getItem(t,`views/${e}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(t){await this.connect();try{const e=`app:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("apps",t);return s&&s.item?s.item:s??null})}catch{return null}}async getPage(t){await this.connect();try{const e=`page:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("pages",t);return s&&s.item?s.item:s??null})}catch{return null}}async getItems(t,e){return await this.connect(),await Promise.all(e.map(async n=>{const a=`${t}:${n}`;return this.metadataCache.get(a,async()=>{const r=await this.client.meta.getItem(t,n);return r&&r.item?r.item:r})}))}getCached(t){return this.metadataCache.getCachedSync(t)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(t){this.metadataCache.invalidate(t)}clearCache(){this.metadataCache.clear()}async uploadFile(t,e,s){await this.connect();const n=new FormData;n.append("file",e),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}async uploadFiles(t,e,s){await this.connect();const n=new FormData;e.forEach((o,c)=>{n.append("files",o,o.name||`file-${c}`)}),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}getAuthHeaders(){const t={};return this.token&&(t.Authorization=`Bearer ${this.token}`),t}}export{N as O};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{r as F,j as J,R as x}from"./vendor-react-Dy_xkBQQ.js";class qt{components=new Map;register(e,t,s){const n=s?.namespace?`${s.namespace}:${e}`:e;s?.namespace||console.warn(`Registering component "${e}" without a namespace is deprecated. Please provide a namespace in the meta parameter.
|
|
2
|
+
|
|
3
|
+
Migration:
|
|
4
|
+
// Before (deprecated):
|
|
5
|
+
registry.register('${e}', MyComponent);
|
|
6
|
+
|
|
7
|
+
// After:
|
|
8
|
+
registry.register('${e}', MyComponent, { namespace: 'my-plugin' });
|
|
9
|
+
|
|
10
|
+
See: https://github.com/objectstack-ai/objectui/blob/main/MIGRATION_GUIDE.md`),this.components.has(n),this.components.set(n,{type:n,component:t,...s}),s?.namespace&&!s?.skipFallback&&this.components.set(e,{type:n,component:t,...s})}get(e,t){if(t){const s=`${t}:${e}`;return this.components.get(s)?.component}return this.components.get(e)?.component}getConfig(e,t){if(t){const s=`${t}:${e}`;return this.components.get(s)}return this.components.get(e)}has(e,t){if(t){const s=`${t}:${e}`;return this.components.has(s)}return this.components.has(e)}getAllTypes(){return Array.from(this.components.keys())}getAllConfigs(){return Array.from(this.components.values())}getNamespaceComponents(e){return Array.from(this.components.values()).filter(t=>t.namespace===e)}}const Wt=new qt;function zt(r){return{$eq:"=",$ne:"!=",$gt:">",$gte:">=",$lt:"<",$lte:"<=",$in:"in",$nin:"notin",$notin:"notin",$contains:"contains",$startswith:"startswith",$between:"between"}[r]||null}function Or(r){const e=[];for(const[t,s]of Object.entries(r))if(s!=null)if(typeof s=="object"&&!Array.isArray(s))for(const[n,i]of Object.entries(s)){if(n==="$regex"){console.warn(`[ObjectUI] Warning: $regex operator is not fully supported. Converting to 'contains' which only supports substring matching, not regex patterns. Field: '${t}', Value: ${JSON.stringify(i)}. Consider using $contains or $startswith instead.`),e.push([t,"contains",i]);continue}const o=zt(n);if(o)e.push([t,o,i]);else throw new Error(`[ObjectUI] Unknown filter operator '${n}' for field '${t}'. Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $contains, $startswith, $between. If you need exact object matching, use the value directly without an operator.`)}else e.push([t,"=",s]);return e.length===0?r:e.length===1?e[0]:["and",...e]}class Se{scopes=[];constructor(e={}){this.scopes.push(new Map(Object.entries(e)))}pushScope(e){this.scopes.push(new Map(Object.entries(e)))}popScope(){this.scopes.length>1&&this.scopes.pop()}get(e){const t=e.split("."),s=t[0];for(let n=this.scopes.length-1;n>=0;n--)if(this.scopes[n].has(s)){let i=this.scopes[n].get(s);for(let o=1;o<t.length;o++)if(i&&typeof i=="object")i=i[t[o]];else return;return i}}set(e,t){this.scopes.length>0&&this.scopes[this.scopes.length-1].set(e,t)}has(e){const t=e.split(".")[0];for(let s=this.scopes.length-1;s>=0;s--)if(this.scopes[s].has(t))return!0;return!1}toObject(){const e={};for(const t of this.scopes)for(const[s,n]of t.entries())e[s]=n;return e}createChild(e={}){const t=new Se;return t.scopes=[...this.scopes,new Map(Object.entries(e))],t}}class Yt{cache=new Map;maxSize;constructor(e=1e3){this.maxSize=e}compile(e,t){const s=`${e}::${t.join(",")}`;if(this.cache.has(s)){const o=this.cache.get(s);return o.hitCount++,o}this.cache.size>=this.maxSize&&this.evictLFU();const i={fn:this.compileExpression(e,t),varNames:[...t],expression:e,compiledAt:Date.now(),hitCount:1};return this.cache.set(s,i),i}compileExpression(e,t){return new Function(...t,`"use strict"; return (${e});`)}evictLFU(){let e=null,t=1/0,s=1/0;for(const[n,i]of this.cache.entries())(i.hitCount<s||i.hitCount===s&&i.compiledAt<t)&&(e=n,t=i.compiledAt,s=i.hitCount);e&&this.cache.delete(e)}has(e,t){const s=`${e}::${t.join(",")}`;return this.cache.has(s)}clear(){this.cache.clear()}getStats(){let e=0;const t=[];for(const s of this.cache.values())e+=s.hitCount,t.push({expression:s.expression,hitCount:s.hitCount});return{size:this.cache.size,maxSize:this.maxSize,totalHits:e,entries:t.sort((s,n)=>n.hitCount-s.hitCount)}}}class bt{functions=new Map;constructor(){this.registerDefaults()}register(e,t){this.functions.set(e.toUpperCase(),t)}get(e){return this.functions.get(e.toUpperCase())}has(e){return this.functions.has(e.toUpperCase())}getNames(){return Array.from(this.functions.keys())}toObject(){const e={};for(const[t,s]of this.functions)e[t]=s;return e}registerDefaults(){this.registerAggregationFunctions(),this.registerDateFunctions(),this.registerLogicFunctions(),this.registerStringFunctions(),this.registerStringSearchFunctions(),this.registerStatisticalFunctions()}registerAggregationFunctions(){this.register("SUM",(...e)=>ae(e).reduce((s,n)=>s+n,0)),this.register("AVG",(...e)=>{const t=ae(e);return t.length===0?0:t.reduce((s,n)=>s+n,0)/t.length}),this.register("COUNT",(...e)=>wt(e).filter(s=>s!=null).length),this.register("MIN",(...e)=>{const t=ae(e);return t.length===0?0:Math.min(...t)}),this.register("MAX",(...e)=>{const t=ae(e);return t.length===0?0:Math.max(...t)})}registerDateFunctions(){this.register("TODAY",()=>new Date().toISOString().split("T")[0]),this.register("NOW",()=>new Date().toISOString()),this.register("DATEADD",(e,t,s)=>{const n=new Date(e);if(isNaN(n.getTime()))throw new Error(`DATEADD: Invalid date "${e}"`);switch(String(s).toLowerCase()){case"day":case"days":n.setDate(n.getDate()+t);break;case"month":case"months":n.setMonth(n.getMonth()+t);break;case"year":case"years":n.setFullYear(n.getFullYear()+t);break;case"hour":case"hours":n.setHours(n.getHours()+t);break;case"minute":case"minutes":n.setMinutes(n.getMinutes()+t);break;default:throw new Error(`DATEADD: Unsupported unit "${s}"`)}return n.toISOString()}),this.register("DATEDIFF",(e,t,s)=>{const n=new Date(e),i=new Date(t);if(isNaN(n.getTime()))throw new Error(`DATEDIFF: Invalid date "${e}"`);if(isNaN(i.getTime()))throw new Error(`DATEDIFF: Invalid date "${t}"`);const o=i.getTime()-n.getTime();switch(String(s).toLowerCase()){case"day":case"days":return Math.floor(o/(1e3*60*60*24));case"month":case"months":return(i.getFullYear()-n.getFullYear())*12+(i.getMonth()-n.getMonth());case"year":case"years":return i.getFullYear()-n.getFullYear();case"hour":case"hours":return Math.floor(o/(1e3*60*60));case"minute":case"minutes":return Math.floor(o/(1e3*60));default:throw new Error(`DATEDIFF: Unsupported unit "${s}"`)}}),this.register("DATEFORMAT",(e,t)=>{const s=new Date(e);if(isNaN(s.getTime()))throw new Error(`DATEFORMAT: Invalid date "${e}"`);const n=(i,o=2)=>String(i).padStart(o,"0");return t.replace("YYYY",String(s.getFullYear())).replace("YY",String(s.getFullYear()).slice(-2)).replace("MM",n(s.getMonth()+1)).replace("DD",n(s.getDate())).replace("HH",n(s.getHours())).replace("mm",n(s.getMinutes())).replace("ss",n(s.getSeconds()))})}registerLogicFunctions(){this.register("IF",(e,t,s)=>e?t:s),this.register("AND",(...e)=>e.every(Boolean)),this.register("OR",(...e)=>e.some(Boolean)),this.register("NOT",e=>!e),this.register("SWITCH",(e,...t)=>{for(let s=0;s<t.length-1;s+=2)if(e===t[s])return t[s+1];if(t.length%2===1)return t[t.length-1]})}registerStringFunctions(){this.register("CONCAT",(...e)=>e.map(t=>String(t??"")).join("")),this.register("LEFT",(e,t)=>String(e??"").substring(0,t)),this.register("RIGHT",(e,t)=>{const s=String(e??"");return s.substring(Math.max(0,s.length-t))}),this.register("TRIM",e=>String(e??"").trim()),this.register("UPPER",e=>String(e??"").toUpperCase()),this.register("LOWER",e=>String(e??"").toLowerCase())}registerStringSearchFunctions(){this.register("FIND",(e,t,s)=>String(t??"").indexOf(String(e??""),s??0)),this.register("REPLACE",(e,t,s)=>String(e??"").split(String(t??"")).join(String(s??""))),this.register("SUBSTRING",(e,t,s)=>{const n=String(e??"");return s!==void 0?n.substring(t,t+s):n.substring(t)}),this.register("REGEX",(e,t,s)=>{const n=String(e??"");return new RegExp(t,s).test(n)}),this.register("LEN",e=>String(e??"").length)}registerStatisticalFunctions(){this.register("MEDIAN",(...e)=>{const t=ae(e).sort((n,i)=>n-i);if(t.length===0)return 0;const s=Math.floor(t.length/2);return t.length%2!==0?t[s]:(t[s-1]+t[s])/2}),this.register("STDEV",(...e)=>{const t=ae(e);if(t.length<2)return 0;const s=t.reduce((o,c)=>o+c,0)/t.length,i=t.map(o=>(o-s)**2).reduce((o,c)=>o+c,0)/(t.length-1);return Math.sqrt(i)}),this.register("VARIANCE",(...e)=>{const t=ae(e);if(t.length<2)return 0;const s=t.reduce((i,o)=>i+o,0)/t.length;return t.map(i=>(i-s)**2).reduce((i,o)=>i+o,0)/(t.length-1)}),this.register("PERCENTILE",(e,...t)=>{const s=ae(t).sort((p,V)=>p-V);if(s.length===0)return 0;const i=Math.max(0,Math.min(100,e))/100*(s.length-1),o=Math.floor(i),c=Math.ceil(i);if(o===c)return s[o];const m=i-o;return s[o]+m*(s[c]-s[o])})}}function ae(r){const e=[];for(const t of r)if(Array.isArray(t))e.push(...ae(t));else{const s=Number(t);isNaN(s)||e.push(s)}return e}function wt(r){const e=[];for(const t of r)Array.isArray(t)?e.push(...wt(t)):e.push(t);return e}class be{context;cache;formulas;constructor(e,t,s){e instanceof Se?this.context=e:this.context=new Se(e||{}),this.cache=t||new Yt,this.formulas=s||new bt}evaluate(e,t={}){if(typeof e!="string")return e;const{defaultValue:s,throwOnError:n=!1,sanitize:i=!0}=t;try{if(!e.includes("${"))return e;const c=e.match(/^\$\{([^}]+)\}$/);return c?this.evaluateExpression(c[1].trim(),{sanitize:i}):e.replace(/\$\{([^}]+)\}/g,(m,p)=>{try{const V=this.evaluateExpression(p.trim(),{sanitize:i});return String(V??"")}catch(V){if(n)throw V;return console.warn(`Expression evaluation failed for: ${p}`,V),m}})}catch(o){if(n)throw o;return console.warn(`Failed to evaluate expression: ${e}`,o),s??e}}evaluateExpression(e,t={}){const{sanitize:s=!0}=t;if(!(!e||e.trim()==="")){if(s&&this.isDangerous(e))throw new Error(`Potentially dangerous expression detected: ${e}`);try{const n=this.context.toObject(),o={...this.formulas.toObject(),...n},c=Object.keys(o),m=Object.values(o);return this.cache.compile(e,c).fn(...m)}catch(n){throw new Error(`Failed to evaluate expression "${e}": ${n.message}`)}}}isDangerous(e){return[/eval\s*\(/i,/Function\s*\(/i,/setTimeout\s*\(/i,/setInterval\s*\(/i,/import\s*\(/i,/require\s*\(/i,/process\./i,/global\./i,/window\./i,/document\./i,/__proto__/i,/constructor\s*\(/i,/prototype\./i].some(s=>s.test(e))}evaluateCondition(e,t={}){return typeof e=="boolean"?e:e?!!this.evaluate(e,t):!0}updateContext(e){Object.entries(e).forEach(([t,s])=>{this.context.set(t,s)})}getContext(){return this.context}withContext(e){return new be(this.context.createChild(e),this.cache,this.formulas)}getCacheStats(){return this.cache.getStats()}clearCache(){this.cache.clear()}getFormulas(){return this.formulas}registerFunction(e,t){this.formulas.register(e,t)}}new bt;class xt{handlers=new Map;evaluator;context;confirmHandler;toastHandler;modalHandler;navigationHandler;paramCollectionHandler;constructor(e={}){this.context=e,this.evaluator=new be(e),this.confirmHandler=async t=>window.confirm(t),this.toastHandler=null,this.modalHandler=null,this.navigationHandler=null,this.paramCollectionHandler=null}setConfirmHandler(e){this.confirmHandler=e}setToastHandler(e){this.toastHandler=e}setModalHandler(e){this.modalHandler=e}setNavigationHandler(e){this.navigationHandler=e}setParamCollectionHandler(e){this.paramCollectionHandler=e}registerHandler(e,t){this.handlers.set(e,t)}unregisterHandler(e){this.handlers.delete(e)}async execute(e){try{const t=e.type||e.actionType||e.name||"";if(e.condition&&!this.evaluator.evaluateCondition(e.condition))return{success:!1,error:"Action condition not met"};if(e.disabled&&(typeof e.disabled=="string"?this.evaluator.evaluateCondition(e.disabled):e.disabled))return{success:!1,error:"Action is disabled"};const s=e.confirm?.message||e.confirmText;if(s&&!await this.confirmHandler(this.evaluator.evaluate(s),e.confirm?{title:e.confirm.title,confirmText:e.confirm.confirmText,cancelText:e.confirm.cancelText}:void 0))return{success:!1,error:"Action cancelled by user"};if(e.actionParams&&Array.isArray(e.actionParams)&&e.actionParams.length>0&&this.paramCollectionHandler){const i=await this.paramCollectionHandler(e.actionParams);if(i===null)return{success:!1,error:"Action cancelled by user (params)"};e.params={...e.params||{},...i}}if(t&&this.handlers.has(t)){const o=await this.handlers.get(t)(e,this.context);return await this.handlePostExecution(e,o),o}let n;switch(t){case"script":n=await this.executeScript(e);break;case"url":n=await this.executeUrl(e);break;case"modal":n=await this.executeModal(e);break;case"flow":n=await this.executeFlow(e);break;case"api":n=await this.executeAPI(e);break;case"navigation":n=await this.executeNavigation(e);break;default:e.navigate?n=await this.executeNavigation(e):e.api||e.endpoint?n=await this.executeAPI(e):e.onClick?(await e.onClick(),n={success:!0}):n=await this.executeActionSchema(e)}return await this.handlePostExecution(e,n),n}catch(t){const s={success:!1,error:t.message};return await this.handlePostExecution(e,s),s}}async executeChain(e,t="sequential"){if(e.length===0)return{success:!0};if(t==="parallel"){const n=await Promise.allSettled(e.map(c=>this.execute(c)));if(n.filter(c=>c.status==="rejected"||c.status==="fulfilled"&&!c.value.success).length>0)return{success:!1,error:n.find(m=>m.status==="fulfilled"&&!m.value.success)?.value?.error||"One or more parallel actions failed"};const o=n[n.length-1];return o.status==="fulfilled"?o.value:{success:!1,error:"Action failed"}}let s={success:!0};for(const n of e)if(s=await this.execute(n),!s.success)return s;return s}async handlePostExecution(e,t){if(this.toastHandler){const s=e.toast??{showOnSuccess:!0,showOnError:!0},n=e.toast?.duration;if(t.success&&s.showOnSuccess!==!1){const i=e.successMessage||"Action completed successfully";this.toastHandler(i,{type:"success",duration:n})}if(!t.success&&s.showOnError!==!1&&t.error){const i=e.errorMessage||t.error;this.toastHandler(i,{type:"error",duration:n})}}if(e.refreshAfter&&t.success&&(t.reload=!0),e.chain&&e.chain.length>0&&t.success){const s=await this.executeChain(e.chain,e.chainMode||"sequential");s.success||(t.success=!1,t.error=s.error),s.data&&(t.data=s.data),s.redirect&&(t.redirect=s.redirect),s.reload&&(t.reload=!0)}if(t.success&&e.onSuccess){const s=Array.isArray(e.onSuccess)?e.onSuccess:[e.onSuccess];await this.executeChain(s,"sequential")}if(!t.success&&e.onFailure){const s=Array.isArray(e.onFailure)?e.onFailure:[e.onFailure];await this.executeChain(s,"sequential")}}async executeScript(e){const t=e.execute||e.target;if(!t)return{success:!1,error:"No script provided for script action"};try{return{success:!0,data:this.evaluator.evaluate(`\${${t}}`)}}catch(s){return{success:!1,error:`Script execution failed: ${s.message}`}}}async executeUrl(e){const t=e.target||e.redirect;if(!t)return{success:!1,error:"No URL provided for url action"};const s=this.evaluator.evaluate(t);if(!this.isValidUrl(s))return{success:!1,error:"Invalid URL scheme. Only http://, https://, and relative URLs are allowed."};const n=s.startsWith("http://")||s.startsWith("https://"),i=e.params?.newTab??n;if(this.navigationHandler)return this.navigationHandler(s,{external:n,newTab:i}),{success:!0};if(i)window.open(s,"_blank","noopener,noreferrer");else return{success:!0,redirect:s};return{success:!0}}async executeModal(e){const t=e.modal||e.target||e.params?.schema;return t?this.modalHandler?await this.modalHandler(t,this.context):{success:!0,modal:t}:{success:!1,error:"No modal schema or target provided for modal action"}}async executeFlow(e){const t=e.target||e.name;return t?this.handlers.has("flow")?await this.handlers.get("flow")(e,this.context):{success:!1,error:`Flow handler not registered. Cannot execute flow: ${t}`}:{success:!1,error:"No flow target provided for flow action"}}async executeActionSchema(e){const t={success:!0};if(e.api||e.endpoint){const s=await this.executeAPI(e);if(!s.success)return s;t.data=s.data}return e.onClick&&await e.onClick(),t.reload=e.reload!==!1,t.close=e.close!==!1,e.redirect&&(t.redirect=this.evaluator.evaluate(e.redirect)),t}async executeNavigation(e){const t=e.navigate||e,s=this.evaluator.evaluate(t.to||t.target);if(!this.isValidUrl(s))return{success:!1,error:"Invalid URL scheme. Only http://, https://, and relative URLs are allowed."};const n=t.external||typeof s=="string"&&(s.startsWith("http://")||s.startsWith("https://"));if(this.navigationHandler)return this.navigationHandler(s,{external:n,newTab:t.newTab??n,replace:t.replace}),{success:!0};if(n)window.open(s,"_blank","noopener,noreferrer");else return{success:!0,redirect:s};return{success:!0}}async executeAPI(e){const t=e.api||e.endpoint||e.target;if(!t)return{success:!1,error:"No API endpoint provided"};try{let s,n,i={"Content-Type":"application/json"},o,c="json";if(typeof t=="string")s=t,n=e.method||"POST",o=JSON.stringify(e.params||this.context.data||{});else{const y=t;if(s=y.url,n=y.method||e.method||"POST",i={...i,...y.headers},c=y.responseType||"json",y.queryParams){const _=new URLSearchParams(y.queryParams);s=`${s}${s.includes("?")?"&":"?"}${_.toString()}`}y.body?o=typeof y.body=="string"?y.body:JSON.stringify(y.body):n!=="GET"&&n!=="HEAD"&&(o=JSON.stringify(e.params||this.context.data||{}))}const m={method:n,headers:i};o&&n!=="GET"&&n!=="HEAD"&&(m.body=o);const p=await fetch(s,m);if(!p.ok)throw new Error(`HTTP ${p.status}: ${p.statusText}`);let V;switch(c){case"text":V=await p.text();break;case"blob":V=await p.blob();break;default:V=await p.json()}return{success:!0,data:V}}catch(s){return{success:!1,error:s.message}}}isValidUrl(e){return typeof e=="string"&&(e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")||e.startsWith("./"))}updateContext(e){this.context={...this.context,...e},this.evaluator.updateContext(e)}getContext(){return this.context}getEvaluator(){return this.evaluator}}var Gt={};function Ue(){try{const r=typeof globalThis<"u"&&globalThis.OBJECTUI_DEBUG;return r===!0||r==="true"||typeof process<"u"&&Gt?.OBJECTUI_DEBUG==="true"}catch{return!1}}function it(r,e,t){Ue()&&(t!==void 0?console.log(`[ObjectUI Debug][${r}] ${e}`,t):console.log(`[ObjectUI Debug][${r}] ${e}`))}const Re=new Map;function Jt(r){Ue()&&Re.set(r,performance.now())}function Kt(r){if(!Ue())return;const e=Re.get(r);if(e!==void 0){const t=(performance.now()-e).toFixed(2);console.log(`[ObjectUI Debug][perf] ${r}: ${t}ms`),Re.delete(r)}}const Ve=F.createContext(null),Mr=({children:r,dataSource:e,debug:t})=>{const s=F.useMemo(()=>({dataSource:e,debug:t}),[e,t]);return J.jsx(Ve.Provider,{value:s,children:r})},Rr=()=>{const r=F.useContext(Ve);if(!r)throw new Error("useSchemaContext must be used within a SchemaRendererProvider");return r},Nr=r=>{const t=F.useContext(Ve)?.dataSource;return!t||!r?t:r.split(".").reduce((s,n)=>s&&s[n],t)};function Qt(r){if(r!=null)return typeof r=="string"?r:r.defaultValue||r.key}function Xt(r){const e={};return r.ariaLabel&&(e["aria-label"]=Qt(r.ariaLabel)),r.ariaDescribedBy&&(e["aria-describedby"]=r.ariaDescribedBy),r.role&&(e.role=r.role),e}class Zt extends F.Component{state={hasError:!1,error:null};static getDerivedStateFromError(e){return{hasError:!0,error:e}}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){if(this.state.hasError&&this.state.error){const e=this.state.error;return J.jsxs("div",{className:"p-4 border border-orange-400 rounded bg-orange-50 text-orange-700 my-2",role:"alert",children:[J.jsxs("p",{className:"font-medium",children:["Component",this.props.componentType?` "${this.props.componentType}"`:""," failed to render"]}),J.jsx("p",{className:"text-sm mt-1",children:e.message}),!1,J.jsx("button",{onClick:this.handleRetry,className:"mt-2 text-sm underline hover:no-underline",children:"Retry"})]})}return this.props.children}}const er=F.forwardRef(({schema:r,...e},t)=>{const n=F.useContext(Ve)?.dataSource||{},i=F.useMemo(()=>{if(!r||typeof r=="string")return r;const A=new be({data:n}),C={...r};if(C.properties&&Object.assign(C,C.properties),typeof C.content=="string"&&(C.content=A.evaluate(C.content)),C.props){const j={...C.props};for(const[Z,ee]of Object.entries(j))j[Z]=A.evaluate(ee);C.props=j}return C},[r,n]);if(!i)return null;if(typeof i=="string")return J.jsx(J.Fragment,{children:i});it("schema","Rendering schema node",{type:i.type,id:i.id});const o=Wt.get(i.type);if(!o)return it("schema","Component not found in registry",{type:i.type}),J.jsxs("div",{className:"p-4 border border-red-500 rounded text-red-500 bg-red-50 my-2",role:"alert",children:[J.jsxs("p",{className:"font-medium",children:["Unknown component type: ",J.jsx("strong",{children:i.type})]}),!1,J.jsx("pre",{className:"text-xs mt-2 overflow-auto",children:JSON.stringify(i,null,2)})]});const{type:c,children:m,body:p,schema:V,visible:y,visibleOn:_,hidden:v,hiddenOn:R,disabled:E,disabledOn:S,...D}=i,w=Xt(i);Jt(`render:${i.type}:${i.id??"anon"}`);const N=J.jsx(Zt,{componentType:i.type,children:x.createElement(o,{schema:i,...D,...i.props||{},...w,className:i.className,"data-obj-id":i.id,"data-obj-type":i.type,...e})});return Kt(`render:${i.type}:${i.id??"anon"}`),N});er.displayName="SchemaRenderer";function $r(r,e={}){return F.useMemo(()=>new be(e).evaluateCondition(r),[r,e])}function Ir(r={}){const e="context"in r?r:{context:r},{context:t={},onConfirm:s,onToast:n,onModal:i,onNavigate:o}=e,[c,m]=F.useState(!1),[p,V]=F.useState(null),[y,_]=F.useState(null),v=F.useMemo(()=>{const S=new xt(t);return s&&S.setConfirmHandler(s),n&&S.setToastHandler(n),i&&S.setModalHandler(i),o&&S.setNavigationHandler(o),S},[JSON.stringify(t)]),R=F.useCallback(async S=>{m(!0),V(null),_(null);try{const D=await v.execute(S);return _(D),D.success||V(D.error||"Action failed"),D}catch(D){const w=D.message;V(w);const N={success:!1,error:w};return _(N),N}finally{m(!1)}},[v]),E=F.useCallback(S=>{v.updateContext(S)},[v]);return{execute:R,loading:c,error:p,result:y,updateContext:E,runner:v}}function Ur(r){const{navigation:e,objectName:t,onNavigate:s,onRowClick:n}=r,[i,o]=F.useState(!1),[c,m]=F.useState(null),p=e?.mode??"page",V=e?.width,y=p==="drawer"||p==="modal"||p==="split"||p==="popover",_=F.useCallback(()=>{o(!1),m(null)},[]),v=F.useCallback(E=>{m(E),o(!0)},[]),R=F.useCallback(E=>{if(n){n(E);return}if(!e){const S=E._id||E.id;s&&S!=null&&s(S,"view");return}if(!(p==="none"||e.preventNavigation)){if(p==="new_window"||e.openNewTab){const S=E._id||E.id,D=t?`/${t}/${S}`:`/${S}`;window.open(D,"_blank");return}if(p==="page"){const S=E._id||E.id;s&&S!=null&&s(S,"view");return}if(y){m(E),o(!0);return}}},[n,e,p,t,s,y]);return F.useMemo(()=>({isOpen:i,selectedRecord:c,mode:p,close:_,open:v,setIsOpen:o,handleClick:R,width:V,isOverlay:y}),[i,c,p,_,v,R,V,y])}const tr=F.createContext(null);function at(r){if(!r||r.length===0)return{};const e={};for(const t of r)if(t.defaultValue!==void 0)e[t.name]=t.defaultValue;else switch(t.type){case"number":e[t.name]=0;break;case"boolean":e[t.name]=!1;break;case"object":e[t.name]={};break;case"array":e[t.name]=[];break;case"string":default:e[t.name]="";break}return e}const rr=({definitions:r,children:e})=>{const[t,s]=F.useState(()=>at(r)),n=F.useCallback((m,p)=>{s(V=>({...V,[m]:p}))},[]),i=F.useCallback(m=>{s(p=>({...p,...m}))},[]),o=F.useCallback(()=>{s(at(r))},[r]),c=F.useMemo(()=>({variables:t,setVariable:n,setVariables:i,resetVariables:o}),[t,n,i,o]);return J.jsx(tr.Provider,{value:c,children:e})};rr.displayName="PageVariablesProvider";F.createContext(null);function sr(r){return typeof window>"u"?()=>{}:(window.addEventListener("online",r),window.addEventListener("offline",r),()=>{window.removeEventListener("online",r),window.removeEventListener("offline",r)})}function nr(){return typeof navigator<"u"?navigator.onLine:!0}function ir(){return!0}const St="objectui-offline-queue";function ar(){if(typeof localStorage>"u")return[];try{const r=localStorage.getItem(St);return r?JSON.parse(r):[]}catch{return[]}}function or(r){if(!(typeof localStorage>"u"))try{localStorage.setItem(St,JSON.stringify(r))}catch{}}let ot=0;function ur(){return ot+=1,`mut_${Date.now()}_${ot}`}const ye={enabled:!0,strategy:"network_first",offlineIndicator:!0,offlineMessage:"You are currently offline. Changes will be synced when reconnected.",queueMaxSize:100};function Pr(r={}){const{enabled:e=ye.enabled,strategy:t=ye.strategy,offlineIndicator:s=ye.offlineIndicator,offlineMessage:n=ye.offlineMessage,queueMaxSize:i=ye.queueMaxSize,sync:o}=r,c=F.useSyncExternalStore(sr,nr,ir),[m,p]=F.useState(ar),[V,y]=F.useState("idle"),_=F.useRef(o);_.current=o,F.useEffect(()=>{or(m)},[m]),F.useEffect(()=>{e&&(c?V==="offline"&&y("idle"):y("offline"))},[c,e,V]);const v=F.useCallback(S=>{e&&p(D=>{const w={...S,id:ur(),timestamp:Date.now()},N=[...D,w];return N.length>i?N.slice(N.length-i):N})},[e,i]),R=F.useCallback(()=>{p([])},[]),E=F.useCallback(async()=>{if(!(!e||m.length===0)){y("syncing");try{const S=_.current?.batchSize??m.length,D=m.slice(0,S);await new Promise(w=>setTimeout(w,0)),p(w=>w.filter(N=>!D.some(A=>A.id===N.id))),y("idle")}catch{y("error")}}},[e,m]);return F.useEffect(()=>{if(!e||!c||m.length===0)return;const S=setTimeout(()=>{E()},100);return()=>clearTimeout(S)},[c,e]),F.useMemo(()=>({isOnline:c,enabled:e,syncState:V,strategy:t,pendingCount:m.length,queueMutation:v,sync:E,clearQueue:R,showIndicator:s&&!c,offlineMessage:n}),[c,e,V,t,m.length,v,E,R,s,n])}const lr=F.createContext(null);function Lr(){const r=F.useContext(lr);if(!r){const e=new xt;return{execute:t=>e.execute(t),executeChain:(t,s)=>e.executeChain(t,s),loading:!1,error:null,result:null,runner:e,updateContext:t=>e.updateContext(t)}}return r}F.createContext(null);const _t=F.createContext(null);function Hr(){const r=F.useContext(_t);if(!r)throw new Error("useDnd must be used within a <DndProvider>. Wrap your app with <DndProvider> to use the drag and drop system.");return r}function jr(){return F.useContext(_t)!==null}var we=r=>r.type==="checkbox",le=r=>r instanceof Date,Y=r=>r==null;const Ct=r=>typeof r=="object";var L=r=>!Y(r)&&!Array.isArray(r)&&Ct(r)&&!le(r),Ft=r=>L(r)&&r.target?we(r.target)?r.target.checked:r.target.value:r,cr=r=>r.substring(0,r.search(/\.\d+(\.|$)/))||r,Vt=(r,e)=>r.has(cr(e)),dr=r=>{const e=r.constructor&&r.constructor.prototype;return L(e)&&e.hasOwnProperty("isPrototypeOf")},Pe=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function U(r){if(r instanceof Date)return new Date(r);const e=typeof FileList<"u"&&r instanceof FileList;if(Pe&&(r instanceof Blob||e))return r;const t=Array.isArray(r);if(!t&&!(L(r)&&dr(r)))return r;const s=t?[]:Object.create(Object.getPrototypeOf(r));for(const n in r)Object.prototype.hasOwnProperty.call(r,n)&&(s[n]=U(r[n]));return s}var Ae=r=>/^\w*$/.test(r),I=r=>r===void 0,Le=r=>Array.isArray(r)?r.filter(Boolean):[],He=r=>Le(r.replace(/["|']|\]/g,"").split(/\.|\[/)),h=(r,e,t)=>{if(!e||!L(r))return t;const s=(Ae(e)?[e]:He(e)).reduce((n,i)=>Y(n)?n:n[i],r);return I(s)||s===r?I(r[e])?t:r[e]:s},K=r=>typeof r=="boolean",z=r=>typeof r=="function",$=(r,e,t)=>{let s=-1;const n=Ae(e)?[e]:He(e),i=n.length,o=i-1;for(;++s<i;){const c=n[s];let m=t;if(s!==o){const p=r[c];m=L(p)||Array.isArray(p)?p:isNaN(+n[s+1])?{}:[]}if(c==="__proto__"||c==="constructor"||c==="prototype")return;r[c]=m,r=r[c]}};const _e={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},re={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},ie={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},je=x.createContext(null);je.displayName="HookFormControlContext";const Be=()=>x.useContext(je);var At=(r,e,t,s=!0)=>{const n={defaultValues:e._defaultValues};for(const i in r)Object.defineProperty(n,i,{get:()=>{const o=i;return e._proxyFormState[o]!==re.all&&(e._proxyFormState[o]=!s||re.all),t&&(t[o]=!0),r[o]}});return n};const qe=typeof window<"u"?x.useLayoutEffect:x.useEffect;function fr(r){const e=Be(),{control:t=e,disabled:s,name:n,exact:i}=r||{},[o,c]=x.useState(t._formState),m=x.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return qe(()=>t._subscribe({name:n,formState:m.current,exact:i,callback:p=>{!s&&c({...t._formState,...p})}}),[n,s,i]),x.useEffect(()=>{m.current.isValid&&t._setValid(!0)},[t]),x.useMemo(()=>At(o,t,m.current,!1),[o,t])}var Q=r=>typeof r=="string",Ne=(r,e,t,s,n)=>Q(r)?(s&&e.watch.add(r),h(t,r,n)):Array.isArray(r)?r.map(i=>(s&&e.watch.add(i),h(t,i))):(s&&(e.watchAll=!0),t),$e=r=>Y(r)||!Ct(r);function se(r,e,t=new WeakSet){if($e(r)||$e(e))return Object.is(r,e);if(le(r)&&le(e))return Object.is(r.getTime(),e.getTime());const s=Object.keys(r),n=Object.keys(e);if(s.length!==n.length)return!1;if(t.has(r)||t.has(e))return!0;t.add(r),t.add(e);for(const i of s){const o=r[i];if(!n.includes(i))return!1;if(i!=="ref"){const c=e[i];if(le(o)&&le(c)||L(o)&&L(c)||Array.isArray(o)&&Array.isArray(c)?!se(o,c,t):!Object.is(o,c))return!1}}return!0}function hr(r){const e=Be(),{control:t=e,name:s,defaultValue:n,disabled:i,exact:o,compute:c}=r||{},m=x.useRef(n),p=x.useRef(c),V=x.useRef(void 0),y=x.useRef(t),_=x.useRef(s);p.current=c;const[v,R]=x.useState(()=>{const A=t._getWatch(s,m.current);return p.current?p.current(A):A}),E=x.useCallback(A=>{const C=Ne(s,t._names,A||t._formValues,!1,m.current);return p.current?p.current(C):C},[t._formValues,t._names,s]),S=x.useCallback(A=>{if(!i){const C=Ne(s,t._names,A||t._formValues,!1,m.current);if(p.current){const j=p.current(C);se(j,V.current)||(R(j),V.current=j)}else R(C)}},[t._formValues,t._names,i,s]);qe(()=>((y.current!==t||!se(_.current,s))&&(y.current=t,_.current=s,S()),t._subscribe({name:s,formState:{values:!0},exact:o,callback:A=>{S(A.values)}})),[t,o,s,S]),x.useEffect(()=>t._removeUnmounted());const D=y.current!==t,w=_.current,N=x.useMemo(()=>{if(i)return null;const A=!D&&!se(w,s);return D||A?E():null},[i,D,s,w,E]);return N!==null?N:v}function gr(r){const e=Be(),{name:t,disabled:s,control:n=e,shouldUnregister:i,defaultValue:o,exact:c=!0}=r,m=Vt(n._names.array,t),p=x.useMemo(()=>h(n._formValues,t,h(n._defaultValues,t,o)),[n,t,o]),V=hr({control:n,name:t,defaultValue:p,exact:c}),y=fr({control:n,name:t,exact:c}),_=x.useRef(r),v=x.useRef(void 0),R=x.useRef(n.register(t,{...r.rules,value:V,...K(r.disabled)?{disabled:r.disabled}:{}}));_.current=r;const E=x.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!h(y.errors,t)},isDirty:{enumerable:!0,get:()=>!!h(y.dirtyFields,t)},isTouched:{enumerable:!0,get:()=>!!h(y.touchedFields,t)},isValidating:{enumerable:!0,get:()=>!!h(y.validatingFields,t)},error:{enumerable:!0,get:()=>h(y.errors,t)}}),[y,t]),S=x.useCallback(A=>R.current.onChange({target:{value:Ft(A),name:t},type:_e.CHANGE}),[t]),D=x.useCallback(()=>R.current.onBlur({target:{value:h(n._formValues,t),name:t},type:_e.BLUR}),[t,n._formValues]),w=x.useCallback(A=>{const C=h(n._fields,t);C&&C._f&&A&&(C._f.ref={focus:()=>z(A.focus)&&A.focus(),select:()=>z(A.select)&&A.select(),setCustomValidity:j=>z(A.setCustomValidity)&&A.setCustomValidity(j),reportValidity:()=>z(A.reportValidity)&&A.reportValidity()})},[n._fields,t]),N=x.useMemo(()=>({name:t,value:V,...K(s)||y.disabled?{disabled:y.disabled||s}:{},onChange:S,onBlur:D,ref:w}),[t,s,y.disabled,S,D,w,V]);return x.useEffect(()=>{const A=n._options.shouldUnregister||i,C=v.current;C&&C!==t&&!m&&n.unregister(C),n.register(t,{..._.current.rules,...K(_.current.disabled)?{disabled:_.current.disabled}:{}});const j=(Z,ee)=>{const ne=h(n._fields,Z);ne&&ne._f&&(ne._f.mount=ee)};if(j(t,!0),A){const Z=U(h(n._options.defaultValues,t,_.current.defaultValue));$(n._defaultValues,t,Z),I(h(n._formValues,t))&&$(n._formValues,t,Z)}return!m&&n.register(t),v.current=t,()=>{(m?A&&!n._state.action:A)?n.unregister(t):j(t,!1)}},[t,n,m,i]),x.useEffect(()=>{n._setDisabledField({disabled:s,name:t})},[s,t,n]),x.useMemo(()=>({field:N,formState:y,fieldState:E}),[N,y,E])}const Br=r=>r.render(gr(r)),We=x.createContext(null);We.displayName="HookFormContext";const qr=()=>x.useContext(We),Wr=r=>{const{children:e,watch:t,getValues:s,getFieldState:n,setError:i,clearErrors:o,setValue:c,trigger:m,formState:p,resetField:V,reset:y,handleSubmit:_,unregister:v,control:R,register:E,setFocus:S,subscribe:D}=r;return x.createElement(We.Provider,{value:x.useMemo(()=>({watch:t,getValues:s,getFieldState:n,setError:i,clearErrors:o,setValue:c,trigger:m,formState:p,resetField:V,reset:y,handleSubmit:_,unregister:v,control:R,register:E,setFocus:S,subscribe:D}),[o,R,p,n,s,_,E,y,V,i,S,c,D,m,v,t])},x.createElement(je.Provider,{value:R},e))};var yr=(r,e,t,s,n)=>e?{...t[r],types:{...t[r]&&t[r].types?t[r].types:{},[s]:n||!0}}:{},pe=r=>Array.isArray(r)?r:[r],ut=()=>{let r=[];return{get observers(){return r},next:n=>{for(const i of r)i.next&&i.next(n)},subscribe:n=>(r.push(n),{unsubscribe:()=>{r=r.filter(i=>i!==n)}}),unsubscribe:()=>{r=[]}}};function Et(r,e){const t={};for(const s in r)if(r.hasOwnProperty(s)){const n=r[s],i=e[s];if(n&&L(n)&&i){const o=Et(n,i);L(o)&&(t[s]=o)}else r[s]&&(t[s]=i)}return t}var W=r=>L(r)&&!Object.keys(r).length,ze=r=>r.type==="file",Ce=r=>{if(!Pe)return!1;const e=r?r.ownerDocument:0;return r instanceof(e&&e.defaultView?e.defaultView.HTMLElement:HTMLElement)},Dt=r=>r.type==="select-multiple",Ye=r=>r.type==="radio",mr=r=>Ye(r)||we(r),Me=r=>Ce(r)&&r.isConnected;function pr(r,e){const t=e.slice(0,-1).length;let s=0;for(;s<t;)r=I(r)?s++:r[e[s++]];return r}function vr(r){for(const e in r)if(r.hasOwnProperty(e)&&!I(r[e]))return!1;return!0}function P(r,e){const t=Array.isArray(e)?e:Ae(e)?[e]:He(e),s=t.length===1?r:pr(r,t),n=t.length-1,i=t[n];return s&&delete s[i],n!==0&&(L(s)&&W(s)||Array.isArray(s)&&vr(s))&&P(r,t.slice(0,-1)),r}var br=r=>{for(const e in r)if(z(r[e]))return!0;return!1};function kt(r){return Array.isArray(r)||L(r)&&!br(r)}function Ie(r,e={}){for(const t in r){const s=r[t];kt(s)?(e[t]=Array.isArray(s)?[]:{},Ie(s,e[t])):I(s)||(e[t]=!0)}return e}function de(r,e,t){t||(t=Ie(e));for(const s in r){const n=r[s];if(kt(n))I(e)||$e(t[s])?t[s]=Ie(n,Array.isArray(n)?[]:{}):de(n,Y(e)?{}:e[s],t[s]);else{const i=e[s];t[s]=!se(n,i)}}return t}const lt={value:!1,isValid:!1},ct={value:!0,isValid:!0};var Tt=r=>{if(Array.isArray(r)){if(r.length>1){const e=r.filter(t=>t&&t.checked&&!t.disabled).map(t=>t.value);return{value:e,isValid:!!e.length}}return r[0].checked&&!r[0].disabled?r[0].attributes&&!I(r[0].attributes.value)?I(r[0].value)||r[0].value===""?ct:{value:r[0].value,isValid:!0}:ct:lt}return lt},Ot=(r,{valueAsNumber:e,valueAsDate:t,setValueAs:s})=>I(r)?r:e?r===""?NaN:r&&+r:t&&Q(r)?new Date(r):s?s(r):r;const dt={isValid:!1,value:null};var Mt=r=>Array.isArray(r)?r.reduce((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e,dt):dt;function ft(r){const e=r.ref;return ze(e)?e.files:Ye(e)?Mt(r.refs).value:Dt(e)?[...e.selectedOptions].map(({value:t})=>t):we(e)?Tt(r.refs).value:Ot(I(e.value)?r.ref.value:e.value,r)}var wr=(r,e,t,s)=>{const n={};for(const i of r){const o=h(e,i);o&&$(n,i,o._f)}return{criteriaMode:t,names:[...r],fields:n,shouldUseNativeValidation:s}},Fe=r=>r instanceof RegExp,me=r=>I(r)?r:Fe(r)?r.source:L(r)?Fe(r.value)?r.value.source:r.value:r,ht=r=>({isOnSubmit:!r||r===re.onSubmit,isOnBlur:r===re.onBlur,isOnChange:r===re.onChange,isOnAll:r===re.all,isOnTouch:r===re.onTouched});const gt="AsyncFunction";var xr=r=>!!r&&!!r.validate&&!!(z(r.validate)&&r.validate.constructor.name===gt||L(r.validate)&&Object.values(r.validate).find(e=>e.constructor.name===gt)),Sr=r=>r.mount&&(r.required||r.min||r.max||r.maxLength||r.minLength||r.pattern||r.validate),yt=(r,e,t)=>!t&&(e.watchAll||e.watch.has(r)||[...e.watch].some(s=>r.startsWith(s)&&/^\.\w+/.test(r.slice(s.length))));const ve=(r,e,t,s)=>{for(const n of t||Object.keys(r)){const i=h(r,n);if(i){const{_f:o,...c}=i;if(o){if(o.refs&&o.refs[0]&&e(o.refs[0],n)&&!s)return!0;if(o.ref&&e(o.ref,o.name)&&!s)return!0;if(ve(c,e))break}else if(L(c)&&ve(c,e))break}}};function mt(r,e,t){const s=h(r,t);if(s||Ae(t))return{error:s,name:t};const n=t.split(".");for(;n.length;){const i=n.join("."),o=h(e,i),c=h(r,i);if(o&&!Array.isArray(o)&&t!==i)return{name:t};if(c&&c.type)return{name:i,error:c};if(c&&c.root&&c.root.type)return{name:`${i}.root`,error:c.root};n.pop()}return{name:t}}var _r=(r,e,t,s)=>{t(r);const{name:n,...i}=r;return W(i)||Object.keys(i).length>=Object.keys(e).length||Object.keys(i).find(o=>e[o]===(!s||re.all))},Cr=(r,e,t)=>!r||!e||r===e||pe(r).some(s=>s&&(t?s===e:s.startsWith(e)||e.startsWith(s))),Fr=(r,e,t,s,n)=>n.isOnAll?!1:!t&&n.isOnTouch?!(e||r):(t?s.isOnBlur:n.isOnBlur)?!r:(t?s.isOnChange:n.isOnChange)?r:!0,Vr=(r,e)=>!Le(h(r,e)).length&&P(r,e),Ar=(r,e,t)=>{const s=pe(h(r,t));return $(s,"root",e[t]),$(r,t,s),r};function pt(r,e,t="validate"){if(Q(r)||Array.isArray(r)&&r.every(Q)||K(r)&&!r)return{type:t,message:Q(r)?r:"",ref:e}}var ce=r=>L(r)&&!Fe(r)?r:{value:r,message:""},vt=async(r,e,t,s,n,i)=>{const{ref:o,refs:c,required:m,maxLength:p,minLength:V,min:y,max:_,pattern:v,validate:R,name:E,valueAsNumber:S,mount:D}=r._f,w=h(t,E);if(!D||e.has(E))return{};const N=c?c[0]:o,A=k=>{n&&N.reportValidity&&(N.setCustomValidity(K(k)?"":k||""),N.reportValidity())},C={},j=Ye(o),Z=we(o),ee=j||Z,ne=(S||ze(o))&&I(o.value)&&I(w)||Ce(o)&&o.value===""||w===""||Array.isArray(w)&&!w.length,X=yr.bind(null,E,s,C),xe=(k,T,H,B=ie.maxLength,te=ie.minLength)=>{const G=k?T:H;C[E]={type:k?B:te,message:G,ref:o,...X(k?B:te,G)}};if(i?!Array.isArray(w)||!w.length:m&&(!ee&&(ne||Y(w))||K(w)&&!w||Z&&!Tt(c).isValid||j&&!Mt(c).isValid)){const{value:k,message:T}=Q(m)?{value:!!m,message:m}:ce(m);if(k&&(C[E]={type:ie.required,message:T,ref:N,...X(ie.required,T)},!s))return A(T),C}if(!ne&&(!Y(y)||!Y(_))){let k,T;const H=ce(_),B=ce(y);if(!Y(w)&&!isNaN(w)){const te=o.valueAsNumber||w&&+w;Y(H.value)||(k=te>H.value),Y(B.value)||(T=te<B.value)}else{const te=o.valueAsDate||new Date(w),G=ge=>new Date(new Date().toDateString()+" "+ge),fe=o.type=="time",he=o.type=="week";Q(H.value)&&w&&(k=fe?G(w)>G(H.value):he?w>H.value:te>new Date(H.value)),Q(B.value)&&w&&(T=fe?G(w)<G(B.value):he?w<B.value:te<new Date(B.value))}if((k||T)&&(xe(!!k,H.message,B.message,ie.max,ie.min),!s))return A(C[E].message),C}if((p||V)&&!ne&&(Q(w)||i&&Array.isArray(w))){const k=ce(p),T=ce(V),H=!Y(k.value)&&w.length>+k.value,B=!Y(T.value)&&w.length<+T.value;if((H||B)&&(xe(H,k.message,T.message),!s))return A(C[E].message),C}if(v&&!ne&&Q(w)){const{value:k,message:T}=ce(v);if(Fe(k)&&!w.match(k)&&(C[E]={type:ie.pattern,message:T,ref:o,...X(ie.pattern,T)},!s))return A(T),C}if(R){if(z(R)){const k=await R(w,t),T=pt(k,N);if(T&&(C[E]={...T,...X(ie.validate,T.message)},!s))return A(T.message),C}else if(L(R)){let k={};for(const T in R){if(!W(k)&&!s)break;const H=pt(await R[T](w,t),N,T);H&&(k={...H,...X(T,H.message)},A(H.message),s&&(C[E]=k))}if(!W(k)&&(C[E]={ref:N,...k},!s))return C}}return A(!0),C};const Er={mode:re.onSubmit,reValidateMode:re.onChange,shouldFocusError:!0};function Dr(r={}){let e={...Er,...r},t={submitCount:0,isDirty:!1,isReady:!1,isLoading:z(e.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1},s={},n=L(e.defaultValues)||L(e.values)?U(e.defaultValues||e.values)||{}:{},i=e.shouldUnregister?{}:U(n),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},c={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},m,p=0;const V={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},y={...V};let _={...y};const v={array:ut(),state:ut()},R=e.criteriaMode===re.all,E=a=>u=>{clearTimeout(p),p=setTimeout(a,u)},S=async a=>{if(!o.keepIsValid&&!e.disabled&&(y.isValid||_.isValid||a)){let u;e.resolver?(u=W((await ee()).errors),D()):u=await X(s,!0),u!==t.isValid&&v.state.next({isValid:u})}},D=(a,u)=>{!e.disabled&&(y.isValidating||y.validatingFields||_.isValidating||_.validatingFields)&&((a||Array.from(c.mount)).forEach(l=>{l&&(u?$(t.validatingFields,l,u):P(t.validatingFields,l))}),v.state.next({validatingFields:t.validatingFields,isValidating:!W(t.validatingFields)}))},w=(a,u=[],l,g,f=!0,d=!0)=>{if(g&&l&&!e.disabled){if(o.action=!0,d&&Array.isArray(h(s,a))){const b=l(h(s,a),g.argA,g.argB);f&&$(s,a,b)}if(d&&Array.isArray(h(t.errors,a))){const b=l(h(t.errors,a),g.argA,g.argB);f&&$(t.errors,a,b),Vr(t.errors,a)}if((y.touchedFields||_.touchedFields)&&d&&Array.isArray(h(t.touchedFields,a))){const b=l(h(t.touchedFields,a),g.argA,g.argB);f&&$(t.touchedFields,a,b)}(y.dirtyFields||_.dirtyFields)&&(t.dirtyFields=de(n,i)),v.state.next({name:a,isDirty:k(a,u),dirtyFields:t.dirtyFields,errors:t.errors,isValid:t.isValid})}else $(i,a,u)},N=(a,u)=>{$(t.errors,a,u),v.state.next({errors:t.errors})},A=a=>{t.errors=a,v.state.next({errors:t.errors,isValid:!1})},C=(a,u,l,g)=>{const f=h(s,a);if(f){const d=h(i,a,I(l)?h(n,a):l);I(d)||g&&g.defaultChecked||u?$(i,a,u?d:ft(f._f)):B(a,d),o.mount&&!o.action&&S()}},j=(a,u,l,g,f)=>{let d=!1,b=!1;const O={name:a};if(!e.disabled){if(!l||g){(y.isDirty||_.isDirty)&&(b=t.isDirty,t.isDirty=O.isDirty=k(),d=b!==O.isDirty);const M=se(h(n,a),u);b=!!h(t.dirtyFields,a),M?P(t.dirtyFields,a):$(t.dirtyFields,a,!0),O.dirtyFields=t.dirtyFields,d=d||(y.dirtyFields||_.dirtyFields)&&b!==!M}if(l){const M=h(t.touchedFields,a);M||($(t.touchedFields,a,l),O.touchedFields=t.touchedFields,d=d||(y.touchedFields||_.touchedFields)&&M!==l)}d&&f&&v.state.next(O)}return d?O:{}},Z=(a,u,l,g)=>{const f=h(t.errors,a),d=(y.isValid||_.isValid)&&K(u)&&t.isValid!==u;if(e.delayError&&l?(m=E(()=>N(a,l)),m(e.delayError)):(clearTimeout(p),m=null,l?$(t.errors,a,l):P(t.errors,a)),(l?!se(f,l):f)||!W(g)||d){const b={...g,...d&&K(u)?{isValid:u}:{},errors:t.errors,name:a};t={...t,...b},v.state.next(b)}},ee=async a=>(D(a,!0),await e.resolver(i,e.context,wr(a||c.mount,s,e.criteriaMode,e.shouldUseNativeValidation))),ne=async a=>{const{errors:u}=await ee(a);if(D(a),a)for(const l of a){const g=h(u,l);g?$(t.errors,l,g):P(t.errors,l)}else t.errors=u;return u},X=async(a,u,l={valid:!0})=>{for(const g in a){const f=a[g];if(f){const{_f:d,...b}=f;if(d){const O=c.array.has(d.name),M=f._f&&xr(f._f);M&&y.validatingFields&&D([d.name],!0);const q=await vt(f,c.disabled,i,R,e.shouldUseNativeValidation&&!u,O);if(M&&y.validatingFields&&D([d.name]),q[d.name]&&(l.valid=!1,u||r.shouldUseNativeValidation))break;!u&&(h(q,d.name)?O?Ar(t.errors,q,d.name):$(t.errors,d.name,q[d.name]):P(t.errors,d.name))}!W(b)&&await X(b,u,l)}}return l.valid},xe=()=>{for(const a of c.unMount){const u=h(s,a);u&&(u._f.refs?u._f.refs.every(l=>!Me(l)):!Me(u._f.ref))&&Ee(a)}c.unMount=new Set},k=(a,u)=>!e.disabled&&(a&&u&&$(i,a,u),!se(Ge(),n)),T=(a,u,l)=>Ne(a,c,{...o.mount?i:I(u)?n:Q(a)?{[a]:u}:u},l,u),H=a=>Le(h(o.mount?i:n,a,e.shouldUnregister?h(n,a,[]):[])),B=(a,u,l={})=>{const g=h(s,a);let f=u;if(g){const d=g._f;d&&(!d.disabled&&$(i,a,Ot(u,d)),f=Ce(d.ref)&&Y(u)?"":u,Dt(d.ref)?[...d.ref.options].forEach(b=>b.selected=f.includes(b.value)):d.refs?we(d.ref)?d.refs.forEach(b=>{(!b.defaultChecked||!b.disabled)&&(Array.isArray(f)?b.checked=!!f.find(O=>O===b.value):b.checked=f===b.value||!!f)}):d.refs.forEach(b=>b.checked=b.value===f):ze(d.ref)?d.ref.value="":(d.ref.value=f,d.ref.type||v.state.next({name:a,values:U(i)})))}(l.shouldDirty||l.shouldTouch)&&j(a,f,l.shouldTouch,l.shouldDirty,!0),l.shouldValidate&&ge(a)},te=(a,u,l)=>{for(const g in u){if(!u.hasOwnProperty(g))return;const f=u[g],d=a+"."+g,b=h(s,d);(c.array.has(a)||L(f)||b&&!b._f)&&!le(f)?te(d,f,l):B(d,f,l)}},G=(a,u,l={})=>{const g=h(s,a),f=c.array.has(a),d=U(u);$(i,a,d),f?(v.array.next({name:a,values:U(i)}),(y.isDirty||y.dirtyFields||_.isDirty||_.dirtyFields)&&l.shouldDirty&&v.state.next({name:a,dirtyFields:de(n,i),isDirty:k(a,d)})):g&&!g._f&&!Y(d)?te(a,d,l):B(a,d,l),yt(a,c)?v.state.next({...t,name:a,values:U(i)}):v.state.next({name:o.mount?a:void 0,values:U(i)})},fe=async a=>{o.mount=!0;const u=a.target;let l=u.name,g=!0;const f=h(s,l),d=M=>{g=Number.isNaN(M)||le(M)&&isNaN(M.getTime())||se(M,h(i,l,M))},b=ht(e.mode),O=ht(e.reValidateMode);if(f){let M,q;const ue=u.type?ft(f._f):Ft(a),oe=a.type===_e.BLUR||a.type===_e.FOCUS_OUT,Ht=!Sr(f._f)&&!e.resolver&&!h(t.errors,l)&&!f._f.deps||Fr(oe,h(t.touchedFields,l),t.isSubmitted,O,b),Te=yt(l,c,oe);$(i,l,ue),oe?(!u||!u.readOnly)&&(f._f.onBlur&&f._f.onBlur(a),m&&m(0)):f._f.onChange&&f._f.onChange(a);const Oe=j(l,ue,oe),jt=!W(Oe)||Te;if(!oe&&v.state.next({name:l,type:a.type,values:U(i)}),Ht)return(y.isValid||_.isValid)&&(e.mode==="onBlur"?oe&&S():oe||S()),jt&&v.state.next({name:l,...Te?{}:Oe});if(!oe&&Te&&v.state.next({...t}),e.resolver){const{errors:st}=await ee([l]);if(D([l]),d(ue),g){const Bt=mt(t.errors,s,l),nt=mt(st,s,Bt.name||l);M=nt.error,l=nt.name,q=W(st)}}else D([l],!0),M=(await vt(f,c.disabled,i,R,e.shouldUseNativeValidation))[l],D([l]),d(ue),g&&(M?q=!1:(y.isValid||_.isValid)&&(q=await X(s,!0)));g&&(f._f.deps&&(!Array.isArray(f._f.deps)||f._f.deps.length>0)&&ge(f._f.deps),Z(l,q,M,Oe))}},he=(a,u)=>{if(h(t.errors,u)&&a.focus)return a.focus(),1},ge=async(a,u={})=>{let l,g;const f=pe(a);if(e.resolver){const d=await ne(I(a)?a:f);l=W(d),g=a?!f.some(b=>h(d,b)):l}else a?(g=(await Promise.all(f.map(async d=>{const b=h(s,d);return await X(b&&b._f?{[d]:b}:b)}))).every(Boolean),!(!g&&!t.isValid)&&S()):g=l=await X(s);return v.state.next({...!Q(a)||(y.isValid||_.isValid)&&l!==t.isValid?{}:{name:a},...e.resolver||!a?{isValid:l}:{},errors:t.errors}),u.shouldFocus&&!g&&ve(s,he,a?f:c.mount),g},Ge=(a,u)=>{let l={...o.mount?i:n};return u&&(l=Et(u.dirtyFields?t.dirtyFields:t.touchedFields,l)),I(a)?l:Q(a)?h(l,a):a.map(g=>h(l,g))},Je=(a,u)=>({invalid:!!h((u||t).errors,a),isDirty:!!h((u||t).dirtyFields,a),error:h((u||t).errors,a),isValidating:!!h(t.validatingFields,a),isTouched:!!h((u||t).touchedFields,a)}),Rt=a=>{a&&pe(a).forEach(u=>P(t.errors,u)),v.state.next({errors:a?t.errors:{}})},Ke=(a,u,l)=>{const g=(h(s,a,{_f:{}})._f||{}).ref,f=h(t.errors,a)||{},{ref:d,message:b,type:O,...M}=f;$(t.errors,a,{...M,...u,ref:g}),v.state.next({name:a,errors:t.errors,isValid:!1}),l&&l.shouldFocus&&g&&g.focus&&g.focus()},Nt=(a,u)=>z(a)?v.state.subscribe({next:l=>"values"in l&&a(T(void 0,u),l)}):T(a,u,!0),Qe=a=>v.state.subscribe({next:u=>{Cr(a.name,u.name,a.exact)&&_r(u,a.formState||y,Lt,a.reRenderRoot)&&a.callback({values:{...i},...t,...u,defaultValues:n})}}).unsubscribe,$t=a=>(o.mount=!0,_={..._,...a.formState},Qe({...a,formState:{...V,...a.formState}})),Ee=(a,u={})=>{for(const l of a?pe(a):c.mount)c.mount.delete(l),c.array.delete(l),u.keepValue||(P(s,l),P(i,l)),!u.keepError&&P(t.errors,l),!u.keepDirty&&P(t.dirtyFields,l),!u.keepTouched&&P(t.touchedFields,l),!u.keepIsValidating&&P(t.validatingFields,l),!e.shouldUnregister&&!u.keepDefaultValue&&P(n,l);v.state.next({values:U(i)}),v.state.next({...t,...u.keepDirty?{isDirty:k()}:{}}),!u.keepIsValid&&S()},Xe=({disabled:a,name:u})=>{if(K(a)&&o.mount||a||c.disabled.has(u)){const f=c.disabled.has(u)!==!!a;a?c.disabled.add(u):c.disabled.delete(u),f&&o.mount&&!o.action&&S()}},De=(a,u={})=>{let l=h(s,a);const g=K(u.disabled)||K(e.disabled);return $(s,a,{...l||{},_f:{...l&&l._f?l._f:{ref:{name:a}},name:a,mount:!0,...u}}),c.mount.add(a),l?Xe({disabled:K(u.disabled)?u.disabled:e.disabled,name:a}):C(a,!0,u.value),{...g?{disabled:u.disabled||e.disabled}:{},...e.progressive?{required:!!u.required,min:me(u.min),max:me(u.max),minLength:me(u.minLength),maxLength:me(u.maxLength),pattern:me(u.pattern)}:{},name:a,onChange:fe,onBlur:fe,ref:f=>{if(f){De(a,u),l=h(s,a);const d=I(f.value)&&f.querySelectorAll&&f.querySelectorAll("input,select,textarea")[0]||f,b=mr(d),O=l._f.refs||[];if(b?O.find(M=>M===d):d===l._f.ref)return;$(s,a,{_f:{...l._f,...b?{refs:[...O.filter(Me),d,...Array.isArray(h(n,a))?[{}]:[]],ref:{type:d.type,name:a}}:{ref:d}}}),C(a,!1,void 0,d)}else l=h(s,a,{}),l._f&&(l._f.mount=!1),(e.shouldUnregister||u.shouldUnregister)&&!(Vt(c.array,a)&&o.action)&&c.unMount.add(a)}}},ke=()=>e.shouldFocusError&&ve(s,he,c.mount),It=a=>{K(a)&&(v.state.next({disabled:a}),ve(s,(u,l)=>{const g=h(s,l);g&&(u.disabled=g._f.disabled||a,Array.isArray(g._f.refs)&&g._f.refs.forEach(f=>{f.disabled=g._f.disabled||a}))},0,!1))},Ze=(a,u)=>async l=>{let g;l&&(l.preventDefault&&l.preventDefault(),l.persist&&l.persist());let f=U(i);if(v.state.next({isSubmitting:!0}),e.resolver){const{errors:d,values:b}=await ee();D(),t.errors=d,f=U(b)}else await X(s);if(c.disabled.size)for(const d of c.disabled)P(f,d);if(P(t.errors,"root"),W(t.errors)){v.state.next({errors:{}});try{await a(f,l)}catch(d){g=d}}else u&&await u({...t.errors},l),ke(),setTimeout(ke);if(v.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:W(t.errors)&&!g,submitCount:t.submitCount+1,errors:t.errors}),g)throw g},Ut=(a,u={})=>{h(s,a)&&(I(u.defaultValue)?G(a,U(h(n,a))):(G(a,u.defaultValue),$(n,a,U(u.defaultValue))),u.keepTouched||P(t.touchedFields,a),u.keepDirty||(P(t.dirtyFields,a),t.isDirty=u.defaultValue?k(a,U(h(n,a))):k()),u.keepError||(P(t.errors,a),y.isValid&&S()),v.state.next({...t}))},et=(a,u={})=>{const l=a?U(a):n,g=U(l),f=W(a),d=f?n:g;if(u.keepDefaultValues||(n=l),!u.keepValues){if(u.keepDirtyValues){const b=new Set([...c.mount,...Object.keys(de(n,i))]);for(const O of Array.from(b)){const M=h(t.dirtyFields,O),q=h(i,O),ue=h(d,O);M&&!I(q)?$(d,O,q):!M&&!I(ue)&&G(O,ue)}}else{if(Pe&&I(a))for(const b of c.mount){const O=h(s,b);if(O&&O._f){const M=Array.isArray(O._f.refs)?O._f.refs[0]:O._f.ref;if(Ce(M)){const q=M.closest("form");if(q){q.reset();break}}}}if(u.keepFieldsRef)for(const b of c.mount)G(b,h(d,b));else s={}}i=e.shouldUnregister?u.keepDefaultValues?U(n):{}:U(d),v.array.next({values:{...d}}),v.state.next({values:{...d}})}c={mount:u.keepDirtyValues?c.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!y.isValid||!!u.keepIsValid||!!u.keepDirtyValues||!e.shouldUnregister&&!W(d),o.watch=!!e.shouldUnregister,o.keepIsValid=!!u.keepIsValid,o.action=!1,u.keepErrors||(t.errors={}),v.state.next({submitCount:u.keepSubmitCount?t.submitCount:0,isDirty:f?!1:u.keepDirty?t.isDirty:!!(u.keepDefaultValues&&!se(a,n)),isSubmitted:u.keepIsSubmitted?t.isSubmitted:!1,dirtyFields:f?{}:u.keepDirtyValues?u.keepDefaultValues&&i?de(n,i):t.dirtyFields:u.keepDefaultValues&&a?de(n,a):u.keepDirty?t.dirtyFields:{},touchedFields:u.keepTouched?t.touchedFields:{},errors:u.keepErrors?t.errors:{},isSubmitSuccessful:u.keepIsSubmitSuccessful?t.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:n})},tt=(a,u)=>et(z(a)?a(i):a,{...e.resetOptions,...u}),Pt=(a,u={})=>{const l=h(s,a),g=l&&l._f;if(g){const f=g.refs?g.refs[0]:g.ref;f.focus&&setTimeout(()=>{f.focus(),u.shouldSelect&&z(f.select)&&f.select()})}},Lt=a=>{t={...t,...a}},rt={control:{register:De,unregister:Ee,getFieldState:Je,handleSubmit:Ze,setError:Ke,_subscribe:Qe,_runSchema:ee,_updateIsValidating:D,_focusError:ke,_getWatch:T,_getDirty:k,_setValid:S,_setFieldArray:w,_setDisabledField:Xe,_setErrors:A,_getFieldArray:H,_reset:et,_resetDefaultValues:()=>z(e.defaultValues)&&e.defaultValues().then(a=>{tt(a,e.resetOptions),v.state.next({isLoading:!1})}),_removeUnmounted:xe,_disableForm:It,_subjects:v,_proxyFormState:y,get _fields(){return s},get _formValues(){return i},get _state(){return o},set _state(a){o=a},get _defaultValues(){return n},get _names(){return c},set _names(a){c=a},get _formState(){return t},get _options(){return e},set _options(a){e={...e,...a}}},subscribe:$t,trigger:ge,register:De,handleSubmit:Ze,watch:Nt,setValue:G,getValues:Ge,reset:tt,resetField:Ut,clearErrors:Rt,unregister:Ee,setError:Ke,setFocus:Pt,getFieldState:Je};return{...rt,formControl:rt}}function zr(r={}){const e=x.useRef(void 0),t=x.useRef(void 0),[s,n]=x.useState({isDirty:!1,isValidating:!1,isLoading:z(r.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:r.errors||{},disabled:r.disabled||!1,isReady:!1,defaultValues:z(r.defaultValues)?void 0:r.defaultValues});if(!e.current)if(r.formControl)e.current={...r.formControl,formState:s},r.defaultValues&&!z(r.defaultValues)&&r.formControl.reset(r.defaultValues,r.resetOptions);else{const{formControl:o,...c}=Dr(r);e.current={...c,formState:s}}const i=e.current.control;return i._options=r,qe(()=>{const o=i._subscribe({formState:i._proxyFormState,callback:()=>n({...i._formState}),reRenderRoot:!0});return n(c=>({...c,isReady:!0})),i._formState.isReady=!0,o},[i]),x.useEffect(()=>i._disableForm(r.disabled),[i,r.disabled]),x.useEffect(()=>{r.mode&&(i._options.mode=r.mode),r.reValidateMode&&(i._options.reValidateMode=r.reValidateMode)},[i,r.mode,r.reValidateMode]),x.useEffect(()=>{r.errors&&(i._setErrors(r.errors),i._focusError())},[i,r.errors]),x.useEffect(()=>{r.shouldUnregister&&i._subjects.state.next({values:i._getWatch()})},[i,r.shouldUnregister]),x.useEffect(()=>{if(i._proxyFormState.isDirty){const o=i._getDirty();o!==s.isDirty&&i._subjects.state.next({isDirty:o})}},[i,s.isDirty]),x.useEffect(()=>{var o;r.values&&!se(r.values,t.current)?(i._reset(r.values,{keepFieldsRef:!0,...i._options.resetOptions}),!((o=i._options.resetOptions)===null||o===void 0)&&o.keepIsValid||i._setValid(),t.current=r.values,n(c=>({...c}))):i._resetDefaultValues()},[i,r.values]),x.useEffect(()=>{i._state.mount||(i._setValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),e.current.formState=x.useMemo(()=>At(s,i),[i,s]),e.current}export{Wt as C,be as E,Wr as F,rr as P,er as S,Br as a,zr as b,Nr as c,Lr as d,$r as e,Ur as f,Rr as g,Or as h,jr as i,Hr as j,Pr as k,Ir as l,Mr as m,qr as u};
|
|
Binary file
|
|
Binary file
|