5
5
RuntimeContext ,
6
6
} from '@gitbook/runtime' ;
7
7
8
- const defaultContent = ' ';
8
+ import { createProject } from './stackblitz ';
9
9
10
10
type IntegrationContext = { } & RuntimeContext ;
11
11
@@ -17,67 +17,33 @@ const handleFetchEvent: FetchEventCallback<IntegrationContext> = async (request,
17
17
return new Response ( JSON . stringify ( user ) ) ;
18
18
} ;
19
19
20
- const stackblitzBlock = createComponent <
21
- {
22
- content ?: string ;
23
- } ,
24
- {
25
- content : string ;
26
- }
27
- > ( {
20
+ const exampleBlock = createComponent ( {
28
21
componentId : 'stackblitz' ,
29
22
initialState : ( props ) => {
30
23
return {
31
- content : props . content || defaultContent ,
24
+ message : 'Click Me' ,
32
25
} ;
33
26
} ,
34
- async render ( element , { environment } ) {
35
- const { editable } = element . context ;
36
- const { content } = element . state ;
37
-
38
- element . setCache ( {
39
- maxAge : 86400 ,
40
- } ) ;
41
-
42
- const output = (
43
- < webframe
44
- source = { {
45
- // url: environment.integration.urls.publicEndpoint,
46
- // TODO: Remove hardcoded example
47
- url : 'https://stackblitz.com/edit/simple-search-filter?embed=1&file=src%2Fapp%2Fapp.component.ts' ,
48
- } }
49
- aspectRatio = { 16 / 9 }
50
- data = { {
51
- content : element . dynamicState ( 'content' ) ,
52
- } }
53
- />
54
- ) ;
55
-
27
+ action : async ( element , action , context ) => {
28
+ switch ( action . action ) {
29
+ case 'click' :
30
+ console . log ( 'Button Clicked' ) ;
31
+ return { } ;
32
+ }
33
+ } ,
34
+ render : async ( element , action , context ) => {
35
+ console . log ( 'RENDER' ) ;
36
+ await createProject ( ) ;
56
37
return (
57
38
< block >
58
- { editable ? (
59
- < codeblock
60
- state = "content"
61
- content = { content }
62
- syntax = "stackblitz"
63
- onContentChange = { {
64
- action : '@editor.node.updateProps' ,
65
- props : {
66
- content : element . dynamicState ( 'content' ) ,
67
- } ,
68
- } }
69
- footer = { [ output ] }
70
- />
71
- ) : (
72
- output
73
- ) }
39
+ < button label = { element . state . message } onPress = { { action : 'click' } } />
74
40
</ block >
75
41
) ;
76
42
} ,
77
43
} ) ;
78
44
79
45
export default createIntegration ( {
80
46
fetch : handleFetchEvent ,
81
- components : [ stackblitzBlock ] ,
47
+ components : [ exampleBlock ] ,
82
48
events : { } ,
83
49
} ) ;
0 commit comments