FileUploader.js 903 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Quill from 'quill';
  2. export default class FileUploader {
  3. quill;
  4. constructor(quill) {
  5. this.quill = quill;
  6. }
  7. // 파일 추가
  8. selectFile() {
  9. const input = document.createElement('input');
  10. input.type = 'file';
  11. input.onchange = () => {
  12. if (!input.files) {
  13. return;
  14. }
  15. const file = input.files[0];
  16. if (!file) {
  17. return;
  18. }
  19. const range = this.quill.getSelection() || { index: 0};
  20. if (range) {
  21. this.quill.insertEmbed(range.index, 'fileCard', { name: file.name, size: file.size }, Quill.sources.USER);
  22. this.quill.setSelection(range.index + 1);
  23. }
  24. };
  25. input.click();
  26. }
  27. // 첨부 파일 활성화 삭제
  28. clearActiveCards() {
  29. this.quill.root.querySelectorAll('.file-card.active').forEach(el => el.classList.remove('active'));
  30. }
  31. }