tldraw / tldraw-v1

A tiny little drawing app. This is the original 2021-2022 version, released under MIT.
https://old.tldraw.com
MIT License
61 stars 36 forks source link

[feature] tldraw plugin for Docusaurus #67

Closed TheKnarf closed 1 year ago

TheKnarf commented 1 year ago

I would like to use .tldr files directly in Docusaurus without having to manually convert them to PNG or SVG files. This would be the perfect case for a Docusaurus Plugin.

TheKnarf commented 1 year ago

Docusaurus support MDX documents where one can embed React components, so it might not be needed to make an actual plugin.

The following code renderes the TLDraw editor inside the documentation:

import { ColorStyle, TDShapeType, Tldraw, TldrawApp } from '@tldraw/tldraw';

# Architecture

<Tldraw />

Screenshot 2022-12-08 at 10 56 42

Three problems still remain:

TheKnarf commented 1 year ago

I managed to solve my two last problems using this example:

import { ColorStyle, TDShapeType, Tldraw, TldrawApp } from '@tldraw/tldraw';
import TLDRDocument from '!!raw-loader!./arcitecture.tldr';

# Architecture

<Tldraw readOnly document={JSON.parse(TLDRDocument).document} />

This required me to add the following two packages to my setup:

yarn add -D raw-loader
yarn add @tldraw/tldraw

Now I just need to solve the issue that it takes up to much of the screen and we're all set.

TheKnarf commented 1 year ago

And there we go with a working solution (inspired by this example):

import { ColorStyle, TDShapeType, Tldraw, TldrawApp } from '@tldraw/tldraw';
import TLDRDocument from '!!raw-loader!./arcitecture.tldr';

# Architecture

<div style={{
    position: 'relative',
    width: '100%',
    height: '500px',
    overflow: 'hidden',
}}>
    <Tldraw readOnly document={JSON.parse(TLDRDocument).document} />
</div>

Screenshot 2022-12-08 at 11 10 06