@storyblok/astro 6.1.0 → 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/index.d.ts +1 -1
- package/dist/storyblok-astro.es.js +547 -315
- package/dist/storyblok-astro.umd.js +12 -12
- package/package.json +4 -2
|
@@ -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 E = `<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
|
|
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
12
|
for (let i = 0; i < r.length; i++) {
|
|
13
|
-
const
|
|
14
|
-
|
|
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
|
-
if (
|
|
21
|
+
if (e = {
|
|
22
22
|
pascalCase: !1,
|
|
23
23
|
preserveConsecutiveUppercase: !1,
|
|
24
|
-
...
|
|
25
|
-
}, Array.isArray(r) ? r = r.map((
|
|
24
|
+
...e
|
|
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
|
|
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
|
-
|
|
50
|
-
else if (
|
|
51
|
-
i.push(
|
|
48
|
+
if (E)
|
|
49
|
+
d.push(`import ${N(g)} from "${E.id}"`);
|
|
50
|
+
else if (t)
|
|
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
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
const
|
|
57
|
+
let p = "";
|
|
58
|
+
if (t)
|
|
59
|
+
if (p = ",FallbackComponent", o) {
|
|
60
|
+
const g = await this.resolve(
|
|
61
61
|
`/${r}/${o}.astro`
|
|
62
62
|
);
|
|
63
|
-
if (!
|
|
63
|
+
if (!g)
|
|
64
64
|
throw new Error(
|
|
65
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
|
-
if (Object.values(
|
|
75
|
-
return `${
|
|
76
|
-
if (
|
|
77
|
-
return `${
|
|
74
|
+
if (Object.values(e).length)
|
|
75
|
+
return `${d.join(";")};export default {${Object.keys(e).filter((g) => !i.includes(g)).map((g) => N(g)).join(",")}${p}}`;
|
|
76
|
+
if (t)
|
|
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,76 +84,76 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const o = "virtual:storyblok-init",
|
|
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({
|
|
100
100
|
accessToken: "${r}",
|
|
101
|
-
use: ${
|
|
102
|
-
apiOptions: ${JSON.stringify(
|
|
101
|
+
use: ${e ? "[]" : "[apiPlugin]"},
|
|
102
|
+
apiOptions: ${JSON.stringify(t)},
|
|
103
103
|
});
|
|
104
104
|
export const storyblokApiInstance = storyblokApi;
|
|
105
105
|
`;
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
const
|
|
109
|
+
function ce(r) {
|
|
110
|
+
const e = "virtual:storyblok-options", t = `\0${e}`;
|
|
111
111
|
return {
|
|
112
112
|
name: "vite-plugin-storyblok-options",
|
|
113
113
|
async resolveId(o) {
|
|
114
|
-
if (o ===
|
|
115
|
-
return
|
|
114
|
+
if (o === e)
|
|
115
|
+
return t;
|
|
116
116
|
},
|
|
117
117
|
async load(o) {
|
|
118
|
-
if (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
133
|
const o = document.createElement("script");
|
|
134
|
-
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (
|
|
135
|
-
|
|
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
136
|
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
137
137
|
});
|
|
138
|
-
var
|
|
139
|
-
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 {
|
|
140
140
|
constructor() {
|
|
141
|
-
|
|
142
|
-
...
|
|
143
|
-
per_page:
|
|
141
|
+
v(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), v(this, "getOptionsPage", (e, t = 25, o = 1) => ({
|
|
142
|
+
...e,
|
|
143
|
+
per_page: t,
|
|
144
144
|
page: o
|
|
145
|
-
})),
|
|
146
|
-
const o = Math.abs(
|
|
147
|
-
return this.arrayFrom(o, (
|
|
148
|
-
}),
|
|
149
|
-
const
|
|
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 = {
|
|
150
150
|
"&": "&",
|
|
151
151
|
"<": "<",
|
|
152
152
|
">": ">",
|
|
153
153
|
'"': """,
|
|
154
154
|
"'": "'"
|
|
155
|
-
}, o = /[&<>"']/g,
|
|
156
|
-
return
|
|
155
|
+
}, o = /[&<>"']/g, n = new RegExp(o.source);
|
|
156
|
+
return e && n.test(e) ? e.replace(o, (s) => t[s]) : e;
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
@@ -163,56 +163,56 @@ class U {
|
|
|
163
163
|
* @param {boolean} isArray
|
|
164
164
|
* @return {string} Stringified object
|
|
165
165
|
*/
|
|
166
|
-
stringify(
|
|
167
|
-
const
|
|
168
|
-
for (const
|
|
169
|
-
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))
|
|
170
170
|
continue;
|
|
171
|
-
const
|
|
171
|
+
const l = e[s], d = o ? "" : encodeURIComponent(s);
|
|
172
172
|
let i;
|
|
173
|
-
typeof
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Array.isArray(
|
|
177
|
-
) : 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);
|
|
178
178
|
}
|
|
179
|
-
return
|
|
179
|
+
return n.join("&");
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* @method getRegionURL
|
|
183
183
|
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
184
184
|
* @return {string} The base URL of the region
|
|
185
185
|
*/
|
|
186
|
-
getRegionURL(
|
|
187
|
-
const
|
|
188
|
-
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) {
|
|
189
189
|
case "us":
|
|
190
190
|
return o;
|
|
191
191
|
case "cn":
|
|
192
|
-
return s;
|
|
193
|
-
case "ap":
|
|
194
192
|
return n;
|
|
193
|
+
case "ap":
|
|
194
|
+
return s;
|
|
195
195
|
case "ca":
|
|
196
|
-
return
|
|
196
|
+
return l;
|
|
197
197
|
default:
|
|
198
|
-
return
|
|
198
|
+
return t;
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
const
|
|
203
|
-
const
|
|
202
|
+
const he = function(r, e) {
|
|
203
|
+
const t = {};
|
|
204
204
|
for (const o in r) {
|
|
205
|
-
const
|
|
206
|
-
|
|
205
|
+
const n = r[o];
|
|
206
|
+
e.includes(o) && n !== null && (t[o] = n);
|
|
207
207
|
}
|
|
208
|
-
return
|
|
209
|
-
},
|
|
208
|
+
return t;
|
|
209
|
+
}, fe = (r) => r === "email", be = () => ({
|
|
210
210
|
singleTag: "hr"
|
|
211
|
-
}),
|
|
211
|
+
}), ye = () => ({
|
|
212
212
|
tag: "blockquote"
|
|
213
|
-
}),
|
|
213
|
+
}), me = () => ({
|
|
214
214
|
tag: "ul"
|
|
215
|
-
}),
|
|
215
|
+
}), ke = (r) => ({
|
|
216
216
|
tag: [
|
|
217
217
|
"pre",
|
|
218
218
|
{
|
|
@@ -220,24 +220,24 @@ const q = function(r, t) {
|
|
|
220
220
|
attrs: r.attrs
|
|
221
221
|
}
|
|
222
222
|
]
|
|
223
|
-
}),
|
|
223
|
+
}), $e = () => ({
|
|
224
224
|
singleTag: "br"
|
|
225
|
-
}),
|
|
225
|
+
}), we = (r) => ({
|
|
226
226
|
tag: `h${r.attrs.level}`
|
|
227
|
-
}),
|
|
227
|
+
}), Te = (r) => ({
|
|
228
228
|
singleTag: [
|
|
229
229
|
{
|
|
230
230
|
tag: "img",
|
|
231
|
-
attrs:
|
|
231
|
+
attrs: he(r.attrs, ["src", "alt", "title"])
|
|
232
232
|
}
|
|
233
233
|
]
|
|
234
|
-
}),
|
|
234
|
+
}), Ee = () => ({
|
|
235
235
|
tag: "li"
|
|
236
|
-
}),
|
|
236
|
+
}), Ce = () => ({
|
|
237
237
|
tag: "ol"
|
|
238
|
-
}),
|
|
238
|
+
}), ve = () => ({
|
|
239
239
|
tag: "p"
|
|
240
|
-
}),
|
|
240
|
+
}), Ie = (r) => ({
|
|
241
241
|
tag: [
|
|
242
242
|
{
|
|
243
243
|
tag: "span",
|
|
@@ -248,58 +248,58 @@ const q = function(r, t) {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
]
|
|
251
|
-
}),
|
|
251
|
+
}), Se = () => ({
|
|
252
252
|
tag: "b"
|
|
253
|
-
}),
|
|
253
|
+
}), Le = () => ({
|
|
254
254
|
tag: "s"
|
|
255
|
-
}),
|
|
255
|
+
}), Ae = () => ({
|
|
256
256
|
tag: "u"
|
|
257
|
-
}),
|
|
257
|
+
}), Re = () => ({
|
|
258
258
|
tag: "strong"
|
|
259
|
-
}),
|
|
259
|
+
}), xe = () => ({
|
|
260
260
|
tag: "code"
|
|
261
|
-
}),
|
|
261
|
+
}), je = () => ({
|
|
262
262
|
tag: "i"
|
|
263
|
-
}),
|
|
263
|
+
}), Oe = (r) => {
|
|
264
264
|
if (!r.attrs)
|
|
265
265
|
return {
|
|
266
266
|
tag: ""
|
|
267
267
|
};
|
|
268
|
-
const
|
|
269
|
-
if (delete
|
|
270
|
-
for (const
|
|
271
|
-
|
|
272
|
-
delete
|
|
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];
|
|
272
|
+
delete t.custom;
|
|
273
273
|
}
|
|
274
274
|
return {
|
|
275
275
|
tag: [
|
|
276
276
|
{
|
|
277
277
|
tag: "a",
|
|
278
|
-
attrs:
|
|
278
|
+
attrs: t
|
|
279
279
|
}
|
|
280
280
|
]
|
|
281
281
|
};
|
|
282
|
-
},
|
|
282
|
+
}, _e = (r) => ({
|
|
283
283
|
tag: [
|
|
284
284
|
{
|
|
285
285
|
tag: "span",
|
|
286
286
|
attrs: r.attrs
|
|
287
287
|
}
|
|
288
288
|
]
|
|
289
|
-
}),
|
|
289
|
+
}), Me = () => ({
|
|
290
290
|
tag: "sub"
|
|
291
|
-
}),
|
|
291
|
+
}), Ne = () => ({
|
|
292
292
|
tag: "sup"
|
|
293
|
-
}),
|
|
293
|
+
}), Pe = (r) => ({
|
|
294
294
|
tag: [
|
|
295
295
|
{
|
|
296
296
|
tag: "span",
|
|
297
297
|
attrs: r.attrs
|
|
298
298
|
}
|
|
299
299
|
]
|
|
300
|
-
}),
|
|
301
|
-
var
|
|
302
|
-
return (
|
|
300
|
+
}), Be = (r) => {
|
|
301
|
+
var e;
|
|
302
|
+
return (e = r.attrs) != null && e.color ? {
|
|
303
303
|
tag: [
|
|
304
304
|
{
|
|
305
305
|
tag: "span",
|
|
@@ -311,9 +311,9 @@ const q = function(r, t) {
|
|
|
311
311
|
} : {
|
|
312
312
|
tag: ""
|
|
313
313
|
};
|
|
314
|
-
},
|
|
315
|
-
var
|
|
316
|
-
return (
|
|
314
|
+
}, De = (r) => {
|
|
315
|
+
var e;
|
|
316
|
+
return (e = r.attrs) != null && e.color ? {
|
|
317
317
|
tag: [
|
|
318
318
|
{
|
|
319
319
|
tag: "span",
|
|
@@ -325,64 +325,64 @@ const q = function(r, t) {
|
|
|
325
325
|
} : {
|
|
326
326
|
tag: ""
|
|
327
327
|
};
|
|
328
|
-
},
|
|
328
|
+
}, Ue = {
|
|
329
329
|
nodes: {
|
|
330
|
-
horizontal_rule:
|
|
331
|
-
blockquote:
|
|
332
|
-
bullet_list:
|
|
333
|
-
code_block:
|
|
334
|
-
hard_break:
|
|
335
|
-
heading:
|
|
336
|
-
image:
|
|
337
|
-
list_item:
|
|
338
|
-
ordered_list:
|
|
339
|
-
paragraph:
|
|
340
|
-
emoji:
|
|
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
|
|
341
341
|
},
|
|
342
342
|
marks: {
|
|
343
|
-
bold:
|
|
344
|
-
strike:
|
|
345
|
-
underline:
|
|
346
|
-
strong:
|
|
347
|
-
code:
|
|
348
|
-
italic:
|
|
349
|
-
link:
|
|
350
|
-
styled:
|
|
351
|
-
subscript:
|
|
352
|
-
superscript:
|
|
353
|
-
anchor:
|
|
354
|
-
highlight:
|
|
355
|
-
textStyle:
|
|
343
|
+
bold: Se,
|
|
344
|
+
strike: Le,
|
|
345
|
+
underline: Ae,
|
|
346
|
+
strong: Re,
|
|
347
|
+
code: xe,
|
|
348
|
+
italic: je,
|
|
349
|
+
link: Oe,
|
|
350
|
+
styled: _e,
|
|
351
|
+
subscript: Me,
|
|
352
|
+
superscript: Ne,
|
|
353
|
+
anchor: Pe,
|
|
354
|
+
highlight: Be,
|
|
355
|
+
textStyle: De
|
|
356
356
|
}
|
|
357
|
-
},
|
|
358
|
-
const
|
|
357
|
+
}, ze = function(r) {
|
|
358
|
+
const e = {
|
|
359
359
|
"&": "&",
|
|
360
360
|
"<": "<",
|
|
361
361
|
">": ">",
|
|
362
362
|
'"': """,
|
|
363
363
|
"'": "'"
|
|
364
|
-
},
|
|
365
|
-
return r && o.test(r) ? r.replace(
|
|
364
|
+
}, t = /[&<>"']/g, o = new RegExp(t.source);
|
|
365
|
+
return r && o.test(r) ? r.replace(t, (n) => e[n]) : r;
|
|
366
366
|
};
|
|
367
|
-
let
|
|
368
|
-
class
|
|
369
|
-
constructor(
|
|
370
|
-
|
|
367
|
+
let D = !1;
|
|
368
|
+
class He {
|
|
369
|
+
constructor(e) {
|
|
370
|
+
v(this, "marks"), v(this, "nodes"), e || (e = Ue), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
371
371
|
}
|
|
372
|
-
addNode(
|
|
373
|
-
this.nodes[
|
|
372
|
+
addNode(e, t) {
|
|
373
|
+
this.nodes[e] = t;
|
|
374
374
|
}
|
|
375
|
-
addMark(
|
|
376
|
-
this.marks[
|
|
375
|
+
addMark(e, t) {
|
|
376
|
+
this.marks[e] = t;
|
|
377
377
|
}
|
|
378
|
-
render(
|
|
379
|
-
if (!
|
|
378
|
+
render(e, t = { optimizeImages: !1 }, o = !0) {
|
|
379
|
+
if (!D && o && (console.warn(
|
|
380
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/"
|
|
381
|
-
),
|
|
382
|
-
let
|
|
383
|
-
return
|
|
384
|
-
|
|
385
|
-
}),
|
|
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;
|
|
386
386
|
}
|
|
387
387
|
return console.warn(
|
|
388
388
|
`The render method must receive an Object with a "content" field.
|
|
@@ -411,197 +411,427 @@ class be {
|
|
|
411
411
|
}`
|
|
412
412
|
), "";
|
|
413
413
|
}
|
|
414
|
-
optimizeImages(
|
|
415
|
-
let o = 0,
|
|
416
|
-
typeof
|
|
417
|
-
const
|
|
418
|
-
return
|
|
414
|
+
optimizeImages(e, t) {
|
|
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}` : "";
|
|
418
|
+
return e = e.replace(
|
|
419
419
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
420
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
421
|
-
), typeof
|
|
422
|
-
var
|
|
423
|
-
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(
|
|
424
424
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
425
425
|
);
|
|
426
|
-
if (
|
|
427
|
-
const
|
|
428
|
-
srcset: (
|
|
429
|
-
if (typeof
|
|
430
|
-
return `//${
|
|
431
|
-
if (typeof
|
|
432
|
-
let
|
|
433
|
-
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`;
|
|
434
434
|
}
|
|
435
435
|
return "";
|
|
436
436
|
}).join(", "),
|
|
437
|
-
sizes: (
|
|
437
|
+
sizes: (g = t.sizes) == null ? void 0 : g.map((m) => m).join(", ")
|
|
438
438
|
};
|
|
439
|
-
let
|
|
440
|
-
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()}`);
|
|
441
441
|
}
|
|
442
442
|
return i;
|
|
443
|
-
})),
|
|
443
|
+
})), e;
|
|
444
444
|
}
|
|
445
|
-
renderNode(
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
const
|
|
449
|
-
|
|
445
|
+
renderNode(e) {
|
|
446
|
+
const t = [];
|
|
447
|
+
e.marks && e.marks.forEach((n) => {
|
|
448
|
+
const s = this.getMatchingMark(n);
|
|
449
|
+
s && s.tag !== "" && t.push(this.renderOpeningTag(s.tag));
|
|
450
450
|
});
|
|
451
|
-
const o = this.getMatchingNode(
|
|
452
|
-
return o && o.tag &&
|
|
453
|
-
|
|
454
|
-
}) :
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
}),
|
|
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));
|
|
457
|
+
}), t.join("");
|
|
458
458
|
}
|
|
459
|
-
renderTag(
|
|
460
|
-
return
|
|
459
|
+
renderTag(e, t) {
|
|
460
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
|
|
461
461
|
if (o.constructor === String)
|
|
462
|
-
return `<${o}${
|
|
462
|
+
return `<${o}${t}>`;
|
|
463
463
|
{
|
|
464
|
-
let
|
|
464
|
+
let n = `<${o.tag}`;
|
|
465
465
|
if (o.attrs) {
|
|
466
|
-
for (const
|
|
467
|
-
if (Object.prototype.hasOwnProperty.call(o.attrs,
|
|
468
|
-
const
|
|
469
|
-
|
|
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}"`);
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
return `${
|
|
472
|
+
return `${n}${t}>`;
|
|
473
473
|
}
|
|
474
474
|
}).join("");
|
|
475
475
|
}
|
|
476
|
-
renderOpeningTag(
|
|
477
|
-
return this.renderTag(
|
|
476
|
+
renderOpeningTag(e) {
|
|
477
|
+
return this.renderTag(e, "");
|
|
478
478
|
}
|
|
479
|
-
renderClosingTag(
|
|
480
|
-
return
|
|
479
|
+
renderClosingTag(e) {
|
|
480
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
481
481
|
}
|
|
482
|
-
getMatchingNode(
|
|
483
|
-
const
|
|
484
|
-
if (typeof
|
|
485
|
-
return e
|
|
482
|
+
getMatchingNode(e) {
|
|
483
|
+
const t = this.nodes[e.type];
|
|
484
|
+
if (typeof t == "function")
|
|
485
|
+
return t(e);
|
|
486
486
|
}
|
|
487
|
-
getMatchingMark(
|
|
488
|
-
const
|
|
489
|
-
if (typeof
|
|
490
|
-
return e
|
|
487
|
+
getMatchingMark(e) {
|
|
488
|
+
const t = this.marks[e.type];
|
|
489
|
+
if (typeof t == "function")
|
|
490
|
+
return t(e);
|
|
491
491
|
}
|
|
492
|
-
renderEmoji(
|
|
493
|
-
if (
|
|
494
|
-
return
|
|
495
|
-
const
|
|
492
|
+
renderEmoji(e) {
|
|
493
|
+
if (e.attrs.emoji)
|
|
494
|
+
return e.attrs.emoji;
|
|
495
|
+
const t = [
|
|
496
496
|
{
|
|
497
497
|
tag: "img",
|
|
498
498
|
attrs: {
|
|
499
|
-
src:
|
|
499
|
+
src: e.attrs.fallbackImage,
|
|
500
500
|
draggable: "false",
|
|
501
501
|
loading: "lazy",
|
|
502
502
|
align: "absmiddle"
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
];
|
|
506
|
-
return this.renderTag(
|
|
506
|
+
return this.renderTag(t, " /");
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
-
const
|
|
509
|
+
const rt = (r) => {
|
|
510
510
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
511
511
|
return {};
|
|
512
512
|
try {
|
|
513
|
-
const
|
|
513
|
+
const e = JSON.parse(
|
|
514
514
|
r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
515
515
|
);
|
|
516
|
-
return
|
|
517
|
-
"data-blok-c": JSON.stringify(
|
|
518
|
-
"data-blok-uid": `${
|
|
516
|
+
return e ? {
|
|
517
|
+
"data-blok-c": JSON.stringify(e),
|
|
518
|
+
"data-blok-uid": `${e.id}-${e.uid}`
|
|
519
519
|
} : {};
|
|
520
520
|
} catch {
|
|
521
521
|
return {};
|
|
522
522
|
}
|
|
523
523
|
};
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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) => {
|
|
756
|
+
r.addNode("blok", (t) => {
|
|
527
757
|
let o = "";
|
|
528
|
-
return
|
|
529
|
-
o +=
|
|
758
|
+
return t.attrs.body.forEach((n) => {
|
|
759
|
+
o += e(n.component, n);
|
|
530
760
|
}), {
|
|
531
761
|
html: o
|
|
532
762
|
};
|
|
533
763
|
});
|
|
534
|
-
},
|
|
535
|
-
var
|
|
536
|
-
return !r || !((
|
|
537
|
-
},
|
|
538
|
-
let o =
|
|
764
|
+
}, Xe = (r) => {
|
|
765
|
+
var e;
|
|
766
|
+
return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
|
767
|
+
}, Ze = (r, e, t) => {
|
|
768
|
+
let o = t || We;
|
|
539
769
|
if (!o) {
|
|
540
770
|
console.error(
|
|
541
771
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
542
772
|
);
|
|
543
773
|
return;
|
|
544
774
|
}
|
|
545
|
-
return
|
|
546
|
-
},
|
|
547
|
-
function
|
|
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() {
|
|
548
778
|
if (!(globalThis != null && globalThis.storyblokApiInstance))
|
|
549
779
|
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
550
780
|
return globalThis.storyblokApiInstance;
|
|
551
781
|
}
|
|
552
|
-
async function
|
|
553
|
-
let
|
|
554
|
-
return r && r.locals._storyblok_preview_data && (
|
|
782
|
+
async function at(r) {
|
|
783
|
+
let e = null;
|
|
784
|
+
return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
|
|
555
785
|
}
|
|
556
|
-
function
|
|
786
|
+
function lt(r, e) {
|
|
557
787
|
var o;
|
|
558
|
-
const
|
|
559
|
-
if (!
|
|
788
|
+
const t = (o = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : o.richTextResolver;
|
|
789
|
+
if (!t)
|
|
560
790
|
throw new Error(
|
|
561
791
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
562
792
|
);
|
|
563
|
-
return
|
|
793
|
+
return Ze(r, e, t);
|
|
564
794
|
}
|
|
565
|
-
function
|
|
795
|
+
function Qe(r) {
|
|
566
796
|
return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
567
797
|
}
|
|
568
|
-
function
|
|
569
|
-
const
|
|
798
|
+
function it(r) {
|
|
799
|
+
const e = {
|
|
570
800
|
useCustomApi: !1,
|
|
571
801
|
bridge: !0,
|
|
572
802
|
componentsDir: "src",
|
|
573
803
|
enableFallbackComponent: !1,
|
|
574
804
|
livePreview: !1,
|
|
575
805
|
...r
|
|
576
|
-
},
|
|
806
|
+
}, t = Qe(e.bridge);
|
|
577
807
|
return {
|
|
578
808
|
name: "@storyblok/astro",
|
|
579
809
|
hooks: {
|
|
580
810
|
"astro:config:setup": ({
|
|
581
811
|
injectScript: o,
|
|
582
|
-
updateConfig:
|
|
583
|
-
addDevToolbarApp:
|
|
584
|
-
addMiddleware:
|
|
585
|
-
config:
|
|
812
|
+
updateConfig: n,
|
|
813
|
+
addDevToolbarApp: s,
|
|
814
|
+
addMiddleware: l,
|
|
815
|
+
config: d
|
|
586
816
|
}) => {
|
|
587
|
-
if (
|
|
817
|
+
if (n({
|
|
588
818
|
vite: {
|
|
589
819
|
plugins: [
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
820
|
+
ie(
|
|
821
|
+
e.accessToken,
|
|
822
|
+
e.useCustomApi,
|
|
823
|
+
e.apiOptions
|
|
594
824
|
),
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
825
|
+
le(
|
|
826
|
+
e.componentsDir,
|
|
827
|
+
e.components,
|
|
828
|
+
e.enableFallbackComponent,
|
|
829
|
+
e.customFallbackComponent
|
|
600
830
|
),
|
|
601
|
-
|
|
831
|
+
ce(e)
|
|
602
832
|
]
|
|
603
833
|
}
|
|
604
|
-
}),
|
|
834
|
+
}), e.livePreview && (d == null ? void 0 : d.output) !== "server")
|
|
605
835
|
throw new Error(
|
|
606
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."
|
|
607
837
|
);
|
|
@@ -611,12 +841,12 @@ function je(r) {
|
|
|
611
841
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
612
842
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
613
843
|
`
|
|
614
|
-
),
|
|
844
|
+
), e.bridge && !e.livePreview && o(
|
|
615
845
|
"page",
|
|
616
846
|
`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
617
847
|
loadStoryblokBridge().then(() => {
|
|
618
848
|
const { StoryblokBridge, location } = window;
|
|
619
|
-
${
|
|
849
|
+
${t}
|
|
620
850
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
621
851
|
if (!event.slugChanged) {
|
|
622
852
|
location.reload(true);
|
|
@@ -624,54 +854,54 @@ function je(r) {
|
|
|
624
854
|
});
|
|
625
855
|
});
|
|
626
856
|
`
|
|
627
|
-
),
|
|
857
|
+
), e.livePreview && (o(
|
|
628
858
|
"page",
|
|
629
859
|
`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
630
860
|
loadStoryblokBridge().then(() => {
|
|
631
861
|
const { StoryblokBridge, location } = window;
|
|
632
|
-
${
|
|
862
|
+
${t}
|
|
633
863
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
634
864
|
});
|
|
635
865
|
`
|
|
636
|
-
),
|
|
866
|
+
), l({
|
|
637
867
|
entrypoint: "@storyblok/astro/middleware.ts",
|
|
638
868
|
order: "pre"
|
|
639
|
-
})),
|
|
869
|
+
})), s({
|
|
640
870
|
id: "storyblok",
|
|
641
871
|
name: "Storyblok",
|
|
642
|
-
icon:
|
|
872
|
+
icon: Q,
|
|
643
873
|
entrypoint: "@storyblok/astro/toolbarApp.ts"
|
|
644
874
|
});
|
|
645
875
|
}
|
|
646
876
|
}
|
|
647
877
|
};
|
|
648
878
|
}
|
|
649
|
-
let
|
|
650
|
-
async function
|
|
651
|
-
const { action:
|
|
652
|
-
if (
|
|
879
|
+
let z;
|
|
880
|
+
async function ct(r) {
|
|
881
|
+
const { action: e, story: t } = r || {};
|
|
882
|
+
if (e === "input" && t) {
|
|
653
883
|
const o = async () => {
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
884
|
+
const s = await tt(t), l = document.body;
|
|
885
|
+
if (s.outerHTML === l.outerHTML)
|
|
656
886
|
return;
|
|
657
|
-
const
|
|
658
|
-
|
|
887
|
+
const d = document.querySelector('[data-blok-focused="true"]');
|
|
888
|
+
et(l, s, d), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
|
|
659
889
|
};
|
|
660
|
-
clearTimeout(
|
|
890
|
+
clearTimeout(z), z = setTimeout(o, 500);
|
|
661
891
|
}
|
|
662
892
|
["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
|
|
663
893
|
}
|
|
664
|
-
function
|
|
665
|
-
if (
|
|
666
|
-
const o =
|
|
894
|
+
function et(r, e, t) {
|
|
895
|
+
if (t) {
|
|
896
|
+
const o = t.getAttribute("data-blok-uid"), n = e.querySelector(
|
|
667
897
|
`[data-blok-uid="${o}"]`
|
|
668
898
|
);
|
|
669
|
-
|
|
899
|
+
n && (n.setAttribute("data-blok-focused", "true"), t.replaceWith(n));
|
|
670
900
|
} else
|
|
671
|
-
r.replaceWith(
|
|
901
|
+
r.replaceWith(e);
|
|
672
902
|
}
|
|
673
|
-
async function
|
|
674
|
-
const
|
|
903
|
+
async function tt(r) {
|
|
904
|
+
const t = await (await fetch(location.href, {
|
|
675
905
|
method: "POST",
|
|
676
906
|
body: JSON.stringify({
|
|
677
907
|
...r,
|
|
@@ -681,17 +911,19 @@ async function Se(r) {
|
|
|
681
911
|
"Content-Type": "application/json"
|
|
682
912
|
}
|
|
683
913
|
})).text();
|
|
684
|
-
return new DOMParser().parseFromString(
|
|
914
|
+
return new DOMParser().parseFromString(t, "text/html").body;
|
|
685
915
|
}
|
|
686
916
|
export {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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
|
|
697
929
|
};
|