@storyblok/react 3.0.4 → 3.0.6

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,26 +1,26 @@
1
- let S = !1;
2
- const E = [], C = (o) => new Promise((e, t) => {
1
+ let _ = !1;
2
+ const j = [], O = (o) => new Promise((t, e) => {
3
3
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
4
  if (window.location === window.parent.location) {
5
5
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
6
  return;
7
7
  }
8
- S ? r() : E.push(r);
8
+ _ ? r() : j.push(r);
9
9
  }, document.getElementById("storyblok-javascript-bridge")))
10
10
  return;
11
11
  const s = document.createElement("script");
12
- s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
13
- E.forEach((i) => i()), S = !0, e(r);
12
+ s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
13
+ j.forEach((i) => i()), _ = !0, t(r);
14
14
  }, document.getElementsByTagName("head")[0].appendChild(s);
15
15
  });
16
- var U = Object.defineProperty, I = (o, e, t) => e in o ? U(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (I(o, typeof e != "symbol" ? e + "" : e, t), t);
16
+ var P = Object.defineProperty, I = (o, t, e) => t in o ? P(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, h = (o, t, e) => (I(o, typeof t != "symbol" ? t + "" : t, e), e);
17
17
  function x(o) {
18
18
  return !(o !== o || o === 1 / 0 || o === -1 / 0);
19
19
  }
20
- function O(o, e, t) {
21
- if (!x(e))
22
- throw new TypeError("Expected `limit` to be a finite number");
20
+ function C(o, t, e) {
23
21
  if (!x(t))
22
+ throw new TypeError("Expected `limit` to be a finite number");
23
+ if (!x(e))
24
24
  throw new TypeError("Expected `interval` to be a finite number");
25
25
  const s = [];
26
26
  let r = [], i = 0;
@@ -30,47 +30,47 @@ function O(o, e, t) {
30
30
  i--, s.length > 0 && n(), r = r.filter(function(u) {
31
31
  return u !== a;
32
32
  });
33
- }, t);
33
+ }, e);
34
34
  r.indexOf(a) < 0 && r.push(a);
35
- const l = s.shift();
36
- l.resolve(o.apply(l.self, l.args));
37
- }, c = function(...a) {
38
- const l = this;
35
+ const c = s.shift();
36
+ c.resolve(o.apply(c.self, c.args));
37
+ }, l = function(...a) {
38
+ const c = this;
39
39
  return new Promise(function(u, p) {
40
40
  s.push({
41
41
  resolve: u,
42
42
  reject: p,
43
43
  args: a,
44
- self: l
45
- }), i < e && n();
44
+ self: c
45
+ }), i < t && n();
46
46
  });
47
47
  };
48
- return c.abort = function() {
48
+ return l.abort = function() {
49
49
  r.forEach(clearTimeout), r = [], s.forEach(function(a) {
50
50
  a.reject(function() {
51
51
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
52
52
  });
53
53
  }), s.length = 0;
54
- }, c;
54
+ }, l;
55
55
  }
56
- class y {
56
+ class b {
57
57
  constructor() {
58
- h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
59
- ...e,
60
- per_page: t,
58
+ h(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (t, e = 25, s = 1) => ({
59
+ ...t,
60
+ per_page: e,
61
61
  page: s
62
- })), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
63
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
64
- return this.arrayFrom(s, (i, n) => n * r + e);
65
- }), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), h(this, "escapeHTML", function(e) {
66
- const t = {
62
+ })), h(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), h(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), h(this, "range", (t = 0, e = t) => {
63
+ const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
64
+ return this.arrayFrom(s, (i, n) => n * r + t);
65
+ }), h(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), h(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], [])), h(this, "escapeHTML", function(t) {
66
+ const e = {
67
67
  "&": "&amp;",
68
68
  "<": "&lt;",
69
69
  ">": "&gt;",
70
70
  '"': "&quot;",
71
71
  "'": "&#39;"
72
72
  }, s = /[&<>"']/g, r = RegExp(s.source);
73
- return e && r.test(e) ? e.replace(s, (i) => t[i]) : e;
73
+ return t && r.test(t) ? t.replace(s, (i) => e[i]) : t;
74
74
  });
75
75
  }
76
76
  /**
@@ -80,18 +80,18 @@ class y {
80
80
  * @param {Boolean} isArray
81
81
  * @return {String} Stringified object
82
82
  */
