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