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