@storyblok/react 2.1.3 → 2.1.4
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/{client-16ee9ae1.mjs → client-7d136bb5.mjs} +1 -1
- package/dist/{client-6eb29fd9.js → client-9f00300c.js} +1 -1
- package/dist/{index-f1318b50.mjs → index-2fd0c215.mjs} +1 -1
- package/dist/{index-65ac33dd.js → index-fd3bb3fa.js} +1 -1
- package/dist/{storyblok-js-612aedc3.mjs → storyblok-js-06eb3096.mjs} +36 -26
- package/dist/storyblok-js-e9ec752f.js +1 -0
- package/dist/storyblok-react.js +1 -1
- package/dist/storyblok-react.mjs +5 -5
- package/dist/storyblok-react2.js +1 -1
- package/dist/storyblok-react2.mjs +2 -2
- package/dist/storyblok-react3.js +1 -1
- package/dist/storyblok-react3.mjs +1 -1
- package/dist/storyblok-react4.js +1 -1
- package/dist/storyblok-react4.mjs +3 -3
- package/package.json +2 -2
- package/dist/storyblok-js-a8758ae9.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
|
-
import { h as he } from "./storyblok-js-
|
|
2
|
+
import { h as he } from "./storyblok-js-06eb3096.mjs";
|
|
3
3
|
const useStoryblokState = (initialStory = null, bridgeOptions = {}) => {
|
|
4
4
|
let [story, setStory] = useState(initialStory);
|
|
5
5
|
const isBridgeEnable = typeof window !== "undefined" && typeof window.storyblokRegisterEvent !== "undefined";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react"),t=require("./storyblok-js-
|
|
1
|
+
"use strict";const e=require("react"),t=require("./storyblok-js-e9ec752f.js");exports.useStoryblokState=(r=null,o={})=>{let[s,i]=e.useState(r);return"undefined"!=typeof window&&void 0!==window.storyblokRegisterEvent&&r?(e.useEffect((()=>{i(r),t.he(s.id,(e=>i(e)),o)}),[r]),s):r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("./storyblok-js-
|
|
1
|
+
"use strict";const o=require("./storyblok-js-e9ec752f.js"),e=require("react"),t=e.forwardRef((({blok:o,...t},r)=>{if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),e.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=l(o.component);return n?e.createElement(n,{ref:r,blok:o,...t}):e.createElement("div",null)}));t.displayName="StoryblokComponent";let r=null,n={};const l=o=>n[o]?n[o]:(console.error(`Component ${o} doesn't exist.`),!1);exports.StoryblokComponent=t,exports.getComponent=l,exports.storyblokInit=(e={})=>{const{storyblokApi:t}=o.ue(e);r=t,n=e.components},exports.useStoryblokApi=()=>(r||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),r);
|
|
@@ -147,25 +147,35 @@ const C = function(n, e) {
|
|
|
147
147
|
attrs: n.attrs
|
|
148
148
|
}
|
|
149
149
|
]
|
|
150
|
-
}), se = (n) =>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
}), se = (n) => {
|
|
151
|
+
var e;
|
|
152
|
+
return (e = n.attrs) != null && e.color ? {
|
|
153
|
+
tag: [
|
|
154
|
+
{
|
|
155
|
+
tag: "span",
|
|
156
|
+
attrs: {
|
|
157
|
+
style: `background-color:${n.attrs.color};`
|
|
158
|
+
}
|
|
156
159
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
]
|
|
161
|
+
} : {
|
|
162
|
+
tag: ""
|
|
163
|
+
};
|
|
164
|
+
}, re = (n) => {
|
|
165
|
+
var e;
|
|
166
|
+
return (e = n.attrs) != null && e.color ? {
|
|
167
|
+
tag: [
|
|
168
|
+
{
|
|
169
|
+
tag: "span",
|
|
170
|
+
attrs: {
|
|
171
|
+
style: `color:${n.attrs.color}`
|
|
172
|
+
}
|
|
165
173
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
174
|
+
]
|
|
175
|
+
} : {
|
|
176
|
+
tag: ""
|
|
177
|
+
};
|
|
178
|
+
}, ie = {
|
|
169
179
|
nodes: {
|
|
170
180
|
horizontal_rule: A,
|
|
171
181
|
blockquote: N,
|
|
@@ -266,8 +276,8 @@ class y {
|
|
|
266
276
|
if (typeof p == "number")
|
|
267
277
|
return `//${d}/m/${p}x0${o} ${p}w`;
|
|
268
278
|
if (typeof p == "object" && p.length === 2) {
|
|
269
|
-
let
|
|
270
|
-
return typeof p[0] == "number" && (
|
|
279
|
+
let v = 0, $ = 0;
|
|
280
|
+
return typeof p[0] == "number" && (v = p[0]), typeof p[1] == "number" && ($ = p[1]), `//${d}/m/${v}x${$}${o} ${v}w`;
|
|
271
281
|
}
|
|
272
282
|
}).join(", "),
|
|
273
283
|
sizes: (u = t.sizes) == null ? void 0 : u.map((p) => p).join(", ")
|
|
@@ -282,14 +292,14 @@ class y {
|
|
|
282
292
|
const t = [];
|
|
283
293
|
e.marks && e.marks.forEach((r) => {
|
|
284
294
|
const i = this.getMatchingMark(r);
|
|
285
|
-
i && t.push(this.renderOpeningTag(i.tag));
|
|
295
|
+
i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
|
|
286
296
|
});
|
|
287
297
|
const s = this.getMatchingNode(e);
|
|
288
298
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
289
299
|
t.push(this.renderNode(r));
|
|
290
300
|
}) : e.text ? t.push(oe(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) => {
|
|
291
301
|
const i = this.getMatchingMark(r);
|
|
292
|
-
i && t.push(this.renderClosingTag(i.tag));
|
|
302
|
+
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
|
293
303
|
}), t.join("");
|
|
294
304
|
}
|
|
295
305
|
renderTag(e, t) {
|
|
@@ -340,7 +350,7 @@ class y {
|
|
|
340
350
|
return this.renderTag(t, " /");
|
|
341
351
|
}
|
|
342
352
|
}
|
|
343
|
-
class
|
|
353
|
+
class k {
|
|
344
354
|
constructor() {
|
|
345
355
|
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
|
346
356
|
...e,
|
|
@@ -429,7 +439,7 @@ class ne {
|
|
|
429
439
|
async _methodHandler(e) {
|
|
430
440
|
let t = `${this.baseURL}${this.url}`, s = null;
|
|
431
441
|
if (e === "get") {
|
|
432
|
-
const a = new
|
|
442
|
+
const a = new k();
|
|
433
443
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
|
434
444
|
this.parameters
|
|
435
445
|
)}`;
|
|
@@ -481,7 +491,7 @@ class ae {
|
|
|
481
491
|
*/
|
|
482
492
|
constructor(e, t) {
|
|
483
493
|
if (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"), !t) {
|
|
484
|
-
const i = new
|
|
494
|
+
const i = new k().getRegionURL, o = e.https === false ? "http" : "https";
|
|
485
495
|
e.oauthToken ? t = `${o}://${i(e.region)}/v1` : t = `${o}://${i(e.region)}/v2`;
|
|
486
496
|
}
|
|
487
497
|
const s = new Headers();
|
|
@@ -489,7 +499,7 @@ class ae {
|
|
|
489
499
|
e.headers && e.headers[o] && s.set(o, e.headers[o]);
|
|
490
500
|
});
|
|
491
501
|
let r = 5;
|
|
492
|
-
e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new y(e.richTextSchema) : this.richTextResolver = new y(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = S(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new
|
|
502
|
+
e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new y(e.richTextSchema) : this.richTextResolver = new y(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = S(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new k(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || true, this.client = new ne({
|
|
493
503
|
baseURL: t,
|
|
494
504
|
timeout: e.timeout || 0,
|
|
495
505
|
headers: s,
|
|
@@ -500,7 +510,7 @@ class ae {
|
|
|
500
510
|
setComponentResolver(e) {
|
|
501
511
|
this.richTextResolver.addNode("blok", (t) => {
|
|
502
512
|
let s = "";
|
|
503
|
-
return t.attrs.body.forEach((r) => {
|
|
513
|
+
return t.attrs.body && t.attrs.body.forEach((r) => {
|
|
504
514
|
s += e(r.component, r);
|
|
505
515
|
}), {
|
|
506
516
|
html: s
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";let t=!1;const e=[],s=s=>new Promise(((r,o)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{window.location!==window.parent.location?t?s():e.push(s):console.warn("You are not in Draft Mode or in the Visual Editor.")},document.getElementById("storyblok-javascript-bridge")))return;const i=document.createElement("script");i.async=!0,i.src=s,i.id="storyblok-javascript-bridge",i.onerror=t=>o(t),i.onload=s=>{e.forEach((t=>t())),t=!0,r(s)},document.getElementsByTagName("head")[0].appendChild(i)}));var r=Object.defineProperty,o=(t,e,s)=>(((t,e,s)=>{e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s);function i(t){return!(t!=t||t===1/0||t===-1/0)}const n=function(t,e){const s={};for(const r in t){const o=t[r];e.indexOf(r)>-1&&null!==o&&(s[r]=o)}return s},a={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:t=>({tag:`h${t.attrs.level}`}),image:t=>({singleTag:[{tag:"img",attrs:n(t.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:t=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":t.attrs.name,emoji:t.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:t=>{const e={...t.attrs},{linktype:s="url"}=t.attrs;if((t=>"email"===t)(s)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const t in e.custom)e[t]=e.custom[t];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},styled:t=>({tag:[{tag:"span",attrs:t.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:t=>({tag:[{tag:"span",attrs:t.attrs}]}),highlight:t=>{var e;return null!=(e=t.attrs)&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${t.attrs.color};`}}]}:{tag:""}},textStyle:t=>{var e;return null!=(e=t.attrs)&&e.color?{tag:[{tag:"span",attrs:{style:`color:${t.attrs.color}`}}]}:{tag:""}}}};class l{constructor(t){o(this,"marks"),o(this,"nodes"),t||(t=a),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach((t=>{s+=this.renderNode(t)})),e.optimizeImages?this.optimizeImages(s,e.optimizeImages):s}return console.warn("The render method must receive an Object with a \"content\" field.\n\t\t\tThe \"content\" field must be an array of nodes as the type ISbRichtext.\n\t\t\tISbRichtext:\n\t\t\t\tcontent?: ISbRichtext[]\n\t\t\t\tmarks?: ISbRichtext[]\n\t\t\t\tattrs?: any\n\t\t\t\ttext?: string\n\t\t\t\ttype: string\n\t\t\t\t\n\t\t\t\tExample:\n\t\t\t\t{\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttext: 'Hello World',\n\t\t\t\t\t\t\t\t\ttype: 'text'\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\ttype: 'paragraph'\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\ttype: 'doc'\n\t\t\t\t}"),""}optimizeImages(t,e){let s=0,r=0,o="",i="";"boolean"!=typeof e&&("number"==typeof e.width&&e.width>0&&(o+=`width="${e.width}" `,s=e.width),"number"==typeof e.height&&e.height>0&&(o+=`height="${e.height}" `,r=e.height),("lazy"===e.loading||"eager"===e.loading)&&(o+=`loading="${e.loading}" `),"string"==typeof e.class&&e.class.length>0&&(o+=`class="${e.class}" `),e.filters&&("number"==typeof e.filters.blur&&e.filters.blur>=0&&e.filters.blur<=100&&(i+=`:blur(${e.filters.blur})`),"number"==typeof e.filters.brightness&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(i+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||"transparent"===e.filters.fill)&&(i+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(i+=`:format(${e.filters.format})`),"boolean"==typeof e.filters.grayscale&&e.filters.grayscale&&(i+=":grayscale()"),"number"==typeof e.filters.quality&&e.filters.quality>=0&&e.filters.quality<=100&&(i+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(i+=`:rotate(${e.filters.rotate})`),i.length>0&&(i="/filters"+i))),o.length>0&&(t=t.replace(/<img/g,`<img ${o.trim()}`));const n=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${n}`),"boolean"!=typeof e&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,(t=>{var s,r;const o=t.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(o&&o.length>0){const n={srcset:null==(s=e.srcset)?void 0:s.map((t=>{if("number"==typeof t)return`//${o}/m/${t}x0${i} ${t}w`;if("object"==typeof t&&2===t.length){let e=0,s=0;return"number"==typeof t[0]&&(e=t[0]),"number"==typeof t[1]&&(s=t[1]),`//${o}/m/${e}x${s}${i} ${e}w`}})).join(", "),sizes:null==(r=e.sizes)?void 0:r.map((t=>t)).join(", ")};let a="";return n.srcset&&(a+=`srcset="${n.srcset}" `),n.sizes&&(a+=`sizes="${n.sizes}" `),t.replace(/<img/g,`<img ${a.trim()}`)}return t}))),t}renderNode(t){const e=[];t.marks&&t.marks.forEach((t=>{const s=this.getMatchingMark(t);s&&""!==s.tag&&e.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach((t=>{e.push(this.renderNode(t))})):t.text?e.push(function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return t&&r.test(t)?t.replace(s,(t=>e[t])):t}(t.text)):s&&s.singleTag?e.push(this.renderTag(s.singleTag," /")):s&&s.html?e.push(s.html):"emoji"===t.type&&e.push(this.renderEmoji(t)),s&&s.tag&&e.push(this.renderClosingTag(s.tag)),t.marks&&t.marks.slice(0).reverse().forEach((t=>{const s=this.getMatchingMark(t);s&&""!==s.tag&&e.push(this.renderClosingTag(s.tag))})),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map((t=>{if(t.constructor===String)return`<${t}${e}>`;{let s=`<${t.tag}`;if(t.attrs)for(const e in t.attrs){const r=t.attrs[e];null!==r&&(s+=` ${e}="${r}"`)}return`${s}${e}>`}})).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map((t=>t.constructor===String?`</${t}>`:`</${t.tag}>`)).join("")}getMatchingNode(t){const e=this.nodes[t.type];if("function"==typeof e)return e(t)}getMatchingMark(t){const e=this.marks[t.type];if("function"==typeof e)return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class c{constructor(){o(this,"isCDNUrl",((t="")=>t.indexOf("/cdn/")>-1)),o(this,"getOptionsPage",((t,e=25,s=1)=>({...t,per_page:e,page:s}))),o(this,"delay",(t=>new Promise((e=>setTimeout(e,t))))),o(this,"arrayFrom",((t=0,e)=>[...Array(t)].map(e))),o(this,"range",((t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,((e,s)=>s*r+t))})),o(this,"asyncMap",(async(t,e)=>Promise.all(t.map(e)))),o(this,"flatMap",((t=[],e)=>t.map(e).reduce(((t,e)=>[...t,...e]),[])))}stringify(t,e,s){const r=[];for(const o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;const i=t[o],n=s?"":encodeURIComponent(o);let a;a="object"==typeof i?this.stringify(i,e?e+encodeURIComponent("["+n+"]"):n,Array.isArray(i)):(e?e+encodeURIComponent("["+n+"]"):n)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(t){switch(t){case"us":return"api-us.storyblok.com";case"cn":return"app.storyblokchina.cn";default:return"api.storyblok.com"}}}class h{constructor(t){o(this,"baseURL"),o(this,"timeout"),o(this,"headers"),o(this,"responseInterceptor"),o(this,"fetch"),o(this,"ejectInterceptor"),o(this,"url"),o(this,"parameters"),this.baseURL=t.baseURL,this.headers=t.headers||new Headers,this.timeout=null!=t&&t.timeout?1e3*t.timeout:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};204!==t.status&&await t.json().then((t=>{s.data=t}));for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if("get"===t){const t=new c;e=`${this.baseURL}${this.url}?${t.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),o=new AbortController,{signal:i}=o;let n;this.timeout&&(n=setTimeout((()=>o.abort()),this.timeout));try{const e=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(n);const o=await this._responseHandler(e);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(o)):this._statusHandler(o)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise(((s,r)=>{if(e.test(`${t.status}`))return s(t);r({message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug})}))}}let u={};const p={};class d{constructor(t,e){if(o(this,"client"),o(this,"maxRetries"),o(this,"throttle"),o(this,"accessToken"),o(this,"cache"),o(this,"helpers"),o(this,"resolveCounter"),o(this,"relations"),o(this,"links"),o(this,"richTextResolver"),o(this,"resolveNestedRelations"),!e){const s=(new c).getRegionURL,r=!1===t.https?"http":"https";e=t.oauthToken?`${r}://${s(t.region)}/v1`:`${r}://${s(t.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach(((e,r)=>{t.headers&&t.headers[r]&&s.set(r,t.headers[r])}));let r=5;t.oauthToken&&(s.set("Authorization",t.oauthToken),r=3),t.rateLimit&&(r=t.rateLimit),t.richTextSchema?this.richTextResolver=new l(t.richTextSchema):this.richTextResolver=new l,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=function(t,e,s){if(!i(e))throw new TypeError("Expected `limit` to be a finite number");if(!i(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let o=[],n=0;const a=function(){n++;const e=setTimeout((function(){n--,r.length>0&&a(),o=o.filter((function(t){return t!==e}))}),s);o.indexOf(e)<0&&o.push(e);const i=r.shift();i.resolve(t.apply(i.self,i.args))},l=function(...t){const s=this;return new Promise((function(o,i){r.push({resolve:o,reject:i,args:t,self:s}),n<e&&a()}))};return l.abort=function(){o.forEach(clearTimeout),o=[],r.forEach((function(t){t.reject((function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"}))})),r.length=0},l}(this.throttledRequest,r,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new c,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new h({baseURL:e,timeout:t.timeout||0,headers:s,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",(e=>{let s="";return e.attrs.body&&e.attrs.body.forEach((e=>{s+=t(e.component,e)})),{html:s}}))}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=p[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const o=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,o)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(null==e?void 0:e.per_page)||25,o=`/${t}`,i=o.split("/"),n=s||i[i.length-1],a=await this.makeRequest(o,e,r,1),l=a.total?Math.ceil(a.total/r):1,c=await this.helpers.asyncMap(this.helpers.range(1,l),(t=>this.makeRequest(o,e,r,t+1)));return this.helpers.flatMap([a,...c],(t=>Object.values(t.data[n])))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,s){const r=t[e];r&&"multilink"==r.fieldtype&&"story"==r.linktype&&"string"==typeof r.id&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&"story"===r.linktype&&"string"==typeof r.uuid&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(t,e,s,r){if(s.indexOf(`${t.component}.${e}`)>-1)if("string"==typeof t[e])this.relations[r][t[e]]&&(t[e]=this._cleanCopy(this.relations[r][t[e]]));else if(t[e]&&t[e].constructor===Array){const s=[];t[e].forEach((t=>{this.relations[r][t]&&s.push(this._cleanCopy(this.relations[r][t]))})),t[e]=s}}iterateTree(t,e,s){const r=t=>{if(null!=t)if(t.constructor===Array)for(let e=0;e<t.length;e++)r(t[e]);else if(t.constructor===Object){if(t._stopResolving)return;for(const o in t)(t.component&&t._uid||"link"===t.type)&&(this._insertRelations(t,o,e,s),this._insertLinks(t,o,s)),r(t[o])}};r(t.content)}async resolveLinks(t,e,s){let r=[];if(t.link_uuids){const s=t.link_uuids.length,o=[],i=50;for(let e=0;e<s;e+=i){const r=Math.min(s,e+i);o.push(t.link_uuids.slice(e,r))}for(let t=0;t<o.length;t++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[t].join(",")})).data.stories.forEach((t=>{r.push(t)}))}else r=t.links;r.forEach((t=>{this.links[s][t.uuid]={...t,_stopResolving:!0}}))}async resolveRelations(t,e,s){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length,o=[],i=50;for(let e=0;e<s;e+=i){const r=Math.min(s,e+i);o.push(t.rel_uuids.slice(e,r))}for(let t=0;t<o.length;t++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[t].join(",")})).data.stories.forEach((t=>{r.push(t)}))}else r=t.rels;r&&r.length>0&&r.forEach((t=>{this.relations[s][t.uuid]={...t,_stopResolving:!0}}))}async resolveStories(t,e,s){var r,o;let i=[];if(this.links[s]={},this.relations[s]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&("string"==typeof e.resolve_relations&&(i=e.resolve_relations.split(",")),await this.resolveRelations(t,e,s)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&(null!=(r=t.links)&&r.length||null!=(o=t.link_uuids)&&o.length)&&await this.resolveLinks(t,e,s),this.resolveNestedRelations)for(const n in this.relations[s])this.iterateTree(this.relations[s][n],i,s);t.story?this.iterateTree(t.story,i,s):t.stories.forEach((t=>{this.iterateTree(t,i,s)})),delete this.links[s],delete this.relations[s]}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),o=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===e.version&&await this.flushCache(),"published"===e.version&&"/cdn/spaces/me"!=t){const t=await o.get(r);if(t)return Promise.resolve(t)}return new Promise(((s,i)=>{try{(async()=>{var n;try{const a=await this.throttle("get",t,e);let l={data:a.data,headers:a.headers};if(null!=(n=a.headers)&&n["per-page"]&&(l=Object.assign({},l,{perPage:a.headers["per-page"]?parseInt(a.headers["per-page"]):0,total:a.headers["per-page"]?parseInt(a.headers.total):0})),200!=a.status)return i(a);if(l.data.story||l.data.stories){const t=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(l.data,e,`${t}`)}return"published"===e.version&&"/cdn/spaces/me"!=t&&await o.set(r,l),l.data.cv&&e.token&&("draft"==e.version&&p[e.token]!=l.data.cv&&await this.flushCache(),p[e.token]=l.data.cv),s(l)}catch(a){return i(a)}})()}catch{}}))}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return p}cacheVersion(){return p[this.accessToken]}setCacheVersion(t){this.accessToken&&(p[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get:t=>Promise.resolve(u[t]),getAll:()=>Promise.resolve(u),set:(t,e)=>(u[t]=e,Promise.resolve(void 0)),flush:()=>(u={},Promise.resolve(void 0))};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get:()=>Promise.resolve(void 0),getAll:()=>Promise.resolve(void 0),set:()=>Promise.resolve(void 0),flush:()=>Promise.resolve(void 0)}}}async flushCache(){return await this.cacheProvider().flush(),this}}let g;const f="https://app.storyblok.com/f/storyblok-v2-latest.js",m=(t,e)=>{t.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))};exports.ce=t=>{if("object"!=typeof t||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}},exports.de=(t,e,s)=>{let r=s||g;if(r)return""===t?"":t?(e&&(r=new l(e.schema),e.resolver&&m(r,e.resolver)),r.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.\n \n For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"");console.error("Please initialize the Storyblok SDK before calling the renderRichText function")},exports.he=(t,e,s={})=>{var r;const o=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL(null==(r=window.location)?void 0:r.href).searchParams.get("_storyblok")===t;if(o&&i){if(!t)return void console.warn("Story ID is not defined. Please provide a valid ID.");window.storyblokRegisterEvent((()=>{new window.StoryblokBridge(s).on(["input","published","change"],(s=>{"input"===s.action&&s.story.id===t?e(s.story):("change"===s.action||"published"===s.action)&&s.storyId===t&&window.location.reload()}))}))}},exports.ie=a,exports.le=(t={})=>{const{apiOptions:e}=t;if(e.accessToken)return{storyblokApi:new d(e)};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")},exports.pe=()=>s(f),exports.ue=(t={})=>{var e,r;const{bridge:o,accessToken:i,use:n=[],apiOptions:a={},richText:c={}}=t;a.accessToken=a.accessToken||i;const h={bridge:o,apiOptions:a};let u={};n.forEach((t=>{u={...u,...t(h)}}));const p=!(typeof window>"u")&&(null==(r=null==(e=window.location)?void 0:e.search)?void 0:r.includes("_storyblok_tk"));return!1!==o&&p&&s(f),g=new l(c.schema),c.resolver&&m(g,c.resolver),u},exports.y=l;
|
package/dist/storyblok-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),o=require("./storyblok-js-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),o=require("./storyblok-js-e9ec752f.js"),t=require("./index-fd3bb3fa.js"),r=require("./client-9f00300c.js");exports.RichTextResolver=o.y,exports.RichTextSchema=o.ie,exports.apiPlugin=o.le,exports.loadStoryblokBridge=o.pe,exports.registerStoryblokBridge=o.he,exports.renderRichText=o.de,exports.storyblokEditable=o.ce,exports.useStoryblokBridge=o.he,exports.StoryblokComponent=t.StoryblokComponent,exports.getComponent=t.getComponent,exports.getStoryblokApi=t.useStoryblokApi,exports.storyblokInit=t.storyblokInit,exports.useStoryblokApi=t.useStoryblokApi,exports.useStoryblokState=r.useStoryblokState,exports.useStoryblok=(r,s={},i={})=>{const n=t.useStoryblokApi();if(!n)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;let[l,p]=e.useState({});const y="undefined"!=typeof window&&void 0!==window.storyblokRegisterEvent;return e.useEffect((()=>{!async function(){const{data:e}=await n.get(`cdn/stories/${r}`,s);p(e.story),y&&e.story.id&&o.he(e.story.id,(e=>p(e)),i)}()}),[r,JSON.stringify(s)]),l};
|
package/dist/storyblok-react.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
|
-
import { h as he } from "./storyblok-js-
|
|
3
|
-
import { y, i, l, p, d, c } from "./storyblok-js-
|
|
4
|
-
import { u as useStoryblokApi } from "./index-
|
|
5
|
-
import { S, g, s } from "./index-
|
|
6
|
-
import { u } from "./client-
|
|
2
|
+
import { h as he } from "./storyblok-js-06eb3096.mjs";
|
|
3
|
+
import { y, i, l, p, d, c } from "./storyblok-js-06eb3096.mjs";
|
|
4
|
+
import { u as useStoryblokApi } from "./index-2fd0c215.mjs";
|
|
5
|
+
import { S, g, s } from "./index-2fd0c215.mjs";
|
|
6
|
+
import { u } from "./client-7d136bb5.mjs";
|
|
7
7
|
const useStoryblok = (slug, apiOptions = {}, bridgeOptions = {}) => {
|
|
8
8
|
const storyblokApiInstance = useStoryblokApi();
|
|
9
9
|
if (!storyblokApiInstance) {
|
package/dist/storyblok-react2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-fd3bb3fa.js"),o=require("./storyblok-js-e9ec752f.js");require("react"),exports.StoryblokComponent=e.StoryblokComponent,exports.getComponent=e.getComponent,exports.getStoryblokApi=e.useStoryblokApi,exports.storyblokInit=e.storyblokInit,exports.useStoryblokApi=e.useStoryblokApi,exports.RichTextResolver=o.y,exports.RichTextSchema=o.ie,exports.apiPlugin=o.le,exports.loadStoryblokBridge=o.pe,exports.registerStoryblokBridge=o.he,exports.renderRichText=o.de,exports.storyblokEditable=o.ce,exports.useStoryblokBridge=o.he;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S, g, u, s, u as u2 } from "./index-
|
|
2
|
-
import { y, i, l, p, h, d, c, h as h2 } from "./storyblok-js-
|
|
1
|
+
import { S, g, u, s, u as u2 } from "./index-2fd0c215.mjs";
|
|
2
|
+
import { y, i, l, p, h, d, c, h as h2 } from "./storyblok-js-06eb3096.mjs";
|
|
3
3
|
import "react";
|
|
4
4
|
export {
|
|
5
5
|
y as RichTextResolver,
|
package/dist/storyblok-react3.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";const e=require("react"),o=require("./storyblok-js-
|
|
1
|
+
"use strict";"use client";const e=require("react"),o=require("./storyblok-js-e9ec752f.js");module.exports=({options:t})=>((async e=>{await o.pe(),new window.StoryblokBridge(e).on(["published","change"],(()=>{window.location.reload()}))})(t),e.createElement(e.Fragment,null));
|
package/dist/storyblok-react4.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";const e=require("react"),t=require("./client-
|
|
1
|
+
"use strict";"use client";const e=require("react"),t=require("./client-9f00300c.js"),r=require("./index-fd3bb3fa.js");require("./storyblok-js-e9ec752f.js");module.exports=({story:o})=>(o=t.useStoryblokState(o),e.createElement(r.StoryblokComponent,{blok:o.content}));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { u as useStoryblokState } from "./client-
|
|
4
|
-
import { S as StoryblokComponent } from "./index-
|
|
5
|
-
import "./storyblok-js-
|
|
3
|
+
import { u as useStoryblokState } from "./client-7d136bb5.mjs";
|
|
4
|
+
import { S as StoryblokComponent } from "./index-2fd0c215.mjs";
|
|
5
|
+
import "./storyblok-js-06eb3096.mjs";
|
|
6
6
|
const StoryblokStory = ({ story }) => {
|
|
7
7
|
story = useStoryblokState(story);
|
|
8
8
|
return /* @__PURE__ */ React.createElement(StoryblokComponent, { blok: story.content });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/storyblok-react.js",
|
|
6
6
|
"module": "./dist/storyblok-react.mjs",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "^2.1.
|
|
47
|
+
"@storyblok/js": "^2.1.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/core": "^7.21.8",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";let t=!1;const e=[],s=s=>new Promise(((r,i)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{window.location!==window.parent.location?t?s():e.push(s):console.warn("You are not in Draft Mode or in the Visual Editor.")},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=s,o.id="storyblok-javascript-bridge",o.onerror=t=>i(t),o.onload=s=>{e.forEach((t=>t())),t=!0,r(s)},document.getElementsByTagName("head")[0].appendChild(o)}));var r=Object.defineProperty,i=(t,e,s)=>(((t,e,s)=>{e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s);function o(t){return!(t!=t||t===1/0||t===-1/0)}const n=function(t,e){const s={};for(const r in t){const i=t[r];e.indexOf(r)>-1&&null!==i&&(s[r]=i)}return s},a={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:t=>({tag:`h${t.attrs.level}`}),image:t=>({singleTag:[{tag:"img",attrs:n(t.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:t=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":t.attrs.name,emoji:t.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:t=>{const e={...t.attrs},{linktype:s="url"}=t.attrs;if((t=>"email"===t)(s)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const t in e.custom)e[t]=e.custom[t];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},styled:t=>({tag:[{tag:"span",attrs:t.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:t=>({tag:[{tag:"span",attrs:t.attrs}]}),highlight:t=>({tag:[{tag:"span",attrs:{style:`background-color:${t.attrs.color};`}}]}),textStyle:t=>({tag:[{tag:"span",attrs:{style:`color:${t.attrs.color}`}}]})}};class l{constructor(t){i(this,"marks"),i(this,"nodes"),t||(t=a),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach((t=>{s+=this.renderNode(t)})),e.optimizeImages?this.optimizeImages(s,e.optimizeImages):s}return console.warn("The render method must receive an Object with a \"content\" field.\n\t\t\tThe \"content\" field must be an array of nodes as the type ISbRichtext.\n\t\t\tISbRichtext:\n\t\t\t\tcontent?: ISbRichtext[]\n\t\t\t\tmarks?: ISbRichtext[]\n\t\t\t\tattrs?: any\n\t\t\t\ttext?: string\n\t\t\t\ttype: string\n\t\t\t\t\n\t\t\t\tExample:\n\t\t\t\t{\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttext: 'Hello World',\n\t\t\t\t\t\t\t\t\ttype: 'text'\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\ttype: 'paragraph'\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\ttype: 'doc'\n\t\t\t\t}"),""}optimizeImages(t,e){let s=0,r=0,i="",o="";"boolean"!=typeof e&&("number"==typeof e.width&&e.width>0&&(i+=`width="${e.width}" `,s=e.width),"number"==typeof e.height&&e.height>0&&(i+=`height="${e.height}" `,r=e.height),("lazy"===e.loading||"eager"===e.loading)&&(i+=`loading="${e.loading}" `),"string"==typeof e.class&&e.class.length>0&&(i+=`class="${e.class}" `),e.filters&&("number"==typeof e.filters.blur&&e.filters.blur>=0&&e.filters.blur<=100&&(o+=`:blur(${e.filters.blur})`),"number"==typeof e.filters.brightness&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(o+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||"transparent"===e.filters.fill)&&(o+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(o+=`:format(${e.filters.format})`),"boolean"==typeof e.filters.grayscale&&e.filters.grayscale&&(o+=":grayscale()"),"number"==typeof e.filters.quality&&e.filters.quality>=0&&e.filters.quality<=100&&(o+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(o+=`:rotate(${e.filters.rotate})`),o.length>0&&(o="/filters"+o))),i.length>0&&(t=t.replace(/<img/g,`<img ${i.trim()}`));const n=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${n}`),"boolean"!=typeof e&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,(t=>{var s,r;const i=t.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(i&&i.length>0){const n={srcset:null==(s=e.srcset)?void 0:s.map((t=>{if("number"==typeof t)return`//${i}/m/${t}x0${o} ${t}w`;if("object"==typeof t&&2===t.length){let e=0,s=0;return"number"==typeof t[0]&&(e=t[0]),"number"==typeof t[1]&&(s=t[1]),`//${i}/m/${e}x${s}${o} ${e}w`}})).join(", "),sizes:null==(r=e.sizes)?void 0:r.map((t=>t)).join(", ")};let a="";return n.srcset&&(a+=`srcset="${n.srcset}" `),n.sizes&&(a+=`sizes="${n.sizes}" `),t.replace(/<img/g,`<img ${a.trim()}`)}return t}))),t}renderNode(t){const e=[];t.marks&&t.marks.forEach((t=>{const s=this.getMatchingMark(t);s&&e.push(this.renderOpeningTag(s.tag))}));const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach((t=>{e.push(this.renderNode(t))})):t.text?e.push(function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return t&&r.test(t)?t.replace(s,(t=>e[t])):t}(t.text)):s&&s.singleTag?e.push(this.renderTag(s.singleTag," /")):s&&s.html?e.push(s.html):"emoji"===t.type&&e.push(this.renderEmoji(t)),s&&s.tag&&e.push(this.renderClosingTag(s.tag)),t.marks&&t.marks.slice(0).reverse().forEach((t=>{const s=this.getMatchingMark(t);s&&e.push(this.renderClosingTag(s.tag))})),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map((t=>{if(t.constructor===String)return`<${t}${e}>`;{let s=`<${t.tag}`;if(t.attrs)for(const e in t.attrs){const r=t.attrs[e];null!==r&&(s+=` ${e}="${r}"`)}return`${s}${e}>`}})).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map((t=>t.constructor===String?`</${t}>`:`</${t.tag}>`)).join("")}getMatchingNode(t){const e=this.nodes[t.type];if("function"==typeof e)return e(t)}getMatchingMark(t){const e=this.marks[t.type];if("function"==typeof e)return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class c{constructor(){i(this,"isCDNUrl",((t="")=>t.indexOf("/cdn/")>-1)),i(this,"getOptionsPage",((t,e=25,s=1)=>({...t,per_page:e,page:s}))),i(this,"delay",(t=>new Promise((e=>setTimeout(e,t))))),i(this,"arrayFrom",((t=0,e)=>[...Array(t)].map(e))),i(this,"range",((t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,((e,s)=>s*r+t))})),i(this,"asyncMap",(async(t,e)=>Promise.all(t.map(e)))),i(this,"flatMap",((t=[],e)=>t.map(e).reduce(((t,e)=>[...t,...e]),[])))}stringify(t,e,s){const r=[];for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const o=t[i],n=s?"":encodeURIComponent(i);let a;a="object"==typeof o?this.stringify(o,e?e+encodeURIComponent("["+n+"]"):n,Array.isArray(o)):(e?e+encodeURIComponent("["+n+"]"):n)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")}getRegionURL(t){switch(t){case"us":return"api-us.storyblok.com";case"cn":return"app.storyblokchina.cn";default:return"api.storyblok.com"}}}class h{constructor(t){i(this,"baseURL"),i(this,"timeout"),i(this,"headers"),i(this,"responseInterceptor"),i(this,"fetch"),i(this,"ejectInterceptor"),i(this,"url"),i(this,"parameters"),this.baseURL=t.baseURL,this.headers=t.headers||new Headers,this.timeout=null!=t&&t.timeout?1e3*t.timeout:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};204!==t.status&&await t.json().then((t=>{s.data=t}));for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if("get"===t){const t=new c;e=`${this.baseURL}${this.url}?${t.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),i=new AbortController,{signal:o}=i;let n;this.timeout&&(n=setTimeout((()=>i.abort()),this.timeout));try{const e=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:o});this.timeout&&clearTimeout(n);const i=await this._responseHandler(e);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(i)):this._statusHandler(i)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise(((s,r)=>{if(e.test(`${t.status}`))return s(t);r({message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug})}))}}let u={};const p={};class d{constructor(t,e){if(i(this,"client"),i(this,"maxRetries"),i(this,"throttle"),i(this,"accessToken"),i(this,"cache"),i(this,"helpers"),i(this,"resolveCounter"),i(this,"relations"),i(this,"links"),i(this,"richTextResolver"),i(this,"resolveNestedRelations"),!e){const s=(new c).getRegionURL,r=!1===t.https?"http":"https";e=t.oauthToken?`${r}://${s(t.region)}/v1`:`${r}://${s(t.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach(((e,r)=>{t.headers&&t.headers[r]&&s.set(r,t.headers[r])}));let r=5;t.oauthToken&&(s.set("Authorization",t.oauthToken),r=3),t.rateLimit&&(r=t.rateLimit),t.richTextSchema?this.richTextResolver=new l(t.richTextSchema):this.richTextResolver=new l,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=function(t,e,s){if(!o(e))throw new TypeError("Expected `limit` to be a finite number");if(!o(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let i=[],n=0;const a=function(){n++;const e=setTimeout((function(){n--,r.length>0&&a(),i=i.filter((function(t){return t!==e}))}),s);i.indexOf(e)<0&&i.push(e);const o=r.shift();o.resolve(t.apply(o.self,o.args))},l=function(...t){const s=this;return new Promise((function(i,o){r.push({resolve:i,reject:o,args:t,self:s}),n<e&&a()}))};return l.abort=function(){i.forEach(clearTimeout),i=[],r.forEach((function(t){t.reject((function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"}))})),r.length=0},l}(this.throttledRequest,r,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new c,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new h({baseURL:e,timeout:t.timeout||0,headers:s,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",(e=>{let s="";return e.attrs.body.forEach((e=>{s+=t(e.component,e)})),{html:s}}))}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=p[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const i=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,i)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(null==e?void 0:e.per_page)||25,i=`/${t}`,o=i.split("/"),n=s||o[o.length-1],a=await this.makeRequest(i,e,r,1),l=a.total?Math.ceil(a.total/r):1,c=await this.helpers.asyncMap(this.helpers.range(1,l),(t=>this.makeRequest(i,e,r,t+1)));return this.helpers.flatMap([a,...c],(t=>Object.values(t.data[n])))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,s){const r=t[e];r&&"multilink"==r.fieldtype&&"story"==r.linktype&&"string"==typeof r.id&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&"story"===r.linktype&&"string"==typeof r.uuid&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(t,e,s,r){if(s.indexOf(`${t.component}.${e}`)>-1)if("string"==typeof t[e])this.relations[r][t[e]]&&(t[e]=this._cleanCopy(this.relations[r][t[e]]));else if(t[e]&&t[e].constructor===Array){const s=[];t[e].forEach((t=>{this.relations[r][t]&&s.push(this._cleanCopy(this.relations[r][t]))})),t[e]=s}}iterateTree(t,e,s){const r=t=>{if(null!=t)if(t.constructor===Array)for(let e=0;e<t.length;e++)r(t[e]);else if(t.constructor===Object){if(t._stopResolving)return;for(const i in t)(t.component&&t._uid||"link"===t.type)&&(this._insertRelations(t,i,e,s),this._insertLinks(t,i,s)),r(t[i])}};r(t.content)}async resolveLinks(t,e,s){let r=[];if(t.link_uuids){const s=t.link_uuids.length,i=[],o=50;for(let e=0;e<s;e+=o){const r=Math.min(s,e+o);i.push(t.link_uuids.slice(e,r))}for(let t=0;t<i.length;t++)(await this.getStories({per_page:o,language:e.language,version:e.version,by_uuids:i[t].join(",")})).data.stories.forEach((t=>{r.push(t)}))}else r=t.links;r.forEach((t=>{this.links[s][t.uuid]={...t,_stopResolving:!0}}))}async resolveRelations(t,e,s){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length,i=[],o=50;for(let e=0;e<s;e+=o){const r=Math.min(s,e+o);i.push(t.rel_uuids.slice(e,r))}for(let t=0;t<i.length;t++)(await this.getStories({per_page:o,language:e.language,version:e.version,by_uuids:i[t].join(",")})).data.stories.forEach((t=>{r.push(t)}))}else r=t.rels;r&&r.length>0&&r.forEach((t=>{this.relations[s][t.uuid]={...t,_stopResolving:!0}}))}async resolveStories(t,e,s){var r,i;let o=[];if(this.links[s]={},this.relations[s]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&("string"==typeof e.resolve_relations&&(o=e.resolve_relations.split(",")),await this.resolveRelations(t,e,s)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&(null!=(r=t.links)&&r.length||null!=(i=t.link_uuids)&&i.length)&&await this.resolveLinks(t,e,s),this.resolveNestedRelations)for(const n in this.relations[s])this.iterateTree(this.relations[s][n],o,s);t.story?this.iterateTree(t.story,o,s):t.stories.forEach((t=>{this.iterateTree(t,o,s)})),delete this.links[s],delete this.relations[s]}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),i=this.cacheProvider();if("auto"===this.cache.clear&&"draft"===e.version&&await this.flushCache(),"published"===e.version&&"/cdn/spaces/me"!=t){const t=await i.get(r);if(t)return Promise.resolve(t)}return new Promise(((s,o)=>{try{(async()=>{var n;try{const a=await this.throttle("get",t,e);let l={data:a.data,headers:a.headers};if(null!=(n=a.headers)&&n["per-page"]&&(l=Object.assign({},l,{perPage:a.headers["per-page"]?parseInt(a.headers["per-page"]):0,total:a.headers["per-page"]?parseInt(a.headers.total):0})),200!=a.status)return o(a);if(l.data.story||l.data.stories){const t=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(l.data,e,`${t}`)}return"published"===e.version&&"/cdn/spaces/me"!=t&&await i.set(r,l),l.data.cv&&e.token&&("draft"==e.version&&p[e.token]!=l.data.cv&&await this.flushCache(),p[e.token]=l.data.cv),s(l)}catch(a){return o(a)}})()}catch{}}))}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return p}cacheVersion(){return p[this.accessToken]}setCacheVersion(t){this.accessToken&&(p[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get:t=>Promise.resolve(u[t]),getAll:()=>Promise.resolve(u),set:(t,e)=>(u[t]=e,Promise.resolve(void 0)),flush:()=>(u={},Promise.resolve(void 0))};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get:()=>Promise.resolve(void 0),getAll:()=>Promise.resolve(void 0),set:()=>Promise.resolve(void 0),flush:()=>Promise.resolve(void 0)}}}async flushCache(){return await this.cacheProvider().flush(),this}}let g;const f="https://app.storyblok.com/f/storyblok-v2-latest.js",m=(t,e)=>{t.addNode("blok",(t=>{let s="";return t.attrs.body.forEach((t=>{s+=e(t.component,t)})),{html:s}}))};exports.ce=t=>{if("object"!=typeof t||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}},exports.de=(t,e,s)=>{let r=s||g;if(r)return""===t?"":t?(e&&(r=new l(e.schema),e.resolver&&m(r,e.resolver)),r.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.\n \n For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"");console.error("Please initialize the Storyblok SDK before calling the renderRichText function")},exports.he=(t,e,s={})=>{var r;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL(null==(r=window.location)?void 0:r.href).searchParams.get("_storyblok")===t;if(i&&o){if(!t)return void console.warn("Story ID is not defined. Please provide a valid ID.");window.storyblokRegisterEvent((()=>{new window.StoryblokBridge(s).on(["input","published","change"],(s=>{"input"===s.action&&s.story.id===t?e(s.story):("change"===s.action||"published"===s.action)&&s.storyId===t&&window.location.reload()}))}))}},exports.ie=a,exports.le=(t={})=>{const{apiOptions:e}=t;if(e.accessToken)return{storyblokApi:new d(e)};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")},exports.pe=()=>s(f),exports.ue=(t={})=>{var e,r;const{bridge:i,accessToken:o,use:n=[],apiOptions:a={},richText:c={}}=t;a.accessToken=a.accessToken||o;const h={bridge:i,apiOptions:a};let u={};n.forEach((t=>{u={...u,...t(h)}}));const p=!(typeof window>"u")&&(null==(r=null==(e=window.location)?void 0:e.search)?void 0:r.includes("_storyblok_tk"));return!1!==i&&p&&s(f),g=new l(c.schema),c.resolver&&m(g,c.resolver),u},exports.y=l;
|