@@ -6,16 +6,18 @@ import {
6
6
StoryData ,
7
7
SbInitResult ,
8
8
Richtext ,
9
- StoryblokComponentType
9
+ StoryblokComponentType ,
10
10
} from "./types" ;
11
11
12
- import RichTextResolver from "storyblok-js-client/source/richTextResolver"
12
+ import RichTextResolver from "storyblok-js-client/source/richTextResolver" ;
13
13
14
- const resolver = new RichTextResolver ;
14
+ const resolver = new RichTextResolver ( ) ;
15
15
16
16
const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js" ;
17
17
18
- export const useStoryblokBridge = < T extends StoryblokComponentType < string > = any > (
18
+ export const useStoryblokBridge = <
19
+ T extends StoryblokComponentType < string > = any
20
+ > (
19
21
id : Number ,
20
22
cb : ( newStory : StoryData < T > ) => void ,
21
23
options : StoryblokBridgeConfigV2 = { }
@@ -40,10 +42,9 @@ export const useStoryblokBridge = <T extends StoryblokComponentType<string> = an
40
42
window . storyblokRegisterEvent ( ( ) => {
41
43
const sbBridge : StoryblokBridgeV2 = new window . StoryblokBridge ( options ) ;
42
44
sbBridge . on ( [ "input" , "published" , "change" ] , ( event ) => {
43
- if ( event . action == "input" && event . story . id === id ) {
44
- cb ( event . story ) ;
45
- } else {
46
- window . location . reload ( ) ;
45
+ if ( event . story . id === id ) {
46
+ if ( event . action === "input" ) cb ( event . story ) ;
47
+ else window . location . reload ( ) ;
47
48
}
48
49
} ) ;
49
50
} ) ;
@@ -73,20 +74,19 @@ export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => {
73
74
return result ;
74
75
} ;
75
76
76
- export const renderRichText = ( text : Richtext ) : string => {
77
- if ( text as any === '' ) {
78
- return ""
79
- }
80
- else if ( ! text ) {
77
+ export const renderRichText = ( text : Richtext ) : string => {
78
+ if ( ( text as any ) === "" ) {
79
+ return "" ;
80
+ } else if ( ! text ) {
81
81
console . warn ( `${ text } is not a valid Richtext object. This might be because the value of the richtext field is empty.
82
82
83
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text` )
84
- return "" ;
83
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text` ) ;
84
+ return "" ;
85
85
}
86
- return resolver . render ( text )
87
- }
86
+ return resolver . render ( text ) ;
87
+ } ;
88
88
89
- export const loadStoryblokBridge = ( ) => loadBridge ( bridgeLatest )
89
+ export const loadStoryblokBridge = ( ) => loadBridge ( bridgeLatest ) ;
90
90
91
91
// Reexport all types so users can have access to them
92
92
export * from "./types" ;
0 commit comments