From 51057facbf7d7fd1be8bf71123822fb16f682c2e Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Fri, 14 Jun 2024 09:18:04 -0500 Subject: [PATCH] Sort spacing sizes when all slugs begin numerically (#62567) Co-authored-by: ajlende Co-authored-by: scruffian Co-authored-by: justintadlock --- .../spacing-sizes-control/hooks/use-spacing-sizes.js | 11 ++--------- schemas/json/theme.json | 5 ++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js b/packages/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js index 9943978c15af18..d822dd200b626d 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +++ b/packages/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js @@ -44,15 +44,8 @@ export default function useSpacingSizes() { ...defaultSizes, ]; - // Only sort if more than one origin has presets defined in order to - // preserve order for themes that don't include default presets and - // want a custom order. - if ( - ( customSizes.length && 1 ) + - ( themeSizes.length && 1 ) + - ( defaultSizes.length && 1 ) > - 1 - ) { + // Using numeric slugs opts-in to sorting by slug. + if ( sizes.every( ( { slug } ) => /^[0-9]/.test( slug ) ) ) { sizes.sort( ( a, b ) => compare( a.slug, b.slug ) ); } diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 37bbd6f7f08935..5b9e37ef7378a6 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -444,9 +444,8 @@ "type": "string" }, "slug": { - "description": "Unique identifier for the space size preset. Will be sorted numerically. For best cross theme compatibility these should be in the form '10','20','30','40','50','60', etc. with '50' representing the 'Medium' size step.", - "type": "string", - "pattern": "^[0-9].*$" + "description": "Unique identifier for the space size preset. For best cross theme compatibility these should be in the form '10','20','30','40','50','60', etc. with '50' representing the 'Medium' size step. If all slugs begin with a number they will be merged with default and user slugs and sorted numerically.", + "type": "string" }, "size": { "description": "CSS space-size value, including units.",