collaboration Drawing app
 
 
 
Go to file
alex e3dec58499
Add DSL to make writing shape-layout test cases much easier (#1413)
As part of my highlighter work, I've been writing a few test cases
around rendering with different combinations of nested frames and
groups. Writing these test cases using `createShapes` is really hard,
and reading them is even harder. I wanted to see if there was an easier
way for us to define shapes for test cases, and turns out... there is!

This diff introduces a JSX-based DSL for defining test cases. It looks
something like this:
```tsx
// create some shapes
const ids = app.createShapesFromJsx([
	<TL.geo ref="A" x={100} y={100} w={100} h={100} />,
	<TL.frame ref="B" x={200} y={200} w={300} h={300}>
		<TL.geo ref="C" x={200} y={200} w={50} h={50} />
		<TL.text ref="D" x={1000} y={1000} text="Hello, world!" align="end" />
	</TL.frame>,
])

// refer to shape IDs according to their `ref`
app.select(ids.C)
```

It's probably not worth trying to migrate everything possible to this,
but i picked a few random tests to convert over to show how it works
(and because i wanted this diff to end up red overall)

In the future, I'd like to use this with visual regression testing to
test rendering/exports on some complex combinations of shapes too.

### Change Type
- [x] `tests` — Changes to any testing-related code only (will not
publish a new version)

### Release Notes

[internal only change]
2023-05-30 13:27:26 +00:00
.github [chore] refactor user preferences (#1435) 2023-05-25 09:54:29 +00:00
.husky [chore] remove yarnrc-private.yml (#1427) 2023-05-22 08:56:05 +00:00
.yarn
apps Feature flags rework (#1474) 2023-05-30 13:06:15 +00:00
assets Add translations for "Leave shared project" action (#1394) 2023-05-25 09:51:28 +00:00
config readmes 2023-05-04 13:47:56 +01:00
e2e Don't allow `g` keyboard shortcut in readonly mode, show laser tool in the toolbar (#1459) 2023-05-25 19:08:52 +00:00
packages Add DSL to make writing shape-layout test cases much easier (#1413) 2023-05-30 13:27:26 +00:00
scripts main: notify huppy after release 2023-05-15 14:17:19 +01:00
.eslintignore enable eslint for test files (#1363) 2023-05-12 13:19:39 +00:00
.eslintplugin.js
.eslintrc.js enable eslint for test files (#1363) 2023-05-12 13:19:39 +00:00
.gitignore Added initial webdriver tests (#1337) 2023-05-09 20:21:45 +00:00
.ignore [feature] ui events (#1326) 2023-05-11 22:14:58 +00:00
.prettierignore [refactor] record migrations (#1430) 2023-05-22 21:46:24 +00:00
.prettierrc [fix] pick a better default language (#1201) 2023-04-29 23:06:02 +00:00
.yarnrc.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md [improvement] readme / contributing (#1199) 2023-05-03 08:32:52 +00:00
LICENSE
README.md Update docs links + guides + build (#1422) 2023-05-22 08:21:54 +00:00
lazy.config.ts [fix] Don't synchronize isReadOnly (#1396) 2023-05-17 10:45:43 +00:00
lerna.json
package.json [fix] local e2e script (#1442) 2023-05-23 15:57:00 +00:00
public-yarn.lock update use-gesture (#1453) 2023-05-25 09:39:47 +00:00

README.md

tldraw

tldraw

Welcome to the public monorepo for tldraw.

What is tldraw?

tldraw is a collaborative digital whiteboard available at tldraw.com. Its editor, user interface, and other underlying libraries are open source and available in this repository. They are also distributed on npm. You can use tldraw to create a drop-in whiteboard for your product or as the foundation on which to build your own inifinite canvas applications.

Learn more at tldraw.dev.

Note This repo contains source code for the current version of tldraw. You can find the source for the original version here.

Installation & Usage

To learn more about using tldraw in your React application, follow our guide here or see this StackBlitz.

import { Tldraw } from '@tldraw/tldraw'
import '@tldraw/tldraw/editor.css'
import '@tldraw/tldraw/ui.css'

function TldrawExample() {
	return <Tldraw />
}

Local development

To run the local development server, first clone this repo.

Install dependencies:

yarn

Start the local development server:

yarn dev

Open the example project at localhost:5420.

Examples

Our development server contains several examples that demonstrates different ways that you can customize tldraw or use its APIs. Each example is found in the apps/examples/src folder.

  • eg: localhost:5420 for the basic example.
  • eg: localhost:5420/api for the API example.

To learn more about using tldraw, visit our docs.

About this repository

Top-level layout

This repository's contents is divided across four primary sections:

  • /apps contains the source for our applications
  • /packages contains the source for our public packages
  • /scripts contains scripts used for building and publishing
  • /assets contains icons and translations relied on by the app

Applications

Packages

  • editor: the tldraw editor
  • ui: the editor's user interface
  • tldraw: the main tldraw package containing both the editor and the UI
  • primitives: low-level primitives for working with vectors and geometry
  • tlschema: shape definitions and migrations
  • tlsync-client: a library for (locally) syncronizing editor instances
  • tlstore: an in-memory reactive database
  • tlvalidate: a validation library used for run-time validation
  • tlassets: a library for working with tldraw's fonts and translations
  • file-format: a library for working with tldraw's .tldr file format
  • utils: low-level data utilities shared by other libraries

Community

Have questions, comments or feedback? Join our discord or start a discussion.

Distributions

You can find tldraw on npm here.

License

The source code for various apps and packages in this repository (as well as our 2.0+ distributions and releases) are currently licensed under Apache-2.0. These licenses are subject to change in our upcoming 2.0 release. If you are planning to use tldraw in a commercial product, please reach out at hello@tldraw.com.

Contribution

Please see our contributing guide. Found a bug? Please submit an issue.

Note: we are currently unable to accept contributions on the @tldraw/tldraw or @tldraw/editor packages while we work out our final licensing.

Contact

Find us on Twitter at @tldraw or email hello@tldraw.com. You can also join our discord for quick help and support.