diff --git a/apps/docs/content/docs/persistence.mdx b/apps/docs/content/docs/persistence.mdx index de9ca656c..5ebb44d0d 100644 --- a/apps/docs/content/docs/persistence.mdx +++ b/apps/docs/content/docs/persistence.mdx @@ -130,10 +130,7 @@ The `store` property of the `` / `` components accepts a s export default function () { const [store] = useState(() => { // Create the store - const newStore = createTLStore({ - shapeUtils: defaultShapeUtils, - bindingUtils: defaultBindingUtils, - }) + const newStore = createTLStore() // Get the snapshot const stringified = localStorage.getItem('my-editor-snapshot') @@ -165,10 +162,7 @@ export default function () { if (cancelled) return // Create the store - const newStore = createTLStore({ - shapeUtils: defaultShapeUtils, - bindingUtils: defaultBindingUtils, - }) + const newStore = createTLStore() // Load the snapshot loadSnapshot(newStore, snapshot) diff --git a/apps/examples/src/examples/local-storage/LocalStorageExample.tsx b/apps/examples/src/examples/local-storage/LocalStorageExample.tsx index 3487d4a34..20f488632 100644 --- a/apps/examples/src/examples/local-storage/LocalStorageExample.tsx +++ b/apps/examples/src/examples/local-storage/LocalStorageExample.tsx @@ -1,13 +1,5 @@ import { useLayoutEffect, useState } from 'react' -import { - Tldraw, - createTLStore, - defaultBindingUtils, - defaultShapeUtils, - getSnapshot, - loadSnapshot, - throttle, -} from 'tldraw' +import { Tldraw, createTLStore, getSnapshot, loadSnapshot, throttle } from 'tldraw' import 'tldraw/tldraw.css' // There's a guide at the bottom of this file! @@ -16,9 +8,7 @@ const PERSISTENCE_KEY = 'example-3' export default function PersistenceExample() { //[1] - const [store] = useState(() => - createTLStore({ shapeUtils: defaultShapeUtils, bindingUtils: defaultBindingUtils }) - ) + const [store] = useState(() => createTLStore()) //[2] const [loadingState, setLoadingState] = useState< { status: 'loading' } | { status: 'ready' } | { status: 'error'; error: string } diff --git a/apps/vscode/extension/src/file.ts b/apps/vscode/extension/src/file.ts index c313ead86..a1e2e21d4 100644 --- a/apps/vscode/extension/src/file.ts +++ b/apps/vscode/extension/src/file.ts @@ -1,22 +1,16 @@ -import { TldrawFile, createTLStore, defaultBindingUtils, defaultShapeUtils } from 'tldraw' +import { TldrawFile, createTLSchema } from 'tldraw' import * as vscode from 'vscode' import { nicelog } from './utils' export const defaultFileContents: TldrawFile = { tldrawFileFormatVersion: 1, - schema: createTLStore({ - shapeUtils: defaultShapeUtils, - bindingUtils: defaultBindingUtils, - }).schema.serialize(), + schema: createTLSchema().serialize(), records: [], } export const fileContentWithErrors: TldrawFile = { tldrawFileFormatVersion: 1, - schema: createTLStore({ - shapeUtils: defaultShapeUtils, - bindingUtils: defaultBindingUtils, - }).schema.serialize(), + schema: createTLSchema().serialize(), records: [{ typeName: 'shape', id: null } as any], } diff --git a/packages/editor/api-report.md b/packages/editor/api-report.md index 9dc7e9a66..2eb2494d7 100644 --- a/packages/editor/api-report.md +++ b/packages/editor/api-report.md @@ -458,7 +458,7 @@ export function counterClockwiseAngleDist(a0: number, a1: number): number; export function createSessionStateSnapshotSignal(store: TLStore): Signal; // @public -export function createTLStore({ initialData, defaultName, id, ...rest }: TLStoreOptions): TLStore; +export function createTLStore({ initialData, defaultName, id, ...rest }?: TLStoreOptions): TLStore; // @public (undocumented) export function createTLUser(opts?: { diff --git a/packages/editor/src/lib/config/createTLStore.ts b/packages/editor/src/lib/config/createTLStore.ts index da853a6c5..d7669f34e 100644 --- a/packages/editor/src/lib/config/createTLStore.ts +++ b/packages/editor/src/lib/config/createTLStore.ts @@ -31,20 +31,22 @@ export function createTLStore({ defaultName = '', id, ...rest -}: TLStoreOptions): TLStore { +}: TLStoreOptions = {}): TLStore { const schema = 'schema' in rest && rest.schema ? // we have a schema rest.schema : // we need a schema createTLSchema({ - shapes: utilsToMap( - checkShapesAndAddCore('shapeUtils' in rest && rest.shapeUtils ? rest.shapeUtils : []) - ), - bindings: utilsToMap( - checkBindings('bindingUtils' in rest && rest.bindingUtils ? rest.bindingUtils : []) - ), - migrations: 'migrations' in rest ? rest.migrations : [], + shapes: + 'shapeUtils' in rest && rest.shapeUtils + ? utilsToMap(checkShapesAndAddCore(rest.shapeUtils)) + : undefined, + bindings: + 'bindingUtils' in rest && rest.bindingUtils + ? utilsToMap(checkBindings(rest.bindingUtils)) + : undefined, + migrations: 'migrations' in rest ? rest.migrations : undefined, }) return new Store({ diff --git a/packages/tlsync/src/test/TLServer.test.ts b/packages/tlsync/src/test/TLServer.test.ts index 57e14b247..153320632 100644 --- a/packages/tlsync/src/test/TLServer.test.ts +++ b/packages/tlsync/src/test/TLServer.test.ts @@ -5,8 +5,7 @@ import { TLDocument, TLRecord, ZERO_INDEX_KEY, - createTLStore, - defaultShapeUtils, + createTLSchema, } from 'tldraw' import { type WebSocket } from 'ws' import { RoomSessionState } from '../lib/RoomSession' @@ -95,7 +94,7 @@ class TLServerTestImpl extends TLServer { } type UnpackPromise = T extends Promise ? U : T -const schema = createTLStore({ shapeUtils: defaultShapeUtils }).schema.serialize() +const schema = createTLSchema().serialize() let server: TLServerTestImpl let sockets: UnpackPromise>