@storyblok/react 5.3.0 → 5.4.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.
Files changed (84) hide show
  1. package/README.md +192 -64
  2. package/dist/core/init.js +1 -0
  3. package/dist/core/init.mjs +17 -0
  4. package/dist/core/richtext-hoc.js +1 -0
  5. package/dist/core/richtext-hoc.mjs +38 -0
  6. package/dist/core/state.js +1 -0
  7. package/dist/core/state.mjs +23 -0
  8. package/dist/core/storyblok-component.js +1 -0
  9. package/dist/{storyblok-component.mjs → core/storyblok-component.mjs} +4 -3
  10. package/dist/core/use-storyblok-api.js +1 -0
  11. package/dist/core/use-storyblok-api.mjs +11 -0
  12. package/dist/core/use-storyblok-state.js +2 -0
  13. package/dist/{client.mjs → core/use-storyblok-state.mjs} +6 -6
  14. package/dist/index.d.ts +209 -13
  15. package/dist/index.js +1 -1
  16. package/dist/index.mjs +33 -32
  17. package/dist/richtext.js +1 -1
  18. package/dist/richtext.mjs +6 -27
  19. package/dist/rsc/live-editing.js +2 -0
  20. package/dist/rsc/live-editing.mjs +30 -0
  21. package/dist/rsc/story.js +1 -0
  22. package/dist/{story.mjs → rsc/story.mjs} +6 -7
  23. package/dist/rsc.d.ts +194 -0
  24. package/dist/rsc.js +1 -1
  25. package/dist/rsc.mjs +32 -29
  26. package/dist/server/richtext.js +1 -0
  27. package/dist/server/richtext.mjs +8 -0
  28. package/dist/server/server-component.js +1 -0
  29. package/dist/{server-component.mjs → server/server-component.mjs} +3 -5
  30. package/dist/server/server-story.js +1 -0
  31. package/dist/server/server-story.mjs +25 -0
  32. package/dist/{server-storyblok-richtext-component.js → server/server-storyblok-richtext-component.js} +1 -1
  33. package/dist/{server-storyblok-richtext-component.mjs → server/server-storyblok-richtext-component.mjs} +2 -2
  34. package/dist/ssr.d.ts +192 -0
  35. package/dist/ssr.js +1 -0
  36. package/dist/ssr.mjs +35 -0
  37. package/package.json +7 -2
  38. package/dist/client.js +0 -2
  39. package/dist/common/client.d.ts +0 -3
  40. package/dist/common/client.d.ts.map +0 -1
  41. package/dist/common/index.d.ts +0 -12
  42. package/dist/common/index.d.ts.map +0 -1
  43. package/dist/common/storyblok-component.d.ts +0 -7
  44. package/dist/common/storyblok-component.d.ts.map +0 -1
  45. package/dist/common.js +0 -1
  46. package/dist/common.mjs +0 -33
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index2.js +0 -1
  49. package/dist/index2.mjs +0 -30
  50. package/dist/live-editing.js +0 -2
  51. package/dist/live-editing.mjs +0 -24
  52. package/dist/richtext.d.ts +0 -7
  53. package/dist/richtext.d.ts.map +0 -1
  54. package/dist/richtext2.js +0 -1
  55. package/dist/richtext2.mjs +0 -32
  56. package/dist/rsc/common.d.ts +0 -15
  57. package/dist/rsc/common.d.ts.map +0 -1
  58. package/dist/rsc/index.d.ts +0 -7
  59. package/dist/rsc/index.d.ts.map +0 -1
  60. package/dist/rsc/live-edit-update-action.d.ts +0 -6
  61. package/dist/rsc/live-edit-update-action.d.ts.map +0 -1
  62. package/dist/rsc/live-editing.d.ts +0 -7
  63. package/dist/rsc/live-editing.d.ts.map +0 -1
  64. package/dist/rsc/richtext.d.ts +0 -11
  65. package/dist/rsc/richtext.d.ts.map +0 -1
  66. package/dist/rsc/server-component.d.ts +0 -7
  67. package/dist/rsc/server-component.d.ts.map +0 -1
  68. package/dist/rsc/server-storyblok-richtext-component.d.ts +0 -5
  69. package/dist/rsc/server-storyblok-richtext-component.d.ts.map +0 -1
  70. package/dist/rsc/story.d.ts +0 -8
  71. package/dist/rsc/story.d.ts.map +0 -1
  72. package/dist/server-component.js +0 -1
  73. package/dist/story.js +0 -1
  74. package/dist/storyblok-component.js +0 -1
  75. package/dist/storyblok-js.js +0 -1
  76. package/dist/storyblok-js.mjs +0 -898
  77. package/dist/storyblok-rich-text.d.ts +0 -5
  78. package/dist/storyblok-rich-text.d.ts.map +0 -1
  79. package/dist/types.d.ts +0 -17
  80. package/dist/types.d.ts.map +0 -1
  81. package/dist/utils.d.ts +0 -19
  82. package/dist/utils.d.ts.map +0 -1
  83. /package/dist/{live-edit-update-action.js → rsc/live-edit-update-action.js} +0 -0
  84. /package/dist/{live-edit-update-action.mjs → rsc/live-edit-update-action.mjs} +0 -0
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  </a>
5
5
  <h1 align="center">@storyblok/react</h1>
