Skip to content

Commit

Permalink
Adding "custom widget builder" widget (#141)
Browse files Browse the repository at this point in the history
Simple widget editor (based on monaco editor), that can edit and serve widgets right from the Grist document.

PR:
#141
  • Loading branch information
berhalak authored Oct 11, 2024
1 parent b7d7579 commit 1659c92
Show file tree
Hide file tree
Showing 9 changed files with 2,263 additions and 9 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ Next start Grist with an URL pointing to a local widget manifest file:
```bash
GRIST_WIDGET_LIST_URL=http://localhost:8585/manifest.json npm start
```

Alternatively you can run the widget repository development server alongside with the Grist docker image preconfigured to use it:

```bash
yarn run grist:serve
```

or run it in development mode with automatic reload:

```bash
yarn install
yarn run grist:dev
```
38 changes: 38 additions & 0 deletions custom-widget-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Grist Custom Widget

This widget enables you to create other custom widgets for Grist documents, right inside Grist that are hosted by Grist itself.

## Getting Started

To begin developing your custom widget, follow these steps:

1. **Open the Widget Editor:** Click on the "Open configuration" button in the creator panel or clear the saved filter settings for the relevant tab.
2. **Edit Code:** Write your widget's logic in the JavaScript tab and structure its appearance in the HTML tab.
3. **Preview and Install:** Click the "Preview" button to see your widget in action. This will save the widget's code to the document's metadata.
4. **Save Configuration:** Press the "Save" button to persist the widget settings to ensure they remain active after refreshing the page.

**Note:** There is no autosave feature, so always remember to save your configuration manually.

## Data Storage

The widget's configuration data is stored in the widget's metadata using the following format:

```javascript
const options = {
_installed: true,
_js: `...your JavaScript code...`,
_html: `...your HTML code...`,
};
grist.setOptions(options);
```

In the final widget, the <code>_html</code> field is inserted as is into an iframe, and the <code>_js</code> field is embedded within a script tag afterwards.

This widget in itself doesn't require any access to documents metadata, but it can be used to create widgets that do. Storing <code>Javascript</code> and <code>HTML</code> code in the metadata stores it only temporarily. User needs to save it in order to persist the changes (just like for regular <code>filters</code>).

Any contribution is welcome, the big thing missing is dark mode support.


## IntelliSense

The widget editor supports `IntelliSense` for the `JavaScript` code. It does it by providing its own types definitions directly to the Monaco editor. The IntelliSense is based on the official Grist Plugin API. See the `genarate.js` script for more details.
Loading

0 comments on commit 1659c92

Please sign in to comment.