Skip to content
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/nasync-js@0.1.0/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... ");
};
});
}
};
```