Skip to content

Commit

Permalink
prep build 09/21
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Sep 21, 2024
2 parents 63e689b + e691b04 commit b62a40a
Show file tree
Hide file tree
Showing 35 changed files with 422 additions and 284 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ jobs:
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: build-assets
path: ./build/
path: |
./build/
./build-module/
test-php:
name: PHP ${{ matrix.php }}${{ matrix.multisite && ' multisite' || '' }}${{ matrix.wordpress != '' && format( ' (WP {0}) ', matrix.wordpress ) || '' }} on ubuntu-latest
Expand Down Expand Up @@ -212,7 +214,6 @@ jobs:
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: build-assets
path: ./build

- name: Docker debug information
run: |
Expand Down
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7360.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7360

* https://github.com/WordPress/gutenberg/pull/65460
50 changes: 50 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,56 @@ function gutenberg_register_vendor_scripts( $scripts ) {
}
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );

/**
* Registers or re-registers Gutenberg Script Modules.
*
* Script modules that are registered by Core will be re-registered by Gutenberg.
*
* @since 19.3.0
*/
function gutenberg_default_script_modules() {
/*
* Expects multidimensional array like:
*
* 'interactivity/index.min.js' => array('dependencies' => array(…), 'version' => '…'),
* 'interactivity/debug.min.js' => array('dependencies' => array(…), 'version' => '…'),
* 'interactivity-router/index.min.js' => …
*/
$assets = include gutenberg_dir_path() . '/build-module/assets.php';

foreach ( $assets as $file_name => $script_module_data ) {
/*
* Build the WordPress Script Module ID from the file name.
* Prepend `@wordpress/` and remove extensions and `/index` if present:
* - interactivity/index.min.js => @wordpress/interactivity
* - interactivity/debug.min.js => @wordpress/interactivity/debug
* - block-library/query/view.js => @wordpress/block-library/query/view
*/
$script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?\.min\.js$~D', '', $file_name, 1 );
switch ( $script_module_id ) {
/*
* Interactivity exposes two entrypoints, "/index" and "/debug".
* "/debug" should replalce "/index" in devlopment.
*/
case '@wordpress/interactivity/debug':
if ( ! SCRIPT_DEBUG ) {
continue 2;
}
$script_module_id = '@wordpress/interactivity';
break;
case '@wordpress/interactivity':
if ( SCRIPT_DEBUG ) {
continue 2;
}
break;
}

$path = gutenberg_url( "build-module/{$file_name}" );
wp_register_script_module( $script_module_id, $path, $script_module_data['dependencies'], $script_module_data['version'] );
}
}
remove_action( 'wp_default_scripts', 'wp_default_script_modules' );
add_action( 'wp_default_scripts', 'gutenberg_default_script_modules' );

/*
* Always remove the Core action hook while gutenberg_enqueue_stored_styles() exists to avoid styles being printed twice.
Expand Down
25 changes: 2 additions & 23 deletions lib/experimental/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,5 @@ function gutenberg_a11y_script_module_html() {
. '<div id="a11y-speak-polite" class="a11y-speak-region" aria-live="polite" aria-relevant="additions text" aria-atomic="true"></div>'
. '</div>';
}

/**
* Registers Gutenberg Script Modules.
*
* @since 19.3
*/
function gutenberg_register_script_modules() {
// When in production, use the plugin's version as the default asset version;
// else (for development or test) default to use the current time.
$default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();

wp_deregister_script_module( '@wordpress/a11y' );
wp_register_script_module(
'@wordpress/a11y',
gutenberg_url( 'build-module/a11y/index.min.js' ),
array(),
$default_version
);

add_action( 'wp_footer', 'gutenberg_a11y_script_module_html' );
add_action( 'admin_footer', 'gutenberg_a11y_script_module_html' );
}
add_action( 'init', 'gutenberg_register_script_modules' );
add_action( 'wp_footer', 'gutenberg_a11y_script_module_html' );
add_action( 'admin_footer', 'gutenberg_a11y_script_module_html' );
31 changes: 0 additions & 31 deletions lib/interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@
* @package gutenberg
*/

