import Quill from 'quill'; const BlockEmbed = Quill.import('blots/block/embed'); const Parchment = Quill.import('parchment'); class FileBlot extends BlockEmbed { static blotName = 'fileCard'; static tagName = 'div'; static className = 'file-card'; static scope = Parchment.Scope.BLOCK_BLOT; static create(value) { const node = super.create(); //node.setAttribute('contenteditable', 'false'); node.setAttribute('data-file-name', value.name); node.setAttribute('data-file-size', value.size); node.setAttribute('draggable', 'true'); node.innerHTML = `
πŸ“„ ${value.name} (${(value.size / 1024 / 1024).toFixed(2)}MB)
`; // 클릭 μ‹œ 이벀트 λ°œμƒ node.addEventListener('click', (e) => { e.preventDefault(); e.stopPropagation(); const quill = FileBlot.getQuillInstance(); if (quill) { const uploader = quill?.getModule('fileUploader'); // μ²¨λΆ€νŒŒμΌ ν™œμ„±ν™” ν•΄μ œ uploader.clearActiveCards(); // 에디터 μ»€μ„œ ν‘œμ‹œ ν•΄μ œ quill.root.blur(); } node.classList.add('active'); }); // μ‚­μ œ λ²„νŠΌ node.querySelector('.file-card-delete')?.addEventListener('click', () => { node.remove(); }); // μ •λ ¬ λ²„νŠΌ node.querySelectorAll('button[data-align]').forEach(btn => { btn.addEventListener('click', (e) => { const target = e.currentTarget; const align = target.dataset.align; node.querySelectorAll('button[data-align]').forEach(el => el.classList.remove('active')); node.style.justifySelf = align || 'start'; target.classList.add('active'); }); }); // λ“œλž˜κ·Έ μ‹œμž‘ node.addEventListener('dragstart', (e) => { const value = { name: node.getAttribute('data-file-name'), size: node.getAttribute('data-file-size') }; e.dataTransfer?.setData('text/plain', JSON.stringify(value)); e.dataTransfer.effectAllowed = 'move'; node.classList.add('dragging'); }); node.addEventListener('dragend', () => { node.classList.remove('dragging'); }); return node; } static value(node) { return { name: node.getAttribute('data-file-name'), size: node.getAttribute('data-file-size') }; } static getQuillInstance() { return Quill.quillInstance || null; } static setQuillInstance(quill) { Quill.quillInstance = quill; } } export default FileBlot;