Skip to content

Commit

Permalink
feat(editor): support v0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 30, 2021
1 parent cd73202 commit c1af89a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
21 changes: 5 additions & 16 deletions src/use/storage/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -118,22 +120,9 @@ export const useDropbox = () => {
dbx
.filesDownload({ path: file.id })
.then(async (data: DropboxResponse<any>) => {
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

Expand Down
24 changes: 3 additions & 21 deletions src/use/storage/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand All @@ -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 () => {
Expand Down
33 changes: 33 additions & 0 deletions src/use/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -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 }
}

0 comments on commit c1af89a

Please sign in to comment.