@storyblok/react 2.4.6 → 2.4.8
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/README.md +2 -2
- package/dist/client.js +1 -1
- package/dist/client.mjs +15 -14
- package/dist/index.js +1 -1
- package/dist/index.mjs +18 -18
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +40 -39
- package/dist/types/common/index.d.ts +2 -2
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -560,7 +560,7 @@ import cloneDeep from "clone-deep";
|
|
|
560
560
|
|
|
561
561
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
562
562
|
// ... and edit the nodes and marks, or add your own.
|
|
563
|
-
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/
|
|
563
|
+
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/main/src/schema.ts
|
|
564
564
|
|
|
565
565
|
storyblokInit({
|
|
566
566
|
accessToken: "<your-token>",
|
|
@@ -625,5 +625,5 @@ By default, `@storyblok/react` returns an empty `<div>` if a component is not im
|
|
|
625
625
|
|
|
626
626
|
### Contributing
|
|
627
627
|
|
|
628
|
-
Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/
|
|
628
|
+
Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and our [code of conduct](https://www.storyblok.com/trust-center#code-of-conduct?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react).
|
|
629
629
|
This project use [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check [this question](https://semantic-release.gitbook.io/semantic-release/support/faq#how-can-i-change-the-type-of-commits-that-trigger-a-release) about it in semantic-release FAQ.
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=require("./storyblok-js.js"),f=(e=null,n={})=>{let[t,o]=s.useState(e);const r=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return s.useEffect(()=>{if(!r||!e)return;const u=t.internalId||t.id;o(e),c.registerStoryblokBridge(u,d=>o(d),n)},[e,r,t]),!r||!e?e:t};exports.useStoryblokState=f;
|
package/dist/client.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
const
|
|
4
|
-
let [t,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
o
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
import { registerStoryblokBridge as p } from "./storyblok-js.mjs";
|
|
3
|
+
const g = (e = null, s = {}) => {
|
|
4
|
+
let [t, o] = f(e);
|
|
5
|
+
const r = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
|
|
6
|
+
return u(() => {
|
|
7
|
+
if (!r || !e)
|
|
8
|
+
return;
|
|
9
|
+
const d = t.internalId || t.id;
|
|
10
|
+
o(e), p(
|
|
11
|
+
d,
|
|
12
|
+
(n) => o(n),
|
|
13
|
+
s
|
|
13
14
|
);
|
|
14
|
-
}, [e]), t;
|
|
15
|
+
}, [e, r, t]), !r || !e ? e : t;
|
|
15
16
|
};
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
+
g as useStoryblokState
|
|
18
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./client.js"),S=require("./storyblok-component.js"),d=(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./client.js"),S=require("./storyblok-component.js"),d=(s,r={},t={})=>{let[a,i]=y.useState({});const u=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u",n=o.useStoryblokApi();return y.useEffect(()=>{if(!n){console.error("You can't use useStoryblok if you're not loading apiPlugin.");return}async function b(){const{data:l}=await n.get(`cdn/stories/${s}`,r);i(l.story),u&&l.story.id&&e.registerStoryblokBridge(l.story.id,k=>i(k),t)}b()},[s,JSON.stringify(r),n]),n?(t.resolveRelations=t.resolveRelations??r.resolve_relations,t.resolveLinks=t.resolveLinks??r.resolve_links,a):null};exports.RichTextResolver=e.RichTextResolver;exports.RichTextSchema=e.RichTextSchema;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;exports.getComponent=o.getComponent;exports.getCustomFallbackComponent=o.getCustomFallbackComponent;exports.getEnableFallbackComponent=o.getEnableFallbackComponent;exports.getStoryblokApi=o.useStoryblokApi;exports.setComponents=o.setComponents;exports.storyblokInit=o.storyblokInit;exports.useStoryblokApi=o.useStoryblokApi;exports.useStoryblokState=c.useStoryblokState;exports.StoryblokComponent=S;exports.useStoryblok=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { useState as f, useEffect as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
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
6
|
import { useStoryblokState as P } from "./client.mjs";
|
|
7
7
|
import { default as J } from "./storyblok-component.mjs";
|
|
8
|
-
const b = (
|
|
9
|
-
const s = c();
|
|
10
|
-
if (!s)
|
|
11
|
-
return console.error(
|
|
12
|
-
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
13
|
-
), null;
|
|
8
|
+
const b = (s, e = {}, o = {}) => {
|
|
14
9
|
let [l, n] = f({});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u", t = c();
|
|
11
|
+
return u(() => {
|
|
12
|
+
if (!t) {
|
|
13
|
+
console.error(
|
|
14
|
+
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
18
|
async function a() {
|
|
19
|
-
const { data:
|
|
20
|
-
`cdn/stories/${
|
|
19
|
+
const { data: r } = await t.get(
|
|
20
|
+
`cdn/stories/${s}`,
|
|
21
21
|
e
|
|
22
22
|
);
|
|
23
|
-
n(
|
|
24
|
-
|
|
23
|
+
n(r.story), i && r.story.id && k(
|
|
24
|
+
r.story.id,
|
|
25
25
|
(y) => n(y),
|
|
26
26
|
o
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
a();
|
|
30
|
-
}, [
|
|
30
|
+
}, [s, JSON.stringify(e), t]), t ? (o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links, l) : null;
|
|
31
31
|
};
|
|
32
32
|
export {
|
|
33
33
|
v as RichTextResolver,
|
|
@@ -39,13 +39,13 @@ export {
|
|
|
39
39
|
T as getEnableFallbackComponent,
|
|
40
40
|
c as getStoryblokApi,
|
|
41
41
|
C as loadStoryblokBridge,
|
|
42
|
-
|
|
42
|
+
k as registerStoryblokBridge,
|
|
43
43
|
w as renderRichText,
|
|
44
44
|
F as setComponents,
|
|
45
45
|
B as storyblokEditable,
|
|
46
46
|
I as storyblokInit,
|
|
47
47
|
b as useStoryblok,
|
|
48
48
|
c as useStoryblokApi,
|
|
49
|
-
|
|
49
|
+
k as useStoryblokBridge,
|
|
50
50
|
P 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
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let _=!1;const j=[],S=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}_?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(o=>o()),_=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var A=Object.defineProperty,N=(i,e,t)=>e in i?A(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,h=(i,e,t)=>(N(i,typeof e!="symbol"?e+"":e,t),t);function x(i){return!(i!==i||i===1/0||i===-1/0)}function M(i,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 n=function(){o++;const a=setTimeout(function(){o--,s.length>0&&n(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(i.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,p){s.push({resolve:u,reject:p,args:a,self:l}),o<e&&n()})};return c.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},c}class b{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,n)=>n*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(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 n=e[o],c=s?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return r;default:return t}}}const L=function(i,e){const t={};for(const s in i){const r=i[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},z=i=>i==="email",U=()=>({singleTag:"hr"}),H=()=>({tag:"blockquote"}),q=()=>({tag:"ul"}),B=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),V=()=>({singleTag:"br"}),J=i=>({tag:`h${i.attrs.level}`}),D=i=>({singleTag:[{tag:"img",attrs:L(i.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),Y=()=>({tag:"ol"}),K=()=>({tag:"p"}),W=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),G=()=>({tag:"b"}),Q=()=>({tag:"strike"}),X=()=>({tag:"u"}),Z=()=>({tag:"strong"}),ee=()=>({tag:"code"}),te=()=>({tag:"i"}),se=i=>{const e=new b().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(t.href&&(t.href=e(i.attrs.href||"")),z(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=i=>({tag:[{tag:"span",attrs:i.attrs}]}),oe=()=>({tag:"sub"}),ne=()=>({tag:"sup"}),ie=i=>({tag:[{tag:"span",attrs:i.attrs}]}),ae=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},le=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},P={nodes:{horizontal_rule:U,blockquote:H,bullet_list:q,code_block:B,hard_break:V,heading:J,image:D,list_item:F,ordered_list:Y,paragraph:K,emoji:W},marks:{bold:G,strike:Q,underline:X,strong:Z,code:ee,italic:te,link:se,styled:re,subscript:oe,superscript:ne,anchor:ie,highlight:ae,textStyle:le}},ce=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};class m{constructor(e){h(this,"marks"),h(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(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,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const d={srcset:(l=t.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${p}/m/${g}x0${n} ${g}w`;if(typeof g=="object"&&g.length===2){let v=0,T=0;return typeof g[0]=="number"&&(v=g[0]),typeof g[1]=="number"&&(T=g[1]),`//${p}/m/${v}x${T}${n} ${v}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(g=>g).join(", ")};let k="";return d.srcset&&(k+=`srcset="${d.srcset}" `),d.sizes&&(k+=`sizes="${d.sizes}" `),a.replace(/<img/g,`<img ${k.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){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class he{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),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={}}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 b;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const x="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let y={};const f={};class ue{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const n=new b().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(x)||(r.set(x,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 m(e.richTextSchema):this.richTextResolver=new m,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=M(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.client=new he({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.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,n=o.split("/"),c=s||n[n.length-1],a=1,l=await this.makeRequest(o,t,r,a),u=l.total?Math.ceil(l.total/r):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),d=>this.makeRequest(o,t,r,d+1));return this.helpers.flatMap([l,...p],d=>Object.values(d.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_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]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const o=[];e[t].forEach(n=>{this.relations[r][n]&&o.push(this._cleanCopy(this.relations[r][n]))}),e[t]=o}}}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(const n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t,s),this._insertLinks(o,n,s)),r(o[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].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 c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=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 n=await o.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&f[t.token]!=u.data.cv&&await this.flushCache(),f[t.token]=u.data.cv),n(u)}catch(l){if(l.response&&l.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l.message)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},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}}const pe=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ue(e)}},ge=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $;const P="https://app.storyblok.com/f/storyblok-v2-latest.js",I=(i,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")===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===i?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===i&&window.location.reload()})})}},de=(i={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:n={},richText:c={}}=i;n.accessToken=n.accessToken||r;const a={bridge:s,apiOptions:n};let l={};o.forEach(p=>{l={...l,...p(a)}});const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&u&&E(P),$=new m(c.schema),c.resolver&&O($,c.resolver),l},O=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},C=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),fe=(i,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(i)?"":(e&&(s=new m(e.schema),e.resolver&&O(s,e.resolver)),s.render(i))},me=()=>E(P);exports.RichTextResolver=m;exports.RichTextSchema=S;exports.apiPlugin=pe;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=me;exports.registerStoryblokBridge=I;exports.renderRichText=fe;exports.storyblokEditable=ge;exports.storyblokInit=de;exports.useStoryblokBridge=I;
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(d=>{if(typeof d=="number")return`//${p}/m/${d}x0${n} ${d}w`;if(typeof d=="object"&&d.length===2){let v=0,R=0;return typeof d[0]=="number"&&(v=d[0]),typeof d[1]=="number"&&(R=d[1]),`//${p}/m/${v}x${R}${n} ${v}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(d=>d).join(", ")};let k="";return g.srcset&&(k+=`srcset="${g.srcset}" `),g.sizes&&(k+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${k.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){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class he{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),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={}}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 b;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const E="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let y={};const f={};class ue{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const n=new b().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(E)||(r.set(E,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 m(e.richTextSchema):this.richTextResolver=new m,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=M(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.client=new he({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.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,n=o.split("/"),c=s||n[n.length-1],a=1,l=await this.makeRequest(o,t,r,a),u=l.total?Math.ceil(l.total/r):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),g=>this.makeRequest(o,t,r,g+1));return this.helpers.flatMap([l,...p],g=>Object.values(g.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_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]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const o=[];e[t].forEach(n=>{this.relations[r][n]&&o.push(this._cleanCopy(this.relations[r][n]))}),e[t]=o}}}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(const n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t,s),this._insertLinks(o,n,s)),r(o[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].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 c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=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 n=await o.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&f[t.token]!=u.data.cv&&await this.flushCache(),f[t.token]=u.data.cv),n(u)}catch(l){if(l.response&&l.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l.message)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},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}}const pe=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ue(e)}},de=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $,T="https://app.storyblok.com/f/storyblok-v2-latest.js";const I=(i,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")===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===i?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===i&&window.location.reload()})})}},ge=(i={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:n={},richText:c={},bridgeUrl:a}=i;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let u={};o.forEach(g=>{u={...u,...g(l)}}),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&&S(T),$=new m(c.schema),c.resolver&&O($,c.resolver),u},O=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},C=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),fe=(i,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(i)?"":(e&&(s=new m(e.schema),e.resolver&&O(s,e.resolver)),s.render(i))},me=()=>S(T);exports.RichTextResolver=m;exports.RichTextSchema=P;exports.apiPlugin=pe;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=me;exports.registerStoryblokBridge=I;exports.renderRichText=fe;exports.storyblokEditable=de;exports.storyblokInit=ge;exports.useStoryblokBridge=I;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
1
|
+
let _ = !1;
|
|
2
|
+
const j = [], P = (i) => new Promise((e, t) => {
|
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
4
4
|
if (window.location === window.parent.location) {
|
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
_ ? r() : j.push(r);
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
10
10
|
return;
|
|
11
11
|
const s = document.createElement("script");
|
|
12
12
|
s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
13
|
-
|
|
13
|
+
j.forEach((o) => o()), _ = !0, e(r);
|
|
14
14
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
15
15
|
});
|
|
16
16
|
var I = Object.defineProperty, O = (i, e, t) => e in i ? I(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (O(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
17
|
-
function
|
|
17
|
+
function x(i) {
|
|
18
18
|
return !(i !== i || i === 1 / 0 || i === -1 / 0);
|
|
19
19
|
}
|
|
20
20
|
function C(i, e, t) {
|
|
21
|
-
if (!
|
|
21
|
+
if (!x(e))
|
|
22
22
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
23
|
-
if (!
|
|
23
|
+
if (!x(t))
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const s = [];
|
|
26
26
|
let r = [], o = 0;
|
|
@@ -125,7 +125,7 @@ const A = function(i, e) {
|
|
|
125
125
|
tag: "blockquote"
|
|
126
126
|
}), z = () => ({
|
|
127
127
|
tag: "ul"
|
|
128
|
-
}),
|
|
128
|
+
}), U = (i) => ({
|
|
129
129
|
tag: [
|
|
130
130
|
"pre",
|
|
131
131
|
{
|
|
@@ -133,7 +133,7 @@ const A = function(i, e) {
|
|
|
133
133
|
attrs: i.attrs
|
|
134
134
|
}
|
|
135
135
|
]
|
|
136
|
-
}),
|
|
136
|
+
}), H = () => ({
|
|
137
137
|
singleTag: "br"
|
|
138
138
|
}), q = (i) => ({
|
|
139
139
|
tag: `h${i.attrs.level}`
|
|
@@ -239,8 +239,8 @@ const A = function(i, e) {
|
|
|
239
239
|
horizontal_rule: M,
|
|
240
240
|
blockquote: L,
|
|
241
241
|
bullet_list: z,
|
|
242
|
-
code_block:
|
|
243
|
-
hard_break:
|
|
242
|
+
code_block: U,
|
|
243
|
+
hard_break: H,
|
|
244
244
|
heading: q,
|
|
245
245
|
image: B,
|
|
246
246
|
list_item: V,
|
|
@@ -330,19 +330,19 @@ class b {
|
|
|
330
330
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
331
331
|
);
|
|
332
332
|
if (p && p.length > 0) {
|
|
333
|
-
const
|
|
334
|
-
srcset: (l = t.srcset) == null ? void 0 : l.map((
|
|
335
|
-
if (typeof
|
|
336
|
-
return `//${p}/m/${
|
|
337
|
-
if (typeof
|
|
338
|
-
let v = 0,
|
|
339
|
-
return typeof
|
|
333
|
+
const g = {
|
|
334
|
+
srcset: (l = t.srcset) == null ? void 0 : l.map((d) => {
|
|
335
|
+
if (typeof d == "number")
|
|
336
|
+
return `//${p}/m/${d}x0${n} ${d}w`;
|
|
337
|
+
if (typeof d == "object" && d.length === 2) {
|
|
338
|
+
let v = 0, R = 0;
|
|
339
|
+
return typeof d[0] == "number" && (v = d[0]), typeof d[1] == "number" && (R = d[1]), `//${p}/m/${v}x${R}${n} ${v}w`;
|
|
340
340
|
}
|
|
341
341
|
}).join(", "),
|
|
342
|
-
sizes: (u = t.sizes) == null ? void 0 : u.map((
|
|
342
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
343
343
|
};
|
|
344
344
|
let k = "";
|
|
345
|
-
return
|
|
345
|
+
return g.srcset && (k += `srcset="${g.srcset}" `), g.sizes && (k += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
|
|
346
346
|
}
|
|
347
347
|
return a;
|
|
348
348
|
})), e;
|
|
@@ -490,7 +490,7 @@ class le {
|
|
|
490
490
|
});
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
|
-
const
|
|
493
|
+
const E = "SB-Agent", w = {
|
|
494
494
|
defaultAgentName: "SB-JS-CLIENT",
|
|
495
495
|
defaultAgentVersion: "SB-Agent-Version",
|
|
496
496
|
packageVersion: "5.14.2"
|
|
@@ -514,7 +514,7 @@ class ce {
|
|
|
514
514
|
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
|
|
515
515
|
for (const n in e.headers)
|
|
516
516
|
r.set(n, e.headers[n]);
|
|
517
|
-
r.has(
|
|
517
|
+
r.has(E) || (r.set(E, w.defaultAgentName), r.set(
|
|
518
518
|
w.defaultAgentVersion,
|
|
519
519
|
w.packageVersion
|
|
520
520
|
));
|
|
@@ -558,11 +558,11 @@ class ce {
|
|
|
558
558
|
async getAll(e, t, s) {
|
|
559
559
|
const r = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, n = o.split("/"), c = s || n[n.length - 1], a = 1, l = await this.makeRequest(o, t, r, a), u = l.total ? Math.ceil(l.total / r) : 1, p = await this.helpers.asyncMap(
|
|
560
560
|
this.helpers.range(a, u),
|
|
561
|
-
(
|
|
561
|
+
(g) => this.makeRequest(o, t, r, g + 1)
|
|
562
562
|
);
|
|
563
563
|
return this.helpers.flatMap(
|
|
564
564
|
[l, ...p],
|
|
565
|
-
(
|
|
565
|
+
(g) => Object.values(g.data[c])
|
|
566
566
|
);
|
|
567
567
|
}
|
|
568
568
|
post(e, t) {
|
|
@@ -806,8 +806,8 @@ const ue = (i = {}) => {
|
|
|
806
806
|
"data-blok-uid": e.id + "-" + e.uid
|
|
807
807
|
} : {};
|
|
808
808
|
};
|
|
809
|
-
let
|
|
810
|
-
const
|
|
809
|
+
let $, T = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
810
|
+
const de = (i, e, t = {}) => {
|
|
811
811
|
var s;
|
|
812
812
|
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
813
813
|
"_storyblok"
|
|
@@ -823,23 +823,24 @@ const P = "https://app.storyblok.com/f/storyblok-v2-latest.js", ge = (i, e, t =
|
|
|
823
823
|
});
|
|
824
824
|
});
|
|
825
825
|
}
|
|
826
|
-
},
|
|
826
|
+
}, ge = (i = {}) => {
|
|
827
827
|
var e, t;
|
|
828
828
|
const {
|
|
829
829
|
bridge: s,
|
|
830
830
|
accessToken: r,
|
|
831
831
|
use: o = [],
|
|
832
832
|
apiOptions: n = {},
|
|
833
|
-
richText: c = {}
|
|
833
|
+
richText: c = {},
|
|
834
|
+
bridgeUrl: a
|
|
834
835
|
} = i;
|
|
835
836
|
n.accessToken = n.accessToken || r;
|
|
836
|
-
const
|
|
837
|
-
let
|
|
838
|
-
o.forEach((
|
|
839
|
-
|
|
840
|
-
});
|
|
841
|
-
const
|
|
842
|
-
return s !== !1 &&
|
|
837
|
+
const l = { bridge: s, apiOptions: n };
|
|
838
|
+
let u = {};
|
|
839
|
+
o.forEach((g) => {
|
|
840
|
+
u = { ...u, ...g(l) };
|
|
841
|
+
}), a && (T = a);
|
|
842
|
+
const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
843
|
+
return s !== !1 && p && P(T), $ = new b(c.schema), c.resolver && S($, c.resolver), u;
|
|
843
844
|
}, S = (i, e) => {
|
|
844
845
|
i.addNode("blok", (t) => {
|
|
845
846
|
let s = "";
|
|
@@ -858,16 +859,16 @@ const P = "https://app.storyblok.com/f/storyblok-v2-latest.js", ge = (i, e, t =
|
|
|
858
859
|
return;
|
|
859
860
|
}
|
|
860
861
|
return he(i) ? "" : (e && (s = new b(e.schema), e.resolver && S(s, e.resolver)), s.render(i));
|
|
861
|
-
}, me = () =>
|
|
862
|
+
}, me = () => P(T);
|
|
862
863
|
export {
|
|
863
864
|
b as RichTextResolver,
|
|
864
865
|
ie as RichTextSchema,
|
|
865
866
|
ue as apiPlugin,
|
|
866
867
|
he as isRichTextEmpty,
|
|
867
868
|
me as loadStoryblokBridge,
|
|
868
|
-
|
|
869
|
+
de as registerStoryblokBridge,
|
|
869
870
|
fe as renderRichText,
|
|
870
871
|
pe as storyblokEditable,
|
|
871
|
-
|
|
872
|
-
|
|
872
|
+
ge as storyblokInit,
|
|
873
|
+
de as useStoryblokBridge
|
|
873
874
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { SbReactComponentsMap, SbReactSDKOptions, StoryblokClient } from "../types";
|
|
3
3
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
4
|
export declare const setComponents: (newComponentsMap: SbReactComponentsMap) => SbReactComponentsMap;
|
|
5
|
-
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any>;
|
|
5
|
+
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
|
|
6
6
|
export declare const getEnableFallbackComponent: () => boolean;
|
|
7
|
-
export declare const getCustomFallbackComponent: () => import("react").ElementType<any>;
|
|
7
|
+
export declare const getCustomFallbackComponent: () => import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
|
|
8
8
|
export declare const storyblokInit: (pluginOptions?: SbReactSDKOptions) => void;
|
|
9
9
|
export { default as StoryblokComponent } from "./storyblok-component";
|
|
10
10
|
export { useStoryblokApi as getStoryblokApi };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8",
|
|
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,26 +44,26 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "^2.
|
|
47
|
+
"@storyblok/js": "^2.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "^7.
|
|
51
|
-
"@babel/preset-env": "^7.
|
|
52
|
-
"@cypress/react": "^
|
|
53
|
-
"@cypress/vite-dev-server": "^
|
|
54
|
-
"@tsconfig/recommended": "^1.0.
|
|
55
|
-
"@types/react": "18.2.
|
|
56
|
-
"@vitejs/plugin-react": "^4.
|
|
57
|
-
"babel-jest": "^29.
|
|
58
|
-
"cypress": "^
|
|
59
|
-
"eslint-plugin-cypress": "^2.
|
|
60
|
-
"eslint-plugin-jest": "^27.
|
|
61
|
-
"jest": "^29.
|
|
50
|
+
"@babel/core": "^7.23.6",
|
|
51
|
+
"@babel/preset-env": "^7.23.6",
|
|
52
|
+
"@cypress/react": "^8.0.0",
|
|
53
|
+
"@cypress/vite-dev-server": "^5.0.6",
|
|
54
|
+
"@tsconfig/recommended": "^1.0.3",
|
|
55
|
+
"@types/react": "18.2.45",
|
|
56
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
57
|
+
"babel-jest": "^29.7.0",
|
|
58
|
+
"cypress": "^13.6.1",
|
|
59
|
+
"eslint-plugin-cypress": "^2.15.1",
|
|
60
|
+
"eslint-plugin-jest": "^27.6.0",
|
|
61
|
+
"jest": "^29.7.0",
|
|
62
62
|
"react": "^18.2.0",
|
|
63
63
|
"react-dom": "^18.2.0",
|
|
64
64
|
"rollup-plugin-preserve-directives": "^0.2.0",
|
|
65
|
-
"start-server-and-test": "^2.0.
|
|
66
|
-
"vite": "^
|
|
65
|
+
"start-server-and-test": "^2.0.3",
|
|
66
|
+
"vite": "^5.0.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": "^17.0.0 || ^18.0.0",
|