Update slate-drop-or-paste-images to slate to >= 0.43#35
Update slate-drop-or-paste-images to slate to >= 0.43#35cdunn wants to merge 4 commits intoianstormtaylor:masterfrom
Conversation
cdunn
commented
Nov 19, 2018
- change -> editor
- Also add context object to insertImage callback. Useful to access original src for example.
|
@cdunn Hah, I missed this when I made #40. Looks like we took the same approach, I like your additions. What do you think of how I handle the types? slate-plugins/packages/slate-drop-or-paste-images/src/index.js Lines 50 to 68 in 39b68f2 |
|
@ianstormtaylor what would it take to merge this? Should the other plugins be upgraded at the same time? |
|
|
||
| function DropOrPasteImages(options = {}) { | ||
| let { insertImage, extensions } = options | ||
| let { insertImage, extensions, acceptableTransferTypes } = options |
There was a problem hiding this comment.
suggest more concise name of transferTypes or transfers
| plugins = [ | ||
| DropOrPasteImages({ | ||
| insertImage: (transform, file) => { | ||
| insertImage: (_event, transform, file, _context) => { |
There was a problem hiding this comment.
a little fuzzy on the _ naming convention, would recommend removing it but won't fight for it
| function onInsertFiles(event, editor, next, transfer, range) { | ||
| const { files } = transfer | ||
|
|
||
| for (const file of files) { |
There was a problem hiding this comment.
const filteredFiles = !extensions ? files : files.filter(file => {
const type = file.type
const [, etx] = type.split('/')
return ext && matchExt(ext)
})
if (!filteredFiles.length) { return next() }
for (const file of filteredFiles) {
There was a problem hiding this comment.
I suggest moving the extension checking logic out of the loop. The reason is that this will enable the plugin to return next() if it determines that none of the extensions for the dropped files need to be inserted (IE a no op).