Skip to content
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

Fix block widget edit shortcuts #53

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions src/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from 'jquery';
import getAPI from './helpers/api';
import { off, send } from './helpers/messenger';
import { send } from './helpers/messenger';
import addFocusListener from './modules/focus-listener';
import { bindPreviewEventsListener } from './helpers/record-event';
import addGuide from './modules/guide';
Expand All @@ -18,11 +18,6 @@ api.bind( 'ready', () => {
addFocusListener( 'focus-menu', id => api.section( id ) );
addFocusListener( 'focus-menu-location', id => api.control( `nav_menu_locations[${ id }]` ) );

// disable core so we can enhance by making sure the controls panel opens
// before trying to focus the widget
off( 'focus-widget-control', api.Widgets.focusWidgetFormControl );
addFocusListener( 'focus-widget-control', id => api.Widgets.getWidgetFormControlForWidget( id ) );

// Toggle icons when customizer toggles preview mode
$( '.collapse-sidebar' ).on( 'click', () => send( 'cdm-toggle-visible' ) );

Expand Down
1 change: 1 addition & 0 deletions src/helpers/icon-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function addClickHandlerToIcon( element ) {
if ( ! element.$icon ) {
return element;
}

addClickHandler( `.${ getIconClassName( element.id ) }`, element.handler );
return element;
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/focus-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function makeHandler( eventName, getControlCallback ) {
const eventTargetId = args[ 0 ];
debug( `received ${ eventName } event for target id ${ eventTargetId }` );
const focusableControl = getControlCallback.apply( getControlCallback, args );

if ( ! focusableControl ) {
debug( `no control found for event ${ eventName } and args:`, args );
return;
Expand Down
15 changes: 11 additions & 4 deletions src/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isSafari, isMobileSafari } from './helpers/user-agent';
import makeFocusable from './modules/focusable';
import { modifyEditPostLinks, disableEditPostLinks } from './modules/edit-post-links';
import { getHeaderElements } from './modules/header-focus';
import { getWidgetElements } from './modules/widget-focus';
import { getMenuElements } from './modules/menu-focus';
import { getFooterElements } from './modules/footer-focus';
import { getSiteLogoElements } from './modules/site-logo-focus';
Expand All @@ -20,7 +19,15 @@ const api = getAPI();
function disableEditShortcuts() {
if ( api.selectiveRefresh && api.selectiveRefresh.Partial && api.selectiveRefresh.Partial.prototype.createEditShortcutForPlacement ) {
debug( 'disabling edit shortcuts' );
api.selectiveRefresh.Partial.prototype.createEditShortcutForPlacement = function() {};

// This is crude but necessary to fix the broken widget shortcuts that broke when block widgets were introduced
// We effectively skip overriding/disabling the default shortcut for widget partials
const createEditShortcutForPlacement = api.selectiveRefresh.Partial.prototype.createEditShortcutForPlacement;
api.selectiveRefresh.Partial.prototype.createEditShortcutForPlacement = function( ...args ) {
if ( args[ 0 ] && args[ 0 ].partial && args[ 0 ].partial.id.startsWith( 'widget' ) ) {
createEditShortcutForPlacement.apply( this, args );
}
};
Comment on lines +25 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even legal? 😆

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it fixes it! 👍

} else {
debug( 'no edit shortcuts support detected' );
}
Expand All @@ -33,11 +40,11 @@ function startDirectManipulation() {
{ id: 'blogname', selector: '.site-title, #site-title', type: 'siteTitle', position: 'middle', title: 'site title' },
];
const headers = ! options.headerImageSupport ? [] : getHeaderElements();
const widgets = isDisabled( 'widget-focus' ) ? [] : getWidgetElements();
const menus = isDisabled( 'menu-focus' ) ? [] : getMenuElements();
const footers = isDisabled( 'footer-focus' ) ? [] : getFooterElements();
const siteLogo = isDisabled( 'site-logo-focus' ) ? [] : getSiteLogoElements();
makeFocusable( basicElements.concat( headers, widgets, menus, footers, siteLogo ) );

makeFocusable( basicElements.concat( headers, menus, footers, siteLogo ) );

if ( ! isDisabled( 'edit-post-links' ) ) {
if ( isSafari() && ! isMobileSafari() ) {
Expand Down