Skip to content

Commit

Permalink
prep build 10/16
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Oct 16, 2024
2 parents a8bbee0 + 27aed30 commit 3cd5e40
Show file tree
Hide file tree
Showing 52 changed files with 527 additions and 356 deletions.
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7552.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7552

* https://github.com/WordPress/gutenberg/pull/66058
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7561.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7561

* https://github.com/WordPress/gutenberg/pull/66084
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7575.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7575

* https://github.com/WordPress/gutenberg/pull/66154
2 changes: 1 addition & 1 deletion docs/how-to-guides/data-basics/3-building-an-edit-form.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,5 @@ function EditPageForm( { pageId, onCancel, onSaveFinished } ) {
## What's next?
* **Previous part:** [Building a list of pages](/docs/how-to-guides/data-basics/2-building-a-list-of-pages.md)
* **Next part:** Building a *New Page* form (coming soon)
* **Next part:** [Building a Create Page form](/docs/how-to-guides/data-basics/4-building-a-create-page-form.md)
* (optional) Review the [finished app](https://github.com/WordPress/block-development-examples/tree/trunk/plugins/data-basics-59c8f8) in the block-development-examples repository
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Part 4: Building a Create page form
# Building a Create page form

In the [previous part](/docs/how-to-guides/data-basics/3-building-an-edit-form.md) we created an *Edit page* feature, and in this part we will add a *Create page* feature. Here's a glimpse of what we're going to build:

Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"parent": "data-basics"
},
{
"title": "Part 4: Building a Create page form",
"title": "Building a Create page form",
"slug": "4-building-a-create-page-form",
"markdown_source": "../docs/how-to-guides/data-basics/4-building-a-create-page-form.md",
"parent": "data-basics"
Expand Down
8 changes: 2 additions & 6 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2732,17 +2732,13 @@ private static function update_separator_declarations( $declarations ) {
* @return array The block nodes in theme.json.
*/
private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) {
$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
$nodes = array();
if ( ! isset( $theme_json['styles'] ) ) {
return $nodes;
}
$nodes = array();

// Blocks.
if ( ! isset( $theme_json['styles']['blocks'] ) ) {
return $nodes;
}

$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
$include_variations = $options['include_block_style_variations'] ?? false;
$include_node_paths_only = $options['include_node_paths_only'] ?? false;

Expand Down
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function gutenberg_default_script_modules() {
switch ( $script_module_id ) {
/*
* Interactivity exposes two entrypoints, "/index" and "/debug".
* "/debug" should replalce "/index" in devlopment.
* "/debug" should replace "/index" in development.
*/
case '@wordpress/interactivity/debug':
if ( ! SCRIPT_DEBUG ) {
Expand Down
42 changes: 16 additions & 26 deletions lib/compat/wordpress-6.7/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,28 @@
*/

/**
* Adds the block bindings sources registered in the server to the editor settings.
*
* This allows them to be bootstrapped in the editor.
*
* @param array $settings The block editor settings from the `block_editor_settings_all` filter.
* @return array The editor settings including the block bindings sources.
* Bootstrap the block bindings sources registered in the server.
*/
function gutenberg_add_server_block_bindings_sources_to_editor_settings( $editor_settings ) {
// Check if the sources are already exposed in the editor settings.
if ( isset( $editor_settings['blockBindingsSources'] ) ) {
return $editor_settings;
}

$registered_block_bindings_sources = get_all_registered_block_bindings_sources();
if ( ! empty( $registered_block_bindings_sources ) ) {
// Initialize array.
$editor_settings['blockBindingsSources'] = array();
foreach ( $registered_block_bindings_sources as $source_name => $source_properties ) {
// Add source with the label to editor settings.
$editor_settings['blockBindingsSources'][ $source_name ] = array(
'label' => $source_properties->label,
function gutenberg_bootstrap_server_block_bindings_sources() {
$registered_sources = get_all_registered_block_bindings_sources();
if ( ! empty( $registered_sources ) ) {
$filtered_sources = array();
foreach ( $registered_sources as $source ) {
$filtered_sources[] = array(
'name' => $source->name,
'label' => $source->label,
'usesContext' => $source->uses_context,
);
// Add `usesContext` property if exists.
if ( ! empty( $source_properties->uses_context ) ) {
$editor_settings['blockBindingsSources'][ $source_name ]['usesContext'] = $source_properties->uses_context;
}
}
$script = sprintf( 'for ( const source of %s ) { ! wp.blocks.getBlockBindingsSource( source.name ) && wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) );
wp_add_inline_script(
'wp-blocks',
$script
);
}
return $editor_settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_add_server_block_bindings_sources_to_editor_settings', 10 );
add_action( 'enqueue_block_editor_assets', 'gutenberg_bootstrap_server_block_bindings_sources', 5 );

/**
* Initialize `canUpdateBlockBindings` editor setting if it doesn't exist. By default, it is `true` only for admin users.
Expand Down
2 changes: 1 addition & 1 deletion lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function gutenberg_menu() {
'gutenberg',
__( 'Experiments Settings', 'gutenberg' ),
__( 'Experiments', 'gutenberg' ),
'edit_posts',
'manage_options',
'gutenberg-experiments',
'the_gutenberg_experiments'
);
Expand Down
5 changes: 0 additions & 5 deletions packages/base-styles/_animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
@include reduce-motion("animation");
}

@mixin editor-canvas-resize-animation() {
transition: all 0.4s cubic-bezier(0.46, 0.03, 0.52, 0.96);
@include reduce-motion("transition");
}

// Deprecated
@mixin edit-post__fade-in-animation($speed: 0.08s, $delay: 0s) {
@warn "The `edit-post__fade-in-animation` mixin is deprecated. Use `animation__fade-in` instead.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ iframe[name="editor-canvas"] {
height: 100%;
display: block;
background-color: transparent;
@include editor-canvas-resize-animation;
}
5 changes: 3 additions & 2 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,15 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
font-size: $default-font-size;
font-family: $default-font;
color: $black;
font-weight: normal;

.is-zoomed-out & {
// Scale the font size based on the zoom level.
font-size: calc(#{$default-font-size} * ( 2 - var(--wp-block-editor-iframe-zoom-out-scale) ));
// Maintains an absolute font-size by counter-scaling based on the zoom level.
font-size: calc(#{$default-font-size} / var(--wp-block-editor-iframe-zoom-out-scale));
}

&.is-dragged-over {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ export function ZoomOutSeparator( {
<AnimatePresence>
{ isVisible && (
<motion.div
as="button"
layout={ ! isReducedMotion }
initial={ { height: 0 } }
animate={ { height: '120px' } }
animate={ {
// Use a height equal to that of the zoom out frame size.
height: 'calc(1 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale)',
} }
exit={ { height: 0 } }
transition={ {
type: 'tween',
duration: 0.2,
duration: isReducedMotion ? 0 : 0.2,
ease: [ 0.6, 0, 0.4, 1 ],
} }
className={ clsx(
Expand All @@ -124,10 +125,11 @@ export function ZoomOutSeparator( {
<motion.div
initial={ { opacity: 0 } }
animate={ { opacity: 1 } }
exit={ { opacity: 0 } }
exit={ { opacity: 0, transition: { delay: -0.125 } } }
transition={ {
type: 'tween',
ease: 'linear',
duration: 0.1,
delay: 0.125,
} }
>
{ __( 'Drop pattern.' ) }
Expand Down
66 changes: 64 additions & 2 deletions packages/block-editor/src/components/block-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import clsx from 'clsx';
*/
import { useMergeRefs } from '@wordpress/compose';
import { Popover } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import {
forwardRef,
useMemo,
Expand All @@ -21,6 +22,8 @@ import {
import { useBlockElement } from '../block-list/use-block-props/use-block-refs';
import usePopoverScroll from './use-popover-scroll';
import { rectUnion, getVisibleElementBounds } from '../../utils/dom';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;

Expand Down Expand Up @@ -74,12 +77,38 @@ function BlockPopover(
};
}, [ selectedElement ] );

const { isZoomOut, parentSectionBlock, isSectionSelected } = useSelect(
( select ) => {
const {
isZoomOut: isZoomOutSelector,
getSectionRootClientId,
getParentSectionBlock,
getBlockOrder,
} = unlock( select( blockEditorStore ) );

return {
isZoomOut: isZoomOutSelector(),
parentSectionBlock:
getParentSectionBlock( clientId ) ?? clientId,
isSectionSelected: getBlockOrder(
getSectionRootClientId()
).includes( clientId ),
};
},
[ clientId ]
);

// This element is used to position the zoom out view vertical toolbar
// correctly, relative to the selected section.
const parentSectionElement = useBlockElement( parentSectionBlock );

const popoverAnchor = useMemo( () => {
if (
// popoverDimensionsRecomputeCounter is by definition always equal or greater
// than 0. This check is only there to satisfy the correctness of the
// exhaustive-deps rule for the `useMemo` hook.
popoverDimensionsRecomputeCounter < 0 ||
( isZoomOut && ! parentSectionElement ) ||
! selectedElement ||
( bottomClientId && ! lastSelectedElement )
) {
Expand All @@ -88,6 +117,35 @@ function BlockPopover(

return {
getBoundingClientRect() {
// The zoom out view has a vertical block toolbar that should always
// be on the edge of the canvas, aligned to the top of the currently
// selected section. This condition changes the anchor of the toolbar
// to the section instead of the block to handle blocks that are
// not full width and nested blocks to keep section height.
if ( isZoomOut && isSectionSelected ) {
// Compute the height based on the parent section of the
// selected block, because the selected block may be
// shorter than the section.
const canvasElementRect = getVisibleElementBounds(
__unstableContentRef.current
);
const parentSectionElementRect =
getVisibleElementBounds( parentSectionElement );
const anchorHeight =
parentSectionElementRect.bottom -
parentSectionElementRect.top;

// Always use the width of the section root element to make sure
// the toolbar is always on the edge of the canvas.
const anchorWidth = canvasElementRect.width;
return new window.DOMRectReadOnly(
canvasElementRect.left,
parentSectionElementRect.top,
anchorWidth,
anchorHeight
);
}

return lastSelectedElement
? rectUnion(
getVisibleElementBounds( selectedElement ),
Expand All @@ -98,10 +156,14 @@ function BlockPopover(
contextElement: selectedElement,
};
}, [
popoverDimensionsRecomputeCounter,
isZoomOut,
parentSectionElement,
selectedElement,
bottomClientId,
lastSelectedElement,
selectedElement,
popoverDimensionsRecomputeCounter,
isSectionSelected,
__unstableContentRef,
] );

if ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

/**
* Source of truth for which block tools are showing in the block editor.
Expand All @@ -24,7 +25,9 @@ export function useShowBlockTools() {
getSettings,
__unstableGetEditorMode,
isTyping,
} = select( blockEditorStore );
getBlockOrder,
getSectionRootClientId,
} = unlock( select( blockEditorStore ) );

const clientId =
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();
Expand All @@ -42,10 +45,14 @@ export function useShowBlockTools() {
editorMode === 'edit' &&
isEmptyDefaultBlock;
const isZoomOut = editorMode === 'zoom-out';
const isSectionSelected = getBlockOrder(
getSectionRootClientId()
).includes( clientId );
const _showZoomOutToolbar =
clientId &&
isZoomOut &&
block?.attributes?.align === 'full' &&
! _showEmptyBlockSideInserter;
! _showEmptyBlockSideInserter &&
isSectionSelected;
const _showBlockToolbarPopover =
! _showZoomOutToolbar &&
! getSettings().hasFixedToolbar &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import clsx from 'clsx';
/**
* Internal dependencies
*/
import BlockPopover from '../block-popover';
import { PrivateBlockPopover as BlockPopover } from '../block-popover';
import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';
import useSelectedBlockToolProps from './use-selected-block-tool-props';
import ZoomOutToolbar from './zoom-out-toolbar';
Expand All @@ -29,6 +29,7 @@ export default function ZoomOutPopover( { clientId, __unstableContentRef } ) {

return (
<BlockPopover
__unstableContentRef={ __unstableContentRef }
clientId={ capturingClientId || clientId }
bottomClientId={ lastClientId }
className={ clsx( 'zoom-out-toolbar-popover', {
Expand Down
25 changes: 20 additions & 5 deletions packages/block-editor/src/components/iframe/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@

.block-editor-iframe__html {
transform-origin: top center;
@include editor-canvas-resize-animation;
// 400ms should match the animation speed used in iframe/index.js
$zoomOutAnimation: all 400ms cubic-bezier(0.46, 0.03, 0.52, 0.96);

// We don't want to animate the transform of the translateX because it is used
// to "center" the canvas. Leaving it on causes the canvas to slide around in
// odd ways.
transition: $zoomOutAnimation, transform 0s scale 0s;
@include reduce-motion("transition");

&.zoom-out-animation {
// we only want to animate the scaling when entering zoom out. When sidebars
// are toggled, the resizing of the iframe handles scaling the canvas as well,
// and the doubled animations cause very odd animations.
transition: $zoomOutAnimation, transform 0s;
}
}

.block-editor-iframe__html.is-zoomed-out {
$scale: var(--wp-block-editor-iframe-zoom-out-scale);
$frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size);
$inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height);
$content-height: var(--wp-block-editor-iframe-zoom-out-content-height);
$prev-container-width: var(--wp-block-editor-iframe-zoom-out-prev-container-width);

transform: scale(#{$scale});

$outer-container-width: var(--wp-block-editor-iframe-zoom-out-outer-container-width);
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw);
// Apply an X translation to center the scaled content within the available space.
transform: translateX(calc(( #{$outer-container-width} - #{ $container-width }) / 2 / #{$scale}));
scale: #{$scale};
background-color: $gray-300;

// Chrome seems to respect that transform scale shouldn't affect the layout size of the element,
Expand Down
Loading

0 comments on commit 3cd5e40

Please sign in to comment.