@devtable/dashboard 10.23.0 → 10.23.1
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/dashboard.es.js +3355 -3336
- package/dist/dashboard.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -51,7 +51,7 @@ Check the top-level render call using <`+V+">.")}return E}}function ku(S,E){{if(
|
|
|
51
51
|
${Gu.map(Wu).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function fr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function gr(e,t){try{return fr(e,t)}catch(n){return console.error(n),n.message}}function Ru({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Tt)}catch(n){return console.error(n),e}}function Yu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Tt)}catch(n){return console.error(n),t}}function Qu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Ku(e,t){let n=Qu(e);return n+="&key="+t,Ia.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ku({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),mt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function Xa(e){qe.baseURL!==e.apiBaseURL&&(qe.baseURL=e.apiBaseURL),e.app_id&&(qe.app_id=e.app_id),e.app_secret&&(qe.app_secret=e.app_secret),e.makeQueryENV&&(qe.makeQueryENV=e.makeQueryENV)}async function Uu({query:e,payload:t},n){if(!e.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=e,c=fr(o,t),d=Ru({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=Yu(u,f),f}async function Xu({type:e,key:t,configString:n},r){return await qe.query(r)({type:e,key:t,query:n},{})}async function mr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function Ja(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class Za{constructor(t){q(this,"rootRef");this.rootRef=re.observable({current:t})}async deleteItem(t){re.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?re.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))re.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else re.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return re.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Aa)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Aa;return this.channels.set(t,r),r}}class Zu{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Ju,instanceData:new Za(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ha(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Za({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Hu=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...Ha(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ec=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...Ha(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},es=(e,t)=>{const n=ct.bezier(e),r=ct.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Cn=e=>{const t=ct.bezier(e);return function(n){return t(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:es(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:es(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:Cn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:Cn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:Cn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:Cn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function dt(e){return new oc(e)}class yr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new yr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ts="10.23.0",lc=Object.freeze(Object.defineProperty({__proto__:null,version:ts},Symbol.toStringTag,{value:"Module"}));class uc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class cc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class dc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class me extends dc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const j=(e,t)=>{const[n,{setFalse:r}]=U.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},br={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function L(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function pc(e){return e.includes(".")?L(e):{queryID:"",columnKey:e}}function pt(e,t){var a;const{queryID:n,columnKey:r}=L(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function Ht(e,t){const{queryID:n}=L(t);return n?e[n]:[]}function hc(e){return Object.values(e)[0]}function Sn(e,t){const{queryID:n,columnKey:r}=L(t);return e[r]}ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Pe.CanvasRenderer]);function fc({context:e}){const{value:t}=j(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,br),h=y.useMemo(()=>Ht(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:L(o),y:L(l),z:L(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const I=x.minBy(h,N=>N[C.columnKey]),B=x.maxBy(h,N=>N[C.columnKey]);return{min:x.get(I,C.columnKey),max:x.get(B,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[C.columnKey]])}]};return t?i(Be,{echarts:ie,option:D,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ns=y.createContext(null),vr=ns.Provider;function xr(){const e=y.useContext(ns);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ye=()=>xr(),wr=()=>xr(),rs=y.createContext(null),Cr=rs.Provider;function is(){const e=y.useContext(rs);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>is(),we=()=>is(),gc={inEditMode:!1},_n=y.createContext(gc),as=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Sr=as.Provider;function ss(){const e=y.useContext(as);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const bt=()=>ss(),nt=()=>ss(),mc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(mc);function os(){const e=y.useContext(_r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=nt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function yc({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),r=x.defaults({},t,br),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(T.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function bc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class vc extends me{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:bc(a,r)}})}}const xc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new vc,name:"bar-3d",viewRender:fc,configRender:yc,createConfig(){return{version:2,config:x.cloneDeep(br)}}};class Fe extends y.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ze={mantissa:0,output:"number",trimMantissa:!1,average:!1};function wc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(T.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(T.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(T.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(wc),Qe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
54
|
+
`;function fr(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(a){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):a}}function gr(e,t){try{return fr(e,t)}catch(n){return console.error(n),n.message}}function Ru({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},Tt)}catch(n){return console.error(n),e}}function Yu(e,t){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,Tt)}catch(n){return console.error(n),t}}function Qu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const a=t[r];if(a!="authentication"&&e[a])n.push(t[r]+"="+(typeof e[a]=="object"?JSON.stringify(e[a]):e[a]));else{const o=Object.keys(e[a]).sort();for(let l=0;l<o.length;l++){const u=o[l];u!="sign"&&e[a][u]&&n.push(o[l]+"="+(typeof e[a][u]=="object"?JSON.stringify(e[a][u]):e[a][u]))}}}return n.sort().join("&")}function Ku(e,t){let n=Qu(e);return n+="&key="+t,Ia.MD5(n).toString().toUpperCase()}const qe={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(e){if(!this.app_id||!this.app_secret)return;const t=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:t,sign:Ku({app_id:this.app_id,nonce_str:t,...e},this.app_secret)}},getRequest(e,t){return(n,r,a={})=>{const o=window.localStorage.getItem("token"),l={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",authorization:o?`bearer ${o}`:"",...a.headers},u={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:a.params,headers:l,signal:t};return["POST","PUT"].includes(e)&&(u.data=a.string?JSON.stringify(r):r,u.data.authentication=this.getAuthentication(u.data)),mt(u).then(c=>c.data).catch(c=>Promise.reject(c))}},makeQueryENV:null,query(e){return async(t,n={})=>{var r;return t.env||(t.env=((r=this.makeQueryENV)==null?void 0:r.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",e)("/query",t,n)}}};function Xa(e){qe.baseURL!==e.apiBaseURL&&(qe.baseURL=e.apiBaseURL),e.app_id&&(qe.app_id=e.app_id),e.app_secret&&(qe.app_secret=e.app_secret),e.makeQueryENV&&(qe.makeQueryENV=e.makeQueryENV)}async function Uu({query:e,payload:t},n){if(!e.sql)return[];const{type:r,key:a,sql:o,pre_process:l,post_process:u}=e,c=fr(o,t),d=Ru({sql:c,pre_process:l});let f=await qe.query(n)({type:r,key:a,query:d},{});return f=Yu(u,f),f}async function Xu({type:e,key:t,configString:n},r){return await qe.query(r)({type:e,key:t,query:n},{})}async function mr(){try{return(await qe.getRequest("POST")("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}})).data}catch(e){return console.error(e),[]}}async function Ja(){try{return(await qe.getRequest("POST")("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}})).data}catch(e){return console.error(e),[]}}class Za{constructor(t){q(this,"rootRef");this.rootRef=re.observable({current:t})}async deleteItem(t){re.runInAction(()=>{x.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?re.toJS(this.rootRef.current):x.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(x.isObject(n))re.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else re.runInAction(()=>{x.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return re.reaction(()=>this.getValueFromRoot(t),(a,o)=>{n(a,o)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Ju{constructor(){q(this,"channels",new Map);q(this,"globalChannel",new Aa)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Aa;return this.channels.set(t,r),r}}class Zu{constructor(t){q(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Ju,instanceData:new Za(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ha(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Za({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Hu=e=>{const{panel:t,vizManager:n,data:r,variables:a}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),u={...Ha(l,r,n,a),viewport:{width:t.layout.w,height:t.layout.h}},c=o.viewRender;return i(c,{context:u,instance:l,...x.omit(e,["panel","vizManager","data"])})},ec=e=>{const{vizManager:t,panel:n,panelInfoEditor:r,data:a,variables:o}=e,l=t.resolveComponent(n.viz.type),u=t.getOrCreateInstance(n),c={...Ha(u,a,t,o),panelInfoEditor:r},d=l.configRender;return i(d,{context:c,instance:u,...x.omit(e,["panel","vizManager","data","panelInfoEditor"])})},es=(e,t)=>{const n=ct.bezier(e),r=ct.bezier(t);return function(a){return a<50?n(a*2/100).hex():r((a-50)*2/100).hex()}},Cn=e=>{const t=ct.bezier(e);return function(n){return t(n/100).hex()}},tc={type:"interpolation",displayName:"Red / Green",getColor:es(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},nc={type:"interpolation",displayName:"Yellow / Blue",getColor:es(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},rc={type:"interpolation",displayName:"Red",getColor:Cn(["#fff7f1","darkred"]),name:"red",category:"sequential"},ic={type:"interpolation",displayName:"Green",getColor:Cn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},ac={type:"interpolation",displayName:"Blue",getColor:Cn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},sc={type:"interpolation",displayName:"Orange",getColor:Cn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class oc{constructor(t){q(this,"symbol");this.symbol=Symbol(t)}}function dt(e){return new oc(e)}class yr{constructor(){q(this,"parent");q(this,"factoryRegistry",new Map);q(this,"instanceRegistry",new Map)}createScoped(){const t=new yr;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=x.get(t,"dispose");x.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const ts="10.23.1",lc=Object.freeze(Object.defineProperty({__proto__:null,version:ts},Symbol.toStringTag,{value:"Module"}));class uc{constructor(t){q(this,"staticColors",new Map);q(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class cc{constructor(){q(this,"plugins",new Map);q(this,"vizComponents",new Map);q(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class dc{constructor(){q(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const a=this.migrations.filter(u=>u.version>t.from&&u.version<=t.to),o=x.orderBy(a,"version","asc");if(((l=x.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((u,c)=>c.handler(u,r),n)}}class me extends dc{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,a)=>({version:t,...n(r,a)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),a=x.get(r,"version",0),o=this.run({from:a,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return x.get(n,"version",0)<this.VERSION}}const j=(e,t)=>{const[n,{setFalse:r}]=U.useBoolean(!0),[a,o]=y.useState();y.useEffect(()=>(e.getItem(t).then(u=>{o(u),r()}),e.watchItem(t,u=>{o(u)})));const l=y.useCallback(async u=>{await e.setItem(t,u),o(u)},[e,t]);return{loading:n,value:a,set:l}},br={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};function L(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function pc(e){return e.includes(".")?L(e):{queryID:"",columnKey:e}}function pt(e,t){var a;const{queryID:n,columnKey:r}=L(t);return n?r?((a=e[n])==null?void 0:a.map(o=>o[r]))??[]:e[n]:[]}function Ht(e,t){const{queryID:n}=L(t);return n?e[n]:[]}function hc(e){return Object.values(e)[0]}function Sn(e,t){const{queryID:n,columnKey:r}=L(t);return e[r]}ie.use([F.GridComponent,F.VisualMapComponent,F.LegendComponent,F.TooltipComponent,Pe.CanvasRenderer]);function fc({context:e}){const{value:t}=j(e.instanceData,"config"),n=e.data,{width:r,height:a}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:u,xAxis3D:c,yAxis3D:d,zAxis3D:f}=x.defaults({},t,br),h=y.useMemo(()=>Ht(n,o),[n,o]),{x:g,y:m,z:C}=y.useMemo(()=>({x:L(o),y:L(l),z:L(u)}),[o,l,u]),{min:w,max:_}=y.useMemo(()=>{const I=x.minBy(h,N=>N[C.columnKey]),B=x.maxBy(h,N=>N[C.columnKey]);return{min:x.get(I,C.columnKey),max:x.get(B,C.columnKey)}},[h,C]),D={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:_,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:c,yAxis3D:d,zAxis3D:f,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(I=>[I[g.columnKey],I[m.columnKey],I[C.columnKey]])}]};return t?i(Be,{echarts:ie,option:D,style:{width:r,height:a},notMerge:!0,theme:"merico-light"}):null}const ns=y.createContext(null),vr=ns.Provider;function xr(){const e=y.useContext(ns);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const ye=()=>xr(),wr=()=>xr(),rs=y.createContext(null),Cr=rs.Provider;function is(){const e=y.useContext(rs);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const le=()=>is(),we=()=>is(),gc={inEditMode:!1},_n=y.createContext(gc),as=y.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Sr=as.Provider;function ss(){const e=y.useContext(as);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const bt=()=>ss(),nt=()=>ss(),mc={fullScreenPanelID:"",setFullScreenPanelID:x.noop},_r=y.createContext(mc);function os(){const e=y.useContext(_r);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const W=k.observer(y.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:a=!1,sx:o,...l},u)=>{const{panel:c}=nt(),d=y.useMemo(()=>{const f=[...c.dataFieldOptions];return a&&f.unshift({label:"unset",value:"",group:""}),f},[c.dataFieldOptions]);return i(s.Select,{ref:u,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function yc({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),r=x.defaults({},t,br),{control:a,handleSubmit:o,reset:l}=v.useForm({defaultValues:r});return y.useEffect(()=>{l(r)},[t]),t?i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:o(n),children:[i(s.Text,{children:"X Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"x_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"xAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Y Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"y_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"yAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Text,{mt:"lg",children:"Z Axis"}),p(s.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[i(v.Controller,{name:"z_axis_data_key",control:a,render:({field:u})=>i(W,{label:"Data Field",required:!0,...u})}),i(v.Controller,{name:"zAxis3D.name",control:a,render:({field:u})=>i(s.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...u})})]}),i(s.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:p(s.Button,{color:"blue",type:"submit",children:[i(T.DeviceFloppy,{size:20}),i(s.Text,{ml:"md",children:"Save"})]})})]})}):null}function bc(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis_data_key:a,y_axis_data_key:o,z_axis_data_key:l,...u}=e;return{...u,x_axis_data_key:r(a),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class vc extends me{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:a}=n;return{...n,version:2,config:bc(a,r)}})}}const xc={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new vc,name:"bar-3d",viewRender:fc,configRender:yc,createConfig(){return{version:2,config:x.cloneDeep(br)}}};class Fe extends y.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return p(s.Box,{children:[i(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),i(s.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const ze={mantissa:0,output:"number",trimMantissa:!1,average:!1};function wc({value:e,onChange:t},n){const r=u=>{t({...e,output:u})},a=u=>{const c=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:c})},o=u=>{t({...e,trimMantissa:u.currentTarget.checked})},l=u=>{t({...e,average:u.currentTarget.checked})};return p(s.Stack,{ref:n,children:[p(s.Group,{grow:!0,children:[i(s.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),i(s.Switch,{label:p(s.Stack,{spacing:0,children:[i(s.Text,{children:"Average"}),i(s.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}}})]}),p(s.Group,{grow:!0,children:[i(s.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:a}),i(s.Switch,{label:"Trim mantissa",checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:{root:{alignSelf:"flex-end"},body:{alignItems:"center"}}})]}),p(s.Stack,{spacing:0,children:[i(s.Text,{weight:"bold",children:"Preview"}),i(Fe,{children:p(s.Group,{position:"apart",children:[p(s.Text,{size:12,color:"gray",children:["123456789 ",i(T.ArrowRight,{size:9})," ",Z(123456789).format(e)]}),p(s.Text,{size:12,color:"gray",children:["1234 ",i(T.ArrowRight,{size:9})," ",Z(1234).format(e)]}),p(s.Text,{size:12,color:"gray",children:["0.1234 ",i(T.ArrowRight,{size:9})," ",Z(.1234).format(e)]})]})})]})]})}const We=y.forwardRef(wc),Qe={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
55
|
`)},ls={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Sc,configRender:Cc,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Cc(e){return i(P,{})}function Sc(e){return i(s.Text,{children:"Click chart's series"})}const _c=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],kn=y.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const a=o=>l=>{const u=x.cloneDeep(t);x.set(u,o,l),n(u)};return p(s.Stack,{spacing:0,children:[e&&i(s.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:a("width")}),i(s.Select,{label:"Overflow",data:_c,value:t.overflow,onChange:a("overflow")}),i(s.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),at=y.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},a=o=>{t({...e,in_tooltip:o})};return p(s.Stack,{ref:n,spacing:0,children:[i(kn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),i(kn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:a})]})}),je={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function st({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",a={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
|
|
56
56
|
max-width: ${t}px;
|
|
57
57
|
word-break: ${n};
|
|
@@ -102,7 +102,7 @@ Check the top-level render call using <`+V+">.")}return E}}function ku(S,E){{if(
|
|
|
102
102
|
`))}ignoreFallback(t){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(t){let n=Re.none,r=Re.none;for(let a=0;a<t.length;a+=2)for(let o=void 0;;){let l=this.parser.matchStyle(t[a],t[a+1],this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{l.clearMark(u)&&(r=u.addToSet(r))}):n=this.parser.schema.marks[l.mark].create(l.attrs).addToSet(n),l.consuming===!1)o=l;else break}return[n,r]}addElementByRule(t,n,r){let a,o,l;n.node?(o=this.parser.schema.nodes[n.node],o.isLeaf?this.insertNode(o.create(n.attrs))||this.leafFallback(t):a=this.enter(o,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let u=this.top;if(o&&o.isLeaf)this.findInside(t);else if(r)this.addElement(t,r);else if(n.getContent)this.findInside(t),n.getContent(t,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=t;typeof n.contentElement=="string"?c=t.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(t):n.contentElement&&(c=n.contentElement),this.findAround(t,c,!0),this.addAll(c)}a&&this.sync(u)&&this.open--,l&&this.removePendingMark(l,u)}addAll(t,n,r){let a=n||0;for(let o=n?t.childNodes[n]:t.firstChild,l=r==null?null:t.childNodes[r];o!=l;o=o.nextSibling,++a)this.findAtPoint(t,a),this.addDOM(o);this.findAtPoint(t,a)}findPlace(t){let n,r;for(let a=this.open;a>=0;a--){let o=this.nodes[a],l=o.findWrapping(t);if(l&&(!n||n.length>l.length)&&(n=l,r=o,!l.length)||o.solid)break}if(!n)return!1;this.sync(r);for(let a=0;a<n.length;a++)this.enterInner(n[a],null,!1);return!0}insertNode(t){if(t.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(t)){this.closeExtra();let n=this.top;n.applyPending(t.type),n.match&&(n.match=n.match.matchType(t.type));let r=n.activeMarks;for(let a=0;a<t.marks.length;a++)(!n.type||n.type.allowsMarkType(t.marks[a].type))&&(r=t.marks[a].addToSet(r));return n.content.push(t.mark(r)),!0}return!1}enter(t,n,r){let a=this.findPlace(t.create(n));return a&&this.enterInner(t,n,!0,r),a}enterInner(t,n=null,r=!1,a){this.closeExtra();let o=this.top;o.applyPending(t),o.match=o.match&&o.match.matchType(t);let l=ys(t,a,o.options);o.options&tn&&o.content.length==0&&(l|=tn),this.nodes.push(new zn(t,n,o.activeMarks,o.pendingMarks,r,null,l)),this.open++}closeExtra(t=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(t){for(let n=this.open;n>=0;n--)if(this.nodes[n]==t)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let a=r.length-1;a>=0;a--)t+=r[a].nodeSize;n&&t++}return t}findAtPoint(t,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==t&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&t.nodeType==1&&t.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(t,n,r){if(t!=n&&this.find)for(let a=0;a<this.find.length;a++)this.find[a].pos==null&&t.nodeType==1&&t.contains(this.find[a].node)&&n.compareDocumentPosition(this.find[a].node)&(r?2:4)&&(this.find[a].pos=this.currentPos)}findInText(t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&(this.find[n].pos=this.currentPos-(t.nodeValue.length-this.find[n].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let n=t.split("/"),r=this.options.context,a=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(a?0:1),l=(u,c)=>{for(;u>=0;u--){let d=n[u];if(d==""){if(u==n.length-1||u==0)continue;for(;c>=o;c--)if(l(u-1,c))return!0;return!1}else{let f=c>0||c==0&&a?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!f||f.name!=d&&f.groups.indexOf(d)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(t){let n=Md(t,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=t.addToSet(this.top.pendingMarks)}removePendingMark(t,n){for(let r=this.open;r>=0;r--){let a=this.nodes[r];if(a.pendingMarks.lastIndexOf(t)>-1)a.pendingMarks=t.removeFromSet(a.pendingMarks);else{a.activeMarks=t.removeFromSet(a.activeMarks);let l=a.popFromStashMark(t);l&&a.type&&a.type.allowsMarkType(l.type)&&(a.activeMarks=l.addToSet(a.activeMarks))}if(a==n)break}}}function _d(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let r=t.nodeType==1?t.nodeName.toLowerCase():null;r&&ms.hasOwnProperty(r)&&n?(n.appendChild(t),t=n):r=="li"?n=t:r&&(n=null)}}function kd(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Td(e){let t=/\s*([\w-]+)\s*:\s*([^;]+)/g,n,r=[];for(;n=t.exec(e);)r.push(n[1],n[2].trim());return r}function vs(e){let t={};for(let n in e)t[n]=e[n];return t}function Dd(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],l=u=>{o.push(u);for(let c=0;c<u.edgeCount;c++){let{type:d,next:f}=u.edge(c);if(d==t||o.indexOf(f)<0&&l(f))return!0}};if(l(a.contentMatch))return!0}}function Md(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}const xs=65535,ws=Math.pow(2,16);function Id(e,t){return e+t*ws}function Cs(e){return e&xs}function Ad(e){return(e-(e&xs))/ws}const Ss=1,_s=2,En=4,ks=8;class Ts{constructor(t,n,r){this.pos=t,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&ks)>0}get deletedBefore(){return(this.delInfo&(Ss|En))>0}get deletedAfter(){return(this.delInfo&(_s|En))>0}get deletedAcross(){return(this.delInfo&En)>0}}class Xe{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&Xe.empty)return Xe.empty}recover(t){let n=0,r=Cs(t);if(!this.inverted)for(let a=0;a<r;a++)n+=this.ranges[a*3+2]-this.ranges[a*3+1];return this.ranges[r*3]+n+Ad(t)}mapResult(t,n=1){return this._map(t,n,!1)}map(t,n=1){return this._map(t,n,!0)}_map(t,n,r){let a=0,o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?a:0);if(c>t)break;let d=this.ranges[u+o],f=this.ranges[u+l],h=c+d;if(t<=h){let g=d?t==c?-1:t==h?1:n:n,m=c+a+(g<0?0:f);if(r)return m;let C=t==(n<0?c:h)?null:Id(u/3,t-c),w=t==c?_s:t==h?Ss:En;return(n<0?t!=c:t!=h)&&(w|=ks),new Ts(m,w,C)}a+=f-d}return r?t+a:new Ts(t+a,0,null)}touches(t,n){let r=0,a=Cs(n),o=this.inverted?2:1,l=this.inverted?1:2;for(let u=0;u<this.ranges.length;u+=3){let c=this.ranges[u]-(this.inverted?r:0);if(c>t)break;let d=this.ranges[u+o],f=c+d;if(t<=f&&u==a*3)return!0;r+=this.ranges[u+l]-d}return!1}forEach(t){let n=this.inverted?2:1,r=this.inverted?1:2;for(let a=0,o=0;a<this.ranges.length;a+=3){let l=this.ranges[a],u=l-(this.inverted?o:0),c=l+(this.inverted?0:o),d=this.ranges[a+n],f=this.ranges[a+r];t(u,u+d,c,c+f),o+=f-d}}invert(){return new Xe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?Xe.empty:new Xe(t<0?[0,-t,0]:[0,0,t])}}Xe.empty=new Xe([]);const Er=Object.create(null);class Ge{getMap(){return Xe.empty}merge(t){return null}static fromJSON(t,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Er[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Er)throw new RangeError("Duplicate use of step JSON ID "+t);return Er[t]=n,n.prototype.jsonID=t,n}}class Te{constructor(t,n){this.doc=t,this.failed=n}static ok(t){return new Te(t,null)}static fail(t){return new Te(null,t)}static fromReplace(t,n,r,a){try{return Te.ok(t.replace(n,r,a))}catch(o){if(o instanceof Cd)return Te.fail(o.message);throw o}}}function $r(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy($r(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return ae.fromArray(r)}class Mt extends Ge{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=t.resolve(this.from),a=r.node(r.sharedDepth(this.to)),o=new ce($r(n.content,(l,u)=>!l.isAtom||!u.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),a),n.openStart,n.openEnd);return Te.fromReplace(t,this.from,this.to,o)}invert(){return new It(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Mt(n.pos,r.pos,this.mark)}merge(t){return t instanceof Mt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Mt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Mt(n.from,n.to,t.markFromJSON(n.mark))}}Ge.jsonID("addMark",Mt);class It extends Ge{constructor(t,n,r){super(),this.from=t,this.to=n,this.mark=r}apply(t){let n=t.slice(this.from,this.to),r=new ce($r(n.content,a=>a.mark(this.mark.removeFromSet(a.marks)),t),n.openStart,n.openEnd);return Te.fromReplace(t,this.from,this.to,r)}invert(){return new Mt(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new It(n.pos,r.pos,this.mark)}merge(t){return t instanceof It&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new It(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new It(n.from,n.to,t.markFromJSON(n.mark))}}Ge.jsonID("removeMark",It);class At extends Ge{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Te.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Te.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let a=0;a<n.marks.length;a++)if(!n.marks[a].isInSet(r))return new At(this.pos,n.marks[a]);return new At(this.pos,this.mark)}}return new nn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new At(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new At(n.pos,t.markFromJSON(n.mark))}}Ge.jsonID("addNodeMark",At);class nn extends Ge{constructor(t,n){super(),this.pos=t,this.mark=n}apply(t){let n=t.nodeAt(this.pos);if(!n)return Te.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Te.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(r),0,n.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new At(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new nn(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new nn(n.pos,t.markFromJSON(n.mark))}}Ge.jsonID("removeNodeMark",nn);class ot extends Ge{constructor(t,n,r,a=!1){super(),this.from=t,this.to=n,this.slice=r,this.structure=a}apply(t){return this.structure&&Lr(t,this.from,this.to)?Te.fail("Structure replace would overwrite content"):Te.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new Xe([this.from,this.to-this.from,this.slice.size])}invert(t){return new ot(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new ot(n.pos,Math.max(n.pos,r.pos),this.slice)}merge(t){if(!(t instanceof ot)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new ot(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?ce.empty:new ce(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new ot(t.from,this.to,n,this.structure)}else return null}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new ot(n.from,n.to,ce.fromJSON(t,n.slice),!!n.structure)}}Ge.jsonID("replace",ot);class zt extends Ge{constructor(t,n,r,a,o,l,u=!1){super(),this.from=t,this.to=n,this.gapFrom=r,this.gapTo=a,this.slice=o,this.insert=l,this.structure=u}apply(t){if(this.structure&&(Lr(t,this.from,this.gapFrom)||Lr(t,this.gapTo,this.to)))return Te.fail("Structure gap-replace would overwrite content");let n=t.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Te.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Te.fromReplace(t,this.from,this.to,r):Te.fail("Content does not fit in gap")}getMap(){return new Xe([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new zt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=t.map(this.gapFrom,-1),o=t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new zt(n.pos,r.pos,a,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new zt(n.from,n.to,n.gapFrom,n.gapTo,ce.fromJSON(t,n.slice),n.insert,!!n.structure)}}Ge.jsonID("replaceAround",zt);function Lr(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let l=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!l||l.isLeaf)return!0;l=l.firstChild,a--}}return!1}function zd(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Ed(e){let n=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let r=e.depth;;--r){let a=e.$from.node(r),o=e.$from.index(r),l=e.$to.indexAfter(r);if(r<e.depth&&a.canReplace(o,l,n))return r;if(r==0||a.type.spec.isolating||!zd(a,o,l))break}return null}function $n(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,l=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!l.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let d=a.depth-1,f=n-2;d>o;d--,f--){let h=a.node(d),g=a.index(d);if(h.type.spec.isolating)return!1;let m=h.content.cutByIndex(g,h.childCount),C=r&&r[f+1];C&&(m=m.replaceChild(0,C.type.create(C.attrs)));let w=r&&r[f]||h;if(!h.canReplace(g+1,h.childCount)||!w.type.validContent(m))return!1}let u=a.indexAfter(o),c=r&&r[0];return a.node(o).canReplaceWith(u,u,c?c.type:a.node(o+1).type)}function Ds(e,t){let n=e.resolve(t),r=n.index();return $d(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function $d(e,t){return!!(e&&t&&!e.isLeaf&&e.canAppend(t))}class rn extends Ge{constructor(t,n,r){super(),this.pos=t,this.attr=n,this.value=r}apply(t){let n=t.nodeAt(this.pos);if(!n)return Te.fail("No node at attribute step's position");let r=Object.create(null);for(let o in n.attrs)r[o]=n.attrs[o];r[this.attr]=this.value;let a=n.type.create(r,null,n.marks);return Te.fromReplace(t,this.pos,this.pos+1,new ce(ae.from(a),0,n.isLeaf?0:1))}getMap(){return Xe.empty}invert(t){return new rn(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new rn(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new rn(n.pos,n.attr,n.value)}}Ge.jsonID("attr",rn);let an=class extends Error{};an=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},an.prototype=Object.create(Error.prototype),an.prototype.constructor=an,an.prototype.name="TransformError";const Or=Object.create(null);class he{constructor(t,n,r){this.$anchor=t,this.$head=n,this.ranges=r||[new Ld(t.min(n),t.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let n=0;n<t.length;n++)if(t[n].$from.pos!=t[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,n=ce.empty){let r=n.content.lastChild,a=null;for(let u=0;u<n.openEnd;u++)a=r,r=r.lastChild;let o=t.steps.length,l=this.ranges;for(let u=0;u<l.length;u++){let{$from:c,$to:d}=l[u],f=t.mapping.slice(o);t.replaceRange(f.map(c.pos),f.map(d.pos),u?ce.empty:n),u==0&&As(t,o,(r?r.isInline:a&&a.isTextblock)?-1:1)}}replaceWith(t,n){let r=t.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:l,$to:u}=a[o],c=t.mapping.slice(r),d=c.map(l.pos),f=c.map(u.pos);o?t.deleteRange(d,f):(t.replaceRangeWith(d,f,n),As(t,r,n.isInline?-1:1))}}static findFrom(t,n,r=!1){let a=t.parent.inlineContent?new De(t):Bt(t.node(0),t.parent,t.pos,t.index(),n,r);if(a)return a;for(let o=t.depth-1;o>=0;o--){let l=n<0?Bt(t.node(0),t.node(o),t.before(o+1),t.index(o),n,r):Bt(t.node(0),t.node(o),t.after(o+1),t.index(o)+1,n,r);if(l)return l}return null}static near(t,n=1){return this.findFrom(t,n)||this.findFrom(t,-n)||new ht(t.node(0))}static atStart(t){return Bt(t,t,0,0,1)||new ht(t)}static atEnd(t){return Bt(t,t,t.content.size,t.childCount,-1)||new ht(t)}static fromJSON(t,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Or[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(t,n)}static jsonID(t,n){if(t in Or)throw new RangeError("Duplicate use of selection JSON ID "+t);return Or[t]=n,n.prototype.jsonID=t,n}getBookmark(){return De.between(this.$anchor,this.$head).getBookmark()}}he.prototype.visible=!0;class Ld{constructor(t,n){this.$from=t,this.$to=n}}let Ms=!1;function Is(e){!Ms&&!e.parent.inlineContent&&(Ms=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class De extends he{constructor(t,n=t){Is(t),Is(n),super(t,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return he.near(r);let a=t.resolve(n.map(this.anchor));return new De(a.parent.inlineContent?a:r,r)}replace(t,n=ce.empty){if(super.replace(t,n),n==ce.empty){let r=this.$from.marksAcross(this.$to);r&&t.ensureMarks(r)}}eq(t){return t instanceof De&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Ln(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new De(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){let a=t.resolve(n);return new this(a,r==n?a:t.resolve(r))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let o=he.findFrom(n,r,!0)||he.findFrom(n,-r,!0);if(o)n=o.$head;else return he.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(he.findFrom(t,-r,!0)||he.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new De(t,n)}}he.jsonID("text",De);class Ln{constructor(t,n){this.anchor=t,this.head=n}map(t){return new Ln(t.map(this.anchor),t.map(this.head))}resolve(t){return De.between(t.resolve(this.anchor),t.resolve(this.head))}}class Ye extends he{constructor(t){let n=t.nodeAfter,r=t.node(0).resolve(t.pos+n.nodeSize);super(t,r),this.node=n}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?he.near(o):new Ye(o)}content(){return new ce(ae.from(this.node),0,0)}eq(t){return t instanceof Ye&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Pr(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Ye(t.resolve(n.anchor))}static create(t,n){return new Ye(t.resolve(n))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==!1}}Ye.prototype.visible=!1,he.jsonID("node",Ye);class Pr{constructor(t){this.anchor=t}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Ln(r,r):new Pr(r)}resolve(t){let n=t.resolve(this.anchor),r=n.nodeAfter;return r&&Ye.isSelectable(r)?new Ye(n):he.near(n)}}class ht extends he{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,n=ce.empty){if(n==ce.empty){t.delete(0,t.doc.content.size);let r=he.atStart(t.doc);r.eq(t.selection)||t.setSelection(r)}else super.replace(t,n)}toJSON(){return{type:"all"}}static fromJSON(t){return new ht(t)}map(t){return new ht(t)}eq(t){return t instanceof ht}getBookmark(){return Od}}he.jsonID("all",ht);const Od={map(){return this},resolve(e){return new ht(e)}};function Bt(e,t,n,r,a,o=!1){if(t.inlineContent)return De.create(e,n);for(let l=r-(a>0?0:1);a>0?l<t.childCount:l>=0;l+=a){let u=t.child(l);if(u.isAtom){if(!o&&Ye.isSelectable(u))return Ye.create(e,n-(a<0?u.nodeSize:0))}else{let c=Bt(e,u,n+a,a<0?u.childCount:0,a,o);if(c)return c}n+=u.nodeSize*a}return null}function As(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof ot||a instanceof zt))return;let o=e.mapping.maps[r],l;o.forEach((u,c,d,f)=>{l==null&&(l=f)}),e.setSelection(he.near(e.doc.resolve(l),n))}function zs(e,t){return!t||!e?e:e.bind(t)}class On{constructor(t,n,r){this.name=t,this.init=zs(n.init,r),this.apply=zs(n.apply,r)}}new On("doc",{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new On("selection",{init(e,t){return e.selection||he.atStart(t.doc)},apply(e){return e.selection}}),new On("storedMarks",{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new On("scrollToSelection",{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}});function Es(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r=="handleDOMEvents"&&(a=Es(a,t,{})),n[r]=a}return n}class sn{constructor(t){this.spec=t,this.props={},t.props&&Es(t.props,this,this.props),this.key=t.key?t.key.key:$s("plugin")}getState(t){return t[this.key]}}const Br=Object.create(null);function $s(e){return e in Br?e+"$"+ ++Br[e]:(Br[e]=0,e+"$")}class on{constructor(t="key"){this.key=$s(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}function Ls(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:a}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return a},get tr(){return r=n.selection,a=n.doc,o=n.storedMarks,n}}}class Pd{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:r}=this,{view:a}=n,{tr:o}=r,l=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([u,c])=>[u,(...f)=>{const h=c(...f)(l);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(o),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a,u=[],c=!!t,d=t||o.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&l.dispatch(d),u.every(g=>g===!0)),h={...Object.fromEntries(Object.entries(r).map(([g,m])=>[g,(...w)=>{const _=this.buildProps(d,n),D=m(...w)(_);return u.push(D),h}])),run:f};return h}createCan(t){const{rawCommands:n,state:r}=this,a=!1,o=t||r.tr,l=this.buildProps(o,a);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...l,dispatch:void 0})])),chain:()=>this.createChain(o,a)}}buildProps(t,n=!0){const{rawCommands:r,editor:a,state:o}=this,{view:l}=a;o.storedMarks&&t.setStoredMarks(o.storedMarks);const u={tr:t,editor:a,view:l,state:Ls({state:o,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(u)]))}};return u}}function vt(e,t,n){return e.config[t]===void 0&&e.parent?vt(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?vt(e.parent,t,n):null}):e.config[t]}function Bd(e){const t=e.filter(a=>a.type==="extension"),n=e.filter(a=>a.type==="node"),r=e.filter(a=>a.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:r}}function Le(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function Vd(e){return typeof e=="function"}function Vt(e,t=void 0,...n){return Vd(e)?t?e.bind(t)(...n):e(...n):e}function Nd(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function qd(e){return Object.prototype.toString.call(e).slice(8,-1)}function Vr(e){return qd(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Os(e,t){const n={...e};return Vr(e)&&Vr(t)&&Object.keys(t).forEach(r=>{Vr(t[r])?r in e?n[r]=Os(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}class lt{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=Vt(vt(this,"addOptions",{name:this.name}))),this.storage=Vt(vt(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new lt(t)}configure(t={}){const n=this.extend();return n.options=Os(this.options,t),n.storage=Vt(vt(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new lt(t);return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=Vt(vt(n,"addOptions",{name:n.name})),n.storage=Vt(vt(n,"addStorage",{name:n.name,options:n.options})),n}}function Fd(e,t,n){const{from:r,to:a}=t,{blockSeparator:o=`
|
|
103
103
|
|
|
104
104
|
`,textSerializers:l={}}=n||{};let u="",c=!0;return e.nodesBetween(r,a,(d,f,h,g)=>{var m;const C=l==null?void 0:l[d.type.name];C?(d.isBlock&&!c&&(u+=o,c=!0),h&&(u+=C({node:d,pos:f,parent:h,index:g,range:t}))):d.isText?(u+=(m=d==null?void 0:d.text)===null||m===void 0?void 0:m.slice(Math.max(r,f)-f,a-f),c=!1):d.isBlock&&!c&&(u+=o,c=!0)}),u}function Gd(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}lt.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new sn({key:new on("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:a}=t,{ranges:o}=a,l=Math.min(...o.map(f=>f.$from.pos)),u=Math.max(...o.map(f=>f.$to.pos)),c=Gd(n);return Fd(r,{from:l,to:u},{textSerializers:c})}}})]}});const Wd=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),jd=(e=!1)=>({commands:t})=>t.setContent("",e),Rd=()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:a}=r;return n&&a.forEach(({$from:o,$to:l})=>{e.doc.nodesBetween(o.pos,l.pos,(u,c)=>{if(u.type.isText)return;const{doc:d,mapping:f}=t,h=d.resolve(f.map(c)),g=d.resolve(f.map(c+u.nodeSize)),m=h.blockRange(g);if(!m)return;const C=Ed(m);if(u.type.isTextblock){const{defaultType:w}=h.parent.contentMatchAt(h.index());t.setNodeMarkup(m.start,w)}(C||C===0)&&t.lift(m,C)})}),!0},Yd=e=>t=>e(t),Qd=()=>({state:e,dispatch:t})=>Ie.createParagraphNear(e,t),Kd=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const a=e.selection.$anchor;for(let o=a.depth;o>0;o-=1)if(a.node(o).type===r.type){if(t){const u=a.before(o),c=a.after(o);e.delete(u,c).scrollIntoView()}return!0}return!1},Ud=e=>({tr:t,state:n,dispatch:r})=>{const a=Le(e,n.schema),o=t.selection.$anchor;for(let l=o.depth;l>0;l-=1)if(o.node(l).type===a){if(r){const c=o.before(l),d=o.after(l);t.delete(c,d).scrollIntoView()}return!0}return!1},Xd=e=>({tr:t,dispatch:n})=>{const{from:r,to:a}=e;return n&&t.delete(r,a),!0},Jd=()=>({state:e,dispatch:t})=>Ie.deleteSelection(e,t),Zd=()=>({commands:e})=>e.keyboardShortcut("Enter"),Hd=()=>({state:e,dispatch:t})=>Ie.exitCode(e,t);function Pn(e,t,n={strict:!0}){const r=Object.keys(t);return r.length?r.every(a=>n.strict?t[a]===e[a]:Nd(t[a])?t[a].test(e[a]):t[a]===e[a]):!0}function Nr(e,t,n={}){return e.find(r=>r.type===t&&Pn(r.attrs,n))}function ep(e,t,n={}){return!!Nr(e,t,n)}function Ps(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&r.offset!==0&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const a=Nr([...r.node.marks],t,n);if(!a)return;let o=r.index,l=e.start()+r.offset,u=o+1,c=l+r.node.nodeSize;for(Nr([...r.node.marks],t,n);o>0&&a.isInSet(e.parent.child(o-1).marks);)o-=1,l-=e.parent.child(o).nodeSize;for(;u<e.parent.childCount&&ep([...e.parent.child(u).marks],t,n);)c+=e.parent.child(u).nodeSize,u+=1;return{from:l,to:c}}function xt(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const tp=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const o=xt(e,r.schema),{doc:l,selection:u}=n,{$from:c,from:d,to:f}=u;if(a){const h=Ps(c,o,t);if(h&&h.from<=d&&h.to>=f){const g=De.create(l,h.from,h.to);n.setSelection(g)}}return!0},np=e=>t=>{const n=typeof e=="function"?e(t):e;for(let r=0;r<n.length;r+=1)if(n[r](t))return!0;return!1};function Bs(e){return e instanceof De}function Et(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function rp(e,t=null){if(!t)return null;const n=he.atStart(e),r=he.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return r;const a=n.from,o=r.to;return t==="all"?De.create(e,Et(0,a,o),Et(e.content.size,a,o)):De.create(e,Et(t,a,o),Et(t,a,o))}function qr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ip=(e=null,t={})=>({editor:n,view:r,tr:a,dispatch:o})=>{t={scrollIntoView:!0,...t};const l=()=>{qr()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&e===null||e===!1)return!0;if(o&&e===null&&!Bs(n.state.selection))return l(),!0;const u=rp(a.doc,e)||n.state.selection,c=n.state.selection.eq(u);return o&&(c||a.setSelection(u),c&&a.storedMarks&&a.setStoredMarks(a.storedMarks),l()),!0},ap=(e,t)=>n=>e.every((r,a)=>t(r,{...n,index:a})),sp=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t);function Vs(e){const t=`<body>${e}</body>`;return new window.DOMParser().parseFromString(t,"text/html").body}function Bn(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?ae.fromArray(e.map(r=>t.nodeFromJSON(r))):t.nodeFromJSON(e)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),Bn("",t,n)}if(typeof e=="string"){const r=Mn.fromSchema(t);return n.slice?r.parseSlice(Vs(e),n.parseOptions).content:r.parse(Vs(e),n.parseOptions)}return Bn("",t,n)}function op(e,t,n){const r=e.steps.length-1;if(r<t)return;const a=e.steps[r];if(!(a instanceof ot||a instanceof zt))return;const o=e.mapping.maps[r];let l=0;o.forEach((u,c,d,f)=>{l===0&&(l=f)}),e.setSelection(he.near(e.doc.resolve(l),n))}const lp=e=>e.toString().startsWith("<"),up=(e,t,n)=>({tr:r,dispatch:a,editor:o})=>{if(a){n={parseOptions:{},updateSelection:!0,...n};const l=Bn(t,o.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(l.toString()==="<>")return!0;let{from:u,to:c}=typeof e=="number"?{from:e,to:e}:e,d=!0,f=!0;if((lp(l)?l:[l]).forEach(g=>{g.check(),d=d?g.isText&&g.marks.length===0:!1,f=f?g.isBlock:!1}),u===c&&f){const{parent:g}=r.doc.resolve(u);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(u-=1,c+=1)}d?Array.isArray(t)?r.insertText(t.map(g=>g.text||"").join(""),u,c):typeof t=="object"&&t&&t.text?r.insertText(t.text,u,c):r.insertText(t,u,c):r.replaceWith(u,c,l),n.updateSelection&&op(r,r.steps.length-1,-1)}return!0},cp=()=>({state:e,dispatch:t})=>Ie.joinUp(e,t),dp=()=>({state:e,dispatch:t})=>Ie.joinDown(e,t),pp=()=>({state:e,dispatch:t})=>Ie.joinBackward(e,t),hp=()=>({state:e,dispatch:t})=>Ie.joinForward(e,t);function Ns(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function fp(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let r,a,o,l;for(let u=0;u<t.length-1;u+=1){const c=t[u];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))a=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))qr()||Ns()?l=!0:a=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),a&&(n=`Ctrl-${n}`),l&&(n=`Meta-${n}`),o&&(n=`Shift-${n}`),n}const gp=e=>({editor:t,view:n,tr:r,dispatch:a})=>{const o=fp(e).split(/-(?!$)/),l=o.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),u=new KeyboardEvent("keydown",{key:l==="Space"?" ":l,altKey:o.includes("Alt"),ctrlKey:o.includes("Ctrl"),metaKey:o.includes("Meta"),shiftKey:o.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,u))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&a&&r.maybeStep(f)}),!0};function Fr(e,t,n={}){const{from:r,to:a,empty:o}=e.selection,l=t?Le(t,e.schema):null,u=[];e.doc.nodesBetween(r,a,(h,g)=>{if(h.isText)return;const m=Math.max(r,g),C=Math.min(a,g+h.nodeSize);u.push({node:h,from:m,to:C})});const c=a-r,d=u.filter(h=>l?l.name===h.node.type.name:!0).filter(h=>Pn(h.node.attrs,n,{strict:!1}));return o?!!d.length:d.reduce((h,g)=>h+g.to-g.from,0)>=c}const mp=(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return Fr(n,a,t)?Ie.lift(n,r):!1},yp=()=>({state:e,dispatch:t})=>Ie.liftEmptyBlock(e,t),bp=e=>({state:t,dispatch:n})=>{const r=Le(e,t.schema);return pr.liftListItem(r)(t,n)},vp=()=>({state:e,dispatch:t})=>Ie.newlineInCode(e,t);function qs(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function Fs(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((r,a)=>(n.includes(a)||(r[a]=e[a]),r),{})}const xp=(e,t)=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=qs(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Le(e,r.schema)),u==="mark"&&(l=xt(e,r.schema)),a&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{o&&o===d.type&&n.setNodeMarkup(f,void 0,Fs(d.attrs,t)),l&&d.marks.length&&d.marks.forEach(h=>{l===h.type&&n.addMark(f,f+d.nodeSize,l.create(Fs(h.attrs,t)))})})}),!0):!1},wp=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Cp=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),Sp=()=>({state:e,dispatch:t})=>Ie.selectNodeBackward(e,t),_p=()=>({state:e,dispatch:t})=>Ie.selectNodeForward(e,t),kp=()=>({state:e,dispatch:t})=>Ie.selectParentNode(e,t),Tp=()=>({state:e,dispatch:t})=>Ie.selectTextblockEnd(e,t),Dp=()=>({state:e,dispatch:t})=>Ie.selectTextblockStart(e,t);function Mp(e,t,n={}){return Bn(e,t,{slice:!1,parseOptions:n})}const Ip=(e,t=!1,n={})=>({tr:r,editor:a,dispatch:o})=>{const{doc:l}=r,u=Mp(e,a.schema,n);return o&&r.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!t),!0};function Ap(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function zp(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Gr(e){return t=>zp(t.$from,e)}function Ep(e,t){const n=xt(t,e.schema),{from:r,to:a,empty:o}=e.selection,l=[];o?(e.storedMarks&&l.push(...e.storedMarks),l.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,a,c=>{l.push(...c.marks)});const u=l.find(c=>c.type.name===n.name);return u?{...u.attrs}:{}}function Vn(e,t,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const a=e.find(o=>o.type===t&&o.name===r);return a?a.attribute.keepOnSplit:!1}))}function $p(e,t,n={}){const{empty:r,ranges:a}=e.selection,o=t?xt(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(h=>o?o.name===h.type.name:!0).find(h=>Pn(h.attrs,n,{strict:!1}));let l=0;const u=[];if(a.forEach(({$from:h,$to:g})=>{const m=h.pos,C=g.pos;e.doc.nodesBetween(m,C,(w,_)=>{if(!w.isText&&!w.marks.length)return;const D=Math.max(m,_),I=Math.min(C,_+w.nodeSize),B=I-D;l+=B,u.push(...w.marks.map(N=>({mark:N,from:D,to:I})))})}),l===0)return!1;const c=u.filter(h=>o?o.name===h.mark.type.name:!0).filter(h=>Pn(h.mark.attrs,n,{strict:!1})).reduce((h,g)=>h+g.to-g.from,0),d=u.filter(h=>o?h.mark.type!==o&&h.mark.type.excludes(o):!0).reduce((h,g)=>h+g.to-g.from,0);return(c>0?c+d:c)>=l}function Gs(e,t){const{nodeExtensions:n}=Bd(t),r=n.find(l=>l.name===e);if(!r)return!1;const a={name:r.name,options:r.options,storage:r.storage},o=Vt(vt(r,"group",a));return typeof o!="string"?!1:o.split(" ").includes("list")}function Lp(e,t,n){var r;const{selection:a}=t;let o=null;if(Bs(a)&&(o=a.$cursor),o){const u=(r=e.storedMarks)!==null&&r!==void 0?r:o.marks();return!!n.isInSet(u)||!u.some(c=>c.type.excludes(n))}const{ranges:l}=a;return l.some(({$from:u,$to:c})=>{let d=u.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(u.pos,c.pos,(f,h,g)=>{if(d)return!1;if(f.isInline){const m=!g||g.type.allowsMarkType(n),C=!!n.isInSet(f.marks)||!f.marks.some(w=>w.type.excludes(n));d=m&&C}return!d}),d})}const Op=(e,t={})=>({tr:n,state:r,dispatch:a})=>{const{selection:o}=n,{empty:l,ranges:u}=o,c=xt(e,r.schema);if(a)if(l){const d=Ep(r,c);n.addStoredMark(c.create({...d,...t}))}else u.forEach(d=>{const f=d.$from.pos,h=d.$to.pos;r.doc.nodesBetween(f,h,(g,m)=>{const C=Math.max(m,f),w=Math.min(m+g.nodeSize,h);g.marks.find(D=>D.type===c)?g.marks.forEach(D=>{c===D.type&&n.addMark(C,w,c.create({...D.attrs,...t}))}):n.addMark(C,w,c.create(t))})});return Lp(r,n,c)},Pp=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Bp=(e,t={})=>({state:n,dispatch:r,chain:a})=>{const o=Le(e,n.schema);return o.isTextblock?a().command(({commands:l})=>Ie.setBlockType(o,t)(n)?!0:l.clearNodes()).command(({state:l})=>Ie.setBlockType(o,t)(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Vp=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,a=Et(e,0,r.content.size),o=Ye.create(r,a);t.setSelection(o)}return!0},Np=e=>({tr:t,dispatch:n})=>{if(n){const{doc:r}=t,{from:a,to:o}=typeof e=="number"?{from:e,to:e}:e,l=De.atStart(r).from,u=De.atEnd(r).to,c=Et(a,l,u),d=Et(o,l,u),f=De.create(r,c,d);t.setSelection(f)}return!0},qp=e=>({state:t,dispatch:n})=>{const r=Le(e,t.schema);return pr.sinkListItem(r)(t,n)};function Ws(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter(a=>t==null?void 0:t.includes(a.type.name));e.tr.ensureMarks(r)}}const Fp=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:a})=>{const{selection:o,doc:l}=t,{$from:u,$to:c}=o,d=a.extensionManager.attributes,f=Vn(d,u.node().type.name,u.node().attrs);if(o instanceof Ye&&o.node.isBlock)return!u.parentOffset||!$n(l,u.pos)?!1:(r&&(e&&Ws(n,a.extensionManager.splittableMarks),t.split(u.pos).scrollIntoView()),!0);if(!u.parent.isBlock)return!1;if(r){const h=c.parentOffset===c.parent.content.size;o instanceof De&&t.deleteSelection();const g=u.depth===0?void 0:Ap(u.node(-1).contentMatchAt(u.indexAfter(-1)));let m=h&&g?[{type:g,attrs:f}]:void 0,C=$n(t.doc,t.mapping.map(u.pos),1,m);if(!m&&!C&&$n(t.doc,t.mapping.map(u.pos),1,g?[{type:g}]:void 0)&&(C=!0,m=g?[{type:g,attrs:f}]:void 0),C&&(t.split(t.mapping.map(u.pos),1,m),g&&!h&&!u.parentOffset&&u.parent.type!==g)){const w=t.mapping.map(u.before()),_=t.doc.resolve(w);u.node(-1).canReplaceWith(_.index(),_.index()+1,g)&&t.setNodeMarkup(t.mapping.map(u.before()),g)}e&&Ws(n,a.extensionManager.splittableMarks),t.scrollIntoView()}return!0},Gp=e=>({tr:t,state:n,dispatch:r,editor:a})=>{var o;const l=Le(e,n.schema),{$from:u,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||u.depth<2||!u.sameParent(c))return!1;const f=u.node(-1);if(f.type!==l)return!1;const h=a.extensionManager.attributes;if(u.parent.content.size===0&&u.node(-1).childCount===u.indexAfter(-1)){if(u.depth===2||u.node(-3).type!==l||u.index(-2)!==u.node(-2).childCount-1)return!1;if(r){let _=ae.empty;const D=u.index(-1)?1:u.index(-2)?2:3;for(let A=u.depth-D;A>=u.depth-3;A-=1)_=ae.from(u.node(A).copy(_));const I=u.indexAfter(-1)<u.node(-2).childCount?1:u.indexAfter(-2)<u.node(-3).childCount?2:3,B=Vn(h,u.node().type.name,u.node().attrs),N=((o=l.contentMatch.defaultType)===null||o===void 0?void 0:o.createAndFill(B))||void 0;_=_.append(ae.from(l.createAndFill(null,N)||void 0));const O=u.before(u.depth-(D-1));t.replace(O,u.after(-I),new ce(_,4-D,0));let z=-1;t.doc.nodesBetween(O,t.doc.content.size,(A,G)=>{if(z>-1)return!1;A.isTextblock&&A.content.size===0&&(z=G+1)}),z>-1&&t.setSelection(De.near(t.doc.resolve(z))),t.scrollIntoView()}return!0}const g=c.pos===u.end()?f.contentMatchAt(0).defaultType:null,m=Vn(h,f.type.name,f.attrs),C=Vn(h,u.node().type.name,u.node().attrs);t.delete(u.pos,c.pos);const w=g?[{type:l,attrs:m},{type:g,attrs:C}]:[{type:l,attrs:m}];if(!$n(t.doc,u.pos,2))return!1;if(r){const{selection:_,storedMarks:D}=n,{splittableMarks:I}=a.extensionManager,B=D||_.$to.parentOffset&&_.$from.marks();if(t.split(u.pos,2,w).scrollIntoView(),!B||!r)return!0;const N=B.filter(O=>I.includes(O.type.name));t.ensureMarks(N)}return!0},Wr=(e,t)=>{const n=Gr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Ds(e.doc,n.pos)&&e.join(n.pos),!0},jr=(e,t)=>{const n=Gr(l=>l.type===t)(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const a=e.doc.nodeAt(r);return n.node.type===(a==null?void 0:a.type)&&Ds(e.doc,r)&&e.join(r),!0};var Wp=Object.freeze({__proto__:null,blur:Wd,clearContent:jd,clearNodes:Rd,command:Yd,createParagraphNear:Qd,deleteCurrentNode:Kd,deleteNode:Ud,deleteRange:Xd,deleteSelection:Jd,enter:Zd,exitCode:Hd,extendMarkRange:tp,first:np,focus:ip,forEach:ap,insertContent:sp,insertContentAt:up,joinUp:cp,joinDown:dp,joinBackward:pp,joinForward:hp,keyboardShortcut:gp,lift:mp,liftEmptyBlock:yp,liftListItem:bp,newlineInCode:vp,resetAttributes:xp,scrollIntoView:wp,selectAll:Cp,selectNodeBackward:Sp,selectNodeForward:_p,selectParentNode:kp,selectTextblockEnd:Tp,selectTextblockStart:Dp,setContent:Ip,setMark:Op,setMeta:Pp,setNode:Bp,setNodeSelection:Vp,setTextSelection:Np,sinkListItem:qp,splitBlock:Fp,splitListItem:Gp,toggleList:(e,t,n,r={})=>({editor:a,tr:o,state:l,dispatch:u,chain:c,commands:d,can:f})=>{const{extensions:h,splittableMarks:g}=a.extensionManager,m=Le(e,l.schema),C=Le(t,l.schema),{selection:w,storedMarks:_}=l,{$from:D,$to:I}=w,B=D.blockRange(I),N=_||w.$to.parentOffset&&w.$from.marks();if(!B)return!1;const O=Gr(z=>Gs(z.type.name,h))(w);if(B.depth>=1&&O&&B.depth-O.depth<=1){if(O.node.type===m)return d.liftListItem(C);if(Gs(O.node.type.name,h)&&m.validContent(O.node.content)&&u)return c().command(()=>(o.setNodeMarkup(O.pos,m),!0)).command(()=>Wr(o,m)).command(()=>jr(o,m)).run()}return!n||!N||!u?c().command(()=>f().wrapInList(m,r)?!0:d.clearNodes()).wrapInList(m,r).command(()=>Wr(o,m)).command(()=>jr(o,m)).run():c().command(()=>{const z=f().wrapInList(m,r),A=N.filter(G=>g.includes(G.type.name));return o.ensureMarks(A),z?!0:d.clearNodes()}).wrapInList(m,r).command(()=>Wr(o,m)).command(()=>jr(o,m)).run()},toggleMark:(e,t={},n={})=>({state:r,commands:a})=>{const{extendEmptyMarkRange:o=!1}=n,l=xt(e,r.schema);return $p(r,l,t)?a.unsetMark(l,{extendEmptyMarkRange:o}):a.setMark(l,t)},toggleNode:(e,t,n={})=>({state:r,commands:a})=>{const o=Le(e,r.schema),l=Le(t,r.schema);return Fr(r,o,n)?a.setNode(l):a.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const a=Le(e,n.schema);return Fr(n,a,t)?r.lift(a):r.wrapIn(a,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const a=n[r];let o;if(a.spec.isInputRules&&(o=a.getState(e))){if(t){const l=e.tr,u=o.transform;for(let c=u.steps.length-1;c>=0;c-=1)l.step(u.steps[c].invert(u.docs[c]));if(o.text){const c=l.doc.resolve(o.from).marks();l.replaceWith(o.from,o.to,e.schema.text(o.text,c))}else l.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:a}=n;return r||t&&a.forEach(o=>{e.removeMark(o.$from.pos,o.$to.pos)}),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:a})=>{var o;const{extendEmptyMarkRange:l=!1}=t,{selection:u}=n,c=xt(e,r.schema),{$from:d,empty:f,ranges:h}=u;if(!a)return!0;if(f&&l){let{from:g,to:m}=u;const C=(o=d.marks().find(_=>_.type===c))===null||o===void 0?void 0:o.attrs,w=Ps(d,c,C);w&&(g=w.from,m=w.to),n.removeMark(g,m,c)}else h.forEach(g=>{n.removeMark(g.$from.pos,g.$to.pos,c)});return n.removeStoredMark(c),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:a})=>{let o=null,l=null;const u=qs(typeof e=="string"?e:e.name,r.schema);return u?(u==="node"&&(o=Le(e,r.schema)),u==="mark"&&(l=xt(e,r.schema)),a&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(h,g)=>{o&&o===h.type&&n.setNodeMarkup(g,void 0,{...h.attrs,...t}),l&&h.marks.length&&h.marks.forEach(m=>{if(l===m.type){const C=Math.max(g,d),w=Math.min(g+h.nodeSize,f);n.addMark(C,w,l.create({...m.attrs,...t}))}})})}),!0):!1},wrapIn:(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return Ie.wrapIn(a,t)(n,r)},wrapInList:(e,t={})=>({state:n,dispatch:r})=>{const a=Le(e,n.schema);return pr.wrapInList(a,t)(n,r)}});lt.create({name:"commands",addCommands(){return{...Wp}}}),lt.create({name:"editable",addProseMirrorPlugins(){return[new sn({key:new on("editable"),props:{editable:()=>this.editor.options.editable}})]}}),lt.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new sn({key:new on("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),lt.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:l})=>[()=>l.undoInputRule(),()=>l.command(({tr:u})=>{const{selection:c,doc:d}=u,{empty:f,$anchor:h}=c,{pos:g,parent:m}=h,C=he.atStart(d).from===g;return!f||!C||!m.type.isTextblock||m.textContent.length?!1:l.clearNodes()}),()=>l.deleteSelection(),()=>l.joinBackward(),()=>l.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:l})=>[()=>l.deleteSelection(),()=>l.deleteCurrentNode(),()=>l.joinForward(),()=>l.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:l})=>[()=>l.newlineInCode(),()=>l.createParagraphNear(),()=>l.liftEmptyBlock(),()=>l.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},a={...r},o={...r,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return qr()||Ns()?o:a},addProseMirrorPlugins(){return[new sn({key:new on("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(C=>C.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:a,from:o,to:l}=t.selection,u=he.atStart(t.doc).from,c=he.atEnd(t.doc).to;if(a||!(o===u&&l===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const h=n.tr,g=Ls({state:n,transaction:h}),{commands:m}=new Pd({editor:this.editor,state:g});if(m.clearNodes(),!!h.steps.length)return h}})]}}),lt.create({name:"tabindex",addProseMirrorPlugins(){return[new sn({key:new on("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});const js=lt.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),jp=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),Rp=[{label:"auto",value:""}].concat(jp.map(e=>({label:e,value:e}))),Yp={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},Qp=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return i(J.RichTextEditor.ControlsGroup,{children:i(s.NativeSelect,{size:"xs",icon:i($.IconTextSize,{stroke:1.5,size:16}),data:Rp,styles:Yp,value:t||"",onChange:n=>{const r=n.currentTarget.value;r?e.chain().focus().setFontSize(r).run():e.chain().focus().unsetFontSize().run()}})})},Nn=({value:e,styles:t={}})=>{const n=Wa.useEditor({extensions:[ja,Ga,J.Link,Oa,La,Ea,Va.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),Fa,qa,Na,Pa.configure({types:["heading","paragraph"]}),$a.configure({placeholder:"This is placeholder"}),Ba,za.Color,js],content:e,editable:!1});y.useEffect(()=>{n==null||n.commands.setContent(e)},[e,n]);const r=y.useMemo(()=>x.defaultsDeep({},{content:Ir},t),[t]);return i(J.RichTextEditor,{editor:n,styles:r,children:i(J.RichTextEditor.Content,{})})};function Kp(){const[e,{open:t,close:n}]=Me.useDisclosure(!1);return p(P,{children:[i(s.Modal,{opened:e,onClose:n,title:"About FunctionUtils",zIndex:330,withinPortal:!0,children:i(Nn,{value:ju,styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),i(s.Button,{variant:"light",color:"violet",size:"xs",onClick:t,leftIcon:i($.IconInfoCircle,{size:16}),children:"About parameter 'utils'"})]})}const Up=({value:e,onChange:t})=>{const n=r=>{r&&t(r)};return i(s.Box,{sx:{position:"relative",flexGrow:1},children:i(Ae,{className:"function-editor",height:"100%",defaultLanguage:"javascript",value:e,onChange:n,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}}})})},ln=y.forwardRef(({value:e,onChange:t,label:n,defaultValue:r},a)=>{const[o,l]=y.useState(e),u=()=>{t(o)},c=()=>{l(e)},d=()=>{l(r)};y.useEffect(()=>{l(e)},[e]);const f=o!==e;return p(s.Stack,{spacing:4,sx:{height:"100%"},children:[p(s.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[i(s.Group,{position:"left",children:i(Kp,{})}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:d,size:"xs",variant:"default",leftIcon:i($.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),i(s.Button,{onClick:c,color:"red",size:"xs",disabled:!f,leftIcon:i($.IconRecycle,{size:16}),children:"Revert Changes"}),i(s.Button,{size:"xs",onClick:u,disabled:!f,leftIcon:i($.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),i(s.Text,{size:14,children:n}),i(Up,{value:o,onChange:l})]})}),Xp=y.forwardRef(({value:e,onChange:t,label:n,triggerLabel:r="Edit",triggerButtonProps:a={},defaultValue:o},l)=>{const[u,{open:c,close:d}]=Me.useDisclosure(!1);return p(P,{children:[i(s.Modal,{opened:u,onClose:d,title:"Authentication",withinPortal:!0,zIndex:320,size:"900px",children:i(s.Box,{h:600,children:i(ln,{value:e,onChange:t,defaultValue:o,label:n})})}),i(s.Button,{onClick:c,...a,children:r})]})}),Rs=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
105
|
-
`),Nt={type:"none",config:{}};function Jp(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function Zp(e){const t=Number(e);return isFinite(t)?t:0}function Hp(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return Jp(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return Ut.quantile(e,t.config.p)??0;case"CV":const n=wn.std(...e),r=wn.mean(...e);return r?n/r:"N/A";case"std":return wn.std(...e);default:return e}}function Rr(e,t){const n=e.map(Zp);return Hp(n,t)}function eh(e,t,n){try{const r=Ht(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},Tt)}catch(r){return console.error(r),r.message}}function qn(e,t,n){try{return n.type==="custom"?eh(e,t,n):Rr(pt(e,t),n)}catch(r){return console.error(r),null}}const th=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"},{label:"Custom",value:"custom"}];function nh({label:e,value:t,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof t=="string"&&n({type:t,config:{}})},[t,n]);const o=c=>{n(c==="quantile"?{type:"quantile",config:{p:.99}}:c==="custom"?{type:"custom",config:{func:Rs}}:{type:c,config:{}})},l=c=>{n({type:"quantile",config:{p:c}})},u=c=>{n({type:"custom",config:{func:c}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:e,data:th,value:t.type,onChange:o}),t.type==="quantile"&&i(s.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&i(Xp,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:Rs,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:i($.IconMathFunction,{size:16})}})]})}const Fn=y.forwardRef(nh);function rh({label:e,value:t,onChange:n},r){const[a,o]=y.useState(Array.isArray(t)?[...t]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,t),[a,t]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(P,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(m,1,C),[...w]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const ih=y.forwardRef(rh);function ah({value:e,onChange:t},n){const{colorManager:r}=y.useContext(ut),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===e),[e,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Ve=y.forwardRef(ah),Gn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function sh({label:e,value:t,onChange:n},r){var l;const[a,o]=y.useState(((l=Gn.find(u=>u.label===t))==null?void 0:l.value)??Gn[0].value);return y.useEffect(()=>{const u=Gn.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:e}),i(s.Slider,{label:null,marks:Gn,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const Ys=y.forwardRef(sh);function oh({label:e,value:t,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(t)?[...t]:[]),u=y.useCallback(()=>{l(h=>[...h,""])},[l]),c=y.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(P,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const C=m.currentTarget.value;l(w=>(w.splice(g,1,C),[...w]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const lh=y.forwardRef(oh),Qs=y.forwardRef(function({value:t,onChange:n},r){const a=t.color.type,o=(
|
|
105
|
+
`),Nt={type:"none",config:{}};function Jp(e){const t=Array.from(e).sort((r,a)=>r-a),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function Zp(e){const t=Number(e);return isFinite(t)?t:0}function Hp(e,t){switch(t.type){case"sum":return x.sum(e);case"mean":return x.mean(e);case"median":return Jp(e);case"max":return x.max(e)??0;case"min":return x.min(e)??0;case"quantile":return Ut.quantile(e,t.config.p)??0;case"CV":const n=wn.std(...e),r=wn.mean(...e);return r?n/r:"N/A";case"std":return wn.std(...e);default:return e}}function Rr(e,t){const n=e.map(Zp);return Hp(n,t)}function eh(e,t,n){try{const r=Ht(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},Tt)}catch(r){return console.error(r),r.message}}function qn(e,t,n){try{return n.type==="custom"?eh(e,t,n):Rr(pt(e,t),n)}catch(r){return console.error(r),null}}const th=[{label:"None",value:"none"},{label:"Sum",value:"sum"},{label:"Mean",value:"mean"},{label:"Median",value:"median"},{label:"Max",value:"max"},{label:"Min",value:"min"},{label:"Coefficient of Variation",value:"CV"},{label:"Standard Variation",value:"std"},{label:"Quantile(99%, 95%, ...)",value:"quantile"},{label:"Custom",value:"custom"}];function nh({label:e,value:t,onChange:n,pt:r="sm"},a){y.useEffect(()=>{typeof t=="string"&&n({type:t,config:{}})},[t,n]);const o=c=>{n(c==="quantile"?{type:"quantile",config:{p:.99}}:c==="custom"?{type:"custom",config:{func:Rs}}:{type:c,config:{}})},l=c=>{n({type:"quantile",config:{p:c}})},u=c=>{n({type:"custom",config:{func:c}})};return p(s.Group,{grow:!0,noWrap:!0,pt:r,children:[i(s.Select,{ref:a,label:e,data:th,value:t.type,onChange:o}),t.type==="quantile"&&i(s.NumberInput,{label:"p",value:t.config.p,onChange:l,precision:2,min:.05,step:.05,max:1}),t.type==="custom"&&i(Xp,{label:"",triggerLabel:"Edit Function",value:t.config.func,onChange:u,defaultValue:Rs,triggerButtonProps:{size:"xs",sx:{flexGrow:0,alignSelf:"center",marginTop:"22px"},leftIcon:i($.IconMathFunction,{size:16})}})]})}const Fn=y.forwardRef(nh);function rh({label:e,value:t,onChange:n},r){const[a,o]=y.useState(Array.isArray(t)?[...t]:[]),l=y.useCallback(()=>{o(g=>[...g,""])},[o]),u=y.useCallback(g=>{o(m=>(m.splice(g,1),[...m]))},[o]),c=y.useMemo(()=>!x.isEqual(a,t),[a,t]),d=()=>{n(a.map(g=>g.toString()))},f=s.useMantineTheme(),h=y.useMemo(()=>Object.entries(f.colors).map(([g,m])=>m[6]),[f]);return p(P,{children:[p(s.Group,{position:"left",ref:r,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!c,onClick:d,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[a.map((g,m)=>i(s.ColorInput,{value:g,onChange:C=>{o(w=>(w.splice(m,1,C),[...w]))},swatches:h,rightSection:i(s.ActionIcon,{onClick:()=>u(m),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const ih=y.forwardRef(rh);function ah({value:e,onChange:t},n){const{colorManager:r}=y.useContext(ut),a=y.useMemo(()=>r.getStaticColors().map(u=>({label:u.name,group:u.category,value:u.value})),[r]),o=y.useMemo(()=>a.some(l=>l.value===e),[e,a]);return p(s.Group,{position:"apart",spacing:4,ref:n,children:[i(s.TextInput,{placeholder:"Set any color",value:o?"":e,onChange:l=>t(l.currentTarget.value),rightSection:i(s.ColorSwatch,{color:o?"transparent":e,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"46%",flexGrow:1}}),i(s.Text,{sx:{flexGrow:0},children:"or"}),i(s.Select,{data:a,value:e,onChange:t,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:i(s.ColorSwatch,{color:o?e:"transparent",radius:4}),sx:{maxWidth:"46%",flexGrow:1}})]})}const Ve=y.forwardRef(ah),Gn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function sh({label:e,value:t,onChange:n},r){var l;const[a,o]=y.useState(((l=Gn.find(u=>u.label===t))==null?void 0:l.value)??Gn[0].value);return y.useEffect(()=>{const u=Gn.find(c=>c.value===a);u&&n(u.label)},[a]),p(s.Stack,{spacing:0,mt:"sm",mb:"lg",children:[i(s.Text,{size:"sm",children:e}),i(s.Slider,{label:null,marks:Gn,value:a,onChange:o,step:25,placeholder:"Pick a font size",px:"1em",ref:r})]})}const Ys=y.forwardRef(sh);function oh({label:e,value:t,onChange:n,type:r},a){const[o,l]=y.useState(Array.isArray(t)?[...t]:[]),u=y.useCallback(()=>{l(h=>[...h,""])},[l]),c=y.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=y.useMemo(()=>!x.isEqual(o.map(String),t.map(String)),[o,t]),f=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return p(P,{children:[p(s.Group,{position:"left",ref:a,children:[i(s.Text,{children:e}),i(s.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:f,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Group,{children:[o.map((h,g)=>i(s.TextInput,{type:r,value:h,onChange:m=>{const C=m.currentTarget.value;l(w=>(w.splice(g,1,C),[...w]))},rightSection:i(s.ActionIcon,{onClick:()=>c(g),color:"red",children:i(T.Trash,{size:14})}),sx:{width:"45%"}})),i(s.ActionIcon,{onClick:u,color:"blue",variant:"outline",children:i(T.PlaylistAdd,{size:20})})]})]})}const lh=y.forwardRef(oh),Qs=y.forwardRef(function({value:t,onChange:n},r){const a=t.color.type,o=(u,c)=>{const d=x.cloneDeep(t);x.set(d,u,c),n(d)},l=u=>{if(u==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return p(P,{children:[i(s.Divider,{my:"xs",label:"Typography",labelPosition:"center"}),i(s.Stack,{children:i(s.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:u=>o("size",u.currentTarget.value)})}),i(s.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:i(Ys,{label:"Font Weight",value:t.weight,onChange:u=>o("weight",u)})}),i(s.Divider,{my:"xs",label:"Style",labelPosition:"center"}),p(s.Stack,{children:[i(s.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),a==="static"&&i(Ve,{value:t.color.staticColor,onChange:u=>o("color.staticColor",u)}),a==="continuous"&&p(P,{children:[i(lh,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:u=>o("color.valueRange",u)}),i(ih,{label:"Color Range",value:t.color.colorRange,onChange:u=>o("color.colorRange",u)})]})]})]})});y.forwardRef(function({value:t,onChange:n,withStyle:r=!0},a){const o=(l,u)=>{const c=x.cloneDeep(t);x.set(c,l,u),n(c)};return p(s.Box,{px:"sm",py:"md",ref:a,children:[i(s.Text,{weight:"bold",pb:0,children:t.name}),i(s.Divider,{my:"xs",label:"Data",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(s.TextInput,{label:"Name",required:!0,value:t.name,onChange:l=>o("name",l.currentTarget.value)}),i(W,{label:"Data Field",required:!0,value:t.data_field,onChange:l=>o("data_field",l)})]}),i(Fn,{label:"Aggregation",value:t.aggregation,onChange:l=>o("aggregation",l)}),i(s.Divider,{my:"xs",label:"Format",labelPosition:"center"}),t.aggregation.type!=="custom"&&i(We,{value:t.formatter,onChange:l=>o("formatter",l)}),r&&i(Qs,{value:t,onChange:n})]})});class uh{constructor({valueRange:t,colorRange:n}){q(this,"mapper");this.mapper=_t.interpolate(t,n)}getColor(t){return this.mapper(t)}}function ch(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function ft({data_field:e,aggregation:t},n){return qn(n,e,t)}function Je({formatter:e,aggregation:t},n){if(!["string","number"].includes(typeof n))return ch(n);if(t.type==="custom")return n;try{return Z(n).format(e)}catch(r){return console.error(r),n}}function dh(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new uh(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function Ks(e,t){const{color:n,data_field:r,aggregation:a,size:o,weight:l}=e,u=qn(t,r,a),c=Je(e,u);return i(s.Text,{sx:{fontSize:o,display:"inline"},color:dh(n,u),weight:l,children:c})}function ph(e,t){const n={};return e.forEach(r=>{const a=r.name;n[a]=Ks(r,t)}),n}function hh(e){return e.split(" ").map((t,n)=>p(y.Fragment,{children:[t," "]},n))}function fh(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
106
106
|
`,"<br/>").split("<br/>");return n.map((a,o)=>{const l=[hh(a)];return o!==n.length-1&&l.push(i("br",{},`br-${o}`)),l}).flat().filter(a=>a!==void 0)}function Yr(e){return fh(e)}function un(e,t,n){const r=ph(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const u=a.exec(o);if(!u)return Yr(o);const c=r[u[1]];if(!c)return Yr(o);const d=u[2]??"";return p(y.Fragment,{children:[c,Yr(d)]},`${o}-${l}`)})}function gh(e,t){const n={};return e.forEach(r=>{const{name:a,data_field:o,aggregation:l}=r,u=qn(t,o,l);n[a]=Je(r,u)}),n}function Wn(e,t,n){const r=gh(t,n),a=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=a.exec(o);if(!l)return o;const u=r[l[1]];if(!u)return o;const c=l[2]??"";return`${u}${c}`}).join("")}function mh(e,t,n){const r=t.reduce((a,o)=>{const l=ft(o,n);return a[o.name]=Je(o,l),a},{});return e.map(a=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:a.name,yAxis:Number(r[a.variable_key])}],silent:!0,symbol:["none","none"],label:{formatter:function(){return Wn(a.template,t,n)},position:"insideEndTop"}}}))}function yh(e){const t={top:30,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),t}function bh({config:e,data:t,variables:n}){const{x_axis:r,y_axis:a,reference_lines:o}=e,l=hd(e,t),u=rt(r.axisLabel.overflow.on_axis),c=gd(e);return{grid:yh(e),dataset:l,legend:fd({config:e}),tooltip:wd({config:e}),xAxis:[{type:"category",name:r.name,nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold",align:"center"},axisTick:{show:!0,alignWithLabel:!0},axisLabel:{...r.axisLabel,...u,formatter:Pt(r.axisLabel.formatter)}}],yAxis:[{name:a.name,minInterval:1,nameTextStyle:{fontWeight:"bold"},axisLine:{show:!0},axisLabel:{formatter:function(d){return Z(d).format(a.label_formatter)}}}],series:[...c,...mh(o,n,t)]}}ie.use([F.DataZoomComponent,pe.BoxplotChart,F.MarkLineComponent,F.GridComponent,F.LegendComponent,F.TooltipComponent,Pe.CanvasRenderer]);function vh({context:e,instance:t}){const{value:n}=j(e.instanceData,"config"),{variables:r}=e,a=e.data,{width:o,height:l}=e.viewport,u=x.defaults({},n,kr),c=Ue({vizManager:e.vizManager,instance:t}),d=Ke(c.triggerManager,ls.id),f=Dt(a,u.x_axis.data_key),h=y.useCallback(C=>{const w=x.get(f,C.name,{error:"rowData is not found"});d.forEach(_=>{c.runInteraction(_.id,{...C,rowData:w})})},[f,d,c]),g=y.useMemo(()=>({click:h}),[h]),m=y.useMemo(()=>bh({config:u,data:a,variables:r}),[u,a,r]);return!n||!o||!l?null:i(s.Box,{sx:{width:o,height:l,overflow:"hidden"},children:i(Be,{echarts:ie,option:m,style:{width:o,height:l},onEvents:g,notMerge:!0,theme:"merico-light"})})}function xh({control:e,index:t,remove:n,variableOptions:r}){return p(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:a})=>i(s.TextInput,{label:"Name",placeholder:"Average Reference Line",required:!0,sx:{flex:1},...a})}),i(v.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:a})=>i(s.Select,{label:"Value",required:!0,data:r,sx:{flex:1},...a})})]}),i(v.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:a})=>i(s.TextInput,{label:"Content Template",placeholder:"Average: ${avg}",required:!0,sx:{flex:1},...a})}),i(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>n(t),sx:{position:"absolute",top:15,right:5},children:i(T.Trash,{size:16})})]},t)}function wh({control:e,watch:t,variables:n}){const{fields:r,append:a,remove:o}=v.useFieldArray({control:e,name:"reference_lines"}),l=t("reference_lines"),u=r.map((f,h)=>({...f,...l[h]})),c=()=>a({name:"",template:"",variable_key:""}),d=y.useMemo(()=>n.map(f=>({label:f.name,value:f.name})),[n]);return p(s.Stack,{children:[u.map((f,h)=>i(xh,{control:e,index:h,remove:o,variableOptions:d},f.id)),i(s.Group,{position:"center",mt:"xs",children:i(s.Button,{onClick:c,children:"Add a Reference Line"})})]})}const Ch=({disabled:e,value:t,onChange:n})=>{const r=a=>{a&&n(a)};return p(s.Box,{sx:{position:"relative"},children:[e&&i(s.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),i(Ae,{height:"500px",defaultLanguage:"javascript",value:t,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},jn=y.forwardRef(({value:e,onChange:t},n)=>{const[r,{setTrue:a,setFalse:o}]=U.useBoolean(),[l,u]=y.useState(e);y.useEffect(()=>{u(e)},[e]);const c=m=>{u({...l,enabled:m})},d=()=>{o();const{enabled:m,func_content:C}=l,w={enabled:m,func_content:C};u(w),t(w)},f=()=>{o(),u(e)},h=m=>{u(C=>({...C,func_content:m}))},g=()=>{h(Qe.func_content)};return p(P,{children:[i(s.Button,{variant:"filled",mt:24,onClick:a,sx:{flexGrow:0},children:"Customize Label"}),i(s.Modal,{size:800,title:"Customize label content",opened:r,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&p(s.Stack,{children:[i(s.Checkbox,{mt:10,label:"Enabled",checked:l.enabled,onChange:m=>c(m.currentTarget.checked)}),i(Ch,{value:l.func_content,onChange:h,disabled:!l.enabled}),p(s.Group,{position:"apart",children:[i(s.Button,{onClick:g,color:"red",leftIcon:i(T.Recycle,{size:20}),children:"Reset"}),p(s.Group,{position:"right",children:[i(s.Button,{onClick:f,variant:"subtle",children:"Cancel"}),i(s.Button,{onClick:d,children:"OK"})]})]})]})})]})}),Sh=({control:e,watch:t})=>(t(["x_axis"]),p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"X Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"x_axis.data_key",control:e,render:({field:n})=>i(W,{label:"X Axis Data Field",required:!0,sx:{flex:1},...n})})]}),i(s.Divider,{mb:-15,label:"Tick Label",labelPosition:"center"}),p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:n})=>i(s.NumberInput,{label:"Rotate",hideControls:!0,min:-90,max:90,rightSection:i(s.Text,{color:"dimmed",children:"degree"}),sx:{width:"48%"},styles:{rightSection:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},...n})}),i(v.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:n})=>i(jn,{...n})})]}),i(v.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:n})=>i(at,{...n})})]})),_h=({control:e,watch:t})=>(t(["y_axis"]),p(P,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:"y_axis.name",control:e,render:({field:n})=>i(s.TextInput,{label:"Y Axis Name",sx:{flex:1},...n})}),i(v.Controller,{name:"y_axis.data_key",control:e,render:({field:n})=>i(W,{label:"Y Axis Data Field",required:!0,sx:{flex:1},...n})})]}),p(s.Stack,{children:[i(s.Divider,{mb:-15,variant:"dashed",label:"Label Format",labelPosition:"center"}),i(v.Controller,{name:"y_axis.label_formatter",control:e,render:({field:n})=>i(We,{...n})})]})]})),kh=({control:e,index:t,remove:n})=>p(s.Stack,{children:[p(s.Group,{grow:!0,noWrap:!0,children:[i(v.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:r})=>i(s.TextInput,{label:"Name",required:!0,sx:{flex:1},...r})}),i(v.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:r})=>i(W,{label:"Value Field",required:!0,sx:{flex:1},...r})})]}),i(s.Divider,{mb:-10,mt:10,variant:"dashed"}),i(s.Button,{leftIcon:i(T.Trash,{size:16}),color:"red",variant:"light",onClick:()=>n(t),sx:{top:15,right:5},children:"Delete this Metric"})]}),Th=({control:e,watch:t})=>{const{fields:n,append:r,remove:a}=v.useFieldArray({control:e,name:"tooltip.metrics"}),o=t("tooltip.metrics"),l=n.map((h,g)=>({...h,...o[g]})),u=()=>r({id:Date.now().toString(),data_key:"",name:""}),c=t("tooltip.metrics.0.id"),[d,f]=y.useState(()=>c??null);return y.useEffect(()=>{c&&f(h=>h!==null?h:c)},[c]),p(P,{children:[p(s.Group,{spacing:2,sx:{cursor:"default",userSelect:"none"},children:[i(T.InfoCircle,{size:14,color:"#888"}),i(s.Text,{size:14,color:"#888",children:"Set additional metrics to show in scatter's tooltip"})]}),p(s.Tabs,{value:d,onTabChange:h=>f(h),styles:{tab:{paddingTop:"0px",paddingBottom:"0px"},panel:{padding:"0px",paddingTop:"6px"}},children:[p(s.Tabs.List,{children:[l.map((h,g)=>i(s.Tabs.Tab,{value:h.id,children:h.name?h.name:g},h.id)),i(s.Tabs.Tab,{onClick:u,value:"add",children:i(T.Plus,{size:18,color:"#228be6"})})]}),l.map((h,g)=>i(s.Tabs.Panel,{value:h.id,children:i(kh,{control:e,index:g,remove:a},h.id)},h.id))]})]})};function Dh({control:e,watch:t}){return i(s.Stack,{children:i(Th,{control:e,watch:t})})}const Mh=[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],Ih=({control:e,watch:t})=>{const n=t("legend"),r=(a,o)=>{const l={...n,orient:a};a==="horizontal"?(l.top="0",l.left="auto",l.right="10",l.bottom="auto"):(l.top="10",l.left="auto",l.right="0",l.bottom="auto"),o(l)};return p(s.Stack,{children:[i(s.Group,{grow:!0,noWrap:!0,mt:20,children:i(v.Controller,{name:"legend.show",control:e,render:({field:a})=>i(s.Switch,{label:"Show Legend",sx:{flex:1},checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})}),i(s.Group,{children:i(v.Controller,{name:"legend",control:e,render:({field:a})=>i(s.Select,{label:"Orientation",data:Mh,sx:{flex:1},value:a.value.orient,onChange:o=>{r(o,a.onChange)},disabled:!n.show})})})]})};function Ah({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),{variables:r}=e,a=y.useMemo(()=>x.defaults({},t,kr),[t]),{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]),u(["x_axis","y_axis","reference_lines","color"]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,t),[f,t]);return i(s.Stack,{spacing:"xs",children:p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[p(s.Tabs.List,{children:[i(s.Tabs.Tab,{value:"X Axis",children:"X Axis"}),i(s.Tabs.Tab,{value:"Y Axis",children:"Y Axis"}),i(s.Tabs.Tab,{value:"Legend",children:"Legend"}),i(s.Tabs.Tab,{value:"Tooltip",children:"Tooltip"}),i(s.Tabs.Tab,{value:"Style",children:"Style"}),i(s.Tabs.Tab,{value:"Reference Lines",children:"Reference Lines"})]}),i(s.Tabs.Panel,{value:"X Axis",children:i(Sh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Y Axis",children:i(_h,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Legend",children:i(Ih,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Tooltip",children:i(Dh,{control:o,watch:u})}),i(s.Tabs.Panel,{value:"Style",children:p(s.Stack,{spacing:4,children:[i(s.Text,{size:"sm",children:"Color"}),i(v.Controller,{name:"color",control:o,render:({field:g})=>i(Ve,{...g})})]})}),i(s.Tabs.Panel,{value:"Reference Lines",children:i(wh,{variables:r,control:o,watch:u})})]})]})})}function zh(e){return x.omit(e,"variables")}function Eh(e){const{label_formatter:t=ze,...n}=e.y_axis;return{...e,y_axis:{...n,label_formatter:t}}}function $h(e){const t={rotate:0,formatter:{...Qe}},{axisLabel:n=t,...r}=e.x_axis;return{...e,x_axis:{...r,axisLabel:n}}}function Lh(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return x.defaultsDeep(t,e)}function Oh(e){delete e.config;const{x_axis:t,tooltip:n}=e.x_axis.axisLabel.overflow,r={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:n}}}};return x.defaultsDeep(r,e)}function Ph(e){const t={tooltip:{metrics:[]}};return x.defaultsDeep(t,e)}function Bh(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=c=>c&&`${n}.${c}`,{x_axis:a,y_axis:o,tooltip:l,...u}=e;return{...u,x_axis:{...a,data_key:r(a.data_key)},y_axis:{...o,data_key:r(o.data_key)},tooltip:{...l,metrics:l.metrics.map(c=>({...c,data_key:r(c.data_key)}))}}}catch(n){throw console.error("[Migration failed]",n),n}}function Vh(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return x.defaultsDeep(t,e)}class Nh extends me{constructor(){super(...arguments);q(this,"VERSION",9)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,{panelModel:r})=>{const{config:a}=n;return(a.variables||[]).forEach(l=>{r.variables.find(u=>u.name===l.name)||r.addVariable(l)}),{...n,version:2,config:zh(a)}}),this.version(3,n=>{const{config:r}=n;return{...n,version:3,config:Eh(r)}}),this.version(4,n=>{const{config:r}=n;return{...n,version:4,config:$h(r)}}),this.version(5,n=>{const{config:r}=n;return{...n,version:5,config:Lh(r)}}),this.version(6,n=>{const{config:r}=n;return{...n,version:6,config:Oh(r)}}),this.version(7,n=>{const{config:r}=n;return{...n,version:7,config:Ph(r)}}),this.version(8,(n,r)=>{const{config:a}=n;return{...n,version:8,config:Bh(a,r)}}),this.version(9,n=>{const{config:r}=n;return{...n,version:9,config:Vh(r)}})}}const qh={displayName:"Boxplot Chart",displayGroup:"ECharts-based charts",migrator:new Nh,name:"boxplot",viewRender:vh,configRender:Ah,createConfig(){return{version:9,config:x.cloneDeep(kr)}},triggers:[ls]},Us={id:"builtin:button:click-button",displayName:"Click Button",nameRender:Gh,configRender:Fh,payload:[]};function Fh(e){return i(P,{})}function Gh(e){return i(s.Text,{children:"Click this button"})}const Qr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Wh={left:"flex-start",center:"center",right:"flex-end"},jh={top:"flex-start",center:"center",bottom:"flex-end"},Rh=k.observer(({context:e,instance:t})=>{const n=Ue({vizManager:e.vizManager,instance:t}),r=Ke(n.triggerManager,Us.id),a=we(),{value:o}=j(e.instanceData,"config"),l=y.useMemo(()=>x.defaultsDeep({},o,Qr),[o]),{content:u,horizontal_align:c,vertical_align:d,...f}=l,{width:h,height:g}=e.viewport,m=a.payloadForSQL,C=()=>{r.forEach(w=>{n.runInteraction(w.id,{})})};return i(s.Center,{sx:{width:h,height:g,justifyContent:Wh[c],alignItems:jh[d]},children:i(s.Button,{...f,onClick:C,children:x.template(u)(m)})})}),Yh=({value:e,onChange:t,label:n})=>{const r=s.useMantineTheme(),a=y.useCallback(l=>()=>t(l),[t]),o=l=>e===l;return p(s.Stack,{spacing:2,children:[i(s.Text,{size:14,sx:{fontWeight:500},children:n}),i(s.Group,{position:"left",spacing:"xs",children:Object.keys(r.colors).map(l=>{const u=r.colors[l][6];return i(s.ColorSwatch,{color:u,onClick:a(l),radius:4,size:26,sx:{cursor:"pointer"},children:o(l)&&i(s.CheckIcon,{width:10,color:"white"})},l)})})]})},Qh=s.MANTINE_SIZES.map(e=>({label:e.toUpperCase(),value:e})),Kh=({label:e,value:t,onChange:n})=>i(s.Select,{data:Qh,label:e,value:t,onChange:n}),Uh=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}],Xh=[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],Jh=[{label:"Top",value:"top"},{label:"Center",value:"center"},{label:"Bottom",value:"bottom"}];function Zh({context:e}){const{value:t,set:n}=j(e.instanceData,"config"),r=y.useMemo(()=>x.defaultsDeep({},t,Qr),[t]),a=r;y.useEffect(()=>{!x.isEqual(r,a)&&(console.log("config malformed, resetting to defaults",r,a),n(a))},[r,a]);const{control:o,handleSubmit:l,watch:u,getValues:c,reset:d}=v.useForm({defaultValues:a});y.useEffect(()=>{d(a)},[a]);const f=c(),h=y.useMemo(()=>!x.isEqual(f,r),[f,r]);return u(["content","variant","color","size","compact","horizontal_align","vertical_align"]),p("form",{onSubmit:l(n),children:[p(s.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[i(s.Text,{children:"Chart Config"}),i(s.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!h,children:i(T.DeviceFloppy,{size:20})})]}),p(s.Stack,{children:[i(v.Controller,{control:o,name:"content",render:({field:g})=>i(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...g,required:!0})}),i(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"variant",render:({field:g})=>i(s.Select,{label:"Variant",data:Uh,...g})}),i(v.Controller,{control:o,name:"color",render:({field:g})=>i(Yh,{label:"Theme",...g})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"size",render:({field:g})=>i(Kh,{label:"Size",...g})}),i(v.Controller,{control:o,name:"compact",render:({field:g})=>i(s.Checkbox,{label:"Compact",checked:g.value,onChange:m=>g.onChange(m.currentTarget.checked),mt:26})})]}),p(s.SimpleGrid,{cols:2,children:[i(v.Controller,{control:o,name:"horizontal_align",render:({field:g})=>i(s.Select,{label:"Horizontal Alignment",data:Xh,...g})}),i(v.Controller,{control:o,name:"vertical_align",render:({field:g})=>i(s.Select,{label:"Vertical Alignment",data:Jh,...g})})]})]})]})}class Hh extends me{constructor(){super(...arguments);q(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,n=>{const{horizontal_align:r="left",vertical_align:a="center",...o}=n.config;return{...n,version:2,config:{...o,horizontal_align:r,vertical_align:a}}})}}const ef={displayName:"Button",displayGroup:"Others",migrator:new Hh,name:"button",viewRender:Rh,configRender:Zh,createConfig(){return{version:2,config:x.cloneDeep(Qr)}},triggers:[Us]},Kr={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:nf,configRender:tf,payload:[{name:"seriesType",description:"'line' | 'scatter' | 'bar'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function tf(e){return i(P,{})}function nf(e){return i(s.Text,{children:"Click chart's series"})}const qt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1},Ur={regressions:[],series:[],stats:{templates:{bottom:"",top:""}},x_axis:{type:"category",axisLabel:{rotate:0,formatter:{...Qe},overflow:je}},x_axis_data_key:"",x_axis_name:"",y_axes:[{min:"",max:"",name:"Y Axis",show:!0,position:"left",nameAlignment:"center",label_formatter:ze}],reference_lines:[],reference_areas:[],dataZoom:qt};function Xr(e){const t=[];return e.x_axis_scroll&&t.push({type:"inside",xAxisIndex:[0],filterMode:"none",minSpan:1}),e.y_axis_scroll&&t.push({type:"inside",yAxisIndex:[0],filterMode:"none",minSpan:1}),e.x_axis_slider&&t.push({type:"slider",xAxisIndex:[0],filterMode:"none",bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),t}function rf(e){const t=e.y_axes.some(a=>!!a.name);let n=15;t&&(n+=20),e.dataZoom.x_axis_slider&&(n+=20);let r=5;return e.x_axis_name&&(r+=15),e.series.some(a=>!a.hide_in_legend)&&(r+=20),{top:n,right:15,bottom:r,left:20,containLabel:!0}}function af(e){return e!=="line"?{}:{itemStyle:{opacity:0}}}function sf(e){switch(e){case"line":return;case"bar":return"roundRect";case"scatter":return"circle"}}function of(e){const t={show:!0,bottom:0,left:"center",type:"scroll"};return t.data=e.filter(n=>!n.hide_in_legend).map(({name:n,type:r})=>({name:n,icon:sf(r),...af(r)})),t}function Rn(e,t){switch(e.config.method){case"linear":return[...yt.regressionLinear()(t)];case"exponential":return[...yt.regressionExp()(t)];case"logarithmic":return[...yt.regressionLog()(t)];case"polynomial":return[...yt.regressionPoly().order(e.config.order)(t)];default:return[]}}function lf(e,t,n,r){const{transform:a,plot:o}=e,l={...o,name:t,data:Rn(a,r),showSymbol:!1,tooltip:{show:!1},smooth:!1,custom:{}};return n&&(l.custom={type:"regression-line",targetSeries:n}),l}function uf({regressions:e=[],x_axis_data_key:t},n){const r=[];if(Object.keys(n).length===0)return r;function a(o,l,u,c){const d=lf(o,l,u,c);r.push(d)}return e.forEach(o=>{const{name:l,group_by_key:u}=o;if(!u||u===t){const h=pt(n,o.y_axis_data_key).map((g,m)=>[m,Number(g)]);a(o,l,"",h);return}const{columnKey:c}=L(o.y_axis_data_key),d=x.groupBy(Ht(n,o.y_axis_data_key),u);Object.entries(d).forEach(([f,h])=>{const g=h.map((C,w)=>[w,Number(C[c])]);a(o,f,f,g)})}),r}function cf(e,t){return e.map(n=>({name:"",type:"line",hide_in_legend:!0,data:[],markArea:{itemStyle:{color:n.color},data:[[{yAxis:t[n.y_keys.upper]},{yAxis:t[n.y_keys.lower]}]],silent:!0}}))}function df(e,t,n,r){return e.map(a=>{const o=a.orientation==="horizontal",l=o?"yAxis":"xAxis",u=o?"insideEndTop":"end";return{name:a.name,type:"line",hide_in_legend:!a.show_in_legend,yAxisIndex:a.yAxisIndex,data:[],lineStyle:a.lineStyle,markLine:{data:[{name:a.name,[l]:n[a.variable_key]}],silent:!0,symbol:["none","none"],lineStyle:a.lineStyle,label:{formatter:function(){return a.template?Wn(a.template,t,r):""},position:u}}}})}function pf({type:e,...t},n,r,a){if(!e)return 10;if(e==="static"){const{size:d}=t;return d}const{func_content:o}=t,{queryID:l,columnKey:u}=L(r),c=x.keyBy(Ht(n,l),u);return(d,f)=>{let h;f.name?h=c[f.name]:h=n[f.dataIndex];try{return new Function(`return ${o}`)()({rowData:h,params:f,variables:a},{lodash:x,interpolate:_t.interpolate})}catch(g){return console.error(`[getEchartsSymbolSize] failed parsing custom function, error: ${g.message}`),10}}}function Jr(e,t,n){const r=pt(e,t),a=pt(e,n);return x.zip(r,a)}function hf(e,t,n,r){const a=Jr(t,n,r);return x.unionBy(a,e,0)}function ff({dataTemplate:e,data:t,x_axis_data_key:n,y_axis_data_key:r,valueTypedXAxis:a}){return a?hf(e,t,n,r):pt(t,r)}function gf({dataTemplate:e,data:t,aggregation_on_value:n,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o}){if(!n||n.type==="none")return ff({dataTemplate:e,data:t,x_axis_data_key:r,y_axis_data_key:a,valueTypedXAxis:o});const l=Jr(t,r,a),u=x.groupBy(l,"0");return e.map(([d])=>{const h=u[d].map(m=>m[1]),g=Rr(h,n);return[d,g]})}function mf({group_by_key:e,data:t,x_axis_data_key:n,y_axis_data_key:r}){const{queryID:a,columnKey:o}=L(e),l=x.groupBy(t[a],o);return Object.entries(l).forEach(([u,c])=>{l[u]=Jr({[a]:c},n,r)}),l}function yf({x_axis_data_key:e,x_axis:t},{y_axis_data_key:n,yAxisIndex:r,label_position:a,name:o,group_by_key:l,aggregation_on_value:u,stack:c,color:d,display_name_on_line:f,symbolSize:h,hide_in_legend:g,...m},C,w,_,D){const I=t.type!=="category",B={label:{show:!!a,position:a,formatter:D[r??"default"]},name:o,xAxisId:"main-x-axis",yAxisIndex:r,stack:c,color:d,symbolSize:pf(h,w,e,_),hide_in_legend:g,labelLayout:{hideOverlap:!0},...m};if(f&&(B.endLabel={show:!0,formatter:o,offset:[-12,12],align:"right"}),!l||l===e)return B.data=gf({dataTemplate:C,data:w,aggregation_on_value:u,x_axis_data_key:e,y_axis_data_key:n,valueTypedXAxis:I}),B;const N=mf({group_by_key:l,data:w,x_axis_data_key:e,y_axis_data_key:n});return Object.entries(N).map(([O,z])=>{const A=x.cloneDeep(B);return A.name=O,A.color=void 0,A.data=z,A})}function bf(e,t,n,r,a,o){const l=t.map(c=>[c,0]);return e.series.map(c=>yf(e,c,l,n,o,r)).flat().concat(df(e.reference_lines,a,o,n)).concat(cf(e.reference_areas,o))}function vf(e,t){const n=e.find(o=>o.axisDim==="x"&&o.axisId==="main-x-axis");if(!n)return"";const{axisValue:r,axisIndex:a}=n;return Pt(t.x_axis.axisLabel.formatter)(r,a)}function xf(e,t,n){const r=t.reduce((a,{yAxisIndex:o,name:l})=>(a[l]=o,a),{});return{trigger:"axis",confine:!0,formatter:function(a){const o=Array.isArray(a)?a:[a];if(o.length===0)return"";const l=o.map(({seriesName:d,marker:f,value:h})=>{if(Array.isArray(h)&&h.length===2&&(h=h[1]),!d)return h;const g=r[d],m=n[g]??n.default;return`
|
|
107
107
|
<tr>
|
|
108
108
|
<td>${f}</td>
|