@storyblok/react 2.0.9 → 2.0.11

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(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u(l.storyblokReact={},l.React))})(this,function(l,u){"use strict";var Tt=Object.defineProperty,_t=Object.defineProperties;var Rt=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(l,u,p)=>u in l?Tt(l,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[u]=p,y=(l,u)=>{for(var p in u||(u={}))U.call(u,p)&&L(l,p,u[p]);if(T)for(var p of T(u))H.call(u,p)&&L(l,p,u[p]);return l},_=(l,u)=>_t(l,Rt(u));var q=(l,u)=>{var p={};for(var g in l)U.call(l,g)&&u.indexOf(g)<0&&(p[g]=l[g]);if(l!=null&&T)for(var g of T(l))u.indexOf(g)<0&&H.call(l,g)&&(p[g]=l[g]);return p};function p(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var g=p(u);let j=!1;const C=[],B=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}j?r():C.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=>{C.forEach(n=>n()),j=!0,t(r)},document.getElementsByTagName("head")[0].appendChild(s)});var D=Object.defineProperty,J=(o,t,e)=>t in o?D(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,h=(o,t,e)=>(J(o,typeof t!="symbol"?t+"":t,e),e);function P(o){return!(o!==o||o===1/0||o===-1/0)}function V(o,t,e){if(!P(t))throw new TypeError("Expected `limit` to be a finite number");if(!P(e))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const c=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(f){return f!==c})},e);r.indexOf(c)<0&&r.push(c);const d=s.shift();d.resolve(o.apply(d.self,d.args))},a=function(...c){const d=this;return new Promise(function(f,E){s.push({resolve:f,reject:E,args:c,self:d}),n<t&&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 Y=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},z=o=>o==="email",F=()=>({singleTag:"hr"}),G=()=>({tag:"blockquote"}),Q=()=>({tag:"ul"}),W=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),X=()=>({singleTag:"br"}),Z=o=>({tag:`h${o.attrs.level}`}),K=o=>({singleTag:[{tag:"img",attrs:Y(o.attrs,["src","alt","title"])}]}),tt=()=>({tag:"li"}),et=()=>({tag:"ol"}),st=()=>({tag:"p"}),rt=()=>({tag:"b"}),ot=()=>({tag:"strike"}),nt=()=>({tag:"u"}),it=()=>({tag:"strong"}),at=()=>({tag:"code"}),lt=()=>({tag:"i"}),ct=o=>{const t=y({},o.attrs),{linktype:e="url"}=o.attrs;return z(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},ht=o=>({tag:[{tag:"span",attrs:o.attrs}]}),O={nodes:{horizontal_rule:F,blockquote:G,bullet_list:Q,code_block:W,hard_break:X,heading:Z,image:K,list_item:tt,ordered_list:et,paragraph:st},marks:{bold:rt,strike:ot,underline:nt,strong:it,code:at,italic:lt,link:ct,styled:ht}},ut=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 k{constructor(t){h(this,"marks"),h(this,"nodes"),t||(t=O),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(ut(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 I{constructor(){h(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(t,e=25,s=1)=>_(y({},t),{per_page:e,page:s})),h(this,"delay",t=>new Promise(e=>setTimeout(e,t))),h(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),h(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)}),h(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),h(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 c;typeof i=="object"?c=this.stringify(i,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):c=(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(c)}return r.join("&")}}class dt{constructor(t){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(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=y({},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 I;e=`${this.baseURL}${this.url}?${c.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 c=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const d=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(d)):this._statusHandler(d)}catch(c){return 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};r(n)})}}let v={};const m={};class pt{constructor(t,e){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(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 k(t.richTextSchema):this.richTextResolver=new k,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries,this.throttle=V(this.throttledRequest,r,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new I,this.resolveNestedRelations=!1,this.client=new dt({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=m[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],c=1,d=await this.makeRequest(n,e,r,c),f=d.total?Math.ceil(d.total/r):1,E=await this.helpers.asyncMap(this.helpers.range(c,f),$=>this.makeRequest(n,e,r,$+1));return this.helpers.flatMap([d,...E],$=>Object.values($.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 c=Math.min(r,a+i);n.push(t.link_uuids.slice(a,c))}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(c=>{s.push(c)})}else s=t.links;s.forEach(r=>{this.links[r.uuid]=_(y({},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 c=Math.min(r,a+i);n.push(t.rel_uuids.slice(a,c))}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(c=>{s.push(c)})}else s=t.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=_(y({},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)})}cacheResponse(t,e,s){return new Promise((r,n)=>{const i=this.helpers.stringify({url:t,params:e}),a=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const c=a.get(i);if(c)return r(c)}try{(async()=>{var c;const d=await this.throttle("get",t,e);let f={data:d.data,headers:d.headers};if((c=d.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{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);(f.data.story||f.data.stories)&&await this.resolveStories(f.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,f),f.data.cv&&e.token&&(e.version=="draft"&&m[e.token]!=f.data.cv&&this.flushCache(),m[e.token]=f.data.cv),r(f)})()}catch{}})}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(t){this.accessToken&&(m[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return v[t]},getAll(){return v},set(t,e){v[t]=e},flush(){v={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}flushCache(){return this.cacheProvider().flush(),this}}const ft=(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 pt(t)}},gt=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 R;const yt="https://app.storyblok.com/f/storyblok-v2-latest.js",w=(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"],s=>{s.action==="input"&&s.story.id===o?t(s.story):(s.action==="change"||s.action==="published")&&s.storyId===o&&window.location.reload()})})}},mt=(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(c=>{a=y(y({},a),c(i))}),t!==!1&&B(yt),R=new k(n.schema),n.resolver&&A(R,n.resolver),a},A=(o,t)=>{o.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})},kt=(o,t,e)=>{let s=e||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(t&&(s=new k(t.schema),t.resolver&&A(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(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u(l.storyblokReact={},l.React))})(this,function(l,u){"use strict";var Te=Object.defineProperty,_e=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(l,u,p)=>u in l?Te(l,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[u]=p,y=(l,u)=>{for(var p in u||(u={}))U.call(u,p)&&L(l,p,u[p]);if(T)for(var p of T(u))H.call(u,p)&&L(l,p,u[p]);return l},_=(l,u)=>_e(l,Re(u));var q=(l,u)=>{var p={};for(var g in l)U.call(l,g)&&u.indexOf(g)<0&&(p[g]=l[g]);if(l!=null&&T)for(var g of T(l))u.indexOf(g)<0&&H.call(l,g)&&(p[g]=l[g]);return p};function p(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var g=p(u);let $=!1;const j=[],B=o=>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}$?r():j.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=>{j.forEach(n=>n()),$=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var D=Object.defineProperty,J=(o,e,t)=>e in o?D(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(J(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function V(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const c=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(f){return f!==c})},t);r.indexOf(c)<0&&r.push(c);const d=s.shift();d.resolve(o.apply(d.self,d.args))},a=function(...c){const d=this;return new Promise(function(f,E){s.push({resolve:f,reject:E,args:c,self:d}),n<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 Y=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},z=o=>o==="email",F=()=>({singleTag:"hr"}),G=()=>({tag:"blockquote"}),Q=()=>({tag:"ul"}),W=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),X=()=>({singleTag:"br"}),Z=o=>({tag:`h${o.attrs.level}`}),K=o=>({singleTag:[{tag:"img",attrs:Y(o.attrs,["src","alt","title"])}]}),ee=()=>({tag:"li"}),te=()=>({tag:"ol"}),se=()=>({tag:"p"}),re=()=>({tag:"b"}),oe=()=>({tag:"strike"}),ne=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ae=()=>({tag:"code"}),le=()=>({tag:"i"}),ce=o=>{const e=y({},o.attrs),{linktype:t="url"}=o.attrs;return z(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},he=o=>({tag:[{tag:"span",attrs:o.attrs}]}),O={nodes:{horizontal_rule:F,blockquote:G,bullet_list:Q,code_block:W,hard_break:X,heading:Z,image:K,list_item:ee,ordered_list:te,paragraph:se},marks:{bold:re,strike:oe,underline:ne,strong:ie,code:ae,italic:le,link:ce,styled:he}},ue=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 k{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=O),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(ue(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 i=s.attrs[n];i!==null&&(r+=` ${n}="${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 I{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>_(y({},e),{per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(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 i=e[n],a=s?"":encodeURIComponent(n);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 de{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers=y({},t),s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const c=new I;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const d=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(d)):this._statusHandler(d)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const n={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(n)})}}let v={};const m={};class pe{constructor(e,t){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),!t){const n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${n}.storyblok.com/v1`:t=`${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)=>{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 k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=V(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new I,this.resolveNestedRelations=!1,this.client=new de({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=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}`,i=n.split("/"),a=s||i[i.length-1],c=1,d=await this.makeRequest(n,t,r,c),f=d.total?Math.ceil(d.total/r):1,E=await this.helpers.asyncMap(this.helpers.range(c,f),P=>this.makeRequest(n,t,r,P+1));return this.helpers.flatMap([d,...E],P=>Object.values(P.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(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=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]=_(y({},r),{_stopResolving:!0})})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=_(y({},r),{_stopResolving:!0})})}async resolveStories(e,t){var s,r;let n=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(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&&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],n);e.story?this.iterateTree(e.story,n):e.stories.forEach(i=>{this.iterateTree(i,n)})}async cacheResponse(e,t,s){const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var c;const d=await this.throttle("get",e,t);let f={data:d.data,headers:d.headers};if((c=d.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{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 a(d);(f.data.story||f.data.stories)&&await this.resolveStories(f.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,f),f.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=f.data.cv&&await this.flushCache(),m[t.token]=f.data.cv),i(f)})()}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 Promise.resolve(v[e])},getAll(){return Promise.resolve(v)},set(e,t){return v[e]=t,Promise.resolve(void 0)},flush(){return v={},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 fe=(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 pe(e)}},ge=o=>{if(typeof o!="object"||typeof o._editable>"u")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 R;const ye="https://app.storyblok.com/f/storyblok-v2-latest.js",w=(o,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(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.action==="input"&&s.story.id===o?e(s.story):(s.action==="change"||s.action==="published")&&s.storyId===o&&window.location.reload()})})}},me=(o={})=>{const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={}}=o;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let a={};return s.forEach(c=>{a=y(y({},a),c(i))}),e!==!1&&B(ye),R=new k(n.schema),n.resolver&&A(R,n.resolver),a},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=(o,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(e&&(s=new k(e.schema),e.resolver&&A(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.
2
2
 
3
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},x=u.forwardRef((s,e)=>{var r=s,{blok:o}=r,t=q(r,["blok"]);if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),g.default.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=N(o.component);return n?g.default.createElement(n,y({ref:e,blok:o},t)):g.default.createElement("div",null)});x.displayName="StoryblokComponent";const bt=(o,t={},e={})=>{let[s,r]=u.useState({});if(!b)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;const n=typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined";return u.useEffect(()=>{async function i(){const{data:a}=await b.get(`cdn/stories/${o}`,t);r(a.story),n&&a.story.id&&w(a.story.id,c=>r(c),e)}i()},[o]),s},vt=(o=null,t={})=>{let[e,s]=u.useState(o);return!(typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined")||!o?o:(u.useEffect(()=>{s(o),w(e.id,n=>s(n),t)},[o]),e)};let b=null;const M=()=>(b||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),b);let S={};const N=o=>S[o]?S[o]:(console.error(`Component ${o} doesn't exist.`),!1),wt=(o={})=>{const{storyblokApi:t}=mt(o);b=t,S=o.components};l.RichTextResolver=k,l.RichTextSchema=O,l.StoryblokComponent=x,l.apiPlugin=ft,l.getComponent=N,l.getStoryblokApi=M,l.registerStoryblokBridge=w,l.renderRichText=kt,l.storyblokEditable=gt,l.storyblokInit=wt,l.useStoryblok=bt,l.useStoryblokApi=M,l.useStoryblokBridge=w,l.useStoryblokState=vt,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
3
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},x=u.forwardRef((s,t)=>{var r=s,{blok:o}=r,e=q(r,["blok"]);if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),g.default.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=N(o.component);return n?g.default.createElement(n,y({ref:t,blok:o},e)):g.default.createElement("div",null)});x.displayName="StoryblokComponent";const be=(o,e={},t={})=>{let[s,r]=u.useState({});if(!b)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;const n=typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined";return u.useEffect(()=>{async function i(){const{data:a}=await b.get(`cdn/stories/${o}`,e);r(a.story),n&&a.story.id&&w(a.story.id,c=>r(c),t)}i()},[o]),s},ve=(o=null,e={})=>{let[t,s]=u.useState(o);return!(typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined")||!o?o:(u.useEffect(()=>{s(o),w(t.id,n=>s(n),e)},[o]),t)};let b=null;const M=()=>(b||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),b);let S={};const N=o=>S[o]?S[o]:(console.error(`Component ${o} doesn't exist.`),!1),we=(o={})=>{const{storyblokApi:e}=me(o);b=e,S=o.components};l.RichTextResolver=k,l.RichTextSchema=O,l.StoryblokComponent=x,l.apiPlugin=fe,l.getComponent=N,l.getStoryblokApi=M,l.registerStoryblokBridge=w,l.renderRichText=ke,l.storyblokEditable=ge,l.storyblokInit=we,l.useStoryblok=be,l.useStoryblokApi=M,l.useStoryblokBridge=w,l.useStoryblokState=ve,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -31,28 +31,28 @@ var __objRest = (source, exclude) => {
31
31
  };
32
32
  import React, { forwardRef, useState, useEffect } from "react";
33
33
  let k = false;
34
- const b = [], w = (n) => new Promise((e, t) => {
34
+ const v = [], w = (n) => new Promise((t, e) => {
35
35
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
36
36
  if (window.location === window.parent.location) {
37
37
  console.warn("You are not in Draft Mode or in the Visual Editor.");
38
38
  return;
39
39
  }
40
- k ? r() : b.push(r);
40
+ k ? r() : v.push(r);
41
41
  }, document.getElementById("storyblok-javascript-bridge")))
42
42
  return;
43
43
  const s = document.createElement("script");
44
- s.async = true, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
45
- b.forEach((o) => o()), k = true, e(r);
44
+ s.async = true, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
45
+ v.forEach((o) => o()), k = true, t(r);
46
46
  }, document.getElementsByTagName("head")[0].appendChild(s);
47
47
  });
