Skip to content

Commit

Permalink
feat(fullscreen): add useWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
yikoyu committed Sep 16, 2023
1 parent 6b8af0a commit ca0c5b2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
4 changes: 3 additions & 1 deletion examples/tiptap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export const vuetifyProTipTap = createVuetifyProTipTap({
}
]
}),
Fullscreen
Fullscreen.configure({
useWindow: true
})
]
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@types/lodash.isequal": "^4.5.6",
"@types/lodash.throttle": "^4.1.7",
"@vitejs/plugin-vue": "^4.3.4",
"@vueuse/core": "^10.4.1",
"@yikoyu/eslint-config-prettier": "^1.3.1",
"commitizen": "^4.3.0",
"conventional-changelog-conventionalcommits": "^6.1.0",
Expand Down
33 changes: 32 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions src/extensions/components/FullscreenActionButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, unref } from 'vue'
import { computed, unref, watch } from 'vue'
import { useFullscreen } from '@vueuse/core'
import { getIcon } from '@/constants/icons'
import { useContext } from '@/hooks'
Expand All @@ -9,17 +10,27 @@ import { ButtonViewReturnComponentProps } from '@/type'
const props = withDefaults(defineProps<Props>(), {
disabled: false,
color: undefined,
isActive: undefined
isActive: undefined,
useWindow: false
})
const { t } = useLocale()
const { state, toggleFullscreen } = useContext()
const { isFullscreen, enter, exit } = useFullscreen()
interface Props {
disabled?: boolean
color?: string
isActive?: ButtonViewReturnComponentProps['isActive']
useWindow?: boolean
}
watch(isFullscreen, val => {
// Press esc to exit full screen
if (!val && state.isFullscreen && props.useWindow) {
onAction()
}
})
const text = computed(() => {
const tooltip = state.isFullscreen ? 'editor.fullscreen.tooltip.exit' : 'editor.fullscreen.tooltip.fullscreen'
if (!tooltip) return undefined
Expand All @@ -31,13 +42,15 @@ const icon = computed(() => {
return getIcon(_icon)
})
function onAction() {
function onAction(_useWindow: boolean = false) {
toggleFullscreen()
if (state.isFullscreen) {
document.documentElement.classList.add('overflow-y-hidden')
_useWindow && enter()
} else {
document.documentElement.classList.remove('overflow-y-hidden')
_useWindow && exit()
}
}
</script>
Expand All @@ -53,7 +66,7 @@ function onAction() {
:class="{
'v-btn--active': isActive?.()
}"
@click="onAction"
@click="onAction(useWindow)"
>
<VIcon :icon="icon" />
Expand Down
10 changes: 7 additions & 3 deletions src/extensions/fullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import FullscreenActionButton from './components/FullscreenActionButton.vue'
import type { ButtonView, GeneralOptions } from '@/type'

export interface FullscreenOptions extends GeneralOptions {
button: ButtonView
button: ButtonView<FullscreenOptions>
useWindow: boolean
}

export const Fullscreen = /* @__PURE__*/ Extension.create<FullscreenOptions>({
name: 'fullscreen',
addOptions() {
return {
...this.parent?.(),
button: ({ editor, t }) => ({
useWindow: false,
button: ({ editor, extension, t }) => ({
component: FullscreenActionButton,
componentProps: {}
componentProps: {
useWindow: extension.options.useWindow ?? false
}
})
}
}
Expand Down

0 comments on commit ca0c5b2

Please sign in to comment.