Skip to content

Commit

Permalink
fix: resolve error when deleting images in default editor
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Aug 29, 2024
1 parent 9c9ac1b commit c4d786d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
11 changes: 3 additions & 8 deletions ui/packages/editor/src/components/bubble/BubbleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ const handleBubbleItemClick = (editor: Editor) => {
}
const callback = props.action?.({ editor });
if (typeof callback === "object") {
if (componentRef.value) {
componentRef.value = undefined;
} else {
componentRef.value = callback;
}
componentRef.value = callback;
}
};
</script>
Expand All @@ -46,6 +42,7 @@ const handleBubbleItemClick = (editor: Editor) => {
:auto-hide="true"
:shown="!!componentRef"
:distance="10"
@hide="componentRef = undefined"
>
<button
v-if="visible({ editor })"
Expand All @@ -67,9 +64,7 @@ const handleBubbleItemClick = (editor: Editor) => {
<div
class="relative rounded-md bg-white overflow-hidden drop-shadow w-96 p-1 max-h-72 overflow-y-auto"
>
<KeepAlive>
<component :is="componentRef" v-bind="props"></component>
</KeepAlive>
<component :is="componentRef" v-bind="props"></component>
</div>
</template>
</VDropdown>
Expand Down
2 changes: 0 additions & 2 deletions ui/packages/editor/src/extensions/paragraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const Paragraph = TiptapParagraph.extend<ExtensionOptions & ParagraphOptions>({
Backspace: ({ editor }: { editor: CoreEditor }) => {
const { state, view } = editor;
const { selection } = state;

if (isListActive(editor) || !isActive(state, Paragraph.name)) {
return false;
}
Expand All @@ -118,7 +117,6 @@ const Paragraph = TiptapParagraph.extend<ExtensionOptions & ParagraphOptions>({
}

const beforePos = $from.before($from.depth);

if (isEmpty($from.parent)) {
return deleteCurrentNodeAndSetSelection(
$from,
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/editor/src/utils/isNodeEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ export const isParagraphEmpty = (node: PMNode) => {
return false;
}

if (node.childCount > 0) {
return false;
}

return node.textContent.length === 0;
};
9 changes: 7 additions & 2 deletions ui/src/components/editor/extensions/audio/AudioView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ const handleSetExternalLink = (attachment: AttachmentAttr) => {
};
const resetUpload = () => {
if (props.getPos()) {
props.updateAttributes({
const canUpdateAttributes = props.editor.can().updateAttributes(Audio.name, {
width: undefined,
height: undefined,
file: undefined,
});
if (canUpdateAttributes && props.getPos()) {
props.editor.commands.updateAttributes(Audio.name, {
width: undefined,
height: undefined,
file: undefined,
Expand Down
10 changes: 8 additions & 2 deletions ui/src/components/editor/extensions/image/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ const handleUploadError = () => {
const resetUpload = () => {
fileBase64.value = undefined;
uploadProgress.value = undefined;
if (props.getPos()) {
props.updateAttributes({
const canUpdateAttributes = props.editor.can().updateAttributes(Image.name, {
width: undefined,
height: undefined,
file: undefined,
});
if (canUpdateAttributes && props.getPos()) {
props.editor.commands.updateAttributes(Image.name, {
width: undefined,
height: undefined,
file: undefined,
Expand Down
10 changes: 8 additions & 2 deletions ui/src/components/editor/extensions/video/VideoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import RiVideoAddLine from "~icons/ri/video-add-line";
import { EditorLinkObtain } from "../../components";
import InlineBlockBox from "../../components/InlineBlockBox.vue";
import type { AttachmentAttr } from "../../utils/attachment";
import Video from "./index";
const props = defineProps<{
editor: Editor;
Expand Down Expand Up @@ -57,8 +58,13 @@ const handleSetExternalLink = (attachment: AttachmentAttr) => {
};
const resetUpload = () => {
if (props.getPos()) {
props.updateAttributes({
const canUpdateAttributes = props.editor.can().updateAttributes(Video.name, {
width: undefined,
height: undefined,
file: undefined,
});
if (canUpdateAttributes && props.getPos()) {
props.editor.commands.updateAttributes(Video.name, {
width: undefined,
height: undefined,
file: undefined,
Expand Down

0 comments on commit c4d786d

Please sign in to comment.