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