Skip to content

Commit

Permalink
Create file blocks when dropping multiple files at once (#11297)
Browse files Browse the repository at this point in the history
* Create file blocks when dropping multiple files at once
* Add changelog entry
  • Loading branch information
ocean90 committed Nov 1, 2018
1 parent 506187b commit de7121c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/block-library/CHANGELOG.md
@@ -1,3 +1,9 @@
## 2.1.8 (Unreleased)

### Polish

- File Block: Create file blocks when dropping multiple files at once.

## 2.1.7 (2018-10-30)

## 2.1.6 (2018-10-30)
Expand Down
23 changes: 15 additions & 8 deletions packages/block-library/src/file/index.js
Expand Up @@ -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 );

// File will be uploaded in componentDidMount()
blocks.push( createBlock( 'core/file', {
href: blobURL,
fileName: file.name,
textLinkHref: blobURL,
} ) );
} );

return blocks;
},
},
{
Expand Down

0 comments on commit de7121c

Please sign in to comment.