@storyblok/astro 1.0.1 → 1.1.1
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/README.md +31 -5
- package/StoryblokComponent.astro +21 -4
- package/dist/storyblok-astro.js +4 -4
- package/dist/storyblok-astro.mjs +397 -366
- package/package.json +6 -5
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -1,57 +1,77 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import N from "axios";
|
|
2
|
+
const L = /[\p{Lu}]/u, M = /[\p{Ll}]/u, v = /^[\p{Lu}](?![\p{Lu}])/gu, O = /([\p{Alpha}\p{N}_]|$)/u, k = /[_.\- ]+/, U = new RegExp("^" + k.source), b = new RegExp(k.source + O.source, "gu"), T = new RegExp("\\d+" + O.source, "gu"), D = (s, e, t) => {
|
|
3
|
+
let r = !1, o = !1, n = !1;
|
|
4
|
+
for (let i = 0; i < s.length; i++) {
|
|
5
|
+
const a = s[i];
|
|
6
|
+
r && L.test(a) ? (s = s.slice(0, i) + "-" + s.slice(i), r = !1, n = o, o = !0, i++) : o && n && M.test(a) ? (s = s.slice(0, i - 1) + "-" + s.slice(i - 1), n = o, o = !1, r = !0) : (r = e(a) === a && t(a) !== a, n = o, o = t(a) === a && e(a) !== a);
|
|
7
|
+
}
|
|
8
|
+
return s;
|
|
9
|
+
}, q = (s, e) => (v.lastIndex = 0, s.replace(v, (t) => e(t))), B = (s, e) => (b.lastIndex = 0, T.lastIndex = 0, s.replace(b, (t, r) => e(r)).replace(T, (t) => e(t)));
|
|
10
|
+
function _(s, e) {
|
|
11
|
+
if (!(typeof s == "string" || Array.isArray(s)))
|
|
12
|
+
throw new TypeError("Expected the input to be `string | string[]`");
|
|
13
|
+
if (e = {
|
|
14
|
+
pascalCase: !1,
|
|
15
|
+
preserveConsecutiveUppercase: !1,
|
|
16
|
+
...e
|
|
17
|
+
}, Array.isArray(s) ? s = s.map((n) => n.trim()).filter((n) => n.length).join("-") : s = s.trim(), s.length === 0)
|
|
18
|
+
return "";
|
|
19
|
+
const t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), r = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
|
|
20
|
+
return s.length === 1 ? k.test(s) ? "" : e.pascalCase ? r(s) : t(s) : (s !== t(s) && (s = D(s, t, r)), s = s.replace(U, ""), s = e.preserveConsecutiveUppercase ? q(s, t) : t(s), e.pascalCase && (s = r(s.charAt(0)) + s.slice(1)), B(s, r));
|
|
21
|
+
}
|
|
22
|
+
function z(s) {
|
|
23
|
+
const e = "virtual:storyblok-components", t = "\0" + e;
|
|
4
24
|
return {
|
|
5
25
|
name: "vite-plugin-storyblok",
|
|
6
26
|
async resolveId(r) {
|
|
7
|
-
if (r ===
|
|
8
|
-
return
|
|
27
|
+
if (r === e)
|
|
28
|
+
return t;
|
|
9
29
|
},
|
|
10
30
|
async load(r) {
|
|
11
|
-
if (r ===
|
|
12
|
-
const
|
|
13
|
-
for await (const [
|
|
14
|
-
const { id:
|
|
15
|
-
|
|
31
|
+
if (r === t) {
|
|
32
|
+
const o = [];
|
|
33
|
+
for await (const [n, i] of Object.entries(s)) {
|
|
34
|
+
const { id: a } = await this.resolve("/src/" + i + ".astro");
|
|
35
|
+
o.push(`import ${_(n)} from "${a}"`);
|
|
16
36
|
}
|
|
17
|
-
return `${
|
|
37
|
+
return `${o.join(";")};export default {${Object.keys(s).map((n) => _(n)).join(",")}}`;
|
|
18
38
|
}
|
|
19
39
|
}
|
|
20
40
|
};
|
|
21
41
|
}
|
|
22
|
-
var
|
|
23
|
-
for (var
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
for (var
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
},
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
42
|
+
var H = Object.defineProperty, V = Object.defineProperties, F = Object.getOwnPropertyDescriptors, R = Object.getOwnPropertySymbols, J = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable, w = (s, e, t) => e in s ? H(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, u = (s, e) => {
|
|
43
|
+
for (var t in e || (e = {}))
|
|
44
|
+
J.call(e, t) && w(s, t, e[t]);
|
|
45
|
+
if (R)
|
|
46
|
+
for (var t of R(e))
|
|
47
|
+
G.call(e, t) && w(s, t, e[t]);
|
|
48
|
+
return s;
|
|
49
|
+
}, g = (s, e) => V(s, F(e));
|
|
50
|
+
let E = !1;
|
|
51
|
+
const A = [], S = (s) => new Promise((e, t) => {
|
|
52
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
|
|
33
53
|
if (window.location === window.parent.location) {
|
|
34
54
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
35
55
|
return;
|
|
36
56
|
}
|
|
37
|
-
|
|
57
|
+
E ? o() : A.push(o);
|
|
38
58
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
39
59
|
return;
|
|
40
60
|
const r = document.createElement("script");
|
|
41
|
-
r.async = !0, r.src =
|
|
42
|
-
|
|
61
|
+
r.async = !0, r.src = s, r.id = "storyblok-javascript-bridge", r.onerror = (o) => t(o), r.onload = (o) => {
|
|
62
|
+
A.forEach((n) => n()), E = !0, e(o);
|
|
43
63
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
44
|
-
}),
|
|
45
|
-
if (!
|
|
64
|
+
}), K = function(s, e) {
|
|
65
|
+
if (!s)
|
|
46
66
|
return null;
|
|
47
|
-
let
|
|
48
|
-
for (let r in
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return
|
|
53
|
-
},
|
|
54
|
-
var
|
|
67
|
+
let t = {};
|
|
68
|
+
for (let r in s) {
|
|
69
|
+
let o = s[r];
|
|
70
|
+
e.indexOf(r) > -1 && o !== null && (t[r] = o);
|
|
71
|
+
}
|
|
72
|
+
return t;
|
|
73
|
+
}, Y = (s) => s === "email";
|
|
74
|
+
var W = {
|
|
55
75
|
nodes: {
|
|
56
76
|
horizontal_rule() {
|
|
57
77
|
return {
|
|
@@ -68,13 +88,13 @@ var B = {
|
|
|
68
88
|
tag: "ul"
|
|
69
89
|
};
|
|
70
90
|
},
|
|
71
|
-
code_block(
|
|
91
|
+
code_block(s) {
|
|
72
92
|
return {
|
|
73
93
|
tag: [
|
|
74
94
|
"pre",
|
|
75
95
|
{
|
|
76
96
|
tag: "code",
|
|
77
|
-
attrs:
|
|
97
|
+
attrs: s.attrs
|
|
78
98
|
}
|
|
79
99
|
]
|
|
80
100
|
};
|
|
@@ -84,17 +104,17 @@ var B = {
|
|
|
84
104
|
singleTag: "br"
|
|
85
105
|
};
|
|
86
106
|
},
|
|
87
|
-
heading(
|
|
107
|
+
heading(s) {
|
|
88
108
|
return {
|
|
89
|
-
tag: `h${
|
|
109
|
+
tag: `h${s.attrs.level}`
|
|
90
110
|
};
|
|
91
111
|
},
|
|
92
|
-
image(
|
|
112
|
+
image(s) {
|
|
93
113
|
return {
|
|
94
114
|
singleTag: [
|
|
95
115
|
{
|
|
96
116
|
tag: "img",
|
|
97
|
-
attrs:
|
|
117
|
+
attrs: K(s.attrs, ["src", "alt", "title"])
|
|
98
118
|
}
|
|
99
119
|
]
|
|
100
120
|
};
|
|
@@ -146,100 +166,100 @@ var B = {
|
|
|
146
166
|
tag: "i"
|
|
147
167
|
};
|
|
148
168
|
},
|
|
149
|
-
link(
|
|
150
|
-
const
|
|
151
|
-
return
|
|
169
|
+
link(s) {
|
|
170
|
+
const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
|
|
171
|
+
return Y(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
|
|
152
172
|
tag: [
|
|
153
173
|
{
|
|
154
174
|
tag: "a",
|
|
155
|
-
attrs:
|
|
175
|
+
attrs: e
|
|
156
176
|
}
|
|
157
177
|
]
|
|
158
178
|
};
|
|
159
179
|
},
|
|
160
|
-
styled(
|
|
180
|
+
styled(s) {
|
|
161
181
|
return {
|
|
162
182
|
tag: [
|
|
163
183
|
{
|
|
164
184
|
tag: "span",
|
|
165
|
-
attrs:
|
|
185
|
+
attrs: s.attrs
|
|
166
186
|
}
|
|
167
187
|
]
|
|
168
188
|
};
|
|
169
189
|
}
|
|
170
190
|
}
|
|
171
191
|
};
|
|
172
|
-
const
|
|
173
|
-
const
|
|
192
|
+
const Q = function(s) {
|
|
193
|
+
const e = {
|
|
174
194
|
"&": "&",
|
|
175
195
|
"<": "<",
|
|
176
196
|
">": ">",
|
|
177
197
|
'"': """,
|
|
178
198
|
"'": "'"
|
|
179
|
-
},
|
|
180
|
-
return
|
|
199
|
+
}, t = /[&<>"']/g, r = RegExp(t.source);
|
|
200
|
+
return s && r.test(s) ? s.replace(t, (o) => e[o]) : s;
|
|
181
201
|
};
|
|
182
|
-
class
|
|
183
|
-
constructor(
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
addNode(
|
|
187
|
-
this.nodes[
|
|
188
|
-
}
|
|
189
|
-
addMark(
|
|
190
|
-
this.marks[
|
|
191
|
-
}
|
|
192
|
-
render(
|
|
193
|
-
if (
|
|
194
|
-
let
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
}),
|
|
202
|
+
class x {
|
|
203
|
+
constructor(e) {
|
|
204
|
+
e || (e = W), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
205
|
+
}
|
|
206
|
+
addNode(e, t) {
|
|
207
|
+
this.nodes[e] = t;
|
|
208
|
+
}
|
|
209
|
+
addMark(e, t) {
|
|
210
|
+
this.marks[e] = t;
|
|
211
|
+
}
|
|
212
|
+
render(e = {}) {
|
|
213
|
+
if (e.content && Array.isArray(e.content)) {
|
|
214
|
+
let t = "";
|
|
215
|
+
return e.content.forEach((r) => {
|
|
216
|
+
t += this.renderNode(r);
|
|
217
|
+
}), t;
|
|
198
218
|
}
|
|
199
219
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
200
220
|
}
|
|
201
|
-
renderNode(
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
221
|
+
renderNode(e) {
|
|
222
|
+
let t = [];
|
|
223
|
+
e.marks && e.marks.forEach((o) => {
|
|
224
|
+
const n = this.getMatchingMark(o);
|
|
225
|
+
n && t.push(this.renderOpeningTag(n.tag));
|
|
206
226
|
});
|
|
207
|
-
const r = this.getMatchingNode(
|
|
208
|
-
return r && r.tag &&
|
|
209
|
-
|
|
210
|
-
}) :
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
}),
|
|
214
|
-
}
|
|
215
|
-
renderTag(
|
|
216
|
-
return
|
|
217
|
-
if (
|
|
218
|
-
return `<${
|
|
227
|
+
const r = this.getMatchingNode(e);
|
|
228
|
+
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
|
|
229
|
+
t.push(this.renderNode(o));
|
|
230
|
+
}) : e.text ? t.push(Q(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
|
|
231
|
+
const n = this.getMatchingMark(o);
|
|
232
|
+
n && t.push(this.renderClosingTag(n.tag));
|
|
233
|
+
}), t.join("");
|
|
234
|
+
}
|
|
235
|
+
renderTag(e, t) {
|
|
236
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
|
|
237
|
+
if (o.constructor === String)
|
|
238
|
+
return `<${o}${t}>`;
|
|
219
239
|
{
|
|
220
|
-
let
|
|
221
|
-
if (
|
|
222
|
-
for (let
|
|
223
|
-
let
|
|
224
|
-
|
|
240
|
+
let n = `<${o.tag}`;
|
|
241
|
+
if (o.attrs)
|
|
242
|
+
for (let i in o.attrs) {
|
|
243
|
+
let a = o.attrs[i];
|
|
244
|
+
a !== null && (n += ` ${i}="${a}"`);
|
|
225
245
|
}
|
|
226
|
-
return `${
|
|
246
|
+
return `${n}${t}>`;
|
|
227
247
|
}
|
|
228
248
|
}).join("");
|
|
229
249
|
}
|
|
230
|
-
renderOpeningTag(
|
|
231
|
-
return this.renderTag(
|
|
250
|
+
renderOpeningTag(e) {
|
|
251
|
+
return this.renderTag(e, "");
|
|
232
252
|
}
|
|
233
|
-
renderClosingTag(
|
|
234
|
-
return
|
|
253
|
+
renderClosingTag(e) {
|
|
254
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
|
|
235
255
|
}
|
|
236
|
-
getMatchingNode(
|
|
237
|
-
if (typeof this.nodes[
|
|
238
|
-
return this.nodes[
|
|
256
|
+
getMatchingNode(e) {
|
|
257
|
+
if (typeof this.nodes[e.type] == "function")
|
|
258
|
+
return this.nodes[e.type](e);
|
|
239
259
|
}
|
|
240
|
-
getMatchingMark(
|
|
241
|
-
if (typeof this.marks[
|
|
242
|
-
return this.marks[
|
|
260
|
+
getMatchingMark(e) {
|
|
261
|
+
if (typeof this.marks[e.type] == "function")
|
|
262
|
+
return this.marks[e.type](e);
|
|
243
263
|
}
|
|
244
264
|
}
|
|
245
265
|
/*!
|
|
@@ -247,319 +267,319 @@ class R {
|
|
|
247
267
|
* Universal JavaScript SDK for Storyblok's API
|
|
248
268
|
* (c) 2020-2022 Stobylok Team
|
|
249
269
|
*/
|
|
250
|
-
function
|
|
251
|
-
return typeof
|
|
270
|
+
function $(s) {
|
|
271
|
+
return typeof s == "number" && s == s && s !== 1 / 0 && s !== -1 / 0;
|
|
252
272
|
}
|
|
253
|
-
function
|
|
254
|
-
if (
|
|
273
|
+
function C(s, e, t) {
|
|
274
|
+
if (!$(e))
|
|
255
275
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
256
|
-
if (
|
|
276
|
+
if (!$(t))
|
|
257
277
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
258
|
-
var r = [],
|
|
259
|
-
|
|
278
|
+
var r = [], o = [], n = 0, i = function() {
|
|
279
|
+
n++;
|
|
260
280
|
var c = setTimeout(function() {
|
|
261
|
-
|
|
281
|
+
n--, r.length > 0 && i(), o = o.filter(function(h) {
|
|
262
282
|
return h !== c;
|
|
263
283
|
});
|
|
264
|
-
},
|
|
265
|
-
|
|
284
|
+
}, t);
|
|
285
|
+
o.indexOf(c) < 0 && o.push(c);
|
|
266
286
|
var l = r.shift();
|
|
267
|
-
l.resolve(
|
|
268
|
-
},
|
|
287
|
+
l.resolve(s.apply(l.self, l.args));
|
|
288
|
+
}, a = function() {
|
|
269
289
|
var c = arguments, l = this;
|
|
270
290
|
return new Promise(function(h, p) {
|
|
271
|
-
r.push({ resolve: h, reject: p, args: c, self: l }),
|
|
291
|
+
r.push({ resolve: h, reject: p, args: c, self: l }), n < e && i();
|
|
272
292
|
});
|
|
273
293
|
};
|
|
274
|
-
return
|
|
275
|
-
|
|
294
|
+
return a.abort = function() {
|
|
295
|
+
o.forEach(clearTimeout), o = [], r.forEach(function(c) {
|
|
276
296
|
c.reject(new throttle.AbortError());
|
|
277
297
|
}), r.length = 0;
|
|
278
|
-
},
|
|
298
|
+
}, a;
|
|
279
299
|
}
|
|
280
|
-
|
|
300
|
+
C.AbortError = function() {
|
|
281
301
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
282
302
|
};
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
303
|
+
const X = function(s, e) {
|
|
304
|
+
if (!s)
|
|
285
305
|
return null;
|
|
286
|
-
let
|
|
287
|
-
for (let r in
|
|
288
|
-
let
|
|
289
|
-
|
|
306
|
+
let t = {};
|
|
307
|
+
for (let r in s) {
|
|
308
|
+
let o = s[r];
|
|
309
|
+
e.indexOf(r) > -1 && o !== null && (t[r] = o);
|
|
290
310
|
}
|
|
291
|
-
return
|
|
311
|
+
return t;
|
|
292
312
|
};
|
|
293
|
-
var
|
|
294
|
-
const
|
|
295
|
-
return
|
|
296
|
-
}, styled: (
|
|
297
|
-
class
|
|
298
|
-
constructor(
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
addNode(
|
|
302
|
-
this.nodes[
|
|
303
|
-
}
|
|
304
|
-
addMark(
|
|
305
|
-
this.marks[
|
|
306
|
-
}
|
|
307
|
-
render(
|
|
308
|
-
if (
|
|
309
|
-
let
|
|
310
|
-
return
|
|
311
|
-
|
|
312
|
-
}),
|
|
313
|
+
var Z = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (s) => ({ tag: ["pre", { tag: "code", attrs: s.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (s) => ({ tag: `h${s.attrs.level}` }), image: (s) => ({ singleTag: [{ tag: "img", attrs: X(s.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(s) {
|
|
314
|
+
const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
|
|
315
|
+
return t === "email" && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), { tag: [{ tag: "a", attrs: e }] };
|
|
316
|
+
}, styled: (s) => ({ tag: [{ tag: "span", attrs: s.attrs }] }) } };
|
|
317
|
+
class ee {
|
|
318
|
+
constructor(e) {
|
|
319
|
+
e || (e = Z), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
320
|
+
}
|
|
321
|
+
addNode(e, t) {
|
|
322
|
+
this.nodes[e] = t;
|
|
323
|
+
}
|
|
324
|
+
addMark(e, t) {
|
|
325
|
+
this.marks[e] = t;
|
|
326
|
+
}
|
|
327
|
+
render(e = {}) {
|
|
328
|
+
if (e.content && Array.isArray(e.content)) {
|
|
329
|
+
let t = "";
|
|
330
|
+
return e.content.forEach((r) => {
|
|
331
|
+
t += this.renderNode(r);
|
|
332
|
+
}), t;
|
|
313
333
|
}
|
|
314
334
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
315
335
|
}
|
|
316
|
-
renderNode(
|
|
317
|
-
let
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
336
|
+
renderNode(e) {
|
|
337
|
+
let t = [];
|
|
338
|
+
e.marks && e.marks.forEach((o) => {
|
|
339
|
+
const n = this.getMatchingMark(o);
|
|
340
|
+
n && t.push(this.renderOpeningTag(n.tag));
|
|
321
341
|
});
|
|
322
|
-
const r = this.getMatchingNode(
|
|
323
|
-
return r && r.tag &&
|
|
324
|
-
|
|
325
|
-
}) :
|
|
326
|
-
const
|
|
327
|
-
return
|
|
328
|
-
}(
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
}),
|
|
332
|
-
}
|
|
333
|
-
renderTag(
|
|
334
|
-
return
|
|
342
|
+
const r = this.getMatchingNode(e);
|
|
343
|
+
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
|
|
344
|
+
t.push(this.renderNode(o));
|
|
345
|
+
}) : e.text ? t.push(function(o) {
|
|
346
|
+
const n = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, i = /[&<>"']/g, a = RegExp(i.source);
|
|
347
|
+
return o && a.test(o) ? o.replace(i, (c) => n[c]) : o;
|
|
348
|
+
}(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
|
|
349
|
+
const n = this.getMatchingMark(o);
|
|
350
|
+
n && t.push(this.renderClosingTag(n.tag));
|
|
351
|
+
}), t.join("");
|
|
352
|
+
}
|
|
353
|
+
renderTag(e, t) {
|
|
354
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
|
|
335
355
|
if (r.constructor === String)
|
|
336
|
-
return `<${r}${
|
|
356
|
+
return `<${r}${t}>`;
|
|
337
357
|
{
|
|
338
|
-
let
|
|
358
|
+
let o = `<${r.tag}`;
|
|
339
359
|
if (r.attrs)
|
|
340
|
-
for (let
|
|
341
|
-
let
|
|
342
|
-
|
|
360
|
+
for (let n in r.attrs) {
|
|
361
|
+
let i = r.attrs[n];
|
|
362
|
+
i !== null && (o += ` ${n}="${i}"`);
|
|
343
363
|
}
|
|
344
|
-
return `${
|
|
364
|
+
return `${o}${t}>`;
|
|
345
365
|
}
|
|
346
366
|
}).join("");
|
|
347
367
|
}
|
|
348
|
-
renderOpeningTag(
|
|
349
|
-
return this.renderTag(
|
|
368
|
+
renderOpeningTag(e) {
|
|
369
|
+
return this.renderTag(e, "");
|
|
350
370
|
}
|
|
351
|
-
renderClosingTag(
|
|
352
|
-
return
|
|
371
|
+
renderClosingTag(e) {
|
|
372
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
353
373
|
}
|
|
354
|
-
getMatchingNode(
|
|
355
|
-
if (typeof this.nodes[
|
|
356
|
-
return this.nodes[
|
|
374
|
+
getMatchingNode(e) {
|
|
375
|
+
if (typeof this.nodes[e.type] == "function")
|
|
376
|
+
return this.nodes[e.type](e);
|
|
357
377
|
}
|
|
358
|
-
getMatchingMark(
|
|
359
|
-
if (typeof this.marks[
|
|
360
|
-
return this.marks[
|
|
378
|
+
getMatchingMark(e) {
|
|
379
|
+
if (typeof this.marks[e.type] == "function")
|
|
380
|
+
return this.marks[e.type](e);
|
|
361
381
|
}
|
|
362
382
|
}
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
return ((
|
|
366
|
-
},
|
|
383
|
+
const te = (s = 0, e = s) => {
|
|
384
|
+
const t = Math.abs(e - s) || 0, r = s < e ? 1 : -1;
|
|
385
|
+
return ((o = 0, n) => [...Array(o)].map(n))(t, (o, n) => n * r + s);
|
|
386
|
+
}, y = (s, e, t) => {
|
|
367
387
|
const r = [];
|
|
368
|
-
for (const
|
|
369
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
388
|
+
for (const o in s) {
|
|
389
|
+
if (!Object.prototype.hasOwnProperty.call(s, o))
|
|
370
390
|
continue;
|
|
371
|
-
const
|
|
372
|
-
let
|
|
373
|
-
|
|
391
|
+
const n = s[o], i = t ? "" : encodeURIComponent(o);
|
|
392
|
+
let a;
|
|
393
|
+
a = typeof n == "object" ? y(n, e ? e + encodeURIComponent("[" + i + "]") : i, Array.isArray(n)) : (e ? e + encodeURIComponent("[" + i + "]") : i) + "=" + encodeURIComponent(n), r.push(a);
|
|
374
394
|
}
|
|
375
395
|
return r.join("&");
|
|
376
396
|
};
|
|
377
|
-
let
|
|
378
|
-
class
|
|
379
|
-
constructor(
|
|
380
|
-
if (!
|
|
381
|
-
let
|
|
382
|
-
|
|
397
|
+
let f = {}, d = {};
|
|
398
|
+
class re {
|
|
399
|
+
constructor(e, t) {
|
|
400
|
+
if (!t) {
|
|
401
|
+
let n = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
|
|
402
|
+
t = e.oauthToken === void 0 ? `${i}://api${n}.storyblok.com/v2` : `${i}://api${n}.storyblok.com/v1`;
|
|
383
403
|
}
|
|
384
|
-
let r = Object.assign({},
|
|
385
|
-
|
|
404
|
+
let r = Object.assign({}, e.headers), o = 5;
|
|
405
|
+
e.oauthToken !== void 0 && (r.Authorization = e.oauthToken, o = 3), e.rateLimit !== void 0 && (o = e.rateLimit), this.richTextResolver = new ee(e.richTextSchema), typeof e.componentResolver == "function" && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = C(this.throttledRequest, o, 1e3), this.accessToken = e.accessToken, this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.client = N.create({ baseURL: t, timeout: e.timeout || 0, headers: r, proxy: e.proxy || !1 }), e.responseInterceptor && this.client.interceptors.response.use((n) => e.responseInterceptor(n)), this.resolveNestedRelations = e.resolveNestedRelations || !0;
|
|
386
406
|
}
|
|
387
|
-
setComponentResolver(
|
|
388
|
-
this.richTextResolver.addNode("blok", (
|
|
407
|
+
setComponentResolver(e) {
|
|
408
|
+
this.richTextResolver.addNode("blok", (t) => {
|
|
389
409
|
let r = "";
|
|
390
|
-
return
|
|
391
|
-
r +=
|
|
410
|
+
return t.attrs.body.forEach((o) => {
|
|
411
|
+
r += e(o.component, o);
|
|
392
412
|
}), { html: r };
|
|
393
413
|
});
|
|
394
414
|
}
|
|
395
|
-
parseParams(
|
|
396
|
-
return
|
|
415
|
+
parseParams(e = {}) {
|
|
416
|
+
return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = d[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
|
397
417
|
}
|
|
398
|
-
factoryParamOptions(
|
|
399
|
-
return ((r = "") => r.indexOf("/cdn/") > -1)(
|
|
418
|
+
factoryParamOptions(e, t = {}) {
|
|
419
|
+
return ((r = "") => r.indexOf("/cdn/") > -1)(e) ? this.parseParams(t) : t;
|
|
400
420
|
}
|
|
401
|
-
makeRequest(
|
|
402
|
-
const
|
|
403
|
-
return this.cacheResponse(
|
|
421
|
+
makeRequest(e, t, r, o) {
|
|
422
|
+
const n = this.factoryParamOptions(e, ((i = {}, a = 25, c = 1) => g(u({}, i), { per_page: a, page: c }))(t, r, o));
|
|
423
|
+
return this.cacheResponse(e, n);
|
|
404
424
|
}
|
|
405
|
-
get(
|
|
406
|
-
let r = `/${
|
|
407
|
-
const
|
|
408
|
-
return this.cacheResponse(r,
|
|
425
|
+
get(e, t) {
|
|
426
|
+
let r = `/${e}`;
|
|
427
|
+
const o = this.factoryParamOptions(r, t);
|
|
428
|
+
return this.cacheResponse(r, o);
|
|
409
429
|
}
|
|
410
|
-
async getAll(
|
|
411
|
-
const
|
|
412
|
-
r = r ||
|
|
413
|
-
const
|
|
414
|
-
return ((l = [], h) => l.map(h).reduce((p, j) => [...p, ...j], []))([
|
|
430
|
+
async getAll(e, t = {}, r) {
|
|
431
|
+
const o = t.per_page || 25, n = `/${e}`, i = n.split("/");
|
|
432
|
+
r = r || i[i.length - 1];
|
|
433
|
+
const a = await this.makeRequest(n, t, o, 1), c = Math.ceil(a.total / o);
|
|
434
|
+
return ((l = [], h) => l.map(h).reduce((p, j) => [...p, ...j], []))([a, ...await (async (l = [], h) => Promise.all(l.map(h)))(te(1, c), async (l) => this.makeRequest(n, t, o, l + 1))], (l) => Object.values(l.data[r]));
|
|
415
435
|
}
|
|
416
|
-
post(
|
|
417
|
-
let r = `/${
|
|
418
|
-
return this.throttle("post", r,
|
|
436
|
+
post(e, t) {
|
|
437
|
+
let r = `/${e}`;
|
|
438
|
+
return this.throttle("post", r, t);
|
|
419
439
|
}
|
|
420
|
-
put(
|
|
421
|
-
let r = `/${
|
|
422
|
-
return this.throttle("put", r,
|
|
440
|
+
put(e, t) {
|
|
441
|
+
let r = `/${e}`;
|
|
442
|
+
return this.throttle("put", r, t);
|
|
423
443
|
}
|
|
424
|
-
delete(
|
|
425
|
-
let r = `/${
|
|
426
|
-
return this.throttle("delete", r,
|
|
444
|
+
delete(e, t) {
|
|
445
|
+
let r = `/${e}`;
|
|
446
|
+
return this.throttle("delete", r, t);
|
|
427
447
|
}
|
|
428
|
-
getStories(
|
|
429
|
-
return this.get("cdn/stories",
|
|
448
|
+
getStories(e) {
|
|
449
|
+
return this.get("cdn/stories", e);
|
|
430
450
|
}
|
|
431
|
-
getStory(
|
|
432
|
-
return this.get(`cdn/stories/${
|
|
451
|
+
getStory(e, t) {
|
|
452
|
+
return this.get(`cdn/stories/${e}`, t);
|
|
433
453
|
}
|
|
434
|
-
setToken(
|
|
435
|
-
this.accessToken =
|
|
454
|
+
setToken(e) {
|
|
455
|
+
this.accessToken = e;
|
|
436
456
|
}
|
|
437
457
|
getToken() {
|
|
438
458
|
return this.accessToken;
|
|
439
459
|
}
|
|
440
|
-
_cleanCopy(
|
|
441
|
-
return JSON.parse(JSON.stringify(
|
|
460
|
+
_cleanCopy(e) {
|
|
461
|
+
return JSON.parse(JSON.stringify(e));
|
|
442
462
|
}
|
|
443
|
-
_insertLinks(
|
|
444
|
-
const r = t
|
|
463
|
+
_insertLinks(e, t) {
|
|
464
|
+
const r = e[t];
|
|
445
465
|
r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[r.id] ? r.story = this._cleanCopy(this.links[r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[r.uuid] && (r.story = this._cleanCopy(this.links[r.uuid]));
|
|
446
466
|
}
|
|
447
|
-
_insertRelations(
|
|
448
|
-
if (r.indexOf(
|
|
449
|
-
if (typeof t
|
|
450
|
-
this.relations[t
|
|
451
|
-
else if (t
|
|
452
|
-
let
|
|
453
|
-
t
|
|
454
|
-
this.relations[
|
|
455
|
-
}), t
|
|
467
|
+
_insertRelations(e, t, r) {
|
|
468
|
+
if (r.indexOf(e.component + "." + t) > -1) {
|
|
469
|
+
if (typeof e[t] == "string")
|
|
470
|
+
this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
|
|
471
|
+
else if (e[t].constructor === Array) {
|
|
472
|
+
let o = [];
|
|
473
|
+
e[t].forEach((n) => {
|
|
474
|
+
this.relations[n] && o.push(this._cleanCopy(this.relations[n]));
|
|
475
|
+
}), e[t] = o;
|
|
456
476
|
}
|
|
457
477
|
}
|
|
458
478
|
}
|
|
459
|
-
_insertAssetsRelations(
|
|
460
|
-
|
|
461
|
-
|
|
479
|
+
_insertAssetsRelations(e, t) {
|
|
480
|
+
t.forEach((r) => {
|
|
481
|
+
e.id === r.id && (e.original = r, e.original.filename = e.filename, e.original.filename = e.original.filename.includes("https://s3.amazonaws.com/") ? e.original.filename : e.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e.original.s3_filename);
|
|
462
482
|
});
|
|
463
483
|
}
|
|
464
|
-
iterateTree(
|
|
465
|
-
let r = (
|
|
466
|
-
if (
|
|
467
|
-
if (
|
|
468
|
-
for (let
|
|
469
|
-
r(
|
|
470
|
-
else if (
|
|
471
|
-
if (
|
|
484
|
+
iterateTree(e, t) {
|
|
485
|
+
let r = (o) => {
|
|
486
|
+
if (o != null) {
|
|
487
|
+
if (o.constructor === Array)
|
|
488
|
+
for (let n = 0; n < o.length; n++)
|
|
489
|
+
r(o[n]);
|
|
490
|
+
else if (o.constructor === Object) {
|
|
491
|
+
if (o._stopResolving)
|
|
472
492
|
return;
|
|
473
|
-
for (let
|
|
474
|
-
|
|
493
|
+
for (let n in o)
|
|
494
|
+
o.component && o._uid || o.type === "link" ? (this._insertRelations(o, n, t), this._insertLinks(o, n)) : "id" in o && o.fieldtype === "asset" && this._insertAssetsRelations(o, t), r(o[n]);
|
|
475
495
|
}
|
|
476
496
|
}
|
|
477
497
|
};
|
|
478
|
-
r(
|
|
498
|
+
r(e.content);
|
|
479
499
|
}
|
|
480
|
-
async resolveLinks(
|
|
500
|
+
async resolveLinks(e, t) {
|
|
481
501
|
let r = [];
|
|
482
|
-
if (
|
|
483
|
-
const
|
|
484
|
-
let
|
|
485
|
-
const
|
|
486
|
-
for (let
|
|
487
|
-
const c = Math.min(
|
|
488
|
-
|
|
502
|
+
if (e.link_uuids) {
|
|
503
|
+
const o = e.link_uuids.length;
|
|
504
|
+
let n = [];
|
|
505
|
+
const i = 50;
|
|
506
|
+
for (let a = 0; a < o; a += i) {
|
|
507
|
+
const c = Math.min(o, a + i);
|
|
508
|
+
n.push(e.link_uuids.slice(a, c));
|
|
489
509
|
}
|
|
490
|
-
for (let
|
|
491
|
-
(await this.getStories({ per_page:
|
|
510
|
+
for (let a = 0; a < n.length; a++)
|
|
511
|
+
(await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
|
|
492
512
|
r.push(c);
|
|
493
513
|
});
|
|
494
514
|
} else
|
|
495
|
-
r =
|
|
496
|
-
r.forEach((
|
|
497
|
-
this.links[
|
|
515
|
+
r = e.links;
|
|
516
|
+
r.forEach((o) => {
|
|
517
|
+
this.links[o.uuid] = g(u({}, o), { _stopResolving: !0 });
|
|
498
518
|
});
|
|
499
519
|
}
|
|
500
|
-
async resolveRelations(
|
|
520
|
+
async resolveRelations(e, t) {
|
|
501
521
|
let r = [];
|
|
502
|
-
if (
|
|
503
|
-
const
|
|
504
|
-
let
|
|
505
|
-
const
|
|
506
|
-
for (let
|
|
507
|
-
const c = Math.min(
|
|
508
|
-
|
|
522
|
+
if (e.rel_uuids) {
|
|
523
|
+
const o = e.rel_uuids.length;
|
|
524
|
+
let n = [];
|
|
525
|
+
const i = 50;
|
|
526
|
+
for (let a = 0; a < o; a += i) {
|
|
527
|
+
const c = Math.min(o, a + i);
|
|
528
|
+
n.push(e.rel_uuids.slice(a, c));
|
|
509
529
|
}
|
|
510
|
-
for (let
|
|
511
|
-
(await this.getStories({ per_page:
|
|
530
|
+
for (let a = 0; a < n.length; a++)
|
|
531
|
+
(await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
|
|
512
532
|
r.push(c);
|
|
513
533
|
});
|
|
514
534
|
} else
|
|
515
|
-
r =
|
|
516
|
-
r.forEach((
|
|
517
|
-
this.relations[
|
|
535
|
+
r = e.rels;
|
|
536
|
+
r.forEach((o) => {
|
|
537
|
+
this.relations[o.uuid] = g(u({}, o), { _stopResolving: !0 });
|
|
518
538
|
});
|
|
519
539
|
}
|
|
520
|
-
async resolveStories(
|
|
540
|
+
async resolveStories(e, t) {
|
|
521
541
|
let r = [];
|
|
522
|
-
if (
|
|
523
|
-
for (const
|
|
524
|
-
this.iterateTree(this.relations[
|
|
525
|
-
|
|
526
|
-
this.iterateTree(
|
|
542
|
+
if (t.resolve_relations !== void 0 && t.resolve_relations.length > 0 && (e.rels || e.rel_uuids) && (r = t.resolve_relations.split(","), await this.resolveRelations(e, t)), ["1", "story", "url"].indexOf(t.resolve_links) > -1 && (e.links || e.link_uuids) && await this.resolveLinks(e, t), this.resolveNestedRelations)
|
|
543
|
+
for (const o in this.relations)
|
|
544
|
+
this.iterateTree(this.relations[o], r);
|
|
545
|
+
e.story ? this.iterateTree(e.story, r) : e.stories.forEach((o) => {
|
|
546
|
+
this.iterateTree(o, r);
|
|
527
547
|
});
|
|
528
548
|
}
|
|
529
|
-
resolveAssetsRelations(
|
|
530
|
-
const { assets:
|
|
549
|
+
resolveAssetsRelations(e) {
|
|
550
|
+
const { assets: t, stories: r, story: o } = e;
|
|
531
551
|
if (r)
|
|
532
|
-
for (const
|
|
533
|
-
this.iterateTree(
|
|
552
|
+
for (const n of r)
|
|
553
|
+
this.iterateTree(n, t);
|
|
534
554
|
else {
|
|
535
|
-
if (!
|
|
536
|
-
return
|
|
537
|
-
this.iterateTree(
|
|
555
|
+
if (!o)
|
|
556
|
+
return e;
|
|
557
|
+
this.iterateTree(o, t);
|
|
538
558
|
}
|
|
539
559
|
}
|
|
540
|
-
cacheResponse(
|
|
541
|
-
return r === void 0 && (r = 0), new Promise(async (
|
|
542
|
-
let
|
|
543
|
-
if (this.cache.clear === "auto" &&
|
|
544
|
-
const l = await
|
|
560
|
+
cacheResponse(e, t, r) {
|
|
561
|
+
return r === void 0 && (r = 0), new Promise(async (o, n) => {
|
|
562
|
+
let i = y({ url: e, params: t }), a = this.cacheProvider();
|
|
563
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
564
|
+
const l = await a.get(i);
|
|
545
565
|
if (l)
|
|
546
|
-
return
|
|
566
|
+
return o(l);
|
|
547
567
|
}
|
|
548
568
|
try {
|
|
549
|
-
let l = await this.throttle("get",
|
|
569
|
+
let l = await this.throttle("get", e, { params: t, paramsSerializer: (p) => y(p) }), h = { data: l.data, headers: l.headers };
|
|
550
570
|
if (h.data.assets && h.data.assets.length && this.resolveAssetsRelations(h.data), l.headers["per-page"] && (h = Object.assign({}, h, { perPage: parseInt(l.headers["per-page"]), total: parseInt(l.headers.total) })), l.status != 200)
|
|
551
|
-
return
|
|
552
|
-
(h.data.story || h.data.stories) && await this.resolveStories(h.data,
|
|
571
|
+
return n(l);
|
|
572
|
+
(h.data.story || h.data.stories) && await this.resolveStories(h.data, t), t.version === "published" && e != "/cdn/spaces/me" && a.set(i, h), h.data.cv && (t.version == "draft" && d[t.token] != h.data.cv && this.flushCache(), d[t.token] = h.data.cv), o(h);
|
|
553
573
|
} catch (l) {
|
|
554
574
|
if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
|
|
555
|
-
return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(
|
|
556
|
-
|
|
575
|
+
return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(e, t, r).then(o).catch(n);
|
|
576
|
+
n(l);
|
|
557
577
|
}
|
|
558
578
|
var c;
|
|
559
579
|
});
|
|
560
580
|
}
|
|
561
|
-
throttledRequest(
|
|
562
|
-
return this.client[
|
|
581
|
+
throttledRequest(e, t, r) {
|
|
582
|
+
return this.client[e](t, r);
|
|
563
583
|
}
|
|
564
584
|
cacheVersions() {
|
|
565
585
|
return d;
|
|
@@ -567,14 +587,14 @@ class D {
|
|
|
567
587
|
cacheVersion() {
|
|
568
588
|
return d[this.accessToken];
|
|
569
589
|
}
|
|
570
|
-
setCacheVersion(
|
|
571
|
-
this.accessToken && (d[this.accessToken] =
|
|
590
|
+
setCacheVersion(e) {
|
|
591
|
+
this.accessToken && (d[this.accessToken] = e);
|
|
572
592
|
}
|
|
573
593
|
cacheProvider() {
|
|
574
|
-
return this.cache.type === "memory" ? { get: (
|
|
575
|
-
|
|
594
|
+
return this.cache.type === "memory" ? { get: (e) => f[e], getAll: () => f, set(e, t) {
|
|
595
|
+
f[e] = t;
|
|
576
596
|
}, flush() {
|
|
577
|
-
|
|
597
|
+
f = {};
|
|
578
598
|
} } : { get() {
|
|
579
599
|
}, getAll() {
|
|
580
600
|
}, set() {
|
|
@@ -585,82 +605,91 @@ class D {
|
|
|
585
605
|
return await this.cacheProvider().flush(), this;
|
|
586
606
|
}
|
|
587
607
|
}
|
|
588
|
-
const
|
|
589
|
-
const { apiOptions:
|
|
590
|
-
if (!
|
|
608
|
+
const se = (s = {}) => {
|
|
609
|
+
const { apiOptions: e } = s;
|
|
610
|
+
if (!e.accessToken) {
|
|
591
611
|
console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");
|
|
592
612
|
return;
|
|
593
613
|
}
|
|
594
|
-
return { storyblokApi: new
|
|
614
|
+
return { storyblokApi: new re(e) };
|
|
595
615
|
};
|
|
596
|
-
var
|
|
597
|
-
if (typeof
|
|
616
|
+
var le = (s) => {
|
|
617
|
+
if (typeof s != "object" || typeof s._editable > "u")
|
|
598
618
|
return {};
|
|
599
|
-
const
|
|
619
|
+
const e = JSON.parse(s._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
600
620
|
return {
|
|
601
|
-
"data-blok-c": JSON.stringify(
|
|
602
|
-
"data-blok-uid":
|
|
621
|
+
"data-blok-c": JSON.stringify(e),
|
|
622
|
+
"data-blok-uid": e.id + "-" + e.uid
|
|
603
623
|
};
|
|
604
624
|
};
|
|
605
|
-
let
|
|
606
|
-
const
|
|
625
|
+
let m;
|
|
626
|
+
const I = "https://app.storyblok.com/f/storyblok-v2-latest.js", oe = (s = {}) => {
|
|
607
627
|
const {
|
|
608
|
-
bridge:
|
|
609
|
-
accessToken:
|
|
628
|
+
bridge: e,
|
|
629
|
+
accessToken: t,
|
|
610
630
|
use: r = [],
|
|
611
|
-
apiOptions:
|
|
612
|
-
richText:
|
|
613
|
-
} =
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
let
|
|
631
|
+
apiOptions: o = {},
|
|
632
|
+
richText: n = {}
|
|
633
|
+
} = s;
|
|
634
|
+
o.accessToken = o.accessToken || t;
|
|
635
|
+
const i = { bridge: e, apiOptions: o };
|
|
636
|
+
let a = {};
|
|
617
637
|
return r.forEach((c) => {
|
|
618
|
-
|
|
619
|
-
}),
|
|
620
|
-
},
|
|
621
|
-
|
|
638
|
+
a = u(u({}, a), c(i));
|
|
639
|
+
}), e !== !1 && S(I), m = new x(n.schema), n.resolver && P(m, n.resolver), a;
|
|
640
|
+
}, P = (s, e) => {
|
|
641
|
+
s.addNode("blok", (t) => {
|
|
622
642
|
let r = "";
|
|
623
|
-
return
|
|
624
|
-
r +=
|
|
643
|
+
return t.attrs.body.forEach((o) => {
|
|
644
|
+
r += e(o.component, o);
|
|
625
645
|
}), {
|
|
626
646
|
html: r
|
|
627
647
|
};
|
|
628
648
|
});
|
|
629
|
-
},
|
|
630
|
-
|
|
649
|
+
}, ne = (s, e, t) => {
|
|
650
|
+
let r = t || m;
|
|
651
|
+
if (!r) {
|
|
631
652
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
632
653
|
return;
|
|
633
654
|
}
|
|
634
|
-
|
|
635
|
-
return "";
|
|
636
|
-
if (!n)
|
|
637
|
-
return console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
655
|
+
return s === "" ? "" : s ? (e && (r = new x(e.schema), e.resolver && P(r, e.resolver)), r.render(s)) : (console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
638
656
|
|
|
639
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "";
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
use: t || [J],
|
|
647
|
-
apiOptions: { ...e }
|
|
657
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
658
|
+
}, ce = () => S(I);
|
|
659
|
+
function ae(s, e, t) {
|
|
660
|
+
const { storyblokApi: r } = oe({
|
|
661
|
+
accessToken: s,
|
|
662
|
+
use: e || [se],
|
|
663
|
+
apiOptions: { ...t }
|
|
648
664
|
});
|
|
649
665
|
globalThis.storyblokApiInstance = r;
|
|
650
666
|
}
|
|
651
|
-
function
|
|
667
|
+
function he() {
|
|
652
668
|
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
653
669
|
}
|
|
654
|
-
function
|
|
670
|
+
function ue(s, e) {
|
|
671
|
+
const t = globalThis.storyblokApiInstance.richTextResolver;
|
|
672
|
+
if (!t) {
|
|
673
|
+
console.error(
|
|
674
|
+
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
675
|
+
);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
return ne(s, e, t);
|
|
679
|
+
}
|
|
680
|
+
function de(s) {
|
|
655
681
|
return {
|
|
656
682
|
name: "@storyblok/astro",
|
|
657
683
|
hooks: {
|
|
658
|
-
"astro:config:setup": ({ injectScript:
|
|
659
|
-
|
|
684
|
+
"astro:config:setup": ({ injectScript: e, updateConfig: t }) => {
|
|
685
|
+
var o;
|
|
686
|
+
t({
|
|
660
687
|
vite: {
|
|
661
|
-
plugins: [
|
|
688
|
+
plugins: [z(s.components)]
|
|
662
689
|
}
|
|
663
|
-
}),
|
|
690
|
+
}), ae(s.accessToken, s.use, s.apiOptions), ((o = s.bridge) != null ? o : !0) && e(
|
|
691
|
+
"page",
|
|
692
|
+
`
|
|
664
693
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
665
694
|
loadStoryblokBridge().then(() => {
|
|
666
695
|
const { StoryblokBridge, location } = window;
|
|
@@ -672,15 +701,17 @@ function Z(n) {
|
|
|
672
701
|
}
|
|
673
702
|
});
|
|
674
703
|
});
|
|
675
|
-
`
|
|
704
|
+
`
|
|
705
|
+
);
|
|
676
706
|
}
|
|
677
707
|
}
|
|
678
708
|
};
|
|
679
709
|
}
|
|
680
710
|
export {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
711
|
+
W as RichTextSchema,
|
|
712
|
+
de as default,
|
|
713
|
+
ce as loadStoryblokBridge,
|
|
714
|
+
ue as renderRichText,
|
|
715
|
+
le as storyblokEditable,
|
|
716
|
+
he as useStoryblokApi
|
|
686
717
|
};
|