@storyblok/react 3.0.12 → 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 +158 -156
- 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,T=0;return typeof d[0]=="number"&&(k=d[0]),typeof d[1]=="number"&&(T=d[1]),`//${p}/m/${k}x${T}${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,x="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(x)||(r.set(x,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,$="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&&($=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($),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($);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 P = Object.defineProperty,
|
|
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"
|
|
@@ -164,19 +164,19 @@ const A = function(n, e) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
]
|
|
167
|
-
}),
|
|
167
|
+
}), W = () => ({
|
|
168
168
|
tag: "b"
|
|
169
|
-
}),
|
|
169
|
+
}), Y = () => ({
|
|
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,30 +245,30 @@ 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
|
},
|
|
258
258
|
marks: {
|
|
259
|
-
bold:
|
|
260
|
-
strike:
|
|
261
|
-
underline:
|
|
262
|
-
strong:
|
|
263
|
-
code:
|
|
264
|
-
italic:
|
|
265
|
-
link:
|
|
259
|
+
bold: W,
|
|
260
|
+
strike: Y,
|
|
261
|
+
underline: K,
|
|
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 = {
|
|
@@ -291,7 +291,9 @@ class le {
|
|
|
291
291
|
this.marks[e] = t;
|
|
292
292
|
}
|
|
293
293
|
render(e, t = { optimizeImages: !1 }) {
|
|
294
|
-
if (
|
|
294
|
+
if (console.warn(
|
|
295
|
+
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
|
|
296
|
+
), e && e.content && Array.isArray(e.content)) {
|
|
295
297
|
let s = "";
|
|
296
298
|
return e.content.forEach((r) => {
|
|
297
299
|
s += this.renderNode(r);
|
|
@@ -325,28 +327,28 @@ class le {
|
|
|
325
327
|
), "";
|
|
326
328
|
}
|
|
327
329
|
optimizeImages(e, t) {
|
|
328
|
-
let s = 0, r = 0,
|
|
329
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
330
|
-
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}` : "";
|
|
331
333
|
return e = e.replace(
|
|
332
334
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
333
335
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
334
336
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
335
337
|
var u, h;
|
|
336
|
-
const
|
|
338
|
+
const d = a.match(
|
|
337
339
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
338
340
|
);
|
|
339
|
-
if (
|
|
341
|
+
if (d && d.length > 0) {
|
|
340
342
|
const g = {
|
|
341
|
-
srcset: (u = t.srcset) == null ? void 0 : u.map((
|
|
342
|
-
if (typeof
|
|
343
|
-
return `//${
|
|
344
|
-
if (typeof
|
|
345
|
-
let k = 0,
|
|
346
|
-
return 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
|
+
let k = 0, $ = 0;
|
|
348
|
+
return typeof p[0] == "number" && (k = p[0]), typeof p[1] == "number" && ($ = p[1]), `//${d}/m/${k}x${$}${i} ${k}w`;
|
|
347
349
|
}
|
|
348
350
|
}).join(", "),
|
|
349
|
-
sizes: (h = t.sizes) == null ? void 0 : h.map((
|
|
351
|
+
sizes: (h = t.sizes) == null ? void 0 : h.map((p) => p).join(", ")
|
|
350
352
|
};
|
|
351
353
|
let f = "";
|
|
352
354
|
return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
|
@@ -357,15 +359,15 @@ class le {
|
|
|
357
359
|
renderNode(e) {
|
|
358
360
|
const t = [];
|
|
359
361
|
e.marks && e.marks.forEach((r) => {
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
+
const o = this.getMatchingMark(r);
|
|
363
|
+
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
|
362
364
|
});
|
|
363
365
|
const s = this.getMatchingNode(e);
|
|
364
366
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
365
367
|
t.push(this.renderNode(r));
|
|
366
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) => {
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
+
const o = this.getMatchingMark(r);
|
|
370
|
+
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
|
369
371
|
}), t.join("");
|
|
370
372
|
}
|
|
371
373
|
renderTag(e, t) {
|
|
@@ -375,10 +377,10 @@ class le {
|
|
|
375
377
|
{
|
|
376
378
|
let r = `<${s.tag}`;
|
|
377
379
|
if (s.attrs) {
|
|
378
|
-
for (const
|
|
379
|
-
if (Object.prototype.hasOwnProperty.call(s.attrs,
|
|
380
|
-
const
|
|
381
|
-
|
|
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}"`);
|
|
382
384
|
}
|
|
383
385
|
}
|
|
384
386
|
return `${r}${t}>`;
|
|
@@ -464,15 +466,15 @@ class ce {
|
|
|
464
466
|
)}`;
|
|
465
467
|
} else
|
|
466
468
|
s = JSON.stringify(this.parameters);
|
|
467
|
-
const r = new URL(t),
|
|
469
|
+
const r = new URL(t), o = new AbortController(), { signal: i } = o;
|
|
468
470
|
let l;
|
|
469
|
-
this.timeout && (l = setTimeout(() =>
|
|
471
|
+
this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
|
|
470
472
|
try {
|
|
471
473
|
const a = await this.fetch(`${r}`, {
|
|
472
474
|
method: e,
|
|
473
475
|
headers: this.headers,
|
|
474
476
|
body: s,
|
|
475
|
-
signal:
|
|
477
|
+
signal: i,
|
|
476
478
|
...this.fetchOptions
|
|
477
479
|
});
|
|
478
480
|
this.timeout && clearTimeout(l);
|
|
@@ -497,12 +499,12 @@ class ce {
|
|
|
497
499
|
return new Promise((s, r) => {
|
|
498
500
|
if (t.test(`${e.status}`))
|
|
499
501
|
return s(e);
|
|
500
|
-
const
|
|
502
|
+
const o = {
|
|
501
503
|
message: e.statusText,
|
|
502
504
|
status: e.status,
|
|
503
505
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
504
506
|
};
|
|
505
|
-
r(
|
|
507
|
+
r(o);
|
|
506
508
|
});
|
|
507
509
|
}
|
|
508
510
|
}
|
|
@@ -523,18 +525,18 @@ class ue {
|
|
|
523
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");
|
|
524
526
|
let s = e.endpoint || t;
|
|
525
527
|
if (!s) {
|
|
526
|
-
const
|
|
527
|
-
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`;
|
|
528
530
|
}
|
|
529
531
|
const r = new Headers();
|
|
530
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && e.headers.entries().toArray().forEach(([
|
|
531
|
-
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);
|
|
532
534
|
}), r.has(S) || (r.set(S, w.defaultAgentName), r.set(
|
|
533
535
|
w.defaultAgentVersion,
|
|
534
536
|
w.packageVersion
|
|
535
537
|
));
|
|
536
|
-
let
|
|
537
|
-
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({
|
|
538
540
|
baseURL: s,
|
|
539
541
|
timeout: e.timeout || 0,
|
|
540
542
|
headers: r,
|
|
@@ -558,28 +560,28 @@ class ue {
|
|
|
558
560
|
factoryParamOptions(e, t) {
|
|
559
561
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
560
562
|
}
|
|
561
|
-
makeRequest(e, t, s, r,
|
|
562
|
-
const
|
|
563
|
+
makeRequest(e, t, s, r, o) {
|
|
564
|
+
const i = this.factoryParamOptions(
|
|
563
565
|
e,
|
|
564
566
|
this.helpers.getOptionsPage(t, s, r)
|
|
565
567
|
);
|
|
566
|
-
return this.cacheResponse(e,
|
|
568
|
+
return this.cacheResponse(e, i, void 0, o);
|
|
567
569
|
}
|
|
568
570
|
get(e, t, s) {
|
|
569
571
|
t || (t = {});
|
|
570
|
-
const r = `/${e}`,
|
|
571
|
-
return this.cacheResponse(r,
|
|
572
|
+
const r = `/${e}`, o = this.factoryParamOptions(r, t);
|
|
573
|
+
return this.cacheResponse(r, o, void 0, s);
|
|
572
574
|
}
|
|
573
575
|
async getAll(e, t, s, r) {
|
|
574
|
-
const
|
|
575
|
-
o,
|
|
576
|
-
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(
|
|
577
577
|
i,
|
|
578
|
+
t,
|
|
579
|
+
o,
|
|
578
580
|
u,
|
|
579
581
|
r
|
|
580
|
-
),
|
|
581
|
-
this.helpers.range(u,
|
|
582
|
-
(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)
|
|
583
585
|
);
|
|
584
586
|
return this.helpers.flatMap(
|
|
585
587
|
[h, ...g],
|
|
@@ -632,28 +634,28 @@ class ue {
|
|
|
632
634
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
633
635
|
}
|
|
634
636
|
_insertRelations(e, t, s, r) {
|
|
635
|
-
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)));
|
|
636
638
|
}
|
|
637
639
|
iterateTree(e, t, s) {
|
|
638
|
-
const r = (
|
|
639
|
-
if (
|
|
640
|
-
if (
|
|
641
|
-
for (let
|
|
642
|
-
r(i
|
|
643
|
-
else if (
|
|
644
|
-
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)
|
|
645
647
|
return;
|
|
646
|
-
for (const
|
|
647
|
-
(
|
|
648
|
-
i,
|
|
648
|
+
for (const i in o)
|
|
649
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(
|
|
649
650
|
o,
|
|
651
|
+
i,
|
|
650
652
|
t,
|
|
651
653
|
s
|
|
652
654
|
), this._insertLinks(
|
|
653
|
-
i,
|
|
654
655
|
o,
|
|
656
|
+
i,
|
|
655
657
|
s
|
|
656
|
-
)), r(i
|
|
658
|
+
)), r(o[i]);
|
|
657
659
|
}
|
|
658
660
|
}
|
|
659
661
|
};
|
|
@@ -662,17 +664,17 @@ class ue {
|
|
|
662
664
|
async resolveLinks(e, t, s) {
|
|
663
665
|
let r = [];
|
|
664
666
|
if (e.link_uuids) {
|
|
665
|
-
const
|
|
666
|
-
for (let a = 0; a <
|
|
667
|
-
const u = Math.min(
|
|
668
|
-
|
|
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));
|
|
669
671
|
}
|
|
670
|
-
for (let a = 0; a <
|
|
672
|
+
for (let a = 0; a < i.length; a++)
|
|
671
673
|
(await this.getStories({
|
|
672
674
|
per_page: l,
|
|
673
675
|
language: t.language,
|
|
674
676
|
version: t.version,
|
|
675
|
-
by_uuids:
|
|
677
|
+
by_uuids: i[a].join(",")
|
|
676
678
|
})).data.stories.forEach(
|
|
677
679
|
(u) => {
|
|
678
680
|
r.push(u);
|
|
@@ -680,9 +682,9 @@ class ue {
|
|
|
680
682
|
);
|
|
681
683
|
} else
|
|
682
684
|
r = e.links;
|
|
683
|
-
r.forEach((
|
|
684
|
-
this.links[s][
|
|
685
|
-
...
|
|
685
|
+
r.forEach((o) => {
|
|
686
|
+
this.links[s][o.uuid] = {
|
|
687
|
+
...o,
|
|
686
688
|
_stopResolving: !0
|
|
687
689
|
};
|
|
688
690
|
});
|
|
@@ -690,26 +692,26 @@ class ue {
|
|
|
690
692
|
async resolveRelations(e, t, s) {
|
|
691
693
|
let r = [];
|
|
692
694
|
if (e.rel_uuids) {
|
|
693
|
-
const
|
|
694
|
-
for (let a = 0; a <
|
|
695
|
-
const u = Math.min(
|
|
696
|
-
|
|
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));
|
|
697
699
|
}
|
|
698
|
-
for (let a = 0; a <
|
|
700
|
+
for (let a = 0; a < i.length; a++)
|
|
699
701
|
(await this.getStories({
|
|
700
702
|
per_page: l,
|
|
701
703
|
language: t.language,
|
|
702
704
|
version: t.version,
|
|
703
|
-
by_uuids:
|
|
705
|
+
by_uuids: i[a].join(","),
|
|
704
706
|
excluding_fields: t.excluding_fields
|
|
705
707
|
})).data.stories.forEach((u) => {
|
|
706
708
|
r.push(u);
|
|
707
709
|
});
|
|
708
710
|
} else
|
|
709
711
|
r = e.rels;
|
|
710
|
-
r && r.length > 0 && r.forEach((
|
|
711
|
-
this.relations[s][
|
|
712
|
-
...
|
|
712
|
+
r && r.length > 0 && r.forEach((o) => {
|
|
713
|
+
this.relations[s][o.uuid] = {
|
|
714
|
+
...o,
|
|
713
715
|
_stopResolving: !0
|
|
714
716
|
};
|
|
715
717
|
});
|
|
@@ -724,23 +726,23 @@ class ue {
|
|
|
724
726
|
*
|
|
725
727
|
*/
|
|
726
728
|
async resolveStories(e, t, s) {
|
|
727
|
-
var r,
|
|
728
|
-
let
|
|
729
|
-
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)
|
|
730
732
|
for (const l in this.relations[s])
|
|
731
733
|
this.iterateTree(
|
|
732
734
|
this.relations[s][l],
|
|
733
|
-
|
|
735
|
+
i,
|
|
734
736
|
s
|
|
735
737
|
);
|
|
736
|
-
e.story ? this.iterateTree(e.story,
|
|
737
|
-
this.iterateTree(l,
|
|
738
|
+
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
|
|
739
|
+
this.iterateTree(l, i, s);
|
|
738
740
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
739
741
|
}
|
|
740
742
|
async cacheResponse(e, t, s, r) {
|
|
741
|
-
const
|
|
743
|
+
const o = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
742
744
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
743
|
-
const l = await
|
|
745
|
+
const l = await i.get(o);
|
|
744
746
|
if (l)
|
|
745
747
|
return Promise.resolve(l);
|
|
746
748
|
}
|
|
@@ -750,15 +752,15 @@ class ue {
|
|
|
750
752
|
const h = await this.throttle("get", e, t, r);
|
|
751
753
|
if (h.status !== 200)
|
|
752
754
|
return a(h);
|
|
753
|
-
let
|
|
754
|
-
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, {
|
|
755
757
|
perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
|
|
756
758
|
total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
|
|
757
|
-
})),
|
|
759
|
+
})), d.data.story || d.data.stories) {
|
|
758
760
|
const g = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
759
|
-
await this.resolveStories(
|
|
761
|
+
await this.resolveStories(d.data, t, `${g}`);
|
|
760
762
|
}
|
|
761
|
-
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);
|
|
762
764
|
} catch (h) {
|
|
763
765
|
if (h.response && h.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
764
766
|
return console.log(
|
|
@@ -823,7 +825,7 @@ class ue {
|
|
|
823
825
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
824
826
|
}
|
|
825
827
|
}
|
|
826
|
-
const
|
|
828
|
+
const pe = (n = {}) => {
|
|
827
829
|
const { apiOptions: e } = n;
|
|
828
830
|
if (!e.accessToken) {
|
|
829
831
|
console.error(
|
|
@@ -847,20 +849,20 @@ const de = (n = {}) => {
|
|
|
847
849
|
return {};
|
|
848
850
|
}
|
|
849
851
|
};
|
|
850
|
-
let R,
|
|
852
|
+
let R, T = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
851
853
|
const fe = (n, e, t = {}) => {
|
|
852
854
|
var s;
|
|
853
|
-
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(
|
|
854
856
|
"_storyblok"
|
|
855
857
|
) === n;
|
|
856
|
-
if (!(!r || !
|
|
858
|
+
if (!(!r || !o)) {
|
|
857
859
|
if (!n) {
|
|
858
860
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
859
861
|
return;
|
|
860
862
|
}
|
|
861
863
|
window.storyblokRegisterEvent(() => {
|
|
862
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
863
|
-
|
|
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();
|
|
864
866
|
});
|
|
865
867
|
});
|
|
866
868
|
}
|
|
@@ -869,19 +871,19 @@ const fe = (n, e, t = {}) => {
|
|
|
869
871
|
const {
|
|
870
872
|
bridge: s,
|
|
871
873
|
accessToken: r,
|
|
872
|
-
use:
|
|
873
|
-
apiOptions:
|
|
874
|
+
use: o = [],
|
|
875
|
+
apiOptions: i = {},
|
|
874
876
|
richText: l = {},
|
|
875
877
|
bridgeUrl: a
|
|
876
878
|
} = n;
|
|
877
|
-
|
|
878
|
-
const u = { bridge: s, apiOptions:
|
|
879
|
+
i.accessToken = i.accessToken || r;
|
|
880
|
+
const u = { bridge: s, apiOptions: i };
|
|
879
881
|
let h = {};
|
|
880
|
-
|
|
882
|
+
o.forEach((g) => {
|
|
881
883
|
h = { ...h, ...g(u) };
|
|
882
|
-
}), a && (
|
|
883
|
-
const
|
|
884
|
-
return s !== !1 &&
|
|
884
|
+
}), a && (T = a);
|
|
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;
|
|
885
887
|
}, E = (n, e) => {
|
|
886
888
|
n.addNode("blok", (t) => {
|
|
887
889
|
let s = "";
|
|
@@ -891,7 +893,7 @@ const fe = (n, e, t = {}) => {
|
|
|
891
893
|
html: s
|
|
892
894
|
};
|
|
893
895
|
});
|
|
894
|
-
},
|
|
896
|
+
}, de = (n) => !n || !(n != null && n.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ye = (n, e, t) => {
|
|
895
897
|
let s = t || R;
|
|
896
898
|
if (!s) {
|
|
897
899
|
console.error(
|
|
@@ -899,13 +901,13 @@ const fe = (n, e, t = {}) => {
|
|
|
899
901
|
);
|
|
900
902
|
return;
|
|
901
903
|
}
|
|
902
|
-
return
|
|
903
|
-
}, be = () => O(
|
|
904
|
+
return de(n) ? "" : (e && (s = new v(e.schema), e.resolver && E(s, e.resolver)), s.render(n));
|
|
905
|
+
}, be = () => O(T);
|
|
904
906
|
export {
|
|
905
907
|
v as RichTextResolver,
|
|
906
908
|
ne as RichTextSchema,
|
|
907
|
-
|
|
908
|
-
|
|
909
|
+
pe as apiPlugin,
|
|
910
|
+
de as isRichTextEmpty,
|
|
909
911
|
be as loadStoryblokBridge,
|
|
910
912
|
fe as registerStoryblokBridge,
|
|
911
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",
|