@storyblok/react 4.3.6 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +8 -8
- package/dist/richtext.d.ts.map +1 -1
- package/dist/richtext.js +1 -1
- package/dist/richtext.mjs +11 -8
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +326 -324
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +16 -51
- package/package.json +3 -3
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
3
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
1
|
+
let U = !1;
|
|
2
|
+
const H = [], F = (r) => new Promise((e, t) => {
|
|
3
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
|
|
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
|
+
U ? n() : H.push(n);
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
10
10
|
return;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
|
11
|
+
const s = document.createElement("script");
|
|
12
|
+
s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (n) => t(n), s.onload = (n) => {
|
|
13
|
+
H.forEach((o) => o()), U = !0, e(n);
|
|
14
|
+
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
15
15
|
});
|
|
16
|
-
var Q = Object.defineProperty, Z = (
|
|
16
|
+
var Q = Object.defineProperty, Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
|
|
17
17
|
class ee extends Error {
|
|
18
18
|
constructor(e) {
|
|
19
19
|
super(e), this.name = "AbortError";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function te(
|
|
22
|
+
function te(r, e, t) {
|
|
23
23
|
if (!Number.isFinite(e))
|
|
24
24
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
25
25
|
if (!Number.isFinite(t))
|
|
26
26
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
27
|
-
const
|
|
28
|
-
let
|
|
27
|
+
const s = [];
|
|
28
|
+
let n = [], o = 0, i = !1;
|
|
29
29
|
const l = async () => {
|
|
30
30
|
o++;
|
|
31
|
-
const h =
|
|
31
|
+
const h = s.shift();
|
|
32
32
|
if (h)
|
|
33
33
|
try {
|
|
34
|
-
const d = await
|
|
34
|
+
const d = await r(...h.args);
|
|
35
35
|
h.resolve(d);
|
|
36
36
|
} catch (d) {
|
|
37
37
|
h.reject(d);
|
|
38
38
|
}
|
|
39
39
|
const u = setTimeout(() => {
|
|
40
|
-
o--,
|
|
40
|
+
o--, s.length > 0 && l(), n = n.filter((d) => d !== u);
|
|
41
41
|
}, t);
|
|
42
|
-
|
|
42
|
+
n.includes(u) || n.push(u);
|
|
43
43
|
}, a = (...h) => i ? Promise.reject(
|
|
44
44
|
new Error(
|
|
45
45
|
"Throttled function is already aborted and not accepting new promises"
|
|
46
46
|
)
|
|
47
47
|
) : new Promise((u, d) => {
|
|
48
|
-
|
|
48
|
+
s.push({
|
|
49
49
|
resolve: u,
|
|
50
50
|
reject: d,
|
|
51
51
|
args: h
|
|
52
52
|
}), o < e && l();
|
|
53
53
|
});
|
|
54
54
|
return a.abort = () => {
|
|
55
|
-
i = !0,
|
|
55
|
+
i = !0, n.forEach(clearTimeout), n = [], s.forEach(
|
|
56
56
|
(h) => h.reject(() => new ee("Throttle function aborted"))
|
|
57
|
-
),
|
|
57
|
+
), s.length = 0;
|
|
58
58
|
}, a;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
let A = class {
|
|
61
61
|
constructor() {
|
|
62
|
-
p(this, "isCDNUrl", (
|
|
63
|
-
...
|
|
64
|
-
per_page:
|
|
65
|
-
page:
|
|
66
|
-
})), p(this, "delay", (
|
|
67
|
-
const
|
|
68
|
-
return this.arrayFrom(
|
|
69
|
-
}), p(this, "asyncMap", async (
|
|
70
|
-
const
|
|
62
|
+
p(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), p(this, "getOptionsPage", (r, e = 25, t = 1) => ({
|
|
63
|
+
...r,
|
|
64
|
+
per_page: e,
|
|
65
|
+
page: t
|
|
66
|
+
})), p(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), p(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), p(this, "range", (r = 0, e = r) => {
|
|
67
|
+
const t = Math.abs(e - r) || 0, s = r < e ? 1 : -1;
|
|
68
|
+
return this.arrayFrom(t, (n, o) => o * s + r);
|
|
69
|
+
}), p(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), p(this, "flatMap", (r = [], e) => r.map(e).reduce((t, s) => [...t, ...s], [])), p(this, "escapeHTML", function(r) {
|
|
70
|
+
const e = {
|
|
71
71
|
"&": "&",
|
|
72
72
|
"<": "<",
|
|
73
73
|
">": ">",
|
|
74
74
|
'"': """,
|
|
75
75
|
"'": "'"
|
|
76
|
-
},
|
|
77
|
-
return
|
|
76
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
77
|
+
return r && s.test(r) ? r.replace(t, (n) => e[n]) : r;
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -84,18 +84,18 @@ class A {
|
|
|
84
84
|
* @param {boolean} isArray
|
|
85
85
|
* @return {string} Stringified object
|
|
86
86
|
*/
|
|
87
|
-
stringify(e, t
|
|
87
|
+
stringify(r, e, t) {
|
|
88
88
|
const s = [];
|
|
89
|
-
for (const
|
|
90
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
89
|
+
for (const n in r) {
|
|
90
|
+
if (!Object.prototype.hasOwnProperty.call(r, n))
|
|
91
91
|
continue;
|
|
92
|
-
const
|
|
93
|
-
let
|
|
94
|
-
typeof
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Array.isArray(
|
|
98
|
-
) :
|
|
92
|
+
const o = r[n], i = t ? "" : encodeURIComponent(n);
|
|
93
|
+
let l;
|
|
94
|
+
typeof o == "object" ? l = this.stringify(
|
|
95
|
+
o,
|
|
96
|
+
e ? e + encodeURIComponent(`[${i}]`) : i,
|
|
97
|
+
Array.isArray(o)
|
|
98
|
+
) : l = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(o)}`, s.push(l);
|
|
99
99
|
}
|
|
100
100
|
return s.join("&");
|
|
101
101
|
}
|
|
@@ -104,52 +104,52 @@ class A {
|
|
|
104
104
|
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
105
105
|
* @return {string} The base URL of the region
|
|
106
106
|
*/
|
|
107
|
-
getRegionURL(
|
|
108
|
-
const
|
|
109
|
-
switch (
|
|
107
|
+
getRegionURL(r) {
|
|
108
|
+
const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
|
109
|
+
switch (r) {
|
|
110
110
|
case "us":
|
|
111
|
-
return
|
|
111
|
+
return t;
|
|
112
112
|
case "cn":
|
|
113
113
|
return s;
|
|
114
114
|
case "ap":
|
|
115
|
-
return
|
|
115
|
+
return n;
|
|
116
116
|
case "ca":
|
|
117
|
-
return
|
|
117
|
+
return o;
|
|
118
118
|
default:
|
|
119
|
-
return
|
|
119
|
+
return e;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
}
|
|
123
|
-
const re = function(
|
|
122
|
+
};
|
|
123
|
+
const re = function(r, e) {
|
|
124
124
|
const t = {};
|
|
125
|
-
for (const
|
|
126
|
-
const
|
|
127
|
-
e.includes(
|
|
125
|
+
for (const s in r) {
|
|
126
|
+
const n = r[s];
|
|
127
|
+
e.includes(s) && n !== null && (t[s] = n);
|
|
128
128
|
}
|
|
129
129
|
return t;
|
|
130
|
-
}, se = (
|
|
130
|
+
}, se = (r) => r === "email", ne = () => ({
|
|
131
131
|
singleTag: "hr"
|
|
132
132
|
}), oe = () => ({
|
|
133
133
|
tag: "blockquote"
|
|
134
134
|
}), ie = () => ({
|
|
135
135
|
tag: "ul"
|
|
136
|
-
}), ae = (
|
|
136
|
+
}), ae = (r) => ({
|
|
137
137
|
tag: [
|
|
138
138
|
"pre",
|
|
139
139
|
{
|
|
140
140
|
tag: "code",
|
|
141
|
-
attrs:
|
|
141
|
+
attrs: r.attrs
|
|
142
142
|
}
|
|
143
143
|
]
|
|
144
144
|
}), le = () => ({
|
|
145
145
|
singleTag: "br"
|
|
146
|
-
}), ce = (
|
|
147
|
-
tag: `h${
|
|
148
|
-
}), he = (
|
|
146
|
+
}), ce = (r) => ({
|
|
147
|
+
tag: `h${r.attrs.level}`
|
|
148
|
+
}), he = (r) => ({
|
|
149
149
|
singleTag: [
|
|
150
150
|
{
|
|
151
151
|
tag: "img",
|
|
152
|
-
attrs: re(
|
|
152
|
+
attrs: re(r.attrs, ["src", "alt", "title"])
|
|
153
153
|
}
|
|
154
154
|
]
|
|
155
155
|
}), ue = () => ({
|
|
@@ -158,14 +158,14 @@ const re = function(n, e) {
|
|
|
158
158
|
tag: "ol"
|
|
159
159
|
}), pe = () => ({
|
|
160
160
|
tag: "p"
|
|
161
|
-
}), ge = (
|
|
161
|
+
}), ge = (r) => ({
|
|
162
162
|
tag: [
|
|
163
163
|
{
|
|
164
164
|
tag: "span",
|
|
165
165
|
attrs: {
|
|
166
166
|
"data-type": "emoji",
|
|
167
|
-
"data-name":
|
|
168
|
-
emoji:
|
|
167
|
+
"data-name": r.attrs.name,
|
|
168
|
+
emoji: r.attrs.emoji
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
]
|
|
@@ -181,15 +181,15 @@ const re = function(n, e) {
|
|
|
181
181
|
tag: "code"
|
|
182
182
|
}), $e = () => ({
|
|
183
183
|
tag: "i"
|
|
184
|
-
}), ve = (
|
|
185
|
-
if (!
|
|
184
|
+
}), ve = (r) => {
|
|
185
|
+
if (!r.attrs)
|
|
186
186
|
return {
|
|
187
187
|
tag: ""
|
|
188
188
|
};
|
|
189
|
-
const e = new A().escapeHTML, t = { ...
|
|
190
|
-
if (delete t.linktype, t.href && (t.href = e(
|
|
191
|
-
for (const
|
|
192
|
-
t[
|
|
189
|
+
const e = new A().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
|
|
190
|
+
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), se(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
191
|
+
for (const n in t.custom)
|
|
192
|
+
t[n] = t.custom[n];
|
|
193
193
|
delete t.custom;
|
|
194
194
|
}
|
|
195
195
|
return {
|
|
@@ -200,46 +200,46 @@ const re = function(n, e) {
|
|
|
200
200
|
}
|
|
201
201
|
]
|
|
202
202
|
};
|
|
203
|
-
}, Te = (
|
|
203
|
+
}, Te = (r) => ({
|
|
204
204
|
tag: [
|
|
205
205
|
{
|
|
206
206
|
tag: "span",
|
|
207
|
-
attrs:
|
|
207
|
+
attrs: r.attrs
|
|
208
208
|
}
|
|
209
209
|
]
|
|
210
210
|
}), we = () => ({
|
|
211
211
|
tag: "sub"
|
|
212
212
|
}), Re = () => ({
|
|
213
213
|
tag: "sup"
|
|
214
|
-
}), _e = (
|
|
214
|
+
}), _e = (r) => ({
|
|
215
215
|
tag: [
|
|
216
216
|
{
|
|
217
217
|
tag: "span",
|
|
218
|
-
attrs:
|
|
218
|
+
attrs: r.attrs
|
|
219
219
|
}
|
|
220
220
|
]
|
|
221
|
-
}), Se = (
|
|
221
|
+
}), Se = (r) => {
|
|
222
222
|
var e;
|
|
223
|
-
return (e =
|
|
223
|
+
return (e = r.attrs) != null && e.color ? {
|
|
224
224
|
tag: [
|
|
225
225
|
{
|
|
226
226
|
tag: "span",
|
|
227
227
|
attrs: {
|
|
228
|
-
style: `background-color:${
|
|
228
|
+
style: `background-color:${r.attrs.color};`
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
]
|
|
232
232
|
} : {
|
|
233
233
|
tag: ""
|
|
234
234
|
};
|
|
235
|
-
}, Ee = (
|
|
235
|
+
}, Ee = (r) => {
|
|
236
236
|
var e;
|
|
237
|
-
return (e =
|
|
237
|
+
return (e = r.attrs) != null && e.color ? {
|
|
238
238
|
tag: [
|
|
239
239
|
{
|
|
240
240
|
tag: "span",
|
|
241
241
|
attrs: {
|
|
242
|
-
style: `color:${
|
|
242
|
+
style: `color:${r.attrs.color}`
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
]
|
|
@@ -275,18 +275,18 @@ const re = function(n, e) {
|
|
|
275
275
|
highlight: Se,
|
|
276
276
|
textStyle: Ee
|
|
277
277
|
}
|
|
278
|
-
}, Ie = function(
|
|
278
|
+
}, Ie = function(r) {
|
|
279
279
|
const e = {
|
|
280
280
|
"&": "&",
|
|
281
281
|
"<": "<",
|
|
282
282
|
">": ">",
|
|
283
283
|
'"': """,
|
|
284
284
|
"'": "'"
|
|
285
|
-
}, t = /[&<>"']/g,
|
|
286
|
-
return
|
|
285
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
286
|
+
return r && s.test(r) ? r.replace(t, (n) => e[n]) : r;
|
|
287
287
|
};
|
|
288
288
|
let z = !1;
|
|
289
|
-
class
|
|
289
|
+
class L {
|
|
290
290
|
constructor(e) {
|
|
291
291
|
p(this, "marks"), p(this, "nodes"), e || (e = je), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
292
292
|
}
|
|
@@ -296,14 +296,14 @@ class xe {
|
|
|
296
296
|
addMark(e, t) {
|
|
297
297
|
this.marks[e] = t;
|
|
298
298
|
}
|
|
299
|
-
render(e, t = { optimizeImages: !1 },
|
|
300
|
-
if (!z &&
|
|
299
|
+
render(e, t = { optimizeImages: !1 }, s = !0) {
|
|
300
|
+
if (!z && s && (console.warn(
|
|
301
301
|
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
|
|
302
302
|
), z = !0), e && e.content && Array.isArray(e.content)) {
|
|
303
|
-
let
|
|
303
|
+
let n = "";
|
|
304
304
|
return e.content.forEach((o) => {
|
|
305
|
-
|
|
306
|
-
}), t.optimizeImages ? this.optimizeImages(
|
|
305
|
+
n += this.renderNode(o);
|
|
306
|
+
}), t.optimizeImages ? this.optimizeImages(n, t.optimizeImages) : n;
|
|
307
307
|
}
|
|
308
308
|
return console.warn(
|
|
309
309
|
`The render method must receive an Object with a "content" field.
|
|
@@ -333,9 +333,9 @@ class xe {
|
|
|
333
333
|
), "";
|
|
334
334
|
}
|
|
335
335
|
optimizeImages(e, t) {
|
|
336
|
-
let
|
|
337
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `,
|
|
338
|
-
const l =
|
|
336
|
+
let s = 0, n = 0, o = "", i = "";
|
|
337
|
+
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}" `, n = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = `/filters${i}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
|
|
338
|
+
const l = s > 0 || n > 0 || i.length > 0 ? `${s}x${n}${i}` : "";
|
|
339
339
|
return e = e.replace(
|
|
340
340
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
341
341
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
@@ -346,51 +346,51 @@ class xe {
|
|
|
346
346
|
);
|
|
347
347
|
if (d && d.length > 0) {
|
|
348
348
|
const m = {
|
|
349
|
-
srcset: (h = t.srcset) == null ? void 0 : h.map((
|
|
350
|
-
if (typeof
|
|
351
|
-
return `//${d}/m/${
|
|
352
|
-
if (typeof
|
|
349
|
+
srcset: (h = t.srcset) == null ? void 0 : h.map((b) => {
|
|
350
|
+
if (typeof b == "number")
|
|
351
|
+
return `//${d}/m/${b}x0${i} ${b}w`;
|
|
352
|
+
if (typeof b == "object" && b.length === 2) {
|
|
353
353
|
let _ = 0, j = 0;
|
|
354
|
-
return typeof
|
|
354
|
+
return typeof b[0] == "number" && (_ = b[0]), typeof b[1] == "number" && (j = b[1]), `//${d}/m/${_}x${j}${i} ${_}w`;
|
|
355
355
|
}
|
|
356
356
|
return "";
|
|
357
357
|
}).join(", "),
|
|
358
|
-
sizes: (u = t.sizes) == null ? void 0 : u.map((
|
|
358
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((b) => b).join(", ")
|
|
359
359
|
};
|
|
360
|
-
let
|
|
361
|
-
return m.srcset && (
|
|
360
|
+
let y = "";
|
|
361
|
+
return m.srcset && (y += `srcset="${m.srcset}" `), m.sizes && (y += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${y.trim()}`);
|
|
362
362
|
}
|
|
363
363
|
return a;
|
|
364
364
|
})), e;
|
|
365
365
|
}
|
|
366
366
|
renderNode(e) {
|
|
367
367
|
const t = [];
|
|
368
|
-
e.marks && e.marks.forEach((
|
|
369
|
-
const o = this.getMatchingMark(
|
|
368
|
+
e.marks && e.marks.forEach((n) => {
|
|
369
|
+
const o = this.getMatchingMark(n);
|
|
370
370
|
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
|
371
371
|
});
|
|
372
|
-
const
|
|
373
|
-
return
|
|
374
|
-
t.push(this.renderNode(
|
|
375
|
-
}) : e.text ? t.push(Ie(e.text)) :
|
|
376
|
-
const o = this.getMatchingMark(
|
|
372
|
+
const s = this.getMatchingNode(e);
|
|
373
|
+
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((n) => {
|
|
374
|
+
t.push(this.renderNode(n));
|
|
375
|
+
}) : e.text ? t.push(Ie(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((n) => {
|
|
376
|
+
const o = this.getMatchingMark(n);
|
|
377
377
|
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
|
378
378
|
}), t.join("");
|
|
379
379
|
}
|
|
380
380
|
renderTag(e, t) {
|
|
381
|
-
return e.constructor === String ? `<${e}${t}>` : e.map((
|
|
382
|
-
if (
|
|
383
|
-
return `<${
|
|
381
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
|
|
382
|
+
if (s.constructor === String)
|
|
383
|
+
return `<${s}${t}>`;
|
|
384
384
|
{
|
|
385
|
-
let
|
|
386
|
-
if (
|
|
387
|
-
for (const o in
|
|
388
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
389
|
-
const i =
|
|
390
|
-
i !== null && (
|
|
385
|
+
let n = `<${s.tag}`;
|
|
386
|
+
if (s.attrs) {
|
|
387
|
+
for (const o in s.attrs)
|
|
388
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, o)) {
|
|
389
|
+
const i = s.attrs[o];
|
|
390
|
+
i !== null && (n += ` ${o}="${i}"`);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
return `${
|
|
393
|
+
return `${n}${t}>`;
|
|
394
394
|
}
|
|
395
395
|
}).join("");
|
|
396
396
|
}
|
|
@@ -427,8 +427,7 @@ class xe {
|
|
|
427
427
|
return this.renderTag(t, " /");
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
|
|
431
|
-
class Oe {
|
|
430
|
+
class xe {
|
|
432
431
|
constructor(e) {
|
|
433
432
|
p(this, "baseURL"), p(this, "timeout"), p(this, "headers"), p(this, "responseInterceptor"), p(this, "fetch"), p(this, "ejectInterceptor"), p(this, "url"), p(this, "parameters"), p(this, "fetchOptions"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
434
433
|
}
|
|
@@ -451,36 +450,36 @@ class Oe {
|
|
|
451
450
|
return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
|
|
452
451
|
}
|
|
453
452
|
async _responseHandler(e) {
|
|
454
|
-
const t = [],
|
|
453
|
+
const t = [], s = {
|
|
455
454
|
data: {},
|
|
456
455
|
headers: {},
|
|
457
456
|
status: 0,
|
|
458
457
|
statusText: ""
|
|
459
458
|
};
|
|
460
|
-
e.status !== 204 && await e.json().then((
|
|
461
|
-
|
|
459
|
+
e.status !== 204 && await e.json().then((n) => {
|
|
460
|
+
s.data = n;
|
|
462
461
|
});
|
|
463
|
-
for (const
|
|
464
|
-
t[
|
|
465
|
-
return
|
|
462
|
+
for (const n of e.headers.entries())
|
|
463
|
+
t[n[0]] = n[1];
|
|
464
|
+
return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
|
|
466
465
|
}
|
|
467
466
|
async _methodHandler(e) {
|
|
468
|
-
let t = `${this.baseURL}${this.url}`,
|
|
467
|
+
let t = `${this.baseURL}${this.url}`, s = null;
|
|
469
468
|
if (e === "get") {
|
|
470
469
|
const a = new A();
|
|
471
470
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
|
472
471
|
this.parameters
|
|
473
472
|
)}`;
|
|
474
473
|
} else
|
|
475
|
-
|
|
476
|
-
const
|
|
474
|
+
s = JSON.stringify(this.parameters);
|
|
475
|
+
const n = new URL(t), o = new AbortController(), { signal: i } = o;
|
|
477
476
|
let l;
|
|
478
477
|
this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
|
|
479
478
|
try {
|
|
480
|
-
const a = await this.fetch(`${
|
|
479
|
+
const a = await this.fetch(`${n}`, {
|
|
481
480
|
method: e,
|
|
482
481
|
headers: this.headers,
|
|
483
|
-
body:
|
|
482
|
+
body: s,
|
|
484
483
|
signal: i,
|
|
485
484
|
...this.fetchOptions
|
|
486
485
|
});
|
|
@@ -503,26 +502,26 @@ class Oe {
|
|
|
503
502
|
}
|
|
504
503
|
_statusHandler(e) {
|
|
505
504
|
const t = /20[0-6]/g;
|
|
506
|
-
return new Promise((
|
|
505
|
+
return new Promise((s, n) => {
|
|
507
506
|
if (t.test(`${e.status}`))
|
|
508
|
-
return
|
|
507
|
+
return s(e);
|
|
509
508
|
const o = {
|
|
510
509
|
message: e.statusText,
|
|
511
510
|
status: e.status,
|
|
512
511
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
513
512
|
};
|
|
514
|
-
|
|
513
|
+
n(o);
|
|
515
514
|
});
|
|
516
515
|
}
|
|
517
516
|
}
|
|
518
|
-
const
|
|
517
|
+
const D = "SB-Agent", C = {
|
|
519
518
|
defaultAgentName: "SB-JS-CLIENT",
|
|
520
519
|
defaultAgentVersion: "SB-Agent-Version",
|
|
521
520
|
packageVersion: "6.0.0"
|
|
522
521
|
};
|
|
523
522
|
let O = {};
|
|
524
|
-
const
|
|
525
|
-
class
|
|
523
|
+
const S = {};
|
|
524
|
+
class Oe {
|
|
526
525
|
/**
|
|
527
526
|
*
|
|
528
527
|
* @param config ISbConfig interface
|
|
@@ -530,96 +529,96 @@ class Le {
|
|
|
530
529
|
*/
|
|
531
530
|
constructor(e, t) {
|
|
532
531
|
p(this, "client"), p(this, "maxRetries"), p(this, "retriesDelay"), p(this, "throttle"), p(this, "accessToken"), p(this, "cache"), p(this, "helpers"), p(this, "resolveCounter"), p(this, "relations"), p(this, "links"), p(this, "richTextResolver"), p(this, "resolveNestedRelations"), p(this, "stringifiedStoriesCache");
|
|
533
|
-
let
|
|
534
|
-
if (!
|
|
532
|
+
let s = e.endpoint || t;
|
|
533
|
+
if (!s) {
|
|
535
534
|
const i = new A().getRegionURL, l = e.https === !1 ? "http" : "https";
|
|
536
|
-
e.oauthToken ?
|
|
535
|
+
e.oauthToken ? s = `${l}://${i(e.region)}/v1` : s = `${l}://${i(e.region)}/v2`;
|
|
537
536
|
}
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}),
|
|
542
|
-
|
|
543
|
-
|
|
537
|
+
const n = new Headers();
|
|
538
|
+
n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, l]) => {
|
|
539
|
+
n.set(i, l);
|
|
540
|
+
}), n.has(D) || (n.set(D, C.defaultAgentName), n.set(
|
|
541
|
+
C.defaultAgentVersion,
|
|
542
|
+
C.packageVersion
|
|
544
543
|
));
|
|
545
544
|
let o = 5;
|
|
546
|
-
e.oauthToken && (
|
|
545
|
+
e.oauthToken && (n.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = te(
|
|
547
546
|
this.throttledRequest.bind(this),
|
|
548
547
|
o,
|
|
549
548
|
1e3
|
|
550
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new
|
|
551
|
-
baseURL:
|
|
549
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
|
|
550
|
+
baseURL: s,
|
|
552
551
|
timeout: e.timeout || 0,
|
|
553
|
-
headers:
|
|
552
|
+
headers: n,
|
|
554
553
|
responseInterceptor: e.responseInterceptor,
|
|
555
554
|
fetch: e.fetch
|
|
556
555
|
});
|
|
557
556
|
}
|
|
558
557
|
setComponentResolver(e) {
|
|
559
558
|
this.richTextResolver.addNode("blok", (t) => {
|
|
560
|
-
let
|
|
561
|
-
return t.attrs.body && t.attrs.body.forEach((
|
|
562
|
-
|
|
559
|
+
let s = "";
|
|
560
|
+
return t.attrs.body && t.attrs.body.forEach((n) => {
|
|
561
|
+
s += e(n.component, n);
|
|
563
562
|
}), {
|
|
564
|
-
html:
|
|
563
|
+
html: s
|
|
565
564
|
};
|
|
566
565
|
});
|
|
567
566
|
}
|
|
568
567
|
parseParams(e) {
|
|
569
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
568
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = S[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
570
569
|
}
|
|
571
570
|
factoryParamOptions(e, t) {
|
|
572
571
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
573
572
|
}
|
|
574
|
-
makeRequest(e, t,
|
|
573
|
+
makeRequest(e, t, s, n, o) {
|
|
575
574
|
const i = this.factoryParamOptions(
|
|
576
575
|
e,
|
|
577
|
-
this.helpers.getOptionsPage(t,
|
|
576
|
+
this.helpers.getOptionsPage(t, s, n)
|
|
578
577
|
);
|
|
579
578
|
return this.cacheResponse(e, i, void 0, o);
|
|
580
579
|
}
|
|
581
|
-
get(e, t,
|
|
580
|
+
get(e, t, s) {
|
|
582
581
|
t || (t = {});
|
|
583
|
-
const
|
|
584
|
-
return this.cacheResponse(
|
|
582
|
+
const n = `/${e}`, o = this.factoryParamOptions(n, t);
|
|
583
|
+
return this.cacheResponse(n, o, void 0, s);
|
|
585
584
|
}
|
|
586
|
-
async getAll(e, t,
|
|
587
|
-
const o = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), l =
|
|
585
|
+
async getAll(e, t, s, n) {
|
|
586
|
+
const o = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), l = s ?? i.substring(i.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
|
|
588
587
|
i,
|
|
589
588
|
t,
|
|
590
589
|
o,
|
|
591
590
|
a,
|
|
592
|
-
|
|
591
|
+
n
|
|
593
592
|
), u = h.total ? Math.ceil(h.total / o) : 1, d = await this.helpers.asyncMap(
|
|
594
593
|
this.helpers.range(a, u),
|
|
595
|
-
(m) => this.makeRequest(i, t, o, m + 1,
|
|
594
|
+
(m) => this.makeRequest(i, t, o, m + 1, n)
|
|
596
595
|
);
|
|
597
596
|
return this.helpers.flatMap([h, ...d], (m) => Object.values(m.data[l]));
|
|
598
597
|
}
|
|
599
|
-
post(e, t,
|
|
600
|
-
const
|
|
598
|
+
post(e, t, s) {
|
|
599
|
+
const n = `/${e}`;
|
|
601
600
|
return Promise.resolve(
|
|
602
|
-
this.throttle("post",
|
|
601
|
+
this.throttle("post", n, t, s)
|
|
603
602
|
);
|
|
604
603
|
}
|
|
605
|
-
put(e, t,
|
|
606
|
-
const
|
|
604
|
+
put(e, t, s) {
|
|
605
|
+
const n = `/${e}`;
|
|
607
606
|
return Promise.resolve(
|
|
608
|
-
this.throttle("put",
|
|
607
|
+
this.throttle("put", n, t, s)
|
|
609
608
|
);
|
|
610
609
|
}
|
|
611
|
-
delete(e, t,
|
|
610
|
+
delete(e, t, s) {
|
|
612
611
|
t || (t = {});
|
|
613
|
-
const
|
|
612
|
+
const n = `/${e}`;
|
|
614
613
|
return Promise.resolve(
|
|
615
|
-
this.throttle("delete",
|
|
614
|
+
this.throttle("delete", n, t, s)
|
|
616
615
|
);
|
|
617
616
|
}
|
|
618
617
|
getStories(e, t) {
|
|
619
618
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
620
619
|
}
|
|
621
|
-
getStory(e, t,
|
|
622
|
-
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t,
|
|
620
|
+
getStory(e, t, s) {
|
|
621
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
|
|
623
622
|
}
|
|
624
623
|
getToken() {
|
|
625
624
|
return this.accessToken;
|
|
@@ -633,9 +632,9 @@ class Le {
|
|
|
633
632
|
_cleanCopy(e) {
|
|
634
633
|
return JSON.parse(JSON.stringify(e));
|
|
635
634
|
}
|
|
636
|
-
_insertLinks(e, t,
|
|
637
|
-
const
|
|
638
|
-
|
|
635
|
+
_insertLinks(e, t, s) {
|
|
636
|
+
const n = e[t];
|
|
637
|
+
n && n.fieldtype === "multilink" && n.linktype === "story" && typeof n.id == "string" && this.links[s][n.id] ? n.story = this._cleanCopy(this.links[s][n.id]) : n && n.linktype === "story" && typeof n.uuid == "string" && this.links[s][n.uuid] && (n.story = this._cleanCopy(this.links[s][n.uuid]));
|
|
639
638
|
}
|
|
640
639
|
/**
|
|
641
640
|
*
|
|
@@ -656,10 +655,10 @@ class Le {
|
|
|
656
655
|
* - For single strings: directly replaces the UUID with the story reference
|
|
657
656
|
* - For arrays: maps through each UUID and replaces with corresponding story references
|
|
658
657
|
*/
|
|
659
|
-
_resolveField(e, t,
|
|
660
|
-
const
|
|
661
|
-
typeof
|
|
662
|
-
(o) => this.getStoryReference(
|
|
658
|
+
_resolveField(e, t, s) {
|
|
659
|
+
const n = e[t];
|
|
660
|
+
typeof n == "string" ? e[t] = this.getStoryReference(s, n) : Array.isArray(n) && (e[t] = n.map(
|
|
661
|
+
(o) => this.getStoryReference(s, o)
|
|
663
662
|
).filter(Boolean));
|
|
664
663
|
}
|
|
665
664
|
/**
|
|
@@ -679,13 +678,13 @@ class Le {
|
|
|
679
678
|
* The method supports both string and array formats for the fields parameter,
|
|
680
679
|
* allowing flexible specification of relation patterns.
|
|
681
680
|
*/
|
|
682
|
-
_insertRelations(e, t,
|
|
683
|
-
if (Array.isArray(
|
|
684
|
-
this._resolveField(e, t,
|
|
681
|
+
_insertRelations(e, t, s, n) {
|
|
682
|
+
if (Array.isArray(s) ? s.find((i) => i.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
|
|
683
|
+
this._resolveField(e, t, n);
|
|
685
684
|
return;
|
|
686
685
|
}
|
|
687
686
|
const o = e.component ? `${e.component}.${t}` : t;
|
|
688
|
-
(Array.isArray(
|
|
687
|
+
(Array.isArray(s) ? s.includes(o) : s === o) && this._resolveField(e, t, n);
|
|
689
688
|
}
|
|
690
689
|
/**
|
|
691
690
|
* Recursively traverses and resolves relations in the story content tree
|
|
@@ -693,22 +692,22 @@ class Le {
|
|
|
693
692
|
* @param fields - The relation patterns to resolve
|
|
694
693
|
* @param resolveId - The unique identifier for the current resolution context
|
|
695
694
|
*/
|
|
696
|
-
iterateTree(e, t,
|
|
697
|
-
const
|
|
695
|
+
iterateTree(e, t, s) {
|
|
696
|
+
const n = (o, i = "") => {
|
|
698
697
|
if (!(!o || o._stopResolving)) {
|
|
699
698
|
if (Array.isArray(o))
|
|
700
|
-
o.forEach((l, a) =>
|
|
699
|
+
o.forEach((l, a) => n(l, `${i}[${a}]`));
|
|
701
700
|
else if (typeof o == "object")
|
|
702
701
|
for (const l in o) {
|
|
703
702
|
const a = i ? `${i}.${l}` : l;
|
|
704
|
-
(o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t,
|
|
703
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, s), this._insertLinks(o, l, s)), n(o[l], a);
|
|
705
704
|
}
|
|
706
705
|
}
|
|
707
706
|
};
|
|
708
|
-
|
|
707
|
+
n(e.content);
|
|
709
708
|
}
|
|
710
|
-
async resolveLinks(e, t,
|
|
711
|
-
let
|
|
709
|
+
async resolveLinks(e, t, s) {
|
|
710
|
+
let n = [];
|
|
712
711
|
if (e.link_uuids) {
|
|
713
712
|
const o = e.link_uuids.length, i = [], l = 50;
|
|
714
713
|
for (let a = 0; a < o; a += l) {
|
|
@@ -723,20 +722,20 @@ class Le {
|
|
|
723
722
|
by_uuids: i[a].join(",")
|
|
724
723
|
})).data.stories.forEach(
|
|
725
724
|
(h) => {
|
|
726
|
-
|
|
725
|
+
n.push(h);
|
|
727
726
|
}
|
|
728
727
|
);
|
|
729
728
|
} else
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
this.links[
|
|
729
|
+
n = e.links;
|
|
730
|
+
n.forEach((o) => {
|
|
731
|
+
this.links[s][o.uuid] = {
|
|
733
732
|
...o,
|
|
734
733
|
_stopResolving: !0
|
|
735
734
|
};
|
|
736
735
|
});
|
|
737
736
|
}
|
|
738
|
-
async resolveRelations(e, t,
|
|
739
|
-
let
|
|
737
|
+
async resolveRelations(e, t, s) {
|
|
738
|
+
let n = [];
|
|
740
739
|
if (e.rel_uuids) {
|
|
741
740
|
const o = e.rel_uuids.length, i = [], l = 50;
|
|
742
741
|
for (let a = 0; a < o; a += l) {
|
|
@@ -751,12 +750,12 @@ class Le {
|
|
|
751
750
|
by_uuids: i[a].join(","),
|
|
752
751
|
excluding_fields: t.excluding_fields
|
|
753
752
|
})).data.stories.forEach((h) => {
|
|
754
|
-
|
|
753
|
+
n.push(h);
|
|
755
754
|
});
|
|
756
755
|
} else
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
this.relations[
|
|
756
|
+
n = e.rels;
|
|
757
|
+
n && n.length > 0 && n.forEach((o) => {
|
|
758
|
+
this.relations[s][o.uuid] = {
|
|
760
759
|
...o,
|
|
761
760
|
_stopResolving: !0
|
|
762
761
|
};
|
|
@@ -771,23 +770,23 @@ class Le {
|
|
|
771
770
|
* @returns Promise<void>
|
|
772
771
|
*
|
|
773
772
|
*/
|
|
774
|
-
async resolveStories(e, t,
|
|
775
|
-
var
|
|
773
|
+
async resolveStories(e, t, s) {
|
|
774
|
+
var n, o;
|
|
776
775
|
let i = [];
|
|
777
|
-
if (this.links[
|
|
778
|
-
for (const l in this.relations[
|
|
776
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((n = e.links) != null && n.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
777
|
+
for (const l in this.relations[s])
|
|
779
778
|
this.iterateTree(
|
|
780
|
-
this.relations[
|
|
779
|
+
this.relations[s][l],
|
|
781
780
|
i,
|
|
782
|
-
|
|
781
|
+
s
|
|
783
782
|
);
|
|
784
|
-
e.story ? this.iterateTree(e.story, i,
|
|
785
|
-
this.iterateTree(l, i,
|
|
786
|
-
}), this.stringifiedStoriesCache = {}, delete this.links[
|
|
783
|
+
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
|
|
784
|
+
this.iterateTree(l, i, s);
|
|
785
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
787
786
|
}
|
|
788
|
-
async cacheResponse(e, t,
|
|
787
|
+
async cacheResponse(e, t, s, n) {
|
|
789
788
|
const o = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
790
|
-
if (
|
|
789
|
+
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
791
790
|
const l = await i.get(o);
|
|
792
791
|
if (l)
|
|
793
792
|
return Promise.resolve(l);
|
|
@@ -799,7 +798,7 @@ class Le {
|
|
|
799
798
|
"get",
|
|
800
799
|
e,
|
|
801
800
|
t,
|
|
802
|
-
|
|
801
|
+
n
|
|
803
802
|
);
|
|
804
803
|
if (u.status !== 200)
|
|
805
804
|
return a(u);
|
|
@@ -808,33 +807,35 @@ class Le {
|
|
|
808
807
|
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
|
809
808
|
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
|
810
809
|
})), d.data.story || d.data.stories) {
|
|
811
|
-
const
|
|
812
|
-
await this.resolveStories(d.data, t, `${
|
|
810
|
+
const y = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
811
|
+
await this.resolveStories(d.data, t, `${y}`);
|
|
813
812
|
}
|
|
814
|
-
|
|
813
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await i.set(o, d);
|
|
814
|
+
const m = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
815
|
+
return t.token && d.data.cv && (m && S[t.token] && S[t.token] !== d.data.cv && await this.flushCache(), S[t.token] = d.data.cv), l(d);
|
|
815
816
|
} catch (u) {
|
|
816
|
-
if (u.response && u.status === 429 && (
|
|
817
|
+
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
817
818
|
return console.log(
|
|
818
819
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
|
819
|
-
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t,
|
|
820
|
+
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
|
820
821
|
a(u);
|
|
821
822
|
}
|
|
822
823
|
});
|
|
823
824
|
}
|
|
824
|
-
throttledRequest(e, t,
|
|
825
|
-
return this.client.setFetchOptions(
|
|
825
|
+
throttledRequest(e, t, s, n) {
|
|
826
|
+
return this.client.setFetchOptions(n), this.client[e](t, s);
|
|
826
827
|
}
|
|
827
828
|
cacheVersions() {
|
|
828
|
-
return
|
|
829
|
+
return S;
|
|
829
830
|
}
|
|
830
831
|
cacheVersion() {
|
|
831
|
-
return
|
|
832
|
+
return S[this.accessToken];
|
|
832
833
|
}
|
|
833
834
|
setCacheVersion(e) {
|
|
834
|
-
this.accessToken && (
|
|
835
|
+
this.accessToken && (S[this.accessToken] = e);
|
|
835
836
|
}
|
|
836
837
|
clearCacheVersion() {
|
|
837
|
-
this.accessToken && (
|
|
838
|
+
this.accessToken && (S[this.accessToken] = 0);
|
|
838
839
|
}
|
|
839
840
|
cacheProvider() {
|
|
840
841
|
switch (this.cache.type) {
|
|
@@ -856,6 +857,7 @@ class Le {
|
|
|
856
857
|
case "custom":
|
|
857
858
|
if (this.cache.custom)
|
|
858
859
|
return this.cache.custom;
|
|
860
|
+
// eslint-disable-next-line no-fallthrough
|
|
859
861
|
default:
|
|
860
862
|
return {
|
|
861
863
|
get() {
|
|
@@ -877,21 +879,21 @@ class Le {
|
|
|
877
879
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
878
880
|
}
|
|
879
881
|
}
|
|
880
|
-
const
|
|
881
|
-
const { apiOptions: e } =
|
|
882
|
+
const Ue = (r = {}) => {
|
|
883
|
+
const { apiOptions: e } = r;
|
|
882
884
|
if (!e || !e.accessToken) {
|
|
883
885
|
console.error(
|
|
884
886
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
885
887
|
);
|
|
886
888
|
return;
|
|
887
889
|
}
|
|
888
|
-
return { storyblokApi: new
|
|
889
|
-
},
|
|
890
|
-
if (typeof
|
|
890
|
+
return { storyblokApi: new Oe(e) };
|
|
891
|
+
}, He = (r) => {
|
|
892
|
+
if (typeof r != "object" || typeof r._editable > "u")
|
|
891
893
|
return {};
|
|
892
894
|
try {
|
|
893
895
|
const e = JSON.parse(
|
|
894
|
-
|
|
896
|
+
r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
895
897
|
);
|
|
896
898
|
return e ? {
|
|
897
899
|
"data-blok-c": JSON.stringify(e),
|
|
@@ -901,39 +903,39 @@ const ze = (n = {}) => {
|
|
|
901
903
|
return {};
|
|
902
904
|
}
|
|
903
905
|
};
|
|
904
|
-
function
|
|
906
|
+
function Ae(r, e) {
|
|
905
907
|
if (!e)
|
|
906
|
-
return { src:
|
|
907
|
-
let t = 0,
|
|
908
|
-
const
|
|
908
|
+
return { src: r, attrs: {} };
|
|
909
|
+
let t = 0, s = 0;
|
|
910
|
+
const n = {}, o = [];
|
|
909
911
|
function i(a, h, u, d, m) {
|
|
910
912
|
typeof a != "number" || a <= h || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${h} and ${u} (inclusive)`) : m.push(`${d}(${a})`);
|
|
911
913
|
}
|
|
912
914
|
if (typeof e == "object") {
|
|
913
|
-
if (typeof e.width == "number" && e.width > 0 ? (
|
|
914
|
-
const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: m, grayscale:
|
|
915
|
-
h && i(h, 0, 100, "blur", o),
|
|
915
|
+
if (typeof e.width == "number" && e.width > 0 ? (n.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (n.height = e.height, s = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (n.loading = e.loading), e.class && (n.class = e.class), e.filters) {
|
|
916
|
+
const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: m, grayscale: y, quality: b, rotate: _ } = a || {};
|
|
917
|
+
h && i(h, 0, 100, "blur", o), b && i(b, 0, 100, "quality", o), u && i(u, 0, 100, "brightness", o), d && o.push(`fill(${d})`), y && o.push("grayscale()"), _ && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${_})`), m && ["webp", "png", "jpeg"].includes(m) && o.push(`format(${m})`);
|
|
916
918
|
}
|
|
917
|
-
e.srcset && (
|
|
919
|
+
e.srcset && (n.srcset = e.srcset.map((a) => {
|
|
918
920
|
if (typeof a == "number")
|
|
919
|
-
return `${
|
|
921
|
+
return `${r}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
|
|
920
922
|
if (Array.isArray(a) && a.length === 2) {
|
|
921
923
|
const [h, u] = a;
|
|
922
|
-
return `${
|
|
924
|
+
return `${r}/m/${h}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
|
|
923
925
|
} else {
|
|
924
926
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
925
927
|
return;
|
|
926
928
|
}
|
|
927
|
-
}).join(", ")), e.sizes && (
|
|
929
|
+
}).join(", ")), e.sizes && (n.sizes = e.sizes.join(", "));
|
|
928
930
|
}
|
|
929
|
-
let l = `${
|
|
930
|
-
return t > 0 &&
|
|
931
|
+
let l = `${r}/m/`;
|
|
932
|
+
return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
|
|
931
933
|
src: l,
|
|
932
|
-
attrs:
|
|
934
|
+
attrs: n
|
|
933
935
|
};
|
|
934
936
|
}
|
|
935
|
-
var v = /* @__PURE__ */ ((
|
|
936
|
-
const
|
|
937
|
+
var v = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r))(v || {}), T = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(T || {}), G = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(G || {}), I = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(I || {});
|
|
938
|
+
const Le = [
|
|
937
939
|
"area",
|
|
938
940
|
"base",
|
|
939
941
|
"br",
|
|
@@ -948,39 +950,39 @@ const Pe = [
|
|
|
948
950
|
"source",
|
|
949
951
|
"track",
|
|
950
952
|
"wbr"
|
|
951
|
-
],
|
|
952
|
-
function
|
|
953
|
-
return
|
|
953
|
+
], Pe = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), Ce = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
|
|
954
|
+
function Ne(r) {
|
|
955
|
+
return r.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
954
956
|
}
|
|
955
|
-
const B = (
|
|
956
|
-
function q(
|
|
957
|
-
const
|
|
958
|
-
if (
|
|
959
|
-
if (
|
|
960
|
-
return `<${
|
|
957
|
+
const B = (r) => Object.fromEntries(Object.entries(r).filter(([e, t]) => t !== void 0));
|
|
958
|
+
function q(r, e = {}, t) {
|
|
959
|
+
const s = Pe(e), n = s ? `${r} ${s}` : r, o = Array.isArray(t) ? t.join("") : t || "";
|
|
960
|
+
if (r) {
|
|
961
|
+
if (Le.includes(r))
|
|
962
|
+
return `<${n}>`;
|
|
961
963
|
} else return o;
|
|
962
|
-
return `<${
|
|
964
|
+
return `<${n}>${o}</${r}>`;
|
|
963
965
|
}
|
|
964
|
-
function
|
|
966
|
+
function ze(r = {}) {
|
|
965
967
|
let e = 0;
|
|
966
968
|
const {
|
|
967
969
|
renderFn: t = q,
|
|
968
|
-
textFn:
|
|
969
|
-
resolvers:
|
|
970
|
+
textFn: s = Ne,
|
|
971
|
+
resolvers: n = {},
|
|
970
972
|
optimizeImages: o = !1,
|
|
971
973
|
keyedResolvers: i = !1
|
|
972
|
-
} =
|
|
974
|
+
} = r, l = t !== q, a = (c) => (g) => {
|
|
973
975
|
const f = g.attrs || {};
|
|
974
976
|
return i && (f.key = `${c}-${e}`), t(c, f, g.children || null);
|
|
975
977
|
}, h = (c) => {
|
|
976
978
|
const { src: g, alt: f, title: k, srcset: R, sizes: $ } = c.attrs || {};
|
|
977
|
-
let w = g,
|
|
979
|
+
let w = g, E = {};
|
|
978
980
|
if (o) {
|
|
979
|
-
const { src: W, attrs: X } =
|
|
980
|
-
w = W,
|
|
981
|
+
const { src: W, attrs: X } = Ae(g, o);
|
|
982
|
+
w = W, E = X;
|
|
981
983
|
}
|
|
982
|
-
i && (
|
|
983
|
-
...
|
|
984
|
+
i && (E = {
|
|
985
|
+
...E,
|
|
984
986
|
key: `img-${e}`
|
|
985
987
|
});
|
|
986
988
|
const Y = {
|
|
@@ -989,7 +991,7 @@ function Be(n = {}) {
|
|
|
989
991
|
title: k,
|
|
990
992
|
srcset: R,
|
|
991
993
|
sizes: $,
|
|
992
|
-
...
|
|
994
|
+
...E
|
|
993
995
|
};
|
|
994
996
|
return t("img", B(Y));
|
|
995
997
|
}, u = (c) => {
|
|
@@ -1014,21 +1016,21 @@ function Be(n = {}) {
|
|
|
1014
1016
|
}, m = (c) => t("pre", {
|
|
1015
1017
|
...c.attrs,
|
|
1016
1018
|
key: `code-${e}`
|
|
1017
|
-
}, t("code", { key: `code-${e}` }, c.children || "")),
|
|
1018
|
-
const { class: R, id: $, ...w } = k || {},
|
|
1019
|
+
}, t("code", { key: `code-${e}` }, c.children || "")), y = (c, g = !1) => ({ text: f, attrs: k }) => {
|
|
1020
|
+
const { class: R, id: $, ...w } = k || {}, E = g ? {
|
|
1019
1021
|
class: R,
|
|
1020
1022
|
id: $,
|
|
1021
|
-
style:
|
|
1023
|
+
style: Ce(w) || void 0
|
|
1022
1024
|
} : k || {};
|
|
1023
|
-
return i && (
|
|
1024
|
-
},
|
|
1025
|
+
return i && (E.key = `${c}-${e}`), t(c, B(E), f);
|
|
1026
|
+
}, b = (c) => P(c), _ = (c) => {
|
|
1025
1027
|
const { marks: g, ...f } = c;
|
|
1026
1028
|
return "text" in c ? g ? g.reduce(
|
|
1027
|
-
(k, R) =>
|
|
1029
|
+
(k, R) => b({ ...R, text: k }),
|
|
1028
1030
|
// Fix: Ensure render function returns a string
|
|
1029
|
-
|
|
1031
|
+
b({ ...f, children: f.children })
|
|
1030
1032
|
// Fix: Cast children to string
|
|
1031
|
-
) :
|
|
1033
|
+
) : s(f.text) : "";
|
|
1032
1034
|
}, j = (c) => {
|
|
1033
1035
|
const { linktype: g, href: f, anchor: k, ...R } = c.attrs || {};
|
|
1034
1036
|
let $ = "";
|
|
@@ -1074,17 +1076,17 @@ function Be(n = {}) {
|
|
|
1074
1076
|
[G.TEXT, _],
|
|
1075
1077
|
[T.LINK, j],
|
|
1076
1078
|
[T.ANCHOR, j],
|
|
1077
|
-
[T.STYLED,
|
|
1078
|
-
[T.BOLD,
|
|
1079
|
-
[T.TEXT_STYLE,
|
|
1080
|
-
[T.ITALIC,
|
|
1081
|
-
[T.UNDERLINE,
|
|
1082
|
-
[T.STRIKE,
|
|
1083
|
-
[T.CODE,
|
|
1084
|
-
[T.SUPERSCRIPT,
|
|
1085
|
-
[T.SUBSCRIPT,
|
|
1086
|
-
[T.HIGHLIGHT,
|
|
1087
|
-
...Object.entries(
|
|
1079
|
+
[T.STYLED, y("span", !0)],
|
|
1080
|
+
[T.BOLD, y("strong")],
|
|
1081
|
+
[T.TEXT_STYLE, y("span", !0)],
|
|
1082
|
+
[T.ITALIC, y("em")],
|
|
1083
|
+
[T.UNDERLINE, y("u")],
|
|
1084
|
+
[T.STRIKE, y("s")],
|
|
1085
|
+
[T.CODE, y("code")],
|
|
1086
|
+
[T.SUPERSCRIPT, y("sup")],
|
|
1087
|
+
[T.SUBSCRIPT, y("sub")],
|
|
1088
|
+
[T.HIGHLIGHT, y("mark")],
|
|
1089
|
+
...Object.entries(n).map(([c, g]) => [c, g])
|
|
1088
1090
|
]);
|
|
1089
1091
|
function x(c) {
|
|
1090
1092
|
e += 1;
|
|
@@ -1093,91 +1095,91 @@ function Be(n = {}) {
|
|
|
1093
1095
|
return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
|
|
1094
1096
|
if (c.type === "text")
|
|
1095
1097
|
return g(c);
|
|
1096
|
-
const f = c.content ? c.content.map(
|
|
1098
|
+
const f = c.content ? c.content.map(P) : void 0;
|
|
1097
1099
|
return g({
|
|
1098
1100
|
...c,
|
|
1099
1101
|
children: f
|
|
1100
1102
|
// Fix: Update the type of 'children' to Node[]
|
|
1101
1103
|
});
|
|
1102
1104
|
}
|
|
1103
|
-
function
|
|
1105
|
+
function P(c) {
|
|
1104
1106
|
return c.type === "doc" ? l ? c.content.map(x) : c.content.map(x).join("") : Array.isArray(c) ? c.map(x) : x(c);
|
|
1105
1107
|
}
|
|
1106
1108
|
return {
|
|
1107
|
-
render:
|
|
1109
|
+
render: P
|
|
1108
1110
|
};
|
|
1109
1111
|
}
|
|
1110
1112
|
let N, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
1111
|
-
const
|
|
1112
|
-
var
|
|
1113
|
-
const
|
|
1113
|
+
const De = (r, e, t = {}) => {
|
|
1114
|
+
var s;
|
|
1115
|
+
const n = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
1114
1116
|
"_storyblok"
|
|
1115
|
-
), i = o !== null && +o ===
|
|
1116
|
-
if (!(!
|
|
1117
|
-
if (!
|
|
1117
|
+
), i = o !== null && +o === r;
|
|
1118
|
+
if (!(!n || !i)) {
|
|
1119
|
+
if (!r) {
|
|
1118
1120
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
1119
1121
|
return;
|
|
1120
1122
|
}
|
|
1121
1123
|
window.storyblokRegisterEvent(() => {
|
|
1122
1124
|
new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
|
|
1123
1125
|
var a;
|
|
1124
|
-
l && (l.action === "input" && ((a = l.story) == null ? void 0 : a.id) ===
|
|
1126
|
+
l && (l.action === "input" && ((a = l.story) == null ? void 0 : a.id) === r ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === r && window.location.reload());
|
|
1125
1127
|
});
|
|
1126
1128
|
});
|
|
1127
1129
|
}
|
|
1128
|
-
}, V = (
|
|
1129
|
-
|
|
1130
|
-
let
|
|
1131
|
-
return t.attrs.body.forEach((
|
|
1132
|
-
|
|
1130
|
+
}, V = (r, e) => {
|
|
1131
|
+
r.addNode("blok", (t) => {
|
|
1132
|
+
let s = "";
|
|
1133
|
+
return t.attrs.body.forEach((n) => {
|
|
1134
|
+
s += e(n.component, n);
|
|
1133
1135
|
}), {
|
|
1134
|
-
html:
|
|
1136
|
+
html: s
|
|
1135
1137
|
};
|
|
1136
1138
|
});
|
|
1137
|
-
},
|
|
1139
|
+
}, Be = (r = {}) => {
|
|
1138
1140
|
var e, t;
|
|
1139
1141
|
const {
|
|
1140
|
-
bridge:
|
|
1141
|
-
accessToken:
|
|
1142
|
+
bridge: s,
|
|
1143
|
+
accessToken: n,
|
|
1142
1144
|
use: o = [],
|
|
1143
1145
|
apiOptions: i = {},
|
|
1144
1146
|
richText: l = {},
|
|
1145
1147
|
bridgeUrl: a
|
|
1146
|
-
} =
|
|
1147
|
-
i.accessToken = i.accessToken ||
|
|
1148
|
-
const h = { bridge:
|
|
1148
|
+
} = r;
|
|
1149
|
+
i.accessToken = i.accessToken || n;
|
|
1150
|
+
const h = { bridge: s, apiOptions: i };
|
|
1149
1151
|
let u = {};
|
|
1150
1152
|
o.forEach((m) => {
|
|
1151
1153
|
u = { ...u, ...m(h) };
|
|
1152
1154
|
}), a && (M = a);
|
|
1153
1155
|
const d = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
1154
|
-
return
|
|
1155
|
-
},
|
|
1156
|
+
return s !== !1 && d && F(M), N = new L(l.schema), l.resolver && V(N, l.resolver), u;
|
|
1157
|
+
}, Me = (r) => {
|
|
1156
1158
|
var e;
|
|
1157
|
-
return !
|
|
1158
|
-
},
|
|
1159
|
-
let
|
|
1160
|
-
if (!
|
|
1159
|
+
return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
|
1160
|
+
}, qe = (r, e, t) => {
|
|
1161
|
+
let s = t || N;
|
|
1162
|
+
if (!s) {
|
|
1161
1163
|
console.error(
|
|
1162
1164
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1163
1165
|
);
|
|
1164
1166
|
return;
|
|
1165
1167
|
}
|
|
1166
|
-
return
|
|
1167
|
-
},
|
|
1168
|
+
return Me(r) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(r, {}, !1));
|
|
1169
|
+
}, Fe = () => F(M);
|
|
1168
1170
|
export {
|
|
1169
1171
|
v as BlockTypes,
|
|
1170
1172
|
T as MarkTypes,
|
|
1171
1173
|
L as RichTextResolver,
|
|
1172
1174
|
je as RichTextSchema,
|
|
1173
1175
|
G as TextTypes,
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1176
|
+
Ue as apiPlugin,
|
|
1177
|
+
Me as isRichTextEmpty,
|
|
1178
|
+
Fe as loadStoryblokBridge,
|
|
1179
|
+
De as registerStoryblokBridge,
|
|
1180
|
+
qe as renderRichText,
|
|
1181
|
+
ze as richTextResolver,
|
|
1182
|
+
He as storyblokEditable,
|
|
1183
|
+
Be as storyblokInit,
|
|
1184
|
+
De as useStoryblokBridge
|
|
1183
1185
|
};
|