@storyblok/astro 6.1.0-alpha.2 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/components/StoryblokComponent.astro +9 -6
- package/dist/index.d.ts +1 -3
- package/dist/storyblok-astro.es.js +494 -825
- package/dist/storyblok-astro.umd.js +8 -8
- package/dist/vite-plugins/vite-plugin-storyblok-options.d.ts +1 -2
- package/package.json +5 -3
- package/dist/content-loader/storyblokLoader.d.ts +0 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Q = `<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 V = `<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
|
|
14
|
-
|
|
10
|
+
</svg>`, ee = /[\p{Lu}]/u, te = /[\p{Ll}]/u, O = /^[\p{Lu}](?![\p{Lu}])/gu, H = /([\p{Alpha}\p{N}_]|$)/u, j = /[_.\- ]+/, re = new RegExp("^" + j.source), _ = new RegExp(j.source + H.source, "gu"), M = new RegExp("\\d+" + H.source, "gu"), oe = (r, e, t, o) => {
|
|
11
|
+
let n = !1, s = !1, l = !1, d = !1;
|
|
12
|
+
for (let i = 0; i < r.length; i++) {
|
|
13
|
+
const p = r[i];
|
|
14
|
+
d = i > 2 ? r[i - 3] === "-" : !0, n && ee.test(p) ? (r = r.slice(0, i) + "-" + r.slice(i), n = !1, l = s, s = !0, i++) : s && l && te.test(p) && (!d || o) ? (r = r.slice(0, i - 1) + "-" + r.slice(i - 1), l = s, s = !1, n = !0) : (n = e(p) === p && t(p) !== p, l = s, s = t(p) === p && e(p) !== p);
|
|
15
15
|
}
|
|
16
16
|
return r;
|
|
17
|
-
},
|
|
18
|
-
function
|
|
17
|
+
}, se = (r, e) => (O.lastIndex = 0, r.replaceAll(O, (t) => e(t))), ne = (r, e) => (_.lastIndex = 0, M.lastIndex = 0, r.replaceAll(M, (t, o, n) => ["_", "-"].includes(r.charAt(n + t.length)) ? t : e(t)).replaceAll(_, (t, o) => e(o)));
|
|
18
|
+
function ae(r, e) {
|
|
19
19
|
if (!(typeof r == "string" || Array.isArray(r)))
|
|
20
20
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
21
21
|
if (e = {
|
|
22
22
|
pascalCase: !1,
|
|
23
23
|
preserveConsecutiveUppercase: !1,
|
|
24
24
|
...e
|
|
25
|
-
}, Array.isArray(r) ? r = r.map((
|
|
25
|
+
}, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
|
|
26
26
|
return "";
|
|
27
|
-
const t = e.locale === !1 ? (
|
|
28
|
-
return r.length === 1 ?
|
|
27
|
+
const t = e.locale === !1 ? (s) => s.toLowerCase() : (s) => s.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (s) => s.toUpperCase() : (s) => s.toLocaleUpperCase(e.locale);
|
|
28
|
+
return r.length === 1 ? j.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = oe(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(re, ""), r = e.preserveConsecutiveUppercase ? se(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), ne(r, o));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function N(r) {
|
|
31
|
+
return ae(r);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
const
|
|
33
|
+
function le(r, e = {}, t, o) {
|
|
34
|
+
const n = "virtual:storyblok-components", s = `\0${n}`;
|
|
35
35
|
return {
|
|
36
36
|
name: "vite-plugin-storyblok-components",
|
|
37
|
-
async resolveId(
|
|
38
|
-
if (
|
|
39
|
-
return
|
|
37
|
+
async resolveId(l) {
|
|
38
|
+
if (l === n)
|
|
39
|
+
return s;
|
|
40
40
|
},
|
|
41
|
-
async load(
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
for await (const [
|
|
45
|
-
const
|
|
46
|
-
`/${r}/${
|
|
41
|
+
async load(l) {
|
|
42
|
+
if (l === s) {
|
|
43
|
+
const d = [], i = [];
|
|
44
|
+
for await (const [g, $] of Object.entries(e)) {
|
|
45
|
+
const E = await this.resolve(
|
|
46
|
+
`/${r}/${$}.astro`
|
|
47
47
|
);
|
|
48
|
-
if (
|
|
49
|
-
|
|
48
|
+
if (E)
|
|
49
|
+
d.push(`import ${N(g)} from "${E.id}"`);
|
|
50
50
|
else if (t)
|
|
51
|
-
|
|
51
|
+
i.push(g);
|
|
52
52
|
else
|
|
53
53
|
throw new Error(
|
|
54
|
-
`Component could not be found for blok "${
|
|
54
|
+
`Component could not be found for blok "${g}"! Does "${`/${r}/${$}`}.astro" exist?`
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
-
let
|
|
57
|
+
let p = "";
|
|
58
58
|
if (t)
|
|
59
|
-
if (
|
|
60
|
-
const
|
|
61
|
-
`/${r}/${
|
|
59
|
+
if (p = ",FallbackComponent", o) {
|
|
60
|
+
const g = await this.resolve(
|
|
61
|
+
`/${r}/${o}.astro`
|
|
62
62
|
);
|
|
63
|
-
if (!
|
|
63
|
+
if (!g)
|
|
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}/${o}`}.astro" exist?`
|
|
66
66
|
);
|
|
67
|
-
|
|
68
|
-
`import FallbackComponent from "${
|
|
67
|
+
d.push(
|
|
68
|
+
`import FallbackComponent from "${g.id}"`
|
|
69
69
|
);
|
|
70
70
|
} else
|
|
71
|
-
|
|
71
|
+
d.push(
|
|
72
72
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
|
|
73
73
|
);
|
|
74
74
|
if (Object.values(e).length)
|
|
75
|
-
return `${
|
|
75
|
+
return `${d.join(";")};export default {${Object.keys(e).filter((g) => !i.includes(g)).map((g) => N(g)).join(",")}${p}}`;
|
|
76
76
|
if (t)
|
|
77
|
-
return `${
|
|
77
|
+
return `${d[0]}; export default {${p.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,16 +84,16 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
87
|
+
function ie(r, e, t) {
|
|
88
|
+
const o = "virtual:storyblok-init", n = `\0${o}`;
|
|
89
89
|
return {
|
|
90
90
|
name: "vite-plugin-storyblok-init",
|
|
91
|
-
async resolveId(
|
|
92
|
-
if (
|
|
93
|
-
return
|
|
91
|
+
async resolveId(s) {
|
|
92
|
+
if (s === o)
|
|
93
|
+
return n;
|
|
94
94
|
},
|
|
95
|
-
async load(
|
|
96
|
-
if (
|
|
95
|
+
async load(s) {
|
|
96
|
+
if (s === n)
|
|
97
97
|
return `
|
|
98
98
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
99
99
|
const { storyblokApi } = storyblokInit({
|
|
@@ -106,97 +106,54 @@ function ee(r, e, t) {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function ce(r) {
|
|
110
110
|
const e = "virtual:storyblok-options", t = `\0${e}`;
|
|
111
111
|
return {
|
|
112
112
|
name: "vite-plugin-storyblok-options",
|
|
113
|
-
async resolveId(
|
|
114
|
-
if (
|
|
113
|
+
async resolveId(o) {
|
|
114
|
+
if (o === e)
|
|
115
115
|
return t;
|
|
116
116
|
},
|
|
117
|
-
async load(
|
|
118
|
-
if (
|
|
117
|
+
async load(o) {
|
|
118
|
+
if (o === 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 P = !1;
|
|
124
|
+
const B = [], ue = (r) => new Promise((e, t) => {
|
|
125
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
|
|
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
|
+
P ? n() : B.push(n);
|
|
131
131
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
132
132
|
return;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
|
133
|
+
const o = document.createElement("script");
|
|
134
|
+
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (n) => t(n), o.onload = (n) => {
|
|
135
|
+
B.forEach((s) => s()), P = !0, e(n);
|
|
136
|
+
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
137
137
|
});
|
|
138
|
-
var
|
|
139
|
-
class
|
|
140
|
-
constructor(e) {
|
|
141
|
-
super(e), this.name = "AbortError";
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function ne(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 oe("Throttle function aborted"))
|
|
179
|
-
), s.length = 0;
|
|
180
|
-
}, l;
|
|
181
|
-
}
|
|
182
|
-
let T = class {
|
|
138
|
+
var de = Object.defineProperty, pe = (r, e, t) => e in r ? de(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, v = (r, e, t) => pe(r, typeof e != "symbol" ? e + "" : e, t);
|
|
139
|
+
class ge {
|
|
183
140
|
constructor() {
|
|
184
|
-
|
|
185
|
-
...
|
|
186
|
-
per_page:
|
|
187
|
-
page:
|
|
188
|
-
})),
|
|
189
|
-
const
|
|
190
|
-
return this.arrayFrom(
|
|
191
|
-
}),
|
|
192
|
-
const
|
|
141
|
+
v(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), v(this, "getOptionsPage", (e, t = 25, o = 1) => ({
|
|
142
|
+
...e,
|
|
143
|
+
per_page: t,
|
|
144
|
+
page: o
|
|
145
|
+
})), v(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), v(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), v(this, "range", (e = 0, t = e) => {
|
|
146
|
+
const o = Math.abs(t - e) || 0, n = e < t ? 1 : -1;
|
|
147
|
+
return this.arrayFrom(o, (s, l) => l * n + e);
|
|
148
|
+
}), v(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), v(this, "flatMap", (e = [], t) => e.map(t).reduce((o, n) => [...o, ...n], [])), v(this, "escapeHTML", function(e) {
|
|
149
|
+
const t = {
|
|
193
150
|
"&": "&",
|
|
194
151
|
"<": "<",
|
|
195
152
|
">": ">",
|
|
196
153
|
'"': """,
|
|
197
154
|
"'": "'"
|
|
198
|
-
},
|
|
199
|
-
return
|
|
155
|
+
}, o = /[&<>"']/g, n = new RegExp(o.source);
|
|
156
|
+
return e && n.test(e) ? e.replace(o, (s) => t[s]) : e;
|
|
200
157
|
});
|
|
201
158
|
}
|
|
202
159
|
/**
|
|
@@ -206,56 +163,56 @@ let T = class {
|
|
|
206
163
|
* @param {boolean} isArray
|
|
207
164
|
* @return {string} Stringified object
|
|
208
165
|
*/
|
|
209
|
-
stringify(
|
|
210
|
-
const
|
|
211
|
-
for (const
|
|
212
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
166
|
+
stringify(e, t, o) {
|
|
167
|
+
const n = [];
|
|
168
|
+
for (const s in e) {
|
|
169
|
+
if (!Object.prototype.hasOwnProperty.call(e, s))
|
|
213
170
|
continue;
|
|
214
|
-
const
|
|
215
|
-
let
|
|
216
|
-
typeof
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
Array.isArray(
|
|
220
|
-
) :
|
|
171
|
+
const l = e[s], d = o ? "" : encodeURIComponent(s);
|
|
172
|
+
let i;
|
|
173
|
+
typeof l == "object" ? i = this.stringify(
|
|
174
|
+
l,
|
|
175
|
+
t ? t + encodeURIComponent(`[${d}]`) : d,
|
|
176
|
+
Array.isArray(l)
|
|
177
|
+
) : i = `${t ? t + encodeURIComponent(`[${d}]`) : d}=${encodeURIComponent(l)}`, n.push(i);
|
|
221
178
|
}
|
|
222
|
-
return
|
|
179
|
+
return n.join("&");
|
|
223
180
|
}
|
|
224
181
|
/**
|
|
225
182
|
* @method getRegionURL
|
|
226
183
|
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
227
184
|
* @return {string} The base URL of the region
|
|
228
185
|
*/
|
|
229
|
-
getRegionURL(
|
|
230
|
-
const
|
|
231
|
-
switch (
|
|
186
|
+
getRegionURL(e) {
|
|
187
|
+
const t = "api.storyblok.com", o = "api-us.storyblok.com", n = "app.storyblokchina.cn", s = "api-ap.storyblok.com", l = "api-ca.storyblok.com";
|
|
188
|
+
switch (e) {
|
|
232
189
|
case "us":
|
|
233
|
-
return
|
|
190
|
+
return o;
|
|
234
191
|
case "cn":
|
|
235
|
-
return
|
|
192
|
+
return n;
|
|
236
193
|
case "ap":
|
|
237
|
-
return
|
|
194
|
+
return s;
|
|
238
195
|
case "ca":
|
|
239
|
-
return
|
|
196
|
+
return l;
|
|
240
197
|
default:
|
|
241
|
-
return
|
|
198
|
+
return t;
|
|
242
199
|
}
|
|
243
200
|
}
|
|
244
|
-
}
|
|
245
|
-
const
|
|
201
|
+
}
|
|
202
|
+
const he = function(r, e) {
|
|
246
203
|
const t = {};
|
|
247
|
-
for (const
|
|
248
|
-
const
|
|
249
|
-
e.includes(
|
|
204
|
+
for (const o in r) {
|
|
205
|
+
const n = r[o];
|
|
206
|
+
e.includes(o) && n !== null && (t[o] = n);
|
|
250
207
|
}
|
|
251
208
|
return t;
|
|
252
|
-
},
|
|
209
|
+
}, fe = (r) => r === "email", be = () => ({
|
|
253
210
|
singleTag: "hr"
|
|
254
|
-
}),
|
|
211
|
+
}), ye = () => ({
|
|
255
212
|
tag: "blockquote"
|
|
256
|
-
}),
|
|
213
|
+
}), me = () => ({
|
|
257
214
|
tag: "ul"
|
|
258
|
-
}),
|
|
215
|
+
}), ke = (r) => ({
|
|
259
216
|
tag: [
|
|
260
217
|
"pre",
|
|
261
218
|
{
|
|
@@ -263,24 +220,24 @@ const ie = function(r, e) {
|
|
|
263
220
|
attrs: r.attrs
|
|
264
221
|
}
|
|
265
222
|
]
|
|
266
|
-
}),
|
|
223
|
+
}), $e = () => ({
|
|
267
224
|
singleTag: "br"
|
|
268
|
-
}),
|
|
225
|
+
}), we = (r) => ({
|
|
269
226
|
tag: `h${r.attrs.level}`
|
|
270
|
-
}),
|
|
227
|
+
}), Te = (r) => ({
|
|
271
228
|
singleTag: [
|
|
272
229
|
{
|
|
273
230
|
tag: "img",
|
|
274
|
-
attrs:
|
|
231
|
+
attrs: he(r.attrs, ["src", "alt", "title"])
|
|
275
232
|
}
|
|
276
233
|
]
|
|
277
|
-
}),
|
|
234
|
+
}), Ee = () => ({
|
|
278
235
|
tag: "li"
|
|
279
|
-
}),
|
|
236
|
+
}), Ce = () => ({
|
|
280
237
|
tag: "ol"
|
|
281
|
-
}),
|
|
238
|
+
}), ve = () => ({
|
|
282
239
|
tag: "p"
|
|
283
|
-
}),
|
|
240
|
+
}), Ie = (r) => ({
|
|
284
241
|
tag: [
|
|
285
242
|
{
|
|
286
243
|
tag: "span",
|
|
@@ -291,27 +248,27 @@ const ie = function(r, e) {
|
|
|
291
248
|
}
|
|
292
249
|
}
|
|
293
250
|
]
|
|
294
|
-
}),
|
|
251
|
+
}), Se = () => ({
|
|
295
252
|
tag: "b"
|
|
296
|
-
}),
|
|
253
|
+
}), Le = () => ({
|
|
297
254
|
tag: "s"
|
|
298
|
-
}),
|
|
255
|
+
}), Ae = () => ({
|
|
299
256
|
tag: "u"
|
|
300
|
-
}),
|
|
257
|
+
}), Re = () => ({
|
|
301
258
|
tag: "strong"
|
|
302
|
-
}),
|
|
259
|
+
}), xe = () => ({
|
|
303
260
|
tag: "code"
|
|
304
|
-
}),
|
|
261
|
+
}), je = () => ({
|
|
305
262
|
tag: "i"
|
|
306
|
-
}),
|
|
263
|
+
}), Oe = (r) => {
|
|
307
264
|
if (!r.attrs)
|
|
308
265
|
return {
|
|
309
266
|
tag: ""
|
|
310
267
|
};
|
|
311
|
-
const e = new
|
|
312
|
-
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")),
|
|
313
|
-
for (const
|
|
314
|
-
t[
|
|
268
|
+
const e = new ge().escapeHTML, t = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
|
|
269
|
+
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), fe(o) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
270
|
+
for (const n in t.custom)
|
|
271
|
+
t[n] = t.custom[n];
|
|
315
272
|
delete t.custom;
|
|
316
273
|
}
|
|
317
274
|
return {
|
|
@@ -329,18 +286,18 @@ const ie = function(r, e) {
|
|
|
329
286
|
attrs: r.attrs
|
|
330
287
|
}
|
|
331
288
|
]
|
|
332
|
-
}),
|
|
289
|
+
}), Me = () => ({
|
|
333
290
|
tag: "sub"
|
|
334
|
-
}),
|
|
291
|
+
}), Ne = () => ({
|
|
335
292
|
tag: "sup"
|
|
336
|
-
}),
|
|
293
|
+
}), Pe = (r) => ({
|
|
337
294
|
tag: [
|
|
338
295
|
{
|
|
339
296
|
tag: "span",
|
|
340
297
|
attrs: r.attrs
|
|
341
298
|
}
|
|
342
299
|
]
|
|
343
|
-
}),
|
|
300
|
+
}), Be = (r) => {
|
|
344
301
|
var e;
|
|
345
302
|
return (e = r.attrs) != null && e.color ? {
|
|
346
303
|
tag: [
|
|
@@ -354,7 +311,7 @@ const ie = function(r, e) {
|
|
|
354
311
|
} : {
|
|
355
312
|
tag: ""
|
|
356
313
|
};
|
|
357
|
-
},
|
|
314
|
+
}, De = (r) => {
|
|
358
315
|
var e;
|
|
359
316
|
return (e = r.attrs) != null && e.color ? {
|
|
360
317
|
tag: [
|
|
@@ -368,49 +325,49 @@ const ie = function(r, e) {
|
|
|
368
325
|
} : {
|
|
369
326
|
tag: ""
|
|
370
327
|
};
|
|
371
|
-
},
|
|
328
|
+
}, Ue = {
|
|
372
329
|
nodes: {
|
|
373
|
-
horizontal_rule:
|
|
374
|
-
blockquote:
|
|
375
|
-
bullet_list:
|
|
376
|
-
code_block:
|
|
377
|
-
hard_break:
|
|
378
|
-
heading:
|
|
379
|
-
image:
|
|
380
|
-
list_item:
|
|
381
|
-
ordered_list:
|
|
382
|
-
paragraph:
|
|
383
|
-
emoji:
|
|
330
|
+
horizontal_rule: be,
|
|
331
|
+
blockquote: ye,
|
|
332
|
+
bullet_list: me,
|
|
333
|
+
code_block: ke,
|
|
334
|
+
hard_break: $e,
|
|
335
|
+
heading: we,
|
|
336
|
+
image: Te,
|
|
337
|
+
list_item: Ee,
|
|
338
|
+
ordered_list: Ce,
|
|
339
|
+
paragraph: ve,
|
|
340
|
+
emoji: Ie
|
|
384
341
|
},
|
|
385
342
|
marks: {
|
|
386
|
-
bold:
|
|
387
|
-
strike:
|
|
388
|
-
underline:
|
|
389
|
-
strong:
|
|
390
|
-
code:
|
|
391
|
-
italic:
|
|
392
|
-
link:
|
|
343
|
+
bold: Se,
|
|
344
|
+
strike: Le,
|
|
345
|
+
underline: Ae,
|
|
346
|
+
strong: Re,
|
|
347
|
+
code: xe,
|
|
348
|
+
italic: je,
|
|
349
|
+
link: Oe,
|
|
393
350
|
styled: _e,
|
|
394
|
-
subscript:
|
|
395
|
-
superscript:
|
|
396
|
-
anchor:
|
|
397
|
-
highlight:
|
|
398
|
-
textStyle:
|
|
351
|
+
subscript: Me,
|
|
352
|
+
superscript: Ne,
|
|
353
|
+
anchor: Pe,
|
|
354
|
+
highlight: Be,
|
|
355
|
+
textStyle: De
|
|
399
356
|
}
|
|
400
|
-
},
|
|
357
|
+
}, ze = function(r) {
|
|
401
358
|
const e = {
|
|
402
359
|
"&": "&",
|
|
403
360
|
"<": "<",
|
|
404
361
|
">": ">",
|
|
405
362
|
'"': """,
|
|
406
363
|
"'": "'"
|
|
407
|
-
}, t = /[&<>"']/g,
|
|
408
|
-
return r &&
|
|
364
|
+
}, t = /[&<>"']/g, o = new RegExp(t.source);
|
|
365
|
+
return r && o.test(r) ? r.replace(t, (n) => e[n]) : r;
|
|
409
366
|
};
|
|
410
|
-
let
|
|
411
|
-
class
|
|
367
|
+
let D = !1;
|
|
368
|
+
class He {
|
|
412
369
|
constructor(e) {
|
|
413
|
-
|
|
370
|
+
v(this, "marks"), v(this, "nodes"), e || (e = Ue), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
414
371
|
}
|
|
415
372
|
addNode(e, t) {
|
|
416
373
|
this.nodes[e] = t;
|
|
@@ -418,14 +375,14 @@ class C {
|
|
|
418
375
|
addMark(e, t) {
|
|
419
376
|
this.marks[e] = t;
|
|
420
377
|
}
|
|
421
|
-
render(e, t = { optimizeImages: !1 },
|
|
422
|
-
if (!
|
|
378
|
+
render(e, t = { optimizeImages: !1 }, o = !0) {
|
|
379
|
+
if (!D && o && (console.warn(
|
|
423
380
|
"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/"
|
|
424
|
-
),
|
|
425
|
-
let
|
|
426
|
-
return e.content.forEach((
|
|
427
|
-
|
|
428
|
-
}), t.optimizeImages ? this.optimizeImages(
|
|
381
|
+
), D = !0), e && e.content && Array.isArray(e.content)) {
|
|
382
|
+
let n = "";
|
|
383
|
+
return e.content.forEach((s) => {
|
|
384
|
+
n += this.renderNode(s);
|
|
385
|
+
}), t.optimizeImages ? this.optimizeImages(n, t.optimizeImages) : n;
|
|
429
386
|
}
|
|
430
387
|
return console.warn(
|
|
431
388
|
`The render method must receive an Object with a "content" field.
|
|
@@ -455,64 +412,64 @@ class C {
|
|
|
455
412
|
), "";
|
|
456
413
|
}
|
|
457
414
|
optimizeImages(e, t) {
|
|
458
|
-
let
|
|
459
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
460
|
-
const
|
|
415
|
+
let o = 0, n = 0, s = "", l = "";
|
|
416
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (s += `width="${t.width}" `, o = t.width), typeof t.height == "number" && t.height > 0 && (s += `height="${t.height}" `, n = t.height), (t.loading === "lazy" || t.loading === "eager") && (s += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (s += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (l += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (l += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (l += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (l += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (l += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (l += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (l += `:rotate(${t.filters.rotate})`), l.length > 0 && (l = `/filters${l}`))), s.length > 0 && (e = e.replace(/<img/g, `<img ${s.trim()}`));
|
|
417
|
+
const d = o > 0 || n > 0 || l.length > 0 ? `${o}x${n}${l}` : "";
|
|
461
418
|
return e = e.replace(
|
|
462
419
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
463
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
464
|
-
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (
|
|
465
|
-
var
|
|
466
|
-
const
|
|
420
|
+
`a.storyblok.com/f/$1/$2.$3/m/${d}`
|
|
421
|
+
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (i) => {
|
|
422
|
+
var p, g;
|
|
423
|
+
const $ = i.match(
|
|
467
424
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
468
425
|
);
|
|
469
|
-
if (
|
|
470
|
-
const
|
|
471
|
-
srcset: (
|
|
472
|
-
if (typeof
|
|
473
|
-
return `//${
|
|
474
|
-
if (typeof
|
|
475
|
-
let
|
|
476
|
-
return typeof
|
|
426
|
+
if ($ && $.length > 0) {
|
|
427
|
+
const E = {
|
|
428
|
+
srcset: (p = t.srcset) == null ? void 0 : p.map((m) => {
|
|
429
|
+
if (typeof m == "number")
|
|
430
|
+
return `//${$}/m/${m}x0${l} ${m}w`;
|
|
431
|
+
if (typeof m == "object" && m.length === 2) {
|
|
432
|
+
let I = 0, S = 0;
|
|
433
|
+
return typeof m[0] == "number" && (I = m[0]), typeof m[1] == "number" && (S = m[1]), `//${$}/m/${I}x${S}${l} ${I}w`;
|
|
477
434
|
}
|
|
478
435
|
return "";
|
|
479
436
|
}).join(", "),
|
|
480
|
-
sizes: (
|
|
437
|
+
sizes: (g = t.sizes) == null ? void 0 : g.map((m) => m).join(", ")
|
|
481
438
|
};
|
|
482
|
-
let
|
|
483
|
-
return
|
|
439
|
+
let w = "";
|
|
440
|
+
return E.srcset && (w += `srcset="${E.srcset}" `), E.sizes && (w += `sizes="${E.sizes}" `), i.replace(/<img/g, `<img ${w.trim()}`);
|
|
484
441
|
}
|
|
485
|
-
return
|
|
442
|
+
return i;
|
|
486
443
|
})), e;
|
|
487
444
|
}
|
|
488
445
|
renderNode(e) {
|
|
489
446
|
const t = [];
|
|
490
|
-
e.marks && e.marks.forEach((
|
|
491
|
-
const
|
|
492
|
-
|
|
447
|
+
e.marks && e.marks.forEach((n) => {
|
|
448
|
+
const s = this.getMatchingMark(n);
|
|
449
|
+
s && s.tag !== "" && t.push(this.renderOpeningTag(s.tag));
|
|
493
450
|
});
|
|
494
|
-
const
|
|
495
|
-
return
|
|
496
|
-
t.push(this.renderNode(
|
|
497
|
-
}) : e.text ? t.push(
|
|
498
|
-
const
|
|
499
|
-
|
|
451
|
+
const o = this.getMatchingNode(e);
|
|
452
|
+
return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((n) => {
|
|
453
|
+
t.push(this.renderNode(n));
|
|
454
|
+
}) : e.text ? t.push(ze(e.text)) : o && o.singleTag ? t.push(this.renderTag(o.singleTag, " /")) : o && o.html ? t.push(o.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), o && o.tag && t.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((n) => {
|
|
455
|
+
const s = this.getMatchingMark(n);
|
|
456
|
+
s && s.tag !== "" && t.push(this.renderClosingTag(s.tag));
|
|
500
457
|
}), t.join("");
|
|
501
458
|
}
|
|
502
459
|
renderTag(e, t) {
|
|
503
|
-
return e.constructor === String ? `<${e}${t}>` : e.map((
|
|
504
|
-
if (
|
|
505
|
-
return `<${
|
|
460
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
|
|
461
|
+
if (o.constructor === String)
|
|
462
|
+
return `<${o}${t}>`;
|
|
506
463
|
{
|
|
507
|
-
let
|
|
508
|
-
if (
|
|
509
|
-
for (const
|
|
510
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
511
|
-
const
|
|
512
|
-
|
|
464
|
+
let n = `<${o.tag}`;
|
|
465
|
+
if (o.attrs) {
|
|
466
|
+
for (const s in o.attrs)
|
|
467
|
+
if (Object.prototype.hasOwnProperty.call(o.attrs, s)) {
|
|
468
|
+
const l = o.attrs[s];
|
|
469
|
+
l !== null && (n += ` ${s}="${l}"`);
|
|
513
470
|
}
|
|
514
471
|
}
|
|
515
|
-
return `${
|
|
472
|
+
return `${n}${t}>`;
|
|
516
473
|
}
|
|
517
474
|
}).join("");
|
|
518
475
|
}
|
|
@@ -549,468 +506,7 @@ class C {
|
|
|
549
506
|
return this.renderTag(t, " /");
|
|
550
507
|
}
|
|
551
508
|
}
|
|
552
|
-
|
|
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 T();
|
|
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 U = "SB-Agent", A = {
|
|
640
|
-
defaultAgentName: "SB-JS-CLIENT",
|
|
641
|
-
defaultAgentVersion: "SB-Agent-Version",
|
|
642
|
-
packageVersion: "6.0.0"
|
|
643
|
-
};
|
|
644
|
-
let $ = {};
|
|
645
|
-
const y = {};
|
|
646
|
-
class Oe {
|
|
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 T().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(U) || (o.set(U, A.defaultAgentName), o.set(
|
|
663
|
-
A.defaultAgentVersion,
|
|
664
|
-
A.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 C(e.richTextSchema) : this.richTextResolver = new C(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ne(
|
|
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 T(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new je({
|
|
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
|
-
(p) => this.makeRequest(i, t, n, p + 1, o)
|
|
717
|
-
);
|
|
718
|
-
return this.helpers.flatMap([c, ...u], (p) => Object.values(p.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 m = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
933
|
-
await this.resolveStories(u.data, t, `${m}`);
|
|
934
|
-
}
|
|
935
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await i.set(n, u);
|
|
936
|
-
const p = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
937
|
-
return t.token && u.data.cv && (p && 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($[e]);
|
|
968
|
-
},
|
|
969
|
-
getAll() {
|
|
970
|
-
return Promise.resolve($);
|
|
971
|
-
},
|
|
972
|
-
set(e, t) {
|
|
973
|
-
return $[e] = t, Promise.resolve(void 0);
|
|
974
|
-
},
|
|
975
|
-
flush() {
|
|
976
|
-
return $ = {}, 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;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
const Ne = (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 Oe(e) };
|
|
1013
|
-
}, He = (r) => {
|
|
509
|
+
const rt = (r) => {
|
|
1014
510
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
1015
511
|
return {};
|
|
1016
512
|
try {
|
|
@@ -1025,69 +521,281 @@ const Ne = (r = {}) => {
|
|
|
1025
521
|
return {};
|
|
1026
522
|
}
|
|
1027
523
|
};
|
|
1028
|
-
|
|
1029
|
-
|
|
524
|
+
function Fe(r, e) {
|
|
525
|
+
if (!e)
|
|
526
|
+
return { src: r, attrs: {} };
|
|
527
|
+
let t = 0, o = 0;
|
|
528
|
+
const n = {}, s = [];
|
|
529
|
+
function l(i, p, g, $, E) {
|
|
530
|
+
typeof i != "number" || i <= p || i >= g ? console.warn(`[StoryblokRichText] - ${$.charAt(0).toUpperCase() + $.slice(1)} value must be a number between ${p} and ${g} (inclusive)`) : E.push(`${$}(${i})`);
|
|
531
|
+
}
|
|
532
|
+
if (typeof e == "object") {
|
|
533
|
+
if (typeof e.width == "number" && e.width > 0 ? (n.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (n.height = e.height, o = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (n.loading = e.loading), e.class && (n.class = e.class), e.filters) {
|
|
534
|
+
const { filters: i } = e || {}, { blur: p, brightness: g, fill: $, format: E, grayscale: w, quality: m, rotate: I } = i || {};
|
|
535
|
+
p && l(p, 0, 100, "blur", s), m && l(m, 0, 100, "quality", s), g && l(g, 0, 100, "brightness", s), $ && s.push(`fill(${$})`), w && s.push("grayscale()"), I && [0, 90, 180, 270].includes(e.filters.rotate || 0) && s.push(`rotate(${I})`), E && ["webp", "png", "jpeg"].includes(E) && s.push(`format(${E})`);
|
|
536
|
+
}
|
|
537
|
+
e.srcset && (n.srcset = e.srcset.map((i) => {
|
|
538
|
+
if (typeof i == "number")
|
|
539
|
+
return `${r}/m/${i}x0/${s.length > 0 ? `filters:${s.join(":")}` : ""} ${i}w`;
|
|
540
|
+
if (Array.isArray(i) && i.length === 2) {
|
|
541
|
+
const [p, g] = i;
|
|
542
|
+
return `${r}/m/${p}x${g}/${s.length > 0 ? `filters:${s.join(":")}` : ""} ${p}w`;
|
|
543
|
+
} else {
|
|
544
|
+
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
}).join(", ")), e.sizes && (n.sizes = e.sizes.join(", "));
|
|
548
|
+
}
|
|
549
|
+
let d = `${r}/m/`;
|
|
550
|
+
return t > 0 && o > 0 && (d = `${d}${t}x${o}/`), s.length > 0 && (d = `${d}filters:${s.join(":")}`), {
|
|
551
|
+
src: d,
|
|
552
|
+
attrs: n
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
var y = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r.TABLE = "table", r.TABLE_ROW = "tableRow", r.TABLE_CELL = "tableCell", r.TABLE_HEADER = "tableHeader", r))(y || {}), C = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(C || {}), F = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(F || {}), L = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(L || {});
|
|
556
|
+
const qe = [
|
|
557
|
+
"area",
|
|
558
|
+
"base",
|
|
559
|
+
"br",
|
|
560
|
+
"col",
|
|
561
|
+
"embed",
|
|
562
|
+
"hr",
|
|
563
|
+
"img",
|
|
564
|
+
"input",
|
|
565
|
+
"link",
|
|
566
|
+
"meta",
|
|
567
|
+
"param",
|
|
568
|
+
"source",
|
|
569
|
+
"track",
|
|
570
|
+
"wbr"
|
|
571
|
+
], Ge = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), Ke = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
|
|
572
|
+
function Je(r) {
|
|
573
|
+
return r.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
574
|
+
}
|
|
575
|
+
const R = (r) => Object.fromEntries(Object.entries(r).filter(([e, t]) => t !== void 0));
|
|
576
|
+
function U(r, e = {}, t) {
|
|
577
|
+
const o = Ge(e), n = o ? `${r} ${o}` : r, s = Array.isArray(t) ? t.join("") : t || "";
|
|
578
|
+
if (r) {
|
|
579
|
+
if (qe.includes(r))
|
|
580
|
+
return `<${n}>`;
|
|
581
|
+
} else return s;
|
|
582
|
+
return `<${n}>${s}</${r}>`;
|
|
583
|
+
}
|
|
584
|
+
function ot(r = {}) {
|
|
585
|
+
let e = 0;
|
|
586
|
+
const {
|
|
587
|
+
renderFn: t = U,
|
|
588
|
+
textFn: o = Je,
|
|
589
|
+
resolvers: n = {},
|
|
590
|
+
optimizeImages: s = !1,
|
|
591
|
+
keyedResolvers: l = !1
|
|
592
|
+
} = r, d = t !== U, i = (a) => (c) => {
|
|
593
|
+
const u = c.attrs || {};
|
|
594
|
+
return l && (u.key = `${a}-${e}`), t(a, u, c.children || null);
|
|
595
|
+
}, p = (a) => {
|
|
596
|
+
const { src: c, alt: u, title: f, srcset: T, sizes: b } = a.attrs || {};
|
|
597
|
+
let h = c, k = {};
|
|
598
|
+
if (s) {
|
|
599
|
+
const { src: X, attrs: Z } = Fe(c, s);
|
|
600
|
+
h = X, k = Z;
|
|
601
|
+
}
|
|
602
|
+
l && (k = {
|
|
603
|
+
...k,
|
|
604
|
+
key: `img-${e}`
|
|
605
|
+
});
|
|
606
|
+
const V = {
|
|
607
|
+
src: h,
|
|
608
|
+
alt: u,
|
|
609
|
+
title: f,
|
|
610
|
+
srcset: T,
|
|
611
|
+
sizes: b,
|
|
612
|
+
...k
|
|
613
|
+
};
|
|
614
|
+
return t("img", R(V));
|
|
615
|
+
}, g = (a) => {
|
|
616
|
+
const { level: c, ...u } = a.attrs || {}, f = {
|
|
617
|
+
...u
|
|
618
|
+
};
|
|
619
|
+
return l && (f.key = `h${c}-${e}`), t(`h${c}`, f, a.children);
|
|
620
|
+
}, $ = (a) => {
|
|
621
|
+
var c, u, f, T;
|
|
622
|
+
const b = t("img", {
|
|
623
|
+
src: (c = a.attrs) == null ? void 0 : c.fallbackImage,
|
|
624
|
+
alt: (u = a.attrs) == null ? void 0 : u.alt,
|
|
625
|
+
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
626
|
+
draggable: "false",
|
|
627
|
+
loading: "lazy"
|
|
628
|
+
}), h = {
|
|
629
|
+
"data-type": "emoji",
|
|
630
|
+
"data-name": (f = a.attrs) == null ? void 0 : f.name,
|
|
631
|
+
"data-emoji": (T = a.attrs) == null ? void 0 : T.emoji
|
|
632
|
+
};
|
|
633
|
+
return l && (h.key = `emoji-${e}`), t("span", h, b);
|
|
634
|
+
}, E = (a) => t("pre", {
|
|
635
|
+
...a.attrs,
|
|
636
|
+
key: `code-${e}`
|
|
637
|
+
}, t("code", { key: `code-${e}` }, a.children || "")), w = (a, c = !1) => ({ text: u, attrs: f }) => {
|
|
638
|
+
const { class: T, id: b, ...h } = f || {}, k = c ? {
|
|
639
|
+
class: T,
|
|
640
|
+
id: b,
|
|
641
|
+
style: Ke(h) || void 0
|
|
642
|
+
} : f || {};
|
|
643
|
+
return l && (k.key = `${a}-${e}`), t(a, R(k), u);
|
|
644
|
+
}, m = (a) => x(a), I = (a) => {
|
|
645
|
+
const { marks: c, ...u } = a;
|
|
646
|
+
return "text" in a ? c ? c.reduce(
|
|
647
|
+
(f, T) => m({ ...T, text: f }),
|
|
648
|
+
// Fix: Ensure render function returns a string
|
|
649
|
+
m({ ...u, children: u.children })
|
|
650
|
+
// Fix: Cast children to string
|
|
651
|
+
) : o(u.text) : "";
|
|
652
|
+
}, S = (a) => {
|
|
653
|
+
const { linktype: c, href: u, anchor: f, ...T } = a.attrs || {};
|
|
654
|
+
let b = "";
|
|
655
|
+
switch (c) {
|
|
656
|
+
case L.ASSET:
|
|
657
|
+
case L.URL:
|
|
658
|
+
b = u;
|
|
659
|
+
break;
|
|
660
|
+
case L.EMAIL:
|
|
661
|
+
b = `mailto:${u}`;
|
|
662
|
+
break;
|
|
663
|
+
case L.STORY:
|
|
664
|
+
b = u, f && (b = `${b}#${f}`);
|
|
665
|
+
break;
|
|
666
|
+
default:
|
|
667
|
+
b = u;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
const h = { ...T };
|
|
671
|
+
return b && (h.href = b), l && (h.key = `a-${e}`), t("a", h, a.text);
|
|
672
|
+
}, q = (a) => {
|
|
673
|
+
var c, u;
|
|
674
|
+
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
|
|
675
|
+
blok: (c = a == null ? void 0 : a.attrs) == null ? void 0 : c.body[0],
|
|
676
|
+
id: (u = a.attrs) == null ? void 0 : u.id,
|
|
677
|
+
key: `component-${e}`,
|
|
678
|
+
style: "display: none"
|
|
679
|
+
});
|
|
680
|
+
}, G = (a) => {
|
|
681
|
+
const c = {};
|
|
682
|
+
return l && (c.key = `table-${e}`), t("table", c, a.children);
|
|
683
|
+
}, K = (a) => {
|
|
684
|
+
const c = {};
|
|
685
|
+
return l && (c.key = `tr-${e}`), t("tr", c, a.children);
|
|
686
|
+
}, J = (a) => {
|
|
687
|
+
const { colspan: c, rowspan: u, colwidth: f, backgroundColor: T, ...b } = a.attrs || {}, h = {
|
|
688
|
+
...b
|
|
689
|
+
};
|
|
690
|
+
c > 1 && (h.colspan = c), u > 1 && (h.rowspan = u);
|
|
691
|
+
const k = [];
|
|
692
|
+
return f && k.push(`width: ${f}px;`), T && k.push(`background-color: ${T};`), k.length > 0 && (h.style = k.join(" ")), l && (h.key = `td-${e}`), t("td", R(h), a.children);
|
|
693
|
+
}, W = (a) => {
|
|
694
|
+
const { colspan: c, rowspan: u, colwidth: f, backgroundColor: T, ...b } = a.attrs || {}, h = {
|
|
695
|
+
...b
|
|
696
|
+
};
|
|
697
|
+
c > 1 && (h.colspan = c), u > 1 && (h.rowspan = u);
|
|
698
|
+
const k = [];
|
|
699
|
+
return f && k.push(`width: ${f}px;`), T && k.push(`background-color: ${T};`), k.length > 0 && (h.style = k.join(" ")), l && (h.key = `th-${e}`), t("th", R(h), a.children);
|
|
700
|
+
}, Y = new Map([
|
|
701
|
+
[y.DOCUMENT, i("")],
|
|
702
|
+
[y.HEADING, g],
|
|
703
|
+
[y.PARAGRAPH, i("p")],
|
|
704
|
+
[y.UL_LIST, i("ul")],
|
|
705
|
+
[y.OL_LIST, i("ol")],
|
|
706
|
+
[y.LIST_ITEM, i("li")],
|
|
707
|
+
[y.IMAGE, p],
|
|
708
|
+
[y.EMOJI, $],
|
|
709
|
+
[y.CODE_BLOCK, E],
|
|
710
|
+
[y.HR, i("hr")],
|
|
711
|
+
[y.BR, i("br")],
|
|
712
|
+
[y.QUOTE, i("blockquote")],
|
|
713
|
+
[y.COMPONENT, q],
|
|
714
|
+
[F.TEXT, I],
|
|
715
|
+
[C.LINK, S],
|
|
716
|
+
[C.ANCHOR, S],
|
|
717
|
+
[C.STYLED, w("span", !0)],
|
|
718
|
+
[C.BOLD, w("strong")],
|
|
719
|
+
[C.TEXT_STYLE, w("span", !0)],
|
|
720
|
+
[C.ITALIC, w("em")],
|
|
721
|
+
[C.UNDERLINE, w("u")],
|
|
722
|
+
[C.STRIKE, w("s")],
|
|
723
|
+
[C.CODE, w("code")],
|
|
724
|
+
[C.SUPERSCRIPT, w("sup")],
|
|
725
|
+
[C.SUBSCRIPT, w("sub")],
|
|
726
|
+
[C.HIGHLIGHT, w("mark")],
|
|
727
|
+
[y.TABLE, G],
|
|
728
|
+
[y.TABLE_ROW, K],
|
|
729
|
+
[y.TABLE_CELL, J],
|
|
730
|
+
[y.TABLE_HEADER, W],
|
|
731
|
+
...Object.entries(n).map(([a, c]) => [a, c])
|
|
732
|
+
]);
|
|
733
|
+
function A(a) {
|
|
734
|
+
e += 1;
|
|
735
|
+
const c = Y.get(a.type);
|
|
736
|
+
if (!c)
|
|
737
|
+
return console.error("<Storyblok>", `No resolver found for node type ${a.type}`), "";
|
|
738
|
+
if (a.type === "text")
|
|
739
|
+
return c(a);
|
|
740
|
+
const u = a.content ? a.content.map(x) : void 0;
|
|
741
|
+
return c({
|
|
742
|
+
...a,
|
|
743
|
+
children: u
|
|
744
|
+
// Fix: Update the type of 'children' to Node[]
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
function x(a) {
|
|
748
|
+
return a.type === "doc" ? d ? a.content.map(A) : a.content.map(A).join("") : Array.isArray(a) ? a.map(A) : A(a);
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
render: x
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
let We, Ye = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
755
|
+
const Ve = (r, e) => {
|
|
1030
756
|
r.addNode("blok", (t) => {
|
|
1031
|
-
let
|
|
1032
|
-
return t.attrs.body.forEach((
|
|
1033
|
-
|
|
757
|
+
let o = "";
|
|
758
|
+
return t.attrs.body.forEach((n) => {
|
|
759
|
+
o += e(n.component, n);
|
|
1034
760
|
}), {
|
|
1035
|
-
html:
|
|
761
|
+
html: o
|
|
1036
762
|
};
|
|
1037
763
|
});
|
|
1038
|
-
},
|
|
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((p) => {
|
|
1052
|
-
h = { ...h, ...p(c) };
|
|
1053
|
-
}), l && (I = 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 && D(I), R = new C(a.schema), a.resolver && z(R, a.resolver), h;
|
|
1056
|
-
}, Ue = (r) => {
|
|
764
|
+
}, Xe = (r) => {
|
|
1057
765
|
var e;
|
|
1058
766
|
return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
|
1059
|
-
},
|
|
1060
|
-
let
|
|
1061
|
-
if (!
|
|
767
|
+
}, Ze = (r, e, t) => {
|
|
768
|
+
let o = t || We;
|
|
769
|
+
if (!o) {
|
|
1062
770
|
console.error(
|
|
1063
771
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1064
772
|
);
|
|
1065
773
|
return;
|
|
1066
774
|
}
|
|
1067
|
-
return
|
|
1068
|
-
},
|
|
1069
|
-
function
|
|
1070
|
-
if (!globalThis.storyblokApiInstance)
|
|
775
|
+
return Xe(r) ? "" : (e && (o = new He(e.schema), e.resolver && Ve(o, e.resolver)), o.render(r, {}, !1));
|
|
776
|
+
}, st = () => ue(Ye);
|
|
777
|
+
function nt() {
|
|
778
|
+
if (!(globalThis != null && globalThis.storyblokApiInstance))
|
|
1071
779
|
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
1072
780
|
return globalThis.storyblokApiInstance;
|
|
1073
781
|
}
|
|
1074
|
-
async function
|
|
782
|
+
async function at(r) {
|
|
1075
783
|
let e = null;
|
|
1076
784
|
return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
|
|
1077
785
|
}
|
|
1078
|
-
function
|
|
1079
|
-
var
|
|
1080
|
-
const t = (
|
|
786
|
+
function lt(r, e) {
|
|
787
|
+
var o;
|
|
788
|
+
const t = (o = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : o.richTextResolver;
|
|
1081
789
|
if (!t)
|
|
1082
790
|
throw new Error(
|
|
1083
791
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1084
792
|
);
|
|
1085
|
-
return
|
|
793
|
+
return Ze(r, e, t);
|
|
1086
794
|
}
|
|
1087
|
-
function
|
|
795
|
+
function Qe(r) {
|
|
1088
796
|
return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
1089
797
|
}
|
|
1090
|
-
function
|
|
798
|
+
function it(r) {
|
|
1091
799
|
const e = {
|
|
1092
800
|
useCustomApi: !1,
|
|
1093
801
|
bridge: !0,
|
|
@@ -1095,45 +803,45 @@ function Ze(r) {
|
|
|
1095
803
|
enableFallbackComponent: !1,
|
|
1096
804
|
livePreview: !1,
|
|
1097
805
|
...r
|
|
1098
|
-
}, t =
|
|
806
|
+
}, t = Qe(e.bridge);
|
|
1099
807
|
return {
|
|
1100
808
|
name: "@storyblok/astro",
|
|
1101
809
|
hooks: {
|
|
1102
810
|
"astro:config:setup": ({
|
|
1103
|
-
injectScript:
|
|
1104
|
-
updateConfig:
|
|
1105
|
-
addDevToolbarApp:
|
|
1106
|
-
addMiddleware:
|
|
1107
|
-
config:
|
|
811
|
+
injectScript: o,
|
|
812
|
+
updateConfig: n,
|
|
813
|
+
addDevToolbarApp: s,
|
|
814
|
+
addMiddleware: l,
|
|
815
|
+
config: d
|
|
1108
816
|
}) => {
|
|
1109
|
-
if (
|
|
817
|
+
if (n({
|
|
1110
818
|
vite: {
|
|
1111
819
|
plugins: [
|
|
1112
|
-
|
|
820
|
+
ie(
|
|
1113
821
|
e.accessToken,
|
|
1114
822
|
e.useCustomApi,
|
|
1115
823
|
e.apiOptions
|
|
1116
824
|
),
|
|
1117
|
-
|
|
825
|
+
le(
|
|
1118
826
|
e.componentsDir,
|
|
1119
827
|
e.components,
|
|
1120
828
|
e.enableFallbackComponent,
|
|
1121
829
|
e.customFallbackComponent
|
|
1122
830
|
),
|
|
1123
|
-
|
|
831
|
+
ce(e)
|
|
1124
832
|
]
|
|
1125
833
|
}
|
|
1126
|
-
}), e.livePreview && (
|
|
834
|
+
}), e.livePreview && (d == null ? void 0 : d.output) !== "server")
|
|
1127
835
|
throw new Error(
|
|
1128
836
|
"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."
|
|
1129
837
|
);
|
|
1130
|
-
|
|
838
|
+
o(
|
|
1131
839
|
"page-ssr",
|
|
1132
840
|
`
|
|
1133
841
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
1134
842
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
1135
843
|
`
|
|
1136
|
-
), e.bridge && !e.livePreview &&
|
|
844
|
+
), e.bridge && !e.livePreview && o(
|
|
1137
845
|
"page",
|
|
1138
846
|
`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
1139
847
|
loadStoryblokBridge().then(() => {
|
|
@@ -1146,7 +854,7 @@ function Ze(r) {
|
|
|
1146
854
|
});
|
|
1147
855
|
});
|
|
1148
856
|
`
|
|
1149
|
-
), e.livePreview && (
|
|
857
|
+
), e.livePreview && (o(
|
|
1150
858
|
"page",
|
|
1151
859
|
`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
1152
860
|
loadStoryblokBridge().then(() => {
|
|
@@ -1155,84 +863,44 @@ function Ze(r) {
|
|
|
1155
863
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
1156
864
|
});
|
|
1157
865
|
`
|
|
1158
|
-
),
|
|
866
|
+
), l({
|
|
1159
867
|
entrypoint: "@storyblok/astro/middleware.ts",
|
|
1160
868
|
order: "pre"
|
|
1161
|
-
})),
|
|
869
|
+
})), s({
|
|
1162
870
|
id: "storyblok",
|
|
1163
871
|
name: "Storyblok",
|
|
1164
|
-
icon:
|
|
872
|
+
icon: Q,
|
|
1165
873
|
entrypoint: "@storyblok/astro/toolbarApp.ts"
|
|
1166
874
|
});
|
|
1167
875
|
}
|
|
1168
876
|
}
|
|
1169
877
|
};
|
|
1170
878
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
accessToken: e,
|
|
1174
|
-
use: t ? [] : [Ne],
|
|
1175
|
-
apiOptions: s
|
|
1176
|
-
});
|
|
1177
|
-
return {
|
|
1178
|
-
name: "story-loader",
|
|
1179
|
-
load: async ({ store: a, meta: l, logger: c, refreshContextData: h }) => {
|
|
1180
|
-
if (!i)
|
|
1181
|
-
throw new Error("storyblokApi is not loaded");
|
|
1182
|
-
if (h != null && h.story) {
|
|
1183
|
-
c.info("Syncing... story updated in Storyblok");
|
|
1184
|
-
const f = h.story;
|
|
1185
|
-
a.set({
|
|
1186
|
-
data: f,
|
|
1187
|
-
id: f.uuid
|
|
1188
|
-
});
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
c.info("Loading stories");
|
|
1192
|
-
const u = l.get("lastPublishedAt"), p = l.get("lastUpdatedAt"), m = l.get("version"), g = { version: o };
|
|
1193
|
-
u && o === "published" ? g.published_at_gt = u : p && (g.updated_at_gt = p), m !== o && (c.info("Version changed, clearing store"), a.clear()), l.set("version", o);
|
|
1194
|
-
const k = await (i == null ? void 0 : i.getAll("cdn/stories", {
|
|
1195
|
-
...g,
|
|
1196
|
-
...n
|
|
1197
|
-
}));
|
|
1198
|
-
c.info(`Fetched ${k.length} stories`);
|
|
1199
|
-
const b = (f) => f ? new Date(f) : null;
|
|
1200
|
-
let v = b(u), w = b(p);
|
|
1201
|
-
for (const f of k) {
|
|
1202
|
-
const S = b(f.published_at), _ = b(f.updated_at), H = S && (!v || S > v), q = _ && (!w || _ > w);
|
|
1203
|
-
H && (v = S), q && (w = _), a.set({
|
|
1204
|
-
data: f,
|
|
1205
|
-
id: f.uuid
|
|
1206
|
-
}), w && l.set("lastUpdatedAt", w.toISOString()), v && l.set("lastPublishedAt", v.toISOString());
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
}
|
|
1211
|
-
let F;
|
|
1212
|
-
async function Ke(r) {
|
|
879
|
+
let z;
|
|
880
|
+
async function ct(r) {
|
|
1213
881
|
const { action: e, story: t } = r || {};
|
|
1214
882
|
if (e === "input" && t) {
|
|
1215
|
-
const
|
|
1216
|
-
const
|
|
1217
|
-
if (
|
|
883
|
+
const o = async () => {
|
|
884
|
+
const s = await tt(t), l = document.body;
|
|
885
|
+
if (s.outerHTML === l.outerHTML)
|
|
1218
886
|
return;
|
|
1219
|
-
const
|
|
1220
|
-
|
|
887
|
+
const d = document.querySelector('[data-blok-focused="true"]');
|
|
888
|
+
et(l, s, d), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
|
|
1221
889
|
};
|
|
1222
|
-
clearTimeout(
|
|
890
|
+
clearTimeout(z), z = setTimeout(o, 500);
|
|
1223
891
|
}
|
|
1224
892
|
["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
|
|
1225
893
|
}
|
|
1226
|
-
function
|
|
894
|
+
function et(r, e, t) {
|
|
1227
895
|
if (t) {
|
|
1228
|
-
const
|
|
1229
|
-
`[data-blok-uid="${
|
|
896
|
+
const o = t.getAttribute("data-blok-uid"), n = e.querySelector(
|
|
897
|
+
`[data-blok-uid="${o}"]`
|
|
1230
898
|
);
|
|
1231
|
-
|
|
899
|
+
n && (n.setAttribute("data-blok-focused", "true"), t.replaceWith(n));
|
|
1232
900
|
} else
|
|
1233
901
|
r.replaceWith(e);
|
|
1234
902
|
}
|
|
1235
|
-
async function
|
|
903
|
+
async function tt(r) {
|
|
1236
904
|
const t = await (await fetch(location.href, {
|
|
1237
905
|
method: "POST",
|
|
1238
906
|
body: JSON.stringify({
|
|
@@ -1246,15 +914,16 @@ async function ze(r) {
|
|
|
1246
914
|
return new DOMParser().parseFromString(t, "text/html").body;
|
|
1247
915
|
}
|
|
1248
916
|
export {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
917
|
+
He as RichTextResolver,
|
|
918
|
+
Ue as RichTextSchema,
|
|
919
|
+
F as TextTypes,
|
|
920
|
+
at as getLiveStory,
|
|
921
|
+
ct as handleStoryblokMessage,
|
|
922
|
+
st as loadStoryblokBridge,
|
|
923
|
+
lt as renderRichText,
|
|
924
|
+
ot as richTextResolver,
|
|
925
|
+
it as storyblok,
|
|
926
|
+
rt as storyblokEditable,
|
|
927
|
+
N as toCamelCase,
|
|
928
|
+
nt as useStoryblokApi
|
|
1260
929
|
};
|