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