@storyblok/js 3.1.7 → 3.1.9
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 +24 -24
- package/dist/storyblok-js.mjs +221 -203
- package/dist/types/types.d.ts +1 -1
- package/package.json +8 -8
package/dist/storyblok-js.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
(function(y,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(y=typeof globalThis<"u"?globalThis:y||self,j(y.storyblok={}))})(this,function(y){"use strict";let j=!1;const z=[],B=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}j?r():z.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=>{z.forEach(n=>n()),j=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 c,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(c=t.srcset)==null?void 0:c.map(b=>{if(typeof b=="number")return`//${p}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,C=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(C=b[1]),`//${p}/m/${S}x${C}${o} ${S}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(b=>b).join(", ")};let T="";return g.srcset&&(T+=`srcset="${g.srcset}" `),g.sizes&&(T+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${T.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(_e(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 O=Ee;class Ie{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 L;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 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 n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const je=Ie,V="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const _={};class Oe{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 L().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,P.defaultAgentName),r.set(P.defaultAgentVersion,P.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Z(this.throttledRequest,n,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,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],c=1,u=await this.makeRequest(o,t,n,c,r),p=u.total?Math.ceil(u.total/n):1,g=await this.helpers.asyncMap(this.helpers.range(c,p),T=>this.makeRequest(o,t,n,T+1,r));return this.helpers.flatMap([u,...g],T=>Object.values(T.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 c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}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(c=>{r.push(c)})}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 c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}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(c=>{r.push(c)})}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 c;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((c=u.headers)!=null&&c["per-page"]&&(p=Object.assign({},p,{perPage:u.headers["per-page"]?parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?parseInt(u.headers.total):0})),p.data.story||p.data.stories){const g=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${g}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(n,p),p.data.cv&&t.token&&_[t.token]!=p.data.cv&&(await this.flushCache(),_[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 _}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(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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 xe=(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 Oe(e)}},Le=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 Ae(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,c,u,p,g){typeof a!="number"||a<=c||a>=u?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${c} and ${u} (inclusive)`):g.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:c,brightness:u,fill:p,format:g,grayscale:T,quality:b,rotate:S}=a||{};c&&o(c,0,100,"blur",n),b&&o(b,0,100,"quality",n),u&&o(u,0,100,"brightness",n),p&&n.push(`fill(${p})`),T&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),g&&["webp","png","jpeg"].includes(g)&&n.push(`format(${g})`)}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[c,u]=a;return`${i}/m/${c}x${u}/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),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 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||{}),$=(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))($||{}),N=(i=>(i.TEXT="text",i))(N||{}),x=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(x||{});const Ce=["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(" "),Ne=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Me(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const J=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function He(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i;return Ce.includes(i)?`<${r}>`:`<${r}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Ue(i={}){let e=0;const{renderFn:t=He,textFn:s=Me,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,l=h=>f=>{const m=f.attrs||{};return o&&(m.key=`${h}-${e}`),t(h,m,f.children||null)},a=h=>{const{src:f,alt:m,title:v,srcset:w,sizes:R}=h.attrs||{};let E=f,I={};if(n){const{src:Ve,attrs:Je}=Ae(f,n);E=Ve,I=Je}o&&(I={...I,key:`img-${e}`});const Ge={src:E,alt:m,title:v,srcset:w,sizes:R,...I};return t("img",J(Ge))},c=h=>{const{level:f,...m}=h.attrs||{},v={...m};return o&&(v.key=`h${f}-${e}`),t(`h${f}`,v,h.children)},u=h=>{var f,m,v,w;const R=t("img",{src:(f=h.attrs)==null?void 0:f.fallbackImage,alt:(m=h.attrs)==null?void 0:m.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),E={"data-type":"emoji","data-name":(v=h.attrs)==null?void 0:v.name,"data-emoji":(w=h.attrs)==null?void 0:w.emoji};return o&&(E.key=`emoji-${e}`),t("span",E,R)},p=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),g=(h,f=!1)=>({text:m,attrs:v})=>{const{class:w,id:R,...E}=v||{},I=f?{class:w,id:R,style:Ne(E)||void 0}:v||{};return o&&(I.key=`${h}-${e}`),t(h,J(I),m)},T=h=>U(h),b=h=>{const{marks:f,...m}=h;return"text"in h?f?f.reduce((v,w)=>T({...w,text:v}),T({...m,children:m.children})):s(m.text):""},S=h=>{const{linktype:f,href:m,anchor:v,...w}=h.attrs||{};let R="";switch(f){case x.ASSET:case x.URL:R=m;break;case x.EMAIL:R=`mailto:${m}`;break;case x.STORY:R=m;break}return v&&(R=`${R}#${v}`),t("a",{...w,href:R,key:`a-${e}`},h.text)},C=h=>{var f,m;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(f=h==null?void 0:h.attrs)==null?void 0:f.body[0],id:(m=h.attrs)==null?void 0:m.id,key:`component-${e}`,style:"display: none"})},qe=new Map([[k.DOCUMENT,l("div")],[k.HEADING,c],[k.PARAGRAPH,l("p")],[k.UL_LIST,l("ul")],[k.OL_LIST,l("ol")],[k.LIST_ITEM,l("li")],[k.IMAGE,a],[k.EMOJI,u],[k.CODE_BLOCK,p],[k.HR,l("hr")],[k.BR,l("br")],[k.QUOTE,l("blockquote")],[k.COMPONENT,C],[N.TEXT,b],[$.LINK,S],[$.ANCHOR,S],[$.STYLED,g("span",!0)],[$.BOLD,g("strong")],[$.TEXT_STYLE,g("span",!0)],[$.ITALIC,g("em")],[$.UNDERLINE,g("u")],[$.STRIKE,g("s")],[$.CODE,g("code")],[$.SUPERSCRIPT,g("sup")],[$.SUBSCRIPT,g("sub")],[$.HIGHLIGHT,g("mark")],...Object.entries(r).map(([h,f])=>[h,f])]);function X(h){e+=1;const f=qe.get(h.type);if(!f)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return f(h);const m=h.content?h.content.map(U):void 0;return f({...h,children:m})}function U(h){return Array.isArray(h)?h.map(X):X(h)}return{render:U}}let M,H="https://app.storyblok.com/f/storyblok-v2-latest.js";const F=(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"],c=>{c.action==="input"&&c.story.id===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload()})})}},ze=(i={})=>{var p,g;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(T=>{a={...a,...T(l)}}),o&&(H=o);const u=!(typeof window>"u")&&((g=(p=window.location)==null?void 0:p.search)==null?void 0:g.includes("_storyblok_tk"));return e!==!1&&u&&B(H),M=new O(n.schema),n.resolver&&K(M,n.resolver),a},K=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Y=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Be=(i,e,t)=>{let s=t||M;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Y(i)?"":(e&&(s=new O(e.schema),e.resolver&&K(s,e.resolver)),s.render(i,{},!1))},De=()=>B(H);y.BlockTypes=k,y.MarkTypes=$,y.RichTextResolver=O,y.RichTextSchema=q,y.TextTypes=N,y.apiPlugin=xe,y.isRichTextEmpty=Y,y.loadStoryblokBridge=De,y.registerStoryblokBridge=F,y.renderRichText=Be,y.richTextResolver=Ue,y.storyblokEditable=Le,y.storyblokInit=ze,y.useStoryblokBridge=F,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(y,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(y=typeof globalThis<"u"?globalThis:y||self,j(y.storyblok={}))})(this,function(y){"use strict";let j=!1;const z=[],B=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}j?r():z.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=>{z.forEach(n=>n()),j=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var X=Object.defineProperty,W=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e,t)=>W(i,typeof e!="symbol"?e+"":e,t);class Q extends Error{constructor(e){super(e),this.name="AbortError"}}function Z(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 c=s.shift();if(c)try{const u=await i(...c.args);c.resolve(u)}catch(u){c.reject(u)}const d=setTimeout(()=>{n--,s.length>0&&l(),r=r.filter(u=>u!==d)},t);r.includes(d)||r.push(d)},a=(...c)=>o?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((d,u)=>{s.push({resolve:d,reject:u,args:c}),n<e&&l()});return a.abort=()=>{o=!0,r.forEach(clearTimeout),r=[],s.forEach(c=>c.reject(()=>new Q("Throttle function aborted"))),s.length=0},a}let L=class{constructor(){p(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),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.from({length:e},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=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],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 ee=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},te=i=>i==="email",se=()=>({singleTag:"hr"}),re=()=>({tag:"blockquote"}),ie=()=>({tag:"ul"}),ne=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),oe=()=>({singleTag:"br"}),ae=i=>({tag:`h${i.attrs.level}`}),le=i=>({singleTag:[{tag:"img",attrs:ee(i.attrs,["src","alt","title"])}]}),ce=()=>({tag:"li"}),he=()=>({tag:"ol"}),ue=()=>({tag:"p"}),de=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),pe=()=>({tag:"b"}),ge=()=>({tag:"s"}),fe=()=>({tag:"u"}),me=()=>({tag:"strong"}),ye=()=>({tag:"code"}),be=()=>({tag:"i"}),ke=i=>{if(!i.attrs)return{tag:""};const e=new L().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),te(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}]}),$e=()=>({tag:"sub"}),Te=()=>({tag:"sup"}),we=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Re=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},D={nodes:{horizontal_rule:se,blockquote:re,bullet_list:ie,code_block:ne,hard_break:oe,heading:ae,image:le,list_item:ce,ordered_list:he,paragraph:ue,emoji:de},marks:{bold:pe,strike:ge,underline:fe,strong:me,code:ye,italic:be,link:ke,styled:ve,subscript:$e,superscript:Te,anchor:we,highlight:Re,textStyle:Se}},_e=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=new RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let q=!1;class Ee{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},s=!0){if(!q&&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/"),q=!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.
|
|
2
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
3
|
+
ISbRichtext:
|
|
4
|
+
content?: ISbRichtext[]
|
|
5
|
+
marks?: ISbRichtext[]
|
|
6
|
+
attrs?: any
|
|
7
|
+
text?: string
|
|
8
|
+
type: string
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
{
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
text: 'Hello World',
|
|
17
|
+
type: 'text'
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
type: 'paragraph'
|
|
21
|
+
}
|
|
22
|
+
],
|
|
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-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 c,d;const u=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(u&&u.length>0){const g={srcset:(c=t.srcset)==null?void 0:c.map(b=>{if(typeof b=="number")return`//${u}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,C=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(C=b[1]),`//${u}/m/${S}x${C}${o} ${S}w`}return""}).join(", "),sizes:(d=t.sizes)==null?void 0:d.map(b=>b).join(", ")};let w="";return g.srcset&&(w+=`srcset="${g.srcset}" `),g.sizes&&(w+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${w.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(_e(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 O=Ee;class Ie{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),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 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 n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const je=Ie,G="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const _={};class Oe{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 L().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(G)||(r.set(G,P.defaultAgentName),r.set(P.defaultAgentVersion,P.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Z(this.throttledRequest.bind(this),n,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,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,c=await this.makeRequest(o,t,n,a,r),d=c.total?Math.ceil(c.total/n):1,u=await this.helpers.asyncMap(this.helpers.range(a,d),g=>this.makeRequest(o,t,n,g+1,r));return this.helpers.flatMap([c,...u],g=>Object.values(g.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){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.includes(`${e.component}.${t}`)&&(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 c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}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(c=>{r.push(c)})}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 c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}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(c=>{r.push(c)})}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(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 c;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((c=d.headers)!=null&&c["per-page"]&&(u=Object.assign({},u,{perPage:d.headers["per-page"]?Number.parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?Number.parseInt(d.headers.total):0})),u.data.story||u.data.stories){const g=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${g}`)}return t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,u),u.data.cv&&t.token&&_[t.token]!==u.data.cv&&(await this.flushCache(),_[t.token]=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(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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 xe=(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 Oe(e)}},Le=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 Ae(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,c,d,u,g){typeof a!="number"||a<=c||a>=d?console.warn(`[StoryblokRichText] - ${u.charAt(0).toUpperCase()+u.slice(1)} value must be a number between ${c} and ${d} (inclusive)`):g.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:c,brightness:d,fill:u,format:g,grayscale:w,quality:b,rotate:S}=a||{};c&&o(c,0,100,"blur",n),b&&o(b,0,100,"quality",n),d&&o(d,0,100,"brightness",n),u&&n.push(`fill(${u})`),w&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),g&&["webp","png","jpeg"].includes(g)&&n.push(`format(${g})`)}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[c,d]=a;return`${i}/m/${c}x${d}/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),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 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||{}),$=(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))($||{}),N=(i=>(i.TEXT="text",i))(N||{}),x=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(x||{});const Ce=["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(" "),Ne=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Me(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const F=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function He(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i;return Ce.includes(i)?`<${r}>`:`<${r}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Ue(i={}){let e=0;const{renderFn:t=He,textFn:s=Me,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,l=h=>f=>{const m=f.attrs||{};return o&&(m.key=`${h}-${e}`),t(h,m,f.children||null)},a=h=>{const{src:f,alt:m,title:v,srcset:R,sizes:T}=h.attrs||{};let E=f,I={};if(n){const{src:Fe,attrs:Ve}=Ae(f,n);E=Fe,I=Ve}o&&(I={...I,key:`img-${e}`});const Ge={src:E,alt:m,title:v,srcset:R,sizes:T,...I};return t("img",F(Ge))},c=h=>{const{level:f,...m}=h.attrs||{},v={...m};return o&&(v.key=`h${f}-${e}`),t(`h${f}`,v,h.children)},d=h=>{var f,m,v,R;const T=t("img",{src:(f=h.attrs)==null?void 0:f.fallbackImage,alt:(m=h.attrs)==null?void 0:m.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),E={"data-type":"emoji","data-name":(v=h.attrs)==null?void 0:v.name,"data-emoji":(R=h.attrs)==null?void 0:R.emoji};return o&&(E.key=`emoji-${e}`),t("span",E,T)},u=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),g=(h,f=!1)=>({text:m,attrs:v})=>{const{class:R,id:T,...E}=v||{},I=f?{class:R,id:T,style:Ne(E)||void 0}:v||{};return o&&(I.key=`${h}-${e}`),t(h,F(I),m)},w=h=>U(h),b=h=>{const{marks:f,...m}=h;return"text"in h?f?f.reduce((v,R)=>w({...R,text:v}),w({...m,children:m.children})):s(m.text):""},S=h=>{const{linktype:f,href:m,anchor:v,...R}=h.attrs||{};let T="";switch(f){case x.ASSET:case x.URL:T=m;break;case x.EMAIL:T=`mailto:${m}`;break;case x.STORY:T=m;break}return v&&(T=`${T}#${v}`),t("a",{...R,href:T,key:`a-${e}`},h.text)},C=h=>{var f,m;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(f=h==null?void 0:h.attrs)==null?void 0:f.body[0],id:(m=h.attrs)==null?void 0:m.id,key:`component-${e}`,style:"display: none"})},qe=new Map([[k.DOCUMENT,l("div")],[k.HEADING,c],[k.PARAGRAPH,l("p")],[k.UL_LIST,l("ul")],[k.OL_LIST,l("ol")],[k.LIST_ITEM,l("li")],[k.IMAGE,a],[k.EMOJI,d],[k.CODE_BLOCK,u],[k.HR,l("hr")],[k.BR,l("br")],[k.QUOTE,l("blockquote")],[k.COMPONENT,C],[N.TEXT,b],[$.LINK,S],[$.ANCHOR,S],[$.STYLED,g("span",!0)],[$.BOLD,g("strong")],[$.TEXT_STYLE,g("span",!0)],[$.ITALIC,g("em")],[$.UNDERLINE,g("u")],[$.STRIKE,g("s")],[$.CODE,g("code")],[$.SUPERSCRIPT,g("sup")],[$.SUBSCRIPT,g("sub")],[$.HIGHLIGHT,g("mark")],...Object.entries(r).map(([h,f])=>[h,f])]);function Y(h){e+=1;const f=qe.get(h.type);if(!f)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return f(h);const m=h.content?h.content.map(U):void 0;return f({...h,children:m})}function U(h){return Array.isArray(h)?h.map(Y):Y(h)}return{render:U}}let M,H="https://app.storyblok.com/f/storyblok-v2-latest.js";const V=(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"],c=>{c.action==="input"&&c.story.id===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload()})})}},ze=(i={})=>{var u,g;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(w=>{a={...a,...w(l)}}),o&&(H=o);const d=!(typeof window>"u")&&((g=(u=window.location)==null?void 0:u.search)==null?void 0:g.includes("_storyblok_tk"));return e!==!1&&d&&B(H),M=new O(n.schema),n.resolver&&J(M,n.resolver),a},J=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},K=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Be=(i,e,t)=>{let s=t||M;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return K(i)?"":(e&&(s=new O(e.schema),e.resolver&&J(s,e.resolver)),s.render(i,{},!1))},De=()=>B(H);y.BlockTypes=k,y.MarkTypes=$,y.RichTextResolver=O,y.RichTextSchema=D,y.TextTypes=N,y.apiPlugin=xe,y.isRichTextEmpty=K,y.loadStoryblokBridge=De,y.registerStoryblokBridge=V,y.renderRichText=Be,y.richTextResolver=Ue,y.storyblokEditable=Le,y.storyblokInit=ze,y.useStoryblokBridge=V,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let H = !1;
|
|
2
|
-
const U = [],
|
|
2
|
+
const U = [], q = (i) => new Promise((e, t) => {
|
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
4
4
|
if (window.location === window.parent.location) {
|
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
@@ -12,72 +12,76 @@ const U = [], G = (i) => new Promise((e, t) => {
|
|
|
12
12
|
U.forEach((n) => n()), H = !0, e(r);
|
|
13
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
14
14
|
});
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
var X = Object.defineProperty, W = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => W(i, typeof e != "symbol" ? e + "" : e, t);
|
|
16
|
+
class Q extends Error {
|
|
17
|
+
constructor(e) {
|
|
18
|
+
super(e), this.name = "AbortError";
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
function Z(i, e, t) {
|
|
20
|
-
if (!
|
|
22
|
+
if (!Number.isFinite(e))
|
|
21
23
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
22
|
-
if (!
|
|
24
|
+
if (!Number.isFinite(t))
|
|
23
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
24
26
|
const s = [];
|
|
25
|
-
let r = [], n = 0;
|
|
26
|
-
const
|
|
27
|
+
let r = [], n = 0, o = !1;
|
|
28
|
+
const l = async () => {
|
|
27
29
|
n++;
|
|
28
|
-
const a = setTimeout(function() {
|
|
29
|
-
n--, s.length > 0 && o(), r = r.filter(function(u) {
|
|
30
|
-
return u !== a;
|
|
31
|
-
});
|
|
32
|
-
}, t);
|
|
33
|
-
r.indexOf(a) < 0 && r.push(a);
|
|
34
30
|
const c = s.shift();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
if (c)
|
|
32
|
+
try {
|
|
33
|
+
const u = await i(...c.args);
|
|
34
|
+
c.resolve(u);
|
|
35
|
+
} catch (u) {
|
|
36
|
+
c.reject(u);
|
|
37
|
+
}
|
|
38
|
+
const d = setTimeout(() => {
|
|
39
|
+
n--, s.length > 0 && l(), r = r.filter((u) => u !== d);
|
|
40
|
+
}, t);
|
|
41
|
+
r.includes(d) || r.push(d);
|
|
42
|
+
}, a = (...c) => o ? Promise.reject(
|
|
43
|
+
new Error(
|
|
44
|
+
"Throttled function is already aborted and not accepting new promises"
|
|
45
|
+
)
|
|
46
|
+
) : new Promise((d, u) => {
|
|
47
|
+
s.push({
|
|
48
|
+
resolve: d,
|
|
49
|
+
reject: u,
|
|
50
|
+
args: c
|
|
51
|
+
}), n < e && l();
|
|
52
|
+
});
|
|
53
|
+
return a.abort = () => {
|
|
54
|
+
o = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
|
55
|
+
(c) => c.reject(() => new Q("Throttle function aborted"))
|
|
56
|
+
), s.length = 0;
|
|
57
|
+
}, a;
|
|
54
58
|
}
|
|
55
59
|
let O = class {
|
|
56
60
|
constructor() {
|
|
57
|
-
|
|
61
|
+
p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
|
58
62
|
...e,
|
|
59
63
|
per_page: t,
|
|
60
64
|
page: s
|
|
61
|
-
})),
|
|
65
|
+
})), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), p(this, "range", (e = 0, t = e) => {
|
|
62
66
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
63
67
|
return this.arrayFrom(s, (n, o) => o * r + e);
|
|
64
|
-
}),
|
|
68
|
+
}), 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
69
|
const t = {
|
|
66
70
|
"&": "&",
|
|
67
71
|
"<": "<",
|
|
68
72
|
">": ">",
|
|
69
73
|
'"': """,
|
|
70
74
|
"'": "'"
|
|
71
|
-
}, s = /[&<>"']/g, r = RegExp(s.source);
|
|
75
|
+
}, s = /[&<>"']/g, r = new RegExp(s.source);
|
|
72
76
|
return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* @method stringify
|
|
77
|
-
* @param {
|
|
78
|
-
* @param {
|
|
79
|
-
* @param {
|
|
80
|
-
* @return {
|
|
81
|
+
* @param {object} params
|
|
82
|
+
* @param {string} prefix
|
|
83
|
+
* @param {boolean} isArray
|
|
84
|
+
* @return {string} Stringified object
|
|
81
85
|
*/
|
|
82
86
|
stringify(e, t, s) {
|
|
83
87
|
const r = [];
|
|
@@ -88,16 +92,16 @@ let O = class {
|
|
|
88
92
|
let a;
|
|
89
93
|
typeof o == "object" ? a = this.stringify(
|
|
90
94
|
o,
|
|
91
|
-
t ? t + encodeURIComponent(
|
|
95
|
+
t ? t + encodeURIComponent(`[${l}]`) : l,
|
|
92
96
|
Array.isArray(o)
|
|
93
|
-
) : a =
|
|
97
|
+
) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
|
|
94
98
|
}
|
|
95
99
|
return r.join("&");
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
98
102
|
* @method getRegionURL
|
|
99
|
-
* @param {
|
|
100
|
-
* @return {
|
|
103
|
+
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
104
|
+
* @return {string} The base URL of the region
|
|
101
105
|
*/
|
|
102
106
|
getRegionURL(e) {
|
|
103
107
|
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
|
@@ -119,7 +123,7 @@ const ee = function(i, e) {
|
|
|
119
123
|
const t = {};
|
|
120
124
|
for (const s in i) {
|
|
121
125
|
const r = i[s];
|
|
122
|
-
e.
|
|
126
|
+
e.includes(s) && r !== null && (t[s] = r);
|
|
123
127
|
}
|
|
124
128
|
return t;
|
|
125
129
|
}, te = (i) => i === "email", se = () => ({
|
|
@@ -206,14 +210,14 @@ const ee = function(i, e) {
|
|
|
206
210
|
tag: "sub"
|
|
207
211
|
}), Te = () => ({
|
|
208
212
|
tag: "sup"
|
|
209
|
-
}),
|
|
213
|
+
}), we = (i) => ({
|
|
210
214
|
tag: [
|
|
211
215
|
{
|
|
212
216
|
tag: "span",
|
|
213
217
|
attrs: i.attrs
|
|
214
218
|
}
|
|
215
219
|
]
|
|
216
|
-
}),
|
|
220
|
+
}), Re = (i) => {
|
|
217
221
|
var e;
|
|
218
222
|
return (e = i.attrs) != null && e.color ? {
|
|
219
223
|
tag: [
|
|
@@ -266,8 +270,8 @@ const ee = function(i, e) {
|
|
|
266
270
|
styled: ve,
|
|
267
271
|
subscript: $e,
|
|
268
272
|
superscript: Te,
|
|
269
|
-
anchor:
|
|
270
|
-
highlight:
|
|
273
|
+
anchor: we,
|
|
274
|
+
highlight: Re,
|
|
271
275
|
textStyle: Se
|
|
272
276
|
}
|
|
273
277
|
}, Ee = function(i) {
|
|
@@ -277,13 +281,13 @@ const ee = function(i, e) {
|
|
|
277
281
|
">": ">",
|
|
278
282
|
'"': """,
|
|
279
283
|
"'": "'"
|
|
280
|
-
}, t = /[&<>"']/g, s = RegExp(t.source);
|
|
284
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
281
285
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
|
282
286
|
};
|
|
283
|
-
let
|
|
287
|
+
let z = !1;
|
|
284
288
|
class Ie {
|
|
285
289
|
constructor(e) {
|
|
286
|
-
|
|
290
|
+
p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
287
291
|
}
|
|
288
292
|
addNode(e, t) {
|
|
289
293
|
this.nodes[e] = t;
|
|
@@ -292,9 +296,9 @@ class Ie {
|
|
|
292
296
|
this.marks[e] = t;
|
|
293
297
|
}
|
|
294
298
|
render(e, t = { optimizeImages: !1 }, s = !0) {
|
|
295
|
-
if (!
|
|
299
|
+
if (!z && s && (console.warn(
|
|
296
300
|
"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/"
|
|
297
|
-
),
|
|
301
|
+
), z = !0), e && e.content && Array.isArray(e.content)) {
|
|
298
302
|
let r = "";
|
|
299
303
|
return e.content.forEach((n) => {
|
|
300
304
|
r += this.renderNode(n);
|
|
@@ -302,57 +306,58 @@ class Ie {
|
|
|
302
306
|
}
|
|
303
307
|
return console.warn(
|
|
304
308
|
`The render method must receive an Object with a "content" field.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
310
|
+
ISbRichtext:
|
|
311
|
+
content?: ISbRichtext[]
|
|
312
|
+
marks?: ISbRichtext[]
|
|
313
|
+
attrs?: any
|
|
314
|
+
text?: string
|
|
315
|
+
type: string
|
|
316
|
+
|
|
317
|
+
Example:
|
|
318
|
+
{
|
|
319
|
+
content: [
|
|
320
|
+
{
|
|
321
|
+
content: [
|
|
322
|
+
{
|
|
323
|
+
text: 'Hello World',
|
|
324
|
+
type: 'text'
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
type: 'paragraph'
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
type: 'doc'
|
|
331
|
+
}`
|
|
328
332
|
), "";
|
|
329
333
|
}
|
|
330
334
|
optimizeImages(e, t) {
|
|
331
335
|
let s = 0, r = 0, n = "", o = "";
|
|
332
|
-
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-
|
|
336
|
+
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()}`));
|
|
333
337
|
const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
|
334
338
|
return e = e.replace(
|
|
335
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
|
339
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
336
340
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
337
341
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
338
|
-
var c,
|
|
339
|
-
const
|
|
340
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
|
342
|
+
var c, d;
|
|
343
|
+
const u = a.match(
|
|
344
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
341
345
|
);
|
|
342
|
-
if (
|
|
346
|
+
if (u && u.length > 0) {
|
|
343
347
|
const g = {
|
|
344
348
|
srcset: (c = t.srcset) == null ? void 0 : c.map((y) => {
|
|
345
349
|
if (typeof y == "number")
|
|
346
|
-
return `//${
|
|
350
|
+
return `//${u}/m/${y}x0${o} ${y}w`;
|
|
347
351
|
if (typeof y == "object" && y.length === 2) {
|
|
348
|
-
let
|
|
349
|
-
return typeof y[0] == "number" && (
|
|
352
|
+
let R = 0, j = 0;
|
|
353
|
+
return typeof y[0] == "number" && (R = y[0]), typeof y[1] == "number" && (j = y[1]), `//${u}/m/${R}x${j}${o} ${R}w`;
|
|
350
354
|
}
|
|
355
|
+
return "";
|
|
351
356
|
}).join(", "),
|
|
352
|
-
sizes: (
|
|
357
|
+
sizes: (d = t.sizes) == null ? void 0 : d.map((y) => y).join(", ")
|
|
353
358
|
};
|
|
354
|
-
let
|
|
355
|
-
return g.srcset && (
|
|
359
|
+
let T = "";
|
|
360
|
+
return g.srcset && (T += `srcset="${g.srcset}" `), g.sizes && (T += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${T.trim()}`);
|
|
356
361
|
}
|
|
357
362
|
return a;
|
|
358
363
|
})), e;
|
|
@@ -424,7 +429,7 @@ class Ie {
|
|
|
424
429
|
const L = Ie;
|
|
425
430
|
class je {
|
|
426
431
|
constructor(e) {
|
|
427
|
-
|
|
432
|
+
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 = {};
|
|
428
433
|
}
|
|
429
434
|
/**
|
|
430
435
|
*
|
|
@@ -509,7 +514,7 @@ class je {
|
|
|
509
514
|
});
|
|
510
515
|
}
|
|
511
516
|
}
|
|
512
|
-
const xe = je,
|
|
517
|
+
const xe = je, B = "SB-Agent", C = {
|
|
513
518
|
defaultAgentName: "SB-JS-CLIENT",
|
|
514
519
|
defaultAgentVersion: "SB-Agent-Version",
|
|
515
520
|
packageVersion: "6.0.0"
|
|
@@ -520,10 +525,10 @@ class Oe {
|
|
|
520
525
|
/**
|
|
521
526
|
*
|
|
522
527
|
* @param config ISbConfig interface
|
|
523
|
-
* @param
|
|
528
|
+
* @param pEndpoint string, optional
|
|
524
529
|
*/
|
|
525
530
|
constructor(e, t) {
|
|
526
|
-
|
|
531
|
+
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");
|
|
527
532
|
let s = e.endpoint || t;
|
|
528
533
|
if (!s) {
|
|
529
534
|
const o = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
|
|
@@ -532,12 +537,16 @@ class Oe {
|
|
|
532
537
|
const r = new Headers();
|
|
533
538
|
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]) => {
|
|
534
539
|
r.set(o, l);
|
|
535
|
-
}), r.has(
|
|
540
|
+
}), r.has(B) || (r.set(B, C.defaultAgentName), r.set(
|
|
536
541
|
C.defaultAgentVersion,
|
|
537
542
|
C.packageVersion
|
|
538
543
|
));
|
|
539
544
|
let n = 5;
|
|
540
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Z(
|
|
545
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Z(
|
|
546
|
+
this.throttledRequest.bind(this),
|
|
547
|
+
n,
|
|
548
|
+
1e3
|
|
549
|
+
), 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 xe({
|
|
541
550
|
baseURL: s,
|
|
542
551
|
timeout: e.timeout || 0,
|
|
543
552
|
headers: r,
|
|
@@ -574,32 +583,35 @@ class Oe {
|
|
|
574
583
|
return this.cacheResponse(r, n, void 0, s);
|
|
575
584
|
}
|
|
576
585
|
async getAll(e, t, s, r) {
|
|
577
|
-
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}
|
|
586
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`.replace(/\/$/, ""), l = s ?? o.substring(o.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
|
|
578
587
|
o,
|
|
579
588
|
t,
|
|
580
589
|
n,
|
|
581
|
-
|
|
590
|
+
a,
|
|
582
591
|
r
|
|
583
|
-
),
|
|
584
|
-
this.helpers.range(
|
|
585
|
-
(
|
|
586
|
-
);
|
|
587
|
-
return this.helpers.flatMap(
|
|
588
|
-
[u, ...g],
|
|
589
|
-
(k) => Object.values(k.data[a])
|
|
592
|
+
), d = c.total ? Math.ceil(c.total / n) : 1, u = await this.helpers.asyncMap(
|
|
593
|
+
this.helpers.range(a, d),
|
|
594
|
+
(g) => this.makeRequest(o, t, n, g + 1, r)
|
|
590
595
|
);
|
|
596
|
+
return this.helpers.flatMap([c, ...u], (g) => Object.values(g.data[l]));
|
|
591
597
|
}
|
|
592
598
|
post(e, t, s) {
|
|
593
599
|
const r = `/${e}`;
|
|
594
|
-
return Promise.resolve(
|
|
600
|
+
return Promise.resolve(
|
|
601
|
+
this.throttle("post", r, t, s)
|
|
602
|
+
);
|
|
595
603
|
}
|
|
596
604
|
put(e, t, s) {
|
|
597
605
|
const r = `/${e}`;
|
|
598
|
-
return Promise.resolve(
|
|
606
|
+
return Promise.resolve(
|
|
607
|
+
this.throttle("put", r, t, s)
|
|
608
|
+
);
|
|
599
609
|
}
|
|
600
610
|
delete(e, t, s) {
|
|
601
611
|
const r = `/${e}`;
|
|
602
|
-
return Promise.resolve(
|
|
612
|
+
return Promise.resolve(
|
|
613
|
+
this.throttle("delete", r, t, s)
|
|
614
|
+
);
|
|
603
615
|
}
|
|
604
616
|
getStories(e, t) {
|
|
605
617
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
@@ -621,7 +633,7 @@ class Oe {
|
|
|
621
633
|
}
|
|
622
634
|
_insertLinks(e, t, s) {
|
|
623
635
|
const r = e[t];
|
|
624
|
-
r && r.fieldtype
|
|
636
|
+
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]));
|
|
625
637
|
}
|
|
626
638
|
/**
|
|
627
639
|
*
|
|
@@ -635,7 +647,7 @@ class Oe {
|
|
|
635
647
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
636
648
|
}
|
|
637
649
|
_insertRelations(e, t, s, r) {
|
|
638
|
-
s.
|
|
650
|
+
s.includes(`${e.component}.${t}`) && (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)));
|
|
639
651
|
}
|
|
640
652
|
iterateTree(e, t, s) {
|
|
641
653
|
const r = (n) => {
|
|
@@ -729,7 +741,7 @@ class Oe {
|
|
|
729
741
|
async resolveStories(e, t, s) {
|
|
730
742
|
var r, n;
|
|
731
743
|
let o = [];
|
|
732
|
-
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"].
|
|
744
|
+
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)
|
|
733
745
|
for (const l in this.relations[s])
|
|
734
746
|
this.iterateTree(
|
|
735
747
|
this.relations[s][l],
|
|
@@ -742,7 +754,7 @@ class Oe {
|
|
|
742
754
|
}
|
|
743
755
|
async cacheResponse(e, t, s, r) {
|
|
744
756
|
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
|
745
|
-
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e
|
|
757
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
|
|
746
758
|
const l = await o.get(n);
|
|
747
759
|
if (l)
|
|
748
760
|
return Promise.resolve(l);
|
|
@@ -750,24 +762,29 @@ class Oe {
|
|
|
750
762
|
return new Promise(async (l, a) => {
|
|
751
763
|
var c;
|
|
752
764
|
try {
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
765
|
+
const d = await this.throttle(
|
|
766
|
+
"get",
|
|
767
|
+
e,
|
|
768
|
+
t,
|
|
769
|
+
r
|
|
770
|
+
);
|
|
771
|
+
if (d.status !== 200)
|
|
772
|
+
return a(d);
|
|
773
|
+
let u = { data: d.data, headers: d.headers };
|
|
774
|
+
if ((c = d.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
|
|
775
|
+
perPage: d.headers["per-page"] ? Number.parseInt(d.headers["per-page"]) : 0,
|
|
776
|
+
total: d.headers["per-page"] ? Number.parseInt(d.headers.total) : 0
|
|
777
|
+
})), u.data.story || u.data.stories) {
|
|
761
778
|
const g = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
762
|
-
await this.resolveStories(
|
|
779
|
+
await this.resolveStories(u.data, t, `${g}`);
|
|
763
780
|
}
|
|
764
|
-
return t.version === "published" && e
|
|
765
|
-
} catch (
|
|
766
|
-
if (
|
|
781
|
+
return t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, u), u.data.cv && t.token && E[t.token] !== u.data.cv && (await this.flushCache(), E[t.token] = u.data.cv), l(u);
|
|
782
|
+
} catch (d) {
|
|
783
|
+
if (d.response && d.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
767
784
|
return console.log(
|
|
768
785
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
|
769
786
|
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
|
770
|
-
a(
|
|
787
|
+
a(d);
|
|
771
788
|
}
|
|
772
789
|
});
|
|
773
790
|
}
|
|
@@ -804,7 +821,8 @@ class Oe {
|
|
|
804
821
|
}
|
|
805
822
|
};
|
|
806
823
|
case "custom":
|
|
807
|
-
if (this.cache.custom)
|
|
824
|
+
if (this.cache.custom)
|
|
825
|
+
return this.cache.custom;
|
|
808
826
|
default:
|
|
809
827
|
return {
|
|
810
828
|
get() {
|
|
@@ -855,20 +873,20 @@ function Le(i, e) {
|
|
|
855
873
|
return { src: i, attrs: {} };
|
|
856
874
|
let t = 0, s = 0;
|
|
857
875
|
const r = {}, n = [];
|
|
858
|
-
function o(a, c,
|
|
859
|
-
typeof a != "number" || a <= c || a >=
|
|
876
|
+
function o(a, c, d, u, g) {
|
|
877
|
+
typeof a != "number" || a <= c || a >= d ? console.warn(`[StoryblokRichText] - ${u.charAt(0).toUpperCase() + u.slice(1)} value must be a number between ${c} and ${d} (inclusive)`) : g.push(`${u}(${a})`);
|
|
860
878
|
}
|
|
861
879
|
if (typeof e == "object") {
|
|
862
880
|
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) {
|
|
863
|
-
const { filters: a } = e || {}, { blur: c, brightness:
|
|
864
|
-
c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n),
|
|
881
|
+
const { filters: a } = e || {}, { blur: c, brightness: d, fill: u, format: g, grayscale: T, quality: y, rotate: R } = a || {};
|
|
882
|
+
c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), d && o(d, 0, 100, "brightness", n), u && n.push(`fill(${u})`), T && n.push("grayscale()"), R && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${R})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
|
|
865
883
|
}
|
|
866
884
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
|
867
885
|
if (typeof a == "number")
|
|
868
886
|
return `${i}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
|
|
869
887
|
if (Array.isArray(a) && a.length === 2) {
|
|
870
|
-
const [c,
|
|
871
|
-
return `${i}/m/${c}x${
|
|
888
|
+
const [c, d] = a;
|
|
889
|
+
return `${i}/m/${c}x${d}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
|
|
872
890
|
} else {
|
|
873
891
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
874
892
|
return;
|
|
@@ -881,7 +899,7 @@ function Le(i, e) {
|
|
|
881
899
|
attrs: r
|
|
882
900
|
};
|
|
883
901
|
}
|
|
884
|
-
var
|
|
902
|
+
var k = /* @__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))(k || {}), 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 || {}), 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 || {});
|
|
885
903
|
const Ae = [
|
|
886
904
|
"area",
|
|
887
905
|
"base",
|
|
@@ -901,7 +919,7 @@ const Ae = [
|
|
|
901
919
|
function Ne(i) {
|
|
902
920
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
903
921
|
}
|
|
904
|
-
const
|
|
922
|
+
const D = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
|
|
905
923
|
function Me(i, e = {}, t) {
|
|
906
924
|
const s = Ce(e), r = s ? `${i} ${s}` : i;
|
|
907
925
|
return Ae.includes(i) ? `<${r}>` : `<${r}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
|
|
@@ -918,33 +936,33 @@ function De(i = {}) {
|
|
|
918
936
|
const m = f.attrs || {};
|
|
919
937
|
return o && (m.key = `${h}-${e}`), t(h, m, f.children || null);
|
|
920
938
|
}, a = (h) => {
|
|
921
|
-
const { src: f, alt: m, title: b, srcset:
|
|
939
|
+
const { src: f, alt: m, title: b, srcset: w, sizes: $ } = h.attrs || {};
|
|
922
940
|
let S = f, _ = {};
|
|
923
941
|
if (n) {
|
|
924
|
-
const { src:
|
|
925
|
-
S =
|
|
942
|
+
const { src: K, attrs: Y } = Le(f, n);
|
|
943
|
+
S = K, _ = Y;
|
|
926
944
|
}
|
|
927
945
|
o && (_ = {
|
|
928
946
|
..._,
|
|
929
947
|
key: `img-${e}`
|
|
930
948
|
});
|
|
931
|
-
const
|
|
949
|
+
const J = {
|
|
932
950
|
src: S,
|
|
933
951
|
alt: m,
|
|
934
952
|
title: b,
|
|
935
|
-
srcset:
|
|
936
|
-
sizes:
|
|
953
|
+
srcset: w,
|
|
954
|
+
sizes: $,
|
|
937
955
|
..._
|
|
938
956
|
};
|
|
939
|
-
return t("img",
|
|
957
|
+
return t("img", D(J));
|
|
940
958
|
}, c = (h) => {
|
|
941
959
|
const { level: f, ...m } = h.attrs || {}, b = {
|
|
942
960
|
...m
|
|
943
961
|
};
|
|
944
962
|
return o && (b.key = `h${f}-${e}`), t(`h${f}`, b, h.children);
|
|
945
|
-
},
|
|
946
|
-
var f, m, b,
|
|
947
|
-
const
|
|
963
|
+
}, d = (h) => {
|
|
964
|
+
var f, m, b, w;
|
|
965
|
+
const $ = t("img", {
|
|
948
966
|
src: (f = h.attrs) == null ? void 0 : f.fallbackImage,
|
|
949
967
|
alt: (m = h.attrs) == null ? void 0 : m.alt,
|
|
950
968
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
@@ -953,43 +971,43 @@ function De(i = {}) {
|
|
|
953
971
|
}), S = {
|
|
954
972
|
"data-type": "emoji",
|
|
955
973
|
"data-name": (b = h.attrs) == null ? void 0 : b.name,
|
|
956
|
-
"data-emoji": (
|
|
974
|
+
"data-emoji": (w = h.attrs) == null ? void 0 : w.emoji
|
|
957
975
|
};
|
|
958
|
-
return o && (S.key = `emoji-${e}`), t("span", S,
|
|
959
|
-
},
|
|
976
|
+
return o && (S.key = `emoji-${e}`), t("span", S, $);
|
|
977
|
+
}, u = (h) => t("pre", {
|
|
960
978
|
...h.attrs,
|
|
961
979
|
key: `code-${e}`
|
|
962
980
|
}, t("code", { key: `code-${e}` }, h.children || "")), g = (h, f = !1) => ({ text: m, attrs: b }) => {
|
|
963
|
-
const { class:
|
|
964
|
-
class:
|
|
965
|
-
id:
|
|
981
|
+
const { class: w, id: $, ...S } = b || {}, _ = f ? {
|
|
982
|
+
class: w,
|
|
983
|
+
id: $,
|
|
966
984
|
style: Pe(S) || void 0
|
|
967
985
|
} : b || {};
|
|
968
|
-
return o && (_.key = `${h}-${e}`), t(h,
|
|
969
|
-
},
|
|
986
|
+
return o && (_.key = `${h}-${e}`), t(h, D(_), m);
|
|
987
|
+
}, T = (h) => A(h), y = (h) => {
|
|
970
988
|
const { marks: f, ...m } = h;
|
|
971
989
|
return "text" in h ? f ? f.reduce(
|
|
972
|
-
(b,
|
|
990
|
+
(b, w) => T({ ...w, text: b }),
|
|
973
991
|
// Fix: Ensure render function returns a string
|
|
974
|
-
|
|
992
|
+
T({ ...m, children: m.children })
|
|
975
993
|
// Fix: Cast children to string
|
|
976
994
|
) : s(m.text) : "";
|
|
977
|
-
},
|
|
978
|
-
const { linktype: f, href: m, anchor: b, ...
|
|
979
|
-
let
|
|
995
|
+
}, R = (h) => {
|
|
996
|
+
const { linktype: f, href: m, anchor: b, ...w } = h.attrs || {};
|
|
997
|
+
let $ = "";
|
|
980
998
|
switch (f) {
|
|
981
999
|
case I.ASSET:
|
|
982
1000
|
case I.URL:
|
|
983
|
-
|
|
1001
|
+
$ = m;
|
|
984
1002
|
break;
|
|
985
1003
|
case I.EMAIL:
|
|
986
|
-
|
|
1004
|
+
$ = `mailto:${m}`;
|
|
987
1005
|
break;
|
|
988
1006
|
case I.STORY:
|
|
989
|
-
|
|
1007
|
+
$ = m;
|
|
990
1008
|
break;
|
|
991
1009
|
}
|
|
992
|
-
return b && (
|
|
1010
|
+
return b && ($ = `${$}#${b}`), t("a", { ...w, href: $, key: `a-${e}` }, h.text);
|
|
993
1011
|
}, j = (h) => {
|
|
994
1012
|
var f, m;
|
|
995
1013
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
|
@@ -998,38 +1016,38 @@ function De(i = {}) {
|
|
|
998
1016
|
key: `component-${e}`,
|
|
999
1017
|
style: "display: none"
|
|
1000
1018
|
});
|
|
1001
|
-
},
|
|
1002
|
-
[
|
|
1003
|
-
[
|
|
1004
|
-
[
|
|
1005
|
-
[
|
|
1006
|
-
[
|
|
1007
|
-
[
|
|
1008
|
-
[
|
|
1009
|
-
[
|
|
1010
|
-
[
|
|
1011
|
-
[
|
|
1012
|
-
[
|
|
1013
|
-
[
|
|
1014
|
-
[
|
|
1015
|
-
[
|
|
1016
|
-
[
|
|
1017
|
-
[
|
|
1018
|
-
[
|
|
1019
|
-
[
|
|
1020
|
-
[
|
|
1021
|
-
[
|
|
1022
|
-
[
|
|
1023
|
-
[
|
|
1024
|
-
[
|
|
1025
|
-
[
|
|
1026
|
-
[
|
|
1027
|
-
[
|
|
1019
|
+
}, V = new Map([
|
|
1020
|
+
[k.DOCUMENT, l("div")],
|
|
1021
|
+
[k.HEADING, c],
|
|
1022
|
+
[k.PARAGRAPH, l("p")],
|
|
1023
|
+
[k.UL_LIST, l("ul")],
|
|
1024
|
+
[k.OL_LIST, l("ol")],
|
|
1025
|
+
[k.LIST_ITEM, l("li")],
|
|
1026
|
+
[k.IMAGE, a],
|
|
1027
|
+
[k.EMOJI, d],
|
|
1028
|
+
[k.CODE_BLOCK, u],
|
|
1029
|
+
[k.HR, l("hr")],
|
|
1030
|
+
[k.BR, l("br")],
|
|
1031
|
+
[k.QUOTE, l("blockquote")],
|
|
1032
|
+
[k.COMPONENT, j],
|
|
1033
|
+
[G.TEXT, y],
|
|
1034
|
+
[v.LINK, R],
|
|
1035
|
+
[v.ANCHOR, R],
|
|
1036
|
+
[v.STYLED, g("span", !0)],
|
|
1037
|
+
[v.BOLD, g("strong")],
|
|
1038
|
+
[v.TEXT_STYLE, g("span", !0)],
|
|
1039
|
+
[v.ITALIC, g("em")],
|
|
1040
|
+
[v.UNDERLINE, g("u")],
|
|
1041
|
+
[v.STRIKE, g("s")],
|
|
1042
|
+
[v.CODE, g("code")],
|
|
1043
|
+
[v.SUPERSCRIPT, g("sup")],
|
|
1044
|
+
[v.SUBSCRIPT, g("sub")],
|
|
1045
|
+
[v.HIGHLIGHT, g("mark")],
|
|
1028
1046
|
...Object.entries(r).map(([h, f]) => [h, f])
|
|
1029
1047
|
]);
|
|
1030
1048
|
function M(h) {
|
|
1031
1049
|
e += 1;
|
|
1032
|
-
const f =
|
|
1050
|
+
const f = V.get(h.type);
|
|
1033
1051
|
if (!f)
|
|
1034
1052
|
return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
|
|
1035
1053
|
if (h.type === "text")
|
|
@@ -1066,7 +1084,7 @@ const qe = (i, e, t = {}) => {
|
|
|
1066
1084
|
});
|
|
1067
1085
|
}
|
|
1068
1086
|
}, Ge = (i = {}) => {
|
|
1069
|
-
var
|
|
1087
|
+
var u, g;
|
|
1070
1088
|
const {
|
|
1071
1089
|
bridge: e,
|
|
1072
1090
|
accessToken: t,
|
|
@@ -1078,12 +1096,12 @@ const qe = (i, e, t = {}) => {
|
|
|
1078
1096
|
r.accessToken = r.accessToken || t;
|
|
1079
1097
|
const l = { bridge: e, apiOptions: r };
|
|
1080
1098
|
let a = {};
|
|
1081
|
-
s.forEach((
|
|
1082
|
-
a = { ...a, ...
|
|
1099
|
+
s.forEach((T) => {
|
|
1100
|
+
a = { ...a, ...T(l) };
|
|
1083
1101
|
}), o && (N = o);
|
|
1084
|
-
const
|
|
1085
|
-
return e !== !1 &&
|
|
1086
|
-
},
|
|
1102
|
+
const d = !(typeof window > "u") && ((g = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : g.includes("_storyblok_tk"));
|
|
1103
|
+
return e !== !1 && d && q(N), P = new L(n.schema), n.resolver && F(P, n.resolver), a;
|
|
1104
|
+
}, F = (i, e) => {
|
|
1087
1105
|
i.addNode("blok", (t) => {
|
|
1088
1106
|
let s = "";
|
|
1089
1107
|
return t.attrs.body.forEach((r) => {
|
|
@@ -1092,7 +1110,7 @@ const qe = (i, e, t = {}) => {
|
|
|
1092
1110
|
html: s
|
|
1093
1111
|
};
|
|
1094
1112
|
});
|
|
1095
|
-
}, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")),
|
|
1113
|
+
}, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Fe = (i, e, t) => {
|
|
1096
1114
|
let s = t || P;
|
|
1097
1115
|
if (!s) {
|
|
1098
1116
|
console.error(
|
|
@@ -1100,19 +1118,19 @@ const qe = (i, e, t = {}) => {
|
|
|
1100
1118
|
);
|
|
1101
1119
|
return;
|
|
1102
1120
|
}
|
|
1103
|
-
return He(i) ? "" : (e && (s = new L(e.schema), e.resolver &&
|
|
1104
|
-
},
|
|
1121
|
+
return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && F(s, e.resolver)), s.render(i, {}, !1));
|
|
1122
|
+
}, Ve = () => q(N);
|
|
1105
1123
|
export {
|
|
1106
|
-
|
|
1107
|
-
|
|
1124
|
+
k as BlockTypes,
|
|
1125
|
+
v as MarkTypes,
|
|
1108
1126
|
L as RichTextResolver,
|
|
1109
1127
|
_e as RichTextSchema,
|
|
1110
|
-
|
|
1128
|
+
G as TextTypes,
|
|
1111
1129
|
ze as apiPlugin,
|
|
1112
1130
|
He as isRichTextEmpty,
|
|
1113
|
-
|
|
1131
|
+
Ve as loadStoryblokBridge,
|
|
1114
1132
|
qe as registerStoryblokBridge,
|
|
1115
|
-
|
|
1133
|
+
Fe as renderRichText,
|
|
1116
1134
|
De as richTextResolver,
|
|
1117
1135
|
Be as storyblokEditable,
|
|
1118
1136
|
Ge as storyblokInit,
|
package/dist/types/types.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface StoryblokBridgeV2 {
|
|
|
53
53
|
export type { ISbConfig, // previously StoryblokConfig
|
|
54
54
|
ISbCache, // previously StoryblokCache
|
|
55
55
|
ISbResult, // previously StoryblokResult
|
|
56
|
-
ISbResponse, ISbError, ISbNode, ISbSchema,
|
|
56
|
+
ISbResponse, ISbError, ISbNode, ISbSchema, ISbThrottle, ISbThrottledRequest, AsyncFn, ArrayFn, ISbContentMangmntAPI, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
|
|
57
57
|
ISbStories, // previously Stories
|
|
58
58
|
ISbStory, // previously Story
|
|
59
59
|
ISbDimensions, ISbComponentType as StoryblokComponentType, ISbStoryData, // previously StoryData
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/js",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.9",
|
|
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",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@storyblok/richtext": "^3.0.0",
|
|
32
|
-
"storyblok-js-client": "^6.10.
|
|
32
|
+
"storyblok-js-client": "^6.10.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tsconfig/recommended": "^1.0.
|
|
36
|
-
"cypress": "^13.
|
|
37
|
-
"eslint-plugin-cypress": "^2.15.
|
|
38
|
-
"eslint-plugin-jest": "^28.
|
|
35
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
36
|
+
"cypress": "^13.16.0",
|
|
37
|
+
"eslint-plugin-cypress": "^2.15.2",
|
|
38
|
+
"eslint-plugin-jest": "^28.9.0",
|
|
39
39
|
"isomorphic-fetch": "^3.0.0",
|
|
40
40
|
"start-server-and-test": "^2.0.8",
|
|
41
|
-
"vite": "^5.4.
|
|
42
|
-
"vitest": "^2.1.
|
|
41
|
+
"vite": "^5.4.11",
|
|
42
|
+
"vitest": "^2.1.5"
|
|
43
43
|
},
|
|
44
44
|
"babel": {
|
|
45
45
|
"presets": [
|