/**
* Deregisters the Core Interactivity API Modules and replace them
* with the ones from the Gutenberg plugin.
*/
function gutenberg_reregister_interactivity_script_modules() {
$default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
wp_deregister_script_module( '@wordpress/interactivity' );
wp_deregister_script_module( '@wordpress/interactivity-router' );

wp_register_script_module(
'@wordpress/interactivity',
gutenberg_url( '/build-module/' . ( SCRIPT_DEBUG ? 'interactivity/debug.min.js' : 'interactivity/index.min.js' ) ),
array(),
$default_version
);

wp_register_script_module(
'@wordpress/interactivity-router',
gutenberg_url( '/build-module/interactivity-router/index.min.js' ),
array(
array(
'id' => '@wordpress/a11y',
'import' => 'dynamic',
),
'@wordpress/interactivity',
),
$default_version
);
}
add_action( 'init', 'gutenberg_reregister_interactivity_script_modules' );

/**
* Adds script data to the interactivity-router script module.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,11 +1027,11 @@ _Parameters_

### useZoomOut

A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
A hook used to set the zoomed out view, invoking the hook sets the mode.

_Parameters_

- _zoomOut_ `boolean`: If we should enter into zoomOut mode or not
- _zoomOut_ `boolean`: If we should zoom out or not.

### Warning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import { unlock } from '../../../lock-unlock';
* @param {string} clientId Block client ID.
*/
export function useZoomOutModeExit( { editorMode } ) {
const { getSettings } = useSelect( blockEditorStore );
const { __unstableSetEditorMode } = unlock(
const { getSettings, isZoomOut } = unlock( useSelect( blockEditorStore ) );
const { __unstableSetEditorMode, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);

return useRefEffect(
( node ) => {
if ( editorMode !== 'zoom-out' ) {
// In "compose" mode.
const composeMode = editorMode === 'zoom-out' && isZoomOut();

if ( ! composeMode ) {
return;
}

Expand All @@ -39,6 +42,7 @@ export function useZoomOutModeExit( { editorMode } ) {
__experimentalSetIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
resetZoomLevel();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isRTL } from '@wordpress/i18n';
*/
import { store as blockEditorStore } from '../../store';
import { InsertionPointOpenRef } from '../block-tools/insertion-point';
import { unlock } from '../../lock-unlock';

export function useInBetweenInserter() {
const openRef = useContext( InsertionPointOpenRef );
Expand All @@ -31,7 +32,8 @@ export function useInBetweenInserter() {
getBlockEditingMode,
getBlockName,
getBlockAttributes,
} = useSelect( blockEditorStore );
getParentSectionBlock,
} = unlock( useSelect( blockEditorStore ) );
const { showInsertionPoint, hideInsertionPoint } =
useDispatch( blockEditorStore );

Expand Down Expand Up @@ -133,7 +135,8 @@ export function useInBetweenInserter() {
const clientId = element.id.slice( 'block-'.length );
if (
! clientId ||
__unstableIsWithinBlockOverlay( clientId )
__unstableIsWithinBlockOverlay( clientId ) ||
!! getParentSectionBlock( clientId )
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import BlockDraggable from '../block-draggable';
import BlockMover from '../block-mover';
import Shuffle from '../block-toolbar/shuffle';
import NavigableToolbar from '../navigable-toolbar';
import { unlock } from '../../lock-unlock';

export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
const selected = useSelect(
Expand Down Expand Up @@ -76,8 +77,9 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
setIsInserterOpened,
} = selected;

const { removeBlock, __unstableSetEditorMode } =
useDispatch( blockEditorStore );
const { removeBlock, __unstableSetEditorMode, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);

const showBlockDraggable = canMove && ! isBlockTemplatePart;

Expand Down Expand Up @@ -132,6 +134,7 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
setIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
resetZoomLevel();
__unstableContentRef.current?.focus();
} }
/>
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/tool-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Icon, edit as editIcon } from '@wordpress/icons';
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const selectIcon = (
<SVG
Expand All @@ -35,7 +36,9 @@ function ToolSelector( props, ref ) {
( select ) => select( blockEditorStore ).__unstableGetEditorMode(),
[]
);
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const { __unstableSetEditorMode } = unlock(
useDispatch( blockEditorStore )
);

return (
<Dropdown
Expand Down
5 changes: 2 additions & 3 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ export const withBlockBindingSupport = createHigherOrderComponent(
let values = {};
if ( ! source.getValues ) {
Object.keys( bindings ).forEach( ( attr ) => {
// Default to the `key` or the source label when `getValues` doesn't exist
values[ attr ] =
bindings[ attr ].args?.key || source.label;
// Default to the the source label when `getValues` doesn't exist.
values[ attr ] = source.label;
} );
} else {
values = source.getValues( {
Expand Down
48 changes: 21 additions & 27 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,40 @@ import { useEffect, useRef } from '@wordpress/element';
* Internal dependencies
*/
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';

/**
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
* A hook used to set the zoomed out view, invoking the hook sets the mode.
*
* @param {boolean} zoomOut If we should enter into zoomOut mode or not
* @param {boolean} zoomOut If we should zoom out or not.
*/
export function useZoomOut( zoomOut = true ) {
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );
const { setZoomLevel } = unlock( useDispatch( blockEditorStore ) );
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );

const originalEditingModeRef = useRef( null );
const mode = __unstableGetEditorMode();
const originalIsZoomOutRef = useRef( null );

useEffect( () => {
// Only set this on mount so we know what to return to when we unmount.
if ( ! originalEditingModeRef.current ) {
originalEditingModeRef.current = mode;
if ( ! originalIsZoomOutRef.current ) {
originalIsZoomOutRef.current = isZoomOut();
}

return () => {
// We need to use __unstableGetEditorMode() here and not `mode`, as mode may not update on unmount
if (
__unstableGetEditorMode() === 'zoom-out' &&
__unstableGetEditorMode() !== originalEditingModeRef.current
) {
__unstableSetEditorMode( originalEditingModeRef.current );
}
};
}, [] );

// The effect opens the zoom-out view if we want it open and it's not currently in zoom-out mode.
useEffect( () => {
if ( zoomOut && mode !== 'zoom-out' ) {
__unstableSetEditorMode( 'zoom-out' );
// The effect opens the zoom-out view if we want it open and the canvas is not currently zoomed-out.
if ( zoomOut && isZoomOut() === false ) {
setZoomLevel( 50 );
} else if (
! zoomOut &&
__unstableGetEditorMode() === 'zoom-out' &&
originalEditingModeRef.current !== mode
isZoomOut() &&
originalIsZoomOutRef.current !== isZoomOut()
) {
__unstableSetEditorMode( originalEditingModeRef.current );
setZoomLevel( originalIsZoomOutRef.current ? 50 : 100 );
}
}, [ __unstableGetEditorMode, __unstableSetEditorMode, zoomOut ] ); // Mode is deliberately excluded from the dependencies so that the effect does not run when mode changes.

return () => {
if ( isZoomOut() && isZoomOut() !== originalIsZoomOutRef.current ) {
setZoomLevel( originalIsZoomOutRef.current ? 50 : 100 );
}
};
}, [ isZoomOut, setZoomLevel, zoomOut ] );
}
23 changes: 23 additions & 0 deletions packages/block-editor/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,26 @@ export const modifyContentLockBlock =
focusModeToRevert
);
};

/**
* Sets the zoom level.
*
* @param {number} zoom the new zoom level
* @return {Object} Action object.
*/
export function setZoomLevel( zoom = 100 ) {
return {
type: 'SET_ZOOM_LEVEL',
zoom,
};
}

/**
* Resets the Zoom state.
* @return {Object} Action object.
*/
export function resetZoomLevel() {
return {
type: 'RESET_ZOOM_LEVEL',
};
}
20 changes: 20 additions & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,23 @@ export function isZoomOutMode( state ) {
export function getSectionRootClientId( state ) {
return state.settings?.[ sectionRootClientIdKey ];
}

/**
* Returns the zoom out state.
*
* @param {Object} state Global application state.
* @return {boolean} The zoom out state.
*/
export function getZoomLevel( state ) {
return state.zoomLevel;
}

/**
* Returns whether the editor is considered zoomed out.
*
* @param {Object} state Global application state.
* @return {boolean} Whether the editor is zoomed.
*/
export function isZoomOut( state ) {
return getZoomLevel( state ) < 100;
}
Loading

0 comments on commit b62a40a

Please sign in to comment.