JavaScript Plugin API, providing custom panels and column menu items

Thanks, Cameron Yick.

https://github.com/simonw/datasette/pull/2052

Co-authored-by: Simon Willison <swillison@gmail.com>
This commit is contained in:
Cameron Yick 2023-10-12 20:00:27 -04:00 committed by GitHub
commit 452a587e23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 399 additions and 19 deletions

View file

@ -0,0 +1,21 @@
from datasette import hookimpl
# Test command:
# datasette fixtures.db \ --plugins-dir=demos/plugins/
# \ --static static:demos/plugins/static
# Create a set with view names that qualify for this JS, since plugins won't do anything on other pages
# Same pattern as in Nteract data explorer
# https://github.com/hydrosquall/datasette-nteract-data-explorer/blob/main/datasette_nteract_data_explorer/__init__.py#L77
PERMITTED_VIEWS = {"table", "query", "database"}
@hookimpl
def extra_js_urls(view_name):
print(view_name)
if view_name in PERMITTED_VIEWS:
return [
{
"url": f"/static/table-example-plugins.js",
}
]