import { Plugin } from 'jodit/src/modules'; import { pluginSystem } from 'jodit/src/core/global'; import { IJodit } from 'jodit/src/types'; export class ReadonlySetting extends Plugin { private setReadonlyJoditFile(): void { const setJoditFile = (file: HTMLElement | Element): void => { file.classList.add('readonly'); const downloadButton = file.querySelector('button'); downloadButton?.addEventListener('click', () => { if (!(file instanceof HTMLElement)) return; const { href, filename } = file.dataset; if (!href) return; fetch(href) .then(response => response.blob()) .then(blob => URL.createObjectURL(blob)) .then(url => { const downloadLink = document.createElement('a'); downloadLink.setAttribute('href', url); downloadLink.setAttribute( 'download', filename || href || 'file' ); downloadLink.style.display = 'none'; document.body.appendChild(downloadLink); downloadLink.click(); document.body.removeChild(downloadLink); URL.revokeObjectURL(url); }); }); }; this.j.editor.querySelectorAll('jodit-file').forEach(setJoditFile); } /** @override */ protected afterInit(editor: IJodit): void { if (!this.j.o.readonly) return; this.setReadonlyJoditFile(); } /** @override */ protected beforeDestruct(editor: IJodit): void { if (!this.j.o.readonly) return; } } pluginSystem.add('readonly-setting', ReadonlySetting);