@storyblok/js 3.2.5 → 3.3.1
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 +302 -275
- package/package.json +7 -5
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(
|
7
|
+
(function($,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):($=typeof globalThis<"u"?globalThis:$||self,I($.storyblok={}))})(this,function($){"use strict";let I=!1;const D=[],q=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():D.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=>{D.forEach(n=>n()),I=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var X=Object.defineProperty,Q=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,g=(i,e,t)=>Q(i,typeof e!="symbol"?e+"":e,t);class Z extends Error{constructor(e){super(e),this.name="AbortError"}}function ee(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 l=async()=>{n++;const h=s.shift();if(h)try{const p=await i(...h.args);h.resolve(p)}catch(p){h.reject(p)}const u=setTimeout(()=>{n--,s.length>0&&l(),r=r.filter(p=>p!==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,p)=>{s.push({resolve:u,reject:p,args:h}),n<e&&l()});return a.abort=()=>{o=!0,r.forEach(clearTimeout),r=[],s.forEach(h=>h.reject(()=>new Z("Throttle function aborted"))),s.length=0},a}class x{constructor(){g(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),g(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),g(this,"delay",e=>new Promise(t=>setTimeout(t,e))),g(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),g(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)}),g(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),g(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),g(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 l=s?"":encodeURIComponent(n);let a;typeof o=="object"?a=this.stringify(o,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(o)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${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 te=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},se=i=>i==="email",re=()=>({singleTag:"hr"}),ie=()=>({tag:"blockquote"}),ne=()=>({tag:"ul"}),oe=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),ae=()=>({singleTag:"br"}),le=i=>({tag:`h${i.attrs.level}`}),ce=i=>({singleTag:[{tag:"img",attrs:te(i.attrs,["src","alt","title"])}]}),he=()=>({tag:"li"}),ue=()=>({tag:"ol"}),de=()=>({tag:"p"}),pe=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),ge=()=>({tag:"b"}),fe=()=>({tag:"s"}),me=()=>({tag:"u"}),ye=()=>({tag:"strong"}),be=()=>({tag:"code"}),ke=()=>({tag:"i"}),$e=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||"")),se(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}]}},ve=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Te=()=>({tag:"sub"}),we=()=>({tag:"sup"}),Re=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Ee=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},_e=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},F={nodes:{horizontal_rule:re,blockquote:ie,bullet_list:ne,code_block:oe,hard_break:ae,heading:le,image:ce,list_item:he,ordered_list:ue,paragraph:de,emoji:pe},marks:{bold:ge,strike:fe,underline:me,strong:ye,code:be,italic:ke,link:$e,styled:ve,subscript:Te,superscript:we,anchor:Re,highlight:Ee,textStyle:_e}},Se=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=new RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let G=!1;class A{constructor(e){g(this,"marks"),g(this,"nodes"),e||(e=F),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(!G&&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/"),G=!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 l=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/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(d&&d.length>0){const m={srcset:(c=t.srcset)==null?void 0:c.map(k=>{if(typeof k=="number")return`//${d}/m/${k}x0${n} ${k}w`;if(typeof k=="object"&&k.length===2){let E=0,x=0;return typeof k[0]=="number"&&(E=k[0]),typeof k[1]=="number"&&(x=k[1]),`//${d}/m/${E}x${x}${n} ${E}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(k=>k).join(", ")};let y="";return m.srcset&&(y+=`srcset="${m.srcset}" `),m.sizes&&(y+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${y.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(Ee(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 je{constructor(e){p(this,"baseURL"),p(this,"timeout"),p(this,"headers"),p(this,"responseInterceptor"),p(this,"fetch"),p(this,"ejectInterceptor"),p(this,"url"),p(this,"parameters"),p(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new L;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 l;this.timeout&&(l=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(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}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 G="SB-Agent",N={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let P={};const _={};class Ie{constructor(e,t){p(this,"client"),p(this,"maxRetries"),p(this,"retriesDelay"),p(this,"throttle"),p(this,"accessToken"),p(this,"cache"),p(this,"helpers"),p(this,"resolveCounter"),p(this,"relations"),p(this,"links"),p(this,"richTextResolver"),p(this,"resolveNestedRelations"),p(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new L().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${n(e.region)}/v1`:s=`${l}://${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,l])=>{r.set(n,l)}),r.has(G)||(r.set(G,N.defaultAgentName),r.set(N.defaultAgentVersion,N.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=ee(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new L,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new je({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=_[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(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1),a=1,c=await this.makeRequest(n,t,o,a,r),u=c.total?Math.ceil(c.total/o):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),m=>this.makeRequest(n,t,o,m+1,r));return this.helpers.flatMap([c,...d],m=>Object.values(m.data[l]))}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((l,a)=>r(l,`${n}[${a}]`));else if(typeof o=="object")for(const l in o){const a=n?`${n}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,s),this._insertLinks(o,l,s)),r(o[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(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=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}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 l in this.relations[s])this.iterateTree(this.relations[s][l],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(l=>{this.iterateTree(l,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 l=await n.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;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((c=u.headers)!=null&&c["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 y=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${y}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,d);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&d.data.cv&&(m&&_[t.token]&&_[t.token]!==d.data.cv&&await this.flushCache(),_[t.token]=d.data.cv),l(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(l).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return _}cacheVersion(){return _[this.accessToken]}setCacheVersion(e){this.accessToken&&(_[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(_[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}}const Oe=(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 Ie(e)}},Ae=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 xe(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},o=[];function n(a,c,u,d,m){typeof a!="number"||a<=c||a>=u?console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase()+d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`):m.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:c,brightness:u,fill:d,format:m,grayscale:y,quality:k,rotate:E}=a||{};c&&n(c,0,100,"blur",o),k&&n(k,0,100,"quality",o),u&&n(u,0,100,"brightness",o),d&&o.push(`fill(${d})`),y&&o.push("grayscale()"),E&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${E})`),m&&["webp","png","jpeg"].includes(m)&&o.push(`format(${m})`)}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[c,u]=a;return`${i}/m/${c}x${u}/${o.length>0?`filters:${o.join(":")}`:""} ${c}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 l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:r}}var v=(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))(v||{}),T=(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))(T||{}),M=(i=>(i.TEXT="text",i))(M||{}),A=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(A||{});const Le=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Ce=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Ne(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const V=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function J(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i,o=Array.isArray(t)?t.join(""):t||"";if(i){if(Le.includes(i))return`<${r}>`}else return o;return`<${r}>${o}</${i}>`}function Me(i={}){let e=0;const{renderFn:t=J,textFn:s=Ne,resolvers:r={},optimizeImages:o=!1,keyedResolvers:n=!1}=i,l=t!==J,a=h=>g=>{const f=g.attrs||{};return n&&(f.key=`${h}-${e}`),t(h,f,g.children||null)},c=h=>{const{src:g,alt:f,title:$,srcset:S,sizes:w}=h.attrs||{};let R=g,j={};if(o){const{src:Fe,attrs:Ge}=xe(g,o);R=Fe,j=Ge}n&&(j={...j,key:`img-${e}`});const qe={src:R,alt:f,title:$,srcset:S,sizes:w,...j};return t("img",V(qe))},u=h=>{const{level:g,...f}=h.attrs||{},$={...f};return n&&($.key=`h${g}-${e}`),t(`h${g}`,$,h.children)},d=h=>{var g,f,$,S;const w=t("img",{src:(g=h.attrs)==null?void 0:g.fallbackImage,alt:(f=h.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),R={"data-type":"emoji","data-name":($=h.attrs)==null?void 0:$.name,"data-emoji":(S=h.attrs)==null?void 0:S.emoji};return n&&(R.key=`emoji-${e}`),t("span",R,w)},m=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),y=(h,g=!1)=>({text:f,attrs:$})=>{const{class:S,id:w,...R}=$||{},j=g?{class:S,id:w,style:Ce(R)||void 0}:$||{};return n&&(j.key=`${h}-${e}`),t(h,V(j),f)},k=h=>z(h),E=h=>{const{marks:g,...f}=h;return"text"in h?g?g.reduce(($,S)=>k({...S,text:$}),k({...f,children:f.children})):s(f.text):""},x=h=>{const{linktype:g,href:f,anchor:$,...S}=h.attrs||{};let w="";switch(g){case A.ASSET:case A.URL:w=f;break;case A.EMAIL:w=`mailto:${f}`;break;case A.STORY:w=f,$&&(w=`${w}#${$}`);break;default:w=f;break}const R={...S};return w&&(R.href=w),n&&(R.key=`a-${e}`),t("a",R,h.text)},Be=h=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(g=h==null?void 0:h.attrs)==null?void 0:g.body[0],id:(f=h.attrs)==null?void 0:f.id,key:`component-${e}`,style:"display: none"})},De=new Map([[v.DOCUMENT,a("")],[v.HEADING,u],[v.PARAGRAPH,a("p")],[v.UL_LIST,a("ul")],[v.OL_LIST,a("ol")],[v.LIST_ITEM,a("li")],[v.IMAGE,c],[v.EMOJI,d],[v.CODE_BLOCK,m],[v.HR,a("hr")],[v.BR,a("br")],[v.QUOTE,a("blockquote")],[v.COMPONENT,Be],[M.TEXT,E],[T.LINK,x],[T.ANCHOR,x],[T.STYLED,y("span",!0)],[T.BOLD,y("strong")],[T.TEXT_STYLE,y("span",!0)],[T.ITALIC,y("em")],[T.UNDERLINE,y("u")],[T.STRIKE,y("s")],[T.CODE,y("code")],[T.SUPERSCRIPT,y("sup")],[T.SUBSCRIPT,y("sub")],[T.HIGHLIGHT,y("mark")],...Object.entries(r).map(([h,g])=>[h,g])]);function C(h){e+=1;const g=De.get(h.type);if(!g)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return g(h);const f=h.content?h.content.map(z):void 0;return g({...h,children:f})}function z(h){return h.type==="doc"?l?h.content.map(C):h.content.map(C).join(""):Array.isArray(h)?h.map(C):C(h)}return{render:z}}let H,U="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(i,e,t={})=>{var l;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((l=window.location)==null?void 0:l.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"],c=>{var u;c&&(c.action==="input"&&((u=c.story)==null?void 0:u.id)===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload())})})}},Y=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},He=(i={})=>{var d,m;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={},bridgeUrl:n}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(y=>{a={...a,...y(l)}}),n&&(U=n);const u=!(typeof window>"u")&&((m=(d=window.location)==null?void 0:d.search)==null?void 0:m.includes("_storyblok_tk"));return e!==!1&&u&&D(U),H=new O(o.schema),o.resolver&&Y(H,o.resolver),a},W=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"))},Ue=(i,e,t)=>{let s=t||H;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return W(i)?"":(e&&(s=new O(e.schema),e.resolver&&Y(s,e.resolver)),s.render(i,{},!1))},ze=()=>D(U);b.BlockTypes=v,b.MarkTypes=T,b.RichTextResolver=O,b.RichTextSchema=q,b.TextTypes=M,b.apiPlugin=Oe,b.isRichTextEmpty=W,b.loadStoryblokBridge=ze,b.registerStoryblokBridge=K,b.renderRichText=Ue,b.richTextResolver=Me,b.storyblokEditable=Ae,b.storyblokInit=He,b.useStoryblokBridge=K,Object.defineProperty(b,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 l=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/${l}`),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 y={srcset:(h=t.srcset)==null?void 0:h.map(w=>{if(typeof w=="number")return`//${p}/m/${w}x0${o} ${w}w`;if(typeof w=="object"&&w.length===2){let j=0,L=0;return typeof w[0]=="number"&&(j=w[0]),typeof w[1]=="number"&&(L=w[1]),`//${p}/m/${j}x${L}${o} ${j}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(w=>w).join(", ")};let k="";return y.srcset&&(k+=`srcset="${y.srcset}" `),y.sizes&&(k+=`sizes="${y.sizes}" `),a.replace(/<img/g,`<img ${k.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(Se(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 je{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(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 l;this.timeout&&(l=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(l);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 S={};class Ie{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"helpers"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const o=new x().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${o(e.region)}/v1`:s=`${l}://${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,l])=>{r.set(o,l)}),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 A(e.richTextSchema):this.richTextResolver=new A,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ee(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.client=new je({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=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}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(/\/$/,""),l=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,p=await this.helpers.asyncMap(this.helpers.range(a,u),y=>this.makeRequest(o,t,n,y+1,r));return this.helpers.flatMap([h,...p],y=>Object.values(y.data[l]))}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((l,a)=>r(l,`${o}[${a}]`));else if(typeof n=="object")for(const l in n){const a=o?`${o}.${l}`:l;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,l,t,s),this._insertLinks(n,l,s)),r(n[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const h=Math.min(n,a+l);o.push(e.link_uuids.slice(a,h))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,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=[],l=50;for(let a=0;a<n;a+=l){const h=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,h))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,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)})}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 l in this.relations[s])this.iterateTree(this.relations[s][l],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(l=>{this.iterateTree(l,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 l=await o.get(n);if(l)return Promise.resolve(l)}return new Promise(async(l,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 k=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${k}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,p);const y=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&p.data.cv&&(y&&S[t.token]&&S[t.token]!==p.data.cv&&await this.flushCache(),S[t.token]=p.data.cv),l(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(l).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[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 Ae=(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 Ie(e)}},Oe=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 Le(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,h,u,p,y){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)`):y.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:y,grayscale:k,quality:w,rotate:j}=a||{};h&&o(h,0,100,"blur",n),w&&o(w,0,100,"quality",n),u&&o(u,0,100,"brightness",n),p&&n.push(`fill(${p})`),k&&n.push("grayscale()"),j&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${j})`),y&&["webp","png","jpeg"].includes(y)&&n.push(`format(${y})`)}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 l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:r}}var v=(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))(v||{}),_=(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))(_||{}),B=(i=>(i.TEXT="text",i))(B||{}),O=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(O||{});const xe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ce=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Pe=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Ne(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 J(i,e={},t){const s=Ce(e),r=s?`${i} ${s}`:i,n=Array.isArray(t)?t.join(""):t||"";if(i){if(xe.includes(i))return`<${r}>`}else return n;return`<${r}>${n}</${i}>`}function He(i={}){let e=0;const{renderFn:t=J,textFn:s=Ne,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,l=t!==J,a=c=>d=>{const f=d.attrs||{};return o&&(f.key=`${c}-${e}`),t(c,f,d.children||null)},h=c=>{const{src:d,alt:f,title:b,srcset:E,sizes:T}=c.attrs||{};let m=d,R={};if(n){const{src:Ke,attrs:Ye}=Le(d,n);m=Ke,R=Ye}o&&(R={...R,key:`img-${e}`});const Je={src:m,alt:f,title:b,srcset:E,sizes:T,...R};return t("img",P(Je))},u=c=>{const{level:d,...f}=c.attrs||{},b={...f};return o&&(b.key=`h${d}-${e}`),t(`h${d}`,b,c.children)},p=c=>{var d,f,b,E;const T=t("img",{src:(d=c.attrs)==null?void 0:d.fallbackImage,alt:(f=c.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),m={"data-type":"emoji","data-name":(b=c.attrs)==null?void 0:b.name,"data-emoji":(E=c.attrs)==null?void 0:E.emoji};return o&&(m.key=`emoji-${e}`),t("span",m,T)},y=c=>t("pre",{...c.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},c.children||"")),k=(c,d=!1)=>({text:f,attrs:b})=>{const{class:E,id:T,...m}=b||{},R=d?{class:E,id:T,style:Pe(m)||void 0}:b||{};return o&&(R.key=`${c}-${e}`),t(c,P(R),f)},w=c=>z(c),j=c=>{const{marks:d,...f}=c;return"text"in c?d?d.reduce((b,E)=>w({...E,text:b}),w({...f,children:f.children})):s(f.text):""},L=c=>{const{linktype:d,href:f,anchor:b,...E}=c.attrs||{};let T="";switch(d){case O.ASSET:case O.URL:T=f;break;case O.EMAIL:T=`mailto:${f}`;break;case O.STORY:T=f,b&&(T=`${T}#${b}`);break;default:T=f;break}const m={...E};return T&&(m.href=T),o&&(m.key=`a-${e}`),t("a",m,c.text)},ze=c=>{var d,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(d=c==null?void 0:c.attrs)==null?void 0:d.body[0],id:(f=c.attrs)==null?void 0:f.id,key:`component-${e}`,style:"display: none"})},De=c=>{const d={};return o&&(d.key=`table-${e}`),t("table",d,c.children)},qe=c=>{const d={};return o&&(d.key=`tr-${e}`),t("tr",d,c.children)},Fe=c=>{const{colspan:d,rowspan:f,colwidth:b,backgroundColor:E,...T}=c.attrs||{},m={...T};d>1&&(m.colspan=d),f>1&&(m.rowspan=f);const R=[];return b&&R.push(`width: ${b}px;`),E&&R.push(`background-color: ${E};`),R.length>0&&(m.style=R.join(" ")),o&&(m.key=`td-${e}`),t("td",P(m),c.children)},Ge=c=>{const{colspan:d,rowspan:f,colwidth:b,backgroundColor:E,...T}=c.attrs||{},m={...T};d>1&&(m.colspan=d),f>1&&(m.rowspan=f);const R=[];return b&&R.push(`width: ${b}px;`),E&&R.push(`background-color: ${E};`),R.length>0&&(m.style=R.join(" ")),o&&(m.key=`th-${e}`),t("th",P(m),c.children)},Ve=new Map([[v.DOCUMENT,a("")],[v.HEADING,u],[v.PARAGRAPH,a("p")],[v.UL_LIST,a("ul")],[v.OL_LIST,a("ol")],[v.LIST_ITEM,a("li")],[v.IMAGE,h],[v.EMOJI,p],[v.CODE_BLOCK,y],[v.HR,a("hr")],[v.BR,a("br")],[v.QUOTE,a("blockquote")],[v.COMPONENT,ze],[B.TEXT,j],[_.LINK,L],[_.ANCHOR,L],[_.STYLED,k("span",!0)],[_.BOLD,k("strong")],[_.TEXT_STYLE,k("span",!0)],[_.ITALIC,k("em")],[_.UNDERLINE,k("u")],[_.STRIKE,k("s")],[_.CODE,k("code")],[_.SUPERSCRIPT,k("sup")],[_.SUBSCRIPT,k("sub")],[_.HIGHLIGHT,k("mark")],[v.TABLE,De],[v.TABLE_ROW,qe],[v.TABLE_CELL,Fe],[v.TABLE_HEADER,Ge],...Object.entries(r).map(([c,d])=>[c,d])]);function N(c){e+=1;const d=Ve.get(c.type);if(!d)return console.error("<Storyblok>",`No resolver found for node type ${c.type}`),"";if(c.type==="text")return d(c);const f=c.content?c.content.map(z):void 0;return d({...c,children:f})}function z(c){return c.type==="doc"?l?c.content.map(N):c.content.map(N).join(""):Array.isArray(c)?c.map(N):N(c)}return{render:z}}let M,U="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(i,e,t={})=>{var l;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((l=window.location)==null?void 0:l.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())})})}},Y=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Be=(i={})=>{var p,y;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={},bridgeUrl:o}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(k=>{a={...a,...k(l)}}),o&&(U=o);const u=!(typeof window>"u")&&((y=(p=window.location)==null?void 0:p.search)==null?void 0:y.includes("_storyblok_tk"));return e!==!1&&u&&q(U),M=new A(n.schema),n.resolver&&Y(M,n.resolver),a},W=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"))},Me=(i,e,t)=>{let s=t||M;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return W(i)?"":(e&&(s=new A(e.schema),e.resolver&&Y(s,e.resolver)),s.render(i,{},!1))},Ue=()=>q(U);$.BlockTypes=v,$.MarkTypes=_,$.RichTextResolver=A,$.RichTextSchema=F,$.TextTypes=B,$.apiPlugin=Ae,$.isRichTextEmpty=W,$.loadStoryblokBridge=Ue,$.registerStoryblokBridge=K,$.renderRichText=Me,$.richTextResolver=He,$.storyblokEditable=Oe,$.storyblokInit=Be,$.useStoryblokBridge=K,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
@@ -4,28 +4,28 @@
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
5
5
|
* author: undefined
|
6
6
|
*/
|
7
|
-
let
|
7
|
+
let B = !1;
|
8
8
|
const U = [], F = (i) => new Promise((e, t) => {
|
9
9
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
10
10
|
if (window.location === window.parent.location) {
|
11
11
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
12
12
|
return;
|
13
13
|
}
|
14
|
-
|
14
|
+
B ? r() : U.push(r);
|
15
15
|
}, document.getElementById("storyblok-javascript-bridge")))
|
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
|
-
U.forEach((o) => o()),
|
19
|
+
U.forEach((o) => o()), B = !0, e(r);
|
20
20
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
21
21
|
});
|
22
|
-
var
|
23
|
-
class
|
22
|
+
var se = Object.defineProperty, re = (i, e, t) => e in i ? se(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, g = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
|
23
|
+
class ie extends Error {
|
24
24
|
constructor(e) {
|
25
25
|
super(e), this.name = "AbortError";
|
26
26
|
}
|
27
27
|
}
|
28
|
-
function
|
28
|
+
function oe(i, e, t) {
|
29
29
|
if (!Number.isFinite(e))
|
30
30
|
throw new TypeError("Expected `limit` to be a finite number");
|
31
31
|
if (!Number.isFinite(t))
|
@@ -34,45 +34,45 @@ function te(i, e, t) {
|
|
34
34
|
let r = [], o = 0, n = !1;
|
35
35
|
const l = async () => {
|
36
36
|
o++;
|
37
|
-
const
|
38
|
-
if (
|
37
|
+
const h = s.shift();
|
38
|
+
if (h)
|
39
39
|
try {
|
40
|
-
const
|
41
|
-
|
42
|
-
} catch (
|
43
|
-
|
40
|
+
const p = await i(...h.args);
|
41
|
+
h.resolve(p);
|
42
|
+
} catch (p) {
|
43
|
+
h.reject(p);
|
44
44
|
}
|
45
45
|
const u = setTimeout(() => {
|
46
|
-
o--, s.length > 0 && l(), r = r.filter((
|
46
|
+
o--, s.length > 0 && l(), r = r.filter((p) => p !== u);
|
47
47
|
}, t);
|
48
48
|
r.includes(u) || r.push(u);
|
49
|
-
}, a = (...
|
49
|
+
}, a = (...h) => n ? 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, p) => {
|
54
54
|
s.push({
|
55
55
|
resolve: u,
|
56
|
-
reject:
|
57
|
-
args:
|
56
|
+
reject: p,
|
57
|
+
args: h
|
58
58
|
}), o < e && l();
|
59
59
|
});
|
60
60
|
return a.abort = () => {
|
61
61
|
n = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
62
|
-
(
|
62
|
+
(h) => h.reject(() => new ie("Throttle function aborted"))
|
63
63
|
), s.length = 0;
|
64
64
|
}, a;
|
65
65
|
}
|
66
|
-
|
66
|
+
class L {
|
67
67
|
constructor() {
|
68
|
-
|
68
|
+
g(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), g(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
69
69
|
...e,
|
70
70
|
per_page: t,
|
71
71
|
page: s
|
72
|
-
})),
|
72
|
+
})), g(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), g(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), g(this, "range", (e = 0, t = e) => {
|
73
73
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
74
74
|
return this.arrayFrom(s, (o, n) => n * r + e);
|
75
|
-
}),
|
75
|
+
}), g(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), g(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), g(this, "escapeHTML", function(e) {
|
76
76
|
const t = {
|
77
77
|
"&": "&",
|
78
78
|
"<": "<",
|
@@ -95,7 +95,10 @@ let A = class {
|
|
95
95
|
for (const o in e) {
|
96
96
|
if (!Object.prototype.hasOwnProperty.call(e, o))
|
97
97
|
continue;
|
98
|
-
const n = e[o]
|
98
|
+
const n = e[o];
|
99
|
+
if (n == null)
|
100
|
+
continue;
|
101
|
+
const l = s ? "" : encodeURIComponent(o);
|
99
102
|
let a;
|
100
103
|
typeof n == "object" ? a = this.stringify(
|
101
104
|
n,
|
@@ -125,21 +128,21 @@ let A = class {
|
|
125
128
|
return t;
|
126
129
|
}
|
127
130
|
}
|
128
|
-
}
|
129
|
-
const
|
131
|
+
}
|
132
|
+
const ne = function(i, e) {
|
130
133
|
const t = {};
|
131
134
|
for (const s in i) {
|
132
135
|
const r = i[s];
|
133
136
|
e.includes(s) && r !== null && (t[s] = r);
|
134
137
|
}
|
135
138
|
return t;
|
136
|
-
},
|
139
|
+
}, ae = (i) => i === "email", le = () => ({
|
137
140
|
singleTag: "hr"
|
138
|
-
}),
|
141
|
+
}), ce = () => ({
|
139
142
|
tag: "blockquote"
|
140
|
-
}),
|
143
|
+
}), he = () => ({
|
141
144
|
tag: "ul"
|
142
|
-
}),
|
145
|
+
}), ue = (i) => ({
|
143
146
|
tag: [
|
144
147
|
"pre",
|
145
148
|
{
|
@@ -147,24 +150,24 @@ const se = function(i, e) {
|
|
147
150
|
attrs: i.attrs
|
148
151
|
}
|
149
152
|
]
|
150
|
-
}),
|
153
|
+
}), de = () => ({
|
151
154
|
singleTag: "br"
|
152
|
-
}),
|
155
|
+
}), pe = (i) => ({
|
153
156
|
tag: `h${i.attrs.level}`
|
154
|
-
}),
|
157
|
+
}), ge = (i) => ({
|
155
158
|
singleTag: [
|
156
159
|
{
|
157
160
|
tag: "img",
|
158
|
-
attrs:
|
161
|
+
attrs: ne(i.attrs, ["src", "alt", "title"])
|
159
162
|
}
|
160
163
|
]
|
161
|
-
}),
|
164
|
+
}), fe = () => ({
|
162
165
|
tag: "li"
|
163
|
-
}),
|
166
|
+
}), me = () => ({
|
164
167
|
tag: "ol"
|
165
|
-
}),
|
168
|
+
}), ye = () => ({
|
166
169
|
tag: "p"
|
167
|
-
}),
|
170
|
+
}), be = (i) => ({
|
168
171
|
tag: [
|
169
172
|
{
|
170
173
|
tag: "span",
|
@@ -175,25 +178,25 @@ const se = function(i, e) {
|
|
175
178
|
}
|
176
179
|
}
|
177
180
|
]
|
178
|
-
}),
|
181
|
+
}), ke = () => ({
|
179
182
|
tag: "b"
|
180
|
-
}),
|
183
|
+
}), $e = () => ({
|
181
184
|
tag: "s"
|
182
|
-
}),
|
185
|
+
}), ve = () => ({
|
183
186
|
tag: "u"
|
184
|
-
}),
|
187
|
+
}), Te = () => ({
|
185
188
|
tag: "strong"
|
186
|
-
}),
|
189
|
+
}), we = () => ({
|
187
190
|
tag: "code"
|
188
|
-
}),
|
191
|
+
}), Re = () => ({
|
189
192
|
tag: "i"
|
190
|
-
}),
|
193
|
+
}), Ee = (i) => {
|
191
194
|
if (!i.attrs)
|
192
195
|
return {
|
193
196
|
tag: ""
|
194
197
|
};
|
195
|
-
const e = new
|
196
|
-
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")),
|
198
|
+
const e = new L().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
|
199
|
+
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), ae(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
197
200
|
for (const r in t.custom)
|
198
201
|
t[r] = t.custom[r];
|
199
202
|
delete t.custom;
|
@@ -206,25 +209,25 @@ const se = function(i, e) {
|
|
206
209
|
}
|
207
210
|
]
|
208
211
|
};
|
209
|
-
},
|
212
|
+
}, _e = (i) => ({
|
210
213
|
tag: [
|
211
214
|
{
|
212
215
|
tag: "span",
|
213
216
|
attrs: i.attrs
|
214
217
|
}
|
215
218
|
]
|
216
|
-
}),
|
219
|
+
}), Se = () => ({
|
217
220
|
tag: "sub"
|
218
|
-
}),
|
221
|
+
}), je = () => ({
|
219
222
|
tag: "sup"
|
220
|
-
}),
|
223
|
+
}), Ie = (i) => ({
|
221
224
|
tag: [
|
222
225
|
{
|
223
226
|
tag: "span",
|
224
227
|
attrs: i.attrs
|
225
228
|
}
|
226
229
|
]
|
227
|
-
}),
|
230
|
+
}), Ae = (i) => {
|
228
231
|
var e;
|
229
232
|
return (e = i.attrs) != null && e.color ? {
|
230
233
|
tag: [
|
@@ -238,7 +241,7 @@ const se = function(i, e) {
|
|
238
241
|
} : {
|
239
242
|
tag: ""
|
240
243
|
};
|
241
|
-
},
|
244
|
+
}, xe = (i) => {
|
242
245
|
var e;
|
243
246
|
return (e = i.attrs) != null && e.color ? {
|
244
247
|
tag: [
|
@@ -252,36 +255,36 @@ const se = function(i, e) {
|
|
252
255
|
} : {
|
253
256
|
tag: ""
|
254
257
|
};
|
255
|
-
},
|
258
|
+
}, Oe = {
|
256
259
|
nodes: {
|
257
|
-
horizontal_rule:
|
258
|
-
blockquote:
|
259
|
-
bullet_list:
|
260
|
-
code_block:
|
261
|
-
hard_break:
|
262
|
-
heading:
|
263
|
-
image:
|
264
|
-
list_item:
|
265
|
-
ordered_list:
|
266
|
-
paragraph:
|
267
|
-
emoji:
|
260
|
+
horizontal_rule: le,
|
261
|
+
blockquote: ce,
|
262
|
+
bullet_list: he,
|
263
|
+
code_block: ue,
|
264
|
+
hard_break: de,
|
265
|
+
heading: pe,
|
266
|
+
image: ge,
|
267
|
+
list_item: fe,
|
268
|
+
ordered_list: me,
|
269
|
+
paragraph: ye,
|
270
|
+
emoji: be
|
268
271
|
},
|
269
272
|
marks: {
|
270
|
-
bold:
|
271
|
-
strike:
|
272
|
-
underline:
|
273
|
-
strong:
|
274
|
-
code:
|
275
|
-
italic:
|
276
|
-
link:
|
277
|
-
styled:
|
278
|
-
subscript:
|
279
|
-
superscript:
|
280
|
-
anchor:
|
281
|
-
highlight:
|
282
|
-
textStyle:
|
283
|
-
}
|
284
|
-
},
|
273
|
+
bold: ke,
|
274
|
+
strike: $e,
|
275
|
+
underline: ve,
|
276
|
+
strong: Te,
|
277
|
+
code: we,
|
278
|
+
italic: Re,
|
279
|
+
link: Ee,
|
280
|
+
styled: _e,
|
281
|
+
subscript: Se,
|
282
|
+
superscript: je,
|
283
|
+
anchor: Ie,
|
284
|
+
highlight: Ae,
|
285
|
+
textStyle: xe
|
286
|
+
}
|
287
|
+
}, Le = function(i) {
|
285
288
|
const e = {
|
286
289
|
"&": "&",
|
287
290
|
"<": "<",
|
@@ -292,9 +295,9 @@ const se = function(i, e) {
|
|
292
295
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
293
296
|
};
|
294
297
|
let z = !1;
|
295
|
-
class
|
298
|
+
class C {
|
296
299
|
constructor(e) {
|
297
|
-
|
300
|
+
g(this, "marks"), g(this, "nodes"), e || (e = Oe), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
298
301
|
}
|
299
302
|
addNode(e, t) {
|
300
303
|
this.nodes[e] = t;
|
@@ -346,25 +349,25 @@ class L {
|
|
346
349
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
347
350
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
348
351
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
349
|
-
var
|
350
|
-
const
|
352
|
+
var h, u;
|
353
|
+
const p = a.match(
|
351
354
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
352
355
|
);
|
353
|
-
if (
|
354
|
-
const
|
355
|
-
srcset: (
|
356
|
-
if (typeof
|
357
|
-
return `//${
|
358
|
-
if (typeof
|
356
|
+
if (p && p.length > 0) {
|
357
|
+
const y = {
|
358
|
+
srcset: (h = t.srcset) == null ? void 0 : h.map((T) => {
|
359
|
+
if (typeof T == "number")
|
360
|
+
return `//${p}/m/${T}x0${n} ${T}w`;
|
361
|
+
if (typeof T == "object" && T.length === 2) {
|
359
362
|
let _ = 0, j = 0;
|
360
|
-
return typeof
|
363
|
+
return typeof T[0] == "number" && (_ = T[0]), typeof T[1] == "number" && (j = T[1]), `//${p}/m/${_}x${j}${n} ${_}w`;
|
361
364
|
}
|
362
365
|
return "";
|
363
366
|
}).join(", "),
|
364
|
-
sizes: (u = t.sizes) == null ? void 0 : u.map((
|
367
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((T) => T).join(", ")
|
365
368
|
};
|
366
|
-
let
|
367
|
-
return
|
369
|
+
let k = "";
|
370
|
+
return y.srcset && (k += `srcset="${y.srcset}" `), y.sizes && (k += `sizes="${y.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
|
368
371
|
}
|
369
372
|
return a;
|
370
373
|
})), e;
|
@@ -378,7 +381,7 @@ class L {
|
|
378
381
|
const s = this.getMatchingNode(e);
|
379
382
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
380
383
|
t.push(this.renderNode(r));
|
381
|
-
}) : e.text ? t.push(
|
384
|
+
}) : e.text ? t.push(Le(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) => {
|
382
385
|
const o = this.getMatchingMark(r);
|
383
386
|
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
384
387
|
}), t.join("");
|
@@ -433,9 +436,9 @@ class L {
|
|
433
436
|
return this.renderTag(t, " /");
|
434
437
|
}
|
435
438
|
}
|
436
|
-
class
|
439
|
+
class Ce {
|
437
440
|
constructor(e) {
|
438
|
-
|
441
|
+
g(this, "baseURL"), g(this, "timeout"), g(this, "headers"), g(this, "responseInterceptor"), g(this, "fetch"), g(this, "ejectInterceptor"), g(this, "url"), g(this, "parameters"), g(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 = {};
|
439
442
|
}
|
440
443
|
/**
|
441
444
|
*
|
@@ -472,7 +475,7 @@ class xe {
|
|
472
475
|
async _methodHandler(e) {
|
473
476
|
let t = `${this.baseURL}${this.url}`, s = null;
|
474
477
|
if (e === "get") {
|
475
|
-
const a = new
|
478
|
+
const a = new L();
|
476
479
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
477
480
|
this.parameters
|
478
481
|
)}`;
|
@@ -490,10 +493,10 @@ class xe {
|
|
490
493
|
...this.fetchOptions
|
491
494
|
});
|
492
495
|
this.timeout && clearTimeout(l);
|
493
|
-
const
|
496
|
+
const h = await this._responseHandler(
|
494
497
|
a
|
495
498
|
);
|
496
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
499
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
|
497
500
|
} catch (a) {
|
498
501
|
return {
|
499
502
|
message: a
|
@@ -520,39 +523,39 @@ class xe {
|
|
520
523
|
});
|
521
524
|
}
|
522
525
|
}
|
523
|
-
const D = "SB-Agent",
|
526
|
+
const D = "SB-Agent", N = {
|
524
527
|
defaultAgentName: "SB-JS-CLIENT",
|
525
528
|
defaultAgentVersion: "SB-Agent-Version",
|
526
529
|
packageVersion: "6.0.0"
|
527
530
|
};
|
528
|
-
let
|
531
|
+
let x = {};
|
529
532
|
const S = {};
|
530
|
-
class
|
533
|
+
class Pe {
|
531
534
|
/**
|
532
535
|
*
|
533
536
|
* @param config ISbConfig interface
|
534
537
|
* @param pEndpoint string, optional
|
535
538
|
*/
|
536
539
|
constructor(e, t) {
|
537
|
-
|
540
|
+
g(this, "client"), g(this, "maxRetries"), g(this, "retriesDelay"), g(this, "throttle"), g(this, "accessToken"), g(this, "cache"), g(this, "helpers"), g(this, "resolveCounter"), g(this, "relations"), g(this, "links"), g(this, "richTextResolver"), g(this, "resolveNestedRelations"), g(this, "stringifiedStoriesCache");
|
538
541
|
let s = e.endpoint || t;
|
539
542
|
if (!s) {
|
540
|
-
const n = new
|
543
|
+
const n = new L().getRegionURL, l = e.https === !1 ? "http" : "https";
|
541
544
|
e.oauthToken ? s = `${l}://${n(e.region)}/v1` : s = `${l}://${n(e.region)}/v2`;
|
542
545
|
}
|
543
546
|
const r = new Headers();
|
544
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(([n, l]) => {
|
545
548
|
r.set(n, l);
|
546
|
-
}), r.has(D) || (r.set(D,
|
547
|
-
|
548
|
-
|
549
|
+
}), r.has(D) || (r.set(D, N.defaultAgentName), r.set(
|
550
|
+
N.defaultAgentVersion,
|
551
|
+
N.packageVersion
|
549
552
|
));
|
550
553
|
let o = 5;
|
551
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new
|
554
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new C(e.richTextSchema) : this.richTextResolver = new C(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = oe(
|
552
555
|
this.throttledRequest.bind(this),
|
553
556
|
o,
|
554
557
|
1e3
|
555
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new
|
558
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new L(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Ce({
|
556
559
|
baseURL: s,
|
557
560
|
timeout: e.timeout || 0,
|
558
561
|
headers: r,
|
@@ -589,17 +592,17 @@ class Oe {
|
|
589
592
|
return this.cacheResponse(r, o, void 0, s);
|
590
593
|
}
|
591
594
|
async getAll(e, t, s, r) {
|
592
|
-
const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = s ?? n.substring(n.lastIndexOf("/") + 1), a = 1,
|
595
|
+
const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = s ?? n.substring(n.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
|
593
596
|
n,
|
594
597
|
t,
|
595
598
|
o,
|
596
599
|
a,
|
597
600
|
r
|
598
|
-
), u =
|
601
|
+
), u = h.total ? Math.ceil(h.total / o) : 1, p = await this.helpers.asyncMap(
|
599
602
|
this.helpers.range(a, u),
|
600
|
-
(
|
603
|
+
(y) => this.makeRequest(n, t, o, y + 1, r)
|
601
604
|
);
|
602
|
-
return this.helpers.flatMap([
|
605
|
+
return this.helpers.flatMap([h, ...p], (y) => Object.values(y.data[l]));
|
603
606
|
}
|
604
607
|
post(e, t, s) {
|
605
608
|
const r = `/${e}`;
|
@@ -717,8 +720,8 @@ class Oe {
|
|
717
720
|
if (e.link_uuids) {
|
718
721
|
const o = e.link_uuids.length, n = [], l = 50;
|
719
722
|
for (let a = 0; a < o; a += l) {
|
720
|
-
const
|
721
|
-
n.push(e.link_uuids.slice(a,
|
723
|
+
const h = Math.min(o, a + l);
|
724
|
+
n.push(e.link_uuids.slice(a, h));
|
722
725
|
}
|
723
726
|
for (let a = 0; a < n.length; a++)
|
724
727
|
(await this.getStories({
|
@@ -728,8 +731,8 @@ class Oe {
|
|
728
731
|
starts_with: t.starts_with,
|
729
732
|
by_uuids: n[a].join(",")
|
730
733
|
})).data.stories.forEach(
|
731
|
-
(
|
732
|
-
r.push(
|
734
|
+
(h) => {
|
735
|
+
r.push(h);
|
733
736
|
}
|
734
737
|
);
|
735
738
|
} else
|
@@ -746,8 +749,8 @@ class Oe {
|
|
746
749
|
if (e.rel_uuids) {
|
747
750
|
const o = e.rel_uuids.length, n = [], l = 50;
|
748
751
|
for (let a = 0; a < o; a += l) {
|
749
|
-
const
|
750
|
-
n.push(e.rel_uuids.slice(a,
|
752
|
+
const h = Math.min(o, a + l);
|
753
|
+
n.push(e.rel_uuids.slice(a, h));
|
751
754
|
}
|
752
755
|
for (let a = 0; a < n.length; a++)
|
753
756
|
(await this.getStories({
|
@@ -757,8 +760,8 @@ class Oe {
|
|
757
760
|
starts_with: t.starts_with,
|
758
761
|
by_uuids: n[a].join(","),
|
759
762
|
excluding_fields: t.excluding_fields
|
760
|
-
})).data.stories.forEach((
|
761
|
-
r.push(
|
763
|
+
})).data.stories.forEach((h) => {
|
764
|
+
r.push(h);
|
762
765
|
});
|
763
766
|
} else
|
764
767
|
r = e.rels;
|
@@ -800,7 +803,7 @@ class Oe {
|
|
800
803
|
return Promise.resolve(l);
|
801
804
|
}
|
802
805
|
return new Promise(async (l, a) => {
|
803
|
-
var
|
806
|
+
var h;
|
804
807
|
try {
|
805
808
|
const u = await this.throttle(
|
806
809
|
"get",
|
@@ -810,17 +813,17 @@ class Oe {
|
|
810
813
|
);
|
811
814
|
if (u.status !== 200)
|
812
815
|
return a(u);
|
813
|
-
let
|
814
|
-
if ((
|
816
|
+
let p = { data: u.data, headers: u.headers };
|
817
|
+
if ((h = u.headers) != null && h["per-page"] && (p = Object.assign({}, p, {
|
815
818
|
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
816
819
|
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
817
|
-
})),
|
818
|
-
const
|
819
|
-
await this.resolveStories(
|
820
|
+
})), p.data.story || p.data.stories) {
|
821
|
+
const k = this.resolveCounter = ++this.resolveCounter % 1e3;
|
822
|
+
await this.resolveStories(p.data, t, `${k}`);
|
820
823
|
}
|
821
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o,
|
822
|
-
const
|
823
|
-
return t.token &&
|
824
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o, p);
|
825
|
+
const y = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
826
|
+
return t.token && p.data.cv && (y && S[t.token] && S[t.token] !== p.data.cv && await this.flushCache(), S[t.token] = p.data.cv), l(p);
|
824
827
|
} catch (u) {
|
825
828
|
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
826
829
|
return console.log(
|
@@ -850,16 +853,16 @@ class Oe {
|
|
850
853
|
case "memory":
|
851
854
|
return {
|
852
855
|
get(e) {
|
853
|
-
return Promise.resolve(
|
856
|
+
return Promise.resolve(x[e]);
|
854
857
|
},
|
855
858
|
getAll() {
|
856
|
-
return Promise.resolve(
|
859
|
+
return Promise.resolve(x);
|
857
860
|
},
|
858
861
|
set(e, t) {
|
859
|
-
return
|
862
|
+
return x[e] = t, Promise.resolve(void 0);
|
860
863
|
},
|
861
864
|
flush() {
|
862
|
-
return
|
865
|
+
return x = {}, Promise.resolve(void 0);
|
863
866
|
}
|
864
867
|
};
|
865
868
|
case "custom":
|
@@ -887,7 +890,7 @@ class Oe {
|
|
887
890
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
888
891
|
}
|
889
892
|
}
|
890
|
-
const
|
893
|
+
const De = (i = {}) => {
|
891
894
|
const { apiOptions: e } = i;
|
892
895
|
if (!e || !e.accessToken) {
|
893
896
|
console.error(
|
@@ -895,8 +898,8 @@ const Ue = (i = {}) => {
|
|
895
898
|
);
|
896
899
|
return;
|
897
900
|
}
|
898
|
-
return { storyblokApi: new
|
899
|
-
},
|
901
|
+
return { storyblokApi: new Pe(e) };
|
902
|
+
}, qe = (i) => {
|
900
903
|
if (typeof i != "object" || typeof i._editable > "u")
|
901
904
|
return {};
|
902
905
|
try {
|
@@ -911,25 +914,25 @@ const Ue = (i = {}) => {
|
|
911
914
|
return {};
|
912
915
|
}
|
913
916
|
};
|
914
|
-
function
|
917
|
+
function Ne(i, e) {
|
915
918
|
if (!e)
|
916
919
|
return { src: i, attrs: {} };
|
917
920
|
let t = 0, s = 0;
|
918
921
|
const r = {}, o = [];
|
919
|
-
function n(a,
|
920
|
-
typeof a != "number" || a <=
|
922
|
+
function n(a, h, u, p, y) {
|
923
|
+
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)`) : y.push(`${p}(${a})`);
|
921
924
|
}
|
922
925
|
if (typeof e == "object") {
|
923
926
|
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) {
|
924
|
-
const { filters: a } = e || {}, { blur:
|
925
|
-
|
927
|
+
const { filters: a } = e || {}, { blur: h, brightness: u, fill: p, format: y, grayscale: k, quality: T, rotate: _ } = a || {};
|
928
|
+
h && n(h, 0, 100, "blur", o), T && n(T, 0, 100, "quality", o), u && n(u, 0, 100, "brightness", o), p && o.push(`fill(${p})`), k && o.push("grayscale()"), _ && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${_})`), y && ["webp", "png", "jpeg"].includes(y) && o.push(`format(${y})`);
|
926
929
|
}
|
927
930
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
928
931
|
if (typeof a == "number")
|
929
932
|
return `${i}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
|
930
933
|
if (Array.isArray(a) && a.length === 2) {
|
931
|
-
const [
|
932
|
-
return `${i}/m/${
|
934
|
+
const [h, u] = a;
|
935
|
+
return `${i}/m/${h}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
|
933
936
|
} else {
|
934
937
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
935
938
|
return;
|
@@ -942,8 +945,8 @@ function Ae(i, e) {
|
|
942
945
|
attrs: r
|
943
946
|
};
|
944
947
|
}
|
945
|
-
var
|
946
|
-
const
|
948
|
+
var v = /* @__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))(v || {}), 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 || {}), G = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(G || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
|
949
|
+
const He = [
|
947
950
|
"area",
|
948
951
|
"base",
|
949
952
|
"br",
|
@@ -958,167 +961,191 @@ const Le = [
|
|
958
961
|
"source",
|
959
962
|
"track",
|
960
963
|
"wbr"
|
961
|
-
],
|
962
|
-
function
|
964
|
+
], Me = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Be = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
|
965
|
+
function Ue(i) {
|
963
966
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
964
967
|
}
|
965
|
-
const
|
968
|
+
const O = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
|
966
969
|
function q(i, e = {}, t) {
|
967
|
-
const s =
|
970
|
+
const s = Me(e), r = s ? `${i} ${s}` : i, o = Array.isArray(t) ? t.join("") : t || "";
|
968
971
|
if (i) {
|
969
|
-
if (
|
972
|
+
if (He.includes(i))
|
970
973
|
return `<${r}>`;
|
971
974
|
} else return o;
|
972
975
|
return `<${r}>${o}</${i}>`;
|
973
976
|
}
|
974
|
-
function
|
977
|
+
function Fe(i = {}) {
|
975
978
|
let e = 0;
|
976
979
|
const {
|
977
980
|
renderFn: t = q,
|
978
|
-
textFn: s =
|
981
|
+
textFn: s = Ue,
|
979
982
|
resolvers: r = {},
|
980
983
|
optimizeImages: o = !1,
|
981
984
|
keyedResolvers: n = !1
|
982
|
-
} = i, l = t !== q, a = (
|
983
|
-
const f =
|
984
|
-
return n && (f.key = `${
|
985
|
-
},
|
986
|
-
const { src:
|
987
|
-
let
|
985
|
+
} = i, l = t !== q, a = (c) => (d) => {
|
986
|
+
const f = d.attrs || {};
|
987
|
+
return n && (f.key = `${c}-${e}`), t(c, f, d.children || null);
|
988
|
+
}, h = (c) => {
|
989
|
+
const { src: d, alt: f, title: b, srcset: R, sizes: $ } = c.attrs || {};
|
990
|
+
let m = d, w = {};
|
988
991
|
if (o) {
|
989
|
-
const { src:
|
990
|
-
|
992
|
+
const { src: ee, attrs: te } = Ne(d, o);
|
993
|
+
m = ee, w = te;
|
991
994
|
}
|
992
|
-
n && (
|
993
|
-
...
|
995
|
+
n && (w = {
|
996
|
+
...w,
|
994
997
|
key: `img-${e}`
|
995
998
|
});
|
996
|
-
const
|
997
|
-
src:
|
999
|
+
const Z = {
|
1000
|
+
src: m,
|
998
1001
|
alt: f,
|
999
|
-
title:
|
1002
|
+
title: b,
|
1000
1003
|
srcset: R,
|
1001
|
-
sizes:
|
1002
|
-
...
|
1004
|
+
sizes: $,
|
1005
|
+
...w
|
1003
1006
|
};
|
1004
|
-
return t("img",
|
1005
|
-
}, u = (
|
1006
|
-
const { level:
|
1007
|
+
return t("img", O(Z));
|
1008
|
+
}, u = (c) => {
|
1009
|
+
const { level: d, ...f } = c.attrs || {}, b = {
|
1007
1010
|
...f
|
1008
1011
|
};
|
1009
|
-
return n && (
|
1010
|
-
},
|
1011
|
-
var
|
1012
|
-
const
|
1013
|
-
src: (
|
1014
|
-
alt: (f =
|
1012
|
+
return n && (b.key = `h${d}-${e}`), t(`h${d}`, b, c.children);
|
1013
|
+
}, p = (c) => {
|
1014
|
+
var d, f, b, R;
|
1015
|
+
const $ = t("img", {
|
1016
|
+
src: (d = c.attrs) == null ? void 0 : d.fallbackImage,
|
1017
|
+
alt: (f = c.attrs) == null ? void 0 : f.alt,
|
1015
1018
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
1016
1019
|
draggable: "false",
|
1017
1020
|
loading: "lazy"
|
1018
|
-
}),
|
1021
|
+
}), m = {
|
1019
1022
|
"data-type": "emoji",
|
1020
|
-
"data-name": (
|
1021
|
-
"data-emoji": (R =
|
1023
|
+
"data-name": (b = c.attrs) == null ? void 0 : b.name,
|
1024
|
+
"data-emoji": (R = c.attrs) == null ? void 0 : R.emoji
|
1022
1025
|
};
|
1023
|
-
return n && (
|
1024
|
-
},
|
1025
|
-
...
|
1026
|
+
return n && (m.key = `emoji-${e}`), t("span", m, $);
|
1027
|
+
}, y = (c) => t("pre", {
|
1028
|
+
...c.attrs,
|
1026
1029
|
key: `code-${e}`
|
1027
|
-
}, t("code", { key: `code-${e}` },
|
1028
|
-
const { class: R, id:
|
1030
|
+
}, t("code", { key: `code-${e}` }, c.children || "")), k = (c, d = !1) => ({ text: f, attrs: b }) => {
|
1031
|
+
const { class: R, id: $, ...m } = b || {}, w = d ? {
|
1029
1032
|
class: R,
|
1030
|
-
id:
|
1031
|
-
style:
|
1032
|
-
} :
|
1033
|
-
return n && (
|
1034
|
-
},
|
1035
|
-
const { marks:
|
1036
|
-
return "text" in
|
1037
|
-
(
|
1033
|
+
id: $,
|
1034
|
+
style: Be(m) || void 0
|
1035
|
+
} : b || {};
|
1036
|
+
return n && (w.key = `${c}-${e}`), t(c, O(w), f);
|
1037
|
+
}, T = (c) => P(c), _ = (c) => {
|
1038
|
+
const { marks: d, ...f } = c;
|
1039
|
+
return "text" in c ? d ? d.reduce(
|
1040
|
+
(b, R) => T({ ...R, text: b }),
|
1038
1041
|
// Fix: Ensure render function returns a string
|
1039
|
-
|
1042
|
+
T({ ...f, children: f.children })
|
1040
1043
|
// Fix: Cast children to string
|
1041
1044
|
) : s(f.text) : "";
|
1042
|
-
}, j = (
|
1043
|
-
const { linktype:
|
1044
|
-
let
|
1045
|
-
switch (
|
1045
|
+
}, j = (c) => {
|
1046
|
+
const { linktype: d, href: f, anchor: b, ...R } = c.attrs || {};
|
1047
|
+
let $ = "";
|
1048
|
+
switch (d) {
|
1046
1049
|
case I.ASSET:
|
1047
1050
|
case I.URL:
|
1048
|
-
|
1051
|
+
$ = f;
|
1049
1052
|
break;
|
1050
1053
|
case I.EMAIL:
|
1051
|
-
|
1054
|
+
$ = `mailto:${f}`;
|
1052
1055
|
break;
|
1053
1056
|
case I.STORY:
|
1054
|
-
|
1057
|
+
$ = f, b && ($ = `${$}#${b}`);
|
1055
1058
|
break;
|
1056
1059
|
default:
|
1057
|
-
|
1060
|
+
$ = f;
|
1058
1061
|
break;
|
1059
1062
|
}
|
1060
|
-
const
|
1061
|
-
return
|
1062
|
-
}, J = (
|
1063
|
-
var
|
1063
|
+
const m = { ...R };
|
1064
|
+
return $ && (m.href = $), n && (m.key = `a-${e}`), t("a", m, c.text);
|
1065
|
+
}, J = (c) => {
|
1066
|
+
var d, f;
|
1064
1067
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
1065
|
-
blok: (
|
1066
|
-
id: (f =
|
1068
|
+
blok: (d = c == null ? void 0 : c.attrs) == null ? void 0 : d.body[0],
|
1069
|
+
id: (f = c.attrs) == null ? void 0 : f.id,
|
1067
1070
|
key: `component-${e}`,
|
1068
1071
|
style: "display: none"
|
1069
1072
|
});
|
1070
|
-
}, K =
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
[
|
1082
|
-
|
1083
|
-
|
1073
|
+
}, K = (c) => {
|
1074
|
+
const d = {};
|
1075
|
+
return n && (d.key = `table-${e}`), t("table", d, c.children);
|
1076
|
+
}, Y = (c) => {
|
1077
|
+
const d = {};
|
1078
|
+
return n && (d.key = `tr-${e}`), t("tr", d, c.children);
|
1079
|
+
}, W = (c) => {
|
1080
|
+
const { colspan: d, rowspan: f, colwidth: b, backgroundColor: R, ...$ } = c.attrs || {}, m = {
|
1081
|
+
...$
|
1082
|
+
};
|
1083
|
+
d > 1 && (m.colspan = d), f > 1 && (m.rowspan = f);
|
1084
|
+
const w = [];
|
1085
|
+
return b && w.push(`width: ${b}px;`), R && w.push(`background-color: ${R};`), w.length > 0 && (m.style = w.join(" ")), n && (m.key = `td-${e}`), t("td", O(m), c.children);
|
1086
|
+
}, X = (c) => {
|
1087
|
+
const { colspan: d, rowspan: f, colwidth: b, backgroundColor: R, ...$ } = c.attrs || {}, m = {
|
1088
|
+
...$
|
1089
|
+
};
|
1090
|
+
d > 1 && (m.colspan = d), f > 1 && (m.rowspan = f);
|
1091
|
+
const w = [];
|
1092
|
+
return b && w.push(`width: ${b}px;`), R && w.push(`background-color: ${R};`), w.length > 0 && (m.style = w.join(" ")), n && (m.key = `th-${e}`), t("th", O(m), c.children);
|
1093
|
+
}, Q = new Map([
|
1094
|
+
[v.DOCUMENT, a("")],
|
1095
|
+
[v.HEADING, u],
|
1096
|
+
[v.PARAGRAPH, a("p")],
|
1097
|
+
[v.UL_LIST, a("ul")],
|
1098
|
+
[v.OL_LIST, a("ol")],
|
1099
|
+
[v.LIST_ITEM, a("li")],
|
1100
|
+
[v.IMAGE, h],
|
1101
|
+
[v.EMOJI, p],
|
1102
|
+
[v.CODE_BLOCK, y],
|
1103
|
+
[v.HR, a("hr")],
|
1104
|
+
[v.BR, a("br")],
|
1105
|
+
[v.QUOTE, a("blockquote")],
|
1106
|
+
[v.COMPONENT, J],
|
1084
1107
|
[G.TEXT, _],
|
1085
|
-
[
|
1086
|
-
[
|
1087
|
-
[
|
1088
|
-
[
|
1089
|
-
[
|
1090
|
-
[
|
1091
|
-
[
|
1092
|
-
[
|
1093
|
-
[
|
1094
|
-
[
|
1095
|
-
[
|
1096
|
-
[
|
1097
|
-
|
1108
|
+
[E.LINK, j],
|
1109
|
+
[E.ANCHOR, j],
|
1110
|
+
[E.STYLED, k("span", !0)],
|
1111
|
+
[E.BOLD, k("strong")],
|
1112
|
+
[E.TEXT_STYLE, k("span", !0)],
|
1113
|
+
[E.ITALIC, k("em")],
|
1114
|
+
[E.UNDERLINE, k("u")],
|
1115
|
+
[E.STRIKE, k("s")],
|
1116
|
+
[E.CODE, k("code")],
|
1117
|
+
[E.SUPERSCRIPT, k("sup")],
|
1118
|
+
[E.SUBSCRIPT, k("sub")],
|
1119
|
+
[E.HIGHLIGHT, k("mark")],
|
1120
|
+
[v.TABLE, K],
|
1121
|
+
[v.TABLE_ROW, Y],
|
1122
|
+
[v.TABLE_CELL, W],
|
1123
|
+
[v.TABLE_HEADER, X],
|
1124
|
+
...Object.entries(r).map(([c, d]) => [c, d])
|
1098
1125
|
]);
|
1099
|
-
function
|
1126
|
+
function A(c) {
|
1100
1127
|
e += 1;
|
1101
|
-
const
|
1102
|
-
if (!
|
1103
|
-
return console.error("<Storyblok>", `No resolver found for node type ${
|
1104
|
-
if (
|
1105
|
-
return
|
1106
|
-
const f =
|
1107
|
-
return
|
1108
|
-
...
|
1128
|
+
const d = Q.get(c.type);
|
1129
|
+
if (!d)
|
1130
|
+
return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
|
1131
|
+
if (c.type === "text")
|
1132
|
+
return d(c);
|
1133
|
+
const f = c.content ? c.content.map(P) : void 0;
|
1134
|
+
return d({
|
1135
|
+
...c,
|
1109
1136
|
children: f
|
1110
1137
|
// Fix: Update the type of 'children' to Node[]
|
1111
1138
|
});
|
1112
1139
|
}
|
1113
|
-
function
|
1114
|
-
return
|
1140
|
+
function P(c) {
|
1141
|
+
return c.type === "doc" ? l ? c.content.map(A) : c.content.map(A).join("") : Array.isArray(c) ? c.map(A) : A(c);
|
1115
1142
|
}
|
1116
1143
|
return {
|
1117
|
-
render:
|
1144
|
+
render: P
|
1118
1145
|
};
|
1119
1146
|
}
|
1120
|
-
let
|
1121
|
-
const
|
1147
|
+
let H, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
1148
|
+
const Ge = (i, e, t = {}) => {
|
1122
1149
|
var l;
|
1123
1150
|
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
1124
1151
|
"_storyblok"
|
@@ -1129,9 +1156,9 @@ const Be = (i, e, t = {}) => {
|
|
1129
1156
|
return;
|
1130
1157
|
}
|
1131
1158
|
window.storyblokRegisterEvent(() => {
|
1132
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
1159
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (h) => {
|
1133
1160
|
var u;
|
1134
|
-
|
1161
|
+
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());
|
1135
1162
|
});
|
1136
1163
|
});
|
1137
1164
|
}
|
@@ -1144,8 +1171,8 @@ const Be = (i, e, t = {}) => {
|
|
1144
1171
|
html: s
|
1145
1172
|
};
|
1146
1173
|
});
|
1147
|
-
},
|
1148
|
-
var
|
1174
|
+
}, Ve = (i = {}) => {
|
1175
|
+
var p, y;
|
1149
1176
|
const {
|
1150
1177
|
bridge: e,
|
1151
1178
|
accessToken: t,
|
@@ -1157,37 +1184,37 @@ const Be = (i, e, t = {}) => {
|
|
1157
1184
|
r.accessToken = r.accessToken || t;
|
1158
1185
|
const l = { bridge: e, apiOptions: r };
|
1159
1186
|
let a = {};
|
1160
|
-
s.forEach((
|
1161
|
-
a = { ...a, ...
|
1187
|
+
s.forEach((k) => {
|
1188
|
+
a = { ...a, ...k(l) };
|
1162
1189
|
}), n && (M = n);
|
1163
|
-
const u = !(typeof window > "u") && ((
|
1164
|
-
return e !== !1 && u && F(M),
|
1165
|
-
},
|
1190
|
+
const u = !(typeof window > "u") && ((y = (p = window.location) == null ? void 0 : p.search) == null ? void 0 : y.includes("_storyblok_tk"));
|
1191
|
+
return e !== !1 && u && F(M), H = new C(o.schema), o.resolver && V(H, o.resolver), a;
|
1192
|
+
}, ze = (i) => {
|
1166
1193
|
var e;
|
1167
1194
|
return !i || !((e = i == null ? void 0 : i.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
1168
|
-
},
|
1169
|
-
let s = t ||
|
1195
|
+
}, Je = (i, e, t) => {
|
1196
|
+
let s = t || H;
|
1170
1197
|
if (!s) {
|
1171
1198
|
console.error(
|
1172
1199
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
1173
1200
|
);
|
1174
1201
|
return;
|
1175
1202
|
}
|
1176
|
-
return
|
1177
|
-
},
|
1203
|
+
return ze(i) ? "" : (e && (s = new C(e.schema), e.resolver && V(s, e.resolver)), s.render(i, {}, !1));
|
1204
|
+
}, Ke = () => F(M);
|
1178
1205
|
export {
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1206
|
+
v as BlockTypes,
|
1207
|
+
E as MarkTypes,
|
1208
|
+
C as RichTextResolver,
|
1209
|
+
Oe as RichTextSchema,
|
1183
1210
|
G as TextTypes,
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1211
|
+
De as apiPlugin,
|
1212
|
+
ze as isRichTextEmpty,
|
1213
|
+
Ke as loadStoryblokBridge,
|
1214
|
+
Ge as registerStoryblokBridge,
|
1215
|
+
Je as renderRichText,
|
1216
|
+
Fe as richTextResolver,
|
1217
|
+
qe as storyblokEditable,
|
1218
|
+
Ve as storyblokInit,
|
1219
|
+
Ge as useStoryblokBridge
|
1193
1220
|
};
|
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.3.1",
|
5
5
|
"private": false,
|
6
6
|
"packageManager": "pnpm@10.2.0",
|
7
7
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
@@ -39,11 +39,12 @@
|
|
39
39
|
"lint": "eslint .",
|
40
40
|
"lint:fix": "eslint . --fix",
|
41
41
|
"cy:run": "cypress run",
|
42
|
-
"cy:open": "cypress open"
|
42
|
+
"cy:open": "cypress open",
|
43
|
+
"check-licenses": "node scripts/license-checker.mjs"
|
43
44
|
},
|
44
45
|
"dependencies": {
|
45
|
-
"@storyblok/richtext": "3.0
|
46
|
-
"storyblok-js-client": "6.10.
|
46
|
+
"@storyblok/richtext": "3.1.0",
|
47
|
+
"storyblok-js-client": "6.10.11"
|
47
48
|
},
|
48
49
|
"devDependencies": {
|
49
50
|
"@commitlint/cli": "^19.7.1",
|
@@ -51,12 +52,13 @@
|
|
51
52
|
"@storyblok/eslint-config": "^0.3.0",
|
52
53
|
"@tsconfig/recommended": "^1.0.8",
|
53
54
|
"@types/node": "^22.13.1",
|
54
|
-
"@vitest/ui": "3.0.
|
55
|
+
"@vitest/ui": "3.0.9",
|
55
56
|
"cypress": "^13.17.0",
|
56
57
|
"eslint": "^9.19.0",
|
57
58
|
"eslint-plugin-cypress": "^4.1.0",
|
58
59
|
"jsdom": "^26.0.0",
|
59
60
|
"kolorist": "^1.8.0",
|
61
|
+
"license-checker": "^25.0.1",
|
60
62
|
"pathe": "^2.0.2",
|
61
63
|
"simple-git-hooks": "^2.11.1",
|
62
64
|
"start-server-and-test": "^2.0.10",
|