tldraw/apps/examples/src
Steve Ruiz 0c4174c0b8
[refactor] User-facing APIs (#1478)
This PR updates our user-facing APIs for the Tldraw and TldrawEditor
components, as well as the Editor (App). It mainly incorporates surface
changes from #1450 without any changes to validators or migrators,
incorporating feedback / discussion with @SomeHats and @ds300.

Here we:
- remove the TldrawEditorConfig
- bring back a loose version of shape definitions
- make a separation between "core" shapes and "default" shapes
- do not allow custom shapes, migrators or validators to overwrite core
shapes
- but _do_ allow new shapes

## `<Tldraw>` component

In this PR, the `Tldraw` component wraps both the `TldrawEditor`
component and our `TldrawUi` component. It accepts a union of props for
both components. Previously, this component also added local syncing via
a `useLocalSyncClient` hook call, however that has been pushed down to
the `TldrawEditor` component.

## `<TldrawEditor>` component

The `TldrawEditor` component now more neatly wraps up the different ways
that the editor can be configured.

## The store prop (`TldrawEditorProps.store`)

There are three main ways for the `TldrawEditor` component to be run:
1. with an externally defined store
2. with an externally defined syncing store (local or remote)
3. with an internally defined store
4. with an internally defined locally syncing store

The `store` prop allows for these configurations.

If the `store` prop is defined, it may be defined either as a `TLStore`
or as a `SyncedStore`. If the store is a `TLStore`, then the Editor will
assume that the store is ready to go; if it is defined as a SyncedStore,
then the component will display the loading / error screens as needed,
or the final editor once the store's status is "synced".

When the store is left undefined, then the `TldrawEditor` will create
its own internal store using the optional `instanceId`, `initialData`,
or `shapes` props to define the store / store schema.

If the `persistenceKey` prop is left undefined, then the store will not
be synced. If the `persistenceKey` is defined, then the store will be
synced locally. In the future, we may also here accept the API key /
roomId / etc for creating a remotely synced store.

The `SyncedStore` type has been expanded to also include types used for
remote syncing, e.g. with `ConnectionStatus`.

## Tools

By default, the App has two "baked-in" tools: the select tool and the
zoom tool. These cannot (for now) be replaced or removed. The default
tools are used by default, but may be replaced by other tools if
provided.

## Shapes

By default, the App has a set of "core" shapes:
- group
- embed
- bookmark
- image
- video
- text

That cannot by overwritten because they're created by the app at
different moments, such as when double clicking on the canvas or via a
copy and paste event. In follow up PRs, we'll split these out so that
users can replace parts of the code where these shapes are created.

### Change Type

- [x] `major` — Breaking Change

### Test Plan

- [x] Unit Tests
2023-06-01 15:47:34 +00:00
..
1-basic transfer-out: transfer out 2023-04-25 12:01:25 +01:00
2-api [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
3-custom-config [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
4-custom-ui [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
5-exploded [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
6-scroll remove svg layer, html all the things, rs to tl (#1227) 2023-05-05 14:14:42 +00:00
7-multiple [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
8-error-boundary [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
9-hide-ui remove svg layer, html all the things, rs to tl (#1227) 2023-05-05 14:14:42 +00:00
10-custom-components remove svg layer, html all the things, rs to tl (#1227) 2023-05-05 14:14:42 +00:00
11-user-presence [refactor] update record names (#1473) 2023-05-26 13:37:59 +00:00
12-ui-events [improvement] rename onEvent to onUiEvent (#1358) 2023-05-12 09:05:56 +00:00
13-store-events [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
14-persistence [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
end-to-end [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
icons New vite-based examples app (#1226) 2023-05-05 13:10:36 +00:00
index.html New vite-based examples app (#1226) 2023-05-05 13:10:36 +00:00
index.tsx [refactor] User-facing APIs (#1478) 2023-06-01 15:47:34 +00:00
styles.css New vite-based examples app (#1226) 2023-05-05 13:10:36 +00:00