@malloy-publisher/sdk 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{RenderedResult-DwB0-9Yx.es.js → RenderedResult-BUb2Xvr2.es.js} +34 -19
- package/dist/{RenderedResult-hKjFEqaN.cjs.js → RenderedResult-qnpbr4tc.cjs.js} +15 -3
- package/dist/{ServerProvider-CcSrGaRN.es.js → ServerProvider-C6QQVKPm.es.js} +149 -141
- package/dist/ServerProvider-Gj-im5VD.cjs.js +1 -0
- package/dist/builder/index.cjs.js +82 -82
- package/dist/builder/index.es.js +3242 -3188
- package/dist/client/api.d.ts +54 -11
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +57 -56
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -5
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +3 -1
- package/dist/components/DashboardBuilder/addTileToDocument.d.ts +14 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +5 -1
- package/dist/components/DashboardBuilder/imports.d.ts +11 -12
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +3 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +5 -5
- package/dist/theme/buildVegaThemeOverride.d.ts +7 -3
- package/dist/{useCompiledDocument-BU6d8FPp.es.js → useCompiledDocument-0sxonf6N.es.js} +3707 -3686
- package/dist/{useCompiledDocument-pOg2W-Yt.cjs.js → useCompiledDocument-tBejqZ7s.cjs.js} +31 -31
- package/package.json +2 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -11
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +13 -5
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +5 -0
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +3 -0
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +3 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +10 -2
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +79 -3
- package/src/components/DashboardBuilder/EditorSurface.tsx +30 -2
- package/src/components/DashboardBuilder/addTile.compile.spec.ts +184 -0
- package/src/components/DashboardBuilder/addTileToDocument.spec.ts +58 -0
- package/src/components/DashboardBuilder/addTileToDocument.ts +64 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +1 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +79 -3
- package/src/components/DashboardBuilder/catalog.ts +23 -5
- package/src/components/DashboardBuilder/imports.spec.ts +56 -0
- package/src/components/DashboardBuilder/imports.ts +16 -13
- package/src/components/DashboardBuilder/preview.spec.ts +21 -0
- package/src/components/DashboardBuilder/preview.ts +10 -1
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +24 -9
- package/src/components/DashboardBuilder/spliceDocument.ts +18 -6
- package/src/components/DashboardBuilder/useDashboardEditor.ts +6 -2
- package/src/components/DashboardBuilder/useTileEditing.ts +13 -48
- package/src/components/RenderedResult/RenderedResult.tsx +12 -0
- package/src/components/given/GivenInput.tsx +39 -16
- package/src/components/given/utils.spec.ts +5 -0
- package/src/components/given/utils.ts +1 -1
- package/src/theme/buildVegaThemeOverride.spec.ts +11 -1
- package/src/theme/buildVegaThemeOverride.ts +10 -3
- package/src/timezone_runs.spec.ts +64 -0
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),C=require("../useCompiledDocument-pOg2W-Yt.cjs.js"),$=require("@mui/material"),k=require("react"),Ke=require("../ServerProvider-Gbf1YPOP.cjs.js"),me=require("../text-entry-BJwltZiy.cjs.js"),sf=require("react-dom"),of=require("@malloydata/malloy-tag"),af=require("@tanstack/react-query"),lf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function cf(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:lf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ei({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:s,onOpen:i,onChange:o,variant:a="standard"}){const l=cf(t,e,n),u=k.useId();return x.jsx($.TextField,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:s!==void 0,onChange:c=>{const d=c.target.value;l.find(f=>f.value===d)?.disabled||o(d)},helperText:s,FormHelperTextProps:{id:u},SelectProps:{...i?{onOpen:i}:{},renderValue:c=>l.find(d=>d.value===c)?.label??String(c),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...s?{"aria-describedby":u}:{}}},sx:{minWidth:140},children:l.map(c=>x.jsx($.MenuItem,{value:c.value,disabled:c.value==="custom"||c.disabled===!0,children:x.jsx($.ListItemText,{primary:c.label,...c.reason?{secondary:c.reason}:{}})},c.value))})}function df({sources:e,source:t,view:n,onSource:r,onView:s}){const{theme:i}=Ke.usePublisherTheme(),o=e.find(a=>a.name===t);return x.jsxs(x.Fragment,{children:[x.jsx($.TextField,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>x.jsxs($.MenuItem,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),x.jsxs($.Box,{children:[x.jsx($.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),x.jsxs($.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:i.border,borderRadius:1},children:[(o?.views??[]).map(a=>x.jsxs($.ListItemButton,{selected:n===a.name,onClick:()=>s(a.name),"aria-label":`View ${a.name}`,children:[x.jsx($.ListItemText,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&x.jsx($.Chip,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&x.jsx($.Typography,{variant:"body2",sx:{p:1.5,color:i.tileTitle},children:"This source declares no views."})]})]})]})}function uf({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o}){const{theme:a}=Ke.usePublisherTheme(),l=k.useMemo(()=>n?.sources??[],[n]),[u,c]=k.useState("query"),[d,f]=k.useState(""),[p,h]=k.useState(""),[v,y]=k.useState(""),[w,g]=k.useState("default"),[m,b]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;c("query");const I=T=>l.some(D=>D.name===T&&D.views.length>0);f(t.sources.map(T=>T.base).find(I)??l.find(T=>T.views.length>0)?.name??""),h(""),y(""),g("default"),b(Math.ceil(r/2))},[e,t,l,r]);const _=d!==""&&p!=="",O=[d,p].filter(I=>I!==""&&!me.isBareName(I)).map(I=>`"${I}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],E=l.find(I=>I.name===d)?.views.find(I=>I.name===p);return x.jsx(C.AppDialog,{open:e,onClose:s,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:s,children:"Cancel"}),x.jsx($.Button,{variant:"contained",disabled:u==="query"&&(!_||O!==void 0),onClick:()=>u==="text"?o():i({base:d,modelPath:l.find(I=>I.name===d)?.modelPath??"",view:p,...v.trim()?{label:v.trim()}:{},...w!=="default"?{chart:w,...E?{chartCarried:E.chart?[E.chart]:[]}:{}}:{},colspan:m}),children:u==="text"?"Add text":"Add tile"})]}),children:x.jsxs($.Stack,{sx:{gap:2,pt:1},children:[x.jsxs($.ToggleButtonGroup,{size:"small",exclusive:!0,value:u,"aria-label":"Tile type",onChange:(I,T)=>{T!==null&&c(T)},children:[x.jsx($.ToggleButton,{value:"query",sx:{px:1.5},children:"Query"}),x.jsx($.ToggleButton,{value:"text",sx:{px:1.5},children:"Text"})]}),u==="text"?x.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):l.length===0?x.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}):x.jsxs(x.Fragment,{children:[x.jsx(df,{sources:l,source:d,view:p,onSource:I=>{f(I),h("")},onView:I=>{h(I),g("default")}}),O&&x.jsx($.Typography,{variant:"body2",color:"error",children:O}),x.jsx(Ei,{state:w,view:E,cellLabel:"new tile",variant:"outlined",...E?{}:{disabledReason:"Pick a view to choose its chart."},onChange:I=>g(I)}),x.jsx($.Stack,{direction:"row",sx:{gap:1.5},children:x.jsx($.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:v,onChange:I=>y(I.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const je=e=>e.kind==="text",xe=e=>e.kind!=="text",Wr=e=>xe(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`,si="self";function ff({open:e,document:t,source:n,givenNames:r,dashboards:s,onClose:i,onApply:o}){const{theme:a}=Ke.usePublisherTheme(),[l,u]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const h=(t.drills??[]).filter(v=>v.source===n.name);u((n.dimensions??[]).map(v=>{const y=h.find(w=>w.name===v.name);return{name:v.name,expression:v.expression,to:y?.to??[],given:y?.given??""}}))},[e,n,t]);const c=(h,v)=>u(y=>y.map((w,g)=>{if(g!==h)return w;const m={...w};return v(m),m})),d=[si,...s.filter(h=>h!==si)],f=h=>h===si?"This dashboard":h,p=()=>{n&&(o(l.filter(h=>h.to.length>0).map(h=>({source:n.name,name:h.name,expression:h.expression,to:h.to,...h.given?{given:h.given}:{}}))),i())};return x.jsx(C.AppDialog,{open:e,onClose:i,title:"Drill",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:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:i,children:"Cancel"}),x.jsx($.Button,{variant:"contained",onClick:p,disabled:l.length===0,children:"Apply"})]}),children:x.jsx($.Stack,{sx:{gap:2,pt:1},children:l.length===0?x.jsx($.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?x.jsxs(x.Fragment,{children:[x.jsx($.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"," ",x.jsx($.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((h,v)=>x.jsxs($.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[x.jsxs($.Box,{sx:{minWidth:0,pt:.75},children:[x.jsx($.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:h.name}),x.jsxs($.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.expression,children:["is ",h.expression]})]}),x.jsx($.TextField,{select:!0,size:"small",label:"Clicks go to",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:y=>y.length===0?"Not clickable":y.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:y=>c(v,w=>{const g=y.target.value;w.to=Array.isArray(g)?g:String(g).split(",").filter(Boolean)}),children:d.map(y=>x.jsxs($.MenuItem,{value:y,children:[x.jsx($.Checkbox,{size:"small",checked:h.to.includes(y),sx:{p:0,mr:1}}),x.jsx($.ListItemText,{primary:f(y)})]},y))}),x.jsxs($.TextField,{select:!0,size:"small",label:"Sets the filter",value:h.given,disabled:h.to.length===0,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:h.given===""?`Named ${h.name}, like the dimension`:void 0,onChange:y=>c(v,w=>{w.given=y.target.value}),children:[x.jsx($.MenuItem,{value:"",children:x.jsx("em",{children:"Same name as the dimension"})}),r.map(y=>x.jsx($.MenuItem,{value:y,children:y},y))]})]},h.name))})})}function hf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function bs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function pf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function rs(e,t){const n=pf(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Da(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 gf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const mf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function vf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=me.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Aa=[{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:"On or after 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;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 Ci=e=>xe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function bf(e,t){return e.tiles.map(n=>{const r=(xe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:bs(t.type)!==void 0?{op:bs(t.type)}:{}}})}function yf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Ci(i))return;const o=(i.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?i.filters=a:delete i.filters})}function xf(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function wf(e,t){for(const r of e.tiles){if(!xe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const Bl=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function _f({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:i}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[u,c]=k.useState({kind:"new"}),[d,f]=k.useState(""),[p,h]=k.useState("select"),[v,y]=k.useState(""),[w,g]=k.useState(""),[m,b]=k.useState([]),[_,O]=k.useState(!1),[E,I]=k.useState(!1),T=M=>t.sources.find(U=>U.name===M.source)?.base??M.source;k.useEffect(()=>{if(e)if(I(n!==void 0),n){c({kind:"existing",name:n.name}),f(n.label??"");const M=bf(t,n);b(M);const U=M.filter(ve=>ve.include),de=new Set(U.map(ve=>ve.field));g(de.size===1?U[0].field:n.field??""),O(de.size>1)}else c({kind:"new"}),f(""),h("select"),g(""),y(new Date().toISOString().slice(0,10)),b(t.tiles.map(M=>({include:Ci(M),field:""}))),O(!1)},[e,n,t]);const D=k.useMemo(()=>[...(t.localGivens??[]).map(M=>M.name),...r.map(M=>M.name)],[t,r]),L=k.useMemo(()=>w.trim()?vf(w.trim(),D):"",[w,D]),R=u.kind==="existing"?n??r.find(M=>M.name===u.name):L?{name:L,type:Br({name:L,label:d,kind:p,field:w}).type}:void 0,z=R?.type!==void 0&&!R.type.startsWith("filter<"),K=m.find(M=>M.include)?.op??bs(R?.type),G=(M,U)=>{I(!0),b(de=>de.map((ve,Re)=>Re===M?{...ve,...U}:ve))},X=M=>{I(!0),b(U=>U.map(de=>({...de,op:M})))},Y=M=>{const U=bs(M);b(de=>de.map(({op:ve,...Re})=>U?{...Re,op:U}:Re))},se=M=>{I(!0),c({kind:"existing",name:M.name}),g(M.field??""),Y(M.type)},te=M=>{I(!0),h(M),Y(Br({name:"X",label:d,kind:M,field:w}).type)},A=t.tiles.map(Ci),B=A.filter(Boolean).length,N=m.filter((M,U)=>M.include&&A[U]).length,j=t.tiles.filter((M,U)=>(m[U]?.include??!1)&&A[U]&&xe(M)),q=j.length>0?j:t.tiles.filter((M,U)=>A[U]&&xe(M)),J=k.useMemo(()=>{const M=new Map;let U=!1;for(const de of q){const ve=s?.(de);if(ve){U=!0;for(const Re of ve)M.has(Re.name)||M.set(Re.name,Re)}}return U?[...M.values()]:void 0},[m,t.tiles,s]),ee=(()=>{const M=w.trim();for(const U of j){const de=s?.(U);if(!de||de.some(ve=>ve.name===M))return T(U)}return j[0]?T(j[0]):t.sources[0]?.base})(),H=M=>{I(!0),b(U=>U.map((de,ve)=>({...de,include:M&&A[ve]})))},S=k.useMemo(()=>_?m:m.map(M=>({...M,field:w})),[_,m,w]),P=M=>{for(const U of q){const de=s?.(U)?.find(ve=>ve.name===M.trim());if(de?.type)return de.type}},F=M=>rs(R?.type,M.type),V=(M,U)=>{if(M.trim()==="")return"Pick the field this filter compares.";const de=U?s?.(U):void 0;if(!de)return;const ve=de.find(Re=>Re.name===M.trim());if(!ve)return`Not a field of ${U?T(U):"the tiles' source"}.`;if(ve.type&&!rs(R?.type,ve.type))return`${M.trim()} is ${Da(ve.type)}; this filter compares ${Da(R?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},ie=M=>{if(I(!0),g(M),l||u.kind!=="new")return;const U=P(M),de=Br({name:"X",label:d,kind:p,field:M}).type;U&&!rs(de,U)&&te(gf(U))},Z=M=>{const U=t.tiles[M];return U&&xe(U)?U:void 0},oe=S.map((M,U)=>M.include&&A[U]?V(M.field,Z(U)):void 0),W=oe.every(M=>M===void 0),Q=E?oe:oe.map(()=>{}),ne=E&&!_&&N>0?j.map(M=>V(w,M)).find(Boolean):void 0,re=R!==void 0&&W&&(u.kind==="existing"||w.trim()!==""&&L!==""),ce=()=>{if(!(!R||!re))if(u.kind==="new")i(R.name,S,Br({name:R.name,label:d.trim()||Bl(R.name),kind:p,field:w.trim(),...ee?{source:ee}:{},...v?{dateDefault:v}:{}}));else if(n?.origin==="dashboard"&&n.local){const M=d.trim(),U=M!==(n.local.label??"");i(R.name,S,U?{...n.local,...M?{label:M}:{}}:void 0)}else i(R.name,S)},pe=l&&a.origin==="model";return{editing:l,shown:a,fromModel:pe,source:u,setSource:c,label:d,setLabel:f,kind:p,dateDefault:v,setDateDefault:y,field:w,rows:m,setRows:b,perTile:_,setPerTile:O,newName:L,target:R,valueTyped:z,commonOp:K,setRow:G,setCommonOp:X,pickExisting:se,pickKind:te,bindable:A,bindableCount:B,included:N,commonFields:J,setAll:H,accepts:F,pickField:ie,rowProblems:Q,commonProblem:ne,canApply:re,apply:ce}}function Pa({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:l,autoFocus:u,placeholder:c,sx:d}){const f=k.useMemo(()=>(n??[]).filter(h=>r?.(h)??!0).map(h=>h.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(h=>[h.name,h.type])),[n]);return x.jsx($.Autocomplete,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(h,v)=>t(v),value:e,onChange:(h,v)=>t(typeof v=="string"?v:""),disabled:l,disableClearable:!0,renderOption:(h,v)=>k.createElement("li",{...h,key:v},x.jsx($.Typography,{variant:"body2",sx:{flex:1},children:v}),p.get(v)&&x.jsx($.Typography,{variant:"caption",sx:{opacity:.6},children:p.get(v)?.replace(/_type$/,"")})),renderInput:h=>x.jsx($.TextField,{...h,label:s,placeholder:c,autoFocus:u,error:o,helperText:a,inputProps:{...h.inputProps,"aria-label":i}}),sx:d})}const Ma=e=>e&&xe(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 kf({open:e,document:t,control:n,available:r,fieldsFor:s,onClose:i,onApply:o,onRemove:a}){const{theme:l}=Ke.usePublisherTheme(),{editing:u,shown:c,fromModel:d,source:f,setSource:p,label:h,setLabel:v,kind:y,dateDefault:w,setDateDefault:g,field:m,rows:b,setRows:_,perTile:O,setPerTile:E,newName:I,target:T,valueTyped:D,commonOp:L,setRow:R,setCommonOp:z,pickExisting:K,pickKind:G,bindable:X,bindableCount:Y,included:se,commonFields:te,setAll:A,accepts:B,pickField:N,rowProblems:j,commonProblem:q,canApply:J,apply:ee}=_f({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:o}),H=(S,P,F)=>x.jsx($.TextField,{select:!0,size:"small",label:"Compares",value:S??">=",onChange:V=>P(V.target.value),inputProps:{"aria-label":F},sx:{width:130},children:mf.filter(V=>V.op!=="~").map(V=>x.jsx($.MenuItem,{value:V.op,children:V.label},V.op))});return x.jsx(C.AppDialog,{open:e,onClose:i,title:u?c.label??c.name:"Add a filter",description:u?x.jsxs(x.Fragment,{children:[x.jsxs($.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 filter on the page, and the tiles it filters.",actions:x.jsxs(x.Fragment,{children:[u&&x.jsx($.Button,{color:"error",startIcon:x.jsx(C.DeleteOutlineIcon,{}),onClick:()=>a(c.name),sx:S=>({mr:"auto",color:C.dangerTextColor(S)}),children:"Remove filter"}),x.jsx($.Button,{onClick:i,children:"Cancel"}),x.jsx($.Tooltip,{title:J||T===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:x.jsx("span",{children:x.jsx($.Button,{variant:"contained",onClick:ee,disabled:!J,children:u?"Apply":"Add filter"})})})]}),children:x.jsxs($.Stack,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&x.jsxs($.ToggleButtonGroup,{exclusive:!0,size:"small",value:f.kind,onChange:(S,P)=>{P==="new"?p({kind:"new"}):P==="existing"&&r[0]&&K(r[0])},"aria-label":"Where the filter comes from",children:[x.jsx($.ToggleButton,{value:"new",children:"New in this dashboard"}),x.jsx($.ToggleButton,{value:"existing",children:"From the model"})]}),!u&&f.kind==="existing"?x.jsx($.TextField,{select:!0,size:"small",label:"Filter",value:f.name,onChange:S=>{const P=r.find(F=>F.name===S.target.value);P&&K(P)},children:r.map(S=>x.jsxs($.MenuItem,{value:S.name,children:[S.label??S.name,x.jsxs($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",S.name]})]},S.name))}):null,x.jsxs($.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!O&&x.jsx(Pa,{value:m,onChange:N,fields:te,accepts:B,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:q!==void 0,helperText:q??(!u&&I?`Declared as $${I}`:void 0),sx:{flex:1,minWidth:200}}),!d&&x.jsx($.TextField,{size:"small",label:"Label",placeholder:I?Bl(I):"",value:h,onChange:S=>v(S.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),D&&!O&&H(L,z,"Comparison")]}),!u&&f.kind==="new"&&x.jsxs($.Stack,{direction:"row",sx:{gap:1.5},children:[x.jsx($.TextField,{select:!0,size:"small",label:"Filter kind",value:y,onChange:S=>G(S.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:S=>Aa.find(P=>P.kind===S)?.label??String(S)}},sx:{flex:1},children:Aa.map(S=>x.jsxs($.MenuItem,{value:S.kind,children:[S.label,x.jsx($.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:S.hint})]},S.kind))}),y==="date"&&x.jsx($.TextField,{size:"small",type:"date",label:"Starts at",value:w,onChange:S=>g(S.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),x.jsxs($.Box,{children:[x.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[x.jsx($.Checkbox,{size:"small",checked:Y>0&&se===Y,indeterminate:se>0&&se<Y,disabled:Y===0,onChange:S=>A(S.target.checked),inputProps:{"aria-label":"All tiles"}}),x.jsxs($.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",se," of ",t.tiles.length," tiles"]}),x.jsx($.Button,{size:"small",onClick:()=>{O||_(S=>S.map(P=>({...P,field:m}))),E(S=>!S)},children:O?"Same field for all":"Adjust per tile"})]}),x.jsx($.Stack,{sx:{gap:O?1:0},children:t.tiles.map((S,P)=>{if(!xe(S))return null;const F=b[P],V=S.label??S.name,ie=O?j[P]:void 0;return x.jsxs($.Stack,{direction:"row",sx:{gap:1,alignItems:O?"flex-start":"center",opacity:X[P]?1:.6},children:[x.jsx($.Checkbox,{size:"small",disabled:!X[P],checked:(F?.include??!1)&&X[P],inputProps:{"aria-label":`Filter ${V}`},onChange:Z=>R(P,{include:Z.target.checked})}),x.jsx($.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:O?1:0},noWrap:!0,children:V}),X[P]?O&&x.jsxs(x.Fragment,{children:[D&&H(F?.op,Z=>R(P,{op:Z}),`Comparison for ${V}`),x.jsx(Pa,{value:F?.field??"",onChange:Z=>R(P,{field:Z}),fields:s?.(S),accepts:B,label:"Field",ariaLabel:`Field for ${V}`,disabled:!F?.include,error:ie!==void 0,helperText:ie,sx:{width:220}})]}):x.jsx($.Tooltip,{title:Ma(t.tiles[P]).reason,children:x.jsx($.Typography,{variant:"caption",sx:{color:l.tileTitle},children:Ma(t.tiles[P]).label})})]},`${S.source}.${S.name}`)})}),se===0&&x.jsx($.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."})]})]})})}const Sf=C.createSvgIcon(x.jsx("path",{d:"M11.71 17.99C8.53 17.84 6 15.22 6 12c0-3.31 2.69-6 6-6 3.22 0 5.84 2.53 5.99 5.71l-2.1-.63C15.48 9.31 13.89 8 12 8c-2.21 0-4 1.79-4 4 0 1.89 1.31 3.48 3.08 3.89zM22 12c0 .3-.01.6-.04.9l-1.97-.59c.01-.1.01-.21.01-.31 0-4.42-3.58-8-8-8s-8 3.58-8 8 3.58 8 8 8c.1 0 .21 0 .31-.01l.59 1.97c-.3.03-.6.04-.9.04-5.52 0-10-4.48-10-10S6.48 2 12 2s10 4.48 10 10m-3.77 4.26L22 15l-10-3 3 10 1.26-3.77 4.27 4.27 1.98-1.98z"}));function Gl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:c=>i(d=>{if(d===void 0)return d;const f=structuredClone(d);return c(f),f}),apply:c=>{if(s===void 0)return;const d=structuredClone(s);c(d),i(d),JSON.stringify(d)!==JSON.stringify(e)&&n(d)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const $f=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,Tf="This tile's view is declared on its source, so its chart is set in the model.";function Of({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:s,removeBlocked:i,onDrills:o,view:a}){const l=k.useId(),{theme:u}=Ke.usePublisherTheme(),{draft:c,apply:d,close:f,discard:p}=Gl(t,e!==null,r,n),h=c!==void 0&&xe(c)?c:void 0,v=h!==void 0&&h.declaration.kind!=="inherited",y=m=>d(b=>{xe(b)&&m(b)}),w=k.useRef(void 0),g=e!==null;return k.useEffect(()=>{g&&(w.current=t&&xe(t)?t.chart:void 0)},[g]),x.jsx($.Popover,{open:e!==null&&c!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:c&&x.jsxs($.Stack,{sx:{gap:1.5},children:[x.jsx($.Typography,{variant:"overline",sx:{color:u.tileTitle,lineHeight:1.5},children:h?`${h.source} → ${h.name}`:`Text · ${c.name}`}),h&&v&&x.jsx(x.Fragment,{children:x.jsx(Ei,{state:h.chart??"default",view:a,cellLabel:`${h.source} ${h.name}`,...h.chart==="custom"?{disabledReason:$f(h.chartLines)}:{},onChange:m=>y(b=>{const _=w.current;m===(_??"default")?(_===void 0?delete b.chart:b.chart=_,delete b.chartCarried):(b.chart=m,a?b.chartCarried=a.chart?[a.chart]:[]:delete b.chartCarried)})})}),h&&!v&&x.jsxs(x.Fragment,{children:[x.jsx($.Typography,{variant:"body2",sx:{color:u.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),x.jsx(Ei,{state:"default",view:a,cellLabel:`${h.source} ${h.name}`,disabledReason:Tf,onChange:()=>{}})]}),h?.declaration.kind==="opaque"&&x.jsxs($.Typography,{variant:"body2",sx:{color:u.tileTitle},children:["Its body is ",h.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),x.jsxs($.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[v?x.jsx($.Button,{size:"small",startIcon:x.jsx(Sf,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):x.jsx("span",{}),x.jsx($.Button,{color:"error",size:"small",startIcon:x.jsx(C.DeleteOutlineIcon,{}),"aria-disabled":i!==void 0||void 0,"aria-describedby":i!==void 0?l:void 0,disableRipple:i!==void 0,sx:m=>({color:C.dangerTextColor(m),...i!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{i===void 0&&(p(),s())},children:"Delete"})]}),i!==void 0&&x.jsx($.Typography,{id:l,variant:"caption",sx:{color:u.tileTitle},children:i})]})})}function Ef({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,confirmConversion:l,exitDialog:u}){const{filterDialog:c,setFilterDialog:d}=s,{menu:f,setMenu:p}=i,h=f===void 0?void 0:e.document.tiles[f.index],v=h&&xe(h)?h:void 0,y=(()=>{if(!v||!t)return;const w=e.document.sources.find(m=>m.name===v.source)?.base??v.source,g=v.declaration.kind==="reference"?v.declaration.from:v.name;return t.sources.find(m=>m.name===w)?.views.find(m=>m.name===g)})();return x.jsxs(x.Fragment,{children:[x.jsx(kf,{open:c!==void 0,document:e.document,...c?.control?{control:c.control}:{},available:s.available,...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>d(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),x.jsx(Of,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>p(void 0),onCommit:w=>{const g=f?.index;g!==void 0&&e.update(m=>{m.tiles[g]=w})},onRemove:()=>{f!==void 0&&i.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved dashboard needs at least one tile."}:{},view:y,onDrills:()=>{a(v?.source)}}),x.jsx(ff,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:s.controlList.map(w=>w.name),dashboards:r??[],onClose:()=>a(void 0),onApply:w=>e.update(g=>{const b=[...(g.drills??[]).filter(_=>_.source!==o),...w];b.length===0?delete g.drills:g.drills=b})}),x.jsx(C.AppDialog,{open:l!==void 0,onClose:()=>l?.stop(),title:"Convert this notebook?",description:"Saving rewrites this notebook in the tile layout. The builder cannot take that back; the file's history in your repository can.",actions:x.jsxs(x.Fragment,{children:[x.jsx($.Button,{onClick:()=>l?.stop(),children:"Cancel"}),x.jsx($.Button,{variant:"contained",onClick:()=>l?.go(),children:"Convert and save"})]}),children:null}),x.jsx(C.UnsavedChangesDialog,{...u}),x.jsx(uf,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText})]})}var Cf=Symbol.for("preact-signals");function zs(){if(yt>1)yt--;else{var e,t=!1;for((function(){var s=xs;for(xs=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();lr!==void 0;){var n=lr;for(lr=void 0,ys++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Kl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ys=0,yt--,t)throw e}}function Te(e){if(yt>0)return e();Ii=++If,yt++;try{return e()}finally{zs()}}var ar,we=void 0;function ue(e){var t=we,n=ar;we=void 0,ar=void 0;try{return e()}finally{we=t,ar=n}}var lr=void 0,yt=0,ys=0,If=0,Ii=0,xs=void 0,ws=0;function ql(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.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=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function Ue(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}Ue.prototype.brand=Cf;Ue.prototype.h=function(){return!0};Ue.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:ue(function(){var r;(r=t.W)==null||r.call(t)}))};Ue.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&&ue(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ue.prototype.subscribe=function(e){var t=this;return st(function(){var n=t.value;ue(function(){return e(n)})},{name:"sub"})};Ue.prototype.valueOf=function(){return this.value};Ue.prototype.toString=function(){return this.value+""};Ue.prototype.toJSON=function(){return this.value};Ue.prototype.peek=function(){var e=this;return ue(function(){return e.value})};Object.defineProperty(Ue.prototype,"value",{get:function(){var e=ql(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ys>100)throw new Error("Cycle detected");(function(n){yt!==0&&ys===0&&n.l!==Ii&&(n.l=Ii,xs={S:n,v:n.v,i:n.i,o:xs})})(this),this.v=e,this.i++,ws++,yt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{zs()}}}});function Tn(e,t){return new Ue(e,t)}function Kl(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 Ul(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 Vl(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 Xt(e,t){Ue.call(this,void 0,t),this.x=e,this.s=void 0,this.g=ws-1,this.f=4}Xt.prototype=new Ue;Xt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ws))return!0;if(this.g=ws,this.f|=1,this.i>0&&!Kl(this))return this.f&=-2,!0;var e=we;try{Ul(this),we=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 we=e,Vl(this),this.f&=-2,!0};Xt.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)}Ue.prototype.S.call(this,e)};Xt.prototype.U=function(e){if(this.t!==void 0&&(Ue.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)}};Xt.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(Xt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=ql(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ja(e,t){return new Xt(e,t)}function Hl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){yt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,yo(e),r}finally{we=n,zs()}}}function yo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Hl(e)}function Df(e){if(we!==this)throw new Error("Out-of-order effect");Vl(this),we=e,this.f&=-2,8&this.f&&yo(this),zs()}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,ar&&ar.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,Hl(this),Ul(this),yt++;var e=we;return we=this,Df.bind(this,e)};On.prototype.N=function(){2&this.f||(this.f|=2,this.u=lr,lr=this)};On.prototype.d=function(){this.f|=8,1&this.f||yo(this)};On.prototype.dispose=function(){this.d()};function st(e,t){var n=new On(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Af=Object.create,xo=Object.defineProperty,Pf=Object.defineProperties,Mf=Object.getOwnPropertyDescriptor,jf=Object.getOwnPropertyDescriptors,Ra=Object.getOwnPropertySymbols,Rf=Object.prototype.hasOwnProperty,Lf=Object.prototype.propertyIsEnumerable,Nf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),En=e=>{throw TypeError(e)},Di=(e,t,n)=>t in e?xo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ff=(e,t)=>{for(var n in t||(t={}))Rf.call(t,n)&&Di(e,n,t[n]);if(Ra)for(var n of Ra(t))Lf.call(t,n)&&Di(e,n,t[n]);return e},zf=(e,t)=>Pf(e,jf(t)),La=(e,t)=>xo(e,"name",{value:t,configurable:!0}),Wf=e=>{var t;return[,,,Af((t=void 0)!=null?t:null)]},Xl=["class","method","getter","setter","accessor","field","value","get","set"],Kn=e=>e!==void 0&&typeof e!="function"?En("Function expected"):e,Bf=(e,t,n,r,s)=>({kind:Xl[e],name:t,metadata:r,addInitializer:i=>n._?En("Already initialized"):s.push(Kn(i||null))}),Yl=(e,t)=>Di(t,Nf("metadata"),e[3]),jt=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},Cn=(e,t,n,r,s,i)=>{var o,a,l,u,c,d=t&7,f=!!(t&8),p=!!(t&16),h=d>3?e.length+1:d?f?1:2:0,v=Xl[d+5],y=d>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),g=d&&(!p&&!f&&(s=s.prototype),d<5&&(d>3||!p)&&Mf(d<4?s:{get[n](){return Je(this,i)},set[n](b){return Ot(this,i,b)}},n));d?p&&d<4&&La(i,(d>2?"set ":d>1?"get ":"")+n):La(s,n);for(var m=r.length-1;m>=0;m--)u=Bf(d,n,l={},e[3],w),d&&(u.static=f,u.private=p,c=u.access={has:p?b=>Gf(s,b):b=>n in b},d^3&&(c.get=p?b=>(d^1?Je:qf)(b,s,d^4?i:g.get):b=>b[n]),d>2&&(c.set=p?(b,_)=>Ot(b,s,_,d^4?i:g.set):(b,_)=>b[n]=_)),a=(0,r[m])(d?d<4?p?i:g[v]:d>4?void 0:{get:g.get,set:g.set}:s,u),l._=1,d^4||a===void 0?Kn(a)&&(d>4?y.unshift(a):d?p?i=a:g[v]=a:s=a):typeof a!="object"||a===null?En("Object expected"):(Kn(o=a.get)&&(g.get=o),Kn(o=a.set)&&(g.set=o),Kn(o=a.init)&&y.unshift(o));return d||Yl(e,s),g&&xo(s,n,g),p?d^4?i:g:s},wo=(e,t,n)=>t.has(e)||En("Cannot "+n),Gf=(e,t)=>Object(t)!==t?En('Cannot use the "in" operator on this value'):e.has(t),Je=(e,t,n)=>(wo(e,t,"read from private field"),n?n.call(e):t.get(e)),Un=(e,t,n)=>t.has(e)?En("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ot=(e,t,n,r)=>(wo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),qf=(e,t,n)=>(wo(e,t,"access private method"),n);function Ai(e,t){if(t){let n;return ja(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return ja(e)}function ot(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,s)=>!ot(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!ot(e[i],t[i]))}return!1}function fe({get:e},t){return{init(n){return Tn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ee(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ai(e.bind(this)),n.set(this,r)),r.value}}function ii(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,zf(Ff({},s),{enumerable:e}))})}}function Er(...e){const t=e.map(n=>st(n));return()=>t.forEach(n=>n())}var Zl,Ql,Jl,ec,tc,nc,Be,_o,oi,Pi,Mi,ze,ko,ai,rc,ji,So,li,Ri,Li;nc=[fe],tc=[fe],ec=[fe],Jl=[ii()],Ql=[ii()],Zl=[ii()];var Yt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,jt(Be,5,this),Un(this,ze),Un(this,_o,jt(Be,8,this)),jt(Be,11,this),Un(this,ko,jt(Be,12,this)),jt(Be,15,this),Un(this,So,jt(Be,16,this)),jt(Be,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Je(this,ze,Ri)}get initial(){return Je(this,ze,Pi)}get previous(){return Je(this,ze,rc)}set current(e){const t=ue(()=>Je(this,ze,Ri));e&&t&&this.equals(t,e)||Te(()=>{Je(this,ze,Pi)||Ot(this,ze,e,Mi),Ot(this,ze,t,ji),Ot(this,ze,e,Li)})}reset(e=this.defaultValue){Te(()=>{Ot(this,ze,void 0,ji),Ot(this,ze,e,Mi),Ot(this,ze,e,Li)})}};Be=Wf();_o=new WeakMap;ze=new WeakSet;ko=new WeakMap;So=new WeakMap;oi=Cn(Be,20,"#initial",nc,ze,_o),Pi=oi.get,Mi=oi.set;ai=Cn(Be,20,"#previous",tc,ze,ko),rc=ai.get,ji=ai.set;li=Cn(Be,20,"#current",ec,ze,So),Ri=li.get,Li=li.set;Cn(Be,2,"current",Jl,Yt);Cn(Be,2,"initial",Ql,Yt);Cn(Be,2,"previous",Zl,Yt);Yl(Be,Yt);function ci(e){return ue(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Rt,Kf=class{constructor(){Un(this,Rt,new WeakMap)}get(e,t){var n;return e?(n=Je(this,Rt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Je(this,Rt).has(e)||Je(this,Rt).set(e,new Map),(r=Je(this,Rt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Je(this,Rt).get(e))==null?void 0:t.clear():void 0}};Rt=new WeakMap;var Uf=Object.create,sc=Object.defineProperty,Vf=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertySymbols,Hf=Object.prototype.hasOwnProperty,Xf=Object.prototype.propertyIsEnumerable,ic=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ws=e=>{throw TypeError(e)},Fa=Math.pow,Ni=(e,t,n)=>t in e?sc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yf=(e,t)=>{for(var n in t||(t={}))Hf.call(t,n)&&Ni(e,n,t[n]);if(Na)for(var n of Na(t))Xf.call(t,n)&&Ni(e,n,t[n]);return e},Zf=e=>{var t;return[,,,Uf((t=e?.[ic("metadata")])!=null?t:null)]},oc=["class","method","getter","setter","accessor","field","value","get","set"],ac=e=>e!==void 0&&typeof e!="function"?Ws("Function expected"):e,Qf=(e,t,n,r,s)=>({kind:oc[e],name:t,metadata:r,addInitializer:i=>n._?Ws("Already initialized"):s.push(ac(i||null))}),Jf=(e,t)=>Ni(t,ic("metadata"),e[3]),eh=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},lc=(e,t,n,r,s,i)=>{for(var o,a,l,u,c=t&7,d=!1,f=!1,p=2,h=oc[c+5],v=e[p]||(e[p]=[]),y=(s=s.prototype,Vf(s,n)),w=r.length-1;w>=0;w--)l=Qf(c,n,a={},e[3],v),l.static=d,l.private=f,u=l.access={has:g=>n in g},u.get=g=>g[n],o=(0,r[w])(y[h],l),a._=1,ac(o)&&(y[h]=o);return y&&sc(s,n,y),s},cc=(e,t,n)=>t.has(e)||Ws("Cannot "+n),th=(e,t,n)=>(cc(e,t,"read from private field"),t.get(e)),nh=(e,t,n)=>t.has(e)?Ws("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rh=(e,t,n,r)=>(cc(e,t,"write to private field"),t.set(e,n),n),et=class Fi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Fi(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 Fi(t,n)}},ft=class Lt{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,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:s,width:i,height:o,scale:a}=this,l=new Lt(s+t,r+n,i,o);return l.scale=Yf({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new et((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Lt))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Lt?sh(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:s}){return new Lt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],l=o==="x"?i.left:i.top,u=o==="x"?i.width:i.height;return a=="start"?l:a=="end"?l+u:l+u/2};return et.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Lt.from(t).intersectionRatio(Lt.from(n))}};function sh(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var dc,uc,zi,ss,Cr,Bs=class extends(zi=Yt,uc=[Ee],dc=[Ee],zi){constructor(t){const n=et.from(t);super(n,(r,s)=>et.equals(r,s)),eh(Cr,5,this),nh(this,ss,0),this.velocity={x:0,y:0}}get delta(){return et.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=et.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-th(this,ss),a=l=>Math.round(l/o*100);Te(()=>{rh(this,ss,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(et.from(t)),this.velocity={x:0,y:0}}};Cr=Zf(zi);ss=new WeakMap;lc(Cr,2,"delta",uc,Bs);lc(Cr,2,"direction",dc,Bs);Jf(Cr,Bs);function Wi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(Fa(r,2)+Fa(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var fc=(e=>(e.Horizontal="x",e.Vertical="y",e))(fc||{}),hc=Object.values(fc),ih=Object.create,$o=Object.defineProperty,oh=Object.defineProperties,ah=Object.getOwnPropertyDescriptor,lh=Object.getOwnPropertyDescriptors,_s=Object.getOwnPropertySymbols,pc=Object.prototype.hasOwnProperty,gc=Object.prototype.propertyIsEnumerable,mc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),In=e=>{throw TypeError(e)},Bi=(e,t,n)=>t in e?$o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,To=(e,t)=>{for(var n in t||(t={}))pc.call(t,n)&&Bi(e,n,t[n]);if(_s)for(var n of _s(t))gc.call(t,n)&&Bi(e,n,t[n]);return e},Oo=(e,t)=>oh(e,lh(t)),za=(e,t)=>$o(e,"name",{value:t,configurable:!0}),vc=(e,t)=>{var n={};for(var r in e)pc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_s)for(var r of _s(e))t.indexOf(r)<0&&gc.call(e,r)&&(n[r]=e[r]);return n},Dn=e=>{var t;return[,,,ih((t=e?.[mc("metadata")])!=null?t:null)]},bc=["class","method","getter","setter","accessor","field","value","get","set"],Vn=e=>e!==void 0&&typeof e!="function"?In("Function expected"):e,ch=(e,t,n,r,s)=>({kind:bc[e],name:t,metadata:r,addInitializer:i=>n._?In("Already initialized"):s.push(Vn(i||null))}),Zt=(e,t)=>Bi(t,mc("metadata"),e[3]),le=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},he=(e,t,n,r,s,i)=>{var o,a,l,u,c,d=t&7,f=!!(t&8),p=!!(t&16),h=d>3?e.length+1:d?f?1:2:0,v=bc[d+5],y=d>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),g=d&&(!p&&!f&&(s=s.prototype),d<5&&(d>3||!p)&&ah(d<4?s:{get[n](){return Oe(this,i)},set[n](b){return Ze(this,i,b)}},n));d?p&&d<4&&za(i,(d>2?"set ":d>1?"get ":"")+n):za(s,n);for(var m=r.length-1;m>=0;m--)u=ch(d,n,l={},e[3],w),d&&(u.static=f,u.private=p,c=u.access={has:p?b=>dh(s,b):b=>n in b},d^3&&(c.get=p?b=>(d^1?Oe:yc)(b,s,d^4?i:g.get):b=>b[n]),d>2&&(c.set=p?(b,_)=>Ze(b,s,_,d^4?i:g.set):(b,_)=>b[n]=_)),a=(0,r[m])(d?d<4?p?i:g[v]:d>4?void 0:{get:g.get,set:g.set}:s,u),l._=1,d^4||a===void 0?Vn(a)&&(d>4?y.unshift(a):d?p?i=a:g[v]=a:s=a):typeof a!="object"||a===null?In("Object expected"):(Vn(o=a.get)&&(g.get=o),Vn(o=a.set)&&(g.set=o),Vn(o=a.init)&&y.unshift(o));return d||Zt(e,s),g&&$o(s,n,g),p?d^4?i:g:s},Eo=(e,t,n)=>t.has(e)||In("Cannot "+n),dh=(e,t)=>Object(t)!==t?In('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Eo(e,t,"read from private field"),n?n.call(e):t.get(e)),ge=(e,t,n)=>t.has(e)?In("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ze=(e,t,n,r)=>(Eo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),yc=(e,t,n)=>(Eo(e,t,"access private method"),n);function xc(e,t){return{plugin:e,options:t}}function Ir(e){return t=>xc(e,t)}function pr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var wc,gr,Co,is;wc=[fe];var We=class{constructor(e,t){this.manager=e,this.options=t,ge(this,Co,le(gr,8,this,!1)),le(gr,11,this),ge(this,is,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ue(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=st(e.bind(this));return Oe(this,is).add(t),t}destroy(){Oe(this,is).forEach(e=>e())}static configure(e){return xc(this,e)}};gr=Dn(null);Co=new WeakMap;is=new WeakMap;he(gr,4,"disabled",wc,We,Co);Zt(gr,We);var Dr=class extends We{},os,di=class{constructor(e){this.manager=e,this.instances=new Map,ge(this,os,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(pr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,os))if(!n.includes(r)){if(r.prototype instanceof Dr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);Ze(this,os,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()}};os=new WeakMap;function uh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Gr=[],an,ln,fh=class extends We{constructor(e){super(e),ge(this,an),ge(this,ln),this.computeCollisions=this.computeCollisions.bind(this),Ze(this,ln,Tn(Gr)),this.destroy=Er(()=>{const t=this.computeCollisions(),n=ue(()=>this.manager.dragOperation.position.current);if(t!==Gr){const r=Oe(this,an);if(Ze(this,an,n),r&&n.x==r.x&&n.y==r.y)return}else Ze(this,an,void 0);Oe(this,ln).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ue(()=>{e?Oe(this,ln).value=this.computeCollisions():Ze(this,an,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Gr;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||s&&!u.accepts(s))continue;const c=t??u.collisionDetector;if(!c)continue;l.push(u),u.shape;const d=ue(()=>c({droppable:u,dragOperation:r}));d&&(u.collisionPriority!=null&&(d.priority=u.collisionPriority),a.push(d))}return l.length===0?Gr:(a.sort(uh),a)}get collisions(){return Oe(this,ln).value}};an=new WeakMap;ln=new WeakMap;var _c,kc,Sc,Io,$c,at,Do,pn,Ao,Po;Sc=[fe],kc=[fe],_c=[fe];var wt=class Nt{constructor(t,n){ge(this,Do,le(at,8,this)),le(at,11,this),ge(this,pn),ge(this,Ao,le(at,12,this)),le(at,15,this),ge(this,Po,le(at,16,this)),le(at,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let l=s;Ze(this,pn,Tn(s)),this.manager=n,this.data=i,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=Oe(this,pn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,pn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return yc(i=Nt,Io,$c).call(i)})),Nt.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)}};at=Dn(null);Io=new WeakSet;$c=function(){const e=wt.pendingIdChanges;wt.pendingIdChanges=null,e&&Te(()=>{for(const[t,n]of e)Oe(t,pn).value=n})};Do=new WeakMap;pn=new WeakMap;Ao=new WeakMap;Po=new WeakMap;he(at,4,"manager",Sc,wt,Do);he(at,4,"data",kc,wt,Ao);he(at,4,"disabled",_c,wt,Po);ge(wt,Io);Zt(at,wt);wt.pendingIdChanges=null;var Gs=wt,Wa=class{constructor(){this.map=Tn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Er(...t.effects());return this.cleanupFunctions.set(t,o),s},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 s=new Map(n);s.delete(e),this.map.value=s}}[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}},Tc,Oc,Ec,Cc,Ic,Dc,Gi,Ge,Mo,jo,Ro,ht=class extends(Gi=Gs,Dc=[fe],Ic=[fe],Cc=[fe],Ec=[Ee],Oc=[Ee],Tc=[Ee],Gi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:l}=r,u=vc(r,["modifiers","type","sensors","plugins","effects"]);super(Oo(To({},u),{effects:()=>{var c;return[...(c=l?.())!=null?c:[],()=>{const{manager:d,plugins:f}=this;if(!(!d||!f))for(const p of f){const{plugin:h}=pr(p);d.registry.plugins.register(h)}}]}}),n),le(Ge,5,this),ge(this,Mo,le(Ge,8,this)),le(Ge,11,this),ge(this,jo,le(Ge,12,this)),le(Ge,15,this),ge(this,Ro,le(Ge,16,this,this.isDragSource?"dragging":"idle")),le(Ge,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=pr(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}};Ge=Dn(Gi);Mo=new WeakMap;jo=new WeakMap;Ro=new WeakMap;he(Ge,4,"type",Dc,ht,Mo);he(Ge,4,"modifiers",Ic,ht,jo);he(Ge,4,"status",Cc,ht,Ro);he(Ge,2,"isDropping",Ec,ht);he(Ge,2,"isDragging",Oc,ht);he(Ge,2,"isDragSource",Tc,ht);Zt(Ge,ht);var Ac,Pc,Mc,jc,Rc,Lc,qi,Pe,Lo,No,Fo,zo,Wo,pt=class extends(qi=Gs,Lc=[fe],Rc=[fe],jc=[fe],Mc=[fe],Pc=[fe],Ac=[Ee],qi){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,l=vc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),le(Pe,5,this),ge(this,Lo,le(Pe,8,this)),le(Pe,11,this),ge(this,No,le(Pe,12,this)),le(Pe,15,this),ge(this,Fo,le(Pe,16,this)),le(Pe,19,this),ge(this,zo,le(Pe,20,this)),le(Pe,23,this),ge(this,Wo,le(Pe,24,this)),le(Pe,27,this),this.accept=s,this.collisionDetector=i,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}};Pe=Dn(qi);Lo=new WeakMap;No=new WeakMap;Fo=new WeakMap;zo=new WeakMap;Wo=new WeakMap;he(Pe,4,"accept",Lc,pt,Lo);he(Pe,4,"type",Rc,pt,No);he(Pe,4,"collisionDetector",jc,pt,Fo);he(Pe,4,"collisionPriority",Mc,pt,zo);he(Pe,4,"shape",Pc,pt,Wo);he(Pe,2,"isDropTarget",Ac,pt);Zt(Pe,pt);var hh=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 s of r)s(...t)}},ph=class extends hh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function as(e,t=!0){let n=!1;return Oo(To({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var gh=class extends Dr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Er(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Gs.pendingIdChanges)return;const o=as({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;ue(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},An=(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))(An||{}),Pn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Pn||{}),Nc,Fc,zc,Wc,Bc,Gc,qc,rt,Bo;qc=[fe],Gc=[Ee],Bc=[Ee],Wc=[Ee],zc=[Ee],Fc=[Ee],Nc=[Ee];var kt=class{constructor(){le(rt,5,this),ge(this,Bo,le(rt,8,this,"idle")),le(rt,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}};rt=Dn(null);Bo=new WeakMap;he(rt,4,"value",qc,kt,Bo);he(rt,2,"current",Gc,kt);he(rt,2,"idle",Bc,kt);he(rt,2,"initializing",Wc,kt);he(rt,2,"initialized",zc,kt);he(rt,2,"dragging",Fc,kt);he(rt,2,"dropped",Nc,kt);Zt(rt,kt);var mh=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 ue(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=as({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ue(()=>{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:s,coordinates:i}=e;Te(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=as({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"&&Te(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ue(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=as({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 f=(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=f})})}stop(e={}){return ue(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const l={resume:()=>{},abort:()=>{}};return i=new Promise((u,c)=>{l.resume=u,l.abort=c}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=ue(()=>{var c;return((c=r.source)==null?void 0:c.status)==="dropping"}),u=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:c}=r,d=st(()=>{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}),i?i.then(a).catch(()=>r.reset()):a()})}},xn=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}},vh=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)}},ls,Kc=class{constructor(e){this.options=e,ge(this,ls)}set controller(e){Ze(this,ls,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,ls))==null||t.activate(e)}};ls=new WeakMap;var Ba=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},bh=class{constructor(e){this.draggables=new Wa,this.droppables=new Wa,this.plugins=new di(e),this.sensors=new di(e),this.modifiers=new di(e)}register(e,t){if(e instanceof ht)return this.draggables.register(e.id,e);if(e instanceof pt)return this.droppables.register(e.id,e);if(e.prototype instanceof Ba)return this.modifiers.register(e,t);if(e.prototype instanceof xn)return this.sensors.register(e,t);if(e.prototype instanceof We)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Gs)return e instanceof ht?this.draggables.unregister(e.id,e):e instanceof pt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Ba)return this.modifiers.unregister(e);if(e.prototype instanceof xn)return this.sensors.unregister(e);if(e.prototype instanceof We)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()}},Uc,Vc,Hc,Xc,Yc,Zc,Qc,Jc,ed,Hn,cs,cn,$e,Go,qo,Ko,Uo,Vo,Xn;ed=[Ee],Jc=[fe],Qc=[fe],Zc=[fe],Yc=[fe],Xc=[fe],Hc=[Ee],Vc=[Ee],Uc=[Ee];var ct=class{constructor(e){le($e,5,this),ge(this,Hn),ge(this,cs),ge(this,cn,new Yt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new kt,ge(this,Go,le($e,8,this,!1)),le($e,11,this),ge(this,qo,le($e,12,this,null)),le($e,15,this),ge(this,Ko,le($e,16,this,null)),le($e,19,this),ge(this,Uo,le($e,20,this,null)),le($e,23,this),ge(this,Vo,le($e,24,this,[])),le($e,27,this),this.position=new Bs({x:0,y:0}),ge(this,Xn,{x:0,y:0}),Ze(this,Hn,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,cn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,cn).current=e:Oe(this,cn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,Hn).registry.draggables.get(t);return n&&Ze(this,cs,n),(e=n??Oe(this,cs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,Hn).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(Oo(To({},this.snapshot()),{transform:n}));return Ze(this,Xn,n),n}snapshot(){return ue(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,Xn),shape:this.shape?ci(this.shape):null,position:ci(this.position),status:ci(this.status),canceled:this.canceled}))}reset(){Te(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,cn).reset(),this.position.reset({x:0,y:0}),Ze(this,Xn,{x:0,y:0}),this.modifiers=[]})}};$e=Dn(null);Hn=new WeakMap;cs=new WeakMap;cn=new WeakMap;Go=new WeakMap;qo=new WeakMap;Ko=new WeakMap;Uo=new WeakMap;Vo=new WeakMap;Xn=new WeakMap;he($e,2,"shape",ed,ct);he($e,4,"canceled",Jc,ct,Go);he($e,4,"activatorEvent",Qc,ct,qo);he($e,4,"sourceIdentifier",Zc,ct,Ko);he($e,4,"targetIdentifier",Yc,ct,Uo);he($e,4,"modifiers",Xc,ct,Vo);he($e,2,"source",Hc,ct);he($e,2,"target",Vc,ct);he($e,2,"transform",Uc,ct);Zt($e,ct);var yh={get rendering(){return Promise.resolve()}};function lt(e,t){return typeof e=="function"?e(t):e??t}var xh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=lt(r.plugins,[]),i=lt(r.sensors,[]),o=lt(r.modifiers,[]),a=(n=r.renderer)!=null?n:yh,l=new ph(this),u=new bh(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new mh(this),this.dragOperation=new ct(this),this.collisionObserver=new fh(this),this.plugins=[gh,...s],this.modifiers=o,this.sensors=i;const{destroy:c}=this,d=Er(()=>{var f,p,h;const v=ue(()=>this.dragOperation.modifiers),y=this.modifiers;for(const w of v)y.includes(w)||w.destroy();this.dragOperation.modifiers=(h=(p=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:p.map(w=>{const{plugin:g,options:m}=pr(w);return new g(this,m)}))!=null?h:y});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}},td=e=>{throw TypeError(e)},Ho=(e,t,n)=>t.has(e)||td("Cannot "+n),ae=(e,t,n)=>(Ho(e,t,"read from private field"),t.get(e)),Ve=(e,t,n)=>t.has(e)?td("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Ho(e,t,"write to private field"),t.set(e,n),n),nd=(e,t,n)=>(Ho(e,t,"access private method"),n);function qs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function rd(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(qs(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function Ks(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function Xo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Ar(e){return"nodeType"in e}function Qe(e){var t,n,r;return e?Xo(e)?e:Ar(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 Yo(e){const{Document:t}=Qe(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Pt(e){return!e||Xo(e)?!1:e instanceof Qe(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function sd(e){return e instanceof Qe(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Mn(e){return e?Xo(e)?e.document:Ar(e)?Yo(e)?e:Pt(e)||sd(e)?e.ownerDocument:document:document:document}function wh(e){var t,n,r,s;const{documentElement:i}=Mn(e),o=Qe(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,l=(n=o?.height)!=null?n:i.clientHeight,u=(r=o?.offsetTop)!=null?r:0,c=(s=o?.offsetLeft)!=null?s:0;return{top:u,left:c,right:c+a,bottom:u+l,width:a,height:l}}function _h(e,t){if(kh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function kh(e){return e.tagName==="DETAILS"}function mr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,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(!_h(d)){const m=d.getBoundingClientRect(),b=n*(m.bottom-m.top),_=n*(m.right-m.left),O=n*(m.bottom-m.top),E=n*(m.right-m.left);l={top:Math.max(l.top,m.top-b),right:Math.min(l.right,m.right+_),bottom:Math.min(l.bottom,m.bottom+O),left:Math.max(l.left,m.left-E),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const f=c.visualViewport,p=(s=f?.offsetTop)!=null?s:0,h=(i=f?.offsetLeft)!=null?i:0,v=(o=f?.width)!=null?o:c.innerWidth,y=(a=f?.height)!=null?a:c.innerHeight,w=n*y,g=n*v;return l={top:Math.max(l.top,p-w),right:Math.min(l.right,h+v+g),bottom:Math.min(l.bottom,p+y+w),left:Math.max(l.left,h-g),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 wn(e){return{x:e.clientX,y:e.clientY}}var id=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ki(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 s=r.contentDocument;s&&!t.has(s)&&n.push(...Ki(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Ki(s.document,t))}}catch{}return n}function Zo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function od(){var e,t;const n=Zo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Qo(e){return!e||!Ar(e)?!1:e instanceof Qe(e).ShadowRoot}function ks(e){if(e&&Ar(e)){let t=e.getRootNode();if(Qo(t))return t;if(t instanceof Document)return t}return Mn(e)}function Jo(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Sh(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((i,o)=>{const a=r[o];if(Ga(i)&&Ga(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),qa(i)&&qa(a)&&a.width>0&&a.height>0){const l=i.getContext("2d");l?.drawImage(a,0,0)}}),n}function Ga(e){return"value"in e}function qa(e){return e.tagName==="CANVAS"}function ad(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if($h(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return ad(s,{x:t-i,y:n-o})}}return r}function $h(e){return e?.tagName==="IFRAME"}var Ui=new WeakMap;function Th(e){return e.closest(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),E=require("../useCompiledDocument-tBejqZ7s.cjs.js"),S=require("@mui/material"),k=require("react"),Ke=require("../ServerProvider-Gj-im5VD.cjs.js"),me=require("../text-entry-BJwltZiy.cjs.js"),of=require("react-dom"),af=require("@malloydata/malloy-tag"),lf=require("@tanstack/react-query"),cf={line_chart:"Line",bar_chart:"Bar",big_value:"Big value",scatter_chart:"Scatter",shape_map:"Shape map",segment_map:"Segment map"};function df(e,t,n){const r=e!==void 0?void 0:n==="loading"?"Still loading this view's details":n==="unlisted"?"Not a view the catalog lists, so its shape is unknown":void 0,s=o=>{if(t!==o){if(o==="big_value")return e?.aggregateOnly===!0?void 0:r??"Needs a view with only totals (no group by)";if(o==="shape_map"||o==="segment_map")return e?.chart===o?void 0:r??"Needs a view that already carries a map chart"}};return[{value:"default",label:"From the view"},{value:"none",label:"Table"},...["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"].map(o=>{const a=s(o);return{value:o,label:cf[o],...a?{disabled:!0,reason:a}:{}}}),...t==="custom"?[{value:"custom",label:"As written"}]:[]]}function Ei({state:e,view:t,viewStatus:n,cellLabel:r,disabledReason:s,onOpen:i,onChange:o,variant:a="standard"}){const l=df(t,e,n),u=k.useId();return x.jsx(S.TextField,{select:!0,size:"small",variant:a,label:"Viz type",value:e,disabled:s!==void 0,onChange:d=>{const c=d.target.value;l.find(f=>f.value===c)?.disabled||o(c)},helperText:s,FormHelperTextProps:{id:u},SelectProps:{...i?{onOpen:i}:{},renderValue:d=>l.find(c=>c.value===d)?.label??String(d),MenuProps:{MenuListProps:{disabledItemsFocusable:!0}},SelectDisplayProps:{"aria-label":`Viz type, ${r}`,"aria-labelledby":void 0,...s?{"aria-describedby":u}:{}}},sx:{minWidth:140},children:l.map(d=>x.jsx(S.MenuItem,{value:d.value,disabled:d.value==="custom"||d.disabled===!0,children:x.jsx(S.ListItemText,{primary:d.label,...d.reason?{secondary:d.reason}:{}})},d.value))})}function uf({sources:e,source:t,view:n,onSource:r,onView:s}){const{theme:i}=Ke.usePublisherTheme(),o=e.find(a=>a.name===t);return x.jsxs(x.Fragment,{children:[x.jsx(S.TextField,{select:!0,size:"small",label:"Source",value:t,onChange:a=>r(a.target.value),inputProps:{"aria-label":"Source"},children:e.map(a=>x.jsxs(S.MenuItem,{value:a.name,disabled:a.views.length===0,children:[a.name,a.views.length===0&&x.jsx(S.Typography,{component:"span",variant:"caption",sx:{ml:1},children:"declares no views"}),a.description&&x.jsx(S.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:a.description})]},a.name))}),x.jsxs(S.Box,{children:[x.jsx(S.Typography,{variant:"subtitle2",sx:{mb:.5},children:"View"}),x.jsxs(S.List,{dense:!0,disablePadding:!0,"aria-label":"Views",sx:{maxHeight:"min(280px, 30vh)",overflowY:"auto",border:i.border,borderRadius:1},children:[(o?.views??[]).map(a=>x.jsxs(S.ListItemButton,{selected:n===a.name,onClick:()=>s(a.name),"aria-label":`View ${a.name}`,children:[x.jsx(S.ListItemText,{primary:a.name,secondary:a.description,primaryTypographyProps:{fontFamily:"ui-monospace, monospace",fontSize:13}}),a.chart&&x.jsx(S.Chip,{size:"small",variant:"outlined",label:a.chart.replace(/_chart$/,"")})]},a.name)),o&&o.views.length===0&&x.jsx(S.Typography,{variant:"body2",sx:{p:1.5,color:i.tileTitle},children:"This source declares no views."})]})]})]})}function ff({open:e,document:t,catalog:n,columns:r,onClose:s,onAdd:i,onAddText:o}){const{theme:a}=Ke.usePublisherTheme(),l=k.useMemo(()=>n?.sources??[],[n]),[u,d]=k.useState("query"),[c,f]=k.useState(""),[p,h]=k.useState(""),[m,y]=k.useState(""),[w,v]=k.useState("default"),[g,b]=k.useState(Math.ceil(r/2));k.useEffect(()=>{if(!e)return;d("query");const T=D=>l.some(N=>N.name===D&&N.views.length>0);f(t.sources.map(D=>D.base).find(T)??l.find(D=>D.views.length>0)?.name??""),h(""),y(""),v("default"),b(Math.ceil(r/2))},[e,t,l,r]);const _=c!==""&&p!=="",O=[c,p].filter(T=>T!==""&&!me.isBareName(T)).map(T=>`"${T}" is not a plain Malloy name, so a tile cannot be written for it.`)[0],I=l.find(T=>T.name===c),M=I?.views.find(T=>T.name===p);return x.jsx(E.AppDialog,{open:e,onClose:s,title:"Add a tile",description:"A tile shows one view of a source in this package.",actions:x.jsxs(x.Fragment,{children:[x.jsx(S.Button,{onClick:s,children:"Cancel"}),x.jsx(S.Button,{variant:"contained",disabled:u==="query"&&(!_||O!==void 0),onClick:()=>u==="text"?o():i({base:c,modelPath:I?.modelPath??"",...I?.exporters?{exporters:I.exporters}:{},view:p,...m.trim()?{label:m.trim()}:{},...w!=="default"?{chart:w,...M?{chartCarried:M.chart?[M.chart]:[]}:{}}:{},colspan:g}),children:u==="text"?"Add text":"Add tile"})]}),children:x.jsxs(S.Stack,{sx:{gap:2,pt:1},children:[x.jsxs(S.ToggleButtonGroup,{size:"small",exclusive:!0,value:u,"aria-label":"Tile type",onChange:(T,D)=>{D!==null&&d(D)},children:[x.jsx(S.ToggleButton,{value:"query",sx:{px:1.5},children:"Query"}),x.jsx(S.ToggleButton,{value:"text",sx:{px:1.5},children:"Text"})]}),u==="text"?x.jsx(S.Typography,{variant:"body2",sx:{color:a.tileTitle},children:"A text tile holds markdown: a heading, a paragraph, a list. It is added empty, and written on the tile itself."}):l.length===0?x.jsx(S.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?"This package publishes no source with a view to put on a tile.":"The package's sources are still loading."}):x.jsxs(x.Fragment,{children:[x.jsx(uf,{sources:l,source:c,view:p,onSource:T=>{f(T),h("")},onView:T=>{h(T),v("default")}}),O&&x.jsx(S.Typography,{variant:"body2",color:"error",children:O}),x.jsx(Ei,{state:w,view:M,cellLabel:"new tile",variant:"outlined",...M?{}:{disabledReason:"Pick a view to choose its chart."},onChange:T=>v(T)}),x.jsx(S.Stack,{direction:"row",sx:{gap:1.5},children:x.jsx(S.TextField,{size:"small",label:"Title",placeholder:"Uses the view's name",value:m,onChange:T=>y(T.target.value),inputProps:{"aria-label":"Tile title"},sx:{flex:1}})})]})]})})}const je=e=>e.kind==="text",xe=e=>e.kind!=="text",Wr=e=>xe(e)?e.label??e.name:e.name,Fe=e=>je(e)?`text.${e.name}`:`${e.source}.${e.name}`,si="self";function hf({open:e,document:t,source:n,givenNames:r,dashboards:s,onClose:i,onApply:o}){const{theme:a}=Ke.usePublisherTheme(),[l,u]=k.useState([]);k.useEffect(()=>{if(!e||!n)return;const h=(t.drills??[]).filter(m=>m.source===n.name);u((n.dimensions??[]).map(m=>{const y=h.find(w=>w.name===m.name);return{name:m.name,expression:m.expression,to:y?.to??[],given:y?.given??""}}))},[e,n,t]);const d=(h,m)=>u(y=>y.map((w,v)=>{if(v!==h)return w;const g={...w};return m(g),g})),c=[si,...s.filter(h=>h!==si)],f=h=>h===si?"This dashboard":h,p=()=>{n&&(o(l.filter(h=>h.to.length>0).map(h=>({source:n.name,name:h.name,expression:h.expression,to:h.to,...h.given?{given:h.given}:{}}))),i())};return x.jsx(E.AppDialog,{open:e,onClose:i,title:"Drill",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:x.jsxs(x.Fragment,{children:[x.jsx(S.Button,{onClick:i,children:"Cancel"}),x.jsx(S.Button,{variant:"contained",onClick:p,disabled:l.length===0,children:"Apply"})]}),children:x.jsx(S.Stack,{sx:{gap:2,pt:1},children:l.length===0?x.jsx(S.Typography,{variant:"body2",sx:{color:a.tileTitle},children:n?x.jsxs(x.Fragment,{children:[x.jsx(S.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"," ",x.jsx(S.Box,{component:"code",children:n.name})," and group by it."]}):"This tile's source is not declared in this file."}):l.map((h,m)=>x.jsxs(S.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr)"},gap:1.5,alignItems:"start"},children:[x.jsxs(S.Box,{sx:{minWidth:0,pt:.75},children:[x.jsx(S.Typography,{variant:"body2",sx:{fontFamily:"ui-monospace, monospace",fontSize:13},children:h.name}),x.jsxs(S.Typography,{variant:"caption",sx:{color:a.tileTitle,display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:h.expression,children:["is ",h.expression]})]}),x.jsx(S.TextField,{select:!0,size:"small",label:"Clicks go to",value:h.to,inputProps:{"aria-label":`Where ${h.name} goes`},SelectProps:{multiple:!0,renderValue:y=>y.length===0?"Not clickable":y.map(f).join(", "),displayEmpty:!0},InputLabelProps:{shrink:!0},onChange:y=>d(m,w=>{const v=y.target.value;w.to=Array.isArray(v)?v:String(v).split(",").filter(Boolean)}),children:c.map(y=>x.jsxs(S.MenuItem,{value:y,children:[x.jsx(S.Checkbox,{size:"small",checked:h.to.includes(y),sx:{p:0,mr:1}}),x.jsx(S.ListItemText,{primary:f(y)})]},y))}),x.jsxs(S.TextField,{select:!0,size:"small",label:"Sets the filter",value:h.given,disabled:h.to.length===0,inputProps:{"aria-label":`Control ${h.name} sets`},SelectProps:{displayEmpty:!0},InputLabelProps:{shrink:!0},helperText:h.given===""?`Named ${h.name}, like the dimension`:void 0,onChange:y=>d(m,w=>{w.given=y.target.value}),children:[x.jsx(S.MenuItem,{value:"",children:x.jsx("em",{children:"Same name as the dimension"})}),r.map(y=>x.jsx(S.MenuItem,{value:y,children:y},y))]})]},h.name))})})}function pf(e,t=[]){const n=new Map;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.set(o.given,(n.get(o.given)??0)+1);const r=[],s=new Set;for(const i of e.localGivens??[])s.add(i.name),r.push({name:i.name,...i.label===void 0?{}:{label:i.label},type:i.type,...i.suggest?{field:i.suggest.dimension}:{},origin:"dashboard",local:i,boundTiles:n.get(i.name)??0});for(const i of t)s.has(i.name)||(s.add(i.name),r.push({...i,origin:"model",boundTiles:n.get(i.name)??0}));for(const[i,o]of n)s.has(i)||r.push({name:i,origin:"model",boundTiles:o});return r}function bs(e){if(!(e===void 0||e.startsWith("filter<")))return e==="string"||e==="boolean"?"=":">="}function gf(e){if(e)return/^filter<(.+)>$/.exec(e)?.[1]??e}function rs(e,t){const n=gf(e),r=t?.replace(/_type$/,"");if(!n||!r)return!0;const s=new Set(["date","timestamp"]);return s.has(n)?s.has(r):n===r}function Aa(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 mf(e){switch(e?.replace(/_type$/,"")){case"number":return"number";case"date":case"timestamp":return"date";default:return"select"}}const vf=[{op:"~",label:"matches"},{op:"=",label:"equals"},{op:">=",label:"at least"},{op:"<=",label:"at most"},{op:">",label:"more than"},{op:"<",label:"less than"}];function bf(e,t){const r=(e.split(".").at(-1)??"").split(/[^A-Za-z0-9]+/).filter(Boolean).join("_").toUpperCase()||"FILTER",s=/^[A-Z_]/.test(r)?r:`F_${r}`,i=me.isStrictName(s)?s:`${s}_FILTER`,o=new Set(t);if(!o.has(i))return i;for(let a=2;;a++)if(!o.has(`${i}_${a}`))return`${i}_${a}`}const Pa=[{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:"On or after 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;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 Ci=e=>xe(e)&&e.declaration.kind!=="inherited"&&e.declaration.kind!=="opaque";function yf(e,t){return e.tiles.map(n=>{const r=(xe(n)?n.filters??[]:[]).find(s=>s.given===t.name);return{include:r!==void 0,field:r?.field??t.field??t.name.toLowerCase(),...r?.op!==void 0?{op:r.op}:bs(t.type)!==void 0?{op:bs(t.type)}:{}}})}function xf(e,t,n){n.forEach((r,s)=>{const i=e.tiles[s];if(!i||!Ci(i))return;const o=(i.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?i.filters=a:delete i.filters})}function wf(e,t){const n=(e.localGivens??[]).filter(i=>i.name!==t.name),r=(e.localGivens??[]).findIndex(i=>i.name===t.name),s=[...n];s.splice(r>=0?r:s.length,0,t),e.localGivens=s}function _f(e,t){for(const r of e.tiles){if(!xe(r))continue;const s=(r.filters??[]).filter(i=>i.given!==t);s.length>0?r.filters=s:delete r.filters}const n=(e.localGivens??[]).filter(r=>r.name!==t);n.length>0?e.localGivens=n:delete e.localGivens}const ql=e=>e.charAt(0)+e.slice(1).toLowerCase().replace(/_/g," ");function kf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:i}){const o=k.useRef(n);e&&(o.current=n);const a=e?n:o.current,l=a!==void 0,[u,d]=k.useState({kind:"new"}),[c,f]=k.useState(""),[p,h]=k.useState("select"),[m,y]=k.useState(""),[w,v]=k.useState(""),[g,b]=k.useState([]),[_,O]=k.useState(!1),[I,M]=k.useState(!1),T=C=>t.sources.find(K=>K.name===C.source)?.base??C.source;k.useEffect(()=>{if(e)if(M(n!==void 0),n){d({kind:"existing",name:n.name}),f(n.label??"");const C=yf(t,n);b(C);const K=C.filter(ve=>ve.include),ie=new Set(K.map(ve=>ve.field));v(ie.size===1?K[0].field:n.field??""),O(ie.size>1)}else d({kind:"new"}),f(""),h("select"),v(""),y(new Date().toISOString().slice(0,10)),b(t.tiles.map(C=>({include:Ci(C),field:""}))),O(!1)},[e,n,t]);const D=k.useMemo(()=>[...(t.localGivens??[]).map(C=>C.name),...r.map(C=>C.name)],[t,r]),N=k.useMemo(()=>w.trim()?bf(w.trim(),D):"",[w,D]),R=u.kind==="existing"?n??r.find(C=>C.name===u.name):N?{name:N,type:Br({name:N,label:c,kind:p,field:w}).type}:void 0,W=R?.type!==void 0&&!R.type.startsWith("filter<"),X=g.find(C=>C.include)?.op??bs(R?.type),G=(C,K)=>{M(!0),b(ie=>ie.map((ve,Re)=>Re===C?{...ve,...K}:ve))},U=C=>{M(!0),b(K=>K.map(ie=>({...ie,op:C})))},Y=C=>{const K=bs(C);b(ie=>ie.map(({op:ve,...Re})=>K?{...Re,op:K}:Re))},re=C=>{M(!0),d({kind:"existing",name:C.name}),v(C.field??""),Y(C.type)},ee=C=>{M(!0),h(C),Y(Br({name:"X",label:c,kind:C,field:w}).type)},A=t.tiles.map(Ci),B=A.filter(Boolean).length,z=g.filter((C,K)=>C.include&&A[K]).length,j=t.tiles.filter((C,K)=>(g[K]?.include??!1)&&A[K]&&xe(C)),q=j.length>0?j:t.tiles.filter((C,K)=>A[K]&&xe(C)),J=k.useMemo(()=>{const C=new Map;let K=!1;for(const ie of q){const ve=s?.(ie);if(ve){K=!0;for(const Re of ve)C.has(Re.name)||C.set(Re.name,Re)}}return K?[...C.values()]:void 0},[g,t.tiles,s]),Q=(()=>{const C=w.trim();for(const K of j){const ie=s?.(K);if(!ie||ie.some(ve=>ve.name===C))return T(K)}return j[0]?T(j[0]):t.sources[0]?.base})(),H=C=>{M(!0),b(K=>K.map((ie,ve)=>({...ie,include:C&&A[ve]})))},$=k.useMemo(()=>_?g:g.map(C=>({...C,field:w})),[_,g,w]),P=C=>{for(const K of q){const ie=s?.(K)?.find(ve=>ve.name===C.trim());if(ie?.type)return ie.type}},F=C=>rs(R?.type,C.type),V=(C,K)=>{if(C.trim()==="")return"Pick the field this filter compares.";const ie=K?s?.(K):void 0;if(!ie)return;const ve=ie.find(Re=>Re.name===C.trim());if(!ve)return`Not a field of ${K?T(K):"the tiles' source"}.`;if(ve.type&&!rs(R?.type,ve.type))return`${C.trim()} is ${Aa(ve.type)}; this filter compares ${Aa(R?.type?.replace(/^filter<(.+)>$/,"$1"))}.`},oe=C=>{if(M(!0),v(C),l||u.kind!=="new")return;const K=P(C),ie=Br({name:"X",label:c,kind:p,field:C}).type;K&&!rs(ie,K)&&ee(mf(K))},Z=C=>{const K=t.tiles[C];return K&&xe(K)?K:void 0},ne=$.map((C,K)=>C.include&&A[K]?V(C.field,Z(K)):void 0),de=ne.every(C=>C===void 0),se=I?ne:ne.map(()=>{}),L=I&&!_&&z>0?j.map(C=>V(w,C)).find(Boolean):void 0,te=R!==void 0&&de&&(u.kind==="existing"||w.trim()!==""&&N!==""),pe=()=>{if(!(!R||!te))if(u.kind==="new")i(R.name,$,Br({name:R.name,label:c.trim()||ql(R.name),kind:p,field:w.trim(),...Q?{source:Q}:{},...m?{dateDefault:m}:{}}));else if(n?.origin==="dashboard"&&n.local){const C=c.trim(),K=C!==(n.local.label??"");i(R.name,$,K?{...n.local,...C?{label:C}:{}}:void 0)}else i(R.name,$)},ae=l&&a.origin==="model";return{editing:l,shown:a,fromModel:ae,source:u,setSource:d,label:c,setLabel:f,kind:p,dateDefault:m,setDateDefault:y,field:w,rows:g,setRows:b,perTile:_,setPerTile:O,newName:N,target:R,valueTyped:W,commonOp:X,setRow:G,setCommonOp:U,pickExisting:re,pickKind:ee,bindable:A,bindableCount:B,included:z,commonFields:J,setAll:H,accepts:F,pickField:oe,rowProblems:se,commonProblem:L,canApply:te,apply:pe}}function Ma({value:e,onChange:t,fields:n,accepts:r,label:s,ariaLabel:i,error:o,helperText:a,disabled:l,autoFocus:u,placeholder:d,sx:c}){const f=k.useMemo(()=>(n??[]).filter(h=>r?.(h)??!0).map(h=>h.name),[n,r]),p=k.useMemo(()=>new Map((n??[]).map(h=>[h.name,h.type])),[n]);return x.jsx(S.Autocomplete,{freeSolo:!0,size:"small",options:f,inputValue:e,onInputChange:(h,m)=>t(m),value:e,onChange:(h,m)=>t(typeof m=="string"?m:""),disabled:l,disableClearable:!0,renderOption:(h,m)=>k.createElement("li",{...h,key:m},x.jsx(S.Typography,{variant:"body2",sx:{flex:1},children:m}),p.get(m)&&x.jsx(S.Typography,{variant:"caption",sx:{opacity:.6},children:p.get(m)?.replace(/_type$/,"")})),renderInput:h=>x.jsx(S.TextField,{...h,label:s,placeholder:d,autoFocus:u,error:o,helperText:a,inputProps:{...h.inputProps,"aria-label":i}}),sx:c})}const ja=e=>e&&xe(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 Sf({open:e,document:t,control:n,available:r,fieldsFor:s,onClose:i,onApply:o,onRemove:a}){const{theme:l}=Ke.usePublisherTheme(),{editing:u,shown:d,fromModel:c,source:f,setSource:p,label:h,setLabel:m,kind:y,dateDefault:w,setDateDefault:v,field:g,rows:b,setRows:_,perTile:O,setPerTile:I,newName:M,target:T,valueTyped:D,commonOp:N,setRow:R,setCommonOp:W,pickExisting:X,pickKind:G,bindable:U,bindableCount:Y,included:re,commonFields:ee,setAll:A,accepts:B,pickField:z,rowProblems:j,commonProblem:q,canApply:J,apply:Q}=kf({open:e,document:t,control:n,available:r,fieldsFor:s,onApply:o}),H=($,P,F)=>x.jsx(S.TextField,{select:!0,size:"small",label:"Compares",value:$??">=",onChange:V=>P(V.target.value),inputProps:{"aria-label":F},sx:{width:130},children:vf.filter(V=>V.op!=="~").map(V=>x.jsx(S.MenuItem,{value:V.op,children:V.label},V.op))});return x.jsx(E.AppDialog,{open:e,onClose:i,title:u?d.label??d.name:"Add a filter",description:u?x.jsxs(x.Fragment,{children:[x.jsxs(S.Box,{component:"span",sx:{fontFamily:"ui-monospace, monospace"},children:["$",d.name]}),c?" · declared in the model, so its label and options are set there":" · declared in this dashboard"]}):"A filter on the page, and the tiles it filters.",actions:x.jsxs(x.Fragment,{children:[u&&x.jsx(S.Button,{color:"error",startIcon:x.jsx(E.DeleteOutlineIcon,{}),onClick:()=>a(d.name),sx:$=>({mr:"auto",color:E.dangerTextColor($)}),children:"Remove filter"}),x.jsx(S.Button,{onClick:i,children:"Cancel"}),x.jsx(S.Tooltip,{title:J||T===void 0?"":"A ticked tile has no field, or names one its source does not have.",children:x.jsx("span",{children:x.jsx(S.Button,{variant:"contained",onClick:Q,disabled:!J,children:u?"Apply":"Add filter"})})})]}),children:x.jsxs(S.Stack,{sx:{gap:2.5,pt:1},children:[!u&&r.length>0&&x.jsxs(S.ToggleButtonGroup,{exclusive:!0,size:"small",value:f.kind,onChange:($,P)=>{P==="new"?p({kind:"new"}):P==="existing"&&r[0]&&X(r[0])},"aria-label":"Where the filter comes from",children:[x.jsx(S.ToggleButton,{value:"new",children:"New in this dashboard"}),x.jsx(S.ToggleButton,{value:"existing",children:"From the model"})]}),!u&&f.kind==="existing"?x.jsx(S.TextField,{select:!0,size:"small",label:"Filter",value:f.name,onChange:$=>{const P=r.find(F=>F.name===$.target.value);P&&X(P)},children:r.map($=>x.jsxs(S.MenuItem,{value:$.name,children:[$.label??$.name,x.jsxs(S.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:["$",$.name]})]},$.name))}):null,x.jsxs(S.Stack,{direction:"row",sx:{gap:1.5,flexWrap:"wrap"},children:[!O&&x.jsx(Ma,{value:g,onChange:z,fields:ee,accepts:B,label:"Field to filter",ariaLabel:"Field to filter",placeholder:"category",autoFocus:!u,error:q!==void 0,helperText:q??(!u&&M?`Declared as $${M}`:void 0),sx:{flex:1,minWidth:200}}),!c&&x.jsx(S.TextField,{size:"small",label:"Label",placeholder:M?ql(M):"",value:h,onChange:$=>m($.target.value),inputProps:{"aria-label":"Filter label"},sx:{flex:1,minWidth:160}}),D&&!O&&H(N,W,"Comparison")]}),!u&&f.kind==="new"&&x.jsxs(S.Stack,{direction:"row",sx:{gap:1.5},children:[x.jsx(S.TextField,{select:!0,size:"small",label:"Filter kind",value:y,onChange:$=>G($.target.value),inputProps:{"aria-label":"Filter kind"},slotProps:{select:{renderValue:$=>Pa.find(P=>P.kind===$)?.label??String($)}},sx:{flex:1},children:Pa.map($=>x.jsxs(S.MenuItem,{value:$.kind,children:[$.label,x.jsx(S.Typography,{component:"span",variant:"caption",sx:{ml:1,opacity:.6},children:$.hint})]},$.kind))}),y==="date"&&x.jsx(S.TextField,{size:"small",type:"date",label:"Starts at",value:w,onChange:$=>v($.target.value),InputLabelProps:{shrink:!0},sx:{flex:1}})]}),x.jsxs(S.Box,{children:[x.jsxs(S.Stack,{direction:"row",sx:{alignItems:"center",gap:.5},children:[x.jsx(S.Checkbox,{size:"small",checked:Y>0&&re===Y,indeterminate:re>0&&re<Y,disabled:Y===0,onChange:$=>A($.target.checked),inputProps:{"aria-label":"All tiles"}}),x.jsxs(S.Typography,{variant:"subtitle2",sx:{flex:1},children:["Applies to ",re," of ",t.tiles.length," tiles"]}),x.jsx(S.Button,{size:"small",onClick:()=>{O||_($=>$.map(P=>({...P,field:g}))),I($=>!$)},children:O?"Same field for all":"Adjust per tile"})]}),x.jsx(S.Stack,{sx:{gap:O?1:0},children:t.tiles.map(($,P)=>{if(!xe($))return null;const F=b[P],V=$.label??$.name,oe=O?j[P]:void 0;return x.jsxs(S.Stack,{direction:"row",sx:{gap:1,alignItems:O?"flex-start":"center",opacity:U[P]?1:.6},children:[x.jsx(S.Checkbox,{size:"small",disabled:!U[P],checked:(F?.include??!1)&&U[P],inputProps:{"aria-label":`Filter ${V}`},onChange:Z=>R(P,{include:Z.target.checked})}),x.jsx(S.Typography,{variant:"body2",sx:{flex:1,minWidth:0,pt:O?1:0},noWrap:!0,children:V}),U[P]?O&&x.jsxs(x.Fragment,{children:[D&&H(F?.op,Z=>R(P,{op:Z}),`Comparison for ${V}`),x.jsx(Ma,{value:F?.field??"",onChange:Z=>R(P,{field:Z}),fields:s?.($),accepts:B,label:"Field",ariaLabel:`Field for ${V}`,disabled:!F?.include,error:oe!==void 0,helperText:oe,sx:{width:220}})]}):x.jsx(S.Tooltip,{title:ja(t.tiles[P]).reason,children:x.jsx(S.Typography,{variant:"caption",sx:{color:l.tileTitle},children:ja(t.tiles[P]).label})})]},`${$.source}.${$.name}`)})}),re===0&&x.jsx(S.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."})]})]})})}const $f=E.createSvgIcon(x.jsx("path",{d:"M11.71 17.99C8.53 17.84 6 15.22 6 12c0-3.31 2.69-6 6-6 3.22 0 5.84 2.53 5.99 5.71l-2.1-.63C15.48 9.31 13.89 8 12 8c-2.21 0-4 1.79-4 4 0 1.89 1.31 3.48 3.08 3.89zM22 12c0 .3-.01.6-.04.9l-1.97-.59c.01-.1.01-.21.01-.31 0-4.42-3.58-8-8-8s-8 3.58-8 8 3.58 8 8 8c.1 0 .21 0 .31-.01l.59 1.97c-.3.03-.6.04-.9.04-5.52 0-10-4.48-10-10S6.48 2 12 2s10 4.48 10 10m-3.77 4.26L22 15l-10-3 3 10 1.26-3.77 4.27 4.27 1.98-1.98z"}));function Kl(e,t,n,r){const[s,i]=k.useState(void 0);return k.useEffect(()=>{t&&e!==void 0&&i(structuredClone(e))},[t,e]),{draft:s,patch:d=>i(c=>{if(c===void 0)return c;const f=structuredClone(c);return d(f),f}),apply:d=>{if(s===void 0)return;const c=structuredClone(s);d(c),i(c),JSON.stringify(c)!==JSON.stringify(e)&&n(c)},close:()=>{s!==void 0&&e!==void 0&&JSON.stringify(s)!==JSON.stringify(e)&&n(s),r()},discard:()=>i(void 0)}}const Tf=e=>e&&e.length===1?`This tile's chart line (${e[0]}) is not one the builder models, so its chart cannot be changed here.`:`This tile has ${e?.length??"several"} chart lines${e?` (${e.join(" and ")})`:""}, so its chart cannot be changed here.`,Of="This tile's view is declared on its source, so its chart is set in the model.";function Ef({anchor:e,tile:t,onClose:n,onCommit:r,onRemove:s,removeBlocked:i,onDrills:o,view:a}){const l=k.useId(),{theme:u}=Ke.usePublisherTheme(),{draft:d,apply:c,close:f,discard:p}=Kl(t,e!==null,r,n),h=d!==void 0&&xe(d)?d:void 0,m=h!==void 0&&h.declaration.kind!=="inherited",y=g=>c(b=>{xe(b)&&g(b)}),w=k.useRef(void 0),v=e!==null;return k.useEffect(()=>{v&&(w.current=t&&xe(t)?t.chart:void 0)},[v]),x.jsx(S.Popover,{open:e!==null&&d!==void 0,anchorEl:e,onClose:f,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{width:320,p:2}}},children:d&&x.jsxs(S.Stack,{sx:{gap:1.5},children:[x.jsx(S.Typography,{variant:"overline",sx:{color:u.tileTitle,lineHeight:1.5},children:h?`${h.source} → ${h.name}`:`Text · ${d.name}`}),h&&m&&x.jsx(x.Fragment,{children:x.jsx(Ei,{state:h.chart??"default",view:a,cellLabel:`${h.source} ${h.name}`,...h.chart==="custom"?{disabledReason:Tf(h.chartLines)}:{},onChange:g=>y(b=>{const _=w.current;g===(_??"default")?(_===void 0?delete b.chart:b.chart=_,delete b.chartCarried):(b.chart=g,a?b.chartCarried=a.chart?[a.chart]:[]:delete b.chartCarried)})})}),h&&!m&&x.jsxs(x.Fragment,{children:[x.jsx(S.Typography,{variant:"body2",sx:{color:u.tileTitle},children:"Declared on its source, so its title and layout are set in the model. It can still be moved."}),x.jsx(Ei,{state:"default",view:a,cellLabel:`${h.source} ${h.name}`,disabledReason:Of,onChange:()=>{}})]}),h?.declaration.kind==="opaque"&&x.jsxs(S.Typography,{variant:"body2",sx:{color:u.tileTitle},children:["Its body is ",h.declaration.why,", so a filter has no single place to go. Everything else here is editable."]}),x.jsxs(S.Stack,{direction:"row",sx:{justifyContent:"space-between"},children:[m?x.jsx(S.Button,{size:"small",startIcon:x.jsx($f,{}),"aria-haspopup":"dialog",onClick:()=>{f(),o()},children:"Drill"}):x.jsx("span",{}),x.jsx(S.Button,{color:"error",size:"small",startIcon:x.jsx(E.DeleteOutlineIcon,{}),"aria-disabled":i!==void 0||void 0,"aria-describedby":i!==void 0?l:void 0,disableRipple:i!==void 0,sx:g=>({color:E.dangerTextColor(g),...i!==void 0?{opacity:.5,cursor:"default"}:{}}),onClick:()=>{i===void 0&&(p(),s())},children:"Delete"})]}),i!==void 0&&x.jsx(S.Typography,{id:l,variant:"caption",sx:{color:u.tileTitle},children:i})]})})}function Cf({editor:e,catalog:t,columns:n,dashboards:r,bindings:s,tiles:i,drillSource:o,setDrillSource:a,confirmConversion:l,exitDialog:u}){const{filterDialog:d,setFilterDialog:c}=s,{menu:f,setMenu:p}=i,h=f===void 0?void 0:e.document.tiles[f.index],m=h&&xe(h)?h:void 0,y=(()=>{if(!m||!t)return;const w=e.document.sources.find(g=>g.name===m.source)?.base??m.source,v=m.declaration.kind==="reference"?m.declaration.from:m.name;return t.sources.find(g=>g.name===w)?.views.find(g=>g.name===v)})();return x.jsxs(x.Fragment,{children:[x.jsx(Sf,{open:d!==void 0,document:e.document,...d?.control?{control:d.control}:{},available:s.available,...t?{fieldsFor:s.fieldsFor}:{},onClose:()=>c(void 0),onApply:s.applyFilter,onRemove:s.dropControl}),x.jsx(Ef,{anchor:f?.anchor??null,tile:f===void 0?void 0:e.document.tiles[f.index],onClose:()=>p(void 0),onCommit:w=>{const v=f?.index;v!==void 0&&e.update(g=>{g.tiles[v]=w})},onRemove:()=>{f!==void 0&&i.removeTile(f.index)},...e.document.tiles.length===1&&e.saved.tiles.length>0?{removeBlocked:"A saved dashboard needs at least one tile."}:{},view:y,onDrills:()=>{a(m?.source)}}),x.jsx(hf,{open:o!==void 0,document:e.document,source:e.document.sources.find(w=>w.name===o),givenNames:s.controlList.map(w=>w.name),dashboards:r??[],onClose:()=>a(void 0),onApply:w=>e.update(v=>{const b=[...(v.drills??[]).filter(_=>_.source!==o),...w];b.length===0?delete v.drills:v.drills=b})}),x.jsx(E.AppDialog,{open:l!==void 0,onClose:()=>l?.stop(),title:"Convert this notebook?",description:"Saving rewrites this notebook in the tile layout. The builder cannot take that back; the file's history in your repository can.",actions:x.jsxs(x.Fragment,{children:[x.jsx(S.Button,{onClick:()=>l?.stop(),children:"Cancel"}),x.jsx(S.Button,{variant:"contained",onClick:()=>l?.go(),children:"Convert and save"})]}),children:null}),x.jsx(E.UnsavedChangesDialog,{...u}),x.jsx(ff,{open:i.addingTile,document:e.document,catalog:t,columns:n,onClose:i.closeAdd,onAdd:i.addTile,onAddText:i.addText})]})}var If=Symbol.for("preact-signals");function zs(){if(yt>1)yt--;else{var e,t=!1;for((function(){var s=xs;for(xs=void 0;s!==void 0;){var i=s.S;if(i.v===s.v)for(var o=i.t;o!==void 0;o=o.x)o.i===s.i&&(o.i=i.i);s=s.o}})();lr!==void 0;){var n=lr;for(lr=void 0,ys++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Vl(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ys=0,yt--,t)throw e}}function Te(e){if(yt>0)return e();Ii=++Df,yt++;try{return e()}finally{zs()}}var ar,we=void 0;function ue(e){var t=we,n=ar;we=void 0,ar=void 0;try{return e()}finally{we=t,ar=n}}var lr=void 0,yt=0,ys=0,Df=0,Ii=0,xs=void 0,ws=0;function Ul(e){if(we!==void 0){var t=e.n;if(t===void 0||t.t!==we)return t={i:0,S:e,p:we.s,n:void 0,t:we,e:void 0,x:void 0,r:t},we.s!==void 0&&(we.s.n=t),we.s=t,e.n=t,32&we.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=we.s,t.n=void 0,we.s.n=t,we.s=t),t}}function Ue(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}Ue.prototype.brand=If;Ue.prototype.h=function(){return!0};Ue.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:ue(function(){var r;(r=t.W)==null||r.call(t)}))};Ue.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&&ue(function(){var s;(s=t.Z)==null||s.call(t)}))}};Ue.prototype.subscribe=function(e){var t=this;return st(function(){var n=t.value;ue(function(){return e(n)})},{name:"sub"})};Ue.prototype.valueOf=function(){return this.value};Ue.prototype.toString=function(){return this.value+""};Ue.prototype.toJSON=function(){return this.value};Ue.prototype.peek=function(){var e=this;return ue(function(){return e.value})};Object.defineProperty(Ue.prototype,"value",{get:function(){var e=Ul(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ys>100)throw new Error("Cycle detected");(function(n){yt!==0&&ys===0&&n.l!==Ii&&(n.l=Ii,xs={S:n,v:n.v,i:n.i,o:xs})})(this),this.v=e,this.i++,ws++,yt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{zs()}}}});function Tn(e,t){return new Ue(e,t)}function Vl(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 Hl(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 Xl(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 Xt(e,t){Ue.call(this,void 0,t),this.x=e,this.s=void 0,this.g=ws-1,this.f=4}Xt.prototype=new Ue;Xt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ws))return!0;if(this.g=ws,this.f|=1,this.i>0&&!Vl(this))return this.f&=-2,!0;var e=we;try{Hl(this),we=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 we=e,Xl(this),this.f&=-2,!0};Xt.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)}Ue.prototype.S.call(this,e)};Xt.prototype.U=function(e){if(this.t!==void 0&&(Ue.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)}};Xt.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(Xt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Ul(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Ra(e,t){return new Xt(e,t)}function Yl(e){var t=e.m;if(e.m=void 0,typeof t=="function"){yt++;var n=we;we=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,xo(e),r}finally{we=n,zs()}}}function xo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Yl(e)}function Af(e){if(we!==this)throw new Error("Out-of-order effect");Xl(this),we=e,this.f&=-2,8&this.f&&xo(this),zs()}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,ar&&ar.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,Yl(this),Hl(this),yt++;var e=we;return we=this,Af.bind(this,e)};On.prototype.N=function(){2&this.f||(this.f|=2,this.u=lr,lr=this)};On.prototype.d=function(){this.f|=8,1&this.f||xo(this)};On.prototype.dispose=function(){this.d()};function st(e,t){var n=new On(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Pf=Object.create,wo=Object.defineProperty,Mf=Object.defineProperties,jf=Object.getOwnPropertyDescriptor,Rf=Object.getOwnPropertyDescriptors,La=Object.getOwnPropertySymbols,Lf=Object.prototype.hasOwnProperty,Nf=Object.prototype.propertyIsEnumerable,Ff=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),En=e=>{throw TypeError(e)},Di=(e,t,n)=>t in e?wo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zf=(e,t)=>{for(var n in t||(t={}))Lf.call(t,n)&&Di(e,n,t[n]);if(La)for(var n of La(t))Nf.call(t,n)&&Di(e,n,t[n]);return e},Wf=(e,t)=>Mf(e,Rf(t)),Na=(e,t)=>wo(e,"name",{value:t,configurable:!0}),Bf=e=>{var t;return[,,,Pf((t=void 0)!=null?t:null)]},Zl=["class","method","getter","setter","accessor","field","value","get","set"],Kn=e=>e!==void 0&&typeof e!="function"?En("Function expected"):e,Gf=(e,t,n,r,s)=>({kind:Zl[e],name:t,metadata:r,addInitializer:i=>n._?En("Already initialized"):s.push(Kn(i||null))}),Ql=(e,t)=>Di(t,Ff("metadata"),e[3]),jt=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},Cn=(e,t,n,r,s,i)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),h=c>3?e.length+1:c?f?1:2:0,m=Zl[c+5],y=c>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),v=c&&(!p&&!f&&(s=s.prototype),c<5&&(c>3||!p)&&jf(c<4?s:{get[n](){return Je(this,i)},set[n](b){return Ot(this,i,b)}},n));c?p&&c<4&&Na(i,(c>2?"set ":c>1?"get ":"")+n):Na(s,n);for(var g=r.length-1;g>=0;g--)u=Gf(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>qf(s,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?Je:Kf)(b,s,c^4?i:v.get):b=>b[n]),c>2&&(d.set=p?(b,_)=>Ot(b,s,_,c^4?i:v.set):(b,_)=>b[n]=_)),a=(0,r[g])(c?c<4?p?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,u),l._=1,c^4||a===void 0?Kn(a)&&(c>4?y.unshift(a):c?p?i=a:v[m]=a:s=a):typeof a!="object"||a===null?En("Object expected"):(Kn(o=a.get)&&(v.get=o),Kn(o=a.set)&&(v.set=o),Kn(o=a.init)&&y.unshift(o));return c||Ql(e,s),v&&wo(s,n,v),p?c^4?i:v:s},_o=(e,t,n)=>t.has(e)||En("Cannot "+n),qf=(e,t)=>Object(t)!==t?En('Cannot use the "in" operator on this value'):e.has(t),Je=(e,t,n)=>(_o(e,t,"read from private field"),n?n.call(e):t.get(e)),Un=(e,t,n)=>t.has(e)?En("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ot=(e,t,n,r)=>(_o(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Kf=(e,t,n)=>(_o(e,t,"access private method"),n);function Ai(e,t){if(t){let n;return Ra(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return Ra(e)}function ot(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,s)=>!ot(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(i=>!ot(e[i],t[i]))}return!1}function fe({get:e},t){return{init(n){return Tn(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ee(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=Ai(e.bind(this)),n.set(this,r)),r.value}}function ii(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Wf(zf({},s),{enumerable:e}))})}}function Er(...e){const t=e.map(n=>st(n));return()=>t.forEach(n=>n())}var Jl,ec,tc,nc,rc,sc,Be,ko,oi,Pi,Mi,ze,So,ai,ic,ji,$o,li,Ri,Li;sc=[fe],rc=[fe],nc=[fe],tc=[ii()],ec=[ii()],Jl=[ii()];var Yt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,jt(Be,5,this),Un(this,ze),Un(this,ko,jt(Be,8,this)),jt(Be,11,this),Un(this,So,jt(Be,12,this)),jt(Be,15,this),Un(this,$o,jt(Be,16,this)),jt(Be,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return Je(this,ze,Ri)}get initial(){return Je(this,ze,Pi)}get previous(){return Je(this,ze,ic)}set current(e){const t=ue(()=>Je(this,ze,Ri));e&&t&&this.equals(t,e)||Te(()=>{Je(this,ze,Pi)||Ot(this,ze,e,Mi),Ot(this,ze,t,ji),Ot(this,ze,e,Li)})}reset(e=this.defaultValue){Te(()=>{Ot(this,ze,void 0,ji),Ot(this,ze,e,Mi),Ot(this,ze,e,Li)})}};Be=Bf();ko=new WeakMap;ze=new WeakSet;So=new WeakMap;$o=new WeakMap;oi=Cn(Be,20,"#initial",sc,ze,ko),Pi=oi.get,Mi=oi.set;ai=Cn(Be,20,"#previous",rc,ze,So),ic=ai.get,ji=ai.set;li=Cn(Be,20,"#current",nc,ze,$o),Ri=li.get,Li=li.set;Cn(Be,2,"current",tc,Yt);Cn(Be,2,"initial",ec,Yt);Cn(Be,2,"previous",Jl,Yt);Ql(Be,Yt);function ci(e){return ue(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Rt,Uf=class{constructor(){Un(this,Rt,new WeakMap)}get(e,t){var n;return e?(n=Je(this,Rt).get(e))==null?void 0:n.get(t):void 0}set(e,t,n){var r;if(e)return Je(this,Rt).has(e)||Je(this,Rt).set(e,new Map),(r=Je(this,Rt).get(e))==null?void 0:r.set(t,n)}clear(e){var t;return e?(t=Je(this,Rt).get(e))==null?void 0:t.clear():void 0}};Rt=new WeakMap;var Vf=Object.create,oc=Object.defineProperty,Hf=Object.getOwnPropertyDescriptor,Fa=Object.getOwnPropertySymbols,Xf=Object.prototype.hasOwnProperty,Yf=Object.prototype.propertyIsEnumerable,ac=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ws=e=>{throw TypeError(e)},za=Math.pow,Ni=(e,t,n)=>t in e?oc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Zf=(e,t)=>{for(var n in t||(t={}))Xf.call(t,n)&&Ni(e,n,t[n]);if(Fa)for(var n of Fa(t))Yf.call(t,n)&&Ni(e,n,t[n]);return e},Qf=e=>{var t;return[,,,Vf((t=e?.[ac("metadata")])!=null?t:null)]},lc=["class","method","getter","setter","accessor","field","value","get","set"],cc=e=>e!==void 0&&typeof e!="function"?Ws("Function expected"):e,Jf=(e,t,n,r,s)=>({kind:lc[e],name:t,metadata:r,addInitializer:i=>n._?Ws("Already initialized"):s.push(cc(i||null))}),eh=(e,t)=>Ni(t,ac("metadata"),e[3]),th=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},dc=(e,t,n,r,s,i)=>{for(var o,a,l,u,d=t&7,c=!1,f=!1,p=2,h=lc[d+5],m=e[p]||(e[p]=[]),y=(s=s.prototype,Hf(s,n)),w=r.length-1;w>=0;w--)l=Jf(d,n,a={},e[3],m),l.static=c,l.private=f,u=l.access={has:v=>n in v},u.get=v=>v[n],o=(0,r[w])(y[h],l),a._=1,cc(o)&&(y[h]=o);return y&&oc(s,n,y),s},uc=(e,t,n)=>t.has(e)||Ws("Cannot "+n),nh=(e,t,n)=>(uc(e,t,"read from private field"),t.get(e)),rh=(e,t,n)=>t.has(e)?Ws("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),sh=(e,t,n,r)=>(uc(e,t,"write to private field"),t.set(e,n),n),et=class Fi{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Fi(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 Fi(t,n)}},ft=class Lt{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,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:s,width:i,height:o,scale:a}=this,l=new Lt(s+t,r+n,i,o);return l.scale=Zf({},a),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:i,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:i,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new et((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof Lt))return!1;const{left:n,top:r,width:s,height:i}=this;return n===t.left&&r===t.top&&s===t.width&&i===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:i}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=i}intersectionArea(t){return t instanceof Lt?ih(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:s}){return new Lt(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(i,o)=>{const a=r[o],l=o==="x"?i.left:i.top,u=o==="x"?i.width:i.height;return a=="start"?l:a=="end"?l+u:l+u/2};return et.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return Lt.from(t).intersectionRatio(Lt.from(n))}};function ih(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),o=s-r,a=i-n;return r<s&&n<i?o*a:0}var fc,hc,zi,ss,Cr,Bs=class extends(zi=Yt,hc=[Ee],fc=[Ee],zi){constructor(t){const n=et.from(t);super(n,(r,s)=>et.equals(r,s)),th(Cr,5,this),rh(this,ss,0),this.velocity={x:0,y:0}}get delta(){return et.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=et.from(t),s={x:r.x-n.x,y:r.y-n.y},i=Date.now(),o=i-nh(this,ss),a=l=>Math.round(l/o*100);Te(()=>{sh(this,ss,i),this.velocity={x:a(s.x),y:a(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(et.from(t)),this.velocity={x:0,y:0}}};Cr=Qf(zi);ss=new WeakMap;dc(Cr,2,"delta",hc,Bs);dc(Cr,2,"direction",fc,Bs);eh(Cr,Bs);function Wi({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(za(r,2)+za(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var pc=(e=>(e.Horizontal="x",e.Vertical="y",e))(pc||{}),gc=Object.values(pc),oh=Object.create,To=Object.defineProperty,ah=Object.defineProperties,lh=Object.getOwnPropertyDescriptor,ch=Object.getOwnPropertyDescriptors,_s=Object.getOwnPropertySymbols,mc=Object.prototype.hasOwnProperty,vc=Object.prototype.propertyIsEnumerable,bc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),In=e=>{throw TypeError(e)},Bi=(e,t,n)=>t in e?To(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Oo=(e,t)=>{for(var n in t||(t={}))mc.call(t,n)&&Bi(e,n,t[n]);if(_s)for(var n of _s(t))vc.call(t,n)&&Bi(e,n,t[n]);return e},Eo=(e,t)=>ah(e,ch(t)),Wa=(e,t)=>To(e,"name",{value:t,configurable:!0}),yc=(e,t)=>{var n={};for(var r in e)mc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_s)for(var r of _s(e))t.indexOf(r)<0&&vc.call(e,r)&&(n[r]=e[r]);return n},Dn=e=>{var t;return[,,,oh((t=e?.[bc("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],Vn=e=>e!==void 0&&typeof e!="function"?In("Function expected"):e,dh=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:i=>n._?In("Already initialized"):s.push(Vn(i||null))}),Zt=(e,t)=>Bi(t,bc("metadata"),e[3]),ce=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},he=(e,t,n,r,s,i)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),h=c>3?e.length+1:c?f?1:2:0,m=xc[c+5],y=c>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),v=c&&(!p&&!f&&(s=s.prototype),c<5&&(c>3||!p)&&lh(c<4?s:{get[n](){return Oe(this,i)},set[n](b){return Ze(this,i,b)}},n));c?p&&c<4&&Wa(i,(c>2?"set ":c>1?"get ":"")+n):Wa(s,n);for(var g=r.length-1;g>=0;g--)u=dh(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>uh(s,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?Oe:wc)(b,s,c^4?i:v.get):b=>b[n]),c>2&&(d.set=p?(b,_)=>Ze(b,s,_,c^4?i:v.set):(b,_)=>b[n]=_)),a=(0,r[g])(c?c<4?p?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,u),l._=1,c^4||a===void 0?Vn(a)&&(c>4?y.unshift(a):c?p?i=a:v[m]=a:s=a):typeof a!="object"||a===null?In("Object expected"):(Vn(o=a.get)&&(v.get=o),Vn(o=a.set)&&(v.set=o),Vn(o=a.init)&&y.unshift(o));return c||Zt(e,s),v&&To(s,n,v),p?c^4?i:v:s},Co=(e,t,n)=>t.has(e)||In("Cannot "+n),uh=(e,t)=>Object(t)!==t?In('Cannot use the "in" operator on this value'):e.has(t),Oe=(e,t,n)=>(Co(e,t,"read from private field"),n?n.call(e):t.get(e)),ge=(e,t,n)=>t.has(e)?In("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ze=(e,t,n,r)=>(Co(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),wc=(e,t,n)=>(Co(e,t,"access private method"),n);function _c(e,t){return{plugin:e,options:t}}function Ir(e){return t=>_c(e,t)}function pr(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var kc,gr,Io,is;kc=[fe];var We=class{constructor(e,t){this.manager=e,this.options=t,ge(this,Io,ce(gr,8,this,!1)),ce(gr,11,this),ge(this,is,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return ue(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=st(e.bind(this));return Oe(this,is).add(t),t}destroy(){Oe(this,is).forEach(e=>e())}static configure(e){return _c(this,e)}};gr=Dn(null);Io=new WeakMap;is=new WeakMap;he(gr,4,"disabled",kc,We,Io);Zt(gr,We);var Dr=class extends We{},os,di=class{constructor(e){this.manager=e,this.instances=new Map,ge(this,os,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(pr).reduce((r,s)=>{const i=r.find(({plugin:o})=>o===s.plugin);return i?(i.options=s.options,r):[...r,s]},[]),n=t.map(({plugin:r})=>r);for(const r of Oe(this,os))if(!n.includes(r)){if(r.prototype instanceof Dr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);Ze(this,os,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()}};os=new WeakMap;function fh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Gr=[],an,ln,hh=class extends We{constructor(e){super(e),ge(this,an),ge(this,ln),this.computeCollisions=this.computeCollisions.bind(this),Ze(this,ln,Tn(Gr)),this.destroy=Er(()=>{const t=this.computeCollisions(),n=ue(()=>this.manager.dragOperation.position.current);if(t!==Gr){const r=Oe(this,an);if(Ze(this,an,n),r&&n.x==r.x&&n.y==r.y)return}else Ze(this,an,void 0);Oe(this,ln).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){ue(()=>{e?Oe(this,ln).value=this.computeCollisions():Ze(this,an,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:i,status:o}=r;if(!o.initialized||!i)return Gr;const a=[],l=[];for(const u of e??n.droppables){if(u.disabled||s&&!u.accepts(s))continue;const d=t??u.collisionDetector;if(!d)continue;l.push(u),u.shape;const c=ue(()=>d({droppable:u,dragOperation:r}));c&&(u.collisionPriority!=null&&(c.priority=u.collisionPriority),a.push(c))}return l.length===0?Gr:(a.sort(fh),a)}get collisions(){return Oe(this,ln).value}};an=new WeakMap;ln=new WeakMap;var Sc,$c,Tc,Do,Oc,at,Ao,pn,Po,Mo;Tc=[fe],$c=[fe],Sc=[fe];var wt=class Nt{constructor(t,n){ge(this,Ao,ce(at,8,this)),ce(at,11,this),ge(this,pn),ge(this,Po,ce(at,12,this)),ce(at,15,this),ge(this,Mo,ce(at,16,this)),ce(at,19,this);const{effects:r,id:s,data:i={},disabled:o=!1,register:a=!0}=t;let l=s;Ze(this,pn,Tn(s)),this.manager=n,this.data=i,this.disabled=o,this.effects=()=>{var u;return[()=>{const{id:d,manager:c}=this;if(d!==l)return l=d,c?.registry.register(this),()=>c?.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=Oe(this,pn).value;return(n=(t=Nt.pendingIdChanges)==null?void 0:t.get(this))!=null?n:r}set id(t){var n,r;const s=(r=(n=Nt.pendingIdChanges)==null?void 0:n.get(this))!=null?r:Oe(this,pn).peek();t!==s&&(Nt.pendingIdChanges||(Nt.pendingIdChanges=new Map,queueMicrotask(()=>{var i;return wc(i=Nt,Do,Oc).call(i)})),Nt.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)}};at=Dn(null);Do=new WeakSet;Oc=function(){const e=wt.pendingIdChanges;wt.pendingIdChanges=null,e&&Te(()=>{for(const[t,n]of e)Oe(t,pn).value=n})};Ao=new WeakMap;pn=new WeakMap;Po=new WeakMap;Mo=new WeakMap;he(at,4,"manager",Tc,wt,Ao);he(at,4,"data",$c,wt,Po);he(at,4,"disabled",Sc,wt,Mo);ge(wt,Do);Zt(at,wt);wt.pendingIdChanges=null;var Gs=wt,Ba=class{constructor(){this.map=Tn(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r&&r.id===e){const a=this.cleanupFunctions.get(r);a?.(),this.cleanupFunctions.delete(r)}const i=new Map(n);for(const[a,l]of n)if(l===t&&a!==e){i.delete(a);break}i.set(e,t),this.map.value=i;const o=Er(...t.effects());return this.cleanupFunctions.set(t,o),s},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 s=new Map(n);s.delete(e),this.map.value=s}}[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}},Ec,Cc,Ic,Dc,Ac,Pc,Gi,Ge,jo,Ro,Lo,ht=class extends(Gi=Gs,Pc=[fe],Ac=[fe],Dc=[fe],Ic=[Ee],Cc=[Ee],Ec=[Ee],Gi){constructor(t,n){var r=t,{modifiers:s,type:i,sensors:o,plugins:a,effects:l}=r,u=yc(r,["modifiers","type","sensors","plugins","effects"]);super(Eo(Oo({},u),{effects:()=>{var d;return[...(d=l?.())!=null?d:[],()=>{const{manager:c,plugins:f}=this;if(!(!c||!f))for(const p of f){const{plugin:h}=pr(p);c.registry.plugins.register(h)}}]}}),n),ce(Ge,5,this),ge(this,jo,ce(Ge,8,this)),ce(Ge,11,this),ge(this,Ro,ce(Ge,12,this)),ce(Ge,15,this),ge(this,Lo,ce(Ge,16,this,this.isDragSource?"dragging":"idle")),ce(Ge,19,this),this.type=i,this.sensors=o,this.modifiers=s,this.alignment=u.alignment,this.plugins=a}pluginConfig(t){if(this.plugins)for(const n of this.plugins){const r=pr(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}};Ge=Dn(Gi);jo=new WeakMap;Ro=new WeakMap;Lo=new WeakMap;he(Ge,4,"type",Pc,ht,jo);he(Ge,4,"modifiers",Ac,ht,Ro);he(Ge,4,"status",Dc,ht,Lo);he(Ge,2,"isDropping",Ic,ht);he(Ge,2,"isDragging",Cc,ht);he(Ge,2,"isDragSource",Ec,ht);Zt(Ge,ht);var Mc,jc,Rc,Lc,Nc,Fc,qi,Pe,No,Fo,zo,Wo,Bo,pt=class extends(qi=Gs,Fc=[fe],Nc=[fe],Lc=[fe],Rc=[fe],jc=[fe],Mc=[Ee],qi){constructor(t,n){var r=t,{accept:s,collisionDetector:i,collisionPriority:o,type:a}=r,l=yc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),ce(Pe,5,this),ge(this,No,ce(Pe,8,this)),ce(Pe,11,this),ge(this,Fo,ce(Pe,12,this)),ce(Pe,15,this),ge(this,zo,ce(Pe,16,this)),ce(Pe,19,this),ge(this,Wo,ce(Pe,20,this)),ce(Pe,23,this),ge(this,Bo,ce(Pe,24,this)),ce(Pe,27,this),this.accept=s,this.collisionDetector=i,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}};Pe=Dn(qi);No=new WeakMap;Fo=new WeakMap;zo=new WeakMap;Wo=new WeakMap;Bo=new WeakMap;he(Pe,4,"accept",Fc,pt,No);he(Pe,4,"type",Nc,pt,Fo);he(Pe,4,"collisionDetector",Lc,pt,zo);he(Pe,4,"collisionPriority",Rc,pt,Wo);he(Pe,4,"shape",jc,pt,Bo);he(Pe,2,"isDropTarget",Mc,pt);Zt(Pe,pt);var ph=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 s of r)s(...t)}},gh=class extends ph{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function as(e,t=!0){let n=!1;return Eo(Oo({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var mh=class extends Dr{constructor(e){super(e);const t=(r,s)=>r.map(({id:i})=>i).join("")===s.map(({id:i})=>i).join("");let n=[];this.destroy=Er(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:i}=r;if(r.isDisabled()||Gs.pendingIdChanges)return;const o=as({collisions:i});if(s.dispatch("collision",o),o.defaultPrevented||t(i,n))return;n=i;const[a]=i;ue(()=>{var l;a?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(a?.id).then(()=>{r.enable()}))})})}},An=(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))(An||{}),Pn=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Pn||{}),zc,Wc,Bc,Gc,qc,Kc,Uc,rt,Go;Uc=[fe],Kc=[Ee],qc=[Ee],Gc=[Ee],Bc=[Ee],Wc=[Ee],zc=[Ee];var kt=class{constructor(){ce(rt,5,this),ge(this,Go,ce(rt,8,this,"idle")),ce(rt,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}};rt=Dn(null);Go=new WeakMap;he(rt,4,"value",Uc,kt,Go);he(rt,2,"current",Kc,kt);he(rt,2,"idle",qc,kt);he(rt,2,"initializing",Gc,kt);he(rt,2,"initialized",Bc,kt);he(rt,2,"dragging",Wc,kt);he(rt,2,"dropped",zc,kt);Zt(rt,kt);var vh=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 ue(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=as({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return ue(()=>{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:s,coordinates:i}=e;Te(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(i)});const o=as({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"&&Te(()=>{t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1})})}),r)})}move(e){return ue(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:i}=r;if(!s.dragging||!i||i.signal.aborted)return;const o=as({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,d,c;if(o.defaultPrevented)return;const f=(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+((d=(u=e.by)==null?void 0:u.y)!=null?d:0)};r.position.current=f})})}stop(e={}){return ue(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let i;const o=()=>{const l={resume:()=>{},abort:()=>{}};return i=new Promise((u,d)=>{l.resume=u,l.abort=d}),l};s.abort();const a=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=ue(()=>{var d;return((d=r.source)==null?void 0:d.status)==="dropping"}),u=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:d}=r,c=st(()=>{d?.status==="idle"&&(c(),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}),i?i.then(a).catch(()=>r.reset()):a()})}},xn=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}},bh=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)}},ls,Vc=class{constructor(e){this.options=e,ge(this,ls)}set controller(e){Ze(this,ls,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Oe(this,ls))==null||t.activate(e)}};ls=new WeakMap;var Ga=class extends We{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},yh=class{constructor(e){this.draggables=new Ba,this.droppables=new Ba,this.plugins=new di(e),this.sensors=new di(e),this.modifiers=new di(e)}register(e,t){if(e instanceof ht)return this.draggables.register(e.id,e);if(e instanceof pt)return this.droppables.register(e.id,e);if(e.prototype instanceof Ga)return this.modifiers.register(e,t);if(e.prototype instanceof xn)return this.sensors.register(e,t);if(e.prototype instanceof We)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Gs)return e instanceof ht?this.draggables.unregister(e.id,e):e instanceof pt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Ga)return this.modifiers.unregister(e);if(e.prototype instanceof xn)return this.sensors.unregister(e);if(e.prototype instanceof We)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()}},Hc,Xc,Yc,Zc,Qc,Jc,ed,td,nd,Hn,cs,cn,$e,qo,Ko,Uo,Vo,Ho,Xn;nd=[Ee],td=[fe],ed=[fe],Jc=[fe],Qc=[fe],Zc=[fe],Yc=[Ee],Xc=[Ee],Hc=[Ee];var ct=class{constructor(e){ce($e,5,this),ge(this,Hn),ge(this,cs),ge(this,cn,new Yt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new kt,ge(this,qo,ce($e,8,this,!1)),ce($e,11,this),ge(this,Ko,ce($e,12,this,null)),ce($e,15,this),ge(this,Uo,ce($e,16,this,null)),ce($e,19,this),ge(this,Vo,ce($e,20,this,null)),ce($e,23,this),ge(this,Ho,ce($e,24,this,[])),ce($e,27,this),this.position=new Bs({x:0,y:0}),ge(this,Xn,{x:0,y:0}),Ze(this,Hn,e)}get shape(){const{current:e,initial:t,previous:n}=Oe(this,cn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Oe(this,cn).current=e:Oe(this,cn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Oe(this,Hn).registry.draggables.get(t);return n&&Ze(this,cs,n),(e=n??Oe(this,cs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Oe(this,Hn).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(Oo({},this.snapshot()),{transform:n}));return Ze(this,Xn,n),n}snapshot(){return ue(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Oe(this,Xn),shape:this.shape?ci(this.shape):null,position:ci(this.position),status:ci(this.status),canceled:this.canceled}))}reset(){Te(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Oe(this,cn).reset(),this.position.reset({x:0,y:0}),Ze(this,Xn,{x:0,y:0}),this.modifiers=[]})}};$e=Dn(null);Hn=new WeakMap;cs=new WeakMap;cn=new WeakMap;qo=new WeakMap;Ko=new WeakMap;Uo=new WeakMap;Vo=new WeakMap;Ho=new WeakMap;Xn=new WeakMap;he($e,2,"shape",nd,ct);he($e,4,"canceled",td,ct,qo);he($e,4,"activatorEvent",ed,ct,Ko);he($e,4,"sourceIdentifier",Jc,ct,Uo);he($e,4,"targetIdentifier",Qc,ct,Vo);he($e,4,"modifiers",Zc,ct,Ho);he($e,2,"source",Yc,ct);he($e,2,"target",Xc,ct);he($e,2,"transform",Hc,ct);Zt($e,ct);var xh={get rendering(){return Promise.resolve()}};function lt(e,t){return typeof e=="function"?e(t):e??t}var wh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(f=>f.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=lt(r.plugins,[]),i=lt(r.sensors,[]),o=lt(r.modifiers,[]),a=(n=r.renderer)!=null?n:xh,l=new gh(this),u=new yh(this);this.registry=u,this.monitor=l,this.renderer=a,this.actions=new vh(this),this.dragOperation=new ct(this),this.collisionObserver=new hh(this),this.plugins=[mh,...s],this.modifiers=o,this.sensors=i;const{destroy:d}=this,c=Er(()=>{var f,p,h;const m=ue(()=>this.dragOperation.modifiers),y=this.modifiers;for(const w of m)y.includes(w)||w.destroy();this.dragOperation.modifiers=(h=(p=(f=this.dragOperation.source)==null?void 0:f.modifiers)==null?void 0:p.map(w=>{const{plugin:v,options:g}=pr(w);return new v(this,g)}))!=null?h:y});this.destroy=()=>{c(),d()}}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}},rd=e=>{throw TypeError(e)},Xo=(e,t,n)=>t.has(e)||rd("Cannot "+n),le=(e,t,n)=>(Xo(e,t,"read from private field"),t.get(e)),Ve=(e,t,n)=>t.has(e)?rd("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,r)=>(Xo(e,t,"write to private field"),t.set(e,n),n),sd=(e,t,n)=>(Xo(e,t,"access private method"),n);function qs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function id(e,t){const n=e.getAnimations();let r=null;for(const s of n){if(s.playState!=="running")continue;const{effect:i}=s,a=(qs(i)?i.getKeyframes():[]).filter(t);a.length>0&&(r=[a[a.length-1],s])}return r}function Ks(e){const{width:t,height:n,top:r,left:s,bottom:i,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:i,right:o}}function Yo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Ar(e){return"nodeType"in e}function Qe(e){var t,n,r;return e?Yo(e)?e:Ar(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 Zo(e){const{Document:t}=Qe(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function Pt(e){return!e||Yo(e)?!1:e instanceof Qe(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function od(e){return e instanceof Qe(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function Mn(e){return e?Yo(e)?e.document:Ar(e)?Zo(e)?e:Pt(e)||od(e)?e.ownerDocument:document:document:document}function _h(e){var t,n,r,s;const{documentElement:i}=Mn(e),o=Qe(e).visualViewport,a=(t=o?.width)!=null?t:i.clientWidth,l=(n=o?.height)!=null?n:i.clientHeight,u=(r=o?.offsetTop)!=null?r:0,d=(s=o?.offsetLeft)!=null?s:0;return{top:u,left:d,right:d+a,bottom:u+l,width:a,height:l}}function kh(e,t){if(Sh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Sh(e){return e.tagName==="DETAILS"}function mr(e,t=e.getBoundingClientRect(),n=0){var r,s,i,o,a;let l=t;const{ownerDocument:u}=e,d=(r=u.defaultView)!=null?r:window;let c=e.parentElement;for(;c&&c!==u.documentElement;){if(!kh(c)){const g=c.getBoundingClientRect(),b=n*(g.bottom-g.top),_=n*(g.right-g.left),O=n*(g.bottom-g.top),I=n*(g.right-g.left);l={top:Math.max(l.top,g.top-b),right:Math.min(l.right,g.right+_),bottom:Math.min(l.bottom,g.bottom+O),left:Math.max(l.left,g.left-I),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}c=c.parentElement}const f=d.visualViewport,p=(s=f?.offsetTop)!=null?s:0,h=(i=f?.offsetLeft)!=null?i:0,m=(o=f?.width)!=null?o:d.innerWidth,y=(a=f?.height)!=null?a:d.innerHeight,w=n*y,v=n*m;return l={top:Math.max(l.top,p-w),right:Math.min(l.right,h+m+v),bottom:Math.min(l.bottom,p+y+w),left:Math.max(l.left,h-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 wn(e){return{x:e.clientX,y:e.clientY}}var ad=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ki(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 s=r.contentDocument;s&&!t.has(s)&&n.push(...Ki(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Ki(s.document,t))}}catch{}return n}function Qo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ld(){var e,t;const n=Qo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Jo(e){return!e||!Ar(e)?!1:e instanceof Qe(e).ShadowRoot}function ks(e){if(e&&Ar(e)){let t=e.getRootNode();if(Jo(t))return t;if(t instanceof Document)return t}return Mn(e)}function ea(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function $h(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((i,o)=>{const a=r[o];if(qa(i)&&qa(a)&&(i.type!=="file"&&(i.value=a.value),i.type==="radio"&&i.name&&(i.name=`Cloned__${i.name}`)),Ka(i)&&Ka(a)&&a.width>0&&a.height>0){const l=i.getContext("2d");l?.drawImage(a,0,0)}}),n}function qa(e){return"value"in e}function Ka(e){return e.tagName==="CANVAS"}function cd(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Th(r)){const{contentDocument:s}=r;if(s){const{left:i,top:o}=r.getBoundingClientRect();return cd(s,{x:t-i,y:n-o})}}return r}function Th(e){return e?.tagName==="IFRAME"}var Ui=new WeakMap;function Oh(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 ld=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];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),s.push(d)}const i=this.entries;return function(){for(const a of s){const[l,{type:u,listener:c,options:d}]=a;l.removeEventListener(u,c,d),i.delete(a)}}}};function _n(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Oh(e){const t=new Set;let n=_n(e);for(;n;)t.add(n),n=_n(n);return t}function Eh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function cd(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Eh(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Ch(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 Ih(e,t=e.getBoundingClientRect()){const{width:n,height:r}=mr(e,t);return n>0&&r>0}var Dh=id?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ds,Ah=class extends Dh{constructor(e){super(t=>{if(!ae(this,ds)){Ye(this,ds,!0);return}e(t,this)}),Ve(this,ds,!1)}};ds=new WeakMap;var Ka=Array.from({length:100},(e,t)=>t/100),dd=75,Ft,Ss,$t,zt,Yn,Ne,cr,Zn,$s,ud,fd,hd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ve(this,$s),this.disconnect=()=>{var i,o,a;Ye(this,cr,!0),(i=ae(this,$t))==null||i.disconnect(),(o=ae(this,zt))==null||o.disconnect(),ae(this,Yn).disconnect(),(a=ae(this,Ne))==null||a.remove()},Ve(this,Ft,!0),Ve(this,Ss),Ve(this,$t),Ve(this,zt),Ve(this,Yn),Ve(this,Ne),Ve(this,cr,!1),Ve(this,Zn,cd(()=>{var i,o,a;const{element:l}=this;if((i=ae(this,zt))==null||i.disconnect(),ae(this,cr)||!ae(this,Ft)||!l.isConnected)return;const u=(o=l.ownerDocument)!=null?o:document,{innerHeight:c,innerWidth:d}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),p=mr(l,f),{top:h,left:v,bottom:y,right:w}=p,g=-Math.floor(h),m=-Math.floor(v),b=-Math.floor(d-w),_=-Math.floor(c-y),O=`${g}px ${b}px ${_}px ${m}px`;this.boundingClientRect=f,Ye(this,zt,new IntersectionObserver(E=>{const[I]=E,{intersectionRect:T}=I;(I.intersectionRatio!==1?I.intersectionRatio:ft.intersectionRatio(T,mr(l)))!==1&&ae(this,Zn).call(this)},{threshold:Ka,rootMargin:O,root:u})),ae(this,zt).observe(l),nd(this,$s,ud).call(this)},dd)),this.boundingClientRect=e.getBoundingClientRect(),Ye(this,Ft,Ih(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(Ye(this,Ne,document.createElement("div")),ae(this,Ne).style.background="rgba(0,0,0,0.15)",ae(this,Ne).style.position="fixed",ae(this,Ne).style.pointerEvents="none",s.body.appendChild(ae(this,Ne))),Ye(this,Yn,new IntersectionObserver(i=>{var o,a;const l=i[i.length-1],{boundingClientRect:u,isIntersecting:c}=l,{width:d,height:f}=u,p=ae(this,Ft);Ye(this,Ft,c),!(!d&&!f)&&(p&&!c?((o=ae(this,zt))==null||o.disconnect(),this.callback(null),(a=ae(this,$t))==null||a.disconnect(),Ye(this,$t,void 0),ae(this,Ne)&&(ae(this,Ne).style.visibility="hidden")):ae(this,Zn).call(this),c&&!ae(this,$t)&&(Ye(this,$t,new Ah(ae(this,Zn))),ae(this,$t).observe(e)))},{threshold:Ka,root:s})),ae(this,Ft)&&!n.skipInitial&&this.callback(this.boundingClientRect),ae(this,Yn).observe(e)}};Ft=new WeakMap;Ss=new WeakMap;$t=new WeakMap;zt=new WeakMap;Yn=new WeakMap;Ne=new WeakMap;cr=new WeakMap;Zn=new WeakMap;$s=new WeakSet;ud=function(){ae(this,cr)||(nd(this,$s,fd).call(this),!Ch(this.boundingClientRect,ae(this,Ss))&&(this.callback(this.boundingClientRect),Ye(this,Ss,this.boundingClientRect)))};fd=function(){if(ae(this,Ne)){const{top:e,left:t,width:n,height:r}=mr(this.element);ae(this,Ne).style.overflow="hidden",ae(this,Ne).style.visibility="visible",ae(this,Ne).style.top=`${Math.floor(e)}px`,ae(this,Ne).style.left=`${Math.floor(t)}px`,ae(this,Ne).style.width=`${Math.floor(n)}px`,ae(this,Ne).style.height=`${Math.floor(r)}px`}};var qr=new WeakMap,Kr=new WeakMap;function Ph(e,t){let n=qr.get(e);return n||(n={disconnect:new hd(e,s=>{const i=qr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),qr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(qr.delete(e),n.disconnect())}}function Mh(e,t){const n=new Set;for(const r of e){const s=Ph(r,t);n.add(s)}return()=>n.forEach(r=>r())}function jh(e,t){var n;const r=e.ownerDocument;if(!Kr.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}),Kr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Kr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Kr.delete(r))})}var Qn,Jn,us,Vi,Rh=class{constructor(e,t,n){this.callback=t,Ve(this,Qn),Ve(this,Jn,!1),Ve(this,us),Ve(this,Vi,cd(o=>{if(!ae(this,Jn)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of ae(this,us))if(o.target.contains(a)){this.callback(ae(this,Qn).boundingClientRect);break}}},dd));const r=Oh(e),s=Mh(r,t),i=jh(e,ae(this,Vi));Ye(this,us,r),Ye(this,Qn,new hd(e,t,n)),this.disconnect=()=>{ae(this,Jn)||(Ye(this,Jn,!0),s(),i(),ae(this,Qn).disconnect())}}};Qn=new WeakMap;Jn=new WeakMap;us=new WeakMap;Vi=new WeakMap;function Hi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function mn(e){try{Hi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Ua(e){return!id||!e?!1:e===Mn(e).scrollingElement}function pd(e){var t,n;const r=Qe(e),s=Ua(e)?wh(e):Ks(e),i=r.visualViewport,o=Ua(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.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:s,position:a,isTop:l,isLeft:u,isBottom:c,isRight:d}}function Lh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=pd(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=!s&&o.current.x+a>0,f=!i&&o.current.x+a<o.max.x;return{top:u,bottom:c,left:d,right:f,x:d||f,y:u||c}}var ea=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 s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Ts=new ea(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Nh=new ea(e=>setTimeout(e,50)),Os=new Map,Fh=Os.clear.bind(Os);function gt(e,t=!1){if(!t)return Va(e);let n=Os.get(e);return n||(n=Va(e),Os.set(e,n),Nh.schedule(Fh),n)}function Va(e){return Qe(e).getComputedStyle(e)}function zh(e,t=gt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Wh(e,t=gt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Bh={excludeElement:!0,escapeShadowDOM:!0};function Xi(e,t=Bh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(Yo(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&Qo(a))return o(a.host);if(!Pt(a))return sd(a)?o(a.parentElement):i;if(i.has(a))return i;const l=gt(a,!0);if(r&&a===e||Wh(a,l)&&i.add(a),zh(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&i.add(u),i}return o(a.parentNode)}return e?o(e):i}function kn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=_n(e);for(;r;){if(r===t)return n;const s=Ks(r),{x:i,y:o}=Gh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=_n(r)}return n}function Gh(e,t=Ks(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Pt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=gt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function qh(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 vr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Us(e){var t,n,r,s,i,o,a,l,u;const{scale:c,transform:d,translate:f}=e,p=qh(c),h=vr(f),v=Kh(d);if(!v&&!p&&!h)return null;const y={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},w={x:(r=h?.x)!=null?r:0,y:(s=h?.y)!=null?s:0},g={x:(i=v?.x)!=null?i:0,y:(o=v?.y)!=null?o:0,scaleX:(a=v?.scaleX)!=null?a:1,scaleY:(l=v?.scaleY)!=null?l:1};return{x:w.x+g.x,y:w.y+g.y,z:(u=h?.z)!=null?u:0,scaleX:y.x*g.scaleX,scaleY:y.y*g.scaleY}}function Kh(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 tt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(tt||{}),Uh={x:.2,y:.2},Vh={x:10,y:10};function Hh(e,t,n,r=25,s=Uh,i=Vh){const{x:o,y:a}=t,{rect:l,isTop:u,isBottom:c,isLeft:d,isRight:f}=pd(e),p=kn(e),h=gt(e,!0),v=Us(h),y=v!==null?v?.scaleX<0:!1,w=v!==null?v?.scaleY<0:!1,g=new ft(l.left*p.scaleX+p.x,l.top*p.scaleY+p.y,l.width*p.scaleX,l.height*p.scaleY),m={x:0,y:0},b={x:0,y:0},_={height:g.height*s.y,width:g.width*s.x};return _.height>0&&(!u||w&&!c)&&a<=g.top+_.height&&n?.y!==1&&o>=g.left-i.x&&o<=g.right+i.x?(m.y=w?1:-1,b.y=r*Math.abs((g.top+_.height-a)/_.height)):_.height>0&&(!c||w&&!u)&&a>=g.bottom-_.height&&n?.y!==-1&&o>=g.left-i.x&&o<=g.right+i.x&&(m.y=w?-1:1,b.y=r*Math.abs((g.bottom-_.height-a)/_.height)),_.width>0&&(!f||y&&!d)&&o>=g.right-_.width&&n?.x!==-1&&a>=g.top-i.y&&a<=g.bottom+i.y?(m.x=y?-1:1,b.x=r*Math.abs((g.right-_.width-o)/_.width)):_.width>0&&(!d||y&&!f)&&o<=g.left+_.width&&n?.x!==1&&a>=g.top-i.y&&a<=g.bottom+i.y&&(m.x=y?1:-1,b.x=r*Math.abs((g.left+_.width-o)/_.width)),{direction:m,speed:b}}function gd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Pt(e))return;const r=Xi(e),s=[];for(const i of r){if(!Pt(i))continue;const{top:o,left:a}=Xh(e,i);let l=o,u=a;for(const c of s)l-=c.scrollTop,u-=c.scrollLeft;if(t!=="none"){const c=l<i.scrollTop,d=l+e.offsetHeight>i.scrollTop+i.clientHeight;c!==d&&(t==="center"?i.scrollTop=l-i.clientHeight/2+e.offsetHeight/2:c?i.scrollTop=l:i.scrollTop=l+e.offsetHeight-i.clientHeight)}if(n!=="none"){const c=u<i.scrollLeft,d=u+e.offsetWidth>i.scrollLeft+i.clientWidth;c!==d&&(n==="center"?i.scrollLeft=u-i.clientWidth/2+e.offsetWidth/2:c?i.scrollLeft=u:i.scrollLeft=u+e.offsetWidth-i.clientWidth)}s.push(i)}}function Ha(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Pt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Xh(e,t){const n=Ha(e),r=Ha(t);return{top:n.top-r.top-t.clientTop,left:n.left-r.left-t.clientLeft}}function Yh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),l=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,c=s?e.height*s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function Zh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),l=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,c=s?e.height/s:e.height;return{width:u,height:c,top:l,right:a+u,bottom:l+c,left:a}}function md({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Xa(e,t=gt(e).translate,n=!0){if(n){const r=rd(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=vr(s);if(i)return i}}}if(t){const r=vr(t);if(r)return r}return{x:0,y:0,z:0}}var Qh=new ea(e=>setTimeout(e,0)),dr=new Map,Jh=dr.clear.bind(dr);function ep(e){const t=e.ownerDocument;let n=dr.get(t);if(n)return n;n=t.getAnimations(),dr.set(t,n),Qh.schedule(Jh);const r=n.filter(s=>qs(s.effect)&&s.effect.target===e);return dr.set(e,r),n}function tp(e,t){const n=ep(e).filter(r=>{var s,i;if(qs(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ut=class extends ft{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=kn(e),ignoreTransforms:a,getBoundingClientRect:l=Ks}=t,u=tp(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||Zo())&&_.contains(e)}),c=l(e);let{top:d,left:f,width:p,height:h}=c,v;const y=gt(e),w=Us(y),g={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},m=np(e,y);u?.(),w&&(v=Zh(c,w,y.transformOrigin),(a||m)&&(d=v.top,f=v.left,p=v.width,h=v.height));const b={width:(s=v?.width)!=null?s:p,height:(i=v?.height)!=null?i:h};if(m&&!a&&v){const _=Yh(v,m,y.transformOrigin);d=_.top,f=_.left,p=_.width,h=_.height,g.x=m.scaleX,g.y=m.scaleY}o&&(a||(f*=o.scaleX,p*=o.scaleX,d*=o.scaleY,h*=o.scaleY),f+=o.x,d+=o.y),super(f,d,p,h),this.scale=g,this.intrinsicWidth=b.width,this.intrinsicHeight=b.height}};function np(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=qs(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:c,translate:d,scale:f}=u;typeof c=="string"&&c&&(r=c,o=!0),typeof d=="string"&&d&&(s=d,o=!0),typeof f=="string"&&f&&(i=f,o=!0)}return o?Us({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function ur(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 rp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(ur(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(ur(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(ur(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ut(e){return e?e instanceof Qe(e).Element||Ar(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function br(e){if(!e)return!1;const{KeyboardEvent:t}=Qe(e.target);return e instanceof t}function sp(e){if(!e)return!1;const{PointerEvent:t}=Qe(e.target);return e instanceof t}function ip(e){if(!Ut(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||op(e)}function op(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var ui={};function Yi(e){const t=ui[e]==null?0:ui[e]+1;return ui[e]=t,`${e}-${t}`}var ta=({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 s=et.distance(t.shape.center,n);return{id:r,value:1/s,type:Pn.PointerIntersection,priority:An.High}}return null},ap=({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:s}=e,i=et.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Pn.ShapeIntersection,priority:An.Normal}}return null},vd=e=>{var t;return(t=ta(e))!=null?t:ap(e)},lp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?ft.from(r.current.boundingRectangle).corners:void 0,a=ft.from(n.shape.boundingRectangle).corners.reduce((l,u,c)=>{var d;return l+et.distance(et.from(u),(d=i?.[c])!=null?d:s.current)},0)/4;return{id:n.id,value:1/a,type:Pn.Collision,priority:An.Normal}},cp=Object.create,na=Object.defineProperty,dp=Object.defineProperties,up=Object.getOwnPropertyDescriptor,fp=Object.getOwnPropertyDescriptors,Es=Object.getOwnPropertySymbols,bd=Object.prototype.hasOwnProperty,yd=Object.prototype.propertyIsEnumerable,xd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),jn=e=>{throw TypeError(e)},Zi=(e,t,n)=>t in e?na(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yr=(e,t)=>{for(var n in t||(t={}))bd.call(t,n)&&Zi(e,n,t[n]);if(Es)for(var n of Es(t))yd.call(t,n)&&Zi(e,n,t[n]);return e},ra=(e,t)=>dp(e,fp(t)),Ya=(e,t)=>na(e,"name",{value:t,configurable:!0}),wd=(e,t)=>{var n={};for(var r in e)bd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Es)for(var r of Es(e))t.indexOf(r)<0&&yd.call(e,r)&&(n[r]=e[r]);return n},Rn=e=>{var t;return[,,,cp((t=e?.[xd("metadata")])!=null?t:null)]},_d=["class","method","getter","setter","accessor","field","value","get","set"],er=e=>e!==void 0&&typeof e!="function"?jn("Function expected"):e,hp=(e,t,n,r,s)=>({kind:_d[e],name:t,metadata:r,addInitializer:i=>n._?jn("Already initialized"):s.push(er(i||null))}),Qt=(e,t)=>Zi(t,xd("metadata"),e[3]),Me=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},it=(e,t,n,r,s,i)=>{var o,a,l,u,c,d=t&7,f=!!(t&8),p=!!(t&16),h=d>3?e.length+1:d?f?1:2:0,v=_d[d+5],y=d>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),g=d&&(!p&&!f&&(s=s.prototype),d<5&&(d>3||!p)&&up(d<4?s:{get[n](){return ye(this,i)},set[n](b){return qe(this,i,b)}},n));d?p&&d<4&&Ya(i,(d>2?"set ":d>1?"get ":"")+n):Ya(s,n);for(var m=r.length-1;m>=0;m--)u=hp(d,n,l={},e[3],w),d&&(u.static=f,u.private=p,c=u.access={has:p?b=>pp(s,b):b=>n in b},d^3&&(c.get=p?b=>(d^1?ye:Vt)(b,s,d^4?i:g.get):b=>b[n]),d>2&&(c.set=p?(b,_)=>qe(b,s,_,d^4?i:g.set):(b,_)=>b[n]=_)),a=(0,r[m])(d?d<4?p?i:g[v]:d>4?void 0:{get:g.get,set:g.set}:s,u),l._=1,d^4||a===void 0?er(a)&&(d>4?y.unshift(a):d?p?i=a:g[v]=a:s=a):typeof a!="object"||a===null?jn("Object expected"):(er(o=a.get)&&(g.get=o),er(o=a.set)&&(g.set=o),er(o=a.init)&&y.unshift(o));return d||Qt(e,s),g&&na(s,n,g),p?d^4?i:g:s},sa=(e,t,n)=>t.has(e)||jn("Cannot "+n),pp=(e,t)=>Object(t)!==t?jn('Cannot use the "in" operator on this value'):e.has(t),ye=(e,t,n)=>(sa(e,t,"read from private field"),n?n.call(e):t.get(e)),Ce=(e,t,n)=>t.has(e)?jn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qe=(e,t,n,r)=>(sa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Vt=(e,t,n)=>(sa(e,t,"access private method"),n),Za={role:"button",roleDescription:"draggable"},gp="dnd-kit-description",mp="dnd-kit-announcement",vp={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."},bp={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 yp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function xp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function wp(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 _p=["dragover","dragmove"],kp=class extends We{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=gp,announcement:s=mp}={},announcements:i=bp,screenReaderInstructions:o=vp,debounce:a=500}=t??{},l=n?`${r}-${n}`:Yi(r),u=n?`${s}-${n}`:Yi(s);let c,d,f,p;const h=(_=p)=>{!f||!_||f?.nodeValue!==_&&(f.nodeValue=_)},v=()=>Ts.schedule(h),y=Sp(v,a),w=Object.entries(i).map(([_,O])=>this.manager.monitor.addEventListener(_,(E,I)=>{const T=f;if(!T)return;const D=O?.(E,I);D&&T.nodeValue!==D&&(p=D,_p.includes(_)?y():(v(),y.cancel()))})),g=()=>{let _=[];c?.isConnected||(c=xp(l,o.draggable),_.push(c)),d?.isConnected||(d=wp(u),f=document.createTextNode(""),d.appendChild(f),_.push(d)),_.length>0&&document.body.append(..._)},m=new Set;function b(){for(const _ of m)_()}this.registerEffect(()=>{var _;m.clear();for(const O of this.manager.registry.draggables.value){const E=(_=O.handle)!=null?_:O.element;if(E){(!c||!d)&&m.add(g),(!yp(E)||Zo())&&!E.hasAttribute("tabindex")&&m.add(()=>E.setAttribute("tabindex","0")),!E.hasAttribute("role")&&E.tagName.toLowerCase()!=="button"&&m.add(()=>E.setAttribute("role",Za.role)),E.hasAttribute("aria-roledescription")||m.add(()=>E.setAttribute("aria-roledescription",Za.roleDescription)),E.hasAttribute("aria-describedby")||m.add(()=>E.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const D=String(O.isDragging);E.getAttribute(T)!==D&&m.add(()=>E.setAttribute(T,D))}const I=String(O.disabled);E.getAttribute("aria-disabled")!==I&&m.add(()=>E.setAttribute("aria-disabled",I))}}m.size>0&&Ts.schedule(b)}),this.destroy=()=>{super.destroy(),c?.remove(),d?.remove(),w.forEach(_=>_())}}};function Sp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Cs=new Map,kd,Sd,$d,Td,Qi,fr,xt,ia,Sn,Od,Ed,Cd,Id,Mt=class extends(Qi=Dr,Td=[fe],$d=[Ee],Sd=[Ee],kd=[Ee],Qi){constructor(t,n){super(t,n),Me(xt,5,this),Ce(this,Sn),Ce(this,fr,new Set),Ce(this,ia,Me(xt,8,this,new Set)),Me(xt,11,this),this.registerEffect(Vt(this,Sn,Od))}register(t){return ye(this,fr).add(t),()=>{ye(this,fr).delete(t)}}addRoot(t){return ue(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ue(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return ks((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return ks((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}};xt=Rn(Qi);fr=new WeakMap;ia=new WeakMap;Sn=new WeakSet;Od=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ye(this,fr))t.push(Vt(this,Sn,Ed).call(this,n,r));return()=>{for(const n of t)n()}};Ed=function(e,t){let n=Cs.get(e);n||(n=new Map,Cs.set(e,n));let r=n.get(t);if(!r){const i=Yo(e)?Vt(this,Sn,Cd).call(this,e,n,t):Vt(this,Sn,Id).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Cd=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Cs.delete(e)}}};Id=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(Qo(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Cs.delete(e)}}};it(xt,4,"additionalRoots",Td,Mt,ia);it(xt,2,"sourceRoot",$d,Mt);it(xt,2,"targetRoot",Sd,Mt);it(xt,2,"roots",kd,Mt);Qt(xt,Mt);Mt.configure=Ir(Mt);var Vs=Mt,$p=class extends We{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Vs),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Pr="data-dnd-",Ji=`${Pr}dropping`,Le="--dnd-",dt=`${Pr}dragging`,Is=`${Pr}placeholder`,Tp=[dt,Is,"popover","aria-pressed","aria-grabbing"],Op=["view-transition-name"],Ep=`
|
|
8
|
+
`)}var dd=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:l,listener:u,options:d}=a,c=[o,a];o.addEventListener(l,u,d),this.entries.add(c),s.push(c)}const i=this.entries;return function(){for(const a of s){const[l,{type:u,listener:d,options:c}]=a;l.removeEventListener(u,d,c),i.delete(a)}}}};function _n(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Eh(e){const t=new Set;let n=_n(e);for(;n;)t.add(n),n=_n(n);return t}function Ch(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ud(e,t){const n=()=>performance.now();let r,s;return function(...i){const o=this;s?(r?.(),r=Ch(()=>{e.apply(o,i),s=n()},t-(n()-s))):(e.apply(o,i),s=n())}}function Ih(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 Dh(e,t=e.getBoundingClientRect()){const{width:n,height:r}=mr(e,t);return n>0&&r>0}var Ah=ad?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},ds,Ph=class extends Ah{constructor(e){super(t=>{if(!le(this,ds)){Ye(this,ds,!0);return}e(t,this)}),Ve(this,ds,!1)}};ds=new WeakMap;var Ua=Array.from({length:100},(e,t)=>t/100),fd=75,Ft,Ss,$t,zt,Yn,Ne,cr,Zn,$s,hd,pd,gd=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,Ve(this,$s),this.disconnect=()=>{var i,o,a;Ye(this,cr,!0),(i=le(this,$t))==null||i.disconnect(),(o=le(this,zt))==null||o.disconnect(),le(this,Yn).disconnect(),(a=le(this,Ne))==null||a.remove()},Ve(this,Ft,!0),Ve(this,Ss),Ve(this,$t),Ve(this,zt),Ve(this,Yn),Ve(this,Ne),Ve(this,cr,!1),Ve(this,Zn,ud(()=>{var i,o,a;const{element:l}=this;if((i=le(this,zt))==null||i.disconnect(),le(this,cr)||!le(this,Ft)||!l.isConnected)return;const u=(o=l.ownerDocument)!=null?o:document,{innerHeight:d,innerWidth:c}=(a=u.defaultView)!=null?a:window,f=l.getBoundingClientRect(),p=mr(l,f),{top:h,left:m,bottom:y,right:w}=p,v=-Math.floor(h),g=-Math.floor(m),b=-Math.floor(c-w),_=-Math.floor(d-y),O=`${v}px ${b}px ${_}px ${g}px`;this.boundingClientRect=f,Ye(this,zt,new IntersectionObserver(I=>{const[M]=I,{intersectionRect:T}=M;(M.intersectionRatio!==1?M.intersectionRatio:ft.intersectionRatio(T,mr(l)))!==1&&le(this,Zn).call(this)},{threshold:Ua,rootMargin:O,root:u})),le(this,zt).observe(l),sd(this,$s,hd).call(this)},fd)),this.boundingClientRect=e.getBoundingClientRect(),Ye(this,Ft,Dh(e,this.boundingClientRect));let r=!0;this.callback=i=>{r&&(r=!1,n.skipInitial)||t(i)};const s=e.ownerDocument;n?.debug&&(Ye(this,Ne,document.createElement("div")),le(this,Ne).style.background="rgba(0,0,0,0.15)",le(this,Ne).style.position="fixed",le(this,Ne).style.pointerEvents="none",s.body.appendChild(le(this,Ne))),Ye(this,Yn,new IntersectionObserver(i=>{var o,a;const l=i[i.length-1],{boundingClientRect:u,isIntersecting:d}=l,{width:c,height:f}=u,p=le(this,Ft);Ye(this,Ft,d),!(!c&&!f)&&(p&&!d?((o=le(this,zt))==null||o.disconnect(),this.callback(null),(a=le(this,$t))==null||a.disconnect(),Ye(this,$t,void 0),le(this,Ne)&&(le(this,Ne).style.visibility="hidden")):le(this,Zn).call(this),d&&!le(this,$t)&&(Ye(this,$t,new Ph(le(this,Zn))),le(this,$t).observe(e)))},{threshold:Ua,root:s})),le(this,Ft)&&!n.skipInitial&&this.callback(this.boundingClientRect),le(this,Yn).observe(e)}};Ft=new WeakMap;Ss=new WeakMap;$t=new WeakMap;zt=new WeakMap;Yn=new WeakMap;Ne=new WeakMap;cr=new WeakMap;Zn=new WeakMap;$s=new WeakSet;hd=function(){le(this,cr)||(sd(this,$s,pd).call(this),!Ih(this.boundingClientRect,le(this,Ss))&&(this.callback(this.boundingClientRect),Ye(this,Ss,this.boundingClientRect)))};pd=function(){if(le(this,Ne)){const{top:e,left:t,width:n,height:r}=mr(this.element);le(this,Ne).style.overflow="hidden",le(this,Ne).style.visibility="visible",le(this,Ne).style.top=`${Math.floor(e)}px`,le(this,Ne).style.left=`${Math.floor(t)}px`,le(this,Ne).style.width=`${Math.floor(n)}px`,le(this,Ne).style.height=`${Math.floor(r)}px`}};var qr=new WeakMap,Kr=new WeakMap;function Mh(e,t){let n=qr.get(e);return n||(n={disconnect:new gd(e,s=>{const i=qr.get(e);i&&i.callbacks.forEach(o=>o(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),qr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(qr.delete(e),n.disconnect())}}function jh(e,t){const n=new Set;for(const r of e){const s=Mh(r,t);n.add(s)}return()=>n.forEach(r=>r())}function Rh(e,t){var n;const r=e.ownerDocument;if(!Kr.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}),Kr.set(r,{disconnect:()=>o.abort(),listeners:a})}const{listeners:s,disconnect:i}=(n=Kr.get(r))!=null?n:{};return!s||!i?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(i(),Kr.delete(r))})}var Qn,Jn,us,Vi,Lh=class{constructor(e,t,n){this.callback=t,Ve(this,Qn),Ve(this,Jn,!1),Ve(this,us),Ve(this,Vi,ud(o=>{if(!le(this,Jn)&&o.target&&"contains"in o.target&&typeof o.target.contains=="function"){for(const a of le(this,us))if(o.target.contains(a)){this.callback(le(this,Qn).boundingClientRect);break}}},fd));const r=Eh(e),s=jh(r,t),i=Rh(e,le(this,Vi));Ye(this,us,r),Ye(this,Qn,new gd(e,t,n)),this.disconnect=()=>{le(this,Jn)||(Ye(this,Jn,!0),s(),i(),le(this,Qn).disconnect())}}};Qn=new WeakMap;Jn=new WeakMap;us=new WeakMap;Vi=new WeakMap;function Hi(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function mn(e){try{Hi(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function Va(e){return!ad||!e?!1:e===Mn(e).scrollingElement}function md(e){var t,n;const r=Qe(e),s=Va(e)?_h(e):Ks(e),i=r.visualViewport,o=Va(e)?{height:(t=i?.height)!=null?t:r.innerHeight,width:(n=i?.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,d=a.current.y>=a.max.y,c=a.current.x>=a.max.x;return{rect:s,position:a,isTop:l,isLeft:u,isBottom:d,isRight:c}}function Nh(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:i,position:o}=md(e),{x:a,y:l}=t??{x:0,y:0},u=!n&&o.current.y+l>0,d=!r&&o.current.y+l<o.max.y,c=!s&&o.current.x+a>0,f=!i&&o.current.x+a<o.max.x;return{top:u,bottom:d,left:c,right:f,x:c||f,y:u||d}}var ta=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 s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Ts=new ta(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Fh=new ta(e=>setTimeout(e,50)),Os=new Map,zh=Os.clear.bind(Os);function gt(e,t=!1){if(!t)return Ha(e);let n=Os.get(e);return n||(n=Ha(e),Os.set(e,n),Fh.schedule(zh),n)}function Ha(e){return Qe(e).getComputedStyle(e)}function Wh(e,t=gt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function Bh(e,t=gt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?n.test(i):!1})}var Gh={excludeElement:!0,escapeShadowDOM:!0};function Xi(e,t=Gh){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,i=new Set;function o(a){if(n!=null&&i.size>=n||!a)return i;if(Zo(a)&&a.scrollingElement!=null&&!i.has(a.scrollingElement))return i.add(a.scrollingElement),i;if(s&&Jo(a))return o(a.host);if(!Pt(a))return od(a)?o(a.parentElement):i;if(i.has(a))return i;const l=gt(a,!0);if(r&&a===e||Bh(a,l)&&i.add(a),Wh(a,l)){const{scrollingElement:u}=a.ownerDocument;return u&&i.add(u),i}return o(a.parentNode)}return e?o(e):i}function kn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=_n(e);for(;r;){if(r===t)return n;const s=Ks(r),{x:i,y:o}=qh(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*i,n.scaleY=n.scaleY*o,r=_n(r)}return n}function qh(e,t=Ks(e)){const n=Math.round(t.width),r=Math.round(t.height);if(Pt(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=gt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function Kh(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 vr(e){if(!e||e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Us(e){var t,n,r,s,i,o,a,l,u;const{scale:d,transform:c,translate:f}=e,p=Kh(d),h=vr(f),m=Uh(c);if(!m&&!p&&!h)return null;const y={x:(t=p?.x)!=null?t:1,y:(n=p?.y)!=null?n:1},w={x:(r=h?.x)!=null?r:0,y:(s=h?.y)!=null?s:0},v={x:(i=m?.x)!=null?i:0,y:(o=m?.y)!=null?o:0,scaleX:(a=m?.scaleX)!=null?a:1,scaleY:(l=m?.scaleY)!=null?l:1};return{x:w.x+v.x,y:w.y+v.y,z:(u=h?.z)!=null?u:0,scaleX:y.x*v.scaleX,scaleY:y.y*v.scaleY}}function Uh(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 tt=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(tt||{}),Vh={x:.2,y:.2},Hh={x:10,y:10};function Xh(e,t,n,r=25,s=Vh,i=Hh){const{x:o,y:a}=t,{rect:l,isTop:u,isBottom:d,isLeft:c,isRight:f}=md(e),p=kn(e),h=gt(e,!0),m=Us(h),y=m!==null?m?.scaleX<0:!1,w=m!==null?m?.scaleY<0:!1,v=new ft(l.left*p.scaleX+p.x,l.top*p.scaleY+p.y,l.width*p.scaleX,l.height*p.scaleY),g={x:0,y:0},b={x:0,y:0},_={height:v.height*s.y,width:v.width*s.x};return _.height>0&&(!u||w&&!d)&&a<=v.top+_.height&&n?.y!==1&&o>=v.left-i.x&&o<=v.right+i.x?(g.y=w?1:-1,b.y=r*Math.abs((v.top+_.height-a)/_.height)):_.height>0&&(!d||w&&!u)&&a>=v.bottom-_.height&&n?.y!==-1&&o>=v.left-i.x&&o<=v.right+i.x&&(g.y=w?-1:1,b.y=r*Math.abs((v.bottom-_.height-a)/_.height)),_.width>0&&(!f||y&&!c)&&o>=v.right-_.width&&n?.x!==-1&&a>=v.top-i.y&&a<=v.bottom+i.y?(g.x=y?-1:1,b.x=r*Math.abs((v.right-_.width-o)/_.width)):_.width>0&&(!c||y&&!f)&&o<=v.left+_.width&&n?.x!==1&&a>=v.top-i.y&&a<=v.bottom+i.y&&(g.x=y?1:-1,b.x=r*Math.abs((v.left+_.width-o)/_.width)),{direction:g,speed:b}}function vd(e,{block:t="nearest",inline:n="nearest"}={}){if(!Pt(e))return;const r=Xi(e),s=[];for(const i of r){if(!Pt(i))continue;const{top:o,left:a}=Yh(e,i);let l=o,u=a;for(const d of s)l-=d.scrollTop,u-=d.scrollLeft;if(t!=="none"){const d=l<i.scrollTop,c=l+e.offsetHeight>i.scrollTop+i.clientHeight;d!==c&&(t==="center"?i.scrollTop=l-i.clientHeight/2+e.offsetHeight/2:d?i.scrollTop=l:i.scrollTop=l+e.offsetHeight-i.clientHeight)}if(n!=="none"){const d=u<i.scrollLeft,c=u+e.offsetWidth>i.scrollLeft+i.clientWidth;d!==c&&(n==="center"?i.scrollLeft=u-i.clientWidth/2+e.offsetWidth/2:d?i.scrollLeft=u:i.scrollLeft=u+e.offsetWidth-i.clientWidth)}s.push(i)}}function Xa(e){let t=0,n=0,r=e;for(;r;){t+=r.offsetTop,n+=r.offsetLeft;const s=r.offsetParent;if(!Pt(s))break;t+=s.clientTop,n+=s.clientLeft,r=s}return{top:t,left:n}}function Yh(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 Zh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left+i+(1-r)*parseFloat(n),l=e.top+o+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width*r:e.width,d=s?e.height*s:e.height;return{width:u,height:d,top:l,right:a+u,bottom:l+d,left:a}}function Qh(e,t,n){const{scaleX:r,scaleY:s,x:i,y:o}=t,a=e.left-i-(1-r)*parseFloat(n),l=e.top-o-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),u=r?e.width/r:e.width,d=s?e.height/s:e.height;return{width:u,height:d,top:l,right:a+u,bottom:l+d,left:a}}function bd({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}function Ya(e,t=gt(e).translate,n=!0){if(n){const r=id(e,s=>"translate"in s);if(r){const{translate:s=""}=r[0];if(typeof s=="string"){const i=vr(s);if(i)return i}}}if(t){const r=vr(t);if(r)return r}return{x:0,y:0,z:0}}var Jh=new ta(e=>setTimeout(e,0)),dr=new Map,ep=dr.clear.bind(dr);function tp(e){const t=e.ownerDocument;let n=dr.get(t);if(n)return n;n=t.getAnimations(),dr.set(t,n),Jh.schedule(ep);const r=n.filter(s=>qs(s.effect)&&s.effect.target===e);return dr.set(e,r),n}function np(e,t){const n=tp(e).filter(r=>{var s,i;if(qs(r.effect)){const{target:o}=r.effect;if((i=o&&((s=t.isValidTarget)==null?void 0:s.call(t,o)))!=null?i:!0)return r.effect.getKeyframes().some(l=>{for(const u of t.properties)if(l[u])return!0})}}).map(r=>{const{effect:s,currentTime:i}=r,o=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof o=="number"&&typeof i=="number"&&i<o)return r.currentTime=o,()=>{r.currentTime=i}});if(n.length>0)return()=>n.forEach(r=>r?.())}var ut=class extends ft{constructor(e,t={}){var n,r,s,i;const{frameTransform:o=kn(e),ignoreTransforms:a,getBoundingClientRect:l=Ks}=t,u=np(e,{properties:["transform","translate","scale","width","height"],isValidTarget:_=>(_!==e||Qo())&&_.contains(e)}),d=l(e);let{top:c,left:f,width:p,height:h}=d,m;const y=gt(e),w=Us(y),v={x:(n=w?.scaleX)!=null?n:1,y:(r=w?.scaleY)!=null?r:1},g=rp(e,y);u?.(),w&&(m=Qh(d,w,y.transformOrigin),(a||g)&&(c=m.top,f=m.left,p=m.width,h=m.height));const b={width:(s=m?.width)!=null?s:p,height:(i=m?.height)!=null?i:h};if(g&&!a&&m){const _=Zh(m,g,y.transformOrigin);c=_.top,f=_.left,p=_.width,h=_.height,v.x=g.scaleX,v.y=g.scaleY}o&&(a||(f*=o.scaleX,p*=o.scaleX,c*=o.scaleY,h*=o.scaleY),f+=o.x,c+=o.y),super(f,c,p,h),this.scale=v,this.intrinsicWidth=b.width,this.intrinsicHeight=b.height}};function rp(e,t){const n=e.getAnimations();if(!n.length)return null;let r,s,i,o=!1;for(const a of n){if(a.playState!=="running")continue;const l=qs(a.effect)?a.effect.getKeyframes():[],u=l[l.length-1];if(!u)continue;const{transform:d,translate:c,scale:f}=u;typeof d=="string"&&d&&(r=d,o=!0),typeof c=="string"&&c&&(s=c,o=!0),typeof f=="string"&&f&&(i=f,o=!0)}return o?Us({transform:r??t.transform,translate:s??t.translate,scale:i??t.scale}):null}function ur(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 sp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(ur(n))for(const[r,s]of Object.entries(e)){const i=`${t}${r}`;this.initial.has(i)||this.initial.set(i,n.style.getPropertyValue(i)),n.style.setProperty(i,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(ur(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(ur(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function Ut(e){return e?e instanceof Qe(e).Element||Ar(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function br(e){if(!e)return!1;const{KeyboardEvent:t}=Qe(e.target);return e instanceof t}function ip(e){if(!e)return!1;const{PointerEvent:t}=Qe(e.target);return e instanceof t}function op(e){if(!Ut(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||ap(e)}function ap(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var ui={};function Yi(e){const t=ui[e]==null?0:ui[e]+1;return ui[e]=t,`${e}-${t}`}var na=({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 s=et.distance(t.shape.center,n);return{id:r,value:1/s,type:Pn.PointerIntersection,priority:An.High}}return null},lp=({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:s}=e,i=et.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Pn.ShapeIntersection,priority:An.Normal}}return null},yd=e=>{var t;return(t=na(e))!=null?t:lp(e)},cp=e=>{const{dragOperation:t,droppable:n}=e,{shape:r,position:s}=t;if(!n.shape)return null;const i=r?ft.from(r.current.boundingRectangle).corners:void 0,a=ft.from(n.shape.boundingRectangle).corners.reduce((l,u,d)=>{var c;return l+et.distance(et.from(u),(c=i?.[d])!=null?c:s.current)},0)/4;return{id:n.id,value:1/a,type:Pn.Collision,priority:An.Normal}},dp=Object.create,ra=Object.defineProperty,up=Object.defineProperties,fp=Object.getOwnPropertyDescriptor,hp=Object.getOwnPropertyDescriptors,Es=Object.getOwnPropertySymbols,xd=Object.prototype.hasOwnProperty,wd=Object.prototype.propertyIsEnumerable,_d=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),jn=e=>{throw TypeError(e)},Zi=(e,t,n)=>t in e?ra(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yr=(e,t)=>{for(var n in t||(t={}))xd.call(t,n)&&Zi(e,n,t[n]);if(Es)for(var n of Es(t))wd.call(t,n)&&Zi(e,n,t[n]);return e},sa=(e,t)=>up(e,hp(t)),Za=(e,t)=>ra(e,"name",{value:t,configurable:!0}),kd=(e,t)=>{var n={};for(var r in e)xd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Es)for(var r of Es(e))t.indexOf(r)<0&&wd.call(e,r)&&(n[r]=e[r]);return n},Rn=e=>{var t;return[,,,dp((t=e?.[_d("metadata")])!=null?t:null)]},Sd=["class","method","getter","setter","accessor","field","value","get","set"],er=e=>e!==void 0&&typeof e!="function"?jn("Function expected"):e,pp=(e,t,n,r,s)=>({kind:Sd[e],name:t,metadata:r,addInitializer:i=>n._?jn("Already initialized"):s.push(er(i||null))}),Qt=(e,t)=>Zi(t,_d("metadata"),e[3]),Me=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},it=(e,t,n,r,s,i)=>{var o,a,l,u,d,c=t&7,f=!!(t&8),p=!!(t&16),h=c>3?e.length+1:c?f?1:2:0,m=Sd[c+5],y=c>3&&(e[h-1]=[]),w=e[h]||(e[h]=[]),v=c&&(!p&&!f&&(s=s.prototype),c<5&&(c>3||!p)&&fp(c<4?s:{get[n](){return ye(this,i)},set[n](b){return qe(this,i,b)}},n));c?p&&c<4&&Za(i,(c>2?"set ":c>1?"get ":"")+n):Za(s,n);for(var g=r.length-1;g>=0;g--)u=pp(c,n,l={},e[3],w),c&&(u.static=f,u.private=p,d=u.access={has:p?b=>gp(s,b):b=>n in b},c^3&&(d.get=p?b=>(c^1?ye:Vt)(b,s,c^4?i:v.get):b=>b[n]),c>2&&(d.set=p?(b,_)=>qe(b,s,_,c^4?i:v.set):(b,_)=>b[n]=_)),a=(0,r[g])(c?c<4?p?i:v[m]:c>4?void 0:{get:v.get,set:v.set}:s,u),l._=1,c^4||a===void 0?er(a)&&(c>4?y.unshift(a):c?p?i=a:v[m]=a:s=a):typeof a!="object"||a===null?jn("Object expected"):(er(o=a.get)&&(v.get=o),er(o=a.set)&&(v.set=o),er(o=a.init)&&y.unshift(o));return c||Qt(e,s),v&&ra(s,n,v),p?c^4?i:v:s},ia=(e,t,n)=>t.has(e)||jn("Cannot "+n),gp=(e,t)=>Object(t)!==t?jn('Cannot use the "in" operator on this value'):e.has(t),ye=(e,t,n)=>(ia(e,t,"read from private field"),n?n.call(e):t.get(e)),Ce=(e,t,n)=>t.has(e)?jn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qe=(e,t,n,r)=>(ia(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Vt=(e,t,n)=>(ia(e,t,"access private method"),n),Qa={role:"button",roleDescription:"draggable"},mp="dnd-kit-description",vp="dnd-kit-announcement",bp={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."},yp={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 xp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function wp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function _p(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 kp=["dragover","dragmove"],Sp=class extends We{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=mp,announcement:s=vp}={},announcements:i=yp,screenReaderInstructions:o=bp,debounce:a=500}=t??{},l=n?`${r}-${n}`:Yi(r),u=n?`${s}-${n}`:Yi(s);let d,c,f,p;const h=(_=p)=>{!f||!_||f?.nodeValue!==_&&(f.nodeValue=_)},m=()=>Ts.schedule(h),y=$p(m,a),w=Object.entries(i).map(([_,O])=>this.manager.monitor.addEventListener(_,(I,M)=>{const T=f;if(!T)return;const D=O?.(I,M);D&&T.nodeValue!==D&&(p=D,kp.includes(_)?y():(m(),y.cancel()))})),v=()=>{let _=[];d?.isConnected||(d=wp(l,o.draggable),_.push(d)),c?.isConnected||(c=_p(u),f=document.createTextNode(""),c.appendChild(f),_.push(c)),_.length>0&&document.body.append(..._)},g=new Set;function b(){for(const _ of g)_()}this.registerEffect(()=>{var _;g.clear();for(const O of this.manager.registry.draggables.value){const I=(_=O.handle)!=null?_:O.element;if(I){(!d||!c)&&g.add(v),(!xp(I)||Qo())&&!I.hasAttribute("tabindex")&&g.add(()=>I.setAttribute("tabindex","0")),!I.hasAttribute("role")&&I.tagName.toLowerCase()!=="button"&&g.add(()=>I.setAttribute("role",Qa.role)),I.hasAttribute("aria-roledescription")||g.add(()=>I.setAttribute("aria-roledescription",Qa.roleDescription)),I.hasAttribute("aria-describedby")||g.add(()=>I.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const D=String(O.isDragging);I.getAttribute(T)!==D&&g.add(()=>I.setAttribute(T,D))}const M=String(O.disabled);I.getAttribute("aria-disabled")!==M&&g.add(()=>I.setAttribute("aria-disabled",M))}}g.size>0&&Ts.schedule(b)}),this.destroy=()=>{super.destroy(),d?.remove(),c?.remove(),w.forEach(_=>_())}}};function $p(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Cs=new Map,$d,Td,Od,Ed,Qi,fr,xt,oa,Sn,Cd,Id,Dd,Ad,Mt=class extends(Qi=Dr,Ed=[fe],Od=[Ee],Td=[Ee],$d=[Ee],Qi){constructor(t,n){super(t,n),Me(xt,5,this),Ce(this,Sn),Ce(this,fr,new Set),Ce(this,oa,Me(xt,8,this,new Set)),Me(xt,11,this),this.registerEffect(Vt(this,Sn,Cd))}register(t){return ye(this,fr).add(t),()=>{ye(this,fr).delete(t)}}addRoot(t){return ue(()=>{const n=new Set(this.additionalRoots);n.add(t),this.additionalRoots=n}),()=>{ue(()=>{const n=new Set(this.additionalRoots);n.delete(t),this.additionalRoots=n})}}get sourceRoot(){var t;const{source:n}=this.manager.dragOperation;return ks((t=n?.element)!=null?t:null)}get targetRoot(){var t;const{target:n}=this.manager.dragOperation;return ks((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}};xt=Rn(Qi);fr=new WeakMap;oa=new WeakMap;Sn=new WeakSet;Cd=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of ye(this,fr))t.push(Vt(this,Sn,Id).call(this,n,r));return()=>{for(const n of t)n()}};Id=function(e,t){let n=Cs.get(e);n||(n=new Map,Cs.set(e,n));let r=n.get(t);if(!r){const i=Zo(e)?Vt(this,Sn,Dd).call(this,e,n,t):Vt(this,Sn,Ad).call(this,e,n,t);if(!i)return()=>{};r=i,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};Dd=function(e,t,n){var r;const s=e.createElement("style"),{nonce:i}=(r=this.options)!=null?r:{};i&&s.setAttribute("nonce",i),s.textContent=n,e.head.prepend(s);const o=new MutationObserver(a=>{for(const l of a)for(const u of Array.from(l.removedNodes))if(u===s){e.head.prepend(s);return}});return o.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{o.disconnect(),s.remove(),t.delete(n),t.size===0&&Cs.delete(e)}}};Ad=function(e,t,n){"adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets);const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return null;const i=new s;return i.replaceSync(n),e.adoptedStyleSheets.push(i),{refCount:0,cleanup:()=>{var o;if(Jo(e)&&((o=e.host)!=null&&o.isConnected)){const a=e.adoptedStyleSheets.indexOf(i);a!==-1&&e.adoptedStyleSheets.splice(a,1)}t.delete(n),t.size===0&&Cs.delete(e)}}};it(xt,4,"additionalRoots",Ed,Mt,oa);it(xt,2,"sourceRoot",Od,Mt);it(xt,2,"targetRoot",Td,Mt);it(xt,2,"roots",$d,Mt);Qt(xt,Mt);Mt.configure=Ir(Mt);var Vs=Mt,Tp=class extends We{constructor(e,t){super(e,t),this.manager=e;const{cursor:n="grabbing"}=t??{},r=e.registry.plugins.get(Vs),s=r?.register(`* { cursor: ${n} !important; }`);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}}},Pr="data-dnd-",Ji=`${Pr}dropping`,Le="--dnd-",dt=`${Pr}dragging`,Is=`${Pr}placeholder`,Op=[dt,Is,"popover","aria-pressed","aria-grabbing"],Ep=["view-transition-name"],Cp=`
|
|
9
9
|
:is(:root,:host) [${dt}] {
|
|
10
10
|
position: fixed !important;
|
|
11
11
|
pointer-events: none !important;
|
|
@@ -64,66 +64,66 @@
|
|
|
64
64
|
display: none;
|
|
65
65
|
visibility: hidden;
|
|
66
66
|
}
|
|
67
|
-
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Cp(e,t="hidden"){return ue(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Ip(n,r.registry.droppables),i=[],o=Sh(n),{remove:a}=o;return Dp(s,o,i),Ap(o,t),o.remove=()=>{i.forEach(l=>l()),a.call(o)},o})}function Ip(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Pr}${Yi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Dp(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),Ui.set(a,o),n.push(()=>{Ui.delete(a),r.proxy=void 0})}}function Ap(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Is,t)}function Dd(e,t){return e===t?!0:_n(e)===_n(t)}function Qa(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ut(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>mn(t))}function eo(e){return e.tagName==="TR"}function Pp(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Tp.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(ur(e)&&ur(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(Op.includes(c)||c.startsWith(Le))continue;const d=u.getPropertyValue(c);t.style.setProperty(c,d)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function Mp(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),mn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),mn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),mn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function jp(e){return new ResizeObserver(()=>{var t,n,r;const s=new ut(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,l=od();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),eo(e.element)&&eo(e.placeholder)){const v=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(v.map(w=>w.style.width));for(const[w,g]of v.entries()){const m=y[w];g.style.width=`${m.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,f=s.width-e.widthOffset,p=s.height-e.heightOffset,h=e.frameTransform;e.dragOperation.shape=new ft(c*h.scaleX+h.x,d*h.scaleY+h.y,f*h.scaleX,p*h.scaleY)})}var Rp=250,Lp="ease";function Np(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const g=i({source:e.source,element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(g).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:o=Rp,easing:a=Lp}=i??{};mn(e.feedbackElement);const[,l]=(t=rd(e.feedbackElement,g=>"translate"in g))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,c={frameTransform:Dd(e.feedbackElement,u)?null:void 0},d=new ut(e.feedbackElement,c),f=(r=vr(gt(e.feedbackElement).translate))!=null?r:e.translate,p=new ut(u,c),h=ft.delta(d,p,e.alignment),v={x:f.x-h.x,y:f.y-h.y},y=Math.round(d.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${d.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${d.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},w=Math.round(d.intrinsicWidth)!==Math.round(p.intrinsicWidth)?{minWidth:[`${d.intrinsicWidth}px`,`${p.intrinsicWidth}px`],maxWidth:[`${d.intrinsicWidth}px`,`${p.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Le),e.feedbackElement.setAttribute(Ji,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),md({element:e.feedbackElement,keyframes:ra(yr(yr({},y),w),{translate:[`${f.x}px ${f.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:Jo(Qe(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Ji),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Ad,to,xr,oa,fs,Pd,Md,$n=class extends(to=We,Ad=[fe],to){constructor(t,n){super(t,n),Ce(this,fs),Ce(this,oa,Me(xr,8,this)),Me(xr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Vs),s=r?.register(Ep);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Vt(this,fs,Pd).bind(this,r)),this.registerEffect(Vt(this,fs,Md))}};xr=Rn(to);oa=new WeakMap;fs=new WeakSet;Pd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ks(t);if(n)return e.addRoot(n)};Md=function(){var e,t,n,r,s,i,o;const{state:a,manager:l,options:u}=this,{dragOperation:c}=l,{position:d,source:f,status:p}=c;if(p.idle){a.current={},a.initial={};return}if(!f)return;const{element:h}=f,v=f.pluginConfig($n),y=(t=(e=v?.feedback)!=null?e:u?.feedback)!=null?t:"default",w=typeof y=="function"?y(f,l):y;if(!h||w==="none"||!p.initialized||p.initializing)return;const{initial:g}=a,m=(n=this.overlay)!=null?n:h,b=kn(m),_=kn(h),O=!Dd(h,m),E=new ut(h,{frameTransform:O?_:null,ignoreTransforms:!O}),I={x:_.scaleX/b.scaleX,y:_.scaleY/b.scaleY};let{width:T,height:D,top:L,left:R}=E;O&&(T=T/I.x,D=D/I.y);const z=new rp(m),K=gt(h),{transition:G,translate:X,boxSizing:Y,paddingBlockStart:se,paddingBlockEnd:te,paddingInlineStart:A,paddingInlineEnd:B,borderInlineStartWidth:N,borderInlineEndWidth:j,borderBlockStartWidth:q,borderBlockEndWidth:J}=K,ee=G.split(",").filter(be=>!/^\s*(transform|translate|scale)\b/.test(be)).join(","),H=Us(K),S=K.transform,P=w==="clone",F=Y==="content-box",V=F?parseInt(A)+parseInt(B)+parseInt(N)+parseInt(j):0,ie=F?parseInt(se)+parseInt(te)+parseInt(q)+parseInt(J):0,Z=w!=="move"&&!this.overlay?Cp(f,P?"clone":"hidden"):null,oe=ue(()=>br(l.dragOperation.activatorEvent));if(!g.translate){if(this.overlay&&H)g.translate={x:H.x,y:H.y};else if(X!=="none"){const be=vr(X);be&&(g.translate=be)}}if(!g.transformOrigin){const be=ue(()=>d.current),Ie=R+((r=H?.x)!=null?r:0),He=L+((s=H?.y)!=null?s:0);g.transformOrigin={x:(be.x-Ie*b.scaleX-b.x)/(T*b.scaleX),y:(be.y-He*b.scaleY-b.y)/(D*b.scaleY)}}const{transformOrigin:W}=g,Q=L*b.scaleY+b.y,ne=R*b.scaleX+b.x;if(!g.coordinates&&(g.coordinates={x:ne,y:Q},I.x!==1||I.y!==1)){const{scaleX:be,scaleY:Ie}=_,{x:He,y:St}=W;g.coordinates.x+=(T*be-T)*He,g.coordinates.y+=(D*Ie-D)*St}g.dimensions||(g.dimensions={width:T,height:D}),g.frameTransform||(g.frameTransform=b);const re={x:g.coordinates.x-ne,y:g.coordinates.y-Q},ce={width:(g.dimensions.width*g.frameTransform.scaleX-T*b.scaleX)*W.x,height:(g.dimensions.height*g.frameTransform.scaleY-D*b.scaleY)*W.y},pe={x:re.x/b.scaleX+ce.width,y:re.y/b.scaleY+ce.height},M={left:R+pe.x,top:L+pe.y};m.setAttribute(dt,"true");const U=ue(()=>c.transform),de=(i=g.translate)!=null?i:{x:0,y:0},ve=U.x*b.scaleX+de.x,Re=U.y*b.scaleY+de.y,Nn=od();z.set({width:T-V,height:D-ie,top:M.top+Nn.y,left:M.left+Nn.x,translate:`${ve}px ${Re}px 0`,transform:this.overlay?"none":S,transition:ee?`${ee}, translate 0ms linear`:"translate 0ms linear",scale:O?`${I.x} ${I.y}`:"","transform-origin":`${W.x*100}% ${W.y*100}%`},Le),Z&&(h.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(h)),Hi(m)&&(m.hasAttribute("popover")||m.setAttribute("popover","manual"),mn(m),m.addEventListener("beforetoggle",Qa));let mt,Fn,vt;const Sa=jp({placeholder:Z,element:h,feedbackElement:m,frameTransform:b,transformOrigin:W,width:T,height:D,top:L,left:R,widthOffset:V,heightOffset:ie,delta:pe,styles:z,dragOperation:c,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>mt,getSavedCellWidths:()=>vt,setSavedCellWidths:be=>{vt=be}}),$a=new ut(m);ue(()=>c.shape=$a);const ei=Qe(m),Ta=be=>{this.manager.actions.stop({event:be})},Ju=Jo(ei);oe&&ei.addEventListener("resize",Ta),ue(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&(Sa.observe(Z),mt=Pp(h,Z,P),Fn=Mp(h,Z,m));const Oa=(o=l.dragOperation.source)==null?void 0:o.id,ef=()=>{var be;if(!oe||Oa==null)return;const Ie=l.registry.draggables.get(Oa),He=(be=Ie?.handle)!=null?be:Ie?.element;Pt(He)&&He.focus()},ti=()=>{mt?.disconnect(),Fn?.disconnect(),Sa.disconnect(),ei.removeEventListener("resize",Ta),Hi(m)&&(m.removeEventListener("beforetoggle",Qa),m.removeAttribute("popover")),m.removeAttribute(dt),z.reset();const be=()=>{var Ie;if(vt&&eo(h)){const ni=Array.from(h.cells);for(const[zr,Jt]of ni.entries())Jt.style.width=(Ie=vt[zr])!=null?Ie:""}f.status="idle";const He=a.current.translate!=null,St=c.status.dragging;Z&&(!St&&He||Z.parentElement!==m.parentElement)&&m.isConnected&&Z.replaceWith(m),Z?.remove()};m===this.overlay?setTimeout(be,0):be()},tf=u?.dropAnimation,Ea=this,nf=Er(()=>{var be,Ie,He;const{transform:St,status:ni}=c;if(!(!St.x&&!St.y&&!a.current.translate)&&ni.dragging){const zr=(be=g.translate)!=null?be:{x:0,y:0},Jt={x:St.x/b.scaleX+zr.x,y:St.y/b.scaleY+zr.y},Ca=a.current.translate,rf=ue(()=>c.modifiers),ri=ue(()=>{var Wn;return(Wn=c.shape)==null?void 0:Wn.current}),zn=u?.keyboardTransition,Ia=oe&&!Ju&&zn!==null?`${(Ie=zn?.duration)!=null?Ie:250}ms ${(He=zn?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(z.set({transition:ee?`${ee}, translate ${Ia}`:`translate ${Ia}`,translate:`${Jt.x}px ${Jt.y}px 0`},Le),mt?.takeRecords(),ri&&ri!==$a&&Ca&&!rf.length){const Wn=et.delta(Jt,Ca);c.shape=ft.from(ri.boundingRectangle).translate(Wn.x*b.scaleX,Wn.y*b.scaleY)}else c.shape=new ut(m);a.current.translate=Jt}},function(){if(c.status.dropped){this.dispose(),f.status="dropping";const be=v?.dropAnimation!==void 0?v.dropAnimation:Ea.dropAnimation!==void 0?Ea.dropAnimation:tf;let Ie=a.current.translate;const He=Ie!=null;if(!Ie&&h!==m&&(Ie={x:0,y:0}),!Ie||be===null){ti();return}l.renderer.rendering.then(()=>{Np({source:f,element:h,feedbackElement:m,placeholder:Z,translate:Ie,moved:He,transition:G,alignment:f.alignment,styles:z,animation:be??void 0,getElementMutationObserver:()=>mt,cleanup:ti,restoreFocus:ef})})}});return()=>{ti(),nf()}};it(xr,4,"overlay",Ad,$n,oa);Qt(xr,$n);$n.configure=Ir($n);var aa=$n,Bn=!0,Fp=!1,jd,Rd,Ld,Nd,Et,la,ca;Nd=(Ld=[fe],tt.Forward),Rd=(jd=[fe],tt.Reverse);var wr=class{constructor(){Ce(this,la,Me(Et,8,this,Bn)),Me(Et,11,this),Ce(this,ca,Me(Et,12,this,Bn)),Me(Et,15,this)}isLocked(e){return e===tt.Idle?!1:e==null?this[tt.Forward]===Bn&&this[tt.Reverse]===Bn:this[e]===Bn}unlock(e){e!==tt.Idle&&(this[e]=Fp)}};Et=Rn(null);la=new WeakMap;ca=new WeakMap;it(Et,4,Nd,Ld,wr,la);it(Et,4,Rd,jd,wr,ca);Qt(Et,wr);var zp=[tt.Forward,tt.Reverse],Ja=class{constructor(){this.x=new wr,this.y=new wr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Wp=class extends We{constructor(e){super(e);const t=Tn(new Ja);let n=null;this.signal=t,st(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Ja;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:el(s.x,n.x),y:el(s.y,n.y)},o=t.peek();Te(()=>{for(const a of hc)for(const l of zp)i[a]===l&&o[a].unlock(l);t.value=o})}n=s})}get current(){return this.signal.peek()}};function el(e,t){return Math.sign(e-t)}var Fd,no,_r,da,Tt,ro,Mr=class extends(no=Dr,Fd=[fe],no){constructor(e){super(e),Ce(this,da,Me(_r,8,this,!1)),Me(_r,11,this),Ce(this,Tt),Ce(this,ro,()=>{if(!ye(this,Tt))return;const{element:i,by:o}=ye(this,Tt);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return qe(this,Tt,void 0),!1;const{position:u}=this.manager.dragOperation,c=u?.current;if(c){const{by:d}=i??{},f=d?{x:tl(d.x),y:tl(d.y)}:void 0,p=f?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const h of l){const v=Lh(h,d);if(v.x||v.y){const{speed:y,direction:w}=Hh(h,c,f,o?.acceleration,o?.threshold);if(p)for(const g of hc)p[g].isLocked(w[g])&&(y[g]=0,w[g]=0);if(w.x||w.y){const{x:g,y:m}=d??w,b=g*y.x,_=m*y.y;if(b||_){const O=(a=ye(this,Tt))==null?void 0:a.by;if(this.autoScrolling&&O&&(O.x&&!b||O.y&&!_))continue;return qe(this,Tt,{element:h,by:{x:b,y:_}}),Ts.schedule(ye(this,ro)),!0}}}}}return qe(this,Tt,void 0),!1};let t=null,n=null;const r=Ai(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=ad(ks(o?.element),i.current);return a&&(t=a),a??t}),s=Ai(()=>{const i=r.value,{documentElement:o}=Mn(i);if(!i||i===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=Xi(l,{excludeElement:!1});return n=u,u}}if(i){const a=Xi(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ot);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Wp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!br(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};_r=Rn(no);da=new WeakMap;Tt=new WeakMap;ro=new WeakMap;it(_r,4,"autoScrolling",Fd,Mr,da);Qt(_r,Mr);function tl(e){return e>0?tt.Forward:e<0?tt.Reverse:tt.Idle}var Bp=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))}},Gp=new Bp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),qp=10,so=class extends We{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Mr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=st(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.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(()=>Gp.schedule(()=>r.scroll(void 0,u)),qp);return()=>{clearInterval(d)}}else r.autoScrolling=!1}})}};so.configure=Ir(so);var zd=so,nl={capture:!0,passive:!0},tr,Kp=class extends Dr{constructor(e){super(e),Ce(this,tr),this.handleScroll=()=>{ye(this,tr)==null&&qe(this,tr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),qe(this,tr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=st(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,nl),()=>{o.removeEventListener("scroll",this.handleScroll,nl)}}})}};tr=new WeakMap;var Up="* { user-select: none !important; -webkit-user-select: none !important; }",Vp=class extends We{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Vs),n=t?.register(Up);if(this.destroy=st(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return fi(),document.addEventListener("selectionchange",fi,{capture:!0}),()=>{document.removeEventListener("selectionchange",fi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function fi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var nr=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,Ds=class extends xn{constructor(t,n){super(t),this.manager=t,this.options=n,Ce(this,dn,[]),this.listeners=new ld,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Ut(r.target)||s.disabled)return;const{keyboardCodes:o=nr.keyboardCodes,preventActivation:a=nr.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return st(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{br(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),gd(s);const{center:i}=new ut(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Mn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];ye(this,dn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=nr.keyboardCodes}=r??{};if(en(t,[...s.end,...s.cancel])){t.preventDefault();const i=en(t,s.cancel);this.handleEnd(t,i);return}en(t,s.up)?this.handleMove("up",t):en(t,s.down)&&this.handleMove("down",t),en(t,s.left)?this.handleMove("left",t):en(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:nr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!i){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(zd);t?.disabled===!1&&(t.disable(),ye(this,dn).push(()=>{t.enable()}))}cleanup(){ye(this,dn).forEach(t=>t()),qe(this,dn,[])}destroy(){this.cleanup(),this.listeners.clear()}};dn=new WeakMap;Ds.configure=Ir(Ds);Ds.defaults=nr;var Wd=Ds;function en(e,t){return t.includes(e.code)}var Wt,Hp=class extends Kc{constructor(){super(...arguments),Ce(this,Wt)}onEvent(e){switch(e.type){case"pointerdown":qe(this,Wt,wn(e));break;case"pointermove":if(!ye(this,Wt))return;const{x:t,y:n}=wn(e),r={x:t-ye(this,Wt).x,y:n-ye(this,Wt).y},{tolerance:s}=this.options;if(s&&Wi(r,s)){this.abort();return}Wi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){qe(this,Wt,void 0)}};Wt=new WeakMap;var un,Bt,Xp=class extends Kc{constructor(){super(...arguments),Ce(this,un),Ce(this,Bt)}onEvent(e){switch(e.type){case"pointerdown":qe(this,Bt,wn(e)),qe(this,un,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ye(this,Bt))return;const{x:t,y:n}=wn(e),r={x:t-ye(this,Bt).x,y:n-ye(this,Bt).y};Wi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ye(this,un)&&(clearTimeout(ye(this,un)),qe(this,Bt,void 0),qe(this,un,void 0))}};un=new WeakMap;Bt=new WeakMap;var gn=class{};gn.Delay=Xp;gn.Distance=Hp;var io=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Ut(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new gn.Delay({value:250,tolerance:5})]:ip(s)&&!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||!Ut(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Th(r);return s===t.element?!1:!!s}}),fn,As=class extends xn{constructor(t,n){super(t),this.manager=t,this.options=n,Ce(this,fn,new Set),this.listeners=new ld,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},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:s=io.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return st(()=>{var s;const i=new AbortController,{signal:o}=i,a=u=>{sp(u)&&this.handlePointerDown(u,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(Qp(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ut(t.target)||n.disabled||Yp(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=io.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Pt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=kn(n.element),{x:l,y:u}=wn(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 vh(c,v=>this.handleStart(n,v));d.signal.onabort=()=>this.handleCancel(t),d.onEvent(t),this.controller=d;const f=Ki(),p=this.listeners.bind(f,[{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:Ur,options:{capture:!0}}]),h=()=>{p(),this.initialCoordinates=void 0};ye(this,fn).add(h)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=wn(t),o=kn(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Ts.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:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Mn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ut(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:Ur,options:{passive:!1}},{type:"click",listener:Ur},{type:"contextmenu",listener:Ur},{type:"keydown",listener:this.handleKeyDown}]);ye(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},ye(this,fn).forEach(n=>n()),ye(this,fn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;As.configure=Ir(As);As.defaults=io;var oo=As;function Yp(e){return"sensor"in e}function Ur(e){e.preventDefault()}function Zp(){}var rl=new WeakSet;function Qp(e){!e||rl.has(e)||(e.addEventListener("touchmove",Zp,{capture:!1,passive:!1}),rl.add(e))}var vn={modifiers:[],plugins:[kp,zd,$p,aa,Vp],sensors:[oo,Wd]},Bd=class extends xh{constructor(e={}){const t=lt(e.plugins,vn.plugins),n=lt(e.sensors,vn.sensors),r=lt(e.modifiers,vn.modifiers);super(ra(yr({},e),{plugins:[Kp,Mr,Vs,...t],sensors:n,modifiers:r}))}},Gd,qd,ao,Ct,ua,fa,Hs=class extends(ao=ht,qd=[fe],Gd=[fe],ao){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=wd(n,["element","effects","handle"]);super(yr({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const d=((l=(a=this.sensors)==null?void 0:a.map(pr))!=null?l:[...u.sensors]).map(f=>{const p=f instanceof xn?f:u.registry.register(f.plugin),h=f instanceof xn?void 0:f.options;return p.bind(this,h)});return function(){d.forEach(p=>p())}}]},o),t),Ce(this,ua,Me(Ct,8,this)),Me(Ct,11,this),Ce(this,fa,Me(Ct,12,this)),Me(Ct,15,this),this.element=r,this.handle=i}};Ct=Rn(ao);ua=new WeakMap;fa=new WeakMap;it(Ct,4,"handle",qd,Hs,ua);it(Ct,4,"element",Gd,Hs,fa);Qt(Ct,Hs);var Kd,Ud,lo,It,ha,hi,Vd,Hd,hr,pa,Xs=class extends(lo=pt,Ud=[fe],Kd=[fe],lo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=wd(n,["element","effects"]);const{collisionDetector:o=vd}=i,a=u=>{const{manager:c,element:d}=this;if(!d||u===null){this.shape=void 0;return}if(!c)return;const f=new ut(d),p=ue(()=>this.shape);return f&&p?.equals(f)?p:(this.shape=f,f)},l=Tn(!1);super(ra(yr({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:u,manager:c}=this;if(!c)return;const{dragOperation:d}=c,{source:f}=d;l.value=!!(f&&d.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const c=new Rh(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),Ce(this,hr),Ce(this,ha,Me(It,8,this)),Me(It,11,this),Ce(this,pa,Me(It,12,this)),Me(It,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){qe(this,hr,e,Hd)}get element(){var e;return(e=this.proxy)!=null?e:ye(this,hr,Vd)}};It=Rn(lo);ha=new WeakMap;hr=new WeakSet;pa=new WeakMap;hi=it(It,20,"#element",Ud,hr,ha),Vd=hi.get,Hd=hi.set;it(It,4,"proxy",Kd,Xs,pa);Qt(It,Xs);function Jp(e){return e!=null&&typeof e=="object"&&"current"in e}function bn(e){var t;if(e!=null)return Jp(e)?(t=e.current)!=null?t:void 0:e}var eg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ln=eg?k.useLayoutEffect:k.useEffect;function tg(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Xd(e,t){const n=k.useRef(new Map),r=tg();return Ln(()=>{if(!e){n.current.clear();return}return st(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[l]=a,u=ue(()=>a[1]),c=e[l];u!==c&&(i=!0,n.current.set(l,c),o=(s=t?.(l,u,c))!=null?s:!1)}i&&(o?queueMicrotask(()=>sf.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function ng(e,t){e()}function tn(e){const t=k.useRef(e);return Ln(()=>{t.current=e},[e]),t}function Se(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function hs(e,t){const n=k.useRef(bn(e));Ln(()=>{const r=bn(e);r!==n.current&&(n.current=r,t(r))})}var rg=Object.defineProperty,sg=Object.defineProperties,ig=Object.getOwnPropertyDescriptors,Ps=Object.getOwnPropertySymbols,Yd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,sl=(e,t,n)=>t in e?rg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,og=(e,t)=>{for(var n in t||(t={}))Yd.call(t,n)&&sl(e,n,t[n]);if(Ps)for(var n of Ps(t))Zd.call(t,n)&&sl(e,n,t[n]);return e},ag=(e,t)=>sg(e,ig(t)),lg=(e,t)=>{var n={};for(var r in e)Yd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ps)for(var r of Ps(e))t.indexOf(r)<0&&Zd.call(e,r)&&(n[r]=e[r]);return n},cg=new Bd,Qd=k.createContext(cg),dg=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{i.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Ln(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),pi=[void 0,ot];function ug(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:l}=t,u=lg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const c=k.useRef(null),{plugins:d,modifiers:f,sensors:p}=u,h=lt(d,vn.plugins),v=lt(p,vn.sensors),y=lt(f,vn.modifiers),w=tn(s),g=tn(i),m=tn(a),b=tn(o),_=tn(l),O=tn(r),E=fg(()=>{var I;return(I=u.manager)!=null?I:new Bd(u)});return k.useEffect(()=>{if(!c.current)throw new Error("Renderer not found");const{renderer:I,trackRendering:T}=c.current,{monitor:D}=E;E.renderer=I;const L=[D.addEventListener("beforedragstart",R=>{const z=w.current;z&&T(()=>z(R,E))}),D.addEventListener("dragstart",R=>{var z;return(z=g.current)==null?void 0:z.call(g,R,E)}),D.addEventListener("dragover",R=>{const z=m.current;z&&T(()=>z(R,E))}),D.addEventListener("dragmove",R=>{const z=b.current;z&&T(()=>z(R,E))}),D.addEventListener("dragend",R=>{const z=_.current;z&&T(()=>z(R,E))}),D.addEventListener("collision",R=>{var z;return(z=O.current)==null?void 0:z.call(O,R,E)})];return()=>L.forEach(R=>R())},[E]),Se(h,()=>E&&(E.plugins=h),...pi),Se(v,()=>E&&(E.sensors=v),...pi),Se(y,()=>E&&(E.modifiers=y),...pi),x.jsxs(Qd.Provider,{value:E,children:[x.jsx(dg,{ref:c,children:n}),n]})}function fg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function hg(){return k.useContext(Qd)}function Jd(e){var t;const n=(t=hg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Ln(r.register,[n,r]),r}var pg=Object.create,eu=Object.defineProperty,gg=Object.getOwnPropertyDescriptor,tu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ys=e=>{throw TypeError(e)},mg=(e,t,n)=>t in e?eu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vg=e=>{var t;return[,,,pg((t=e?.[tu("metadata")])!=null?t:null)]},nu=["class","method","getter","setter","accessor","field","value","get","set"],ru=e=>e!==void 0&&typeof e!="function"?Ys("Function expected"):e,bg=(e,t,n,r,s)=>({kind:nu[e],name:t,metadata:r,addInitializer:i=>n._?Ys("Already initialized"):s.push(ru(i||null))}),yg=(e,t)=>mg(t,tu("metadata"),e[3]),xg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},su=(e,t,n,r,s,i)=>{for(var o,a,l,u,c=t&7,d=!1,f=!1,p=2,h=nu[c+5],v=e[p]||(e[p]=[]),y=(s=s.prototype,gg(s,n)),w=r.length-1;w>=0;w--)l=bg(c,n,a={},e[3],v),l.static=d,l.private=f,u=l.access={has:g=>n in g},u.get=g=>g[n],o=(0,r[w])(y[h],l),a._=1,ru(o)&&(y[h]=o);return y&&eu(s,n,y),s},iu=(e,t,n)=>t.has(e)||Ys("Cannot "+n),wg=(e,t,n)=>(iu(e,t,"read from private field"),t.get(e)),_g=(e,t,n)=>t.has(e)?Ys("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),kg=(e,t,n,r)=>(iu(e,t,"write to private field"),t.set(e,n),n),qt=class co{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new co(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 co(t,n)}},ou,au,uo,ps,jr,ga=class extends(uo=Yt,au=[Ee],ou=[Ee],uo){constructor(e){const t=qt.from(e);super(t,(n,r)=>qt.equals(n,r)),xg(jr,5,this),_g(this,ps,0),this.velocity={x:0,y:0}}get delta(){return qt.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=qt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-wg(this,ps),o=a=>Math.round(a/i*100);Te(()=>{kg(this,ps,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(qt.from(e)),this.velocity={x:0,y:0}}};jr=vg(uo);ps=new WeakMap;su(jr,2,"delta",au,ga);su(jr,2,"direction",ou,ga);yg(jr,ga);var lu=(e=>(e.Horizontal="x",e.Vertical="y",e))(lu||{});Object.values(lu);var Sg=({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 s=qt.distance(t.shape.center,n);return{id:r,value:1/s,type:Pn.PointerIntersection,priority:An.High}}return null},$g=({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:s}=e,i=qt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Pn.ShapeIntersection,priority:An.Normal}}return null},Tg=e=>{var t;return(t=Sg(e))!=null?t:$g(e)};function Og(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,l=Jd(c=>new Xs(ag(og({},e),{register:!1,element:bn(s)}),c)),u=Xd(l);return Se(i,()=>l.id=i),hs(s,c=>l.element=c),Se(o,()=>l.accept=o,void 0,ot),Se(t,()=>l.collisionDetector=t??Tg),Se(n,()=>n&&(l.data=n)),Se(r,()=>l.disabled=r===!0),Se(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:k.useCallback(c=>{var d,f;!c&&((d=l.element)!=null&&d.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=c??void 0)},[l])}}const il=`url("data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>')}")`,cu=(e,t="line")=>{const n=[":is(p, h1, h2, h3, h4, h5, h6):first-child::after","> * > span:only-child::after"],r=o=>n.map(a=>`${o} ${a}`).join(", "),s=t==="line"?"&::after":r("&"),i=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[s]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:il,WebkitMaskImage:il,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${C.MOTION_FAST}`,...C.reducedMotionSx,pointerEvents:"none"},[i]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},du=k.createContext(void 0);function uu(e,t){const n=k.useContext(du),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function fo({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Ke.usePublisherTheme(),[o,a]=k.useState(void 0),l=k.useRef(!1),u=()=>{l.current||o===void 0||(a(void 0),o!==e&&r(o))};uu(o!==void 0&&o!==e,()=>(u(),!0));const c=()=>{l.current=!1,a(e)};if(o===void 0){const d=e==="",f=d&&s;return x.jsx($.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:c,onKeyDown:p=>{p.key!=="Enter"&&p.key!==" "||(p.preventDefault(),c())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...d&&{fontStyle:"italic",opacity:f?0:.6}},cu(i)],children:d?t:e})}return x.jsx($.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:d=>d.target.select(),onChange:d=>a(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.nativeEvent.isComposing?u():d.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Eg=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Cg=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},fu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),hu=e=>`gap.${e}`,Ig=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),l=o===0||i.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),l&&(r=0),n.push(fu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Dg=Object.create,pu=Object.defineProperty,Ag=Object.defineProperties,Pg=Object.getOwnPropertyDescriptor,Mg=Object.getOwnPropertyDescriptors,Ms=Object.getOwnPropertySymbols,gu=Object.prototype.hasOwnProperty,mu=Object.prototype.propertyIsEnumerable,jg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Rr=e=>{throw TypeError(e)},ho=(e,t,n)=>t in e?pu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gi=(e,t)=>{for(var n in t||(t={}))gu.call(t,n)&&ho(e,n,t[n]);if(Ms)for(var n of Ms(t))mu.call(t,n)&&ho(e,n,t[n]);return e},mi=(e,t)=>Ag(e,Mg(t)),Rg=(e,t)=>{var n={};for(var r in e)gu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ms)for(var r of Ms(e))t.indexOf(r)<0&&mu.call(e,r)&&(n[r]=e[r]);return n},Lg=e=>{var t;return[,,,Dg((t=void 0)!=null?t:null)]},vu=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Rr("Function expected"):e,Ng=(e,t,n,r,s)=>({kind:vu[e],name:t,metadata:r,addInitializer:i=>n._?Rr("Already initialized"):s.push(rr(i||null))}),Fg=(e,t)=>ho(t,jg("metadata"),e[3]),Vr=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},bu=(e,t,n,r,s,i)=>{for(var o,a,l,u,c,d=t&7,f=!1,p=!1,h=e.length+1,v=vu[d+5],y=e[h-1]=[],w=e[h]||(e[h]=[]),g=(s=s.prototype,Pg({get[n](){return sr(this,i)},set[n](b){return Gt(this,i,b)}},n)),m=r.length-1;m>=0;m--)u=Ng(d,n,l={},e[3],w),u.static=f,u.private=p,c=u.access={has:b=>n in b},c.get=b=>b[n],c.set=(b,_)=>b[n]=_,a=(0,r[m])({get:g.get,set:g.set},u),l._=1,a===void 0?rr(a)&&(g[v]=a):typeof a!="object"||a===null?Rr("Object expected"):(rr(o=a.get)&&(g.get=o),rr(o=a.set)&&(g.set=o),rr(o=a.init)&&y.unshift(o));return g&&pu(s,n,g),s},yu=(e,t,n)=>t.has(e)||Rr("Cannot "+n),sr=(e,t,n)=>(yu(e,t,"read from private field"),t.get(e)),Gn=(e,t,n)=>t.has(e)?Rr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Gt=(e,t,n,r)=>(yu(e,t,"write to private field"),t.set(e,n),n);function Kt(e){return e instanceof ba||e instanceof ku}var Hr=10,zg=class extends We{constructor(e){super(e);const t=st(()=>{const{dragOperation:r}=e;if(br(r.activatorEvent)&&Kt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Mr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!br(r.nativeEvent)||!Kt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const c=Wg(u),{source:d,target:f}=i,{center:p}=i.shape.current,h=[],v=[];Te(()=>{for(const _ of l.droppables){const{id:O}=_;if(!_.accepts(d)||O===f?.id&&Kt(_)||!_.element)continue;let E=_.shape;const I=new ut(_.element,{getBoundingClientRect:T=>mr(T,void 0,.2)});!I.height||!I.width||(c=="down"&&p.y+Hr<I.center.y||c=="up"&&p.y-Hr>I.center.y||c=="left"&&p.x-Hr>I.center.x||c=="right"&&p.x+Hr<I.center.x)&&(h.push(_),_.shape=I,v.push(()=>_.shape=E))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(h,lp);Te(()=>v.forEach(_=>_()));const[w]=y;if(!w)return;const{id:g}=w,{index:m,group:b}=d.sortable;o.setDropTarget(g).then(()=>{const{source:_,target:O,shape:E}=i;if(!_||!Kt(_)||!E)return;const{index:I,group:T,target:D}=_.sortable,L=m!==I||b!==T,R=L?D:O?.element;if(!R)return;gd(R);const z=new ut(R);if(!z)return;const K=ft.delta(z,ft.from(E.current.boundingRectangle),_.alignment);o.move({by:K}),L?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Wg(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 Bg=Object.defineProperty,Gg=Object.defineProperties,qg=Object.getOwnPropertyDescriptors,ol=Object.getOwnPropertySymbols,Kg=Object.prototype.hasOwnProperty,Ug=Object.prototype.propertyIsEnumerable,al=(e,t,n)=>t in e?Bg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nn=(e,t)=>{for(var n in t||(t={}))Kg.call(t,n)&&al(e,n,t[n]);if(ol)for(var n of ol(t))Ug.call(t,n)&&al(e,n,t[n]);return e},rn=(e,t)=>Gg(e,qg(t));function Vg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Xr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function vi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Hg(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(m,b)=>m===b||m!==null&&typeof m=="object"&&"id"in m&&m.id===b;if(Array.isArray(e)){const m=e.findIndex(_=>l(_,i.id)),b=e.findIndex(_=>l(_,o.id));if(m===-1||b===-1){if(vi(i)){const _=i.initialIndex,O=i.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==m)return n(e,m,_)}return n(e,m,b)}const u=Object.entries(e);let c=-1,d,f=-1,p;for(const[m,b]of u)if(c===-1&&(c=b.findIndex(_=>l(_,i.id)),c!==-1&&(d=m)),f===-1&&(f=b.findIndex(_=>l(_,o.id)),f!==-1&&(p=m)),c!==-1&&f!==-1)break;if(c===-1&&vi(i)){const m=i.initialGroup==null?void 0:Xr(e,i.initialGroup),b=i.initialIndex,_=i.group==null?void 0:Xr(e,i.group),O=i.index;if(m==null||_==null||m===_&&b===O)return"preventDefault"in t&&t.preventDefault(),e;if(m===_)return rn(nn({},e),{[m]:n(e[m],b,O)});const E=e[m][b];return rn(nn({},e),{[m]:[...e[m].slice(0,b),...e[m].slice(b+1)],[_]:[...e[_].slice(0,O),E,...e[_].slice(O)]})}if(!i.manager)return e;const{dragOperation:h}=i.manager,v=(s=(r=h.shape)==null?void 0:r.current.center)!=null?s:h.position.current;if(p==null){const m=Xr(e,o.id);if(m!=null){const b=o.shape&&v.y>o.shape.center.y?e[m].length:0;p=m,f=b}}if(d==null||p==null||d===p&&c===f){if(d!=null&&d===p&&c===f&&vi(i)){const m=i.group==null?void 0:Xr(e,i.group),b=i.group!=null&&m!==d,_=i.index!==c;if(b||_){const O=i.group==null?d:m;if(O!=null){if(d===O)return rn(nn({},e),{[d]:n(e[d],c,i.index)});const E=e[d][c];return rn(nn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[O]:[...e[O].slice(0,i.index),E,...e[O].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===p)return rn(nn({},e),{[d]:n(e[d],c,f)});const w=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[d][c];return rn(nn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[p]:[...e[p].slice(0,f+w),g,...e[p].slice(f+w)]})}function Xg(e,t){return Hg(e,t,Vg)}function ll(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function cl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var dl="__default__",Yg=class extends We{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof ba){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Kt(o)||!Kt(a)||o.sortable===a.sortable)return;const l=t(),u=ll(l),c=o.sortable.group===a.sortable.group,d=l.get(o.sortable.group),f=c?d:l.get(a.sortable.group);!d||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var p,h;const v=t();if(cl(u,l,v))return;const y=o.sortable.element,w=a.sortable.element;if(!w||!y||!c&&a.id===o.sortable.group)return;const g=Yr(d),m=c?g:Yr(f),b=(p=o.sortable.group)!=null?p:dl,_=(h=a.sortable.group)!=null?h:dl,O={[b]:g,[_]:m},E=Xg(O,r);if(O===E)return;const I=E[_].indexOf(o.sortable),T=E[_].indexOf(a.sortable);s.collisionObserver.disable(),ul(y,I,w,T),Te(()=>{for(const[D,L]of E[b].entries())L.index=D;if(!c)for(const[D,L]of E[_].entries())L.group=a.sortable.group,L.index=D}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Kt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=ll(a),u=a.get(o.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const c=t();if(cl(l,a,c))return;const d=Yr(u),f=Yr(u,Qg),p=o.sortable.element,h=f.indexOf(o.sortable),v=d[h],y=v?.element;!v||!y||!p||(ul(p,v.index,y,o.index),Te(()=>{for(const w of a.values()){const g=Array.from(w).values();for(const m of g)m.index=m.initialIndex,m.group=m.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function ul(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Zg(e,t){return e.index-t.index}function Qg(e,t){return e.initialIndex-t.initialIndex}function Yr(e,t=Zg){return Array.from(e).sort(t)}var fl=[zg,Yg],xu={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function hl(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 Zr=new Kf,wu,_u,Dt,ma,ir,or,va,hn;_u=[fe],wu=[fe];var Zs=class{constructor(e,t){Gn(this,ma,Vr(Dt,8,this)),Vr(Dt,11,this),Gn(this,ir),Gn(this,or),Gn(this,va,Vr(Dt,12,this)),Vr(Dt,15,this),Gn(this,hn),this.register=()=>(Te(()=>{var h,v;(h=this.manager)==null||h.registry.register(this.droppable),(v=this.manager)==null||v.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Te(()=>{var h,v;(h=this.manager)==null||h.registry.unregister(this.droppable),(v=this.manager)==null||v.registry.unregister(this.draggable)})},this.destroy=()=>{Te(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:l,transition:u=xu,plugins:c}=n,d=Rg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=lt(c,fl),p=hl(s);this.droppable=new ba(mi(gi({},d),{disabled:p.droppable}),t,this),this.draggable=new ku(mi(gi({},d),{disabled:p.draggable,plugins:f,effects:()=>[()=>{var h,v,y;const w=(h=this.manager)==null?void 0:h.dragOperation.status;w?.initializing&&this.id===((y=(v=this.manager)==null?void 0:v.dragOperation.source)==null?void 0:y.id)&&Zr.clear(this.manager),w?.dragging&&Zr.set(this.manager,this.id,ue(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:h,group:v,manager:y}=this,w=sr(this,or),g=sr(this,ir);(h!==w||v!==g)&&(Gt(this,or,h),Gt(this,ir,v),this.animate())},()=>{var h,v;const{target:y}=this,{isDragSource:w}=this.draggable;((v=(h=this.draggable.pluginConfig(aa))==null?void 0:h.feedback)!=null?v:"default")==="move"&&w&&(this.droppable.disabled=!y)},...r()],type:l,sensors:a}),t,this),Gt(this,hn,d.element),this.manager=t,this.index=o,Gt(this,or,o),this.group=i,Gt(this,ir,i),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=Zr.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Zr.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ue(()=>{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:s}=this;if(!s)return;for(const c of s.getAnimations())"transitionProperty"in c&&(c.transitionProperty==="transform"||c.transitionProperty==="translate"||c.transitionProperty==="scale")&&c.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=gt(s),l=Xa(s,a,!1),u=Xa(s,a);if(o.x||o.y){const c=Jo(Qe(s))?mi(gi({},t),{duration:0}):t;md({element:s,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){Te(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Te(()=>{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),Gt(this,hn,e)})}get element(){var e,t;const n=sr(this,hn);if(n)return(t=(e=Ui.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=lt(e,fl)}set disabled(e){const t=hl(e);Te(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Te(()=>{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??vd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Te(()=>{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)}};Dt=Lg();ma=new WeakMap;ir=new WeakMap;or=new WeakMap;va=new WeakMap;hn=new WeakMap;bu(Dt,4,"index",_u,Zs,ma);bu(Dt,4,"group",wu,Zs,va);Fg(Dt,Zs);var ku=class extends Hs{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}},ba=class extends Xs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},Jg=Object.defineProperty,em=Object.defineProperties,tm=Object.getOwnPropertyDescriptors,pl=Object.getOwnPropertySymbols,nm=Object.prototype.hasOwnProperty,rm=Object.prototype.propertyIsEnumerable,gl=(e,t,n)=>t in e?Jg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bi=(e,t)=>{for(var n in t||(t={}))nm.call(t,n)&&gl(e,n,t[n]);if(pl)for(var n of pl(t))rm.call(t,n)&&gl(e,n,t[n]);return e},sm=(e,t)=>em(e,tm(t));function im(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:l,group:u,disabled:c,modifiers:d,sensors:f,target:p,type:h,plugins:v}=e,y=bi(bi({},xu),e.transition),w=Jd(m=>new Zs(sm(bi({},e),{transition:y,register:!1,handle:bn(a),element:bn(o),target:bn(p)}),m)),g=Xd(w,om);return Se(s,()=>w.id=s),Ln(()=>{Te(()=>{w.group=u,w.index=l})},[w,u,l]),Se(h,()=>w.type=h),Se(t,()=>w.accept=t,void 0,ot),Se(i,()=>i&&(w.data=i)),Se(l,()=>{var m;(m=w.manager)!=null&&m.dragOperation.status.idle&&y?.idle&&w.refreshShape()},ng),hs(a,m=>w.handle=m),hs(o,m=>w.element=m),hs(p,m=>w.target=m),Se(c,()=>w.disabled=c??!1,void 0,ot),Se(f,()=>w.sensors=f,void 0,ot),Se(n,()=>w.collisionDetector=n),Se(r,()=>w.collisionPriority=r),Se(v,()=>w.plugins=v,void 0,ot),Se(y,()=>w.transition=y,void 0,ot),Se(d,()=>w.modifiers=d,void 0,ot),Se(e.alignment,()=>w.alignment=e.alignment),{sortable:g,get isDragging(){return g.isDragging},get isDropping(){return g.isDropping},get isDragSource(){return g.isDragSource},get isDropTarget(){return g.isDropTarget},handleRef:k.useCallback(m=>{w.handle=m??void 0},[w]),ref:k.useCallback(m=>{var b,_;!m&&((b=w.element)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.element=m??void 0)},[w]),sourceRef:k.useCallback(m=>{var b,_;!m&&((b=w.source)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.source=m??void 0)},[w]),targetRef:k.useCallback(m=>{var b,_;!m&&((b=w.target)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.target=m??void 0)},[w])}}function om(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const po="tile",Su="gap",am=[oo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${$u}]`)!==null||(oo.defaults.preventActivation?.(e,t)??!1)}),Wd],$u="data-no-drag",lm=e=>[...e,aa.configure({feedback:"clone"})];function cm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=im({id:e,index:t,type:po,accept:po,collisionDetector:ta,plugins:lm});return x.jsx(x.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function dm({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Og({id:e,type:Su,accept:po,collisionDetector:ta,data:{after:t}});return x.jsx(x.Fragment,{children:n({ref:r,isDropTarget:s})})}const Tu=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],Ou=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],Qs=e=>Ou.includes(e),go=new Set([...Tu,"viz"]);function At(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let s;for(const i of n)if(i.startsWith("-")){if(s!==void 0)return;const o=i.slice(1);if(!go.has(o))return;r.push(o)}else{if(s!==void 0||!go.has(i))return;s=i}return{negated:r,...s!==void 0&&{pick:s}}}function kr(e){const t=e.trim();return!/^#[ \t]/.test(t)||At(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(r=>go.has(r))}function yn(e,t){return["#",...Ou.filter(r=>r!==e&&(t===void 0||t.includes(r))).map(r=>`-${r}`),"-viz",...e==="none"?[]:[e]].join(" ")}function um(e){return e.pick!==void 0?Qs(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function fm(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=At(e[0]);return t?um(t):"custom"}function hm(e){const t=e.filter(n=>At(n));return e.some(kr)?"custom":t.length===0?void 0:fm(t)}const pm=e=>e.filter(t=>At(t)||kr(t)),Eu=e=>e.ok===!1,De=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Lr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>De(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>De(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>De(e,"VIEW","subQueryDefList"),defDimension:e=>De(e,"defList","DIMENSION"),exploreProperties:e=>De(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>De(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>De(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>De(e,"WHERE","filterClauseList"),givenDef:e=>De(e,"givenNameDef"),givenStatement:e=>De(e,"GIVEN","givenDefList"),importStatement:e=>De(e,"IMPORT","importURL"),vArrow:e=>De(e,"ARROW","vExpr","segExpr"),segRefine:e=>De(e,"PLUS","segExpr"),segOps:e=>De(e,"queryProperties"),segField:e=>De(e,"fieldPath")&&!De(e,"segExpr"),segParen:e=>De(e,"OPAREN","CPAREN","vExpr"),compare:e=>De(e,"fieldExpr","compareOp"),givenRef:e=>De(e,"GIVEN_REF")};function gm(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 mm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
-
`&&t.push(n+1);return t}class
|
|
69
|
-
`),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:l,oneLine:a}}function
|
|
70
|
-
`),
|
|
71
|
-
`||e.text[p-1]==="\r");)p--;s.push({start:f,end:p})}}const o=[...s].sort((c
|
|
67
|
+
`.replace(/\n+/g," ").replace(/\s+/g," ").trim();function Ip(e,t="hidden"){return ue(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=Dp(n,r.registry.droppables),i=[],o=$h(n),{remove:a}=o;return Ap(s,o,i),Pp(o,t),o.remove=()=>{i.forEach(l=>l()),a.call(o)},o})}function Dp(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Pr}${Yi("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function Ap(e,t,n){for(const[r,s]of e){if(!r.element)continue;const i=`[${s}]`,o=t.matches(i)?t:t.querySelector(i);if(r.element.removeAttribute(s),!o)continue;const a=r.element;r.proxy=o,o.removeAttribute(s),Ui.set(a,o),n.push(()=>{Ui.delete(a),r.proxy=void 0})}}function Pp(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Is,t)}function Pd(e,t){return e===t?!0:_n(e)===_n(t)}function Ja(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&Ut(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>mn(t))}function eo(e){return e.tagName==="TR"}function Mp(e,t,n){const r=new MutationObserver(s=>{let i=!1;for(const o of s){if(o.target!==e){i=!0;continue}if(o.type!=="attributes")continue;const a=o.attributeName;if(a.startsWith("aria-")||Op.includes(a))continue;const l=e.getAttribute(a);if(a==="style"){if(ur(e)&&ur(t)){const u=e.style;for(const d of Array.from(t.style))u.getPropertyValue(d)===""&&t.style.removeProperty(d);for(const d of Array.from(u)){if(Ep.includes(d)||d.startsWith(Le))continue;const c=u.getPropertyValue(d);t.style.setProperty(d,c)}}}else l!==null?t.setAttribute(a,l):t.removeAttribute(a)}i&&n&&t.replaceChildren(...e.cloneNode(!0).childNodes)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function jp(e,t,n){const r=new MutationObserver(s=>{for(const i of s)if(i.addedNodes.length!==0)for(const o of Array.from(i.addedNodes)){if(o.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),mn(n);return}if(o.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),mn(n);return}}e.isConnected&&t.isConnected&&e.nextElementSibling!==t&&(e.insertAdjacentElement("afterend",t),mn(n))});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function Rp(e){return new ResizeObserver(()=>{var t,n,r;const s=new ut(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),i=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-s.width)*i.x+e.delta.x,a=(e.height-s.height)*i.y+e.delta.y,l=ld();if(e.styles.set({width:s.width-e.widthOffset,height:s.height-e.heightOffset,top:e.top+a+l.y,left:e.left+o+l.x},Le),(n=e.getElementMutationObserver())==null||n.takeRecords(),eo(e.element)&&eo(e.placeholder)){const m=Array.from(e.element.cells),y=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(m.map(w=>w.style.width));for(const[w,v]of m.entries()){const g=y[w];v.style.width=`${g.getBoundingClientRect().width}px`}}const u=(r=e.getTranslate())!=null?r:{x:0,y:0},d=e.left+o+l.x+u.x,c=e.top+a+l.y+u.y,f=s.width-e.widthOffset,p=s.height-e.heightOffset,h=e.frameTransform;e.dragOperation.shape=new ft(d*h.scaleX+h.x,c*h.scaleY+h.y,f*h.scaleX,p*h.scaleY)})}var Lp=250,Np="ease";function Fp(e){var t,n,r,s;const{animation:i}=e;if(typeof i=="function"){const v=i({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=Lp,easing:a=Np}=i??{};mn(e.feedbackElement);const[,l]=(t=id(e.feedbackElement,v=>"translate"in v))!=null?t:[];l?.pause();const u=(n=e.placeholder)!=null?n:e.element,d={frameTransform:Pd(e.feedbackElement,u)?null:void 0},c=new ut(e.feedbackElement,d),f=(r=vr(gt(e.feedbackElement).translate))!=null?r:e.translate,p=new ut(u,d),h=ft.delta(c,p,e.alignment),m={x:f.x-h.x,y:f.y-h.y},y=Math.round(c.intrinsicHeight)!==Math.round(p.intrinsicHeight)?{minHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`],maxHeight:[`${c.intrinsicHeight}px`,`${p.intrinsicHeight}px`]}:{},w=Math.round(c.intrinsicWidth)!==Math.round(p.intrinsicWidth)?{minWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`],maxWidth:[`${c.intrinsicWidth}px`,`${p.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Le),e.feedbackElement.setAttribute(Ji,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),bd({element:e.feedbackElement,keyframes:sa(yr(yr({},y),w),{translate:[`${f.x}px ${f.y}px 0`,`${m.x}px ${m.y}px 0`]}),options:{duration:ea(Qe(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?o:0,easing:a}}).then(()=>{e.feedbackElement.removeAttribute(Ji),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Md,to,xr,aa,fs,jd,Rd,$n=class extends(to=We,Md=[fe],to){constructor(t,n){super(t,n),Ce(this,fs),Ce(this,aa,Me(xr,8,this)),Me(xr,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(Vs),s=r?.register(Cp);if(s){const i=this.destroy.bind(this);this.destroy=()=>{s(),i()}}this.registerEffect(Vt(this,fs,jd).bind(this,r)),this.registerEffect(Vt(this,fs,Rd))}};xr=Rn(to);aa=new WeakMap;fs=new WeakSet;jd=function(e){const{overlay:t}=this;if(!t||!e)return;const n=ks(t);if(n)return e.addRoot(n)};Rd=function(){var e,t,n,r,s,i,o;const{state:a,manager:l,options:u}=this,{dragOperation:d}=l,{position:c,source:f,status:p}=d;if(p.idle){a.current={},a.initial={};return}if(!f)return;const{element:h}=f,m=f.pluginConfig($n),y=(t=(e=m?.feedback)!=null?e:u?.feedback)!=null?t:"default",w=typeof y=="function"?y(f,l):y;if(!h||w==="none"||!p.initialized||p.initializing)return;const{initial:v}=a,g=(n=this.overlay)!=null?n:h,b=kn(g),_=kn(h),O=!Pd(h,g),I=new ut(h,{frameTransform:O?_:null,ignoreTransforms:!O}),M={x:_.scaleX/b.scaleX,y:_.scaleY/b.scaleY};let{width:T,height:D,top:N,left:R}=I;O&&(T=T/M.x,D=D/M.y);const W=new sp(g),X=gt(h),{transition:G,translate:U,boxSizing:Y,paddingBlockStart:re,paddingBlockEnd:ee,paddingInlineStart:A,paddingInlineEnd:B,borderInlineStartWidth:z,borderInlineEndWidth:j,borderBlockStartWidth:q,borderBlockEndWidth:J}=X,Q=G.split(",").filter(be=>!/^\s*(transform|translate|scale)\b/.test(be)).join(","),H=Us(X),$=X.transform,P=w==="clone",F=Y==="content-box",V=F?parseInt(A)+parseInt(B)+parseInt(z)+parseInt(j):0,oe=F?parseInt(re)+parseInt(ee)+parseInt(q)+parseInt(J):0,Z=w!=="move"&&!this.overlay?Ip(f,P?"clone":"hidden"):null,ne=ue(()=>br(l.dragOperation.activatorEvent));if(!v.translate){if(this.overlay&&H)v.translate={x:H.x,y:H.y};else if(U!=="none"){const be=vr(U);be&&(v.translate=be)}}if(!v.transformOrigin){const be=ue(()=>c.current),Ie=R+((r=H?.x)!=null?r:0),He=N+((s=H?.y)!=null?s:0);v.transformOrigin={x:(be.x-Ie*b.scaleX-b.x)/(T*b.scaleX),y:(be.y-He*b.scaleY-b.y)/(D*b.scaleY)}}const{transformOrigin:de}=v,se=N*b.scaleY+b.y,L=R*b.scaleX+b.x;if(!v.coordinates&&(v.coordinates={x:L,y:se},M.x!==1||M.y!==1)){const{scaleX:be,scaleY:Ie}=_,{x:He,y:St}=de;v.coordinates.x+=(T*be-T)*He,v.coordinates.y+=(D*Ie-D)*St}v.dimensions||(v.dimensions={width:T,height:D}),v.frameTransform||(v.frameTransform=b);const te={x:v.coordinates.x-L,y:v.coordinates.y-se},pe={width:(v.dimensions.width*v.frameTransform.scaleX-T*b.scaleX)*de.x,height:(v.dimensions.height*v.frameTransform.scaleY-D*b.scaleY)*de.y},ae={x:te.x/b.scaleX+pe.width,y:te.y/b.scaleY+pe.height},C={left:R+ae.x,top:N+ae.y};g.setAttribute(dt,"true");const K=ue(()=>d.transform),ie=(i=v.translate)!=null?i:{x:0,y:0},ve=K.x*b.scaleX+ie.x,Re=K.y*b.scaleY+ie.y,Nn=ld();W.set({width:T-V,height:D-oe,top:C.top+Nn.y,left:C.left+Nn.x,translate:`${ve}px ${Re}px 0`,transform:this.overlay?"none":$,transition:Q?`${Q}, translate 0ms linear`:"translate 0ms linear",scale:O?`${M.x} ${M.y}`:"","transform-origin":`${de.x*100}% ${de.y*100}%`},Le),Z&&(h.insertAdjacentElement("afterend",Z),u?.rootElement&&(typeof u.rootElement=="function"?u.rootElement(f):u.rootElement).appendChild(h)),Hi(g)&&(g.hasAttribute("popover")||g.setAttribute("popover","manual"),mn(g),g.addEventListener("beforetoggle",Ja));let mt,Fn,vt;const $a=Rp({placeholder:Z,element:h,feedbackElement:g,frameTransform:b,transformOrigin:de,width:T,height:D,top:N,left:R,widthOffset:V,heightOffset:oe,delta:ae,styles:W,dragOperation:d,getTranslate:()=>a.current.translate,getElementMutationObserver:()=>mt,getSavedCellWidths:()=>vt,setSavedCellWidths:be=>{vt=be}}),Ta=new ut(g);ue(()=>d.shape=Ta);const ei=Qe(g),Oa=be=>{this.manager.actions.stop({event:be})},ef=ea(ei);ne&&ei.addEventListener("resize",Oa),ue(()=>f.status)==="idle"&&requestAnimationFrame(()=>f.status="dragging"),Z&&($a.observe(Z),mt=Mp(h,Z,P),Fn=jp(h,Z,g));const Ea=(o=l.dragOperation.source)==null?void 0:o.id,tf=()=>{var be;if(!ne||Ea==null)return;const Ie=l.registry.draggables.get(Ea),He=(be=Ie?.handle)!=null?be:Ie?.element;Pt(He)&&He.focus()},ti=()=>{mt?.disconnect(),Fn?.disconnect(),$a.disconnect(),ei.removeEventListener("resize",Oa),Hi(g)&&(g.removeEventListener("beforetoggle",Ja),g.removeAttribute("popover")),g.removeAttribute(dt),W.reset();const be=()=>{var Ie;if(vt&&eo(h)){const ni=Array.from(h.cells);for(const[zr,Jt]of ni.entries())Jt.style.width=(Ie=vt[zr])!=null?Ie:""}f.status="idle";const He=a.current.translate!=null,St=d.status.dragging;Z&&(!St&&He||Z.parentElement!==g.parentElement)&&g.isConnected&&Z.replaceWith(g),Z?.remove()};g===this.overlay?setTimeout(be,0):be()},nf=u?.dropAnimation,Ca=this,rf=Er(()=>{var be,Ie,He;const{transform:St,status:ni}=d;if(!(!St.x&&!St.y&&!a.current.translate)&&ni.dragging){const zr=(be=v.translate)!=null?be:{x:0,y:0},Jt={x:St.x/b.scaleX+zr.x,y:St.y/b.scaleY+zr.y},Ia=a.current.translate,sf=ue(()=>d.modifiers),ri=ue(()=>{var Wn;return(Wn=d.shape)==null?void 0:Wn.current}),zn=u?.keyboardTransition,Da=ne&&!ef&&zn!==null?`${(Ie=zn?.duration)!=null?Ie:250}ms ${(He=zn?.easing)!=null?He:"cubic-bezier(0.25, 1, 0.5, 1)"}`:"0ms linear";if(W.set({transition:Q?`${Q}, translate ${Da}`:`translate ${Da}`,translate:`${Jt.x}px ${Jt.y}px 0`},Le),mt?.takeRecords(),ri&&ri!==Ta&&Ia&&!sf.length){const Wn=et.delta(Jt,Ia);d.shape=ft.from(ri.boundingRectangle).translate(Wn.x*b.scaleX,Wn.y*b.scaleY)}else d.shape=new ut(g);a.current.translate=Jt}},function(){if(d.status.dropped){this.dispose(),f.status="dropping";const be=m?.dropAnimation!==void 0?m.dropAnimation:Ca.dropAnimation!==void 0?Ca.dropAnimation:nf;let Ie=a.current.translate;const He=Ie!=null;if(!Ie&&h!==g&&(Ie={x:0,y:0}),!Ie||be===null){ti();return}l.renderer.rendering.then(()=>{Fp({source:f,element:h,feedbackElement:g,placeholder:Z,translate:Ie,moved:He,transition:G,alignment:f.alignment,styles:W,animation:be??void 0,getElementMutationObserver:()=>mt,cleanup:ti,restoreFocus:tf})})}});return()=>{ti(),rf()}};it(xr,4,"overlay",Md,$n,aa);Qt(xr,$n);$n.configure=Ir($n);var la=$n,Bn=!0,zp=!1,Ld,Nd,Fd,zd,Et,ca,da;zd=(Fd=[fe],tt.Forward),Nd=(Ld=[fe],tt.Reverse);var wr=class{constructor(){Ce(this,ca,Me(Et,8,this,Bn)),Me(Et,11,this),Ce(this,da,Me(Et,12,this,Bn)),Me(Et,15,this)}isLocked(e){return e===tt.Idle?!1:e==null?this[tt.Forward]===Bn&&this[tt.Reverse]===Bn:this[e]===Bn}unlock(e){e!==tt.Idle&&(this[e]=zp)}};Et=Rn(null);ca=new WeakMap;da=new WeakMap;it(Et,4,zd,Fd,wr,ca);it(Et,4,Nd,Ld,wr,da);Qt(Et,wr);var Wp=[tt.Forward,tt.Reverse],el=class{constructor(){this.x=new wr,this.y=new wr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},Bp=class extends We{constructor(e){super(e);const t=Tn(new el);let n=null;this.signal=t,st(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new el;return}const{delta:s}=e.dragOperation.position;if(n){const i={x:tl(s.x,n.x),y:tl(s.y,n.y)},o=t.peek();Te(()=>{for(const a of gc)for(const l of Wp)i[a]===l&&o[a].unlock(l);t.value=o})}n=s})}get current(){return this.signal.peek()}};function tl(e,t){return Math.sign(e-t)}var Wd,no,_r,ua,Tt,ro,Mr=class extends(no=Dr,Wd=[fe],no){constructor(e){super(e),Ce(this,ua,Me(_r,8,this,!1)),Me(_r,11,this),Ce(this,Tt),Ce(this,ro,()=>{if(!ye(this,Tt))return;const{element:i,by:o}=ye(this,Tt);o.y&&(i.scrollTop+=o.y),o.x&&(i.scrollLeft+=o.x)}),this.scroll=(i,o)=>{var a;if(this.disabled)return!1;const l=this.getScrollableElements();if(!l)return qe(this,Tt,void 0),!1;const{position:u}=this.manager.dragOperation,d=u?.current;if(d){const{by:c}=i??{},f=c?{x:nl(c.x),y:nl(c.y)}:void 0,p=f?void 0:this.scrollIntentTracker.current;if(p?.isLocked())return!1;for(const h of l){const m=Nh(h,c);if(m.x||m.y){const{speed:y,direction:w}=Xh(h,d,f,o?.acceleration,o?.threshold);if(p)for(const v of gc)p[v].isLocked(w[v])&&(y[v]=0,w[v]=0);if(w.x||w.y){const{x:v,y:g}=c??w,b=v*y.x,_=g*y.y;if(b||_){const O=(a=ye(this,Tt))==null?void 0:a.by;if(this.autoScrolling&&O&&(O.x&&!b||O.y&&!_))continue;return qe(this,Tt,{element:h,by:{x:b,y:_}}),Ts.schedule(ye(this,ro)),!0}}}}}return qe(this,Tt,void 0),!1};let t=null,n=null;const r=Ai(()=>{const{position:i,source:o}=e.dragOperation;if(!i)return null;const a=cd(ks(o?.element),i.current);return a&&(t=a),a??t}),s=Ai(()=>{const i=r.value,{documentElement:o}=Mn(i);if(!i||i===o){const{target:a}=e.dragOperation,l=a?.element;if(l){const u=Xi(l,{excludeElement:!1});return n=u,u}}if(i){const a=Xi(i,{excludeElement:!1});return this.autoScrolling&&n&&a.size<n?.size?n:(n=a,a)}return n=null,null},ot);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new Bp(e),this.destroy=e.monitor.addEventListener("dragmove",i=>{this.disabled||i.defaultPrevented||!br(e.dragOperation.activatorEvent)||!i.by||this.scroll({by:i.by})&&i.preventDefault()})}};_r=Rn(no);ua=new WeakMap;Tt=new WeakMap;ro=new WeakMap;it(_r,4,"autoScrolling",Wd,Mr,ua);Qt(_r,Mr);function nl(e){return e>0?tt.Forward:e<0?tt.Reverse:tt.Idle}var Gp=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))}},qp=new Gp(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),Kp=10,so=class extends We{constructor(t,n){super(t,n);const r=t.registry.plugins.get(Mr);if(!r)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=st(()=>{var s,i,o;if(this.disabled)return;const{position:a,status:l}=t.dragOperation;if(l.dragging){const u={acceleration:(s=this.options)==null?void 0:s.acceleration,threshold:typeof((i=this.options)==null?void 0:i.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 c=setInterval(()=>qp.schedule(()=>r.scroll(void 0,u)),Kp);return()=>{clearInterval(c)}}else r.autoScrolling=!1}})}};so.configure=Ir(so);var Bd=so,rl={capture:!0,passive:!0},tr,Up=class extends Dr{constructor(e){super(e),Ce(this,tr),this.handleScroll=()=>{ye(this,tr)==null&&qe(this,tr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),qe(this,tr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=st(()=>{var n,r,s;if(t.status.dragging){const o=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return o.addEventListener("scroll",this.handleScroll,rl),()=>{o.removeEventListener("scroll",this.handleScroll,rl)}}})}};tr=new WeakMap;var Vp="* { user-select: none !important; -webkit-user-select: none !important; }",Hp=class extends We{constructor(e){super(e),this.manager=e;const t=e.registry.plugins.get(Vs),n=t?.register(Vp);if(this.destroy=st(()=>{const{dragOperation:r}=this.manager;if(r.status.initialized)return fi(),document.addEventListener("selectionchange",fi,{capture:!0}),()=>{document.removeEventListener("selectionchange",fi,{capture:!0})}}),n){const r=this.destroy.bind(this);this.destroy=()=>{n(),r()}}}};function fi(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var nr=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,Ds=class extends xn{constructor(t,n){super(t),this.manager=t,this.options=n,Ce(this,dn,[]),this.listeners=new dd,this.handleSourceKeyDown=(r,s,i)=>{if(this.disabled||r.defaultPrevented||!Ut(r.target)||s.disabled)return;const{keyboardCodes:o=nr.keyboardCodes,preventActivation:a=nr.preventActivation}=i??{};o.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(a?.(r,s)||this.handleStart(r,s,i))}}bind(t,n=this.options){return st(()=>{var s;const i=(s=t.handle)!=null?s:t.element,o=a=>{br(a)&&this.handleSourceKeyDown(a,t,n)};if(i)return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),vd(s);const{center:i}=new ut(s);if(this.manager.actions.start({event:t,coordinates:{x:i.x,y:i.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const a=Mn(s),l=[this.listeners.bind(a,[{type:"keydown",listener:u=>this.handleKeyDown(u,n,r),options:{capture:!0}}])];ye(this,dn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=nr.keyboardCodes}=r??{};if(en(t,[...s.end,...s.cancel])){t.preventDefault();const i=en(t,s.cancel);this.handleEnd(t,i);return}en(t,s.up)?this.handleMove("up",t):en(t,s.down)&&this.handleMove("down",t),en(t,s.left)?this.handleMove("left",t):en(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:i}=this.manager.dragOperation,o=n.shiftKey?5:1;let a={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:nr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!i){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(Bd);t?.disabled===!1&&(t.disable(),ye(this,dn).push(()=>{t.enable()}))}cleanup(){ye(this,dn).forEach(t=>t()),qe(this,dn,[])}destroy(){this.cleanup(),this.listeners.clear()}};dn=new WeakMap;Ds.configure=Ir(Ds);Ds.defaults=nr;var Gd=Ds;function en(e,t){return t.includes(e.code)}var Wt,Xp=class extends Vc{constructor(){super(...arguments),Ce(this,Wt)}onEvent(e){switch(e.type){case"pointerdown":qe(this,Wt,wn(e));break;case"pointermove":if(!ye(this,Wt))return;const{x:t,y:n}=wn(e),r={x:t-ye(this,Wt).x,y:n-ye(this,Wt).y},{tolerance:s}=this.options;if(s&&Wi(r,s)){this.abort();return}Wi(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){qe(this,Wt,void 0)}};Wt=new WeakMap;var un,Bt,Yp=class extends Vc{constructor(){super(...arguments),Ce(this,un),Ce(this,Bt)}onEvent(e){switch(e.type){case"pointerdown":qe(this,Bt,wn(e)),qe(this,un,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!ye(this,Bt))return;const{x:t,y:n}=wn(e),r={x:t-ye(this,Bt).x,y:n-ye(this,Bt).y};Wi(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){ye(this,un)&&(clearTimeout(ye(this,un)),qe(this,Bt,void 0),qe(this,un,void 0))}};un=new WeakMap;Bt=new WeakMap;var gn=class{};gn.Delay=Yp;gn.Distance=Xp;var io=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&Ut(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new gn.Delay({value:250,tolerance:5})]:op(s)&&!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||!Ut(r)||(n=t.handle)!=null&&n.contains(r))return!1;const s=Oh(r);return s===t.element?!1:!!s}}),fn,As=class extends xn{constructor(t,n){super(t),this.manager=t,this.options=n,Ce(this,fn,new Set),this.listeners=new dd,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},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:s=io.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return st(()=>{var s;const i=new AbortController,{signal:o}=i,a=u=>{ip(u)&&this.handlePointerDown(u,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const u of l)u&&(Jp(u.ownerDocument.defaultView),u.addEventListener("pointerdown",a,{signal:o}));return()=>i.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!Ut(t.target)||n.disabled||Zp(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=io.preventActivation}=r??{};if(s?.(t,n))return;const{target:i}=t,o=Pt(i)&&i.draggable&&i.getAttribute("draggable")==="true",a=kn(n.element),{x:l,y:u}=wn(t);this.initialCoordinates={x:l*a.scaleX+a.x,y:u*a.scaleY+a.y};const d=this.activationConstraints(t,n,r);t.sensor=this;const c=new bh(d,m=>this.handleStart(n,m));c.signal.onabort=()=>this.handleCancel(t),c.onEvent(t),this.controller=c;const f=Ki(),p=this.listeners.bind(f,[{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:Ur,options:{capture:!0}}]),h=()=>{p(),this.initialCoordinates=void 0};ye(this,fn).add(h)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const i=wn(t),o=kn(n.element);i.x=i.x*o.scaleX+o.x,i.y=i.y*o.scaleY+o.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=i,Ts.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:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const a=Mn(n.target).body;try{a.setPointerCapture(n.pointerId)}catch{this.handleCancel(n);return}const l=Ut(n.target)?[n.target,a]:a,u=this.listeners.bind(l,[{type:"touchmove",listener:Ur,options:{passive:!1}},{type:"click",listener:Ur},{type:"contextmenu",listener:Ur},{type:"keydown",listener:this.handleKeyDown}]);ye(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},ye(this,fn).forEach(n=>n()),ye(this,fn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};fn=new WeakMap;As.configure=Ir(As);As.defaults=io;var oo=As;function Zp(e){return"sensor"in e}function Ur(e){e.preventDefault()}function Qp(){}var sl=new WeakSet;function Jp(e){!e||sl.has(e)||(e.addEventListener("touchmove",Qp,{capture:!1,passive:!1}),sl.add(e))}var vn={modifiers:[],plugins:[Sp,Bd,Tp,la,Hp],sensors:[oo,Gd]},qd=class extends wh{constructor(e={}){const t=lt(e.plugins,vn.plugins),n=lt(e.sensors,vn.sensors),r=lt(e.modifiers,vn.modifiers);super(sa(yr({},e),{plugins:[Up,Mr,Vs,...t],sensors:n,modifiers:r}))}},Kd,Ud,ao,Ct,fa,ha,Hs=class extends(ao=ht,Ud=[fe],Kd=[fe],ao){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:i}=n,o=kd(n,["element","effects","handle"]);super(yr({effects:()=>[...s(),()=>{var a,l;const{manager:u}=this;if(!u)return;const c=((l=(a=this.sensors)==null?void 0:a.map(pr))!=null?l:[...u.sensors]).map(f=>{const p=f instanceof xn?f:u.registry.register(f.plugin),h=f instanceof xn?void 0:f.options;return p.bind(this,h)});return function(){c.forEach(p=>p())}}]},o),t),Ce(this,fa,Me(Ct,8,this)),Me(Ct,11,this),Ce(this,ha,Me(Ct,12,this)),Me(Ct,15,this),this.element=r,this.handle=i}};Ct=Rn(ao);fa=new WeakMap;ha=new WeakMap;it(Ct,4,"handle",Ud,Hs,fa);it(Ct,4,"element",Kd,Hs,ha);Qt(Ct,Hs);var Vd,Hd,lo,It,pa,hi,Xd,Yd,hr,ga,Xs=class extends(lo=pt,Hd=[fe],Vd=[fe],lo){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,i=kd(n,["element","effects"]);const{collisionDetector:o=yd}=i,a=u=>{const{manager:d,element:c}=this;if(!c||u===null){this.shape=void 0;return}if(!d)return;const f=new ut(c),p=ue(()=>this.shape);return f&&p?.equals(f)?p:(this.shape=f,f)},l=Tn(!1);super(sa(yr({},i),{collisionDetector:o,effects:()=>[...s(),()=>{const{element:u,manager:d}=this;if(!d)return;const{dragOperation:c}=d,{source:f}=c;l.value=!!(f&&c.status.initialized&&u&&!this.disabled&&this.accepts(f))},()=>{const{element:u}=this;if(l.value&&u){const d=new Lh(u,a);return()=>{d.disconnect(),this.shape=void 0}}},()=>{var u;if((u=this.manager)!=null&&u.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),Ce(this,hr),Ce(this,pa,Me(It,8,this)),Me(It,11,this),Ce(this,ga,Me(It,12,this)),Me(It,15,this),this.element=r,this.refreshShape=()=>a()}set element(e){qe(this,hr,e,Yd)}get element(){var e;return(e=this.proxy)!=null?e:ye(this,hr,Xd)}};It=Rn(lo);pa=new WeakMap;hr=new WeakSet;ga=new WeakMap;hi=it(It,20,"#element",Hd,hr,pa),Xd=hi.get,Yd=hi.set;it(It,4,"proxy",Vd,Xs,ga);Qt(It,Xs);function eg(e){return e!=null&&typeof e=="object"&&"current"in e}function bn(e){var t;if(e!=null)return eg(e)?(t=e.current)!=null?t:void 0:e}var tg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ln=tg?k.useLayoutEffect:k.useEffect;function ng(){const e=k.useState(0)[1];return k.useCallback(()=>{e(t=>t+1)},[e])}function Zd(e,t){const n=k.useRef(new Map),r=ng();return Ln(()=>{if(!e){n.current.clear();return}return st(()=>{var s;let i=!1,o=!1;for(const a of n.current){const[l]=a,u=ue(()=>a[1]),d=e[l];u!==d&&(i=!0,n.current.set(l,d),o=(s=t?.(l,u,d))!=null?s:!1)}i&&(o?queueMicrotask(()=>of.flushSync(r)):r())})},[e]),k.useMemo(()=>e&&new Proxy(e,{get(s,i){const o=s[i];return n.current.set(i,o),o}}),[e])}function rg(e,t){e()}function tn(e){const t=k.useRef(e);return Ln(()=>{t.current=e},[e]),t}function Se(e,t,n=k.useEffect,r=Object.is){const s=k.useRef(e);n(()=>{const i=s.current;r(e,i)||(s.current=e,t(e,i))},[t,e])}function hs(e,t){const n=k.useRef(bn(e));Ln(()=>{const r=bn(e);r!==n.current&&(n.current=r,t(r))})}var sg=Object.defineProperty,ig=Object.defineProperties,og=Object.getOwnPropertyDescriptors,Ps=Object.getOwnPropertySymbols,Qd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,il=(e,t,n)=>t in e?sg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ag=(e,t)=>{for(var n in t||(t={}))Qd.call(t,n)&&il(e,n,t[n]);if(Ps)for(var n of Ps(t))Jd.call(t,n)&&il(e,n,t[n]);return e},lg=(e,t)=>ig(e,og(t)),cg=(e,t)=>{var n={};for(var r in e)Qd.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ps)for(var r of Ps(e))t.indexOf(r)<0&&Jd.call(e,r)&&(n[r]=e[r]);return n},dg=new qd,eu=k.createContext(dg),ug=k.memo(k.forwardRef(({children:e},t)=>{const[n,r]=k.useState(0),s=k.useRef(null),i=k.useRef(null),o=k.useMemo(()=>({renderer:{get rendering(){var a;return(a=s.current)!=null?a:Promise.resolve()}},trackRendering(a){s.current||(s.current=new Promise(l=>{i.current=l})),k.startTransition(()=>{a(),r(l=>l+1)})}}),[]);return Ln(()=>{var a;(a=i.current)==null||a.call(i),s.current=null},[e,n]),k.useImperativeHandle(t,()=>o),null})),pi=[void 0,ot];function fg(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:i,onDragMove:o,onDragOver:a,onDragEnd:l}=t,u=cg(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const d=k.useRef(null),{plugins:c,modifiers:f,sensors:p}=u,h=lt(c,vn.plugins),m=lt(p,vn.sensors),y=lt(f,vn.modifiers),w=tn(s),v=tn(i),g=tn(a),b=tn(o),_=tn(l),O=tn(r),I=hg(()=>{var M;return(M=u.manager)!=null?M:new qd(u)});return k.useEffect(()=>{if(!d.current)throw new Error("Renderer not found");const{renderer:M,trackRendering:T}=d.current,{monitor:D}=I;I.renderer=M;const N=[D.addEventListener("beforedragstart",R=>{const W=w.current;W&&T(()=>W(R,I))}),D.addEventListener("dragstart",R=>{var W;return(W=v.current)==null?void 0:W.call(v,R,I)}),D.addEventListener("dragover",R=>{const W=g.current;W&&T(()=>W(R,I))}),D.addEventListener("dragmove",R=>{const W=b.current;W&&T(()=>W(R,I))}),D.addEventListener("dragend",R=>{const W=_.current;W&&T(()=>W(R,I))}),D.addEventListener("collision",R=>{var W;return(W=O.current)==null?void 0:W.call(O,R,I)})];return()=>N.forEach(R=>R())},[I]),Se(h,()=>I&&(I.plugins=h),...pi),Se(m,()=>I&&(I.sensors=m),...pi),Se(y,()=>I&&(I.modifiers=y),...pi),x.jsxs(eu.Provider,{value:I,children:[x.jsx(ug,{ref:d,children:n}),n]})}function hg(e){const t=k.useRef(null);return t.current||(t.current=e()),k.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}function pg(){return k.useContext(eu)}function tu(e){var t;const n=(t=pg())!=null?t:void 0,[r]=k.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Ln(r.register,[n,r]),r}var gg=Object.create,nu=Object.defineProperty,mg=Object.getOwnPropertyDescriptor,ru=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ys=e=>{throw TypeError(e)},vg=(e,t,n)=>t in e?nu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bg=e=>{var t;return[,,,gg((t=e?.[ru("metadata")])!=null?t:null)]},su=["class","method","getter","setter","accessor","field","value","get","set"],iu=e=>e!==void 0&&typeof e!="function"?Ys("Function expected"):e,yg=(e,t,n,r,s)=>({kind:su[e],name:t,metadata:r,addInitializer:i=>n._?Ys("Already initialized"):s.push(iu(i||null))}),xg=(e,t)=>vg(t,ru("metadata"),e[3]),wg=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)i[s].call(n);return r},ou=(e,t,n,r,s,i)=>{for(var o,a,l,u,d=t&7,c=!1,f=!1,p=2,h=su[d+5],m=e[p]||(e[p]=[]),y=(s=s.prototype,mg(s,n)),w=r.length-1;w>=0;w--)l=yg(d,n,a={},e[3],m),l.static=c,l.private=f,u=l.access={has:v=>n in v},u.get=v=>v[n],o=(0,r[w])(y[h],l),a._=1,iu(o)&&(y[h]=o);return y&&nu(s,n,y),s},au=(e,t,n)=>t.has(e)||Ys("Cannot "+n),_g=(e,t,n)=>(au(e,t,"read from private field"),t.get(e)),kg=(e,t,n)=>t.has(e)?Ys("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Sg=(e,t,n,r)=>(au(e,t,"write to private field"),t.set(e,n),n),qt=class co{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new co(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 co(t,n)}},lu,cu,uo,ps,jr,ma=class extends(uo=Yt,cu=[Ee],lu=[Ee],uo){constructor(e){const t=qt.from(e);super(t,(n,r)=>qt.equals(n,r)),wg(jr,5,this),kg(this,ps,0),this.velocity={x:0,y:0}}get delta(){return qt.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=qt.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),i=s-_g(this,ps),o=a=>Math.round(a/i*100);Te(()=>{Sg(this,ps,s),this.velocity={x:o(r.x),y:o(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(qt.from(e)),this.velocity={x:0,y:0}}};jr=bg(uo);ps=new WeakMap;ou(jr,2,"delta",cu,ma);ou(jr,2,"direction",lu,ma);xg(jr,ma);var du=(e=>(e.Horizontal="x",e.Vertical="y",e))(du||{});Object.values(du);var $g=({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 s=qt.distance(t.shape.center,n);return{id:r,value:1/s,type:Pn.PointerIntersection,priority:An.High}}return null},Tg=({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:s}=e,i=qt.distance(t.shape.center,s.current),a=r/(n.current.area+t.shape.area-r)/i;return{id:t.id,value:a,type:Pn.ShapeIntersection,priority:An.Normal}}return null},Og=e=>{var t;return(t=$g(e))!=null?t:Tg(e)};function Eg(e){const{collisionDetector:t,data:n,disabled:r,element:s,id:i,accept:o,type:a}=e,l=tu(d=>new Xs(lg(ag({},e),{register:!1,element:bn(s)}),d)),u=Zd(l);return Se(i,()=>l.id=i),hs(s,d=>l.element=d),Se(o,()=>l.accept=o,void 0,ot),Se(t,()=>l.collisionDetector=t??Og),Se(n,()=>n&&(l.data=n)),Se(r,()=>l.disabled=r===!0),Se(a,()=>l.type=a),{droppable:u,get isDropTarget(){return u.isDropTarget},ref:k.useCallback(d=>{var c,f;!d&&((c=l.element)!=null&&c.isConnected)&&!((f=l.manager)!=null&&f.dragOperation.status.idle)||(l.element=d??void 0)},[l])}}const ol=`url("data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>')}")`,uu=(e,t="line")=>{const n=[":is(p, h1, h2, h3, h4, h5, h6):first-child::after","> * > span:only-child::after"],r=o=>n.map(a=>`${o} ${a}`).join(", "),s=t==="line"?"&::after":r("&"),i=t==="line"?"&:hover::after, &:focus-visible::after":`${r("&:hover")}, ${r("&:focus-visible")}`;return{cursor:"text",borderRadius:"2px",[s]:{content:'""',display:"inline-block",width:"0.8em",height:"0.8em",ml:"0.4em",verticalAlign:"-0.05em",backgroundColor:"currentColor",maskImage:ol,WebkitMaskImage:ol,maskSize:"contain",WebkitMaskSize:"contain",maskRepeat:"no-repeat",WebkitMaskRepeat:"no-repeat",opacity:.35,transition:`opacity ${E.MOTION_FAST}`,...E.reducedMotionSx,pointerEvents:"none"},[i]:{opacity:.8},"&:focus-visible":{outline:`2px solid ${e.accent}`,outlineOffset:2}}},fu=k.createContext(void 0);function hu(e,t){const n=k.useContext(fu),r=k.useRef(t);r.current=t,k.useEffect(()=>{if(!n||!e)return;const i=()=>r.current();return n.commitRef.current=i,()=>{n.commitRef.current===i&&(n.commitRef.current=void 0)}},[n,e]);const s=k.useRef(!1);k.useLayoutEffect(()=>{!e&&!s.current||(s.current=e,n?.setDirty(e))},[n,e]),k.useLayoutEffect(()=>()=>{s.current&&n?.setDirty(!1)},[n])}function fo({value:e,placeholder:t,ariaLabel:n,onCommit:r,faintWhenEmpty:s=!1}){const{theme:i}=Ke.usePublisherTheme(),[o,a]=k.useState(void 0),l=k.useRef(!1),u=()=>{l.current||o===void 0||(a(void 0),o!==e&&r(o))};hu(o!==void 0&&o!==e,()=>(u(),!0));const d=()=>{l.current=!1,a(e)};if(o===void 0){const c=e==="",f=c&&s;return x.jsx(S.Box,{component:"button",type:"button",className:f?"builder-affordance":void 0,onClick:d,onKeyDown:p=>{p.key!=="Enter"&&p.key!==" "||(p.preventDefault(),d())},sx:[{all:"unset",boxSizing:"border-box",font:"inherit",color:"inherit",display:"inline-block",maxWidth:"100%",...c&&{fontStyle:"italic",opacity:f?0:.6}},uu(i)],children:c?t:e})}return x.jsx(S.InputBase,{autoFocus:!0,fullWidth:!0,value:o,placeholder:t,inputProps:{"aria-label":n},onFocus:c=>c.target.select(),onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&!c.nativeEvent.isComposing?u():c.key==="Escape"&&(l.current=!0,a(void 0))},onBlur:u,sx:{font:"inherit",color:"inherit",p:0,"& input":{p:0}}})}const Cg=(e,t)=>e.map((n,r)=>{const s=t[r]??!1;if(s===(n.break??!1))return n;const i={...n};return s?i.break=!0:delete i.break,i}),Ig=(e,t,n)=>{const r=[...e],[s]=r.splice(t,1);if(!s)return[...e];const i=r[t];s.break&&i&&!i.break&&(r[t]={...i,break:!0});const o={...s};return delete o.break,r.splice(n,0,o),r},pu=(e,t)=>({kind:"tile",tile:e,index:t,colspan:e.colspan,break:e.break}),gu=e=>`gap.${e}`,Dg=(e,t)=>{const n=[];let r=0;e.forEach((i,o)=>{const a=Math.min(i.colspan??1,t),l=o===0||i.break===!0||r+a>t;l&&o>0&&r<t&&n.push({kind:"gap",after:Fe(e[o-1]),colspan:t-r}),l&&(r=0),n.push(pu(i,o)),r+=a});const s=e.at(-1);return s&&r<t&&n.push({kind:"gap",after:Fe(s),colspan:t-r}),n};var Ag=Object.create,mu=Object.defineProperty,Pg=Object.defineProperties,Mg=Object.getOwnPropertyDescriptor,jg=Object.getOwnPropertyDescriptors,Ms=Object.getOwnPropertySymbols,vu=Object.prototype.hasOwnProperty,bu=Object.prototype.propertyIsEnumerable,Rg=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Rr=e=>{throw TypeError(e)},ho=(e,t,n)=>t in e?mu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gi=(e,t)=>{for(var n in t||(t={}))vu.call(t,n)&&ho(e,n,t[n]);if(Ms)for(var n of Ms(t))bu.call(t,n)&&ho(e,n,t[n]);return e},mi=(e,t)=>Pg(e,jg(t)),Lg=(e,t)=>{var n={};for(var r in e)vu.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Ms)for(var r of Ms(e))t.indexOf(r)<0&&bu.call(e,r)&&(n[r]=e[r]);return n},Ng=e=>{var t;return[,,,Ag((t=void 0)!=null?t:null)]},yu=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Rr("Function expected"):e,Fg=(e,t,n,r,s)=>({kind:yu[e],name:t,metadata:r,addInitializer:i=>n._?Rr("Already initialized"):s.push(rr(i||null))}),zg=(e,t)=>ho(t,Rg("metadata"),e[3]),Vr=(e,t,n,r)=>{for(var s=0,i=e[t>>1],o=i&&i.length;s<o;s++)t&1?i[s].call(n):r=i[s].call(n,r);return r},xu=(e,t,n,r,s,i)=>{for(var o,a,l,u,d,c=t&7,f=!1,p=!1,h=e.length+1,m=yu[c+5],y=e[h-1]=[],w=e[h]||(e[h]=[]),v=(s=s.prototype,Mg({get[n](){return sr(this,i)},set[n](b){return Gt(this,i,b)}},n)),g=r.length-1;g>=0;g--)u=Fg(c,n,l={},e[3],w),u.static=f,u.private=p,d=u.access={has:b=>n in b},d.get=b=>b[n],d.set=(b,_)=>b[n]=_,a=(0,r[g])({get:v.get,set:v.set},u),l._=1,a===void 0?rr(a)&&(v[m]=a):typeof a!="object"||a===null?Rr("Object expected"):(rr(o=a.get)&&(v.get=o),rr(o=a.set)&&(v.set=o),rr(o=a.init)&&y.unshift(o));return v&&mu(s,n,v),s},wu=(e,t,n)=>t.has(e)||Rr("Cannot "+n),sr=(e,t,n)=>(wu(e,t,"read from private field"),t.get(e)),Gn=(e,t,n)=>t.has(e)?Rr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Gt=(e,t,n,r)=>(wu(e,t,"write to private field"),t.set(e,n),n);function Kt(e){return e instanceof ya||e instanceof $u}var Hr=10,Wg=class extends We{constructor(e){super(e);const t=st(()=>{const{dragOperation:r}=e;if(br(r.activatorEvent)&&Kt(r.source)&&r.status.initialized){const s=e.registry.plugins.get(Mr);if(s)return s.disable(),()=>s.enable()}}),n=e.monitor.addEventListener("dragmove",(r,s)=>{queueMicrotask(()=>{if(this.disabled||r.defaultPrevented||!r.nativeEvent)return;const{dragOperation:i}=s;if(!br(r.nativeEvent)||!Kt(i.source)||!i.shape)return;const{actions:o,collisionObserver:a,registry:l}=s,{by:u}=r;if(!u)return;const d=Bg(u),{source:c,target:f}=i,{center:p}=i.shape.current,h=[],m=[];Te(()=>{for(const _ of l.droppables){const{id:O}=_;if(!_.accepts(c)||O===f?.id&&Kt(_)||!_.element)continue;let I=_.shape;const M=new ut(_.element,{getBoundingClientRect:T=>mr(T,void 0,.2)});!M.height||!M.width||(d=="down"&&p.y+Hr<M.center.y||d=="up"&&p.y-Hr>M.center.y||d=="left"&&p.x-Hr>M.center.x||d=="right"&&p.x+Hr<M.center.x)&&(h.push(_),_.shape=M,m.push(()=>_.shape=I))}}),r.preventDefault(),a.disable();const y=a.computeCollisions(h,cp);Te(()=>m.forEach(_=>_()));const[w]=y;if(!w)return;const{id:v}=w,{index:g,group:b}=c.sortable;o.setDropTarget(v).then(()=>{const{source:_,target:O,shape:I}=i;if(!_||!Kt(_)||!I)return;const{index:M,group:T,target:D}=_.sortable,N=g!==M||b!==T,R=N?D:O?.element;if(!R)return;vd(R);const W=new ut(R);if(!W)return;const X=ft.delta(W,ft.from(I.current.boundingRectangle),_.alignment);o.move({by:X}),N?o.setDropTarget(_.id).then(()=>a.enable()):a.enable()})})});this.destroy=()=>{n(),t()}}};function Bg(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 Gg=Object.defineProperty,qg=Object.defineProperties,Kg=Object.getOwnPropertyDescriptors,al=Object.getOwnPropertySymbols,Ug=Object.prototype.hasOwnProperty,Vg=Object.prototype.propertyIsEnumerable,ll=(e,t,n)=>t in e?Gg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nn=(e,t)=>{for(var n in t||(t={}))Ug.call(t,n)&&ll(e,n,t[n]);if(al)for(var n of al(t))Vg.call(t,n)&&ll(e,n,t[n]);return e},rn=(e,t)=>qg(e,Kg(t));function Hg(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function Xr(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function vi(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Xg(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,b)=>g===b||g!==null&&typeof g=="object"&&"id"in g&&g.id===b;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),b=e.findIndex(_=>l(_,o.id));if(g===-1||b===-1){if(vi(i)){const _=i.initialIndex,O=i.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,b)}const u=Object.entries(e);let d=-1,c,f=-1,p;for(const[g,b]of u)if(d===-1&&(d=b.findIndex(_=>l(_,i.id)),d!==-1&&(c=g)),f===-1&&(f=b.findIndex(_=>l(_,o.id)),f!==-1&&(p=g)),d!==-1&&f!==-1)break;if(d===-1&&vi(i)){const g=i.initialGroup==null?void 0:Xr(e,i.initialGroup),b=i.initialIndex,_=i.group==null?void 0:Xr(e,i.group),O=i.index;if(g==null||_==null||g===_&&b===O)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return rn(nn({},e),{[g]:n(e[g],b,O)});const I=e[g][b];return rn(nn({},e),{[g]:[...e[g].slice(0,b),...e[g].slice(b+1)],[_]:[...e[_].slice(0,O),I,...e[_].slice(O)]})}if(!i.manager)return e;const{dragOperation:h}=i.manager,m=(s=(r=h.shape)==null?void 0:r.current.center)!=null?s:h.position.current;if(p==null){const g=Xr(e,o.id);if(g!=null){const b=o.shape&&m.y>o.shape.center.y?e[g].length:0;p=g,f=b}}if(c==null||p==null||c===p&&d===f){if(c!=null&&c===p&&d===f&&vi(i)){const g=i.group==null?void 0:Xr(e,i.group),b=i.group!=null&&g!==c,_=i.index!==d;if(b||_){const O=i.group==null?c:g;if(O!=null){if(c===O)return rn(nn({},e),{[c]:n(e[c],d,i.index)});const I=e[c][d];return rn(nn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[O]:[...e[O].slice(0,i.index),I,...e[O].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return rn(nn({},e),{[c]:n(e[c],d,f)});const w=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][d];return rn(nn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[p]:[...e[p].slice(0,f+w),v,...e[p].slice(f+w)]})}function Yg(e,t){return Xg(e,t,Hg)}function cl(e){const t=new Map;for(const[,n]of e)for(const r of n)t.set(r.id,r.index);return t}function dl(e,t,n){var r;for(const[s,i]of t)for(const o of i){const a=e.get(o.id);if(o.index!==a||o.group!==s||!((r=n.get(s))!=null&&r.has(o)))return!0}return!1}var ul="__default__",Zg=class extends We{constructor(e){super(e);const t=()=>{const r=new Map;for(const s of e.registry.droppables)if(s instanceof ya){const{sortable:i}=s,{group:o}=i;let a=r.get(o);a||(a=new Set,r.set(o,a)),a.add(i)}return r},n=[e.monitor.addEventListener("dragover",(r,s)=>{if(this.disabled)return;const{dragOperation:i}=s,{source:o,target:a}=i;if(!Kt(o)||!Kt(a)||o.sortable===a.sortable)return;const l=t(),u=cl(l),d=o.sortable.group===a.sortable.group,c=l.get(o.sortable.group),f=d?c:l.get(a.sortable.group);!c||!f||queueMicrotask(()=>{r.defaultPrevented||s.renderer.rendering.then(()=>{var p,h;const m=t();if(dl(u,l,m))return;const y=o.sortable.element,w=a.sortable.element;if(!w||!y||!d&&a.id===o.sortable.group)return;const v=Yr(c),g=d?v:Yr(f),b=(p=o.sortable.group)!=null?p:ul,_=(h=a.sortable.group)!=null?h:ul,O={[b]:v,[_]:g},I=Yg(O,r);if(O===I)return;const M=I[_].indexOf(o.sortable),T=I[_].indexOf(a.sortable);s.collisionObserver.disable(),fl(y,M,w,T),Te(()=>{for(const[D,N]of I[b].entries())N.index=D;if(!d)for(const[D,N]of I[_].entries())N.group=a.sortable.group,N.index=D}),s.actions.setDropTarget(o.id).then(()=>s.collisionObserver.enable())})})}),e.monitor.addEventListener("dragend",(r,s)=>{if(!r.canceled)return;const{dragOperation:i}=s,{source:o}=i;Kt(o)&&(o.sortable.initialIndex===o.sortable.index&&o.sortable.initialGroup===o.sortable.group||queueMicrotask(()=>{const a=t(),l=cl(a),u=a.get(o.sortable.initialGroup);u&&s.renderer.rendering.then(()=>{const d=t();if(dl(l,a,d))return;const c=Yr(u),f=Yr(u,Jg),p=o.sortable.element,h=f.indexOf(o.sortable),m=c[h],y=m?.element;!m||!y||!p||(fl(p,m.index,y,o.index),Te(()=>{for(const w of a.values()){const v=Array.from(w).values();for(const g of v)g.index=g.initialIndex,g.group=g.initialGroup}}))})}))})];this.destroy=()=>{for(const r of n)r()}}};function fl(e,t,n,r){const s=r<t?"afterend":"beforebegin";n.insertAdjacentElement(s,e)}function Qg(e,t){return e.index-t.index}function Jg(e,t){return e.initialIndex-t.initialIndex}function Yr(e,t=Qg){return Array.from(e).sort(t)}var hl=[Wg,Zg],_u={duration:250,easing:"cubic-bezier(0.25, 1, 0.5, 1)",idle:!1};function pl(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 Zr=new Uf,ku,Su,Dt,va,ir,or,ba,hn;Su=[fe],ku=[fe];var Zs=class{constructor(e,t){Gn(this,va,Vr(Dt,8,this)),Vr(Dt,11,this),Gn(this,ir),Gn(this,or),Gn(this,ba,Vr(Dt,12,this)),Vr(Dt,15,this),Gn(this,hn),this.register=()=>(Te(()=>{var h,m;(h=this.manager)==null||h.registry.register(this.droppable),(m=this.manager)==null||m.registry.register(this.draggable)}),()=>this.unregister()),this.unregister=()=>{Te(()=>{var h,m;(h=this.manager)==null||h.registry.unregister(this.droppable),(m=this.manager)==null||m.registry.unregister(this.draggable)})},this.destroy=()=>{Te(()=>{this.droppable.destroy(),this.draggable.destroy()})};var n=e,{effects:r=()=>[],disabled:s,group:i,index:o,sensors:a,type:l,transition:u=_u,plugins:d}=n,c=Lg(n,["effects","disabled","group","index","sensors","type","transition","plugins"]);const f=lt(d,hl),p=pl(s);this.droppable=new ya(mi(gi({},c),{disabled:p.droppable}),t,this),this.draggable=new $u(mi(gi({},c),{disabled:p.draggable,plugins:f,effects:()=>[()=>{var h,m,y;const w=(h=this.manager)==null?void 0:h.dragOperation.status;w?.initializing&&this.id===((y=(m=this.manager)==null?void 0:m.dragOperation.source)==null?void 0:y.id)&&Zr.clear(this.manager),w?.dragging&&Zr.set(this.manager,this.id,ue(()=>({initialIndex:this.index,initialGroup:this.group})))},()=>{const{index:h,group:m,manager:y}=this,w=sr(this,or),v=sr(this,ir);(h!==w||m!==v)&&(Gt(this,or,h),Gt(this,ir,m),this.animate())},()=>{var h,m;const{target:y}=this,{isDragSource:w}=this.draggable;((m=(h=this.draggable.pluginConfig(la))==null?void 0:h.feedback)!=null?m:"default")==="move"&&w&&(this.droppable.disabled=!y)},...r()],type:l,sensors:a}),t,this),Gt(this,hn,c.element),this.manager=t,this.index=o,Gt(this,or,o),this.group=i,Gt(this,ir,i),this.type=l,this.transition=u}get initialIndex(){var e,t;return(t=(e=Zr.get(this.manager,this.id))==null?void 0:e.initialIndex)!=null?t:this.index}get initialGroup(){var e,t;return(t=(e=Zr.get(this.manager,this.id))==null?void 0:e.initialGroup)!=null?t:this.group}animate(){ue(()=>{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:s}=this;if(!s)return;for(const d of s.getAnimations())"transitionProperty"in d&&(d.transitionProperty==="transform"||d.transitionProperty==="translate"||d.transitionProperty==="scale")&&d.cancel();const i=this.refreshShape();if(!i)return;const o={x:n.boundingRectangle.left-i.boundingRectangle.left,y:n.boundingRectangle.top-i.boundingRectangle.top},{translate:a}=gt(s),l=Ya(s,a,!1),u=Ya(s,a);if(o.x||o.y){const d=ea(Qe(s))?mi(gi({},t),{duration:0}):t;bd({element:s,keyframes:{translate:[`${l.x+o.x}px ${l.y+o.y}px ${l.z}`,`${u.x}px ${u.y}px ${u.z}`]},options:d}).then(()=>{e.dragOperation.status.dragging||(this.droppable.shape=void 0)})}})})}get manager(){return this.draggable.manager}set manager(e){Te(()=>{this.draggable.manager=e,this.droppable.manager=e})}set element(e){Te(()=>{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),Gt(this,hn,e)})}get element(){var e,t;const n=sr(this,hn);if(n)return(t=(e=Ui.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=lt(e,hl)}set disabled(e){const t=pl(e);Te(()=>{this.droppable.disabled=t.droppable,this.draggable.disabled=t.draggable})}set data(e){Te(()=>{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??yd}set alignment(e){this.draggable.alignment=e}get alignment(){return this.draggable.alignment}set type(e){Te(()=>{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)}};Dt=Ng();va=new WeakMap;ir=new WeakMap;or=new WeakMap;ba=new WeakMap;hn=new WeakMap;xu(Dt,4,"index",Su,Zs,va);xu(Dt,4,"group",ku,Zs,ba);zg(Dt,Zs);var $u=class extends Hs{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}},ya=class extends Xs{constructor(e,t,n){super(e,t),this.sortable=n}get index(){return this.sortable.index}get group(){return this.sortable.group}},em=Object.defineProperty,tm=Object.defineProperties,nm=Object.getOwnPropertyDescriptors,gl=Object.getOwnPropertySymbols,rm=Object.prototype.hasOwnProperty,sm=Object.prototype.propertyIsEnumerable,ml=(e,t,n)=>t in e?em(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bi=(e,t)=>{for(var n in t||(t={}))rm.call(t,n)&&ml(e,n,t[n]);if(gl)for(var n of gl(t))sm.call(t,n)&&ml(e,n,t[n]);return e},im=(e,t)=>tm(e,nm(t));function om(e){const{accept:t,collisionDetector:n,collisionPriority:r,id:s,data:i,element:o,handle:a,index:l,group:u,disabled:d,modifiers:c,sensors:f,target:p,type:h,plugins:m}=e,y=bi(bi({},_u),e.transition),w=tu(g=>new Zs(im(bi({},e),{transition:y,register:!1,handle:bn(a),element:bn(o),target:bn(p)}),g)),v=Zd(w,am);return Se(s,()=>w.id=s),Ln(()=>{Te(()=>{w.group=u,w.index=l})},[w,u,l]),Se(h,()=>w.type=h),Se(t,()=>w.accept=t,void 0,ot),Se(i,()=>i&&(w.data=i)),Se(l,()=>{var g;(g=w.manager)!=null&&g.dragOperation.status.idle&&y?.idle&&w.refreshShape()},rg),hs(a,g=>w.handle=g),hs(o,g=>w.element=g),hs(p,g=>w.target=g),Se(d,()=>w.disabled=d??!1,void 0,ot),Se(f,()=>w.sensors=f,void 0,ot),Se(n,()=>w.collisionDetector=n),Se(r,()=>w.collisionPriority=r),Se(m,()=>w.plugins=m,void 0,ot),Se(y,()=>w.transition=y,void 0,ot),Se(c,()=>w.modifiers=c,void 0,ot),Se(e.alignment,()=>w.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:k.useCallback(g=>{w.handle=g??void 0},[w]),ref:k.useCallback(g=>{var b,_;!g&&((b=w.element)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.element=g??void 0)},[w]),sourceRef:k.useCallback(g=>{var b,_;!g&&((b=w.source)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.source=g??void 0)},[w]),targetRef:k.useCallback(g=>{var b,_;!g&&((b=w.target)!=null&&b.isConnected)&&!((_=w.manager)!=null&&_.dragOperation.status.idle)||(w.target=g??void 0)},[w])}}function am(e,t,n){return!!(e==="isDragSource"&&!n&&t)}const po="tile",Tu="gap",lm=[oo.configure({activatorElements:e=>[e.element],preventActivation:(e,t)=>e.target instanceof Element&&e.target.closest(`[${Ou}]`)!==null||(oo.defaults.preventActivation?.(e,t)??!1)}),Gd],Ou="data-no-drag",cm=e=>[...e,la.configure({feedback:"clone"})];function dm({id:e,index:t,children:n}){const{ref:r,handleRef:s,isDragSource:i}=om({id:e,index:t,type:po,accept:po,collisionDetector:na,plugins:cm});return x.jsx(x.Fragment,{children:n({ref:r,handleRef:s,isDragSource:i})})}function um({id:e,after:t,children:n}){const{ref:r,isDropTarget:s}=Eg({id:e,type:Tu,accept:po,collisionDetector:na,data:{after:t}});return x.jsx(x.Fragment,{children:n({ref:r,isDropTarget:s})})}const Eu=["bar_chart","line_chart","scatter_chart","shape_map","segment_map","big_value","sparkline"],Cu=["line_chart","bar_chart","big_value","scatter_chart","shape_map","segment_map"],Qs=e=>Cu.includes(e),go=new Set([...Eu,"viz"]);function At(e){const t=e.trim();if(!/^#[ \t]/.test(t)||/[{=]/.test(t))return;const n=t.slice(1).trim().split(/[ \t]+/),r=[];let s;for(const i of n)if(i.startsWith("-")){if(s!==void 0)return;const o=i.slice(1);if(!go.has(o))return;r.push(o)}else{if(s!==void 0||!go.has(i))return;s=i}return{negated:r,...s!==void 0&&{pick:s}}}function kr(e){const t=e.trim();return!/^#[ \t]/.test(t)||At(t)?!1:(t.replace(/"(?:[^"\\]|\\.)*"/g,'""').match(/[A-Za-z_]+/g)??[]).some(r=>go.has(r))}function yn(e,t){return["#",...Cu.filter(r=>r!==e&&(t===void 0||t.includes(r))).map(r=>`-${r}`),"-viz",...e==="none"?[]:[e]].join(" ")}function fm(e){return e.pick!==void 0?Qs(e.pick)?e.pick:"custom":e.negated.includes("viz")?"none":"custom"}function hm(e){if(e.length===0)return"default";if(e.length>1)return"custom";const t=At(e[0]);return t?fm(t):"custom"}function pm(e){const t=e.filter(n=>At(n));return e.some(kr)?"custom":t.length===0?void 0:hm(t)}const gm=e=>e.filter(t=>At(t)||kr(t)),Iu=e=>e.ok===!1,De=(e,...t)=>t.every(n=>typeof e?.[n]=="function"),Lr=e=>e!==void 0&&e.ruleIndex!==void 0&&(e.childCount??0)>0,ke={sourceDefinition:e=>De(e,"sourceNameDef","isDefine","sqExplore"),exploreQueryDef:e=>De(e,"exploreQueryNameDef","isDefine","vExpr"),defExploreQuery:e=>De(e,"VIEW","subQueryDefList"),defDimension:e=>De(e,"defList","DIMENSION"),exploreProperties:e=>De(e,"exploreStatement","OCURLY","CCURLY"),queryProperties:e=>De(e,"queryStatement","OCURLY","CCURLY"),queryStatement:e=>De(e,"whereStatement","aggregateStatement","nestStatement"),whereStatement:e=>De(e,"WHERE","filterClauseList"),givenDef:e=>De(e,"givenNameDef"),givenStatement:e=>De(e,"GIVEN","givenDefList"),importStatement:e=>De(e,"IMPORT","importURL"),vArrow:e=>De(e,"ARROW","vExpr","segExpr"),segRefine:e=>De(e,"PLUS","segExpr"),segOps:e=>De(e,"queryProperties"),segField:e=>De(e,"fieldPath")&&!De(e,"segExpr"),segParen:e=>De(e,"OPAREN","CPAREN","vExpr"),compare:e=>De(e,"fieldExpr","compareOp"),givenRef:e=>De(e,"GIVEN_REF")};function mm(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 vm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
68
|
+
`&&t.push(n+1);return t}class xa{constructor(t){this.text=t,this.map=mm(t),this.lineStarts=vm(t)}map;lineStarts;commentLines=new Set;proseLines=new Set;blocks=[];span(t){if(!Lr(t))return;const n=t.start,r=t.stop;if(!n||!r)return;const s=this.map[n.startIndex],i=this.map[r.stopIndex+1];if(!(s===void 0||i===void 0||i<s))return{start:s,end:i}}terminal(t){const n=t?.symbol;if(!n)return;const r=this.map[n.startIndex],s=this.map[n.stopIndex+1];if(!(r===void 0||s===void 0||s<r))return{start:r,end:s}}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 s=n+r+1>>1;this.lineStarts[s]<=t?n=s:r=s-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 Nr(e,t,n=[]){Lr(e)&&t(e)&&n.push(e);for(let r=0;r<(e.childCount??0);r++)Nr(e.getChild(r),t,n);return n}const bm=e=>De(e,"OCURLY","CCURLY");function Sr(e,t){const n=[],r=s=>{if(Lr(s)){if(t(s)){n.push(s);return}if(!bm(s))for(let i=0;i<(s.childCount??0);i++)r(s.getChild(i))}};for(let s=0;s<(e.childCount??0);s++)r(e.getChild(s));return n}const Ae=(e,t)=>e[t]?.call(e),Ht=(e,t)=>e[t]?.call(e)??[];function ym(e,t){if(!ke.compare(t)||(t.childCount??0)!==3)return;const n=t.getChild(2);if(!ke.givenRef(n))return;const r=e.text_(t.getChild(0)),s=e.text_(t.getChild(1)),i=e.text_(n)??"";if(!(r===void 0||s===void 0))return{field:r,op:s.trim(),given:i.replace(/^\$/,"")}}function Du(e,t){const n=e.positioned(t);if(!n)return;const r=Ae(t,"filterClauseList"),s=[];for(const i of r?Ht(r,"fieldExpr"):[]){const o=e.positioned(i);if(!o)continue;const a=Nr(i,ke.givenRef).map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.replace(/^\$/,""));s.push({...o,givens:a,binding:ym(e,i)})}return{...n,clauses:s}}function mo(e,t){const n=e.span(t);if(!n)return;const r=[],s=[];for(const u of Sr(t,ke.queryStatement)){const d=e.positioned(u);d&&r.push(d);const c=Ae(u,"whereStatement");if(c&&ke.whereStatement(c)){const f=Du(e,c);f&&s.push(f)}}const i=n.start+1,o=n.end-1,a=!e.text.slice(n.start,n.end).includes(`
|
|
69
|
+
`),l=r.length?e.indentAt(r[0].span.start):e.indentAt(n.start)+" ";return{span:n,openEnd:i,closeStart:o,statements:r,wheres:s,indent:l,oneLine:a}}function wa(e,t,n){const r=[],s=e.line(t.start),i=e.line(n);for(let o=s;o<i;o++){if(e.commentLines.has(o)||e.proseLines.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 xm(e,t){const n=Ae(t,"segExpr");if(!n)return{kind:"unsupported",why:"an unreadable expression"};const r=ke.vArrow(t);if(ke.segOps(n)){const s=Ae(n,"queryProperties"),i=s&&mo(e,s);return i?{kind:"inline",stage:i,...r?{pipeline:!0}:{}}:{kind:"unsupported",why:"an unreadable body"}}if(r)return{kind:"unsupported",why:"a `->` pipeline from a named view"};if(ke.segField(n)){const s=e.span(n);return s?{kind:"reference",from:e.text.slice(s.start,s.end),fromSpan:s}:{kind:"unsupported",why:"an unreadable name"}}if(ke.segRefine(n)){const s=Ht(n,"segExpr"),i=s[0],o=s[s.length-1];let a=i;for(;ke.segRefine(a);){const f=Ht(a,"segExpr");if(f.some(p=>ke.segOps(p)||ke.segParen(p)))return{kind:"unsupported",why:"a chained refinement"};a=f[0]}if(a&&ke.segParen(a))return{kind:"unsupported",why:"a parenthesized expression"};if(!a||!ke.segField(a))return{kind:"unsupported",why:"a `{ … } + { … }` compound refinement"};const l=e.span(i);if(!l||!o)return{kind:"unsupported",why:"an unreadable refinement"};if(!ke.segOps(o)){const f=e.span(n);return f?{kind:"reference",from:e.text.slice(f.start,f.end),fromSpan:f}:{kind:"unsupported",why:"an unreadable refinement"}}const u=e.text.slice(l.start,l.end),d=Ae(o,"queryProperties"),c=d&&mo(e,d);return c?{kind:"reference",from:u,fromSpan:l,refinement:c}:{kind:"reference",from:u,fromSpan:l}}return{kind:"unsupported",why:"a parenthesized expression"}}function wm(e,t){const n=[];for(const r of Sr(t,ke.defExploreQuery)){const s=e.span(r),i=Ae(r,"subQueryDefList");if(!s||!i)continue;const o=Ht(i,"exploreQueryDef").filter(ke.exploreQueryDef),a=e.terminal(Ae(r,"VIEW"));for(const l of o){const u=e.span(l),d=Ae(l,"exploreQueryNameDef"),c=e.text_(d),f=Ae(l,"vExpr");!u||!c||!f||n.push({name:c,span:u,line:e.line(u.start),statement:s,tags:wa(e,s,a?.start??u.start),siblings:o.length,body:xm(e,f)})}}return n}function _m(e,t){const n=[];for(const r of Sr(t,ke.defDimension)){const s=e.span(r),i=Ae(r,"defList");if(!s||!i)continue;const o=e.terminal(Ae(r,"DIMENSION"));for(const a of Ht(i,"fieldDef")){const l=e.span(a),u=e.text_(Ae(a,"fieldNameDef"))?.trim(),d=e.text_(Ae(a,"fieldExpr"))?.trim();!l||!u||d===void 0||n.push({name:u,expression:d,span:l,line:e.line(l.start),statement:s,tags:wa(e,s,o?.start??l.start)})}}return n}function km(e,t){const n=[];for(const r of Nr(t,ke.sourceDefinition)){const s=e.span(r),i=e.text_(Ae(r,"sourceNameDef")),o=Ae(r,"sqExplore");if(!s||!i||!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(),d=Sr(o,ke.exploreProperties)[0],c=d&&mo(e,d),f={start:e.lineStarts[e.line(s.start)],end:s.end},p=[];if(d)for(const h of Sr(d,ke.whereStatement)){const m=Du(e,h);m&&p.push(m)}n.push({name:i,base:u,span:s,line:e.line(s.start),statement:f,...c?{properties:c}:{},views:d?wm(e,d):[],dimensions:d?_m(e,d):[],wheres:p})}return n}function Sm(e,t){const n=[];for(const r of Nr(t,ke.givenStatement)){const s=e.terminal(Ae(r,"GIVEN")),i=Ae(r,"givenDefList"),o=s?e.line(s.start):void 0;for(const a of i?Ht(i,"givenDef"):[]){const l=e.span(a),u=e.span(Ae(a,"givenNameDef")),d=u&&e.text.slice(u.start,u.end);if(!l||!u||!d)continue;const c={start:u.start,end:l.end},f=e.line(c.start);n.push({name:d,declaration:e.text.slice(c.start,c.end),span:c,line:f,statement:{start:e.lineStarts[f],end:c.end},tags:wa(e,l,c.start),...o!==void 0&&o!==f?{blockHeader:o}:{}})}}return n}function $m(e,t){const n=[];for(const r of Nr(t,ke.importStatement)){const s=e.span(r),i=e.text_(Ae(r,"importURL"));if(!s||i===void 0)continue;const o=Ae(r,"importSelect"),a=o?Ht(o,"importItem").map(l=>e.text_(l)).filter(l=>l!==void 0).map(l=>l.trim()):void 0;n.push({from:i.replace(/^['"]|['"]$/g,""),...a&&a.length>0?{names:a}:{},span:s,line:e.line(s.start),statement:s})}return n}async function Au(e){let t;try{t=await Js(e,"file://dashboard-builder.malloy")}catch(f){return{ok:!1,reason:`Malloy could not read this file: ${f}`}}const n=t.problems.filter(f=>f.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,s=r?.root;if(!s||!Lr(s)||typeof s.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 i=r?.tokenStream??{},o=typeof i.getTokens=="function"?i.getTokens():void 0;if(!o||typeof i.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 xa(e),l=_a(a,i);a.commentLines=l.lines;const u=e.split(`
|
|
70
|
+
`),d=f=>l.lines.has(f);a.proseLines=me.markdownLines(u,d),a.blocks=me.blockSpans(u,d).filter(([f])=>!u[f].trimStart().startsWith("##"));const c=km(a,s);return c.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:$m(a,s),sources:c,givens:Sm(a,s),textBlocks:Om(a,i),trailingComment:f=>l.trailing.get(f),comments:l.all,commentLine:f=>l.lines.has(f),proseLine:f=>a.proseLines.has(f),commentIn:f=>l.all.find(p=>p.start>=f.start&&p.start<f.end),blockStart:f=>Tm(a,l.lines,f)}}}async function Js(e,t){const{MalloyTranslator:n}=await E.loadMalloy(),r=new n(t,null,{urls:{[t]:e}});return{problems:r.translate().problems??[],parse:r.parseStep?.response?.parse}}function _a(e,t){const n=new Map,r=new Set,s=[],i=t.tokenSource?.vocabulary;for(const d of t.getTokens?.()??[]){const c=i?.getSymbolicName(d.type);if(c!=="COMMENT_TO_EOL"&&c!=="BLOCK_COMMENT")continue;const f=e.utf16(d.startIndex);let p=e.utf16(d.stopIndex+1);if(!(f===void 0||p===void 0||p<f)){for(;p>f&&(e.text[p-1]===`
|
|
71
|
+
`||e.text[p-1]==="\r");)p--;s.push({start:f,end:p})}}const o=[...s].sort((d,c)=>d.start-c.start);let a="",l=0;for(const d of o)a+=e.text.slice(l,Math.max(l,d.start)),a+=e.text.slice(Math.max(l,d.start),Math.max(l,d.end)).replace(/[^\n\r]/g," "),l=Math.max(l,d.end);a+=e.text.slice(l);const u=d=>a.slice(e.lineStarts[d],e.lineStarts[d+1]??a.length);for(const d of s){const c=e.line(d.start),f=e.line(d.end-1);for(let m=c;m<=f;m++)u(m).trim()===""&&r.add(m);const p=a.slice(e.lineStarts[c],d.start).trim(),h=a.slice(d.end,e.lineStarts[f+1]??a.length).trim();p!==""&&h===""&&n.set(f,d)}return{trailing:n,lines:r,all:s}}function Tm(e,t,n){const r=i=>e.text.slice(e.lineStarts[i],e.lineStarts[i+1]??e.text.length).trim();let s=n;for(let i=n-1;i>=0;i--){const o=r(i),a=e.blocks.find(([,l])=>l===i);if(a){s=i=a[0];continue}if(o===""&&!t.has(i))break;if(o.startsWith("#")||t.has(i))s=i;else break}return s}function Om(e,t){const n=t.getTokens?.()??[],r=t.tokenSource?.vocabulary,s=a=>r?.getSymbolicName(a.type),i=a=>e.text.slice(e.utf16(a.startIndex)??0,e.utf16(a.stopIndex+1)??e.text.length),o=[];for(let a=0;a<n.length;a++){if(s(n[a])!=="DOC_BLOCK_ANNOTATION_BEGIN")continue;const l=me.textBlockOpener(i(n[a]).replace(/\r?\n$/,""));if(!l)continue;const u=[];let d=a+1;for(;s(n[d]??n[a])==="BLOCK_ANNOTATION_TEXT";d++)u.push(i(n[d]));const c=n[d];if(!c||s(c)!=="BLOCK_ANNOTATION_END")continue;const f=e.line(e.utf16(n[a].startIndex)??0),p=e.utf16(c.stopIndex+1)??e.text.length,h=l.name===void 0&&l.rest?[`${l.rest}
|
|
72
72
|
`]:[];o.push({...l.name===void 0?{}:{name:l.name},route:l.route,body:[...h,...u].join("").replace(/\r\n?/g,`
|
|
73
|
-
`).replace(/\n$/,""),span:{start:e.lineStarts[f],end:p},line:f}),a=
|
|
73
|
+
`).replace(/\n$/,""),span:{start:e.lineStarts[f],end:p},line:f}),a=d}return o}function Pu(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function ka(e){let t=0,n=0;for(let r=0;r<e.length;r++){const s=e[r];if(s==='"')r=Pu(e,r);else if(s==="{"||s==="[")t++===0&&n++;else if(s==="}"||s==="]")t--;else if(n===1&&t===1&&e.startsWith("tiles",r)&&!/[A-Za-z0-9_]/.test(e[r-1]??" ")){const i=/^tiles\s*=\s*\[/.exec(e.slice(r));if(i)return Em(e,r+i[0].length-1)}}}function Em(e,t){const n=[];let r=0,s=t+1;const i=o=>{const a=e.slice(s,o),l=a.length-a.trimStart().length,u=a.trim();u!==""&&n.push({text:u,span:{start:s+l,end:s+l+u.length}})};for(let o=t+1;o<e.length;o++){const a=e[o];if(a==='"')o=Pu(e,o);else if(a==="{"||a==="[")r++;else if(a==="}")r--;else if(a==="]"){if(r===0)return i(o),{open:t,close:o,entries:n};r--}else a===","&&r===0&&(i(o),s=o+1)}}function Cm(e,t){const n=e[t];if(n==="`"){for(let r=t+1;r<e.length;r++)if(e[r]==="\\")r++;else{if(e[r]==="`")return r+1;if(e[r]===`
|
|
74
74
|
`)return e.length}return e.length}if(e.startsWith("<<<",t)){let r=t+3;for(;;){const s=e.indexOf(`
|
|
75
75
|
`,r),i=s===-1?e.length:s;if(e.slice(r,i).trim()===">>>")return i;if(s===-1)return e.length;r=s+1}}if(n==='"'||n==="'"){const r=n.repeat(3);if(e.startsWith(r,t)){for(let s=t+3;s<e.length;s++)if(e[s]==="\\")s++;else if(e.startsWith(r,s))return s+3;return e.length}for(let s=t+1;s<e.length;s++)if(e[s]==="\\")s++;else{if(e[s]===n)return s+1;if(e[s]===`
|
|
76
|
-
`)return s}return e.length}return t}function
|
|
77
|
-
`&&t.push(n+1);return t}function
|
|
78
|
-
`})}function
|
|
76
|
+
`)return s}return e.length}return t}function Im(e){const t=/^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;let n="",r=0;for(;r<e.length;){const s=Cm(e,r);if(s>r){n+=e.slice(r,s),r=s;continue}const i=e[r];if(/[=[,]/.test(i)){const o=t.exec(e.slice(r+1));if(o){const a=o[3].replace(/\\/g,"\\\\").replace(/"/g,'\\"');n+=`${i}${o[1]}"f'${a}'"`,r+=1+o[0].length;continue}}n+=i,r+=1}return n}function Mu(e,t){const n=e(t);if(n.log.length===0)return{tag:n.tag,errors:[]};const r=t.map(i=>{if(e([i]).log.length===0)return i;const o=Im(i);return e([o]).log.length===0?o:i}),s=e(r);return{tag:s.tag,errors:s.log.map(i=>i.message)}}const $r=e=>e.ok===!1;function Fr(e,t,n){const r=e.blockStart(n),s=[],i=[];for(let o=r;o<n;o++){if(e.commentLine(o))continue;if(e.proseLine(o)){i.push(o);continue}const a=t[o].trim();a.startsWith("#")&&!a.startsWith("##")&&s.push({line:o,text:a})}return{start:r,tags:s,prose:i}}const js=e=>e.map(t=>t.text);function vl(e){const t=js(e),n=pm(t);return n===void 0?{}:n==="custom"?{chart:n,chartLines:gm(t)}:{chart:n}}function Dm(e){if(!e)return;const t=[];for(const n of e.wheres)for(const r of n.clauses){if(!r.binding)continue;const{field:s,op:i,given:o}=r.binding;t.push({field:me.readPath(s),given:o,...i==="~"?{}:{op:i}})}return t.length>0?t:void 0}function Am(e,t,n){const r=[];for(const s of e.givens){const i=/^([A-Za-z_][A-Za-z0-9_]*)\s*::\s*(\S+)\s+is\s+([\s\S]+)$/.exec(s.declaration);i&&r.push({name:i[1],type:i[2],default:i[3].trim(),...Pm(n(js(Fr(e,t,s.line).tags)).tag)})}return r.length>0?r:void 0}function Pm(e){if(!e)return{};const t=e.tag("suggest"),n=t?.text("dimension"),r=e.numeric("range_min"),s=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},...s===void 0?{}:{rangeMax:s}}}function yi(e,t){const n=e?.text(t)?.trim();if(n===void 0||!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/.test(n))return;const r=Number(n);return Number.isInteger(r)&&r>=1?r:void 0}const Mm=/^"((?:[^"\\]|\\.)+)"$/,jm=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;async function Tr(e,t,n=!1){try{return await Rm(e,t,n)}catch(r){return{ok:!1,reason:`A value in this file's tags cannot be read (${r instanceof Error?r.message:String(r)}), so it cannot be opened in the builder.`}}}async function Rm(e,t,n){const{parseAnnotation:r}=await E.loadMalloyTag(),s=me.splitSourceLines(e),i=await Au(e);if(Iu(i))return{ok:!1,reason:i.reason,...i.line?{line:i.line}:{}};const o=i.parsed,a=me.descriptionNotes(s).text,l=me.artifactTag(s);if(l===void 0)return{ok:!1,reason:"No `## artifact { … }` tag, so this file is not a composite dashboard."};if(!me.artifactLeads(l.text))return{ok:!1,reason:me.ARTIFACT_NOT_FIRST,line:l.from+1};const{tag:u,errors:d}=Mu(r,[me.tagAnnotation(l.text)]),c=u?.tag("artifact"),f=c?.text("kind"),p=c?.has("tiles")===!0||u?.tag("dashboard")!==void 0,h=f==="notebook"||f!=="dashboard"&&(n?!p:t?.startsWith("notebooks/"))?"notebook":void 0,m=ka(l.text);if(m===void 0)return d.length>0?{ok:!1,reason:`The \`## artifact\` tag does not parse: ${d[0]}`}:h==="notebook"?{ok:!1,legacyNotebook:!0,reason:"This notebook is in the cell format, with no `tiles=[…]` list."}:{ok:!1,reason:"The `## artifact` tag has no `tiles=[…]` list the builder can read."};const y=o.imports.map(T=>T.names?{kind:"names",names:T.names,from:T.from}:{kind:"all",from:T.from}),w=[],v=[],g=new Map;for(const T of o.sources){const D={name:T.name,base:T.base};T.dimensions.length>0&&(D.dimensions=T.dimensions.map(R=>({name:R.name,expression:R.expression})));const N=new Set(T.wheres.flatMap(R=>R.clauses.flatMap(W=>W.givens)));N.size>0&&(D.scopedBy=Array.from(N)),w.push(D);for(const R of T.dimensions){const W=r(js(Fr(o,s,R.line).tags)).tag?.tag("drill");if(!W)continue;const X=W.textArray("to")??[W.text("to")??""];v.push({source:T.name,name:R.name,expression:R.expression,to:X.filter(Boolean),...W.text("given")?{given:W.text("given")}:{}})}g.set(T.name,new Map(T.views.map(R=>[R.name,R])))}const b=[];for(const{text:T}of m.entries){const D=Mm.exec(T),N=D?void 0:jm.exec(T)?.[1];if(N!==void 0){const A=r([`# ${T}`]).tag?.tag(N);if(A?.text("kind")!=="text")return{ok:!1,reason:`The tile \`${T}\` is neither a quoted \`source -> view\` expression nor a \`${N} { kind=text }\` entry, which are the only forms the builder can lay out.`};if(b.some(z=>je(z)&&z.name===N))return{ok:!1,reason:`Two text tiles are named \`${N}\`, so the builder cannot tell them apart.`};const B=yi(A,"colspan");b.push({kind:"text",name:N,markdown:o.textBlocks.find(z=>z.name===N)?.body??"",...B===void 0?{}:{colspan:B},...A.has("break")?{break:!0}:{}});continue}const R=D?.[1]??T,W=D?me.tileSteps(R):void 0;if(!W)return{ok:!1,reason:`The tile \`${R}\` is not a \`source -> view\` expression, which is the only form the builder can lay out.`};const{source:X,view:G}=W,U=g.get(X)?.get(G);if(U===void 0){b.push({name:G,source:X,declaration:{kind:"inherited"}});continue}const Y=r(js(U.tags)).tag,re=U.body.kind==="reference"?{kind:"reference",from:U.body.from}:U.body.kind==="inline"?{kind:"inline"}:void 0;if(re===void 0){b.push({name:G,source:X,declaration:{kind:"opaque",why:U.body.kind==="unsupported"?U.body.why:"unreadable"},...Y?.text("label")?{label:Y.text("label")}:{},...Y?.text("subtitle")?{subtitle:Y.text("subtitle")}:{},...Y?.numeric("colspan")!==void 0?{colspan:Y.numeric("colspan")}:{},...vl(U.tags),...Y?.has("break")?{break:!0}:{},...Y?.has("borderless")?{borderless:!0}:{}});continue}const ee=Dm(U.body.kind==="reference"?U.body.refinement:U.body.kind==="inline"?U.body.stage:void 0);b.push({name:G,source:X,declaration:re,...ee?{filters:ee}:{},...Y?.text("label")?{label:Y.text("label")}:{},...Y?.text("subtitle")?{subtitle:Y.text("subtitle")}:{},...Y?.numeric("colspan")!==void 0?{colspan:Y.numeric("colspan")}:{},...vl(U.tags),...Y?.has("break")?{break:!0}:{},...Y?.has("borderless")?{borderless:!0}:{}})}const _=Am(o,s,r),O={},I=c?.tag("givens");for(const T of Object.keys(I?.dict??{})){const D=I?.text(T);D!==void 0&&(O[T]=D)}const M=u?.tag("dashboard")?.has("columns")?yi(u.tag("dashboard"),"columns"):c?.array("tiles")?yi(c,"dashboard_columns"):void 0;return{ok:!0,document:{...h?{kind:h}:{},title:c?.text("title")??"",...a?{description:a}:{},...M===void 0?{}:{columns:M},...c?.has("autorun")?{autorun:c.isTrue("autorun")}:{},imports:y,sources:w,..._?{localGivens:_}:{},...Object.keys(O).length>0?{startingGivens:O}:{},...v.length>0?{drills:v}:{},tiles:b}}}const Rs=e=>e.ok===!1;async function bl(e){const{problems:t}=await Js(e,"file://splice-check.malloy");return t.filter(n=>n.code==="syntax-error").map(n=>n.message??"").sort()}function _e(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n=="object"){const r={};for(const s of Object.keys(n).sort())r[s]=t(n[s]);return r}return n};return JSON.stringify(t(e))}function ju(e){return e.replace(/^(?:[ \t]*\r?\n)+/,"").trimEnd()}function Lm(e){const t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
77
|
+
`&&t.push(n+1);return t}function Nm(e,t){let n=e;for(const r of[...t].sort((s,i)=>i.start-s.start||i.end-s.end))n=n.slice(0,r.start)+r.text+n.slice(r.end);return n}const Ru=e=>e==="none"||Qs(e)?e:void 0;function Lu(e,t=!0){const n=[];e.colspan!==void 0&&n.push(`# colspan=${e.colspan}`),e.break&&n.push("# break"),e.borderless&&n.push("# borderless"),e.label!==void 0&&n.push(`# label=${bt(e.label)}`),e.subtitle!==void 0&&n.push(`# subtitle=${bt(e.subtitle)}`);const r=t?Ru(e.chart):void 0;return r!==void 0&&n.push(yn(r,e.chartCarried)),n}function gs(e){return/^#\s*([a-z_]+)/.exec(e)?.[1]}const Fm=new Set(["colspan","break","borderless","label","subtitle"]),zm=new Set(["label","description","control","suggest","range_min","range_max"]),Xe=e=>e.kind??"dashboard";function yl(e){const t=[];if(e.label!==void 0&&t.push(`label=${bt(e.label)}`),e.description!==void 0&&t.push(`description=${bt(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=${bt(e.suggest.query)}`:void 0;t.push(`suggest { ${n?`${n} `:""}dimension=${bt(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 xl=e=>`given: ${e.name} :: ${e.type} is ${e.default}`;function Wm(e,t,n){const r=e.sources.find(s=>s.name===t)?.views.find(s=>s.name===n);return r?r.line:-1}function wl(e){return`# drill { to=${e.to.length===1?e.to[0]:`[${e.to.map(n=>`"${n}"`).join(", ")}]`}${e.given?` given=${e.given}`:""} }`}const Ls=e=>`${e.source}.${e.name}`,bt=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`,vo=e=>je(e)?_e(["text",e.name]):_e([e.name,e.source,e.declaration]),nt=vo,_l=e=>_e(e.tiles.map(nt));function Bm(e,t,n,r){if(Xe(e)!==Xe(t)&&!n)return{ok:!1,reason:"The document's kind is not changed by an ordinary edit; switch it with the explicit kind change."};const s=new Set(e.tiles.map(nt)),i=new Set(t.tiles.map(nt)),o=e.tiles.filter(h=>!i.has(nt(h))),a=t.tiles.filter(h=>!s.has(nt(h))),u=o.length>0||a.length>0||_l(e)!==_l(t);for(const h of a)if(xe(h)&&h.declaration.kind!=="reference")return{ok:!1,reason:`A new tile names a view of a source; \`${h.name}\` is ${h.declaration.kind==="inline"?"an inline query":"not declared here"}, which the builder cannot write.`};const d=new Map(e.sources.map(h=>[h.name,h])),c=new Set(t.imports.flatMap(h=>h.kind==="names"?h.names:[]));for(const h of e.sources)c.add(h.base);const f=t.imports.some(h=>h.kind==="all"),p=t.sources.filter(h=>!d.has(h.name));for(const h of e.sources){const m=t.sources.find(y=>y.name===h.name);if(!m||m.base!==h.base)return{ok:!1,reason:`The source \`${h.name}\` cannot be changed or removed here.`}}for(const h of p){if(!a.some(m=>xe(m)&&m.source===h.name))return{ok:!1,reason:`A new source \`${h.name}\` needs a tile on it.`};if(!c.has(h.base)&&!f&&!r?.includes(h.base))return{ok:!1,reason:`\`${h.base}\` is not imported in this file, so a tile cannot be put on it.`}}return{currentKeys:s,nextKeys:i,removedTiles:o,addedTiles:a,newSources:p,currentSources:d,reordered:u}}const kl=(e,t)=>e.colspan!==t.colspan||!!e.break!=!!t.break;function Gm(e){let t="";for(let n=0;n<e.length;n++){if(e[n]!=='"'){t+=e[n];continue}const r=Or(e,n);t+="x".repeat(Math.min(r,e.length-1)-n+1),n=r}return t}function Sl(e,t){if(t===void 0)return`${e.name} { kind=text${e.colspan===void 0?"":` colspan=${e.colspan}`}${e.break?" break":""} }`;const n=Gm(t),r=n.indexOf("{"),s=n.lastIndexOf("}");let i=t.slice(r+1,s),o=n.slice(r+1,s);const a=u=>{const d=u.exec(o);d&&(i=i.slice(0,d.index)+i.slice(d.index+d[0].length),o=o.slice(0,d.index)+o.slice(d.index+d[0].length))};a(/\s*\bcolspan\s*=\s*[^\s}]+/),a(/\s*\bbreak\b(?!\s*=)/);const l=[i.trim(),e.colspan===void 0?"":`colspan=${e.colspan}`,e.break?"break":""].filter(Boolean);return`${t.slice(0,r)}{ ${l.join(" ")} }${t.slice(s+1)}`}function qm(e){const{lines:t,wholeLine:n,current:r,next:s,reordered:i,currentKeys:o,nextKeys:a,edits:l}=e,u=new Map(r.tiles.filter(je).map(v=>[v.name,v])),d=s.tiles.filter(je).some(v=>{const g=u.get(v.name);return g!==void 0&&kl(g,v)});if(!i&&!d)return;const c=me.artifactTag(t);if(!c)return{ok:!1,reason:"Could not find the `## artifact` tag to reorder."};const f=c.text,p=ka(f);if(!p)return{ok:!1,reason:"Could not read the `tiles=[…]` list to rewrite it."};if(a.size===0&&o.size>0)return{ok:!1,reason:"A dashboard with no tiles is not served, so the last tile cannot be removed. Add another tile first."};const h=new Map;for(const{text:v}of p.entries){const g=/^"((?:[^"\\]|\\.)+)"$/.exec(v);if(g){const _=g[1].split("->").map(O=>O.trim());_.length===2&&h.set(`${_[0]}->${_[1]}`,v);continue}const b=/^([A-Za-z_][A-Za-z0-9_]*)\s*\{/.exec(v)?.[1];b!==void 0&&h.set(`text.${b}`,v)}const m=s.tiles.map(v=>{const g=!o.has(nt(v));if(je(v)){const b=h.get(`text.${v.name}`);return b!==void 0?u.has(v.name)&&!kl(u.get(v.name),v)?b:Sl(v,b):g?Sl(v):void 0}return h.get(`${v.source}->${v.name}`)??(g?`"${v.source} -> ${v.name}"`:void 0)});if(m.some(v=>v===void 0))return{ok:!1,reason:"A tile in the new order is not one the `## artifact` tag names."};const y=f.slice(0,p.open).search(/tiles\s*=\s*$/),w=`${f.slice(0,y)}tiles=[${Km(f,p,m)}]${f.slice(p.close+1)}`;w!==f&&l.push({...Nu(n,c),text:`${w}
|
|
78
|
+
`})}function Nu(e,t){return{start:e(t.from).start,end:e(t.block?t.to-1:t.from).end}}function Km(e,t,n){const r=t.entries[0],s=t.entries[t.entries.length-1];if(!r||!/\n/.test(e.slice(t.open,t.close)))return n.join(", ");const i=e.slice(t.open+1,r.span.start),o=e.slice(s.span.end,t.close),a=i.slice(i.lastIndexOf(`
|
|
79
79
|
`)),l=t.entries.length>1?e.slice(r.span.end,t.entries[1].span.start):`,${a.startsWith(`
|
|
80
|
-
`)?a:" "}`;return`${i}${n.join(l)}${o}`}function
|
|
81
|
-
${/\n([ \t]+)\S/.exec(h)?.[1]??" "}`:" ",y=
|
|
82
|
-
`:`${h.trimEnd()} ${
|
|
80
|
+
`)?a:" "}`;return`${i}${n.join(l)}${o}`}function $l(e,t){let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];if(i==='"')s=Or(e,s);else if(i==="{"||i==="[")n++===0&&r++;else if(i==="}"||i==="]")n--;else if(r===1&&n===1&&e.startsWith(t,s)&&!/[A-Za-z0-9_]/.test(e[s-1]??" ")){const o=/^\s*=\s*/.exec(e.slice(s+t.length));if(!o)continue;const a=s+t.length+o[0].length,l=e[a]==='"'?Or(e,a)+1:a+(/^[^\s}]*/.exec(e.slice(a))?.[0].length??0),u=s-(/\s*$/.exec(e.slice(0,s))?.[0].length??0);return e.slice(0,u)+e.slice(l)}}return e}function Um(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(r==='"')n=Or(e,n);else if(r==="{"||r==="[")t++;else if(r==="}"||r==="]")t--;else if(t===0&&e.startsWith("dashboard",n)&&!/[A-Za-z0-9_]/.test(e[n-1]??" ")){const s=/^dashboard\s*\{/.exec(e.slice(n));if(!s)continue;let i=1,o=n+s[0].length;for(;o<e.length&&i>0;o++)e[o]==='"'?o=Or(e,o):e[o]==="{"?i++:e[o]==="}"&&i--;const a=n-(/\s*$/.exec(e.slice(0,n))?.[0].length??0);return e.slice(0,a)+e.slice(o)}}return e}function Or(e,t){for(let n=t+1;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==='"')return n;return e.length}function Vm(e){const{lines:t,wholeLine:n,current:r,next:s,edits:i}=e;if(Xe(r)!==Xe(s)||r.title!==s.title||r.autorun!==s.autorun||r.columns!==s.columns||_e(r.startingGivens)!==_e(s.startingGivens)){const o=me.artifactTag(t);if(!o)return{ok:!1,reason:"Could not find the `## artifact` tag to change the page's settings."};const a=Nu(n,o),l=i.find(v=>v.start===a.start&&v.end===a.end);let u=l?l.text.replace(/\n$/,""):o.text;Xe(r)!==Xe(s)&&(u=$l(u,"kind"));const d=u.indexOf("artifact"),c=u.indexOf("{",d);let f=0,p=-1;for(let v=c;v<u.length;v++)if(u[v]==="{")f++;else if(u[v]==="}"&&--f===0){p=v;break}if(c<0||p<0)return{ok:!1,reason:"Could not read the `## artifact { … }` tag."};let h=u.slice(c+1,p);const m=o.block?`
|
|
81
|
+
${/\n([ \t]+)\S/.exec(h)?.[1]??" "}`:" ",y=v=>o.block?`${h.trimEnd()}${m}${v}
|
|
82
|
+
`:`${h.trimEnd()} ${v} `,w=(v,g)=>{const b=new RegExp(`${o.block?"[ \\t]*":"\\s*"}\\b${v}=(?:"(?:[^"\\\\]|\\\\.)*"|[^\\s}]+)`);if(g===void 0){const _=new RegExp(`
|
|
83
83
|
${b.source}[ \\t]*(?=
|
|
84
|
-
)`);h=h.replace(o.block&&_.test(h)?_:b,"")}else b.test(h)?h=h.replace(b,_=>`${o.block?_.slice(0,_.length-_.trimStart().length):" "}${
|
|
84
|
+
)`);h=h.replace(o.block&&_.test(h)?_:b,"")}else b.test(h)?h=h.replace(b,_=>`${o.block?_.slice(0,_.length-_.trimStart().length):" "}${v}=${g}`):h=y(`${v}=${g}`)};if(Xe(r)!==Xe(s)&&Xe(s)==="notebook"?h=y("kind=notebook"):Xe(r)!==Xe(s)&&(e.explicitKind||!e.modelPath?.startsWith("dashboards/"))&&(h=y("kind=dashboard")),r.title!==s.title&&w("title",s.title?bt(s.title):void 0),r.autorun!==s.autorun&&w("autorun",s.autorun===void 0?void 0:String(s.autorun)),_e(r.startingGivens)!==_e(s.startingGivens)){h=h.replace(/\s*\bgivens\s*\{[^}]*\}/,"");const v=Object.entries(s.startingGivens??{});v.length>0&&(h=y(`givens { ${v.map(([g,b])=>`${g}=${bt(b)}`).join(" ")} }`))}o.block?u=`${u.slice(0,c+1)}${h}${u.slice(p)}`:(h=h.replace(/\s{2,}/g," "),u=`${u.slice(0,c+1)}${h.startsWith(" ")?h:` ${h}`}${h.endsWith(" ")?"":" "}${u.slice(p)}`),r.columns!==s.columns&&(u=$l(u,"dashboard_columns"),u=Um(u),s.columns!==void 0&&(u=`${u.trimEnd()} dashboard { columns=${s.columns} }`)),l?l.text=`${u}
|
|
85
85
|
`:i.push({...a,text:`${u}
|
|
86
|
-
`})}if(r.description!==s.description){const{read:o,blankAbove:a,below:l,belowBlock:u,inBlock:
|
|
87
|
-
`).map(
|
|
88
|
-
`),f=o.length>0&&o[0]<me.artifactLine(t),p=s.description===void 0,h=f?[...o.slice(1),...p?l:[]]:[...o,...a];for(const
|
|
89
|
-
`});else if(s.description!==void 0){const
|
|
90
|
-
`})}}}function
|
|
91
|
-
`).trim();o.push({start:n(y.line).start,end:n(_).end,text:(
|
|
86
|
+
`})}if(r.description!==s.description){const{read:o,blankAbove:a,below:l,belowBlock:u,inBlock:d}=me.descriptionNotes(t);if(d||s.description===void 0&&u)return{ok:!1,reason:"The description is written in a `##|\"` block, which the builder cannot edit in place. Change it in the file's text."};const c=ju(s.description??"").split(`
|
|
87
|
+
`).map(m=>m.trim()===""?'##"':`##" ${m.trim()}`).join(`
|
|
88
|
+
`),f=o.length>0&&o[0]<me.artifactLine(t),p=s.description===void 0,h=f?[...o.slice(1),...p?l:[]]:[...o,...a];for(const m of h)i.push({...n(m),text:""});if(f)i.push({...n(o[0]),text:s.description===void 0?"":`${c}
|
|
89
|
+
`});else if(s.description!==void 0){const m=n(me.artifactLine(t)).start;i.push({start:m,end:m,text:`${c}
|
|
90
|
+
`})}}}function Hm(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.localGivens??[]).map(p=>[p.name,p])),u=new Map((i.localGivens??[]).map(p=>[p.name,p])),d=new Map(a.givens.map(p=>[p.name,p])),c=new Set;for(const[p,h]of l){const m=u.get(p);if(m!==void 0&&_e(m)===_e(h))continue;const y=d.get(p);if(y===void 0)return{ok:!1,reason:`Could not find where the given \`${p}\` is declared.`};const{tags:w,prose:v}=Fr(a,t,y.line),b=[...(m===void 0?w:w.filter(D=>{const N=gs(D.text);return N!==void 0&&zm.has(N)})).map(D=>D.line),...m===void 0?v:[]];for(const D of b)o.push({...n(D),text:""}),c.add(D);const _=_t(a,y.span.end-1);if(m===void 0){o.push({start:n(y.line).start,end:n(_).end,text:""});for(let G=y.line;G<=_;G++)c.add(G);const D=Math.min(y.line,...b),N=y.blockHeader??D,R=(t[_+1]??"x").trim()==="",W=N===0||t[N-1].trim()==="",X=y.blockHeader===void 0||![...d.values()].some(G=>G.blockHeader===y.blockHeader&&G.line>y.line&&u.has([...d.entries()].find(([,U])=>U===G)?.[0]??""));R&&W&&X&&!c.has(_+1)&&(o.push({...n(_+1),text:""}),c.add(_+1));continue}const O=r(y.line),I=yl(m),T=m.type!==h.type||m.default!==h.default?y.blockHeader===void 0?xl(m):`${m.name} :: ${m.type} is ${m.default}`:t.slice(y.line,_+1).join(`
|
|
91
|
+
`).trim();o.push({start:n(y.line).start,end:n(_).end,text:(I?`${O}${I}
|
|
92
92
|
`:"")+`${O}${T}
|
|
93
|
-
`})}for(const[p,h]of
|
|
94
|
-
`:"")+`${
|
|
93
|
+
`})}for(const[p,h]of d){if(h.blockHeader===void 0||u.has(p))continue;![...d.values()].some(y=>y.blockHeader===h.blockHeader&&!c.has(y.line))&&!c.has(h.blockHeader)&&(o.push({...n(h.blockHeader),text:""}),c.add(h.blockHeader))}const f=[...u.values()].filter(p=>!l.has(p.name));if(f.length>0){const p=Math.max(-1,...[...d.values()].map(g=>g.line)),h=(()=>{let g=-1;for(let b=0;b<t.length;b++){const _=t[b].trim();(_.startsWith("import ")||g>=0&&/^}\s*from\s/.test(_))&&(g=b)}return g})(),m=p>=0?p:h,y=f.map(g=>{const b=yl(g);return(b?`${b}
|
|
94
|
+
`:"")+`${xl(g)}
|
|
95
95
|
`}).join(`
|
|
96
|
-
`),w=
|
|
97
|
-
${y}`}),t.some(
|
|
98
|
-
`})}}const
|
|
99
|
-
`).join("")})}}function
|
|
100
|
-
`});else{const
|
|
101
|
-
`})}}}function
|
|
102
|
-
`)};let
|
|
103
|
-
`)+p.map(b=>
|
|
96
|
+
`),w=m>=0?n(m).end:n(0).end;o.push({start:w,end:w,text:`
|
|
97
|
+
${y}`}),t.some(g=>g.trim().startsWith("##! experimental.givens"))||o.push({start:0,end:0,text:`##! experimental.givens
|
|
98
|
+
`})}}const Tl=(e,t)=>`import { ${e.join(", ")} } from ${bt(t)}`;function Xm(e){const{parsed:t,current:n,next:r,edits:s,wholeLine:i}=e,o=c=>_e(c.imports.flatMap(f=>f.kind==="all"?[f.from]:[]).sort());if(o(n)!==o(r))return{ok:!1,reason:"A whole-file `import` cannot be changed here."};if(_e(n.imports)===_e(r.imports))return;const a=r.imports.flatMap(c=>c.kind==="names"?[{...c,claimed:!1}]:[]),l=new Set([...r.sources.map(c=>c.base),...r.tiles.filter(xe).map(c=>c.source)]),u=t.imports.map((c,f)=>({statement:c,entry:n.imports[f]}));for(const{statement:c,entry:f}of u){if(!f||f.kind!=="names")continue;const p=a.find(g=>!g.claimed&&g.from===f.from);p&&(p.claimed=!0);const h=p?.names??[],y=f.names.filter(g=>!h.includes(g)).find(g=>l.has(g));if(y!==void 0)return{ok:!1,reason:`\`${y}\` is still read by a tile, so its import cannot be removed.`};if(_e(h)===_e(f.names))continue;const w=h.length===0?Sa(t,c.statement):c.statement,v=t.commentIn(w);if(v)return{ok:!1,reason:`Changing this import would also remove the comment inside it (\`${t.text.slice(v.start,v.end).trim()}\`), so nothing was written. Delete it in the file first.`};s.push({...w,text:h.length===0?"":Tl(h,f.from)})}const d=a.filter(c=>!c.claimed);if(d.length>0){const c=t.imports.at(-1);if(!c)return{ok:!1,reason:"This file has no `import` to put a source beside. Import its first source in the file."};const f=i(_t(t,c.statement.end-1)).end;s.push({start:f,end:f,text:d.map(p=>`${Tl(p.names,p.from)}
|
|
99
|
+
`).join("")})}}function Ym(e){const{lines:t,wholeLine:n,indentOf:r,current:s,next:i,edits:o,parsed:a}=e,l=new Map((s.drills??[]).map(d=>[Ls(d),d])),u=new Map((i.drills??[]).map(d=>[Ls(d),d]));for(const d of new Set([...l.keys(),...u.keys()])){const c=l.get(d),f=u.get(d);if(c&&f&&_e(c)===_e(f))continue;const p=f??c;if(f&&f.to.length===0)return{ok:!1,reason:`The drill on \`${d}\` names no destination.`};const h=a.sources.find(v=>v.name===p.source)?.dimensions.find(v=>v.name===p.name);if(h===void 0)return{ok:!1,reason:`\`${p.name}\` is not a dimension \`${p.source}\` declares in this file, so a drill cannot be put on it here.`};const{tags:m}=Fr(a,t,h.line),y=m.find(v=>/^#\s*drill\b/.test(v.text)),w=r(h.line);if(f===void 0)y&&o.push({...n(y.line),text:""});else if(y)o.push({...n(y.line),text:`${w}${wl(f)}
|
|
100
|
+
`});else{const v=n(h.line).start;o.push({start:v,end:v,text:`${w}${wl(f)}
|
|
101
|
+
`})}}}function Zm(e){const{lines:t,wholeLine:n,removedTiles:r,edits:s,parsed:i}=e;for(const o of r){if(je(o)||o.declaration.kind==="inherited")continue;const a=Fu(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=_t(i,a.statement.start),u=_t(i,a.statement.end-1),d=i.trailingComment(u),c=d&&d.start>=a.statement.end?d.end:a.statement.end;if(i.text.slice(i.lineStarts[l],a.statement.start).trim()!==""||i.text.slice(c,n(u).end).trim()!==""){s.push({...Sa(i,a.statement),text:""});continue}s.push({start:i.lineStarts[l],end:n(u).end,text:""});const p=l===0?"":t[l-1].trim();(t[u+1]??"x").trim()===""&&(l===0||p===""||p.endsWith("{"))&&s.push({...n(u+1),text:""})}}function Qm(e){const{sourceText:t,lines:n,wholeLine:r,addedTiles:s,newSources:i,currentSources:o,edits:a,parsed:l}=e,u=new Map;for(const f of s){if(je(f))continue;const p=u.get(f.source)??[];p.push(f),u.set(f.source,p)}const d=(f,p)=>{const h=f.declaration.kind==="reference"?f.declaration.from:f.name,m=(f.filters??[]).map(y=>`where: ${me.malloyPath(y.field)} ${y.op??"~"} $${y.given}`).join(", ");return[...Lu(f).map(y=>`${p}${y}`),`${p}view: ${f.name} is ${h}${m?` + { ${m} }`:""}`].join(`
|
|
102
|
+
`)};let c=-1;for(const f of l.sources)c=Math.max(c,_t(l,f.span.end-1));for(const[f,p]of u)if(o.has(f)){const h=l.sources.find(b=>b.name===f);if(!h)return{ok:!1,reason:`Could not find where the source \`${f}\` is declared.`};if(!h.properties)return{ok:!1,reason:`\`${f}\` never opens an \`extend { … }\` block, so a new tile cannot be added inside it.`};const m=h.line,y=_t(l,h.properties.closeStart);let w=" ";for(let b=m+1;b<y;b++){const _=/^(\s+)view:/.exec(n[b]);if(_){w=_[1];break}}const v=r(y).start,g=(n[y-1]??"").trim()==="";a.push({start:v,end:v,text:(g?"":`
|
|
103
|
+
`)+p.map(b=>d(b,w)).join(`
|
|
104
104
|
|
|
105
105
|
`)+`
|
|
106
|
-
`})}else{const h=i.find(
|
|
106
|
+
`})}else{const h=i.find(g=>g.name===f);if(!h)return{ok:!1,reason:`The tile's source \`${f}\` is not declared.`};const m=`
|
|
107
107
|
source: ${h.name} is ${h.base} extend {
|
|
108
|
-
`+p.map(
|
|
108
|
+
`+p.map(g=>d(g," ")).join(`
|
|
109
109
|
|
|
110
110
|
`)+`
|
|
111
111
|
}
|
|
112
|
-
`;let y=
|
|
112
|
+
`;let y=c;if(y<0)for(let g=0;g<n.length;g++){const b=n[g].trim();(/^(import\s|given:|}\s*from\s)/.test(b)||/^[A-Z_]+\s*::/.test(b))&&(y=g)}const w=y>=0?r(y).end:t.length,v=w===t.length&&!t.endsWith(`
|
|
113
113
|
`)?`
|
|
114
|
-
`:"";a.push({start:w,end:w,text:
|
|
115
|
-
`}),b=!0;continue}const D=gs(T.text);if(D===void 0||!
|
|
116
|
-
`})}const _=
|
|
117
|
-
`).join("")})}if(_e(
|
|
114
|
+
`:"";a.push({start:w,end:w,text:v+m}),c=y}}function Jm(e){const{lines:t,starts:n,wholeLine:r,indentOf:s,current:i,next:o,edits:a,parsed:l}=e,u=new Map(i.tiles.map(d=>[nt(d),d]));for(const d of o.tiles){const c=u.get(nt(d));if(c===void 0||je(d)||je(c)||_e(Ns(c))===_e(Ns(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 f=Wm(l,d.source,d.name);if(f<0)return{ok:!1,reason:`Could not find where \`${d.name}\` is declared inside \`${d.source}\`.`};const{tags:p}=Fr(l,t,f),h=s(f),m=Lu(d,!1),y=new Map(m.map(T=>[gs(T)??T,T])),w=new Set,v=Ru(d.chart),g=Ol(c)!==Ol(d);if(g){const T=p.filter(R=>kr(R.text)),D=p.filter(R=>At(R.text)),N=c.chart==="custom"?p.filter(R=>At(R.text)||kr(R.text)):T.length>0?T:D.length>1?D:[];if(N.length>0)return{ok:!1,reason:`\`${d.source} -> ${d.name}\` has a chart line the builder does not model (${N.map(R=>R.text).join(" and ")}), so its chart cannot be changed here.`}}let b=!1;for(const T of p){if(g&&At(T.text)){v===void 0?a.push({...r(T.line),text:""}):T.text!==yn(v,d.chartCarried)&&a.push({...r(T.line),text:`${h}${yn(v,d.chartCarried)}
|
|
115
|
+
`}),b=!0;continue}const D=gs(T.text);if(D===void 0||!Fm.has(D))continue;const N=y.get(D);if(N===void 0){a.push({...r(T.line),text:""});continue}w.add(D),N!==T.text&&a.push({...r(T.line),text:`${h}${N}
|
|
116
|
+
`})}const _=m.filter(T=>!w.has(gs(T)??T));if(g&&v!==void 0&&!b&&_.push(yn(v,d.chartCarried)),_.length>0){const T=n[f];a.push({start:T,end:T,text:_.map(D=>`${h}${D}
|
|
117
|
+
`).join("")})}if(_e(c.filters)===_e(d.filters))continue;const O=Fu(e,d);if(!O)return{ok:!1,reason:`Could not find \`${d.name}\`'s declaration to filter it.`};if(O.body.kind==="reference"){const T=ov(e,d,O);if(T)return T;continue}if(O.body.kind!=="inline")return{ok:!1,reason:`\`${d.name}\`'s body is ${O.body.why}, so there is no single first stage to write its filter into.`};const I=zu(d.filters,O.body.stage);if(I)return Wu(d.name,I.given);const M=Bu(e,d,O.body.stage);if(M)return M}}const Ol=e=>e.chart==="default"?void 0:e.chart,Ns=e=>{const{chartLines:t,chartCarried:n,...r}=e;if(r.chart!=="default")return r;const{chart:s,...i}=r;return i};function ev(e,t){const n=new Map(e.tiles.map(r=>[nt(r),r]));return{...t,tiles:t.tiles.map(r=>{const s=n.get(nt(r));return xe(r)&&r.chart===void 0&&s&&xe(s)&&s.chart!==void 0?{...r,chart:s.chart}:r})}}function ms(e){if(e.includes("\r"))return"Text uses plain line breaks; a carriage return cannot be written.";if(/^\|##/m.test(e))return"A line starting with `|##` would close the text early. Indent that line or reword it."}function tv(e,t,n){if(n.has(e.name))return`Two text tiles are named \`${e.name}\`, so they could not be told apart.`;if(n.add(e.name),t===void 0&&!me.isIdentifier(e.name))return`The text tile name ${JSON.stringify(e.name)} must be a bare word.`;if(t===void 0||e.markdown!==t.markdown){const r=ms(e.markdown);if(r)return r}if(e.colspan!==void 0&&e.colspan!==t?.colspan&&!(Number.isInteger(e.colspan)&&e.colspan>=1))return"A text tile's width is a whole number of columns, 1 or more."}const xi=e=>`##|(markdown) ${e.name}
|
|
118
118
|
${e.markdown===""?"":`${e.markdown}
|
|
119
119
|
`}|##
|
|
120
|
-
`;function
|
|
120
|
+
`;function nv(e){const{sourceText:t,lines:n,wholeLine:r,current:s,next:i,parsed:o,edits:a}=e,l=new Map(s.tiles.filter(je).map(p=>[p.name,p])),u=i.tiles.filter(je),d=p=>o.textBlocks.find(h=>h.name===p),c=new Set(u.map(p=>p.name));for(const p of l.keys()){const h=c.has(p)?void 0:d(p);if(!h)continue;const m=_t(o,h.span.end-1);a.push({...h.span,text:""});const y=r(m+1),w=h.line===0||n[h.line-1].trim()==="";y.end>y.start&&n[m+1].trim()===""&&w?a.push({...y,text:""}):h.line>0&&w&&t.slice(h.span.end).trim()===""&&a.push({...r(h.line-1),text:""})}const f=[];for(const p of u){const h=l.get(p.name),m=d(p.name);if(h===void 0){if(m)return{ok:!1,reason:`A block named \`${p.name}\` is already in this file, so a new text tile cannot take that name.`};f.push(xi(p))}else h.markdown!==p.markdown&&(m?a.push({...m.span,text:xi(p)}):f.push(xi(p)))}if(f.length>0){const p=o.textBlocks.filter(v=>v.name===void 0||c.has(v.name)),h=p[p.length-1],m=o.sources.find(v=>v.name.endsWith("_tiles"));if(h){const v=h.span.end,g=t.slice(v);a.push({start:v,end:v,text:`
|
|
121
121
|
${f.join(`
|
|
122
|
-
`)}${
|
|
122
|
+
`)}${g===""||g.startsWith(`
|
|
123
123
|
`)?"":`
|
|
124
|
-
`}`});return}if(
|
|
124
|
+
`}`});return}if(m){const v=e.starts[o.blockStart(m.line)],g=v===0||t.slice(0,v).endsWith(`
|
|
125
125
|
|
|
126
|
-
`);a.push({start:
|
|
126
|
+
`);a.push({start:v,end:v,text:`${g?"":`
|
|
127
127
|
`}${f.join(`
|
|
128
128
|
`)}
|
|
129
129
|
`});return}const y=t.length,w=t===""||t.endsWith(`
|
|
@@ -133,58 +133,58 @@ ${f.join(`
|
|
|
133
133
|
`:`
|
|
134
134
|
|
|
135
135
|
`;a.push({start:y,end:y,text:w+f.join(`
|
|
136
|
-
`)})}}const Qr=(e,t=me.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function
|
|
137
|
-
`,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[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
|
|
138
|
-
${n.indent}${vs(f)}`).join("");s.push({start:u,end:u,text:
|
|
139
|
-
`)&&!/(?<!\r)\n/.test(e)))return
|
|
136
|
+
`)})}}const Qr=(e,t=me.isBareName)=>t(e)?void 0:`The name ${JSON.stringify(e)} cannot be written as a Malloy name.`;function rv(e,t){const n=new Map(e.tiles.map(o=>[nt(o),o]));if(Xe(t)==="notebook"&&t.columns!==void 0&&(Xe(e)!=="notebook"||t.columns!==e.columns))return"A notebook is one column, so its width is not written. Clear the width when switching a dashboard to a notebook.";const r=new Set;for(const o of t.tiles){const a=n.get(nt(o));if(je(o)){const c=tv(o,a&&je(a)?a:void 0,r);if(c)return c;continue}const l=a&&xe(a)?a:void 0;if(a&&!l)continue;const u=o.chart;if(u!==void 0&&u!=="default"&&u!=="none"&&!Qs(u)&&!(u==="custom"&&l?.chart==="custom"))return`"${String(u)}" is not a chart this editor writes.`;const d=new Set(l?.filters?.map(c=>c.field));for(const c of o.filters??[])if(!d.has(c.field)&&/[\r\n]/.test(c.field))return"A filter field is one line.";if(a===void 0){const c=[o.name,o.source];o.declaration.kind==="reference"&&c.push(o.declaration.from);for(const f of c){const p=Qr(f);if(p)return p}}for(const c of["label","subtitle"]){const f=o[c];if(f===void 0||f===l?.[c])continue;const p=E.annotationTextProblem(`tile ${c}`,f);if(p)return p}}const s=new Set(e.sources.map(o=>o.name));for(const o of t.sources)if(!s.has(o.name))for(const a of[o.name,o.base]){const l=Qr(a);if(l)return l}if(t.description!==e.description)for(const o of(t.description??"").split(/\r?\n/)){const a=E.annotationTextProblem("description line",o);if(a)return a}if(t.title!==e.title){const o=E.annotationTextProblem("title",t.title);if(o)return o}const i=new Map((e.localGivens??[]).map(o=>[o.name,o]));for(const o of t.localGivens??[]){const a=i.get(o.name);if(a===void 0){const u=Qr(o.name,me.isStrictName);if(u)return u}const l=o.suggest?.source;if(l!==void 0&&l!==a?.suggest?.source){const u=Qr(l);if(u)return`The suggest source is not a name. ${u}`}for(const u of["query","dimension"]){const d=o.suggest?.[u];if(d===void 0||d===a?.suggest?.[u])continue;const c=E.annotationTextProblem(`suggest ${u}`,d);if(c)return c}for(const u of["label","description"]){const d=o[u];if(d===void 0||d===i.get(o.name)?.[u])continue;const c=E.annotationTextProblem(`given ${u}`,d);if(c)return c}}for(const[o,a]of Object.entries(t.startingGivens??{})){if(a===e.startingGivens?.[o])continue;const l=E.annotationTextProblem(`starting value for ${o}`,a);if(l)return l}}const _t=(e,t)=>e.lineStarts.findLastIndex(n=>n<=t);function Fu(e,t){return e.parsed.sources.find(n=>n.name===t.source)?.views.find(n=>n.name===t.name)}function zu(e,t){if(!t)return;const n=new Set;for(const r of t.wheres)for(const s of r.clauses)if(!s.binding)for(const i of s.givens)n.add(i);return(e??[]).find(r=>n.has(r.given))}function Wu(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 vs=e=>`where: ${me.malloyPath(e.field)} ${e.op??"~"} $${e.given}`;function El(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 sv(e,t,n){const r=e.commentIn(n);if(r)return r;const s=e.trailingComment(_t(e,t.end-1));return s&&s.start>=t.end&&e.text.slice(t.end,s.start).trim()===""?s:void 0}function iv(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 Sa(e,t){const n=e.lineStarts[e.lineStarts.findLastIndex(a=>a<=t.start)],r=e.text.slice(n,t.start),s=e.text.indexOf(`
|
|
137
|
+
`,t.end),i=e.text.slice(t.end,s<0?void 0:s);if(r.trim()===""&&i.trim()==="")return{start:n,end:s<0?e.text.length:s+1};if(r.trim()===""){const a=/^\s*/.exec(i)?.[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 Bu(e,t,n){const{parsed:r,edits:s}=e,i=new Map((t.filters??[]).map(f=>[f.given,f])),o=new Set;let a;for(const f of n.wheres){const p=f.clauses.map((m,y)=>({clause:m,index:y})).filter(({clause:m})=>m.binding!==void 0);if(p.length===0)continue;const h=p.filter(({clause:m})=>i.has(m.binding.given));for(const{clause:m}of p)o.add(m.binding.given);if(h.length===0&&p.length===f.clauses.length){const m=Sa(r,f.span),y=sv(r,f.span,m);if(y)return El(t.name,r,y);s.push({...m,text:""});continue}h.length>0&&(a=f.span);for(let m=p.length-1;m>=0;m--){const{clause:y,index:w}=p[m],v=i.get(y.binding.given);if(!v){const b=iv(f.clauses,w),_=r.commentIn(b);if(_)return El(t.name,r,_);s.push({...b,text:""});continue}const g=vs(v).replace(/^where:\s*/,"");g!==r.text.slice(y.span.start,y.span.end)&&s.push({...y.span,text:g})}}const l=(t.filters??[]).filter(f=>!o.has(f.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 f=r.trailingComment(_t(r,u));f&&f.start>=u&&(u=f.end)}const d=a!==void 0&&!/,\s*$/.test(r.text.slice(0,u))?", ":" ",c=n.oneLine?`${d}${l.map(vs).join(", ")}`:l.map(f=>`
|
|
138
|
+
${n.indent}${vs(f)}`).join("");s.push({start:u,end:u,text:c})}function ov(e,t,n){if(n.body.kind!=="reference")return;const{edits:r}=e,{fromSpan:s,refinement:i}=n.body,o=zu(t.filters,i);if(o)return Wu(t.name,o.given);const a=t.filters??[];if(!i){if(a.length===0)return;const d=` + { ${a.map(vs).join(", ")} }`;r.push({start:s.end,end:s.end,text:d});return}const l=i.wheres.some(d=>d.clauses.some(c=>!c.binding)),u=i.statements.some(d=>!i.wheres.some(c=>c.span.start===d.span.start));if(a.length===0&&!l&&!u){const d={start:s.end,end:i.span.end},c=e.parsed.commentIn(d);if(c)return{ok:!1,reason:`Removing the last filter from \`${t.name}\` would also remove the comment beside its refinement (\`${e.parsed.text.slice(c.start,c.end).trim()}\`), so nothing was written. Delete it in the file first, or edit the refinement there.`};r.push({...d,text:""});return}return Bu(e,t,i)}async function Gu(e,t,n={}){if(!(e.includes(`\r
|
|
139
|
+
`)&&!/(?<!\r)\n/.test(e)))return Cl(e,t,n);const s=await Cl(e.replace(/\r\n/g,`
|
|
140
140
|
`),t,n);return Rs(s)?s:{...s,source:s.source.replace(/\n/g,`\r
|
|
141
|
-
`)}}async function
|
|
142
|
-
`),c=Rm(e),d=g=>({start:c[g],end:g+1<c.length?c[g+1]:e.length}),f=g=>/^\s*/.exec(u[g])?.[0]??"",p=[],h={...o,sourceText:e,parsed:l.parsed,lines:u,starts:c,wholeLine:d,indentOf:f,current:s,next:i,edits:p,...n.modelPath!==void 0?{modelPath:n.modelPath}:{},...n.explicitKind?{explicitKind:!0}:{}};for(const g of[Gm,Um,Hm,Vm,Xm,Ym,Zm,Qm,tv]){const m=g(h);if(m)return m}const v=g=>{const{drills:m,localGivens:b,kind:_,description:O,...E}=g,I=g.tiles.map(T=>{if(je(T))return T;if(T.filters?.length)return Ns(T);const{filters:D,...L}=T;return Ns(L)});return{...E,...O===void 0?{}:{description:Pu(O)},..._==="notebook"?{kind:_}:{},tiles:I,...m?.length?{drills:[...m].sort((T,D)=>Ls(T).localeCompare(Ls(D)))}:{},...b?.length?{localGivens:b}:{}}};if(p.length===0)return _e(v(s))!==_e(v(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const y=Lm(e,p);if((await vl(e)).length===0){const g=await vl(y);if(g.length>0)return{ok:!1,reason:`The edit would have produced a file Malloy cannot parse, so it was not written (${g[0]}). Your changes are still here.`}}const w=await Tr(y,n.modelPath);return $r(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:_e(v(w.document))!==_e(v(i))?{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:y}}function Bu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Ke.usePublisherTheme(),[i,o]=k.useState(!1),a=k.useMemo(()=>i?{text:e}:void 0,[i,e]),{draft:l,patch:u,close:c,discard:d}=Gl(a,i,m=>n(m.text),()=>o(!1)),f=i&&l!==void 0&&l.text!==e,p=l!==void 0&&l.text!==e?ms(l.text):void 0;uu(f,()=>p!==void 0?!1:(c(),!0));const h=k.useRef(null),v=k.useRef(!1);k.useEffect(()=>{i||(v.current=!1)},[i]);const y=k.useCallback(m=>{!m||v.current||(v.current=!0,m.setSelectionRange(m.value.length,m.value.length))},[]);if(!i||l===void 0){const m=e.trim()?ms(e):void 0;return x.jsxs($.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():o(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),o(!0)))},sx:[{minHeight:24},cu(s,"prose")],children:[e.trim()?x.jsx(C.Prose,{variant:r,children:e}):x.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),m&&x.jsx($.Typography,{variant:"caption",color:"error",role:"alert",children:m})]})}const w=l.text!==e?ms(l.text):void 0,g=()=>{w===void 0&&c()};return x.jsxs($.Stack,{spacing:1,children:[x.jsx($.TextField,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:y,inputProps:{"aria-label":"Markdown"},onChange:m=>u(b=>{b.text=m.target.value}),onKeyDown:m=>{m.key==="Escape"?g():m.key==="Enter"&&(m.metaKey||m.ctrlKey)&&(m.preventDefault(),g())},onBlur:m=>{m.relatedTarget instanceof Node&&h.current?.contains(m.relatedTarget)||c()}}),x.jsxs($.Stack,{ref:h,direction:"row",spacing:1,children:[x.jsx($.Button,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:g,children:"Done"}),x.jsx($.Button,{size:"small",onMouseDown:m=>m.preventDefault(),onClick:()=>{d(),o(!1)},children:"Cancel"})]})]})}const ov="Write markdown: # heading, **bold**, - list";function av({tile:e,onChange:t,chrome:n="card"}){return x.jsx(C.TileCard,{chrome:n,kind:"text",children:x.jsx(Bu,{markdown:e.markdown,placeholder:ov,onCommit:t})})}const Fs=e=>e.label??C.tileTitle(`${e.source} -> ${e.name}`);function lv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:l,resizing:u=!1,width:c,onResizeStart:d,onResizeMove:f,onResizeEnd:p,children:h}){const{theme:v}=Ke.usePublisherTheme();return x.jsx(cm,{id:Fe(e),index:t,children:({ref:y,handleRef:w})=>x.jsxs($.Box,{ref:y,onClick:a,onPointerDown:g=>{g.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Gu(v,{selected:n,flash:r,bare:i}),"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:v.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${v.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[h,x.jsx($.Box,{ref:w,"aria-label":`Move ${Wr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),x.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Wr(e)}`,onClick:g=>{g.stopPropagation(),l(g.currentTarget)},sx:{position:"absolute",top:`${-((i?C.BARE_RING_OFFSET_PX+1:0)+12)}px`,right:i?0:"12px",border:v.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:v.tileTitle,bgcolor:v.tile,opacity:n||s?.9:0,transition:`opacity ${C.MOTION_FAST}`,...C.reducedMotionSx,"&:hover":{opacity:1,bgcolor:v.tile}},children:x.jsx(fv,{})}),d&&x.jsx($.Box,{className:"builder-affordance",[$u]:"",role:"separator",tabIndex:c?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Wr(e)}`,...c?{"aria-valuenow":c.span,"aria-valuemin":1,"aria-valuemax":c.columns,"aria-valuetext":`${c.span} of ${c.columns} columns`}:{},onKeyDown:g=>{if(!c)return;const m=g.key==="ArrowRight"?c.span+1:g.key==="ArrowLeft"?c.span-1:g.key==="Home"?1:g.key==="End"?c.columns:void 0;m!==void 0&&(g.preventDefault(),g.stopPropagation(),c.onStep(Math.min(Math.max(m,1),c.columns)))},onPointerDown:d,onPointerMove:f,onPointerUp:p,onPointerCancel:p,onClick:g=>g.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:u||n?1:0,transition:`opacity ${C.MOTION_FAST}`,...C.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${v.accent}`,outlineOffset:1,borderRadius:"3px"},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:v.accent}}}),o&&x.jsx($.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Wr(e)}`,onClick:g=>{g.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(i?C.NOTEBOOK_GAP_PX:C.GRID_GAP_PX)/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:v.tileTitle,bgcolor:v.tile,border:v.cardBorder,opacity:0,transition:`opacity ${C.MOTION_FAST}`,...C.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:v.tile}},children:x.jsx(C.AddIcon,{sx:{fontSize:14}})})]})})}const wi=4,Gu=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const s=t||n?e.accent:"transparent",i=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${C.MOTION_FAST}, border-color ${C.MOTION_FAST}, opacity ${C.MOTION_FAST}, box-shadow ${C.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-C.BARE_RING_OFFSET_PX}px`,borderRadius:1,border:`2px solid ${s}`,pointerEvents:"none",transition:o,...C.reducedMotionSx},"&:hover::before":{borderColor:i}}:{borderRadius:1,outline:`2px solid ${s}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...C.reducedMotionSx,"&:hover":{outlineColor:i,boxShadow:e.shadow.lift}}};function cv({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Ke.usePublisherTheme();return x.jsxs(C.TileCard,{chrome:r,children:[x.jsx(C.TileHeading,{title:t?.title??Fs(e),subtitle:t?t.subtitle:e.subtitle}),n&&x.jsx($.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),x.jsxs($.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function dv({after:e}){const{theme:t}=Ke.usePublisherTheme();return x.jsx(dm,{id:hu(e),after:e,children:({ref:n,isDropTarget:r})=>x.jsx($.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${C.MOTION_FAST}, background-color ${C.MOTION_FAST}`,...C.reducedMotionSx}})})}function uv({columns:e}){const{theme:t}=Ke.usePublisherTheme();return x.jsx($.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${C.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>x.jsx($.Box,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function fv(){return x.jsxs($.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[x.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),x.jsx("circle",{cx:"12",cy:"12",r:"2"}),x.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function hv({editor:e,reorder:t,resizing:n,gridBox:r,columns:s,notebook:i,chrome:o,canAdd:a,selected:l,flash:u,menuIndex:c,onSelect:d,onOpenMenu:f,openAdd:p,editTile:h,renderTile:v}){const{dragging:y,preview:w,onDragStart:g,onDragOver:m,onDragEnd:b}=t,{resize:_,startResize:O,onResize:E,endResize:I}=n,T=_!==void 0?e.document.tiles.map((z,K)=>K===_.index?{...z,colspan:_.span}:z):w??e.document.tiles,D=e.document.tiles.length===0,L=y?Ig(T,s):T.map(fu),R=z=>pv(z,Fs(z),h);return x.jsxs(x.Fragment,{children:[x.jsx(ug,{sensors:am,onDragStart:g,onDragOver:m,onDragEnd:b,children:x.jsxs($.Box,{ref:r,sx:{position:"relative"},children:[!i&&(y||_!==void 0)&&x.jsx(uv,{columns:s}),x.jsx(C.DashboardGrid,{tiles:L,columns:s,rowGapPx:o==="none"?C.NOTEBOOK_GAP_PX:C.GRID_GAP_PX,keyOf:z=>z.kind==="gap"?hu(z.after):Fe(z.tile),renderTile:z=>{if(z.kind==="gap")return x.jsx(dv,{after:z.after});const{tile:K,index:G}=z;return x.jsx(lv,{tile:K,index:G,selected:G===l,flash:Fe(K)===u,menuOpen:c===G,bare:o==="none",...i&&a?{onInsertAfter:()=>p(G+1)}:{},...s>1&&gv(K)?{resizing:_?.index===G,width:{span:K.colspan??1,columns:s,onStep:X=>{X!==(K.colspan??1)&&e.update(Y=>{const se=Y.tiles[G];se&&(se.colspan=X)})}},onResizeStart:X=>O(X,G),onResizeMove:E,onResizeEnd:I}:{},onSelect:()=>d(G),onOpenMenu:X=>f(X,G),children:je(K)?x.jsx(av,{tile:K,chrome:o,onChange:X=>h(Fe(K),Y=>{je(Y)&&(Y.markdown=X)})}):v&&!e.pendingOpen?v(K,R(K),o):x.jsx(cv,{tile:K,chrome:o,heading:R(K),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),i&&a&&!D&&x.jsx($.Button,{size:"small",startIcon:x.jsx(C.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const pv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{xe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:x.jsx(fo,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:x.jsx(fo,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},gv=e=>je(e)||e.declaration.kind!=="inherited";function mv({editor:e,notebook:t,documentSlug:n,chrome:r,actions:s,descriptionSelected:i,selectDescription:o}){const{theme:a}=Ke.usePublisherTheme();return x.jsxs(x.Fragment,{children:[x.jsxs($.Stack,{direction:"row",sx:{alignItems:"center",gap:2},children:[x.jsx($.Typography,{variant:"h5",sx:{flex:1,minWidth:0},children:x.jsx(fo,{value:e.document.title,placeholder:n??(t?"Untitled notebook":"Untitled dashboard"),ariaLabel:t?"Notebook title":"Dashboard title",onCommit:l=>e.update(u=>{u.title=l})})}),x.jsx($.Box,{sx:{my:"-4px"},children:s})]}),x.jsx($.Box,{role:"group","aria-label":"Description","aria-current":i,onPointerDown:o,onFocus:o,sx:r==="none"?{my:`${C.BARE_DESCRIPTION_MARGIN_PX}px`}:void 0,children:x.jsx(C.TileCard,{chrome:r,kind:"text",sx:{position:"relative",overflow:"visible",...Gu(a,{selected:i,bare:r==="none"})},children:x.jsx(Bu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:l=>e.update(u=>{l.trim()===""?delete u.description:u.description=l})})})})]})}const vv=({size:e,notebook:t,savesTo:n,onEvent:r})=>({size:e,saved:({size:s,structural:i,durationMs:o,fromOpen:a})=>r?.(t?{type:"notebook.saved",cells:s,structural:i,converted:a,where:n,durationMs:o}:{type:"dashboard.saved",tiles:s,structural:i,where:n,durationMs:o}),refused:s=>r?.({type:t?"notebook.save_refused":"dashboard.save_refused",reason:s}),undone:({size:s,structural:i,durationMs:o})=>r?.(t?{type:"notebook.save_undone",cells:s,structural:i,where:n,durationMs:o}:{type:"dashboard.save_undone",tiles:s,structural:i,where:n,durationMs:o}),undoRefused:s=>r?.({type:t?"notebook.save_undo_refused":"dashboard.save_undo_refused",reason:s})}),bv=C.createSvgIcon(x.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"})),yv=C.createSvgIcon(x.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"})),bo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),_i=bo?"⌘":"Ctrl+",Cl=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},ki=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function xv(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=bo?i.metaKey:i.ctrlKey,l=i.key.toLowerCase();if(i.key==="Escape"){if(Cl(i.target)||ki(i.target))return;o.escape();return}if(Cl(i.target)){if(a&&l==="s"){if(i.preventDefault(),!o.save||ki(i.target))return;i.target.blur(),r(!0)}return}if(ki(i.target)){a&&l==="s"&&i.preventDefault();return}if(a&&l==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!bo&&a&&l==="y"){i.preventDefault(),o.redo();return}if(a&&l==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Il={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function wv({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:l,saveButton:u,actions:c,onAddTile:d,onExit:f}){return x.jsxs($.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[d&&x.jsx($.Button,{startIcon:x.jsx(C.AddIcon,{}),onClick:d,"aria-label":"Add tile",children:"Tile"}),d&&x.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),x.jsx($.Tooltip,{title:`Undo (${_i}Z)`,children:x.jsx("span",{children:x.jsx($.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:x.jsx(yv,{fontSize:"small"})})})}),x.jsx($.Tooltip,{title:`Redo (${_i}⇧Z)`,children:x.jsx("span",{children:x.jsx($.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:x.jsx(bv,{fontSize:"small"})})})}),(c||o||f)&&x.jsx($.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),c,o?x.jsx($.Tooltip,{title:s?`Save (${_i}S) · ${l??Il[a]}`:l??Il[a],children:x.jsx("span",{children:x.jsx($.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{minWidth:124},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&x.jsx($.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),f&&x.jsx(C.SecondaryButton,{label:"Close",icon:x.jsx(C.CheckIcon,{}),onClick:f})]})}const _v=C.createSvgIcon(x.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),kv=C.createSvgIcon(x.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function Sv({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:s,addDisabledReason:i,onRemove:o,children:a}){const{theme:l}=Ke.usePublisherTheme();return x.jsx(x.Fragment,{children:x.jsxs($.Stack,{sx:{gap:1,position:"sticky",top:0,zIndex:C.STICKY_CONTROLS_Z,bgcolor:"background.default",pb:1},children:[x.jsx($.Stack,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:x.jsxs($.Stack,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[x.jsx(kv,{sx:{fontSize:18,color:l.tileTitle,opacity:.7}}),x.jsx($.Typography,{variant:"subtitle2",sx:{color:l.tileTitle,mr:.5},children:"Filters"}),e.length===0&&x.jsx($.Typography,{variant:"body2",sx:{color:l.tileTitle,opacity:.8},children:"None yet."}),e.map(u=>{const c=n(u.name,u.type);return x.jsx($.Tooltip,{title:c.length>0?`$${u.name} · cannot filter on: ${c.join(", ")}`:`$${u.name} · ${u.origin==="dashboard"?"declared here":"from the model"} · ${u.boundTiles} of ${t} tiles`,children:x.jsx($.Chip,{size:"small",label:`${u.label??u.name}${u.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${u.name}`,color:c.length>0?"warning":"default",variant:u.origin==="dashboard"?"filled":"outlined",onClick:()=>r(u),onDelete:()=>o(u.name),deleteIcon:x.jsx(_v,{"aria-label":`Remove filter ${u.name}`}),sx:{opacity:u.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${C.MOTION_FAST}`,...C.reducedMotionSx}})},u.name)}),x.jsx($.Tooltip,{title:i??"",children:x.jsx("span",{children:x.jsx($.Chip,{component:"button",size:"small",variant:"outlined",icon:x.jsx(C.AddIcon,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:i!==void 0,onClick:()=>s(),sx:{cursor:"pointer",color:l.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),a]})})}function $v(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Tv({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(v=>r(y=>typeof y=="object"&&y.tile===v?y:{tile:v}),[]),a=k.useCallback(()=>r(v=>v==="description"?v:void 0),[]),l=k.useCallback(()=>r("description"),[]),u=k.useCallback(()=>r(void 0),[]),[c,d]=k.useState(void 0),f=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const v=p.current;if(p.current=e.document,!f.current)return;f.current=!1;const y=$v(v,e.document);if(y===void 0)return;d(y),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(g=>g.dataset.tileKey===y)?.scrollIntoView?.({block:"nearest",behavior:C.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(c===void 0)return;const v=setTimeout(()=>d(void 0),1500);return()=>clearTimeout(v)},[c]);const h=k.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:l,clearSelection:u,flash:c,stepEditor:h}}function Ov({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,l]=k.useState(!1),u=k.useRef(r);u.current=r;const c=k.useRef(s);c.current=s;const d=k.useRef(0),f=k.useCallback(async()=>{const h=++d.current;l(!1),o("saving");try{await u.current()}catch{d.current===h&&o("idle");return}d.current===h&&l(!0)},[]);return k.useEffect(()=>{if(i==="waiting"){if(t)return;e?f():(o("idle"),c.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||c.current()}},[i,a,t,e,f]),{requestExit:k.useCallback(()=>{i==="idle"&&(e?o("asking"):c.current())},[i,e]),dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),c.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):f())}}}}function Ev({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,report:o,unit:a,prepare:l,shortcuts:u}){const[c,d]=k.useState(!1),[f,p]=k.useState(!1),h=k.useRef(null),v=k.useRef(o);v.current=o;const y=e.dirty||i,w=(e.edited??e.dirty)||i;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(w)},[w,n]);const g=k.useRef(n);g.current=n,k.useEffect(()=>()=>g.current?.(!1),[]);const m=k.useRef(a);m.current=a,k.useEffect(()=>{p(!1)},[e.document]);const b=k.useCallback(()=>{d(!0),p(!1);const G=C.now(),{structural:X}=e,Y=e.pendingOpen??!1,se=v.current.size;return e.save().then(te=>{te.ok===!0?v.current.saved({size:se,structural:X,fromOpen:Y,durationMs:C.now()-G}):v.current.refused(te.reason)}).finally(()=>d(!1))},[e]),_=k.useRef(!1),O=k.useRef(!1);k.useEffect(()=>{!O.current||c||(O.current=!1,h.current?.focus())},[f,c]);const E=k.useCallback(()=>{if(!t||c||_.current||!e.canUndoSave)return;_.current=!0,d(!0);const G=C.now(),X=e.lastSave?.structural??!1,Y=v.current.size;return e.undoSave().then(se=>{se.ok===!0?(O.current=!0,p(!0),v.current.undone({size:Y,structural:X,fromOpen:!1,durationMs:C.now()-G})):v.current.undoRefused(se.reason)}).finally(()=>{_.current=!1,d(!1)})},[t,c,e]),I=k.useCallback(()=>{if(!(!t||!e.dirty||c))return b()},[t,e,c,b]),T=k.useRef(I);T.current=I;const D=k.useCallback(()=>{const G=()=>T.current();return l?l(G):G()},[l]),L=Ov({dirty:w,saving:c,canSave:!!t,save:D,onExit:()=>r?.()});xv(k.useMemo(()=>({...u,undo:e.undo,redo:e.redo,...t?{save:D}:{},paused:L.dialog.open}),[u,e,t,D,L.dialog.open]));const R=!!t&&!c&&e.canUndoSave,z=e.lastSave,K={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:y,saving:c,saveButton:h,...t?{onSave:D}:{},...r?{onExit:L.requestExit}:{}};return{saving:c,save:D,exitGuard:L,undoSave:E,canUndoSave:R,lastSave:z,toolbarProps:K}}function Jr(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Dl(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&Tu.includes(n))return n}}const Cv=1;function qu(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...qu(a,`${t}${i}.`,n-1))}}}return r}function Iv(e){const t=new Map;for(const n of Ku(e))t.set(n.name,qu(n.schema?.fields,"",Cv));return t}function Ku(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Dv=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&of.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Av(e){const t=new Map;for(const n of Ku(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Dv)&&r.add(s.name)}t.set(n.name,r)}return t}function Al(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const Uu=e=>(e??"").startsWith("dashboards/"),Pv=e=>e.modelPath??e.path??"";function Vu(e){const t=[],n=new Set;for(const r of e){const s=Pv(r);if(Uu(s))continue;const i=Iv(r),o=Av(r);for(const a of r.sources??[]){const l=a.name;if(!l||n.has(l))continue;n.add(l);const u=(a.givens??[]).map(c=>c.name).filter(c=>typeof c=="string");t.push({name:l,modelPath:s,...Jr(a.annotations)?{description:Jr(a.annotations)}:{},views:(a.views??[]).filter(c=>typeof c.name=="string").map(c=>({name:c.name,...Jr(c.annotations)?{description:Jr(c.annotations)}:{},...Dl(c.annotations)?{chart:Dl(c.annotations)}:{},...o.get(l)?.has(c.name)?{aggregateOnly:!0}:{}})),givens:u,fields:i.get(l)??[]})}}return{sources:t}}function Mv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const h=new Set((t.localGivens??[]).map(v=>v.name));return(n??[]).filter(v=>!h.has(v.name))},[t,n]),a=k.useMemo(()=>hf(e.document,o),[e.document,o]),l=k.useMemo(()=>new Map(e.document.sources.map(h=>[h.name,Al(r,h.base)])),[r,e.document.sources]),u=k.useCallback(h=>l.get(h.source)??Al(r,h.source),[l,r]),c=(h,v)=>{const y=[];for(const w of e.document.tiles){if(!xe(w))continue;const g=u(w);if(!g)continue;const m=new Map(g.map(b=>[b.name,b.type]));for(const b of w.filters??[])b.given===h&&(!m.has(b.field)||!rs(v,m.get(b.field)))&&y.push(`${b.field} on ${w.label??w.name} (${e.document.sources.find(_=>_.name===w.source)?.base??w.source})`)}return y},d=k.useMemo(()=>a.filter(h=>h.origin==="model"&&h.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:u,unknownFieldsOf:c,available:d,applyFilter:(h,v,y)=>{i(void 0),e.update(w=>{y&&xf(w,y),yf(w,h,v)})},dropControl:h=>{i(void 0),e.update(v=>wf(v,h))}}}function jv({pendingOpen:e,prepare:t}){const[n,r]=k.useState(void 0),s=k.useRef(e);s.current=e;const i=k.useCallback(o=>s.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:i}}function Rv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s,opensDirty:i=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,u]=k.useState(e.source),[c,d]=k.useState(void 0),[f,p]=k.useState(e.document),[h,v]=k.useState(i),[y,w]=k.useState(e.replaces),[g,m]=k.useState(!1),b=o.stack[o.index],_=k.useRef(o);_.current=o;const O=k.useRef(!1),[E,I]=k.useState(!1),T=j=>{O.current=j,I(j)},[D,L]=k.useState(void 0),R=k.useCallback(j=>{d(void 0),a(q=>{const J=structuredClone(q.stack[q.index]);if(j(J),JSON.stringify(J)===JSON.stringify(q.stack[q.index]))return q;const H=[...q.stack.slice(0,q.index+1),J].slice(-100);return{stack:H,index:H.length-1}})},[]),z=k.useCallback(()=>{d(void 0),a(j=>j.index>0?{...j,index:j.index-1}:j)},[]),K=k.useCallback(()=>{d(void 0),a(j=>j.index<j.stack.length-1?{...j,index:j.index+1}:j)},[]),G=k.useCallback(async(j,q)=>{try{return await t(j,q)}catch(J){return{ok:!1,reason:`Could not build the file: ${J instanceof Error?J.message:String(J)}`}}},[t]),X=k.useCallback(async()=>{if(O.current)return{ok:!1,reason:"A save is still being written."};const j={source:l,saved:f,history:_.current,pendingOpen:h,replacing:y,unwritten:g},q=s?.(f,b)??!1,J=r?.(f,b)??!1;T(!0);try{const ee=await G(l,b);if(Rs(ee))return d(ee.reason),{ok:!1,reason:ee.reason};try{await n?.(ee.source,{purpose:"save",document:b})}catch(S){const P=`Could not save: ${S instanceof Error?S.message:String(S)}`;return d(P),{ok:!1,reason:P}}u(ee.source),p(b),v(!1),w(void 0),m(!1);const H=q?{stack:[b],index:0}:j.history;return a(S=>S===j.history?H:q?{stack:[S.stack[S.index]],index:0}:S),L(n?{before:j,after:H,lastSave:{before:y??l,after:ee.source,structural:J,clearsHistory:q}}:void 0),d(void 0),{ok:!0}}finally{T(!1)}},[b,G,n,l,f,h,y,g,s,r]),Y=k.useCallback(async()=>{if(O.current)return{ok:!1,reason:"A save is still being written."};if(!n||D===void 0||D.after!==_.current)return{ok:!1,reason:"There is no save to undo."};const{before:j}=D;T(!0);try{await n(j.replacing??j.source,{purpose:"undo",document:j.saved})}catch(q){const J=`Could not undo the save: ${q instanceof Error?q.message:String(q)}`;return d(J),{ok:!1,reason:J}}finally{T(!1)}return u(j.source),p(j.saved),v(j.pendingOpen),w(j.replacing),m(j.unwritten||j.replacing!==void 0),a(q=>q===D.after?j.history:q),L(void 0),d(void 0),{ok:!0}},[n,D]),se=k.useMemo(()=>g||JSON.stringify(b)!==JSON.stringify(f),[b,f,g]),te=k.useMemo(()=>r?.(f,b)??!1,[b,f,r]),A=k.useMemo(()=>s?.(f,b)??!1,[b,f,s]),B=D!==void 0&&D.after===o,N=k.useCallback(async()=>{const j=await G(l,b);return Rs(j)?{ok:!1,reason:j.reason}:{ok:!0,source:j.source}},[b,G,l]);return{document:b,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:se||h,edited:se,pendingOpen:h,...c===void 0?{}:{error:c},update:R,undo:z,redo:K,save:X,preview:N,structural:te,clearsHistory:A,canUndoSave:B&&!E&&n!==void 0,...B?{lastSave:D.lastSave}:{},undoSave:Y}}const Lv=(e,t)=>{const n=new Set(e.tiles.map(vo)),r=new Set(t.tiles.map(vo));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Nv(e){const{conversion:t,modelPath:n,explicitKind:r,...s}=e,i=t?.from,o=t?.to,a=k.useCallback((l,u)=>Wu(i!==void 0&&l===i?o:l,u,{changeKind:!0,...n!==void 0?{modelPath:n}:{},...r?{explicitKind:r}:{}}),[i,o,n,r]);return Rv({...s,splice:a,structural:Lv,opensDirty:t!==void 0})}function Fv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}const Hu="dashboards/document.malloy",Xu=e=>e.slice(0,e.lastIndexOf("/")+1),Yu=(e,t)=>new URL(e,`https://malloy.invalid/${Xu(t)}`).pathname.slice(1);function zv(e,t){const n=Xu(t).split("/").filter(Boolean),r=e.split("/");let s=0;for(;s<n.length&&s<r.length-1&&n[s]===r[s];)s++;const i=n.length-s;return`${i===0?"./":"../".repeat(i)}${r.slice(s).join("/")}`}function Wv(e,t,n,r=Hu){return e.sources.some(s=>s.base===t)?!0:e.imports.some(s=>s.kind==="names"?s.names.includes(t):Yu(s.from,r)===n)}function Bv(e,t,n,r=Hu){const{imports:s}=e;if(Wv(e,t,n,r))return s;const i=s.findIndex(o=>o.kind==="names"&&Yu(o.from,r)===n);return i<0?[...s,{kind:"names",names:[t],from:zv(n,r)}]:s.map((o,a)=>a===i&&o.kind==="names"?{...o,names:[...o.names,t]}:o)}function Gv({editor:e,notebook:t,columns:n,modelPath:r,selectTile:s,deselectTile:i}){const[o,a]=k.useState(void 0),[l,u]=k.useState(!1),[c,d]=k.useState(void 0);return{menu:o,setMenu:a,addingTile:l,openAdd:g=>{d(g),u(!0)},closeAdd:()=>u(!1),addTile:g=>{u(!1),e.update(m=>{g.modelPath&&(m.imports=Bv(m,g.base,g.modelPath,...r?[r]:[]));let b=m.sources.find(E=>E.base===g.base);if(!b){const E=new Set(m.sources.map(T=>T.name));let I=`${g.base}_tiles`;for(let T=2;E.has(I);T++)I=`${g.base}_tiles_${T}`;b={name:I,base:g.base},m.sources.push(b)}const _=new Set(m.tiles.filter(xe).filter(E=>E.source===b.name).map(E=>E.name));let O=`${g.view}_tile`;for(let E=2;_.has(O);E++)O=`${g.view}_tile_${E}`;m.tiles.splice(c??m.tiles.length,0,{name:O,source:b.name,declaration:{kind:"reference",from:g.view},...t?{}:{colspan:g.colspan},...g.label?{label:g.label}:{},...g.chart?{chart:g.chart}:{},...g.chartCarried?{chartCarried:g.chartCarried}:{}})}),s(c??e.document.tiles.length)},addText:()=>{u(!1),e.update(g=>{const m=new Set(g.tiles.filter(je).map(_=>_.name));let b=1;for(;m.has(`text_${b}`);)b++;g.tiles.splice(c??g.tiles.length,0,{kind:"text",name:`text_${b}`,markdown:"",...t?{}:{colspan:n}})}),s(c??e.document.tiles.length)},editTile:(g,m)=>e.update(b=>{const _=b.tiles.find(O=>Fe(O)===g);_&&m(_)}),removeTile:g=>{a(void 0),i(),e.update(m=>{m.tiles.splice(g,1)})}}}var qv=Object.defineProperty,Kv=Object.defineProperties,Uv=Object.getOwnPropertyDescriptors,Pl=Object.getOwnPropertySymbols,Vv=Object.prototype.hasOwnProperty,Hv=Object.prototype.propertyIsEnumerable,Ml=(e,t,n)=>t in e?qv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Vv.call(t,n)&&Ml(e,n,t[n]);if(Pl)for(var n of Pl(t))Hv.call(t,n)&&Ml(e,n,t[n]);return e},on=(e,t)=>Kv(e,Uv(t));function Xv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function es(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Si(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Yv(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(m,b)=>m===b||m!==null&&typeof m=="object"&&"id"in m&&m.id===b;if(Array.isArray(e)){const m=e.findIndex(_=>l(_,i.id)),b=e.findIndex(_=>l(_,o.id));if(m===-1||b===-1){if(Si(i)){const _=i.initialIndex,O=i.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==m)return n(e,m,_)}return n(e,m,b)}const u=Object.entries(e);let c=-1,d,f=-1,p;for(const[m,b]of u)if(c===-1&&(c=b.findIndex(_=>l(_,i.id)),c!==-1&&(d=m)),f===-1&&(f=b.findIndex(_=>l(_,o.id)),f!==-1&&(p=m)),c!==-1&&f!==-1)break;if(c===-1&&Si(i)){const m=i.initialGroup==null?void 0:es(e,i.initialGroup),b=i.initialIndex,_=i.group==null?void 0:es(e,i.group),O=i.index;if(m==null||_==null||m===_&&b===O)return"preventDefault"in t&&t.preventDefault(),e;if(m===_)return on(sn({},e),{[m]:n(e[m],b,O)});const E=e[m][b];return on(sn({},e),{[m]:[...e[m].slice(0,b),...e[m].slice(b+1)],[_]:[...e[_].slice(0,O),E,...e[_].slice(O)]})}if(!i.manager)return e;const{dragOperation:h}=i.manager,v=(s=(r=h.shape)==null?void 0:r.current.center)!=null?s:h.position.current;if(p==null){const m=es(e,o.id);if(m!=null){const b=o.shape&&v.y>o.shape.center.y?e[m].length:0;p=m,f=b}}if(d==null||p==null||d===p&&c===f){if(d!=null&&d===p&&c===f&&Si(i)){const m=i.group==null?void 0:es(e,i.group),b=i.group!=null&&m!==d,_=i.index!==c;if(b||_){const O=i.group==null?d:m;if(O!=null){if(d===O)return on(sn({},e),{[d]:n(e[d],c,i.index)});const E=e[d][c];return on(sn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[O]:[...e[O].slice(0,i.index),E,...e[O].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(d===p)return on(sn({},e),{[d]:n(e[d],c,f)});const w=o.shape&&Math.round(v.y)>Math.round(o.shape.center.y)?1:0,g=e[d][c];return on(sn({},e),{[d]:[...e[d].slice(0,c),...e[d].slice(c+1)],[p]:[...e[p].slice(0,f+w),g,...e[p].slice(f+w)]})}function Zv(e,t){return Yv(e,t,Xv)}function Qv({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:d=>{const{source:f,target:p}=d.operation;if(!f||!p)return;const h=i.current??e;let v;if(p.type===Su){const{after:y}=p.data,w=h.findIndex(b=>Fe(b)===f.id);if(w<0||y===f.id)return;const m=h.filter((b,_)=>_!==w).findIndex(b=>Fe(b)===y)+1;v=Cg(h,w,m)}else{const y=h.map(Fe),w=Zv(y,d);if(w.every((m,b)=>m===y[b]))return;const g=new Map(h.map(m=>[Fe(m),m]));v=Eg(w.map(m=>g.get(m)),e.map(m=>m.break??!1))}i.current=v,s(v)},onDragEnd:d=>{a(!1);const f=i.current;if(i.current=void 0,s(void 0),d.canceled||!f)return;t(f);const p=f.findIndex(h=>Fe(h)===d.operation.source?.id);p>=0&&n(p)}}}const $i=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function Jv({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),l=f=>{a.current=f,o(f)};return k.useEffect(()=>()=>$i(!1),[]),{resize:i,startResize:(f,p)=>{const h=n.current?.getBoundingClientRect(),v=f.currentTarget.parentElement?.getBoundingClientRect();if(!h||!v)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),$i(!0),r(p);const y=e[p]?.colspan??1;l({index:p,span:y,from:y,left:v.left,track:(h.width-C.GRID_GAP_PX*(t-1))/t})},onResize:f=>{const p=a.current;if(!p)return;const h=f.clientX-p.left,v=Math.round((h+C.GRID_GAP_PX)/(p.track+C.GRID_GAP_PX)),y=Math.min(Math.max(v,1),t);y!==p.span&&l({...p,span:y})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),$i(!1);const p=a.current;if(!p)return;const{index:h,span:v,from:y}=p;l(void 0),!(f.type==="pointercancel"||v===y)&&s(h,v)}}}function Zu({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,controls:a,givens:l,catalog:u,toolbar:c,dashboards:d,onEvent:f,conversion:p,savesTo:h="package",saveLabel:v,replaces:y,modelPath:w,explicitKind:g,addFilterDisabledReason:m}){const b=Nv({source:e,document:t,...n?{onSave:n}:{},...p?{conversion:p}:{},...y!==void 0?{replaces:y}:{},...w!==void 0?{modelPath:w}:{},...g?{explicitKind:g}:{}}),_=k.useRef(null),{selected:O,descriptionSelected:E,selectTile:I,deselectTile:T,selectDescription:D,clearSelection:L,flash:R,stepEditor:z}=Tv({editor:b,gridBox:_}),K=b.document.kind==="notebook",G=K?1:b.document.columns??C.DEFAULT_COLUMNS,X=K?"none":"card",Y=w?.split("/").at(-1)?.replace(/\.malloy$/,""),se=Qv({tiles:b.document.tiles,commit:ce=>b.update(pe=>{pe.tiles=ce}),onLanded:I}),{dragging:te}=se,A=Jv({tiles:b.document.tiles,columns:G,gridBox:_,onStart:I,commit:(ce,pe)=>b.update(M=>{const U=M.tiles[ce];U&&(U.colspan=pe)})}),B=Gv({editor:b,notebook:K,columns:G,modelPath:w,selectTile:I,deselectTile:T}),{menu:N,addingTile:j,openAdd:q}=B,J=Mv({editor:b,opened:t,givens:l,catalog:u}),{filterDialog:ee,setFilterDialog:H}=J,[S,P]=k.useState(void 0),{draftDirty:F,openDraft:V,prepare:ie}=Fv({editorDirty:b.dirty}),{confirmConversion:Z,prepareSave:oe}=jv({pendingOpen:b.pendingOpen,prepare:ie}),W=k.useMemo(()=>({escape:()=>{!N&&!ee&&!j&&S===void 0&&Z===void 0&&L()},nudge:ce=>{if(te||O===void 0||K)return;const pe=b.document.tiles[O];if(!pe||xe(pe)&&pe.declaration.kind==="inherited")return;const M=C.nudgedSpan(pe.colspan??1,ce,G);M!==(pe.colspan??1)&&b.update(U=>{U.tiles[O].colspan=M})}}),[b,N,ee,j,S,Z,L,O,G,K,te]),Q=Ev({editor:z,extraDirty:F,prepare:oe,unit:{name:"tile",count:ce=>ce.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:W,report:vv({size:b.document.tiles.length,notebook:K,savesTo:h,onEvent:f})}),ne=b.document.tiles.length===0,re=x.jsx(wv,{...Q.toolbarProps,...c?{actions:c}:{},...u?{onAddTile:()=>q()}:{},savesTo:h,...v?{saveLabel:v}:{}});return x.jsx(du.Provider,{value:V,children:x.jsx($.Stack,{sx:{gap:0,mx:`-${wi}px`},children:x.jsxs($.Stack,{sx:{gap:2,px:`${wi}px`,pb:`${wi}px`},children:[b.pendingOpen&&x.jsx($.Alert,{severity:"info",children:"This notebook is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view."}),x.jsx(mv,{editor:b,notebook:K,documentSlug:Y,chrome:X,actions:re,descriptionSelected:E,selectDescription:D}),ne?x.jsx(x.Fragment,{children:x.jsxs($.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[x.jsxs($.Typography,{variant:"body2",children:["This ",K?"notebook":"dashboard"," is not served until it has a tile."]}),u&&x.jsx($.Button,{size:"small",startIcon:x.jsx(C.AddIcon,{}),onClick:()=>q(),children:"Add tile"})]})}):x.jsx(Sv,{controls:J.controlList,tileCount:b.document.tiles.length,unknownFieldsOf:J.unknownFieldsOf,onEdit:ce=>H({control:ce}),onAdd:()=>H({}),...m?{addDisabledReason:m}:{},onRemove:J.dropControl,children:a}),b.error&&x.jsx($.Alert,{severity:"warning",children:b.error}),x.jsx(hv,{editor:b,reorder:se,resizing:A,gridBox:_,columns:G,notebook:K,chrome:X,canAdd:!!u,selected:O,flash:R,menuIndex:N?.index,onSelect:I,onOpenMenu:(ce,pe)=>{I(pe),B.setMenu({anchor:ce,index:pe})},openAdd:q,editTile:B.editTile,...o?{renderTile:o}:{}}),x.jsx(Ef,{editor:b,catalog:u,columns:G,dashboards:d,bindings:J,tiles:B,drillSource:S,setDrillSource:P,confirmConversion:Z,exitDialog:Q.exitGuard.dialog})]})})})}function eb(e,t){const n=new Set;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.add(o.given);const r=[],s=new Set;for(const i of e.localGivens??[])n.has(i.name)&&(s.add(i.name),r.push(tb(i)));for(const i of t)i.name===void 0||s.has(i.name)||!n.has(i.name)||(s.add(i.name),r.push(i));return r}function tb(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 nb(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function ts(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function rb(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(v=>[v.name,v.type])),l=e.sources.find(v=>v.name===i)?.scopedBy??[],u=new Set([...l,...s??[]].filter(v=>n.has(v))),c=new Set([...l,...s??[]]),d=[];for(const v of t.filters??[]){const y=`where: ${me.malloyPath(v.field)} ${v.op??"~"}`;if(n.has(v.given)){u.add(v.given),c.add(v.given),d.push(`${y} $${v.given}`);continue}if(!a.has(v.given))continue;c.add(v.given);const w=C.malloyLiteral(r.get(v.given),a.get(v.given));w!==void 0&&d.push(`${y} ${w}`)}const f=d.join(", "),p=t.chart,h=p==="none"||Qs(p)?yn(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
-
`):p==="default"&&
|
|
144
|
-
`);async function
|
|
145
|
-
`).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,s;try{r=await Js(e,
|
|
146
|
-
`,...B].join("")).replace(/\n$/,"")},y=new
|
|
147
|
-
`||e[q-1]==="\r");)q--;return{startCp:B,stopCp:
|
|
148
|
-
${V}`:
|
|
141
|
+
`)}}async function Cl(e,t,n){const r=await Tr(e,n.modelPath);if($r(r))return{ok:!1,reason:`Cannot edit a file that will not open: ${r.reason}`};const s=r.document,i=ev(s,t),o=Bm(s,i,n.changeKind===!0,n.visibleSources);if("reason"in o)return o;const a=rv(s,i);if(a)return{ok:!1,reason:a};const l=await Au(e);if(Iu(l))return{ok:!1,reason:`Cannot edit a file that will not open: ${l.reason}`};const u=e.split(`
|
|
142
|
+
`),d=Lm(e),c=v=>({start:d[v],end:v+1<d.length?d[v+1]:e.length}),f=v=>/^\s*/.exec(u[v])?.[0]??"",p=[],h={...o,sourceText:e,parsed:l.parsed,lines:u,starts:d,wholeLine:c,indentOf:f,current:s,next:i,edits:p,...n.modelPath!==void 0?{modelPath:n.modelPath}:{},...n.explicitKind?{explicitKind:!0}:{}};for(const v of[qm,Vm,Xm,Hm,Ym,Zm,Qm,Jm,nv]){const g=v(h);if(g)return g}const m=v=>{const{drills:g,localGivens:b,kind:_,description:O,...I}=v,M=v.tiles.map(T=>{if(je(T))return T;if(T.filters?.length)return Ns(T);const{filters:D,...N}=T;return Ns(N)});return{...I,...O===void 0?{}:{description:ju(O)},..._==="notebook"?{kind:_}:{},tiles:M,...g?.length?{drills:[...g].sort((T,D)=>Ls(T).localeCompare(Ls(D)))}:{},...b?.length?{localGivens:b}:{}}};if(p.length===0)return _e(m(s))!==_e(m(i))?{ok:!1,reason:"No part of this edit was recognized, so nothing was written. Your changes are still here."}:{ok:!0,source:e};const y=Nm(e,p);if((await bl(e)).length===0){const v=await bl(y);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 w=await Tr(y,n.modelPath);return $r(w)?{ok:!1,reason:`The edit produced a file that cannot be read back: ${w.reason}`}:_e(m(w.document))!==_e(m(i))?{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:y}}function qu({markdown:e,placeholder:t,onCommit:n,variant:r="document"}){const{theme:s}=Ke.usePublisherTheme(),[i,o]=k.useState(!1),a=k.useMemo(()=>i?{text:e}:void 0,[i,e]),{draft:l,patch:u,close:d,discard:c}=Kl(a,i,g=>n(g.text),()=>o(!1)),f=i&&l!==void 0&&l.text!==e,p=l!==void 0&&l.text!==e?ms(l.text):void 0;hu(f,()=>p!==void 0?!1:(d(),!0));const h=k.useRef(null),m=k.useRef(!1);k.useEffect(()=>{i||(m.current=!1)},[i]);const y=k.useCallback(g=>{!g||m.current||(m.current=!0,g.setSelectionRange(g.value.length,g.value.length))},[]);if(!i||l===void 0){const g=e.trim()?ms(e):void 0;return x.jsxs(S.Box,{role:"button",tabIndex:0,onClick:b=>{b.target.closest("a")?b.preventDefault():o(!0)},onKeyDown:b=>{b.target===b.currentTarget&&(b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),o(!0)))},sx:[{minHeight:24},uu(s,"prose")],children:[e.trim()?x.jsx(E.Prose,{variant:r,children:e}):x.jsx(S.Typography,{variant:"body2",sx:{color:s.tileTitle,opacity:.6,fontStyle:"italic"},children:t}),g&&x.jsx(S.Typography,{variant:"caption",color:"error",role:"alert",children:g})]})}const w=l.text!==e?ms(l.text):void 0,v=()=>{w===void 0&&d()};return x.jsxs(S.Stack,{spacing:1,children:[x.jsx(S.TextField,{multiline:!0,autoFocus:!0,minRows:3,maxRows:14,fullWidth:!0,value:l.text,placeholder:t,error:w!==void 0,helperText:w,inputRef:y,inputProps:{"aria-label":"Markdown"},onChange:g=>u(b=>{b.text=g.target.value}),onKeyDown:g=>{g.key==="Escape"?v():g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&(g.preventDefault(),v())},onBlur:g=>{g.relatedTarget instanceof Node&&h.current?.contains(g.relatedTarget)||d()}}),x.jsxs(S.Stack,{ref:h,direction:"row",spacing:1,children:[x.jsx(S.Button,{size:"small",variant:"outlined",disabled:w!==void 0,onClick:v,children:"Done"}),x.jsx(S.Button,{size:"small",onMouseDown:g=>g.preventDefault(),onClick:()=>{c(),o(!1)},children:"Cancel"})]})]})}const av="Write markdown: # heading, **bold**, - list";function lv({tile:e,onChange:t,chrome:n="card"}){return x.jsx(E.TileCard,{chrome:n,kind:"text",children:x.jsx(qu,{markdown:e.markdown,placeholder:av,onCommit:t})})}const Fs=e=>e.label??E.tileTitle(`${e.source} -> ${e.name}`);function cv({tile:e,index:t,selected:n,flash:r=!1,menuOpen:s,bare:i=!1,onInsertAfter:o,onSelect:a,onOpenMenu:l,resizing:u=!1,width:d,onResizeStart:c,onResizeMove:f,onResizeEnd:p,children:h}){const{theme:m}=Ke.usePublisherTheme();return x.jsx(dm,{id:Fe(e),index:t,children:({ref:y,handleRef:w})=>x.jsxs(S.Box,{ref:y,onClick:a,onPointerDown:v=>{v.button===0&&a()},role:"group","aria-label":`Tile ${e.name}`,"aria-current":n,onFocus:a,"data-tile-key":Fe(e),"data-flash":r||void 0,sx:{position:"relative",display:"grid",minWidth:0,cursor:"grab",...Ku(m,{selected:n,flash:r,bare:i}),"&&[data-dnd-dragging]":{opacity:1,outline:"none",boxShadow:m.shadow.drag},"&&[data-dnd-placeholder]":{opacity:.45,outline:`2px dashed ${m.accent}`,boxShadow:"none"},"&:hover .builder-affordance, &:focus-within .builder-affordance":{opacity:1},"@media (hover: none)":{"& .builder-affordance":{opacity:1}}},children:[h,x.jsx(S.Box,{ref:w,"aria-label":`Move ${Wr(e)}`,sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"}}),x.jsx(S.IconButton,{className:"builder-affordance",size:"small","aria-label":`Settings for ${Wr(e)}`,onClick:v=>{v.stopPropagation(),l(v.currentTarget)},sx:{position:"absolute",top:`${-((i?E.BARE_RING_OFFSET_PX+1:0)+12)}px`,right:i?0:"12px",border:m.cardBorder,borderRadius:1,width:28,height:24,zIndex:2,color:m.tileTitle,bgcolor:m.tile,opacity:n||s?.9:0,transition:`opacity ${E.MOTION_FAST}`,...E.reducedMotionSx,"&:hover":{opacity:1,bgcolor:m.tile}},children:x.jsx(hv,{})}),c&&x.jsx(S.Box,{className:"builder-affordance",[Ou]:"",role:"separator",tabIndex:d?0:-1,"aria-orientation":"vertical","aria-label":`Width of ${Wr(e)}`,...d?{"aria-valuenow":d.span,"aria-valuemin":1,"aria-valuemax":d.columns,"aria-valuetext":`${d.span} of ${d.columns} columns`}:{},onKeyDown:v=>{if(!d)return;const g=v.key==="ArrowRight"?d.span+1:v.key==="ArrowLeft"?d.span-1:v.key==="Home"?1:v.key==="End"?d.columns:void 0;g!==void 0&&(v.preventDefault(),v.stopPropagation(),d.onStep(Math.min(Math.max(g,1),d.columns)))},onPointerDown:c,onPointerMove:f,onPointerUp:p,onPointerCancel:p,onClick:v=>v.stopPropagation(),sx:{position:"absolute",top:0,bottom:0,right:"-5px",width:"10px",cursor:"col-resize",touchAction:"none",zIndex:2,opacity:u||n?1:0,transition:`opacity ${E.MOTION_FAST}`,...E.reducedMotionSx,"&:hover":{opacity:1},"&:focus-visible":{opacity:1,outline:`2px solid ${m.accent}`,outlineOffset:1,borderRadius:"3px"},"&::after":{content:'""',position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"4px",height:"28px",borderRadius:"2px",bgcolor:m.accent}}}),o&&x.jsx(S.IconButton,{className:"builder-affordance",size:"small","aria-label":`Insert tile after ${Wr(e)}`,onClick:v=>{v.stopPropagation(),o()},sx:{position:"absolute",bottom:`-${(i?E.NOTEBOOK_GAP_PX:E.GRID_GAP_PX)/2+12}px`,left:"50%",transform:"translateX(-50%)",width:24,height:24,zIndex:3,color:m.tileTitle,bgcolor:m.tile,border:m.cardBorder,opacity:0,transition:`opacity ${E.MOTION_FAST}`,...E.reducedMotionSx,"&:hover, &:focus-visible":{opacity:1,bgcolor:m.tile}},children:x.jsx(E.AddIcon,{sx:{fontSize:14}})})]})})}const wi=4,Ku=(e,{selected:t,flash:n=!1,bare:r=!1})=>{const s=t||n?e.accent:"transparent",i=t?e.accent:e.cardBorder.replace(/^1px solid /,""),o=`outline-color ${E.MOTION_FAST}, border-color ${E.MOTION_FAST}, opacity ${E.MOTION_FAST}, box-shadow ${E.MOTION_FAST}`;return r?{borderRadius:1,"&::before":{content:'""',position:"absolute",inset:`${-E.BARE_RING_OFFSET_PX}px`,borderRadius:1,border:`2px solid ${s}`,pointerEvents:"none",transition:o,...E.reducedMotionSx},"&:hover::before":{borderColor:i}}:{borderRadius:1,outline:`2px solid ${s}`,outlineOffset:2,...n&&{boxShadow:`0 0 0 6px color-mix(in srgb, ${e.accent} 25%, transparent)`},transition:o,...E.reducedMotionSx,"&:hover":{outlineColor:i,boxShadow:e.shadow.lift}}};function dv({tile:e,heading:t,note:n,chrome:r="card"}){const{theme:s}=Ke.usePublisherTheme();return x.jsxs(E.TileCard,{chrome:r,children:[x.jsx(E.TileHeading,{title:t?.title??Fs(e),subtitle:t?t.subtitle:e.subtitle}),n&&x.jsx(S.Typography,{variant:"body2",sx:{color:s.tileTitle,py:2},children:n}),x.jsxs(S.Typography,{variant:"caption",sx:{display:"block",color:s.tileTitle,opacity:.7},children:[e.source," → ",e.name]})]})}function uv({after:e}){const{theme:t}=Ke.usePublisherTheme();return x.jsx(um,{id:gu(e),after:e,children:({ref:n,isDropTarget:r})=>x.jsx(S.Box,{ref:n,"aria-hidden":!0,sx:{minHeight:48,borderRadius:1,border:`1px dashed ${t.accent}`,bgcolor:r?`color-mix(in srgb, ${t.accent} 12%, transparent)`:"transparent",opacity:r?.95:.4,transition:`opacity ${E.MOTION_FAST}, background-color ${E.MOTION_FAST}`,...E.reducedMotionSx}})})}function fv({columns:e}){const{theme:t}=Ke.usePublisherTheme();return x.jsx(S.Box,{"aria-hidden":!0,sx:{position:"absolute",inset:0,pointerEvents:"none",zIndex:3,display:"grid",gridTemplateColumns:`repeat(${e}, minmax(0, 1fr))`,gap:`${E.GRID_GAP_PX}px`},children:Array.from({length:e},(n,r)=>x.jsx(S.Box,{sx:{borderLeft:`1px dashed ${t.accent}`,borderRight:r===e-1?`1px dashed ${t.accent}`:"none",opacity:.35}},r))})}function hv(){return x.jsxs(S.SvgIcon,{sx:{fontSize:18},viewBox:"0 0 24 24",children:[x.jsx("circle",{cx:"3.5",cy:"12",r:"2"}),x.jsx("circle",{cx:"12",cy:"12",r:"2"}),x.jsx("circle",{cx:"20.5",cy:"12",r:"2"})]})}function pv({editor:e,reorder:t,resizing:n,gridBox:r,columns:s,notebook:i,chrome:o,canAdd:a,selected:l,flash:u,menuIndex:d,onSelect:c,onOpenMenu:f,openAdd:p,editTile:h,renderTile:m}){const{dragging:y,preview:w,onDragStart:v,onDragOver:g,onDragEnd:b}=t,{resize:_,startResize:O,onResize:I,endResize:M}=n,T=_!==void 0?e.document.tiles.map((W,X)=>X===_.index?{...W,colspan:_.span}:W):w??e.document.tiles,D=e.document.tiles.length===0,N=y?Dg(T,s):T.map(pu),R=W=>gv(W,Fs(W),h);return x.jsxs(x.Fragment,{children:[x.jsx(fg,{sensors:lm,onDragStart:v,onDragOver:g,onDragEnd:b,children:x.jsxs(S.Box,{ref:r,sx:{position:"relative"},children:[!i&&(y||_!==void 0)&&x.jsx(fv,{columns:s}),x.jsx(E.DashboardGrid,{tiles:N,columns:s,rowGapPx:o==="none"?E.NOTEBOOK_GAP_PX:E.GRID_GAP_PX,keyOf:W=>W.kind==="gap"?gu(W.after):Fe(W.tile),renderTile:W=>{if(W.kind==="gap")return x.jsx(uv,{after:W.after});const{tile:X,index:G}=W;return x.jsx(cv,{tile:X,index:G,selected:G===l,flash:Fe(X)===u,menuOpen:d===G,bare:o==="none",...i&&a?{onInsertAfter:()=>p(G+1)}:{},...s>1&&mv(X)?{resizing:_?.index===G,width:{span:X.colspan??1,columns:s,onStep:U=>{U!==(X.colspan??1)&&e.update(Y=>{const re=Y.tiles[G];re&&(re.colspan=U)})}},onResizeStart:U=>O(U,G),onResizeMove:I,onResizeEnd:M}:{},onSelect:()=>c(G),onOpenMenu:U=>f(U,G),children:je(X)?x.jsx(lv,{tile:X,chrome:o,onChange:U=>h(Fe(X),Y=>{je(Y)&&(Y.markdown=U)})}):m&&!e.pendingOpen?m(X,R(X),o):x.jsx(dv,{tile:X,chrome:o,heading:R(X),...e.pendingOpen?{note:"Preview appears after you Save"}:{}})})}})]})}),i&&a&&!D&&x.jsx(S.Button,{size:"small",startIcon:x.jsx(E.AddIcon,{}),"aria-label":"Add tile at the end",onClick:()=>p(),sx:{alignSelf:"center"},children:"Add tile"})]})}const gv=(e,t,n)=>{if(e.declaration.kind==="inherited")return;const r=Fe(e),s=i=>o=>n(r,a=>{xe(a)&&(o===""?delete a[i]:a[i]=o)});return{title:x.jsx(fo,{value:e.label??"",placeholder:t,ariaLabel:"Tile title",onCommit:s("label")}),subtitle:x.jsx(fo,{value:e.subtitle??"",placeholder:"Add a subtitle",ariaLabel:"Tile subtitle",faintWhenEmpty:!0,onCommit:s("subtitle")})}},mv=e=>je(e)||e.declaration.kind!=="inherited";function vv({editor:e,notebook:t,documentSlug:n,chrome:r,actions:s,descriptionSelected:i,selectDescription:o}){const{theme:a}=Ke.usePublisherTheme();return x.jsxs(x.Fragment,{children:[x.jsxs(S.Stack,{direction:"row",sx:{alignItems:"center",gap:2},children:[x.jsx(S.Typography,{variant:"h5",sx:{flex:1,minWidth:0},children:x.jsx(fo,{value:e.document.title,placeholder:n??(t?"Untitled notebook":"Untitled dashboard"),ariaLabel:t?"Notebook title":"Dashboard title",onCommit:l=>e.update(u=>{u.title=l})})}),x.jsx(S.Box,{sx:{my:"-4px"},children:s})]}),x.jsx(S.Box,{role:"group","aria-label":"Description","aria-current":i,onPointerDown:o,onFocus:o,sx:r==="none"?{my:`${E.BARE_DESCRIPTION_MARGIN_PX}px`}:void 0,children:x.jsx(E.TileCard,{chrome:r,kind:"text",sx:{position:"relative",overflow:"visible",...Ku(a,{selected:i,bare:r==="none"})},children:x.jsx(qu,{markdown:e.document.description??"",placeholder:"Add a description",onCommit:l=>e.update(u=>{l.trim()===""?delete u.description:u.description=l})})})})]})}const bv=({size:e,notebook:t,savesTo:n,onEvent:r})=>({size:e,saved:({size:s,structural:i,durationMs:o,fromOpen:a})=>r?.(t?{type:"notebook.saved",cells:s,structural:i,converted:a,where:n,durationMs:o}:{type:"dashboard.saved",tiles:s,structural:i,where:n,durationMs:o}),refused:s=>r?.({type:t?"notebook.save_refused":"dashboard.save_refused",reason:s}),undone:({size:s,structural:i,durationMs:o})=>r?.(t?{type:"notebook.save_undone",cells:s,structural:i,where:n,durationMs:o}:{type:"dashboard.save_undone",tiles:s,structural:i,where:n,durationMs:o}),undoRefused:s=>r?.({type:t?"notebook.save_undo_refused":"dashboard.save_undo_refused",reason:s})}),yv=E.createSvgIcon(x.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"})),xv=E.createSvgIcon(x.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"})),bo=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),_i=bo?"⌘":"Ctrl+",Il=e=>{if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"},ki=e=>e instanceof Element&&e.closest('[role="dialog"], .MuiPopover-root, .MuiDialog-root')!==null;function wv(e){const t=k.useRef(e);k.useEffect(()=>{t.current=e});const[n,r]=k.useState(!1);k.useEffect(()=>{n&&(r(!1),t.current.save?.())},[n]),k.useEffect(()=>{const s=i=>{const o=t.current;if(o.paused)return;const a=bo?i.metaKey:i.ctrlKey,l=i.key.toLowerCase();if(i.key==="Escape"){if(Il(i.target)||ki(i.target))return;o.escape();return}if(Il(i.target)){if(a&&l==="s"){if(i.preventDefault(),!o.save||ki(i.target))return;i.target.blur(),r(!0)}return}if(ki(i.target)){a&&l==="s"&&i.preventDefault();return}if(a&&l==="z"){i.preventDefault(),i.shiftKey?o.redo():o.undo();return}if(!bo&&a&&l==="y"){i.preventDefault(),o.redo();return}if(a&&l==="s"){i.preventDefault(),o.save?.();return}o.nudge&&!a&&!i.altKey&&!i.shiftKey&&(i.key==="ArrowLeft"||i.key==="ArrowRight")&&(i.preventDefault(),o.nudge(i.key==="ArrowRight"?1:-1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[])}const Dl={package:"Saves to the package file",browser:"Saves in this browser",host:"Saves to the app this is embedded in"};function _v({canUndo:e,canRedo:t,onUndo:n,onRedo:r,dirty:s,saving:i,onSave:o,savesTo:a="package",saveLabel:l,saveButton:u,actions:d,onAddTile:c,onExit:f}){return x.jsxs(S.Stack,{direction:"row","aria-label":"Builder actions",sx:{alignItems:"center",gap:.5,flexShrink:0,"& .MuiButton-root":{whiteSpace:"nowrap"}},children:[c&&x.jsx(S.Button,{startIcon:x.jsx(E.AddIcon,{}),onClick:c,"aria-label":"Add tile",children:"Tile"}),c&&x.jsx(S.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),x.jsx(S.Tooltip,{title:`Undo (${_i}Z)`,children:x.jsx("span",{children:x.jsx(S.IconButton,{"aria-label":"Undo",disabled:!e,onClick:n,sx:{width:37,height:37},children:x.jsx(xv,{fontSize:"small"})})})}),x.jsx(S.Tooltip,{title:`Redo (${_i}⇧Z)`,children:x.jsx("span",{children:x.jsx(S.IconButton,{"aria-label":"Redo",disabled:!t,onClick:r,sx:{width:37,height:37},children:x.jsx(yv,{fontSize:"small"})})})}),(d||o||f)&&x.jsx(S.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5}}),d,o?x.jsx(S.Tooltip,{title:s?`Save (${_i}S) · ${l??Dl[a]}`:l??Dl[a],children:x.jsx("span",{children:x.jsx(S.Button,{ref:u,variant:s?"contained":"outlined",disabled:!s||i,onClick:o,sx:{minWidth:124},children:i?"Saving…":s?"Save":"Saved"})})}):null,o&&x.jsx(S.Box,{component:"span","aria-live":"polite",sx:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clipPath:"inset(50%)",whiteSpace:"nowrap"},children:i?"Saving":s?"Unsaved changes":"All changes saved"}),f&&x.jsx(E.SecondaryButton,{label:"Close",icon:x.jsx(E.CheckIcon,{}),onClick:f})]})}const kv=E.createSvgIcon(x.jsx("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2m5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12z"})),Sv=E.createSvgIcon(x.jsx("path",{d:"M10 18h4v-2h-4zM3 6v2h18V6zm3 7h12v-2H6z"}));function $v({controls:e,tileCount:t,unknownFieldsOf:n,onEdit:r,onAdd:s,addDisabledReason:i,onRemove:o,children:a}){const{theme:l}=Ke.usePublisherTheme();return x.jsx(x.Fragment,{children:x.jsxs(S.Stack,{sx:{gap:1,position:"sticky",top:0,zIndex:E.STICKY_CONTROLS_Z,bgcolor:"background.default",pb:1},children:[x.jsx(S.Stack,{direction:"row",sx:{gap:2,alignItems:"center",minHeight:32},children:x.jsxs(S.Stack,{direction:"row",role:"group","aria-label":"Filters",sx:{gap:1,alignItems:"center",flexWrap:"wrap",flex:1,minWidth:0},children:[x.jsx(Sv,{sx:{fontSize:18,color:l.tileTitle,opacity:.7}}),x.jsx(S.Typography,{variant:"subtitle2",sx:{color:l.tileTitle,mr:.5},children:"Filters"}),e.length===0&&x.jsx(S.Typography,{variant:"body2",sx:{color:l.tileTitle,opacity:.8},children:"None yet."}),e.map(u=>{const d=n(u.name,u.type);return x.jsx(S.Tooltip,{title:d.length>0?`$${u.name} · cannot filter on: ${d.join(", ")}`:`$${u.name} · ${u.origin==="dashboard"?"declared here":"from the model"} · ${u.boundTiles} of ${t} tiles`,children:x.jsx(S.Chip,{size:"small",label:`${u.label??u.name}${u.boundTiles===0?" · unused":""}`,"aria-label":`Edit filter ${u.name}`,color:d.length>0?"warning":"default",variant:u.origin==="dashboard"?"filled":"outlined",onClick:()=>r(u),onDelete:()=>o(u.name),deleteIcon:x.jsx(kv,{"aria-label":`Remove filter ${u.name}`}),sx:{opacity:u.boundTiles===0?.6:1,cursor:"pointer",transition:`opacity ${E.MOTION_FAST}`,...E.reducedMotionSx}})},u.name)}),x.jsx(S.Tooltip,{title:i??"",children:x.jsx("span",{children:x.jsx(S.Chip,{component:"button",size:"small",variant:"outlined",icon:x.jsx(E.AddIcon,{}),label:"Filter","aria-label":"Add filter","aria-haspopup":"dialog",disabled:i!==void 0,onClick:()=>s(),sx:{cursor:"pointer",color:l.tileTitle,borderStyle:"dashed","& .MuiChip-icon":{color:"inherit",fontSize:16}}})})})]})}),a]})})}function Tv(e,t){const n=new Map(e.tiles.map((r,s)=>[Fe(r),{tile:r,index:s}]));for(const[r,s]of t.tiles.entries()){const i=n.get(Fe(s));if(!i||i.index!==r||JSON.stringify(i.tile)!==JSON.stringify(s))return Fe(s)}}function Ov({editor:e,gridBox:t}){const[n,r]=k.useState(void 0),s=typeof n=="object"?n.tile:void 0,i=n==="description",o=k.useCallback(m=>r(y=>typeof y=="object"&&y.tile===m?y:{tile:m}),[]),a=k.useCallback(()=>r(m=>m==="description"?m:void 0),[]),l=k.useCallback(()=>r("description"),[]),u=k.useCallback(()=>r(void 0),[]),[d,c]=k.useState(void 0),f=k.useRef(!1),p=k.useRef(e.document);k.useEffect(()=>{const m=p.current;if(p.current=e.document,!f.current)return;f.current=!1;const y=Tv(m,e.document);if(y===void 0)return;c(y),Array.from(t.current?.querySelectorAll("[data-tile-key]")??[]).find(v=>v.dataset.tileKey===y)?.scrollIntoView?.({block:"nearest",behavior:E.scrollBehavior()})},[e.document,t]),k.useEffect(()=>{if(d===void 0)return;const m=setTimeout(()=>c(void 0),1500);return()=>clearTimeout(m)},[d]);const h=k.useMemo(()=>({...e,undo:()=>{f.current=!0,e.undo()},redo:()=>{f.current=!0,e.redo()}}),[e]);return{selected:s,descriptionSelected:i,selectTile:o,deselectTile:a,selectDescription:l,clearSelection:u,flash:d,stepEditor:h}}function Ev({dirty:e,saving:t,canSave:n,save:r,onExit:s}){const[i,o]=k.useState("idle"),[a,l]=k.useState(!1),u=k.useRef(r);u.current=r;const d=k.useRef(s);d.current=s;const c=k.useRef(0),f=k.useCallback(async()=>{const h=++c.current;l(!1),o("saving");try{await u.current()}catch{c.current===h&&o("idle");return}c.current===h&&l(!0)},[]);return k.useEffect(()=>{if(i==="waiting"){if(t)return;e?f():(o("idle"),d.current())}else if(i==="saving"){if(!a||t)return;o("idle"),e||d.current()}},[i,a,t,e,f]),{requestExit:k.useCallback(()=>{i==="idle"&&(e?o("asking"):d.current())},[i,e]),dialog:{open:i==="asking",canSave:n,onKeepEditing:()=>{i==="asking"&&o("idle")},onDiscard:()=>{i==="asking"&&(o("idle"),d.current())},onSaveAndExit:()=>{i==="asking"&&(t?o("waiting"):f())}}}}function Cv({editor:e,onSave:t,onDirtyChange:n,onExit:r,onChange:s,extraDirty:i=!1,report:o,unit:a,prepare:l,shortcuts:u}){const[d,c]=k.useState(!1),[f,p]=k.useState(!1),h=k.useRef(null),m=k.useRef(o);m.current=o;const y=e.dirty||i,w=(e.edited??e.dirty)||i;k.useEffect(()=>{s?.(e.document)},[e.document,s]),k.useLayoutEffect(()=>{n?.(w)},[w,n]);const v=k.useRef(n);v.current=n,k.useEffect(()=>()=>v.current?.(!1),[]);const g=k.useRef(a);g.current=a,k.useEffect(()=>{p(!1)},[e.document]);const b=k.useCallback(()=>{c(!0),p(!1);const G=E.now(),{structural:U}=e,Y=e.pendingOpen??!1,re=m.current.size;return e.save().then(ee=>{ee.ok===!0?m.current.saved({size:re,structural:U,fromOpen:Y,durationMs:E.now()-G}):m.current.refused(ee.reason)}).finally(()=>c(!1))},[e]),_=k.useRef(!1),O=k.useRef(!1);k.useEffect(()=>{!O.current||d||(O.current=!1,h.current?.focus())},[f,d]);const I=k.useCallback(()=>{if(!t||d||_.current||!e.canUndoSave)return;_.current=!0,c(!0);const G=E.now(),U=e.lastSave?.structural??!1,Y=m.current.size;return e.undoSave().then(re=>{re.ok===!0?(O.current=!0,p(!0),m.current.undone({size:Y,structural:U,fromOpen:!1,durationMs:E.now()-G})):m.current.undoRefused(re.reason)}).finally(()=>{_.current=!1,c(!1)})},[t,d,e]),M=k.useCallback(()=>{if(!(!t||!e.dirty||d))return b()},[t,e,d,b]),T=k.useRef(M);T.current=M;const D=k.useCallback(()=>{const G=()=>T.current();return l?l(G):G()},[l]),N=Ev({dirty:w,saving:d,canSave:!!t,save:D,onExit:()=>r?.()});wv(k.useMemo(()=>({...u,undo:e.undo,redo:e.redo,...t?{save:D}:{},paused:N.dialog.open}),[u,e,t,D,N.dialog.open]));const R=!!t&&!d&&e.canUndoSave,W=e.lastSave,X={canUndo:e.canUndo,canRedo:e.canRedo,onUndo:e.undo,onRedo:e.redo,dirty:y,saving:d,saveButton:h,...t?{onSave:D}:{},...r?{onExit:N.requestExit}:{}};return{saving:d,save:D,exitGuard:N,undoSave:I,canUndoSave:R,lastSave:W,toolbarProps:X}}function Jr(e){for(const t of e??[]){const n=/^#\(doc\)\s*(.*)$/s.exec(t.trim());if(n)return n[1].trim()}}function Al(e){for(const t of e??[]){const n=/^#\s*(?:-[A-Za-z_]+\s+)*([a-z_]+)/.exec(t.trim())?.[1];if(n&&Eu.includes(n))return n}}const Iv=1;function Uu(e,t,n){const r=[];for(const s of e??[]){const i=s.name,o=s.kind;if(typeof i=="string"){if(o==="dimension"||o==="measure"){const a=s.type?.kind;r.push({name:t+i,kind:o,...a?{type:a}:{}})}else if(o==="join"&&n>0){const a=s.schema?.fields;r.push(...Uu(a,`${t}${i}.`,n-1))}}}return r}function Dv(e){const t=new Map;for(const n of Vu(e))t.set(n.name,Uu(n.schema?.fields,"",Iv));return t}function Vu(e){const t=[];for(const n of e.sourceInfos??[])try{const r=typeof n=="string"?JSON.parse(n):n;r?.name&&t.push(r)}catch{continue}return t}const Av=e=>(e.annotations??[]).some(t=>{const n=t.value??"";return n.startsWith("#(malloy)")&&af.parseTag(n.slice(9)).tag?.has("calculation")===!0});function Pv(e){const t=new Map;for(const n of Vu(e)){const r=new Set;for(const s of n.schema?.fields??[]){if(s.kind!=="view"||typeof s.name!="string")continue;const i=s.schema?.fields;i&&i.length>0&&i.every(Av)&&r.add(s.name)}t.set(n.name,r)}return t}function Pl(e,t){return!e||t===void 0?void 0:e.sources.find(r=>r.name===t)?.fields.filter(r=>r.kind==="dimension")}const yo=e=>(e??"").startsWith("dashboards/"),Ml=e=>e.modelPath??e.path??"";function Hu(e){const t=[],n=new Set,r=new Map,s=new Map,i=new Map;for(const o of e){const a=Ml(o);if(yo(a))continue;const l=E.exportedSources(o.modelInfo);s.set(o,l);for(const{name:u}of o.sources??[])u&&i.set(u,[...i.get(u)??[],a]);for(const u of l)r.set(u,[...r.get(u)??[],a])}for(const o of e){const a=Ml(o);if(yo(a))continue;const l=Dv(o),u=Pv(o);for(const d of o.sources??[]){const c=d.name;if(!c||!s.get(o)?.has(c)||n.has(c))continue;n.add(c);const f=(d.givens??[]).map(p=>p.name).filter(p=>typeof p=="string");t.push({name:c,modelPath:a,exporters:r.get(c)??[a],visibleIn:i.get(c)??[a],...Jr(d.annotations)?{description:Jr(d.annotations)}:{},views:(d.views??[]).filter(p=>typeof p.name=="string").map(p=>({name:p.name,...Jr(p.annotations)?{description:Jr(p.annotations)}:{},...Al(p.annotations)?{chart:Al(p.annotations)}:{},...u.get(c)?.has(p.name)?{aggregateOnly:!0}:{}})),givens:f,fields:l.get(c)??[]})}}return{sources:t}}function Mv({editor:e,opened:t,givens:n,catalog:r}){const[s,i]=k.useState(void 0),o=k.useMemo(()=>{const h=new Set((t.localGivens??[]).map(m=>m.name));return(n??[]).filter(m=>!h.has(m.name))},[t,n]),a=k.useMemo(()=>pf(e.document,o),[e.document,o]),l=k.useMemo(()=>new Map(e.document.sources.map(h=>[h.name,Pl(r,h.base)])),[r,e.document.sources]),u=k.useCallback(h=>l.get(h.source)??Pl(r,h.source),[l,r]),d=(h,m)=>{const y=[];for(const w of e.document.tiles){if(!xe(w))continue;const v=u(w);if(!v)continue;const g=new Map(v.map(b=>[b.name,b.type]));for(const b of w.filters??[])b.given===h&&(!g.has(b.field)||!rs(m,g.get(b.field)))&&y.push(`${b.field} on ${w.label??w.name} (${e.document.sources.find(_=>_.name===w.source)?.base??w.source})`)}return y},c=k.useMemo(()=>a.filter(h=>h.origin==="model"&&h.boundTiles===0),[a]);return{filterDialog:s,setFilterDialog:i,controlList:a,fieldsFor:u,unknownFieldsOf:d,available:c,applyFilter:(h,m,y)=>{i(void 0),e.update(w=>{y&&wf(w,y),xf(w,h,m)})},dropControl:h=>{i(void 0),e.update(m=>_f(m,h))}}}function jv({pendingOpen:e,prepare:t}){const[n,r]=k.useState(void 0),s=k.useRef(e);s.current=e;const i=k.useCallback(o=>s.current?new Promise(a=>r({go:()=>{r(void 0),a(t(o))},stop:()=>{r(void 0),a()}})):t(o),[t]);return{confirmConversion:n,prepareSave:i}}function Rv(e){const{splice:t,onSave:n,structural:r,clearsHistory:s,opensDirty:i=!1}=e,[o,a]=k.useState({stack:[e.document],index:0}),[l,u]=k.useState(e.source),[d,c]=k.useState(void 0),[f,p]=k.useState(e.document),[h,m]=k.useState(i),[y,w]=k.useState(e.replaces),[v,g]=k.useState(!1),b=o.stack[o.index],_=k.useRef(o);_.current=o;const O=k.useRef(!1),[I,M]=k.useState(!1),T=j=>{O.current=j,M(j)},[D,N]=k.useState(void 0),R=k.useCallback(j=>{c(void 0),a(q=>{const J=structuredClone(q.stack[q.index]);if(j(J),JSON.stringify(J)===JSON.stringify(q.stack[q.index]))return q;const H=[...q.stack.slice(0,q.index+1),J].slice(-100);return{stack:H,index:H.length-1}})},[]),W=k.useCallback(()=>{c(void 0),a(j=>j.index>0?{...j,index:j.index-1}:j)},[]),X=k.useCallback(()=>{c(void 0),a(j=>j.index<j.stack.length-1?{...j,index:j.index+1}:j)},[]),G=k.useCallback(async(j,q)=>{try{return await t(j,q)}catch(J){return{ok:!1,reason:`Could not build the file: ${J instanceof Error?J.message:String(J)}`}}},[t]),U=k.useCallback(async()=>{if(O.current)return{ok:!1,reason:"A save is still being written."};const j={source:l,saved:f,history:_.current,pendingOpen:h,replacing:y,unwritten:v},q=s?.(f,b)??!1,J=r?.(f,b)??!1;T(!0);try{const Q=await G(l,b);if(Rs(Q))return c(Q.reason),{ok:!1,reason:Q.reason};try{await n?.(Q.source,{purpose:"save",document:b})}catch($){const P=`Could not save: ${$ instanceof Error?$.message:String($)}`;return c(P),{ok:!1,reason:P}}u(Q.source),p(b),m(!1),w(void 0),g(!1);const H=q?{stack:[b],index:0}:j.history;return a($=>$===j.history?H:q?{stack:[$.stack[$.index]],index:0}:$),N(n?{before:j,after:H,lastSave:{before:y??l,after:Q.source,structural:J,clearsHistory:q}}:void 0),c(void 0),{ok:!0}}finally{T(!1)}},[b,G,n,l,f,h,y,v,s,r]),Y=k.useCallback(async()=>{if(O.current)return{ok:!1,reason:"A save is still being written."};if(!n||D===void 0||D.after!==_.current)return{ok:!1,reason:"There is no save to undo."};const{before:j}=D;T(!0);try{await n(j.replacing??j.source,{purpose:"undo",document:j.saved})}catch(q){const J=`Could not undo the save: ${q instanceof Error?q.message:String(q)}`;return c(J),{ok:!1,reason:J}}finally{T(!1)}return u(j.source),p(j.saved),m(j.pendingOpen),w(j.replacing),g(j.unwritten||j.replacing!==void 0),a(q=>q===D.after?j.history:q),N(void 0),c(void 0),{ok:!0}},[n,D]),re=k.useMemo(()=>v||JSON.stringify(b)!==JSON.stringify(f),[b,f,v]),ee=k.useMemo(()=>r?.(f,b)??!1,[b,f,r]),A=k.useMemo(()=>s?.(f,b)??!1,[b,f,s]),B=D!==void 0&&D.after===o,z=k.useCallback(async()=>{const j=await G(l,b);return Rs(j)?{ok:!1,reason:j.reason}:{ok:!0,source:j.source}},[b,G,l]);return{document:b,saved:f,source:l,canUndo:o.index>0,canRedo:o.index<o.stack.length-1,dirty:re||h,edited:re,pendingOpen:h,...d===void 0?{}:{error:d},update:R,undo:W,redo:X,save:U,preview:z,structural:ee,clearsHistory:A,canUndoSave:B&&!I&&n!==void 0,...B?{lastSave:D.lastSave}:{},undoSave:Y}}const Lv=(e,t)=>{const n=new Set(e.tiles.map(vo)),r=new Set(t.tiles.map(vo));return[...n].some(s=>!r.has(s))||[...r].some(s=>!n.has(s))};function Nv(e){const{conversion:t,modelPath:n,explicitKind:r,visibleSources:s,...i}=e,o=t?.from,a=t?.to,l=k.useCallback((u,d)=>Gu(o!==void 0&&u===o?a:u,d,{changeKind:!0,...n!==void 0?{modelPath:n}:{},...r?{explicitKind:r}:{},...s?{visibleSources:s}:{}}),[o,a,n,r,s]);return Rv({...i,splice:l,structural:Lv,opensDirty:t!==void 0})}function Fv({editorDirty:e}){const[t,n]=k.useState(!1),r=k.useRef(void 0),s=k.useRef(void 0),i=k.useMemo(()=>({setDirty:n,commitRef:r}),[]),o=k.useCallback(a=>{if(!r.current)return a();if(r.current())return new Promise(l=>{s.current=()=>l(a())})},[]);return k.useEffect(()=>{if(t||!s.current)return;const a=s.current;s.current=void 0,a()},[t,e]),{draftDirty:t,openDraft:i,prepare:o}}const Xu="dashboards/document.malloy",Yu=e=>e.slice(0,e.lastIndexOf("/")+1),Zu=(e,t)=>new URL(e,`https://malloy.invalid/${Yu(t)}`).pathname.slice(1);function zv(e,t){const n=Yu(t).split("/").filter(Boolean),r=e.split("/");let s=0;for(;s<n.length&&s<r.length-1&&n[s]===r[s];)s++;const i=n.length-s;return`${i===0?"./":"../".repeat(i)}${r.slice(s).join("/")}`}function Wv(e,t,n,r=Xu,s=[n]){return e.sources.some(i=>i.base===t)?!0:e.imports.some(i=>i.kind==="names"?i.names.includes(t):s.includes(Zu(i.from,r)))}function Bv(e,t,n,r=Xu,s=[n]){const{imports:i}=e;if(Wv(e,t,n,r,s))return i;const o=i.findIndex(a=>a.kind==="names"&&s.includes(Zu(a.from,r)));return o<0?[...i,{kind:"names",names:[t],from:zv(n,r)}]:i.map((a,l)=>l===o&&a.kind==="names"?{...a,names:[...a.names,t]}:a)}function Gv(e,t,{modelPath:n,textHeld:r,notebook:s,insertAt:i}){t.modelPath&&!r&&(e.imports=Bv(e,t.base,t.modelPath,n,t.exporters??[t.modelPath]));let o=e.sources.find(u=>u.base===t.base);if(!o){const u=new Set(e.sources.map(c=>c.name));let d=`${t.base}_tiles`;for(let c=2;u.has(d);c++)d=`${t.base}_tiles_${c}`;o={name:d,base:t.base},e.sources.push(o)}const a=new Set(e.tiles.filter(xe).filter(u=>u.source===o.name).map(u=>u.name));let l=`${t.view}_tile`;for(let u=2;a.has(l);u++)l=`${t.view}_tile_${u}`;e.tiles.splice(i??e.tiles.length,0,{name:l,source:o.name,declaration:{kind:"reference",from:t.view},...s?{}:{colspan:t.colspan},...t.label?{label:t.label}:{},...t.chart?{chart:t.chart}:{},...t.chartCarried?{chartCarried:t.chartCarried}:{}})}function qv({editor:e,notebook:t,columns:n,modelPath:r,textHeld:s,selectTile:i,deselectTile:o}){const[a,l]=k.useState(void 0),[u,d]=k.useState(!1),[c,f]=k.useState(void 0);return{menu:a,setMenu:l,addingTile:u,openAdd:g=>{f(g),d(!0)},closeAdd:()=>d(!1),addTile:g=>{d(!1),e.update(b=>Gv(b,g,{modelPath:r,textHeld:s,notebook:t,insertAt:c})),i(c??e.document.tiles.length)},addText:()=>{d(!1),e.update(g=>{const b=new Set(g.tiles.filter(je).map(O=>O.name));let _=1;for(;b.has(`text_${_}`);)_++;g.tiles.splice(c??g.tiles.length,0,{kind:"text",name:`text_${_}`,markdown:"",...t?{}:{colspan:n}})}),i(c??e.document.tiles.length)},editTile:(g,b)=>e.update(_=>{const O=_.tiles.find(I=>Fe(I)===g);O&&b(O)}),removeTile:g=>{l(void 0),o(),e.update(b=>{b.tiles.splice(g,1)})}}}var Kv=Object.defineProperty,Uv=Object.defineProperties,Vv=Object.getOwnPropertyDescriptors,jl=Object.getOwnPropertySymbols,Hv=Object.prototype.hasOwnProperty,Xv=Object.prototype.propertyIsEnumerable,Rl=(e,t,n)=>t in e?Kv(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t||(t={}))Hv.call(t,n)&&Rl(e,n,t[n]);if(jl)for(var n of jl(t))Xv.call(t,n)&&Rl(e,n,t[n]);return e},on=(e,t)=>Uv(e,Vv(t));function Yv(e,t,n){if(t===n)return e;const r=e.slice();return r.splice(n,0,r.splice(t,1)[0]),r}function es(e,t){const n=String(t);return Object.prototype.hasOwnProperty.call(e,n)?n:void 0}function Si(e){return"initialIndex"in e&&typeof e.initialIndex=="number"&&"index"in e&&typeof e.index=="number"}function Zv(e,t,n){var r,s;const{source:i,target:o,canceled:a}=t.operation;if(!i||!o||a)return"preventDefault"in t&&t.preventDefault(),e;const l=(g,b)=>g===b||g!==null&&typeof g=="object"&&"id"in g&&g.id===b;if(Array.isArray(e)){const g=e.findIndex(_=>l(_,i.id)),b=e.findIndex(_=>l(_,o.id));if(g===-1||b===-1){if(Si(i)){const _=i.initialIndex,O=i.index;return _===O||_<0||_>=e.length?("preventDefault"in t&&t.preventDefault(),e):n(e,_,O)}return e}if(!a&&"index"in i&&typeof i.index=="number"){const _=i.index;if(_!==g)return n(e,g,_)}return n(e,g,b)}const u=Object.entries(e);let d=-1,c,f=-1,p;for(const[g,b]of u)if(d===-1&&(d=b.findIndex(_=>l(_,i.id)),d!==-1&&(c=g)),f===-1&&(f=b.findIndex(_=>l(_,o.id)),f!==-1&&(p=g)),d!==-1&&f!==-1)break;if(d===-1&&Si(i)){const g=i.initialGroup==null?void 0:es(e,i.initialGroup),b=i.initialIndex,_=i.group==null?void 0:es(e,i.group),O=i.index;if(g==null||_==null||g===_&&b===O)return"preventDefault"in t&&t.preventDefault(),e;if(g===_)return on(sn({},e),{[g]:n(e[g],b,O)});const I=e[g][b];return on(sn({},e),{[g]:[...e[g].slice(0,b),...e[g].slice(b+1)],[_]:[...e[_].slice(0,O),I,...e[_].slice(O)]})}if(!i.manager)return e;const{dragOperation:h}=i.manager,m=(s=(r=h.shape)==null?void 0:r.current.center)!=null?s:h.position.current;if(p==null){const g=es(e,o.id);if(g!=null){const b=o.shape&&m.y>o.shape.center.y?e[g].length:0;p=g,f=b}}if(c==null||p==null||c===p&&d===f){if(c!=null&&c===p&&d===f&&Si(i)){const g=i.group==null?void 0:es(e,i.group),b=i.group!=null&&g!==c,_=i.index!==d;if(b||_){const O=i.group==null?c:g;if(O!=null){if(c===O)return on(sn({},e),{[c]:n(e[c],d,i.index)});const I=e[c][d];return on(sn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[O]:[...e[O].slice(0,i.index),I,...e[O].slice(i.index)]})}}}return"preventDefault"in t&&t.preventDefault(),e}if(c===p)return on(sn({},e),{[c]:n(e[c],d,f)});const w=o.shape&&Math.round(m.y)>Math.round(o.shape.center.y)?1:0,v=e[c][d];return on(sn({},e),{[c]:[...e[c].slice(0,d),...e[c].slice(d+1)],[p]:[...e[p].slice(0,f+w),v,...e[p].slice(f+w)]})}function Qv(e,t){return Zv(e,t,Yv)}function Jv({tiles:e,commit:t,onLanded:n}){const[r,s]=k.useState(void 0),i=k.useRef(void 0),[o,a]=k.useState(!1);return{dragging:o,preview:r,onDragStart:()=>{a(!0),i.current=e},onDragOver:c=>{const{source:f,target:p}=c.operation;if(!f||!p)return;const h=i.current??e;let m;if(p.type===Tu){const{after:y}=p.data,w=h.findIndex(b=>Fe(b)===f.id);if(w<0||y===f.id)return;const g=h.filter((b,_)=>_!==w).findIndex(b=>Fe(b)===y)+1;m=Ig(h,w,g)}else{const y=h.map(Fe),w=Qv(y,c);if(w.every((g,b)=>g===y[b]))return;const v=new Map(h.map(g=>[Fe(g),g]));m=Cg(w.map(g=>v.get(g)),e.map(g=>g.break??!1))}i.current=m,s(m)},onDragEnd:c=>{a(!1);const f=i.current;if(i.current=void 0,s(void 0),c.canceled||!f)return;t(f);const p=f.findIndex(h=>Fe(h)===c.operation.source?.id);p>=0&&n(p)}}}const $i=e=>{const t=window.document.body;t.style.userSelect=e?"none":"",t.style.cursor=e?"grabbing":""};function eb({tiles:e,columns:t,gridBox:n,onStart:r,commit:s}){const[i,o]=k.useState(void 0),a=k.useRef(void 0),l=f=>{a.current=f,o(f)};return k.useEffect(()=>()=>$i(!1),[]),{resize:i,startResize:(f,p)=>{const h=n.current?.getBoundingClientRect(),m=f.currentTarget.parentElement?.getBoundingClientRect();if(!h||!m)return;f.stopPropagation(),f.preventDefault(),f.currentTarget.setPointerCapture(f.pointerId),$i(!0),r(p);const y=e[p]?.colspan??1;l({index:p,span:y,from:y,left:m.left,track:(h.width-E.GRID_GAP_PX*(t-1))/t})},onResize:f=>{const p=a.current;if(!p)return;const h=f.clientX-p.left,m=Math.round((h+E.GRID_GAP_PX)/(p.track+E.GRID_GAP_PX)),y=Math.min(Math.max(m,1),t);y!==p.span&&l({...p,span:y})},endResize:f=>{f.currentTarget.hasPointerCapture(f.pointerId)&&f.currentTarget.releasePointerCapture(f.pointerId),$i(!1);const p=a.current;if(!p)return;const{index:h,span:m,from:y}=p;l(void 0),!(f.type==="pointercancel"||m===y)&&s(h,m)}}}function Qu({source:e,document:t,onSave:n,onChange:r,onDirtyChange:s,onExit:i,renderTile:o,controls:a,givens:l,catalog:u,toolbar:d,dashboards:c,onEvent:f,conversion:p,savesTo:h="package",saveLabel:m,replaces:y,modelPath:w,explicitKind:v,visibleSources:g,addFilterDisabledReason:b}){const _=Nv({source:e,document:t,...n?{onSave:n}:{},...p?{conversion:p}:{},...y!==void 0?{replaces:y}:{},...w!==void 0?{modelPath:w}:{},...v?{explicitKind:v}:{},...g?{visibleSources:g}:{}}),O=k.useRef(null),{selected:I,descriptionSelected:M,selectTile:T,deselectTile:D,selectDescription:N,clearSelection:R,flash:W,stepEditor:X}=Ov({editor:_,gridBox:O}),G=_.document.kind==="notebook",U=G?1:_.document.columns??E.DEFAULT_COLUMNS,Y=G?"none":"card",re=w?.split("/").at(-1)?.replace(/\.malloy$/,""),ee=Jv({tiles:_.document.tiles,commit:ae=>_.update(C=>{C.tiles=ae}),onLanded:T}),{dragging:A}=ee,B=eb({tiles:_.document.tiles,columns:U,gridBox:O,onStart:T,commit:(ae,C)=>_.update(K=>{const ie=K.tiles[ae];ie&&(ie.colspan=C)})}),z=qv({editor:_,notebook:G,columns:U,modelPath:w,textHeld:g!==void 0,selectTile:T,deselectTile:D}),{menu:j,addingTile:q,openAdd:J}=z,Q=Mv({editor:_,opened:t,givens:l,catalog:u}),{filterDialog:H,setFilterDialog:$}=Q,[P,F]=k.useState(void 0),{draftDirty:V,openDraft:oe,prepare:Z}=Fv({editorDirty:_.dirty}),{confirmConversion:ne,prepareSave:de}=jv({pendingOpen:_.pendingOpen,prepare:Z}),se=k.useMemo(()=>({escape:()=>{!j&&!H&&!q&&P===void 0&&ne===void 0&&R()},nudge:ae=>{if(A||I===void 0||G)return;const C=_.document.tiles[I];if(!C||xe(C)&&C.declaration.kind==="inherited")return;const K=E.nudgedSpan(C.colspan??1,ae,U);K!==(C.colspan??1)&&_.update(ie=>{ie.tiles[I].colspan=K})}}),[_,j,H,q,P,ne,R,I,U,G,A]),L=Cv({editor:X,extraDirty:V,prepare:de,unit:{name:"tile",count:ae=>ae.tiles.length},onSave:n,onDirtyChange:s,onExit:i,onChange:r,shortcuts:se,report:bv({size:_.document.tiles.length,notebook:G,savesTo:h,onEvent:f})}),te=_.document.tiles.length===0,pe=x.jsx(_v,{...L.toolbarProps,...d?{actions:d}:{},...u?{onAddTile:()=>J()}:{},savesTo:h,...m?{saveLabel:m}:{}});return x.jsx(fu.Provider,{value:oe,children:x.jsx(S.Stack,{sx:{gap:0,mx:`-${wi}px`},children:x.jsxs(S.Stack,{sx:{gap:2,px:`${wi}px`,pb:`${wi}px`},children:[_.pendingOpen&&x.jsx(S.Alert,{severity:"info",children:"This notebook is in the cell format. Saving rewrites it as a layout notebook, and a named query run once becomes that tile's view."}),x.jsx(vv,{editor:_,notebook:G,documentSlug:re,chrome:Y,actions:pe,descriptionSelected:M,selectDescription:N}),te?x.jsx(x.Fragment,{children:x.jsxs(S.Stack,{sx:{alignItems:"flex-start",gap:1,py:3,px:2,border:1,borderStyle:"dashed",borderColor:"divider",borderRadius:1},children:[x.jsxs(S.Typography,{variant:"body2",children:["This ",G?"notebook":"dashboard"," is not served until it has a tile."]}),u&&x.jsx(S.Button,{size:"small",startIcon:x.jsx(E.AddIcon,{}),onClick:()=>J(),children:"Add tile"})]})}):x.jsx($v,{controls:Q.controlList,tileCount:_.document.tiles.length,unknownFieldsOf:Q.unknownFieldsOf,onEdit:ae=>$({control:ae}),onAdd:()=>$({}),...b?{addDisabledReason:b}:{},onRemove:Q.dropControl,children:a}),_.error&&x.jsx(S.Alert,{severity:"warning",children:_.error}),x.jsx(pv,{editor:_,reorder:ee,resizing:B,gridBox:O,columns:U,notebook:G,chrome:Y,canAdd:!!u,selected:I,flash:W,menuIndex:j?.index,onSelect:T,onOpenMenu:(ae,C)=>{T(C),z.setMenu({anchor:ae,index:C})},openAdd:J,editTile:z.editTile,...o?{renderTile:o}:{}}),x.jsx(Cf,{editor:_,catalog:u,columns:U,dashboards:c,bindings:Q,tiles:z,drillSource:P,setDrillSource:F,confirmConversion:ne,exitDialog:L.exitGuard.dialog})]})})})}function tb(e,t){const n=new Set;for(const i of e.tiles)for(const o of xe(i)?i.filters??[]:[])n.add(o.given);const r=[],s=new Set;for(const i of e.localGivens??[])n.has(i.name)&&(s.add(i.name),r.push(nb(i)));for(const i of t)i.name===void 0||s.has(i.name)||!n.has(i.name)||(s.add(i.name),r.push(i));return r}function nb(e){const t=rb(e);return{name:e.name,type:e.type,...t===void 0?{}:{default:t},...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 rb(e){if(!e.type?.startsWith("filter<"))return e.default;const t=e.default?.match(/^f(['"])([\s\S]*)\1$/)?.[2];return t===void 0?e.default:t===""?void 0:t}function sb(e){return e.kind==="inline"?!0:e.kind==="opaque"&&(e.why.includes("compound")||e.why.includes("pipeline"))}function ts(e){return e.split("->").map(t=>t.trim().replace(/\s+/g," ")).join(" -> ").replace(/\s+/g," ")}function ib(e,t,n,r=new Map,s){if(t.declaration.kind==="inherited")return{expression:`${t.source} -> ${t.name}`,givenNames:void 0,reads:s&&[...s]};const i=t.source,o=t.declaration.kind==="reference"?t.declaration.from:t.name,a=new Map((e.localGivens??[]).map(m=>[m.name,m.type])),l=e.sources.find(m=>m.name===i)?.scopedBy??[],u=new Set([...l,...s??[]].filter(m=>n.has(m))),d=new Set([...l,...s??[]]),c=[];for(const m of t.filters??[]){const y=`where: ${me.malloyPath(m.field)} ${m.op??"~"}`;if(n.has(m.given)){u.add(m.given),d.add(m.given),c.push(`${y} $${m.given}`);continue}if(!a.has(m.given))continue;d.add(m.given);const w=E.malloyLiteral(r.get(m.given),a.get(m.given));w!==void 0&&c.push(`${y} ${w}`)}const f=c.join(", "),p=t.chart,h=p==="none"||Qs(p)?yn(p,t.chartCarried):p==="custom"&&t.chartLines?.length?t.chartLines.join(`
|
|
143
|
+
`):p==="default"&&sb(t.declaration)?yn("none"):void 0;return{...h?{annotation:h}:{},expression:`${i} -> ${o}`+(f?` + { ${f} }`:""),givenNames:Array.from(u),reads:s||d.size>0?Array.from(d):void 0}}const ob={};function ab({textSource:e,kind:t,modelGivens:n,environmentName:r,packageName:s,modelPath:i,slug:o,versionId:a,opened:l,replaces:u,onSave:d,onDirtyChange:c,onExit:f,onEvent:p,savesTo:h,saveLabel:m,note:y}){const{apiClients:w}=Ke.useServer(),v=t==="notebook",[g,b]=k.useState(l.document.tiles.length>0);k.useEffect(()=>b(l.document.tiles.length>0),[l.generation,l.document]);const{data:_,isSuccess:O,isError:I}=E.useQueryWithApiError({queryKey:["dashboard-editor-manifest",r,s,o,a,t],queryFn:async()=>{if(!v)return(await w.dashboards.getDashboard(r,s,o,a)).data;const L=(await w.notebooks.getNotebook(r,s,i,a)).data;return L.dashboard??{...L.startingGivens?{startingGivens:L.startingGivens}:{},...L.autorun===void 0?{}:{autorun:L.autorun}}},enabled:g&&!e}),M=e?.modelPath??i,T=E.useCompiledDocument({environmentName:r,packageName:s,modelPath:M,source:l.source,...e?.givens?{givens:e.givens}:{}},{enabled:e!==void 0}),D=T.data?.document,N=e?T.isSuccess?D?.manifest??ob:void 0:_,R=e?T.isSuccess:O,W=e?T.isError:I,X=e?E.documentPreamble(D?.cells):void 0,G=(T.data?.result.problems??[]).filter(L=>L.severity==="error"),U=k.useMemo(()=>new Set(e?.hiddenGivens??[]),[e]),Y=e?.givens,re=k.useMemo(()=>new Set((N?.tiles??[]).flatMap(L=>L.restricted&&L.query?[ts(L.query)]:[])),[N]),{data:ee}=E.useQueryWithApiError({queryKey:["dashboards",r,s,a],staleTime:6e4,queryFn:()=>w.dashboards.listDashboards(r,s,a),enabled:!v}),A=k.useMemo(()=>(ee?.data??[]).map(L=>L.name).filter(L=>!!L&&L!==o),[ee,o]),{data:B}=E.useQueryWithApiError({queryKey:["dashboard-editor-catalog",r,s,a],queryFn:async()=>{const L=(await w.models.listModels(r,s,a)).data.filter(ae=>ae.path&&!ae.error&&!yo(ae.path)&&!ae.path.startsWith("notebooks/")),pe=(await Promise.allSettled(L.map(ae=>w.models.getModel(r,s,ae.path,a).then(C=>C.data)))).flatMap(ae=>ae.status==="fulfilled"?[ae.value]:[]);return Hu(pe)}}),z=k.useMemo(()=>e?(B?.sources??[]).filter(L=>(L.visibleIn??L.exporters??[L.modelPath]).includes(M)).map(L=>L.name):void 0,[B,e,M]),j=k.useMemo(()=>B&&z?{sources:B.sources.filter(L=>z.includes(L.name))}:B,[B,z]),[q,J]=k.useState(l.document);k.useEffect(()=>J(l.document),[l.document]);const Q=k.useMemo(()=>d&&h==="package"?async(L,te)=>{await d(L),b(te.document.tiles.length>0)}:d,[d,h]),H=k.useMemo(()=>(N?.givens??(l.conversion?n??[]:[])).filter(L=>!(e&&L.secure===!0)&&!(L.name!==void 0&&U.has(L.name))),[N,l.conversion,n,U,e]),$=k.useMemo(()=>new Set([...H.map(L=>L.name).filter(L=>L!==void 0),...Object.keys(Y??{})]),[H,Y]),P=k.useMemo(()=>tb(q,H),[q,H]),{declaredTypes:F,applied:V,panel:oe}=E.useDocumentControls({specs:P,loaded:R,startingValues:N?.startingGivens,documentKey:`${r}/${s}/${a??""}/${v?"notebook/":""}${o}/edit`,autorun:N?.autorun!==!1,environmentName:r,packageName:s,modelPath:e?M:N?.path,versionId:a,documentName:o,...X!==void 0?{preamble:X}:{},...Y?{hostGivens:Y}:{}}),Z=k.useMemo(()=>Object.fromEntries(Object.entries(Y??{}).filter(([L])=>!F.has(L))),[Y,F]),ne=!g||R||W,de=k.useMemo(()=>new Map((N?.tiles??[]).flatMap(L=>L.kind!=="text"&&L.query&&L.givenNames?[[ts(L.query),L.givenNames]]:[])),[N]),se=k.useMemo(()=>function(te,pe,ae="card"){if(!ne)return x.jsxs(E.TileCard,{chrome:ae,children:[x.jsx(E.TileHeading,{title:pe?.title??Fs(te),subtitle:pe?pe.subtitle:te.subtitle}),x.jsx(E.Loading,{text:"Running…"})]});const C=ib(q,te,$,V,de.get(ts(`${te.source} -> ${te.name}`)));return x.jsx(E.DashboardTile,{environmentName:r,packageName:s,versionId:a,modelPath:M,...X!==void 0?{preamble:X}:{},...re.has(ts(`${te.source} -> ${te.name}`))?{restricted:!0}:{},tile:C.expression,...C.annotation?{annotation:C.annotation}:{},label:Fs(te),chrome:ae,subtitle:te.subtitle,...pe?{heading:pe}:{},borderless:te.borderless,givens:V,hostGivens:Z,declaredTypes:F,givenNames:C.givenNames,ignoredFilters:E.tileIgnoredFilterLabels(C.reads,P),height:E.TILE_MAX_HEIGHT})},[q,ne,$,de,r,s,a,M,X,re,V,Z,F,P]);return x.jsxs(S.Stack,{sx:{gap:1},children:[e&&G.length>0&&x.jsxs(S.Alert,{severity:"error",children:["The server could not compile this document:"," ",G.map(L=>L.message).join("; ")]}),e&&T.isError&&x.jsxs(S.Alert,{severity:"error",children:["The server could not compile this document:"," ",T.error?.message]}),x.jsx(Qu,{...e?{addFilterDisabledReason:"This document holds no given: of its own. Bind a filter the model offers from its chip."}:{},source:l.source,document:l.document,renderTile:se,givens:P.filter(L=>L.name!==void 0).map(L=>({name:L.name,...L.label?{label:L.label}:{},...L.type?{type:L.type}:{},...L.suggest?.dimension?{field:L.suggest.dimension}:{}})),onChange:J,onDirtyChange:c,...f?{onExit:f}:{},...l.conversion?{conversion:l.conversion}:{},...j?{catalog:j}:{},dashboards:A,...p?{onEvent:p}:{},controls:R?x.jsx(E.GivensPanel,{...oe,layout:v?"panel":"bar"}):void 0,...Q?{onSave:Q}:{},savesTo:h,...m?{saveLabel:m}:{},...u!==void 0?{replaces:u}:{},modelPath:i,...e?{explicitKind:!0,visibleSources:z}:{}}),x.jsx(S.Box,{sx:{px:.5},children:x.jsx(S.Typography,{variant:"caption",sx:{opacity:.7},children:y})})]})}function lb({storage:e,kind:t,notebook:n,environmentName:r,packageName:s,modelPath:i}){const[o,a]=k.useState(void 0),[l,u]=k.useState(void 0),[d,c]=k.useState(e===void 0),[f,p]=k.useState(!1),[h,m]=k.useState(void 0);return k.useEffect(()=>{if(!e)return;let y=!1;return m(void 0),(async()=>{try{const w=E.chooseWorkspace(await e.listWorkspaces(!1));if(y)return;if(a(w),w!==void 0&&(!n||w.authoritative)){const v=await e.getDocument(E.locatorFor(t,w.name,r,s,i)).catch(g=>{if(!E.isDocumentNotFound(g))throw g});if(y)return;u(v),p(v!==void 0)}}catch(w){if(y)return;m(E.storageErrorMessage(w))}y||c(!0)})(),()=>{y=!0}},[e,t,n,r,s,i]),{workspace:o,draft:l,setDraft:u,draftChecked:d,offered:f,setOffered:p,readFailure:h}}const cb=e=>e.ok===!1,qn=(e,t)=>{const n=e[t];return typeof n=="function"?n.call(e):void 0},db=[["runStatement","run"],["docAnnotations","notes"],["importStatement","definition"],["defineSourceStatement","definition"],["defineQuery","definition"],["defineGivenStatement","definition"],["defineUserTypeStatement","definition"],["exportStatement","definition"]],ub=/^[A-Za-z_][A-Za-z0-9_]*$/,fb="file:///publisher-notebook-builder/notebook.malloy",ns=e=>e.replace(/\r\n?/g,`
|
|
144
|
+
`);async function hb(e){const t=(A,B)=>({ok:!1,refused:`Line ${A+1}: ${B}`,line:A+1}),n=/\r(?!\n)/.exec(e);if(n)return t(e.slice(0,n.index).split(`
|
|
145
|
+
`).length-1,"a carriage return that is not part of a CRLF line ending, so the cells cannot be located. Fix: save the file with LF or CRLF line endings.");let r,s;try{r=await Js(e,fb),s=await E.loadMalloy()}catch(A){return t(0,`Malloy could not read this notebook: ${A}`)}const i=r.problems.find(A=>A.code==="syntax-error");if(i)return t(i.at?.range?.start?.line??0,`Malloy could not parse this notebook (${i.message??"unknown"}), so it cannot be edited here. Fix: correct the syntax on that line.`);const o=r.parse?.root,a=r.parse?.tokenStream,l=a?.tokenSource?.vocabulary,u=typeof a?.getTokens=="function"?a.getTokens():void 0;if(!o||typeof o.getChild!="function"||!a||!u||typeof l?.getSymbolicName!="function"||u.length===0&&e.trim()!=="")return{ok:!1,refused:"This build of Malloy does not expose a parse tree and token stream the notebook builder can read, so editing is off."};const d=A=>l.getSymbolicName(A.type),c=A=>s.routeOf({value:A.trimStart()}),f=A=>s.payloadOf({value:A}),p=A=>A==="markdown"||A==='"'||A==="text",h=A=>ns(f(A)).replace(/\n$/,""),m=(A,B)=>{const z=f(A).trim(),j=c(A)!=='"'&&ub.test(z)?"":z;return ns([j&&`${j}
|
|
146
|
+
`,...B].join("")).replace(/\n$/,"")},y=new xa(e),w=_a(y,a),v=A=>e.slice(y.utf16(A.startIndex),y.utf16(A.stopIndex+1)),g=A=>{const B=A.start?.startIndex,z=A.stop?.stopIndex,j=y.span(A);if(B===void 0||z===void 0||!j)return;let q=j.end;for(;q>j.start&&(e[q-1]===`
|
|
147
|
+
`||e[q-1]==="\r");)q--;return{startCp:B,stopCp:z,...j,startLine:y.line(j.start),endLine:y.line(Math.max(j.start,q-1))}},b=A=>{let B=0,z=u.length;for(;B<z;){const j=B+z>>1;u[j].startIndex<A?B=j+1:z=j}return B},_=(A,B)=>{const z=[],j=[],q={lines:[],insertAt:y.utf16(A)};let J=-2;for(let Q=b(A);Q<u.length;Q++){const H=u[Q];if(H.startIndex>B)break;if(H.channel!==0)continue;const $=d(H);if($!=="ANNOTATION"&&$!=="BLOCK_ANNOTATION_BEGIN"){q.insertAt=y.lineStarts[y.line(y.utf16(H.startIndex))];break}const P=ns(v(H)),F=[];if($==="BLOCK_ANNOTATION_BEGIN"){for(;d(u[Q+1]??H)==="BLOCK_ANNOTATION_TEXT";)F.push(v(u[++Q]));d(u[Q+1]??H)==="BLOCK_ANNOTATION_END"&&Q++}if(p(c(P))){const V=y.utf16(H.startIndex),oe=y.lineStarts[y.line(V)],Z=/^[ \t]*$/.test(e.slice(oe,V));j.push({start:Z?oe:V,end:y.utf16(u[Q].stopIndex+1)})}if($==="ANNOTATION"){const V=P.replace(/\n$/,"");if(At(V)){const oe=y.utf16(H.startIndex),Z=y.lineStarts[y.line(oe)];q.lines.push({span:{start:/^[ \t]*$/.test(e.slice(Z,oe))?Z:oe,end:y.utf16(H.stopIndex+1)},text:V})}else kr(V)&&q.unmodelled===void 0&&(q.unmodelled=V.trim())}if(c(P)!=="markdown")J=-2;else if($==="BLOCK_ANNOTATION_BEGIN")z.push(m(P,F)),J=-2;else{const V=h(P);H.line===J+1?z[z.length-1]+=`
|
|
148
|
+
${V}`:z.push(V),J=H.line}}return{markdown:z.length>0?z.join(`
|
|
149
149
|
|
|
150
|
-
`):void 0,prose:j,chart:q}},O=[],
|
|
151
|
-
`)[0];return
|
|
152
|
-
`,1)[0],V.map(
|
|
153
|
-
${
|
|
154
|
-
`,n),i=s<0?e.length:s;t+=" ".repeat(i-n),n=i}else if(r==="/*"){const s=e.indexOf("*/",n+2),i=s<0?e.length:s+2;t+=e.slice(n,i).replace(/[^\n]/g," "),n=i}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const s=e[n];let i=n+1;for(;i<e.length&&e[i]!==s;)i+=e[i]==="\\"?2:1;const o=Math.min(i,e.length);t+=s+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=s),n=o+1}else t+=e[n],n++}return t}function
|
|
150
|
+
`):void 0,prose:j,chart:q}},O=[],I=[],M=(A,B,z="remove it, or rewrite it as an import, source:, query:, given:, type: or export statement, a run:, or a `##(markdown)` / `##|(markdown)` prose note.")=>t(A,`${B}, which no notebook cell can hold, so the notebook cannot be edited here. Fix: ${z}`);for(let A=0;A<(o.childCount??0);A++){const B=o.getChild(A);if(!Lr(B)){const H=B?.symbol,$=H?d(H):void 0;if(H&&$==="EOF")continue;if(H&&$==="SEMI"){O.push([H.startIndex,H.stopIndex]);continue}return M((H?.line??1)-1,"a token outside any statement")}const z=g(B);if(!z)return M(0,"a statement with no readable range");const j=db.find(([H])=>qn(B,H)!==void 0);if(!j&&qn(B,"ignoredObjectAnnotations"))return M(z.startLine,"a # tag that annotates no statement","move the tag directly above its run:, or write trailing prose as a `##(markdown)` note.");if(!j){const H=e.slice(z.start,z.end).split(`
|
|
151
|
+
`)[0];return M(z.startLine,`\`${H.trim()}\` is a statement the notebook reader does not recognize`)}O.push([z.startCp,z.stopCp]);const[q,J]=j;if(J!=="notes"){const{markdown:H,prose:$,chart:P}=_(z.startCp,z.stopCp);I.push({kind:"statement",run:J==="run",...H!==void 0&&{markdown:H},prose:$,chart:P,startLine:z.startLine,endLine:z.endLine});continue}const Q=qn(B,q);for(const H of qn(Q,"docAnnotation")??[]){const $=g(H);if(!$)return M(z.startLine,"a note with no readable range");const P=qn(H,"docBlockAnnotation")!==void 0,F=u.filter(se=>se.startIndex>=$.startCp&&se.stopIndex<=$.stopCp),V=F.filter(se=>d(se)==="BLOCK_ANNOTATION_TEXT"),oe=V[V.length-1]??F[0],Z=ns(P&&oe?e.slice($.start,y.utf16(oe.stopIndex+1)).replace(/\r?\n$/,""):e.slice($.start,$.end)),ne=c(Z),de=p(ne)?P?m(Z.split(`
|
|
152
|
+
`,1)[0],V.map(v)):h(Z):void 0;I.push({kind:"note",note:{text:Z,route:ne,...de!==void 0&&{body:de},block:P,startLine:$.startLine,endLine:$.endLine}})}}for(const A of u){if(d(A)!=="BLOCK_ANNOTATION_END")continue;const B=v(A).trimStart().replace(/^\|#{1,2}/,"").trim();if(B)return t(A.line-1,`the text after a block's closer (\`${B}\`) is not part of any cell, so the notebook cannot be edited here. Fix: put it on its own line, or inside the block.`)}let T=0;for(const A of u){if(A.channel!==0||d(A)==="EOF")continue;for(;T<O.length&&O[T][1]<A.startIndex;)T++;const[B,z]=O[T]??[1/0,-1/0];if(A.startIndex<B||A.stopIndex>z)return M(A.line-1,"a token outside any statement")}const D=I.findIndex(A=>A.kind==="note"&&me.setsArtifactProperty(A.note.text));if(D<0)return t(0,"this file has no ## artifact note, so it is not a notebook the builder can edit. Fix: add `## artifact { kind=notebook }` after the ##! line.");const N=I.findIndex((A,B)=>B<D&&A.kind==="statement");if(N>=0)return t(I[N].startLine,'a statement sits above the `## artifact` tag, where only `##!` flags, comments and `"` notes may. Fix: move it below the artifact tag.');for(let A=1;A<I.length;A++){const B=I[A-1],z=I[A],j=B.kind==="note"?B.note.endLine:B.endLine,q=z.kind==="note"?z.note.startLine:z.startLine;if(q<=j)return M(q,"a line holding two statements or notes","put each statement and note on its own line.")}const R=A=>y.lineStarts[A+1]??e.length,W=[];let X=-1,G=!0,U;I.forEach((A,B)=>{if(A.kind==="statement"){G=!1,U=void 0,W.push({cell:{kind:A.run?"query":"definition",...A.markdown!==void 0&&{markdown:A.markdown},...A.prose.length>0&&{prose:A.prose},...A.run&&{chart:A.chart},id:""},startLine:A.startLine,endLine:A.endLine});return}const{note:z}=A;if(!(B>D&&z.body!==void 0)){G&&(X=z.endLine),U=void 0;return}if(G=!1,!z.block&&U&&U.endLine+1===z.startLine){U.cell.markdown+=`
|
|
153
|
+
${z.body}`,U.endLine=z.endLine;return}const q={cell:{kind:"markdown",markdown:z.body,id:""},startLine:z.startLine,endLine:z.endLine};W.push(q),U=z.block?void 0:q});const Y={start:0,end:R(X)};let re=X;const ee=W.map(({cell:A,startLine:B,endLine:z},j)=>{let q=B;for(;q-1>re&&w.lines.has(q-1);)q--;return re=z,{...A,span:{start:y.lineStarts[q],end:R(z)},id:String(j)}});for(const A of[Y,...ee.map(B=>B.span)]){const B=w.all.find(z=>z.start<A.start&&z.end>A.start||z.start<A.end&&z.end>A.end);if(B)return M(y.line(B.start),"a comment that straddles a cell","start the comment on its own line.")}return{ok:!0,source:{text:e,header:Y,cells:ee}}}const pb=e=>e.ok===!1,gb=/^[A-Za-z_][A-Za-z0-9_]*$/,Ll=/^query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s+is\s+/,Nl=e=>`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;function Ti(e){let t="",n=0;for(;n<e.length;){const r=e.slice(n,n+2);if(r==="//"||r==="--"){const s=e.indexOf(`
|
|
154
|
+
`,n),i=s<0?e.length:s;t+=" ".repeat(i-n),n=i}else if(r==="/*"){const s=e.indexOf("*/",n+2),i=s<0?e.length:s+2;t+=e.slice(n,i).replace(/[^\n]/g," "),n=i}else if(e[n]==="'"||e[n]==='"'||e[n]==="`"){const s=e[n];let i=n+1;for(;i<e.length&&e[i]!==s;)i+=e[i]==="\\"?2:1;const o=Math.min(i,e.length);t+=s+e.slice(n+1,o).replace(/[^\n]/g," "),o<e.length&&(t+=s),n=o+1}else t+=e[n],n++}return t}function Fl(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const s=e[r];s==="{"||s==="("||s==="["?n++:s==="}"||s===")"||s==="]"?n--:n===0&&s==="-"&&e[r+1]===">"&&t.push(r)}return t}function zl(e,t,n){let r=e;for(const s of[...n].sort((i,o)=>o.start-i.start))r=r.slice(0,s.start-t)+r.slice(s.end-t);return r}function Wl(e,t){const n=t.split(`
|
|
155
155
|
`).map(r=>r.startsWith("|##")?` ${r}`:r).join(`
|
|
156
156
|
`);return`##|(markdown) ${e}
|
|
157
157
|
${n===""?"":`${n}
|
|
158
158
|
`}|##
|
|
159
|
-
`}function
|
|
160
|
-
`),o=me.artifactTag(i);if(o&&!me.artifactLeads(o.text))return s(o.from,me.ARTIFACT_NOT_FIRST);if(!o||
|
|
161
|
-
`),b=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),_
|
|
162
|
-
`,1)[0])),...
|
|
163
|
-
`:" ";F=`${
|
|
164
|
-
`).join("");
|
|
165
|
-
`}if(P.kind==="definition"){const
|
|
166
|
-
`).filter(
|
|
167
|
-
`)].filter(
|
|
168
|
-
`).map((
|
|
169
|
-
`);
|
|
170
|
-
`)),R.add(
|
|
159
|
+
`}function mb(e){return e.trim()===""?"":/^\s*(#|\/\/|--|\/\*)/.test(e)?` ${e.trimStart()}`:` ${e}`}function vb(e){const t=(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),n=t.length>40?t.lastIndexOf("_",40):t.length,r=t.slice(0,n>0?n:40);return/^[a-z]/.test(r)&&me.isBareName(r)?r:void 0}async function bb(e){const t=await hb(e);if(cb(t))return{ok:!1,refused:t.refused,line:t.line};const{header:n,cells:r}=t.source,s=($,P)=>({ok:!1,refused:`Line ${$+1}: ${P}`,line:$+1}),i=e.slice(n.start,n.end).split(`
|
|
160
|
+
`),o=me.artifactTag(i);if(o&&!me.artifactLeads(o.text))return s(o.from,me.ARTIFACT_NOT_FIRST);if(!o||ka(o.text))return s(Math.max(o?.from??0,0),"this notebook already lists its tiles, so there is nothing to convert.");const l=(await Js(e,"file:///publisher-notebook-builder/convert.malloy")).parse?.tokenStream,u=l?.tokenSource?.vocabulary,d=l?.getTokens?.()??[];if(typeof u?.getSymbolicName!="function")return s(0,"Malloy's token stream is not available.");const c=await E.loadMalloy(),{parseAnnotation:f}=await E.loadMalloyTag(),p=$=>u.getSymbolicName($.type),h=new xa(e),m=_a(h,l),y=$=>e.slice(h.utf16($.startIndex),h.utf16($.stopIndex+1)),w=$=>c.routeOf({value:$.trimStart()}),v=$=>c.payloadOf({value:$}),g=$=>$.replace(/\r\n?/g,`
|
|
161
|
+
`),b=new Set(e.match(/[A-Za-z_][A-Za-z0-9_]*/g)),_=$=>{let P=$;for(let F=2;b.has(P);F++)P=`${$}_${F}`;return b.add(P),P},O=$=>{const P=d.filter(se=>se.channel===0&&h.utf16(se.startIndex)>=$.span.start&&h.utf16(se.stopIndex+1)<=$.span.end),F=[],V=[],oe=[];let Z;for(let se=0;se<P.length;se++){const L=p(P[se]);if(L!=="ANNOTATION"&&L!=="BLOCK_ANNOTATION_BEGIN"){Z=P[se];break}let te=se;const pe=[];if(L==="BLOCK_ANNOTATION_BEGIN"){for(;p(P[te+1]??P[se])==="BLOCK_ANNOTATION_TEXT";)pe.push(y(P[++te]));p(P[te+1]??P[se])==="BLOCK_ANNOTATION_END"&&te++}const ae=g(y(P[se])),C=w(ae),K=h.utf16(P[se].startIndex),ie=h.lineStarts[h.line(K)],ve={start:/^[ \t]*$/.test(e.slice(ie,K))?ie:K,end:h.utf16(P[te].stopIndex+1)};C==="markdown"?F.push(ve):C==='"'&&(V.push(ve),oe.push(L==="ANNOTATION"?g(v(ae)).replace(/\n$/,"").trim():[g(v(ae.split(`
|
|
162
|
+
`,1)[0])),...pe.map(g)].map(Re=>Re.trim()).filter(Boolean).join(" "))),se=te}if(!Z)return;const ne=h.utf16(Z.startIndex),de=e.slice($.span.start,$.span.end);return{cell:$,above:zl(e.slice($.span.start,ne),$.span.start,($.kind==="query"?[...F,...V]:F).filter(se=>se.end<=ne)),statement:e.slice(ne,$.span.end).trimEnd(),kept:zl(de,$.span.start,F),...$.kind==="query"&&oe.length>0&&{caption:oe.join(" ")},line:h.line(ne)}},I=new Map,M=new Map;for(const[$,P]of r.entries()){if(P.kind==="markdown")continue;const F=O(P);if(!F)return s(h.line(P.span.start),"a cell with no statement the converter can place.");M.set($,F);const V=Ll.exec(F.statement);P.kind==="definition"&&V&&I.set(V[1],{expression:F.statement.slice(V[0].length).trim(),cell:$})}const T=$=>{const P=/^run\s*:\s*/.exec($.statement);if(!P)return s($.line,"a run that is not `run: <query>`.");let F=$.statement.slice(P[0].length).trim();const V=[];for(let se=0;se<10;se++){const L=Ti(F),te=/^[A-Za-z_][A-Za-z0-9_]*/.exec(L)?.[0],pe=te?I.get(te):void 0;if(!te||!pe)break;const ae=F.slice(te.length).trim(),C=L.slice(te.length).trim();if(C!==""&&!C.startsWith("->")&&!C.startsWith("+"))break;if(C.startsWith("+")&&Fl(Ti(pe.expression)).length!==1)return s($.line,`\`${te} + { … }\` refines a query with more than one stage, which cannot become one view.`);V.push(te);const K=/(\/\/|--)[^\n]*$/.test(pe.expression)?`
|
|
163
|
+
`:" ";F=`${pe.expression}${ae===""?"":`${K}${ae}`}`}const oe=Ti(F);if(I.has(/^[A-Za-z_][A-Za-z0-9_]*/.exec(oe)?.[0]??""))return s($.line,"this run names a query defined through more than 10 other queries, which the converter does not follow.");const Z=Fl(oe);if(Z.length===0)return s($.line,"this run is not `source -> view`, so it cannot become a tile. Fix: write it as `run: <source> -> <view>`.");const ne=F.slice(0,Z[0]).trim();if(/\bextend\b/.test(oe.slice(0,Z[0])))return s($.line,"this run extends its source inline before `->`, so it cannot become a tile. Fix: declare the extension with a `source:` statement and run that.");if(!gb.test(ne)&&!/^`[^`]+`$/.test(ne))return s($.line,"the source of this run is not a name, so it cannot become a tile. Fix: name it with a `source:` statement and run that.");const de=F.slice(Z[0]+2).trim();return de===""?s($.line,"this run has nothing after `->`."):{source:ne,body:de,used:V}},D=new Map,N=[],R=new Set,W=new Map;let X=0,G=0;const U=new Map;for(const $ of M.values()){if($.cell.kind!=="query")continue;const P=T($);if("ok"in P)return P;for(const F of P.used)U.set(F,(U.get(F)??0)+1)}const Y=$=>U.get($)===1&&(e.match(new RegExp(`\\b${$}\\b`,"g"))??[]).length===2,re=new Map;for(const[$,P]of r.entries()){if(P.kind==="markdown"){const C=_(`text_${++X}`);N.push(`${C} { kind=text }`);const K=m.all.filter(ie=>ie.start>=P.span.start&&ie.end<=P.span.end).map(ie=>`${e.slice(ie.start,ie.end)}
|
|
164
|
+
`).join("");W.set($,K+Wl(C,P.markdown??""));continue}const F=M.get($);let V="";if(P.markdown!==void 0){const C=_(`text_${++X}`);N.push(`${C} { kind=text }`),V=`${Wl(C,P.markdown)}
|
|
165
|
+
`}if(P.kind==="definition"){const C=Ll.exec(F.statement)?.[1];if(C&&Y(C)){R.add($),re.set(C,F.above.split(`
|
|
166
|
+
`).filter(K=>K.trim()!=="")),V&&W.set($,V.replace(/\n$/,""));continue}W.set($,`${V}${F.kept}`);continue}const oe=T(F),Z=oe.source.replace(/`/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/^(?=[0-9])/,"_");let ne=D.get(oe.source);ne||(ne={name:_(`${Z}_tiles`),base:oe.source,views:[]},D.set(oe.source,ne));const de=[...oe.used.flatMap(C=>re.get(C)??[]),...F.above.split(`
|
|
167
|
+
`)].filter(C=>C.trim()!==""),se=de.filter(C=>/^\s*#(?!["(|])/.test(C)),L=se.length>0?Mu(f,se).tag:void 0,te=_(vb(L?.text("label")??F.caption)??`tile_${G+1}`);G++,N.push(`"${ne.name} -> ${te}"`);const pe=de.map(mb);if(F.caption!==void 0){const C=E.annotationTextProblem("caption",F.caption)===void 0;C&&!L?.has("label")?pe.push(` # label=${Nl(F.caption)}`):C&&!L?.has("subtitle")?pe.push(` # subtitle=${Nl(F.caption)}`):pe.push(` #" ${F.caption}`)}const ae=oe.body.split(`
|
|
168
|
+
`).map((C,K)=>K===0||C.trim()===""?C:` ${C}`).join(`
|
|
169
|
+
`);ne.views.push([...pe,` view: ${te} is ${ae}`].join(`
|
|
170
|
+
`)),R.add($),V&&W.set($,V.replace(/\n$/,""))}const ee=(()=>{let $=0;const P=o.text;for(let F=P.indexOf("{");F<P.length;F++)if(P[F]==='"')for(F++;F<P.length&&P[F]!=='"';F++)P[F]==="\\"&&F++;else if(P[F]==="{")$++;else if(P[F]==="}"&&--$===0)return F;return-1})();if(ee<0)return s(o.from,"the `## artifact { … }` tag never closes.");const A=N.length===0?`
|
|
171
171
|
tiles=[]
|
|
172
172
|
`:`
|
|
173
173
|
tiles=[
|
|
174
|
-
${
|
|
174
|
+
${N.map($=>` ${$}`).join(`,
|
|
175
175
|
`)}
|
|
176
176
|
]
|
|
177
|
-
`,B=`${o.text.slice(0,
|
|
177
|
+
`,B=`${o.text.slice(0,ee).trimEnd().replace(/^##(?!\|)/,"##|")}${A}${o.text.slice(ee)}`;i.splice(o.from,o.block?o.to-o.from:1,...(o.block?B:`${B}
|
|
178
178
|
|##`).split(`
|
|
179
|
-
`));const
|
|
180
|
-
`),F=P.pop(),V=[];let
|
|
181
|
-
`).join("")+F},j={text:"",at:[]},q=(
|
|
182
|
-
`),
|
|
179
|
+
`));const z=$=>{const P=$.text.split(`
|
|
180
|
+
`),F=P.pop(),V=[];let oe=0;for(const Z of P){const ne=$.at[oe]??-1,de=m.all.some(se=>ne>=se.start&&ne<se.end);(Z.trim()!==""||V.at(-1)?.trim()!==""||de)&&V.push(Z),oe+=Z.length+1}return V.map(Z=>`${Z}
|
|
181
|
+
`).join("")+F},j={text:"",at:[]},q=($,P)=>{j.text+=e.slice($,P);for(let F=$;F<P;F++)j.at.push(F)};let J=i.join(`
|
|
182
|
+
`),Q=n.end;for(const[$,P]of r.entries()){q(Q,P.span.start),Q=P.span.end;const F=W.get($);F!==void 0&&(J+=z(j)+(F.endsWith(`
|
|
183
183
|
`)?F:`${F}
|
|
184
|
-
`),j.text="",j.at=[])}q(
|
|
185
|
-
`+(j.text.trim()===""?"":
|
|
186
|
-
`;const H=[...D.values()].map(
|
|
187
|
-
${
|
|
184
|
+
`),j.text="",j.at=[])}q(Q,e.length),J=`${J.trimEnd()}
|
|
185
|
+
`+(j.text.trim()===""?"":z(j)),J=`${J.trimEnd()}
|
|
186
|
+
`;const H=[...D.values()].map($=>`source: ${$.name} is ${$.base} extend {
|
|
187
|
+
${$.views.join(`
|
|
188
188
|
|
|
189
189
|
`)}
|
|
190
190
|
}
|
|
@@ -192,4 +192,4 @@ ${S.views.join(`
|
|
|
192
192
|
${H.join(`
|
|
193
193
|
`)}`),e.includes(`\r
|
|
194
194
|
`)&&(J=J.replace(/\r?\n/g,`\r
|
|
195
|
-
`)),{ok:!0,text:J,tiles:L.length}}const Oi=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function vb(e,t,n=!1){const r=await Tr(e,t,n);if(!$r(r))return{ok:!0,document:r.document};if(!r.legacyNotebook)return{ok:!1,reason:Oi(r.reason,r.line)};const s=await mb(e);if(fb(s))return{ok:!1,reason:Oi(s.refused,s.line)};const i=await Tr(s.text,t,n);return $r(i)?{ok:!1,reason:`The converted notebook cannot be opened: ${Oi(i.reason,i.line)}`}:{ok:!0,document:i.document,conversion:{from:e,to:s.text}}}const zl="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` notebook under notebooks/ to edit it here.",Wl="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function bb({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,notebook:l,noun:u,refusedEvent:c,legacyFormat:d,textHeld:f,startedAt:p,onEventRef:h}){const v=e?.authoritative===!0,y=v&&r!==void 0,[w,g]=k.useState(void 0),m=(v||w===!0)&&t!==void 0,[b,_]=k.useState(void 0),[O,E]=k.useState(d?zl:void 0),I=k.useRef(void 0),T=k.useRef(void 0),[D,L]=k.useState(void 0),R=k.useRef(i);R.current=i;const z=D!==void 0&&D.onFetch===i?D.text:s,K=k.useRef(z);K.current=z;const G=m?t:z,[X,Y]=k.useState(!1),[se,te]=k.useState(void 0),[A,B]=k.useState(void 0),N=G!==void 0&&G!==A,j=b?.source,J=N&&(X||!v&&t!==void 0&&j===t&&t!==z)&&j!==void 0&&G!==se,ee=J?j:N?G:j??G,H=J?G:void 0,S=k.useRef(j);S.current=j;const P=k.useRef(G);P.current=G;const F=k.useRef("package");F.current=m?v?"record":"draft":"package",k.useEffect(()=>{if(ee===void 0||!n||y||ee===S.current)return;let oe=!1;const W=K.current,Q=P.current;return vb(ee,a,f).then(ne=>{if(!oe){if(ne.ok===!1){E(ne.reason),h.current?.({type:c,reason:ne.reason});return}E(void 0),I.current=void 0,T.current=W,L(void 0),te(void 0),B(Q),_(re=>({source:ee,document:ne.document,...ne.conversion?{conversion:ne.conversion}:{},...W!==void 0?{packageText:W}:{},generation:(re?.generation??0)+1})),h.current?.(l||ne.document.kind==="notebook"?{type:"notebook.opened",from:F.current==="package"?"package":"record",cells:ne.document.tiles.length,durationMs:C.now()-p.current}:{type:"dashboard.opened",from:F.current,tiles:ne.document.tiles.length,durationMs:C.now()-p.current})}}).catch(ne=>{if(oe)return;const re=`Could not read the ${u}: ${ne instanceof Error?ne.message:String(ne)}`;E(re),h.current?.({type:c,reason:re})}),()=>{oe=!0}},[ee,a,n,y,l,u,c,f,p,h]),k.useEffect(()=>{d&&h.current?.({type:"notebook.open_refused",reason:zl})},[d,h]),k.useEffect(()=>{!f||!n||b||r!==void 0||(v?t===void 0&&E("the host's storage has no document at this location."):E("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,b,r,v,t]);const V=l&&!f&&!b&&n&&!m&&o&&s===void 0;return k.useEffect(()=>{V&&(E(Wl),h.current?.({type:"notebook.open_refused",reason:Wl}))},[V,h]),{authoritative:v,blockedOnRecord:y,resume:w,setResume:g,fromDraft:m,opened:b,setOpened:_,openError:O,savedHashRef:I,packageBaseRef:T,setWrote:L,fetchedAtRef:R,setDirty:Y,setSeen:B,held:H,choose:oe=>{p.current=C.now(),te(oe?t:z),g(oe)},acceptHeld:()=>{p.current=C.now(),te(H)}}}function yb({storage:e,workspace:t,kind:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:l,queryClient:u,mutable:c,textHeld:d,readFailure:f,authoritative:p,resume:h,setResume:v,setOpened:y,setDraft:w,setOffered:g,setSeen:m,setWrote:b,savedHashRef:_,packageBaseRef:O,fetchedAtRef:E}){const I=t===void 0?void 0:C.locatorFor(n,t.name,s,i,o),T=k.useCallback(async te=>{if(!e||!I)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(I,te),y(A=>A&&{...A,source:te}),w(te),(p||h===!0)&&m(te),p||v(A=>A??!1)},[e,I,p,h,y,w,m,v]),[D,L]=k.useState(void 0),R=k.useCallback(async te=>{const A=await C.expectedHashFor(_.current,O.current);if(A===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",s,i,o,a,r];await C.writePackageFile({apiClients:l,queryClient:u,environmentName:s,packageName:i,modelPath:o,source:te,expectedHash:A,invalidateOnError:[B],afterWrite:async N=>{if(y(j=>j&&{...j,source:te}),b({text:te,onFetch:E.current}),m(te),_.current=N,L(void 0),e&&I)try{await e.deleteDocument(I),w(void 0),g(!1)}catch(j){C.isDocumentNotFound(j)?(w(void 0),g(!1)):L(C.storageErrorMessage(j))}v(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:C.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]},{queryKey:["dashboards"]},{queryKey:["dashboard"]},...r?[{queryKey:[C.encodeResourceUri({environmentName:s,packageName:i,modelPath:o})]}]:[]]})},[l,s,i,o,a,r,e,I,u,_,O,E,y,b,m,w,g,v]),z=t?.writeable===!0,K=c===!0&&!d,{savesTo:G,pinnedPackageSave:X,writer:Y}=C.saveTarget({authoritative:p,mutable:K,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!I&&z&&(!r||p),readFailed:f!==void 0});return{save:Y==="storage"?T:Y==="package"?R:void 0,savesTo:G,writer:Y,pinnedPackageSave:X,takesWrites:K,supersedeFailure:D}}function Qu(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:s="dashboard",path:i,textSource:o}=e,a=s==="notebook",l=o!==void 0,{environmentName:u,packageName:c,versionId:d,namesBoth:f}=C.resolveEditorTarget(e),p="resourceUri"in e?e.dashboard:e.dashboardName,h=a?"notebook":"dashboard",v=a?"notebook.open_refused":"dashboard.open_refused",{apiClients:y,mutable:w,isLoadingStatus:g}=Ke.useServer(),m=af.useQueryClient(),b=k.useRef(C.now()),_=k.useRef(t);_.current=t;const O=k.useRef(n);O.current=n;const E=C.useOptionalDocumentStorage()?.documentStorage,I=a&&/\.malloynb$/i.test(p),T=i??`${s}s/${p}.malloy`,D=C.useQueryWithApiError({queryKey:["dashboard-editor-model",u,c,T,d,a],queryFn:()=>y.models.getModel(u,c,T,d,a?!0:void 0),enabled:f&&!I&&!l}),L=D.data?.data?.sourceText,{workspace:R,draft:z,setDraft:K,draftChecked:G,offered:X,setOffered:Y,readFailure:se}=ob({storage:E,kind:s,notebook:a,environmentName:u,packageName:c,modelPath:T}),{authoritative:te,blockedOnRecord:A,resume:B,setResume:N,fromDraft:j,opened:q,setOpened:J,openError:ee,savedHashRef:H,packageBaseRef:S,setWrote:P,fetchedAtRef:F,setDirty:V,setSeen:ie,held:Z,choose:oe,acceptHeld:W}=bb({workspace:R,draft:z,draftChecked:G,readFailure:se,packageText:L,fetchedAt:D.dataUpdatedAt,packageSettled:D.isSuccess&&!D.isFetching,modelPath:T,notebook:a,noun:h,refusedEvent:v,legacyFormat:I,textHeld:l,startedAt:b,onEventRef:_}),{save:Q,savesTo:ne,writer:re,pinnedPackageSave:ce,takesWrites:pe,supersedeFailure:M}=yb({storage:E,workspace:R,kind:s,notebook:a,environmentName:u,packageName:c,modelPath:T,versionId:d,apiClients:y,queryClient:m,mutable:w,textHeld:l,readFailure:se,authoritative:te,resume:B,setResume:N,setOpened:J,setDraft:K,setOffered:Y,setSeen:ie,setWrote:P,savedHashRef:H,packageBaseRef:S,fetchedAtRef:F}),U=R?.name,de=k.useCallback(vt=>{_.current?.(C.withWorkspace(vt,U))},[U]),ve=k.useCallback(vt=>{V(vt),O.current?.(vt)},[V]),Re=ne==="host"&&R?.description?R.description:void 0,Nn=!te&&!l&&w===void 0?g?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":C.saveCaption({authoritative:te,mutable:pe,pinnedPackageSave:ce,...R?{workspace:R}:{},...se!==void 0?{readFailure:se}:{},...d!==void 0?{versionId:d}:{}}),mt=Nn===Re?"":Nn;if(!f&&"resourceUri"in e)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["A ",h," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(ee)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",h," cannot be opened in the builder: ",ee]});if(D.isError&&!q)return x.jsx(C.ApiErrorDisplay,{error:D.error,context:`Opening the ${h}`});if(!q&&(!(l||L)||!G))return x.jsx(C.Loading,{text:`Opening the ${h}…`});if(A)return x.jsxs($.Alert,{severity:"error",sx:{m:2},children:["This ",h," cannot be opened: ",se]});const Fn=z!==void 0&&z!==L;return x.jsxs($.Stack,{sx:{gap:2},children:[D.isError&&x.jsxs($.Alert,{severity:"warning",children:["The ",h," could not be re-read from the server:"," ",D.error?.message,". Your edits are still here."]}),!a&&!te&&X&&Fn&&B===void 0&&x.jsx($.Alert,{severity:"info",action:x.jsxs($.Stack,{direction:"row",sx:{gap:1},children:[x.jsx($.Button,{size:"small",onClick:()=>oe(!0),children:"Resume"}),x.jsx($.Button,{size:"small",onClick:()=>oe(!1),children:"Start from the package"})]}),children:"You have edits to this dashboard saved in this browser that the package does not have."}),Z!==void 0&&x.jsx($.Alert,{severity:"warning",action:x.jsx($.Button,{size:"small",onClick:W,children:"Load it"}),children:ne==="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.":ne==="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."}),M!==void 0&&x.jsxs($.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:"," ",M]}),q&&x.jsx(ib,{kind:s,environmentName:u,packageName:c,modelPath:T,...o?{textSource:o}:{},slug:p,modelGivens:D.data?.data?.givens,...d!==void 0?{versionId:d}:{},opened:q,...j&&re==="package"&&q.packageText!==void 0?{replaces:q.packageText}:{},onSave:Q,onDirtyChange:ve,...r?{onExit:r}:{},savesTo:ne,...Re?{saveLabel:Re}:{},...t?{onEvent:de}:{},note:mt},q.generation)]})}function xb(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return x.jsx(Qu,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=C.MAX_SLUG_ATTEMPTS;exports.createDocument=C.createDocument;exports.createRoute=C.createRoute;exports.documentPathFor=C.documentPathFor;exports.documentPathForTitle=C.documentPathForTitle;exports.locatorFor=C.locatorFor;exports.newDashboardSource=C.newDashboardSource;exports.newDocumentProblem=C.newDocumentProblem;exports.newNotebookSource=C.newNotebookSource;exports.slugFor=C.slugFor;exports.slugOrFallback=C.slugOrFallback;exports.useDocumentChoices=C.useDocumentChoices;exports.DashboardBuilder=Zu;exports.DashboardEditor=Qu;exports.NotebookEditor=xb;exports.buildCatalog=Vu;exports.readDashboardDocument=Tr;exports.readFailed=$r;exports.spliceDashboardDocument=Wu;exports.spliceFailed=Rs;
|
|
195
|
+
`)),{ok:!0,text:J,tiles:N.length}}const Oi=(e,t)=>t!==void 0&&!/\bline \d+/i.test(e)?`${e} (line ${t})`:e;async function yb(e,t,n=!1){const r=await Tr(e,t,n);if(!$r(r))return{ok:!0,document:r.document};if(!r.legacyNotebook)return{ok:!1,reason:Oi(r.reason,r.line)};const s=await bb(e);if(pb(s))return{ok:!1,reason:Oi(s.refused,s.line)};const i=await Tr(s.text,t,n);return $r(i)?{ok:!1,reason:`The converted notebook cannot be opened: ${Oi(i.reason,i.line)}`}:{ok:!0,document:i.document,conversion:{from:e,to:s.text}}}const Bl="a .malloynb notebook is read, not edited. Fix: rewrite it as a `.malloy` notebook under notebooks/ to edit it here.",Gl="the server did not send this notebook's text, so there is nothing here to edit. Fix: edit the file in the package.";function xb({workspace:e,draft:t,draftChecked:n,readFailure:r,packageText:s,fetchedAt:i,packageSettled:o,modelPath:a,notebook:l,noun:u,refusedEvent:d,legacyFormat:c,textHeld:f,startedAt:p,onEventRef:h}){const m=e?.authoritative===!0,y=m&&r!==void 0,[w,v]=k.useState(void 0),g=(m||w===!0)&&t!==void 0,[b,_]=k.useState(void 0),[O,I]=k.useState(c?Bl:void 0),M=k.useRef(void 0),T=k.useRef(void 0),[D,N]=k.useState(void 0),R=k.useRef(i);R.current=i;const W=D!==void 0&&D.onFetch===i?D.text:s,X=k.useRef(W);X.current=W;const G=g?t:W,[U,Y]=k.useState(!1),[re,ee]=k.useState(void 0),[A,B]=k.useState(void 0),z=G!==void 0&&G!==A,j=b?.source,J=z&&(U||!m&&t!==void 0&&j===t&&t!==W)&&j!==void 0&&G!==re,Q=J?j:z?G:j??G,H=J?G:void 0,$=k.useRef(j);$.current=j;const P=k.useRef(G);P.current=G;const F=k.useRef("package");F.current=g?m?"record":"draft":"package",k.useEffect(()=>{if(Q===void 0||!n||y||Q===$.current)return;let ne=!1;const de=X.current,se=P.current;return yb(Q,a,f).then(L=>{if(!ne){if(L.ok===!1){I(L.reason),h.current?.({type:d,reason:L.reason});return}I(void 0),M.current=void 0,T.current=de,N(void 0),ee(void 0),B(se),_(te=>({source:Q,document:L.document,...L.conversion?{conversion:L.conversion}:{},...de!==void 0?{packageText:de}:{},generation:(te?.generation??0)+1})),h.current?.(l||L.document.kind==="notebook"?{type:"notebook.opened",from:F.current==="package"?"package":"record",cells:L.document.tiles.length,durationMs:E.now()-p.current}:{type:"dashboard.opened",from:F.current,tiles:L.document.tiles.length,durationMs:E.now()-p.current})}}).catch(L=>{if(ne)return;const te=`Could not read the ${u}: ${L instanceof Error?L.message:String(L)}`;I(te),h.current?.({type:d,reason:te})}),()=>{ne=!0}},[Q,a,n,y,l,u,d,f,p,h]),k.useEffect(()=>{c&&h.current?.({type:"notebook.open_refused",reason:Bl})},[c,h]),k.useEffect(()=>{!f||!n||b||r!==void 0||(m?t===void 0&&I("the host's storage has no document at this location."):I("a document held as text needs a storage whose workspace is authoritative. Fix: mark the workspace that keeps it `authoritative`."))},[f,n,b,r,m,t]);const V=l&&!f&&!b&&n&&!g&&o&&s===void 0;return k.useEffect(()=>{V&&(I(Gl),h.current?.({type:"notebook.open_refused",reason:Gl}))},[V,h]),{authoritative:m,blockedOnRecord:y,resume:w,setResume:v,fromDraft:g,opened:b,setOpened:_,openError:O,savedHashRef:M,packageBaseRef:T,setWrote:N,fetchedAtRef:R,setDirty:Y,setSeen:B,held:H,choose:ne=>{p.current=E.now(),ee(ne?t:W),v(ne)},acceptHeld:()=>{p.current=E.now(),ee(H)}}}function wb({storage:e,workspace:t,kind:n,notebook:r,environmentName:s,packageName:i,modelPath:o,versionId:a,apiClients:l,queryClient:u,mutable:d,textHeld:c,readFailure:f,authoritative:p,resume:h,setResume:m,setOpened:y,setDraft:w,setOffered:v,setSeen:g,setWrote:b,savedHashRef:_,packageBaseRef:O,fetchedAtRef:I}){const M=t===void 0?void 0:E.locatorFor(n,t.name,s,i,o),T=k.useCallback(async ee=>{if(!e||!M)throw new Error("This host keeps no documents, so there is nowhere to save.");await e.saveDocument(M,ee),y(A=>A&&{...A,source:ee}),w(ee),(p||h===!0)&&g(ee),p||m(A=>A??!1)},[e,M,p,h,y,w,g,m]),[D,N]=k.useState(void 0),R=k.useCallback(async ee=>{const A=await E.expectedHashFor(_.current,O.current);if(A===void 0)throw new Error("The package file is still loading; try again.");const B=["dashboard-editor-model",s,i,o,a,r];await E.writePackageFile({apiClients:l,queryClient:u,environmentName:s,packageName:i,modelPath:o,source:ee,expectedHash:A,invalidateOnError:[B],afterWrite:async z=>{if(y(j=>j&&{...j,source:ee}),b({text:ee,onFetch:I.current}),g(ee),_.current=z,N(void 0),e&&M)try{await e.deleteDocument(M),w(void 0),v(!1)}catch(j){E.isDocumentNotFound(j)?(w(void 0),v(!1)):N(E.storageErrorMessage(j))}m(!1)},invalidate:[{queryKey:B,wait:!0},{queryKey:E.modelResultsKey({environmentName:s,packageName:i,versionId:a,modelPath:o})},{queryKey:["dashboard-editor-manifest"]},{queryKey:["dashboards"]},{queryKey:["dashboard"]},...r?[{queryKey:[E.encodeResourceUri({environmentName:s,packageName:i,modelPath:o})]}]:[]]})},[l,s,i,o,a,r,e,M,u,_,O,I,y,b,g,w,v,m]),W=t?.writeable===!0,X=d===!0&&!c,{savesTo:G,pinnedPackageSave:U,writer:Y}=E.saveTarget({authoritative:p,mutable:X,...a!==void 0?{versionId:a}:{},canStore:!!e&&!!M&&W&&(!r||p),readFailed:f!==void 0});return{save:Y==="storage"?T:Y==="package"?R:void 0,savesTo:G,writer:Y,pinnedPackageSave:U,takesWrites:X,supersedeFailure:D}}function Ju(e){const{onEvent:t,onDirtyChange:n,onExit:r,kind:s="dashboard",path:i,textSource:o}=e,a=s==="notebook",l=o!==void 0,{environmentName:u,packageName:d,versionId:c,namesBoth:f}=E.resolveEditorTarget(e),p="resourceUri"in e?e.dashboard:e.dashboardName,h=a?"notebook":"dashboard",m=a?"notebook.open_refused":"dashboard.open_refused",{apiClients:y,mutable:w,isLoadingStatus:v}=Ke.useServer(),g=lf.useQueryClient(),b=k.useRef(E.now()),_=k.useRef(t);_.current=t;const O=k.useRef(n);O.current=n;const I=E.useOptionalDocumentStorage()?.documentStorage,M=a&&/\.malloynb$/i.test(p),T=i??`${s}s/${p}.malloy`,D=E.useQueryWithApiError({queryKey:["dashboard-editor-model",u,d,T,c,a],queryFn:()=>y.models.getModel(u,d,T,c,a?!0:void 0),enabled:f&&!M&&!l}),N=D.data?.data?.sourceText,{workspace:R,draft:W,setDraft:X,draftChecked:G,offered:U,setOffered:Y,readFailure:re}=lb({storage:I,kind:s,notebook:a,environmentName:u,packageName:d,modelPath:T}),{authoritative:ee,blockedOnRecord:A,resume:B,setResume:z,fromDraft:j,opened:q,setOpened:J,openError:Q,savedHashRef:H,packageBaseRef:$,setWrote:P,fetchedAtRef:F,setDirty:V,setSeen:oe,held:Z,choose:ne,acceptHeld:de}=xb({workspace:R,draft:W,draftChecked:G,readFailure:re,packageText:N,fetchedAt:D.dataUpdatedAt,packageSettled:D.isSuccess&&!D.isFetching,modelPath:T,notebook:a,noun:h,refusedEvent:m,legacyFormat:M,textHeld:l,startedAt:b,onEventRef:_}),{save:se,savesTo:L,writer:te,pinnedPackageSave:pe,takesWrites:ae,supersedeFailure:C}=wb({storage:I,workspace:R,kind:s,notebook:a,environmentName:u,packageName:d,modelPath:T,versionId:c,apiClients:y,queryClient:g,mutable:w,textHeld:l,readFailure:re,authoritative:ee,resume:B,setResume:z,setOpened:J,setDraft:X,setOffered:Y,setSeen:oe,setWrote:P,savedHashRef:H,packageBaseRef:$,fetchedAtRef:F}),K=R?.name,ie=k.useCallback(vt=>{_.current?.(E.withWorkspace(vt,K))},[K]),ve=k.useCallback(vt=>{V(vt),O.current?.(vt)},[V]),Re=L==="host"&&R?.description?R.description:void 0,Nn=!ee&&!l&&w===void 0?v?"Checking whether this server takes writes.":"This server did not say whether it takes writes, so Save is off.":E.saveCaption({authoritative:ee,mutable:ae,pinnedPackageSave:pe,...R?{workspace:R}:{},...re!==void 0?{readFailure:re}:{},...c!==void 0?{versionId:c}:{}}),mt=Nn===Re?"":Nn;if(!f&&"resourceUri"in e)return x.jsxs(S.Alert,{severity:"error",sx:{m:2},children:["A ",h," resource URI must name an environment and a package. Received: ",e.resourceUri]});if(Q)return x.jsxs(S.Alert,{severity:"error",sx:{m:2},children:["This ",h," cannot be opened in the builder: ",Q]});if(D.isError&&!q)return x.jsx(E.ApiErrorDisplay,{error:D.error,context:`Opening the ${h}`});if(!q&&(!(l||N)||!G))return x.jsx(E.Loading,{text:`Opening the ${h}…`});if(A)return x.jsxs(S.Alert,{severity:"error",sx:{m:2},children:["This ",h," cannot be opened: ",re]});const Fn=W!==void 0&&W!==N;return x.jsxs(S.Stack,{sx:{gap:2},children:[D.isError&&x.jsxs(S.Alert,{severity:"warning",children:["The ",h," could not be re-read from the server:"," ",D.error?.message,". Your edits are still here."]}),!a&&!ee&&U&&Fn&&B===void 0&&x.jsx(S.Alert,{severity:"info",action:x.jsxs(S.Stack,{direction:"row",sx:{gap:1},children:[x.jsx(S.Button,{size:"small",onClick:()=>ne(!0),children:"Resume"}),x.jsx(S.Button,{size:"small",onClick:()=>ne(!1),children:"Start from the package"})]}),children:"You have edits to this dashboard saved in this browser that the package does not have."}),Z!==void 0&&x.jsx(S.Alert,{severity:"warning",action:x.jsx(S.Button,{size:"small",onClick:de,children:"Load it"}),children:L==="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.":L==="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."}),C!==void 0&&x.jsxs(S.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:"," ",C]}),q&&x.jsx(ab,{kind:s,environmentName:u,packageName:d,modelPath:T,...o?{textSource:o}:{},slug:p,modelGivens:D.data?.data?.givens,...c!==void 0?{versionId:c}:{},opened:q,...j&&te==="package"&&q.packageText!==void 0?{replaces:q.packageText}:{},onSave:se,onDirtyChange:ve,...r?{onExit:r}:{},savesTo:L,...Re?{saveLabel:Re}:{},...t?{onEvent:ie}:{},note:mt},q.generation)]})}function _b(e){const{onEvent:t,onDirtyChange:n,onExit:r,path:s}=e,i="resourceUri"in e?{resourceUri:e.resourceUri,dashboard:e.notebook}:{environmentName:e.environmentName,packageName:e.packageName,dashboardName:e.notebookName};return x.jsx(Ju,{...i,kind:"notebook",...t?{onEvent:t}:{},...n?{onDirtyChange:n}:{},...r?{onExit:r}:{},...s!==void 0?{path:s}:{}})}typeof globalThis.process>"u"?globalThis.process={env:{}}:globalThis.process.env===void 0&&(globalThis.process.env={});exports.MAX_SLUG_ATTEMPTS=E.MAX_SLUG_ATTEMPTS;exports.createDocument=E.createDocument;exports.createRoute=E.createRoute;exports.documentPathFor=E.documentPathFor;exports.documentPathForTitle=E.documentPathForTitle;exports.locatorFor=E.locatorFor;exports.newDashboardSource=E.newDashboardSource;exports.newDocumentProblem=E.newDocumentProblem;exports.newNotebookSource=E.newNotebookSource;exports.slugFor=E.slugFor;exports.slugOrFallback=E.slugOrFallback;exports.useDocumentChoices=E.useDocumentChoices;exports.DashboardBuilder=Qu;exports.DashboardEditor=Ju;exports.NotebookEditor=_b;exports.buildCatalog=Hu;exports.readDashboardDocument=Tr;exports.readFailed=$r;exports.spliceDashboardDocument=Gu;exports.spliceFailed=Rs;
|