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