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

Throwaway: merge content editing with toolbar anchoring #65844

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9b2bc9f
Edit Mode: Prevent editable text selection on first click
youknowriad Sep 27, 2024
a9c5e10
Show zoom-out toolbar even when child blocks are selected
youknowriad Sep 27, 2024
8635e98
ToggleGroupControl: Fix arrow key navigation in RTL (#65735)
mirka Sep 30, 2024
bb29dbd
`Tabs`: tweak sizing and overflow behavior of TabList (#64371)
DaniGuardiola Sep 30, 2024
39f2aa7
Update tools menus with Write / Design order (#65721)
mtias Sep 30, 2024
4443474
Only show zoom out inserters on block selection (#65759)
jeryj Sep 30, 2024
cfabf03
Block Bindings: Open the stable editor APIs (#65713)
SantosGuillamot Oct 1, 2024
cb403ea
Update versions-in-wordpress.md
noisysocks Oct 1, 2024
9c64c8c
List view: fix miscolored icons (#65707)
t-hamano Oct 1, 2024
fd467a8
Buttons: add box-sizing:border-box rule (#65716)
t-hamano Oct 1, 2024
8502b3f
Update block-filters.md (#64959)
davy440 Oct 1, 2024
d3f4a3b
limit zoom out toggle to specific post types (#65732)
draganescu Oct 1, 2024
91578d0
SearchControl: Fix rest props mutation (#65740)
tyxla Oct 1, 2024
d3780dd
Edit Site: Fix useLink prop mutation (#65739)
tyxla Oct 1, 2024
dbbe52d
Button: Add `__next40pxDefaultSize` in block-editor 6 (#65742)
mirka Oct 1, 2024
d637d8a
Navigator: use stable export instead of experimental export (#65753)
ciampo Oct 1, 2024
3b10909
Navigator: fix README heading hierarchy (#65763)
ciampo Oct 1, 2024
fba175d
Remove editorMode from blockProps (#65326)
jeryj Oct 1, 2024
bc2eb38
Temp disable test for Classic Block Media issue (#65793)
getdave Oct 1, 2024
5b6b849
BorderControl: Promote to stable (#65475)
DaniGuardiola Oct 1, 2024
dbd79a7
ToggleGroupControl: improve animation (#65175)
DaniGuardiola Oct 1, 2024
493cfe6
Fix focus loss when deleting selected block in zoom out mode (#65761)
jeryj Oct 1, 2024
44aaefb
Social Links: Fix block appender size (#65769)
t-hamano Oct 1, 2024
56542d6
Revert "Temp disable test for Classic Block Media issue (#65793)" (#6…
peterwilsoncc Oct 1, 2024
06297ca
Restore accidentally removed entries in changelog (components package…
DaniGuardiola Oct 2, 2024
fc6cd26
Global style revisions: remove unnecessary `goTo` navigation call (#6…
ramonjd Oct 2, 2024
d727b8a
Block Bindings: Add `@since` tag in bindings apis JSDocs (#65796)
SantosGuillamot Oct 2, 2024
24e5a7c
Resize cover block only in normal mode (#65731)
draganescu Oct 2, 2024
6da8fab
Inserter: Fix Block visibility manager (#65700)
youknowriad Oct 2, 2024
a502791
Avoid errors when a fontSize preset is not available (#65791)
matiasbenedetto Oct 2, 2024
9cd64c0
Hide Zoom Out inserter buttons when dragging (#65789)
getdave Oct 2, 2024
5ab5789
Fix: Shadow/Font size preset panel crashes the editor (#65765)
t-hamano Oct 2, 2024
377316a
Composite: always await initial render setup in unit tests (#65823)
ciampo Oct 2, 2024
7c339b1
Navigator: mark experimental exports as deprecated (#65802)
ciampo Oct 2, 2024
78c0be8
Docs/interactivity api router package readme (#62062)
juanmaguitar Oct 2, 2024
2b6b567
Composite: fix legacy implementation passing store prop (#65821)
ciampo Oct 2, 2024
e0a8d29
DataForm - Add combined fields support (#65399)
louwie17 Oct 2, 2024
6aa8828
Customize widgets, edit post: refactor Button to new sizes (#65807)
ciampo Oct 2, 2024
2d532d6
enable vertical toolbar for non full width elements, anchor based on …
draganescu Sep 24, 2024
ff91129
Update packages/block-editor/src/components/block-popover/index.js
draganescu Sep 25, 2024
9ef0991
Update packages/block-editor/src/components/block-popover/index.js
draganescu Sep 25, 2024
dd8d563
make zoom out check a dependency of the memoization, improve code rea…
draganescu Sep 30, 2024
6207a57
comment typos
draganescu Oct 1, 2024
9d26cb9
subscribe to state instead of calculating zoom out view state when ca…
draganescu Oct 1, 2024
268eaa7
get the section wrapper for anchoring instead of the parent
draganescu Oct 2, 2024
025582c
use a selector instead of computing on the fly the parent section
draganescu Oct 2, 2024
0fb8736
check if the block element exists yet before computing the anchor
draganescu Oct 2, 2024
da6458c
check if the block element exists yet before computing the anchor
draganescu Oct 2, 2024
ac617ac
merged work
draganescu Oct 2, 2024
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
1 change: 1 addition & 0 deletions docs/contributors/versions-in-wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ If anything looks incorrect here, please bring it up in #core-editor in [WordPre

| Gutenberg Versions | WordPress Version |
| ------------------ | ----------------- |
| 18.6-19.3 | 6.7 |
| 17.8-18.5 | 6.6.1 |
| 17.8-18.5 | 6.6 |
| 16.8-17.7 | 6.5.5 |
Expand Down
25 changes: 25 additions & 0 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ Used to filter an individual transform result from block transformation. All of

Called immediately after the default parsing of a block's attributes and before validation to allow a plugin to manipulate attribute values in time for validation and/or the initial values rendering of the block in the editor.

The callback function for this filter accepts 4 parameters:
- `blockAttributes` (`Object`): All block attributes.
- `blockType` (`Object`): The block type.
- `innerHTML` (`string`): Raw block content.
- `attributes` (`object`): Known block attributes (from delimiters).

In the example below, we use the `blocks.getBlockAttributes` filter to lock the position of all paragraph blocks on a page.

```js
// Our filter function
function lockParagraphs( blockAttributes, blockType, innerHTML, attributes ) {
if('core/paragraph' === blockType.name) {
blockAttributes['lock'] = {move: true}
}
return blockAttributes;
}

// Add the filter
wp.hooks.addFilter(
'blocks.getBlockAttributes',
'my-plugin/lock-paragraphs',
lockParagraphs
);
```

### `editor.BlockEdit`

Used to modify the block's `edit` component. It receives the original block `BlockEdit` component and returns a new wrapped component.
Expand Down
46 changes: 46 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,52 @@ _Related_

- <https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-popover/README.md>

### useBlockBindingsUtils

Retrieves the existing utils needed to update the block `bindings` metadata. They can be used to create, modify, or remove connections from the existing block attributes.

It contains the following utils:

- `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.
- `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.

_Usage_

```js
import { useBlockBindingsUtils } from '@wordpress/block-editor';
const { updateBlockBindings, removeAllBlockBindings } = useBlockBindingsUtils();

// Update url and alt attributes.
updateBlockBindings( {
url: {
source: 'core/post-meta',
args: {
key: 'url_custom_field',
},
},
alt: {
source: 'core/post-meta',
args: {
key: 'text_custom_field',
},
},
} );

// Remove binding from url attribute.
updateBlockBindings( { url: undefined } );

// Remove bindings from all attributes.
removeAllBlockBindings();
```

_Returns_

- `?WPBlockBindingsUtils`: Object containing the block bindings utils.

_Changelog_

`6.7.0` Introduced in WordPress core.

### useBlockCommands

Undocumented declaration.
Expand Down
6 changes: 0 additions & 6 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ function BlockListBlockProvider( props ) {
isBlockBeingDragged,
isDragging,
__unstableHasActiveBlockOverlayActive,
__unstableGetEditorMode,
getSelectedBlocksInitialCaretPosition,
} = unlock( select( blockEditorStore ) );
const blockWithoutAttributes =
Expand Down Expand Up @@ -680,8 +679,6 @@ function BlockListBlockProvider( props ) {
blocksWithSameName.length &&
blocksWithSameName[ 0 ] !== clientId;

const editorMode = __unstableGetEditorMode();

return {
...previewContext,
mode: getBlockMode( clientId ),
Expand All @@ -708,7 +705,6 @@ function BlockListBlockProvider( props ) {
) && hasSelectedInnerBlock( clientId ),
blockApiVersion: blockType?.apiVersion || 1,
blockTitle: match?.title || blockType?.title,
editorMode,
isSubtreeDisabled:
blockEditingMode === 'disabled' &&
isBlockSubtreeDisabled( clientId ),
Expand Down Expand Up @@ -755,7 +751,6 @@ function BlockListBlockProvider( props ) {
themeSupportsLayout,
isTemporarilyEditingAsBlocks,
blockEditingMode,
editorMode,
mayDisplayControls,
mayDisplayParentControls,
index,
Expand Down Expand Up @@ -808,7 +803,6 @@ function BlockListBlockProvider( props ) {
hasOverlay,
initialPosition,
blockEditingMode,
editorMode,
isHighlighted,
isMultiSelected,
isPartiallySelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
name,
blockApiVersion,
blockTitle,
editorMode,
isSelected,
isSubtreeDisabled,
hasOverlay,
Expand Down Expand Up @@ -113,7 +112,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
useBlockRefProvider( clientId ),
useFocusHandler( clientId ),
useEventHandlers( { clientId, isSelected } ),
useZoomOutModeExit( { editorMode } ),
useZoomOutModeExit(),
useIsHovered( { clientId } ),
useIntersectionObserver(),
useMovingAnimation( { triggerAnimationOnChange: index, clientId } ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ import { unlock } from '../../../lock-unlock';

/**
* Allows Zoom Out mode to be exited by double clicking in the selected block.
*
* @param {string} clientId Block client ID.
*/
export function useZoomOutModeExit( { editorMode } ) {
const { getSettings, isZoomOut } = unlock( useSelect( blockEditorStore ) );
export function useZoomOutModeExit() {
const { getSettings, isZoomOut, __unstableGetEditorMode } = unlock(
useSelect( blockEditorStore )
);

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

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

if ( ! composeMode ) {
return;
}
if ( ! composeMode ) {
return;
}

function onDoubleClick( event ) {
if ( ! event.defaultPrevented ) {
event.preventDefault();

Expand All @@ -52,6 +54,12 @@ export function useZoomOutModeExit( { editorMode } ) {
node.removeEventListener( 'dblclick', onDoubleClick );
};
},
[ editorMode, getSettings, __unstableSetEditorMode ]
[
getSettings,
__unstableSetEditorMode,
__unstableGetEditorMode,
isZoomOut,
resetZoomLevel,
]
);
}
61 changes: 61 additions & 0 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,39 @@ function BlockPopover(
};
}, [ selectedElement ] );

const { isZoomOut, sectionRootClientId, getParentSectionBlock } = useSelect(
( select ) => {
const {
isZoomOut: isZoomOutSelector,
getSectionRootClientId,
getParentSectionBlock: getParentSectionBlockFn,
} = unlock( select( blockEditorStore ) );

const root = getSectionRootClientId();
return {
sectionRootClientId: root,
isZoomOut: isZoomOutSelector(),
getParentSectionBlock: getParentSectionBlockFn,
};
},
[]
);

// These elements are used to position the zoom out view vertical toolbar
// correctly, relative to the selected section.
const rootSectionElement = useBlockElement( sectionRootClientId );
const parentSectionElement = useBlockElement(
getParentSectionBlock( clientId ) ?? clientId
);

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 ||
! rootSectionElement ||
! parentSectionElement ||
! selectedElement ||
( bottomClientId && ! lastSelectedElement )
) {
Expand All @@ -88,6 +118,36 @@ 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 blocksn that are
// not full width and nested blocks to keep section height.
if ( isZoomOut ) {
// Compute the height based on the parent section of the
// selected block, because the selected block may be
// shorter than the section.
const rootSectionElementRect =
getVisibleElementBounds( rootSectionElement );
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 andchorWidth =
rootSectionElementRect.right -
rootSectionElementRect.left;
return new window.DOMRectReadOnly(
rootSectionElementRect.left,
parentSectionElementRect.top,
andchorWidth,
anchorHeight
);
}

return lastSelectedElement
? rectUnion(
getVisibleElementBounds( selectedElement ),
Expand All @@ -102,6 +162,7 @@ function BlockPopover(
lastSelectedElement,
selectedElement,
popoverDimensionsRecomputeCounter,
isZoomOut,
] );

if ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {
Expand Down
34 changes: 25 additions & 9 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@ function selector( select ) {
getSettings,
__unstableGetEditorMode,
isTyping,
} = select( blockEditorStore );
isSectionBlock,
getParentSectionBlock,
isDragging,
} = unlock( select( blockEditorStore ) );

const clientId =
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();

const editorMode = __unstableGetEditorMode();
const isZoomOut = editorMode === 'zoom-out';
let zoomOutToolbarClientId;
if ( isZoomOut ) {
zoomOutToolbarClientId = isSectionBlock( clientId )
? clientId
: getParentSectionBlock( clientId );
}

return {
clientId,
zoomOutToolbarClientId,
hasFixedToolbar: getSettings().hasFixedToolbar,
isTyping: isTyping(),
isZoomOutMode: editorMode === 'zoom-out',
isZoomOutMode: isZoomOut,
isDragging: isDragging(),
};
}

Expand All @@ -63,10 +75,14 @@ export default function BlockTools( {
__unstableContentRef,
...props
} ) {
const { clientId, hasFixedToolbar, isTyping, isZoomOutMode } = useSelect(
selector,
[]
);
const {
clientId,
zoomOutToolbarClientId,
hasFixedToolbar,
isTyping,
isZoomOutMode,
isDragging,
} = useSelect( selector, [] );
const isMatch = useShortcutEventMatch();
const {
getBlocksByClientId,
Expand Down Expand Up @@ -221,10 +237,10 @@ export default function BlockTools( {
/>
) }

{ showZoomOutToolbar && (
{ showZoomOutToolbar && !! zoomOutToolbarClientId && (
<ZoomOutPopover
__unstableContentRef={ __unstableContentRef }
clientId={ clientId }
clientId={ zoomOutToolbarClientId }
/>
) }

Expand All @@ -241,7 +257,7 @@ export default function BlockTools( {
name="__unstable-block-tools-after"
ref={ blockToolbarAfterRef }
/>
{ isZoomOutMode && (
{ isZoomOutMode && ! isDragging && (
<ZoomOutModeInserters
__unstableContentRef={ __unstableContentRef }
/>
Expand Down
8 changes: 0 additions & 8 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,3 @@
border: none;
}
}

.block-editor-block-tools__zoom-out-mode-inserter-button {
visibility: hidden;

&.is-visible {
visibility: visible;
}
}
Loading
Loading