Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c4e5e68
Block Editor: Include resolved bound content when copying blocks
salvatorecorsi Oct 9, 2026
3cb94c5
Docs: Add changelog for resolved bound block copying
salvatorecorsi Oct 9, 2026
8a96fca
Tests: Disambiguate Copy from Copy styles in bound block E2E test
salvatorecorsi Oct 9, 2026
1dd5d84
Merge trunk to restore bound content copy contribution compatibility
salvatorecorsi Oct 16, 2026
967b369
Merge trunk and keep bound-content clipboard fixtures compatible with…
salvatorecorsi Oct 16, 2026
2ff68c4
Merge trunk into fix/copy-bound-block-content
salvatorecorsi Nov 2, 2026
d93737b
Merge trunk into fix/copy-bound-block-content
salvatorecorsi Nov 4, 2026
6fe84ff
Merge current trunk into PR #84428
salvatorecorsi Nov 9, 2026
b8c0df2
Merge upstream trunk into the bound content copy fix
salvatorecorsi Nov 16, 2026
53cf427
Preserve bound blocks and styles in menu clipboard actions
salvatorecorsi Nov 17, 2026
ad78b40
Merge trunk and preserve readable clipboard formats when pasting styles
salvatorecorsi Nov 18, 2026
47e52b6
Merge trunk and preserve original Gutenberg contribution changelogs
salvatorecorsi Nov 19, 2026
cf52e7a
Merge current trunk and preserve the focused fix
salvatorecorsi Nov 20, 2026
2e8faea
Block Editor: Preserve bound data across clipboard fallbacks
salvatorecorsi Nov 22, 2026
589f770
Preserve bound copy fallbacks and clipboard compatibility and merge t…
salvatorecorsi Nov 24, 2026
5771525
Preserve safe binding fallbacks and consistent copy wrappers
salvatorecorsi Nov 24, 2026
794e519
Merge current trunk and preserve the focused fix
salvatorecorsi Nov 24, 2026
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: 15 additions & 4 deletions docs/reference-guides/block-api/block-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ The function to register a custom source is `registerBlockBindingsSource( args )
- `name`: `string` with the unique and machine-readable name.
- `label`: `string` with the human readable name of the custom source. In case it was defined already on the server, the server label will be overridden by this one, in that case, it is not recommended to be defined here. (optional)
- `usesContext`: `array` with the block context that the custom source may need. In case it was defined already on the server, it should not be defined here. (optional)
- `supportsCopy`: `boolean` that opts the source in to resolving values for copied blocks. Defaults to `false`, so existing sources preserve the saved block attributes when copied. (optional)
- `getValues`: `function` that retrieves the values from the source. (optional)
- `setValues`: `function` that allows updating the values connected to the source. (optional)
- `canUserEditValue`: `function` to determine if the user can edit the value. The user won't be able to edit by default. (optional)
Expand All @@ -390,21 +391,28 @@ registerBlockBindingsSource( {
name: 'wpmovies/visualization-date',
label: __( 'Visualization Date', 'custom-bindings' ), // We can skip the label, as it was already defined in the server in the previous example.
usesContext: [ 'postType' ], // We can skip postId, as it was already defined in the server in the previous example.
getValues( { select, context } ) {
supportsCopy: true,
getValues( { select, context, isForCopy } ) {
let wpMoviesVisualizationDate;
const { getEditedEntityRecord } = select( coreDataStore );
if ( context?.postType && context?.postId ) {
wpMoviesVisualizationDate = getEditedEntityRecord(
'postType',
context?.postType,
context?.postId
).meta?.wp_movies_visualization_date;
)?.meta?.wp_movies_visualization_date;
}
if ( wpMoviesVisualizationDate ) {
if (
wpMoviesVisualizationDate ||
( isForCopy && wpMoviesVisualizationDate === '' )
) {
return {
content: wpMoviesVisualizationDate,
};
}
if ( isForCopy ) {
return {};
}

return {
content: new Date().toLocaleDateString( 'en-US' ),
Expand All @@ -430,16 +438,19 @@ registerBlockBindingsSource( {

#### getValues

The `getValues` function retrieves the value from the source on block loading. It receives an `object` as an argument with the following properties:
The `getValues` function retrieves values from the source when rendering a block. Sources with `supportsCopy: true` also receive copy requests to resolve bound attributes for the clipboard. It receives an `object` as an argument with the following properties:

- `bindings` returns the bindings object of the specific source. It must have the attributes as a key, and the value can be a `string` or an `object` with arguments.
- `clientId` returns a `string` with the current block client ID.
- `context` returns an `object` of the current block context, defined in the `usesContext` property. [More about block context.](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-context/).
- `isForCopy` is an optional `boolean` set to `true` when resolving clipboard values. It is omitted for display requests.
- `select` returns an `object` of a given store's selectors. [More info in their docs.](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-data/#select).

The function must return an `object` with this structure:
`{ 'block attribute' : value }`

Set `supportsCopy: true` only when the source handles copy requests. For copy requests, return the actual source values. Omit an attribute, or return `undefined` for it, when its value is unavailable and the editor displays a placeholder instead. This preserves the attribute's saved fallback in the copied block. Return genuine values even when they are empty, read-only, or equal to a field's key or label. In the example above, an empty stored date remains empty when copied, while missing or `null` meta omits the copied value; the display still falls back to today's date.

#### setValues

The `setValues` function updates all the values of the source of the block bound. It receives an `object` as an argument with the following properties:
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Writing flow: Bring back the editor header and block toolbar that iOS slides off screen when the on-screen keyboard opens, once the canvas stops scrolling ([#87316](https://github.com/WordPress/gutenberg/pull/87316)).
- Block states: Undo a text gradient set in Global Styles, for the block type or an applied block style variation, when a state or breakpoint sets a box clip or text color. A breakpoint pseudo-state now also undoes one set by the default pseudo-state ([#86245](https://github.com/WordPress/gutenberg/pull/86245)).
- List View: Arrow Left moves to the parent row when the parent is outside the render window ([#87266](https://github.com/WordPress/gutenberg/pull/87266)).
- Clipboard: Include resolved content from opted-in binding sources when copying blocks, preserve saved fallbacks and bindings, and consistently wrap copied List Items ([#84428](https://github.com/WordPress/gutenberg/pull/84428)).

### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ it( 'clears selection and focuses the editor canvas from the document button', a
const refsMap = observableMap< string, Element | null >();
await render(
<RegistryProvider value={ registry }>
<BlockRefs.Provider value={ { refsMap, eventHandlers: new Map() } }>
<BlockRefs.Provider
value={ {
refsMap,
eventHandlers: new Map(),
attributesForCopy: new Map(),
} }
>
<div
className="editor-styles-wrapper"
role="group"
Expand Down
105 changes: 92 additions & 13 deletions packages/block-editor/src/components/block-edit/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import {
} from '@wordpress/blocks';
import { withFilters } from '@wordpress/components';
import { useRegistry, useSelect } from '@wordpress/data';
import { useCallback, useContext, useMemo } from '@wordpress/element';
import {
useCallback,
useContext,
useLayoutEffect,
useMemo,
useRef,
} from '@wordpress/element';
import type { ComponentType } from 'react';
import type { BlockBindingsSource } from '@wordpress/blocks';
import BlockContext from '../block-context';
Expand All @@ -17,6 +23,8 @@ import {
replacePatternOverridesDefaultBinding,
} from '../../utils/block-bindings';
import { PrivateBlockContext } from '../block-list/private-block-context';
import { BlockRefs } from '../provider/block-refs-provider';
import { isPreviewModeKey, useBlockEditContext } from './context';
import type { BlockEditPublicProps } from './types';

const Edit = ( props: BlockEditPublicProps ) => {
Expand Down Expand Up @@ -54,6 +62,9 @@ const EditWithGeneratedProps = ( props: BlockEditPublicProps ) => {
bindableAttributes,
blockBindingsSources: registeredSources = NO_SOURCES,
} = useContext( PrivateBlockContext );
const { attributesForCopy } = useContext( BlockRefs );
const { [ isPreviewModeKey ]: isPreviewMode } = useBlockEditContext();
const instanceToken = useRef( {} ).current;

const { blockBindings, context, hasPatternOverrides } = useMemo( () => {
return {
Expand Down Expand Up @@ -88,26 +99,23 @@ const EditWithGeneratedProps = ( props: BlockEditPublicProps ) => {
registeredSources,
] );

const computedAttributes = useSelect(
( select ) => {
if ( ! blockBindings ) {
return attributes;
}

const getBoundAttributes = useCallback(
( select: typeof registry.select, isForCopy = false ) => {
const attributesFromSources: Record< string, unknown > = {};
const blockBindingsBySource = new Map<
Omit< BlockBindingsSource, 'name' >,
Record< string, { args?: Record< string, unknown > } >
>();

for ( const [ attributeName, binding ] of Object.entries(
blockBindings
blockBindings ?? {}
) ) {
const { source: sourceName, args: sourceArgs } = binding;
// An absent source looks up nothing.
const source = registeredSources[ sourceName as string ];
if (
! source ||
( isForCopy && source.supportsCopy !== true ) ||
! bindableAttributes?.includes( attributeName )
) {
continue;
Expand All @@ -126,6 +134,9 @@ const EditWithGeneratedProps = ( props: BlockEditPublicProps ) => {
// Get values in batch if the source supports it.
let values: Record< string, unknown > = {};
if ( ! source.getValues ) {
if ( isForCopy ) {
continue;
}
Object.keys( bindings ).forEach( ( attr ) => {
// Default to the source label when `getValues` doesn't exist.
values[ attr ] = source.label;
Expand All @@ -136,11 +147,15 @@ const EditWithGeneratedProps = ( props: BlockEditPublicProps ) => {
context,
clientId,
bindings,
...( isForCopy ? { isForCopy: true } : {} ),
} );
}
for ( const [ attributeName, value ] of Object.entries(
values
) ) {
if ( isForCopy && value === undefined ) {
continue;
}
if (
attributeName === 'url' &&
// Sources return URLs as strings.
Expand All @@ -155,20 +170,84 @@ const EditWithGeneratedProps = ( props: BlockEditPublicProps ) => {
}
}

return {
...attributes,
...attributesFromSources,
};
return attributesFromSources;
},
[
attributes,
bindableAttributes,
blockBindings,
clientId,
context,
registeredSources,
registry,
]
);
const computedAttributes = useSelect(
( select ) =>
blockBindings
? { ...attributes, ...getBoundAttributes( select ) }
: attributes,
[ attributes, blockBindings, getBoundAttributes ]
);
const getAttributesForCopy = useCallback(
() => getBoundAttributes( registry.select, true ),
[ getBoundAttributes, registry ]
);

const boundAttributeNames = useMemo(
() =>
Object.entries( blockBindings ?? {} )
.filter( ( [ attributeName, binding ] ) => {
const source =
registeredSources[ binding?.source as string ];
return (
bindableAttributes?.includes( attributeName ) &&
source?.supportsCopy === true &&
source.getValues
);
} )
.map( ( [ attributeName ] ) => attributeName ),
[ bindableAttributes, blockBindings, registeredSources ]
);
useLayoutEffect( () => {
if (
! clientId ||
! attributesForCopy ||
! boundAttributeNames.length ||
isPreviewMode ||
blockContext.query !== undefined ||
blockContext.queryId !== undefined ||
blockContext.termQuery !== undefined
) {
return;
}
const instances = attributesForCopy.get( clientId ) ?? new Map();
instances.set( instanceToken, {
attributes,
boundAttributeNames,
getAttributesForCopy,
} );
attributesForCopy.set( clientId, instances );
return () => {
instances.delete( instanceToken );
if (
! instances.size &&
attributesForCopy.get( clientId ) === instances
) {
attributesForCopy.delete( clientId );
}
};
}, [
attributes,
attributesForCopy,
blockContext.query,
blockContext.queryId,
blockContext.termQuery,
boundAttributeNames,
clientId,
getAttributesForCopy,
instanceToken,
isPreviewMode,
] );

const setBoundAttributes = useCallback(
( nextAttributes: Record< string, unknown > ) => {
Expand Down
Loading
Loading