48
- var $ = Object.defineProperty, j = (n, e, t) => e in n ? $(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t, c = (n, e, t) => (j(n, typeof e != "symbol" ? e + "" : e, t), t);
49
- function v(n) {
48
+ var $ = Object.defineProperty, P = (n, t, e) => t in n ? $(n, t, { enumerable: true, configurable: true, writable: true, value: e }) : n[t] = e, c = (n, t, e) => (P(n, typeof t != "symbol" ? t + "" : t, e), e);
49
+ function b(n) {
50
50
  return !(n !== n || n === 1 / 0 || n === -1 / 0);
51
51
  }
52
- function x(n, e, t) {
53
- if (!v(e))
52
+ function j(n, t, e) {
53
+ if (!b(t))
54
54
  throw new TypeError("Expected `limit` to be a finite number");
55
- if (!v(t))
55
+ if (!b(e))
56
56
  throw new TypeError("Expected `interval` to be a finite number");
57
57
  const s = [];
58
58
  let r = [], o = 0;
@@ -62,7 +62,7 @@ function x(n, e, t) {
62
62
  o--, s.length > 0 && i(), r = r.filter(function(u) {
63
63
  return u !== l;
64
64
  });
65
- }, t);
65
+ }, e);
66
66
  r.indexOf(l) < 0 && r.push(l);
67
67
  const h = s.shift();
68
68
  h.resolve(n.apply(h.self, h.args));
@@ -74,7 +74,7 @@ function x(n, e, t) {
74
74
  reject: f,
75
75
  args: l,
76
76
  self: h
77
- }), o < e && i();
77
+ }), o < t && i();
78
78
  });
