-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
File Block: Add support for embedding PDFs #30857
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff41b60
Re-implement #24233.
pento a1fc013
Linting.
pento 7db1432
Build the final frontend.js file from the transpiled version, not the…
pento 42f0991
Rearrange the webpack config for determining block frontend entrypoints.
pento c75befe
Use `wp_script_is()` instead of manually checking the scripts queue.
pento a9bb5ea
Force the `displayPreview` flag to be boolean when toggling the setting.
pento df220ff
Fix a few potential errors.
pento e56b133
Update fixtures.
pento c7f3b38
A couple of minor fixes.
pento 7bee495
Make the default height a little shorter.
pento fd00c93
Fixing fixture file for fixed file (block) fixtures.
pento 23f3b34
Update the default height missed in 7bee495.
pento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { hidePdfEmbedsOnUnsupportedBrowsers } from './utils'; | ||
|
||
hidePdfEmbedsOnUnsupportedBrowsers(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/file` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-library-file` script. | ||
* | ||
* @param array $attributes The block attributes. | ||
* @param array $content The block content. | ||
* | ||
* @return string Returns the block content. | ||
*/ | ||
function render_block_core_file( $attributes, $content ) { | ||
if ( ! empty( $attributes['displayPreview'] ) ) { | ||
pento marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Check if it's already enqueued, so we don't add the inline script multiple times. | ||
if ( ! wp_script_is( 'wp-block-library-file' ) ) { | ||
wp_enqueue_script( 'wp-block-library-file', plugins_url( 'file/frontend.js', __FILE__ ) ); | ||
} | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
/** | ||
* Registers the `core/file` block on server. | ||
*/ | ||
function register_block_core_file() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/file', | ||
array( | ||
'render_callback' => 'render_block_core_file', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_file' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like this option and I believe we should probably extend it to various file types. Like QuickView for Gutenberg.
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.
Yes, it looks like previews for different file types are being discussed 👍🏻