-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
261 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Plugins | ||
|
||
A powerful concept that TypeCell explores is _End User Programming_. In TypeCell, it's possible to customize the program you're using (a Notion-style document editor) with new capabilities, _right from within the application itself_. This means you can modify the way TypeCell works, without changing the source code, but just by creating new code in TypeCell code blocks. | ||
|
||
## Map block | ||
|
||
When using software like Notion, Google Docs, or Word, you're limited to the blocks they provide (paragraphs, images, lists, tables, etc.). What if you want to add an interactive map, or chart to your document? Let's explore how this can be done in TypeCell. | ||
|
||
Let's first set up the code to render a Map, based on _react-map-gl_. | ||
|
||
### Map code | ||
|
||
First, let's set up some reactive variables for our map component: | ||
|
||
```typescript | ||
export let zoom = 1; | ||
export let latitude = 1; | ||
export let longitude = 1; | ||
export let markers: Array<{ | ||
latitude: number; | ||
longitude: number; | ||
color: string; | ||
text: string; | ||
}> = []; | ||
``` | ||
|
||
And import the required CSS stylesheet: | ||
|
||
```typescript | ||
import css from "maplibre-gl/dist/maplibre-gl.css"; | ||
export { css }; | ||
``` | ||
|
||
Now, let's create the main code that renders our map component: | ||
|
||
```typescript | ||
import MapLibre, { Marker, Source, Layer, Popup } from "react-map-gl/maplibre"; | ||
import maplibregl from "maplibre-gl"; | ||
|
||
export const map = ( | ||
<div style={{ width: 700, height: 400 }}> | ||
<MapLibre | ||
onMove={(e) => { | ||
$.zoom = e.viewState.zoom; | ||
$.latitude = e.viewState.latitude; | ||
$.longitude = e.viewState.longitude; | ||
}} | ||
longitude={$.longitude} | ||
latitude={$.latitude} | ||
zoom={$.zoom} | ||
mapStyle="https://demotiles.maplibre.org/style.json"> | ||
{$.markers.map((m, i) => ( | ||
<Marker | ||
key={i} | ||
latitude={m.latitude} | ||
longitude={m.longitude} | ||
color={m.color} | ||
popup={m.text ? new maplibregl.Popup().setText(m.text) : undefined} | ||
/> | ||
))} | ||
</MapLibre> | ||
</div> | ||
); | ||
``` | ||
|
||
### Register a plugin | ||
|
||
```typescript | ||
// Plugin registration | ||
typecell.editor.registerBlock({ | ||
name: "Map", | ||
blockVariable: "map", | ||
settings: { | ||
latitude: true, | ||
longitude: true, | ||
zoom: true, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.