Browse Source

updates docs / readmes / adds contributor guide

main
Steve Ruiz 2 years ago
parent
commit
84a91ccc70

+ 80
- 0
CODE_OF_CONDUCT.md View File

@@ -0,0 +1,80 @@
1
+# Contributor Covenant Code of Conduct
2
+
3
+## Our Pledge
4
+
5
+We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+## Our Standards
10
+
11
+Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+- Demonstrating empathy and kindness toward other people
14
+- Being respectful of differing opinions, viewpoints, and experiences
15
+- Giving and gracefully accepting constructive feedback
16
+- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+- Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+Examples of unacceptable behavior include:
20
+
21
+- The use of sexualized language or imagery, and sexual attention or advances of any kind
22
+- Trolling, insulting or derogatory comments, and personal or political attacks
23
+- Public or private harassment
24
+- Publishing others' private information, such as a physical or email address, without their explicit permission
25
+- Contacting individual members, contributors, or leaders privately, outside designated community mechanisms, without their explicit permission
26
+- Other conduct which could reasonably be considered inappropriate in a professional setting
27
+
28
+## Enforcement Responsibilities
29
+
30
+Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
31
+
32
+Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
33
+
34
+## Scope
35
+
36
+This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
37
+
38
+## Enforcement
39
+
40
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at opensource@github.com. All complaints will be reviewed and investigated promptly and fairly.
41
+
42
+All community leaders are obligated to respect the privacy and security of the reporter of any incident.
43
+
44
+## Enforcement Guidelines
45
+
46
+Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
47
+
48
+### 1. Correction
49
+
50
+**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
51
+
52
+**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
53
+
54
+### 2. Warning
55
+
56
+**Community Impact**: A violation through a single incident or series of actions.
57
+
58
+**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
59
+
60
+### 3. Temporary Ban
61
+
62
+**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
63
+
64
+**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
65
+
66
+### 4. Permanent Ban
67
+
68
+**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
69
+
70
+**Consequence**: A permanent ban from any sort of public interaction within the community.
71
+
72
+## Attribution
73
+
74
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.
75
+
76
+Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
77
+
78
+[homepage]: https://www.contributor-covenant.org
79
+
80
+For answers to common questions about this code of conduct, see the FAQ at <https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.

+ 80
- 0
CONTRIBUTING.md View File

