feat(editor): properly bubble changes when they are made
This commit is contained in:
parent
22103626b8
commit
9b20dc1899
@ -25,44 +25,6 @@
|
|||||||
</template>
|
</template>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ul class="actions d-print-none" v-if="bottomActions.length > 0">
|
|
||||||
<li v-if="isEditEnabled && !showPreviewText && showSave">
|
|
||||||
<BaseButton
|
|
||||||
v-if="showEditButton"
|
|
||||||
@click="toggleEdit"
|
|
||||||
v-shortcut="editShortcut">
|
|
||||||
{{ $t('input.editor.edit') }}
|
|
||||||
</BaseButton>
|
|
||||||
<BaseButton
|
|
||||||
v-else-if="isEditActive"
|
|
||||||
@click="bubbleSaveClick"
|
|
||||||
class="done-edit">
|
|
||||||
{{ $t('misc.save') }}
|
|
||||||
</BaseButton>
|
|
||||||
</li>
|
|
||||||
<li v-for="(action, k) in bottomActions" :key="k">
|
|
||||||
<BaseButton @click="action.action">{{ action.title }}</BaseButton>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<template v-else-if="isEditEnabled && showSave">
|
|
||||||
<ul v-if="showEditButton" class="actions d-print-none">
|
|
||||||
<li>
|
|
||||||
<BaseButton
|
|
||||||
@click="toggleEdit"
|
|
||||||
v-shortcut="editShortcut">
|
|
||||||
{{ $t('input.editor.edit') }}
|
|
||||||
</BaseButton>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<x-button
|
|
||||||
v-else-if="isEditActive"
|
|
||||||
@click="bubbleSaveClick"
|
|
||||||
variant="secondary"
|
|
||||||
:shadow="false"
|
|
||||||
v-cy="'saveEditor'">
|
|
||||||
{{ $t('misc.save') }}
|
|
||||||
</x-button>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -70,6 +70,29 @@
|
|||||||
ref="uploadInputRef"
|
ref="uploadInputRef"
|
||||||
@change="addImage"
|
@change="addImage"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ul class="actions d-print-none" v-if="bottomActions.length > 0">
|
||||||
|
<li v-if="isEditEnabled && showSave">
|
||||||
|
<BaseButton
|
||||||
|
@click="bubbleSave"
|
||||||
|
class="done-edit">
|
||||||
|
{{ $t('misc.save') }}
|
||||||
|
</BaseButton>
|
||||||
|
</li>
|
||||||
|
<li v-for="(action, k) in bottomActions" :key="k">
|
||||||
|
<BaseButton @click="action.action">{{ action.title }}</BaseButton>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<x-button
|
||||||
|
v-else-if="isEditEnabled && showSave"
|
||||||
|
class="mt-4"
|
||||||
|
@click="bubbleSave"
|
||||||
|
variant="secondary"
|
||||||
|
:shadow="false"
|
||||||
|
v-cy="'saveEditor'"
|
||||||
|
>
|
||||||
|
{{ $t('misc.save') }}
|
||||||
|
</x-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -109,13 +132,14 @@ import suggestionSetup from './suggestion'
|
|||||||
// load all highlight.js languages
|
// load all highlight.js languages
|
||||||
import {lowlight} from 'lowlight'
|
import {lowlight} from 'lowlight'
|
||||||
|
|
||||||
import type {UploadCallback} from './types'
|
import type {BottomAction, UploadCallback} from './types'
|
||||||
import type {ITask} from '@/modelTypes/ITask'
|
import type {ITask} from '@/modelTypes/ITask'
|
||||||
import type {IAttachment} from '@/modelTypes/IAttachment'
|
import type {IAttachment} from '@/modelTypes/IAttachment'
|
||||||
import AttachmentModel from '@/models/attachment'
|
import AttachmentModel from '@/models/attachment'
|
||||||
import AttachmentService from '@/services/attachment'
|
import AttachmentService from '@/services/attachment'
|
||||||
import {useI18n} from 'vue-i18n'
|
import {useI18n} from 'vue-i18n'
|
||||||
import BaseButton from '@/components/base/BaseButton.vue'
|
import BaseButton from '@/components/base/BaseButton.vue'
|
||||||
|
import XButton from '@/components/input/button.vue'
|
||||||
|
|
||||||
const {t} = useI18n()
|
const {t} = useI18n()
|
||||||
|
|
||||||
@ -140,15 +164,22 @@ const CustomTableCell = TableCell.extend({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
modelValue,
|
modelValue,
|
||||||
uploadCallback,
|
uploadCallback,
|
||||||
|
isEditEnabled = true,
|
||||||
|
bottomActions = [],
|
||||||
|
showSave = false,
|
||||||
} = defineProps<{
|
} = defineProps<{
|
||||||
modelValue: string,
|
modelValue: string,
|
||||||
uploadCallback?: UploadCallback,
|
uploadCallback?: UploadCallback,
|
||||||
|
isEditEnabled?: boolean,
|
||||||
|
bottomActions?: BottomAction[],
|
||||||
|
showSave?: boolean,
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'change'])
|
const emit = defineEmits(['update:modelValue', 'save'])
|
||||||
|
|
||||||
const inputHTML = ref('')
|
const inputHTML = ref('')
|
||||||
watch(
|
watch(
|
||||||
@ -172,7 +203,7 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
function onImageAdded() {
|
function onImageAdded() {
|
||||||
bubbleChanges()
|
bubbleSave()
|
||||||
loadImages()
|
loadImages()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,11 +242,15 @@ function loadImages() {
|
|||||||
|
|
||||||
const debouncedInputHTML = refDebounced(inputHTML, 1000)
|
const debouncedInputHTML = refDebounced(inputHTML, 1000)
|
||||||
|
|
||||||
watch(debouncedInputHTML, () => bubbleChanges())
|
watch(debouncedInputHTML, () => bubbleNow())
|
||||||
|
|
||||||
function bubbleChanges() {
|
function bubbleNow() {
|
||||||
emit('update:modelValue', TIPTAP_TEXT_VALUE_PREFIX + inputHTML.value)
|
emit('update:modelValue', TIPTAP_TEXT_VALUE_PREFIX + inputHTML.value)
|
||||||
emit('change', TIPTAP_TEXT_VALUE_PREFIX + inputHTML.value) // FIXME: remove this
|
}
|
||||||
|
|
||||||
|
function bubbleSave() {
|
||||||
|
bubbleNow()
|
||||||
|
emit('save', TIPTAP_TEXT_VALUE_PREFIX + inputHTML.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
@ -302,9 +337,9 @@ function addImage() {
|
|||||||
if (!files || files.length === 0) {
|
if (!files || files.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadAndInsertFiles(files)
|
uploadAndInsertFiles(files)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1,6 @@
|
|||||||
export type UploadCallback = (files: File[] | FileList) => Promise<string[]>
|
export type UploadCallback = (files: File[] | FileList) => Promise<string[]>
|
||||||
|
|
||||||
|
export interface BottomAction {
|
||||||
|
title: string
|
||||||
|
action: Function
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user