@storyblok/react 3.0.15 → 4.0.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
@@ -222,7 +222,7 @@ export async function fetchData() {
222
222
  }
223
223
  ```
224
224
 
225
- ## Next.js using App Router - Live Editing support
225
+ ## Next.js using App Router
226
226
 
227
227
  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.
228
228
 
@@ -230,16 +230,30 @@ The components in the `app` directory are by default React Server Side Component
230
230
 
231
231
  ### 1. Initialize
232
232
 
233
- In `app/layout.jsx`, call the `storyblokInit` function, but without loading the component list (we will do that on the client). Wrap your whole app using a `StoryblokProvider` component (this provider is created in the next step) :
233
+ 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.
234
234
 
235
235
  ```js
236
- import { apiPlugin, storyblokInit } from '@storyblok/react/rsc'
237
- import StoryblokProvider from '../components/StoryblokProvider'
236
+ // lib/storyblok.js
237
+ import Page from '@/components/Page';
238
+ import Teaser from '@/components/Teaser';
239
+ import { apiPlugin, storyblokInit } from '@storyblok/react/rsc';
238
240
 
239
- storyblokInit({
241
+ export const getStoryblokApi = storyblokInit({
240
242
  accessToken: 'YOUR_ACCESS_TOKEN',
241
243
  use: [apiPlugin],
242
- })
244
+ components: {
245
+ teaser: Teaser,
246
+ page: Page,
247
+ },
248
+ });
249
+ ```
250
+
251
+ In `app/layout.jsx`, wrap your whole app using a `StoryblokProvider` component (this provider is created in the next step) :
252
+
253
+ ```js
254
+ // app/layout.jsx
255
+ import { apiPlugin, storyblokInit } from '@storyblok/react/rsc'
256
+ import StoryblokProvider from '../components/StoryblokProvider'
243
257
 
