@storyblok/astro 6.1.0-alpha.2 → 6.1.0

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.
@@ -1,4 +1,4 @@
1
- const V = `<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">
1
+ const E = `<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>`, J = /[\p{Lu}]/u, W = /[\p{Ll}]/u, x = /^[\p{Lu}](?![\p{Lu}])/gu, B = /([\p{Alpha}\p{N}_]|$)/u, L = /[_.\- ]+/, Z = new RegExp("^" + L.source), E = new RegExp(L.source + B.source, "gu"), P = new RegExp("\\d+" + B.source, "gu"), G = (r, e, t, s) => {
11
- let o = !1, n = !1, i = !1, a = !1;
12
- for (let l = 0; l < r.length; l++) {
13
- const c = r[l];
14
- a = l > 2 ? r[l - 3] === "-" : !0, o && J.test(c) ? (r = r.slice(0, l) + "-" + r.slice(l), o = !1, i = n, n = !0, l++) : n && i && W.test(c) && (!a || s) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), i = n, n = !1, o = !0) : (o = e(c) === c && t(c) !== c, i = n, n = t(c) === c && e(c) !== c);
10
+ </svg>`, L = /[\p{Lu}]/u, T = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, A = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, j = new RegExp("^" + b.source), w = new RegExp(b.source + A.source, "gu"), $ = new RegExp("\\d+" + A.source, "gu"), R = (r, t, e, o) => {
11
+ let s = !1, n = !1, a = !1, l = !1;
12
+ for (let i = 0; i < r.length; i++) {
13
+ const c = r[i];
14
+ l = i > 2 ? r[i - 3] === "-" : !0, s && L.test(c) ? (r = r.slice(0, i) + "-" + r.slice(i), s = !1, a = n, n = !0, i++) : n && a && T.test(c) && (!l || o) ? (r = r.slice(0, i - 1) + "-" + r.slice(i - 1), a = n, n = !1, s = !0) : (s = t(c) === c && e(c) !== c, a = n, n = e(c) === c && t(c) !== c);
15
15
  }
16
16
  return r;
17
- }, K = (r, e) => (x.lastIndex = 0, r.replaceAll(x, (t) => e(t))), Y = (r, e) => (E.lastIndex = 0, P.lastIndex = 0, r.replaceAll(P, (t, s, o) => ["_", "-"].includes(r.charAt(o + t.length)) ? t : e(t)).replaceAll(E, (t, s) => e(s)));
18
- function Q(r, e) {
17
+ }, M = (r, t) => (k.lastIndex = 0, r.replaceAll(k, (e) => t(e))), O = (r, t) => (w.lastIndex = 0, $.lastIndex = 0, r.replaceAll($, (e, o, s) => ["_", "-"].includes(r.charAt(s + e.length)) ? e : t(e)).replaceAll(w, (e, o) => t(o)));
18
+ function P(r, t) {
19
19
  if (!(typeof r == "string" || Array.isArray(r)))
20
20
  throw new TypeError("Expected the input to be `string | string[]`");
21
- if (e = {
21
+ if (t = {
22
22
  pascalCase: !1,
23
23
  preserveConsecutiveUppercase: !1,
24
- ...e
24
+ ...t
25
25
  }, Array.isArray(r) ? r = r.map((n) => n.trim()).filter((n) => n.length).join("-") : r = r.trim(), r.length === 0)
26
26
  return "";
27
- const t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
28
- return r.length === 1 ? L.test(r) ? "" : e.pascalCase ? s(r) : t(r) : (r !== t(r) && (r = G(r, t, s, e.preserveConsecutiveUppercase)), r = r.replace(Z, ""), r = e.preserveConsecutiveUppercase ? K(r, t) : t(r), e.pascalCase && (r = s(r.charAt(0)) + r.slice(1)), Y(r, s));
27
+ const e = t.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(t.locale);
28
+ return r.length === 1 ? b.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = R(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(j, ""), r = t.preserveConsecutiveUppercase ? M(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
29
29
  }
30
- function j(r) {
31
- return Q(r);
30
+ function v(r) {
31
+ return P(r);
32
32
  }
33
- function X(r, e = {}, t, s) {
34
- const o = "virtual:storyblok-components", n = `\0${o}`;
33
+ function _(r, t = {}, e, o) {
34
+ const s = "virtual:storyblok-components", n = `\0${s}`;
35
35
  return {
36
36
  name: "vite-plugin-storyblok-components",
37
- async resolveId(i) {
38
- if (i === o)
37
+ async resolveId(a) {
38
+ if (a === s)
39
39
  return n;
40
40
  },
41
- async load(i) {
42
- if (i === n) {
43
- const a = [], l = [];
44
- for await (const [h, u] of Object.entries(e)) {
45
- const p = await this.resolve(
46
- `/${r}/${u}.astro`
41
+ async load(a) {
42
+ if (a === n) {
43
+ const l = [], i = [];
44
+ for await (const [u, p] of Object.entries(t)) {
45
+ const f = await this.resolve(
46
+ `/${r}/${p}.astro`
47
47
  );
48
- if (p)
49
- a.push(`import ${j(h)} from "${p.id}"`);
50
- else if (t)
51
- l.push(h);
48
+ if (f)
49
+ l.push(`import ${v(u)} from "${f.id}"`);
50
+ else if (e)
51
+ i.push(u);
52
52
  else
53
53
  throw new Error(
54
- `Component could not be found for blok "${h}"! Does "${`/${r}/${u}`}.astro" exist?`
54
+ `Component could not be found for blok "${u}"! Does "${`/${r}/${p}`}.astro" exist?`
55
55
  );
56
56
  }
57
57
  let c = "";
58
- if (t)
59
- if (c = ",FallbackComponent", s) {
60
- const h = await this.resolve(
61
- `/${r}/${s}.astro`
58
+ if (e)
59
+ if (c = ",FallbackComponent", o) {
60
+ const u = await this.resolve(
61
+ `/${r}/${o}.astro`
62
62
  );
63
- if (!h)
63
+ if (!u)
64
64
  throw new Error(
65
- `Custom fallback component could not be found. Does "${`/${r}/${s}`}.astro" exist?`
65
+ `Custom fallback component could not be found. Does "${`/${r}/${o}`}.astro" exist?`
66
66
  );
67
- a.push(
68
- `import FallbackComponent from "${h.id}"`
67
+ l.push(
68
+ `import FallbackComponent from "${u.id}"`
69
69
  );
70
70
  } else
71
- a.push(
71
+ l.push(
72
72
  "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
73
73
  );
74
- if (Object.values(e).length)
75
- return `${a.join(";")};export default {${Object.keys(e).filter((h) => !l.includes(h)).map((h) => j(h)).join(",")}${c}}`;
76
- if (t)
77
- return `${a[0]}; export default {${c.replace(",", "")}}`;
74
+ if (Object.values(t).length)
75
+ return `${l.join(";")};export default {${Object.keys(t).filter((u) => !i.includes(u)).map((u) => v(u)).join(",")}${c}}`;
76
+ if (e)
77
+ return `${l[0]}; export default {${c.replace(",", "")}}`;
78
78
  throw new Error(
79
79
  `Currently, no Storyblok components are registered in astro.config.mjs.
80
80
  Please register your components or enable the fallback component.
@@ -84,119 +84,76 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
84
84
  }
85
85
  };
86
86
  }
87
- function ee(r, e, t) {
88
- const s = "virtual:storyblok-init", o = `\0${s}`;
87
+ function N(r, t, e) {
88
+ const o = "virtual:storyblok-init", s = `\0${o}`;
89
89
  return {
90
90
  name: "vite-plugin-storyblok-init",
91
91
  async resolveId(n) {
92
- if (n === s)
93
- return o;
92
+ if (n === o)
93
+ return s;
94
94
  },
95
95
  async load(n) {
96
- if (n === o)
96
+ if (n === s)
97
97
  return `
98
98
  import { storyblokInit, apiPlugin } from "@storyblok/js";
99
99
  const { storyblokApi } = storyblokInit({
100
100
  accessToken: "${r}",
101
- use: ${e ? "[]" : "[apiPlugin]"},
102
- apiOptions: ${JSON.stringify(t)},
101
+ use: ${t ? "[]" : "[apiPlugin]"},
102
+ apiOptions: ${JSON.stringify(e)},
103
103
  });
104
104
  export const storyblokApiInstance = storyblokApi;
105
105
  `;
106
106
  }
107
107
  };
108
108
  }
109
- function te(r) {
110
- const e = "virtual:storyblok-options", t = `\0${e}`;
109
+ function z(r) {
110
+ const t = "virtual:storyblok-options", e = `\0${t}`;
111
111
  return {
112
112
  name: "vite-plugin-storyblok-options",
113
- async resolveId(s) {
114
- if (s === e)
115
- return t;
113
+ async resolveId(o) {
114
+ if (o === t)
115
+ return e;
116
116
  },
117
- async load(s) {
118
- if (s === t)
117
+ async load(o) {
118
+ if (o === e)
119
119
  return `export default ${JSON.stringify(r)}`;
120
120
  }
121
121
  };
122
122
  }
123
- let O = !1;
124
- const N = [], D = (r) => new Promise((e, t) => {
125
- if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
123
+ let C = !1;
124
+ const I = [], B = (r) => new Promise((t, e) => {
125
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
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
- O ? o() : N.push(o);
130
+ C ? s() : I.push(s);
131
131
  }, document.getElementById("storyblok-javascript-bridge")))
132
132
  return;
133
- const s = document.createElement("script");
134
- s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (o) => t(o), s.onload = (o) => {
135
- N.forEach((n) => n()), O = !0, e(o);
136
- }, document.getElementsByTagName("head")[0].appendChild(s);
133
+ const o = document.createElement("script");
134
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
135
+ I.forEach((n) => n()), C = !0, t(s);
136
+ }, document.getElementsByTagName("head")[0].appendChild(o);
137
137
  });
138
- var se = Object.defineProperty, re = (r, e, t) => e in r ? se(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e, t) => re(r, typeof e != "symbol" ? e + "" : e, t);
139
- class oe extends Error {
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 D = Object.defineProperty, F = (r, t, e) => t in r ? D(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, g = (r, t, e) => F(r, typeof t != "symbol" ? t + "" : t, e);
139
+ class U {
183
140
  constructor() {
184
- d(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), d(this, "getOptionsPage", (r, e = 25, t = 1) => ({
185
- ...r,
141
+ g(this, "isCDNUrl", (t = "") => t.includes("/cdn/")), g(this, "getOptionsPage", (t, e = 25, o = 1) => ({
142
+ ...t,
186
143
  per_page: e,
187
- page: t
188
- })), d(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), d(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), d(this, "range", (r = 0, e = r) => {
189
- const t = Math.abs(e - r) || 0, s = r < e ? 1 : -1;
190
- return this.arrayFrom(t, (o, n) => n * s + r);
191
- }), d(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), d(this, "flatMap", (r = [], e) => r.map(e).reduce((t, s) => [...t, ...s], [])), d(this, "escapeHTML", function(r) {
144
+ page: o
145
+ })), g(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), g(this, "arrayFrom", (t = 0, e) => Array.from({ length: t }, e)), g(this, "range", (t = 0, e = t) => {
146
+ const o = Math.abs(e - t) || 0, s = t < e ? 1 : -1;
147
+ return this.arrayFrom(o, (n, a) => a * s + t);
148
+ }), g(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), g(this, "flatMap", (t = [], e) => t.map(e).reduce((o, s) => [...o, ...s], [])), g(this, "escapeHTML", function(t) {
192
149
  const e = {
193
150
  "&": "&amp;",
194
151
  "<": "&lt;",
195
152
  ">": "&gt;",
196
153
  '"': "&quot;",
197
154
  "'": "&#39;"
198
- }, t = /[&<>"']/g, s = new RegExp(t.source);
199
- return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
155
+ }, o = /[&<>"']/g, s = new RegExp(o.source);
156
+ return t && s.test(t) ? t.replace(o, (n) => e[n]) : t;
200
157
  });
201
158
  }
202
159
  /**
@@ -206,18 +163,18 @@ let T = class {
206
163
  * @param {boolean} isArray
207
164
  * @return {string} Stringified object
208
165
  */
209
- stringify(r, e, t) {
166
+ stringify(t, e, o) {
210
167
  const s = [];
211
- for (const o in r) {
212
- if (!Object.prototype.hasOwnProperty.call(r, o))
168
+ for (const n in t) {
169
+ if (!Object.prototype.hasOwnProperty.call(t, n))
213
170
  continue;
214
- const n = r[o], i = t ? "" : encodeURIComponent(o);
215
- let a;
216
- typeof n == "object" ? a = this.stringify(
217
- n,
218
- e ? e + encodeURIComponent(`[${i}]`) : i,
219
- Array.isArray(n)
220
- ) : a = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(n)}`, s.push(a);
171
+ const a = t[n], l = o ? "" : encodeURIComponent(n);
172
+ let i;
173
+ typeof a == "object" ? i = this.stringify(
174
+ a,
175
+ e ? e + encodeURIComponent(`[${l}]`) : l,
176
+ Array.isArray(a)
177
+ ) : i = `${e ? e + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(a)}`, s.push(i);
221
178
  }
222
179
  return s.join("&");
223
180
  }
@@ -226,36 +183,36 @@ let T = class {
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(r) {
230
- const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
231
- switch (r) {
186
+ getRegionURL(t) {
187
+ const e = "api.storyblok.com", o = "api-us.storyblok.com", s = "app.storyblokchina.cn", n = "api-ap.storyblok.com", a = "api-ca.storyblok.com";
188
+ switch (t) {
232
189
  case "us":
233
- return t;
190
+ return o;
234
191
  case "cn":
235
192
  return s;
236
193
  case "ap":
237
- return o;
238
- case "ca":
239
194
  return n;
195
+ case "ca":
196
+ return a;
240
197
  default:
241
198
  return e;
242
199
  }
243
200
  }
244
- };
245
- const ie = function(r, e) {
246
- const t = {};
247
- for (const s in r) {
248
- const o = r[s];
249
- e.includes(s) && o !== null && (t[s] = o);
250
- }
251
- return t;
252
- }, ae = (r) => r === "email", le = () => ({
201
+ }
202
+ const q = function(r, t) {
203
+ const e = {};
204
+ for (const o in r) {
205
+ const s = r[o];
206
+ t.includes(o) && s !== null && (e[o] = s);
207
+ }
208
+ return e;
209
+ }, H = (r) => r === "email", J = () => ({
253
210
  singleTag: "hr"
254
- }), ce = () => ({
211
+ }), W = () => ({
255
212
  tag: "blockquote"
256
- }), he = () => ({
213
+ }), K = () => ({
257
214
  tag: "ul"
258
- }), ue = (r) => ({
215
+ }), V = (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
- }), de = () => ({
223
+ }), Z = () => ({
267
224
  singleTag: "br"
268
- }), pe = (r) => ({
225
+ }), G = (r) => ({
269
226
  tag: `h${r.attrs.level}`
270
- }), ge = (r) => ({
227
+ }), Y = (r) => ({
271
228
  singleTag: [
272
229
  {
273
230
  tag: "img",
274
- attrs: ie(r.attrs, ["src", "alt", "title"])
231
+ attrs: q(r.attrs, ["src", "alt", "title"])
275
232
  }
276
233
  ]
277
- }), fe = () => ({
234
+ }), Q = () => ({
278
235
  tag: "li"
279
- }), ye = () => ({
236
+ }), X = () => ({
280
237
  tag: "ol"
281
- }), me = () => ({
238
+ }), ee = () => ({
282
239
  tag: "p"
283
- }), be = (r) => ({
240
+ }), te = (r) => ({
284
241
  tag: [
285
242
  {
286
243
  tag: "span",
@@ -291,58 +248,58 @@ const ie = function(r, e) {
291
248
  }
292
249
  }
293
250
  ]
294
- }), ke = () => ({
251
+ }), re = () => ({
295
252
  tag: "b"
296
- }), ve = () => ({
253
+ }), oe = () => ({
297
254
  tag: "s"
298
- }), we = () => ({
255
+ }), se = () => ({
299
256
  tag: "u"
300
- }), $e = () => ({
257
+ }), ne = () => ({
301
258
  tag: "strong"
302
- }), Te = () => ({
259
+ }), ae = () => ({
303
260
  tag: "code"
304
- }), Ce = () => ({
261
+ }), le = () => ({
305
262
  tag: "i"
306
- }), Se = (r) => {
263
+ }), ie = (r) => {
307
264
  if (!r.attrs)
308
265
  return {
309
266
  tag: ""
310
267
  };
311
- const e = new T().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
312
- if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), ae(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
313
- for (const o in t.custom)
314
- t[o] = t.custom[o];
315
- delete t.custom;
268
+ const t = new U().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
269
+ if (delete e.linktype, e.href && (e.href = t(r.attrs.href || "")), H(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
270
+ for (const s in e.custom)
271
+ e[s] = e.custom[s];
272
+ delete e.custom;
316
273
  }
317
274
  return {
318
275
  tag: [
319
276
  {
320
277
  tag: "a",
321
- attrs: t
278
+ attrs: e
322
279
  }
323
280
  ]
324
281
  };
325
- }, _e = (r) => ({
282
+ }, ce = (r) => ({
326
283
  tag: [
327
284
  {
328
285
  tag: "span",
329
286
  attrs: r.attrs
330
287
  }
331
288
  ]
332
- }), Ae = () => ({
289
+ }), ue = () => ({
333
290
  tag: "sub"
334
- }), Re = () => ({
291
+ }), de = () => ({
335
292
  tag: "sup"
336
- }), Ie = (r) => ({
293
+ }), ge = (r) => ({
337
294
  tag: [
338
295
  {
339
296
  tag: "span",
340
297
  attrs: r.attrs
341
298
  }
342
299
  ]
343
- }), Le = (r) => {
344
- var e;
345
- return (e = r.attrs) != null && e.color ? {
300
+ }), pe = (r) => {
301
+ var t;
302
+ return (t = r.attrs) != null && t.color ? {
346
303
  tag: [
347
304
  {
348
305
  tag: "span",
@@ -354,9 +311,9 @@ const ie = function(r, e) {
354
311
  } : {
355
312
  tag: ""
356
313
  };
357
- }, xe = (r) => {
358
- var e;
359
- return (e = r.attrs) != null && e.color ? {
314
+ }, fe = (r) => {
315
+ var t;
316
+ return (t = r.attrs) != null && t.color ? {
360
317
  tag: [
361
318
  {
362
319
  tag: "span",
@@ -368,64 +325,64 @@ const ie = function(r, e) {
368
325
  } : {
369
326
  tag: ""
370
327
  };
371
- }, Ee = {
328
+ }, he = {
372
329
  nodes: {
373
- horizontal_rule: le,
374
- blockquote: ce,
375
- bullet_list: he,
376
- code_block: ue,
377
- hard_break: de,
378
- heading: pe,
379
- image: ge,
380
- list_item: fe,
381
- ordered_list: ye,
382
- paragraph: me,
383
- emoji: be
330
+ horizontal_rule: J,
331
+ blockquote: W,
332
+ bullet_list: K,
333
+ code_block: V,
334
+ hard_break: Z,
335
+ heading: G,
336
+ image: Y,
337
+ list_item: Q,
338
+ ordered_list: X,
339
+ paragraph: ee,
340
+ emoji: te
384
341
  },
385
342
  marks: {
386
- bold: ke,
387
- strike: ve,
388
- underline: we,
389
- strong: $e,
390
- code: Te,
391
- italic: Ce,
392
- link: Se,
393
- styled: _e,
394
- subscript: Ae,
395
- superscript: Re,
396
- anchor: Ie,
397
- highlight: Le,
398
- textStyle: xe
399
- }
400
- }, Pe = function(r) {
401
- const e = {
343
+ bold: re,
344
+ strike: oe,
345
+ underline: se,
346
+ strong: ne,
347
+ code: ae,
348
+ italic: le,
349
+ link: ie,
350
+ styled: ce,
351
+ subscript: ue,
352
+ superscript: de,
353
+ anchor: ge,
354
+ highlight: pe,
355
+ textStyle: fe
356
+ }
357
+ }, ye = function(r) {
358
+ const t = {
402
359
  "&": "&amp;",
403
360
  "<": "&lt;",
404
361
  ">": "&gt;",
405
362
  '"': "&quot;",
406
363
  "'": "&#39;"
407
- }, t = /[&<>"']/g, s = new RegExp(t.source);
408
- return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
364
+ }, e = /[&<>"']/g, o = new RegExp(e.source);
365
+ return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
409
366
  };
410
- let M = !1;
411
- class C {
412
- constructor(e) {
413
- d(this, "marks"), d(this, "nodes"), e || (e = Ee), this.marks = e.marks || [], this.nodes = e.nodes || [];
367
+ let S = !1;
368
+ class be {
369
+ constructor(t) {
370
+ g(this, "marks"), g(this, "nodes"), t || (t = he), this.marks = t.marks || [], this.nodes = t.nodes || [];
414
371
  }
415
- addNode(e, t) {
416
- this.nodes[e] = t;
372
+ addNode(t, e) {
373
+ this.nodes[t] = e;
417
374
  }
418
- addMark(e, t) {
419
- this.marks[e] = t;
375
+ addMark(t, e) {
376
+ this.marks[t] = e;
420
377
  }
421
- render(e, t = { optimizeImages: !1 }, s = !0) {
422
- if (!M && s && (console.warn(
378
+ render(t, e = { optimizeImages: !1 }, o = !0) {
379
+ if (!S && 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
- ), M = !0), e && e.content && Array.isArray(e.content)) {
425
- let o = "";
426
- return e.content.forEach((n) => {
427
- o += this.renderNode(n);
428
- }), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
381
+ ), S = !0), t && t.content && Array.isArray(t.content)) {
382
+ let s = "";
383
+ return t.content.forEach((n) => {
384
+ s += this.renderNode(n);
385
+ }), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
429
386
  }
430
387
  return console.warn(
431
388
  `The render method must receive an Object with a "content" field.
@@ -454,691 +411,212 @@ class C {
454
411
  }`
455
412
  ), "";
456
413
  }
457
- optimizeImages(e, t) {
458
- let s = 0, o = 0, n = "", i = "";
459
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, o = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = `/filters${i}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
460
- const a = s > 0 || o > 0 || i.length > 0 ? `${s}x${o}${i}` : "";
461
- return e = e.replace(
414
+ optimizeImages(t, e) {
415
+ let o = 0, s = 0, n = "", a = "";
416
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (n += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (n += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (n += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (n += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (a += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (a += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-F]{6}/gi) || e.filters.fill === "transparent") && (a += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (a += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (a += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (a += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (a += `:rotate(${e.filters.rotate})`), a.length > 0 && (a = `/filters${a}`))), n.length > 0 && (t = t.replace(/<img/g, `<img ${n.trim()}`));
417
+ const l = o > 0 || s > 0 || a.length > 0 ? `${o}x${s}${a}` : "";
418
+ return t = t.replace(
462
419
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
463
- `a.storyblok.com/f/$1/$2.$3/m/${a}`
464
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
465
- var c, h;
466
- const u = l.match(
420
+ `a.storyblok.com/f/$1/$2.$3/m/${l}`
421
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (i) => {
422
+ var c, u;
423
+ const p = i.match(
467
424
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
468
425
  );
469
- if (u && u.length > 0) {
470
- const p = {
471
- srcset: (c = t.srcset) == null ? void 0 : c.map((g) => {
472
- if (typeof g == "number")
473
- return `//${u}/m/${g}x0${i} ${g}w`;
474
- if (typeof g == "object" && g.length === 2) {
475
- let k = 0, b = 0;
476
- return typeof g[0] == "number" && (k = g[0]), typeof g[1] == "number" && (b = g[1]), `//${u}/m/${k}x${b}${i} ${k}w`;
426
+ if (p && p.length > 0) {
427
+ const f = {
428
+ srcset: (c = e.srcset) == null ? void 0 : c.map((d) => {
429
+ if (typeof d == "number")
430
+ return `//${p}/m/${d}x0${a} ${d}w`;
431
+ if (typeof d == "object" && d.length === 2) {
432
+ let y = 0, m = 0;
433
+ return typeof d[0] == "number" && (y = d[0]), typeof d[1] == "number" && (m = d[1]), `//${p}/m/${y}x${m}${a} ${y}w`;
477
434
  }
478
435
  return "";
479
436
  }).join(", "),
480
- sizes: (h = t.sizes) == null ? void 0 : h.map((g) => g).join(", ")
437
+ sizes: (u = e.sizes) == null ? void 0 : u.map((d) => d).join(", ")
481
438
  };
482
- let m = "";
483
- return p.srcset && (m += `srcset="${p.srcset}" `), p.sizes && (m += `sizes="${p.sizes}" `), l.replace(/<img/g, `<img ${m.trim()}`);
439
+ let h = "";
440
+ return f.srcset && (h += `srcset="${f.srcset}" `), f.sizes && (h += `sizes="${f.sizes}" `), i.replace(/<img/g, `<img ${h.trim()}`);
484
441
  }
485
- return l;
486
- })), e;
487
- }
488
- renderNode(e) {
489
- const t = [];
490
- e.marks && e.marks.forEach((o) => {
491
- const n = this.getMatchingMark(o);
492
- n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
442
+ return i;
443
+ })), t;
444
+ }
445
+ renderNode(t) {
446
+ const e = [];
447
+ t.marks && t.marks.forEach((s) => {
448
+ const n = this.getMatchingMark(s);
449
+ n && n.tag !== "" && e.push(this.renderOpeningTag(n.tag));
493
450
  });
494
- const s = this.getMatchingNode(e);
495
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((o) => {
496
- t.push(this.renderNode(o));
497
- }) : e.text ? t.push(Pe(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
498
- const n = this.getMatchingMark(o);
499
- n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
500
- }), t.join("");
501
- }
502
- renderTag(e, t) {
503
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
504
- if (s.constructor === String)
505
- return `<${s}${t}>`;
451
+ const o = this.getMatchingNode(t);
452
+ return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
453
+ e.push(this.renderNode(s));
454
+ }) : t.text ? e.push(ye(t.text)) : o && o.singleTag ? e.push(this.renderTag(o.singleTag, " /")) : o && o.html ? e.push(o.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), o && o.tag && e.push(this.renderClosingTag(o.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
455
+ const n = this.getMatchingMark(s);
456
+ n && n.tag !== "" && e.push(this.renderClosingTag(n.tag));
457
+ }), e.join("");
458
+ }
459
+ renderTag(t, e) {
460
+ return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
461
+ if (o.constructor === String)
462
+ return `<${o}${e}>`;
506
463
  {
507
- let o = `<${s.tag}`;
508
- if (s.attrs) {
509
- for (const n in s.attrs)
510
- if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
511
- const i = s.attrs[n];
512
- i !== null && (o += ` ${n}="${i}"`);
464
+ let s = `<${o.tag}`;
465
+ if (o.attrs) {
466
+ for (const n in o.attrs)
467
+ if (Object.prototype.hasOwnProperty.call(o.attrs, n)) {
468
+ const a = o.attrs[n];
469
+ a !== null && (s += ` ${n}="${a}"`);
513
470
  }
514
471
  }
515
- return `${o}${t}>`;
472
+ return `${s}${e}>`;
516
473
  }
517
474
  }).join("");
518
475
  }
519
- renderOpeningTag(e) {
520
- return this.renderTag(e, "");
476
+ renderOpeningTag(t) {
477
+ return this.renderTag(t, "");
521
478
  }
522
- renderClosingTag(e) {
523
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
479
+ renderClosingTag(t) {
480
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
524
481
  }
525
- getMatchingNode(e) {
526
- const t = this.nodes[e.type];
527
- if (typeof t == "function")
528
- return t(e);
482
+ getMatchingNode(t) {
483
+ const e = this.nodes[t.type];
484
+ if (typeof e == "function")
485
+ return e(t);
529
486
  }
530
- getMatchingMark(e) {
531
- const t = this.marks[e.type];
532
- if (typeof t == "function")
533
- return t(e);
487
+ getMatchingMark(t) {
488
+ const e = this.marks[t.type];
489
+ if (typeof e == "function")
490
+ return e(t);
534
491
  }
535
- renderEmoji(e) {
536
- if (e.attrs.emoji)
537
- return e.attrs.emoji;
538
- const t = [
492
+ renderEmoji(t) {
493
+ if (t.attrs.emoji)
494
+ return t.attrs.emoji;
495
+ const e = [
539
496
  {
540
497
  tag: "img",
541
498
  attrs: {
542
- src: e.attrs.fallbackImage,
499
+ src: t.attrs.fallbackImage,
543
500
  draggable: "false",
544
501
  loading: "lazy",
545
502
  align: "absmiddle"
546
503
  }
547
504
  }
548
505
  ];
549
- return this.renderTag(t, " /");
550
- }
551
- }
552
- class je {
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;
506
+ return this.renderTag(e, " /");
1002
507
  }
1003
508
  }
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 xe = (r) => {
1014
510
  if (typeof r != "object" || typeof r._editable > "u")
1015
511
  return {};
1016
512
  try {
1017
- const e = JSON.parse(
513
+ const t = JSON.parse(
1018
514
  r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
1019
515
  );
1020
- return e ? {
1021
- "data-blok-c": JSON.stringify(e),
1022
- "data-blok-uid": `${e.id}-${e.uid}`
516
+ return t ? {
517
+ "data-blok-c": JSON.stringify(t),
518
+ "data-blok-uid": `${t.id}-${t.uid}`
1023
519
  } : {};
1024
520
  } catch {
1025
521
  return {};
1026
522
  }
1027
523
  };
1028
- let R, I = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1029
- const z = (r, e) => {
1030
- r.addNode("blok", (t) => {
1031
- let s = "";
1032
- return t.attrs.body.forEach((o) => {
1033
- s += e(o.component, o);
524
+ let me, ke = "https://app.storyblok.com/f/storyblok-v2-latest.js";
525
+ const we = (r, t) => {
526
+ r.addNode("blok", (e) => {
527
+ let o = "";
528
+ return e.attrs.body.forEach((s) => {
529
+ o += t(s.component, s);
1034
530
  }), {
1035
- html: s
531
+ html: o
1036
532
  };
1037
533
  });
1038
- }, Me = (r = {}) => {
1039
- var e, t;
1040
- const {
1041
- bridge: s,
1042
- accessToken: o,
1043
- use: n = [],
1044
- apiOptions: i = {},
1045
- richText: a = {},
1046
- bridgeUrl: l
1047
- } = r;
1048
- i.accessToken = i.accessToken || o;
1049
- const c = { bridge: s, apiOptions: i };
1050
- let h = {};
1051
- n.forEach((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) => {
1057
- var e;
1058
- return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
1059
- }, Fe = (r, e, t) => {
1060
- let s = t || R;
1061
- if (!s) {
534
+ }, $e = (r) => {
535
+ var t;
536
+ return !r || !((t = r == null ? void 0 : r.content) != null && t.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule"));
537
+ }, ve = (r, t, e) => {
538
+ let o = e || me;
539
+ if (!o) {
1062
540
  console.error(
1063
541
  "Please initialize the Storyblok SDK before calling the renderRichText function"
1064
542
  );
1065
543
  return;
1066
544
  }
1067
- return Ue(r) ? "" : (e && (s = new C(e.schema), e.resolver && z(s, e.resolver)), s.render(r, {}, !1));
1068
- }, qe = () => D(I);
1069
- function Ve() {
1070
- if (!globalThis.storyblokApiInstance)
545
+ return $e(r) ? "" : (t && (o = new be(t.schema), t.resolver && we(o, t.resolver)), o.render(r, {}, !1));
546
+ }, Ae = () => B(ke);
547
+ function Ee() {
548
+ if (!(globalThis != null && globalThis.storyblokApiInstance))
1071
549
  throw new Error("storyblokApiInstance has not been initialized correctly");
1072
550
  return globalThis.storyblokApiInstance;
1073
551
  }
1074
- async function Je(r) {
1075
- let e = null;
1076
- return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
552
+ async function Le(r) {
553
+ let t = null;
554
+ return r && r.locals._storyblok_preview_data && (t = r.locals._storyblok_preview_data), t;
1077
555
  }
1078
- function We(r, e) {
1079
- var s;
1080
- const t = (s = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : s.richTextResolver;
1081
- if (!t)
556
+ function Te(r, t) {
557
+ var o;
558
+ const e = (o = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : o.richTextResolver;
559
+ if (!e)
1082
560
  throw new Error(
1083
561
  "Please initialize the Storyblok SDK before calling the renderRichText function"
1084
562
  );
1085
- return Fe(r, e, t);
563
+ return ve(r, t, e);
1086
564
  }
1087
- function Be(r) {
565
+ function Ce(r) {
1088
566
  return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
1089
567
  }
1090
- function Ze(r) {
1091
- const e = {
568
+ function je(r) {
569
+ const t = {
1092
570
  useCustomApi: !1,
1093
571
  bridge: !0,
1094
572
  componentsDir: "src",
1095
573
  enableFallbackComponent: !1,
1096
574
  livePreview: !1,
1097
575
  ...r
1098
- }, t = Be(e.bridge);
576
+ }, e = Ce(t.bridge);
1099
577
  return {
1100
578
  name: "@storyblok/astro",
1101
579
  hooks: {
1102
580
  "astro:config:setup": ({
1103
- injectScript: s,
1104
- updateConfig: o,
581
+ injectScript: o,
582
+ updateConfig: s,
1105
583
  addDevToolbarApp: n,
1106
- addMiddleware: i,
1107
- config: a
584
+ addMiddleware: a,
585
+ config: l
1108
586
  }) => {
1109
- if (o({
587
+ if (s({
1110
588
  vite: {
1111
589
  plugins: [
1112
- ee(
1113
- e.accessToken,
1114
- e.useCustomApi,
1115
- e.apiOptions
590
+ N(
591
+ t.accessToken,
592
+ t.useCustomApi,
593
+ t.apiOptions
1116
594
  ),
1117
- X(
1118
- e.componentsDir,
1119
- e.components,
1120
- e.enableFallbackComponent,
1121
- e.customFallbackComponent
595
+ _(
596
+ t.componentsDir,
597
+ t.components,
598
+ t.enableFallbackComponent,
599
+ t.customFallbackComponent
1122
600
  ),
1123
- te(e)
601
+ z(t)
1124
602
  ]
1125
603
  }
1126
- }), e.livePreview && (a == null ? void 0 : a.output) !== "server")
604
+ }), t.livePreview && (l == null ? void 0 : l.output) !== "server")
1127
605
  throw new Error(
1128
606
  "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
607
  );
1130
- s(
608
+ o(
1131
609
  "page-ssr",
1132
610
  `
1133
611
  import { storyblokApiInstance } from "virtual:storyblok-init";
1134
612
  globalThis.storyblokApiInstance = storyblokApiInstance;
1135
613
  `
1136
- ), e.bridge && !e.livePreview && s(
614
+ ), t.bridge && !t.livePreview && o(
1137
615
  "page",
1138
616
  `import { loadStoryblokBridge } from "@storyblok/astro";
1139
617
  loadStoryblokBridge().then(() => {
1140
618
  const { StoryblokBridge, location } = window;
1141
- ${t}
619
+ ${e}
1142
620
  storyblokInstance.on(["published", "change"], (event) => {
1143
621
  if (!event.slugChanged) {
1144
622
  location.reload(true);
@@ -1146,94 +624,54 @@ function Ze(r) {
1146
624
  });
1147
625
  });
1148
626
  `
1149
- ), e.livePreview && (s(
627
+ ), t.livePreview && (o(
1150
628
  "page",
1151
629
  `import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
1152
630
  loadStoryblokBridge().then(() => {
1153
631
  const { StoryblokBridge, location } = window;
1154
- ${t}
632
+ ${e}
1155
633
  storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
1156
634
  });
1157
635
  `
1158
- ), i({
636
+ ), a({
1159
637
  entrypoint: "@storyblok/astro/middleware.ts",
1160
638
  order: "pre"
1161
639
  })), n({
1162
640
  id: "storyblok",
1163
641
  name: "Storyblok",
1164
- icon: V,
642
+ icon: E,
1165
643
  entrypoint: "@storyblok/astro/toolbarApp.ts"
1166
644
  });
1167
645
  }
1168
646
  }
1169
647
  };
1170
648
  }
1171
- function Ge(r) {
1172
- const { accessToken: e, useCustomApi: t, apiOptions: s, version: o, storiesParams: n } = r, { storyblokApi: i } = Me({
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) {
1213
- const { action: e, story: t } = r || {};
1214
- if (e === "input" && t) {
1215
- const s = async () => {
1216
- const n = await ze(t), i = document.body;
1217
- if (n.outerHTML === i.outerHTML)
649
+ let x;
650
+ async function Re(r) {
651
+ const { action: t, story: e } = r || {};
652
+ if (t === "input" && e) {
653
+ const o = async () => {
654
+ const n = await Se(e), a = document.body;
655
+ if (n.outerHTML === a.outerHTML)
1218
656
  return;
1219
- const a = document.querySelector('[data-blok-focused="true"]');
1220
- De(i, n, a), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
657
+ const l = document.querySelector('[data-blok-focused="true"]');
658
+ Ie(a, n, l), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
1221
659
  };
1222
- clearTimeout(F), F = setTimeout(s, 500);
660
+ clearTimeout(x), x = setTimeout(o, 500);
1223
661
  }
1224
662
  ["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
1225
663
  }
1226
- function De(r, e, t) {
1227
- if (t) {
1228
- const s = t.getAttribute("data-blok-uid"), o = e.querySelector(
1229
- `[data-blok-uid="${s}"]`
664
+ function Ie(r, t, e) {
665
+ if (e) {
666
+ const o = e.getAttribute("data-blok-uid"), s = t.querySelector(
667
+ `[data-blok-uid="${o}"]`
1230
668
  );
1231
- o && (o.setAttribute("data-blok-focused", "true"), t.replaceWith(o));
669
+ s && (s.setAttribute("data-blok-focused", "true"), e.replaceWith(s));
1232
670
  } else
1233
- r.replaceWith(e);
671
+ r.replaceWith(t);
1234
672
  }
1235
- async function ze(r) {
1236
- const t = await (await fetch(location.href, {
673
+ async function Se(r) {
674
+ const e = await (await fetch(location.href, {
1237
675
  method: "POST",
1238
676
  body: JSON.stringify({
1239
677
  ...r,
@@ -1243,18 +681,17 @@ async function ze(r) {
1243
681
  "Content-Type": "application/json"
1244
682
  }
1245
683
  })).text();
1246
- return new DOMParser().parseFromString(t, "text/html").body;
684
+ return new DOMParser().parseFromString(e, "text/html").body;
1247
685
  }
1248
686
  export {
1249
- C as RichTextResolver,
1250
- Ee as RichTextSchema,
1251
- Je as getLiveStory,
1252
- Ke as handleStoryblokMessage,
1253
- qe as loadStoryblokBridge,
1254
- We as renderRichText,
1255
- Ze as storyblok,
1256
- He as storyblokEditable,
1257
- Ge as storyblokLoader,
1258
- j as toCamelCase,
1259
- Ve as useStoryblokApi
687
+ be as RichTextResolver,
688
+ he as RichTextSchema,
689
+ Le as getLiveStory,
690
+ Re as handleStoryblokMessage,
691
+ Ae as loadStoryblokBridge,
692
+ Te as renderRichText,
693
+ je as storyblok,
694
+ xe as storyblokEditable,
695
+ v as toCamelCase,
696
+ Ee as useStoryblokApi
1260
697
  };