Пример #1
0
const placeholdAndCreateImage = (quill, file) => {
  // needed for quill.getSelection() to work
  quill.focus();
  const selectionAt = quill.getSelection() ?
    quill.getSelection().index :
    // when we are not focused on the editor (e.g. when we just drop something)
    quill.getLength();

  fromFileToDataUrl(file, (dataUrl) => {
    quill.updateContents(
      new Delta()
        .retain(selectionAt)
        .insert({ loadingImage: { src: dataUrl, className: 'placeholder-for-loading-image' } })
    );
    FileApi.upload(false, file)
      .then((response) => {
        preloadImage(response.url, () => {
          quill.updateContents(
            new Delta()
              .retain(selectionAt)
              .delete(2) // delete the placeholder
              .insert({ image: response.url })
          );
        });
      });
  });
};
Пример #2
0
const insertImageWithDataUrlSrc = (quill, file) => {
  console.log(quill.getSelection());
  const selectionAt = quill.getSelection() ?
    quill.getSelection().index :
    // when we are not focused on the editor (e.g. when we just drop something)
    quill.getLength();

  fromFileToDataUrl(file, (dataUrl) => {
    quill.updateContents(
      new Delta()
        .retain(selectionAt)
        .insert({ image: dataUrl })
    );
  });
};