@storyblok/js 2.0.5 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 he=Object.defineProperty,ue=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var pe=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var I=(h,u,g)=>u in h?he(h,u,{enumerable:!0,configurable:!0,writable:!0,value:g}):h[u]=g,f=(h,u)=>{for(var g in u||(u={}))pe.call(u,g)&&I(h,g,u[g]);if(x)for(var g of x(u))ge.call(u,g)&&I(h,g,u[g]);return h},v=(h,u)=>ue(h,de(u));let u=!1;const g=[],_=o=>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=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{g.forEach(n=>n()),u=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var C=Object.defineProperty,M=(o,e,t)=>e in o?C(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,c=(o,e,t)=>(M(o,typeof e!="symbol"?e+"":e,t),t);function E(o){return!(o!==o||o===1/0||o===-1/0)}function N(o,e,t){if(!E(e))throw new TypeError("Expected `limit` to be a finite number");if(!E(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const a=function(){n++;const l=setTimeout(function(){n--,s.length>0&&a(),r=r.filter(function(p){return p!==l})},t);r.indexOf(l)<0&&r.push(l);const d=s.shift();d.resolve(o.apply(d.self,d.args))},i=function(...l){const d=this;return new Promise(function(p,w){s.push({resolve:p,reject:w,args:l,self:d}),n<e&&a()})};return i.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},i}const A=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},L=o=>o==="email",U=()=>({singleTag:"hr"}),B=()=>({tag:"blockquote"}),H=()=>({tag:"ul"}),q=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),D=()=>({singleTag:"br"}),J=o=>({tag:`h${o.attrs.level}`}),F=o=>({singleTag:[{tag:"img",attrs:A(o.attrs,["src","alt","title"])}]}),V=()=>({tag:"li"}),z=()=>({tag:"ol"}),G=()=>({tag:"p"}),Y=()=>({tag:"b"}),K=()=>({tag:"strike"}),Q=()=>({tag:"u"}),W=()=>({tag:"strong"}),X=()=>({tag:"code"}),Z=()=>({tag:"i"}),ee=o=>{const e=f({},o.attrs),{linktype:t="url"}=o.attrs;return L(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},te=o=>({tag:[{tag:"span",attrs:o.attrs}]}),$={nodes:{horizontal_rule:U,blockquote:B,bullet_list:H,code_block:q,hard_break:D,heading:J,image:F,list_item:V,ordered_list:z,paragraph:G},marks:{bold:Y,strike:K,underline:Q,strong:W,code:X,italic:Z,link:ee,styled:te}},se=function(o){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class y{constructor(e){c(this,"marks"),c(this,"nodes"),e||(e=$),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 n=this.getMatchingMark(r);n&&t.push(this.renderOpeningTag(n.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(se(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 n=this.getMatchingMark(r);n&&t.push(this.renderClosingTag(n.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 n in s.attrs){const a=s.attrs[n];a!==null&&(r+=` ${n}="${a}"`)}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 j{constructor(){c(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),c(this,"getOptionsPage",(e,t=25,s=1)=>v(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,(n,a)=>a*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 n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const a=e[n],i=s?"":encodeURIComponent(n);let l;typeof a=="object"?l=this.stringify(a,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(a)):l=(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(a),r.push(l)}return r.join("&")}}var k=(o=>(o.GET="get",o.DELETE="delete",o.POST="post",o.PUT="put",o))(k||{});class re{constructor(e){c(this,"baseURL"),c(this,"timeout"),c(this,"headers"),c(this,"responseInterceptor"),c(this,"ejectInterceptor"),c(this,"url"),c(this,"parameters"),this.baseURL=e.baseURL,this.timeout=e.timeout?e.timeout*1e3:1e3,this.headers=e.headers||[],this.responseInterceptor=e.responseInterceptor,this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler(k.GET)}post(e,t){return this.url=e,this.parameters=t,this._methodHandler(k.POST)}put(e,t){return this.url=e,this.parameters=t,this._methodHandler(k.PUT)}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler(k.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 i=new j;t.search=i.stringify(this.parameters)}else s=JSON.stringify(this.parameters);const r=new AbortController,{signal:n}=r,a=setTimeout(()=>r.abort(),this.timeout);try{const i=await fetch(`${t}`,{method:e,headers:this.headers,body:s,signal:n});clearTimeout(a);const l=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(i){return i}}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 b={};const m={};class oe{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 n=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";e.oauthToken?t=`${a}://api${n}.storyblok.com/v1`:t=`${a}://api${n}.storyblok.com/v2`}const s=Object.assign({},e.headers);let r=5;e.oauthToken&&(s.Authorization=e.oauthToken,r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new y(e.richTextSchema):this.richTextResolver=new y,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=N(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new j,this.resolveNestedRelations=!1,this.client=new re({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor})}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=m[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 n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}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,n=`/${e}`,a=n.split("/"),i=s||a[a.length-1],l=1,d=await this.makeRequest(n,t,r,l),p=d.total?Math.ceil(d.total/r):1,w=await this.helpers.asyncMap(this.helpers.range(l,p),R=>this.makeRequest(n,t,r,R+1));return this.helpers.flatMap([d,...w],R=>Object.values(R.data[i]))}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(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),e[t]=r}}}iterateTree(e,t){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,t),this._insertLinks(r,n)),s(r[n])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,n=[],a=50;for(let i=0;i<r;i+=a){const l=Math.min(r,i+a);n.push(e.link_uuids.slice(i,l))}for(let i=0;i<n.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:n[i].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]=v(f({},r),{_stopResolving:!0})})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,n=[],a=50;for(let i=0;i<r;i+=a){const l=Math.min(r,i+a);n.push(e.rel_uuids.slice(i,l))}for(let i=0;i<n.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:n[i].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=v(f({},r),{_stopResolving:!0})})}async resolveStories(e,t){var s,r;let n=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(n=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 a in this.relations)this.iterateTree(this.relations[a],n);e.story?this.iterateTree(e.story,n):e.stories.forEach(a=>{this.iterateTree(a,n)})}cacheResponse(e,t,s){return new Promise((r,n)=>{const a=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=i.get(a);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 n(d);(p.data.story||p.data.stories)&&await this.resolveStories(p.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(a,p),p.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=p.data.cv&&this.flushCache(),m[t.token]=p.data.cv),r(p)})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return b[e]},getAll(){return b},set(e,t){b[e]=t},flush(){b={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}flushCache(){return this.cacheProvider().flush(),this}}const ne=(o={})=>{const{apiOptions:e}=o;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 oe(e)}};var ie=o=>{if(typeof o!="object"||typeof o._editable=="undefined")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let T;const S="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,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(!o){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===o?e(r.story):(r.action==="change"||r.action==="published")&&r.storyId===o&&window.location.reload()})})}},ae=(o={})=>{const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={}}=o;r.accessToken=r.accessToken||t;const a={bridge:e,apiOptions:r};let i={};return s.forEach(l=>{i=f(f({},i),l(a))}),e!==!1&&_(S),T=new y(n.schema),n.resolver&&O(T,n.resolver),i},O=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},le=(o,e,t)=>{let s=t||T;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(e&&(s=new y(e.schema),e.resolver&&O(s,e.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 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:""};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]/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`),"")},ce=()=>_(S);h.RichTextResolver=y,h.RichTextSchema=$,h.apiPlugin=ne,h.loadStoryblokBridge=ce,h.registerStoryblokBridge=P,h.renderRichText=le,h.storyblokEditable=ie,h.storyblokInit=ae,h.useStoryblokBridge=P,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,125 +1,88 @@
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 R = (i, t, e) => t in i ? m(i, t, { enumerable: true, configurable: true, writable: true, value: e }) : i[t] = e;
53
- var l = (i, t, e) => (R(i, typeof t != "symbol" ? t + "" : t, e), e);
54
- function y(i) {
55
- return !(i !== i || i === 1 / 0 || i === -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 _(i, t, e) {
58
- if (!y(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 (!y(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;
64
- const c = function() {
65
- n++;
66
- const a = setTimeout(function() {
67
- n--, s.length > 0 && c(), r = r.filter(function(u) {
68
- return u !== a;
26
+ let r = [], o = 0;
27
+ const i = function() {
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(i.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, g) {
39
+ return new Promise(function(u, f) {
77
40
  s.push({
78
41
  resolve: u,
79
- reject: g,
80
- args: a,
42
+ reject: f,
43
+ args: c,
81
44
  self: h
82
- }), n < t && c();
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 b = function(i, t) {
94
- const e = {};
95
- for (const s in i) {
96
- const r = i[s];
97
- t.indexOf(s) > -1 && r !== null && (e[s] = r);
98
- }
99
- return e;
100
- }, $ = (i) => i === "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
- }), E = () => ({
65
+ }), P = () => ({
103
66
  tag: "blockquote"
104
- }), x = () => ({
67
+ }), C = () => ({
105
68
  tag: "ul"
106
- }), P = (i) => ({
69
+ }), I = (n) => ({
107
70
  tag: [
108
71
  "pre",
109
72
  {
110
73
  tag: "code",
111
- attrs: i.attrs
74
+ attrs: n.attrs
112
75
  }
113
76
  ]
114
- }), O = () => ({
77
+ }), A = () => ({
115
78
  singleTag: "br"
116
- }), S = (i) => ({
117
- tag: `h${i.attrs.level}`
118
- }), C = (i) => ({
79
+ }), N = (n) => ({
80
+ tag: `h${n.attrs.level}`
81
+ }), M = (n) => ({
119
82
  singleTag: [
120
83
  {
121
84
  tag: "img",
122
- attrs: b(i.attrs, ["src", "alt", "title"])
85
+ attrs: E(n.attrs, ["src", "alt", "title"])
123
86
  }
124
87
  ]
125
88
  }), L = () => ({
@@ -128,309 +91,305 @@ const b = function(i, t) {
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
- }), M = () => ({
98
+ }), D = () => ({
136
99
  tag: "u"
137
- }), N = () => ({
100
+ }), J = () => ({
138
101
  tag: "strong"
139
- }), q = () => ({
102
+ }), F = () => ({
140
103
  tag: "code"
141
- }), z = () => ({
104
+ }), V = () => ({
142
105
  tag: "i"
143
- }), F = (i) => {
144
- const t = __spreadValues({}, i.attrs), { linktype: e = "url" } = i.attrs;
145
- return $(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
- }, V = (i) => ({
116
+ }, Y = (n) => ({
154
117
  tag: [
155
118
  {
156
119
  tag: "span",
157
- attrs: i.attrs
120
+ attrs: n.attrs
158
121
  }
159
122
  ]
160
- }), j = {
123
+ }), K = {
161
124
  nodes: {
162
- horizontal_rule: w,
163
- blockquote: E,
164
- bullet_list: x,
165
- code_block: P,
166
- hard_break: O,
167
- heading: S,
168
- image: C,
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,
169
132
  list_item: L,
170
133
  ordered_list: U,
171
134
  paragraph: H
172
135
  },
173
136
  marks: {
174
- bold: A,
175
- strike: I,
176
- underline: M,
177
- strong: N,
178
- code: q,
179
- italic: z,
180
- link: F,
181
- styled: V
182
- }
183
- }, J = function(i) {
184
- const t = {
137
+ bold: B,
138
+ strike: q,
139
+ underline: D,
140
+ strong: J,
141
+ code: F,
142
+ italic: V,
143
+ link: z,
144
+ styled: Y
145
+ }
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 i && s.test(i) ? i.replace(e, (r) => t[r]) : i;
153
+ }, t = /[&<>"']/g, s = RegExp(t.source);
154
+ return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
192
155
  };
193
- class v {
194
- constructor(t) {
195
- l(this, "marks");
196
- l(this, "nodes");
197
- t || (t = j), 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(J(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 c in r.attrs) {
236
- const o = r.attrs[c];
237
- o !== null && (n += ` ${c}="${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
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, c) => c * 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 c = t[n], o = s ? "" : encodeURIComponent(n);
282
- let a;
283
- typeof c == "object" ? a = this.stringify(c, e ? e + encodeURIComponent("[" + o + "]") : o, Array.isArray(c)) : a = (e ? e + encodeURIComponent("[" + o + "]") : o) + "=" + encodeURIComponent(c), 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
- var f = /* @__PURE__ */ ((i) => (i.GET = "get", i.DELETE = "delete", i.POST = "post", i.PUT = "put", i))(f || {});
289
250
  class G {
290
- constructor(t) {
291
- l(this, "baseURL");
292
- l(this, "timeout");
293
- l(this, "headers");
294
- l(this, "responseInterceptor");
295
- l(this, "ejectInterceptor");
296
- l(this, "url");
297
- l(this, "parameters");
298
- this.baseURL = t.baseURL, this.timeout = t.timeout ? t.timeout * 1e3 : 1e3, this.headers = t.headers || [], this.responseInterceptor = t.responseInterceptor, this.ejectInterceptor = false, this.url = "", this.parameters = {};
299
- }
300
- get(t, e) {
301
- return this.url = t, this.parameters = e, this._methodHandler(f.GET);
302
- }
303
- post(t, e) {
304
- return this.url = t, this.parameters = e, this._methodHandler(f.POST);
305
- }
306
- put(t, e) {
307
- return this.url = t, this.parameters = e, this._methodHandler(f.PUT);
308
- }
309
- delete(t, e) {
310
- return this.url = t, this.parameters = e, this._methodHandler(f.DELETE);
311
- }
312
- async _responseHandler(t) {
313
- const e = [], s = {
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
+ 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 T();
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, c = 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 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(c);
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]/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
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}` : "", c = t.https === false ? "http" : "https";
377
- t.oauthToken ? e = `${c}://api${n}.storyblok.com/v1` : e = `${c}://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
- const s = Object.assign({}, t.headers);
325
+ const s = new Headers();
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]);
328
+ });
380
329
  let r = 5;
381
- t.oauthToken && (s.Authorization = t.oauthToken, r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new v(t.richTextSchema) : this.richTextResolver = new v(), 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 T(), this.resolveNestedRelations = false, this.client = new G({
382
- baseURL: e,
383
- 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,
384
333
  headers: s,
385
- responseInterceptor: t.responseInterceptor
334
+ responseInterceptor: e.responseInterceptor,
335
+ fetch: e.fetch
386
336
  });
387
337
  }
388
- setComponentResolver(t) {
389
- this.richTextResolver.addNode("blok", (e) => {
338
+ setComponentResolver(e) {
339
+ this.richTextResolver.addNode("blok", (t) => {
390
340
  let s = "";
391
- return e.attrs.body.forEach((r) => {
392
- s += t(r.component, r);
341
+ return t.attrs.body.forEach((r) => {
342
+ s += e(r.component, r);
393
343
  }), {
394
344
  html: s
395
345
  };
396
346
  });
397
347
  }
398
- parseParams(t) {
399
- 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;
400
350
  }
401
- factoryParamOptions(t, e) {
402
- return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
351
+ factoryParamOptions(e, t) {
352
+ return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
403
353
  }
404
- makeRequest(t, e, s, r) {
405
- const n = this.factoryParamOptions(t, this.helpers.getOptionsPage(e, s, r));
406
- 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);
407
360
  }
408
- get(t, e) {
409
- e || (e = {});
410
- const s = `/${t}`, r = this.factoryParamOptions(s, e);
361
+ get(e, t) {
362
+ t || (t = {});
363
+ const s = `/${e}`, r = this.factoryParamOptions(s, t);
411
364
  return this.cacheResponse(s, r);
412
365
  }
413
- async getAll(t, e, s) {
414
- const r = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, c = n.split("/"), o = s || c[c.length - 1], a = 1, h = await this.makeRequest(n, e, r, a), u = h.total ? Math.ceil(h.total / r) : 1, g = await this.helpers.asyncMap(this.helpers.range(a, u), (k) => this.makeRequest(n, e, r, k + 1));
415
- return this.helpers.flatMap([h, ...g], (k) => Object.values(k.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
+ );
416
375
  }
417
- post(t, e) {
418
- const s = `/${t}`;
419
- 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));
420
379
  }
421
- put(t, e) {
422
- const s = `/${t}`;
423
- 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));
424
383
  }
425
- delete(t, e) {
426
- const s = `/${t}`;
427
- 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));
428
387
  }
429
- getStories(t) {
430
- return this.get("cdn/stories", t);
388
+ getStories(e) {
389
+ return this.get("cdn/stories", e);
431
390
  }
432
- getStory(t, e) {
433
- return this.get(`cdn/stories/${t}`, e);
391
+ getStory(e, t) {
392
+ return this.get(`cdn/stories/${e}`, t);
434
393
  }
435
394
  getToken() {
436
395
  return this.accessToken;
@@ -438,123 +397,129 @@ class Q {
438
397
  ejectInterceptor() {
439
398
  this.client.eject();
440
399
  }
441
- _cleanCopy(t) {
442
- return JSON.parse(JSON.stringify(t));
400
+ _cleanCopy(e) {
401
+ return JSON.parse(JSON.stringify(e));
443
402
  }
444
- _insertLinks(t, e) {
445
- const s = t[e];
403
+ _insertLinks(e, t) {
404
+ const s = e[t];
446
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]));
447
406
  }
448
- _insertRelations(t, e, s) {
449
- if (s.indexOf(`${t.component}.${e}`) > -1) {
450
- if (typeof t[e] == "string")
451
- this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
452
- 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) {
453
412
  const r = [];
454
- t[e].forEach((n) => {
455
- this.relations[n] && r.push(this._cleanCopy(this.relations[n]));
456
- }), t[e] = r;
413
+ e[t].forEach((o) => {
414
+ this.relations[o] && r.push(this._cleanCopy(this.relations[o]));
415
+ }), e[t] = r;
457
416
  }
458
417
  }
459
418
  }
460
- iterateTree(t, e) {
419
+ iterateTree(e, t) {
461
420
  const s = (r) => {
462
421
  if (r != null) {
463
422
  if (r.constructor === Array)
464
- for (let n = 0; n < r.length; n++)
465
- s(r[n]);
423
+ for (let o = 0; o < r.length; o++)
424
+ s(r[o]);
466
425
  else if (r.constructor === Object) {
467
426
  if (r._stopResolving)
468
427
  return;
469
- for (const n in r)
470
- (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]);
471
434
  }
472
435
  }
473
436
  };
474
- s(t.content);
437
+ s(e.content);
475
438
  }
476
- async resolveLinks(t, e) {
439
+ async resolveLinks(e, t) {
477
440
  let s = [];
478
- if (t.link_uuids) {
479
- const r = t.link_uuids.length, n = [], c = 50;
480
- for (let o = 0; o < r; o += c) {
481
- const a = Math.min(r, o + c);
482
- 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));
483
446
  }
484
- for (let o = 0; o < n.length; o++)
447
+ for (let a = 0; a < o.length; a++)
485
448
  (await this.getStories({
486
- per_page: c,
487
- language: e.language,
488
- version: e.version,
489
- by_uuids: n[o].join(",")
490
- })).data.stories.forEach((h) => {
491
- s.push(h);
492
- });
449
+ per_page: i,
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
+ );
493
458
  } else
494
- s = t.links;
459
+ s = e.links;
495
460
  s.forEach((r) => {
496
- this.links[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
461
+ this.links[r.uuid] = { ...r, _stopResolving: !0 };
497
462
  });
498
463
  }
499
- async resolveRelations(t, e) {
464
+ async resolveRelations(e, t) {
500
465
  let s = [];
501
- if (t.rel_uuids) {
502
- const r = t.rel_uuids.length, n = [], c = 50;
503
- for (let o = 0; o < r; o += c) {
504
- const a = Math.min(r, o + c);
505
- 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));
506
471
  }
507
- for (let o = 0; o < n.length; o++)
472
+ for (let a = 0; a < o.length; a++)
508
473
  (await this.getStories({
509
- per_page: c,
510
- language: e.language,
511
- version: e.version,
512
- by_uuids: n[o].join(",")
513
- })).data.stories.forEach((h) => {
514
- s.push(h);
474
+ per_page: i,
475
+ language: t.language,
476
+ version: t.version,
477
+ by_uuids: o[a].join(",")
478
+ })).data.stories.forEach((c) => {
479
+ s.push(c);
515
480
  });
516
481
  } else
517
- s = t.rels;
482
+ s = e.rels;
518
483
  s && s.length > 0 && s.forEach((r) => {
519
- this.relations[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
484
+ this.relations[r.uuid] = { ...r, _stopResolving: !0 };
520
485
  });
521
486
  }
522
- async resolveStories(t, e) {
523
- var r, n;
524
- let s = [];
525
- if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (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)
526
- for (const c in this.relations)
527
- this.iterateTree(this.relations[c], s);
528
- t.story ? this.iterateTree(t.story, s) : t.stories.forEach((c) => {
529
- this.iterateTree(c, s);
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)
491
+ for (const i in this.relations)
492
+ this.iterateTree(this.relations[i], o);
493
+ e.story ? this.iterateTree(e.story, o) : e.stories.forEach((i) => {
494
+ this.iterateTree(i, o);
530
495
  });
531
496
  }
532
- cacheResponse(t, e, s) {
533
- return new Promise((r, n) => {
534
- const c = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
535
- if (this.cache.clear === "auto" && e.version === "draft" && this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
536
- const a = o.get(c);
537
- if (a)
538
- 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);
539
504
  }
540
505
  try {
541
506
  (async () => {
542
- var u;
543
- const a = await this.throttle("get", t, e);
544
- let h = { data: a.data, headers: a.headers };
545
- if ((u = a.headers) != null && u["per-page"] && (h = Object.assign({}, h, {
546
- perPage: a.headers["per-page"] ? parseInt(a.headers["per-page"]) : 0,
547
- total: a.headers["per-page"] ? parseInt(a.headers.total) : 0
548
- })), a.status != 200)
549
- return n(a);
550
- (h.data.story || h.data.stories) && await this.resolveStories(h.data, e), e.version === "published" && t != "/cdn/spaces/me" && o.set(c, 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);
551
516
  })();
552
517
  } catch {
553
518
  }
554
519
  });
555
520
  }
556
- throttledRequest(t, e, s) {
557
- return this.client[t](e, s);
521
+ throttledRequest(e, t, s) {
522
+ return this.client[e](t, s);
558
523
  }
559
524
  cacheVersions() {
560
525
  return d;
@@ -562,21 +527,21 @@ class Q {
562
527
  cacheVersion() {
563
528
  return d[this.accessToken];
564
529
  }
565
- setCacheVersion(t) {
566
- this.accessToken && (d[this.accessToken] = t);
530
+ setCacheVersion(e) {
531
+ this.accessToken && (d[this.accessToken] = e);
567
532
  }
568
533
  cacheProvider() {
569
534
  switch (this.cache.type) {
570
535
  case "memory":
571
536
  return {
572
- get(t) {
573
- return p[t];
537
+ get(e) {
538
+ return p[e];
574
539
  },
575
540
  getAll() {
576
541
  return p;
577
542
  },
578
- set(t, e) {
579
- p[t] = e;
543
+ set(e, t) {
544
+ p[e] = t;
580
545
  },
581
546
  flush() {
582
547
  p = {};
@@ -599,105 +564,88 @@ class Q {
599
564
  return this.cacheProvider().flush(), this;
600
565
  }
601
566
  }
602
- const apiFactory = (options = {}) => {
603
- const { apiOptions } = options;
604
- if (!apiOptions.accessToken) {
605
- 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
+ );
606
573
  return;
607
574
  }
608
- const storyblokApi = new Q(apiOptions);
609
- return { storyblokApi };
610
- };
611
- var editable = (blok) => {
612
- 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")
613
578
  return {};
614
- }
615
- const options = JSON.parse(blok._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
579
+ const e = JSON.parse(
580
+ n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
581
+ );
616
582
  return {
617
- "data-blok-c": JSON.stringify(options),
618
- "data-blok-uid": options.id + "-" + options.uid
583
+ "data-blok-c": JSON.stringify(e),
584
+ "data-blok-uid": e.id + "-" + e.uid
619
585
  };
620
586
  };
621
- let richTextResolver;
622
- const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
623
- const useStoryblokBridge = (id, cb, options = {}) => {
624
- if (typeof window === "undefined") {
625
- return;
626
- }
627
- if (typeof window.storyblokRegisterEvent === "undefined") {
628
- console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
629
- return;
630
- }
631
- if (!id) {
632
- console.warn("Story ID is not defined. Please provide a valid ID.");
633
- return;
634
- }
635
- window.storyblokRegisterEvent(() => {
636
- const sbBridge = new window.StoryblokBridge(options);
637
- sbBridge.on(["input", "published", "change"], (event) => {
638
- if (event.action === "input" && event.story.id === id) {
639
- cb(event.story);
640
- } else if ((event.action === "change" || event.action === "published") && event.storyId === id) {
641
- window.location.reload();
642
- }
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
+ });
643
604
  });
644
- });
645
- };
646
- const storyblokInit = (pluginOptions = {}) => {
647
- const {
648
- bridge,
649
- accessToken,
650
- use = [],
651
- apiOptions = {},
652
- richText = {}
653
- } = pluginOptions;
654
- apiOptions.accessToken = apiOptions.accessToken || accessToken;
655
- const options = { bridge, apiOptions };
656
- let result = {};
657
- use.forEach((pluginFactory) => {
658
- result = __spreadValues(__spreadValues({}, result), pluginFactory(options));
659
- });
660
- if (bridge !== false) {
661
- loadBridge(bridgeLatest);
662
- }
663
- richTextResolver = new v(richText.schema);
664
- if (richText.resolver) {
665
- setComponentResolver(richTextResolver, richText.resolver);
666
605
  }
667
- return result;
668
- };
669
- const setComponentResolver = (resolver, resolveFn) => {
670
- resolver.addNode("blok", (node) => {
671
- let html = "";
672
- node.attrs.body.forEach((blok) => {
673
- html += resolveFn(blok.component, blok);
674
- });
675
- return {
676
- 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
677
627
  };
678
628
  });
679
- };
680
- const renderRichText = (data, options, resolverInstance) => {
681
- let localResolver = resolverInstance || richTextResolver;
682
- if (!localResolver) {
683
- 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
+ );
684
635
  return;
685
636
  }
686
- if (data === "") {
687
- return "";
688
- } else if (!data) {
689
- 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.
690
638
 
691
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
692
- return "";
693
- }
694
- if (options) {
695
- localResolver = new v(options.schema);
696
- if (options.resolver) {
697
- setComponentResolver(localResolver, options.resolver);
698
- }
699
- }
700
- 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
701
651
  };
702
- const loadStoryblokBridge = () => loadBridge(bridgeLatest);
703
- export { v as RichTextResolver, j 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.5",
3
+ "version": "2.0.7",
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.1.6"
30
+ "storyblok-js-client": "^5.3.0"
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.25.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": [