@storyblok/js 4.2.7 → 4.2.8
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.
- package/dist/storyblok-js.js +1 -1
- package/dist/storyblok-js.mjs +343 -325
- package/package.json +2 -2
package/dist/storyblok-js.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.storyblok={}))})(this,function(m){"use strict";var Ce=Object.defineProperty;var Pe=(m,b,w)=>b in m?Ce(m,b,{enumerable:!0,configurable:!0,writable:!0,value:w}):m[b]=w;var p=(m,b,w)=>Pe(m,typeof b!="symbol"?b+"":b,w);let b=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),w=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),U=function(e){return e.TEXT="text",e}({}),O=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const X=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Q=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),Z=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ee(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const C=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function te(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function a(u,c,f,g,A){typeof u!="number"||u<=c||u>=f?console.warn(`[StoryblokRichText] - ${g.charAt(0).toUpperCase()+g.slice(1)} value must be a number between ${c} and ${f} (inclusive)`):A.push(`${g}(${u})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(i.width=t.width,s=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(i.height=t.height,r=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(i.loading=t.loading),t.class&&(i.class=t.class),t.filters){const{filters:u}=t||{},{blur:c,brightness:f,fill:g,format:A,grayscale:E,quality:L,rotate:I}=u||{};c&&a(c,0,100,"blur",n),L&&a(L,0,100,"quality",n),f&&a(f,0,100,"brightness",n),g&&n.push(`fill(${g})`),E&&n.push("grayscale()"),I&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${I})`),A&&["webp","png","jpeg"].includes(A)&&n.push(`format(${A})`)}t.srcset&&(i.srcset=t.srcset.map(u=>{if(typeof u=="number")return`${e}/m/${u}x0/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`;if(Array.isArray(u)&&u.length===2){const[c,f]=u;return`${e}/m/${c}x${f}/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(i.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return s>0&&r>0&&(l=`${l}${s}x${r}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:i}}function B(e,t={},s){const r=Q(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(X.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function F(e={}){const t=new Map,{renderFn:s=B,textFn:r=ee,resolvers:i={},optimizeImages:n=!1,keyedResolvers:a=!1}=e,l=s!==B,u=o=>(d,h)=>{const y=d.attrs||{};return h.render(o,y,d.children||null)},c=(o,d)=>{const{src:h,alt:y,title:v,srcset:R,sizes:k}=o.attrs||{};let _=h,S={};if(n){const{src:Le,attrs:Oe}=te(h,n);_=Le,S=Oe}const Te={src:_,alt:y,title:v,srcset:R,sizes:k,...S};return d.render("img",C(Te))},f=(o,d)=>{const{level:h,...y}=o.attrs||{};return d.render(`h${h}`,y,o.children)},g=(o,d)=>{var y,v,R,k;const h=d.render("img",{src:(y=o.attrs)==null?void 0:y.fallbackImage,alt:(v=o.attrs)==null?void 0:v.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return d.render("span",{"data-type":"emoji","data-name":(R=o.attrs)==null?void 0:R.name,"data-emoji":(k=o.attrs)==null?void 0:k.emoji},h)},A=(o,d)=>d.render("pre",o.attrs||{},d.render("code",{},o.children||"")),E=(o,d=!1)=>({text:h,attrs:y},v)=>{const{class:R,id:k,..._}=y||{},S=d?{class:R,id:k,style:Z(_)||void 0}:y||{};return v.render(o,C(S),h)},L=o=>x(o),I=o=>{const{marks:d,...h}=o;if("text"in o){if(d)return d.reduce((v,R)=>L({...R,text:v}),L({...h,children:h.children}));const y=o.attrs||{};if(a){const v=t.get("txt")||0;t.set("txt",v+1),y.key=`txt-${v}`}return r(h.text,y)}return""},K=(o,d)=>{const{linktype:h,href:y,anchor:v,...R}=o.attrs||{};let k="";switch(h){case O.ASSET:case O.URL:k=y;break;case O.EMAIL:k=`mailto:${y}`;break;case O.STORY:k=y,v&&(k=`${k}#${v}`);break;default:k=y;break}const _={...R};return k&&(_.href=k),d.render("a",_,o.text)},ke=(o,d)=>{var h,y;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),d.render("span",{blok:(h=o==null?void 0:o.attrs)==null?void 0:h.body[0],id:(y=o.attrs)==null?void 0:y.id,style:"display: none"})},we=(o,d)=>{const h={},y=d.render("tbody",{},o.children);return d.render("table",h,y)},_e=(o,d)=>{const h={};return d.render("tr",h,o.children)},Se=(o,d)=>{const{colspan:h,rowspan:y,colwidth:v,backgroundColor:R,...k}=o.attrs||{},_={...k};h>1&&(_.colspan=h),y>1&&(_.rowspan=y);const S=[];return v&&S.push(`width: ${v}px;`),R&&S.push(`background-color: ${R};`),S.length>0&&(_.style=S.join(" ")),d.render("td",C(_),o.children)},Ee=(o,d)=>{const{colspan:h,rowspan:y,colwidth:v,backgroundColor:R,...k}=o.attrs||{},_={...k};h>1&&(_.colspan=h),y>1&&(_.rowspan=y);const S=[];return v&&S.push(`width: ${v}px;`),R&&S.push(`background-color: ${R};`),S.length>0&&(_.style=S.join(" ")),d.render("th",C(_),o.children)},Y=new Map([[b.DOCUMENT,u("")],[b.HEADING,f],[b.PARAGRAPH,u("p")],[b.UL_LIST,u("ul")],[b.OL_LIST,u("ol")],[b.LIST_ITEM,u("li")],[b.IMAGE,c],[b.EMOJI,g],[b.CODE_BLOCK,A],[b.HR,u("hr")],[b.BR,u("br")],[b.QUOTE,u("blockquote")],[b.COMPONENT,ke],[U.TEXT,I],[w.LINK,K],[w.ANCHOR,K],[w.STYLED,E("span",!0)],[w.BOLD,E("strong")],[w.TEXT_STYLE,E("span",!0)],[w.ITALIC,E("em")],[w.UNDERLINE,E("u")],[w.STRIKE,E("s")],[w.CODE,E("code")],[w.SUPERSCRIPT,E("sup")],[w.SUBSCRIPT,E("sub")],[w.HIGHLIGHT,E("mark")],[b.TABLE,we],[b.TABLE_ROW,_e],[b.TABLE_CELL,Se],[b.TABLE_HEADER,Ee]]),W=new Map([...Y,...Object.entries(i).map(([o,d])=>[o,d])]),Ae=()=>({render:(h,y={},v)=>{if(a&&h){const R=t.get(h)||0;t.set(h,R+1),y.key=`${h}-${R}`}return s(h,y,v)},originalResolvers:Y,mergedResolvers:W});function N(o){const d=W.get(o.type);if(!d)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const h=Ae();if(o.type==="text")return d(o,h);const y=o.content?o.content.map(x):void 0;return d({...o,children:y},h)}function x(o){return o.type==="doc"?l?o.content.map(N):o.content.map(N).join(""):Array.isArray(o)?o.map(N):N(o)}return{render:x}}let z=!1;const G=[],M=e=>new Promise((t,s)=>{if(typeof window>"u"){s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=i=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?i():G.push(i)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const r=document.createElement("script");r.async=!0,r.src=e,r.id="storyblok-javascript-bridge",r.onerror=i=>s(i),r.onload=i=>{G.forEach(n=>n()),z=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)});var re=class extends Error{constructor(e){super(e),this.name="AbortError"}};function se(e,t,s){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let i=[],n=0,a=!1;const l=async()=>{n++;const c=r.shift();if(c)try{const g=await e(...c.args);c.resolve(g)}catch(g){c.reject(g)}const f=setTimeout(()=>{n--,r.length>0&&l(),i=i.filter(g=>g!==f)},s);i.includes(f)||i.push(f)},u=(...c)=>a?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,g)=>{r.push({resolve:f,reject:g,args:c}),n<t&&l()});return u.abort=()=>{a=!0,i.forEach(clearTimeout),i=[],r.forEach(c=>c.reject(()=>new re("Throttle function aborted"))),r.length=0},u}var ie=se;const q=(e="")=>e.includes("/cdn/"),ne=(e,t=25,s=1)=>({...e,per_page:t,page:s}),oe=e=>new Promise(t=>setTimeout(t,e)),le=(e=0,t)=>Array.from({length:e},t),ae=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return le(s,(i,n)=>n*r+e)},ce=async(e,t)=>Promise.all(e.map(t)),ue=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),$=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i];if(n==null)continue;const a=s?"":encodeURIComponent(i);let l;typeof n=="object"?l=$(n,t?t+encodeURIComponent(`[${a}]`):a,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${a}]`):a}=${encodeURIComponent(n)}`,r.push(l)}return r.join("&")},V=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var he=class{constructor(e){p(this,"baseURL");p(this,"timeout");p(this,"headers");p(this,"responseInterceptor");p(this,"fetch");p(this,"ejectInterceptor");p(this,"url");p(this,"parameters");p(this,"fetchOptions");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=!1,this.url="",this.parameters={},this.fetchOptions={}}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={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;e==="get"?t=`${this.baseURL}${this.url}?${$(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let a;this.timeout&&(a=setTimeout(()=>i.abort(),this.timeout));try{const l=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(a);const u=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(l){return{message:l}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(i)})}},de=he;const D="SB-Agent",j={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},fe={PUBLISHED:"published"};let P={};const T={};var ye=class{constructor(e,t){p(this,"client");p(this,"maxRetries");p(this,"retriesDelay");p(this,"throttle");p(this,"accessToken");p(this,"cache");p(this,"resolveCounter");p(this,"relations");p(this,"links");p(this,"version");p(this,"richTextResolver");p(this,"resolveNestedRelations");p(this,"stringifiedStoriesCache");p(this,"inlineAssets");let s=e.endpoint||t;if(!s){const n=e.https===!1?"http":"https";e.oauthToken?s=`${n}://${V(e.region)}/v1`:s=`${n}://${V(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([a,l])=>{r.set(a,l)}),r.has(D)||(r.set(D,j.defaultAgentName),r.set(j.defaultAgentVersion,j.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ie(this.throttledRequest.bind(this),i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||fe.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new de({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=T[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return q(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,ne(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;q(r)&&(t.version=t.version||this.version);const i=this.factoryParamOptions(r,t);return this.cacheResponse(r,i,void 0,s)}async getAll(e,t={},s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),a=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,u=await this.makeRequest(n,t,i,l,r),c=u.total?Math.ceil(u.total/(u.perPage||i)):1,f=await ce(ae(l,c),g=>this.makeRequest(n,t,i,g+1,r));return ue([u,...f],g=>Object.values(g.data[a]))}post(e,t={},s){const r=`/${e}`;return this.throttle("post",r,t,s)}put(e,t={},s){const r=`/${e}`;return this.throttle("put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`;return this.throttle("delete",r,t,s)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];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]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(s,r):Array.isArray(r)&&(e[t]=r.map(i=>this.getStoryReference(s,i)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(a=>a.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(i,n="")=>{if(!(!i||i._stopResolving)){if(Array.isArray(i))i.forEach((a,l)=>r(a,`${n}[${l}]`));else if(typeof i=="object")for(const a in i){const l=n?`${n}.${a}`:a;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,a,t,s),this._insertLinks(i,a,s)),r(i[a],l)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],a=50;for(let l=0;l<i;l+=a){const u=Math.min(i,l+a);n.push(e.link_uuids.slice(l,u))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],a=50;for(let l=0;l<i;l+=a){const u=Math.min(i,l+a);n.push(e.rel_uuids.slice(l,u))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var i,n;let r=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(r=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((i=e.links)!=null&&i.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const a in this.relations[s])this.iterateTree(this.relations[s][a],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(a=>{this.iterateTree(a,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=$({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const a=await n.get(i);if(a)return Promise.resolve(a)}return new Promise(async(a,l)=>{var u;try{const c=await this.throttle("get",e,t,r);if(c.status!==200)return l(c);let f={data:c.data,headers:c.headers};if((u=c.headers)!=null&&u["per-page"]&&(f=Object.assign({},f,{perPage:c.headers["per-page"]?Number.parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?Number.parseInt(c.headers.total):0})),f.data.story||f.data.stories){const A=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(f.data,t,`${A}`),f=await this.processInlineAssets(f)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(i,f);const g=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&f.data.cv&&(g&&T[t.token]&&T[t.token]!==f.data.cv&&await this.flushCache(),T[t.token]=f.data.cv),a(f)}catch(c){if(c.response&&c.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await oe(this.retriesDelay),this.cacheResponse(e,t,s).then(a).catch(l);l(c)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return T}cacheVersion(){return T[this.accessToken]}setCacheVersion(e){this.accessToken&&(T[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(T[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=s=>{if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>t(i));let r={...s};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...r,...e.data.assets.find(i=>i.id===r.id)});for(const i in r)typeof r[i]=="object"&&(r[i]=t(r[i]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(s=>(s.content=t(s.content),s))),e}},be=ye;const ge=(e={})=>{const{apiOptions:t}=e;if(!t||!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 be(t)}},pe=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let H="https://app.storyblok.com/f/storyblok-v2-latest.js";const J=(e,t,s={})=>{var l;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((l=window.location)==null?void 0:l.href).searchParams.get("_storyblok"),a=n!==null&&+n===e;if(!(!i||!a)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(s).on(["input","published","change"],c=>{var f;c&&(c.action==="input"&&((f=c.story)==null?void 0:f.id)===e?t(c.story):(c.action==="change"||c.action==="published")&&c.storyId===e&&window.location.reload())})})}},me=(e={})=>{var f,g;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const a={bridge:t,apiOptions:i};let l={};r.forEach(A=>{l={...l,...A(a)}}),n&&(H=n);const c=!(typeof window>"u")&&((g=(f=window.location)==null?void 0:f.search)==null?void 0:g.includes("_storyblok_tk"));return t!==!1&&c&&M(H),l};function ve(e,t){return F(t).render(e)}const Re=()=>M(H);m.BlockTypes=b,m.MarkTypes=w,m.TextTypes=U,m.apiPlugin=ge,m.loadStoryblokBridge=Re,m.registerStoryblokBridge=J,m.renderRichText=ve,m.richTextResolver=F,m.storyblokEditable=pe,m.storyblokInit=me,m.useStoryblokBridge=J,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
7
|
+
(function(R,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(R=typeof globalThis<"u"?globalThis:R||self,g(R.storyblok={}))})(this,function(R){"use strict";var Pe=Object.defineProperty;var Ie=(R,g,w)=>g in R?Pe(R,g,{enumerable:!0,configurable:!0,writable:!0,value:w}):R[g]=w;var v=(R,g,w)=>Ie(R,typeof g!="symbol"?g+"":g,w);let g=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),w=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),B=function(e){return e.TEXT="text",e}({}),P=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const Q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Z=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ee=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function te(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const L=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function re(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function c(u,a,y,m,A){typeof u!="number"||u<=a||u>=y?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${a} and ${y} (inclusive)`):A.push(`${m}(${u})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(i.width=t.width,s=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(i.height=t.height,r=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(i.loading=t.loading),t.class&&(i.class=t.class),t.filters){const{filters:u}=t||{},{blur:a,brightness:y,fill:m,format:A,grayscale:H,quality:S,rotate:O}=u||{};a&&c(a,0,100,"blur",n),S&&c(S,0,100,"quality",n),y&&c(y,0,100,"brightness",n),m&&n.push(`fill(${m})`),H&&n.push("grayscale()"),O&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${O})`),A&&["webp","png","jpeg"].includes(A)&&n.push(`format(${A})`)}t.srcset&&(i.srcset=t.srcset.map(u=>{if(typeof u=="number")return`${e}/m/${u}x0/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`;if(Array.isArray(u)&&u.length===2){const[a,y]=u;return`${e}/m/${a}x${y}/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(i.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return s>0&&r>0&&(l=`${l}${s}x${r}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:i}}function F(e,t={},s){const r=Z(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(Q.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function z(e={}){const t=new Map,{renderFn:s=F,textFn:r=te,resolvers:i={},optimizeImages:n=!1,keyedResolvers:c=!1}=e,l=s!==F,u=(o={})=>{const{textAlign:h,class:d,id:f,style:b,...k}=o,p=[];return b&&p.push(b.endsWith(";")?b:`${b};`),h&&p.push(`text-align: ${h};`),L({...k,class:d,id:f,...p.length>0?{style:p.join(" ")}:{}})},a=o=>(h,d)=>{const f=u(h.attrs);return d.render(o,f,h.children||null)},y=(o,h)=>{const{src:d,alt:f,title:b,srcset:k,sizes:p}=o.attrs||{};let E=d,_={};if(n){const{src:Oe,attrs:Ce}=re(d,n);E=Oe,_=Ce}const C={src:E,alt:f,title:b,srcset:k,sizes:p,..._};return h.render("img",L(C))},m=(o,h)=>{const{level:d,...f}=o.attrs||{},b=u(f);return h.render(`h${d}`,b,o.children)},A=(o,h)=>{var f,b,k,p;const d=h.render("img",{src:(f=o.attrs)==null?void 0:f.fallbackImage,alt:(b=o.attrs)==null?void 0:b.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(k=o.attrs)==null?void 0:k.name,"data-emoji":(p=o.attrs)==null?void 0:p.emoji},d)},H=(o,h)=>h.render("pre",o.attrs||{},h.render("code",{},o.children||"")),S=(o,h=!1)=>({text:d,attrs:f},b)=>{const{class:k,id:p,...E}=f||{},_=h?{class:k,id:p,style:ee(E)||void 0}:f||{};return b.render(o,L(_),d)},O=o=>U(o),we=o=>{const{marks:h,...d}=o;if("text"in o){if(h)return h.reduce((b,k)=>O({...k,text:b}),O({...d,children:d.children}));const f=o.attrs||{};if(c){const b=t.get("txt")||0;t.set("txt",b+1),f.key=`txt-${b}`}return r(d.text,f)}return""},Y=(o,h)=>{const{linktype:d,href:f,anchor:b,...k}=o.attrs||{};let p="";switch(d){case P.ASSET:case P.URL:p=f;break;case P.EMAIL:p=`mailto:${f}`;break;case P.STORY:p=f,b&&(p=`${p}#${b}`);break;default:p=f;break}const E={...k};return p&&(E.href=p),h.render("a",E,o.text)},_e=(o,h)=>{var d,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=o==null?void 0:o.attrs)==null?void 0:d.body[0],id:(f=o.attrs)==null?void 0:f.id,style:"display: none"})},Se=(o,h)=>{const d=u(o.attrs),f=o.children||null;return h.render("table",d,h.render("tbody",{},f))},Ae=(o,h)=>{const d=u(o.attrs);return h.render("tr",d,o.children)},Ee=(o,h)=>{const{colspan:d,rowspan:f,colwidth:b,backgroundColor:k,textAlign:p,...E}=o.attrs||{},_=[];b&&_.push(`width: ${b}px;`),k&&_.push(`background-color: ${k};`),p&&_.push(`text-align: ${p};`);const C={...E,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},..._.length>0?{style:_.join(" ")}:{}};return h.render("td",L(C),o.children)},Te=(o,h)=>{const{colspan:d,rowspan:f,colwidth:b,backgroundColor:k,textAlign:p,...E}=o.attrs||{},_=[];b&&_.push(`width: ${b}px;`),k&&_.push(`background-color: ${k};`),p&&_.push(`text-align: ${p};`);const C={...E,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},..._.length>0?{style:_.join(" ")}:{}};return h.render("th",L(C),o.children)},W=new Map([[g.DOCUMENT,a("")],[g.HEADING,m],[g.PARAGRAPH,a("p")],[g.UL_LIST,a("ul")],[g.OL_LIST,a("ol")],[g.LIST_ITEM,a("li")],[g.IMAGE,y],[g.EMOJI,A],[g.CODE_BLOCK,H],[g.HR,a("hr")],[g.BR,a("br")],[g.QUOTE,a("blockquote")],[g.COMPONENT,_e],[B.TEXT,we],[w.LINK,Y],[w.ANCHOR,Y],[w.STYLED,S("span",!0)],[w.BOLD,S("strong")],[w.TEXT_STYLE,S("span",!0)],[w.ITALIC,S("em")],[w.UNDERLINE,S("u")],[w.STRIKE,S("s")],[w.CODE,S("code")],[w.SUPERSCRIPT,S("sup")],[w.SUBSCRIPT,S("sub")],[w.HIGHLIGHT,S("mark")],[g.TABLE,Se],[g.TABLE_ROW,Ae],[g.TABLE_CELL,Ee],[g.TABLE_HEADER,Te]]),X=new Map([...W,...Object.entries(i).map(([o,h])=>[o,h])]),Le=()=>({render:(d,f={},b)=>{if(c&&d){const k=t.get(d)||0;t.set(d,k+1),f.key=`${d}-${k}`}return s(d,f,b)},originalResolvers:W,mergedResolvers:X});function N(o){const h=X.get(o.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const d=Le();if(o.type==="text")return h(o,d);const f=o.content?o.content.map(U):void 0;return h({...o,children:f},d)}function U(o){return o.type==="doc"?l?o.content.map(N):o.content.map(N).join(""):Array.isArray(o)?o.map(N):N(o)}return{render:U}}let G=!1;const M=[],q=e=>new Promise((t,s)=>{if(typeof window>"u"){s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=i=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}G?i():M.push(i)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const r=document.createElement("script");r.async=!0,r.src=e,r.id="storyblok-javascript-bridge",r.onerror=i=>s(i),r.onload=i=>{M.forEach(n=>n()),G=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)});var se=class extends Error{constructor(e){super(e),this.name="AbortError"}};function ie(e,t,s){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let i=[],n=0,c=!1;const l=async()=>{n++;const a=r.shift();if(a)try{const m=await e(...a.args);a.resolve(m)}catch(m){a.reject(m)}const y=setTimeout(()=>{n--,r.length>0&&l(),i=i.filter(m=>m!==y)},s);i.includes(y)||i.push(y)},u=(...a)=>c?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((y,m)=>{r.push({resolve:y,reject:m,args:a}),n<t&&l()});return u.abort=()=>{c=!0,i.forEach(clearTimeout),i=[],r.forEach(a=>a.reject(()=>new se("Throttle function aborted"))),r.length=0},u}var ne=ie;const V=(e="")=>e.includes("/cdn/"),oe=(e,t=25,s=1)=>({...e,per_page:t,page:s}),le=e=>new Promise(t=>setTimeout(t,e)),ae=(e=0,t)=>Array.from({length:e},t),ce=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return ae(s,(i,n)=>n*r+e)},ue=async(e,t)=>Promise.all(e.map(t)),he=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),$=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i];if(n==null)continue;const c=s?"":encodeURIComponent(i);let l;typeof n=="object"?l=$(n,t?t+encodeURIComponent(`[${c}]`):c,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(n)}`,r.push(l)}return r.join("&")},D=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var de=class{constructor(e){v(this,"baseURL");v(this,"timeout");v(this,"headers");v(this,"responseInterceptor");v(this,"fetch");v(this,"ejectInterceptor");v(this,"url");v(this,"parameters");v(this,"fetchOptions");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=!1,this.url="",this.parameters={},this.fetchOptions={}}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={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;e==="get"?t=`${this.baseURL}${this.url}?${$(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const l=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const u=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(l){return{message:l}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(i)})}},fe=de;const J="SB-Agent",x={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},ye={PUBLISHED:"published"};let I={};const T={};var ge=class{constructor(e,t){v(this,"client");v(this,"maxRetries");v(this,"retriesDelay");v(this,"throttle");v(this,"accessToken");v(this,"cache");v(this,"resolveCounter");v(this,"relations");v(this,"links");v(this,"version");v(this,"richTextResolver");v(this,"resolveNestedRelations");v(this,"stringifiedStoriesCache");v(this,"inlineAssets");let s=e.endpoint||t;if(!s){const n=e.https===!1?"http":"https";e.oauthToken?s=`${n}://${D(e.region)}/v1`:s=`${n}://${D(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([c,l])=>{r.set(c,l)}),r.has(J)||(r.set(J,x.defaultAgentName),r.set(x.defaultAgentVersion,x.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ne(this.throttledRequest.bind(this),i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||ye.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=T[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return V(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,oe(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;V(r)&&(t.version=t.version||this.version);const i=this.factoryParamOptions(r,t);return this.cacheResponse(r,i,void 0,s)}async getAll(e,t={},s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),c=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,u=await this.makeRequest(n,t,i,l,r),a=u.total?Math.ceil(u.total/(u.perPage||i)):1,y=await ue(ce(l,a),m=>this.makeRequest(n,t,i,m+1,r));return he([u,...y],m=>Object.values(m.data[c]))}post(e,t={},s){const r=`/${e}`;return this.throttle("post",r,t,s)}put(e,t={},s){const r=`/${e}`;return this.throttle("put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`;return this.throttle("delete",r,t,s)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];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]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(s,r):Array.isArray(r)&&(e[t]=r.map(i=>this.getStoryReference(s,i)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(c=>c.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(i,n="")=>{if(!(!i||i._stopResolving)){if(Array.isArray(i))i.forEach((c,l)=>r(c,`${n}[${l}]`));else if(typeof i=="object")for(const c in i){const l=n?`${n}.${c}`:c;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,c,t,s),this._insertLinks(i,c,s)),r(i[c],l)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],c=50;for(let l=0;l<i;l+=c){const u=Math.min(i,l+c);n.push(e.link_uuids.slice(l,u))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(a=>{r.push(a)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],c=50;for(let l=0;l<i;l+=c){const u=Math.min(i,l+c);n.push(e.rel_uuids.slice(l,u))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(a=>{r.push(a)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var i,n;let r=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(r=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((i=e.links)!=null&&i.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(c=>{this.iterateTree(c,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=$({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await n.get(i);if(c)return Promise.resolve(c)}return new Promise(async(c,l)=>{var u;try{const a=await this.throttle("get",e,t,r);if(a.status!==200)return l(a);let y={data:a.data,headers:a.headers};if((u=a.headers)!=null&&u["per-page"]&&(y=Object.assign({},y,{perPage:a.headers["per-page"]?Number.parseInt(a.headers["per-page"]):0,total:a.headers["per-page"]?Number.parseInt(a.headers.total):0})),y.data.story||y.data.stories){const A=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${A}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(i,y);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(m&&T[t.token]&&T[t.token]!==y.data.cv&&await this.flushCache(),T[t.token]=y.data.cv),c(y)}catch(a){if(a.response&&a.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await le(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(l);l(a)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return T}cacheVersion(){return T[this.accessToken]}setCacheVersion(e){this.accessToken&&(T[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(T[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(I[e])},getAll(){return Promise.resolve(I)},set(e,t){return I[e]=t,Promise.resolve(void 0)},flush(){return I={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=s=>{if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>t(i));let r={...s};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...r,...e.data.assets.find(i=>i.id===r.id)});for(const i in r)typeof r[i]=="object"&&(r[i]=t(r[i]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(s=>(s.content=t(s.content),s))),e}},be=ge;const pe=(e={})=>{const{apiOptions:t}=e;if(!t||!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 be(t)}},me=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let j="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(e,t,s={})=>{var l;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((l=window.location)==null?void 0:l.href).searchParams.get("_storyblok"),c=n!==null&&+n===e;if(!(!i||!c)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(s).on(["input","published","change"],a=>{var y;a&&(a.action==="input"&&((y=a.story)==null?void 0:y.id)===e?t(a.story):(a.action==="change"||a.action==="published")&&a.storyId===e&&window.location.reload())})})}},ve=(e={})=>{var y,m;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const c={bridge:t,apiOptions:i};let l={};r.forEach(A=>{l={...l,...A(c)}}),n&&(j=n);const a=!(typeof window>"u")&&((m=(y=window.location)==null?void 0:y.search)==null?void 0:m.includes("_storyblok_tk"));return t!==!1&&a&&q(j),l};function Re(e,t){return z(t).render(e)}const ke=()=>q(j);R.BlockTypes=g,R.MarkTypes=w,R.TextTypes=B,R.apiPlugin=pe,R.loadStoryblokBridge=ke,R.registerStoryblokBridge=K,R.renderRichText=Re,R.richTextResolver=z,R.storyblokEditable=me,R.storyblokInit=ve,R.useStoryblokBridge=K,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
let
|
|
7
|
+
var se = Object.defineProperty;
|
|
8
|
+
var ie = (e, t, s) => t in e ? se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
9
|
+
var m = (e, t, s) => ie(e, typeof t != "symbol" ? t + "" : t, s);
|
|
10
|
+
let R = /* @__PURE__ */ function(e) {
|
|
11
11
|
return e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e.TABLE = "table", e.TABLE_ROW = "tableRow", e.TABLE_CELL = "tableCell", e.TABLE_HEADER = "tableHeader", e;
|
|
12
|
-
}({}),
|
|
12
|
+
}({}), _ = /* @__PURE__ */ function(e) {
|
|
13
13
|
return e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e;
|
|
14
|
-
}({}),
|
|
14
|
+
}({}), ne = /* @__PURE__ */ function(e) {
|
|
15
15
|
return e.TEXT = "text", e;
|
|
16
|
-
}({}),
|
|
16
|
+
}({}), P = /* @__PURE__ */ function(e) {
|
|
17
17
|
return e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e;
|
|
18
18
|
}({});
|
|
19
|
-
const
|
|
19
|
+
const oe = [
|
|
20
20
|
"area",
|
|
21
21
|
"base",
|
|
22
22
|
"br",
|
|
@@ -31,225 +31,243 @@ const ne = [
|
|
|
31
31
|
"source",
|
|
32
32
|
"track",
|
|
33
33
|
"wbr"
|
|
34
|
-
],
|
|
35
|
-
function
|
|
34
|
+
], le = (e = {}) => Object.keys(e).map((t) => `${t}="${e[t]}"`).join(" "), ae = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
|
|
35
|
+
function ce(e) {
|
|
36
36
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
37
37
|
}
|
|
38
|
-
const
|
|
39
|
-
function
|
|
38
|
+
const O = (e) => Object.fromEntries(Object.entries(e).filter(([t, s]) => s !== void 0));
|
|
39
|
+
function ue(e, t) {
|
|
40
40
|
if (!t) return {
|
|
41
41
|
src: e,
|
|
42
42
|
attrs: {}
|
|
43
43
|
};
|
|
44
44
|
let s = 0, r = 0;
|
|
45
45
|
const i = {}, n = [];
|
|
46
|
-
function
|
|
47
|
-
typeof u != "number" || u <=
|
|
46
|
+
function c(u, a, g, p, S) {
|
|
47
|
+
typeof u != "number" || u <= a || u >= g ? console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase() + p.slice(1)} value must be a number between ${a} and ${g} (inclusive)`) : S.push(`${p}(${u})`);
|
|
48
48
|
}
|
|
49
49
|
if (typeof t == "object") {
|
|
50
50
|
if (typeof t.width == "number" && t.width > 0 ? (i.width = t.width, s = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), t.height && typeof t.height == "number" && t.height > 0 ? (i.height = t.height, r = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), t.loading && ["lazy", "eager"].includes(t.loading) && (i.loading = t.loading), t.class && (i.class = t.class), t.filters) {
|
|
51
|
-
const { filters: u } = t || {}, { blur:
|
|
52
|
-
|
|
51
|
+
const { filters: u } = t || {}, { blur: a, brightness: g, fill: p, format: S, grayscale: x, quality: w, rotate: T } = u || {};
|
|
52
|
+
a && c(a, 0, 100, "blur", n), w && c(w, 0, 100, "quality", n), g && c(g, 0, 100, "brightness", n), p && n.push(`fill(${p})`), x && n.push("grayscale()"), T && [
|
|
53
53
|
0,
|
|
54
54
|
90,
|
|
55
55
|
180,
|
|
56
56
|
270
|
|
57
|
-
].includes(t.filters.rotate || 0) && n.push(`rotate(${
|
|
57
|
+
].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`), S && [
|
|
58
58
|
"webp",
|
|
59
59
|
"png",
|
|
60
60
|
"jpeg"
|
|
61
|
-
].includes(
|
|
61
|
+
].includes(S) && n.push(`format(${S})`);
|
|
62
62
|
}
|
|
63
63
|
t.srcset && (i.srcset = t.srcset.map((u) => {
|
|
64
64
|
if (typeof u == "number") return `${e}/m/${u}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${u}w`;
|
|
65
65
|
if (Array.isArray(u) && u.length === 2) {
|
|
66
|
-
const [
|
|
67
|
-
return `${e}/m/${
|
|
66
|
+
const [a, g] = u;
|
|
67
|
+
return `${e}/m/${a}x${g}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
|
|
68
68
|
} else {
|
|
69
69
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
}).join(", ")), t.sizes && (i.sizes = t.sizes.join(", "));
|
|
73
73
|
}
|
|
74
|
-
let
|
|
75
|
-
return s > 0 && r > 0 && (
|
|
76
|
-
src:
|
|
74
|
+
let l = `${e}/m/`;
|
|
75
|
+
return s > 0 && r > 0 && (l = `${l}${s}x${r}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
|
|
76
|
+
src: l,
|
|
77
77
|
attrs: i
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
const r =
|
|
80
|
+
function z(e, t = {}, s) {
|
|
81
|
+
const r = le(t), i = r ? `${e} ${r}` : e, n = Array.isArray(s) ? s.join("") : s || "";
|
|
82
82
|
if (e) {
|
|
83
|
-
if (
|
|
83
|
+
if (oe.includes(e)) return `<${i}>`;
|
|
84
84
|
} else return n;
|
|
85
85
|
return `<${i}>${n}</${e}>`;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const t = /* @__PURE__ */ new Map(), { renderFn: s =
|
|
89
|
-
const y =
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
function he(e = {}) {
|
|
88
|
+
const t = /* @__PURE__ */ new Map(), { renderFn: s = z, textFn: r = ce, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: c = !1 } = e, l = s !== z, u = (o = {}) => {
|
|
89
|
+
const { textAlign: h, class: d, id: f, style: y, ...v } = o, b = [];
|
|
90
|
+
return y && b.push(y.endsWith(";") ? y : `${y};`), h && b.push(`text-align: ${h};`), O({
|
|
91
|
+
...v,
|
|
92
|
+
class: d,
|
|
93
|
+
id: f,
|
|
94
|
+
...b.length > 0 ? { style: b.join(" ") } : {}
|
|
95
|
+
});
|
|
96
|
+
}, a = (o) => (h, d) => {
|
|
97
|
+
const f = u(h.attrs);
|
|
98
|
+
return d.render(o, f, h.children || null);
|
|
99
|
+
}, g = (o, h) => {
|
|
100
|
+
const { src: d, alt: f, title: y, srcset: v, sizes: b } = o.attrs || {};
|
|
101
|
+
let A = d, k = {};
|
|
94
102
|
if (n) {
|
|
95
|
-
const { src:
|
|
96
|
-
|
|
103
|
+
const { src: te, attrs: re } = ue(d, n);
|
|
104
|
+
A = te, k = re;
|
|
97
105
|
}
|
|
98
|
-
const
|
|
99
|
-
src:
|
|
100
|
-
alt:
|
|
101
|
-
title:
|
|
102
|
-
srcset:
|
|
103
|
-
sizes:
|
|
106
|
+
const L = {
|
|
107
|
+
src: A,
|
|
108
|
+
alt: f,
|
|
109
|
+
title: y,
|
|
110
|
+
srcset: v,
|
|
111
|
+
sizes: b,
|
|
104
112
|
...k
|
|
105
113
|
};
|
|
106
|
-
return
|
|
107
|
-
},
|
|
108
|
-
const { level:
|
|
109
|
-
return
|
|
110
|
-
},
|
|
111
|
-
var
|
|
112
|
-
const
|
|
113
|
-
src: (
|
|
114
|
-
alt: (
|
|
114
|
+
return h.render("img", O(L));
|
|
115
|
+
}, p = (o, h) => {
|
|
116
|
+
const { level: d, ...f } = o.attrs || {}, y = u(f);
|
|
117
|
+
return h.render(`h${d}`, y, o.children);
|
|
118
|
+
}, S = (o, h) => {
|
|
119
|
+
var f, y, v, b;
|
|
120
|
+
const d = h.render("img", {
|
|
121
|
+
src: (f = o.attrs) == null ? void 0 : f.fallbackImage,
|
|
122
|
+
alt: (y = o.attrs) == null ? void 0 : y.alt,
|
|
115
123
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
116
124
|
draggable: "false",
|
|
117
125
|
loading: "lazy"
|
|
118
126
|
});
|
|
119
|
-
return
|
|
127
|
+
return h.render("span", {
|
|
120
128
|
"data-type": "emoji",
|
|
121
|
-
"data-name": (
|
|
122
|
-
"data-emoji": (
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
const { class:
|
|
126
|
-
class:
|
|
127
|
-
id:
|
|
128
|
-
style: ae(
|
|
129
|
-
} :
|
|
130
|
-
return
|
|
131
|
-
}, T = (o) => N(o),
|
|
132
|
-
const { marks:
|
|
129
|
+
"data-name": (v = o.attrs) == null ? void 0 : v.name,
|
|
130
|
+
"data-emoji": (b = o.attrs) == null ? void 0 : b.emoji
|
|
131
|
+
}, d);
|
|
132
|
+
}, x = (o, h) => h.render("pre", o.attrs || {}, h.render("code", {}, o.children || "")), w = (o, h = !1) => ({ text: d, attrs: f }, y) => {
|
|
133
|
+
const { class: v, id: b, ...A } = f || {}, k = h ? {
|
|
134
|
+
class: v,
|
|
135
|
+
id: b,
|
|
136
|
+
style: ae(A) || void 0
|
|
137
|
+
} : f || {};
|
|
138
|
+
return y.render(o, O(k), d);
|
|
139
|
+
}, T = (o) => N(o), K = (o) => {
|
|
140
|
+
const { marks: h, ...d } = o;
|
|
133
141
|
if ("text" in o) {
|
|
134
|
-
if (
|
|
135
|
-
...
|
|
136
|
-
text:
|
|
142
|
+
if (h) return h.reduce((y, v) => T({
|
|
143
|
+
...v,
|
|
144
|
+
text: y
|
|
137
145
|
}), T({
|
|
138
|
-
...
|
|
139
|
-
children:
|
|
146
|
+
...d,
|
|
147
|
+
children: d.children
|
|
140
148
|
}));
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
t.set("txt",
|
|
149
|
+
const f = o.attrs || {};
|
|
150
|
+
if (c) {
|
|
151
|
+
const y = t.get("txt") || 0;
|
|
152
|
+
t.set("txt", y + 1), f.key = `txt-${y}`;
|
|
145
153
|
}
|
|
146
|
-
return r(
|
|
154
|
+
return r(d.text, f);
|
|
147
155
|
}
|
|
148
156
|
return "";
|
|
149
|
-
},
|
|
150
|
-
const { linktype:
|
|
151
|
-
let
|
|
152
|
-
switch (
|
|
153
|
-
case
|
|
154
|
-
case
|
|
155
|
-
|
|
157
|
+
}, U = (o, h) => {
|
|
158
|
+
const { linktype: d, href: f, anchor: y, ...v } = o.attrs || {};
|
|
159
|
+
let b = "";
|
|
160
|
+
switch (d) {
|
|
161
|
+
case P.ASSET:
|
|
162
|
+
case P.URL:
|
|
163
|
+
b = f;
|
|
156
164
|
break;
|
|
157
|
-
case
|
|
158
|
-
|
|
165
|
+
case P.EMAIL:
|
|
166
|
+
b = `mailto:${f}`;
|
|
159
167
|
break;
|
|
160
|
-
case
|
|
161
|
-
|
|
168
|
+
case P.STORY:
|
|
169
|
+
b = f, y && (b = `${b}#${y}`);
|
|
162
170
|
break;
|
|
163
171
|
default:
|
|
164
|
-
|
|
172
|
+
b = f;
|
|
165
173
|
break;
|
|
166
174
|
}
|
|
167
|
-
const
|
|
168
|
-
return
|
|
169
|
-
},
|
|
170
|
-
var
|
|
171
|
-
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),
|
|
172
|
-
blok: (
|
|
173
|
-
id: (
|
|
175
|
+
const A = { ...v };
|
|
176
|
+
return b && (A.href = b), h.render("a", A, o.text);
|
|
177
|
+
}, Y = (o, h) => {
|
|
178
|
+
var d, f;
|
|
179
|
+
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
|
|
180
|
+
blok: (d = o == null ? void 0 : o.attrs) == null ? void 0 : d.body[0],
|
|
181
|
+
id: (f = o.attrs) == null ? void 0 : f.id,
|
|
174
182
|
style: "display: none"
|
|
175
183
|
});
|
|
176
|
-
},
|
|
177
|
-
const
|
|
178
|
-
return
|
|
179
|
-
},
|
|
180
|
-
const
|
|
181
|
-
return
|
|
182
|
-
},
|
|
183
|
-
const { colspan:
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
[
|
|
204
|
-
[
|
|
205
|
-
[
|
|
206
|
-
[
|
|
207
|
-
[
|
|
208
|
-
[
|
|
209
|
-
[
|
|
210
|
-
[
|
|
211
|
-
[
|
|
212
|
-
[
|
|
213
|
-
[
|
|
214
|
-
[
|
|
215
|
-
[
|
|
216
|
-
[
|
|
217
|
-
[
|
|
218
|
-
[
|
|
219
|
-
[
|
|
220
|
-
[
|
|
221
|
-
[
|
|
222
|
-
[
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
184
|
+
}, W = (o, h) => {
|
|
185
|
+
const d = u(o.attrs), f = o.children || null;
|
|
186
|
+
return h.render("table", d, h.render("tbody", {}, f));
|
|
187
|
+
}, X = (o, h) => {
|
|
188
|
+
const d = u(o.attrs);
|
|
189
|
+
return h.render("tr", d, o.children);
|
|
190
|
+
}, Q = (o, h) => {
|
|
191
|
+
const { colspan: d, rowspan: f, colwidth: y, backgroundColor: v, textAlign: b, ...A } = o.attrs || {}, k = [];
|
|
192
|
+
y && k.push(`width: ${y}px;`), v && k.push(`background-color: ${v};`), b && k.push(`text-align: ${b};`);
|
|
193
|
+
const L = {
|
|
194
|
+
...A,
|
|
195
|
+
...d > 1 ? { colspan: d } : {},
|
|
196
|
+
...f > 1 ? { rowspan: f } : {},
|
|
197
|
+
...k.length > 0 ? { style: k.join(" ") } : {}
|
|
198
|
+
};
|
|
199
|
+
return h.render("td", O(L), o.children);
|
|
200
|
+
}, Z = (o, h) => {
|
|
201
|
+
const { colspan: d, rowspan: f, colwidth: y, backgroundColor: v, textAlign: b, ...A } = o.attrs || {}, k = [];
|
|
202
|
+
y && k.push(`width: ${y}px;`), v && k.push(`background-color: ${v};`), b && k.push(`text-align: ${b};`);
|
|
203
|
+
const L = {
|
|
204
|
+
...A,
|
|
205
|
+
...d > 1 ? { colspan: d } : {},
|
|
206
|
+
...f > 1 ? { rowspan: f } : {},
|
|
207
|
+
...k.length > 0 ? { style: k.join(" ") } : {}
|
|
208
|
+
};
|
|
209
|
+
return h.render("th", O(L), o.children);
|
|
210
|
+
}, B = /* @__PURE__ */ new Map([
|
|
211
|
+
[R.DOCUMENT, a("")],
|
|
212
|
+
[R.HEADING, p],
|
|
213
|
+
[R.PARAGRAPH, a("p")],
|
|
214
|
+
[R.UL_LIST, a("ul")],
|
|
215
|
+
[R.OL_LIST, a("ol")],
|
|
216
|
+
[R.LIST_ITEM, a("li")],
|
|
217
|
+
[R.IMAGE, g],
|
|
218
|
+
[R.EMOJI, S],
|
|
219
|
+
[R.CODE_BLOCK, x],
|
|
220
|
+
[R.HR, a("hr")],
|
|
221
|
+
[R.BR, a("br")],
|
|
222
|
+
[R.QUOTE, a("blockquote")],
|
|
223
|
+
[R.COMPONENT, Y],
|
|
224
|
+
[ne.TEXT, K],
|
|
225
|
+
[_.LINK, U],
|
|
226
|
+
[_.ANCHOR, U],
|
|
227
|
+
[_.STYLED, w("span", !0)],
|
|
228
|
+
[_.BOLD, w("strong")],
|
|
229
|
+
[_.TEXT_STYLE, w("span", !0)],
|
|
230
|
+
[_.ITALIC, w("em")],
|
|
231
|
+
[_.UNDERLINE, w("u")],
|
|
232
|
+
[_.STRIKE, w("s")],
|
|
233
|
+
[_.CODE, w("code")],
|
|
234
|
+
[_.SUPERSCRIPT, w("sup")],
|
|
235
|
+
[_.SUBSCRIPT, w("sub")],
|
|
236
|
+
[_.HIGHLIGHT, w("mark")],
|
|
237
|
+
[R.TABLE, W],
|
|
238
|
+
[R.TABLE_ROW, X],
|
|
239
|
+
[R.TABLE_CELL, Q],
|
|
240
|
+
[R.TABLE_HEADER, Z]
|
|
241
|
+
]), F = new Map([...B, ...Object.entries(i).map(([o, h]) => [o, h])]), ee = () => ({
|
|
242
|
+
render: (d, f = {}, y) => {
|
|
243
|
+
if (c && d) {
|
|
244
|
+
const v = t.get(d) || 0;
|
|
245
|
+
t.set(d, v + 1), f.key = `${d}-${v}`;
|
|
228
246
|
}
|
|
229
|
-
return s(
|
|
247
|
+
return s(d, f, y);
|
|
230
248
|
},
|
|
231
|
-
originalResolvers:
|
|
232
|
-
mergedResolvers:
|
|
249
|
+
originalResolvers: B,
|
|
250
|
+
mergedResolvers: F
|
|
233
251
|
});
|
|
234
|
-
function
|
|
235
|
-
const
|
|
236
|
-
if (!
|
|
252
|
+
function C(o) {
|
|
253
|
+
const h = F.get(o.type);
|
|
254
|
+
if (!h)
|
|
237
255
|
return console.error("<Storyblok>", `No resolver found for node type ${o.type}`), "";
|
|
238
|
-
const
|
|
239
|
-
if (o.type === "text") return
|
|
240
|
-
const
|
|
241
|
-
return
|
|
256
|
+
const d = ee();
|
|
257
|
+
if (o.type === "text") return h(o, d);
|
|
258
|
+
const f = o.content ? o.content.map(N) : void 0;
|
|
259
|
+
return h({
|
|
242
260
|
...o,
|
|
243
|
-
children:
|
|
244
|
-
},
|
|
261
|
+
children: f
|
|
262
|
+
}, d);
|
|
245
263
|
}
|
|
246
264
|
function N(o) {
|
|
247
|
-
return o.type === "doc" ?
|
|
265
|
+
return o.type === "doc" ? l ? o.content.map(C) : o.content.map(C).join("") : Array.isArray(o) ? o.map(C) : C(o);
|
|
248
266
|
}
|
|
249
267
|
return { render: N };
|
|
250
268
|
}
|
|
251
|
-
let
|
|
252
|
-
const
|
|
269
|
+
let G = !1;
|
|
270
|
+
const q = [], J = (e) => new Promise((t, s) => {
|
|
253
271
|
if (typeof window > "u") {
|
|
254
272
|
s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
255
273
|
return;
|
|
@@ -259,70 +277,70 @@ const G = [], M = (e) => new Promise((t, s) => {
|
|
|
259
277
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
260
278
|
return;
|
|
261
279
|
}
|
|
262
|
-
|
|
280
|
+
G ? i() : q.push(i);
|
|
263
281
|
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
264
282
|
t(void 0);
|
|
265
283
|
return;
|
|
266
284
|
}
|
|
267
285
|
const r = document.createElement("script");
|
|
268
286
|
r.async = !0, r.src = e, r.id = "storyblok-javascript-bridge", r.onerror = (i) => s(i), r.onload = (i) => {
|
|
269
|
-
|
|
287
|
+
q.forEach((n) => n()), G = !0, t(i);
|
|
270
288
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
271
289
|
});
|
|
272
|
-
var
|
|
290
|
+
var de = class extends Error {
|
|
273
291
|
constructor(e) {
|
|
274
292
|
super(e), this.name = "AbortError";
|
|
275
293
|
}
|
|
276
294
|
};
|
|
277
|
-
function
|
|
295
|
+
function fe(e, t, s) {
|
|
278
296
|
if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
|
|
279
297
|
if (!Number.isFinite(s)) throw new TypeError("Expected `interval` to be a finite number");
|
|
280
298
|
const r = [];
|
|
281
|
-
let i = [], n = 0,
|
|
282
|
-
const
|
|
299
|
+
let i = [], n = 0, c = !1;
|
|
300
|
+
const l = async () => {
|
|
283
301
|
n++;
|
|
284
|
-
const
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
} catch (
|
|
289
|
-
|
|
302
|
+
const a = r.shift();
|
|
303
|
+
if (a) try {
|
|
304
|
+
const p = await e(...a.args);
|
|
305
|
+
a.resolve(p);
|
|
306
|
+
} catch (p) {
|
|
307
|
+
a.reject(p);
|
|
290
308
|
}
|
|
291
|
-
const
|
|
292
|
-
n--, r.length > 0 &&
|
|
309
|
+
const g = setTimeout(() => {
|
|
310
|
+
n--, r.length > 0 && l(), i = i.filter((p) => p !== g);
|
|
293
311
|
}, s);
|
|
294
|
-
i.includes(
|
|
295
|
-
}, u = (...
|
|
312
|
+
i.includes(g) || i.push(g);
|
|
313
|
+
}, u = (...a) => c ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((g, p) => {
|
|
296
314
|
r.push({
|
|
297
|
-
resolve:
|
|
298
|
-
reject:
|
|
299
|
-
args:
|
|
300
|
-
}), n < t &&
|
|
315
|
+
resolve: g,
|
|
316
|
+
reject: p,
|
|
317
|
+
args: a
|
|
318
|
+
}), n < t && l();
|
|
301
319
|
});
|
|
302
320
|
return u.abort = () => {
|
|
303
|
-
|
|
321
|
+
c = !0, i.forEach(clearTimeout), i = [], r.forEach((a) => a.reject(() => new de("Throttle function aborted"))), r.length = 0;
|
|
304
322
|
}, u;
|
|
305
323
|
}
|
|
306
|
-
var
|
|
307
|
-
const
|
|
324
|
+
var ge = fe;
|
|
325
|
+
const V = (e = "") => e.includes("/cdn/"), ye = (e, t = 25, s = 1) => ({
|
|
308
326
|
...e,
|
|
309
327
|
per_page: t,
|
|
310
328
|
page: s
|
|
311
|
-
}),
|
|
329
|
+
}), be = (e) => new Promise((t) => setTimeout(t, e)), pe = (e = 0, t) => Array.from({ length: e }, t), me = (e = 0, t = e) => {
|
|
312
330
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
313
|
-
return
|
|
314
|
-
},
|
|
331
|
+
return pe(s, (i, n) => n * r + e);
|
|
332
|
+
}, ve = async (e, t) => Promise.all(e.map(t)), Re = (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []), j = (e, t, s) => {
|
|
315
333
|
const r = [];
|
|
316
334
|
for (const i in e) {
|
|
317
335
|
if (!Object.prototype.hasOwnProperty.call(e, i)) continue;
|
|
318
336
|
const n = e[i];
|
|
319
337
|
if (n == null) continue;
|
|
320
|
-
const
|
|
321
|
-
let
|
|
322
|
-
typeof n == "object" ?
|
|
338
|
+
const c = s ? "" : encodeURIComponent(i);
|
|
339
|
+
let l;
|
|
340
|
+
typeof n == "object" ? l = j(n, t ? t + encodeURIComponent(`[${c}]`) : c, Array.isArray(n)) : l = `${t ? t + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(n)}`, r.push(l);
|
|
323
341
|
}
|
|
324
342
|
return r.join("&");
|
|
325
|
-
},
|
|
343
|
+
}, D = (e) => {
|
|
326
344
|
const t = {
|
|
327
345
|
eu: "api.storyblok.com",
|
|
328
346
|
us: "api-us.storyblok.com",
|
|
@@ -332,17 +350,17 @@ const q = (e = "") => e.includes("/cdn/"), ye = (e, t = 25, s = 1) => ({
|
|
|
332
350
|
};
|
|
333
351
|
return t[e] ?? t.eu;
|
|
334
352
|
};
|
|
335
|
-
var
|
|
353
|
+
var ke = class {
|
|
336
354
|
constructor(e) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
355
|
+
m(this, "baseURL");
|
|
356
|
+
m(this, "timeout");
|
|
357
|
+
m(this, "headers");
|
|
358
|
+
m(this, "responseInterceptor");
|
|
359
|
+
m(this, "fetch");
|
|
360
|
+
m(this, "ejectInterceptor");
|
|
361
|
+
m(this, "url");
|
|
362
|
+
m(this, "parameters");
|
|
363
|
+
m(this, "fetchOptions");
|
|
346
364
|
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 = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
347
365
|
}
|
|
348
366
|
/**
|
|
@@ -378,23 +396,23 @@ var Re = class {
|
|
|
378
396
|
}
|
|
379
397
|
async _methodHandler(e) {
|
|
380
398
|
let t = `${this.baseURL}${this.url}`, s = null;
|
|
381
|
-
e === "get" ? t = `${this.baseURL}${this.url}?${
|
|
399
|
+
e === "get" ? t = `${this.baseURL}${this.url}?${j(this.parameters)}` : s = JSON.stringify(this.parameters);
|
|
382
400
|
const r = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
383
|
-
let
|
|
384
|
-
this.timeout && (
|
|
401
|
+
let c;
|
|
402
|
+
this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
|
|
385
403
|
try {
|
|
386
|
-
const
|
|
404
|
+
const l = await this.fetch(`${r}`, {
|
|
387
405
|
method: e,
|
|
388
406
|
headers: this.headers,
|
|
389
407
|
body: s,
|
|
390
408
|
signal: n,
|
|
391
409
|
...this.fetchOptions
|
|
392
410
|
});
|
|
393
|
-
this.timeout && clearTimeout(
|
|
394
|
-
const u = await this._responseHandler(
|
|
411
|
+
this.timeout && clearTimeout(c);
|
|
412
|
+
const u = await this._responseHandler(l);
|
|
395
413
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(u)) : this._statusHandler(u);
|
|
396
|
-
} catch (
|
|
397
|
-
return { message:
|
|
414
|
+
} catch (l) {
|
|
415
|
+
return { message: l };
|
|
398
416
|
}
|
|
399
417
|
}
|
|
400
418
|
setFetchOptions(e = {}) {
|
|
@@ -432,52 +450,52 @@ var Re = class {
|
|
|
432
450
|
r(i);
|
|
433
451
|
});
|
|
434
452
|
}
|
|
435
|
-
}, we =
|
|
436
|
-
const
|
|
453
|
+
}, we = ke;
|
|
454
|
+
const M = "SB-Agent", $ = {
|
|
437
455
|
defaultAgentName: "SB-JS-CLIENT",
|
|
438
456
|
defaultAgentVersion: "SB-Agent-Version",
|
|
439
457
|
packageVersion: "7.0.0"
|
|
440
|
-
},
|
|
458
|
+
}, _e = {
|
|
441
459
|
PUBLISHED: "published"
|
|
442
460
|
};
|
|
443
461
|
let I = {};
|
|
444
|
-
const
|
|
445
|
-
var
|
|
462
|
+
const E = {};
|
|
463
|
+
var Se = class {
|
|
446
464
|
/**
|
|
447
465
|
*
|
|
448
466
|
* @param config ISbConfig interface
|
|
449
467
|
* @param pEndpoint string, optional
|
|
450
468
|
*/
|
|
451
469
|
constructor(e, t) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
470
|
+
m(this, "client");
|
|
471
|
+
m(this, "maxRetries");
|
|
472
|
+
m(this, "retriesDelay");
|
|
473
|
+
m(this, "throttle");
|
|
474
|
+
m(this, "accessToken");
|
|
475
|
+
m(this, "cache");
|
|
476
|
+
m(this, "resolveCounter");
|
|
477
|
+
m(this, "relations");
|
|
478
|
+
m(this, "links");
|
|
479
|
+
m(this, "version");
|
|
462
480
|
/**
|
|
463
481
|
* @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
|
|
464
482
|
* @see https://github.com/storyblok/richtext
|
|
465
483
|
*/
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
484
|
+
m(this, "richTextResolver");
|
|
485
|
+
m(this, "resolveNestedRelations");
|
|
486
|
+
m(this, "stringifiedStoriesCache");
|
|
487
|
+
m(this, "inlineAssets");
|
|
470
488
|
let s = e.endpoint || t;
|
|
471
489
|
if (!s) {
|
|
472
490
|
const n = e.https === !1 ? "http" : "https";
|
|
473
|
-
e.oauthToken ? s = `${n}://${
|
|
491
|
+
e.oauthToken ? s = `${n}://${D(e.region)}/v1` : s = `${n}://${D(e.region)}/v2`;
|
|
474
492
|
}
|
|
475
493
|
const r = new Headers();
|
|
476
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([
|
|
477
|
-
r.set(
|
|
478
|
-
}), r.has(
|
|
494
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([c, l]) => {
|
|
495
|
+
r.set(c, l);
|
|
496
|
+
}), r.has(M) || (r.set(M, $.defaultAgentName), r.set($.defaultAgentVersion, $.packageVersion));
|
|
479
497
|
let i = 5;
|
|
480
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle =
|
|
498
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ge(this.throttledRequest.bind(this), i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || _e.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new we({
|
|
481
499
|
baseURL: s,
|
|
482
500
|
timeout: e.timeout || 0,
|
|
483
501
|
headers: r,
|
|
@@ -486,10 +504,10 @@ var _e = class {
|
|
|
486
504
|
});
|
|
487
505
|
}
|
|
488
506
|
parseParams(e) {
|
|
489
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
507
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
490
508
|
}
|
|
491
509
|
factoryParamOptions(e, t) {
|
|
492
|
-
return
|
|
510
|
+
return V(e) ? this.parseParams(t) : t;
|
|
493
511
|
}
|
|
494
512
|
makeRequest(e, t, s, r, i) {
|
|
495
513
|
const n = this.factoryParamOptions(e, ye(t, s, r));
|
|
@@ -498,15 +516,15 @@ var _e = class {
|
|
|
498
516
|
get(e, t = {}, s) {
|
|
499
517
|
t || (t = {});
|
|
500
518
|
const r = `/${e}`;
|
|
501
|
-
|
|
519
|
+
V(r) && (t.version = t.version || this.version);
|
|
502
520
|
const i = this.factoryParamOptions(r, t);
|
|
503
521
|
return this.cacheResponse(r, i, void 0, s);
|
|
504
522
|
}
|
|
505
523
|
async getAll(e, t = {}, s, r) {
|
|
506
|
-
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""),
|
|
524
|
+
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), c = s ?? n.substring(n.lastIndexOf("/") + 1);
|
|
507
525
|
t.version = t.version || this.version;
|
|
508
|
-
const
|
|
509
|
-
return
|
|
526
|
+
const l = 1, u = await this.makeRequest(n, t, i, l, r), a = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, g = await ve(me(l, a), (p) => this.makeRequest(n, t, i, p + 1, r));
|
|
527
|
+
return Re([u, ...g], (p) => Object.values(p.data[c]));
|
|
510
528
|
}
|
|
511
529
|
post(e, t = {}, s) {
|
|
512
530
|
const r = `/${e}`;
|
|
@@ -584,7 +602,7 @@ var _e = class {
|
|
|
584
602
|
* allowing flexible specification of relation patterns.
|
|
585
603
|
*/
|
|
586
604
|
_insertRelations(e, t, s, r) {
|
|
587
|
-
if (Array.isArray(s) ? s.find((
|
|
605
|
+
if (Array.isArray(s) ? s.find((c) => c.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
|
|
588
606
|
this._resolveField(e, t, r);
|
|
589
607
|
return;
|
|
590
608
|
}
|
|
@@ -600,10 +618,10 @@ var _e = class {
|
|
|
600
618
|
iterateTree(e, t, s) {
|
|
601
619
|
const r = (i, n = "") => {
|
|
602
620
|
if (!(!i || i._stopResolving)) {
|
|
603
|
-
if (Array.isArray(i)) i.forEach((
|
|
604
|
-
else if (typeof i == "object") for (const
|
|
605
|
-
const
|
|
606
|
-
(i.component && i._uid || i.type === "link") && (this._insertRelations(i,
|
|
621
|
+
if (Array.isArray(i)) i.forEach((c, l) => r(c, `${n}[${l}]`));
|
|
622
|
+
else if (typeof i == "object") for (const c in i) {
|
|
623
|
+
const l = n ? `${n}.${c}` : c;
|
|
624
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(i, c, t, s), this._insertLinks(i, c, s)), r(i[c], l);
|
|
607
625
|
}
|
|
608
626
|
}
|
|
609
627
|
};
|
|
@@ -612,20 +630,20 @@ var _e = class {
|
|
|
612
630
|
async resolveLinks(e, t, s) {
|
|
613
631
|
let r = [];
|
|
614
632
|
if (e.link_uuids) {
|
|
615
|
-
const i = e.link_uuids.length, n = [],
|
|
616
|
-
for (let
|
|
617
|
-
const u = Math.min(i,
|
|
618
|
-
n.push(e.link_uuids.slice(
|
|
633
|
+
const i = e.link_uuids.length, n = [], c = 50;
|
|
634
|
+
for (let l = 0; l < i; l += c) {
|
|
635
|
+
const u = Math.min(i, l + c);
|
|
636
|
+
n.push(e.link_uuids.slice(l, u));
|
|
619
637
|
}
|
|
620
|
-
for (let
|
|
638
|
+
for (let l = 0; l < n.length; l++)
|
|
621
639
|
(await this.getStories({
|
|
622
|
-
per_page:
|
|
640
|
+
per_page: c,
|
|
623
641
|
language: t.language,
|
|
624
642
|
version: t.version,
|
|
625
643
|
starts_with: t.starts_with,
|
|
626
|
-
by_uuids: n[
|
|
627
|
-
})).data.stories.forEach((
|
|
628
|
-
r.push(
|
|
644
|
+
by_uuids: n[l].join(",")
|
|
645
|
+
})).data.stories.forEach((a) => {
|
|
646
|
+
r.push(a);
|
|
629
647
|
});
|
|
630
648
|
} else r = e.links;
|
|
631
649
|
r.forEach((i) => {
|
|
@@ -638,21 +656,21 @@ var _e = class {
|
|
|
638
656
|
async resolveRelations(e, t, s) {
|
|
639
657
|
let r = [];
|
|
640
658
|
if (e.rel_uuids) {
|
|
641
|
-
const i = e.rel_uuids.length, n = [],
|
|
642
|
-
for (let
|
|
643
|
-
const u = Math.min(i,
|
|
644
|
-
n.push(e.rel_uuids.slice(
|
|
659
|
+
const i = e.rel_uuids.length, n = [], c = 50;
|
|
660
|
+
for (let l = 0; l < i; l += c) {
|
|
661
|
+
const u = Math.min(i, l + c);
|
|
662
|
+
n.push(e.rel_uuids.slice(l, u));
|
|
645
663
|
}
|
|
646
|
-
for (let
|
|
664
|
+
for (let l = 0; l < n.length; l++)
|
|
647
665
|
(await this.getStories({
|
|
648
|
-
per_page:
|
|
666
|
+
per_page: c,
|
|
649
667
|
language: t.language,
|
|
650
668
|
version: t.version,
|
|
651
669
|
starts_with: t.starts_with,
|
|
652
|
-
by_uuids: n[
|
|
670
|
+
by_uuids: n[l].join(","),
|
|
653
671
|
excluding_fields: t.excluding_fields
|
|
654
|
-
})).data.stories.forEach((
|
|
655
|
-
r.push(
|
|
672
|
+
})).data.stories.forEach((a) => {
|
|
673
|
+
r.push(a);
|
|
656
674
|
});
|
|
657
675
|
r.length > 0 && (e.rels = r, delete e.rel_uuids);
|
|
658
676
|
} else r = e.rels;
|
|
@@ -680,43 +698,43 @@ var _e = class {
|
|
|
680
698
|
"story",
|
|
681
699
|
"url",
|
|
682
700
|
"link"
|
|
683
|
-
].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations) for (const
|
|
684
|
-
e.story ? this.iterateTree(e.story, r, s) : e.stories.forEach((
|
|
685
|
-
this.iterateTree(
|
|
701
|
+
].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations) for (const c in this.relations[s]) this.iterateTree(this.relations[s][c], r, s);
|
|
702
|
+
e.story ? this.iterateTree(e.story, r, s) : e.stories.forEach((c) => {
|
|
703
|
+
this.iterateTree(c, r, s);
|
|
686
704
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
687
705
|
}
|
|
688
706
|
async cacheResponse(e, t, s, r) {
|
|
689
|
-
const i =
|
|
707
|
+
const i = j({
|
|
690
708
|
url: e,
|
|
691
709
|
params: t
|
|
692
710
|
}), n = this.cacheProvider();
|
|
693
711
|
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
694
|
-
const
|
|
695
|
-
if (
|
|
712
|
+
const c = await n.get(i);
|
|
713
|
+
if (c) return Promise.resolve(c);
|
|
696
714
|
}
|
|
697
|
-
return new Promise(async (
|
|
715
|
+
return new Promise(async (c, l) => {
|
|
698
716
|
var u;
|
|
699
717
|
try {
|
|
700
|
-
const
|
|
701
|
-
if (
|
|
702
|
-
let
|
|
703
|
-
data:
|
|
704
|
-
headers:
|
|
718
|
+
const a = await this.throttle("get", e, t, r);
|
|
719
|
+
if (a.status !== 200) return l(a);
|
|
720
|
+
let g = {
|
|
721
|
+
data: a.data,
|
|
722
|
+
headers: a.headers
|
|
705
723
|
};
|
|
706
|
-
if ((u =
|
|
707
|
-
perPage:
|
|
708
|
-
total:
|
|
709
|
-
})),
|
|
710
|
-
const
|
|
711
|
-
await this.resolveStories(
|
|
724
|
+
if ((u = a.headers) != null && u["per-page"] && (g = Object.assign({}, g, {
|
|
725
|
+
perPage: a.headers["per-page"] ? Number.parseInt(a.headers["per-page"]) : 0,
|
|
726
|
+
total: a.headers["per-page"] ? Number.parseInt(a.headers.total) : 0
|
|
727
|
+
})), g.data.story || g.data.stories) {
|
|
728
|
+
const S = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
729
|
+
await this.resolveStories(g.data, t, `${S}`), g = await this.processInlineAssets(g);
|
|
712
730
|
}
|
|
713
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i,
|
|
714
|
-
const
|
|
715
|
-
return t.token &&
|
|
716
|
-
} catch (
|
|
717
|
-
if (
|
|
718
|
-
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await
|
|
719
|
-
a
|
|
731
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, g);
|
|
732
|
+
const p = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
733
|
+
return t.token && g.data.cv && (p && E[t.token] && E[t.token] !== g.data.cv && await this.flushCache(), E[t.token] = g.data.cv), c(g);
|
|
734
|
+
} catch (a) {
|
|
735
|
+
if (a.response && a.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
736
|
+
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await be(this.retriesDelay), this.cacheResponse(e, t, s).then(c).catch(l);
|
|
737
|
+
l(a);
|
|
720
738
|
}
|
|
721
739
|
});
|
|
722
740
|
}
|
|
@@ -724,16 +742,16 @@ var _e = class {
|
|
|
724
742
|
return this.client.setFetchOptions(r), this.client[e](t, s);
|
|
725
743
|
}
|
|
726
744
|
cacheVersions() {
|
|
727
|
-
return
|
|
745
|
+
return E;
|
|
728
746
|
}
|
|
729
747
|
cacheVersion() {
|
|
730
|
-
return
|
|
748
|
+
return E[this.accessToken];
|
|
731
749
|
}
|
|
732
750
|
setCacheVersion(e) {
|
|
733
|
-
this.accessToken && (
|
|
751
|
+
this.accessToken && (E[this.accessToken] = e);
|
|
734
752
|
}
|
|
735
753
|
clearCacheVersion() {
|
|
736
|
-
this.accessToken && (
|
|
754
|
+
this.accessToken && (E[this.accessToken] = 0);
|
|
737
755
|
}
|
|
738
756
|
cacheProvider() {
|
|
739
757
|
switch (this.cache.type) {
|
|
@@ -789,8 +807,8 @@ var _e = class {
|
|
|
789
807
|
};
|
|
790
808
|
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((s) => (s.content = t(s.content), s))), e;
|
|
791
809
|
}
|
|
792
|
-
},
|
|
793
|
-
const
|
|
810
|
+
}, Ae = Se;
|
|
811
|
+
const Te = (e = {}) => {
|
|
794
812
|
const { apiOptions: t } = e;
|
|
795
813
|
if (!t || !t.accessToken) {
|
|
796
814
|
console.error(
|
|
@@ -798,8 +816,8 @@ const Ae = (e = {}) => {
|
|
|
798
816
|
);
|
|
799
817
|
return;
|
|
800
818
|
}
|
|
801
|
-
return { storyblokApi: new
|
|
802
|
-
},
|
|
819
|
+
return { storyblokApi: new Ae(t) };
|
|
820
|
+
}, Le = (e) => {
|
|
803
821
|
if (typeof e != "object" || typeof e._editable > "u")
|
|
804
822
|
return {};
|
|
805
823
|
try {
|
|
@@ -814,26 +832,26 @@ const Ae = (e = {}) => {
|
|
|
814
832
|
return {};
|
|
815
833
|
}
|
|
816
834
|
};
|
|
817
|
-
let
|
|
818
|
-
const
|
|
819
|
-
var
|
|
820
|
-
const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((
|
|
835
|
+
let H = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
836
|
+
const Oe = (e, t, s = {}) => {
|
|
837
|
+
var l;
|
|
838
|
+
const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
|
821
839
|
"_storyblok"
|
|
822
|
-
),
|
|
823
|
-
if (!(!i || !
|
|
840
|
+
), c = n !== null && +n === e;
|
|
841
|
+
if (!(!i || !c)) {
|
|
824
842
|
if (!e) {
|
|
825
843
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
826
844
|
return;
|
|
827
845
|
}
|
|
828
846
|
window.storyblokRegisterEvent(() => {
|
|
829
|
-
new window.StoryblokBridge(s).on(["input", "published", "change"], (
|
|
830
|
-
var
|
|
831
|
-
|
|
847
|
+
new window.StoryblokBridge(s).on(["input", "published", "change"], (a) => {
|
|
848
|
+
var g;
|
|
849
|
+
a && (a.action === "input" && ((g = a.story) == null ? void 0 : g.id) === e ? t(a.story) : (a.action === "change" || a.action === "published") && a.storyId === e && window.location.reload());
|
|
832
850
|
});
|
|
833
851
|
});
|
|
834
852
|
}
|
|
835
|
-
},
|
|
836
|
-
var
|
|
853
|
+
}, Ce = (e = {}) => {
|
|
854
|
+
var g, p;
|
|
837
855
|
const {
|
|
838
856
|
bridge: t,
|
|
839
857
|
accessToken: s,
|
|
@@ -842,28 +860,28 @@ const Le = (e, t, s = {}) => {
|
|
|
842
860
|
bridgeUrl: n
|
|
843
861
|
} = e;
|
|
844
862
|
i.accessToken = i.accessToken || s;
|
|
845
|
-
const
|
|
846
|
-
let
|
|
847
|
-
r.forEach((
|
|
848
|
-
|
|
849
|
-
}), n && (
|
|
850
|
-
const
|
|
851
|
-
return t !== !1 &&
|
|
863
|
+
const c = { bridge: t, apiOptions: i };
|
|
864
|
+
let l = {};
|
|
865
|
+
r.forEach((S) => {
|
|
866
|
+
l = { ...l, ...S(c) };
|
|
867
|
+
}), n && (H = n);
|
|
868
|
+
const a = !(typeof window > "u") && ((p = (g = window.location) == null ? void 0 : g.search) == null ? void 0 : p.includes("_storyblok_tk"));
|
|
869
|
+
return t !== !1 && a && J(H), l;
|
|
852
870
|
};
|
|
853
|
-
function
|
|
854
|
-
return
|
|
871
|
+
function Pe(e, t) {
|
|
872
|
+
return he(t).render(e);
|
|
855
873
|
}
|
|
856
|
-
const
|
|
874
|
+
const Ie = () => J(H);
|
|
857
875
|
export {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
876
|
+
R as BlockTypes,
|
|
877
|
+
_ as MarkTypes,
|
|
878
|
+
ne as TextTypes,
|
|
879
|
+
Te as apiPlugin,
|
|
880
|
+
Ie as loadStoryblokBridge,
|
|
881
|
+
Oe as registerStoryblokBridge,
|
|
882
|
+
Pe as renderRichText,
|
|
883
|
+
he as richTextResolver,
|
|
884
|
+
Le as storyblokEditable,
|
|
885
|
+
Ce as storyblokInit,
|
|
886
|
+
Oe as useStoryblokBridge
|
|
869
887
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.8",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@storyblok/richtext": "3.
|
|
31
|
+
"@storyblok/richtext": "3.8.0",
|
|
32
32
|
"storyblok-js-client": "7.1.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|