Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:karthick-murugan/gutenberg into fe…
Browse files Browse the repository at this point in the history
…ature/block-comments-scroll
  • Loading branch information
karthick-murugan committed Nov 28, 2024
2 parents 07c85f6 + 2f6ef27 commit a7693d4
Show file tree
Hide file tree
Showing 43 changed files with 2,603 additions and 596 deletions.
291 changes: 291 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { AlignmentToolbar } from '..';

/**
* The `AlignmentToolbar` component renders a dropdown menu that displays alignment options for the selected block in `Toolbar`.
*/
const meta = {
title: 'BlockEditor/AlignmentToolbar',
component: AlignmentToolbar,
argTypes: {
value: {
control: { type: null },
defaultValue: 'undefined',
description: 'The current value of the alignment setting.',
},
onChange: {
action: 'onChange',
control: { type: null },
description:
"A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie: `left`, `center`, `right`, `undefined`) as the only argument.",
},
},
};
export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();
return (
<AlignmentToolbar
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
value={ value }
/>
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { AlignmentControl } from '../';

/**
* The `AlignmentControl` component renders a dropdown menu that displays alignment options for the selected block.
*
* This component is mostly used for blocks that display text, such as Heading, Paragraph, Post Author, Post Comments, Verse, Quote, Post Title, etc... And the available alignment options are `left`, `center` or `right` alignment.
*
* If you want to use the alignment control in a toolbar, you should use the `AlignmentToolbar` component instead.
*/
const meta = {
title: 'BlockEditor/AlignmentControl',
component: AlignmentControl,
argTypes: {
value: {
control: { type: null },
defaultValue: 'undefined',
description: 'The current value of the alignment setting.',
},
onChange: {
action: 'onChange',
control: { type: null },
description:
"A callback function invoked when the toolbar's alignment value is changed via an interaction with any of the toolbar's buttons. Called with the new alignment value (ie: `left`, `center`, `right`, `undefined`) as the only argument.",
},
},
};
export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();
return (
<AlignmentControl
{ ...args }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
value={ value }
/>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function BlockPattern( {
onHover,
showTitlesAsTooltip,
category,
isSelected,
} ) {
const [ isDragging, setIsDragging ] = useState( false );
const { blocks, viewportWidth } = pattern;
Expand Down Expand Up @@ -114,6 +115,7 @@ function BlockPattern( {
pattern.type ===
INSERTER_PATTERN_TYPES.user &&
! pattern.syncStatus,
'is-selected': isSelected,
}
) }
/>
Expand Down Expand Up @@ -192,6 +194,7 @@ function BlockPatternsList(
ref
) {
const [ activeCompositeId, setActiveCompositeId ] = useState( undefined );
const [ activePattern, setActivePattern ] = useState( null ); // State to track active pattern

useEffect( () => {
// Reset the active composite item whenever the available patterns change,
Expand All @@ -201,6 +204,11 @@ function BlockPatternsList(
setActiveCompositeId( firstCompositeItemId );
}, [ blockPatterns ] );

const handleClickPattern = ( pattern, blocks ) => {
setActivePattern( pattern.name );
onClickPattern( pattern, blocks );
};

return (
<Composite
orientation={ orientation }
Expand All @@ -216,11 +224,14 @@ function BlockPatternsList(
key={ pattern.name }
id={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
onClick={ handleClickPattern }
onHover={ onHover }
isDraggable={ isDraggable }
showTitlesAsTooltip={ showTitlesAsTooltip }
category={ category }
isSelected={
!! activePattern && activePattern === pattern.name
}
/>
) ) }
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,29 @@
outline: $border-width solid rgba($black, 0.1);
outline-offset: -$border-width;
border-radius: $radius-medium;

transition: outline 0.1s linear;
@include reduce-motion("transition");
}
}

&:hover:not(:focus) .block-editor-block-preview__container::after {
// Selected
&.is-selected .block-editor-block-preview__container::after {
outline-color: $gray-900;
outline-width: var(--wp-admin-border-width-focus);
outline-offset: calc(-1 * var(--wp-admin-border-width-focus));
}

// Hover state
&:hover .block-editor-block-preview__container::after {
outline-color: rgba($black, 0.3);
}

&:focus .block-editor-block-preview__container::after {
// Focused state
&[data-focus-visible] .block-editor-block-preview__container::after {
outline-color: var(--wp-admin-theme-color);
outline-width: var(--wp-admin-border-width-focus);
outline-offset: calc((-1 * var(--wp-admin-border-width-focus)));
transition: outline 0.1s linear;
@include reduce-motion("transition");
outline-offset: calc(-1 * var(--wp-admin-border-width-focus));
}

.block-editor-patterns__pattern-details:not(:empty) {
Expand All @@ -68,6 +78,7 @@
.block-editor-patterns__pattern-icon-wrapper {
min-width: 24px;
height: 24px;

.block-editor-patterns__pattern-icon {
fill: var(--wp-block-synced-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => {
const convertToGroupButtonProps =
useConvertToGroupButtonProps( selectedClientIds );
const { isGroupable, isUngroupable } = convertToGroupButtonProps;
const showConvertToGroupButton = isGroupable || isUngroupable;
const showConvertToGroupButton =
( isGroupable || isUngroupable ) && ! isContentOnly;

return (
<Slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export function BlockSettingsDropdown( {
const currentClientId = block?.clientId;
const count = clientIds.length;
const firstBlockClientId = clientIds[ 0 ];

const {
firstParentClientId,
parentBlockType,
previousBlockClientId,
selectedBlockClientIds,
openedBlockSettingsMenu,
isContentOnly,
isZoomOut,
} = useSelect(
( select ) => {
const {
Expand All @@ -74,6 +76,7 @@ export function BlockSettingsDropdown( {
getBlockAttributes,
getOpenedBlockSettingsMenu,
getBlockEditingMode,
isZoomOut: _isZoomOut,
} = unlock( select( blockEditorStore ) );

const { getActiveBlockVariation } = select( blocksStore );
Expand All @@ -98,10 +101,12 @@ export function BlockSettingsDropdown( {
openedBlockSettingsMenu: getOpenedBlockSettingsMenu(),
isContentOnly:
getBlockEditingMode( firstBlockClientId ) === 'contentOnly',
isZoomOut: _isZoomOut(),
};
},
[ firstBlockClientId ]
);

const { getBlockOrder, getSelectedBlockClientIds } =
useSelect( blockEditorStore );

Expand Down Expand Up @@ -248,7 +253,7 @@ export function BlockSettingsDropdown( {
clientId={ firstBlockClientId }
/>
) }
{ ! isContentOnly && (
{ ( ! isContentOnly || isZoomOut ) && (
<CopyMenuItem
clientIds={ clientIds }
onCopy={ onCopy }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const blockLabelMap = {
};

jest.mock( '@wordpress/blocks', () => {
const actualImplementation = jest.requireActual( '@wordpress/blocks' );
return {
...actualImplementation,
isReusableBlock( { title } ) {
return title === 'Reusable Block';
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
* WordPress dependencies
*/
import { Draggable } from '@wordpress/components';
import {
createBlock,
serialize,
store as blocksStore,
} from '@wordpress/blocks';
import { createBlock, store as blocksStore } from '@wordpress/blocks';
import { useDispatch, useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -24,20 +21,6 @@ const InserterDraggableBlocks = ( {
children,
pattern,
} ) => {
const transferData = {
type: 'inserter',
blocks,
};

const blocksContainMedia =
blocks.filter(
( block ) =>
( block.name === 'core/image' ||
block.name === 'core/audio' ||
block.name === 'core/video' ) &&
( block.attributes.url || block.attributes.src )
).length > 0;

const blockTypeIcon = useSelect(
( select ) => {
const { getBlockType } = select( blocksStore );
Expand All @@ -52,6 +35,13 @@ const InserterDraggableBlocks = ( {
useDispatch( blockEditorStore )
);

const patternBlock = useMemo( () => {
return pattern?.type === INSERTER_PATTERN_TYPES.user &&
pattern?.syncStatus !== 'unsynced'
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
: undefined;
}, [ pattern?.type, pattern?.syncStatus, pattern?.id ] );

if ( ! isEnabled ) {
return children( {
draggable: false,
Expand All @@ -60,21 +50,21 @@ const InserterDraggableBlocks = ( {
} );
}

const draggableBlocks = patternBlock ?? blocks;
return (
<Draggable
__experimentalTransferDataType="wp-blocks"
transferData={ transferData }
transferData={ { type: 'inserter', blocks: draggableBlocks } }
onDragStart={ ( event ) => {
startDragging();
const parsedBlocks =
pattern?.type === INSERTER_PATTERN_TYPES.user &&
pattern?.syncStatus !== 'unsynced'
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
: blocks;
event.dataTransfer.setData(
blocksContainMedia ? 'default' : 'text/html',
serialize( parsedBlocks )
);
for ( const block of draggableBlocks ) {
const type = `wp-block:${ block.name }`;
// This will fill in the dataTransfer.types array so that
// the drop zone can check if the draggable is eligible.
// Unfortuantely, on drag start, we don't have access to the
// actual data, only the data keys/types.
event.dataTransfer.items.add( '', type );
}
} }
onDragEnd={ () => {
stopDragging();
Expand Down
Loading

0 comments on commit a7693d4

Please sign in to comment.