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-61931
  • Loading branch information
amitraj2203 committed May 29, 2024
2 parents c2a65ec + e8bec8d commit edc136b
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 31 deletions.
4 changes: 0 additions & 4 deletions package-lock.json

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

27 changes: 22 additions & 5 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,40 @@ export const BlockBindingsPanel = ( { metadata } ) => {
return null;
}

// Don't show the bindings connected to pattern overrides in the inspectors panel.
// TODO: Explore if this should be abstracted to let other sources decide.
const filteredBindings = { ...bindings };
Object.keys( filteredBindings ).forEach( ( key ) => {
if ( filteredBindings[ key ].source === 'core/pattern-overrides' ) {
delete filteredBindings[ key ];
}
} );

if ( Object.keys( filteredBindings ).length === 0 ) {
return null;
}

return (
<InspectorControls>
<PanelBody
title={ __( 'Bindings' ) }
className="components-panel__block-bindings-panel"
>
<ItemGroup isBordered isSeparated size="large">
{ Object.keys( bindings ).map( ( key ) => {
{ Object.keys( filteredBindings ).map( ( key ) => {
return (
<Item key={ key }>
<HStack>
<span>{ key }</span>
<span className="components-item__block-bindings-source">
{ sources[ bindings[ key ].source ]
? sources[ bindings[ key ].source ]
.label
: bindings[ key ].source }
{ sources[
filteredBindings[ key ].source
]
? sources[
filteredBindings[ key ]
.source
].label
: filteredBindings[ key ].source }
</span>
</HStack>
</Item>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ To find out more about contributing to this package or Gutenberg as a whole, ple
⚠️ Adding new blocks to this package **requires** additional steps!
1. Do not forget to register a new core block in the [`index.js`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/index.js) file of this package. For example, if you were to add the new core block called `core/blinking-paragraph`, you would have to add something like:
1. Do not forget to register a new core block in the [`index.js`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/index.js) file of this package. For example, if you were to add the new core block called `core/blinking-paragraph`, you would have to add something like:
```js
// packages/block-library/src/index.js
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/html/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
box-sizing: border-box;
max-height: 250px;
@include editor-input-reset();
// HTML input is always LTR regardless of language.
/*rtl:ignore*/
direction: ltr;
}
}
1 change: 0 additions & 1 deletion packages/edit-post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@wordpress/icons": "file:../icons",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/plugins": "file:../plugins",
"@wordpress/preferences": "file:../preferences",
Expand Down
13 changes: 0 additions & 13 deletions packages/edit-post/src/hooks/components/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/edit-post/src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* Internal dependencies
*/
import './components';
import './validate-multiple-use';
1 change: 0 additions & 1 deletion packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@wordpress/icons": "file:../icons",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/patterns": "file:../patterns",
"@wordpress/plugins": "file:../plugins",
Expand Down
10 changes: 8 additions & 2 deletions packages/edit-site/src/components/global-styles/shadows-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { unlock } from '../../lock-unlock';
import Subtitle from './subtitle';
import { NavigationButtonAsItem } from './navigation-button';
import ScreenHeader from './header';
import { getNewIndexFromPresets } from './utils';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );

Expand Down Expand Up @@ -81,10 +82,15 @@ export default function ShadowsPanel() {

function ShadowList( { label, shadows, category, canCreate, onCreate } ) {
const handleAddShadow = () => {
const newIndex = getNewIndexFromPresets( shadows, 'shadow-' );
onCreate( {
name: `Shadow ${ shadows.length + 1 }`,
name: sprintf(
/* translators: %s: is an index for a preset */
__( 'Shadow %s' ),
newIndex
),
shadow: defaultShadow,
slug: `shadow-${ shadows.length + 1 }`,
slug: `shadow-${ newIndex }`,
} );
};

Expand Down
59 changes: 59 additions & 0 deletions packages/edit-site/src/components/global-styles/test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Internal dependencies
*/
import { getNewIndexFromPresets } from '../utils';

const validPresets = {
single: [ { slug: 'preset-1' } ],
multiple: [ { slug: 'preset-1' }, { slug: 'preset-2' } ],
withGaps: [ { slug: 'preset-1' }, { slug: 'preset-3' } ],
mixedPrefixes: [
{ slug: 'preset-1' },
{ slug: 'shadow-2' },
{ slug: 'preset-3' },
],
nonStringSlug: [ { slug: 'preset-1' }, { slug: 2 } ],
emptyArray: [],
};

const invalidPresets = {
noMatch: [ { slug: 'preset-alpha' }, { slug: 'preset-beta' } ],
emptySlug: [ { slug: '' } ],
nullSlug: [ { slug: null } ],
undefinedSlug: [ { slug: undefined } ],
nonObjectElements: [ 'preset-1' ],
};

const getExpectedIndex = ( presetKey, presets ) => {
if ( presetKey === 'withGaps' ) {
return 4;
}
if ( presetKey === 'mixedPrefixes' ) {
return 4;
}
if ( presetKey === 'nonStringSlug' ) {
return 2;
}
return presets.length + 1;
};

describe( 'getNewIndexFromPresets', () => {
Object.entries( validPresets ).forEach( ( [ presetKey, presets ] ) => {
describe( `test valid preset format: ${ presetKey }`, () => {
const newIndex = getNewIndexFromPresets( presets, 'preset-' );
it( `should return correct new index for ${ presetKey }`, () => {
const expectedIndex = getExpectedIndex( presetKey, presets );
expect( newIndex ).toBe( expectedIndex );
} );
} );
} );

Object.entries( invalidPresets ).forEach( ( [ presetKey, presets ] ) => {
describe( `test invalid preset format: ${ presetKey }`, () => {
const newIndex = getNewIndexFromPresets( presets, 'preset-' );
it( `should return 1 for ${ presetKey }`, () => {
expect( newIndex ).toBe( 1 );
} );
} );
} );
} );
27 changes: 27 additions & 0 deletions packages/edit-site/src/components/global-styles/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ export function getVariationClassName( variation ) {
return `is-style-${ variation }`;
}

/**
* Iterates through the presets array and searches for slugs that start with the specified
* slugPrefix followed by a numerical suffix. It identifies the highest numerical suffix found
* and returns one greater than the highest found suffix, ensuring that the new index is unique.
*
* @param {Array} presets The array of preset objects, each potentially containing a slug property.
* @param {string} slugPrefix The prefix to look for in the preset slugs.
*
* @return {number} The next available index for a preset with the specified slug prefix, or 1 if no matching slugs are found.
*/
export function getNewIndexFromPresets( presets, slugPrefix ) {
const nameRegex = new RegExp( `^${ slugPrefix }([\\d]+)$` );
const highestPresetValue = presets.reduce( ( currentHighest, preset ) => {
if ( typeof preset?.slug === 'string' ) {
const matches = preset?.slug.match( nameRegex );
if ( matches ) {
const id = parseInt( matches[ 1 ], 10 );
if ( id > currentHighest ) {
return id;
}
}
}
return currentHighest;
}, 0 );
return highestPresetValue + 1;
}

function getFontFamilyFromSetting( fontFamilies, setting ) {
if ( ! Array.isArray( fontFamilies ) || ! setting ) {
return null;
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* Internal dependencies
*/
import './components';
import './push-changes-to-global-styles';
5 changes: 4 additions & 1 deletion packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { store as commandsStore } from '@wordpress/commands';
import { useRef, useEffect } from '@wordpress/element';
import { useReducedMotion } from '@wordpress/compose';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand Down Expand Up @@ -190,7 +191,9 @@ export default function DocumentBar() {
: undefined
}
>
{ title }
{ title
? decodeEntities( title )
: __( 'No Title' ) }
</Text>
</motion.div>
<span className="editor-document-bar__shortcut">
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*/
import './custom-sources-backwards-compatibility';
import './default-autocompleters';
import './media-upload';
import './pattern-overrides';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { MediaUpload } from '@wordpress/media-utils';

addFilter(
'editor.MediaUpload',
'core/edit-site/components/media-upload',
'core/editor/components/media-upload',
() => MediaUpload
);

0 comments on commit edc136b

Please sign in to comment.