Add editor notes to the docs (#3832)

People just don't know that they need to put the components using
useEditor inside the <tldraw> component as a children

Either it is defined somewhere else or not defined at all, so it will
really help those.

Describe what your pull request does. If appropriate, add GIFs or images
showing the before and after.

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [ ] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [X] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [ ] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [X] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know


### Test Plan [No need]

1. Add a step-by-step description of how to test your PR here.
2.

- [ ] Unit Tests
- [ ] End to end tests

### Release Notes [No need]

- Add a brief release note for your PR here.

---------

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
CodeTorso 2024-06-04 17:31:10 +05:30 committed by GitHub
parent e74d2470c5
commit 38c573aacc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 243 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import { MDXRemote } from 'next-mdx-remote/rsc'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeHighlight from 'rehype-highlight'
import rehypeSlug from 'rehype-slug-custom-id'
import remarkGfm from 'remark-gfm'
import { components } from './mdx-components'
interface MdxProps {
@ -15,7 +16,7 @@ export function Mdx({ content }: MdxProps) {
components={components}
options={{
mdxOptions: {
// remarkPlugins: [remarkGfm, {}],
remarkPlugins: [remarkGfm, {}],
rehypePlugins: [
[rehypeHighlight as any, {}],
[rehypeAutolinkHeadings, {}],

View file

@ -18,6 +18,44 @@ By design, the [Editor](?)'s surface area is very large. Almost everything is av
This page gives a broad idea of how the [Editor](?) class is organized and some of the architectural concepts involved. The full reference is available in the [Editor](?) API.
## Using the editor
You can access the editor in two ways:
1. From the [Tldraw](?) component's `onMount` callback, where the editor is provided as the first argument in the callback.
```tsx
function App() {
return (
<Tldraw
onMount={(editor) => {
// your editor code here
}}
/>
)
}
```
2. Via the [useEditor](?) hook. This must be called from within the JSX of the [Tldraw](?) component.
```tsx
function InsideOfContext() {
const editor = useEditor()
// your editor code here
return null // or whatever
}
function App() {
return (
<Tldraw>
<InsideOfContext />
</Tldraw>
)
}
```
> If you are using the subcomponents as shown in [this example](/examples/editor-api/exploded), the editor instance is provided by the [TldrawEditor](?) component.
## Store
The editor holds the raw state of the document in its [Editor#store](?) property. Data is kept here as a table of JSON serializable records.
@ -121,7 +159,6 @@ Each node can be active or inactive. Each state node may also have zero or more
When a user interaction is sent to the editor via its [Editor#dispatch](?) method, this event is sent to the editor's root state node ([Editor#root](?)) and passed then down through the chart's active states until either it reaches a leaf node or until one of those nodes produces a transaction.
<Image
title="Events"
src="/images/api/events.png"
alt="A diagram showing an event being sent to the editor and handled in the state chart."
title="The editor passes an event into the state start where it is handled by each active state in order."

View file

@ -78,6 +78,7 @@
"rehype-highlight": "^7.0.0",
"rehype-slug": "^5.1.0",
"rehype-slug-custom-id": "^1.1.0",
"remark-gfm": "3.0.1",
"rimraf": "^4.4.0",
"sqlite": "^5.0.1",
"sqlite3": "^5.1.6",

View file

@ -1091,7 +1091,12 @@ body {
.layout {
display: grid;
grid-template-columns: 200px 1fr;
column-gap: 40px;
column-gap: 24px;
}
.article {
padding-left: 16px;
padding-right: 16px;
}
.footer {

197
yarn.lock
View file

@ -7470,6 +7470,7 @@ __metadata:
rehype-highlight: "npm:^7.0.0"
rehype-slug: "npm:^5.1.0"
rehype-slug-custom-id: "npm:^1.1.0"
remark-gfm: "npm:3.0.1"
rimraf: "npm:^4.4.0"
sqlite: "npm:^5.0.1"
sqlite3: "npm:^5.1.6"
@ -18284,6 +18285,13 @@ __metadata:
languageName: node
linkType: hard
"markdown-table@npm:^3.0.0":
version: 3.0.3
resolution: "markdown-table@npm:3.0.3"
checksum: ee6e661935c85734620d2fd10e237a60ae2992ef861713b71aa66135a5d5ae957cf06ce5e15fedf3ed1fce839dd7af1f9e87c5729186490f69fa9469e8e5c3e8
languageName: node
linkType: hard
"marked@npm:^10.0.0":
version: 10.0.0
resolution: "marked@npm:10.0.0"
@ -18315,6 +18323,18 @@ __metadata:
languageName: node
linkType: hard
"mdast-util-find-and-replace@npm:^2.0.0":
version: 2.2.2
resolution: "mdast-util-find-and-replace@npm:2.2.2"
dependencies:
"@types/mdast": "npm:^3.0.0"
escape-string-regexp: "npm:^5.0.0"
unist-util-is: "npm:^5.0.0"
unist-util-visit-parents: "npm:^5.0.0"
checksum: 59e11e853b74d8f6083950327df39e27287b383930ff836298a5100aeda5568282bb45046c27886d2156ea101580bb0689b890c29623cefa5adc74e95d9ca9ff
languageName: node
linkType: hard
"mdast-util-from-markdown@npm:^1.0.0, mdast-util-from-markdown@npm:^1.1.0":
version: 1.3.1
resolution: "mdast-util-from-markdown@npm:1.3.1"
@ -18380,6 +18400,76 @@ __metadata:
languageName: node
linkType: hard
"mdast-util-gfm-autolink-literal@npm:^1.0.0":
version: 1.0.3
resolution: "mdast-util-gfm-autolink-literal@npm:1.0.3"
dependencies:
"@types/mdast": "npm:^3.0.0"
ccount: "npm:^2.0.0"
mdast-util-find-and-replace: "npm:^2.0.0"
micromark-util-character: "npm:^1.0.0"
checksum: 272d075cdc7937bec0179af4052bd9032a6fbb05608b387b1b075b0491c73ce012f3ff1c718cdb5fb0ed1032c1fa7570d955b59c0ab3c3c72609928754774529
languageName: node
linkType: hard
"mdast-util-gfm-footnote@npm:^1.0.0":
version: 1.0.2
resolution: "mdast-util-gfm-footnote@npm:1.0.2"
dependencies:
"@types/mdast": "npm:^3.0.0"
mdast-util-to-markdown: "npm:^1.3.0"
micromark-util-normalize-identifier: "npm:^1.0.0"
checksum: 825f207afc98fd1daa0acc8adcb5754d1f0d577ccb1749245289bee7c892557668d8ee3a5ab618f42e710646cf018dcda84f3c0c608ae11718e9014e5bf4f9dc
languageName: node
linkType: hard
"mdast-util-gfm-strikethrough@npm:^1.0.0":
version: 1.0.3
resolution: "mdast-util-gfm-strikethrough@npm:1.0.3"
dependencies:
"@types/mdast": "npm:^3.0.0"
mdast-util-to-markdown: "npm:^1.3.0"
checksum: a9c2dc3ef46be7952d13b7063a16171bba8aa266bffe6b1e7267df02a60b4fa3734115cca311e9127db8cfcbbcd68fdd92aa26152bcd0c14372c79b254e4df2f
languageName: node
linkType: hard
"mdast-util-gfm-table@npm:^1.0.0":
version: 1.0.7
resolution: "mdast-util-gfm-table@npm:1.0.7"
dependencies:
"@types/mdast": "npm:^3.0.0"
markdown-table: "npm:^3.0.0"
mdast-util-from-markdown: "npm:^1.0.0"
mdast-util-to-markdown: "npm:^1.3.0"
checksum: 167f7f7a9dc17ce852f4f9bd155d7be179588e2ccf4ce3c4f23b12c1c9db5de904cdacc6f41b2d635cb84eb09a7ff5a33497585f2664a7f1e6bd6f7ab7e1197a
languageName: node
linkType: hard
"mdast-util-gfm-task-list-item@npm:^1.0.0":
version: 1.0.2
resolution: "mdast-util-gfm-task-list-item@npm:1.0.2"
dependencies:
"@types/mdast": "npm:^3.0.0"
mdast-util-to-markdown: "npm:^1.3.0"
checksum: 958417a7d7690728b44d65127ab9189c7feaa17aea924dd56a888c781ab3abaa4eb0c209f05c4dbf203da3d0c4df8fdace4c9471b644268bfc7fc792a018a171
languageName: node
linkType: hard
"mdast-util-gfm@npm:^2.0.0":
version: 2.0.2
resolution: "mdast-util-gfm@npm:2.0.2"
dependencies:
mdast-util-from-markdown: "npm:^1.0.0"
mdast-util-gfm-autolink-literal: "npm:^1.0.0"
mdast-util-gfm-footnote: "npm:^1.0.0"
mdast-util-gfm-strikethrough: "npm:^1.0.0"
mdast-util-gfm-table: "npm:^1.0.0"
mdast-util-gfm-task-list-item: "npm:^1.0.0"
mdast-util-to-markdown: "npm:^1.0.0"
checksum: 70e6cd32af94181d409f171f984f83fc18b3efe316844c62f31816f5c1612a92517b8ed766340f23e0a6d6cb0f27a8b07d288bab6619cbdbb0c5341006bcdc4d
languageName: node
linkType: hard
"mdast-util-mdx-expression@npm:^1.0.0":
version: 1.3.2
resolution: "mdast-util-mdx-expression@npm:1.3.2"
@ -18737,6 +18827,99 @@ __metadata:
languageName: node
linkType: hard
"micromark-extension-gfm-autolink-literal@npm:^1.0.0":
version: 1.0.5
resolution: "micromark-extension-gfm-autolink-literal@npm:1.0.5"
dependencies:
micromark-util-character: "npm:^1.0.0"
micromark-util-sanitize-uri: "npm:^1.0.0"
micromark-util-symbol: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
checksum: 1e0ccc758baef3cd0478ba84ff86fa1ec2b389042421c7cade9485b775456c1a9c3bd797393002b2c6f6abd9bdf829cb114874557bbcb8e43d16d06a464811c0
languageName: node
linkType: hard
"micromark-extension-gfm-footnote@npm:^1.0.0":
version: 1.1.2
resolution: "micromark-extension-gfm-footnote@npm:1.1.2"
dependencies:
micromark-core-commonmark: "npm:^1.0.0"
micromark-factory-space: "npm:^1.0.0"
micromark-util-character: "npm:^1.0.0"
micromark-util-normalize-identifier: "npm:^1.0.0"
micromark-util-sanitize-uri: "npm:^1.0.0"
micromark-util-symbol: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
uvu: "npm:^0.5.0"
checksum: 8777073fb76d2fd01f6b2405106af6c349c1e25660c4d37cadcc61c187d71c8444870f73cefaaa67f12884d5e45c78ee3c5583561a0b330bd91c6d997113584a
languageName: node
linkType: hard
"micromark-extension-gfm-strikethrough@npm:^1.0.0":
version: 1.0.7
resolution: "micromark-extension-gfm-strikethrough@npm:1.0.7"
dependencies:
micromark-util-chunked: "npm:^1.0.0"
micromark-util-classify-character: "npm:^1.0.0"
micromark-util-resolve-all: "npm:^1.0.0"
micromark-util-symbol: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
uvu: "npm:^0.5.0"
checksum: 8411ef1aa5dc83f662e8b45b085f70ddff29deb3c4259269e8a1ff656397abb755d8ea841a14be23e8585a31d3c0a5de1bd2c05f3453b66670e499d4a0004f5e
languageName: node
linkType: hard
"micromark-extension-gfm-table@npm:^1.0.0":
version: 1.0.7
resolution: "micromark-extension-gfm-table@npm:1.0.7"
dependencies:
micromark-factory-space: "npm:^1.0.0"
micromark-util-character: "npm:^1.0.0"
micromark-util-symbol: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
uvu: "npm:^0.5.0"
checksum: f05d86a099c941a2a309d60bf4839d16a00a93cb880cda4ab8faeb831647763fff6e03197ec15b80e1f195002afcca6afe2b95c3622b049b82d7ff8ef1c1c776
languageName: node
linkType: hard
"micromark-extension-gfm-tagfilter@npm:^1.0.0":
version: 1.0.2
resolution: "micromark-extension-gfm-tagfilter@npm:1.0.2"
dependencies:
micromark-util-types: "npm:^1.0.0"
checksum: 55c7d9019d6a39efaaed2c2e40b0aaa137d2c4f9c94cac82e93f509a806c3a775e4c815b5d8e986617450b68861a19776e4b886307e83db452b393f15a837b39
languageName: node
linkType: hard
"micromark-extension-gfm-task-list-item@npm:^1.0.0":
version: 1.0.5
resolution: "micromark-extension-gfm-task-list-item@npm:1.0.5"
dependencies:
micromark-factory-space: "npm:^1.0.0"
micromark-util-character: "npm:^1.0.0"
micromark-util-symbol: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
uvu: "npm:^0.5.0"
checksum: 46bb1baa10bfb785a2e3e2f975e5509260b9995d5c3aeddf77051957d218ce1af4ea737bcb6a56a930e62d42b05307b20632a400eff25cdb290789ff3170cad5
languageName: node
linkType: hard
"micromark-extension-gfm@npm:^2.0.0":
version: 2.0.3
resolution: "micromark-extension-gfm@npm:2.0.3"
dependencies:
micromark-extension-gfm-autolink-literal: "npm:^1.0.0"
micromark-extension-gfm-footnote: "npm:^1.0.0"
micromark-extension-gfm-strikethrough: "npm:^1.0.0"
micromark-extension-gfm-table: "npm:^1.0.0"
micromark-extension-gfm-tagfilter: "npm:^1.0.0"
micromark-extension-gfm-task-list-item: "npm:^1.0.0"
micromark-util-combine-extensions: "npm:^1.0.0"
micromark-util-types: "npm:^1.0.0"
checksum: 3ffd06ced4314abd0f0c72ec227f034f38dd47facbb62439ef3216d42f32433f3901d14675cf806e8d73689802a11849958b330bb5b55dd4fd5cdc64ebaf345c
languageName: node
linkType: hard
"micromark-extension-mdx-expression@npm:^1.0.0":
version: 1.0.8
resolution: "micromark-extension-mdx-expression@npm:1.0.8"
@ -22209,6 +22392,18 @@ __metadata:
languageName: node
linkType: hard
"remark-gfm@npm:3.0.1":
version: 3.0.1
resolution: "remark-gfm@npm:3.0.1"
dependencies:
"@types/mdast": "npm:^3.0.0"
mdast-util-gfm: "npm:^2.0.0"
micromark-extension-gfm: "npm:^2.0.0"
unified: "npm:^10.0.0"
checksum: 8ec301f5fb1f52c548b5a6d7ca6a3422d55db73cd703f147c979d16dca003f065181f55404d6f3f49d33f1faca3fe56ae731ed7fe0acc00cd945a8e605f155f2
languageName: node
linkType: hard
"remark-html@npm:^16.0.1":
version: 16.0.1
resolution: "remark-html@npm:16.0.1"
@ -25206,7 +25401,7 @@ __metadata:
languageName: node
linkType: hard
"unist-util-visit-parents@npm:^5.1.1":
"unist-util-visit-parents@npm:^5.0.0, unist-util-visit-parents@npm:^5.1.1":
version: 5.1.3
resolution: "unist-util-visit-parents@npm:5.1.3"
dependencies: