@storyblok/react 5.1.3 → 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 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 rendering them inside a wrapper (`StoryblokPovider`) on the client. The SDK allows you to take full advantage of the Live Editing, but the use of Server Side Components is partial, which will be still better than the older Next.js approach performance-wise. The next section explains about how to use complete server side approach.
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 { StoryblokStory } from '@storyblok/react/rsc';
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
- <StoryblokStory story={data.story} />
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
- `StoryblokStory` keeps the state for thet story behind the scenes and uses `StoryblokComponent` to render the route components dynamically, using the list of components loaded during the initialization inside the `storyblokInit` function. You can use the `StoryblokComponent` inside the components to render the nested components dynamically. You can also pass bridge options to `StoryblokStory` using the prop `bridgeOptions`.
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 y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./richtext.js"),S=require("./client.js"),d=require("./storyblok-rich-text.js"),g=require("./utils.js"),T=require("./storyblok-component.js"),p=(n,r={},t={})=>{const[u,i]=y.useState({}),k=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u",s=o.useStoryblokApi();return y.useEffect(()=>{if(!s){console.error("You can't use useStoryblok if you're not loading apiPlugin.");return}async function b(){const{data:l}=await s.get(`cdn/stories/${n}`,r);i(l.story),k&&l.story.id&&e.registerStoryblokBridge(l.story.id,a=>i(a),t)}b()},[n,JSON.stringify(r),s]),s?(t.resolveRelations=t.resolveRelations??r.resolve_relations,t.resolveLinks=t.resolveLinks??r.resolve_links,u):null},R=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=S.useStoryblokState;exports.StoryblokRichText=d;exports.convertAttributesInElement=g.convertAttributesInElement;exports.StoryblokComponent=T;exports.useStoryblok=p;exports.useStoryblokRichTextResolver=R;
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 k } from "react";
2
- import { registerStoryblokBridge as u } from "./storyblok-js.mjs";
3
- import { BlockTypes as T, MarkTypes as B, TextTypes as C, apiPlugin as E, loadStoryblokBridge as h, renderRichText as w, richTextResolver as A, storyblokEditable as I } from "./storyblok-js.mjs";
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 L, getCustomFallbackComponent as P, getEnableFallbackComponent as _, setComponents as $, storyblokInit as J } from "./index2.mjs";
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
7
  import { useStoryblokState as N } from "./client.mjs";
