@storyblok/react 2.0.2 → 2.0.4

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