@storyblok/react 2.3.4 → 2.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.
- package/README.md +10 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +27 -25
- package/dist/index2.js +1 -1
- package/dist/index2.mjs +24 -22
- package/dist/rsc.js +1 -1
- package/dist/rsc.mjs +22 -20
- package/dist/storyblok-component.js +1 -1
- package/dist/storyblok-component.mjs +16 -10
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,16 +63,20 @@ import { storyblokInit, apiPlugin } from "@storyblok/react";
|
|
|
63
63
|
/** Import your components */
|
|
64
64
|
import Page from "./components/Page";
|
|
65
65
|
import Teaser from "./components/Teaser";
|
|
66
|
+
// import FallbackComponent from "./components/FallbackComponent";
|
|
66
67
|
|
|
67
68
|
storyblokInit({
|
|
68
69
|
accessToken: "YOUR_ACCESS_TOKEN",
|
|
69
70
|
use: [apiPlugin],
|
|
70
|
-
// bridge: false,
|
|
71
|
-
// apiOptions: {},
|
|
72
71
|
components: {
|
|
73
72
|
page: Page,
|
|
74
73
|
teaser: Teaser,
|
|
75
74
|
},
|
|
75
|
+
// bridge: false,
|
|
76
|
+
// apiOptions: {},
|
|
77
|
+
// richText: {},
|
|
78
|
+
// enableFallbackComponent: false,
|
|
79
|
+
// customFallbackComponent: FallbackComponent,
|
|
76
80
|
});
|
|
77
81
|
```
|
|
78
82
|
|
|
@@ -591,6 +595,10 @@ renderRichText(blok.richTextField, {
|
|
|
591
595
|
|
|
592
596
|
We also recommend using the [Storyblok Rich Text Renderer for React by Claus](https://github.com/claus/storyblok-rich-text-react-renderer) for rendering your Storyblok rich text content to React elements and Next.js applications.
|
|
593
597
|
|
|
598
|
+
### Using fallback components
|
|
599
|
+
|
|
600
|
+
By default, `@storyblok/react` returns an empty `<div>` if a component is not implemented. Setting `enableFallbackComponent` to `true` when calling `storyblokInit` bypasses that behavior, rendering a fallback component in the frontend instead. You can use the default fallback component, or create a custom React fallback component in your project and use it by setting `customFallbackComponent: [YourFallbackComponent]`.
|
|
601
|
+
|
|
594
602
|
## The Storyblok JavaScript SDK Ecosystem
|
|
595
603
|
|
|
596
604
|

|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./client.js"),S=require("./storyblok-component.js"),d=(n,r={},t={})=>{const s=o.useStoryblokApi();if(!s)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;let[a,i]=y.useState({});t.resolveRelations=t.resolveRelations??r.resolve_relations,t.resolveLinks=t.resolveLinks??r.resolve_links;const b=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return y.useEffect(()=>{async function k(){const{data:l}=await s.get(`cdn/stories/${n}`,r);i(l.story),b&&l.story.id&&e.registerStoryblokBridge(l.story.id,u=>i(u),t)}k()},[n,JSON.stringify(r)]),a};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;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.useStoryblokState=c.useStoryblokState;exports.StoryblokComponent=S;exports.useStoryblok=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useState as f, useEffect as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
import { RichTextResolver as v, RichTextSchema as x, apiPlugin as R, loadStoryblokBridge as
|
|
4
|
-
import { useStoryblokApi as
|
|
5
|
-
import { getComponent as A, setComponents as
|
|
6
|
-
import { useStoryblokState as
|
|
7
|
-
import { default as
|
|
1
|
+
import { useState as f, useEffect as k } from "react";
|
|
2
|
+
import { registerStoryblokBridge as u } from "./storyblok-js.mjs";
|
|
3
|
+
import { RichTextResolver as v, RichTextSchema as x, apiPlugin as R, loadStoryblokBridge as C, renderRichText as w, storyblokEditable as B } from "./storyblok-js.mjs";
|
|
4
|
+
import { useStoryblokApi as c } from "./index2.mjs";
|
|
5
|
+
import { getComponent as h, getCustomFallbackComponent as A, getEnableFallbackComponent as T, setComponents as F, storyblokInit as I } from "./index2.mjs";
|
|
6
|
+
import { useStoryblokState as P } from "./client.mjs";
|
|
7
|
+
import { default as J } from "./storyblok-component.mjs";
|
|
8
8
|
const b = (r, e = {}, o = {}) => {
|
|
9
|
-
const s =
|
|
9
|
+
const s = c();
|
|
10
10
|
if (!s)
|
|
11
11
|
return console.error(
|
|
12
12
|
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
@@ -14,36 +14,38 @@ const b = (r, e = {}, o = {}) => {
|
|
|
14
14
|
let [l, n] = f({});
|
|
15
15
|
o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links;
|
|
16
16
|
const i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
|
|
17
|
-
return
|
|
18
|
-
async function
|
|
17
|
+
return k(() => {
|
|
18
|
+
async function a() {
|
|
19
19
|
const { data: t } = await s.get(
|
|
20
20
|
`cdn/stories/${r}`,
|
|
21
21
|
e
|
|
22
22
|
);
|
|
23
|
-
n(t.story), i && t.story.id &&
|
|
23
|
+
n(t.story), i && t.story.id && u(
|
|
24
24
|
t.story.id,
|
|
25
|
-
(
|
|
25
|
+
(y) => n(y),
|
|
26
26
|
o
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
a();
|
|
30
30
|
}, [r, JSON.stringify(e)]), l;
|
|
31
31
|
};
|
|
32
32
|
export {
|
|
33
33
|
v as RichTextResolver,
|
|
34
34
|
x as RichTextSchema,
|
|
35
|
-
|
|
35
|
+
J as StoryblokComponent,
|
|
36
36
|
R as apiPlugin,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
h as getComponent,
|
|
38
|
+
A as getCustomFallbackComponent,
|
|
39
|
+
T as getEnableFallbackComponent,
|
|
40
|
+
c as getStoryblokApi,
|
|
41
|
+
C as loadStoryblokBridge,
|
|
42
|
+
u as registerStoryblokBridge,
|
|
43
|
+
w as renderRichText,
|
|
44
|
+
F as setComponents,
|
|
45
|
+
B as storyblokEditable,
|
|
46
|
+
I as storyblokInit,
|
|
45
47
|
b as useStoryblok,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
c as useStoryblokApi,
|
|
49
|
+
u as useStoryblokBridge,
|
|
50
|
+
P as useStoryblokState
|
|
49
51
|
};
|
package/dist/index2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./storyblok-js.js"),b=require("./storyblok-component.js");let l=null,t={},n=!1,r=null;const s=()=>(l||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),l),i=o=>(t=o,t),c=o=>t[o]?t[o]:(console.error(`Component ${o} doesn't exist.`),!1),k=()=>n,m=()=>r,u=(o={})=>{const{storyblokApi:a}=e.storyblokInit(o);l=a,t=o.components,n=o.enableFallbackComponent,r=o.customFallbackComponent};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;exports.StoryblokComponent=b;exports.getComponent=c;exports.getCustomFallbackComponent=m;exports.getEnableFallbackComponent=k;exports.getStoryblokApi=s;exports.setComponents=i;exports.storyblokInit=u;exports.useStoryblokApi=s;
|
package/dist/index2.mjs
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import { storyblokInit as
|
|
2
|
-
import { RichTextResolver as
|
|
3
|
-
import { default as
|
|
4
|
-
let
|
|
5
|
-
const
|
|
1
|
+
import { storyblokInit as s } from "./storyblok-js.mjs";
|
|
2
|
+
import { RichTextResolver as g, RichTextSchema as C, apiPlugin as d, loadStoryblokBridge as f, registerStoryblokBridge as S, renderRichText as x, storyblokEditable as F, registerStoryblokBridge as A } from "./storyblok-js.mjs";
|
|
3
|
+
import { default as B } from "./storyblok-component.mjs";
|
|
4
|
+
let t = null, e = {}, r = !1, l = null;
|
|
5
|
+
const b = () => (t || console.error(
|
|
6
6
|
"You can't use getStoryblokApi if you're not loading apiPlugin."
|
|
7
|
-
),
|
|
8
|
-
const { storyblokApi:
|
|
9
|
-
e = r,
|
|
7
|
+
), t), c = (o) => (e = o, e), i = (o) => e[o] ? e[o] : (console.error(`Component ${o} doesn't exist.`), !1), k = () => r, m = () => l, p = (o = {}) => {
|
|
8
|
+
const { storyblokApi: n } = s(o);
|
|
9
|
+
t = n, e = o.components, r = o.enableFallbackComponent, l = o.customFallbackComponent;
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
g as RichTextResolver,
|
|
13
|
+
C as RichTextSchema,
|
|
14
|
+
B as StoryblokComponent,
|
|
15
|
+
d as apiPlugin,
|
|
16
|
+
i as getComponent,
|
|
17
|
+
m as getCustomFallbackComponent,
|
|
18
|
+
k as getEnableFallbackComponent,
|
|
19
|
+
b as getStoryblokApi,
|
|
20
|
+
f as loadStoryblokBridge,
|
|
21
|
+
S as registerStoryblokBridge,
|
|
22
|
+
x as renderRichText,
|
|
23
|
+
c as setComponents,
|
|
24
|
+
F as storyblokEditable,
|
|
25
|
+
p as storyblokInit,
|
|
26
|
+
b as useStoryblokApi,
|
|
27
|
+
A as useStoryblokBridge
|
|
26
28
|
};
|
package/dist/rsc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index2.js"),t=require("./story.js"),r=require("./bridge-loader.js"),l=require("./storyblok-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.BridgeLoader=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;
|
package/dist/rsc.mjs
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { getComponent as r, useStoryblokApi as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { RichTextResolver as
|
|
1
|
+
import { getComponent as t, getCustomFallbackComponent as r, getEnableFallbackComponent as l, useStoryblokApi as a, setComponents as i, storyblokInit as s, useStoryblokApi as b } from "./index2.mjs";
|
|
2
|
+
import { default as p } from "./story.mjs";
|
|
3
|
+
import { default as d } from "./bridge-loader.mjs";
|
|
4
|
+
import { default as m } from "./storyblok-component.mjs";
|
|
5
|
+
import { RichTextResolver as S, RichTextSchema as f, apiPlugin as u, loadStoryblokBridge as x, registerStoryblokBridge as c, renderRichText as C, storyblokEditable as B, registerStoryblokBridge as h } from "./storyblok-js.mjs";
|
|
6
6
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
d as BridgeLoader,
|
|
8
|
+
S as RichTextResolver,
|
|
9
|
+
f as RichTextSchema,
|
|
10
|
+
m as StoryblokComponent,
|
|
11
|
+
p as StoryblokStory,
|
|
12
|
+
u as apiPlugin,
|
|
13
|
+
t as getComponent,
|
|
14
|
+
r as getCustomFallbackComponent,
|
|
15
|
+
l as getEnableFallbackComponent,
|
|
16
|
+
a as getStoryblokApi,
|
|
17
|
+
x as loadStoryblokBridge,
|
|
18
|
+
c as registerStoryblokBridge,
|
|
19
|
+
C as renderRichText,
|
|
20
|
+
i as setComponents,
|
|
19
21
|
B as storyblokEditable,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
s as storyblokInit,
|
|
23
|
+
b as useStoryblokApi,
|
|
24
|
+
h as useStoryblokBridge
|
|
23
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react"),
|
|
1
|
+
"use strict";const e=require("react"),o=require("./index2.js"),c=e.forwardRef(({blok:t,...n},a)=>{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:a,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;
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getComponent as
|
|
3
|
-
const
|
|
4
|
-
({ blok:
|
|
5
|
-
if (!
|
|
1
|
+
import e, { forwardRef as m } from "react";
|
|
2
|
+
import { getComponent as a, getEnableFallbackComponent as p, getCustomFallbackComponent as c } from "./index2.mjs";
|
|
3
|
+
const u = m(
|
|
4
|
+
({ blok: t, ...o }, l) => {
|
|
5
|
+
if (!t)
|
|
6
6
|
return console.error(
|
|
7
7
|
"Please provide a 'blok' property to the StoryblokComponent"
|
|
8
|
-
), /* @__PURE__ */
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
), /* @__PURE__ */ e.createElement("div", null, "Please provide a blok property to the StoryblokComponent");
|
|
9
|
+
const n = a(t.component);
|
|
10
|
+
if (n)
|
|
11
|
+
return /* @__PURE__ */ e.createElement(n, { ref: l, blok: t, ...o });
|
|
12
|
+
if (p()) {
|
|
13
|
+
const r = c();
|
|
14
|
+
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?"));
|
|
15
|
+
}
|
|
16
|
+
return /* @__PURE__ */ e.createElement("div", null);
|
|
11
17
|
}
|
|
12
18
|
);
|
|
13
|
-
|
|
19
|
+
u.displayName = "StoryblokComponent";
|
|
14
20
|
export {
|
|
15
|
-
|
|
21
|
+
u as default
|
|
16
22
|
};
|
|
@@ -3,6 +3,8 @@ import { SbReactComponentsMap, SbReactSDKOptions, StoryblokClient } from "../typ
|
|
|
3
3
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
4
|
export declare const setComponents: (newComponentsMap: SbReactComponentsMap) => SbReactComponentsMap;
|
|
5
5
|
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any>;
|
|
6
|
+
export declare const getEnableFallbackComponent: () => boolean;
|
|
7
|
+
export declare const getCustomFallbackComponent: () => import("react").ElementType<any>;
|
|
6
8
|
export declare const storyblokInit: (pluginOptions?: SbReactSDKOptions) => void;
|
|
7
9
|
export { default as StoryblokComponent } from "./storyblok-component";
|
|
8
10
|
export { useStoryblokApi as getStoryblokApi };
|
package/dist/types/types.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface SbReactComponentsMap {
|
|
|
6
6
|
}
|
|
7
7
|
export interface SbReactSDKOptions extends SbSDKOptions {
|
|
8
8
|
components?: SbReactComponentsMap;
|
|
9
|
+
enableFallbackComponent?: boolean;
|
|
10
|
+
customFallbackComponent?: React.ElementType;
|
|
9
11
|
}
|
|
10
12
|
export type TUseStoryblokState = <T = void>(initialStory: ISbStoryData<T> | null, bridgeOptions?: StoryblokBridgeConfigV2) => ISbStoryData<T> | null;
|
|
11
13
|
export type { ISbConfig, ISbCache, ISbResult, ISbResponse, ISbError, ISbNode, ISbSchema, ThrottleFn, AsyncFn, ArrayFn, ISbContentMangmntAPI, ISbManagmentApiResult, ISbStories, ISbStory, ISbDimensions, ISbStoryData, ISbAlternateObject, ISbStoriesParams, ISbStoryParams, ISbRichtext, SbBlokData, SbBlokKeyDataTypes, SbRichTextOptions, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, useStoryblokBridge, } from "@storyblok/js";
|