-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
315 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 5 additions & 59 deletions
64
packages/app/src/components/page/editor/main/render/history/EditorBaseRenderHistory.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,25 @@ | ||
<template> | ||
<section v-if="HISTORY.bar.length !== 0" class="flex z-50 wb-text items-center bg-theme-background-opacity-1 justify-between w-full"> | ||
<button v-for="(item, index) in HISTORY.bar" :key="index" :class="[HISTORY.barActive === item.id ? 'bg-theme-background-2' : 'hover:bg-theme-background-opacity-1']" class="flex-1 font-bold flex justify-around items-center font-raleway min-w-12 h-10 md:(h-9)" @click.prevent.stop="onLoad(item)"> | ||
<button v-for="(item, index) in HISTORY.bar" :key="index" :class="[HISTORY.barActive === item.id ? 'bg-theme-background-2' : 'hover:bg-theme-background-opacity-1']" class="flex-1 font-bold flex justify-around items-center font-raleway min-w-12 h-10 md:(h-9)" @click.prevent.stop="history.onLoad(item)"> | ||
<div class="flex gap-2 truncate pl-2"> | ||
<CustomIcon v-if="item.customIcon" :icon="item.customIcon" /> | ||
<p class="truncate">{{ item.name || item.id }}</p> | ||
</div> | ||
<button @click.prevent.stop="onDeleteBar(item)"> | ||
<button @click.prevent.stop="history.onDeleteBar(item)"> | ||
<IconClose class="w-6 h-6 wb-icon"/> | ||
</button> | ||
</button> | ||
<button class="wb-icon ml-2" @click.prevent.stop="onCloseAll"> | ||
<button class="wb-icon ml-2" @click.prevent.stop="history.onCloseAll"> | ||
<IconCloseAll class="w-6 h-6" /> | ||
</button> | ||
</section> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useHistoryStore } from '@/store/history'; | ||
import { usePlugin } from 'better-write-plugin-core'; | ||
import { useSchemas } from '@/use/schemas' | ||
import { HistoryStateBarItem } from 'better-write-types'; | ||
import { useGraph } from '@/use/graph'; | ||
import { useProjectStore } from '@/store/project'; | ||
import { useStorage } from '@/use/storage/storage'; | ||
import { useHistory } from '@/use/history' | ||
const HISTORY = useHistoryStore() | ||
const PROJECT = useProjectStore() | ||
const plugin = usePlugin() | ||
const schemas = useSchemas() | ||
const graph = useGraph() | ||
const storage = useStorage() | ||
const onLoad = async (item?: HistoryStateBarItem) => { | ||
await storage.normalize() | ||
if(!item) item = HISTORY.bar.shift() | ||
if(!item) return | ||
if(item.type === 'annotations') { | ||
const target = schemas.findFile(item.id) | ||
if(!target) { | ||
HISTORY.deleteBar(item) | ||
return | ||
} | ||
plugin.emit('plugin-schemas-start', target) | ||
HISTORY.barActive = target.id | ||
return | ||
} | ||
const page = PROJECT.chapters.find(chapter => chapter.id === item?.id) | ||
if(!page) { | ||
HISTORY.deleteBar(item) | ||
return | ||
} | ||
HISTORY.barActive = item.id | ||
graph.load(item.id as number, page, page.entities[0], item.scrollHeight) | ||
} | ||
const onDeleteBar = (item: HistoryStateBarItem) => { | ||
HISTORY.deleteBar(item) | ||
onLoad() | ||
} | ||
const onCloseAll = () => { | ||
HISTORY.bar = [] | ||
HISTORY.barActive = undefined | ||
} | ||
const history = useHistory() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useHistoryStore } from '@/store/history' | ||
import { usePlugin } from 'better-write-plugin-core' | ||
import { useSchemas } from '@/use/schemas' | ||
import { HistoryStateBarItem } from 'better-write-types' | ||
import { useGraph } from '@/use/graph' | ||
import { useProjectStore } from '@/store/project' | ||
import { useStorage } from '@/use/storage/storage' | ||
|
||
export const useHistory = () => { | ||
const HISTORY = useHistoryStore() | ||
const PROJECT = useProjectStore() | ||
|
||
const plugin = usePlugin() | ||
const schemas = useSchemas() | ||
const graph = useGraph() | ||
const storage = useStorage() | ||
|
||
const onLoad = async (item?: HistoryStateBarItem) => { | ||
await storage.normalize() | ||
|
||
if (!item) item = HISTORY.bar.shift() | ||
|
||
if (!item) return | ||
|
||
if (item.type === 'annotations') { | ||
const target = schemas.findFile(item.id) | ||
|
||
if (!target) { | ||
HISTORY.deleteBar(item) | ||
|
||
return | ||
} | ||
|
||
HISTORY.updateScroll() | ||
plugin.emit('plugin-schemas-start', { target, item }) | ||
HISTORY.barActive = item.id | ||
|
||
return | ||
} | ||
|
||
const page = PROJECT.chapters.find((chapter) => chapter.id === item?.id) | ||
|
||
if (!page) { | ||
HISTORY.deleteBar(item) | ||
|
||
return | ||
} | ||
|
||
HISTORY.updateScroll() | ||
await graph.to(item.id as number, page, page.entities[0], item.scrollHeight) | ||
} | ||
|
||
const onDeleteBar = (item: HistoryStateBarItem) => { | ||
HISTORY.deleteBar(item) | ||
|
||
onLoad() | ||
} | ||
|
||
const onCloseAll = () => { | ||
HISTORY.bar = [] | ||
HISTORY.barActive = undefined | ||
} | ||
|
||
return { onDeleteBar, onCloseAll, onLoad } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.