-
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.
feat(editor): create page inside a editor
- Loading branch information
Showing
5 changed files
with
58 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
<template> | ||
<button class="wb-aside-button" @click="onCreateNewPage"> | ||
<InjectButtonInstance | ||
class="wb-aside-button" | ||
@click.prevent="usePage().onCreatePage" | ||
> | ||
{{ t('editor.aside.project.page.new.title') }} | ||
</button> | ||
</InjectButtonInstance> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n } from 'vue-i18n' | ||
import { useStore } from 'vuex' | ||
import { usePage } from '@/use/page' | ||
const store = useStore() | ||
const { t } = useI18n() | ||
const onCreateNewPage = async () => { | ||
store.commit('project/newPage') | ||
const arr = store.state.project.pages | ||
const obj = arr[arr.length - 1] | ||
store.commit('context/load', obj) | ||
} | ||
</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,3 @@ | ||
<template> | ||
<button><slot /></button> | ||
</template> |
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,26 @@ | ||
import { nextTick } from 'vue' | ||
import { useStore } from 'vuex' | ||
|
||
export const usePage = () => { | ||
const store = useStore() | ||
|
||
const onCreatePage = async () => { | ||
store.commit('project/newPage') | ||
|
||
const arr = store.state.project.pages | ||
const obj = arr[arr.length - 1] | ||
|
||
store.commit('context/load', obj) | ||
} | ||
|
||
const onDeletePage = async () => { | ||
if (store.state.project.pages.length <= 1) return | ||
|
||
store.commit('project/deletePage', store.state.context) | ||
await nextTick | ||
|
||
store.commit('context/load', store.state.project.pages[0]) | ||
} | ||
|
||
return { onCreatePage, onDeletePage } | ||
} |