@storyblok/react 2.0.5 → 2.0.6

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){const e=new URL(`${this.baseURL}${this.url}`);let s=null;if(t==="get"){const a=new I;e.search=a.stringify(this.parameters)}else s=JSON.stringify(this.parameters);const r=new AbortController,{signal:n}=r;let i;this.timeout&&(i=setTimeout(()=>r.abort(),this.timeout));try{const a=await this.fetch(`${e}`,{method:t,headers:this.headers,body:s,signal:n});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(t){if(/20[01|04]/g.test(`${t.status}`))return t;throw{message:new Error(t.statusText||`status: ${t.status}`),response:t}}}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 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){if(/20[01|04]/g.test(`${t.status}`))return t;throw{message:new Error(t.statusText||`status: ${t.status}`),response:t}}}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.
2
2
 
3
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"}})});
@@ -45,7 +45,7 @@ const b = [], w = (n) => new Promise((e, t) => {
45
45
  b.forEach((o) => o()), k = true, e(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, l = (n, e, t) => (j(n, typeof e != "symbol" ? e + "" : e, t), t);
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
49
  function v(n) {
50
50
  return !(n !== n || n === 1 / 0 || n === -1 / 0);
51
51
  }
@@ -58,28 +58,28 @@ function x(n, e, t) {
58
58
  let r = [], o = 0;
59
59
  const i = function() {
60
60
  o++;
61
- const c = setTimeout(function() {
61
+ const l = setTimeout(function() {
62
62
  o--, s.length > 0 && i(), r = r.filter(function(u) {
63
- return u !== c;
63
+ return u !== l;
64
64
  });
65
65
  }, t);
66
- r.indexOf(c) < 0 && r.push(c);
66
+ r.indexOf(l) < 0 && r.push(l);
67
67
  const h = s.shift();
68
68
  h.resolve(n.apply(h.self, h.args));
69
- }, a = function(...c) {
69
+ }, a = function(...l) {
70
70
  const h = this;
71
71
  return new Promise(function(u, f) {
72
72
  s.push({
73
73
  resolve: u,
74
74
  reject: f,
75
- args: c,
75
+ args: l,
76
76
  self: h
77
77
  }), o < e && i();
78
78
  });
79
79
  };
80
80
  return a.abort = function() {
81
- r.forEach(clearTimeout), r = [], s.forEach(function(c) {
82
- c.reject(function() {
81
+ r.forEach(clearTimeout), r = [], s.forEach(function(l) {
82
+ l.reject(function() {
83
83
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
84
84
  });
85
85
  }), s.length = 0;
@@ -187,7 +187,7 @@ const E = function(n, e) {
187
187
  };
188
188
  class g {
189
189
  constructor(e) {
190
- l(this, "marks"), l(this, "nodes"), e || (e = K), this.marks = e.marks || [], this.nodes = e.nodes || [];
190
+ c(this, "marks"), c(this, "nodes"), e || (e = K), this.marks = e.marks || [], this.nodes = e.nodes || [];
191
191
  }
192
192
  addNode(e, t) {
193
193
  this.nodes[e] = t;
@@ -252,13 +252,13 @@ class g {
252
252
  }
253
253
  class T {
254
254
  constructor() {
255
- l(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), l(this, "getOptionsPage", (e, t = 25, s = 1) => __spreadProps(__spreadValues({}, e), {
255
+ c(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), c(this, "getOptionsPage", (e, t = 25, s = 1) => __spreadProps(__spreadValues({}, e), {
256
256
  per_page: t,
257
257
  page: s
258
- })), 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) => {
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
259
  const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
260
260
  return this.arrayFrom(s, (o, i) => i * r + e);
261
- }), l(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), l(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
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], []));
262
262
  }
263
263
  stringify(e, t, s) {
264
264
  const r = [];
@@ -266,15 +266,15 @@ class T {
266
266
  if (!Object.prototype.hasOwnProperty.call(e, o))
267
267
  continue;
268
268
  const i = e[o], a = s ? "" : encodeURIComponent(o);
269
- let c;
270
- 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);
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);
271
271
  }
272
272
  return r.join("&");
273
273
  }
274
274
  }
275
275
  class G {
276
276
  constructor(e) {
277
- 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 = false, this.url = "", this.parameters = {};
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 = {};
278
278
  }
279
279
  get(e, t) {
280
280
  return this.url = e, this.parameters = t, this._methodHandler("get");
@@ -303,28 +303,27 @@ class G {
303
303
  return s.headers = __spreadValues({}, t), s.status = e.status, s.statusText = e.statusText, s;
304
304
  }
305
305
  async _methodHandler(e) {
306
- const t = new URL(`${this.baseURL}${this.url}`);
307
- let s = null;
306
+ let t = `${this.baseURL}${this.url}}`, s = null;
308
307
  if (e === "get") {
309
- const a = new T();
310
- t.search = a.stringify(this.parameters);
308
+ const l = new T();
309
+ t = `${this.baseURL}${this.url}?${l.stringify(this.parameters)}`;
311
310
  } else
312
311
  s = JSON.stringify(this.parameters);
313
- const r = new AbortController(), { signal: o } = r;
314
- let i;
315
- this.timeout && (i = setTimeout(() => r.abort(), this.timeout));
312
+ const r = new URL(t), o = new AbortController(), { signal: i } = o;
313
+ let a;
314
+ this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
316
315
  try {
317
- const a = await this.fetch(`${t}`, {
316
+ const l = await this.fetch(`${r}`, {
318
317
  method: e,
319
318
  headers: this.headers,
320
319
  body: s,
321
- signal: o
320
+ signal: i
322
321
  });
323
- this.timeout && clearTimeout(i);
324
- const c = await this._responseHandler(a);
325
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
326
- } catch (a) {
327
- return a;
322
+ this.timeout && clearTimeout(a);
323
+ const h = await this._responseHandler(l);
324
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
325
+ } catch (l) {
326
+ return l;
328
327
  }
329
328
  }
330
329
  eject() {
@@ -343,7 +342,7 @@ let p = {};
343
342
  const d = {};
344
343
  class W {
345
344
  constructor(e, t) {
346
- 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) {
345
+ 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) {
347
346
  const o = e.region ? `-${e.region}` : "", i = e.https === false ? "http" : "https";
348
347
  e.oauthToken ? t = `${i}://api${o}.storyblok.com/v1` : t = `${i}://api${o}.storyblok.com/v2`;
349
348
  }
@@ -386,7 +385,7 @@ class W {
386
385
  return this.cacheResponse(s, r);
387
386
  }
388
387
  async getAll(e, t, s) {
389
- 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(this.helpers.range(c, u), (m) => this.makeRequest(o, t, r, m + 1));
388
+ 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));
390
389
  return this.helpers.flatMap([h, ...f], (m) => Object.values(m.data[a]));
391
390
  }
392
391
  post(e, t) {
@@ -453,8 +452,8 @@ class W {
453
452
  if (e.link_uuids) {
454
453
  const r = e.link_uuids.length, o = [], i = 50;
455
454
  for (let a = 0; a < r; a += i) {
456
- const c = Math.min(r, a + i);
457
- o.push(e.link_uuids.slice(a, c));
455
+ const l = Math.min(r, a + i);
456
+ o.push(e.link_uuids.slice(a, l));
458
457
  }
459
458
  for (let a = 0; a < o.length; a++)
460
459
  (await this.getStories({
@@ -462,8 +461,8 @@ class W {
462
461
  language: t.language,
463
462
  version: t.version,
464
463
  by_uuids: o[a].join(",")
465
- })).data.stories.forEach((c) => {
466
- s.push(c);
464
+ })).data.stories.forEach((l) => {
465
+ s.push(l);
467
466
  });
468
467
  } else
469
468
  s = e.links;
@@ -476,8 +475,8 @@ class W {
476
475
  if (e.rel_uuids) {
477
476
  const r = e.rel_uuids.length, o = [], i = 50;
478
477
  for (let a = 0; a < r; a += i) {
479
- const c = Math.min(r, a + i);
480
- o.push(e.rel_uuids.slice(a, c));
478
+ const l = Math.min(r, a + i);
479
+ o.push(e.rel_uuids.slice(a, l));
481
480
  }
482
481
  for (let a = 0; a < o.length; a++)
483
482
  (await this.getStories({
@@ -485,8 +484,8 @@ class W {
485
484
  language: t.language,
486
485
  version: t.version,
487
486
  by_uuids: o[a].join(",")
488
- })).data.stories.forEach((c) => {
489
- s.push(c);
487
+ })).data.stories.forEach((l) => {
488
+ s.push(l);
490
489
  });
491
490
  } else
492
491
  s = e.rels;
@@ -508,16 +507,16 @@ class W {
508
507
  return new Promise((r, o) => {
509
508
  const i = this.helpers.stringify({ url: e, params: t }), a = this.cacheProvider();
510
509
  if (this.cache.clear === "auto" && t.version === "draft" && this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
511
- const c = a.get(i);
512
- if (c)
513
- return r(c);
510
+ const l = a.get(i);
511
+ if (l)
512
+ return r(l);
514
513
  }
515
514
  try {
516
515
  (async () => {
517
- var c;
516
+ var l;
518
517
  const h = await this.throttle("get", e, t);
519
518
  let u = { data: h.data, headers: h.headers };
520
- if ((c = h.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
519
+ if ((l = h.headers) != null && l["per-page"] && (u = Object.assign({}, u, {
521
520
  perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
522
521
  total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
523
522
  })), h.status != 200)
@@ -618,8 +617,8 @@ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", ee = (n, e, t =
618
617
  r.accessToken = r.accessToken || t;
619
618
  const i = { bridge: e, apiOptions: r };
620
619
  let a = {};
621
- return s.forEach((c) => {
622
- a = __spreadValues(__spreadValues({}, a), c(i));
620
+ return s.forEach((l) => {
621
+ a = __spreadValues(__spreadValues({}, a), l(i));
623
622
  }), e !== false && w(R), y = new g(o.schema), o.resolver && _(y, o.resolver), a;
624
623
  }, _ = (n, e) => {
625
624
  n.addNode("blok", (t) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/react",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
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.8"
27
+ "@storyblok/js": "^2.0.9"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.20.12",
@@ -32,7 +32,7 @@
32
32
  "@cypress/react": "^5.12.5",
33
33
  "@cypress/vite-dev-server": "^2.2.3",
34
34
  "@tsconfig/recommended": "^1.0.2",
35
- "@types/react": "18.0.26",
35
+ "@types/react": "18.0.27",
36
36
  "@vitejs/plugin-react": "^1.3.2",
37
37
  "babel-jest": "^29.3.1",
38
38
  "cypress": "^9.7.0",