From 5be36d9bd84f2e7ff68ab0afd880b34c1a385499 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Thu, 11 Nov 2021 11:41:04 +0000 Subject: [PATCH] changelog --- CHANGELOG.md | 4 + lerna.json | 4 +- packages/tldraw/CHANGELOG.md | 9 +- packages/tldraw/README.md | 180 +++++++++++++++++++++-------------- 4 files changed, 123 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d042b1d6..c9dca1e8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.13 + +- Fixes bugs related to `readOnly` mode. + ## 0.1.12 - Fixes behavior of context menu. diff --git a/lerna.json b/lerna.json index c40d09a19..2c5454c1a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.1.12", + "version": "0.1.11", "registry": "https://registry.npmjs.org/", "publishConfig": { "access": "public", @@ -7,4 +7,4 @@ }, "npmClient": "yarn", "useWorkspaces": true -} +} \ No newline at end of file diff --git a/packages/tldraw/CHANGELOG.md b/packages/tldraw/CHANGELOG.md index 8260155aa..c9dca1e8c 100644 --- a/packages/tldraw/CHANGELOG.md +++ b/packages/tldraw/CHANGELOG.md @@ -1,6 +1,13 @@ -## 0.1.11 +## 0.1.13 + +- Fixes bugs related to `readOnly` mode. + +## 0.1.12 - Fixes behavior of context menu. + +## 0.1.11 + - Fixes appearance of keyboard shortcuts in tooltips. ## 0.1.10 diff --git a/packages/tldraw/README.md b/packages/tldraw/README.md index 8ac2cc67b..209415905 100644 --- a/packages/tldraw/README.md +++ b/packages/tldraw/README.md @@ -98,29 +98,51 @@ Internally, the `TLDraw` component's user interface uses this API to make change 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.** -| Prop | Type | Description | -| --------------- | ---------------- | -------------------------------------------------------------------------------------------- | -| `id` | `string` | An id under which to persist the component's state. | -| `document` | `TLDrawDocument` | An initial [`TLDrawDocument`](#tldrawdocument) object. | -| `currentPageId` | `string` | A current page id, referencing the `TLDrawDocument` object provided via the `document` prop. | -| `onMount` | `Function` | Called when the editor first mounts, receiving the current `TLDrawState`. | -| `onPatch` | `Function` | Called when the state is updated via a patch. | -| `onCommand` | `Function` | Called when the state is updated via a command. | -| `onPersist` | `Function` | Called when the state is persisted after an action. | -| `onChange` | `Function` | Called when the `TLDrawState` updates for any reason. | -| `onUndo` | `Function` | Called when the `TLDrawState` updates after an undo. | -| `onRedo` | `Function` | Called when the `TLDrawState` updates after a redo. | -| `onUserChange` | `Function` | Called when the user's "presence" information changes. | -| `autofocus` | `boolean` | Whether the editor should immediately receive focus. Defaults to true. | -| `showMenu` | `boolean` | Whether to show the menu. | -| `showPages` | `boolean` | Whether to show the pages menu. | -| `showStyles` | `boolean` | Whether to show the styles menu. | -| `showTools` | `boolean` | Whether to show the tools. | -| `showUI` | `boolean` | Whether to show any UI other than the canvas. | +| Prop | Type | Description | +| ----------------- | ---------------- | --------------------------------------------------------------------------------------------------------- | +| `id` | `string` | An id under which to persist the component's state. | +| `document` | `TLDrawDocument` | An initial [`TLDrawDocument`](#tldrawdocument) object. | +| `currentPageId` | `string` | A current page id, referencing the `TLDrawDocument` object provided via the `document` prop. | +| `autofocus` | `boolean` | Whether the editor should immediately receive focus. Defaults to true. | +| `showMenu` | `boolean` | Whether to show the menu. | +| `showPages` | `boolean` | Whether to show the pages menu. | +| `showStyles` | `boolean` | Whether to show the styles menu. | +| `showTools` | `boolean` | Whether to show the tools. | +| `showUI` | `boolean` | Whether to show any UI other than the canvas. | +| `onMount` | `Function` | Called when the editor first mounts, receiving the current `TLDrawState`. | +| `onPatch` | `Function` | Called when the state is updated via a patch. | +| `onCommand` | `Function` | Called when the state is updated via a command. | +| `onPersist` | `Function` | Called when the state is persisted after an action. | +| `onChange` | `Function` | Called when the `TLDrawState` updates for any reason. | +| `onUserChange` | `Function` | Called when the user's "presence" information changes. | +| `onUndo` | `Function` | Called when the `TLDrawState` updates after an undo. | +| `onRedo` | `Function` | Called when the `TLDrawState` updates after a redo. | +| `onSignIn` | `Function` | Called when the user selects Sign In from the menu. | +| `onSignOut` | `Function` | Called when the user selects Sign Out from the menu. | +| `onNewProject` | `Function` | Called when the user when the user creates a new project through the menu or through a keyboard shortcut. | +| `onSaveProject` | `Function` | Called when the user saves a project through the menu or through a keyboard shortcut. | +| `onSaveProjectAs` | `Function` | Called when the user saves a project as a new project through the menu or through a keyboard shortcut. | +| `onOpenProject` | `Function` | Called when the user opens new project through the menu or through a keyboard shortcut. | + +> **Note**: For help with the file-related callbacks, see `useFileSystem`. + +### `useFileSystem` + +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. + +```ts +import { TLDraw, useFileSystem } from '@tldraw/tldraw' + +function App() { + const fileSystemEvents = useFileSystem() + + return +} +``` ### `TLDrawDocument` -A `TLDrawDocument` is an object with three properties: +You can initialize or control the `` component via its `document` property. A `TLDrawDocument` is an object with three properties: - `id` - A unique ID for this document - `pages` - A table of `TLDrawPage` objects @@ -130,7 +152,7 @@ A `TLDrawDocument` is an object with three properties: ```ts import { TLDrawDocument, TLDrawState } from '@tldraw/tldraw' -const tldocument: TLDrawDocument = { +const myDocument: TLDrawDocument = { id: 'doc', version: TLDrawState.version, pages: { @@ -152,9 +174,13 @@ const tldocument: TLDrawDocument = { }, }, } + +function App() { + return +} ``` -**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. +**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. **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. @@ -179,7 +205,7 @@ Your `TLPage` objects may include shapes: objects that fit one of the `TLDrawSha | `isGenerated` | `boolean` | (optional) True if the shape is generated. | | `isAspectRatioLocked` | `boolean` | (optional) True if the shape's aspect ratio is locked. | -> **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. +> **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. The `ShapeStyle` object is a common style API for all shapes. @@ -268,71 +294,81 @@ function App() { } ``` -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. +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: + +``` +/packages/tldraw/docs/classes/TLDrawState.html +``` Here are some useful methods: -| Method | Description | -| ----------------- | ----------- | -| `loadDocument` | | -| `select` | | -| `selectAll` | | -| `selectNone` | | -| `delete` | | -| `deleteAll` | | -| `deletePage` | | -| `changePage` | | -| `cut` | | -| `copy` | | -| `paste` | | -| `copyJson` | | -| `copySvg` | | -| `undo` | | -| `redo` | | -| `zoomIn` | | -| `zoomOut` | | -| `zoomToContent` | | -| `zoomToSelection` | | -| `zoomToFit` | | -| `zoomTo` | | -| `resetZoom` | | -| `setCamera` | | -| `resetCamera` | | -| `align` | | -| `distribute` | | -| `stretch` | | -| `nudge` | | -| `duplicate` | | -| `flipHorizontal` | | -| `flipVertical` | | -| `rotate` | | -| `style` | | -| `group` | | -| `ungroup` | | -| `createShapes` | | -| `updateShapes` | | -| `updateDocument` | | -| `updateUsers` | | -| `removeUser` | | -| `setSetting` | | -| `selectTool` | | -| `cancel` | | +- `loadDocument` +- `select` +- `selectAll` +- `selectNone` +- `delete` +- `deleteAll` +- `deletePage` +- `changePage` +- `cut` +- `copy` +- `paste` +- `copyJson` +- `copySvg` +- `undo` +- `redo` +- `zoomIn` +- `zoomOut` +- `zoomToContent` +- `zoomToSelection` +- `zoomToFit` +- `zoomTo` +- `resetZoom` +- `setCamera` +- `resetCamera` +- `align` +- `distribute` +- `stretch` +- `nudge` +- `duplicate` +- `flipHorizontal` +- `flipVertical` +- `rotate` +- `style` +- `group` +- `ungroup` +- `createShapes` +- `updateShapes` +- `updateDocument` +- `updateUsers` +- `removeUser` +- `setSetting` +- `selectTool` +- `cancel` + +Check the generated docs, source or the TypeScript types for more on these and other methods. ## Local Development +From the root folder: + - Run `yarn` to install dependencies. - Run `yarn start` to start the development server for the package and for the example. - Open `localhost:5420` to view the example project. +**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. + +Other scripts: + - Run `yarn test` to execute unit tests via [Jest](https://jestjs.io). - Run `yarn docs` to build the docs via [ts-doc](https://typedoc.org/). ## Example -See the `example` folder. +See the `example` folder for examples of how to use the `` component. ## Community @@ -346,7 +382,9 @@ Want to connect with other devs? Visit the [Discord channel](https://discord.gg/ ### License -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). +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). ## Author