@storyblok/js 3.1.9 → 3.2.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/LICENSE +21 -0
- package/README.md +35 -36
- package/dist/{types/modules/api.d.ts → api.d.ts} +1 -1
- package/dist/editable.d.ts +9 -0
- package/dist/index.d.ts +18 -0
- package/dist/storyblok-js.js +8 -2
- package/dist/storyblok-js.mjs +429 -378
- package/dist/types/index.d.ts +64 -13
- package/package.json +55 -63
- package/dist/types/modules/editable.d.ts +0 -9
- package/dist/types/types.d.ts +0 -63
- /package/dist/{types/modules/bridge.d.ts → bridge.d.ts} +0 -0
package/dist/storyblok-js.mjs
CHANGED
@@ -1,62 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* name: @storyblok/js
|
3
|
+
* (c) 2024
|
4
|
+
* description: SDK to integrate Storyblok into your project using JavaScript.
|
5
|
+
* author: undefined
|
6
|
+
*/
|
1
7
|
let H = !1;
|
2
|
-
const U = [],
|
8
|
+
const U = [], F = (i) => new Promise((e, t) => {
|
3
9
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
4
10
|
if (window.location === window.parent.location) {
|
5
11
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
6
12
|
return;
|
7
13
|
}
|
8
14
|
H ? r() : U.push(r);
|
9
|
-
}, document.getElementById("storyblok-javascript-bridge")))
|
15
|
+
}, document.getElementById("storyblok-javascript-bridge")))
|
16
|
+
return;
|
10
17
|
const s = document.createElement("script");
|
11
18
|
s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
12
|
-
U.forEach((
|
19
|
+
U.forEach((o) => o()), H = !0, e(r);
|
13
20
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
14
21
|
});
|
15
|
-
var
|
16
|
-
class
|
22
|
+
var Q = Object.defineProperty, Z = (i, e, t) => e in i ? Q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => Z(i, typeof e != "symbol" ? e + "" : e, t);
|
23
|
+
class ee extends Error {
|
17
24
|
constructor(e) {
|
18
25
|
super(e), this.name = "AbortError";
|
19
26
|
}
|
20
27
|
}
|
21
|
-
function
|
28
|
+
function te(i, e, t) {
|
22
29
|
if (!Number.isFinite(e))
|
23
30
|
throw new TypeError("Expected `limit` to be a finite number");
|
24
31
|
if (!Number.isFinite(t))
|
25
32
|
throw new TypeError("Expected `interval` to be a finite number");
|
26
33
|
const s = [];
|
27
|
-
let r = [],
|
34
|
+
let r = [], o = 0, n = !1;
|
28
35
|
const l = async () => {
|
29
|
-
|
36
|
+
o++;
|
30
37
|
const c = s.shift();
|
31
38
|
if (c)
|
32
39
|
try {
|
33
|
-
const
|
34
|
-
c.resolve(
|
35
|
-
} catch (
|
36
|
-
c.reject(
|
40
|
+
const d = await i(...c.args);
|
41
|
+
c.resolve(d);
|
42
|
+
} catch (d) {
|
43
|
+
c.reject(d);
|
37
44
|
}
|
38
|
-
const
|
39
|
-
|
45
|
+
const u = setTimeout(() => {
|
46
|
+
o--, s.length > 0 && l(), r = r.filter((d) => d !== u);
|
40
47
|
}, t);
|
41
|
-
r.includes(
|
42
|
-
}, a = (...c) =>
|
48
|
+
r.includes(u) || r.push(u);
|
49
|
+
}, a = (...c) => n ? Promise.reject(
|
43
50
|
new Error(
|
44
51
|
"Throttled function is already aborted and not accepting new promises"
|
45
52
|
)
|
46
|
-
) : new Promise((
|
53
|
+
) : new Promise((u, d) => {
|
47
54
|
s.push({
|
48
|
-
resolve:
|
49
|
-
reject:
|
55
|
+
resolve: u,
|
56
|
+
reject: d,
|
50
57
|
args: c
|
51
|
-
}),
|
58
|
+
}), o < e && l();
|
52
59
|
});
|
53
60
|
return a.abort = () => {
|
54
|
-
|
55
|
-
(c) => c.reject(() => new
|
61
|
+
n = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
62
|
+
(c) => c.reject(() => new ee("Throttle function aborted"))
|
56
63
|
), s.length = 0;
|
57
64
|
}, a;
|
58
65
|
}
|
59
|
-
|
66
|
+
class A {
|
60
67
|
constructor() {
|
61
68
|
p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
62
69
|
...e,
|
@@ -64,7 +71,7 @@ let O = class {
|
|
64
71
|
page: s
|
65
72
|
})), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), p(this, "range", (e = 0, t = e) => {
|
66
73
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
67
|
-
return this.arrayFrom(s, (
|
74
|
+
return this.arrayFrom(s, (o, n) => n * r + e);
|
68
75
|
}), p(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), p(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), p(this, "escapeHTML", function(e) {
|
69
76
|
const t = {
|
70
77
|
"&": "&",
|
@@ -73,7 +80,7 @@ let O = class {
|
|
73
80
|
'"': """,
|
74
81
|
"'": "'"
|
75
82
|
}, s = /[&<>"']/g, r = new RegExp(s.source);
|
76
|
-
return e && r.test(e) ? e.replace(s, (
|
83
|
+
return e && r.test(e) ? e.replace(s, (o) => t[o]) : e;
|
77
84
|
});
|
78
85
|
}
|
79
86
|
/**
|
@@ -85,16 +92,16 @@ let O = class {
|
|
85
92
|
*/
|
86
93
|
stringify(e, t, s) {
|
87
94
|
const r = [];
|
88
|
-
for (const
|
89
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
95
|
+
for (const o in e) {
|
96
|
+
if (!Object.prototype.hasOwnProperty.call(e, o))
|
90
97
|
continue;
|
91
|
-
const
|
98
|
+
const n = e[o], l = s ? "" : encodeURIComponent(o);
|
92
99
|
let a;
|
93
|
-
typeof
|
94
|
-
|
100
|
+
typeof n == "object" ? a = this.stringify(
|
101
|
+
n,
|
95
102
|
t ? t + encodeURIComponent(`[${l}]`) : l,
|
96
|
-
Array.isArray(
|
97
|
-
) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(
|
103
|
+
Array.isArray(n)
|
104
|
+
) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, r.push(a);
|
98
105
|
}
|
99
106
|
return r.join("&");
|
100
107
|
}
|
@@ -104,35 +111,35 @@ let O = class {
|
|
104
111
|
* @return {string} The base URL of the region
|
105
112
|
*/
|
106
113
|
getRegionURL(e) {
|
107
|
-
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn",
|
114
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
108
115
|
switch (e) {
|
109
116
|
case "us":
|
110
117
|
return s;
|
111
118
|
case "cn":
|
112
119
|
return r;
|
113
120
|
case "ap":
|
114
|
-
return n;
|
115
|
-
case "ca":
|
116
121
|
return o;
|
122
|
+
case "ca":
|
123
|
+
return n;
|
117
124
|
default:
|
118
125
|
return t;
|
119
126
|
}
|
120
127
|
}
|
121
|
-
}
|
122
|
-
const
|
128
|
+
}
|
129
|
+
const se = function(i, e) {
|
123
130
|
const t = {};
|
124
131
|
for (const s in i) {
|
125
132
|
const r = i[s];
|
126
133
|
e.includes(s) && r !== null && (t[s] = r);
|
127
134
|
}
|
128
135
|
return t;
|
129
|
-
},
|
136
|
+
}, re = (i) => i === "email", ie = () => ({
|
130
137
|
singleTag: "hr"
|
131
|
-
}),
|
138
|
+
}), oe = () => ({
|
132
139
|
tag: "blockquote"
|
133
|
-
}),
|
140
|
+
}), ne = () => ({
|
134
141
|
tag: "ul"
|
135
|
-
}),
|
142
|
+
}), ae = (i) => ({
|
136
143
|
tag: [
|
137
144
|
"pre",
|
138
145
|
{
|
@@ -140,24 +147,24 @@ const ee = function(i, e) {
|
|
140
147
|
attrs: i.attrs
|
141
148
|
}
|
142
149
|
]
|
143
|
-
}),
|
150
|
+
}), le = () => ({
|
144
151
|
singleTag: "br"
|
145
|
-
}),
|
152
|
+
}), ce = (i) => ({
|
146
153
|
tag: `h${i.attrs.level}`
|
147
|
-
}),
|
154
|
+
}), he = (i) => ({
|
148
155
|
singleTag: [
|
149
156
|
{
|
150
157
|
tag: "img",
|
151
|
-
attrs:
|
158
|
+
attrs: se(i.attrs, ["src", "alt", "title"])
|
152
159
|
}
|
153
160
|
]
|
154
|
-
}),
|
161
|
+
}), ue = () => ({
|
155
162
|
tag: "li"
|
156
|
-
}),
|
163
|
+
}), de = () => ({
|
157
164
|
tag: "ol"
|
158
|
-
}),
|
165
|
+
}), pe = () => ({
|
159
166
|
tag: "p"
|
160
|
-
}),
|
167
|
+
}), ge = (i) => ({
|
161
168
|
tag: [
|
162
169
|
{
|
163
170
|
tag: "span",
|
@@ -168,25 +175,25 @@ const ee = function(i, e) {
|
|
168
175
|
}
|
169
176
|
}
|
170
177
|
]
|
171
|
-
}),
|
178
|
+
}), fe = () => ({
|
172
179
|
tag: "b"
|
173
|
-
}),
|
180
|
+
}), me = () => ({
|
174
181
|
tag: "s"
|
175
|
-
}),
|
182
|
+
}), ye = () => ({
|
176
183
|
tag: "u"
|
177
|
-
}),
|
184
|
+
}), be = () => ({
|
178
185
|
tag: "strong"
|
179
|
-
}),
|
186
|
+
}), ke = () => ({
|
180
187
|
tag: "code"
|
181
|
-
}),
|
188
|
+
}), ve = () => ({
|
182
189
|
tag: "i"
|
183
|
-
}),
|
190
|
+
}), $e = (i) => {
|
184
191
|
if (!i.attrs)
|
185
192
|
return {
|
186
193
|
tag: ""
|
187
194
|
};
|
188
|
-
const e = new
|
189
|
-
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")),
|
195
|
+
const e = new A().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
|
196
|
+
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), re(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
190
197
|
for (const r in t.custom)
|
191
198
|
t[r] = t.custom[r];
|
192
199
|
delete t.custom;
|
@@ -199,25 +206,25 @@ const ee = function(i, e) {
|
|
199
206
|
}
|
200
207
|
]
|
201
208
|
};
|
202
|
-
},
|
209
|
+
}, Te = (i) => ({
|
203
210
|
tag: [
|
204
211
|
{
|
205
212
|
tag: "span",
|
206
213
|
attrs: i.attrs
|
207
214
|
}
|
208
215
|
]
|
209
|
-
}),
|
216
|
+
}), we = () => ({
|
210
217
|
tag: "sub"
|
211
|
-
}),
|
218
|
+
}), Re = () => ({
|
212
219
|
tag: "sup"
|
213
|
-
}),
|
220
|
+
}), Se = (i) => ({
|
214
221
|
tag: [
|
215
222
|
{
|
216
223
|
tag: "span",
|
217
224
|
attrs: i.attrs
|
218
225
|
}
|
219
226
|
]
|
220
|
-
}),
|
227
|
+
}), _e = (i) => {
|
221
228
|
var e;
|
222
229
|
return (e = i.attrs) != null && e.color ? {
|
223
230
|
tag: [
|
@@ -231,7 +238,7 @@ const ee = function(i, e) {
|
|
231
238
|
} : {
|
232
239
|
tag: ""
|
233
240
|
};
|
234
|
-
},
|
241
|
+
}, Ee = (i) => {
|
235
242
|
var e;
|
236
243
|
return (e = i.attrs) != null && e.color ? {
|
237
244
|
tag: [
|
@@ -245,36 +252,36 @@ const ee = function(i, e) {
|
|
245
252
|
} : {
|
246
253
|
tag: ""
|
247
254
|
};
|
248
|
-
},
|
255
|
+
}, je = {
|
249
256
|
nodes: {
|
250
|
-
horizontal_rule:
|
251
|
-
blockquote:
|
252
|
-
bullet_list:
|
253
|
-
code_block:
|
254
|
-
hard_break:
|
255
|
-
heading:
|
256
|
-
image:
|
257
|
-
list_item:
|
258
|
-
ordered_list:
|
259
|
-
paragraph:
|
260
|
-
emoji:
|
257
|
+
horizontal_rule: ie,
|
258
|
+
blockquote: oe,
|
259
|
+
bullet_list: ne,
|
260
|
+
code_block: ae,
|
261
|
+
hard_break: le,
|
262
|
+
heading: ce,
|
263
|
+
image: he,
|
264
|
+
list_item: ue,
|
265
|
+
ordered_list: de,
|
266
|
+
paragraph: pe,
|
267
|
+
emoji: ge
|
261
268
|
},
|
262
269
|
marks: {
|
263
|
-
bold:
|
264
|
-
strike:
|
265
|
-
underline:
|
266
|
-
strong:
|
267
|
-
code:
|
268
|
-
italic:
|
269
|
-
link:
|
270
|
-
styled:
|
271
|
-
subscript:
|
272
|
-
superscript:
|
273
|
-
anchor:
|
274
|
-
highlight:
|
275
|
-
textStyle:
|
276
|
-
}
|
277
|
-
},
|
270
|
+
bold: fe,
|
271
|
+
strike: me,
|
272
|
+
underline: ye,
|
273
|
+
strong: be,
|
274
|
+
code: ke,
|
275
|
+
italic: ve,
|
276
|
+
link: $e,
|
277
|
+
styled: Te,
|
278
|
+
subscript: we,
|
279
|
+
superscript: Re,
|
280
|
+
anchor: Se,
|
281
|
+
highlight: _e,
|
282
|
+
textStyle: Ee
|
283
|
+
}
|
284
|
+
}, Ie = function(i) {
|
278
285
|
const e = {
|
279
286
|
"&": "&",
|
280
287
|
"<": "<",
|
@@ -285,9 +292,9 @@ const ee = function(i, e) {
|
|
285
292
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
286
293
|
};
|
287
294
|
let z = !1;
|
288
|
-
class
|
295
|
+
class xe {
|
289
296
|
constructor(e) {
|
290
|
-
p(this, "marks"), p(this, "nodes"), e || (e =
|
297
|
+
p(this, "marks"), p(this, "nodes"), e || (e = je), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
291
298
|
}
|
292
299
|
addNode(e, t) {
|
293
300
|
this.nodes[e] = t;
|
@@ -300,8 +307,8 @@ class Ie {
|
|
300
307
|
"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/"
|
301
308
|
), z = !0), e && e.content && Array.isArray(e.content)) {
|
302
309
|
let r = "";
|
303
|
-
return e.content.forEach((
|
304
|
-
r += this.renderNode(
|
310
|
+
return e.content.forEach((o) => {
|
311
|
+
r += this.renderNode(o);
|
305
312
|
}), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
|
306
313
|
}
|
307
314
|
return console.warn(
|
@@ -332,32 +339,32 @@ class Ie {
|
|
332
339
|
), "";
|
333
340
|
}
|
334
341
|
optimizeImages(e, t) {
|
335
|
-
let s = 0, r = 0,
|
336
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
337
|
-
const l = s > 0 || r > 0 ||
|
342
|
+
let s = 0, r = 0, o = "", n = "";
|
343
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = `/filters${n}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
|
344
|
+
const l = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
|
338
345
|
return e = e.replace(
|
339
346
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
340
347
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
341
348
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
342
|
-
var c,
|
343
|
-
const
|
349
|
+
var c, u;
|
350
|
+
const d = a.match(
|
344
351
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
345
352
|
);
|
346
|
-
if (
|
347
|
-
const
|
348
|
-
srcset: (c = t.srcset) == null ? void 0 : c.map((
|
349
|
-
if (typeof
|
350
|
-
return `//${
|
351
|
-
if (typeof
|
352
|
-
let
|
353
|
-
return typeof
|
353
|
+
if (d && d.length > 0) {
|
354
|
+
const m = {
|
355
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((b) => {
|
356
|
+
if (typeof b == "number")
|
357
|
+
return `//${d}/m/${b}x0${n} ${b}w`;
|
358
|
+
if (typeof b == "object" && b.length === 2) {
|
359
|
+
let S = 0, j = 0;
|
360
|
+
return typeof b[0] == "number" && (S = b[0]), typeof b[1] == "number" && (j = b[1]), `//${d}/m/${S}x${j}${n} ${S}w`;
|
354
361
|
}
|
355
362
|
return "";
|
356
363
|
}).join(", "),
|
357
|
-
sizes: (
|
364
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((b) => b).join(", ")
|
358
365
|
};
|
359
|
-
let
|
360
|
-
return
|
366
|
+
let y = "";
|
367
|
+
return m.srcset && (y += `srcset="${m.srcset}" `), m.sizes && (y += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${y.trim()}`);
|
361
368
|
}
|
362
369
|
return a;
|
363
370
|
})), e;
|
@@ -365,15 +372,15 @@ class Ie {
|
|
365
372
|
renderNode(e) {
|
366
373
|
const t = [];
|
367
374
|
e.marks && e.marks.forEach((r) => {
|
368
|
-
const
|
369
|
-
|
375
|
+
const o = this.getMatchingMark(r);
|
376
|
+
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
370
377
|
});
|
371
378
|
const s = this.getMatchingNode(e);
|
372
379
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
373
380
|
t.push(this.renderNode(r));
|
374
|
-
}) : e.text ? t.push(
|
375
|
-
const
|
376
|
-
|
381
|
+
}) : 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((r) => {
|
382
|
+
const o = this.getMatchingMark(r);
|
383
|
+
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
377
384
|
}), t.join("");
|
378
385
|
}
|
379
386
|
renderTag(e, t) {
|
@@ -383,10 +390,10 @@ class Ie {
|
|
383
390
|
{
|
384
391
|
let r = `<${s.tag}`;
|
385
392
|
if (s.attrs) {
|
386
|
-
for (const
|
387
|
-
if (Object.prototype.hasOwnProperty.call(s.attrs,
|
388
|
-
const
|
389
|
-
|
393
|
+
for (const o in s.attrs)
|
394
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, o)) {
|
395
|
+
const n = s.attrs[o];
|
396
|
+
n !== null && (r += ` ${o}="${n}"`);
|
390
397
|
}
|
391
398
|
}
|
392
399
|
return `${r}${t}>`;
|
@@ -426,8 +433,8 @@ class Ie {
|
|
426
433
|
return this.renderTag(t, " /");
|
427
434
|
}
|
428
435
|
}
|
429
|
-
const L =
|
430
|
-
class
|
436
|
+
const L = xe;
|
437
|
+
class Oe {
|
431
438
|
constructor(e) {
|
432
439
|
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 = {};
|
433
440
|
}
|
@@ -447,7 +454,7 @@ class je {
|
|
447
454
|
return this.url = e, this.parameters = t, this._methodHandler("put");
|
448
455
|
}
|
449
456
|
delete(e, t) {
|
450
|
-
return this.url = e, this.parameters = t, this._methodHandler("delete");
|
457
|
+
return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
|
451
458
|
}
|
452
459
|
async _responseHandler(e) {
|
453
460
|
const t = [], s = {
|
@@ -466,21 +473,21 @@ class je {
|
|
466
473
|
async _methodHandler(e) {
|
467
474
|
let t = `${this.baseURL}${this.url}`, s = null;
|
468
475
|
if (e === "get") {
|
469
|
-
const a = new
|
476
|
+
const a = new A();
|
470
477
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
471
478
|
this.parameters
|
472
479
|
)}`;
|
473
480
|
} else
|
474
481
|
s = JSON.stringify(this.parameters);
|
475
|
-
const r = new URL(t),
|
482
|
+
const r = new URL(t), o = new AbortController(), { signal: n } = o;
|
476
483
|
let l;
|
477
|
-
this.timeout && (l = setTimeout(() =>
|
484
|
+
this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
|
478
485
|
try {
|
479
486
|
const a = await this.fetch(`${r}`, {
|
480
487
|
method: e,
|
481
488
|
headers: this.headers,
|
482
489
|
body: s,
|
483
|
-
signal:
|
490
|
+
signal: n,
|
484
491
|
...this.fetchOptions
|
485
492
|
});
|
486
493
|
this.timeout && clearTimeout(l);
|
@@ -505,23 +512,23 @@ class je {
|
|
505
512
|
return new Promise((s, r) => {
|
506
513
|
if (t.test(`${e.status}`))
|
507
514
|
return s(e);
|
508
|
-
const
|
515
|
+
const o = {
|
509
516
|
message: e.statusText,
|
510
517
|
status: e.status,
|
511
518
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
512
519
|
};
|
513
|
-
r(
|
520
|
+
r(o);
|
514
521
|
});
|
515
522
|
}
|
516
523
|
}
|
517
|
-
const
|
524
|
+
const Ae = Oe, D = "SB-Agent", P = {
|
518
525
|
defaultAgentName: "SB-JS-CLIENT",
|
519
526
|
defaultAgentVersion: "SB-Agent-Version",
|
520
527
|
packageVersion: "6.0.0"
|
521
528
|
};
|
522
|
-
let
|
529
|
+
let O = {};
|
523
530
|
const E = {};
|
524
|
-
class
|
531
|
+
class Le {
|
525
532
|
/**
|
526
533
|
*
|
527
534
|
* @param config ISbConfig interface
|
@@ -531,22 +538,22 @@ class Oe {
|
|
531
538
|
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");
|
532
539
|
let s = e.endpoint || t;
|
533
540
|
if (!s) {
|
534
|
-
const
|
535
|
-
e.oauthToken ? s = `${l}://${
|
541
|
+
const n = new A().getRegionURL, l = e.https === !1 ? "http" : "https";
|
542
|
+
e.oauthToken ? s = `${l}://${n(e.region)}/v1` : s = `${l}://${n(e.region)}/v2`;
|
536
543
|
}
|
537
544
|
const r = new Headers();
|
538
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([
|
539
|
-
r.set(
|
540
|
-
}), r.has(
|
541
|
-
|
542
|
-
|
545
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, l]) => {
|
546
|
+
r.set(n, l);
|
547
|
+
}), r.has(D) || (r.set(D, P.defaultAgentName), r.set(
|
548
|
+
P.defaultAgentVersion,
|
549
|
+
P.packageVersion
|
543
550
|
));
|
544
|
-
let
|
545
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
551
|
+
let o = 5;
|
552
|
+
e.oauthToken && (r.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(
|
546
553
|
this.throttledRequest.bind(this),
|
547
|
-
|
554
|
+
o,
|
548
555
|
1e3
|
549
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new
|
556
|
+
), 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 Ae({
|
550
557
|
baseURL: s,
|
551
558
|
timeout: e.timeout || 0,
|
552
559
|
headers: r,
|
@@ -570,30 +577,30 @@ class Oe {
|
|
570
577
|
factoryParamOptions(e, t) {
|
571
578
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
572
579
|
}
|
573
|
-
makeRequest(e, t, s, r,
|
574
|
-
const
|
580
|
+
makeRequest(e, t, s, r, o) {
|
581
|
+
const n = this.factoryParamOptions(
|
575
582
|
e,
|
576
583
|
this.helpers.getOptionsPage(t, s, r)
|
577
584
|
);
|
578
|
-
return this.cacheResponse(e,
|
585
|
+
return this.cacheResponse(e, n, void 0, o);
|
579
586
|
}
|
580
587
|
get(e, t, s) {
|
581
588
|
t || (t = {});
|
582
|
-
const r = `/${e}`,
|
583
|
-
return this.cacheResponse(r,
|
589
|
+
const r = `/${e}`, o = this.factoryParamOptions(r, t);
|
590
|
+
return this.cacheResponse(r, o, void 0, s);
|
584
591
|
}
|
585
592
|
async getAll(e, t, s, r) {
|
586
|
-
const
|
587
|
-
o,
|
588
|
-
t,
|
593
|
+
const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = s ?? n.substring(n.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
|
589
594
|
n,
|
595
|
+
t,
|
596
|
+
o,
|
590
597
|
a,
|
591
598
|
r
|
592
|
-
),
|
593
|
-
this.helpers.range(a,
|
594
|
-
(
|
599
|
+
), u = c.total ? Math.ceil(c.total / o) : 1, d = await this.helpers.asyncMap(
|
600
|
+
this.helpers.range(a, u),
|
601
|
+
(m) => this.makeRequest(n, t, o, m + 1, r)
|
595
602
|
);
|
596
|
-
return this.helpers.flatMap([c, ...
|
603
|
+
return this.helpers.flatMap([c, ...d], (m) => Object.values(m.data[l]));
|
597
604
|
}
|
598
605
|
post(e, t, s) {
|
599
606
|
const r = `/${e}`;
|
@@ -608,6 +615,7 @@ class Oe {
|
|
608
615
|
);
|
609
616
|
}
|
610
617
|
delete(e, t, s) {
|
618
|
+
t || (t = {});
|
611
619
|
const r = `/${e}`;
|
612
620
|
return Promise.resolve(
|
613
621
|
this.throttle("delete", r, t, s)
|
@@ -642,34 +650,65 @@ class Oe {
|
|
642
650
|
* @returns string | object
|
643
651
|
*/
|
644
652
|
getStoryReference(e, t) {
|
645
|
-
return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.
|
646
|
-
this.relations[e][t]
|
647
|
-
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
653
|
+
return this.relations[e][t] ? JSON.parse(this.stringifiedStoriesCache[t] || JSON.stringify(this.relations[e][t])) : t;
|
648
654
|
}
|
655
|
+
/**
|
656
|
+
* Resolves a field's value by replacing UUIDs with their corresponding story references
|
657
|
+
* @param jtree - The JSON tree object containing the field to resolve
|
658
|
+
* @param treeItem - The key of the field to resolve
|
659
|
+
* @param resolveId - The unique identifier for the current resolution context
|
660
|
+
*
|
661
|
+
* This method handles both single string UUIDs and arrays of UUIDs:
|
662
|
+
* - For single strings: directly replaces the UUID with the story reference
|
663
|
+
* - For arrays: maps through each UUID and replaces with corresponding story references
|
664
|
+
*/
|
665
|
+
_resolveField(e, t, s) {
|
666
|
+
const r = e[t];
|
667
|
+
typeof r == "string" ? e[t] = this.getStoryReference(s, r) : Array.isArray(r) && (e[t] = r.map(
|
668
|
+
(o) => this.getStoryReference(s, o)
|
669
|
+
).filter(Boolean));
|
670
|
+
}
|
671
|
+
/**
|
672
|
+
* Inserts relations into the JSON tree by resolving references
|
673
|
+
* @param jtree - The JSON tree object to process
|
674
|
+
* @param treeItem - The current field being processed
|
675
|
+
* @param fields - The relation patterns to resolve (string or array of strings)
|
676
|
+
* @param resolveId - The unique identifier for the current resolution context
|
677
|
+
*
|
678
|
+
* This method handles two types of relation patterns:
|
679
|
+
* 1. Nested relations: matches fields that end with the current field name
|
680
|
+
* Example: If treeItem is "event_type", it matches patterns like "*.event_type"
|
681
|
+
*
|
682
|
+
* 2. Direct component relations: matches exact component.field patterns
|
683
|
+
* Example: "event.event_type" for component "event" and field "event_type"
|
684
|
+
*
|
685
|
+
* The method supports both string and array formats for the fields parameter,
|
686
|
+
* allowing flexible specification of relation patterns.
|
687
|
+
*/
|
649
688
|
_insertRelations(e, t, s, r) {
|
650
|
-
|
689
|
+
if (Array.isArray(s) ? s.find((n) => n.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
|
690
|
+
this._resolveField(e, t, r);
|
691
|
+
return;
|
692
|
+
}
|
693
|
+
const o = e.component ? `${e.component}.${t}` : t;
|
694
|
+
(Array.isArray(s) ? s.includes(o) : s === o) && this._resolveField(e, t, r);
|
651
695
|
}
|
696
|
+
/**
|
697
|
+
* Recursively traverses and resolves relations in the story content tree
|
698
|
+
* @param story - The story object containing the content to process
|
699
|
+
* @param fields - The relation patterns to resolve
|
700
|
+
* @param resolveId - The unique identifier for the current resolution context
|
701
|
+
*/
|
652
702
|
iterateTree(e, t, s) {
|
653
|
-
const r = (n) => {
|
654
|
-
if (
|
655
|
-
if (
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
(n.component && n._uid || n.type === "link") && (this._insertRelations(
|
663
|
-
n,
|
664
|
-
o,
|
665
|
-
t,
|
666
|
-
s
|
667
|
-
), this._insertLinks(
|
668
|
-
n,
|
669
|
-
o,
|
670
|
-
s
|
671
|
-
)), r(n[o]);
|
672
|
-
}
|
703
|
+
const r = (o, n = "") => {
|
704
|
+
if (!(!o || o._stopResolving)) {
|
705
|
+
if (Array.isArray(o))
|
706
|
+
o.forEach((l, a) => r(l, `${n}[${a}]`));
|
707
|
+
else if (typeof o == "object")
|
708
|
+
for (const l in o) {
|
709
|
+
const a = n ? `${n}.${l}` : l;
|
710
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, s), this._insertLinks(o, l, s)), r(o[l], a);
|
711
|
+
}
|
673
712
|
}
|
674
713
|
};
|
675
714
|
r(e.content);
|
@@ -677,17 +716,17 @@ class Oe {
|
|
677
716
|
async resolveLinks(e, t, s) {
|
678
717
|
let r = [];
|
679
718
|
if (e.link_uuids) {
|
680
|
-
const
|
681
|
-
for (let a = 0; a <
|
682
|
-
const c = Math.min(
|
683
|
-
|
719
|
+
const o = e.link_uuids.length, n = [], l = 50;
|
720
|
+
for (let a = 0; a < o; a += l) {
|
721
|
+
const c = Math.min(o, a + l);
|
722
|
+
n.push(e.link_uuids.slice(a, c));
|
684
723
|
}
|
685
|
-
for (let a = 0; a <
|
724
|
+
for (let a = 0; a < n.length; a++)
|
686
725
|
(await this.getStories({
|
687
726
|
per_page: l,
|
688
727
|
language: t.language,
|
689
728
|
version: t.version,
|
690
|
-
by_uuids:
|
729
|
+
by_uuids: n[a].join(",")
|
691
730
|
})).data.stories.forEach(
|
692
731
|
(c) => {
|
693
732
|
r.push(c);
|
@@ -695,9 +734,9 @@ class Oe {
|
|
695
734
|
);
|
696
735
|
} else
|
697
736
|
r = e.links;
|
698
|
-
r.forEach((
|
699
|
-
this.links[s][
|
700
|
-
...
|
737
|
+
r.forEach((o) => {
|
738
|
+
this.links[s][o.uuid] = {
|
739
|
+
...o,
|
701
740
|
_stopResolving: !0
|
702
741
|
};
|
703
742
|
});
|
@@ -705,26 +744,26 @@ class Oe {
|
|
705
744
|
async resolveRelations(e, t, s) {
|
706
745
|
let r = [];
|
707
746
|
if (e.rel_uuids) {
|
708
|
-
const
|
709
|
-
for (let a = 0; a <
|
710
|
-
const c = Math.min(
|
711
|
-
|
747
|
+
const o = e.rel_uuids.length, n = [], l = 50;
|
748
|
+
for (let a = 0; a < o; a += l) {
|
749
|
+
const c = Math.min(o, a + l);
|
750
|
+
n.push(e.rel_uuids.slice(a, c));
|
712
751
|
}
|
713
|
-
for (let a = 0; a <
|
752
|
+
for (let a = 0; a < n.length; a++)
|
714
753
|
(await this.getStories({
|
715
754
|
per_page: l,
|
716
755
|
language: t.language,
|
717
756
|
version: t.version,
|
718
|
-
by_uuids:
|
757
|
+
by_uuids: n[a].join(","),
|
719
758
|
excluding_fields: t.excluding_fields
|
720
759
|
})).data.stories.forEach((c) => {
|
721
760
|
r.push(c);
|
722
761
|
});
|
723
762
|
} else
|
724
763
|
r = e.rels;
|
725
|
-
r && r.length > 0 && r.forEach((
|
726
|
-
this.relations[s][
|
727
|
-
...
|
764
|
+
r && r.length > 0 && r.forEach((o) => {
|
765
|
+
this.relations[s][o.uuid] = {
|
766
|
+
...o,
|
728
767
|
_stopResolving: !0
|
729
768
|
};
|
730
769
|
});
|
@@ -739,52 +778,52 @@ class Oe {
|
|
739
778
|
*
|
740
779
|
*/
|
741
780
|
async resolveStories(e, t, s) {
|
742
|
-
var r,
|
743
|
-
let
|
744
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
781
|
+
var r, o;
|
782
|
+
let n = [];
|
783
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
745
784
|
for (const l in this.relations[s])
|
746
785
|
this.iterateTree(
|
747
786
|
this.relations[s][l],
|
748
|
-
|
787
|
+
n,
|
749
788
|
s
|
750
789
|
);
|
751
|
-
e.story ? this.iterateTree(e.story,
|
752
|
-
this.iterateTree(l,
|
790
|
+
e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((l) => {
|
791
|
+
this.iterateTree(l, n, s);
|
753
792
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
754
793
|
}
|
755
794
|
async cacheResponse(e, t, s, r) {
|
756
|
-
const
|
795
|
+
const o = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
|
757
796
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
|
758
|
-
const l = await
|
797
|
+
const l = await n.get(o);
|
759
798
|
if (l)
|
760
799
|
return Promise.resolve(l);
|
761
800
|
}
|
762
801
|
return new Promise(async (l, a) => {
|
763
802
|
var c;
|
764
803
|
try {
|
765
|
-
const
|
804
|
+
const u = await this.throttle(
|
766
805
|
"get",
|
767
806
|
e,
|
768
807
|
t,
|
769
808
|
r
|
770
809
|
);
|
771
|
-
if (
|
772
|
-
return a(
|
773
|
-
let
|
774
|
-
if ((c =
|
775
|
-
perPage:
|
776
|
-
total:
|
777
|
-
})),
|
778
|
-
const
|
779
|
-
await this.resolveStories(
|
810
|
+
if (u.status !== 200)
|
811
|
+
return a(u);
|
812
|
+
let d = { data: u.data, headers: u.headers };
|
813
|
+
if ((c = u.headers) != null && c["per-page"] && (d = Object.assign({}, d, {
|
814
|
+
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
815
|
+
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
816
|
+
})), d.data.story || d.data.stories) {
|
817
|
+
const m = this.resolveCounter = ++this.resolveCounter % 1e3;
|
818
|
+
await this.resolveStories(d.data, t, `${m}`);
|
780
819
|
}
|
781
|
-
return t.version === "published" && e !== "/cdn/spaces/me" && await
|
782
|
-
} catch (
|
783
|
-
if (
|
820
|
+
return t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
|
821
|
+
} catch (u) {
|
822
|
+
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
784
823
|
return console.log(
|
785
824
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
786
825
|
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
787
|
-
a(
|
826
|
+
a(u);
|
788
827
|
}
|
789
828
|
});
|
790
829
|
}
|
@@ -808,16 +847,16 @@ class Oe {
|
|
808
847
|
case "memory":
|
809
848
|
return {
|
810
849
|
get(e) {
|
811
|
-
return Promise.resolve(
|
850
|
+
return Promise.resolve(O[e]);
|
812
851
|
},
|
813
852
|
getAll() {
|
814
|
-
return Promise.resolve(
|
853
|
+
return Promise.resolve(O);
|
815
854
|
},
|
816
855
|
set(e, t) {
|
817
|
-
return
|
856
|
+
return O[e] = t, Promise.resolve(void 0);
|
818
857
|
},
|
819
858
|
flush() {
|
820
|
-
return
|
859
|
+
return O = {}, Promise.resolve(void 0);
|
821
860
|
}
|
822
861
|
};
|
823
862
|
case "custom":
|
@@ -846,14 +885,14 @@ class Oe {
|
|
846
885
|
}
|
847
886
|
const ze = (i = {}) => {
|
848
887
|
const { apiOptions: e } = i;
|
849
|
-
if (!e.accessToken) {
|
888
|
+
if (!e || !e.accessToken) {
|
850
889
|
console.error(
|
851
890
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
852
891
|
);
|
853
892
|
return;
|
854
893
|
}
|
855
|
-
return { storyblokApi: new
|
856
|
-
},
|
894
|
+
return { storyblokApi: new Le(e) };
|
895
|
+
}, De = (i) => {
|
857
896
|
if (typeof i != "object" || typeof i._editable > "u")
|
858
897
|
return {};
|
859
898
|
try {
|
@@ -862,31 +901,31 @@ const ze = (i = {}) => {
|
|
862
901
|
);
|
863
902
|
return e ? {
|
864
903
|
"data-blok-c": JSON.stringify(e),
|
865
|
-
"data-blok-uid": e.id
|
904
|
+
"data-blok-uid": `${e.id}-${e.uid}`
|
866
905
|
} : {};
|
867
906
|
} catch {
|
868
907
|
return {};
|
869
908
|
}
|
870
909
|
};
|
871
|
-
function
|
910
|
+
function Ce(i, e) {
|
872
911
|
if (!e)
|
873
912
|
return { src: i, attrs: {} };
|
874
913
|
let t = 0, s = 0;
|
875
|
-
const r = {},
|
876
|
-
function
|
877
|
-
typeof a != "number" || a <= c || a >=
|
914
|
+
const r = {}, o = [];
|
915
|
+
function n(a, c, u, d, m) {
|
916
|
+
typeof a != "number" || a <= c || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`) : m.push(`${d}(${a})`);
|
878
917
|
}
|
879
918
|
if (typeof e == "object") {
|
880
919
|
if (typeof e.width == "number" && e.width > 0 ? (r.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 ? (r.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) && (r.loading = e.loading), e.class && (r.class = e.class), e.filters) {
|
881
|
-
const { filters: a } = e || {}, { blur: c, brightness:
|
882
|
-
c &&
|
920
|
+
const { filters: a } = e || {}, { blur: c, brightness: u, fill: d, format: m, grayscale: y, quality: b, rotate: S } = a || {};
|
921
|
+
c && n(c, 0, 100, "blur", o), b && n(b, 0, 100, "quality", o), u && n(u, 0, 100, "brightness", o), d && o.push(`fill(${d})`), y && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), m && ["webp", "png", "jpeg"].includes(m) && o.push(`format(${m})`);
|
883
922
|
}
|
884
923
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
885
924
|
if (typeof a == "number")
|
886
|
-
return `${i}/m/${a}x0/${
|
925
|
+
return `${i}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
|
887
926
|
if (Array.isArray(a) && a.length === 2) {
|
888
|
-
const [c,
|
889
|
-
return `${i}/m/${c}x${
|
927
|
+
const [c, u] = a;
|
928
|
+
return `${i}/m/${c}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${c}w`;
|
890
929
|
} else {
|
891
930
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
892
931
|
return;
|
@@ -894,13 +933,13 @@ function Le(i, e) {
|
|
894
933
|
}).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
|
895
934
|
}
|
896
935
|
let l = `${i}/m/`;
|
897
|
-
return t > 0 && s > 0 && (l = `${l}${t}x${s}/`),
|
936
|
+
return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
|
898
937
|
src: l,
|
899
938
|
attrs: r
|
900
939
|
};
|
901
940
|
}
|
902
|
-
var
|
903
|
-
const
|
941
|
+
var $ = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i))($ || {}), T = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(T || {}), G = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(G || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
|
942
|
+
const Pe = [
|
904
943
|
"area",
|
905
944
|
"base",
|
906
945
|
"br",
|
@@ -915,224 +954,236 @@ const Ae = [
|
|
915
954
|
"source",
|
916
955
|
"track",
|
917
956
|
"wbr"
|
918
|
-
],
|
919
|
-
function
|
957
|
+
], Ne = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Me = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
|
958
|
+
function He(i) {
|
920
959
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
921
960
|
}
|
922
|
-
const
|
923
|
-
function
|
924
|
-
const s =
|
925
|
-
|
961
|
+
const B = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
|
962
|
+
function q(i, e = {}, t) {
|
963
|
+
const s = Ne(e), r = s ? `${i} ${s}` : i, o = Array.isArray(t) ? t.join("") : t || "";
|
964
|
+
if (i) {
|
965
|
+
if (Pe.includes(i))
|
966
|
+
return `<${r}>`;
|
967
|
+
} else return o;
|
968
|
+
return `<${r}>${o}</${i}>`;
|
926
969
|
}
|
927
|
-
function
|
970
|
+
function Be(i = {}) {
|
928
971
|
let e = 0;
|
929
972
|
const {
|
930
|
-
renderFn: t =
|
931
|
-
textFn: s =
|
973
|
+
renderFn: t = q,
|
974
|
+
textFn: s = He,
|
932
975
|
resolvers: r = {},
|
933
|
-
optimizeImages:
|
934
|
-
keyedResolvers:
|
935
|
-
} = i, l = (h) => (
|
936
|
-
const
|
937
|
-
return
|
938
|
-
},
|
939
|
-
const { src:
|
940
|
-
let
|
941
|
-
if (
|
942
|
-
const { src:
|
943
|
-
|
976
|
+
optimizeImages: o = !1,
|
977
|
+
keyedResolvers: n = !1
|
978
|
+
} = i, l = t !== q, a = (h) => (g) => {
|
979
|
+
const f = g.attrs || {};
|
980
|
+
return n && (f.key = `${h}-${e}`), t(h, f, g.children || null);
|
981
|
+
}, c = (h) => {
|
982
|
+
const { src: g, alt: f, title: k, srcset: R, sizes: v } = h.attrs || {};
|
983
|
+
let w = g, _ = {};
|
984
|
+
if (o) {
|
985
|
+
const { src: W, attrs: X } = Ce(g, o);
|
986
|
+
w = W, _ = X;
|
944
987
|
}
|
945
|
-
|
988
|
+
n && (_ = {
|
946
989
|
..._,
|
947
990
|
key: `img-${e}`
|
948
991
|
});
|
949
|
-
const
|
950
|
-
src:
|
951
|
-
alt:
|
952
|
-
title:
|
953
|
-
srcset:
|
954
|
-
sizes:
|
992
|
+
const Y = {
|
993
|
+
src: w,
|
994
|
+
alt: f,
|
995
|
+
title: k,
|
996
|
+
srcset: R,
|
997
|
+
sizes: v,
|
955
998
|
..._
|
956
999
|
};
|
957
|
-
return t("img",
|
958
|
-
},
|
959
|
-
const { level:
|
960
|
-
...
|
1000
|
+
return t("img", B(Y));
|
1001
|
+
}, u = (h) => {
|
1002
|
+
const { level: g, ...f } = h.attrs || {}, k = {
|
1003
|
+
...f
|
961
1004
|
};
|
962
|
-
return
|
1005
|
+
return n && (k.key = `h${g}-${e}`), t(`h${g}`, k, h.children);
|
963
1006
|
}, d = (h) => {
|
964
|
-
var
|
965
|
-
const
|
966
|
-
src: (
|
967
|
-
alt: (
|
1007
|
+
var g, f, k, R;
|
1008
|
+
const v = t("img", {
|
1009
|
+
src: (g = h.attrs) == null ? void 0 : g.fallbackImage,
|
1010
|
+
alt: (f = h.attrs) == null ? void 0 : f.alt,
|
968
1011
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
969
1012
|
draggable: "false",
|
970
1013
|
loading: "lazy"
|
971
|
-
}),
|
1014
|
+
}), w = {
|
972
1015
|
"data-type": "emoji",
|
973
|
-
"data-name": (
|
974
|
-
"data-emoji": (
|
1016
|
+
"data-name": (k = h.attrs) == null ? void 0 : k.name,
|
1017
|
+
"data-emoji": (R = h.attrs) == null ? void 0 : R.emoji
|
975
1018
|
};
|
976
|
-
return
|
977
|
-
},
|
1019
|
+
return n && (w.key = `emoji-${e}`), t("span", w, v);
|
1020
|
+
}, m = (h) => t("pre", {
|
978
1021
|
...h.attrs,
|
979
1022
|
key: `code-${e}`
|
980
|
-
}, t("code", { key: `code-${e}` }, h.children || "")),
|
981
|
-
const { class:
|
982
|
-
class:
|
983
|
-
id:
|
984
|
-
style:
|
985
|
-
} :
|
986
|
-
return
|
987
|
-
},
|
988
|
-
const { marks:
|
989
|
-
return "text" in h ?
|
990
|
-
(
|
1023
|
+
}, t("code", { key: `code-${e}` }, h.children || "")), y = (h, g = !1) => ({ text: f, attrs: k }) => {
|
1024
|
+
const { class: R, id: v, ...w } = k || {}, _ = g ? {
|
1025
|
+
class: R,
|
1026
|
+
id: v,
|
1027
|
+
style: Me(w) || void 0
|
1028
|
+
} : k || {};
|
1029
|
+
return n && (_.key = `${h}-${e}`), t(h, B(_), f);
|
1030
|
+
}, b = (h) => C(h), S = (h) => {
|
1031
|
+
const { marks: g, ...f } = h;
|
1032
|
+
return "text" in h ? g ? g.reduce(
|
1033
|
+
(k, R) => b({ ...R, text: k }),
|
991
1034
|
// Fix: Ensure render function returns a string
|
992
|
-
|
1035
|
+
b({ ...f, children: f.children })
|
993
1036
|
// Fix: Cast children to string
|
994
|
-
) : s(
|
995
|
-
},
|
996
|
-
const { linktype:
|
997
|
-
let
|
998
|
-
switch (
|
1037
|
+
) : s(f.text) : "";
|
1038
|
+
}, j = (h) => {
|
1039
|
+
const { linktype: g, href: f, anchor: k, ...R } = h.attrs || {};
|
1040
|
+
let v = "";
|
1041
|
+
switch (g) {
|
999
1042
|
case I.ASSET:
|
1000
1043
|
case I.URL:
|
1001
|
-
|
1044
|
+
v = f;
|
1002
1045
|
break;
|
1003
1046
|
case I.EMAIL:
|
1004
|
-
|
1047
|
+
v = `mailto:${f}`;
|
1005
1048
|
break;
|
1006
1049
|
case I.STORY:
|
1007
|
-
|
1050
|
+
v = f, k && (v = `${v}#${k}`);
|
1051
|
+
break;
|
1052
|
+
default:
|
1053
|
+
v = f;
|
1008
1054
|
break;
|
1009
1055
|
}
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1056
|
+
const w = { ...R };
|
1057
|
+
return v && (w.href = v), n && (w.key = `a-${e}`), t("a", w, h.text);
|
1058
|
+
}, J = (h) => {
|
1059
|
+
var g, f;
|
1013
1060
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
1014
|
-
blok: (
|
1015
|
-
id: (
|
1061
|
+
blok: (g = h == null ? void 0 : h.attrs) == null ? void 0 : g.body[0],
|
1062
|
+
id: (f = h.attrs) == null ? void 0 : f.id,
|
1016
1063
|
key: `component-${e}`,
|
1017
1064
|
style: "display: none"
|
1018
1065
|
});
|
1019
|
-
},
|
1020
|
-
[
|
1021
|
-
[
|
1022
|
-
[
|
1023
|
-
[
|
1024
|
-
[
|
1025
|
-
[
|
1026
|
-
[
|
1027
|
-
[
|
1028
|
-
[
|
1029
|
-
[
|
1030
|
-
[
|
1031
|
-
[
|
1032
|
-
[
|
1033
|
-
[G.TEXT,
|
1034
|
-
[
|
1035
|
-
[
|
1036
|
-
[
|
1037
|
-
[
|
1038
|
-
[
|
1039
|
-
[
|
1040
|
-
[
|
1041
|
-
[
|
1042
|
-
[
|
1043
|
-
[
|
1044
|
-
[
|
1045
|
-
[
|
1046
|
-
...Object.entries(r).map(([h,
|
1066
|
+
}, K = new Map([
|
1067
|
+
[$.DOCUMENT, a("")],
|
1068
|
+
[$.HEADING, u],
|
1069
|
+
[$.PARAGRAPH, a("p")],
|
1070
|
+
[$.UL_LIST, a("ul")],
|
1071
|
+
[$.OL_LIST, a("ol")],
|
1072
|
+
[$.LIST_ITEM, a("li")],
|
1073
|
+
[$.IMAGE, c],
|
1074
|
+
[$.EMOJI, d],
|
1075
|
+
[$.CODE_BLOCK, m],
|
1076
|
+
[$.HR, a("hr")],
|
1077
|
+
[$.BR, a("br")],
|
1078
|
+
[$.QUOTE, a("blockquote")],
|
1079
|
+
[$.COMPONENT, J],
|
1080
|
+
[G.TEXT, S],
|
1081
|
+
[T.LINK, j],
|
1082
|
+
[T.ANCHOR, j],
|
1083
|
+
[T.STYLED, y("span", !0)],
|
1084
|
+
[T.BOLD, y("strong")],
|
1085
|
+
[T.TEXT_STYLE, y("span", !0)],
|
1086
|
+
[T.ITALIC, y("em")],
|
1087
|
+
[T.UNDERLINE, y("u")],
|
1088
|
+
[T.STRIKE, y("s")],
|
1089
|
+
[T.CODE, y("code")],
|
1090
|
+
[T.SUPERSCRIPT, y("sup")],
|
1091
|
+
[T.SUBSCRIPT, y("sub")],
|
1092
|
+
[T.HIGHLIGHT, y("mark")],
|
1093
|
+
...Object.entries(r).map(([h, g]) => [h, g])
|
1047
1094
|
]);
|
1048
|
-
function
|
1095
|
+
function x(h) {
|
1049
1096
|
e += 1;
|
1050
|
-
const
|
1051
|
-
if (!
|
1097
|
+
const g = K.get(h.type);
|
1098
|
+
if (!g)
|
1052
1099
|
return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
|
1053
1100
|
if (h.type === "text")
|
1054
|
-
return
|
1055
|
-
const
|
1056
|
-
return
|
1101
|
+
return g(h);
|
1102
|
+
const f = h.content ? h.content.map(C) : void 0;
|
1103
|
+
return g({
|
1057
1104
|
...h,
|
1058
|
-
children:
|
1105
|
+
children: f
|
1059
1106
|
// Fix: Update the type of 'children' to Node[]
|
1060
1107
|
});
|
1061
1108
|
}
|
1062
|
-
function
|
1063
|
-
return Array.isArray(h) ? h.map(
|
1109
|
+
function C(h) {
|
1110
|
+
return h.type === "doc" ? l ? h.content.map(x) : h.content.map(x).join("") : Array.isArray(h) ? h.map(x) : x(h);
|
1064
1111
|
}
|
1065
1112
|
return {
|
1066
|
-
render:
|
1113
|
+
render: C
|
1067
1114
|
};
|
1068
1115
|
}
|
1069
|
-
let
|
1116
|
+
let N, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
1070
1117
|
const qe = (i, e, t = {}) => {
|
1071
1118
|
var l;
|
1072
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o =
|
1119
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
1073
1120
|
"_storyblok"
|
1074
|
-
) === i;
|
1075
|
-
if (!(!r || !
|
1121
|
+
), n = o !== null && +o === i;
|
1122
|
+
if (!(!r || !n)) {
|
1076
1123
|
if (!i) {
|
1077
1124
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
1078
1125
|
return;
|
1079
1126
|
}
|
1080
1127
|
window.storyblokRegisterEvent(() => {
|
1081
1128
|
new window.StoryblokBridge(t).on(["input", "published", "change"], (c) => {
|
1082
|
-
|
1129
|
+
var u;
|
1130
|
+
c && (c.action === "input" && ((u = c.story) == null ? void 0 : u.id) === i ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === i && window.location.reload());
|
1083
1131
|
});
|
1084
1132
|
});
|
1085
1133
|
}
|
1086
|
-
},
|
1087
|
-
|
1134
|
+
}, V = (i, e) => {
|
1135
|
+
i.addNode("blok", (t) => {
|
1136
|
+
let s = "";
|
1137
|
+
return t.attrs.body.forEach((r) => {
|
1138
|
+
s += e(r.component, r);
|
1139
|
+
}), {
|
1140
|
+
html: s
|
1141
|
+
};
|
1142
|
+
});
|
1143
|
+
}, Fe = (i = {}) => {
|
1144
|
+
var d, m;
|
1088
1145
|
const {
|
1089
1146
|
bridge: e,
|
1090
1147
|
accessToken: t,
|
1091
1148
|
use: s = [],
|
1092
1149
|
apiOptions: r = {},
|
1093
|
-
richText:
|
1094
|
-
bridgeUrl:
|
1150
|
+
richText: o = {},
|
1151
|
+
bridgeUrl: n
|
1095
1152
|
} = i;
|
1096
1153
|
r.accessToken = r.accessToken || t;
|
1097
1154
|
const l = { bridge: e, apiOptions: r };
|
1098
1155
|
let a = {};
|
1099
|
-
s.forEach((
|
1100
|
-
a = { ...a, ...
|
1101
|
-
}),
|
1102
|
-
const
|
1103
|
-
return e !== !1 &&
|
1104
|
-
},
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
}), {
|
1110
|
-
html: s
|
1111
|
-
};
|
1112
|
-
});
|
1113
|
-
}, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Fe = (i, e, t) => {
|
1114
|
-
let s = t || P;
|
1156
|
+
s.forEach((y) => {
|
1157
|
+
a = { ...a, ...y(l) };
|
1158
|
+
}), n && (M = n);
|
1159
|
+
const u = !(typeof window > "u") && ((m = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : m.includes("_storyblok_tk"));
|
1160
|
+
return e !== !1 && u && F(M), N = new L(o.schema), o.resolver && V(N, o.resolver), a;
|
1161
|
+
}, Ue = (i) => {
|
1162
|
+
var e;
|
1163
|
+
return !i || !((e = i == null ? void 0 : i.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
1164
|
+
}, Ge = (i, e, t) => {
|
1165
|
+
let s = t || N;
|
1115
1166
|
if (!s) {
|
1116
1167
|
console.error(
|
1117
1168
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
1118
1169
|
);
|
1119
1170
|
return;
|
1120
1171
|
}
|
1121
|
-
return
|
1122
|
-
}, Ve = () =>
|
1172
|
+
return Ue(i) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(i, {}, !1));
|
1173
|
+
}, Ve = () => F(M);
|
1123
1174
|
export {
|
1124
|
-
|
1125
|
-
|
1175
|
+
$ as BlockTypes,
|
1176
|
+
T as MarkTypes,
|
1126
1177
|
L as RichTextResolver,
|
1127
|
-
|
1178
|
+
je as RichTextSchema,
|
1128
1179
|
G as TextTypes,
|
1129
1180
|
ze as apiPlugin,
|
1130
|
-
|
1181
|
+
Ue as isRichTextEmpty,
|
1131
1182
|
Ve as loadStoryblokBridge,
|
1132
1183
|
qe as registerStoryblokBridge,
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1184
|
+
Ge as renderRichText,
|
1185
|
+
Be as richTextResolver,
|
1186
|
+
De as storyblokEditable,
|
1187
|
+
Fe as storyblokInit,
|
1137
1188
|
qe as useStoryblokBridge
|
1138
1189
|
};
|