-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Show/Hide Unsynced/Synced Patterns - Fix Preview Button in B…
…lock Editor (#34) * Fixing pattern preview for WP 6.7. Adding ability to hide synced and unsynced patterns. * Version bump. * Doing prod build. --------- Co-authored-by: Ronald Huereca <[email protected]>
- Loading branch information
1 parent
7caf32e
commit 6486c09
Showing
17 changed files
with
5,944 additions
and
8,587 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array(), 'version' => '1472e41936552f67aa2d'); | ||
<?php return array('dependencies' => array(), 'version' => 'bad5a743eede878200a1'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-i18n', 'wp-plugins'), 'version' => 'e4831e8d3fc819aefa57'); | ||
<?php return array('dependencies' => array('wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '7b290f09beaf54ea94a4'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-i18n'), 'version' => '8acc3b91df9514a84ffc'); | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-i18n'), 'version' => 'fb0b42dfb9db277c7e2c'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,57 +1,46 @@ | ||
import { useEffect } from 'react'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
// Try to get ActionItem, but don't fail if it's not available | ||
let PluginPreviewMenuItem; | ||
try { | ||
const { PluginPreviewMenuItem: ImportedPluginPreviewMenuItem } = require( '@wordpress/editor' ); | ||
PluginPreviewMenuItem = ImportedPluginPreviewMenuItem; | ||
} catch ( e ) { | ||
// ActionItem not available | ||
} | ||
|
||
console.log( PluginPreviewMenuItem ); | ||
|
||
/** | ||
* Render a Preview Button. | ||
* | ||
* @return {Object} The rendered component. | ||
* @return {Object|null} The rendered component or null if ActionItem not available. | ||
*/ | ||
const PatternPreviewButton = () => { | ||
useEffect( () => { | ||
const headerToolbar = document.querySelector( '.edit-post-header' ); | ||
if ( null === headerToolbar ) { | ||
return; | ||
} | ||
|
||
// Get the left toolbar and add to it. | ||
const settingsToolbar = headerToolbar.querySelector( '.edit-post-header__settings' ); | ||
if ( null === settingsToolbar ) { | ||
return; | ||
} | ||
|
||
// Create the button. | ||
const button = document.createElement( 'a' ); | ||
button.className = 'dlx-button-preview components-button has-icon'; | ||
button.ariaLabel = __( 'Preview', 'pattern-wrangler' ); | ||
button.href = dlxPatternWranglerPreview.previewUrl; | ||
button.target = '_blank'; | ||
button.rel = 'noopener noreferrer'; | ||
|
||
// Add icon. | ||
const icon = document.createElement( 'svg' ); | ||
icon.className = 'dlx-pattern-wrangler-preview-icon'; | ||
icon.innerHTML = '<svg width="16" height="16" style="display: inline-block; margin-right: 8px;"><use xlink:href="#dlx-pattern-wrangler-preview-icon" /></svg>'; | ||
button.prepend( icon ); | ||
// Add the button to the toolbar as the first child. | ||
settingsToolbar.prepend( button ); | ||
}, [] ); | ||
// Return early if ActionItem isn't available | ||
if ( ! PluginPreviewMenuItem ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<svg height="0" width="0" xmlns="http://www.w3.org/2000/svg" style={ { display: 'none' } } aria-hidden="true"> | ||
<symbol id="dlx-pattern-wrangler-preview-icon" | ||
width="16" | ||
height="16" | ||
viewBox="0 0 512 512" | ||
> | ||
<path fill="currentColor" d="M304 24c0 13.3 10.7 24 24 24h102.1L207 271c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l223-223V184c0 13.3 10.7 24 24 24s24-10.7 24-24V24c0-13.3-10.7-24-24-24H328c-13.3 0-24 10.7-24 24zM72 32C32.2 32 0 64.2 0 104v336c0 39.8 32.2 72 72 72h336c39.8 0 72-32.2 72-72V312c0-13.3-10.7-24-24-24s-24 10.7-24 24v128c0 13.3-10.7 24-24 24H72c-13.3 0-24-10.7-24-24V104c0-13.3 10.7-24 24-24h128c13.3 0 24-10.7 24-24s-10.7-24-24-24H72z" /> | ||
</symbol> | ||
</svg> | ||
</> | ||
<PluginPreviewMenuItem | ||
icon="external" | ||
label={ __( 'Preview Pattern', 'pattern-wrangler' ) } | ||
onClick={ () => { | ||
window.open( dlxPatternWranglerPreview.previewUrl, '_blank' ); | ||
} } | ||
> | ||
{ __( 'Preview Pattern', 'pattern-wrangler' ) } | ||
</PluginPreviewMenuItem> | ||
); | ||
}; | ||
registerPlugin( 'dlx-pattern-wrangler-preview-button', { | ||
render: PatternPreviewButton, | ||
} ); | ||
|
||
// Only register if ActionItem is available | ||
if ( PluginPreviewMenuItem ) { | ||
registerPlugin( 'dlx-pattern-wrangler-preview-button', { | ||
render: PatternPreviewButton, | ||
} ); | ||
} | ||
|
Oops, something went wrong.