@storyblok/react 5.1.2 → 5.2.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 +47 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +37 -32
- package/dist/index2.mjs +2 -2
- package/dist/live-editing.js +1 -1
- package/dist/live-editing.mjs +19 -14
- package/dist/rsc/index.d.ts +1 -0
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/live-edit-update-action.d.ts.map +1 -1
- package/dist/rsc/live-editing.d.ts +1 -1
- package/dist/rsc/live-editing.d.ts.map +1 -1
- package/dist/rsc.js +1 -1
- package/dist/rsc.mjs +24 -22
- package/dist/storyblok-js.js +1 -1
- package/dist/storyblok-js.mjs +41 -41
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +25 -19
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -227,10 +227,26 @@ export async function fetchData() {
|
|
|
227
227
|
|
|
228
228
|
## Next.js using App Router
|
|
229
229
|
|
|
230
|
-
The components in the `app` directory are by default React Server Side Components, which limits the reactivity. You can enable Storyblok Visual Editor's live editing with React Server Components by
|
|
230
|
+
The components in the `app` directory are by default React Server Side Components, which limits the reactivity. You can enable Storyblok Visual Editor's live editing with React Server Components by using the `StoryblokLiveEditing` component, which automatically handles bridge loading and registration. The SDK allows you to take full advantage of the Live Editing while maintaining the performance benefits of Server Components.
|
|
231
231
|
|
|
232
232
|
> The SDK has a special module for RSC. Always import `@storyblok/react/rsc` while using Server Components.
|
|
233
233
|
|
|
234
|
+
### Live Editing Bridge Loading
|
|
235
|
+
|
|
236
|
+
**When do you need `StoryblokLiveEditing`?**
|
|
237
|
+
|
|
238
|
+
- ✅ **Pure Server-Side Rendering**: When using only `StoryblokServerComponent` (RSC-only apps)
|
|
239
|
+
- ❌ **Client-Side Components**: When using `StoryblokComponent` or other client components that already load the bridge
|
|
240
|
+
- ❌ **Hybrid Apps**: When you already have client components that load the bridge elsewhere
|
|
241
|
+
|
|
242
|
+
**Why is this needed for RSC-only apps?**
|
|
243
|
+
|
|
244
|
+
In React Server Components environments where components are purely server-rendered, the Storyblok bridge script isn't automatically loaded on the client. The `StoryblokLiveEditing` component detects when running in the Visual Editor and loads the bridge script for you.
|
|
245
|
+
|
|
246
|
+
**How to know if you need it?**
|
|
247
|
+
|
|
248
|
+
If live editing doesn't work in your RSC app, add `StoryblokLiveEditing`. If it's already working (because you have client components), you don't need it.
|
|
249
|
+
|
|
234
250
|
### 1. Initialize
|
|
235
251
|
|
|
236
252
|
Create a new file `lib/storyblok.js` and initialize the SDK. Make sure you export the `getStoryblokApi` function, which is an instance of [storyblok-js-client](https://github.com/storyblok/storyblok-js-client) that is shared by client and server components.
|
|
@@ -291,7 +307,7 @@ The `getStoryblokApi` function can now be used inside your Story components to f
|
|
|
291
307
|
|
|
292
308
|
```js
|
|
293
309
|
import { StoryblokClient, ISbStoriesParams } from '@storyblok/react';
|
|
294
|
-
import {
|
|
310
|
+
import { StoryblokServerComponent, StoryblokLiveEditing } from '@storyblok/react/rsc';
|
|
295
311
|
import { getStoryblokApi } from '@/lib/storyblok'; // Remember to import from the local file
|
|
296
312
|
|
|
297
313
|
export default async function Home() {
|
|
@@ -299,7 +315,8 @@ export default async function Home() {
|
|
|
299
315
|
|
|
300
316
|
return (
|
|
301
317
|
<div>
|
|
302
|
-
<
|
|
318
|
+
<StoryblokServerComponent blok={data.story.content} />
|
|
319
|
+
<StoryblokLiveEditing story={data.story} />
|
|
303
320
|
</div>
|
|
304
321
|
);
|
|
305
322
|
}
|
|
@@ -312,11 +329,37 @@ export async function fetchData() {
|
|
|
312
329
|
}
|
|
313
330
|
```
|
|
314
331
|
|
|
315
|
-
|
|
332
|
+
**Live Editing in RSC Environments:**
|
|
333
|
+
|
|
334
|
+
For **pure React Server Components** apps (no client-side components), you need two separate components:
|
|
335
|
+
|
|
336
|
+
- `StoryblokServerComponent`: Renders the Storyblok content components on the server
|
|
337
|
+
- `StoryblokLiveEditing`: Loads the bridge script and handles live editing (only needed for RSC-only apps)
|
|
316
338
|
|
|
317
339
|
```jsx
|
|
318
340
|
const bridgeOptions = { resolveRelations: ['article.author'] }
|
|
319
341
|
|
|
342
|
+
<StoryblokLiveEditing story={data.story} bridgeOptions={bridgeOptions} />
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**If you have client-side components in your app**, the bridge is likely already loaded, so you can skip `StoryblokLiveEditing`:
|
|
346
|
+
|
|
347
|
+
```jsx
|
|
348
|
+
// RSC-only app (bridge needed)
|
|
349
|
+
<StoryblokServerComponent blok={data.story.content} />
|
|
350
|
+
<StoryblokLiveEditing story={data.story} />
|
|
351
|
+
|
|
352
|
+
// Hybrid app with client components (bridge already loaded)
|
|
353
|
+
<StoryblokServerComponent blok={data.story.content} />
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Alternative: Using StoryblokStory (All-in-One)**
|
|
357
|
+
|
|
358
|
+
If you prefer a single component that handles both rendering and live editing:
|
|
359
|
+
|
|
360
|
+
```jsx
|
|
361
|
+
import { StoryblokStory } from '@storyblok/react/rsc';
|
|
362
|
+
|
|
320
363
|
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />
|
|
321
364
|
```
|
|
322
365
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./richtext.js"),d=require("./client.js"),g=require("./storyblok-rich-text.js"),t=require("./utils.js"),T=require("./storyblok-component.js"),p=(n,s={},r={})=>{const[k,y]=u.useState({}),b=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u",i=o.useStoryblokApi();return u.useEffect(()=>{if(!i){console.error("You can't use useStoryblok if you're not loading apiPlugin.");return}async function a(){const{data:l}=await i.get(`cdn/stories/${n}`,s);y(l.story),b&&l.story.id&&e.registerStoryblokBridge(l.story.id,S=>y(S),r)}a()},[n,JSON.stringify(s),i]),i?(r.resolveRelations=r.resolveRelations??s.resolve_relations,r.resolveLinks=r.resolveLinks??s.resolve_links,k):null},m=c.useStoryblokRichText;exports.BlockTypes=e.BlockTypes;exports.MarkTypes=e.MarkTypes;exports.TextTypes=e.TextTypes;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.richTextResolver=e.richTextResolver;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;exports.getComponent=o.getComponent;exports.getCustomFallbackComponent=o.getCustomFallbackComponent;exports.getEnableFallbackComponent=o.getEnableFallbackComponent;exports.getStoryblokApi=o.useStoryblokApi;exports.setComponents=o.setComponents;exports.storyblokInit=o.storyblokInit;exports.useStoryblokApi=o.useStoryblokApi;exports.useStoryblokRichText=c.useStoryblokRichText;exports.useStoryblokState=d.useStoryblokState;exports.StoryblokRichText=g;exports.convertAttributesInElement=t.convertAttributesInElement;exports.isBridgeLoaded=t.isBridgeLoaded;exports.isBrowser=t.isBrowser;exports.isIframe=t.isIframe;exports.isServer=t.isServer;exports.isVisualEditor=t.isVisualEditor;exports.StoryblokComponent=T;exports.useStoryblok=p;exports.useStoryblokRichTextResolver=m;
|
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,64 @@
|
|
|
1
|
-
import { useState as f, useEffect as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
import { BlockTypes as T, MarkTypes as B, TextTypes as
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
import { registerStoryblokBridge as k } from "./storyblok-js.mjs";
|
|
3
|
+
import { BlockTypes as T, MarkTypes as B, TextTypes as E, apiPlugin as w, loadStoryblokBridge as C, renderRichText as h, richTextResolver as A, storyblokEditable as I } from "./storyblok-js.mjs";
|
|
4
4
|
import { useStoryblokApi as c } from "./index2.mjs";
|
|
5
|
-
import { getComponent as
|
|
5
|
+
import { getComponent as F, getCustomFallbackComponent as P, getEnableFallbackComponent as _, setComponents as $, storyblokInit as J } from "./index2.mjs";
|
|
6
6
|
import { useStoryblokRichText as m } from "./richtext.mjs";
|
|
7
|
-
import { useStoryblokState as
|
|
8
|
-
import { default as
|
|
9
|
-
import { convertAttributesInElement as z } from "./utils.mjs";
|
|
10
|
-
import { default as
|
|
11
|
-
const
|
|
12
|
-
const [
|
|
13
|
-
return
|
|
7
|
+
import { useStoryblokState as N } from "./client.mjs";
|
|
8
|
+
import { default as Y } from "./storyblok-rich-text.mjs";
|
|
9
|
+
import { convertAttributesInElement as q, isBridgeLoaded as z, isBrowser as D, isIframe as G, isServer as H, isVisualEditor as K } from "./utils.mjs";
|
|
10
|
+
import { default as U } from "./storyblok-component.mjs";
|
|
11
|
+
const g = (s, e = {}, o = {}) => {
|
|
12
|
+
const [n, l] = f({}), i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u", t = c();
|
|
13
|
+
return u(() => {
|
|
14
14
|
if (!t) {
|
|
15
15
|
console.error(
|
|
16
16
|
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
17
17
|
);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
async function
|
|
20
|
+
async function a() {
|
|
21
21
|
const { data: r } = await t.get(
|
|
22
22
|
`cdn/stories/${s}`,
|
|
23
23
|
e
|
|
24
24
|
);
|
|
25
|
-
|
|
25
|
+
l(r.story), i && r.story.id && k(
|
|
26
26
|
r.story.id,
|
|
27
|
-
(
|
|
27
|
+
(y) => l(y),
|
|
28
28
|
o
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
}, [s, JSON.stringify(e), t]), t ? (o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links,
|
|
33
|
-
},
|
|
31
|
+
a();
|
|
32
|
+
}, [s, JSON.stringify(e), t]), t ? (o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links, n) : null;
|
|
33
|
+
}, x = m;
|
|
34
34
|
export {
|
|
35
35
|
T as BlockTypes,
|
|
36
36
|
B as MarkTypes,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
U as StoryblokComponent,
|
|
38
|
+
Y as StoryblokRichText,
|
|
39
|
+
E as TextTypes,
|
|
40
|
+
w as apiPlugin,
|
|
41
|
+
q as convertAttributesInElement,
|
|
42
|
+
F as getComponent,
|
|
43
43
|
P as getCustomFallbackComponent,
|
|
44
44
|
_ as getEnableFallbackComponent,
|
|
45
45
|
c as getStoryblokApi,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
z as isBridgeLoaded,
|
|
47
|
+
D as isBrowser,
|
|
48
|
+
G as isIframe,
|
|
49
|
+
H as isServer,
|
|
50
|
+
K as isVisualEditor,
|
|
51
|
+
C as loadStoryblokBridge,
|
|
52
|
+
k as registerStoryblokBridge,
|
|
53
|
+
h as renderRichText,
|
|
49
54
|
A as richTextResolver,
|
|
50
|
-
|
|
55
|
+
$ as setComponents,
|
|
51
56
|
I as storyblokEditable,
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
J as storyblokInit,
|
|
58
|
+
g as useStoryblok,
|
|
54
59
|
c as useStoryblokApi,
|
|
55
|
-
|
|
60
|
+
k as useStoryblokBridge,
|
|
56
61
|
m as useStoryblokRichText,
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
x as useStoryblokRichTextResolver,
|
|
63
|
+
N as useStoryblokState
|
|
59
64
|
};
|
package/dist/index2.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { storyblokInit as s } from "./storyblok-js.mjs";
|
|
2
2
|
import { BlockTypes as g, MarkTypes as C, TextTypes as d, apiPlugin as f, loadStoryblokBridge as S, registerStoryblokBridge as x, renderRichText as F, richTextResolver as T, storyblokEditable as A, registerStoryblokBridge as B } from "./storyblok-js.mjs";
|
|
3
|
-
import { default as
|
|
3
|
+
import { default as R } from "./storyblok-component.mjs";
|
|
4
4
|
let t = null, e = {}, r = !1, l = null;
|
|
5
5
|
const b = () => (t || console.error(
|
|
6
6
|
"You can't use getStoryblokApi if you're not loading apiPlugin."
|
|
@@ -11,7 +11,7 @@ const b = () => (t || console.error(
|
|
|
11
11
|
export {
|
|
12
12
|
g as BlockTypes,
|
|
13
13
|
C as MarkTypes,
|
|
14
|
-
|
|
14
|
+
R as StoryblokComponent,
|
|
15
15
|
d as TextTypes,
|
|
16
16
|
f as apiPlugin,
|
|
17
17
|
k as getComponent,
|
package/dist/live-editing.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";const
|
|
2
|
+
"use strict";const r=require("./storyblok-js.js"),o=require("react"),l=require("./live-edit-update-action.js"),s=require("./utils.js"),d=({story:t=null,bridgeOptions:e={}})=>{if(!s.isVisualEditor())return null;const n=(t==null?void 0:t.id)??0;return o.useEffect(()=>{(async()=>{s.isBridgeLoaded()||await r.loadStoryblokBridge();const a=i=>{i&&o.startTransition(()=>{l.liveEditUpdateAction({story:i,pathToRevalidate:window.location.pathname})})};r.registerStoryblokBridge(n,i=>a(i),e)})()},[n,JSON.stringify(e)]),null};module.exports=d;
|
package/dist/live-editing.mjs
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
import { useEffect as
|
|
4
|
-
import { liveEditUpdateAction as
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { loadStoryblokBridge as n, registerStoryblokBridge as e } from "./storyblok-js.mjs";
|
|
3
|
+
import { useEffect as l, startTransition as d } from "react";
|
|
4
|
+
import { liveEditUpdateAction as s } from "./live-edit-update-action.mjs";
|
|
5
|
+
import { isVisualEditor as u, isBridgeLoaded as f } from "./utils.mjs";
|
|
6
|
+
const S = ({ story: t = null, bridgeOptions: o = {} }) => {
|
|
7
|
+
if (!u())
|
|
7
8
|
return null;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const r = (t == null ? void 0 : t.id) ?? 0;
|
|
10
|
+
return l(() => {
|
|
11
|
+
(async () => {
|
|
12
|
+
f() || await n();
|
|
13
|
+
const a = (i) => {
|
|
14
|
+
i && d(() => {
|
|
15
|
+
s({ story: i, pathToRevalidate: window.location.pathname });
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
e(r, (i) => a(i), o);
|
|
19
|
+
})();
|
|
20
|
+
}, [r, JSON.stringify(o)]), null;
|
|
16
21
|
};
|
|
17
22
|
export {
|
|
18
|
-
|
|
23
|
+
S as default
|
|
19
24
|
};
|
package/dist/rsc/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './common';
|
|
2
|
+
export { default as StoryblokLiveEditing } from './live-editing';
|
|
2
3
|
export { useStoryblokServerRichText } from './richtext';
|
|
3
4
|
export { default as StoryblokServerRichText } from './server-storyblok-richtext-component';
|
|
4
5
|
export { default as StoryblokStory } from './story';
|
package/dist/rsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EACL,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,KAAK,yCAAyC,EAC9C,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,SAAS,GACV,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EACL,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,KAAK,yCAAyC,EAC9C,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,SAAS,GACV,MAAM,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-edit-update-action.d.ts","sourceRoot":"","sources":["../../src/rsc/live-edit-update-action.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"live-edit-update-action.d.ts","sourceRoot":"","sources":["../../src/rsc/live-edit-update-action.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,wBAAsB,oBAAoB,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,iBAiBxH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISbStoryData, StoryblokBridgeConfigV2 } from '@storyblok/js';
|
|
2
2
|
declare const StoryblokLiveEditing: ({ story, bridgeOptions }: {
|
|
3
3
|
story: ISbStoryData;
|
|
4
|
-
bridgeOptions
|
|
4
|
+
bridgeOptions?: StoryblokBridgeConfigV2;
|
|
5
5
|
}) => any;
|
|
6
6
|
export default StoryblokLiveEditing;
|
|
7
7
|
//# sourceMappingURL=live-editing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-editing.d.ts","sourceRoot":"","sources":["../../src/rsc/live-editing.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"live-editing.d.ts","sourceRoot":"","sources":["../../src/rsc/live-editing.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAgD,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAK9H,QAAA,MAAM,oBAAoB,GAAI,0BAAsC;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,aAAa,CAAC,EAAE,uBAAuB,CAAA;CAAE,QA+BnI,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
package/dist/rsc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./common.js"),t=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./common.js"),t=require("./live-editing.js"),r=require("./richtext2.js"),i=require("./server-storyblok-richtext-component.js"),l=require("./story.js"),e=require("./storyblok-js.js"),n=require("./server-component.js");exports.getComponent=o.getComponent;exports.getCustomFallbackComponent=o.getCustomFallbackComponent;exports.getEnableFallbackComponent=o.getEnableFallbackComponent;exports.getStoryblokApi=o.useStoryblokApi;exports.setComponents=o.setComponents;exports.storyblokInit=o.storyblokInit;exports.useStoryblokApi=o.useStoryblokApi;exports.StoryblokLiveEditing=t;exports.useStoryblokServerRichText=r.useStoryblokServerRichText;exports.StoryblokServerRichText=i;exports.StoryblokStory=l;exports.BlockTypes=e.BlockTypes;exports.MarkTypes=e.MarkTypes;exports.TextTypes=e.TextTypes;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.richTextResolver=e.richTextResolver;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;exports.StoryblokServerComponent=n;
|
package/dist/rsc.mjs
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { getComponent as r, getCustomFallbackComponent as t, getEnableFallbackComponent as l, useStoryblokApi as s, setComponents as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { default as m } from "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { getComponent as r, getCustomFallbackComponent as t, getEnableFallbackComponent as l, useStoryblokApi as s, setComponents as i, storyblokInit as a, useStoryblokApi as p } from "./common.mjs";
|
|
2
|
+
import { default as k } from "./live-editing.mjs";
|
|
3
|
+
import { useStoryblokServerRichText as S } from "./richtext2.mjs";
|
|
4
|
+
import { default as m } from "./server-storyblok-richtext-component.mjs";
|
|
5
|
+
import { default as g } from "./story.mjs";
|
|
6
|
+
import { BlockTypes as f, MarkTypes as u, TextTypes as T, apiPlugin as c, loadStoryblokBridge as C, registerStoryblokBridge as v, renderRichText as B, richTextResolver as h, storyblokEditable as R, registerStoryblokBridge as A } from "./storyblok-js.mjs";
|
|
7
|
+
import { default as F } from "./server-component.mjs";
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
m as
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
f as BlockTypes,
|
|
10
|
+
u as MarkTypes,
|
|
11
|
+
k as StoryblokLiveEditing,
|
|
12
|
+
F as StoryblokServerComponent,
|
|
13
|
+
m as StoryblokServerRichText,
|
|
14
|
+
g as StoryblokStory,
|
|
15
|
+
T as TextTypes,
|
|
16
|
+
c as apiPlugin,
|
|
15
17
|
r as getComponent,
|
|
16
18
|
t as getCustomFallbackComponent,
|
|
17
19
|
l as getEnableFallbackComponent,
|
|
18
20
|
s as getStoryblokApi,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
C as loadStoryblokBridge,
|
|
22
|
+
v as registerStoryblokBridge,
|
|
23
|
+
B as renderRichText,
|
|
24
|
+
h as richTextResolver,
|
|
25
|
+
i as setComponents,
|
|
26
|
+
R as storyblokEditable,
|
|
25
27
|
a as storyblokInit,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
p as useStoryblokApi,
|
|
29
|
+
A as useStoryblokBridge,
|
|
30
|
+
S as useStoryblokServerRichText
|
|
29
31
|
};
|
package/dist/storyblok-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function oe(n,e){if(!e)return{src:n,attrs:{}};let t=0,r=0;const s={},o=[];function c(i,h,f,y,$){typeof i!="number"||i<=h||i>=f?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`):$.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(s.height=e.height,r=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:i}=e||{},{blur:h,brightness:f,fill:y,format:$,grayscale:T,quality:A,rotate:I}=i||{};h&&c(h,0,100,"blur",o),A&&c(A,0,100,"quality",o),f&&c(f,0,100,"brightness",o),y&&o.push(`fill(${y})`),T&&o.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${I})`),$&&["webp","png","jpeg"].includes($)&&o.push(`format(${$})`)}e.srcset&&(s.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${n}/m/${i}x0/${o.length>0?`filters:${o.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[h,f]=i;return`${n}/m/${h}x${f}/${o.length>0?`filters:${o.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let l=`${n}/m/`;return t>0&&r>0&&(l=`${l}${t}x${r}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:s}}var b=(n=>(n.DOCUMENT="doc",n.HEADING="heading",n.PARAGRAPH="paragraph",n.QUOTE="blockquote",n.OL_LIST="ordered_list",n.UL_LIST="bullet_list",n.LIST_ITEM="list_item",n.CODE_BLOCK="code_block",n.HR="horizontal_rule",n.BR="hard_break",n.IMAGE="image",n.EMOJI="emoji",n.COMPONENT="blok",n.TABLE="table",n.TABLE_ROW="tableRow",n.TABLE_CELL="tableCell",n.TABLE_HEADER="tableHeader",n))(b||{}),_=(n=>(n.BOLD="bold",n.STRONG="strong",n.STRIKE="strike",n.UNDERLINE="underline",n.ITALIC="italic",n.CODE="code",n.LINK="link",n.ANCHOR="anchor",n.STYLED="styled",n.SUPERSCRIPT="superscript",n.SUBSCRIPT="subscript",n.TEXT_STYLE="textStyle",n.HIGHLIGHT="highlight",n))(_||{}),N=(n=>(n.TEXT="text",n))(N||{}),S=(n=>(n.URL="url",n.STORY="story",n.ASSET="asset",n.EMAIL="email",n))(S||{});const ie=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ae=(n={})=>Object.keys(n).map(e=>`${e}="${n[e]}"`).join(" "),le=(n={})=>Object.keys(n).map(e=>`${e}: ${n[e]}`).join("; ");function ce(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=n=>Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0));function M(n,e={},t){const r=ae(e),s=r?`${n} ${r}`:n,o=Array.isArray(t)?t.join(""):t||"";if(n){if(ie.includes(n))return`<${s}>`}else return o;return`<${s}>${o}</${n}>`}function F(n={}){const e=new Map,{renderFn:t=M,textFn:r=ce,resolvers:s={},optimizeImages:o=!1,keyedResolvers:c=!1}=n,l=t!==M,i=a=>(u,d)=>{const p=u.attrs||{};return d.render(a,p,u.children||null)},h=(a,u)=>{const{src:d,alt:p,title:m,srcset:w,sizes:v}=a.attrs||{};let k=d,R={};if(o){const{src:re,attrs:ne}=oe(d,o);k=re,R=ne}const se={src:k,alt:p,title:m,srcset:w,sizes:v,...R};return u.render("img",O(se))},f=(a,u)=>{const{level:d,...p}=a.attrs||{};return u.render(`h${d}`,p,a.children)},y=(a,u)=>{var d,p,m,w;const v=u.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=a.attrs)==null?void 0:m.name,"data-emoji":(w=a.attrs)==null?void 0:w.emoji},v)},$=(a,u)=>u.render("pre",a.attrs||{},u.render("code",{},a.children||"")),T=(a,u=!1)=>({text:d,attrs:p},m)=>{const{class:w,id:v,...k}=p||{},R=u?{class:w,id:v,style:le(k)||void 0}:p||{};return m.render(a,O(R),d)},A=a=>C(a),I=a=>{const{marks:u,...d}=a;if("text"in a){if(u)return u.reduce((m,w)=>A({...w,text:m}),A({...d,children:d.children}));const p=a.attrs||{};if(c){const m=e.get("txt")||0;e.set("txt",m+1),p.key=`txt-${m}`}return r(d.text,p)}return""},U=(a,u)=>{const{linktype:d,href:p,anchor:m,...w}=a.attrs||{};let v="";switch(d){case S.ASSET:case S.URL:v=p;break;case S.EMAIL:v=`mailto:${p}`;break;case S.STORY:v=p,m&&(v=`${v}#${m}`);break;default:v=p;break}const k={...w};return v&&(k.href=v),u.render("a",k,a.text)},W=(a,u)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},X=(a,u)=>{const d={},p=u.render("tbody",{},a.children);return u.render("table",d,p)},Q=(a,u)=>{const d={};return u.render("tr",d,a.children)},Z=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("td",O(k),a.children)},ee=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("th",O(k),a.children)},B=new Map([[b.DOCUMENT,i("")],[b.HEADING,f],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,$],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,W],[N.TEXT,I],[_.LINK,U],[_.ANCHOR,U],[_.STYLED,T("span",!0)],[_.BOLD,T("strong")],[_.TEXT_STYLE,T("span",!0)],[_.ITALIC,T("em")],[_.UNDERLINE,T("u")],[_.STRIKE,T("s")],[_.CODE,T("code")],[_.SUPERSCRIPT,T("sup")],[_.SUBSCRIPT,T("sub")],[_.HIGHLIGHT,T("mark")],[b.TABLE,X],[b.TABLE_ROW,Q],[b.TABLE_CELL,Z],[b.TABLE_HEADER,ee]]),D=new Map([...B,...Object.entries(s).map(([a,u])=>[a,u])]),te=()=>({render:(a,u={},d)=>{if(c&&a){const p=e.get(a)||0;e.set(a,p+1),u.key=`${a}-${p}`}return t(a,u,d)},originalResolvers:B,mergedResolvers:D});function L(a){const u=D.get(a.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=te();if(a.type==="text")return u(a,d);const p=a.content?a.content.map(C):void 0;return u({...a,children:p},d)}function C(a){return a.type==="doc"?l?a.content.map(L):a.content.map(L).join(""):Array.isArray(a)?a.map(L):L(a)}return{render:C}}let z=!1;const G=[],Y=n=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():G.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>t(s),r.onload=s=>{G.forEach(o=>o()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)});var he=Object.defineProperty,ue=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e,t)=>ue(n,typeof e!="symbol"?e+"":e,t);class de extends Error{constructor(e){super(e),this.name="AbortError"}}function pe(n,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],o=0,c=!1;const l=async()=>{o++;const h=r.shift();if(h)try{const y=await n(...h.args);h.resolve(y)}catch(y){h.reject(y)}const f=setTimeout(()=>{o--,r.length>0&&l(),s=s.filter(y=>y!==f)},t);s.includes(f)||s.push(f)},i=(...h)=>c?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,y)=>{r.push({resolve:f,reject:y,args:h}),o<e&&l()});return i.abort=()=>{c=!0,s.forEach(clearTimeout),s=[],r.forEach(h=>h.reject(()=>new de("Throttle function aborted"))),r.length=0},i}const V=(n="")=>n.includes("/cdn/"),fe=(n,e=25,t=1)=>({...n,per_page:e,page:t}),ye=n=>new Promise(e=>setTimeout(e,n)),ge=(n=0,e)=>Array.from({length:n},e),me=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return ge(t,(s,o)=>o*r+n)},be=async(n,e)=>Promise.all(n.map(e)),ve=(n=[],e)=>n.map(e).reduce((t,r)=>[...t,...r],[]),H=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s];if(o==null)continue;const c=t?"":encodeURIComponent(s);let l;typeof o=="object"?l=H(o,e?e+encodeURIComponent(`[${c}]`):c,Array.isArray(o)):l=`${e?e+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(o)}`,r.push(l)}return r.join("&")},q=n=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[n]??e.eu};class ke{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${H(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:c}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const i=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:c,...this.fetchOptions});this.timeout&&clearTimeout(l);const h=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(i){return{message:i}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}}const J="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},we={PUBLISHED:"published"};let j={};const E={};class Te{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const c=e.https===!1?"http":"https";e.oauthToken?r=`${c}://${q(e.region)}/v1`:r=`${c}://${q(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([c,l])=>{s.set(c,l)}),s.has(J)||(s.set(J,P.defaultAgentName),s.set(P.defaultAgentVersion,P.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=pe(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return V(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const c=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,c,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;V(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,c=`/${e}`.replace(/\/$/,""),l=r??c.substring(c.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,h=await this.makeRequest(c,t,o,i,s),f=h.total?Math.ceil(h.total/o):1,y=await be(me(i,f),$=>this.makeRequest(c,t,o,$+1,s));return ve([h,...y],$=>Object.values($.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(c=>c.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,c="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,i)=>s(l,`${c}[${i}]`));else if(typeof o=="object")for(const l in o){const i=c?`${c}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],i)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.link_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.rel_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let c=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(c=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],c,r);e.story?this.iterateTree(e.story,c,r):e.stories.forEach(l=>{this.iterateTree(l,c,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=H({url:e,params:t}),c=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await c.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,i)=>{var h;try{const f=await this.throttle("get",e,t,s);if(f.status!==200)return i(f);let y={data:f.data,headers:f.headers};if((h=f.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:f.headers["per-page"]?Number.parseInt(f.headers["per-page"]):0,total:f.headers["per-page"]?Number.parseInt(f.headers.total):0})),y.data.story||y.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${T}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await c.set(o,y);const $=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&($&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(f){if(f.response&&f.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(i);i(f)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}}const Re=(n={})=>{const{apiOptions:e}=n;if(!e||!e.accessToken){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");return}return{storyblokApi:new Te(e)}},_e=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let x="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(n,e,t={})=>{var r;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((r=window.location)==null?void 0:r.href).searchParams.get("_storyblok"),c=o!==null&&+o===n;if(!(!s||!c)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{var i;l&&(l.action==="input"&&((i=l.story)==null?void 0:i.id)===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload())})})}},$e=(n={})=>{var e,t;const{bridge:r,accessToken:s,use:o=[],apiOptions:c={},bridgeUrl:l}=n;c.accessToken=c.accessToken||s;const i={bridge:r,apiOptions:c};let h={};o.forEach(y=>{h={...h,...y(i)}}),l&&(x=l);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return r!==!1&&f&&Y(x),h};function Ee(n,e){return F(e).render(n)}const Ae=()=>Y(x);exports.BlockTypes=b;exports.MarkTypes=_;exports.TextTypes=N;exports.apiPlugin=Re;exports.loadStoryblokBridge=Ae;exports.registerStoryblokBridge=K;exports.renderRichText=Ee;exports.richTextResolver=F;exports.storyblokEditable=_e;exports.storyblokInit=$e;exports.useStoryblokBridge=K;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function oe(n,e){if(!e)return{src:n,attrs:{}};let t=0,r=0;const s={},o=[];function c(i,h,f,y,R){typeof i!="number"||i<=h||i>=f?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`):R.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(s.height=e.height,r=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:i}=e||{},{blur:h,brightness:f,fill:y,format:R,grayscale:T,quality:A,rotate:I}=i||{};h&&c(h,0,100,"blur",o),A&&c(A,0,100,"quality",o),f&&c(f,0,100,"brightness",o),y&&o.push(`fill(${y})`),T&&o.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${I})`),R&&["webp","png","jpeg"].includes(R)&&o.push(`format(${R})`)}e.srcset&&(s.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${n}/m/${i}x0/${o.length>0?`filters:${o.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[h,f]=i;return`${n}/m/${h}x${f}/${o.length>0?`filters:${o.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let l=`${n}/m/`;return t>0&&r>0&&(l=`${l}${t}x${r}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:s}}var b=(n=>(n.DOCUMENT="doc",n.HEADING="heading",n.PARAGRAPH="paragraph",n.QUOTE="blockquote",n.OL_LIST="ordered_list",n.UL_LIST="bullet_list",n.LIST_ITEM="list_item",n.CODE_BLOCK="code_block",n.HR="horizontal_rule",n.BR="hard_break",n.IMAGE="image",n.EMOJI="emoji",n.COMPONENT="blok",n.TABLE="table",n.TABLE_ROW="tableRow",n.TABLE_CELL="tableCell",n.TABLE_HEADER="tableHeader",n))(b||{}),$=(n=>(n.BOLD="bold",n.STRONG="strong",n.STRIKE="strike",n.UNDERLINE="underline",n.ITALIC="italic",n.CODE="code",n.LINK="link",n.ANCHOR="anchor",n.STYLED="styled",n.SUPERSCRIPT="superscript",n.SUBSCRIPT="subscript",n.TEXT_STYLE="textStyle",n.HIGHLIGHT="highlight",n))($||{}),N=(n=>(n.TEXT="text",n))(N||{}),S=(n=>(n.URL="url",n.STORY="story",n.ASSET="asset",n.EMAIL="email",n))(S||{});const ie=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ae=(n={})=>Object.keys(n).map(e=>`${e}="${n[e]}"`).join(" "),le=(n={})=>Object.keys(n).map(e=>`${e}: ${n[e]}`).join("; ");function ce(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=n=>Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0));function M(n,e={},t){const r=ae(e),s=r?`${n} ${r}`:n,o=Array.isArray(t)?t.join(""):t||"";if(n){if(ie.includes(n))return`<${s}>`}else return o;return`<${s}>${o}</${n}>`}function F(n={}){const e=new Map,{renderFn:t=M,textFn:r=ce,resolvers:s={},optimizeImages:o=!1,keyedResolvers:c=!1}=n,l=t!==M,i=a=>(u,d)=>{const p=u.attrs||{};return d.render(a,p,u.children||null)},h=(a,u)=>{const{src:d,alt:p,title:m,srcset:w,sizes:v}=a.attrs||{};let k=d,_={};if(o){const{src:re,attrs:ne}=oe(d,o);k=re,_=ne}const se={src:k,alt:p,title:m,srcset:w,sizes:v,..._};return u.render("img",O(se))},f=(a,u)=>{const{level:d,...p}=a.attrs||{};return u.render(`h${d}`,p,a.children)},y=(a,u)=>{var d,p,m,w;const v=u.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=a.attrs)==null?void 0:m.name,"data-emoji":(w=a.attrs)==null?void 0:w.emoji},v)},R=(a,u)=>u.render("pre",a.attrs||{},u.render("code",{},a.children||"")),T=(a,u=!1)=>({text:d,attrs:p},m)=>{const{class:w,id:v,...k}=p||{},_=u?{class:w,id:v,style:le(k)||void 0}:p||{};return m.render(a,O(_),d)},A=a=>C(a),I=a=>{const{marks:u,...d}=a;if("text"in a){if(u)return u.reduce((m,w)=>A({...w,text:m}),A({...d,children:d.children}));const p=a.attrs||{};if(c){const m=e.get("txt")||0;e.set("txt",m+1),p.key=`txt-${m}`}return r(d.text,p)}return""},U=(a,u)=>{const{linktype:d,href:p,anchor:m,...w}=a.attrs||{};let v="";switch(d){case S.ASSET:case S.URL:v=p;break;case S.EMAIL:v=`mailto:${p}`;break;case S.STORY:v=p,m&&(v=`${v}#${m}`);break;default:v=p;break}const k={...w};return v&&(k.href=v),u.render("a",k,a.text)},W=(a,u)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},X=(a,u)=>{const d={},p=u.render("tbody",{},a.children);return u.render("table",d,p)},Q=(a,u)=>{const d={};return u.render("tr",d,a.children)},Z=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const _=[];return m&&_.push(`width: ${m}px;`),w&&_.push(`background-color: ${w};`),_.length>0&&(k.style=_.join(" ")),u.render("td",O(k),a.children)},ee=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const _=[];return m&&_.push(`width: ${m}px;`),w&&_.push(`background-color: ${w};`),_.length>0&&(k.style=_.join(" ")),u.render("th",O(k),a.children)},B=new Map([[b.DOCUMENT,i("")],[b.HEADING,f],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,R],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,W],[N.TEXT,I],[$.LINK,U],[$.ANCHOR,U],[$.STYLED,T("span",!0)],[$.BOLD,T("strong")],[$.TEXT_STYLE,T("span",!0)],[$.ITALIC,T("em")],[$.UNDERLINE,T("u")],[$.STRIKE,T("s")],[$.CODE,T("code")],[$.SUPERSCRIPT,T("sup")],[$.SUBSCRIPT,T("sub")],[$.HIGHLIGHT,T("mark")],[b.TABLE,X],[b.TABLE_ROW,Q],[b.TABLE_CELL,Z],[b.TABLE_HEADER,ee]]),D=new Map([...B,...Object.entries(s).map(([a,u])=>[a,u])]),te=()=>({render:(a,u={},d)=>{if(c&&a){const p=e.get(a)||0;e.set(a,p+1),u.key=`${a}-${p}`}return t(a,u,d)},originalResolvers:B,mergedResolvers:D});function L(a){const u=D.get(a.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=te();if(a.type==="text")return u(a,d);const p=a.content?a.content.map(C):void 0;return u({...a,children:p},d)}function C(a){return a.type==="doc"?l?a.content.map(L):a.content.map(L).join(""):Array.isArray(a)?a.map(L):L(a)}return{render:C}}let z=!1;const G=[],Y=n=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():G.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>t(s),r.onload=s=>{G.forEach(o=>o()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)});var he=Object.defineProperty,ue=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e,t)=>ue(n,typeof e!="symbol"?e+"":e,t);class de extends Error{constructor(e){super(e),this.name="AbortError"}}function pe(n,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],o=0,c=!1;const l=async()=>{o++;const h=r.shift();if(h)try{const y=await n(...h.args);h.resolve(y)}catch(y){h.reject(y)}const f=setTimeout(()=>{o--,r.length>0&&l(),s=s.filter(y=>y!==f)},t);s.includes(f)||s.push(f)},i=(...h)=>c?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,y)=>{r.push({resolve:f,reject:y,args:h}),o<e&&l()});return i.abort=()=>{c=!0,s.forEach(clearTimeout),s=[],r.forEach(h=>h.reject(()=>new de("Throttle function aborted"))),r.length=0},i}const V=(n="")=>n.includes("/cdn/"),fe=(n,e=25,t=1)=>({...n,per_page:e,page:t}),ye=n=>new Promise(e=>setTimeout(e,n)),ge=(n=0,e)=>Array.from({length:n},e),me=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return ge(t,(s,o)=>o*r+n)},be=async(n,e)=>Promise.all(n.map(e)),ve=(n=[],e)=>n.map(e).reduce((t,r)=>[...t,...r],[]),H=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s];if(o==null)continue;const c=t?"":encodeURIComponent(s);let l;typeof o=="object"?l=H(o,e?e+encodeURIComponent(`[${c}]`):c,Array.isArray(o)):l=`${e?e+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(o)}`,r.push(l)}return r.join("&")},q=n=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[n]??e.eu};class ke{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${H(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:c}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const i=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:c,...this.fetchOptions});this.timeout&&clearTimeout(l);const h=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(i){return{message:i}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}}const J="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},we={PUBLISHED:"published"};let j={};const E={};class Te{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const c=e.https===!1?"http":"https";e.oauthToken?r=`${c}://${q(e.region)}/v1`:r=`${c}://${q(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([c,l])=>{s.set(c,l)}),s.has(J)||(s.set(J,P.defaultAgentName),s.set(P.defaultAgentVersion,P.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=pe(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return V(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const c=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,c,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;V(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,c=`/${e}`.replace(/\/$/,""),l=r??c.substring(c.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,h=await this.makeRequest(c,t,o,i,s),f=h.total?Math.ceil(h.total/o):1,y=await be(me(i,f),R=>this.makeRequest(c,t,o,R+1,s));return ve([h,...y],R=>Object.values(R.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(c=>c.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,c="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,i)=>s(l,`${c}[${i}]`));else if(typeof o=="object")for(const l in o){const i=c?`${c}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],i)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.link_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.rel_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let c=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(c=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],c,r);e.story?this.iterateTree(e.story,c,r):e.stories.forEach(l=>{this.iterateTree(l,c,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=H({url:e,params:t}),c=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await c.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,i)=>{var h;try{const f=await this.throttle("get",e,t,s);if(f.status!==200)return i(f);let y={data:f.data,headers:f.headers};if((h=f.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:f.headers["per-page"]?Number.parseInt(f.headers["per-page"]):0,total:f.headers["per-page"]?Number.parseInt(f.headers.total):0})),y.data.story||y.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${T}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await c.set(o,y);const R=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(R&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(f){if(f.response&&f.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(i);i(f)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}}const _e=(n={})=>{const{apiOptions:e}=n;if(!e||!e.accessToken){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");return}return{storyblokApi:new Te(e)}},$e=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let x="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(n,e,t={})=>{var r;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((r=window.location)==null?void 0:r.href).searchParams.get("_storyblok"),c=o!==null&&+o===n;if(!(!s||!c)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{var i;l&&(l.action==="input"&&((i=l.story)==null?void 0:i.id)===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload())})})}},Re=(n={})=>{var e,t;const{bridge:r,accessToken:s,use:o=[],apiOptions:c={},bridgeUrl:l}=n;c.accessToken=c.accessToken||s;const i={bridge:r,apiOptions:c};let h={};o.forEach(y=>{h={...h,...y(i)}}),l&&(x=l);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return r!==!1&&f&&Y(x),h};function Ee(n,e){return F(e).render(n)}const Ae=()=>Y(x);exports.BlockTypes=b;exports.MarkTypes=$;exports.TextTypes=N;exports.apiPlugin=_e;exports.loadStoryblokBridge=Ae;exports.registerStoryblokBridge=K;exports.renderRichText=Ee;exports.richTextResolver=F;exports.storyblokEditable=$e;exports.storyblokInit=Re;exports.useStoryblokBridge=K;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -3,13 +3,13 @@ function re(n, e) {
|
|
|
3
3
|
return { src: n, attrs: {} };
|
|
4
4
|
let t = 0, r = 0;
|
|
5
5
|
const s = {}, o = [];
|
|
6
|
-
function c(i, h, f, y,
|
|
7
|
-
typeof i != "number" || i <= h || i >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`) :
|
|
6
|
+
function c(i, h, f, y, $) {
|
|
7
|
+
typeof i != "number" || i <= h || i >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`) : $.push(`${y}(${i})`);
|
|
8
8
|
}
|
|
9
9
|
if (typeof e == "object") {
|
|
10
10
|
if (typeof e.width == "number" && e.width > 0 ? (s.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (s.height = e.height, r = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
|
|
11
|
-
const { filters: i } = e || {}, { blur: h, brightness: f, fill: y, format:
|
|
12
|
-
h && c(h, 0, 100, "blur", o), A && c(A, 0, 100, "quality", o), f && c(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), T && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`),
|
|
11
|
+
const { filters: i } = e || {}, { blur: h, brightness: f, fill: y, format: $, grayscale: T, quality: A, rotate: S } = i || {};
|
|
12
|
+
h && c(h, 0, 100, "blur", o), A && c(A, 0, 100, "quality", o), f && c(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), T && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), $ && ["webp", "png", "jpeg"].includes($) && o.push(`format(${$})`);
|
|
13
13
|
}
|
|
14
14
|
e.srcset && (s.srcset = e.srcset.map((i) => {
|
|
15
15
|
if (typeof i == "number")
|
|
@@ -29,7 +29,7 @@ function re(n, e) {
|
|
|
29
29
|
attrs: s
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}),
|
|
32
|
+
var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), R = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))(R || {}), J = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(J || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
|
|
33
33
|
const ne = [
|
|
34
34
|
"area",
|
|
35
35
|
"base",
|
|
@@ -70,10 +70,10 @@ function le(n = {}) {
|
|
|
70
70
|
return d.render(a, p, u.children || null);
|
|
71
71
|
}, h = (a, u) => {
|
|
72
72
|
const { src: d, alt: p, title: m, srcset: w, sizes: b } = a.attrs || {};
|
|
73
|
-
let k = d,
|
|
73
|
+
let k = d, _ = {};
|
|
74
74
|
if (o) {
|
|
75
75
|
const { src: te, attrs: se } = re(d, o);
|
|
76
|
-
k = te,
|
|
76
|
+
k = te, _ = se;
|
|
77
77
|
}
|
|
78
78
|
const ee = {
|
|
79
79
|
src: k,
|
|
@@ -81,7 +81,7 @@ function le(n = {}) {
|
|
|
81
81
|
title: m,
|
|
82
82
|
srcset: w,
|
|
83
83
|
sizes: b,
|
|
84
|
-
...
|
|
84
|
+
..._
|
|
85
85
|
};
|
|
86
86
|
return u.render("img", O(ee));
|
|
87
87
|
}, f = (a, u) => {
|
|
@@ -101,17 +101,17 @@ function le(n = {}) {
|
|
|
101
101
|
"data-name": (m = a.attrs) == null ? void 0 : m.name,
|
|
102
102
|
"data-emoji": (w = a.attrs) == null ? void 0 : w.emoji
|
|
103
103
|
}, b);
|
|
104
|
-
},
|
|
104
|
+
}, $ = (a, u) => u.render(
|
|
105
105
|
"pre",
|
|
106
106
|
a.attrs || {},
|
|
107
107
|
u.render("code", {}, a.children || "")
|
|
108
108
|
), T = (a, u = !1) => ({ text: d, attrs: p }, m) => {
|
|
109
|
-
const { class: w, id: b, ...k } = p || {},
|
|
109
|
+
const { class: w, id: b, ...k } = p || {}, _ = u ? {
|
|
110
110
|
class: w,
|
|
111
111
|
id: b,
|
|
112
112
|
style: ie(k) || void 0
|
|
113
113
|
} : p || {};
|
|
114
|
-
return m.render(a, O(
|
|
114
|
+
return m.render(a, O(_), d);
|
|
115
115
|
}, A = (a) => C(a), S = (a) => {
|
|
116
116
|
const { marks: u, ...d } = a;
|
|
117
117
|
if ("text" in a) {
|
|
@@ -166,15 +166,15 @@ function le(n = {}) {
|
|
|
166
166
|
...b
|
|
167
167
|
};
|
|
168
168
|
d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
|
|
169
|
-
const
|
|
170
|
-
return m &&
|
|
169
|
+
const _ = [];
|
|
170
|
+
return m && _.push(`width: ${m}px;`), w && _.push(`background-color: ${w};`), _.length > 0 && (k.style = _.join(" ")), u.render("td", O(k), a.children);
|
|
171
171
|
}, Q = (a, u) => {
|
|
172
172
|
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = a.attrs || {}, k = {
|
|
173
173
|
...b
|
|
174
174
|
};
|
|
175
175
|
d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
|
|
176
|
-
const
|
|
177
|
-
return m &&
|
|
176
|
+
const _ = [];
|
|
177
|
+
return m && _.push(`width: ${m}px;`), w && _.push(`background-color: ${w};`), _.length > 0 && (k.style = _.join(" ")), u.render("th", O(k), a.children);
|
|
178
178
|
}, U = /* @__PURE__ */ new Map([
|
|
179
179
|
[v.DOCUMENT, i("")],
|
|
180
180
|
[v.HEADING, f],
|
|
@@ -184,24 +184,24 @@ function le(n = {}) {
|
|
|
184
184
|
[v.LIST_ITEM, i("li")],
|
|
185
185
|
[v.IMAGE, h],
|
|
186
186
|
[v.EMOJI, y],
|
|
187
|
-
[v.CODE_BLOCK,
|
|
187
|
+
[v.CODE_BLOCK, $],
|
|
188
188
|
[v.HR, i("hr")],
|
|
189
189
|
[v.BR, i("br")],
|
|
190
190
|
[v.QUOTE, i("blockquote")],
|
|
191
191
|
[v.COMPONENT, Y],
|
|
192
192
|
[J.TEXT, S],
|
|
193
|
-
[
|
|
194
|
-
[
|
|
195
|
-
[
|
|
196
|
-
[
|
|
197
|
-
[
|
|
198
|
-
[
|
|
199
|
-
[
|
|
200
|
-
[
|
|
201
|
-
[
|
|
202
|
-
[
|
|
203
|
-
[
|
|
204
|
-
[
|
|
193
|
+
[R.LINK, H],
|
|
194
|
+
[R.ANCHOR, H],
|
|
195
|
+
[R.STYLED, T("span", !0)],
|
|
196
|
+
[R.BOLD, T("strong")],
|
|
197
|
+
[R.TEXT_STYLE, T("span", !0)],
|
|
198
|
+
[R.ITALIC, T("em")],
|
|
199
|
+
[R.UNDERLINE, T("u")],
|
|
200
|
+
[R.STRIKE, T("s")],
|
|
201
|
+
[R.CODE, T("code")],
|
|
202
|
+
[R.SUPERSCRIPT, T("sup")],
|
|
203
|
+
[R.SUBSCRIPT, T("sub")],
|
|
204
|
+
[R.HIGHLIGHT, T("mark")],
|
|
205
205
|
[v.TABLE, K],
|
|
206
206
|
[v.TABLE_ROW, W],
|
|
207
207
|
[v.TABLE_CELL, X],
|
|
@@ -247,7 +247,7 @@ const z = [], F = (n) => new Promise((e, t) => {
|
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
249
|
if (window.storyblokRegisterEvent = (s) => {
|
|
250
|
-
if (window.location
|
|
250
|
+
if (!window.location.search.includes("_storyblok")) {
|
|
251
251
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
@@ -515,9 +515,9 @@ class we {
|
|
|
515
515
|
s
|
|
516
516
|
), f = h.total ? Math.ceil(h.total / o) : 1, y = await me(
|
|
517
517
|
ge(i, f),
|
|
518
|
-
(
|
|
518
|
+
($) => this.makeRequest(c, t, o, $ + 1, s)
|
|
519
519
|
);
|
|
520
|
-
return be([h, ...y], (
|
|
520
|
+
return be([h, ...y], ($) => Object.values($.data[l]));
|
|
521
521
|
}
|
|
522
522
|
post(e, t = {}, r) {
|
|
523
523
|
const s = `/${e}`;
|
|
@@ -732,8 +732,8 @@ class we {
|
|
|
732
732
|
await this.resolveStories(y.data, t, `${T}`), y = await this.processInlineAssets(y);
|
|
733
733
|
}
|
|
734
734
|
t.version === "published" && e !== "/cdn/spaces/me" && await c.set(o, y);
|
|
735
|
-
const
|
|
736
|
-
return t.token && y.data.cv && (
|
|
735
|
+
const $ = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
736
|
+
return t.token && y.data.cv && ($ && E[t.token] && E[t.token] !== y.data.cv && await this.flushCache(), E[t.token] = y.data.cv), l(y);
|
|
737
737
|
} catch (f) {
|
|
738
738
|
if (f.response && f.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
739
739
|
return console.log(
|
|
@@ -828,7 +828,7 @@ const Te = (n = {}) => {
|
|
|
828
828
|
return;
|
|
829
829
|
}
|
|
830
830
|
return { storyblokApi: new we(e) };
|
|
831
|
-
},
|
|
831
|
+
}, _e = (n) => {
|
|
832
832
|
if (typeof n != "object" || typeof n._editable > "u")
|
|
833
833
|
return {};
|
|
834
834
|
try {
|
|
@@ -844,7 +844,7 @@ const Te = (n = {}) => {
|
|
|
844
844
|
}
|
|
845
845
|
};
|
|
846
846
|
let x = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
847
|
-
const
|
|
847
|
+
const $e = (n, e, t = {}) => {
|
|
848
848
|
var r;
|
|
849
849
|
const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((r = window.location) == null ? void 0 : r.href).searchParams.get(
|
|
850
850
|
"_storyblok"
|
|
@@ -861,7 +861,7 @@ const _e = (n, e, t = {}) => {
|
|
|
861
861
|
});
|
|
862
862
|
});
|
|
863
863
|
}
|
|
864
|
-
},
|
|
864
|
+
}, Re = (n = {}) => {
|
|
865
865
|
var e, t;
|
|
866
866
|
const {
|
|
867
867
|
bridge: r,
|
|
@@ -885,14 +885,14 @@ function Ee(n, e) {
|
|
|
885
885
|
const Ae = () => F(x);
|
|
886
886
|
export {
|
|
887
887
|
v as BlockTypes,
|
|
888
|
-
|
|
888
|
+
R as MarkTypes,
|
|
889
889
|
J as TextTypes,
|
|
890
890
|
Te as apiPlugin,
|
|
891
891
|
Ae as loadStoryblokBridge,
|
|
892
|
-
|
|
892
|
+
$e as registerStoryblokBridge,
|
|
893
893
|
Ee as renderRichText,
|
|
894
894
|
le as richTextResolver,
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
895
|
+
_e as storyblokEditable,
|
|
896
|
+
Re as storyblokInit,
|
|
897
|
+
$e as useStoryblokBridge
|
|
898
898
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,4 +6,14 @@ import { default as React } from 'react';
|
|
|
6
6
|
* @return {React.ReactElement} A new React element with converted attributes.
|
|
7
7
|
*/
|
|
8
8
|
export declare function convertAttributesInElement(element: React.ReactElement | React.ReactElement[]): React.ReactElement | React.ReactElement[];
|
|
9
|
+
export declare const isBrowser: () => boolean;
|
|
10
|
+
export declare const isServer: () => boolean;
|
|
11
|
+
export declare const isBridgeLoaded: () => boolean;
|
|
12
|
+
export declare const isIframe: () => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Detects if the current page is running inside Storyblok's Visual Editor.
|
|
15
|
+
* Requires the page to be in an iframe context with the _storyblok URL parameter.
|
|
16
|
+
* This is more reliable than just checking for the URL parameter alone.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isVisualEditor: () => boolean;
|
|
9
19
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,EAAE,CAsCxI"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,EAAE,CAsCxI;AAGD,eAAO,MAAM,SAAS,eAAsC,CAAC;AAC7D,eAAO,MAAM,QAAQ,eAAsC,CAAC;AAG5D,eAAO,MAAM,cAAc,eAA4E,CAAC;AACxG,eAAO,MAAM,QAAQ,eAAkD,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,cAAc,eAAmF,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function l(t){return t.replace(/-([a-z])/g,o=>o[1].toUpperCase())}function w(t){return t.split(";").reduce((o,i)=>{let[r,n]=i.split(":");return r=r==null?void 0:r.trim(),n=n==null?void 0:n.trim(),r&&n&&(o[l(r)]=n),o},{})}function d(t){if(Array.isArray(t))return t.map(e=>d(e));const o={class:"className",for:"htmlFor",targetAttr:"targetattr"},i=Object.keys(t.props).reduce((e,s)=>{let a=t.props[s];s==="style"&&typeof a=="string"&&(a=w(a));const f=o[s]||s;return e[f]=a,e},{});i.key=t.key;const r=u.Children.map(t.props.children,e=>typeof e=="string"?e:d(e));return u.createElement(t.type,i,r)}const c=()=>typeof window<"u",y=()=>typeof window>"u",g=()=>c()&&typeof window.storyblokRegisterEvent<"u",p=()=>c()&&window.self!==window.top,m=()=>c()&&p()&&window.location.search.includes("_storyblok");exports.convertAttributesInElement=d;exports.isBridgeLoaded=g;exports.isBrowser=c;exports.isIframe=p;exports.isServer=y;exports.isVisualEditor=m;
|
package/dist/utils.mjs
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
function f(
|
|
3
|
-
return
|
|
1
|
+
import a from "react";
|
|
2
|
+
function f(t) {
|
|
3
|
+
return t.replace(/-([a-z])/g, (o) => o[1].toUpperCase());
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return
|
|
7
|
-
let [
|
|
8
|
-
return
|
|
5
|
+
function w(t) {
|
|
6
|
+
return t.split(";").reduce((o, s) => {
|
|
7
|
+
let [r, n] = s.split(":");
|
|
8
|
+
return r = r == null ? void 0 : r.trim(), n = n == null ? void 0 : n.trim(), r && n && (o[f(r)] = n), o;
|
|
9
9
|
}, {});
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
if (Array.isArray(
|
|
13
|
-
return
|
|
11
|
+
function d(t) {
|
|
12
|
+
if (Array.isArray(t))
|
|
13
|
+
return t.map((e) => d(e));
|
|
14
14
|
const o = {
|
|
15
15
|
class: "className",
|
|
16
16
|
for: "htmlFor",
|
|
17
17
|
targetAttr: "targetattr"
|
|
18
18
|
// Add more attribute conversions here as needed
|
|
19
|
-
},
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
const u = o[
|
|
23
|
-
return e[u] =
|
|
19
|
+
}, s = Object.keys(t.props).reduce((e, i) => {
|
|
20
|
+
let p = t.props[i];
|
|
21
|
+
i === "style" && typeof p == "string" && (p = w(p));
|
|
22
|
+
const u = o[i] || i;
|
|
23
|
+
return e[u] = p, e;
|
|
24
24
|
}, {});
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
return
|
|
25
|
+
s.key = t.key;
|
|
26
|
+
const r = a.Children.map(t.props.children, (e) => typeof e == "string" ? e : d(e));
|
|
27
|
+
return a.createElement(t.type, s, r);
|
|
28
28
|
}
|
|
29
|
+
const c = () => typeof window < "u", m = () => typeof window > "u", g = () => c() && typeof window.storyblokRegisterEvent < "u", l = () => c() && window.self !== window.top, E = () => c() && l() && window.location.search.includes("_storyblok");
|
|
29
30
|
export {
|
|
30
|
-
|
|
31
|
+
d as convertAttributesInElement,
|
|
32
|
+
g as isBridgeLoaded,
|
|
33
|
+
c as isBrowser,
|
|
34
|
+
l as isIframe,
|
|
35
|
+
m as isServer,
|
|
36
|
+
E as isVisualEditor
|
|
31
37
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
7
7
|
"author": "Storyblok",
|
|
@@ -44,13 +44,15 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "4.1.
|
|
47
|
+
"@storyblok/js": "4.1.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/core": "^7.27.1",
|
|
51
51
|
"@babel/preset-env": "^7.27.2",
|
|
52
52
|
"@cypress/react": "^9.0.1",
|
|
53
53
|
"@cypress/vite-dev-server": "^6.0.3",
|
|
54
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
55
|
+
"@testing-library/react": "^16.3.0",
|
|
54
56
|
"@tsconfig/recommended": "^1.0.8",
|
|
55
57
|
"@types/node": "^22.15.18",
|
|
56
58
|
"@types/react": "19.1.4",
|
|
@@ -60,6 +62,7 @@
|
|
|
60
62
|
"eslint": "^9.26.0",
|
|
61
63
|
"eslint-plugin-cypress": "^4.3.0",
|
|
62
64
|
"eslint-plugin-jest": "^28.11.0",
|
|
65
|
+
"jsdom": "^26.1.0",
|
|
63
66
|
"react": "^19.1.0",
|
|
64
67
|
"react-dom": "^19.1.0",
|
|
65
68
|
"rollup-plugin-preserve-directives": "^0.4.0",
|