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