@storyblok/js 3.1.0-next.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +211 -206
- package/dist/types/index.d.ts +1 -7
- package/package.json +9 -9
package/dist/storyblok-js.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
(function(
|
1
|
+
(function(y,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(y=typeof globalThis<"u"?globalThis:y||self,E(y.storyblok={}))})(this,function(y){"use strict";let E=!1;const U=[],H=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}E?r():U.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=>{U.forEach(n=>n()),E=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var F=Object.defineProperty,K=(i,e,t)=>e in i?F(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e,t)=>K(i,typeof e!="symbol"?e+"":e,t);function B(i){return!(i!==i||i===1/0||i===-1/0)}function Y(i,e,t){if(!B(e))throw new TypeError("Expected `limit` to be a finite number");if(!B(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const o=function(){n++;const a=setTimeout(function(){n--,s.length>0&&o(),r=r.filter(function(d){return d!==a})},t);r.indexOf(a)<0&&r.push(a);const h=s.shift();h.resolve(i.apply(h.self,h.args))},l=function(...a){const h=this;return new Promise(function(d,u){s.push({resolve:d,reject:u,args:a,self:h}),n<e&&o()})};return l.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},l}class O{constructor(){p(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),p(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),p(this,"delay",e=>new Promise(t=>setTimeout(t,e))),p(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),p(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)}),p(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),p(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),p(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=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],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 X=function(i,e){const t={};for(const s in i){const r=i[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},W=i=>i==="email",Q=()=>({singleTag:"hr"}),Z=()=>({tag:"blockquote"}),ee=()=>({tag:"ul"}),te=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),se=()=>({singleTag:"br"}),re=i=>({tag:`h${i.attrs.level}`}),ie=i=>({singleTag:[{tag:"img",attrs:X(i.attrs,["src","alt","title"])}]}),ne=()=>({tag:"li"}),oe=()=>({tag:"ol"}),ae=()=>({tag:"p"}),le=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),ce=()=>({tag:"b"}),he=()=>({tag:"s"}),ue=()=>({tag:"u"}),de=()=>({tag:"strong"}),pe=()=>({tag:"code"}),ge=()=>({tag:"i"}),fe=i=>{if(!i.attrs)return{tag:""};const e=new O().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),W(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}]}},me=i=>({tag:[{tag:"span",attrs:i.attrs}]}),ye=()=>({tag:"sub"}),be=()=>({tag:"sup"}),ke=i=>({tag:[{tag:"span",attrs:i.attrs}]}),ve=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:""}},D={nodes:{horizontal_rule:Q,blockquote:Z,bullet_list:ee,code_block:te,hard_break:se,heading:re,image:ie,list_item:ne,ordered_list:oe,paragraph:ae,emoji:le},marks:{bold:ce,strike:he,underline:ue,strong:de,code:pe,italic:ge,link:fe,styled:me,subscript:ye,superscript:be,anchor:ke,highlight:ve,textStyle:$e}},Te=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};class Re{constructor(e){p(this,"marks"),p(this,"nodes"),e||(e=D),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}){if(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/"),e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
|
2
2
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
3
3
|
ISbRichtext:
|
4
4
|
content?: ISbRichtext[]
|
@@ -21,4 +21,4 @@
|
|
21
21
|
}
|
22
22
|
],
|
23
23
|
type: 'doc'
|
24
|
-
}`),""}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-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(o+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(o+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(o+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(o+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(o+=`:rotate(${t.filters.rotate})`),o.length>0&&(o="/filters"+o))),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|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const y={srcset:(l=t.srcset)==null?void 0:l.map(b=>{if(typeof b=="number")return`//${p}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,L=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(L=b[1]),`//${p}/m/${S}x${L}${o} ${S}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(b=>b).join(", ")};let $="";return y.srcset&&($+=`srcset="${y.srcset}" `),y.sizes&&($+=`sizes="${y.sizes}" `),a.replace(/<img/g,`<img ${$.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(Te(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){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 Re{constructor(e){d(this,"baseURL"),d(this,"timeout"),d(this,"headers"),d(this,"responseInterceptor"),d(this,"fetch"),d(this,"ejectInterceptor"),d(this,"url"),d(this,"parameters"),d(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 j;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 l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}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 z="SB-Agent",A={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let x={};const _={};class we{constructor(e,t){d(this,"client"),d(this,"maxRetries"),d(this,"retriesDelay"),d(this,"throttle"),d(this,"accessToken"),d(this,"cache"),d(this,"helpers"),d(this,"resolveCounter"),d(this,"relations"),d(this,"links"),d(this,"richTextResolver"),d(this,"resolveNestedRelations"),d(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const o=new j().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;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const o in e.headers)r.set(o,e.headers[o]);r.has(z)||(r.set(z,A.defaultAgentName),r.set(A.defaultAgentVersion,A.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new I(e.richTextSchema):this.richTextResolver=new I,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Y(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new j,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new Re({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){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t,s){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,n)}async getAll(e,t,s,r){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`,c=o.split("/"),a=s||c[c.length-1],l=1,u=await this.makeRequest(o,t,n,l),p=u.total?Math.ceil(u.total/n):1;this.client.setFetchOptions(r);const y=await this.helpers.asyncMap(this.helpers.range(l,p),$=>this.makeRequest(o,t,n,$+1));return this.helpers.flatMap([u,...y],$=>Object.values($.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this._addResolveLevel(e),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t)}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]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let o=0;o<n.length;o++)r(n[o]);else if(n.constructor===Object){if(n._stopResolving)return;for(const o in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,o,t,s),this._insertLinks(n,o,s)),r(n[o])}}};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 l=Math.min(n,a+c);o.push(e.link_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}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 l=Math.min(n,a+c);o.push(e.rel_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}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"].indexOf(t.resolve_links)>-1&&((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){const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const o=await n.get(r);if(o)return Promise.resolve(o)}return new Promise(async(o,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,u),u.data.cv&&t.token&&(t.version==="draft"&&_[t.token]!=u.data.cv&&await this.flushCache(),_[t.token]=t.cv?t.cv:u.data.cv),o(u)}catch(l){if(l.response&&l.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(o).catch(c);c(l)}})}throttledRequest(e,t,s){return 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(x[e])},getAll(){return Promise.resolve(x)},set(e,t){return x[e]=t,Promise.resolve(void 0)},flush(){return x={},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 Se=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new we(e)}},_e=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{}}};var k=(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))(k||{}),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))(v||{}),C=(i=>(i.TEXT="text",i))(C||{}),O=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(O||{});function Ee(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,l,u,p,y){typeof a!="number"||a<=l||a>=u?console.warn(`[SbRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${l} 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("[SbRichText] - 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("[SbRichText] - 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:l,brightness:u,fill:p,format:y,grayscale:$,quality:b,rotate:S}=a||{};l&&o(l,0,100,"blur",n),b&&o(b,0,100,"quality",n),u&&o(u,0,100,"brightness",n),p&&n.push(`fill(${p})`),$&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),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[l,u]=a;return`${i}/m/${l}x${u}/${n.length>0?"filters:"+n.join(":"):""} ${l}w`}}).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}}const Ie=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Oe=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function je(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function xe(i,e={},t){const s=Ie(e);return`<${s?`${i} ${s}`:i}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Le(i={}){let e=0;const{renderFn:t=xe,textFn:s=je,resolvers:r={},optimizeImages:n=!1}=i,o=h=>g=>t(h,{...g.attrs,key:`${h}-${e}`},g.children||null),c=h=>{const{src:g,alt:f,...T}=h.attrs||{};let R=g,w={};if(n){const{src:Me,attrs:Ue}=Ee(g,n);R=Me,w=Ue}const Ne={src:R,alt:f||"",key:`img-${e}`,...T,...w};return t("img",Ne,"")},a=h=>{const{level:g,...f}=h.attrs||{};return t(`h${g}`,{...f,key:`h${g}-${e}`},h.children)},l=h=>{var g,f,T,R;return t("span",{"data-type":"emoji","data-name":(g=h.attrs)==null?void 0:g.name,emoji:(f=h.attrs)==null?void 0:f.emoji,key:`emoji-${e}`},t("img",{src:(T=h.attrs)==null?void 0:T.fallbackImage,alt:(R=h.attrs)==null?void 0:R.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"},""))},u=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),p=(h,g=!1)=>({text:f,attrs:T})=>t(h,g?{style:Oe(T),key:`${h}-${e}`}:{...T,key:`${h}-${e}`},f),y=h=>M(h),$=h=>{const{marks:g,...f}=h;return"text"in h?g?g.reduce((T,R)=>y({...R,text:T}),y({...f,children:f.children})):s(f.text):""},b=h=>{const{linktype:g,href:f,anchor:T,...R}=h.attrs||{};let w="";switch(g){case O.ASSET:case O.URL:w=f;break;case O.EMAIL:w=`mailto:${f}`;break;case O.STORY:w=f;break}return T&&(w=`${w}#${T}`),t("a",{...R,href:w,key:`a-${e}`},h.text)},S=h=>{var g,f;return console.warn("[SbRichtText] - 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"},"")},L=new Map([[k.DOCUMENT,o("div")],[k.HEADING,a],[k.PARAGRAPH,o("p")],[k.UL_LIST,o("ul")],[k.OL_LIST,o("ol")],[k.LIST_ITEM,o("li")],[k.IMAGE,c],[k.EMOJI,l],[k.CODE_BLOCK,u],[k.HR,o("hr")],[k.BR,o("br")],[k.QUOTE,o("blockquote")],[k.COMPONENT,S],[C.TEXT,$],[v.LINK,b],[v.ANCHOR,b],[v.STYLED,p("span",!0)],[v.BOLD,p("strong")],[v.TEXT_STYLE,p("span",!0)],[v.ITALIC,p("em")],[v.UNDERLINE,p("u")],[v.STRIKE,p("s")],[v.CODE,p("code")],[v.SUPERSCRIPT,p("sup")],[v.SUBSCRIPT,p("sub")],[v.HIGHLIGHT,p("mark")],...Object.entries(r).map(([h,g])=>[h,g])]);function V(h){e+=1;const g=L.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(M):void 0;return g({...h,children:f})}function M(h){return Array.isArray(h)?h.map(V):V(h)}return{render:M}}let P,N="https://app.storyblok.com/f/storyblok-v2-latest.js";const q=(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")===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"],l=>{l.action==="input"&&l.story.id===i?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===i&&window.location.reload()})})}},Ae=(i={})=>{var p,y;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($=>{a={...a,...$(c)}}),o&&(N=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&&H(N),P=new I(n.schema),n.resolver&&F(P,n.resolver),a},F=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},G=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Ce=(i,e,t)=>{let s=t||P;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return G(i)?"":(e&&(s=new I(e.schema),e.resolver&&F(s,e.resolver)),s.render(i))},Pe=()=>H(N);m.BlockTypes=k,m.MarkTypes=v,m.RichTextResolver=I,m.RichTextSchema=D,m.TextTypes=C,m.apiPlugin=Se,m.isRichTextEmpty=G,m.loadStoryblokBridge=Pe,m.registerStoryblokBridge=q,m.renderRichText=Ce,m.richTextResolver=Le,m.storyblokEditable=_e,m.storyblokInit=Ae,m.useStoryblokBridge=q,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
24
|
+
}`),""}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-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(o+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(o+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(o+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(o+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(o+=`:rotate(${t.filters.rotate})`),o.length>0&&(o="/filters"+o))),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|tiff|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,d;const u=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(u&&u.length>0){const m={srcset:(h=t.srcset)==null?void 0:h.map(b=>{if(typeof b=="number")return`//${u}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,L=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(L=b[1]),`//${u}/m/${S}x${L}${o} ${S}w`}}).join(", "),sizes:(d=t.sizes)==null?void 0:d.map(b=>b).join(", ")};let $="";return m.srcset&&($+=`srcset="${m.srcset}" `),m.sizes&&($+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${$.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(Te(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," /")}}const I=Re;class we{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 O;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 Se=we,z="SB-Agent",A={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let x={};const _={};class _e{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 o=new O().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.entries().toArray().forEach(([o,l])=>{r.set(o,l)}),r.has(z)||(r.set(z,A.defaultAgentName),r.set(A.defaultAgentVersion,A.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new I(e.richTextSchema):this.richTextResolver=new I,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Y(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new O,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new Se({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,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}`,l=o.split("/"),a=s||l[l.length-1],h=1,d=await this.makeRequest(o,t,n,h,r),u=d.total?Math.ceil(d.total/n):1,m=await this.helpers.asyncMap(this.helpers.range(h,u),$=>this.makeRequest(o,t,n,$+1,r));return this.helpers.flatMap([d,...m],$=>Object.values($.data[a]))}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){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]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let o=0;o<n.length;o++)r(n[o]);else if(n.constructor===Object){if(n._stopResolving)return;for(const o in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,o,t,s),this._insertLinks(n,o,s)),r(n[o])}}};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,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,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"].indexOf(t.resolve_links)>-1&&((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(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),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 d=await this.throttle("get",e,t,r);if(d.status!==200)return a(d);let u={data:d.data,headers:d.headers};if((h=d.headers)!=null&&h["per-page"]&&(u=Object.assign({},u,{perPage:d.headers["per-page"]?parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?parseInt(d.headers.total):0})),u.data.story||u.data.stories){const m=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${m}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(n,u),u.data.cv&&t.token&&(t.version==="draft"&&_[t.token]!=u.data.cv&&await this.flushCache(),_[t.token]=t.cv?t.cv:u.data.cv),l(u)}catch(d){if(d.response&&d.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(d)}})}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(x[e])},getAll(){return Promise.resolve(x)},set(e,t){return x[e]=t,Promise.resolve(void 0)},flush(){return x={},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 Ee=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new _e(e)}},Ie=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{}}};var k=(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))(k||{}),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))(v||{}),C=(i=>(i.TEXT="text",i))(C||{}),j=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(j||{});function je(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,h,d,u,m){typeof a!="number"||a<=h||a>=d?console.warn(`[StoryblokRichText] - ${u.charAt(0).toUpperCase()+u.slice(1)} value must be a number between ${h} and ${d} (inclusive)`):m.push(`${u}(${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:d,fill:u,format:m,grayscale:$,quality:b,rotate:S}=a||{};h&&o(h,0,100,"blur",n),b&&o(b,0,100,"quality",n),d&&o(d,0,100,"brightness",n),u&&n.push(`fill(${u})`),$&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),m&&["webp","png","jpeg"].includes(m)&&n.push(`format(${m})`)}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,d]=a;return`${i}/m/${h}x${d}/${n.length>0?"filters:"+n.join(":"):""} ${h}w`}}).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}}const Oe=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),xe=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Le(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ae(i,e={},t){const s=Oe(e);return`<${s?`${i} ${s}`:i}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Ce(i={}){let e=0;const{renderFn:t=Ae,textFn:s=Le,resolvers:r={},optimizeImages:n=!1}=i,o=c=>g=>t(c,{...g.attrs,key:`${c}-${e}`},g.children||null),l=c=>{const{src:g,alt:f,...T}=c.attrs||{};let R=g,w={};if(n){const{src:He,attrs:Be}=je(g,n);R=He,w=Be}const Ue={src:R,alt:f||"",key:`img-${e}`,...T,...w};return t("img",Ue,"")},a=c=>{const{level:g,...f}=c.attrs||{};return t(`h${g}`,{...f,key:`h${g}-${e}`},c.children)},h=c=>{var g,f,T,R;return t("span",{"data-type":"emoji","data-name":(g=c.attrs)==null?void 0:g.name,emoji:(f=c.attrs)==null?void 0:f.emoji,key:`emoji-${e}`},t("img",{src:(T=c.attrs)==null?void 0:T.fallbackImage,alt:(R=c.attrs)==null?void 0:R.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"},""))},d=c=>t("pre",{...c.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},c.children||"")),u=(c,g=!1)=>({text:f,attrs:T})=>t(c,g?{style:xe(T),key:`${c}-${e}`}:{...T,key:`${c}-${e}`},f),m=c=>M(c),$=c=>{const{marks:g,...f}=c;return"text"in c?g?g.reduce((T,R)=>m({...R,text:T}),m({...f,children:f.children})):s(f.text):""},b=c=>{const{linktype:g,href:f,anchor:T,...R}=c.attrs||{};let w="";switch(g){case j.ASSET:case j.URL:w=f;break;case j.EMAIL:w=`mailto:${f}`;break;case j.STORY:w=f;break}return T&&(w=`${w}#${T}`),t("a",{...R,href:w,key:`a-${e}`},c.text)},S=c=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(g=c==null?void 0:c.attrs)==null?void 0:g.body[0],id:(f=c.attrs)==null?void 0:f.id,key:`component-${e}`,style:"display: none"},"")},L=new Map([[k.DOCUMENT,o("div")],[k.HEADING,a],[k.PARAGRAPH,o("p")],[k.UL_LIST,o("ul")],[k.OL_LIST,o("ol")],[k.LIST_ITEM,o("li")],[k.IMAGE,l],[k.EMOJI,h],[k.CODE_BLOCK,d],[k.HR,o("hr")],[k.BR,o("br")],[k.QUOTE,o("blockquote")],[k.COMPONENT,S],[C.TEXT,$],[v.LINK,b],[v.ANCHOR,b],[v.STYLED,u("span",!0)],[v.BOLD,u("strong")],[v.TEXT_STYLE,u("span",!0)],[v.ITALIC,u("em")],[v.UNDERLINE,u("u")],[v.STRIKE,u("s")],[v.CODE,u("code")],[v.SUPERSCRIPT,u("sup")],[v.SUBSCRIPT,u("sub")],[v.HIGHLIGHT,u("mark")],...Object.entries(r).map(([c,g])=>[c,g])]);function J(c){e+=1;const g=L.get(c.type);if(!g)return console.error("<Storyblok>",`No resolver found for node type ${c.type}`),"";if(c.type==="text")return g(c);const f=c.content?c.content.map(M):void 0;return g({...c,children:f})}function M(c){return Array.isArray(c)?c.map(J):J(c)}return{render:M}}let P,N="https://app.storyblok.com/f/storyblok-v2-latest.js";const q=(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")===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=>{h.action==="input"&&h.story.id===i?e(h.story):(h.action==="change"||h.action==="published")&&h.storyId===i&&window.location.reload()})})}},Pe=(i={})=>{var u,m;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($=>{a={...a,...$(l)}}),o&&(N=o);const d=!(typeof window>"u")&&((m=(u=window.location)==null?void 0:u.search)==null?void 0:m.includes("_storyblok_tk"));return e!==!1&&d&&H(N),P=new I(n.schema),n.resolver&&G(P,n.resolver),a},G=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},V=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Ne=(i,e,t)=>{let s=t||P;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return V(i)?"":(e&&(s=new I(e.schema),e.resolver&&G(s,e.resolver)),s.render(i))},Me=()=>H(N);y.BlockTypes=k,y.MarkTypes=v,y.RichTextResolver=I,y.RichTextSchema=D,y.TextTypes=C,y.apiPlugin=Ee,y.isRichTextEmpty=V,y.loadStoryblokBridge=Me,y.registerStoryblokBridge=q,y.renderRichText=Ne,y.richTextResolver=Ce,y.storyblokEditable=Ie,y.storyblokInit=Pe,y.useStoryblokBridge=q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
@@ -12,7 +12,7 @@ const M = [], D = (i) => new Promise((e, t) => {
|
|
12
12
|
M.forEach((n) => n()), N = !0, e(r);
|
13
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
14
14
|
});
|
15
|
-
var
|
15
|
+
var J = Object.defineProperty, F = (i, e, t) => e in i ? J(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => F(i, typeof e != "symbol" ? e + "" : e, t);
|
16
16
|
function U(i) {
|
17
17
|
return !(i !== i || i === 1 / 0 || i === -1 / 0);
|
18
18
|
}
|
@@ -26,42 +26,42 @@ function K(i, e, t) {
|
|
26
26
|
const o = function() {
|
27
27
|
n++;
|
28
28
|
const a = setTimeout(function() {
|
29
|
-
n--, s.length > 0 && o(), r = r.filter(function(
|
30
|
-
return
|
29
|
+
n--, s.length > 0 && o(), r = r.filter(function(d) {
|
30
|
+
return d !== a;
|
31
31
|
});
|
32
32
|
}, t);
|
33
33
|
r.indexOf(a) < 0 && r.push(a);
|
34
|
-
const
|
35
|
-
|
36
|
-
},
|
37
|
-
const
|
38
|
-
return new Promise(function(
|
34
|
+
const h = s.shift();
|
35
|
+
h.resolve(i.apply(h.self, h.args));
|
36
|
+
}, l = function(...a) {
|
37
|
+
const h = this;
|
38
|
+
return new Promise(function(d, u) {
|
39
39
|
s.push({
|
40
|
-
resolve:
|
41
|
-
reject:
|
40
|
+
resolve: d,
|
41
|
+
reject: u,
|
42
42
|
args: a,
|
43
|
-
self:
|
43
|
+
self: h
|
44
44
|
}), n < e && o();
|
45
45
|
});
|
46
46
|
};
|
47
|
-
return
|
47
|
+
return l.abort = function() {
|
48
48
|
r.forEach(clearTimeout), r = [], s.forEach(function(a) {
|
49
49
|
a.reject(function() {
|
50
50
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
51
51
|
});
|
52
52
|
}), s.length = 0;
|
53
|
-
},
|
53
|
+
}, l;
|
54
54
|
}
|
55
|
-
class
|
55
|
+
class x {
|
56
56
|
constructor() {
|
57
|
-
|
57
|
+
p(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
58
58
|
...e,
|
59
59
|
per_page: t,
|
60
60
|
page: s
|
61
|
-
})),
|
61
|
+
})), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), p(this, "range", (e = 0, t = e) => {
|
62
62
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
63
63
|
return this.arrayFrom(s, (n, o) => o * r + e);
|
64
|
-
}),
|
64
|
+
}), p(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), p(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), p(this, "escapeHTML", function(e) {
|
65
65
|
const t = {
|
66
66
|
"&": "&",
|
67
67
|
"<": "<",
|
@@ -84,13 +84,13 @@ class O {
|
|
84
84
|
for (const n in e) {
|
85
85
|
if (!Object.prototype.hasOwnProperty.call(e, n))
|
86
86
|
continue;
|
87
|
-
const o = e[n],
|
87
|
+
const o = e[n], l = s ? "" : encodeURIComponent(n);
|
88
88
|
let a;
|
89
89
|
typeof o == "object" ? a = this.stringify(
|
90
90
|
o,
|
91
|
-
t ? t + encodeURIComponent("[" +
|
91
|
+
t ? t + encodeURIComponent("[" + l + "]") : l,
|
92
92
|
Array.isArray(o)
|
93
|
-
) : a = (t ? t + encodeURIComponent("[" +
|
93
|
+
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(o), r.push(a);
|
94
94
|
}
|
95
95
|
return r.join("&");
|
96
96
|
}
|
@@ -181,7 +181,7 @@ const Y = function(i, e) {
|
|
181
181
|
return {
|
182
182
|
tag: ""
|
183
183
|
};
|
184
|
-
const e = new
|
184
|
+
const e = new x().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
|
185
185
|
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), X(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
186
186
|
for (const r in t.custom)
|
187
187
|
t[r] = t.custom[r];
|
@@ -280,9 +280,9 @@ const Y = function(i, e) {
|
|
280
280
|
}, t = /[&<>"']/g, s = RegExp(t.source);
|
281
281
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
282
282
|
};
|
283
|
-
class
|
283
|
+
class Re {
|
284
284
|
constructor(e) {
|
285
|
-
|
285
|
+
p(this, "marks"), p(this, "nodes"), e || (e = $e), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
286
286
|
}
|
287
287
|
addNode(e, t) {
|
288
288
|
this.nodes[e] = t;
|
@@ -292,7 +292,7 @@ class x {
|
|
292
292
|
}
|
293
293
|
render(e, t = { optimizeImages: !1 }) {
|
294
294
|
if (console.warn(
|
295
|
-
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` instead. https://github.com/storyblok/richtext/"
|
295
|
+
"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/"
|
296
296
|
), e && e.content && Array.isArray(e.content)) {
|
297
297
|
let s = "";
|
298
298
|
return e.content.forEach((r) => {
|
@@ -329,26 +329,26 @@ class x {
|
|
329
329
|
optimizeImages(e, t) {
|
330
330
|
let s = 0, r = 0, n = "", o = "";
|
331
331
|
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-Fa-f]{6}/g) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = "/filters" + o))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
|
332
|
-
const
|
332
|
+
const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
333
333
|
return e = e.replace(
|
334
334
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
335
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
335
|
+
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
336
336
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
337
|
-
var
|
338
|
-
const
|
337
|
+
var h, d;
|
338
|
+
const u = a.match(
|
339
339
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
340
340
|
);
|
341
|
-
if (
|
341
|
+
if (u && u.length > 0) {
|
342
342
|
const m = {
|
343
|
-
srcset: (
|
343
|
+
srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
|
344
344
|
if (typeof y == "number")
|
345
|
-
return `//${
|
345
|
+
return `//${u}/m/${y}x0${o} ${y}w`;
|
346
346
|
if (typeof y == "object" && y.length === 2) {
|
347
347
|
let w = 0, E = 0;
|
348
|
-
return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (E = y[1]), `//${
|
348
|
+
return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (E = y[1]), `//${u}/m/${w}x${E}${o} ${w}w`;
|
349
349
|
}
|
350
350
|
}).join(", "),
|
351
|
-
sizes: (
|
351
|
+
sizes: (d = t.sizes) == null ? void 0 : d.map((y) => y).join(", ")
|
352
352
|
};
|
353
353
|
let k = "";
|
354
354
|
return m.srcset && (k += `srcset="${m.srcset}" `), m.sizes && (k += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
|
@@ -376,11 +376,13 @@ class x {
|
|
376
376
|
return `<${s}${t}>`;
|
377
377
|
{
|
378
378
|
let r = `<${s.tag}`;
|
379
|
-
if (s.attrs)
|
380
|
-
for (const n in s.attrs)
|
381
|
-
|
382
|
-
|
383
|
-
|
379
|
+
if (s.attrs) {
|
380
|
+
for (const n in s.attrs)
|
381
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
|
382
|
+
const o = s.attrs[n];
|
383
|
+
o !== null && (r += ` ${n}="${o}"`);
|
384
|
+
}
|
385
|
+
}
|
384
386
|
return `${r}${t}>`;
|
385
387
|
}
|
386
388
|
}).join("");
|
@@ -418,9 +420,10 @@ class x {
|
|
418
420
|
return this.renderTag(t, " /");
|
419
421
|
}
|
420
422
|
}
|
421
|
-
|
423
|
+
const j = Re;
|
424
|
+
class we {
|
422
425
|
constructor(e) {
|
423
|
-
|
426
|
+
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 = {};
|
424
427
|
}
|
425
428
|
/**
|
426
429
|
*
|
@@ -457,15 +460,15 @@ class Re {
|
|
457
460
|
async _methodHandler(e) {
|
458
461
|
let t = `${this.baseURL}${this.url}`, s = null;
|
459
462
|
if (e === "get") {
|
460
|
-
const a = new
|
463
|
+
const a = new x();
|
461
464
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
462
465
|
this.parameters
|
463
466
|
)}`;
|
464
467
|
} else
|
465
468
|
s = JSON.stringify(this.parameters);
|
466
469
|
const r = new URL(t), n = new AbortController(), { signal: o } = n;
|
467
|
-
let
|
468
|
-
this.timeout && (
|
470
|
+
let l;
|
471
|
+
this.timeout && (l = setTimeout(() => n.abort(), this.timeout));
|
469
472
|
try {
|
470
473
|
const a = await this.fetch(`${r}`, {
|
471
474
|
method: e,
|
@@ -474,11 +477,11 @@ class Re {
|
|
474
477
|
signal: o,
|
475
478
|
...this.fetchOptions
|
476
479
|
});
|
477
|
-
this.timeout && clearTimeout(
|
478
|
-
const
|
480
|
+
this.timeout && clearTimeout(l);
|
481
|
+
const h = await this._responseHandler(
|
479
482
|
a
|
480
483
|
);
|
481
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
484
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
|
482
485
|
} catch (a) {
|
483
486
|
return {
|
484
487
|
message: a
|
@@ -505,36 +508,35 @@ class Re {
|
|
505
508
|
});
|
506
509
|
}
|
507
510
|
}
|
508
|
-
const H = "SB-Agent", L = {
|
511
|
+
const Se = we, H = "SB-Agent", L = {
|
509
512
|
defaultAgentName: "SB-JS-CLIENT",
|
510
513
|
defaultAgentVersion: "SB-Agent-Version",
|
511
514
|
packageVersion: "6.0.0"
|
512
515
|
};
|
513
516
|
let I = {};
|
514
517
|
const S = {};
|
515
|
-
class
|
518
|
+
class _e {
|
516
519
|
/**
|
517
520
|
*
|
518
521
|
* @param config ISbConfig interface
|
519
522
|
* @param endpoint string, optional
|
520
523
|
*/
|
521
524
|
constructor(e, t) {
|
522
|
-
|
525
|
+
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");
|
523
526
|
let s = e.endpoint || t;
|
524
527
|
if (!s) {
|
525
|
-
const o = new
|
526
|
-
e.oauthToken ? s = `${
|
528
|
+
const o = new x().getRegionURL, l = e.https === !1 ? "http" : "https";
|
529
|
+
e.oauthToken ? s = `${l}://${o(e.region)}/v1` : s = `${l}://${o(e.region)}/v2`;
|
527
530
|
}
|
528
531
|
const r = new Headers();
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
r.has(H) || (r.set(H, L.defaultAgentName), r.set(
|
532
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && e.headers.entries().toArray().forEach(([o, l]) => {
|
533
|
+
r.set(o, l);
|
534
|
+
}), r.has(H) || (r.set(H, L.defaultAgentName), r.set(
|
533
535
|
L.defaultAgentVersion,
|
534
536
|
L.packageVersion
|
535
537
|
));
|
536
538
|
let n = 5;
|
537
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new
|
539
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new j(e.richTextSchema) : this.richTextResolver = new j(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = K(this.throttledRequest, 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 Se({
|
538
540
|
baseURL: s,
|
539
541
|
timeout: e.timeout || 0,
|
540
542
|
headers: r,
|
@@ -558,47 +560,51 @@ class we {
|
|
558
560
|
factoryParamOptions(e, t) {
|
559
561
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
560
562
|
}
|
561
|
-
makeRequest(e, t, s, r) {
|
562
|
-
const
|
563
|
+
makeRequest(e, t, s, r, n) {
|
564
|
+
const o = this.factoryParamOptions(
|
563
565
|
e,
|
564
566
|
this.helpers.getOptionsPage(t, s, r)
|
565
567
|
);
|
566
|
-
return this.cacheResponse(e, n);
|
568
|
+
return this.cacheResponse(e, o, void 0, n);
|
567
569
|
}
|
568
570
|
get(e, t, s) {
|
569
571
|
t || (t = {});
|
570
572
|
const r = `/${e}`, n = this.factoryParamOptions(r, t);
|
571
|
-
return this.
|
573
|
+
return this.cacheResponse(r, n, void 0, s);
|
572
574
|
}
|
573
575
|
async getAll(e, t, s, r) {
|
574
|
-
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`,
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
576
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, l = o.split("/"), a = s || l[l.length - 1], h = 1, d = await this.makeRequest(
|
577
|
+
o,
|
578
|
+
t,
|
579
|
+
n,
|
580
|
+
h,
|
581
|
+
r
|
582
|
+
), u = d.total ? Math.ceil(d.total / n) : 1, m = await this.helpers.asyncMap(
|
583
|
+
this.helpers.range(h, u),
|
584
|
+
(k) => this.makeRequest(o, t, n, k + 1, r)
|
579
585
|
);
|
580
586
|
return this.helpers.flatMap(
|
581
|
-
[
|
587
|
+
[d, ...m],
|
582
588
|
(k) => Object.values(k.data[a])
|
583
589
|
);
|
584
590
|
}
|
585
591
|
post(e, t, s) {
|
586
592
|
const r = `/${e}`;
|
587
|
-
return
|
593
|
+
return Promise.resolve(this.throttle("post", r, t, s));
|
588
594
|
}
|
589
595
|
put(e, t, s) {
|
590
596
|
const r = `/${e}`;
|
591
|
-
return
|
597
|
+
return Promise.resolve(this.throttle("put", r, t, s));
|
592
598
|
}
|
593
599
|
delete(e, t, s) {
|
594
600
|
const r = `/${e}`;
|
595
|
-
return
|
601
|
+
return Promise.resolve(this.throttle("delete", r, t, s));
|
596
602
|
}
|
597
603
|
getStories(e, t) {
|
598
|
-
return this.
|
604
|
+
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
599
605
|
}
|
600
606
|
getStory(e, t, s) {
|
601
|
-
return this.
|
607
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
|
602
608
|
}
|
603
609
|
getToken() {
|
604
610
|
return this.accessToken;
|
@@ -658,20 +664,20 @@ class we {
|
|
658
664
|
async resolveLinks(e, t, s) {
|
659
665
|
let r = [];
|
660
666
|
if (e.link_uuids) {
|
661
|
-
const n = e.link_uuids.length, o = [],
|
662
|
-
for (let a = 0; a < n; a +=
|
663
|
-
const
|
664
|
-
o.push(e.link_uuids.slice(a,
|
667
|
+
const n = e.link_uuids.length, o = [], l = 50;
|
668
|
+
for (let a = 0; a < n; a += l) {
|
669
|
+
const h = Math.min(n, a + l);
|
670
|
+
o.push(e.link_uuids.slice(a, h));
|
665
671
|
}
|
666
672
|
for (let a = 0; a < o.length; a++)
|
667
673
|
(await this.getStories({
|
668
|
-
per_page:
|
674
|
+
per_page: l,
|
669
675
|
language: t.language,
|
670
676
|
version: t.version,
|
671
677
|
by_uuids: o[a].join(",")
|
672
678
|
})).data.stories.forEach(
|
673
|
-
(
|
674
|
-
r.push(
|
679
|
+
(h) => {
|
680
|
+
r.push(h);
|
675
681
|
}
|
676
682
|
);
|
677
683
|
} else
|
@@ -686,20 +692,20 @@ class we {
|
|
686
692
|
async resolveRelations(e, t, s) {
|
687
693
|
let r = [];
|
688
694
|
if (e.rel_uuids) {
|
689
|
-
const n = e.rel_uuids.length, o = [],
|
690
|
-
for (let a = 0; a < n; a +=
|
691
|
-
const
|
692
|
-
o.push(e.rel_uuids.slice(a,
|
695
|
+
const n = e.rel_uuids.length, o = [], l = 50;
|
696
|
+
for (let a = 0; a < n; a += l) {
|
697
|
+
const h = Math.min(n, a + l);
|
698
|
+
o.push(e.rel_uuids.slice(a, h));
|
693
699
|
}
|
694
700
|
for (let a = 0; a < o.length; a++)
|
695
701
|
(await this.getStories({
|
696
|
-
per_page:
|
702
|
+
per_page: l,
|
697
703
|
language: t.language,
|
698
704
|
version: t.version,
|
699
705
|
by_uuids: o[a].join(","),
|
700
706
|
excluding_fields: t.excluding_fields
|
701
|
-
})).data.stories.forEach((
|
702
|
-
r.push(
|
707
|
+
})).data.stories.forEach((h) => {
|
708
|
+
r.push(h);
|
703
709
|
});
|
704
710
|
} else
|
705
711
|
r = e.rels;
|
@@ -723,49 +729,49 @@ class we {
|
|
723
729
|
var r, n;
|
724
730
|
let o = [];
|
725
731
|
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"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
726
|
-
for (const
|
732
|
+
for (const l in this.relations[s])
|
727
733
|
this.iterateTree(
|
728
|
-
this.relations[s][
|
734
|
+
this.relations[s][l],
|
729
735
|
o,
|
730
736
|
s
|
731
737
|
);
|
732
|
-
e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((
|
733
|
-
this.iterateTree(
|
738
|
+
e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((l) => {
|
739
|
+
this.iterateTree(l, o, s);
|
734
740
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
735
741
|
}
|
736
|
-
async cacheResponse(e, t, s) {
|
737
|
-
const
|
742
|
+
async cacheResponse(e, t, s, r) {
|
743
|
+
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
738
744
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
739
|
-
const
|
740
|
-
if (
|
741
|
-
return Promise.resolve(
|
745
|
+
const l = await o.get(n);
|
746
|
+
if (l)
|
747
|
+
return Promise.resolve(l);
|
742
748
|
}
|
743
|
-
return new Promise(async (
|
744
|
-
var
|
749
|
+
return new Promise(async (l, a) => {
|
750
|
+
var h;
|
745
751
|
try {
|
746
|
-
const
|
747
|
-
if (
|
748
|
-
return
|
749
|
-
let u = { data:
|
750
|
-
if ((
|
751
|
-
perPage:
|
752
|
-
total:
|
752
|
+
const d = await this.throttle("get", e, t, r);
|
753
|
+
if (d.status !== 200)
|
754
|
+
return a(d);
|
755
|
+
let u = { data: d.data, headers: d.headers };
|
756
|
+
if ((h = d.headers) != null && h["per-page"] && (u = Object.assign({}, u, {
|
757
|
+
perPage: d.headers["per-page"] ? parseInt(d.headers["per-page"]) : 0,
|
758
|
+
total: d.headers["per-page"] ? parseInt(d.headers.total) : 0
|
753
759
|
})), u.data.story || u.data.stories) {
|
754
|
-
const
|
755
|
-
await this.resolveStories(u.data, t, `${
|
760
|
+
const m = this.resolveCounter = ++this.resolveCounter % 1e3;
|
761
|
+
await this.resolveStories(u.data, t, `${m}`);
|
756
762
|
}
|
757
|
-
return t.version === "published" && e != "/cdn/spaces/me" && await
|
758
|
-
} catch (
|
759
|
-
if (
|
763
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await o.set(n, u), u.data.cv && t.token && (t.version === "draft" && S[t.token] != u.data.cv && await this.flushCache(), S[t.token] = t.cv ? t.cv : u.data.cv), l(u);
|
764
|
+
} catch (d) {
|
765
|
+
if (d.response && d.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
760
766
|
return console.log(
|
761
767
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
762
|
-
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(
|
763
|
-
|
768
|
+
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
769
|
+
a(d);
|
764
770
|
}
|
765
771
|
});
|
766
772
|
}
|
767
|
-
throttledRequest(e, t, s) {
|
768
|
-
return this.client[e](t, s);
|
773
|
+
throttledRequest(e, t, s, r) {
|
774
|
+
return this.client.setFetchOptions(r), this.client[e](t, s);
|
769
775
|
}
|
770
776
|
cacheVersions() {
|
771
777
|
return S;
|
@@ -797,8 +803,7 @@ class we {
|
|
797
803
|
}
|
798
804
|
};
|
799
805
|
case "custom":
|
800
|
-
if (this.cache.custom)
|
801
|
-
return this.cache.custom;
|
806
|
+
if (this.cache.custom) return this.cache.custom;
|
802
807
|
default:
|
803
808
|
return {
|
804
809
|
get() {
|
@@ -820,7 +825,7 @@ class we {
|
|
820
825
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
821
826
|
}
|
822
827
|
}
|
823
|
-
const
|
828
|
+
const Ae = (i = {}) => {
|
824
829
|
const { apiOptions: e } = i;
|
825
830
|
if (!e.accessToken) {
|
826
831
|
console.error(
|
@@ -828,8 +833,8 @@ const je = (i = {}) => {
|
|
828
833
|
);
|
829
834
|
return;
|
830
835
|
}
|
831
|
-
return { storyblokApi: new
|
832
|
-
},
|
836
|
+
return { storyblokApi: new _e(e) };
|
837
|
+
}, Ce = (i) => {
|
833
838
|
if (typeof i != "object" || typeof i._editable > "u")
|
834
839
|
return {};
|
835
840
|
try {
|
@@ -845,54 +850,54 @@ const je = (i = {}) => {
|
|
845
850
|
}
|
846
851
|
};
|
847
852
|
var b = /* @__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))(b || {}), v = /* @__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))(v || {}), z = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(z || {}), _ = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(_ || {});
|
848
|
-
function
|
853
|
+
function Ee(i, e) {
|
849
854
|
if (!e) return { src: i, attrs: {} };
|
850
855
|
let t = 0, s = 0;
|
851
856
|
const r = {}, n = [];
|
852
|
-
function o(a,
|
853
|
-
typeof a != "number" || a <=
|
857
|
+
function o(a, h, d, u, m) {
|
858
|
+
typeof a != "number" || a <= h || a >= d ? console.warn(`[StoryblokRichText] - ${u.charAt(0).toUpperCase() + u.slice(1)} value must be a number between ${h} and ${d} (inclusive)`) : m.push(`${u}(${a})`);
|
854
859
|
}
|
855
860
|
if (typeof e == "object") {
|
856
|
-
if (typeof e.width == "number" && e.width > 0 ? (r.width = e.width, t = e.width) : console.warn("[
|
857
|
-
const { filters: a } = e || {}, { blur:
|
858
|
-
|
861
|
+
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) {
|
862
|
+
const { filters: a } = e || {}, { blur: h, brightness: d, fill: u, format: m, grayscale: k, quality: y, rotate: w } = a || {};
|
863
|
+
h && o(h, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), d && o(d, 0, 100, "brightness", n), u && n.push(`fill(${u})`), k && n.push("grayscale()"), w && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${w})`), m && ["webp", "png", "jpeg"].includes(m) && n.push(`format(${m})`);
|
859
864
|
}
|
860
865
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
861
866
|
if (typeof a == "number")
|
862
867
|
return `${i}/m/${a}x0/${n.length > 0 ? "filters:" + n.join(":") : ""} ${a}w`;
|
863
868
|
if (Array.isArray(a) && a.length === 2) {
|
864
|
-
const [
|
865
|
-
return `${i}/m/${
|
869
|
+
const [h, d] = a;
|
870
|
+
return `${i}/m/${h}x${d}/${n.length > 0 ? "filters:" + n.join(":") : ""} ${h}w`;
|
866
871
|
}
|
867
872
|
}).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
|
868
873
|
}
|
869
|
-
let
|
870
|
-
return t > 0 && s > 0 && (
|
871
|
-
src:
|
874
|
+
let l = `${i}/m/`;
|
875
|
+
return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
|
876
|
+
src: l,
|
872
877
|
attrs: r
|
873
878
|
};
|
874
879
|
}
|
875
|
-
const
|
876
|
-
function
|
880
|
+
const Ie = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), xe = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
|
881
|
+
function je(i) {
|
877
882
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
878
883
|
}
|
879
884
|
function Oe(i, e = {}, t) {
|
880
|
-
const s =
|
885
|
+
const s = Ie(e);
|
881
886
|
return `<${s ? `${i} ${s}` : i}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
|
882
887
|
}
|
883
|
-
function
|
888
|
+
function Pe(i = {}) {
|
884
889
|
let e = 0;
|
885
890
|
const {
|
886
891
|
renderFn: t = Oe,
|
887
|
-
textFn: s =
|
892
|
+
textFn: s = je,
|
888
893
|
resolvers: r = {},
|
889
894
|
optimizeImages: n = !1
|
890
|
-
} = i, o = (
|
891
|
-
const { src: g, alt: f, ...$ } =
|
895
|
+
} = i, o = (c) => (g) => t(c, { ...g.attrs, key: `${c}-${e}` }, g.children || null), l = (c) => {
|
896
|
+
const { src: g, alt: f, ...$ } = c.attrs || {};
|
892
897
|
let T = g, R = {};
|
893
898
|
if (n) {
|
894
|
-
const { src:
|
895
|
-
T =
|
899
|
+
const { src: G, attrs: V } = Ee(g, n);
|
900
|
+
T = G, R = V;
|
896
901
|
}
|
897
902
|
const q = {
|
898
903
|
src: T,
|
@@ -902,36 +907,36 @@ function Ae(i = {}) {
|
|
902
907
|
...R
|
903
908
|
};
|
904
909
|
return t("img", q, "");
|
905
|
-
}, a = (
|
906
|
-
const { level: g, ...f } =
|
907
|
-
return t(`h${g}`, { ...f, key: `h${g}-${e}` },
|
908
|
-
},
|
910
|
+
}, a = (c) => {
|
911
|
+
const { level: g, ...f } = c.attrs || {};
|
912
|
+
return t(`h${g}`, { ...f, key: `h${g}-${e}` }, c.children);
|
913
|
+
}, h = (c) => {
|
909
914
|
var g, f, $, T;
|
910
915
|
return t("span", {
|
911
916
|
"data-type": "emoji",
|
912
|
-
"data-name": (g =
|
913
|
-
emoji: (f =
|
917
|
+
"data-name": (g = c.attrs) == null ? void 0 : g.name,
|
918
|
+
emoji: (f = c.attrs) == null ? void 0 : f.emoji,
|
914
919
|
key: `emoji-${e}`
|
915
920
|
}, t("img", {
|
916
|
-
src: ($ =
|
917
|
-
alt: (T =
|
921
|
+
src: ($ = c.attrs) == null ? void 0 : $.fallbackImage,
|
922
|
+
alt: (T = c.attrs) == null ? void 0 : T.alt,
|
918
923
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
919
924
|
draggable: "false",
|
920
925
|
loading: "lazy"
|
921
926
|
}, ""));
|
922
|
-
},
|
923
|
-
style:
|
924
|
-
key: `${
|
925
|
-
} : { ...$, key: `${
|
926
|
-
const { marks: g, ...f } =
|
927
|
-
return "text" in
|
927
|
+
}, d = (c) => t("pre", { ...c.attrs, key: `code-${e}` }, t("code", { key: `code-${e}` }, c.children || "")), u = (c, g = !1) => ({ text: f, attrs: $ }) => t(c, g ? {
|
928
|
+
style: xe($),
|
929
|
+
key: `${c}-${e}`
|
930
|
+
} : { ...$, key: `${c}-${e}` }, f), m = (c) => O(c), k = (c) => {
|
931
|
+
const { marks: g, ...f } = c;
|
932
|
+
return "text" in c ? g ? g.reduce(
|
928
933
|
($, T) => m({ ...T, text: $ }),
|
929
934
|
// Fix: Ensure render function returns a string
|
930
935
|
m({ ...f, children: f.children })
|
931
936
|
// Fix: Cast children to string
|
932
937
|
) : s(f.text) : "";
|
933
|
-
}, y = (
|
934
|
-
const { linktype: g, href: f, anchor: $, ...T } =
|
938
|
+
}, y = (c) => {
|
939
|
+
const { linktype: g, href: f, anchor: $, ...T } = c.attrs || {};
|
935
940
|
let R = "";
|
936
941
|
switch (g) {
|
937
942
|
case _.ASSET:
|
@@ -945,12 +950,12 @@ function Ae(i = {}) {
|
|
945
950
|
R = f;
|
946
951
|
break;
|
947
952
|
}
|
948
|
-
return $ && (R = `${R}#${$}`), t("a", { ...T, href: R, key: `a-${e}` },
|
949
|
-
}, w = (
|
953
|
+
return $ && (R = `${R}#${$}`), t("a", { ...T, href: R, key: `a-${e}` }, c.text);
|
954
|
+
}, w = (c) => {
|
950
955
|
var g, f;
|
951
|
-
return console.warn("[
|
952
|
-
blok: (g =
|
953
|
-
id: (f =
|
956
|
+
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
957
|
+
blok: (g = c == null ? void 0 : c.attrs) == null ? void 0 : g.body[0],
|
958
|
+
id: (f = c.attrs) == null ? void 0 : f.id,
|
954
959
|
key: `component-${e}`,
|
955
960
|
style: "display: none"
|
956
961
|
}, "");
|
@@ -961,9 +966,9 @@ function Ae(i = {}) {
|
|
961
966
|
[b.UL_LIST, o("ul")],
|
962
967
|
[b.OL_LIST, o("ol")],
|
963
968
|
[b.LIST_ITEM, o("li")],
|
964
|
-
[b.IMAGE,
|
965
|
-
[b.EMOJI,
|
966
|
-
[b.CODE_BLOCK,
|
969
|
+
[b.IMAGE, l],
|
970
|
+
[b.EMOJI, h],
|
971
|
+
[b.CODE_BLOCK, d],
|
967
972
|
[b.HR, o("hr")],
|
968
973
|
[b.BR, o("br")],
|
969
974
|
[b.QUOTE, o("blockquote")],
|
@@ -971,43 +976,43 @@ function Ae(i = {}) {
|
|
971
976
|
[z.TEXT, k],
|
972
977
|
[v.LINK, y],
|
973
978
|
[v.ANCHOR, y],
|
974
|
-
[v.STYLED,
|
975
|
-
[v.BOLD,
|
976
|
-
[v.TEXT_STYLE,
|
977
|
-
[v.ITALIC,
|
978
|
-
[v.UNDERLINE,
|
979
|
-
[v.STRIKE,
|
980
|
-
[v.CODE,
|
981
|
-
[v.SUPERSCRIPT,
|
982
|
-
[v.SUBSCRIPT,
|
983
|
-
[v.HIGHLIGHT,
|
984
|
-
...Object.entries(r).map(([
|
979
|
+
[v.STYLED, u("span", !0)],
|
980
|
+
[v.BOLD, u("strong")],
|
981
|
+
[v.TEXT_STYLE, u("span", !0)],
|
982
|
+
[v.ITALIC, u("em")],
|
983
|
+
[v.UNDERLINE, u("u")],
|
984
|
+
[v.STRIKE, u("s")],
|
985
|
+
[v.CODE, u("code")],
|
986
|
+
[v.SUPERSCRIPT, u("sup")],
|
987
|
+
[v.SUBSCRIPT, u("sub")],
|
988
|
+
[v.HIGHLIGHT, u("mark")],
|
989
|
+
...Object.entries(r).map(([c, g]) => [c, g])
|
985
990
|
]);
|
986
|
-
function P(
|
991
|
+
function P(c) {
|
987
992
|
e += 1;
|
988
|
-
const g = E.get(
|
993
|
+
const g = E.get(c.type);
|
989
994
|
if (!g)
|
990
|
-
return console.error("<Storyblok>", `No resolver found for node type ${
|
991
|
-
if (
|
992
|
-
return g(
|
993
|
-
const f =
|
995
|
+
return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
|
996
|
+
if (c.type === "text")
|
997
|
+
return g(c);
|
998
|
+
const f = c.content ? c.content.map(O) : void 0;
|
994
999
|
return g({
|
995
|
-
...
|
1000
|
+
...c,
|
996
1001
|
children: f
|
997
1002
|
// Fix: Update the type of 'children' to Node[]
|
998
1003
|
});
|
999
1004
|
}
|
1000
|
-
function
|
1001
|
-
return Array.isArray(
|
1005
|
+
function O(c) {
|
1006
|
+
return Array.isArray(c) ? c.map(P) : P(c);
|
1002
1007
|
}
|
1003
1008
|
return {
|
1004
|
-
render:
|
1009
|
+
render: O
|
1005
1010
|
};
|
1006
1011
|
}
|
1007
1012
|
let A, C = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
1008
|
-
const
|
1009
|
-
var
|
1010
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((
|
1013
|
+
const Ne = (i, e, t = {}) => {
|
1014
|
+
var l;
|
1015
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
1011
1016
|
"_storyblok"
|
1012
1017
|
) === i;
|
1013
1018
|
if (!(!r || !o)) {
|
@@ -1016,13 +1021,13 @@ const Ce = (i, e, t = {}) => {
|
|
1016
1021
|
return;
|
1017
1022
|
}
|
1018
1023
|
window.storyblokRegisterEvent(() => {
|
1019
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
1020
|
-
|
1024
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (h) => {
|
1025
|
+
h.action === "input" && h.story.id === i ? e(h.story) : (h.action === "change" || h.action === "published") && h.storyId === i && window.location.reload();
|
1021
1026
|
});
|
1022
1027
|
});
|
1023
1028
|
}
|
1024
|
-
},
|
1025
|
-
var
|
1029
|
+
}, Me = (i = {}) => {
|
1030
|
+
var u, m;
|
1026
1031
|
const {
|
1027
1032
|
bridge: e,
|
1028
1033
|
accessToken: t,
|
@@ -1032,13 +1037,13 @@ const Ce = (i, e, t = {}) => {
|
|
1032
1037
|
bridgeUrl: o
|
1033
1038
|
} = i;
|
1034
1039
|
r.accessToken = r.accessToken || t;
|
1035
|
-
const
|
1040
|
+
const l = { bridge: e, apiOptions: r };
|
1036
1041
|
let a = {};
|
1037
1042
|
s.forEach((k) => {
|
1038
|
-
a = { ...a, ...k(
|
1043
|
+
a = { ...a, ...k(l) };
|
1039
1044
|
}), o && (C = o);
|
1040
|
-
const
|
1041
|
-
return e !== !1 &&
|
1045
|
+
const d = !(typeof window > "u") && ((m = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : m.includes("_storyblok_tk"));
|
1046
|
+
return e !== !1 && d && D(C), A = new j(n.schema), n.resolver && B(A, n.resolver), a;
|
1042
1047
|
}, B = (i, e) => {
|
1043
1048
|
i.addNode("blok", (t) => {
|
1044
1049
|
let s = "";
|
@@ -1048,7 +1053,7 @@ const Ce = (i, e, t = {}) => {
|
|
1048
1053
|
html: s
|
1049
1054
|
};
|
1050
1055
|
});
|
1051
|
-
},
|
1056
|
+
}, Le = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ue = (i, e, t) => {
|
1052
1057
|
let s = t || A;
|
1053
1058
|
if (!s) {
|
1054
1059
|
console.error(
|
@@ -1056,21 +1061,21 @@ const Ce = (i, e, t = {}) => {
|
|
1056
1061
|
);
|
1057
1062
|
return;
|
1058
1063
|
}
|
1059
|
-
return
|
1060
|
-
},
|
1064
|
+
return Le(i) ? "" : (e && (s = new j(e.schema), e.resolver && B(s, e.resolver)), s.render(i));
|
1065
|
+
}, He = () => D(C);
|
1061
1066
|
export {
|
1062
1067
|
b as BlockTypes,
|
1063
1068
|
v as MarkTypes,
|
1064
|
-
|
1069
|
+
j as RichTextResolver,
|
1065
1070
|
$e as RichTextSchema,
|
1066
1071
|
z as TextTypes,
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1072
|
+
Ae as apiPlugin,
|
1073
|
+
Le as isRichTextEmpty,
|
1074
|
+
He as loadStoryblokBridge,
|
1075
|
+
Ne as registerStoryblokBridge,
|
1076
|
+
Ue as renderRichText,
|
1077
|
+
Pe as richTextResolver,
|
1078
|
+
Ce as storyblokEditable,
|
1079
|
+
Me as storyblokInit,
|
1080
|
+
Ne as useStoryblokBridge
|
1076
1081
|
};
|
package/dist/types/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { SbSDKOptions, StoryblokBridgeConfigV2, ISbStoryData, SbInitResult, ISbRichtext, StoryblokComponentType, SbRichTextOptions } from "./types";
|
2
2
|
import { RichtextResolver } from "storyblok-js-client";
|
3
|
-
import { type SbRichTextOptions as stdSbRichTextOptions } from "@storyblok/richtext";
|
4
3
|
export declare const useStoryblokBridge: <T extends StoryblokComponentType<string> = any>(id: Number, cb: (newStory: ISbStoryData<T>) => void, options?: StoryblokBridgeConfigV2) => void;
|
5
4
|
export declare const storyblokInit: (pluginOptions?: SbSDKOptions) => SbInitResult;
|
6
5
|
export declare const isRichTextEmpty: (data?: ISbRichtext) => boolean;
|
@@ -11,9 +10,4 @@ export { default as apiPlugin } from "./modules/api";
|
|
11
10
|
export { default as storyblokEditable } from "./modules/editable";
|
12
11
|
export { RichtextResolver as RichTextResolver, RichtextSchema as RichTextSchema, } from "storyblok-js-client";
|
13
12
|
export * from "./types";
|
14
|
-
|
15
|
-
* This is a temporaly class to avoid type collision with the legacy richtext resolver.
|
16
|
-
* It will become ~~`newSbRichTextOptions`~~ -> `SbRichTextOptions` on v4.x
|
17
|
-
*/
|
18
|
-
export type newSbRichTextOptions = stdSbRichTextOptions;
|
19
|
-
export { BlockTypes, MarkTypes, richTextResolver, TextTypes, type SbRichTextDocumentNode, type SbRichTextNodeTypes, type SbRichTextNode, type SbRichTextResolvers, type SbRichTextNodeResolver, type SbRichTextImageOptimizationOptions, } from "@storyblok/richtext";
|
13
|
+
export { BlockTypes, MarkTypes, richTextResolver, TextTypes, type StoryblokRichTextOptions, type StoryblokRichTextDocumentNode, type StoryblokRichTextNodeTypes, type StoryblokRichTextNode, type StoryblokRichTextResolvers, type StoryblokRichTextNodeResolver, type StoryblokRichTextImageOptimizationOptions, } from "@storyblok/richtext";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storyblok/js",
|
3
|
-
"version": "3.1.0
|
3
|
+
"version": "3.1.0",
|
4
4
|
"description": "SDK to integrate Storyblok into your project using JavaScript.",
|
5
5
|
"main": "./dist/storyblok-js.js",
|
6
6
|
"module": "./dist/storyblok-js.mjs",
|
@@ -28,18 +28,18 @@
|
|
28
28
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@storyblok/richtext": "^
|
32
|
-
"storyblok-js-client": "^6.9.0
|
31
|
+
"@storyblok/richtext": "^2.0.0",
|
32
|
+
"storyblok-js-client": "^6.9.0"
|
33
33
|
},
|
34
34
|
"devDependencies": {
|
35
|
-
"@tsconfig/recommended": "^1.0.
|
36
|
-
"cypress": "^13.
|
35
|
+
"@tsconfig/recommended": "^1.0.7",
|
36
|
+
"cypress": "^13.13.3",
|
37
37
|
"eslint-plugin-cypress": "^2.15.1",
|
38
|
-
"eslint-plugin-jest": "^28.
|
38
|
+
"eslint-plugin-jest": "^28.8.0",
|
39
39
|
"isomorphic-fetch": "^3.0.0",
|
40
|
-
"start-server-and-test": "^2.0.
|
41
|
-
"vite": "^5.
|
42
|
-
"vitest": "^
|
40
|
+
"start-server-and-test": "^2.0.5",
|
41
|
+
"vite": "^5.4.2",
|
42
|
+
"vitest": "^2.0.5"
|
43
43
|
},
|
44
44
|
"babel": {
|
45
45
|
"presets": [
|