6
6
  <p align="center">
7
- The React plugin you need to interact with <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react" target="_blank">Storyblok API</a> and enable the <a href="https://www.storyblok.com/docs/guide/essentials/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react" target="_blank">Real-time Visual Editing Experience</a>. This package helps you integrate Storyblok with React along with all types of React based frameworks like Next.js, Remix etc. This SDK also includes the support for React Server Side Components.
7
+ The React plugin you need to interact with <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react" target="_blank">Storyblok API</a> and enable the <a href="https://www.storyblok.com/docs/guide/essentials/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react" target="_blank">Real-time Visual Editing Experience</a>. This package helps you integrate Storyblok with React along with all types of React based frameworks like Next.js, Remix etc. This SDK includes support for React Server Components, static site generation, and Next.js static exports.
8
8
  </p>
9
9
  <br />
10
10
  </div>
@@ -225,98 +225,154 @@ export async function fetchData() {
225
225
  }
226
226
  ```
227
227
 
228
- ## Next.js using App Router
228
+ ## Choosing the Right Export
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 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.
230
+ `@storyblok/react` provides three different exports to meet different deployment and framework requirements:
231
231
 
232
- > The SDK has a special module for RSC. Always import `@storyblok/react/rsc` while using Server Components.
232
+ ### Export Types
233
233
 
234
- ### Live Editing Bridge Loading
234
+ | Export | Use Case | Live Editing | Static Export Support |
235
+ | ---------------------- | ----------------------------------- | ------------ | --------------------- |
236
+ | `@storyblok/react` | Client-side rendering, SPA | ✅ | ✅ |
237
+ | `@storyblok/react/ssr` | Server-side rendering, static sites | ❌ | ✅ |
238
+ | `@storyblok/react/rsc` | React Server Components | ✅ | ❌ |
235
239
 
236
- **When do you need `StoryblokLiveEditing`?**
240
+ ### When to Use Each Export
237
241
 
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
242
+ **Use `@storyblok/react`** for:
243
+ - Single Page Applications (SPA)
244
+ - Client-side rendered React apps
245
+ - When you need live editing in browser-based applications
241
246
 
242
- **Why is this needed for RSC-only apps?**
247
+ **Use `@storyblok/react/ssr`** for:
248
+ - Next.js static exports (`output: 'export'`)
249
+ - Static site generation without live editing
250
+ - Server-side rendering where live editing isn't required
251
+ - Performance-critical scenarios where bundle size matters
243
252
 
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.
253
+ **Use `@storyblok/react/rsc`** for:
254
+ - Next.js App Router with React Server Components
255
+ - When you need live editing with server components
256
+ - Modern React applications with server/client component separation
245
257
 
246
- **How to know if you need it?**
258
+ ## Next.js Static Export Support
247
259
 
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.
260
+ If you're using Next.js with `output: 'export'` for static site generation, you must use the **`@storyblok/react/ssr`** export. The RSC export includes server actions that are incompatible with static exports.
249
261
 
250
- ### 1. Initialize
262
+ ### Static Export Configuration
263
+
264
+ ```js
265
+ // next.config.js
266
+ /** @type {import('next').NextConfig} */
267
+ const nextConfig = {
268
+ output: 'export', // Enables static export
269
+ };
270
+
271
+ module.exports = nextConfig;
272
+ ```
251
273
 
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.
274
+ ### Static Export Implementation
253
275
 
254
276
  ```js
