@wordpress/block-editor 8.0.11 → 8.0.12-next.33ec3857e2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/components/block-caption/index.native.js +14 -3
- package/build/components/block-caption/index.native.js.map +1 -1
- package/build/components/block-inspector/index.js +12 -23
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list-appender/index.js +3 -11
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-preview/auto.js +10 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +51 -0
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-settings/container.native.js +2 -1
- package/build/components/block-settings/container.native.js.map +1 -1
- package/build/components/block-styles/index.js +110 -134
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-styles/menu-items.js +63 -0
- package/build/components/block-styles/menu-items.js.map +1 -0
- package/build/components/block-styles/preview-panel.js +45 -0
- package/build/components/block-styles/preview-panel.js.map +1 -0
- package/build/components/block-styles/use-styles-for-block.js +119 -0
- package/build/components/block-styles/use-styles-for-block.js.map +1 -0
- package/build/components/block-styles/utils.js +39 -0
- package/build/components/block-styles/utils.js.map +1 -1
- package/build/components/block-switcher/block-styles-menu.js +3 -23
- package/build/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +11 -1
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/button-block-appender/index.js +2 -1
- package/build/components/button-block-appender/index.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +51 -10
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/default-block-appender/index.js +16 -19
- package/build/components/default-block-appender/index.js.map +1 -1
- package/build/components/default-style-picker/index.js +18 -3
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/iframe/index.js +3 -4
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +17 -10
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/default-block-appender.js +2 -4
- package/build/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build/components/inserter/index.native.js +1 -1
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +7 -4
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inspector-controls/block-support-slot-container.js +2 -1
- package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +3 -5
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls/slot.js +1 -3
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +6 -6
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +23 -3
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/media-placeholder/index.js +2 -0
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +2 -0
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/rich-text/file-paste-handler.js +1 -1
- package/build/components/rich-text/file-paste-handler.js.map +1 -1
- package/build/components/rich-text/prevent-event-discovery.js +33 -0
- package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +3 -1
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/selection-scroll-into-view/index.js +2 -1
- package/build/components/selection-scroll-into-view/index.js.map +1 -1
- package/build/components/use-display-block-controls/index.native.js +45 -0
- package/build/components/use-display-block-controls/index.native.js.map +1 -0
- package/build/components/use-on-block-drop/index.js +7 -3
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +3 -1
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/hooks/border-color.js +63 -5
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border-radius.js +47 -0
- package/build/hooks/border-radius.js.map +1 -1
- package/build/hooks/border-style.js +41 -0
- package/build/hooks/border-style.js.map +1 -1
- package/build/hooks/border-width.js +70 -31
- package/build/hooks/border-width.js.map +1 -1
- package/build/hooks/border.js +81 -11
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/letter-spacing.js +1 -1
- package/build/hooks/letter-spacing.js.map +1 -1
- package/build/hooks/typography.js +1 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/store/actions.js +1 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/selectors.js +25 -7
- package/build/store/selectors.js.map +1 -1
- package/build/utils/get-paste-event-data.js +1 -1
- package/build/utils/get-paste-event-data.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +1 -1
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-caption/index.native.js +13 -3
- package/build-module/components/block-caption/index.native.js.map +1 -1
- package/build-module/components/block-inspector/index.js +12 -23
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +3 -10
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +10 -2
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +46 -0
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-settings/container.native.js +2 -1
- package/build-module/components/block-settings/container.native.js.map +1 -1
- package/build-module/components/block-styles/index.js +112 -133
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-styles/menu-items.js +50 -0
- package/build-module/components/block-styles/menu-items.js.map +1 -0
- package/build-module/components/block-styles/preview-panel.js +35 -0
- package/build-module/components/block-styles/preview-panel.js.map +1 -0
- package/build-module/components/block-styles/use-styles-for-block.js +107 -0
- package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
- package/build-module/components/block-styles/utils.js +34 -0
- package/build-module/components/block-styles/utils.js.map +1 -1
- package/build-module/components/block-switcher/block-styles-menu.js +3 -21
- package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +11 -1
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/button-block-appender/index.js +2 -1
- package/build-module/components/button-block-appender/index.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +54 -13
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/default-block-appender/index.js +15 -18
- package/build-module/components/default-block-appender/index.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +17 -3
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/iframe/index.js +3 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +2 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/default-block-appender.js +2 -4
- package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
- package/build-module/components/inserter/index.native.js +2 -2
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +7 -4
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
- package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +3 -5
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +1 -3
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +6 -6
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +22 -3
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +2 -0
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +2 -0
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/rich-text/file-paste-handler.js +1 -1
- package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
- package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
- package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +2 -1
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/selection-scroll-into-view/index.js +2 -1
- package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
- package/build-module/components/use-display-block-controls/index.native.js +34 -0
- package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
- package/build-module/components/use-on-block-drop/index.js +7 -3
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +3 -4
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/hooks/border-color.js +61 -7
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border-radius.js +42 -0
- package/build-module/hooks/border-radius.js.map +1 -1
- package/build-module/hooks/border-style.js +36 -0
- package/build-module/hooks/border-style.js.map +1 -1
- package/build-module/hooks/border-width.js +66 -32
- package/build-module/hooks/border-width.js.map +1 -1
- package/build-module/hooks/border.js +80 -12
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/letter-spacing.js +1 -1
- package/build-module/hooks/letter-spacing.js.map +1 -1
- package/build-module/hooks/typography.js +1 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/store/actions.js +1 -2
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/selectors.js +24 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/get-paste-event-data.js +1 -1
- package/build-module/utils/get-paste-event-data.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +1 -1
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +226 -180
- package/build-style/style.css +226 -180
- package/package.json +27 -27
- package/src/components/block-caption/index.native.js +22 -4
- package/src/components/block-inspector/index.js +14 -17
- package/src/components/block-list-appender/index.js +5 -21
- package/src/components/block-preview/auto.js +7 -2
- package/src/components/block-preview/index.js +60 -0
- package/src/components/block-preview/style.scss +23 -0
- package/src/components/block-preview/test/index.js +114 -0
- package/src/components/block-settings/container.native.js +1 -0
- package/src/components/block-styles/index.js +125 -145
- package/src/components/block-styles/menu-items.js +49 -0
- package/src/components/block-styles/preview-panel.js +36 -0
- package/src/components/block-styles/style.scss +59 -51
- package/src/components/block-styles/test/{index.js → utils.js} +60 -1
- package/src/components/block-styles/use-styles-for-block.js +99 -0
- package/src/components/block-styles/utils.js +39 -0
- package/src/components/block-switcher/block-styles-menu.js +3 -38
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +10 -1
- package/src/components/border-style-control/style.scss +0 -1
- package/src/components/button-block-appender/index.js +1 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +75 -19
- package/src/components/colors-gradients/style.scss +42 -5
- package/src/components/default-block-appender/index.js +17 -24
- package/src/components/default-block-appender/style.scss +4 -0
- package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
- package/src/components/default-block-appender/test/index.js +4 -14
- package/src/components/default-style-picker/index.js +18 -6
- package/src/components/iframe/index.js +6 -3
- package/src/components/index.js +5 -2
- package/src/components/inner-blocks/README.md +2 -0
- package/src/components/inner-blocks/default-block-appender.js +2 -7
- package/src/components/inserter/index.native.js +2 -2
- package/src/components/inserter/tabs.native.js +5 -4
- package/src/components/inspector-controls/block-support-slot-container.js +3 -1
- package/src/components/inspector-controls/fill.native.js +4 -3
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls/slot.js +2 -7
- package/src/components/letter-spacing-control/index.js +6 -6
- package/src/components/link-control/README.md +1 -1
- package/src/components/link-control/test/index.js +2 -0
- package/src/components/list-view/block-select-button.js +20 -1
- package/src/components/media-placeholder/index.js +2 -0
- package/src/components/media-replace-flow/index.js +2 -0
- package/src/components/rich-text/file-paste-handler.js +3 -1
- package/src/components/rich-text/prevent-event-discovery.js +23 -0
- package/src/components/rich-text/use-input-rules.js +2 -1
- package/src/components/selection-scroll-into-view/index.js +1 -0
- package/src/components/url-input/README.md +5 -0
- package/src/components/use-display-block-controls/index.native.js +38 -0
- package/src/components/use-on-block-drop/index.js +7 -3
- package/src/components/writing-flow/test/use-multi-selection.js +36 -0
- package/src/components/writing-flow/use-multi-selection.js +12 -9
- package/src/hooks/border-color.js +55 -3
- package/src/hooks/border-radius.js +32 -0
- package/src/hooks/border-style.js +26 -0
- package/src/hooks/border-width.js +56 -32
- package/src/hooks/border.js +115 -20
- package/src/hooks/border.scss +3 -17
- package/src/hooks/dimensions.scss +5 -0
- package/src/hooks/letter-spacing.js +1 -1
- package/src/hooks/typography.js +1 -1
- package/src/store/actions.js +1 -2
- package/src/store/defaults.js +2 -0
- package/src/store/selectors.js +37 -7
- package/src/style.scss +4 -3
- package/src/utils/get-paste-event-data.js +1 -1
- package/src/utils/parse-css-unit-to-px.js +1 -1
- package/src/utils/test/parse-css-unit-to-px.js +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/use-canvas-click-redirect/index.js +0 -66
- package/build/components/use-canvas-click-redirect/index.js.map +0 -1
- package/build-module/components/use-canvas-click-redirect/index.js +0 -54
- package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
- package/src/components/use-canvas-click-redirect/index.js +0 -57
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import InserterPreviewPanel from '../inserter/preview-panel';
|
|
10
|
+
import { replaceActiveStyle } from './utils';
|
|
11
|
+
|
|
12
|
+
export default function BlockStylesPreviewPanel( {
|
|
13
|
+
genericPreviewBlock,
|
|
14
|
+
style,
|
|
15
|
+
className,
|
|
16
|
+
activeStyle,
|
|
17
|
+
} ) {
|
|
18
|
+
const styleClassName = replaceActiveStyle( className, activeStyle, style );
|
|
19
|
+
const previewBlocks = useMemo( () => {
|
|
20
|
+
return {
|
|
21
|
+
...genericPreviewBlock,
|
|
22
|
+
title: style.label || style.name,
|
|
23
|
+
description: style.description,
|
|
24
|
+
initialAttributes: {
|
|
25
|
+
...genericPreviewBlock.attributes,
|
|
26
|
+
className:
|
|
27
|
+
styleClassName +
|
|
28
|
+
' block-editor-block-styles__block-preview-container',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}, [ genericPreviewBlock, styleClassName ] );
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<InserterPreviewPanel item={ previewBlocks } isStylePreview={ true } />
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -1,67 +1,75 @@
|
|
|
1
|
-
.block-editor-block-styles {
|
|
2
|
-
|
|
3
|
-
flex-wrap: wrap;
|
|
4
|
-
justify-content: space-between;
|
|
1
|
+
.block-editor-block-styles + .default-style-picker__default-switcher {
|
|
2
|
+
margin-top: $grid-unit-20;
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
.block-editor-block-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
padding: $grid-unit-05 * 1.5;
|
|
15
|
-
display: flex;
|
|
16
|
-
flex-direction: column;
|
|
17
|
-
|
|
18
|
-
&:focus {
|
|
19
|
-
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
5
|
+
.block-editor-block-styles__preview-panel {
|
|
6
|
+
display: none;
|
|
7
|
+
position: absolute;
|
|
8
|
+
right: $grid-unit-20;
|
|
9
|
+
left: auto;
|
|
10
|
+
// Same layer as the sidebar from which it's triggered.
|
|
11
|
+
z-index: z-index(".interface-interface-skeleton__sidebar {greater than small}");
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
// Only show in narrow widths.
|
|
14
|
+
@include break-medium() {
|
|
15
|
+
display: block;
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
// Overrides for InserterPreviewPanel.
|
|
19
|
+
.block-editor-inserter__preview-container {
|
|
20
|
+
left: auto;
|
|
21
|
+
right: auto;
|
|
22
|
+
top: auto;
|
|
23
|
+
position: static;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
font-weight: bold;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.block-editor-block-styles__item-preview {
|
|
35
|
-
margin: 0;
|
|
36
|
-
border: 2px solid $gray-900;
|
|
37
|
-
}
|
|
26
|
+
.block-editor-block-card__title.block-editor-block-card__title {
|
|
27
|
+
margin: 0;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
cursor: inherit;
|
|
29
|
+
.block-editor-block-icon {
|
|
30
|
+
display: none;
|
|
42
31
|
}
|
|
43
32
|
}
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
.block-editor-block-styles__item-preview {
|
|
47
|
-
outline: $border-width solid transparent; // Shown in Windows High Contrast mode.
|
|
48
|
-
padding: 0;
|
|
49
|
-
margin: 2px;
|
|
50
|
-
border-radius: $radius-block-ui;
|
|
34
|
+
.block-editor-block-styles__variants {
|
|
51
35
|
display: flex;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
flex-wrap: wrap;
|
|
37
|
+
justify-content: space-between;
|
|
38
|
+
gap: $grid-unit-10;
|
|
39
|
+
|
|
40
|
+
.block-editor-block-styles__item {
|
|
41
|
+
color: $gray-800;
|
|
42
|
+
box-shadow: inset 0 0 0 1px $gray-400;
|
|
43
|
+
display: inline-block;
|
|
44
|
+
width: calc(50% - #{$grid-unit-05});
|
|
45
|
+
|
|
46
|
+
&:focus,
|
|
47
|
+
&:hover {
|
|
48
|
+
color: var(--wp-admin-theme-color);
|
|
49
|
+
box-shadow: inset 0 0 0 2px var(--wp-admin-theme-color);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&.is-active,
|
|
53
|
+
&.is-active:hover {
|
|
54
|
+
background-color: $gray-800;
|
|
55
|
+
box-shadow: none;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&.is-active .block-editor-block-styles__item-text,
|
|
59
|
+
&.is-active:hover .block-editor-block-styles__item-text {
|
|
60
|
+
color: $white;
|
|
61
|
+
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
&.is-active:focus {
|
|
64
|
+
box-shadow: inset 0 0 0 1px $white, 0 0 0 2px var(--wp-admin-theme-color);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
// To prevent overflow in the preview container,
|
|
70
|
+
// ensure that block contents' margin and padding
|
|
71
|
+
// do not add to the block container's width.
|
|
72
|
+
.block-editor-block-styles__block-preview-container,
|
|
73
|
+
.block-editor-block-styles__block-preview-container * {
|
|
74
|
+
box-sizing: border-box !important;
|
|
67
75
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getActiveStyle,
|
|
6
|
+
getDefaultStyle,
|
|
7
|
+
getRenderedStyles,
|
|
8
|
+
replaceActiveStyle,
|
|
9
|
+
} from '../utils';
|
|
5
10
|
|
|
6
11
|
describe( 'getActiveStyle', () => {
|
|
7
12
|
it( 'Should return the undefined if no active style', () => {
|
|
@@ -74,3 +79,57 @@ describe( 'replaceActiveStyle', () => {
|
|
|
74
79
|
);
|
|
75
80
|
} );
|
|
76
81
|
} );
|
|
82
|
+
|
|
83
|
+
describe( 'getRenderedStyles', () => {
|
|
84
|
+
it( 'Should return an empty array if styles is falsy', () => {
|
|
85
|
+
expect( getRenderedStyles( null ) ).toEqual( [] );
|
|
86
|
+
} );
|
|
87
|
+
|
|
88
|
+
it( 'Should return an empty array if styles array is empty', () => {
|
|
89
|
+
expect( getRenderedStyles( [] ) ).toEqual( [] );
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
it( 'Should return styles collection if there is a default', () => {
|
|
93
|
+
const styles = [
|
|
94
|
+
{ name: 'hazlenut' },
|
|
95
|
+
{ name: 'cashew', isDefault: true },
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
expect( getRenderedStyles( styles ) ).toEqual( styles );
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
it( 'Should add a default item to the styles collection if there is no default', () => {
|
|
102
|
+
const styles = [ { name: 'pistachio' }, { name: 'peanut' } ];
|
|
103
|
+
const defaultStyle = {
|
|
104
|
+
name: 'default',
|
|
105
|
+
label: 'Default',
|
|
106
|
+
isDefault: true,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
expect( getRenderedStyles( styles ) ).toEqual( [
|
|
110
|
+
defaultStyle,
|
|
111
|
+
...styles,
|
|
112
|
+
] );
|
|
113
|
+
} );
|
|
114
|
+
} );
|
|
115
|
+
|
|
116
|
+
describe( 'getDefaultStyle', () => {
|
|
117
|
+
it( 'Should return default style object', () => {
|
|
118
|
+
const styles = [
|
|
119
|
+
{ name: 'trout' },
|
|
120
|
+
{ name: 'bream', isDefault: true },
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
expect( getDefaultStyle( styles ) ).toEqual( styles[ 1 ] );
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
it( 'Should return `undefined` if there is no default', () => {
|
|
127
|
+
const styles = [ { name: 'snapper' }, { name: 'perch' } ];
|
|
128
|
+
|
|
129
|
+
expect( getDefaultStyle( styles ) ).toBeUndefined();
|
|
130
|
+
} );
|
|
131
|
+
|
|
132
|
+
it( 'Should return `undefined` if `styles` argument is no passed', () => {
|
|
133
|
+
expect( getDefaultStyle() ).toBeUndefined();
|
|
134
|
+
} );
|
|
135
|
+
} );
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
+
import {
|
|
6
|
+
cloneBlock,
|
|
7
|
+
getBlockType,
|
|
8
|
+
getBlockFromExample,
|
|
9
|
+
store as blocksStore,
|
|
10
|
+
} from '@wordpress/blocks';
|
|
11
|
+
import { useMemo } from '@wordpress/element';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { getActiveStyle, getRenderedStyles, replaceActiveStyle } from './utils';
|
|
17
|
+
import { store as blockEditorStore } from '../../store';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {WPBlock} block Block object.
|
|
22
|
+
* @param {WPBlockType} type Block type settings.
|
|
23
|
+
* @return {WPBlock} A generic block ready for styles preview.
|
|
24
|
+
*/
|
|
25
|
+
function useGenericPreviewBlock( block, type ) {
|
|
26
|
+
return useMemo( () => {
|
|
27
|
+
const example = type?.example;
|
|
28
|
+
const blockName = type?.name;
|
|
29
|
+
|
|
30
|
+
if ( example && blockName ) {
|
|
31
|
+
return getBlockFromExample( blockName, {
|
|
32
|
+
attributes: example.attributes,
|
|
33
|
+
innerBlocks: example.innerBlocks,
|
|
34
|
+
} );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ( block ) {
|
|
38
|
+
return cloneBlock( block );
|
|
39
|
+
}
|
|
40
|
+
}, [ type?.example ? block?.name : block, type ] );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef useStylesForBlocksArguments
|
|
45
|
+
* @property {string} clientId Block client ID.
|
|
46
|
+
* @property {() => void} onSwitch Block style switch callback function.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {useStylesForBlocksArguments} useStylesForBlocks arguments.
|
|
52
|
+
* @return {Object} Results of the select methods.
|
|
53
|
+
*/
|
|
54
|
+
export default function useStylesForBlocks( { clientId, onSwitch } ) {
|
|
55
|
+
const selector = ( select ) => {
|
|
56
|
+
const { getBlock } = select( blockEditorStore );
|
|
57
|
+
const block = getBlock( clientId );
|
|
58
|
+
|
|
59
|
+
if ( ! block ) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
const blockType = getBlockType( block.name );
|
|
63
|
+
const { getBlockStyles } = select( blocksStore );
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
block,
|
|
67
|
+
blockType,
|
|
68
|
+
styles: getBlockStyles( block.name ),
|
|
69
|
+
className: block.attributes.className || '',
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const { styles, block, blockType, className } = useSelect( selector, [
|
|
73
|
+
clientId,
|
|
74
|
+
] );
|
|
75
|
+
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
76
|
+
const stylesToRender = getRenderedStyles( styles );
|
|
77
|
+
const activeStyle = getActiveStyle( stylesToRender, className );
|
|
78
|
+
const genericPreviewBlock = useGenericPreviewBlock( block, blockType );
|
|
79
|
+
|
|
80
|
+
const onSelect = ( style ) => {
|
|
81
|
+
const styleClassName = replaceActiveStyle(
|
|
82
|
+
className,
|
|
83
|
+
activeStyle,
|
|
84
|
+
style
|
|
85
|
+
);
|
|
86
|
+
updateBlockAttributes( clientId, {
|
|
87
|
+
className: styleClassName,
|
|
88
|
+
} );
|
|
89
|
+
onSwitch();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
onSelect,
|
|
94
|
+
stylesToRender,
|
|
95
|
+
activeStyle,
|
|
96
|
+
genericPreviewBlock,
|
|
97
|
+
className,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -6,6 +6,7 @@ import { find } from 'lodash';
|
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
8
|
import TokenList from '@wordpress/token-list';
|
|
9
|
+
import { _x } from '@wordpress/i18n';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Returns the active style from the given className.
|
|
@@ -51,3 +52,41 @@ export function replaceActiveStyle( className, activeStyle, newStyle ) {
|
|
|
51
52
|
|
|
52
53
|
return list.value;
|
|
53
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a collection of styles that can be represented on the frontend.
|
|
58
|
+
* The function checks a style collection for a default style. If none is found, it adds one to
|
|
59
|
+
* act as a fallback for when there is no active style applied to a block. The default item also serves
|
|
60
|
+
* as a switch on the frontend to deactivate non-default styles.
|
|
61
|
+
*
|
|
62
|
+
* @param {Array} styles Block style variations.
|
|
63
|
+
*
|
|
64
|
+
* @return {Array<Object?>} The style collection.
|
|
65
|
+
*/
|
|
66
|
+
export function getRenderedStyles( styles ) {
|
|
67
|
+
if ( ! styles || styles.length === 0 ) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return getDefaultStyle( styles )
|
|
72
|
+
? styles
|
|
73
|
+
: [
|
|
74
|
+
{
|
|
75
|
+
name: 'default',
|
|
76
|
+
label: _x( 'Default', 'block style' ),
|
|
77
|
+
isDefault: true,
|
|
78
|
+
},
|
|
79
|
+
...styles,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns a style object from a collection of styles where that style object is the default block style.
|
|
85
|
+
*
|
|
86
|
+
* @param {Array} styles Block style variations.
|
|
87
|
+
*
|
|
88
|
+
* @return {Object?} The default style object, if found.
|
|
89
|
+
*/
|
|
90
|
+
export function getDefaultStyle( styles ) {
|
|
91
|
+
return find( styles, 'isDefault' );
|
|
92
|
+
}
|
|
@@ -3,56 +3,21 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { MenuGroup } from '@wordpress/components';
|
|
6
|
-
import { useState } from '@wordpress/element';
|
|
7
|
-
import { useSelect } from '@wordpress/data';
|
|
8
|
-
import {
|
|
9
|
-
cloneBlock,
|
|
10
|
-
getBlockFromExample,
|
|
11
|
-
store as blocksStore,
|
|
12
|
-
} from '@wordpress/blocks';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* Internal dependencies
|
|
16
9
|
*/
|
|
17
|
-
import
|
|
18
|
-
import PreviewBlockPopover from './preview-block-popover';
|
|
10
|
+
import BlockStylesMenuItems from '../block-styles/menu-items';
|
|
19
11
|
|
|
20
12
|
export default function BlockStylesMenu( { hoveredBlock, onSwitch } ) {
|
|
21
|
-
const {
|
|
22
|
-
const [ hoveredClassName, setHoveredClassName ] = useState();
|
|
23
|
-
const blockType = useSelect(
|
|
24
|
-
( select ) => select( blocksStore ).getBlockType( name ),
|
|
25
|
-
[ name ]
|
|
26
|
-
);
|
|
13
|
+
const { clientId } = hoveredBlock;
|
|
27
14
|
|
|
28
15
|
return (
|
|
29
16
|
<MenuGroup
|
|
30
17
|
label={ __( 'Styles' ) }
|
|
31
18
|
className="block-editor-block-switcher__styles__menugroup"
|
|
32
19
|
>
|
|
33
|
-
{
|
|
34
|
-
<PreviewBlockPopover
|
|
35
|
-
blocks={
|
|
36
|
-
blockType && blockType.example
|
|
37
|
-
? getBlockFromExample( blockType.name, {
|
|
38
|
-
attributes: {
|
|
39
|
-
...blockType.example.attributes,
|
|
40
|
-
className: hoveredClassName,
|
|
41
|
-
},
|
|
42
|
-
innerBlocks: blockType.example.innerBlocks,
|
|
43
|
-
} )
|
|
44
|
-
: cloneBlock( hoveredBlock, {
|
|
45
|
-
className: hoveredClassName,
|
|
46
|
-
} )
|
|
47
|
-
}
|
|
48
|
-
/>
|
|
49
|
-
) }
|
|
50
|
-
<BlockStyles
|
|
51
|
-
clientId={ clientId }
|
|
52
|
-
onSwitch={ onSwitch }
|
|
53
|
-
onHoverClassName={ setHoveredClassName }
|
|
54
|
-
itemRole="menuitem"
|
|
55
|
-
/>
|
|
20
|
+
<BlockStylesMenuItems clientId={ clientId } onSwitch={ onSwitch } />
|
|
56
21
|
</MenuGroup>
|
|
57
22
|
);
|
|
58
23
|
}
|
|
@@ -32,7 +32,7 @@ function InsertionPointPopover( {
|
|
|
32
32
|
__unstablePopoverSlot,
|
|
33
33
|
__unstableContentRef,
|
|
34
34
|
} ) {
|
|
35
|
-
const { selectBlock } = useDispatch( blockEditorStore );
|
|
35
|
+
const { selectBlock, hideInsertionPoint } = useDispatch( blockEditorStore );
|
|
36
36
|
const openRef = useContext( InsertionPointOpenRef );
|
|
37
37
|
const ref = useRef();
|
|
38
38
|
const {
|
|
@@ -195,6 +195,14 @@ function InsertionPointPopover( {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
function maybeHideInserterPoint( event ) {
|
|
199
|
+
// Only hide the inserter if it's triggered on the wrapper,
|
|
200
|
+
// and the inserter is not open.
|
|
201
|
+
if ( event.target === ref.current && ! openRef.current ) {
|
|
202
|
+
hideInsertionPoint();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
198
206
|
// Only show the in-between inserter between blocks, so when there's a
|
|
199
207
|
// previous and a next element.
|
|
200
208
|
const showInsertionPointInserter =
|
|
@@ -309,6 +317,7 @@ function InsertionPointPopover( {
|
|
|
309
317
|
className={ classnames( className, {
|
|
310
318
|
'is-with-inserter': showInsertionPointInserter,
|
|
311
319
|
} ) }
|
|
320
|
+
onHoverEnd={ maybeHideInserterPoint }
|
|
312
321
|
style={ style }
|
|
313
322
|
>
|
|
314
323
|
<motion.div
|
|
@@ -90,6 +90,7 @@ function ButtonBlockAppender(
|
|
|
90
90
|
export const ButtonBlockerAppender = forwardRef( ( props, ref ) => {
|
|
91
91
|
deprecated( `wp.blockEditor.ButtonBlockerAppender`, {
|
|
92
92
|
alternative: 'wp.blockEditor.ButtonBlockAppender',
|
|
93
|
+
since: '5.9',
|
|
93
94
|
} );
|
|
94
95
|
|
|
95
96
|
return ButtonBlockAppender( props, ref );
|
|
@@ -7,8 +7,17 @@ import { every, isEmpty } from 'lodash';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
__experimentalItemGroup as ItemGroup,
|
|
12
|
+
__experimentalItem as Item,
|
|
13
|
+
__experimentalHStack as HStack,
|
|
14
|
+
__experimentalSpacer as Spacer,
|
|
15
|
+
FlexItem,
|
|
16
|
+
ColorIndicator,
|
|
17
|
+
PanelBody,
|
|
18
|
+
Dropdown,
|
|
19
|
+
} from '@wordpress/components';
|
|
20
|
+
import { sprintf, __, isRTL } from '@wordpress/i18n';
|
|
12
21
|
|
|
13
22
|
/**
|
|
14
23
|
* Internal dependencies
|
|
@@ -127,6 +136,13 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
127
136
|
</span>
|
|
128
137
|
);
|
|
129
138
|
|
|
139
|
+
let dropdownPosition;
|
|
140
|
+
let popoverProps;
|
|
141
|
+
if ( __experimentalIsRenderedInSidebar ) {
|
|
142
|
+
dropdownPosition = isRTL() ? 'bottom right' : 'bottom left';
|
|
143
|
+
popoverProps = { __unstableForcePosition: true };
|
|
144
|
+
}
|
|
145
|
+
|
|
130
146
|
return (
|
|
131
147
|
<PanelBody
|
|
132
148
|
className={ classnames(
|
|
@@ -136,23 +152,63 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
136
152
|
title={ showTitle ? titleElement : undefined }
|
|
137
153
|
{ ...props }
|
|
138
154
|
>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
<ItemGroup
|
|
156
|
+
isBordered
|
|
157
|
+
isSeparated
|
|
158
|
+
className="block-editor-panel-color-gradient-settings__item-group"
|
|
159
|
+
>
|
|
160
|
+
{ settings.map( ( setting, index ) => (
|
|
161
|
+
<Dropdown
|
|
162
|
+
position={ dropdownPosition }
|
|
163
|
+
popoverProps={ popoverProps }
|
|
164
|
+
className="block-editor-panel-color-gradient-settings__dropdown"
|
|
165
|
+
key={ index }
|
|
166
|
+
contentClassName="block-editor-panel-color-gradient-settings__dropdown-content"
|
|
167
|
+
renderToggle={ ( { isOpen, onToggle } ) => {
|
|
168
|
+
return (
|
|
169
|
+
<Item
|
|
170
|
+
onClick={ onToggle }
|
|
171
|
+
className={ classnames(
|
|
172
|
+
'block-editor-panel-color-gradient-settings__item',
|
|
173
|
+
{ 'is-open': isOpen }
|
|
174
|
+
) }
|
|
175
|
+
>
|
|
176
|
+
<HStack justify="flex-start">
|
|
177
|
+
<ColorIndicator
|
|
178
|
+
className="block-editor-panel-color-gradient-settings__color-indicator"
|
|
179
|
+
colorValue={
|
|
180
|
+
setting.gradientValue ??
|
|
181
|
+
setting.colorValue
|
|
182
|
+
}
|
|
183
|
+
/>
|
|
184
|
+
<FlexItem>{ setting.label }</FlexItem>
|
|
185
|
+
</HStack>
|
|
186
|
+
</Item>
|
|
187
|
+
);
|
|
188
|
+
} }
|
|
189
|
+
renderContent={ () => (
|
|
190
|
+
<ColorGradientControl
|
|
191
|
+
showTitle={ false }
|
|
192
|
+
{ ...{
|
|
193
|
+
colors,
|
|
194
|
+
gradients,
|
|
195
|
+
disableCustomColors,
|
|
196
|
+
disableCustomGradients,
|
|
197
|
+
__experimentalHasMultipleOrigins,
|
|
198
|
+
__experimentalIsRenderedInSidebar,
|
|
199
|
+
enableAlpha,
|
|
200
|
+
...setting,
|
|
201
|
+
} }
|
|
202
|
+
/>
|
|
203
|
+
) }
|
|
204
|
+
/>
|
|
205
|
+
) ) }
|
|
206
|
+
</ItemGroup>
|
|
207
|
+
{ !! children && (
|
|
208
|
+
<>
|
|
209
|
+
<Spacer marginY={ 4 } /> { children }
|
|
210
|
+
</>
|
|
211
|
+
) }
|
|
156
212
|
</PanelBody>
|
|
157
213
|
);
|
|
158
214
|
};
|
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
.block-editor-panel-color-gradient-settings {
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
.block-editor-panel-color-gradient-settings__panel-title {
|
|
9
|
+
display: flex;
|
|
10
|
+
gap: $grid-unit-15;
|
|
11
11
|
|
|
12
|
-
&__panel-title {
|
|
13
12
|
.component-color-indicator {
|
|
14
|
-
|
|
13
|
+
width: $grid-unit-15;
|
|
14
|
+
height: $grid-unit-15;
|
|
15
|
+
align-self: center;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -37,4 +38,40 @@
|
|
|
37
38
|
.block-editor-block-inspector & .components-base-control {
|
|
38
39
|
margin-bottom: inherit;
|
|
39
40
|
}
|
|
41
|
+
|
|
42
|
+
.block-editor-panel-color-gradient-settings__dropdown {
|
|
43
|
+
display: block;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.block-editor-panel-color-gradient-settings__dropdown-content .components-popover__content {
|
|
48
|
+
& > div {
|
|
49
|
+
width: $sidebar-width;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@include break-medium() {
|
|
54
|
+
.block-editor-panel-color-gradient-settings__dropdown-content .components-popover__content {
|
|
55
|
+
margin-right: #{ math.div($sidebar-width, 2) + $grid-unit-20 } !important;
|
|
56
|
+
margin-top: #{ -($grid-unit-60 + $grid-unit-15) } !important;
|
|
57
|
+
}
|
|
40
58
|
}
|
|
59
|
+
|
|
60
|
+
.block-editor-panel-color-gradient-settings__dropdown:last-child > div {
|
|
61
|
+
border-bottom-width: 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.block-editor-panel-color-gradient-settings__item {
|
|
65
|
+
padding-top: $grid-unit-15 !important;
|
|
66
|
+
padding-bottom: $grid-unit-15 !important;
|
|
67
|
+
.block-editor-panel-color-gradient-settings__color-indicator {
|
|
68
|
+
// Show a diagonal line (crossed out) for empty swatches.
|
|
69
|
+
background: linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
&.is-open {
|
|
73
|
+
background: $gray-100;
|
|
74
|
+
color: var(--wp-admin-theme-color);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|