@@ -4,7 +4,7 @@ Now you can integrate our code cells into your webapps and run AO LUA anywhere
44
55[ ![ npm] ( https://img.shields.io/badge/@betteridea/codecell-npm-red )] ( https://www.npmjs.com/package/@betteridea/codecell )
66[ ![ 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 )
88
99
1010## Installation
@@ -15,34 +15,39 @@ npm install @betteridea/codecell
1515
1616## API
1717
18- ### ` CodeCell `
18+ ### ` < CodeCell .../> `
1919
2020A react component to render a code cell in your app.
2121
2222#### Props
2323
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 |
3235
33- ### ` setCellCode `
36+ ### ` setCellCode(...) `
3437
3538To 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.
3740
3841#### Arguments
3942
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 |
4348
4449
45- ### ~~ ` runCell ` ~~ (deprecated due to security reasons)
50+ ### ~~ ` runCell(...) ` ~~ (deprecated due to security reasons)
4651
4752~~ To run the code in a cell, after it has been rendered (optional, since the cell already has a run button)~~
4853
@@ -54,38 +59,47 @@ It is discouraged to update code by changing the `code` prop directly, since it
5459## Usage
5560
5661``` javascript
57- import { CodeCell , runCell } from ' @betteridea/codecell' ;
62+ import { CodeCell } from ' @betteridea/codecell' ;
5863
5964// in your react app
6065< CodeCell
6166 cellId= " 1" // any unique cell id
6267 appName= " BetterIDEa-Code-Cell" // Your unique app name
6368 code= " print('Portable code cell ftw!')" // initial code (optional)
69+ onAOProcess= {(pid ) => console .log (" using process: " ,pid)} // print the process id whenever it loads
6470/ >
6571```
6672
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.
6874
6975``` javascript
70- import { runCell } from ' @betteridea/codecell' ;
76+ import { setCellCode } from ' @betteridea/codecell' ;
7177
7278...
7379
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!') " );
7682```
7783
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.
7990
8091``` javascript
81- import { setCellCode } from ' @betteridea/codecell' ;
92+ import { runCell } from ' @betteridea/codecell' ;
8293
8394...
8495
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" );
8798```
8899
100+ </details >
101+
102+
89103## Developing
90104
91105To start the vite development server, run:
@@ -98,10 +112,10 @@ npm run dev
98112
99113then make changes to the component and run function and test them in the vite app at [ http://localhost:5173 ] ( http://localhost:5173 )
100114
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 )
102116
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 )
104118
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 )
106120
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