Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic plugin example #54

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# How to add a plugin to a Starboard Notebook

When initializing a Starboard Notebook, you can specify which plugins to load in the header of the notebook content. For example:

```
---
starboard:
plugins:
- src: "https://someserver/noNewCellsPlugin/index.js"
args: [1,2 ]
- src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js"
---
```

*Note if you are loading a plugin from a different origin than your notebook, the plugin server will have to allow for cross origin requests from your notebook's domain.

# A simple plugin

A pretty minimal plugin for starboard may look like this:

noNewCellsPlugin/src/index.ts
```
export const plugin = {
id: "unhott-hates-new-cells",
metadata: {
name: "NoNewCellsPlugin (or some other human friendly name)",
},
exports: {},
async register(runtime: Runtime, opts: {}) {
runtime.dom.notebook.addEventListener("sb:remove_cell", (event) => {
console.log("This is perfectly fine... ");
});
runtime.dom.notebook.addEventListener("sb:insert_cell", (event) => {
console.log("Haha, no cell for you! ");
event.preventDefault();
});
runtime.dom.notebook.addEventListener("sb:set_cell_property", (event) => {
if (event.detail.property == 'locked') {
event.preventDefault();
console.log("I'm sorry, I can't let you do that... ");
};
});
}
};
```