8
- import { default as j } from "./storyblok-rich-text.mjs";
9
- import { convertAttributesInElement as z } from "./utils.mjs";
10
- import { default as G } from "./storyblok-component.mjs";
11
- const x = (s, e = {}, o = {}) => {
12
- const [l, n] = f({}), i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u", t = c();
13
- return k(() => {
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 y() {
20
+ async function a() {
21
21
  const { data: r } = await t.get(
22
22
  `cdn/stories/${s}`,
23
23
  e
24
24
  );
25
- n(r.story), i && r.story.id && u(
25
+ l(r.story), i && r.story.id && k(
26
26
  r.story.id,
27
- (a) => n(a),
27
+ (y) => l(y),
28
28
  o
29
29
  );
30
30
  }
31
- y();
32
- }, [s, JSON.stringify(e), t]), t ? (o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links, l) : null;
33
- }, g = m;
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
- G as StoryblokComponent,
38
- j as StoryblokRichText,
39
- C as TextTypes,
40
- E as apiPlugin,
41
- z as convertAttributesInElement,
42
- L as getComponent,
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
- h as loadStoryblokBridge,
47
- u as registerStoryblokBridge,
48
- w as renderRichText,
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
57
  J as storyblokInit,
53
- x as useStoryblok,
58
+ g as useStoryblok,
54
59
  c as useStoryblokApi,
55
- u as useStoryblokBridge,
60
+ k as useStoryblokBridge,
56
61
  m as useStoryblokRichText,
57
- g as useStoryblokRichTextResolver,
62
+ x as useStoryblokRichTextResolver,
58
63
  N as useStoryblokState
59
64
  };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";const s=require("./storyblok-js.js"),i=require("react"),d=require("./live-edit-update-action.js"),l=()=>typeof window>"u"?!1:typeof window.storyblokRegisterEvent<"u"&&window.location.search.includes("_storyblok"),u=({story:e=null,bridgeOptions:n={}})=>{if(!l())return null;const o=t=>{t&&i.startTransition(()=>{d.liveEditUpdateAction({story:t,pathToRevalidate:window.location.pathname})})},r=(e==null?void 0:e.id)??0;return i.useEffect(()=>{s.registerStoryblokBridge(r,t=>o(t),n)},[]),null};module.exports=u;
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;
@@ -1,19 +1,24 @@
1
1
  "use client";
2
- import { registerStoryblokBridge as r } from "./storyblok-js.mjs";
3
- import { useEffect as d, startTransition as l } from "react";
4
- import { liveEditUpdateAction as a } from "./live-edit-update-action.mjs";
5
- const s = () => typeof window > "u" ? !1 : typeof window.storyblokRegisterEvent < "u" && window.location.search.includes("_storyblok"), p = ({ story: e = null, bridgeOptions: i = {} }) => {
6
- if (!s())
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 n = (t) => {
9
- t && l(() => {
10
- a({ story: t, pathToRevalidate: window.location.pathname });
11
- });
12
- }, o = (e == null ? void 0 : e.id) ?? 0;
13
- return d(() => {
14
- r(o, (t) => n(t), i);
15
- }, []), null;
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
- p as default
23
+ S as default
19
24
  };
@@ -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';
@@ -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":"AAEA,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
+ {"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: StoryblokBridgeConfigV2;
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,EAA2B,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAWzG,QAAA,MAAM,oBAAoB,GAAI,0BAAsC;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,aAAa,EAAE,uBAAuB,CAAA;CAAE,QAoBlI,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
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("./richtext2.js"),r=require("./server-storyblok-richtext-component.js"),l=require("./story.js"),e=require("./storyblok-js.js"),s=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.useStoryblokServerRichText=t.useStoryblokServerRichText;exports.StoryblokServerRichText=r;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=s;
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 p, storyblokInit as a, useStoryblokApi as b } from "./common.mjs";
2
- import { useStoryblokServerRichText as k } from "./richtext2.mjs";
3
- import { default as S } from "./server-storyblok-richtext-component.mjs";
4
- import { default as m } from "./story.mjs";
5
- import { BlockTypes as x, MarkTypes as d, TextTypes as f, apiPlugin as u, loadStoryblokBridge as T, registerStoryblokBridge as c, renderRichText as C, richTextResolver as B, storyblokEditable as h, registerStoryblokBridge as v } from "./storyblok-js.mjs";
6
- import { default as A } from "./server-component.mjs";
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
- x as BlockTypes,
9
- d as MarkTypes,
10
- A as StoryblokServerComponent,
11
- S as StoryblokServerRichText,
12
- m as StoryblokStory,
13
- f as TextTypes,
14
- u as apiPlugin,
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
- T as loadStoryblokBridge,
20
- c as registerStoryblokBridge,
21
- C as renderRichText,
22
- B as richTextResolver,
23
- p as setComponents,
24
- h as storyblokEditable,
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
- b as useStoryblokApi,
27
- v as useStoryblokBridge,
28
- k as useStoryblokServerRichText
28
+ p as useStoryblokApi,
29
+ A as useStoryblokBridge,
30
+ S as useStoryblokServerRichText
29
31
  };
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
@@ -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 p=require("react");function l(t){return t.replace(/-([a-z])/g,o=>o[1].toUpperCase())}function f(t){return t.split(";").reduce((o,s)=>{let[r,n]=s.split(":");return r=r==null?void 0:r.trim(),n=n==null?void 0:n.trim(),r&&n&&(o[l(r)]=n),o},{})}function c(t){if(Array.isArray(t))return t.map(e=>c(e));const o={class:"className",for:"htmlFor",targetAttr:"targetattr"},s=Object.keys(t.props).reduce((e,i)=>{let a=t.props[i];i==="style"&&typeof a=="string"&&(a=f(a));const u=o[i]||i;return e[u]=a,e},{});s.key=t.key;const r=p.Children.map(t.props.children,e=>typeof e=="string"?e:c(e));return p.createElement(t.type,s,r)}exports.convertAttributesInElement=c;
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 i from "react";
2
- function f(r) {
3
- return r.replace(/-([a-z])/g, (o) => o[1].toUpperCase());
1
+ import a from "react";
2
+ function f(t) {
3
+ return t.replace(/-([a-z])/g, (o) => o[1].toUpperCase());
4
4
  }
5
- function l(r) {
6
- return r.split(";").reduce((o, p) => {
7
- let [t, n] = p.split(":");
8
- return t = t == null ? void 0 : t.trim(), n = n == null ? void 0 : n.trim(), t && n && (o[f(t)] = n), o;
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 c(r) {
12
- if (Array.isArray(r))
13
- return r.map((e) => c(e));
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
- }, p = Object.keys(r.props).reduce((e, s) => {
20
- let a = r.props[s];
21
- s === "style" && typeof a == "string" && (a = l(a));
22
- const u = o[s] || s;
23
- return e[u] = a, e;
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
- p.key = r.key;
26
- const t = i.Children.map(r.props.children, (e) => typeof e == "string" ? e : c(e));
27
- return i.createElement(r.type, p, t);
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
- c as convertAttributesInElement
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.1.3",
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",
@@ -51,6 +51,8 @@
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",