From bfcc4cf0735ee3de12152e4898a483089b8d6ce2 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Fri, 14 Jun 2024 00:01:41 -0500 Subject: [PATCH] Sort spacing sizes when all slugs begin numerically --- .../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 9943978c15af1..d822dd200b626 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 bdfea7279f67a..277bc2a7782bc 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.",