From c1af89ac5b1f9376e47ba9fdde162ecd0f3a85ac Mon Sep 17 00:00:00 2001 From: Novout Date: Sat, 30 Oct 2021 20:16:57 -0300 Subject: [PATCH] feat(editor): support v0.5.3 --- src/use/storage/dropbox.ts | 21 +++++---------------- src/use/storage/local.ts | 24 +++--------------------- src/use/storage/storage.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 src/use/storage/storage.ts diff --git a/src/use/storage/dropbox.ts b/src/use/storage/dropbox.ts index 07a9a912e..02813a5a4 100644 --- a/src/use/storage/dropbox.ts +++ b/src/use/storage/dropbox.ts @@ -15,6 +15,7 @@ import { useAbsoluteStore } from '@/store/absolute' import usePlugin from '../plugin/core' import { useProject } from '../project' import { ProjectObject } from '../../types/project' +import { useStorage } from './storage' export const useDropbox = () => { const CONTEXT = useContextStore() @@ -28,6 +29,7 @@ export const useDropbox = () => { const toast = useToast() const emitter = useEmitter() const env = useEnv() + const storage = useStorage() const plugin = usePlugin() const project = useProject() const { t } = i18n.global @@ -118,22 +120,9 @@ export const useDropbox = () => { dbx .filesDownload({ path: file.id }) .then(async (data: DropboxResponse) => { - const context = JSON.parse(await data.result.fileBlob.text()) - // <= v0.3.10 - if (context.project?.pages[0]?.entity) { - context.project?.pages.forEach((target: any) => { - target['entities'] = target['entity'] - delete target['entity'] - }) - } - - // <= 0.4.0 - if (!context.project.bw) { - context.project.bw = { - platform: isElectron() ? 'desktop' : 'web', - version: env.packageVersion(), - } - } + let context = storage.support( + JSON.parse(await data.result.fileBlob.text()) + ) ABSOLUTE.aside = true diff --git a/src/use/storage/local.ts b/src/use/storage/local.ts index 8987083a5..d5983e57d 100644 --- a/src/use/storage/local.ts +++ b/src/use/storage/local.ts @@ -8,9 +8,8 @@ import { useEditorStore } from '@/store/editor' import { useLoggerStore } from '@/store/logger' import { usePDFStore } from '@/store/pdf' import useEmitter from '@/use/emitter' -import isElectron from 'is-electron' import usePlugin from '../plugin/core' - +import { useStorage } from './storage' export const useLocalStorage = () => { const PROJECT = useProjectStore() const EDITOR = useEditorStore() @@ -20,6 +19,7 @@ export const useLocalStorage = () => { const toast = useToast() const env = useEnv() const emitter = useEmitter() + const storage = useStorage() const plugin = usePlugin() const { t } = i18n.global @@ -36,25 +36,7 @@ export const useLocalStorage = () => { } const getProject = (): ProjectObject => { - const _ = get(env.projectLocalStorage()) - - // <= v0.3.10 - if (_.project?.pages[0]?.entity) { - _.project?.pages.forEach((target: any) => { - target['entities'] = target['entity'] - delete target['entity'] - }) - } - - // <= 0.4.0 - if (!_.project.bw) { - _.project.bw = { - platform: isElectron() ? 'desktop' : 'web', - version: env.packageVersion(), - } - } - - return _ + return storage.support(get(env.projectLocalStorage())) } const onSaveProject = async () => { diff --git a/src/use/storage/storage.ts b/src/use/storage/storage.ts new file mode 100644 index 000000000..6e0b88061 --- /dev/null +++ b/src/use/storage/storage.ts @@ -0,0 +1,33 @@ +import isElectron from 'is-electron' +import { useEnv } from '../env' +export const useStorage = () => { + const env = useEnv() + + const support = (project: any) => { + let _ = project + // <= v0.3.10 + if (_.project?.pages[0]?.entity) { + _.project?.pages.forEach((target: any) => { + target['entities'] = target['entity'] + delete target['entity'] + }) + } + + // <= 0.4.0 + if (!_.project.bw) { + _.project.bw = { + platform: isElectron() ? 'desktop' : 'web', + version: env.packageVersion(), + } + } + + // <= 0.5.3 + if (!_.editor.configuration.auto) { + _.editor.configuration.auto = 5 + } + + return _ + } + + return { support } +}