@storyblok/astro 6.0.2 → 6.1.0-alpha.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/dist/content-loader/storyblokLoader.d.ts +7 -0
- package/dist/index.d.ts +2 -1
- package/dist/storyblok-astro.es.js +887 -328
- package/dist/storyblok-astro.umd.js +12 -12
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const B = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
2
2
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
4
4
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -7,74 +7,74 @@ const A = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xml
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
11
|
-
let
|
|
12
|
-
for (let
|
|
13
|
-
const c = r[
|
|
14
|
-
|
|
10
|
+
</svg>`, D = /[\p{Lu}]/u, z = /[\p{Ll}]/u, C = /^[\p{Lu}](?![\p{Lu}])/gu, O = /([\p{Alpha}\p{N}_]|$)/u, _ = /[_.\- ]+/, H = new RegExp("^" + _.source), R = new RegExp(_.source + O.source, "gu"), A = new RegExp("\\d+" + O.source, "gu"), q = (r, e, t, s) => {
|
|
11
|
+
let o = !1, n = !1, i = !1, a = !1;
|
|
12
|
+
for (let l = 0; l < r.length; l++) {
|
|
13
|
+
const c = r[l];
|
|
14
|
+
a = l > 2 ? r[l - 3] === "-" : !0, o && D.test(c) ? (r = r.slice(0, l) + "-" + r.slice(l), o = !1, i = n, n = !0, l++) : n && i && z.test(c) && (!a || s) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), i = n, n = !1, o = !0) : (o = e(c) === c && t(c) !== c, i = n, n = t(c) === c && e(c) !== c);
|
|
15
15
|
}
|
|
16
16
|
return r;
|
|
17
|
-
},
|
|
18
|
-
function
|
|
17
|
+
}, V = (r, e) => (C.lastIndex = 0, r.replaceAll(C, (t) => e(t))), J = (r, e) => (R.lastIndex = 0, A.lastIndex = 0, r.replaceAll(A, (t, s, o) => ["_", "-"].includes(r.charAt(o + t.length)) ? t : e(t)).replaceAll(R, (t, s) => e(s)));
|
|
18
|
+
function W(r, e) {
|
|
19
19
|
if (!(typeof r == "string" || Array.isArray(r)))
|
|
20
20
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
21
|
-
if (
|
|
21
|
+
if (e = {
|
|
22
22
|
pascalCase: !1,
|
|
23
23
|
preserveConsecutiveUppercase: !1,
|
|
24
|
-
...
|
|
24
|
+
...e
|
|
25
25
|
}, Array.isArray(r) ? r = r.map((n) => n.trim()).filter((n) => n.length).join("-") : r = r.trim(), r.length === 0)
|
|
26
26
|
return "";
|
|
27
|
-
const
|
|
28
|
-
return r.length === 1 ?
|
|
27
|
+
const t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
|
|
28
|
+
return r.length === 1 ? _.test(r) ? "" : e.pascalCase ? s(r) : t(r) : (r !== t(r) && (r = q(r, t, s, e.preserveConsecutiveUppercase)), r = r.replace(H, ""), r = e.preserveConsecutiveUppercase ? V(r, t) : t(r), e.pascalCase && (r = s(r.charAt(0)) + r.slice(1)), J(r, s));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function I(r) {
|
|
31
|
+
return W(r);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
const
|
|
33
|
+
function K(r, e = {}, t, s) {
|
|
34
|
+
const o = "virtual:storyblok-components", n = `\0${o}`;
|
|
35
35
|
return {
|
|
36
36
|
name: "vite-plugin-storyblok-components",
|
|
37
|
-
async resolveId(
|
|
38
|
-
if (
|
|
37
|
+
async resolveId(i) {
|
|
38
|
+
if (i === o)
|
|
39
39
|
return n;
|
|
40
40
|
},
|
|
41
|
-
async load(
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
for await (const [
|
|
45
|
-
const
|
|
46
|
-
`/${r}/${
|
|
41
|
+
async load(i) {
|
|
42
|
+
if (i === n) {
|
|
43
|
+
const a = [], l = [];
|
|
44
|
+
for await (const [h, u] of Object.entries(e)) {
|
|
45
|
+
const g = await this.resolve(
|
|
46
|
+
`/${r}/${u}.astro`
|
|
47
47
|
);
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
else if (
|
|
51
|
-
|
|
48
|
+
if (g)
|
|
49
|
+
a.push(`import ${I(h)} from "${g.id}"`);
|
|
50
|
+
else if (t)
|
|
51
|
+
l.push(h);
|
|
52
52
|
else
|
|
53
53
|
throw new Error(
|
|
54
|
-
`Component could not be found for blok "${
|
|
54
|
+
`Component could not be found for blok "${h}"! Does "${`/${r}/${u}`}.astro" exist?`
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
let c = "";
|
|
58
|
-
if (
|
|
59
|
-
if (c = ",FallbackComponent",
|
|
60
|
-
const
|
|
61
|
-
`/${r}/${
|
|
58
|
+
if (t)
|
|
59
|
+
if (c = ",FallbackComponent", s) {
|
|
60
|
+
const h = await this.resolve(
|
|
61
|
+
`/${r}/${s}.astro`
|
|
62
62
|
);
|
|
63
|
-
if (!
|
|
63
|
+
if (!h)
|
|
64
64
|
throw new Error(
|
|
65
|
-
`Custom fallback component could not be found. Does "${`/${r}/${
|
|
65
|
+
`Custom fallback component could not be found. Does "${`/${r}/${s}`}.astro" exist?`
|
|
66
66
|
);
|
|
67
|
-
|
|
68
|
-
`import FallbackComponent from "${
|
|
67
|
+
a.push(
|
|
68
|
+
`import FallbackComponent from "${h.id}"`
|
|
69
69
|
);
|
|
70
70
|
} else
|
|
71
|
-
|
|
71
|
+
a.push(
|
|
72
72
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
|
|
73
73
|
);
|
|
74
|
-
if (Object.values(
|
|
75
|
-
return `${
|
|
76
|
-
if (
|
|
77
|
-
return `${
|
|
74
|
+
if (Object.values(e).length)
|
|
75
|
+
return `${a.join(";")};export default {${Object.keys(e).filter((h) => !l.includes(h)).map((h) => I(h)).join(",")}${c}}`;
|
|
76
|
+
if (t)
|
|
77
|
+
return `${a[0]}; export default {${c.replace(",", "")}}`;
|
|
78
78
|
throw new Error(
|
|
79
79
|
`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
80
80
|
Please register your components or enable the fallback component.
|
|
@@ -84,76 +84,119 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
87
|
+
function Z(r, e, t) {
|
|
88
|
+
const s = "virtual:storyblok-init", o = `\0${s}`;
|
|
89
89
|
return {
|
|
90
90
|
name: "vite-plugin-storyblok-init",
|
|
91
91
|
async resolveId(n) {
|
|
92
|
-
if (n ===
|
|
93
|
-
return
|
|
92
|
+
if (n === s)
|
|
93
|
+
return o;
|
|
94
94
|
},
|
|
95
95
|
async load(n) {
|
|
96
|
-
if (n ===
|
|
96
|
+
if (n === o)
|
|
97
97
|
return `
|
|
98
98
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
99
99
|
const { storyblokApi } = storyblokInit({
|
|
100
100
|
accessToken: "${r}",
|
|
101
|
-
use: ${
|
|
102
|
-
apiOptions: ${JSON.stringify(
|
|
101
|
+
use: ${e ? "[]" : "[apiPlugin]"},
|
|
102
|
+
apiOptions: ${JSON.stringify(t)},
|
|
103
103
|
});
|
|
104
104
|
export const storyblokApiInstance = storyblokApi;
|
|
105
105
|
`;
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
const
|
|
109
|
+
function G(r) {
|
|
110
|
+
const e = "virtual:storyblok-options", t = `\0${e}`;
|
|
111
111
|
return {
|
|
112
112
|
name: "vite-plugin-storyblok-options",
|
|
113
|
-
async resolveId(
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
113
|
+
async resolveId(s) {
|
|
114
|
+
if (s === e)
|
|
115
|
+
return t;
|
|
116
116
|
},
|
|
117
|
-
async load(
|
|
118
|
-
if (
|
|
117
|
+
async load(s) {
|
|
118
|
+
if (s === t)
|
|
119
119
|
return `export default ${JSON.stringify(r)}`;
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
let
|
|
124
|
-
const
|
|
125
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
123
|
+
let L = !1;
|
|
124
|
+
const E = [], N = (r) => new Promise((e, t) => {
|
|
125
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
|
|
126
126
|
if (window.location === window.parent.location) {
|
|
127
127
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
L ? o() : E.push(o);
|
|
131
131
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
132
132
|
return;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
|
133
|
+
const s = document.createElement("script");
|
|
134
|
+
s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (o) => t(o), s.onload = (o) => {
|
|
135
|
+
E.forEach((n) => n()), L = !0, e(o);
|
|
136
|
+
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
137
137
|
});
|
|
138
|
-
var
|
|
139
|
-
|
|
138
|
+
var Y = Object.defineProperty, Q = (r, e, t) => e in r ? Y(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e, t) => Q(r, typeof e != "symbol" ? e + "" : e, t);
|
|
139
|
+
class X extends Error {
|
|
140
|
+
constructor(e) {
|
|
141
|
+
super(e), this.name = "AbortError";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function ee(r, e, t) {
|
|
145
|
+
if (!Number.isFinite(e))
|
|
146
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
147
|
+
if (!Number.isFinite(t))
|
|
148
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
149
|
+
const s = [];
|
|
150
|
+
let o = [], n = 0, i = !1;
|
|
151
|
+
const a = async () => {
|
|
152
|
+
n++;
|
|
153
|
+
const c = s.shift();
|
|
154
|
+
if (c)
|
|
155
|
+
try {
|
|
156
|
+
const u = await r(...c.args);
|
|
157
|
+
c.resolve(u);
|
|
158
|
+
} catch (u) {
|
|
159
|
+
c.reject(u);
|
|
160
|
+
}
|
|
161
|
+
const h = setTimeout(() => {
|
|
162
|
+
n--, s.length > 0 && a(), o = o.filter((u) => u !== h);
|
|
163
|
+
}, t);
|
|
164
|
+
o.includes(h) || o.push(h);
|
|
165
|
+
}, l = (...c) => i ? Promise.reject(
|
|
166
|
+
new Error(
|
|
167
|
+
"Throttled function is already aborted and not accepting new promises"
|
|
168
|
+
)
|
|
169
|
+
) : new Promise((h, u) => {
|
|
170
|
+
s.push({
|
|
171
|
+
resolve: h,
|
|
172
|
+
reject: u,
|
|
173
|
+
args: c
|
|
174
|
+
}), n < e && a();
|
|
175
|
+
});
|
|
176
|
+
return l.abort = () => {
|
|
177
|
+
i = !0, o.forEach(clearTimeout), o = [], s.forEach(
|
|
178
|
+
(c) => c.reject(() => new X("Throttle function aborted"))
|
|
179
|
+
), s.length = 0;
|
|
180
|
+
}, l;
|
|
181
|
+
}
|
|
182
|
+
let v = class {
|
|
140
183
|
constructor() {
|
|
141
|
-
|
|
184
|
+
d(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), d(this, "getOptionsPage", (r, e = 25, t = 1) => ({
|
|
142
185
|
...r,
|
|
143
|
-
per_page:
|
|
144
|
-
page:
|
|
145
|
-
})),
|
|
146
|
-
const
|
|
147
|
-
return this.arrayFrom(
|
|
148
|
-
}),
|
|
149
|
-
const
|
|
186
|
+
per_page: e,
|
|
187
|
+
page: t
|
|
188
|
+
})), d(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), d(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), d(this, "range", (r = 0, e = r) => {
|
|
189
|
+
const t = Math.abs(e - r) || 0, s = r < e ? 1 : -1;
|
|
190
|
+
return this.arrayFrom(t, (o, n) => n * s + r);
|
|
191
|
+
}), d(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), d(this, "flatMap", (r = [], e) => r.map(e).reduce((t, s) => [...t, ...s], [])), d(this, "escapeHTML", function(r) {
|
|
192
|
+
const e = {
|
|
150
193
|
"&": "&",
|
|
151
194
|
"<": "<",
|
|
152
195
|
">": ">",
|
|
153
196
|
'"': """,
|
|
154
197
|
"'": "'"
|
|
155
|
-
},
|
|
156
|
-
return r &&
|
|
198
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
199
|
+
return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
|
|
157
200
|
});
|
|
158
201
|
}
|
|
159
202
|
/**
|
|
@@ -163,20 +206,20 @@ let U = class {
|
|
|
163
206
|
* @param {boolean} isArray
|
|
164
207
|
* @return {string} Stringified object
|
|
165
208
|
*/
|
|
166
|
-
stringify(r,
|
|
167
|
-
const
|
|
168
|
-
for (const
|
|
169
|
-
if (!Object.prototype.hasOwnProperty.call(r,
|
|
209
|
+
stringify(r, e, t) {
|
|
210
|
+
const s = [];
|
|
211
|
+
for (const o in r) {
|
|
212
|
+
if (!Object.prototype.hasOwnProperty.call(r, o))
|
|
170
213
|
continue;
|
|
171
|
-
const n = r[
|
|
172
|
-
let
|
|
173
|
-
typeof n == "object" ?
|
|
214
|
+
const n = r[o], i = t ? "" : encodeURIComponent(o);
|
|
215
|
+
let a;
|
|
216
|
+
typeof n == "object" ? a = this.stringify(
|
|
174
217
|
n,
|
|
175
|
-
|
|
218
|
+
e ? e + encodeURIComponent(`[${i}]`) : i,
|
|
176
219
|
Array.isArray(n)
|
|
177
|
-
) :
|
|
220
|
+
) : a = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(n)}`, s.push(a);
|
|
178
221
|
}
|
|
179
|
-
return
|
|
222
|
+
return s.join("&");
|
|
180
223
|
}
|
|
181
224
|
/**
|
|
182
225
|
* @method getRegionURL
|
|
@@ -184,35 +227,35 @@ let U = class {
|
|
|
184
227
|
* @return {string} The base URL of the region
|
|
185
228
|
*/
|
|
186
229
|
getRegionURL(r) {
|
|
187
|
-
const
|
|
230
|
+
const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
|
188
231
|
switch (r) {
|
|
189
232
|
case "us":
|
|
190
|
-
return
|
|
233
|
+
return t;
|
|
191
234
|
case "cn":
|
|
192
|
-
return o;
|
|
193
|
-
case "ap":
|
|
194
235
|
return s;
|
|
236
|
+
case "ap":
|
|
237
|
+
return o;
|
|
195
238
|
case "ca":
|
|
196
239
|
return n;
|
|
197
240
|
default:
|
|
198
|
-
return
|
|
241
|
+
return e;
|
|
199
242
|
}
|
|
200
243
|
}
|
|
201
244
|
};
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
for (const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
return
|
|
209
|
-
},
|
|
245
|
+
const te = function(r, e) {
|
|
246
|
+
const t = {};
|
|
247
|
+
for (const s in r) {
|
|
248
|
+
const o = r[s];
|
|
249
|
+
e.includes(s) && o !== null && (t[s] = o);
|
|
250
|
+
}
|
|
251
|
+
return t;
|
|
252
|
+
}, se = (r) => r === "email", re = () => ({
|
|
210
253
|
singleTag: "hr"
|
|
211
|
-
}),
|
|
254
|
+
}), oe = () => ({
|
|
212
255
|
tag: "blockquote"
|
|
213
|
-
}),
|
|
256
|
+
}), ne = () => ({
|
|
214
257
|
tag: "ul"
|
|
215
|
-
}),
|
|
258
|
+
}), ie = (r) => ({
|
|
216
259
|
tag: [
|
|
217
260
|
"pre",
|
|
218
261
|
{
|
|
@@ -220,24 +263,24 @@ const q = function(r, t) {
|
|
|
220
263
|
attrs: r.attrs
|
|
221
264
|
}
|
|
222
265
|
]
|
|
223
|
-
}),
|
|
266
|
+
}), ae = () => ({
|
|
224
267
|
singleTag: "br"
|
|
225
|
-
}),
|
|
268
|
+
}), le = (r) => ({
|
|
226
269
|
tag: `h${r.attrs.level}`
|
|
227
|
-
}),
|
|
270
|
+
}), ce = (r) => ({
|
|
228
271
|
singleTag: [
|
|
229
272
|
{
|
|
230
273
|
tag: "img",
|
|
231
|
-
attrs:
|
|
274
|
+
attrs: te(r.attrs, ["src", "alt", "title"])
|
|
232
275
|
}
|
|
233
276
|
]
|
|
234
|
-
}),
|
|
277
|
+
}), he = () => ({
|
|
235
278
|
tag: "li"
|
|
236
|
-
}),
|
|
279
|
+
}), ue = () => ({
|
|
237
280
|
tag: "ol"
|
|
238
|
-
}),
|
|
281
|
+
}), de = () => ({
|
|
239
282
|
tag: "p"
|
|
240
|
-
}),
|
|
283
|
+
}), pe = (r) => ({
|
|
241
284
|
tag: [
|
|
242
285
|
{
|
|
243
286
|
tag: "span",
|
|
@@ -248,58 +291,58 @@ const q = function(r, t) {
|
|
|
248
291
|
}
|
|
249
292
|
}
|
|
250
293
|
]
|
|
251
|
-
}),
|
|
294
|
+
}), ge = () => ({
|
|
252
295
|
tag: "b"
|
|
253
|
-
}),
|
|
296
|
+
}), fe = () => ({
|
|
254
297
|
tag: "s"
|
|
255
|
-
}),
|
|
298
|
+
}), ye = () => ({
|
|
256
299
|
tag: "u"
|
|
257
|
-
}),
|
|
300
|
+
}), me = () => ({
|
|
258
301
|
tag: "strong"
|
|
259
|
-
}),
|
|
302
|
+
}), be = () => ({
|
|
260
303
|
tag: "code"
|
|
261
|
-
}),
|
|
304
|
+
}), ke = () => ({
|
|
262
305
|
tag: "i"
|
|
263
|
-
}),
|
|
306
|
+
}), ve = (r) => {
|
|
264
307
|
if (!r.attrs)
|
|
265
308
|
return {
|
|
266
309
|
tag: ""
|
|
267
310
|
};
|
|
268
|
-
const
|
|
269
|
-
if (delete
|
|
270
|
-
for (const
|
|
271
|
-
|
|
272
|
-
delete
|
|
311
|
+
const e = new v().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
|
|
312
|
+
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), se(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
313
|
+
for (const o in t.custom)
|
|
314
|
+
t[o] = t.custom[o];
|
|
315
|
+
delete t.custom;
|
|
273
316
|
}
|
|
274
317
|
return {
|
|
275
318
|
tag: [
|
|
276
319
|
{
|
|
277
320
|
tag: "a",
|
|
278
|
-
attrs:
|
|
321
|
+
attrs: t
|
|
279
322
|
}
|
|
280
323
|
]
|
|
281
324
|
};
|
|
282
|
-
},
|
|
325
|
+
}, we = (r) => ({
|
|
283
326
|
tag: [
|
|
284
327
|
{
|
|
285
328
|
tag: "span",
|
|
286
329
|
attrs: r.attrs
|
|
287
330
|
}
|
|
288
331
|
]
|
|
289
|
-
}),
|
|
332
|
+
}), $e = () => ({
|
|
290
333
|
tag: "sub"
|
|
291
|
-
}),
|
|
334
|
+
}), Te = () => ({
|
|
292
335
|
tag: "sup"
|
|
293
|
-
}),
|
|
336
|
+
}), Se = (r) => ({
|
|
294
337
|
tag: [
|
|
295
338
|
{
|
|
296
339
|
tag: "span",
|
|
297
340
|
attrs: r.attrs
|
|
298
341
|
}
|
|
299
342
|
]
|
|
300
|
-
}),
|
|
301
|
-
var
|
|
302
|
-
return (
|
|
343
|
+
}), _e = (r) => {
|
|
344
|
+
var e;
|
|
345
|
+
return (e = r.attrs) != null && e.color ? {
|
|
303
346
|
tag: [
|
|
304
347
|
{
|
|
305
348
|
tag: "span",
|
|
@@ -311,9 +354,9 @@ const q = function(r, t) {
|
|
|
311
354
|
} : {
|
|
312
355
|
tag: ""
|
|
313
356
|
};
|
|
314
|
-
},
|
|
315
|
-
var
|
|
316
|
-
return (
|
|
357
|
+
}, Ce = (r) => {
|
|
358
|
+
var e;
|
|
359
|
+
return (e = r.attrs) != null && e.color ? {
|
|
317
360
|
tag: [
|
|
318
361
|
{
|
|
319
362
|
tag: "span",
|
|
@@ -325,64 +368,64 @@ const q = function(r, t) {
|
|
|
325
368
|
} : {
|
|
326
369
|
tag: ""
|
|
327
370
|
};
|
|
328
|
-
},
|
|
371
|
+
}, Re = {
|
|
329
372
|
nodes: {
|
|
330
|
-
horizontal_rule:
|
|
331
|
-
blockquote:
|
|
332
|
-
bullet_list:
|
|
333
|
-
code_block:
|
|
334
|
-
hard_break:
|
|
335
|
-
heading:
|
|
336
|
-
image:
|
|
337
|
-
list_item:
|
|
338
|
-
ordered_list:
|
|
339
|
-
paragraph:
|
|
340
|
-
emoji:
|
|
373
|
+
horizontal_rule: re,
|
|
374
|
+
blockquote: oe,
|
|
375
|
+
bullet_list: ne,
|
|
376
|
+
code_block: ie,
|
|
377
|
+
hard_break: ae,
|
|
378
|
+
heading: le,
|
|
379
|
+
image: ce,
|
|
380
|
+
list_item: he,
|
|
381
|
+
ordered_list: ue,
|
|
382
|
+
paragraph: de,
|
|
383
|
+
emoji: pe
|
|
341
384
|
},
|
|
342
385
|
marks: {
|
|
343
|
-
bold:
|
|
344
|
-
strike:
|
|
345
|
-
underline:
|
|
346
|
-
strong:
|
|
347
|
-
code:
|
|
348
|
-
italic:
|
|
349
|
-
link:
|
|
350
|
-
styled:
|
|
351
|
-
subscript:
|
|
352
|
-
superscript:
|
|
353
|
-
anchor:
|
|
354
|
-
highlight:
|
|
355
|
-
textStyle:
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
const
|
|
386
|
+
bold: ge,
|
|
387
|
+
strike: fe,
|
|
388
|
+
underline: ye,
|
|
389
|
+
strong: me,
|
|
390
|
+
code: be,
|
|
391
|
+
italic: ke,
|
|
392
|
+
link: ve,
|
|
393
|
+
styled: we,
|
|
394
|
+
subscript: $e,
|
|
395
|
+
superscript: Te,
|
|
396
|
+
anchor: Se,
|
|
397
|
+
highlight: _e,
|
|
398
|
+
textStyle: Ce
|
|
399
|
+
}
|
|
400
|
+
}, Ae = function(r) {
|
|
401
|
+
const e = {
|
|
359
402
|
"&": "&",
|
|
360
403
|
"<": "<",
|
|
361
404
|
">": ">",
|
|
362
405
|
'"': """,
|
|
363
406
|
"'": "'"
|
|
364
|
-
},
|
|
365
|
-
return r &&
|
|
407
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
408
|
+
return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
|
|
366
409
|
};
|
|
367
|
-
let
|
|
368
|
-
class
|
|
369
|
-
constructor(
|
|
370
|
-
|
|
410
|
+
let x = !1;
|
|
411
|
+
class w {
|
|
412
|
+
constructor(e) {
|
|
413
|
+
d(this, "marks"), d(this, "nodes"), e || (e = Re), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
371
414
|
}
|
|
372
|
-
addNode(
|
|
373
|
-
this.nodes[
|
|
415
|
+
addNode(e, t) {
|
|
416
|
+
this.nodes[e] = t;
|
|
374
417
|
}
|
|
375
|
-
addMark(
|
|
376
|
-
this.marks[
|
|
418
|
+
addMark(e, t) {
|
|
419
|
+
this.marks[e] = t;
|
|
377
420
|
}
|
|
378
|
-
render(
|
|
379
|
-
if (!
|
|
421
|
+
render(e, t = { optimizeImages: !1 }, s = !0) {
|
|
422
|
+
if (!x && s && (console.warn(
|
|
380
423
|
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
|
|
381
|
-
),
|
|
382
|
-
let
|
|
383
|
-
return
|
|
384
|
-
|
|
385
|
-
}),
|
|
424
|
+
), x = !0), e && e.content && Array.isArray(e.content)) {
|
|
425
|
+
let o = "";
|
|
426
|
+
return e.content.forEach((n) => {
|
|
427
|
+
o += this.renderNode(n);
|
|
428
|
+
}), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
|
|
386
429
|
}
|
|
387
430
|
return console.warn(
|
|
388
431
|
`The render method must receive an Object with a "content" field.
|
|
@@ -411,212 +454,691 @@ class be {
|
|
|
411
454
|
}`
|
|
412
455
|
), "";
|
|
413
456
|
}
|
|
414
|
-
optimizeImages(
|
|
415
|
-
let
|
|
416
|
-
typeof
|
|
417
|
-
const
|
|
418
|
-
return
|
|
457
|
+
optimizeImages(e, t) {
|
|
458
|
+
let s = 0, o = 0, n = "", i = "";
|
|
459
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, o = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = `/filters${i}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
|
|
460
|
+
const a = s > 0 || o > 0 || i.length > 0 ? `${s}x${o}${i}` : "";
|
|
461
|
+
return e = e.replace(
|
|
419
462
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
420
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
421
|
-
), typeof
|
|
422
|
-
var c,
|
|
423
|
-
const
|
|
463
|
+
`a.storyblok.com/f/$1/$2.$3/m/${a}`
|
|
464
|
+
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
|
|
465
|
+
var c, h;
|
|
466
|
+
const u = l.match(
|
|
424
467
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
425
468
|
);
|
|
426
|
-
if (
|
|
427
|
-
const
|
|
428
|
-
srcset: (c =
|
|
429
|
-
if (typeof
|
|
430
|
-
return `//${
|
|
431
|
-
if (typeof
|
|
432
|
-
let
|
|
433
|
-
return typeof
|
|
469
|
+
if (u && u.length > 0) {
|
|
470
|
+
const g = {
|
|
471
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((p) => {
|
|
472
|
+
if (typeof p == "number")
|
|
473
|
+
return `//${u}/m/${p}x0${i} ${p}w`;
|
|
474
|
+
if (typeof p == "object" && p.length === 2) {
|
|
475
|
+
let m = 0, b = 0;
|
|
476
|
+
return typeof p[0] == "number" && (m = p[0]), typeof p[1] == "number" && (b = p[1]), `//${u}/m/${m}x${b}${i} ${m}w`;
|
|
434
477
|
}
|
|
435
478
|
return "";
|
|
436
479
|
}).join(", "),
|
|
437
|
-
sizes: (
|
|
480
|
+
sizes: (h = t.sizes) == null ? void 0 : h.map((p) => p).join(", ")
|
|
438
481
|
};
|
|
439
|
-
let
|
|
440
|
-
return
|
|
482
|
+
let f = "";
|
|
483
|
+
return g.srcset && (f += `srcset="${g.srcset}" `), g.sizes && (f += `sizes="${g.sizes}" `), l.replace(/<img/g, `<img ${f.trim()}`);
|
|
441
484
|
}
|
|
442
|
-
return
|
|
443
|
-
})),
|
|
444
|
-
}
|
|
445
|
-
renderNode(
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
const n = this.getMatchingMark(
|
|
449
|
-
n && n.tag !== "" &&
|
|
485
|
+
return l;
|
|
486
|
+
})), e;
|
|
487
|
+
}
|
|
488
|
+
renderNode(e) {
|
|
489
|
+
const t = [];
|
|
490
|
+
e.marks && e.marks.forEach((o) => {
|
|
491
|
+
const n = this.getMatchingMark(o);
|
|
492
|
+
n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
|
|
450
493
|
});
|
|
451
|
-
const
|
|
452
|
-
return
|
|
453
|
-
|
|
454
|
-
}) :
|
|
455
|
-
const n = this.getMatchingMark(
|
|
456
|
-
n && n.tag !== "" &&
|
|
457
|
-
}),
|
|
458
|
-
}
|
|
459
|
-
renderTag(
|
|
460
|
-
return
|
|
461
|
-
if (
|
|
462
|
-
return `<${
|
|
494
|
+
const s = this.getMatchingNode(e);
|
|
495
|
+
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((o) => {
|
|
496
|
+
t.push(this.renderNode(o));
|
|
497
|
+
}) : e.text ? t.push(Ae(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
|
|
498
|
+
const n = this.getMatchingMark(o);
|
|
499
|
+
n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
|
|
500
|
+
}), t.join("");
|
|
501
|
+
}
|
|
502
|
+
renderTag(e, t) {
|
|
503
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
|
|
504
|
+
if (s.constructor === String)
|
|
505
|
+
return `<${s}${t}>`;
|
|
463
506
|
{
|
|
464
|
-
let
|
|
465
|
-
if (
|
|
466
|
-
for (const n in
|
|
467
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
468
|
-
const
|
|
469
|
-
|
|
507
|
+
let o = `<${s.tag}`;
|
|
508
|
+
if (s.attrs) {
|
|
509
|
+
for (const n in s.attrs)
|
|
510
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
|
|
511
|
+
const i = s.attrs[n];
|
|
512
|
+
i !== null && (o += ` ${n}="${i}"`);
|
|
470
513
|
}
|
|
471
514
|
}
|
|
472
|
-
return `${
|
|
515
|
+
return `${o}${t}>`;
|
|
473
516
|
}
|
|
474
517
|
}).join("");
|
|
475
518
|
}
|
|
476
|
-
renderOpeningTag(
|
|
477
|
-
return this.renderTag(
|
|
519
|
+
renderOpeningTag(e) {
|
|
520
|
+
return this.renderTag(e, "");
|
|
478
521
|
}
|
|
479
|
-
renderClosingTag(
|
|
480
|
-
return
|
|
522
|
+
renderClosingTag(e) {
|
|
523
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
481
524
|
}
|
|
482
|
-
getMatchingNode(
|
|
483
|
-
const
|
|
484
|
-
if (typeof
|
|
485
|
-
return e
|
|
525
|
+
getMatchingNode(e) {
|
|
526
|
+
const t = this.nodes[e.type];
|
|
527
|
+
if (typeof t == "function")
|
|
528
|
+
return t(e);
|
|
486
529
|
}
|
|
487
|
-
getMatchingMark(
|
|
488
|
-
const
|
|
489
|
-
if (typeof
|
|
490
|
-
return e
|
|
530
|
+
getMatchingMark(e) {
|
|
531
|
+
const t = this.marks[e.type];
|
|
532
|
+
if (typeof t == "function")
|
|
533
|
+
return t(e);
|
|
491
534
|
}
|
|
492
|
-
renderEmoji(
|
|
493
|
-
if (
|
|
494
|
-
return
|
|
495
|
-
const
|
|
535
|
+
renderEmoji(e) {
|
|
536
|
+
if (e.attrs.emoji)
|
|
537
|
+
return e.attrs.emoji;
|
|
538
|
+
const t = [
|
|
496
539
|
{
|
|
497
540
|
tag: "img",
|
|
498
541
|
attrs: {
|
|
499
|
-
src:
|
|
542
|
+
src: e.attrs.fallbackImage,
|
|
500
543
|
draggable: "false",
|
|
501
544
|
loading: "lazy",
|
|
502
545
|
align: "absmiddle"
|
|
503
546
|
}
|
|
504
547
|
}
|
|
505
548
|
];
|
|
506
|
-
return this.renderTag(
|
|
549
|
+
return this.renderTag(t, " /");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
class Ie {
|
|
553
|
+
constructor(e) {
|
|
554
|
+
d(this, "baseURL"), d(this, "timeout"), d(this, "headers"), d(this, "responseInterceptor"), d(this, "fetch"), d(this, "ejectInterceptor"), d(this, "url"), d(this, "parameters"), d(this, "fetchOptions"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
*
|
|
558
|
+
* @param url string
|
|
559
|
+
* @param params ISbStoriesParams
|
|
560
|
+
* @returns Promise<ISbResponse | Error>
|
|
561
|
+
*/
|
|
562
|
+
get(e, t) {
|
|
563
|
+
return this.url = e, this.parameters = t, this._methodHandler("get");
|
|
564
|
+
}
|
|
565
|
+
post(e, t) {
|
|
566
|
+
return this.url = e, this.parameters = t, this._methodHandler("post");
|
|
567
|
+
}
|
|
568
|
+
put(e, t) {
|
|
569
|
+
return this.url = e, this.parameters = t, this._methodHandler("put");
|
|
570
|
+
}
|
|
571
|
+
delete(e, t) {
|
|
572
|
+
return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
|
|
573
|
+
}
|
|
574
|
+
async _responseHandler(e) {
|
|
575
|
+
const t = [], s = {
|
|
576
|
+
data: {},
|
|
577
|
+
headers: {},
|
|
578
|
+
status: 0,
|
|
579
|
+
statusText: ""
|
|
580
|
+
};
|
|
581
|
+
e.status !== 204 && await e.json().then((o) => {
|
|
582
|
+
s.data = o;
|
|
583
|
+
});
|
|
584
|
+
for (const o of e.headers.entries())
|
|
585
|
+
t[o[0]] = o[1];
|
|
586
|
+
return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
|
|
587
|
+
}
|
|
588
|
+
async _methodHandler(e) {
|
|
589
|
+
let t = `${this.baseURL}${this.url}`, s = null;
|
|
590
|
+
if (e === "get") {
|
|
591
|
+
const l = new v();
|
|
592
|
+
t = `${this.baseURL}${this.url}?${l.stringify(
|
|
593
|
+
this.parameters
|
|
594
|
+
)}`;
|
|
595
|
+
} else
|
|
596
|
+
s = JSON.stringify(this.parameters);
|
|
597
|
+
const o = new URL(t), n = new AbortController(), { signal: i } = n;
|
|
598
|
+
let a;
|
|
599
|
+
this.timeout && (a = setTimeout(() => n.abort(), this.timeout));
|
|
600
|
+
try {
|
|
601
|
+
const l = await this.fetch(`${o}`, {
|
|
602
|
+
method: e,
|
|
603
|
+
headers: this.headers,
|
|
604
|
+
body: s,
|
|
605
|
+
signal: i,
|
|
606
|
+
...this.fetchOptions
|
|
607
|
+
});
|
|
608
|
+
this.timeout && clearTimeout(a);
|
|
609
|
+
const c = await this._responseHandler(
|
|
610
|
+
l
|
|
611
|
+
);
|
|
612
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
|
|
613
|
+
} catch (l) {
|
|
614
|
+
return {
|
|
615
|
+
message: l
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
setFetchOptions(e = {}) {
|
|
620
|
+
Object.keys(e).length > 0 && "method" in e && delete e.method, this.fetchOptions = { ...e };
|
|
621
|
+
}
|
|
622
|
+
eject() {
|
|
623
|
+
this.ejectInterceptor = !0;
|
|
624
|
+
}
|
|
625
|
+
_statusHandler(e) {
|
|
626
|
+
const t = /20[0-6]/g;
|
|
627
|
+
return new Promise((s, o) => {
|
|
628
|
+
if (t.test(`${e.status}`))
|
|
629
|
+
return s(e);
|
|
630
|
+
const n = {
|
|
631
|
+
message: e.statusText,
|
|
632
|
+
status: e.status,
|
|
633
|
+
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
634
|
+
};
|
|
635
|
+
o(n);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const P = "SB-Agent", $ = {
|
|
640
|
+
defaultAgentName: "SB-JS-CLIENT",
|
|
641
|
+
defaultAgentVersion: "SB-Agent-Version",
|
|
642
|
+
packageVersion: "6.0.0"
|
|
643
|
+
};
|
|
644
|
+
let k = {};
|
|
645
|
+
const y = {};
|
|
646
|
+
class Le {
|
|
647
|
+
/**
|
|
648
|
+
*
|
|
649
|
+
* @param config ISbConfig interface
|
|
650
|
+
* @param pEndpoint string, optional
|
|
651
|
+
*/
|
|
652
|
+
constructor(e, t) {
|
|
653
|
+
d(this, "client"), d(this, "maxRetries"), d(this, "retriesDelay"), d(this, "throttle"), d(this, "accessToken"), d(this, "cache"), d(this, "helpers"), d(this, "resolveCounter"), d(this, "relations"), d(this, "links"), d(this, "richTextResolver"), d(this, "resolveNestedRelations"), d(this, "stringifiedStoriesCache");
|
|
654
|
+
let s = e.endpoint || t;
|
|
655
|
+
if (!s) {
|
|
656
|
+
const i = new v().getRegionURL, a = e.https === !1 ? "http" : "https";
|
|
657
|
+
e.oauthToken ? s = `${a}://${i(e.region)}/v1` : s = `${a}://${i(e.region)}/v2`;
|
|
658
|
+
}
|
|
659
|
+
const o = new Headers();
|
|
660
|
+
o.set("Content-Type", "application/json"), o.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, a]) => {
|
|
661
|
+
o.set(i, a);
|
|
662
|
+
}), o.has(P) || (o.set(P, $.defaultAgentName), o.set(
|
|
663
|
+
$.defaultAgentVersion,
|
|
664
|
+
$.packageVersion
|
|
665
|
+
));
|
|
666
|
+
let n = 5;
|
|
667
|
+
e.oauthToken && (o.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new w(e.richTextSchema) : this.richTextResolver = new w(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ee(
|
|
668
|
+
this.throttledRequest.bind(this),
|
|
669
|
+
n,
|
|
670
|
+
1e3
|
|
671
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new v(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Ie({
|
|
672
|
+
baseURL: s,
|
|
673
|
+
timeout: e.timeout || 0,
|
|
674
|
+
headers: o,
|
|
675
|
+
responseInterceptor: e.responseInterceptor,
|
|
676
|
+
fetch: e.fetch
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
setComponentResolver(e) {
|
|
680
|
+
this.richTextResolver.addNode("blok", (t) => {
|
|
681
|
+
let s = "";
|
|
682
|
+
return t.attrs.body && t.attrs.body.forEach((o) => {
|
|
683
|
+
s += e(o.component, o);
|
|
684
|
+
}), {
|
|
685
|
+
html: s
|
|
686
|
+
};
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
parseParams(e) {
|
|
690
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = y[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
691
|
+
}
|
|
692
|
+
factoryParamOptions(e, t) {
|
|
693
|
+
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
694
|
+
}
|
|
695
|
+
makeRequest(e, t, s, o, n) {
|
|
696
|
+
const i = this.factoryParamOptions(
|
|
697
|
+
e,
|
|
698
|
+
this.helpers.getOptionsPage(t, s, o)
|
|
699
|
+
);
|
|
700
|
+
return this.cacheResponse(e, i, void 0, n);
|
|
701
|
+
}
|
|
702
|
+
get(e, t, s) {
|
|
703
|
+
t || (t = {});
|
|
704
|
+
const o = `/${e}`, n = this.factoryParamOptions(o, t);
|
|
705
|
+
return this.cacheResponse(o, n, void 0, s);
|
|
706
|
+
}
|
|
707
|
+
async getAll(e, t, s, o) {
|
|
708
|
+
const n = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), a = s ?? i.substring(i.lastIndexOf("/") + 1), l = 1, c = await this.makeRequest(
|
|
709
|
+
i,
|
|
710
|
+
t,
|
|
711
|
+
n,
|
|
712
|
+
l,
|
|
713
|
+
o
|
|
714
|
+
), h = c.total ? Math.ceil(c.total / n) : 1, u = await this.helpers.asyncMap(
|
|
715
|
+
this.helpers.range(l, h),
|
|
716
|
+
(g) => this.makeRequest(i, t, n, g + 1, o)
|
|
717
|
+
);
|
|
718
|
+
return this.helpers.flatMap([c, ...u], (g) => Object.values(g.data[a]));
|
|
719
|
+
}
|
|
720
|
+
post(e, t, s) {
|
|
721
|
+
const o = `/${e}`;
|
|
722
|
+
return Promise.resolve(
|
|
723
|
+
this.throttle("post", o, t, s)
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
put(e, t, s) {
|
|
727
|
+
const o = `/${e}`;
|
|
728
|
+
return Promise.resolve(
|
|
729
|
+
this.throttle("put", o, t, s)
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
delete(e, t, s) {
|
|
733
|
+
t || (t = {});
|
|
734
|
+
const o = `/${e}`;
|
|
735
|
+
return Promise.resolve(
|
|
736
|
+
this.throttle("delete", o, t, s)
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
getStories(e, t) {
|
|
740
|
+
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
741
|
+
}
|
|
742
|
+
getStory(e, t, s) {
|
|
743
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
|
|
744
|
+
}
|
|
745
|
+
getToken() {
|
|
746
|
+
return this.accessToken;
|
|
747
|
+
}
|
|
748
|
+
ejectInterceptor() {
|
|
749
|
+
this.client.eject();
|
|
750
|
+
}
|
|
751
|
+
_addResolveLevel(e) {
|
|
752
|
+
typeof e.resolve_relations < "u" && (e.resolve_level = 2);
|
|
753
|
+
}
|
|
754
|
+
_cleanCopy(e) {
|
|
755
|
+
return JSON.parse(JSON.stringify(e));
|
|
756
|
+
}
|
|
757
|
+
_insertLinks(e, t, s) {
|
|
758
|
+
const o = e[t];
|
|
759
|
+
o && o.fieldtype === "multilink" && o.linktype === "story" && typeof o.id == "string" && this.links[s][o.id] ? o.story = this._cleanCopy(this.links[s][o.id]) : o && o.linktype === "story" && typeof o.uuid == "string" && this.links[s][o.uuid] && (o.story = this._cleanCopy(this.links[s][o.uuid]));
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
*
|
|
763
|
+
* @param resolveId A counter number as a string
|
|
764
|
+
* @param uuid The uuid of the story
|
|
765
|
+
* @returns string | object
|
|
766
|
+
*/
|
|
767
|
+
getStoryReference(e, t) {
|
|
768
|
+
return this.relations[e][t] ? JSON.parse(this.stringifiedStoriesCache[t] || JSON.stringify(this.relations[e][t])) : t;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Resolves a field's value by replacing UUIDs with their corresponding story references
|
|
772
|
+
* @param jtree - The JSON tree object containing the field to resolve
|
|
773
|
+
* @param treeItem - The key of the field to resolve
|
|
774
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
775
|
+
*
|
|
776
|
+
* This method handles both single string UUIDs and arrays of UUIDs:
|
|
777
|
+
* - For single strings: directly replaces the UUID with the story reference
|
|
778
|
+
* - For arrays: maps through each UUID and replaces with corresponding story references
|
|
779
|
+
*/
|
|
780
|
+
_resolveField(e, t, s) {
|
|
781
|
+
const o = e[t];
|
|
782
|
+
typeof o == "string" ? e[t] = this.getStoryReference(s, o) : Array.isArray(o) && (e[t] = o.map(
|
|
783
|
+
(n) => this.getStoryReference(s, n)
|
|
784
|
+
).filter(Boolean));
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Inserts relations into the JSON tree by resolving references
|
|
788
|
+
* @param jtree - The JSON tree object to process
|
|
789
|
+
* @param treeItem - The current field being processed
|
|
790
|
+
* @param fields - The relation patterns to resolve (string or array of strings)
|
|
791
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
792
|
+
*
|
|
793
|
+
* This method handles two types of relation patterns:
|
|
794
|
+
* 1. Nested relations: matches fields that end with the current field name
|
|
795
|
+
* Example: If treeItem is "event_type", it matches patterns like "*.event_type"
|
|
796
|
+
*
|
|
797
|
+
* 2. Direct component relations: matches exact component.field patterns
|
|
798
|
+
* Example: "event.event_type" for component "event" and field "event_type"
|
|
799
|
+
*
|
|
800
|
+
* The method supports both string and array formats for the fields parameter,
|
|
801
|
+
* allowing flexible specification of relation patterns.
|
|
802
|
+
*/
|
|
803
|
+
_insertRelations(e, t, s, o) {
|
|
804
|
+
if (Array.isArray(s) ? s.find((i) => i.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
|
|
805
|
+
this._resolveField(e, t, o);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const n = e.component ? `${e.component}.${t}` : t;
|
|
809
|
+
(Array.isArray(s) ? s.includes(n) : s === n) && this._resolveField(e, t, o);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Recursively traverses and resolves relations in the story content tree
|
|
813
|
+
* @param story - The story object containing the content to process
|
|
814
|
+
* @param fields - The relation patterns to resolve
|
|
815
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
816
|
+
*/
|
|
817
|
+
iterateTree(e, t, s) {
|
|
818
|
+
const o = (n, i = "") => {
|
|
819
|
+
if (!(!n || n._stopResolving)) {
|
|
820
|
+
if (Array.isArray(n))
|
|
821
|
+
n.forEach((a, l) => o(a, `${i}[${l}]`));
|
|
822
|
+
else if (typeof n == "object")
|
|
823
|
+
for (const a in n) {
|
|
824
|
+
const l = i ? `${i}.${a}` : a;
|
|
825
|
+
(n.component && n._uid || n.type === "link") && (this._insertRelations(n, a, t, s), this._insertLinks(n, a, s)), o(n[a], l);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
o(e.content);
|
|
830
|
+
}
|
|
831
|
+
async resolveLinks(e, t, s) {
|
|
832
|
+
let o = [];
|
|
833
|
+
if (e.link_uuids) {
|
|
834
|
+
const n = e.link_uuids.length, i = [], a = 50;
|
|
835
|
+
for (let l = 0; l < n; l += a) {
|
|
836
|
+
const c = Math.min(n, l + a);
|
|
837
|
+
i.push(e.link_uuids.slice(l, c));
|
|
838
|
+
}
|
|
839
|
+
for (let l = 0; l < i.length; l++)
|
|
840
|
+
(await this.getStories({
|
|
841
|
+
per_page: a,
|
|
842
|
+
language: t.language,
|
|
843
|
+
version: t.version,
|
|
844
|
+
by_uuids: i[l].join(",")
|
|
845
|
+
})).data.stories.forEach(
|
|
846
|
+
(c) => {
|
|
847
|
+
o.push(c);
|
|
848
|
+
}
|
|
849
|
+
);
|
|
850
|
+
} else
|
|
851
|
+
o = e.links;
|
|
852
|
+
o.forEach((n) => {
|
|
853
|
+
this.links[s][n.uuid] = {
|
|
854
|
+
...n,
|
|
855
|
+
_stopResolving: !0
|
|
856
|
+
};
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
async resolveRelations(e, t, s) {
|
|
860
|
+
let o = [];
|
|
861
|
+
if (e.rel_uuids) {
|
|
862
|
+
const n = e.rel_uuids.length, i = [], a = 50;
|
|
863
|
+
for (let l = 0; l < n; l += a) {
|
|
864
|
+
const c = Math.min(n, l + a);
|
|
865
|
+
i.push(e.rel_uuids.slice(l, c));
|
|
866
|
+
}
|
|
867
|
+
for (let l = 0; l < i.length; l++)
|
|
868
|
+
(await this.getStories({
|
|
869
|
+
per_page: a,
|
|
870
|
+
language: t.language,
|
|
871
|
+
version: t.version,
|
|
872
|
+
by_uuids: i[l].join(","),
|
|
873
|
+
excluding_fields: t.excluding_fields
|
|
874
|
+
})).data.stories.forEach((c) => {
|
|
875
|
+
o.push(c);
|
|
876
|
+
});
|
|
877
|
+
} else
|
|
878
|
+
o = e.rels;
|
|
879
|
+
o && o.length > 0 && o.forEach((n) => {
|
|
880
|
+
this.relations[s][n.uuid] = {
|
|
881
|
+
...n,
|
|
882
|
+
_stopResolving: !0
|
|
883
|
+
};
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
*
|
|
888
|
+
* @param responseData
|
|
889
|
+
* @param params
|
|
890
|
+
* @param resolveId
|
|
891
|
+
* @description Resolves the relations and links of the stories
|
|
892
|
+
* @returns Promise<void>
|
|
893
|
+
*
|
|
894
|
+
*/
|
|
895
|
+
async resolveStories(e, t, s) {
|
|
896
|
+
var o, n;
|
|
897
|
+
let i = [];
|
|
898
|
+
if (this.links[s] = {}, this.relations[s] = {}, 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, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((o = e.links) != null && o.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
899
|
+
for (const a in this.relations[s])
|
|
900
|
+
this.iterateTree(
|
|
901
|
+
this.relations[s][a],
|
|
902
|
+
i,
|
|
903
|
+
s
|
|
904
|
+
);
|
|
905
|
+
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((a) => {
|
|
906
|
+
this.iterateTree(a, i, s);
|
|
907
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
908
|
+
}
|
|
909
|
+
async cacheResponse(e, t, s, o) {
|
|
910
|
+
const n = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
911
|
+
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
912
|
+
const a = await i.get(n);
|
|
913
|
+
if (a)
|
|
914
|
+
return Promise.resolve(a);
|
|
915
|
+
}
|
|
916
|
+
return new Promise(async (a, l) => {
|
|
917
|
+
var c;
|
|
918
|
+
try {
|
|
919
|
+
const h = await this.throttle(
|
|
920
|
+
"get",
|
|
921
|
+
e,
|
|
922
|
+
t,
|
|
923
|
+
o
|
|
924
|
+
);
|
|
925
|
+
if (h.status !== 200)
|
|
926
|
+
return l(h);
|
|
927
|
+
let u = { data: h.data, headers: h.headers };
|
|
928
|
+
if ((c = h.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
|
|
929
|
+
perPage: h.headers["per-page"] ? Number.parseInt(h.headers["per-page"]) : 0,
|
|
930
|
+
total: h.headers["per-page"] ? Number.parseInt(h.headers.total) : 0
|
|
931
|
+
})), u.data.story || u.data.stories) {
|
|
932
|
+
const f = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
933
|
+
await this.resolveStories(u.data, t, `${f}`);
|
|
934
|
+
}
|
|
935
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await i.set(n, u);
|
|
936
|
+
const g = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
937
|
+
return t.token && u.data.cv && (g && y[t.token] && y[t.token] !== u.data.cv && await this.flushCache(), y[t.token] = u.data.cv), a(u);
|
|
938
|
+
} catch (h) {
|
|
939
|
+
if (h.response && h.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
940
|
+
return console.log(
|
|
941
|
+
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
|
942
|
+
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(a).catch(l);
|
|
943
|
+
l(h);
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
throttledRequest(e, t, s, o) {
|
|
948
|
+
return this.client.setFetchOptions(o), this.client[e](t, s);
|
|
949
|
+
}
|
|
950
|
+
cacheVersions() {
|
|
951
|
+
return y;
|
|
952
|
+
}
|
|
953
|
+
cacheVersion() {
|
|
954
|
+
return y[this.accessToken];
|
|
955
|
+
}
|
|
956
|
+
setCacheVersion(e) {
|
|
957
|
+
this.accessToken && (y[this.accessToken] = e);
|
|
958
|
+
}
|
|
959
|
+
clearCacheVersion() {
|
|
960
|
+
this.accessToken && (y[this.accessToken] = 0);
|
|
961
|
+
}
|
|
962
|
+
cacheProvider() {
|
|
963
|
+
switch (this.cache.type) {
|
|
964
|
+
case "memory":
|
|
965
|
+
return {
|
|
966
|
+
get(e) {
|
|
967
|
+
return Promise.resolve(k[e]);
|
|
968
|
+
},
|
|
969
|
+
getAll() {
|
|
970
|
+
return Promise.resolve(k);
|
|
971
|
+
},
|
|
972
|
+
set(e, t) {
|
|
973
|
+
return k[e] = t, Promise.resolve(void 0);
|
|
974
|
+
},
|
|
975
|
+
flush() {
|
|
976
|
+
return k = {}, Promise.resolve(void 0);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
case "custom":
|
|
980
|
+
if (this.cache.custom)
|
|
981
|
+
return this.cache.custom;
|
|
982
|
+
// eslint-disable-next-line no-fallthrough
|
|
983
|
+
default:
|
|
984
|
+
return {
|
|
985
|
+
get() {
|
|
986
|
+
return Promise.resolve();
|
|
987
|
+
},
|
|
988
|
+
getAll() {
|
|
989
|
+
return Promise.resolve(void 0);
|
|
990
|
+
},
|
|
991
|
+
set() {
|
|
992
|
+
return Promise.resolve(void 0);
|
|
993
|
+
},
|
|
994
|
+
flush() {
|
|
995
|
+
return Promise.resolve(void 0);
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
async flushCache() {
|
|
1001
|
+
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
507
1002
|
}
|
|
508
1003
|
}
|
|
509
|
-
const
|
|
1004
|
+
const Ee = (r = {}) => {
|
|
1005
|
+
const { apiOptions: e } = r;
|
|
1006
|
+
if (!e || !e.accessToken) {
|
|
1007
|
+
console.error(
|
|
1008
|
+
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
1009
|
+
);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
return { storyblokApi: new Le(e) };
|
|
1013
|
+
}, Ue = (r) => {
|
|
510
1014
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
511
1015
|
return {};
|
|
512
1016
|
try {
|
|
513
|
-
const
|
|
1017
|
+
const e = JSON.parse(
|
|
514
1018
|
r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
515
1019
|
);
|
|
516
|
-
return
|
|
517
|
-
"data-blok-c": JSON.stringify(
|
|
518
|
-
"data-blok-uid": `${
|
|
1020
|
+
return e ? {
|
|
1021
|
+
"data-blok-c": JSON.stringify(e),
|
|
1022
|
+
"data-blok-uid": `${e.id}-${e.uid}`
|
|
519
1023
|
} : {};
|
|
520
1024
|
} catch {
|
|
521
1025
|
return {};
|
|
522
1026
|
}
|
|
523
1027
|
};
|
|
524
|
-
let
|
|
525
|
-
const
|
|
526
|
-
r.addNode("blok", (
|
|
527
|
-
let
|
|
528
|
-
return
|
|
529
|
-
|
|
1028
|
+
let T, S = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
1029
|
+
const M = (r, e) => {
|
|
1030
|
+
r.addNode("blok", (t) => {
|
|
1031
|
+
let s = "";
|
|
1032
|
+
return t.attrs.body.forEach((o) => {
|
|
1033
|
+
s += e(o.component, o);
|
|
530
1034
|
}), {
|
|
531
|
-
html:
|
|
1035
|
+
html: s
|
|
532
1036
|
};
|
|
533
1037
|
});
|
|
534
|
-
},
|
|
535
|
-
var t;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
1038
|
+
}, xe = (r = {}) => {
|
|
1039
|
+
var e, t;
|
|
1040
|
+
const {
|
|
1041
|
+
bridge: s,
|
|
1042
|
+
accessToken: o,
|
|
1043
|
+
use: n = [],
|
|
1044
|
+
apiOptions: i = {},
|
|
1045
|
+
richText: a = {},
|
|
1046
|
+
bridgeUrl: l
|
|
1047
|
+
} = r;
|
|
1048
|
+
i.accessToken = i.accessToken || o;
|
|
1049
|
+
const c = { bridge: s, apiOptions: i };
|
|
1050
|
+
let h = {};
|
|
1051
|
+
n.forEach((g) => {
|
|
1052
|
+
h = { ...h, ...g(c) };
|
|
1053
|
+
}), l && (S = l);
|
|
1054
|
+
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
1055
|
+
return s !== !1 && u && N(S), T = new w(a.schema), a.resolver && M(T, a.resolver), h;
|
|
1056
|
+
}, Pe = (r) => {
|
|
1057
|
+
var e;
|
|
1058
|
+
return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
|
1059
|
+
}, je = (r, e, t) => {
|
|
1060
|
+
let s = t || T;
|
|
1061
|
+
if (!s) {
|
|
540
1062
|
console.error(
|
|
541
1063
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
542
1064
|
);
|
|
543
1065
|
return;
|
|
544
1066
|
}
|
|
545
|
-
return
|
|
546
|
-
},
|
|
547
|
-
function
|
|
1067
|
+
return Pe(r) ? "" : (e && (s = new w(e.schema), e.resolver && M(s, e.resolver)), s.render(r, {}, !1));
|
|
1068
|
+
}, Fe = () => N(S);
|
|
1069
|
+
function Be() {
|
|
548
1070
|
if (!(globalThis != null && globalThis.storyblokApiInstance))
|
|
549
1071
|
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
550
1072
|
return globalThis.storyblokApiInstance;
|
|
551
1073
|
}
|
|
552
|
-
async function
|
|
553
|
-
let
|
|
554
|
-
return r && r.locals._storyblok_preview_data && (
|
|
1074
|
+
async function De(r) {
|
|
1075
|
+
let e = null;
|
|
1076
|
+
return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
|
|
555
1077
|
}
|
|
556
|
-
function
|
|
557
|
-
var
|
|
558
|
-
const
|
|
559
|
-
if (!
|
|
1078
|
+
function ze(r, e) {
|
|
1079
|
+
var s;
|
|
1080
|
+
const t = (s = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : s.richTextResolver;
|
|
1081
|
+
if (!t)
|
|
560
1082
|
throw new Error(
|
|
561
1083
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
562
1084
|
);
|
|
563
|
-
return
|
|
1085
|
+
return je(r, e, t);
|
|
564
1086
|
}
|
|
565
|
-
function
|
|
1087
|
+
function Oe(r) {
|
|
566
1088
|
return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
567
1089
|
}
|
|
568
|
-
function
|
|
569
|
-
const
|
|
1090
|
+
function He(r) {
|
|
1091
|
+
const e = {
|
|
570
1092
|
useCustomApi: !1,
|
|
571
1093
|
bridge: !0,
|
|
572
1094
|
componentsDir: "src",
|
|
573
1095
|
enableFallbackComponent: !1,
|
|
574
1096
|
livePreview: !1,
|
|
575
1097
|
...r
|
|
576
|
-
},
|
|
1098
|
+
}, t = Oe(e.bridge);
|
|
577
1099
|
return {
|
|
578
1100
|
name: "@storyblok/astro",
|
|
579
1101
|
hooks: {
|
|
580
1102
|
"astro:config:setup": ({
|
|
581
|
-
injectScript:
|
|
582
|
-
updateConfig:
|
|
1103
|
+
injectScript: s,
|
|
1104
|
+
updateConfig: o,
|
|
583
1105
|
addDevToolbarApp: n,
|
|
584
|
-
addMiddleware:
|
|
585
|
-
config:
|
|
1106
|
+
addMiddleware: i,
|
|
1107
|
+
config: a
|
|
586
1108
|
}) => {
|
|
587
|
-
if (
|
|
1109
|
+
if (o({
|
|
588
1110
|
vite: {
|
|
589
1111
|
plugins: [
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
1112
|
+
Z(
|
|
1113
|
+
e.accessToken,
|
|
1114
|
+
e.useCustomApi,
|
|
1115
|
+
e.apiOptions
|
|
594
1116
|
),
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
1117
|
+
K(
|
|
1118
|
+
e.componentsDir,
|
|
1119
|
+
e.components,
|
|
1120
|
+
e.enableFallbackComponent,
|
|
1121
|
+
e.customFallbackComponent
|
|
600
1122
|
),
|
|
601
|
-
|
|
1123
|
+
G(e)
|
|
602
1124
|
]
|
|
603
1125
|
}
|
|
604
|
-
}),
|
|
1126
|
+
}), e.livePreview && (a == null ? void 0 : a.output) !== "server")
|
|
605
1127
|
throw new Error(
|
|
606
1128
|
"To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode."
|
|
607
1129
|
);
|
|
608
|
-
|
|
1130
|
+
s(
|
|
609
1131
|
"page-ssr",
|
|
610
1132
|
`
|
|
611
1133
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
612
1134
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
613
1135
|
`
|
|
614
|
-
),
|
|
1136
|
+
), e.bridge && !e.livePreview && s(
|
|
615
1137
|
"page",
|
|
616
1138
|
`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
617
1139
|
loadStoryblokBridge().then(() => {
|
|
618
1140
|
const { StoryblokBridge, location } = window;
|
|
619
|
-
${
|
|
1141
|
+
${t}
|
|
620
1142
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
621
1143
|
if (!event.slugChanged) {
|
|
622
1144
|
location.reload(true);
|
|
@@ -624,54 +1146,90 @@ function je(r) {
|
|
|
624
1146
|
});
|
|
625
1147
|
});
|
|
626
1148
|
`
|
|
627
|
-
),
|
|
1149
|
+
), e.livePreview && (s(
|
|
628
1150
|
"page",
|
|
629
1151
|
`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
630
1152
|
loadStoryblokBridge().then(() => {
|
|
631
1153
|
const { StoryblokBridge, location } = window;
|
|
632
|
-
${
|
|
1154
|
+
${t}
|
|
633
1155
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
634
1156
|
});
|
|
635
1157
|
`
|
|
636
|
-
),
|
|
1158
|
+
), i({
|
|
637
1159
|
entrypoint: "@storyblok/astro/middleware.ts",
|
|
638
1160
|
order: "pre"
|
|
639
1161
|
})), n({
|
|
640
1162
|
id: "storyblok",
|
|
641
1163
|
name: "Storyblok",
|
|
642
|
-
icon:
|
|
1164
|
+
icon: B,
|
|
643
1165
|
entrypoint: "@storyblok/astro/toolbarApp.ts"
|
|
644
1166
|
});
|
|
645
1167
|
}
|
|
646
1168
|
}
|
|
647
1169
|
};
|
|
648
1170
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
1171
|
+
function qe(r) {
|
|
1172
|
+
const { storyblokApi: e } = xe({
|
|
1173
|
+
accessToken: r.STORYBLOK_TOKEN,
|
|
1174
|
+
use: [Ee]
|
|
1175
|
+
});
|
|
1176
|
+
return {
|
|
1177
|
+
name: "story-loader",
|
|
1178
|
+
load: async ({ store: t, meta: s, logger: o, refreshContextData: n }) => {
|
|
1179
|
+
if (!e)
|
|
1180
|
+
throw new Error("storyblokApi is not loaded");
|
|
1181
|
+
if (n != null && n.story) {
|
|
1182
|
+
o.info("Syncing... story updated in Storyblok");
|
|
1183
|
+
const p = n.story;
|
|
1184
|
+
t.set({
|
|
1185
|
+
data: p,
|
|
1186
|
+
id: p.uuid
|
|
1187
|
+
});
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
o.info("Loading stories");
|
|
1191
|
+
const i = s.get("lastPublishedAt"), a = s.get("lastUpdatedAt"), l = s.get("version"), c = { version: r.version };
|
|
1192
|
+
i && r.version === "published" ? c.published_at_gt = i : a && (c.updated_at_gt = a), l !== r.version && (o.info("Version changed, clearing store"), t.clear()), s.set("version", r.version);
|
|
1193
|
+
const h = await (e == null ? void 0 : e.getAll("cdn/stories", c));
|
|
1194
|
+
o.info(`Fetched ${h.length} stories`);
|
|
1195
|
+
const u = (p) => p ? new Date(p) : null;
|
|
1196
|
+
let g = u(i), f = u(a);
|
|
1197
|
+
for (const p of h) {
|
|
1198
|
+
const m = u(p.published_at), b = u(p.updated_at), U = m && (!g || m > g), F = b && (!f || b > f);
|
|
1199
|
+
U && (g = m), F && (f = b), t.set({
|
|
1200
|
+
data: p,
|
|
1201
|
+
id: p.uuid
|
|
1202
|
+
}), f && s.set("lastUpdatedAt", f.toISOString()), g && s.set("lastPublishedAt", g.toISOString());
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
let j;
|
|
1208
|
+
async function Ve(r) {
|
|
1209
|
+
const { action: e, story: t } = r || {};
|
|
1210
|
+
if (e === "input" && t) {
|
|
1211
|
+
const s = async () => {
|
|
1212
|
+
const n = await Me(t), i = document.body;
|
|
1213
|
+
if (n.outerHTML === i.outerHTML)
|
|
656
1214
|
return;
|
|
657
|
-
const
|
|
658
|
-
|
|
1215
|
+
const a = document.querySelector('[data-blok-focused="true"]');
|
|
1216
|
+
Ne(i, n, a), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
|
|
659
1217
|
};
|
|
660
|
-
clearTimeout(
|
|
1218
|
+
clearTimeout(j), j = setTimeout(s, 500);
|
|
661
1219
|
}
|
|
662
1220
|
["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
|
|
663
1221
|
}
|
|
664
|
-
function
|
|
665
|
-
if (
|
|
666
|
-
const
|
|
667
|
-
`[data-blok-uid="${
|
|
1222
|
+
function Ne(r, e, t) {
|
|
1223
|
+
if (t) {
|
|
1224
|
+
const s = t.getAttribute("data-blok-uid"), o = e.querySelector(
|
|
1225
|
+
`[data-blok-uid="${s}"]`
|
|
668
1226
|
);
|
|
669
|
-
|
|
1227
|
+
o && (o.setAttribute("data-blok-focused", "true"), t.replaceWith(o));
|
|
670
1228
|
} else
|
|
671
|
-
r.replaceWith(
|
|
1229
|
+
r.replaceWith(e);
|
|
672
1230
|
}
|
|
673
|
-
async function
|
|
674
|
-
const
|
|
1231
|
+
async function Me(r) {
|
|
1232
|
+
const t = await (await fetch(location.href, {
|
|
675
1233
|
method: "POST",
|
|
676
1234
|
body: JSON.stringify({
|
|
677
1235
|
...r,
|
|
@@ -681,17 +1239,18 @@ async function Se(r) {
|
|
|
681
1239
|
"Content-Type": "application/json"
|
|
682
1240
|
}
|
|
683
1241
|
})).text();
|
|
684
|
-
return new DOMParser().parseFromString(
|
|
1242
|
+
return new DOMParser().parseFromString(t, "text/html").body;
|
|
685
1243
|
}
|
|
686
1244
|
export {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1245
|
+
w as RichTextResolver,
|
|
1246
|
+
Re as RichTextSchema,
|
|
1247
|
+
De as getLiveStory,
|
|
1248
|
+
Ve as handleStoryblokMessage,
|
|
1249
|
+
Fe as loadStoryblokBridge,
|
|
1250
|
+
ze as renderRichText,
|
|
1251
|
+
He as storyblok,
|
|
1252
|
+
Ue as storyblokEditable,
|
|
1253
|
+
qe as storyblokLoader,
|
|
1254
|
+
I as toCamelCase,
|
|
1255
|
+
Be as useStoryblokApi
|
|
697
1256
|
};
|