Update migrate.ts (#1000)

This commit is contained in:
Steve Ruiz 2022-09-30 15:28:55 +01:00 committed by GitHub
parent e58599b290
commit e722fcdb4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,84 +51,84 @@ export function migrate(state: TDSnapshot, newVersion: number): TDSnapshot {
} }
}) })
if (version === newVersion) return state if (version !== newVersion) {
if (version < 14) {
if (version < 14) { Object.values(document.pages).forEach((page) => {
Object.values(document.pages).forEach((page) => { Object.values(page.shapes)
Object.values(page.shapes) .filter((shape) => shape.type === TDShapeType.Text)
.filter((shape) => shape.type === TDShapeType.Text) .forEach((shape) => (shape as TextShape).style.font === FontStyle.Script)
.forEach((shape) => (shape as TextShape).style.font === FontStyle.Script)
})
}
// Lowercase styles, move binding meta to binding
if (version <= 13) {
Object.values(document.pages).forEach((page) => {
Object.values(page.bindings).forEach((binding) => {
Object.assign(binding, (binding as any).meta)
}) })
}
Object.values(page.shapes).forEach((shape) => { // Lowercase styles, move binding meta to binding
Object.entries(shape.style).forEach(([id, style]) => { if (version <= 13) {
if (typeof style === 'string') { Object.values(document.pages).forEach((page) => {
// @ts-ignore Object.values(page.bindings).forEach((binding) => {
shape.style[id] = style.toLowerCase() Object.assign(binding, (binding as any).meta)
}
}) })
if (shape.type === TDShapeType.Arrow) { Object.values(page.shapes).forEach((shape) => {
if (shape.decorations) { Object.entries(shape.style).forEach(([id, style]) => {
Object.entries(shape.decorations).forEach(([id, decoration]) => { if (typeof style === 'string') {
if ((decoration as unknown) === 'Arrow') { // @ts-ignore
shape.decorations = { shape.style[id] = style.toLowerCase()
...shape.decorations, }
[id]: Decoration.Arrow, })
if (shape.type === TDShapeType.Arrow) {
if (shape.decorations) {
Object.entries(shape.decorations).forEach(([id, decoration]) => {
if ((decoration as unknown) === 'Arrow') {
shape.decorations = {
...shape.decorations,
[id]: Decoration.Arrow,
}
} }
} })
}) }
}
})
})
}
// Add document name and file system handle
if (version <= 13.1) {
document.name = 'New Document'
}
if (version < 15) {
document.assets = {}
}
Object.values(document.pages).forEach((page) => {
Object.values(page.shapes).forEach((shape) => {
if (version < 15.2) {
if (shape.type === TDShapeType.Image || shape.type === TDShapeType.Video) {
shape.style.isFilled = true
}
}
if (version < 15.3) {
if (
shape.type === TDShapeType.Rectangle ||
shape.type === TDShapeType.Triangle ||
shape.type === TDShapeType.Ellipse ||
shape.type === TDShapeType.Arrow
) {
shape.label = (shape as any).text || ''
shape.labelPoint = [0.5, 0.5]
} }
} }
}) })
}) })
}
// Add document name and file system handle if (version < 15.4) {
if (version <= 13.1) { settings.dockPosition = 'bottom'
document.name = 'New Document' }
}
if (version < 15) { if (version < 15.5) {
document.assets = {} settings.exportBackground = TDExportBackground.Transparent
} }
Object.values(document.pages).forEach((page) => {
Object.values(page.shapes).forEach((shape) => {
if (version < 15.2) {
if (shape.type === TDShapeType.Image || shape.type === TDShapeType.Video) {
shape.style.isFilled = true
}
}
if (version < 15.3) {
if (
shape.type === TDShapeType.Rectangle ||
shape.type === TDShapeType.Triangle ||
shape.type === TDShapeType.Ellipse ||
shape.type === TDShapeType.Arrow
) {
shape.label = (shape as any).text || ''
shape.labelPoint = [0.5, 0.5]
}
}
})
})
if (version < 15.4) {
settings.dockPosition = 'bottom'
}
if (version < 15.5) {
settings.exportBackground = TDExportBackground.Transparent
} }
// Cleanup // Cleanup