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