From 38c573aaccfe19d082d4d08474d4d0157e4fef09 Mon Sep 17 00:00:00 2001 From: CodeTorso <129188028+CodeTorso@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:31:10 +0530 Subject: [PATCH] Add editor notes to the docs (#3832) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit People just don't know that they need to put the components using useEditor inside the 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 - [ ] `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 - [ ] `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 --- apps/docs/components/Mdx.tsx | 3 +- apps/docs/content/docs/editor.mdx | 39 +++++- apps/docs/package.json | 1 + apps/docs/styles/globals.css | 7 +- yarn.lock | 197 +++++++++++++++++++++++++++++- 5 files changed, 243 insertions(+), 4 deletions(-) diff --git a/apps/docs/components/Mdx.tsx b/apps/docs/components/Mdx.tsx index 7b320542c..2f2f363bb 100644 --- a/apps/docs/components/Mdx.tsx +++ b/apps/docs/components/Mdx.tsx @@ -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, {}], diff --git a/apps/docs/content/docs/editor.mdx b/apps/docs/content/docs/editor.mdx index 7767ff3ab..ed01c14d2 100644 --- a/apps/docs/content/docs/editor.mdx +++ b/apps/docs/content/docs/editor.mdx @@ -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 ( + { + // 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 ( + + + + ) +} +``` + +> 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.