255
277
  // lib/storyblok.js
278
+ import { apiPlugin, storyblokInit } from "@storyblok/react/ssr"; // Use SSR export
256
279
  import Page from "@/components/Page";
257
280
  import Teaser from "@/components/Teaser";
258
- import { apiPlugin, storyblokInit } from "@storyblok/react/rsc";
259
281
 
260
282
  export const getStoryblokApi = storyblokInit({
261
283
  accessToken: "YOUR_ACCESS_TOKEN",
262
284
  use: [apiPlugin],
263
285
  components: {
264
- teaser: Teaser,
265
286
  page: Page,
287
+ teaser: Teaser,
266
288
  },
267
289
  });
268
290
  ```
269
291
 
270
- In `app/layout.jsx`, wrap your whole app using a `StoryblokProvider` component (this provider is created in the next step) :
271
-
272
292
  ```js
273
- // app/layout.jsx
274
- import { apiPlugin, storyblokInit } from "@storyblok/react/rsc";
275
- import StoryblokProvider from "../components/StoryblokProvider";
293
+ // app/page.js
294
+ import { StoryblokServerStory } from "@storyblok/react/ssr";
295
+ import { getStoryblokApi } from "@/lib/storyblok";
296
+
297
+ export default async function Home() {
298
+ const { data } = await fetchData();
276
299
 
277
- export default function RootLayout({ children }) {
278
300
  return (
279
- <StoryblokProvider>
280
- <html lang="en">
281
- <body>{children}</body>
282
- </html>
283
- </StoryblokProvider>
301
+ <div>
302
+ <StoryblokServerStory story={data.story} />
303
+ </div>
284
304
  );
285
305
  }
306
+
307
+ export async function fetchData() {
308
+ const storyblokApi = getStoryblokApi();
309
+ return storyblokApi.get(`cdn/stories/home`, { version: 'draft' });
310
+ }
286
311
  ```
287
312
 
288
- ### 2. Create StoryblokProvider and Import your Storyblok Components
313
+ > [!NOTE]
314
+ > The SSR export does not include live editing capabilities. Live editing requires client-side JavaScript that's incompatible with static exports.
289
315
 
290
- 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.
316
+ ## Next.js using App Router
291
317
 
292
- ```js
293
- // components/StoryblokProvider.jsx
294
- "use client";
318
+ The components in the `app` directory are by default React Server Side Components. The SDK provides different approaches depending on your deployment needs:
295
319
 
296
- import { getStoryblokApi } from "@/lib/storyblok";
320
+ - **For static exports**: Use `@storyblok/react/ssr` (no live editing)
321
+ - **For dynamic apps**: Use `@storyblok/react/rsc` (with live editing)
297
322
 
298
- export default function StoryblokProvider({ children }) {
299
- getStoryblokApi();
300
- return children;
301
- }
323
+ ### React Server Components with Live Editing
324
+
325
+ You can enable Storyblok Visual Editor's live editing with React Server Components by using the `StoryblokStory` component, which automatically handles both content rendering and live editing bridge loading. The SDK allows you to take full advantage of the Live Editing while maintaining the performance benefits of Server Components.
326
+
327
+ > For live editing with RSC, always import `@storyblok/react/rsc`.
328
+
329
+ ### Live Editing Bridge Loading
330
+
331
+ **When is bridge loading automatic?**
332
+
333
+ - ✅ **Using `StoryblokStory`**: Automatically handles bridge loading and live editing
334
+ - ✅ **Client-Side Components**: When using `StoryblokComponent` or other client components that already load the bridge
335
+ - ❌ **Pure `StoryblokServerComponent`**: Manual bridge loading needed with `StoryblokLiveEditing`
336
+
337
+ **Why does RSC need special handling?**
338
+
339
+ In React Server Components environments where components are purely server-rendered, the Storyblok bridge script isn't automatically loaded on the client. The `StoryblokStory` component detects when running in the Visual Editor and loads the bridge script for you.
340
+
341
+ ### 1. Initialize
342
+
343
+ 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 server components.
344
+
345
+ ```js
346
+ // lib/storyblok.js
347
+ import Page from "@/components/Page";
348
+ import Teaser from "@/components/Teaser";
349
+ import { apiPlugin, storyblokInit } from "@storyblok/react/rsc";
350
+
351
+ export const getStoryblokApi = storyblokInit({
352
+ accessToken: "YOUR_ACCESS_TOKEN",
353
+ use: [apiPlugin],
354
+ components: {
355
+ teaser: Teaser,
356
+ page: Page,
357
+ },
358
+ });
302
359
  ```
303
360
 
304
- ### 3. Fetch Content and Render Components
361
+ ### 2. Fetch Content and Render Components
305
362
 
306
363
  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:
307
364
 
308
365
  ```js
309
- import { StoryblokClient, ISbStoriesParams } from '@storyblok/react';
310
- import { StoryblokServerComponent, StoryblokLiveEditing } from '@storyblok/react/rsc';
311
- import { getStoryblokApi } from '@/lib/storyblok'; // Remember to import from the local file
366
+ import { StoryblokClient, ISbStoriesParams } from '@storyblok/react/rsc';
367
+ import { StoryblokStory } from '@storyblok/react/rsc';
368
+ import { getStoryblokApi } from '@/lib/storyblok';
312
369
 
313
370
  export default async function Home() {
314
371
  const { data } = await fetchData();
315
372
 
316
373
  return (
317
374
  <div>
318
- <StoryblokServerComponent blok={data.story.content} />
319
- <StoryblokLiveEditing story={data.story} />
375
+ <StoryblokStory story={data.story} />
320
376
  </div>
321
377
  );
322
378
  }
@@ -329,48 +385,65 @@ export async function fetchData() {
329
385
  }
330
386
  ```
331
387
 
332
- **Live Editing in RSC Environments:**
388
+ **The `StoryblokStory` component automatically:**
389
+ - Renders your Storyblok content components on the server
390
+ - Loads the bridge script for live editing (when in Visual Editor)
391
+ - Handles live content updates via global cache
392
+ - Manages bridge registration and cleanup
333
393
 
334
- For **pure React Server Components** apps (no client-side components), you need two separate components:
394
+ **Advanced: Bridge Options**
335
395
 
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)
396
+ You can pass bridge options for advanced configurations:
338
397
 
