@storyblok/js 2.0.15 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
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=[],w=o=>new Promise((t,e)=>{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=o,s.id="storyblok-javascript-bridge",s.onerror=r=>e(r),s.onload=r=>{v.forEach(n=>n()),p=!0,t(r)},document.getElementsByTagName("head")[0].appendChild(s)});var E=Object.defineProperty,S=(o,t,e)=>t in o?E(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,c=(o,t,e)=>(S(o,typeof t!="symbol"?t+"":t,e),e);function T(o){return!(o!==o||o===1/0||o===-1/0)}function x(o,t,e){if(!T(t))throw new TypeError("Expected `limit` to be a finite number");if(!T(e))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const l=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(u){return u!==l})},e);r.indexOf(l)<0&&r.push(l);const h=s.shift();h.resolve(o.apply(h.self,h.args))},a=function(...l){const h=this;return new Promise(function(u,k){s.push({resolve:u,reject:k,args:l,self:h}),n<t&&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 O=function(o,t){const e={};for(const s in o){const r=o[s];t.indexOf(s)>-1&&r!==null&&(e[s]=r)}return e},I=o=>o==="email",C=()=>({singleTag:"hr"}),A=()=>({tag:"blockquote"}),M=()=>({tag:"ul"}),N=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),L=()=>({singleTag:"br"}),U=o=>({tag:`h${o.attrs.level}`}),B=o=>({singleTag:[{tag:"img",attrs:O(o.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=o=>{const t={...o.attrs},{linktype:e="url"}=o.attrs;return I(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},G=o=>({tag:[{tag:"span",attrs:o.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(o){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,s=RegExp(e.source);return o&&s.test(o)?o.replace(e,r=>t[r]):o};class f{constructor(t){c(this,"marks"),c(this,"nodes"),t||(t=R),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t){if(t&&t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(s=>{e+=this.renderNode(s)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){const e=[];t.marks&&t.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&e.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach(r=>{e.push(this.renderNode(r))}):t.text?e.push(W(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=>{const n=this.getMatchingMark(r);n&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}}class _{constructor(){c(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),c(this,"getOptionsPage",(t,e=25,s=1)=>({...t,per_page:e,page:s})),c(this,"delay",t=>new Promise(e=>setTimeout(e,t))),c(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),c(this,"range",(t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,(n,i)=>i*r+t)}),c(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),c(this,"flatMap",(t=[],e)=>t.map(e).reduce((s,r)=>[...s,...r],[]))}stringify(t,e,s){const r=[];for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const i=t[n],a=s?"":encodeURIComponent(n);let l;typeof i=="object"?l=this.stringify(i,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):l=(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(l)}return r.join("&")}}class X{constructor(t){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=t.baseURL,this.headers=t.headers||[],this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(r=>{s.data=r});for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if(t==="get"){const l=new _;e=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const l=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const h=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(l){return{message:l}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((s,r)=>{if(e.test(`${t.status}`))return s(t);const n={message:new Error(t.statusText),status:t.status,response:t.data.error||t.data.slug};r(n)})}}let m={};const g={};class Z{constructor(t,e){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"),!e){const n=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";t.oauthToken?e=`${i}://api${n}.storyblok.com/v1`:e=`${i}://api${n}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((n,i)=>{t.headers&&t.headers[i]&&s.set(i,t.headers[i])});let r=5;t.oauthToken&&(s.set("Authorization",t.oauthToken),r=3),t.rateLimit&&(r=t.rateLimit),t.richTextSchema?this.richTextResolver=new f(t.richTextSchema):this.richTextResolver=new f,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries,this.throttle=x(this.throttledRequest,r,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new _,this.resolveNestedRelations=!1,this.client=new X({baseURL:e,timeout:t.timeout||0,headers:s,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const n=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,n)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(e==null?void 0:e.per_page)||25,n=`/${t}`,i=n.split("/"),a=s||i[i.length-1],l=1,h=await this.makeRequest(n,e,r,l),u=h.total?Math.ceil(h.total/r):1,k=await this.helpers.asyncMap(this.helpers.range(l,u),b=>this.makeRequest(n,e,r,b+1));return this.helpers.flatMap([h,...k],b=>Object.values(b.data[a]))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const s=t[e];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(t,e,s){if(s.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e]&&t[e].constructor===Array){const r=[];t[e].forEach(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),t[e]=r}}}iterateTree(t,e){const s=r=>{if(r!=null){if(r.constructor===Array)for(let n=0;n<r.length;n++)s(r[n]);else if(r.constructor===Object){if(r._stopResolving)return;for(const n in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,n,e),this._insertLinks(r,n)),s(r[n])}}};s(t.content)}async resolveLinks(t,e){let s=[];if(t.link_uuids){const r=t.link_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);n.push(t.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=t.links;s.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(t,e){let s=[];if(t.rel_uuids){const r=t.rel_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);n.push(t.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=t.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(t,e){var s,r;let n=[];if(typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(n=e.resolve_relations.split(",")),await this.resolveRelations(t,e)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((s=t.links)!=null&&s.length||(r=t.link_uuids)!=null&&r.length)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],n);t.story?this.iterateTree(t.story,n):t.stories.forEach(i=>{this.iterateTree(i,n)})}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),n=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var l;try{const h=await this.throttle("get",t,e);let u={data:h.data,headers:h.headers};return(l=h.headers)!=null&&l["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?a(h):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&await n.set(r,u),u.data.cv&&e.token&&(e.version=="draft"&&g[e.token]!=u.data.cv&&await this.flushCache(),g[e.token]=u.data.cv),i(u))}catch(h){return a(h)}})()}catch{}})}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(m[t])},getAll(){return Promise.resolve(m)},set(t,e){return m[t]=e,Promise.resolve(void 0)},flush(){return m={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const tt=(o={})=>{const{apiOptions:t}=o;if(!t.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(t)}},et=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let y;const $="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,t,e={})=>{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(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],r=>{r.action==="input"&&r.story.id===o?t(r.story):(r.action==="change"||r.action==="published")&&r.storyId===o&&window.location.reload()})})}},st=(o={})=>{const{bridge:t,accessToken:e,use:s=[],apiOptions:r={},richText:n={}}=o;r.accessToken=r.accessToken||e;const i={bridge:t,apiOptions:r};let a={};return s.forEach(l=>{a={...a,...l(i)}}),t!==!1&&w($),y=new f(n.schema),n.resolver&&j(y,n.resolver),a},j=(o,t)=>{o.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})},rt=(o,t,e)=>{let s=e||y;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(t&&(s=new f(t.schema),t.resolver&&j(s,t.resolver)),s.render(o)):(console.warn(`${o} 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 b=[],w=i=>new Promise((t,e)=>{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():b.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>e(r),s.onload=r=>{b.forEach(n=>n()),p=!0,t(r)},document.getElementsByTagName("head")[0].appendChild(s)});var E=Object.defineProperty,S=(i,t,e)=>t in i?E(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,l=(i,t,e)=>(S(i,typeof t!="symbol"?t+"":t,e),e);function T(i){return!(i!==i||i===1/0||i===-1/0)}function x(i,t,e){if(!T(t))throw new TypeError("Expected `limit` to be a finite number");if(!T(e))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const o=function(){n++;const c=setTimeout(function(){n--,s.length>0&&o(),r=r.filter(function(u){return u!==c})},e);r.indexOf(c)<0&&r.push(c);const h=s.shift();h.resolve(i.apply(h.self,h.args))},a=function(...c){const h=this;return new Promise(function(u,f){s.push({resolve:u,reject:f,args:c,self:h}),n<t&&o()})};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 O=function(i,t){const e={};for(const s in i){const r=i[s];t.indexOf(s)>-1&&r!==null&&(e[s]=r)}return e},I=i=>i==="email",C=()=>({singleTag:"hr"}),A=()=>({tag:"blockquote"}),M=()=>({tag:"ul"}),N=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),L=()=>({singleTag:"br"}),U=i=>({tag:`h${i.attrs.level}`}),B=i=>({singleTag:[{tag:"img",attrs:O(i.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=i=>{const t={...i.attrs},{linktype:e="url"}=i.attrs;return I(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},G=i=>({tag:[{tag:"span",attrs:i.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(i){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,s=RegExp(e.source);return i&&s.test(i)?i.replace(e,r=>t[r]):i};class m{constructor(t){l(this,"marks"),l(this,"nodes"),t||(t=R),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t){if(t&&t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(s=>{e+=this.renderNode(s)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){const e=[];t.marks&&t.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&e.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach(r=>{e.push(this.renderNode(r))}):t.text?e.push(W(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=>{const n=this.getMatchingMark(r);n&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const o=s.attrs[n];o!==null&&(r+=` ${n}="${o}"`)}return`${r}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}}class _{constructor(){l(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),l(this,"getOptionsPage",(t,e=25,s=1)=>({...t,per_page:e,page:s})),l(this,"delay",t=>new Promise(e=>setTimeout(e,t))),l(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),l(this,"range",(t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,(n,o)=>o*r+t)}),l(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),l(this,"flatMap",(t=[],e)=>t.map(e).reduce((s,r)=>[...s,...r],[]))}stringify(t,e,s){const r=[];for(const n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const o=t[n],a=s?"":encodeURIComponent(n);let c;typeof o=="object"?c=this.stringify(o,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(o)):c=(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(o),r.push(c)}return r.join("&")}}class X{constructor(t){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=t.baseURL,this.headers=t.headers||[],this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(r=>{s.data=r});for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if(t==="get"){const c=new _;e=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),n=new AbortController,{signal:o}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:o});this.timeout&&clearTimeout(a);const h=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((s,r)=>{if(e.test(`${t.status}`))return s(t);const n={message:new Error(t.statusText),status:t.status,response:t.data.error||t.data.slug};r(n)})}}let k={};const g={};class Z{constructor(t,e){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"),!e){const n=t.region?`-${t.region}`:"",o=t.https===!1?"http":"https";t.oauthToken?e=`${o}://api${n}.storyblok.com/v1`:e=`${o}://api${n}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((n,o)=>{t.headers&&t.headers[o]&&s.set(o,t.headers[o])});let r=5;t.oauthToken&&(s.set("Authorization",t.oauthToken),r=3),t.rateLimit&&(r=t.rateLimit),t.richTextSchema?this.richTextResolver=new m(t.richTextSchema):this.richTextResolver=new m,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries,this.throttle=x(this.throttledRequest,r,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new _,this.resolveNestedRelations=!1,this.client=new X({baseURL:e,timeout:t.timeout||0,headers:s,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const n=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,n)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(e==null?void 0:e.per_page)||25,n=`/${t}`,o=n.split("/"),a=s||o[o.length-1],c=1,h=await this.makeRequest(n,e,r,c),u=h.total?Math.ceil(h.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(c,u),y=>this.makeRequest(n,e,r,y+1));return this.helpers.flatMap([h,...f],y=>Object.values(y.data[a]))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const s=t[e];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(t,e,s){if(s.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e]&&t[e].constructor===Array){const r=[];t[e].forEach(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),t[e]=r}}}iterateTree(t,e){const s=r=>{if(r!=null){if(r.constructor===Array)for(let n=0;n<r.length;n++)s(r[n]);else if(r.constructor===Object){if(r._stopResolving)return;for(const n in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,n,e),this._insertLinks(r,n)),s(r[n])}}};s(t.content)}async resolveLinks(t,e){let s=[];if(t.link_uuids){const r=t.link_uuids.length,n=[],o=50;for(let a=0;a<r;a+=o){const c=Math.min(r,a+o);n.push(t.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:o,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=t.links;s.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(t,e){let s=[];if(t.rel_uuids){const r=t.rel_uuids.length,n=[],o=50;for(let a=0;a<r;a+=o){const c=Math.min(r,a+o);n.push(t.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:o,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=t.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(t,e){var s,r;let n=[];if(typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(n=e.resolve_relations.split(",")),await this.resolveRelations(t,e)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((s=t.links)!=null&&s.length||(r=t.link_uuids)!=null&&r.length)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const o in this.relations)this.iterateTree(this.relations[o],n);t.story?this.iterateTree(t.story,n):t.stories.forEach(o=>{this.iterateTree(o,n)})}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),n=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const o=await n.get(r);if(o)return Promise.resolve(o)}return new Promise((o,a)=>{try{(async()=>{var c;try{const h=await this.throttle("get",t,e);let u={data:h.data,headers:h.headers};return(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?a(h):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&await n.set(r,u),u.data.cv&&e.token&&(e.version=="draft"&&g[e.token]!=u.data.cv&&await this.flushCache(),g[e.token]=u.data.cv),o(u))}catch(h){return a(h)}})()}catch{}})}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(k[t])},getAll(){return Promise.resolve(k)},set(t,e){return k[t]=e,Promise.resolve(void 0)},flush(){return k={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const tt=(i={})=>{const{apiOptions:t}=i;if(!t.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(t)}},et=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};const t=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let v;const $="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(i,t,e={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],o=>{o.action==="input"&&o.story.id===i?t(o.story):(o.action==="change"||o.action==="published")&&o.storyId===i&&window.location.reload()})})}},st=(i={})=>{var u,f;const{bridge:t,accessToken:e,use:s=[],apiOptions:r={},richText:n={}}=i;r.accessToken=r.accessToken||e;const o={bridge:t,apiOptions:r};let a={};s.forEach(y=>{a={...a,...y(o)}});const h=!(typeof window>"u")&&((f=(u=window.location)==null?void 0:u.search)==null?void 0:f.includes("_storyblok_tk"));return t!==!1&&h&&w($),v=new m(n.schema),n.resolver&&j(v,n.resolver),a},j=(i,t)=>{i.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})},rt=(i,t,e)=>{let s=e||v;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return i===""?"":i?(t&&(s=new m(t.schema),t.resolver&&j(s,t.resolver)),s.render(i)):(console.warn(`${i} 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`),"")},nt=()=>w($);d.RichTextResolver=f,d.RichTextSchema=R,d.apiPlugin=tt,d.loadStoryblokBridge=nt,d.registerStoryblokBridge=P,d.renderRichText=rt,d.storyblokEditable=et,d.storyblokInit=st,d.useStoryblokBridge=P,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
3
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},nt=()=>w($);d.RichTextResolver=m,d.RichTextSchema=R,d.apiPlugin=tt,d.loadStoryblokBridge=nt,d.registerStoryblokBridge=P,d.renderRichText=rt,d.storyblokEditable=et,d.storyblokInit=st,d.useStoryblokBridge=P,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
@@ -1,88 +1,88 @@
1
- let k = !1;
2
- const v = [], w = (n) => new Promise((t, e) => {
1
+ let v = !1;
2
+ const k = [], w = (o) => new Promise((t, e) => {
3
3
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
4
  if (window.location === window.parent.location) {
5
5
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
6
  return;
7
7
  }
8
- k ? r() : v.push(r);
8
+ v ? r() : k.push(r);
9
9
  }, document.getElementById("storyblok-javascript-bridge")))
10
10
  return;
11
11
  const s = document.createElement("script");
12
- s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
13
- v.forEach((o) => o()), k = !0, t(r);
12
+ s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
13
+ k.forEach((n) => n()), v = !0, t(r);
14
14
  }, document.getElementsByTagName("head")[0].appendChild(s);
15
15
  });
16
- var $ = Object.defineProperty, P = (n, t, e) => t in n ? $(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, c = (n, t, e) => (P(n, typeof t != "symbol" ? t + "" : t, e), e);
17
- function b(n) {
18
- return !(n !== n || n === 1 / 0 || n === -1 / 0);
16
+ var $ = Object.defineProperty, P = (o, t, e) => t in o ? $(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, l = (o, t, e) => (P(o, typeof t != "symbol" ? t + "" : t, e), e);
17
+ function b(o) {
18
+ return !(o !== o || o === 1 / 0 || o === -1 / 0);
19
19
  }
20
- function j(n, t, e) {
20
+ function x(o, t, e) {
21
21
  if (!b(t))
22
22
  throw new TypeError("Expected `limit` to be a finite number");
23
23
  if (!b(e))
24
24
  throw new TypeError("Expected `interval` to be a finite number");
25
25
  const s = [];
26
- let r = [], o = 0;
26
+ let r = [], n = 0;
27
27
  const i = function() {
28
- o++;
29
- const l = setTimeout(function() {
30
- o--, s.length > 0 && i(), r = r.filter(function(u) {
31
- return u !== l;
28
+ n++;
29
+ const c = setTimeout(function() {
30
+ n--, s.length > 0 && i(), r = r.filter(function(u) {
31
+ return u !== c;
32
32
  });
33
33
  }, e);
34
- r.indexOf(l) < 0 && r.push(l);
34
+ r.indexOf(c) < 0 && r.push(c);
35
35
  const h = s.shift();
36
- h.resolve(n.apply(h.self, h.args));
37
- }, a = function(...l) {
36
+ h.resolve(o.apply(h.self, h.args));
37
+ }, a = function(...c) {
38
38
  const h = this;
39
- return new Promise(function(u, f) {
39
+ return new Promise(function(u, d) {
40
40
  s.push({
41
41
  resolve: u,
42
- reject: f,
43
- args: l,
42
+ reject: d,
43
+ args: c,
44
44
  self: h
45
- }), o < t && i();
45
+ }), n < t && i();
46
46
  });
47
47
  };
48
48
  return a.abort = function() {
49
- r.forEach(clearTimeout), r = [], s.forEach(function(l) {
50
- l.reject(function() {
49
+ r.forEach(clearTimeout), r = [], s.forEach(function(c) {
50
+ c.reject(function() {
51
51
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
52
52
  });
53
53
  }), s.length = 0;
54
54
  }, a;
55
55
  }
56
- const x = function(n, t) {
56
+ const E = function(o, t) {
57
57
  const e = {};
58
- for (const s in n) {
59
- const r = n[s];
58
+ for (const s in o) {
59
+ const r = o[s];
60
60
  t.indexOf(s) > -1 && r !== null && (e[s] = r);
61
61
  }
62
62
  return e;
63
- }, E = (n) => n === "email", S = () => ({
63
+ }, j = (o) => o === "email", S = () => ({
64
64
  singleTag: "hr"
65
65
  }), O = () => ({
66
66
  tag: "blockquote"
67
67
  }), C = () => ({
68
68
  tag: "ul"
69
- }), I = (n) => ({
69
+ }), I = (o) => ({
70
70
  tag: [
71
71
  "pre",
72
72
  {
73
73
  tag: "code",
74
- attrs: n.attrs
74
+ attrs: o.attrs
75
75
  }
76
76
  ]
77
77
  }), A = () => ({
78
78
  singleTag: "br"
79
- }), N = (n) => ({
80
- tag: `h${n.attrs.level}`
81
- }), M = (n) => ({
79
+ }), N = (o) => ({
80
+ tag: `h${o.attrs.level}`
81
+ }), M = (o) => ({
82
82
  singleTag: [
83
83
  {
84
84
  tag: "img",
85
- attrs: x(n.attrs, ["src", "alt", "title"])
85
+ attrs: E(o.attrs, ["src", "alt", "title"])
86
86
  }
87
87
  ]
88
88
  }), L = () => ({
@@ -103,9 +103,9 @@ const x = function(n, t) {
103
103
  tag: "code"
104
104
  }), V = () => ({
105
105
  tag: "i"
106
- }), z = (n) => {
107
- const t = { ...n.attrs }, { linktype: e = "url" } = n.attrs;
108
- return E(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
106
+ }), z = (o) => {
107
+ const t = { ...o.attrs }, { linktype: e = "url" } = o.attrs;
108
+ return j(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
109
109
  tag: [
110
110
  {
111
111
  tag: "a",
@@ -113,11 +113,11 @@ const x = function(n, t) {
113
113
  }
114
114
  ]
115
115
  };
116
- }, Y = (n) => ({
116
+ }, Y = (o) => ({
117
117
  tag: [
118
118
  {
119
119
  tag: "span",
120
- attrs: n.attrs
120
+ attrs: o.attrs
121
121
  }
122
122
  ]
123
123
  }), K = {
@@ -143,7 +143,7 @@ const x = function(n, t) {
143
143
  link: z,
144
144
  styled: Y
145
145
  }
146
- }, Q = function(n) {
146
+ }, Q = function(o) {
147
147
  const t = {
148
148
  "&": "&amp;",
149
149
  "<": "&lt;",
@@ -151,11 +151,11 @@ const x = function(n, t) {
151
151
  '"': "&quot;",
152
152
  "'": "&#39;"
153
153
  }, e = /[&<>"']/g, s = RegExp(e.source);
154
- return n && s.test(n) ? n.replace(e, (r) => t[r]) : n;
154
+ return o && s.test(o) ? o.replace(e, (r) => t[r]) : o;
155
155
  };
156
- class g {
156
+ class m {
157
157
  constructor(t) {
158
- c(this, "marks"), c(this, "nodes"), t || (t = K), this.marks = t.marks || [], this.nodes = t.nodes || [];
158
+ l(this, "marks"), l(this, "nodes"), t || (t = K), this.marks = t.marks || [], this.nodes = t.nodes || [];
159
159
  }
160
160
  addNode(t, e) {
161
161
  this.nodes[t] = e;
@@ -177,15 +177,15 @@ class g {
177
177
  renderNode(t) {
178
178
  const e = [];
179
179
  t.marks && t.marks.forEach((r) => {
180
- const o = this.getMatchingMark(r);
181
- o && e.push(this.renderOpeningTag(o.tag));
180
+ const n = this.getMatchingMark(r);
181
+ n && e.push(this.renderOpeningTag(n.tag));
182
182
  });
183
183
  const s = this.getMatchingNode(t);
184
184
  return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
185
185
  e.push(this.renderNode(r));
186
186
  }) : t.text ? e.push(Q(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) => {
187
- const o = this.getMatchingMark(r);
188
- o && e.push(this.renderClosingTag(o.tag));
187
+ const n = this.getMatchingMark(r);
188
+ n && e.push(this.renderClosingTag(n.tag));
189
189
  }), e.join("");
190
190
  }
191
191
  renderTag(t, e) {
@@ -195,9 +195,9 @@ class g {
195
195
  {
196
196
  let r = `<${s.tag}`;
197
197
  if (s.attrs)
198
- for (const o in s.attrs) {
199
- const i = s.attrs[o];
200
- i !== null && (r += ` ${o}="${i}"`);
198
+ for (const n in s.attrs) {
199
+ const i = s.attrs[n];
200
+ i !== null && (r += ` ${n}="${i}"`);
201
201
  }
202
202
  return `${r}${e}>`;
203
203
  }
@@ -222,34 +222,34 @@ class g {
222
222
  }
223
223
  class T {
224
224
  constructor() {
225
- c(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), c(this, "getOptionsPage", (t, e = 25, s = 1) => ({
225
+ l(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), l(this, "getOptionsPage", (t, e = 25, s = 1) => ({
226
226
  ...t,
227
227
  per_page: e,
228
228
  page: s
229
- })), c(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), c(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), c(this, "range", (t = 0, e = t) => {
229
+ })), l(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), l(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), l(this, "range", (t = 0, e = t) => {
230
230
  const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
231
- return this.arrayFrom(s, (o, i) => i * r + t);
232
- }), c(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), c(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
231
+ return this.arrayFrom(s, (n, i) => i * r + t);
232
+ }), l(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), l(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
233
233
  }
234
234
  stringify(t, e, s) {
235
235
  const r = [];
236
- for (const o in t) {
237
- if (!Object.prototype.hasOwnProperty.call(t, o))
236
+ for (const n in t) {
237
+ if (!Object.prototype.hasOwnProperty.call(t, n))
238
238
  continue;
239
- const i = t[o], a = s ? "" : encodeURIComponent(o);
240
- let l;
241
- typeof i == "object" ? l = this.stringify(
239
+ const i = t[n], a = s ? "" : encodeURIComponent(n);
240
+ let c;
241
+ typeof i == "object" ? c = this.stringify(
242
242
  i,
243
243
  e ? e + encodeURIComponent("[" + a + "]") : a,
244
244
  Array.isArray(i)
245
- ) : l = (e ? e + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), r.push(l);
245
+ ) : c = (e ? e + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), r.push(c);
246
246
  }
247
247
  return r.join("&");
248
248
  }
249
249
  }
250
250
  class G {
251
251
  constructor(t) {
252
- 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 = t.baseURL, this.headers = t.headers || [], this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
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 = t.baseURL, this.headers = t.headers || [], this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
253
253
  }
254
254
  get(t, e) {
255
255
  return this.url = t, this.parameters = e, this._methodHandler("get");
@@ -280,28 +280,28 @@ class G {
280
280
  async _methodHandler(t) {
281
281
  let e = `${this.baseURL}${this.url}`, s = null;
282
282
  if (t === "get") {
283
- const l = new T();
284
- e = `${this.baseURL}${this.url}?${l.stringify(
283
+ const c = new T();
284
+ e = `${this.baseURL}${this.url}?${c.stringify(
285
285
  this.parameters
286
286
  )}`;
287
287
  } else
288
288
  s = JSON.stringify(this.parameters);
289
- const r = new URL(e), o = new AbortController(), { signal: i } = o;
289
+ const r = new URL(e), n = new AbortController(), { signal: i } = n;
290
290
  let a;
291
- this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
291
+ this.timeout && (a = setTimeout(() => n.abort(), this.timeout));
292
292
  try {
293
- const l = await this.fetch(`${r}`, {
293
+ const c = await this.fetch(`${r}`, {
294
294
  method: t,
295
295
  headers: this.headers,
296
296
  body: s,
297
297
  signal: i
298
298
  });
299
299
  this.timeout && clearTimeout(a);
300
- const h = await this._responseHandler(l);
300
+ const h = await this._responseHandler(c);
301
301
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
302
- } catch (l) {
302
+ } catch (c) {
303
303
  return {
304
- message: l
304
+ message: c
305
305
  };
306
306
  }
307
307
  }
@@ -313,29 +313,29 @@ class G {
313
313
  return new Promise((s, r) => {
314
314
  if (e.test(`${t.status}`))
315
315
  return s(t);
316
- const o = {
316
+ const n = {
317
317
  message: new Error(t.statusText),
318
318
  status: t.status,
319
319
  response: t.data.error || t.data.slug
320
320
  };
321
- r(o);
321
+ r(n);
322
322
  });
323
323
  }
324
324
  }
325
- let p = {};
326
- const d = {};
325
+ let f = {};
326
+ const p = {};
327
327
  class W {
328
328
  constructor(t, e) {
329
- 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"), !e) {
330
- const o = t.region ? `-${t.region}` : "", i = t.https === !1 ? "http" : "https";
331
- t.oauthToken ? e = `${i}://api${o}.storyblok.com/v1` : e = `${i}://api${o}.storyblok.com/v2`;
329
+ 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"), !e) {
330
+ const n = t.region ? `-${t.region}` : "", i = t.https === !1 ? "http" : "https";
331
+ t.oauthToken ? e = `${i}://api${n}.storyblok.com/v1` : e = `${i}://api${n}.storyblok.com/v2`;
332
332
  }
333
333
  const s = new Headers();
334
- s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((o, i) => {
334
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((n, i) => {
335
335
  t.headers && t.headers[i] && s.set(i, t.headers[i]);
336
336
  });
337
337
  let r = 5;
338
- t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new g(t.richTextSchema) : this.richTextResolver = new g(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = j(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new T(), this.resolveNestedRelations = !1, this.client = new G({
338
+ t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new m(t.richTextSchema) : this.richTextResolver = new m(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = x(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new T(), this.resolveNestedRelations = !1, this.client = new G({
339
339
  baseURL: e,
340
340
  timeout: t.timeout || 0,
341
341
  headers: s,
@@ -354,17 +354,17 @@ class W {
354
354
  });
355
355
  }
356
356
  parseParams(t) {
357
- 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;
357
+ return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = p[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
358
358
  }
359
359
  factoryParamOptions(t, e) {
360
360
  return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
361
361
  }
362
362
  makeRequest(t, e, s, r) {
363
- const o = this.factoryParamOptions(
363
+ const n = this.factoryParamOptions(
364
364
  t,
365
365
  this.helpers.getOptionsPage(e, s, r)
366
366
  );
367
- return this.cacheResponse(t, o);
367
+ return this.cacheResponse(t, n);
368
368
  }
369
369
  get(t, e) {
370
370
  e || (e = {});
@@ -372,13 +372,13 @@ class W {
372
372
  return this.cacheResponse(s, r);
373
373
  }
374
374
  async getAll(t, e, s) {
375
- const r = (e == null ? void 0 : e.per_page) || 25, o = `/${t}`, i = o.split("/"), a = s || i[i.length - 1], l = 1, h = await this.makeRequest(o, e, r, l), u = h.total ? Math.ceil(h.total / r) : 1, f = await this.helpers.asyncMap(
376
- this.helpers.range(l, u),
377
- (m) => this.makeRequest(o, e, r, m + 1)
375
+ const r = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, i = n.split("/"), a = s || i[i.length - 1], c = 1, h = await this.makeRequest(n, e, r, c), u = h.total ? Math.ceil(h.total / r) : 1, d = await this.helpers.asyncMap(
376
+ this.helpers.range(c, u),
377
+ (g) => this.makeRequest(n, e, r, g + 1)
378
378
  );
379
379
  return this.helpers.flatMap(
380
- [h, ...f],
381
- (m) => Object.values(m.data[a])
380
+ [h, ...d],
381
+ (g) => Object.values(g.data[a])
382
382
  );
383
383
  }
384
384
  post(t, e) {
@@ -418,8 +418,8 @@ class W {
418
418
  this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
419
419
  else if (t[e] && t[e].constructor === Array) {
420
420
  const r = [];
421
- t[e].forEach((o) => {
422
- this.relations[o] && r.push(this._cleanCopy(this.relations[o]));
421
+ t[e].forEach((n) => {
422
+ this.relations[n] && r.push(this._cleanCopy(this.relations[n]));
423
423
  }), t[e] = r;
424
424
  }
425
425
  }
@@ -428,17 +428,17 @@ class W {
428
428
  const s = (r) => {
429
429
  if (r != null) {
430
430
  if (r.constructor === Array)
431
- for (let o = 0; o < r.length; o++)
432
- s(r[o]);
431
+ for (let n = 0; n < r.length; n++)
432
+ s(r[n]);
433
433
  else if (r.constructor === Object) {
434
434
  if (r._stopResolving)
435
435
  return;
436
- for (const o in r)
436
+ for (const n in r)
437
437
  (r.component && r._uid || r.type === "link") && (this._insertRelations(
438
438
  r,
439
- o,
439
+ n,
440
440
  e
441
- ), this._insertLinks(r, o)), s(r[o]);
441
+ ), this._insertLinks(r, n)), s(r[n]);
442
442
  }
443
443
  }
444
444
  };
@@ -447,20 +447,20 @@ class W {
447
447
  async resolveLinks(t, e) {
448
448
  let s = [];
449
449
  if (t.link_uuids) {
450
- const r = t.link_uuids.length, o = [], i = 50;
450
+ const r = t.link_uuids.length, n = [], i = 50;
451
451
  for (let a = 0; a < r; a += i) {
452
- const l = Math.min(r, a + i);
453
- o.push(t.link_uuids.slice(a, l));
452
+ const c = Math.min(r, a + i);
453
+ n.push(t.link_uuids.slice(a, c));
454
454
  }
455
- for (let a = 0; a < o.length; a++)
455
+ for (let a = 0; a < n.length; a++)
456
456
  (await this.getStories({
457
457
  per_page: i,
458
458
  language: e.language,
459
459
  version: e.version,
460
- by_uuids: o[a].join(",")
460
+ by_uuids: n[a].join(",")
461
461
  })).data.stories.forEach(
462
- (l) => {
463
- s.push(l);
462
+ (c) => {
463
+ s.push(c);
464
464
  }
465
465
  );
466
466
  } else
@@ -472,19 +472,19 @@ class W {
472
472
  async resolveRelations(t, e) {
473
473
  let s = [];
474
474
  if (t.rel_uuids) {
475
- const r = t.rel_uuids.length, o = [], i = 50;
475
+ const r = t.rel_uuids.length, n = [], i = 50;
476
476
  for (let a = 0; a < r; a += i) {
477
- const l = Math.min(r, a + i);
478
- o.push(t.rel_uuids.slice(a, l));
477
+ const c = Math.min(r, a + i);
478
+ n.push(t.rel_uuids.slice(a, c));
479
479
  }
480
- for (let a = 0; a < o.length; a++)
480
+ for (let a = 0; a < n.length; a++)
481
481
  (await this.getStories({
482
482
  per_page: i,
483
483
  language: e.language,
484
484
  version: e.version,
485
- by_uuids: o[a].join(",")
486
- })).data.stories.forEach((l) => {
487
- s.push(l);
485
+ by_uuids: n[a].join(",")
486
+ })).data.stories.forEach((c) => {
487
+ s.push(c);
488
488
  });
489
489
  } else
490
490
  s = t.rels;
@@ -494,32 +494,32 @@ class W {
494
494
  }
495
495
  async resolveStories(t, e) {
496
496
  var s, r;
497
- let o = [];
498
- if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (o = e.resolve_relations.split(",")), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && ((s = t.links) != null && s.length || (r = t.link_uuids) != null && r.length) && await this.resolveLinks(t, e), this.resolveNestedRelations)
497
+ let n = [];
498
+ if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (n = e.resolve_relations.split(",")), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && ((s = t.links) != null && s.length || (r = t.link_uuids) != null && r.length) && await this.resolveLinks(t, e), this.resolveNestedRelations)
499
499
  for (const i in this.relations)
500
- this.iterateTree(this.relations[i], o);
501
- t.story ? this.iterateTree(t.story, o) : t.stories.forEach((i) => {
502
- this.iterateTree(i, o);
500
+ this.iterateTree(this.relations[i], n);
501
+ t.story ? this.iterateTree(t.story, n) : t.stories.forEach((i) => {
502
+ this.iterateTree(i, n);
503
503
  });
504
504
  }
505
505
  async cacheResponse(t, e, s) {
506
- const r = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
506
+ const r = this.helpers.stringify({ url: t, params: e }), n = this.cacheProvider();
507
507
  if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
508
- const i = await o.get(r);
508
+ const i = await n.get(r);
509
509
  if (i)
510
510
  return Promise.resolve(i);
511
511
  }
512
512
  return new Promise((i, a) => {
513
513
  try {
514
514
  (async () => {
515
- var l;
515
+ var c;
516
516
  try {
517
517
  const h = await this.throttle("get", t, e);
518
518
  let u = { data: h.data, headers: h.headers };
519
- return (l = h.headers) != null && l["per-page"] && (u = Object.assign({}, u, {
519
+ return (c = h.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
520
520
  perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
521
521
  total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
522
- })), h.status != 200 ? a(h) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && await o.set(r, u), u.data.cv && e.token && (e.version == "draft" && d[e.token] != u.data.cv && await this.flushCache(), d[e.token] = u.data.cv), i(u));
522
+ })), h.status != 200 ? a(h) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && await n.set(r, u), u.data.cv && e.token && (e.version == "draft" && p[e.token] != u.data.cv && await this.flushCache(), p[e.token] = u.data.cv), i(u));
523
523
  } catch (h) {
524
524
  return a(h);
525
525
  }
@@ -532,29 +532,29 @@ class W {
532
532
  return this.client[t](e, s);
533
533
  }
534
534
  cacheVersions() {
535
- return d;
535
+ return p;
536
536
  }
537
537
  cacheVersion() {
538
- return d[this.accessToken];
538
+ return p[this.accessToken];
539
539
  }
540
540
  setCacheVersion(t) {
541
- this.accessToken && (d[this.accessToken] = t);
541
+ this.accessToken && (p[this.accessToken] = t);
542
542
  }
543
543
  cacheProvider() {
544
544
  switch (this.cache.type) {
545
545
  case "memory":
546
546
  return {
547
547
  get(t) {
548
- return Promise.resolve(p[t]);
548
+ return Promise.resolve(f[t]);
549
549
  },
550
550
  getAll() {
551
- return Promise.resolve(p);
551
+ return Promise.resolve(f);
552
552
  },
553
553
  set(t, e) {
554
- return p[t] = e, Promise.resolve(void 0);
554
+ return f[t] = e, Promise.resolve(void 0);
555
555
  },
556
556
  flush() {
557
- return p = {}, Promise.resolve(void 0);
557
+ return f = {}, Promise.resolve(void 0);
558
558
  }
559
559
  };
560
560
  case "custom":
@@ -581,8 +581,8 @@ class W {
581
581
  return await this.cacheProvider().flush(), this;
582
582
  }
583
583
  }
584
- const X = (n = {}) => {
585
- const { apiOptions: t } = n;
584
+ const X = (o = {}) => {
585
+ const { apiOptions: t } = o;
586
586
  if (!t.accessToken) {
587
587
  console.error(
588
588
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
@@ -590,11 +590,11 @@ const X = (n = {}) => {
590
590
  return;
591
591
  }
592
592
  return { storyblokApi: new W(t) };
593
- }, Z = (n) => {
594
- if (typeof n != "object" || typeof n._editable > "u")
593
+ }, Z = (o) => {
594
+ if (typeof o != "object" || typeof o._editable > "u")
595
595
  return {};
596
596
  const t = JSON.parse(
597
- n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
597
+ o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
598
598
  );
599
599
  return {
600
600
  "data-blok-c": JSON.stringify(t),
@@ -602,40 +602,37 @@ const X = (n = {}) => {
602
602
  };
603
603
  };
604
604
  let y;
605
- const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e = {}) => {
606
- if (!(typeof window > "u")) {
607
- if (typeof window.storyblokRegisterEvent > "u") {
608
- console.error(
609
- "Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js"
610
- );
611
- return;
612
- }
613
- if (!n) {
605
+ const _ = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (o, t, e = {}) => {
606
+ if (!(typeof window > "u") && typeof window.storyblokRegisterEvent < "u") {
607
+ if (!o) {
614
608
  console.warn("Story ID is not defined. Please provide a valid ID.");
615
609
  return;
616
610
  }
617
611
  window.storyblokRegisterEvent(() => {
618
- new window.StoryblokBridge(e).on(["input", "published", "change"], (r) => {
619
- r.action === "input" && r.story.id === n ? t(r.story) : (r.action === "change" || r.action === "published") && r.storyId === n && window.location.reload();
612
+ new window.StoryblokBridge(e).on(["input", "published", "change"], (i) => {
613
+ i.action === "input" && i.story.id === o ? t(i.story) : (i.action === "change" || i.action === "published") && i.storyId === o && window.location.reload();
620
614
  });
621
615
  });
622
616
  }
623
- }, et = (n = {}) => {
617
+ }, et = (o = {}) => {
618
+ var u, d;
624
619
  const {
625
620
  bridge: t,
626
621
  accessToken: e,
627
622
  use: s = [],
628
623
  apiOptions: r = {},
629
- richText: o = {}
630
- } = n;
624
+ richText: n = {}
625
+ } = o;
631
626
  r.accessToken = r.accessToken || e;
632
627
  const i = { bridge: t, apiOptions: r };
633
628
  let a = {};
634
- return s.forEach((l) => {
635
- a = { ...a, ...l(i) };
636
- }), t !== !1 && w(R), y = new g(o.schema), o.resolver && _(y, o.resolver), a;
637
- }, _ = (n, t) => {
638
- n.addNode("blok", (e) => {
629
+ s.forEach((g) => {
630
+ a = { ...a, ...g(i) };
631
+ });
632
+ const h = !(typeof window > "u") && ((d = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : d.includes("_storyblok_tk"));
633
+ return t !== !1 && h && w(_), y = new m(n.schema), n.resolver && R(y, n.resolver), a;
634
+ }, R = (o, t) => {
635
+ o.addNode("blok", (e) => {
639
636
  let s = "";
640
637
  return e.attrs.body.forEach((r) => {
641
638
  s += t(r.component, r);
@@ -643,7 +640,7 @@ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e =
643
640
  html: s
644
641
  };
645
642
  });
646
- }, st = (n, t, e) => {
643
+ }, st = (o, t, e) => {
647
644
  let s = e || y;
648
645
  if (!s) {
649
646
  console.error(
@@ -651,12 +648,12 @@ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e =
651
648
  );
652
649
  return;
653
650
  }
654
- return n === "" ? "" : n ? (t && (s = new g(t.schema), t.resolver && _(s, t.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.
651
+ return o === "" ? "" : o ? (t && (s = new m(t.schema), t.resolver && R(s, t.resolver)), s.render(o)) : (console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
655
652
 
656
653
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
657
- }, rt = () => w(R);
654
+ }, rt = () => w(_);
658
655
  export {
659
- g as RichTextResolver,
656
+ m as RichTextResolver,
660
657
  K as RichTextSchema,
661
658
  X as apiPlugin,
662
659
  rt as loadStoryblokBridge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
- "version": "2.0.15",
3
+ "version": "2.1.0",
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",