Skip to content

Commit

Permalink
Merge branch 'WordPress:trunk' into fix/datepicket-day-labels-uk-dts-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksVeter authored Dec 2, 2024
2 parents 1a174b6 + 6561108 commit ee6229b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {

if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) {
$tag_processor = new WP_HTML_Tag_Processor( $html );
while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item__content' ) ) ) {
while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item' ) ) ) {
$tag_processor->add_class( 'current-menu-ancestor' );
}
$html = $tag_processor->get_updated_html();
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Upgraded `@ariakit/react` (v0.4.13) and `@ariakit/test` (v0.4.5) ([#65907](https://github.com/WordPress/gutenberg/pull/65907)).
- Upgraded `@ariakit/react` (v0.4.15) and `@ariakit/test` (v0.4.7) ([#67404](https://github.com/WordPress/gutenberg/pull/67404)).
- Exported the `WPCompleter` type as it was being used in block-editor/autocompleters ([#67410](https://github.com/WordPress/gutenberg/pull/67410)).
- `SlotFill`: remove manual rerenders from the portal `Fill` component ([#67471](https://github.com/WordPress/gutenberg/pull/67471)).

### Bug Fixes

Expand Down
18 changes: 7 additions & 11 deletions packages/components/src/slot-fill/bubbles-virtually/fill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { useObservableValue } from '@wordpress/compose';
import {
useContext,
useReducer,
useRef,
useEffect,
createPortal,
Expand All @@ -20,18 +19,15 @@ import type { FillComponentProps } from '../types';
export default function Fill( { name, children }: FillComponentProps ) {
const registry = useContext( SlotFillContext );
const slot = useObservableValue( registry.slots, name );
const [ , rerender ] = useReducer( () => [], [] );
const ref = useRef( { rerender } );
const instanceRef = useRef( {} );

// We register fills so we can keep track of their existence.
// Slots can use the `useSlotFills` hook to know if there're already fills
// registered so they can choose to render themselves or not.
useEffect( () => {
// We register fills so we can keep track of their existence.
// Some Slot implementations need to know if there're already fills
// registered so they can choose to render themselves or not.
const refValue = ref.current;
registry.registerFill( name, refValue );
return () => {
registry.unregisterFill( name, refValue );
};
const instance = instanceRef.current;
registry.registerFill( name, instance );
return () => registry.unregisterFill( name, instance );
}, [ registry, name ] );

if ( ! slot || ! slot.ref.current ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ function createSlotRegistry(): SlotFillBubblesVirtuallyContext {
ref,
fillProps
) => {
const slot = slots.get( name );

slots.set( name, {
...slot,
ref: ref || slot?.ref,
fillProps: fillProps || slot?.fillProps || {},
} );
slots.set( name, { ref, fillProps } );
};

const unregisterSlot: SlotFillBubblesVirtuallyContext[ 'unregisterSlot' ] =
Expand Down Expand Up @@ -66,12 +60,7 @@ function createSlotRegistry(): SlotFillBubblesVirtuallyContext {
return;
}

slot.fillProps = fillProps;
const slotFills = fills.get( name );
if ( slotFills ) {
// Force update fills.
slotFills.forEach( ( fill ) => fill.rerender() );
}
slots.set( name, { ref, fillProps } );
};

const registerFill: SlotFillBubblesVirtuallyContext[ 'registerFill' ] = (
Expand Down
11 changes: 4 additions & 7 deletions packages/components/src/slot-fill/bubbles-virtually/slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ function Slot(
...restProps
} = props;

const { registerSlot, unregisterSlot, ...registry } =
useContext( SlotFillContext );
const registry = useContext( SlotFillContext );

const ref = useRef< HTMLElement >( null );

Expand All @@ -54,11 +53,9 @@ function Slot(
}, [ fillProps ] );

useLayoutEffect( () => {
registerSlot( name, ref, fillPropsRef.current );
return () => {
unregisterSlot( name, ref );
};
}, [ registerSlot, unregisterSlot, name ] );
registry.registerSlot( name, ref, fillPropsRef.current );
return () => registry.unregisterSlot( name, ref );
}, [ registry, name ] );

useLayoutEffect( () => {
registry.updateSlot( name, ref, fillPropsRef.current );
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/slot-fill/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ export type SlotFillProviderProps = {

export type SlotRef = RefObject< HTMLElement >;
export type Rerenderable = { rerender: () => void };
export type FillInstance = {};

export type SlotFillBubblesVirtuallyContext = {
slots: ObservableMap< SlotKey, { ref: SlotRef; fillProps: FillProps } >;
fills: ObservableMap< SlotKey, Rerenderable[] >;
fills: ObservableMap< SlotKey, FillInstance[] >;
registerSlot: ( name: SlotKey, ref: SlotRef, fillProps: FillProps ) => void;
unregisterSlot: ( name: SlotKey, ref: SlotRef ) => void;
updateSlot: ( name: SlotKey, ref: SlotRef, fillProps: FillProps ) => void;
registerFill: ( name: SlotKey, ref: Rerenderable ) => void;
unregisterFill: ( name: SlotKey, ref: Rerenderable ) => void;
registerFill: ( name: SlotKey, instance: FillInstance ) => void;
unregisterFill: ( name: SlotKey, instance: FillInstance ) => void;

/**
* This helps the provider know if it's using the default context value or not.
Expand Down
12 changes: 9 additions & 3 deletions packages/edit-site/src/components/save-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const { EntitiesSavedStatesExtensible, NavigableRegion } =
unlock( privateApis );
const { useLocation } = unlock( routerPrivateApis );

const EntitiesSavedStatesForPreview = ( { onClose } ) => {
const EntitiesSavedStatesForPreview = ( { onClose, renderDialog } ) => {
const isDirtyProps = useEntitiesSavedStatesIsDirty();
let activateSaveLabel;
if ( isDirtyProps.isDirty ) {
Expand Down Expand Up @@ -75,14 +75,20 @@ const EntitiesSavedStatesForPreview = ( { onClose } ) => {
onSave,
saveEnabled: true,
saveLabel: activateSaveLabel,
renderDialog,
} }
/>
);
};

const _EntitiesSavedStates = ( { onClose, renderDialog = undefined } ) => {
const _EntitiesSavedStates = ( { onClose, renderDialog } ) => {
if ( isPreviewingTheme() ) {
return <EntitiesSavedStatesForPreview onClose={ onClose } />;
return (
<EntitiesSavedStatesForPreview
onClose={ onClose }
renderDialog={ renderDialog }
/>
);
}
return (
<EntitiesSavedStates close={ onClose } renderDialog={ renderDialog } />
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ _Parameters_

- _props_ `Object`: The component props.
- _props.close_ `Function`: The function to close the dialog.
- _props.renderDialog_ `Function`: The function to render the dialog.
- _props.renderDialog_ `boolean`: Whether to render the component with modal dialog behavior.

_Returns_

Expand Down
15 changes: 6 additions & 9 deletions packages/editor/src/components/entities-saved-states/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ function identity( values ) {
*
* @param {Object} props The component props.
* @param {Function} props.close The function to close the dialog.
* @param {Function} props.renderDialog The function to render the dialog.
* @param {boolean} props.renderDialog Whether to render the component with modal dialog behavior.
*
* @return {React.ReactNode} The rendered component.
*/
export default function EntitiesSavedStates( {
close,
renderDialog = undefined,
} ) {
export default function EntitiesSavedStates( { close, renderDialog } ) {
const isDirtyProps = useIsDirty();
return (
<EntitiesSavedStatesExtensible
Expand All @@ -58,7 +55,7 @@ export default function EntitiesSavedStates( {
* @param {Function} props.onSave Function to call when saving entities.
* @param {boolean} props.saveEnabled Flag indicating if save is enabled.
* @param {string} props.saveLabel Label for the save button.
* @param {Function} props.renderDialog Function to render a custom dialog.
* @param {boolean} props.renderDialog Whether to render the component with modal dialog behavior.
* @param {Array} props.dirtyEntityRecords Array of dirty entity records.
* @param {boolean} props.isDirty Flag indicating if there are dirty entities.
* @param {Function} props.setUnselectedEntities Function to set unselected entities.
Expand All @@ -72,7 +69,7 @@ export function EntitiesSavedStatesExtensible( {
onSave = identity,
saveEnabled: saveEnabledProp = undefined,
saveLabel = __( 'Save' ),
renderDialog = undefined,
renderDialog,
dirtyEntityRecords,
isDirty,
setUnselectedEntities,
Expand Down Expand Up @@ -120,8 +117,8 @@ export function EntitiesSavedStatesExtensible( {

return (
<div
ref={ saveDialogRef }
{ ...saveDialogProps }
ref={ renderDialog ? saveDialogRef : undefined }
{ ...( renderDialog && saveDialogProps ) }
className="entities-saved-states__panel"
role={ renderDialog ? 'dialog' : undefined }
aria-labelledby={ renderDialog ? dialogLabel : undefined }
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class PostPublishButton extends Component {
isBusy: ! isAutoSaving && isSaving,
variant: 'primary',
onClick: this.createOnClick( onClickButton ),
'aria-haspopup': hasNonPostEntityChanges ? 'dialog' : undefined,
};

const toggleProps = {
Expand All @@ -161,6 +162,7 @@ export class PostPublishButton extends Component {
variant: 'primary',
size: 'compact',
onClick: this.createOnClick( onClickToggle ),
'aria-haspopup': hasNonPostEntityChanges ? 'dialog' : undefined,
};
const componentProps = isToggle ? toggleProps : buttonProps;
return (
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/components/save-publish-panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function SavePublishPanels( {
variant="secondary"
onClick={ openEntitiesSavedStates }
aria-expanded={ false }
aria-haspopup="dialog"
disabled={ ! isDirty }
accessibleWhenDisabled
>
Expand All @@ -102,7 +103,10 @@ export default function SavePublishPanels( {
return (
<>
{ isEntitiesSavedStatesOpen && (
<EntitiesSavedStates close={ closeEntitiesSavedStates } />
<EntitiesSavedStates
close={ closeEntitiesSavedStates }
renderDialog
/>
) }
<Slot bubblesVirtually />
{ ! isEntitiesSavedStatesOpen && unmountableContent }
Expand Down

0 comments on commit ee6229b

Please sign in to comment.