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