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