339
398
  ```jsx
340
- const bridgeOptions = { resolveRelations: ['article.author'] }
399
+ const bridgeOptions = { resolveRelations: ['article.author'] };
341
400
 
342
- <StoryblokLiveEditing story={data.story} bridgeOptions={bridgeOptions} />
401
+ <StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />
343
402
  ```
344
403
 
345
- **If you have client-side components in your app**, the bridge is likely already loaded, so you can skip `StoryblokLiveEditing`:
404
+ **Advanced: Manual Component Separation**
405
+
406
+ For advanced use cases where you need more control, you can use the individual components:
346
407
 
347
408
  ```jsx
348
- // RSC-only app (bridge needed)
349
- <StoryblokServerComponent blok={data.story.content} />
350
- <StoryblokLiveEditing story={data.story} />
409
+ import { StoryblokServerComponent, StoryblokLiveEditing } from '@storyblok/react/rsc';
351
410
 
352
- // Hybrid app with client components (bridge already loaded)
411
+ // Manual approach (only use if you need special control)
353
412
  <StoryblokServerComponent blok={data.story.content} />
413
+ <StoryblokLiveEditing story={data.story} bridgeOptions={bridgeOptions} />
354
414
  ```
355
415
 
356
- **Alternative: Using StoryblokStory (All-in-One)**
416
+ > [!NOTE]
417
+ > Most applications should use `StoryblokStory` for the best developer experience and automatic live editing support.
418
+
419
+ **Important: Individual Content Components**
357
420
 
