Steve Ruiz 3 роки тому
джерело
коміт
5be36d9bd8
4 змінених файлів з 123 додано та 74 видалено
  1. 4
    0
      CHANGELOG.md
  2. 2
    2
      lerna.json
  3. 8
    1
      packages/tldraw/CHANGELOG.md
  4. 109
    71
      packages/tldraw/README.md

+ 4
- 0
CHANGELOG.md Переглянути файл

1
+## 0.1.13
2
+
3
+- Fixes bugs related to `readOnly` mode.
4
+
1
 ## 0.1.12
5
 ## 0.1.12
2
 
6
 
3
 - Fixes behavior of context menu.
7
 - Fixes behavior of context menu.

+ 2
- 2
lerna.json Переглянути файл

1
 {
1
 {
2
-  "version": "0.1.12",
2
+  "version": "0.1.11",
3
   "registry": "https://registry.npmjs.org/",
3
   "registry": "https://registry.npmjs.org/",
4
   "publishConfig": {
4
   "publishConfig": {
5
     "access": "public",
5
     "access": "public",
7
   },
7
   },
8
   "npmClient": "yarn",
8
   "npmClient": "yarn",
9
   "useWorkspaces": true
9
   "useWorkspaces": true
10
-}
10
+}

+ 8
- 1
packages/tldraw/CHANGELOG.md Переглянути файл

1
-## 0.1.11
1
+## 0.1.13
2
+
3
+- Fixes bugs related to `readOnly` mode.
4
+
5
+## 0.1.12
2
 
6
 
3
 - Fixes behavior of context menu.
7
 - Fixes behavior of context menu.
8
+
9
+## 0.1.11
10
+
4
 - Fixes appearance of keyboard shortcuts in tooltips.
11
 - Fixes appearance of keyboard shortcuts in tooltips.
5
 
12
 
6
 ## 0.1.10
13
 ## 0.1.10

+ 109
- 71
packages/tldraw/README.md Переглянути файл

98
 
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.**
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
 
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
-| `onMount`       | `Function`       | Called when the editor first mounts, receiving the current `TLDrawState`.                    |
107
-| `onPatch`       | `Function`       | Called when the state is updated via a patch.                                                |
108
-| `onCommand`     | `Function`       | Called when the state is updated via a command.                                              |
109
-| `onPersist`     | `Function`       | Called when the state is persisted after an action.                                          |
110
-| `onChange`      | `Function`       | Called when the `TLDrawState` updates for any reason.                                        |
111
-| `onUndo`        | `Function`       | Called when the `TLDrawState` updates after an undo.                                         |
112
-| `onRedo`        | `Function`       | Called when the `TLDrawState` updates after a redo.                                          |
113
-| `onUserChange`  | `Function`       | Called when the user's "presence" information changes.                                       |
114
-| `autofocus`     | `boolean`        | Whether the editor should immediately receive focus. Defaults to true.                       |
115
-| `showMenu`      | `boolean`        | Whether to show the menu.                                                                    |
116
-| `showPages`     | `boolean`        | Whether to show the pages menu.                                                              |
117
-| `showStyles`    | `boolean`        | Whether to show the styles menu.                                                             |
118
-| `showTools`     | `boolean`        | Whether to show the tools.                                                                   |
119
-| `showUI`        | `boolean`        | Whether to show any UI other than the canvas.                                                |
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
+```
120
 
142
 
121
 ### `TLDrawDocument`
143
 ### `TLDrawDocument`
122
 
144
 
123
-A `TLDrawDocument` is an object with three properties:
145
+You can initialize or control the `<TLDraw>` component via its `document` property. A `TLDrawDocument` is an object with three properties:
124
 
146
 
125
 - `id` - A unique ID for this document
147
 - `id` - A unique ID for this document
126
 - `pages` - A table of `TLDrawPage` objects
148
 - `pages` - A table of `TLDrawPage` objects
130
 ```ts
152
 ```ts
131
 import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw'
153
 import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw'
132
 
154
 
133
-const tldocument: TLDrawDocument = {
155
+const myDocument: TLDrawDocument = {
134
   id: 'doc',
156
   id: 'doc',
135
   version: TLDrawState.version,
157
   version: TLDrawState.version,
136
   pages: {
158
   pages: {
152
     },
174
     },
153
   },
175
   },
154
 }
176
 }
177
+
178
+function App() {
179
+  return <TLDraw document={myDocument} />
180
+}
155
 ```
