-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create file blocks when dropping multiple files at once #11297
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,20 +77,27 @@ export const settings = { | |
from: [ | ||
{ | ||
type: 'files', | ||
isMatch: ( files ) => files.length === 1, | ||
isMatch( files ) { | ||
return files.length > 0; | ||
}, | ||
// We define a lower priorty (higher number) than the default of 10. This | ||
// ensures that the File block is only created as a fallback. | ||
priority: 15, | ||
transform: ( files ) => { | ||
const file = files[ 0 ]; | ||
const blobURL = createBlobURL( file ); | ||
const blocks = []; | ||
|
||
// File will be uploaded in componentDidMount() | ||
return createBlock( 'core/file', { | ||
href: blobURL, | ||
fileName: file.name, | ||
textLinkHref: blobURL, | ||
files.map( ( file ) => { | ||
const blobURL = createBlobURL( file ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope of this PR but I thought I'd mention for context. Ideally, we shouldn't rely on the That said, we don't have a proper solution for this problem at the moment, we'll more likely need to think about a "reactive" transform API but this is not high-priority. |
||
|
||
// File will be uploaded in componentDidMount() | ||
blocks.push( createBlock( 'core/file', { | ||
href: blobURL, | ||
fileName: file.name, | ||
textLinkHref: blobURL, | ||
} ) ); | ||
} ); | ||
|
||
return blocks; | ||
}, | ||
}, | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isMatch
is required pergutenberg/packages/editor/src/components/block-drop-zone/index.js
Line 62 in fe51bd0