Skip to content

Commit

Permalink
prep build 11/08
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Nov 8, 2024
2 parents dd95a69 + 93a025d commit 2c70121
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Hide and show additional content. ([Source](https://github.com/WordPress/gutenbe

- **Name:** core/details
- **Category:** text
- **Supports:** align (full, wide), color (background, gradients, link, text), interactivity (clientNavigation), layout (~~allowEditing~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), interactivity (clientNavigation), layout (~~allowEditing~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** showContent, summary

## Embed
Expand Down
17 changes: 17 additions & 0 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ function Iframe( {
preventFileDropDefault,
false
);
// Prevent clicks on links from navigating away. Note that links
// inside `contenteditable` are already disabled by the browser, so
// this is for links in blocks outside of `contenteditable`.
iFrameDocument.addEventListener( 'click', ( event ) => {
if ( event.target.tagName === 'A' ) {
event.preventDefault();

// Appending a hash to the current URL will not reload the
// page. This is useful for e.g. footnotes.
const href = event.target.getAttribute( 'href' );
if ( href.startsWith( '#' ) ) {
iFrameDocument.defaultView.location.hash =
href.slice( 1 );
}
}
} );
}

node.addEventListener( 'load', onLoad );
Expand Down Expand Up @@ -272,6 +288,7 @@ function Iframe( {
<html>
<head>
<meta charset="utf-8">
<base href="${ window.location.origin }">
<script>window.frameElement._load()</script>
<style>
html{
Expand Down
11 changes: 5 additions & 6 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) {
*
* @return {Object[]} Tree of block objects with only clientID and innerBlocks set.
*/
export const getEnabledClientIdsTree = createSelector(
getEnabledClientIdsTreeUnmemoized,
( state ) => [
export const getEnabledClientIdsTree = createRegistrySelector( ( select ) =>
createSelector( getEnabledClientIdsTreeUnmemoized, ( state ) => [
state.blocks.order,
state.blockEditingModes,
state.settings.templateLock,
state.blockListSettings,
state.editorMode,
select( STORE_NAME ).__unstableGetEditorMode( state ),
state.zoomLevel,
getSectionRootClientId( state ),
]
] )
);

/**
Expand Down Expand Up @@ -317,7 +316,7 @@ export const hasAllowedPatterns = createRegistrySelector( ( select ) =>
},
( state, rootClientId ) => [
...getAllPatternsDependants( select )( state ),
...getInsertBlockTypeDependants( state, rootClientId ),
...getInsertBlockTypeDependants( select )( state, rootClientId ),
]
)
);
Expand Down
95 changes: 52 additions & 43 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,12 @@ const canInsertBlockTypeUnmemoized = (
*
* @return {boolean} Whether the given block type is allowed to be inserted.
*/
export const canInsertBlockType = createSelector(
canInsertBlockTypeUnmemoized,
( state, blockName, rootClientId ) =>
getInsertBlockTypeDependants( state, rootClientId )
export const canInsertBlockType = createRegistrySelector( ( select ) =>
createSelector(
canInsertBlockTypeUnmemoized,
( state, blockName, rootClientId ) =>
getInsertBlockTypeDependants( select )( state, rootClientId )
)
);

/**
Expand Down Expand Up @@ -2224,7 +2226,7 @@ export const getInserterItems = createRegistrySelector( ( select ) =>
unlock( select( STORE_NAME ) ).getReusableBlocks(),
state.blocks.order,
state.preferences.insertUsage,
...getInsertBlockTypeDependants( state, rootClientId ),
...getInsertBlockTypeDependants( select )( state, rootClientId ),
]
)
);
Expand Down Expand Up @@ -2255,44 +2257,51 @@ export const getInserterItems = createRegistrySelector( ( select ) =>
* this item.
* @property {number} frecency Heuristic that combines frequency and recency.
*/
export const getBlockTransformItems = createSelector(
( state, blocks, rootClientId = null ) => {
const normalizedBlocks = Array.isArray( blocks ) ? blocks : [ blocks ];
const buildBlockTypeTransformItem = buildBlockTypeItem( state, {
buildScope: 'transform',
} );
const blockTypeTransformItems = getBlockTypes()
.filter( ( blockType ) =>
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
)
.map( buildBlockTypeTransformItem );
export const getBlockTransformItems = createRegistrySelector( ( select ) =>
createSelector(
( state, blocks, rootClientId = null ) => {
const normalizedBlocks = Array.isArray( blocks )
? blocks
: [ blocks ];
const buildBlockTypeTransformItem = buildBlockTypeItem( state, {
buildScope: 'transform',
} );
const blockTypeTransformItems = getBlockTypes()
.filter( ( blockType ) =>
canIncludeBlockTypeInInserter(
state,
blockType,
rootClientId
)
)
.map( buildBlockTypeTransformItem );

const itemsByName = Object.fromEntries(
Object.entries( blockTypeTransformItems ).map( ( [ , value ] ) => [
value.name,
value,
] )
);
const itemsByName = Object.fromEntries(
Object.entries( blockTypeTransformItems ).map(
( [ , value ] ) => [ value.name, value ]
)
);

const possibleTransforms = getPossibleBlockTransformations(
normalizedBlocks
).reduce( ( accumulator, block ) => {
if ( itemsByName[ block?.name ] ) {
accumulator.push( itemsByName[ block.name ] );
}
return accumulator;
}, [] );
return orderBy(
possibleTransforms,
( block ) => itemsByName[ block.name ].frecency,
'desc'
);
},
( state, blocks, rootClientId ) => [
getBlockTypes(),
state.preferences.insertUsage,
...getInsertBlockTypeDependants( state, rootClientId ),
]
const possibleTransforms = getPossibleBlockTransformations(
normalizedBlocks
).reduce( ( accumulator, block ) => {
if ( itemsByName[ block?.name ] ) {
accumulator.push( itemsByName[ block.name ] );
}
return accumulator;
}, [] );
return orderBy(
possibleTransforms,
( block ) => itemsByName[ block.name ].frecency,
'desc'
);
},
( state, blocks, rootClientId ) => [
getBlockTypes(),
state.preferences.insertUsage,
...getInsertBlockTypeDependants( select )( state, rootClientId ),
]
)
);

/**
Expand Down Expand Up @@ -2360,7 +2369,7 @@ export const getAllowedBlocks = createRegistrySelector( ( select ) =>
( state, rootClientId ) => [
getBlockTypes(),
unlock( select( STORE_NAME ) ).getReusableBlocks(),
...getInsertBlockTypeDependants( state, rootClientId ),
...getInsertBlockTypeDependants( select )( state, rootClientId ),
]
)
);
Expand Down Expand Up @@ -2435,7 +2444,7 @@ export const __experimentalGetParsedPattern = createRegistrySelector(

const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => [
...getAllPatternsDependants( select )( state ),
...getInsertBlockTypeDependants( state, rootClientId ),
...getInsertBlockTypeDependants( select )( state, rootClientId ),
];

const patternsWithParsedBlocks = new WeakMap();
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/store/test/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ describe( 'private selectors', () => {
'9b9c5c3f-2e46-4f02-9e14-9fe9515b958f': {},
},
};
getEnabledClientIdsTree.registry = {
select: jest.fn( () => ( {
__unstableGetEditorMode: () => 'edit',
} ) ),
};

it( 'should return tree containing only clientId and innerBlocks', () => {
const state = {
Expand Down
23 changes: 12 additions & 11 deletions packages/block-editor/src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ export const getAllPatternsDependants = ( select ) => ( state ) => {
];
};

export function getInsertBlockTypeDependants( state, rootClientId ) {
return [
state.blockListSettings[ rootClientId ],
state.blocks.byClientId.get( rootClientId ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
state.blockEditingModes,
state.editorMode,
getSectionRootClientId( state ),
];
}
export const getInsertBlockTypeDependants =
( select ) => ( state, rootClientId ) => {
return [
state.blockListSettings[ rootClientId ],
state.blocks.byClientId.get( rootClientId ),
state.settings.allowedBlockTypes,
state.settings.templateLock,
state.blockEditingModes,
select( STORE_NAME ).__unstableGetEditorMode( state ),
getSectionRootClientId( state ),
];
};
1 change: 1 addition & 0 deletions packages/block-library/src/details/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"supports": {
"__experimentalOnEnter": true,
"align": [ "wide", "full" ],
"anchor": true,
"color": {
"gradients": true,
"link": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function ContentOnlyControls( {
setIsAltDialogOpen( true );
onClose();
} }
aria-haspopup="dialog"
>
{ _x(
'Alternative text',
Expand All @@ -146,6 +147,7 @@ function ContentOnlyControls( {
setIsTitleDialogOpen( true );
onClose();
} }
aria-haspopup="dialog"
>
{ __( 'Title text' ) }
</MenuItem>
Expand Down
47 changes: 32 additions & 15 deletions packages/blocks/src/store/process-block-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,32 @@ function stabilizeSupports( rawSupports ) {
return rawSupports;
}

const supports = { ...rawSupports };
if ( supports?.typography && typeof supports.typography === 'object' ) {
supports.typography = Object.fromEntries(
Object.entries( supports.typography ).map( ( [ key, value ] ) => [
TYPOGRAPHY_SUPPORTS_EXPERIMENTAL_TO_STABLE[ key ] || key,
value,
] )
);
// Create a new object to avoid mutating the original. This ensures that
// custom block plugins that rely on immutable supports are not affected.
// See: https://github.com/WordPress/gutenberg/pull/66849#issuecomment-2463614281
const newSupports = {};
for ( const [ key, value ] of Object.entries( rawSupports ) ) {
if (
key === 'typography' &&
typeof value === 'object' &&
value !== null
) {
newSupports.typography = Object.fromEntries(
Object.entries( value ).map(
( [ typographyKey, typographyValue ] ) => [
TYPOGRAPHY_SUPPORTS_EXPERIMENTAL_TO_STABLE[
typographyKey
] || typographyKey,
typographyValue,
]
)
);
} else {
newSupports[ key ] = value;
}
}

return supports;
return newSupports;
}

/**
Expand Down Expand Up @@ -150,10 +165,12 @@ export const processBlockType =
if ( settings.deprecated ) {
settings.deprecated = settings.deprecated.map( ( deprecation ) => {
// Stabilize any experimental supports before applying filters.
deprecation.supports = stabilizeSupports(
deprecation.supports
);
const filteredDeprecation = // Only keep valid deprecation keys.
let filteredDeprecation = {
...deprecation,
supports: stabilizeSupports( deprecation.supports ),
};

filteredDeprecation = // Only keep valid deprecation keys.
applyFilters(
'blocks.registerBlockType',
// Merge deprecation keys with pre-filter settings
Expand All @@ -163,10 +180,10 @@ export const processBlockType =
// Omit deprecation keys here so that deprecations
// can opt out of specific keys like "supports".
...omit( blockType, DEPRECATED_ENTRY_KEYS ),
...deprecation,
...filteredDeprecation,
},
blockType.name,
deprecation
filteredDeprecation
);
// Re-stabilize any experimental supports after applying filters.
// This ensures that any supports updated by filters are also stabilized.
Expand Down
6 changes: 6 additions & 0 deletions packages/blocks/src/store/test/process-block-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ describe( 'processBlockType', () => {
],
};

// Freeze the deprecated block object and its supports so that the original is not mutated.
// This ensures the test covers a regression where the original object was mutated.
// See: https://github.com/WordPress/gutenberg/pull/63401#discussion_r1832394335.
Object.freeze( blockSettings.deprecated[ 0 ] );
Object.freeze( blockSettings.deprecated[ 0 ].supports );

const processedBlockType = processBlockType(
'test/block',
blockSettings
Expand Down
8 changes: 5 additions & 3 deletions packages/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ For example, when a user types "contact", the Command Palette needs to filter th

Static and dynamic commands can be contextual. This means that in a given context (for example, when navigating the Site Editor or editing a template), some specific commands are given more priority and are visible as soon as you open the Command Palette. Also, when typing the Command Palette, these contextual commands are shown above the rest of the commands.

At the moment, two contexts have been implemented:
At the moment, three contexts have been implemented:

- `site-editor`: This is the context that is set when you are navigating in the site editor (sidebar visible).
- `site-editor-edit`: This is the context that is set when you are editing a document (template, template part or page) in the site editor.
As the usage of the Command Palette expands, more contexts will be added.
- `entity-edit`: This is the context that is set when you are editing a document (template, template part or page).
- `block-selection-edit`: This is the context that is set when a block is selected.

As the usage of the Command Palette expands, more contexts will be added.

Attaching a command or command loader to a given context is as simple as adding the `context` property (with the right context value from the available contexts above) to the `useCommand` or `useCommandLoader` calls.

Expand Down
2 changes: 1 addition & 1 deletion packages/core-commands/src/admin-navigation-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function useAdminNavigationCommands() {
label: __( 'Add new post' ),
icon: plus,
callback: () => {
document.location.href = 'post-new.php';
document.location.assign( 'post-new.php' );
},
} );

Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/components/editor-interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export default function EditorInterface( {
customSaveButton={ customSaveButton }
forceDisableBlockTools={ forceDisableBlockTools }
title={ title }
isEditorIframed={ ! disableIframe }
/>
)
}
Expand Down
Loading

0 comments on commit 2c70121

Please sign in to comment.