@storyblok/react 5.3.0 → 5.4.1
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 +192 -64
- package/dist/core/init.js +1 -0
- package/dist/core/init.mjs +17 -0
- package/dist/core/richtext-hoc.js +1 -0
- package/dist/core/richtext-hoc.mjs +38 -0
- package/dist/core/state.js +1 -0
- package/dist/core/state.mjs +23 -0
- package/dist/core/storyblok-component.js +1 -0
- package/dist/{storyblok-component.mjs → core/storyblok-component.mjs} +4 -3
- package/dist/core/use-storyblok-api.js +1 -0
- package/dist/core/use-storyblok-api.mjs +11 -0
- package/dist/core/use-storyblok-state.js +2 -0
- package/dist/{client.mjs → core/use-storyblok-state.mjs} +6 -6
- package/dist/index.d.ts +209 -13
- package/dist/index.js +1 -1
- package/dist/index.mjs +33 -32
- package/dist/richtext.js +1 -1
- package/dist/richtext.mjs +6 -27
- package/dist/rsc/live-editing.js +2 -0
- package/dist/rsc/live-editing.mjs +30 -0
- package/dist/rsc/story.js +1 -0
- package/dist/{story.mjs → rsc/story.mjs} +6 -7
- package/dist/rsc.d.ts +194 -0
- package/dist/rsc.js +1 -1
- package/dist/rsc.mjs +32 -29
- package/dist/server/richtext.js +1 -0
- package/dist/server/richtext.mjs +8 -0
- package/dist/server/server-component.js +1 -0
- package/dist/{server-component.mjs → server/server-component.mjs} +3 -5
- package/dist/server/server-story.js +1 -0
- package/dist/server/server-story.mjs +25 -0
- package/dist/{server-storyblok-richtext-component.js → server/server-storyblok-richtext-component.js} +1 -1
- package/dist/{server-storyblok-richtext-component.mjs → server/server-storyblok-richtext-component.mjs} +2 -2
- package/dist/ssr.d.ts +192 -0
- package/dist/ssr.js +1 -0
- package/dist/ssr.mjs +35 -0
- package/package.json +8 -3
- package/dist/client.js +0 -2
- package/dist/common/client.d.ts +0 -3
- package/dist/common/client.d.ts.map +0 -1
- package/dist/common/index.d.ts +0 -12
- package/dist/common/index.d.ts.map +0 -1
- package/dist/common/storyblok-component.d.ts +0 -7
- package/dist/common/storyblok-component.d.ts.map +0 -1
- package/dist/common.js +0 -1
- package/dist/common.mjs +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index2.js +0 -1
- package/dist/index2.mjs +0 -30
- package/dist/live-editing.js +0 -2
- package/dist/live-editing.mjs +0 -24
- package/dist/richtext.d.ts +0 -7
- package/dist/richtext.d.ts.map +0 -1
- package/dist/richtext2.js +0 -1
- package/dist/richtext2.mjs +0 -32
- package/dist/rsc/common.d.ts +0 -15
- package/dist/rsc/common.d.ts.map +0 -1
- package/dist/rsc/index.d.ts +0 -7
- package/dist/rsc/index.d.ts.map +0 -1
- package/dist/rsc/live-edit-update-action.d.ts +0 -6
- package/dist/rsc/live-edit-update-action.d.ts.map +0 -1
- package/dist/rsc/live-editing.d.ts +0 -7
- package/dist/rsc/live-editing.d.ts.map +0 -1
- package/dist/rsc/richtext.d.ts +0 -11
- package/dist/rsc/richtext.d.ts.map +0 -1
- package/dist/rsc/server-component.d.ts +0 -7
- package/dist/rsc/server-component.d.ts.map +0 -1
- package/dist/rsc/server-storyblok-richtext-component.d.ts +0 -5
- package/dist/rsc/server-storyblok-richtext-component.d.ts.map +0 -1
- package/dist/rsc/story.d.ts +0 -8
- package/dist/rsc/story.d.ts.map +0 -1
- package/dist/server-component.js +0 -1
- package/dist/story.js +0 -1
- package/dist/storyblok-component.js +0 -1
- package/dist/storyblok-js.js +0 -1
- package/dist/storyblok-js.mjs +0 -898
- package/dist/storyblok-rich-text.d.ts +0 -5
- package/dist/storyblok-rich-text.d.ts.map +0 -1
- package/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -19
- package/dist/utils.d.ts.map +0 -1
- /package/dist/{live-edit-update-action.js → rsc/live-edit-update-action.js} +0 -0
- /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
|
|
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
|
-
##
|
|
228
|
+
## Choosing the Right Export
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
`@storyblok/react` provides three different exports to meet different deployment and framework requirements:
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
### Export Types
|
|
233
233
|
|
|
234
|
-
|
|
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
|
-
|
|
240
|
+
### When to Use Each Export
|
|
237
241
|
|
|
238
|
-
|
|
239
|
-
-
|
|
240
|
-
-
|
|
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
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
258
|
+
## Next.js Static Export Support
|
|
247
259
|
|
|
248
|
-
If
|
|
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
|
-
###
|
|
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
|
-
|
|
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/
|
|
274
|
-
import {
|
|
275
|
-
import
|
|
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
|
-
<
|
|
280
|
-
<
|
|
281
|
-
|
|
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
|
-
|
|
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
|
-
|
|
316
|
+
## Next.js using App Router
|
|
291
317
|
|
|
292
|
-
|
|
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
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
###
|
|
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 {
|
|
311
|
-
import { getStoryblokApi } from '@/lib/storyblok';
|
|
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
|
-
<
|
|
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
|
-
**
|
|
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
|
-
|
|
394
|
+
**Advanced: Bridge Options**
|
|
335
395
|
|
|
336
|
-
|
|
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
|
-
<
|
|
401
|
+
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />
|
|
343
402
|
```
|
|
344
403
|
|
|
345
|
-
**
|
|
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
|
-
|
|
349
|
-
<StoryblokServerComponent blok={data.story.content} />
|
|
350
|
-
<StoryblokLiveEditing story={data.story} />
|
|
409
|
+
import { StoryblokServerComponent, StoryblokLiveEditing } from '@storyblok/react/rsc';
|
|
351
410
|
|
|
352
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
425
|
+
import {
|
|
426
|
+
storyblokEditable,
|
|
427
|
+
StoryblokServerComponent,
|
|
428
|
+
} from "@storyblok/react/rsc";
|
|
362
429
|
|
|
363
|
-
|
|
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
|
-
|
|
367
|
-
|
|
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/
|
|
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
|
|
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
|

|
|
@@ -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
|
|
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
|
|
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(
|
|
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 "
|
|
4
|
-
const g = (e = null,
|
|
5
|
-
const [r,
|
|
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
|
-
|
|
7
|
+
o(e), !(!t || !e) && c(
|
|
8
8
|
d,
|
|
9
|
-
(f) =>
|
|
10
|
-
|
|
9
|
+
(f) => o(f),
|
|
10
|
+
s
|
|
11
11
|
);
|
|
12
12
|
}, [e]), r;
|
|
13
13
|
};
|