@@ -4,7 +4,7 @@ Now you can integrate our code cells into your webapps and run AO LUA anywhere
4
4
5
5
[ ![ npm] ( https://img.shields.io/badge/@betteridea/codecell-npm-red )] ( https://www.npmjs.com/package/@betteridea/codecell )
6
6
[ ![ downloads] ( https://img.shields.io/npm/dt/@betteridea/codecell?color=red )] ( https://www.npmjs.com/package/@betteridea/codecell )
7
- [ ![ X Follow] ( https://img.shields.io/twitter/follow/betteridea-dev )] ( https://twitter.com/betteridea-dev )
7
+ [ ![ X Follow] ( https://img.shields.io/twitter/follow/betteridea_dev )] ( https://twitter.com/betteridea_dev )
8
8
9
9
10
10
## Installation
@@ -15,34 +15,39 @@ npm install @betteridea/codecell
15
15
16
16
## API
17
17
18
- ### ` CodeCell `
18
+ ### ` < CodeCell .../> `
19
19
20
20
A react component to render a code cell in your app.
21
21
22
22
#### Props
23
23
24
- - ` cellId ` - Unique id for the cell
25
- - ` appName ` - Unique app name
26
- - ` code ` - Initial code for the cell
27
- - ` width ` - Width of the cell
28
- - ` height ` - Height of the cell
29
- - ` className ` - Class names for styling
30
- - ` style ` - Inline styles
31
- - ` devMode ` - Boolean to enable dev mode
24
+ | Prop | Type | Description |
25
+ | ------------- | ---------------------- | ------------------------------------------------------------------ |
26
+ | ` cellId ` | ` string ` | Unique id for the cell |
27
+ | ` appName ` | ` string ` | Unique app name |
28
+ | ` code ` | ` string ` | Initial code for the cell |
29
+ | ` onAOProcess ` | ` (pid:string) => void ` | Callback function that gets called whenever a process is is loaded |
30
+ | ` width ` | ` string ` | Width of the cell |
31
+ | ` height ` | ` string ` | Height of the cell |
32
+ | ` className ` | ` string ` | Class names for styling |
33
+ | ` style ` | ` React.CSSProperties ` | Inline styles |
34
+ | ` devMode ` | ` boolean ` | Boolean to enable dev mode |
32
35
33
- ### ` setCellCode `
36
+ ### ` setCellCode(...) `
34
37
35
38
To update the code in a cell, after it has been rendered.
36
- It is discouraged to update code by changing the ` code ` prop directly, since it re-renders the iframe , again this is personal preference.
39
+ It is discouraged to update code by changing the ` code ` prop directly, since it re-renders the webview , again this is personal preference.
37
40
38
41
#### Arguments
39
42
40
- - ` cellId ` - Unique id of the cell
41
- - ` code ` - Code to set in the cell
42
- - ` devMode ` - Boolean to enable dev mode
43
+ | Argument | Type | Description |
44
+ | --------- | --------- | -------------------------- |
45
+ | ` cellId ` | ` string ` | Unique id of the cell |
46
+ | ` code ` | ` string ` | Code to set in the cell |
47
+ | ` devMode ` | ` boolean ` | Boolean to enable dev mode |
43
48
44
49
45
- ### ~~ ` runCell ` ~~ (deprecated due to security reasons)
50
+ ### ~~ ` runCell(...) ` ~~ (deprecated due to security reasons)
46
51
47
52
~~ To run the code in a cell, after it has been rendered (optional, since the cell already has a run button)~~
48
53
@@ -54,38 +59,47 @@ It is discouraged to update code by changing the `code` prop directly, since it
54
59
## Usage
55
60
56
61
``` javascript
57
- import { CodeCell , runCell } from ' @betteridea/codecell' ;
62
+ import { CodeCell } from ' @betteridea/codecell' ;
58
63
59
64
// in your react app
60
65
< CodeCell
61
66
cellId= " 1" // any unique cell id
62
67
appName= " BetterIDEa-Code-Cell" // Your unique app name
63
68
code= " print('Portable code cell ftw!')" // initial code (optional)
69
+ onAOProcess= {(pid ) => console .log (" using process: " ,pid)} // print the process id whenever it loads
64
70
/ >
65
71
```
66
72
67
- ~~ To run code from external sources , you can use the ` runCell ` function.~~ (deprecated due to security reasons)
73
+ To update the cell with a different code snippet , you can use the ` setCellCode ` function.
68
74
69
75
``` javascript
70
- import { runCell } from ' @betteridea/codecell' ;
76
+ import { setCellCode } from ' @betteridea/codecell' ;
71
77
72
78
...
73
79
74
- // This will run whatever code is typed in the cell with the id provided
75
- runCell (" 1" );
80
+ // This will update the code in the cell with the id provided
81
+ setCellCode (" 1" , " print('Updated code!') " );
76
82
```
77
83
78
- To update the cell with a different code snippet, you can use the ` setCellCode ` function.
84
+ <details >
85
+ <summary >Deprecation Warning</summary >
86
+
87
+ ** runCell() function has been deprecated due to security reasons, since it might be possible anyone can run some mischevious code in your process without you knowing.**
88
+
89
+ To run code from external sources, you can use the ` runCell ` function.
79
90
80
91
``` javascript
81
- import { setCellCode } from ' @betteridea/codecell' ;
92
+ import { runCell } from ' @betteridea/codecell' ;
82
93
83
94
...
84
95
85
- // This will update the code in the cell with the id provided
86
- setCellCode (" 1" , " print('Updated code!') " );
96
+ // This will run whatever code is typed in the cell with the id provided
97
+ runCell (" 1" );
87
98
```
88
99
100
+ </details >
101
+
102
+
89
103
## Developing
90
104
91
105
To start the vite development server, run:
@@ -98,10 +112,10 @@ npm run dev
98
112
99
113
then make changes to the component and run function and test them in the vite app at [ http://localhost:5173 ] ( http://localhost:5173 )
100
114
101
- 1 . ` CodeCell ` component -> [ ./src/components/CodeCell.tsx] ( https://github.com/betteridea-dev/ide /blob/main/packages/codecell /src/components/codecell.tsx )
115
+ 1 . ` CodeCell ` component -> [ ./src/components/CodeCell.tsx] ( https://github.com/betteridea-dev/codecell /blob/main/src/components/codecell.tsx )
102
116
103
- 2 . ` runCell ` function -> [ ./src/lib/runCell.ts ] ( https://github.com/betteridea-dev/ide/blob /main/packages/codecell/ src/lib/runCell.ts )
117
+ 2 . Library functions -> [ ./src/lib] ( https://github.com/betteridea-dev/codecell/tree /main/src/lib )
104
118
105
- Both are essentially a wrapper around https://ide.betteridea.dev /codecell page from the main [ IDE ] ( https://ide. betteridea. dev ) to run the code in any webapp through an iframe.
119
+ 3 . ` /codecell ` webview -> [ next_app/src/pages /codecell.tsx ] ( https://github.com/ betteridea- dev/ide/blob/main/next_app/src/pages/codecell.tsx )
106
120
107
- ` /codecell ` -> [ next_app/src/pages /codecell.tsx ] ( https://github.com/ betteridea-dev/ide/blob/main/next_app/src/pages/codecell.tsx )
121
+ The package is essentially a wrapper around https://ide.betteridea.dev /codecell route from the main [ IDE ] ( https://ide. betteridea.dev ) to run code in any webapp through a webview.
0 commit comments