@storyblok/react 3.0.13 → 3.0.14
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/index.mjs +4 -4
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +146 -146
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { registerStoryblokBridge as k } from "./storyblok-js.mjs";
|
|
|
3
3
|
import { RichTextResolver as v, RichTextSchema as x, apiPlugin as R, loadStoryblokBridge as C, renderRichText as w, storyblokEditable as B } from "./storyblok-js.mjs";
|
|
4
4
|
import { useStoryblokApi as c } from "./index2.mjs";
|
|
5
5
|
import { getComponent as h, getCustomFallbackComponent as A, getEnableFallbackComponent as T, setComponents as F, storyblokInit as I } from "./index2.mjs";
|
|
6
|
-
import { useStoryblokState as
|
|
7
|
-
import { default as
|
|
6
|
+
import { useStoryblokState as N } from "./client.mjs";
|
|
7
|
+
import { default as _ } from "./storyblok-component.mjs";
|
|
8
8
|
const b = (s, e = {}, o = {}) => {
|
|
9
9
|
let [l, n] = f({});
|
|
10
10
|
const i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u", t = c();
|
|
@@ -32,7 +32,7 @@ const b = (s, e = {}, o = {}) => {
|
|
|
32
32
|
export {
|
|
33
33
|
v as RichTextResolver,
|
|
34
34
|
x as RichTextSchema,
|
|
35
|
-
|
|
35
|
+
_ as StoryblokComponent,
|
|
36
36
|
R as apiPlugin,
|
|
37
37
|
h as getComponent,
|
|
38
38
|
A as getCustomFallbackComponent,
|
|
@@ -47,5 +47,5 @@ export {
|
|
|
47
47
|
b as useStoryblok,
|
|
48
48
|
c as useStoryblokApi,
|
|
49
49
|
k as useStoryblokBridge,
|
|
50
|
-
|
|
50
|
+
N as useStoryblokState
|
|
51
51
|
};
|
package/dist/storyblok-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let _=!1;const j=[],O=n=>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}_?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let _=!1;const j=[],O=n=>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}_?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(o=>o()),_=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var A=Object.defineProperty,N=(n,e,t)=>e in n?A(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,c=(n,e,t)=>N(n,typeof e!="symbol"?e+"":e,t);function x(n){return!(n!==n||n===1/0||n===-1/0)}function L(n,e,t){if(!x(e))throw new TypeError("Expected `limit` to be a finite number");if(!x(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const i=function(){o++;const a=setTimeout(function(){o--,s.length>0&&i(),r=r.filter(function(h){return h!==a})},t);r.indexOf(a)<0&&r.push(a);const u=s.shift();u.resolve(n.apply(u.self,u.args))},l=function(...a){const u=this;return new Promise(function(h,d){s.push({resolve:h,reject:d,args:a,self:u}),o<e&&i()})};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 v{constructor(){c(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),c(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),c(this,"delay",e=>new Promise(t=>setTimeout(t,e))),c(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),c(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,i)=>i*r+e)}),c(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),c(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),c(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,o=>t[o]):e})}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],l=s?"":encodeURIComponent(o);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(i)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",o="api-ap.storyblok.com",i="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return o;case"ca":return i;default:return t}}}const M=function(n,e){const t={};for(const s in n){const r=n[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},H=n=>n==="email",U=()=>({singleTag:"hr"}),z=()=>({tag:"blockquote"}),q=()=>({tag:"ul"}),B=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),D=()=>({singleTag:"br"}),V=n=>({tag:`h${n.attrs.level}`}),J=n=>({singleTag:[{tag:"img",attrs:M(n.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),W=()=>({tag:"ol"}),Y=()=>({tag:"p"}),K=n=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":n.attrs.name,emoji:n.attrs.emoji}}]}),Q=()=>({tag:"b"}),X=()=>({tag:"s"}),Z=()=>({tag:"u"}),G=()=>({tag:"strong"}),ee=()=>({tag:"code"}),te=()=>({tag:"i"}),se=n=>{if(!n.attrs)return{tag:""};const e=new v().escapeHTML,t={...n.attrs},{linktype:s="url"}=n.attrs;if(delete t.linktype,t.href&&(t.href=e(n.attrs.href||"")),H(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}]}},re=n=>({tag:[{tag:"span",attrs:n.attrs}]}),oe=()=>({tag:"sub"}),ie=()=>({tag:"sup"}),ne=n=>({tag:[{tag:"span",attrs:n.attrs}]}),ae=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${n.attrs.color};`}}]}:{tag:""}},le=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${n.attrs.color}`}}]}:{tag:""}},P={nodes:{horizontal_rule:U,blockquote:z,bullet_list:q,code_block:B,hard_break:D,heading:V,image:J,list_item:F,ordered_list:W,paragraph:Y,emoji:K},marks:{bold:Q,strike:X,underline:Z,strong:G,code:ee,italic:te,link:se,styled:re,subscript:oe,superscript:ie,anchor:ne,highlight:ae,textStyle:le}},ce=function(n){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return n&&s.test(n)?n.replace(t,r=>e[r]):n};class he{constructor(e){c(this,"marks"),c(this,"nodes"),e||(e=P),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,i="",o="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(i+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(i+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(i+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(i+=`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))),i.length>0&&(e=e.replace(/<img/g,`<img ${i.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 u,h;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:(u=t.srcset)==null?void 0:u.map(d=>{if(typeof d=="number")return`//${p}/m/${d}x0${o} ${d}w`;if(typeof d=="object"&&d.length===2){let k=0,$=0;return typeof d[0]=="number"&&(k=d[0]),typeof d[1]=="number"&&($=d[1]),`//${p}/m/${k}x${$}${o} ${k}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(d=>d).join(", ")};let f="";return g.srcset&&(f+=`srcset="${g.srcset}" `),g.sizes&&(f+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${f.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderOpeningTag(i.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(ce(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 i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderClosingTag(i.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 i in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,i)){const o=s.attrs[i];o!==null&&(r+=` ${i}="${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 y=he;class ue{constructor(e){c(this,"baseURL"),c(this,"timeout"),c(this,"headers"),c(this,"responseInterceptor"),c(this,"fetch"),c(this,"ejectInterceptor"),c(this,"url"),c(this,"parameters"),c(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 v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:o}=i;let l;this.timeout&&(l=setTimeout(()=>i.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 u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(i)})}}const pe=ue,S="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let b={};const m={};class de{constructor(e,t){c(this,"client"),c(this,"maxRetries"),c(this,"retriesDelay"),c(this,"throttle"),c(this,"accessToken"),c(this,"cache"),c(this,"helpers"),c(this,"resolveCounter"),c(this,"relations"),c(this,"links"),c(this,"richTextResolver"),c(this,"resolveNestedRelations"),c(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const o=new v().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(S)||(r.set(S,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),e.richTextSchema?this.richTextResolver=new y(e.richTextSchema):this.richTextResolver=new y,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=L(this.throttledRequest,i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new pe({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=m[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,i){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o,void 0,i)}get(e,t,s){t||(t={});const r=`/${e}`,i=this.factoryParamOptions(r,t);return this.cacheResponse(r,i,void 0,s)}async getAll(e,t,s,r){const i=(t==null?void 0:t.per_page)||25,o=`/${e}`,l=o.split("/"),a=s||l[l.length-1],u=1,h=await this.makeRequest(o,t,i,u,r),p=h.total?Math.ceil(h.total/i):1,g=await this.helpers.asyncMap(this.helpers.range(u,p),f=>this.makeRequest(o,t,i,f+1,r));return this.helpers.flatMap([h,...g],f=>Object.values(f.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(i=>this.getStoryReference(r,i)).filter(Boolean)))}iterateTree(e,t,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let o=0;o<i.length;o++)r(i[o]);else if(i.constructor===Object){if(i._stopResolving)return;for(const o in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,o,t,s),this._insertLinks(i,o,s)),r(i[o])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,o=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);o.push(e.link_uuids.slice(a,u))}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(u=>{r.push(u)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,o=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);o.push(e.rel_uuids.slice(a,u))}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(u=>{r.push(u)})}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var r,i;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||(i=e.link_uuids)!=null&&i.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 i=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(i);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var u;try{const h=await this.throttle("get",e,t,r);if(h.status!==200)return a(h);let p={data:h.data,headers:h.headers};if((u=h.headers)!=null&&u["per-page"]&&(p=Object.assign({},p,{perPage:h.headers["per-page"]?parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?parseInt(h.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(i,p),p.data.cv&&t.token&&(t.version==="draft"&&m[t.token]!=p.data.cv&&await this.flushCache(),m[t.token]=t.cv?t.cv:p.data.cv),l(p)}catch(h){if(h.response&&h.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(h)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(m[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(b[e])},getAll(){return Promise.resolve(b)},set(e,t){return b[e]=t,Promise.resolve(void 0)},flush(){return b={},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 ge=(n={})=>{const{apiOptions:e}=n;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 de(e)}},fe=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let R,T="https://app.storyblok.com/f/storyblok-v2-latest.js";const E=(n,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===n;if(!(!r||!i)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],o=>{o.action==="input"&&o.story.id===n?e(o.story):(o.action==="change"||o.action==="published")&&o.storyId===n&&window.location.reload()})})}},me=(n={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:o={},richText:l={},bridgeUrl:a}=n;o.accessToken=o.accessToken||r;const u={bridge:s,apiOptions:o};let h={};i.forEach(g=>{h={...h,...g(u)}}),a&&(T=a);const p=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&p&&O(T),R=new y(l.schema),l.resolver&&I(R,l.resolver),h},I=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},C=n=>!n||!(n!=null&&n.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ye=(n,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(n)?"":(e&&(s=new y(e.schema),e.resolver&&I(s,e.resolver)),s.render(n))},be=()=>O(T);exports.RichTextResolver=y;exports.RichTextSchema=P;exports.apiPlugin=ge;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=be;exports.registerStoryblokBridge=E;exports.renderRichText=ye;exports.storyblokEditable=fe;exports.storyblokInit=me;exports.useStoryblokBridge=E;
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,o="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const l=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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 u,h;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const g={srcset:(u=t.srcset)==null?void 0:u.map(p=>{if(typeof p=="number")return`//${d}/m/${p}x0${i} ${p}w`;if(typeof p=="object"&&p.length===2){let k=0,$=0;return typeof p[0]=="number"&&(k=p[0]),typeof p[1]=="number"&&($=p[1]),`//${d}/m/${k}x${$}${i} ${k}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(p=>p).join(", ")};let f="";return g.srcset&&(f+=`srcset="${g.srcset}" `),g.sizes&&(f+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${f.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ce(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs){for(const o in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,o)){const i=s.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}}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 y=he;class ue{constructor(e){c(this,"baseURL"),c(this,"timeout"),c(this,"headers"),c(this,"responseInterceptor"),c(this,"fetch"),c(this,"ejectInterceptor"),c(this,"url"),c(this,"parameters"),c(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 v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:i}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i,...this.fetchOptions});this.timeout&&clearTimeout(l);const u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const de=ue,S="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let b={};const m={};class pe{constructor(e,t){c(this,"client"),c(this,"maxRetries"),c(this,"retriesDelay"),c(this,"throttle"),c(this,"accessToken"),c(this,"cache"),c(this,"helpers"),c(this,"resolveCounter"),c(this,"relations"),c(this,"links"),c(this,"richTextResolver"),c(this,"resolveNestedRelations"),c(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${i(e.region)}/v1`:s=`${l}://${i(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(([i,l])=>{r.set(i,l)}),r.has(S)||(r.set(S,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new y(e.richTextSchema):this.richTextResolver=new y,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=L(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new de({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=m[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r,o){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i,void 0,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o,void 0,s)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,i=`/${e}`,l=i.split("/"),a=s||l[l.length-1],u=1,h=await this.makeRequest(i,t,o,u,r),d=h.total?Math.ceil(h.total/o):1,g=await this.helpers.asyncMap(this.helpers.range(u,d),f=>this.makeRequest(i,t,o,f+1,r));return this.helpers.flatMap([h,...g],f=>Object.values(f.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(o=>this.getStoryReference(r,o)).filter(Boolean)))}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let i=0;i<o.length;i++)r(o[i]);else if(o.constructor===Object){if(o._stopResolving)return;for(const i in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,s),this._insertLinks(o,i,s)),r(o[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,i=[],l=50;for(let a=0;a<o;a+=l){const u=Math.min(o,a+l);i.push(e.link_uuids.slice(a,u))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(u=>{r.push(u)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,i=[],l=50;for(let a=0;a<o;a+=l){const u=Math.min(o,a+l);i.push(e.rel_uuids.slice(a,u))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(u=>{r.push(u)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=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||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(l=>{this.iterateTree(l,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const o=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await i.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var u;try{const h=await this.throttle("get",e,t,r);if(h.status!==200)return a(h);let d={data:h.data,headers:h.headers};if((u=h.headers)!=null&&u["per-page"]&&(d=Object.assign({},d,{perPage:h.headers["per-page"]?parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?parseInt(h.headers.total):0})),d.data.story||d.data.stories){const g=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${g}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(o,d),d.data.cv&&t.token&&(t.version==="draft"&&m[t.token]!=d.data.cv&&await this.flushCache(),m[t.token]=t.cv?t.cv:d.data.cv),l(d)}catch(h){if(h.response&&h.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(h)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(m[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(b[e])},getAll(){return Promise.resolve(b)},set(e,t){return b[e]=t,Promise.resolve(void 0)},flush(){return b={},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 ge=(n={})=>{const{apiOptions:e}=n;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 pe(e)}},fe=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let R,T="https://app.storyblok.com/f/storyblok-v2-latest.js";const E=(n,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===n;if(!(!r||!o)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===n?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===n&&window.location.reload()})})}},me=(n={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:i={},richText:l={},bridgeUrl:a}=n;i.accessToken=i.accessToken||r;const u={bridge:s,apiOptions:i};let h={};o.forEach(g=>{h={...h,...g(u)}}),a&&(T=a);const d=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&d&&O(T),R=new y(l.schema),l.resolver&&C(R,l.resolver),h},C=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},I=n=>!n||!(n!=null&&n.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ye=(n,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return I(n)?"":(e&&(s=new y(e.schema),e.resolver&&C(s,e.resolver)),s.render(n))},be=()=>O(T);exports.RichTextResolver=y;exports.RichTextSchema=P;exports.apiPlugin=ge;exports.isRichTextEmpty=I;exports.loadStoryblokBridge=be;exports.registerStoryblokBridge=E;exports.renderRichText=ye;exports.storyblokEditable=fe;exports.storyblokInit=me;exports.useStoryblokBridge=E;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -9,24 +9,24 @@ const j = [], O = (n) => new Promise((e, t) => {
|
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge"))) return;
|
|
10
10
|
const s = document.createElement("script");
|
|
11
11
|
s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
12
|
-
j.forEach((
|
|
12
|
+
j.forEach((o) => o()), _ = !0, e(r);
|
|
13
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
14
14
|
});
|
|
15
|
-
var
|
|
15
|
+
var P = Object.defineProperty, C = (n, e, t) => e in n ? P(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, c = (n, e, t) => C(n, typeof e != "symbol" ? e + "" : e, t);
|
|
16
16
|
function x(n) {
|
|
17
17
|
return !(n !== n || n === 1 / 0 || n === -1 / 0);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function I(n, e, t) {
|
|
20
20
|
if (!x(e))
|
|
21
21
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
22
22
|
if (!x(t))
|
|
23
23
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
24
24
|
const s = [];
|
|
25
|
-
let r = [],
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
let r = [], o = 0;
|
|
26
|
+
const i = function() {
|
|
27
|
+
o++;
|
|
28
28
|
const a = setTimeout(function() {
|
|
29
|
-
|
|
29
|
+
o--, s.length > 0 && i(), r = r.filter(function(h) {
|
|
30
30
|
return h !== a;
|
|
31
31
|
});
|
|
32
32
|
}, t);
|
|
@@ -35,13 +35,13 @@ function C(n, e, t) {
|
|
|
35
35
|
u.resolve(n.apply(u.self, u.args));
|
|
36
36
|
}, l = function(...a) {
|
|
37
37
|
const u = this;
|
|
38
|
-
return new Promise(function(h,
|
|
38
|
+
return new Promise(function(h, d) {
|
|
39
39
|
s.push({
|
|
40
40
|
resolve: h,
|
|
41
|
-
reject:
|
|
41
|
+
reject: d,
|
|
42
42
|
args: a,
|
|
43
43
|
self: u
|
|
44
|
-
}),
|
|
44
|
+
}), o < e && i();
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
return l.abort = function() {
|
|
@@ -60,7 +60,7 @@ class b {
|
|
|
60
60
|
page: s
|
|
61
61
|
})), c(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), c(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), c(this, "range", (e = 0, t = e) => {
|
|
62
62
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
63
|
-
return this.arrayFrom(s, (
|
|
63
|
+
return this.arrayFrom(s, (o, i) => i * r + e);
|
|
64
64
|
}), c(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), c(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), c(this, "escapeHTML", function(e) {
|
|
65
65
|
const t = {
|
|
66
66
|
"&": "&",
|
|
@@ -69,7 +69,7 @@ class b {
|
|
|
69
69
|
'"': """,
|
|
70
70
|
"'": "'"
|
|
71
71
|
}, s = /[&<>"']/g, r = RegExp(s.source);
|
|
72
|
-
return e && r.test(e) ? e.replace(s, (
|
|
72
|
+
return e && r.test(e) ? e.replace(s, (o) => t[o]) : e;
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -81,16 +81,16 @@ class b {
|
|
|
81
81
|
*/
|
|
82
82
|
stringify(e, t, s) {
|
|
83
83
|
const r = [];
|
|
84
|
-
for (const
|
|
85
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
84
|
+
for (const o in e) {
|
|
85
|
+
if (!Object.prototype.hasOwnProperty.call(e, o))
|
|
86
86
|
continue;
|
|
87
|
-
const
|
|
87
|
+
const i = e[o], l = s ? "" : encodeURIComponent(o);
|
|
88
88
|
let a;
|
|
89
|
-
typeof
|
|
90
|
-
|
|
89
|
+
typeof i == "object" ? a = this.stringify(
|
|
90
|
+
i,
|
|
91
91
|
t ? t + encodeURIComponent("[" + l + "]") : l,
|
|
92
|
-
Array.isArray(
|
|
93
|
-
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(
|
|
92
|
+
Array.isArray(i)
|
|
93
|
+
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(i), r.push(a);
|
|
94
94
|
}
|
|
95
95
|
return r.join("&");
|
|
96
96
|
}
|
|
@@ -100,16 +100,16 @@ class b {
|
|
|
100
100
|
* @return {String} The base URL of the region
|
|
101
101
|
*/
|
|
102
102
|
getRegionURL(e) {
|
|
103
|
-
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn",
|
|
103
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", o = "api-ap.storyblok.com", i = "api-ca.storyblok.com";
|
|
104
104
|
switch (e) {
|
|
105
105
|
case "us":
|
|
106
106
|
return s;
|
|
107
107
|
case "cn":
|
|
108
108
|
return r;
|
|
109
109
|
case "ap":
|
|
110
|
-
return i;
|
|
111
|
-
case "ca":
|
|
112
110
|
return o;
|
|
111
|
+
case "ca":
|
|
112
|
+
return i;
|
|
113
113
|
default:
|
|
114
114
|
return t;
|
|
115
115
|
}
|
|
@@ -126,7 +126,7 @@ const A = function(n, e) {
|
|
|
126
126
|
singleTag: "hr"
|
|
127
127
|
}), M = () => ({
|
|
128
128
|
tag: "blockquote"
|
|
129
|
-
}),
|
|
129
|
+
}), H = () => ({
|
|
130
130
|
tag: "ul"
|
|
131
131
|
}), U = (n) => ({
|
|
132
132
|
tag: [
|
|
@@ -136,20 +136,20 @@ const A = function(n, e) {
|
|
|
136
136
|
attrs: n.attrs
|
|
137
137
|
}
|
|
138
138
|
]
|
|
139
|
-
}),
|
|
139
|
+
}), z = () => ({
|
|
140
140
|
singleTag: "br"
|
|
141
141
|
}), q = (n) => ({
|
|
142
142
|
tag: `h${n.attrs.level}`
|
|
143
|
-
}),
|
|
143
|
+
}), B = (n) => ({
|
|
144
144
|
singleTag: [
|
|
145
145
|
{
|
|
146
146
|
tag: "img",
|
|
147
147
|
attrs: A(n.attrs, ["src", "alt", "title"])
|
|
148
148
|
}
|
|
149
149
|
]
|
|
150
|
-
}), B = () => ({
|
|
151
|
-
tag: "li"
|
|
152
150
|
}), D = () => ({
|
|
151
|
+
tag: "li"
|
|
152
|
+
}), V = () => ({
|
|
153
153
|
tag: "ol"
|
|
154
154
|
}), J = () => ({
|
|
155
155
|
tag: "p"
|
|
@@ -170,13 +170,13 @@ const A = function(n, e) {
|
|
|
170
170
|
tag: "s"
|
|
171
171
|
}), K = () => ({
|
|
172
172
|
tag: "u"
|
|
173
|
-
}), G = () => ({
|
|
174
|
-
tag: "strong"
|
|
175
173
|
}), Q = () => ({
|
|
176
|
-
tag: "
|
|
174
|
+
tag: "strong"
|
|
177
175
|
}), X = () => ({
|
|
176
|
+
tag: "code"
|
|
177
|
+
}), Z = () => ({
|
|
178
178
|
tag: "i"
|
|
179
|
-
}),
|
|
179
|
+
}), G = (n) => {
|
|
180
180
|
if (!n.attrs)
|
|
181
181
|
return {
|
|
182
182
|
tag: ""
|
|
@@ -213,7 +213,7 @@ const A = function(n, e) {
|
|
|
213
213
|
attrs: n.attrs
|
|
214
214
|
}
|
|
215
215
|
]
|
|
216
|
-
}),
|
|
216
|
+
}), oe = (n) => {
|
|
217
217
|
var e;
|
|
218
218
|
return (e = n.attrs) != null && e.color ? {
|
|
219
219
|
tag: [
|
|
@@ -227,7 +227,7 @@ const A = function(n, e) {
|
|
|
227
227
|
} : {
|
|
228
228
|
tag: ""
|
|
229
229
|
};
|
|
230
|
-
},
|
|
230
|
+
}, ie = (n) => {
|
|
231
231
|
var e;
|
|
232
232
|
return (e = n.attrs) != null && e.color ? {
|
|
233
233
|
tag: [
|
|
@@ -245,13 +245,13 @@ const A = function(n, e) {
|
|
|
245
245
|
nodes: {
|
|
246
246
|
horizontal_rule: L,
|
|
247
247
|
blockquote: M,
|
|
248
|
-
bullet_list:
|
|
248
|
+
bullet_list: H,
|
|
249
249
|
code_block: U,
|
|
250
|
-
hard_break:
|
|
250
|
+
hard_break: z,
|
|
251
251
|
heading: q,
|
|
252
|
-
image:
|
|
253
|
-
list_item:
|
|
254
|
-
ordered_list:
|
|
252
|
+
image: B,
|
|
253
|
+
list_item: D,
|
|
254
|
+
ordered_list: V,
|
|
255
255
|
paragraph: J,
|
|
256
256
|
emoji: F
|
|
257
257
|
},
|
|
@@ -259,16 +259,16 @@ const A = function(n, e) {
|
|
|
259
259
|
bold: W,
|
|
260
260
|
strike: Y,
|
|
261
261
|
underline: K,
|
|
262
|
-
strong:
|
|
263
|
-
code:
|
|
264
|
-
italic:
|
|
265
|
-
link:
|
|
262
|
+
strong: Q,
|
|
263
|
+
code: X,
|
|
264
|
+
italic: Z,
|
|
265
|
+
link: G,
|
|
266
266
|
styled: ee,
|
|
267
267
|
subscript: te,
|
|
268
268
|
superscript: se,
|
|
269
269
|
anchor: re,
|
|
270
|
-
highlight:
|
|
271
|
-
textStyle:
|
|
270
|
+
highlight: oe,
|
|
271
|
+
textStyle: ie
|
|
272
272
|
}
|
|
273
273
|
}, ae = function(n) {
|
|
274
274
|
const e = {
|
|
@@ -327,28 +327,28 @@ class le {
|
|
|
327
327
|
), "";
|
|
328
328
|
}
|
|
329
329
|
optimizeImages(e, t) {
|
|
330
|
-
let s = 0, r = 0,
|
|
331
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
332
|
-
const l = s > 0 || r > 0 ||
|
|
330
|
+
let s = 0, r = 0, o = "", i = "";
|
|
331
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = "/filters" + i))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
|
|
332
|
+
const l = s > 0 || r > 0 || i.length > 0 ? `${s}x${r}${i}` : "";
|
|
333
333
|
return e = e.replace(
|
|
334
334
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
335
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
337
|
var u, h;
|
|
338
|
-
const
|
|
338
|
+
const d = a.match(
|
|
339
339
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
340
340
|
);
|
|
341
|
-
if (
|
|
341
|
+
if (d && d.length > 0) {
|
|
342
342
|
const g = {
|
|
343
|
-
srcset: (u = t.srcset) == null ? void 0 : u.map((
|
|
344
|
-
if (typeof
|
|
345
|
-
return `//${
|
|
346
|
-
if (typeof
|
|
343
|
+
srcset: (u = t.srcset) == null ? void 0 : u.map((p) => {
|
|
344
|
+
if (typeof p == "number")
|
|
345
|
+
return `//${d}/m/${p}x0${i} ${p}w`;
|
|
346
|
+
if (typeof p == "object" && p.length === 2) {
|
|
347
347
|
let k = 0, $ = 0;
|
|
348
|
-
return typeof
|
|
348
|
+
return typeof p[0] == "number" && (k = p[0]), typeof p[1] == "number" && ($ = p[1]), `//${d}/m/${k}x${$}${i} ${k}w`;
|
|
349
349
|
}
|
|
350
350
|
}).join(", "),
|
|
351
|
-
sizes: (h = t.sizes) == null ? void 0 : h.map((
|
|
351
|
+
sizes: (h = t.sizes) == null ? void 0 : h.map((p) => p).join(", ")
|
|
352
352
|
};
|
|
353
353
|
let f = "";
|
|
354
354
|
return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
|
@@ -359,15 +359,15 @@ class le {
|
|
|
359
359
|
renderNode(e) {
|
|
360
360
|
const t = [];
|
|
361
361
|
e.marks && e.marks.forEach((r) => {
|
|
362
|
-
const
|
|
363
|
-
|
|
362
|
+
const o = this.getMatchingMark(r);
|
|
363
|
+
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
|
364
364
|
});
|
|
365
365
|
const s = this.getMatchingNode(e);
|
|
366
366
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
367
367
|
t.push(this.renderNode(r));
|
|
368
368
|
}) : e.text ? t.push(ae(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) => {
|
|
369
|
-
const
|
|
370
|
-
|
|
369
|
+
const o = this.getMatchingMark(r);
|
|
370
|
+
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
|
371
371
|
}), t.join("");
|
|
372
372
|
}
|
|
373
373
|
renderTag(e, t) {
|
|
@@ -377,10 +377,10 @@ class le {
|
|
|
377
377
|
{
|
|
378
378
|
let r = `<${s.tag}`;
|
|
379
379
|
if (s.attrs) {
|
|
380
|
-
for (const
|
|
381
|
-
if (Object.prototype.hasOwnProperty.call(s.attrs,
|
|
382
|
-
const
|
|
383
|
-
|
|
380
|
+
for (const o in s.attrs)
|
|
381
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, o)) {
|
|
382
|
+
const i = s.attrs[o];
|
|
383
|
+
i !== null && (r += ` ${o}="${i}"`);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
return `${r}${t}>`;
|
|
@@ -466,15 +466,15 @@ class ce {
|
|
|
466
466
|
)}`;
|
|
467
467
|
} else
|
|
468
468
|
s = JSON.stringify(this.parameters);
|
|
469
|
-
const r = new URL(t),
|
|
469
|
+
const r = new URL(t), o = new AbortController(), { signal: i } = o;
|
|
470
470
|
let l;
|
|
471
|
-
this.timeout && (l = setTimeout(() =>
|
|
471
|
+
this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
|
|
472
472
|
try {
|
|
473
473
|
const a = await this.fetch(`${r}`, {
|
|
474
474
|
method: e,
|
|
475
475
|
headers: this.headers,
|
|
476
476
|
body: s,
|
|
477
|
-
signal:
|
|
477
|
+
signal: i,
|
|
478
478
|
...this.fetchOptions
|
|
479
479
|
});
|
|
480
480
|
this.timeout && clearTimeout(l);
|
|
@@ -499,12 +499,12 @@ class ce {
|
|
|
499
499
|
return new Promise((s, r) => {
|
|
500
500
|
if (t.test(`${e.status}`))
|
|
501
501
|
return s(e);
|
|
502
|
-
const
|
|
502
|
+
const o = {
|
|
503
503
|
message: e.statusText,
|
|
504
504
|
status: e.status,
|
|
505
505
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
506
506
|
};
|
|
507
|
-
r(
|
|
507
|
+
r(o);
|
|
508
508
|
});
|
|
509
509
|
}
|
|
510
510
|
}
|
|
@@ -525,18 +525,18 @@ class ue {
|
|
|
525
525
|
c(this, "client"), c(this, "maxRetries"), c(this, "retriesDelay"), c(this, "throttle"), c(this, "accessToken"), c(this, "cache"), c(this, "helpers"), c(this, "resolveCounter"), c(this, "relations"), c(this, "links"), c(this, "richTextResolver"), c(this, "resolveNestedRelations"), c(this, "stringifiedStoriesCache");
|
|
526
526
|
let s = e.endpoint || t;
|
|
527
527
|
if (!s) {
|
|
528
|
-
const
|
|
529
|
-
e.oauthToken ? s = `${l}://${
|
|
528
|
+
const i = new b().getRegionURL, l = e.https === !1 ? "http" : "https";
|
|
529
|
+
e.oauthToken ? s = `${l}://${i(e.region)}/v1` : s = `${l}://${i(e.region)}/v2`;
|
|
530
530
|
}
|
|
531
531
|
const r = new Headers();
|
|
532
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && e.headers.entries().toArray().forEach(([
|
|
533
|
-
r.set(
|
|
532
|
+
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(([i, l]) => {
|
|
533
|
+
r.set(i, l);
|
|
534
534
|
}), r.has(S) || (r.set(S, w.defaultAgentName), r.set(
|
|
535
535
|
w.defaultAgentVersion,
|
|
536
536
|
w.packageVersion
|
|
537
537
|
));
|
|
538
|
-
let
|
|
539
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
|
538
|
+
let o = 5;
|
|
539
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new v(e.richTextSchema) : this.richTextResolver = new v(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = I(this.throttledRequest, o, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new he({
|
|
540
540
|
baseURL: s,
|
|
541
541
|
timeout: e.timeout || 0,
|
|
542
542
|
headers: r,
|
|
@@ -560,28 +560,28 @@ class ue {
|
|
|
560
560
|
factoryParamOptions(e, t) {
|
|
561
561
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
562
562
|
}
|
|
563
|
-
makeRequest(e, t, s, r,
|
|
564
|
-
const
|
|
563
|
+
makeRequest(e, t, s, r, o) {
|
|
564
|
+
const i = this.factoryParamOptions(
|
|
565
565
|
e,
|
|
566
566
|
this.helpers.getOptionsPage(t, s, r)
|
|
567
567
|
);
|
|
568
|
-
return this.cacheResponse(e,
|
|
568
|
+
return this.cacheResponse(e, i, void 0, o);
|
|
569
569
|
}
|
|
570
570
|
get(e, t, s) {
|
|
571
571
|
t || (t = {});
|
|
572
|
-
const r = `/${e}`,
|
|
573
|
-
return this.cacheResponse(r,
|
|
572
|
+
const r = `/${e}`, o = this.factoryParamOptions(r, t);
|
|
573
|
+
return this.cacheResponse(r, o, void 0, s);
|
|
574
574
|
}
|
|
575
575
|
async getAll(e, t, s, r) {
|
|
576
|
-
const
|
|
577
|
-
o,
|
|
578
|
-
t,
|
|
576
|
+
const o = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, l = i.split("/"), a = s || l[l.length - 1], u = 1, h = await this.makeRequest(
|
|
579
577
|
i,
|
|
578
|
+
t,
|
|
579
|
+
o,
|
|
580
580
|
u,
|
|
581
581
|
r
|
|
582
|
-
),
|
|
583
|
-
this.helpers.range(u,
|
|
584
|
-
(f) => this.makeRequest(
|
|
582
|
+
), d = h.total ? Math.ceil(h.total / o) : 1, g = await this.helpers.asyncMap(
|
|
583
|
+
this.helpers.range(u, d),
|
|
584
|
+
(f) => this.makeRequest(i, t, o, f + 1, r)
|
|
585
585
|
);
|
|
586
586
|
return this.helpers.flatMap(
|
|
587
587
|
[h, ...g],
|
|
@@ -634,28 +634,28 @@ class ue {
|
|
|
634
634
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
635
635
|
}
|
|
636
636
|
_insertRelations(e, t, s, r) {
|
|
637
|
-
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((
|
|
637
|
+
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((o) => this.getStoryReference(r, o)).filter(Boolean)));
|
|
638
638
|
}
|
|
639
639
|
iterateTree(e, t, s) {
|
|
640
|
-
const r = (
|
|
641
|
-
if (
|
|
642
|
-
if (
|
|
643
|
-
for (let
|
|
644
|
-
r(i
|
|
645
|
-
else if (
|
|
646
|
-
if (
|
|
640
|
+
const r = (o) => {
|
|
641
|
+
if (o != null) {
|
|
642
|
+
if (o.constructor === Array)
|
|
643
|
+
for (let i = 0; i < o.length; i++)
|
|
644
|
+
r(o[i]);
|
|
645
|
+
else if (o.constructor === Object) {
|
|
646
|
+
if (o._stopResolving)
|
|
647
647
|
return;
|
|
648
|
-
for (const
|
|
649
|
-
(
|
|
650
|
-
i,
|
|
648
|
+
for (const i in o)
|
|
649
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(
|
|
651
650
|
o,
|
|
651
|
+
i,
|
|
652
652
|
t,
|
|
653
653
|
s
|
|
654
654
|
), this._insertLinks(
|
|
655
|
-
i,
|
|
656
655
|
o,
|
|
656
|
+
i,
|
|
657
657
|
s
|
|
658
|
-
)), r(i
|
|
658
|
+
)), r(o[i]);
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
661
|
};
|
|
@@ -664,17 +664,17 @@ class ue {
|
|
|
664
664
|
async resolveLinks(e, t, s) {
|
|
665
665
|
let r = [];
|
|
666
666
|
if (e.link_uuids) {
|
|
667
|
-
const
|
|
668
|
-
for (let a = 0; a <
|
|
669
|
-
const u = Math.min(
|
|
670
|
-
|
|
667
|
+
const o = e.link_uuids.length, i = [], l = 50;
|
|
668
|
+
for (let a = 0; a < o; a += l) {
|
|
669
|
+
const u = Math.min(o, a + l);
|
|
670
|
+
i.push(e.link_uuids.slice(a, u));
|
|
671
671
|
}
|
|
672
|
-
for (let a = 0; a <
|
|
672
|
+
for (let a = 0; a < i.length; a++)
|
|
673
673
|
(await this.getStories({
|
|
674
674
|
per_page: l,
|
|
675
675
|
language: t.language,
|
|
676
676
|
version: t.version,
|
|
677
|
-
by_uuids:
|
|
677
|
+
by_uuids: i[a].join(",")
|
|
678
678
|
})).data.stories.forEach(
|
|
679
679
|
(u) => {
|
|
680
680
|
r.push(u);
|
|
@@ -682,9 +682,9 @@ class ue {
|
|
|
682
682
|
);
|
|
683
683
|
} else
|
|
684
684
|
r = e.links;
|
|
685
|
-
r.forEach((
|
|
686
|
-
this.links[s][
|
|
687
|
-
...
|
|
685
|
+
r.forEach((o) => {
|
|
686
|
+
this.links[s][o.uuid] = {
|
|
687
|
+
...o,
|
|
688
688
|
_stopResolving: !0
|
|
689
689
|
};
|
|
690
690
|
});
|
|
@@ -692,26 +692,26 @@ class ue {
|
|
|
692
692
|
async resolveRelations(e, t, s) {
|
|
693
693
|
let r = [];
|
|
694
694
|
if (e.rel_uuids) {
|
|
695
|
-
const
|
|
696
|
-
for (let a = 0; a <
|
|
697
|
-
const u = Math.min(
|
|
698
|
-
|
|
695
|
+
const o = e.rel_uuids.length, i = [], l = 50;
|
|
696
|
+
for (let a = 0; a < o; a += l) {
|
|
697
|
+
const u = Math.min(o, a + l);
|
|
698
|
+
i.push(e.rel_uuids.slice(a, u));
|
|
699
699
|
}
|
|
700
|
-
for (let a = 0; a <
|
|
700
|
+
for (let a = 0; a < i.length; a++)
|
|
701
701
|
(await this.getStories({
|
|
702
702
|
per_page: l,
|
|
703
703
|
language: t.language,
|
|
704
704
|
version: t.version,
|
|
705
|
-
by_uuids:
|
|
705
|
+
by_uuids: i[a].join(","),
|
|
706
706
|
excluding_fields: t.excluding_fields
|
|
707
707
|
})).data.stories.forEach((u) => {
|
|
708
708
|
r.push(u);
|
|
709
709
|
});
|
|
710
710
|
} else
|
|
711
711
|
r = e.rels;
|
|
712
|
-
r && r.length > 0 && r.forEach((
|
|
713
|
-
this.relations[s][
|
|
714
|
-
...
|
|
712
|
+
r && r.length > 0 && r.forEach((o) => {
|
|
713
|
+
this.relations[s][o.uuid] = {
|
|
714
|
+
...o,
|
|
715
715
|
_stopResolving: !0
|
|
716
716
|
};
|
|
717
717
|
});
|
|
@@ -726,23 +726,23 @@ class ue {
|
|
|
726
726
|
*
|
|
727
727
|
*/
|
|
728
728
|
async resolveStories(e, t, s) {
|
|
729
|
-
var r,
|
|
730
|
-
let
|
|
731
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
|
729
|
+
var r, o;
|
|
730
|
+
let i = [];
|
|
731
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = 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 || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
732
732
|
for (const l in this.relations[s])
|
|
733
733
|
this.iterateTree(
|
|
734
734
|
this.relations[s][l],
|
|
735
|
-
|
|
735
|
+
i,
|
|
736
736
|
s
|
|
737
737
|
);
|
|
738
|
-
e.story ? this.iterateTree(e.story,
|
|
739
|
-
this.iterateTree(l,
|
|
738
|
+
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
|
|
739
|
+
this.iterateTree(l, i, s);
|
|
740
740
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
741
741
|
}
|
|
742
742
|
async cacheResponse(e, t, s, r) {
|
|
743
|
-
const
|
|
743
|
+
const o = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
744
744
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
745
|
-
const l = await
|
|
745
|
+
const l = await i.get(o);
|
|
746
746
|
if (l)
|
|
747
747
|
return Promise.resolve(l);
|
|
748
748
|
}
|
|
@@ -752,15 +752,15 @@ class ue {
|
|
|
752
752
|
const h = await this.throttle("get", e, t, r);
|
|
753
753
|
if (h.status !== 200)
|
|
754
754
|
return a(h);
|
|
755
|
-
let
|
|
756
|
-
if ((u = h.headers) != null && u["per-page"] && (
|
|
755
|
+
let d = { data: h.data, headers: h.headers };
|
|
756
|
+
if ((u = h.headers) != null && u["per-page"] && (d = Object.assign({}, d, {
|
|
757
757
|
perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
|
|
758
758
|
total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
|
|
759
|
-
})),
|
|
759
|
+
})), d.data.story || d.data.stories) {
|
|
760
760
|
const g = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
761
|
-
await this.resolveStories(
|
|
761
|
+
await this.resolveStories(d.data, t, `${g}`);
|
|
762
762
|
}
|
|
763
|
-
return t.version === "published" && e != "/cdn/spaces/me" && await
|
|
763
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await i.set(o, d), d.data.cv && t.token && (t.version === "draft" && m[t.token] != d.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : d.data.cv), l(d);
|
|
764
764
|
} catch (h) {
|
|
765
765
|
if (h.response && h.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
766
766
|
return console.log(
|
|
@@ -825,7 +825,7 @@ class ue {
|
|
|
825
825
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
|
-
const
|
|
828
|
+
const pe = (n = {}) => {
|
|
829
829
|
const { apiOptions: e } = n;
|
|
830
830
|
if (!e.accessToken) {
|
|
831
831
|
console.error(
|
|
@@ -852,17 +852,17 @@ const de = (n = {}) => {
|
|
|
852
852
|
let R, T = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
853
853
|
const fe = (n, e, t = {}) => {
|
|
854
854
|
var s;
|
|
855
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
855
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
856
856
|
"_storyblok"
|
|
857
857
|
) === n;
|
|
858
|
-
if (!(!r || !
|
|
858
|
+
if (!(!r || !o)) {
|
|
859
859
|
if (!n) {
|
|
860
860
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
861
861
|
return;
|
|
862
862
|
}
|
|
863
863
|
window.storyblokRegisterEvent(() => {
|
|
864
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
865
|
-
|
|
864
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (i) => {
|
|
865
|
+
i.action === "input" && i.story.id === n ? e(i.story) : (i.action === "change" || i.action === "published") && i.storyId === n && window.location.reload();
|
|
866
866
|
});
|
|
867
867
|
});
|
|
868
868
|
}
|
|
@@ -871,20 +871,20 @@ const fe = (n, e, t = {}) => {
|
|
|
871
871
|
const {
|
|
872
872
|
bridge: s,
|
|
873
873
|
accessToken: r,
|
|
874
|
-
use:
|
|
875
|
-
apiOptions:
|
|
874
|
+
use: o = [],
|
|
875
|
+
apiOptions: i = {},
|
|
876
876
|
richText: l = {},
|
|
877
877
|
bridgeUrl: a
|
|
878
878
|
} = n;
|
|
879
|
-
|
|
880
|
-
const u = { bridge: s, apiOptions:
|
|
879
|
+
i.accessToken = i.accessToken || r;
|
|
880
|
+
const u = { bridge: s, apiOptions: i };
|
|
881
881
|
let h = {};
|
|
882
|
-
|
|
882
|
+
o.forEach((g) => {
|
|
883
883
|
h = { ...h, ...g(u) };
|
|
884
884
|
}), a && (T = a);
|
|
885
|
-
const
|
|
886
|
-
return s !== !1 &&
|
|
887
|
-
},
|
|
885
|
+
const d = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
886
|
+
return s !== !1 && d && O(T), R = new v(l.schema), l.resolver && E(R, l.resolver), h;
|
|
887
|
+
}, E = (n, e) => {
|
|
888
888
|
n.addNode("blok", (t) => {
|
|
889
889
|
let s = "";
|
|
890
890
|
return t.attrs.body.forEach((r) => {
|
|
@@ -893,7 +893,7 @@ const fe = (n, e, t = {}) => {
|
|
|
893
893
|
html: s
|
|
894
894
|
};
|
|
895
895
|
});
|
|
896
|
-
},
|
|
896
|
+
}, de = (n) => !n || !(n != null && n.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ye = (n, e, t) => {
|
|
897
897
|
let s = t || R;
|
|
898
898
|
if (!s) {
|
|
899
899
|
console.error(
|
|
@@ -901,13 +901,13 @@ const fe = (n, e, t = {}) => {
|
|
|
901
901
|
);
|
|
902
902
|
return;
|
|
903
903
|
}
|
|
904
|
-
return
|
|
904
|
+
return de(n) ? "" : (e && (s = new v(e.schema), e.resolver && E(s, e.resolver)), s.render(n));
|
|
905
905
|
}, be = () => O(T);
|
|
906
906
|
export {
|
|
907
907
|
v as RichTextResolver,
|
|
908
908
|
ne as RichTextSchema,
|
|
909
|
-
|
|
910
|
-
|
|
909
|
+
pe as apiPlugin,
|
|
910
|
+
de as isRichTextEmpty,
|
|
911
911
|
be as loadStoryblokBridge,
|
|
912
912
|
fe as registerStoryblokBridge,
|
|
913
913
|
ye as renderRichText,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "^3.
|
|
47
|
+
"@storyblok/js": "^3.1.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/core": "^7.25.2",
|