@storyblok/react 3.0.5 → 3.0.6
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/client.mjs +2 -2
- package/dist/index.mjs +4 -4
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +401 -401
- package/package.json +2 -2
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
1
|
+
let _ = !1;
|
|
2
|
+
const j = [], O = (o) => 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
|
+
_ ? r() : j.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 = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
|
|
13
|
+
j.forEach((i) => i()), _ = !0, t(r);
|
|
14
14
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
15
15
|
});
|
|
16
|
-
var
|
|
17
|
-
function
|
|
18
|
-
return !(
|
|
16
|
+
var P = Object.defineProperty, I = (o, t, e) => t in o ? P(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, h = (o, t, e) => (I(o, typeof t != "symbol" ? t + "" : t, e), e);
|
|
17
|
+
function x(o) {
|
|
18
|
+
return !(o !== o || o === 1 / 0 || o === -1 / 0);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
if (!
|
|
20
|
+
function C(o, t, e) {
|
|
21
|
+
if (!x(t))
|
|
22
22
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
23
|
-
if (!
|
|
23
|
+
if (!x(e))
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const s = [];
|
|
26
|
-
let r = [],
|
|
26
|
+
let r = [], i = 0;
|
|
27
27
|
const n = function() {
|
|
28
|
-
|
|
28
|
+
i++;
|
|
29
29
|
const a = setTimeout(function() {
|
|
30
|
-
|
|
30
|
+
i--, 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 c = s.shift();
|
|
36
|
-
c.resolve(
|
|
36
|
+
c.resolve(o.apply(c.self, c.args));
|
|
37
37
|
}, l = function(...a) {
|
|
38
38
|
const c = 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: c
|
|
45
|
-
}),
|
|
45
|
+
}), i < t && n();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
return l.abort = function() {
|
|
@@ -55,22 +55,22 @@ function H(i, 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, (
|
|
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, 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
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
|
|
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 n =
|
|
88
|
+
const n = t[i], l = s ? "" : encodeURIComponent(i);
|
|
89
89
|
let a;
|
|
90
90
|
typeof n == "object" ? a = this.stringify(
|
|
91
91
|
n,
|
|
92
|
-
|
|
92
|
+
e ? e + encodeURIComponent("[" + l + "]") : l,
|
|
93
93
|
Array.isArray(n)
|
|
94
|
-
) : a = (
|
|
94
|
+
) : a = (e ? e + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(n), r.push(a);
|
|
95
95
|
}
|
|
96
96
|
return r.join("&");
|
|
97
97
|
}
|
|
@@ -100,203 +100,203 @@ 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", n = "api-ca.storyblok.com";
|
|
105
|
+
switch (t) {
|
|
106
106
|
case "us":
|
|
107
107
|
return s;
|
|
108
108
|
case "cn":
|
|
109
109
|
return r;
|
|
110
110
|
case "ap":
|
|
111
|
-
return
|
|
111
|
+
return i;
|
|
112
112
|
case "ca":
|
|
113
113
|
return n;
|
|
114
114
|
default:
|
|
115
|
-
return
|
|
115
|
+
return e;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
for (const s in
|
|
122
|
-
const r =
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return
|
|
126
|
-
},
|
|
119
|
+
const A = function(o, t) {
|
|
120
|
+
const e = {};
|
|
121
|
+
for (const s in o) {
|
|
122
|
+
const r = o[s];
|
|
123
|
+
t.indexOf(s) > -1 && r !== null && (e[s] = r);
|
|
124
|
+
}
|
|
125
|
+
return e;
|
|
126
|
+
}, N = (o) => o === "email", M = () => ({
|
|
127
127
|
singleTag: "hr"
|
|
128
|
-
}),
|
|
128
|
+
}), L = () => ({
|
|
129
129
|
tag: "blockquote"
|
|
130
|
-
}),
|
|
130
|
+
}), z = () => ({
|
|
131
131
|
tag: "ul"
|
|
132
|
-
}),
|
|
132
|
+
}), U = (o) => ({
|
|
133
133
|
tag: [
|
|
134
134
|
"pre",
|
|
135
135
|
{
|
|
136
136
|
tag: "code",
|
|
137
|
-
attrs:
|
|
137
|
+
attrs: o.attrs
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
|
-
}),
|
|
140
|
+
}), H = () => ({
|
|
141
141
|
singleTag: "br"
|
|
142
|
-
}),
|
|
143
|
-
tag: `h${
|
|
144
|
-
}),
|
|
142
|
+
}), q = (o) => ({
|
|
143
|
+
tag: `h${o.attrs.level}`
|
|
144
|
+
}), F = (o) => ({
|
|
145
145
|
singleTag: [
|
|
146
146
|
{
|
|
147
147
|
tag: "img",
|
|
148
|
-
attrs:
|
|
148
|
+
attrs: A(o.attrs, ["src", "alt", "title"])
|
|
149
149
|
}
|
|
150
150
|
]
|
|
151
|
-
}),
|
|
151
|
+
}), B = () => ({
|
|
152
152
|
tag: "li"
|
|
153
|
-
}),
|
|
153
|
+
}), V = () => ({
|
|
154
154
|
tag: "ol"
|
|
155
|
-
}),
|
|
155
|
+
}), J = () => ({
|
|
156
156
|
tag: "p"
|
|
157
|
-
}),
|
|
157
|
+
}), D = (o) => ({
|
|
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": o.attrs.name,
|
|
164
|
+
emoji: o.attrs.emoji
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
]
|
|
168
|
-
}),
|
|
168
|
+
}), Y = () => ({
|
|
169
169
|
tag: "b"
|
|
170
|
-
}),
|
|
170
|
+
}), K = () => ({
|
|
171
171
|
tag: "s"
|
|
172
|
-
}),
|
|
172
|
+
}), W = () => ({
|
|
173
173
|
tag: "u"
|
|
174
|
-
}),
|
|
174
|
+
}), G = () => ({
|
|
175
175
|
tag: "strong"
|
|
176
|
-
}), q = () => ({
|
|
177
|
-
tag: "code"
|
|
178
176
|
}), Q = () => ({
|
|
177
|
+
tag: "code"
|
|
178
|
+
}), X = () => ({
|
|
179
179
|
tag: "i"
|
|
180
|
-
}), Z = (
|
|
181
|
-
if (!
|
|
180
|
+
}), Z = (o) => {
|
|
181
|
+
if (!o.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 = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
|
|
186
|
+
if (delete e.linktype, e.href && (e.href = t(o.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 = (o) => ({
|
|
200
200
|
tag: [
|
|
201
201
|
{
|
|
202
202
|
tag: "span",
|
|
203
|
-
attrs:
|
|
203
|
+
attrs: o.attrs
|
|
204
204
|
}
|
|
205
205
|
]
|
|
206
|
-
}),
|
|
206
|
+
}), et = () => ({
|
|
207
207
|
tag: "sub"
|
|
208
|
-
}),
|
|
208
|
+
}), st = () => ({
|
|
209
209
|
tag: "sup"
|
|
210
|
-
}),
|
|
210
|
+
}), rt = (o) => ({
|
|
211
211
|
tag: [
|
|
212
212
|
{
|
|
213
213
|
tag: "span",
|
|
214
|
-
attrs:
|
|
214
|
+
attrs: o.attrs
|
|
215
215
|
}
|
|
216
216
|
]
|
|
217
|
-
}),
|
|
218
|
-
var
|
|
219
|
-
return (
|
|
217
|
+
}), it = (o) => {
|
|
218
|
+
var t;
|
|
219
|
+
return (t = o.attrs) != null && t.color ? {
|
|
220
220
|
tag: [
|
|
221
221
|
{
|
|
222
222
|
tag: "span",
|
|
223
223
|
attrs: {
|
|
224
|
-
style: `background-color:${
|
|
224
|
+
style: `background-color:${o.attrs.color};`
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
]
|
|
228
228
|
} : {
|
|
229
229
|
tag: ""
|
|
230
230
|
};
|
|
231
|
-
},
|
|
232
|
-
var
|
|
233
|
-
return (
|
|
231
|
+
}, nt = (o) => {
|
|
232
|
+
var t;
|
|
233
|
+
return (t = o.attrs) != null && t.color ? {
|
|
234
234
|
tag: [
|
|
235
235
|
{
|
|
236
236
|
tag: "span",
|
|
237
237
|
attrs: {
|
|
238
|
-
style: `color:${
|
|
238
|
+
style: `color:${o.attrs.color}`
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
]
|
|
242
242
|
} : {
|
|
243
243
|
tag: ""
|
|
244
244
|
};
|
|
245
|
-
},
|
|
245
|
+
}, ot = {
|
|
246
246
|
nodes: {
|
|
247
|
-
horizontal_rule:
|
|
248
|
-
blockquote:
|
|
249
|
-
bullet_list:
|
|
250
|
-
code_block:
|
|
251
|
-
hard_break:
|
|
252
|
-
heading:
|
|
253
|
-
image:
|
|
254
|
-
list_item:
|
|
255
|
-
ordered_list:
|
|
256
|
-
paragraph:
|
|
257
|
-
emoji:
|
|
247
|
+
horizontal_rule: M,
|
|
248
|
+
blockquote: L,
|
|
249
|
+
bullet_list: z,
|
|
250
|
+
code_block: U,
|
|
251
|
+
hard_break: H,
|
|
252
|
+
heading: q,
|
|
253
|
+
image: F,
|
|
254
|
+
list_item: B,
|
|
255
|
+
ordered_list: V,
|
|
256
|
+
paragraph: J,
|
|
257
|
+
emoji: D
|
|
258
258
|
},
|
|
259
259
|
marks: {
|
|
260
|
-
bold:
|
|
261
|
-
strike:
|
|
262
|
-
underline:
|
|
263
|
-
strong:
|
|
264
|
-
code:
|
|
265
|
-
italic:
|
|
260
|
+
bold: Y,
|
|
261
|
+
strike: K,
|
|
262
|
+
underline: W,
|
|
263
|
+
strong: G,
|
|
264
|
+
code: Q,
|
|
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(o) {
|
|
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 o && s.test(o) ? o.replace(e, (r) => t[r]) : o;
|
|
283
283
|
};
|
|
284
|
-
class
|
|
285
|
-
constructor(
|
|
286
|
-
h(this, "marks"), h(this, "nodes"),
|
|
284
|
+
class k {
|
|
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 T {
|
|
|
325
325
|
}`
|
|
326
326
|
), "";
|
|
327
327
|
}
|
|
328
|
-
optimizeImages(
|
|
329
|
-
let s = 0, r = 0,
|
|
330
|
-
typeof
|
|
328
|
+
optimizeImages(t, e) {
|
|
329
|
+
let s = 0, r = 0, i = "", n = "";
|
|
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 && (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))), i.length > 0 && (t = t.replace(/<img/g, `<img ${i.trim()}`));
|
|
331
331
|
const l = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
|
|
332
|
-
return
|
|
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/${l}`
|
|
335
|
-
), typeof
|
|
335
|
+
), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
336
336
|
var c, u;
|
|
337
|
-
const
|
|
337
|
+
const p = a.match(
|
|
338
338
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
339
339
|
);
|
|
340
|
-
if (
|
|
341
|
-
const
|
|
342
|
-
srcset: (c =
|
|
343
|
-
if (typeof
|
|
344
|
-
return `//${
|
|
345
|
-
if (typeof
|
|
346
|
-
let
|
|
347
|
-
return typeof
|
|
340
|
+
if (p && p.length > 0) {
|
|
341
|
+
const d = {
|
|
342
|
+
srcset: (c = e.srcset) == null ? void 0 : c.map((g) => {
|
|
343
|
+
if (typeof g == "number")
|
|
344
|
+
return `//${p}/m/${g}x0${n} ${g}w`;
|
|
345
|
+
if (typeof g == "object" && g.length === 2) {
|
|
346
|
+
let v = 0, T = 0;
|
|
347
|
+
return typeof g[0] == "number" && (v = g[0]), typeof g[1] == "number" && (T = g[1]), `//${p}/m/${v}x${T}${n} ${v}w`;
|
|
348
348
|
}
|
|
349
349
|
}).join(", "),
|
|
350
|
-
sizes: (u =
|
|
350
|
+
sizes: (u = e.sizes) == null ? void 0 : u.map((g) => g).join(", ")
|
|
351
351
|
};
|
|
352
|
-
let
|
|
353
|
-
return
|
|
352
|
+
let f = "";
|
|
353
|
+
return d.srcset && (f += `srcset="${d.srcset}" `), d.sizes && (f += `sizes="${d.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
|
354
354
|
}
|
|
355
355
|
return a;
|
|
356
|
-
})),
|
|
356
|
+
})), t;
|
|
357
357
|
}
|
|
358
|
-
renderNode(
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
358
|
+
renderNode(t) {
|
|
359
|
+
const e = [];
|
|
360
|
+
t.marks && t.marks.forEach((r) => {
|
|
361
|
+
const i = this.getMatchingMark(r);
|
|
362
|
+
i && i.tag !== "" && e.push(this.renderOpeningTag(i.tag));
|
|
363
363
|
});
|
|
364
|
-
const s = this.getMatchingNode(
|
|
365
|
-
return s && s.tag &&
|
|
366
|
-
|
|
367
|
-
}) :
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
}),
|
|
371
|
-
}
|
|
372
|
-
renderTag(
|
|
373
|
-
return
|
|
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
|
+
const i = this.getMatchingMark(r);
|
|
369
|
+
i && i.tag !== "" && e.push(this.renderClosingTag(i.tag));
|
|
370
|
+
}), e.join("");
|
|
371
|
+
}
|
|
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
|
-
for (const
|
|
380
|
-
const n = s.attrs[
|
|
381
|
-
n !== null && (r += ` ${
|
|
379
|
+
for (const i in s.attrs) {
|
|
380
|
+
const n = s.attrs[i];
|
|
381
|
+
n !== null && (r += ` ${i}="${n}"`);
|
|
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,47 +427,47 @@ 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: n } = i;
|
|
466
466
|
let l;
|
|
467
|
-
this.timeout && (l = setTimeout(() =>
|
|
467
|
+
this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
|
|
468
468
|
try {
|
|
469
469
|
const a = await fetch(`${r}`, {
|
|
470
|
-
method:
|
|
470
|
+
method: t,
|
|
471
471
|
headers: this.headers,
|
|
472
472
|
body: s,
|
|
473
473
|
signal: n,
|
|
@@ -484,119 +484,119 @@ 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(
|
|
498
|
-
const
|
|
499
|
-
message:
|
|
500
|
-
status:
|
|
501
|
-
response: Array.isArray(
|
|
496
|
+
if (e.test(`${t.status}`))
|
|
497
|
+
return s(t);
|
|
498
|
+
const i = {
|
|
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
|
-
r(
|
|
503
|
+
r(i);
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
var
|
|
508
|
-
const
|
|
507
|
+
var ct = { npm_package_version: "6.6.1" };
|
|
508
|
+
const S = "SB-Agent", w = {
|
|
509
509
|
defaultAgentName: "SB-JS-CLIENT",
|
|
510
510
|
defaultAgentVersion: "SB-Agent-Version",
|
|
511
|
-
packageVersion:
|
|
511
|
+
packageVersion: ct.npm_package_version
|
|
512
512
|
};
|
|
513
|
-
let
|
|
514
|
-
const
|
|
515
|
-
class
|
|
513
|
+
let y = {};
|
|
514
|
+
const m = {};
|
|
515
|
+
class ht {
|
|
516
516
|
/**
|
|
517
517
|
*
|
|
518
518
|
* @param config ISbConfig interface
|
|
519
519
|
* @param endpoint string, optional
|
|
520
520
|
*/
|
|
521
|
-
constructor(
|
|
521
|
+
constructor(t, e) {
|
|
522
522
|
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
|
-
const r = new b().getRegionURL,
|
|
525
|
-
|
|
523
|
+
let s = t.endpoint || e;
|
|
524
|
+
const r = new b().getRegionURL, i = t.https === !1 ? "http" : "https";
|
|
525
|
+
t.oauthToken ? s = `${i}://${r(t.region)}/v1` : s = `${i}://${r(t.region)}/v2`;
|
|
526
526
|
const n = new Headers();
|
|
527
|
-
if (n.set("Content-Type", "application/json"), n.set("Accept", "application/json"),
|
|
528
|
-
for (const a in
|
|
529
|
-
n.set(a,
|
|
530
|
-
n.has(
|
|
531
|
-
|
|
532
|
-
|
|
527
|
+
if (n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), t.headers)
|
|
528
|
+
for (const a in t.headers)
|
|
529
|
+
n.set(a, t.headers[a]);
|
|
530
|
+
n.has(S) || (n.set(S, w.defaultAgentName), n.set(
|
|
531
|
+
w.defaultAgentVersion,
|
|
532
|
+
w.packageVersion
|
|
533
533
|
));
|
|
534
534
|
let l = 5;
|
|
535
|
-
|
|
535
|
+
t.oauthToken && (n.set("Authorization", t.oauthToken), l = 3), t.rateLimit && (l = t.rateLimit), t.richTextSchema ? this.richTextResolver = new k(t.richTextSchema) : this.richTextResolver = new k(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = C(this.throttledRequest, l, 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
536
|
baseURL: s,
|
|
537
|
-
timeout:
|
|
537
|
+
timeout: t.timeout || 0,
|
|
538
538
|
headers: n,
|
|
539
|
-
responseInterceptor:
|
|
540
|
-
fetch:
|
|
539
|
+
responseInterceptor: t.responseInterceptor,
|
|
540
|
+
fetch: t.fetch
|
|
541
541
|
});
|
|
542
542
|
}
|
|
543
|
-
setComponentResolver(
|
|
544
|
-
this.richTextResolver.addNode("blok", (
|
|
543
|
+
setComponentResolver(t) {
|
|
544
|
+
this.richTextResolver.addNode("blok", (e) => {
|
|
545
545
|
let s = "";
|
|
546
|
-
return
|
|
547
|
-
s +=
|
|
546
|
+
return e.attrs.body && e.attrs.body.forEach((r) => {
|
|
547
|
+
s += t(r.component, r);
|
|
548
548
|
}), {
|
|
549
549
|
html: s
|
|
550
550
|
};
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
parseParams(
|
|
554
|
-
return
|
|
553
|
+
parseParams(t) {
|
|
554
|
+
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(",")), t;
|
|
555
555
|
}
|
|
556
|
-
factoryParamOptions(
|
|
557
|
-
return this.helpers.isCDNUrl(
|
|
556
|
+
factoryParamOptions(t, e) {
|
|
557
|
+
return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
|
|
558
558
|
}
|
|
559
|
-
makeRequest(
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
this.helpers.getOptionsPage(
|
|
559
|
+
makeRequest(t, e, s, r) {
|
|
560
|
+
const i = this.factoryParamOptions(
|
|
561
|
+
t,
|
|
562
|
+
this.helpers.getOptionsPage(e, s, r)
|
|
563
563
|
);
|
|
564
|
-
return this.cacheResponse(
|
|
564
|
+
return this.cacheResponse(t, i);
|
|
565
565
|
}
|
|
566
|
-
get(
|
|
567
|
-
|
|
568
|
-
const r = `/${
|
|
569
|
-
return this.client.setFetchOptions(s), this.cacheResponse(r,
|
|
566
|
+
get(t, e, s) {
|
|
567
|
+
e || (e = {});
|
|
568
|
+
const r = `/${t}`, i = this.factoryParamOptions(r, e);
|
|
569
|
+
return this.client.setFetchOptions(s), this.cacheResponse(r, i);
|
|
570
570
|
}
|
|
571
|
-
async getAll(
|
|
572
|
-
const
|
|
571
|
+
async getAll(t, e, s, r) {
|
|
572
|
+
const i = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, l = n.split("/"), a = s || l[l.length - 1], c = 1, u = await this.makeRequest(n, e, i, c), p = u.total ? Math.ceil(u.total / i) : 1;
|
|
573
573
|
this.client.setFetchOptions(r);
|
|
574
|
-
const
|
|
575
|
-
this.helpers.range(c,
|
|
576
|
-
(
|
|
574
|
+
const d = await this.helpers.asyncMap(
|
|
575
|
+
this.helpers.range(c, p),
|
|
576
|
+
(f) => this.makeRequest(n, e, i, f + 1)
|
|
577
577
|
);
|
|
578
578
|
return this.helpers.flatMap(
|
|
579
|
-
[u, ...
|
|
580
|
-
(
|
|
579
|
+
[u, ...d],
|
|
580
|
+
(f) => Object.values(f.data[a])
|
|
581
581
|
);
|
|
582
582
|
}
|
|
583
|
-
post(
|
|
584
|
-
const r = `/${
|
|
585
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r,
|
|
583
|
+
post(t, e, s) {
|
|
584
|
+
const r = `/${t}`;
|
|
585
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, e));
|
|
586
586
|
}
|
|
587
|
-
put(
|
|
588
|
-
const r = `/${
|
|
589
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r,
|
|
587
|
+
put(t, e, s) {
|
|
588
|
+
const r = `/${t}`;
|
|
589
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, e));
|
|
590
590
|
}
|
|
591
|
-
delete(
|
|
592
|
-
const r = `/${
|
|
593
|
-
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r,
|
|
591
|
+
delete(t, e, s) {
|
|
592
|
+
const r = `/${t}`;
|
|
593
|
+
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, e));
|
|
594
594
|
}
|
|
595
|
-
getStories(
|
|
596
|
-
return this.client.setFetchOptions(
|
|
595
|
+
getStories(t, e) {
|
|
596
|
+
return this.client.setFetchOptions(e), this.get("cdn/stories", t);
|
|
597
597
|
}
|
|
598
|
-
getStory(
|
|
599
|
-
return this.client.setFetchOptions(s), this.get(`cdn/stories/${
|
|
598
|
+
getStory(t, e, s) {
|
|
599
|
+
return this.client.setFetchOptions(s), this.get(`cdn/stories/${t}`, e);
|
|
600
600
|
}
|
|
601
601
|
getToken() {
|
|
602
602
|
return this.accessToken;
|
|
@@ -604,11 +604,11 @@ class he {
|
|
|
604
604
|
ejectInterceptor() {
|
|
605
605
|
this.client.eject();
|
|
606
606
|
}
|
|
607
|
-
_cleanCopy(
|
|
608
|
-
return JSON.parse(JSON.stringify(
|
|
607
|
+
_cleanCopy(t) {
|
|
608
|
+
return JSON.parse(JSON.stringify(t));
|
|
609
609
|
}
|
|
610
|
-
_insertLinks(
|
|
611
|
-
const r = e
|
|
610
|
+
_insertLinks(t, e, s) {
|
|
611
|
+
const r = t[e];
|
|
612
612
|
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
613
|
}
|
|
614
614
|
/**
|
|
@@ -617,52 +617,52 @@ class he {
|
|
|
617
617
|
* @param uuid The uuid of the story
|
|
618
618
|
* @returns string | object
|
|
619
619
|
*/
|
|
620
|
-
getStoryReference(
|
|
621
|
-
return this.relations[
|
|
622
|
-
this.relations[
|
|
623
|
-
)), JSON.parse(this.stringifiedStoriesCache[
|
|
624
|
-
}
|
|
625
|
-
_insertRelations(
|
|
626
|
-
s.indexOf(`${
|
|
627
|
-
}
|
|
628
|
-
iterateTree(
|
|
629
|
-
const r = (
|
|
630
|
-
if (
|
|
631
|
-
if (
|
|
632
|
-
for (let n = 0; n <
|
|
633
|
-
r(
|
|
634
|
-
else if (
|
|
635
|
-
if (
|
|
620
|
+
getStoryReference(t, e) {
|
|
621
|
+
return this.relations[t][e] ? (this.stringifiedStoriesCache[e] || (this.stringifiedStoriesCache[e] = JSON.stringify(
|
|
622
|
+
this.relations[t][e]
|
|
623
|
+
)), JSON.parse(this.stringifiedStoriesCache[e])) : e;
|
|
624
|
+
}
|
|
625
|
+
_insertRelations(t, e, s, r) {
|
|
626
|
+
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
|
+
}
|
|
628
|
+
iterateTree(t, e, s) {
|
|
629
|
+
const r = (i) => {
|
|
630
|
+
if (i != null) {
|
|
631
|
+
if (i.constructor === Array)
|
|
632
|
+
for (let n = 0; n < i.length; n++)
|
|
633
|
+
r(i[n]);
|
|
634
|
+
else if (i.constructor === Object) {
|
|
635
|
+
if (i._stopResolving)
|
|
636
636
|
return;
|
|
637
|
-
for (const n in
|
|
638
|
-
(
|
|
639
|
-
|
|
637
|
+
for (const n in i)
|
|
638
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
|
639
|
+
i,
|
|
640
640
|
n,
|
|
641
|
-
|
|
641
|
+
e,
|
|
642
642
|
s
|
|
643
643
|
), this._insertLinks(
|
|
644
|
-
|
|
644
|
+
i,
|
|
645
645
|
n,
|
|
646
646
|
s
|
|
647
|
-
)), r(
|
|
647
|
+
)), r(i[n]);
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
};
|
|
651
|
-
r(
|
|
651
|
+
r(t.content);
|
|
652
652
|
}
|
|
653
|
-
async resolveLinks(
|
|
653
|
+
async resolveLinks(t, e, s) {
|
|
654
654
|
let r = [];
|
|
655
|
-
if (
|
|
656
|
-
const
|
|
657
|
-
for (let a = 0; a <
|
|
658
|
-
const c = Math.min(
|
|
659
|
-
n.push(
|
|
655
|
+
if (t.link_uuids) {
|
|
656
|
+
const i = t.link_uuids.length, n = [], l = 50;
|
|
657
|
+
for (let a = 0; a < i; a += l) {
|
|
658
|
+
const c = Math.min(i, a + l);
|
|
659
|
+
n.push(t.link_uuids.slice(a, c));
|
|
660
660
|
}
|
|
661
661
|
for (let a = 0; a < n.length; a++)
|
|
662
662
|
(await this.getStories({
|
|
663
663
|
per_page: l,
|
|
664
|
-
language:
|
|
665
|
-
version:
|
|
664
|
+
language: e.language,
|
|
665
|
+
version: e.version,
|
|
666
666
|
by_uuids: n[a].join(",")
|
|
667
667
|
})).data.stories.forEach(
|
|
668
668
|
(c) => {
|
|
@@ -670,37 +670,37 @@ class he {
|
|
|
670
670
|
}
|
|
671
671
|
);
|
|
672
672
|
} else
|
|
673
|
-
r =
|
|
674
|
-
r.forEach((
|
|
675
|
-
this.links[s][
|
|
676
|
-
...
|
|
673
|
+
r = t.links;
|
|
674
|
+
r.forEach((i) => {
|
|
675
|
+
this.links[s][i.uuid] = {
|
|
676
|
+
...i,
|
|
677
677
|
_stopResolving: !0
|
|
678
678
|
};
|
|
679
679
|
});
|
|
680
680
|
}
|
|
681
|
-
async resolveRelations(
|
|
681
|
+
async resolveRelations(t, e, s) {
|
|
682
682
|
let r = [];
|
|
683
|
-
if (
|
|
684
|
-
const
|
|
685
|
-
for (let a = 0; a <
|
|
686
|
-
const c = Math.min(
|
|
687
|
-
n.push(
|
|
683
|
+
if (t.rel_uuids) {
|
|
684
|
+
const i = t.rel_uuids.length, n = [], l = 50;
|
|
685
|
+
for (let a = 0; a < i; a += l) {
|
|
686
|
+
const c = Math.min(i, a + l);
|
|
687
|
+
n.push(t.rel_uuids.slice(a, c));
|
|
688
688
|
}
|
|
689
689
|
for (let a = 0; a < n.length; a++)
|
|
690
690
|
(await this.getStories({
|
|
691
691
|
per_page: l,
|
|
692
|
-
language:
|
|
693
|
-
version:
|
|
692
|
+
language: e.language,
|
|
693
|
+
version: e.version,
|
|
694
694
|
by_uuids: n[a].join(","),
|
|
695
|
-
excluding_fields:
|
|
695
|
+
excluding_fields: e.excluding_fields
|
|
696
696
|
})).data.stories.forEach((c) => {
|
|
697
697
|
r.push(c);
|
|
698
698
|
});
|
|
699
699
|
} else
|
|
700
|
-
r =
|
|
701
|
-
r && r.length > 0 && r.forEach((
|
|
702
|
-
this.relations[s][
|
|
703
|
-
...
|
|
700
|
+
r = t.rels;
|
|
701
|
+
r && r.length > 0 && r.forEach((i) => {
|
|
702
|
+
this.relations[s][i.uuid] = {
|
|
703
|
+
...i,
|
|
704
704
|
_stopResolving: !0
|
|
705
705
|
};
|
|
706
706
|
});
|
|
@@ -714,34 +714,34 @@ class he {
|
|
|
714
714
|
* @returns Promise<void>
|
|
715
715
|
*
|
|
716
716
|
*/
|
|
717
|
-
async resolveStories(
|
|
718
|
-
var r,
|
|
717
|
+
async resolveStories(t, e, s) {
|
|
718
|
+
var r, i;
|
|
719
719
|
let n = [];
|
|
720
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof
|
|
720
|
+
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", "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
721
|
for (const l in this.relations[s])
|
|
722
722
|
this.iterateTree(
|
|
723
723
|
this.relations[s][l],
|
|
724
724
|
n,
|
|
725
725
|
s
|
|
726
726
|
);
|
|
727
|
-
|
|
727
|
+
t.story ? this.iterateTree(t.story, n, s) : t.stories.forEach((l) => {
|
|
728
728
|
this.iterateTree(l, n, s);
|
|
729
729
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
730
730
|
}
|
|
731
|
-
async cacheResponse(
|
|
731
|
+
async cacheResponse(t, e, s) {
|
|
732
732
|
(typeof s > "u" || !s) && (s = 0);
|
|
733
|
-
const r = this.helpers.stringify({ url:
|
|
734
|
-
if (this.cache.clear === "auto" &&
|
|
735
|
-
const n = await
|
|
733
|
+
const r = this.helpers.stringify({ url: t, params: e }), i = this.cacheProvider();
|
|
734
|
+
if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
|
|
735
|
+
const n = await i.get(r);
|
|
736
736
|
if (n)
|
|
737
737
|
return Promise.resolve(n);
|
|
738
738
|
}
|
|
739
739
|
return new Promise(async (n, l) => {
|
|
740
740
|
var a;
|
|
741
741
|
try {
|
|
742
|
-
const c = await this.throttle("get",
|
|
742
|
+
const c = await this.throttle("get", t, e);
|
|
743
743
|
if (c.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
|
744
|
-
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(
|
|
744
|
+
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(t, e, s).then(n).catch(l);
|
|
745
745
|
if (c.status !== 200)
|
|
746
746
|
return l(c);
|
|
747
747
|
let u = { data: c.data, headers: c.headers };
|
|
@@ -749,42 +749,42 @@ class he {
|
|
|
749
749
|
perPage: c.headers["per-page"] ? parseInt(c.headers["per-page"]) : 0,
|
|
750
750
|
total: c.headers["per-page"] ? parseInt(c.headers.total) : 0
|
|
751
751
|
})), u.data.story || u.data.stories) {
|
|
752
|
-
const
|
|
753
|
-
await this.resolveStories(u.data,
|
|
752
|
+
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
753
|
+
await this.resolveStories(u.data, e, `${p}`);
|
|
754
754
|
}
|
|
755
|
-
return
|
|
755
|
+
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), n(u);
|
|
756
756
|
} catch (c) {
|
|
757
757
|
l(c);
|
|
758
758
|
}
|
|
759
759
|
});
|
|
760
760
|
}
|
|
761
|
-
throttledRequest(
|
|
762
|
-
return this.client[
|
|
761
|
+
throttledRequest(t, e, s) {
|
|
762
|
+
return this.client[t](e, s);
|
|
763
763
|
}
|
|
764
764
|
cacheVersions() {
|
|
765
|
-
return
|
|
765
|
+
return m;
|
|
766
766
|
}
|
|
767
767
|
cacheVersion() {
|
|
768
|
-
return
|
|
768
|
+
return m[this.accessToken];
|
|
769
769
|
}
|
|
770
|
-
setCacheVersion(
|
|
771
|
-
this.accessToken && (
|
|
770
|
+
setCacheVersion(t) {
|
|
771
|
+
this.accessToken && (m[this.accessToken] = t);
|
|
772
772
|
}
|
|
773
773
|
cacheProvider() {
|
|
774
774
|
switch (this.cache.type) {
|
|
775
775
|
case "memory":
|
|
776
776
|
return {
|
|
777
|
-
get(
|
|
778
|
-
return Promise.resolve(
|
|
777
|
+
get(t) {
|
|
778
|
+
return Promise.resolve(y[t]);
|
|
779
779
|
},
|
|
780
780
|
getAll() {
|
|
781
|
-
return Promise.resolve(
|
|
781
|
+
return Promise.resolve(y);
|
|
782
782
|
},
|
|
783
|
-
set(
|
|
784
|
-
return
|
|
783
|
+
set(t, e) {
|
|
784
|
+
return y[t] = e, Promise.resolve(void 0);
|
|
785
785
|
},
|
|
786
786
|
flush() {
|
|
787
|
-
return
|
|
787
|
+
return y = {}, Promise.resolve(void 0);
|
|
788
788
|
}
|
|
789
789
|
};
|
|
790
790
|
case "custom":
|
|
@@ -811,93 +811,93 @@ class he {
|
|
|
811
811
|
return await this.cacheProvider().flush(), this;
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
|
-
const
|
|
815
|
-
const { apiOptions:
|
|
816
|
-
if (!
|
|
814
|
+
const pt = (o = {}) => {
|
|
815
|
+
const { apiOptions: t } = o;
|
|
816
|
+
if (!t.accessToken) {
|
|
817
817
|
console.error(
|
|
818
818
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
819
819
|
);
|
|
820
820
|
return;
|
|
821
821
|
}
|
|
822
|
-
return { storyblokApi: new
|
|
823
|
-
},
|
|
824
|
-
if (typeof
|
|
822
|
+
return { storyblokApi: new ht(t) };
|
|
823
|
+
}, gt = (o) => {
|
|
824
|
+
if (typeof o != "object" || typeof o._editable > "u")
|
|
825
825
|
return {};
|
|
826
826
|
try {
|
|
827
|
-
const
|
|
828
|
-
|
|
827
|
+
const t = JSON.parse(
|
|
828
|
+
o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
829
829
|
);
|
|
830
|
-
return
|
|
831
|
-
"data-blok-c": JSON.stringify(
|
|
832
|
-
"data-blok-uid":
|
|
830
|
+
return t ? {
|
|
831
|
+
"data-blok-c": JSON.stringify(t),
|
|
832
|
+
"data-blok-uid": t.id + "-" + t.uid
|
|
833
833
|
} : {};
|
|
834
834
|
} catch {
|
|
835
835
|
return {};
|
|
836
836
|
}
|
|
837
837
|
};
|
|
838
|
-
let
|
|
839
|
-
const
|
|
838
|
+
let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
839
|
+
const dt = (o, t, e = {}) => {
|
|
840
840
|
var s;
|
|
841
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
841
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
842
842
|
"_storyblok"
|
|
843
|
-
) ===
|
|
844
|
-
if (!(!r || !
|
|
845
|
-
if (!
|
|
843
|
+
) === o;
|
|
844
|
+
if (!(!r || !i)) {
|
|
845
|
+
if (!o) {
|
|
846
846
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
847
847
|
return;
|
|
848
848
|
}
|
|
849
849
|
window.storyblokRegisterEvent(() => {
|
|
850
|
-
new window.StoryblokBridge(
|
|
851
|
-
n.action === "input" && n.story.id ===
|
|
850
|
+
new window.StoryblokBridge(e).on(["input", "published", "change"], (n) => {
|
|
851
|
+
n.action === "input" && n.story.id === o ? t(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
|
|
852
852
|
});
|
|
853
853
|
});
|
|
854
854
|
}
|
|
855
|
-
},
|
|
856
|
-
var
|
|
855
|
+
}, ft = (o = {}) => {
|
|
856
|
+
var t, e;
|
|
857
857
|
const {
|
|
858
858
|
bridge: s,
|
|
859
859
|
accessToken: r,
|
|
860
|
-
use:
|
|
860
|
+
use: i = [],
|
|
861
861
|
apiOptions: n = {},
|
|
862
862
|
richText: l = {},
|
|
863
863
|
bridgeUrl: a
|
|
864
|
-
} =
|
|
864
|
+
} = o;
|
|
865
865
|
n.accessToken = n.accessToken || r;
|
|
866
866
|
const c = { bridge: s, apiOptions: n };
|
|
867
867
|
let u = {};
|
|
868
|
-
|
|
869
|
-
u = { ...u, ...
|
|
870
|
-
}), a && (
|
|
871
|
-
const
|
|
872
|
-
return s !== !1 &&
|
|
873
|
-
},
|
|
874
|
-
|
|
868
|
+
i.forEach((d) => {
|
|
869
|
+
u = { ...u, ...d(c) };
|
|
870
|
+
}), a && (R = a);
|
|
871
|
+
const p = !(typeof window > "u") && ((e = (t = window.location) == null ? void 0 : t.search) == null ? void 0 : e.includes("_storyblok_tk"));
|
|
872
|
+
return s !== !1 && p && O(R), $ = new k(l.schema), l.resolver && E($, l.resolver), u;
|
|
873
|
+
}, E = (o, t) => {
|
|
874
|
+
o.addNode("blok", (e) => {
|
|
875
875
|
let s = "";
|
|
876
|
-
return
|
|
877
|
-
s +=
|
|
876
|
+
return e.attrs.body.forEach((r) => {
|
|
877
|
+
s += t(r.component, r);
|
|
878
878
|
}), {
|
|
879
879
|
html: s
|
|
880
880
|
};
|
|
881
881
|
});
|
|
882
|
-
},
|
|
883
|
-
let s =
|
|
882
|
+
}, ut = (o) => !o || !(o != null && o.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), mt = (o, t, e) => {
|
|
883
|
+
let s = e || $;
|
|
884
884
|
if (!s) {
|
|
885
885
|
console.error(
|
|
886
886
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
887
887
|
);
|
|
888
888
|
return;
|
|
889
889
|
}
|
|
890
|
-
return
|
|
891
|
-
},
|
|
890
|
+
return ut(o) ? "" : (t && (s = new k(t.schema), t.resolver && E(s, t.resolver)), s.render(o));
|
|
891
|
+
}, yt = () => O(R);
|
|
892
892
|
export {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
893
|
+
k as RichTextResolver,
|
|
894
|
+
ot as RichTextSchema,
|
|
895
|
+
pt as apiPlugin,
|
|
896
|
+
ut as isRichTextEmpty,
|
|
897
|
+
yt as loadStoryblokBridge,
|
|
898
|
+
dt as registerStoryblokBridge,
|
|
899
|
+
mt as renderRichText,
|
|
900
|
+
gt as storyblokEditable,
|
|
901
|
+
ft as storyblokInit,
|
|
902
|
+
dt as useStoryblokBridge
|
|
903
903
|
};
|