UNPKG

@silexlabs/silex

Version:

Free and easy website builder for everyone.

16 lines 1.84 MB
/*! For license information please see main.js.LICENSE.txt */ var silex;(()=>{var t={58:function(t){var e;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window&&window,e=()=>(()=>{var t={365:t=>{t.exports=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=[],r="string"==typeof t?[t]:t.slice();r[r.length-1]=r[r.length-1].replace(/\r?\n([\t ]*)$/,"");for(var i=0;i<r.length;i++){var s;(s=r[i].match(/\n[\t ]+/g))&&o.push.apply(o,s)}if(o.length){var a=Math.min.apply(Math,o.map(function(t){return t.length-1})),l=new RegExp("\n[\t ]{"+a+"}","g");for(i=0;i<r.length;i++)r[i]=r[i].replace(l,"\n")}r[0]=r[0].replace(/^\r?\n/,"");var c=r[0];for(i=0;i<e.length;i++)c+=e[i]+r[i+1];return c}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{"use strict";n.r(o),n.d(o,{BinaryOperator:()=>C,COMMAND_ADD_DATA_SOURCE:()=>w,COMMAND_PREVIEW_ACTIVATE:()=>m,COMMAND_PREVIEW_DEACTIVATE:()=>v,COMMAND_PREVIEW_REFRESH:()=>y,COMMAND_PREVIEW_TOGGLE:()=>b,COMMAND_REFRESH:()=>g,COMPONENT_NAME_PREFIX:()=>Qn,COMPONENT_STATE_CHANGED:()=>s,DATA_SOURCE_CHANGED:()=>i,DATA_SOURCE_DATA_LOAD_CANCEL:()=>c,DATA_SOURCE_DATA_LOAD_END:()=>l,DATA_SOURCE_DATA_LOAD_START:()=>a,DATA_SOURCE_ERROR:()=>r,DATA_SOURCE_READY:()=>e,FIXED_TOKEN_ID:()=>t,NOTIFICATION_GROUP:()=>Xn,PREVIEW_ACTIVATED:()=>h,PREVIEW_DEACTIVATED:()=>f,PREVIEW_RENDER_END:()=>p,PREVIEW_RENDER_ERROR:()=>d,PREVIEW_RENDER_START:()=>u,Properties:()=>O,UnariOperator:()=>x,addDataSource:()=>An,addFilters:()=>Vn,buildPageQueries:()=>On,builtinTypeIds:()=>_,builtinTypes:()=>S,clearPreviewData:()=>Ln,createDataSource:()=>Zn,default:()=>dr,fromStored:()=>Un,getAllDataSources:()=>En,getCompletion:()=>Rn,getDataSource:()=>Tn,getExpressionResultType:()=>Fn,getOrCreatePersistantId:()=>Bn,getPageExpressions:()=>Dn,getPageQuery:()=>Cn,getPersistantId:()=>Hn,getPreviewData:()=>jn,getState:()=>Wn,getStateIds:()=>qn,getStateVariableName:()=>Jn,getValue:()=>Nn,loadPreviewData:()=>$n,refreshDataSources:()=>Pn,removeDataSource:()=>kn,removeFilters:()=>zn,removeState:()=>Kn,setPreviewData:()=>In,setPreviewIndex:()=>Mn,setState:()=>Gn,toExpression:()=>Yn,version:()=>hr});const t="fixed",e="data-source:ready",r="data-source:error",i="data-source:changed",s="component:state:changed",a="data-source:data-load:start",l="data-source:data-load:end",c="data-source:data-load:cancel",u="data-source:start:preview",p="data-source:start:end",d="data-source:start:error",h="data-source:preview:activated",f="data-source:preview:deactivated",g="data-source:refresh",m="data-source:preview:activate",v="data-source:preview:deactivate",y="data-source:preview:refresh",b="data-source:preview:toggle",w="data-source:add",_=["String","Int","Float","Boolean","ID","Unknown"],S=_.map(t=>({id:t,label:t,fields:[]}));var x,C,O;!function(t){t.TRUTHY="truthy",t.FALSY="falsy",t.EMPTY_ARR="empty array",t.NOT_EMPTY_ARR="not empty array"}(x||(x={})),function(t){t.EQUAL="==",t.NOT_EQUAL="!=",t.GREATER_THAN=">",t.LESS_THAN="<",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN_OR_EQUAL="<="}(C||(C={})),function(t){t.innerHTML="innerHTML",t.condition="condition",t.condition2="condition2",t.__data="__data"}(O||(O={}));const E="publicStates",T="privateStates",A="id-plugin-data-source",k="nameForDataSource";function P(t){var e;return null!==(e=t.get(A))&&void 0!==e?e:null}function $(t){const e=t.get(A);if(e)return e;const n=`${t.ccid}-${Math.round(1e4*Math.random())}`;return t.set(A,n),n}function j(t,e){return e?P(e)===t?e:j(t,e.parent()):null}const I=[];function M(t,e){I.forEach(n=>n(t,e))}function L(t,e=!0,n){var o;try{const r=(null!==(o=t.get(e?E:T))&&void 0!==o?o:[]).sort((t,e)=>{var n,o;return Number(null!==(n=e.hidden)&&void 0!==n&&n)-Number(null!==(o=t.hidden)&&void 0!==o&&o)}).map(t=>t.id);if(n){const t=r.indexOf(n);return t<0?r:r.slice(0,t)}return r}catch(t){return console.error("Error while getting state ids",t),[]}}function N(t,e=!0){var n;return(null!==(n=t.get(e?E:T))&&void 0!==n?n:[]).map(t=>({label:t.label,hidden:t.hidden,expression:t.expression}))}function D(t,e,n=!0){var o,r;const i=null!==(r=(null!==(o=t.get(n?E:T))&&void 0!==o?o:[]).find(t=>t.id===e))&&void 0!==r?r:null;return i?{label:i.label,hidden:i.hidden,expression:i.expression}:null}function R(t,e,n,o=!0,r=-1){var i,s;const a=o?E:T,l=null!==(i=t.get(a))&&void 0!==i?i:[],c=null!==(s=l.find(t=>t.id===e))&&void 0!==s?s:null;if(c?t.set(a,l.map(t=>t.id!==e?t:Object.assign({id:e},n))):t.set(a,[...l,Object.assign({id:e},n)]),r>=0){const n=[...t.get(a)],o=n.find(t=>t.id===e);o&&r<n.length&&(n.splice(n.indexOf(o),1),n.splice(r,0,o),t.set(a,n))}M({label:n.label,hidden:n.hidden,expression:n.expression},t)}function U(t,e,n=!0){var o;const r=n?E:T,i=(null!==(o=t.get(r))&&void 0!==o?o:[]).filter(t=>t.id!==e);t.set(r,i),M(null,t)}let F=null;function V(){if(!F)throw new Error("DataSourceRegistry not initialized. Call initializeDataSourceRegistry first.");return F}function z(){return[...V().dataSources]}function H(t){const e=V();e.dataSources.push(t),t.connect().then(()=>{e.editor.trigger(i)}).catch(t=>{console.error("Failed to connect data source:",t),e.editor.trigger(i)})}function B(t){const e=V(),n=e.dataSources.indexOf(t);n>-1&&(e.dataSources.splice(n,1),e.editor.trigger(i))}function W(t){return V().dataSources.find(e=>e.id===t)}function q(t){const e=V();e.dataSources=[...t],e.editor.trigger(i)}const G=globalThis,K=G.ShadowRoot&&(void 0===G.ShadyCSS||G.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,J=Symbol(),Y=new WeakMap;class Z{constructor(t,e,n){if(this._$cssResult$=!0,n!==J)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(K&&void 0===t){const n=void 0!==e&&1===e.length;n&&(t=Y.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&Y.set(e,t))}return t}toString(){return this.cssText}}const X=(t,...e)=>{const n=1===t.length?t[0]:e.reduce((e,n,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[o+1],t[0]);return new Z(n,t,J)},Q=K?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return(t=>new Z("string"==typeof t?t:t+"",void 0,J))(e)})(t):t,{is:tt,defineProperty:et,getOwnPropertyDescriptor:nt,getOwnPropertyNames:ot,getOwnPropertySymbols:rt,getPrototypeOf:it}=Object,st=globalThis,at=st.trustedTypes,lt=at?at.emptyScript:"",ct=st.reactiveElementPolyfillSupport,ut=(t,e)=>t,pt={toAttribute(t,e){switch(e){case Boolean:t=t?lt:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},dt=(t,e)=>!tt(t,e),ht={attribute:!0,type:String,converter:pt,reflect:!1,useDefault:!1,hasChanged:dt};Symbol.metadata??=Symbol("metadata"),st.litPropertyMetadata??=new WeakMap;class ft extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=ht){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const n=Symbol(),o=this.getPropertyDescriptor(t,n,e);void 0!==o&&et(this.prototype,t,o)}}static getPropertyDescriptor(t,e,n){const{get:o,set:r}=nt(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:o,set(e){const i=o?.call(this);r?.call(this,e),this.requestUpdate(t,i,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??ht}static _$Ei(){if(this.hasOwnProperty(ut("elementProperties")))return;const t=it(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(ut("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(ut("properties"))){const t=this.properties,e=[...ot(t),...rt(t)];for(const n of e)this.createProperty(n,t[n])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,n]of e)this.elementProperties.set(t,n)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const n=this._$Eu(t,e);void 0!==n&&this._$Eh.set(n,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(Q(t))}else void 0!==t&&e.push(Q(t));return e}static _$Eu(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const n of e.keys())this.hasOwnProperty(n)&&(t.set(n,this[n]),delete this[n]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{if(K)t.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const n of e){const e=document.createElement("style"),o=G.litNonce;void 0!==o&&e.setAttribute("nonce",o),e.textContent=n.cssText,t.appendChild(e)}})(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,n){this._$AK(t,n)}_$ET(t,e){const n=this.constructor.elementProperties.get(t),o=this.constructor._$Eu(t,n);if(void 0!==o&&!0===n.reflect){const r=(void 0!==n.converter?.toAttribute?n.converter:pt).toAttribute(e,n.type);this._$Em=t,null==r?this.removeAttribute(o):this.setAttribute(o,r),this._$Em=null}}_$AK(t,e){const n=this.constructor,o=n._$Eh.get(t);if(void 0!==o&&this._$Em!==o){const t=n.getPropertyOptions(o),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:pt;this._$Em=o;const i=r.fromAttribute(e,t.type);this[o]=i??this._$Ej?.get(o)??i,this._$Em=null}}requestUpdate(t,e,n,o=!1,r){if(void 0!==t){const i=this.constructor;if(!1===o&&(r=this[t]),n??=i.getPropertyOptions(t),!((n.hasChanged??dt)(r,e)||n.useDefault&&n.reflect&&r===this._$Ej?.get(t)&&!this.hasAttribute(i._$Eu(t,n))))return;this.C(t,e,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:n,reflect:o,wrapped:r},i){n&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,i??e??this[t]),!0!==r||void 0!==i)||(this._$AL.has(t)||(this.hasUpdated||n||(e=void 0),this._$AL.set(t,e)),!0===o&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,n]of t){const{wrapped:t}=n,o=this[e];!0!==t||this._$AL.has(e)||void 0===o||this.C(e,void 0,n,o)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(t){}firstUpdated(t){}}ft.elementStyles=[],ft.shadowRootOptions={mode:"open"},ft[ut("elementProperties")]=new Map,ft[ut("finalized")]=new Map,ct?.({ReactiveElement:ft}),(st.reactiveElementVersions??=[]).push("2.1.2");const gt=globalThis,mt=gt.trustedTypes,vt=mt?mt.createPolicy("lit-html",{createHTML:t=>t}):void 0,yt="$lit$",bt=`lit$${Math.random().toFixed(9).slice(2)}$`,wt="?"+bt,_t=`<${wt}>`,St=document,xt=()=>St.createComment(""),Ct=t=>null===t||"object"!=typeof t&&"function"!=typeof t,Ot=Array.isArray,Et=t=>Ot(t)||"function"==typeof t?.[Symbol.iterator],Tt="[ \t\n\f\r]",At=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,kt=/-->/g,Pt=/>/g,$t=RegExp(`>|${Tt}(?:([^\\s"'>=/]+)(${Tt}*=${Tt}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),jt=/'/g,It=/"/g,Mt=/^(?:script|style|textarea|title)$/i,Lt=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),Nt=Lt(1),Dt=(Lt(2),Lt(3),Symbol.for("lit-noChange")),Rt=Symbol.for("lit-nothing"),Ut=new WeakMap,Ft=St.createTreeWalker(St,129);function Vt(t,e){if(!Ot(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==vt?vt.createHTML(e):e}const zt=(t,e)=>{const n=t.length-1,o=[];let r,i=2===e?"<svg>":3===e?"<math>":"",s=At;for(let e=0;e<n;e++){const n=t[e];let a,l,c=-1,u=0;for(;u<n.length&&(s.lastIndex=u,l=s.exec(n),null!==l);)u=s.lastIndex,s===At?"!--"===l[1]?s=kt:void 0!==l[1]?s=Pt:void 0!==l[2]?(Mt.test(l[2])&&(r=RegExp("</"+l[2],"g")),s=$t):void 0!==l[3]&&(s=$t):s===$t?">"===l[0]?(s=r??At,c=-1):void 0===l[1]?c=-2:(c=s.lastIndex-l[2].length,a=l[1],s=void 0===l[3]?$t:'"'===l[3]?It:jt):s===It||s===jt?s=$t:s===kt||s===Pt?s=At:(s=$t,r=void 0);const p=s===$t&&t[e+1].startsWith("/>")?" ":"";i+=s===At?n+_t:c>=0?(o.push(a),n.slice(0,c)+yt+n.slice(c)+bt+p):n+bt+(-2===c?e:p)}return[Vt(t,i+(t[n]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),o]};class Ht{constructor({strings:t,_$litType$:e},n){let o;this.parts=[];let r=0,i=0;const s=t.length-1,a=this.parts,[l,c]=zt(t,e);if(this.el=Ht.createElement(l,n),Ft.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(o=Ft.nextNode())&&a.length<s;){if(1===o.nodeType){if(o.hasAttributes())for(const t of o.getAttributeNames())if(t.endsWith(yt)){const e=c[i++],n=o.getAttribute(t).split(bt),s=/([.?@])?(.*)/.exec(e);a.push({type:1,index:r,name:s[2],strings:n,ctor:"."===s[1]?Kt:"?"===s[1]?Jt:"@"===s[1]?Yt:Gt}),o.removeAttribute(t)}else t.startsWith(bt)&&(a.push({type:6,index:r}),o.removeAttribute(t));if(Mt.test(o.tagName)){const t=o.textContent.split(bt),e=t.length-1;if(e>0){o.textContent=mt?mt.emptyScript:"";for(let n=0;n<e;n++)o.append(t[n],xt()),Ft.nextNode(),a.push({type:2,index:++r});o.append(t[e],xt())}}}else if(8===o.nodeType)if(o.data===wt)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=o.data.indexOf(bt,t+1));)a.push({type:7,index:r}),t+=bt.length-1}r++}}static createElement(t,e){const n=St.createElement("template");return n.innerHTML=t,n}}function Bt(t,e,n=t,o){if(e===Dt)return e;let r=void 0!==o?n._$Co?.[o]:n._$Cl;const i=Ct(e)?void 0:e._$litDirective$;return r?.constructor!==i&&(r?._$AO?.(!1),void 0===i?r=void 0:(r=new i(t),r._$AT(t,n,o)),void 0!==o?(n._$Co??=[])[o]=r:n._$Cl=r),void 0!==r&&(e=Bt(t,r._$AS(t,e.values),r,o)),e}class Wt{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:n}=this._$AD,o=(t?.creationScope??St).importNode(e,!0);Ft.currentNode=o;let r=Ft.nextNode(),i=0,s=0,a=n[0];for(;void 0!==a;){if(i===a.index){let e;2===a.type?e=new qt(r,r.nextSibling,this,t):1===a.type?e=new a.ctor(r,a.name,a.strings,this,t):6===a.type&&(e=new Zt(r,this,t)),this._$AV.push(e),a=n[++s]}i!==a?.index&&(r=Ft.nextNode(),i++)}return Ft.currentNode=St,o}p(t){let e=0;for(const n of this._$AV)void 0!==n&&(void 0!==n.strings?(n._$AI(t,n,e),e+=n.strings.length-2):n._$AI(t[e])),e++}}class qt{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,n,o){this.type=2,this._$AH=Rt,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=n,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Bt(this,t,e),Ct(t)?t===Rt||null==t||""===t?(this._$AH!==Rt&&this._$AR(),this._$AH=Rt):t!==this._$AH&&t!==Dt&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):Et(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==Rt&&Ct(this._$AH)?this._$AA.nextSibling.data=t:this.T(St.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:n}=t,o="number"==typeof n?this._$AC(t):(void 0===n.el&&(n.el=Ht.createElement(Vt(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===o)this._$AH.p(e);else{const t=new Wt(o,this),n=t.u(this.options);t.p(e),this.T(n),this._$AH=t}}_$AC(t){let e=Ut.get(t.strings);return void 0===e&&Ut.set(t.strings,e=new Ht(t)),e}k(t){Ot(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,o=0;for(const r of t)o===e.length?e.push(n=new qt(this.O(xt()),this.O(xt()),this,this.options)):n=e[o],n._$AI(r),o++;o<e.length&&(this._$AR(n&&n._$AB.nextSibling,o),e.length=o)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class Gt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,n,o,r){this.type=1,this._$AH=Rt,this._$AN=void 0,this.element=t,this.name=e,this._$AM=o,this.options=r,n.length>2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=Rt}_$AI(t,e=this,n,o){const r=this.strings;let i=!1;if(void 0===r)t=Bt(this,t,e,0),i=!Ct(t)||t!==this._$AH&&t!==Dt,i&&(this._$AH=t);else{const o=t;let s,a;for(t=r[0],s=0;s<r.length-1;s++)a=Bt(this,o[n+s],e,s),a===Dt&&(a=this._$AH[s]),i||=!Ct(a)||a!==this._$AH[s],a===Rt?t=Rt:t!==Rt&&(t+=(a??"")+r[s+1]),this._$AH[s]=a}i&&!o&&this.j(t)}j(t){t===Rt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Kt extends Gt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===Rt?void 0:t}}class Jt extends Gt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==Rt)}}class Yt extends Gt{constructor(t,e,n,o,r){super(t,e,n,o,r),this.type=5}_$AI(t,e=this){if((t=Bt(this,t,e,0)??Rt)===Dt)return;const n=this._$AH,o=t===Rt&&n!==Rt||t.capture!==n.capture||t.once!==n.once||t.passive!==n.passive,r=t!==Rt&&(n===Rt||o);o&&this.element.removeEventListener(this.name,this,n),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class Zt{constructor(t,e,n){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(t){Bt(this,t)}}const Xt={M:yt,P:bt,A:wt,C:1,L:zt,R:Wt,D:Et,V:Bt,I:qt,H:Gt,N:Jt,U:Yt,B:Kt,F:Zt},Qt=gt.litHtmlPolyfillSupport;Qt?.(Ht,qt),(gt.litHtmlVersions??=[]).push("3.3.0");const te=(t,e,n)=>{const o=n?.renderBefore??e;let r=o._$litPart$;if(void 0===r){const t=n?.renderBefore??null;o._$litPart$=r=new qt(e.insertBefore(xt(),t),t,void 0,n??{})}return r._$AI(t),r},ee=globalThis;class ne extends ft{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=te(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Dt}}ne._$litElement$=!0,ne.finalized=!0,ee.litElementHydrateSupport?.({LitElement:ne});const oe=ee.litElementPolyfillSupport;oe?.({LitElement:ne}),(ee.litElementVersions??=[]).push("4.2.2");var re=n(365),ie=n.n(re),se=function(t,e,n,o){return new(n||(n=Promise))(function(r,i){function s(t){try{l(o.next(t))}catch(t){i(t)}}function a(t){try{l(o.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}l((o=o.apply(t,e||[])).next())})};const ae="\n query TypeNamesQuery {\n __schema {\n queryType {\n name\n }\n types {\n name\n kind\n }\n }\n }\n";class le{constructor(t){this.type="graphql",this.method="POST",this.headers={},this.backendType="generic",this.types=[],this.queryables=[],this.queryType="",this.ready=!1,this.eventListeners={},this.id=t.id.toString(),this.label=t.label,this.url=t.url,this.type=t.type,this.method=t.method||"POST",this.headers=t.headers||{},this.queryable=t.queryable,this.readonly=t.readonly,this.hidden=t.hidden,this.backendType=t.backendType||"generic",this.disabledTypes=t.disabledTypes}on(t,e){this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(e)}off(t,e){this.eventListeners[t]&&(this.eventListeners[t]=e?this.eventListeners[t].filter(t=>t!==e):[])}trigger(t,...e){this.eventListeners[t]&&this.eventListeners[t].forEach(t=>t(...e))}fetchTypeNames(){return se(this,void 0,void 0,function*(){var t,e,n;try{const o=yield this.call(ae);if(!(null===(e=null===(t=o.data)||void 0===t?void 0:t.__schema)||void 0===e?void 0:e.types))throw new Error(`Invalid response: ${JSON.stringify(o)}`);const r=(null===(n=o.data.__schema.queryType)||void 0===n?void 0:n.name)||"Query";return{types:o.data.__schema.types.filter(t=>!t.name.startsWith("__")),queryTypeName:r}}catch(t){throw console.error("[GraphQL] Failed to fetch type names:",t.message),new Error(`Failed to fetch type names: ${t.message}`)}})}static getDefaultEnabledTypes(t,e,n="Query"){const o=e.map(t=>t.name),r=e.filter(t=>"SCALAR"===t.kind).map(t=>t.name);switch(t){case"gitlab":{const t=["Project","Namespace","User","Group","Repository","Commit","Branch","MergeRequest","Issue","Pipeline","Job","Release","Milestone","Label","Note","Discussion","Snippet","Board","Epic","Vulnerability","Package","ContainerRepository","Environment","Deployment","CiRunner","Topic","PageInfo"],e=[...r,n,...t,...o.filter(e=>!e.endsWith("Input")&&!e.endsWith("Enum")&&(e.endsWith("Connection")||e.endsWith("Edge")||t.some(t=>e.startsWith(t))))];return o.filter(t=>e.includes(t))}case"wordpress":{const t=e.filter(t=>"INPUT_OBJECT"===t.kind).map(t=>t.name),n=["RootMutation","Settings","DiscussionSettings","GeneralSettings","ReadingSettings","WritingSettings","Plugin","Theme","UserRole","Avatar","ContentTemplate","DefaultTemplate"],r=[/^Create.+Input$/,/^Update.+Input$/,/^Delete.+Input$/,/^Register.+Input$/,/^Reset.+Input$/,/^Restore.+Input$/,/^Send.+Input$/,/Payload$/,/^RootQueryToPlugin/,/^RootQueryToTheme/,/^RootQueryToUserRole/,/Plugin(?:Connection|Edge|PageInfo|Status)/,/Theme(?:Connection|Edge|PageInfo)/,/UserRole(?:Connection|Edge|PageInfo)/,/Enqueued/,/Script(?!$)/,/Stylesheet/,/Revision/,/Comment/,/Commenter/,/PostFormat/,/^RootQueryToContentNode/],i=e=>!!t.includes(e)||!!n.includes(e)||r.some(t=>t.test(e));return o.filter(t=>!i(t))}case"strapi":{const t=e.filter(t=>"INPUT_OBJECT"===t.kind).map(t=>t.name),n=["Mutation","GenericMorph"],r=[/Payload$/,/^UsersPermissions/,/^UploadFolder/,/^I18N/,/EntityResponse$/,/EntityResponseCollection$/,/^ContentType/,/^Admin/],i=e=>!!t.includes(e)||!!n.includes(e)||r.some(t=>t.test(e));return o.filter(t=>!i(t))}case"supabase":{const t=e.filter(t=>"INPUT_OBJECT"===t.kind).map(t=>t.name),n=["Mutation","Cursor"],r=[/InsertInput$/,/UpdateInput$/,/DeleteInput$/,/InsertResponse$/,/UpdateResponse$/,/DeleteResponse$/,/OrderBy$/,/OrderByDirection$/,/Filter$/,/FilterInput$/,/Edge$/],i=e=>!!t.includes(e)||!!n.includes(e)||r.some(t=>t.test(e));return o.filter(t=>!i(t))}default:return[...o]}}triggerError(t){throw console.error("GraphQL error:",t),this.trigger(r,t,this),new Error(t)}loadData(){return se(this,void 0,void 0,function*(){var t,e,n,o,r,i;try{let s,a;if(this.disabledTypes&&this.disabledTypes.length>0){const o=yield this.call(ae);if(!(null===(e=null===(t=o.data)||void 0===t?void 0:t.__schema)||void 0===e?void 0:e.types))return this.triggerError(`Invalid lightweight response: ${JSON.stringify(o)}`);const r=o.data.__schema.types.map(t=>t.name).filter(t=>!t.startsWith("__")),i=(null===(n=o.data.__schema.queryType)||void 0===n?void 0:n.name)||"Query",l=o.data.__schema.types.filter(t=>"SCALAR"===t.kind&&!t.name.startsWith("__")).map(t=>t.name),c=r.filter(t=>!this.disabledTypes.includes(t));!c.includes(i)&&r.includes(i)&&c.push(i);for(const t of l)c.includes(t)||c.push(t);const u="gitlab"===this.backendType?5:100,p=[];for(let t=0;t<c.length;t+=u)p.push(c.slice(t,t+u));const d=yield Promise.all(p.map(t=>se(this,void 0,void 0,function*(){try{const e=`\n query BatchTypeIntrospection {\n${t.map(t=>` type_${t.replace(/[^a-zA-Z0-9_]/g,"_")}: __type(name: "${t}") { ...SelectiveType }`).join("\n")}\n }\n \n fragment SelectiveType on __Type {\n name\n kind\n fields(includeDeprecated: false) {\n name\n args {\n name\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n defaultValue\n }\n type {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n\n `,n=yield this.call(e),o=[];for(const[t,e]of Object.entries(n.data||{}))t.startsWith("type_")&&null!==e&&o.push(e);return o}catch(t){return console.warn("[GraphQL] Failed to fetch batch:",t.message),[]}})));s=d.flat(),a=i}else{const t=yield this.call("\n query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n types {\n ...FullType\n }\n }\n }\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: false) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: false) {\n name\n description\n }\n possibleTypes {\n ...TypeRef\n }\n }\n fragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n }\n fragment TypeRef on __Type {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n ofType {\n kind\n name\n possibleTypes {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n }\n");if(!(null===(r=null===(o=t.data)||void 0===o?void 0:o.__schema)||void 0===r?void 0:r.types))return this.triggerError(`Invalid response: ${JSON.stringify(t)}`);s=t.data.__schema.types,a=null===(i=t.data.__schema.queryType)||void 0===i?void 0:i.name}if(!a)return this.triggerError("Invalid response, queryType not found");const l=s.map(t=>t.name).concat(_),c=s.find(t=>t.name===a);if(!c)return this.triggerError(`Query type "${a}" not found in schema. Make sure to enable it.`);const u=s.filter(t=>!t.name.startsWith("__")).filter(t=>{var e;return!(null===(e=null==c?void 0:c.fields)||void 0===e?void 0:e.find(e=>e.name===t.name))}).map(t=>this.graphQLToType(l,t,"SCALAR",!1)).concat(S),p=(c.fields||[]).map(t=>({type:Object.assign(Object.assign({},s.find(e=>e.name===this.getOfTypeProp("name",t.type,t.name))),{name:t.name}),kind:this.ofKindToKind(t.type)})).filter(({type:t})=>void 0!==t.fields).map(({type:t,kind:e})=>this.graphQLToType(l,t,e,!0)),d=(c.fields||[]).filter(t=>{const e=this.getOfTypeProp("name",t.type,t.name);return s.some(t=>t.name===e)||_.includes(e)}).map(t=>this.graphQLToField(t));return[p.concat(u),d,a]}catch(t){return this.triggerError(`GraphQL introspection failed: ${t.message}`)}})}graphQLToField(t){var e;const n=this.ofKindToKind(t.type);return{id:t.name,dataSourceId:this.id,label:t.name,typeIds:this.graphQLToTypes(t),kind:n?this.graphQLToKind(n):"unknown",arguments:null===(e=t.args)||void 0===e?void 0:e.map(t=>({name:t.name,typeId:this.getOfTypeProp("name",t.type,t.name),defaultValue:t.defaultValue}))}}getOfTypeProp(t,e,n){const o=this.getOfTypePropRecursive(t,e);if(o)return o;if(n)return n;throw new Error(`Type ${JSON.stringify(e)} has no property ${t} and no default was provided`)}getOfTypePropRecursive(t,e){if(!e)throw console.error("Invalid type",e),new Error("Invalid type");if(e.ofType){const n=this.getOfTypePropRecursive(t,e.ofType);if(n)return n}return e[t]}graphQLToTypes(t){const e=this.getOfTypeProp("possibleTypes",t.type,[]);return e.length>0?e.map(t=>t.name):[this.getOfTypeProp("name",t.type,t.name)]}graphQLToKind(t){switch(t){case"LIST":return"list";case"OBJECT":return"object";case"SCALAR":return"scalar";default:throw new Error(`Unable to find a valid kind for ${t}`)}}validKind(t){return["LIST","OBJECT","SCALAR"].includes(t)}ofKindToKind(t){if(t.possibleTypes){const e=t.possibleTypes.reduce((e,n)=>{if(!e)return n.kind;if(e!==n.kind)throw new Error(`Unable to find a valid kind for ${t.kind}. Union types with different kind is not supported`);return e},null);return e||(console.error("Unable to find a valid kind (1)",t),null)}return this.validKind(t.kind)?t.kind:t.ofType?this.ofKindToKind(t.ofType):null}graphQLToType(t,e,n,o){var r,i,s;const a=this.queryable;return{id:e.name,dataSourceId:this.id,label:e.name,fields:null!==(s=null===(i=null===(r=e.fields)||void 0===r?void 0:r.filter(e=>t.includes(this.getOfTypeProp("name",e.type,e.name))))||void 0===i?void 0:i.map(t=>this.graphQLToField(t)))&&void 0!==s?s:[],queryable:o&&(!a||a.includes(e.name))}}connect(){return se(this,void 0,void 0,function*(){try{const[t,n,o]=yield this.loadData();if(0===t.length)return this.triggerError("No types found in GraphQL schema");if(0===n.length)return this.triggerError("No fields found in GraphQL schema");if(!o)return this.triggerError("No query type found in GraphQL schema");this.types=t,this.queryables=n,this.queryType=o,this.ready?this.trigger(i,this):(this.ready=!0,this.trigger(e,this))}catch(t){return this.triggerError(`GraphQL connection failed: ${t.message}`)}})}isConnected(){return this.ready}getTypes(){if(!this.ready)throw console.error("DataSource is not ready. Attempted to get types before ready status was achieved."),new Error("DataSource is not ready. Ensure it is connected and ready before querying.");if(0===this.types.length)throw console.error("No types available. It seems the data source may not be connected or the schema is incomplete.",this.ready),new Error("No types found. The data source may not be connected or there might be an issue with the schema.");return this.types}getQueryables(){return this.queryables}call(t){return se(this,void 0,void 0,function*(){var e;const n=this.url;if(!n)return this.triggerError("Missing GraphQL URL");const o=this.headers;if(!o)return this.triggerError("Missing GraphQL headers");const r=Object.keys(o).find(t=>"content-type"===t.toLowerCase());o[r||"Content-Type"]=o[r||"Content-Type"]||"application/json";const i=null!==(e=this.method)&&void 0!==e?e:"POST",s=yield fetch(n,Object.assign({method:i,headers:o},"POST"===i?{body:JSON.stringify({query:t})}:{}));return(null==s?void 0:s.ok)?s.json():(console.error("GraphQL call failed",null==s?void 0:s.status,null==s?void 0:s.statusText,t),this.triggerError(`GraphQL call failed with \`${null==s?void 0:s.statusText}\` and status ${null==s?void 0:s.status}`))})}getQuery(t){return this.getQueryRecursive({token:{dataSourceId:this.id,fieldId:"query",kind:"object",typeIds:[this.queryType]},children:t})}getQueryRecursive(e,n="",o=""){const r=o?`...on ${o}`:`${e.token.fieldId}${function(t){const e=t?`(${Object.keys(t).map(e=>({key:e,value:t[e]})).filter(({value:t})=>!Te(t)).map(({key:t,value:e})=>`${t}: ${e}`).join(", ")})`:"";return"()"===e?"":e}(e.token.options)}`;switch(e.token.kind){case"scalar":return e.token.fieldId===t?"":n+r;case"object":case"list":{const t=this.getTypes().filter(t=>{var n;return null===(n=e.token.typeIds)||void 0===n?void 0:n.includes(t.id)});if(0===t.length)throw new Error(`Type not found for ${e.token.fieldId} (${e.token.typeIds})`);if(t.length>1)throw new Error(`Multiple types found for ${e.token.fieldId}`);const o=t[0],i=e.children.map(t=>{const e=o.fields.find(e=>e.id===t.token.fieldId);return e?{fieldType:e,child:t}:null}).filter(t=>null!==t),s=i.filter(({fieldType:t})=>t.typeIds.length>1).map(({child:t})=>({query:this.getQueryRecursive(t,n+" ",t.token.typeIds[0]),child:t})).map(({query:t,child:e})=>ie()` ${n}${e.token.fieldId} { ${t} } `).join("\n"),a=i.filter(({fieldType:t})=>1===t.typeIds.length).map(({child:t})=>this.getQueryRecursive(t,n+" ")).join("\n");return ie()`${n}${r} { ${n} __typename ${a} ${s} ${n}}`}default:throw console.error("Unable to build GraphQL query",e),new Error(`Unable to build GraphQL query: unable to build tree ${JSON.stringify(e)}`)}}fetchValues(t){return se(this,void 0,void 0,function*(){return(yield this.call(t)).data})}}const ce="Data source";function ue(t){const e=t.parent(),n=null==e?void 0:e.getName(),o=null==e?void 0:e.get("tagName"),r=n?`${n} (${o})`:o,i=t.cid,s=t.get("tagName"),a=t.getClasses(),l=a.length?`.${a.join(".")}`:"";return`${r} > ${t.getName()} (${s}#${i}${l})`}function pe(t,e){switch(e.type){case"property":{const t=function(t,e){const n=t.join(", ").toLowerCase();return"list"===e?` (${n}[])`:"object"===e?` (${n}{})`:` (${n})`}(e.typeIds,e.kind);return`${e.label} ${t}`}case"filter":return e.label;case"state":return function(t,e){var n;const o=j(e.componentId,t),r=null!==(n=null==o?void 0:o.get(k))&&void 0!==n?n:"";return`${r?r+" ":""}${e.label||e.storedStateId}`}(t,e);default:throw console.error("Unknown token type (reading type)",e),new Error("Unknown token type")}}function de(t,e,n,o){return n.reduce((n,r)=>{var i,s,a,l;let c;switch(r.type){case"filter":c="Filters";break;case"property":if(r.dataSourceId)if(o.length>0)try{const t=Ce(o,e);c=null!==(s=null!==(i=null==t?void 0:t.label)&&void 0!==i?i:null==t?void 0:t.id)&&void 0!==s?s:"Unknown"}catch(t){console.error("Error while getting expression result type in groupByType",{expression:o,component:e}),c="Unknown"}else{const e=W(r.dataSourceId);if(!e)throw console.error("Data source not found",r.dataSourceId),t.runCommand("notifications:add",{type:"error",group:ce,message:`Data source not found: ${r.dataSourceId}`}),new Error(`Data source not found: ${r.dataSourceId}`);c=e.label||(null===(l=(a=e).get)||void 0===l?void 0:l.call(a,"label"))||r.dataSourceId}else c="Fields";break;case"state":{const t=j(r.componentId,e),n="body"===(null==t?void 0:t.get("tagName"))?"Website":null==t?void 0:t.getName();c=n?`${n}'s states`:"States";break}default:throw console.error("Unknown token type (reading type)",r),new Error("Unknown token type")}return n[c]||(n[c]=[]),n[c].push(r),n},{})}function he(e){return{type:"property",propType:"field",fieldId:t,label:"Fixed value",kind:"scalar",typeIds:["String"],options:{value:e},optionsForm:()=>Nt` <label>Value <input type="text" name="value" .value=${e}> </label> `}}function fe(t){return JSON.stringify(Object.assign({},t))}function ge(t){switch(t.type){case"property":return`property__${t.dataSourceId||""}__${t.fieldId}__${t.kind}__${t.typeIds.join(",")}`;case"filter":return`filter____${t.id}`;case"state":return`state__${t.componentId}__${t.storedStateId}`;default:throw console.error("Unknown token type (reading type)",t),new Error("Unknown token type")}}function me(t,e,n){return Se(JSON.parse(e),n)}function ve(e){try{return"string"==typeof e&&(e=JSON.parse(e)),function(e){if("string"==typeof e)throw new Error("json must be parsed");return!!Array.isArray(e)&&e.every(e=>{var n;if("object"!=typeof e)return!1;if(!e.type)return!1;switch(e.type){case"property":if(!e.fieldId)return!1;if(e.fieldId===t&&!(null===(n=e.options)||void 0===n?void 0:n.value))return!1;break;case"state":if(!e.componentId)return!1;if(!e.storedStateId)return!1;break;case"filter":if(!e.id)return!1}return!0})}(e)?e:null}catch(t){return null}}function ye(t,e,n){if(!t)return null;if(t.kind!==e)throw console.error(`Field is not a ${e}`,t),new Error(`Field ${t.label} is not a ${e}`);return Object.assign(Object.assign({},t),{kind:n})}function be(t,e){if(void 0===t)throw new Error("el option must be set");if("string"==typeof t){const e=document.querySelector(t);if(!e)throw new Error(`Element ${t} not found`);return e}if("function"==typeof t){const e=t();if(!e)throw new Error("el option must be a returned by the provided function");return e}if(t instanceof HTMLElement)return t;throw new Error(`${e} must be a string or an HTMLElement or a function`)}function we(t=Math.random().toString(36).slice(2,8)){return{id:`ds-${t}`,label:"New data source",type:"graphql",url:"",method:"POST",headers:{},readonly:!1}}function _e(t={},e){const n=Object.assign(Object.assign({},we(e)),t);if("graphql"===n.type)return new le(n);throw new Error(`Unknown data source type: ${n.type}`)}function Se(t,e){var n;if(!t||"object"!=typeof t)throw console.error("Invalid token: not an object",t),new Error("Invalid token: expected an object");if(!t.type)throw console.error("Invalid token: missing type property",t),new Error("Invalid token: missing type property");switch(t.type){case"filter":{if(t.optionsForm)return t;const e=Xe().find(e=>e.id===t.id);if(!e)throw console.error("Filter not found",t),new Error(`Filter ${t.id} not found`);return Object.assign(Object.assign(Object.assign({},e),t),{type:"filter"})}case"property":{if(t.optionsForm)return t;const o=xe(t,e);if(!o)throw console.error("Field not found for token",t),new Error(`Field ${t.fieldId} not found`);return Object.assign(Object.assign(Object.assign({},null!==(n=Oe(o))&&void 0!==n?n:{}),t),{type:"property",propType:"field"})}case"state":return t;default:throw console.error("Unknown token type (reading type)",t),new Error("Unknown token type")}}function xe(t,e){var n,o;const r=Ye(),i=r.cachedTypes.length>0?r.cachedTypes:[],s=[];for(const a of t.typeIds){const l=i.find(e=>e.id===a&&(!t.dataSourceId||e.dataSourceId===t.dataSourceId));l?s.push(l.label):(r.editor.runCommand("notifications:add",{type:"error",group:ce,message:`Type not found ${null!==(n=t.dataSourceId)&&void 0!==n?n:""}.${a}`,componentId:e}),console.error(`Type not found ${null!==(o=t.dataSourceId)&&void 0!==o?o:""}.${a}`))}const a=t.options?Object.entries(t.options).map(([t,e])=>({typeId:"JSON",name:t,defaultValue:e})):void 0;return{id:t.fieldId,label:s.length>0?s.join(", "):t.label,typeIds:t.typeIds,kind:t.kind,dataSourceId:t.dataSourceId,arguments:a,previewIndex:t.previewIndex}}function Ce(t,e){return t.reduce((t,n)=>function(t,e,n){var o,r,i;switch(t.type){case"filter":try{const r=function(t,e){if("filter"!==t.type)throw new Error("Token is not a filter");const n=e.find(e=>e.id===t.id);if(!n)throw console.error("Filter not found",t),new Error(`Filter ${t.id} not found`);return Object.assign(Object.assign(Object.assign({},t),n),{options:t.options})}(t,Xe());try{if(r.validate(e))return r.output(e,null!==(o=r.options)&&void 0!==o?o:{})}catch(n){return console.warn("Filter validate error:",n,{token:t,prev:e}),null}return null}catch(o){return console.error("Error while getting filter result type",{token:t,prev:e,component:n}),null}case"property":try{return xe(t,n.getId())}catch(e){return console.error("Error while getting property result type",{token:t,component:n}),null}case"state":{const o=j(t.componentId,n);if(!o)return console.warn("Component not found for state",t),Ye().editor.runCommand("notifications:add",{type:"error",group:ce,message:`Component not found for state: ${t.storedStateId}`,componentId:n.getId()}),null;const s=null===(r=D(o,t.storedStateId,t.exposed))||void 0===r?void 0:r.expression;if(!s)return console.warn("State is not defined on component",{component:o,token:t}),Ye().editor.runCommand("notifications:add",{type:"error",group:ce,message:`State '${t.storedStateId}' is not defined on component '${o.getName()||o.get("id")}'`,componentId:o.getId()}),null;try{const e=Ce(s,o);return e?Object.assign(Object.assign({},e),{kind:null!==(i=t.forceKind)&&void 0!==i?i:e.kind}):null}catch(r){return console.error("Error while getting expression result type in tokenToField",{expression:s,parent:o,component:n,token:t,prev:e}),null}}default:throw console.error("Unknown token type (reading type)",t),new Error("Unknown token type")}}(Se(n,e.getId()),t,e),null)}function Oe(t){return t.arguments&&t.arguments.length>0?{optionsForm:(e=t.arguments.map(t=>({name:t.name,value:t.defaultValue})),(t,n,o)=>Nt` ${e.map(t=>{var e,n;const r=null!==(n=null!==(e=o[t.name])&&void 0!==e?e:t.value)&&void 0!==n?n:"";return Nt`<label>${t.name}</label><input type="text" name=${t.name} .value=${r}>`})} `),options:t.arguments.reduce((t,e)=>(t[e.name]=e.defaultValue,t),{})}:null;var e}function Ee(t,e){if(!t&&!e)return{error:!1,result:void 0};if(Te(t)&&Te(e))return{error:!1,result:void 0};if(!t||!e)return{error:!0,result:void 0};if(Te(t)||Te(e))return{error:!0,result:void 0};const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return{error:!0,result:void 0};for(const o of n)if(t[o]!==e[o])return{error:!0,result:void 0};return{error:!1,result:t}}function Te(t){if(null==t)return!0;const e="string"==typeof t,n=e&&function(t){if("string"!=typeof t)return!1;if(0===t.length)return!1;try{JSON.parse(t)}catch(t){return!1}return!0}(t);if(e&&!n)return""===t;const o=n?JSON.parse(t):t;return null===o||(Array.isArray(o)?0===o.length:"object"==typeof o&&0===Object.values(o).filter(t=>!!t).length)}function Ae(t,e){return void 0===e.previewIndex?t:Array.isArray(t)?t[e.previewIndex]:t}function ke(e,n,o=null){if(0===e.length)return o;const r=e.map(t=>Object.assign({},t)),[i,...s]=r;switch(i.type){case"state":return function(t,e,n,o){var r;const i=Pe(t,n.component,n);if(!i)throw new Error(`Unable to resolve state: ${JSON.stringify(t)}`);const s=null===(r=i[i.length-1])||void 0===r?void 0:r.previewIndex;return"items"===t.storedStateId&&void 0!==s&&(i[0].isItems=!0),ke([...i,...e],n,o)}(i,s,n,o);case"property":return function(e,n,o,r){var i;if(e.fieldId===t)return ke(n,o,null===(i=e.options)||void 0===i?void 0:i.value);let s;if(null==r){if(!e.dataSourceId)throw new Error(`Data source ID is missing for token: ${JSON.stringify(e)}`);s=o.previewData[e.dataSourceId]}else s=r;let a=s?s[e.fieldId]:null;if(o.resolvePreviewIndex){const t=n[0];t&&"filter"===t.type||(a=Ae(a,e))}return n.length>0&&!o.resolvePreviewIndex&&"filter"!==n[0].type&&(a=Ae(a,e)),e.isItems&&void 0!==e.previewIndex&&n.length>0&&(a=[a]),ke(n,o,a)}(i,s,n,o);case"filter":return function(t,e,n,o){var r;const i=Object.entries(t.options).reduce((t,[e,o])=>{const r=ve(o);return t[e]=r?ke(r,n,null):o,t},{}),s=n.filters.find(e=>e.id===t.id);if(!s)throw new Error(`Filter not found: ${t.id}`);let a;try{a=s.apply(o,i)}catch(t){return console.warn(`Filter "${s.id}" error:`,t,{filter:s.id,prevValues:o,options:i,valueType:typeof o,isArray:Array.isArray(o),isNull:null===o}),null}return e.length>0&&"filter"===(null===(r=e[0])||void 0===r?void 0:r.type)||!(n.resolvePreviewIndex||e.length>0)||(a=Ae(a,t)),ke(e,n,a)}(i,s,n,o);default:throw new Error(`Unsupported token type: ${JSON.stringify(i)}`)}}function Pe(t,e,n){const o=j(t.componentId,e);if(!o)return console.error("Component not found for state",t,e.get("id-plugin-data-source")),null;const r=D(o,t.storedStateId,t.exposed);return(null==r?void 0:r.expression)?r.expression.flatMap(t=>{var r;return"state"===t.type?null!==(r=Pe(Se(t,e.getId()),o,n))&&void 0!==r?r:[]:t}):(console.warn("State is not defined on component",o.getId(),t,r),null)}function $e(t,e){const n=[],o=e.getMainComponent();return o&&o.onAll(t=>{N(t,!0).concat(N(t,!1)).forEach(e=>{e.expression&&n.push({expression:e.expression,component:t})}),Object.values(t.getAttributes()).forEach(e=>{const o=ve(e);o&&n.push({expression:o,component:t})})}),n}function je(t,{expression:e,component:n},o){if(0===e.length)return[];const r=e[0];switch(r.type){case"property":{if(r.dataSourceId!==o)return[];const i=je(t,{expression:e.slice(1),component:n},o);return 0===i.length?[{token:r,children:[]}]:i.flatMap(e=>function(t,e,n,o){const r=t.dataSources.find(t=>t.id===o);if(!r)throw new Error(`Data source not found ${o}`);if(!r.isConnected())throw new Error(`Data source ${o} is not ready (not connected)`);const i=r.getTypes().filter(t=>e.typeIds.includes(t.id)),s=i.flatMap(t=>t.fields.map(t=>t.typeIds).flat());return s.length>0&&n.typeIds.some(t=>s.includes(t))}(t,r,e.token,o)?{token:r,children:[e]}:[{token:r,children:[]},e])}case"filter":{const i=Object.values(r.options).map(t=>ve(t)).filter(t=>!!t&&t.length>0).flatMap(e=>je(t,{expression:e,component:n},o)),s=je(t,{expression:e.slice(1),component:n},o);return 0===s.length?i:s.flatMap(t=>[t,...i])}case"state":{const e=Pe(r,n,t);if(!e)throw t.editor.runCommand("notifications:add",{type:"error",group:ce,message:`Unable to resolve state <pre>${JSON.stringify(r)}</pre>`,componentId:n.getId()}),new Error(`Unable to resolve state ${JSON.stringify(r)}. State defined on component ${ue(n)}`);return je(t,{expression:e,component:n},o)}default:throw t.editor.runCommand("notifications:add",{type:"error",group:ce,message:`Invalid expression <pre>${JSON.stringify(e)}</pre>`,componentId:n.getId()}),new Error(`Invalid expression ${JSON.stringify(e)}. Expression used on component ${ue(n)}`)}}function Ie(t,e,n){return 0===e.length?[]:e.flatMap(e=>je(t,e,n)).reduce((t,e)=>{const n=t.find(t=>t[0].token.fieldId===e.token.fieldId&&(!e.token.dataSourceId||t[0].token.dataSourceId===e.token.dataSourceId));return n?n.push(e):t.push([e]),t},[]).map(n=>{try{return n.reduce((t,e)=>Me(t,e))}catch(o){throw t.editor.runCommand("notifications:add",{type:"error",group:ce,message:`Unable to merge trees <pre>${JSON.stringify(n)}</pre>`,componentId:e[0].component.getId()}),o}})}function Me(t,e){if(t.token.dataSourceId!==e.token.dataSourceId)throw console.error("Unable to merge trees",t,e),new Error(`Unable to build GraphQL query: unable to merge trees ${JSON.stringify(t)} and ${JSON.stringify(e)}`);const n=t.children.filter(t=>e.children.find(e=>t.token.fieldId===e.token.fieldId&&Ee(t.token.options,e.token.options).error)).map(t=>{const n=e.children.find(e=>t.token.fieldId===e.token.fieldId);return`${t.token.fieldId} appears twice with different options: ${JSON.stringify(t.token.options)} vs ${JSON.stringify(null==n?void 0:n.token.options)}`});if(n.length>0)throw console.error("Unable to merge trees",n),new Error(`Unable to build GraphQL query: unable to merge trees: \n* ${n.join("\n* ")}`);const o=t.children.filter(t=>!e.children.find(e=>t.token.fieldId===e.token.fieldId&&t.token.typeIds.join(",")===e.token.typeIds.join(",")&&!Ee(t.token.options,e.token.options).error)).concat(e.children.filter(e=>!t.children.find(t=>t.token.fieldId===e.token.fieldId&&t.token.typeIds.join(",")===e.token.typeIds.join(",")&&!Ee(t.token.options,e.token.options).error))),r=t.children.filter(t=>e.children.find(e=>t.token.fieldId===e.token.fieldId&&t.token.typeIds.join(",")===e.token.typeIds.join(",")&&!Ee(t.token.options,e.token.options).error));return{token:t.token,children:o.concat(r.map(t=>{const n=e.c