Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Finished work on image paste feature
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed Jul 30, 2020
1 parent 56a6f00 commit dad1ff0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/TextBlock/extensions/insertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const withInsertData = (editor) => {

editor.insertData = (data) => {
insertData(data);
// console.log('insert', editor.children);
deconstructToVoltoBlocks(editor);
};

Expand Down
28 changes: 15 additions & 13 deletions src/editor/plugins/Image/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Transforms } from 'slate';
import { IMAGE } from 'volto-slate/constants';
import { jsx } from 'slate-hyperscript';
import { getBaseUrl } from '@plone/volto/helpers';
// import { createImageBlock } from 'volto-slate/utils';
import { v4 as uuid } from 'uuid';

export const isImageUrl = (url) => {
if (!isUrl(url)) return false;
Expand All @@ -32,21 +32,26 @@ export const onImageLoad = (editor, reader) => () => {
// TODO: we need a way to get the uploaded image URL
// This would be easier if we would have block transformers-based image
// blocks

uploadContent(
getBaseUrl(pathname),
{
const url = getBaseUrl(pathname);
const uploadId = uuid();
const uploadFileName = `clipboard-${uploadId}`;
const uploadTitle = `Clipboard ${uploadId}`;
const content = {
'@type': 'Image',
title: 'clipboard',
title: uploadTitle,
image: {
data: fields[3],
encoding: fields[2],
'content-type': fields[1],
filename: 'clipboard',
filename: uploadFileName,
},
},
block,
);
};

const rv = uploadContent(url, content, block);
rv.then((data) => {
const dlUrl = data.image.download;
insertImage(editor, dlUrl);
});
};

export const insertImage = (editor, url, { typeImg = IMAGE } = {}) => {
Expand Down Expand Up @@ -89,7 +94,6 @@ export const withImage = (editor) => {
};

editor.insertData = (data) => {
console.log('image insertData', data);
const text = data.getData('text/plain');
const { files } = data;
if (files && files.length > 0) {
Expand All @@ -101,8 +105,6 @@ export const withImage = (editor) => {
reader.readAsDataURL(file);
}
}
} else if (isImageUrl(text)) {
insertImage(editor, text);
} else {
insertData(data);
}
Expand Down

0 comments on commit dad1ff0

Please sign in to comment.