@storyblok/js 3.0.6 → 3.0.8
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/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +344 -337
- package/package.json +7 -7
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let _ = !1;
|
|
2
|
-
const S = [], O = (
|
|
2
|
+
const S = [], O = (n) => new Promise((t, e) => {
|
|
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.");
|
|
@@ -9,31 +9,31 @@ const S = [], O = (o) => new Promise((e, t) => {
|
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
10
10
|
return;
|
|
11
11
|
const s = document.createElement("script");
|
|
12
|
-
s.async = !0, s.src =
|
|
13
|
-
S.forEach((i) => i()), _ = !0,
|
|
12
|
+
s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
|
|
13
|
+
S.forEach((i) => i()), _ = !0, t(r);
|
|
14
14
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
15
15
|
});
|
|
16
|
-
var I = Object.defineProperty, P = (
|
|
17
|
-
function j(
|
|
18
|
-
return !(
|
|
16
|
+
var I = Object.defineProperty, P = (n, t, e) => t in n ? I(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, h = (n, t, e) => (P(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
17
|
+
function j(n) {
|
|
18
|
+
return !(n !== n || n === 1 / 0 || n === -1 / 0);
|
|
19
19
|
}
|
|
20
|
-
function C(
|
|
21
|
-
if (!j(e))
|
|
22
|
-
throw new TypeError("Expected `limit` to be a finite number");
|
|
20
|
+
function C(n, t, e) {
|
|
23
21
|
if (!j(t))
|
|
22
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
23
|
+
if (!j(e))
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const s = [];
|
|
26
26
|
let r = [], i = 0;
|
|
27
|
-
const
|
|
27
|
+
const o = function() {
|
|
28
28
|
i++;
|
|
29
29
|
const a = setTimeout(function() {
|
|
30
|
-
i--, s.length > 0 &&
|
|
30
|
+
i--, s.length > 0 && o(), r = r.filter(function(u) {
|
|
31
31
|
return u !== a;
|
|
32
32
|
});
|
|
33
|
-
},
|
|
33
|
+
}, e);
|
|
34
34
|
r.indexOf(a) < 0 && r.push(a);
|
|
35
35
|
const l = s.shift();
|
|
36
|
-
l.resolve(
|
|
36
|
+
l.resolve(n.apply(l.self, l.args));
|
|
37
37
|
}, c = function(...a) {
|
|
38
38
|
const l = this;
|
|
39
39
|
return new Promise(function(u, p) {
|
|
@@ -42,7 +42,7 @@ function C(o, e, t) {
|
|
|
42
42
|
reject: p,
|
|
43
43
|
args: a,
|
|
44
44
|
self: l
|
|
45
|
-
}), i <
|
|
45
|
+
}), i < t && o();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
return c.abort = function() {
|
|
@@ -55,22 +55,22 @@ function C(o, e, t) {
|
|
|
55
55
|
}
|
|
56
56
|
class b {
|
|
57
57
|
constructor() {
|
|
58
|
-
h(this, "isCDNUrl", (
|
|
59
|
-
...
|
|
60
|
-
per_page:
|
|
58
|
+
h(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (t, e = 25, s = 1) => ({
|
|
59
|
+
...t,
|
|
60
|
+
per_page: e,
|
|
61
61
|
page: s
|
|
62
|
-
})), h(this, "delay", (
|
|
63
|
-
const s = Math.abs(
|
|
64
|
-
return this.arrayFrom(s, (i,
|
|
65
|
-
}), h(this, "asyncMap", async (
|
|
66
|
-
const
|
|
62
|
+
})), h(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), h(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), h(this, "range", (t = 0, e = t) => {
|
|
63
|
+
const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
|
|
64
|
+
return this.arrayFrom(s, (i, o) => o * r + t);
|
|
65
|
+
}), h(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), h(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], [])), h(this, "escapeHTML", function(t) {
|
|
66
|
+
const e = {
|
|
67
67
|
"&": "&",
|
|
68
68
|
"<": "<",
|
|
69
69
|
">": ">",
|
|
70
70
|
'"': """,
|
|
71
71
|
"'": "'"
|
|
72
72
|
}, s = /[&<>"']/g, r = RegExp(s.source);
|
|
73
|
-
return
|
|
73
|
+
return t && r.test(t) ? t.replace(s, (i) => e[i]) : t;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
@@ -80,18 +80,18 @@ class b {
|
|
|
80
80
|
* @param {Boolean} isArray
|
|
81
81
|
* @return {String} Stringified object
|
|
82
82
|
*/
|
|
83
|
-
stringify(
|
|
83
|
+
stringify(t, e, s) {
|
|
84
84
|
const r = [];
|
|
85
|
-
for (const i in
|
|
86
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
85
|
+
for (const i in t) {
|
|
86
|
+
if (!Object.prototype.hasOwnProperty.call(t, i))
|
|
87
87
|
continue;
|
|
88
|
-
const
|
|
88
|
+
const o = t[i], c = s ? "" : encodeURIComponent(i);
|
|
89
89
|
let a;
|
|
90
|
-
typeof
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Array.isArray(
|
|
94
|
-
) : a = (
|
|
90
|
+
typeof o == "object" ? a = this.stringify(
|
|
91
|
+
o,
|
|
92
|
+
e ? e + encodeURIComponent("[" + c + "]") : c,
|
|
93
|
+
Array.isArray(o)
|
|
94
|
+
) : a = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(o), r.push(a);
|
|
95
95
|
}
|
|
96
96
|
return r.join("&");
|
|
97
97
|
}
|
|
@@ -100,9 +100,9 @@ class b {
|
|
|
100
100
|
* @param {String} regionCode region code, could be eu, us, cn, ap or ca
|
|
101
101
|
* @return {String} The base URL of the region
|
|
102
102
|
*/
|
|
103
|
-
getRegionURL(
|
|
104
|
-
const
|
|
105
|
-
switch (
|
|
103
|
+
getRegionURL(t) {
|
|
104
|
+
const e = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
|
105
|
+
switch (t) {
|
|
106
106
|
case "us":
|
|
107
107
|
return s;
|
|
108
108
|
case "cn":
|
|
@@ -110,42 +110,42 @@ class b {
|
|
|
110
110
|
case "ap":
|
|
111
111
|
return i;
|
|
112
112
|
case "ca":
|
|
113
|
-
return
|
|
113
|
+
return o;
|
|
114
114
|
default:
|
|
115
|
-
return
|
|
115
|
+
return e;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
const A = function(
|
|
120
|
-
const
|
|
121
|
-
for (const s in
|
|
122
|
-
const r =
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return
|
|
126
|
-
}, N = (
|
|
119
|
+
const A = function(n, t) {
|
|
120
|
+
const e = {};
|
|
121
|
+
for (const s in n) {
|
|
122
|
+
const r = n[s];
|
|
123
|
+
t.indexOf(s) > -1 && r !== null && (e[s] = r);
|
|
124
|
+
}
|
|
125
|
+
return e;
|
|
126
|
+
}, N = (n) => n === "email", L = () => ({
|
|
127
127
|
singleTag: "hr"
|
|
128
128
|
}), M = () => ({
|
|
129
129
|
tag: "blockquote"
|
|
130
130
|
}), z = () => ({
|
|
131
131
|
tag: "ul"
|
|
132
|
-
}), U = (
|
|
132
|
+
}), U = (n) => ({
|
|
133
133
|
tag: [
|
|
134
134
|
"pre",
|
|
135
135
|
{
|
|
136
136
|
tag: "code",
|
|
137
|
-
attrs:
|
|
137
|
+
attrs: n.attrs
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
140
|
}), H = () => ({
|
|
141
141
|
singleTag: "br"
|
|
142
|
-
}), q = (
|
|
143
|
-
tag: `h${
|
|
144
|
-
}), B = (
|
|
142
|
+
}), q = (n) => ({
|
|
143
|
+
tag: `h${n.attrs.level}`
|
|
144
|
+
}), B = (n) => ({
|
|
145
145
|
singleTag: [
|
|
146
146
|
{
|
|
147
147
|
tag: "img",
|
|
148
|
-
attrs: A(
|
|
148
|
+
attrs: A(n.attrs, ["src", "alt", "title"])
|
|
149
149
|
}
|
|
150
150
|
]
|
|
151
151
|
}), F = () => ({
|
|
@@ -154,14 +154,14 @@ const A = function(o, e) {
|
|
|
154
154
|
tag: "ol"
|
|
155
155
|
}), J = () => ({
|
|
156
156
|
tag: "p"
|
|
157
|
-
}), D = (
|
|
157
|
+
}), D = (n) => ({
|
|
158
158
|
tag: [
|
|
159
159
|
{
|
|
160
160
|
tag: "span",
|
|
161
161
|
attrs: {
|
|
162
162
|
"data-type": "emoji",
|
|
163
|
-
"data-name":
|
|
164
|
-
emoji:
|
|
163
|
+
"data-name": n.attrs.name,
|
|
164
|
+
emoji: n.attrs.emoji
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
]
|
|
@@ -177,72 +177,72 @@ const A = function(o, e) {
|
|
|
177
177
|
tag: "code"
|
|
178
178
|
}), X = () => ({
|
|
179
179
|
tag: "i"
|
|
180
|
-
}), Z = (
|
|
181
|
-
if (!
|
|
180
|
+
}), Z = (n) => {
|
|
181
|
+
if (!n.attrs)
|
|
182
182
|
return {
|
|
183
183
|
tag: ""
|
|
184
184
|
};
|
|
185
|
-
const
|
|
186
|
-
if (delete
|
|
187
|
-
for (const r in
|
|
188
|
-
|
|
189
|
-
delete
|
|
185
|
+
const t = new b().escapeHTML, e = { ...n.attrs }, { linktype: s = "url" } = n.attrs;
|
|
186
|
+
if (delete e.linktype, e.href && (e.href = t(n.attrs.href || "")), N(s) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
|
|
187
|
+
for (const r in e.custom)
|
|
188
|
+
e[r] = e.custom[r];
|
|
189
|
+
delete e.custom;
|
|
190
190
|
}
|
|
191
191
|
return {
|
|
192
192
|
tag: [
|
|
193
193
|
{
|
|
194
194
|
tag: "a",
|
|
195
|
-
attrs:
|
|
195
|
+
attrs: e
|
|
196
196
|
}
|
|
197
197
|
]
|
|
198
198
|
};
|
|
199
|
-
},
|
|
199
|
+
}, tt = (n) => ({
|
|
200
200
|
tag: [
|
|
201
201
|
{
|
|
202
202
|
tag: "span",
|
|
203
|
-
attrs:
|
|
203
|
+
attrs: n.attrs
|
|
204
204
|
}
|
|
205
205
|
]
|
|
206
|
-
}),
|
|
206
|
+
}), et = () => ({
|
|
207
207
|
tag: "sub"
|
|
208
|
-
}),
|
|
208
|
+
}), st = () => ({
|
|
209
209
|
tag: "sup"
|
|
210
|
-
}),
|
|
210
|
+
}), rt = (n) => ({
|
|
211
211
|
tag: [
|
|
212
212
|
{
|
|
213
213
|
tag: "span",
|
|
214
|
-
attrs:
|
|
214
|
+
attrs: n.attrs
|
|
215
215
|
}
|
|
216
216
|
]
|
|
217
|
-
}),
|
|
218
|
-
var
|
|
219
|
-
return (
|
|
217
|
+
}), it = (n) => {
|
|
218
|
+
var t;
|
|
219
|
+
return (t = n.attrs) != null && t.color ? {
|
|
220
220
|
tag: [
|
|
221
221
|
{
|
|
222
222
|
tag: "span",
|
|
223
223
|
attrs: {
|
|
224
|
-
style: `background-color:${
|
|
224
|
+
style: `background-color:${n.attrs.color};`
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
]
|
|
228
228
|
} : {
|
|
229
229
|
tag: ""
|
|
230
230
|
};
|
|
231
|
-
},
|
|
232
|
-
var
|
|
233
|
-
return (
|
|
231
|
+
}, nt = (n) => {
|
|
232
|
+
var t;
|
|
233
|
+
return (t = n.attrs) != null && t.color ? {
|
|
234
234
|
tag: [
|
|
235
235
|
{
|
|
236
236
|
tag: "span",
|
|
237
237
|
attrs: {
|
|
238
|
-
style: `color:${
|
|
238
|
+
style: `color:${n.attrs.color}`
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
]
|
|
242
242
|
} : {
|
|
243
243
|
tag: ""
|
|
244
244
|
};
|
|
245
|
-
},
|
|
245
|
+
}, ot = {
|
|
246
246
|
nodes: {
|
|
247
247
|
horizontal_rule: L,
|
|
248
248
|
blockquote: M,
|
|
@@ -264,39 +264,39 @@ const A = function(o, e) {
|
|
|
264
264
|
code: Q,
|
|
265
265
|
italic: X,
|
|
266
266
|
link: Z,
|
|
267
|
-
styled:
|
|
268
|
-
subscript:
|
|
269
|
-
superscript:
|
|
270
|
-
anchor:
|
|
271
|
-
highlight:
|
|
272
|
-
textStyle:
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
const
|
|
267
|
+
styled: tt,
|
|
268
|
+
subscript: et,
|
|
269
|
+
superscript: st,
|
|
270
|
+
anchor: rt,
|
|
271
|
+
highlight: it,
|
|
272
|
+
textStyle: nt
|
|
273
|
+
}
|
|
274
|
+
}, at = function(n) {
|
|
275
|
+
const t = {
|
|
276
276
|
"&": "&",
|
|
277
277
|
"<": "<",
|
|
278
278
|
">": ">",
|
|
279
279
|
'"': """,
|
|
280
280
|
"'": "'"
|
|
281
|
-
},
|
|
282
|
-
return
|
|
281
|
+
}, e = /[&<>"']/g, s = RegExp(e.source);
|
|
282
|
+
return n && s.test(n) ? n.replace(e, (r) => t[r]) : n;
|
|
283
283
|
};
|
|
284
|
-
class
|
|
285
|
-
constructor(
|
|
286
|
-
h(this, "marks"), h(this, "nodes"),
|
|
284
|
+
class v {
|
|
285
|
+
constructor(t) {
|
|
286
|
+
h(this, "marks"), h(this, "nodes"), t || (t = ot), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
287
287
|
}
|
|
288
|
-
addNode(
|
|
289
|
-
this.nodes[
|
|
288
|
+
addNode(t, e) {
|
|
289
|
+
this.nodes[t] = e;
|
|
290
290
|
}
|
|
291
|
-
addMark(
|
|
292
|
-
this.marks[
|
|
291
|
+
addMark(t, e) {
|
|
292
|
+
this.marks[t] = e;
|
|
293
293
|
}
|
|
294
|
-
render(
|
|
295
|
-
if (
|
|
294
|
+
render(t, e = { optimizeImages: !1 }) {
|
|
295
|
+
if (t && t.content && Array.isArray(t.content)) {
|
|
296
296
|
let s = "";
|
|
297
|
-
return
|
|
297
|
+
return t.content.forEach((r) => {
|
|
298
298
|
s += this.renderNode(r);
|
|
299
|
-
}),
|
|
299
|
+
}), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
|
|
300
300
|
}
|
|
301
301
|
return console.warn(
|
|
302
302
|
`The render method must receive an Object with a "content" field.
|
|
@@ -325,101 +325,101 @@ class k {
|
|
|
325
325
|
}`
|
|
326
326
|
), "";
|
|
327
327
|
}
|
|
328
|
-
optimizeImages(
|
|
329
|
-
let s = 0, r = 0, i = "",
|
|
330
|
-
typeof
|
|
331
|
-
const c = s > 0 || r > 0 ||
|
|
332
|
-
return
|
|
328
|
+
optimizeImages(t, e) {
|
|
329
|
+
let s = 0, r = 0, i = "", o = "";
|
|
330
|
+
typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (i += `width="${e.width}" `, s = e.width), typeof e.height == "number" && e.height > 0 && (i += `height="${e.height}" `, r = e.height), (e.loading === "lazy" || e.loading === "eager") && (i += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (i += `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-Fa-f]{6}/g) || 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))), i.length > 0 && (t = t.replace(/<img/g, `<img ${i.trim()}`));
|
|
331
|
+
const c = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
|
332
|
+
return t = t.replace(
|
|
333
333
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
334
334
|
`a.storyblok.com/f/$1/$2.$3/m/${c}`
|
|
335
|
-
), typeof
|
|
335
|
+
), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
336
336
|
var l, u;
|
|
337
337
|
const p = a.match(
|
|
338
338
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
339
339
|
);
|
|
340
340
|
if (p && p.length > 0) {
|
|
341
341
|
const g = {
|
|
342
|
-
srcset: (l =
|
|
342
|
+
srcset: (l = e.srcset) == null ? void 0 : l.map((d) => {
|
|
343
343
|
if (typeof d == "number")
|
|
344
|
-
return `//${p}/m/${d}x0${
|
|
344
|
+
return `//${p}/m/${d}x0${o} ${d}w`;
|
|
345
345
|
if (typeof d == "object" && d.length === 2) {
|
|
346
|
-
let
|
|
347
|
-
return typeof d[0] == "number" && (
|
|
346
|
+
let k = 0, T = 0;
|
|
347
|
+
return typeof d[0] == "number" && (k = d[0]), typeof d[1] == "number" && (T = d[1]), `//${p}/m/${k}x${T}${o} ${k}w`;
|
|
348
348
|
}
|
|
349
349
|
}).join(", "),
|
|
350
|
-
sizes: (u =
|
|
350
|
+
sizes: (u = e.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
351
351
|
};
|
|
352
352
|
let f = "";
|
|
353
353
|
return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
|
354
354
|
}
|
|
355
355
|
return a;
|
|
356
|
-
})),
|
|
356
|
+
})), t;
|
|
357
357
|
}
|
|
358
|
-
renderNode(
|
|
359
|
-
const
|
|
360
|
-
|
|
358
|
+
renderNode(t) {
|
|
359
|
+
const e = [];
|
|
360
|
+
t.marks && t.marks.forEach((r) => {
|
|
361
361
|
const i = this.getMatchingMark(r);
|
|
362
|
-
i && i.tag !== "" &&
|
|
362
|
+
i && i.tag !== "" && e.push(this.renderOpeningTag(i.tag));
|
|
363
363
|
});
|
|
364
|
-
const s = this.getMatchingNode(
|
|
365
|
-
return s && s.tag &&
|
|
366
|
-
|
|
367
|
-
}) :
|
|
364
|
+
const s = this.getMatchingNode(t);
|
|
365
|
+
return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
|
|
366
|
+
e.push(this.renderNode(r));
|
|
367
|
+
}) : t.text ? e.push(at(t.text)) : s && s.singleTag ? e.push(this.renderTag(s.singleTag, " /")) : s && s.html ? e.push(s.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), s && s.tag && e.push(this.renderClosingTag(s.tag)), t.marks && t.marks.slice(0).reverse().forEach((r) => {
|
|
368
368
|
const i = this.getMatchingMark(r);
|
|
369
|
-
i && i.tag !== "" &&
|
|
370
|
-
}),
|
|
369
|
+
i && i.tag !== "" && e.push(this.renderClosingTag(i.tag));
|
|
370
|
+
}), e.join("");
|
|
371
371
|
}
|
|
372
|
-
renderTag(
|
|
373
|
-
return
|
|
372
|
+
renderTag(t, e) {
|
|
373
|
+
return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
|
|
374
374
|
if (s.constructor === String)
|
|
375
|
-
return `<${s}${
|
|
375
|
+
return `<${s}${e}>`;
|
|
376
376
|
{
|
|
377
377
|
let r = `<${s.tag}`;
|
|
378
378
|
if (s.attrs)
|
|
379
379
|
for (const i in s.attrs) {
|
|
380
|
-
const
|
|
381
|
-
|
|
380
|
+
const o = s.attrs[i];
|
|
381
|
+
o !== null && (r += ` ${i}="${o}"`);
|
|
382
382
|
}
|
|
383
|
-
return `${r}${
|
|
383
|
+
return `${r}${e}>`;
|
|
384
384
|
}
|
|
385
385
|
}).join("");
|
|
386
386
|
}
|
|
387
|
-
renderOpeningTag(
|
|
388
|
-
return this.renderTag(
|
|
387
|
+
renderOpeningTag(t) {
|
|
388
|
+
return this.renderTag(t, "");
|
|
389
389
|
}
|
|
390
|
-
renderClosingTag(
|
|
391
|
-
return
|
|
390
|
+
renderClosingTag(t) {
|
|
391
|
+
return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
|
|
392
392
|
}
|
|
393
|
-
getMatchingNode(
|
|
394
|
-
const
|
|
395
|
-
if (typeof
|
|
396
|
-
return t
|
|
393
|
+
getMatchingNode(t) {
|
|
394
|
+
const e = this.nodes[t.type];
|
|
395
|
+
if (typeof e == "function")
|
|
396
|
+
return e(t);
|
|
397
397
|
}
|
|
398
|
-
getMatchingMark(
|
|
399
|
-
const
|
|
400
|
-
if (typeof
|
|
401
|
-
return t
|
|
398
|
+
getMatchingMark(t) {
|
|
399
|
+
const e = this.marks[t.type];
|
|
400
|
+
if (typeof e == "function")
|
|
401
|
+
return e(t);
|
|
402
402
|
}
|
|
403
|
-
renderEmoji(
|
|
404
|
-
if (
|
|
405
|
-
return
|
|
406
|
-
const
|
|
403
|
+
renderEmoji(t) {
|
|
404
|
+
if (t.attrs.emoji)
|
|
405
|
+
return t.attrs.emoji;
|
|
406
|
+
const e = [
|
|
407
407
|
{
|
|
408
408
|
tag: "img",
|
|
409
409
|
attrs: {
|
|
410
|
-
src:
|
|
410
|
+
src: t.attrs.fallbackImage,
|
|
411
411
|
draggable: "false",
|
|
412
412
|
loading: "lazy",
|
|
413
413
|
align: "absmiddle"
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
];
|
|
417
|
-
return this.renderTag(
|
|
417
|
+
return this.renderTag(e, " /");
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
class
|
|
421
|
-
constructor(
|
|
422
|
-
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), h(this, "fetchOptions"), this.baseURL =
|
|
420
|
+
class lt {
|
|
421
|
+
constructor(t) {
|
|
422
|
+
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), h(this, "fetchOptions"), this.baseURL = t.baseURL, this.headers = t.headers || new Headers(), this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
423
423
|
}
|
|
424
424
|
/**
|
|
425
425
|
*
|
|
@@ -427,50 +427,50 @@ class le {
|
|
|
427
427
|
* @param params ISbStoriesParams
|
|
428
428
|
* @returns Promise<ISbResponse | Error>
|
|
429
429
|
*/
|
|
430
|
-
get(
|
|
431
|
-
return this.url =
|
|
430
|
+
get(t, e) {
|
|
431
|
+
return this.url = t, this.parameters = e, this._methodHandler("get");
|
|
432
432
|
}
|
|
433
|
-
post(
|
|
434
|
-
return this.url =
|
|
433
|
+
post(t, e) {
|
|
434
|
+
return this.url = t, this.parameters = e, this._methodHandler("post");
|
|
435
435
|
}
|
|
436
|
-
put(
|
|
437
|
-
return this.url =
|
|
436
|
+
put(t, e) {
|
|
437
|
+
return this.url = t, this.parameters = e, this._methodHandler("put");
|
|
438
438
|
}
|
|
439
|
-
delete(
|
|
440
|
-
return this.url =
|
|
439
|
+
delete(t, e) {
|
|
440
|
+
return this.url = t, this.parameters = e, this._methodHandler("delete");
|
|
441
441
|
}
|
|
442
|
-
async _responseHandler(
|
|
443
|
-
const
|
|
442
|
+
async _responseHandler(t) {
|
|
443
|
+
const e = [], s = {
|
|
444
444
|
data: {},
|
|
445
445
|
headers: {},
|
|
446
446
|
status: 0,
|
|
447
447
|
statusText: ""
|
|
448
448
|
};
|
|
449
|
-
|
|
449
|
+
t.status !== 204 && await t.json().then((r) => {
|
|
450
450
|
s.data = r;
|
|
451
451
|
});
|
|
452
|
-
for (const r of
|
|
453
|
-
|
|
454
|
-
return s.headers = { ...
|
|
452
|
+
for (const r of t.headers.entries())
|
|
453
|
+
e[r[0]] = r[1];
|
|
454
|
+
return s.headers = { ...e }, s.status = t.status, s.statusText = t.statusText, s;
|
|
455
455
|
}
|
|
456
|
-
async _methodHandler(
|
|
457
|
-
let
|
|
458
|
-
if (
|
|
456
|
+
async _methodHandler(t) {
|
|
457
|
+
let e = `${this.baseURL}${this.url}`, s = null;
|
|
458
|
+
if (t === "get") {
|
|
459
459
|
const a = new b();
|
|
460
|
-
|
|
460
|
+
e = `${this.baseURL}${this.url}?${a.stringify(
|
|
461
461
|
this.parameters
|
|
462
462
|
)}`;
|
|
463
463
|
} else
|
|
464
464
|
s = JSON.stringify(this.parameters);
|
|
465
|
-
const r = new URL(
|
|
465
|
+
const r = new URL(e), i = new AbortController(), { signal: o } = i;
|
|
466
466
|
let c;
|
|
467
467
|
this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
|
|
468
468
|
try {
|
|
469
|
-
const a = await fetch(`${r}`, {
|
|
470
|
-
method:
|
|
469
|
+
const a = await this.fetch(`${r}`, {
|
|
470
|
+
method: t,
|
|
471
471
|
headers: this.headers,
|
|
472
472
|
body: s,
|
|
473
|
-
signal:
|
|
473
|
+
signal: o,
|
|
474
474
|
...this.fetchOptions
|
|
475
475
|
});
|
|
476
476
|
this.timeout && clearTimeout(c);
|
|
@@ -484,119 +484,120 @@ class le {
|
|
|
484
484
|
};
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
|
-
setFetchOptions(
|
|
488
|
-
Object.keys(
|
|
487
|
+
setFetchOptions(t = {}) {
|
|
488
|
+
Object.keys(t).length > 0 && "method" in t && delete t.method, this.fetchOptions = { ...t };
|
|
489
489
|
}
|
|
490
490
|
eject() {
|
|
491
491
|
this.ejectInterceptor = !0;
|
|
492
492
|
}
|
|
493
|
-
_statusHandler(
|
|
494
|
-
const
|
|
493
|
+
_statusHandler(t) {
|
|
494
|
+
const e = /20[0-6]/g;
|
|
495
495
|
return new Promise((s, r) => {
|
|
496
|
-
if (
|
|
497
|
-
return s(
|
|
496
|
+
if (e.test(`${t.status}`))
|
|
497
|
+
return s(t);
|
|
498
498
|
const i = {
|
|
499
|
-
message:
|
|
500
|
-
status:
|
|
501
|
-
response: Array.isArray(
|
|
499
|
+
message: t.statusText,
|
|
500
|
+
status: t.status,
|
|
501
|
+
response: Array.isArray(t.data) ? t.data[0] : t.data.error || t.data.slug
|
|
502
502
|
};
|
|
503
503
|
r(i);
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
var ce = { npm_package_version: "6.6.3" };
|
|
508
507
|
const x = "SB-Agent", w = {
|
|
509
508
|
defaultAgentName: "SB-JS-CLIENT",
|
|
510
509
|
defaultAgentVersion: "SB-Agent-Version",
|
|
511
|
-
packageVersion:
|
|
510
|
+
packageVersion: "6.0.0"
|
|
512
511
|
};
|
|
513
512
|
let y = {};
|
|
514
513
|
const m = {};
|
|
515
|
-
class
|
|
514
|
+
class ct {
|
|
516
515
|
/**
|
|
517
516
|
*
|
|
518
517
|
* @param config ISbConfig interface
|
|
519
518
|
* @param endpoint string, optional
|
|
520
519
|
*/
|
|
521
|
-
constructor(
|
|
520
|
+
constructor(t, e) {
|
|
522
521
|
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), h(this, "stringifiedStoriesCache");
|
|
523
|
-
let s =
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
522
|
+
let s = t.endpoint || e;
|
|
523
|
+
if (!s) {
|
|
524
|
+
const o = new b().getRegionURL, c = t.https === !1 ? "http" : "https";
|
|
525
|
+
t.oauthToken ? s = `${c}://${o(t.region)}/v1` : s = `${c}://${o(t.region)}/v2`;
|
|
526
|
+
}
|
|
527
|
+
const r = new Headers();
|
|
528
|
+
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), t.headers)
|
|
529
|
+
for (const o in t.headers)
|
|
530
|
+
r.set(o, t.headers[o]);
|
|
531
|
+
r.has(x) || (r.set(x, w.defaultAgentName), r.set(
|
|
531
532
|
w.defaultAgentVersion,
|
|
532
533
|
w.packageVersion
|
|
533
534
|
));
|
|
534
|
-
let
|
|
535
|
-
|
|
535
|
+
let i = 5;
|
|
536
|
+
t.oauthToken && (r.set("Authorization", t.oauthToken), i = 3), t.rateLimit && (i = t.rateLimit), t.richTextSchema ? this.richTextResolver = new v(t.richTextSchema) : this.richTextResolver = new v(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = C(this.throttledRequest, i, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = t.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new lt({
|
|
536
537
|
baseURL: s,
|
|
537
|
-
timeout:
|
|
538
|
-
headers:
|
|
539
|
-
responseInterceptor:
|
|
540
|
-
fetch:
|
|
538
|
+
timeout: t.timeout || 0,
|
|
539
|
+
headers: r,
|
|
540
|
+
responseInterceptor: t.responseInterceptor,
|
|
541
|
+
fetch: t.fetch
|
|
541
542
|
});
|
|
542
543
|
}
|
|
543
|
-
setComponentResolver(
|
|
544
|
-
this.richTextResolver.addNode("blok", (
|
|
544
|
+
setComponentResolver(t) {
|
|
545
|
+
this.richTextResolver.addNode("blok", (e) => {
|
|
545
546
|
let s = "";
|
|
546
|
-
return
|
|
547
|
-
s +=
|
|
547
|
+
return e.attrs.body && e.attrs.body.forEach((r) => {
|
|
548
|
+
s += t(r.component, r);
|
|
548
549
|
}), {
|
|
549
550
|
html: s
|
|
550
551
|
};
|
|
551
552
|
});
|
|
552
553
|
}
|
|
553
|
-
parseParams(
|
|
554
|
-
return
|
|
554
|
+
parseParams(t) {
|
|
555
|
+
return t.token || (t.token = this.getToken()), t.cv || (t.cv = m[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), typeof t.resolve_relations < "u" && (t.resolve_level = 2), t;
|
|
555
556
|
}
|
|
556
|
-
factoryParamOptions(
|
|
557
|
-
return this.helpers.isCDNUrl(
|
|
557
|
+
factoryParamOptions(t, e) {
|
|
558
|
+
return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
|
|
558
559
|
}
|
|
559
|
-
makeRequest(
|
|
560
|
+
makeRequest(t, e, s, r) {
|
|
560
561
|
const i = this.factoryParamOptions(
|
|
561
|
-
|
|
562
|
-
this.helpers.getOptionsPage(
|
|
562
|
+
t,
|
|
563
|
+
this.helpers.getOptionsPage(e, s, r)
|
|
563
564
|
);
|
|
564
|
-
return this.cacheResponse(
|
|
565
|
+
return this.cacheResponse(t, i);
|
|
565
566
|
}
|
|
566
|
-
get(
|
|
567
|
-
|
|
568
|
-
const r = `/${
|
|
567
|
+
get(t, e, s) {
|
|
568
|
+
e || (e = {});
|
|
569
|
+
const r = `/${t}`, i = this.factoryParamOptions(r, e);
|
|
569
570
|
return this.client.setFetchOptions(s), this.cacheResponse(r, i);
|
|
570
571
|
}
|
|
571
|
-
async getAll(
|
|
572
|
-
const i = (
|
|
572
|
+
async getAll(t, e, s, r) {
|
|
573
|
+
const i = (e == null ? void 0 : e.per_page) || 25, o = `/${t}`, c = o.split("/"), a = s || c[c.length - 1], l = 1, u = await this.makeRequest(o, e, i, l), p = u.total ? Math.ceil(u.total / i) : 1;
|
|
573
574
|
this.client.setFetchOptions(r);
|
|
574
575
|
const g = await this.helpers.asyncMap(
|
|
575
576
|
this.helpers.range(l, p),
|
|
576
|
-
(f) => this.makeRequest(
|
|
577
|
+
(f) => this.makeRequest(o, e, i, f + 1)
|
|
577
578
|
);
|
|
578
579
|
return this.helpers.flatMap(
|
|
579
580
|
[u, ...g],
|
|
580
581
|
(f) => Object.values(f.data[a])
|
|
581
582
|
);
|
|
582
583
|
}
|
|
583
|
-
post(
|
|
584
|
-
const r = `/${
|
|
585
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r,
|
|
584
|
+
post(t, e, s) {
|
|
585
|
+
const r = `/${t}`;
|
|
586
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, e));
|
|
586
587
|
}
|
|
587
|
-
put(
|
|
588
|
-
const r = `/${
|
|
589
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r,
|
|
588
|
+
put(t, e, s) {
|
|
589
|
+
const r = `/${t}`;
|
|
590
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, e));
|
|
590
591
|
}
|
|
591
|
-
delete(
|
|
592
|
-
const r = `/${
|
|
593
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r,
|
|
592
|
+
delete(t, e, s) {
|
|
593
|
+
const r = `/${t}`;
|
|
594
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, e));
|
|
594
595
|
}
|
|
595
|
-
getStories(
|
|
596
|
-
return this.client.setFetchOptions(t), this.get("cdn/stories",
|
|
596
|
+
getStories(t, e) {
|
|
597
|
+
return this.client.setFetchOptions(e), this._addResolveLevel(t), this.get("cdn/stories", t);
|
|
597
598
|
}
|
|
598
|
-
getStory(
|
|
599
|
-
return this.client.setFetchOptions(s), this.get(`cdn/stories/${
|
|
599
|
+
getStory(t, e, s) {
|
|
600
|
+
return this.client.setFetchOptions(s), this._addResolveLevel(e), this.get(`cdn/stories/${t}`, e);
|
|
600
601
|
}
|
|
601
602
|
getToken() {
|
|
602
603
|
return this.accessToken;
|
|
@@ -604,11 +605,14 @@ class he {
|
|
|
604
605
|
ejectInterceptor() {
|
|
605
606
|
this.client.eject();
|
|
606
607
|
}
|
|
607
|
-
|
|
608
|
-
|
|
608
|
+
_addResolveLevel(t) {
|
|
609
|
+
typeof t.resolve_relations < "u" && (t.resolve_level = 2);
|
|
610
|
+
}
|
|
611
|
+
_cleanCopy(t) {
|
|
612
|
+
return JSON.parse(JSON.stringify(t));
|
|
609
613
|
}
|
|
610
|
-
_insertLinks(
|
|
611
|
-
const r = e
|
|
614
|
+
_insertLinks(t, e, s) {
|
|
615
|
+
const r = t[e];
|
|
612
616
|
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]));
|
|
613
617
|
}
|
|
614
618
|
/**
|
|
@@ -617,60 +621,60 @@ class he {
|
|
|
617
621
|
* @param uuid The uuid of the story
|
|
618
622
|
* @returns string | object
|
|
619
623
|
*/
|
|
620
|
-
getStoryReference(
|
|
621
|
-
return this.relations[
|
|
622
|
-
this.relations[
|
|
623
|
-
)), JSON.parse(this.stringifiedStoriesCache[
|
|
624
|
+
getStoryReference(t, e) {
|
|
625
|
+
return this.relations[t][e] ? (this.stringifiedStoriesCache[e] || (this.stringifiedStoriesCache[e] = JSON.stringify(
|
|
626
|
+
this.relations[t][e]
|
|
627
|
+
)), JSON.parse(this.stringifiedStoriesCache[e])) : e;
|
|
624
628
|
}
|
|
625
|
-
_insertRelations(
|
|
626
|
-
s.indexOf(`${
|
|
629
|
+
_insertRelations(t, e, s, r) {
|
|
630
|
+
s.indexOf(`${t.component}.${e}`) > -1 && (typeof t[e] == "string" ? t[e] = this.getStoryReference(r, t[e]) : Array.isArray(t[e]) && (t[e] = t[e].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
|
|
627
631
|
}
|
|
628
|
-
iterateTree(
|
|
632
|
+
iterateTree(t, e, s) {
|
|
629
633
|
const r = (i) => {
|
|
630
634
|
if (i != null) {
|
|
631
635
|
if (i.constructor === Array)
|
|
632
|
-
for (let
|
|
633
|
-
r(i[
|
|
636
|
+
for (let o = 0; o < i.length; o++)
|
|
637
|
+
r(i[o]);
|
|
634
638
|
else if (i.constructor === Object) {
|
|
635
639
|
if (i._stopResolving)
|
|
636
640
|
return;
|
|
637
|
-
for (const
|
|
641
|
+
for (const o in i)
|
|
638
642
|
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
|
639
643
|
i,
|
|
640
|
-
|
|
641
|
-
|
|
644
|
+
o,
|
|
645
|
+
e,
|
|
642
646
|
s
|
|
643
647
|
), this._insertLinks(
|
|
644
648
|
i,
|
|
645
|
-
|
|
649
|
+
o,
|
|
646
650
|
s
|
|
647
|
-
)), r(i[
|
|
651
|
+
)), r(i[o]);
|
|
648
652
|
}
|
|
649
653
|
}
|
|
650
654
|
};
|
|
651
|
-
r(
|
|
655
|
+
r(t.content);
|
|
652
656
|
}
|
|
653
|
-
async resolveLinks(
|
|
657
|
+
async resolveLinks(t, e, s) {
|
|
654
658
|
let r = [];
|
|
655
|
-
if (
|
|
656
|
-
const i =
|
|
659
|
+
if (t.link_uuids) {
|
|
660
|
+
const i = t.link_uuids.length, o = [], c = 50;
|
|
657
661
|
for (let a = 0; a < i; a += c) {
|
|
658
662
|
const l = Math.min(i, a + c);
|
|
659
|
-
|
|
663
|
+
o.push(t.link_uuids.slice(a, l));
|
|
660
664
|
}
|
|
661
|
-
for (let a = 0; a <
|
|
665
|
+
for (let a = 0; a < o.length; a++)
|
|
662
666
|
(await this.getStories({
|
|
663
667
|
per_page: c,
|
|
664
|
-
language:
|
|
665
|
-
version:
|
|
666
|
-
by_uuids:
|
|
668
|
+
language: e.language,
|
|
669
|
+
version: e.version,
|
|
670
|
+
by_uuids: o[a].join(",")
|
|
667
671
|
})).data.stories.forEach(
|
|
668
672
|
(l) => {
|
|
669
673
|
r.push(l);
|
|
670
674
|
}
|
|
671
675
|
);
|
|
672
676
|
} else
|
|
673
|
-
r =
|
|
677
|
+
r = t.links;
|
|
674
678
|
r.forEach((i) => {
|
|
675
679
|
this.links[s][i.uuid] = {
|
|
676
680
|
...i,
|
|
@@ -678,26 +682,26 @@ class he {
|
|
|
678
682
|
};
|
|
679
683
|
});
|
|
680
684
|
}
|
|
681
|
-
async resolveRelations(
|
|
685
|
+
async resolveRelations(t, e, s) {
|
|
682
686
|
let r = [];
|
|
683
|
-
if (
|
|
684
|
-
const i =
|
|
687
|
+
if (t.rel_uuids) {
|
|
688
|
+
const i = t.rel_uuids.length, o = [], c = 50;
|
|
685
689
|
for (let a = 0; a < i; a += c) {
|
|
686
690
|
const l = Math.min(i, a + c);
|
|
687
|
-
|
|
691
|
+
o.push(t.rel_uuids.slice(a, l));
|
|
688
692
|
}
|
|
689
|
-
for (let a = 0; a <
|
|
693
|
+
for (let a = 0; a < o.length; a++)
|
|
690
694
|
(await this.getStories({
|
|
691
695
|
per_page: c,
|
|
692
|
-
language:
|
|
693
|
-
version:
|
|
694
|
-
by_uuids:
|
|
695
|
-
excluding_fields:
|
|
696
|
+
language: e.language,
|
|
697
|
+
version: e.version,
|
|
698
|
+
by_uuids: o[a].join(","),
|
|
699
|
+
excluding_fields: e.excluding_fields
|
|
696
700
|
})).data.stories.forEach((l) => {
|
|
697
701
|
r.push(l);
|
|
698
702
|
});
|
|
699
703
|
} else
|
|
700
|
-
r =
|
|
704
|
+
r = t.rels;
|
|
701
705
|
r && r.length > 0 && r.forEach((i) => {
|
|
702
706
|
this.relations[s][i.uuid] = {
|
|
703
707
|
...i,
|
|
@@ -714,32 +718,32 @@ class he {
|
|
|
714
718
|
* @returns Promise<void>
|
|
715
719
|
*
|
|
716
720
|
*/
|
|
717
|
-
async resolveStories(
|
|
721
|
+
async resolveStories(t, e, s) {
|
|
718
722
|
var r, i;
|
|
719
|
-
let
|
|
720
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof
|
|
723
|
+
let o = [];
|
|
724
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (o = e.resolve_relations.split(",")), await this.resolveRelations(t, e, s)), e.resolve_links && ["1", "story", "url", "link"].indexOf(e.resolve_links) > -1 && ((r = t.links) != null && r.length || (i = t.link_uuids) != null && i.length) && await this.resolveLinks(t, e, s), this.resolveNestedRelations)
|
|
721
725
|
for (const c in this.relations[s])
|
|
722
726
|
this.iterateTree(
|
|
723
727
|
this.relations[s][c],
|
|
724
|
-
|
|
728
|
+
o,
|
|
725
729
|
s
|
|
726
730
|
);
|
|
727
|
-
|
|
728
|
-
this.iterateTree(c,
|
|
731
|
+
t.story ? this.iterateTree(t.story, o, s) : t.stories.forEach((c) => {
|
|
732
|
+
this.iterateTree(c, o, s);
|
|
729
733
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
730
734
|
}
|
|
731
|
-
async cacheResponse(
|
|
735
|
+
async cacheResponse(t, e, s) {
|
|
732
736
|
(typeof s > "u" || !s) && (s = 0);
|
|
733
|
-
const r = this.helpers.stringify({ url:
|
|
734
|
-
if (this.cache.clear === "auto" &&
|
|
735
|
-
const
|
|
736
|
-
if (
|
|
737
|
-
return Promise.resolve(
|
|
737
|
+
const r = this.helpers.stringify({ url: t, params: e }), i = this.cacheProvider();
|
|
738
|
+
if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
|
|
739
|
+
const o = await i.get(r);
|
|
740
|
+
if (o)
|
|
741
|
+
return Promise.resolve(o);
|
|
738
742
|
}
|
|
739
|
-
return new Promise(async (
|
|
743
|
+
return new Promise(async (o, c) => {
|
|
740
744
|
var a;
|
|
741
745
|
try {
|
|
742
|
-
const l = await this.throttle("get",
|
|
746
|
+
const l = await this.throttle("get", t, e);
|
|
743
747
|
if (l.status !== 200)
|
|
744
748
|
return c(l);
|
|
745
749
|
let u = { data: l.data, headers: l.headers };
|
|
@@ -748,18 +752,18 @@ class he {
|
|
|
748
752
|
total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
|
|
749
753
|
})), u.data.story || u.data.stories) {
|
|
750
754
|
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
751
|
-
await this.resolveStories(u.data,
|
|
755
|
+
await this.resolveStories(u.data, e, `${p}`);
|
|
752
756
|
}
|
|
753
|
-
return
|
|
757
|
+
return e.version === "published" && t != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && e.token && (e.version === "draft" && m[e.token] != u.data.cv && await this.flushCache(), m[e.token] = e.cv ? e.cv : u.data.cv), o(u);
|
|
754
758
|
} catch (l) {
|
|
755
759
|
if (l.response && l.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
|
756
|
-
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(
|
|
760
|
+
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(t, e, s).then(o).catch(c);
|
|
757
761
|
c(l);
|
|
758
762
|
}
|
|
759
763
|
});
|
|
760
764
|
}
|
|
761
|
-
throttledRequest(
|
|
762
|
-
return this.client[
|
|
765
|
+
throttledRequest(t, e, s) {
|
|
766
|
+
return this.client[t](e, s);
|
|
763
767
|
}
|
|
764
768
|
cacheVersions() {
|
|
765
769
|
return m;
|
|
@@ -767,21 +771,24 @@ class he {
|
|
|
767
771
|
cacheVersion() {
|
|
768
772
|
return m[this.accessToken];
|
|
769
773
|
}
|
|
770
|
-
setCacheVersion(
|
|
771
|
-
this.accessToken && (m[this.accessToken] =
|
|
774
|
+
setCacheVersion(t) {
|
|
775
|
+
this.accessToken && (m[this.accessToken] = t);
|
|
776
|
+
}
|
|
777
|
+
clearCacheVersion() {
|
|
778
|
+
this.accessToken && (m[this.accessToken] = 0);
|
|
772
779
|
}
|
|
773
780
|
cacheProvider() {
|
|
774
781
|
switch (this.cache.type) {
|
|
775
782
|
case "memory":
|
|
776
783
|
return {
|
|
777
|
-
get(
|
|
778
|
-
return Promise.resolve(y[
|
|
784
|
+
get(t) {
|
|
785
|
+
return Promise.resolve(y[t]);
|
|
779
786
|
},
|
|
780
787
|
getAll() {
|
|
781
788
|
return Promise.resolve(y);
|
|
782
789
|
},
|
|
783
|
-
set(
|
|
784
|
-
return y[
|
|
790
|
+
set(t, e) {
|
|
791
|
+
return y[t] = e, Promise.resolve(void 0);
|
|
785
792
|
},
|
|
786
793
|
flush() {
|
|
787
794
|
return y = {}, Promise.resolve(void 0);
|
|
@@ -808,96 +815,96 @@ class he {
|
|
|
808
815
|
}
|
|
809
816
|
}
|
|
810
817
|
async flushCache() {
|
|
811
|
-
return await this.cacheProvider().flush(), this;
|
|
818
|
+
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
812
819
|
}
|
|
813
820
|
}
|
|
814
|
-
const
|
|
815
|
-
const { apiOptions:
|
|
816
|
-
if (!
|
|
821
|
+
const ut = (n = {}) => {
|
|
822
|
+
const { apiOptions: t } = n;
|
|
823
|
+
if (!t.accessToken) {
|
|
817
824
|
console.error(
|
|
818
825
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
819
826
|
);
|
|
820
827
|
return;
|
|
821
828
|
}
|
|
822
|
-
return { storyblokApi: new
|
|
823
|
-
},
|
|
824
|
-
if (typeof
|
|
829
|
+
return { storyblokApi: new ct(t) };
|
|
830
|
+
}, pt = (n) => {
|
|
831
|
+
if (typeof n != "object" || typeof n._editable > "u")
|
|
825
832
|
return {};
|
|
826
833
|
try {
|
|
827
|
-
const
|
|
828
|
-
|
|
834
|
+
const t = JSON.parse(
|
|
835
|
+
n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
829
836
|
);
|
|
830
|
-
return
|
|
831
|
-
"data-blok-c": JSON.stringify(
|
|
832
|
-
"data-blok-uid":
|
|
837
|
+
return t ? {
|
|
838
|
+
"data-blok-c": JSON.stringify(t),
|
|
839
|
+
"data-blok-uid": t.id + "-" + t.uid
|
|
833
840
|
} : {};
|
|
834
841
|
} catch {
|
|
835
842
|
return {};
|
|
836
843
|
}
|
|
837
844
|
};
|
|
838
845
|
let R, $ = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
839
|
-
const
|
|
846
|
+
const dt = (n, t, e = {}) => {
|
|
840
847
|
var c;
|
|
841
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
848
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((c = window.location) == null ? void 0 : c.href).searchParams.get(
|
|
842
849
|
"_storyblok"
|
|
843
|
-
) ===
|
|
844
|
-
if (!(!r || !
|
|
845
|
-
if (!
|
|
850
|
+
) === n;
|
|
851
|
+
if (!(!r || !o)) {
|
|
852
|
+
if (!n) {
|
|
846
853
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
847
854
|
return;
|
|
848
855
|
}
|
|
849
856
|
window.storyblokRegisterEvent(() => {
|
|
850
|
-
new window.StoryblokBridge(
|
|
851
|
-
l.action === "input" && l.story.id ===
|
|
857
|
+
new window.StoryblokBridge(e).on(["input", "published", "change"], (l) => {
|
|
858
|
+
l.action === "input" && l.story.id === n ? t(l.story) : (l.action === "change" || l.action === "published") && l.storyId === n && window.location.reload();
|
|
852
859
|
});
|
|
853
860
|
});
|
|
854
861
|
}
|
|
855
|
-
},
|
|
862
|
+
}, gt = (n = {}) => {
|
|
856
863
|
var p, g;
|
|
857
864
|
const {
|
|
858
|
-
bridge:
|
|
859
|
-
accessToken:
|
|
865
|
+
bridge: t,
|
|
866
|
+
accessToken: e,
|
|
860
867
|
use: s = [],
|
|
861
868
|
apiOptions: r = {},
|
|
862
869
|
richText: i = {},
|
|
863
|
-
bridgeUrl:
|
|
864
|
-
} =
|
|
865
|
-
r.accessToken = r.accessToken ||
|
|
866
|
-
const c = { bridge:
|
|
870
|
+
bridgeUrl: o
|
|
871
|
+
} = n;
|
|
872
|
+
r.accessToken = r.accessToken || e;
|
|
873
|
+
const c = { bridge: t, apiOptions: r };
|
|
867
874
|
let a = {};
|
|
868
875
|
s.forEach((f) => {
|
|
869
876
|
a = { ...a, ...f(c) };
|
|
870
|
-
}),
|
|
877
|
+
}), o && ($ = o);
|
|
871
878
|
const u = !(typeof window > "u") && ((g = (p = window.location) == null ? void 0 : p.search) == null ? void 0 : g.includes("_storyblok_tk"));
|
|
872
|
-
return
|
|
873
|
-
}, E = (
|
|
874
|
-
|
|
879
|
+
return t !== !1 && u && O($), R = new v(i.schema), i.resolver && E(R, i.resolver), a;
|
|
880
|
+
}, E = (n, t) => {
|
|
881
|
+
n.addNode("blok", (e) => {
|
|
875
882
|
let s = "";
|
|
876
|
-
return
|
|
877
|
-
s +=
|
|
883
|
+
return e.attrs.body.forEach((r) => {
|
|
884
|
+
s += t(r.component, r);
|
|
878
885
|
}), {
|
|
879
886
|
html: s
|
|
880
887
|
};
|
|
881
888
|
});
|
|
882
|
-
},
|
|
883
|
-
let s =
|
|
889
|
+
}, ht = (n) => !n || !(n != null && n.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ft = (n, t, e) => {
|
|
890
|
+
let s = e || R;
|
|
884
891
|
if (!s) {
|
|
885
892
|
console.error(
|
|
886
893
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
887
894
|
);
|
|
888
895
|
return;
|
|
889
896
|
}
|
|
890
|
-
return
|
|
891
|
-
},
|
|
897
|
+
return ht(n) ? "" : (t && (s = new v(t.schema), t.resolver && E(s, t.resolver)), s.render(n));
|
|
898
|
+
}, mt = () => O($);
|
|
892
899
|
export {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
900
|
+
v as RichTextResolver,
|
|
901
|
+
ot as RichTextSchema,
|
|
902
|
+
ut as apiPlugin,
|
|
903
|
+
ht as isRichTextEmpty,
|
|
904
|
+
mt as loadStoryblokBridge,
|
|
905
|
+
dt as registerStoryblokBridge,
|
|
906
|
+
ft as renderRichText,
|
|
907
|
+
pt as storyblokEditable,
|
|
908
|
+
gt as storyblokInit,
|
|
909
|
+
dt as useStoryblokBridge
|
|
903
910
|
};
|