358
- If you prefer a single component that handles both rendering and live editing:
421
+ When creating your individual Storyblok content components (like `Page`, `Teaser`, etc.), you must use `StoryblokServerComponent` for nested components. Import it from the same export you're using:
359
422
 
423
+ **For RSC (with live editing):**
360
424
  ```jsx
361
- import { StoryblokStory } from '@storyblok/react/rsc';
425
+ import {
426
+ storyblokEditable,
427
+ StoryblokServerComponent,
428
+ } from "@storyblok/react/rsc";
362
429
 
363
- <StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />
364
- ```
430
+ const Page = ({ blok }) => (
431
+ <main {...storyblokEditable(blok)}>
432
+ {blok.body.map((nestedBlok) => (
433
+ <StoryblokServerComponent blok={nestedBlok} key={nestedBlok._uid} />
434
+ ))}
435
+ </main>
436
+ );
365
437
 
366
- > [!IMPORTANT]
367
- > When you render components, you must use `StoryblokServerComponent` exported from `@storyblok/react/rsc` instead of `StoryblokComponent`, even when you declare a client component with `"use client"`. This is because the components are always rendered on the server side.
438
+ export default Page;
439
+ ```
368
440
 
441
+ **For SSR (static exports):**
369
442
  ```jsx
370
443
  import {
371
444
  storyblokEditable,
372
445
  StoryblokServerComponent,
373
- } from "@storyblok/react/rsc";
446
+ } from "@storyblok/react/ssr";
374
447
 
