@storyblok/react 2.1.7 → 2.1.8
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 +63 -0
- package/dist/client-0cdf4d8e.js +1 -0
- package/dist/{client-580f8a39.mjs → client-798eb80c.mjs} +2 -1
- package/dist/{index-45a2f239.js → index-364d653e.js} +1 -1
- package/dist/{index-b8bd6e01.mjs → index-4af66cd0.mjs} +6 -1
- package/dist/storyblok-react.js +1 -1
- package/dist/storyblok-react.mjs +5 -4
- package/dist/storyblok-react2.js +1 -1
- package/dist/storyblok-react2.mjs +3 -2
- package/dist/storyblok-react4.js +1 -1
- package/dist/storyblok-react4.mjs +5 -2
- package/dist/types/common/index.d.ts +2 -1
- package/package.json +5 -5
- package/dist/client-f55c03c7.js +0 -1
package/README.md
CHANGED
|
@@ -425,6 +425,69 @@ export async function getStaticProps({ preview = false }) {
|
|
|
425
425
|
|
|
426
426
|
**Check out the [code for the first part of our Next.js + Storyblok Ultimate Tutorial](https://github.com/storyblok/next.js-ultimate-tutorial/tree/part-1). Or you can also read on how to add Storyblok to a Next.js project in 5 minutes [here](https://www.storyblok.com/tp/add-a-headless-cms-to-next-js-in-5-minutes)**
|
|
427
427
|
|
|
428
|
+
### 3. Adding components per page
|
|
429
|
+
|
|
430
|
+
If you are using the pages router, you might want to load your components per page, instead of all in the `_app` file.
|
|
431
|
+
|
|
432
|
+
If you load all components in the `_app` file with `storyblokInit` funciton, the JavaScript for all of those components will be loaded on every page, even on pages where most of these components might not be used.
|
|
433
|
+
|
|
434
|
+
A better approach is to load these components on a per-page basis, reducing the JS bundle for that page, improving your load time, and SEO.
|
|
435
|
+
|
|
436
|
+
Simply execute `storyblokInit` in the `_app` file as you did before, but omit the `components` object and the component imports like so:
|
|
437
|
+
|
|
438
|
+
```diff
|
|
439
|
+
import { storyblokInit, apiPlugin } from "@storyblok/react";
|
|
440
|
+
|
|
441
|
+
/** Import your components */
|
|
442
|
+
-import Page from "./components/Page";
|
|
443
|
+
-import Teaser from "./components/Teaser";
|
|
444
|
+
|
|
445
|
+
storyblokInit({
|
|
446
|
+
accessToken: "YOUR_ACCESS_TOKEN",
|
|
447
|
+
use: [apiPlugin],
|
|
448
|
+
- components: {
|
|
449
|
+
- page: Page,
|
|
450
|
+
- teaser: Teaser,
|
|
451
|
+
- },
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
After that, use the `setComponent` method in each of your pages, to only load the components you need for that particular page:
|
|
456
|
+
|
|
457
|
+
```diff
|
|
458
|
+
import React from "react";
|
|
459
|
+
import Teaser from "../components/teaser";
|
|
460
|
+
import Grid from "../components/grid";
|
|
461
|
+
import Page from "../components/page";
|
|
462
|
+
import Feature from "../components/feature";
|
|
463
|
+
|
|
464
|
+
import {
|
|
465
|
+
useStoryblokState,
|
|
466
|
+
StoryblokComponent,
|
|
467
|
+
+ setComponents,
|
|
468
|
+
} from "@storyblok/react";
|
|
469
|
+
|
|
470
|
+
export default function Home({
|
|
471
|
+
story: initialStory,
|
|
472
|
+
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
|
473
|
+
|
|
474
|
+
+ setComponents({
|
|
475
|
+
+ teaser: Teaser,
|
|
476
|
+
+ grid: Grid,
|
|
477
|
+
+ feature: Feature,
|
|
478
|
+
+ page: Page,
|
|
479
|
+
+ })
|
|
480
|
+
|
|
481
|
+
const story = useStoryblokState(initialStory);
|
|
482
|
+
|
|
483
|
+
if (!story.content) {
|
|
484
|
+
return <div>Loading...</div>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return <StoryblokComponent blok={story.content} />;
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
428
491
|
## Features and API
|
|
429
492
|
|
|
430
493
|
You can **choose the features to use** when you initialize the plugin. In that way, you can improve Web Performance by optimizing your page load and save some bytes.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("react"),t=require("./storyblok-js-5db94779.js");exports.useStoryblokState=(r=null,o={})=>{let[s,n]=e.useState(r);if(!("undefined"!=typeof window&&void 0!==window.storyblokRegisterEvent)||!r)return r;const i=s.internalId||s.id;return e.useEffect((()=>{n(r),t.ue(i,(e=>n(e)),o)}),[r]),s};
|
|
@@ -6,10 +6,11 @@ const useStoryblokState = (initialStory = null, bridgeOptions = {}) => {
|
|
|
6
6
|
if (!isBridgeEnable || !initialStory) {
|
|
7
7
|
return initialStory;
|
|
8
8
|
}
|
|
9
|
+
const id = story.internalId || story.id;
|
|
9
10
|
useEffect(() => {
|
|
10
11
|
setStory(initialStory);
|
|
11
12
|
ue(
|
|
12
|
-
|
|
13
|
+
id,
|
|
13
14
|
(newStory) => setStory(newStory),
|
|
14
15
|
bridgeOptions
|
|
15
16
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("./storyblok-js-5db94779.js"),e=require("react"),t=e.forwardRef((({blok:o,...t},r)=>{if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),e.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=l(o.component);return n?e.createElement(n,{ref:r,blok:o,...t}):e.createElement("div",null)}));t.displayName="StoryblokComponent";let r=null,n={};const l=o=>n[o]?n[o]:(console.error(`Component ${o} doesn't exist.`),!1);exports.StoryblokComponent=t,exports.getComponent=l,exports.storyblokInit=(e={})=>{const{storyblokApi:t}=o.pe(e);r=t,n=e.components},exports.useStoryblokApi=()=>(r||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),r);
|
|
1
|
+
"use strict";const o=require("./storyblok-js-5db94779.js"),e=require("react"),t=e.forwardRef((({blok:o,...t},r)=>{if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),e.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=l(o.component);return n?e.createElement(n,{ref:r,blok:o,...t}):e.createElement("div",null)}));t.displayName="StoryblokComponent";let r=null,n={};const l=o=>n[o]?n[o]:(console.error(`Component ${o} doesn't exist.`),!1);exports.StoryblokComponent=t,exports.getComponent=l,exports.setComponents=o=>(n=o,n),exports.storyblokInit=(e={})=>{const{storyblokApi:t}=o.pe(e);r=t,n=e.components},exports.useStoryblokApi=()=>(r||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),r);
|
|
@@ -26,6 +26,10 @@ const useStoryblokApi = () => {
|
|
|
26
26
|
}
|
|
27
27
|
return storyblokApiInstance;
|
|
28
28
|
};
|
|
29
|
+
const setComponents = (newComponentsMap) => {
|
|
30
|
+
componentsMap = newComponentsMap;
|
|
31
|
+
return componentsMap;
|
|
32
|
+
};
|
|
29
33
|
const getComponent = (componentKey) => {
|
|
30
34
|
if (!componentsMap[componentKey]) {
|
|
31
35
|
console.error(`Component ${componentKey} doesn't exist.`);
|
|
@@ -40,7 +44,8 @@ const storyblokInit = (pluginOptions = {}) => {
|
|
|
40
44
|
};
|
|
41
45
|
export {
|
|
42
46
|
StoryblokComponent as S,
|
|
47
|
+
storyblokInit as a,
|
|
43
48
|
getComponent as g,
|
|
44
|
-
|
|
49
|
+
setComponents as s,
|
|
45
50
|
useStoryblokApi as u
|
|
46
51
|
};
|
package/dist/storyblok-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),o=require("./storyblok-js-5db94779.js"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),o=require("./storyblok-js-5db94779.js"),t=require("./index-364d653e.js"),r=require("./client-0cdf4d8e.js");exports.RichTextResolver=o.y,exports.RichTextSchema=o.ie,exports.apiPlugin=o.ce,exports.loadStoryblokBridge=o.ge,exports.registerStoryblokBridge=o.ue,exports.renderRichText=o.de,exports.storyblokEditable=o.he,exports.useStoryblokBridge=o.ue,exports.StoryblokComponent=t.StoryblokComponent,exports.getComponent=t.getComponent,exports.getStoryblokApi=t.useStoryblokApi,exports.setComponents=t.setComponents,exports.storyblokInit=t.storyblokInit,exports.useStoryblokApi=t.useStoryblokApi,exports.useStoryblokState=r.useStoryblokState,exports.useStoryblok=(r,s={},i={})=>{const n=t.useStoryblokApi();if(!n)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;let[l,p]=e.useState({});const u="undefined"!=typeof window&&void 0!==window.storyblokRegisterEvent;return e.useEffect((()=>{!async function(){const{data:e}=await n.get(`cdn/stories/${r}`,s);p(e.story),u&&e.story.id&&o.ue(e.story.id,(e=>p(e)),i)}()}),[r,JSON.stringify(s)]),l};
|
package/dist/storyblok-react.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
2
|
import { u as ue } from "./storyblok-js-5fd880b4.mjs";
|
|
3
3
|
import { y, i, c, g, d, h } from "./storyblok-js-5fd880b4.mjs";
|
|
4
|
-
import { u as useStoryblokApi } from "./index-
|
|
5
|
-
import { S, g as g2, s } from "./index-
|
|
6
|
-
import { u } from "./client-
|
|
4
|
+
import { u as useStoryblokApi } from "./index-4af66cd0.mjs";
|
|
5
|
+
import { S, g as g2, s, a } from "./index-4af66cd0.mjs";
|
|
6
|
+
import { u } from "./client-798eb80c.mjs";
|
|
7
7
|
const useStoryblok = (slug, apiOptions = {}, bridgeOptions = {}) => {
|
|
8
8
|
const storyblokApiInstance = useStoryblokApi();
|
|
9
9
|
if (!storyblokApiInstance) {
|
|
@@ -43,8 +43,9 @@ export {
|
|
|
43
43
|
g as loadStoryblokBridge,
|
|
44
44
|
ue as registerStoryblokBridge,
|
|
45
45
|
d as renderRichText,
|
|
46
|
+
s as setComponents,
|
|
46
47
|
h as storyblokEditable,
|
|
47
|
-
|
|
48
|
+
a as storyblokInit,
|
|
48
49
|
useStoryblok,
|
|
49
50
|
useStoryblokApi,
|
|
50
51
|
ue as useStoryblokBridge,
|
package/dist/storyblok-react2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-364d653e.js"),o=require("./storyblok-js-5db94779.js");require("react"),exports.StoryblokComponent=e.StoryblokComponent,exports.getComponent=e.getComponent,exports.getStoryblokApi=e.useStoryblokApi,exports.setComponents=e.setComponents,exports.storyblokInit=e.storyblokInit,exports.useStoryblokApi=e.useStoryblokApi,exports.RichTextResolver=o.y,exports.RichTextSchema=o.ie,exports.apiPlugin=o.ce,exports.loadStoryblokBridge=o.ge,exports.registerStoryblokBridge=o.ue,exports.renderRichText=o.de,exports.storyblokEditable=o.he,exports.useStoryblokBridge=o.ue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S, g, u, s, u as u2 } from "./index-
|
|
1
|
+
import { S, g, u, s, a, u as u2 } from "./index-4af66cd0.mjs";
|
|
2
2
|
import { y, i, c, g as g2, u as u3, d, h, u as u4 } from "./storyblok-js-5fd880b4.mjs";
|
|
3
3
|
import "react";
|
|
4
4
|
export {
|
|
@@ -11,8 +11,9 @@ export {
|
|
|
11
11
|
g2 as loadStoryblokBridge,
|
|
12
12
|
u3 as registerStoryblokBridge,
|
|
13
13
|
d as renderRichText,
|
|
14
|
+
s as setComponents,
|
|
14
15
|
h as storyblokEditable,
|
|
15
|
-
|
|
16
|
+
a as storyblokInit,
|
|
16
17
|
u2 as useStoryblokApi,
|
|
17
18
|
u4 as useStoryblokBridge
|
|
18
19
|
};
|
package/dist/storyblok-react4.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";const e=require("react"),
|
|
1
|
+
"use strict";"use client";const e=require("react"),t=require("./client-0cdf4d8e.js"),r=require("./index-364d653e.js");require("./storyblok-js-5db94779.js");const o=e.forwardRef((({story:o,...n},s)=>("string"==typeof o.content&&(o.content=JSON.parse(o.content)),o=t.useStoryblokState(o),e.createElement(r.StoryblokComponent,{ref:s,blok:o.content,...n}))));module.exports=o;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React, { forwardRef } from "react";
|
|
3
|
-
import { u as useStoryblokState } from "./client-
|
|
4
|
-
import { S as StoryblokComponent } from "./index-
|
|
3
|
+
import { u as useStoryblokState } from "./client-798eb80c.mjs";
|
|
4
|
+
import { S as StoryblokComponent } from "./index-4af66cd0.mjs";
|
|
5
5
|
import "./storyblok-js-5fd880b4.mjs";
|
|
6
6
|
const StoryblokStory = forwardRef(
|
|
7
7
|
({ story, ...restProps }, ref) => {
|
|
8
|
+
if (typeof story.content === "string") {
|
|
9
|
+
story.content = JSON.parse(story.content);
|
|
10
|
+
}
|
|
8
11
|
story = useStoryblokState(story);
|
|
9
12
|
return /* @__PURE__ */ React.createElement(StoryblokComponent, { ref, blok: story.content, ...restProps });
|
|
10
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SbReactSDKOptions, StoryblokClient } from "../types";
|
|
2
|
+
import { SbReactComponentsMap, SbReactSDKOptions, StoryblokClient } from "../types";
|
|
3
3
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
|
+
export declare const setComponents: (newComponentsMap: SbReactComponentsMap) => SbReactComponentsMap;
|
|
4
5
|
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any>;
|
|
5
6
|
export declare const storyblokInit: (pluginOptions?: SbReactSDKOptions) => void;
|
|
6
7
|
export { default as StoryblokComponent } from "./storyblok-component";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/storyblok-react.js",
|
|
6
6
|
"module": "./dist/storyblok-react.mjs",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@storyblok/js": "^2.2.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "^7.22.
|
|
51
|
-
"@babel/preset-env": "^7.22.
|
|
50
|
+
"@babel/core": "^7.22.6",
|
|
51
|
+
"@babel/preset-env": "^7.22.6",
|
|
52
52
|
"@cypress/react": "^5.12.5",
|
|
53
53
|
"@cypress/vite-dev-server": "^2.2.3",
|
|
54
54
|
"@tsconfig/recommended": "^1.0.2",
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
"cypress": "^9.7.0",
|
|
59
59
|
"eslint-plugin-cypress": "^2.13.3",
|
|
60
60
|
"eslint-plugin-jest": "^27.2.2",
|
|
61
|
-
"jest": "^29.
|
|
61
|
+
"jest": "^29.6.0",
|
|
62
62
|
"react": "^18.2.0",
|
|
63
63
|
"react-dom": "^18.2.0",
|
|
64
64
|
"start-server-and-test": "^2.0.0",
|
|
65
|
-
"terser": "^5.18.
|
|
65
|
+
"terser": "^5.18.2",
|
|
66
66
|
"vite": "^4.1.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
package/dist/client-f55c03c7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react"),t=require("./storyblok-js-5db94779.js");exports.useStoryblokState=(r=null,o={})=>{let[s,u]=e.useState(r);return"undefined"!=typeof window&&void 0!==window.storyblokRegisterEvent&&r?(e.useEffect((()=>{u(r),t.ue(s.id,(e=>u(e)),o)}),[r]),s):r};
|