Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:amitraj2203/gutenberg into fix/iss…
Browse files Browse the repository at this point in the history
…ue-62040
  • Loading branch information
amitraj2203 committed May 30, 2024
2 parents 04b466e + a96a728 commit 7cb9e9d
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 114 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import InserterMenu from './menu';
import { PrivateInserterMenu } from './menu';
import { store as blockEditorStore } from '../../store';

const noop = () => {};
Expand All @@ -23,7 +23,7 @@ function InserterLibrary(
__experimentalInitialTab,
__experimentalInitialCategory,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
onPatternCategorySelection,
onSelect = noop,
shouldFocusBlock = false,
onClose,
Expand All @@ -43,7 +43,7 @@ function InserterLibrary(
);

return (
<InserterMenu
<PrivateInserterMenu
onSelect={ onSelect }
rootClientId={ destinationRootClientId }
clientId={ clientId }
Expand All @@ -52,9 +52,7 @@ function InserterLibrary(
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
__experimentalFilterValue={ __experimentalFilterValue }
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
onPatternCategorySelection={ onPatternCategorySelection }
__experimentalInitialTab={ __experimentalInitialTab }
__experimentalInitialCategory={ __experimentalInitialCategory }
shouldFocusBlock={ shouldFocusBlock }
Expand All @@ -64,4 +62,16 @@ function InserterLibrary(
);
}

export default forwardRef( InserterLibrary );
export const PrivateInserterLibrary = forwardRef( InserterLibrary );

function PublicInserterLibrary( props, ref ) {
return (
<PrivateInserterLibrary
{ ...props }
onPatternCategorySelection={ undefined }
ref={ ref }
/>
);
}

export default forwardRef( PublicInserterLibrary );
20 changes: 16 additions & 4 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function InserterMenu(
showMostUsedBlocks,
__experimentalFilterValue = '',
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
onPatternCategorySelection,
onClose,
__experimentalInitialTab,
__experimentalInitialCategory,
Expand Down Expand Up @@ -128,9 +128,9 @@ function InserterMenu(
( patternCategory, filter ) => {
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
__experimentalOnPatternCategorySelection();
onPatternCategorySelection?.();
},
[ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ]
[ setSelectedPatternCategory, onPatternCategorySelection ]
);

const showPatternPanel =
Expand Down Expand Up @@ -341,4 +341,16 @@ function InserterMenu(
);
}

export default forwardRef( InserterMenu );
export const PrivateInserterMenu = forwardRef( InserterMenu );

function PublicInserterMenu( props, ref ) {
return (
<PrivateInserterMenu
{ ...props }
onPatternCategorySelection={ NOOP }
ref={ ref }
/>
);
}

export default forwardRef( PublicInserterMenu );
2 changes: 2 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { requiresWrapperOnCopy } from './components/writing-flow/utils';
import { PrivateRichText } from './components/rich-text/';
import { PrivateBlockPopover } from './components/block-popover';
import { PrivateInserterLibrary } from './components/inserter/library';

/**
* Private @wordpress/block-editor APIs.
Expand Down Expand Up @@ -78,6 +79,7 @@ lock( privateApis, {
selectBlockPatternsKey,
requiresWrapperOnCopy,
PrivateRichText,
PrivateInserterLibrary,
reusableBlocksSelectKey,
PrivateBlockPopover,
} );
1 change: 0 additions & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@wordpress/autop": "file:../autop",
"@wordpress/blob": "file:../blob",
"@wordpress/block-serialization-default-parser": "file:../block-serialization-default-parser",
"@wordpress/compose": "file:../compose",
"@wordpress/data": "file:../data",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/dom": "file:../dom",
Expand Down
35 changes: 8 additions & 27 deletions packages/blocks/src/api/parser/get-block-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import memoize from 'memize';
/**
* WordPress dependencies
*/
import { pipe } from '@wordpress/compose';
import { applyFilters } from '@wordpress/hooks';
import { RichTextData } from '@wordpress/rich-text';

Expand Down Expand Up @@ -37,24 +36,8 @@ import { normalizeBlockType, getDefault } from '../utils';
*
* @return {Function} Enhanced hpq matcher.
*/
export const toBooleanAttributeMatcher = ( matcher ) =>
pipe( [
matcher,
// Expected values from `attr( 'disabled' )`:
//
// <input>
// - Value: `undefined`
// - Transformed: `false`
//
// <input disabled>
// - Value: `''`
// - Transformed: `true`
//
// <input disabled="disabled">
// - Value: `'disabled'`
// - Transformed: `true`
( value ) => value !== undefined,
] );
export const toBooleanAttributeMatcher = ( matcher ) => ( value ) =>
matcher( value ) !== undefined;

/**
* Returns true if value is of the given JSON schema type, or false otherwise.
Expand Down Expand Up @@ -214,13 +197,13 @@ export function isValidByEnum( value, enumSet ) {
*/
export const matcherFromSource = memoize( ( sourceConfig ) => {
switch ( sourceConfig.source ) {
case 'attribute':
case 'attribute': {
let matcher = attr( sourceConfig.selector, sourceConfig.attribute );
if ( sourceConfig.type === 'boolean' ) {
matcher = toBooleanAttributeMatcher( matcher );
}

return matcher;
}
case 'html':
return html( sourceConfig.selector, sourceConfig.multiline );
case 'text':
Expand All @@ -244,12 +227,10 @@ export const matcherFromSource = memoize( ( sourceConfig ) => {
)
);
return query( sourceConfig.selector, subMatchers );
case 'tag':
return pipe( [
prop( sourceConfig.selector, 'nodeName' ),
( nodeName ) =>
nodeName ? nodeName.toLowerCase() : undefined,
] );
case 'tag': {
const matcher = prop( sourceConfig.selector, 'nodeName' );
return ( domNode ) => matcher( domNode )?.toLowerCase();
}
default:
// eslint-disable-next-line no-console
console.error( `Unknown source type "${ sourceConfig.source }"` );
Expand Down
37 changes: 15 additions & 22 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import removeAccents from 'remove-accents';
/**
* WordPress dependencies
*/
import { pipe } from '@wordpress/compose';
import { createSelector } from '@wordpress/data';

/**
Expand Down Expand Up @@ -645,6 +644,18 @@ export function hasBlockSupport( state, nameOrType, feature, defaultSupports ) {
return !! getBlockSupport( state, nameOrType, feature, defaultSupports );
}

/**
* Normalizes a search term string: removes accents, converts to lowercase, removes extra whitespace.
*
* @param {string|null|undefined} term Search term to normalize.
* @return {string} Normalized search term.
*/
function getNormalizedSearchTerm( term ) {
return removeAccents( term ?? '' )
.toLowerCase()
.trim();
}

/**
* Returns true if the block type by the given name or object value matches a
* search term, or false otherwise.
Expand Down Expand Up @@ -684,30 +695,12 @@ export function hasBlockSupport( state, nameOrType, feature, defaultSupports ) {
*
* @return {Object[]} Whether block type matches search term.
*/
export function isMatchingSearchTerm( state, nameOrType, searchTerm ) {
export function isMatchingSearchTerm( state, nameOrType, searchTerm = '' ) {
const blockType = getNormalizedBlockType( state, nameOrType );

const getNormalizedSearchTerm = pipe( [
// Disregard diacritics.
// Input: "média"
( term ) => removeAccents( term ?? '' ),

// Lowercase.
// Input: "MEDIA"
( term ) => term.toLowerCase(),

// Strip leading and trailing whitespace.
// Input: " media "
( term ) => term.trim(),
] );

const normalizedSearchTerm = getNormalizedSearchTerm( searchTerm );

const isSearchMatch = pipe( [
getNormalizedSearchTerm,
( normalizedCandidate ) =>
normalizedCandidate.includes( normalizedSearchTerm ),
] );
const isSearchMatch = ( candidate ) =>
getNormalizedSearchTerm( candidate ).includes( normalizedSearchTerm );

return (
isSearchMatch( blockType.title ) ||
Expand Down
7 changes: 6 additions & 1 deletion packages/dataviews/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
th:first-child {
padding-left: $grid-unit-60;

.dataviews-view-table-header-button {
.dataviews-view-table-header-button,
.dataviews-view-table-header {
margin-left: - #{$grid-unit-10};
}
}
Expand Down Expand Up @@ -235,6 +236,10 @@
}
}

.dataviews-view-table-header {
padding-left: $grid-unit-05;
}

.dataviews-view-table__actions-column {
width: 1%;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/dataviews/src/view-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
privateApis as componentsPrivateApis,
CheckboxControl,
Spinner,
VisuallyHidden,
} from '@wordpress/components';
import {
forwardRef,
Expand Down Expand Up @@ -549,9 +548,9 @@ function ViewTable< Item extends AnyItem >( {
data-field-id="actions"
className="dataviews-view-table__actions-column"
>
<VisuallyHidden>
<span className="dataviews-view-table-header">
{ __( 'Actions' ) }
</VisuallyHidden>
</span>
</th>
) }
</tr>
Expand Down
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export default function AddNewPattern() {
<DropdownMenu
controls={ controls }
icon={ null }
toggleProps={ { variant: 'primary', showTooltip: false } }
toggleProps={ {
variant: 'primary',
showTooltip: false,
__next40pxDefaultSize: true,
} }
text={ addNewPatternLabel }
label={ addNewPatternLabel }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ function NewTemplate() {
variant="primary"
onClick={ () => setShowModal( true ) }
label={ postType.labels.add_new_item }
__next40pxDefaultSize
>
{ postType.labels.add_new_item }
</Button>
Expand Down
19 changes: 6 additions & 13 deletions packages/edit-site/src/components/global-styles/font-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
__experimentalVStack as VStack,
__experimentalHStack as HStack,
Button,
Tooltip,
} from '@wordpress/components';
import { settings } from '@wordpress/icons';
import { useContext } from '@wordpress/element';
Expand Down Expand Up @@ -40,18 +39,12 @@ function FontFamilies() {
<VStack spacing={ 2 }>
<HStack justify="space-between">
<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>
<HStack justify="flex-end">
<Tooltip text={ __( 'Manage fonts' ) }>
<Button
onClick={ () =>
toggleModal( 'installed-fonts' )
}
aria-label={ __( 'Manage fonts' ) }
icon={ settings }
size="small"
/>
</Tooltip>
</HStack>
<Button
onClick={ () => toggleModal( 'installed-fonts' ) }
label={ __( 'Manage fonts' ) }
icon={ settings }
size="small"
/>
</HStack>
{ hasFonts ? (
<ItemGroup isBordered isSeparated>
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function useLayoutAreas() {
areas: {
sidebar: (
<SidebarNavigationScreen
title={ __( 'Manage pages' ) }
title={ __( 'Pages' ) }
backPath={ {} }
content={ <DataViewsSidebarContent /> }
/>
Expand Down
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,11 @@ export default function PagePages() {
actions={
addNewLabel && (
<>
<Button variant="primary" onClick={ openModal }>
<Button
variant="primary"
onClick={ openModal }
__next40pxDefaultSize
>
{ addNewLabel }
</Button>
{ showAddPageModal && (
Expand Down
Loading

0 comments on commit 7cb9e9d

Please sign in to comment.