@storyblok/js 4.4.2 → 4.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +234 -234
- package/package.json +3 -3
package/dist/storyblok-js.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @storyblok/js
|
|
3
|
-
* (c)
|
|
3
|
+
* (c) 2026
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
(function(v,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(v=typeof globalThis<"u"?globalThis:v||self,b(v.storyblok={}))})(this,function(v){"use strict";var Be=Object.defineProperty;var De=(v,b,E)=>b in v?Be(v,b,{enumerable:!0,configurable:!0,writable:!0,value:E}):v[b]=E;var R=(v,b,E)=>De(v,typeof b!="symbol"?b+"":b,E);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}({}),E=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}({}),D=function(e){return e.TEXT="text",e}({}),N=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const ne=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],oe=(e={})=>{const{custom:t,...s}=e,r={...s,...t};return Object.keys(r).map(i=>`${i}="${r[i]}"`).join(" ")},ae=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function le(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const T=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function ce(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function l(u,c,f,y,S){typeof u!="number"||u<=c||u>=f?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${c} and ${f} (inclusive)`):S.push(`${y}(${u})`)}if(typeof t=="object"){if(t.width!==void 0&&(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 or equal to 0")),t.height!==void 0&&(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 or equal to 0")),t.height===0&&t.width===0&&(delete i.width,delete i.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 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:y,format:S,grayscale:O,quality:A,rotate:I}=u||{};c&&l(c,0,100,"blur",n),A&&l(A,0,100,"quality",n),f&&l(f,0,100,"brightness",n),y&&n.push(`fill(${y})`),O&&n.push("grayscale()"),I&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${I})`),S&&["webp","png","jpeg"].includes(S)&&n.push(`format(${S})`)}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 a=`${e}/m/`;return(s>0||r>0)&&(a=`${a}${s}x${r}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:i}}function z(e,t={},s){const r=oe(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(ne.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function V(e={}){const t=new Map,{renderFn:s=z,textFn:r=le,resolvers:i={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=s!==z,u=(o={})=>{const{textAlign:h,class:d,id:g,style:m,..._}=o,p=[];return m&&p.push(m.endsWith(";")?m:`${m};`),h&&p.push(`text-align: ${h};`),T({..._,class:d,id:g,...p.length>0?{style:p.join(" ")}:{}})},c=o=>(h,d)=>{const g=u(h.attrs);return d.render(o,g,h.children||null)},f=(o,h)=>{const{src:d,alt:g,title:m,srcset:_,sizes:p}=o.attrs||{};let w=d,k={};if(n){const{src:qe,attrs:Fe}=ce(d,n);w=qe,k=Fe}const P={src:w,alt:g,title:m,srcset:_,sizes:p,...k};return h.render("img",T(P))},y=(o,h)=>{const{level:d,...g}=o.attrs||{},m=u(g);return h.render(`h${d}`,m,o.children)},S=(o,h)=>{var g,m,_,p;const d=h.render("img",{src:(g=o.attrs)==null?void 0:g.fallbackImage,alt:(m=o.attrs)==null?void 0:m.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":(_=o.attrs)==null?void 0:_.name,"data-emoji":(p=o.attrs)==null?void 0:p.emoji},d)},O=(o,h)=>h.render("pre",o.attrs||{},h.render("code",{},o.children||"")),A=(o,h=!1)=>({text:d,attrs:g},m)=>{const{class:_,id:p,...w}=g||{},k=h?{class:_,id:p,style:ae(w)||void 0}:g||{};return m.render(o,T(k),d)},I=o=>B(o),xe=o=>{const{marks:h,...d}=o;if("text"in o){if(h)return h.reduce((m,_)=>I({..._,text:m}),I({...d,children:d.children}));const g=o.attrs||{};if(l){const m=t.get("txt")||0;t.set("txt",m+1),g.key=`txt-${m}`}return r(d.text,g)}return""},re=(o,h)=>{const{linktype:d,href:g,anchor:m,..._}=o.attrs||{};let p="";switch(d){case N.ASSET:case N.URL:p=g;break;case N.EMAIL:p=`mailto:${g}`;break;case N.STORY:p=g,m&&(p=`${p}#${m}`);break;default:p=g;break}const w={..._};return p&&(w.href=p),h.render("a",w,o.text)},He=(o,h)=>{var d,g;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:(g=o.attrs)==null?void 0:g.id,style:"display: none"})},Me=(o,h)=>{const d=u(o.attrs),g=o.children||null;return h.render("table",d,h.render("tbody",{},g))},Ue=(o,h)=>{const d=u(o.attrs);return h.render("tr",d,o.children)},$e=(o,h)=>{const{colspan:d,rowspan:g,colwidth:m,backgroundColor:_,textAlign:p,...w}=o.attrs||{},k=[];m&&k.push(`width: ${m}px;`),_&&k.push(`background-color: ${_};`),p&&k.push(`text-align: ${p};`);const P={...w,...d>1?{colspan:d}:{},...g>1?{rowspan:g}:{},...k.length>0?{style:k.join(" ")}:{}};return h.render("td",T(P),o.children)},je=(o,h)=>{const{colspan:d,rowspan:g,colwidth:m,backgroundColor:_,textAlign:p,...w}=o.attrs||{},k=[];m&&k.push(`width: ${m}px;`),_&&k.push(`background-color: ${_};`),p&&k.push(`text-align: ${p};`);const P={...w,...d>1?{colspan:d}:{},...g>1?{rowspan:g}:{},...k.length>0?{style:k.join(" ")}:{}};return h.render("th",T(P),o.children)},se=new Map([[b.DOCUMENT,c("")],[b.HEADING,y],[b.PARAGRAPH,c("p")],[b.UL_LIST,c("ul")],[b.OL_LIST,c("ol")],[b.LIST_ITEM,c("li")],[b.IMAGE,f],[b.EMOJI,S],[b.CODE_BLOCK,O],[b.HR,c("hr")],[b.BR,c("br")],[b.QUOTE,c("blockquote")],[b.COMPONENT,He],[D.TEXT,xe],[E.LINK,re],[E.ANCHOR,re],[E.STYLED,A("span",!0)],[E.BOLD,A("strong")],[E.TEXT_STYLE,A("span",!0)],[E.ITALIC,A("em")],[E.UNDERLINE,A("u")],[E.STRIKE,A("s")],[E.CODE,A("code")],[E.SUPERSCRIPT,A("sup")],[E.SUBSCRIPT,A("sub")],[E.HIGHLIGHT,A("mark")],[b.TABLE,Me],[b.TABLE_ROW,Ue],[b.TABLE_CELL,$e],[b.TABLE_HEADER,je]]),ie=new Map([...se,...Object.entries(i).map(([o,h])=>[o,h])]),Ge=()=>({render:(d,g={},m)=>{if(l&&d){const _=t.get(d)||0;t.set(d,_+1),g.key=`${d}-${_}`}return s(d,g,m)},originalResolvers:se,mergedResolvers:ie});function M(o){const h=ie.get(o.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const d=Ge();if(o.type==="text")return h(o,d);const g=o.content?o.content.map(B):void 0;return h({...o,children:g},d)}function B(o){return o.type==="doc"?a?o.content.map(M):o.content.map(M).join(""):Array.isArray(o)?o.map(M):M(o)}return{render:B}}let Y=!1;const J=[],K=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}Y?i():J.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=>{J.forEach(n=>n()),Y=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)}),W=(e="")=>e.includes("/cdn/"),ue=(e,t=25,s=1)=>({...e,per_page:t,page:s}),he=e=>new Promise(t=>setTimeout(t,e)),de=(e=0,t)=>Array.from({length:e},t),fe=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return de(s,(i,n)=>n*r+e)},ge=async(e,t)=>Promise.all(e.map(t)),ye=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),U=(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 l=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=U(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")},Q=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 be=class{constructor(e){R(this,"baseURL");R(this,"timeout");R(this,"headers");R(this,"responseInterceptor");R(this,"fetch");R(this,"ejectInterceptor");R(this,"url");R(this,"parameters");R(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}?${U(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let l=null;this.timeout&&(l=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&l&&clearTimeout(l);const u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return{message:a}}}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)})}},me=be;const X="SB-Agent",$={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},Z={DRAFT:"draft",PUBLISHED:"published"},Re=25,j={SMALL:25,MEDIUM:50,LARGE:75},C={SINGLE_OR_SMALL:50,MEDIUM:15,LARGE:10,VERY_LARGE:6},G=1e3,q=3;function pe(e){return e.version===Z.DRAFT}function ve(e,t){const s=e.includes("/cdn/stories/"),r=e.split("/").length>3&&!e.endsWith("/cdn/stories"),i="find_by"in t;return s&&r||i}function _e(e){return e<=j.SMALL?C.SINGLE_OR_SMALL:e<=j.MEDIUM?C.MEDIUM:e<=j.LARGE?C.LARGE:C.VERY_LARGE}function x(e,t,s={},r){if(s.userRateLimit!==void 0)return Math.min(s.userRateLimit,G);if(s.serverHeadersRateLimit!==void 0)return Math.min(s.serverHeadersRateLimit,G);if(t&&!pe(t))return G;if(r!==void 0)return r;if(ve(e,t))return C.SINGLE_OR_SMALL;const i=t.per_page||Re;return _e(i)}function Ee(e){if(!e)return null;const t=e["x-ratelimit"]||e["X-RateLimit"],s=e["x-ratelimit-policy"]||e["X-RateLimit-Policy"];if(!t&&!s)return null;const r={};if(t){const i=t.match(/r=(\d+)/);i&&(r.remaining=Number.parseInt(i[1],10))}if(s){const i=s.match(/q=(\d+)/);i&&(r.max=Number.parseInt(i[1],10))}return Object.keys(r).length>0?r:null}function ke(e,t=!1){return{userRateLimit:e,serverHeadersRateLimit:void 0,isManagementApi:t}}var Ae=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,l=!1;const a=async()=>{n++;const c=r.shift();if(c)try{const y=await e(...c.args);c.resolve(y)}catch(y){c.reject(y)}const f=setTimeout(()=>{n--,r.length>0&&a(),i=i.filter(y=>y!==f)},s);i.includes(f)||i.push(f)},u=(...c)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,y)=>{r.push({resolve:f,reject:y,args:c}),n<t&&a()});return u.abort=()=>{l=!0,i.forEach(clearTimeout),i=[],r.forEach(c=>c.reject(()=>new Ae("Throttle function aborted"))),r.length=0},u}var we=Se,Le=class{constructor(e,t=1e3){R(this,"queues");R(this,"interval");R(this,"throttledRequestFn");this.queues=new Map,this.interval=t,this.throttledRequestFn=e}getQueue(e){let t=this.queues.get(e);return t||(t=we(this.throttledRequestFn,e,this.interval),this.queues.set(e,t)),t}execute(e,...t){return this.getQueue(e)(...t)}abortAll(){this.queues.forEach(e=>{var t;(t=e.abort)==null||t.call(e)}),this.queues.clear()}getQueueCount(){return this.queues.size}};let H={};const L={};var Te=class{constructor(e,t){R(this,"client");R(this,"maxRetries");R(this,"retriesDelay");R(this,"throttleManager");R(this,"accessToken");R(this,"cache");R(this,"resolveCounter");R(this,"relations");R(this,"links");R(this,"version");R(this,"rateLimitConfig");R(this,"richTextResolver");R(this,"resolveNestedRelations");R(this,"stringifiedStoriesCache");R(this,"inlineAssets");let s=e.endpoint||t;if(!s){const i=e.https===!1?"http":"https";e.oauthToken?s=`${i}://${Q(e.region)}/v1`:s=`${i}://${Q(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(([n,l])=>{r.set(n,l)}),r.has(X)||(r.set(X,$.defaultAgentName),r.set($.defaultAgentVersion,$.packageVersion)),e.oauthToken&&r.set("Authorization",e.oauthToken),this.rateLimitConfig=ke(e.rateLimit,!!e.oauthToken),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttleManager=new Le(this.throttledRequest.bind(this),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||Z.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new me({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=L[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 W(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,ue(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;W(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(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,u=await this.makeRequest(n,t,i,a,r),c=u.total?Math.ceil(u.total/(u.perPage||i)):1,f=await ge(fe(a,c),y=>this.makeRequest(n,t,i,y+1,r));return ye([u,...f],y=>Object.values(y.data[l]))}post(e,t={},s){const r=`/${e}`,i=x(void 0,void 0,this.rateLimitConfig,q);return this.throttleManager.execute(i,"post",r,t,s)}put(e,t={},s){const r=`/${e}`,i=x(void 0,void 0,this.rateLimitConfig,q);return this.throttleManager.execute(i,"put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`,i=x(void 0,void 0,this.rateLimitConfig,q);return this.throttleManager.execute(i,"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(l=>l.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((l,a)=>r(l,`${n}[${a}]`));else if(typeof i=="object")for(const l in i){const a=n?`${n}.${l}`:l;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,l,t,s),this._insertLinks(i,l,s)),r(i[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.link_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].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=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.rel_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].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 l in this.relations[s])this.iterateTree(this.relations[s][l],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(l=>{this.iterateTree(l,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=U({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)}const l=x(e,t,this.rateLimitConfig);return new Promise(async(a,u)=>{var c;try{const f=await this.throttleManager.execute(l,"get",e,t,r);if(f.status!==200)return u(f);let y={data:f.data,headers:f.headers};const S=Ee(f.headers);if((S==null?void 0:S.max)!==void 0&&(this.rateLimitConfig.serverHeadersRateLimit=S.max),(c=f.headers)!=null&&c["per-page"]&&(y=Object.assign({},y,{perPage:f.headers["per-page"]?Number.parseInt(f.headers["per-page"]):0,total:f.headers["per-page"]?Number.parseInt(f.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 O=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(O&&L[t.token]&&L[t.token]!==y.data.cv&&await this.flushCache(),L[t.token]=y.data.cv),a(y)}catch(f){if(f.response&&f.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 he(this.retriesDelay),this.cacheResponse(e,t,s).then(a).catch(u);u(f)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return L}cacheVersion(){return L[this.accessToken]}setCacheVersion(e){this.accessToken&&(L[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(L[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(H[e])},getAll(){return Promise.resolve(H)},set(e,t){return H[e]=t,Promise.resolve(void 0)},flush(){return H={},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={...e.data.assets.find(i=>i.id===r.id),...r});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}},ee=Te;const Ce=(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 ee(t)}},Oe=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 F="https://app.storyblok.com/f/storyblok-v2-latest.js";const te=(e,t,s={})=>{var a;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((a=window.location)==null?void 0:a.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!i||!l)){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())})})}},Ie=(e={})=>{var f,y;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const l={bridge:t,apiOptions:i};let a={};r.forEach(S=>{a={...a,...S(l)}}),n&&(F=n);const c=!(typeof window>"u")&&((y=(f=window.location)==null?void 0:f.search)==null?void 0:y.includes("_storyblok_tk"));return t!==!1&&c&&K(F),a};function Pe(e,t){return V(t).render(e)}const Ne=()=>K(F);v.BlockTypes=b,v.MarkTypes=E,v.StoryblokClient=ee,v.TextTypes=D,v.apiPlugin=Ce,v.loadStoryblokBridge=Ne,v.registerStoryblokBridge=te,v.renderRichText=Pe,v.richTextResolver=V,v.storyblokEditable=Oe,v.storyblokInit=Ie,v.useStoryblokBridge=te,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
7
|
+
(function(_,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(_=typeof globalThis<"u"?globalThis:_||self,g(_.storyblok={}))})(this,function(_){"use strict";var Be=Object.defineProperty;var De=(_,g,E)=>g in _?Be(_,g,{enumerable:!0,configurable:!0,writable:!0,value:E}):_[g]=E;var b=(_,g,E)=>De(_,typeof g!="symbol"?g+"":g,E);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}({}),E=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}({}),V=function(e){return e.TEXT="text",e}({}),N=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ae=(e={})=>{const{custom:t,...s}=e,r={...s,...t};return Object.keys(r).map(i=>`${i}="${r[i]}"`).join(" ")},le=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ce(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function ue(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function l(u,c,m,p,v){typeof u!="number"||u<=c||u>=m?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${c} and ${m} (inclusive)`):v.push(`${p}(${u})`)}if(typeof t=="object"){if(t.width!==void 0&&(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 or equal to 0")),t.height!==void 0&&(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 or equal to 0")),t.height===0&&t.width===0&&(delete i.width,delete i.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 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:m,fill:p,format:v,grayscale:w,quality:k,rotate:C}=u||{};c&&l(c,0,100,"blur",n),k&&l(k,0,100,"quality",n),m&&l(m,0,100,"brightness",n),p&&n.push(`fill(${p})`),w&&n.push("grayscale()"),C&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${C})`),v&&["webp","png","jpeg"].includes(v)&&n.push(`format(${v})`)}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,m]=u;return`${e}/m/${c}x${m}/${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 a=`${e}/m/`;return(s>0||r>0)&&(a=`${a}${s}x${r}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:i}}function Y(e,t={},s){const r=ae(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(oe.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function J(e={}){const t=new Map,{renderFn:s=Y,textFn:r=ce,resolvers:i={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=s!==Y,u=(o={})=>{const{textAlign:h,class:d,id:f,style:y,...A}=o,R=[];return y&&R.push(y.endsWith(";")?y:`${y};`),h&&R.push(`text-align: ${h};`),O({...A,class:d,id:f,...R.length>0?{style:R.join(" ")}:{}})},c=o=>(h,d)=>{const f=u(h.attrs);return d.render(o,f,h.children||null)},m=(o,h)=>{const{src:d,alt:f,title:y,srcset:A,sizes:R}=o.attrs||{};let L=d,S={};if(n){const{src:Ge,attrs:Fe}=ue(d,n);L=Ge,S=Fe}const P={src:L,alt:f,title:y,srcset:A,sizes:R,...S};return h.render("img",O(P))},p=(o,h)=>{const{level:d,...f}=o.attrs||{},y=u(f);return h.render(`h${d}`,y,o.children)},v=(o,h)=>{var f,y,A,R;const d=h.render("img",{src:(f=o.attrs)==null?void 0:f.fallbackImage,alt:(y=o.attrs)==null?void 0:y.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":(A=o.attrs)==null?void 0:A.name,"data-emoji":(R=o.attrs)==null?void 0:R.emoji},d)},w=(o,h)=>h.render("pre",o.attrs||{},h.render("code",{},o.children||"")),k=(o,h=!1)=>({text:d,attrs:f},y)=>{const{class:A,id:R,...L}=f||{},S=h?{class:A,id:R,style:le(L)||void 0}:f||{};return y.render(o,O(S),d)},C=o=>z(o),D=o=>{const{marks:h,...d}=o;if("text"in o){if(h)return h.reduce((y,A)=>C({...A,text:y}),C({...d,children:d.children}));const f=o.attrs||{};if(l){const y=t.get("txt")||0;t.set("txt",y+1),f.key=`txt-${y}`}return r(d.text,f)}return""},se=(o,h)=>{const{linktype:d,href:f,anchor:y,...A}=o.attrs||{};let R="";switch(d){case N.ASSET:case N.URL:R=f;break;case N.EMAIL:R=`mailto:${f}`;break;case N.STORY:R=f,y&&(R=`${R}#${y}`);break;default:R=f;break}const L={...A};return R&&(L.href=R),h.render("a",L,o.text)},Me=(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"})},He=(o,h)=>{const d=u(o.attrs),f=o.children||null;return h.render("table",d,h.render("tbody",{},f))},$e=(o,h)=>{const d=u(o.attrs);return h.render("tr",d,o.children)},Ue=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:A,textAlign:R,...L}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),A&&S.push(`background-color: ${A};`),R&&S.push(`text-align: ${R};`);const P={...L,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("td",O(P),o.children)},je=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:A,textAlign:R,...L}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),A&&S.push(`background-color: ${A};`),R&&S.push(`text-align: ${R};`);const P={...L,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("th",O(P),o.children)},ie=new Map([[g.DOCUMENT,c("")],[g.HEADING,p],[g.PARAGRAPH,c("p")],[g.UL_LIST,c("ul")],[g.OL_LIST,c("ol")],[g.LIST_ITEM,c("li")],[g.IMAGE,m],[g.EMOJI,v],[g.CODE_BLOCK,w],[g.HR,c("hr")],[g.BR,c("br")],[g.QUOTE,c("blockquote")],[g.COMPONENT,Me],[V.TEXT,D],[E.LINK,se],[E.ANCHOR,se],[E.STYLED,k("span",!0)],[E.BOLD,k("strong")],[E.TEXT_STYLE,k("span",!0)],[E.ITALIC,k("em")],[E.UNDERLINE,k("u")],[E.STRIKE,k("s")],[E.CODE,k("code")],[E.SUPERSCRIPT,k("sup")],[E.SUBSCRIPT,k("sub")],[E.HIGHLIGHT,k("mark")],[g.TABLE,He],[g.TABLE_ROW,$e],[g.TABLE_CELL,Ue],[g.TABLE_HEADER,je]]),ne=new Map([...ie,...Object.entries(i).map(([o,h])=>[o,h])]),qe=()=>({render:(d,f={},y)=>{if(l&&d){const A=t.get(d)||0;t.set(d,A+1),f.key=`${d}-${A}`}return s(d,f,y)},originalResolvers:ie,mergedResolvers:ne});function $(o){const h=ne.get(o.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const d=qe();if(o.type==="text")return h(o,d);const f=o.content?o.content.map(z):void 0;return h({...o,children:f},d)}function z(o){return o.type==="doc"?a?o.content.map($):o.content.map($).join(""):Array.isArray(o)?o.map($):$(o)}return{render:z}}let K=!1;const W=[],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}K?i():W.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=>{W.forEach(n=>n()),K=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)}),U=(e="")=>e.includes("/cdn/"),he=(e,t=25,s=1)=>({...e,per_page:t,page:s}),de=e=>new Promise(t=>setTimeout(t,e)),fe=(e=0,t)=>Array.from({length:e},t),ge=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return fe(s,(i,n)=>n*r+e)},ye=async(e,t)=>Promise.all(e.map(t)),be=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),j=(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 l=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=j(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")},X=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 me=class{constructor(e){b(this,"baseURL");b(this,"timeout");b(this,"headers");b(this,"responseInterceptor");b(this,"fetch");b(this,"ejectInterceptor");b(this,"url");b(this,"parameters");b(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}?${j(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let l=null;this.timeout&&(l=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&l&&clearTimeout(l);const u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return a.name==="AbortError"?{message:"Request timeout: The request was aborted due to timeout"}:{message:a.message||a.toString()||"An unknown error occurred"}}}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)})}},pe=me;const Z="SB-Agent",q={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},ee={DRAFT:"draft",PUBLISHED:"published"},Re=25,G={SMALL:25,MEDIUM:50,LARGE:75},I={SINGLE_OR_SMALL:50,MEDIUM:15,LARGE:10,VERY_LARGE:6},F=1e3,x=3;function ve(e){return e.version===ee.DRAFT}function _e(e,t){const s=e.includes("/cdn/stories/"),r=e.split("/").length>3&&!e.endsWith("/cdn/stories"),i="find_by"in t;return s&&r||i}function Ae(e){return e<=G.SMALL?I.SINGLE_OR_SMALL:e<=G.MEDIUM?I.MEDIUM:e<=G.LARGE?I.LARGE:I.VERY_LARGE}function M(e,t,s={},r){if(s.userRateLimit!==void 0)return Math.min(s.userRateLimit,F);if(s.serverHeadersRateLimit!==void 0)return Math.min(s.serverHeadersRateLimit,F);if(r!==void 0)return r;if(t&&!ve(t))return F;if(_e(e,t))return I.SINGLE_OR_SMALL;const i=t.per_page||Re;return Ae(i)}function Ee(e){if(!e)return null;const t=e["x-ratelimit"]||e["X-RateLimit"],s=e["x-ratelimit-policy"]||e["X-RateLimit-Policy"];if(!t&&!s)return null;const r={};if(t){const i=t.match(/r=(\d+)/);i&&(r.remaining=Number.parseInt(i[1],10))}if(s){const i=s.match(/q=(\d+)/);i&&(r.max=Number.parseInt(i[1],10))}return Object.keys(r).length>0?r:null}function ke(e,t=!1){return{userRateLimit:e,serverHeadersRateLimit:void 0,isManagementApi:t}}var we=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,l=!1;const a=async()=>{n++;const c=r.shift();if(c)try{const p=await e(...c.args);c.resolve(p)}catch(p){c.reject(p)}const m=setTimeout(()=>{n--,r.length>0&&a(),i=i.filter(p=>p!==m)},s);i.includes(m)||i.push(m)},u=(...c)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,p)=>{r.push({resolve:m,reject:p,args:c}),n<t&&a()});return u.abort=()=>{l=!0,i.forEach(clearTimeout),i=[],r.forEach(c=>c.reject(()=>new we("Throttle function aborted"))),r.length=0},u}var Le=Se,Te=class{constructor(e,t=1e3){b(this,"queues");b(this,"interval");b(this,"throttledRequestFn");this.queues=new Map,this.interval=t,this.throttledRequestFn=e}getQueue(e){let t=this.queues.get(e);return t||(t=Le(this.throttledRequestFn,e,this.interval),this.queues.set(e,t)),t}execute(e,...t){return this.getQueue(e)(...t)}abortAll(){this.queues.forEach(e=>{var t;(t=e.abort)==null||t.call(e)}),this.queues.clear()}getQueueCount(){return this.queues.size}};let H={};const T={};var Ce=class{constructor(e,t){b(this,"client");b(this,"maxRetries");b(this,"retriesDelay");b(this,"throttleManager");b(this,"accessToken");b(this,"cache");b(this,"resolveCounter");b(this,"relations");b(this,"links");b(this,"version");b(this,"rateLimitConfig");b(this,"richTextResolver");b(this,"resolveNestedRelations");b(this,"stringifiedStoriesCache");b(this,"inlineAssets");let s=e.endpoint||t;if(!s){const i=e.https===!1?"http":"https";e.oauthToken?s=`${i}://${X(e.region)}/v1`:s=`${i}://${X(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(([n,l])=>{r.set(n,l)}),r.has(Z)||(r.set(Z,q.defaultAgentName),r.set(q.defaultAgentVersion,q.packageVersion)),e.oauthToken&&r.set("Authorization",e.oauthToken),this.rateLimitConfig=ke(e.rateLimit,!!e.oauthToken),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttleManager=new Te(this.throttledRequest.bind(this),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||ee.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new pe({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 U(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,he(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;U(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(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,u=await this.makeRequest(n,t,i,a,r),c=u.total?Math.ceil(u.total/(u.perPage||i)):1,m=await ye(ge(a,c),p=>this.makeRequest(n,t,i,p+1,r));return be([u,...m],p=>Object.values(p.data[l]))}post(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"post",r,t,s)}put(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"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(l=>l.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((l,a)=>r(l,`${n}[${a}]`));else if(typeof i=="object")for(const l in i){const a=n?`${n}.${l}`:l;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,l,t,s),this._insertLinks(i,l,s)),r(i[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.link_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].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=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.rel_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].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 l in this.relations[s])this.iterateTree(this.relations[s][l],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(l=>{this.iterateTree(l,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=j({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)}const a=!U(e)&&this.rateLimitConfig.isManagementApi?x:void 0,u=M(e,t,this.rateLimitConfig,a);return new Promise(async(c,m)=>{var p;try{const v=await this.throttleManager.execute(u,"get",e,t,r);if(v.status!==200)return m(v);let w={data:v.data,headers:v.headers};const k=Ee(v.headers);if((k==null?void 0:k.max)!==void 0&&(this.rateLimitConfig.serverHeadersRateLimit=k.max),(p=v.headers)!=null&&p["per-page"]&&(w=Object.assign({},w,{perPage:v.headers["per-page"]?Number.parseInt(v.headers["per-page"]):0,total:v.headers["per-page"]?Number.parseInt(v.headers.total):0})),w.data.story||w.data.stories){const D=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(w.data,t,`${D}`),w=await this.processInlineAssets(w)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(i,w);const C=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&w.data.cv&&(C&&T[t.token]&&T[t.token]!==w.data.cv&&await this.flushCache(),T[t.token]=w.data.cv),c(w)}catch(v){if(v.response&&v.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 de(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(m);m(v)}})}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(H[e])},getAll(){return Promise.resolve(H)},set(e,t){return H[e]=t,Promise.resolve(void 0)},flush(){return H={},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={...e.data.assets.find(i=>i.id===r.id),...r});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}},te=Ce;const Oe=(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 te(t)}},Ie=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 B="https://app.storyblok.com/f/storyblok-v2-latest.js";const re=(e,t,s={})=>{var a;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((a=window.location)==null?void 0:a.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!i||!l)){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 m;c&&(c.action==="input"&&((m=c.story)==null?void 0:m.id)===e?t(c.story):(c.action==="change"||c.action==="published")&&c.storyId===e&&window.location.reload())})})}},Pe=(e={})=>{var m,p;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const l={bridge:t,apiOptions:i};let a={};r.forEach(v=>{a={...a,...v(l)}}),n&&(B=n);const c=!(typeof window>"u")&&((p=(m=window.location)==null?void 0:m.search)==null?void 0:p.includes("_storyblok_tk"));return t!==!1&&c&&Q(B),a};function Ne(e,t){return J(t).render(e)}const xe=()=>Q(B);_.BlockTypes=g,_.MarkTypes=E,_.StoryblokClient=te,_.TextTypes=V,_.apiPlugin=Oe,_.loadStoryblokBridge=xe,_.registerStoryblokBridge=re,_.renderRichText=Ne,_.richTextResolver=J,_.storyblokEditable=Ie,_.storyblokInit=Pe,_.useStoryblokBridge=re,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* name: @storyblok/js
|
|
3
|
-
* (c)
|
|
3
|
+
* (c) 2026
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
7
|
var ce = Object.defineProperty;
|
|
8
8
|
var ue = (e, t, r) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
9
|
-
var
|
|
10
|
-
let
|
|
9
|
+
var y = (e, t, r) => ue(e, typeof t != "symbol" ? t + "" : t, r);
|
|
10
|
+
let A = /* @__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
|
+
}({}), L = /* @__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
|
}({}), he = /* @__PURE__ */ function(e) {
|
|
15
15
|
return e.TEXT = "text", e;
|
|
@@ -49,28 +49,28 @@ function be(e, t) {
|
|
|
49
49
|
};
|
|
50
50
|
let r = 0, s = 0;
|
|
51
51
|
const i = {}, n = [];
|
|
52
|
-
function l(u, c,
|
|
53
|
-
typeof u != "number" || u <= c || u >=
|
|
52
|
+
function l(u, c, b, m, R) {
|
|
53
|
+
typeof u != "number" || u <= c || u >= b ? console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase() + m.slice(1)} value must be a number between ${c} and ${b} (inclusive)`) : R.push(`${m}(${u})`);
|
|
54
54
|
}
|
|
55
55
|
if (typeof t == "object") {
|
|
56
56
|
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (i.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (i.height = t.height, s = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete i.width, delete i.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (i.loading = t.loading), t.class && (i.class = t.class), t.filters) {
|
|
57
|
-
const { filters: u } = t || {}, { blur: c, brightness:
|
|
58
|
-
c && l(c, 0, 100, "blur", n),
|
|
57
|
+
const { filters: u } = t || {}, { blur: c, brightness: b, fill: m, format: R, grayscale: E, quality: _, rotate: T } = u || {};
|
|
58
|
+
c && l(c, 0, 100, "blur", n), _ && l(_, 0, 100, "quality", n), b && l(b, 0, 100, "brightness", n), m && n.push(`fill(${m})`), E && n.push("grayscale()"), T && [
|
|
59
59
|
0,
|
|
60
60
|
90,
|
|
61
61
|
180,
|
|
62
62
|
270
|
|
63
|
-
].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`),
|
|
63
|
+
].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`), R && [
|
|
64
64
|
"webp",
|
|
65
65
|
"png",
|
|
66
66
|
"jpeg"
|
|
67
|
-
].includes(
|
|
67
|
+
].includes(R) && n.push(`format(${R})`);
|
|
68
68
|
}
|
|
69
69
|
t.srcset && (i.srcset = t.srcset.map((u) => {
|
|
70
70
|
if (typeof u == "number") return `${e}/m/${u}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${u}w`;
|
|
71
71
|
if (Array.isArray(u) && u.length === 2) {
|
|
72
|
-
const [c,
|
|
73
|
-
return `${e}/m/${c}x${
|
|
72
|
+
const [c, b] = u;
|
|
73
|
+
return `${e}/m/${c}x${b}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
|
|
74
74
|
} else {
|
|
75
75
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
76
76
|
return;
|
|
@@ -83,7 +83,7 @@ function be(e, t) {
|
|
|
83
83
|
attrs: i
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function J(e, t = {}, r) {
|
|
87
87
|
const s = fe(t), i = s ? `${e} ${s}` : e, n = Array.isArray(r) ? r.join("") : r || "";
|
|
88
88
|
if (e) {
|
|
89
89
|
if (de.includes(e)) return `<${i}>`;
|
|
@@ -91,180 +91,180 @@ function V(e, t = {}, r) {
|
|
|
91
91
|
return `<${i}>${n}</${e}>`;
|
|
92
92
|
}
|
|
93
93
|
function me(e = {}) {
|
|
94
|
-
const t = /* @__PURE__ */ new Map(), { renderFn: r =
|
|
95
|
-
const { textAlign: h, class: d, id:
|
|
96
|
-
return
|
|
97
|
-
...
|
|
94
|
+
const t = /* @__PURE__ */ new Map(), { renderFn: r = J, textFn: s = ye, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: l = !1 } = e, a = r !== J, u = (o = {}) => {
|
|
95
|
+
const { textAlign: h, class: d, id: f, style: g, ...v } = o, p = [];
|
|
96
|
+
return g && p.push(g.endsWith(";") ? g : `${g};`), h && p.push(`text-align: ${h};`), O({
|
|
97
|
+
...v,
|
|
98
98
|
class: d,
|
|
99
|
-
id:
|
|
99
|
+
id: f,
|
|
100
100
|
...p.length > 0 ? { style: p.join(" ") } : {}
|
|
101
101
|
});
|
|
102
102
|
}, c = (o) => (h, d) => {
|
|
103
|
-
const
|
|
104
|
-
return d.render(o,
|
|
105
|
-
},
|
|
106
|
-
const { src: d, alt:
|
|
107
|
-
let k = d,
|
|
103
|
+
const f = u(h.attrs);
|
|
104
|
+
return d.render(o, f, h.children || null);
|
|
105
|
+
}, b = (o, h) => {
|
|
106
|
+
const { src: d, alt: f, title: g, srcset: v, sizes: p } = o.attrs || {};
|
|
107
|
+
let k = d, w = {};
|
|
108
108
|
if (n) {
|
|
109
109
|
const { src: ae, attrs: le } = be(d, n);
|
|
110
|
-
k = ae,
|
|
110
|
+
k = ae, w = le;
|
|
111
111
|
}
|
|
112
112
|
const C = {
|
|
113
113
|
src: k,
|
|
114
|
-
alt:
|
|
115
|
-
title:
|
|
116
|
-
srcset:
|
|
114
|
+
alt: f,
|
|
115
|
+
title: g,
|
|
116
|
+
srcset: v,
|
|
117
117
|
sizes: p,
|
|
118
|
-
...
|
|
118
|
+
...w
|
|
119
119
|
};
|
|
120
120
|
return h.render("img", O(C));
|
|
121
|
-
},
|
|
122
|
-
const { level: d, ...
|
|
123
|
-
return h.render(`h${d}`,
|
|
124
|
-
},
|
|
125
|
-
var
|
|
121
|
+
}, m = (o, h) => {
|
|
122
|
+
const { level: d, ...f } = o.attrs || {}, g = u(f);
|
|
123
|
+
return h.render(`h${d}`, g, o.children);
|
|
124
|
+
}, R = (o, h) => {
|
|
125
|
+
var f, g, v, p;
|
|
126
126
|
const d = h.render("img", {
|
|
127
|
-
src: (
|
|
128
|
-
alt: (
|
|
127
|
+
src: (f = o.attrs) == null ? void 0 : f.fallbackImage,
|
|
128
|
+
alt: (g = o.attrs) == null ? void 0 : g.alt,
|
|
129
129
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
130
130
|
draggable: "false",
|
|
131
131
|
loading: "lazy"
|
|
132
132
|
});
|
|
133
133
|
return h.render("span", {
|
|
134
134
|
"data-type": "emoji",
|
|
135
|
-
"data-name": (
|
|
135
|
+
"data-name": (v = o.attrs) == null ? void 0 : v.name,
|
|
136
136
|
"data-emoji": (p = o.attrs) == null ? void 0 : p.emoji
|
|
137
137
|
}, d);
|
|
138
|
-
},
|
|
139
|
-
const { class:
|
|
140
|
-
class:
|
|
138
|
+
}, E = (o, h) => h.render("pre", o.attrs || {}, h.render("code", {}, o.children || "")), _ = (o, h = !1) => ({ text: d, attrs: f }, g) => {
|
|
139
|
+
const { class: v, id: p, ...k } = f || {}, w = h ? {
|
|
140
|
+
class: v,
|
|
141
141
|
id: p,
|
|
142
142
|
style: ge(k) || void 0
|
|
143
|
-
} :
|
|
144
|
-
return
|
|
145
|
-
}, T = (o) => U(o),
|
|
143
|
+
} : f || {};
|
|
144
|
+
return g.render(o, O(w), d);
|
|
145
|
+
}, T = (o) => U(o), M = (o) => {
|
|
146
146
|
const { marks: h, ...d } = o;
|
|
147
147
|
if ("text" in o) {
|
|
148
|
-
if (h) return h.reduce((
|
|
149
|
-
...
|
|
150
|
-
text:
|
|
148
|
+
if (h) return h.reduce((g, v) => T({
|
|
149
|
+
...v,
|
|
150
|
+
text: g
|
|
151
151
|
}), T({
|
|
152
152
|
...d,
|
|
153
153
|
children: d.children
|
|
154
154
|
}));
|
|
155
|
-
const
|
|
155
|
+
const f = o.attrs || {};
|
|
156
156
|
if (l) {
|
|
157
|
-
const
|
|
158
|
-
t.set("txt",
|
|
157
|
+
const g = t.get("txt") || 0;
|
|
158
|
+
t.set("txt", g + 1), f.key = `txt-${g}`;
|
|
159
159
|
}
|
|
160
|
-
return s(d.text,
|
|
160
|
+
return s(d.text, f);
|
|
161
161
|
}
|
|
162
162
|
return "";
|
|
163
|
-
},
|
|
164
|
-
const { linktype: d, href:
|
|
163
|
+
}, z = (o, h) => {
|
|
164
|
+
const { linktype: d, href: f, anchor: g, ...v } = o.attrs || {};
|
|
165
165
|
let p = "";
|
|
166
166
|
switch (d) {
|
|
167
167
|
case x.ASSET:
|
|
168
168
|
case x.URL:
|
|
169
|
-
p =
|
|
169
|
+
p = f;
|
|
170
170
|
break;
|
|
171
171
|
case x.EMAIL:
|
|
172
|
-
p = `mailto:${
|
|
172
|
+
p = `mailto:${f}`;
|
|
173
173
|
break;
|
|
174
174
|
case x.STORY:
|
|
175
|
-
p =
|
|
175
|
+
p = f, g && (p = `${p}#${g}`);
|
|
176
176
|
break;
|
|
177
177
|
default:
|
|
178
|
-
p =
|
|
178
|
+
p = f;
|
|
179
179
|
break;
|
|
180
180
|
}
|
|
181
|
-
const k = { ...
|
|
181
|
+
const k = { ...v };
|
|
182
182
|
return p && (k.href = p), h.render("a", k, o.text);
|
|
183
183
|
}, te = (o, h) => {
|
|
184
|
-
var d,
|
|
184
|
+
var d, f;
|
|
185
185
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
|
|
186
186
|
blok: (d = o == null ? void 0 : o.attrs) == null ? void 0 : d.body[0],
|
|
187
|
-
id: (
|
|
187
|
+
id: (f = o.attrs) == null ? void 0 : f.id,
|
|
188
188
|
style: "display: none"
|
|
189
189
|
});
|
|
190
190
|
}, re = (o, h) => {
|
|
191
|
-
const d = u(o.attrs),
|
|
192
|
-
return h.render("table", d, h.render("tbody", {},
|
|
191
|
+
const d = u(o.attrs), f = o.children || null;
|
|
192
|
+
return h.render("table", d, h.render("tbody", {}, f));
|
|
193
193
|
}, se = (o, h) => {
|
|
194
194
|
const d = u(o.attrs);
|
|
195
195
|
return h.render("tr", d, o.children);
|
|
196
196
|
}, ie = (o, h) => {
|
|
197
|
-
const { colspan: d, rowspan:
|
|
198
|
-
|
|
197
|
+
const { colspan: d, rowspan: f, colwidth: g, backgroundColor: v, textAlign: p, ...k } = o.attrs || {}, w = [];
|
|
198
|
+
g && w.push(`width: ${g}px;`), v && w.push(`background-color: ${v};`), p && w.push(`text-align: ${p};`);
|
|
199
199
|
const C = {
|
|
200
200
|
...k,
|
|
201
201
|
...d > 1 ? { colspan: d } : {},
|
|
202
|
-
...
|
|
203
|
-
...
|
|
202
|
+
...f > 1 ? { rowspan: f } : {},
|
|
203
|
+
...w.length > 0 ? { style: w.join(" ") } : {}
|
|
204
204
|
};
|
|
205
205
|
return h.render("td", O(C), o.children);
|
|
206
206
|
}, ne = (o, h) => {
|
|
207
|
-
const { colspan: d, rowspan:
|
|
208
|
-
|
|
207
|
+
const { colspan: d, rowspan: f, colwidth: g, backgroundColor: v, textAlign: p, ...k } = o.attrs || {}, w = [];
|
|
208
|
+
g && w.push(`width: ${g}px;`), v && w.push(`background-color: ${v};`), p && w.push(`text-align: ${p};`);
|
|
209
209
|
const C = {
|
|
210
210
|
...k,
|
|
211
211
|
...d > 1 ? { colspan: d } : {},
|
|
212
|
-
...
|
|
213
|
-
...
|
|
212
|
+
...f > 1 ? { rowspan: f } : {},
|
|
213
|
+
...w.length > 0 ? { style: w.join(" ") } : {}
|
|
214
214
|
};
|
|
215
215
|
return h.render("th", O(C), o.children);
|
|
216
|
-
},
|
|
217
|
-
[
|
|
218
|
-
[
|
|
219
|
-
[
|
|
220
|
-
[
|
|
221
|
-
[
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
[
|
|
225
|
-
[
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[he.TEXT,
|
|
231
|
-
[
|
|
232
|
-
[
|
|
233
|
-
[
|
|
234
|
-
[
|
|
235
|
-
[
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
[
|
|
239
|
-
[
|
|
240
|
-
[
|
|
241
|
-
[
|
|
242
|
-
[
|
|
243
|
-
[
|
|
244
|
-
[
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
]),
|
|
248
|
-
render: (d,
|
|
216
|
+
}, V = /* @__PURE__ */ new Map([
|
|
217
|
+
[A.DOCUMENT, c("")],
|
|
218
|
+
[A.HEADING, m],
|
|
219
|
+
[A.PARAGRAPH, c("p")],
|
|
220
|
+
[A.UL_LIST, c("ul")],
|
|
221
|
+
[A.OL_LIST, c("ol")],
|
|
222
|
+
[A.LIST_ITEM, c("li")],
|
|
223
|
+
[A.IMAGE, b],
|
|
224
|
+
[A.EMOJI, R],
|
|
225
|
+
[A.CODE_BLOCK, E],
|
|
226
|
+
[A.HR, c("hr")],
|
|
227
|
+
[A.BR, c("br")],
|
|
228
|
+
[A.QUOTE, c("blockquote")],
|
|
229
|
+
[A.COMPONENT, te],
|
|
230
|
+
[he.TEXT, M],
|
|
231
|
+
[L.LINK, z],
|
|
232
|
+
[L.ANCHOR, z],
|
|
233
|
+
[L.STYLED, _("span", !0)],
|
|
234
|
+
[L.BOLD, _("strong")],
|
|
235
|
+
[L.TEXT_STYLE, _("span", !0)],
|
|
236
|
+
[L.ITALIC, _("em")],
|
|
237
|
+
[L.UNDERLINE, _("u")],
|
|
238
|
+
[L.STRIKE, _("s")],
|
|
239
|
+
[L.CODE, _("code")],
|
|
240
|
+
[L.SUPERSCRIPT, _("sup")],
|
|
241
|
+
[L.SUBSCRIPT, _("sub")],
|
|
242
|
+
[L.HIGHLIGHT, _("mark")],
|
|
243
|
+
[A.TABLE, re],
|
|
244
|
+
[A.TABLE_ROW, se],
|
|
245
|
+
[A.TABLE_CELL, ie],
|
|
246
|
+
[A.TABLE_HEADER, ne]
|
|
247
|
+
]), Y = new Map([...V, ...Object.entries(i).map(([o, h]) => [o, h])]), oe = () => ({
|
|
248
|
+
render: (d, f = {}, g) => {
|
|
249
249
|
if (l && d) {
|
|
250
|
-
const
|
|
251
|
-
t.set(d,
|
|
250
|
+
const v = t.get(d) || 0;
|
|
251
|
+
t.set(d, v + 1), f.key = `${d}-${v}`;
|
|
252
252
|
}
|
|
253
|
-
return r(d,
|
|
253
|
+
return r(d, f, g);
|
|
254
254
|
},
|
|
255
|
-
originalResolvers:
|
|
256
|
-
mergedResolvers:
|
|
255
|
+
originalResolvers: V,
|
|
256
|
+
mergedResolvers: Y
|
|
257
257
|
});
|
|
258
258
|
function P(o) {
|
|
259
|
-
const h =
|
|
259
|
+
const h = Y.get(o.type);
|
|
260
260
|
if (!h)
|
|
261
261
|
return console.error("<Storyblok>", `No resolver found for node type ${o.type}`), "";
|
|
262
262
|
const d = oe();
|
|
263
263
|
if (o.type === "text") return h(o, d);
|
|
264
|
-
const
|
|
264
|
+
const f = o.content ? o.content.map(U) : void 0;
|
|
265
265
|
return h({
|
|
266
266
|
...o,
|
|
267
|
-
children:
|
|
267
|
+
children: f
|
|
268
268
|
}, d);
|
|
269
269
|
}
|
|
270
270
|
function U(o) {
|
|
@@ -272,8 +272,8 @@ function me(e = {}) {
|
|
|
272
272
|
}
|
|
273
273
|
return { render: U };
|
|
274
274
|
}
|
|
275
|
-
let
|
|
276
|
-
const
|
|
275
|
+
let K = !1;
|
|
276
|
+
const W = [], Z = (e) => new Promise((t, r) => {
|
|
277
277
|
if (typeof window > "u") {
|
|
278
278
|
r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
279
279
|
return;
|
|
@@ -283,23 +283,23 @@ const J = [], X = (e) => new Promise((t, r) => {
|
|
|
283
283
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
|
-
|
|
286
|
+
K ? i() : W.push(i);
|
|
287
287
|
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
288
288
|
t(void 0);
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
291
291
|
const s = document.createElement("script");
|
|
292
292
|
s.async = !0, s.src = e, s.id = "storyblok-javascript-bridge", s.onerror = (i) => r(i), s.onload = (i) => {
|
|
293
|
-
|
|
293
|
+
W.forEach((n) => n()), K = !0, t(i);
|
|
294
294
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
295
|
-
}),
|
|
295
|
+
}), j = (e = "") => e.includes("/cdn/"), pe = (e, t = 25, r = 1) => ({
|
|
296
296
|
...e,
|
|
297
297
|
per_page: t,
|
|
298
298
|
page: r
|
|
299
299
|
}), Re = (e) => new Promise((t) => setTimeout(t, e)), ve = (e = 0, t) => Array.from({ length: e }, t), _e = (e = 0, t = e) => {
|
|
300
300
|
const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
|
|
301
301
|
return ve(r, (i, n) => n * s + e);
|
|
302
|
-
},
|
|
302
|
+
}, Ae = async (e, t) => Promise.all(e.map(t)), Ee = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), B = (e, t, r) => {
|
|
303
303
|
const s = [];
|
|
304
304
|
for (const i in e) {
|
|
305
305
|
if (!Object.prototype.hasOwnProperty.call(e, i)) continue;
|
|
@@ -307,10 +307,10 @@ const J = [], X = (e) => new Promise((t, r) => {
|
|
|
307
307
|
if (n == null) continue;
|
|
308
308
|
const l = r ? "" : encodeURIComponent(i);
|
|
309
309
|
let a;
|
|
310
|
-
typeof n == "object" ? a =
|
|
310
|
+
typeof n == "object" ? a = B(n, t ? t + encodeURIComponent(`[${l}]`) : l, Array.isArray(n)) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, s.push(a);
|
|
311
311
|
}
|
|
312
312
|
return s.join("&");
|
|
313
|
-
},
|
|
313
|
+
}, Q = (e) => {
|
|
314
314
|
const t = {
|
|
315
315
|
eu: "api.storyblok.com",
|
|
316
316
|
us: "api-us.storyblok.com",
|
|
@@ -322,15 +322,15 @@ const J = [], X = (e) => new Promise((t, r) => {
|
|
|
322
322
|
};
|
|
323
323
|
var we = class {
|
|
324
324
|
constructor(e) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
325
|
+
y(this, "baseURL");
|
|
326
|
+
y(this, "timeout");
|
|
327
|
+
y(this, "headers");
|
|
328
|
+
y(this, "responseInterceptor");
|
|
329
|
+
y(this, "fetch");
|
|
330
|
+
y(this, "ejectInterceptor");
|
|
331
|
+
y(this, "url");
|
|
332
|
+
y(this, "parameters");
|
|
333
|
+
y(this, "fetchOptions");
|
|
334
334
|
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 = {};
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
@@ -366,7 +366,7 @@ var we = class {
|
|
|
366
366
|
}
|
|
367
367
|
async _methodHandler(e) {
|
|
368
368
|
let t = `${this.baseURL}${this.url}`, r = null;
|
|
369
|
-
e === "get" ? t = `${this.baseURL}${this.url}?${
|
|
369
|
+
e === "get" ? t = `${this.baseURL}${this.url}?${B(this.parameters)}` : r = JSON.stringify(this.parameters);
|
|
370
370
|
const s = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
371
371
|
let l = null;
|
|
372
372
|
this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
|
|
@@ -382,7 +382,7 @@ var we = class {
|
|
|
382
382
|
const u = await this._responseHandler(a);
|
|
383
383
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(u)) : this._statusHandler(u);
|
|
384
384
|
} catch (a) {
|
|
385
|
-
return { message: a };
|
|
385
|
+
return a.name === "AbortError" ? { message: "Request timeout: The request was aborted due to timeout" } : { message: a.message || a.toString() || "An unknown error occurred" };
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
setFetchOptions(e = {}) {
|
|
@@ -420,15 +420,15 @@ var we = class {
|
|
|
420
420
|
s(i);
|
|
421
421
|
});
|
|
422
422
|
}
|
|
423
|
-
},
|
|
424
|
-
const
|
|
423
|
+
}, Le = we;
|
|
424
|
+
const X = "SB-Agent", q = {
|
|
425
425
|
defaultAgentName: "SB-JS-CLIENT",
|
|
426
426
|
defaultAgentVersion: "SB-Agent-Version",
|
|
427
427
|
packageVersion: "7.0.0"
|
|
428
|
-
},
|
|
428
|
+
}, ee = {
|
|
429
429
|
DRAFT: "draft",
|
|
430
430
|
PUBLISHED: "published"
|
|
431
|
-
},
|
|
431
|
+
}, ke = 25, G = {
|
|
432
432
|
SMALL: 25,
|
|
433
433
|
MEDIUM: 50,
|
|
434
434
|
LARGE: 75
|
|
@@ -437,24 +437,24 @@ const Q = "SB-Agent", $ = {
|
|
|
437
437
|
MEDIUM: 15,
|
|
438
438
|
LARGE: 10,
|
|
439
439
|
VERY_LARGE: 6
|
|
440
|
-
},
|
|
440
|
+
}, F = 1e3, N = 3;
|
|
441
441
|
function Se(e) {
|
|
442
|
-
return e.version ===
|
|
442
|
+
return e.version === ee.DRAFT;
|
|
443
443
|
}
|
|
444
444
|
function Te(e, t) {
|
|
445
445
|
const r = e.includes("/cdn/stories/"), s = e.split("/").length > 3 && !e.endsWith("/cdn/stories"), i = "find_by" in t;
|
|
446
446
|
return r && s || i;
|
|
447
447
|
}
|
|
448
448
|
function Ce(e) {
|
|
449
|
-
return e <=
|
|
449
|
+
return e <= G.SMALL ? I.SINGLE_OR_SMALL : e <= G.MEDIUM ? I.MEDIUM : e <= G.LARGE ? I.LARGE : I.VERY_LARGE;
|
|
450
450
|
}
|
|
451
|
-
function
|
|
452
|
-
if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit,
|
|
453
|
-
if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit,
|
|
454
|
-
if (t && !Se(t)) return j;
|
|
451
|
+
function H(e, t, r = {}, s) {
|
|
452
|
+
if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit, F);
|
|
453
|
+
if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit, F);
|
|
455
454
|
if (s !== void 0) return s;
|
|
455
|
+
if (t && !Se(t)) return F;
|
|
456
456
|
if (Te(e, t)) return I.SINGLE_OR_SMALL;
|
|
457
|
-
const i = t.per_page ||
|
|
457
|
+
const i = t.per_page || ke;
|
|
458
458
|
return Ce(i);
|
|
459
459
|
}
|
|
460
460
|
function Oe(e) {
|
|
@@ -493,19 +493,19 @@ function xe(e, t, r) {
|
|
|
493
493
|
n++;
|
|
494
494
|
const c = s.shift();
|
|
495
495
|
if (c) try {
|
|
496
|
-
const
|
|
497
|
-
c.resolve(
|
|
498
|
-
} catch (
|
|
499
|
-
c.reject(
|
|
496
|
+
const m = await e(...c.args);
|
|
497
|
+
c.resolve(m);
|
|
498
|
+
} catch (m) {
|
|
499
|
+
c.reject(m);
|
|
500
500
|
}
|
|
501
|
-
const
|
|
502
|
-
n--, s.length > 0 && a(), i = i.filter((
|
|
501
|
+
const b = setTimeout(() => {
|
|
502
|
+
n--, s.length > 0 && a(), i = i.filter((m) => m !== b);
|
|
503
503
|
}, r);
|
|
504
|
-
i.includes(
|
|
505
|
-
}, u = (...c) => l ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((
|
|
504
|
+
i.includes(b) || i.push(b);
|
|
505
|
+
}, u = (...c) => l ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((b, m) => {
|
|
506
506
|
s.push({
|
|
507
|
-
resolve:
|
|
508
|
-
reject:
|
|
507
|
+
resolve: b,
|
|
508
|
+
reject: m,
|
|
509
509
|
args: c
|
|
510
510
|
}), n < t && a();
|
|
511
511
|
});
|
|
@@ -515,9 +515,9 @@ function xe(e, t, r) {
|
|
|
515
515
|
}
|
|
516
516
|
var Ne = xe, He = class {
|
|
517
517
|
constructor(e, t = 1e3) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
518
|
+
y(this, "queues");
|
|
519
|
+
y(this, "interval");
|
|
520
|
+
y(this, "throttledRequestFn");
|
|
521
521
|
this.queues = /* @__PURE__ */ new Map(), this.interval = t, this.throttledRequestFn = e;
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
@@ -549,43 +549,43 @@ var Ne = xe, He = class {
|
|
|
549
549
|
return this.queues.size;
|
|
550
550
|
}
|
|
551
551
|
};
|
|
552
|
-
let
|
|
553
|
-
const
|
|
554
|
-
var
|
|
552
|
+
let $ = {};
|
|
553
|
+
const S = {};
|
|
554
|
+
var $e = class {
|
|
555
555
|
/**
|
|
556
556
|
*
|
|
557
557
|
* @param config ISbConfig interface
|
|
558
558
|
* @param pEndpoint string, optional
|
|
559
559
|
*/
|
|
560
560
|
constructor(e, t) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
561
|
+
y(this, "client");
|
|
562
|
+
y(this, "maxRetries");
|
|
563
|
+
y(this, "retriesDelay");
|
|
564
|
+
y(this, "throttleManager");
|
|
565
|
+
y(this, "accessToken");
|
|
566
|
+
y(this, "cache");
|
|
567
|
+
y(this, "resolveCounter");
|
|
568
|
+
y(this, "relations");
|
|
569
|
+
y(this, "links");
|
|
570
|
+
y(this, "version");
|
|
571
|
+
y(this, "rateLimitConfig");
|
|
572
572
|
/**
|
|
573
573
|
* @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
|
|
574
574
|
* @see https://github.com/storyblok/richtext
|
|
575
575
|
*/
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
576
|
+
y(this, "richTextResolver");
|
|
577
|
+
y(this, "resolveNestedRelations");
|
|
578
|
+
y(this, "stringifiedStoriesCache");
|
|
579
|
+
y(this, "inlineAssets");
|
|
580
580
|
let r = e.endpoint || t;
|
|
581
581
|
if (!r) {
|
|
582
582
|
const i = e.https === !1 ? "http" : "https";
|
|
583
|
-
e.oauthToken ? r = `${i}://${
|
|
583
|
+
e.oauthToken ? r = `${i}://${Q(e.region)}/v1` : r = `${i}://${Q(e.region)}/v2`;
|
|
584
584
|
}
|
|
585
585
|
const s = new Headers();
|
|
586
586
|
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, l]) => {
|
|
587
587
|
s.set(n, l);
|
|
588
|
-
}), s.has(
|
|
588
|
+
}), s.has(X) || (s.set(X, q.defaultAgentName), s.set(q.defaultAgentVersion, q.packageVersion)), e.oauthToken && s.set("Authorization", e.oauthToken), this.rateLimitConfig = Ie(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttleManager = new He(this.throttledRequest.bind(this), 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 || ee.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new Le({
|
|
589
589
|
baseURL: r,
|
|
590
590
|
timeout: e.timeout || 0,
|
|
591
591
|
headers: s,
|
|
@@ -594,10 +594,10 @@ var Ue = class {
|
|
|
594
594
|
});
|
|
595
595
|
}
|
|
596
596
|
parseParams(e) {
|
|
597
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
597
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = S[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
598
598
|
}
|
|
599
599
|
factoryParamOptions(e, t) {
|
|
600
|
-
return
|
|
600
|
+
return j(e) ? this.parseParams(t) : t;
|
|
601
601
|
}
|
|
602
602
|
makeRequest(e, t, r, s, i) {
|
|
603
603
|
const n = this.factoryParamOptions(e, pe(t, r, s));
|
|
@@ -606,27 +606,27 @@ var Ue = class {
|
|
|
606
606
|
get(e, t = {}, r) {
|
|
607
607
|
t || (t = {});
|
|
608
608
|
const s = `/${e}`;
|
|
609
|
-
|
|
609
|
+
j(s) && (t.version = t.version || this.version);
|
|
610
610
|
const i = this.factoryParamOptions(s, t);
|
|
611
611
|
return this.cacheResponse(s, i, void 0, r);
|
|
612
612
|
}
|
|
613
613
|
async getAll(e, t = {}, r, s) {
|
|
614
614
|
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = r ?? n.substring(n.lastIndexOf("/") + 1);
|
|
615
615
|
t.version = t.version || this.version;
|
|
616
|
-
const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1,
|
|
617
|
-
return
|
|
616
|
+
const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, b = await Ae(_e(a, c), (m) => this.makeRequest(n, t, i, m + 1, s));
|
|
617
|
+
return Ee([u, ...b], (m) => Object.values(m.data[l]));
|
|
618
618
|
}
|
|
619
619
|
post(e, t = {}, r) {
|
|
620
|
-
const s = `/${e}`, i =
|
|
620
|
+
const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
|
|
621
621
|
return this.throttleManager.execute(i, "post", s, t, r);
|
|
622
622
|
}
|
|
623
623
|
put(e, t = {}, r) {
|
|
624
|
-
const s = `/${e}`, i =
|
|
624
|
+
const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
|
|
625
625
|
return this.throttleManager.execute(i, "put", s, t, r);
|
|
626
626
|
}
|
|
627
627
|
delete(e, t = {}, r) {
|
|
628
628
|
t || (t = {});
|
|
629
|
-
const s = `/${e}`, i =
|
|
629
|
+
const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
|
|
630
630
|
return this.throttleManager.execute(i, "delete", s, t, r);
|
|
631
631
|
}
|
|
632
632
|
getStories(e = {}, t) {
|
|
@@ -794,39 +794,39 @@ var Ue = class {
|
|
|
794
794
|
}), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
|
|
795
795
|
}
|
|
796
796
|
async cacheResponse(e, t, r, s) {
|
|
797
|
-
const i =
|
|
797
|
+
const i = B({
|
|
798
798
|
url: e,
|
|
799
799
|
params: t
|
|
800
800
|
}), n = this.cacheProvider();
|
|
801
801
|
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
802
|
-
const
|
|
803
|
-
if (
|
|
802
|
+
const c = await n.get(i);
|
|
803
|
+
if (c) return Promise.resolve(c);
|
|
804
804
|
}
|
|
805
|
-
const
|
|
806
|
-
return new Promise(async (
|
|
807
|
-
var
|
|
805
|
+
const a = !j(e) && this.rateLimitConfig.isManagementApi ? N : void 0, u = H(e, t, this.rateLimitConfig, a);
|
|
806
|
+
return new Promise(async (c, b) => {
|
|
807
|
+
var m;
|
|
808
808
|
try {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
811
|
-
let
|
|
812
|
-
data:
|
|
813
|
-
headers:
|
|
809
|
+
const R = await this.throttleManager.execute(u, "get", e, t, s);
|
|
810
|
+
if (R.status !== 200) return b(R);
|
|
811
|
+
let E = {
|
|
812
|
+
data: R.data,
|
|
813
|
+
headers: R.headers
|
|
814
814
|
};
|
|
815
|
-
const
|
|
816
|
-
if ((
|
|
817
|
-
perPage:
|
|
818
|
-
total:
|
|
819
|
-
})),
|
|
820
|
-
const
|
|
821
|
-
await this.resolveStories(
|
|
815
|
+
const _ = Oe(R.headers);
|
|
816
|
+
if ((_ == null ? void 0 : _.max) !== void 0 && (this.rateLimitConfig.serverHeadersRateLimit = _.max), (m = R.headers) != null && m["per-page"] && (E = Object.assign({}, E, {
|
|
817
|
+
perPage: R.headers["per-page"] ? Number.parseInt(R.headers["per-page"]) : 0,
|
|
818
|
+
total: R.headers["per-page"] ? Number.parseInt(R.headers.total) : 0
|
|
819
|
+
})), E.data.story || E.data.stories) {
|
|
820
|
+
const M = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
821
|
+
await this.resolveStories(E.data, t, `${M}`), E = await this.processInlineAssets(E);
|
|
822
822
|
}
|
|
823
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i,
|
|
824
|
-
const
|
|
825
|
-
return t.token &&
|
|
826
|
-
} catch (
|
|
827
|
-
if (
|
|
828
|
-
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(
|
|
829
|
-
|
|
823
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, E);
|
|
824
|
+
const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
825
|
+
return t.token && E.data.cv && (T && S[t.token] && S[t.token] !== E.data.cv && await this.flushCache(), S[t.token] = E.data.cv), c(E);
|
|
826
|
+
} catch (R) {
|
|
827
|
+
if (R.response && R.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
828
|
+
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(c).catch(b);
|
|
829
|
+
b(R);
|
|
830
830
|
}
|
|
831
831
|
});
|
|
832
832
|
}
|
|
@@ -834,32 +834,32 @@ var Ue = class {
|
|
|
834
834
|
return this.client.setFetchOptions(s), this.client[e](t, r);
|
|
835
835
|
}
|
|
836
836
|
cacheVersions() {
|
|
837
|
-
return
|
|
837
|
+
return S;
|
|
838
838
|
}
|
|
839
839
|
cacheVersion() {
|
|
840
|
-
return
|
|
840
|
+
return S[this.accessToken];
|
|
841
841
|
}
|
|
842
842
|
setCacheVersion(e) {
|
|
843
|
-
this.accessToken && (
|
|
843
|
+
this.accessToken && (S[this.accessToken] = e);
|
|
844
844
|
}
|
|
845
845
|
clearCacheVersion() {
|
|
846
|
-
this.accessToken && (
|
|
846
|
+
this.accessToken && (S[this.accessToken] = 0);
|
|
847
847
|
}
|
|
848
848
|
cacheProvider() {
|
|
849
849
|
switch (this.cache.type) {
|
|
850
850
|
case "memory":
|
|
851
851
|
return {
|
|
852
852
|
get(e) {
|
|
853
|
-
return Promise.resolve(
|
|
853
|
+
return Promise.resolve($[e]);
|
|
854
854
|
},
|
|
855
855
|
getAll() {
|
|
856
|
-
return Promise.resolve(
|
|
856
|
+
return Promise.resolve($);
|
|
857
857
|
},
|
|
858
858
|
set(e, t) {
|
|
859
|
-
return
|
|
859
|
+
return $[e] = t, Promise.resolve(void 0);
|
|
860
860
|
},
|
|
861
861
|
flush() {
|
|
862
|
-
return
|
|
862
|
+
return $ = {}, Promise.resolve(void 0);
|
|
863
863
|
}
|
|
864
864
|
};
|
|
865
865
|
case "custom":
|
|
@@ -899,7 +899,7 @@ var Ue = class {
|
|
|
899
899
|
};
|
|
900
900
|
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
|
|
901
901
|
}
|
|
902
|
-
},
|
|
902
|
+
}, Me = $e;
|
|
903
903
|
const je = (e = {}) => {
|
|
904
904
|
const { apiOptions: t } = e;
|
|
905
905
|
if (!t || !t.accessToken) {
|
|
@@ -908,8 +908,8 @@ const je = (e = {}) => {
|
|
|
908
908
|
);
|
|
909
909
|
return;
|
|
910
910
|
}
|
|
911
|
-
return { storyblokApi: new
|
|
912
|
-
},
|
|
911
|
+
return { storyblokApi: new Me(t) };
|
|
912
|
+
}, qe = (e) => {
|
|
913
913
|
if (typeof e != "object" || typeof e._editable > "u")
|
|
914
914
|
return {};
|
|
915
915
|
try {
|
|
@@ -924,8 +924,8 @@ const je = (e = {}) => {
|
|
|
924
924
|
return {};
|
|
925
925
|
}
|
|
926
926
|
};
|
|
927
|
-
let
|
|
928
|
-
const
|
|
927
|
+
let D = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
928
|
+
const Ge = (e, t, r = {}) => {
|
|
929
929
|
var a;
|
|
930
930
|
const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((a = window.location) == null ? void 0 : a.href).searchParams.get(
|
|
931
931
|
"_storyblok"
|
|
@@ -937,13 +937,13 @@ const qe = (e, t, r = {}) => {
|
|
|
937
937
|
}
|
|
938
938
|
window.storyblokRegisterEvent(() => {
|
|
939
939
|
new window.StoryblokBridge(r).on(["input", "published", "change"], (c) => {
|
|
940
|
-
var
|
|
941
|
-
c && (c.action === "input" && ((
|
|
940
|
+
var b;
|
|
941
|
+
c && (c.action === "input" && ((b = c.story) == null ? void 0 : b.id) === e ? t(c.story) : (c.action === "change" || c.action === "published") && c.storyId === e && window.location.reload());
|
|
942
942
|
});
|
|
943
943
|
});
|
|
944
944
|
}
|
|
945
945
|
}, Fe = (e = {}) => {
|
|
946
|
-
var
|
|
946
|
+
var b, m;
|
|
947
947
|
const {
|
|
948
948
|
bridge: t,
|
|
949
949
|
accessToken: r,
|
|
@@ -954,27 +954,27 @@ const qe = (e, t, r = {}) => {
|
|
|
954
954
|
i.accessToken = i.accessToken || r;
|
|
955
955
|
const l = { bridge: t, apiOptions: i };
|
|
956
956
|
let a = {};
|
|
957
|
-
s.forEach((
|
|
958
|
-
a = { ...a, ...
|
|
959
|
-
}), n && (
|
|
960
|
-
const c = !(typeof window > "u") && ((
|
|
961
|
-
return t !== !1 && c &&
|
|
957
|
+
s.forEach((R) => {
|
|
958
|
+
a = { ...a, ...R(l) };
|
|
959
|
+
}), n && (D = n);
|
|
960
|
+
const c = !(typeof window > "u") && ((m = (b = window.location) == null ? void 0 : b.search) == null ? void 0 : m.includes("_storyblok_tk"));
|
|
961
|
+
return t !== !1 && c && Z(D), a;
|
|
962
962
|
};
|
|
963
963
|
function De(e, t) {
|
|
964
964
|
return me(t).render(e);
|
|
965
965
|
}
|
|
966
|
-
const Be = () =>
|
|
966
|
+
const Be = () => Z(D);
|
|
967
967
|
export {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
968
|
+
A as BlockTypes,
|
|
969
|
+
L as MarkTypes,
|
|
970
|
+
Me as StoryblokClient,
|
|
971
971
|
he as TextTypes,
|
|
972
972
|
je as apiPlugin,
|
|
973
973
|
Be as loadStoryblokBridge,
|
|
974
|
-
|
|
974
|
+
Ge as registerStoryblokBridge,
|
|
975
975
|
De as renderRichText,
|
|
976
976
|
me as richTextResolver,
|
|
977
|
-
|
|
977
|
+
qe as storyblokEditable,
|
|
978
978
|
Fe as storyblokInit,
|
|
979
|
-
|
|
979
|
+
Ge as useStoryblokBridge
|
|
980
980
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"storyblok
|
|
32
|
-
"
|
|
31
|
+
"@storyblok/richtext": "3.8.2",
|
|
32
|
+
"storyblok-js-client": "7.2.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tsconfig/recommended": "^1.0.8",
|