From 7d47273c0038b1c3ff11965a36fbfecc39011fad Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 10:50:53 +1300 Subject: [PATCH 01/28] Add initial colorization code --- .../block-editor/src/components/list-view/block.js | 2 ++ .../block-editor/src/components/list-view/style.scss | 10 +++++++++- .../components/use-block-display-information/index.js | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/list-view/block.js b/packages/block-editor/src/components/list-view/block.js index f8e19cc6ac3358..1c411a88b7322b 100644 --- a/packages/block-editor/src/components/list-view/block.js +++ b/packages/block-editor/src/components/list-view/block.js @@ -207,6 +207,8 @@ function ListViewBlock( { 'is-branch-selected': isBranchSelected, 'is-dragging': isDragged, 'has-single-cell': ! showBlockActions, + 'is-reusable': blockInformation.isReusable, + 'is-template-part': blockInformation.isTemplatePart, } ); // Only include all selected blocks if the currently clicked on block diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index 9782dc7027bc7c..c66ee5feaac6f7 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -14,11 +14,19 @@ .block-editor-list-view-leaf { // Use position relative for row animation. position: relative; - + &.is-template-part { + color: #7c4dc3; + } // The background has to be applied to the td, not tr, or border-radius won't work. &.is-selected td { background: var(--wp-admin-theme-color); } + &.is-selected.is-template-part td { + background: #7c4dc3; + } + &.is-selected.is-reusable td { + background: #34948e; + } &.is-selected .block-editor-list-view-block-contents, &.is-selected .components-button.has-icon { color: $white; diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index cb8e7a2122f5e5..0cf5db00e1e838 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -16,6 +16,7 @@ import { store as blockEditorStore } from '../../store'; * * @typedef {Object} WPBlockDisplayInformation * + * @property {string} type Machine readable block type which is used to indicate if color should be applied. * @property {string} title Human-readable block type label. * @property {WPIcon} icon Block type icon. * @property {string} description A detailed block type description. @@ -51,6 +52,9 @@ export default function useBlockDisplayInformation( clientId ) { const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); const blockTypeInfo = { + isReusable: + blockType.name === 'core/block' && + blockType.category === 'reusable', title: blockType.title, icon: blockType.icon, description: blockType.description, @@ -59,6 +63,7 @@ export default function useBlockDisplayInformation( clientId ) { if ( ! match ) return blockTypeInfo; return { + isTemplatePart: blockType.name === 'core/template-part', title: match.title || blockType.title, icon: match.icon || blockType.icon, description: match.description || blockType.description, From 920483021fc61c7a8ee7c1e88c7bb84eee4281d2 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 11:53:21 +1300 Subject: [PATCH 02/28] Tidy up the setting of colors in the list view --- packages/base-styles/_colors.scss | 5 ++++ .../src/components/list-view/style.scss | 27 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/base-styles/_colors.scss b/packages/base-styles/_colors.scss index 03f6bfbdd566d4..ea6d6243858d7b 100644 --- a/packages/base-styles/_colors.scss +++ b/packages/base-styles/_colors.scss @@ -24,3 +24,8 @@ $light-gray-placeholder: rgba($white, 0.65); $alert-yellow: #f0b849; $alert-red: #cc1818; $alert-green: #4ab866; + +:root { + --wp-block-template-color: #7c4dc3; + --wp-block-reusable-color: #34948e; +} diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index c66ee5feaac6f7..4bf0aa029fd9e3 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -14,18 +14,22 @@ .block-editor-list-view-leaf { // Use position relative for row animation. position: relative; - &.is-template-part { - color: #7c4dc3; - } + // The background has to be applied to the td, not tr, or border-radius won't work. &.is-selected td { background: var(--wp-admin-theme-color); } &.is-selected.is-template-part td { - background: #7c4dc3; + background: var(--wp-block-template-color); } &.is-selected.is-reusable td { - background: #34948e; + background: var(--wp-block-reusable-color); + } + &.is-template-part .block-editor-list-view-block-contents { + color: var(--wp-block-template-color); + } + &.is-reusable .block-editor-list-view-block-contents { + color: var(--wp-block-reusable-color); } &.is-selected .block-editor-list-view-block-contents, &.is-selected .components-button.has-icon { @@ -150,6 +154,19 @@ } } } + + &.is-template-part .block-editor-list-view-block-contents:focus { + &::after { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-color); + } + } + + &.is-reusable .block-editor-list-view-block-contents:focus { + &::after { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); + } + } + // Fix focus styling width when one row has fewer cells. &.has-single-cell .block-editor-list-view-block-contents:focus::after { right: 0; From c26150be8869b3d1bbf5e89547f5f1b4612f5b50 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 11:59:30 +1300 Subject: [PATCH 03/28] Tidy up doc block types --- .../use-block-display-information/index.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 0cf5db00e1e838..8b4d0eba95c418 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -16,11 +16,12 @@ import { store as blockEditorStore } from '../../store'; * * @typedef {Object} WPBlockDisplayInformation * - * @property {string} type Machine readable block type which is used to indicate if color should be applied. - * @property {string} title Human-readable block type label. - * @property {WPIcon} icon Block type icon. - * @property {string} description A detailed block type description. - * @property {string} anchor HTML anchor. + * @property {boolean} isReusable True if is a reusable block + * @property {boolean} isTemplatePart True if is a template part block + * @property {string} title Human-readable block type label. + * @property {WPIcon} icon Block type icon. + * @property {string} description A detailed block type description. + * @property {string} anchor HTML anchor. */ /** @@ -51,10 +52,13 @@ export default function useBlockDisplayInformation( clientId ) { if ( ! blockType ) return null; const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); + const isReusable = + blockType.name === 'core/block' && + blockType.category === 'reusable'; + const isTemplatePart = blockType.name === 'core/template-part'; const blockTypeInfo = { - isReusable: - blockType.name === 'core/block' && - blockType.category === 'reusable', + isReusable, + isTemplatePart, title: blockType.title, icon: blockType.icon, description: blockType.description, @@ -63,7 +67,8 @@ export default function useBlockDisplayInformation( clientId ) { if ( ! match ) return blockTypeInfo; return { - isTemplatePart: blockType.name === 'core/template-part', + isReusable, + isTemplatePart, title: match.title || blockType.title, icon: match.icon || blockType.icon, description: match.description || blockType.description, From 27e1cf5c910dd7864e038073c7152d422920b3fa Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 12:23:48 +1300 Subject: [PATCH 04/28] Add color to block toolbar --- .../block-editor/src/components/block-toolbar/index.js | 10 +++++++++- .../src/components/block-toolbar/style.scss | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index b2160b3db4b6b6..ecc7cb9e77857b 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -74,6 +74,10 @@ const BlockToolbar = ( { hideDragHandle } ) => { }; }, [] ); + const isReusable = + blockType.name === 'core/block' && blockType.category === 'reusable'; + const isTemplatePart = blockType.name === 'core/template-part'; + // Handles highlighting the current block outline on hover or focus of the // block type toolbar area. const { toggleBlockHighlight } = useDispatch( blockEditorStore ); @@ -112,7 +116,11 @@ const BlockToolbar = ( { hideDragHandle } ) => { const classes = classnames( 'block-editor-block-toolbar', - shouldShowMovers && 'is-showing-movers' + shouldShowMovers && 'is-showing-movers', + { + 'is-reusable': isReusable, + 'is-template-part': isTemplatePart, + } ); return ( diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index 00d8d0da47f34e..224bf8777b0f19 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -39,6 +39,14 @@ border-right: $border-width solid $gray-300; } + &.is-reusable .block-editor-block-switcher .components-button { + color: var(--wp-block-reusable-color); + } + + &.is-template-part .block-editor-block-switcher .components-button { + color: var(--wp-block-reusable-color); + } + > :last-child, > :last-child .components-toolbar-group, > :last-child .components-toolbar { From 1ab821468bb8a926f01227abf1db89dfe21807ff Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 12:53:41 +1300 Subject: [PATCH 05/28] Add color to template block toolbar --- .../block-editor/src/components/block-toolbar/style.scss | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index 224bf8777b0f19..5f2bad4f1cbcf8 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -43,8 +43,11 @@ color: var(--wp-block-reusable-color); } - &.is-template-part .block-editor-block-switcher .components-button { - color: var(--wp-block-reusable-color); + &.is-template-part .components-toolbar-button.block-editor-block-switcher__no-switcher-icon { + color: var(--wp-block-template-color); + &:disabled .block-editor-block-icon.has-colors { + color: var(--wp-block-template-color); + } } > :last-child, From 93bf9ba5a52596253c81d7a7b3d5ef453c60d060 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 14:14:12 +1300 Subject: [PATCH 06/28] Add selection box color --- packages/base-styles/_colors.scss | 2 +- .../src/components/block-toolbar/style.scss | 4 ++-- .../src/components/list-view/style.scss | 6 ++--- packages/block-library/src/block/editor.scss | 16 ++++++++++++++ .../src/template-part/editor.scss | 22 +++++++++++++++++-- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/packages/base-styles/_colors.scss b/packages/base-styles/_colors.scss index ea6d6243858d7b..85fa4bd3a9df6f 100644 --- a/packages/base-styles/_colors.scss +++ b/packages/base-styles/_colors.scss @@ -26,6 +26,6 @@ $alert-red: #cc1818; $alert-green: #4ab866; :root { - --wp-block-template-color: #7c4dc3; + --wp-block-template-part-color: #7c4dc3; --wp-block-reusable-color: #34948e; } diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index 5f2bad4f1cbcf8..61f14e1308242b 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -44,9 +44,9 @@ } &.is-template-part .components-toolbar-button.block-editor-block-switcher__no-switcher-icon { - color: var(--wp-block-template-color); + color: var(--wp-block-template-part-color); &:disabled .block-editor-block-icon.has-colors { - color: var(--wp-block-template-color); + color: var(--wp-block-template-part-color); } } diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index 4bf0aa029fd9e3..fb4c3cf95254eb 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -20,13 +20,13 @@ background: var(--wp-admin-theme-color); } &.is-selected.is-template-part td { - background: var(--wp-block-template-color); + background: var(--wp-block-template-part-color); } &.is-selected.is-reusable td { background: var(--wp-block-reusable-color); } &.is-template-part .block-editor-list-view-block-contents { - color: var(--wp-block-template-color); + color: var(--wp-block-template-part-color); } &.is-reusable .block-editor-list-view-block-contents { color: var(--wp-block-reusable-color); @@ -157,7 +157,7 @@ &.is-template-part .block-editor-list-view-block-contents:focus { &::after { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-color); + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); } } diff --git a/packages/block-library/src/block/editor.scss b/packages/block-library/src/block/editor.scss index b3eb1a67e99459..9b57d229a46814 100644 --- a/packages/block-library/src/block/editor.scss +++ b/packages/block-library/src/block/editor.scss @@ -13,4 +13,20 @@ .components-disabled .block-list-appender { display: none; } + + &.is-highlighted, + &.is-selected { + border-radius: $radius-block-ui; + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); + } + + &.block-editor-block-list__block:not([contenteditable]):focus { + &::after { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); + // Show a light color for dark themes. + .is-dark-theme & { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; + } + } + } } diff --git a/packages/block-library/src/template-part/editor.scss b/packages/block-library/src/template-part/editor.scss index c17d37a6078e2d..e807d5bbb8309e 100644 --- a/packages/block-library/src/template-part/editor.scss +++ b/packages/block-library/src/template-part/editor.scss @@ -5,8 +5,8 @@ // and height are used instead of max-(width/height). .components-modal__frame { @include break-small() { - width: calc(100% - #{ $grid-unit-20 * 2 }); - height: calc(100% - #{ $header-height * 2 }); + width: calc(100% - #{$grid-unit-20 * 2}); + height: calc(100% - #{$header-height * 2}); } @include break-medium() { width: $break-medium - $grid-unit-20 * 2; @@ -24,3 +24,21 @@ padding: $grid-unit-20 0; z-index: z-index(".block-library-template-part__selection-search"); } + +.wp-block-template-part { + &.is-highlighted, + &.is-selected { + border-radius: $radius-block-ui; + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); + } + + &.block-editor-block-list__block:not([contenteditable]):focus { + &::after { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); + // Show a light color for dark themes. + .is-dark-theme & { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; + } + } + } +} From 2a3decac763d4cccd1bae777c09fc876ae833685 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 14:33:44 +1300 Subject: [PATCH 07/28] Fix scope of styles --- packages/block-library/src/block/editor.scss | 3 ++- packages/block-library/src/template-part/editor.scss | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/block/editor.scss b/packages/block-library/src/block/editor.scss index 9b57d229a46814..6496a5339d0a21 100644 --- a/packages/block-library/src/block/editor.scss +++ b/packages/block-library/src/block/editor.scss @@ -13,10 +13,11 @@ .components-disabled .block-list-appender { display: none; } +} +.block-library-block__reusable-block-container { &.is-highlighted, &.is-selected { - border-radius: $radius-block-ui; box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); } diff --git a/packages/block-library/src/template-part/editor.scss b/packages/block-library/src/template-part/editor.scss index e807d5bbb8309e..60f71efed7db77 100644 --- a/packages/block-library/src/template-part/editor.scss +++ b/packages/block-library/src/template-part/editor.scss @@ -28,7 +28,6 @@ .wp-block-template-part { &.is-highlighted, &.is-selected { - border-radius: $radius-block-ui; box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); } From 22c5977ed89b6a6f3c83ac8558898b1b6a1ada60 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 16:08:58 +1300 Subject: [PATCH 08/28] Add colors to block selector --- .../src/components/inserter-list-item/index.js | 13 ++++++++++++- .../src/components/inserter-list-item/style.scss | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/inserter-list-item/index.js b/packages/block-editor/src/components/inserter-list-item/index.js index d24df56df241fe..a78efc0ab2f871 100644 --- a/packages/block-editor/src/components/inserter-list-item/index.js +++ b/packages/block-editor/src/components/inserter-list-item/index.js @@ -47,6 +47,10 @@ function InserterListItem( { ]; }, [ item.name, item.initialAttributes, item.initialAttributes ] ); + const isReusable = + item.name === 'core/block' && item.category === 'reusable'; + const isTemplatePart = item.name === 'core/template-part'; + return ( { ( { draggable, onDragStart, onDragEnd } ) => (
{ isDragging.current = true; diff --git a/packages/block-editor/src/components/inserter-list-item/style.scss b/packages/block-editor/src/components/inserter-list-item/style.scss index b3078adb519f15..c134d29254e389 100644 --- a/packages/block-editor/src/components/inserter-list-item/style.scss +++ b/packages/block-editor/src/components/inserter-list-item/style.scss @@ -3,6 +3,18 @@ width: 33.33%; padding: 0; margin: 0; + &.is-template-part { + .block-editor-block-icon.has-colors, + .block-editor-block-types-list__item-title { + color: var(--wp-block-template-part-color); + } + } + &.is-reusable { + .block-editor-block-icon.has-colors, + .block-editor-block-types-list__item-title { + color: var(--wp-block-reusable-color); + } + } } .components-button.block-editor-block-types-list__item { From be58817e2025b6c7a6fae861ce7bc8d5bb092401 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Nov 2022 17:04:46 +1300 Subject: [PATCH 09/28] fix issue with outline styles --- .../src/components/list-view/style.scss | 12 ------------ packages/block-library/src/block/editor.scss | 17 ----------------- .../src/template-part/editor.scss | 19 ++++++++++++++++++- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index fb4c3cf95254eb..e35a522399c55e 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -155,18 +155,6 @@ } } - &.is-template-part .block-editor-list-view-block-contents:focus { - &::after { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); - } - } - - &.is-reusable .block-editor-list-view-block-contents:focus { - &::after { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); - } - } - // Fix focus styling width when one row has fewer cells. &.has-single-cell .block-editor-list-view-block-contents:focus::after { right: 0; diff --git a/packages/block-library/src/block/editor.scss b/packages/block-library/src/block/editor.scss index 6496a5339d0a21..b3eb1a67e99459 100644 --- a/packages/block-library/src/block/editor.scss +++ b/packages/block-library/src/block/editor.scss @@ -14,20 +14,3 @@ display: none; } } - -.block-library-block__reusable-block-container { - &.is-highlighted, - &.is-selected { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); - } - - &.block-editor-block-list__block:not([contenteditable]):focus { - &::after { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); - // Show a light color for dark themes. - .is-dark-theme & { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; - } - } - } -} diff --git a/packages/block-library/src/template-part/editor.scss b/packages/block-library/src/template-part/editor.scss index 60f71efed7db77..500860062f554c 100644 --- a/packages/block-library/src/template-part/editor.scss +++ b/packages/block-library/src/template-part/editor.scss @@ -25,7 +25,7 @@ z-index: z-index(".block-library-template-part__selection-search"); } -.wp-block-template-part { +.is-outline-mode .block-editor-block-list__block:not(.remove-outline).wp-block-template-part { &.is-highlighted, &.is-selected { box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-template-part-color); @@ -41,3 +41,20 @@ } } } + +.is-outline-mode .block-editor-block-list__block:not(.remove-outline).is-reusable { + &.is-highlighted, + &.is-selected { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); + } + + &.block-editor-block-list__block:not([contenteditable]):focus { + &::after { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-reusable-color); + // Show a light color for dark themes. + .is-dark-theme & { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; + } + } + } +} From 0d1dbb97b935ca541c1ea9f9bc8c06cfb41a69ab Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 3 Nov 2022 08:52:53 +1300 Subject: [PATCH 10/28] Switch to using the existing isTemplatePart and isReusable methods --- .../src/components/block-toolbar/index.js | 13 ++++++++----- .../use-block-display-information/index.js | 12 +++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index ecc7cb9e77857b..f7b68907f5977e 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -9,7 +9,12 @@ import classnames from 'classnames'; import { useSelect, useDispatch } from '@wordpress/data'; import { useRef } from '@wordpress/element'; import { useViewportMatch } from '@wordpress/compose'; -import { getBlockType, hasBlockSupport } from '@wordpress/blocks'; +import { + getBlockType, + hasBlockSupport, + isReusableBlock, + isTemplatePart as isTemplate, +} from '@wordpress/blocks'; import { ToolbarGroup } from '@wordpress/components'; /** @@ -74,10 +79,6 @@ const BlockToolbar = ( { hideDragHandle } ) => { }; }, [] ); - const isReusable = - blockType.name === 'core/block' && blockType.category === 'reusable'; - const isTemplatePart = blockType.name === 'core/template-part'; - // Handles highlighting the current block outline on hover or focus of the // block type toolbar area. const { toggleBlockHighlight } = useDispatch( blockEditorStore ); @@ -113,6 +114,8 @@ const BlockToolbar = ( { hideDragHandle } ) => { const shouldShowVisualToolbar = isValid && isVisual; const isMultiToolbar = blockClientIds.length > 1; + const isReusable = isReusableBlock( blockType ); + const isTemplatePart = isTemplate( blockType ); const classes = classnames( 'block-editor-block-toolbar', diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 8b4d0eba95c418..c489acef5dc790 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -2,7 +2,11 @@ * WordPress dependencies */ import { useSelect } from '@wordpress/data'; -import { store as blocksStore } from '@wordpress/blocks'; +import { + store as blocksStore, + isReusableBlock, + isTemplatePart as isTemplate, +} from '@wordpress/blocks'; /** * Internal dependencies @@ -52,10 +56,8 @@ export default function useBlockDisplayInformation( clientId ) { if ( ! blockType ) return null; const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); - const isReusable = - blockType.name === 'core/block' && - blockType.category === 'reusable'; - const isTemplatePart = blockType.name === 'core/template-part'; + const isReusable = isReusableBlock( blockType ); + const isTemplatePart = isTemplate( blockType ); const blockTypeInfo = { isReusable, isTemplatePart, From 3fbf88dbd26cfe7b1869806d62be947357b586dd Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 3 Nov 2022 08:57:05 +1300 Subject: [PATCH 11/28] another switch to use existing methods --- .../src/components/inserter-list-item/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/inserter-list-item/index.js b/packages/block-editor/src/components/inserter-list-item/index.js index a78efc0ab2f871..a4bc92627743f2 100644 --- a/packages/block-editor/src/components/inserter-list-item/index.js +++ b/packages/block-editor/src/components/inserter-list-item/index.js @@ -10,6 +10,8 @@ import { useMemo, useRef, memo } from '@wordpress/element'; import { createBlock, createBlocksFromInnerBlocksTemplate, + isReusableBlock, + isTemplatePart as isTemplate, } from '@wordpress/blocks'; import { __experimentalTruncate as Truncate } from '@wordpress/components'; import { ENTER, isAppleOS } from '@wordpress/keycodes'; @@ -47,9 +49,8 @@ function InserterListItem( { ]; }, [ item.name, item.initialAttributes, item.initialAttributes ] ); - const isReusable = - item.name === 'core/block' && item.category === 'reusable'; - const isTemplatePart = item.name === 'core/template-part'; + const isReusable = isReusableBlock( item ); + const isTemplatePart = isTemplate( item ); return ( Date: Thu, 3 Nov 2022 16:54:48 +1300 Subject: [PATCH 12/28] Combine the template part and reusable block colors under an `isSynced` flag --- packages/base-styles/_colors.scss | 3 +-- .../src/components/block-toolbar/index.js | 9 ++++---- .../src/components/block-toolbar/style.scss | 10 ++++---- .../components/inserter-list-item/index.js | 8 +++---- .../components/inserter-list-item/style.scss | 10 ++------ .../src/components/list-view/block.js | 3 +-- .../src/components/list-view/style.scss | 14 ++++------- .../use-block-display-information/index.js | 23 ++++++++----------- .../src/template-part/editor.scss | 11 +++++---- 9 files changed, 36 insertions(+), 55 deletions(-) diff --git a/packages/base-styles/_colors.scss b/packages/base-styles/_colors.scss index 85fa4bd3a9df6f..b99407fd5a767e 100644 --- a/packages/base-styles/_colors.scss +++ b/packages/base-styles/_colors.scss @@ -26,6 +26,5 @@ $alert-red: #cc1818; $alert-green: #4ab866; :root { - --wp-block-template-part-color: #7c4dc3; - --wp-block-reusable-color: #34948e; + --wp-block-synced-color: #7a00df; } diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index f7b68907f5977e..0ce0764313f689 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -13,7 +13,7 @@ import { getBlockType, hasBlockSupport, isReusableBlock, - isTemplatePart as isTemplate, + isTemplatePart, } from '@wordpress/blocks'; import { ToolbarGroup } from '@wordpress/components'; @@ -114,15 +114,14 @@ const BlockToolbar = ( { hideDragHandle } ) => { const shouldShowVisualToolbar = isValid && isVisual; const isMultiToolbar = blockClientIds.length > 1; - const isReusable = isReusableBlock( blockType ); - const isTemplatePart = isTemplate( blockType ); + const isSynced = + isReusableBlock( blockType ) || isTemplatePart( blockType ); const classes = classnames( 'block-editor-block-toolbar', shouldShowMovers && 'is-showing-movers', { - 'is-reusable': isReusable, - 'is-template-part': isTemplatePart, + 'is-synced': isSynced, } ); diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index 61f14e1308242b..12dcf482a0100f 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -39,14 +39,14 @@ border-right: $border-width solid $gray-300; } - &.is-reusable .block-editor-block-switcher .components-button { - color: var(--wp-block-reusable-color); + &.is-synced .block-editor-block-switcher .components-button { + color: var(--wp-block-synced-color); } - &.is-template-part .components-toolbar-button.block-editor-block-switcher__no-switcher-icon { - color: var(--wp-block-template-part-color); + &.is-synced .components-toolbar-button.block-editor-block-switcher__no-switcher-icon { + color: var(--wp-block-synced-color); &:disabled .block-editor-block-icon.has-colors { - color: var(--wp-block-template-part-color); + color: var(--wp-block-synced-color); } } diff --git a/packages/block-editor/src/components/inserter-list-item/index.js b/packages/block-editor/src/components/inserter-list-item/index.js index a4bc92627743f2..2c7e73ffc0f68e 100644 --- a/packages/block-editor/src/components/inserter-list-item/index.js +++ b/packages/block-editor/src/components/inserter-list-item/index.js @@ -11,7 +11,7 @@ import { createBlock, createBlocksFromInnerBlocksTemplate, isReusableBlock, - isTemplatePart as isTemplate, + isTemplatePart, } from '@wordpress/blocks'; import { __experimentalTruncate as Truncate } from '@wordpress/components'; import { ENTER, isAppleOS } from '@wordpress/keycodes'; @@ -49,8 +49,7 @@ function InserterListItem( { ]; }, [ item.name, item.initialAttributes, item.initialAttributes ] ); - const isReusable = isReusableBlock( item ); - const isTemplatePart = isTemplate( item ); + const isSynced = isReusableBlock( item ) || isTemplatePart( item ); return ( Date: Thu, 3 Nov 2022 17:12:01 +1300 Subject: [PATCH 13/28] Remove color from block name and just color icon --- packages/block-editor/src/components/block-toolbar/style.scss | 3 +-- .../block-editor/src/components/inserter-list-item/style.scss | 3 +-- packages/block-editor/src/components/list-view/style.scss | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index 12dcf482a0100f..41faa1a46eaed2 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -39,12 +39,11 @@ border-right: $border-width solid $gray-300; } - &.is-synced .block-editor-block-switcher .components-button { + &.is-synced .block-editor-block-switcher .components-button .block-editor-block-icon { color: var(--wp-block-synced-color); } &.is-synced .components-toolbar-button.block-editor-block-switcher__no-switcher-icon { - color: var(--wp-block-synced-color); &:disabled .block-editor-block-icon.has-colors { color: var(--wp-block-synced-color); } diff --git a/packages/block-editor/src/components/inserter-list-item/style.scss b/packages/block-editor/src/components/inserter-list-item/style.scss index aefdcaf21a1341..67e49db0d6c4d9 100644 --- a/packages/block-editor/src/components/inserter-list-item/style.scss +++ b/packages/block-editor/src/components/inserter-list-item/style.scss @@ -4,8 +4,7 @@ padding: 0; margin: 0; &.is-synced { - .block-editor-block-icon.has-colors, - .block-editor-block-types-list__item-title { + .block-editor-block-icon.has-colors { color: var(--wp-block-synced-color); } } diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index 8d6f59697f413d..5df71cb7467a86 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -22,7 +22,7 @@ &.is-selected.is-synced td { background: var(--wp-block-synced-color); } - &.is-synced .block-editor-list-view-block-contents { + &.is-synced .block-editor-list-view-block-contents .block-editor-block-icon { color: var(--wp-block-synced-color); } &.is-selected .block-editor-list-view-block-contents, From e0f590511fe4b2d088f0cacb02c6b2d352fd05ac Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 3 Nov 2022 17:21:00 +1300 Subject: [PATCH 14/28] Apply selected outline color to reusable blocks in the post editor --- packages/block-library/src/block/editor.scss | 17 +++++++++++++++++ .../block-library/src/template-part/editor.scss | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/block-library/src/block/editor.scss b/packages/block-library/src/block/editor.scss index b3eb1a67e99459..c49675392a525e 100644 --- a/packages/block-library/src/block/editor.scss +++ b/packages/block-library/src/block/editor.scss @@ -14,3 +14,20 @@ display: none; } } + +.edit-post-visual-editor .block-editor-block-list__block:not(.remove-outline).is-reusable { + &.is-highlighted, + &.is-selected { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color); + } + + &.block-editor-block-list__block:not([contenteditable]):focus { + &::after { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color); + // Show a light color for dark themes. + .is-dark-theme & { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; + } + } + } +} diff --git a/packages/block-library/src/template-part/editor.scss b/packages/block-library/src/template-part/editor.scss index 74b3d780032204..a847ecec01f94d 100644 --- a/packages/block-library/src/template-part/editor.scss +++ b/packages/block-library/src/template-part/editor.scss @@ -42,20 +42,3 @@ } } } - -.is-outline-mode .block-editor-block-list__block:not(.remove-outline).is-reusable { - &.is-highlighted, - &.is-selected { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color); - } - - &.block-editor-block-list__block:not([contenteditable]):focus { - &::after { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color); - // Show a light color for dark themes. - .is-dark-theme & { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus; - } - } - } -} From 693158644b94770ce6d81b9d5fac93ff8e3a8de0 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 4 Nov 2022 10:27:14 +1300 Subject: [PATCH 15/28] change colour of focus outline --- packages/block-editor/src/components/list-view/style.scss | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/block-editor/src/components/list-view/style.scss b/packages/block-editor/src/components/list-view/style.scss index 5df71cb7467a86..e269ae0ad34d6e 100644 --- a/packages/block-editor/src/components/list-view/style.scss +++ b/packages/block-editor/src/components/list-view/style.scss @@ -43,6 +43,13 @@ 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); } } + &.is-selected.is-synced .block-editor-list-view-block-contents:focus { + &::after { + box-shadow: + inset 0 0 0 1px $white, + 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color); + } + } &.is-selected .block-editor-list-view-block__menu:focus { box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $white; } From e5d1f96ea1a0ed734b92acb496095b484a4836a0 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 23 Nov 2022 09:06:30 +1300 Subject: [PATCH 16/28] Add synced color to block icon in inspector panel header --- .../block-editor/src/components/block-card/index.js | 12 +++++++++++- .../src/components/block-card/style.scss | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-card/index.js b/packages/block-editor/src/components/block-card/index.js index 6362b1b4ca2c7c..afda93d5ece7af 100644 --- a/packages/block-editor/src/components/block-card/index.js +++ b/packages/block-editor/src/components/block-card/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -17,6 +22,7 @@ function BlockCard( { blockType, parentBlockClientId, handleBackButton, + isSynced, } ) { if ( blockType ) { deprecated( '`blockType` property in `BlockCard component`', { @@ -30,7 +36,11 @@ function BlockCard( { window?.__experimentalEnableOffCanvasNavigationEditor === true; return ( -
+
{ isOffCanvasNavigationEditorEnabled && parentBlockClientId && (