@@ -0,0 +1,80 @@
1
+# Welcome to the TLDraw contributing guide <!-- omit in toc -->
2
+
3
+Thank you for investing your time in contributing to our project! Any contribution you make will be reflected in the @tldraw/tldraw package and at [tldraw.com](https://tldraw.com).
4
+
5
+Read our [Code of Conduct](./CODE_OF_CONDUCT.md) to keep our community approachable and respectable.
6
+
7
+In this guide you will get an overview of the contribution workflow from opening an issue, creating a PR, reviewing, and merging the PR.
8
+
9
+Use the table of contents icon <img src="./assets/images/table-of-contents.png" width="25" height="25" /> on the top left corner of this document to get to a specific section of this guide quickly.
10
+
11
+## New contributor guide
12
+
13
+To get an overview of the project, read the [README](README.md). Here are some resources to help you get started with open source contributions:
14
+
15
+- [Finding ways to contribute to open source on GitHub](https://docs.github.com/en/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github)
16
+- [Set up Git](https://docs.github.com/en/get-started/quickstart/set-up-git)
17
+- [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow)
18
+- [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests)
19
+
20
+## Getting started
21
+
22
+Join the [Discord channel](https://discord.gg/s4FXZ6fppJ). If you have questions or feedback, this is the best place to reach the team and other contributors directly.
23
+
24
+### Issues
25
+
26
+#### Create a new issue
27
+
28
+If you spot a problem, [search if an issue already exists](https://github.com/tldraw/tldraw/issues). If a related issue doesn't exist, you can open a new issue using a relevant [issue form](https://github.com/tldraw/tldraw/issues/new/choose).
29
+
30
+#### Solve an issue
31
+
32
+Scan through our [existing issues](https://github.com/tldraw/tldraw/issues) to find one that interests you. You can narrow down the search using `labels` as filters. See [Labels](/contributing/how-to-use-labels.md) for more information. If you find an issue to work on, you are welcome to open a PR with a fix.
33
+
34
+### Make Changes
35
+
36
+#### Make changes locally
37
+
38
+1. [Install Git LFS](https://docs.github.com/en/github/managing-large-files/versioning-large-files/installing-git-large-file-storage).
39
+
40
+2. Fork the repository.
41
+
42
+- Using GitHub Desktop:
43
+
44
+  - [Getting started with GitHub Desktop](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/getting-started-with-github-desktop) will guide you through setting up Desktop.
45
+  - Once Desktop is set up, you can use it to [fork the repo](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/cloning-and-forking-repositories-from-github-desktop)!
46
+
47
+- Using the command line:
48
+
49
+  - [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them.
50
+
51
+- GitHub Codespaces:
52
+  - [Fork, edit, and preview](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace) using [GitHub Codespaces](https://github.com/features/codespaces) without having to install and run the project locally.
53
+
54
+3. Install or update to **Node.js v16**.
55
+
56
+4. Create a working branch and start with your changes!
57
+
58
+5. Follow the [the development guide](guides/development.md).
59
+
60
+### Commit your update
61
+
62
+Commit the changes once you are happy with them.
63
+
64
+### Pull Request
65
+
66
+When you're finished with the changes, create a pull request, also known as a PR.
67
+
68
+- Fill the "Ready for review" template so that we can review your PR. This template helps reviewers understand your changes as well as the purpose of your pull request.
69
+- Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if you are solving one.
70
+- Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) so the branch can be updated for a merge.
71
+  Once you submit your PR, a team member will review your proposal. We may ask questions or request for additional information.
72
+- We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch.
73
+- As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations).
74
+- If you run into any merge issues, checkout this [git tutorial](https://lab.github.com/githubtraining/managing-merge-conflicts) to help you resolve merge conflicts and other issues.
75
+
76
+### Your PR is merged!
77
+
78
+Congratulations :tada::tada: The GitHub team thanks you :sparkles:.
79
+
80
+Once your PR is merged, your contributions will become part of the next TLDraw release, and will be visible in the [TLDraw app](https://tldraw.com).

+ 12
- 274
README.md View File

@@ -4,9 +4,9 @@
4 4
 
5 5
 # @tldraw/tldraw
6 6
 
7
-This package contains the [tldraw](https://tldraw.com) editor as a React component named `<TLDraw>`. You can use this package to embed the editor in any React application.
7
+This package contains the [TLDraw](https://tldraw.com) editor as a React component named `<TLDraw>`. You can use this package to embed the editor in any React application.
8 8
 
9
-🎨 Want to build your own tldraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
9
+🎨 Want to build your own TLDraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
10 10
 
11 11
 💕 Love this library? Consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
12 12
 
@@ -74,297 +74,35 @@ function App() {
74 74
 }
75 75
 ```
76 76
 
77
-Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section for more on this API.
77
+Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section of the [documentation](guides/documentation) for more on this API.
78 78
 
79 79
 ### Responding to Changes
80 80
 
81
-You can respond to changes and user actions using the `onChange` callback.
81
+You can respond to changes and user actions using the `onChange` callback. For more specific changes, you can also use the `onPatch`, `onCommand`, or `onPersist` callbacks. See the [documentation](guides/documentation) for more.
82 82
 
83 83
 ```tsx
84 84
 import { TLDraw, TLDrawState } from '@tldraw/tldraw'
85 85
 
86 86
 function App() {
87
-  const handleChange = React.useCallback((state: TLDrawState, reason: string) => {}, [])
87
+  const handleChange = React.useCallback((state: TLDrawState, reason: string) => {
88
+    // Do something with the change
89
+  }, [])
88 90
 
89 91
   return <TLDraw onMount={handleMount} />
90 92
 }
91 93
 ```
92 94
 
93
-Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section for more on this API.
94
-
95 95
 ## Documentation
96 96
 
97
-### `TLDraw`
98
-
99
-The `TLDraw` React component is the [tldraw](https://tldraw.com) editor exported as a standalone component. You can control the editor through props, or through the `TLDrawState`'s imperative API. **All props are optional.**
100
-
101
-| Prop              | Type             | Description                                                                                               |
102
-| ----------------- | ---------------- | --------------------------------------------------------------------------------------------------------- |
103
-| `id`              | `string`         | An id under which to persist the component's state.                                                       |
104
-| `document`        | `TLDrawDocument` | An initial [`TLDrawDocument`](#tldrawdocument) object.                                                    |
105
-| `currentPageId`   | `string`         | A current page id, referencing the `TLDrawDocument` object provided via the `document` prop.              |
106
-| `autofocus`       | `boolean`        | Whether the editor should immediately receive focus. Defaults to true.                                    |
107
-| `showMenu`        | `boolean`        | Whether to show the menu.                                                                                 |
108
-| `showPages`       | `boolean`        | Whether to show the pages menu.                                                                           |
109
-| `showStyles`      | `boolean`        | Whether to show the styles menu.                                                                          |
110
-| `showTools`       | `boolean`        | Whether to show the tools.                                                                                |
111
-| `showUI`          | `boolean`        | Whether to show any UI other than the canvas.                                                             |
112
-| `onMount`         | `Function`       | Called when the editor first mounts, receiving the current `TLDrawState`.                                 |
113
-| `onPatch`         | `Function`       | Called when the state is updated via a patch.                                                             |
114
-| `onCommand`       | `Function`       | Called when the state is updated via a command.                                                           |
115
-| `onPersist`       | `Function`       | Called when the state is persisted after an action.                                                       |
116
-| `onChange`        | `Function`       | Called when the `TLDrawState` updates for any reason.                                                     |
117
-| `onUserChange`    | `Function`       | Called when the user's "presence" information changes.                                                    |
118
-| `onUndo`          | `Function`       | Called when the `TLDrawState` updates after an undo.                                                      |
119
-| `onRedo`          | `Function`       | Called when the `TLDrawState` updates after a redo.                                                       |
120
-| `onSignIn`        | `Function`       | Called when the user selects Sign In from the menu.                                                       |
121
-| `onSignOut`       | `Function`       | Called when the user selects Sign Out from the menu.                                                      |
122
-| `onNewProject`    | `Function`       | Called when the user when the user creates a new project through the menu or through a keyboard shortcut. |
123
-| `onSaveProject`   | `Function`       | Called when the user saves a project through the menu or through a keyboard shortcut.                     |
124
-| `onSaveProjectAs` | `Function`       | Called when the user saves a project as a new project through the menu or through a keyboard shortcut.    |
125
-| `onOpenProject`   | `Function`       | Called when the user opens new project through the menu or through a keyboard shortcut.                   |
126
-
127
-> **Note**: For help with the file-related callbacks, see `useFileSystem`.
128
-
129
-### `useFileSystem`
130
-
131
-You can use the `useFileSystem` hook to get prepared callbacks for `onNewProject`, `onOpenProject`, `onSaveProject`, and `onSaveProjectAs`. These callbacks allow a user to save files via the [FileSystem](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) API.
132
-
133
-```ts
134
-import { TLDraw, useFileSystem } from '@tldraw/tldraw'
135
-
136
-function App() {
137
-  const fileSystemEvents = useFileSystem()
138
-
139
-  return <TLDraw {...fileSystemEvents} />
140
-}
141
-```
142
-
143
-### `TLDrawDocument`
144
-
145
-You can initialize or control the `<TLDraw>` component via its `document` property. A `TLDrawDocument` is an object with three properties:
146
-
147
-- `id` - A unique ID for this document
148
-- `pages` - A table of `TLDrawPage` objects
149
-- `pageStates` - A table of `TLPageState` objects
150
-- `version` - The document's version, used internally for migrations.
151
-
152
-```ts
153
-import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw'
154
-
155
-const myDocument: TLDrawDocument = {
156
-  id: 'doc',
157
-  version: TLDrawState.version,
158
-  pages: {
159
-    page1: {
160
-      id: 'page1',
161
-      shapes: {},
162
-      bindings: {},
163
-    },
164
-  },
165
-  pageStates: {
166
-    page1: {
167
-      id: 'page1',
168
-      selectedIds: [],
169
-      currentParentId: 'page1',
170
-      camera: {
171
-        point: [0, 0],
172
-        zoom: 1,
173
-      },
174
-    },
175
-  },
176
-}
177
-
178
-function App() {
179
-  return <TLDraw document={myDocument} />
180
-}
181
-```
182
-
183
-**Tip:** TLDraw is built on [@tldraw/core](https://github.com/tldraw/core). The pages and pageStates in TLDraw are objects containing `TLPage` and `TLPageState` objects from the core library. For more about these types, check out the [@tldraw/core](https://github.com/tldraw/core) documentation.
184
-
185
-**Important:** In the `pages` object, each `TLPage` object must be keyed under its `id` property. Likewise, each `TLPageState` object must be keyed under its `id`. In addition, each `TLPageState` object must have an `id` that matches its corresponding page.
186
-
187
-### Shapes
188
-
189
-Your `TLPage` objects may include shapes: objects that fit one of the `TLDrawShape` interfaces listed below. All `TLDrawShapes` extends a common interface:
190
-
191
-| Property              | Type             | Description                                                     |
192
-| --------------------- | ---------------- | --------------------------------------------------------------- |
193
-| `id`                  | `string`         | A unique ID for the shape.                                      |
194
-| `name`                | `string`         | The shape's name.                                               |
195
-| `type`                | `string`         | The shape's type.                                               |
196
-| `parentId`            | `string`         | The ID of the shape's parent (a shape or its page).             |
197
-| `childIndex`          | `number`         | The shape's order within its parent's children, indexed from 1. |
198
-| `point`               | `number[]`       | The `[x, y]` position of the shape.                             |
199
-| `rotation`            | `number[]`       | (optional) The shape's rotation in radians.                     |
200
-| `children`            | `string[]`       | (optional) The shape's child shape ids.                         |
201
-| `handles`             | `TLDrawHandle{}` | (optional) A table of `TLHandle` objects.                       |
202
-| `isLocked`            | `boolean`        | (optional) True if the shape is locked.                         |
203
-| `isHidden`            | `boolean`        | (optional) True if the shape is hidden.                         |
204
-| `isEditing`           | `boolean`        | (optional) True if the shape is currently editing.              |
205
-| `isGenerated`         | `boolean`        | (optional) True if the shape is generated.                      |
206
-| `isAspectRatioLocked` | `boolean`        | (optional) True if the shape's aspect ratio is locked.          |
207
-
208
-> **Important:** In order for re-ordering to work, a shape's `childIndex` values _must_ start from 1, not 0. The page or parent shape's "bottom-most" child should have a `childIndex` of 1.
209
-
210
-The `ShapeStyle` object is a common style API for all shapes.
211
-
212
-| Property   | Type         | Description                             |
213
-| ---------- | ------------ | --------------------------------------- |
214
-| `size`     | `SizeStyle`  | The size of the shape's stroke.         |
215
-| `dash`     | `DashStyle`  | The style of the shape's stroke.        |
216
-| `color`    | `ColorStyle` | The shape's color.                      |
217
-| `isFilled` | `boolean`    | (optional) True if the shape is filled. |
218
-
219
-#### `DrawShape`
220
-
221
-A hand-drawn line.
222
-
223
-| Property | Type         | Description                               |
224
-| -------- | ------------ | ----------------------------------------- |
225
-| `points` | `number[][]` | An array of points as `[x, y, pressure]`. |
226
-
227
-##### `RectangleShape`
228
-
229
-A rectangular shape.
230
-
231
-| Property | Type       | Description                             |
232
-| -------- | ---------- | --------------------------------------- |
233
-| `size`   | `number[]` | The `[width, height]` of the rectangle. |
234
-
235
-#### `EllipseShape`
236
-
237
-An elliptical shape.
97
+See the project's [documentation](/guides/documentation).
238 98
 
239
-| Property | Type       | Description                         |
240
-| -------- | ---------- | ----------------------------------- |
241
-| `radius` | `number[]` | The `[x, y]` radius of the ellipse. |
99
+## Contribution
242 100
 
243
-#### `ArrowShape`
101
+See the [contributing guide](/CONTRIBUTING.md).
244 102
 
245
-An arrow that can connect shapes.
246
-
247
-| Property      | Type     | Description                                                             |
248
-| ------------- | -------- | ----------------------------------------------------------------------- |
249
-| `handles`     | `object` | An object with three `TLHandle` properties: `start`, `end`, and `bend`. |
250
-| `decorations` | `object` | An object with two properties `start`, `end`, and `bend`.               |
251
-
252
-#### `TextShape`
253
-
254
-A line of text.
255
-
256
-| Property | Type     | Description               |
257
-| -------- | -------- | ------------------------- |
258
-| `text`   | `string` | The shape's text content. |
259
-
260
-#### `StickyShape`
261
-
262
-A sticky note.
263
-
264
-| Property | Type     | Description               |
265
-| -------- | -------- | ------------------------- |
266
-| `text`   | `string` | The shape's text content. |
267
-
268
-### Bindings
269
-
270
-A binding is a connection **from** one shape and **to** another shape. At the moment, only arrows may be bound "from". Most shapes may be bound "to", except other `ArrowShape` and `DrawShape`s.
271
-
272
-| Property   | Type             | Description                                              |
273
-| ---------- | ---------------- | -------------------------------------------------------- |
274
-| `id`       | `string`         | The binding's own unique ID.                             |
275
-| `fromId`   | `string`         | The id of the `ArrowShape` that the binding is bound to. |
276
-| `toId`     | `string`         | The id of the other shape that the binding is bound to.  |
277
-| `handleId` | `start` or `end` | The connected arrow handle.                              |
278
-| `distance` | `number`         | The distance from the bound point.                       |
279
-| `point`    | `number[]`       | A normalized point representing the bound point.         |
280
-
281
-### `TLDrawState` API
282
-
283
-You can change the `TLDraw` component's state through an imperative API called `TLDrawState`. To access this API, use the `onMount` callback, or any of the component's callback props, like `onPersist`.
284
-
285
-```tsx
286
-import { TLDraw, TLDrawState } from '@tldraw/tldraw'
287
-
288
-function App() {
289
-  const handleMount = React.useCallback((state: TLDrawState) => {
290
-    state.selectAll()
291
-  }, [])
292
-
293
-  return <TLDraw onMount={handleMount} />
294
-}
295
-```
296
-
297
-To view the full documentation of the `TLDrawState` API, generate the project's documentation by running `yarn docs` from the root folder, then open the file at:
298
-
299
-```
300
-/packages/tldraw/docs/classes/TLDrawState.html
301
-```
103
+## Development
302 104
 
303
-Here are some useful methods:
304
-
305
-- `loadDocument`
306
-- `select`
307
-- `selectAll`
308
-- `selectNone`
309
-- `delete`
310
-- `deleteAll`
311
-- `deletePage`
312
-- `changePage`
313
-- `cut`
314
-- `copy`
315
-- `paste`
316
-- `copyJson`
317
-- `copySvg`
318
-- `undo`
319
-- `redo`
320
-- `zoomIn`
321
-- `zoomOut`
322
-- `zoomToContent`
323
-- `zoomToSelection`
324
-- `zoomToFit`
325
-- `zoomTo`
326
-- `resetZoom`
327
-- `setCamera`
328
-- `resetCamera`
329
-- `align`
330
-- `distribute`
331
-- `stretch`
332
-- `nudge`
333
-- `duplicate`
334
-- `flipHorizontal`
335
-- `flipVertical`
336
-- `rotate`
337
-- `style`
338
-- `group`
339
-- `ungroup`
340
-- `createShapes`
341
-- `updateShapes`
342
-- `updateDocument`
343
-- `updateUsers`
344
-- `removeUser`
345
-- `setSetting`
346
-- `selectTool`
347
-- `cancel`
348
-
349
-Check the generated docs, source or the TypeScript types for more on these and other methods.
350
-
351
-## Local Development
352
-
353
-From the root folder:
354
-
355
-- Run `yarn` to install dependencies.
356
-
357
-- Run `yarn start` to start the development server for the package and for the example.
358
-
359
-- Open `localhost:5420` to view the example project.
360
-
361
-**Note:** The multiplayer examples and endpoints currently require an API key from [Liveblocks](https://liveblocks.io/), however the storage services that are used in TLDraw are currently in alpha and (as of November 2021) not accessible to the general public. You won't be able to authenticate and run these parts of the project.
362
-
363
-Other scripts:
364
-
365
-- Run `yarn test` to execute unit tests via [Jest](https://jestjs.io).
366
-
367
-- Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/).
105
+See the [development guide](/guides/development.md).
368 106
 
369 107
 ## Example
370 108
 

+ 17
- 0
guides/development.md View File

@@ -0,0 +1,17 @@
1
+# Development
2
+
3
+From the root folder:
4
+
5
+- Run `yarn` to install dependencies.
6
+
7
+- Run `yarn start` to start the development server for the package and for the example.
8
+
9
+- Open `localhost:5420` to view the example project.
10
+
11
+**Note:** The multiplayer examples and endpoints currently require an API key from [Liveblocks](https://liveblocks.io/), however the storage services that are used in TLDraw are currently in alpha and (as of November 2021) not accessible to the general public. You won't be able to authenticate and run these parts of the project.
12
+
13
+Other scripts:
14
+
15
+- Run `yarn test` to execute unit tests via [Jest](https://jestjs.io).
16
+
17
+- Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/).

+ 268
- 0
guides/documentation.md View File

@@ -0,0 +1,268 @@
1
+# Documentation
2
+
3
+## Introduction
4
+
5
+This file contains the documentatin for the `<TLDraw>` component as well as the data model that the component accepts.
6
+
7
+In addition to the docs written below, this project also includes **generated documentation**. To view the generated docs:
8
+
9
+1. Run `yarn docs` from the root folder
10
+2. Open the file at:
11
+
12
+```
13
+/packages/tldraw/docs/classes/TLDrawState.html
14
+```
15
+
16
+## `TLDraw`
17
+
18
+The `TLDraw` React component is the [tldraw](https://tldraw.com) editor exported as a standalone component. You can control the editor through props, or through the `TLDrawState`'s imperative API. **All props are optional.**
19
+
20
+| Prop              | Type             | Description                                                                                               |
21
+| ----------------- | ---------------- | --------------------------------------------------------------------------------------------------------- |
22
+| `id`              | `string`         | An id under which to persist the component's state.                                                       |
23
+| `document`        | `TLDrawDocument` | An initial [`TLDrawDocument`](#tldrawdocument) object.                                                    |
24
+| `currentPageId`   | `string`         | A current page id, referencing the `TLDrawDocument` object provided via the `document` prop.              |
25
+| `autofocus`       | `boolean`        | Whether the editor should immediately receive focus. Defaults to true.                                    |
26
+| `showMenu`        | `boolean`        | Whether to show the menu.                                                                                 |
27
+| `showPages`       | `boolean`        | Whether to show the pages menu.                                                                           |
28
+| `showStyles`      | `boolean`        | Whether to show the styles menu.                                                                          |
29
+| `showTools`       | `boolean`        | Whether to show the tools.                                                                                |
30
+| `showUI`          | `boolean`        | Whether to show any UI other than the canvas.                                                             |
31
+| `onMount`         | `Function`       | Called when the editor first mounts, receiving the current `TLDrawState`.                                 |
32
+| `onPatch`         | `Function`       | Called when the state is updated via a patch.                                                             |
33
+| `onCommand`       | `Function`       | Called when the state is updated via a command.                                                           |
34
+| `onPersist`       | `Function`       | Called when the state is persisted after an action.                                                       |
35
+| `onChange`        | `Function`       | Called when the `TLDrawState` updates for any reason.                                                     |
36
+| `onUserChange`    | `Function`       | Called when the user's "presence" information changes.                                                    |
37
+| `onUndo`          | `Function`       | Called when the `TLDrawState` updates after an undo.                                                      |
38
+| `onRedo`          | `Function`       | Called when the `TLDrawState` updates after a redo.                                                       |
39
+| `onSignIn`        | `Function`       | Called when the user selects Sign In from the menu.                                                       |
40
+| `onSignOut`       | `Function`       | Called when the user selects Sign Out from the menu.                                                      |
41
+| `onNewProject`    | `Function`       | Called when the user when the user creates a new project through the menu or through a keyboard shortcut. |
42
+| `onSaveProject`   | `Function`       | Called when the user saves a project through the menu or through a keyboard shortcut.                     |
43
+| `onSaveProjectAs` | `Function`       | Called when the user saves a project as a new project through the menu or through a keyboard shortcut.    |
44
+| `onOpenProject`   | `Function`       | Called when the user opens new project through the menu or through a keyboard shortcut.                   |
45
+
46
+> **Note**: For help with the file-related callbacks, see `useFileSystem`.
47
+
48
+## `useFileSystem`
49
+
50
+You can use the `useFileSystem` hook to get prepared callbacks for `onNewProject`, `onOpenProject`, `onSaveProject`, and `onSaveProjectAs`. These callbacks allow a user to save files via the [FileSystem](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) API.
51
+
52
+```ts
53
+import { TLDraw, useFileSystem } from '@tldraw/tldraw'
54
+
55
+function App() {
56
+  const fileSystemEvents = useFileSystem()
57
+
58
+  return <TLDraw {...fileSystemEvents} />
59
+}
60
+```
61
+
62
+## `TLDrawDocument`
63
+
64
+You can initialize or control the `<TLDraw>` component via its `document` property. A `TLDrawDocument` is an object with three properties:
65
+
66
+- `id` - A unique ID for this document
67
+- `pages` - A table of `TLDrawPage` objects
68
+- `pageStates` - A table of `TLPageState` objects
69
+- `version` - The document's version, used internally for migrations.
70
+
71
+```ts
72
+import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw'
73
+
74
+const myDocument: TLDrawDocument = {
75
+  id: 'doc',
76
+  version: TLDrawState.version,
77
+  pages: {
78
+    page1: {
79
+      id: 'page1',
80
+      shapes: {},
81
+      bindings: {},
82
+    },
83
+  },
84
+  pageStates: {
85
+    page1: {
86
+      id: 'page1',
87
+      selectedIds: [],
88
+      currentParentId: 'page1',
89
+      camera: {
90
+        point: [0, 0],
91
+        zoom: 1,
92
+      },
93
+    },
94
+  },
95
+}
96
+
97
+function App() {
98
+  return <TLDraw document={myDocument} />
99
+}
100
+```
101
+
102
+**Tip:** TLDraw is built on [@tldraw/core](https://github.com/tldraw/core). The pages and pageStates in TLDraw are objects containing `TLPage` and `TLPageState` objects from the core library. For more about these types, check out the [@tldraw/core](https://github.com/tldraw/core) documentation.
103
+
104
+**Important:** In the `pages` object, each `TLPage` object must be keyed under its `id` property. Likewise, each `TLPageState` object must be keyed under its `id`. In addition, each `TLPageState` object must have an `id` that matches its corresponding page.
105
+
106
+## Shapes
107
+
108
+Your `TLPage` objects may include shapes: objects that fit one of the `TLDrawShape` interfaces listed below. All `TLDrawShapes` extends a common interface:
109
+
110
+| Property              | Type             | Description                                                     |
111
+| --------------------- | ---------------- | --------------------------------------------------------------- |
112
+| `id`                  | `string`         | A unique ID for the shape.                                      |
113
+| `name`                | `string`         | The shape's name.                                               |
114
+| `type`                | `string`         | The shape's type.                                               |
115
+| `parentId`            | `string`         | The ID of the shape's parent (a shape or its page).             |
116
+| `childIndex`          | `number`         | The shape's order within its parent's children, indexed from 1. |
117
+| `point`               | `number[]`       | The `[x, y]` position of the shape.                             |
118
+| `rotation`            | `number[]`       | (optional) The shape's rotation in radians.                     |
119
+| `children`            | `string[]`       | (optional) The shape's child shape ids.                         |
120
+| `handles`             | `TLDrawHandle{}` | (optional) A table of `TLHandle` objects.                       |
121
+| `isLocked`            | `boolean`        | (optional) True if the shape is locked.                         |
122
+| `isHidden`            | `boolean`        | (optional) True if the shape is hidden.                         |
123
+| `isEditing`           | `boolean`        | (optional) True if the shape is currently editing.              |
124
+| `isGenerated`         | `boolean`        | (optional) True if the shape is generated.                      |
125
+| `isAspectRatioLocked` | `boolean`        | (optional) True if the shape's aspect ratio is locked.          |
126
+
127
+> **Important:** In order for re-ordering to work, a shape's `childIndex` values _must_ start from 1, not 0. The page or parent shape's "bottom-most" child should have a `childIndex` of 1.
128
+
129
+The `ShapeStyle` object is a common style API for all shapes.
130
+
131
+| Property   | Type         | Description                             |
132
+| ---------- | ------------ | --------------------------------------- |
133
+| `size`     | `SizeStyle`  | The size of the shape's stroke.         |
134
+| `dash`     | `DashStyle`  | The style of the shape's stroke.        |
135
+| `color`    | `ColorStyle` | The shape's color.                      |
136
+| `isFilled` | `boolean`    | (optional) True if the shape is filled. |
137
+
138
+### `DrawShape`
139
+
140
+A hand-drawn line.
141
+
142
+| Property | Type         | Description                               |
143
+| -------- | ------------ | ----------------------------------------- |
144
+| `points` | `number[][]` | An array of points as `[x, y, pressure]`. |
145
+
146
+#### `RectangleShape`
147
+
148
+A rectangular shape.
149
+
150
+| Property | Type       | Description                             |
151
+| -------- | ---------- | --------------------------------------- |
152
+| `size`   | `number[]` | The `[width, height]` of the rectangle. |
153
+
154
+### `EllipseShape`
155
+
156
+An elliptical shape.
157
+
158
+| Property | Type       | Description                         |
159
+| -------- | ---------- | ----------------------------------- |
160
+| `radius` | `number[]` | The `[x, y]` radius of the ellipse. |
161
+
162
+### `ArrowShape`
163
+
164
+An arrow that can connect shapes.
165
+
166
+| Property      | Type     | Description                                                             |
167
+| ------------- | -------- | ----------------------------------------------------------------------- |
168
+| `handles`     | `object` | An object with three `TLHandle` properties: `start`, `end`, and `bend`. |
169
+| `decorations` | `object` | An object with two properties `start`, `end`, and `bend`.               |
170
+
171
+### `TextShape`
172
+
173
+A line of text.
174
+
175
+| Property | Type     | Description               |
176
+| -------- | -------- | ------------------------- |
177
+| `text`   | `string` | The shape's text content. |
178
+
179
+### `StickyShape`
180
+
181
+A sticky note.
182
+
183
+| Property | Type     | Description               |
184
+| -------- | -------- | ------------------------- |
185
+| `text`   | `string` | The shape's text content. |
186
+
187
+## Bindings
188
+
189
+A binding is a connection **from** one shape and **to** another shape. At the moment, only arrows may be bound "from". Most shapes may be bound "to", except other `ArrowShape` and `DrawShape`s.
190
+
191
+| Property   | Type             | Description                                              |
192
+| ---------- | ---------------- | -------------------------------------------------------- |
193
+| `id`       | `string`         | The binding's own unique ID.                             |
194
+| `fromId`   | `string`         | The id of the `ArrowShape` that the binding is bound to. |
195
+| `toId`     | `string`         | The id of the other shape that the binding is bound to.  |
196
+| `handleId` | `start` or `end` | The connected arrow handle.                              |
197
+| `distance` | `number`         | The distance from the bound point.                       |
198
+| `point`    | `number[]`       | A normalized point representing the bound point.         |
199
+
200
+## `TLDrawState` API
201
+
202
+You can change the `TLDraw` component's state through an imperative API called `TLDrawState`. To access this API, use the `onMount` callback, or any of the component's callback props, like `onPersist`.
203
+
204
+```tsx
205
+import { TLDraw, TLDrawState } from '@tldraw/tldraw'
206
+
207
+function App() {
208
+  const handleMount = React.useCallback((state: TLDrawState) => {
209
+    state.selectAll()
210
+  }, [])
211
+
212
+  return <TLDraw onMount={handleMount} />
213
+}
214
+```
215
+
216
+To view the full documentation of the `TLDrawState` API, generate the project's documentation by running `yarn docs` from the root folder, then open the file at:
217
+
218
+```
219
+/packages/tldraw/docs/classes/TLDrawState.html
220
+```
221
+
222
+Here are some useful methods:
223
+
224
+- `loadDocument`
225
+- `select`
226
+- `selectAll`
227
+- `selectNone`
228
+- `delete`
229
+- `deleteAll`
230
+- `deletePage`
231
+- `changePage`
232
+- `cut`
233
+- `copy`
234
+- `paste`
235
+- `copyJson`
236
+- `copySvg`
237
+- `undo`
238
+- `redo`
239
+- `zoomIn`
240
+- `zoomOut`
241
+- `zoomToContent`
242
+- `zoomToSelection`
243
+- `zoomToFit`
244
+- `zoomTo`
245
+- `resetZoom`
246
+- `setCamera`
247
+- `resetCamera`
248
+- `align`
249
+- `distribute`
250
+- `stretch`
251
+- `nudge`
252
+- `duplicate`
253
+- `flipHorizontal`
254
+- `flipVertical`
255
+- `rotate`
256
+- `style`
257
+- `group`
258
+- `ungroup`
259
+- `createShapes`
260
+- `updateShapes`
261
+- `updateDocument`
262
+- `updateUsers`
263
+- `removeUser`
264
+- `setSetting`
265
+- `selectTool`
266
+- `cancel`
267
+
268
+Check the generated docs, source or the TypeScript types for more on these and other methods.

+ 5
- 0
guides/publishing.md View File

@@ -0,0 +1,5 @@
1
+# Publishing
2
+
3
+At the moment, publishing is done by hand by the project's maintainers.
4
+
5
+This guide will be updated when more information is available.

+ 3
- 381
packages/tldraw/README.md View File

@@ -4,388 +4,10 @@
4 4
 
5 5
 # @tldraw/tldraw
6 6
 
7
-This package contains the [tldraw](https://tldraw.com) editor as a React component named `<TLDraw>`. You can use this package to embed the editor in any React application.
7
+This package contains the [TLDraw](https://tldraw.com) editor as a React component named `<TLDraw>`. You can use this package to embed the editor in any React application.
8 8
 
9
-🎨 Want to build your own tldraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
9
+🎨 Want to build your own TLDraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
10 10
 
11 11
 💕 Love this library? Consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
12 12
 
13
-## Installation
14
-
15
-Use your package manager of choice to install `@tldraw/tldraw` and its peer dependencies.
16
-
17
-```bash
18
-yarn add @tldraw/tldraw
19
-# or
20
-npm i @tldraw/tldraw
21
-```
22
-
23
-## Usage
24
-
25
-Import the `TLDraw` React component and use it in your app.
26
-
27
-```tsx
28
-import { TLDraw } from '@tldraw/tldraw'
29
-
30
-function App() {
31
-  return <TLDraw />
32
-}
33
-```
34
-
35
-### Persisting the State
36
-
37
-You can use the `id` to persist the state in a user's browser storage.
38
-
39
-```tsx
40
-import { TLDraw } from '@tldraw/tldraw'
41
-
42
-function App() {
43
-  return <TLDraw id="myState" />
44
-}
45
-```
46
-
47
-### Controlling the Component through Props
48
-
49
-You can control the `TLDraw` component through its props.
50
-
51
-```tsx
52
-import { TLDraw, TLDrawDocument } from '@tldraw/tldraw'
53
-
54
-function App() {
55
-  const myDocument: TLDrawDocument = {}
56
-
57
-  return <TLDraw document={document} />
58
-}
59
-```
60
-
61
-### Controlling the Component through the TLDrawState API
62
-
63
-You can also control the `TLDraw` component imperatively through the `TLDrawState` API.
64
-
65
-```tsx
66
-import { TLDraw, TLDrawState } from '@tldraw/tldraw'
67
-
68
-function App() {
69
-  const handleMount = React.useCallback((state: TLDrawState) => {
70
-    state.selectAll()
71
-  }, [])
72
-
73
-  return <TLDraw onMount={handleMount} />
74
-}
75
-```
76
-
77
-Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section for more on this API.
78
-
79
-### Responding to Changes
80
-
81
-You can respond to changes and user actions using the `onChange` callback.
82
-
83
-```tsx
84
-import { TLDraw, TLDrawState } from '@tldraw/tldraw'
85
-
86
-function App() {
87
-  const handleChange = React.useCallback((state: TLDrawState, reason: string) => {}, [])
88
-
89
-  return <TLDraw onMount={handleMount} />
90
-}
91
-```
92
-
93
-Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section for more on this API.
94
-
95
-## Documentation
96
-
97
-### `TLDraw`
98
-
99
-The `TLDraw` React component is the [tldraw](https://tldraw.com) editor exported as a standalone component. You can control the editor through props, or through the `TLDrawState`'s imperative API. **All props are optional.**
100
-
101
-| Prop              | Type             | Description                                                                                               |
102
-| ----------------- | ---------------- | --------------------------------------------------------------------------------------------------------- |
103
-| `id`              | `string`         | An id under which to persist the component's state.                                                       |
104
-| `document`        | `TLDrawDocument` | An initial [`TLDrawDocument`](#tldrawdocument) object.                                                    |
105
-| `currentPageId`   | `string`         | A current page id, referencing the `TLDrawDocument` object provided via the `document` prop.              |
106
-| `autofocus`       | `boolean`        | Whether the editor should immediately receive focus. Defaults to true.                                    |
107
-| `showMenu`        | `boolean`        | Whether to show the menu.                                                                                 |
108
-| `showPages`       | `boolean`        | Whether to show the pages menu.                                                                           |
109
-| `showStyles`      | `boolean`        | Whether to show the styles menu.                                                                          |
110
-| `showTools`       | `boolean`        | Whether to show the tools.                                                                                |
111
-| `showUI`          | `boolean`        | Whether to show any UI other than the canvas.                                                             |
112
-| `onMount`         | `Function`       | Called when the editor first mounts, receiving the current `TLDrawState`.                                 |
113
-| `onPatch`         | `Function`       | Called when the state is updated via a patch.                                                             |
114
-| `onCommand`       | `Function`       | Called when the state is updated via a command.                                                           |
115
-| `onPersist`       | `Function`       | Called when the state is persisted after an action.                                                       |
116
-| `onChange`        | `Function`       | Called when the `TLDrawState` updates for any reason.                                                     |
117
-| `onUserChange`    | `Function`       | Called when the user's "presence" information changes.                                                    |
118
-| `onUndo`          | `Function`       | Called when the `TLDrawState` updates after an undo.                                                      |
119
-| `onRedo`          | `Function`       | Called when the `TLDrawState` updates after a redo.                                                       |
120
-| `onSignIn`        | `Function`       | Called when the user selects Sign In from the menu.                                                       |
121
-| `onSignOut`       | `Function`       | Called when the user selects Sign Out from the menu.                                                      |
122
-| `onNewProject`    | `Function`       | Called when the user when the user creates a new project through the menu or through a keyboard shortcut. |
123
-| `onSaveProject`   | `Function`       | Called when the user saves a project through the menu or through a keyboard shortcut.                     |
124
-| `onSaveProjectAs` | `Function`       | Called when the user saves a project as a new project through the menu or through a keyboard shortcut.    |
125
-| `onOpenProject`   | `Function`       | Called when the user opens new project through the menu or through a keyboard shortcut.                   |
126
-
127
-> **Note**: For help with the file-related callbacks, see `useFileSystem`.
128
-
129
-### `useFileSystem`
130
-
131
-You can use the `useFileSystem` hook to get prepared callbacks for `onNewProject`, `onOpenProject`, `onSaveProject`, and `onSaveProjectAs`. These callbacks allow a user to save files via the [FileSystem](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) API.
132
-
133
-```ts
134
-import { TLDraw, useFileSystem } from '@tldraw/tldraw'
135
-
136
-function App() {
137
-  const fileSystemEvents = useFileSystem()
138
-
139
-  return <TLDraw {...fileSystemEvents} />
140
-}
141
-```
142
-
143
-### `TLDrawDocument`
144
-
145
-You can initialize or control the `<TLDraw>` component via its `document` property. A `TLDrawDocument` is an object with three properties:
146
-
147
-- `id` - A unique ID for this document
148
-- `pages` - A table of `TLDrawPage` objects
149
-- `pageStates` - A table of `TLPageState` objects
150
-- `version` - The document's version, used internally for migrations.
151
-
152
-```ts
153
-import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw'
154
-
155
-const myDocument: TLDrawDocument = {
156
-  id: 'doc',
157
-  version: TLDrawState.version,
158
-  pages: {
159
-    page1: {
160
-      id: 'page1',
161
-      shapes: {},
162
-      bindings: {},
163
-    },
164
-  },
165
-  pageStates: {
166
-    page1: {
167
-      id: 'page1',
168
-      selectedIds: [],
169
-      currentParentId: 'page1',
170
-      camera: {
171
-        point: [0, 0],
172
-        zoom: 1,
173
-      },
174
-    },
175
-  },
176
-}
177
-
178
-function App() {
179
-  return <TLDraw document={myDocument} />
180
-}
181
-```
182
-
183
-**Tip:** TLDraw is built on [@tldraw/core](https://github.com/tldraw/core). The pages and pageStates in TLDraw are objects containing `TLPage` and `TLPageState` objects from the core library. For more about these types, check out the [@tldraw/core](https://github.com/tldraw/core) documentation.
184
-
185
-**Important:** In the `pages` object, each `TLPage` object must be keyed under its `id` property. Likewise, each `TLPageState` object must be keyed under its `id`. In addition, each `TLPageState` object must have an `id` that matches its corresponding page.
186
-
187
-### Shapes
188
-
189
-Your `TLPage` objects may include shapes: objects that fit one of the `TLDrawShape` interfaces listed below. All `TLDrawShapes` extends a common interface:
190
-
191
-| Property              | Type             | Description                                                     |
192
-| --------------------- | ---------------- | --------------------------------------------------------------- |
193
-| `id`                  | `string`         | A unique ID for the shape.                                      |
194
-| `name`                | `string`         | The shape's name.                                               |
195
-| `type`                | `string`         | The shape's type.                                               |
196
-| `parentId`            | `string`         | The ID of the shape's parent (a shape or its page).             |
197
-| `childIndex`          | `number`         | The shape's order within its parent's children, indexed from 1. |
198
-| `point`               | `number[]`       | The `[x, y]` position of the shape.                             |
199
-| `rotation`            | `number[]`       | (optional) The shape's rotation in radians.                     |
200
-| `children`            | `string[]`       | (optional) The shape's child shape ids.                         |
201
-| `handles`             | `TLDrawHandle{}` | (optional) A table of `TLHandle` objects.                       |
202
-| `isLocked`            | `boolean`        | (optional) True if the shape is locked.                         |
203
-| `isHidden`            | `boolean`        | (optional) True if the shape is hidden.                         |
204
-| `isEditing`           | `boolean`        | (optional) True if the shape is currently editing.              |
205
-| `isGenerated`         | `boolean`        | (optional) True if the shape is generated.                      |
206
-| `isAspectRatioLocked` | `boolean`        | (optional) True if the shape's aspect ratio is locked.          |
207
-
208
-> **Important:** In order for re-ordering to work, a shape's `childIndex` values _must_ start from 1, not 0. The page or parent shape's "bottom-most" child should have a `childIndex` of 1.
209
-
210
-The `ShapeStyle` object is a common style API for all shapes.
211
-
212
-| Property   | Type         | Description                             |
213
-| ---------- | ------------ | --------------------------------------- |
214
-| `size`     | `SizeStyle`  | The size of the shape's stroke.         |
215
-| `dash`     | `DashStyle`  | The style of the shape's stroke.        |
216
-| `color`    | `ColorStyle` | The shape's color.                      |
217
-| `isFilled` | `boolean`    | (optional) True if the shape is filled. |
218
-
219
-#### `DrawShape`
220
-
221
-A hand-drawn line.
222
-
223
-| Property | Type         | Description                               |
224
-| -------- | ------------ | ----------------------------------------- |
225
-| `points` | `number[][]` | An array of points as `[x, y, pressure]`. |
226
-
227
-##### `RectangleShape`
228
-
229
-A rectangular shape.
230
-
231
-| Property | Type       | Description                             |
232
-| -------- | ---------- | --------------------------------------- |
233
-| `size`   | `number[]` | The `[width, height]` of the rectangle. |
234
-
235
-#### `EllipseShape`
236
-
237
-An elliptical shape.
238
-
239
-| Property | Type       | Description                         |
240
-| -------- | ---------- | ----------------------------------- |
241
-| `radius` | `number[]` | The `[x, y]` radius of the ellipse. |
242
-
243
-#### `ArrowShape`
244
-
245
-An arrow that can connect shapes.
246
-
247
-| Property      | Type     | Description                                                             |
248
-| ------------- | -------- | ----------------------------------------------------------------------- |
249
-| `handles`     | `object` | An object with three `TLHandle` properties: `start`, `end`, and `bend`. |
250
-| `decorations` | `object` | An object with two properties `start`, `end`, and `bend`.               |
251
-
252
-#### `TextShape`
253
-
254
-A line of text.
255
-
256
-| Property | Type     | Description               |
257
-| -------- | -------- | ------------------------- |
258
-| `text`   | `string` | The shape's text content. |
259
-
260
-#### `StickyShape`
261
-
262
-A sticky note.
263
-
264
-| Property | Type     | Description               |
265
-| -------- | -------- | ------------------------- |
266
-| `text`   | `string` | The shape's text content. |
267
-
268
-### Bindings
269
-
270
-A binding is a connection **from** one shape and **to** another shape. At the moment, only arrows may be bound "from". Most shapes may be bound "to", except other `ArrowShape` and `DrawShape`s.
271
-
272
-| Property   | Type             | Description                                              |
273
-| ---------- | ---------------- | -------------------------------------------------------- |
274
-| `id`       | `string`         | The binding's own unique ID.                             |
275
-| `fromId`   | `string`         | The id of the `ArrowShape` that the binding is bound to. |
276
-| `toId`     | `string`         | The id of the other shape that the binding is bound to.  |
277
-| `handleId` | `start` or `end` | The connected arrow handle.                              |
278
-| `distance` | `number`         | The distance from the bound point.                       |
279
-| `point`    | `number[]`       | A normalized point representing the bound point.         |
280
-
281
-### `TLDrawState` API
282
-
283
-You can change the `TLDraw` component's state through an imperative API called `TLDrawState`. To access this API, use the `onMount` callback, or any of the component's callback props, like `onPersist`.
284
-
285
-```tsx
286
-import { TLDraw, TLDrawState } from '@tldraw/tldraw'
287
-
288
-function App() {
289
-  const handleMount = React.useCallback((state: TLDrawState) => {
290
-    state.selectAll()
291
-  }, [])
292
-
293
-  return <TLDraw onMount={handleMount} />
294
-}
295
-```
296
-
297
-To view the full documentation of the `TLDrawState` API, generate the project's documentation by running `yarn docs` from the root folder, then open the file at:
298
-
299
-```
300
-/packages/tldraw/docs/classes/TLDrawState.html
301
-```
302
-
303
-Here are some useful methods:
304
-
305
-- `loadDocument`
306
-- `select`
307
-- `selectAll`
308
-- `selectNone`
309
-- `delete`
310
-- `deleteAll`
311
-- `deletePage`
312
-- `changePage`
313
-- `cut`
314
-- `copy`
315
-- `paste`
316
-- `copyJson`
317
-- `copySvg`
318
-- `undo`
319
-- `redo`
320
-- `zoomIn`
321
-- `zoomOut`
322
-- `zoomToContent`
323
-- `zoomToSelection`
324
-- `zoomToFit`
325
-- `zoomTo`
326
-- `resetZoom`
327
-- `setCamera`
328
-- `resetCamera`
329
-- `align`
330
-- `distribute`
331
-- `stretch`
332
-- `nudge`
333
-- `duplicate`
334
-- `flipHorizontal`
335
-- `flipVertical`
336
-- `rotate`
337
-- `style`
338
-- `group`
339
-- `ungroup`
340
-- `createShapes`
341
-- `updateShapes`
342
-- `updateDocument`
343
-- `updateUsers`
344
-- `removeUser`
345
-- `setSetting`
346
-- `selectTool`
347
-- `cancel`
348
-
349
-Check the generated docs, source or the TypeScript types for more on these and other methods.
350
-
351
-## Local Development
352
-
353
-From the root folder:
354
-
355
-- Run `yarn` to install dependencies.
356
-
357
-- Run `yarn start` to start the development server for the package and for the example.
358
-
359
-- Open `localhost:5420` to view the example project.
360
-
361
-**Note:** The multiplayer examples and endpoints currently require an API key from [Liveblocks](https://liveblocks.io/), however the storage services that are used in TLDraw are currently in alpha and (as of November 2021) not accessible to the general public. You won't be able to authenticate and run these parts of the project.
362
-
363
-Other scripts:
364
-
365
-- Run `yarn test` to execute unit tests via [Jest](https://jestjs.io).
366
-
367
-- Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/).
368
-
369
-## Example
370
-
371
-See the `example` folder for examples of how to use the `<TLDraw/>` component.
372
-
373
-## Community
374
-
375
-### Support
376
-
377
-Need help? Please [open an issue](https://github.com/tldraw/tldraw/issues/new) for support.
378
-
379
-### Discussion
380
-
381
-Want to connect with other devs? Visit the [Discord channel](https://discord.gg/s4FXZ6fppJ).
382
-
383
-### License
384
-
385
-This project is licensed under MIT.
386
-
387
-If you're using the library in a commercial product, please consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
388
-
389
-## Author
390
-
391
-- [@steveruizok](https://twitter.com/steveruizok)
13
+For documentation, see the [TLDraw](https://github.com/tldraw) repository.

+ 2
- 2
packages/tldraw/package.json View File

@@ -24,7 +24,7 @@
24 24
   "scripts": {
25 25
     "start:electron": "yarn start",
26 26
     "start": "node scripts/dev & yarn types:dev",
27
-    "build": "node scripts/build && yarn types:build && node scripts/copy-readme",
27
+    "build": "node scripts/build && yarn types:build && node scripts/copy-files",
28 28
     "types:dev": "tsc -w",
29 29
     "types:build": "tsc -p tsconfig.build.json && tsconfig-replace-paths -p tsconfig.build.json",
30 30
     "lint": "eslint src/ --ext .ts,.tsx",
@@ -59,4 +59,4 @@
59 59
     "tsconfig-replace-paths": "^0.0.5"
60 60
   },
61 61
   "gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
62
-}
62
+}

packages/tldraw/scripts/copy-readme.js → packages/tldraw/scripts/copy-files.js View File

@@ -1,7 +1,7 @@
1 1
 /* eslint-disable */
2 2
 const fs = require('fs')
3 3
 
4
-const filesToCopy = ['README.md', 'CHANGELOG.md', 'LICENSE.md', 'card-repo.png']
4
+const filesToCopy = ['CHANGELOG.md', 'LICENSE.md', 'card-repo.png']
5 5
 
6 6
 filesToCopy.forEach((file) => {
7 7
   fs.copyFile(`../../${file}`, `./${file}`, (err) => {

Loading…
Cancel
Save