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)
export const BOUND_ARROW_OFFSET = 10;
// @internal (undocumented)
export function buildFromV1Document(app: App, document: LegacyTldrawDocument): void;
// @public (undocumented)
export const Canvas: React_3.MemoExoticComponent<({ onDropOverride, }: {
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)
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)
export function LoadingScreen({ children }: {
children: any;

View file

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

View file

@ -14,9 +14,28 @@ import { TLTranslationKey } from '@tldraw/ui';
import { ToastsContextType } from '@tldraw/ui';
import { UnknownRecord } from '@tldraw/tlstore';
// @internal (undocumented)
export function buildFromV1Document(app: App, document: LegacyTldrawDocument): void;
// @public (undocumented)
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)
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": {
"@tldraw/editor": "workspace:*",
"@tldraw/primitives": "workspace:*",
"@tldraw/tlstore": "workspace:*",
"@tldraw/tlvalidate": "workspace:*",
"@tldraw/ui": "workspace:*",

View file

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

View file

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

View file

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

View file

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

View file

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