244
258
  export default function RootLayout({ children }) {
245
259
  return (
@@ -254,55 +268,44 @@ export default function RootLayout({ children }) {
254
268
 
255
269
  ### 2. Create StoryblokProvider and Import your Storyblok Components
256
270
 
257
- Create the `components/StoryblokProvider.jsx` file. Re-initalize the connection with Storyblok (this time, on the client) using `storyblokInit`, and import your Storyblok components:
271
+ Create the `components/StoryblokProvider.jsx` file. Re-initalize the connection with Storyblok (this time, on the client) using the `getStoryblokApi` function imported from the `lib/storyblok` file. This will enable the client-side compoenents to interact with the Storyblok API, including the Visual Editor.
258
272
 
259
273
  ```js
260
- /** 1. Tag it as a client component */
261
- 'use client'
262
- import { apiPlugin, storyblokInit } from '@storyblok/react/rsc'
263
-
264
- /** 2. Import your components */
265
- import Page from '../components/Page'
266
- import Teaser from '../components/Teaser'
274
+ // components/StoryblokProvider.jsx
275
+ 'use client';
267
276
 
268
- /** 3. Initialize it as usual */
269
- storyblokInit({
270
- accessToken: 'YOUR_ACCESS_TOKEN',
271
- use: [apiPlugin],
272
- components: {
273
- teaser: Teaser,
274
- page: Page,
275
- },
276
- })
277
+ import { getStoryblokApi } from '@/lib/storyblok';
277
278
 
278
279
  export default function StoryblokProvider({ children }) {
279
- return children
280
+ getStoryblokApi();
281
+ return children;
280
282
  }
281
283
  ```
282
284
 
283
- > Note: it's necessary to re-initialize here as well, as to enable the live editing experience inside the Visual Editor you need to initialize the lib universally (client + server).
284
-
285
285
  ### 3. Fetch Content and Render Components
286
286
 
287
- The `getStoryblokApi` function, which is an instance of [storyblok-js-client](https://github.com/storyblok/storyblok-js-client) can be used to fetch the data from the Storyblok API. This should be imported from `@storyblok/react/rsc`.
288
- You can render the content of your route with the `StoryblokStory` component, which will automatically handle the Visual Editor live events when editing the story. In `app/page.jsx`, use them as follows:
287
+ The `getStoryblokApi` function can now be used inside your Story components to fetch the data from Storyblok. In `app/page.jsx`, use it as follows:
289
288
 
290
289
  ```js
291
- import { getStoryblokApi, StoryblokStory } from '@storyblok/react/rsc'
290
+ import { StoryblokClient, ISbStoriesParams } from '@storyblok/react';
291
+ import { StoryblokStory } from '@storyblok/react/rsc';
292
+ import { getStoryblokApi } from '@/lib/storyblok'; // Remember to import from the local file
292
293
 
293
294
  export default async function Home() {
294
- const { data } = await fetchData()
295
+ const { data } = await fetchData();
295
296
 
296
297
  return (
297
298
  <div>
298
299
  <StoryblokStory story={data.story} />
299
300
  </div>
300
- )
301
+ );
301
302
  }
302
303
 
303
304
  export async function fetchData() {
304
- const storyblokApi = getStoryblokApi()
305
- return storyblokApi.get(`cdn/stories/home`, { version: 'draft' })
305
+ let sbParams: ISbStoriesParams = { version: 'draft' };
306
+
307
+ const storyblokApi: StoryblokClient = getStoryblokApi();
308
+ return storyblokApi.get(`cdn/stories/home`, sbParams);
306
309
  }
307
310
  ```
308
311
 
@@ -318,81 +321,6 @@ const bridgeOptions = { resolveRelations: ['article.author'] }
318
321
 
319
322
  To try this setup, take a look at the [Next 13 Live Editing Playground](https://github.com/arorachakit/storyblok-react/tree/main/playground-next13-live-editing) in this repo.
320
323
 
321
- ## Next.js using App Router - Full React Server Components
322
-
323
- If you want to use the Next.js `app` directory approach, and React Server Components exclusively with everything on the server side, follow this approach.
324
-
325
- > The SDK has a special module for RSC. Always import `@storyblok/react/rsc` while using Server Components.
326
-
327
- **Limitation** - Real-time editing won't work if all the components are rendered on the server. Although, you can see the changes applied in the Visual Editor whenever you save or publish the changes applied to the story.
328
-
329
- ### 1. Initialize and Import your Storyblok Components
330
-
331
- The initialzation remains the same here as well. Please refer to the above section about "Initialization" for more information about `storyblokInit` function.
332
- In `app/layout.jsx`, call the `storyblokInit` function and use the new `StoryblokBridgeLoader` component to set up the Storyblok bridge. This Bridge Loader can be imported from `@storyblok/react/bridge-loader`:
333
-
334
- ```js
335
- import { storyblokInit, apiPlugin, StoryblokBridgeLoader } from "@storyblok/react/rsc";
336
-
337
- import Page from "../components/Page";
338
- import Teaser from "../components/Teaser";
339
-
340
- storyblokInit({
341
- accessToken: "YOUR_ACCESS_TOKEN",
342
- use: [apiPlugin],
343
- components: {
344
- teaser: Teaser,
345
- page: Page,
346
- },
347
- });
348
-
349
- export default RootLayout(({ children }) => {
350
- const bridgeOptions = { resolveRelations: ["article.author"] };
351
-
352
- return (
353
- <html lang="en">
354
- <body>{children}</body>
355
- <StoryblokBridgeLoader options={bridgeOptions} />
356
- </html>
357
- );
358
- }
359
- ```
360
-
361
- As the name says, `StoryblokBridgeLoader` loads the bridge on the client. It helps you see the dotted lines and allows you to still click on the components inside the Visual Editor to open their schema. You can pass the bridge options using the `options` prop.
362
-
363
- ### 2. Fetch Content and Render Components
364
-
365
- The `getStoryblokApi` function, is an instance of [storyblok-js-client](https://github.com/storyblok/storyblok-js-client) can be used to fetch the data from the Storyblok API. This is imported from `@storyblok/react/rsc`.
366
- Go to the route you want to fetch data from and use it as follows:
367
-
368
- ```js
369
- import { getStoryblokApi, StoryblokComponent } from '@storyblok/react/rsc'
370
-
371
- export default async function Home() {
372
- const { data } = await fetchData()
373
-
374
- return (
375
- <div>
376
- <h1>
377
- Story:
378
- {data.story.id}
379
- </h1>
380
- <StoryblokComponent blok={data.story.content} />
381
- </div>
382
- )
383
- }
384
-
385
- export async function fetchData() {
386
- const storyblokApi = getStoryblokApi()
387
- return storyblokApi.get(`cdn/stories/home`, { version: 'draft' })
388
- }
389
- ```
390
-
391
- > Note: To use this approach (with `getStoryblokApi`), you need to include the `apiPlugin` module when calling `storyblokInit` function. If you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
392
-
393
- `StoryblokComponent` renders the route components dynamically, using the list of components loaded during the initialization inside the `storyblokInit` function.
394
- To try it, take a look at the [Next 13 RSC Playground](https://github.com/arorachakit/storyblok-react/tree/main/playground-next13-rsc) in this repo.
395
-
396
324
  ## Next.js using Pages Router
397
325
 
398
326
  In this section, we'll see how to use the React SDK with the `pages` directory approach.
@@ -708,3 +636,7 @@ By using these techniques, you can ensure that only the necessary components and
708
636
 
709
637
  Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and our [code of conduct](https://www.storyblok.com/trust-center#code-of-conduct?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react).
710
638
  This project use [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check [this question](https://semantic-release.gitbook.io/semantic-release/support/faq#how-can-i-change-the-type-of-commits-that-trigger-a-release) about it in semantic-release FAQ.
639
+
640
+ ## License
641
+
642
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/dist/client.js CHANGED
@@ -1 +1,2 @@
1
+ "use client";
1
2
  "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),b=require("./storyblok-js.js"),f=(e=null,o={})=>{const[u,s]=d.useState(e),r=(e==null?void 0:e.internalId)??(e==null?void 0:e.id)??0,t=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return d.useEffect(()=>{s(e),!(!t||!e)&&b.registerStoryblokBridge(r,c=>s(c),o)},[e]),u};exports.useStoryblokState=f;
package/dist/client.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useState as c, useEffect as p } from "react";
2
3
  import { registerStoryblokBridge as b } from "./storyblok-js.mjs";
3
4
  const n = (e = null, d = {}) => {
package/dist/common.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./storyblok-js.js"),b=require("./server-component.js");let t=null;const n=new Map;let l=!1,s=null;globalThis.storyCache=new Map;const a=()=>(t||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),t),c=e=>(Object.entries(e).forEach(([r,i])=>{n.set(r,i)}),n),k=e=>n.has(e)?n.get(e):(console.error(`Component ${e} doesn't exist.`),!1),m=()=>l,u=()=>s,g=(e={})=>{if(t)return()=>t;const{storyblokApi:r}=o.storyblokInit(e);return t=r,e.components&&c(e.components),l=e.enableFallbackComponent,s=e.customFallbackComponent,()=>r};exports.RichTextResolver=o.RichTextResolver;exports.RichTextSchema=o.RichTextSchema;exports.apiPlugin=o.apiPlugin;exports.loadStoryblokBridge=o.loadStoryblokBridge;exports.registerStoryblokBridge=o.registerStoryblokBridge;exports.renderRichText=o.renderRichText;exports.storyblokEditable=o.storyblokEditable;exports.useStoryblokBridge=o.registerStoryblokBridge;exports.StoryblokServerComponent=b;exports.getComponent=k;exports.getCustomFallbackComponent=u;exports.getEnableFallbackComponent=m;exports.getStoryblokApi=a;exports.setComponents=c;exports.storyblokInit=g;exports.useStoryblokApi=a;
@@ -0,0 +1,35 @@
1
+ import { storyblokInit as a } from "./storyblok-js.mjs";
2
+ import { RichTextResolver as g, RichTextSchema as C, apiPlugin as d, loadStoryblokBridge as S, registerStoryblokBridge as h, renderRichText as x, storyblokEditable as F, registerStoryblokBridge as A } from "./storyblok-js.mjs";
3
+ import { default as M } from "./server-component.mjs";
4
+ let e = null;
5
+ const r = /* @__PURE__ */ new Map();
6
+ let n = !1, l = null;
7
+ globalThis.storyCache = /* @__PURE__ */ new Map();
8
+ const i = () => (e || console.error(
9
+ "You can't use getStoryblokApi if you're not loading apiPlugin."
10
+ ), e), c = (o) => (Object.entries(o).forEach(([t, s]) => {
11
+ r.set(t, s);
12
+ }), r), k = (o) => r.has(o) ? r.get(o) : (console.error(`Component ${o} doesn't exist.`), !1), m = () => n, p = () => l, u = (o = {}) => {
13
+ if (e)
14
+ return () => e;
15
+ const { storyblokApi: t } = a(o);
16
+ return e = t, o.components && c(o.components), n = o.enableFallbackComponent, l = o.customFallbackComponent, () => t;
17
+ };
18
+ export {
19
+ g as RichTextResolver,
20
+ C as RichTextSchema,
21
+ M as StoryblokServerComponent,
22
+ d as apiPlugin,
23
+ k as getComponent,
24
+ p as getCustomFallbackComponent,
25
+ m as getEnableFallbackComponent,
26
+ i as getStoryblokApi,
27
+ S as loadStoryblokBridge,
28
+ h as registerStoryblokBridge,
29
+ x as renderRichText,
30
+ c as setComponents,
31
+ F as storyblokEditable,
32
+ u as storyblokInit,
33
+ i as useStoryblokApi,
34
+ A as useStoryblokBridge
35
+ };
@@ -0,0 +1,2 @@
1
+ "use server";
2
+ "use strict";var n=Object.create;var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty;var p=(e,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of d(t))!s.call(e,r)&&r!==i&&a(e,r,{get:()=>t[r],enumerable:!(o=c(t,r))||o.enumerable});return e};var v=(e,t,i)=>(i=e!=null?n(l(e)):{},p(t||!e||!e.__esModule?a(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function u({story:e,pathToRevalidate:t}){if(!e||!t)return console.error("liveEditUpdateAction: story or pathToRevalidate is not provided");if(globalThis.storyCache.set(e.uuid,e),process.env.NEXT_RUNTIME)try{const{revalidatePath:i}=await import("next/cache");i(t)}catch(i){console.error("liveEditUpdateAction: error while revalidating path",i)}}exports.liveEditUpdateAction=u;
@@ -0,0 +1,15 @@
1
+ "use server";
2
+ async function r({ story: e, pathToRevalidate: i }) {
3
+ if (!e || !i)
4
+ return console.error("liveEditUpdateAction: story or pathToRevalidate is not provided");
5
+ if (globalThis.storyCache.set(e.uuid, e), process.env.NEXT_RUNTIME)
6
+ try {
7
+ const { revalidatePath: t } = await import("next/cache");
8
+ t(i);
9
+ } catch (t) {
10
+ console.error("liveEditUpdateAction: error while revalidating path", t);
11
+ }
12
+ }
13
+ export {
14
+ r as liveEditUpdateAction
15
+ };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";const r=require("./storyblok-js.js"),t=require("react"),o=require("./live-edit-update-action.js"),a=({story:e=null,bridgeOptions:i={}})=>{if(typeof window>"u")return null;const d=n=>{n&&t.startTransition(()=>{o.liveEditUpdateAction({story:n,pathToRevalidate:window.location.pathname})})},l=(e==null?void 0:e.internalId)??(e==null?void 0:e.id)??0;return t.useEffect(()=>{r.registerStoryblokBridge(l,n=>d(n),i)},[]),null};module.exports=a;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { registerStoryblokBridge as d } from "./storyblok-js.mjs";
3
+ import { useEffect as l, startTransition as o } from "react";
4
+ import { liveEditUpdateAction as r } from "./live-edit-update-action.mjs";
5
+ const m = ({ story: n = null, bridgeOptions: i = {} }) => {
6
+ if (typeof window > "u")
7
+ return null;
8
+ const t = (e) => {
9
+ e && o(() => {
10
+ r({ story: e, pathToRevalidate: window.location.pathname });
11
+ });
12
+ }, a = (n == null ? void 0 : n.internalId) ?? (n == null ? void 0 : n.id) ?? 0;
13
+ return l(() => {
14
+ d(a, (e) => t(e), i);
15
+ }, []), null;
16
+ };
17
+ export {
18
+ m as default
19
+ };
package/dist/rsc.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./bridge-loader.js"),o=require("./index2.js"),r=require("./story.js"),l=require("./storyblok-component.js"),e=require("./storyblok-js.js");exports.BridgeLoader=t;exports.StoryblokBridgeLoader=t;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.StoryblokStory=r;exports.StoryblokComponent=l;exports.RichTextResolver=e.RichTextResolver;exports.RichTextSchema=e.RichTextSchema;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./common.js"),t=require("./story.js"),r=require("./server-component.js"),e=require("./storyblok-js.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.StoryblokStory=t;exports.StoryblokServerComponent=r;exports.RichTextResolver=e.RichTextResolver;exports.RichTextSchema=e.RichTextSchema;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;
package/dist/rsc.mjs CHANGED
@@ -1,26 +1,23 @@
1
- import { default as t, default as r } from "./bridge-loader.mjs";
2
- import { getComponent as a, getCustomFallbackComponent as i, getEnableFallbackComponent as s, useStoryblokApi as b, setComponents as d, storyblokInit as k, useStoryblokApi as n } from "./index2.mjs";
3
- import { default as g } from "./story.mjs";
4
- import { default as m } from "./storyblok-component.mjs";
5
- import { RichTextResolver as f, RichTextSchema as u, apiPlugin as x, loadStoryblokBridge as c, registerStoryblokBridge as B, renderRichText as C, storyblokEditable as h, registerStoryblokBridge as R } from "./storyblok-js.mjs";
1
+ import { getComponent as t, getCustomFallbackComponent as r, getEnableFallbackComponent as l, useStoryblokApi as i, setComponents as a, storyblokInit as b, useStoryblokApi as s } from "./common.mjs";
2
+ import { default as k } from "./story.mjs";
3
+ import { default as y } from "./server-component.mjs";
4
+ import { RichTextResolver as g, RichTextSchema as m, apiPlugin as d, loadStoryblokBridge as u, registerStoryblokBridge as x, renderRichText as c, storyblokEditable as f, registerStoryblokBridge as C } from "./storyblok-js.mjs";
6
5
  export {
7
- t as BridgeLoader,
8
- f as RichTextResolver,
9
- u as RichTextSchema,
10
- r as StoryblokBridgeLoader,
11
- m as StoryblokComponent,
12
- g as StoryblokStory,
13
- x as apiPlugin,
14
- a as getComponent,
15
- i as getCustomFallbackComponent,
16
- s as getEnableFallbackComponent,
17
- b as getStoryblokApi,
18
- c as loadStoryblokBridge,
19
- B as registerStoryblokBridge,
20
- C as renderRichText,
21
- d as setComponents,
22
- h as storyblokEditable,
23
- k as storyblokInit,
24
- n as useStoryblokApi,
25
- R as useStoryblokBridge
6
+ g as RichTextResolver,
7
+ m as RichTextSchema,
8
+ y as StoryblokServerComponent,
9
+ k as StoryblokStory,
10
+ d as apiPlugin,
11
+ t as getComponent,
12
+ r as getCustomFallbackComponent,
13
+ l as getEnableFallbackComponent,
14
+ i as getStoryblokApi,
15
+ u as loadStoryblokBridge,
16
+ x as registerStoryblokBridge,
17
+ c as renderRichText,
18
+ a as setComponents,
19
+ f as storyblokEditable,
20
+ b as storyblokInit,
21
+ s as useStoryblokApi,
22
+ C as useStoryblokBridge
26
23
  };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react"),o=require("./common.js");require("./story.js");const c=e.forwardRef(({blok:t,...n},m)=>{if(!t)return console.error("Please provide a 'blok' property to the StoryblokComponent"),e.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const r=o.getComponent(t.component);if(r)return e.createElement(r,{ref:m,blok:t,...n});if(o.getEnableFallbackComponent()){const l=o.getCustomFallbackComponent();return l?e.createElement(l,{blok:t,...n}):e.createElement(e.Fragment,null,e.createElement("p",null,"Component could not be found for blok"," ",e.createElement("strong",null,t.component),"! Is it configured correctly?"))}return e.createElement("div",null)});c.displayName="StoryblokComponent";module.exports=c;
@@ -0,0 +1,23 @@
1
+ import e, { forwardRef as m } from "react";
2
+ import { getComponent as a, getEnableFallbackComponent as p, getCustomFallbackComponent as c } from "./common.mjs";
3
+ import "./story.mjs";
4
+ const u = m(
5
+ ({ blok: t, ...o }, l) => {
6
+ if (!t)
7
+ return console.error(
8
+ "Please provide a 'blok' property to the StoryblokComponent"
9
+ ), /* @__PURE__ */ e.createElement("div", null, "Please provide a blok property to the StoryblokComponent");
10
+ const n = a(t.component);
11
+ if (n)
12
+ return /* @__PURE__ */ e.createElement(n, { ref: l, blok: t, ...o });
13
+ if (p()) {
14
+ const r = c();
15
+ return r ? /* @__PURE__ */ e.createElement(r, { blok: t, ...o }) : /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("p", null, "Component could not be found for blok", " ", /* @__PURE__ */ e.createElement("strong", null, t.component), "! Is it configured correctly?"));
16
+ }
17
+ return /* @__PURE__ */ e.createElement("div", null);
18
+ }
19
+ );
20
+ u.displayName = "StoryblokComponent";
21
+ export {
22
+ u as default
23
+ };
package/dist/story.js CHANGED
@@ -1,2 +1 @@
1
- "use client";
2
- "use strict";const t=require("react"),c=require("./client.js"),i=require("./storyblok-component.js"),l=t.forwardRef(({story:e,bridgeOptions:n,...o},r)=>(typeof e.content=="string"&&(e.content=JSON.parse(e.content)),e=c.useStoryblokState(e,n),t.createElement(i,{ref:r,blok:e.content,...o})));module.exports=l;
1
+ "use strict";const r=require("react");require("./common.js");const i=require("./live-editing.js"),l=require("./server-component.js"),a=r.forwardRef(({story:e,bridgeOptions:t,...n},o)=>{if(!e)return console.error("Please provide a 'story' property to the StoryblokServerComponent"),null;if(globalThis.storyCache.has(e.uuid)&&(e=globalThis.storyCache.get(e.uuid)),typeof e.content=="string")try{e.content=JSON.parse(e.content)}catch(c){console.error("An error occurred while trying to parse the story content",c),e.content={}}return r.createElement(r.Fragment,null,r.createElement(l,{ref:o,blok:e.content,...n}),r.createElement(i,{story:e,bridgeOptions:t}))});module.exports=a;
package/dist/story.mjs CHANGED
@@ -1,10 +1,25 @@
1
- "use client";
2
- import r, { forwardRef as f } from "react";
3
- import { useStoryblokState as m } from "./client.mjs";
4
- import a from "./storyblok-component.mjs";
5
- const S = f(
6
- ({ story: t, bridgeOptions: o, ...e }, n) => (typeof t.content == "string" && (t.content = JSON.parse(t.content)), t = m(t, o), /* @__PURE__ */ r.createElement(a, { ref: n, blok: t.content, ...e }))
1
+ import r, { forwardRef as c } from "react";
2
+ import "./common.mjs";
3
+ import a from "./live-editing.mjs";
4
+ import i from "./server-component.mjs";
5
+ const h = c(
6
+ ({ story: e, bridgeOptions: t, ...o }, n) => {
7
+ if (!e)
8
+ return console.error(
9
+ "Please provide a 'story' property to the StoryblokServerComponent"
10
+ ), null;
11
+ if (globalThis.storyCache.has(e.uuid) && (e = globalThis.storyCache.get(e.uuid)), typeof e.content == "string")
12
+ try {
13
+ e.content = JSON.parse(e.content);
14
+ } catch (l) {
15
+ console.error(
16
+ "An error occurred while trying to parse the story content",
17
+ l
18
+ ), e.content = {};
19
+ }
20
+ return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(i, { ref: n, blok: e.content, ...o }), /* @__PURE__ */ r.createElement(a, { story: e, bridgeOptions: t }));
21
+ }
7
22
  );
8
23
  export {
9
- S as default
24
+ h as default
10
25
  };
@@ -0,0 +1,11 @@
1
+ import type { SbReactComponentsMap, SbReactSDKOptions, StoryblokClient } from '../types';
2
+ export declare const useStoryblokApi: () => StoryblokClient;
3
+ export declare const setComponents: (newComponentsMap: SbReactComponentsMap) => Map<string, import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>>;
4
+ export declare const getComponent: (componentKey: string) => React.ElementType | false;
5
+ export declare const getEnableFallbackComponent: () => boolean;
6
+ export declare const getCustomFallbackComponent: () => import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
7
+ export declare const storyblokInit: (pluginOptions?: SbReactSDKOptions) => (() => StoryblokClient);
8
+ export * from '../types';
9
+ export { useStoryblokApi as getStoryblokApi };
10
+ export { default as StoryblokServerComponent } from './server-component';
11
+ export { apiPlugin, loadStoryblokBridge, registerStoryblokBridge, renderRichText, RichTextResolver, RichTextSchema, storyblokEditable, useStoryblokBridge, } from '@storyblok/js';
@@ -1,4 +1,2 @@
1
- export { default as BridgeLoader } from '../bridge-loader';
2
- export { default as StoryblokBridgeLoader } from '../bridge-loader';
3
- export * from '../common';
4
- export { default as StoryblokStory } from '../story';
1
+ export * from './common';
2
+ export { default as StoryblokStory } from './story';
@@ -0,0 +1,4 @@
1
+ export declare function liveEditUpdateAction({ story, pathToRevalidate }: {
2
+ story: any;
3
+ pathToRevalidate: any;
4
+ }): Promise<void>;
@@ -0,0 +1,5 @@
1
+ declare const StoryblokLiveEditing: ({ story, bridgeOptions }: {
2
+ story?: any;
3
+ bridgeOptions?: {};
4
+ }) => any;
5
+ export default StoryblokLiveEditing;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { SbBlokData } from '../types';
3
+ interface SbServerComponentProps {
4
+ blok: SbBlokData;
5
+ [key: string]: unknown;
6
+ }
7
+ declare const StoryblokServerComponent: React.ForwardRefExoticComponent<Omit<SbServerComponentProps, "ref"> & React.RefAttributes<HTMLElement>>;
8
+ export default StoryblokServerComponent;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { ISbStoryData, StoryblokBridgeConfigV2 } from './types';
2
+ import type { ISbStoryData, StoryblokBridgeConfigV2 } from '../types';
3
3
  interface StoryblokStoryProps {
4
4
  story: ISbStoryData;
5
5
  bridgeOptions: StoryblokBridgeConfigV2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/react",
3
- "version": "3.0.15",
3
+ "version": "4.0.0",
4
4
  "description": "SDK to integrate Storyblok into your project using React.",
5
5
  "author": "Storyblok",
6
6
  "homepage": "https://github.com/storyblok/storyblok-react",
@@ -57,7 +57,8 @@
57
57
  "react-dom": "^17.0.0 || ^18.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@storyblok/js": "^3.1.1"
60
+ "@storyblok/js": "^3.1.1",
61
+ "next": "14.2.14"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@babel/core": "^7.25.2",
@@ -1,2 +0,0 @@
1
- "use client";
2
- "use strict";const o=require("react"),r=require("./storyblok-js.js"),t=async e=>{await r.loadStoryblokBridge(),new window.StoryblokBridge(e).on(["published","change"],()=>{window.location.reload()})},n=({options:e})=>(t(e),o.createElement(o.Fragment,null));module.exports=n;
@@ -1,11 +0,0 @@
1
- "use client";
2
- import o from "react";
3
- import { loadStoryblokBridge as r } from "./storyblok-js.mjs";
4
- const t = async (e) => {
5
- await r(), new window.StoryblokBridge(e).on(["published", "change"], () => {
6
- window.location.reload();
7
- });
8
- }, i = ({ options: e }) => (t(e), /* @__PURE__ */ o.createElement(o.Fragment, null));
9
- export {
10
- i as default
11
- };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import type { StoryblokBridgeConfigV2 } from './types';
3
- interface StoryblokBridgeLoaderProps {
4
- options: StoryblokBridgeConfigV2;
5
- [key: string]: unknown;
6
- }
7
- declare const StoryblokBridgeLoader: ({ options }: StoryblokBridgeLoaderProps) => React.JSX.Element;
8
- export default StoryblokBridgeLoader;