@storyblok/js 2.3.0 → 3.0.1

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