79
79
  };
80
80
  return a.abort = function() {
@@ -85,14 +85,14 @@ function x(n, e, t) {
85
85
  }), s.length = 0;
86
86
  }, a;
87
87
  }
88
- const E = function(n, e) {
89
- const t = {};
88
+ const x = function(n, t) {
89
+ const e = {};
90
90
  for (const s in n) {
91
91
  const r = n[s];
92
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
92
+ t.indexOf(s) > -1 && r !== null && (e[s] = r);
93
93
  }
94
- return t;
95
- }, P = (n) => n === "email", S = () => ({
94
+ return e;
95
+ }, E = (n) => n === "email", S = () => ({
96
96
  singleTag: "hr"
97
97
  }), O = () => ({
98
98
  tag: "blockquote"
@@ -114,7 +114,7 @@ const E = function(n, e) {
114
114
  singleTag: [
115
115
  {
116
116
  tag: "img",
117
- attrs: E(n.attrs, ["src", "alt", "title"])
117
+ attrs: x(n.attrs, ["src", "alt", "title"])
118
118
  }
119
119
  ]
120
120
  }), L = () => ({
@@ -136,12 +136,12 @@ const E = function(n, e) {
136
136
  }), V = () => ({
137
137
  tag: "i"
138
138
  }), z = (n) => {
139
- const e = __spreadValues({}, n.attrs), { linktype: t = "url" } = n.attrs;
140
- return P(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
139
+ const t = __spreadValues({}, n.attrs), { linktype: e = "url" } = n.attrs;
140
+ return E(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
141
141
  tag: [
142
142
  {
143
143
  tag: "a",
144
- attrs: e
144
+ attrs: t
145
145
  }
146
146
  ]
147
147
  };
@@ -176,52 +176,52 @@ const E = function(n, e) {
176
176
  styled: Y
177
177
  }
178
178
  }, Q = function(n) {
179
- const e = {
179
+ const t = {
180
180
  "&": "&amp;",
181
181
  "<": "&lt;",
182
182
  ">": "&gt;",
183
183
  '"': "&quot;",
184
184
  "'": "&#39;"
185
- }, t = /[&<>"']/g, s = RegExp(t.source);
186
- return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
185
+ }, e = /[&<>"']/g, s = RegExp(e.source);
186
+ return n && s.test(n) ? n.replace(e, (r) => t[r]) : n;
187
187
  };
188
188
  class g {
189
- constructor(e) {
190
- c(this, "marks"), c(this, "nodes"), e || (e = K), this.marks = e.marks || [], this.nodes = e.nodes || [];
189
+ constructor(t) {
190
+ c(this, "marks"), c(this, "nodes"), t || (t = K), this.marks = t.marks || [], this.nodes = t.nodes || [];
191
191
  }
192
- addNode(e, t) {
193
- this.nodes[e] = t;
192
+ addNode(t, e) {
193
+ this.nodes[t] = e;
194
194
  }
195
- addMark(e, t) {
196
- this.marks[e] = t;
195
+ addMark(t, e) {
196
+ this.marks[t] = e;
197
197
  }
198
- render(e) {
199
- if (e && e.content && Array.isArray(e.content)) {
200
- let t = "";
201
- return e.content.forEach((s) => {
202
- t += this.renderNode(s);
203
- }), t;
198
+ render(t) {
199
+ if (t && t.content && Array.isArray(t.content)) {
200
+ let e = "";
201
+ return t.content.forEach((s) => {
202
+ e += this.renderNode(s);
203
+ }), e;
204
204
  }
205
205
  return console.warn("The render method must receive an object with a content field, which is an array"), "";
206
206
  }
207
- renderNode(e) {
208
- const t = [];
209
- e.marks && e.marks.forEach((r) => {
207
+ renderNode(t) {
208
+ const e = [];
209
+ t.marks && t.marks.forEach((r) => {
210
210
  const o = this.getMatchingMark(r);
211
- o && t.push(this.renderOpeningTag(o.tag));
211
+ o && e.push(this.renderOpeningTag(o.tag));
212
212
  });
213
- const s = this.getMatchingNode(e);
214
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
215
- t.push(this.renderNode(r));
216
- }) : 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) => {
213
+ const s = this.getMatchingNode(t);
214
+ return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
215
+ e.push(this.renderNode(r));
216
+ }) : 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) => {
217
217
  const o = this.getMatchingMark(r);
218
- o && t.push(this.renderClosingTag(o.tag));
219
- }), t.join("");
218
+ o && e.push(this.renderClosingTag(o.tag));
219
+ }), e.join("");
220
220
  }
221
- renderTag(e, t) {
222
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
221
+ renderTag(t, e) {
222
+ return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
223
223
  if (s.constructor === String)
224
- return `<${s}${t}>`;
224
+ return `<${s}${e}>`;
225
225
  {
226
226
  let r = `<${s.tag}`;
227
227
  if (s.attrs)
@@ -229,92 +229,92 @@ class g {
229
229
  const i = s.attrs[o];
230
230
  i !== null && (r += ` ${o}="${i}"`);
231
231
  }
232
- return `${r}${t}>`;
232
+ return `${r}${e}>`;
233
233
  }
234
234
  }).join("");
235
235
  }
236
- renderOpeningTag(e) {
237
- return this.renderTag(e, "");
236
+ renderOpeningTag(t) {
237
+ return this.renderTag(t, "");
238
238
  }
239
- renderClosingTag(e) {
240
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
239
+ renderClosingTag(t) {
240
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
241
241
  }
242
- getMatchingNode(e) {
243
- const t = this.nodes[e.type];
244
- if (typeof t == "function")
245
- return t(e);
242
+ getMatchingNode(t) {
243
+ const e = this.nodes[t.type];
244
+ if (typeof e == "function")
245
+ return e(t);
246
246
  }
247
- getMatchingMark(e) {
248
- const t = this.marks[e.type];
249
- if (typeof t == "function")
250
- return t(e);
247
+ getMatchingMark(t) {
248
+ const e = this.marks[t.type];
249
+ if (typeof e == "function")
250
+ return e(t);
251
251
  }
252
252
  }
253
253
  class T {
254
254
  constructor() {
255
- c(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), c(this, "getOptionsPage", (e, t = 25, s = 1) => __spreadProps(__spreadValues({}, e), {
256
- per_page: t,
255
+ c(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), c(this, "getOptionsPage", (t, e = 25, s = 1) => __spreadProps(__spreadValues({}, t), {
256
+ per_page: e,
257
257
  page: s
258
- })), 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) => {
259
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
260
- return this.arrayFrom(s, (o, i) => i * r + e);
261
- }), c(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), c(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
258
+ })), 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) => {
259
+ const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
260
+ return this.arrayFrom(s, (o, i) => i * r + t);
261
+ }), c(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), c(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
262
262
  }
263
- stringify(e, t, s) {
263
+ stringify(t, e, s) {
264
264
  const r = [];
265
- for (const o in e) {
266
- if (!Object.prototype.hasOwnProperty.call(e, o))
265
+ for (const o in t) {
266
+ if (!Object.prototype.hasOwnProperty.call(t, o))
267
267
  continue;
268
- const i = e[o], a = s ? "" : encodeURIComponent(o);
268
+ const i = t[o], a = s ? "" : encodeURIComponent(o);
269
269
  let l;
270
- typeof i == "object" ? l = this.stringify(i, t ? t + encodeURIComponent("[" + a + "]") : a, Array.isArray(i)) : l = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), r.push(l);
270
+ 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);
271
271
  }
272
272
  return r.join("&");
273
273
  }
274
274
  }
275
275
  class G {
276
- constructor(e) {
277
- c(this, "baseURL"), c(this, "timeout"), c(this, "headers"), c(this, "responseInterceptor"), c(this, "fetch"), c(this, "ejectInterceptor"), c(this, "url"), c(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || [], this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = false, this.url = "", this.parameters = {};
276
+ constructor(t) {
277
+ 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 = false, this.url = "", this.parameters = {};
278
278
  }
279
- get(e, t) {
280
- return this.url = e, this.parameters = t, this._methodHandler("get");
279
+ get(t, e) {
280
+ return this.url = t, this.parameters = e, this._methodHandler("get");
281
281
  }
282
- post(e, t) {
283
- return this.url = e, this.parameters = t, this._methodHandler("post");
282
+ post(t, e) {
283
+ return this.url = t, this.parameters = e, this._methodHandler("post");
284
284
  }
285
- put(e, t) {
286
- return this.url = e, this.parameters = t, this._methodHandler("put");
285
+ put(t, e) {
286
+ return this.url = t, this.parameters = e, this._methodHandler("put");
287
287
  }
288
- delete(e, t) {
289
- return this.url = e, this.parameters = t, this._methodHandler("delete");
288
+ delete(t, e) {
289
+ return this.url = t, this.parameters = e, this._methodHandler("delete");
290
290
  }
291
- async _responseHandler(e) {
292
- const t = [], s = {
291
+ async _responseHandler(t) {
292
+ const e = [], s = {
293
293
  data: {},
294
294
  headers: {},
295
295
  status: 0,
296
296
  statusText: ""
297
297
  };
298
- e.status !== 204 && await e.json().then((r) => {
298
+ t.status !== 204 && await t.json().then((r) => {
299
299
  s.data = r;
300
300
  });
301
- for (const r of e.headers.entries())
302
- t[r[0]] = r[1];
303
- return s.headers = __spreadValues({}, t), s.status = e.status, s.statusText = e.statusText, s;
301
+ for (const r of t.headers.entries())
302
+ e[r[0]] = r[1];
303
+ return s.headers = __spreadValues({}, e), s.status = t.status, s.statusText = t.statusText, s;
304
304
  }
305
- async _methodHandler(e) {
306
- let t = `${this.baseURL}${this.url}`, s = null;
307
- if (e === "get") {
305
+ async _methodHandler(t) {
306
+ let e = `${this.baseURL}${this.url}`, s = null;
307
+ if (t === "get") {
308
308
  const l = new T();
309
- t = `${this.baseURL}${this.url}?${l.stringify(this.parameters)}`;
309
+ e = `${this.baseURL}${this.url}?${l.stringify(this.parameters)}`;
310
310
  } else
311
311
  s = JSON.stringify(this.parameters);
312
- const r = new URL(t), o = new AbortController(), { signal: i } = o;
312
+ const r = new URL(e), o = new AbortController(), { signal: i } = o;
313
313
  let a;
314
314
  this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
315
315
  try {
316
316
  const l = await this.fetch(`${r}`, {
317
- method: e,
317
+ method: t,
318
318
  headers: this.headers,
319
319
  body: s,
320
320
  signal: i
@@ -323,20 +323,23 @@ class G {
323
323
  const h = await this._responseHandler(l);
324
324
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
325
325
  } catch (l) {
326
- return l;
326
+ return {
327
+ message: l
328
+ };
327
329
  }
328
330
  }
329
331
  eject() {
330
332
  this.ejectInterceptor = true;
331
333
  }
332
- _statusHandler(e) {
333
- const t = /20[0-6]/g;
334
+ _statusHandler(t) {
335
+ const e = /20[0-6]/g;
334
336
  return new Promise((s, r) => {
335
- if (t.test(`${e.status}`))
336
- return s(e);
337
+ if (e.test(`${t.status}`))
338
+ return s(t);
337
339
  const o = {
338
- message: new Error(e.statusText || `status: ${e.status}`),
339
- response: e
340
+ message: new Error(t.statusText),
341
+ status: t.status,
342
+ response: t.data.error || t.data.slug
340
343
  };
341
344
  r(o);
342
345
  });
@@ -345,70 +348,70 @@ class G {
345
348
  let p = {};
346
349
  const d = {};
347
350
  class W {
348
- constructor(e, t) {
349
- 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) {
350
- const o = e.region ? `-${e.region}` : "", i = e.https === false ? "http" : "https";
351
- e.oauthToken ? t = `${i}://api${o}.storyblok.com/v1` : t = `${i}://api${o}.storyblok.com/v2`;
351
+ constructor(t, e) {
352
+ 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) {
353
+ const o = t.region ? `-${t.region}` : "", i = t.https === false ? "http" : "https";
354
+ t.oauthToken ? e = `${i}://api${o}.storyblok.com/v1` : e = `${i}://api${o}.storyblok.com/v2`;
352
355
  }
353
356
  const s = new Headers();
354
357
  s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((o, i) => {
355
- e.headers && e.headers[i] && s.set(i, e.headers[i]);
358
+ t.headers && t.headers[i] && s.set(i, t.headers[i]);
356
359
  });
357
360
  let r = 5;
358
- 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 = false, this.client = new G({
359
- baseURL: t,
360
- timeout: e.timeout || 0,
361
+ 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 = false, this.client = new G({
362
+ baseURL: e,
363
+ timeout: t.timeout || 0,
361
364
  headers: s,
362
- responseInterceptor: e.responseInterceptor,
363
- fetch: e.fetch
365
+ responseInterceptor: t.responseInterceptor,
366
+ fetch: t.fetch
364
367
  });
365
368
  }
366
- setComponentResolver(e) {
367
- this.richTextResolver.addNode("blok", (t) => {
369
+ setComponentResolver(t) {
370
+ this.richTextResolver.addNode("blok", (e) => {
368
371
  let s = "";
369
- return t.attrs.body.forEach((r) => {
370
- s += e(r.component, r);
372
+ return e.attrs.body.forEach((r) => {
373
+ s += t(r.component, r);
371
374
  }), {
372
375
  html: s
373
376
  };
374
377
  });
375
378
  }
376
- parseParams(e) {
377
- 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;
379
+ parseParams(t) {
380
+ 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;
378
381
  }
379
- factoryParamOptions(e, t) {
380
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
382
+ factoryParamOptions(t, e) {
383
+ return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
381
384
  }
382
- makeRequest(e, t, s, r) {
383
- const o = this.factoryParamOptions(e, this.helpers.getOptionsPage(t, s, r));
384
- return this.cacheResponse(e, o);
385
+ makeRequest(t, e, s, r) {
386
+ const o = this.factoryParamOptions(t, this.helpers.getOptionsPage(e, s, r));
387
+ return this.cacheResponse(t, o);
385
388
  }
386
- get(e, t) {
387
- t || (t = {});
388
- const s = `/${e}`, r = this.factoryParamOptions(s, t);
389
+ get(t, e) {
390
+ e || (e = {});
391
+ const s = `/${t}`, r = this.factoryParamOptions(s, e);
389
392
  return this.cacheResponse(s, r);
390
393
  }
391
- async getAll(e, t, s) {
392
- const r = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, i = o.split("/"), a = s || i[i.length - 1], l = 1, h = await this.makeRequest(o, t, r, l), u = h.total ? Math.ceil(h.total / r) : 1, f = await this.helpers.asyncMap(this.helpers.range(l, u), (m) => this.makeRequest(o, t, r, m + 1));
394
+ async getAll(t, e, s) {
395
+ 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(this.helpers.range(l, u), (m) => this.makeRequest(o, e, r, m + 1));
393
396
  return this.helpers.flatMap([h, ...f], (m) => Object.values(m.data[a]));
394
397
  }
395
- post(e, t) {
396
- const s = `/${e}`;
397
- return Promise.resolve(this.throttle("post", s, t));
398
+ post(t, e) {
399
+ const s = `/${t}`;
400
+ return Promise.resolve(this.throttle("post", s, e));
398
401
  }
399
- put(e, t) {
400
- const s = `/${e}`;
401
- return Promise.resolve(this.throttle("put", s, t));
402
+ put(t, e) {
403
+ const s = `/${t}`;
404
+ return Promise.resolve(this.throttle("put", s, e));
402
405
  }
403
- delete(e, t) {
404
- const s = `/${e}`;
405
- return Promise.resolve(this.throttle("delete", s, t));
406
+ delete(t, e) {
407
+ const s = `/${t}`;
408
+ return Promise.resolve(this.throttle("delete", s, e));
406
409
  }
407
- getStories(e) {
408
- return this.get("cdn/stories", e);
410
+ getStories(t) {
411
+ return this.get("cdn/stories", t);
409
412
  }
410
- getStory(e, t) {
411
- return this.get(`cdn/stories/${e}`, t);
413
+ getStory(t, e) {
414
+ return this.get(`cdn/stories/${t}`, e);
412
415
  }
413
416
  getToken() {
414
417
  return this.accessToken;
@@ -416,26 +419,26 @@ class W {
416
419
  ejectInterceptor() {
417
420
  this.client.eject();
418
421
  }
419
- _cleanCopy(e) {
420
- return JSON.parse(JSON.stringify(e));
422
+ _cleanCopy(t) {
423
+ return JSON.parse(JSON.stringify(t));
421
424
  }
422
- _insertLinks(e, t) {
423
- const s = e[t];
425
+ _insertLinks(t, e) {
426
+ const s = t[e];
424
427
  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]));
425
428
  }
426
- _insertRelations(e, t, s) {
427
- if (s.indexOf(`${e.component}.${t}`) > -1) {
428
- if (typeof e[t] == "string")
429
- this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
430
- else if (e[t] && e[t].constructor === Array) {
429
+ _insertRelations(t, e, s) {
430
+ if (s.indexOf(`${t.component}.${e}`) > -1) {
431
+ if (typeof t[e] == "string")
432
+ this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
433
+ else if (t[e] && t[e].constructor === Array) {
431
434
  const r = [];
432
- e[t].forEach((o) => {
435
+ t[e].forEach((o) => {
433
436
  this.relations[o] && r.push(this._cleanCopy(this.relations[o]));
434
- }), e[t] = r;
437
+ }), t[e] = r;
435
438
  }
436
439
  }
437
440
  }
438
- iterateTree(e, t) {
441
+ iterateTree(t, e) {
439
442
  const s = (r) => {
440
443
  if (r != null) {
441
444
  if (r.constructor === Array)
@@ -445,94 +448,94 @@ class W {
445
448
  if (r._stopResolving)
446
449
  return;
447
450
  for (const o in r)
448
- (r.component && r._uid || r.type === "link") && (this._insertRelations(r, o, t), this._insertLinks(r, o)), s(r[o]);
451
+ (r.component && r._uid || r.type === "link") && (this._insertRelations(r, o, e), this._insertLinks(r, o)), s(r[o]);
449
452
  }
450
453
  }
451
454
  };
452
- s(e.content);
455
+ s(t.content);
453
456
  }
454
- async resolveLinks(e, t) {
457
+ async resolveLinks(t, e) {
455
458
  let s = [];
456
- if (e.link_uuids) {
457
- const r = e.link_uuids.length, o = [], i = 50;
459
+ if (t.link_uuids) {
460
+ const r = t.link_uuids.length, o = [], i = 50;
458
461
  for (let a = 0; a < r; a += i) {
459
462
  const l = Math.min(r, a + i);
460
- o.push(e.link_uuids.slice(a, l));
463
+ o.push(t.link_uuids.slice(a, l));
461
464
  }
462
465
  for (let a = 0; a < o.length; a++)
463
466
  (await this.getStories({
464
467
  per_page: i,
465
- language: t.language,
466
- version: t.version,
468
+ language: e.language,
469
+ version: e.version,
467
470
  by_uuids: o[a].join(",")
468
471
  })).data.stories.forEach((l) => {
469
472
  s.push(l);
470
473
  });
471
474
  } else
472
- s = e.links;
475
+ s = t.links;
473
476
  s.forEach((r) => {
474
477
  this.links[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
475
478
  });
476
479
  }
477
- async resolveRelations(e, t) {
480
+ async resolveRelations(t, e) {
478
481
  let s = [];
479
- if (e.rel_uuids) {
480
- const r = e.rel_uuids.length, o = [], i = 50;
482
+ if (t.rel_uuids) {
483
+ const r = t.rel_uuids.length, o = [], i = 50;
481
484
  for (let a = 0; a < r; a += i) {
482
485
  const l = Math.min(r, a + i);
483
- o.push(e.rel_uuids.slice(a, l));
486
+ o.push(t.rel_uuids.slice(a, l));
484
487
  }
485
488
  for (let a = 0; a < o.length; a++)
486
489
  (await this.getStories({
487
490
  per_page: i,
488
- language: t.language,
489
- version: t.version,
491
+ language: e.language,
492
+ version: e.version,
490
493
  by_uuids: o[a].join(",")
491
494
  })).data.stories.forEach((l) => {
492
495
  s.push(l);
493
496
  });
494
497
  } else
495
- s = e.rels;
498
+ s = t.rels;
496
499
  s && s.length > 0 && s.forEach((r) => {
497
500
  this.relations[r.uuid] = __spreadProps(__spreadValues({}, r), { _stopResolving: true });
498
501
  });
499
502
  }
500
- async resolveStories(e, t) {
503
+ async resolveStories(t, e) {
501
504
  var s, r;
502
505
  let o = [];
503
- 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)
506
+ 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)
504
507
  for (const i in this.relations)
505
508
  this.iterateTree(this.relations[i], o);
506
- e.story ? this.iterateTree(e.story, o) : e.stories.forEach((i) => {
509
+ t.story ? this.iterateTree(t.story, o) : t.stories.forEach((i) => {
507
510
  this.iterateTree(i, o);
508
511
  });
509
512
  }
510
- cacheResponse(e, t, s) {
511
- return new Promise((r, o) => {
512
- const i = this.helpers.stringify({ url: e, params: t }), a = this.cacheProvider();
513
- if (this.cache.clear === "auto" && t.version === "draft" && this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
514
- const l = a.get(i);
515
- if (l)
516
- return r(l);
517
- }
513
+ async cacheResponse(t, e, s) {
514
+ const r = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
515
+ if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
516
+ const i = await o.get(r);
517
+ if (i)
518
+ return Promise.resolve(i);
519
+ }
520
+ return new Promise((i, a) => {
518
521
  try {
519
522
  (async () => {
520
523
  var l;
521
- const h = await this.throttle("get", e, t);
524
+ const h = await this.throttle("get", t, e);
522
525
  let u = { data: h.data, headers: h.headers };
523
526
  if ((l = h.headers) != null && l["per-page"] && (u = Object.assign({}, u, {
524
527
  perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
525
528
  total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
526
529
  })), h.status != 200)
527
- return o(h);
528
- (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);
530
+ return a(h);
531
+ (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);
529
532
  })();
530
533
  } catch {
531
534
  }
532
535
  });
533
536
  }
534
- throttledRequest(e, t, s) {
535
- return this.client[e](t, s);
537
+ throttledRequest(t, e, s) {
538
+ return this.client[t](e, s);
536
539
  }
537
540
  cacheVersions() {
538
541
  return d;
@@ -540,61 +543,68 @@ class W {
540
543
  cacheVersion() {
541
544
  return d[this.accessToken];
542
545
  }
543
- setCacheVersion(e) {
544
- this.accessToken && (d[this.accessToken] = e);
546
+ setCacheVersion(t) {
547
+ this.accessToken && (d[this.accessToken] = t);
545
548
  }
546
549
  cacheProvider() {
547
550
  switch (this.cache.type) {
548
551
  case "memory":
549
552
  return {
550
- get(e) {
551
- return p[e];
553
+ get(t) {
554
+ return Promise.resolve(p[t]);
552
555
  },
553
556
  getAll() {
554
- return p;
557
+ return Promise.resolve(p);
555
558
  },
556
- set(e, t) {
557
- p[e] = t;
559
+ set(t, e) {
560
+ return p[t] = e, Promise.resolve(void 0);
558
561
  },
559
562
  flush() {
560
- p = {};
563
+ return p = {}, Promise.resolve(void 0);
561
564
  }
562
565
  };
566
+ case "custom":
567
+ if (this.cache.custom)
568
+ return this.cache.custom;
563
569
  default:
564
570
  return {
565
571
  get() {
572
+ return Promise.resolve(void 0);
566
573
  },
567
574
  getAll() {
575
+ return Promise.resolve(void 0);
568
576
  },
569
577
  set() {
578
+ return Promise.resolve(void 0);
570
579
  },
571
580
  flush() {
581
+ return Promise.resolve(void 0);
572
582
  }
573
583
  };
574
584
  }
575
585
  }
576
- flushCache() {
577
- return this.cacheProvider().flush(), this;
586
+ async flushCache() {
587
+ return await this.cacheProvider().flush(), this;
578
588
  }
579
589
  }
580
590
  const X = (n = {}) => {
581
- const { apiOptions: e } = n;
582
- if (!e.accessToken) {
591
+ const { apiOptions: t } = n;
592
+ if (!t.accessToken) {
583
593
  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");
584
594
  return;
585
595
  }
586
- return { storyblokApi: new W(e) };
596
+ return { storyblokApi: new W(t) };
587
597
  }, Z = (n) => {
588
598
  if (typeof n != "object" || typeof n._editable > "u")
589
599
  return {};
590
- const e = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
600
+ const t = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
591
601
  return {
592
- "data-blok-c": JSON.stringify(e),
593
- "data-blok-uid": e.id + "-" + e.uid
602
+ "data-blok-c": JSON.stringify(t),
603
+ "data-blok-uid": t.id + "-" + t.uid
594
604
  };
595
605
  };
596
606
  let y;
597
- const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", ee = (n, e, t = {}) => {
607
+ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e = {}) => {
598
608
  if (!(typeof window > "u")) {
599
609
  if (typeof window.storyblokRegisterEvent > "u") {
600
610
  console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
@@ -605,41 +615,41 @@ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", ee = (n, e, t =
605
615
  return;
606
616
  }
607
617
  window.storyblokRegisterEvent(() => {
608
- new window.StoryblokBridge(t).on(["input", "published", "change"], (r) => {
609
- r.action === "input" && r.story.id === n ? e(r.story) : (r.action === "change" || r.action === "published") && r.storyId === n && window.location.reload();
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();
610
620
  });
611
621
  });
612
622
  }
613
- }, te = (n = {}) => {
623
+ }, et = (n = {}) => {
614
624
  const {
615
- bridge: e,
616
- accessToken: t,
625
+ bridge: t,
626
+ accessToken: e,
617
627
  use: s = [],
618
628
  apiOptions: r = {},
619
629
  richText: o = {}
620
630
  } = n;
621
- r.accessToken = r.accessToken || t;
622
- const i = { bridge: e, apiOptions: r };
631
+ r.accessToken = r.accessToken || e;
632
+ const i = { bridge: t, apiOptions: r };
623
633
  let a = {};
624
634
  return s.forEach((l) => {
625
635
  a = __spreadValues(__spreadValues({}, a), l(i));
626
- }), e !== false && w(R), y = new g(o.schema), o.resolver && _(y, o.resolver), a;
627
- }, _ = (n, e) => {
628
- n.addNode("blok", (t) => {
636
+ }), t !== false && w(R), y = new g(o.schema), o.resolver && _(y, o.resolver), a;
637
+ }, _ = (n, t) => {
638
+ n.addNode("blok", (e) => {
629
639
  let s = "";
630
- return t.attrs.body.forEach((r) => {
631
- s += e(r.component, r);
640
+ return e.attrs.body.forEach((r) => {
641
+ s += t(r.component, r);
632
642
  }), {
633
643
  html: s
634
644
  };
635
645
  });
636
- }, se = (n, e, t) => {
637
- let s = t || y;
646
+ }, st = (n, t, e) => {
647
+ let s = e || y;
638
648
  if (!s) {
639
649
  console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
640
650
  return;
641
651
  }
642
- 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.
652
+ 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.
643
653
 
644
654
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
645
655
  };
@@ -671,7 +681,7 @@ const useStoryblok = (slug, apiOptions = {}, bridgeOptions = {}) => {
671
681
  const { data } = await storyblokApiInstance.get(`cdn/stories/${slug}`, apiOptions);
672
682
  setStory(data.story);
673
683
  if (isBridgeEnable && data.story.id) {
674
- ee(data.story.id, (story2) => setStory(story2), bridgeOptions);
684
+ tt(data.story.id, (story2) => setStory(story2), bridgeOptions);
675
685
  }
676
686
  }
677
687
  initStory();
@@ -686,7 +696,7 @@ const useStoryblokState = (initialStory = null, bridgeOptions = {}) => {
686
696
  }
687
697
  useEffect(() => {
688
698
  setStory(initialStory);
689
- ee(story.id, (newStory) => setStory(newStory), bridgeOptions);
699
+ tt(story.id, (newStory) => setStory(newStory), bridgeOptions);
690
700
  }, [initialStory]);
691
701
  return story;
692
702
  };
@@ -706,8 +716,8 @@ const getComponent = (componentKey) => {
706
716
  return componentsMap[componentKey];
707
717
  };
708
718
  const storyblokInit = (pluginOptions = {}) => {
709
- const { storyblokApi } = te(pluginOptions);
719
+ const { storyblokApi } = et(pluginOptions);
710
720
  storyblokApiInstance = storyblokApi;
711
721
  componentsMap = pluginOptions.components;
712
722
  };
713
- export { g as RichTextResolver, K as RichTextSchema, StoryblokComponent, X as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, ee as registerStoryblokBridge, se as renderRichText, Z as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, ee as useStoryblokBridge, useStoryblokState };
723
+ export { g as RichTextResolver, K as RichTextSchema, StoryblokComponent, X as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, tt as registerStoryblokBridge, st as renderRichText, Z as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, tt as useStoryblokBridge, useStoryblokState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/react",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "SDK to integrate Storyblok into your project using React.",
5
5
  "main": "./dist/storyblok-react.js",
6
6
  "module": "./dist/storyblok-react.mjs",
@@ -24,7 +24,7 @@
24
24
  "prepublishOnly": "npm run build && cp ../README.md ./"
25
25
  },
26
26
  "dependencies": {
27
- "@storyblok/js": "^2.0.12"
27
+ "@storyblok/js": "^2.0.14"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.20.12",