move v1 migration code into file-format (#1499)

Move v1 migration code out of editor

### Change Type

- [x] `minor` — New Feature
This commit is contained in:
Steve Ruiz 2023-06-02 10:38:13 +01:00 committed by GitHub
parent 09c367811d
commit da35e0da27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 29 deletions

View file

@ -569,9 +569,6 @@ export function blobAsString(blob: Blob): Promise<string>;
// @internal (undocumented) // @internal (undocumented)
export const BOUND_ARROW_OFFSET = 10; export const BOUND_ARROW_OFFSET = 10;
// @internal (undocumented)
export function buildFromV1Document(app: App, document: LegacyTldrawDocument): void;
// @public (undocumented) // @public (undocumented)
export const Canvas: React_3.MemoExoticComponent<({ onDropOverride, }: { export const Canvas: React_3.MemoExoticComponent<({ onDropOverride, }: {
onDropOverride?: ((defaultOnDrop: (e: React_3.DragEvent<Element>) => Promise<void>) => (e: React_3.DragEvent<Element>) => Promise<void>) | undefined; onDropOverride?: ((defaultOnDrop: (e: React_3.DragEvent<Element>) => Promise<void>) => (e: React_3.DragEvent<Element>) => Promise<void>) | undefined;
@ -923,22 +920,6 @@ export const isValidHttpURL: (url: string) => boolean;
// @public (undocumented) // @public (undocumented)
export const LABEL_FONT_SIZES: Record<TLSizeType, number>; export const LABEL_FONT_SIZES: Record<TLSizeType, number>;
// @internal (undocumented)
export interface LegacyTldrawDocument {
// (undocumented)
assets: TDAssets;
// (undocumented)
id: string;
// (undocumented)
name: string;
// (undocumented)
pages: Record<string, TDPage>;
// (undocumented)
pageStates: Record<string, TLV1PageState>;
// (undocumented)
version: number;
}
// @public (undocumented) // @public (undocumented)
export function LoadingScreen({ children }: { export function LoadingScreen({ children }: {
children: any; children: any;

View file

@ -204,7 +204,6 @@ export {
isSvgText, isSvgText,
isValidHttpURL, isValidHttpURL,
} from './lib/utils/assets' } from './lib/utils/assets'
export { buildFromV1Document, type LegacyTldrawDocument } from './lib/utils/buildFromV1Document'
export { export {
checkFlag, checkFlag,
fileToBase64, fileToBase64,

View file

@ -14,9 +14,28 @@ import { TLTranslationKey } from '@tldraw/ui';
import { ToastsContextType } from '@tldraw/ui'; import { ToastsContextType } from '@tldraw/ui';
import { UnknownRecord } from '@tldraw/tlstore'; import { UnknownRecord } from '@tldraw/tlstore';
// @internal (undocumented)
export function buildFromV1Document(app: App, document: LegacyTldrawDocument): void;
// @public (undocumented) // @public (undocumented)
export function isV1File(data: any): boolean; export function isV1File(data: any): boolean;
// @internal (undocumented)
export interface LegacyTldrawDocument {
// (undocumented)
assets: TDAssets;
// (undocumented)
id: string;
// (undocumented)
name: string;
// (undocumented)
pages: Record<string, TDPage>;
// (undocumented)
pageStates: Record<string, TLV1PageState>;
// (undocumented)
version: number;
}
// @internal (undocumented) // @internal (undocumented)
export function parseAndLoadDocument(app: App, document: string, msg: (id: TLTranslationKey) => string, addToast: ToastsContextType['addToast'], onV1FileLoad?: () => void, forceDarkMode?: boolean): Promise<void>; export function parseAndLoadDocument(app: App, document: string, msg: (id: TLTranslationKey) => string, addToast: ToastsContextType['addToast'], onV1FileLoad?: () => void, forceDarkMode?: boolean): Promise<void>;

View file

@ -42,6 +42,7 @@
}, },
"dependencies": { "dependencies": {
"@tldraw/editor": "workspace:*", "@tldraw/editor": "workspace:*",
"@tldraw/primitives": "workspace:*",
"@tldraw/tlstore": "workspace:*", "@tldraw/tlstore": "workspace:*",
"@tldraw/tlvalidate": "workspace:*", "@tldraw/tlvalidate": "workspace:*",
"@tldraw/ui": "workspace:*", "@tldraw/ui": "workspace:*",

View file

@ -1,3 +1,4 @@
export { buildFromV1Document, type LegacyTldrawDocument } from './lib/buildFromV1Document'
export { export {
TLDRAW_FILE_EXTENSION, TLDRAW_FILE_EXTENSION,
TLDRAW_FILE_MIMETYPE, TLDRAW_FILE_MIMETYPE,

View file

@ -1,11 +1,13 @@
import { clamp, Vec2d } from '@tldraw/primitives'
import { import {
App,
AssetRecordType, AssetRecordType,
MAX_SHAPES_PER_PAGE,
PageRecordType, PageRecordType,
TLAlignType, TLAlignType,
TLArrowheadType,
TLArrowShape, TLArrowShape,
TLArrowTerminal, TLArrowTerminal,
TLArrowUtil,
TLArrowheadType,
TLAsset, TLAsset,
TLAssetId, TLAssetId,
TLColorType, TLColorType,
@ -22,17 +24,14 @@ import {
TLTextShape, TLTextShape,
TLVideoShape, TLVideoShape,
Vec2dModel, Vec2dModel,
} from '@tldraw/tlschema' } from '@tldraw/editor'
import { transact } from 'signia' import { Vec2d, clamp } from '@tldraw/primitives'
import { App } from '../app/App'
import { TLArrowUtil } from '../app/shapeutils/TLArrowUtil/TLArrowUtil'
import { MAX_SHAPES_PER_PAGE } from '../constants'
const TLDRAW_V1_VERSION = 15.5 const TLDRAW_V1_VERSION = 15.5
/** @internal */ /** @internal */
export function buildFromV1Document(app: App, document: LegacyTldrawDocument) { export function buildFromV1Document(app: App, document: LegacyTldrawDocument) {
transact(() => { app.batch(() => {
document = migrate(document, TLDRAW_V1_VERSION) document = migrate(document, TLDRAW_V1_VERSION)
// Cancel any interactions / states // Cancel any interactions / states
app.cancel().cancel().cancel().cancel() app.cancel().cancel().cancel().cancel()

View file

@ -1,6 +1,5 @@
import { import {
App, App,
buildFromV1Document,
createTLStore, createTLStore,
fileToBase64, fileToBase64,
TLAsset, TLAsset,
@ -19,6 +18,7 @@ import {
import { T } from '@tldraw/tlvalidate' import { T } from '@tldraw/tlvalidate'
import { TLTranslationKey, ToastsContextType } from '@tldraw/ui' import { TLTranslationKey, ToastsContextType } from '@tldraw/ui'
import { exhaustiveSwitchError, Result } from '@tldraw/utils' import { exhaustiveSwitchError, Result } from '@tldraw/utils'
import { buildFromV1Document } from './buildFromV1Document'
/** @public */ /** @public */
export const TLDRAW_FILE_MIMETYPE = 'application/vnd.tldraw+json' as const export const TLDRAW_FILE_MIMETYPE = 'application/vnd.tldraw+json' as const

View file

@ -10,6 +10,7 @@
{ "path": "../editor" }, { "path": "../editor" },
{ "path": "../tlstore" }, { "path": "../tlstore" },
{ "path": "../tlvalidate" }, { "path": "../tlvalidate" },
{ "path": "../primitives" },
{ "path": "../utils" }, { "path": "../utils" },
{ "path": "../ui" } { "path": "../ui" }
] ]

View file

@ -4373,6 +4373,7 @@ __metadata:
resolution: "@tldraw/file-format@workspace:packages/file-format" resolution: "@tldraw/file-format@workspace:packages/file-format"
dependencies: dependencies:
"@tldraw/editor": "workspace:*" "@tldraw/editor": "workspace:*"
"@tldraw/primitives": "workspace:*"
"@tldraw/tlstore": "workspace:*" "@tldraw/tlstore": "workspace:*"
"@tldraw/tlvalidate": "workspace:*" "@tldraw/tlvalidate": "workspace:*"
"@tldraw/ui": "workspace:*" "@tldraw/ui": "workspace:*"