@storyblok/react 2.0.15 → 2.0.17

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