* feat: 统一并标准化eslint * lint: napcat.webui * lint: napcat.webui * lint: napcat.core * build: fix * lint: napcat.webui * refactor: 重构eslint * Update README.md
31 lines
744 B
TypeScript
31 lines
744 B
TypeScript
import Quill from 'quill';
|
|
|
|
// eslint-disable-next-line
|
|
const Embed = Quill.import('blots/embed') as any
|
|
export interface ImageValue {
|
|
alt: string
|
|
src: string
|
|
}
|
|
class ImageBlot extends Embed {
|
|
static blotName = 'image';
|
|
static tagName = 'img';
|
|
static classNames: string[] = ['max-w-48', 'max-h-48', 'align-bottom'];
|
|
|
|
static create (value: ImageValue) {
|
|
const node = super.create();
|
|
node.setAttribute('alt', value.alt);
|
|
node.setAttribute('src', value.src);
|
|
node.classList.add(...ImageBlot.classNames);
|
|
return node;
|
|
}
|
|
|
|
static value (node: HTMLImageElement): ImageValue {
|
|
return {
|
|
alt: node.getAttribute('alt') ?? '',
|
|
src: node.getAttribute('src') ?? '',
|
|
};
|
|
}
|
|
}
|
|
|
|
export default ImageBlot;
|