@storyblok/js 2.0.6 → 2.0.8

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.
@@ -1,3 +1,3 @@
1
- (function(h,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(h=typeof globalThis!="undefined"?globalThis:h||self,u(h.storyblok={}))})(this,function(h){"use strict";var ce=Object.defineProperty,he=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var P=(h,u,g)=>u in h?ce(h,u,{enumerable:!0,configurable:!0,writable:!0,value:g}):h[u]=g,f=(h,u)=>{for(var g in u||(u={}))de.call(u,g)&&P(h,g,u[g]);if(O)for(var g of O(u))pe.call(u,g)&&P(h,g,u[g]);return h},b=(h,u)=>he(h,ue(u));let u=!1;const g=[],R=n=>new Promise((e,t)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}u?r():g.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{g.forEach(o=>o()),u=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var I=Object.defineProperty,C=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,c=(n,e,t)=>(C(n,typeof e!="symbol"?e+"":e,t),t);function _(n){return!(n!==n||n===1/0||n===-1/0)}function M(n,e,t){if(!_(e))throw new TypeError("Expected `limit` to be a finite number");if(!_(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const i=function(){o++;const l=setTimeout(function(){o--,s.length>0&&i(),r=r.filter(function(p){return p!==l})},t);r.indexOf(l)<0&&r.push(l);const d=s.shift();d.resolve(n.apply(d.self,d.args))},a=function(...l){const d=this;return new Promise(function(p,T){s.push({resolve:p,reject:T,args:l,self:d}),o<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(l){l.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const A=function(n,e){const t={};for(const s in n){const r=n[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},N=n=>n==="email",L=()=>({singleTag:"hr"}),U=()=>({tag:"blockquote"}),B=()=>({tag:"ul"}),H=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),q=()=>({singleTag:"br"}),D=n=>({tag:`h${n.attrs.level}`}),J=n=>({singleTag:[{tag:"img",attrs:A(n.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),V=()=>({tag:"ol"}),z=()=>({tag:"p"}),Y=()=>({tag:"b"}),K=()=>({tag:"strike"}),Q=()=>({tag:"u"}),G=()=>({tag:"strong"}),W=()=>({tag:"code"}),X=()=>({tag:"i"}),Z=n=>{const e=f({},n.attrs),{linktype:t="url"}=n.attrs;return N(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},ee=n=>({tag:[{tag:"span",attrs:n.attrs}]}),j={nodes:{horizontal_rule:L,blockquote:U,bullet_list:B,code_block:H,hard_break:q,heading:D,image:J,list_item:F,ordered_list:V,paragraph:z},marks:{bold:Y,strike:K,underline:Q,strong:G,code:W,italic:X,link:Z,styled:ee}},te=function(n){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return n&&s.test(n)?n.replace(t,r=>e[r]):n};class m{constructor(e){c(this,"marks"),c(this,"nodes"),e||(e=j),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e){if(e&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(te(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const i=s.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class ${constructor(){c(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),c(this,"getOptionsPage",(e,t=25,s=1)=>b(f({},e),{per_page:t,page:s})),c(this,"delay",e=>new Promise(t=>setTimeout(t,e))),c(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),c(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,i)=>i*r+e)}),c(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),c(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],a=s?"":encodeURIComponent(o);let l;typeof i=="object"?l=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):l=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(l)}return r.join("&")}}class se{constructor(e){c(this,"baseURL"),c(this,"timeout"),c(this,"headers"),c(this,"responseInterceptor"),c(this,"fetch"),c(this,"ejectInterceptor"),c(this,"url"),c(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e.timeout?e.timeout*1e3:1e3,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers=f({},t),s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){const t=new URL(`${this.baseURL}${this.url}`);let s=null;if(e==="get"){const a=new $;t.search=a.stringify(this.parameters)}else s=JSON.stringify(this.parameters);const r=new AbortController,{signal:o}=r,i=setTimeout(()=>r.abort(),this.timeout);try{const a=await this.fetch(`${t}`,{method:e,headers:this.headers,body:s,signal:o});clearTimeout(i);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return a}}eject(){this.ejectInterceptor=!0}_statusHandler(e){if(/20[01]/g.test(`${e.status}`))return e;throw{message:new Error(e.statusText||`status: ${e.status}`),response:e}}}let k={};const y={};class re{constructor(e,t){if(c(this,"client"),c(this,"maxRetries"),c(this,"throttle"),c(this,"accessToken"),c(this,"cache"),c(this,"helpers"),c(this,"relations"),c(this,"links"),c(this,"richTextResolver"),c(this,"resolveNestedRelations"),!t){const o=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${o}.storyblok.com/v1`:t=`${i}://api${o}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((o,i)=>{e.headers&&e.headers[i]&&s.set(i,e.headers[i])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new m(e.richTextSchema):this.richTextResolver=new m,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=M(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new $,this.resolveNestedRelations=!1,this.client=new se({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=y[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),a=s||i[i.length-1],l=1,d=await this.makeRequest(o,t,r,l),p=d.total?Math.ceil(d.total/r):1,T=await this.helpers.asyncMap(this.helpers.range(l,p),w=>this.makeRequest(o,t,r,w+1));return this.helpers.flatMap([d,...T],w=>Object.values(w.data[a]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t]&&e[t].constructor===Array){const r=[];e[t].forEach(o=>{this.relations[o]&&r.push(this._cleanCopy(this.relations[o]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let o=0;o<r.length;o++)s(r[o]);else if(r.constructor===Object){if(r._stopResolving)return;for(const o in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,o,t),this._insertLinks(r,o)),s(r[o])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);o.push(e.link_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]=b(f({},r),{_stopResolving:!0})})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);o.push(e.rel_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=b(f({},r),{_stopResolving:!0})})}async resolveStories(e,t){var s,r;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&(((s=e.links)==null?void 0:s.length)||((r=e.link_uuids)==null?void 0:r.length))&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(i=>{this.iterateTree(i,o)})}cacheResponse(e,t,s){return new Promise((r,o)=>{const i=this.helpers.stringify({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=a.get(i);if(l)return r(l)}try{(async()=>{var l;const d=await this.throttle("get",e,t);let p={data:d.data,headers:d.headers};if((l=d.headers)!=null&&l["per-page"]&&(p=Object.assign({},p,{perPage:d.headers["per-page"]?parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?parseInt(d.headers.total):0})),d.status!=200)return o(d);(p.data.story||p.data.stories)&&await this.resolveStories(p.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,p),p.data.cv&&t.token&&(t.version=="draft"&&y[t.token]!=p.data.cv&&this.flushCache(),y[t.token]=p.data.cv),r(p)})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return y}cacheVersion(){return y[this.accessToken]}setCacheVersion(e){this.accessToken&&(y[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return k[e]},getAll(){return k},set(e,t){k[e]=t},flush(){k={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}flushCache(){return this.cacheProvider().flush(),this}}const oe=(n={})=>{const{apiOptions:e}=n;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new re(e)}};var ne=n=>{if(typeof n!="object"||typeof n._editable=="undefined")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let v;const E="https://app.storyblok.com/f/storyblok-v2-latest.js",S=(n,e,t={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],r=>{r.action==="input"&&r.story.id===n?e(r.story):(r.action==="change"||r.action==="published")&&r.storyId===n&&window.location.reload()})})}},ie=(n={})=>{const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={}}=n;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let a={};return s.forEach(l=>{a=f(f({},a),l(i))}),e!==!1&&R(E),v=new m(o.schema),o.resolver&&x(v,o.resolver),a},x=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ae=(n,e,t)=>{let s=t||v;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return n===""?"":n?(e&&(s=new m(e.schema),e.resolver&&x(s,e.resolver)),s.render(n)):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
1
+ (function(d,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(d=typeof globalThis<"u"?globalThis:d||self,p(d.storyblok={}))})(this,function(d){"use strict";let p=!1;const v=[],T=n=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}p?r():v.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{v.forEach(o=>o()),p=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var S=Object.defineProperty,x=(n,e,t)=>e in n?S(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,l=(n,e,t)=>(x(n,typeof e!="symbol"?e+"":e,t),t);function w(n){return!(n!==n||n===1/0||n===-1/0)}function O(n,e,t){if(!w(e))throw new TypeError("Expected `limit` to be a finite number");if(!w(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const i=function(){o++;const c=setTimeout(function(){o--,s.length>0&&i(),r=r.filter(function(u){return u!==c})},t);r.indexOf(c)<0&&r.push(c);const h=s.shift();h.resolve(n.apply(h.self,h.args))},a=function(...c){const h=this;return new Promise(function(u,k){s.push({resolve:u,reject:k,args:c,self:h}),o<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const P=function(n,e){const t={};for(const s in n){const r=n[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},I=n=>n==="email",C=()=>({singleTag:"hr"}),A=()=>({tag:"blockquote"}),M=()=>({tag:"ul"}),N=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),L=()=>({singleTag:"br"}),U=n=>({tag:`h${n.attrs.level}`}),B=n=>({singleTag:[{tag:"img",attrs:P(n.attrs,["src","alt","title"])}]}),H=()=>({tag:"li"}),q=()=>({tag:"ol"}),D=()=>({tag:"p"}),J=()=>({tag:"b"}),F=()=>({tag:"strike"}),V=()=>({tag:"u"}),z=()=>({tag:"strong"}),Y=()=>({tag:"code"}),K=()=>({tag:"i"}),Q=n=>{const e={...n.attrs},{linktype:t="url"}=n.attrs;return I(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},G=n=>({tag:[{tag:"span",attrs:n.attrs}]}),R={nodes:{horizontal_rule:C,blockquote:A,bullet_list:M,code_block:N,hard_break:L,heading:U,image:B,list_item:H,ordered_list:q,paragraph:D},marks:{bold:J,strike:F,underline:V,strong:z,code:Y,italic:K,link:Q,styled:G}},W=function(n){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return n&&s.test(n)?n.replace(t,r=>e[r]):n};class f{constructor(e){l(this,"marks"),l(this,"nodes"),e||(e=R),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e){if(e&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(W(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const i=s.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class _{constructor(){l(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),l(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),l(this,"delay",e=>new Promise(t=>setTimeout(t,e))),l(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),l(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,i)=>i*r+e)}),l(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),l(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],a=s?"":encodeURIComponent(o);let c;typeof i=="object"?c=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):c=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(c)}return r.join("&")}}class X{constructor(e){l(this,"baseURL"),l(this,"timeout"),l(this,"headers"),l(this,"responseInterceptor"),l(this,"fetch"),l(this,"ejectInterceptor"),l(this,"url"),l(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){const t=new URL(`${this.baseURL}${this.url}`);let s=null;if(e==="get"){const a=new _;t.search=a.stringify(this.parameters)}else s=JSON.stringify(this.parameters);const r=new AbortController,{signal:o}=r;let i;this.timeout&&(i=setTimeout(()=>r.abort(),this.timeout));try{const a=await this.fetch(`${t}`,{method:e,headers:this.headers,body:s,signal:o});this.timeout&&clearTimeout(i);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return a}}eject(){this.ejectInterceptor=!0}_statusHandler(e){if(/20[01|04]/g.test(`${e.status}`))return e;throw{message:new Error(e.statusText||`status: ${e.status}`),response:e}}}let m={};const g={};class Z{constructor(e,t){if(l(this,"client"),l(this,"maxRetries"),l(this,"throttle"),l(this,"accessToken"),l(this,"cache"),l(this,"helpers"),l(this,"relations"),l(this,"links"),l(this,"richTextResolver"),l(this,"resolveNestedRelations"),!t){const o=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${o}.storyblok.com/v1`:t=`${i}://api${o}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((o,i)=>{e.headers&&e.headers[i]&&s.set(i,e.headers[i])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new f(e.richTextSchema):this.richTextResolver=new f,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=O(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new _,this.resolveNestedRelations=!1,this.client=new X({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),a=s||i[i.length-1],c=1,h=await this.makeRequest(o,t,r,c),u=h.total?Math.ceil(h.total/r):1,k=await this.helpers.asyncMap(this.helpers.range(c,u),b=>this.makeRequest(o,t,r,b+1));return this.helpers.flatMap([h,...k],b=>Object.values(b.data[a]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t]&&e[t].constructor===Array){const r=[];e[t].forEach(o=>{this.relations[o]&&r.push(this._cleanCopy(this.relations[o]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let o=0;o<r.length;o++)s(r[o]);else if(r.constructor===Object){if(r._stopResolving)return;for(const o in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,o,t),this._insertLinks(r,o)),s(r[o])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var s,r;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((s=e.links)!=null&&s.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(i=>{this.iterateTree(i,o)})}cacheResponse(e,t,s){return new Promise((r,o)=>{const i=this.helpers.stringify({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const c=a.get(i);if(c)return r(c)}try{(async()=>{var c;const h=await this.throttle("get",e,t);let u={data:h.data,headers:h.headers};if((c=h.headers)!=null&&c["per-page"]&&(u=Object.assign({},u,{perPage:h.headers["per-page"]?parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?parseInt(h.headers.total):0})),h.status!=200)return o(h);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,u),u.data.cv&&t.token&&(t.version=="draft"&&g[t.token]!=u.data.cv&&this.flushCache(),g[t.token]=u.data.cv),r(u)})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(e){this.accessToken&&(g[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return m[e]},getAll(){return m},set(e,t){m[e]=t},flush(){m={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}flushCache(){return this.cacheProvider().flush(),this}}const ee=(n={})=>{const{apiOptions:e}=n;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Z(e)}},te=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let y;const j="https://app.storyblok.com/f/storyblok-v2-latest.js",$=(n,e,t={})=>{if(!(typeof window>"u")){if(typeof window.storyblokRegisterEvent>"u"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],r=>{r.action==="input"&&r.story.id===n?e(r.story):(r.action==="change"||r.action==="published")&&r.storyId===n&&window.location.reload()})})}},se=(n={})=>{const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={}}=n;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let a={};return s.forEach(c=>{a={...a,...c(i)}}),e!==!1&&T(j),y=new f(o.schema),o.resolver&&E(y,o.resolver),a},E=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},re=(n,e,t)=>{let s=t||y;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return n===""?"":n?(e&&(s=new f(e.schema),e.resolver&&E(s,e.resolver)),s.render(n)):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
2
2
 
3
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},le=()=>R(E);h.RichTextResolver=m,h.RichTextSchema=j,h.apiPlugin=oe,h.loadStoryblokBridge=le,h.registerStoryblokBridge=S,h.renderRichText=ae,h.storyblokEditable=ne,h.storyblokInit=ie,h.useStoryblokBridge=S,Object.defineProperty(h,"__esModule",{value:!0}),h[Symbol.toStringTag]="Module"});
3
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},oe=()=>T(j);d.RichTextResolver=f,d.RichTextSchema=R,d.apiPlugin=ee,d.loadStoryblokBridge=oe,d.registerStoryblokBridge=$,d.renderRichText=re,d.storyblokEditable=te,d.storyblokInit=se,d.useStoryblokBridge=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
@@ -1,440 +1,395 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b2) => {
9
- for (var prop in b2 || (b2 = {}))
10
- if (__hasOwnProp.call(b2, prop))
11
- __defNormalProp(a, prop, b2[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b2)) {
14
- if (__propIsEnum.call(b2, prop))
15
- __defNormalProp(a, prop, b2[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b2) => __defProps(a, __getOwnPropDescs(b2));
20
- let loaded = false;
21
- const callbacks = [];
22
- const loadBridge = (src) => {
23
- return new Promise((resolve, reject) => {
24
- if (typeof window === "undefined")
1
+ let k = !1;
2
+ const b = [], w = (n) => new Promise((e, t) => {
3
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
+ if (window.location === window.parent.location) {
5
+ console.warn("You are not in Draft Mode or in the Visual Editor.");
25
6
  return;
26
- window.storyblokRegisterEvent = (cb) => {
27
- if (window.location === window.parent.location) {
28
- console.warn("You are not in Draft Mode or in the Visual Editor.");
29
- return;
30
- }
31
- if (!loaded)
32
- callbacks.push(cb);
33
- else
34
- cb();
35
- };
36
- if (document.getElementById("storyblok-javascript-bridge"))
37
- return;
38
- const script = document.createElement("script");
39
- script.async = true;
40
- script.src = src;
41
- script.id = "storyblok-javascript-bridge";
42
- script.onerror = (error) => reject(error);
43
- script.onload = (ev) => {
44
- callbacks.forEach((cb) => cb());
45
- loaded = true;
46
- resolve(ev);
47
- };
48
- document.getElementsByTagName("head")[0].appendChild(script);
49
- });
50
- };
51
- var m = Object.defineProperty;
52
- var T = (c, t, e) => t in c ? m(c, t, { enumerable: true, configurable: true, writable: true, value: e }) : c[t] = e;
53
- var l = (c, t, e) => (T(c, typeof t != "symbol" ? t + "" : t, e), e);
54
- function k(c) {
55
- return !(c !== c || c === 1 / 0 || c === -1 / 0);
7
+ }
8
+ k ? r() : b.push(r);
9
+ }, document.getElementById("storyblok-javascript-bridge")))
10
+ return;
11
+ const s = document.createElement("script");
12
+ s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
13
+ b.forEach((o) => o()), k = !0, e(r);
14
+ }, document.getElementsByTagName("head")[0].appendChild(s);
15
+ });
16
+ var $ = Object.defineProperty, j = (n, e, t) => e in n ? $(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, l = (n, e, t) => (j(n, typeof e != "symbol" ? e + "" : e, t), t);
17
+ function v(n) {
18
+ return !(n !== n || n === 1 / 0 || n === -1 / 0);
56
19
  }
57
- function _(c, t, e) {
58
- if (!k(t))
20
+ function x(n, e, t) {
21
+ if (!v(e))
59
22
  throw new TypeError("Expected `limit` to be a finite number");
60
- if (!k(e))
23
+ if (!v(t))
61
24
  throw new TypeError("Expected `interval` to be a finite number");
62
25
  const s = [];
63
- let r = [], n = 0;
26
+ let r = [], o = 0;
64
27
  const i = function() {
65
- n++;
66
- const a = setTimeout(function() {
67
- n--, s.length > 0 && i(), r = r.filter(function(u) {
68
- return u !== a;
28
+ o++;
29
+ const c = setTimeout(function() {
30
+ o--, s.length > 0 && i(), r = r.filter(function(u) {
31
+ return u !== c;
69
32
  });
70
- }, e);
71
- r.indexOf(a) < 0 && r.push(a);
33
+ }, t);
34
+ r.indexOf(c) < 0 && r.push(c);
72
35
  const h = s.shift();
73
- h.resolve(c.apply(h.self, h.args));
74
- }, o = function(...a) {
36
+ h.resolve(n.apply(h.self, h.args));
37
+ }, a = function(...c) {
75
38
  const h = this;
76
- return new Promise(function(u, p) {
39
+ return new Promise(function(u, f) {
77
40
  s.push({
78
41
  resolve: u,
79
- reject: p,
80
- args: a,
42
+ reject: f,
43
+ args: c,
81
44
  self: h
82
- }), n < t && i();
45
+ }), o < e && i();
83
46
  });
84
47
  };
85
- return o.abort = function() {
86
- r.forEach(clearTimeout), r = [], s.forEach(function(a) {
87
- a.reject(function() {
48
+ return a.abort = function() {
49
+ r.forEach(clearTimeout), r = [], s.forEach(function(c) {
50
+ c.reject(function() {
88
51
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
89
52
  });
90
53
  }), s.length = 0;
91
- }, o;
54
+ }, a;
92
55
  }
93
- const R = function(c, t) {
94
- const e = {};
95
- for (const s in c) {
96
- const r = c[s];
97
- t.indexOf(s) > -1 && r !== null && (e[s] = r);
98
- }
99
- return e;
100
- }, b = (c) => c === "email", w = () => ({
56
+ const E = function(n, e) {
57
+ const t = {};
58
+ for (const s in n) {
59
+ const r = n[s];
60
+ e.indexOf(s) > -1 && r !== null && (t[s] = r);
61
+ }
62
+ return t;
63
+ }, S = (n) => n === "email", O = () => ({
101
64
  singleTag: "hr"
102
- }), $ = () => ({
65
+ }), P = () => ({
103
66
  tag: "blockquote"
104
- }), x = () => ({
67
+ }), C = () => ({
105
68
  tag: "ul"
106
- }), E = (c) => ({
69
+ }), I = (n) => ({
107
70
  tag: [
108
71
  "pre",
109
72
  {
110
73
  tag: "code",
111
- attrs: c.attrs
74
+ attrs: n.attrs
112
75
  }
113
76
  ]
114
- }), P = () => ({
77
+ }), A = () => ({
115
78
  singleTag: "br"
116
- }), S = (c) => ({
117
- tag: `h${c.attrs.level}`
118
- }), C = (c) => ({
79
+ }), N = (n) => ({
80
+ tag: `h${n.attrs.level}`
81
+ }), M = (n) => ({
119
82
  singleTag: [
120
83
  {
121
84
  tag: "img",
122
- attrs: R(c.attrs, ["src", "alt", "title"])
85
+ attrs: E(n.attrs, ["src", "alt", "title"])
123
86
  }
124
87
  ]
125
- }), O = () => ({
88
+ }), L = () => ({
126
89
  tag: "li"
127
- }), M = () => ({
90
+ }), U = () => ({
128
91
  tag: "ol"
129
92
  }), H = () => ({
130
93
  tag: "p"
131
- }), A = () => ({
94
+ }), B = () => ({
132
95
  tag: "b"
133
- }), I = () => ({
96
+ }), q = () => ({
134
97
  tag: "strike"
135
- }), L = () => ({
98
+ }), D = () => ({
136
99
  tag: "u"
137
- }), N = () => ({
100
+ }), J = () => ({
138
101
  tag: "strong"
139
- }), U = () => ({
102
+ }), F = () => ({
140
103
  tag: "code"
141
- }), q = () => ({
104
+ }), V = () => ({
142
105
  tag: "i"
143
- }), z = (c) => {
144
- const t = __spreadValues({}, c.attrs), { linktype: e = "url" } = c.attrs;
145
- return b(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
106
+ }), z = (n) => {
107
+ const e = { ...n.attrs }, { linktype: t = "url" } = n.attrs;
108
+ return S(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
146
109
  tag: [
147
110
  {
148
111
  tag: "a",
149
- attrs: t
112
+ attrs: e
150
113
  }
151
114
  ]
152
115
  };
153
- }, j = (c) => ({
116
+ }, Y = (n) => ({
154
117
  tag: [
155
118
  {
156
119
  tag: "span",
157
- attrs: c.attrs
120
+ attrs: n.attrs
158
121
  }
159
122
  ]
160
- }), F = {
123
+ }), K = {
161
124
  nodes: {
162
- horizontal_rule: w,
163
- blockquote: $,
164
- bullet_list: x,
165
- code_block: E,
166
- hard_break: P,
167
- heading: S,
168
- image: C,
169
- list_item: O,
170
- ordered_list: M,
125
+ horizontal_rule: O,
126
+ blockquote: P,
127
+ bullet_list: C,
128
+ code_block: I,
129
+ hard_break: A,
130
+ heading: N,
131
+ image: M,
132
+ list_item: L,
133
+ ordered_list: U,
171
134
  paragraph: H
172
135
  },
173
136
  marks: {
174
- bold: A,
175
- strike: I,
176
- underline: L,
177
- strong: N,
178
- code: U,
179
- italic: q,
137
+ bold: B,
138
+ strike: q,
139
+ underline: D,
140
+ strong: J,
141
+ code: F,
142
+ italic: V,
180
143
  link: z,
181
- styled: j
144
+ styled: Y
182
145
  }
183
- }, V = function(c) {
184
- const t = {
146
+ }, Q = function(n) {
147
+ const e = {
185
148
  "&": "&amp;",
186
149
  "<": "&lt;",
187
150
  ">": "&gt;",
188
151
  '"': "&quot;",
189
152
  "'": "&#39;"
190
- }, e = /[&<>"']/g, s = RegExp(e.source);
191
- return c && s.test(c) ? c.replace(e, (r) => t[r]) : c;
153
+ }, t = /[&<>"']/g, s = RegExp(t.source);
154
+ return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
192
155
  };
193
- class y {
194
- constructor(t) {
195
- l(this, "marks");
196
- l(this, "nodes");
197
- t || (t = F), this.marks = t.marks || [], this.nodes = t.nodes || [];
198
- }
199
- addNode(t, e) {
200
- this.nodes[t] = e;
201
- }
202
- addMark(t, e) {
203
- this.marks[t] = e;
204
- }
205
- render(t) {
206
- if (t && t.content && Array.isArray(t.content)) {
207
- let e = "";
208
- return t.content.forEach((s) => {
209
- e += this.renderNode(s);
210
- }), e;
156
+ class g {
157
+ constructor(e) {
158
+ l(this, "marks"), l(this, "nodes"), e || (e = K), this.marks = e.marks || [], this.nodes = e.nodes || [];
159
+ }
160
+ addNode(e, t) {
161
+ this.nodes[e] = t;
162
+ }
163
+ addMark(e, t) {
164
+ this.marks[e] = t;
165
+ }
166
+ render(e) {
167
+ if (e && e.content && Array.isArray(e.content)) {
168
+ let t = "";
169
+ return e.content.forEach((s) => {
170
+ t += this.renderNode(s);
171
+ }), t;
211
172
  }
212
- return console.warn("The render method must receive an object with a content field, which is an array"), "";
213
- }
214
- renderNode(t) {
215
- const e = [];
216
- t.marks && t.marks.forEach((r) => {
217
- const n = this.getMatchingMark(r);
218
- n && e.push(this.renderOpeningTag(n.tag));
173
+ return console.warn(
174
+ "The render method must receive an object with a content field, which is an array"
175
+ ), "";
176
+ }
177
+ renderNode(e) {
178
+ const t = [];
179
+ e.marks && e.marks.forEach((r) => {
180
+ const o = this.getMatchingMark(r);
181
+ o && t.push(this.renderOpeningTag(o.tag));
219
182
  });
220
- const s = this.getMatchingNode(t);
221
- return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
222
- e.push(this.renderNode(r));
223
- }) : t.text ? e.push(V(t.text)) : s && s.singleTag ? e.push(this.renderTag(s.singleTag, " /")) : s && s.html && e.push(s.html), s && s.tag && e.push(this.renderClosingTag(s.tag)), t.marks && t.marks.slice(0).reverse().forEach((r) => {
224
- const n = this.getMatchingMark(r);
225
- n && e.push(this.renderClosingTag(n.tag));
226
- }), e.join("");
227
- }
228
- renderTag(t, e) {
229
- return t.constructor === String ? `<${t}${e}>` : t.map((r) => {
230
- if (r.constructor === String)
231
- return `<${r}${e}>`;
183
+ const s = this.getMatchingNode(e);
184
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
185
+ t.push(this.renderNode(r));
186
+ }) : e.text ? t.push(Q(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html && t.push(s.html), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
187
+ const o = this.getMatchingMark(r);
188
+ o && t.push(this.renderClosingTag(o.tag));
189
+ }), t.join("");
190
+ }
191
+ renderTag(e, t) {
192
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
193
+ if (s.constructor === String)
194
+ return `<${s}${t}>`;
232
195
  {
233
- let n = `<${r.tag}`;
234
- if (r.attrs)
235
- for (const i in r.attrs) {
236
- const o = r.attrs[i];
237
- o !== null && (n += ` ${i}="${o}"`);
196
+ let r = `<${s.tag}`;
197
+ if (s.attrs)
198
+ for (const o in s.attrs) {
199
+ const i = s.attrs[o];
200
+ i !== null && (r += ` ${o}="${i}"`);
238
201
  }
239
- return `${n}${e}>`;
202
+ return `${r}${t}>`;
240
203
  }
241
204
  }).join("");
242
205
  }
243
- renderOpeningTag(t) {
244
- return this.renderTag(t, "");
206
+ renderOpeningTag(e) {
207
+ return this.renderTag(e, "");
245
208
  }
246
- renderClosingTag(t) {
247
- return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((s) => s.constructor === String ? `</${s}>` : `</${s.tag}>`).join("");
209
+ renderClosingTag(e) {
210
+ return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
248
211
  }
249
- getMatchingNode(t) {
250
- const e = this.nodes[t.type];
251
- if (typeof e == "function")
252
- return e(t);
212
+ getMatchingNode(e) {
213
+ const t = this.nodes[e.type];
214
+ if (typeof t == "function")
215
+ return t(e);
253
216
  }
254
- getMatchingMark(t) {
255
- const e = this.marks[t.type];
256
- if (typeof e == "function")
257
- return e(t);
217
+ getMatchingMark(e) {
218
+ const t = this.marks[e.type];
219
+ if (typeof t == "function")
220
+ return t(e);
258
221
  }
259
222
  }
260
- class v {
223
+ class T {
261
224
  constructor() {
262
- l(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1);
263
- l(this, "getOptionsPage", (t, e = 25, s = 1) => __spreadProps(__spreadValues({}, t), {
264
- per_page: e,
225
+ l(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), l(this, "getOptionsPage", (e, t = 25, s = 1) => ({
226
+ ...e,
227
+ per_page: t,
265
228
  page: s
266
- }));
267
- l(this, "delay", (t) => new Promise((e) => setTimeout(e, t)));
268
- l(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e));
269
- l(this, "range", (t = 0, e = t) => {
270
- const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
271
- return this.arrayFrom(s, (n, i) => i * r + t);
272
- });
273
- l(this, "asyncMap", async (t, e) => Promise.all(t.map(e)));
274
- l(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
229
+ })), l(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), l(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), l(this, "range", (e = 0, t = e) => {
230
+ const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
231
+ return this.arrayFrom(s, (o, i) => i * r + e);
232
+ }), l(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), l(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
275
233
  }
276
- stringify(t, e, s) {
234
+ stringify(e, t, s) {
277
235
  const r = [];
278
- for (const n in t) {
279
- if (!Object.prototype.hasOwnProperty.call(t, n))
236
+ for (const o in e) {
237
+ if (!Object.prototype.hasOwnProperty.call(e, o))
280
238
  continue;
281
- const i = t[n], o = s ? "" : encodeURIComponent(n);
282
- let a;
283
- typeof i == "object" ? a = this.stringify(i, e ? e + encodeURIComponent("[" + o + "]") : o, Array.isArray(i)) : a = (e ? e + encodeURIComponent("[" + o + "]") : o) + "=" + encodeURIComponent(i), r.push(a);
239
+ const i = e[o], a = s ? "" : encodeURIComponent(o);
240
+ let c;
241
+ typeof i == "object" ? c = this.stringify(
242
+ i,
243
+ t ? t + encodeURIComponent("[" + a + "]") : a,
244
+ Array.isArray(i)
245
+ ) : c = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), r.push(c);
284
246
  }
285
247
  return r.join("&");
286
248
  }
287
249
  }
288
- class J {
289
- constructor(t) {
290
- l(this, "baseURL");
291
- l(this, "timeout");
292
- l(this, "headers");
293
- l(this, "responseInterceptor");
294
- l(this, "fetch");
295
- l(this, "ejectInterceptor");
296
- l(this, "url");
297
- l(this, "parameters");
298
- this.baseURL = t.baseURL, this.headers = t.headers || [], this.timeout = t.timeout ? t.timeout * 1e3 : 1e3, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = false, this.url = "", this.parameters = {};
299
- }
300
- get(t, e) {
301
- return this.url = t, this.parameters = e, this._methodHandler("get");
302
- }
303
- post(t, e) {
304
- return this.url = t, this.parameters = e, this._methodHandler("post");
305
- }
306
- put(t, e) {
307
- return this.url = t, this.parameters = e, this._methodHandler("put");
308
- }
309
- delete(t, e) {
310
- return this.url = t, this.parameters = e, this._methodHandler("delete");
311
- }
312
- async _responseHandler(t) {
313
- const e = [], s = {
250
+ class G {
251
+ constructor(e) {
252
+ l(this, "baseURL"), l(this, "timeout"), l(this, "headers"), l(this, "responseInterceptor"), l(this, "fetch"), l(this, "ejectInterceptor"), l(this, "url"), l(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || [], this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
253
+ }
254
+ get(e, t) {
255
+ return this.url = e, this.parameters = t, this._methodHandler("get");
256
+ }
257
+ post(e, t) {
258
+ return this.url = e, this.parameters = t, this._methodHandler("post");
259
+ }
260
+ put(e, t) {
261
+ return this.url = e, this.parameters = t, this._methodHandler("put");
262
+ }
263
+ delete(e, t) {
264
+ return this.url = e, this.parameters = t, this._methodHandler("delete");
265
+ }
266
+ async _responseHandler(e) {
267
+ const t = [], s = {
314
268
  data: {},
315
269
  headers: {},
316
270
  status: 0,
317
271
  statusText: ""
318
272
  };
319
- await t.json().then((r) => {
273
+ e.status !== 204 && await e.json().then((r) => {
320
274
  s.data = r;
321
275
  });
322
- for (const r of t.headers.entries())
323
- e[r[0]] = r[1];
324
- return s.headers = __spreadValues({}, e), s.status = t.status, s.statusText = t.statusText, s;
276
+ for (const r of e.headers.entries())
277
+ t[r[0]] = r[1];
278
+ return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
325
279
  }
326
- async _methodHandler(t) {
327
- const e = new URL(`${this.baseURL}${this.url}`);
280
+ async _methodHandler(e) {
281
+ const t = new URL(`${this.baseURL}${this.url}`);
328
282
  let s = null;
329
- if (t === "get") {
330
- const o = new v();
331
- e.search = o.stringify(this.parameters);
283
+ if (e === "get") {
284
+ const a = new T();
285
+ t.search = a.stringify(this.parameters);
332
286
  } else
333
287
  s = JSON.stringify(this.parameters);
334
- const r = new AbortController(), { signal: n } = r, i = setTimeout(() => r.abort(), this.timeout);
288
+ const r = new AbortController(), { signal: o } = r;
289
+ let i;
290
+ this.timeout && (i = setTimeout(() => r.abort(), this.timeout));
335
291
  try {
336
- const o = await this.fetch(`${e}`, {
337
- method: t,
292
+ const a = await this.fetch(`${t}`, {
293
+ method: e,
338
294
  headers: this.headers,
339
295
  body: s,
340
- signal: n
296
+ signal: o
341
297
  });
342
- clearTimeout(i);
343
- const a = await this._responseHandler(o);
344
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(a)) : this._statusHandler(a);
345
- } catch (o) {
346
- return o;
298
+ this.timeout && clearTimeout(i);
299
+ const c = await this._responseHandler(a);
300
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
301
+ } catch (a) {
302
+ return a;
347
303
  }
348
304
  }
349
305
  eject() {
350
- this.ejectInterceptor = true;
306
+ this.ejectInterceptor = !0;
351
307
  }
352
- _statusHandler(t) {
353
- if (/20[01]/g.test(`${t.status}`))
354
- return t;
308
+ _statusHandler(e) {
309
+ if (/20[01|04]/g.test(`${e.status}`))
310
+ return e;
355
311
  throw {
356
- message: new Error(t.statusText || `status: ${t.status}`),
357
- response: t
312
+ message: new Error(e.statusText || `status: ${e.status}`),
313
+ response: e
358
314
  };
359
315
  }
360
316
  }
361
- let f = {};
317
+ let p = {};
362
318
  const d = {};
363
- class Q {
364
- constructor(t, e) {
365
- l(this, "client");
366
- l(this, "maxRetries");
367
- l(this, "throttle");
368
- l(this, "accessToken");
369
- l(this, "cache");
370
- l(this, "helpers");
371
- l(this, "relations");
372
- l(this, "links");
373
- l(this, "richTextResolver");
374
- l(this, "resolveNestedRelations");
375
- if (!e) {
376
- const n = t.region ? `-${t.region}` : "", i = t.https === false ? "http" : "https";
377
- t.oauthToken ? e = `${i}://api${n}.storyblok.com/v1` : e = `${i}://api${n}.storyblok.com/v2`;
319
+ class W {
320
+ constructor(e, t) {
321
+ if (l(this, "client"), l(this, "maxRetries"), l(this, "throttle"), l(this, "accessToken"), l(this, "cache"), l(this, "helpers"), l(this, "relations"), l(this, "links"), l(this, "richTextResolver"), l(this, "resolveNestedRelations"), !t) {
322
+ const o = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
323
+ e.oauthToken ? t = `${i}://api${o}.storyblok.com/v1` : t = `${i}://api${o}.storyblok.com/v2`;
378
324
  }
379
325
  const s = new Headers();
380
- s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((n, i) => {
381
- t.headers && t.headers[i] && s.set(i, t.headers[i]);
326
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((o, i) => {
327
+ e.headers && e.headers[i] && s.set(i, e.headers[i]);
382
328
  });
383
329
  let r = 5;
384
- t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new y(t.richTextSchema) : this.richTextResolver = new y(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = _(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new v(), this.resolveNestedRelations = false, this.client = new J({
385
- baseURL: e,
386
- timeout: t.timeout || 0,
330
+ e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new g(e.richTextSchema) : this.richTextResolver = new g(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = x(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new T(), this.resolveNestedRelations = !1, this.client = new G({
331
+ baseURL: t,
332
+ timeout: e.timeout || 0,
387
333
  headers: s,
388
- responseInterceptor: t.responseInterceptor,
389
- fetch: t.fetch
334
+ responseInterceptor: e.responseInterceptor,
335
+ fetch: e.fetch
390
336
  });
391
337
  }
392
- setComponentResolver(t) {
393
- this.richTextResolver.addNode("blok", (e) => {
338
+ setComponentResolver(e) {
339
+ this.richTextResolver.addNode("blok", (t) => {
394
340
  let s = "";
395
- return e.attrs.body.forEach((r) => {
396
- s += t(r.component, r);
341
+ return t.attrs.body.forEach((r) => {
342
+ s += e(r.component, r);
397
343
  }), {
398
344
  html: s
399
345
  };
400
346
  });
401
347
  }
402
- parseParams(t) {
403
- return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = d[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
348
+ parseParams(e) {
349
+ return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = d[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
404
350
  }
405
- factoryParamOptions(t, e) {
406
- return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
351
+ factoryParamOptions(e, t) {
352
+ return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
407
353
  }
408
- makeRequest(t, e, s, r) {
409
- const n = this.factoryParamOptions(t, this.helpers.getOptionsPage(e, s, r));
410
- return this.cacheResponse(t, n);
354
+ makeRequest(e, t, s, r) {
355
+ const o = this.factoryParamOptions(
356
+ e,
357
+ this.helpers.getOptionsPage(t, s, r)
358
+ );
359
+ return this.cacheResponse(e, o);
411
360
  }
412
- get(t, e) {
413
- e || (e = {});
414
- const s = `/${t}`, r = this.factoryParamOptions(s, e);
361
+ get(e, t) {
362
+ t || (t = {});
363
+ const s = `/${e}`, r = this.factoryParamOptions(s, t);
415
364
  return this.cacheResponse(s, r);
416
365
  }
417
- async getAll(t, e, s) {
418
- const r = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, i = n.split("/"), o = s || i[i.length - 1], a = 1, h = await this.makeRequest(n, e, r, a), u = h.total ? Math.ceil(h.total / r) : 1, p = await this.helpers.asyncMap(this.helpers.range(a, u), (g) => this.makeRequest(n, e, r, g + 1));
419
- return this.helpers.flatMap([h, ...p], (g) => Object.values(g.data[o]));
366
+ async getAll(e, t, s) {
367
+ const r = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, i = o.split("/"), a = s || i[i.length - 1], c = 1, h = await this.makeRequest(o, t, r, c), u = h.total ? Math.ceil(h.total / r) : 1, f = await this.helpers.asyncMap(
368
+ this.helpers.range(c, u),
369
+ (m) => this.makeRequest(o, t, r, m + 1)
370
+ );
371
+ return this.helpers.flatMap(
372
+ [h, ...f],
373
+ (m) => Object.values(m.data[a])
374
+ );
420
375
  }
421
- post(t, e) {
422
- const s = `/${t}`;
423
- return Promise.resolve(this.throttle("post", s, e));
376
+ post(e, t) {
377
+ const s = `/${e}`;
378
+ return Promise.resolve(this.throttle("post", s, t));
424
379
  }
425
- put(t, e) {
426
- const s = `/${t}`;
427
- return Promise.resolve(this.throttle("put", s, e));
380
+ put(e, t) {
381
+ const s = `/${e}`;
382
+ return Promise.resolve(this.throttle("put", s, t));
428
383
  }
429
- delete(t, e) {
430
- const s = `/${t}`;
431
- return Promise.resolve(this.throttle("delete", s, e));
384
+ delete(e, t) {
385
+ const s = `/${e}`;
386
+ return Promise.resolve(this.throttle("delete", s, t));
432
387
  }
433
- getStories(t) {
434
- return this.get("cdn/stories", t);
388
+ getStories(e) {
389
+ return this.get("cdn/stories", e);
435
390
  }
436
- getStory(t, e) {
437
- return this.get(`cdn/stories/${t}`, e);
391
+ getStory(e, t) {
392
+ return this.get(`cdn/stories/${e}`, t);
438
393
  }
439
394
  getToken() {
440
395
  return this.accessToken;
@@ -442,123 +397,129 @@ class Q {
442
397
  ejectInterceptor() {
443
398
  this.client.eject();
444
399
  }
445
- _cleanCopy(t) {
446
- return JSON.parse(JSON.stringify(t));
400
+ _cleanCopy(e) {
401
+ return JSON.parse(JSON.stringify(e));
447
402
  }
448
- _insertLinks(t, e) {
449
- const s = t[e];
403
+ _insertLinks(e, t) {
404
+ const s = e[t];
450
405
  s && s.fieldtype == "multilink" && s.linktype == "story" && typeof s.id == "string" && this.links[s.id] ? s.story = this._cleanCopy(this.links[s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[s.uuid] && (s.story = this._cleanCopy(this.links[s.uuid]));
451
406
  }
452
- _insertRelations(t, e, s) {
453
- if (s.indexOf(`${t.component}.${e}`) > -1) {
454
- if (typeof t[e] == "string")
455
- this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
456
- else if (t[e] && t[e].constructor === Array) {
407
+ _insertRelations(e, t, s) {
408
+ if (s.indexOf(`${e.component}.${t}`) > -1) {
409
+ if (typeof e[t] == "string")
410
+ this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
411
+ else if (e[t] && e[t].constructor === Array) {
457
412
  const r = [];
458
- t[e].forEach((n) => {
459
- this.relations[n] && r.push(this._cleanCopy(this.relations[n]));
460
- }), t[e] = r;
413
+ e[t].forEach((o) => {
414
+ this.relations[o] && r.push(this._cleanCopy(this.relations[o]));
415
+ }), e[t] = r;
461
416
  }
462
417
  }
463
418
  }
464
- iterateTree(t, e) {
419
+ iterateTree(e, t) {
465
420
  const s = (r) => {
466
421
  if (r != null) {
467
422
  if (r.constructor === Array)
468
- for (let n = 0; n < r.length; n++)
469
- s(r[n]);
423
+ for (let o = 0; o < r.length; o++)
424
+ s(r[o]);
470
425
  else if (r.constructor === Object) {
471
426
  if (r._stopResolving)
472
427
  return;
473
- for (const n in r)
474
- (r.component && r._uid || r.type === "link") && (this._insertRelations(r, n, e), this._insertLinks(r, n)), s(r[n]);
428
+ for (const o in r)
429
+ (r.component && r._uid || r.type === "link") && (this._insertRelations(
430
+ r,
431
+ o,
432
+ t
433
+ ), this._insertLinks(r, o)), s(r[o]);
475
434
  }
476
435
  }
477
436
  };
478
- s(t.content);
437
+ s(e.content);
479
438
  }
480
- async resolveLinks(t, e) {
439
+ async resolveLinks(e, t) {
481
440
  let s = [];
482
- if (t.link_uuids) {
483
- const r = t.link_uuids.length, n = [], i = 50;
484
- for (let o = 0; o < r; o += i) {
485
- const a = Math.min(r, o + i);
486
- n.push(t.link_uuids.slice(o, a));
441
+ if (e.link_uuids) {
442
+ const r = e.link_uuids.length, o = [], i = 50;
443
+ for (let a = 0; a < r; a += i) {
444
+ const c = Math.min(r, a + i);
445
+ o.push(e.link_uuids.slice(a, c));
487
446
  }
488
- for (let o = 0; o < n.length; o++)
447
+ for (let a = 0; a < o.length; a++)
489
448
  (await this.getStories({
490
449
  per_page: i,
491
- language: e.language,
492
- version: e.version,
493
- by_uuids: n[o].join(",")
494
- })).data.stories.forEach((h) => {
495
- s.push(h);
496
- });
450
+ language: t.language,
451
+ version: t.version,
452
+ by_uuids: o[a].join(",")
453
+ })).data.stories.forEach(
454
+ (c) => {
455
+ s.push(c);
456
+ }
457
+ );
497
458
  } else
498
- s = t.links;
459
+ s = e.links;
499
460
  s.forEach((r) => {
500
- this.links[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
461
+ this.links[r.uuid] = { ...r, _stopResolving: !0 };
501
462
  });
502
463
  }
503
- async resolveRelations(t, e) {
464
+ async resolveRelations(e, t) {
504
465
  let s = [];
505
- if (t.rel_uuids) {
506
- const r = t.rel_uuids.length, n = [], i = 50;
507
- for (let o = 0; o < r; o += i) {
508
- const a = Math.min(r, o + i);
509
- n.push(t.rel_uuids.slice(o, a));
466
+ if (e.rel_uuids) {
467
+ const r = e.rel_uuids.length, o = [], i = 50;
468
+ for (let a = 0; a < r; a += i) {
469
+ const c = Math.min(r, a + i);
470
+ o.push(e.rel_uuids.slice(a, c));
510
471
  }
511
- for (let o = 0; o < n.length; o++)
472
+ for (let a = 0; a < o.length; a++)
512
473
  (await this.getStories({
513
474
  per_page: i,
514
- language: e.language,
515
- version: e.version,
516
- by_uuids: n[o].join(",")
517
- })).data.stories.forEach((h) => {
518
- s.push(h);
475
+ language: t.language,
476
+ version: t.version,
477
+ by_uuids: o[a].join(",")
478
+ })).data.stories.forEach((c) => {
479
+ s.push(c);
519
480
  });
520
481
  } else
521
- s = t.rels;
482
+ s = e.rels;
522
483
  s && s.length > 0 && s.forEach((r) => {
523
- this.relations[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
484
+ this.relations[r.uuid] = { ...r, _stopResolving: !0 };
524
485
  });
525
486
  }
526
- async resolveStories(t, e) {
527
- var r, n;
528
- let s = [];
529
- if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (s = e.resolve_relations.split(",")), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && (((r = t.links) == null ? void 0 : r.length) || ((n = t.link_uuids) == null ? void 0 : n.length)) && await this.resolveLinks(t, e), this.resolveNestedRelations)
487
+ async resolveStories(e, t) {
488
+ var s, r;
489
+ let o = [];
490
+ if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((s = e.links) != null && s.length || (r = e.link_uuids) != null && r.length) && await this.resolveLinks(e, t), this.resolveNestedRelations)
530
491
  for (const i in this.relations)
531
- this.iterateTree(this.relations[i], s);
532
- t.story ? this.iterateTree(t.story, s) : t.stories.forEach((i) => {
533
- this.iterateTree(i, s);
492
+ this.iterateTree(this.relations[i], o);
493
+ e.story ? this.iterateTree(e.story, o) : e.stories.forEach((i) => {
494
+ this.iterateTree(i, o);
534
495
  });
535
496
  }
536
- cacheResponse(t, e, s) {
537
- return new Promise((r, n) => {
538
- const i = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
539
- if (this.cache.clear === "auto" && e.version === "draft" && this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
540
- const a = o.get(i);
541
- if (a)
542
- return r(a);
497
+ cacheResponse(e, t, s) {
498
+ return new Promise((r, o) => {
499
+ const i = this.helpers.stringify({ url: e, params: t }), a = this.cacheProvider();
500
+ if (this.cache.clear === "auto" && t.version === "draft" && this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
501
+ const c = a.get(i);
502
+ if (c)
503
+ return r(c);
543
504
  }
544
505
  try {
545
506
  (async () => {
546
- var u;
547
- const a = await this.throttle("get", t, e);
548
- let h = { data: a.data, headers: a.headers };
549
- if ((u = a.headers) != null && u["per-page"] && (h = Object.assign({}, h, {
550
- perPage: a.headers["per-page"] ? parseInt(a.headers["per-page"]) : 0,
551
- total: a.headers["per-page"] ? parseInt(a.headers.total) : 0
552
- })), a.status != 200)
553
- return n(a);
554
- (h.data.story || h.data.stories) && await this.resolveStories(h.data, e), e.version === "published" && t != "/cdn/spaces/me" && o.set(i, h), h.data.cv && e.token && (e.version == "draft" && d[e.token] != h.data.cv && this.flushCache(), d[e.token] = h.data.cv), r(h);
507
+ var c;
508
+ const h = await this.throttle("get", e, t);
509
+ let u = { data: h.data, headers: h.headers };
510
+ if ((c = h.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
511
+ perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
512
+ total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
513
+ })), h.status != 200)
514
+ return o(h);
515
+ (u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && a.set(i, u), u.data.cv && t.token && (t.version == "draft" && d[t.token] != u.data.cv && this.flushCache(), d[t.token] = u.data.cv), r(u);
555
516
  })();
556
517
  } catch {
557
518
  }
558
519
  });
559
520
  }
560
- throttledRequest(t, e, s) {
561
- return this.client[t](e, s);
521
+ throttledRequest(e, t, s) {
522
+ return this.client[e](t, s);
562
523
  }
563
524
  cacheVersions() {
564
525
  return d;
@@ -566,24 +527,24 @@ class Q {
566
527
  cacheVersion() {
567
528
  return d[this.accessToken];
568
529
  }
569
- setCacheVersion(t) {
570
- this.accessToken && (d[this.accessToken] = t);
530
+ setCacheVersion(e) {
531
+ this.accessToken && (d[this.accessToken] = e);
571
532
  }
572
533
  cacheProvider() {
573
534
  switch (this.cache.type) {
574
535
  case "memory":
575
536
  return {
576
- get(t) {
577
- return f[t];
537
+ get(e) {
538
+ return p[e];
578
539
  },
579
540
  getAll() {
580
- return f;
541
+ return p;
581
542
  },
582
- set(t, e) {
583
- f[t] = e;
543
+ set(e, t) {
544
+ p[e] = t;
584
545
  },
585
546
  flush() {
586
- f = {};
547
+ p = {};
587
548
  }
588
549
  };
589
550
  default:
@@ -603,105 +564,88 @@ class Q {
603
564
  return this.cacheProvider().flush(), this;
604
565
  }
605
566
  }
606
- const apiFactory = (options = {}) => {
607
- const { apiOptions } = options;
608
- if (!apiOptions.accessToken) {
609
- console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");
567
+ const X = (n = {}) => {
568
+ const { apiOptions: e } = n;
569
+ if (!e.accessToken) {
570
+ console.error(
571
+ "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
572
+ );
610
573
  return;
611
574
  }
612
- const storyblokApi = new Q(apiOptions);
613
- return { storyblokApi };
614
- };
615
- var editable = (blok) => {
616
- if (typeof blok !== "object" || typeof blok._editable === "undefined") {
575
+ return { storyblokApi: new W(e) };
576
+ }, Z = (n) => {
577
+ if (typeof n != "object" || typeof n._editable > "u")
617
578
  return {};
618
- }
619
- const options = JSON.parse(blok._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
579
+ const e = JSON.parse(
580
+ n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
581
+ );
620
582
  return {
621
- "data-blok-c": JSON.stringify(options),
622
- "data-blok-uid": options.id + "-" + options.uid
583
+ "data-blok-c": JSON.stringify(e),
584
+ "data-blok-uid": e.id + "-" + e.uid
623
585
  };
624
586
  };
625
- let richTextResolver;
626
- const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
627
- const useStoryblokBridge = (id, cb, options = {}) => {
628
- if (typeof window === "undefined") {
629
- return;
630
- }
631
- if (typeof window.storyblokRegisterEvent === "undefined") {
632
- console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
633
- return;
634
- }
635
- if (!id) {
636
- console.warn("Story ID is not defined. Please provide a valid ID.");
637
- return;
638
- }
639
- window.storyblokRegisterEvent(() => {
640
- const sbBridge = new window.StoryblokBridge(options);
641
- sbBridge.on(["input", "published", "change"], (event) => {
642
- if (event.action === "input" && event.story.id === id) {
643
- cb(event.story);
644
- } else if ((event.action === "change" || event.action === "published") && event.storyId === id) {
645
- window.location.reload();
646
- }
587
+ let y;
588
+ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", ee = (n, e, t = {}) => {
589
+ if (!(typeof window > "u")) {
590
+ if (typeof window.storyblokRegisterEvent > "u") {
591
+ console.error(
592
+ "Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js"
593
+ );
594
+ return;
595
+ }
596
+ if (!n) {
597
+ console.warn("Story ID is not defined. Please provide a valid ID.");
598
+ return;
599
+ }
600
+ window.storyblokRegisterEvent(() => {
601
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (r) => {
602
+ r.action === "input" && r.story.id === n ? e(r.story) : (r.action === "change" || r.action === "published") && r.storyId === n && window.location.reload();
603
+ });
647
604
  });
648
- });
649
- };
650
- const storyblokInit = (pluginOptions = {}) => {
651
- const {
652
- bridge,
653
- accessToken,
654
- use = [],
655
- apiOptions = {},
656
- richText = {}
657
- } = pluginOptions;
658
- apiOptions.accessToken = apiOptions.accessToken || accessToken;
659
- const options = { bridge, apiOptions };
660
- let result = {};
661
- use.forEach((pluginFactory) => {
662
- result = __spreadValues(__spreadValues({}, result), pluginFactory(options));
663
- });
664
- if (bridge !== false) {
665
- loadBridge(bridgeLatest);
666
- }
667
- richTextResolver = new y(richText.schema);
668
- if (richText.resolver) {
669
- setComponentResolver(richTextResolver, richText.resolver);
670
605
  }
671
- return result;
672
- };
673
- const setComponentResolver = (resolver, resolveFn) => {
674
- resolver.addNode("blok", (node) => {
675
- let html = "";
676
- node.attrs.body.forEach((blok) => {
677
- html += resolveFn(blok.component, blok);
678
- });
679
- return {
680
- html
606
+ }, te = (n = {}) => {
607
+ const {
608
+ bridge: e,
609
+ accessToken: t,
610
+ use: s = [],
611
+ apiOptions: r = {},
612
+ richText: o = {}
613
+ } = n;
614
+ r.accessToken = r.accessToken || t;
615
+ const i = { bridge: e, apiOptions: r };
616
+ let a = {};
617
+ return s.forEach((c) => {
618
+ a = { ...a, ...c(i) };
619
+ }), e !== !1 && w(R), y = new g(o.schema), o.resolver && _(y, o.resolver), a;
620
+ }, _ = (n, e) => {
621
+ n.addNode("blok", (t) => {
622
+ let s = "";
623
+ return t.attrs.body.forEach((r) => {
624
+ s += e(r.component, r);
625
+ }), {
626
+ html: s
681
627
  };
682
628
  });
683
- };
684
- const renderRichText = (data, options, resolverInstance) => {
685
- let localResolver = resolverInstance || richTextResolver;
686
- if (!localResolver) {
687
- console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
629
+ }, se = (n, e, t) => {
630
+ let s = t || y;
631
+ if (!s) {
632
+ console.error(
633
+ "Please initialize the Storyblok SDK before calling the renderRichText function"
634
+ );
688
635
  return;
689
636
  }
690
- if (data === "") {
691
- return "";
692
- } else if (!data) {
693
- console.warn(`${data} is not a valid Richtext object. This might be because the value of the richtext field is empty.
637
+ return n === "" ? "" : n ? (e && (s = new g(e.schema), e.resolver && _(s, e.resolver)), s.render(n)) : (console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
694
638
 
695
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
696
- return "";
697
- }
698
- if (options) {
699
- localResolver = new y(options.schema);
700
- if (options.resolver) {
701
- setComponentResolver(localResolver, options.resolver);
702
- }
703
- }
704
- return localResolver.render(data);
639
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
640
+ }, re = () => w(R);
641
+ export {
642
+ g as RichTextResolver,
643
+ K as RichTextSchema,
644
+ X as apiPlugin,
645
+ re as loadStoryblokBridge,
646
+ ee as registerStoryblokBridge,
647
+ se as renderRichText,
648
+ Z as storyblokEditable,
649
+ te as storyblokInit,
650
+ ee as useStoryblokBridge
705
651
  };
706
- const loadStoryblokBridge = () => loadBridge(bridgeLatest);
707
- export { y as RichTextResolver, F as RichTextSchema, apiFactory as apiPlugin, loadStoryblokBridge, useStoryblokBridge as registerStoryblokBridge, renderRichText, editable as storyblokEditable, storyblokInit, useStoryblokBridge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "SDK to integrate Storyblok into your project using JavaScript.",
5
5
  "main": "./dist/storyblok-js.js",
6
6
  "module": "./dist/storyblok-js.mjs",
@@ -19,25 +19,25 @@
19
19
  "build": "vite build && tsc --project tsconfig.json",
20
20
  "test": "npm run test:unit && npm run test:e2e",
21
21
  "test:unit": "vitest run",
22
- "test:e2e": "start-server-and-test cy:playground http-get://localhost:3000/ cy:run",
23
- "test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:3000/ cy:open",
22
+ "test:e2e": "start-server-and-test cy:playground http://localhost:5173/ cy:run",
23
+ "test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:5173/ cy:open",
24
24
  "cy:playground": "npm run demo --prefix ../playground",
25
25
  "cy:run": "cypress run",
26
26
  "cy:open": "cypress open",
27
27
  "prepublishOnly": "npm run build && cp ../README.md ./"
28
28
  },
29
29
  "dependencies": {
30
- "storyblok-js-client": "^5.2.5"
30
+ "storyblok-js-client": "^5.3.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@tsconfig/recommended": "^1.0.1",
34
- "cypress": "^9.6.1",
34
+ "cypress": "^12.3.0",
35
35
  "eslint-plugin-cypress": "^2.12.1",
36
36
  "eslint-plugin-jest": "^26.9.0",
37
37
  "isomorphic-fetch": "^3.0.0",
38
- "start-server-and-test": "^1.14.0",
39
- "vite": "^2.9.15",
40
- "vitest": "^0.26.3"
38
+ "start-server-and-test": "^1.15.2",
39
+ "vite": "^4.0.4",
40
+ "vitest": "^0.27.2"
41
41
  },
42
42
  "babel": {
43
43
  "presets": [