@malloy-publisher/sdk 0.4.1 → 0.5.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.
Files changed (59) hide show
  1. package/dist/{DocumentStorage-BiFqO15i.es.js → DocumentStorage-B04sZ5Ie.es.js} +2284 -2319
  2. package/dist/{DocumentStorage-CMyLifsz.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +29 -29
  3. package/dist/{RenderedResult-CvrmYyr5.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
  4. package/dist/{RenderedResult-CZzE8wv-.cjs.js → RenderedResult-DVuGhatg.cjs.js} +27 -7
  5. package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
  6. package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
  7. package/dist/builder/index.cjs.js +54 -49
  8. package/dist/builder/index.es.js +4124 -3521
  9. package/dist/client/api.d.ts +14 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +1 -1
  12. package/dist/components/Dashboard/TileCard.d.ts +7 -3
  13. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +15 -4
  14. package/dist/components/DashboardBuilder/controls.d.ts +8 -6
  15. package/dist/components/DashboardBuilder/document.d.ts +19 -5
  16. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
  17. package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
  18. package/dist/components/DashboardBuilder/preview.d.ts +17 -0
  19. package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
  20. package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
  21. package/dist/index.cjs.js +1 -1
  22. package/dist/index.es.js +5 -5
  23. package/dist/theme/resolveTheme.d.ts +1 -1
  24. package/dist/theme/types.d.ts +12 -2
  25. package/package.json +1 -1
  26. package/src/components/Dashboard/TileCard.tsx +8 -4
  27. package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
  28. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
  29. package/src/components/DashboardBuilder/DashboardEditor.tsx +116 -25
  30. package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
  31. package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
  32. package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
  33. package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
  34. package/src/components/DashboardBuilder/controls.spec.ts +53 -3
  35. package/src/components/DashboardBuilder/controls.ts +9 -7
  36. package/src/components/DashboardBuilder/document.ts +17 -5
  37. package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
  38. package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
  39. package/src/components/DashboardBuilder/malloyText.ts +4 -109
  40. package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
  41. package/src/components/DashboardBuilder/malloyTree.ts +954 -0
  42. package/src/components/DashboardBuilder/preview.spec.ts +18 -0
  43. package/src/components/DashboardBuilder/preview.ts +24 -6
  44. package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
  45. package/src/components/DashboardBuilder/readDocument.ts +144 -165
  46. package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
  47. package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
  48. package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
  49. package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
  50. package/src/components/RenderedResult/RenderedResult.tsx +21 -1
  51. package/src/components/given/GivensPanel.tsx +15 -3
  52. package/src/theme/buildTableCssVars.spec.ts +3 -0
  53. package/src/theme/buildTableCssVars.ts +6 -0
  54. package/src/theme/defaults.ts +16 -12
  55. package/src/theme/resolveTheme.spec.ts +14 -7
  56. package/src/theme/resolveTheme.ts +14 -8
  57. package/src/theme/types.ts +12 -2
  58. package/tsconfig.spec.json +5 -1
  59. package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
@@ -1,52 +1,52 @@
1
- "use strict";var Id=Object.create;var Xo=Object.defineProperty;var jd=Object.getOwnPropertyDescriptor;var Ad=Object.getOwnPropertyNames;var Rd=Object.getPrototypeOf,Ld=Object.prototype.hasOwnProperty;var zd=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ad(t))!Ld.call(e,i)&&i!==n&&Xo(e,i,{get:()=>t[i],enumerable:!(r=jd(t,i))||r.enumerable});return e};var Yo=(e,t,n)=>(n=e!=null?Id(Rd(e)):{},zd(t||!e||!e.__esModule?Xo(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),S=require("react"),Wd=require("react-dom"),k=require("@mui/material"),j=require("../DocumentStorage-CMyLifsz.cjs.js"),Le=require("../ServerProvider-Cc489A3f.cjs.js"),Fd=require("@tanstack/react-query");var Bd=Symbol.for("preact-signals");function Si(){if(gt>1)gt--;else{var e,t=!1;for((function(){var i=ii;for(ii=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();rr!==void 0;){var n=rr;for(rr=void 0,ri++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Ua(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(ri=0,gt--,t)throw e}}function ae(e){if(gt>0)return e();rs=++Nd,gt++;try{return e()}finally{Si()}}var nr,re=void 0;function H(e){var t=re,n=nr;re=void 0,nr=void 0;try{return e()}finally{re=t,nr=n}}var rr=void 0,gt=0,ri=0,Nd=0,rs=0,ii=void 0,si=0;function qa(e){if(re!==void 0){var t=e.n;if(t===void 0||t.t!==re)return t={i:0,S:e,p:re.s,n:void 0,t:re,e:void 0,x:void 0,r:t},re.s!==void 0&&(re.s.n=t),re.s=t,e.n=t,32&re.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=re.s,t.n=void 0,re.s.n=t,re.s=t),t}}function Me(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Me.prototype.brand=Bd;Me.prototype.h=function(){return!0};Me.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:H(function(){var r;(r=t.W)==null||r.call(t)}))};Me.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&H(function(){var i;(i=t.Z)==null||i.call(t)}))}};Me.prototype.subscribe=function(e){var t=this;return Qe(function(){var n=t.value;H(function(){return e(n)})},{name:"sub"})};Me.prototype.valueOf=function(){return this.value};Me.prototype.toString=function(){return this.value+""};Me.prototype.toJSON=function(){return this.value};Me.prototype.peek=function(){var e=this;return H(function(){return e.value})};Object.defineProperty(Me.prototype,"value",{get:function(){var e=qa(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ri>100)throw new Error("Cycle detected");(function(n){gt!==0&&ri===0&&n.l!==rs&&(n.l=rs,ii={S:n,v:n.v,i:n.i,o:ii})})(this),this.v=e,this.i++,si++,gt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Si()}}}});function wn(e,t){return new Me(e,t)}function Ua(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Xa(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Ya(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function Gt(e,t){Me.call(this,void 0,t),this.x=e,this.s=void 0,this.g=si-1,this.f=4}Gt.prototype=new Me;Gt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===si))return!0;if(this.g=si,this.f|=1,this.i>0&&!Ua(this))return this.f&=-2,!0;var e=re;try{Xa(this),re=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return re=e,Ya(this),this.f&=-2,!0};Gt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Me.prototype.S.call(this,e)};Gt.prototype.U=function(e){if(this.t!==void 0&&(Me.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Gt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Gt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=qa(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Zo(e,t){return new Gt(e,t)}function Za(e){var t=e.m;if(e.m=void 0,typeof t=="function"){gt++;var n=re;re=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,Ks(e),r}finally{re=n,Si()}}}function Ks(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Za(e)}function Gd(e){if(re!==this)throw new Error("Out-of-order effect");Ya(this),re=e,this.f&=-2,8&this.f&&Ks(this),Si()}function kn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,nr&&nr.push(this)}kn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};kn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Za(this),Xa(this),gt++;var e=re;return re=this,Gd.bind(this,e)};kn.prototype.N=function(){2&this.f||(this.f|=2,this.u=rr,rr=this)};kn.prototype.d=function(){this.f|=8,1&this.f||Ks(this)};kn.prototype.dispose=function(){this.d()};function Qe(e,t){var n=new kn(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Vd=Object.create,qs=Object.defineProperty,Hd=Object.defineProperties,Kd=Object.getOwnPropertyDescriptor,qd=Object.getOwnPropertyDescriptors,Qo=Object.getOwnPropertySymbols,Ud=Object.prototype.hasOwnProperty,Xd=Object.prototype.propertyIsEnumerable,Yd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Sn=e=>{throw TypeError(e)},is=(e,t,n)=>t in e?qs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Zd=(e,t)=>{for(var n in t||(t={}))Ud.call(t,n)&&is(e,n,t[n]);if(Qo)for(var n of Qo(t))Xd.call(t,n)&&is(e,n,t[n]);return e},Qd=(e,t)=>Hd(e,qd(t)),Jo=(e,t)=>qs(e,"name",{value:t,configurable:!0}),Jd=e=>{var t;return[,,,Vd((t=void 0)!=null?t:null)]},Qa=["class","method","getter","setter","accessor","field","value","get","set"],Fn=e=>e!==void 0&&typeof e!="function"?Sn("Function expected"):e,eu=(e,t,n,r,i)=>({kind:Qa[e],name:t,metadata:r,addInitializer:s=>n._?Sn("Already initialized"):i.push(Fn(s||null))}),Ja=(e,t)=>is(t,Yd("metadata"),e[3]),Dt=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},$n=(e,t,n,r,i,s)=>{var o,a,l,d,u,c=t&7,h=!!(t&8),f=!!(t&16),g=c>3?e.length+1:c?h?1:2:0,m=Qa[c+5],w=c>3&&(e[g-1]=[]),b=e[g]||(e[g]=[]),v=c&&(!f&&!h&&(i=i.prototype),c<5&&(c>3||!f)&&Kd(c<4?i:{get[n](){return Ue(this,s)},set[n](x){return wt(this,s,x)}},n));c?f&&c<4&&Jo(s,(c>2?"set ":c>1?"get ":"")+n):Jo(i,n);for(var p=r.length-1;p>=0;p--)d=eu(c,n,l={},e[3],b),c&&(d.static=h,d.private=f,u=d.access={has:f?x=>tu(i,x):x=>n in x},c^3&&(u.get=f?x=>(c^1?Ue:nu)(x,i,c^4?s:v.get):x=>x[n]),c>2&&(u.set=f?(x,_)=>wt(x,i,_,c^4?s:v.set):(x,_)=>x[n]=_)),a=(0,r[p])(c?c<4?f?s:v[m]:c>4?void 0:{get:v.get,set:v.set}:i,d),l._=1,c^4||a===void 0?Fn(a)&&(c>4?w.unshift(a):c?f?s=a:v[m]=a:i=a):typeof a!="object"||a===null?Sn("Object expected"):(Fn(o=a.get)&&(v.get=o),Fn(o=a.set)&&(v.set=o),Fn(o=a.init)&&w.unshift(o));return c||Ja(e,i),v&&qs(i,n,v),f?c^4?s:v:i},Us=(e,t,n)=>t.has(e)||Sn("Cannot "+n),tu=(e,t)=>Object(t)!==t?Sn('Cannot use the "in" operator on this value'):e.has(t),Ue=(e,t,n)=>(Us(e,t,"read from private field"),n?n.call(e):t.get(e)),Bn=(e,t,n)=>t.has(e)?Sn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(Us(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),nu=(e,t,n)=>(Us(e,t,"access private method"),n);function ss(e,t){if(t){let n;return Zo(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Zo(e)}function nt(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,i)=>!nt(r,t[i]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(s=>!nt(e[s],t[s]))}return!1}function K({get:e},t){return{init(n){return wn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function ce(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ss(e.bind(this)),n.set(this,r)),r.value}}function Wi(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),i=Object.getOwnPropertyDescriptor(r,n.name);i&&Object.defineProperty(r,n.name,Qd(Zd({},i),{enumerable:e}))})}}function yr(...e){const t=e.map(n=>Qe(n));return()=>t.forEach(n=>n())}var el,tl,nl,rl,il,sl,De,Xs,Fi,os,as,Te,Ys,Bi,ol,ls,Zs,Ni,cs,ds;sl=[K],il=[K],rl=[K],nl=[Wi()],tl=[Wi()],el=[Wi()];var Vt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Dt(De,5,this),Bn(this,Te),Bn(this,Xs,Dt(De,8,this)),Dt(De,11,this),Bn(this,Ys,Dt(De,12,this)),Dt(De,15,this),Bn(this,Zs,Dt(De,16,this)),Dt(De,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Ue(this,Te,cs)}get initial(){return Ue(this,Te,os)}get previous(){return Ue(this,Te,ol)}set current(e){const t=H(()=>Ue(this,Te,cs));e&&t&&this.equals(t,e)||ae(()=>{Ue(this,Te,os)||wt(this,Te,e,as),wt(this,Te,t,ls),wt(this,Te,e,ds)})}reset(e=this.defaultValue){ae(()=>{wt(this,Te,void 0,ls),wt(this,Te,e,as),wt(this,Te,e,ds)})}};De=Jd();Xs=new WeakMap;Te=new WeakSet;Ys=new WeakMap;Zs=new WeakMap;Fi=$n(De,20,"#initial",sl,Te,Xs),os=Fi.get,as=Fi.set;Bi=$n(De,20,"#previous",il,Te,Ys),ol=Bi.get,ls=Bi.set;Ni=$n(De,20,"#current",rl,Te,Zs),cs=Ni.get,ds=Ni.set;$n(De,2,"current",nl,Vt);$n(De,2,"initial",tl,Vt);$n(De,2,"previous",el,Vt);Ja(De,Vt);function Gi(e){return H(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Pt,ru=class{constructor(){Bn(this,Pt,new WeakMap)}get(e,t){var n;return e?(n=Ue(this,Pt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Ue(this,Pt).has(e)||Ue(this,Pt).set(e,new Map),(r=Ue(this,Pt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Ue(this,Pt).get(e))==null?void 0:t.clear():void 0}};Pt=new WeakMap;var iu=Object.create,al=Object.defineProperty,su=Object.getOwnPropertyDescriptor,ea=Object.getOwnPropertySymbols,ou=Object.prototype.hasOwnProperty,au=Object.prototype.propertyIsEnumerable,ll=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),$i=e=>{throw TypeError(e)},ta=Math.pow,us=(e,t,n)=>t in e?al(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lu=(e,t)=>{for(var n in t||(t={}))ou.call(t,n)&&us(e,n,t[n]);if(ea)for(var n of ea(t))au.call(t,n)&&us(e,n,t[n]);return e},cu=e=>{var t;return[,,,iu((t=e?.[ll("metadata")])!=null?t:null)]},cl=["class","method","getter","setter","accessor","field","value","get","set"],dl=e=>e!==void 0&&typeof e!="function"?$i("Function expected"):e,du=(e,t,n,r,i)=>({kind:cl[e],name:t,metadata:r,addInitializer:s=>n._?$i("Already initialized"):i.push(dl(s||null))}),uu=(e,t)=>us(t,ll("metadata"),e[3]),fu=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},ul=(e,t,n,r,i,s)=>{for(var o,a,l,d,u=t&7,c=!1,h=!1,f=2,g=cl[u+5],m=e[f]||(e[f]=[]),w=(i=i.prototype,su(i,n)),b=r.length-1;b>=0;b--)l=du(u,n,a={},e[3],m),l.static=c,l.private=h,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[b])(w[g],l),a._=1,dl(o)&&(w[g]=o);return w&&al(i,n,w),i},fl=(e,t,n)=>t.has(e)||$i("Cannot "+n),hu=(e,t,n)=>(fl(e,t,"read from private field"),t.get(e)),pu=(e,t,n)=>t.has(e)?$i("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),gu=(e,t,n,r)=>(fl(e,t,"write to private field"),t.set(e,n),n),Xe=class fs{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new fs(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new fs(t,n)}},lt=class Ct{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,l=new Ct(i+t,r+n,s,o);return l.scale=lu({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new Xe((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Ct))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof Ct?vu(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:i}){return new Ct(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],l=o==="x"?s.left:s.top,d=o==="x"?s.width:s.height;return a=="start"?l:a=="end"?l+d:l+d/2};return Xe.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return Ct.from(t).intersectionRatio(Ct.from(n))}};function vu(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var hl,pl,hs,Vr,br,Oi=class extends(hs=Vt,pl=[ce],hl=[ce],hs){constructor(t){const n=Xe.from(t);super(n,(r,i)=>Xe.equals(r,i)),fu(br,5,this),pu(this,Vr,0),this.velocity={x:0,y:0}}get delta(){return Xe.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Xe.from(t),i={x:r.x-n.x,y:r.y-n.y},s=Date.now(),o=s-hu(this,Vr),a=l=>Math.round(l/o*100);ae(()=>{gu(this,Vr,s),this.velocity={x:a(i.x),y:a(i.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Xe.from(t)),this.velocity={x:0,y:0}}};br=cu(hs);Vr=new WeakMap;ul(br,2,"delta",pl,Oi);ul(br,2,"direction",hl,Oi);uu(br,Oi);function ps({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(ta(r,2)+ta(i,2))>n:"x"in n&&"y"in n?r>n.x&&i>n.y:"x"in n?r>n.x:"y"in n?i>n.y:!1}var gl=(e=>(e.Horizontal="x",e.Vertical="y",e))(gl||{}),vl=Object.values(gl),mu=Object.create,Qs=Object.defineProperty,yu=Object.defineProperties,bu=Object.getOwnPropertyDescriptor,xu=Object.getOwnPropertyDescriptors,oi=Object.getOwnPropertySymbols,ml=Object.prototype.hasOwnProperty,yl=Object.prototype.propertyIsEnumerable,bl=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),On=e=>{throw TypeError(e)},gs=(e,t,n)=>t in e?Qs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Js=(e,t)=>{for(var n in t||(t={}))ml.call(t,n)&&gs(e,n,t[n]);if(oi)for(var n of oi(t))yl.call(t,n)&&gs(e,n,t[n]);return e},eo=(e,t)=>yu(e,xu(t)),na=(e,t)=>Qs(e,"name",{value:t,configurable:!0}),xl=(e,t)=>{var n={};for(var r in e)ml.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&oi)for(var r of oi(e))t.indexOf(r)<0&&yl.call(e,r)&&(n[r]=e[r]);return n},Tn=e=>{var t;return[,,,mu((t=e?.[bl("metadata")])!=null?t:null)]},_l=["class","method","getter","setter","accessor","field","value","get","set"],Nn=e=>e!==void 0&&typeof e!="function"?On("Function expected"):e,_u=(e,t,n,r,i)=>({kind:_l[e],name:t,metadata:r,addInitializer:s=>n._?On("Already initialized"):i.push(Nn(s||null))}),Ht=(e,t)=>gs(t,bl("metadata"),e[3]),N=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},q=(e,t,n,r,i,s)=>{var o,a,l,d,u,c=t&7,h=!!(t&8),f=!!(t&16),g=c>3?e.length+1:c?h?1:2:0,m=_l[c+5],w=c>3&&(e[g-1]=[]),b=e[g]||(e[g]=[]),v=c&&(!f&&!h&&(i=i.prototype),c<5&&(c>3||!f)&&bu(c<4?i:{get[n](){return le(this,s)},set[n](x){return Ve(this,s,x)}},n));c?f&&c<4&&na(s,(c>2?"set ":c>1?"get ":"")+n):na(i,n);for(var p=r.length-1;p>=0;p--)d=_u(c,n,l={},e[3],b),c&&(d.static=h,d.private=f,u=d.access={has:f?x=>wu(i,x):x=>n in x},c^3&&(u.get=f?x=>(c^1?le:wl)(x,i,c^4?s:v.get):x=>x[n]),c>2&&(u.set=f?(x,_)=>Ve(x,i,_,c^4?s:v.set):(x,_)=>x[n]=_)),a=(0,r[p])(c?c<4?f?s:v[m]:c>4?void 0:{get:v.get,set:v.set}:i,d),l._=1,c^4||a===void 0?Nn(a)&&(c>4?w.unshift(a):c?f?s=a:v[m]=a:i=a):typeof a!="object"||a===null?On("Object expected"):(Nn(o=a.get)&&(v.get=o),Nn(o=a.set)&&(v.set=o),Nn(o=a.init)&&w.unshift(o));return c||Ht(e,i),v&&Qs(i,n,v),f?c^4?s:v:i},to=(e,t,n)=>t.has(e)||On("Cannot "+n),wu=(e,t)=>Object(t)!==t?On('Cannot use the "in" operator on this value'):e.has(t),le=(e,t,n)=>(to(e,t,"read from private field"),n?n.call(e):t.get(e)),Z=(e,t,n)=>t.has(e)?On("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ve=(e,t,n,r)=>(to(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wl=(e,t,n)=>(to(e,t,"access private method"),n);function kl(e,t){return{plugin:e,options:t}}function xr(e){return t=>kl(e,t)}function cr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Sl,dr,no,Hr;Sl=[K];var Ee=class{constructor(e,t){this.manager=e,this.options=t,Z(this,no,N(dr,8,this,!1)),N(dr,11,this),Z(this,Hr,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return H(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Qe(e.bind(this));return le(this,Hr).add(t),t}destroy(){le(this,Hr).forEach(e=>e())}static configure(e){return kl(this,e)}};dr=Tn(null);no=new WeakMap;Hr=new WeakMap;q(dr,4,"disabled",Sl,Ee,no);Ht(dr,Ee);var _r=class extends Ee{},Kr,Vi=class{constructor(e){this.manager=e,this.instances=new Map,Z(this,Kr,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(cr).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of le(this,Kr))if(!n.includes(r)){if(r.prototype instanceof _r)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);Ve(this,Kr,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};Kr=new WeakMap;function ku(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Mr=[],nn,rn,Su=class extends Ee{constructor(e){super(e),Z(this,nn),Z(this,rn),this.computeCollisions=this.computeCollisions.bind(this),Ve(this,rn,wn(Mr)),this.destroy=yr(()=>{const t=this.computeCollisions(),n=H(()=>this.manager.dragOperation.position.current);if(t!==Mr){const r=le(this,nn);if(Ve(this,nn,n),r&&n.x==r.x&&n.y==r.y)return}else Ve(this,nn,void 0);le(this,rn).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){H(()=>{e?le(this,rn).value=this.computeCollisions():Ve(this,nn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return Mr;const a=[],l=[];for(const d of e??n.droppables){if(d.disabled||i&&!d.accepts(i))continue;const u=t??d.collisionDetector;if(!u)continue;l.push(d),d.shape;const c=H(()=>u({droppable:d,dragOperation:r}));c&&(d.collisionPriority!=null&&(c.priority=d.collisionPriority),a.push(c))}return l.length===0?Mr:(a.sort(ku),a)}get collisions(){return le(this,rn).value}};nn=new WeakMap;rn=new WeakMap;var $l,Ol,Tl,ro,El,rt,io,dn,so,oo;Tl=[K],Ol=[K],$l=[K];var mt=class Mt{constructor(t,n){Z(this,io,N(rt,8,this)),N(rt,11,this),Z(this,dn),Z(this,so,N(rt,12,this)),N(rt,15,this),Z(this,oo,N(rt,16,this)),N(rt,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let l=i;Ve(this,dn,wn(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var d;return[()=>{const{id:u,manager:c}=this;if(u!==l)return l=u,c?.registry.register(this),()=>c?.registry.unregister(this)},...(d=r?.())!=null?d:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=le(this,dn).value;return(n=(t=Mt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=Mt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:le(this,dn).peek();t!==i&&(Mt.pendingIdChanges||(Mt.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return wl(s=Mt,ro,El).call(s)})),Mt.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};rt=Tn(null);ro=new WeakSet;El=function(){const e=mt.pendingIdChanges;mt.pendingIdChanges=null,e&&ae(()=>{for(const[t,n]of e)le(t,dn).value=n})};io=new WeakMap;dn=new WeakMap;so=new WeakMap;oo=new WeakMap;q(rt,4,"manager",Tl,mt,io);q(rt,4,"data",Ol,mt,so);q(rt,4,"disabled",$l,mt,oo);Z(mt,ro);Ht(rt,mt);mt.pendingIdChanges=null;var Ti=mt,ra=class{constructor(){this.map=wn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const s=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=yr(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Dl,Pl,Cl,Ml,Il,jl,vs,Pe,ao,lo,co,ct=class extends(vs=Ti,jl=[K],Il=[K],Ml=[K],Cl=[ce],Pl=[ce],Dl=[ce],vs){constructor(t,n){var r=t,{modifiers:i,type:s,sensors:o,plugins:a,effects:l}=r,d=xl(r,["modifiers","type","sensors","plugins","effects"]);super(eo(Js({},d),{effects:()=>{var u;return[...(u=l?.())!=null?u:[],()=>{const{manager:c,plugins:h}=this;if(!(!c||!h))for(const f of h){const{plugin:g}=cr(f);c.registry.plugins.register(g)}}]}}),n),N(Pe,5,this),Z(this,ao,N(Pe,8,this)),N(Pe,11,this),Z(this,lo,N(Pe,12,this)),N(Pe,15,this),Z(this,co,N(Pe,16,this,this.isDragSource?"dragging":"idle")),N(Pe,19,this),this.type=s,this.sensors=o,this.modifiers=i,this.alignment=d.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=cr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};Pe=Tn(vs);ao=new WeakMap;lo=new WeakMap;co=new WeakMap;q(Pe,4,"type",jl,ct,ao);q(Pe,4,"modifiers",Il,ct,lo);q(Pe,4,"status",Ml,ct,co);q(Pe,2,"isDropping",Cl,ct);q(Pe,2,"isDragging",Pl,ct);q(Pe,2,"isDragSource",Dl,ct);Ht(Pe,ct);var Al,Rl,Ll,zl,Wl,Fl,ms,he,uo,fo,ho,po,go,dt=class extends(ms=Ti,Fl=[K],Wl=[K],zl=[K],Ll=[K],Rl=[K],Al=[ce],ms){constructor(t,n){var r=t,{accept:i,collisionDetector:s,collisionPriority:o,type:a}=r,l=xl(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),N(he,5,this),Z(this,uo,N(he,8,this)),N(he,11,this),Z(this,fo,N(he,12,this)),N(he,15,this),Z(this,ho,N(he,16,this)),N(he,19,this),Z(this,po,N(he,20,this)),N(he,23,this),Z(this,go,N(he,24,this)),N(he,27,this),this.accept=i,this.collisionDetector=s,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};he=Tn(ms);uo=new WeakMap;fo=new WeakMap;ho=new WeakMap;po=new WeakMap;go=new WeakMap;q(he,4,"accept",Fl,dt,uo);q(he,4,"type",Wl,dt,fo);q(he,4,"collisionDetector",zl,dt,ho);q(he,4,"collisionPriority",Ll,dt,po);q(he,4,"shape",Rl,dt,go);q(he,2,"isDropTarget",Al,dt);Ht(he,dt);var $u=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const i of r)i(...t)}},Ou=class extends $u{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function qr(e,t=!0){let n=!1;return eo(Js({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Tu=class extends _r{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=yr(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||Ti.pendingIdChanges)return;const o=qr({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;H(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},En=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(En||{}),Dn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Dn||{}),Bl,Nl,Gl,Vl,Hl,Kl,ql,Ze,vo;ql=[K],Kl=[ce],Hl=[ce],Vl=[ce],Gl=[ce],Nl=[ce],Bl=[ce];var yt=class{constructor(){N(Ze,5,this),Z(this,vo,N(Ze,8,this,"idle")),N(Ze,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};Ze=Tn(null);vo=new WeakMap;q(Ze,4,"value",ql,yt,vo);q(Ze,2,"current",Kl,yt);q(Ze,2,"idle",Hl,yt);q(Ze,2,"initializing",Vl,yt);q(Ze,2,"initialized",Gl,yt);q(Ze,2,"dragging",Nl,yt);q(Ze,2,"dropped",Bl,yt);Ht(Ze,yt);var Eu=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return H(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=qr({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return H(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:i,coordinates:s}=e;ae(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=i??null,t.position.reset(s)});const o=qr({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&ae(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:i,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return H(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=qr({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,l,d,u,c;if(o.defaultPrevented)return;const h=(c=e.to)!=null?c:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((u=(d=e.by)==null?void 0:d.y)!=null?u:0)};r.position.current=h})})}stop(e={}){return H(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const l={resume:()=>{},abort:()=>{}};return s=new Promise((d,u)=>{l.resume=d,l.abort=u}),l};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=H(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),d=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,c=Qe(()=>{u?.status==="idle"&&(c(),d())})}else this.manager.renderer.rendering.then(d)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},gn=class extends Ee{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Du=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},Ur,Ul=class{constructor(e){this.options=e,Z(this,Ur)}set controller(e){Ve(this,Ur,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=le(this,Ur))==null||t.activate(e)}};Ur=new WeakMap;var ia=class extends Ee{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Pu=class{constructor(e){this.draggables=new ra,this.droppables=new ra,this.plugins=new Vi(e),this.sensors=new Vi(e),this.modifiers=new Vi(e)}register(e,t){if(e instanceof ct)return this.draggables.register(e.id,e);if(e instanceof dt)return this.droppables.register(e.id,e);if(e.prototype instanceof ia)return this.modifiers.register(e,t);if(e.prototype instanceof gn)return this.sensors.register(e,t);if(e.prototype instanceof Ee)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Ti)return e instanceof ct?this.draggables.unregister(e.id,e):e instanceof dt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof ia)return this.modifiers.unregister(e);if(e.prototype instanceof gn)return this.sensors.unregister(e);if(e.prototype instanceof Ee)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},Xl,Yl,Zl,Ql,Jl,ec,tc,nc,rc,Gn,Xr,sn,oe,mo,yo,bo,xo,_o,Vn;rc=[ce],nc=[K],tc=[K],ec=[K],Jl=[K],Ql=[K],Zl=[ce],Yl=[ce],Xl=[ce];var st=class{constructor(e){N(oe,5,this),Z(this,Gn),Z(this,Xr),Z(this,sn,new Vt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new yt,Z(this,mo,N(oe,8,this,!1)),N(oe,11,this),Z(this,yo,N(oe,12,this,null)),N(oe,15,this),Z(this,bo,N(oe,16,this,null)),N(oe,19,this),Z(this,xo,N(oe,20,this,null)),N(oe,23,this),Z(this,_o,N(oe,24,this,[])),N(oe,27,this),this.position=new Oi({x:0,y:0}),Z(this,Vn,{x:0,y:0}),Ve(this,Gn,e)}get shape(){const{current:e,initial:t,previous:n}=le(this,sn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?le(this,sn).current=e:le(this,sn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=le(this,Gn).registry.draggables.get(t);return n&&Ve(this,Xr,n),(e=n??le(this,Xr))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=le(this,Gn).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(eo(Js({},this.snapshot()),{transform:n}));return Ve(this,Vn,n),n}snapshot(){return H(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:le(this,Vn),shape:this.shape?Gi(this.shape):null,position:Gi(this.position),status:Gi(this.status),canceled:this.canceled}))}reset(){ae(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,le(this,sn).reset(),this.position.reset({x:0,y:0}),Ve(this,Vn,{x:0,y:0}),this.modifiers=[]})}};oe=Tn(null);Gn=new WeakMap;Xr=new WeakMap;sn=new WeakMap;mo=new WeakMap;yo=new WeakMap;bo=new WeakMap;xo=new WeakMap;_o=new WeakMap;Vn=new WeakMap;q(oe,2,"shape",rc,st);q(oe,4,"canceled",nc,st,mo);q(oe,4,"activatorEvent",tc,st,yo);q(oe,4,"sourceIdentifier",ec,st,bo);q(oe,4,"targetIdentifier",Jl,st,xo);q(oe,4,"modifiers",Ql,st,_o);q(oe,2,"source",Zl,st);q(oe,2,"target",Yl,st);q(oe,2,"transform",Xl,st);Ht(oe,st);var Cu={get rendering(){return Promise.resolve()}};function it(e,t){return typeof e=="function"?e(t):e??t}var Mu=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(h=>h.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},i=it(r.plugins,[]),s=it(r.sensors,[]),o=it(r.modifiers,[]),a=(n=r.renderer)!=null?n:Cu,l=new Ou(this),d=new Pu(this);this.registry=d,this.monitor=l,this.renderer=a,this.actions=new Eu(this),this.dragOperation=new st(this),this.collisionObserver=new Su(this),this.plugins=[Tu,...i],this.modifiers=o,this.sensors=s;const{destroy:u}=this,c=yr(()=>{var h,f,g;const m=H(()=>this.dragOperation.modifiers),w=this.modifiers;for(const b of m)w.includes(b)||b.destroy();this.dragOperation.modifiers=(g=(f=(h=this.dragOperation.source)==null?void 0:h.modifiers)==null?void 0:f.map(b=>{const{plugin:v,options:p}=cr(b);return new v(this,p)}))!=null?g:w});this.destroy=()=>{c(),u()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},ic=e=>{throw TypeError(e)},wo=(e,t,n)=>t.has(e)||ic("Cannot "+n),B=(e,t,n)=>(wo(e,t,"read from private field"),t.get(e)),Re=(e,t,n)=>t.has(e)?ic("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ge=(e,t,n,r)=>(wo(e,t,"write to private field"),t.set(e,n),n),sc=(e,t,n)=>(wo(e,t,"access private method"),n);function Ei(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function oc(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,a=(Ei(s)?s.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],i])}return r}function Di(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function ko(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function wr(e){return"nodeType"in e}function He(e){var t,n,r;return e?ko(e)?e:wr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function So(e){const{Document:t}=He(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Tt(e){return!e||ko(e)?!1:e instanceof He(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function ac(e){return e instanceof He(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Pn(e){return e?ko(e)?e.document:wr(e)?So(e)?e:Tt(e)||ac(e)?e.ownerDocument:document:document:document}function Iu(e){var t,n,r,i;const{documentElement:s}=Pn(e),o=He(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,l=(n=o?.height)!=null?n:s.clientHeight,d=(r=o?.offsetTop)!=null?r:0,u=(i=o?.offsetLeft)!=null?i:0;return{top:d,left:u,right:u+a,bottom:d+l,width:a,height:l}}function ju(e,t){if(Au(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function Au(e){return e.tagName==="DETAILS"}function ur(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let l=t;const{ownerDocument:d}=e,u=(r=d.defaultView)!=null?r:window;let c=e.parentElement;for(;c&&c!==d.documentElement;){if(!ju(c)){const p=c.getBoundingClientRect(),x=n*(p.bottom-p.top),_=n*(p.right-p.left),O=n*(p.bottom-p.top),T=n*(p.right-p.left);l={top:Math.max(l.top,p.top-x),right:Math.min(l.right,p.right+_),bottom:Math.min(l.bottom,p.bottom+O),left:Math.max(l.left,p.left-T),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}c=c.parentElement}const h=u.visualViewport,f=(i=h?.offsetTop)!=null?i:0,g=(s=h?.offsetLeft)!=null?s:0,m=(o=h?.width)!=null?o:u.innerWidth,w=(a=h?.height)!=null?a:u.innerHeight,b=n*w,v=n*m;return l={top:Math.max(l.top,f-b),right:Math.min(l.right,g+m+v),bottom:Math.min(l.bottom,f+w+b),left:Math.max(l.left,g-v),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function vn(e){return{x:e.clientX,y:e.clientY}}var lc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ys(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const i=r.contentDocument;i&&!t.has(i)&&n.push(...ys(i,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const i=r.parent;i&&i.document&&i.document!==e&&n.push(...ys(i.document,t))}}catch{}return n}function $o(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function cc(){var e,t;const n=$o()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Oo(e){return!e||!wr(e)?!1:e instanceof He(e).ShadowRoot}function ai(e){if(e&&wr(e)){let t=e.getRootNode();if(Oo(t))return t;if(t instanceof Document)return t}return Pn(e)}function To(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ru(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((s,o)=>{const a=r[o];if(sa(s)&&sa(a)&&(s.type!=="file"&&(s.value=a.value),s.type==="radio"&&s.name&&(s.name=`Cloned__${s.name}`)),oa(s)&&oa(a)&&a.width>0&&a.height>0){const l=s.getContext("2d");l?.drawImage(a,0,0)}}),n}function sa(e){return"value"in e}function oa(e){return e.tagName==="CANVAS"}function dc(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Lu(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return dc(i,{x:t-s,y:n-o})}}return r}function Lu(e){return e?.tagName==="IFRAME"}var bs=new WeakMap;function zu(e){return e.closest(`
1
+ "use strict";var Jd=Object.create;var sa=Object.defineProperty;var eu=Object.getOwnPropertyDescriptor;var tu=Object.getOwnPropertyNames;var nu=Object.getPrototypeOf,ru=Object.prototype.hasOwnProperty;var iu=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tu(t))!ru.call(e,i)&&i!==n&&sa(e,i,{get:()=>t[i],enumerable:!(r=eu(t,i))||r.enumerable});return e};var oa=(e,t,n)=>(n=e!=null?Jd(nu(e)):{},iu(t||!e||!e.__esModule?sa(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),S=require("react"),su=require("react-dom"),k=require("@mui/material"),j=require("../DocumentStorage-B_MMJ0Ot.cjs.js"),Be=require("../ServerProvider-D-jjzfE5.cjs.js"),ou=require("@tanstack/react-query");var au=Symbol.for("preact-signals");function Ci(){if(vt>1)vt--;else{var e,t=!1;for((function(){var i=ui;for(ui=void 0;i!==void 0;){var s=i.S;if(s.v===i.v)for(var o=s.t;o!==void 0;o=o.x)o.i===i.i&&(o.i=s.i);i=i.o}})();cr!==void 0;){var n=cr;for(cr=void 0,di++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&ol(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=r}}if(di=0,vt--,t)throw e}}function de(e){if(vt>0)return e();ds=++lu,vt++;try{return e()}finally{Ci()}}var lr,re=void 0;function U(e){var t=re,n=lr;re=void 0,lr=void 0;try{return e()}finally{re=t,lr=n}}var cr=void 0,vt=0,di=0,lu=0,ds=0,ui=void 0,fi=0;function sl(e){if(re!==void 0){var t=e.n;if(t===void 0||t.t!==re)return t={i:0,S:e,p:re.s,n:void 0,t:re,e:void 0,x:void 0,r:t},re.s!==void 0&&(re.s.n=t),re.s=t,e.n=t,32&re.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=re.s,t.n=void 0,re.s.n=t,re.s=t),t}}function Re(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Re.prototype.brand=au;Re.prototype.h=function(){return!0};Re.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:U(function(){var r;(r=t.W)==null||r.call(t)}))};Re.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&U(function(){var i;(i=t.Z)==null||i.call(t)}))}};Re.prototype.subscribe=function(e){var t=this;return tt(function(){var n=t.value;U(function(){return e(n)})},{name:"sub"})};Re.prototype.valueOf=function(){return this.value};Re.prototype.toString=function(){return this.value+""};Re.prototype.toJSON=function(){return this.value};Re.prototype.peek=function(){var e=this;return U(function(){return e.value})};Object.defineProperty(Re.prototype,"value",{get:function(){var e=sl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(di>100)throw new Error("Cycle detected");(function(n){vt!==0&&di===0&&n.l!==ds&&(n.l=ds,ui={S:n,v:n.v,i:n.i,o:ui})})(this),this.v=e,this.i++,fi++,vt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Ci()}}}});function En(e,t){return new Re(e,t)}function ol(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function al(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function ll(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function qt(e,t){Re.call(this,void 0,t),this.x=e,this.s=void 0,this.g=fi-1,this.f=4}qt.prototype=new Re;qt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===fi))return!0;if(this.g=fi,this.f|=1,this.i>0&&!ol(this))return this.f&=-2,!0;var e=re;try{al(this),re=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return re=e,ll(this),this.f&=-2,!0};qt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Re.prototype.S.call(this,e)};qt.prototype.U=function(e){if(this.t!==void 0&&(Re.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};qt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(qt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=sl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function aa(e,t){return new qt(e,t)}function cl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){vt++;var n=re;re=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,eo(e),r}finally{re=n,Ci()}}}function eo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,cl(e)}function cu(e){if(re!==this)throw new Error("Out-of-order effect");ll(this),re=e,this.f&=-2,8&this.f&&eo(this),Ci()}function On(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,lr&&lr.push(this)}On.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};On.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,cl(this),al(this),vt++;var e=re;return re=this,cu.bind(this,e)};On.prototype.N=function(){2&this.f||(this.f|=2,this.u=cr,cr=this)};On.prototype.d=function(){this.f|=8,1&this.f||eo(this)};On.prototype.dispose=function(){this.d()};function tt(e,t){var n=new On(e,t);try{n.c()}catch(i){throw n.d(),i}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var du=Object.create,to=Object.defineProperty,uu=Object.defineProperties,fu=Object.getOwnPropertyDescriptor,hu=Object.getOwnPropertyDescriptors,la=Object.getOwnPropertySymbols,pu=Object.prototype.hasOwnProperty,gu=Object.prototype.propertyIsEnumerable,vu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Dn=e=>{throw TypeError(e)},us=(e,t,n)=>t in e?to(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mu=(e,t)=>{for(var n in t||(t={}))pu.call(t,n)&&us(e,n,t[n]);if(la)for(var n of la(t))gu.call(t,n)&&us(e,n,t[n]);return e},yu=(e,t)=>uu(e,hu(t)),ca=(e,t)=>to(e,"name",{value:t,configurable:!0}),bu=e=>{var t;return[,,,du((t=void 0)!=null?t:null)]},dl=["class","method","getter","setter","accessor","field","value","get","set"],Hn=e=>e!==void 0&&typeof e!="function"?Dn("Function expected"):e,xu=(e,t,n,r,i)=>({kind:dl[e],name:t,metadata:r,addInitializer:s=>n._?Dn("Already initialized"):i.push(Hn(s||null))}),ul=(e,t)=>us(t,vu("metadata"),e[3]),Mt=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},Tn=(e,t,n,r,i,s)=>{var o,a,l,u,c,d=t&7,h=!!(t&8),f=!!(t&16),g=d>3?e.length+1:d?h?1:2:0,v=dl[d+5],w=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),m=d&&(!f&&!h&&(i=i.prototype),d<5&&(d>3||!f)&&fu(d<4?i:{get[n](){return Qe(this,s)},set[n](b){return kt(this,s,b)}},n));d?f&&d<4&&ca(s,(d>2?"set ":d>1?"get ":"")+n):ca(i,n);for(var p=r.length-1;p>=0;p--)u=xu(d,n,l={},e[3],x),d&&(u.static=h,u.private=f,c=u.access={has:f?b=>wu(i,b):b=>n in b},d^3&&(c.get=f?b=>(d^1?Qe:_u)(b,i,d^4?s:m.get):b=>b[n]),d>2&&(c.set=f?(b,_)=>kt(b,i,_,d^4?s:m.set):(b,_)=>b[n]=_)),a=(0,r[p])(d?d<4?f?s:m[v]:d>4?void 0:{get:m.get,set:m.set}:i,u),l._=1,d^4||a===void 0?Hn(a)&&(d>4?w.unshift(a):d?f?s=a:m[v]=a:i=a):typeof a!="object"||a===null?Dn("Object expected"):(Hn(o=a.get)&&(m.get=o),Hn(o=a.set)&&(m.set=o),Hn(o=a.init)&&w.unshift(o));return d||ul(e,i),m&&to(i,n,m),f?d^4?s:m:i},no=(e,t,n)=>t.has(e)||Dn("Cannot "+n),wu=(e,t)=>Object(t)!==t?Dn('Cannot use the "in" operator on this value'):e.has(t),Qe=(e,t,n)=>(no(e,t,"read from private field"),n?n.call(e):t.get(e)),qn=(e,t,n)=>t.has(e)?Dn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),kt=(e,t,n,r)=>(no(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_u=(e,t,n)=>(no(e,t,"access private method"),n);function fs(e,t){if(t){let n;return aa(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return aa(e)}function rt(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,i)=>!rt(r,t[i]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(s=>!rt(e[s],t[s]))}return!1}function H({get:e},t){return{init(n){return En(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function pe(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=fs(e.bind(this)),n.set(this,r)),r.value}}function Hi(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),i=Object.getOwnPropertyDescriptor(r,n.name);i&&Object.defineProperty(r,n.name,yu(mu({},i),{enumerable:e}))})}}function $r(...e){const t=e.map(n=>tt(n));return()=>t.forEach(n=>n())}var fl,hl,pl,gl,vl,ml,Ie,ro,qi,hs,ps,Ce,io,Ki,yl,gs,so,Yi,vs,ms;ml=[H],vl=[H],gl=[H],pl=[Hi()],hl=[Hi()],fl=[Hi()];var Kt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,Mt(Ie,5,this),qn(this,Ce),qn(this,ro,Mt(Ie,8,this)),Mt(Ie,11,this),qn(this,io,Mt(Ie,12,this)),Mt(Ie,15,this),qn(this,so,Mt(Ie,16,this)),Mt(Ie,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Qe(this,Ce,vs)}get initial(){return Qe(this,Ce,hs)}get previous(){return Qe(this,Ce,yl)}set current(e){const t=U(()=>Qe(this,Ce,vs));e&&t&&this.equals(t,e)||de(()=>{Qe(this,Ce,hs)||kt(this,Ce,e,ps),kt(this,Ce,t,gs),kt(this,Ce,e,ms)})}reset(e=this.defaultValue){de(()=>{kt(this,Ce,void 0,gs),kt(this,Ce,e,ps),kt(this,Ce,e,ms)})}};Ie=bu();ro=new WeakMap;Ce=new WeakSet;io=new WeakMap;so=new WeakMap;qi=Tn(Ie,20,"#initial",ml,Ce,ro),hs=qi.get,ps=qi.set;Ki=Tn(Ie,20,"#previous",vl,Ce,io),yl=Ki.get,gs=Ki.set;Yi=Tn(Ie,20,"#current",gl,Ce,so),vs=Yi.get,ms=Yi.set;Tn(Ie,2,"current",pl,Kt);Tn(Ie,2,"initial",hl,Kt);Tn(Ie,2,"previous",fl,Kt);ul(Ie,Kt);function Xi(e){return U(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var It,ku=class{constructor(){qn(this,It,new WeakMap)}get(e,t){var n;return e?(n=Qe(this,It).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Qe(this,It).has(e)||Qe(this,It).set(e,new Map),(r=Qe(this,It).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Qe(this,It).get(e))==null?void 0:t.clear():void 0}};It=new WeakMap;var Su=Object.create,bl=Object.defineProperty,$u=Object.getOwnPropertyDescriptor,da=Object.getOwnPropertySymbols,Eu=Object.prototype.hasOwnProperty,Ou=Object.prototype.propertyIsEnumerable,xl=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Pi=e=>{throw TypeError(e)},ua=Math.pow,ys=(e,t,n)=>t in e?bl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Du=(e,t)=>{for(var n in t||(t={}))Eu.call(t,n)&&ys(e,n,t[n]);if(da)for(var n of da(t))Ou.call(t,n)&&ys(e,n,t[n]);return e},Tu=e=>{var t;return[,,,Su((t=e?.[xl("metadata")])!=null?t:null)]},wl=["class","method","getter","setter","accessor","field","value","get","set"],_l=e=>e!==void 0&&typeof e!="function"?Pi("Function expected"):e,Cu=(e,t,n,r,i)=>({kind:wl[e],name:t,metadata:r,addInitializer:s=>n._?Pi("Already initialized"):i.push(_l(s||null))}),Pu=(e,t)=>ys(t,xl("metadata"),e[3]),Mu=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},kl=(e,t,n,r,i,s)=>{for(var o,a,l,u,c=t&7,d=!1,h=!1,f=2,g=wl[c+5],v=e[f]||(e[f]=[]),w=(i=i.prototype,$u(i,n)),x=r.length-1;x>=0;x--)l=Cu(c,n,a={},e[3],v),l.static=d,l.private=h,u=l.access={has:m=>n in m},u.get=m=>m[n],o=(0,r[x])(w[g],l),a._=1,_l(o)&&(w[g]=o);return w&&bl(i,n,w),i},Sl=(e,t,n)=>t.has(e)||Pi("Cannot "+n),Iu=(e,t,n)=>(Sl(e,t,"read from private field"),t.get(e)),ju=(e,t,n)=>t.has(e)?Pi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Au=(e,t,n,r)=>(Sl(e,t,"write to private field"),t.set(e,n),n),Ze=class bs{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new bs(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new bs(t,n)}},dt=class jt{constructor(t,n,r,i){this.left=t,this.top=n,this.width=r,this.height=i,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:i,width:s,height:o,scale:a}=this,l=new jt(i+t,r+n,s,o);return l.scale=Du({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:i,right:s,bottom:o}=this;return{width:t,height:n,left:r,top:i,right:s,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:i}=this;return new Ze((t+r)/2,(n+i)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof jt))return!1;const{left:n,top:r,width:i,height:s}=this;return n===t.left&&r===t.top&&i===t.width&&s===t.height}containsPoint(t){const{top:n,left:r,bottom:i,right:s}=this;return n<=t.y&&t.y<=i&&r<=t.x&&t.x<=s}intersectionArea(t){return t instanceof jt?Ru(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:i}){return new jt(n,t,r,i)}static delta(t,n,r={x:"center",y:"center"}){const i=(s,o)=>{const a=r[o],l=o==="x"?s.left:s.top,u=o==="x"?s.width:s.height;return a=="start"?l:a=="end"?l+u:l+u/2};return Ze.delta({x:i(t,"x"),y:i(t,"y")},{x:i(n,"x"),y:i(n,"y")})}static intersectionRatio(t,n){return jt.from(t).intersectionRatio(jt.from(n))}};function Ru(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),o=i-r,a=s-n;return r<i&&n<s?o*a:0}var $l,El,xs,Xr,Er,Mi=class extends(xs=Kt,El=[pe],$l=[pe],xs){constructor(t){const n=Ze.from(t);super(n,(r,i)=>Ze.equals(r,i)),Mu(Er,5,this),ju(this,Xr,0),this.velocity={x:0,y:0}}get delta(){return Ze.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Ze.from(t),i={x:r.x-n.x,y:r.y-n.y},s=Date.now(),o=s-Iu(this,Xr),a=l=>Math.round(l/o*100);de(()=>{Au(this,Xr,s),this.velocity={x:a(i.x),y:a(i.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Ze.from(t)),this.velocity={x:0,y:0}}};Er=Tu(xs);Xr=new WeakMap;kl(Er,2,"delta",El,Mi);kl(Er,2,"direction",$l,Mi);Pu(Er,Mi);function ws({x:e,y:t},n){const r=Math.abs(e),i=Math.abs(t);return typeof n=="number"?Math.sqrt(ua(r,2)+ua(i,2))>n:"x"in n&&"y"in n?r>n.x&&i>n.y:"x"in n?r>n.x:"y"in n?i>n.y:!1}var Ol=(e=>(e.Horizontal="x",e.Vertical="y",e))(Ol||{}),Dl=Object.values(Ol),Lu=Object.create,oo=Object.defineProperty,Wu=Object.defineProperties,zu=Object.getOwnPropertyDescriptor,Fu=Object.getOwnPropertyDescriptors,hi=Object.getOwnPropertySymbols,Tl=Object.prototype.hasOwnProperty,Cl=Object.prototype.propertyIsEnumerable,Pl=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Cn=e=>{throw TypeError(e)},_s=(e,t,n)=>t in e?oo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ao=(e,t)=>{for(var n in t||(t={}))Tl.call(t,n)&&_s(e,n,t[n]);if(hi)for(var n of hi(t))Cl.call(t,n)&&_s(e,n,t[n]);return e},lo=(e,t)=>Wu(e,Fu(t)),fa=(e,t)=>oo(e,"name",{value:t,configurable:!0}),Ml=(e,t)=>{var n={};for(var r in e)Tl.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&hi)for(var r of hi(e))t.indexOf(r)<0&&Cl.call(e,r)&&(n[r]=e[r]);return n},Pn=e=>{var t;return[,,,Lu((t=e?.[Pl("metadata")])!=null?t:null)]},Il=["class","method","getter","setter","accessor","field","value","get","set"],Kn=e=>e!==void 0&&typeof e!="function"?Cn("Function expected"):e,Nu=(e,t,n,r,i)=>({kind:Il[e],name:t,metadata:r,addInitializer:s=>n._?Cn("Already initialized"):i.push(Kn(s||null))}),Yt=(e,t)=>_s(t,Pl("metadata"),e[3]),N=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},q=(e,t,n,r,i,s)=>{var o,a,l,u,c,d=t&7,h=!!(t&8),f=!!(t&16),g=d>3?e.length+1:d?h?1:2:0,v=Il[d+5],w=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),m=d&&(!f&&!h&&(i=i.prototype),d<5&&(d>3||!f)&&zu(d<4?i:{get[n](){return he(this,s)},set[n](b){return qe(this,s,b)}},n));d?f&&d<4&&fa(s,(d>2?"set ":d>1?"get ":"")+n):fa(i,n);for(var p=r.length-1;p>=0;p--)u=Nu(d,n,l={},e[3],x),d&&(u.static=h,u.private=f,c=u.access={has:f?b=>Bu(i,b):b=>n in b},d^3&&(c.get=f?b=>(d^1?he:jl)(b,i,d^4?s:m.get):b=>b[n]),d>2&&(c.set=f?(b,_)=>qe(b,i,_,d^4?s:m.set):(b,_)=>b[n]=_)),a=(0,r[p])(d?d<4?f?s:m[v]:d>4?void 0:{get:m.get,set:m.set}:i,u),l._=1,d^4||a===void 0?Kn(a)&&(d>4?w.unshift(a):d?f?s=a:m[v]=a:i=a):typeof a!="object"||a===null?Cn("Object expected"):(Kn(o=a.get)&&(m.get=o),Kn(o=a.set)&&(m.set=o),Kn(o=a.init)&&w.unshift(o));return d||Yt(e,i),m&&oo(i,n,m),f?d^4?s:m:i},co=(e,t,n)=>t.has(e)||Cn("Cannot "+n),Bu=(e,t)=>Object(t)!==t?Cn('Cannot use the "in" operator on this value'):e.has(t),he=(e,t,n)=>(co(e,t,"read from private field"),n?n.call(e):t.get(e)),J=(e,t,n)=>t.has(e)?Cn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qe=(e,t,n,r)=>(co(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),jl=(e,t,n)=>(co(e,t,"access private method"),n);function Al(e,t){return{plugin:e,options:t}}function Or(e){return t=>Al(e,t)}function gr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Rl,vr,uo,Qr;Rl=[H];var Pe=class{constructor(e,t){this.manager=e,this.options=t,J(this,uo,N(vr,8,this,!1)),N(vr,11,this),J(this,Qr,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return U(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=tt(e.bind(this));return he(this,Qr).add(t),t}destroy(){he(this,Qr).forEach(e=>e())}static configure(e){return Al(this,e)}};vr=Pn(null);uo=new WeakMap;Qr=new WeakMap;q(vr,4,"disabled",Rl,Pe,uo);Yt(vr,Pe);var Dr=class extends Pe{},Zr,Qi=class{constructor(e){this.manager=e,this.instances=new Map,J(this,Zr,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(gr).reduce((r,i)=>{const s=r.find(({plugin:o})=>o===i.plugin);return s?(s.options=i.options,r):[...r,i]},[]),n=t.map(({plugin:r})=>r);for(const r of he(this,Zr))if(!n.includes(r)){if(r.prototype instanceof Dr)continue;this.unregister(r)}for(const{plugin:r,options:i}of t)this.register(r,i);qe(this,Zr,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};Zr=new WeakMap;function Vu(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Wr=[],an,ln,Gu=class extends Pe{constructor(e){super(e),J(this,an),J(this,ln),this.computeCollisions=this.computeCollisions.bind(this),qe(this,ln,En(Wr)),this.destroy=$r(()=>{const t=this.computeCollisions(),n=U(()=>this.manager.dragOperation.position.current);if(t!==Wr){const r=he(this,an);if(qe(this,an,n),r&&n.x==r.x&&n.y==r.y)return}else qe(this,an,void 0);he(this,ln).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){U(()=>{e?he(this,ln).value=this.computeCollisions():qe(this,an,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:i,shape:s,status:o}=r;if(!o.initialized||!s)return Wr;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||i&&!u.accepts(i))continue;const c=t??u.collisionDetector;if(!c)continue;l.push(u),u.shape;const d=U(()=>c({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return l.length===0?Wr:(a.sort(Vu),a)}get collisions(){return he(this,ln).value}};an=new WeakMap;ln=new WeakMap;var Ll,Wl,zl,fo,Fl,it,ho,pn,po,go;zl=[H],Wl=[H],Ll=[H];var yt=class At{constructor(t,n){J(this,ho,N(it,8,this)),N(it,11,this),J(this,pn),J(this,po,N(it,12,this)),N(it,15,this),J(this,go,N(it,16,this)),N(it,19,this);const{effects:r,id:i,data:s={},disabled:o=!1,register:a=!0}=t;let l=i;qe(this,pn,En(i)),this.manager=n,this.data=s,this.disabled=o,this.effects=()=>{var u;return[()=>{const{id:c,manager:d}=this;if(c!==l)return l=c,d?.registry.register(this),()=>d?.registry.unregister(this)},...(u=r?.())!=null?u:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),n&&a&&queueMicrotask(this.register)}get id(){var t,n;const r=he(this,pn).value;return(n=(t=At.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const i=(r=(n=At.pendingIdChanges)==null?void 0:n.get(this))!=null?r:he(this,pn).peek();t!==i&&(At.pendingIdChanges||(At.pendingIdChanges=new Map,queueMicrotask(()=>{var s;return jl(s=At,fo,Fl).call(s)})),At.pendingIdChanges.set(this,t))}register(){var t;return(t=this.manager)==null?void 0:t.registry.register(this)}unregister(){var t;(t=this.manager)==null||t.registry.unregister(this)}destroy(){var t;(t=this.manager)==null||t.registry.unregister(this)}};it=Pn(null);fo=new WeakSet;Fl=function(){const e=yt.pendingIdChanges;yt.pendingIdChanges=null,e&&de(()=>{for(const[t,n]of e)he(t,pn).value=n})};ho=new WeakMap;pn=new WeakMap;po=new WeakMap;go=new WeakMap;q(it,4,"manager",zl,yt,ho);q(it,4,"data",Wl,yt,po);q(it,4,"disabled",Ll,yt,go);J(yt,fo);Yt(it,yt);yt.pendingIdChanges=null;var Ii=yt,ha=class{constructor(){this.map=En(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),i=()=>this.unregister(e,t);if(r===t)return i;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const s=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){s.delete(a);break}s.set(e,t),this.map.value=s;const o=$r(...t.effects());return this.cleanupFunctions.set(t,o),i},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const i=new Map(n);i.delete(e),this.map.value=i}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Nl,Bl,Vl,Gl,Ul,Hl,ks,je,vo,mo,yo,ut=class extends(ks=Ii,Hl=[H],Ul=[H],Gl=[H],Vl=[pe],Bl=[pe],Nl=[pe],ks){constructor(t,n){var r=t,{modifiers:i,type:s,sensors:o,plugins:a,effects:l}=r,u=Ml(r,["modifiers","type","sensors","plugins","effects"]);super(lo(ao({},u),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:d,plugins:h}=this;if(!(!d||!h))for(const f of h){const{plugin:g}=gr(f);d.registry.plugins.register(g)}}]}}),n),N(je,5,this),J(this,vo,N(je,8,this)),N(je,11,this),J(this,mo,N(je,12,this)),N(je,15,this),J(this,yo,N(je,16,this,this.isDragSource?"dragging":"idle")),N(je,19,this),this.type=s,this.sensors=o,this.modifiers=i,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=gr(n);if(r.plugin===t)return r.options}}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};je=Pn(ks);vo=new WeakMap;mo=new WeakMap;yo=new WeakMap;q(je,4,"type",Hl,ut,vo);q(je,4,"modifiers",Ul,ut,mo);q(je,4,"status",Gl,ut,yo);q(je,2,"isDropping",Vl,ut);q(je,2,"isDragging",Bl,ut);q(je,2,"isDragSource",Nl,ut);Yt(je,ut);var ql,Kl,Yl,Xl,Ql,Zl,Ss,xe,bo,xo,wo,_o,ko,ft=class extends(Ss=Ii,Zl=[H],Ql=[H],Xl=[H],Yl=[H],Kl=[H],ql=[pe],Ss){constructor(t,n){var r=t,{accept:i,collisionDetector:s,collisionPriority:o,type:a}=r,l=Ml(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),N(xe,5,this),J(this,bo,N(xe,8,this)),N(xe,11,this),J(this,xo,N(xe,12,this)),N(xe,15,this),J(this,wo,N(xe,16,this)),N(xe,19,this),J(this,_o,N(xe,20,this)),N(xe,23,this),J(this,ko,N(xe,24,this)),N(xe,27,this),this.accept=i,this.collisionDetector=s,this.collisionPriority=o,this.type=a}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};xe=Pn(Ss);bo=new WeakMap;xo=new WeakMap;wo=new WeakMap;_o=new WeakMap;ko=new WeakMap;q(xe,4,"accept",Zl,ft,bo);q(xe,4,"type",Ql,ft,xo);q(xe,4,"collisionDetector",Xl,ft,wo);q(xe,4,"collisionPriority",Yl,ft,_o);q(xe,4,"shape",Kl,ft,ko);q(xe,2,"isDropTarget",ql,ft);Yt(xe,ft);var Uu=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const i of r)i(...t)}},Hu=class extends Uu{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function Jr(e,t=!0){let n=!1;return lo(ao({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var qu=class extends Dr{constructor(e){super(e);const t=(r,i)=>r.map(({id:s})=>s).join("")===i.map(({id:s})=>s).join("");let n=[];this.destroy=$r(()=>{const{dragOperation:r,collisionObserver:i}=e;r.status.initializing&&(n=[],i.enable())},()=>{const{collisionObserver:r,monitor:i}=e,{collisions:s}=r;if(r.isDisabled()||Ii.pendingIdChanges)return;const o=Jr({collisions:s});if(i.dispatch("collision",o),o.defaultPrevented||t(s,n))return;n=s;const[a]=s;U(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},Mn=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Mn||{}),In=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(In||{}),Jl,ec,tc,nc,rc,ic,sc,et,So;sc=[H],ic=[pe],rc=[pe],nc=[pe],tc=[pe],ec=[pe],Jl=[pe];var bt=class{constructor(){N(et,5,this),J(this,So,N(et,8,this,"idle")),N(et,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};et=Pn(null);So=new WeakMap;q(et,4,"value",sc,bt,So);q(et,2,"current",ic,bt);q(et,2,"idle",rc,bt);q(et,2,"initializing",nc,bt);q(et,2,"initialized",tc,bt);q(et,2,"dragging",ec,bt);q(et,2,"dropped",Jl,bt);Yt(et,bt);var Ku=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return U(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=Jr({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return U(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:i,coordinates:s}=e;de(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=i??null,t.position.reset(s)});const o=Jr({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:a}=t;a.current==="initializing"&&de(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:i,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return U(()=>{var t,n;const{dragOperation:r}=this.manager,{status:i,controller:s}=r;if(!i.dragging||!s||s.signal.aborted)return;const o=Jr({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var a,l,u,c,d;if(o.defaultPrevented)return;const h=(d=e.to)!=null?d:{x:r.position.current.x+((l=(a=e.by)==null?void 0:a.x)!=null?l:0),y:r.position.current.y+((c=(u=e.by)==null?void 0:u.y)!=null?c:0)};r.position.current=h})})}stop(e={}){return U(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:i}=r;if(!i||i.signal.aborted)return;let s;const o=()=>{const l={resume:()=>{},abort:()=>{}};return s=new Promise((u,c)=>{l.resume=u,l.abort=c}),l};i.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=U(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),u=()=>{r.controller===i&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,d=tt(()=>{c?.status==="idle"&&(d(),u())})}else this.manager.renderer.rendering.then(u)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),s?s.then(a).catch(()=>r.reset()):a()})}},bn=class extends Pe{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Yu=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},ei,oc=class{constructor(e){this.options=e,J(this,ei)}set controller(e){qe(this,ei,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=he(this,ei))==null||t.activate(e)}};ei=new WeakMap;var pa=class extends Pe{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Xu=class{constructor(e){this.draggables=new ha,this.droppables=new ha,this.plugins=new Qi(e),this.sensors=new Qi(e),this.modifiers=new Qi(e)}register(e,t){if(e instanceof ut)return this.draggables.register(e.id,e);if(e instanceof ft)return this.droppables.register(e.id,e);if(e.prototype instanceof pa)return this.modifiers.register(e,t);if(e.prototype instanceof bn)return this.sensors.register(e,t);if(e.prototype instanceof Pe)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Ii)return e instanceof ut?this.draggables.unregister(e.id,e):e instanceof ft?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof pa)return this.modifiers.unregister(e);if(e.prototype instanceof bn)return this.sensors.unregister(e);if(e.prototype instanceof Pe)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},ac,lc,cc,dc,uc,fc,hc,pc,gc,Yn,ti,cn,le,$o,Eo,Oo,Do,To,Xn;gc=[pe],pc=[H],hc=[H],fc=[H],uc=[H],dc=[H],cc=[pe],lc=[pe],ac=[pe];var ot=class{constructor(e){N(le,5,this),J(this,Yn),J(this,ti),J(this,cn,new Kt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new bt,J(this,$o,N(le,8,this,!1)),N(le,11,this),J(this,Eo,N(le,12,this,null)),N(le,15,this),J(this,Oo,N(le,16,this,null)),N(le,19,this),J(this,Do,N(le,20,this,null)),N(le,23,this),J(this,To,N(le,24,this,[])),N(le,27,this),this.position=new Mi({x:0,y:0}),J(this,Xn,{x:0,y:0}),qe(this,Yn,e)}get shape(){const{current:e,initial:t,previous:n}=he(this,cn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?he(this,cn).current=e:he(this,cn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=he(this,Yn).registry.draggables.get(t);return n&&qe(this,ti,n),(e=n??he(this,ti))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=he(this,Yn).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(lo(ao({},this.snapshot()),{transform:n}));return qe(this,Xn,n),n}snapshot(){return U(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:he(this,Xn),shape:this.shape?Xi(this.shape):null,position:Xi(this.position),status:Xi(this.status),canceled:this.canceled}))}reset(){de(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,he(this,cn).reset(),this.position.reset({x:0,y:0}),qe(this,Xn,{x:0,y:0}),this.modifiers=[]})}};le=Pn(null);Yn=new WeakMap;ti=new WeakMap;cn=new WeakMap;$o=new WeakMap;Eo=new WeakMap;Oo=new WeakMap;Do=new WeakMap;To=new WeakMap;Xn=new WeakMap;q(le,2,"shape",gc,ot);q(le,4,"canceled",pc,ot,$o);q(le,4,"activatorEvent",hc,ot,Eo);q(le,4,"sourceIdentifier",fc,ot,Oo);q(le,4,"targetIdentifier",uc,ot,Do);q(le,4,"modifiers",dc,ot,To);q(le,2,"source",cc,ot);q(le,2,"target",lc,ot);q(le,2,"transform",ac,ot);Yt(le,ot);var Qu={get rendering(){return Promise.resolve()}};function st(e,t){return typeof e=="function"?e(t):e??t}var Zu=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(h=>h.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},i=st(r.plugins,[]),s=st(r.sensors,[]),o=st(r.modifiers,[]),a=(n=r.renderer)!=null?n:Qu,l=new Hu(this),u=new Xu(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new Ku(this),this.dragOperation=new ot(this),this.collisionObserver=new Gu(this),this.plugins=[qu,...i],this.modifiers=o,this.sensors=s;const{destroy:c}=this,d=$r(()=>{var h,f,g;const v=U(()=>this.dragOperation.modifiers),w=this.modifiers;for(const x of v)w.includes(x)||x.destroy();this.dragOperation.modifiers=(g=(f=(h=this.dragOperation.source)==null?void 0:h.modifiers)==null?void 0:f.map(x=>{const{plugin:m,options:p}=gr(x);return new m(this,p)}))!=null?g:w});this.destroy=()=>{d(),c()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},vc=e=>{throw TypeError(e)},Co=(e,t,n)=>t.has(e)||vc("Cannot "+n),F=(e,t,n)=>(Co(e,t,"read from private field"),t.get(e)),Ne=(e,t,n)=>t.has(e)?vc("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),He=(e,t,n,r)=>(Co(e,t,"write to private field"),t.set(e,n),n),mc=(e,t,n)=>(Co(e,t,"access private method"),n);function ji(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function yc(e,t){const n=e.getAnimations();let r=null;for(const i of n){if(i.playState!=="running")continue;const{effect:s}=i,a=(ji(s)?s.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],i])}return r}function Ai(e){const{width:t,height:n,top:r,left:i,bottom:s,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:i,bottom:s,right:o}}function Po(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Tr(e){return"nodeType"in e}function Ke(e){var t,n,r;return e?Po(e)?e:Tr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function Mo(e){const{Document:t}=Ke(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Dt(e){return!e||Po(e)?!1:e instanceof Ke(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function bc(e){return e instanceof Ke(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function jn(e){return e?Po(e)?e.document:Tr(e)?Mo(e)?e:Dt(e)||bc(e)?e.ownerDocument:document:document:document}function Ju(e){var t,n,r,i;const{documentElement:s}=jn(e),o=Ke(e).visualViewport,a=(t=o?.width)!=null?t:s.clientWidth,l=(n=o?.height)!=null?n:s.clientHeight,u=(r=o?.offsetTop)!=null?r:0,c=(i=o?.offsetLeft)!=null?i:0;return{top:u,left:c,right:c+a,bottom:u+l,width:a,height:l}}function ef(e,t){if(tf(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:i}=getComputedStyle(e);return n==="visible"&&r==="visible"&&i==="visible"}function tf(e){return e.tagName==="DETAILS"}function mr(e,t=e.getBoundingClientRect(),n=0){var r,i,s,o,a;let l=t;const{ownerDocument:u}=e,c=(r=u.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==u.documentElement;){if(!ef(d)){const p=d.getBoundingClientRect(),b=n*(p.bottom-p.top),_=n*(p.right-p.left),$=n*(p.bottom-p.top),O=n*(p.right-p.left);l={top:Math.max(l.top,p.top-b),right:Math.min(l.right,p.right+_),bottom:Math.min(l.bottom,p.bottom+$),left:Math.max(l.left,p.left-O),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const h=c.visualViewport,f=(i=h?.offsetTop)!=null?i:0,g=(s=h?.offsetLeft)!=null?s:0,v=(o=h?.width)!=null?o:c.innerWidth,w=(a=h?.height)!=null?a:c.innerHeight,x=n*w,m=n*v;return l={top:Math.max(l.top,f-x),right:Math.min(l.right,g+v+m),bottom:Math.min(l.bottom,f+w+x),left:Math.max(l.left,g-m),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function xn(e){return{x:e.clientX,y:e.clientY}}var xc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function $s(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const i=r.contentDocument;i&&!t.has(i)&&n.push(...$s(i,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const i=r.parent;i&&i.document&&i.document!==e&&n.push(...$s(i.document,t))}}catch{}return n}function Io(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function wc(){var e,t;const n=Io()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function jo(e){return!e||!Tr(e)?!1:e instanceof Ke(e).ShadowRoot}function pi(e){if(e&&Tr(e)){let t=e.getRootNode();if(jo(t))return t;if(t instanceof Document)return t}return jn(e)}function Ao(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function nf(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((s,o)=>{const a=r[o];if(ga(s)&&ga(a)&&(s.type!=="file"&&(s.value=a.value),s.type==="radio"&&s.name&&(s.name=`Cloned__${s.name}`)),va(s)&&va(a)&&a.width>0&&a.height>0){const l=s.getContext("2d");l?.drawImage(a,0,0)}}),n}function ga(e){return"value"in e}function va(e){return e.tagName==="CANVAS"}function _c(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(rf(r)){const{contentDocument:i}=r;if(i){const{left:s,top:o}=r.getBoundingClientRect();return _c(i,{x:t-s,y:n-o})}}return r}function rf(e){return e?.tagName==="IFRAME"}var Es=new WeakMap;function sf(e){return e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),
5
5
  button:not([disabled]),
6
6
  a[href],
7
7
  [contenteditable]:not([contenteditable="false"])
8
- `)}var uc=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:l,listener:d,options:u}=a,c=[o,a];o.addEventListener(l,d,u),this.entries.add(c),i.push(c)}const s=this.entries;return function(){for(const a of i){const[l,{type:d,listener:u,options:c}]=a;l.removeEventListener(d,u,c),s.delete(a)}}}};function mn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Wu(e){const t=new Set;let n=mn(e);for(;n;)t.add(n),n=mn(n);return t}function Fu(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function fc(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=Fu(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function Bu(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function Nu(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ur(e,t);return n>0&&r>0}var Gu=lc?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},Yr,Vu=class extends Gu{constructor(e){super(t=>{if(!B(this,Yr)){Ge(this,Yr,!0);return}e(t,this)}),Re(this,Yr,!1)}};Yr=new WeakMap;var aa=Array.from({length:100},(e,t)=>t/100),hc=75,It,li,xt,jt,Hn,ke,ir,Kn,ci,pc,gc,vc=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Re(this,ci),this.disconnect=()=>{var s,o,a;Ge(this,ir,!0),(s=B(this,xt))==null||s.disconnect(),(o=B(this,jt))==null||o.disconnect(),B(this,Hn).disconnect(),(a=B(this,ke))==null||a.remove()},Re(this,It,!0),Re(this,li),Re(this,xt),Re(this,jt),Re(this,Hn),Re(this,ke),Re(this,ir,!1),Re(this,Kn,fc(()=>{var s,o,a;const{element:l}=this;if((s=B(this,jt))==null||s.disconnect(),B(this,ir)||!B(this,It)||!l.isConnected)return;const d=(o=l.ownerDocument)!=null?o:document,{innerHeight:u,innerWidth:c}=(a=d.defaultView)!=null?a:window,h=l.getBoundingClientRect(),f=ur(l,h),{top:g,left:m,bottom:w,right:b}=f,v=-Math.floor(g),p=-Math.floor(m),x=-Math.floor(c-b),_=-Math.floor(u-w),O=`${v}px ${x}px ${_}px ${p}px`;this.boundingClientRect=h,Ge(this,jt,new IntersectionObserver(T=>{const[E]=T,{intersectionRect:I}=E;(E.intersectionRatio!==1?E.intersectionRatio:lt.intersectionRatio(I,ur(l)))!==1&&B(this,Kn).call(this)},{threshold:aa,rootMargin:O,root:d})),B(this,jt).observe(l),sc(this,ci,pc).call(this)},hc)),this.boundingClientRect=e.getBoundingClientRect(),Ge(this,It,Nu(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(Ge(this,ke,document.createElement("div")),B(this,ke).style.background="rgba(0,0,0,0.15)",B(this,ke).style.position="fixed",B(this,ke).style.pointerEvents="none",i.body.appendChild(B(this,ke))),Ge(this,Hn,new IntersectionObserver(s=>{var o,a;const l=s[s.length-1],{boundingClientRect:d,isIntersecting:u}=l,{width:c,height:h}=d,f=B(this,It);Ge(this,It,u),!(!c&&!h)&&(f&&!u?((o=B(this,jt))==null||o.disconnect(),this.callback(null),(a=B(this,xt))==null||a.disconnect(),Ge(this,xt,void 0),B(this,ke)&&(B(this,ke).style.visibility="hidden")):B(this,Kn).call(this),u&&!B(this,xt)&&(Ge(this,xt,new Vu(B(this,Kn))),B(this,xt).observe(e)))},{threshold:aa,root:i})),B(this,It)&&!n.skipInitial&&this.callback(this.boundingClientRect),B(this,Hn).observe(e)}};It=new WeakMap;li=new WeakMap;xt=new WeakMap;jt=new WeakMap;Hn=new WeakMap;ke=new WeakMap;ir=new WeakMap;Kn=new WeakMap;ci=new WeakSet;pc=function(){B(this,ir)||(sc(this,ci,gc).call(this),!Bu(this.boundingClientRect,B(this,li))&&(this.callback(this.boundingClientRect),Ge(this,li,this.boundingClientRect)))};gc=function(){if(B(this,ke)){const{top:e,left:t,width:n,height:r}=ur(this.element);B(this,ke).style.overflow="hidden",B(this,ke).style.visibility="visible",B(this,ke).style.top=`${Math.floor(e)}px`,B(this,ke).style.left=`${Math.floor(t)}px`,B(this,ke).style.width=`${Math.floor(n)}px`,B(this,ke).style.height=`${Math.floor(r)}px`}};var Ir=new WeakMap,jr=new WeakMap;function Hu(e,t){let n=Ir.get(e);return n||(n={disconnect:new vc(e,i=>{const s=Ir.get(e);s&&s.callbacks.forEach(o=>o(i))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Ir.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Ir.delete(e),n.disconnect())}}function Ku(e,t){const n=new Set;for(const r of e){const i=Hu(r,t);n.add(i)}return()=>n.forEach(r=>r())}function qu(e,t){var n;const r=e.ownerDocument;if(!jr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(d=>d(l)),{capture:!0,passive:!0,signal:o.signal}),jr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=jr.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),jr.delete(r))})}var qn,Un,Zr,xs,Uu=class{constructor(e,t,n){this.callback=t,Re(this,qn),Re(this,Un,!1),Re(this,Zr),Re(this,xs,fc(o=>{if(!B(this,Un)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of B(this,Zr))if(o.target.contains(a)){this.callback(B(this,qn).boundingClientRect);break}}},hc));const r=Wu(e),i=Ku(r,t),s=qu(e,B(this,xs));Ge(this,Zr,r),Ge(this,qn,new vc(e,t,n)),this.disconnect=()=>{B(this,Un)||(Ge(this,Un,!0),i(),s(),B(this,qn).disconnect())}}};qn=new WeakMap;Un=new WeakMap;Zr=new WeakMap;xs=new WeakMap;function _s(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function fn(e){try{_s(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function la(e){return!lc||!e?!1:e===Pn(e).scrollingElement}function mc(e){var t,n;const r=He(e),i=la(e)?Iu(e):Di(e),s=r.visualViewport,o=la(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},l=a.current.y<=0,d=a.current.x<=0,u=a.current.y>=a.max.y,c=a.current.x>=a.max.x;return{rect:i,position:a,isTop:l,isLeft:d,isBottom:u,isRight:c}}function Xu(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=mc(e),{x:a,y:l}=t??{x:0,y:0},d=!n&&o.current.y+l>0,u=!r&&o.current.y+l<o.max.y,c=!i&&o.current.x+a>0,h=!s&&o.current.x+a<o.max.x;return{top:d,bottom:u,left:c,right:h,x:c||h,y:d||u}}var Eo=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const i of n)i();for(const i of r)i()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},di=new Eo(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Yu=new Eo(e=>setTimeout(e,50)),ui=new Map,Zu=ui.clear.bind(ui);function ut(e,t=!1){if(!t)return ca(e);let n=ui.get(e);return n||(n=ca(e),ui.set(e,n),Yu.schedule(Zu),n)}function ca(e){return He(e).getComputedStyle(e)}function Qu(e,t=ut(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Ju(e,t=ut(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(i=>{const s=t[i];return typeof s=="string"?n.test(s):!1})}var ef={excludeElement:!0,escapeShadowDOM:!0};function ws(e,t=ef){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(So(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&Oo(a))return o(a.host);if(!Tt(a))return ac(a)?o(a.parentElement):s;if(s.has(a))return s;const l=ut(a,!0);if(r&&a===e||Ju(a,l)&&s.add(a),Qu(a,l)){const{scrollingElement:d}=a.ownerDocument;return d&&s.add(d),s}return o(a.parentNode)}return e?o(e):s}function yn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=mn(e);for(;r;){if(r===t)return n;const i=Di(r),{x:s,y:o}=tf(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=mn(r)}return n}function tf(e,t=Di(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Tt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=ut(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function nf(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function fr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),i={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(i.x)&&isNaN(i.y)?null:{x:isNaN(i.x)?0:i.x,y:isNaN(i.y)?0:i.y,z:isNaN(i.z)?0:i.z}}function Pi(e){var t,n,r,i,s,o,a,l,d;const{scale:u,transform:c,translate:h}=e,f=nf(u),g=fr(h),m=rf(c);if(!m&&!f&&!g)return null;const w={x:(t=f?.x)!=null?t:1,y:(n=f?.y)!=null?n:1},b={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},v={x:(s=m?.x)!=null?s:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(l=m?.scaleY)!=null?l:1};return{x:b.x+v.x,y:b.y+v.y,z:(d=g?.z)!=null?d:0,scaleX:w.x*v.scaleX,scaleY:w.y*v.scaleY}}function rf(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var Ye=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(Ye||{}),sf={x:.2,y:.2},of={x:10,y:10};function af(e,t,n,r=25,i=sf,s=of){const{x:o,y:a}=t,{rect:l,isTop:d,isBottom:u,isLeft:c,isRight:h}=mc(e),f=yn(e),g=ut(e,!0),m=Pi(g),w=m!==null?m?.scaleX<0:!1,b=m!==null?m?.scaleY<0:!1,v=new lt(l.left*f.scaleX+f.x,l.top*f.scaleY+f.y,l.width*f.scaleX,l.height*f.scaleY),p={x:0,y:0},x={x:0,y:0},_={height:v.height*i.y,width:v.width*i.x};return _.height>0&&(!d||b&&!u)&&a<=v.top+_.height&&n?.y!==1&&o>=v.left-s.x&&o<=v.right+s.x?(p.y=b?1:-1,x.y=r*Math.abs((v.top+_.height-a)/_.height)):_.height>0&&(!u||b&&!d)&&a>=v.bottom-_.height&&n?.y!==-1&&o>=v.left-s.x&&o<=v.right+s.x&&(p.y=b?-1:1,x.y=r*Math.abs((v.bottom-_.height-a)/_.height)),_.width>0&&(!h||w&&!c)&&o>=v.right-_.width&&n?.x!==-1&&a>=v.top-s.y&&a<=v.bottom+s.y?(p.x=w?-1:1,x.x=r*Math.abs((v.right-_.width-o)/_.width)):_.width>0&&(!c||w&&!h)&&o<=v.left+_.width&&n?.x!==1&&a>=v.top-s.y&&a<=v.bottom+s.y&&(p.x=w?1:-1,x.x=r*Math.abs((v.left+_.width-o)/_.width)),{direction:p,speed:x}}function yc(e,{block:t="nearest",inline:n="nearest"}={}){if(!Tt(e))return;const r=ws(e),i=[];for(const s of r){if(!Tt(s))continue;const{top:o,left:a}=lf(e,s);let l=o,d=a;for(const u of i)l-=u.scrollTop,d-=u.scrollLeft;if(t!=="none"){const u=l<s.scrollTop,c=l+e.offsetHeight>s.scrollTop+s.clientHeight;u!==c&&(t==="center"?s.scrollTop=l-s.clientHeight/2+e.offsetHeight/2:u?s.scrollTop=l:s.scrollTop=l+e.offsetHeight-s.clientHeight)}if(n!=="none"){const u=d<s.scrollLeft,c=d+e.offsetWidth>s.scrollLeft+s.clientWidth;u!==c&&(n==="center"?s.scrollLeft=d-s.clientWidth/2+e.offsetWidth/2:u?s.scrollLeft=d:s.scrollLeft=d+e.offsetWidth-s.clientWidth)}i.push(s)}}function da(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!Tt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function lf(e,t){const n=da(e),r=da(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function cf(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),l=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width*r:e.width,u=i?e.height*i:e.height;return{width:d,height:u,top:l,right:a+d,bottom:l+u,left:a}}function df(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),l=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?e.width/r:e.width,u=i?e.height/i:e.height;return{width:d,height:u,top:l,right:a+d,bottom:l+u,left:a}}function bc({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function ua(e,t=ut(e).translate,n=!0){if(n){const r=oc(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=fr(i);if(s)return s}}}if(t){const r=fr(t);if(r)return r}return{x:0,y:0,z:0}}var uf=new Eo(e=>setTimeout(e,0)),sr=new Map,ff=sr.clear.bind(sr);function hf(e){const t=e.ownerDocument;let n=sr.get(t);if(n)return n;n=t.getAnimations(),sr.set(t,n),uf.schedule(ff);const r=n.filter(i=>Ei(i.effect)&&i.effect.target===e);return sr.set(e,r),n}function pf(e,t){const n=hf(e).filter(r=>{var i,s;if(Ei(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))!=null?s:!0)return r.effect.getKeyframes().some(l=>{for(const d of t.properties)if(l[d])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var at=class extends lt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=yn(e),ignoreTransforms:a,getBoundingClientRect:l=Di}=t,d=pf(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||$o())&&_.contains(e)}),u=l(e);let{top:c,left:h,width:f,height:g}=u,m;const w=ut(e),b=Pi(w),v={x:(n=b?.scaleX)!=null?n:1,y:(r=b?.scaleY)!=null?r:1},p=gf(e,w);d?.(),b&&(m=df(u,b,w.transformOrigin),(a||p)&&(c=m.top,h=m.left,f=m.width,g=m.height));const x={width:(i=m?.width)!=null?i:f,height:(s=m?.height)!=null?s:g};if(p&&!a&&m){const _=cf(m,p,w.transformOrigin);c=_.top,h=_.left,f=_.width,g=_.height,v.x=p.scaleX,v.y=p.scaleY}o&&(a||(h*=o.scaleX,f*=o.scaleX,c*=o.scaleY,g*=o.scaleY),h+=o.x,c+=o.y),super(h,c,f,g),this.scale=v,this.intrinsicWidth=x.width,this.intrinsicHeight=x.height}};function gf(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=Ei(a.effect)?a.effect.getKeyframes():[],d=l[l.length-1];if(!d)continue;const{transform:u,translate:c,scale:h}=d;typeof u=="string"&&u&&(r=u,o=!0),typeof c=="string"&&c&&(i=c,o=!0),typeof h=="string"&&h&&(s=h,o=!0)}return o?Pi({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function or(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var vf=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(or(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(or(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(or(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ft(e){return e?e instanceof He(e).Element||wr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function hr(e){if(!e)return!1;const{KeyboardEvent:t}=He(e.target);return e instanceof t}function mf(e){if(!e)return!1;const{PointerEvent:t}=He(e.target);return e instanceof t}function yf(e){if(!Ft(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||bf(e)}function bf(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Hi={};function ks(e){const t=Hi[e]==null?0:Hi[e]+1;return Hi[e]=t,`${e}-${t}`}var Do=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=Xe.distance(t.shape.center,n);return{id:r,value:1/i,type:Dn.PointerIntersection,priority:En.High}}return null},xf=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=Xe.distance(t.shape.center,i.current),a=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:a,type:Dn.ShapeIntersection,priority:En.Normal}}return null},xc=e=>{var t;return(t=Do(e))!=null?t:xf(e)},_f=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?lt.from(r.current.boundingRectangle).corners:void 0,a=lt.from(n.shape.boundingRectangle).corners.reduce((l,d,u)=>{var c;return l+Xe.distance(Xe.from(d),(c=s?.[u])!=null?c:i.current)},0)/4;return{id:n.id,value:1/a,type:Dn.Collision,priority:En.Normal}},wf=Object.create,Po=Object.defineProperty,kf=Object.defineProperties,Sf=Object.getOwnPropertyDescriptor,$f=Object.getOwnPropertyDescriptors,fi=Object.getOwnPropertySymbols,_c=Object.prototype.hasOwnProperty,wc=Object.prototype.propertyIsEnumerable,kc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Cn=e=>{throw TypeError(e)},Ss=(e,t,n)=>t in e?Po(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pr=(e,t)=>{for(var n in t||(t={}))_c.call(t,n)&&Ss(e,n,t[n]);if(fi)for(var n of fi(t))wc.call(t,n)&&Ss(e,n,t[n]);return e},Co=(e,t)=>kf(e,$f(t)),fa=(e,t)=>Po(e,"name",{value:t,configurable:!0}),Sc=(e,t)=>{var n={};for(var r in e)_c.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&fi)for(var r of fi(e))t.indexOf(r)<0&&wc.call(e,r)&&(n[r]=e[r]);return n},Mn=e=>{var t;return[,,,wf((t=e?.[kc("metadata")])!=null?t:null)]},$c=["class","method","getter","setter","accessor","field","value","get","set"],Xn=e=>e!==void 0&&typeof e!="function"?Cn("Function expected"):e,Of=(e,t,n,r,i)=>({kind:$c[e],name:t,metadata:r,addInitializer:s=>n._?Cn("Already initialized"):i.push(Xn(s||null))}),Kt=(e,t)=>Ss(t,kc("metadata"),e[3]),pe=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},Je=(e,t,n,r,i,s)=>{var o,a,l,d,u,c=t&7,h=!!(t&8),f=!!(t&16),g=c>3?e.length+1:c?h?1:2:0,m=$c[c+5],w=c>3&&(e[g-1]=[]),b=e[g]||(e[g]=[]),v=c&&(!f&&!h&&(i=i.prototype),c<5&&(c>3||!f)&&Sf(c<4?i:{get[n](){return te(this,s)},set[n](x){return Ce(this,s,x)}},n));c?f&&c<4&&fa(s,(c>2?"set ":c>1?"get ":"")+n):fa(i,n);for(var p=r.length-1;p>=0;p--)d=Of(c,n,l={},e[3],b),c&&(d.static=h,d.private=f,u=d.access={has:f?x=>Tf(i,x):x=>n in x},c^3&&(u.get=f?x=>(c^1?te:Bt)(x,i,c^4?s:v.get):x=>x[n]),c>2&&(u.set=f?(x,_)=>Ce(x,i,_,c^4?s:v.set):(x,_)=>x[n]=_)),a=(0,r[p])(c?c<4?f?s:v[m]:c>4?void 0:{get:v.get,set:v.set}:i,d),l._=1,c^4||a===void 0?Xn(a)&&(c>4?w.unshift(a):c?f?s=a:v[m]=a:i=a):typeof a!="object"||a===null?Cn("Object expected"):(Xn(o=a.get)&&(v.get=o),Xn(o=a.set)&&(v.set=o),Xn(o=a.init)&&w.unshift(o));return c||Kt(e,i),v&&Po(i,n,v),f?c^4?s:v:i},Mo=(e,t,n)=>t.has(e)||Cn("Cannot "+n),Tf=(e,t)=>Object(t)!==t?Cn('Cannot use the "in" operator on this value'):e.has(t),te=(e,t,n)=>(Mo(e,t,"read from private field"),n?n.call(e):t.get(e)),de=(e,t,n)=>t.has(e)?Cn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ce=(e,t,n,r)=>(Mo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Bt=(e,t,n)=>(Mo(e,t,"access private method"),n),ha={role:"button",roleDescription:"draggable"},Ef="dnd-kit-description",Df="dnd-kit-announcement",Pf={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Cf={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Mf(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function If(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function jf(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Af=["dragover","dragmove"],Rf=class extends Ee{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=Ef,announcement:i=Df}={},announcements:s=Cf,screenReaderInstructions:o=Pf,debounce:a=500}=t??{},l=n?`${r}-${n}`:ks(r),d=n?`${i}-${n}`:ks(i);let u,c,h,f;const g=(_=f)=>{!h||!_||h?.nodeValue!==_&&(h.nodeValue=_)},m=()=>di.schedule(g),w=Lf(m,a),b=Object.entries(s).map(([_,O])=>this.manager.monitor.addEventListener(_,(T,E)=>{const I=h;if(!I)return;const D=O?.(T,E);D&&I.nodeValue!==D&&(f=D,Af.includes(_)?w():(m(),w.cancel()))})),v=()=>{let _=[];u?.isConnected||(u=If(l,o.draggable),_.push(u)),c?.isConnected||(c=jf(d),h=document.createTextNode(""),c.appendChild(h),_.push(c)),_.length>0&&document.body.append(..._)},p=new Set;function x(){for(const _ of p)_()}this.registerEffect(()=>{var _;p.clear();for(const O of this.manager.registry.draggables.value){const T=(_=O.handle)!=null?_:O.element;if(T){(!u||!c)&&p.add(v),(!Mf(T)||$o())&&!T.hasAttribute("tabindex")&&p.add(()=>T.setAttribute("tabindex","0")),!T.hasAttribute("role")&&T.tagName.toLowerCase()!=="button"&&p.add(()=>T.setAttribute("role",ha.role)),T.hasAttribute("aria-roledescription")||p.add(()=>T.setAttribute("aria-roledescription",ha.roleDescription)),T.hasAttribute("aria-describedby")||p.add(()=>T.setAttribute("aria-describedby",l));for(const I of["aria-pressed","aria-grabbed"]){const D=String(O.isDragging);T.getAttribute(I)!==D&&p.add(()=>T.setAttribute(I,D))}const E=String(O.disabled);T.getAttribute("aria-disabled")!==E&&p.add(()=>T.setAttribute("aria-disabled",E))}}p.size>0&&di.schedule(x)}),this.destroy=()=>{super.destroy(),u?.remove(),c?.remove(),b.forEach(_=>_())}}};function Lf(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var hi=new Map,Oc,Tc,Ec,Dc,$s,ar,vt,Io,bn,Pc,Cc,Mc,Ic,Et=class extends($s=_r,Dc=[K],Ec=[ce],Tc=[ce],Oc=[ce],$s){constructor(t,n){super(t,n),pe(vt,5,this),de(this,bn),de(this,ar,new Set),de(this,Io,pe(vt,8,this,new Set)),pe(vt,11,this),this.registerEffect(Bt(this,bn,Pc))}register(t){return te(this,ar).add(t),()=>{te(this,ar).delete(t)}}addRoot(t){return H(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{H(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return ai((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return ai((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};vt=Mn($s);ar=new WeakMap;Io=new WeakMap;bn=new WeakSet;Pc=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of te(this,ar))t.push(Bt(this,bn,Cc).call(this,n,r));return()=>{for(const n of t)n()}};Cc=function(e,t){let n=hi.get(e);n||(n=new Map,hi.set(e,n));let r=n.get(t);if(!r){const s=So(e)?Bt(this,bn,Mc).call(this,e,n,t):Bt(this,bn,Ic).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Mc=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const l of a)for(const d of Array.from(l.removedNodes))if(d===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&hi.delete(e)}}};Ic=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(Oo(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&hi.delete(e)}}};Je(vt,4,"additionalRoots",Dc,Et,Io);Je(vt,2,"sourceRoot",Ec,Et);Je(vt,2,"targetRoot",Tc,Et);Je(vt,2,"roots",Oc,Et);Kt(vt,Et);Et.configure=xr(Et);var Ci=Et,zf=class extends Ee{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Ci),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},kr="data-dnd-",Os=`${kr}dropping`,we="--dnd-",ot=`${kr}dragging`,pi=`${kr}placeholder`,Wf=[ot,pi,"popover","aria-pressed","aria-grabbing"],Ff=["view-transition-name"],Bf=`
9
- :is(:root,:host) [${ot}] {
8
+ `)}var kc=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:i}]=e;t.removeEventListener(n,r,i)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],i=[];for(const o of n)for(const a of r){const{type:l,listener:u,options:c}=a,d=[o,a];o.addEventListener(l,u,c),this.entries.add(d),i.push(d)}const s=this.entries;return function(){for(const a of i){const[l,{type:u,listener:c,options:d}]=a;l.removeEventListener(u,c,d),s.delete(a)}}}};function wn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function of(e){const t=new Set;let n=wn(e);for(;n;)t.add(n),n=wn(n);return t}function af(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function Sc(e,t){const n=()=>performance.now();let r,i;return function(...s){const o=this;i?(r?.(),r=af(()=>{e.apply(o,s),i=n()},t-(n()-i))):(e.apply(o,s),i=n())}}function lf(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function cf(e,t=e.getBoundingClientRect()){const{width:n,height:r}=mr(e,t);return n>0&&r>0}var df=xc?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ni,uf=class extends df{constructor(e){super(t=>{if(!F(this,ni)){He(this,ni,!0);return}e(t,this)}),Ne(this,ni,!1)}};ni=new WeakMap;var ma=Array.from({length:100},(e,t)=>t/100),$c=75,Rt,gi,wt,Lt,Qn,De,dr,Zn,vi,Ec,Oc,Dc=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ne(this,vi),this.disconnect=()=>{var s,o,a;He(this,dr,!0),(s=F(this,wt))==null||s.disconnect(),(o=F(this,Lt))==null||o.disconnect(),F(this,Qn).disconnect(),(a=F(this,De))==null||a.remove()},Ne(this,Rt,!0),Ne(this,gi),Ne(this,wt),Ne(this,Lt),Ne(this,Qn),Ne(this,De),Ne(this,dr,!1),Ne(this,Zn,Sc(()=>{var s,o,a;const{element:l}=this;if((s=F(this,Lt))==null||s.disconnect(),F(this,dr)||!F(this,Rt)||!l.isConnected)return;const u=(o=l.ownerDocument)!=null?o:document,{innerHeight:c,innerWidth:d}=(a=u.defaultView)!=null?a:window,h=l.getBoundingClientRect(),f=mr(l,h),{top:g,left:v,bottom:w,right:x}=f,m=-Math.floor(g),p=-Math.floor(v),b=-Math.floor(d-x),_=-Math.floor(c-w),$=`${m}px ${b}px ${_}px ${p}px`;this.boundingClientRect=h,He(this,Lt,new IntersectionObserver(O=>{const[D]=O,{intersectionRect:M}=D;(D.intersectionRatio!==1?D.intersectionRatio:dt.intersectionRatio(M,mr(l)))!==1&&F(this,Zn).call(this)},{threshold:ma,rootMargin:$,root:u})),F(this,Lt).observe(l),mc(this,vi,Ec).call(this)},$c)),this.boundingClientRect=e.getBoundingClientRect(),He(this,Rt,cf(e,this.boundingClientRect));let r=!0;this.callback=s=>{r&&(r=!1,n.skipInitial)||t(s)};const i=e.ownerDocument;n?.debug&&(He(this,De,document.createElement("div")),F(this,De).style.background="rgba(0,0,0,0.15)",F(this,De).style.position="fixed",F(this,De).style.pointerEvents="none",i.body.appendChild(F(this,De))),He(this,Qn,new IntersectionObserver(s=>{var o,a;const l=s[s.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:h}=u,f=F(this,Rt);He(this,Rt,c),!(!d&&!h)&&(f&&!c?((o=F(this,Lt))==null||o.disconnect(),this.callback(null),(a=F(this,wt))==null||a.disconnect(),He(this,wt,void 0),F(this,De)&&(F(this,De).style.visibility="hidden")):F(this,Zn).call(this),c&&!F(this,wt)&&(He(this,wt,new uf(F(this,Zn))),F(this,wt).observe(e)))},{threshold:ma,root:i})),F(this,Rt)&&!n.skipInitial&&this.callback(this.boundingClientRect),F(this,Qn).observe(e)}};Rt=new WeakMap;gi=new WeakMap;wt=new WeakMap;Lt=new WeakMap;Qn=new WeakMap;De=new WeakMap;dr=new WeakMap;Zn=new WeakMap;vi=new WeakSet;Ec=function(){F(this,dr)||(mc(this,vi,Oc).call(this),!lf(this.boundingClientRect,F(this,gi))&&(this.callback(this.boundingClientRect),He(this,gi,this.boundingClientRect)))};Oc=function(){if(F(this,De)){const{top:e,left:t,width:n,height:r}=mr(this.element);F(this,De).style.overflow="hidden",F(this,De).style.visibility="visible",F(this,De).style.top=`${Math.floor(e)}px`,F(this,De).style.left=`${Math.floor(t)}px`,F(this,De).style.width=`${Math.floor(n)}px`,F(this,De).style.height=`${Math.floor(r)}px`}};var zr=new WeakMap,Fr=new WeakMap;function ff(e,t){let n=zr.get(e);return n||(n={disconnect:new Dc(e,i=>{const s=zr.get(e);s&&s.callbacks.forEach(o=>o(i))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),zr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(zr.delete(e),n.disconnect())}}function hf(e,t){const n=new Set;for(const r of e){const i=ff(r,t);n.add(i)}return()=>n.forEach(r=>r())}function pf(e,t){var n;const r=e.ownerDocument;if(!Fr.has(r)){const o=new AbortController,a=new Set;document.addEventListener("scroll",l=>a.forEach(u=>u(l)),{capture:!0,passive:!0,signal:o.signal}),Fr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:i,disconnect:s}=(n=Fr.get(r))!=null?n:{};return!i||!s?()=>{}:(i.add(t),()=>{i.delete(t),i.size===0&&(s(),Fr.delete(r))})}var Jn,er,ri,Os,gf=class{constructor(e,t,n){this.callback=t,Ne(this,Jn),Ne(this,er,!1),Ne(this,ri),Ne(this,Os,Sc(o=>{if(!F(this,er)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of F(this,ri))if(o.target.contains(a)){this.callback(F(this,Jn).boundingClientRect);break}}},$c));const r=of(e),i=hf(r,t),s=pf(e,F(this,Os));He(this,ri,r),He(this,Jn,new Dc(e,t,n)),this.disconnect=()=>{F(this,er)||(He(this,er,!0),i(),s(),F(this,Jn).disconnect())}}};Jn=new WeakMap;er=new WeakMap;ri=new WeakMap;Os=new WeakMap;function Ds(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function vn(e){try{Ds(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function ya(e){return!xc||!e?!1:e===jn(e).scrollingElement}function Tc(e){var t,n;const r=Ke(e),i=ya(e)?Ju(e):Ai(e),s=r.visualViewport,o=ya(e)?{height:(t=s?.height)!=null?t:r.innerHeight,width:(n=s?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},a={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-o.width,y:e.scrollHeight-o.height}},l=a.current.y<=0,u=a.current.x<=0,c=a.current.y>=a.max.y,d=a.current.x>=a.max.x;return{rect:i,position:a,isTop:l,isLeft:u,isBottom:c,isRight:d}}function vf(e,t){const{isTop:n,isBottom:r,isLeft:i,isRight:s,position:o}=Tc(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&o.current.y+l>0,c=!r&&o.current.y+l<o.max.y,d=!i&&o.current.x+a>0,h=!s&&o.current.x+a<o.max.x;return{top:u,bottom:c,left:d,right:h,x:d||h,y:u||c}}var Ro=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const i of n)i();for(const i of r)i()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},mi=new Ro(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),mf=new Ro(e=>setTimeout(e,50)),yi=new Map,yf=yi.clear.bind(yi);function ht(e,t=!1){if(!t)return ba(e);let n=yi.get(e);return n||(n=ba(e),yi.set(e,n),mf.schedule(yf),n)}function ba(e){return Ke(e).getComputedStyle(e)}function bf(e,t=ht(e,!0)){return t.position==="fixed"||t.position==="sticky"}function xf(e,t=ht(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(i=>{const s=t[i];return typeof s=="string"?n.test(s):!1})}var wf={excludeElement:!0,escapeShadowDOM:!0};function Ts(e,t=wf){const{limit:n,excludeElement:r,escapeShadowDOM:i}=t,s=new Set;function o(a){if(n!=null&&s.size>=n||!a)return s;if(Mo(a)&&a.scrollingElement!=null&&!s.has(a.scrollingElement))return s.add(a.scrollingElement),s;if(i&&jo(a))return o(a.host);if(!Dt(a))return bc(a)?o(a.parentElement):s;if(s.has(a))return s;const l=ht(a,!0);if(r&&a===e||xf(a,l)&&s.add(a),bf(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&s.add(u),s}return o(a.parentNode)}return e?o(e):s}function _n(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=wn(e);for(;r;){if(r===t)return n;const i=Ai(r),{x:s,y:o}=_f(r,i);n.x=n.x+i.left,n.y=n.y+i.top,n.scaleX=n.scaleX*s,n.scaleY=n.scaleY*o,r=wn(r)}return n}function _f(e,t=Ai(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Dt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const i=ht(e,!0);return{x:(parseFloat(i.width)||n)/n,y:(parseFloat(i.height)||r)/r}}function kf(e){if(!e||e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function yr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),i={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(i.x)&&isNaN(i.y)?null:{x:isNaN(i.x)?0:i.x,y:isNaN(i.y)?0:i.y,z:isNaN(i.z)?0:i.z}}function Ri(e){var t,n,r,i,s,o,a,l,u;const{scale:c,transform:d,translate:h}=e,f=kf(c),g=yr(h),v=Sf(d);if(!v&&!f&&!g)return null;const w={x:(t=f?.x)!=null?t:1,y:(n=f?.y)!=null?n:1},x={x:(r=g?.x)!=null?r:0,y:(i=g?.y)!=null?i:0},m={x:(s=v?.x)!=null?s:0,y:(o=v?.y)!=null?o:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(l=v?.scaleY)!=null?l:1};return{x:x.x+m.x,y:x.y+m.y,z:(u=g?.z)!=null?u:0,scaleX:w.x*m.scaleX,scaleY:w.y*m.scaleY}}function Sf(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var Je=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(Je||{}),$f={x:.2,y:.2},Ef={x:10,y:10};function Of(e,t,n,r=25,i=$f,s=Ef){const{x:o,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:h}=Tc(e),f=_n(e),g=ht(e,!0),v=Ri(g),w=v!==null?v?.scaleX<0:!1,x=v!==null?v?.scaleY<0:!1,m=new dt(l.left*f.scaleX+f.x,l.top*f.scaleY+f.y,l.width*f.scaleX,l.height*f.scaleY),p={x:0,y:0},b={x:0,y:0},_={height:m.height*i.y,width:m.width*i.x};return _.height>0&&(!u||x&&!c)&&a<=m.top+_.height&&n?.y!==1&&o>=m.left-s.x&&o<=m.right+s.x?(p.y=x?1:-1,b.y=r*Math.abs((m.top+_.height-a)/_.height)):_.height>0&&(!c||x&&!u)&&a>=m.bottom-_.height&&n?.y!==-1&&o>=m.left-s.x&&o<=m.right+s.x&&(p.y=x?-1:1,b.y=r*Math.abs((m.bottom-_.height-a)/_.height)),_.width>0&&(!h||w&&!d)&&o>=m.right-_.width&&n?.x!==-1&&a>=m.top-s.y&&a<=m.bottom+s.y?(p.x=w?-1:1,b.x=r*Math.abs((m.right-_.width-o)/_.width)):_.width>0&&(!d||w&&!h)&&o<=m.left+_.width&&n?.x!==1&&a>=m.top-s.y&&a<=m.bottom+s.y&&(p.x=w?1:-1,b.x=r*Math.abs((m.left+_.width-o)/_.width)),{direction:p,speed:b}}function Cc(e,{block:t="nearest",inline:n="nearest"}={}){if(!Dt(e))return;const r=Ts(e),i=[];for(const s of r){if(!Dt(s))continue;const{top:o,left:a}=Df(e,s);let l=o,u=a;for(const c of i)l-=c.scrollTop,u-=c.scrollLeft;if(t!=="none"){const c=l<s.scrollTop,d=l+e.offsetHeight>s.scrollTop+s.clientHeight;c!==d&&(t==="center"?s.scrollTop=l-s.clientHeight/2+e.offsetHeight/2:c?s.scrollTop=l:s.scrollTop=l+e.offsetHeight-s.clientHeight)}if(n!=="none"){const c=u<s.scrollLeft,d=u+e.offsetWidth>s.scrollLeft+s.clientWidth;c!==d&&(n==="center"?s.scrollLeft=u-s.clientWidth/2+e.offsetWidth/2:c?s.scrollLeft=u:s.scrollLeft=u+e.offsetWidth-s.clientWidth)}i.push(s)}}function xa(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const i=r.offsetParent;if(!Dt(i))break;t+=i.clientTop,n+=i.clientLeft,r=i}return{top:t,left:n}}function Df(e,t){const n=xa(e),r=xa(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Tf(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left+s+(1-r)*parseFloat(n),l=e.top+o+(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,c=i?e.height*i:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Cf(e,t,n){const{scaleX:r,scaleY:i,x:s,y:o}=t,a=e.left-s-(1-r)*parseFloat(n),l=e.top-o-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,c=i?e.height/i:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Pc({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function wa(e,t=ht(e).translate,n=!0){if(n){const r=yc(e,i=>"translate"in i);if(r){const{translate:i=""}=r[0];if(typeof i=="string"){const s=yr(i);if(s)return s}}}if(t){const r=yr(t);if(r)return r}return{x:0,y:0,z:0}}var Pf=new Ro(e=>setTimeout(e,0)),ur=new Map,Mf=ur.clear.bind(ur);function If(e){const t=e.ownerDocument;let n=ur.get(t);if(n)return n;n=t.getAnimations(),ur.set(t,n),Pf.schedule(Mf);const r=n.filter(i=>ji(i.effect)&&i.effect.target===e);return ur.set(e,r),n}function jf(e,t){const n=If(e).filter(r=>{var i,s;if(ji(r.effect)){const{target:o}=r.effect;if((s=o&&((i=t.isValidTarget)==null?void 0:i.call(t,o)))!=null?s:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:i,currentTime:s}=r,o=i?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof s=="number"&&s<o)return r.currentTime=o,()=>{r.currentTime=s}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ct=class extends dt{constructor(e,t={}){var n,r,i,s;const{frameTransform:o=_n(e),ignoreTransforms:a,getBoundingClientRect:l=Ai}=t,u=jf(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||Io())&&_.contains(e)}),c=l(e);let{top:d,left:h,width:f,height:g}=c,v;const w=ht(e),x=Ri(w),m={x:(n=x?.scaleX)!=null?n:1,y:(r=x?.scaleY)!=null?r:1},p=Af(e,w);u?.(),x&&(v=Cf(c,x,w.transformOrigin),(a||p)&&(d=v.top,h=v.left,f=v.width,g=v.height));const b={width:(i=v?.width)!=null?i:f,height:(s=v?.height)!=null?s:g};if(p&&!a&&v){const _=Tf(v,p,w.transformOrigin);d=_.top,h=_.left,f=_.width,g=_.height,m.x=p.scaleX,m.y=p.scaleY}o&&(a||(h*=o.scaleX,f*=o.scaleX,d*=o.scaleY,g*=o.scaleY),h+=o.x,d+=o.y),super(h,d,f,g),this.scale=m,this.intrinsicWidth=b.width,this.intrinsicHeight=b.height}};function Af(e,t){const n=e.getAnimations();if(!n.length)return null;let r,i,s,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=ji(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:c,translate:d,scale:h}=u;typeof c=="string"&&c&&(r=c,o=!0),typeof d=="string"&&d&&(i=d,o=!0),typeof h=="string"&&h&&(s=h,o=!0)}return o?Ri({transform:r??t.transform,translate:i??t.translate,scale:s??t.scale}):null}function fr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var Rf=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(fr(n))for(const[r,i]of Object.entries(e)){const s=`${t}${r}`;this.initial.has(s)||this.initial.set(s,n.style.getPropertyValue(s)),n.style.setProperty(s,typeof i=="string"?i:`${i}px`)}}remove(e,t=""){const{element:n}=this;if(fr(n))for(const r of e){const i=`${t}${r}`;n.style.removeProperty(i)}}reset(){const{element:e}=this;if(fr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Vt(e){return e?e instanceof Ke(e).Element||Tr(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function br(e){if(!e)return!1;const{KeyboardEvent:t}=Ke(e.target);return e instanceof t}function Lf(e){if(!e)return!1;const{PointerEvent:t}=Ke(e.target);return e instanceof t}function Wf(e){if(!Vt(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||zf(e)}function zf(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var Zi={};function Cs(e){const t=Zi[e]==null?0:Zi[e]+1;return Zi[e]=t,`${e}-${t}`}var Lo=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=Ze.distance(t.shape.center,n);return{id:r,value:1/i,type:In.PointerIntersection,priority:Mn.High}}return null},Ff=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=Ze.distance(t.shape.center,i.current),a=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:a,type:In.ShapeIntersection,priority:Mn.Normal}}return null},Mc=e=>{var t;return(t=Lo(e))!=null?t:Ff(e)},Nf=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:i}=t;if(!n.shape)return null;const s=r?dt.from(r.current.boundingRectangle).corners:void 0,a=dt.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+Ze.distance(Ze.from(u),(d=s?.[c])!=null?d:i.current)},0)/4;return{id:n.id,value:1/a,type:In.Collision,priority:Mn.Normal}},Bf=Object.create,Wo=Object.defineProperty,Vf=Object.defineProperties,Gf=Object.getOwnPropertyDescriptor,Uf=Object.getOwnPropertyDescriptors,bi=Object.getOwnPropertySymbols,Ic=Object.prototype.hasOwnProperty,jc=Object.prototype.propertyIsEnumerable,Ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),An=e=>{throw TypeError(e)},Ps=(e,t,n)=>t in e?Wo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xr=(e,t)=>{for(var n in t||(t={}))Ic.call(t,n)&&Ps(e,n,t[n]);if(bi)for(var n of bi(t))jc.call(t,n)&&Ps(e,n,t[n]);return e},zo=(e,t)=>Vf(e,Uf(t)),_a=(e,t)=>Wo(e,"name",{value:t,configurable:!0}),Rc=(e,t)=>{var n={};for(var r in e)Ic.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&bi)for(var r of bi(e))t.indexOf(r)<0&&jc.call(e,r)&&(n[r]=e[r]);return n},Rn=e=>{var t;return[,,,Bf((t=e?.[Ac("metadata")])!=null?t:null)]},Lc=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?An("Function expected"):e,Hf=(e,t,n,r,i)=>({kind:Lc[e],name:t,metadata:r,addInitializer:s=>n._?An("Already initialized"):i.push(tr(s||null))}),Xt=(e,t)=>Ps(t,Ac("metadata"),e[3]),we=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},nt=(e,t,n,r,i,s)=>{var o,a,l,u,c,d=t&7,h=!!(t&8),f=!!(t&16),g=d>3?e.length+1:d?h?1:2:0,v=Lc[d+5],w=d>3&&(e[g-1]=[]),x=e[g]||(e[g]=[]),m=d&&(!f&&!h&&(i=i.prototype),d<5&&(d>3||!f)&&Gf(d<4?i:{get[n](){return ne(this,s)},set[n](b){return Ae(this,s,b)}},n));d?f&&d<4&&_a(s,(d>2?"set ":d>1?"get ":"")+n):_a(i,n);for(var p=r.length-1;p>=0;p--)u=Hf(d,n,l={},e[3],x),d&&(u.static=h,u.private=f,c=u.access={has:f?b=>qf(i,b):b=>n in b},d^3&&(c.get=f?b=>(d^1?ne:Gt)(b,i,d^4?s:m.get):b=>b[n]),d>2&&(c.set=f?(b,_)=>Ae(b,i,_,d^4?s:m.set):(b,_)=>b[n]=_)),a=(0,r[p])(d?d<4?f?s:m[v]:d>4?void 0:{get:m.get,set:m.set}:i,u),l._=1,d^4||a===void 0?tr(a)&&(d>4?w.unshift(a):d?f?s=a:m[v]=a:i=a):typeof a!="object"||a===null?An("Object expected"):(tr(o=a.get)&&(m.get=o),tr(o=a.set)&&(m.set=o),tr(o=a.init)&&w.unshift(o));return d||Xt(e,i),m&&Wo(i,n,m),f?d^4?s:m:i},Fo=(e,t,n)=>t.has(e)||An("Cannot "+n),qf=(e,t)=>Object(t)!==t?An('Cannot use the "in" operator on this value'):e.has(t),ne=(e,t,n)=>(Fo(e,t,"read from private field"),n?n.call(e):t.get(e)),ge=(e,t,n)=>t.has(e)?An("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ae=(e,t,n,r)=>(Fo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Gt=(e,t,n)=>(Fo(e,t,"access private method"),n),ka={role:"button",roleDescription:"draggable"},Kf="dnd-kit-description",Yf="dnd-kit-announcement",Xf={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Qf={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Zf(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Jf(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function eh(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var th=["dragover","dragmove"],nh=class extends Pe{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=Kf,announcement:i=Yf}={},announcements:s=Qf,screenReaderInstructions:o=Xf,debounce:a=500}=t??{},l=n?`${r}-${n}`:Cs(r),u=n?`${i}-${n}`:Cs(i);let c,d,h,f;const g=(_=f)=>{!h||!_||h?.nodeValue!==_&&(h.nodeValue=_)},v=()=>mi.schedule(g),w=rh(v,a),x=Object.entries(s).map(([_,$])=>this.manager.monitor.addEventListener(_,(O,D)=>{const M=h;if(!M)return;const I=$?.(O,D);I&&M.nodeValue!==I&&(f=I,th.includes(_)?w():(v(),w.cancel()))})),m=()=>{let _=[];c?.isConnected||(c=Jf(l,o.draggable),_.push(c)),d?.isConnected||(d=eh(u),h=document.createTextNode(""),d.appendChild(h),_.push(d)),_.length>0&&document.body.append(..._)},p=new Set;function b(){for(const _ of p)_()}this.registerEffect(()=>{var _;p.clear();for(const $ of this.manager.registry.draggables.value){const O=(_=$.handle)!=null?_:$.element;if(O){(!c||!d)&&p.add(m),(!Zf(O)||Io())&&!O.hasAttribute("tabindex")&&p.add(()=>O.setAttribute("tabindex","0")),!O.hasAttribute("role")&&O.tagName.toLowerCase()!=="button"&&p.add(()=>O.setAttribute("role",ka.role)),O.hasAttribute("aria-roledescription")||p.add(()=>O.setAttribute("aria-roledescription",ka.roleDescription)),O.hasAttribute("aria-describedby")||p.add(()=>O.setAttribute("aria-describedby",l));for(const M of["aria-pressed","aria-grabbed"]){const I=String($.isDragging);O.getAttribute(M)!==I&&p.add(()=>O.setAttribute(M,I))}const D=String($.disabled);O.getAttribute("aria-disabled")!==D&&p.add(()=>O.setAttribute("aria-disabled",D))}}p.size>0&&mi.schedule(b)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),x.forEach(_=>_())}}};function rh(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var xi=new Map,Wc,zc,Fc,Nc,Ms,hr,mt,No,kn,Bc,Vc,Gc,Uc,Tt=class extends(Ms=Dr,Nc=[H],Fc=[pe],zc=[pe],Wc=[pe],Ms){constructor(t,n){super(t,n),we(mt,5,this),ge(this,kn),ge(this,hr,new Set),ge(this,No,we(mt,8,this,new Set)),we(mt,11,this),this.registerEffect(Gt(this,kn,Bc))}register(t){return ne(this,hr).add(t),()=>{ne(this,hr).delete(t)}}addRoot(t){return U(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{U(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return pi((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return pi((t=n?.element)!=null?t:null)}get roots(){const{status:t}=this.manager.dragOperation;if(t.initializing||t.initialized){const n=[this.sourceRoot,this.targetRoot].filter(r=>r!=null);return new Set([...n,...this.additionalRoots])}return new Set}};mt=Rn(Ms);hr=new WeakMap;No=new WeakMap;kn=new WeakSet;Bc=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ne(this,hr))t.push(Gt(this,kn,Vc).call(this,n,r));return()=>{for(const n of t)n()}};Vc=function(e,t){let n=xi.get(e);n||(n=new Map,xi.set(e,n));let r=n.get(t);if(!r){const s=Mo(e)?Gt(this,kn,Gc).call(this,e,n,t):Gt(this,kn,Uc).call(this,e,n,t);if(!s)return()=>{};r=s,n.set(t,r)}r.refCount++;let i=!1;return()=>{i||(i=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Gc=function(e,t,n){var r;const i=e.createElement("style"),{nonce:s}=(r=this.options)!=null?r:{};s&&i.setAttribute("nonce",s),i.textContent=n,e.head.prepend(i);const o=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===i){e.head.prepend(i);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),i.remove(),t.delete(n),t.size===0&&xi.delete(e)}}};Uc=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:i}=r??{};if(!i)return null;const s=new i;return s.replaceSync(n),e.adoptedStyleSheets.push(s),{refCount:0,cleanup:()=>{var o;if(jo(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(s);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&xi.delete(e)}}};nt(mt,4,"additionalRoots",Nc,Tt,No);nt(mt,2,"sourceRoot",Fc,Tt);nt(mt,2,"targetRoot",zc,Tt);nt(mt,2,"roots",Wc,Tt);Xt(mt,Tt);Tt.configure=Or(Tt);var Li=Tt,ih=class extends Pe{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Li),i=r?.register(`* { cursor: ${n} !important; }`);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}}},Cr="data-dnd-",Is=`${Cr}dropping`,Oe="--dnd-",lt=`${Cr}dragging`,wi=`${Cr}placeholder`,sh=[lt,wi,"popover","aria-pressed","aria-grabbing"],oh=["view-transition-name"],ah=`
9
+ :is(:root,:host) [${lt}] {
10
10
  position: fixed !important;
11
11
  pointer-events: none !important;
12
12
  touch-action: none;
13
13
  z-index: calc(infinity);
14
14
  will-change: translate;
15
- top: var(${we}top, 0px) !important;
16
- left: var(${we}left, 0px) !important;
15
+ top: var(${Oe}top, 0px) !important;
16
+ left: var(${Oe}left, 0px) !important;
17
17
  right: unset !important;
18
18
  bottom: unset !important;
19
- width: var(${we}width, auto);
20
- max-width: var(${we}width, auto);
21
- height: var(${we}height, auto);
22
- max-height: var(${we}height, auto);
23
- transform: var(${we}transform, none) !important;
24
- transition: var(${we}transition) !important;
19
+ width: var(${Oe}width, auto);
20
+ max-width: var(${Oe}width, auto);
21
+ height: var(${Oe}height, auto);
22
+ max-height: var(${Oe}height, auto);
23
+ transform: var(${Oe}transform, none) !important;
24
+ transition: var(${Oe}transition) !important;
25
25
  }
26
26
 
27
- :is(:root,:host) [${pi}] {
27
+ :is(:root,:host) [${wi}] {
28
28
  transition: none;
29
29
  }
30
30
 
31
- :is(:root,:host) [${pi}='hidden'] {
31
+ :is(:root,:host) [${wi}='hidden'] {
32
32
  visibility: hidden;
33
33
  }
34
34
 
35
- [${ot}] * {
35
+ [${lt}] * {
36
36
  pointer-events: none !important;
37
37
  }
38
38
 
39
- [${ot}]:not([${Os}]) {
40
- translate: var(${we}translate) !important;
39
+ [${lt}]:not([${Is}]) {
40
+ translate: var(${Oe}translate) !important;
41
41
  }
42
42
 
43
- [${ot}][style*='${we}scale'] {
44
- scale: var(${we}scale) !important;
45
- transform-origin: var(${we}transform-origin) !important;
43
+ [${lt}][style*='${Oe}scale'] {
44
+ scale: var(${Oe}scale) !important;
45
+ transform-origin: var(${Oe}transform-origin) !important;
46
46
  }
47
47
 
48
48
  @layer dnd-kit {
49
- :where([${ot}][popover]) {
49
+ :where([${lt}][popover]) {
50
50
  overflow: visible;
51
51
  background: unset;
52
52
  border: unset;
@@ -60,46 +60,51 @@
60
60
  }
61
61
  }
62
62
  }
63
- [${ot}]::backdrop, [${kr}overlay]:not([${ot}]) {
63
+ [${lt}]::backdrop, [${Cr}overlay]:not([${lt}]) {
64
64
  display: none;
65
65
  visibility: hidden;
66
66
  }
67
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Nf(e,t="hidden"){return H(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=Gf(n,r.registry.droppables),s=[],o=Ru(n),{remove:a}=o;return Vf(i,o,s),Hf(o,t),o.remove=()=>{s.forEach(l=>l()),a.call(o)},o})}function Gf(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${kr}${ks("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function Vf(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),bs.set(a,o),n.push(()=>{bs.delete(a),r.proxy=void 0})}}function Hf(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(pi,t)}function jc(e,t){return e===t?!0:mn(e)===mn(t)}function pa(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ft(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>fn(t))}function Ts(e){return e.tagName==="TR"}function Kf(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Wf.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(or(e)&&or(t)){const d=e.style;for(const u of Array.from(t.style))d.getPropertyValue(u)===""&&t.style.removeProperty(u);for(const u of Array.from(d)){if(Ff.includes(u)||u.startsWith(we))continue;const c=d.getPropertyValue(u);t.style.setProperty(u,c)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function qf(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),fn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),fn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),fn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Uf(e){return new ResizeObserver(()=>{var t,n,r;const i=new at(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,l=cc();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},we),(n=e.getElementMutationObserver())==null||n.takeRecords(),Ts(e.element)&&Ts(e.placeholder)){const m=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(b=>b.style.width));for(const[b,v]of m.entries()){const p=w[b];v.style.width=`${p.getBoundingClientRect().width}px`}}const d=(r=e.getTranslate())!=null?r:{x:0,y:0},u=e.left+o+l.x+d.x,c=e.top+a+l.y+d.y,h=i.width-e.widthOffset,f=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new lt(u*g.scaleX+g.x,c*g.scaleY+g.y,h*g.scaleX,f*g.scaleY)})}var Xf=250,Yf="ease";function Zf(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const v=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(v).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Xf,easing:a=Yf}=s??{};fn(e.feedbackElement);const[,l]=(t=oc(e.feedbackElement,v=>"translate"in v))!=null?t:[];l?.pause();const d=(n=e.placeholder)!=null?n:e.element,u={frameTransform:jc(e.feedbackElement,d)?null:void 0},c=new at(e.feedbackElement,u),h=(r=fr(ut(e.feedbackElement).translate))!=null?r:e.translate,f=new at(d,u),g=lt.delta(c,f,e.alignment),m={x:h.x-g.x,y:h.y-g.y},w=Math.round(c.intrinsicHeight)!==Math.round(f.intrinsicHeight)?{minHeight:[`${c.intrinsicHeight}px`,`${f.intrinsicHeight}px`],maxHeight:[`${c.intrinsicHeight}px`,`${f.intrinsicHeight}px`]}:{},b=Math.round(c.intrinsicWidth)!==Math.round(f.intrinsicWidth)?{minWidth:[`${c.intrinsicWidth}px`,`${f.intrinsicWidth}px`],maxWidth:[`${c.intrinsicWidth}px`,`${f.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},we),e.feedbackElement.setAttribute(Os,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),bc({element:e.feedbackElement,keyframes:Co(pr(pr({},w),b),{translate:[`${h.x}px ${h.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:To(He(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Os),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Ac,Es,gr,jo,Qr,Rc,Lc,xn=class extends(Es=Ee,Ac=[K],Es){constructor(t,n){super(t,n),de(this,Qr),de(this,jo,pe(gr,8,this)),pe(gr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Ci),i=r?.register(Bf);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}this.registerEffect(Bt(this,Qr,Rc).bind(this,r)),this.registerEffect(Bt(this,Qr,Lc))}};gr=Mn(Es);jo=new WeakMap;Qr=new WeakSet;Rc=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ai(t);if(n)return e.addRoot(n)};Lc=function(){var e,t,n,r,i,s,o;const{state:a,manager:l,options:d}=this,{dragOperation:u}=l,{position:c,source:h,status:f}=u;if(f.idle){a.current={},a.initial={};return}if(!h)return;const{element:g}=h,m=h.pluginConfig(xn),w=(t=(e=m?.feedback)!=null?e:d?.feedback)!=null?t:"default",b=typeof w=="function"?w(h,l):w;if(!g||b==="none"||!f.initialized||f.initializing)return;const{initial:v}=a,p=(n=this.overlay)!=null?n:g,x=yn(p),_=yn(g),O=!jc(g,p),T=new at(g,{frameTransform:O?_:null,ignoreTransforms:!O}),E={x:_.scaleX/x.scaleX,y:_.scaleY/x.scaleY};let{width:I,height:D,top:L,left:M}=T;O&&(I=I/E.x,D=D/E.y);const A=new vf(p),Q=ut(g),{transition:J,translate:ye,boxSizing:Ie,paddingBlockStart:ie,paddingBlockEnd:ze,paddingInlineStart:Ke,paddingInlineEnd:be,borderInlineStartWidth:qe,borderInlineEndWidth:We,borderBlockStartWidth:je,borderBlockEndWidth:Fe}=Q,xe=J.split(",").filter(W=>!/^\s*(transform|translate|scale)\b/.test(W)).join(","),ee=Pi(Q),z=Q.transform,V=b==="clone",_e=Ie==="content-box",ne=_e?parseInt(Ke)+parseInt(be)+parseInt(qe)+parseInt(We):0,Ae=_e?parseInt(ie)+parseInt(ze)+parseInt(je)+parseInt(Fe):0,X=b!=="move"&&!this.overlay?Nf(h,V?"clone":"hidden"):null,et=H(()=>hr(l.dragOperation.activatorEvent));if(!v.translate){if(this.overlay&&ee)v.translate={x:ee.x,y:ee.y};else if(ye!=="none"){const W=fr(ye);W&&(v.translate=W)}}if(!v.transformOrigin){const W=H(()=>c.current),ue=M+((r=ee?.x)!=null?r:0),Ne=L+((i=ee?.y)!=null?i:0);v.transformOrigin={x:(W.x-ue*x.scaleX-x.x)/(I*x.scaleX),y:(W.y-Ne*x.scaleY-x.y)/(D*x.scaleY)}}const{transformOrigin:Se}=v,ft=L*x.scaleY+x.y,P=M*x.scaleX+x.x;if(!v.coordinates&&(v.coordinates={x:P,y:ft},E.x!==1||E.y!==1)){const{scaleX:W,scaleY:ue}=_,{x:Ne,y:bt}=Se;v.coordinates.x+=(I*W-I)*Ne,v.coordinates.y+=(D*ue-D)*bt}v.dimensions||(v.dimensions={width:I,height:D}),v.frameTransform||(v.frameTransform=x);const R={x:v.coordinates.x-P,y:v.coordinates.y-ft},U={width:(v.dimensions.width*v.frameTransform.scaleX-I*x.scaleX)*Se.x,height:(v.dimensions.height*v.frameTransform.scaleY-D*x.scaleY)*Se.y},$={x:R.x/x.scaleX+U.width,y:R.y/x.scaleY+U.height},C={left:M+$.x,top:L+$.y};p.setAttribute(ot,"true");const F=H(()=>u.transform),Y=(s=v.translate)!=null?s:{x:0,y:0},Be=F.x*x.scaleX+Y.x,ge=F.y*x.scaleY+Y.y,$e=cc();A.set({width:I-ne,height:D-Ae,top:C.top+$e.y,left:C.left+$e.x,translate:`${Be}px ${ge}px 0`,transform:this.overlay?"none":z,transition:xe?`${xe}, translate 0ms linear`:"translate 0ms linear",scale:O?`${E.x} ${E.y}`:"","transform-origin":`${Se.x*100}% ${Se.y*100}%`},we),X&&(g.insertAdjacentElement("afterend",X),d?.rootElement&&(typeof d.rootElement=="function"?d.rootElement(h):d.rootElement).appendChild(g)),_s(p)&&(p.hasAttribute("popover")||p.setAttribute("popover","manual"),fn(p),p.addEventListener("beforetoggle",pa));let ve,qt,jn;const Tr=Uf({placeholder:X,element:g,feedbackElement:p,frameTransform:x,transformOrigin:Se,width:I,height:D,top:L,left:M,widthOffset:ne,heightOffset:Ae,delta:$,styles:A,dragOperation:u,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>ve,getSavedCellWidths:()=>jn,setSavedCellWidths:W=>{jn=W}}),Ut=new at(p);H(()=>u.shape=Ut);const An=He(p),Er=W=>{this.manager.actions.stop({event:W})},Dr=To(An);et&&An.addEventListener("resize",Er),H(()=>h.status)==="idle"&&requestAnimationFrame(()=>h.status="dragging"),X&&(Tr.observe(X),ve=Kf(g,X,V),qt=qf(g,X,p));const Pr=(o=l.dragOperation.source)==null?void 0:o.id,Ri=()=>{var W;if(!et||Pr==null)return;const ue=l.registry.draggables.get(Pr),Ne=(W=ue?.handle)!=null?W:ue?.element;Tt(Ne)&&Ne.focus()},G=()=>{ve?.disconnect(),qt?.disconnect(),Tr.disconnect(),An.removeEventListener("resize",Er),_s(p)&&(p.removeEventListener("beforetoggle",pa),p.removeAttribute("popover")),p.removeAttribute(ot),A.reset();const W=()=>{var ue;if(jn&&Ts(g)){const Li=Array.from(g.cells);for(const[Cr,Xt]of Li.entries())Xt.style.width=(ue=jn[Cr])!=null?ue:""}h.status="idle";const Ne=a.current.translate!=null,bt=u.status.dragging;X&&(!bt&&Ne||X.parentElement!==p.parentElement)&&p.isConnected&&X.replaceWith(p),X?.remove()};p===this.overlay?setTimeout(W,0):W()},Oe=d?.dropAnimation,tt=this,fe=yr(()=>{var W,ue,Ne;const{transform:bt,status:Li}=u;if(!(!bt.x&&!bt.y&&!a.current.translate)&&Li.dragging){const Cr=(W=v.translate)!=null?W:{x:0,y:0},Xt={x:bt.x/x.scaleX+Cr.x,y:bt.y/x.scaleY+Cr.y},qo=a.current.translate,Md=H(()=>u.modifiers),zi=H(()=>{var Ln;return(Ln=u.shape)==null?void 0:Ln.current}),Rn=d?.keyboardTransition,Uo=et&&!Dr&&Rn!==null?`${(ue=Rn?.duration)!=null?ue:250}ms ${(Ne=Rn?.easing)!=null?Ne:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(A.set({transition:xe?`${xe}, translate ${Uo}`:`translate ${Uo}`,translate:`${Xt.x}px ${Xt.y}px 0`},we),ve?.takeRecords(),zi&&zi!==Ut&&qo&&!Md.length){const Ln=Xe.delta(Xt,qo);u.shape=lt.from(zi.boundingRectangle).translate(Ln.x*x.scaleX,Ln.y*x.scaleY)}else u.shape=new at(p);a.current.translate=Xt}},function(){if(u.status.dropped){this.dispose(),h.status="dropping";const W=m?.dropAnimation!==void 0?m.dropAnimation:tt.dropAnimation!==void 0?tt.dropAnimation:Oe;let ue=a.current.translate;const Ne=ue!=null;if(!ue&&g!==p&&(ue={x:0,y:0}),!ue||W===null){G();return}l.renderer.rendering.then(()=>{Zf({source:h,element:g,feedbackElement:p,placeholder:X,translate:ue,moved:Ne,transition:J,alignment:h.alignment,styles:A,animation:W??void 0,getElementMutationObserver:()=>ve,cleanup:G,restoreFocus:Ri})})}});return()=>{G(),fe()}};Je(gr,4,"overlay",Ac,xn,jo);Kt(gr,xn);xn.configure=xr(xn);var Ao=xn,zn=!0,Qf=!1,zc,Wc,Fc,Bc,kt,Ro,Lo;Bc=(Fc=[K],Ye.Forward),Wc=(zc=[K],Ye.Reverse);var vr=class{constructor(){de(this,Ro,pe(kt,8,this,zn)),pe(kt,11,this),de(this,Lo,pe(kt,12,this,zn)),pe(kt,15,this)}isLocked(e){return e===Ye.Idle?!1:e==null?this[Ye.Forward]===zn&&this[Ye.Reverse]===zn:this[e]===zn}unlock(e){e!==Ye.Idle&&(this[e]=Qf)}};kt=Mn(null);Ro=new WeakMap;Lo=new WeakMap;Je(kt,4,Bc,Fc,vr,Ro);Je(kt,4,Wc,zc,vr,Lo);Kt(kt,vr);var Jf=[Ye.Forward,Ye.Reverse],ga=class{constructor(){this.x=new vr,this.y=new vr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},eh=class extends Ee{constructor(e){super(e);const t=wn(new ga);let n=null;this.signal=t,Qe(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new ga;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:va(i.x,n.x),y:va(i.y,n.y)},o=t.peek();ae(()=>{for(const a of vl)for(const l of Jf)s[a]===l&&o[a].unlock(l);t.value=o})}n=i})}get current(){return this.signal.peek()}};function va(e,t){return Math.sign(e-t)}var Nc,Ds,mr,zo,_t,Ps,Sr=class extends(Ds=_r,Nc=[K],Ds){constructor(e){super(e),de(this,zo,pe(mr,8,this,!1)),pe(mr,11,this),de(this,_t),de(this,Ps,()=>{if(!te(this,_t))return;const{element:s,by:o}=te(this,_t);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return Ce(this,_t,void 0),!1;const{position:d}=this.manager.dragOperation,u=d?.current;if(u){const{by:c}=s??{},h=c?{x:ma(c.x),y:ma(c.y)}:void 0,f=h?void 0:this.scrollIntentTracker.current;if(f?.isLocked())return!1;for(const g of l){const m=Xu(g,c);if(m.x||m.y){const{speed:w,direction:b}=af(g,u,h,o?.acceleration,o?.threshold);if(f)for(const v of vl)f[v].isLocked(b[v])&&(w[v]=0,b[v]=0);if(b.x||b.y){const{x:v,y:p}=c??b,x=v*w.x,_=p*w.y;if(x||_){const O=(a=te(this,_t))==null?void 0:a.by;if(this.autoScrolling&&O&&(O.x&&!x||O.y&&!_))continue;return Ce(this,_t,{element:g,by:{x,y:_}}),di.schedule(te(this,Ps)),!0}}}}}return Ce(this,_t,void 0),!1};let t=null,n=null;const r=ss(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=dc(ai(o?.element),s.current);return a&&(t=a),a??t}),i=ss(()=>{const s=r.value,{documentElement:o}=Pn(s);if(!s||s===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const d=ws(l,{excludeElement:!1});return n=d,d}}if(s){const a=ws(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},nt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new eh(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!hr(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};mr=Mn(Ds);zo=new WeakMap;_t=new WeakMap;Ps=new WeakMap;Je(mr,4,"autoScrolling",Nc,Sr,zo);Kt(mr,Sr);function ma(e){return e>0?Ye.Forward:e<0?Ye.Reverse:Ye.Idle}var th=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},nh=new th(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),rh=10,Cs=class extends Ee{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Sr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=Qe(()=>{var i,s,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const d={acceleration:(i=this.options)==null?void 0:i.acceleration,threshold:typeof((s=this.options)==null?void 0:s.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,d)){r.autoScrolling=!0;const c=setInterval(()=>nh.schedule(()=>r.scroll(void 0,d)),rh);return()=>{clearInterval(c)}}else r.autoScrolling=!1}})}};Cs.configure=xr(Cs);var Gc=Cs,ya={capture:!0,passive:!0},Yn,ih=class extends _r{constructor(e){super(e),de(this,Yn),this.handleScroll=()=>{te(this,Yn)==null&&Ce(this,Yn,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ce(this,Yn,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=Qe(()=>{var n,r,i;if(t.status.dragging){const o=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return o.addEventListener("scroll",this.handleScroll,ya),()=>{o.removeEventListener("scroll",this.handleScroll,ya)}}})}};Yn=new WeakMap;var sh="* { user-select: none !important; -webkit-user-select: none !important; }",oh=class extends Ee{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Ci),n=t?.register(sh);if(this.destroy=Qe(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ki(),document.addEventListener("selectionchange",Ki,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ki,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ki(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var Zn=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),on,gi=class extends gn{constructor(t,n){super(t),this.manager=t,this.options=n,de(this,on,[]),this.listeners=new uc,this.handleSourceKeyDown=(r,i,s)=>{if(this.disabled||r.defaultPrevented||!Ft(r.target)||i.disabled)return;const{keyboardCodes:o=Zn.keyboardCodes,preventActivation:a=Zn.preventActivation}=s??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,i)||this.handleStart(r,i,s))}}bind(t,n=this.options){return Qe(()=>{var i;const s=(i=t.handle)!=null?i:t.element,o=a=>{hr(a)&&this.handleSourceKeyDown(a,t,n)};if(s)return s.addEventListener("keydown",o),()=>{s.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:i}=n;if(!i)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),yc(i);const{center:s}=new at(i);if(this.manager.actions.start({event:t,coordinates:{x:s.x,y:s.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Pn(i),l=[this.listeners.bind(a,[{type:"keydown",listener:d=>this.handleKeyDown(d,n,r),options:{capture:!0}}])];te(this,on).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:i=Zn.keyboardCodes}=r??{};if(Yt(t,[...i.end,...i.cancel])){t.preventDefault();const s=Yt(t,i.cancel);this.handleEnd(t,s);return}Yt(t,i.up)?this.handleMove("up",t):Yt(t,i.down)&&this.handleMove("down",t),Yt(t,i.left)?this.handleMove("left",t):Yt(t,i.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,i;const{shape:s}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(i=(r=this.options)==null?void 0:r.offset)!=null?i:Zn.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!s){switch(t){case"up":a={x:0,y:-l.y*o};break;case"down":a={x:0,y:l.y*o};break;case"left":a={x:-l.x*o,y:0};break;case"right":a={x:l.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(Gc);t?.disabled===!1&&(t.disable(),te(this,on).push(()=>{t.enable()}))}cleanup(){te(this,on).forEach(t=>t()),Ce(this,on,[])}destroy(){this.cleanup(),this.listeners.clear()}};on=new WeakMap;gi.configure=xr(gi);gi.defaults=Zn;var Vc=gi;function Yt(e,t){return t.includes(e.code)}var At,ah=class extends Ul{constructor(){super(...arguments),de(this,At)}onEvent(e){switch(e.type){case"pointerdown":Ce(this,At,vn(e));break;case"pointermove":if(!te(this,At))return;const{x:t,y:n}=vn(e),r={x:t-te(this,At).x,y:n-te(this,At).y},{tolerance:i}=this.options;if(i&&ps(r,i)){this.abort();return}ps(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ce(this,At,void 0)}};At=new WeakMap;var an,Rt,lh=class extends Ul{constructor(){super(...arguments),de(this,an),de(this,Rt)}onEvent(e){switch(e.type){case"pointerdown":Ce(this,Rt,vn(e)),Ce(this,an,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!te(this,Rt))return;const{x:t,y:n}=vn(e),r={x:t-te(this,Rt).x,y:n-te(this,Rt).y};ps(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){te(this,an)&&(clearTimeout(te(this,an)),Ce(this,Rt,void 0),Ce(this,an,void 0))}};an=new WeakMap;Rt=new WeakMap;var un=class{};un.Delay=lh;un.Distance=ah;var Ms=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&Ft(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new un.Delay({value:250,tolerance:5})]:yf(i)&&!e.defaultPrevented?[new un.Delay({value:200,tolerance:0})]:[new un.Delay({value:200,tolerance:10}),new un.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Ft(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=zu(r);return i===t.element?!1:!!i}}),ln,vi=class extends gn{constructor(t,n){super(t),this.manager=t,this.options=n,de(this,ln,new Set),this.listeners=new uc,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:i}=this.latest;!r||!i||this.manager.actions.move({event:r,to:i})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:i=Ms.activationConstraints}=r??{};return typeof i=="function"?i(t,n):i}bind(t,n=this.options){return Qe(()=>{var i;const s=new AbortController,{signal:o}=s,a=d=>{mf(d)&&this.handlePointerDown(d,t,n)};let l=[(i=t.handle)!=null?i:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const d of l)d&&(uh(d.ownerDocument.defaultView),d.addEventListener("pointerdown",a,{signal:o}));return()=>s.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ft(t.target)||n.disabled||ch(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:i=Ms.preventActivation}=r??{};if(i?.(t,n))return;const{target:s}=t,o=Tt(s)&&s.draggable&&s.getAttribute("draggable")==="true",a=yn(n.element),{x:l,y:d}=vn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:d*a.scaleY+a.y};const u=this.activationConstraints(t,n,r);t.sensor=this;const c=new Du(u,m=>this.handleStart(n,m));c.signal.onabort=()=>this.handleCancel(t),c.onEvent(t),this.controller=c;const h=ys(),f=this.listeners.bind(h,[{type:"pointermove",listener:m=>this.handlePointerMove(m,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:Ar,options:{capture:!0}}]),g=()=>{f(),this.initialCoordinates=void 0};te(this,ln).add(g)}handlePointerMove(t,n){var r,i;if(((r=this.controller)==null?void 0:r.activated)===!1){(i=this.controller)==null||i.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const s=vn(t),o=yn(n.element);s.x=s.x*o.scaleX+o.x,s.y=s.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=s,di.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:i}=this;if(!i||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:i,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Pn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ft(n.target)?[n.target,a]:a,d=this.listeners.bind(l,[{type:"touchmove",listener:Ar,options:{passive:!1}},{type:"click",listener:Ar},{type:"contextmenu",listener:Ar},{type:"keydown",listener:this.handleKeyDown}]);te(this,ln).add(d)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},te(this,ln).forEach(n=>n()),te(this,ln).clear()}destroy(){this.cleanup(),this.listeners.clear()}};ln=new WeakMap;vi.configure=xr(vi);vi.defaults=Ms;var Is=vi;function ch(e){return"sensor"in e}function Ar(e){e.preventDefault()}function dh(){}var ba=new WeakSet;function uh(e){!e||ba.has(e)||(e.addEventListener("touchmove",dh,{capture:!1,passive:!1}),ba.add(e))}var hn={modifiers:[],plugins:[Rf,Gc,zf,Ao,oh],sensors:[Is,Vc]},Hc=class extends Mu{constructor(e={}){const t=it(e.plugins,hn.plugins),n=it(e.sensors,hn.sensors),r=it(e.modifiers,hn.modifiers);super(Co(pr({},e),{plugins:[ih,Sr,Ci,...t],sensors:n,modifiers:r}))}},Kc,qc,js,St,Wo,Fo,Mi=class extends(js=ct,qc=[K],Kc=[K],js){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=Sc(n,["element","effects","handle"]);super(pr({effects:()=>[...i(),()=>{var a,l;const{manager:d}=this;if(!d)return;const c=((l=(a=this.sensors)==null?void 0:a.map(cr))!=null?l:[...d.sensors]).map(h=>{const f=h instanceof gn?h:d.registry.register(h.plugin),g=h instanceof gn?void 0:h.options;return f.bind(this,g)});return function(){c.forEach(f=>f())}}]},o),t),de(this,Wo,pe(St,8,this)),pe(St,11,this),de(this,Fo,pe(St,12,this)),pe(St,15,this),this.element=r,this.handle=s}};St=Mn(js);Wo=new WeakMap;Fo=new WeakMap;Je(St,4,"handle",qc,Mi,Wo);Je(St,4,"element",Kc,Mi,Fo);Kt(St,Mi);var Uc,Xc,As,$t,Bo,qi,Yc,Zc,lr,No,Ii=class extends(As=dt,Xc=[K],Uc=[K],As){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=Sc(n,["element","effects"]);const{collisionDetector:o=xc}=s,a=d=>{const{manager:u,element:c}=this;if(!c||d===null){this.shape=void 0;return}if(!u)return;const h=new at(c),f=H(()=>this.shape);return h&&f?.equals(h)?f:(this.shape=h,h)},l=wn(!1);super(Co(pr({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:d,manager:u}=this;if(!u)return;const{dragOperation:c}=u,{source:h}=c;l.value=!!(h&&c.status.initialized&&d&&!this.disabled&&this.accepts(h))},()=>{const{element:d}=this;if(l.value&&d){const u=new Uu(d,a);return()=>{u.disconnect(),this.shape=void 0}}},()=>{var d;if((d=this.manager)!=null&&d.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),de(this,lr),de(this,Bo,pe($t,8,this)),pe($t,11,this),de(this,No,pe($t,12,this)),pe($t,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ce(this,lr,e,Zc)}get element(){var e;return(e=this.proxy)!=null?e:te(this,lr,Yc)}};$t=Mn(As);Bo=new WeakMap;lr=new WeakSet;No=new WeakMap;qi=Je($t,20,"#element",Xc,lr,Bo),Yc=qi.get,Zc=qi.set;Je($t,4,"proxy",Uc,Ii,No);Kt($t,Ii);function fh(e){return e!=null&&typeof e=="object"&&"current"in e}function pn(e){var t;if(e!=null)return fh(e)?(t=e.current)!=null?t:void 0:e}var hh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",In=hh?S.useLayoutEffect:S.useEffect;function ph(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function Qc(e,t){const n=S.useRef(new Map),r=ph();return In(()=>{if(!e){n.current.clear();return}return Qe(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[l]=a,d=H(()=>a[1]),u=e[l];d!==u&&(s=!0,n.current.set(l,u),o=(i=t?.(l,d,u))!=null?i:!1)}s&&(o?queueMicrotask(()=>Wd.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function gh(e,t){e()}function Zt(e){const t=S.useRef(e);return In(()=>{t.current=e},[e]),t}function se(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function Jr(e,t){const n=S.useRef(pn(e));In(()=>{const r=pn(e);r!==n.current&&(n.current=r,t(r))})}var vh=Object.defineProperty,mh=Object.defineProperties,yh=Object.getOwnPropertyDescriptors,mi=Object.getOwnPropertySymbols,Jc=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,xa=(e,t,n)=>t in e?vh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bh=(e,t)=>{for(var n in t||(t={}))Jc.call(t,n)&&xa(e,n,t[n]);if(mi)for(var n of mi(t))ed.call(t,n)&&xa(e,n,t[n]);return e},xh=(e,t)=>mh(e,yh(t)),_h=(e,t)=>{var n={};for(var r in e)Jc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&mi)for(var r of mi(e))t.indexOf(r)<0&&ed.call(e,r)&&(n[r]=e[r]);return n},wh=new Hc,td=S.createContext(wh),kh=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),s=S.useRef(null),o=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(l=>{s.current=l})),S.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return In(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),Ui=[void 0,nt];function Sh(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:l}=t,d=_h(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const u=S.useRef(null),{plugins:c,modifiers:h,sensors:f}=d,g=it(c,hn.plugins),m=it(f,hn.sensors),w=it(h,hn.modifiers),b=Zt(i),v=Zt(s),p=Zt(a),x=Zt(o),_=Zt(l),O=Zt(r),T=$h(()=>{var E;return(E=d.manager)!=null?E:new Hc(d)});return S.useEffect(()=>{if(!u.current)throw new Error("Renderer not found");const{renderer:E,trackRendering:I}=u.current,{monitor:D}=T;T.renderer=E;const L=[D.addEventListener("beforedragstart",M=>{const A=b.current;A&&I(()=>A(M,T))}),D.addEventListener("dragstart",M=>{var A;return(A=v.current)==null?void 0:A.call(v,M,T)}),D.addEventListener("dragover",M=>{const A=p.current;A&&I(()=>A(M,T))}),D.addEventListener("dragmove",M=>{const A=x.current;A&&I(()=>A(M,T))}),D.addEventListener("dragend",M=>{const A=_.current;A&&I(()=>A(M,T))}),D.addEventListener("collision",M=>{var A;return(A=O.current)==null?void 0:A.call(O,M,T)})];return()=>L.forEach(M=>M())},[T]),se(g,()=>T&&(T.plugins=g),...Ui),se(m,()=>T&&(T.sensors=m),...Ui),se(w,()=>T&&(T.modifiers=w),...Ui),y.jsxs(td.Provider,{value:T,children:[y.jsx(kh,{ref:u,children:n}),n]})}function $h(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Oh(){return S.useContext(td)}function nd(e){var t;const n=(t=Oh())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),In(r.register,[n,r]),r}var Th=Object.create,rd=Object.defineProperty,Eh=Object.getOwnPropertyDescriptor,id=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),ji=e=>{throw TypeError(e)},Dh=(e,t,n)=>t in e?rd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ph=e=>{var t;return[,,,Th((t=e?.[id("metadata")])!=null?t:null)]},sd=["class","method","getter","setter","accessor","field","value","get","set"],od=e=>e!==void 0&&typeof e!="function"?ji("Function expected"):e,Ch=(e,t,n,r,i)=>({kind:sd[e],name:t,metadata:r,addInitializer:s=>n._?ji("Already initialized"):i.push(od(s||null))}),Mh=(e,t)=>Dh(t,id("metadata"),e[3]),Ih=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},ad=(e,t,n,r,i,s)=>{for(var o,a,l,d,u=t&7,c=!1,h=!1,f=2,g=sd[u+5],m=e[f]||(e[f]=[]),w=(i=i.prototype,Eh(i,n)),b=r.length-1;b>=0;b--)l=Ch(u,n,a={},e[3],m),l.static=c,l.private=h,d=l.access={has:v=>n in v},d.get=v=>v[n],o=(0,r[b])(w[g],l),a._=1,od(o)&&(w[g]=o);return w&&rd(i,n,w),i},ld=(e,t,n)=>t.has(e)||ji("Cannot "+n),jh=(e,t,n)=>(ld(e,t,"read from private field"),t.get(e)),Ah=(e,t,n)=>t.has(e)?ji("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Rh=(e,t,n,r)=>(ld(e,t,"write to private field"),t.set(e,n),n),zt=class Rs{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Rs(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Rs(t,n)}},cd,dd,Ls,ei,$r,Go=class extends(Ls=Vt,dd=[ce],cd=[ce],Ls){constructor(e){const t=zt.from(e);super(t,(n,r)=>zt.equals(n,r)),Ih($r,5,this),Ah(this,ei,0),this.velocity={x:0,y:0}}get delta(){return zt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=zt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-jh(this,ei),o=a=>Math.round(a/s*100);ae(()=>{Rh(this,ei,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(zt.from(e)),this.velocity={x:0,y:0}}};$r=Ph(Ls);ei=new WeakMap;ad($r,2,"delta",dd,Go);ad($r,2,"direction",cd,Go);Mh($r,Go);var ud=(e=>(e.Horizontal="x",e.Vertical="y",e))(ud||{});Object.values(ud);var Lh=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=zt.distance(t.shape.center,n);return{id:r,value:1/i,type:Dn.PointerIntersection,priority:En.High}}return null},zh=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=zt.distance(t.shape.center,i.current),a=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:a,type:Dn.ShapeIntersection,priority:En.Normal}}return null},Wh=e=>{var t;return(t=Lh(e))!=null?t:zh(e)};function Fh(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,l=nd(u=>new Ii(xh(bh({},e),{register:!1,element:pn(i)}),u)),d=Qc(l);return se(s,()=>l.id=s),Jr(i,u=>l.element=u),se(o,()=>l.accept=o,void 0,nt),se(t,()=>l.collisionDetector=t??Wh),se(n,()=>n&&(l.data=n)),se(r,()=>l.disabled=r===!0),se(a,()=>l.type=a),{droppable:d,get isDropTarget(){return d.isDropTarget},ref:S.useCallback(u=>{var c,h;!u&&((c=l.element)!=null&&c.isConnected)&&!((h=l.manager)!=null&&h.dragOperation.status.idle)||(l.element=u??void 0)},[l])}}function Bh(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of s.filters??[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function yi(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function Nh(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function ti(e,t){const n=Nh(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const i=new Set(["date","timestamp"]);return i.has(n)?i.has(r):n===r}function _a(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function Gh(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const Vh=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function Hh(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",i=/^[A-Z_]/.test(r)?r:`F_${r}`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const wa=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"Since a date",hint:"A date picker; tiles keep rows on or after it"}];function Rr(e){const t=e.label.trim()||e.name,n=e.field.split(".").at(-1)??e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const zs=e=>e.declaration.kind==="reference";function Kh(e,t){return e.tiles.map(n=>{const r=(n.filters??[]).find(i=>i.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:yi(t.type)!==void 0?{op:yi(t.type)}:{}}})}function qh(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!zs(s))return;const o=(s.filters??[]).filter(l=>l.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function Uh(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function Xh(e,t){for(const r of e.tiles){const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Yh=j.createSvgIcon(y.jsx("path",{d:"M3 17v2h6v-2zM3 5v2h10V5zm10 16v-2h8v-2h-8v-2h-2v6zM7 9v2H3v2h4v2h2V9zm14 4v-2H11v2zm-6-4h2V7h4V5h-4V3h-2z"})),Zh=j.createSvgIcon(y.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"})),Qh=j.createSvgIcon(y.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),Jh=j.createSvgIcon(y.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),Ws=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),Xi=Ws?"⌘":"Ctrl+",ep=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"};function tp(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e}),S.useEffect(()=>{const n=r=>{const i=t.current,s=Ws?r.metaKey:r.ctrlKey,o=r.key.toLowerCase();if(r.key==="Escape"){i.escape();return}if(!ep(r.target)){if(s&&o==="z"){r.preventDefault(),r.shiftKey?i.redo():i.undo();return}if(!Ws&&s&&o==="y"){r.preventDefault(),i.redo();return}if(s&&o==="s"){r.preventDefault(),i.save?.();return}!s&&!r.altKey&&!r.shiftKey&&(r.key==="ArrowLeft"||r.key==="ArrowRight")&&(r.preventDefault(),i.nudge(r.key==="ArrowRight"?1:-1))}};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[])}function np({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,actions:a,onAddTile:l,onSettings:d}){const{theme:u}=Le.usePublisherTheme();return y.jsxs(j.DashboardBar,{left:y.jsx(k.Chip,{size:"medium",variant:"outlined",icon:y.jsx(Zh,{sx:{fontSize:20}}),label:"Editing",sx:{height:37,fontSize:"0.875rem",fontWeight:500,border:u.border,color:u.tileTitle,"& .MuiChip-icon":{color:"inherit"},"& .MuiChip-label":{fontSize:"0.875rem"}}}),children:[l&&y.jsx(k.Button,{startIcon:y.jsx(j.AddIcon,{}),onClick:l,"aria-label":"Add tile",children:"Tile"}),y.jsx(k.Button,{startIcon:y.jsx(Yh,{}),onClick:c=>d(c.currentTarget),children:"Settings"}),y.jsx(k.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),y.jsx(k.Tooltip,{title:`Undo (${Xi}Z)`,children:y.jsx("span",{children:y.jsx(k.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:y.jsx(Jh,{fontSize:"small"})})})}),y.jsx(k.Tooltip,{title:`Redo (${Xi}⇧Z)`,children:y.jsx("span",{children:y.jsx(k.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:y.jsx(Qh,{fontSize:"small"})})})}),o&&y.jsx(y.Fragment,{children:y.jsx(k.Tooltip,{title:i?`Save (${Xi}S)`:"",children:y.jsx("span",{children:y.jsx(k.Button,{variant:i?"contained":"outlined",disabled:!i||s,onClick:o,startIcon:!i&&!s?y.jsx(j.CheckIcon,{}):void 0,sx:{minWidth:124},children:s?"Saving…":i?"Save changes":"Saved"})})})}),a&&y.jsxs(y.Fragment,{children:[y.jsx(k.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),a]})]})}const rp=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"];function Lr(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function ka(e){for(const t of e??[]){const n=/^#\s*([a-z_]+)/.exec(t.trim())?.[1];if(n&&rp.includes(n))return n}}const ip=1;function fd(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...fd(a,`${t}${s}.`,n-1))}}}return r}function sp(e){const t=new Map;for(const n of e.sourceInfos??[]){let r;try{r=typeof n=="string"?JSON.parse(n):n}catch{continue}const i=r;i?.name&&t.set(i.name,fd(i.schema?.fields,"",ip))}return t}function Sa(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const op=e=>(e??"").startsWith("dashboards/"),ap=e=>e.modelPath??e.path??"";function hd(e){const t=[],n=new Set;for(const r of e){const i=ap(r);if(op(i))continue;const s=sp(r);for(const o of r.sources??[]){const a=o.name;if(!a||n.has(a))continue;n.add(a);const l=(o.givens??[]).map(d=>d.name).filter(d=>typeof d=="string");t.push({name:a,modelPath:i,...Lr(o.annotations)?{description:Lr(o.annotations)}:{},views:(o.views??[]).filter(d=>typeof d.name=="string").map(d=>({name:d.name,...Lr(d.annotations)?{description:Lr(d.annotations)}:{},...ka(d.annotations)?{chart:ka(d.annotations)}:{}})),givens:l,fields:s.get(a)??[]})}}return{sources:t}}const ht=e=>`${e.source}.${e.name}`;function lp(e,t){if(!t)return[];const n=new Set;for(const r of e.sources)n.add(r.base);for(const r of e.imports)if(r.kind==="names")for(const i of r.names)n.add(i);return t.sources.filter(r=>n.has(r.name))}function cp({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s}){const{theme:o}=Le.usePublisherTheme(),a=S.useMemo(()=>lp(t,n),[t,n]),[l,d]=S.useState(""),[u,c]=S.useState(""),[h,f]=S.useState(""),[g,m]=S.useState(Math.ceil(r/2));S.useEffect(()=>{e&&(d(t.sources[0]?.base??a[0]?.name??""),c(""),f(""),m(Math.ceil(r/2)))},[e,t,a,r]);const w=a.find(v=>v.name===l),b=l!==""&&u!=="";return y.jsx(j.AppDialog,{open:e,onClose:i,title:"Add a tile",description:"A tile shows one view of one source this dashboard imports.",actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:i,children:"Cancel"}),y.jsx(k.Button,{variant:"contained",disabled:!b,onClick:()=>s({base:l,view:u,...h.trim()?{label:h.trim()}:{},colspan:g}),children:"Add tile"})]}),children:y.jsx(k.Stack,{sx:{gap:2,pt:1},children:a.length===0?y.jsx(k.Typography,{variant:"body2",sx:{color:o.tileTitle},children:n?"This dashboard imports no source by name, so there is nothing to put a tile on. Import a source in the file first.":"The package's sources are still loading."}):y.jsxs(y.Fragment,{children:[y.jsx(k.TextField,{select:!0,size:"small",label:"Source",value:l,onChange:v=>{d(v.target.value),c("")},inputProps:{"aria-label":"Source"},children:a.map(v=>y.jsxs(k.MenuItem,{value:v.name,children:[v.name,v.description&&y.jsx(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:v.description})]},v.name))}),y.jsxs(k.Box,{children:[y.jsx(k.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),y.jsxs(k.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:280,overflowY:"auto",border:o.border,borderRadius:1},children:[(w?.views??[]).map(v=>y.jsxs(k.ListItemButton,{selected:u===v.name,onClick:()=>c(v.name),"aria-label":`View ${v.name}`,children:[y.jsx(k.ListItemText,{primary:v.name,secondary:v.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),v.chart&&y.jsx(k.Chip,{size:"small",variant:"outlined",label:v.chart.replace(/_chart$/,"")})]},v.name)),w&&w.views.length===0&&y.jsx(k.Typography,{variant:"body2",sx:{p:1.5,color:o.tileTitle},children:"This source declares no views."})]})]}),y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5},children:[y.jsx(k.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:h,onChange:v=>f(v.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}}),y.jsx(k.TextField,{size:"small",type:"number",label:`Width (of ${r})`,value:g,onChange:v=>m(Math.min(Math.max(Number(v.target.value)||1,1),r)),inputProps:{min:1,max:r,"aria-label":"Tile width"},sx:{width:140}})]})]})})})}const $a=4e3;function dp(e,t){const n=e.split(`
67
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function lh(e,t="hidden"){return U(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const i=ch(n,r.registry.droppables),s=[],o=nf(n),{remove:a}=o;return dh(i,o,s),uh(o,t),o.remove=()=>{s.forEach(l=>l()),a.call(o)},o})}function ch(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const i=`${Cr}${Cs("dom-id")}`;r.element.setAttribute(i,""),n.set(r,i)}return n}function dh(e,t,n){for(const[r,i]of e){if(!r.element)continue;const s=`[${i}]`,o=t.matches(s)?t:t.querySelector(s);if(r.element.removeAttribute(i),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(i),Es.set(a,o),n.push(()=>{Es.delete(a),r.proxy=void 0})}}function uh(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(wi,t)}function Hc(e,t){return e===t?!0:wn(e)===wn(t)}function Sa(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Vt(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>vn(t))}function js(e){return e.tagName==="TR"}function fh(e,t,n){const r=new MutationObserver(i=>{let s=!1;for(const o of i){if(o.target!==e){s=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||sh.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(fr(e)&&fr(t)){const u=e.style;for(const c of Array.from(t.style))u.getPropertyValue(c)===""&&t.style.removeProperty(c);for(const c of Array.from(u)){if(oh.includes(c)||c.startsWith(Oe))continue;const d=u.getPropertyValue(c);t.style.setProperty(c,d)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}s&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function hh(e,t,n){const r=new MutationObserver(i=>{for(const s of i)if(s.addedNodes.length!==0)for(const o of Array.from(s.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),vn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),vn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),vn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function ph(e){return new ResizeObserver(()=>{var t,n,r;const i=new ct(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-i.width)*s.x+e.delta.x,a=(e.height-i.height)*s.y+e.delta.y,l=wc();if(e.styles.set({width:i.width-e.widthOffset,height:i.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Oe),(n=e.getElementMutationObserver())==null||n.takeRecords(),js(e.element)&&js(e.placeholder)){const v=Array.from(e.element.cells),w=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(x=>x.style.width));for(const[x,m]of v.entries()){const p=w[x];m.style.width=`${p.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},c=e.left+o+l.x+u.x,d=e.top+a+l.y+u.y,h=i.width-e.widthOffset,f=i.height-e.heightOffset,g=e.frameTransform;e.dragOperation.shape=new dt(c*g.scaleX+g.x,d*g.scaleY+g.y,h*g.scaleX,f*g.scaleY)})}var gh=250,vh="ease";function mh(e){var t,n,r,i;const{animation:s}=e;if(typeof s=="function"){const m=s({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(m).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=gh,easing:a=vh}=s??{};vn(e.feedbackElement);const[,l]=(t=yc(e.feedbackElement,m=>"translate"in m))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Hc(e.feedbackElement,u)?null:void 0},d=new ct(e.feedbackElement,c),h=(r=yr(ht(e.feedbackElement).translate))!=null?r:e.translate,f=new ct(u,c),g=dt.delta(d,f,e.alignment),v={x:h.x-g.x,y:h.y-g.y},w=Math.round(d.intrinsicHeight)!==Math.round(f.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${f.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${f.intrinsicHeight}px`]}:{},x=Math.round(d.intrinsicWidth)!==Math.round(f.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${f.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${f.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Oe),e.feedbackElement.setAttribute(Is,""),(i=e.getElementMutationObserver())==null||i.takeRecords(),Pc({element:e.feedbackElement,keyframes:zo(xr(xr({},w),x),{translate:[`${h.x}px ${h.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:Ao(Ke(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Is),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var qc,As,wr,Bo,ii,Kc,Yc,Sn=class extends(As=Pe,qc=[H],As){constructor(t,n){super(t,n),ge(this,ii),ge(this,Bo,we(wr,8,this)),we(wr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Li),i=r?.register(ah);if(i){const s=this.destroy.bind(this);this.destroy=()=>{i(),s()}}this.registerEffect(Gt(this,ii,Kc).bind(this,r)),this.registerEffect(Gt(this,ii,Yc))}};wr=Rn(As);Bo=new WeakMap;ii=new WeakSet;Kc=function(e){const{overlay:t}=this;if(!t||!e)return;const n=pi(t);if(n)return e.addRoot(n)};Yc=function(){var e,t,n,r,i,s,o;const{state:a,manager:l,options:u}=this,{dragOperation:c}=l,{position:d,source:h,status:f}=c;if(f.idle){a.current={},a.initial={};return}if(!h)return;const{element:g}=h,v=h.pluginConfig(Sn),w=(t=(e=v?.feedback)!=null?e:u?.feedback)!=null?t:"default",x=typeof w=="function"?w(h,l):w;if(!g||x==="none"||!f.initialized||f.initializing)return;const{initial:m}=a,p=(n=this.overlay)!=null?n:g,b=_n(p),_=_n(g),$=!Hc(g,p),O=new ct(g,{frameTransform:$?_:null,ignoreTransforms:!$}),D={x:_.scaleX/b.scaleX,y:_.scaleY/b.scaleY};let{width:M,height:I,top:K,left:z}=O;$&&(M=M/D.x,I=I/D.y);const C=new Rf(p),W=ht(g),{transition:Y,translate:ve,boxSizing:Me,paddingBlockStart:se,paddingBlockEnd:Le,paddingInlineStart:Ve,paddingInlineEnd:Te,borderInlineStartWidth:Ye,borderInlineEndWidth:Ge,borderBlockStartWidth:We,borderBlockEndWidth:Xe}=W,Se=Y.split(",").filter(Z=>!/^\s*(transform|translate|scale)\b/.test(Z)).join(","),ue=Ri(W),L=W.transform,V=x==="clone",_e=Me==="content-box",X=_e?parseInt(Ve)+parseInt(Te)+parseInt(Ye)+parseInt(Ge):0,ze=_e?parseInt(se)+parseInt(Le)+parseInt(We)+parseInt(Xe):0,te=x!=="move"&&!this.overlay?lh(h,V?"clone":"hidden"):null,at=U(()=>br(l.dragOperation.activatorEvent));if(!m.translate){if(this.overlay&&ue)m.translate={x:ue.x,y:ue.y};else if(ve!=="none"){const Z=yr(ve);Z&&(m.translate=Z)}}if(!m.transformOrigin){const Z=U(()=>d.current),R=z+((r=ue?.x)!=null?r:0),ee=K+((i=ue?.y)!=null?i:0);m.transformOrigin={x:(Z.x-R*b.scaleX-b.x)/(M*b.scaleX),y:(Z.y-ee*b.scaleY-b.y)/(I*b.scaleY)}}const{transformOrigin:Fe}=m,xt=K*b.scaleY+b.y,T=z*b.scaleX+b.x;if(!m.coordinates&&(m.coordinates={x:T,y:xt},D.x!==1||D.y!==1)){const{scaleX:Z,scaleY:R}=_,{x:ee,y:Ee}=Fe;m.coordinates.x+=(M*Z-M)*ee,m.coordinates.y+=(I*R-I)*Ee}m.dimensions||(m.dimensions={width:M,height:I}),m.frameTransform||(m.frameTransform=b);const A={x:m.coordinates.x-T,y:m.coordinates.y-xt},G={width:(m.dimensions.width*m.frameTransform.scaleX-M*b.scaleX)*Fe.x,height:(m.dimensions.height*m.frameTransform.scaleY-I*b.scaleY)*Fe.y},E={x:A.x/b.scaleX+G.width,y:A.y/b.scaleY+G.height},P={left:z+E.x,top:K+E.y};p.setAttribute(lt,"true");const B=U(()=>c.transform),Q=(s=m.translate)!=null?s:{x:0,y:0},Ue=B.x*b.scaleX+Q.x,ke=B.y*b.scaleY+Q.y,ie=wc();C.set({width:M-X,height:I-ze,top:P.top+ie.y,left:P.left+ie.x,translate:`${Ue}px ${ke}px 0`,transform:this.overlay?"none":L,transition:Se?`${Se}, translate 0ms linear`:"translate 0ms linear",scale:$?`${D.x} ${D.y}`:"","transform-origin":`${Fe.x*100}% ${Fe.y*100}%`},Oe),te&&(g.insertAdjacentElement("afterend",te),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(h):u.rootElement).appendChild(g)),Ds(p)&&(p.hasAttribute("popover")||p.setAttribute("popover","manual"),vn(p),p.addEventListener("beforetoggle",Sa));let $e,Qt,Ct;const Rr=ph({placeholder:te,element:g,feedbackElement:p,frameTransform:b,transformOrigin:Fe,width:M,height:I,top:K,left:z,widthOffset:X,heightOffset:ze,delta:E,styles:C,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>$e,getSavedCellWidths:()=>Ct,setSavedCellWidths:Z=>{Ct=Z}}),Pt=new ct(p);U(()=>c.shape=Pt);const Zt=Ke(p),Wn=Z=>{this.manager.actions.stop({event:Z})},na=Ao(Zt);at&&Zt.addEventListener("resize",Wn),U(()=>h.status)==="idle"&&requestAnimationFrame(()=>h.status="dragging"),te&&(Rr.observe(te),$e=fh(g,te,V),Qt=hh(g,te,p));const Lr=(o=l.dragOperation.source)==null?void 0:o.id,zn=()=>{var Z;if(!at||Lr==null)return;const R=l.registry.draggables.get(Lr),ee=(Z=R?.handle)!=null?Z:R?.element;Dt(ee)&&ee.focus()},Fn=()=>{$e?.disconnect(),Qt?.disconnect(),Rr.disconnect(),Zt.removeEventListener("resize",Wn),Ds(p)&&(p.removeEventListener("beforetoggle",Sa),p.removeAttribute("popover")),p.removeAttribute(lt),C.reset();const Z=()=>{var R;if(Ct&&js(g)){const fe=Array.from(g.cells);for(const[oe,Jt]of fe.entries())Jt.style.width=(R=Ct[oe])!=null?R:""}h.status="idle";const ee=a.current.translate!=null,Ee=c.status.dragging;te&&(!Ee&&ee||te.parentElement!==p.parentElement)&&p.isConnected&&te.replaceWith(p),te?.remove()};p===this.overlay?setTimeout(Z,0):Z()},Vi=u?.dropAnimation,Nn=this,Gi=$r(()=>{var Z,R,ee;const{transform:Ee,status:fe}=c;if(!(!Ee.x&&!Ee.y&&!a.current.translate)&&fe.dragging){const oe=(Z=m.translate)!=null?Z:{x:0,y:0},Jt={x:Ee.x/b.scaleX+oe.x,y:Ee.y/b.scaleY+oe.y},ra=a.current.translate,Zd=U(()=>c.modifiers),Ui=U(()=>{var Vn;return(Vn=c.shape)==null?void 0:Vn.current}),Bn=u?.keyboardTransition,ia=at&&!na&&Bn!==null?`${(R=Bn?.duration)!=null?R:250}ms ${(ee=Bn?.easing)!=null?ee:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(C.set({transition:Se?`${Se}, translate ${ia}`:`translate ${ia}`,translate:`${Jt.x}px ${Jt.y}px 0`},Oe),$e?.takeRecords(),Ui&&Ui!==Pt&&ra&&!Zd.length){const Vn=Ze.delta(Jt,ra);c.shape=dt.from(Ui.boundingRectangle).translate(Vn.x*b.scaleX,Vn.y*b.scaleY)}else c.shape=new ct(p);a.current.translate=Jt}},function(){if(c.status.dropped){this.dispose(),h.status="dropping";const Z=v?.dropAnimation!==void 0?v.dropAnimation:Nn.dropAnimation!==void 0?Nn.dropAnimation:Vi;let R=a.current.translate;const ee=R!=null;if(!R&&g!==p&&(R={x:0,y:0}),!R||Z===null){Fn();return}l.renderer.rendering.then(()=>{mh({source:h,element:g,feedbackElement:p,placeholder:te,translate:R,moved:ee,transition:Y,alignment:h.alignment,styles:C,animation:Z??void 0,getElementMutationObserver:()=>$e,cleanup:Fn,restoreFocus:zn})})}});return()=>{Fn(),Gi()}};nt(wr,4,"overlay",qc,Sn,Bo);Xt(wr,Sn);Sn.configure=Or(Sn);var Vo=Sn,Gn=!0,yh=!1,Xc,Qc,Zc,Jc,St,Go,Uo;Jc=(Zc=[H],Je.Forward),Qc=(Xc=[H],Je.Reverse);var _r=class{constructor(){ge(this,Go,we(St,8,this,Gn)),we(St,11,this),ge(this,Uo,we(St,12,this,Gn)),we(St,15,this)}isLocked(e){return e===Je.Idle?!1:e==null?this[Je.Forward]===Gn&&this[Je.Reverse]===Gn:this[e]===Gn}unlock(e){e!==Je.Idle&&(this[e]=yh)}};St=Rn(null);Go=new WeakMap;Uo=new WeakMap;nt(St,4,Jc,Zc,_r,Go);nt(St,4,Qc,Xc,_r,Uo);Xt(St,_r);var bh=[Je.Forward,Je.Reverse],$a=class{constructor(){this.x=new _r,this.y=new _r}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},xh=class extends Pe{constructor(e){super(e);const t=En(new $a);let n=null;this.signal=t,tt(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new $a;return}const{delta:i}=e.dragOperation.position;if(n){const s={x:Ea(i.x,n.x),y:Ea(i.y,n.y)},o=t.peek();de(()=>{for(const a of Dl)for(const l of bh)s[a]===l&&o[a].unlock(l);t.value=o})}n=i})}get current(){return this.signal.peek()}};function Ea(e,t){return Math.sign(e-t)}var ed,Rs,kr,Ho,_t,Ls,Pr=class extends(Rs=Dr,ed=[H],Rs){constructor(e){super(e),ge(this,Ho,we(kr,8,this,!1)),we(kr,11,this),ge(this,_t),ge(this,Ls,()=>{if(!ne(this,_t))return;const{element:s,by:o}=ne(this,_t);o.y&&(s.scrollTop+=o.y),o.x&&(s.scrollLeft+=o.x)}),this.scroll=(s,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return Ae(this,_t,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=s??{},h=d?{x:Oa(d.x),y:Oa(d.y)}:void 0,f=h?void 0:this.scrollIntentTracker.current;if(f?.isLocked())return!1;for(const g of l){const v=vf(g,d);if(v.x||v.y){const{speed:w,direction:x}=Of(g,c,h,o?.acceleration,o?.threshold);if(f)for(const m of Dl)f[m].isLocked(x[m])&&(w[m]=0,x[m]=0);if(x.x||x.y){const{x:m,y:p}=d??x,b=m*w.x,_=p*w.y;if(b||_){const $=(a=ne(this,_t))==null?void 0:a.by;if(this.autoScrolling&&$&&($.x&&!b||$.y&&!_))continue;return Ae(this,_t,{element:g,by:{x:b,y:_}}),mi.schedule(ne(this,Ls)),!0}}}}}return Ae(this,_t,void 0),!1};let t=null,n=null;const r=fs(()=>{const{position:s,source:o}=e.dragOperation;if(!s)return null;const a=_c(pi(o?.element),s.current);return a&&(t=a),a??t}),i=fs(()=>{const s=r.value,{documentElement:o}=jn(s);if(!s||s===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=Ts(l,{excludeElement:!1});return n=u,u}}if(s){const a=Ts(s,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},rt);this.getScrollableElements=()=>i.value,this.scrollIntentTracker=new xh(e),this.destroy=e.monitor.addEventListener("dragmove",s=>{this.disabled||s.defaultPrevented||!br(e.dragOperation.activatorEvent)||!s.by||this.scroll({by:s.by})&&s.preventDefault()})}};kr=Rn(Rs);Ho=new WeakMap;_t=new WeakMap;Ls=new WeakMap;nt(kr,4,"autoScrolling",ed,Pr,Ho);Xt(kr,Pr);function Oa(e){return e>0?Je.Forward:e<0?Je.Reverse:Je.Idle}var wh=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},_h=new wh(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),kh=10,Ws=class extends Pe{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Pr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=tt(()=>{var i,s,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(i=this.options)==null?void 0:i.acceleration,threshold:typeof((s=this.options)==null?void 0:s.threshold)=="number"?{x:this.options.threshold,y:this.options.threshold}:(o=this.options)==null?void 0:o.threshold};if(r.scroll(void 0,u)){r.autoScrolling=!0;const d=setInterval(()=>_h.schedule(()=>r.scroll(void 0,u)),kh);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};Ws.configure=Or(Ws);var td=Ws,Da={capture:!0,passive:!0},nr,Sh=class extends Dr{constructor(e){super(e),ge(this,nr),this.handleScroll=()=>{ne(this,nr)==null&&Ae(this,nr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),Ae(this,nr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=tt(()=>{var n,r,i;if(t.status.dragging){const o=(i=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?i:document;return o.addEventListener("scroll",this.handleScroll,Da),()=>{o.removeEventListener("scroll",this.handleScroll,Da)}}})}};nr=new WeakMap;var $h="* { user-select: none !important; -webkit-user-select: none !important; }",Eh=class extends Pe{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Li),n=t?.register($h);if(this.destroy=tt(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return Ji(),document.addEventListener("selectionchange",Ji,{capture:!0}),()=>{document.removeEventListener("selectionchange",Ji,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function Ji(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var rr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),dn,_i=class extends bn{constructor(t,n){super(t),this.manager=t,this.options=n,ge(this,dn,[]),this.listeners=new kc,this.handleSourceKeyDown=(r,i,s)=>{if(this.disabled||r.defaultPrevented||!Vt(r.target)||i.disabled)return;const{keyboardCodes:o=rr.keyboardCodes,preventActivation:a=rr.preventActivation}=s??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,i)||this.handleStart(r,i,s))}}bind(t,n=this.options){return tt(()=>{var i;const s=(i=t.handle)!=null?i:t.element,o=a=>{br(a)&&this.handleSourceKeyDown(a,t,n)};if(s)return s.addEventListener("keydown",o),()=>{s.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:i}=n;if(!i)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),Cc(i);const{center:s}=new ct(i);if(this.manager.actions.start({event:t,coordinates:{x:s.x,y:s.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=jn(i),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];ne(this,dn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:i=rr.keyboardCodes}=r??{};if(en(t,[...i.end,...i.cancel])){t.preventDefault();const s=en(t,i.cancel);this.handleEnd(t,s);return}en(t,i.up)?this.handleMove("up",t):en(t,i.down)&&this.handleMove("down",t),en(t,i.left)?this.handleMove("left",t):en(t,i.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,i;const{shape:s}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(i=(r=this.options)==null?void 0:r.offset)!=null?i:rr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!s){switch(t){case"up":a={x:0,y:-l.y*o};break;case"down":a={x:0,y:l.y*o};break;case"left":a={x:-l.x*o,y:0};break;case"right":a={x:l.x*o,y:0};break}(a.x||a.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:a}))}}sideEffects(){const t=this.manager.registry.plugins.get(td);t?.disabled===!1&&(t.disable(),ne(this,dn).push(()=>{t.enable()}))}cleanup(){ne(this,dn).forEach(t=>t()),Ae(this,dn,[])}destroy(){this.cleanup(),this.listeners.clear()}};dn=new WeakMap;_i.configure=Or(_i);_i.defaults=rr;var nd=_i;function en(e,t){return t.includes(e.code)}var Wt,Oh=class extends oc{constructor(){super(...arguments),ge(this,Wt)}onEvent(e){switch(e.type){case"pointerdown":Ae(this,Wt,xn(e));break;case"pointermove":if(!ne(this,Wt))return;const{x:t,y:n}=xn(e),r={x:t-ne(this,Wt).x,y:n-ne(this,Wt).y},{tolerance:i}=this.options;if(i&&ws(r,i)){this.abort();return}ws(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){Ae(this,Wt,void 0)}};Wt=new WeakMap;var un,zt,Dh=class extends oc{constructor(){super(...arguments),ge(this,un),ge(this,zt)}onEvent(e){switch(e.type){case"pointerdown":Ae(this,zt,xn(e)),Ae(this,un,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ne(this,zt))return;const{x:t,y:n}=xn(e),r={x:t-ne(this,zt).x,y:n-ne(this,zt).y};ws(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ne(this,un)&&(clearTimeout(ne(this,un)),Ae(this,zt,void 0),Ae(this,un,void 0))}};un=new WeakMap;zt=new WeakMap;var gn=class{};gn.Delay=Dh;gn.Distance=Oh;var zs=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:i}=e;if(!(r==="mouse"&&Vt(i)&&(t.handle===i||(n=t.handle)!=null&&n.contains(i))))return r==="touch"?[new gn.Delay({value:250,tolerance:5})]:Wf(i)&&!e.defaultPrevented?[new gn.Delay({value:200,tolerance:0})]:[new gn.Delay({value:200,tolerance:10}),new gn.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;if(r===t.element||r===t.handle||!Vt(r)||(n=t.handle)!=null&&n.contains(r))return!1;const i=sf(r);return i===t.element?!1:!!i}}),fn,ki=class extends bn{constructor(t,n){super(t),this.manager=t,this.options=n,ge(this,fn,new Set),this.listeners=new kc,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:i}=this.latest;!r||!i||this.manager.actions.move({event:r,to:i})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:i=zs.activationConstraints}=r??{};return typeof i=="function"?i(t,n):i}bind(t,n=this.options){return tt(()=>{var i;const s=new AbortController,{signal:o}=s,a=u=>{Lf(u)&&this.handlePointerDown(u,t,n)};let l=[(i=t.handle)!=null?i:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(Ph(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:o}));return()=>s.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Vt(t.target)||n.disabled||Th(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:i=zs.preventActivation}=r??{};if(i?.(t,n))return;const{target:s}=t,o=Dt(s)&&s.draggable&&s.getAttribute("draggable")==="true",a=_n(n.element),{x:l,y:u}=xn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:u*a.scaleY+a.y};const c=this.activationConstraints(t,n,r);t.sensor=this;const d=new Yu(c,v=>this.handleStart(n,v));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const h=$s(),f=this.listeners.bind(h,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:o?this.handleCancel:Nr,options:{capture:!0}}]),g=()=>{f(),this.initialCoordinates=void 0};ne(this,fn).add(g)}handlePointerMove(t,n){var r,i;if(((r=this.controller)==null?void 0:r.activated)===!1){(i=this.controller)==null||i.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const s=xn(t),o=_n(n.element);s.x=s.x*o.scaleX+o.x,s.y=s.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=s,mi.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:i}=this;if(!i||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:i,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=jn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Vt(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:Nr,options:{passive:!1}},{type:"click",listener:Nr},{type:"contextmenu",listener:Nr},{type:"keydown",listener:this.handleKeyDown}]);ne(this,fn).add(u)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){const{controller:t}=this;this.controller=void 0,t&&!t.signal.aborted&&t.abort(),this.latest={event:void 0,coordinates:void 0},ne(this,fn).forEach(n=>n()),ne(this,fn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;ki.configure=Or(ki);ki.defaults=zs;var Fs=ki;function Th(e){return"sensor"in e}function Nr(e){e.preventDefault()}function Ch(){}var Ta=new WeakSet;function Ph(e){!e||Ta.has(e)||(e.addEventListener("touchmove",Ch,{capture:!1,passive:!1}),Ta.add(e))}var mn={modifiers:[],plugins:[nh,td,ih,Vo,Eh],sensors:[Fs,nd]},rd=class extends Zu{constructor(e={}){const t=st(e.plugins,mn.plugins),n=st(e.sensors,mn.sensors),r=st(e.modifiers,mn.modifiers);super(zo(xr({},e),{plugins:[Sh,Pr,Li,...t],sensors:n,modifiers:r}))}},id,sd,Ns,$t,qo,Ko,Wi=class extends(Ns=ut,sd=[H],id=[H],Ns){constructor(e,t){var n=e,{element:r,effects:i=()=>[],handle:s}=n,o=Rc(n,["element","effects","handle"]);super(xr({effects:()=>[...i(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(gr))!=null?l:[...u.sensors]).map(h=>{const f=h instanceof bn?h:u.registry.register(h.plugin),g=h instanceof bn?void 0:h.options;return f.bind(this,g)});return function(){d.forEach(f=>f())}}]},o),t),ge(this,qo,we($t,8,this)),we($t,11,this),ge(this,Ko,we($t,12,this)),we($t,15,this),this.element=r,this.handle=s}};$t=Rn(Ns);qo=new WeakMap;Ko=new WeakMap;nt($t,4,"handle",sd,Wi,qo);nt($t,4,"element",id,Wi,Ko);Xt($t,Wi);var od,ad,Bs,Et,Yo,es,ld,cd,pr,Xo,zi=class extends(Bs=ft,ad=[H],od=[H],Bs){constructor(e,t){var n=e,{element:r,effects:i=()=>[]}=n,s=Rc(n,["element","effects"]);const{collisionDetector:o=Mc}=s,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const h=new ct(d),f=U(()=>this.shape);return h&&f?.equals(h)?f:(this.shape=h,h)},l=En(!1);super(zo(xr({},s),{collisionDetector:o,effects:()=>[...i(),()=>{const{element:u,manager:c}=this;if(!c)return;const{dragOperation:d}=c,{source:h}=d;l.value=!!(h&&d.status.initialized&&u&&!this.disabled&&this.accepts(h))},()=>{const{element:u}=this;if(l.value&&u){const c=new gf(u,a);return()=>{c.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),ge(this,pr),ge(this,Yo,we(Et,8,this)),we(Et,11,this),ge(this,Xo,we(Et,12,this)),we(Et,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){Ae(this,pr,e,cd)}get element(){var e;return(e=this.proxy)!=null?e:ne(this,pr,ld)}};Et=Rn(Bs);Yo=new WeakMap;pr=new WeakSet;Xo=new WeakMap;es=nt(Et,20,"#element",ad,pr,Yo),ld=es.get,cd=es.set;nt(Et,4,"proxy",od,zi,Xo);Xt(Et,zi);function Mh(e){return e!=null&&typeof e=="object"&&"current"in e}function yn(e){var t;if(e!=null)return Mh(e)?(t=e.current)!=null?t:void 0:e}var Ih=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ln=Ih?S.useLayoutEffect:S.useEffect;function jh(){const e=S.useState(0)[1];return S.useCallback(()=>{e(t=>t+1)},[e])}function dd(e,t){const n=S.useRef(new Map),r=jh();return Ln(()=>{if(!e){n.current.clear();return}return tt(()=>{var i;let s=!1,o=!1;for(const a of n.current){const[l]=a,u=U(()=>a[1]),c=e[l];u!==c&&(s=!0,n.current.set(l,c),o=(i=t?.(l,u,c))!=null?i:!1)}s&&(o?queueMicrotask(()=>su.flushSync(r)):r())})},[e]),S.useMemo(()=>e&&new Proxy(e,{get(i,s){const o=i[s];return n.current.set(s,o),o}}),[e])}function Ah(e,t){e()}function tn(e){const t=S.useRef(e);return Ln(()=>{t.current=e},[e]),t}function ae(e,t,n=S.useEffect,r=Object.is){const i=S.useRef(e);n(()=>{const s=i.current;r(e,s)||(i.current=e,t(e,s))},[t,e])}function si(e,t){const n=S.useRef(yn(e));Ln(()=>{const r=yn(e);r!==n.current&&(n.current=r,t(r))})}var Rh=Object.defineProperty,Lh=Object.defineProperties,Wh=Object.getOwnPropertyDescriptors,Si=Object.getOwnPropertySymbols,ud=Object.prototype.hasOwnProperty,fd=Object.prototype.propertyIsEnumerable,Ca=(e,t,n)=>t in e?Rh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zh=(e,t)=>{for(var n in t||(t={}))ud.call(t,n)&&Ca(e,n,t[n]);if(Si)for(var n of Si(t))fd.call(t,n)&&Ca(e,n,t[n]);return e},Fh=(e,t)=>Lh(e,Wh(t)),Nh=(e,t)=>{var n={};for(var r in e)ud.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Si)for(var r of Si(e))t.indexOf(r)<0&&fd.call(e,r)&&(n[r]=e[r]);return n},Bh=new rd,hd=S.createContext(Bh),Vh=S.memo(S.forwardRef(({children:e},t)=>{const[n,r]=S.useState(0),i=S.useRef(null),s=S.useRef(null),o=S.useMemo(()=>({renderer:{get rendering(){var a;return(a=i.current)!=null?a:Promise.resolve()}},trackRendering(a){i.current||(i.current=new Promise(l=>{s.current=l})),S.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Ln(()=>{var a;(a=s.current)==null||a.call(s),i.current=null},[e,n]),S.useImperativeHandle(t,()=>o),null})),ts=[void 0,rt];function Gh(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:i,onDragStart:s,onDragMove:o,onDragOver:a,onDragEnd:l}=t,u=Nh(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=S.useRef(null),{plugins:d,modifiers:h,sensors:f}=u,g=st(d,mn.plugins),v=st(f,mn.sensors),w=st(h,mn.modifiers),x=tn(i),m=tn(s),p=tn(a),b=tn(o),_=tn(l),$=tn(r),O=Uh(()=>{var D;return(D=u.manager)!=null?D:new rd(u)});return S.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:D,trackRendering:M}=c.current,{monitor:I}=O;O.renderer=D;const K=[I.addEventListener("beforedragstart",z=>{const C=x.current;C&&M(()=>C(z,O))}),I.addEventListener("dragstart",z=>{var C;return(C=m.current)==null?void 0:C.call(m,z,O)}),I.addEventListener("dragover",z=>{const C=p.current;C&&M(()=>C(z,O))}),I.addEventListener("dragmove",z=>{const C=b.current;C&&M(()=>C(z,O))}),I.addEventListener("dragend",z=>{const C=_.current;C&&M(()=>C(z,O))}),I.addEventListener("collision",z=>{var C;return(C=$.current)==null?void 0:C.call($,z,O)})];return()=>K.forEach(z=>z())},[O]),ae(g,()=>O&&(O.plugins=g),...ts),ae(v,()=>O&&(O.sensors=v),...ts),ae(w,()=>O&&(O.modifiers=w),...ts),y.jsxs(hd.Provider,{value:O,children:[y.jsx(Vh,{ref:c,children:n}),n]})}function Uh(e){const t=S.useRef(null);return t.current||(t.current=e()),S.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function Hh(){return S.useContext(hd)}function pd(e){var t;const n=(t=Hh())!=null?t:void 0,[r]=S.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Ln(r.register,[n,r]),r}var qh=Object.create,gd=Object.defineProperty,Kh=Object.getOwnPropertyDescriptor,vd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Fi=e=>{throw TypeError(e)},Yh=(e,t,n)=>t in e?gd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xh=e=>{var t;return[,,,qh((t=e?.[vd("metadata")])!=null?t:null)]},md=["class","method","getter","setter","accessor","field","value","get","set"],yd=e=>e!==void 0&&typeof e!="function"?Fi("Function expected"):e,Qh=(e,t,n,r,i)=>({kind:md[e],name:t,metadata:r,addInitializer:s=>n._?Fi("Already initialized"):i.push(yd(s||null))}),Zh=(e,t)=>Yh(t,vd("metadata"),e[3]),Jh=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)s[i].call(n);return r},bd=(e,t,n,r,i,s)=>{for(var o,a,l,u,c=t&7,d=!1,h=!1,f=2,g=md[c+5],v=e[f]||(e[f]=[]),w=(i=i.prototype,Kh(i,n)),x=r.length-1;x>=0;x--)l=Qh(c,n,a={},e[3],v),l.static=d,l.private=h,u=l.access={has:m=>n in m},u.get=m=>m[n],o=(0,r[x])(w[g],l),a._=1,yd(o)&&(w[g]=o);return w&&gd(i,n,w),i},xd=(e,t,n)=>t.has(e)||Fi("Cannot "+n),ep=(e,t,n)=>(xd(e,t,"read from private field"),t.get(e)),tp=(e,t,n)=>t.has(e)?Fi("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),np=(e,t,n,r)=>(xd(e,t,"write to private field"),t.set(e,n),n),Nt=class Vs{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Vs(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Vs(t,n)}},wd,_d,Gs,oi,Mr,Qo=class extends(Gs=Kt,_d=[pe],wd=[pe],Gs){constructor(e){const t=Nt.from(e);super(t,(n,r)=>Nt.equals(n,r)),Jh(Mr,5,this),tp(this,oi,0),this.velocity={x:0,y:0}}get delta(){return Nt.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=Nt.from(e),r={x:n.x-t.x,y:n.y-t.y},i=Date.now(),s=i-ep(this,oi),o=a=>Math.round(a/s*100);de(()=>{np(this,oi,i),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(Nt.from(e)),this.velocity={x:0,y:0}}};Mr=Xh(Gs);oi=new WeakMap;bd(Mr,2,"delta",_d,Qo);bd(Mr,2,"direction",wd,Qo);Zh(Mr,Qo);var kd=(e=>(e.Horizontal="x",e.Vertical="y",e))(kd||{});Object.values(kd);var rp=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const i=Nt.distance(t.shape.center,n);return{id:r,value:1/i,type:In.PointerIntersection,priority:Mn.High}}return null},ip=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:i}=e,s=Nt.distance(t.shape.center,i.current),a=r/(n.current.area+t.shape.area-r)/s;return{id:t.id,value:a,type:In.ShapeIntersection,priority:Mn.Normal}}return null},sp=e=>{var t;return(t=rp(e))!=null?t:ip(e)};function op(e){const{collisionDetector:t,data:n,disabled:r,element:i,id:s,accept:o,type:a}=e,l=pd(c=>new zi(Fh(zh({},e),{register:!1,element:yn(i)}),c)),u=dd(l);return ae(s,()=>l.id=s),si(i,c=>l.element=c),ae(o,()=>l.accept=o,void 0,rt),ae(t,()=>l.collisionDetector=t??sp),ae(n,()=>n&&(l.data=n)),ae(r,()=>l.disabled=r===!0),ae(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:S.useCallback(c=>{var d,h;!c&&((d=l.element)!=null&&d.isConnected)&&!((h=l.manager)!=null&&h.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}function ap(e,t=[]){const n=new Map;for(const s of e.tiles)for(const o of s.filters??[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],i=new Set;for(const s of e.localGivens??[])i.add(s.name),r.push({name:s.name,...s.label===void 0?{}:{label:s.label},type:s.type,...s.suggest?{field:s.suggest.dimension}:{},origin:"dashboard",local:s,boundTiles:n.get(s.name)??0});for(const s of t)i.has(s.name)||(i.add(s.name),r.push({...s,origin:"model",boundTiles:n.get(s.name)??0}));for(const[s,o]of n)i.has(s)||r.push({name:s,origin:"model",boundTiles:o});return r}function $i(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function lp(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function ai(e,t){const n=lp(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const i=new Set(["date","timestamp"]);return i.has(n)?i.has(r):n===r}function Pa(e){switch(e?.replace(/_type$/,"")){case"string":return"text";case"number":return"a number";case"date":return"a date";case"timestamp":return"a timestamp";case"boolean":return"true or false";default:return e??"an unknown type"}}function cp(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const dp=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function up(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",i=/^[A-Z_]/.test(r)?r:`F_${r}`,s=new Set(t);if(!s.has(i))return i;for(let o=2;;o++)if(!s.has(`${i}_${o}`))return`${i}_${o}`}const Ma=[{kind:"select",label:"Pick one",hint:"A dropdown of the field's values"},{kind:"multiselect",label:"Pick several",hint:"The same, taking more than one"},{kind:"text",label:"Text",hint:"A box taking Malloy filter syntax"},{kind:"number",label:"Number range",hint:"A slider over the field's values"},{kind:"date",label:"Since a date",hint:"A date picker; tiles keep rows on or after it"}];function Br(e){const t=e.label.trim()||e.name,n=e.field.split(".").at(-1)??e.field;switch(e.kind){case"select":case"multiselect":return{name:e.name,type:"filter<string>",default:"f''",label:t,control:e.kind,...e.source?{suggest:{source:e.source,dimension:n}}:{}};case"text":return{name:e.name,type:"filter<string>",default:"f''",label:t};case"number":return{name:e.name,type:"filter<number>",default:"f''",label:t,...e.range?{rangeMin:e.range.min,rangeMax:e.range.max}:{}};case"date":return{name:e.name,type:"date",default:`@${e.dateDefault??new Date().toISOString().slice(0,10)}`,label:t}}}const Us=e=>e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function fp(e,t){return e.tiles.map(n=>{const r=(n.filters??[]).find(i=>i.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:$i(t.type)!==void 0?{op:$i(t.type)}:{}}})}function hp(e,t,n){n.forEach((r,i)=>{const s=e.tiles[i];if(!s||!Us(s))return;const o=(s.filters??[]).filter(l=>l.given!==t),a=r.include?[...o,{field:r.field.trim()||t.toLowerCase(),given:t,...r.op&&r.op!=="~"?{op:r.op}:{}}]:o;a.length>0?s.filters=a:delete s.filters})}function pp(e,t){const n=(e.localGivens??[]).filter(s=>s.name!==t.name),r=(e.localGivens??[]).findIndex(s=>s.name===t.name),i=[...n];i.splice(r>=0?r:i.length,0,t),e.localGivens=i}function gp(e,t){for(const r of e.tiles){const i=(r.filters??[]).filter(s=>s.given!==t);i.length>0?r.filters=i:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const vp=j.createSvgIcon(y.jsx("path",{d:"M3 17v2h6v-2zM3 5v2h10V5zm10 16v-2h8v-2h-8v-2h-2v6zM7 9v2H3v2h4v2h2V9zm14 4v-2H11v2zm-6-4h2V7h4V5h-4V3h-2z"})),mp=j.createSvgIcon(y.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"})),yp=j.createSvgIcon(y.jsx("path",{d:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7z"})),bp=j.createSvgIcon(y.jsx("path",{d:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8"})),Hs=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),ns=Hs?"⌘":"Ctrl+",xp=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"};function wp(e){const t=S.useRef(e);S.useEffect(()=>{t.current=e}),S.useEffect(()=>{const n=r=>{const i=t.current,s=Hs?r.metaKey:r.ctrlKey,o=r.key.toLowerCase();if(r.key==="Escape"){i.escape();return}if(!xp(r.target)){if(s&&o==="z"){r.preventDefault(),r.shiftKey?i.redo():i.undo();return}if(!Hs&&s&&o==="y"){r.preventDefault(),i.redo();return}if(s&&o==="s"){r.preventDefault(),i.save?.();return}!s&&!r.altKey&&!r.shiftKey&&(r.key==="ArrowLeft"||r.key==="ArrowRight")&&(r.preventDefault(),i.nudge(r.key==="ArrowRight"?1:-1))}};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[])}function _p({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:i,saving:s,onSave:o,actions:a,onAddTile:l,onSettings:u}){const{theme:c}=Be.usePublisherTheme();return y.jsxs(j.DashboardBar,{left:y.jsx(k.Chip,{size:"medium",variant:"outlined",icon:y.jsx(mp,{sx:{fontSize:20}}),label:"Editing",sx:{height:37,fontSize:"0.875rem",fontWeight:500,border:c.border,color:c.tileTitle,"& .MuiChip-icon":{color:"inherit"},"& .MuiChip-label":{fontSize:"0.875rem"}}}),children:[l&&y.jsx(k.Button,{startIcon:y.jsx(j.AddIcon,{}),onClick:l,"aria-label":"Add tile",children:"Tile"}),y.jsx(k.Button,{startIcon:y.jsx(vp,{}),onClick:d=>u(d.currentTarget),children:"Settings"}),y.jsx(k.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),y.jsx(k.Tooltip,{title:`Undo (${ns}Z)`,children:y.jsx("span",{children:y.jsx(k.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:y.jsx(bp,{fontSize:"small"})})})}),y.jsx(k.Tooltip,{title:`Redo (${ns}⇧Z)`,children:y.jsx("span",{children:y.jsx(k.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:y.jsx(yp,{fontSize:"small"})})})}),o&&y.jsx(y.Fragment,{children:y.jsx(k.Tooltip,{title:i?`Save (${ns}S)`:"",children:y.jsx("span",{children:y.jsx(k.Button,{variant:i?"contained":"outlined",disabled:!i||s,onClick:o,sx:{minWidth:124},children:s?"Saving…":i?"Save changes":"Saved"})})})}),a&&y.jsxs(y.Fragment,{children:[y.jsx(k.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),a]})]})}const kp=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"];function Vr(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Ia(e){for(const t of e??[]){const n=/^#\s*([a-z_]+)/.exec(t.trim())?.[1];if(n&&kp.includes(n))return n}}const Sp=1;function Sd(e,t,n){const r=[];for(const i of e??[]){const s=i.name,o=i.kind;if(typeof s=="string"){if(o==="dimension"||o==="measure"){const a=i.type?.kind;r.push({name:t+s,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=i.schema?.fields;r.push(...Sd(a,`${t}${s}.`,n-1))}}}return r}function $p(e){const t=new Map;for(const n of e.sourceInfos??[]){let r;try{r=typeof n=="string"?JSON.parse(n):n}catch{continue}const i=r;i?.name&&t.set(i.name,Sd(i.schema?.fields,"",Sp))}return t}function ja(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Ep=e=>(e??"").startsWith("dashboards/"),Op=e=>e.modelPath??e.path??"";function $d(e){const t=[],n=new Set;for(const r of e){const i=Op(r);if(Ep(i))continue;const s=$p(r);for(const o of r.sources??[]){const a=o.name;if(!a||n.has(a))continue;n.add(a);const l=(o.givens??[]).map(u=>u.name).filter(u=>typeof u=="string");t.push({name:a,modelPath:i,...Vr(o.annotations)?{description:Vr(o.annotations)}:{},views:(o.views??[]).filter(u=>typeof u.name=="string").map(u=>({name:u.name,...Vr(u.annotations)?{description:Vr(u.annotations)}:{},...Ia(u.annotations)?{chart:Ia(u.annotations)}:{}})),givens:l,fields:s.get(a)??[]})}}return{sources:t}}const pt=e=>`${e.source}.${e.name}`;function Dp(e,t){if(!t)return[];const n=new Set;for(const r of e.sources)n.add(r.base);for(const r of e.imports)if(r.kind==="names")for(const i of r.names)n.add(i);return t.sources.filter(r=>n.has(r.name))}function Tp({open:e,document:t,catalog:n,columns:r,onClose:i,onAdd:s}){const{theme:o}=Be.usePublisherTheme(),a=S.useMemo(()=>Dp(t,n),[t,n]),[l,u]=S.useState(""),[c,d]=S.useState(""),[h,f]=S.useState(""),[g,v]=S.useState(Math.ceil(r/2));S.useEffect(()=>{e&&(u(t.sources[0]?.base??a[0]?.name??""),d(""),f(""),v(Math.ceil(r/2)))},[e,t,a,r]);const w=a.find(m=>m.name===l),x=l!==""&&c!=="";return y.jsx(j.AppDialog,{open:e,onClose:i,title:"Add a tile",description:"A tile shows one view of one source this dashboard imports.",actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:i,children:"Cancel"}),y.jsx(k.Button,{variant:"contained",disabled:!x,onClick:()=>s({base:l,view:c,...h.trim()?{label:h.trim()}:{},colspan:g}),children:"Add tile"})]}),children:y.jsx(k.Stack,{sx:{gap:2,pt:1},children:a.length===0?y.jsx(k.Typography,{variant:"body2",sx:{color:o.tileTitle},children:n?"This dashboard imports no source by name, so there is nothing to put a tile on. Import a source in the file first.":"The package's sources are still loading."}):y.jsxs(y.Fragment,{children:[y.jsx(k.TextField,{select:!0,size:"small",label:"Source",value:l,onChange:m=>{u(m.target.value),d("")},inputProps:{"aria-label":"Source"},children:a.map(m=>y.jsxs(k.MenuItem,{value:m.name,children:[m.name,m.description&&y.jsx(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:m.description})]},m.name))}),y.jsxs(k.Box,{children:[y.jsx(k.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),y.jsxs(k.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:280,overflowY:"auto",border:o.border,borderRadius:1},children:[(w?.views??[]).map(m=>y.jsxs(k.ListItemButton,{selected:c===m.name,onClick:()=>d(m.name),"aria-label":`View ${m.name}`,children:[y.jsx(k.ListItemText,{primary:m.name,secondary:m.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),m.chart&&y.jsx(k.Chip,{size:"small",variant:"outlined",label:m.chart.replace(/_chart$/,"")})]},m.name)),w&&w.views.length===0&&y.jsx(k.Typography,{variant:"body2",sx:{p:1.5,color:o.tileTitle},children:"This source declares no views."})]})]}),y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5},children:[y.jsx(k.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:h,onChange:m=>f(m.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}}),y.jsx(k.TextField,{size:"small",type:"number",label:`Width (of ${r})`,value:g,onChange:m=>v(Math.min(Math.max(Number(m.target.value)||1,1),r)),inputProps:{min:1,max:r,"aria-label":"Tile width"},sx:{width:140}})]})]})})})}const Aa=4e3;function Cp(e,t){const n=e.split(`
68
68
  `),r=t.split(`
69
- `);if(n.length>$a||r.length>$a)return[...n.map(l=>({kind:"del",text:l})),...r.map(l=>({kind:"add",text:l}))];const i=Array.from({length:n.length+1},()=>new Uint32Array(r.length+1));for(let l=n.length-1;l>=0;l--)for(let d=r.length-1;d>=0;d--)i[l][d]=n[l]===r[d]?i[l+1][d+1]+1:Math.max(i[l+1][d],i[l][d+1]);const s=[];let o=0,a=0;for(;o<n.length&&a<r.length;)n[o]===r[a]?(s.push({kind:"same",text:n[o]}),o++,a++):i[o+1][a]>=i[o][a+1]?s.push({kind:"del",text:n[o++]}):s.push({kind:"add",text:r[a++]});for(;o<n.length;)s.push({kind:"del",text:n[o++]});for(;a<r.length;)s.push({kind:"add",text:r[a++]});return s}function up(e,t=3){const n=new Array(e.length).fill(!1);e.forEach((s,o)=>{if(s.kind!=="same")for(let a=Math.max(0,o-t);a<=Math.min(e.length-1,o+t);a++)n[a]=!0});const r=[];let i=0;return e.forEach((s,o)=>{n[o]?(i>0&&r.push({kind:"fold",count:i}),i=0,r.push(s)):i++}),i>0&&r.push({kind:"fold",count:i}),r}function fp({open:e,before:t,after:n,onConfirm:r,onClose:i}){const{theme:s}=Le.usePublisherTheme(),o=S.useMemo(()=>e?up(dp(t,n)):[],[e,t,n]),a=o.filter(d=>d.kind==="add").length,l=o.filter(d=>d.kind==="del").length;return y.jsx(j.AppDialog,{open:e,onClose:i,maxWidth:"md",title:"Review the change to the file",description:y.jsxs(y.Fragment,{children:["A tile was added or removed, which moves declarations. Lines the builder does not own — comments, other Malloy — are left where they were; check they still read right."," ",y.jsxs(k.Box,{component:"span",sx:{fontVariantNumeric:"tabular-nums"},children:["+",a," −",l]})]}),actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:i,children:"Keep editing"}),y.jsx(k.Button,{variant:"contained",onClick:r,children:"Save this"})]}),children:y.jsx(k.Box,{component:"pre","aria-label":"File changes",sx:{m:0,px:2,py:1,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,lineHeight:1.6,overflowX:"auto",bgcolor:s.background,color:s.foreground},children:o.map((d,u)=>d.kind==="fold"?y.jsx(k.Box,{component:"span",sx:{display:"block",opacity:.55,py:.25},children:`⋯ ${d.count} unchanged line${d.count===1?"":"s"}`},u):y.jsxs(k.Box,{component:"span",sx:{display:"block",mx:-2,px:2,whiteSpace:"pre",bgcolor:d.kind==="add"?"rgba(46, 125, 91, 0.16)":d.kind==="del"?"rgba(168, 41, 31, 0.14)":"transparent",textDecoration:d.kind==="del"?"line-through":"none",opacity:d.kind==="del"?.8:1},children:[d.kind==="add"?"+ ":d.kind==="del"?"− ":" ",d.text]},u))})})}const Yi="self";function hp({open:e,document:t,source:n,givenNames:r,dashboards:i,onClose:s,onApply:o}){const{theme:a}=Le.usePublisherTheme(),[l,d]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(m=>m.source===n.name);d((n.dimensions??[]).map(m=>{const w=g.find(b=>b.name===m.name);return{name:m.name,expression:m.expression,to:w?.to??[],given:w?.given??""}}))},[e,n,t]);const u=(g,m)=>d(w=>w.map((b,v)=>{if(v!==g)return b;const p={...b};return m(p),p})),c=[Yi,...i.filter(g=>g!==Yi)],h=g=>g===Yi?"This dashboard":g,f=()=>{n&&(o(l.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),s())};return y.jsx(j.AppDialog,{open:e,onClose:s,title:"Clickable cells",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the dashboard it opens.",actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:s,children:"Cancel"}),y.jsx(k.Button,{variant:"contained",onClick:f,disabled:l.length===0,children:"Apply"})]}),children:y.jsx(k.Stack,{sx:{gap:2,pt:1},children:l.length===0?y.jsx(k.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?y.jsxs(y.Fragment,{children:[y.jsx(k.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",y.jsx(k.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((g,m)=>y.jsxs(k.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[y.jsxs(k.Box,{sx:{minWidth:0,pt:.75},children:[y.jsx(k.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:g.name}),y.jsxs(k.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g.expression,children:["is ",g.expression]})]}),y.jsx(k.TextField,{select:!0,size:"small",label:"Clicks go to",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:w=>w.length===0?"Not clickable":w.map(h).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:w=>u(m,b=>{const v=w.target.value;b.to=Array.isArray(v)?v:String(v).split(",").filter(Boolean)}),children:c.map(w=>y.jsxs(k.MenuItem,{value:w,children:[y.jsx(k.Checkbox,{size:"small",checked:g.to.includes(w),sx:{p:0,mr:1}}),y.jsx(k.ListItemText,{primary:h(w)})]},w))}),y.jsxs(k.TextField,{select:!0,size:"small",label:"Sets the control",value:g.given,disabled:g.to.length===0,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:g.given===""?`Named ${g.name}, like the dimension`:void 0,onChange:w=>u(m,b=>{b.given=w.target.value}),children:[y.jsx(k.MenuItem,{value:"",children:y.jsx("em",{children:"Same name as the dimension"})}),r.map(w=>y.jsx(k.MenuItem,{value:w,children:w},w))]})]},g.name))})})}const pd=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function pp({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:s}){const o=S.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[d,u]=S.useState({kind:"new"}),[c,h]=S.useState(""),[f,g]=S.useState("select"),[m,w]=S.useState(""),[b,v]=S.useState(""),[p,x]=S.useState([]),[_,O]=S.useState(!1),T=P=>t.sources.find(R=>R.name===P.source)?.base??P.source;S.useEffect(()=>{if(e)if(n){u({kind:"existing",name:n.name}),h(n.label??"");const P=Kh(t,n);x(P);const R=P.filter($=>$.include),U=new Set(R.map($=>$.field));v(U.size===1?R[0].field:n.field??""),O(U.size>1)}else u({kind:"new"}),h(""),g("select"),v(""),w(new Date().toISOString().slice(0,10)),x(t.tiles.map(P=>({include:zs(P),field:""}))),O(!1)},[e,n,t]);const E=S.useMemo(()=>[...(t.localGivens??[]).map(P=>P.name),...r.map(P=>P.name)],[t,r]),I=S.useMemo(()=>b.trim()?Hh(b.trim(),E):"",[b,E]),D=d.kind==="existing"?n??r.find(P=>P.name===d.name):I?{name:I,type:Rr({name:I,label:c,kind:f,field:b}).type}:void 0,L=D?.type!==void 0&&!D.type.startsWith("filter<"),M=p.find(P=>P.include)?.op??yi(D?.type),A=(P,R)=>x(U=>U.map(($,C)=>C===P?{...$,...R}:$)),Q=P=>x(R=>R.map(U=>({...U,op:P}))),J=P=>{const R=yi(P);x(U=>U.map(({op:$,...C})=>R?{...C,op:R}:C))},ye=P=>{u({kind:"existing",name:P.name}),v(P.field??""),J(P.type)},Ie=P=>{g(P),J(Rr({name:"X",label:c,kind:P,field:b}).type)},ie=t.tiles.map(zs),ze=ie.filter(Boolean).length,Ke=p.filter((P,R)=>P.include&&ie[R]).length,be=t.tiles.filter((P,R)=>(p[R]?.include??!1)&&ie[R]),qe=be.length>0?be:t.tiles.filter((P,R)=>ie[R]),We=S.useMemo(()=>{const P=new Map;let R=!1;for(const U of qe){const $=i?.(U);if($){R=!0;for(const C of $)P.has(C.name)||P.set(C.name,C)}}return R?[...P.values()]:void 0},[p,t.tiles,i]),je=(()=>{const P=b.trim();for(const R of be){const U=i?.(R);if(!U||U.some($=>$.name===P))return T(R)}return be[0]?T(be[0]):t.sources[0]?.base})(),Fe=P=>x(R=>R.map((U,$)=>({...U,include:P&&ie[$]}))),xe=S.useMemo(()=>_?p:p.map(P=>({...P,field:b})),[_,p,b]),ee=P=>{for(const R of qe){const U=i?.(R)?.find($=>$.name===P.trim());if(U?.type)return U.type}},z=P=>ti(D?.type,P.type),V=(P,R)=>{if(P.trim()==="")return"Pick the field this filter compares.";const U=R?i?.(R):void 0;if(!U)return;const $=U.find(C=>C.name===P.trim());if(!$)return`Not a field of ${R?T(R):"the tiles' source"}.`;if($.type&&!ti(D?.type,$.type))return`${P.trim()} is ${_a($.type)}; this filter compares ${_a(D?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},_e=P=>{if(v(P),l||d.kind!=="new")return;const R=ee(P),U=Rr({name:"X",label:c,kind:f,field:P}).type;R&&!ti(U,R)&&Ie(Gh(R))},ne=xe.map((P,R)=>P.include&&ie[R]?V(P.field,t.tiles[R]):void 0),Ae=ne.every(P=>P===void 0),X=!_&&Ke>0?be.map(P=>V(b,P)).find(Boolean):void 0,et=D!==void 0&&Ae&&(d.kind==="existing"||b.trim()!==""&&I!==""),Se=()=>{if(!(!D||!et))if(d.kind==="new")s(D.name,xe,Rr({name:D.name,label:c.trim()||pd(D.name),kind:f,field:b.trim(),...je?{source:je}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const P=c.trim(),R=P!==(n.local.label??"");s(D.name,xe,R?{...n.local,...P?{label:P}:{}}:void 0)}else s(D.name,xe)},ft=l&&a.origin==="model";return{editing:l,shown:a,fromModel:ft,source:d,setSource:u,label:c,setLabel:h,kind:f,dateDefault:m,setDateDefault:w,field:b,rows:p,setRows:x,perTile:_,setPerTile:O,newName:I,target:D,valueTyped:L,commonOp:M,setRow:A,setCommonOp:Q,pickExisting:ye,pickKind:Ie,bindable:ie,bindableCount:ze,included:Ke,commonFields:We,setAll:Fe,accepts:z,pickField:_e,rowProblems:ne,commonProblem:X,canApply:et,apply:Se}}function Oa({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:l,autoFocus:d,placeholder:u,sx:c}){const h=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),f=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return y.jsx(k.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(g,m)=>t(m),value:e,onChange:(g,m)=>t(typeof m=="string"?m:""),disabled:l,disableClearable:!0,renderOption:(g,m)=>S.createElement("li",{...g,key:m},y.jsx(k.Typography,{variant:"body2",sx:{flex:1},children:m}),f.get(m)&&y.jsx(k.Typography,{variant:"caption",sx:{opacity:.6},children:f.get(m)?.replace(/_type$/,"")})),renderInput:g=>y.jsx(k.TextField,{...g,label:i,placeholder:u,autoFocus:d,error:o,helperText:a,inputProps:{...g.inputProps,"aria-label":s}}),sx:c})}function gp({open:e,document:t,control:n,available:r,fieldsFor:i,onClose:s,onApply:o,onRemove:a}){const{theme:l}=Le.usePublisherTheme(),{editing:d,shown:u,fromModel:c,source:h,setSource:f,label:g,setLabel:m,kind:w,dateDefault:b,setDateDefault:v,field:p,rows:x,setRows:_,perTile:O,setPerTile:T,newName:E,target:I,valueTyped:D,commonOp:L,setRow:M,setCommonOp:A,pickExisting:Q,pickKind:J,bindable:ye,bindableCount:Ie,included:ie,commonFields:ze,setAll:Ke,accepts:be,pickField:qe,rowProblems:We,commonProblem:je,canApply:Fe,apply:xe}=pp({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:o}),ee=(z,V,_e)=>y.jsx(k.TextField,{select:!0,size:"small",label:"Compares",value:z??">=",onChange:ne=>V(ne.target.value),inputProps:{"aria-label":_e},sx:{width:130},children:Vh.filter(ne=>ne.op!=="~").map(ne=>y.jsx(k.MenuItem,{value:ne.op,children:ne.label},ne.op))});return y.jsx(j.AppDialog,{open:e,onClose:s,title:d?u.label??u.name:"Add a filter",description:d?y.jsxs(y.Fragment,{children:[y.jsxs(k.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",u.name]}),c?" · declared in the model, so its label and options are set there":" · declared in this dashboard"]}):"A control on the page, and the tiles it filters.",actions:y.jsxs(y.Fragment,{children:[d&&y.jsx(k.Button,{color:"error",onClick:()=>a(u.name),"aria-label":`Remove control ${u.name}`,sx:{mr:"auto"},children:"Remove from dashboard"}),y.jsx(k.Button,{onClick:s,children:"Cancel"}),y.jsx(k.Tooltip,{title:Fe||I===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:y.jsx("span",{children:y.jsx(k.Button,{variant:"contained",onClick:xe,disabled:!Fe,children:d?"Apply":"Add filter"})})})]}),children:y.jsxs(k.Stack,{sx:{gap:2.5,pt:1},children:[!d&&r.length>0&&y.jsxs(k.ToggleButtonGroup,{exclusive:!0,size:"small",value:h.kind,onChange:(z,V)=>{V==="new"?f({kind:"new"}):V==="existing"&&r[0]&&Q(r[0])},"aria-label":"Where the filter comes from",children:[y.jsx(k.ToggleButton,{value:"new",children:"New in this dashboard"}),y.jsx(k.ToggleButton,{value:"existing",children:"From the model"})]}),!d&&h.kind==="existing"?y.jsx(k.TextField,{select:!0,size:"small",label:"Control",value:h.name,onChange:z=>{const V=r.find(_e=>_e.name===z.target.value);V&&Q(V)},children:r.map(z=>y.jsxs(k.MenuItem,{value:z.name,children:[z.label??z.name,y.jsxs(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",z.name]})]},z.name))}):null,y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!O&&y.jsx(Oa,{value:p,onChange:qe,fields:ze,accepts:be,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!d,error:je!==void 0,helperText:je??(!d&&E?`Declared as $${E}`:void 0),sx:{flex:1,minWidth:200}}),!c&&y.jsx(k.TextField,{size:"small",label:"Label",placeholder:E?pd(E):"",value:g,onChange:z=>m(z.target.value),inputProps:{"aria-label":"Control label"},sx:{flex:1,minWidth:160}}),D&&!O&&ee(L,A,"Comparison")]}),!d&&h.kind==="new"&&y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5},children:[y.jsx(k.TextField,{select:!0,size:"small",label:"Control",value:w,onChange:z=>J(z.target.value),inputProps:{"aria-label":"Kind of control"},slotProps:{select:{renderValue:z=>wa.find(V=>V.kind===z)?.label??String(z)}},sx:{flex:1},children:wa.map(z=>y.jsxs(k.MenuItem,{value:z.kind,children:[z.label,y.jsx(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:z.hint})]},z.kind))}),w==="date"&&y.jsx(k.TextField,{size:"small",type:"date",label:"Starts at",value:b,onChange:z=>v(z.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),y.jsxs(k.Box,{children:[y.jsxs(k.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[y.jsx(k.Checkbox,{size:"small",checked:Ie>0&&ie===Ie,indeterminate:ie>0&&ie<Ie,disabled:Ie===0,onChange:z=>Ke(z.target.checked),inputProps:{"aria-label":"All tiles"}}),y.jsxs(k.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",ie," of ",t.tiles.length," tiles"]}),y.jsx(k.Button,{size:"small",onClick:()=>{O||_(z=>z.map(V=>({...V,field:p}))),T(z=>!z)},children:O?"Same field for all":"Adjust per tile"})]}),y.jsx(k.Stack,{sx:{gap:O?1:0},children:t.tiles.map((z,V)=>{const _e=x[V],ne=z.label??z.name,Ae=O?We[V]:void 0;return y.jsxs(k.Stack,{direction:"row",sx:{gap:1,alignItems:O?"flex-start":"center",opacity:ye[V]?1:.6},children:[y.jsx(k.Checkbox,{size:"small",disabled:!ye[V],checked:(_e?.include??!1)&&ye[V],inputProps:{"aria-label":`Filter ${ne}`},onChange:X=>M(V,{include:X.target.checked})}),y.jsx(k.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:O?1:0},noWrap:!0,children:ne}),ye[V]?O&&y.jsxs(y.Fragment,{children:[D&&ee(_e?.op,X=>M(V,{op:X}),`Comparison for ${ne}`),y.jsx(Oa,{value:_e?.field??"",onChange:X=>M(V,{field:X}),fields:i?.(z),accepts:be,label:"Field",ariaLabel:`Field for ${ne}`,disabled:!_e?.include,error:Ae!==void 0,helperText:Ae,sx:{width:220}})]}):y.jsx(k.Tooltip,{title:z.declaration.kind==="inherited"?"Declared on its source, which this dashboard does not write.":"Its query is written out here rather than named, so a filter cannot be added to it.",children:y.jsx(k.Typography,{variant:"caption",sx:{color:l.tileTitle},children:z.declaration.kind==="inherited"?"From the model":"Inline query"})})]},`${z.source}.${z.name}`)})}),ie===0&&y.jsx(k.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}function gd(e,t,n,r){const[i,s]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:d=>s(u=>{if(u===void 0)return u;const c=structuredClone(u);return d(c),c}),close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}const vp=e=>({title:e.title,...e.description===void 0?{}:{description:e.description},...e.columns===void 0?{}:{columns:e.columns},...e.autorun===void 0?{}:{autorun:e.autorun}}),Zi=[2,3,4,6,8,12,16,24];function mp({anchor:e,settings:t,onClose:n,onCommit:r}){const{theme:i}=Le.usePublisherTheme(),{draft:s,patch:o,close:a}=gd(t,e!==null,r,n),l=s?.columns!==void 0&&!Zi.includes(s.columns)?[...Zi,s.columns].sort((d,u)=>d-u):Zi;return y.jsx(k.Popover,{open:e!==null&&s!==void 0,anchorEl:e,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:380,p:2}}},children:s&&y.jsxs(k.Stack,{sx:{gap:1.5},children:[y.jsx(k.Typography,{variant:"overline",sx:{color:i.tileTitle,lineHeight:1.5},children:"Dashboard"}),y.jsx(k.TextField,{size:"small",label:"Title",value:s.title,autoFocus:!0,inputProps:{"aria-label":"Dashboard title"},onChange:d=>o(u=>{u.title=d.target.value})}),y.jsx(k.TextField,{size:"small",label:"Description",multiline:!0,minRows:3,maxRows:10,value:s.description??"",helperText:"Markdown. A blank line starts a new paragraph.",inputProps:{"aria-label":"Dashboard description"},onChange:d=>o(u=>{const c=d.target.value;c.trim()===""?delete u.description:u.description=c})}),y.jsxs(k.TextField,{select:!0,size:"small",label:"Grid width",value:s.columns??"",helperText:"Columns across the page. Tiles are placed in these.",inputProps:{"aria-label":"Grid width"},onChange:d=>o(u=>{const c=Number(d.target.value);c?u.columns=c:delete u.columns}),children:[y.jsx(k.MenuItem,{value:"",children:"Default (2)"}),l.map(d=>y.jsx(k.MenuItem,{value:d,children:d},d))]}),y.jsx(k.FormControlLabel,{control:y.jsx(k.Switch,{size:"small",checked:s.autorun!==!1,slotProps:{input:{"aria-label":"Run as controls change"}},onChange:d=>o(u=>{d.target.checked?delete u.autorun:u.autorun=!1})}),label:y.jsxs(k.Typography,{variant:"body2",children:["Run as controls change",y.jsx(k.Typography,{component:"span",variant:"caption",sx:{display:"block",opacity:.7},children:"Off, readers press Apply. For a page whose queries are slow."})]})})]})})}const yp=j.createSvgIcon(y.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function bp({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:i,children:s}){const{theme:o}=Le.usePublisherTheme();return y.jsx(y.Fragment,{children:y.jsxs(k.Stack,{sx:{gap:1},children:[y.jsxs(k.Stack,{direction:"row","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",minHeight:32},children:[y.jsx(yp,{sx:{fontSize:18,color:o.tileTitle,opacity:.7}}),y.jsx(k.Typography,{variant:"subtitle2",sx:{color:o.tileTitle,mr:.5},children:"Filters"}),e.length===0&&y.jsx(k.Typography,{variant:"body2",sx:{color:o.tileTitle,opacity:.8},children:"None yet."}),e.map(a=>{const l=n(a.name,a.type);return y.jsx(k.Tooltip,{title:l.length>0?`$${a.name} · cannot filter on: ${l.join(", ")}`:`$${a.name} · ${a.origin==="dashboard"?"declared here":"from the model"} · ${a.boundTiles} of ${t} tiles`,children:y.jsx(k.Chip,{size:"small",label:a.label??a.name,"aria-label":`Edit filter ${a.name}`,color:l.length>0?"warning":"default",variant:a.origin==="dashboard"?"filled":"outlined",onClick:()=>r(a),sx:{opacity:a.boundTiles===0?.6:1,cursor:"pointer",transition:"opacity 120ms"}})},a.name)}),y.jsx(k.Box,{sx:{ml:"auto"},children:y.jsx(j.SecondaryButton,{label:"Filter",icon:y.jsx(j.AddIcon,{}),onClick:()=>i(),ariaLabel:"Add filter",ariaHasPopup:"dialog"})})]}),s]})})}const xp=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),_p=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},vd=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),md=e=>`gap.${e}`,wp=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),l=o===0||s.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:ht(e[o-1]),colspan:t-r}),l&&(r=0),n.push(vd(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:ht(i),colspan:t-r}),n};var kp=Object.create,yd=Object.defineProperty,Sp=Object.defineProperties,$p=Object.getOwnPropertyDescriptor,Op=Object.getOwnPropertyDescriptors,bi=Object.getOwnPropertySymbols,bd=Object.prototype.hasOwnProperty,xd=Object.prototype.propertyIsEnumerable,Tp=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Or=e=>{throw TypeError(e)},Fs=(e,t,n)=>t in e?yd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qi=(e,t)=>{for(var n in t||(t={}))bd.call(t,n)&&Fs(e,n,t[n]);if(bi)for(var n of bi(t))xd.call(t,n)&&Fs(e,n,t[n]);return e},Ji=(e,t)=>Sp(e,Op(t)),Ep=(e,t)=>{var n={};for(var r in e)bd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&bi)for(var r of bi(e))t.indexOf(r)<0&&xd.call(e,r)&&(n[r]=e[r]);return n},Dp=e=>{var t;return[,,,kp((t=void 0)!=null?t:null)]},_d=["class","method","getter","setter","accessor","field","value","get","set"],Qn=e=>e!==void 0&&typeof e!="function"?Or("Function expected"):e,Pp=(e,t,n,r,i)=>({kind:_d[e],name:t,metadata:r,addInitializer:s=>n._?Or("Already initialized"):i.push(Qn(s||null))}),Cp=(e,t)=>Fs(t,Tp("metadata"),e[3]),zr=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},wd=(e,t,n,r,i,s)=>{for(var o,a,l,d,u,c=t&7,h=!1,f=!1,g=e.length+1,m=_d[c+5],w=e[g-1]=[],b=e[g]||(e[g]=[]),v=(i=i.prototype,$p({get[n](){return Jn(this,s)},set[n](x){return Lt(this,s,x)}},n)),p=r.length-1;p>=0;p--)d=Pp(c,n,l={},e[3],b),d.static=h,d.private=f,u=d.access={has:x=>n in x},u.get=x=>x[n],u.set=(x,_)=>x[n]=_,a=(0,r[p])({get:v.get,set:v.set},d),l._=1,a===void 0?Qn(a)&&(v[m]=a):typeof a!="object"||a===null?Or("Object expected"):(Qn(o=a.get)&&(v.get=o),Qn(o=a.set)&&(v.set=o),Qn(o=a.init)&&w.unshift(o));return v&&yd(i,n,v),i},kd=(e,t,n)=>t.has(e)||Or("Cannot "+n),Jn=(e,t,n)=>(kd(e,t,"read from private field"),t.get(e)),Wn=(e,t,n)=>t.has(e)?Or("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Lt=(e,t,n,r)=>(kd(e,t,"write to private field"),t.set(e,n),n);function Wt(e){return e instanceof Ko||e instanceof Td}var Wr=10,Mp=class extends Ee{constructor(e){super(e);const t=Qe(()=>{const{dragOperation:r}=e;if(hr(r.activatorEvent)&&Wt(r.source)&&r.status.initialized){const i=e.registry.plugins.get(Sr);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!hr(r.nativeEvent)||!Wt(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:l}=i,{by:d}=r;if(!d)return;const u=Ip(d),{source:c,target:h}=s,{center:f}=s.shape.current,g=[],m=[];ae(()=>{for(const _ of l.droppables){const{id:O}=_;if(!_.accepts(c)||O===h?.id&&Wt(_)||!_.element)continue;let T=_.shape;const E=new at(_.element,{getBoundingClientRect:I=>ur(I,void 0,.2)});!E.height||!E.width||(u=="down"&&f.y+Wr<E.center.y||u=="up"&&f.y-Wr>E.center.y||u=="left"&&f.x-Wr>E.center.x||u=="right"&&f.x+Wr<E.center.x)&&(g.push(_),_.shape=E,m.push(()=>_.shape=T))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(g,_f);ae(()=>m.forEach(_=>_()));const[b]=w;if(!b)return;const{id:v}=b,{index:p,group:x}=c.sortable;o.setDropTarget(v).then(()=>{const{source:_,target:O,shape:T}=s;if(!_||!Wt(_)||!T)return;const{index:E,group:I,target:D}=_.sortable,L=p!==E||x!==I,M=L?D:O?.element;if(!M)return;yc(M);const A=new at(M);if(!A)return;const Q=lt.delta(A,lt.from(T.current.boundingRectangle),_.alignment);o.move({by:Q}),L?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Ip(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var jp=Object.defineProperty,Ap=Object.defineProperties,Rp=Object.getOwnPropertyDescriptors,Ta=Object.getOwnPropertySymbols,Lp=Object.prototype.hasOwnProperty,zp=Object.prototype.propertyIsEnumerable,Ea=(e,t,n)=>t in e?jp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qt=(e,t)=>{for(var n in t||(t={}))Lp.call(t,n)&&Ea(e,n,t[n]);if(Ta)for(var n of Ta(t))zp.call(t,n)&&Ea(e,n,t[n]);return e},Jt=(e,t)=>Ap(e,Rp(t));function Wp(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Fr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function es(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Fp(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(p,x)=>p===x||p!==null&&typeof p=="object"&&"id"in p&&p.id===x;if(Array.isArray(e)){const p=e.findIndex(_=>l(_,s.id)),x=e.findIndex(_=>l(_,o.id));if(p===-1||x===-1){if(es(s)){const _=s.initialIndex,O=s.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const _=s.index;if(_!==p)return n(e,p,_)}return n(e,p,x)}const d=Object.entries(e);let u=-1,c,h=-1,f;for(const[p,x]of d)if(u===-1&&(u=x.findIndex(_=>l(_,s.id)),u!==-1&&(c=p)),h===-1&&(h=x.findIndex(_=>l(_,o.id)),h!==-1&&(f=p)),u!==-1&&h!==-1)break;if(u===-1&&es(s)){const p=s.initialGroup==null?void 0:Fr(e,s.initialGroup),x=s.initialIndex,_=s.group==null?void 0:Fr(e,s.group),O=s.index;if(p==null||_==null||p===_&&x===O)return"preventDefault"in t&&t.preventDefault(),e;if(p===_)return Jt(Qt({},e),{[p]:n(e[p],x,O)});const T=e[p][x];return Jt(Qt({},e),{[p]:[...e[p].slice(0,x),...e[p].slice(x+1)],[_]:[...e[_].slice(0,O),T,...e[_].slice(O)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(f==null){const p=Fr(e,o.id);if(p!=null){const x=o.shape&&m.y>o.shape.center.y?e[p].length:0;f=p,h=x}}if(c==null||f==null||c===f&&u===h){if(c!=null&&c===f&&u===h&&es(s)){const p=s.group==null?void 0:Fr(e,s.group),x=s.group!=null&&p!==c,_=s.index!==u;if(x||_){const O=s.group==null?c:p;if(O!=null){if(c===O)return Jt(Qt({},e),{[c]:n(e[c],u,s.index)});const T=e[c][u];return Jt(Qt({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[O]:[...e[O].slice(0,s.index),T,...e[O].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===f)return Jt(Qt({},e),{[c]:n(e[c],u,h)});const b=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][u];return Jt(Qt({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[f]:[...e[f].slice(0,h+b),v,...e[f].slice(h+b)]})}function Bp(e,t){return Fp(e,t,Wp)}function Da(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Pa(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var Ca="__default__",Np=class extends Ee{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof Ko){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!Wt(o)||!Wt(a)||o.sortable===a.sortable)return;const l=t(),d=Da(l),u=o.sortable.group===a.sortable.group,c=l.get(o.sortable.group),h=u?c:l.get(a.sortable.group);!c||!h||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var f,g;const m=t();if(Pa(d,l,m))return;const w=o.sortable.element,b=a.sortable.element;if(!b||!w||!u&&a.id===o.sortable.group)return;const v=Br(c),p=u?v:Br(h),x=(f=o.sortable.group)!=null?f:Ca,_=(g=a.sortable.group)!=null?g:Ca,O={[x]:v,[_]:p},T=Bp(O,r);if(O===T)return;const E=T[_].indexOf(o.sortable),I=T[_].indexOf(a.sortable);i.collisionObserver.disable(),Ma(w,E,b,I),ae(()=>{for(const[D,L]of T[x].entries())L.index=D;if(!u)for(const[D,L]of T[_].entries())L.group=a.sortable.group,L.index=D}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;Wt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=Da(a),d=a.get(o.sortable.initialGroup);d&&i.renderer.rendering.then(()=>{const u=t();if(Pa(l,a,u))return;const c=Br(d),h=Br(d,Vp),f=o.sortable.element,g=h.indexOf(o.sortable),m=c[g],w=m?.element;!m||!w||!f||(Ma(f,m.index,w,o.index),ae(()=>{for(const b of a.values()){const v=Array.from(b).values();for(const p of v)p.index=p.initialIndex,p.group=p.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Ma(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function Gp(e,t){return e.index-t.index}function Vp(e,t){return e.initialIndex-t.initialIndex}function Br(e,t=Gp){return Array.from(e).sort(t)}var Ia=[Mp,Np],Sd={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function ja(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var Nr=new ru,$d,Od,Ot,Vo,er,tr,Ho,cn;Od=[K],$d=[K];var Ai=class{constructor(e,t){Wn(this,Vo,zr(Ot,8,this)),zr(Ot,11,this),Wn(this,er),Wn(this,tr),Wn(this,Ho,zr(Ot,12,this)),zr(Ot,15,this),Wn(this,cn),this.register=()=>(ae(()=>{var g,m;(g=this.manager)==null||g.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{ae(()=>{var g,m;(g=this.manager)==null||g.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{ae(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:l,transition:d=Sd,plugins:u}=n,c=Ep(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const h=it(u,Ia),f=ja(i);this.droppable=new Ko(Ji(Qi({},c),{disabled:f.droppable}),t,this),this.draggable=new Td(Ji(Qi({},c),{disabled:f.draggable,plugins:h,effects:()=>[()=>{var g,m,w;const b=(g=this.manager)==null?void 0:g.dragOperation.status;b?.initializing&&this.id===((w=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:w.id)&&Nr.clear(this.manager),b?.dragging&&Nr.set(this.manager,this.id,H(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:m,manager:w}=this,b=Jn(this,tr),v=Jn(this,er);(g!==b||m!==v)&&(Lt(this,tr,g),Lt(this,er,m),this.animate())},()=>{var g,m;const{target:w}=this,{isDragSource:b}=this.draggable;((m=(g=this.draggable.pluginConfig(Ao))==null?void 0:g.feedback)!=null?m:"default")==="move"&&b&&(this.droppable.disabled=!w)},...r()],type:l,sensors:a}),t,this),Lt(this,cn,c.element),this.manager=t,this.index=o,Lt(this,tr,o),this.group=s,Lt(this,er,s),this.type=l,this.transition=d}get initialIndex(){var e,t;return(t=(e=Nr.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Nr.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){H(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:i}=this;if(!i)return;for(const u of i.getAnimations())"transitionProperty"in u&&(u.transitionProperty==="transform"||u.transitionProperty==="translate"||u.transitionProperty==="scale")&&u.cancel();const s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=ut(i),l=ua(i,a,!1),d=ua(i,a);if(o.x||o.y){const u=To(He(i))?Ji(Qi({},t),{duration:0}):t;bc({element:i,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${d.x}px ${d.y}px ${d.z}`]},options:u}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){ae(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){ae(()=>{const t=Jn(this,cn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Lt(this,cn,e)})}get element(){var e,t;const n=Jn(this,cn);if(n)return(t=(e=bs.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=it(e,Ia)}set disabled(e){const t=ja(e);ae(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){ae(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??xc}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){ae(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Ot=Dp();Vo=new WeakMap;er=new WeakMap;tr=new WeakMap;Ho=new WeakMap;cn=new WeakMap;wd(Ot,4,"index",Od,Ai,Vo);wd(Ot,4,"group",$d,Ai,Ho);Cp(Ot,Ai);var Td=class extends Mi{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},Ko=class extends Ii{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Hp=Object.defineProperty,Kp=Object.defineProperties,qp=Object.getOwnPropertyDescriptors,Aa=Object.getOwnPropertySymbols,Up=Object.prototype.hasOwnProperty,Xp=Object.prototype.propertyIsEnumerable,Ra=(e,t,n)=>t in e?Hp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ts=(e,t)=>{for(var n in t||(t={}))Up.call(t,n)&&Ra(e,n,t[n]);if(Aa)for(var n of Aa(t))Xp.call(t,n)&&Ra(e,n,t[n]);return e},Yp=(e,t)=>Kp(e,qp(t));function Zp(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:l,group:d,disabled:u,modifiers:c,sensors:h,target:f,type:g,plugins:m}=e,w=ts(ts({},Sd),e.transition),b=nd(p=>new Ai(Yp(ts({},e),{transition:w,register:!1,handle:pn(a),element:pn(o),target:pn(f)}),p)),v=Qc(b,Qp);return se(i,()=>b.id=i),In(()=>{ae(()=>{b.group=d,b.index=l})},[b,d,l]),se(g,()=>b.type=g),se(t,()=>b.accept=t,void 0,nt),se(s,()=>s&&(b.data=s)),se(l,()=>{var p;(p=b.manager)!=null&&p.dragOperation.status.idle&&w?.idle&&b.refreshShape()},gh),Jr(a,p=>b.handle=p),Jr(o,p=>b.element=p),Jr(f,p=>b.target=p),se(u,()=>b.disabled=u??!1,void 0,nt),se(h,()=>b.sensors=h,void 0,nt),se(n,()=>b.collisionDetector=n),se(r,()=>b.collisionPriority=r),se(m,()=>b.plugins=m,void 0,nt),se(w,()=>b.transition=w,void 0,nt),se(c,()=>b.modifiers=c,void 0,nt),se(e.alignment,()=>b.alignment=e.alignment),{sortable:v,get isDragging(){return v.isDragging},get isDropping(){return v.isDropping},get isDragSource(){return v.isDragSource},get isDropTarget(){return v.isDropTarget},handleRef:S.useCallback(p=>{b.handle=p??void 0},[b]),ref:S.useCallback(p=>{var x,_;!p&&((x=b.element)!=null&&x.isConnected)&&!((_=b.manager)!=null&&_.dragOperation.status.idle)||(b.element=p??void 0)},[b]),sourceRef:S.useCallback(p=>{var x,_;!p&&((x=b.source)!=null&&x.isConnected)&&!((_=b.manager)!=null&&_.dragOperation.status.idle)||(b.source=p??void 0)},[b]),targetRef:S.useCallback(p=>{var x,_;!p&&((x=b.target)!=null&&x.isConnected)&&!((_=b.manager)!=null&&_.dragOperation.status.idle)||(b.target=p??void 0)},[b])}}function Qp(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Bs="tile",Ed="gap",Jp='[role="separator"]',eg=[Is.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>(Is.defaults.preventActivation?.(e,t)??!1)||e.target instanceof Element&&e.target.closest(Jp)!==null}),Vc],tg=e=>[...e,Ao.configure({feedback:"clone"})];function ng({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=Zp({id:e,index:t,type:Bs,accept:Bs,collisionDetector:Do,plugins:tg});return y.jsx(y.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function rg({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=Fh({id:e,type:Ed,accept:Bs,collisionDetector:Do,data:{after:t}});return y.jsx(y.Fragment,{children:n({ref:r,isDropTarget:i})})}const ig=j.createSvgIcon(y.jsx("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2m-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"})),sg=j.createSvgIcon(y.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"}));function og({tile:e,index:t,selected:n,menuOpen:r,resizeSpan:i,columns:s,onSelect:o,onOpenMenu:a,onResizeStart:l,onResizeMove:d,onResizeEnd:u,children:c}){const{theme:h}=Le.usePublisherTheme();return y.jsx(ng,{id:ht(e),index:t,children:({ref:f,handleRef:g,isDragSource:m})=>y.jsxs(k.Box,{ref:f,onClick:o,onPointerDown:w=>{w.button===0&&o()},"aria-label":`Tile ${e.name}`,"aria-current":n,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",borderRadius:1,outline:n?`2px solid ${h.drillLink}`:"2px solid transparent",outlineOffset:2,transition:"outline-color 120ms, opacity 120ms, box-shadow 120ms","&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:"0 12px 32px rgba(0, 0, 0, 0.22)"},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${h.drillLink}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"&:hover":{outlineColor:n?h.drillLink:h.border,boxShadow:"0 2px 10px rgba(0, 0, 0, 0.10)"}},children:[c,y.jsx(k.Box,{ref:g,className:"builder-affordance","aria-label":`Move ${e.label??e.name}`,sx:{position:"absolute",top:"2px",left:"2px",display:"grid",placeItems:"center",width:"22px",height:"22px",borderRadius:"4px",cursor:"grab",touchAction:"none",zIndex:2,color:h.tileTitle,bgcolor:h.tile,opacity:m||n?.9:0,transition:"opacity 120ms","&:hover":{opacity:1},"&:active":{cursor:"grabbing"},"&:focus-visible":{opacity:1,outline:`2px solid ${h.drillLink}`,outlineOffset:1}},children:y.jsx(ig,{sx:{fontSize:16}})}),i===void 0&&y.jsx(k.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${e.label??e.name}`,onClick:w=>{w.stopPropagation(),a(w.currentTarget)},sx:{position:"absolute",top:"2px",right:"2px",width:22,height:22,zIndex:2,color:h.tileTitle,bgcolor:h.tile,opacity:n||r?.9:0,transition:"opacity 120ms","&:hover":{opacity:1,bgcolor:h.tile}},children:y.jsx(sg,{sx:{fontSize:16}})}),i!==void 0&&y.jsxs(k.Box,{"aria-hidden":!0,sx:{position:"absolute",top:"6px",right:"6px",px:.75,py:.25,borderRadius:"4px",bgcolor:h.drillLink,color:h.tile,fontSize:11,fontVariantNumeric:"tabular-nums",zIndex:4,pointerEvents:"none"},children:[i," of ",s," ·"," ",Math.round(i/s*100),"%"]}),e.declaration.kind!=="inherited"&&y.jsx(k.Box,{className:"builder-affordance",role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e.label??e.name}`,onPointerDown:l,onPointerMove:d,onPointerUp:u,onPointerCancel:u,sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:1,opacity:i!==void 0||n?1:0,transition:"opacity 120ms","&:hover":{opacity:1},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:h.drillLink}}})]})})}function ag({tile:e}){const{theme:t}=Le.usePublisherTheme();return y.jsxs(j.TileCard,{sx:{minHeight:140},children:[y.jsx(j.TileHeading,{title:e.label??e.name,subtitle:e.subtitle}),y.jsxs(k.Typography,{variant:"caption",sx:{display:"block",color:t.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function lg({after:e}){const{theme:t}=Le.usePublisherTheme();return y.jsx(rg,{id:md(e),after:e,children:({ref:n,isDropTarget:r})=>y.jsx(k.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.drillLink}`,bgcolor:r?t.tile:"transparent",opacity:r?.95:.4,transition:"opacity 120ms, background-color 120ms"}})})}function cg({columns:e}){const{theme:t}=Le.usePublisherTheme();return y.jsx(k.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${j.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>y.jsx(k.Box,{sx:{borderLeft:`1px dashed ${t.drillLink}`,borderRight:r===e-1?`1px dashed ${t.drillLink}`:"none",opacity:.35}},r))})}var dg=Object.defineProperty,ug=Object.defineProperties,fg=Object.getOwnPropertyDescriptors,La=Object.getOwnPropertySymbols,hg=Object.prototype.hasOwnProperty,pg=Object.prototype.propertyIsEnumerable,za=(e,t,n)=>t in e?dg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,en=(e,t)=>{for(var n in t||(t={}))hg.call(t,n)&&za(e,n,t[n]);if(La)for(var n of La(t))pg.call(t,n)&&za(e,n,t[n]);return e},tn=(e,t)=>ug(e,fg(t));function gg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Gr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function ns(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function vg(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(p,x)=>p===x||p!==null&&typeof p=="object"&&"id"in p&&p.id===x;if(Array.isArray(e)){const p=e.findIndex(_=>l(_,s.id)),x=e.findIndex(_=>l(_,o.id));if(p===-1||x===-1){if(ns(s)){const _=s.initialIndex,O=s.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const _=s.index;if(_!==p)return n(e,p,_)}return n(e,p,x)}const d=Object.entries(e);let u=-1,c,h=-1,f;for(const[p,x]of d)if(u===-1&&(u=x.findIndex(_=>l(_,s.id)),u!==-1&&(c=p)),h===-1&&(h=x.findIndex(_=>l(_,o.id)),h!==-1&&(f=p)),u!==-1&&h!==-1)break;if(u===-1&&ns(s)){const p=s.initialGroup==null?void 0:Gr(e,s.initialGroup),x=s.initialIndex,_=s.group==null?void 0:Gr(e,s.group),O=s.index;if(p==null||_==null||p===_&&x===O)return"preventDefault"in t&&t.preventDefault(),e;if(p===_)return tn(en({},e),{[p]:n(e[p],x,O)});const T=e[p][x];return tn(en({},e),{[p]:[...e[p].slice(0,x),...e[p].slice(x+1)],[_]:[...e[_].slice(0,O),T,...e[_].slice(O)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,m=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(f==null){const p=Gr(e,o.id);if(p!=null){const x=o.shape&&m.y>o.shape.center.y?e[p].length:0;f=p,h=x}}if(c==null||f==null||c===f&&u===h){if(c!=null&&c===f&&u===h&&ns(s)){const p=s.group==null?void 0:Gr(e,s.group),x=s.group!=null&&p!==c,_=s.index!==u;if(x||_){const O=s.group==null?c:p;if(O!=null){if(c===O)return tn(en({},e),{[c]:n(e[c],u,s.index)});const T=e[c][u];return tn(en({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[O]:[...e[O].slice(0,s.index),T,...e[O].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===f)return tn(en({},e),{[c]:n(e[c],u,h)});const b=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][u];return tn(en({},e),{[c]:[...e[c].slice(0,u),...e[c].slice(u+1)],[f]:[...e[f].slice(0,h+b),v,...e[f].slice(h+b)]})}function mg(e,t){return vg(e,t,gg)}function yg({tiles:e,commit:t,onLanded:n}){const[r,i]=S.useState(void 0),s=S.useRef(void 0),[o,a]=S.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:c=>{const{source:h,target:f}=c.operation;if(!h||!f)return;const g=s.current??e;let m;if(f.type===Ed){const{after:w}=f.data,b=g.findIndex(x=>ht(x)===h.id);if(b<0||w===h.id)return;const p=g.filter((x,_)=>_!==b).findIndex(x=>ht(x)===w)+1;m=_p(g,b,p)}else{const w=g.map(ht),b=mg(w,c);if(b.every((p,x)=>p===w[x]))return;const v=new Map(g.map(p=>[ht(p),p]));m=xp(b.map(p=>v.get(p)),e.map(p=>p.break??!1))}s.current=m,i(m)},onDragEnd:c=>{a(!1);const h=s.current;if(s.current=void 0,i(void 0),c.canceled||!h)return;t(h);const f=h.findIndex(g=>ht(g)===c.operation.source?.id);f>=0&&n(f)}}}const Wa=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function bg({tiles:e,columns:t,onStart:n,commit:r}){const[i,s]=S.useState(void 0),o=S.useRef(null);return{resize:i,gridBox:o,startResize:(u,c)=>{const h=o.current?.getBoundingClientRect(),f=u.currentTarget.parentElement?.getBoundingClientRect();!h||!f||(u.stopPropagation(),u.preventDefault(),u.currentTarget.setPointerCapture(u.pointerId),Wa(!0),n(c),s({index:c,span:e[c]?.colspan??1,left:f.left,track:(h.width-j.GRID_GAP_PX*(t-1))/t}))},onResize:u=>{if(!i)return;const c=u.clientX-i.left,h=Math.round((c+j.GRID_GAP_PX)/(i.track+j.GRID_GAP_PX)),f=Math.min(Math.max(h,1),t);f!==i.span&&s({...i,span:f})},endResize:u=>{if(u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),Wa(!1),!i)return;const{index:c,span:h}=i;s(void 0),r(c,h)}}}function xg({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:i,columns:s,onDrills:o}){const{theme:a}=Le.usePublisherTheme(),{draft:l,patch:d,close:u,discard:c}=gd(t,e!==null,r,n),h=l!==void 0&&l.declaration.kind!=="inherited";return y.jsx(k.Popover,{open:e!==null&&l!==void 0,anchorEl:e,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:l&&y.jsxs(k.Stack,{sx:{gap:1.5},children:[y.jsxs(k.Typography,{variant:"overline",sx:{color:a.tileTitle,lineHeight:1.5},children:[l.source," → ",l.name]}),h?y.jsxs(y.Fragment,{children:[y.jsx(k.TextField,{size:"small",label:"Title",value:l.label??"",autoFocus:!0,inputProps:{"aria-label":"Tile title"},onChange:f=>d(g=>{const m=f.target.value;m===""?delete g.label:g.label=m})}),y.jsx(k.TextField,{size:"small",label:"Subtitle",value:l.subtitle??"",inputProps:{"aria-label":"Tile subtitle"},onChange:f=>d(g=>{const m=f.target.value;m===""?delete g.subtitle:g.subtitle=m})}),y.jsxs(k.Stack,{direction:"row",sx:{gap:.5,alignItems:"center"},children:[y.jsx(k.Typography,{variant:"caption",sx:{color:a.tileTitle,mr:.5},children:"Width"}),[["Full",1],["½",2],["⅓",3],["¼",4]].map(([f,g])=>{const m=Math.max(1,Math.round(s/g)),w=(l.colspan??1)===m;return y.jsx(k.Button,{size:"small",variant:w?"contained":"outlined","aria-label":`Width ${f}`,"aria-pressed":w,onClick:()=>d(b=>{b.colspan=m}),sx:{minWidth:40,px:1},children:f},f)})]})]}):y.jsx(k.Typography,{variant:"body2",sx:{color:a.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),y.jsx(k.Divider,{}),y.jsxs(k.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[h?y.jsx(k.Button,{size:"small",onClick:()=>{u(),o()},children:"Clickable cells…"}):y.jsx("span",{}),y.jsx(k.Button,{color:"error",size:"small",onClick:()=>{c(),i()},children:"Remove tile"})]})]})})}const xi=e=>e.ok===!1;function Nt(e,t){let n=t;for(let i=t-1;i>=0;i--){const s=e[i].trim();if(s==="")break;if(s.startsWith("#")||s.startsWith("//"))n=i;else break}const r=[];for(let i=n;i<t;i++){const s=e[i].trim();s.startsWith("#")&&!s.startsWith("##")&&r.push({line:i,text:s})}return{start:n,tags:r}}const Ns=e=>e.map(t=>t.text);function _g(e){const t=[],n=[];for(const r of e){const i=r.trim();if(i.startsWith('##"'))t.push(i.slice(3).trim());else{if(i.startsWith("##!"))continue;i.startsWith("##")&&n.push(i)}}return{description:t.length>0?t.join(`
70
- `):void 0,artifact:n}}function wg(e,t){return new RegExp(`source:\\s*${t}\\s+is\\s+([A-Za-z_][A-Za-z0-9_.]*)`).exec(e)?.[1]}function kg(e,t){const n=new RegExp(`view:\\s*${t}\\s+is\\s+([A-Za-z_][A-Za-z0-9_.]*)\\s*(\\+\\s*\\{[\\s\\S]*\\})?`).exec(e);if(n)return{kind:"reference",from:n[1],refinement:n[2]?.trim()};if(new RegExp(`view:\\s*${t}\\s+is\\s*\\{`).test(e))return{kind:"inline"}}const Dd=/where:\s*([A-Za-z_][A-Za-z0-9_.]*)\s*(~|>=|<=|!=|=|>|<)\s*\$([A-Za-z_][A-Za-z0-9_]*)/g;function Sg(e){if(!e)return;const t=[];for(const n of e.matchAll(Dd))t.push({field:n[1],given:n[3],...n[2]==="~"?{}:{op:n[2]}});return t.length>0?t:void 0}function $g(e,t){const n=[];for(const r of j.givenDeclarations(e).values()){const i=/^([A-Z_][A-Z0-9_]*)\s*::\s*(\S+)\s+is\s+(.+)$/.exec(r.declaration);i&&n.push({name:i[1],type:i[2],default:i[3].trim(),...Og(t(Ns(Nt(e,r.line).tags)).tag)})}return n.length>0?n:void 0}function Og(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),i=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...i===void 0?{}:{rangeMax:i}}}function Tg(e){const t=e.search(/tiles\s*=\s*\[/);if(t<0)return[];const n=e.indexOf("[",t),r=e.indexOf("]",n);return r<0?[]:[...e.slice(n+1,r).matchAll(/"([^"]+)"/g)].map(s=>s[1])}async function _i(e){const{Malloy:t}=await import("@malloydata/malloy"),{parseAnnotation:n}=await import("@malloydata/malloy-tag"),r=e.split(`
71
- `);let i;try{i=t.parse({source:e}).symbols}catch(x){return{ok:!1,reason:`This file is not valid Malloy: ${x}`}}const{description:s,artifact:o}=_g(r),a=o.find(x=>x.includes("artifact"));if(a===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a composite dashboard."};const l=n([a.replace(/^##\s*/,"# ")]).tag,d=l?.tag("artifact"),u=Tg(a);if(u.length===0)return{ok:!1,reason:"The `## artifact` tag names no tiles, so there is nothing to lay out."};const c=[],h=[],f=[],g=new Map;for(const x of i){if(x.type==="import"){const D=(x.children??[]).filter(L=>L.type==="import_item").map(L=>String(L.name));c.push(D.length>0?{kind:"names",names:D,from:String(x.name)}:{kind:"all",from:String(x.name)});continue}if(x.type!=="explore")continue;const _=String(x.name),O=r[x.range.start.line]??"",T=wg(O,_);if(T===void 0)return{ok:!1,reason:`Could not read what source \`${_}\` extends.`,line:x.range.start.line+1};h.push({name:_,base:T});const E=j.declarationsUnder(r,_,"view"),I=j.declarationsUnder(r,_,"dimension");I.size>0&&(h[h.length-1].dimensions=[...I].map(([D,L])=>({name:D,expression:L.rest})));for(const[D,L]of I){const{tags:M}=Nt(r,L.line),A=n(Ns(M)).tag?.tag("drill");if(!A)continue;const Q=A.textArray("to")??[A.text("to")??""];f.push({source:_,name:D,expression:L.rest,to:Q.filter(Boolean),...A.text("given")?{given:A.text("given")}:{}})}g.set(_,E)}const m=[];for(const x of u){const _=j.tileSteps(x);if(!_)return{ok:!1,reason:`The tile \`${x}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:O,view:T}=_,E=g.get(O)?.get(T)?.line;if(E===void 0){m.push({name:T,source:O,declaration:{kind:"inherited"}});continue}const I=kg(r[E],T);if(I===void 0)return{ok:!1,reason:`Could not read what view \`${T}\` is declared from.`,line:E+1};const{tags:D}=Nt(r,E),L=n(Ns(D)).tag,M=I.kind==="reference"?Sg(I.refinement):void 0;m.push({name:T,source:O,declaration:I.kind==="reference"?{kind:"reference",from:I.from}:{kind:"inline"},...M?{filters:M}:{},...L?.text("label")?{label:L.text("label")}:{},...L?.text("subtitle")?{subtitle:L.text("subtitle")}:{},...L?.numeric("colspan")!==void 0?{colspan:L.numeric("colspan")}:{},...L?.has("break")?{break:!0}:{},...L?.has("borderless")?{borderless:!0}:{}})}const w=$g(r,n),b={},v=d?.tag("givens");for(const x of Object.keys(v?.dict??{})){const _=v?.text(x);_!==void 0&&(b[x]=_)}const p=l?.tag("dashboard")?.numeric("columns");return{ok:!0,document:{title:d?.text("title")??"",...s?{description:s}:{},...p===void 0?{}:{columns:p},...d?.has("autorun")?{autorun:d.isTrue("autorun")}:{},imports:c,sources:h,...w?{localGivens:w}:{},...Object.keys(b).length>0?{startingGivens:b}:{},...f.length>0?{drills:f}:{},tiles:m}}}const Gs=e=>e.ok===!1;function me(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const i of Object.keys(n).sort())r[i]=t(n[i]);return r}return n};return JSON.stringify(t(e))}function Eg(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
72
- `&&t.push(n+1);return t}function Dg(e,t){let n=e;for(const r of[...t].sort((i,s)=>s.start-i.start))n=n.slice(0,r.start)+r.text+n.slice(r.end);return n}function Pd(e){const t=[];return e.colspan!==void 0&&t.push(`# colspan=${e.colspan}`),e.break&&t.push("# break"),e.borderless&&t.push("# borderless"),e.label!==void 0&&t.push(`# label=${_n(e.label)}`),e.subtitle!==void 0&&t.push(`# subtitle=${_n(e.subtitle)}`),t}function ni(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Pg=new Set(["colspan","break","borderless","label","subtitle"]),Cg=new Set(["label","description","control","suggest","range_min","range_max"]),Mg=(e,t)=>me(e.imports)===me(t.imports);function Fa(e){const t=[];if(e.label!==void 0&&t.push(`label=${_n(e.label)}`),e.description!==void 0&&t.push(`description=${_n(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${e.suggest.query}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${e.suggest.dimension} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const Ba=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function wi(e,t){let n=0,r=!1;for(let i=t;i<e.length;i++){for(const s of e[i])s==="{"?(n++,r=!0):s==="}"&&n--;if(r&&n<=0||!r&&i===t)return i}return e.length-1}const Na=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Ig(e,t,n){const r=e.findIndex(o=>new RegExp(`\\bsource:\\s*${Na(t)}\\s+is\\b`).test(o));if(r<0)return-1;const i=wi(e,r),s=new RegExp(`\\bview:\\s*${Na(n)}\\s+is\\b`);for(let o=r;o<=i;o++)if(s.test(e[o]))return o;return-1}function Ga(e){return`# drill { to=${e.to.length===1?e.to[0]:`[${e.to.map(n=>`"${n}"`).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const ki=e=>`${e.source}.${e.name}`,_n=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Vs=e=>me([e.name,e.source,e.declaration]),pt=Vs,Va=e=>me(e.tiles.map(pt));function jg(e,t){const n=new Set(e.tiles.map(pt)),r=new Set(t.tiles.map(pt)),i=e.tiles.filter(c=>!r.has(pt(c))),s=t.tiles.filter(c=>!n.has(pt(c))),a=i.length>0||s.length>0||Va(e)!==Va(t);for(const c of s)if(c.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${c.name}\` is ${c.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const l=new Map(e.sources.map(c=>[c.name,c])),d=new Set(e.imports.flatMap(c=>c.kind==="names"?c.names:[]));for(const c of e.sources)d.add(c.base);const u=t.sources.filter(c=>!l.has(c.name));for(const c of e.sources){const h=t.sources.find(f=>f.name===c.name);if(!h||h.base!==c.base)return{ok:!1,reason:`The source \`${c.name}\` cannot be changed or removed here.`}}for(const c of u){if(!s.some(h=>h.source===c.name))return{ok:!1,reason:`A new source \`${c.name}\` needs a tile on it.`};if(!d.has(c.base))return{ok:!1,reason:`\`${c.base}\` is not imported by name in this file, so a tile cannot be put on it. The builder does not add imports: import { ${c.base} } from the model first.`}}return Mg(e,t)?{currentKeys:n,nextKeys:r,removedTiles:i,addedTiles:s,newSources:u,currentSources:l,reordered:a}:{ok:!1,reason:"The dashboard's imports cannot be changed here."}}function Ag(e){const{lines:t,wholeLine:n,next:r,reordered:i,currentKeys:s,nextKeys:o,edits:a}=e;if(i){const l=j.artifactLine(t);if(l<0)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const d=[...t[l].matchAll(/"([^"]+)"/g)].map(g=>g[1]),u=new Map;for(const g of d){const m=g.split("->").map(w=>w.trim());m.length===2&&u.set(`${m[0]}->${m[1]}`,g)}const c=r.tiles.map(g=>u.get(`${g.source}->${g.name}`)??(o.has(pt(g))&&!s.has(pt(g))?`${g.source} -> ${g.name}`:void 0));if(c.some(g=>g===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const h=`tiles=[${c.map(g=>`"${g}"`).join(", ")}]`,f=t[l].replace(/tiles\s*=\s*\[[\s\S]*?\]/,h);f!==t[l]&&a.push({...n(l),text:`${f}
73
- `})}}function Rg(e){const{lines:t,wholeLine:n,current:r,next:i,edits:s}=e;if(r.title!==i.title||r.autorun!==i.autorun||r.columns!==i.columns||me(r.startingGivens)!==me(i.startingGivens)){const o=j.artifactLine(t);if(o<0)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=s.find(m=>m.start===n(o).start&&m.end===n(o).end);let l=a?a.text.replace(/\n$/,""):t[o];const d=l.indexOf("artifact"),u=l.indexOf("{",d);let c=0,h=-1;for(let m=u;m<l.length;m++)if(l[m]==="{")c++;else if(l[m]==="}"&&--c===0){h=m;break}if(u<0||h<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let f=l.slice(u+1,h);const g=(m,w)=>{const b=new RegExp(`\\s*\\b${m}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);w===void 0?f=f.replace(b,""):b.test(f)?f=f.replace(b,` ${m}=${w}`):f=`${f.replace(/\s+$/,"")} ${m}=${w} `};if(r.title!==i.title&&g("title",i.title?_n(i.title):void 0),r.autorun!==i.autorun&&g("autorun",i.autorun===void 0?void 0:String(i.autorun)),me(r.startingGivens)!==me(i.startingGivens)){f=f.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const m=Object.entries(i.startingGivens??{});m.length>0&&(f=`${f.replace(/\s+$/,"")} givens { ${m.map(([w,b])=>`${w}=${_n(b)}`).join(" ")} }`)}f=f.replace(/\s{2,}/g," "),l=`${l.slice(0,u+1)}${f.startsWith(" ")?f:` ${f}`}${f.endsWith(" ")?"":" "}${l.slice(h)}`,r.columns!==i.columns&&(l=l.replace(/\s*dashboard\s*\{[^}]*\}/,""),i.columns!==void 0&&(l=`${l.trimEnd()} dashboard { columns=${i.columns} }`)),a?a.text=`${l}
69
+ `);if(n.length>Aa||r.length>Aa)return[...n.map(l=>({kind:"del",text:l})),...r.map(l=>({kind:"add",text:l}))];const i=Array.from({length:n.length+1},()=>new Uint32Array(r.length+1));for(let l=n.length-1;l>=0;l--)for(let u=r.length-1;u>=0;u--)i[l][u]=n[l]===r[u]?i[l+1][u+1]+1:Math.max(i[l+1][u],i[l][u+1]);const s=[];let o=0,a=0;for(;o<n.length&&a<r.length;)n[o]===r[a]?(s.push({kind:"same",text:n[o]}),o++,a++):i[o+1][a]>=i[o][a+1]?s.push({kind:"del",text:n[o++]}):s.push({kind:"add",text:r[a++]});for(;o<n.length;)s.push({kind:"del",text:n[o++]});for(;a<r.length;)s.push({kind:"add",text:r[a++]});return s}function Pp(e,t=3){const n=new Array(e.length).fill(!1);e.forEach((s,o)=>{if(s.kind!=="same")for(let a=Math.max(0,o-t);a<=Math.min(e.length-1,o+t);a++)n[a]=!0});const r=[];let i=0;return e.forEach((s,o)=>{n[o]?(i>0&&r.push({kind:"fold",count:i}),i=0,r.push(s)):i++}),i>0&&r.push({kind:"fold",count:i}),r}function Mp({open:e,before:t,after:n,onConfirm:r,onClose:i}){const{theme:s}=Be.usePublisherTheme(),o=S.useMemo(()=>e?Pp(Cp(t,n)):[],[e,t,n]),a=o.filter(u=>u.kind==="add").length,l=o.filter(u=>u.kind==="del").length;return y.jsx(j.AppDialog,{open:e,onClose:i,maxWidth:"md",title:"Review the change to the file",description:y.jsxs(y.Fragment,{children:["A tile was added or removed, which moves declarations. Lines the builder does not own — comments, other Malloy — are left where they were; check they still read right."," ",y.jsxs(k.Box,{component:"span",sx:{fontVariantNumeric:"tabular-nums"},children:["+",a," −",l]})]}),actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:i,children:"Keep editing"}),y.jsx(k.Button,{variant:"contained",onClick:r,children:"Save this"})]}),children:y.jsx(k.Box,{component:"pre","aria-label":"File changes",sx:{m:0,px:2,py:1,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,lineHeight:1.6,overflowX:"auto",bgcolor:s.background,color:s.foreground},children:o.map((u,c)=>u.kind==="fold"?y.jsx(k.Box,{component:"span",sx:{display:"block",opacity:.55,py:.25},children:`⋯ ${u.count} unchanged line${u.count===1?"":"s"}`},c):y.jsxs(k.Box,{component:"span",sx:{display:"block",mx:-2,px:2,whiteSpace:"pre",bgcolor:u.kind==="add"?"rgba(46, 125, 91, 0.16)":u.kind==="del"?"rgba(168, 41, 31, 0.14)":"transparent",textDecoration:u.kind==="del"?"line-through":"none",opacity:u.kind==="del"?.8:1},children:[u.kind==="add"?"+ ":u.kind==="del"?"− ":" ",u.text]},c))})})}const rs="self";function Ip({open:e,document:t,source:n,givenNames:r,dashboards:i,onClose:s,onApply:o}){const{theme:a}=Be.usePublisherTheme(),[l,u]=S.useState([]);S.useEffect(()=>{if(!e||!n)return;const g=(t.drills??[]).filter(v=>v.source===n.name);u((n.dimensions??[]).map(v=>{const w=g.find(x=>x.name===v.name);return{name:v.name,expression:v.expression,to:w?.to??[],given:w?.given??""}}))},[e,n,t]);const c=(g,v)=>u(w=>w.map((x,m)=>{if(m!==g)return x;const p={...x};return v(p),p})),d=[rs,...i.filter(g=>g!==rs)],h=g=>g===rs?"This dashboard":g,f=()=>{n&&(o(l.filter(g=>g.to.length>0).map(g=>({source:n.name,name:g.name,expression:g.expression,to:g.to,...g.given?{given:g.given}:{}}))),s())};return y.jsx(j.AppDialog,{open:e,onClose:s,title:"Clickable cells",description:"A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the dashboard it opens.",actions:y.jsxs(y.Fragment,{children:[y.jsx(k.Button,{onClick:s,children:"Cancel"}),y.jsx(k.Button,{variant:"contained",onClick:f,disabled:l.length===0,children:"Apply"})]}),children:y.jsx(k.Stack,{sx:{gap:2,pt:1},children:l.length===0?y.jsx(k.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?y.jsxs(y.Fragment,{children:[y.jsx(k.Box,{component:"code",children:n.name})," declares no dimensions of its own in this file. A drill is a tag on the dimension's declaration, so a dimension the model declares is made clickable in the model; to make one clickable here, declare it in"," ",y.jsx(k.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((g,v)=>y.jsxs(k.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[y.jsxs(k.Box,{sx:{minWidth:0,pt:.75},children:[y.jsx(k.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:g.name}),y.jsxs(k.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g.expression,children:["is ",g.expression]})]}),y.jsx(k.TextField,{select:!0,size:"small",label:"Clicks go to",value:g.to,inputProps:{"aria-label":`Where ${g.name} goes`},SelectProps:{multiple:!0,renderValue:w=>w.length===0?"Not clickable":w.map(h).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:w=>c(v,x=>{const m=w.target.value;x.to=Array.isArray(m)?m:String(m).split(",").filter(Boolean)}),children:d.map(w=>y.jsxs(k.MenuItem,{value:w,children:[y.jsx(k.Checkbox,{size:"small",checked:g.to.includes(w),sx:{p:0,mr:1}}),y.jsx(k.ListItemText,{primary:h(w)})]},w))}),y.jsxs(k.TextField,{select:!0,size:"small",label:"Sets the control",value:g.given,disabled:g.to.length===0,inputProps:{"aria-label":`Control ${g.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:g.given===""?`Named ${g.name}, like the dimension`:void 0,onChange:w=>c(v,x=>{x.given=w.target.value}),children:[y.jsx(k.MenuItem,{value:"",children:y.jsx("em",{children:"Same name as the dimension"})}),r.map(w=>y.jsx(k.MenuItem,{value:w,children:w},w))]})]},g.name))})})}const Ed=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function jp({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:s}){const o=S.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[u,c]=S.useState({kind:"new"}),[d,h]=S.useState(""),[f,g]=S.useState("select"),[v,w]=S.useState(""),[x,m]=S.useState(""),[p,b]=S.useState([]),[_,$]=S.useState(!1),O=T=>t.sources.find(A=>A.name===T.source)?.base??T.source;S.useEffect(()=>{if(e)if(n){c({kind:"existing",name:n.name}),h(n.label??"");const T=fp(t,n);b(T);const A=T.filter(E=>E.include),G=new Set(A.map(E=>E.field));m(G.size===1?A[0].field:n.field??""),$(G.size>1)}else c({kind:"new"}),h(""),g("select"),m(""),w(new Date().toISOString().slice(0,10)),b(t.tiles.map(T=>({include:Us(T),field:""}))),$(!1)},[e,n,t]);const D=S.useMemo(()=>[...(t.localGivens??[]).map(T=>T.name),...r.map(T=>T.name)],[t,r]),M=S.useMemo(()=>x.trim()?up(x.trim(),D):"",[x,D]),I=u.kind==="existing"?n??r.find(T=>T.name===u.name):M?{name:M,type:Br({name:M,label:d,kind:f,field:x}).type}:void 0,K=I?.type!==void 0&&!I.type.startsWith("filter<"),z=p.find(T=>T.include)?.op??$i(I?.type),C=(T,A)=>b(G=>G.map((E,P)=>P===T?{...E,...A}:E)),W=T=>b(A=>A.map(G=>({...G,op:T}))),Y=T=>{const A=$i(T);b(G=>G.map(({op:E,...P})=>A?{...P,op:A}:P))},ve=T=>{c({kind:"existing",name:T.name}),m(T.field??""),Y(T.type)},Me=T=>{g(T),Y(Br({name:"X",label:d,kind:T,field:x}).type)},se=t.tiles.map(Us),Le=se.filter(Boolean).length,Ve=p.filter((T,A)=>T.include&&se[A]).length,Te=t.tiles.filter((T,A)=>(p[A]?.include??!1)&&se[A]),Ye=Te.length>0?Te:t.tiles.filter((T,A)=>se[A]),Ge=S.useMemo(()=>{const T=new Map;let A=!1;for(const G of Ye){const E=i?.(G);if(E){A=!0;for(const P of E)T.has(P.name)||T.set(P.name,P)}}return A?[...T.values()]:void 0},[p,t.tiles,i]),We=(()=>{const T=x.trim();for(const A of Te){const G=i?.(A);if(!G||G.some(E=>E.name===T))return O(A)}return Te[0]?O(Te[0]):t.sources[0]?.base})(),Xe=T=>b(A=>A.map((G,E)=>({...G,include:T&&se[E]}))),Se=S.useMemo(()=>_?p:p.map(T=>({...T,field:x})),[_,p,x]),ue=T=>{for(const A of Ye){const G=i?.(A)?.find(E=>E.name===T.trim());if(G?.type)return G.type}},L=T=>ai(I?.type,T.type),V=(T,A)=>{if(T.trim()==="")return"Pick the field this filter compares.";const G=A?i?.(A):void 0;if(!G)return;const E=G.find(P=>P.name===T.trim());if(!E)return`Not a field of ${A?O(A):"the tiles' source"}.`;if(E.type&&!ai(I?.type,E.type))return`${T.trim()} is ${Pa(E.type)}; this filter compares ${Pa(I?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},_e=T=>{if(m(T),l||u.kind!=="new")return;const A=ue(T),G=Br({name:"X",label:d,kind:f,field:T}).type;A&&!ai(G,A)&&Me(cp(A))},X=Se.map((T,A)=>T.include&&se[A]?V(T.field,t.tiles[A]):void 0),ze=X.every(T=>T===void 0),te=!_&&Ve>0?Te.map(T=>V(x,T)).find(Boolean):void 0,at=I!==void 0&&ze&&(u.kind==="existing"||x.trim()!==""&&M!==""),Fe=()=>{if(!(!I||!at))if(u.kind==="new")s(I.name,Se,Br({name:I.name,label:d.trim()||Ed(I.name),kind:f,field:x.trim(),...We?{source:We}:{},...v?{dateDefault:v}:{}}));else if(n?.origin==="dashboard"&&n.local){const T=d.trim(),A=T!==(n.local.label??"");s(I.name,Se,A?{...n.local,...T?{label:T}:{}}:void 0)}else s(I.name,Se)},xt=l&&a.origin==="model";return{editing:l,shown:a,fromModel:xt,source:u,setSource:c,label:d,setLabel:h,kind:f,dateDefault:v,setDateDefault:w,field:x,rows:p,setRows:b,perTile:_,setPerTile:$,newName:M,target:I,valueTyped:K,commonOp:z,setRow:C,setCommonOp:W,pickExisting:ve,pickKind:Me,bindable:se,bindableCount:Le,included:Ve,commonFields:Ge,setAll:Xe,accepts:L,pickField:_e,rowProblems:X,commonProblem:te,canApply:at,apply:Fe}}function Ra({value:e,onChange:t,fields:n,accepts:r,label:i,ariaLabel:s,error:o,helperText:a,disabled:l,autoFocus:u,placeholder:c,sx:d}){const h=S.useMemo(()=>(n??[]).filter(g=>r?.(g)??!0).map(g=>g.name),[n,r]),f=S.useMemo(()=>new Map((n??[]).map(g=>[g.name,g.type])),[n]);return y.jsx(k.Autocomplete,{freeSolo:!0,size:"small",options:h,inputValue:e,onInputChange:(g,v)=>t(v),value:e,onChange:(g,v)=>t(typeof v=="string"?v:""),disabled:l,disableClearable:!0,renderOption:(g,v)=>S.createElement("li",{...g,key:v},y.jsx(k.Typography,{variant:"body2",sx:{flex:1},children:v}),f.get(v)&&y.jsx(k.Typography,{variant:"caption",sx:{opacity:.6},children:f.get(v)?.replace(/_type$/,"")})),renderInput:g=>y.jsx(k.TextField,{...g,label:i,placeholder:c,autoFocus:u,error:o,helperText:a,inputProps:{...g.inputProps,"aria-label":s}}),sx:d})}const La=e=>e?.declaration.kind==="opaque"?{label:"Not bindable",reason:`Its body is ${e.declaration.why}, so a filter has no single place to go.`}:{label:"From the model",reason:"Declared on its source, which this dashboard does not write."};function Ap({open:e,document:t,control:n,available:r,fieldsFor:i,onClose:s,onApply:o,onRemove:a}){const{theme:l}=Be.usePublisherTheme(),{editing:u,shown:c,fromModel:d,source:h,setSource:f,label:g,setLabel:v,kind:w,dateDefault:x,setDateDefault:m,field:p,rows:b,setRows:_,perTile:$,setPerTile:O,newName:D,target:M,valueTyped:I,commonOp:K,setRow:z,setCommonOp:C,pickExisting:W,pickKind:Y,bindable:ve,bindableCount:Me,included:se,commonFields:Le,setAll:Ve,accepts:Te,pickField:Ye,rowProblems:Ge,commonProblem:We,canApply:Xe,apply:Se}=jp({open:e,document:t,control:n,available:r,fieldsFor:i,onApply:o}),ue=(L,V,_e)=>y.jsx(k.TextField,{select:!0,size:"small",label:"Compares",value:L??">=",onChange:X=>V(X.target.value),inputProps:{"aria-label":_e},sx:{width:130},children:dp.filter(X=>X.op!=="~").map(X=>y.jsx(k.MenuItem,{value:X.op,children:X.label},X.op))});return y.jsx(j.AppDialog,{open:e,onClose:s,title:u?c.label??c.name:"Add a filter",description:u?y.jsxs(y.Fragment,{children:[y.jsxs(k.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",c.name]}),d?" · declared in the model, so its label and options are set there":" · declared in this dashboard"]}):"A control on the page, and the tiles it filters.",actions:y.jsxs(y.Fragment,{children:[u&&y.jsx(k.Button,{color:"error",onClick:()=>a(c.name),"aria-label":`Remove control ${c.name}`,sx:{mr:"auto"},children:"Remove from dashboard"}),y.jsx(k.Button,{onClick:s,children:"Cancel"}),y.jsx(k.Tooltip,{title:Xe||M===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:y.jsx("span",{children:y.jsx(k.Button,{variant:"contained",onClick:Se,disabled:!Xe,children:u?"Apply":"Add filter"})})})]}),children:y.jsxs(k.Stack,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&y.jsxs(k.ToggleButtonGroup,{exclusive:!0,size:"small",value:h.kind,onChange:(L,V)=>{V==="new"?f({kind:"new"}):V==="existing"&&r[0]&&W(r[0])},"aria-label":"Where the filter comes from",children:[y.jsx(k.ToggleButton,{value:"new",children:"New in this dashboard"}),y.jsx(k.ToggleButton,{value:"existing",children:"From the model"})]}),!u&&h.kind==="existing"?y.jsx(k.TextField,{select:!0,size:"small",label:"Control",value:h.name,onChange:L=>{const V=r.find(_e=>_e.name===L.target.value);V&&W(V)},children:r.map(L=>y.jsxs(k.MenuItem,{value:L.name,children:[L.label??L.name,y.jsxs(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",L.name]})]},L.name))}):null,y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!$&&y.jsx(Ra,{value:p,onChange:Ye,fields:Le,accepts:Te,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:We!==void 0,helperText:We??(!u&&D?`Declared as $${D}`:void 0),sx:{flex:1,minWidth:200}}),!d&&y.jsx(k.TextField,{size:"small",label:"Label",placeholder:D?Ed(D):"",value:g,onChange:L=>v(L.target.value),inputProps:{"aria-label":"Control label"},sx:{flex:1,minWidth:160}}),I&&!$&&ue(K,C,"Comparison")]}),!u&&h.kind==="new"&&y.jsxs(k.Stack,{direction:"row",sx:{gap:1.5},children:[y.jsx(k.TextField,{select:!0,size:"small",label:"Control",value:w,onChange:L=>Y(L.target.value),inputProps:{"aria-label":"Kind of control"},slotProps:{select:{renderValue:L=>Ma.find(V=>V.kind===L)?.label??String(L)}},sx:{flex:1},children:Ma.map(L=>y.jsxs(k.MenuItem,{value:L.kind,children:[L.label,y.jsx(k.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:L.hint})]},L.kind))}),w==="date"&&y.jsx(k.TextField,{size:"small",type:"date",label:"Starts at",value:x,onChange:L=>m(L.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),y.jsxs(k.Box,{children:[y.jsxs(k.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[y.jsx(k.Checkbox,{size:"small",checked:Me>0&&se===Me,indeterminate:se>0&&se<Me,disabled:Me===0,onChange:L=>Ve(L.target.checked),inputProps:{"aria-label":"All tiles"}}),y.jsxs(k.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",se," of ",t.tiles.length," tiles"]}),y.jsx(k.Button,{size:"small",onClick:()=>{$||_(L=>L.map(V=>({...V,field:p}))),O(L=>!L)},children:$?"Same field for all":"Adjust per tile"})]}),y.jsx(k.Stack,{sx:{gap:$?1:0},children:t.tiles.map((L,V)=>{const _e=b[V],X=L.label??L.name,ze=$?Ge[V]:void 0;return y.jsxs(k.Stack,{direction:"row",sx:{gap:1,alignItems:$?"flex-start":"center",opacity:ve[V]?1:.6},children:[y.jsx(k.Checkbox,{size:"small",disabled:!ve[V],checked:(_e?.include??!1)&&ve[V],inputProps:{"aria-label":`Filter ${X}`},onChange:te=>z(V,{include:te.target.checked})}),y.jsx(k.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:$?1:0},noWrap:!0,children:X}),ve[V]?$&&y.jsxs(y.Fragment,{children:[I&&ue(_e?.op,te=>z(V,{op:te}),`Comparison for ${X}`),y.jsx(Ra,{value:_e?.field??"",onChange:te=>z(V,{field:te}),fields:i?.(L),accepts:Te,label:"Field",ariaLabel:`Field for ${X}`,disabled:!_e?.include,error:ze!==void 0,helperText:ze,sx:{width:220}})]}):y.jsx(k.Tooltip,{title:La(t.tiles[V]).reason,children:y.jsx(k.Typography,{variant:"caption",sx:{color:l.tileTitle},children:La(t.tiles[V]).label})})]},`${L.source}.${L.name}`)})}),se===0&&y.jsx(k.Typography,{variant:"caption",sx:{color:"warning.main",display:"block",mt:1},children:"No tile is ticked, so this control will not appear on the dashboard."})]})]})})}function Od(e,t,n,r){const[i,s]=S.useState(void 0);return S.useEffect(()=>{t&&e!==void 0&&s(structuredClone(e))},[t,e]),{draft:i,patch:u=>s(c=>{if(c===void 0)return c;const d=structuredClone(c);return u(d),d}),close:()=>{i!==void 0&&e!==void 0&&JSON.stringify(i)!==JSON.stringify(e)&&n(i),r()},discard:()=>s(void 0)}}const Rp=e=>({title:e.title,...e.description===void 0?{}:{description:e.description},...e.columns===void 0?{}:{columns:e.columns},...e.autorun===void 0?{}:{autorun:e.autorun}}),is=[2,3,4,6,8,12,16,24];function Lp({anchor:e,settings:t,onClose:n,onCommit:r}){const{theme:i}=Be.usePublisherTheme(),{draft:s,patch:o,close:a}=Od(t,e!==null,r,n),l=s?.columns!==void 0&&!is.includes(s.columns)?[...is,s.columns].sort((u,c)=>u-c):is;return y.jsx(k.Popover,{open:e!==null&&s!==void 0,anchorEl:e,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:380,p:2}}},children:s&&y.jsxs(k.Stack,{sx:{gap:1.5},children:[y.jsx(k.Typography,{variant:"overline",sx:{color:i.tileTitle,lineHeight:1.5},children:"Dashboard"}),y.jsx(k.TextField,{size:"small",label:"Title",value:s.title,autoFocus:!0,inputProps:{"aria-label":"Dashboard title"},onChange:u=>o(c=>{c.title=u.target.value})}),y.jsx(k.TextField,{size:"small",label:"Description",multiline:!0,minRows:3,maxRows:10,value:s.description??"",helperText:"Markdown. A blank line starts a new paragraph.",inputProps:{"aria-label":"Dashboard description"},onChange:u=>o(c=>{const d=u.target.value;d.trim()===""?delete c.description:c.description=d})}),y.jsxs(k.TextField,{select:!0,size:"small",label:"Grid width",value:s.columns??"",helperText:"Columns across the page. Tiles are placed in these.",inputProps:{"aria-label":"Grid width"},onChange:u=>o(c=>{const d=Number(u.target.value);d?c.columns=d:delete c.columns}),children:[y.jsx(k.MenuItem,{value:"",children:"Default (2)"}),l.map(u=>y.jsx(k.MenuItem,{value:u,children:u},u))]}),y.jsx(k.FormControlLabel,{control:y.jsx(k.Switch,{size:"small",checked:s.autorun!==!1,slotProps:{input:{"aria-label":"Run as controls change"}},onChange:u=>o(c=>{u.target.checked?delete c.autorun:c.autorun=!1})}),label:y.jsxs(k.Typography,{variant:"body2",children:["Run as controls change",y.jsx(k.Typography,{component:"span",variant:"caption",sx:{display:"block",opacity:.7},children:"Off, readers press Apply. For a page whose queries are slow."})]})})]})})}const Wp=j.createSvgIcon(y.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function zp({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:i,children:s}){const{theme:o}=Be.usePublisherTheme();return y.jsx(y.Fragment,{children:y.jsxs(k.Stack,{sx:{gap:1},children:[y.jsxs(k.Stack,{direction:"row","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",minHeight:32},children:[y.jsx(Wp,{sx:{fontSize:18,color:o.tileTitle,opacity:.7}}),y.jsx(k.Typography,{variant:"subtitle2",sx:{color:o.tileTitle,mr:.5},children:"Filters"}),e.length===0&&y.jsx(k.Typography,{variant:"body2",sx:{color:o.tileTitle,opacity:.8},children:"None yet."}),e.map(a=>{const l=n(a.name,a.type);return y.jsx(k.Tooltip,{title:l.length>0?`$${a.name} · cannot filter on: ${l.join(", ")}`:`$${a.name} · ${a.origin==="dashboard"?"declared here":"from the model"} · ${a.boundTiles} of ${t} tiles`,children:y.jsx(k.Chip,{size:"small",label:a.label??a.name,"aria-label":`Edit filter ${a.name}`,color:l.length>0?"warning":"default",variant:a.origin==="dashboard"?"filled":"outlined",onClick:()=>r(a),sx:{opacity:a.boundTiles===0?.6:1,cursor:"pointer",transition:"opacity 120ms"}})},a.name)}),y.jsx(k.Box,{sx:{ml:"auto"},children:y.jsx(j.SecondaryButton,{label:"Filter",icon:y.jsx(j.AddIcon,{}),onClick:()=>i(),ariaLabel:"Add filter",ariaHasPopup:"dialog"})})]}),s]})})}const Fp=(e,t)=>e.map((n,r)=>{const i=t[r]??!1;if(i===(n.break??!1))return n;const s={...n};return i?s.break=!0:delete s.break,s}),Np=(e,t,n)=>{const r=[...e],[i]=r.splice(t,1);if(!i)return[...e];const s=r[t];i.break&&s&&!s.break&&(r[t]={...s,break:!0});const o={...i};return delete o.break,r.splice(n,0,o),r},Dd=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),Td=e=>`gap.${e}`,Bp=(e,t)=>{const n=[];let r=0;e.forEach((s,o)=>{const a=Math.min(s.colspan??1,t),l=o===0||s.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:pt(e[o-1]),colspan:t-r}),l&&(r=0),n.push(Dd(s,o)),r+=a});const i=e.at(-1);return i&&r<t&&n.push({kind:"gap",after:pt(i),colspan:t-r}),n};var Vp=Object.create,Cd=Object.defineProperty,Gp=Object.defineProperties,Up=Object.getOwnPropertyDescriptor,Hp=Object.getOwnPropertyDescriptors,Ei=Object.getOwnPropertySymbols,Pd=Object.prototype.hasOwnProperty,Md=Object.prototype.propertyIsEnumerable,qp=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ir=e=>{throw TypeError(e)},qs=(e,t,n)=>t in e?Cd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ss=(e,t)=>{for(var n in t||(t={}))Pd.call(t,n)&&qs(e,n,t[n]);if(Ei)for(var n of Ei(t))Md.call(t,n)&&qs(e,n,t[n]);return e},os=(e,t)=>Gp(e,Hp(t)),Kp=(e,t)=>{var n={};for(var r in e)Pd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ei)for(var r of Ei(e))t.indexOf(r)<0&&Md.call(e,r)&&(n[r]=e[r]);return n},Yp=e=>{var t;return[,,,Vp((t=void 0)!=null?t:null)]},Id=["class","method","getter","setter","accessor","field","value","get","set"],ir=e=>e!==void 0&&typeof e!="function"?Ir("Function expected"):e,Xp=(e,t,n,r,i)=>({kind:Id[e],name:t,metadata:r,addInitializer:s=>n._?Ir("Already initialized"):i.push(ir(s||null))}),Qp=(e,t)=>qs(t,qp("metadata"),e[3]),Gr=(e,t,n,r)=>{for(var i=0,s=e[t>>1],o=s&&s.length;i<o;i++)t&1?s[i].call(n):r=s[i].call(n,r);return r},jd=(e,t,n,r,i,s)=>{for(var o,a,l,u,c,d=t&7,h=!1,f=!1,g=e.length+1,v=Id[d+5],w=e[g-1]=[],x=e[g]||(e[g]=[]),m=(i=i.prototype,Up({get[n](){return sr(this,s)},set[n](b){return Ft(this,s,b)}},n)),p=r.length-1;p>=0;p--)u=Xp(d,n,l={},e[3],x),u.static=h,u.private=f,c=u.access={has:b=>n in b},c.get=b=>b[n],c.set=(b,_)=>b[n]=_,a=(0,r[p])({get:m.get,set:m.set},u),l._=1,a===void 0?ir(a)&&(m[v]=a):typeof a!="object"||a===null?Ir("Object expected"):(ir(o=a.get)&&(m.get=o),ir(o=a.set)&&(m.set=o),ir(o=a.init)&&w.unshift(o));return m&&Cd(i,n,m),i},Ad=(e,t,n)=>t.has(e)||Ir("Cannot "+n),sr=(e,t,n)=>(Ad(e,t,"read from private field"),t.get(e)),Un=(e,t,n)=>t.has(e)?Ir("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ft=(e,t,n,r)=>(Ad(e,t,"write to private field"),t.set(e,n),n);function Bt(e){return e instanceof ea||e instanceof zd}var Ur=10,Zp=class extends Pe{constructor(e){super(e);const t=tt(()=>{const{dragOperation:r}=e;if(br(r.activatorEvent)&&Bt(r.source)&&r.status.initialized){const i=e.registry.plugins.get(Pr);if(i)return i.disable(),()=>i.enable()}}),n=e.monitor.addEventListener("dragmove",(r,i)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:s}=i;if(!br(r.nativeEvent)||!Bt(s.source)||!s.shape)return;const{actions:o,collisionObserver:a,registry:l}=i,{by:u}=r;if(!u)return;const c=Jp(u),{source:d,target:h}=s,{center:f}=s.shape.current,g=[],v=[];de(()=>{for(const _ of l.droppables){const{id:$}=_;if(!_.accepts(d)||$===h?.id&&Bt(_)||!_.element)continue;let O=_.shape;const D=new ct(_.element,{getBoundingClientRect:M=>mr(M,void 0,.2)});!D.height||!D.width||(c=="down"&&f.y+Ur<D.center.y||c=="up"&&f.y-Ur>D.center.y||c=="left"&&f.x-Ur>D.center.x||c=="right"&&f.x+Ur<D.center.x)&&(g.push(_),_.shape=D,v.push(()=>_.shape=O))}}),r.preventDefault(),a.disable();const w=a.computeCollisions(g,Nf);de(()=>v.forEach(_=>_()));const[x]=w;if(!x)return;const{id:m}=x,{index:p,group:b}=d.sortable;o.setDropTarget(m).then(()=>{const{source:_,target:$,shape:O}=s;if(!_||!Bt(_)||!O)return;const{index:D,group:M,target:I}=_.sortable,K=p!==D||b!==M,z=K?I:$?.element;if(!z)return;Cc(z);const C=new ct(z);if(!C)return;const W=dt.delta(C,dt.from(O.current.boundingRectangle),_.alignment);o.move({by:W}),K?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Jp(e){const{x:t,y:n}=e;if(t>0)return"right";if(t<0)return"left";if(n>0)return"down";if(n<0)return"up"}var eg=Object.defineProperty,tg=Object.defineProperties,ng=Object.getOwnPropertyDescriptors,Wa=Object.getOwnPropertySymbols,rg=Object.prototype.hasOwnProperty,ig=Object.prototype.propertyIsEnumerable,za=(e,t,n)=>t in e?eg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nn=(e,t)=>{for(var n in t||(t={}))rg.call(t,n)&&za(e,n,t[n]);if(Wa)for(var n of Wa(t))ig.call(t,n)&&za(e,n,t[n]);return e},rn=(e,t)=>tg(e,ng(t));function sg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Hr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function as(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function og(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(p,b)=>p===b||p!==null&&typeof p=="object"&&"id"in p&&p.id===b;if(Array.isArray(e)){const p=e.findIndex(_=>l(_,s.id)),b=e.findIndex(_=>l(_,o.id));if(p===-1||b===-1){if(as(s)){const _=s.initialIndex,$=s.index;return _===$||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,$)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const _=s.index;if(_!==p)return n(e,p,_)}return n(e,p,b)}const u=Object.entries(e);let c=-1,d,h=-1,f;for(const[p,b]of u)if(c===-1&&(c=b.findIndex(_=>l(_,s.id)),c!==-1&&(d=p)),h===-1&&(h=b.findIndex(_=>l(_,o.id)),h!==-1&&(f=p)),c!==-1&&h!==-1)break;if(c===-1&&as(s)){const p=s.initialGroup==null?void 0:Hr(e,s.initialGroup),b=s.initialIndex,_=s.group==null?void 0:Hr(e,s.group),$=s.index;if(p==null||_==null||p===_&&b===$)return"preventDefault"in t&&t.preventDefault(),e;if(p===_)return rn(nn({},e),{[p]:n(e[p],b,$)});const O=e[p][b];return rn(nn({},e),{[p]:[...e[p].slice(0,b),...e[p].slice(b+1)],[_]:[...e[_].slice(0,$),O,...e[_].slice($)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,v=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(f==null){const p=Hr(e,o.id);if(p!=null){const b=o.shape&&v.y>o.shape.center.y?e[p].length:0;f=p,h=b}}if(d==null||f==null||d===f&&c===h){if(d!=null&&d===f&&c===h&&as(s)){const p=s.group==null?void 0:Hr(e,s.group),b=s.group!=null&&p!==d,_=s.index!==c;if(b||_){const $=s.group==null?d:p;if($!=null){if(d===$)return rn(nn({},e),{[d]:n(e[d],c,s.index)});const O=e[d][c];return rn(nn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[$]:[...e[$].slice(0,s.index),O,...e[$].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===f)return rn(nn({},e),{[d]:n(e[d],c,h)});const x=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,m=e[d][c];return rn(nn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[f]:[...e[f].slice(0,h+x),m,...e[f].slice(h+x)]})}function ag(e,t){return og(e,t,sg)}function Fa(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function Na(e,t,n){var r;for(const[i,s]of t)for(const o of s){const a=e.get(o.id);if(o.index!==a||o.group!==i||!((r=n.get(i))!=null&&r.has(o)))return!0}return!1}var Ba="__default__",lg=class extends Pe{constructor(e){super(e);const t=()=>{const r=new Map;for(const i of e.registry.droppables)if(i instanceof ea){const{sortable:s}=i,{group:o}=s;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(s)}return r},n=[e.monitor.addEventListener("dragover",(r,i)=>{if(this.disabled)return;const{dragOperation:s}=i,{source:o,target:a}=s;if(!Bt(o)||!Bt(a)||o.sortable===a.sortable)return;const l=t(),u=Fa(l),c=o.sortable.group===a.sortable.group,d=l.get(o.sortable.group),h=c?d:l.get(a.sortable.group);!d||!h||queueMicrotask(()=>{r.defaultPrevented||i.renderer.rendering.then(()=>{var f,g;const v=t();if(Na(u,l,v))return;const w=o.sortable.element,x=a.sortable.element;if(!x||!w||!c&&a.id===o.sortable.group)return;const m=qr(d),p=c?m:qr(h),b=(f=o.sortable.group)!=null?f:Ba,_=(g=a.sortable.group)!=null?g:Ba,$={[b]:m,[_]:p},O=ag($,r);if($===O)return;const D=O[_].indexOf(o.sortable),M=O[_].indexOf(a.sortable);i.collisionObserver.disable(),Va(w,D,x,M),de(()=>{for(const[I,K]of O[b].entries())K.index=I;if(!c)for(const[I,K]of O[_].entries())K.group=a.sortable.group,K.index=I}),i.actions.setDropTarget(o.id).then(()=>i.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,i)=>{if(!r.canceled)return;const{dragOperation:s}=i,{source:o}=s;Bt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=Fa(a),u=a.get(o.sortable.initialGroup);u&&i.renderer.rendering.then(()=>{const c=t();if(Na(l,a,c))return;const d=qr(u),h=qr(u,dg),f=o.sortable.element,g=h.indexOf(o.sortable),v=d[g],w=v?.element;!v||!w||!f||(Va(f,v.index,w,o.index),de(()=>{for(const x of a.values()){const m=Array.from(x).values();for(const p of m)p.index=p.initialIndex,p.group=p.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function Va(e,t,n,r){const i=r<t?"afterend":"beforebegin";n.insertAdjacentElement(i,e)}function cg(e,t){return e.index-t.index}function dg(e,t){return e.initialIndex-t.initialIndex}function qr(e,t=cg){return Array.from(e).sort(t)}var Ga=[Zp,lg],Rd={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function Ua(e){var t,n;return typeof e=="boolean"?{draggable:e,droppable:e}:{draggable:(t=e?.draggable)!=null?t:!1,droppable:(n=e?.droppable)!=null?n:!1}}var Kr=new ku,Ld,Wd,Ot,Zo,or,ar,Jo,hn;Wd=[H],Ld=[H];var Ni=class{constructor(e,t){Un(this,Zo,Gr(Ot,8,this)),Gr(Ot,11,this),Un(this,or),Un(this,ar),Un(this,Jo,Gr(Ot,12,this)),Gr(Ot,15,this),Un(this,hn),this.register=()=>(de(()=>{var g,v;(g=this.manager)==null||g.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{de(()=>{var g,v;(g=this.manager)==null||g.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{de(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:i,group:s,index:o,sensors:a,type:l,transition:u=Rd,plugins:c}=n,d=Kp(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const h=st(c,Ga),f=Ua(i);this.droppable=new ea(os(ss({},d),{disabled:f.droppable}),t,this),this.draggable=new zd(os(ss({},d),{disabled:f.draggable,plugins:h,effects:()=>[()=>{var g,v,w;const x=(g=this.manager)==null?void 0:g.dragOperation.status;x?.initializing&&this.id===((w=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:w.id)&&Kr.clear(this.manager),x?.dragging&&Kr.set(this.manager,this.id,U(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:g,group:v,manager:w}=this,x=sr(this,ar),m=sr(this,or);(g!==x||v!==m)&&(Ft(this,ar,g),Ft(this,or,v),this.animate())},()=>{var g,v;const{target:w}=this,{isDragSource:x}=this.draggable;((v=(g=this.draggable.pluginConfig(Vo))==null?void 0:g.feedback)!=null?v:"default")==="move"&&x&&(this.droppable.disabled=!w)},...r()],type:l,sensors:a}),t,this),Ft(this,hn,d.element),this.manager=t,this.index=o,Ft(this,ar,o),this.group=s,Ft(this,or,s),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=Kr.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Kr.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){U(()=>{const{manager:e,transition:t}=this,{shape:n}=this.droppable;if(!e)return;const{idle:r}=e.dragOperation.status;!n||!t||r&&!t.idle||e.renderer.rendering.then(()=>{const{element:i}=this;if(!i)return;for(const c of i.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const s=this.refreshShape();if(!s)return;const o={x:n.boundingRectangle.left-s.boundingRectangle.left,y:n.boundingRectangle.top-s.boundingRectangle.top},{translate:a}=ht(i),l=wa(i,a,!1),u=wa(i,a);if(o.x||o.y){const c=Ao(Ke(i))?os(ss({},t),{duration:0}):t;Pc({element:i,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:c}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){de(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){de(()=>{const t=sr(this,hn),n=this.droppable.element,r=this.draggable.element;(!n||n===t)&&(this.droppable.element=e),(!r||r===t)&&(this.draggable.element=e),Ft(this,hn,e)})}get element(){var e,t;const n=sr(this,hn);if(n)return(t=(e=Es.get(n))!=null?e:n)!=null?t:this.droppable.element}set target(e){this.droppable.element=e}get target(){return this.droppable.element}set source(e){this.draggable.element=e}get source(){return this.draggable.element}get disabled(){const{disabled:e}=this.draggable,{disabled:t}=this.droppable;return e===t?e:{draggable:e,droppable:t}}set plugins(e){this.draggable.plugins=st(e,Ga)}set disabled(e){const t=Ua(e);de(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){de(()=>{this.droppable.data=e,this.draggable.data=e})}set handle(e){this.draggable.handle=e}set id(e){this.droppable.id=e,this.draggable.id=e}get id(){return this.droppable.id}set sensors(e){this.draggable.sensors=e}set modifiers(e){this.draggable.modifiers=e}set collisionPriority(e){this.droppable.collisionPriority=e}set collisionDetector(e){this.droppable.collisionDetector=e??Mc}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){de(()=>{this.droppable.type=e,this.draggable.type=e})}get type(){return this.draggable.type}set accept(e){this.droppable.accept=e}get accept(){return this.droppable.accept}get isDropTarget(){return this.droppable.isDropTarget}get isDragSource(){return this.draggable.isDragSource}get isDragging(){return this.draggable.isDragging}get isDropping(){return this.draggable.isDropping}get status(){return this.draggable.status}refreshShape(){return this.droppable.refreshShape()}accepts(e){return this.droppable.accepts(e)}};Ot=Yp();Zo=new WeakMap;or=new WeakMap;ar=new WeakMap;Jo=new WeakMap;hn=new WeakMap;jd(Ot,4,"index",Wd,Ni,Zo);jd(Ot,4,"group",Ld,Ni,Jo);Qp(Ot,Ni);var zd=class extends Wi{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get initialIndex(){return this.sortable.initialIndex}get group(){return this.sortable.group}get initialGroup(){return this.sortable.initialGroup}},ea=class extends zi{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},ug=Object.defineProperty,fg=Object.defineProperties,hg=Object.getOwnPropertyDescriptors,Ha=Object.getOwnPropertySymbols,pg=Object.prototype.hasOwnProperty,gg=Object.prototype.propertyIsEnumerable,qa=(e,t,n)=>t in e?ug(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ls=(e,t)=>{for(var n in t||(t={}))pg.call(t,n)&&qa(e,n,t[n]);if(Ha)for(var n of Ha(t))gg.call(t,n)&&qa(e,n,t[n]);return e},vg=(e,t)=>fg(e,hg(t));function mg(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:i,data:s,element:o,handle:a,index:l,group:u,disabled:c,modifiers:d,sensors:h,target:f,type:g,plugins:v}=e,w=ls(ls({},Rd),e.transition),x=pd(p=>new Ni(vg(ls({},e),{transition:w,register:!1,handle:yn(a),element:yn(o),target:yn(f)}),p)),m=dd(x,yg);return ae(i,()=>x.id=i),Ln(()=>{de(()=>{x.group=u,x.index=l})},[x,u,l]),ae(g,()=>x.type=g),ae(t,()=>x.accept=t,void 0,rt),ae(s,()=>s&&(x.data=s)),ae(l,()=>{var p;(p=x.manager)!=null&&p.dragOperation.status.idle&&w?.idle&&x.refreshShape()},Ah),si(a,p=>x.handle=p),si(o,p=>x.element=p),si(f,p=>x.target=p),ae(c,()=>x.disabled=c??!1,void 0,rt),ae(h,()=>x.sensors=h,void 0,rt),ae(n,()=>x.collisionDetector=n),ae(r,()=>x.collisionPriority=r),ae(v,()=>x.plugins=v,void 0,rt),ae(w,()=>x.transition=w,void 0,rt),ae(d,()=>x.modifiers=d,void 0,rt),ae(e.alignment,()=>x.alignment=e.alignment),{sortable:m,get isDragging(){return m.isDragging},get isDropping(){return m.isDropping},get isDragSource(){return m.isDragSource},get isDropTarget(){return m.isDropTarget},handleRef:S.useCallback(p=>{x.handle=p??void 0},[x]),ref:S.useCallback(p=>{var b,_;!p&&((b=x.element)!=null&&b.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.element=p??void 0)},[x]),sourceRef:S.useCallback(p=>{var b,_;!p&&((b=x.source)!=null&&b.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.source=p??void 0)},[x]),targetRef:S.useCallback(p=>{var b,_;!p&&((b=x.target)!=null&&b.isConnected)&&!((_=x.manager)!=null&&_.dragOperation.status.idle)||(x.target=p??void 0)},[x])}}function yg(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const Ks="tile",Fd="gap",bg='[role="separator"]',xg=[Fs.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>(Fs.defaults.preventActivation?.(e,t)??!1)||e.target instanceof Element&&e.target.closest(bg)!==null}),nd],wg=e=>[...e,Vo.configure({feedback:"clone"})];function _g({id:e,index:t,children:n}){const{ref:r,handleRef:i,isDragSource:s}=mg({id:e,index:t,type:Ks,accept:Ks,collisionDetector:Lo,plugins:wg});return y.jsx(y.Fragment,{children:n({ref:r,handleRef:i,isDragSource:s})})}function kg({id:e,after:t,children:n}){const{ref:r,isDropTarget:i}=op({id:e,type:Fd,accept:Ks,collisionDetector:Lo,data:{after:t}});return y.jsx(y.Fragment,{children:n({ref:r,isDropTarget:i})})}const Sg=j.createSvgIcon(y.jsx("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2m-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"})),$g=j.createSvgIcon(y.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2m0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2m0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2"}));function Eg({tile:e,index:t,selected:n,menuOpen:r,resizeSpan:i,columns:s,onSelect:o,onOpenMenu:a,onResizeStart:l,onResizeMove:u,onResizeEnd:c,children:d}){const{theme:h}=Be.usePublisherTheme();return y.jsx(_g,{id:pt(e),index:t,children:({ref:f,handleRef:g,isDragSource:v})=>y.jsxs(k.Box,{ref:f,onClick:o,onPointerDown:w=>{w.button===0&&o()},"aria-label":`Tile ${e.name}`,"aria-current":n,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",borderRadius:1,outline:n?`2px solid ${h.drillLink}`:"2px solid transparent",outlineOffset:2,transition:"outline-color 120ms, opacity 120ms, box-shadow 120ms","&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:"0 12px 32px rgba(0, 0, 0, 0.22)"},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${h.drillLink}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"&:hover":{outlineColor:n?h.drillLink:h.cardBorder,boxShadow:"0 2px 10px rgba(0, 0, 0, 0.10)"}},children:[d,y.jsx(k.Box,{ref:g,className:"builder-affordance","aria-label":`Move ${e.label??e.name}`,sx:{position:"absolute",top:"2px",left:"2px",display:"grid",placeItems:"center",width:"22px",height:"22px",borderRadius:"4px",cursor:"grab",touchAction:"none",zIndex:2,color:h.tileTitle,bgcolor:h.tile,opacity:v||n?.9:0,transition:"opacity 120ms","&:hover":{opacity:1},"&:active":{cursor:"grabbing"},"&:focus-visible":{opacity:1,outline:`2px solid ${h.drillLink}`,outlineOffset:1}},children:y.jsx(Sg,{sx:{fontSize:16}})}),i===void 0&&y.jsx(k.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${e.label??e.name}`,onClick:w=>{w.stopPropagation(),a(w.currentTarget)},sx:{position:"absolute",top:"2px",right:"2px",width:22,height:22,zIndex:2,color:h.tileTitle,bgcolor:h.tile,opacity:n||r?.9:0,transition:"opacity 120ms","&:hover":{opacity:1,bgcolor:h.tile}},children:y.jsx($g,{sx:{fontSize:16}})}),i!==void 0&&y.jsxs(k.Box,{"aria-hidden":!0,sx:{position:"absolute",top:"6px",right:"6px",px:.75,py:.25,borderRadius:"4px",bgcolor:h.drillLink,color:h.tile,fontSize:11,fontVariantNumeric:"tabular-nums",zIndex:4,pointerEvents:"none"},children:[i," of ",s," ·"," ",Math.round(i/s*100),"%"]}),e.declaration.kind!=="inherited"&&y.jsx(k.Box,{className:"builder-affordance",role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e.label??e.name}`,onPointerDown:l,onPointerMove:u,onPointerUp:c,onPointerCancel:c,sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:1,opacity:i!==void 0||n?1:0,transition:"opacity 120ms","&:hover":{opacity:1},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:h.drillLink}}})]})})}function Og({tile:e}){const{theme:t}=Be.usePublisherTheme();return y.jsxs(j.TileCard,{sx:{minHeight:140},children:[y.jsx(j.TileHeading,{title:e.label??e.name,subtitle:e.subtitle}),y.jsxs(k.Typography,{variant:"caption",sx:{display:"block",color:t.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function Dg({after:e}){const{theme:t}=Be.usePublisherTheme();return y.jsx(kg,{id:Td(e),after:e,children:({ref:n,isDropTarget:r})=>y.jsx(k.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.drillLink}`,bgcolor:r?`color-mix(in srgb, ${t.drillLink} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:"opacity 120ms, background-color 120ms"}})})}function Tg({columns:e}){const{theme:t}=Be.usePublisherTheme();return y.jsx(k.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${j.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>y.jsx(k.Box,{sx:{borderLeft:`1px dashed ${t.drillLink}`,borderRight:r===e-1?`1px dashed ${t.drillLink}`:"none",opacity:.35}},r))})}var Cg=Object.defineProperty,Pg=Object.defineProperties,Mg=Object.getOwnPropertyDescriptors,Ka=Object.getOwnPropertySymbols,Ig=Object.prototype.hasOwnProperty,jg=Object.prototype.propertyIsEnumerable,Ya=(e,t,n)=>t in e?Cg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Ig.call(t,n)&&Ya(e,n,t[n]);if(Ka)for(var n of Ka(t))jg.call(t,n)&&Ya(e,n,t[n]);return e},on=(e,t)=>Pg(e,Mg(t));function Ag(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Yr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function cs(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Rg(e,t,n){var r,i;const{source:s,target:o,canceled:a}=t.operation;if(!s||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(p,b)=>p===b||p!==null&&typeof p=="object"&&"id"in p&&p.id===b;if(Array.isArray(e)){const p=e.findIndex(_=>l(_,s.id)),b=e.findIndex(_=>l(_,o.id));if(p===-1||b===-1){if(cs(s)){const _=s.initialIndex,$=s.index;return _===$||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,$)}return e}if(!a&&"index"in s&&typeof s.index=="number"){const _=s.index;if(_!==p)return n(e,p,_)}return n(e,p,b)}const u=Object.entries(e);let c=-1,d,h=-1,f;for(const[p,b]of u)if(c===-1&&(c=b.findIndex(_=>l(_,s.id)),c!==-1&&(d=p)),h===-1&&(h=b.findIndex(_=>l(_,o.id)),h!==-1&&(f=p)),c!==-1&&h!==-1)break;if(c===-1&&cs(s)){const p=s.initialGroup==null?void 0:Yr(e,s.initialGroup),b=s.initialIndex,_=s.group==null?void 0:Yr(e,s.group),$=s.index;if(p==null||_==null||p===_&&b===$)return"preventDefault"in t&&t.preventDefault(),e;if(p===_)return on(sn({},e),{[p]:n(e[p],b,$)});const O=e[p][b];return on(sn({},e),{[p]:[...e[p].slice(0,b),...e[p].slice(b+1)],[_]:[...e[_].slice(0,$),O,...e[_].slice($)]})}if(!s.manager)return e;const{dragOperation:g}=s.manager,v=(i=(r=g.shape)==null?void 0:r.current.center)!=null?i:g.position.current;if(f==null){const p=Yr(e,o.id);if(p!=null){const b=o.shape&&v.y>o.shape.center.y?e[p].length:0;f=p,h=b}}if(d==null||f==null||d===f&&c===h){if(d!=null&&d===f&&c===h&&cs(s)){const p=s.group==null?void 0:Yr(e,s.group),b=s.group!=null&&p!==d,_=s.index!==c;if(b||_){const $=s.group==null?d:p;if($!=null){if(d===$)return on(sn({},e),{[d]:n(e[d],c,s.index)});const O=e[d][c];return on(sn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[$]:[...e[$].slice(0,s.index),O,...e[$].slice(s.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===f)return on(sn({},e),{[d]:n(e[d],c,h)});const x=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,m=e[d][c];return on(sn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[f]:[...e[f].slice(0,h+x),m,...e[f].slice(h+x)]})}function Lg(e,t){return Rg(e,t,Ag)}function Wg({tiles:e,commit:t,onLanded:n}){const[r,i]=S.useState(void 0),s=S.useRef(void 0),[o,a]=S.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),s.current=e},onDragOver:d=>{const{source:h,target:f}=d.operation;if(!h||!f)return;const g=s.current??e;let v;if(f.type===Fd){const{after:w}=f.data,x=g.findIndex(b=>pt(b)===h.id);if(x<0||w===h.id)return;const p=g.filter((b,_)=>_!==x).findIndex(b=>pt(b)===w)+1;v=Np(g,x,p)}else{const w=g.map(pt),x=Lg(w,d);if(x.every((p,b)=>p===w[b]))return;const m=new Map(g.map(p=>[pt(p),p]));v=Fp(x.map(p=>m.get(p)),e.map(p=>p.break??!1))}s.current=v,i(v)},onDragEnd:d=>{a(!1);const h=s.current;if(s.current=void 0,i(void 0),d.canceled||!h)return;t(h);const f=h.findIndex(g=>pt(g)===d.operation.source?.id);f>=0&&n(f)}}}const Xa=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function zg({tiles:e,columns:t,onStart:n,commit:r}){const[i,s]=S.useState(void 0),o=S.useRef(null);return{resize:i,gridBox:o,startResize:(c,d)=>{const h=o.current?.getBoundingClientRect(),f=c.currentTarget.parentElement?.getBoundingClientRect();!h||!f||(c.stopPropagation(),c.preventDefault(),c.currentTarget.setPointerCapture(c.pointerId),Xa(!0),n(d),s({index:d,span:e[d]?.colspan??1,left:f.left,track:(h.width-j.GRID_GAP_PX*(t-1))/t}))},onResize:c=>{if(!i)return;const d=c.clientX-i.left,h=Math.round((d+j.GRID_GAP_PX)/(i.track+j.GRID_GAP_PX)),f=Math.min(Math.max(h,1),t);f!==i.span&&s({...i,span:f})},endResize:c=>{if(c.currentTarget.hasPointerCapture(c.pointerId)&&c.currentTarget.releasePointerCapture(c.pointerId),Xa(!1),!i)return;const{index:d,span:h}=i;s(void 0),r(d,h)}}}function Fg({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:i,columns:s,onDrills:o}){const{theme:a}=Be.usePublisherTheme(),{draft:l,patch:u,close:c,discard:d}=Od(t,e!==null,r,n),h=l!==void 0&&l.declaration.kind!=="inherited";return y.jsx(k.Popover,{open:e!==null&&l!==void 0,anchorEl:e,onClose:c,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:l&&y.jsxs(k.Stack,{sx:{gap:1.5},children:[y.jsxs(k.Typography,{variant:"overline",sx:{color:a.tileTitle,lineHeight:1.5},children:[l.source," → ",l.name]}),h?y.jsxs(y.Fragment,{children:[y.jsx(k.TextField,{size:"small",label:"Title",value:l.label??"",autoFocus:!0,inputProps:{"aria-label":"Tile title"},onChange:f=>u(g=>{const v=f.target.value;v===""?delete g.label:g.label=v})}),y.jsx(k.TextField,{size:"small",label:"Subtitle",value:l.subtitle??"",inputProps:{"aria-label":"Tile subtitle"},onChange:f=>u(g=>{const v=f.target.value;v===""?delete g.subtitle:g.subtitle=v})}),y.jsxs(k.Stack,{direction:"row",sx:{gap:.5,alignItems:"center"},children:[y.jsx(k.Typography,{variant:"caption",sx:{color:a.tileTitle,mr:.5},children:"Width"}),[["Full",1],["½",2],["⅓",3],["¼",4]].map(([f,g])=>{const v=Math.max(1,Math.round(s/g)),w=(l.colspan??1)===v;return y.jsx(k.Button,{size:"small",variant:w?"contained":"outlined","aria-label":`Width ${f}`,"aria-pressed":w,onClick:()=>u(x=>{x.colspan=v}),sx:{minWidth:40,px:1},children:f},f)})]})]}):y.jsx(k.Typography,{variant:"body2",sx:{color:a.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),l?.declaration.kind==="opaque"&&y.jsxs(k.Typography,{variant:"body2",sx:{color:a.tileTitle},children:["Its body is ",l.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),y.jsx(k.Divider,{}),y.jsxs(k.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[h?y.jsx(k.Button,{size:"small",onClick:()=>{c(),o()},children:"Clickable cells…"}):y.jsx("span",{}),y.jsx(k.Button,{color:"error",size:"small",onClick:()=>{d(),i()},children:"Remove tile"})]})]})})}const Nd=e=>e.ok===!1,me=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Bi=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ce={sourceDefinition:e=>me(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>me(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>me(e,"VIEW","subQueryDefList"),defDimension:e=>me(e,"defList","DIMENSION"),exploreProperties:e=>me(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>me(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>me(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>me(e,"WHERE","filterClauseList"),givenDef:e=>me(e,"givenNameDef"),givenStatement:e=>me(e,"GIVEN","givenDefList"),importStatement:e=>me(e,"IMPORT","importURL"),vArrow:e=>me(e,"ARROW","vExpr","segExpr"),segRefine:e=>me(e,"PLUS","segExpr"),segOps:e=>me(e,"queryProperties"),segField:e=>me(e,"fieldPath")&&!me(e,"segExpr"),segParen:e=>me(e,"OPAREN","CPAREN","vExpr"),compare:e=>me(e,"fieldExpr","compareOp"),givenRef:e=>me(e,"GIVEN_REF")};function Ng(e){const t=new Int32Array([...e].length+1);let n=0;for(let r=0;r<e.length;)t[n++]=r,r+=e.codePointAt(r)>65535?2:1;return t[n]=e.length,t}function Bg(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
70
+ `&&t.push(n+1);return t}class Vg{constructor(t){this.text=t,this.map=Ng(t),this.lineStarts=Bg(t)}map;lineStarts;commentLines=new Set;span(t){if(!Bi(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const i=this.map[n.startIndex],s=this.map[r.stopIndex+1];if(!(i===void 0||s===void 0||s<i))return{start:i,end:s}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],i=this.map[n.stopIndex+1];if(!(r===void 0||i===void 0||i<r))return{start:r,end:i}}utf16(t){return this.map[t]}text_(t){const n=this.span(t);return n&&this.text.slice(n.start,n.end)}line(t){let n=0,r=this.lineStarts.length-1;for(;n<r;){const i=n+r+1>>1;this.lineStarts[i]<=t?n=i:r=i-1}return n}positioned(t){const n=this.span(t);return n&&{span:n,line:this.line(n.start)}}indentAt(t){const n=this.lineStarts[this.line(t)];return/^[ \t]*/.exec(this.text.slice(n))?.[0]??""}}function jr(e,t,n=[]){Bi(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)jr(e.getChild(r),t,n);return n}const Gg=e=>me(e,"OCURLY","CCURLY");function Sr(e,t){const n=[],r=i=>{if(Bi(i)){if(t(i)){n.push(i);return}if(!Gg(i))for(let s=0;s<(i.childCount??0);s++)r(i.getChild(s))}};for(let i=0;i<(e.childCount??0);i++)r(e.getChild(i));return n}const ye=(e,t)=>e[t]?.call(e),Ut=(e,t)=>e[t]?.call(e)??[];function Ug(e,t){if(!ce.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!ce.givenRef(n))return;const r=e.text_(t.getChild(0)),i=e.text_(t.getChild(1)),s=e.text_(n)??"";if(!(r===void 0||i===void 0))return{field:r,op:i.trim(),given:s.replace(/^\$/,"")}}function Bd(e,t){const n=e.positioned(t);if(!n)return;const r=ye(t,"filterClauseList"),i=[];for(const s of r?Ut(r,"fieldExpr"):[]){const o=e.positioned(s);if(!o)continue;const a=jr(s,ce.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));i.push({...o,givens:a,binding:Ug(e,s)})}return{...n,clauses:i}}function Ys(e,t){const n=e.span(t);if(!n)return;const r=[],i=[];for(const u of Sr(t,ce.queryStatement)){const c=e.positioned(u);c&&r.push(c);const d=ye(u,"whereStatement");if(d&&ce.whereStatement(d)){const h=Bd(e,d);h&&i.push(h)}}const s=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
71
+ `),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:s,closeStart:o,statements:r,wheres:i,indent:l,oneLine:a}}function ta(e,t,n){const r=[],i=e.line(t.start),s=e.line(n);for(let o=i;o<s;o++){if(e.commentLines.has(o))continue;const a=e.text.slice(e.lineStarts[o],e.lineStarts[o+1]??e.text.length).trim();a.startsWith("#")&&!a.startsWith("##")&&r.push({line:o,text:a})}return r}function Hg(e,t){const n=ye(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ce.vArrow(t);if(ce.segOps(n)){const i=ye(n,"queryProperties"),s=i&&Ys(e,i);return s?{kind:"inline",stage:s,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ce.segField(n)){const i=e.span(n);return i?{kind:"reference",from:e.text.slice(i.start,i.end),fromSpan:i}:{kind:"unsupported",why:"an unreadable name"}}if(ce.segRefine(n)){const i=Ut(n,"segExpr"),s=i[0],o=i[i.length-1];let a=s;for(;ce.segRefine(a);){const h=Ut(a,"segExpr");if(h.some(f=>ce.segOps(f)||ce.segParen(f)))return{kind:"unsupported",why:"a chained refinement"};a=h[0]}if(!a||!ce.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const l=e.span(s);if(!l||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ce.segOps(o)){const h=e.span(n);return h?{kind:"reference",from:e.text.slice(h.start,h.end),fromSpan:h}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(l.start,l.end),c=ye(o,"queryProperties"),d=c&&Ys(e,c);return d?{kind:"reference",from:u,fromSpan:l,refinement:d}:{kind:"reference",from:u,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function qg(e,t){const n=[];for(const r of Sr(t,ce.defExploreQuery)){const i=e.span(r),s=ye(r,"subQueryDefList");if(!i||!s)continue;const o=Ut(s,"exploreQueryDef").filter(ce.exploreQueryDef),a=e.terminal(ye(r,"VIEW"));for(const l of o){const u=e.span(l),c=ye(l,"exploreQueryNameDef"),d=e.text_(c),h=ye(l,"vExpr");!u||!d||!h||n.push({name:d,span:u,line:e.line(u.start),statement:i,tags:ta(e,i,a?.start??u.start),siblings:o.length,body:Hg(e,h)})}}return n}function Kg(e,t){const n=[];for(const r of Sr(t,ce.defDimension)){const i=e.span(r),s=ye(r,"defList");if(!i||!s)continue;const o=e.terminal(ye(r,"DIMENSION"));for(const a of Ut(s,"fieldDef")){const l=e.span(a),u=e.text_(ye(a,"fieldNameDef"))?.trim(),c=e.text_(ye(a,"fieldExpr"))?.trim();!l||!u||c===void 0||n.push({name:u,expression:c,span:l,line:e.line(l.start),statement:i,tags:ta(e,i,o?.start??l.start)})}}return n}function Yg(e,t){const n=[];for(const r of jr(t,ce.sourceDefinition)){const i=e.span(r),s=e.text_(ye(r,"sourceNameDef")),o=ye(r,"sqExplore");if(!i||!s||!o)continue;const a=e.span(o),l=a?e.text.slice(a.start,a.end):"",u=(/^\s*(`[^`]*`|[A-Za-z_][A-Za-z0-9_.]*)/.exec(l)?.[1]??"").trim(),c=Sr(o,ce.exploreProperties)[0],d=c&&Ys(e,c),h={start:e.lineStarts[e.line(i.start)],end:i.end},f=[];if(c)for(const g of Sr(c,ce.whereStatement)){const v=Bd(e,g);v&&f.push(v)}n.push({name:s,base:u,span:i,line:e.line(i.start),statement:h,...d?{properties:d}:{},views:c?qg(e,c):[],dimensions:c?Kg(e,c):[],wheres:f})}return n}function Xg(e,t){const n=[];for(const r of jr(t,ce.givenStatement)){const i=e.terminal(ye(r,"GIVEN")),s=ye(r,"givenDefList"),o=i?e.line(i.start):void 0;for(const a of s?Ut(s,"givenDef"):[]){const l=e.span(a),u=e.span(ye(a,"givenNameDef")),c=u&&e.text.slice(u.start,u.end);if(!l||!u||!c)continue;const d={start:u.start,end:l.end},h=e.line(d.start);n.push({name:c,declaration:e.text.slice(d.start,d.end),span:d,line:h,statement:{start:e.lineStarts[h],end:d.end},tags:ta(e,l,d.start),...o!==void 0&&o!==h?{blockHeader:o}:{}})}}return n}function Qg(e,t){const n=[];for(const r of jr(t,ce.importStatement)){const i=e.span(r),s=e.text_(ye(r,"importURL"));if(!i||s===void 0)continue;const o=ye(r,"importSelect"),a=o?Ut(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:s.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:i,line:e.line(i.start),statement:i})}return n}async function Vd(e){let t;try{t=await Gd(e,"file://dashboard-builder.malloy")}catch(c){return{ok:!1,reason:`Malloy could not read this file: ${c}`}}const n=t.problems.filter(c=>c.code==="syntax-error");if(n.length>0)return{ok:!1,reason:`This file has a Malloy syntax error, so it cannot be edited here: ${n[0].message??"unknown"}`};const r=t.parse,i=r?.root;if(!i||!Bi(i)||typeof i.getChild!="function")return{ok:!1,reason:`This build of Malloy does not expose a parse tree the builder can read (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`};const s=r?.tokenStream??{},o=typeof s.getTokens=="function"?s.getTokens():void 0;if(!o||typeof s.tokenSource?.vocabulary?.getSymbolicName!="function"||o.length===0&&e.trim()!=="")return{ok:!1,reason:`This build of Malloy does not expose a token stream the builder can read (malloy ${r?.malloyVersion??"unknown"}), so it cannot tell a comment from code and editing is off.`};const a=new Vg(e),l=Zg(a,s);a.commentLines=l.lines;const u=Yg(a,i);return u.length===0&&/^\s*source:/m.test(e)?{ok:!1,reason:`The builder could not locate this file's sources in Malloy's parse tree (malloy ${r?.malloyVersion??"unknown"}), so editing is off.`}:{ok:!0,parsed:{text:e,lineStarts:a.lineStarts,imports:Qg(a,i),sources:u,givens:Xg(a,i),trailingComment:c=>l.trailing.get(c),comments:l.all,commentLine:c=>l.lines.has(c),commentIn:c=>l.all.find(d=>d.start>=c.start&&d.start<c.end),blockStart:c=>Jg(a,l.lines,c)}}}async function Gd(e,t){const{MalloyTranslator:n}=await import("@malloydata/malloy"),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function Zg(e,t){const n=new Map,r=new Set,i=[],s=t.tokenSource?.vocabulary;for(const c of t.getTokens?.()??[]){const d=s?.getSymbolicName(c.type);if(d!=="COMMENT_TO_EOL"&&d!=="BLOCK_COMMENT")continue;const h=e.utf16(c.startIndex);let f=e.utf16(c.stopIndex+1);if(!(h===void 0||f===void 0||f<h)){for(;f>h&&(e.text[f-1]===`
72
+ `||e.text[f-1]==="\r");)f--;i.push({start:h,end:f})}}const o=[...i].sort((c,d)=>c.start-d.start);let a="",l=0;for(const c of o)a+=e.text.slice(l,Math.max(l,c.start)),a+=e.text.slice(Math.max(l,c.start),Math.max(l,c.end)).replace(/[^\n\r]/g," "),l=Math.max(l,c.end);a+=e.text.slice(l);const u=c=>a.slice(e.lineStarts[c],e.lineStarts[c+1]??a.length);for(const c of i){const d=e.line(c.start),h=e.line(c.end-1);for(let v=d;v<=h;v++)u(v).trim()===""&&r.add(v);const f=a.slice(e.lineStarts[d],c.start).trim(),g=a.slice(c.end,e.lineStarts[h+1]??a.length).trim();f!==""&&g===""&&n.set(h,c)}return{trailing:n,lines:r,all:i}}function Jg(e,t,n){let r=n;for(let i=n-1;i>=0;i--){const s=e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();if(s===""&&!t.has(i))break;if(s.startsWith("#")||t.has(i))r=i;else break}return r}const Oi=e=>e.ok===!1;function Ar(e,t,n){const r=e.blockStart(n),i=[];for(let s=r;s<n;s++){if(e.commentLine(s))continue;const o=t[s].trim();o.startsWith("#")&&!o.startsWith("##")&&i.push({line:s,text:o})}return{start:r,tags:i}}const Xs=e=>e.map(t=>t.text);function ev(e){const t=[],n=[];for(const r of e){const i=r.trim();if(i.startsWith('##"'))t.push(i.slice(3).trim());else{if(i.startsWith("##!"))continue;i.startsWith("##")&&n.push(i)}}return{description:t.length>0?t.join(`
73
+ `):void 0,artifact:n}}function tv(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:i,op:s,given:o}=r.binding;t.push({field:i,given:o,...s==="~"?{}:{op:s}})}return t.length>0?t:void 0}function nv(e,t,n){const r=[];for(const i of e.givens){const s=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(i.declaration);s&&r.push({name:s[1],type:s[2],default:s[3].trim(),...rv(n(Xs(Ar(e,t,i.line).tags)).tag)})}return r.length>0?r:void 0}function rv(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),i=e.numeric("range_max");return{...e.text("label")===void 0?{}:{label:e.text("label")},...e.text("description")===void 0?{}:{description:e.text("description")},...e.text("control")===void 0?{}:{control:e.text("control")},...t&&n?{suggest:{...t.text("source")===void 0?{}:{source:t.text("source")},...t.text("query")===void 0?{}:{query:t.text("query")},dimension:n}}:{},...r===void 0?{}:{rangeMin:r},...i===void 0?{}:{rangeMax:i}}}function iv(e){const t=e.search(/tiles\s*=\s*\[/);if(t<0)return[];const n=e.indexOf("[",t),r=e.indexOf("]",n);return r<0?[]:[...e.slice(n+1,r).matchAll(/"([^"]+)"/g)].map(s=>s[1])}async function Di(e){const{parseAnnotation:t}=await import("@malloydata/malloy-tag"),n=e.split(`
74
+ `),r=await Vd(e);if(Nd(r))return{ok:!1,reason:r.reason,...r.line?{line:r.line}:{}};const i=r.parsed,{description:s,artifact:o}=ev(n),a=o.find(b=>b.includes("artifact"));if(a===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a composite dashboard."};const l=t([a.replace(/^##\s*/,"# ")]).tag,u=l?.tag("artifact"),c=iv(a);if(c.length===0)return{ok:!1,reason:"The `## artifact` tag names no tiles, so there is nothing to lay out."};const d=i.imports.map(b=>b.names?{kind:"names",names:b.names,from:b.from}:{kind:"all",from:b.from}),h=[],f=[],g=new Map;for(const b of i.sources){const _={name:b.name,base:b.base};b.dimensions.length>0&&(_.dimensions=b.dimensions.map($=>({name:$.name,expression:$.expression}))),h.push(_);for(const $ of b.dimensions){const O=t(Xs(Ar(i,n,$.line).tags)).tag?.tag("drill");if(!O)continue;const D=O.textArray("to")??[O.text("to")??""];f.push({source:b.name,name:$.name,expression:$.expression,to:D.filter(Boolean),...O.text("given")?{given:O.text("given")}:{}})}g.set(b.name,new Map(b.views.map($=>[$.name,$])))}const v=[];for(const b of c){const _=j.tileSteps(b);if(!_)return{ok:!1,reason:`The tile \`${b}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:$,view:O}=_,D=g.get($)?.get(O);if(D===void 0){v.push({name:O,source:$,declaration:{kind:"inherited"}});continue}const M=t(Xs(D.tags)).tag,I=D.body.kind==="reference"?{kind:"reference",from:D.body.from}:D.body.kind==="inline"?{kind:"inline"}:void 0;if(I===void 0){v.push({name:O,source:$,declaration:{kind:"opaque",why:D.body.kind==="unsupported"?D.body.why:"unreadable"},...M?.text("label")?{label:M.text("label")}:{},...M?.text("subtitle")?{subtitle:M.text("subtitle")}:{},...M?.numeric("colspan")!==void 0?{colspan:M.numeric("colspan")}:{},...M?.has("break")?{break:!0}:{},...M?.has("borderless")?{borderless:!0}:{}});continue}const K=tv(D.body.kind==="reference"?D.body.refinement:D.body.kind==="inline"?D.body.stage:void 0);v.push({name:O,source:$,declaration:I,...K?{filters:K}:{},...M?.text("label")?{label:M.text("label")}:{},...M?.text("subtitle")?{subtitle:M.text("subtitle")}:{},...M?.numeric("colspan")!==void 0?{colspan:M.numeric("colspan")}:{},...M?.has("break")?{break:!0}:{},...M?.has("borderless")?{borderless:!0}:{}})}const w=nv(i,n,t),x={},m=u?.tag("givens");for(const b of Object.keys(m?.dict??{})){const _=m?.text(b);_!==void 0&&(x[b]=_)}const p=l?.tag("dashboard")?.numeric("columns");return{ok:!0,document:{title:u?.text("title")??"",...s?{description:s}:{},...p===void 0?{}:{columns:p},...u?.has("autorun")?{autorun:u.isTrue("autorun")}:{},imports:d,sources:h,...w?{localGivens:w}:{},...Object.keys(x).length>0?{startingGivens:x}:{},...f.length>0?{drills:f}:{},tiles:v}}}async function Qa(e){const{problems:t}=await Gd(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}const Qs=e=>e.ok===!1;function be(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const i of Object.keys(n).sort())r[i]=t(n[i]);return r}return n};return JSON.stringify(t(e))}function sv(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
75
+ `&&t.push(n+1);return t}function ov(e,t){let n=e;for(const r of[...t].sort((i,s)=>s.start-i.start||s.end-i.end))n=n.slice(0,r.start)+r.text+n.slice(r.end);return n}function Ud(e){const t=[];return e.colspan!==void 0&&t.push(`# colspan=${e.colspan}`),e.break&&t.push("# break"),e.borderless&&t.push("# borderless"),e.label!==void 0&&t.push(`# label=${$n(e.label)}`),e.subtitle!==void 0&&t.push(`# subtitle=${$n(e.subtitle)}`),t}function li(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const av=new Set(["colspan","break","borderless","label","subtitle"]),lv=new Set(["label","description","control","suggest","range_min","range_max"]),cv=(e,t)=>be(e.imports)===be(t.imports);function Za(e){const t=[];if(e.label!==void 0&&t.push(`label=${$n(e.label)}`),e.description!==void 0&&t.push(`description=${$n(e.description)}`),e.control!==void 0&&t.push(`control=${e.control}`),e.suggest){const n=e.suggest.source!==void 0?`source=${e.suggest.source}`:e.suggest.query!==void 0?`query=${e.suggest.query}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${e.suggest.dimension} }`)}return e.rangeMin!==void 0&&t.push(`range_min=${e.rangeMin}`),e.rangeMax!==void 0&&t.push(`range_max=${e.rangeMax}`),t.length>0?`# ${t.join(" ")}`:void 0}const Ja=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function dv(e,t,n){const r=e.sources.find(i=>i.name===t)?.views.find(i=>i.name===n);return r?r.line:-1}function el(e){return`# drill { to=${e.to.length===1?e.to[0]:`[${e.to.map(n=>`"${n}"`).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ti=e=>`${e.source}.${e.name}`,$n=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,Zs=e=>be([e.name,e.source,e.declaration]),gt=Zs,tl=e=>be(e.tiles.map(gt));function uv(e,t){const n=new Set(e.tiles.map(gt)),r=new Set(t.tiles.map(gt)),i=e.tiles.filter(d=>!r.has(gt(d))),s=t.tiles.filter(d=>!n.has(gt(d))),a=i.length>0||s.length>0||tl(e)!==tl(t);for(const d of s)if(d.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${d.name}\` is ${d.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const l=new Map(e.sources.map(d=>[d.name,d])),u=new Set(e.imports.flatMap(d=>d.kind==="names"?d.names:[]));for(const d of e.sources)u.add(d.base);const c=t.sources.filter(d=>!l.has(d.name));for(const d of e.sources){const h=t.sources.find(f=>f.name===d.name);if(!h||h.base!==d.base)return{ok:!1,reason:`The source \`${d.name}\` cannot be changed or removed here.`}}for(const d of c){if(!s.some(h=>h.source===d.name))return{ok:!1,reason:`A new source \`${d.name}\` needs a tile on it.`};if(!u.has(d.base))return{ok:!1,reason:`\`${d.base}\` is not imported by name in this file, so a tile cannot be put on it. The builder does not add imports: import { ${d.base} } from the model first.`}}return cv(e,t)?{currentKeys:n,nextKeys:r,removedTiles:i,addedTiles:s,newSources:c,currentSources:l,reordered:a}:{ok:!1,reason:"The dashboard's imports cannot be changed here."}}function fv(e){const{lines:t,wholeLine:n,next:r,reordered:i,currentKeys:s,nextKeys:o,edits:a}=e;if(i){const l=j.artifactLine(t);if(l<0)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const u=[...t[l].matchAll(/"([^"]+)"/g)].map(g=>g[1]),c=new Map;for(const g of u){const v=g.split("->").map(w=>w.trim());v.length===2&&c.set(`${v[0]}->${v[1]}`,g)}const d=r.tiles.map(g=>c.get(`${g.source}->${g.name}`)??(o.has(gt(g))&&!s.has(gt(g))?`${g.source} -> ${g.name}`:void 0));if(d.some(g=>g===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const h=`tiles=[${d.map(g=>`"${g}"`).join(", ")}]`,f=t[l].replace(/tiles\s*=\s*\[[\s\S]*?\]/,h);f!==t[l]&&a.push({...n(l),text:`${f}
76
+ `})}}function hv(e){const{lines:t,wholeLine:n,current:r,next:i,edits:s}=e;if(r.title!==i.title||r.autorun!==i.autorun||r.columns!==i.columns||be(r.startingGivens)!==be(i.startingGivens)){const o=j.artifactLine(t);if(o<0)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=s.find(v=>v.start===n(o).start&&v.end===n(o).end);let l=a?a.text.replace(/\n$/,""):t[o];const u=l.indexOf("artifact"),c=l.indexOf("{",u);let d=0,h=-1;for(let v=c;v<l.length;v++)if(l[v]==="{")d++;else if(l[v]==="}"&&--d===0){h=v;break}if(c<0||h<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let f=l.slice(c+1,h);const g=(v,w)=>{const x=new RegExp(`\\s*\\b${v}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);w===void 0?f=f.replace(x,""):x.test(f)?f=f.replace(x,` ${v}=${w}`):f=`${f.replace(/\s+$/,"")} ${v}=${w} `};if(r.title!==i.title&&g("title",i.title?$n(i.title):void 0),r.autorun!==i.autorun&&g("autorun",i.autorun===void 0?void 0:String(i.autorun)),be(r.startingGivens)!==be(i.startingGivens)){f=f.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const v=Object.entries(i.startingGivens??{});v.length>0&&(f=`${f.replace(/\s+$/,"")} givens { ${v.map(([w,x])=>`${w}=${$n(x)}`).join(" ")} }`)}f=f.replace(/\s{2,}/g," "),l=`${l.slice(0,c+1)}${f.startsWith(" ")?f:` ${f}`}${f.endsWith(" ")?"":" "}${l.slice(h)}`,r.columns!==i.columns&&(l=l.replace(/\s*dashboard\s*\{[^}]*\}/,""),i.columns!==void 0&&(l=`${l.trimEnd()} dashboard { columns=${i.columns} }`)),a?a.text=`${l}
74
77
  `:s.push({...n(o),text:`${l}
75
- `})}if(r.description!==i.description){const o=t.map((l,d)=>l.trim().startsWith('##"')?d:-1).filter(l=>l>=0),a=(i.description??"").split(`
78
+ `})}if(r.description!==i.description){const o=t.map((l,u)=>l.trim().startsWith('##"')?u:-1).filter(l=>l>=0),a=(i.description??"").split(`
76
79
  `).map(l=>l.trim()===""?'##"':`##" ${l.trim()}`).join(`
77
- `);if(o.length>0){const l=o[0],d=o[o.length-1];s.push({start:n(l).start,end:n(d).end,text:i.description===void 0?"":`${a}
78
- `})}else if(i.description!==void 0){const l=j.artifactLine(t),d=n(l).start;s.push({start:d,end:d,text:`${a}
79
- `})}}}function Lg(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o}=e,a=new Map((i.localGivens??[]).map(h=>[h.name,h])),l=new Map((s.localGivens??[]).map(h=>[h.name,h])),d=j.givenDeclarations(t),u=new Set;for(const[h,f]of a){const g=l.get(h);if(g!==void 0&&me(g)===me(f))continue;const m=d.get(h);if(m===void 0)return{ok:!1,reason:`Could not find where the given \`${h}\` is declared.`};const{tags:w}=Nt(t,m.line),b=g===void 0?w:w.filter(O=>{const T=ni(O.text);return T!==void 0&&Cg.has(T)});for(const O of b)o.push({...n(O.line),text:""}),u.add(O.line);if(g===void 0){o.push({...n(m.line),text:""}),u.add(m.line);const O=Math.min(m.line,...w.map(L=>L.line)),T=m.blockHeader??O,E=(t[m.line+1]??"x").trim()==="",I=T===0||t[T-1].trim()==="",D=m.blockHeader===void 0||![...d.values()].some(L=>L.blockHeader===m.blockHeader&&L.line>m.line&&l.has([...d.entries()].find(([,M])=>M===L)?.[0]??""));E&&I&&D&&!u.has(m.line+1)&&(o.push({...n(m.line+1),text:""}),u.add(m.line+1));continue}const v=r(m.line),p=Fa(g),_=g.type!==f.type||g.default!==f.default?m.blockHeader===void 0?Ba(g):`${g.name} :: ${g.type} is ${g.default}`:t[m.line].trim();o.push({...n(m.line),text:(p?`${v}${p}
80
- `:"")+`${v}${_}
81
- `})}for(const[h,f]of d){if(f.blockHeader===void 0||l.has(h))continue;![...d.values()].some(m=>m.blockHeader===f.blockHeader&&!u.has(m.line))&&!u.has(f.blockHeader)&&(o.push({...n(f.blockHeader),text:""}),u.add(f.blockHeader))}const c=[...l.values()].filter(h=>!a.has(h.name));if(c.length>0){const h=Math.max(-1,...[...d.values()].map(v=>v.line)),f=(()=>{let v=-1;for(let p=0;p<t.length;p++){const x=t[p].trim();(x.startsWith("import ")||v>=0&&/^}\s*from\s/.test(x))&&(v=p)}return v})(),g=h>=0?h:f,m=c.map(v=>{const p=Fa(v);return(p?`${p}
82
- `:"")+`${Ba(v)}
80
+ `);if(o.length>0){const l=o[0],u=o[o.length-1];s.push({start:n(l).start,end:n(u).end,text:i.description===void 0?"":`${a}
81
+ `})}else if(i.description!==void 0){const l=j.artifactLine(t),u=n(l).start;s.push({start:u,end:u,text:`${a}
82
+ `})}}}function pv(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,l=new Map((i.localGivens??[]).map(f=>[f.name,f])),u=new Map((s.localGivens??[]).map(f=>[f.name,f])),c=new Map(a.givens.map(f=>[f.name,f])),d=new Set;for(const[f,g]of l){const v=u.get(f);if(v!==void 0&&be(v)===be(g))continue;const w=c.get(f);if(w===void 0)return{ok:!1,reason:`Could not find where the given \`${f}\` is declared.`};const{tags:x}=Ar(a,t,w.line),m=v===void 0?x:x.filter(D=>{const M=li(D.text);return M!==void 0&&lv.has(M)});for(const D of m)o.push({...n(D.line),text:""}),d.add(D.line);const p=Ht(a,w.span.end-1);if(v===void 0){o.push({start:n(w.line).start,end:n(p).end,text:""});for(let C=w.line;C<=p;C++)d.add(C);const D=Math.min(w.line,...x.map(C=>C.line)),M=w.blockHeader??D,I=(t[p+1]??"x").trim()==="",K=M===0||t[M-1].trim()==="",z=w.blockHeader===void 0||![...c.values()].some(C=>C.blockHeader===w.blockHeader&&C.line>w.line&&u.has([...c.entries()].find(([,W])=>W===C)?.[0]??""));I&&K&&z&&!d.has(p+1)&&(o.push({...n(p+1),text:""}),d.add(p+1));continue}const b=r(w.line),_=Za(v),O=v.type!==g.type||v.default!==g.default?w.blockHeader===void 0?Ja(v):`${v.name} :: ${v.type} is ${v.default}`:t.slice(w.line,p+1).join(`
83
+ `).trim();o.push({start:n(w.line).start,end:n(p).end,text:(_?`${b}${_}
84
+ `:"")+`${b}${O}
85
+ `})}for(const[f,g]of c){if(g.blockHeader===void 0||u.has(f))continue;![...c.values()].some(w=>w.blockHeader===g.blockHeader&&!d.has(w.line))&&!d.has(g.blockHeader)&&(o.push({...n(g.blockHeader),text:""}),d.add(g.blockHeader))}const h=[...u.values()].filter(f=>!l.has(f.name));if(h.length>0){const f=Math.max(-1,...[...c.values()].map(p=>p.line)),g=(()=>{let p=-1;for(let b=0;b<t.length;b++){const _=t[b].trim();(_.startsWith("import ")||p>=0&&/^}\s*from\s/.test(_))&&(p=b)}return p})(),v=f>=0?f:g,w=h.map(p=>{const b=Za(p);return(b?`${b}
86
+ `:"")+`${Ja(p)}
83
87
  `}).join(`
84
- `),w=g>=0?n(g).end:n(0).end;o.push({start:w,end:w,text:`
85
- ${m}`}),t.some(v=>v.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
86
- `})}}function zg(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o}=e,a=new Map((i.drills??[]).map(d=>[ki(d),d])),l=new Map((s.drills??[]).map(d=>[ki(d),d]));for(const d of new Set([...a.keys(),...l.keys()])){const u=a.get(d),c=l.get(d);if(u&&c&&me(u)===me(c))continue;const h=c??u;if(c&&c.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const f=j.declarationsUnder(t,h.source,"dimension").get(h.name);if(f===void 0)return{ok:!1,reason:`\`${h.name}\` is not a dimension \`${h.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:g}=Nt(t,f.line),m=g.find(b=>/^#\s*drill\b/.test(b.text)),w=r(f.line);if(c===void 0)m&&o.push({...n(m.line),text:""});else if(m)o.push({...n(m.line),text:`${w}${Ga(c)}
87
- `});else{const b=n(f.line).start;o.push({start:b,end:b,text:`${w}${Ga(c)}
88
- `})}}}function Wg(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i}=e;for(const s of r){if(s.declaration.kind==="inherited")continue;const o=j.declarationLine(t,"view",s.name);if(o<0)return{ok:!1,reason:`Could not find where \`${s.name}\` is declared.`};const a=wi(t,o),{tags:l}=Nt(t,o),d=Math.min(o,...l.map(c=>c.line));for(const c of l)i.push({...n(c.line),text:""});i.push({start:n(o).start,end:n(a).end,text:""});const u=d===0?"":t[d-1].trim();(t[a+1]??"x").trim()===""&&(d===0||u===""||u.endsWith("{"))&&i.push({...n(a+1),text:""})}}function Fg(e){const{sourceText:t,lines:n,wholeLine:r,current:i,addedTiles:s,newSources:o,currentSources:a,edits:l}=e,d=new Map;for(const h of s){const f=d.get(h.source)??[];f.push(h),d.set(h.source,f)}const u=(h,f)=>{const g=h.declaration.kind==="reference"?h.declaration.from:h.name,m=(h.filters??[]).map(w=>`where: ${w.field} ${w.op??"~"} $${w.given}`).join(", ");return[...Pd(h).map(w=>`${f}${w}`),`${f}view: ${h.name} is ${g}${m?` + { ${m} }`:""}`].join(`
89
- `)};let c=-1;for(const h of i.sources){const f=j.declarationLine(n,"source",h.name);f>=0&&(c=Math.max(c,wi(n,f)))}for(const[h,f]of d)if(a.has(h)){const g=j.declarationLine(n,"source",h);if(g<0)return{ok:!1,reason:`Could not find where the source \`${h}\` is declared.`};const m=wi(n,g);let w=" ";for(let p=g+1;p<m;p++){const x=/^(\s+)view:/.exec(n[p]);if(x){w=x[1];break}}const b=r(m).start,v=(n[m-1]??"").trim()==="";l.push({start:b,end:b,text:(v?"":`
90
- `)+f.map(p=>u(p,w)).join(`
88
+ `),x=v>=0?n(v).end:n(0).end;o.push({start:x,end:x,text:`
89
+ ${w}`}),t.some(p=>p.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
90
+ `})}}function gv(e){const{lines:t,wholeLine:n,indentOf:r,current:i,next:s,edits:o,parsed:a}=e,l=new Map((i.drills??[]).map(c=>[Ti(c),c])),u=new Map((s.drills??[]).map(c=>[Ti(c),c]));for(const c of new Set([...l.keys(),...u.keys()])){const d=l.get(c),h=u.get(c);if(d&&h&&be(d)===be(h))continue;const f=h??d;if(h&&h.to.length===0)return{ok:!1,reason:`The drill on \`${c}\` names no destination.`};const g=a.sources.find(m=>m.name===f.source)?.dimensions.find(m=>m.name===f.name);if(g===void 0)return{ok:!1,reason:`\`${f.name}\` is not a dimension \`${f.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:v}=Ar(a,t,g.line),w=v.find(m=>/^#\s*drill\b/.test(m.text)),x=r(g.line);if(h===void 0)w&&o.push({...n(w.line),text:""});else if(w)o.push({...n(w.line),text:`${x}${el(h)}
91
+ `});else{const m=n(g.line).start;o.push({start:m,end:m,text:`${x}${el(h)}
92
+ `})}}}function vv(e){const{lines:t,wholeLine:n,removedTiles:r,edits:i,parsed:s}=e;for(const o of r){if(o.declaration.kind==="inherited")continue;const a=Hd(e,o);if(!a)return{ok:!1,reason:`Could not find where \`${o.name}\` is declared.`};if(a.siblings>1)return{ok:!1,reason:`\`${o.name}\` is one of several views declared by a single \`view:\` statement, which the builder does not restructure.`};const l=Ht(s,a.statement.start),u=Ht(s,a.statement.end-1),c=s.trailingComment(u),d=c&&c.start>=a.statement.end?c.end:a.statement.end;if(s.text.slice(s.lineStarts[l],a.statement.start).trim()!==""||s.text.slice(d,n(u).end).trim()!==""){i.push({...Yd(s,a.statement),text:""});continue}i.push({start:s.lineStarts[l],end:n(u).end,text:""});const f=l===0?"":t[l-1].trim();(t[u+1]??"x").trim()===""&&(l===0||f===""||f.endsWith("{"))&&i.push({...n(u+1),text:""})}}function mv(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:i,newSources:s,currentSources:o,edits:a,parsed:l}=e,u=new Map;for(const h of i){const f=u.get(h.source)??[];f.push(h),u.set(h.source,f)}const c=(h,f)=>{const g=h.declaration.kind==="reference"?h.declaration.from:h.name,v=(h.filters??[]).map(w=>`where: ${w.field} ${w.op??"~"} $${w.given}`).join(", ");return[...Ud(h).map(w=>`${f}${w}`),`${f}view: ${h.name} is ${g}${v?` + { ${v} }`:""}`].join(`
93
+ `)};let d=-1;for(const h of l.sources)d=Math.max(d,Ht(l,h.span.end-1));for(const[h,f]of u)if(o.has(h)){const g=l.sources.find(b=>b.name===h);if(!g)return{ok:!1,reason:`Could not find where the source \`${h}\` is declared.`};if(!g.properties)return{ok:!1,reason:`\`${h}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const v=g.line,w=Ht(l,g.properties.closeStart);let x=" ";for(let b=v+1;b<w;b++){const _=/^(\s+)view:/.exec(n[b]);if(_){x=_[1];break}}const m=r(w).start,p=(n[w-1]??"").trim()==="";a.push({start:m,end:m,text:(p?"":`
94
+ `)+f.map(b=>c(b,x)).join(`
91
95
 
92
96
  `)+`
93
- `})}else{const g=o.find(p=>p.name===h);if(!g)return{ok:!1,reason:`The tile's source \`${h}\` is not declared.`};const m=`
97
+ `})}else{const g=s.find(p=>p.name===h);if(!g)return{ok:!1,reason:`The tile's source \`${h}\` is not declared.`};const v=`
94
98
  source: ${g.name} is ${g.base} extend {
95
- `+f.map(p=>u(p," ")).join(`
99
+ `+f.map(p=>c(p," ")).join(`
96
100
 
97
101
  `)+`
98
102
  }
99
- `;let w=c;if(w<0)for(let p=0;p<n.length;p++){const x=n[p].trim();(/^(import\s|given:|}\s*from\s)/.test(x)||/^[A-Z_]+\s*::/.test(x))&&(w=p)}const b=w>=0?r(w).end:t.length,v=b===t.length&&!t.endsWith(`
103
+ `;let w=d;if(w<0)for(let p=0;p<n.length;p++){const b=n[p].trim();(/^(import\s|given:|}\s*from\s)/.test(b)||/^[A-Z_]+\s*::/.test(b))&&(w=p)}const x=w>=0?r(w).end:t.length,m=x===t.length&&!t.endsWith(`
100
104
  `)?`
101
- `:"";l.push({start:b,end:b,text:v+m}),c=w}}function Bg(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:s,next:o,edits:a}=e,l=new Map(s.tiles.map(d=>[pt(d),d]));for(const d of o.tiles){const u=l.get(pt(d));if(u===void 0||me(u)===me(d))continue;if(d.declaration.kind==="inherited")return{ok:!1,reason:`\`${d.source} -> ${d.name}\` is declared on its source, not in this dashboard, so its presentation cannot be changed here.`};const c=Ig(t,d.source,d.name);if(c<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:h}=Nt(t,c),f=i(c),g=Pd(d),m=new Map(g.map(E=>[ni(E)??E,E])),w=new Set;for(const E of h){const I=ni(E.text);if(I===void 0||!Pg.has(I))continue;const D=m.get(I);if(D===void 0){a.push({...r(E.line),text:""});continue}w.add(I),D!==E.text&&a.push({...r(E.line),text:`${f}${D}
102
- `})}const b=g.filter(E=>!w.has(ni(E)??E));if(b.length>0){const E=n[c];a.push({start:E,end:E,text:b.map(I=>`${f}${I}
103
- `).join("")})}const p=(/\+\s*\{([\s\S]*)\}\s*$/.exec(t[c])?.[1]??"").replace(Dd,"").replace(/\s*,\s*,\s*/g,", ").replace(/^[\s,;]+|[\s,;]+$/g,""),x=(d.filters??[]).map(E=>`where: ${E.field} ${E.op??"~"} $${E.given}`),_=[...p?[p]:[],...x],O=t[c].replace(/\s*\+\s*\{[\s\S]*\}\s*$/,""),T=_.length===0?O:`${O} + { ${_.join(", ")} }`;T!==t[c]&&a.push({...r(c),text:`${T}
104
- `})}}async function Hs(e,t){const n=await _i(e);if(xi(n))return{ok:!1,reason:`Cannot edit a file that will not open: ${n.reason}`};const r=n.document,i=jg(r,t);if("reason"in i)return i;const s=e.split(`
105
- `),o=Eg(e),a=g=>({start:o[g],end:g+1<o.length?o[g+1]:e.length}),l=g=>/^\s*/.exec(s[g])?.[0]??"",d=[],u={...i,sourceText:e,lines:s,starts:o,wholeLine:a,indentOf:l,current:r,next:t,edits:d};for(const g of[Ag,Rg,Lg,zg,Wg,Fg,Bg]){const m=g(u);if(m)return m}const c=g=>{const{drills:m,localGivens:w,...b}=g,v=g.tiles.map(p=>{if(p.filters?.length)return p;const{filters:x,..._}=p;return _});return{...b,tiles:v,...m?.length?{drills:[...m].sort((p,x)=>ki(p).localeCompare(ki(x)))}:{},...w?.length?{localGivens:w}:{}}};if(d.length===0)return me(c(r))!==me(c(t))?{ok:!1,reason:"The edit did not produce the dashboard that was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:e};const h=Dg(e,d),f=await _i(h);return xi(f)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${f.reason}`}:me(c(f.document))!==me(c(t))?{ok:!1,reason:"The edit did not produce the dashboard that was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:h}}function Ng(e){const[t,n]=S.useState({stack:[e.document],index:0}),[r,i]=S.useState(e.source),[s,o]=S.useState(void 0),[a,l]=S.useState(e.document),d=t.stack[t.index],u=S.useCallback(b=>{o(void 0),n(v=>{const p=structuredClone(v.stack[v.index]);if(b(p),JSON.stringify(p)===JSON.stringify(v.stack[v.index]))return v;const _=[...v.stack.slice(0,v.index+1),p].slice(-100);return{stack:_,index:_.length-1}})},[]),c=S.useCallback(()=>{o(void 0),n(b=>b.index>0?{...b,index:b.index-1}:b)},[]),h=S.useCallback(()=>{o(void 0),n(b=>b.index<b.stack.length-1?{...b,index:b.index+1}:b)},[]),f=S.useCallback(async()=>{const b=await Hs(r,d);if(Gs(b))return o(b.reason),{ok:!1,reason:b.reason};try{await e.onSave?.(b.source)}catch(v){const p=`Could not save: ${v}`;return o(p),{ok:!1,reason:p}}return i(b.source),l(d),o(void 0),{ok:!0}},[d,e,r]),g=S.useMemo(()=>JSON.stringify(d)!==JSON.stringify(a),[d,a]),m=S.useMemo(()=>{const b=new Set(a.tiles.map(Vs)),v=new Set(d.tiles.map(Vs));return[...b].some(p=>!v.has(p))||[...v].some(p=>!b.has(p))},[d,a]),w=S.useCallback(async()=>{const b=await Hs(r,d);return Gs(b)?{ok:!1,reason:b.reason}:{ok:!0,source:b.source}},[d,r]);return{document:d,source:r,canUndo:t.index>0,canRedo:t.index<t.stack.length-1,dirty:g,...s===void 0?{}:{error:s},update:u,undo:c,redo:h,save:f,preview:w,structural:m}}function Cd({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,renderTile:s,controls:o,givens:a,catalog:l,toolbar:d,dashboards:u,onEvent:c,savesTo:h="package"}){const f=Ng({source:e,document:t,...n?{onSave:n}:{}}),[g,m]=S.useState(void 0),[w,b]=S.useState(!1),v=f.document.columns??j.DEFAULT_COLUMNS,{resize:p,gridBox:x,startResize:_,onResize:O,endResize:T}=bg({tiles:f.document.tiles,columns:v,onStart:m,commit:($,C)=>f.update(F=>{F.tiles[$].colspan=C})}),{dragging:E,preview:I,onDragStart:D,onDragOver:L,onDragEnd:M}=yg({tiles:f.document.tiles,commit:$=>f.update(C=>{C.tiles=$}),onLanded:m}),[A,Q]=S.useState(void 0),[J,ye]=S.useState(void 0),[Ie,ie]=S.useState(!1),[ze,Ke]=S.useState(void 0),[be,qe]=S.useState(null),[We,je]=S.useState(void 0);S.useEffect(()=>{r?.(f.document)},[f.document,r]),S.useEffect(()=>{i?.(f.dirty)},[f.dirty,i]);const Fe=S.useMemo(()=>vp(f.document),[f.document]),xe=S.useMemo(()=>{const $=new Set((t.localGivens??[]).map(C=>C.name));return(a??[]).filter(C=>!$.has(C.name))},[t,a]),ee=S.useMemo(()=>Bh(f.document,xe),[f.document,xe]),z=S.useMemo(()=>new Map(f.document.sources.map($=>[$.name,Sa(l,$.base)])),[l,f.document.sources]),V=S.useCallback($=>z.get($.source)??Sa(l,$.source),[z,l]),_e=($,C)=>{const F=[];for(const Y of f.document.tiles){const Be=V(Y);if(!Be)continue;const ge=new Map(Be.map($e=>[$e.name,$e.type]));for(const $e of Y.filters??[])$e.given===$&&(!ge.has($e.field)||!ti(C,ge.get($e.field)))&&F.push(`${$e.field} on ${Y.label??Y.name} (${f.document.sources.find(ve=>ve.name===Y.source)?.base??Y.source})`)}return F},ne=S.useMemo(()=>ee.filter($=>$.origin==="model"&&$.boundTiles===0),[ee]),Ae=S.useCallback(()=>{je(void 0),b(!0);const $=j.now(),{structural:C}=f,F=f.document.tiles.length;f.save().then(Y=>{Y.ok===!0?c?.({type:"dashboard.saved",tiles:F,structural:C,where:h,durationMs:j.now()-$}):c?.({type:"dashboard.save_refused",reason:Y.reason})}).finally(()=>b(!1))},[f,c,h]),X=S.useCallback(()=>{if(!(!n||!f.dirty||w)){if(!f.structural){Ae();return}f.preview().then($=>{$.ok?je({before:f.source,after:$.source}):Ae()})}},[n,f,w,Ae]),et=$=>{ie(!1),f.update(C=>{let F=C.sources.find(ge=>ge.base===$.base);if(!F){const ge=new Set(C.sources.map(ve=>ve.name));let $e=`${$.base}_tiles`;for(let ve=2;ge.has($e);ve++)$e=`${$.base}_tiles_${ve}`;F={name:$e,base:$.base},C.sources.push(F)}const Y=new Set(C.tiles.filter(ge=>ge.source===F.name).map(ge=>ge.name));let Be=`${$.view}_tile`;for(let ge=2;Y.has(Be);ge++)Be=`${$.view}_tile_${ge}`;C.tiles.push({name:Be,source:F.name,declaration:{kind:"reference",from:$.view},colspan:$.colspan,...$.label?{label:$.label}:{}})}),m(f.document.tiles.length)},Se=$=>{ye(void 0),m(void 0),f.update(C=>{C.tiles.splice($,1)})};tp(S.useMemo(()=>({undo:f.undo,redo:f.redo,...n?{save:X}:{},escape:()=>{!J&&!A&&m(void 0)},nudge:$=>{if(g===void 0)return;const C=f.document.tiles[g];if(!C||C.declaration.kind==="inherited")return;const F=Math.min(Math.max((C.colspan??1)+$,1),v);F!==(C.colspan??1)&&f.update(Y=>{Y.tiles[g].colspan=F})}}),[f,n,X,J,A,g,v]));const ft=($,C,F)=>{Q(void 0),f.update(Y=>{F&&Uh(Y,F),qh(Y,$,C)})},P=$=>{Q(void 0),f.update(C=>Xh(C,$))},R=(()=>{const $=f.document.tiles;return p!==void 0?$.map((C,F)=>F===p.index?{...C,colspan:p.span}:C):I??$})(),U=E?wp(R,v):R.map(vd);return y.jsxs(k.Stack,{sx:{gap:0},children:[y.jsx(np,{canUndo:f.canUndo,canRedo:f.canRedo,onUndo:f.undo,onRedo:f.redo,dirty:f.dirty,saving:w,...n?{onSave:X}:{},...d?{actions:d}:{},...l?{onAddTile:()=>ie(!0)}:{},onSettings:qe}),y.jsxs(k.Stack,{sx:{gap:2,px:"4px",pb:"4px"},children:[y.jsx(j.DashboardProse,{title:f.document.title||"Untitled dashboard",...f.document.description?{description:f.document.description}:{}}),y.jsx(bp,{controls:ee,tileCount:f.document.tiles.length,unknownFieldsOf:_e,onEdit:$=>Q({control:$}),onAdd:()=>Q({}),children:o}),f.error&&y.jsx(k.Alert,{severity:"warning",children:f.error}),y.jsx(Sh,{sensors:eg,onDragStart:D,onDragOver:L,onDragEnd:M,children:y.jsxs(k.Box,{ref:x,sx:{position:"relative"},children:[(p!==void 0||E)&&y.jsx(cg,{columns:v}),y.jsx(j.DashboardGrid,{tiles:U,columns:v,keyOf:$=>$.kind==="gap"?md($.after):ht($.tile),renderTile:$=>{if($.kind==="gap")return y.jsx(lg,{after:$.after});const{tile:C,index:F}=$;return y.jsx(og,{tile:C,index:F,selected:F===g,menuOpen:J?.index===F,resizeSpan:p?.index===F?p.span:void 0,columns:v,onSelect:()=>m(F),onOpenMenu:Y=>{m(F),ye({anchor:Y,index:F})},onResizeStart:Y=>_(Y,F),onResizeMove:O,onResizeEnd:T,children:s?s(C):y.jsx(ag,{tile:C})})}})]})}),y.jsx(gp,{open:A!==void 0,document:f.document,...A?.control?{control:A.control}:{},available:ne,...l?{fieldsFor:V}:{},onClose:()=>Q(void 0),onApply:ft,onRemove:P}),y.jsx(xg,{anchor:J?.anchor??null,tile:J===void 0?void 0:f.document.tiles[J.index],onClose:()=>ye(void 0),onCommit:$=>{const C=J?.index;C!==void 0&&f.update(F=>{F.tiles[C]=$})},onRemove:()=>{J!==void 0&&Se(J.index)},columns:v,onDrills:()=>{J!==void 0&&Ke(f.document.tiles[J.index]?.source)}}),y.jsx(hp,{open:ze!==void 0,document:f.document,source:f.document.sources.find($=>$.name===ze),givenNames:ee.map($=>$.name),dashboards:u??[],onClose:()=>Ke(void 0),onApply:$=>f.update(C=>{const Y=[...(C.drills??[]).filter(Be=>Be.source!==ze),...$];Y.length===0?delete C.drills:C.drills=Y})}),y.jsx(mp,{anchor:be,settings:Fe,onClose:()=>qe(null),onCommit:$=>f.update(C=>{C.title=$.title,$.description===void 0?delete C.description:C.description=$.description,$.columns===void 0?delete C.columns:C.columns=$.columns,$.autorun===void 0?delete C.autorun:C.autorun=$.autorun})}),y.jsx(cp,{open:Ie,document:f.document,catalog:l,columns:v,onClose:()=>ie(!1),onAdd:et}),y.jsx(fp,{open:We!==void 0,before:We?.before??"",after:We?.after??"",onConfirm:Ae,onClose:()=>je(void 0)})]})]})}function Gg(e,t){const n=new Set;for(const s of e.tiles)for(const o of s.filters??[])n.add(o.given);const r=[],i=new Set;for(const s of e.localGivens??[])n.has(s.name)&&(i.add(s.name),r.push(Vg(s)));for(const s of t)s.name===void 0||i.has(s.name)||!n.has(s.name)||(i.add(s.name),r.push(s));return r}function Vg(e){return{name:e.name,type:e.type,default:e.default,...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function Hg(e,t,n,r=new Map){if(t.declaration.kind!=="reference")return{expression:`${t.source} -> ${t.name}`,givenNames:t.declaration.kind==="inherited"?void 0:[]};const i=t.source,s=new Map((e.localGivens??[]).map(d=>[d.name,d.type])),o=[],a=[];for(const d of t.filters??[]){const u=`where: ${d.field} ${d.op??"~"}`;if(n.has(d.given)){o.push(d.given),a.push(`${u} $${d.given}`);continue}if(!s.has(d.given))continue;const c=j.malloyLiteral(r.get(d.given),s.get(d.given));c!==void 0&&a.push(`${u} ${c}`)}const l=a.join(", ");return{expression:`${i} -> ${t.declaration.from}`+(l?` + { ${l} }`:""),givenNames:o}}async function Kg(e){const t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("")}const Ha=(e,t,n,r)=>({workspace:e,type:"dashboard",path:`${t}/${n}/${r}`});function qg({environmentName:e,packageName:t,dashboardName:n,onExit:r,onEvent:i,onDirtyChange:s}){const{apiClients:o,mutable:a}=Le.useServer(),l=Fd.useQueryClient(),d=S.useRef(j.now()),u=S.useRef(i);u.current=i;const c=S.useRef(s);c.current=s;const h=j.useOptionalDocumentStorage()?.documentStorage,f=`dashboards/${n}.malloy`,g=j.useQueryWithApiError({queryKey:["dashboard-editor-model",e,t,f],queryFn:()=>o.models.getModel(e,t,f)}),m=g.data?.data?.sourceText,[w,b]=S.useState(void 0),[v,p]=S.useState(void 0),[x,_]=S.useState(h===void 0),[O,T]=S.useState(!1),[E,I]=S.useState(void 0);S.useEffect(()=>{if(!h)return;let G=!1;return I(void 0),(async()=>{try{const Oe=await h.listWorkspaces(!1),tt=Oe.find(fe=>fe.authoritative)??Oe.find(fe=>fe.writeable);if(G)return;if(b(tt),tt!==void 0){const fe=await h.getDocument(Ha(tt.name,e,t,f)).catch(W=>{if(!j.isDocumentNotFound(W))throw W});if(G)return;p(fe),T(fe!==void 0)}}catch(Oe){if(G)return;I(Ka(Oe))}G||_(!0)})(),()=>{G=!0}},[h,e,t,f]);const D=w?.authoritative===!0,L=D&&E!==void 0,[M,A]=S.useState(void 0),Q=(D||M===!0)&&v!==void 0,[J,ye]=S.useState(void 0),[Ie,ie]=S.useState(void 0),ze=S.useRef(void 0),Ke=S.useRef(void 0),[be,qe]=S.useState(void 0),We=g.dataUpdatedAt,je=S.useRef(We);je.current=We;const Fe=be!==void 0&&be.onFetch===We?be.text:m,xe=S.useRef(Fe);xe.current=Fe;const ee=Q?v:Fe,[z,V]=S.useState(!1),[_e,ne]=S.useState(void 0),[Ae,X]=S.useState(void 0),et=ee!==void 0&&ee!==Ae,Se=J?.source,ft=et&&z&&Se!==void 0&&ee!==_e,P=ft?Se:et?ee:Se??ee,R=ft?ee:void 0,U=S.useRef(Se);U.current=Se;const $=S.useRef(ee);$.current=ee;const C=S.useRef("package");C.current=Q?D?"record":"draft":"package",S.useEffect(()=>{if(P===void 0||!x||L||P===U.current)return;let G=!1;const Oe=xe.current,tt=$.current;return _i(P).then(fe=>{if(!G){if(xi(fe)){const W=fe.line?`${fe.reason} (line ${fe.line})`:fe.reason;ie(W),u.current?.({type:"dashboard.open_refused",reason:W});return}ie(void 0),ze.current=void 0,Ke.current=Oe,qe(void 0),ne(void 0),X(tt),ye(W=>({source:P,document:fe.document,generation:(W?.generation??0)+1})),u.current?.({type:"dashboard.opened",from:C.current,tiles:fe.document.tiles.length,durationMs:j.now()-d.current})}}),()=>{G=!0}},[P,x,L]);const F=w===void 0?void 0:Ha(w.name,e,t,f),Y=S.useCallback(async G=>{if(!h||!F)throw new Error("This host keeps no documents, so there is nowhere to save.");await h.saveDocument(F,G),ye(Oe=>Oe&&{...Oe,source:G}),p(G),(D||M===!0)&&X(G),D||A(Oe=>Oe??!1)},[h,F,D,M]),[Be,ge]=S.useState(void 0),$e=S.useCallback(async G=>{const Oe=Ke.current,tt=ze.current??(Oe===void 0?void 0:await Kg(Oe));if(tt===void 0)throw new Error("The package file is still loading; try again.");let fe;try{fe=await o.models.updateModelSource(e,t,f,{source:G,expectedHash:tt})}catch(W){throw l.invalidateQueries({queryKey:["dashboard-editor-model",e,t,f]}),new Error(Yg(W))}if(ye(W=>W&&{...W,source:G}),qe({text:G,onFetch:je.current}),X(G),ze.current=fe.data.contentHash,ge(void 0),h&&F)try{await h.deleteDocument(F),p(void 0),T(!1)}catch(W){j.isDocumentNotFound(W)?(p(void 0),T(!1)):ge(Ka(W))}A(!1),await l.invalidateQueries({queryKey:["dashboard-editor-model",e,t,f]});for(const W of["dashboard-editor-manifest","dashboards","dashboard"])l.invalidateQueries({queryKey:[W]})},[o,e,t,f,h,F,l]),ve=D?"host":a?"package":"browser",qt=w?.writeable===!0,Tr=E===void 0?D?h&&F&&qt?Y:void 0:a?$e:h&&F&&qt?Y:void 0:void 0,Ut=w?.name,An=S.useCallback(G=>{u.current?.(G.type==="dashboard.saved"&&G.where!=="package"&&Ut!==void 0?{...G,workspace:Ut}:G)},[Ut]),Er=S.useCallback(G=>{V(G),c.current?.(G)},[]),Dr=G=>{d.current=j.now(),ne(G?v:Fe),A(G)},Pr=()=>{d.current=j.now(),ne(R)};if(g.isError)return y.jsx(j.ApiErrorDisplay,{error:g.error,context:"Opening the dashboard"});if(!m||!x)return y.jsxs(k.Stack,{sx:{gap:2},children:[y.jsx(j.DashboardBar,{}),y.jsx(j.Loading,{text:"Opening the dashboard…"})]});if(L)return y.jsxs(k.Alert,{severity:"error",sx:{m:2},children:["This dashboard cannot be opened: ",E]});if(Ie)return y.jsxs(k.Alert,{severity:"error",sx:{m:2},children:["This dashboard cannot be opened in the builder: ",Ie]});const Ri=v!==void 0&&v!==m;return y.jsxs(k.Stack,{sx:{gap:2},children:[!D&&O&&Ri&&M===void 0&&y.jsx(k.Alert,{severity:"info",action:y.jsxs(k.Stack,{direction:"row",sx:{gap:1},children:[y.jsx(k.Button,{size:"small",onClick:()=>Dr(!0),children:"Resume"}),y.jsx(k.Button,{size:"small",onClick:()=>Dr(!1),children:"Start from the package"})]}),children:"You have edits to this dashboard saved in this browser that the package does not have."}),R!==void 0&&y.jsx(k.Alert,{severity:"warning",action:y.jsx(k.Button,{size:"small",onClick:Pr,children:"Load it"}),children:ve==="package"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":ve==="host"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them."}),Be!==void 0&&y.jsxs(k.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",Be]}),J&&y.jsx(Xg,{environmentName:e,packageName:t,modelPath:f,slug:n,opened:J,onSave:Tr,onDirtyChange:Er,savesTo:ve,...i?{onEvent:An}:{},toolbar:r&&y.jsx(j.SecondaryButton,{label:"Done editing",icon:y.jsx(j.CheckIcon,{}),onClick:r}),note:Ug({authoritative:D,mutable:a,...w?{workspace:w}:{},...E!==void 0?{readFailure:E}:{}})},J.generation)]})}function Ug({authoritative:e,mutable:t,workspace:n,readFailure:r}){return r!==void 0?`The saved copy could not be read, so Save is off: ${r}`:e&&n?n.writeable?n.description:`${n.description}: you cannot save into it.`:t?"Save writes the file into the package.":n?`${n.description}: this server does not take writes.`:"This server does not take writes."}function Xg({environmentName:e,packageName:t,modelPath:n,slug:r,opened:i,onSave:s,onDirtyChange:o,onEvent:a,savesTo:l,toolbar:d,note:u}){const{apiClients:c}=Le.useServer(),{data:h,isSuccess:f}=j.useQueryWithApiError({queryKey:["dashboard-editor-manifest",e,t,r],queryFn:()=>c.dashboards.getDashboard(e,t,r,void 0)}),g=h?.data,{data:m}=j.useQueryWithApiError({queryKey:["dashboard-editor-dashboards",e,t],queryFn:()=>c.dashboards.listDashboards(e,t,void 0)}),w=S.useMemo(()=>(m?.data??[]).map(M=>M.name).filter(M=>!!M&&M!==r),[m,r]),b=S.useMemo(()=>{const M=n.slice(0,n.lastIndexOf("/")+1),A=new Set;for(const Q of i.document.imports){const J=new URL(Q.from,`https://malloy.invalid/${M}`);A.add(J.pathname.slice(1))}return[...A]},[i.document.imports,n]),{data:v}=j.useQueryWithApiError({queryKey:["dashboard-editor-catalog",e,t,...b],queryFn:async()=>{const M=await Promise.all(b.map(A=>c.models.getModel(e,t,A).then(Q=>Q.data)));return hd(M)},enabled:b.length>0}),[p,x]=S.useState(i.document);S.useEffect(()=>x(i.document),[i.document]);const _=S.useMemo(()=>g?.givens??[],[g]),O=S.useMemo(()=>new Set(_.map(M=>M.name).filter(M=>M!==void 0)),[_]),T=S.useMemo(()=>Gg(p,_),[p,_]),{declaredTypes:E,applied:I,panel:D}=j.useDocumentControls({specs:T,loaded:f,startingValues:g?.startingGivens,documentKey:`${e}/${t}/${r}/edit`,autorun:g?.autorun!==!1,environmentName:e,packageName:t,modelPath:g?.path,documentName:r}),L=S.useMemo(()=>function(A){const Q=Hg(p,A,O,I);return y.jsx(j.DashboardTile,{environmentName:e,packageName:t,modelPath:n,tile:Q.expression,label:A.label??j.tileTitle(`${A.source} -> ${A.name}`),subtitle:A.subtitle,borderless:A.borderless,givens:I,declaredTypes:E,givenNames:Q.givenNames,height:j.TILE_MAX_HEIGHT})},[p,O,e,t,n,I,E]);return y.jsxs(k.Stack,{sx:{gap:1},children:[y.jsx(Cd,{source:i.source,document:i.document,renderTile:L,givens:T.filter(M=>M.name!==void 0).map(M=>({name:M.name,...M.label?{label:M.label}:{},...M.type?{type:M.type}:{},...M.suggest?.dimension?{field:M.suggest.dimension}:{}})),onChange:x,onDirtyChange:o,...v?{catalog:v}:{},dashboards:w,...a?{onEvent:a}:{},toolbar:d,controls:f?y.jsx(j.GivensPanel,{...D,layout:"bar"}):void 0,...s?{onSave:s}:{},savesTo:l}),y.jsx(k.Box,{sx:{px:.5},children:y.jsx(k.Typography,{variant:"caption",sx:{opacity:.7},children:u})})]})}function Ka(e){return e instanceof Error?e.message:String(e)}function Yg(e){const t=e.response?.data;return t?.message?t.message:e instanceof Error?e.message:String(e)}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.DashboardBuilder=Cd;exports.DashboardEditor=qg;exports.buildCatalog=hd;exports.readDashboardDocument=_i;exports.readFailed=xi;exports.spliceDashboardDocument=Hs;exports.spliceFailed=Gs;
105
+ `:"";a.push({start:x,end:x,text:m+v}),d=w}}function yv(e){const{lines:t,starts:n,wholeLine:r,indentOf:i,current:s,next:o,edits:a,parsed:l}=e,u=new Map(s.tiles.map(c=>[gt(c),c]));for(const c of o.tiles){const d=u.get(gt(c));if(d===void 0||be(d)===be(c))continue;if(c.declaration.kind==="inherited")return{ok:!1,reason:`\`${c.source} -> ${c.name}\` is declared on its source, not in this dashboard, so its presentation cannot be changed here.`};const h=dv(l,c.source,c.name);if(h<0)return{ok:!1,reason:`Could not find where \`${c.name}\` is declared inside \`${c.source}\`.`};const{tags:f}=Ar(l,t,h),g=i(h),v=Ud(c),w=new Map(v.map($=>[li($)??$,$])),x=new Set;for(const $ of f){const O=li($.text);if(O===void 0||!av.has(O))continue;const D=w.get(O);if(D===void 0){a.push({...r($.line),text:""});continue}x.add(O),D!==$.text&&a.push({...r($.line),text:`${g}${D}
106
+ `})}const m=v.filter($=>!x.has(li($)??$));if(m.length>0){const $=n[h];a.push({start:$,end:$,text:m.map(O=>`${g}${O}
107
+ `).join("")})}if(be(d.filters)===be(c.filters))continue;const p=Hd(e,c);if(!p)return{ok:!1,reason:`Could not find \`${c.name}\`'s declaration to filter it.`};if(p.body.kind==="reference"){const $=wv(e,c,p);if($)return $;continue}if(p.body.kind!=="inline")return{ok:!1,reason:`\`${c.name}\`'s body is ${p.body.why}, so there is no single first stage to write its filter into.`};const b=qd(c.filters,p.body.stage);if(b)return Kd(c.name,b.given);const _=Xd(e,c,p.body.stage);if(_)return _}}const Ht=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Hd(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function qd(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const i of r.clauses)if(!i.binding)for(const s of i.givens)n.add(s);return(e??[]).find(r=>n.has(r.given))}function Kd(e,t){return{ok:!1,reason:`\`${e}\` already filters on \`$${t}\` in a \`where:\` the builder does not manage, so binding it again would filter on it twice. Edit that \`where:\` in the file instead.`}}const ci=e=>`where: ${e.field} ${e.op??"~"} $${e.given}`;function nl(e,t,n){return{ok:!1,reason:`Removing a filter from \`${e}\` would also remove the comment written beside it (\`${t.text.slice(n.start,n.end).trim()}\`), so nothing was written. Delete it in the file first.`}}function bv(e,t,n){const r=e.commentIn(n);if(r)return r;const i=e.trailingComment(Ht(e,t.end-1));return i&&i.start>=t.end&&e.text.slice(t.end,i.start).trim()===""?i:void 0}function xv(e,t){const n=e[t].span;return t+1<e.length?{start:n.start,end:e[t+1].span.start}:t>0?{start:e[t-1].span.end,end:n.end}:n}function Yd(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),i=e.text.indexOf(`
108
+ `,t.end),s=e.text.slice(t.end,i<0?void 0:i);if(r.trim()===""&&s.trim()==="")return{start:n,end:i<0?e.text.length:i+1};if(r.trim()===""){const a=/^\s*/.exec(s)?.[0].length??0;return{start:t.start,end:t.end+a}}const o=r.replace(/[\s,]*$/,"");return{start:n+o.length,end:t.end}}function Xd(e,t,n){const{parsed:r,edits:i}=e,s=new Map((t.filters??[]).map(h=>[h.given,h])),o=new Set;let a;for(const h of n.wheres){const f=h.clauses.map((v,w)=>({clause:v,index:w})).filter(({clause:v})=>v.binding!==void 0);if(f.length===0)continue;const g=f.filter(({clause:v})=>s.has(v.binding.given));for(const{clause:v}of f)o.add(v.binding.given);if(g.length===0&&f.length===h.clauses.length){const v=Yd(r,h.span),w=bv(r,h.span,v);if(w)return nl(t.name,r,w);i.push({...v,text:""});continue}g.length>0&&(a=h.span);for(let v=f.length-1;v>=0;v--){const{clause:w,index:x}=f[v],m=s.get(w.binding.given);if(!m){const b=xv(h.clauses,x),_=r.commentIn(b);if(_)return nl(t.name,r,_);i.push({...b,text:""});continue}const p=ci(m).replace(/^where:\s*/,"");p!==r.text.slice(w.span.start,w.span.end)&&i.push({...w.span,text:p})}}const l=(t.filters??[]).filter(h=>!o.has(h.given));if(l.length===0)return;let u=a?.end??(n.statements.length>0?n.statements[n.statements.length-1].span.end:n.openEnd);if(!n.oneLine){const h=r.trailingComment(Ht(r,u));h&&h.start>=u&&(u=h.end)}const c=a!==void 0&&!/,\s*$/.test(r.text.slice(0,u))?", ":" ",d=n.oneLine?`${c}${l.map(ci).join(", ")}`:l.map(h=>`
109
+ ${n.indent}${ci(h)}`).join("");i.push({start:u,end:u,text:d})}function wv(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:i,refinement:s}=n.body,o=qd(t.filters,s);if(o)return Kd(t.name,o.given);const a=t.filters??[];if(!s){if(a.length===0)return;const c=` + { ${a.map(ci).join(", ")} }`;r.push({start:i.end,end:i.end,text:c});return}const l=s.wheres.some(c=>c.clauses.some(d=>!d.binding)),u=s.statements.some(c=>!s.wheres.some(d=>d.span.start===c.span.start));if(a.length===0&&!l&&!u){const c={start:i.end,end:s.span.end},d=e.parsed.commentIn(c);if(d)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(d.start,d.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...c,text:""});return}return Xd(e,t,s)}async function Js(e,t){const n=await Di(e);if(Oi(n))return{ok:!1,reason:`Cannot edit a file that will not open: ${n.reason}`};const r=n.document,i=uv(r,t);if("reason"in i)return i;const s=await Vd(e);if(Nd(s))return{ok:!1,reason:`Cannot edit a file that will not open: ${s.reason}`};const o=e.split(`
110
+ `),a=sv(e),l=v=>({start:a[v],end:v+1<a.length?a[v+1]:e.length}),u=v=>/^\s*/.exec(o[v])?.[0]??"",c=[],d={...i,sourceText:e,parsed:s.parsed,lines:o,starts:a,wholeLine:l,indentOf:u,current:r,next:t,edits:c};for(const v of[fv,hv,pv,gv,vv,mv,yv]){const w=v(d);if(w)return w}const h=v=>{const{drills:w,localGivens:x,...m}=v,p=v.tiles.map(b=>{if(b.filters?.length)return b;const{filters:_,...$}=b;return $});return{...m,tiles:p,...w?.length?{drills:[...w].sort((b,_)=>Ti(b).localeCompare(Ti(_)))}:{},...x?.length?{localGivens:x}:{}}};if(c.length===0)return be(h(r))!==be(h(t))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const f=ov(e,c);if((await Qa(e)).length===0){const v=await Qa(f);if(v.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${v[0]}). Your changes are still here.`}}const g=await Di(f);return Oi(g)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${g.reason}`}:be(h(g.document))!==be(h(t))?{ok:!1,reason:"What was written did not read back as what was asked for, so it was not written. Your changes are still here."}:{ok:!0,source:f}}function _v(e){const[t,n]=S.useState({stack:[e.document],index:0}),[r,i]=S.useState(e.source),[s,o]=S.useState(void 0),[a,l]=S.useState(e.document),u=t.stack[t.index],c=S.useCallback(x=>{o(void 0),n(m=>{const p=structuredClone(m.stack[m.index]);if(x(p),JSON.stringify(p)===JSON.stringify(m.stack[m.index]))return m;const _=[...m.stack.slice(0,m.index+1),p].slice(-100);return{stack:_,index:_.length-1}})},[]),d=S.useCallback(()=>{o(void 0),n(x=>x.index>0?{...x,index:x.index-1}:x)},[]),h=S.useCallback(()=>{o(void 0),n(x=>x.index<x.stack.length-1?{...x,index:x.index+1}:x)},[]),f=S.useCallback(async()=>{const x=await Js(r,u);if(Qs(x))return o(x.reason),{ok:!1,reason:x.reason};try{await e.onSave?.(x.source)}catch(m){const p=`Could not save: ${m}`;return o(p),{ok:!1,reason:p}}return i(x.source),l(u),o(void 0),{ok:!0}},[u,e,r]),g=S.useMemo(()=>JSON.stringify(u)!==JSON.stringify(a),[u,a]),v=S.useMemo(()=>{const x=new Set(a.tiles.map(Zs)),m=new Set(u.tiles.map(Zs));return[...x].some(p=>!m.has(p))||[...m].some(p=>!x.has(p))},[u,a]),w=S.useCallback(async()=>{const x=await Js(r,u);return Qs(x)?{ok:!1,reason:x.reason}:{ok:!0,source:x.source}},[u,r]);return{document:u,source:r,canUndo:t.index>0,canRedo:t.index<t.stack.length-1,dirty:g,...s===void 0?{}:{error:s},update:c,undo:d,redo:h,save:f,preview:w,structural:v}}function Qd({source:e,document:t,onSave:n,onChange:r,onDirtyChange:i,renderTile:s,controls:o,givens:a,catalog:l,toolbar:u,dashboards:c,onEvent:d,savesTo:h="package"}){const f=_v({source:e,document:t,...n?{onSave:n}:{}}),[g,v]=S.useState(void 0),[w,x]=S.useState(!1),m=f.document.columns??j.DEFAULT_COLUMNS,{resize:p,gridBox:b,startResize:_,onResize:$,endResize:O}=zg({tiles:f.document.tiles,columns:m,onStart:v,commit:(E,P)=>f.update(B=>{B.tiles[E].colspan=P})}),{dragging:D,preview:M,onDragStart:I,onDragOver:K,onDragEnd:z}=Wg({tiles:f.document.tiles,commit:E=>f.update(P=>{P.tiles=E}),onLanded:v}),[C,W]=S.useState(void 0),[Y,ve]=S.useState(void 0),[Me,se]=S.useState(!1),[Le,Ve]=S.useState(void 0),[Te,Ye]=S.useState(null),[Ge,We]=S.useState(void 0);S.useEffect(()=>{r?.(f.document)},[f.document,r]),S.useEffect(()=>{i?.(f.dirty)},[f.dirty,i]);const Xe=S.useMemo(()=>Rp(f.document),[f.document]),Se=S.useMemo(()=>{const E=new Set((t.localGivens??[]).map(P=>P.name));return(a??[]).filter(P=>!E.has(P.name))},[t,a]),ue=S.useMemo(()=>ap(f.document,Se),[f.document,Se]),L=S.useMemo(()=>new Map(f.document.sources.map(E=>[E.name,ja(l,E.base)])),[l,f.document.sources]),V=S.useCallback(E=>L.get(E.source)??ja(l,E.source),[L,l]),_e=(E,P)=>{const B=[];for(const Q of f.document.tiles){const Ue=V(Q);if(!Ue)continue;const ke=new Map(Ue.map(ie=>[ie.name,ie.type]));for(const ie of Q.filters??[])ie.given===E&&(!ke.has(ie.field)||!ai(P,ke.get(ie.field)))&&B.push(`${ie.field} on ${Q.label??Q.name} (${f.document.sources.find($e=>$e.name===Q.source)?.base??Q.source})`)}return B},X=S.useMemo(()=>ue.filter(E=>E.origin==="model"&&E.boundTiles===0),[ue]),ze=S.useCallback(()=>{We(void 0),x(!0);const E=j.now(),{structural:P}=f,B=f.document.tiles.length;f.save().then(Q=>{Q.ok===!0?d?.({type:"dashboard.saved",tiles:B,structural:P,where:h,durationMs:j.now()-E}):d?.({type:"dashboard.save_refused",reason:Q.reason})}).finally(()=>x(!1))},[f,d,h]),te=S.useCallback(()=>{if(!(!n||!f.dirty||w)){if(!f.structural){ze();return}f.preview().then(E=>{E.ok?We({before:f.source,after:E.source}):ze()})}},[n,f,w,ze]),at=E=>{se(!1),f.update(P=>{let B=P.sources.find(ke=>ke.base===E.base);if(!B){const ke=new Set(P.sources.map($e=>$e.name));let ie=`${E.base}_tiles`;for(let $e=2;ke.has(ie);$e++)ie=`${E.base}_tiles_${$e}`;B={name:ie,base:E.base},P.sources.push(B)}const Q=new Set(P.tiles.filter(ke=>ke.source===B.name).map(ke=>ke.name));let Ue=`${E.view}_tile`;for(let ke=2;Q.has(Ue);ke++)Ue=`${E.view}_tile_${ke}`;P.tiles.push({name:Ue,source:B.name,declaration:{kind:"reference",from:E.view},colspan:E.colspan,...E.label?{label:E.label}:{}})}),v(f.document.tiles.length)},Fe=E=>{ve(void 0),v(void 0),f.update(P=>{P.tiles.splice(E,1)})};wp(S.useMemo(()=>({undo:f.undo,redo:f.redo,...n?{save:te}:{},escape:()=>{!Y&&!C&&v(void 0)},nudge:E=>{if(g===void 0)return;const P=f.document.tiles[g];if(!P||P.declaration.kind==="inherited")return;const B=Math.min(Math.max((P.colspan??1)+E,1),m);B!==(P.colspan??1)&&f.update(Q=>{Q.tiles[g].colspan=B})}}),[f,n,te,Y,C,g,m]));const xt=(E,P,B)=>{W(void 0),f.update(Q=>{B&&pp(Q,B),hp(Q,E,P)})},T=E=>{W(void 0),f.update(P=>gp(P,E))},A=(()=>{const E=f.document.tiles;return p!==void 0?E.map((P,B)=>B===p.index?{...P,colspan:p.span}:P):M??E})(),G=D?Bp(A,m):A.map(Dd);return y.jsxs(k.Stack,{sx:{gap:0},children:[y.jsx(_p,{canUndo:f.canUndo,canRedo:f.canRedo,onUndo:f.undo,onRedo:f.redo,dirty:f.dirty,saving:w,...n?{onSave:te}:{},...u?{actions:u}:{},...l?{onAddTile:()=>se(!0)}:{},onSettings:Ye}),y.jsxs(k.Stack,{sx:{gap:2,px:"4px",pb:"4px"},children:[y.jsx(j.DashboardProse,{title:f.document.title||"Untitled dashboard",...f.document.description?{description:f.document.description}:{}}),y.jsx(zp,{controls:ue,tileCount:f.document.tiles.length,unknownFieldsOf:_e,onEdit:E=>W({control:E}),onAdd:()=>W({}),children:o}),f.error&&y.jsx(k.Alert,{severity:"warning",children:f.error}),y.jsx(Gh,{sensors:xg,onDragStart:I,onDragOver:K,onDragEnd:z,children:y.jsxs(k.Box,{ref:b,sx:{position:"relative"},children:[(p!==void 0||D)&&y.jsx(Tg,{columns:m}),y.jsx(j.DashboardGrid,{tiles:G,columns:m,keyOf:E=>E.kind==="gap"?Td(E.after):pt(E.tile),renderTile:E=>{if(E.kind==="gap")return y.jsx(Dg,{after:E.after});const{tile:P,index:B}=E;return y.jsx(Eg,{tile:P,index:B,selected:B===g,menuOpen:Y?.index===B,resizeSpan:p?.index===B?p.span:void 0,columns:m,onSelect:()=>v(B),onOpenMenu:Q=>{v(B),ve({anchor:Q,index:B})},onResizeStart:Q=>_(Q,B),onResizeMove:$,onResizeEnd:O,children:s?s(P):y.jsx(Og,{tile:P})})}})]})}),y.jsx(Ap,{open:C!==void 0,document:f.document,...C?.control?{control:C.control}:{},available:X,...l?{fieldsFor:V}:{},onClose:()=>W(void 0),onApply:xt,onRemove:T}),y.jsx(Fg,{anchor:Y?.anchor??null,tile:Y===void 0?void 0:f.document.tiles[Y.index],onClose:()=>ve(void 0),onCommit:E=>{const P=Y?.index;P!==void 0&&f.update(B=>{B.tiles[P]=E})},onRemove:()=>{Y!==void 0&&Fe(Y.index)},columns:m,onDrills:()=>{Y!==void 0&&Ve(f.document.tiles[Y.index]?.source)}}),y.jsx(Ip,{open:Le!==void 0,document:f.document,source:f.document.sources.find(E=>E.name===Le),givenNames:ue.map(E=>E.name),dashboards:c??[],onClose:()=>Ve(void 0),onApply:E=>f.update(P=>{const Q=[...(P.drills??[]).filter(Ue=>Ue.source!==Le),...E];Q.length===0?delete P.drills:P.drills=Q})}),y.jsx(Lp,{anchor:Te,settings:Xe,onClose:()=>Ye(null),onCommit:E=>f.update(P=>{P.title=E.title,E.description===void 0?delete P.description:P.description=E.description,E.columns===void 0?delete P.columns:P.columns=E.columns,E.autorun===void 0?delete P.autorun:P.autorun=E.autorun})}),y.jsx(Tp,{open:Me,document:f.document,catalog:l,columns:m,onClose:()=>se(!1),onAdd:at}),y.jsx(Mp,{open:Ge!==void 0,before:Ge?.before??"",after:Ge?.after??"",onConfirm:ze,onClose:()=>We(void 0)})]})]})}function kv(e,t){const n=new Set;for(const s of e.tiles)for(const o of s.filters??[])n.add(o.given);const r=[],i=new Set;for(const s of e.localGivens??[])n.has(s.name)&&(i.add(s.name),r.push(Sv(s)));for(const s of t)s.name===void 0||i.has(s.name)||!n.has(s.name)||(i.add(s.name),r.push(s));return r}function Sv(e){return{name:e.name,type:e.type,default:e.default,...e.label===void 0?{}:{label:e.label},...e.description===void 0?{}:{description:e.description},...e.control===void 0?{}:{control:e.control},...e.suggest?{suggest:{...e.suggest.source===void 0?{}:{source:e.suggest.source},...e.suggest.query===void 0?{}:{query:e.suggest.query},dimension:e.suggest.dimension}}:{},...e.rangeMin===void 0?{}:{rangeMin:e.rangeMin},...e.rangeMax===void 0?{}:{rangeMax:e.rangeMax}}}function $v(e,t,n,r=new Map){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0};const i=t.source,s=t.declaration.kind==="reference"?t.declaration.from:t.name,o=new Map((e.localGivens??[]).map(c=>[c.name,c.type])),a=[],l=[];for(const c of t.filters??[]){const d=`where: ${c.field} ${c.op??"~"}`;if(n.has(c.given)){a.push(c.given),l.push(`${d} $${c.given}`);continue}if(!o.has(c.given))continue;const h=j.malloyLiteral(r.get(c.given),o.get(c.given));h!==void 0&&l.push(`${d} ${h}`)}const u=l.join(", ");return{expression:`${i} -> ${s}`+(u?` + { ${u} }`:""),givenNames:a}}async function Ev(e){const t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("")}const rl=(e,t,n,r)=>({workspace:e,type:"dashboard",path:`${t}/${n}/${r}`});function Ov(e){const{onExit:t,onEvent:n,onDirtyChange:r}=e,i=(()=>{if("resourceUri"in e)try{return j.parseResourceUri(e.resourceUri)}catch{return}})(),s="resourceUri"in e?i?.environmentName??"":e.environmentName,o="resourceUri"in e?i?.packageName??"":e.packageName,a="resourceUri"in e?e.dashboard:e.dashboardName,l=i?.versionId,u="resourceUri"in e?!!i?.environmentName&&!!i?.packageName:!0,{apiClients:c,mutable:d}=Be.useServer(),h=ou.useQueryClient(),f=S.useRef(j.now()),g=S.useRef(n);g.current=n;const v=S.useRef(r);v.current=r;const w=j.useOptionalDocumentStorage()?.documentStorage,x=`dashboards/${a}.malloy`,m=j.useQueryWithApiError({queryKey:["dashboard-editor-model",s,o,x,l],queryFn:()=>c.models.getModel(s,o,x,l),enabled:u}),p=m.data?.data?.sourceText,[b,_]=S.useState(void 0),[$,O]=S.useState(void 0),[D,M]=S.useState(w===void 0),[I,K]=S.useState(!1),[z,C]=S.useState(void 0);S.useEffect(()=>{if(!w)return;let R=!1;return C(void 0),(async()=>{try{const ee=await w.listWorkspaces(!1),Ee=ee.find(fe=>fe.authoritative)??ee.find(fe=>fe.writeable);if(R)return;if(_(Ee),Ee!==void 0){const fe=await w.getDocument(rl(Ee.name,s,o,x)).catch(oe=>{if(!j.isDocumentNotFound(oe))throw oe});if(R)return;O(fe),K(fe!==void 0)}}catch(ee){if(R)return;C(il(ee))}R||M(!0)})(),()=>{R=!0}},[w,s,o,x]);const W=b?.authoritative===!0,Y=W&&z!==void 0,[ve,Me]=S.useState(void 0),se=(W||ve===!0)&&$!==void 0,[Le,Ve]=S.useState(void 0),[Te,Ye]=S.useState(void 0),Ge=S.useRef(void 0),We=S.useRef(void 0),[Xe,Se]=S.useState(void 0),ue=m.dataUpdatedAt,L=S.useRef(ue);L.current=ue;const V=Xe!==void 0&&Xe.onFetch===ue?Xe.text:p,_e=S.useRef(V);_e.current=V;const X=se?$:V,[ze,te]=S.useState(!1),[at,Fe]=S.useState(void 0),[xt,T]=S.useState(void 0),A=X!==void 0&&X!==xt,G=Le?.source,E=A&&ze&&G!==void 0&&X!==at,P=E?G:A?X:G??X,B=E?X:void 0,Q=S.useRef(G);Q.current=G;const Ue=S.useRef(X);Ue.current=X;const ke=S.useRef("package");ke.current=se?W?"record":"draft":"package",S.useEffect(()=>{if(P===void 0||!D||Y||P===Q.current)return;let R=!1;const ee=_e.current,Ee=Ue.current;return Di(P).then(fe=>{if(!R){if(Oi(fe)){const oe=fe.line?`${fe.reason} (line ${fe.line})`:fe.reason;Ye(oe),g.current?.({type:"dashboard.open_refused",reason:oe});return}Ye(void 0),Ge.current=void 0,We.current=ee,Se(void 0),Fe(void 0),T(Ee),Ve(oe=>({source:P,document:fe.document,generation:(oe?.generation??0)+1})),g.current?.({type:"dashboard.opened",from:ke.current,tiles:fe.document.tiles.length,durationMs:j.now()-f.current})}}),()=>{R=!0}},[P,D,Y]);const ie=b===void 0?void 0:rl(b.name,s,o,x),$e=S.useCallback(async R=>{if(!w||!ie)throw new Error("This host keeps no documents, so there is nowhere to save.");await w.saveDocument(ie,R),Ve(ee=>ee&&{...ee,source:R}),O(R),(W||ve===!0)&&T(R),W||Me(ee=>ee??!1)},[w,ie,W,ve]),[Qt,Ct]=S.useState(void 0),Rr=S.useCallback(async R=>{const ee=We.current,Ee=Ge.current??(ee===void 0?void 0:await Ev(ee));if(Ee===void 0)throw new Error("The package file is still loading; try again.");let fe;try{fe=await c.models.updateModelSource(s,o,x,{source:R,expectedHash:Ee})}catch(oe){throw h.invalidateQueries({queryKey:["dashboard-editor-model",s,o,x,l]}),new Error(Cv(oe))}if(Ve(oe=>oe&&{...oe,source:R}),Se({text:R,onFetch:L.current}),T(R),Ge.current=fe.data.contentHash,Ct(void 0),w&&ie)try{await w.deleteDocument(ie),O(void 0),K(!1)}catch(oe){j.isDocumentNotFound(oe)?(O(void 0),K(!1)):Ct(il(oe))}Me(!1),await h.invalidateQueries({queryKey:["dashboard-editor-model",s,o,x,l]});for(const oe of["dashboard-editor-manifest","dashboards","dashboard"])h.invalidateQueries({queryKey:[oe]})},[c,s,o,x,l,w,ie,h]),Pt=W?"host":d?"package":"browser",Zt=b?.writeable===!0,Wn=l!==void 0&&Pt==="package",Lr=z===void 0?W?w&&ie&&Zt?$e:void 0:Wn?void 0:d?Rr:w&&ie&&Zt?$e:void 0:void 0,zn=b?.name,Fn=S.useCallback(R=>{g.current?.(R.type==="dashboard.saved"&&R.where!=="package"&&zn!==void 0?{...R,workspace:zn}:R)},[zn]),Vi=S.useCallback(R=>{te(R),v.current?.(R)},[]),Nn=R=>{f.current=j.now(),Fe(R?$:V),Me(R)},Gi=()=>{f.current=j.now(),Fe(B)};if(!u&&"resourceUri"in e)return y.jsxs(k.Alert,{severity:"error",sx:{m:2},children:["A dashboard resource URI must name an environment and a package. Received: ",e.resourceUri]});if(m.isError)return y.jsx(j.ApiErrorDisplay,{error:m.error,context:"Opening the dashboard"});if(!p||!D)return y.jsxs(k.Stack,{sx:{gap:2},children:[y.jsx(j.DashboardBar,{}),y.jsx(j.Loading,{text:"Opening the dashboard…"})]});if(Y)return y.jsxs(k.Alert,{severity:"error",sx:{m:2},children:["This dashboard cannot be opened: ",z]});if(Te)return y.jsxs(k.Alert,{severity:"error",sx:{m:2},children:["This dashboard cannot be opened in the builder: ",Te]});const Z=$!==void 0&&$!==p;return y.jsxs(k.Stack,{sx:{gap:2},children:[!W&&I&&Z&&ve===void 0&&y.jsx(k.Alert,{severity:"info",action:y.jsxs(k.Stack,{direction:"row",sx:{gap:1},children:[y.jsx(k.Button,{size:"small",onClick:()=>Nn(!0),children:"Resume"}),y.jsx(k.Button,{size:"small",onClick:()=>Nn(!1),children:"Start from the package"})]}),children:"You have edits to this dashboard saved in this browser that the package does not have."}),B!==void 0&&y.jsx(k.Alert,{severity:"warning",action:y.jsx(k.Button,{size:"small",onClick:Gi,children:"Load it"}),children:Pt==="package"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and until you do, saving is refused.":Pt==="host"?"This dashboard changed since you opened it. Your edits are still here; loading the new version replaces them, and saving keeps yours and writes over it.":"The package's copy of this dashboard changed since you opened it. Your edits are still here; loading the new version replaces them."}),Qt!==void 0&&y.jsxs(k.Alert,{severity:"warning",children:["The file was saved into the package, but the copy kept beside it could not be cleared, so it will be offered again:"," ",Qt]}),Le&&y.jsx(Tv,{environmentName:s,packageName:o,modelPath:x,slug:a,...l!==void 0?{versionId:l}:{},opened:Le,onSave:Lr,onDirtyChange:Vi,savesTo:Pt,...n?{onEvent:Fn}:{},toolbar:t&&y.jsx(j.SecondaryButton,{label:"Done editing",icon:y.jsx(j.CheckIcon,{}),onClick:t}),note:Dv({authoritative:W,mutable:d,pinnedPackageSave:Wn,...b?{workspace:b}:{},...z!==void 0?{readFailure:z}:{},...l!==void 0?{versionId:l}:{}})},Le.generation)]})}function Dv({authoritative:e,mutable:t,pinnedPackageSave:n,workspace:r,readFailure:i,versionId:s}){return i!==void 0?`The saved copy could not be read, so Save is off: ${i}`:e&&r?r.writeable?r.description:`${r.description}: you cannot save into it.`:n?`Reading version ${s}: a version is a fixed point in history, so Save is off.`:t?"Save writes the file into the package.":r?`${r.description}: this server does not take writes.`:"This server does not take writes."}function Tv({environmentName:e,packageName:t,modelPath:n,slug:r,versionId:i,opened:s,onSave:o,onDirtyChange:a,onEvent:l,savesTo:u,toolbar:c,note:d}){const{apiClients:h}=Be.useServer(),{data:f,isSuccess:g}=j.useQueryWithApiError({queryKey:["dashboard-editor-manifest",e,t,r,i],queryFn:()=>h.dashboards.getDashboard(e,t,r,i)}),v=f?.data,{data:w}=j.useQueryWithApiError({queryKey:["dashboard-editor-dashboards",e,t,i],queryFn:()=>h.dashboards.listDashboards(e,t,i)}),x=S.useMemo(()=>(w?.data??[]).map(C=>C.name).filter(C=>!!C&&C!==r),[w,r]),m=S.useMemo(()=>{const C=n.slice(0,n.lastIndexOf("/")+1),W=new Set;for(const Y of s.document.imports){const ve=new URL(Y.from,`https://malloy.invalid/${C}`);W.add(ve.pathname.slice(1))}return[...W]},[s.document.imports,n]),{data:p}=j.useQueryWithApiError({queryKey:["dashboard-editor-catalog",e,t,...m,i],queryFn:async()=>{const C=await Promise.all(m.map(W=>h.models.getModel(e,t,W,i).then(Y=>Y.data)));return $d(C)},enabled:m.length>0}),[b,_]=S.useState(s.document);S.useEffect(()=>_(s.document),[s.document]);const $=S.useMemo(()=>v?.givens??[],[v]),O=S.useMemo(()=>new Set($.map(C=>C.name).filter(C=>C!==void 0)),[$]),D=S.useMemo(()=>kv(b,$),[b,$]),{declaredTypes:M,applied:I,panel:K}=j.useDocumentControls({specs:D,loaded:g,startingValues:v?.startingGivens,documentKey:`${e}/${t}/${i??""}/${r}/edit`,autorun:v?.autorun!==!1,environmentName:e,packageName:t,modelPath:v?.path,versionId:i,documentName:r}),z=S.useMemo(()=>function(W){const Y=$v(b,W,O,I);return y.jsx(j.DashboardTile,{environmentName:e,packageName:t,versionId:i,modelPath:n,tile:Y.expression,label:W.label??j.tileTitle(`${W.source} -> ${W.name}`),subtitle:W.subtitle,borderless:W.borderless,givens:I,declaredTypes:M,givenNames:Y.givenNames,height:j.TILE_MAX_HEIGHT})},[b,O,e,t,i,n,I,M]);return y.jsxs(k.Stack,{sx:{gap:1},children:[y.jsx(Qd,{source:s.source,document:s.document,renderTile:z,givens:D.filter(C=>C.name!==void 0).map(C=>({name:C.name,...C.label?{label:C.label}:{},...C.type?{type:C.type}:{},...C.suggest?.dimension?{field:C.suggest.dimension}:{}})),onChange:_,onDirtyChange:a,...p?{catalog:p}:{},dashboards:x,...l?{onEvent:l}:{},toolbar:c,controls:g?y.jsx(j.GivensPanel,{...K,layout:"bar"}):void 0,...o?{onSave:o}:{},savesTo:u}),y.jsx(k.Box,{sx:{px:.5},children:y.jsx(k.Typography,{variant:"caption",sx:{opacity:.7},children:d})})]})}function il(e){return e instanceof Error?e.message:String(e)}function Cv(e){const t=e.response?.data;return t?.message?t.message:e instanceof Error?e.message:String(e)}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.DashboardBuilder=Qd;exports.DashboardEditor=Ov;exports.buildCatalog=$d;exports.readDashboardDocument=Di;exports.readFailed=Oi;exports.spliceDashboardDocument=Js;exports.spliceFailed=Qs;