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