2023-05-07 13:47:10 +00:00
|
|
|
import { Image } from '@tiptap/extension-image'
|
2023-05-06 12:38:22 +00:00
|
|
|
|
|
|
|
declare module '@tiptap/core' {
|
|
|
|
interface Commands<ReturnType> {
|
2023-05-07 13:16:03 +00:00
|
|
|
customImage: {
|
|
|
|
/**
|
|
|
|
* Add an image
|
|
|
|
*/
|
|
|
|
setImage: (options: { src: string; alt?: string; title?: string }) => ReturnType
|
2023-05-29 10:09:44 +00:00
|
|
|
setImageFloat: (float: null | 'left' | 'right') => ReturnType
|
2023-05-06 12:38:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-07 13:47:10 +00:00
|
|
|
export const CustomImage = Image.extend({
|
2023-05-06 12:38:22 +00:00
|
|
|
addAttributes() {
|
|
|
|
return {
|
|
|
|
src: {
|
2023-11-14 15:10:00 +00:00
|
|
|
default: null,
|
2023-05-06 12:38:22 +00:00
|
|
|
},
|
|
|
|
alt: {
|
2023-11-14 15:10:00 +00:00
|
|
|
default: null,
|
2023-05-06 12:38:22 +00:00
|
|
|
},
|
|
|
|
width: {
|
2023-11-14 15:10:00 +00:00
|
|
|
default: null,
|
2023-05-06 12:38:22 +00:00
|
|
|
},
|
|
|
|
height: {
|
2023-11-14 15:10:00 +00:00
|
|
|
default: null,
|
2023-05-06 12:38:22 +00:00
|
|
|
},
|
|
|
|
'data-float': {
|
2023-11-14 15:10:00 +00:00
|
|
|
default: null,
|
|
|
|
},
|
2023-05-06 12:38:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2023-05-07 13:16:03 +00:00
|
|
|
setImage:
|
|
|
|
(options) =>
|
|
|
|
({ commands }) => {
|
|
|
|
return commands.insertContent({
|
|
|
|
type: this.name,
|
2023-11-14 15:10:00 +00:00
|
|
|
attrs: options,
|
2023-05-07 13:16:03 +00:00
|
|
|
})
|
|
|
|
},
|
2023-05-29 10:09:44 +00:00
|
|
|
setImageFloat:
|
2023-05-06 12:38:22 +00:00
|
|
|
(value) =>
|
|
|
|
({ commands }) => {
|
|
|
|
return commands.updateAttributes(this.name, { 'data-float': value })
|
2023-11-14 15:10:00 +00:00
|
|
|
},
|
2023-05-06 12:38:22 +00:00
|
|
|
}
|
2023-11-14 15:10:00 +00:00
|
|
|
},
|
2023-05-06 12:38:22 +00:00
|
|
|
})
|