@storyblok/js 3.1.6 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/storyblok-js.js +24 -24
- package/dist/storyblok-js.mjs +411 -358
- package/dist/types/types.d.ts +1 -1
- package/package.json +9 -9
package/dist/storyblok-js.mjs
CHANGED
@@ -1,64 +1,65 @@
|
|
1
|
-
let
|
2
|
-
const
|
1
|
+
let H = !1;
|
2
|
+
const U = [], q = (i) => new Promise((e, t) => {
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
4
4
|
if (window.location === window.parent.location) {
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
6
6
|
return;
|
7
7
|
}
|
8
|
-
|
8
|
+
H ? r() : U.push(r);
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge"))) return;
|
10
10
|
const s = document.createElement("script");
|
11
11
|
s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
12
|
-
|
12
|
+
U.forEach((n) => n()), H = !0, e(r);
|
13
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
14
14
|
});
|
15
|
-
var
|
16
|
-
|
17
|
-
|
15
|
+
var X = Object.defineProperty, W = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => W(i, typeof e != "symbol" ? e + "" : e, t);
|
16
|
+
class Q extends Error {
|
17
|
+
constructor(e) {
|
18
|
+
super(e), this.name = "AbortError";
|
19
|
+
}
|
18
20
|
}
|
19
|
-
function
|
20
|
-
if (!
|
21
|
+
function Z(i, e, t) {
|
22
|
+
if (!Number.isFinite(e))
|
21
23
|
throw new TypeError("Expected `limit` to be a finite number");
|
22
|
-
if (!
|
24
|
+
if (!Number.isFinite(t))
|
23
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
24
26
|
const s = [];
|
25
|
-
let r = [], n = 0;
|
26
|
-
const
|
27
|
+
let r = [], n = 0, o = !1;
|
28
|
+
const l = async () => {
|
27
29
|
n++;
|
28
|
-
const
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
const c = s.shift();
|
31
|
+
if (c) {
|
32
|
+
const d = await i(...c.args);
|
33
|
+
c.resolve(d);
|
34
|
+
}
|
35
|
+
const u = setTimeout(() => {
|
36
|
+
n--, s.length > 0 && l(), r = r.filter((d) => d !== u);
|
32
37
|
}, t);
|
33
|
-
r.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
51
|
-
});
|
52
|
-
}), s.length = 0;
|
53
|
-
}, l;
|
38
|
+
r.includes(u) || r.push(u);
|
39
|
+
}, a = (...c) => o ? Promise.reject(
|
40
|
+
new Error(
|
41
|
+
"Throttled function is already aborted and not accepting new promises"
|
42
|
+
)
|
43
|
+
) : new Promise((u, d) => {
|
44
|
+
s.push({
|
45
|
+
resolve: u,
|
46
|
+
reject: d,
|
47
|
+
args: c
|
48
|
+
}), n < e && l();
|
49
|
+
});
|
50
|
+
return a.abort = () => {
|
51
|
+
o = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
52
|
+
(c) => c.reject(() => new Q("Throttle function aborted"))
|
53
|
+
), s.length = 0;
|
54
|
+
}, a;
|
54
55
|
}
|
55
|
-
class
|
56
|
+
let O = class {
|
56
57
|
constructor() {
|
57
|
-
p(this, "isCDNUrl", (e = "") => e.
|
58
|
+
p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
58
59
|
...e,
|
59
60
|
per_page: t,
|
60
61
|
page: s
|
61
|
-
})), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) =>
|
62
|
+
})), 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) => {
|
62
63
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
63
64
|
return this.arrayFrom(s, (n, o) => o * r + e);
|
64
65
|
}), 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) {
|
@@ -68,16 +69,16 @@ class x {
|
|
68
69
|
">": ">",
|
69
70
|
'"': """,
|
70
71
|
"'": "'"
|
71
|
-
}, s = /[&<>"']/g, r = RegExp(s.source);
|
72
|
+
}, s = /[&<>"']/g, r = new RegExp(s.source);
|
72
73
|
return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
|
73
74
|
});
|
74
75
|
}
|
75
76
|
/**
|
76
77
|
* @method stringify
|
77
|
-
* @param {
|
78
|
-
* @param {
|
79
|
-
* @param {
|
80
|
-
* @return {
|
78
|
+
* @param {object} params
|
79
|
+
* @param {string} prefix
|
80
|
+
* @param {boolean} isArray
|
81
|
+
* @return {string} Stringified object
|
81
82
|
*/
|
82
83
|
stringify(e, t, s) {
|
83
84
|
const r = [];
|
@@ -88,16 +89,16 @@ class x {
|
|
88
89
|
let a;
|
89
90
|
typeof o == "object" ? a = this.stringify(
|
90
91
|
o,
|
91
|
-
t ? t + encodeURIComponent(
|
92
|
+
t ? t + encodeURIComponent(`[${l}]`) : l,
|
92
93
|
Array.isArray(o)
|
93
|
-
) : a =
|
94
|
+
) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
|
94
95
|
}
|
95
96
|
return r.join("&");
|
96
97
|
}
|
97
98
|
/**
|
98
99
|
* @method getRegionURL
|
99
|
-
* @param {
|
100
|
-
* @return {
|
100
|
+
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
101
|
+
* @return {string} The base URL of the region
|
101
102
|
*/
|
102
103
|
getRegionURL(e) {
|
103
104
|
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
@@ -114,21 +115,21 @@ class x {
|
|
114
115
|
return t;
|
115
116
|
}
|
116
117
|
}
|
117
|
-
}
|
118
|
-
const
|
118
|
+
};
|
119
|
+
const ee = function(i, e) {
|
119
120
|
const t = {};
|
120
121
|
for (const s in i) {
|
121
122
|
const r = i[s];
|
122
|
-
e.
|
123
|
+
e.includes(s) && r !== null && (t[s] = r);
|
123
124
|
}
|
124
125
|
return t;
|
125
|
-
},
|
126
|
+
}, te = (i) => i === "email", se = () => ({
|
126
127
|
singleTag: "hr"
|
127
|
-
}),
|
128
|
+
}), re = () => ({
|
128
129
|
tag: "blockquote"
|
129
|
-
}),
|
130
|
+
}), ie = () => ({
|
130
131
|
tag: "ul"
|
131
|
-
}),
|
132
|
+
}), ne = (i) => ({
|
132
133
|
tag: [
|
133
134
|
"pre",
|
134
135
|
{
|
@@ -136,24 +137,24 @@ const X = function(i, e) {
|
|
136
137
|
attrs: i.attrs
|
137
138
|
}
|
138
139
|
]
|
139
|
-
}),
|
140
|
+
}), oe = () => ({
|
140
141
|
singleTag: "br"
|
141
|
-
}),
|
142
|
+
}), ae = (i) => ({
|
142
143
|
tag: `h${i.attrs.level}`
|
143
|
-
}),
|
144
|
+
}), le = (i) => ({
|
144
145
|
singleTag: [
|
145
146
|
{
|
146
147
|
tag: "img",
|
147
|
-
attrs:
|
148
|
+
attrs: ee(i.attrs, ["src", "alt", "title"])
|
148
149
|
}
|
149
150
|
]
|
150
|
-
}),
|
151
|
+
}), ce = () => ({
|
151
152
|
tag: "li"
|
152
|
-
}),
|
153
|
+
}), he = () => ({
|
153
154
|
tag: "ol"
|
154
|
-
}),
|
155
|
+
}), ue = () => ({
|
155
156
|
tag: "p"
|
156
|
-
}),
|
157
|
+
}), de = (i) => ({
|
157
158
|
tag: [
|
158
159
|
{
|
159
160
|
tag: "span",
|
@@ -164,25 +165,25 @@ const X = function(i, e) {
|
|
164
165
|
}
|
165
166
|
}
|
166
167
|
]
|
167
|
-
}),
|
168
|
+
}), pe = () => ({
|
168
169
|
tag: "b"
|
169
|
-
}),
|
170
|
+
}), ge = () => ({
|
170
171
|
tag: "s"
|
171
|
-
}),
|
172
|
+
}), fe = () => ({
|
172
173
|
tag: "u"
|
173
|
-
}),
|
174
|
+
}), me = () => ({
|
174
175
|
tag: "strong"
|
175
|
-
}),
|
176
|
+
}), ye = () => ({
|
176
177
|
tag: "code"
|
177
|
-
}),
|
178
|
+
}), be = () => ({
|
178
179
|
tag: "i"
|
179
|
-
}),
|
180
|
+
}), ke = (i) => {
|
180
181
|
if (!i.attrs)
|
181
182
|
return {
|
182
183
|
tag: ""
|
183
184
|
};
|
184
|
-
const e = new
|
185
|
-
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")),
|
185
|
+
const e = new O().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
|
186
|
+
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), te(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
186
187
|
for (const r in t.custom)
|
187
188
|
t[r] = t.custom[r];
|
188
189
|
delete t.custom;
|
@@ -195,25 +196,25 @@ const X = function(i, e) {
|
|
195
196
|
}
|
196
197
|
]
|
197
198
|
};
|
198
|
-
},
|
199
|
+
}, ve = (i) => ({
|
199
200
|
tag: [
|
200
201
|
{
|
201
202
|
tag: "span",
|
202
203
|
attrs: i.attrs
|
203
204
|
}
|
204
205
|
]
|
205
|
-
}),
|
206
|
+
}), $e = () => ({
|
206
207
|
tag: "sub"
|
207
|
-
}),
|
208
|
+
}), Te = () => ({
|
208
209
|
tag: "sup"
|
209
|
-
}),
|
210
|
+
}), we = (i) => ({
|
210
211
|
tag: [
|
211
212
|
{
|
212
213
|
tag: "span",
|
213
214
|
attrs: i.attrs
|
214
215
|
}
|
215
216
|
]
|
216
|
-
}),
|
217
|
+
}), Re = (i) => {
|
217
218
|
var e;
|
218
219
|
return (e = i.attrs) != null && e.color ? {
|
219
220
|
tag: [
|
@@ -227,7 +228,7 @@ const X = function(i, e) {
|
|
227
228
|
} : {
|
228
229
|
tag: ""
|
229
230
|
};
|
230
|
-
},
|
231
|
+
}, Se = (i) => {
|
231
232
|
var e;
|
232
233
|
return (e = i.attrs) != null && e.color ? {
|
233
234
|
tag: [
|
@@ -241,49 +242,49 @@ const X = function(i, e) {
|
|
241
242
|
} : {
|
242
243
|
tag: ""
|
243
244
|
};
|
244
|
-
},
|
245
|
+
}, _e = {
|
245
246
|
nodes: {
|
246
|
-
horizontal_rule:
|
247
|
-
blockquote:
|
248
|
-
bullet_list:
|
249
|
-
code_block:
|
250
|
-
hard_break:
|
251
|
-
heading:
|
252
|
-
image:
|
253
|
-
list_item:
|
254
|
-
ordered_list:
|
255
|
-
paragraph:
|
256
|
-
emoji:
|
247
|
+
horizontal_rule: se,
|
248
|
+
blockquote: re,
|
249
|
+
bullet_list: ie,
|
250
|
+
code_block: ne,
|
251
|
+
hard_break: oe,
|
252
|
+
heading: ae,
|
253
|
+
image: le,
|
254
|
+
list_item: ce,
|
255
|
+
ordered_list: he,
|
256
|
+
paragraph: ue,
|
257
|
+
emoji: de
|
257
258
|
},
|
258
259
|
marks: {
|
259
|
-
bold:
|
260
|
-
strike:
|
261
|
-
underline:
|
262
|
-
strong:
|
263
|
-
code:
|
264
|
-
italic:
|
265
|
-
link:
|
266
|
-
styled:
|
267
|
-
subscript:
|
268
|
-
superscript:
|
269
|
-
anchor:
|
270
|
-
highlight:
|
271
|
-
textStyle:
|
272
|
-
}
|
273
|
-
},
|
260
|
+
bold: pe,
|
261
|
+
strike: ge,
|
262
|
+
underline: fe,
|
263
|
+
strong: me,
|
264
|
+
code: ye,
|
265
|
+
italic: be,
|
266
|
+
link: ke,
|
267
|
+
styled: ve,
|
268
|
+
subscript: $e,
|
269
|
+
superscript: Te,
|
270
|
+
anchor: we,
|
271
|
+
highlight: Re,
|
272
|
+
textStyle: Se
|
273
|
+
}
|
274
|
+
}, Ee = function(i) {
|
274
275
|
const e = {
|
275
276
|
"&": "&",
|
276
277
|
"<": "<",
|
277
278
|
">": ">",
|
278
279
|
'"': """,
|
279
280
|
"'": "'"
|
280
|
-
}, t = /[&<>"']/g, s = RegExp(t.source);
|
281
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
281
282
|
return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
|
282
283
|
};
|
283
|
-
let
|
284
|
-
class
|
284
|
+
let z = !1;
|
285
|
+
class Ie {
|
285
286
|
constructor(e) {
|
286
|
-
p(this, "marks"), p(this, "nodes"), e || (e =
|
287
|
+
p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
287
288
|
}
|
288
289
|
addNode(e, t) {
|
289
290
|
this.nodes[e] = t;
|
@@ -292,9 +293,9 @@ class we {
|
|
292
293
|
this.marks[e] = t;
|
293
294
|
}
|
294
295
|
render(e, t = { optimizeImages: !1 }, s = !0) {
|
295
|
-
if (!
|
296
|
+
if (!z && s && (console.warn(
|
296
297
|
"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/"
|
297
|
-
),
|
298
|
+
), z = !0), e && e.content && Array.isArray(e.content)) {
|
298
299
|
let r = "";
|
299
300
|
return e.content.forEach((n) => {
|
300
301
|
r += this.renderNode(n);
|
@@ -302,57 +303,58 @@ class we {
|
|
302
303
|
}
|
303
304
|
return console.warn(
|
304
305
|
`The render method must receive an Object with a "content" field.
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
306
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
307
|
+
ISbRichtext:
|
308
|
+
content?: ISbRichtext[]
|
309
|
+
marks?: ISbRichtext[]
|
310
|
+
attrs?: any
|
311
|
+
text?: string
|
312
|
+
type: string
|
313
|
+
|
314
|
+
Example:
|
315
|
+
{
|
316
|
+
content: [
|
317
|
+
{
|
318
|
+
content: [
|
319
|
+
{
|
320
|
+
text: 'Hello World',
|
321
|
+
type: 'text'
|
322
|
+
}
|
323
|
+
],
|
324
|
+
type: 'paragraph'
|
325
|
+
}
|
326
|
+
],
|
327
|
+
type: 'doc'
|
328
|
+
}`
|
328
329
|
), "";
|
329
330
|
}
|
330
331
|
optimizeImages(e, t) {
|
331
332
|
let s = 0, r = 0, n = "", o = "";
|
332
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-
|
333
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = `/filters${o}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
|
333
334
|
const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
334
335
|
return e = e.replace(
|
335
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
336
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
336
337
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
337
338
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
338
|
-
var
|
339
|
-
const
|
340
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
339
|
+
var c, u;
|
340
|
+
const d = a.match(
|
341
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
341
342
|
);
|
342
|
-
if (
|
343
|
-
const
|
344
|
-
srcset: (
|
343
|
+
if (d && d.length > 0) {
|
344
|
+
const g = {
|
345
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((y) => {
|
345
346
|
if (typeof y == "number")
|
346
|
-
return `//${
|
347
|
+
return `//${d}/m/${y}x0${o} ${y}w`;
|
347
348
|
if (typeof y == "object" && y.length === 2) {
|
348
|
-
let
|
349
|
-
return typeof y[0] == "number" && (
|
349
|
+
let R = 0, j = 0;
|
350
|
+
return typeof y[0] == "number" && (R = y[0]), typeof y[1] == "number" && (j = y[1]), `//${d}/m/${R}x${j}${o} ${R}w`;
|
350
351
|
}
|
352
|
+
return "";
|
351
353
|
}).join(", "),
|
352
|
-
sizes: (
|
354
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
|
353
355
|
};
|
354
|
-
let
|
355
|
-
return
|
356
|
+
let T = "";
|
357
|
+
return g.srcset && (T += `srcset="${g.srcset}" `), g.sizes && (T += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${T.trim()}`);
|
356
358
|
}
|
357
359
|
return a;
|
358
360
|
})), e;
|
@@ -366,7 +368,7 @@ class we {
|
|
366
368
|
const s = this.getMatchingNode(e);
|
367
369
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
368
370
|
t.push(this.renderNode(r));
|
369
|
-
}) : e.text ? t.push(
|
371
|
+
}) : e.text ? t.push(Ee(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) => {
|
370
372
|
const n = this.getMatchingMark(r);
|
371
373
|
n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
|
372
374
|
}), t.join("");
|
@@ -421,8 +423,8 @@ class we {
|
|
421
423
|
return this.renderTag(t, " /");
|
422
424
|
}
|
423
425
|
}
|
424
|
-
const
|
425
|
-
class
|
426
|
+
const L = Ie;
|
427
|
+
class je {
|
426
428
|
constructor(e) {
|
427
429
|
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 = {};
|
428
430
|
}
|
@@ -461,7 +463,7 @@ class Se {
|
|
461
463
|
async _methodHandler(e) {
|
462
464
|
let t = `${this.baseURL}${this.url}`, s = null;
|
463
465
|
if (e === "get") {
|
464
|
-
const a = new
|
466
|
+
const a = new O();
|
465
467
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
466
468
|
this.parameters
|
467
469
|
)}`;
|
@@ -479,10 +481,10 @@ class Se {
|
|
479
481
|
...this.fetchOptions
|
480
482
|
});
|
481
483
|
this.timeout && clearTimeout(l);
|
482
|
-
const
|
484
|
+
const c = await this._responseHandler(
|
483
485
|
a
|
484
486
|
);
|
485
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
487
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
|
486
488
|
} catch (a) {
|
487
489
|
return {
|
488
490
|
message: a
|
@@ -509,35 +511,39 @@ class Se {
|
|
509
511
|
});
|
510
512
|
}
|
511
513
|
}
|
512
|
-
const
|
514
|
+
const xe = je, B = "SB-Agent", C = {
|
513
515
|
defaultAgentName: "SB-JS-CLIENT",
|
514
516
|
defaultAgentVersion: "SB-Agent-Version",
|
515
517
|
packageVersion: "6.0.0"
|
516
518
|
};
|
517
|
-
let
|
518
|
-
const
|
519
|
-
class
|
519
|
+
let x = {};
|
520
|
+
const E = {};
|
521
|
+
class Oe {
|
520
522
|
/**
|
521
523
|
*
|
522
524
|
* @param config ISbConfig interface
|
523
|
-
* @param
|
525
|
+
* @param pEndpoint string, optional
|
524
526
|
*/
|
525
527
|
constructor(e, t) {
|
526
528
|
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");
|
527
529
|
let s = e.endpoint || t;
|
528
530
|
if (!s) {
|
529
|
-
const o = new
|
531
|
+
const o = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
|
530
532
|
e.oauthToken ? s = `${l}://${o(e.region)}/v1` : s = `${l}://${o(e.region)}/v2`;
|
531
533
|
}
|
532
534
|
const r = new Headers();
|
533
535
|
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(([o, l]) => {
|
534
536
|
r.set(o, l);
|
535
|
-
}), r.has(
|
536
|
-
|
537
|
-
|
537
|
+
}), r.has(B) || (r.set(B, C.defaultAgentName), r.set(
|
538
|
+
C.defaultAgentVersion,
|
539
|
+
C.packageVersion
|
538
540
|
));
|
539
541
|
let n = 5;
|
540
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new
|
542
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = 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 = Z(
|
543
|
+
this.throttledRequest.bind(this),
|
544
|
+
n,
|
545
|
+
1e3
|
546
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new O(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
|
541
547
|
baseURL: s,
|
542
548
|
timeout: e.timeout || 0,
|
543
549
|
headers: r,
|
@@ -556,7 +562,7 @@ class Ee {
|
|
556
562
|
});
|
557
563
|
}
|
558
564
|
parseParams(e) {
|
559
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
565
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
560
566
|
}
|
561
567
|
factoryParamOptions(e, t) {
|
562
568
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
@@ -574,32 +580,35 @@ class Ee {
|
|
574
580
|
return this.cacheResponse(r, n, void 0, s);
|
575
581
|
}
|
576
582
|
async getAll(e, t, s, r) {
|
577
|
-
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}
|
583
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`.replace(/\/$/, ""), l = s ?? o.substring(o.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
|
578
584
|
o,
|
579
585
|
t,
|
580
586
|
n,
|
581
|
-
|
587
|
+
a,
|
582
588
|
r
|
583
|
-
), u =
|
584
|
-
this.helpers.range(
|
585
|
-
(
|
586
|
-
);
|
587
|
-
return this.helpers.flatMap(
|
588
|
-
[d, ...m],
|
589
|
-
(k) => Object.values(k.data[a])
|
589
|
+
), u = c.total ? Math.ceil(c.total / n) : 1, d = await this.helpers.asyncMap(
|
590
|
+
this.helpers.range(a, u),
|
591
|
+
(g) => this.makeRequest(o, t, n, g + 1, r)
|
590
592
|
);
|
593
|
+
return this.helpers.flatMap([c, ...d], (g) => Object.values(g.data[l]));
|
591
594
|
}
|
592
595
|
post(e, t, s) {
|
593
596
|
const r = `/${e}`;
|
594
|
-
return Promise.resolve(
|
597
|
+
return Promise.resolve(
|
598
|
+
this.throttle("post", r, t, s)
|
599
|
+
);
|
595
600
|
}
|
596
601
|
put(e, t, s) {
|
597
602
|
const r = `/${e}`;
|
598
|
-
return Promise.resolve(
|
603
|
+
return Promise.resolve(
|
604
|
+
this.throttle("put", r, t, s)
|
605
|
+
);
|
599
606
|
}
|
600
607
|
delete(e, t, s) {
|
601
608
|
const r = `/${e}`;
|
602
|
-
return Promise.resolve(
|
609
|
+
return Promise.resolve(
|
610
|
+
this.throttle("delete", r, t, s)
|
611
|
+
);
|
603
612
|
}
|
604
613
|
getStories(e, t) {
|
605
614
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
@@ -621,7 +630,7 @@ class Ee {
|
|
621
630
|
}
|
622
631
|
_insertLinks(e, t, s) {
|
623
632
|
const r = e[t];
|
624
|
-
r && r.fieldtype
|
633
|
+
r && r.fieldtype === "multilink" && r.linktype === "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
|
625
634
|
}
|
626
635
|
/**
|
627
636
|
*
|
@@ -635,7 +644,7 @@ class Ee {
|
|
635
644
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
636
645
|
}
|
637
646
|
_insertRelations(e, t, s, r) {
|
638
|
-
s.
|
647
|
+
s.includes(`${e.component}.${t}`) && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(r, n)).filter(Boolean)));
|
639
648
|
}
|
640
649
|
iterateTree(e, t, s) {
|
641
650
|
const r = (n) => {
|
@@ -667,8 +676,8 @@ class Ee {
|
|
667
676
|
if (e.link_uuids) {
|
668
677
|
const n = e.link_uuids.length, o = [], l = 50;
|
669
678
|
for (let a = 0; a < n; a += l) {
|
670
|
-
const
|
671
|
-
o.push(e.link_uuids.slice(a,
|
679
|
+
const c = Math.min(n, a + l);
|
680
|
+
o.push(e.link_uuids.slice(a, c));
|
672
681
|
}
|
673
682
|
for (let a = 0; a < o.length; a++)
|
674
683
|
(await this.getStories({
|
@@ -677,8 +686,8 @@ class Ee {
|
|
677
686
|
version: t.version,
|
678
687
|
by_uuids: o[a].join(",")
|
679
688
|
})).data.stories.forEach(
|
680
|
-
(
|
681
|
-
r.push(
|
689
|
+
(c) => {
|
690
|
+
r.push(c);
|
682
691
|
}
|
683
692
|
);
|
684
693
|
} else
|
@@ -695,8 +704,8 @@ class Ee {
|
|
695
704
|
if (e.rel_uuids) {
|
696
705
|
const n = e.rel_uuids.length, o = [], l = 50;
|
697
706
|
for (let a = 0; a < n; a += l) {
|
698
|
-
const
|
699
|
-
o.push(e.rel_uuids.slice(a,
|
707
|
+
const c = Math.min(n, a + l);
|
708
|
+
o.push(e.rel_uuids.slice(a, c));
|
700
709
|
}
|
701
710
|
for (let a = 0; a < o.length; a++)
|
702
711
|
(await this.getStories({
|
@@ -705,8 +714,8 @@ class Ee {
|
|
705
714
|
version: t.version,
|
706
715
|
by_uuids: o[a].join(","),
|
707
716
|
excluding_fields: t.excluding_fields
|
708
|
-
})).data.stories.forEach((
|
709
|
-
r.push(
|
717
|
+
})).data.stories.forEach((c) => {
|
718
|
+
r.push(c);
|
710
719
|
});
|
711
720
|
} else
|
712
721
|
r = e.rels;
|
@@ -729,7 +738,7 @@ class Ee {
|
|
729
738
|
async resolveStories(e, t, s) {
|
730
739
|
var r, n;
|
731
740
|
let o = [];
|
732
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].
|
741
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
733
742
|
for (const l in this.relations[s])
|
734
743
|
this.iterateTree(
|
735
744
|
this.relations[s][l],
|
@@ -742,32 +751,37 @@ class Ee {
|
|
742
751
|
}
|
743
752
|
async cacheResponse(e, t, s, r) {
|
744
753
|
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
745
|
-
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e
|
754
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
|
746
755
|
const l = await o.get(n);
|
747
756
|
if (l)
|
748
757
|
return Promise.resolve(l);
|
749
758
|
}
|
750
759
|
return new Promise(async (l, a) => {
|
751
|
-
var
|
760
|
+
var c;
|
752
761
|
try {
|
753
|
-
const
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
762
|
+
const u = await this.throttle(
|
763
|
+
"get",
|
764
|
+
e,
|
765
|
+
t,
|
766
|
+
r
|
767
|
+
);
|
768
|
+
if (u.status !== 200)
|
769
|
+
return a(u);
|
770
|
+
let d = { data: u.data, headers: u.headers };
|
771
|
+
if ((c = u.headers) != null && c["per-page"] && (d = Object.assign({}, d, {
|
772
|
+
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
773
|
+
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
774
|
+
})), d.data.story || d.data.stories) {
|
775
|
+
const g = this.resolveCounter = ++this.resolveCounter % 1e3;
|
776
|
+
await this.resolveStories(d.data, t, `${g}`);
|
763
777
|
}
|
764
|
-
return t.version === "published" && e
|
765
|
-
} catch (
|
766
|
-
if (
|
778
|
+
return t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
|
779
|
+
} catch (u) {
|
780
|
+
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
767
781
|
return console.log(
|
768
782
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
769
783
|
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
770
|
-
a(
|
784
|
+
a(u);
|
771
785
|
}
|
772
786
|
});
|
773
787
|
}
|
@@ -775,36 +789,37 @@ class Ee {
|
|
775
789
|
return this.client.setFetchOptions(r), this.client[e](t, s);
|
776
790
|
}
|
777
791
|
cacheVersions() {
|
778
|
-
return
|
792
|
+
return E;
|
779
793
|
}
|
780
794
|
cacheVersion() {
|
781
|
-
return
|
795
|
+
return E[this.accessToken];
|
782
796
|
}
|
783
797
|
setCacheVersion(e) {
|
784
|
-
this.accessToken && (
|
798
|
+
this.accessToken && (E[this.accessToken] = e);
|
785
799
|
}
|
786
800
|
clearCacheVersion() {
|
787
|
-
this.accessToken && (
|
801
|
+
this.accessToken && (E[this.accessToken] = 0);
|
788
802
|
}
|
789
803
|
cacheProvider() {
|
790
804
|
switch (this.cache.type) {
|
791
805
|
case "memory":
|
792
806
|
return {
|
793
807
|
get(e) {
|
794
|
-
return Promise.resolve(
|
808
|
+
return Promise.resolve(x[e]);
|
795
809
|
},
|
796
810
|
getAll() {
|
797
|
-
return Promise.resolve(
|
811
|
+
return Promise.resolve(x);
|
798
812
|
},
|
799
813
|
set(e, t) {
|
800
|
-
return
|
814
|
+
return x[e] = t, Promise.resolve(void 0);
|
801
815
|
},
|
802
816
|
flush() {
|
803
|
-
return
|
817
|
+
return x = {}, Promise.resolve(void 0);
|
804
818
|
}
|
805
819
|
};
|
806
820
|
case "custom":
|
807
|
-
if (this.cache.custom)
|
821
|
+
if (this.cache.custom)
|
822
|
+
return this.cache.custom;
|
808
823
|
default:
|
809
824
|
return {
|
810
825
|
get() {
|
@@ -826,7 +841,7 @@ class Ee {
|
|
826
841
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
827
842
|
}
|
828
843
|
}
|
829
|
-
const
|
844
|
+
const ze = (i = {}) => {
|
830
845
|
const { apiOptions: e } = i;
|
831
846
|
if (!e.accessToken) {
|
832
847
|
console.error(
|
@@ -834,8 +849,8 @@ const Ce = (i = {}) => {
|
|
834
849
|
);
|
835
850
|
return;
|
836
851
|
}
|
837
|
-
return { storyblokApi: new
|
838
|
-
},
|
852
|
+
return { storyblokApi: new Oe(e) };
|
853
|
+
}, Be = (i) => {
|
839
854
|
if (typeof i != "object" || typeof i._editable > "u")
|
840
855
|
return {};
|
841
856
|
try {
|
@@ -850,25 +865,28 @@ const Ce = (i = {}) => {
|
|
850
865
|
return {};
|
851
866
|
}
|
852
867
|
};
|
853
|
-
|
854
|
-
|
855
|
-
|
868
|
+
function Le(i, e) {
|
869
|
+
if (!e)
|
870
|
+
return { src: i, attrs: {} };
|
856
871
|
let t = 0, s = 0;
|
857
872
|
const r = {}, n = [];
|
858
|
-
function o(a,
|
859
|
-
typeof a != "number" || a <=
|
873
|
+
function o(a, c, u, d, g) {
|
874
|
+
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)`) : g.push(`${d}(${a})`);
|
860
875
|
}
|
861
876
|
if (typeof e == "object") {
|
862
877
|
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) {
|
863
|
-
const { filters: a } = e || {}, { blur:
|
864
|
-
|
878
|
+
const { filters: a } = e || {}, { blur: c, brightness: u, fill: d, format: g, grayscale: T, quality: y, rotate: R } = a || {};
|
879
|
+
c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), d && n.push(`fill(${d})`), T && n.push("grayscale()"), R && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${R})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
|
865
880
|
}
|
866
881
|
e.srcset && (r.srcset = e.srcset.map((a) => {
|
867
882
|
if (typeof a == "number")
|
868
|
-
return `${i}/m/${a}x0/${n.length > 0 ?
|
883
|
+
return `${i}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
|
869
884
|
if (Array.isArray(a) && a.length === 2) {
|
870
|
-
const [
|
871
|
-
return `${i}/m/${
|
885
|
+
const [c, u] = a;
|
886
|
+
return `${i}/m/${c}x${u}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
|
887
|
+
} else {
|
888
|
+
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
889
|
+
return;
|
872
890
|
}
|
873
891
|
}).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
|
874
892
|
}
|
@@ -878,140 +896,175 @@ function Ie(i, e) {
|
|
878
896
|
attrs: r
|
879
897
|
};
|
880
898
|
}
|
881
|
-
|
882
|
-
|
899
|
+
var k = /* @__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))(k || {}), v = /* @__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))(v || {}), 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 || {});
|
900
|
+
const Ae = [
|
901
|
+
"area",
|
902
|
+
"base",
|
903
|
+
"br",
|
904
|
+
"col",
|
905
|
+
"embed",
|
906
|
+
"hr",
|
907
|
+
"img",
|
908
|
+
"input",
|
909
|
+
"link",
|
910
|
+
"meta",
|
911
|
+
"param",
|
912
|
+
"source",
|
913
|
+
"track",
|
914
|
+
"wbr"
|
915
|
+
], Ce = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Pe = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
|
916
|
+
function Ne(i) {
|
883
917
|
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
884
918
|
}
|
885
|
-
|
886
|
-
|
887
|
-
|
919
|
+
const D = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
|
920
|
+
function Me(i, e = {}, t) {
|
921
|
+
const s = Ce(e), r = s ? `${i} ${s}` : i;
|
922
|
+
return Ae.includes(i) ? `<${r}>` : `<${r}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
|
888
923
|
}
|
889
|
-
function
|
924
|
+
function De(i = {}) {
|
890
925
|
let e = 0;
|
891
926
|
const {
|
892
|
-
renderFn: t =
|
893
|
-
textFn: s =
|
927
|
+
renderFn: t = Me,
|
928
|
+
textFn: s = Ne,
|
894
929
|
resolvers: r = {},
|
895
|
-
optimizeImages: n = !1
|
896
|
-
|
897
|
-
|
898
|
-
|
930
|
+
optimizeImages: n = !1,
|
931
|
+
keyedResolvers: o = !1
|
932
|
+
} = i, l = (h) => (f) => {
|
933
|
+
const m = f.attrs || {};
|
934
|
+
return o && (m.key = `${h}-${e}`), t(h, m, f.children || null);
|
935
|
+
}, a = (h) => {
|
936
|
+
const { src: f, alt: m, title: b, srcset: w, sizes: $ } = h.attrs || {};
|
937
|
+
let S = f, _ = {};
|
899
938
|
if (n) {
|
900
|
-
const { src:
|
901
|
-
|
939
|
+
const { src: K, attrs: Y } = Le(f, n);
|
940
|
+
S = K, _ = Y;
|
902
941
|
}
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
942
|
+
o && (_ = {
|
943
|
+
..._,
|
944
|
+
key: `img-${e}`
|
945
|
+
});
|
946
|
+
const J = {
|
947
|
+
src: S,
|
948
|
+
alt: m,
|
949
|
+
title: b,
|
950
|
+
srcset: w,
|
951
|
+
sizes: $,
|
952
|
+
..._
|
909
953
|
};
|
910
|
-
return t("img",
|
911
|
-
},
|
912
|
-
const { level:
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
}, t("img", {
|
922
|
-
src: ($ = c.attrs) == null ? void 0 : $.fallbackImage,
|
923
|
-
alt: (T = c.attrs) == null ? void 0 : T.alt,
|
954
|
+
return t("img", D(J));
|
955
|
+
}, c = (h) => {
|
956
|
+
const { level: f, ...m } = h.attrs || {}, b = {
|
957
|
+
...m
|
958
|
+
};
|
959
|
+
return o && (b.key = `h${f}-${e}`), t(`h${f}`, b, h.children);
|
960
|
+
}, u = (h) => {
|
961
|
+
var f, m, b, w;
|
962
|
+
const $ = t("img", {
|
963
|
+
src: (f = h.attrs) == null ? void 0 : f.fallbackImage,
|
964
|
+
alt: (m = h.attrs) == null ? void 0 : m.alt,
|
924
965
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
925
966
|
draggable: "false",
|
926
967
|
loading: "lazy"
|
927
|
-
},
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
968
|
+
}), S = {
|
969
|
+
"data-type": "emoji",
|
970
|
+
"data-name": (b = h.attrs) == null ? void 0 : b.name,
|
971
|
+
"data-emoji": (w = h.attrs) == null ? void 0 : w.emoji
|
972
|
+
};
|
973
|
+
return o && (S.key = `emoji-${e}`), t("span", S, $);
|
974
|
+
}, d = (h) => t("pre", {
|
975
|
+
...h.attrs,
|
976
|
+
key: `code-${e}`
|
977
|
+
}, t("code", { key: `code-${e}` }, h.children || "")), g = (h, f = !1) => ({ text: m, attrs: b }) => {
|
978
|
+
const { class: w, id: $, ...S } = b || {}, _ = f ? {
|
979
|
+
class: w,
|
980
|
+
id: $,
|
981
|
+
style: Pe(S) || void 0
|
982
|
+
} : b || {};
|
983
|
+
return o && (_.key = `${h}-${e}`), t(h, D(_), m);
|
984
|
+
}, T = (h) => A(h), y = (h) => {
|
985
|
+
const { marks: f, ...m } = h;
|
986
|
+
return "text" in h ? f ? f.reduce(
|
987
|
+
(b, w) => T({ ...w, text: b }),
|
935
988
|
// Fix: Ensure render function returns a string
|
936
|
-
|
989
|
+
T({ ...m, children: m.children })
|
937
990
|
// Fix: Cast children to string
|
938
|
-
) : s(
|
939
|
-
},
|
940
|
-
const { linktype:
|
941
|
-
let
|
942
|
-
switch (
|
943
|
-
case
|
944
|
-
case
|
945
|
-
|
991
|
+
) : s(m.text) : "";
|
992
|
+
}, R = (h) => {
|
993
|
+
const { linktype: f, href: m, anchor: b, ...w } = h.attrs || {};
|
994
|
+
let $ = "";
|
995
|
+
switch (f) {
|
996
|
+
case I.ASSET:
|
997
|
+
case I.URL:
|
998
|
+
$ = m;
|
946
999
|
break;
|
947
|
-
case
|
948
|
-
|
1000
|
+
case I.EMAIL:
|
1001
|
+
$ = `mailto:${m}`;
|
949
1002
|
break;
|
950
|
-
case
|
951
|
-
|
1003
|
+
case I.STORY:
|
1004
|
+
$ = m;
|
952
1005
|
break;
|
953
1006
|
}
|
954
|
-
return
|
955
|
-
},
|
956
|
-
var
|
1007
|
+
return b && ($ = `${$}#${b}`), t("a", { ...w, href: $, key: `a-${e}` }, h.text);
|
1008
|
+
}, j = (h) => {
|
1009
|
+
var f, m;
|
957
1010
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
958
|
-
blok: (
|
959
|
-
id: (
|
1011
|
+
blok: (f = h == null ? void 0 : h.attrs) == null ? void 0 : f.body[0],
|
1012
|
+
id: (m = h.attrs) == null ? void 0 : m.id,
|
960
1013
|
key: `component-${e}`,
|
961
1014
|
style: "display: none"
|
962
|
-
}
|
963
|
-
},
|
964
|
-
[
|
965
|
-
[
|
966
|
-
[
|
967
|
-
[
|
968
|
-
[
|
969
|
-
[
|
970
|
-
[
|
971
|
-
[
|
972
|
-
[
|
973
|
-
[
|
974
|
-
[
|
975
|
-
[
|
976
|
-
[
|
977
|
-
[
|
978
|
-
[v.LINK,
|
979
|
-
[v.ANCHOR,
|
980
|
-
[v.STYLED,
|
981
|
-
[v.BOLD,
|
982
|
-
[v.TEXT_STYLE,
|
983
|
-
[v.ITALIC,
|
984
|
-
[v.UNDERLINE,
|
985
|
-
[v.STRIKE,
|
986
|
-
[v.CODE,
|
987
|
-
[v.SUPERSCRIPT,
|
988
|
-
[v.SUBSCRIPT,
|
989
|
-
[v.HIGHLIGHT,
|
990
|
-
...Object.entries(r).map(([
|
1015
|
+
});
|
1016
|
+
}, V = new Map([
|
1017
|
+
[k.DOCUMENT, l("div")],
|
1018
|
+
[k.HEADING, c],
|
1019
|
+
[k.PARAGRAPH, l("p")],
|
1020
|
+
[k.UL_LIST, l("ul")],
|
1021
|
+
[k.OL_LIST, l("ol")],
|
1022
|
+
[k.LIST_ITEM, l("li")],
|
1023
|
+
[k.IMAGE, a],
|
1024
|
+
[k.EMOJI, u],
|
1025
|
+
[k.CODE_BLOCK, d],
|
1026
|
+
[k.HR, l("hr")],
|
1027
|
+
[k.BR, l("br")],
|
1028
|
+
[k.QUOTE, l("blockquote")],
|
1029
|
+
[k.COMPONENT, j],
|
1030
|
+
[G.TEXT, y],
|
1031
|
+
[v.LINK, R],
|
1032
|
+
[v.ANCHOR, R],
|
1033
|
+
[v.STYLED, g("span", !0)],
|
1034
|
+
[v.BOLD, g("strong")],
|
1035
|
+
[v.TEXT_STYLE, g("span", !0)],
|
1036
|
+
[v.ITALIC, g("em")],
|
1037
|
+
[v.UNDERLINE, g("u")],
|
1038
|
+
[v.STRIKE, g("s")],
|
1039
|
+
[v.CODE, g("code")],
|
1040
|
+
[v.SUPERSCRIPT, g("sup")],
|
1041
|
+
[v.SUBSCRIPT, g("sub")],
|
1042
|
+
[v.HIGHLIGHT, g("mark")],
|
1043
|
+
...Object.entries(r).map(([h, f]) => [h, f])
|
991
1044
|
]);
|
992
|
-
function
|
1045
|
+
function M(h) {
|
993
1046
|
e += 1;
|
994
|
-
const
|
995
|
-
if (!
|
996
|
-
return console.error("<Storyblok>", `No resolver found for node type ${
|
997
|
-
if (
|
998
|
-
return
|
999
|
-
const
|
1000
|
-
return
|
1001
|
-
...
|
1002
|
-
children:
|
1047
|
+
const f = V.get(h.type);
|
1048
|
+
if (!f)
|
1049
|
+
return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
|
1050
|
+
if (h.type === "text")
|
1051
|
+
return f(h);
|
1052
|
+
const m = h.content ? h.content.map(A) : void 0;
|
1053
|
+
return f({
|
1054
|
+
...h,
|
1055
|
+
children: m
|
1003
1056
|
// Fix: Update the type of 'children' to Node[]
|
1004
1057
|
});
|
1005
1058
|
}
|
1006
|
-
function
|
1007
|
-
return Array.isArray(
|
1059
|
+
function A(h) {
|
1060
|
+
return Array.isArray(h) ? h.map(M) : M(h);
|
1008
1061
|
}
|
1009
1062
|
return {
|
1010
|
-
render:
|
1063
|
+
render: A
|
1011
1064
|
};
|
1012
1065
|
}
|
1013
|
-
let
|
1014
|
-
const
|
1066
|
+
let P, N = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
1067
|
+
const qe = (i, e, t = {}) => {
|
1015
1068
|
var l;
|
1016
1069
|
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
1017
1070
|
"_storyblok"
|
@@ -1022,13 +1075,13 @@ const Me = (i, e, t = {}) => {
|
|
1022
1075
|
return;
|
1023
1076
|
}
|
1024
1077
|
window.storyblokRegisterEvent(() => {
|
1025
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
1026
|
-
|
1078
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (c) => {
|
1079
|
+
c.action === "input" && c.story.id === i ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === i && window.location.reload();
|
1027
1080
|
});
|
1028
1081
|
});
|
1029
1082
|
}
|
1030
|
-
},
|
1031
|
-
var
|
1083
|
+
}, Ge = (i = {}) => {
|
1084
|
+
var d, g;
|
1032
1085
|
const {
|
1033
1086
|
bridge: e,
|
1034
1087
|
accessToken: t,
|
@@ -1040,12 +1093,12 @@ const Me = (i, e, t = {}) => {
|
|
1040
1093
|
r.accessToken = r.accessToken || t;
|
1041
1094
|
const l = { bridge: e, apiOptions: r };
|
1042
1095
|
let a = {};
|
1043
|
-
s.forEach((
|
1044
|
-
a = { ...a, ...
|
1045
|
-
}), o && (
|
1046
|
-
const
|
1047
|
-
return e !== !1 &&
|
1048
|
-
},
|
1096
|
+
s.forEach((T) => {
|
1097
|
+
a = { ...a, ...T(l) };
|
1098
|
+
}), o && (N = o);
|
1099
|
+
const u = !(typeof window > "u") && ((g = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : g.includes("_storyblok_tk"));
|
1100
|
+
return e !== !1 && u && q(N), P = new L(n.schema), n.resolver && F(P, n.resolver), a;
|
1101
|
+
}, F = (i, e) => {
|
1049
1102
|
i.addNode("blok", (t) => {
|
1050
1103
|
let s = "";
|
1051
1104
|
return t.attrs.body.forEach((r) => {
|
@@ -1054,29 +1107,29 @@ const Me = (i, e, t = {}) => {
|
|
1054
1107
|
html: s
|
1055
1108
|
};
|
1056
1109
|
});
|
1057
|
-
},
|
1058
|
-
let s = t ||
|
1110
|
+
}, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Fe = (i, e, t) => {
|
1111
|
+
let s = t || P;
|
1059
1112
|
if (!s) {
|
1060
1113
|
console.error(
|
1061
1114
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
1062
1115
|
);
|
1063
1116
|
return;
|
1064
1117
|
}
|
1065
|
-
return
|
1066
|
-
},
|
1118
|
+
return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && F(s, e.resolver)), s.render(i, {}, !1));
|
1119
|
+
}, Ve = () => q(N);
|
1067
1120
|
export {
|
1068
|
-
|
1121
|
+
k as BlockTypes,
|
1069
1122
|
v as MarkTypes,
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1123
|
+
L as RichTextResolver,
|
1124
|
+
_e as RichTextSchema,
|
1125
|
+
G as TextTypes,
|
1126
|
+
ze as apiPlugin,
|
1127
|
+
He as isRichTextEmpty,
|
1128
|
+
Ve as loadStoryblokBridge,
|
1129
|
+
qe as registerStoryblokBridge,
|
1130
|
+
Fe as renderRichText,
|
1131
|
+
De as richTextResolver,
|
1132
|
+
Be as storyblokEditable,
|
1133
|
+
Ge as storyblokInit,
|
1134
|
+
qe as useStoryblokBridge
|
1082
1135
|
};
|