@storyblok/react 5.0.0 → 5.0.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.
@@ -1,21 +1,21 @@
1
- function te(n, e) {
1
+ function se(n, e) {
2
2
  if (!e)
3
3
  return { src: n, attrs: {} };
4
4
  let t = 0, r = 0;
5
5
  const s = {}, o = [];
6
- function l(c, h, f, y, _) {
7
- typeof c != "number" || c <= h || c >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`) : _.push(`${y}(${c})`);
6
+ function c(i, h, f, y, _) {
7
+ typeof i != "number" || i <= h || i >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`) : _.push(`${y}(${i})`);
8
8
  }
9
9
  if (typeof e == "object") {
10
10
  if (typeof e.width == "number" && e.width > 0 ? (s.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 ? (s.height = e.height, r = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
11
- const { filters: c } = e || {}, { blur: h, brightness: f, fill: y, format: _, grayscale: A, quality: $, rotate: S } = c || {};
12
- h && l(h, 0, 100, "blur", o), $ && l($, 0, 100, "quality", o), f && l(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), A && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), _ && ["webp", "png", "jpeg"].includes(_) && o.push(`format(${_})`);
11
+ const { filters: i } = e || {}, { blur: h, brightness: f, fill: y, format: _, grayscale: T, quality: A, rotate: S } = i || {};
12
+ h && c(h, 0, 100, "blur", o), A && c(A, 0, 100, "quality", o), f && c(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), T && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), _ && ["webp", "png", "jpeg"].includes(_) && o.push(`format(${_})`);
13
13
  }
14
- e.srcset && (s.srcset = e.srcset.map((c) => {
15
- if (typeof c == "number")
16
- return `${n}/m/${c}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${c}w`;
17
- if (Array.isArray(c) && c.length === 2) {
18
- const [h, f] = c;
14
+ e.srcset && (s.srcset = e.srcset.map((i) => {
15
+ if (typeof i == "number")
16
+ return `${n}/m/${i}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${i}w`;
17
+ if (Array.isArray(i) && i.length === 2) {
18
+ const [h, f] = i;
19
19
  return `${n}/m/${h}x${f}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
20
20
  } else {
21
21
  console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
@@ -23,14 +23,14 @@ function te(n, e) {
23
23
  }
24
24
  }).join(", ")), e.sizes && (s.sizes = e.sizes.join(", "));
25
25
  }
26
- let a = `${n}/m/`;
27
- return t > 0 && r > 0 && (a = `${a}${t}x${r}/`), o.length > 0 && (a = `${a}filters:${o.join(":")}`), {
28
- src: a,
26
+ let l = `${n}/m/`;
27
+ return t > 0 && r > 0 && (l = `${l}${t}x${r}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
28
+ src: l,
29
29
  attrs: s
30
30
  };
31
31
  }
32
- var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), R = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))(R || {}), F = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(F || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
33
- const se = [
32
+ var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), $ = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))($ || {}), V = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(V || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
33
+ const re = [
34
34
  "area",
35
35
  "base",
36
36
  "br",
@@ -45,97 +45,91 @@ const se = [
45
45
  "source",
46
46
  "track",
47
47
  "wbr"
48
- ], re = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), ne = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
49
- function oe(n) {
48
+ ], ne = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), oe = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
49
+ function ie(n) {
50
50
  return n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
51
51
  }
52
52
  const O = (n) => Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0));
53
- function U(n, e = {}, t) {
54
- const r = re(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
53
+ function D(n, e = {}, t) {
54
+ const r = ne(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
55
55
  if (n) {
56
- if (se.includes(n))
56
+ if (re.includes(n))
57
57
  return `<${s}>`;
58
58
  } else return o;
59
59
  return `<${s}>${o}</${n}>`;
60
60
  }
61
- function ie(n = {}) {
61
+ function ae(n = {}) {
62
62
  const e = /* @__PURE__ */ new Map(), {
63
- renderFn: t = U,
64
- textFn: r = oe,
63
+ renderFn: t = D,
64
+ textFn: r = ie,
65
65
  resolvers: s = {},
66
66
  optimizeImages: o = !1,
67
- keyedResolvers: l = !1
68
- } = n, a = t !== U, c = () => ({ render: (i, u = {}, d) => {
69
- if (l && i) {
70
- const p = e.get(i) || 0;
71
- e.set(i, p + 1), u.key = `${i}-${p}`;
72
- }
73
- return t(i, u, d);
74
- } }), h = (i) => (u, d) => {
67
+ keyedResolvers: c = !1
68
+ } = n, l = t !== D, i = (a) => (u, d) => {
75
69
  const p = u.attrs || {};
76
- return d.render(i, p, u.children || null);
77
- }, f = (i, u) => {
78
- const { src: d, alt: p, title: m, srcset: w, sizes: b } = i.attrs || {};
79
- let k = d, T = {};
70
+ return d.render(a, p, u.children || null);
71
+ }, h = (a, u) => {
72
+ const { src: d, alt: p, title: m, srcset: w, sizes: b } = a.attrs || {};
73
+ let k = d, R = {};
80
74
  if (o) {
81
- const { src: Z, attrs: ee } = te(d, o);
82
- k = Z, T = ee;
75
+ const { src: ee, attrs: te } = se(d, o);
76
+ k = ee, R = te;
83
77
  }
84
- const Q = {
78
+ const Z = {
85
79
  src: k,
86
80
  alt: p,
87
81
  title: m,
88
82
  srcset: w,
89
83
  sizes: b,
90
- ...T
84
+ ...R
91
85
  };
92
- return u.render("img", O(Q));
93
- }, y = (i, u) => {
94
- const { level: d, ...p } = i.attrs || {};
95
- return u.render(`h${d}`, p, i.children);
96
- }, _ = (i, u) => {
86
+ return u.render("img", O(Z));
87
+ }, f = (a, u) => {
88
+ const { level: d, ...p } = a.attrs || {};
89
+ return u.render(`h${d}`, p, a.children);
90
+ }, y = (a, u) => {
97
91
  var d, p, m, w;
98
92
  const b = u.render("img", {
99
- src: (d = i.attrs) == null ? void 0 : d.fallbackImage,
100
- alt: (p = i.attrs) == null ? void 0 : p.alt,
93
+ src: (d = a.attrs) == null ? void 0 : d.fallbackImage,
94
+ alt: (p = a.attrs) == null ? void 0 : p.alt,
101
95
  style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
102
96
  draggable: "false",
103
97
  loading: "lazy"
104
98
  });
105
99
  return u.render("span", {
106
100
  "data-type": "emoji",
107
- "data-name": (m = i.attrs) == null ? void 0 : m.name,
108
- "data-emoji": (w = i.attrs) == null ? void 0 : w.emoji
101
+ "data-name": (m = a.attrs) == null ? void 0 : m.name,
102
+ "data-emoji": (w = a.attrs) == null ? void 0 : w.emoji
109
103
  }, b);
110
- }, A = (i, u) => u.render(
104
+ }, _ = (a, u) => u.render(
111
105
  "pre",
112
- i.attrs || {},
113
- u.render("code", {}, i.children || "")
114
- ), $ = (i, u = !1) => ({ text: d, attrs: p }, m) => {
115
- const { class: w, id: b, ...k } = p || {}, T = u ? {
106
+ a.attrs || {},
107
+ u.render("code", {}, a.children || "")
108
+ ), T = (a, u = !1) => ({ text: d, attrs: p }, m) => {
109
+ const { class: w, id: b, ...k } = p || {}, R = u ? {
116
110
  class: w,
117
111
  id: b,
118
- style: ne(k) || void 0
112
+ style: oe(k) || void 0
119
113
  } : p || {};
120
- return m.render(i, O(T), d);
121
- }, S = (i) => C(i), V = (i) => {
122
- const { marks: u, ...d } = i;
123
- if ("text" in i) {
114
+ return m.render(a, O(R), d);
115
+ }, A = (a) => C(a), S = (a) => {
116
+ const { marks: u, ...d } = a;
117
+ if ("text" in a) {
124
118
  if (u)
125
119
  return u.reduce(
126
- (m, w) => S({ ...w, text: m }),
127
- S({ ...d, children: d.children })
120
+ (m, w) => A({ ...w, text: m }),
121
+ A({ ...d, children: d.children })
128
122
  );
129
- const p = i.attrs || {};
130
- if (l) {
123
+ const p = a.attrs || {};
124
+ if (c) {
131
125
  const m = e.get("txt") || 0;
132
126
  e.set("txt", m + 1), p.key = `txt-${m}`;
133
127
  }
134
128
  return r(d.text, p);
135
129
  }
136
130
  return "";
137
- }, H = (i, u) => {
138
- const { linktype: d, href: p, anchor: m, ...w } = i.attrs || {};
131
+ }, H = (a, u) => {
132
+ const { linktype: d, href: p, anchor: m, ...w } = a.attrs || {};
139
133
  let b = "";
140
134
  switch (d) {
141
135
  case I.ASSET:
@@ -153,116 +147,134 @@ function ie(n = {}) {
153
147
  break;
154
148
  }
155
149
  const k = { ...w };
156
- return b && (k.href = b), u.render("a", k, i.text);
157
- }, q = (i, u) => {
150
+ return b && (k.href = b), u.render("a", k, a.text);
151
+ }, J = (a, u) => {
158
152
  var d, p;
159
153
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
160
- blok: (d = i == null ? void 0 : i.attrs) == null ? void 0 : d.body[0],
161
- id: (p = i.attrs) == null ? void 0 : p.id,
154
+ blok: (d = a == null ? void 0 : a.attrs) == null ? void 0 : d.body[0],
155
+ id: (p = a.attrs) == null ? void 0 : p.id,
162
156
  style: "display: none"
163
157
  });
164
- }, J = (i, u) => {
165
- const d = {}, p = u.render("tbody", {}, i.children);
158
+ }, Y = (a, u) => {
159
+ const d = {}, p = u.render("tbody", {}, a.children);
166
160
  return u.render("table", d, p);
167
- }, Y = (i, u) => {
161
+ }, K = (a, u) => {
168
162
  const d = {};
169
- return u.render("tr", d, i.children);
170
- }, K = (i, u) => {
171
- const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
163
+ return u.render("tr", d, a.children);
164
+ }, W = (a, u) => {
165
+ const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = a.attrs || {}, k = {
172
166
  ...b
173
167
  };
174
168
  d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
175
- const T = [];
176
- return m && T.push(`width: ${m}px;`), w && T.push(`background-color: ${w};`), T.length > 0 && (k.style = T.join(" ")), u.render("td", O(k), i.children);
177
- }, W = (i, u) => {
178
- const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
169
+ const R = [];
170
+ return m && R.push(`width: ${m}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (k.style = R.join(" ")), u.render("td", O(k), a.children);
171
+ }, X = (a, u) => {
172
+ const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = a.attrs || {}, k = {
179
173
  ...b
180
174
  };
181
175
  d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
182
- const T = [];
183
- return m && T.push(`width: ${m}px;`), w && T.push(`background-color: ${w};`), T.length > 0 && (k.style = T.join(" ")), u.render("th", O(k), i.children);
184
- }, X = new Map([
185
- [v.DOCUMENT, h("")],
186
- [v.HEADING, y],
187
- [v.PARAGRAPH, h("p")],
188
- [v.UL_LIST, h("ul")],
189
- [v.OL_LIST, h("ol")],
190
- [v.LIST_ITEM, h("li")],
191
- [v.IMAGE, f],
192
- [v.EMOJI, _],
193
- [v.CODE_BLOCK, A],
194
- [v.HR, h("hr")],
195
- [v.BR, h("br")],
196
- [v.QUOTE, h("blockquote")],
197
- [v.COMPONENT, q],
198
- [F.TEXT, V],
199
- [R.LINK, H],
200
- [R.ANCHOR, H],
201
- [R.STYLED, $("span", !0)],
202
- [R.BOLD, $("strong")],
203
- [R.TEXT_STYLE, $("span", !0)],
204
- [R.ITALIC, $("em")],
205
- [R.UNDERLINE, $("u")],
206
- [R.STRIKE, $("s")],
207
- [R.CODE, $("code")],
208
- [R.SUPERSCRIPT, $("sup")],
209
- [R.SUBSCRIPT, $("sub")],
210
- [R.HIGHLIGHT, $("mark")],
211
- [v.TABLE, J],
212
- [v.TABLE_ROW, Y],
213
- [v.TABLE_CELL, K],
214
- [v.TABLE_HEADER, W],
215
- ...Object.entries(s).map(([i, u]) => [i, u])
216
- ]);
217
- function L(i) {
218
- const u = X.get(i.type);
176
+ const R = [];
177
+ return m && R.push(`width: ${m}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (k.style = R.join(" ")), u.render("th", O(k), a.children);
178
+ }, U = /* @__PURE__ */ new Map([
179
+ [v.DOCUMENT, i("")],
180
+ [v.HEADING, f],
181
+ [v.PARAGRAPH, i("p")],
182
+ [v.UL_LIST, i("ul")],
183
+ [v.OL_LIST, i("ol")],
184
+ [v.LIST_ITEM, i("li")],
185
+ [v.IMAGE, h],
186
+ [v.EMOJI, y],
187
+ [v.CODE_BLOCK, _],
188
+ [v.HR, i("hr")],
189
+ [v.BR, i("br")],
190
+ [v.QUOTE, i("blockquote")],
191
+ [v.COMPONENT, J],
192
+ [V.TEXT, S],
193
+ [$.LINK, H],
194
+ [$.ANCHOR, H],
195
+ [$.STYLED, T("span", !0)],
196
+ [$.BOLD, T("strong")],
197
+ [$.TEXT_STYLE, T("span", !0)],
198
+ [$.ITALIC, T("em")],
199
+ [$.UNDERLINE, T("u")],
200
+ [$.STRIKE, T("s")],
201
+ [$.CODE, T("code")],
202
+ [$.SUPERSCRIPT, T("sup")],
203
+ [$.SUBSCRIPT, T("sub")],
204
+ [$.HIGHLIGHT, T("mark")],
205
+ [v.TABLE, Y],
206
+ [v.TABLE_ROW, K],
207
+ [v.TABLE_CELL, W],
208
+ [v.TABLE_HEADER, X]
209
+ ]), B = new Map([
210
+ ...U,
211
+ ...Object.entries(s).map(([a, u]) => [a, u])
212
+ ]), Q = () => ({
213
+ render: (a, u = {}, d) => {
214
+ if (c && a) {
215
+ const p = e.get(a) || 0;
216
+ e.set(a, p + 1), u.key = `${a}-${p}`;
217
+ }
218
+ return t(a, u, d);
219
+ },
220
+ originalResolvers: U,
221
+ mergedResolvers: B
222
+ });
223
+ function L(a) {
224
+ const u = B.get(a.type);
219
225
  if (!u)
220
- return console.error("<Storyblok>", `No resolver found for node type ${i.type}`), "";
221
- const d = c();
222
- if (i.type === "text")
223
- return u(i, d);
224
- const p = i.content ? i.content.map(C) : void 0;
226
+ return console.error("<Storyblok>", `No resolver found for node type ${a.type}`), "";
227
+ const d = Q();
228
+ if (a.type === "text")
229
+ return u(a, d);
230
+ const p = a.content ? a.content.map(C) : void 0;
225
231
  return u({
226
- ...i,
232
+ ...a,
227
233
  children: p
228
234
  }, d);
229
235
  }
230
- function C(i) {
231
- return i.type === "doc" ? a ? i.content.map(L) : i.content.map(L).join("") : Array.isArray(i) ? i.map(L) : L(i);
236
+ function C(a) {
237
+ return a.type === "doc" ? l ? a.content.map(L) : a.content.map(L).join("") : Array.isArray(a) ? a.map(L) : L(a);
232
238
  }
233
239
  return {
234
240
  render: C
235
241
  };
236
242
  }
237
- let B = !1;
238
- const D = [], G = (n) => new Promise((e, t) => {
239
- if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
243
+ let M = !1;
244
+ const z = [], q = (n) => new Promise((e, t) => {
245
+ if (typeof window > "u") {
246
+ t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
247
+ return;
248
+ }
249
+ if (window.storyblokRegisterEvent = (s) => {
240
250
  if (window.location === window.parent.location) {
241
251
  console.warn("You are not in Draft Mode or in the Visual Editor.");
242
252
  return;
243
253
  }
244
- B ? s() : D.push(s);
245
- }, document.getElementById("storyblok-javascript-bridge")))
254
+ M ? s() : z.push(s);
255
+ }, document.getElementById("storyblok-javascript-bridge")) {
256
+ e(void 0);
246
257
  return;
258
+ }
247
259
  const r = document.createElement("script");
248
260
  r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => t(s), r.onload = (s) => {
249
- D.forEach((o) => o()), B = !0, e(s);
261
+ z.forEach((o) => o()), M = !0, e(s);
250
262
  }, document.getElementsByTagName("head")[0].appendChild(r);
251
263
  });
252
- var ae = Object.defineProperty, le = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t) => le(n, typeof e != "symbol" ? e + "" : e, t);
253
- class ce extends Error {
264
+ var le = Object.defineProperty, ce = (n, e, t) => e in n ? le(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t) => ce(n, typeof e != "symbol" ? e + "" : e, t);
265
+ class he extends Error {
254
266
  constructor(e) {
255
267
  super(e), this.name = "AbortError";
256
268
  }
257
269
  }
258
- function he(n, e, t) {
270
+ function ue(n, e, t) {
259
271
  if (!Number.isFinite(e))
260
272
  throw new TypeError("Expected `limit` to be a finite number");
261
273
  if (!Number.isFinite(t))
262
274
  throw new TypeError("Expected `interval` to be a finite number");
263
275
  const r = [];
264
- let s = [], o = 0, l = !1;
265
- const a = async () => {
276
+ let s = [], o = 0, c = !1;
277
+ const l = async () => {
266
278
  o++;
267
279
  const h = r.shift();
268
280
  if (h)
@@ -273,10 +285,10 @@ function he(n, e, t) {
273
285
  h.reject(y);
274
286
  }
275
287
  const f = setTimeout(() => {
276
- o--, r.length > 0 && a(), s = s.filter((y) => y !== f);
288
+ o--, r.length > 0 && l(), s = s.filter((y) => y !== f);
277
289
  }, t);
278
290
  s.includes(f) || s.push(f);
279
- }, c = (...h) => l ? Promise.reject(
291
+ }, i = (...h) => c ? Promise.reject(
280
292
  new Error(
281
293
  "Throttled function is already aborted and not accepting new promises"
282
294
  )
@@ -285,22 +297,22 @@ function he(n, e, t) {
285
297
  resolve: f,
286
298
  reject: y,
287
299
  args: h
288
- }), o < e && a();
300
+ }), o < e && l();
289
301
  });
290
- return c.abort = () => {
291
- l = !0, s.forEach(clearTimeout), s = [], r.forEach(
292
- (h) => h.reject(() => new ce("Throttle function aborted"))
302
+ return i.abort = () => {
303
+ c = !0, s.forEach(clearTimeout), s = [], r.forEach(
304
+ (h) => h.reject(() => new he("Throttle function aborted"))
293
305
  ), r.length = 0;
294
- }, c;
306
+ }, i;
295
307
  }
296
- const ue = (n = "") => n.includes("/cdn/"), de = (n, e = 25, t = 1) => ({
308
+ const de = (n = "") => n.includes("/cdn/"), pe = (n, e = 25, t = 1) => ({
297
309
  ...n,
298
310
  per_page: e,
299
311
  page: t
300
- }), pe = (n) => new Promise((e) => setTimeout(e, n)), fe = (n = 0, e) => Array.from({ length: n }, e), ye = (n = 0, e = n) => {
312
+ }), fe = (n) => new Promise((e) => setTimeout(e, n)), ye = (n = 0, e) => Array.from({ length: n }, e), ge = (n = 0, e = n) => {
301
313
  const t = Math.abs(e - n) || 0, r = n < e ? 1 : -1;
302
- return fe(t, (s, o) => o * r + n);
303
- }, ge = async (n, e) => Promise.all(n.map(e)), me = (n = [], e) => n.map(e).reduce((t, r) => [...t, ...r], []), N = (n, e, t) => {
314
+ return ye(t, (s, o) => o * r + n);
315
+ }, me = async (n, e) => Promise.all(n.map(e)), be = (n = [], e) => n.map(e).reduce((t, r) => [...t, ...r], []), N = (n, e, t) => {
304
316
  const r = [];
305
317
  for (const s in n) {
306
318
  if (!Object.prototype.hasOwnProperty.call(n, s))
@@ -308,16 +320,16 @@ const ue = (n = "") => n.includes("/cdn/"), de = (n, e = 25, t = 1) => ({
308
320
  const o = n[s];
309
321
  if (o == null)
310
322
  continue;
311
- const l = t ? "" : encodeURIComponent(s);
312
- let a;
313
- typeof o == "object" ? a = N(
323
+ const c = t ? "" : encodeURIComponent(s);
324
+ let l;
325
+ typeof o == "object" ? l = N(
314
326
  o,
315
- e ? e + encodeURIComponent(`[${l}]`) : l,
327
+ e ? e + encodeURIComponent(`[${c}]`) : c,
316
328
  Array.isArray(o)
317
- ) : a = `${e ? e + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
329
+ ) : l = `${e ? e + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(o)}`, r.push(l);
318
330
  }
319
331
  return r.join("&");
320
- }, M = (n) => {
332
+ }, F = (n) => {
321
333
  const e = {
322
334
  eu: "api.storyblok.com",
323
335
  us: "api-us.storyblok.com",
@@ -327,7 +339,7 @@ const ue = (n = "") => n.includes("/cdn/"), de = (n, e = 25, t = 1) => ({
327
339
  };
328
340
  return e[n] ?? e.eu;
329
341
  };
330
- class be {
342
+ class ve {
331
343
  constructor(e) {
332
344
  g(this, "baseURL"), g(this, "timeout"), g(this, "headers"), g(this, "responseInterceptor"), g(this, "fetch"), g(this, "ejectInterceptor"), g(this, "url"), g(this, "parameters"), g(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 = {};
333
345
  }
@@ -366,25 +378,25 @@ class be {
366
378
  async _methodHandler(e) {
367
379
  let t = `${this.baseURL}${this.url}`, r = null;
368
380
  e === "get" ? t = `${this.baseURL}${this.url}?${N(this.parameters)}` : r = JSON.stringify(this.parameters);
369
- const s = new URL(t), o = new AbortController(), { signal: l } = o;
370
- let a;
371
- this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
381
+ const s = new URL(t), o = new AbortController(), { signal: c } = o;
382
+ let l;
383
+ this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
372
384
  try {
373
- const c = await this.fetch(`${s}`, {
385
+ const i = await this.fetch(`${s}`, {
374
386
  method: e,
375
387
  headers: this.headers,
376
388
  body: r,
377
- signal: l,
389
+ signal: c,
378
390
  ...this.fetchOptions
379
391
  });
380
- this.timeout && clearTimeout(a);
392
+ this.timeout && clearTimeout(l);
381
393
  const h = await this._responseHandler(
382
- c
394
+ i
383
395
  );
384
396
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
385
- } catch (c) {
397
+ } catch (i) {
386
398
  return {
387
- message: c
399
+ message: i
388
400
  };
389
401
  }
390
402
  }
@@ -430,16 +442,16 @@ class be {
430
442
  });
431
443
  }
432
444
  }
433
- const z = "SB-Agent", P = {
445
+ const G = "SB-Agent", P = {
434
446
  defaultAgentName: "SB-JS-CLIENT",
435
447
  defaultAgentVersion: "SB-Agent-Version",
436
448
  packageVersion: "6.0.0"
437
- }, ve = {
449
+ }, ke = {
438
450
  DRAFT: "draft"
439
451
  };
440
452
  let j = {};
441
453
  const E = {};
442
- class ke {
454
+ class we {
443
455
  /**
444
456
  *
445
457
  * @param config ISbConfig interface
@@ -449,22 +461,22 @@ class ke {
449
461
  g(this, "client"), g(this, "maxRetries"), g(this, "retriesDelay"), g(this, "throttle"), g(this, "accessToken"), g(this, "cache"), g(this, "resolveCounter"), g(this, "relations"), g(this, "links"), g(this, "version"), g(this, "richTextResolver"), g(this, "resolveNestedRelations"), g(this, "stringifiedStoriesCache"), g(this, "inlineAssets");
450
462
  let r = e.endpoint || t;
451
463
  if (!r) {
452
- const l = e.https === !1 ? "http" : "https";
453
- e.oauthToken ? r = `${l}://${M(e.region)}/v1` : r = `${l}://${M(e.region)}/v2`;
464
+ const c = e.https === !1 ? "http" : "https";
465
+ e.oauthToken ? r = `${c}://${F(e.region)}/v1` : r = `${c}://${F(e.region)}/v2`;
454
466
  }
455
467
  const s = new Headers();
456
- s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([l, a]) => {
457
- s.set(l, a);
458
- }), s.has(z) || (s.set(z, P.defaultAgentName), s.set(
468
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([c, l]) => {
469
+ s.set(c, l);
470
+ }), s.has(G) || (s.set(G, P.defaultAgentName), s.set(
459
471
  P.defaultAgentVersion,
460
472
  P.packageVersion
461
473
  ));
462
474
  let o = 5;
463
- e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = he(
475
+ e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ue(
464
476
  this.throttledRequest.bind(this),
465
477
  o,
466
478
  1e3
467
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ve.DRAFT, this.inlineAssets = e.inlineAssets || !1, this.client = new be({
479
+ ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ke.DRAFT, this.inlineAssets = e.inlineAssets || !1, this.client = new ve({
468
480
  baseURL: r,
469
481
  timeout: e.timeout || 0,
470
482
  headers: s,
@@ -476,14 +488,14 @@ class ke {
476
488
  return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
477
489
  }
478
490
  factoryParamOptions(e, t) {
479
- return ue(e) ? this.parseParams(t) : t;
491
+ return de(e) ? this.parseParams(t) : t;
480
492
  }
481
493
  makeRequest(e, t, r, s, o) {
482
- const l = this.factoryParamOptions(
494
+ const c = this.factoryParamOptions(
483
495
  e,
484
- de(t, r, s)
496
+ pe(t, r, s)
485
497
  );
486
- return this.cacheResponse(e, l, void 0, o);
498
+ return this.cacheResponse(e, c, void 0, o);
487
499
  }
488
500
  get(e, t = {}, r) {
489
501
  t || (t = {});
@@ -493,19 +505,19 @@ class ke {
493
505
  return this.cacheResponse(s, o, void 0, r);
494
506
  }
495
507
  async getAll(e, t = {}, r, s) {
496
- const o = (t == null ? void 0 : t.per_page) || 25, l = `/${e}`.replace(/\/$/, ""), a = r ?? l.substring(l.lastIndexOf("/") + 1);
508
+ const o = (t == null ? void 0 : t.per_page) || 25, c = `/${e}`.replace(/\/$/, ""), l = r ?? c.substring(c.lastIndexOf("/") + 1);
497
509
  t.version = t.version || this.version;
498
- const c = 1, h = await this.makeRequest(
499
- l,
510
+ const i = 1, h = await this.makeRequest(
511
+ c,
500
512
  t,
501
513
  o,
502
- c,
514
+ i,
503
515
  s
504
- ), f = h.total ? Math.ceil(h.total / o) : 1, y = await ge(
505
- ye(c, f),
506
- (_) => this.makeRequest(l, t, o, _ + 1, s)
516
+ ), f = h.total ? Math.ceil(h.total / o) : 1, y = await me(
517
+ ge(i, f),
518
+ (_) => this.makeRequest(c, t, o, _ + 1, s)
507
519
  );
508
- return me([h, ...y], (_) => Object.values(_.data[a]));
520
+ return be([h, ...y], (_) => Object.values(_.data[l]));
509
521
  }
510
522
  post(e, t = {}, r) {
511
523
  const s = `/${e}`;
@@ -585,7 +597,7 @@ class ke {
585
597
  * allowing flexible specification of relation patterns.
586
598
  */
587
599
  _insertRelations(e, t, r, s) {
588
- if (Array.isArray(r) ? r.find((l) => l.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
600
+ if (Array.isArray(r) ? r.find((c) => c.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
589
601
  this._resolveField(e, t, s);
590
602
  return;
591
603
  }
@@ -599,14 +611,14 @@ class ke {
599
611
  * @param resolveId - The unique identifier for the current resolution context
600
612
  */
601
613
  iterateTree(e, t, r) {
602
- const s = (o, l = "") => {
614
+ const s = (o, c = "") => {
603
615
  if (!(!o || o._stopResolving)) {
604
616
  if (Array.isArray(o))
605
- o.forEach((a, c) => s(a, `${l}[${c}]`));
617
+ o.forEach((l, i) => s(l, `${c}[${i}]`));
606
618
  else if (typeof o == "object")
607
- for (const a in o) {
608
- const c = l ? `${l}.${a}` : a;
609
- (o.component && o._uid || o.type === "link") && (this._insertRelations(o, a, t, r), this._insertLinks(o, a, r)), s(o[a], c);
619
+ for (const l in o) {
620
+ const i = c ? `${c}.${l}` : l;
621
+ (o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, r), this._insertLinks(o, l, r)), s(o[l], i);
610
622
  }
611
623
  }
612
624
  };
@@ -615,18 +627,18 @@ class ke {
615
627
  async resolveLinks(e, t, r) {
616
628
  let s = [];
617
629
  if (e.link_uuids) {
618
- const o = e.link_uuids.length, l = [], a = 50;
619
- for (let c = 0; c < o; c += a) {
620
- const h = Math.min(o, c + a);
621
- l.push(e.link_uuids.slice(c, h));
630
+ const o = e.link_uuids.length, c = [], l = 50;
631
+ for (let i = 0; i < o; i += l) {
632
+ const h = Math.min(o, i + l);
633
+ c.push(e.link_uuids.slice(i, h));
622
634
  }
623
- for (let c = 0; c < l.length; c++)
635
+ for (let i = 0; i < c.length; i++)
624
636
  (await this.getStories({
625
- per_page: a,
637
+ per_page: l,
626
638
  language: t.language,
627
639
  version: t.version,
628
640
  starts_with: t.starts_with,
629
- by_uuids: l[c].join(",")
641
+ by_uuids: c[i].join(",")
630
642
  })).data.stories.forEach(
631
643
  (h) => {
632
644
  s.push(h);
@@ -644,18 +656,18 @@ class ke {
644
656
  async resolveRelations(e, t, r) {
645
657
  let s = [];
646
658
  if (e.rel_uuids) {
647
- const o = e.rel_uuids.length, l = [], a = 50;
648
- for (let c = 0; c < o; c += a) {
649
- const h = Math.min(o, c + a);
650
- l.push(e.rel_uuids.slice(c, h));
659
+ const o = e.rel_uuids.length, c = [], l = 50;
660
+ for (let i = 0; i < o; i += l) {
661
+ const h = Math.min(o, i + l);
662
+ c.push(e.rel_uuids.slice(i, h));
651
663
  }
652
- for (let c = 0; c < l.length; c++)
664
+ for (let i = 0; i < c.length; i++)
653
665
  (await this.getStories({
654
- per_page: a,
666
+ per_page: l,
655
667
  language: t.language,
656
668
  version: t.version,
657
669
  starts_with: t.starts_with,
658
- by_uuids: l[c].join(","),
670
+ by_uuids: c[i].join(","),
659
671
  excluding_fields: t.excluding_fields
660
672
  })).data.stories.forEach((h) => {
661
673
  s.push(h);
@@ -681,26 +693,26 @@ class ke {
681
693
  */
682
694
  async resolveStories(e, t, r) {
683
695
  var s, o;
684
- let l = [];
685
- if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (l = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((s = e.links) != null && s.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations)
686
- for (const a in this.relations[r])
696
+ let c = [];
697
+ if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (c = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((s = e.links) != null && s.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations)
698
+ for (const l in this.relations[r])
687
699
  this.iterateTree(
688
- this.relations[r][a],
689
- l,
700
+ this.relations[r][l],
701
+ c,
690
702
  r
691
703
  );
692
- e.story ? this.iterateTree(e.story, l, r) : e.stories.forEach((a) => {
693
- this.iterateTree(a, l, r);
704
+ e.story ? this.iterateTree(e.story, c, r) : e.stories.forEach((l) => {
705
+ this.iterateTree(l, c, r);
694
706
  }), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
695
707
  }
696
708
  async cacheResponse(e, t, r, s) {
697
- const o = N({ url: e, params: t }), l = this.cacheProvider();
709
+ const o = N({ url: e, params: t }), c = this.cacheProvider();
698
710
  if (t.version === "published" && e !== "/cdn/spaces/me") {
699
- const a = await l.get(o);
700
- if (a)
701
- return Promise.resolve(a);
711
+ const l = await c.get(o);
712
+ if (l)
713
+ return Promise.resolve(l);
702
714
  }
703
- return new Promise(async (a, c) => {
715
+ return new Promise(async (l, i) => {
704
716
  var h;
705
717
  try {
706
718
  const f = await this.throttle(
@@ -710,24 +722,24 @@ class ke {
710
722
  s
711
723
  );
712
724
  if (f.status !== 200)
713
- return c(f);
725
+ return i(f);
714
726
  let y = { data: f.data, headers: f.headers };
715
727
  if ((h = f.headers) != null && h["per-page"] && (y = Object.assign({}, y, {
716
728
  perPage: f.headers["per-page"] ? Number.parseInt(f.headers["per-page"]) : 0,
717
729
  total: f.headers["per-page"] ? Number.parseInt(f.headers.total) : 0
718
730
  })), y.data.story || y.data.stories) {
719
- const A = this.resolveCounter = ++this.resolveCounter % 1e3;
720
- await this.resolveStories(y.data, t, `${A}`), y = await this.processInlineAssets(y);
731
+ const T = this.resolveCounter = ++this.resolveCounter % 1e3;
732
+ await this.resolveStories(y.data, t, `${T}`), y = await this.processInlineAssets(y);
721
733
  }
722
- t.version === "published" && e !== "/cdn/spaces/me" && await l.set(o, y);
734
+ t.version === "published" && e !== "/cdn/spaces/me" && await c.set(o, y);
723
735
  const _ = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
724
- return t.token && y.data.cv && (_ && E[t.token] && E[t.token] !== y.data.cv && await this.flushCache(), E[t.token] = y.data.cv), a(y);
736
+ return t.token && y.data.cv && (_ && E[t.token] && E[t.token] !== y.data.cv && await this.flushCache(), E[t.token] = y.data.cv), l(y);
725
737
  } catch (f) {
726
738
  if (f.response && f.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
727
739
  return console.log(
728
740
  `Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
729
- ), await pe(this.retriesDelay), this.cacheResponse(e, t, r).then(a).catch(c);
730
- c(f);
741
+ ), await fe(this.retriesDelay), this.cacheResponse(e, t, r).then(l).catch(i);
742
+ i(f);
731
743
  }
732
744
  });
733
745
  }
@@ -766,6 +778,7 @@ class ke {
766
778
  case "custom":
767
779
  if (this.cache.custom)
768
780
  return this.cache.custom;
781
+ // eslint-disable-next-line no-fallthrough
769
782
  default:
770
783
  return {
771
784
  get() {
@@ -806,7 +819,7 @@ class ke {
806
819
  return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
807
820
  }
808
821
  }
809
- const we = (n = {}) => {
822
+ const Te = (n = {}) => {
810
823
  const { apiOptions: e } = n;
811
824
  if (!e || !e.accessToken) {
812
825
  console.error(
@@ -814,8 +827,8 @@ const we = (n = {}) => {
814
827
  );
815
828
  return;
816
829
  }
817
- return { storyblokApi: new ke(e) };
818
- }, Te = (n) => {
830
+ return { storyblokApi: new we(e) };
831
+ }, Re = (n) => {
819
832
  if (typeof n != "object" || typeof n._editable > "u")
820
833
  return {};
821
834
  try {
@@ -835,16 +848,16 @@ const _e = (n, e, t = {}) => {
835
848
  var r;
836
849
  const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((r = window.location) == null ? void 0 : r.href).searchParams.get(
837
850
  "_storyblok"
838
- ), l = o !== null && +o === n;
839
- if (!(!s || !l)) {
851
+ ), c = o !== null && +o === n;
852
+ if (!(!s || !c)) {
840
853
  if (!n) {
841
854
  console.warn("Story ID is not defined. Please provide a valid ID.");
842
855
  return;
843
856
  }
844
857
  window.storyblokRegisterEvent(() => {
845
- new window.StoryblokBridge(t).on(["input", "published", "change"], (a) => {
846
- var c;
847
- a && (a.action === "input" && ((c = a.story) == null ? void 0 : c.id) === n ? e(a.story) : (a.action === "change" || a.action === "published") && a.storyId === n && window.location.reload());
858
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
859
+ var i;
860
+ l && (l.action === "input" && ((i = l.story) == null ? void 0 : i.id) === n ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === n && window.location.reload());
848
861
  });
849
862
  });
850
863
  }
@@ -854,32 +867,32 @@ const _e = (n, e, t = {}) => {
854
867
  bridge: r,
855
868
  accessToken: s,
856
869
  use: o = [],
857
- apiOptions: l = {},
858
- bridgeUrl: a
870
+ apiOptions: c = {},
871
+ bridgeUrl: l
859
872
  } = n;
860
- l.accessToken = l.accessToken || s;
861
- const c = { bridge: r, apiOptions: l };
873
+ c.accessToken = c.accessToken || s;
874
+ const i = { bridge: r, apiOptions: c };
862
875
  let h = {};
863
876
  o.forEach((y) => {
864
- h = { ...h, ...y(c) };
865
- }), a && (x = a);
877
+ h = { ...h, ...y(i) };
878
+ }), l && (x = l);
866
879
  const f = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
867
- return r !== !1 && f && G(x), h;
880
+ return r !== !1 && f && q(x), h;
868
881
  };
869
- function Re(n, e) {
870
- return ie(e).render(n);
882
+ function Ee(n, e) {
883
+ return ae(e).render(n);
871
884
  }
872
- const Ee = () => G(x);
885
+ const Ae = () => q(x);
873
886
  export {
874
887
  v as BlockTypes,
875
- R as MarkTypes,
876
- F as TextTypes,
877
- we as apiPlugin,
878
- Ee as loadStoryblokBridge,
888
+ $ as MarkTypes,
889
+ V as TextTypes,
890
+ Te as apiPlugin,
891
+ Ae as loadStoryblokBridge,
879
892
  _e as registerStoryblokBridge,
880
- Re as renderRichText,
881
- ie as richTextResolver,
882
- Te as storyblokEditable,
893
+ Ee as renderRichText,
894
+ ae as richTextResolver,
895
+ Re as storyblokEditable,
883
896
  $e as storyblokInit,
884
897
  _e as useStoryblokBridge
885
898
  };