83
- stringify(e, t, s) {
83
+ stringify(t, e, s) {
84
84
  const r = [];
85
- for (const i in e) {
86
- if (!Object.prototype.hasOwnProperty.call(e, i))
85
+ for (const i in t) {
86
+ if (!Object.prototype.hasOwnProperty.call(t, i))
87
87
  continue;
88
- const n = e[i], c = s ? "" : encodeURIComponent(i);
88
+ const n = t[i], l = s ? "" : encodeURIComponent(i);
89
89
  let a;
90
90
  typeof n == "object" ? a = this.stringify(
91
91
  n,
92
- t ? t + encodeURIComponent("[" + c + "]") : c,
92
+ e ? e + encodeURIComponent("[" + l + "]") : l,
93
93
  Array.isArray(n)
94
- ) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), r.push(a);
94
+ ) : a = (e ? e + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(n), r.push(a);
95
95
  }
96
96
  return r.join("&");
97
97
  }
@@ -100,9 +100,9 @@ class y {
100
100
  * @param {String} regionCode region code, could be eu, us, cn, ap or ca
101
101
  * @return {String} The base URL of the region
102
102
  */
103
- getRegionURL(e) {
104
- const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
105
- switch (e) {
103
+ getRegionURL(t) {
104
+ const e = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
105
+ switch (t) {
106
106
  case "us":
107
107
  return s;
108
108
  case "cn":
@@ -112,24 +112,24 @@ class y {
112
112
  case "ca":
113
113
  return n;
114
114
  default:
115
- return t;
115
+ return e;
116
116
  }
117
117
  }
118
118
  }
119
- const N = function(o, e) {
120
- const t = {};
119
+ const A = function(o, t) {
120
+ const e = {};
121
121
  for (const s in o) {
122
122
  const r = o[s];
123
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
123
+ t.indexOf(s) > -1 && r !== null && (e[s] = r);
124
124
  }
125
- return t;
126
- }, P = (o) => o === "email", A = () => ({
125
+ return e;
126
+ }, N = (o) => o === "email", M = () => ({
127
127
  singleTag: "hr"
128
128
  }), L = () => ({
129
129
  tag: "blockquote"
130
- }), M = () => ({
130
+ }), z = () => ({
131
131
  tag: "ul"
132
- }), D = (o) => ({
132
+ }), U = (o) => ({
133
133
  tag: [
134
134
  "pre",
135
135
  {
@@ -137,24 +137,24 @@ const N = function(o, e) {
137
137
  attrs: o.attrs
138
138
  }
139
139
  ]
140
- }), B = () => ({
140
+ }), H = () => ({
141
141
  singleTag: "br"
142
- }), H = (o) => ({
142
+ }), q = (o) => ({
143
143
  tag: `h${o.attrs.level}`
144
- }), z = (o) => ({
144
+ }), F = (o) => ({
145
145
  singleTag: [
146
146
  {
147
147
  tag: "img",
148
- attrs: N(o.attrs, ["src", "alt", "title"])
148
+ attrs: A(o.attrs, ["src", "alt", "title"])
149
149
  }
150
150
  ]
151
- }), F = () => ({
151
+ }), B = () => ({
152
152
  tag: "li"
153
- }), q = () => ({
154
- tag: "ol"
155
153
  }), V = () => ({
154
+ tag: "ol"
155
+ }), J = () => ({
156
156
  tag: "p"
157
- }), G = (o) => ({
157
+ }), D = (o) => ({
158
158
  tag: [
159
159
  {
160
160
  tag: "span",
@@ -165,58 +165,58 @@ const N = function(o, e) {
165
165
  }
166
166
  }
167
167
  ]
168
- }), J = () => ({
169
- tag: "b"
170
168
  }), Y = () => ({
171
- tag: "s"
169
+ tag: "b"
172
170
  }), K = () => ({
173
- tag: "u"
171
+ tag: "s"
174
172
  }), W = () => ({
173
+ tag: "u"
174
+ }), G = () => ({
175
175
  tag: "strong"
176
- }), X = () => ({
176
+ }), Q = () => ({
177
177
  tag: "code"
178
- }), Z = () => ({
178
+ }), X = () => ({
179
179
  tag: "i"
180
- }), Q = (o) => {
180
+ }), Z = (o) => {
181
181
  if (!o.attrs)
182
182
  return {
183
183
  tag: ""
184
184
  };
185
- const e = new y().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
186
- if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), P(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
187
- for (const r in t.custom)
188
- t[r] = t.custom[r];
189
- delete t.custom;
185
+ const t = new b().escapeHTML, e = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
186
+ if (delete e.linktype, e.href && (e.href = t(o.attrs.href || "")), N(s) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
187
+ for (const r in e.custom)
188
+ e[r] = e.custom[r];
189
+ delete e.custom;
190
190
  }
191
191
  return {
192
192
  tag: [
193
193
  {
194
194
  tag: "a",
195
- attrs: t
195
+ attrs: e
196
196
  }
197
197
  ]
198
198
  };
199
- }, ee = (o) => ({
199
+ }, tt = (o) => ({
200
200
  tag: [
201
201
  {
202
202
  tag: "span",
203
203
  attrs: o.attrs
204
204
  }
205
205
  ]
206
- }), te = () => ({
206
+ }), et = () => ({
207
207
  tag: "sub"
208
- }), se = () => ({
208
+ }), st = () => ({
209
209
  tag: "sup"
210
- }), re = (o) => ({
210
+ }), rt = (o) => ({
211
211
  tag: [
212
212
  {
213
213
  tag: "span",
214
214
  attrs: o.attrs
215
215
  }
216
216
  ]
217
- }), ie = (o) => {
218
- var e;
219
- return (e = o.attrs) != null && e.color ? {
217
+ }), it = (o) => {
218
+ var t;
219
+ return (t = o.attrs) != null && t.color ? {
220
220
  tag: [
221
221
  {
222
222
  tag: "span",
@@ -228,9 +228,9 @@ const N = function(o, e) {
228
228
  } : {
229
229
  tag: ""
230
230
  };
231
- }, ne = (o) => {
232
- var e;
233
- return (e = o.attrs) != null && e.color ? {
231
+ }, nt = (o) => {
232
+ var t;
233
+ return (t = o.attrs) != null && t.color ? {
234
234
  tag: [
235
235
  {
236
236
  tag: "span",
@@ -242,61 +242,61 @@ const N = function(o, e) {
242
242
  } : {
243
243
  tag: ""
244
244
  };
245
- }, oe = {
245
+ }, ot = {
246
246
  nodes: {
247
- horizontal_rule: A,
247
+ horizontal_rule: M,
248
248
  blockquote: L,
249
- bullet_list: M,
250
- code_block: D,
251
- hard_break: B,
252
- heading: H,
253
- image: z,
254
- list_item: F,
255
- ordered_list: q,
256
- paragraph: V,
257
- emoji: G
249
+ bullet_list: z,
250
+ code_block: U,
251
+ hard_break: H,
252
+ heading: q,
253
+ image: F,
254
+ list_item: B,
255
+ ordered_list: V,
256
+ paragraph: J,
257
+ emoji: D
258
258
  },
259
259
  marks: {
260
- bold: J,
261
- strike: Y,
262
- underline: K,
263
- strong: W,
264
- code: X,
265
- italic: Z,
266
- link: Q,
267
- styled: ee,
268
- subscript: te,
269
- superscript: se,
270
- anchor: re,
271
- highlight: ie,
272
- textStyle: ne
273
- }
274
- }, ae = function(o) {
275
- const e = {
260
+ bold: Y,
261
+ strike: K,
262
+ underline: W,
263
+ strong: G,
264
+ code: Q,
265
+ italic: X,
266
+ link: Z,
267
+ styled: tt,
268
+ subscript: et,
269
+ superscript: st,
270
+ anchor: rt,
271
+ highlight: it,
272
+ textStyle: nt
273
+ }
274
+ }, at = function(o) {
275
+ const t = {
276
276
  "&": "&amp;",
277
277
  "<": "&lt;",
278
278
  ">": "&gt;",
279
279
  '"': "&quot;",
280
280
  "'": "&#39;"
281
- }, t = /[&<>"']/g, s = RegExp(t.source);
282
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
281
+ }, e = /[&<>"']/g, s = RegExp(e.source);
282
+ return o && s.test(o) ? o.replace(e, (r) => t[r]) : o;
283
283
  };
284
- class b {
285
- constructor(e) {
286
- h(this, "marks"), h(this, "nodes"), e || (e = oe), this.marks = e.marks || [], this.nodes = e.nodes || [];
284
+ class k {
285
+ constructor(t) {
286
+ h(this, "marks"), h(this, "nodes"), t || (t = ot), this.marks = t.marks || [], this.nodes = t.nodes || [];
287
287
  }
288
- addNode(e, t) {
289
- this.nodes[e] = t;
288
+ addNode(t, e) {
289
+ this.nodes[t] = e;
290
290
  }
291
- addMark(e, t) {
292
- this.marks[e] = t;
291
+ addMark(t, e) {
292
+ this.marks[t] = e;
293
293
  }
294
- render(e, t = { optimizeImages: !1 }) {
295
- if (e && e.content && Array.isArray(e.content)) {
294
+ render(t, e = { optimizeImages: !1 }) {
295
+ if (t && t.content && Array.isArray(t.content)) {
296
296
  let s = "";
297
- return e.content.forEach((r) => {
297
+ return t.content.forEach((r) => {
298
298
  s += this.renderNode(r);
299
- }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
299
+ }), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
300
300
  }
301
301
  return console.warn(
302
302
  `The render method must receive an Object with a "content" field.
@@ -325,54 +325,54 @@ class b {
325
325
  }`
326
326
  ), "";
327
327
  }
328
- optimizeImages(e, t) {
328
+ optimizeImages(t, e) {
329
329
  let s = 0, r = 0, i = "", n = "";
330
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
331
- const c = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
332
- return e = e.replace(
330
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (i += `width="${e.width}" `, s = e.width), typeof e.height == "number" && e.height > 0 && (i += `height="${e.height}" `, r = e.height), (e.loading === "lazy" || e.loading === "eager") && (i += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (i += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (n += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (n += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-Fa-f]{6}/g) || e.filters.fill === "transparent") && (n += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (n += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (n += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (n += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (n += `:rotate(${e.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), i.length > 0 && (t = t.replace(/<img/g, `<img ${i.trim()}`));
331
+ const l = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
332
+ return t = t.replace(
333
333
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
334
- `a.storyblok.com/f/$1/$2.$3/m/${c}`
335
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
336
- var l, u;
334
+ `a.storyblok.com/f/$1/$2.$3/m/${l}`
335
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
336
+ var c, u;
337
337
  const p = a.match(
338
338
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
339
339
  );
340
340
  if (p && p.length > 0) {
341
- const g = {
342
- srcset: (l = t.srcset) == null ? void 0 : l.map((d) => {
343
- if (typeof d == "number")
344
- return `//${p}/m/${d}x0${n} ${d}w`;
345
- if (typeof d == "object" && d.length === 2) {
346
- let _ = 0, T = 0;
347
- return typeof d[0] == "number" && (_ = d[0]), typeof d[1] == "number" && (T = d[1]), `//${p}/m/${_}x${T}${n} ${_}w`;
341
+ const d = {
342
+ srcset: (c = e.srcset) == null ? void 0 : c.map((g) => {
343
+ if (typeof g == "number")
344
+ return `//${p}/m/${g}x0${n} ${g}w`;
345
+ if (typeof g == "object" && g.length === 2) {
346
+ let v = 0, T = 0;
347
+ return typeof g[0] == "number" && (v = g[0]), typeof g[1] == "number" && (T = g[1]), `//${p}/m/${v}x${T}${n} ${v}w`;
348
348
  }
349
349
  }).join(", "),
350
- sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
350
+ sizes: (u = e.sizes) == null ? void 0 : u.map((g) => g).join(", ")
351
351
  };
352
- let v = "";
353
- return g.srcset && (v += `srcset="${g.srcset}" `), g.sizes && (v += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${v.trim()}`);
352
+ let f = "";
353
+ return d.srcset && (f += `srcset="${d.srcset}" `), d.sizes && (f += `sizes="${d.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
354
354
  }
355
355
  return a;
356
- })), e;
356
+ })), t;
357
357
  }
358
- renderNode(e) {
359
- const t = [];
360
- e.marks && e.marks.forEach((r) => {
358
+ renderNode(t) {
359
+ const e = [];
360
+ t.marks && t.marks.forEach((r) => {
361
361
  const i = this.getMatchingMark(r);
362
- i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
362
+ i && i.tag !== "" && e.push(this.renderOpeningTag(i.tag));
363
363
  });
364
- const s = this.getMatchingNode(e);
365
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
366
- t.push(this.renderNode(r));
367
- }) : e.text ? t.push(ae(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
364
+ const s = this.getMatchingNode(t);
365
+ return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
366
+ e.push(this.renderNode(r));
367
+ }) : t.text ? e.push(at(t.text)) : s && s.singleTag ? e.push(this.renderTag(s.singleTag, " /")) : s && s.html ? e.push(s.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), s && s.tag && e.push(this.renderClosingTag(s.tag)), t.marks && t.marks.slice(0).reverse().forEach((r) => {
368
368
  const i = this.getMatchingMark(r);
369
- i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
370
- }), t.join("");
369
+ i && i.tag !== "" && e.push(this.renderClosingTag(i.tag));
370
+ }), e.join("");
371
371
  }
372
- renderTag(e, t) {
373
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
372
+ renderTag(t, e) {
373
+ return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
374
374
  if (s.constructor === String)
375
- return `<${s}${t}>`;
375
+ return `<${s}${e}>`;
376
376
  {
377
377
  let r = `<${s.tag}`;
378
378
  if (s.attrs)
@@ -380,46 +380,46 @@ class b {
380
380
  const n = s.attrs[i];
381
381
  n !== null && (r += ` ${i}="${n}"`);
382
382
  }
383
- return `${r}${t}>`;
383
+ return `${r}${e}>`;
384
384
  }
385
385
  }).join("");
386
386
  }
387
- renderOpeningTag(e) {
388
- return this.renderTag(e, "");
387
+ renderOpeningTag(t) {
388
+ return this.renderTag(t, "");
389
389
  }
390
- renderClosingTag(e) {
391
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
390
+ renderClosingTag(t) {
391
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
392
392
  }
393
- getMatchingNode(e) {
394
- const t = this.nodes[e.type];
395
- if (typeof t == "function")
396
- return t(e);
393
+ getMatchingNode(t) {
394
+ const e = this.nodes[t.type];
395
+ if (typeof e == "function")
396
+ return e(t);
397
397
  }
398
- getMatchingMark(e) {
399
- const t = this.marks[e.type];
400
- if (typeof t == "function")
401
- return t(e);
398
+ getMatchingMark(t) {
399
+ const e = this.marks[t.type];
400
+ if (typeof e == "function")
401
+ return e(t);
402
402
  }
403
- renderEmoji(e) {
404
- if (e.attrs.emoji)
405
- return e.attrs.emoji;
406
- const t = [
403
+ renderEmoji(t) {
404
+ if (t.attrs.emoji)
405
+ return t.attrs.emoji;
406
+ const e = [
407
407
  {
408
408
  tag: "img",
409
409
  attrs: {
410
- src: e.attrs.fallbackImage,
410
+ src: t.attrs.fallbackImage,
411
411
  draggable: "false",
412
412
  loading: "lazy",
413
413
  align: "absmiddle"
414
414
  }
415
415
  }
416
416
  ];
417
- return this.renderTag(t, " /");
417
+ return this.renderTag(e, " /");
418
418
  }
419
419
  }
420
- class le {
421
- constructor(e) {
422
- h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), 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 = {};
420
+ class lt {
421
+ constructor(t) {
422
+ h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), h(this, "fetchOptions"), this.baseURL = t.baseURL, this.headers = t.headers || new Headers(), this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
423
423
  }
424
424
  /**
425
425
  *
@@ -427,170 +427,176 @@ class le {
427
427
  * @param params ISbStoriesParams
428
428
  * @returns Promise<ISbResponse | Error>
429
429
  */
430
- get(e, t) {
431
- return this.url = e, this.parameters = t, this._methodHandler("get");
430
+ get(t, e) {
431
+ return this.url = t, this.parameters = e, this._methodHandler("get");
432
432
  }
433
- post(e, t) {
434
- return this.url = e, this.parameters = t, this._methodHandler("post");
433
+ post(t, e) {
434
+ return this.url = t, this.parameters = e, this._methodHandler("post");
435
435
  }
436
- put(e, t) {
437
- return this.url = e, this.parameters = t, this._methodHandler("put");
436
+ put(t, e) {
437
+ return this.url = t, this.parameters = e, this._methodHandler("put");
438
438
  }
439
- delete(e, t) {
440
- return this.url = e, this.parameters = t, this._methodHandler("delete");
439
+ delete(t, e) {
440
+ return this.url = t, this.parameters = e, this._methodHandler("delete");
441
441
  }
442
- async _responseHandler(e) {
443
- const t = [], s = {
442
+ async _responseHandler(t) {
443
+ const e = [], s = {
444
444
  data: {},
445
445
  headers: {},
446
446
  status: 0,
447
447
  statusText: ""
448
448
  };
449
- e.status !== 204 && await e.json().then((r) => {
449
+ t.status !== 204 && await t.json().then((r) => {
450
450
  s.data = r;
451
451
  });
452
- for (const r of e.headers.entries())
453
- t[r[0]] = r[1];
454
- return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
455
- }
456
- async _methodHandler(e) {
457
- let t = `${this.baseURL}${this.url}`, s = null;
458
- if (e === "get") {
459
- const a = new y();
460
- t = `${this.baseURL}${this.url}?${a.stringify(
452
+ for (const r of t.headers.entries())
453
+ e[r[0]] = r[1];
454
+ return s.headers = { ...e }, s.status = t.status, s.statusText = t.statusText, s;
455
+ }
456
+ async _methodHandler(t) {
457
+ let e = `${this.baseURL}${this.url}`, s = null;
458
+ if (t === "get") {
459
+ const a = new b();
460
+ e = `${this.baseURL}${this.url}?${a.stringify(
461
461
  this.parameters
462
462
  )}`;
463
463
  } else
464
464
  s = JSON.stringify(this.parameters);
465
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
466
- let c;
467
- this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
465
+ const r = new URL(e), i = new AbortController(), { signal: n } = i;
466
+ let l;
467
+ this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
468
468
  try {
469
469
  const a = await fetch(`${r}`, {
470
- method: e,
470
+ method: t,
471
471
  headers: this.headers,
472
472
  body: s,
473
- signal: n
473
+ signal: n,
474
+ ...this.fetchOptions
474
475
  });
475
- this.timeout && clearTimeout(c);
476
- const l = await this._responseHandler(a);
477
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
476
+ this.timeout && clearTimeout(l);
477
+ const c = await this._responseHandler(
478
+ a
479
+ );
480
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
478
481
  } catch (a) {
479
482
  return {
480
483
  message: a
481
484
  };
482
485
  }
483
486
  }
487
+ setFetchOptions(t = {}) {
488
+ Object.keys(t).length > 0 && "method" in t && delete t.method, this.fetchOptions = { ...t };
489
+ }
484
490
  eject() {
485
491
  this.ejectInterceptor = !0;
486
492
  }
487
- _statusHandler(e) {
488
- const t = /20[0-6]/g;
493
+ _statusHandler(t) {
494
+ const e = /20[0-6]/g;
489
495
  return new Promise((s, r) => {
490
- if (t.test(`${e.status}`))
491
- return s(e);
496
+ if (e.test(`${t.status}`))
497
+ return s(t);
492
498
  const i = {
493
- message: e.statusText,
494
- status: e.status,
495
- response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
499
+ message: t.statusText,
500
+ status: t.status,
501
+ response: Array.isArray(t.data) ? t.data[0] : t.data.error || t.data.slug
496
502
  };
497
503
  r(i);
498
504
  });
499
505
  }
500
506
  }
501
- var ce = { NVM_INC: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/include/node", TERM_PROGRAM: "iTerm.app", NODE: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NVM_CD_FLAGS: "-q", INIT_CWD: "/Users/lisilinhart/Code/storyblok-js-client", SHELL: "/bin/zsh", TERM: "xterm-256color", TMPDIR: "/var/folders/9v/t3hq3s9n2rj6_x9jlsjjq95w0000gn/T/", npm_config_metrics_registry: "https://registry.npmjs.org/", npm_config_global_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", TERM_PROGRAM_VERSION: "3.4.20", TERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", COLOR: "0", npm_config_noproxy: "", ZSH: "/Users/lisilinhart/.oh-my-zsh", npm_config_local_prefix: "/Users/lisilinhart/Code/storyblok-js-client", USER: "lisilinhart", NVM_DIR: "/Users/lisilinhart/.nvm", COMMAND_MODE: "unix2003", npm_config_globalconfig: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/etc/npmrc", SSH_AUTH_SOCK: "/private/tmp/com.apple.launchd.oUounWp9qr/Listeners", __CF_USER_TEXT_ENCODING: "0x1F5:0x0:0x5C", npm_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/bin/npm-cli.js", PAGER: "less", npm_package_integrity: "null", LSCOLORS: "Gxfxcxdxbxegedabagacad", PATH: "/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.yarn/bin:/Users/lisilinhart/.config/yarn/global/node_modules/.bin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin:/Users/lisilinhart/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/lisilinhart/.cargo/bin", RUBY_CONFIGURE_OPTS: "--with-openssl-dir=/usr/local/opt/openssl@1.1", LaunchInstanceID: "9D2A03D3-35CC-4CDD-810D-0D5C25991BBB", _: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", npm_package_json: "/Users/lisilinhart/Code/storyblok-js-client/package.json", __CFBundleIdentifier: "com.googlecode.iterm2", npm_config_init_module: "/Users/lisilinhart/.npm-init.js", npm_config_userconfig: "/Users/lisilinhart/.npmrc", PWD: "/Users/lisilinhart/Code/storyblok-js-client", npm_command: "run-script", P9K_SSH: "0", EDITOR: "vi", npm_lifecycle_event: "build", LANG: "de_AT.UTF-8", P9K_TTY: "old", npm_package_name: "storyblok-js-client", ITERM_PROFILE: "Default", XPC_FLAGS: "0x0", RBENV_SHELL: "zsh", npm_config_node_gyp: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js", XPC_SERVICE_NAME: "0", npm_package_version: "6.4.1", COLORFGBG: "7;0", HOME: "/Users/lisilinhart", SHLVL: "3", npm_package_resolved: "/Users/lisilinhart/Code/storyblok-js-client", LC_TERMINAL_VERSION: "3.4.20", ITERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", LOGNAME: "lisilinhart", LESS: "-R", npm_config_cache: "/Users/lisilinhart/.npm", npm_lifecycle_script: "node vite.build.mjs && tsc", NVM_BIN: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin", npm_config_user_agent: "npm/9.5.1 node/v18.16.0 darwin x64 workspaces/false", LC_TERMINAL: "iTerm2", SECURITYSESSIONID: "186a1", COLORTERM: "truecolor", npm_config_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", npm_node_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NODE_ENV: "production" };
502
- const $ = "SB-Agent", k = {
507
+ var ct = { npm_package_version: "6.6.1" };
508
+ const S = "SB-Agent", w = {
503
509
  defaultAgentName: "SB-JS-CLIENT",
504
510
  defaultAgentVersion: "SB-Agent-Version",
505
- packageVersion: ce.npm_package_version
511
+ packageVersion: ct.npm_package_version
506
512
  };
507
- let f = {};
513
+ let y = {};
508
514
  const m = {};
509
- class he {
515
+ class ht {
510
516
  /**
511
517
  *
512
518
  * @param config ISbConfig interface
513
519
  * @param endpoint string, optional
514
520
  */
515
- constructor(e, t) {
521
+ constructor(t, e) {
516
522
  h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), h(this, "stringifiedStoriesCache");
517
- let s = e.endpoint || t;
518
- if (!s) {
519
- const n = new y().getRegionURL, c = e.https === !1 ? "http" : "https";
520
- e.oauthToken ? s = `${c}://${n(e.region)}/v1` : s = `${c}://${n(e.region)}/v2`;
521
- }
522
- const r = new Headers();
523
- if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
524
- for (const n in e.headers)
525
- r.set(n, e.headers[n]);
526
- r.has($) || (r.set($, k.defaultAgentName), r.set(
527
- k.defaultAgentVersion,
528
- k.packageVersion
523
+ let s = t.endpoint || e;
524
+ const r = new b().getRegionURL, i = t.https === !1 ? "http" : "https";
525
+ t.oauthToken ? s = `${i}://${r(t.region)}/v1` : s = `${i}://${r(t.region)}/v2`;
526
+ const n = new Headers();
527
+ if (n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), t.headers)
528
+ for (const a in t.headers)
529
+ n.set(a, t.headers[a]);
530
+ n.has(S) || (n.set(S, w.defaultAgentName), n.set(
531
+ w.defaultAgentVersion,
532
+ w.packageVersion
529
533
  ));
530
- let i = 5;
531
- e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new b(e.richTextSchema) : this.richTextResolver = new b(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = O(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new y(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new le({
534
+ let l = 5;
535
+ t.oauthToken && (n.set("Authorization", t.oauthToken), l = 3), t.rateLimit && (l = t.rateLimit), t.richTextSchema ? this.richTextResolver = new k(t.richTextSchema) : this.richTextResolver = new k(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = C(this.throttledRequest, l, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = t.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new lt({
532
536
  baseURL: s,
533
- timeout: e.timeout || 0,
534
- headers: r,
535
- responseInterceptor: e.responseInterceptor,
536
- fetch: e.fetch
537
+ timeout: t.timeout || 0,
538
+ headers: n,
539
+ responseInterceptor: t.responseInterceptor,
540
+ fetch: t.fetch
537
541
  });
538
542
  }
539
- setComponentResolver(e) {
540
- this.richTextResolver.addNode("blok", (t) => {
543
+ setComponentResolver(t) {
544
+ this.richTextResolver.addNode("blok", (e) => {
541
545
  let s = "";
542
- return t.attrs.body && t.attrs.body.forEach((r) => {
543
- s += e(r.component, r);
546
+ return e.attrs.body && e.attrs.body.forEach((r) => {
547
+ s += t(r.component, r);
544
548
  }), {
545
549
  html: s
546
550
  };
547
551
  });
548
552
  }
549
- parseParams(e) {
550
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
553
+ parseParams(t) {
554
+ return t.token || (t.token = this.getToken()), t.cv || (t.cv = m[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
551
555
  }
552
- factoryParamOptions(e, t) {
553
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
556
+ factoryParamOptions(t, e) {
557
+ return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
554
558
  }
555
- makeRequest(e, t, s, r) {
559
+ makeRequest(t, e, s, r) {
556
560
  const i = this.factoryParamOptions(
557
- e,
558
- this.helpers.getOptionsPage(t, s, r)
561
+ t,
562
+ this.helpers.getOptionsPage(e, s, r)
559
563
  );
560
- return this.cacheResponse(e, i);
561
- }
562
- get(e, t) {
563
- t || (t = {});
564
- const s = `/${e}`, r = this.factoryParamOptions(s, t);
565
- return this.cacheResponse(s, r);
566
- }
567
- async getAll(e, t, s) {
568
- const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, n = i.split("/"), c = s || n[n.length - 1], a = 1, l = await this.makeRequest(i, t, r, a), u = l.total ? Math.ceil(l.total / r) : 1, p = await this.helpers.asyncMap(
569
- this.helpers.range(a, u),
570
- (g) => this.makeRequest(i, t, r, g + 1)
564
+ return this.cacheResponse(t, i);
565
+ }
566
+ get(t, e, s) {
567
+ e || (e = {});
568
+ const r = `/${t}`, i = this.factoryParamOptions(r, e);
569
+ return this.client.setFetchOptions(s), this.cacheResponse(r, i);
570
+ }
571
+ async getAll(t, e, s, r) {
572
+ const i = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, l = n.split("/"), a = s || l[l.length - 1], c = 1, u = await this.makeRequest(n, e, i, c), p = u.total ? Math.ceil(u.total / i) : 1;
573
+ this.client.setFetchOptions(r);
574
+ const d = await this.helpers.asyncMap(
575
+ this.helpers.range(c, p),
576
+ (f) => this.makeRequest(n, e, i, f + 1)
571
577
  );
572
578
  return this.helpers.flatMap(
573
- [l, ...p],
574
- (g) => Object.values(g.data[c])
579
+ [u, ...d],
580
+ (f) => Object.values(f.data[a])
575
581
  );
576
582
  }
577
- post(e, t) {
578
- const s = `/${e}`;
579
- return Promise.resolve(this.throttle("post", s, t));
583
+ post(t, e, s) {
584
+ const r = `/${t}`;
585
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, e));
580
586
  }
581
- put(e, t) {
582
- const s = `/${e}`;
583
- return Promise.resolve(this.throttle("put", s, t));
587
+ put(t, e, s) {
588
+ const r = `/${t}`;
589
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, e));
584
590
  }
585
- delete(e, t) {
586
- const s = `/${e}`;
587
- return Promise.resolve(this.throttle("delete", s, t));
591
+ delete(t, e, s) {
592
+ const r = `/${t}`;
593
+ return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, e));
588
594
  }
589
- getStories(e) {
590
- return this.get("cdn/stories", e);
595
+ getStories(t, e) {
596
+ return this.client.setFetchOptions(e), this.get("cdn/stories", t);
591
597
  }
592
- getStory(e, t) {
593
- return this.get(`cdn/stories/${e}`, t);
598
+ getStory(t, e, s) {
599
+ return this.client.setFetchOptions(s), this.get(`cdn/stories/${t}`, e);
594
600
  }
595
601
  getToken() {
596
602
  return this.accessToken;
@@ -598,11 +604,11 @@ class he {
598
604
  ejectInterceptor() {
599
605
  this.client.eject();
600
606
  }
601
- _cleanCopy(e) {
602
- return JSON.parse(JSON.stringify(e));
607
+ _cleanCopy(t) {
608
+ return JSON.parse(JSON.stringify(t));
603
609
  }
604
- _insertLinks(e, t, s) {
605
- const r = e[t];
610
+ _insertLinks(t, e, s) {
611
+ const r = t[e];
606
612
  r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
607
613
  }
608
614
  /**
@@ -611,15 +617,15 @@ class he {
611
617
  * @param uuid The uuid of the story
612
618
  * @returns string | object
613
619
  */
614
- getStoryReference(e, t) {
615
- return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
616
- this.relations[e][t]
617
- )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
620
+ getStoryReference(t, e) {
621
+ return this.relations[t][e] ? (this.stringifiedStoriesCache[e] || (this.stringifiedStoriesCache[e] = JSON.stringify(
622
+ this.relations[t][e]
623
+ )), JSON.parse(this.stringifiedStoriesCache[e])) : e;
618
624
  }
619
- _insertRelations(e, t, s, r) {
620
- s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
625
+ _insertRelations(t, e, s, r) {
626
+ s.indexOf(`${t.component}.${e}`) > -1 && (typeof t[e] == "string" ? t[e] = this.getStoryReference(r, t[e]) : Array.isArray(t[e]) && (t[e] = t[e].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
621
627
  }
622
- iterateTree(e, t, s) {
628
+ iterateTree(t, e, s) {
623
629
  const r = (i) => {
624
630
  if (i != null) {
625
631
  if (i.constructor === Array)
@@ -632,7 +638,7 @@ class he {
632
638
  (i.component && i._uid || i.type === "link") && (this._insertRelations(
633
639
  i,
634
640
  n,
635
- t,
641
+ e,
636
642
  s
637
643
  ), this._insertLinks(
638
644
  i,
@@ -642,29 +648,29 @@ class he {
642
648
  }
643
649
  }
644
650
  };
645
- r(e.content);
651
+ r(t.content);
646
652
  }
647
- async resolveLinks(e, t, s) {
653
+ async resolveLinks(t, e, s) {
648
654
  let r = [];
649
- if (e.link_uuids) {
650
- const i = e.link_uuids.length, n = [], c = 50;
651
- for (let a = 0; a < i; a += c) {
652
- const l = Math.min(i, a + c);
653
- n.push(e.link_uuids.slice(a, l));
655
+ if (t.link_uuids) {
656
+ const i = t.link_uuids.length, n = [], l = 50;
657
+ for (let a = 0; a < i; a += l) {
658
+ const c = Math.min(i, a + l);
659
+ n.push(t.link_uuids.slice(a, c));
654
660
  }
655
661
  for (let a = 0; a < n.length; a++)
656
662
  (await this.getStories({
657
- per_page: c,
658
- language: t.language,
659
- version: t.version,
663
+ per_page: l,
664
+ language: e.language,
665
+ version: e.version,
660
666
  by_uuids: n[a].join(",")
661
667
  })).data.stories.forEach(
662
- (l) => {
663
- r.push(l);
668
+ (c) => {
669
+ r.push(c);
664
670
  }
665
671
  );
666
672
  } else
667
- r = e.links;
673
+ r = t.links;
668
674
  r.forEach((i) => {
669
675
  this.links[s][i.uuid] = {
670
676
  ...i,
@@ -672,26 +678,26 @@ class he {
672
678
  };
673
679
  });
674
680
  }
675
- async resolveRelations(e, t, s) {
681
+ async resolveRelations(t, e, s) {
676
682
  let r = [];
677
- if (e.rel_uuids) {
678
- const i = e.rel_uuids.length, n = [], c = 50;
679
- for (let a = 0; a < i; a += c) {
680
- const l = Math.min(i, a + c);
681
- n.push(e.rel_uuids.slice(a, l));
683
+ if (t.rel_uuids) {
684
+ const i = t.rel_uuids.length, n = [], l = 50;
685
+ for (let a = 0; a < i; a += l) {
686
+ const c = Math.min(i, a + l);
687
+ n.push(t.rel_uuids.slice(a, c));
682
688
  }
683
689
  for (let a = 0; a < n.length; a++)
684
690
  (await this.getStories({
685
- per_page: c,
686
- language: t.language,
687
- version: t.version,
691
+ per_page: l,
692
+ language: e.language,
693
+ version: e.version,
688
694
  by_uuids: n[a].join(","),
689
- excluding_fields: t.excluding_fields
690
- })).data.stories.forEach((l) => {
691
- r.push(l);
695
+ excluding_fields: e.excluding_fields
696
+ })).data.stories.forEach((c) => {
697
+ r.push(c);
692
698
  });
693
699
  } else
694
- r = e.rels;
700
+ r = t.rels;
695
701
  r && r.length > 0 && r.forEach((i) => {
696
702
  this.relations[s][i.uuid] = {
697
703
  ...i,
@@ -699,52 +705,61 @@ class he {
699
705
  };
700
706
  });
701
707
  }
702
- async resolveStories(e, t, s) {
708
+ /**
709
+ *
710
+ * @param responseData
711
+ * @param params
712
+ * @param resolveId
713
+ * @description Resolves the relations and links of the stories
714
+ * @returns Promise<void>
715
+ *
716
+ */
717
+ async resolveStories(t, e, s) {
703
718
  var r, i;
704
719
  let n = [];
705
- if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
706
- for (const c in this.relations[s])
720
+ if (this.links[s] = {}, this.relations[s] = {}, typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (n = e.resolve_relations.split(",")), await this.resolveRelations(t, e, s)), e.resolve_links && ["1", "story", "url", "link"].indexOf(e.resolve_links) > -1 && ((r = t.links) != null && r.length || (i = t.link_uuids) != null && i.length) && await this.resolveLinks(t, e, s), this.resolveNestedRelations)
721
+ for (const l in this.relations[s])
707
722
  this.iterateTree(
708
- this.relations[s][c],
723
+ this.relations[s][l],
709
724
  n,
710
725
  s
711
726
  );
712
- e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((c) => {
713
- this.iterateTree(c, n, s);
727
+ t.story ? this.iterateTree(t.story, n, s) : t.stories.forEach((l) => {
728
+ this.iterateTree(l, n, s);
714
729
  }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
715
730
  }
716
- async cacheResponse(e, t, s) {
731
+ async cacheResponse(t, e, s) {
717
732
  (typeof s > "u" || !s) && (s = 0);
718
- const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
719
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
733
+ const r = this.helpers.stringify({ url: t, params: e }), i = this.cacheProvider();
734
+ if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
720
735
  const n = await i.get(r);
721
736
  if (n)
722
737
  return Promise.resolve(n);
723
738
  }
724
- return new Promise(async (n, c) => {
739
+ return new Promise(async (n, l) => {
725
740
  var a;
726
741
  try {
727
- const l = await this.throttle("get", e, t);
728
- if (l.status !== 200)
729
- return c(l);
730
- let u = { data: l.data, headers: l.headers };
731
- if ((a = l.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
732
- perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
733
- total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
742
+ const c = await this.throttle("get", t, e);
743
+ if (c.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
744
+ return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(t, e, s).then(n).catch(l);
745
+ if (c.status !== 200)
746
+ return l(c);
747
+ let u = { data: c.data, headers: c.headers };
748
+ if ((a = c.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
749
+ perPage: c.headers["per-page"] ? parseInt(c.headers["per-page"]) : 0,
750
+ total: c.headers["per-page"] ? parseInt(c.headers.total) : 0
734
751
  })), u.data.story || u.data.stories) {
735
752
  const p = this.resolveCounter = ++this.resolveCounter % 1e3;
736
- await this.resolveStories(u.data, t, `${p}`);
753
+ await this.resolveStories(u.data, e, `${p}`);
737
754
  }
738
- return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version === "draft" && m[t.token] != u.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : u.data.cv), n(u);
739
- } catch (l) {
740
- if (l.response && l.response.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
741
- return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(n).catch(c);
742
- c(l);
755
+ return e.version === "published" && t != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && e.token && (e.version === "draft" && m[e.token] != u.data.cv && await this.flushCache(), m[e.token] = e.cv ? e.cv : u.data.cv), n(u);
756
+ } catch (c) {
757
+ l(c);
743
758
  }
744
759
  });
745
760
  }
746
- throttledRequest(e, t, s) {
747
- return this.client[e](t, s);
761
+ throttledRequest(t, e, s) {
762
+ return this.client[t](e, s);
748
763
  }
749
764
  cacheVersions() {
750
765
  return m;
@@ -752,21 +767,24 @@ class he {
752
767
  cacheVersion() {
753
768
  return m[this.accessToken];
754
769
  }
770
+ setCacheVersion(t) {
771
+ this.accessToken && (m[this.accessToken] = t);
772
+ }
755
773
  cacheProvider() {
756
774
  switch (this.cache.type) {
757
775
  case "memory":
758
776
  return {
759
- get(e) {
760
- return Promise.resolve(f[e]);
777
+ get(t) {
778
+ return Promise.resolve(y[t]);
761
779
  },
762
780
  getAll() {
763
- return Promise.resolve(f);
781
+ return Promise.resolve(y);
764
782
  },
765
- set(e, t) {
766
- return f[e] = t, Promise.resolve(void 0);
783
+ set(t, e) {
784
+ return y[t] = e, Promise.resolve(void 0);
767
785
  },
768
786
  flush() {
769
- return f = {}, Promise.resolve(void 0);
787
+ return y = {}, Promise.resolve(void 0);
770
788
  }
771
789
  };
772
790
  case "custom":
@@ -793,32 +811,32 @@ class he {
793
811
  return await this.cacheProvider().flush(), this;
794
812
  }
795
813
  }
796
- const pe = (o = {}) => {
797
- const { apiOptions: e } = o;
798
- if (!e.accessToken) {
814
+ const pt = (o = {}) => {
815
+ const { apiOptions: t } = o;
816
+ if (!t.accessToken) {
799
817
  console.error(
800
818
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
801
819
  );
802
820
  return;
803
821
  }
804
- return { storyblokApi: new he(e) };
805
- }, de = (o) => {
822
+ return { storyblokApi: new ht(t) };
823
+ }, gt = (o) => {
806
824
  if (typeof o != "object" || typeof o._editable > "u")
807
825
  return {};
808
826
  try {
809
- const e = JSON.parse(
827
+ const t = JSON.parse(
810
828
  o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
811
829
  );
812
- return e ? {
813
- "data-blok-c": JSON.stringify(e),
814
- "data-blok-uid": e.id + "-" + e.uid
830
+ return t ? {
831
+ "data-blok-c": JSON.stringify(t),
832
+ "data-blok-uid": t.id + "-" + t.uid
815
833
  } : {};
816
834
  } catch {
817
835
  return {};
818
836
  }
819
837
  };
820
- let R, w = "https://app.storyblok.com/f/storyblok-v2-latest.js";
821
- const ge = (o, e, t = {}) => {
838
+ let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
839
+ const dt = (o, t, e = {}) => {
822
840
  var s;
823
841
  const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
824
842
  "_storyblok"
@@ -829,57 +847,57 @@ const ge = (o, e, t = {}) => {
829
847
  return;
830
848
  }
831
849
  window.storyblokRegisterEvent(() => {
832
- new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
833
- n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
850
+ new window.StoryblokBridge(e).on(["input", "published", "change"], (n) => {
851
+ n.action === "input" && n.story.id === o ? t(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
834
852
  });
835
853
  });
836
854
  }
837
- }, me = (o = {}) => {
838
- var e, t;
855
+ }, ft = (o = {}) => {
856
+ var t, e;
839
857
  const {
840
858
  bridge: s,
841
859
  accessToken: r,
842
860
  use: i = [],
843
861
  apiOptions: n = {},
844
- richText: c = {},
862
+ richText: l = {},
845
863
  bridgeUrl: a
846
864
  } = o;
847
865
  n.accessToken = n.accessToken || r;
848
- const l = { bridge: s, apiOptions: n };
866
+ const c = { bridge: s, apiOptions: n };
849
867
  let u = {};
850
- i.forEach((g) => {
851
- u = { ...u, ...g(l) };
852
- }), a && (w = a);
853
- const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
854
- return s !== !1 && p && C(w), R = new b(c.schema), c.resolver && j(R, c.resolver), u;
855
- }, j = (o, e) => {
856
- o.addNode("blok", (t) => {
868
+ i.forEach((d) => {
869
+ u = { ...u, ...d(c) };
870
+ }), a && (R = a);
871
+ const p = !(typeof window > "u") && ((e = (t = window.location) == null ? void 0 : t.search) == null ? void 0 : e.includes("_storyblok_tk"));
872
+ return s !== !1 && p && O(R), $ = new k(l.schema), l.resolver && E($, l.resolver), u;
873
+ }, E = (o, t) => {
874
+ o.addNode("blok", (e) => {
857
875
  let s = "";
858
- return t.attrs.body.forEach((r) => {
859
- s += e(r.component, r);
876
+ return e.attrs.body.forEach((r) => {
877
+ s += t(r.component, r);
860
878
  }), {
861
879
  html: s
862
880
  };
863
881
  });
864
- }, ue = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), fe = (o, e, t) => {
865
- let s = t || R;
882
+ }, ut = (o) => !o || !(o != null && o.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), mt = (o, t, e) => {
883
+ let s = e || $;
866
884
  if (!s) {
867
885
  console.error(
868
886
  "Please initialize the Storyblok SDK before calling the renderRichText function"
869
887
  );
870
888
  return;
871
889
  }
872
- return ue(o) ? "" : (e && (s = new b(e.schema), e.resolver && j(s, e.resolver)), s.render(o));
873
- }, ye = () => C(w);
890
+ return ut(o) ? "" : (t && (s = new k(t.schema), t.resolver && E(s, t.resolver)), s.render(o));
891
+ }, yt = () => O(R);
874
892
  export {
875
- b as RichTextResolver,
876
- oe as RichTextSchema,
877
- pe as apiPlugin,
878
- ue as isRichTextEmpty,
879
- ye as loadStoryblokBridge,
880
- ge as registerStoryblokBridge,
881
- fe as renderRichText,
882
- de as storyblokEditable,
883
- me as storyblokInit,
884
- ge as useStoryblokBridge
893
+ k as RichTextResolver,
894
+ ot as RichTextSchema,
895
+ pt as apiPlugin,
896
+ ut as isRichTextEmpty,
897
+ yt as loadStoryblokBridge,
898
+ dt as registerStoryblokBridge,
899
+ mt as renderRichText,
900
+ gt as storyblokEditable,
901
+ ft as storyblokInit,
902
+ dt as useStoryblokBridge
885
903
  };