@wordpress/block-editor 10.1.1-next.4d3b314fd5.0 → 10.3.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/CHANGELOG.md +14 -0
- package/README.md +41 -0
- package/build/components/block-controls/slot.js +2 -2
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.js +4 -2
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -5
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-compact.native.js +1 -0
- package/build/components/block-list/block-list-compact.native.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +79 -12
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -23
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +9 -6
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +5 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +5 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/drop-zone.js +85 -0
- package/build/components/block-popover/drop-zone.js.map +1 -0
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +22 -17
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +6 -9
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-preview/live.js +3 -7
- package/build/components/block-preview/live.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +9 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -16
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +18 -42
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -4
- package/build/components/block-toolbar/index.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 +50 -20
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +15 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +256 -0
- package/build/components/font-sizes/fluid-utils.js.map +1 -0
- package/build/components/font-sizes/index.js +8 -0
- package/build/components/font-sizes/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +151 -78
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +1 -1
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/menu.js +14 -3
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-items.js +2 -17
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +4 -2
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +2 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/preview-options/index.js +2 -3
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.js +17 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +40 -9
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +98 -57
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +12 -12
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/types.js +6 -0
- package/build/components/use-on-block-drop/types.js.map +1 -0
- package/build/hooks/align.js +1 -3
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/align.native.js +1 -7
- package/build/hooks/align.native.js.map +1 -1
- package/build/hooks/font-size.js +60 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/margin.js +6 -5
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +2 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +126 -4
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-typography-props.js +17 -3
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/store/actions.js +59 -45
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +3 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +36 -18
- package/build/store/reducer.js.map +1 -1
- package/build/utils/math.js +14 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/pre-parse-patterns.js +19 -2
- package/build/utils/pre-parse-patterns.js.map +1 -1
- package/build-module/components/block-controls/slot.js +3 -3
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +7 -3
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -6
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-compact.native.js +1 -0
- package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +80 -13
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +8 -24
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +10 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +5 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/drop-zone.js +70 -0
- package/build-module/components/block-popover/drop-zone.js.map +1 -0
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +22 -17
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +6 -9
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-preview/live.js +3 -6
- package/build-module/components/block-preview/live.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +9 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +25 -19
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +19 -44
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +4 -4
- package/build-module/components/block-toolbar/index.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 +48 -20
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +15 -3
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +245 -0
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
- package/build-module/components/font-sizes/index.js +1 -0
- package/build-module/components/font-sizes/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +148 -81
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +10 -3
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -17
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +3 -2
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -3
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +17 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +40 -10
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +98 -58
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +12 -12
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/types.js +2 -0
- package/build-module/components/use-on-block-drop/types.js.map +1 -0
- package/build-module/hooks/align.js +1 -2
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/align.native.js +1 -6
- package/build-module/hooks/align.native.js.map +1 -1
- package/build-module/hooks/font-size.js +59 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/margin.js +6 -5
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +2 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +124 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +17 -4
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/store/actions.js +55 -42
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +3 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +36 -19
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/pre-parse-patterns.js +19 -2
- package/build-module/utils/pre-parse-patterns.js.map +1 -1
- package/build-style/style-rtl.css +256 -152
- package/build-style/style.css +256 -152
- package/package.json +28 -29
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-controls/slot.js +3 -3
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -11
- package/src/components/block-list/block-list-compact.native.js +1 -0
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/block.native.js +123 -9
- package/src/components/block-list/style.scss +93 -126
- package/src/components/block-list/use-in-between-inserter.js +8 -19
- package/src/components/block-lock/modal.js +12 -7
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-parent-selector/index.js +5 -5
- package/src/components/block-patterns-list/index.js +9 -5
- package/src/components/block-patterns-list/style.scss +7 -3
- package/src/components/block-popover/README.md +8 -0
- package/src/components/block-popover/drop-zone.js +63 -0
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +39 -22
- package/src/components/block-popover/style.scss +17 -1
- package/src/components/block-preview/auto.js +1 -1
- package/src/components/block-preview/index.js +7 -8
- package/src/components/block-preview/live.js +2 -7
- package/src/components/block-preview/test/index.js +1 -7
- package/src/components/block-selection-clearer/index.js +7 -2
- package/src/components/block-selection-clearer/test/index.js +118 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +32 -18
- package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
- package/src/components/block-styles/index.js +26 -49
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +104 -33
- package/src/components/block-switcher/test/index.js +121 -61
- package/src/components/block-toolbar/index.js +4 -6
- package/src/components/block-toolbar/style.scss +38 -14
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +42 -17
- package/src/components/block-tools/selected-block-popover.js +14 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +32 -52
- package/src/components/color-palette/test/control.js +11 -15
- package/src/components/colors-gradients/control.js +2 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
- package/src/components/colors-gradients/test/control.js +49 -77
- package/src/components/font-sizes/fluid-utils.js +296 -0
- package/src/components/font-sizes/index.js +1 -0
- package/src/components/font-sizes/test/fluid-utils.js +168 -0
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/image-size-control/test/index.js +47 -60
- package/src/components/index.js +0 -1
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/src/components/inserter/block-patterns-tab.js +232 -98
- package/src/components/inserter/block-types-tab.js +3 -3
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/inspector-controls/slot.js +6 -2
- package/src/components/link-control/test/index.js +1 -1
- package/src/components/list-view/use-list-view-drop-zone.js +4 -18
- package/src/components/panel-color-settings/test/index.js +4 -4
- package/src/components/preview-options/index.js +2 -2
- package/src/components/preview-options/style.scss +1 -1
- package/src/components/provider/test/use-block-sync.js +131 -165
- package/src/components/responsive-block-control/test/index.js +77 -122
- package/src/components/rich-text/index.js +22 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +24 -9
- package/src/components/spacing-sizes-control/style.scss +42 -31
- package/src/components/use-block-drop-zone/index.js +136 -79
- package/src/components/use-block-drop-zone/test/index.js +333 -81
- package/src/components/use-on-block-drop/index.js +11 -12
- package/src/components/use-on-block-drop/types.ts +1 -0
- package/src/hooks/align.js +3 -2
- package/src/hooks/align.native.js +5 -8
- package/src/hooks/font-size.js +75 -0
- package/src/hooks/margin.js +5 -4
- package/src/hooks/padding.js +1 -0
- package/src/hooks/style.js +122 -3
- package/src/hooks/test/style.js +206 -1
- package/src/hooks/test/use-typography-props.js +22 -0
- package/src/hooks/use-typography-props.js +18 -3
- package/src/hooks/utils.js +6 -2
- package/src/store/actions.js +20 -12
- package/src/store/defaults.js +3 -0
- package/src/store/reducer.js +35 -28
- package/src/store/test/actions.js +0 -9
- package/src/utils/math.js +17 -0
- package/src/utils/pre-parse-patterns.js +12 -7
- package/build/components/inserter/pattern-panel.js +0 -87
- package/build/components/inserter/pattern-panel.js.map +0 -1
- package/build-module/components/inserter/pattern-panel.js +0 -74
- package/build-module/components/inserter/pattern-panel.js.map +0 -1
- package/src/components/inserter/pattern-panel.js +0 -93
|
@@ -4,7 +4,6 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
/**
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
|
-
import { omit } from 'lodash';
|
|
8
7
|
import classnames from 'classnames';
|
|
9
8
|
/**
|
|
10
9
|
* WordPress dependencies
|
|
@@ -118,6 +117,128 @@ const skipSerializationPathsSave = { ...skipSerializationPathsEdit,
|
|
|
118
117
|
const renamedFeatures = {
|
|
119
118
|
gradients: 'gradient'
|
|
120
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* A utility function used to remove one or more paths from a style object.
|
|
122
|
+
* Works in a way similar to Lodash's `omit()`. See unit tests and examples below.
|
|
123
|
+
*
|
|
124
|
+
* It supports a single string path:
|
|
125
|
+
*
|
|
126
|
+
* ```
|
|
127
|
+
* omitStyle( { color: 'red' }, 'color' ); // {}
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* or an array of paths:
|
|
131
|
+
*
|
|
132
|
+
* ```
|
|
133
|
+
* omitStyle( { color: 'red', background: '#fff' }, [ 'color', 'background' ] ); // {}
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* It also allows you to specify paths at multiple levels in a string.
|
|
137
|
+
*
|
|
138
|
+
* ```
|
|
139
|
+
* omitStyle( { typography: { textDecoration: 'underline' } }, 'typography.textDecoration' ); // {}
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* You can remove multiple paths at the same time:
|
|
143
|
+
*
|
|
144
|
+
* ```
|
|
145
|
+
* omitStyle(
|
|
146
|
+
* {
|
|
147
|
+
* typography: {
|
|
148
|
+
* textDecoration: 'underline',
|
|
149
|
+
* textTransform: 'uppercase',
|
|
150
|
+
* }
|
|
151
|
+
* },
|
|
152
|
+
* [
|
|
153
|
+
* 'typography.textDecoration',
|
|
154
|
+
* 'typography.textTransform',
|
|
155
|
+
* ]
|
|
156
|
+
* );
|
|
157
|
+
* // {}
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* You can also specify nested paths as arrays:
|
|
161
|
+
*
|
|
162
|
+
* ```
|
|
163
|
+
* omitStyle(
|
|
164
|
+
* {
|
|
165
|
+
* typography: {
|
|
166
|
+
* textDecoration: 'underline',
|
|
167
|
+
* textTransform: 'uppercase',
|
|
168
|
+
* }
|
|
169
|
+
* },
|
|
170
|
+
* [
|
|
171
|
+
* [ 'typography', 'textDecoration' ],
|
|
172
|
+
* [ 'typography', 'textTransform' ],
|
|
173
|
+
* ]
|
|
174
|
+
* );
|
|
175
|
+
* // {}
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* With regards to nesting of styles, infinite depth is supported:
|
|
179
|
+
*
|
|
180
|
+
* ```
|
|
181
|
+
* omitStyle(
|
|
182
|
+
* {
|
|
183
|
+
* border: {
|
|
184
|
+
* radius: {
|
|
185
|
+
* topLeft: '10px',
|
|
186
|
+
* topRight: '0.5rem',
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* },
|
|
190
|
+
* [
|
|
191
|
+
* [ 'border', 'radius', 'topRight' ],
|
|
192
|
+
* ]
|
|
193
|
+
* );
|
|
194
|
+
* // { border: { radius: { topLeft: '10px' } } }
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* The third argument, `preserveReference`, defines how to treat the input style object.
|
|
198
|
+
* It is mostly necessary to properly handle mutation when recursively handling the style object.
|
|
199
|
+
* Defaulting to `false`, this will always create a new object, avoiding to mutate `style`.
|
|
200
|
+
* However, when recursing, we change that value to `true` in order to work with a single copy
|
|
201
|
+
* of the original style object.
|
|
202
|
+
*
|
|
203
|
+
* @see https://lodash.com/docs/4.17.15#omit
|
|
204
|
+
*
|
|
205
|
+
* @param {Object} style Styles object.
|
|
206
|
+
* @param {Array|string} paths Paths to remove.
|
|
207
|
+
* @param {boolean} preserveReference True to mutate the `style` object, false otherwise.
|
|
208
|
+
* @return {Object} Styles object with the specified paths removed.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
export function omitStyle(style, paths) {
|
|
212
|
+
let preserveReference = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
213
|
+
|
|
214
|
+
if (!style) {
|
|
215
|
+
return style;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let newStyle = style;
|
|
219
|
+
|
|
220
|
+
if (!preserveReference) {
|
|
221
|
+
newStyle = JSON.parse(JSON.stringify(style));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!Array.isArray(paths)) {
|
|
225
|
+
paths = [paths];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
paths.forEach(path => {
|
|
229
|
+
if (!Array.isArray(path)) {
|
|
230
|
+
path = path.split('.');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (path.length > 1) {
|
|
234
|
+
const [firstSubpath, ...restPath] = path;
|
|
235
|
+
omitStyle(newStyle[firstSubpath], [restPath], true);
|
|
236
|
+
} else if (path.length === 1) {
|
|
237
|
+
delete newStyle[path[0]];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return newStyle;
|
|
241
|
+
}
|
|
121
242
|
/**
|
|
122
243
|
* Override props assigned to save component to inject the CSS variables definition.
|
|
123
244
|
*
|
|
@@ -144,13 +265,13 @@ export function addSaveProps(props, blockType, attributes) {
|
|
|
144
265
|
const skipSerialization = getBlockSupport(blockType, indicator);
|
|
145
266
|
|
|
146
267
|
if (skipSerialization === true) {
|
|
147
|
-
style =
|
|
268
|
+
style = omitStyle(style, path);
|
|
148
269
|
}
|
|
149
270
|
|
|
150
271
|
if (Array.isArray(skipSerialization)) {
|
|
151
272
|
skipSerialization.forEach(featureName => {
|
|
152
273
|
const feature = renamedFeatures[featureName] || featureName;
|
|
153
|
-
style =
|
|
274
|
+
style = omitStyle(style, [[...path, feature]]);
|
|
154
275
|
});
|
|
155
276
|
}
|
|
156
277
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/style.js"],"names":["omit","classnames","useContext","useMemo","createPortal","addFilter","getBlockSupport","hasBlockSupport","__EXPERIMENTAL_ELEMENTS","ELEMENTS","createHigherOrderComponent","useInstanceId","getCSSRules","compileCSS","BlockList","BORDER_SUPPORT_KEY","BorderPanel","COLOR_SUPPORT_KEY","ColorEdit","TypographyPanel","TYPOGRAPHY_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEYS","SPACING_SUPPORT_KEY","DimensionsPanel","useDisplayBlockControls","shouldSkipSerialization","styleSupportKeys","hasStyleSupport","blockType","some","key","getInlineStyles","styles","output","forEach","rule","value","addAttribute","settings","attributes","style","Object","assign","type","skipSerializationPathsEdit","skipSerializationPathsSave","renamedFeatures","gradients","addSaveProps","props","skipPaths","entries","indicator","path","skipSerialization","Array","isArray","featureName","feature","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBlockControls","BlockEdit","shouldDisplayControls","withElementsStyles","BlockListBlock","blockElementsContainerIdentifier","skipLinkColorSerialization","name","rawElementsStyles","elements","elementCssRules","keys","length","filteredElementsStyles","link","color","undefined","elementName","elementStyles","cssRule","selector","push","element","__unstableElementContext","__html","className"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,EAAqBC,OAArB,EAA8BC,YAA9B,QAAkD,oBAAlD;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SACCC,eADD,EAECC,eAFD,EAGCC,uBAAuB,IAAIC,QAH5B,QAIO,mBAJP;AAKA,SAASC,0BAAT,EAAqCC,aAArC,QAA0D,oBAA1D;AACA,SAASC,WAAT,EAAsBC,UAAtB,QAAwC,yBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,0BAAtB;AACA,SAASC,kBAAT,EAA6BC,WAA7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3D,SAAjB,CAA1B;;AAMA,YAAK,CAAC,CAAEE,OAAR,EAAkB;AACjBT,UAAAA,eAAe,CAACW,IAAhB,CAAsBF,OAAtB;AACA;AACD;AACD;;AACD,WAAOT,eAAe,CAACE,MAAhB,GAAyB,CAAzB,GAA6BF,eAA7B,GAA+CM,SAAtD;AACA,GAjCqB,EAiCnB,2BAAE7B,KAAK,CAACV,UAAN,CAAiBC,KAAnB,2DAAE,uBAAwB+B,QAA1B,CAjCmB,CAAtB;AAmCA,QAAMa,OAAO,GAAGlF,UAAU,CAAEY,SAAS,CAACuE,wBAAZ,CAA1B;AAEA,SACC,8BACGrD,MAAM,IACPoD,OADC,IAEDhF,YAAY,CACX;AACC,IAAA,uBAAuB,EAAG;AACzBkF,MAAAA,MAAM,EAAEtD;AADiB;AAD3B,IADW,EAMXoD,OANW,CAHd,EAYC,cAAC,cAAD,eACMnC,KADN;AAEC,IAAA,SAAS,EACR,0BAAAA,KAAK,CAACV,UAAN,CAAiBC,KAAjB,0EAAwB+B,QAAxB,GACGtE,UAAU,CACVgD,KAAK,CAACsC,SADI,EAEVpB,gCAFU,CADb,GAKGlB,KAAK,CAACsC;AARX,KAZD,CADD;AA0BA,CA3EmD,CAArD;AA8EAlF,SAAS,CACR,0BADQ,EAER,yBAFQ,EAGRgC,YAHQ,CAAT;AAMAhC,SAAS,CACR,kCADQ,EAER,yBAFQ,EAGR2C,YAHQ,CAAT;AAMA3C,SAAS,CACR,0BADQ,EAER,yBAFQ,EAGRsD,YAHQ,CAAT;AAMAtD,SAAS,CACR,kBADQ,EAER,gCAFQ,EAGRyD,iBAHQ,CAAT;AAMAzD,SAAS,CACR,uBADQ,EAER,kCAFQ,EAGR4D,kBAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport { omit } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, createPortal } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\thasBlockSupport,\n\t__EXPERIMENTAL_ELEMENTS as ELEMENTS,\n} from '@wordpress/blocks';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { getCSSRules, compileCSS } from '@wordpress/style-engine';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport { BORDER_SUPPORT_KEY, BorderPanel } from './border';\nimport { COLOR_SUPPORT_KEY, ColorEdit } from './color';\nimport {\n\tTypographyPanel,\n\tTYPOGRAPHY_SUPPORT_KEY,\n\tTYPOGRAPHY_SUPPORT_KEYS,\n} from './typography';\nimport { SPACING_SUPPORT_KEY, DimensionsPanel } from './dimensions';\nimport useDisplayBlockControls from '../components/use-display-block-controls';\nimport { shouldSkipSerialization } from './utils';\n\nconst styleSupportKeys = [\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\nconst hasStyleSupport = ( blockType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( blockType, key ) );\n\n/**\n * Returns the inline styles to add depending on the style object\n *\n * @param {Object} styles Styles configuration.\n *\n * @return {Object} Flattened CSS variables declaration.\n */\nexport function getInlineStyles( styles = {} ) {\n\tconst output = {};\n\t// The goal is to move everything to server side generated engine styles\n\t// This is temporary as we absorb more and more styles into the engine.\n\tgetCSSRules( styles ).forEach( ( rule ) => {\n\t\toutput[ rule.key ] = rule.value;\n\t} );\n\n\treturn output;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `style` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttribute( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.style ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tstyle: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsEdit = {\n\t[ `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ 'border' ],\n\t[ `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tCOLOR_SUPPORT_KEY,\n\t],\n\t[ `${ TYPOGRAPHY_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t],\n\t[ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\t'spacing',\n\t],\n};\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * Extends the Edit skip paths to enable skipping additional paths in just\n * the Save component. This allows a block support to be serialized within the\n * editor, while using an alternate approach, such as server-side rendering, when\n * the support is saved.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsSave = {\n\t...skipSerializationPathsEdit,\n\t[ `${ SPACING_SUPPORT_KEY }` ]: [ 'spacing.blockGap' ],\n};\n\n/**\n * A dictionary used to normalize feature names between support flags, style\n * object properties and __experimentSkipSerialization configuration arrays.\n *\n * This allows not having to provide a migration for a support flag and possible\n * backwards compatibility bridges, while still achieving consistency between\n * the support flag and the skip serialization array.\n *\n * @constant\n * @type {Record<string, string>}\n */\nconst renamedFeatures = { gradients: 'gradient' };\n\n/**\n * Override props assigned to save component to inject the CSS variables definition.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @param {?Record<string, string[]>} skipPaths An object of keys and paths to skip serialization.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps(\n\tprops,\n\tblockType,\n\tattributes,\n\tskipPaths = skipSerializationPathsSave\n) {\n\tif ( ! hasStyleSupport( blockType ) ) {\n\t\treturn props;\n\t}\n\n\tlet { style } = attributes;\n\tObject.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {\n\t\tconst skipSerialization = getBlockSupport( blockType, indicator );\n\n\t\tif ( skipSerialization === true ) {\n\t\t\tstyle = omit( style, path );\n\t\t}\n\n\t\tif ( Array.isArray( skipSerialization ) ) {\n\t\t\tskipSerialization.forEach( ( featureName ) => {\n\t\t\t\tconst feature = renamedFeatures[ featureName ] || featureName;\n\t\t\t\tstyle = omit( style, [ [ ...path, feature ] ] );\n\t\t\t} );\n\t\t}\n\t} );\n\n\tprops.style = {\n\t\t...getInlineStyles( style ),\n\t\t...props.style,\n\t};\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to extend the block edit wrapper\n * to apply the desired styles and classnames properly.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object}.Filtered block settings.\n */\nexport function addEditProps( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps(\n\t\t\tprops,\n\t\t\tsettings,\n\t\t\tattributes,\n\t\t\tskipSerializationPathsEdit\n\t\t);\n\t};\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include new inspector controls for\n * all the custom styles configs.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst shouldDisplayControls = useDisplayBlockControls();\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldDisplayControls && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ColorEdit { ...props } />\n\t\t\t\t\t\t<TypographyPanel { ...props } />\n\t\t\t\t\t\t<BorderPanel { ...props } />\n\t\t\t\t\t\t<DimensionsPanel { ...props } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\n/**\n * Override the default block element to include elements styles.\n *\n * @param {Function} BlockListBlock Original component\n * @return {Function} Wrapped component\n */\nconst withElementsStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(\n\t\t\tBlockListBlock\n\t\t) }`;\n\n\t\tconst skipLinkColorSerialization = shouldSkipSerialization(\n\t\t\tprops.name,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t'link'\n\t\t);\n\n\t\tconst styles = useMemo( () => {\n\t\t\tconst rawElementsStyles = props.attributes.style?.elements;\n\t\t\tconst elementCssRules = [];\n\t\t\tif (\n\t\t\t\trawElementsStyles &&\n\t\t\t\tObject.keys( rawElementsStyles ).length > 0\n\t\t\t) {\n\t\t\t\t// Remove values based on whether serialization has been skipped for a specific style.\n\t\t\t\tconst filteredElementsStyles = {\n\t\t\t\t\t...rawElementsStyles,\n\t\t\t\t\tlink: {\n\t\t\t\t\t\t...rawElementsStyles.link,\n\t\t\t\t\t\tcolor: ! skipLinkColorSerialization\n\t\t\t\t\t\t\t? rawElementsStyles.link?.color\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tfor ( const [ elementName, elementStyles ] of Object.entries(\n\t\t\t\t\tfilteredElementsStyles\n\t\t\t\t) ) {\n\t\t\t\t\tconst cssRule = compileCSS( elementStyles, {\n\t\t\t\t\t\t// The .editor-styles-wrapper selector is required on elements styles. As it is\n\t\t\t\t\t\t// added to all other editor styles, not providing it causes reset and global\n\t\t\t\t\t\t// styles to override element styles because of higher specificity.\n\t\t\t\t\t\tselector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS[ elementName ] }`,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( !! cssRule ) {\n\t\t\t\t\t\telementCssRules.push( cssRule );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn elementCssRules.length > 0 ? elementCssRules : undefined;\n\t\t}, [ props.attributes.style?.elements ] );\n\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ styles &&\n\t\t\t\t\telement &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t\t__html: styles,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\n\t\t\t\t<BlockListBlock\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tprops.attributes.style?.elements\n\t\t\t\t\t\t\t? classnames(\n\t\t\t\t\t\t\t\t\tprops.className,\n\t\t\t\t\t\t\t\t\tblockElementsContainerIdentifier\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: props.className\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addAttribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/style/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/style/with-block-controls',\n\twithBlockControls\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/with-elements-styles',\n\twithElementsStyles\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/style.js"],"names":["classnames","useContext","useMemo","createPortal","addFilter","getBlockSupport","hasBlockSupport","__EXPERIMENTAL_ELEMENTS","ELEMENTS","createHigherOrderComponent","useInstanceId","getCSSRules","compileCSS","BlockList","BORDER_SUPPORT_KEY","BorderPanel","COLOR_SUPPORT_KEY","ColorEdit","TypographyPanel","TYPOGRAPHY_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEYS","SPACING_SUPPORT_KEY","DimensionsPanel","useDisplayBlockControls","shouldSkipSerialization","styleSupportKeys","hasStyleSupport","blockType","some","key","getInlineStyles","styles","output","forEach","rule","value","addAttribute","settings","attributes","style","Object","assign","type","skipSerializationPathsEdit","skipSerializationPathsSave","renamedFeatures","gradients","omitStyle","paths","preserveReference","newStyle","JSON","parse","stringify","Array","isArray","path","split","length","firstSubpath","restPath","addSaveProps","props","skipPaths","entries","indicator","skipSerialization","featureName","feature","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBlockControls","BlockEdit","shouldDisplayControls","withElementsStyles","BlockListBlock","blockElementsContainerIdentifier","skipLinkColorSerialization","name","rawElementsStyles","elements","elementCssRules","keys","filteredElementsStyles","link","color","undefined","elementName","elementStyles","cssRule","selector","push","element","__unstableElementContext","__html","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,EAAqBC,OAArB,EAA8BC,YAA9B,QAAkD,oBAAlD;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SACCC,eADD,EAECC,eAFD,EAGCC,uBAAuB,IAAIC,QAH5B,QAIO,mBAJP;AAKA,SAASC,0BAAT,EAAqCC,aAArC,QAA0D,oBAA1D;AACA,SAASC,WAAT,EAAsBC,UAAtB,QAAwC,yBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,0BAAtB;AACA,SAASC,kBAAT,EAA6BC,WAA7B,QAAgD,UAAhD;AACA,SAASC,iBAAT,EAA4BC,SAA5B,QAA6C,SAA7C;AACA,SACCC,eADD,EAECC,sBAFD,EAGCC,uBAHD,QAIO,cAJP;A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GE,iBAAmB,kCAAzB,GAA8D,CAC7DA,iBAD6D,CAF5B;AAKlC,GAAG,GAAGG,sBAAwB,kCAA9B,GAAmE,CAClEA,sBADkE,CALjC;AAQlC,GAAG,GAAGE,mBAAqB,kCAA3B,GAAgE,CAC/D,SAD+D;AAR9B,CAAnC;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMuB,0BAA0B,GAAG,EAClC,GAAGD,0BAD+B;AAElC,GAAG,GAAGtB,mBAAqB,EAA3B,GAAgC,CAAE,kBAAF;AAFE,CAAnC;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMwB,eAAe,GAAG;AAAEC,EAAAA,SAAS,EAAE;AAAb,CAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAoBR,KAApB,EAA2BS,KAA3B,EAA8D;AAAA,MAA5BC,iBAA4B,uEAAR,KAAQ;;AACpE,MAAK,CAAEV,KAAP,EAAe;AACd,WAAOA,KAAP;AACA;;AAED,MAAIW,QAAQ,GAAGX,KAAf;;AACA,MAAK,CAAEU,iBAAP,EAA2B;AAC1BC,IAAAA,QAAQ,GAAGC,IAAI,CAACC,KAAL,CAAYD,IAAI,CAACE,SAAL,CAAgBd,KAAh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\n * WordPress dependencies\n */\nimport { useContext, useMemo, createPortal } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\thasBlockSupport,\n\t__EXPERIMENTAL_ELEMENTS as ELEMENTS,\n} from '@wordpress/blocks';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { getCSSRules, compileCSS } from '@wordpress/style-engine';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport { BORDER_SUPPORT_KEY, BorderPanel } from './border';\nimport { COLOR_SUPPORT_KEY, ColorEdit } from './color';\nimport {\n\tTypographyPanel,\n\tTYPOGRAPHY_SUPPORT_KEY,\n\tTYPOGRAPHY_SUPPORT_KEYS,\n} from './typography';\nimport { SPACING_SUPPORT_KEY, DimensionsPanel } from './dimensions';\nimport useDisplayBlockControls from '../components/use-display-block-controls';\nimport { shouldSkipSerialization } from './utils';\n\nconst styleSupportKeys = [\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\nconst hasStyleSupport = ( blockType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( blockType, key ) );\n\n/**\n * Returns the inline styles to add depending on the style object\n *\n * @param {Object} styles Styles configuration.\n *\n * @return {Object} Flattened CSS variables declaration.\n */\nexport function getInlineStyles( styles = {} ) {\n\tconst output = {};\n\t// The goal is to move everything to server side generated engine styles\n\t// This is temporary as we absorb more and more styles into the engine.\n\tgetCSSRules( styles ).forEach( ( rule ) => {\n\t\toutput[ rule.key ] = rule.value;\n\t} );\n\n\treturn output;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `style` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttribute( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.style ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tstyle: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsEdit = {\n\t[ `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ 'border' ],\n\t[ `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tCOLOR_SUPPORT_KEY,\n\t],\n\t[ `${ TYPOGRAPHY_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t],\n\t[ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [\n\t\t'spacing',\n\t],\n};\n\n/**\n * A dictionary of paths to flag skipping block support serialization as the key,\n * with values providing the style paths to be omitted from serialization.\n *\n * Extends the Edit skip paths to enable skipping additional paths in just\n * the Save component. This allows a block support to be serialized within the\n * editor, while using an alternate approach, such as server-side rendering, when\n * the support is saved.\n *\n * @constant\n * @type {Record<string, string[]>}\n */\nconst skipSerializationPathsSave = {\n\t...skipSerializationPathsEdit,\n\t[ `${ SPACING_SUPPORT_KEY }` ]: [ 'spacing.blockGap' ],\n};\n\n/**\n * A dictionary used to normalize feature names between support flags, style\n * object properties and __experimentSkipSerialization configuration arrays.\n *\n * This allows not having to provide a migration for a support flag and possible\n * backwards compatibility bridges, while still achieving consistency between\n * the support flag and the skip serialization array.\n *\n * @constant\n * @type {Record<string, string>}\n */\nconst renamedFeatures = { gradients: 'gradient' };\n\n/**\n * A utility function used to remove one or more paths from a style object.\n * Works in a way similar to Lodash's `omit()`. See unit tests and examples below.\n *\n * It supports a single string path:\n *\n * ```\n * omitStyle( { color: 'red' }, 'color' ); // {}\n * ```\n *\n * or an array of paths:\n *\n * ```\n * omitStyle( { color: 'red', background: '#fff' }, [ 'color', 'background' ] ); // {}\n * ```\n *\n * It also allows you to specify paths at multiple levels in a string.\n *\n * ```\n * omitStyle( { typography: { textDecoration: 'underline' } }, 'typography.textDecoration' ); // {}\n * ```\n *\n * You can remove multiple paths at the same time:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\ttypography: {\n * \t\t\t\ttextDecoration: 'underline',\n * \t\t\t\ttextTransform: 'uppercase',\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t'typography.textDecoration',\n * \t\t\t'typography.textTransform',\n *\t\t]\n * );\n * // {}\n * ```\n *\n * You can also specify nested paths as arrays:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\ttypography: {\n * \t\t\t\ttextDecoration: 'underline',\n * \t\t\t\ttextTransform: 'uppercase',\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t[ 'typography', 'textDecoration' ],\n * \t\t\t[ 'typography', 'textTransform' ],\n *\t\t]\n * );\n * // {}\n * ```\n *\n * With regards to nesting of styles, infinite depth is supported:\n *\n * ```\n * omitStyle(\n * \t\t{\n * \t\t\tborder: {\n * \t\t\t\tradius: {\n * \t\t\t\t\ttopLeft: '10px',\n * \t\t\t\t\ttopRight: '0.5rem',\n * \t\t\t\t}\n * \t\t\t}\n *\t\t},\n *\t\t[\n * \t\t\t[ 'border', 'radius', 'topRight' ],\n *\t\t]\n * );\n * // { border: { radius: { topLeft: '10px' } } }\n * ```\n *\n * The third argument, `preserveReference`, defines how to treat the input style object.\n * It is mostly necessary to properly handle mutation when recursively handling the style object.\n * Defaulting to `false`, this will always create a new object, avoiding to mutate `style`.\n * However, when recursing, we change that value to `true` in order to work with a single copy\n * of the original style object.\n *\n * @see https://lodash.com/docs/4.17.15#omit\n *\n * @param {Object} style Styles object.\n * @param {Array|string} paths Paths to remove.\n * @param {boolean} preserveReference True to mutate the `style` object, false otherwise.\n * @return {Object} Styles object with the specified paths removed.\n */\nexport function omitStyle( style, paths, preserveReference = false ) {\n\tif ( ! style ) {\n\t\treturn style;\n\t}\n\n\tlet newStyle = style;\n\tif ( ! preserveReference ) {\n\t\tnewStyle = JSON.parse( JSON.stringify( style ) );\n\t}\n\n\tif ( ! Array.isArray( paths ) ) {\n\t\tpaths = [ paths ];\n\t}\n\n\tpaths.forEach( ( path ) => {\n\t\tif ( ! Array.isArray( path ) ) {\n\t\t\tpath = path.split( '.' );\n\t\t}\n\n\t\tif ( path.length > 1 ) {\n\t\t\tconst [ firstSubpath, ...restPath ] = path;\n\t\t\tomitStyle( newStyle[ firstSubpath ], [ restPath ], true );\n\t\t} else if ( path.length === 1 ) {\n\t\t\tdelete newStyle[ path[ 0 ] ];\n\t\t}\n\t} );\n\n\treturn newStyle;\n}\n\n/**\n * Override props assigned to save component to inject the CSS variables definition.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @param {?Record<string, string[]>} skipPaths An object of keys and paths to skip serialization.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps(\n\tprops,\n\tblockType,\n\tattributes,\n\tskipPaths = skipSerializationPathsSave\n) {\n\tif ( ! hasStyleSupport( blockType ) ) {\n\t\treturn props;\n\t}\n\n\tlet { style } = attributes;\n\tObject.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {\n\t\tconst skipSerialization = getBlockSupport( blockType, indicator );\n\n\t\tif ( skipSerialization === true ) {\n\t\t\tstyle = omitStyle( style, path );\n\t\t}\n\n\t\tif ( Array.isArray( skipSerialization ) ) {\n\t\t\tskipSerialization.forEach( ( featureName ) => {\n\t\t\t\tconst feature = renamedFeatures[ featureName ] || featureName;\n\t\t\t\tstyle = omitStyle( style, [ [ ...path, feature ] ] );\n\t\t\t} );\n\t\t}\n\t} );\n\n\tprops.style = {\n\t\t...getInlineStyles( style ),\n\t\t...props.style,\n\t};\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to extend the block edit wrapper\n * to apply the desired styles and classnames properly.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object}.Filtered block settings.\n */\nexport function addEditProps( settings ) {\n\tif ( ! hasStyleSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps(\n\t\t\tprops,\n\t\t\tsettings,\n\t\t\tattributes,\n\t\t\tskipSerializationPathsEdit\n\t\t);\n\t};\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include new inspector controls for\n * all the custom styles configs.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst shouldDisplayControls = useDisplayBlockControls();\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldDisplayControls && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ColorEdit { ...props } />\n\t\t\t\t\t\t<TypographyPanel { ...props } />\n\t\t\t\t\t\t<BorderPanel { ...props } />\n\t\t\t\t\t\t<DimensionsPanel { ...props } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\n/**\n * Override the default block element to include elements styles.\n *\n * @param {Function} BlockListBlock Original component\n * @return {Function} Wrapped component\n */\nconst withElementsStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(\n\t\t\tBlockListBlock\n\t\t) }`;\n\n\t\tconst skipLinkColorSerialization = shouldSkipSerialization(\n\t\t\tprops.name,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t'link'\n\t\t);\n\n\t\tconst styles = useMemo( () => {\n\t\t\tconst rawElementsStyles = props.attributes.style?.elements;\n\t\t\tconst elementCssRules = [];\n\t\t\tif (\n\t\t\t\trawElementsStyles &&\n\t\t\t\tObject.keys( rawElementsStyles ).length > 0\n\t\t\t) {\n\t\t\t\t// Remove values based on whether serialization has been skipped for a specific style.\n\t\t\t\tconst filteredElementsStyles = {\n\t\t\t\t\t...rawElementsStyles,\n\t\t\t\t\tlink: {\n\t\t\t\t\t\t...rawElementsStyles.link,\n\t\t\t\t\t\tcolor: ! skipLinkColorSerialization\n\t\t\t\t\t\t\t? rawElementsStyles.link?.color\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tfor ( const [ elementName, elementStyles ] of Object.entries(\n\t\t\t\t\tfilteredElementsStyles\n\t\t\t\t) ) {\n\t\t\t\t\tconst cssRule = compileCSS( elementStyles, {\n\t\t\t\t\t\t// The .editor-styles-wrapper selector is required on elements styles. As it is\n\t\t\t\t\t\t// added to all other editor styles, not providing it causes reset and global\n\t\t\t\t\t\t// styles to override element styles because of higher specificity.\n\t\t\t\t\t\tselector: `.editor-styles-wrapper .${ blockElementsContainerIdentifier } ${ ELEMENTS[ elementName ] }`,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( !! cssRule ) {\n\t\t\t\t\t\telementCssRules.push( cssRule );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn elementCssRules.length > 0 ? elementCssRules : undefined;\n\t\t}, [ props.attributes.style?.elements ] );\n\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ styles &&\n\t\t\t\t\telement &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t\t__html: styles,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\n\t\t\t\t<BlockListBlock\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tprops.attributes.style?.elements\n\t\t\t\t\t\t\t? classnames(\n\t\t\t\t\t\t\t\t\tprops.className,\n\t\t\t\t\t\t\t\t\tblockElementsContainerIdentifier\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: props.className\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addAttribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/style/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/style/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/style/with-block-controls',\n\twithBlockControls\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/with-elements-styles',\n\twithElementsStyles\n);\n"]}
|
|
@@ -8,7 +8,8 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { getInlineStyles } from './style';
|
|
11
|
-
import { getFontSizeClass } from '../components/font-sizes';
|
|
11
|
+
import { getFontSizeClass } from '../components/font-sizes';
|
|
12
|
+
import { getComputedFluidTypographyValue } from '../components/font-sizes/fluid-utils'; // This utility is intended to assist where the serialization of the typography
|
|
12
13
|
// block support is being skipped for a block but the typography related CSS
|
|
13
14
|
// styles still need to be generated so they can be applied to inner elements.
|
|
14
15
|
|
|
@@ -16,15 +17,27 @@ import { getFontSizeClass } from '../components/font-sizes'; // This utility is
|
|
|
16
17
|
* Provides the CSS class names and inline styles for a block's typography support
|
|
17
18
|
* attributes.
|
|
18
19
|
*
|
|
19
|
-
* @param {Object}
|
|
20
|
+
* @param {Object} attributes Block attributes.
|
|
21
|
+
* @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.
|
|
20
22
|
*
|
|
21
23
|
* @return {Object} Typography block support derived CSS classes & styles.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
|
-
export function getTypographyClassesAndStyles(attributes) {
|
|
26
|
+
export function getTypographyClassesAndStyles(attributes, isFluidFontSizeActive) {
|
|
25
27
|
var _attributes$style;
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
let typographyStyles = (attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.typography) || {};
|
|
30
|
+
|
|
31
|
+
if (isFluidFontSizeActive) {
|
|
32
|
+
var _attributes$style2, _attributes$style2$ty;
|
|
33
|
+
|
|
34
|
+
typographyStyles = { ...typographyStyles,
|
|
35
|
+
fontSize: getComputedFluidTypographyValue({
|
|
36
|
+
fontSize: attributes === null || attributes === void 0 ? void 0 : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$ty = _attributes$style2.typography) === null || _attributes$style2$ty === void 0 ? void 0 : _attributes$style2$ty.fontSize
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
const style = getInlineStyles({
|
|
29
42
|
typography: typographyStyles
|
|
30
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["kebabCase","classnames","getInlineStyles","getFontSizeClass","getTypographyClassesAndStyles","attributes","typographyStyles","style","typography","fontFamilyClassName","fontFamily","className"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/use-typography-props.js"],"names":["kebabCase","classnames","getInlineStyles","getFontSizeClass","getComputedFluidTypographyValue","getTypographyClassesAndStyles","attributes","isFluidFontSizeActive","typographyStyles","style","typography","fontSize","fontFamilyClassName","fontFamily","className"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,SAAhC;AACA,SAASC,gBAAT,QAAiC,0BAAjC;AACA,SAASC,+BAAT,QAAgD,sCAAhD,C,CAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,6BAAT,CACNC,UADM,EAENC,qBAFM,EAGL;AAAA;;AACD,MAAIC,gBAAgB,GAAG,CAAAF,UAAU,SAAV,IAAAA,UAAU,WAAV,iCAAAA,UAAU,CAAEG,KAAZ,wEAAmBC,UAAnB,KAAiC,EAAxD;;AAEA,MAAKH,qBAAL,EAA6B;AAAA;;AAC5BC,IAAAA,gBAAgB,GAAG,EAClB,GAAGA,gBADe;AAElBG,MAAAA,QAAQ,EAAEP,+BAA+B,CAAE;AAC1CO,QAAAA,QAAQ,EAAEL,UAAF,aAAEA,UAAF,6CAAEA,UAAU,CAAEG,KAAd,gFAAE,mBAAmBC,UAArB,0DAAE,sBAA+BC;AADC,OAAF;AAFvB,KAAnB;AAMA;;AAED,QAAMF,KAAK,GAAGP,eAAe,CAAE;AAAEQ,IAAAA,UAAU,EAAEF;AAAd,GAAF,CAA7B;AACA,QAAMI,mBAAmB,GAAG,CAAC,EAAEN,UAAF,aAAEA,UAAF,eAAEA,UAAU,CAAEO,UAAd,CAAD,GACxB,OAAOb,SAAS,CAAEM,UAAU,CAACO,UAAb,CAA2B,cADnB,GAEzB,EAFH;AAIA,QAAMC,SAAS,GAAGb,UAAU,CAC3BW,mBAD2B,EAE3BT,gBAAgB,CAAEG,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAEK,QAAd,CAFW,CAA5B;AAKA,SAAO;AACNG,IAAAA,SADM;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * Internal dependencies\n */\nimport { getInlineStyles } from './style';\nimport { getFontSizeClass } from '../components/font-sizes';\nimport { getComputedFluidTypographyValue } from '../components/font-sizes/fluid-utils';\n\n// This utility is intended to assist where the serialization of the typography\n// block support is being skipped for a block but the typography related CSS\n// styles still need to be generated so they can be applied to inner elements.\n\n/**\n * Provides the CSS class names and inline styles for a block's typography support\n * attributes.\n *\n * @param {Object} attributes Block attributes.\n * @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.\n *\n * @return {Object} Typography block support derived CSS classes & styles.\n */\nexport function getTypographyClassesAndStyles(\n\tattributes,\n\tisFluidFontSizeActive\n) {\n\tlet typographyStyles = attributes?.style?.typography || {};\n\n\tif ( isFluidFontSizeActive ) {\n\t\ttypographyStyles = {\n\t\t\t...typographyStyles,\n\t\t\tfontSize: getComputedFluidTypographyValue( {\n\t\t\t\tfontSize: attributes?.style?.typography?.fontSize,\n\t\t\t} ),\n\t\t};\n\t}\n\n\tconst style = getInlineStyles( { typography: typographyStyles } );\n\tconst fontFamilyClassName = !! attributes?.fontFamily\n\t\t? `has-${ kebabCase( attributes.fontFamily ) }-font-family`\n\t\t: '';\n\n\tconst className = classnames(\n\t\tfontFamilyClassName,\n\t\tgetFontSizeClass( attributes?.fontSize )\n\t);\n\n\treturn {\n\t\tclassName,\n\t\tstyle,\n\t};\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { pickBy, isEmpty, mapValues, get, setWith, clone
|
|
4
|
+
import { pickBy, isEmpty, mapValues, get, setWith, clone } from 'lodash';
|
|
5
5
|
/**
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
@@ -32,7 +32,7 @@ export function transformStyles(activeSupports, migrationPaths, result, source,
|
|
|
32
32
|
var _source$;
|
|
33
33
|
|
|
34
34
|
// If there are no active supports return early.
|
|
35
|
-
if (
|
|
35
|
+
if (Object.values(activeSupports !== null && activeSupports !== void 0 ? activeSupports : {}).every(isActive => !isActive)) {
|
|
36
36
|
return result;
|
|
37
37
|
} // If the condition verifies we are probably in the presence of a wrapping transform
|
|
38
38
|
// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["pickBy","isEmpty","mapValues","get","setWith","clone","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["pickBy","isEmpty","mapValues","get","setWith","clone","getBlockSupport","identity","x","cleanEmptyObject","object","Array","isArray","cleanedNestedObjects","undefined","immutableSet","path","value","transformStyles","activeSupports","migrationPaths","result","source","index","results","Object","values","every","isActive","length","innerBlocks","referenceBlockAttributes","attributes","returnBlock","entries","forEach","support","styleValue","shouldSkipSerialization","blockType","featureSet","feature","skipSerialization","__experimentalSkipSerialization","includes"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,GAArC,EAA0CC,OAA1C,EAAmDC,KAAnD,QAAgE,QAAhE;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,mBAAhC;;AAEA,MAAMC,QAAQ,GAAKC,CAAF,IAASA,CAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMC,gBAAgB,GAAKC,MAAF,IAAc;AAC7C,MACCA,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEAC,KAAK,CAACC,OAAN,CAAeF,MAAf,CAHD,EAIE;AACD,WAAOA,MAAP;AACA;;AACD,QAAMG,oBAAoB,GAAGb,MAAM,CAClCE,SAAS,CAAEQ,MAAF,EAAUD,gBAAV,CADyB,EAElCF,QAFkC,CAAnC;AAIA,SAAON,OAAO,CAAEY,oBAAF,CAAP,GAAkCC,SAAlC,GAA8CD,oBAArD;AACA,CAbM;AAeP,OAAO,SAASE,YAAT,CAAuBL,MAAvB,EAA+BM,IAA/B,EAAqCC,KAArC,EAA6C;AACnD,SAAOb,OAAO,CAAEM,MAAM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AU,GAAGlC,GAAG,CAAE4B,wBAAF,EAA4Bf,IAA5B,CAAtB;;AACA,YAAKqB,UAAL,EAAkB;AACjBJ,UAAAA,WAAW,GAAG,EACb,GAAGA,WADU;AAEbD,YAAAA,UAAU,EAAEjB,YAAY,CACvBkB,WAAW,CAACD,UADW,EAEvBhB,IAFuB,EAGvBqB,UAHuB;AAFX,WAAd;AAQA;AACD,OAZD;AAaA;AACD,GAhBD;AAiBA,SAAOJ,WAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,uBAAT,CAAkCC,SAAlC,EAA6CC,UAA7C,EAAyDC,OAAzD,EAAmE;AACzE,QAAML,OAAO,GAAG9B,eAAe,CAAEiC,SAAF,EAAaC,UAAb,CAA/B;AACA,QAAME,iBAAiB,GAAGN,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEO,+BAAnC;;AAEA,MAAKhC,KAAK,CAACC,OAAN,CAAe8B,iBAAf,CAAL,EAA0C;AACzC,WAAOA,iBAAiB,CAACE,QAAlB,CAA4BH,OAA5B,CAAP;AACA;;AAED,SAAOC,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { pickBy, isEmpty, mapValues, get, setWith, clone } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\n\nconst identity = ( x ) => x;\n\n/**\n * Removed falsy values from nested object.\n *\n * @param {*} object\n * @return {*} Object cleaned from falsy values\n */\nexport const cleanEmptyObject = ( object ) => {\n\tif (\n\t\tobject === null ||\n\t\ttypeof object !== 'object' ||\n\t\tArray.isArray( object )\n\t) {\n\t\treturn object;\n\t}\n\tconst cleanedNestedObjects = pickBy(\n\t\tmapValues( object, cleanEmptyObject ),\n\t\tidentity\n\t);\n\treturn isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;\n};\n\nexport function immutableSet( object, path, value ) {\n\treturn setWith( object ? clone( object ) : {}, path, value, clone );\n}\n\nexport function transformStyles(\n\tactiveSupports,\n\tmigrationPaths,\n\tresult,\n\tsource,\n\tindex,\n\tresults\n) {\n\t// If there are no active supports return early.\n\tif (\n\t\tObject.values( activeSupports ?? {} ).every(\n\t\t\t( isActive ) => ! isActive\n\t\t)\n\t) {\n\t\treturn result;\n\t}\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\t// For cases where we have a transform from one block to multiple blocks\n\t// or multiple blocks to one block we apply the styles of the first source block\n\t// to the result(s).\n\tlet referenceBlockAttributes = source[ 0 ]?.attributes;\n\t// If we are in presence of transform between more than one block in the source\n\t// that has more than one block in the result\n\t// we apply the styles on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( results.length > 1 && source.length > 1 ) {\n\t\tif ( source[ index ] ) {\n\t\t\treferenceBlockAttributes = source[ index ]?.attributes;\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t}\n\tlet returnBlock = result;\n\tObject.entries( activeSupports ).forEach( ( [ support, isActive ] ) => {\n\t\tif ( isActive ) {\n\t\t\tmigrationPaths[ support ].forEach( ( path ) => {\n\t\t\t\tconst styleValue = get( referenceBlockAttributes, path );\n\t\t\t\tif ( styleValue ) {\n\t\t\t\t\treturnBlock = {\n\t\t\t\t\t\t...returnBlock,\n\t\t\t\t\t\tattributes: immutableSet(\n\t\t\t\t\t\t\treturnBlock.attributes,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tstyleValue\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t} );\n\treturn returnBlock;\n}\n\n/**\n * Check whether serialization of specific block support feature or set should\n * be skipped.\n *\n * @param {string|Object} blockType Block name or block type object.\n * @param {string} featureSet Name of block support feature set.\n * @param {string} feature Name of the individual feature to check.\n *\n * @return {boolean} Whether serialization should occur.\n */\nexport function shouldSkipSerialization( blockType, featureSet, feature ) {\n\tconst support = getBlockSupport( blockType, featureSet );\n\tconst skipSerialization = support?.__experimentalSkipSerialization;\n\n\tif ( Array.isArray( skipSerialization ) ) {\n\t\treturn skipSerialization.includes( feature );\n\t}\n\n\treturn skipSerialization;\n}\n"]}
|
|
@@ -12,6 +12,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
12
12
|
|
|
13
13
|
import { mapRichTextSettings } from './utils';
|
|
14
14
|
import { retrieveSelectedAttribute, START_OF_SELECTED_AREA } from '../utils/selection';
|
|
15
|
+
/** @typedef {import('../components/use-on-block-drop/types').WPDropOperation} WPDropOperation */
|
|
15
16
|
|
|
16
17
|
const castArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
17
18
|
/**
|
|
@@ -605,10 +606,13 @@ export const insertBlocks = function (blocks, index, rootClientId) {
|
|
|
605
606
|
/**
|
|
606
607
|
* Action that shows the insertion point.
|
|
607
608
|
*
|
|
608
|
-
* @param
|
|
609
|
-
*
|
|
610
|
-
* @param
|
|
611
|
-
* @param
|
|
609
|
+
* @param {?string} rootClientId Optional root client ID of block list on
|
|
610
|
+
* which to insert.
|
|
611
|
+
* @param {?number} index Index at which block should be inserted.
|
|
612
|
+
* @param {?Object} __unstableOptions Additional options.
|
|
613
|
+
* @property {boolean} __unstableWithInserter Whether or not to show an inserter button.
|
|
614
|
+
* @property {WPDropOperation} operation The operation to perform when applied,
|
|
615
|
+
* either 'insert' or 'replace' for now.
|
|
612
616
|
*
|
|
613
617
|
* @return {Object} Action object.
|
|
614
618
|
*/
|
|
@@ -617,26 +621,35 @@ export function showInsertionPoint(rootClientId, index) {
|
|
|
617
621
|
let __unstableOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
618
622
|
|
|
619
623
|
const {
|
|
620
|
-
__unstableWithInserter
|
|
624
|
+
__unstableWithInserter,
|
|
625
|
+
operation
|
|
621
626
|
} = __unstableOptions;
|
|
622
627
|
return {
|
|
623
628
|
type: 'SHOW_INSERTION_POINT',
|
|
624
629
|
rootClientId,
|
|
625
630
|
index,
|
|
626
|
-
__unstableWithInserter
|
|
631
|
+
__unstableWithInserter,
|
|
632
|
+
operation
|
|
627
633
|
};
|
|
628
634
|
}
|
|
629
635
|
/**
|
|
630
636
|
* Action that hides the insertion point.
|
|
631
|
-
*
|
|
632
|
-
* @return {Object} Action object.
|
|
633
637
|
*/
|
|
634
638
|
|
|
635
|
-
export
|
|
636
|
-
|
|
639
|
+
export const hideInsertionPoint = () => _ref11 => {
|
|
640
|
+
let {
|
|
641
|
+
select,
|
|
642
|
+
dispatch
|
|
643
|
+
} = _ref11;
|
|
644
|
+
|
|
645
|
+
if (!select.isBlockInsertionPointVisible()) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
dispatch({
|
|
637
650
|
type: 'HIDE_INSERTION_POINT'
|
|
638
|
-
};
|
|
639
|
-
}
|
|
651
|
+
});
|
|
652
|
+
};
|
|
640
653
|
/**
|
|
641
654
|
* Action that resets the template validity.
|
|
642
655
|
*
|
|
@@ -657,11 +670,11 @@ export function setTemplateValidity(isValid) {
|
|
|
657
670
|
* @return {Object} Action object.
|
|
658
671
|
*/
|
|
659
672
|
|
|
660
|
-
export const synchronizeTemplate = () =>
|
|
673
|
+
export const synchronizeTemplate = () => _ref12 => {
|
|
661
674
|
let {
|
|
662
675
|
select,
|
|
663
676
|
dispatch
|
|
664
|
-
} =
|
|
677
|
+
} = _ref12;
|
|
665
678
|
dispatch({
|
|
666
679
|
type: 'SYNCHRONIZE_TEMPLATE'
|
|
667
680
|
});
|
|
@@ -676,12 +689,12 @@ export const synchronizeTemplate = () => _ref11 => {
|
|
|
676
689
|
* @param {boolean} isForward
|
|
677
690
|
*/
|
|
678
691
|
|
|
679
|
-
export const __unstableDeleteSelection = isForward =>
|
|
692
|
+
export const __unstableDeleteSelection = isForward => _ref13 => {
|
|
680
693
|
let {
|
|
681
694
|
registry,
|
|
682
695
|
select,
|
|
683
696
|
dispatch
|
|
684
|
-
} =
|
|
697
|
+
} = _ref13;
|
|
685
698
|
const selectionAnchor = select.getSelectionStart();
|
|
686
699
|
const selectionFocus = select.getSelectionEnd();
|
|
687
700
|
if (selectionAnchor.clientId === selectionFocus.clientId) return; // It's not mergeable if there's no rich text selection.
|
|
@@ -799,11 +812,11 @@ export const __unstableDeleteSelection = isForward => _ref12 => {
|
|
|
799
812
|
* Split the current selection.
|
|
800
813
|
*/
|
|
801
814
|
|
|
802
|
-
export const __unstableSplitSelection = () =>
|
|
815
|
+
export const __unstableSplitSelection = () => _ref14 => {
|
|
803
816
|
let {
|
|
804
817
|
select,
|
|
805
818
|
dispatch
|
|
806
|
-
} =
|
|
819
|
+
} = _ref14;
|
|
807
820
|
const selectionAnchor = select.getSelectionStart();
|
|
808
821
|
const selectionFocus = select.getSelectionEnd();
|
|
809
822
|
if (selectionAnchor.clientId === selectionFocus.clientId) return; // Can't split if the selection is not set.
|
|
@@ -874,11 +887,11 @@ export const __unstableSplitSelection = () => _ref13 => {
|
|
|
874
887
|
* Expand the selection to cover the entire blocks, removing partial selection.
|
|
875
888
|
*/
|
|
876
889
|
|
|
877
|
-
export const __unstableExpandSelection = () =>
|
|
890
|
+
export const __unstableExpandSelection = () => _ref15 => {
|
|
878
891
|
let {
|
|
879
892
|
select,
|
|
880
893
|
dispatch
|
|
881
|
-
} =
|
|
894
|
+
} = _ref15;
|
|
882
895
|
const selectionAnchor = select.getSelectionStart();
|
|
883
896
|
const selectionFocus = select.getSelectionEnd();
|
|
884
897
|
dispatch.selectionChange({
|
|
@@ -897,12 +910,12 @@ export const __unstableExpandSelection = () => _ref14 => {
|
|
|
897
910
|
* @param {string} secondBlockClientId Client ID of the second block to merge.
|
|
898
911
|
*/
|
|
899
912
|
|
|
900
|
-
export const mergeBlocks = (firstBlockClientId, secondBlockClientId) =>
|
|
913
|
+
export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref16 => {
|
|
901
914
|
let {
|
|
902
915
|
registry,
|
|
903
916
|
select,
|
|
904
917
|
dispatch
|
|
905
|
-
} =
|
|
918
|
+
} = _ref16;
|
|
906
919
|
const blocks = [firstBlockClientId, secondBlockClientId];
|
|
907
920
|
dispatch({
|
|
908
921
|
type: 'MERGE_BLOCKS',
|
|
@@ -1024,11 +1037,11 @@ export const mergeBlocks = (firstBlockClientId, secondBlockClientId) => _ref15 =
|
|
|
1024
1037
|
|
|
1025
1038
|
export const removeBlocks = function (clientIds) {
|
|
1026
1039
|
let selectPrevious = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1027
|
-
return
|
|
1040
|
+
return _ref17 => {
|
|
1028
1041
|
let {
|
|
1029
1042
|
select,
|
|
1030
1043
|
dispatch
|
|
1031
|
-
} =
|
|
1044
|
+
} = _ref17;
|
|
1032
1045
|
|
|
1033
1046
|
if (!clientIds || !clientIds.length) {
|
|
1034
1047
|
return;
|
|
@@ -1229,10 +1242,10 @@ export function selectionChange(clientId, attributeKey, startOffset, endOffset)
|
|
|
1229
1242
|
* @param {?number} index Optional index where to insert the default block.
|
|
1230
1243
|
*/
|
|
1231
1244
|
|
|
1232
|
-
export const insertDefaultBlock = (attributes, rootClientId, index) =>
|
|
1245
|
+
export const insertDefaultBlock = (attributes, rootClientId, index) => _ref18 => {
|
|
1233
1246
|
let {
|
|
1234
1247
|
dispatch
|
|
1235
|
-
} =
|
|
1248
|
+
} = _ref18;
|
|
1236
1249
|
// Abort if there is no default block type (if it has been unregistered).
|
|
1237
1250
|
const defaultBlockName = getDefaultBlockName();
|
|
1238
1251
|
|
|
@@ -1321,10 +1334,10 @@ export function __unstableMarkNextChangeAsNotPersistent() {
|
|
|
1321
1334
|
* selection changes have been recorded.
|
|
1322
1335
|
*/
|
|
1323
1336
|
|
|
1324
|
-
export const __unstableMarkAutomaticChange = () =>
|
|
1337
|
+
export const __unstableMarkAutomaticChange = () => _ref19 => {
|
|
1325
1338
|
let {
|
|
1326
1339
|
dispatch
|
|
1327
|
-
} =
|
|
1340
|
+
} = _ref19;
|
|
1328
1341
|
dispatch({
|
|
1329
1342
|
type: 'MARK_AUTOMATIC_CHANGE'
|
|
1330
1343
|
});
|
|
@@ -1345,10 +1358,10 @@ export const __unstableMarkAutomaticChange = () => _ref18 => {
|
|
|
1345
1358
|
|
|
1346
1359
|
export const setNavigationMode = function () {
|
|
1347
1360
|
let isNavigationMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1348
|
-
return
|
|
1361
|
+
return _ref20 => {
|
|
1349
1362
|
let {
|
|
1350
1363
|
dispatch
|
|
1351
|
-
} =
|
|
1364
|
+
} = _ref20;
|
|
1352
1365
|
|
|
1353
1366
|
dispatch.__unstableSetEditorMode(isNavigationMode ? 'navigation' : 'edit');
|
|
1354
1367
|
};
|
|
@@ -1359,11 +1372,11 @@ export const setNavigationMode = function () {
|
|
|
1359
1372
|
* @param {string} mode Editor mode
|
|
1360
1373
|
*/
|
|
1361
1374
|
|
|
1362
|
-
export const __unstableSetEditorMode = mode =>
|
|
1375
|
+
export const __unstableSetEditorMode = mode => _ref21 => {
|
|
1363
1376
|
let {
|
|
1364
1377
|
dispatch,
|
|
1365
1378
|
select
|
|
1366
|
-
} =
|
|
1379
|
+
} = _ref21;
|
|
1367
1380
|
|
|
1368
1381
|
// When switching to zoom-out mode, we need to select the root block
|
|
1369
1382
|
if (mode === 'zoom-out') {
|
|
@@ -1395,10 +1408,10 @@ export const __unstableSetEditorMode = mode => _ref20 => {
|
|
|
1395
1408
|
|
|
1396
1409
|
export const setBlockMovingClientId = function () {
|
|
1397
1410
|
let hasBlockMovingClientId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1398
|
-
return
|
|
1411
|
+
return _ref22 => {
|
|
1399
1412
|
let {
|
|
1400
1413
|
dispatch
|
|
1401
|
-
} =
|
|
1414
|
+
} = _ref22;
|
|
1402
1415
|
dispatch({
|
|
1403
1416
|
type: 'SET_BLOCK_MOVING_MODE',
|
|
1404
1417
|
hasBlockMovingClientId
|
|
@@ -1418,11 +1431,11 @@ export const setBlockMovingClientId = function () {
|
|
|
1418
1431
|
|
|
1419
1432
|
export const duplicateBlocks = function (clientIds) {
|
|
1420
1433
|
let updateSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1421
|
-
return
|
|
1434
|
+
return _ref23 => {
|
|
1422
1435
|
let {
|
|
1423
1436
|
select,
|
|
1424
1437
|
dispatch
|
|
1425
|
-
} =
|
|
1438
|
+
} = _ref23;
|
|
1426
1439
|
|
|
1427
1440
|
if (!clientIds || !clientIds.length) {
|
|
1428
1441
|
return;
|
|
@@ -1461,11 +1474,11 @@ export const duplicateBlocks = function (clientIds) {
|
|
|
1461
1474
|
* @param {string} clientId
|
|
1462
1475
|
*/
|
|
1463
1476
|
|
|
1464
|
-
export const insertBeforeBlock = clientId =>
|
|
1477
|
+
export const insertBeforeBlock = clientId => _ref24 => {
|
|
1465
1478
|
let {
|
|
1466
1479
|
select,
|
|
1467
1480
|
dispatch
|
|
1468
|
-
} =
|
|
1481
|
+
} = _ref24;
|
|
1469
1482
|
|
|
1470
1483
|
if (!clientId) {
|
|
1471
1484
|
return;
|
|
@@ -1487,11 +1500,11 @@ export const insertBeforeBlock = clientId => _ref23 => {
|
|
|
1487
1500
|
* @param {string} clientId
|
|
1488
1501
|
*/
|
|
1489
1502
|
|
|
1490
|
-
export const insertAfterBlock = clientId =>
|
|
1503
|
+
export const insertAfterBlock = clientId => _ref25 => {
|
|
1491
1504
|
let {
|
|
1492
1505
|
select,
|
|
1493
1506
|
dispatch
|
|
1494
|
-
} =
|
|
1507
|
+
} = _ref25;
|
|
1495
1508
|
|
|
1496
1509
|
if (!clientId) {
|
|
1497
1510
|
return;
|
|
@@ -1527,10 +1540,10 @@ export function toggleBlockHighlight(clientId, isHighlighted) {
|
|
|
1527
1540
|
* @param {string} clientId Target block client ID.
|
|
1528
1541
|
*/
|
|
1529
1542
|
|
|
1530
|
-
export const flashBlock = clientId => async
|
|
1543
|
+
export const flashBlock = clientId => async _ref26 => {
|
|
1531
1544
|
let {
|
|
1532
1545
|
dispatch
|
|
1533
|
-
} =
|
|
1546
|
+
} = _ref26;
|
|
1534
1547
|
dispatch(toggleBlockHighlight(clientId, true));
|
|
1535
1548
|
await new Promise(resolve => setTimeout(resolve, 150));
|
|
1536
1549
|
dispatch(toggleBlockHighlight(clientId, false));
|