Skip to content

Commit

Permalink
Components: remove createPrivateSlotFill function
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Nov 22, 2024
1 parent b4c614f commit 2b37d65
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 43 deletions.
8 changes: 5 additions & 3 deletions packages/block-editor/src/components/block-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export default function BlockControlsSlot( { group = 'default', ...props } ) {
[ toolbarState, contextState ]
);

const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot ) {
const slotFill = groups[ group ];
const fills = useSlotFills( slotFill.name );

if ( ! slotFill ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}
Expand All @@ -42,6 +43,7 @@ export default function BlockControlsSlot( { group = 'default', ...props } ) {
return null;
}

const { Slot } = slotFill;
const slot = <Slot { ...props } bubblesVirtually fillProps={ fillProps } />;

if ( group === 'default' ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/**
* WordPress dependencies
*/
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import {
useBlockEditContext,
mayDisplayControlsKey,
} from '../block-edit/context';

const { createPrivateSlotFill } = unlock( componentsPrivateApis );
const { Fill, Slot } = createPrivateSlotFill( 'BlockInformation' );
const { Fill, Slot } = createSlotFill( Symbol( 'BlockInformation' ) );

const BlockInfo = ( props ) => {
const context = useBlockEditContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ const PositionControlsPanel = () => {
};

const PositionControls = () => {
const fills = useSlotFills(
InspectorControlsGroups.position.Slot.__unstableName
);
const fills = useSlotFills( InspectorControlsGroups.position.name );
const hasFills = Boolean( fills && fills.length );

if ( ! hasFills ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ export default function useInspectorControlsTabs( blockName ) {

// List View Tab: If there are any fills for the list group add that tab.
const listViewDisabled = useIsListViewTabDisabled( blockName );
const listFills = useSlotFills( listGroup.Slot.__unstableName );
const listFills = useSlotFills( listGroup.name );
const hasListFills = ! listViewDisabled && !! listFills && listFills.length;

// Styles Tab: Add this tab if there are any fills for block supports
// e.g. border, color, spacing, typography, etc.
const styleFills = [
...( useSlotFills( borderGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( colorGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( dimensionsGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( stylesGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( typographyGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( effectsGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( borderGroup.name ) || [] ),
...( useSlotFills( colorGroup.name ) || [] ),
...( useSlotFills( dimensionsGroup.name ) || [] ),
...( useSlotFills( stylesGroup.name ) || [] ),
...( useSlotFills( typographyGroup.name ) || [] ),
...( useSlotFills( effectsGroup.name ) || [] ),
];
const hasStyleFills = styleFills.length;

Expand All @@ -67,12 +67,12 @@ export default function useInspectorControlsTabs( blockName ) {
// the advanced controls slot as well to ensure they are rendered.
const advancedFills = [
...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),
...( useSlotFills( bindingsGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( bindingsGroup.name ) || [] ),
];

const settingsFills = [
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( defaultGroup.name ) || [] ),
...( useSlotFills( positionGroup.name ) || [] ),
...( hasListFills && hasStyleFills > 1 ? advancedFills : [] ),
];

Expand Down
10 changes: 6 additions & 4 deletions packages/block-editor/src/components/inspector-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export default function InspectorControlsSlot( {
);
group = __experimentalGroup;
}
const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
const slotFill = groups[ group ];
const fills = useSlotFills( slotFill?.name );

const motionContextValue = useContext( MotionContext );

const computedFillProps = useMemo(
() => ( {
...( fillProps ?? {} ),
...fillProps,
forwardedContext: [
...( fillProps?.forwardedContext ?? [] ),
[ MotionContext.Provider, { value: motionContextValue } ],
Expand All @@ -50,7 +50,7 @@ export default function InspectorControlsSlot( {
[ motionContextValue, fillProps ]
);

if ( ! Slot ) {
if ( ! slotFill ) {
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
Expand All @@ -59,6 +59,8 @@ export default function InspectorControlsSlot( {
return null;
}

const { Slot } = slotFill;

if ( label ) {
return (
<BlockSupportToolsPanel group={ group } label={ label }>
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Internal dependencies
*/
import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';
import { createPrivateSlotFill } from './slot-fill';
import { Menu } from './menu';
import { ComponentsContext } from './context/context-system-provider';
import Theme from './theme';
Expand All @@ -13,7 +12,6 @@ import { lock } from './lock-unlock';
export const privateApis = {};
lock( privateApis, {
__experimentalPopoverLegacyPositionToPlacement,
createPrivateSlotFill,
ComponentsContext,
Tabs,
Theme,
Expand Down
9 changes: 2 additions & 7 deletions packages/components/src/slot-fill/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ export function createSlotFill( key: SlotKey ) {
props: DistributiveOmit< SlotComponentProps, 'name' >
) => <Slot name={ key } { ...props } />;
SlotComponent.displayName = `${ baseName }Slot`;
// deprecated legacy property, should use `slotFill.name` instead of `slotFill.Slot.__unstableName`
SlotComponent.__unstableName = key;

return {
name: key,
Fill: FillComponent,
Slot: SlotComponent,
};
}

export const createPrivateSlotFill = ( name: string ) => {
const privateKey = Symbol( name );
const privateSlotFill = createSlotFill( privateKey );

return { privateKey, ...privateSlotFill };
};
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function EditorCanvasContainer( {
}

function useHasEditorCanvasContainer() {
const fills = useSlotFills( EditorContentSlotFill.privateKey );
const fills = useSlotFills( EditorContentSlotFill.name );
return !! fills?.length;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/**
* WordPress dependencies
*/
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';

const { createPrivateSlotFill } = unlock( componentsPrivateApis );
const SLOT_FILL_NAME = 'EditCanvasContainerSlot';
const EditorContentSlotFill = createPrivateSlotFill( SLOT_FILL_NAME );
const EditorContentSlotFill = createSlotFill(
Symbol( 'EditCanvasContainerSlot' )
);

export default EditorContentSlotFill;

0 comments on commit 2b37d65

Please sign in to comment.