cleanup (broken files)
This commit is contained in:
+24
-20
@@ -7,27 +7,19 @@ export const CustomImage = Image.extend({
|
||||
selectable: true,
|
||||
draggable: true,
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
addAttributes() {
|
||||
return {
|
||||
Backspace: () => {
|
||||
const { selection } = this.editor.state;
|
||||
if (!selection.empty) {
|
||||
const selectedNode = this.editor.state.doc.nodeAt(selection.from);
|
||||
if (selectedNode?.type.name === this.name) {
|
||||
return true; // Prevent default deletion if image is selected
|
||||
}
|
||||
}
|
||||
return false;
|
||||
...this.parent?.(),
|
||||
src: {
|
||||
default: null,
|
||||
},
|
||||
Delete: () => {
|
||||
const { selection } = this.editor.state;
|
||||
if (!selection.empty) {
|
||||
const selectedNode = this.editor.state.doc.nodeAt(selection.from);
|
||||
if (selectedNode?.type.name === this.name) {
|
||||
return true; // Prevent default deletion if image is selected
|
||||
}
|
||||
}
|
||||
return false;
|
||||
filename: {
|
||||
default: null,
|
||||
parseHTML: element => element.getAttribute('data-filename'),
|
||||
renderHTML: attributes => {
|
||||
if (!attributes.filename) return {};
|
||||
return { 'data-filename': attributes.filename };
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
@@ -43,7 +35,11 @@ export const CustomImage = Image.extend({
|
||||
const img = document.createElement('img');
|
||||
Object.entries(node.attrs).forEach(([key, value]) => {
|
||||
if (value !== null && value !== undefined) {
|
||||
img.setAttribute(key, value);
|
||||
if (key === 'filename') {
|
||||
img.setAttribute('data-filename', value);
|
||||
} else {
|
||||
img.setAttribute(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
img.classList.add('rounded-lg', 'border', 'border-border', 'max-w-full', 'h-auto', 'cursor-default');
|
||||
@@ -79,3 +75,11 @@ export const CustomImage = Image.extend({
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands<ReturnType> {
|
||||
image: {
|
||||
setImage: (options: { src: string, alt?: string, title?: string, filename?: string }) => ReturnType;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user