Skip to content

Commit

Permalink
Merge branch 'trunk' into docs/simplify-code-example-toggle-control
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Nov 22, 2023
2 parents a8987e2 + 3861da9 commit 85f12b0
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 44 deletions.
2 changes: 2 additions & 0 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ _Returns_

### getCurrentThemeGlobalStylesRevisions

> **Deprecated** since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
Returns the revisions of the current global styles theme.

_Parameters_
Expand Down
28 changes: 17 additions & 11 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Icon, symbol } from '@wordpress/icons';
import BlockPreview from '../block-preview';
import InserterDraggableBlocks from '../inserter-draggable-blocks';
import BlockPatternsPaging from '../block-patterns-paging';
import { PATTERN_TYPES } from '../inserter/block-patterns-tab/utils';

const WithToolTip = ( { showTooltip, title, children } ) => {
if ( showTooltip ) {
Expand Down Expand Up @@ -71,7 +72,9 @@ function BlockPattern( {
} }
>
<WithToolTip
showTooltip={ showTooltip && ! pattern.id }
showTooltip={
showTooltip && ! pattern.type !== PATTERN_TYPES.user
}
title={ pattern.title }
>
<CompositeItem
Expand All @@ -82,7 +85,8 @@ function BlockPattern( {
'block-editor-block-patterns-list__item',
{
'block-editor-block-patterns-list__list-item-synced':
pattern.id && ! pattern.syncStatus,
pattern.type === PATTERN_TYPES.user &&
! pattern.syncStatus,
}
) }
onClick={ () => {
Expand All @@ -107,15 +111,17 @@ function BlockPattern( {
/>

<HStack className="block-editor-patterns__pattern-details">
{ pattern.id && ! pattern.syncStatus && (
<div className="block-editor-patterns__pattern-icon-wrapper">
<Icon
className="block-editor-patterns__pattern-icon"
icon={ symbol }
/>
</div>
) }
{ ( ! showTooltip || pattern.id ) && (
{ pattern.type === PATTERN_TYPES.user &&
! pattern.syncStatus && (
<div className="block-editor-patterns__pattern-icon-wrapper">
<Icon
className="block-editor-patterns__pattern-icon"
icon={ symbol }
/>
</div>
) }
{ ( ! showTooltip ||
pattern.type === PATTERN_TYPES.user ) && (
<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
__experimentalNumberControl as NumberControl,
__experimentalHStack as HStack,
} from '@wordpress/components';
import deprecated from '@wordpress/deprecated';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -31,11 +30,6 @@ export default function ImageSizeControl( {
onChange,
onChangeImage = noop,
} ) {
deprecated( 'wp.blockEditor.__experimentalImageSizeControl', {
since: '6.3',
alternative:
'wp.blockEditor.privateApis.DimensionsTool and wp.blockEditor.privateApis.ResolutionTool',
} );
const { currentHeight, currentWidth, updateDimension, updateDimensions } =
useDimensionHandler( height, width, imageHeight, imageWidth, onChange );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { searchItems } from '../search-items';
import BlockPatternsPaging from '../../block-patterns-paging';
import usePatternsPaging from '../hooks/use-patterns-paging';
import {
PATTERN_TYPES,
allPatternsCategory,
myPatternsCategory,
} from '../block-patterns-tab/utils';
Expand Down Expand Up @@ -70,7 +71,10 @@ function PatternList( { searchValue, selectedCategory, patternCategories } ) {
if ( selectedCategory === allPatternsCategory.name ) {
return true;
}
if ( selectedCategory === myPatternsCategory.name && pattern.id ) {
if (
selectedCategory === myPatternsCategory.name &&
pattern.type === PATTERN_TYPES.user
) {
return true;
}
if ( selectedCategory === 'uncategorized' ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isPatternFiltered,
allPatternsCategory,
myPatternsCategory,
PATTERN_TYPES,
} from './utils';

const noop = () => {};
Expand Down Expand Up @@ -69,7 +70,10 @@ export function PatternCategoryPreviews( {
if ( category.name === allPatternsCategory.name ) {
return true;
}
if ( category.name === myPatternsCategory.name && pattern.id ) {
if (
category.name === myPatternsCategory.name &&
pattern.type === PATTERN_TYPES.user
) {
return true;
}
if ( category.name !== 'uncategorized' ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isPatternFiltered,
allPatternsCategory,
myPatternsCategory,
PATTERN_TYPES,
} from './utils';

export function usePatternCategories( rootClientId, sourceFilter = 'all' ) {
Expand Down Expand Up @@ -69,7 +70,11 @@ export function usePatternCategories( rootClientId, sourceFilter = 'all' ) {
label: _x( 'Uncategorized' ),
} );
}
if ( filteredPatterns.some( ( pattern ) => pattern.id ) ) {
if (
filteredPatterns.some(
( pattern ) => pattern.type === PATTERN_TYPES.user
)
) {
categories.unshift( myPatternsCategory );
}
if ( filteredPatterns.length > 0 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
return true;
}

// If user source selected, filter out theme patterns. Any pattern without
// an id wasn't created by a user.
if ( sourceFilter === PATTERN_TYPES.user && ! pattern.id ) {
// If user source selected, filter out theme patterns.
if (
sourceFilter === PATTERN_TYPES.user &&
pattern.type !== PATTERN_TYPES.user
) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { store as noticesStore } from '@wordpress/notices';
* Internal dependencies
*/
import { store as blockEditorStore } from '../../../store';
import { PATTERN_TYPES } from '../block-patterns-tab/utils';

/**
* Retrieves the block patterns inserter state.
Expand Down Expand Up @@ -57,7 +58,8 @@ const usePatternsState = ( onInsert, rootClientId ) => {
const onClickPattern = useCallback(
( pattern, blocks ) => {
const patternBlocks =
pattern.id && pattern.syncStatus !== 'unsynced'
pattern.type === PATTERN_TYPES.user &&
pattern.syncStatus !== 'unsynced'
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
: blocks;
onInsert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default function SpacingInputControl( {
useMemo(
() => parseQuantityAndUnitFromRawValue( currentValue ),
[ currentValue ]
)[ 1 ] || units[ 0 ].value;
)[ 1 ] || units[ 0 ]?.value;

const setInitialValue = () => {
if ( value === undefined ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function useMovingAnimation( {
const finishedMoving = x === 0 && y === 0;
ref.current.style.transformOrigin = 'center center';
ref.current.style.transform = finishedMoving
? undefined
? null // Set to `null` to explicitly remove the transform.
: `translate3d(${ x }px,${ y }px,0)`;
ref.current.style.zIndex = isSelected ? '1' : '';

Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { createRegistrySelector } from '@wordpress/data';
* Internal dependencies
*/
import { orderBy } from '../utils/sorting';
import { PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils';

/**
* A block selection object.
Expand Down Expand Up @@ -2287,6 +2288,7 @@ function getUserPatterns( state ) {
return {
name: `core/block/${ userPattern.id }`,
id: userPattern.id,
type: PATTERN_TYPES.user,
title: userPattern.title.raw,
categories: userPattern.wp_pattern_category.map( ( catId ) =>
categories && categories.get( catId )
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
h4,
h5,
h6 {
&:not(.has-text-color) {
&:where(:not(.has-text-color)) {
color: inherit;
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ const PatternEdit = ( { attributes, clientId } ) => {
[]
);

const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const { setBlockEditingMode } = useDispatch( blockEditorStore );
const {
replaceBlocks,
setBlockEditingMode,
__unstableMarkNextChangeAsNotPersistent,
} = useDispatch( blockEditorStore );
const { getBlockRootClientId, getBlockEditingMode } =
useSelect( blockEditorStore );

Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/combobox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ function MyComboboxControl() {
onFilterValueChange={ ( inputValue ) =>
setFilteredOptions(
options.filter( ( option ) =>
option.label
.toLowerCase()
.startsWith( inputValue.toLowerCase() )
option.value === inputValue
)
)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ _Returns_

### getCurrentThemeGlobalStylesRevisions

> **Deprecated** since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
Returns the revisions of the current global styles theme.

_Parameters_
Expand Down
9 changes: 9 additions & 0 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export function receiveThemeSupports() {
* Returns an action object used in signalling that the theme global styles CPT post revisions have been received.
* Ignored from documentation as it's internal to the data store.
*
* @deprecated since WordPress 6.5.0. Callers should use `dispatch( 'core' ).receiveRevision` instead.
*
* @ignore
*
* @param {number} currentId The post id.
Expand All @@ -226,6 +228,13 @@ export function receiveThemeSupports() {
* @return {Object} Action object.
*/
export function receiveThemeGlobalStyleRevisions( currentId, revisions ) {
deprecated(
"wp.data.dispatch( 'core' ).receiveThemeGlobalStyleRevisions()",
{
since: '6.5.0',
alternative: "wp.data.dispatch( 'core' ).receiveRevisions",
}
);
return {
type: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS',
currentId,
Expand Down
9 changes: 8 additions & 1 deletion packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,20 @@ export function getUserPatternCategories(
/**
* Returns the revisions of the current global styles theme.
*
* @param state Data state.
* @deprecated since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
*
* @param state Data state.
*
* @return The current global styles.
*/
export function getCurrentThemeGlobalStylesRevisions(
state: State
): Array< object > | null {
deprecated( "select( 'core' ).getCurrentThemeGlobalStylesRevisions()", {
since: '6.5.0',
alternative:
"select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )",
} );
const currentGlobalStylesId =
__experimentalGetCurrentGlobalStylesId( state );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ export default function useGlobalStylesRevisions() {
__experimentalGetDirtyEntityRecords,
getCurrentUser,
getUsers,
getCurrentThemeGlobalStylesRevisions,
getRevisions,
__experimentalGetCurrentGlobalStylesId,
isResolving,
} = select( coreStore );
const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
const _currentUser = getCurrentUser();
const _isDirty = dirtyEntityRecords.length > 0;
const globalStylesRevisions =
getCurrentThemeGlobalStylesRevisions() || EMPTY_ARRAY;
getRevisions(
'root',
'globalStyles',
__experimentalGetCurrentGlobalStylesId(),
{
per_page: 100,
}
) || EMPTY_ARRAY;
const _authors = getUsers( SITE_EDITOR_AUTHORS_QUERY ) || EMPTY_ARRAY;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const selectPatterns = createSelector(
// User patterns can have their sync statuses checked directly
// Non-user patterns are all unsynced for the time being.
patterns = patterns.filter( ( pattern ) => {
return pattern.id
return pattern.type === PATTERN_TYPES.user
? pattern.syncStatus === syncStatus
: syncStatus === PATTERN_SYNC_TYPES.unsynced;
} );
Expand Down
13 changes: 7 additions & 6 deletions packages/patterns/src/components/duplicate-pattern-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { store as noticesStore } from '@wordpress/notices';
* Internal dependencies
*/
import CreatePatternModal from './create-pattern-modal';
import { PATTERN_SYNC_TYPES } from '../constants';
import { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';

function getTermLabels( pattern, categories ) {
// Theme patterns don't have an id and rely on core pattern categories.
if ( ! pattern.id ) {
// Theme patterns rely on core pattern categories.
if ( pattern.type !== PATTERN_TYPES.user ) {
return categories.core
?.filter( ( category ) =>
pattern.categories.includes( category.name )
Expand Down Expand Up @@ -52,9 +52,10 @@ export default function DuplicatePatternModal( {
const duplicatedProps = {
content: pattern.content,
defaultCategories: getTermLabels( pattern, categories ),
defaultSyncType: ! pattern.id // Theme patterns don't have an ID.
? PATTERN_SYNC_TYPES.unsynced
: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
defaultSyncType:
pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.
? PATTERN_SYNC_TYPES.unsynced
: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
defaultTitle: sprintf(
/* translators: %s: Existing pattern title */
__( '%s (Copy)' ),
Expand Down
3 changes: 2 additions & 1 deletion schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@
"items": {
"type": "string"
},
"default": [ "px", "em", "rem", "vh", "vw", "%" ]
"default": [ "px", "em", "rem", "vh", "vw", "%" ],
"minItems": 1
},
"customSpacingSize": {
"description": "Allow users to set custom space sizes.",
Expand Down

0 comments on commit 85f12b0

Please sign in to comment.