375
448
  const Page = ({ blok }) => (
376
449
  <main {...storyblokEditable(blok)}>
@@ -383,10 +456,13 @@ const Page = ({ blok }) => (
383
456
  export default Page;
384
457
  ```
385
458
 
459
+ > [!IMPORTANT]
460
+ > Always use `StoryblokServerComponent` for nested content components, even when you declare them as client components with `"use client"`. This ensures proper server-side rendering.
461
+
386
462
  > [!NOTE]
387
463
  > 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.
388
464
 
389
- To try this setup, take a look at the [Next 13 Live Editing Playground](https://github.com/storyblok/storyblok-react/tree/main/playground/next13) in this repo.
465
+ To try this setup, take a look at the [Next.js RSC Playgrounds](https://github.com/storyblok/monoblok/tree/main/packages/react/playground) in this repo.
390
466
 
391
467
  ## Next.js using Pages Router
392
468
 
@@ -789,6 +865,58 @@ Storyblok's React SDK automatically renders these predefined components based on
789
865
 
790
866
  By using these techniques, you can ensure that only the necessary components and dependencies are loaded for each page, improving your site's performance and speed.
791
867
 
868
+ ## Troubleshooting
869
+
870
+ ### "Server Actions are not supported with static export"
871
+
872
+ **Error:** When using Next.js with `output: 'export'`, you might encounter:
873
+ ```
874
+ Error: Server Actions are not supported with static export
875
+ ```
876
+
877
+ **Solution:** Use `@storyblok/react/ssr` instead of `@storyblok/react/rsc` for static exports:
878
+
879
+ ```diff
880
+ - import { StoryblokStory } from "@storyblok/react/rsc";
881
+ + import { StoryblokServerStory } from "@storyblok/react/ssr";
882
+ ```
883
+
884
+ **Explanation:** The RSC export includes server actions for live editing, which are incompatible with static exports. The SSR export provides server-side rendering without server actions.
885
+
886
+ ### Live Editing Not Working
887
+
888
+ **Issue:** Live editing doesn't work in the Visual Editor.
889
+
890
+ **Possible Solutions:**
891
+
892
+ 1. **Using SSR export**: Live editing isn't available with `@storyblok/react/ssr`. Use `@storyblok/react/rsc` for live editing.
893
+
894
+ 2. **Missing bridge loading**: Ensure you're using `StoryblokStory` (RSC) which automatically loads the bridge, or manually add `StoryblokLiveEditing`.
895
+
896
+ 3. **Development mode**: Live editing only works in development mode or when the Visual Editor is active.
897
+
898
+ ### Component Not Found
899
+
900
+ **Error:** Seeing empty divs or "Component not found" instead of your content.
901
+
902
+ **Solution:** Ensure all your Storyblok components are registered during initialization:
903
+
904
+ ```js
905
+ storyblokInit({
906
+ components: {
907
+ page: Page, // Matches 'page' component in Storyblok
908
+ teaser: Teaser, // Matches 'teaser' component in Storyblok
909
+ // Add all your components here
910
+ },
911
+ });
912
+ ```
913
+
914
+ ### TypeScript Import Errors
915
+
916
+ **Issue:** TypeScript can't find the `/ssr` or `/rsc` exports.
917
+
918
+ **Solution:** Ensure you're using the latest version of `@storyblok/react` (v5.3.0+) which includes these exports.
919
+
792
920
  ## The Storyblok JavaScript SDK Ecosystem
793
921
 
794
922
  ![A visual representation of the Storyblok JavaScript SDK Ecosystem](https://a.storyblok.com/f/88751/2400x1350/be4a4a4180/sdk-ecosystem.png/m/1200x0)
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@storyblok/js"),t=require("./state.js"),l=(e={})=>{const o=t.getStoryblokApiInstance();if(o)return()=>o;const{storyblokApi:n}=a.storyblokInit(e);return t.setStoryblokApiInstance(n),e.components&&t.setComponents(e.components),e.enableFallbackComponent!==void 0&&t.setEnableFallbackComponent(e.enableFallbackComponent),e.customFallbackComponent&&t.setCustomFallbackComponent(e.customFallbackComponent),()=>n};exports.getComponent=t.getComponent;exports.getCustomFallbackComponent=t.getCustomFallbackComponent;exports.getEnableFallbackComponent=t.getEnableFallbackComponent;exports.setComponents=t.setComponents;exports.storyblokInit=l;
@@ -0,0 +1,17 @@
1
+ import { storyblokInit as n } from "@storyblok/js";
2
+ import { setStoryblokApiInstance as a, setComponents as m, setEnableFallbackComponent as l, setCustomFallbackComponent as b, getStoryblokApiInstance as c } from "./state.mjs";
3
+ import { getComponent as f, getCustomFallbackComponent as p, getEnableFallbackComponent as y } from "./state.mjs";
4
+ const k = (o = {}) => {
5
+ const t = c();
6
+ if (t)
7
+ return () => t;
8
+ const { storyblokApi: e } = n(o);
9
+ return a(e), o.components && m(o.components), o.enableFallbackComponent !== void 0 && l(o.enableFallbackComponent), o.customFallbackComponent && b(o.customFallbackComponent), () => e;
10
+ };
11
+ export {
12
+ f as getComponent,
13
+ p as getCustomFallbackComponent,
14
+ y as getEnableFallbackComponent,
15
+ m as setComponents,
16
+ k as storyblokInit
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),i=require("@storyblok/js");function u(o,{isServerContext:t=!1}={}){return function(e){var a,l;const r=(a=e==null?void 0:e.attrs)==null?void 0:a.body,c=Array.isArray(r)&&r.length>0?r[0]:void 0,s=((l=e.attrs)==null?void 0:l.id)||(t?`fallback-key-${JSON.stringify(e.attrs)}`:void 0);return n.createElement(o,{blok:c,key:s})}}function m(o,{isServerContext:t=!1}={}){return function(e){const r=u(o,{isServerContext:t}),c={...t?e:{},renderFn:n.createElement,textFn:s=>n.createElement(n.Fragment,{key:Math.random().toString(36).substring(2,15)},s),resolvers:{[i.BlockTypes.COMPONENT]:r,...e.resolvers},keyedResolvers:!0,...t?{}:e};return i.richTextResolver(c)}}exports.createComponentResolver=u;exports.createRichTextHook=m;
@@ -0,0 +1,38 @@
1
+ import n from "react";
2
+ import { BlockTypes as m, richTextResolver as u } from "@storyblok/js";
3
+ function f(o, {
4
+ isServerContext: t = !1
5
+ } = {}) {
6
+ return function(e) {
7
+ var a, l;
8
+ const r = (a = e == null ? void 0 : e.attrs) == null ? void 0 : a.body, s = Array.isArray(r) && r.length > 0 ? r[0] : void 0, c = ((l = e.attrs) == null ? void 0 : l.id) || (t ? `fallback-key-${JSON.stringify(e.attrs)}` : void 0);
9
+ return n.createElement(o, {
10
+ blok: s,
11
+ key: c
12
+ });
13
+ };
14
+ }
15
+ function R(o, {
16
+ isServerContext: t = !1
17
+ } = {}) {
18
+ return function(e) {
19
+ const r = f(o, { isServerContext: t }), s = {
20
+ ...t ? e : {},
21
+ renderFn: n.createElement,
22
+ textFn: (c) => n.createElement(n.Fragment, {
23
+ key: Math.random().toString(36).substring(2, 15)
24
+ }, c),
25
+ resolvers: {
26
+ [m.COMPONENT]: r,
27
+ ...e.resolvers
28
+ },
29
+ keyedResolvers: !0,
30
+ ...t ? {} : e
31
+ };
32
+ return u(s);
33
+ };
34
+ }
35
+ export {
36
+ f as createComponentResolver,
37
+ R as createRichTextHook
38
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let o=null;const e=new Map;let n=!1,l=null;globalThis.storyCache=globalThis.storyCache?globalThis.storyCache:new Map;const c=()=>o,b=t=>{o=t},p=t=>(Object.entries(t).forEach(([s,a])=>{e.set(s,a)}),e),r=t=>e.has(t)?e.get(t):(console.error(`Component ${t} doesn't exist.`),!1),C=()=>n,m=t=>{n=t},k=()=>l,g=t=>{l=t};exports.getComponent=r;exports.getCustomFallbackComponent=k;exports.getEnableFallbackComponent=C;exports.getStoryblokApiInstance=c;exports.setComponents=p;exports.setCustomFallbackComponent=g;exports.setEnableFallbackComponent=m;exports.setStoryblokApiInstance=b;
@@ -0,0 +1,23 @@
1
+ let e = null;
2
+ const o = /* @__PURE__ */ new Map();
3
+ let n = !1, s = null;
4
+ globalThis.storyCache = globalThis.storyCache ? globalThis.storyCache : /* @__PURE__ */ new Map();
5
+ const c = () => e, r = (t) => {
6
+ e = t;
7
+ }, b = (t) => (Object.entries(t).forEach(([l, a]) => {
8
+ o.set(l, a);
9
+ }), o), p = (t) => o.has(t) ? o.get(t) : (console.error(`Component ${t} doesn't exist.`), !1), C = () => n, m = (t) => {
10
+ n = t;
11
+ }, i = () => s, k = (t) => {
12
+ s = t;
13
+ };
14
+ export {
15
+ p as getComponent,
16
+ i as getCustomFallbackComponent,
17
+ C as getEnableFallbackComponent,
18
+ c as getStoryblokApiInstance,
19
+ b as setComponents,
20
+ k as setCustomFallbackComponent,
21
+ m as setEnableFallbackComponent,
22
+ r as setStoryblokApiInstance
23
+ };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react");require("@storyblok/js");const t=require("./state.js"),c=l.forwardRef(({blok:o,...n},i)=>{if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),e.jsx("div",{children:"Please provide a blok property to the StoryblokComponent"});const r=t.getComponent(o.component);if(r)return e.jsx(r,{ref:i,blok:o,...n});if(t.getEnableFallbackComponent()){const s=t.getCustomFallbackComponent();return s?e.jsx(s,{blok:o,...n}):e.jsx(e.Fragment,{children:e.jsxs("p",{children:["Component could not be found for blok"," ",e.jsx("strong",{children:o.component}),"! Is it configured correctly?"]})})}return e.jsx("div",{})});c.displayName="StoryblokComponent";module.exports=c;
@@ -1,6 +1,7 @@
1
- import { jsx as o, Fragment as l, jsxs as m } from "react/jsx-runtime";
1
+ import { jsx as o, Fragment as m, jsxs as l } from "react/jsx-runtime";
2
2
  import { forwardRef as i } from "react";
3
- import { getComponent as a, getEnableFallbackComponent as c, getCustomFallbackComponent as d } from "./index2.mjs";
3
+ import "@storyblok/js";
4
+ import { getComponent as a, getEnableFallbackComponent as c, getCustomFallbackComponent as d } from "./state.mjs";
4
5
  const s = i(
5
6
  ({ blok: e, ...t }, p) => {
6
7
  if (!e)
@@ -12,7 +13,7 @@ const s = i(
12
13
  return /* @__PURE__ */ o(n, { ref: p, blok: e, ...t });
13
14
  if (c()) {
14
15
  const r = d();
15
- return r ? /* @__PURE__ */ o(r, { blok: e, ...t }) : /* @__PURE__ */ o(l, { children: /* @__PURE__ */ m("p", { children: [
16
+ return r ? /* @__PURE__ */ o(r, { blok: e, ...t }) : /* @__PURE__ */ o(m, { children: /* @__PURE__ */ l("p", { children: [
16
17
  "Component could not be found for blok",
17
18
  " ",
18
19
  /* @__PURE__ */ o("strong", { children: e.component }),
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./state.js"),t=()=>{const o=e.getStoryblokApiInstance();return o||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),o};exports.getStoryblokApi=t;exports.useStoryblokApi=t;
@@ -0,0 +1,11 @@
1
+ import { getStoryblokApiInstance as t } from "./state.mjs";
2
+ const e = () => {
3
+ const o = t();
4
+ return o || console.error(
5
+ "You can't use getStoryblokApi if you're not loading apiPlugin."
6
+ ), o;
7
+ };
8
+ export {
9
+ e as getStoryblokApi,
10
+ e as useStoryblokApi
11
+ };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),c=require("@storyblok/js"),f=(e=null,o={})=>{const[r,s]=t.useState(e),u=(e==null?void 0:e.id)??0,d=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return t.useEffect(()=>{s(e),!(!d||!e)&&c.registerStoryblokBridge(u,n=>s(n),o)},[e]),r};exports.useStoryblokState=f;
@@ -1,13 +1,13 @@
1
1
  "use client";
2
2
  import { useState as u, useEffect as n } from "react";
3
- import { registerStoryblokBridge as c } from "./storyblok-js.mjs";
4
- const g = (e = null, o = {}) => {
5
- const [r, s] = u(e), d = (e == null ? void 0 : e.id) ?? 0, t = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
3
+ import { registerStoryblokBridge as c } from "@storyblok/js";
4
+ const g = (e = null, s = {}) => {
5
+ const [r, o] = u(e), d = (e == null ? void 0 : e.id) ?? 0, t = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
6
6
  return n(() => {
7
- s(e), !(!t || !e) && c(
7
+ o(e), !(!t || !e) && c(
8
8
  d,
9
- (f) => s(f),
10
- o
9
+ (f) => o(f),
10
+ s
11
11
  );
12
12
  }, [e]), r;
13
13
  };