@storyblok/js 3.4.0 → 3.5.0
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 +243 -223
- package/package.json +3 -3
package/dist/storyblok-js.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
5
5
|
* author: undefined
|
6
6
|
*/
|
7
|
-
(function(v,
|
7
|
+
(function(v,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(v=typeof globalThis<"u"?globalThis:v||self,I(v.storyblok={}))})(this,function(v){"use strict";let I=!1;const q=[],F=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}I?r():q.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{q.forEach(n=>n()),I=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var Z=Object.defineProperty,ee=(i,e,t)=>e in i?Z(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,m=(i,e,t)=>ee(i,typeof e!="symbol"?e+"":e,t);class te extends Error{constructor(e){super(e),this.name="AbortError"}}function se(i,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0,o=!1;const c=async()=>{n++;const h=s.shift();if(h)try{const d=await i(...h.args);h.resolve(d)}catch(d){h.reject(d)}const u=setTimeout(()=>{n--,s.length>0&&c(),r=r.filter(d=>d!==u)},t);r.includes(u)||r.push(u)},a=(...h)=>o?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((u,d)=>{s.push({resolve:u,reject:d,args:h}),n<e&&c()});return a.abort=()=>{o=!0,r.forEach(clearTimeout),r=[],s.forEach(h=>h.reject(()=>new te("Throttle function aborted"))),s.length=0},a}class x{constructor(){m(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),m(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),m(this,"delay",e=>new Promise(t=>setTimeout(t,e))),m(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),m(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,o)=>o*r+e)}),m(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),m(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),m(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=new RegExp(s.source);return e&&r.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const o=e[n];if(o==null)continue;const c=s?"":encodeURIComponent(n);let a;typeof o=="object"?a=this.stringify(o,t?t+encodeURIComponent(`[${c}]`):c,Array.isArray(o)):a=`${t?t+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(o)}`,r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",n="api-ap.storyblok.com",o="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return n;case"ca":return o;default:return t}}}const re=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},ie=i=>i==="email",ne=()=>({singleTag:"hr"}),oe=()=>({tag:"blockquote"}),ae=()=>({tag:"ul"}),le=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),ce=()=>({singleTag:"br"}),he=i=>({tag:`h${i.attrs.level}`}),ue=i=>({singleTag:[{tag:"img",attrs:re(i.attrs,["src","alt","title"])}]}),de=()=>({tag:"li"}),pe=()=>({tag:"ol"}),ge=()=>({tag:"p"}),fe=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),me=()=>({tag:"b"}),ye=()=>({tag:"s"}),be=()=>({tag:"u"}),ke=()=>({tag:"strong"}),ve=()=>({tag:"code"}),$e=()=>({tag:"i"}),Te=i=>{if(!i.attrs)return{tag:""};const e=new x().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),ie(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},we=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Re=()=>({tag:"sub"}),Ee=()=>({tag:"sup"}),_e=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},Ae=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},G={nodes:{horizontal_rule:ne,blockquote:oe,bullet_list:ae,code_block:le,hard_break:ce,heading:he,image:ue,list_item:de,ordered_list:pe,paragraph:ge,emoji:fe},marks:{bold:me,strike:ye,underline:be,strong:ke,code:ve,italic:$e,link:Te,styled:we,subscript:Re,superscript:Ee,anchor:_e,highlight:Se,textStyle:Ae}},je=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=new RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let J=!1;class O{constructor(e){m(this,"marks"),m(this,"nodes"),e||(e=G),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1},s=!0){if(!J&&s&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),J=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
|
8
8
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
9
9
|
ISbRichtext:
|
10
10
|
content?: ISbRichtext[]
|
@@ -27,4 +27,4 @@
|
|
27
27
|
}
|
28
28
|
],
|
29
29
|
type: 'doc'
|
30
|
-
}`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n=`/filters${n}`))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var h,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(p&&p.length>0){const b={srcset:(h=t.srcset)==null?void 0:h.map(y=>{if(typeof y=="number")return`//${p}/m/${y}x0${n} ${y}w`;if(typeof y=="object"&&y.length===2){let j=0,N=0;return typeof y[0]=="number"&&(j=y[0]),typeof y[1]=="number"&&(N=y[1]),`//${p}/m/${j}x${N}${n} ${j}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(y=>y).join(", ")};let S="";return b.srcset&&(S+=`srcset="${b.srcset}" `),b.sizes&&(S+=`sizes="${b.sizes}" `),a.replace(/<img/g,`<img ${S.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(Ie(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs){for(const o in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,o)){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}};class Ae{constructor(e){m(this,"baseURL"),m(this,"timeout"),m(this,"headers"),m(this,"responseInterceptor"),m(this,"fetch"),m(this,"ejectInterceptor"),m(this,"url"),m(this,"parameters"),m(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;if(e==="get"){const a=new x;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const h=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const V="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let C={};const I={};class Oe{constructor(e,t){m(this,"client"),m(this,"maxRetries"),m(this,"retriesDelay"),m(this,"throttle"),m(this,"accessToken"),m(this,"cache"),m(this,"helpers"),m(this,"resolveCounter"),m(this,"relations"),m(this,"links"),m(this,"richTextResolver"),m(this,"resolveNestedRelations"),m(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new x().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(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,c])=>{r.set(n,c)}),r.has(V)||(r.set(V,H.defaultAgentName),r.set(H.defaultAgentVersion,H.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=se(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new x,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new Ae({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=I[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 this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r,o){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n,void 0,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o,void 0,s)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),c=s??n.substring(n.lastIndexOf("/")+1),a=1,h=await this.makeRequest(n,t,o,a,r),u=h.total?Math.ceil(h.total/o):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),b=>this.makeRequest(n,t,o,b+1,r));return this.helpers.flatMap([h,...p],b=>Object.values(b.data[c]))}post(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t,s))}put(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t,s))}delete(e,t,s){t||(t={});const r=`/${e}`;return Promise.resolve(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(o=>this.getStoryReference(s,o)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(n=>n.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(o):s===o)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((c,a)=>r(c,`${n}[${a}]`));else if(typeof o=="object")for(const c in o){const a=n?`${n}.${c}`:c;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,c,t,s),this._insertLinks(o,c,s)),r(o[c],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const h=Math.min(o,a+c);n.push(e.link_uuids.slice(a,h))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(h=>{r.push(h)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const h=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,h))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{r.push(h)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const o=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await n.get(o);if(c)return Promise.resolve(c)}return new Promise(async(c,a)=>{var h;try{const u=await this.throttle("get",e,t,r);if(u.status!==200)return a(u);let p={data:u.data,headers:u.headers};if((h=u.headers)!=null&&h["per-page"]&&(p=Object.assign({},p,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),p.data.story||p.data.stories){const S=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${S}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,p);const b=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&p.data.cv&&(b&&I[t.token]&&I[t.token]!==p.data.cv&&await this.flushCache(),I[t.token]=p.data.cv),c(p)}catch(u){if(u.response&&u.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 this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return I}cacheVersion(){return I[this.accessToken]}setCacheVersion(e){this.accessToken&&(I[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(I[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(C[e])},getAll(){return Promise.resolve(C)},set(e,t){return C[e]=t,Promise.resolve(void 0)},flush(){return C={},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}}const Le=(i={})=>{const{apiOptions:e}=i;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Oe(e)}},xe=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Ce(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},o=[];function n(a,h,u,p,b){typeof a!="number"||a<=h||a>=u?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${h} and ${u} (inclusive)`):b.push(`${p}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,s=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:a}=e||{},{blur:h,brightness:u,fill:p,format:b,grayscale:S,quality:y,rotate:j}=a||{};h&&n(h,0,100,"blur",o),y&&n(y,0,100,"quality",o),u&&n(u,0,100,"brightness",o),p&&o.push(`fill(${p})`),S&&o.push("grayscale()"),j&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${j})`),b&&["webp","png","jpeg"].includes(b)&&o.push(`format(${b})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${o.length>0?`filters:${o.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[h,u]=a;return`${i}/m/${h}x${u}/${o.length>0?`filters:${o.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let c=`${i}/m/`;return t>0&&s>0&&(c=`${c}${t}x${s}/`),o.length>0&&(c=`${c}filters:${o.join(":")}`),{src:c,attrs:r}}var $=(i=>(i.DOCUMENT="doc",i.HEADING="heading",i.PARAGRAPH="paragraph",i.QUOTE="blockquote",i.OL_LIST="ordered_list",i.UL_LIST="bullet_list",i.LIST_ITEM="list_item",i.CODE_BLOCK="code_block",i.HR="horizontal_rule",i.BR="hard_break",i.IMAGE="image",i.EMOJI="emoji",i.COMPONENT="blok",i.TABLE="table",i.TABLE_ROW="tableRow",i.TABLE_CELL="tableCell",i.TABLE_HEADER="tableHeader",i))($||{}),E=(i=>(i.BOLD="bold",i.STRONG="strong",i.STRIKE="strike",i.UNDERLINE="underline",i.ITALIC="italic",i.CODE="code",i.LINK="link",i.ANCHOR="anchor",i.STYLED="styled",i.SUPERSCRIPT="superscript",i.SUBSCRIPT="subscript",i.TEXT_STYLE="textStyle",i.HIGHLIGHT="highlight",i))(E||{}),B=(i=>(i.TEXT="text",i))(B||{}),L=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(L||{});const Pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ne=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Me=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function He(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const P=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function K(i,e={},t){const s=Ne(e),r=s?`${i} ${s}`:i,o=Array.isArray(t)?t.join(""):t||"";if(i){if(Pe.includes(i))return`<${r}>`}else return o;return`<${r}>${o}</${i}>`}function Be(i={}){const e=new Map,{renderFn:t=K,textFn:s=He,resolvers:r={},optimizeImages:o=!1,keyedResolvers:n=!1}=i,c=t!==K,a=()=>({render:(l,d={},g)=>{if(n&&l){const f=e.get(l)||0;e.set(l,f+1),d.key=`${l}-${f}`}return t(l,d,g)}}),h=l=>(d,g)=>{const f=d.attrs||{};return g.render(l,f,d.children||null)},u=(l,d)=>{const{src:g,alt:f,title:k,srcset:R,sizes:T}=l.attrs||{};let w=g,_={};if(o){const{src:We,attrs:Xe}=Ce(g,o);w=We,_=Xe}const Ye={src:w,alt:f,title:k,srcset:R,sizes:T,..._};return d.render("img",P(Ye))},p=(l,d)=>{const{level:g,...f}=l.attrs||{};return d.render(`h${g}`,f,l.children)},b=(l,d)=>{var g,f,k,R;const T=d.render("img",{src:(g=l.attrs)==null?void 0:g.fallbackImage,alt:(f=l.attrs)==null?void 0:f.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":(k=l.attrs)==null?void 0:k.name,"data-emoji":(R=l.attrs)==null?void 0:R.emoji},T)},S=(l,d)=>d.render("pre",l.attrs||{},d.render("code",{},l.children||"")),y=(l,d=!1)=>({text:g,attrs:f},k)=>{const{class:R,id:T,...w}=f||{},_=d?{class:R,id:T,style:Me(w)||void 0}:f||{};return k.render(l,P(_),g)},j=l=>D(l),N=l=>{const{marks:d,...g}=l;if("text"in l){if(d)return d.reduce((k,R)=>j({...R,text:k}),j({...g,children:g.children}));const f=l.attrs||{};if(n){const k=e.get("txt")||0;e.set("txt",k+1),f.key=`txt-${k}`}return s(g.text,f)}return""},Q=(l,d)=>{const{linktype:g,href:f,anchor:k,...R}=l.attrs||{};let T="";switch(g){case L.ASSET:case L.URL:T=f;break;case L.EMAIL:T=`mailto:${f}`;break;case L.STORY:T=f,k&&(T=`${T}#${k}`);break;default:T=f;break}const w={...R};return T&&(w.href=T),d.render("a",w,l.text)},qe=(l,d)=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),d.render("span",{blok:(g=l==null?void 0:l.attrs)==null?void 0:g.body[0],id:(f=l.attrs)==null?void 0:f.id,style:"display: none"})},Fe=(l,d)=>{const g={},f=d.render("tbody",{},l.children);return d.render("table",g,f)},Ge=(l,d)=>{const g={};return d.render("tr",g,l.children)},Je=(l,d)=>{const{colspan:g,rowspan:f,colwidth:k,backgroundColor:R,...T}=l.attrs||{},w={...T};g>1&&(w.colspan=g),f>1&&(w.rowspan=f);const _=[];return k&&_.push(`width: ${k}px;`),R&&_.push(`background-color: ${R};`),_.length>0&&(w.style=_.join(" ")),d.render("td",P(w),l.children)},Ve=(l,d)=>{const{colspan:g,rowspan:f,colwidth:k,backgroundColor:R,...T}=l.attrs||{},w={...T};g>1&&(w.colspan=g),f>1&&(w.rowspan=f);const _=[];return k&&_.push(`width: ${k}px;`),R&&_.push(`background-color: ${R};`),_.length>0&&(w.style=_.join(" ")),d.render("th",P(w),l.children)},Ke=new Map([[$.DOCUMENT,h("")],[$.HEADING,p],[$.PARAGRAPH,h("p")],[$.UL_LIST,h("ul")],[$.OL_LIST,h("ol")],[$.LIST_ITEM,h("li")],[$.IMAGE,u],[$.EMOJI,b],[$.CODE_BLOCK,S],[$.HR,h("hr")],[$.BR,h("br")],[$.QUOTE,h("blockquote")],[$.COMPONENT,qe],[B.TEXT,N],[E.LINK,Q],[E.ANCHOR,Q],[E.STYLED,y("span",!0)],[E.BOLD,y("strong")],[E.TEXT_STYLE,y("span",!0)],[E.ITALIC,y("em")],[E.UNDERLINE,y("u")],[E.STRIKE,y("s")],[E.CODE,y("code")],[E.SUPERSCRIPT,y("sup")],[E.SUBSCRIPT,y("sub")],[E.HIGHLIGHT,y("mark")],[$.TABLE,Fe],[$.TABLE_ROW,Ge],[$.TABLE_CELL,Je],[$.TABLE_HEADER,Ve],...Object.entries(r).map(([l,d])=>[l,d])]);function M(l){const d=Ke.get(l.type);if(!d)return console.error("<Storyblok>",`No resolver found for node type ${l.type}`),"";const g=a();if(l.type==="text")return d(l,g);const f=l.content?l.content.map(D):void 0;return d({...l,children:f},g)}function D(l){return l.type==="doc"?c?l.content.map(M):l.content.map(M).join(""):Array.isArray(l)?l.map(M):M(l)}return{render:D}}let U,z="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(i,e,t={})=>{var c;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok"),n=o!==null&&+o===i;if(!(!r||!n)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],h=>{var u;h&&(h.action==="input"&&((u=h.story)==null?void 0:u.id)===i?e(h.story):(h.action==="change"||h.action==="published")&&h.storyId===i&&window.location.reload())})})}},W=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Ue=(i={})=>{var p,b;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={},bridgeUrl:n}=i;r.accessToken=r.accessToken||t;const c={bridge:e,apiOptions:r};let a={};s.forEach(S=>{a={...a,...S(c)}}),n&&(z=n);const u=!(typeof window>"u")&&((b=(p=window.location)==null?void 0:p.search)==null?void 0:b.includes("_storyblok_tk"));return e!==!1&&u&&F(z),U=new O(o.schema),o.resolver&&W(U,o.resolver),a},X=i=>{var e;return!i||!((e=i==null?void 0:i.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},ze=(i,e,t)=>{let s=t||U;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return X(i)?"":(e&&(s=new O(e.schema),e.resolver&&W(s,e.resolver)),s.render(i,{},!1))},De=()=>F(z);v.BlockTypes=$,v.MarkTypes=E,v.RichTextResolver=O,v.RichTextSchema=G,v.TextTypes=B,v.apiPlugin=Le,v.isRichTextEmpty=X,v.loadStoryblokBridge=De,v.registerStoryblokBridge=Y,v.renderRichText=ze,v.richTextResolver=Be,v.storyblokEditable=xe,v.storyblokInit=Ue,v.useStoryblokBridge=Y,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
30
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,n="",o="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(o+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(o+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(o+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(o+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(o+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(o+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(o+=`:rotate(${t.filters.rotate})`),o.length>0&&(o=`/filters${o}`))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const c=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var h,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(d&&d.length>0){const b={srcset:(h=t.srcset)==null?void 0:h.map(y=>{if(typeof y=="number")return`//${d}/m/${y}x0${o} ${y}w`;if(typeof y=="object"&&y.length===2){let A=0,N=0;return typeof y[0]=="number"&&(A=y[0]),typeof y[1]=="number"&&(N=y[1]),`//${d}/m/${A}x${N}${o} ${A}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(y=>y).join(", ")};let S="";return b.srcset&&(S+=`srcset="${b.srcset}" `),b.sizes&&(S+=`sizes="${b.sizes}" `),a.replace(/<img/g,`<img ${S.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(je(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs){for(const n in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,n)){const o=s.attrs[n];o!==null&&(r+=` ${n}="${o}"`)}}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class Ie{constructor(e){m(this,"baseURL"),m(this,"timeout"),m(this,"headers"),m(this,"responseInterceptor"),m(this,"fetch"),m(this,"ejectInterceptor"),m(this,"url"),m(this,"parameters"),m(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;if(e==="get"){const a=new x;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:o}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:o,...this.fetchOptions});this.timeout&&clearTimeout(c);const h=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const V="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let C={};const j={};class Oe{constructor(e,t){m(this,"client"),m(this,"maxRetries"),m(this,"retriesDelay"),m(this,"throttle"),m(this,"accessToken"),m(this,"cache"),m(this,"helpers"),m(this,"resolveCounter"),m(this,"relations"),m(this,"links"),m(this,"richTextResolver"),m(this,"resolveNestedRelations"),m(this,"stringifiedStoriesCache"),m(this,"inlineAssets");let s=e.endpoint||t;if(!s){const o=new x().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${o(e.region)}/v1`:s=`${c}://${o(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(([o,c])=>{r.set(o,c)}),r.has(V)||(r.set(V,H.defaultAgentName),r.set(H.defaultAgentVersion,H.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=se(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new x,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.inlineAssets=e.inlineAssets||!1,this.client=new Ie({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=j[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 this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r,n){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o,void 0,n)}get(e,t,s){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,s)}async getAll(e,t,s,r){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`.replace(/\/$/,""),c=s??o.substring(o.lastIndexOf("/")+1),a=1,h=await this.makeRequest(o,t,n,a,r),u=h.total?Math.ceil(h.total/n):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),b=>this.makeRequest(o,t,n,b+1,r));return this.helpers.flatMap([h,...d],b=>Object.values(b.data[c]))}post(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t,s))}put(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t,s))}delete(e,t,s){t||(t={});const r=`/${e}`;return Promise.resolve(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(n=>this.getStoryReference(s,n)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(o=>o.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=(n,o="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,a)=>r(c,`${o}[${a}]`));else if(typeof n=="object")for(const c in n){const a=o?`${o}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,s),this._insertLinks(n,c,s)),r(n[c],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);o.push(e.link_uuids.slice(a,h))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(",")})).data.stories.forEach(h=>{r.push(h)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);o.push(e.rel_uuids.slice(a,h))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{r.push(h)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let o=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.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],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(c=>{this.iterateTree(c,o,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const n=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await o.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,a)=>{var h;try{const u=await this.throttle("get",e,t,r);if(u.status!==200)return a(u);let d={data:u.data,headers:u.headers};if((h=u.headers)!=null&&h["per-page"]&&(d=Object.assign({},d,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),d.data.story||d.data.stories){const S=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${S}`),d=await this.processInlineAssets(d)}t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,d);const b=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&d.data.cv&&(b&&j[t.token]&&j[t.token]!==d.data.cv&&await this.flushCache(),j[t.token]=d.data.cv),c(d)}catch(u){if(u.response&&u.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 this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return j}cacheVersion(){return j[this.accessToken]}setCacheVersion(e){this.accessToken&&(j[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(j[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(C[e])},getAll(){return Promise.resolve(C)},set(e,t){return C[e]=t,Promise.resolve(void 0)},flush(){return C={},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(n=>t(n));let r={...s};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...r,...e.data.assets.find(n=>n.id===r.id)});for(const n in r)typeof r[n]=="object"&&(r[n]=t(r[n]));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}}const Le=(i={})=>{const{apiOptions:e}=i;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Oe(e)}},xe=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Ce(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,h,u,d,b){typeof a!="number"||a<=h||a>=u?console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase()+d.slice(1)} value must be a number between ${h} and ${u} (inclusive)`):b.push(`${d}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,s=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:a}=e||{},{blur:h,brightness:u,fill:d,format:b,grayscale:S,quality:y,rotate:A}=a||{};h&&o(h,0,100,"blur",n),y&&o(y,0,100,"quality",n),u&&o(u,0,100,"brightness",n),d&&n.push(`fill(${d})`),S&&n.push("grayscale()"),A&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${A})`),b&&["webp","png","jpeg"].includes(b)&&n.push(`format(${b})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[h,u]=a;return`${i}/m/${h}x${u}/${n.length>0?`filters:${n.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let c=`${i}/m/`;return t>0&&s>0&&(c=`${c}${t}x${s}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:r}}var $=(i=>(i.DOCUMENT="doc",i.HEADING="heading",i.PARAGRAPH="paragraph",i.QUOTE="blockquote",i.OL_LIST="ordered_list",i.UL_LIST="bullet_list",i.LIST_ITEM="list_item",i.CODE_BLOCK="code_block",i.HR="horizontal_rule",i.BR="hard_break",i.IMAGE="image",i.EMOJI="emoji",i.COMPONENT="blok",i.TABLE="table",i.TABLE_ROW="tableRow",i.TABLE_CELL="tableCell",i.TABLE_HEADER="tableHeader",i))($||{}),E=(i=>(i.BOLD="bold",i.STRONG="strong",i.STRIKE="strike",i.UNDERLINE="underline",i.ITALIC="italic",i.CODE="code",i.LINK="link",i.ANCHOR="anchor",i.STYLED="styled",i.SUPERSCRIPT="superscript",i.SUBSCRIPT="subscript",i.TEXT_STYLE="textStyle",i.HIGHLIGHT="highlight",i))(E||{}),B=(i=>(i.TEXT="text",i))(B||{}),L=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(L||{});const Pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ne=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Me=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function He(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const P=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function K(i,e={},t){const s=Ne(e),r=s?`${i} ${s}`:i,n=Array.isArray(t)?t.join(""):t||"";if(i){if(Pe.includes(i))return`<${r}>`}else return n;return`<${r}>${n}</${i}>`}function Be(i={}){const e=new Map,{renderFn:t=K,textFn:s=He,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,c=t!==K,a=()=>({render:(l,p={},g)=>{if(o&&l){const f=e.get(l)||0;e.set(l,f+1),p.key=`${l}-${f}`}return t(l,p,g)}}),h=l=>(p,g)=>{const f=p.attrs||{};return g.render(l,f,p.children||null)},u=(l,p)=>{const{src:g,alt:f,title:k,srcset:R,sizes:T}=l.attrs||{};let w=g,_={};if(n){const{src:We,attrs:Xe}=Ce(g,n);w=We,_=Xe}const Ye={src:w,alt:f,title:k,srcset:R,sizes:T,..._};return p.render("img",P(Ye))},d=(l,p)=>{const{level:g,...f}=l.attrs||{};return p.render(`h${g}`,f,l.children)},b=(l,p)=>{var g,f,k,R;const T=p.render("img",{src:(g=l.attrs)==null?void 0:g.fallbackImage,alt:(f=l.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return p.render("span",{"data-type":"emoji","data-name":(k=l.attrs)==null?void 0:k.name,"data-emoji":(R=l.attrs)==null?void 0:R.emoji},T)},S=(l,p)=>p.render("pre",l.attrs||{},p.render("code",{},l.children||"")),y=(l,p=!1)=>({text:g,attrs:f},k)=>{const{class:R,id:T,...w}=f||{},_=p?{class:R,id:T,style:Me(w)||void 0}:f||{};return k.render(l,P(_),g)},A=l=>D(l),N=l=>{const{marks:p,...g}=l;if("text"in l){if(p)return p.reduce((k,R)=>A({...R,text:k}),A({...g,children:g.children}));const f=l.attrs||{};if(o){const k=e.get("txt")||0;e.set("txt",k+1),f.key=`txt-${k}`}return s(g.text,f)}return""},Q=(l,p)=>{const{linktype:g,href:f,anchor:k,...R}=l.attrs||{};let T="";switch(g){case L.ASSET:case L.URL:T=f;break;case L.EMAIL:T=`mailto:${f}`;break;case L.STORY:T=f,k&&(T=`${T}#${k}`);break;default:T=f;break}const w={...R};return T&&(w.href=T),p.render("a",w,l.text)},qe=(l,p)=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),p.render("span",{blok:(g=l==null?void 0:l.attrs)==null?void 0:g.body[0],id:(f=l.attrs)==null?void 0:f.id,style:"display: none"})},Fe=(l,p)=>{const g={},f=p.render("tbody",{},l.children);return p.render("table",g,f)},Ge=(l,p)=>{const g={};return p.render("tr",g,l.children)},Je=(l,p)=>{const{colspan:g,rowspan:f,colwidth:k,backgroundColor:R,...T}=l.attrs||{},w={...T};g>1&&(w.colspan=g),f>1&&(w.rowspan=f);const _=[];return k&&_.push(`width: ${k}px;`),R&&_.push(`background-color: ${R};`),_.length>0&&(w.style=_.join(" ")),p.render("td",P(w),l.children)},Ve=(l,p)=>{const{colspan:g,rowspan:f,colwidth:k,backgroundColor:R,...T}=l.attrs||{},w={...T};g>1&&(w.colspan=g),f>1&&(w.rowspan=f);const _=[];return k&&_.push(`width: ${k}px;`),R&&_.push(`background-color: ${R};`),_.length>0&&(w.style=_.join(" ")),p.render("th",P(w),l.children)},Ke=new Map([[$.DOCUMENT,h("")],[$.HEADING,d],[$.PARAGRAPH,h("p")],[$.UL_LIST,h("ul")],[$.OL_LIST,h("ol")],[$.LIST_ITEM,h("li")],[$.IMAGE,u],[$.EMOJI,b],[$.CODE_BLOCK,S],[$.HR,h("hr")],[$.BR,h("br")],[$.QUOTE,h("blockquote")],[$.COMPONENT,qe],[B.TEXT,N],[E.LINK,Q],[E.ANCHOR,Q],[E.STYLED,y("span",!0)],[E.BOLD,y("strong")],[E.TEXT_STYLE,y("span",!0)],[E.ITALIC,y("em")],[E.UNDERLINE,y("u")],[E.STRIKE,y("s")],[E.CODE,y("code")],[E.SUPERSCRIPT,y("sup")],[E.SUBSCRIPT,y("sub")],[E.HIGHLIGHT,y("mark")],[$.TABLE,Fe],[$.TABLE_ROW,Ge],[$.TABLE_CELL,Je],[$.TABLE_HEADER,Ve],...Object.entries(r).map(([l,p])=>[l,p])]);function M(l){const p=Ke.get(l.type);if(!p)return console.error("<Storyblok>",`No resolver found for node type ${l.type}`),"";const g=a();if(l.type==="text")return p(l,g);const f=l.content?l.content.map(D):void 0;return p({...l,children:f},g)}function D(l){return l.type==="doc"?c?l.content.map(M):l.content.map(M).join(""):Array.isArray(l)?l.map(M):M(l)}return{render:D}}let U,z="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(i,e,t={})=>{var c;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok"),o=n!==null&&+n===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],h=>{var u;h&&(h.action==="input"&&((u=h.story)==null?void 0:u.id)===i?e(h.story):(h.action==="change"||h.action==="published")&&h.storyId===i&&window.location.reload())})})}},W=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Ue=(i={})=>{var d,b;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={},bridgeUrl:o}=i;r.accessToken=r.accessToken||t;const c={bridge:e,apiOptions:r};let a={};s.forEach(S=>{a={...a,...S(c)}}),o&&(z=o);const u=!(typeof window>"u")&&((b=(d=window.location)==null?void 0:d.search)==null?void 0:b.includes("_storyblok_tk"));return e!==!1&&u&&F(z),U=new O(n.schema),n.resolver&&W(U,n.resolver),a},X=i=>{var e;return!i||!((e=i==null?void 0:i.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},ze=(i,e,t)=>{let s=t||U;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return X(i)?"":(e&&(s=new O(e.schema),e.resolver&&W(s,e.resolver)),s.render(i,{},!1))},De=()=>F(z);v.BlockTypes=$,v.MarkTypes=E,v.RichTextResolver=O,v.RichTextSchema=G,v.TextTypes=B,v.apiPlugin=Le,v.isRichTextEmpty=X,v.loadStoryblokBridge=De,v.registerStoryblokBridge=Y,v.renderRichText=ze,v.richTextResolver=Be,v.storyblokEditable=xe,v.storyblokInit=Ue,v.useStoryblokBridge=Y,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
@@ -16,11 +16,11 @@ const D = [], J = (i) => new Promise((e, t) => {
|
|
16
16
|
return;
|
17
17
|
const s = document.createElement("script");
|
18
18
|
s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
19
|
-
D.forEach((
|
19
|
+
D.forEach((n) => n()), z = !0, e(r);
|
20
20
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
21
21
|
});
|
22
|
-
var ie = Object.defineProperty,
|
23
|
-
class
|
22
|
+
var ie = Object.defineProperty, ne = (i, e, t) => e in i ? ie(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, m = (i, e, t) => ne(i, typeof e != "symbol" ? e + "" : e, t);
|
23
|
+
class oe extends Error {
|
24
24
|
constructor(e) {
|
25
25
|
super(e), this.name = "AbortError";
|
26
26
|
}
|
@@ -31,35 +31,35 @@ function ae(i, e, t) {
|
|
31
31
|
if (!Number.isFinite(t))
|
32
32
|
throw new TypeError("Expected `interval` to be a finite number");
|
33
33
|
const s = [];
|
34
|
-
let r = [],
|
34
|
+
let r = [], n = 0, o = !1;
|
35
35
|
const c = async () => {
|
36
|
-
|
36
|
+
n++;
|
37
37
|
const h = s.shift();
|
38
38
|
if (h)
|
39
39
|
try {
|
40
|
-
const
|
41
|
-
h.resolve(
|
42
|
-
} catch (
|
43
|
-
h.reject(
|
40
|
+
const d = await i(...h.args);
|
41
|
+
h.resolve(d);
|
42
|
+
} catch (d) {
|
43
|
+
h.reject(d);
|
44
44
|
}
|
45
45
|
const u = setTimeout(() => {
|
46
|
-
|
46
|
+
n--, s.length > 0 && c(), r = r.filter((d) => d !== u);
|
47
47
|
}, t);
|
48
48
|
r.includes(u) || r.push(u);
|
49
|
-
}, a = (...h) =>
|
49
|
+
}, a = (...h) => o ? Promise.reject(
|
50
50
|
new Error(
|
51
51
|
"Throttled function is already aborted and not accepting new promises"
|
52
52
|
)
|
53
|
-
) : new Promise((u,
|
53
|
+
) : new Promise((u, d) => {
|
54
54
|
s.push({
|
55
55
|
resolve: u,
|
56
|
-
reject:
|
56
|
+
reject: d,
|
57
57
|
args: h
|
58
|
-
}),
|
58
|
+
}), n < e && c();
|
59
59
|
});
|
60
60
|
return a.abort = () => {
|
61
|
-
|
62
|
-
(h) => h.reject(() => new
|
61
|
+
o = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
62
|
+
(h) => h.reject(() => new oe("Throttle function aborted"))
|
63
63
|
), s.length = 0;
|
64
64
|
}, a;
|
65
65
|
}
|
@@ -71,7 +71,7 @@ class C {
|
|
71
71
|
page: s
|
72
72
|
})), m(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), m(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), m(this, "range", (e = 0, t = e) => {
|
73
73
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
74
|
-
return this.arrayFrom(s, (
|
74
|
+
return this.arrayFrom(s, (n, o) => o * r + e);
|
75
75
|
}), m(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), m(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), m(this, "escapeHTML", function(e) {
|
76
76
|
const t = {
|
77
77
|
"&": "&",
|
@@ -80,7 +80,7 @@ class C {
|
|
80
80
|
'"': """,
|
81
81
|
"'": "'"
|
82
82
|
}, s = /[&<>"']/g, r = new RegExp(s.source);
|
83
|
-
return e && r.test(e) ? e.replace(s, (
|
83
|
+
return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
|
84
84
|
});
|
85
85
|
}
|
86
86
|
/**
|
@@ -92,19 +92,19 @@ class C {
|
|
92
92
|
*/
|
93
93
|
stringify(e, t, s) {
|
94
94
|
const r = [];
|
95
|
-
for (const
|
96
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
95
|
+
for (const n in e) {
|
96
|
+
if (!Object.prototype.hasOwnProperty.call(e, n))
|
97
97
|
continue;
|
98
|
-
const
|
99
|
-
if (
|
98
|
+
const o = e[n];
|
99
|
+
if (o == null)
|
100
100
|
continue;
|
101
|
-
const c = s ? "" : encodeURIComponent(
|
101
|
+
const c = s ? "" : encodeURIComponent(n);
|
102
102
|
let a;
|
103
|
-
typeof
|
104
|
-
|
103
|
+
typeof o == "object" ? a = this.stringify(
|
104
|
+
o,
|
105
105
|
t ? t + encodeURIComponent(`[${c}]`) : c,
|
106
|
-
Array.isArray(
|
107
|
-
) : a = `${t ? t + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(
|
106
|
+
Array.isArray(o)
|
107
|
+
) : a = `${t ? t + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(o)}`, r.push(a);
|
108
108
|
}
|
109
109
|
return r.join("&");
|
110
110
|
}
|
@@ -114,16 +114,16 @@ class C {
|
|
114
114
|
* @return {string} The base URL of the region
|
115
115
|
*/
|
116
116
|
getRegionURL(e) {
|
117
|
-
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn",
|
117
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
118
118
|
switch (e) {
|
119
119
|
case "us":
|
120
120
|
return s;
|
121
121
|
case "cn":
|
122
122
|
return r;
|
123
123
|
case "ap":
|
124
|
-
return o;
|
125
|
-
case "ca":
|
126
124
|
return n;
|
125
|
+
case "ca":
|
126
|
+
return o;
|
127
127
|
default:
|
128
128
|
return t;
|
129
129
|
}
|
@@ -209,18 +209,18 @@ const le = function(i, e) {
|
|
209
209
|
}
|
210
210
|
]
|
211
211
|
};
|
212
|
-
},
|
212
|
+
}, Ae = (i) => ({
|
213
213
|
tag: [
|
214
214
|
{
|
215
215
|
tag: "span",
|
216
216
|
attrs: i.attrs
|
217
217
|
}
|
218
218
|
]
|
219
|
-
}),
|
219
|
+
}), je = () => ({
|
220
220
|
tag: "sub"
|
221
|
-
}),
|
221
|
+
}), Ie = () => ({
|
222
222
|
tag: "sup"
|
223
|
-
}),
|
223
|
+
}), xe = (i) => ({
|
224
224
|
tag: [
|
225
225
|
{
|
226
226
|
tag: "span",
|
@@ -277,10 +277,10 @@ const le = function(i, e) {
|
|
277
277
|
code: Ee,
|
278
278
|
italic: _e,
|
279
279
|
link: Se,
|
280
|
-
styled:
|
281
|
-
subscript:
|
282
|
-
superscript:
|
283
|
-
anchor:
|
280
|
+
styled: Ae,
|
281
|
+
subscript: je,
|
282
|
+
superscript: Ie,
|
283
|
+
anchor: xe,
|
284
284
|
highlight: Oe,
|
285
285
|
textStyle: Le
|
286
286
|
}
|
@@ -294,7 +294,8 @@ const le = function(i, e) {
|
|
294
294
|
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
295
295
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
296
296
|
};
|
297
|
-
let q = !1
|
297
|
+
let q = !1;
|
298
|
+
class P {
|
298
299
|
constructor(e) {
|
299
300
|
m(this, "marks"), m(this, "nodes"), e || (e = Ce), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
300
301
|
}
|
@@ -309,8 +310,8 @@ let q = !1, P = class {
|
|
309
310
|
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
|
310
311
|
), q = !0), e && e.content && Array.isArray(e.content)) {
|
311
312
|
let r = "";
|
312
|
-
return e.content.forEach((
|
313
|
-
r += this.renderNode(
|
313
|
+
return e.content.forEach((n) => {
|
314
|
+
r += this.renderNode(n);
|
314
315
|
}), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
|
315
316
|
}
|
316
317
|
return console.warn(
|
@@ -341,25 +342,25 @@ let q = !1, P = class {
|
|
341
342
|
), "";
|
342
343
|
}
|
343
344
|
optimizeImages(e, t) {
|
344
|
-
let s = 0, r = 0,
|
345
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
346
|
-
const c = s > 0 || r > 0 ||
|
345
|
+
let s = 0, r = 0, n = "", o = "";
|
346
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = `/filters${o}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
|
347
|
+
const c = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
347
348
|
return e = e.replace(
|
348
349
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
349
350
|
`a.storyblok.com/f/$1/$2.$3/m/${c}`
|
350
351
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
351
352
|
var h, u;
|
352
|
-
const
|
353
|
+
const d = a.match(
|
353
354
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
354
355
|
);
|
355
|
-
if (
|
356
|
+
if (d && d.length > 0) {
|
356
357
|
const b = {
|
357
358
|
srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
|
358
359
|
if (typeof y == "number")
|
359
|
-
return `//${
|
360
|
+
return `//${d}/m/${y}x0${o} ${y}w`;
|
360
361
|
if (typeof y == "object" && y.length === 2) {
|
361
|
-
let S = 0,
|
362
|
-
return typeof y[0] == "number" && (S = y[0]), typeof y[1] == "number" && (
|
362
|
+
let S = 0, I = 0;
|
363
|
+
return typeof y[0] == "number" && (S = y[0]), typeof y[1] == "number" && (I = y[1]), `//${d}/m/${S}x${I}${o} ${S}w`;
|
363
364
|
}
|
364
365
|
return "";
|
365
366
|
}).join(", "),
|
@@ -374,15 +375,15 @@ let q = !1, P = class {
|
|
374
375
|
renderNode(e) {
|
375
376
|
const t = [];
|
376
377
|
e.marks && e.marks.forEach((r) => {
|
377
|
-
const
|
378
|
-
|
378
|
+
const n = this.getMatchingMark(r);
|
379
|
+
n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
|
379
380
|
});
|
380
381
|
const s = this.getMatchingNode(e);
|
381
382
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
382
383
|
t.push(this.renderNode(r));
|
383
384
|
}) : e.text ? t.push(Pe(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
|
384
|
-
const
|
385
|
-
|
385
|
+
const n = this.getMatchingMark(r);
|
386
|
+
n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
|
386
387
|
}), t.join("");
|
387
388
|
}
|
388
389
|
renderTag(e, t) {
|
@@ -392,10 +393,10 @@ let q = !1, P = class {
|
|
392
393
|
{
|
393
394
|
let r = `<${s.tag}`;
|
394
395
|
if (s.attrs) {
|
395
|
-
for (const
|
396
|
-
if (Object.prototype.hasOwnProperty.call(s.attrs,
|
397
|
-
const
|
398
|
-
|
396
|
+
for (const n in s.attrs)
|
397
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
|
398
|
+
const o = s.attrs[n];
|
399
|
+
o !== null && (r += ` ${n}="${o}"`);
|
399
400
|
}
|
400
401
|
}
|
401
402
|
return `${r}${t}>`;
|
@@ -434,7 +435,7 @@ let q = !1, P = class {
|
|
434
435
|
];
|
435
436
|
return this.renderTag(t, " /");
|
436
437
|
}
|
437
|
-
}
|
438
|
+
}
|
438
439
|
class Ne {
|
439
440
|
constructor(e) {
|
440
441
|
m(this, "baseURL"), m(this, "timeout"), m(this, "headers"), m(this, "responseInterceptor"), m(this, "fetch"), m(this, "ejectInterceptor"), m(this, "url"), m(this, "parameters"), m(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 = {};
|
@@ -480,15 +481,15 @@ class Ne {
|
|
480
481
|
)}`;
|
481
482
|
} else
|
482
483
|
s = JSON.stringify(this.parameters);
|
483
|
-
const r = new URL(t),
|
484
|
+
const r = new URL(t), n = new AbortController(), { signal: o } = n;
|
484
485
|
let c;
|
485
|
-
this.timeout && (c = setTimeout(() =>
|
486
|
+
this.timeout && (c = setTimeout(() => n.abort(), this.timeout));
|
486
487
|
try {
|
487
488
|
const a = await this.fetch(`${r}`, {
|
488
489
|
method: e,
|
489
490
|
headers: this.headers,
|
490
491
|
body: s,
|
491
|
-
signal:
|
492
|
+
signal: o,
|
492
493
|
...this.fetchOptions
|
493
494
|
});
|
494
495
|
this.timeout && clearTimeout(c);
|
@@ -513,12 +514,12 @@ class Ne {
|
|
513
514
|
return new Promise((s, r) => {
|
514
515
|
if (t.test(`${e.status}`))
|
515
516
|
return s(e);
|
516
|
-
const
|
517
|
+
const n = {
|
517
518
|
message: e.statusText,
|
518
519
|
status: e.status,
|
519
520
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
520
521
|
};
|
521
|
-
r(
|
522
|
+
r(n);
|
522
523
|
});
|
523
524
|
}
|
524
525
|
}
|
@@ -528,7 +529,7 @@ const F = "SB-Agent", H = {
|
|
528
529
|
packageVersion: "6.0.0"
|
529
530
|
};
|
530
531
|
let O = {};
|
531
|
-
const
|
532
|
+
const A = {};
|
532
533
|
class He {
|
533
534
|
/**
|
534
535
|
*
|
@@ -536,25 +537,25 @@ class He {
|
|
536
537
|
* @param pEndpoint string, optional
|
537
538
|
*/
|
538
539
|
constructor(e, t) {
|
539
|
-
m(this, "client"), m(this, "maxRetries"), m(this, "retriesDelay"), m(this, "throttle"), m(this, "accessToken"), m(this, "cache"), m(this, "helpers"), m(this, "resolveCounter"), m(this, "relations"), m(this, "links"), m(this, "richTextResolver"), m(this, "resolveNestedRelations"), m(this, "stringifiedStoriesCache");
|
540
|
+
m(this, "client"), m(this, "maxRetries"), m(this, "retriesDelay"), m(this, "throttle"), m(this, "accessToken"), m(this, "cache"), m(this, "helpers"), m(this, "resolveCounter"), m(this, "relations"), m(this, "links"), m(this, "richTextResolver"), m(this, "resolveNestedRelations"), m(this, "stringifiedStoriesCache"), m(this, "inlineAssets");
|
540
541
|
let s = e.endpoint || t;
|
541
542
|
if (!s) {
|
542
|
-
const
|
543
|
-
e.oauthToken ? s = `${c}://${
|
543
|
+
const o = new C().getRegionURL, c = e.https === !1 ? "http" : "https";
|
544
|
+
e.oauthToken ? s = `${c}://${o(e.region)}/v1` : s = `${c}://${o(e.region)}/v2`;
|
544
545
|
}
|
545
546
|
const r = new Headers();
|
546
|
-
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(([
|
547
|
-
r.set(
|
547
|
+
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(([o, c]) => {
|
548
|
+
r.set(o, c);
|
548
549
|
}), r.has(F) || (r.set(F, H.defaultAgentName), r.set(
|
549
550
|
H.defaultAgentVersion,
|
550
551
|
H.packageVersion
|
551
552
|
));
|
552
|
-
let
|
553
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
553
|
+
let n = 5;
|
554
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new P(e.richTextSchema) : this.richTextResolver = new P(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ae(
|
554
555
|
this.throttledRequest.bind(this),
|
555
|
-
|
556
|
+
n,
|
556
557
|
1e3
|
557
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new C(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Ne({
|
558
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new C(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.inlineAssets = e.inlineAssets || !1, this.client = new Ne({
|
558
559
|
baseURL: s,
|
559
560
|
timeout: e.timeout || 0,
|
560
561
|
headers: r,
|
@@ -573,35 +574,35 @@ class He {
|
|
573
574
|
});
|
574
575
|
}
|
575
576
|
parseParams(e) {
|
576
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
577
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = A[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
577
578
|
}
|
578
579
|
factoryParamOptions(e, t) {
|
579
580
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
580
581
|
}
|
581
|
-
makeRequest(e, t, s, r,
|
582
|
-
const
|
582
|
+
makeRequest(e, t, s, r, n) {
|
583
|
+
const o = this.factoryParamOptions(
|
583
584
|
e,
|
584
585
|
this.helpers.getOptionsPage(t, s, r)
|
585
586
|
);
|
586
|
-
return this.cacheResponse(e,
|
587
|
+
return this.cacheResponse(e, o, void 0, n);
|
587
588
|
}
|
588
589
|
get(e, t, s) {
|
589
590
|
t || (t = {});
|
590
|
-
const r = `/${e}`,
|
591
|
-
return this.cacheResponse(r,
|
591
|
+
const r = `/${e}`, n = this.factoryParamOptions(r, t);
|
592
|
+
return this.cacheResponse(r, n, void 0, s);
|
592
593
|
}
|
593
594
|
async getAll(e, t, s, r) {
|
594
|
-
const
|
595
|
-
n,
|
596
|
-
t,
|
595
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`.replace(/\/$/, ""), c = s ?? o.substring(o.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
|
597
596
|
o,
|
597
|
+
t,
|
598
|
+
n,
|
598
599
|
a,
|
599
600
|
r
|
600
|
-
), u = h.total ? Math.ceil(h.total /
|
601
|
+
), u = h.total ? Math.ceil(h.total / n) : 1, d = await this.helpers.asyncMap(
|
601
602
|
this.helpers.range(a, u),
|
602
|
-
(b) => this.makeRequest(
|
603
|
+
(b) => this.makeRequest(o, t, n, b + 1, r)
|
603
604
|
);
|
604
|
-
return this.helpers.flatMap([h, ...
|
605
|
+
return this.helpers.flatMap([h, ...d], (b) => Object.values(b.data[c]));
|
605
606
|
}
|
606
607
|
post(e, t, s) {
|
607
608
|
const r = `/${e}`;
|
@@ -666,7 +667,7 @@ class He {
|
|
666
667
|
_resolveField(e, t, s) {
|
667
668
|
const r = e[t];
|
668
669
|
typeof r == "string" ? e[t] = this.getStoryReference(s, r) : Array.isArray(r) && (e[t] = r.map(
|
669
|
-
(
|
670
|
+
(n) => this.getStoryReference(s, n)
|
670
671
|
).filter(Boolean));
|
671
672
|
}
|
672
673
|
/**
|
@@ -687,12 +688,12 @@ class He {
|
|
687
688
|
* allowing flexible specification of relation patterns.
|
688
689
|
*/
|
689
690
|
_insertRelations(e, t, s, r) {
|
690
|
-
if (Array.isArray(s) ? s.find((
|
691
|
+
if (Array.isArray(s) ? s.find((o) => o.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
|
691
692
|
this._resolveField(e, t, r);
|
692
693
|
return;
|
693
694
|
}
|
694
|
-
const
|
695
|
-
(Array.isArray(s) ? s.includes(
|
695
|
+
const n = e.component ? `${e.component}.${t}` : t;
|
696
|
+
(Array.isArray(s) ? s.includes(n) : s === n) && this._resolveField(e, t, r);
|
696
697
|
}
|
697
698
|
/**
|
698
699
|
* Recursively traverses and resolves relations in the story content tree
|
@@ -701,14 +702,14 @@ class He {
|
|
701
702
|
* @param resolveId - The unique identifier for the current resolution context
|
702
703
|
*/
|
703
704
|
iterateTree(e, t, s) {
|
704
|
-
const r = (
|
705
|
-
if (!(!
|
706
|
-
if (Array.isArray(
|
707
|
-
|
708
|
-
else if (typeof
|
709
|
-
for (const c in
|
710
|
-
const a =
|
711
|
-
(
|
705
|
+
const r = (n, o = "") => {
|
706
|
+
if (!(!n || n._stopResolving)) {
|
707
|
+
if (Array.isArray(n))
|
708
|
+
n.forEach((c, a) => r(c, `${o}[${a}]`));
|
709
|
+
else if (typeof n == "object")
|
710
|
+
for (const c in n) {
|
711
|
+
const a = o ? `${o}.${c}` : c;
|
712
|
+
(n.component && n._uid || n.type === "link") && (this._insertRelations(n, c, t, s), this._insertLinks(n, c, s)), r(n[c], a);
|
712
713
|
}
|
713
714
|
}
|
714
715
|
};
|
@@ -717,18 +718,18 @@ class He {
|
|
717
718
|
async resolveLinks(e, t, s) {
|
718
719
|
let r = [];
|
719
720
|
if (e.link_uuids) {
|
720
|
-
const
|
721
|
-
for (let a = 0; a <
|
722
|
-
const h = Math.min(
|
723
|
-
|
721
|
+
const n = e.link_uuids.length, o = [], c = 50;
|
722
|
+
for (let a = 0; a < n; a += c) {
|
723
|
+
const h = Math.min(n, a + c);
|
724
|
+
o.push(e.link_uuids.slice(a, h));
|
724
725
|
}
|
725
|
-
for (let a = 0; a <
|
726
|
+
for (let a = 0; a < o.length; a++)
|
726
727
|
(await this.getStories({
|
727
728
|
per_page: c,
|
728
729
|
language: t.language,
|
729
730
|
version: t.version,
|
730
731
|
starts_with: t.starts_with,
|
731
|
-
by_uuids:
|
732
|
+
by_uuids: o[a].join(",")
|
732
733
|
})).data.stories.forEach(
|
733
734
|
(h) => {
|
734
735
|
r.push(h);
|
@@ -736,9 +737,9 @@ class He {
|
|
736
737
|
);
|
737
738
|
} else
|
738
739
|
r = e.links;
|
739
|
-
r.forEach((
|
740
|
-
this.links[s][
|
741
|
-
...
|
740
|
+
r.forEach((n) => {
|
741
|
+
this.links[s][n.uuid] = {
|
742
|
+
...n,
|
742
743
|
_stopResolving: !0
|
743
744
|
};
|
744
745
|
});
|
@@ -746,27 +747,28 @@ class He {
|
|
746
747
|
async resolveRelations(e, t, s) {
|
747
748
|
let r = [];
|
748
749
|
if (e.rel_uuids) {
|
749
|
-
const
|
750
|
-
for (let a = 0; a <
|
751
|
-
const h = Math.min(
|
752
|
-
|
750
|
+
const n = e.rel_uuids.length, o = [], c = 50;
|
751
|
+
for (let a = 0; a < n; a += c) {
|
752
|
+
const h = Math.min(n, a + c);
|
753
|
+
o.push(e.rel_uuids.slice(a, h));
|
753
754
|
}
|
754
|
-
for (let a = 0; a <
|
755
|
+
for (let a = 0; a < o.length; a++)
|
755
756
|
(await this.getStories({
|
756
757
|
per_page: c,
|
757
758
|
language: t.language,
|
758
759
|
version: t.version,
|
759
760
|
starts_with: t.starts_with,
|
760
|
-
by_uuids:
|
761
|
+
by_uuids: o[a].join(","),
|
761
762
|
excluding_fields: t.excluding_fields
|
762
763
|
})).data.stories.forEach((h) => {
|
763
764
|
r.push(h);
|
764
765
|
});
|
766
|
+
r.length > 0 && (e.rels = r, delete e.rel_uuids);
|
765
767
|
} else
|
766
768
|
r = e.rels;
|
767
|
-
r && r.length > 0 && r.forEach((
|
768
|
-
this.relations[s][
|
769
|
-
...
|
769
|
+
r && r.length > 0 && r.forEach((n) => {
|
770
|
+
this.relations[s][n.uuid] = {
|
771
|
+
...n,
|
770
772
|
_stopResolving: !0
|
771
773
|
};
|
772
774
|
});
|
@@ -781,23 +783,23 @@ class He {
|
|
781
783
|
*
|
782
784
|
*/
|
783
785
|
async resolveStories(e, t, s) {
|
784
|
-
var r,
|
785
|
-
let
|
786
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
786
|
+
var r, n;
|
787
|
+
let o = [];
|
788
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
787
789
|
for (const c in this.relations[s])
|
788
790
|
this.iterateTree(
|
789
791
|
this.relations[s][c],
|
790
|
-
|
792
|
+
o,
|
791
793
|
s
|
792
794
|
);
|
793
|
-
e.story ? this.iterateTree(e.story,
|
794
|
-
this.iterateTree(c,
|
795
|
+
e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((c) => {
|
796
|
+
this.iterateTree(c, o, s);
|
795
797
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
796
798
|
}
|
797
799
|
async cacheResponse(e, t, s, r) {
|
798
|
-
const
|
800
|
+
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
799
801
|
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
800
|
-
const c = await
|
802
|
+
const c = await o.get(n);
|
801
803
|
if (c)
|
802
804
|
return Promise.resolve(c);
|
803
805
|
}
|
@@ -812,17 +814,17 @@ class He {
|
|
812
814
|
);
|
813
815
|
if (u.status !== 200)
|
814
816
|
return a(u);
|
815
|
-
let
|
816
|
-
if ((h = u.headers) != null && h["per-page"] && (
|
817
|
+
let d = { data: u.data, headers: u.headers };
|
818
|
+
if ((h = u.headers) != null && h["per-page"] && (d = Object.assign({}, d, {
|
817
819
|
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
818
820
|
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
819
|
-
})),
|
821
|
+
})), d.data.story || d.data.stories) {
|
820
822
|
const _ = this.resolveCounter = ++this.resolveCounter % 1e3;
|
821
|
-
await this.resolveStories(
|
823
|
+
await this.resolveStories(d.data, t, `${_}`), d = await this.processInlineAssets(d);
|
822
824
|
}
|
823
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await
|
825
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, d);
|
824
826
|
const b = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
825
|
-
return t.token &&
|
827
|
+
return t.token && d.data.cv && (b && A[t.token] && A[t.token] !== d.data.cv && await this.flushCache(), A[t.token] = d.data.cv), c(d);
|
826
828
|
} catch (u) {
|
827
829
|
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
828
830
|
return console.log(
|
@@ -836,16 +838,16 @@ class He {
|
|
836
838
|
return this.client.setFetchOptions(r), this.client[e](t, s);
|
837
839
|
}
|
838
840
|
cacheVersions() {
|
839
|
-
return
|
841
|
+
return A;
|
840
842
|
}
|
841
843
|
cacheVersion() {
|
842
|
-
return
|
844
|
+
return A[this.accessToken];
|
843
845
|
}
|
844
846
|
setCacheVersion(e) {
|
845
|
-
this.accessToken && (
|
847
|
+
this.accessToken && (A[this.accessToken] = e);
|
846
848
|
}
|
847
849
|
clearCacheVersion() {
|
848
|
-
this.accessToken && (
|
850
|
+
this.accessToken && (A[this.accessToken] = 0);
|
849
851
|
}
|
850
852
|
cacheProvider() {
|
851
853
|
switch (this.cache.type) {
|
@@ -867,7 +869,6 @@ class He {
|
|
867
869
|
case "custom":
|
868
870
|
if (this.cache.custom)
|
869
871
|
return this.cache.custom;
|
870
|
-
// eslint-disable-next-line no-fallthrough
|
871
872
|
default:
|
872
873
|
return {
|
873
874
|
get() {
|
@@ -888,8 +889,27 @@ class He {
|
|
888
889
|
async flushCache() {
|
889
890
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
890
891
|
}
|
892
|
+
async processInlineAssets(e) {
|
893
|
+
if (!this.inlineAssets)
|
894
|
+
return e;
|
895
|
+
const t = (s) => {
|
896
|
+
if (!s || typeof s != "object")
|
897
|
+
return s;
|
898
|
+
if (Array.isArray(s))
|
899
|
+
return s.map((n) => t(n));
|
900
|
+
let r = { ...s };
|
901
|
+
r.fieldtype === "asset" && Array.isArray(e.data.assets) && (r = {
|
902
|
+
...r,
|
903
|
+
...e.data.assets.find((n) => n.id === r.id)
|
904
|
+
});
|
905
|
+
for (const n in r)
|
906
|
+
typeof r[n] == "object" && (r[n] = t(r[n]));
|
907
|
+
return r;
|
908
|
+
};
|
909
|
+
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;
|
910
|
+
}
|
891
911
|
}
|
892
|
-
const
|
912
|
+
const Fe = (i = {}) => {
|
893
913
|
const { apiOptions: e } = i;
|
894
914
|
if (!e || !e.accessToken) {
|
895
915
|
console.error(
|
@@ -898,7 +918,7 @@ const Ge = (i = {}) => {
|
|
898
918
|
return;
|
899
919
|
}
|
900
920
|
return { storyblokApi: new He(e) };
|
901
|
-
},
|
921
|
+
}, Ge = (i) => {
|
902
922
|
if (typeof i != "object" || typeof i._editable > "u")
|
903
923
|
return {};
|
904
924
|
try {
|
@@ -917,21 +937,21 @@ function Me(i, e) {
|
|
917
937
|
if (!e)
|
918
938
|
return { src: i, attrs: {} };
|
919
939
|
let t = 0, s = 0;
|
920
|
-
const r = {},
|
921
|
-
function
|
922
|
-
typeof a != "number" || a <= h || a >= u ? console.warn(`[StoryblokRichText] - ${
|
940
|
+
const r = {}, n = [];
|
941
|
+
function o(a, h, u, d, b) {
|
942
|
+
typeof a != "number" || a <= h || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${h} and ${u} (inclusive)`) : b.push(`${d}(${a})`);
|
923
943
|
}
|
924
944
|
if (typeof e == "object") {
|
925
945
|
if (typeof e.width == "number" && e.width > 0 ? (r.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (r.height = e.height, s = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (r.loading = e.loading), e.class && (r.class = e.class), e.filters) {
|
926
|
-
const { filters: a } = e || {}, { blur: h, brightness: u, fill:
|
927
|
-
h &&
|
946
|
+
const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: b, grayscale: _, quality: y, rotate: S } = a || {};
|
947
|
+
h && o(h, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), d && n.push(`fill(${d})`), _ && n.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${S})`), b && ["webp", "png", "jpeg"].includes(b) && n.push(`format(${b})`);
|
928
948
|
}
|
929
949
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
930
950
|
if (typeof a == "number")
|
931
|
-
return `${i}/m/${a}x0/${
|
951
|
+
return `${i}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
|
932
952
|
if (Array.isArray(a) && a.length === 2) {
|
933
953
|
const [h, u] = a;
|
934
|
-
return `${i}/m/${h}x${u}/${
|
954
|
+
return `${i}/m/${h}x${u}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${h}w`;
|
935
955
|
} else {
|
936
956
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
937
957
|
return;
|
@@ -939,12 +959,12 @@ function Me(i, e) {
|
|
939
959
|
}).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
|
940
960
|
}
|
941
961
|
let c = `${i}/m/`;
|
942
|
-
return t > 0 && s > 0 && (c = `${c}${t}x${s}/`),
|
962
|
+
return t > 0 && s > 0 && (c = `${c}${t}x${s}/`), n.length > 0 && (c = `${c}filters:${n.join(":")}`), {
|
943
963
|
src: c,
|
944
964
|
attrs: r
|
945
965
|
};
|
946
966
|
}
|
947
|
-
var $ = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i.TABLE = "table", i.TABLE_ROW = "tableRow", i.TABLE_CELL = "tableCell", i.TABLE_HEADER = "tableHeader", i))($ || {}), E = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(E || {}), V = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(V || {}),
|
967
|
+
var $ = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i.TABLE = "table", i.TABLE_ROW = "tableRow", i.TABLE_CELL = "tableCell", i.TABLE_HEADER = "tableHeader", i))($ || {}), E = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(E || {}), V = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(V || {}), j = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(j || {});
|
948
968
|
const Be = [
|
949
969
|
"area",
|
950
970
|
"base",
|
@@ -966,34 +986,34 @@ function De(i) {
|
|
966
986
|
}
|
967
987
|
const L = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
|
968
988
|
function G(i, e = {}, t) {
|
969
|
-
const s = Ue(e), r = s ? `${i} ${s}` : i,
|
989
|
+
const s = Ue(e), r = s ? `${i} ${s}` : i, n = Array.isArray(t) ? t.join("") : t || "";
|
970
990
|
if (i) {
|
971
991
|
if (Be.includes(i))
|
972
992
|
return `<${r}>`;
|
973
|
-
} else return
|
974
|
-
return `<${r}>${
|
993
|
+
} else return n;
|
994
|
+
return `<${r}>${n}</${i}>`;
|
975
995
|
}
|
976
|
-
function
|
996
|
+
function Je(i = {}) {
|
977
997
|
const e = /* @__PURE__ */ new Map(), {
|
978
998
|
renderFn: t = G,
|
979
999
|
textFn: s = De,
|
980
1000
|
resolvers: r = {},
|
981
|
-
optimizeImages:
|
982
|
-
keyedResolvers:
|
983
|
-
} = i, c = t !== G, a = () => ({ render: (l,
|
984
|
-
if (
|
1001
|
+
optimizeImages: n = !1,
|
1002
|
+
keyedResolvers: o = !1
|
1003
|
+
} = i, c = t !== G, a = () => ({ render: (l, p = {}, g) => {
|
1004
|
+
if (o && l) {
|
985
1005
|
const f = e.get(l) || 0;
|
986
|
-
e.set(l, f + 1),
|
1006
|
+
e.set(l, f + 1), p.key = `${l}-${f}`;
|
987
1007
|
}
|
988
|
-
return t(l,
|
989
|
-
} }), h = (l) => (
|
990
|
-
const f =
|
991
|
-
return g.render(l, f,
|
992
|
-
}, u = (l,
|
1008
|
+
return t(l, p, g);
|
1009
|
+
} }), h = (l) => (p, g) => {
|
1010
|
+
const f = p.attrs || {};
|
1011
|
+
return g.render(l, f, p.children || null);
|
1012
|
+
}, u = (l, p) => {
|
993
1013
|
const { src: g, alt: f, title: k, srcset: w, sizes: v } = l.attrs || {};
|
994
1014
|
let T = g, R = {};
|
995
|
-
if (
|
996
|
-
const { src: se, attrs: re } = Me(g,
|
1015
|
+
if (n) {
|
1016
|
+
const { src: se, attrs: re } = Me(g, n);
|
997
1017
|
T = se, R = re;
|
998
1018
|
}
|
999
1019
|
const te = {
|
@@ -1004,63 +1024,63 @@ function Ve(i = {}) {
|
|
1004
1024
|
sizes: v,
|
1005
1025
|
...R
|
1006
1026
|
};
|
1007
|
-
return
|
1008
|
-
},
|
1027
|
+
return p.render("img", L(te));
|
1028
|
+
}, d = (l, p) => {
|
1009
1029
|
const { level: g, ...f } = l.attrs || {};
|
1010
|
-
return
|
1011
|
-
}, b = (l,
|
1030
|
+
return p.render(`h${g}`, f, l.children);
|
1031
|
+
}, b = (l, p) => {
|
1012
1032
|
var g, f, k, w;
|
1013
|
-
const v =
|
1033
|
+
const v = p.render("img", {
|
1014
1034
|
src: (g = l.attrs) == null ? void 0 : g.fallbackImage,
|
1015
1035
|
alt: (f = l.attrs) == null ? void 0 : f.alt,
|
1016
1036
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
1017
1037
|
draggable: "false",
|
1018
1038
|
loading: "lazy"
|
1019
1039
|
});
|
1020
|
-
return
|
1040
|
+
return p.render("span", {
|
1021
1041
|
"data-type": "emoji",
|
1022
1042
|
"data-name": (k = l.attrs) == null ? void 0 : k.name,
|
1023
1043
|
"data-emoji": (w = l.attrs) == null ? void 0 : w.emoji
|
1024
1044
|
}, v);
|
1025
|
-
}, _ = (l,
|
1045
|
+
}, _ = (l, p) => p.render(
|
1026
1046
|
"pre",
|
1027
1047
|
l.attrs || {},
|
1028
|
-
|
1029
|
-
), y = (l,
|
1030
|
-
const { class: w, id: v, ...T } = f || {}, R =
|
1048
|
+
p.render("code", {}, l.children || "")
|
1049
|
+
), y = (l, p = !1) => ({ text: g, attrs: f }, k) => {
|
1050
|
+
const { class: w, id: v, ...T } = f || {}, R = p ? {
|
1031
1051
|
class: w,
|
1032
1052
|
id: v,
|
1033
1053
|
style: ze(T) || void 0
|
1034
1054
|
} : f || {};
|
1035
1055
|
return k.render(l, L(R), g);
|
1036
|
-
}, S = (l) => N(l),
|
1037
|
-
const { marks:
|
1056
|
+
}, S = (l) => N(l), I = (l) => {
|
1057
|
+
const { marks: p, ...g } = l;
|
1038
1058
|
if ("text" in l) {
|
1039
|
-
if (
|
1040
|
-
return
|
1059
|
+
if (p)
|
1060
|
+
return p.reduce(
|
1041
1061
|
(k, w) => S({ ...w, text: k }),
|
1042
1062
|
S({ ...g, children: g.children })
|
1043
1063
|
);
|
1044
1064
|
const f = l.attrs || {};
|
1045
|
-
if (
|
1065
|
+
if (o) {
|
1046
1066
|
const k = e.get("txt") || 0;
|
1047
1067
|
e.set("txt", k + 1), f.key = `txt-${k}`;
|
1048
1068
|
}
|
1049
1069
|
return s(g.text, f);
|
1050
1070
|
}
|
1051
1071
|
return "";
|
1052
|
-
}, U = (l,
|
1072
|
+
}, U = (l, p) => {
|
1053
1073
|
const { linktype: g, href: f, anchor: k, ...w } = l.attrs || {};
|
1054
1074
|
let v = "";
|
1055
1075
|
switch (g) {
|
1056
|
-
case
|
1057
|
-
case
|
1076
|
+
case j.ASSET:
|
1077
|
+
case j.URL:
|
1058
1078
|
v = f;
|
1059
1079
|
break;
|
1060
|
-
case
|
1080
|
+
case j.EMAIL:
|
1061
1081
|
v = `mailto:${f}`;
|
1062
1082
|
break;
|
1063
|
-
case
|
1083
|
+
case j.STORY:
|
1064
1084
|
v = f, k && (v = `${v}#${k}`);
|
1065
1085
|
break;
|
1066
1086
|
default:
|
@@ -1068,37 +1088,37 @@ function Ve(i = {}) {
|
|
1068
1088
|
break;
|
1069
1089
|
}
|
1070
1090
|
const T = { ...w };
|
1071
|
-
return v && (T.href = v),
|
1072
|
-
}, Y = (l,
|
1091
|
+
return v && (T.href = v), p.render("a", T, l.text);
|
1092
|
+
}, Y = (l, p) => {
|
1073
1093
|
var g, f;
|
1074
|
-
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),
|
1094
|
+
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), p.render("span", {
|
1075
1095
|
blok: (g = l == null ? void 0 : l.attrs) == null ? void 0 : g.body[0],
|
1076
1096
|
id: (f = l.attrs) == null ? void 0 : f.id,
|
1077
1097
|
style: "display: none"
|
1078
1098
|
});
|
1079
|
-
}, W = (l,
|
1080
|
-
const g = {}, f =
|
1081
|
-
return
|
1082
|
-
}, X = (l,
|
1099
|
+
}, W = (l, p) => {
|
1100
|
+
const g = {}, f = p.render("tbody", {}, l.children);
|
1101
|
+
return p.render("table", g, f);
|
1102
|
+
}, X = (l, p) => {
|
1083
1103
|
const g = {};
|
1084
|
-
return
|
1085
|
-
}, Q = (l,
|
1104
|
+
return p.render("tr", g, l.children);
|
1105
|
+
}, Q = (l, p) => {
|
1086
1106
|
const { colspan: g, rowspan: f, colwidth: k, backgroundColor: w, ...v } = l.attrs || {}, T = {
|
1087
1107
|
...v
|
1088
1108
|
};
|
1089
1109
|
g > 1 && (T.colspan = g), f > 1 && (T.rowspan = f);
|
1090
1110
|
const R = [];
|
1091
|
-
return k && R.push(`width: ${k}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (T.style = R.join(" ")),
|
1092
|
-
}, Z = (l,
|
1111
|
+
return k && R.push(`width: ${k}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (T.style = R.join(" ")), p.render("td", L(T), l.children);
|
1112
|
+
}, Z = (l, p) => {
|
1093
1113
|
const { colspan: g, rowspan: f, colwidth: k, backgroundColor: w, ...v } = l.attrs || {}, T = {
|
1094
1114
|
...v
|
1095
1115
|
};
|
1096
1116
|
g > 1 && (T.colspan = g), f > 1 && (T.rowspan = f);
|
1097
1117
|
const R = [];
|
1098
|
-
return k && R.push(`width: ${k}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (T.style = R.join(" ")),
|
1118
|
+
return k && R.push(`width: ${k}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (T.style = R.join(" ")), p.render("th", L(T), l.children);
|
1099
1119
|
}, ee = new Map([
|
1100
1120
|
[$.DOCUMENT, h("")],
|
1101
|
-
[$.HEADING,
|
1121
|
+
[$.HEADING, d],
|
1102
1122
|
[$.PARAGRAPH, h("p")],
|
1103
1123
|
[$.UL_LIST, h("ul")],
|
1104
1124
|
[$.OL_LIST, h("ol")],
|
@@ -1110,7 +1130,7 @@ function Ve(i = {}) {
|
|
1110
1130
|
[$.BR, h("br")],
|
1111
1131
|
[$.QUOTE, h("blockquote")],
|
1112
1132
|
[$.COMPONENT, Y],
|
1113
|
-
[V.TEXT,
|
1133
|
+
[V.TEXT, I],
|
1114
1134
|
[E.LINK, U],
|
1115
1135
|
[E.ANCHOR, U],
|
1116
1136
|
[E.STYLED, y("span", !0)],
|
@@ -1127,35 +1147,35 @@ function Ve(i = {}) {
|
|
1127
1147
|
[$.TABLE_ROW, X],
|
1128
1148
|
[$.TABLE_CELL, Q],
|
1129
1149
|
[$.TABLE_HEADER, Z],
|
1130
|
-
...Object.entries(r).map(([l,
|
1150
|
+
...Object.entries(r).map(([l, p]) => [l, p])
|
1131
1151
|
]);
|
1132
|
-
function
|
1133
|
-
const
|
1134
|
-
if (!
|
1152
|
+
function x(l) {
|
1153
|
+
const p = ee.get(l.type);
|
1154
|
+
if (!p)
|
1135
1155
|
return console.error("<Storyblok>", `No resolver found for node type ${l.type}`), "";
|
1136
1156
|
const g = a();
|
1137
1157
|
if (l.type === "text")
|
1138
|
-
return
|
1158
|
+
return p(l, g);
|
1139
1159
|
const f = l.content ? l.content.map(N) : void 0;
|
1140
|
-
return
|
1160
|
+
return p({
|
1141
1161
|
...l,
|
1142
1162
|
children: f
|
1143
1163
|
}, g);
|
1144
1164
|
}
|
1145
1165
|
function N(l) {
|
1146
|
-
return l.type === "doc" ? c ? l.content.map(
|
1166
|
+
return l.type === "doc" ? c ? l.content.map(x) : l.content.map(x).join("") : Array.isArray(l) ? l.map(x) : x(l);
|
1147
1167
|
}
|
1148
1168
|
return {
|
1149
1169
|
render: N
|
1150
1170
|
};
|
1151
1171
|
}
|
1152
1172
|
let M, B = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
1153
|
-
const
|
1173
|
+
const Ve = (i, e, t = {}) => {
|
1154
1174
|
var c;
|
1155
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
1175
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((c = window.location) == null ? void 0 : c.href).searchParams.get(
|
1156
1176
|
"_storyblok"
|
1157
|
-
),
|
1158
|
-
if (!(!r || !
|
1177
|
+
), o = n !== null && +n === i;
|
1178
|
+
if (!(!r || !o)) {
|
1159
1179
|
if (!i) {
|
1160
1180
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
1161
1181
|
return;
|
@@ -1176,28 +1196,28 @@ const Ke = (i, e, t = {}) => {
|
|
1176
1196
|
html: s
|
1177
1197
|
};
|
1178
1198
|
});
|
1179
|
-
},
|
1180
|
-
var
|
1199
|
+
}, Ke = (i = {}) => {
|
1200
|
+
var d, b;
|
1181
1201
|
const {
|
1182
1202
|
bridge: e,
|
1183
1203
|
accessToken: t,
|
1184
1204
|
use: s = [],
|
1185
1205
|
apiOptions: r = {},
|
1186
|
-
richText:
|
1187
|
-
bridgeUrl:
|
1206
|
+
richText: n = {},
|
1207
|
+
bridgeUrl: o
|
1188
1208
|
} = i;
|
1189
1209
|
r.accessToken = r.accessToken || t;
|
1190
1210
|
const c = { bridge: e, apiOptions: r };
|
1191
1211
|
let a = {};
|
1192
1212
|
s.forEach((_) => {
|
1193
1213
|
a = { ...a, ..._(c) };
|
1194
|
-
}),
|
1195
|
-
const u = !(typeof window > "u") && ((b = (
|
1196
|
-
return e !== !1 && u && J(B), M = new P(
|
1214
|
+
}), o && (B = o);
|
1215
|
+
const u = !(typeof window > "u") && ((b = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : b.includes("_storyblok_tk"));
|
1216
|
+
return e !== !1 && u && J(B), M = new P(n.schema), n.resolver && K(M, n.resolver), a;
|
1197
1217
|
}, qe = (i) => {
|
1198
1218
|
var e;
|
1199
1219
|
return !i || !((e = i == null ? void 0 : i.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
1200
|
-
},
|
1220
|
+
}, Ye = (i, e, t) => {
|
1201
1221
|
let s = t || M;
|
1202
1222
|
if (!s) {
|
1203
1223
|
console.error(
|
@@ -1206,20 +1226,20 @@ const Ke = (i, e, t = {}) => {
|
|
1206
1226
|
return;
|
1207
1227
|
}
|
1208
1228
|
return qe(i) ? "" : (e && (s = new P(e.schema), e.resolver && K(s, e.resolver)), s.render(i, {}, !1));
|
1209
|
-
},
|
1229
|
+
}, We = () => J(B);
|
1210
1230
|
export {
|
1211
1231
|
$ as BlockTypes,
|
1212
1232
|
E as MarkTypes,
|
1213
1233
|
P as RichTextResolver,
|
1214
1234
|
Ce as RichTextSchema,
|
1215
1235
|
V as TextTypes,
|
1216
|
-
|
1236
|
+
Fe as apiPlugin,
|
1217
1237
|
qe as isRichTextEmpty,
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1238
|
+
We as loadStoryblokBridge,
|
1239
|
+
Ve as registerStoryblokBridge,
|
1240
|
+
Ye as renderRichText,
|
1241
|
+
Je as richTextResolver,
|
1242
|
+
Ge as storyblokEditable,
|
1243
|
+
Ke as storyblokInit,
|
1244
|
+
Ve as useStoryblokBridge
|
1225
1245
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storyblok/js",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.
|
4
|
+
"version": "3.5.0",
|
5
5
|
"private": false,
|
6
6
|
"packageManager": "pnpm@10.2.0",
|
7
7
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
@@ -44,7 +44,7 @@
|
|
44
44
|
},
|
45
45
|
"dependencies": {
|
46
46
|
"@storyblok/richtext": "3.2.0",
|
47
|
-
"storyblok-js-client": "6.
|
47
|
+
"storyblok-js-client": "6.11.0"
|
48
48
|
},
|
49
49
|
"devDependencies": {
|
50
50
|
"@commitlint/cli": "^19.7.1",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"@storyblok/eslint-config": "^0.3.0",
|
53
53
|
"@tsconfig/recommended": "^1.0.8",
|
54
54
|
"@types/node": "^22.13.1",
|
55
|
-
"@vitest/ui": "3.1.
|
55
|
+
"@vitest/ui": "3.1.3",
|
56
56
|
"cypress": "^13.17.0",
|
57
57
|
"eslint": "^9.19.0",
|
58
58
|
"eslint-plugin-cypress": "^4.1.0",
|