181
 ```
156
 
182
 
157
-**Tip:** TLDraw is built on [@tldraw/core](https://github.com/tldraw/core). The pages and pageStates in TLDraw are just 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.
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.
158
 
184
 
159
 **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.
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.
160
 
186
 
179
 | `isGenerated`         | `boolean`        | (optional) True if the shape is generated.                      |
205
 | `isGenerated`         | `boolean`        | (optional) True if the shape is generated.                      |
180
 | `isAspectRatioLocked` | `boolean`        | (optional) True if the shape's aspect ratio is locked.          |
206
 | `isAspectRatioLocked` | `boolean`        | (optional) True if the shape's aspect ratio is locked.          |
181
 
207
 
182
-> **Important:** In order for re-ordering to work correctly, 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.
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.
183
 
209
 
184
 The `ShapeStyle` object is a common style API for all shapes.
210
 The `ShapeStyle` object is a common style API for all shapes.
185
 
211
 
268
 }
294
 }
269
 ```
295
 ```
270
 
296
 
271
-The `TLDrawState` API is too large to document here. To view documentation for the API, build the documentation by running `yarn docs` from the root folder and open the file at `/packages/tldraw/docs/classes/TLDrawState.html` in your browser.
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
+```
272
 
302
 
273
 Here are some useful methods:
303
 Here are some useful methods:
274
 
304
 
275
-| Method            | Description |
276
-| ----------------- | ----------- |
277
-| `loadDocument`    |             |
278
-| `select`          |             |
279
-| `selectAll`       |             |
280
-| `selectNone`      |             |
281
-| `delete`          |             |
282
-| `deleteAll`       |             |
283
-| `deletePage`      |             |
284
-| `changePage`      |             |
285
-| `cut`             |             |
286
-| `copy`            |             |
287
-| `paste`           |             |
288
-| `copyJson`        |             |
289
-| `copySvg`         |             |
290
-| `undo`            |             |
291
-| `redo`            |             |
292
-| `zoomIn`          |             |
293
-| `zoomOut`         |             |
294
-| `zoomToContent`   |             |
295
-| `zoomToSelection` |             |
296
-| `zoomToFit`       |             |
297
-| `zoomTo`          |             |
298
-| `resetZoom`       |             |
299
-| `setCamera`       |             |
300
-| `resetCamera`     |             |
301
-| `align`           |             |
302
-| `distribute`      |             |
303
-| `stretch`         |             |
304
-| `nudge`           |             |
305
-| `duplicate`       |             |
306
-| `flipHorizontal`  |             |
307
-| `flipVertical`    |             |
308
-| `rotate`          |             |
309
-| `style`           |             |
310
-| `group`           |             |
311
-| `ungroup`         |             |
312
-| `createShapes`    |             |
313
-| `updateShapes`    |             |
314
-| `updateDocument`  |             |
315
-| `updateUsers`     |             |
316
-| `removeUser`      |             |
317
-| `setSetting`      |             |
318
-| `selectTool`      |             |
319
-| `cancel`          |             |
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.
320
 
350
 
321
 ## Local Development
351
 ## Local Development
322
 
352
 
353
+From the root folder:
354
+
323
 - Run `yarn` to install dependencies.
355
 - Run `yarn` to install dependencies.
324
 
356
 
325
 - Run `yarn start` to start the development server for the package and for the example.
357
 - Run `yarn start` to start the development server for the package and for the example.
326
 
358
 
327
 - Open `localhost:5420` to view the example project.
359
 - Open `localhost:5420` to view the example project.
328
 
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
+
329
 - Run `yarn test` to execute unit tests via [Jest](https://jestjs.io).
365
 - Run `yarn test` to execute unit tests via [Jest](https://jestjs.io).
330
 
366
 
331
 - Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/).
367
 - Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/).
332
 
368
 
333
 ## Example
369
 ## Example
334
 
370
 
335
-See the `example` folder.
371
+See the `example` folder for examples of how to use the `<TLDraw/>` component.
336
 
372
 
337
 ## Community
373
 ## Community
338
 
374
 
346
 
382
 
347
 ### License
383
 ### License
348
 
384
 
349
-This project is licensed under MIT. If you're using the library in a commercial product, please consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
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).
350
 
388
 
351
 ## Author
389
 ## Author
352
 
390
 

Завантаження…
Відмінити
Зберегти