@storyblok/js 3.0.8 → 3.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -23
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +354 -348
- package/package.json +16 -8
package/dist/storyblok-js.mjs
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
let _ = !1;
|
2
|
-
const S = [], O = (n) => new Promise((
|
2
|
+
const S = [], O = (n) => new Promise((e, t) => {
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
4
4
|
if (window.location === window.parent.location) {
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
6
6
|
return;
|
7
7
|
}
|
8
8
|
_ ? r() : S.push(r);
|
9
|
-
}, document.getElementById("storyblok-javascript-bridge")))
|
10
|
-
return;
|
9
|
+
}, document.getElementById("storyblok-javascript-bridge"))) return;
|
11
10
|
const s = document.createElement("script");
|
12
|
-
s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) =>
|
13
|
-
S.forEach((i) => i()), _ = !0,
|
11
|
+
s.async = !0, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
12
|
+
S.forEach((i) => i()), _ = !0, e(r);
|
14
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
15
14
|
});
|
16
|
-
var I = Object.defineProperty, P = (n,
|
15
|
+
var I = Object.defineProperty, P = (n, e, t) => e in n ? I(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, h = (n, e, t) => (P(n, typeof e != "symbol" ? e + "" : e, t), t);
|
17
16
|
function j(n) {
|
18
17
|
return !(n !== n || n === 1 / 0 || n === -1 / 0);
|
19
18
|
}
|
20
|
-
function C(n,
|
21
|
-
if (!j(t))
|
22
|
-
throw new TypeError("Expected `limit` to be a finite number");
|
19
|
+
function C(n, e, t) {
|
23
20
|
if (!j(e))
|
21
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
22
|
+
if (!j(t))
|
24
23
|
throw new TypeError("Expected `interval` to be a finite number");
|
25
24
|
const s = [];
|
26
25
|
let r = [], i = 0;
|
@@ -30,47 +29,47 @@ function C(n, t, e) {
|
|
30
29
|
i--, 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
|
-
const
|
36
|
-
|
37
|
-
},
|
38
|
-
const
|
39
|
-
return new Promise(function(u,
|
34
|
+
const c = s.shift();
|
35
|
+
c.resolve(n.apply(c.self, c.args));
|
36
|
+
}, l = function(...a) {
|
37
|
+
const c = this;
|
38
|
+
return new Promise(function(u, d) {
|
40
39
|
s.push({
|
41
40
|
resolve: u,
|
42
|
-
reject:
|
41
|
+
reject: d,
|
43
42
|
args: a,
|
44
|
-
self:
|
45
|
-
}), i <
|
43
|
+
self: c
|
44
|
+
}), i < e && o();
|
46
45
|
});
|
47
46
|
};
|
48
|
-
return
|
47
|
+
return l.abort = function() {
|
49
48
|
r.forEach(clearTimeout), r = [], s.forEach(function(a) {
|
50
49
|
a.reject(function() {
|
51
50
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
52
51
|
});
|
53
52
|
}), s.length = 0;
|
54
|
-
},
|
53
|
+
}, l;
|
55
54
|
}
|
56
55
|
class b {
|
57
56
|
constructor() {
|
58
|
-
h(this, "isCDNUrl", (
|
59
|
-
...
|
60
|
-
per_page:
|
57
|
+
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
58
|
+
...e,
|
59
|
+
per_page: t,
|
61
60
|
page: s
|
62
|
-
})), h(this, "delay", (
|
63
|
-
const s = Math.abs(
|
64
|
-
return this.arrayFrom(s, (i, o) => o * r +
|
65
|
-
}), h(this, "asyncMap", async (
|
66
|
-
const
|
61
|
+
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
62
|
+
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
63
|
+
return this.arrayFrom(s, (i, o) => o * r + e);
|
64
|
+
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), h(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, (i) => t[i]) : 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 i in
|
86
|
-
if (!Object.prototype.hasOwnProperty.call(
|
84
|
+
for (const i in e) {
|
85
|
+
if (!Object.prototype.hasOwnProperty.call(e, i))
|
87
86
|
continue;
|
88
|
-
const o =
|
87
|
+
const o = e[i], l = s ? "" : encodeURIComponent(i);
|
89
88
|
let a;
|
90
89
|
typeof o == "object" ? a = this.stringify(
|
91
90
|
o,
|
92
|
-
|
91
|
+
t ? t + encodeURIComponent("[" + l + "]") : l,
|
93
92
|
Array.isArray(o)
|
94
|
-
) : a = (
|
93
|
+
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(o), r.push(a);
|
95
94
|
}
|
96
95
|
return r.join("&");
|
97
96
|
}
|
@@ -100,9 +99,9 @@ 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", i = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
|
104
|
+
switch (e) {
|
106
105
|
case "us":
|
107
106
|
return s;
|
108
107
|
case "cn":
|
@@ -112,17 +111,17 @@ class b {
|
|
112
111
|
case "ca":
|
113
112
|
return o;
|
114
113
|
default:
|
115
|
-
return
|
114
|
+
return t;
|
116
115
|
}
|
117
116
|
}
|
118
117
|
}
|
119
|
-
const A = function(n,
|
120
|
-
const
|
118
|
+
const A = function(n, e) {
|
119
|
+
const t = {};
|
121
120
|
for (const s in n) {
|
122
121
|
const r = n[s];
|
123
|
-
|
122
|
+
e.indexOf(s) > -1 && r !== null && (t[s] = r);
|
124
123
|
}
|
125
|
-
return
|
124
|
+
return t;
|
126
125
|
}, N = (n) => n === "email", L = () => ({
|
127
126
|
singleTag: "hr"
|
128
127
|
}), M = () => ({
|
@@ -148,13 +147,13 @@ const A = function(n, t) {
|
|
148
147
|
attrs: A(n.attrs, ["src", "alt", "title"])
|
149
148
|
}
|
150
149
|
]
|
151
|
-
}), F = () => ({
|
152
|
-
tag: "li"
|
153
150
|
}), V = () => ({
|
151
|
+
tag: "li"
|
152
|
+
}), D = () => ({
|
154
153
|
tag: "ol"
|
155
154
|
}), J = () => ({
|
156
155
|
tag: "p"
|
157
|
-
}),
|
156
|
+
}), F = (n) => ({
|
158
157
|
tag: [
|
159
158
|
{
|
160
159
|
tag: "span",
|
@@ -182,41 +181,41 @@ const A = function(n, t) {
|
|
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 b().escapeHTML, t = { ...n.attrs }, { linktype: s = "url" } = n.attrs;
|
185
|
+
if (delete t.linktype, t.href && (t.href = e(n.attrs.href || "")), N(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
|
+
}, ee = (n) => ({
|
200
199
|
tag: [
|
201
200
|
{
|
202
201
|
tag: "span",
|
203
202
|
attrs: n.attrs
|
204
203
|
}
|
205
204
|
]
|
206
|
-
}),
|
205
|
+
}), te = () => ({
|
207
206
|
tag: "sub"
|
208
|
-
}),
|
207
|
+
}), se = () => ({
|
209
208
|
tag: "sup"
|
210
|
-
}),
|
209
|
+
}), re = (n) => ({
|
211
210
|
tag: [
|
212
211
|
{
|
213
212
|
tag: "span",
|
214
213
|
attrs: n.attrs
|
215
214
|
}
|
216
215
|
]
|
217
|
-
}),
|
218
|
-
var
|
219
|
-
return (
|
216
|
+
}), ie = (n) => {
|
217
|
+
var e;
|
218
|
+
return (e = n.attrs) != null && e.color ? {
|
220
219
|
tag: [
|
221
220
|
{
|
222
221
|
tag: "span",
|
@@ -228,9 +227,9 @@ const A = function(n, t) {
|
|
228
227
|
} : {
|
229
228
|
tag: ""
|
230
229
|
};
|
231
|
-
},
|
232
|
-
var
|
233
|
-
return (
|
230
|
+
}, ne = (n) => {
|
231
|
+
var e;
|
232
|
+
return (e = n.attrs) != null && e.color ? {
|
234
233
|
tag: [
|
235
234
|
{
|
236
235
|
tag: "span",
|
@@ -242,7 +241,7 @@ const A = function(n, t) {
|
|
242
241
|
} : {
|
243
242
|
tag: ""
|
244
243
|
};
|
245
|
-
},
|
244
|
+
}, oe = {
|
246
245
|
nodes: {
|
247
246
|
horizontal_rule: L,
|
248
247
|
blockquote: M,
|
@@ -251,10 +250,10 @@ const A = function(n, t) {
|
|
251
250
|
hard_break: H,
|
252
251
|
heading: q,
|
253
252
|
image: B,
|
254
|
-
list_item:
|
255
|
-
ordered_list:
|
253
|
+
list_item: V,
|
254
|
+
ordered_list: D,
|
256
255
|
paragraph: J,
|
257
|
-
emoji:
|
256
|
+
emoji: F
|
258
257
|
},
|
259
258
|
marks: {
|
260
259
|
bold: Y,
|
@@ -264,39 +263,39 @@ const A = function(n, t) {
|
|
264
263
|
code: Q,
|
265
264
|
italic: X,
|
266
265
|
link: Z,
|
267
|
-
styled:
|
268
|
-
subscript:
|
269
|
-
superscript:
|
270
|
-
anchor:
|
271
|
-
highlight:
|
272
|
-
textStyle:
|
273
|
-
}
|
274
|
-
},
|
275
|
-
const
|
266
|
+
styled: ee,
|
267
|
+
subscript: te,
|
268
|
+
superscript: se,
|
269
|
+
anchor: re,
|
270
|
+
highlight: ie,
|
271
|
+
textStyle: ne
|
272
|
+
}
|
273
|
+
}, ae = function(n) {
|
274
|
+
const e = {
|
276
275
|
"&": "&",
|
277
276
|
"<": "<",
|
278
277
|
">": ">",
|
279
278
|
'"': """,
|
280
279
|
"'": "'"
|
281
|
-
},
|
282
|
-
return n && s.test(n) ? n.replace(
|
280
|
+
}, t = /[&<>"']/g, s = RegExp(t.source);
|
281
|
+
return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
|
283
282
|
};
|
284
283
|
class v {
|
285
|
-
constructor(
|
286
|
-
h(this, "marks"), h(this, "nodes"),
|
284
|
+
constructor(e) {
|
285
|
+
h(this, "marks"), h(this, "nodes"), e || (e = oe), 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 (e && e.content && Array.isArray(e.content)) {
|
296
295
|
let s = "";
|
297
|
-
return
|
296
|
+
return e.content.forEach((r) => {
|
298
297
|
s += this.renderNode(r);
|
299
|
-
}),
|
298
|
+
}), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
|
300
299
|
}
|
301
300
|
return console.warn(
|
302
301
|
`The render method must receive an Object with a "content" field.
|
@@ -325,101 +324,103 @@ class v {
|
|
325
324
|
}`
|
326
325
|
), "";
|
327
326
|
}
|
328
|
-
optimizeImages(
|
327
|
+
optimizeImages(e, t) {
|
329
328
|
let s = 0, r = 0, i = "", o = "";
|
330
|
-
typeof
|
331
|
-
const
|
332
|
-
return
|
329
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `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))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
|
330
|
+
const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
331
|
+
return e = e.replace(
|
333
332
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
334
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
335
|
-
), typeof
|
336
|
-
var
|
337
|
-
const
|
333
|
+
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
334
|
+
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
335
|
+
var c, u;
|
336
|
+
const d = a.match(
|
338
337
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
339
338
|
);
|
340
|
-
if (
|
341
|
-
const
|
342
|
-
srcset: (
|
343
|
-
if (typeof
|
344
|
-
return `//${
|
345
|
-
if (typeof
|
339
|
+
if (d && d.length > 0) {
|
340
|
+
const p = {
|
341
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((g) => {
|
342
|
+
if (typeof g == "number")
|
343
|
+
return `//${d}/m/${g}x0${o} ${g}w`;
|
344
|
+
if (typeof g == "object" && g.length === 2) {
|
346
345
|
let k = 0, T = 0;
|
347
|
-
return typeof
|
346
|
+
return typeof g[0] == "number" && (k = g[0]), typeof g[1] == "number" && (T = g[1]), `//${d}/m/${k}x${T}${o} ${k}w`;
|
348
347
|
}
|
349
348
|
}).join(", "),
|
350
|
-
sizes: (u =
|
349
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((g) => g).join(", ")
|
351
350
|
};
|
352
351
|
let f = "";
|
353
|
-
return
|
352
|
+
return p.srcset && (f += `srcset="${p.srcset}" `), p.sizes && (f += `sizes="${p.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
354
353
|
}
|
355
354
|
return a;
|
356
|
-
})),
|
355
|
+
})), e;
|
357
356
|
}
|
358
|
-
renderNode(
|
359
|
-
const
|
360
|
-
|
357
|
+
renderNode(e) {
|
358
|
+
const t = [];
|
359
|
+
e.marks && e.marks.forEach((r) => {
|
361
360
|
const i = this.getMatchingMark(r);
|
362
|
-
i && i.tag !== "" &&
|
361
|
+
i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
|
363
362
|
});
|
364
|
-
const s = this.getMatchingNode(
|
365
|
-
return s && s.tag &&
|
366
|
-
|
367
|
-
}) :
|
363
|
+
const s = this.getMatchingNode(e);
|
364
|
+
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
365
|
+
t.push(this.renderNode(r));
|
366
|
+
}) : e.text ? t.push(ae(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) => {
|
368
367
|
const i = this.getMatchingMark(r);
|
369
|
-
i && i.tag !== "" &&
|
370
|
-
}),
|
368
|
+
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
369
|
+
}), t.join("");
|
371
370
|
}
|
372
|
-
renderTag(
|
373
|
-
return
|
371
|
+
renderTag(e, t) {
|
372
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
|
374
373
|
if (s.constructor === String)
|
375
|
-
return `<${s}${
|
374
|
+
return `<${s}${t}>`;
|
376
375
|
{
|
377
376
|
let r = `<${s.tag}`;
|
378
|
-
if (s.attrs)
|
379
|
-
for (const i in s.attrs)
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
377
|
+
if (s.attrs) {
|
378
|
+
for (const i in s.attrs)
|
379
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, i)) {
|
380
|
+
const o = s.attrs[i];
|
381
|
+
o !== null && (r += ` ${i}="${o}"`);
|
382
|
+
}
|
383
|
+
}
|
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
|
-
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 =
|
421
|
+
class le {
|
422
|
+
constructor(e) {
|
423
|
+
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 = 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,78 +428,78 @@ 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 = { ...
|
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;
|
455
456
|
}
|
456
|
-
async _methodHandler(
|
457
|
-
let
|
458
|
-
if (
|
457
|
+
async _methodHandler(e) {
|
458
|
+
let t = `${this.baseURL}${this.url}`, s = null;
|
459
|
+
if (e === "get") {
|
459
460
|
const a = new b();
|
460
|
-
|
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
|
-
let
|
467
|
-
this.timeout && (
|
466
|
+
const r = new URL(t), i = new AbortController(), { signal: o } = i;
|
467
|
+
let l;
|
468
|
+
this.timeout && (l = setTimeout(() => i.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,
|
474
475
|
...this.fetchOptions
|
475
476
|
});
|
476
|
-
this.timeout && clearTimeout(
|
477
|
-
const
|
477
|
+
this.timeout && clearTimeout(l);
|
478
|
+
const c = await this._responseHandler(
|
478
479
|
a
|
479
480
|
);
|
480
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
481
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
|
481
482
|
} catch (a) {
|
482
483
|
return {
|
483
484
|
message: a
|
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(
|
497
|
+
if (t.test(`${e.status}`))
|
498
|
+
return s(e);
|
498
499
|
const i = {
|
499
|
-
message:
|
500
|
-
status:
|
501
|
-
response: Array.isArray(
|
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
504
|
r(i);
|
504
505
|
});
|
@@ -511,93 +512,97 @@ const x = "SB-Agent", w = {
|
|
511
512
|
};
|
512
513
|
let y = {};
|
513
514
|
const m = {};
|
514
|
-
class
|
515
|
+
class ce {
|
515
516
|
/**
|
516
517
|
*
|
517
518
|
* @param config ISbConfig interface
|
518
519
|
* @param endpoint string, optional
|
519
520
|
*/
|
520
|
-
constructor(
|
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");
|
522
|
-
let s =
|
521
|
+
constructor(e, t) {
|
522
|
+
h(this, "client"), h(this, "maxRetries"), h(this, "retriesDelay"), 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 = e.endpoint || t;
|
523
524
|
if (!s) {
|
524
|
-
const o = new b().getRegionURL,
|
525
|
-
|
525
|
+
const o = new b().getRegionURL, l = e.https === !1 ? "http" : "https";
|
526
|
+
e.oauthToken ? s = `${l}://${o(e.region)}/v1` : s = `${l}://${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,
|
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]);
|
531
532
|
r.has(x) || (r.set(x, w.defaultAgentName), r.set(
|
532
533
|
w.defaultAgentVersion,
|
533
534
|
w.packageVersion
|
534
535
|
));
|
535
536
|
let i = 5;
|
536
|
-
|
537
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new v(e.richTextSchema) : this.richTextResolver = new v(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = C(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new le({
|
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 = m[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, i) {
|
562
|
+
const o = this.factoryParamOptions(
|
563
|
+
e,
|
564
|
+
this.helpers.getOptionsPage(t, s, r)
|
564
565
|
);
|
565
|
-
return this.cacheResponse(
|
566
|
-
}
|
567
|
-
get(
|
568
|
-
|
569
|
-
const r = `/${
|
570
|
-
return this.
|
571
|
-
}
|
572
|
-
async getAll(
|
573
|
-
const i = (
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
566
|
+
return this.cacheResponse(e, o, void 0, i);
|
567
|
+
}
|
568
|
+
get(e, t, s) {
|
569
|
+
t || (t = {});
|
570
|
+
const r = `/${e}`, i = this.factoryParamOptions(r, t);
|
571
|
+
return this.cacheResponse(r, i, void 0, s);
|
572
|
+
}
|
573
|
+
async getAll(e, t, s, r) {
|
574
|
+
const i = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, l = o.split("/"), a = s || l[l.length - 1], c = 1, u = await this.makeRequest(
|
575
|
+
o,
|
576
|
+
t,
|
577
|
+
i,
|
578
|
+
c,
|
579
|
+
r
|
580
|
+
), d = u.total ? Math.ceil(u.total / i) : 1, p = await this.helpers.asyncMap(
|
581
|
+
this.helpers.range(c, d),
|
582
|
+
(f) => this.makeRequest(o, t, i, f + 1, r)
|
578
583
|
);
|
579
584
|
return this.helpers.flatMap(
|
580
|
-
[u, ...
|
585
|
+
[u, ...p],
|
581
586
|
(f) => Object.values(f.data[a])
|
582
587
|
);
|
583
588
|
}
|
584
|
-
post(
|
585
|
-
const r = `/${
|
586
|
-
return
|
589
|
+
post(e, t, s) {
|
590
|
+
const r = `/${e}`;
|
591
|
+
return Promise.resolve(this.throttle("post", r, t, s));
|
587
592
|
}
|
588
|
-
put(
|
589
|
-
const r = `/${
|
590
|
-
return
|
593
|
+
put(e, t, s) {
|
594
|
+
const r = `/${e}`;
|
595
|
+
return Promise.resolve(this.throttle("put", r, t, s));
|
591
596
|
}
|
592
|
-
delete(
|
593
|
-
const r = `/${
|
594
|
-
return
|
597
|
+
delete(e, t, s) {
|
598
|
+
const r = `/${e}`;
|
599
|
+
return Promise.resolve(this.throttle("delete", r, t, s));
|
595
600
|
}
|
596
|
-
getStories(
|
597
|
-
return this.
|
601
|
+
getStories(e, t) {
|
602
|
+
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
598
603
|
}
|
599
|
-
getStory(
|
600
|
-
return this.
|
604
|
+
getStory(e, t, s) {
|
605
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
|
601
606
|
}
|
602
607
|
getToken() {
|
603
608
|
return this.accessToken;
|
@@ -605,14 +610,14 @@ class ct {
|
|
605
610
|
ejectInterceptor() {
|
606
611
|
this.client.eject();
|
607
612
|
}
|
608
|
-
_addResolveLevel(
|
609
|
-
typeof
|
613
|
+
_addResolveLevel(e) {
|
614
|
+
typeof e.resolve_relations < "u" && (e.resolve_level = 2);
|
610
615
|
}
|
611
|
-
_cleanCopy(
|
612
|
-
return JSON.parse(JSON.stringify(
|
616
|
+
_cleanCopy(e) {
|
617
|
+
return JSON.parse(JSON.stringify(e));
|
613
618
|
}
|
614
|
-
_insertLinks(
|
615
|
-
const r = t
|
619
|
+
_insertLinks(e, t, s) {
|
620
|
+
const r = e[t];
|
616
621
|
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
622
|
}
|
618
623
|
/**
|
@@ -621,15 +626,15 @@ class ct {
|
|
621
626
|
* @param uuid The uuid of the story
|
622
627
|
* @returns string | object
|
623
628
|
*/
|
624
|
-
getStoryReference(
|
625
|
-
return this.relations[
|
626
|
-
this.relations[
|
627
|
-
)), JSON.parse(this.stringifiedStoriesCache[
|
629
|
+
getStoryReference(e, t) {
|
630
|
+
return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
|
631
|
+
this.relations[e][t]
|
632
|
+
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
628
633
|
}
|
629
|
-
_insertRelations(
|
630
|
-
s.indexOf(`${
|
634
|
+
_insertRelations(e, t, s, r) {
|
635
|
+
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((i) => this.getStoryReference(r, i)).filter(Boolean)));
|
631
636
|
}
|
632
|
-
iterateTree(
|
637
|
+
iterateTree(e, t, s) {
|
633
638
|
const r = (i) => {
|
634
639
|
if (i != null) {
|
635
640
|
if (i.constructor === Array)
|
@@ -642,7 +647,7 @@ class ct {
|
|
642
647
|
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
643
648
|
i,
|
644
649
|
o,
|
645
|
-
|
650
|
+
t,
|
646
651
|
s
|
647
652
|
), this._insertLinks(
|
648
653
|
i,
|
@@ -652,29 +657,29 @@ class ct {
|
|
652
657
|
}
|
653
658
|
}
|
654
659
|
};
|
655
|
-
r(
|
660
|
+
r(e.content);
|
656
661
|
}
|
657
|
-
async resolveLinks(
|
662
|
+
async resolveLinks(e, t, s) {
|
658
663
|
let r = [];
|
659
|
-
if (
|
660
|
-
const i =
|
661
|
-
for (let a = 0; a < i; a +=
|
662
|
-
const
|
663
|
-
o.push(
|
664
|
+
if (e.link_uuids) {
|
665
|
+
const i = e.link_uuids.length, o = [], l = 50;
|
666
|
+
for (let a = 0; a < i; a += l) {
|
667
|
+
const c = Math.min(i, a + l);
|
668
|
+
o.push(e.link_uuids.slice(a, c));
|
664
669
|
}
|
665
670
|
for (let a = 0; a < o.length; a++)
|
666
671
|
(await this.getStories({
|
667
|
-
per_page:
|
668
|
-
language:
|
669
|
-
version:
|
672
|
+
per_page: l,
|
673
|
+
language: t.language,
|
674
|
+
version: t.version,
|
670
675
|
by_uuids: o[a].join(",")
|
671
676
|
})).data.stories.forEach(
|
672
|
-
(
|
673
|
-
r.push(
|
677
|
+
(c) => {
|
678
|
+
r.push(c);
|
674
679
|
}
|
675
680
|
);
|
676
681
|
} else
|
677
|
-
r =
|
682
|
+
r = e.links;
|
678
683
|
r.forEach((i) => {
|
679
684
|
this.links[s][i.uuid] = {
|
680
685
|
...i,
|
@@ -682,26 +687,26 @@ class ct {
|
|
682
687
|
};
|
683
688
|
});
|
684
689
|
}
|
685
|
-
async resolveRelations(
|
690
|
+
async resolveRelations(e, t, s) {
|
686
691
|
let r = [];
|
687
|
-
if (
|
688
|
-
const i =
|
689
|
-
for (let a = 0; a < i; a +=
|
690
|
-
const
|
691
|
-
o.push(
|
692
|
+
if (e.rel_uuids) {
|
693
|
+
const i = e.rel_uuids.length, o = [], l = 50;
|
694
|
+
for (let a = 0; a < i; a += l) {
|
695
|
+
const c = Math.min(i, a + l);
|
696
|
+
o.push(e.rel_uuids.slice(a, c));
|
692
697
|
}
|
693
698
|
for (let a = 0; a < o.length; a++)
|
694
699
|
(await this.getStories({
|
695
|
-
per_page:
|
696
|
-
language:
|
697
|
-
version:
|
700
|
+
per_page: l,
|
701
|
+
language: t.language,
|
702
|
+
version: t.version,
|
698
703
|
by_uuids: o[a].join(","),
|
699
|
-
excluding_fields:
|
700
|
-
})).data.stories.forEach((
|
701
|
-
r.push(
|
704
|
+
excluding_fields: t.excluding_fields
|
705
|
+
})).data.stories.forEach((c) => {
|
706
|
+
r.push(c);
|
702
707
|
});
|
703
708
|
} else
|
704
|
-
r =
|
709
|
+
r = e.rels;
|
705
710
|
r && r.length > 0 && r.forEach((i) => {
|
706
711
|
this.relations[s][i.uuid] = {
|
707
712
|
...i,
|
@@ -718,52 +723,53 @@ class ct {
|
|
718
723
|
* @returns Promise<void>
|
719
724
|
*
|
720
725
|
*/
|
721
|
-
async resolveStories(
|
726
|
+
async resolveStories(e, t, s) {
|
722
727
|
var r, i;
|
723
728
|
let o = [];
|
724
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof
|
725
|
-
for (const
|
729
|
+
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 || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
730
|
+
for (const l in this.relations[s])
|
726
731
|
this.iterateTree(
|
727
|
-
this.relations[s][
|
732
|
+
this.relations[s][l],
|
728
733
|
o,
|
729
734
|
s
|
730
735
|
);
|
731
|
-
|
732
|
-
this.iterateTree(
|
736
|
+
e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((l) => {
|
737
|
+
this.iterateTree(l, o, s);
|
733
738
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
734
739
|
}
|
735
|
-
async cacheResponse(t,
|
736
|
-
(
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
return Promise.resolve(o);
|
740
|
+
async cacheResponse(e, t, s, r) {
|
741
|
+
const i = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
742
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
743
|
+
const l = await o.get(i);
|
744
|
+
if (l)
|
745
|
+
return Promise.resolve(l);
|
742
746
|
}
|
743
|
-
return new Promise(async (
|
744
|
-
var
|
747
|
+
return new Promise(async (l, a) => {
|
748
|
+
var c;
|
745
749
|
try {
|
746
|
-
const
|
747
|
-
if (
|
748
|
-
return
|
749
|
-
let
|
750
|
-
if ((
|
751
|
-
perPage:
|
752
|
-
total:
|
753
|
-
})),
|
750
|
+
const u = await this.throttle("get", e, t, r);
|
751
|
+
if (u.status !== 200)
|
752
|
+
return a(u);
|
753
|
+
let d = { data: u.data, headers: u.headers };
|
754
|
+
if ((c = u.headers) != null && c["per-page"] && (d = Object.assign({}, d, {
|
755
|
+
perPage: u.headers["per-page"] ? parseInt(u.headers["per-page"]) : 0,
|
756
|
+
total: u.headers["per-page"] ? parseInt(u.headers.total) : 0
|
757
|
+
})), d.data.story || d.data.stories) {
|
754
758
|
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
755
|
-
await this.resolveStories(
|
759
|
+
await this.resolveStories(d.data, t, `${p}`);
|
756
760
|
}
|
757
|
-
return
|
758
|
-
} catch (
|
759
|
-
if (
|
760
|
-
return console.log(
|
761
|
-
|
761
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await o.set(i, d), d.data.cv && t.token && (t.version === "draft" && m[t.token] != d.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : d.data.cv), l(d);
|
762
|
+
} catch (u) {
|
763
|
+
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
764
|
+
return console.log(
|
765
|
+
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
766
|
+
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
|
767
|
+
a(u);
|
762
768
|
}
|
763
769
|
});
|
764
770
|
}
|
765
|
-
throttledRequest(t,
|
766
|
-
return this.client[
|
771
|
+
throttledRequest(e, t, s, r) {
|
772
|
+
return this.client.setFetchOptions(r), this.client[e](t, s);
|
767
773
|
}
|
768
774
|
cacheVersions() {
|
769
775
|
return m;
|
@@ -771,8 +777,8 @@ class ct {
|
|
771
777
|
cacheVersion() {
|
772
778
|
return m[this.accessToken];
|
773
779
|
}
|
774
|
-
setCacheVersion(
|
775
|
-
this.accessToken && (m[this.accessToken] =
|
780
|
+
setCacheVersion(e) {
|
781
|
+
this.accessToken && (m[this.accessToken] = e);
|
776
782
|
}
|
777
783
|
clearCacheVersion() {
|
778
784
|
this.accessToken && (m[this.accessToken] = 0);
|
@@ -781,14 +787,14 @@ class ct {
|
|
781
787
|
switch (this.cache.type) {
|
782
788
|
case "memory":
|
783
789
|
return {
|
784
|
-
get(
|
785
|
-
return Promise.resolve(y[
|
790
|
+
get(e) {
|
791
|
+
return Promise.resolve(y[e]);
|
786
792
|
},
|
787
793
|
getAll() {
|
788
794
|
return Promise.resolve(y);
|
789
795
|
},
|
790
|
-
set(
|
791
|
-
return y[
|
796
|
+
set(e, t) {
|
797
|
+
return y[e] = t, Promise.resolve(void 0);
|
792
798
|
},
|
793
799
|
flush() {
|
794
800
|
return y = {}, Promise.resolve(void 0);
|
@@ -818,34 +824,34 @@ class ct {
|
|
818
824
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
819
825
|
}
|
820
826
|
}
|
821
|
-
const
|
822
|
-
const { apiOptions:
|
823
|
-
if (!
|
827
|
+
const ue = (n = {}) => {
|
828
|
+
const { apiOptions: e } = n;
|
829
|
+
if (!e.accessToken) {
|
824
830
|
console.error(
|
825
831
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
826
832
|
);
|
827
833
|
return;
|
828
834
|
}
|
829
|
-
return { storyblokApi: new
|
830
|
-
},
|
835
|
+
return { storyblokApi: new ce(e) };
|
836
|
+
}, de = (n) => {
|
831
837
|
if (typeof n != "object" || typeof n._editable > "u")
|
832
838
|
return {};
|
833
839
|
try {
|
834
|
-
const
|
840
|
+
const e = JSON.parse(
|
835
841
|
n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
836
842
|
);
|
837
|
-
return
|
838
|
-
"data-blok-c": JSON.stringify(
|
839
|
-
"data-blok-uid":
|
843
|
+
return e ? {
|
844
|
+
"data-blok-c": JSON.stringify(e),
|
845
|
+
"data-blok-uid": e.id + "-" + e.uid
|
840
846
|
} : {};
|
841
847
|
} catch {
|
842
848
|
return {};
|
843
849
|
}
|
844
850
|
};
|
845
851
|
let R, $ = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
846
|
-
const
|
847
|
-
var
|
848
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((
|
852
|
+
const pe = (n, e, t = {}) => {
|
853
|
+
var l;
|
854
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
|
849
855
|
"_storyblok"
|
850
856
|
) === n;
|
851
857
|
if (!(!r || !o)) {
|
@@ -854,57 +860,57 @@ const dt = (n, t, e = {}) => {
|
|
854
860
|
return;
|
855
861
|
}
|
856
862
|
window.storyblokRegisterEvent(() => {
|
857
|
-
new window.StoryblokBridge(
|
858
|
-
|
863
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (c) => {
|
864
|
+
c.action === "input" && c.story.id === n ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === n && window.location.reload();
|
859
865
|
});
|
860
866
|
});
|
861
867
|
}
|
862
|
-
},
|
863
|
-
var
|
868
|
+
}, ge = (n = {}) => {
|
869
|
+
var d, p;
|
864
870
|
const {
|
865
|
-
bridge:
|
866
|
-
accessToken:
|
871
|
+
bridge: e,
|
872
|
+
accessToken: t,
|
867
873
|
use: s = [],
|
868
874
|
apiOptions: r = {},
|
869
875
|
richText: i = {},
|
870
876
|
bridgeUrl: o
|
871
877
|
} = n;
|
872
|
-
r.accessToken = r.accessToken ||
|
873
|
-
const
|
878
|
+
r.accessToken = r.accessToken || t;
|
879
|
+
const l = { bridge: e, apiOptions: r };
|
874
880
|
let a = {};
|
875
881
|
s.forEach((f) => {
|
876
|
-
a = { ...a, ...f(
|
882
|
+
a = { ...a, ...f(l) };
|
877
883
|
}), o && ($ = o);
|
878
|
-
const u = !(typeof window > "u") && ((
|
879
|
-
return
|
880
|
-
}, E = (n,
|
881
|
-
n.addNode("blok", (
|
884
|
+
const u = !(typeof window > "u") && ((p = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : p.includes("_storyblok_tk"));
|
885
|
+
return e !== !1 && u && O($), R = new v(i.schema), i.resolver && E(R, i.resolver), a;
|
886
|
+
}, E = (n, e) => {
|
887
|
+
n.addNode("blok", (t) => {
|
882
888
|
let s = "";
|
883
|
-
return
|
884
|
-
s +=
|
889
|
+
return t.attrs.body.forEach((r) => {
|
890
|
+
s += e(r.component, r);
|
885
891
|
}), {
|
886
892
|
html: s
|
887
893
|
};
|
888
894
|
});
|
889
|
-
},
|
890
|
-
let s =
|
895
|
+
}, he = (n) => !n || !(n != null && n.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), fe = (n, e, t) => {
|
896
|
+
let s = t || R;
|
891
897
|
if (!s) {
|
892
898
|
console.error(
|
893
899
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
894
900
|
);
|
895
901
|
return;
|
896
902
|
}
|
897
|
-
return
|
898
|
-
},
|
903
|
+
return he(n) ? "" : (e && (s = new v(e.schema), e.resolver && E(s, e.resolver)), s.render(n));
|
904
|
+
}, me = () => O($);
|
899
905
|
export {
|
900
906
|
v as RichTextResolver,
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
907
|
+
oe as RichTextSchema,
|
908
|
+
ue as apiPlugin,
|
909
|
+
he as isRichTextEmpty,
|
910
|
+
me as loadStoryblokBridge,
|
911
|
+
pe as registerStoryblokBridge,
|
912
|
+
fe as renderRichText,
|
913
|
+
de as storyblokEditable,
|
914
|
+
ge as storyblokInit,
|
915
|
+
pe as useStoryblokBridge
|
910
916
|
};
|