TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
5.91k stars 386 forks source link

Can't download file or get file link when editor not editable #770

Closed lamtuanamc closed 1 month ago

lamtuanamc commented 1 month ago

image

I solved it by using useEffect and interacting with the dom, but it doesn't seem to be the right way to do it.

const divElements = document.querySelectorAll('div[data-url]');
        divElements.forEach((element) => {
          const dataUrl = element.getAttribute('data-url');

          if(dataUrl) {
            element.addEventListener('click', () => handleDownload(dataUrl));
          }
        });

  const handleDownload = (url: string): void => {
      const link = document.createElement('a');
      link.href = url;
      link.download = url.split('/').pop() || 'download';
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
  }

Thread on Discord