@wordpress/block-editor 9.0.0 → 9.1.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 +2 -0
- package/README.md +1 -0
- package/build/components/block-alignment-matrix-control/index.js +1 -6
- package/build/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build/components/block-content-overlay/index.js +4 -82
- package/build/components/block-content-overlay/index.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.native.js +64 -0
- package/build/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js +157 -0
- package/build/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build/components/block-draggable/index.native.js +484 -0
- package/build/components/block-draggable/index.native.js.map +1 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js +130 -0
- package/build/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build/components/block-list/block-list-context.native.js +195 -0
- package/build/components/block-list/block-list-context.native.js.map +1 -0
- package/build/components/block-list/block-list-item-cell.native.js +67 -0
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build/components/block-list/block-list-item.native.js +12 -9
- package/build/components/block-list/block-list-item.native.js.map +1 -1
- package/build/components/block-list/block.native.js +26 -5
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +75 -23
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +8 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-mobile-toolbar/index.native.js +9 -3
- package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build/components/block-mover/index.native.js +17 -4
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-popover/inbetween.js +10 -2
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +4 -16
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/index.js +1 -1
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +1 -29
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/border-radius-control/input-controls.js +10 -3
- package/build/components/border-radius-control/input-controls.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +149 -44
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/iframe/index.js +51 -50
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +3 -1
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/index.js +5 -14
- package/build/components/index.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/link-control/constants.js +11 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/search-results.js +4 -3
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/use-search-handler.js +4 -4
- package/build/components/link-control/use-search-handler.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +0 -1
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +12 -2
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +0 -1
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +1 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-input/index.js +4 -1
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.native.js +167 -0
- package/build/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build/components/use-on-block-drop/index.native.js +95 -0
- package/build/components/use-on-block-drop/index.native.js.map +1 -0
- package/build/components/warning/index.js +6 -1
- package/build/components/warning/index.js.map +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +2 -7
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color-panel.js +14 -7
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/style.js +14 -13
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +6 -2
- package/build/hooks/typography.js.map +1 -1
- package/build-module/components/block-alignment-matrix-control/index.js +1 -6
- package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
- package/build-module/components/block-content-overlay/index.js +3 -78
- package/build-module/components/block-content-overlay/index.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.native.js +50 -0
- package/build-module/components/block-draggable/draggable-chip.native.js.map +1 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js +137 -0
- package/build-module/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
- package/build-module/components/block-draggable/index.native.js +449 -0
- package/build-module/components/block-draggable/index.native.js.map +1 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js +120 -0
- package/build-module/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
- package/build-module/components/block-list/block-list-context.native.js +179 -0
- package/build-module/components/block-list/block-list-context.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item-cell.native.js +59 -0
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -0
- package/build-module/components/block-list/block-list-item.native.js +12 -9
- package/build-module/components/block-list/block-list-item.native.js.map +1 -1
- package/build-module/components/block-list/block.native.js +25 -5
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +72 -23
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +9 -5
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/index.native.js +8 -3
- package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +18 -5
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +10 -2
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +4 -15
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/index.js +1 -1
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +2 -29
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/border-radius-control/input-controls.js +11 -4
- package/build-module/components/border-radius-control/input-controls.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +151 -46
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/iframe/index.js +52 -51
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +2 -1
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/index.js +1 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +1 -1
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/link-control/constants.js +5 -0
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -4
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/use-search-handler.js +5 -5
- package/build-module/components/link-control/use-search-handler.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +0 -1
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +12 -2
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +0 -1
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +1 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-input/index.js +4 -1
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.native.js +148 -0
- package/build-module/components/use-block-drop-zone/index.native.js.map +1 -0
- package/build-module/components/use-on-block-drop/index.native.js +83 -0
- package/build-module/components/use-on-block-drop/index.native.js.map +1 -0
- package/build-module/components/warning/index.js +6 -1
- package/build-module/components/warning/index.js.map +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +2 -7
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color-panel.js +11 -6
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/style.js +15 -14
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +6 -2
- package/build-module/hooks/typography.js.map +1 -1
- package/build-style/style-rtl.css +60 -174
- package/build-style/style.css +60 -174
- package/package.json +28 -28
- package/src/components/block-alignment-matrix-control/index.js +1 -5
- package/src/components/block-content-overlay/index.js +8 -95
- package/src/components/block-content-overlay/style.scss +2 -11
- package/src/components/block-draggable/draggable-chip.native.js +49 -0
- package/src/components/block-draggable/dropping-insertion-point.native.js +181 -0
- package/src/components/block-draggable/dropping-insertion-point.native.scss +8 -0
- package/src/components/block-draggable/index.native.js +458 -0
- package/src/components/block-draggable/style.native.scss +19 -0
- package/src/components/block-draggable/use-scroll-when-dragging.native.js +135 -0
- package/src/components/block-list/block-list-context.native.js +175 -0
- package/src/components/block-list/block-list-item-cell.native.js +49 -0
- package/src/components/block-list/block-list-item.native.js +7 -11
- package/src/components/block-list/block.native.js +36 -8
- package/src/components/block-list/index.native.js +54 -13
- package/src/components/block-list/test/block-list-context.native.js +253 -0
- package/src/components/block-list/test/fixtures/block-list-context.native.js +79 -0
- package/src/components/block-list/use-block-props/index.js +10 -5
- package/src/components/block-list/use-in-between-inserter.js +1 -1
- package/src/components/block-mobile-toolbar/index.native.js +8 -1
- package/src/components/block-mover/index.native.js +22 -6
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +6 -0
- package/src/components/block-popover/inbetween.js +9 -1
- package/src/components/block-popover/index.js +1 -16
- package/src/components/block-popover/style.scss +1 -0
- package/src/components/block-preview/index.js +1 -4
- package/src/components/block-switcher/style.scss +2 -39
- package/src/components/block-tools/selected-block-popover.js +1 -36
- package/src/components/block-tools/style.scss +1 -12
- package/src/components/border-radius-control/input-controls.js +16 -8
- package/src/components/border-radius-control/style.scss +3 -2
- package/src/components/colors-gradients/dropdown.js +156 -62
- package/src/components/colors-gradients/style.scss +51 -23
- package/src/components/duotone-control/style.scss +1 -7
- package/src/components/iframe/index.js +62 -54
- package/src/components/image-editor/use-save-image.js +2 -1
- package/src/components/index.js +1 -2
- package/src/components/inserter/index.native.js +1 -1
- package/src/components/inserter/style.scss +2 -1
- package/src/components/link-control/constants.js +11 -0
- package/src/components/link-control/search-results.js +4 -5
- package/src/components/link-control/use-search-handler.js +11 -5
- package/src/components/list-view/drop-indicator.js +0 -1
- package/src/components/list-view/style.scss +2 -1
- package/src/components/navigable-toolbar/index.js +12 -2
- package/src/components/preview-options/style.scss +0 -4
- package/src/components/rich-text/format-toolbar-container.js +0 -1
- package/src/components/rich-text/index.js +1 -1
- package/src/components/rich-text/style.scss +2 -8
- package/src/components/url-input/index.js +3 -1
- package/src/components/use-block-drop-zone/index.native.js +173 -0
- package/src/components/use-on-block-drop/index.native.js +119 -0
- package/src/components/warning/index.js +47 -42
- package/src/components/warning/test/__snapshots__/index.js.snap +15 -6
- package/src/components/warning/test/index.js +1 -1
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +2 -11
- package/src/hooks/border.scss +0 -48
- package/src/hooks/color-panel.js +13 -9
- package/src/hooks/color.scss +0 -62
- package/src/hooks/style.js +25 -39
- package/src/hooks/typography.js +2 -0
- package/src/style.scss +0 -1
- package/build/components/colors-gradients/tools-panel-color-dropdown.js +0 -89
- package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +0 -75
- package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
- package/src/components/block-alignment-matrix-control/style.scss +0 -10
- package/src/components/colors-gradients/tools-panel-color-dropdown.js +0 -85
|
@@ -9,67 +9,172 @@ import classnames from 'classnames';
|
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { Button, ColorIndicator, Dropdown, FlexItem, __experimentalHStack as HStack, __experimentalItem as Item, __experimentalItemGroup as ItemGroup, __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import ColorGradientControl from './control';
|
|
18
|
-
|
|
17
|
+
import ColorGradientControl from './control'; // Conditionally wraps the `ColorGradientSettingsDropdown` color controls in an
|
|
18
|
+
// `ItemGroup` allowing for a standalone group of controls to be
|
|
19
|
+
// rendered semantically.
|
|
20
|
+
|
|
21
|
+
const WithItemGroup = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
__experimentalIsItemGroup,
|
|
24
|
+
children
|
|
25
|
+
} = _ref;
|
|
26
|
+
|
|
27
|
+
if (!__experimentalIsItemGroup) {
|
|
28
|
+
return children;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return createElement(ItemGroup, {
|
|
32
|
+
isBordered: true,
|
|
33
|
+
isSeparated: true,
|
|
34
|
+
className: "block-editor-panel-color-gradient-settings__item-group"
|
|
35
|
+
}, children);
|
|
36
|
+
}; // When the `ColorGradientSettingsDropdown` controls are being rendered to a
|
|
37
|
+
// `ToolsPanel` they must be wrapped in a `ToolsPanelItem`.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const WithToolsPanelItem = _ref2 => {
|
|
41
|
+
let {
|
|
42
|
+
__experimentalIsItemGroup,
|
|
43
|
+
settings,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
} = _ref2;
|
|
47
|
+
|
|
48
|
+
if (__experimentalIsItemGroup) {
|
|
49
|
+
return children;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return createElement(ToolsPanelItem, _extends({
|
|
53
|
+
hasValue: settings.hasValue,
|
|
54
|
+
label: settings.label,
|
|
55
|
+
onDeselect: settings.onDeselect,
|
|
56
|
+
isShownByDefault: settings.isShownByDefault,
|
|
57
|
+
resetAllFilter: settings.resetAllFilter
|
|
58
|
+
}, props, {
|
|
59
|
+
className: "block-editor-tools-panel-color-gradient-settings__item"
|
|
60
|
+
}), children);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const LabeledColorIndicator = _ref3 => {
|
|
64
|
+
let {
|
|
65
|
+
colorValue,
|
|
66
|
+
label
|
|
67
|
+
} = _ref3;
|
|
68
|
+
return createElement(HStack, {
|
|
69
|
+
justify: "flex-start"
|
|
70
|
+
}, createElement(ColorIndicator, {
|
|
71
|
+
className: "block-editor-panel-color-gradient-settings__color-indicator",
|
|
72
|
+
colorValue: colorValue
|
|
73
|
+
}), createElement(FlexItem, null, label));
|
|
74
|
+
}; // Renders a color dropdown's toggle as an `Item` if it is within an `ItemGroup`
|
|
75
|
+
// or as a `Button` if it isn't e.g. the controls are being rendered in
|
|
76
|
+
// a `ToolsPanel`.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const renderToggle = settings => _ref4 => {
|
|
80
|
+
let {
|
|
81
|
+
onToggle,
|
|
82
|
+
isOpen
|
|
83
|
+
} = _ref4;
|
|
84
|
+
const {
|
|
85
|
+
__experimentalIsItemGroup,
|
|
86
|
+
colorValue,
|
|
87
|
+
label
|
|
88
|
+
} = settings; // Determine component, `Item` or `Button`, to wrap color indicator with.
|
|
89
|
+
|
|
90
|
+
const ToggleComponent = __experimentalIsItemGroup ? Item : Button;
|
|
91
|
+
const toggleClassName = __experimentalIsItemGroup ? 'block-editor-panel-color-gradient-settings__item' : 'block-editor-panel-color-gradient-settings__dropdown';
|
|
92
|
+
const toggleProps = {
|
|
93
|
+
onClick: onToggle,
|
|
94
|
+
className: classnames(toggleClassName, {
|
|
95
|
+
'is-open': isOpen
|
|
96
|
+
}),
|
|
97
|
+
'aria-expanded': __experimentalIsItemGroup ? undefined : isOpen
|
|
98
|
+
};
|
|
99
|
+
return createElement(ToggleComponent, toggleProps, createElement(LabeledColorIndicator, {
|
|
100
|
+
colorValue: colorValue,
|
|
101
|
+
label: label
|
|
102
|
+
}));
|
|
103
|
+
}; // Renders a collection of color controls as dropdowns. Depending upon the
|
|
104
|
+
// context in which these dropdowns are being rendered, they may be wrapped
|
|
105
|
+
// in an `ItemGroup` with each dropdown's toggle as an `Item`, or alternatively,
|
|
106
|
+
// the may be individually wrapped in a `ToolsPanelItem` with the toggle as
|
|
107
|
+
// a regular `Button`.
|
|
108
|
+
//
|
|
109
|
+
// For more context see: https://github.com/WordPress/gutenberg/pull/40084
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
export default function ColorGradientSettingsDropdown(_ref5) {
|
|
19
113
|
let {
|
|
20
114
|
colors,
|
|
21
|
-
gradients,
|
|
22
115
|
disableCustomColors,
|
|
23
116
|
disableCustomGradients,
|
|
117
|
+
enableAlpha,
|
|
118
|
+
gradients,
|
|
119
|
+
__experimentalIsItemGroup = true,
|
|
120
|
+
settings,
|
|
24
121
|
__experimentalHasMultipleOrigins,
|
|
25
122
|
__experimentalIsRenderedInSidebar,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
123
|
+
...props
|
|
124
|
+
} = _ref5;
|
|
125
|
+
const dropdownClassName = __experimentalIsItemGroup ? 'block-editor-panel-color-gradient-settings__dropdown' : 'block-editor-tools-panel-color-gradient-settings__dropdown';
|
|
126
|
+
let popoverProps;
|
|
30
127
|
|
|
31
128
|
if (__experimentalIsRenderedInSidebar) {
|
|
32
|
-
|
|
129
|
+
popoverProps = {
|
|
130
|
+
placement: 'left-start',
|
|
131
|
+
offset: 36
|
|
132
|
+
};
|
|
33
133
|
}
|
|
34
134
|
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
key: index,
|
|
41
|
-
position: dropdownPosition,
|
|
42
|
-
className: "block-editor-panel-color-gradient-settings__dropdown",
|
|
43
|
-
contentClassName: "block-editor-panel-color-gradient-settings__dropdown-content",
|
|
44
|
-
renderToggle: _ref2 => {
|
|
135
|
+
return (// Only wrap with `ItemGroup` if these controls are being rendered
|
|
136
|
+
// semantically.
|
|
137
|
+
createElement(WithItemGroup, {
|
|
138
|
+
__experimentalIsItemGroup: __experimentalIsItemGroup
|
|
139
|
+
}, settings.map((setting, index) => {
|
|
45
140
|
var _setting$gradientValu;
|
|
46
141
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
142
|
+
const controlProps = {
|
|
143
|
+
clearable: __experimentalIsItemGroup ? undefined : false,
|
|
144
|
+
colorValue: setting.colorValue,
|
|
145
|
+
colors,
|
|
146
|
+
disableCustomColors,
|
|
147
|
+
disableCustomGradients,
|
|
148
|
+
enableAlpha,
|
|
149
|
+
gradientValue: setting.gradientValue,
|
|
150
|
+
gradients,
|
|
151
|
+
label: setting.label,
|
|
152
|
+
onColorChange: setting.onColorChange,
|
|
153
|
+
onGradientChange: setting.onGradientChange,
|
|
154
|
+
showTitle: false,
|
|
155
|
+
__experimentalHasMultipleOrigins,
|
|
156
|
+
__experimentalIsRenderedInSidebar,
|
|
157
|
+
...setting
|
|
158
|
+
};
|
|
159
|
+
const toggleSettings = {
|
|
160
|
+
colorValue: (_setting$gradientValu = setting.gradientValue) !== null && _setting$gradientValu !== void 0 ? _setting$gradientValu : setting.colorValue,
|
|
161
|
+
__experimentalIsItemGroup,
|
|
162
|
+
label: setting.label
|
|
163
|
+
};
|
|
164
|
+
return setting && // If not in an `ItemGroup` wrap the dropdown in a
|
|
165
|
+
// `ToolsPanelItem`
|
|
166
|
+
createElement(WithToolsPanelItem, _extends({
|
|
167
|
+
key: index,
|
|
168
|
+
__experimentalIsItemGroup: __experimentalIsItemGroup,
|
|
169
|
+
settings: setting
|
|
170
|
+
}, props), createElement(Dropdown, {
|
|
171
|
+
popoverProps: popoverProps,
|
|
172
|
+
className: dropdownClassName,
|
|
173
|
+
contentClassName: "block-editor-panel-color-gradient-settings__dropdown-content",
|
|
174
|
+
renderToggle: renderToggle(toggleSettings),
|
|
175
|
+
renderContent: () => createElement(ColorGradientControl, controlProps)
|
|
176
|
+
}));
|
|
177
|
+
}))
|
|
178
|
+
);
|
|
74
179
|
}
|
|
75
180
|
//# sourceMappingURL=dropdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/dropdown.js"],"names":["classnames","__experimentalItemGroup","ItemGroup","__experimentalItem","Item","__experimentalHStack","HStack","FlexItem","ColorIndicator","Dropdown","ColorGradientControl","ColorGradientSettingsDropdown","colors","gradients","disableCustomColors","disableCustomGradients","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","enableAlpha","settings","dropdownPosition","map","setting","index","isOpen","onToggle","gradientValue","colorValue","label"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,uBAAuB,IAAIC,SAD5B,EAECC,kBAAkB,IAAIC,IAFvB,EAGCC,oBAAoB,IAAIC,MAHzB,EAICC,QAJD,EAKCC,cALD,EAMCC,QAND,QAOO,uBAPP;AASA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,WAAjC;AAEA,eAAe,SAASC,6BAAT,OASX;AAAA,MATmD;AACtDC,IAAAA,MADsD;AAEtDC,IAAAA,SAFsD;AAGtDC,IAAAA,mBAHsD;AAItDC,IAAAA,sBAJsD;AAKtDC,IAAAA,gCALsD;AAMtDC,I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*/\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalHStack as HStack,\n\tFlexItem,\n\tColorIndicator,\n\tDropdown,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from './control';\n\nexport default function ColorGradientSettingsDropdown( {\n\tcolors,\n\tgradients,\n\tdisableCustomColors,\n\tdisableCustomGradients,\n\t__experimentalHasMultipleOrigins,\n\t__experimentalIsRenderedInSidebar,\n\tenableAlpha,\n\tsettings,\n} ) {\n\tlet dropdownPosition;\n\tif ( __experimentalIsRenderedInSidebar ) {\n\t\tdropdownPosition = 'bottom left';\n\t}\n\n\treturn (\n\t\t<ItemGroup\n\t\t\tisBordered\n\t\t\tisSeparated\n\t\t\tclassName=\"block-editor-panel-color-gradient-settings__item-group\"\n\t\t>\n\t\t\t{ settings.map(\n\t\t\t\t( setting, index ) =>\n\t\t\t\t\tsetting && (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\t\tposition={ dropdownPosition }\n\t\t\t\t\t\t\tclassName=\"block-editor-panel-color-gradient-settings__dropdown\"\n\t\t\t\t\t\t\tcontentClassName=\"block-editor-panel-color-gradient-settings__dropdown-content\"\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<Item\n\t\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t\t\t'block-editor-panel-color-gradient-settings__item',\n\t\t\t\t\t\t\t\t\t\t\t{ 'is-open': isOpen }\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t<ColorIndicator\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-panel-color-gradient-settings__color-indicator\"\n\t\t\t\t\t\t\t\t\t\t\t\tcolorValue={\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetting.gradientValue ??\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetting.colorValue\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t\t{ setting.label }\n\t\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t</Item>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\trenderContent={ () => (\n\t\t\t\t\t\t\t\t<ColorGradientControl\n\t\t\t\t\t\t\t\t\tshowTitle={ false }\n\t\t\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\t\t\tgradients,\n\t\t\t\t\t\t\t\t\t\tdisableCustomColors,\n\t\t\t\t\t\t\t\t\t\tdisableCustomGradients,\n\t\t\t\t\t\t\t\t\t\t__experimentalHasMultipleOrigins,\n\t\t\t\t\t\t\t\t\t\t__experimentalIsRenderedInSidebar,\n\t\t\t\t\t\t\t\t\t\tenableAlpha,\n\t\t\t\t\t\t\t\t\t\t...setting,\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t)\n\t\t\t) }\n\t\t</ItemGroup>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/colors-gradients/dropdown.js"],"names":["classnames","Button","ColorIndicator","Dropdown","FlexItem","__experimentalHStack","HStack","__experimentalItem","Item","__experimentalItemGroup","ItemGroup","__experimentalToolsPanelItem","ToolsPanelItem","ColorGradientControl","WithItemGroup","__experimentalIsItemGroup","children","WithToolsPanelItem","settings","props","hasValue","label","onDeselect","isShownByDefault","resetAllFilter","LabeledColorIndicator","colorValue","renderToggle","onToggle","isOpen","ToggleComponent","toggleClassName","toggleProps","onClick","className","undefined","ColorGradientSettingsDropdown","colors","disableCustomColors","disableCustomGradients","enableAlpha","gradients","__experimentalHasMultipleOrigins","__experimentalIsRenderedInSidebar","dropdownClassName","popoverProps","placement","offset","map","setting","index","controlProps","clearable","gradientValue","onColorChange","onGradientChange","showTitle","toggleSettings"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,MADD,EAECC,cAFD,EAGCC,QAHD,EAICC,QAJD,EAKCC,oBAAoB,IAAIC,MALzB,EAMCC,kBAAkB,IAAIC,IANvB,EAOCC,uBAAuB,IAAIC,SAP5B,EAQCC,4BAA4B,IAAIC,cARjC,QASO,uBATP;AAWA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,WAAjC,C,CAEA;AACA;AACA;;AACA,MAAMC,aAAa,GAAG,QAA+C;AAAA,MAA7C;AAAEC,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,GAA6C;;AACpE,MAAK,CAAED,yBAAP,EAAmC;AAClC,WAAOC,QAAP;AACA;;AAED,SACC,cAAC,SAAD;AACC,IAAA,UAAU,MADX;AAEC,IAAA,WAAW,MAFZ;AAGC,IAAA,SAAS,EAAC;AAHX,KAKGA,QALH,CADD;AASA,CAdD,C,CAgBA;AACA;;;AACA,MAAMC,kBAAkB,GAAG,SAKpB;AAAA,MALsB;AAC5BF,IAAAA,yBAD4B;AAE5BG,IAAAA,QAF4B;AAG5BF,IAAAA,QAH4B;AAI5B,OAAGG;AAJyB,GAKtB;;AACN,MAAKJ,yBAAL,EAAiC;AAChC,WAAOC,QAAP;AACA;;AAED,SACC,cAAC,cAAD;AACC,IAAA,QAAQ,EAAGE,QAAQ,CAACE,QADrB;A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AcpBC,QAAAA,iCAdoB;AAepB,WAAGM;AAfiB,OAArB;AAiBA,YAAMQ,cAAc,GAAG;AACtB/B,QAAAA,UAAU,2BAAEuB,OAAO,CAACI,aAAV,yEAA2BJ,OAAO,CAACvB,UADvB;AAEtBX,QAAAA,yBAFsB;AAGtBM,QAAAA,KAAK,EAAE4B,OAAO,CAAC5B;AAHO,OAAvB;AAMA,aACC4B,OAAO,IACN;AACA;AACA,oBAAC,kBAAD;AACC,QAAA,GAAG,EAAGC,KADP;AAEC,QAAA,yBAAyB,EACxBnC,yBAHF;AAKC,QAAA,QAAQ,EAAGkC;AALZ,SAMM9B,KANN,GAQC,cAAC,QAAD;AACC,QAAA,YAAY,EAAG0B,YADhB;AAEC,QAAA,SAAS,EAAGD,iBAFb;AAGC,QAAA,gBAAgB,EAAC,8DAHlB;AAIC,QAAA,YAAY,EAAGjB,YAAY,CAAE8B,cAAF,CAJ5B;AAKC,QAAA,aAAa,EAAG,MACf,cAAC,oBAAD,EAA2BN,YAA3B;AANF,QARD,CAJF;AAwBA,KAhDC,CADH;AAHD;AAuDA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tColorIndicator,\n\tDropdown,\n\tFlexItem,\n\t__experimentalHStack as HStack,\n\t__experimentalItem as Item,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientControl from './control';\n\n// Conditionally wraps the `ColorGradientSettingsDropdown` color controls in an\n// `ItemGroup` allowing for a standalone group of controls to be\n// rendered semantically.\nconst WithItemGroup = ( { __experimentalIsItemGroup, children } ) => {\n\tif ( ! __experimentalIsItemGroup ) {\n\t\treturn children;\n\t}\n\n\treturn (\n\t\t<ItemGroup\n\t\t\tisBordered\n\t\t\tisSeparated\n\t\t\tclassName=\"block-editor-panel-color-gradient-settings__item-group\"\n\t\t>\n\t\t\t{ children }\n\t\t</ItemGroup>\n\t);\n};\n\n// When the `ColorGradientSettingsDropdown` controls are being rendered to a\n// `ToolsPanel` they must be wrapped in a `ToolsPanelItem`.\nconst WithToolsPanelItem = ( {\n\t__experimentalIsItemGroup,\n\tsettings,\n\tchildren,\n\t...props\n} ) => {\n\tif ( __experimentalIsItemGroup ) {\n\t\treturn children;\n\t}\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ settings.hasValue }\n\t\t\tlabel={ settings.label }\n\t\t\tonDeselect={ settings.onDeselect }\n\t\t\tisShownByDefault={ settings.isShownByDefault }\n\t\t\tresetAllFilter={ settings.resetAllFilter }\n\t\t\t{ ...props }\n\t\t\tclassName=\"block-editor-tools-panel-color-gradient-settings__item\"\n\t\t>\n\t\t\t{ children }\n\t\t</ToolsPanelItem>\n\t);\n};\n\nconst LabeledColorIndicator = ( { colorValue, label } ) => (\n\t<HStack justify=\"flex-start\">\n\t\t<ColorIndicator\n\t\t\tclassName=\"block-editor-panel-color-gradient-settings__color-indicator\"\n\t\t\tcolorValue={ colorValue }\n\t\t/>\n\t\t<FlexItem>{ label }</FlexItem>\n\t</HStack>\n);\n\n// Renders a color dropdown's toggle as an `Item` if it is within an `ItemGroup`\n// or as a `Button` if it isn't e.g. the controls are being rendered in\n// a `ToolsPanel`.\nconst renderToggle = ( settings ) => ( { onToggle, isOpen } ) => {\n\tconst { __experimentalIsItemGroup, colorValue, label } = settings;\n\n\t// Determine component, `Item` or `Button`, to wrap color indicator with.\n\tconst ToggleComponent = __experimentalIsItemGroup ? Item : Button;\n\tconst toggleClassName = __experimentalIsItemGroup\n\t\t? 'block-editor-panel-color-gradient-settings__item'\n\t\t: 'block-editor-panel-color-gradient-settings__dropdown';\n\tconst toggleProps = {\n\t\tonClick: onToggle,\n\t\tclassName: classnames( toggleClassName, { 'is-open': isOpen } ),\n\t\t'aria-expanded': __experimentalIsItemGroup ? undefined : isOpen,\n\t};\n\n\treturn (\n\t\t<ToggleComponent { ...toggleProps }>\n\t\t\t<LabeledColorIndicator colorValue={ colorValue } label={ label } />\n\t\t</ToggleComponent>\n\t);\n};\n\n// Renders a collection of color controls as dropdowns. Depending upon the\n// context in which these dropdowns are being rendered, they may be wrapped\n// in an `ItemGroup` with each dropdown's toggle as an `Item`, or alternatively,\n// the may be individually wrapped in a `ToolsPanelItem` with the toggle as\n// a regular `Button`.\n//\n// For more context see: https://github.com/WordPress/gutenberg/pull/40084\nexport default function ColorGradientSettingsDropdown( {\n\tcolors,\n\tdisableCustomColors,\n\tdisableCustomGradients,\n\tenableAlpha,\n\tgradients,\n\t__experimentalIsItemGroup = true,\n\tsettings,\n\t__experimentalHasMultipleOrigins,\n\t__experimentalIsRenderedInSidebar,\n\t...props\n} ) {\n\tconst dropdownClassName = __experimentalIsItemGroup\n\t\t? 'block-editor-panel-color-gradient-settings__dropdown'\n\t\t: 'block-editor-tools-panel-color-gradient-settings__dropdown';\n\tlet popoverProps;\n\tif ( __experimentalIsRenderedInSidebar ) {\n\t\tpopoverProps = {\n\t\t\tplacement: 'left-start',\n\t\t\toffset: 36,\n\t\t};\n\t}\n\n\treturn (\n\t\t// Only wrap with `ItemGroup` if these controls are being rendered\n\t\t// semantically.\n\t\t<WithItemGroup __experimentalIsItemGroup={ __experimentalIsItemGroup }>\n\t\t\t{ settings.map( ( setting, index ) => {\n\t\t\t\tconst controlProps = {\n\t\t\t\t\tclearable: __experimentalIsItemGroup ? undefined : false,\n\t\t\t\t\tcolorValue: setting.colorValue,\n\t\t\t\t\tcolors,\n\t\t\t\t\tdisableCustomColors,\n\t\t\t\t\tdisableCustomGradients,\n\t\t\t\t\tenableAlpha,\n\t\t\t\t\tgradientValue: setting.gradientValue,\n\t\t\t\t\tgradients,\n\t\t\t\t\tlabel: setting.label,\n\t\t\t\t\tonColorChange: setting.onColorChange,\n\t\t\t\t\tonGradientChange: setting.onGradientChange,\n\t\t\t\t\tshowTitle: false,\n\t\t\t\t\t__experimentalHasMultipleOrigins,\n\t\t\t\t\t__experimentalIsRenderedInSidebar,\n\t\t\t\t\t...setting,\n\t\t\t\t};\n\t\t\t\tconst toggleSettings = {\n\t\t\t\t\tcolorValue: setting.gradientValue ?? setting.colorValue,\n\t\t\t\t\t__experimentalIsItemGroup,\n\t\t\t\t\tlabel: setting.label,\n\t\t\t\t};\n\n\t\t\t\treturn (\n\t\t\t\t\tsetting && (\n\t\t\t\t\t\t// If not in an `ItemGroup` wrap the dropdown in a\n\t\t\t\t\t\t// `ToolsPanelItem`\n\t\t\t\t\t\t<WithToolsPanelItem\n\t\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\t\t__experimentalIsItemGroup={\n\t\t\t\t\t\t\t\t__experimentalIsItemGroup\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsettings={ setting }\n\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t\t\t\tclassName={ dropdownClassName }\n\t\t\t\t\t\t\t\tcontentClassName=\"block-editor-panel-color-gradient-settings__dropdown-content\"\n\t\t\t\t\t\t\t\trenderToggle={ renderToggle( toggleSettings ) }\n\t\t\t\t\t\t\t\trenderContent={ () => (\n\t\t\t\t\t\t\t\t\t<ColorGradientControl { ...controlProps } />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</WithToolsPanelItem>\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</WithItemGroup>\n\t);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import classnames from 'classnames';
|
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { useState, createPortal, forwardRef,
|
|
12
|
+
import { useState, createPortal, forwardRef, useMemo, useReducer } from '@wordpress/element';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
14
14
|
import { useMergeRefs, useRefEffect } from '@wordpress/compose';
|
|
15
15
|
import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
|
|
@@ -28,63 +28,63 @@ const BLOCK_PREFIX = 'wp-block';
|
|
|
28
28
|
*
|
|
29
29
|
* Ideally, this hook should be removed in the future and styles should be added
|
|
30
30
|
* explicitly as editor styles.
|
|
31
|
-
*
|
|
32
|
-
* @param {Document} doc The document to append cloned stylesheets to.
|
|
33
31
|
*/
|
|
34
32
|
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
function useStylesCompatibility() {
|
|
34
|
+
return useRefEffect(node => {
|
|
35
|
+
// Search the document for stylesheets targetting the editor canvas.
|
|
36
|
+
Array.from(document.styleSheets).forEach(styleSheet => {
|
|
37
|
+
try {
|
|
38
|
+
// May fail for external styles.
|
|
39
|
+
// eslint-disable-next-line no-unused-expressions
|
|
40
|
+
styleSheet.cssRules;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const {
|
|
46
|
+
ownerNode,
|
|
47
|
+
cssRules
|
|
48
|
+
} = styleSheet;
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (!cssRules) {
|
|
51
|
+
return;
|
|
52
|
+
} // Generally, ignore inline styles. We add inline styles belonging to a
|
|
53
|
+
// stylesheet later, which may or may not match the selectors.
|
|
55
54
|
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (ownerNode.tagName !== 'LINK') {
|
|
57
|
+
return;
|
|
58
|
+
} // Don't try to add the reset styles, which were removed as a dependency
|
|
59
|
+
// from `edit-blocks` for the iframe since we don't need to reset admin
|
|
60
|
+
// styles.
|
|
62
61
|
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (ownerNode.id === 'wp-reset-editor-styles-css') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const isMatch = Array.from(cssRules).find(_ref => {
|
|
68
|
+
let {
|
|
69
|
+
selectorText
|
|
70
|
+
} = _ref;
|
|
71
|
+
return selectorText && (selectorText.includes(`.${BODY_CLASS_NAME}`) || selectorText.includes(`.${BLOCK_PREFIX}`));
|
|
72
|
+
});
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
if (isMatch && !node.ownerDocument.getElementById(ownerNode.id)) {
|
|
75
|
+
// Display warning once we have a way to add style dependencies to the editor.
|
|
76
|
+
// See: https://github.com/WordPress/gutenberg/pull/37466.
|
|
77
|
+
node.appendChild(ownerNode.cloneNode(true)); // Add inline styles belonging to the stylesheet.
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const inlineCssId = ownerNode.id.replace('-css', '-inline-css');
|
|
80
|
+
const inlineCssElement = document.getElementById(inlineCssId);
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
if (inlineCssElement) {
|
|
83
|
+
node.appendChild(inlineCssElement.cloneNode(true));
|
|
84
|
+
}
|
|
85
85
|
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
86
|
+
});
|
|
87
|
+
}, []);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Bubbles some event types (keydown, keypress, and dragover) to parent document
|
|
@@ -224,11 +224,7 @@ function Iframe(_ref3, ref) {
|
|
|
224
224
|
});
|
|
225
225
|
}, []);
|
|
226
226
|
const bodyRef = useMergeRefs([contentRef, clearerRef, writingFlowRef]);
|
|
227
|
-
|
|
228
|
-
if (iframeDocument) {
|
|
229
|
-
styleSheetsCompat(iframeDocument);
|
|
230
|
-
}
|
|
231
|
-
}, [iframeDocument]);
|
|
227
|
+
const styleCompatibilityRef = useStylesCompatibility();
|
|
232
228
|
head = createElement(Fragment, null, createElement("style", null, 'body{margin:0}'), styles.map(_ref4 => {
|
|
233
229
|
let {
|
|
234
230
|
tagName,
|
|
@@ -266,7 +262,12 @@ function Iframe(_ref3, ref) {
|
|
|
266
262
|
}, head), createElement("body", {
|
|
267
263
|
ref: bodyRef,
|
|
268
264
|
className: classnames(BODY_CLASS_NAME, ...bodyClasses)
|
|
269
|
-
}, createElement(
|
|
265
|
+
}, createElement("div", {
|
|
266
|
+
style: {
|
|
267
|
+
display: 'none'
|
|
268
|
+
},
|
|
269
|
+
ref: styleCompatibilityRef
|
|
270
|
+
}), createElement(StyleProvider, {
|
|
270
271
|
document: iframeDocument
|
|
271
272
|
}, children))), iframeDocument.documentElement)), tabIndex >= 0 && after);
|
|
272
273
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useEffect","useMemo","useReducer","__","useMergeRefs","useRefEffect","__experimentalStyleProvider","StyleProvider","useBlockSelectionClearer","useWritingFlow","BODY_CLASS_NAME","BLOCK_PREFIX","styleSheetsCompat","doc","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","getElementById","head","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","bubbleEvents","defaultView","frameElement","bubbleEvent","event","prototype","Object","getPrototypeOf","constructorName","constructor","name","Constructor","window","init","key","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","cancelled","dispatchEvent","preventDefault","eventTypes","addEventListener","useParsedAssets","html","implementation","createHTMLDocument","body","innerHTML","children","loadScript","src","Promise","resolve","reject","script","ownerDocument","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","node","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","map","href","rel","media","textContent","TagName","toLowerCase"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,YAFD,EAGCC,UAHD,EAICC,SAJD,EAKCC,OALD,EAMCC,UAND,QAOO,oBAPP;AAQA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,2BAA2B,IAAIC,aAAxC,QAA6D,uBAA7D;AAEA;AACA;AACA;;AACA,SAASC,wBAAT,QAAyC,4BAAzC;AACA,SAASC,cAAT,QAA+B,iBAA/B;AAEA,MAAMC,eAAe,GAAG,uBAAxB;AACA,MAAMC,YAAY,GAAG,UAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,iBAAT,CAA4BC,GAA5B,EAAkC;AACjC;AACAC,EAAAA,KAAK,CAACC,IAAN,CAAYC,QAAQ,CAACC,WAArB,EAAmCC,OAAnC,CAA8CC,UAAF,IAAkB;AAC7D,QAAI;AACH;AACA;AACAA,MAAAA,UAAU,CAACC,QAAX;AACA,KAJD,CAIE,OAAQC,CAAR,EAAY;AACb;AACA;;AAED,UAAM;AAAEC,MAAAA,SAAF;AAAaF,MAAAA;AAAb,QAA0BD,UAAhC;;AAEA,QAAK,CAAEC,QAAP,EAAkB;AACjB;AACA,KAb4D,CAe7D;AACA;;;AACA,QAAKE,SAAS,CAACC,OAAV,KAAsB,MAA3B,EAAoC;AACnC;AACA,KAnB4D,CAqB7D;AACA;AACA;;;AACA,QAAKD,SAAS,CAACE,EAAV,KAAiB,4BAAtB,EAAqD;AACpD;AAC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GnF,YAAY,CAAE,CAAE+E,GAAF,EAAOgB,MAAP,CAAF,CAFnB;AAGC,IAAA,QAAQ,EAAGd,QAHZ,CAIC;AAJD;AAKC,IAAA,MAAM,EAAC,iBALR;AAMC,IAAA,KAAK,EAAGlF,EAAE,CAAE,eAAF;AANX,MAQGsF,cAAc,IACf3F,YAAY,CACX,8BACC;AAAM,IAAA,GAAG,EAAGiH;AAAZ,KAAwBjF,IAAxB,CADD,EAEC;AACC,IAAA,GAAG,EAAGuF,OADP;AAEC,IAAA,SAAS,EAAGzH,UAAU,CACrBc,eADqB,EAErB,GAAGiF,WAFkB;AAFvB,KAOC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAGF;AAA1B,KACGlB,QADH,CAPD,CAFD,CADW,EAeXkB,cAAc,CAACe,eAfJ,CATd,CAFD,EA6BGnB,QAAQ,IAAI,CAAZ,IAAiBa,KA7BpB,CADD;AAiCA;;AAED,eAAenG,UAAU,CAAEmF,MAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n *\n * @param {Document} doc The document to append cloned stylesheets to.\n */\nfunction styleSheetsCompat( doc ) {\n\t// Search the document for stylesheets targetting the editor canvas.\n\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\ttry {\n\t\t\t// May fail for external styles.\n\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\tstyleSheet.cssRules;\n\t\t} catch ( e ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\tif ( ! cssRules ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t// stylesheet later, which may or may not match the selectors.\n\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t// styles.\n\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t( { selectorText } ) =>\n\t\t\t\tselectorText &&\n\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t);\n\n\t\tif ( isMatch && ! doc.getElementById( ownerNode.id ) ) {\n\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\n\t\t\tdoc.head.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\tconst inlineCssId = ownerNode.id.replace( '-css', '-inline-css' );\n\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\tif ( inlineCssElement ) {\n\t\t\t\tdoc.head.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} doc Document to attach listeners to.\n */\nfunction bubbleEvents( doc ) {\n\tconst { defaultView } = doc;\n\tconst { frameElement } = defaultView;\n\n\tfunction bubbleEvent( event ) {\n\t\tconst prototype = Object.getPrototypeOf( event );\n\t\tconst constructorName = prototype.constructor.name;\n\t\tconst Constructor = window[ constructorName ];\n\n\t\tconst init = {};\n\n\t\tfor ( const key in event ) {\n\t\t\tinit[ key ] = event[ key ];\n\t\t}\n\n\t\tif ( event instanceof defaultView.MouseEvent ) {\n\t\t\tconst rect = frameElement.getBoundingClientRect();\n\t\t\tinit.clientX += rect.left;\n\t\t\tinit.clientY += rect.top;\n\t\t}\n\n\t\tconst newEvent = new Constructor( event.type, init );\n\t\tconst cancelled = ! frameElement.dispatchEvent( newEvent );\n\n\t\tif ( cancelled ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n\n\tconst eventTypes = [ 'dragover' ];\n\n\tfor ( const name of eventTypes ) {\n\t\tdoc.addEventListener( name, bubbleEvent );\n\t}\n}\n\nfunction useParsedAssets( html ) {\n\treturn useMemo( () => {\n\t\tconst doc = document.implementation.createHTMLDocument( '' );\n\t\tdoc.body.innerHTML = html;\n\t\treturn Array.from( doc.body.children );\n\t}, [ html ] );\n}\n\nasync function loadScript( head, { id, src } ) {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst script = head.ownerDocument.createElement( 'script' );\n\t\tscript.id = id;\n\t\tif ( src ) {\n\t\t\tscript.src = src;\n\t\t\tscript.onload = () => resolve();\n\t\t\tscript.onerror = () => reject();\n\t\t} else {\n\t\t\tresolve();\n\t\t}\n\t\thead.appendChild( script );\n\t} );\n}\n\nfunction Iframe(\n\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tbubbleEvents( contentDocument );\n\t\t\tsetIframeDocument( contentDocument );\n\t\t\tclearerRef( documentElement );\n\n\t\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t\t// the server in the future (which will run the PHP filters).\n\t\t\tsetBodyClasses(\n\t\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\t\t\tdocumentElement.removeChild( contentDocument.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\n\tconst headRef = useRefEffect( ( element ) => {\n\t\tscripts\n\t\t\t.reduce(\n\t\t\t\t( promise, script ) =>\n\t\t\t\t\tpromise.then( () => loadScript( element, script ) ),\n\t\t\t\tPromise.resolve()\n\t\t\t)\n\t\t\t.finally( () => {\n\t\t\t\t// When script are loaded, re-render blocks to allow them\n\t\t\t\t// to initialise.\n\t\t\t\tforceRender();\n\t\t\t} );\n\t}, [] );\n\tconst bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\n\tuseEffect( () => {\n\t\tif ( iframeDocument ) {\n\t\t\tstyleSheetsCompat( iframeDocument );\n\t\t}\n\t}, [ iframeDocument ] );\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ tabIndex >= 0 && before }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\n\t\t\t\ttitle={ __( 'Editor canvas' ) }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ tabIndex >= 0 && after }\n\t\t</>\n\t);\n}\n\nexport default forwardRef( Iframe );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useMemo","useReducer","__","useMergeRefs","useRefEffect","__experimentalStyleProvider","StyleProvider","useBlockSelectionClearer","useWritingFlow","BODY_CLASS_NAME","BLOCK_PREFIX","useStylesCompatibility","node","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","ownerDocument","getElementById","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","bubbleEvents","doc","defaultView","frameElement","bubbleEvent","event","prototype","Object","getPrototypeOf","constructorName","constructor","name","Constructor","window","init","key","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","cancelled","dispatchEvent","preventDefault","eventTypes","addEventListener","useParsedAssets","html","implementation","createHTMLDocument","body","innerHTML","children","loadScript","head","src","Promise","resolve","reject","script","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","styleCompatibilityRef","map","href","rel","media","textContent","TagName","toLowerCase","display"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,YAFD,EAGCC,UAHD,EAICC,OAJD,EAKCC,UALD,QAMO,oBANP;AAOA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X,KADT;AAEC,IAAA,GAAG,EAAGR;AAFP,IAZD,EAgBC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAG5B;AAA1B,KACGlB,QADH,CAhBD,CAFD,CADW,EAwBXkB,cAAc,CAACc,eAxBJ,CATd,CAFD,EAsCGlB,QAAQ,IAAI,CAAZ,IAAiBa,KAtCpB,CADD;AA0CA;;AAED,eAAenG,UAAU,CAAEmF,MAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n */\nfunction useStylesCompatibility() {\n\treturn useRefEffect( ( node ) => {\n\t\t// Search the document for stylesheets targetting the editor canvas.\n\t\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\t\ttry {\n\t\t\t\t// May fail for external styles.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tstyleSheet.cssRules;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\t\tif ( ! cssRules ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t\t// stylesheet later, which may or may not match the selectors.\n\t\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t\t// styles.\n\t\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t\t( { selectorText } ) =>\n\t\t\t\t\tselectorText &&\n\t\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t\t);\n\n\t\t\tif (\n\t\t\t\tisMatch &&\n\t\t\t\t! node.ownerDocument.getElementById( ownerNode.id )\n\t\t\t) {\n\t\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\t\t\t\tnode.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\t\tconst inlineCssId = ownerNode.id.replace(\n\t\t\t\t\t'-css',\n\t\t\t\t\t'-inline-css'\n\t\t\t\t);\n\t\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\t\tif ( inlineCssElement ) {\n\t\t\t\t\tnode.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}, [] );\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} doc Document to attach listeners to.\n */\nfunction bubbleEvents( doc ) {\n\tconst { defaultView } = doc;\n\tconst { frameElement } = defaultView;\n\n\tfunction bubbleEvent( event ) {\n\t\tconst prototype = Object.getPrototypeOf( event );\n\t\tconst constructorName = prototype.constructor.name;\n\t\tconst Constructor = window[ constructorName ];\n\n\t\tconst init = {};\n\n\t\tfor ( const key in event ) {\n\t\t\tinit[ key ] = event[ key ];\n\t\t}\n\n\t\tif ( event instanceof defaultView.MouseEvent ) {\n\t\t\tconst rect = frameElement.getBoundingClientRect();\n\t\t\tinit.clientX += rect.left;\n\t\t\tinit.clientY += rect.top;\n\t\t}\n\n\t\tconst newEvent = new Constructor( event.type, init );\n\t\tconst cancelled = ! frameElement.dispatchEvent( newEvent );\n\n\t\tif ( cancelled ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n\n\tconst eventTypes = [ 'dragover' ];\n\n\tfor ( const name of eventTypes ) {\n\t\tdoc.addEventListener( name, bubbleEvent );\n\t}\n}\n\nfunction useParsedAssets( html ) {\n\treturn useMemo( () => {\n\t\tconst doc = document.implementation.createHTMLDocument( '' );\n\t\tdoc.body.innerHTML = html;\n\t\treturn Array.from( doc.body.children );\n\t}, [ html ] );\n}\n\nasync function loadScript( head, { id, src } ) {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst script = head.ownerDocument.createElement( 'script' );\n\t\tscript.id = id;\n\t\tif ( src ) {\n\t\t\tscript.src = src;\n\t\t\tscript.onload = () => resolve();\n\t\t\tscript.onerror = () => reject();\n\t\t} else {\n\t\t\tresolve();\n\t\t}\n\t\thead.appendChild( script );\n\t} );\n}\n\nfunction Iframe(\n\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tbubbleEvents( contentDocument );\n\t\t\tsetIframeDocument( contentDocument );\n\t\t\tclearerRef( documentElement );\n\n\t\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t\t// the server in the future (which will run the PHP filters).\n\t\t\tsetBodyClasses(\n\t\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\t\t\tdocumentElement.removeChild( contentDocument.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\n\tconst headRef = useRefEffect( ( element ) => {\n\t\tscripts\n\t\t\t.reduce(\n\t\t\t\t( promise, script ) =>\n\t\t\t\t\tpromise.then( () => loadScript( element, script ) ),\n\t\t\t\tPromise.resolve()\n\t\t\t)\n\t\t\t.finally( () => {\n\t\t\t\t// When script are loaded, re-render blocks to allow them\n\t\t\t\t// to initialise.\n\t\t\t\tforceRender();\n\t\t\t} );\n\t}, [] );\n\tconst bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\tconst styleCompatibilityRef = useStylesCompatibility();\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ tabIndex >= 0 && before }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\n\t\t\t\ttitle={ __( 'Editor canvas' ) }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ /*\n\t\t\t\t\t\t\t\t * This is a wrapper for the extra styles and scripts\n\t\t\t\t\t\t\t\t * rendered imperatively by cloning the parent,\n\t\t\t\t\t\t\t\t * it's important that this div's content remains uncontrolled.\n\t\t\t\t\t\t\t\t */ }\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tstyle={ { display: 'none' } }\n\t\t\t\t\t\t\t\t\tref={ styleCompatibilityRef }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ tabIndex >= 0 && after }\n\t\t</>\n\t);\n}\n\nexport default forwardRef( Iframe );\n"]}
|
|
@@ -6,6 +6,7 @@ import { useDispatch } from '@wordpress/data';
|
|
|
6
6
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
7
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
8
8
|
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
9
10
|
export default function useSaveImage(_ref) {
|
|
10
11
|
let {
|
|
11
12
|
crop,
|
|
@@ -53,7 +54,7 @@ export default function useSaveImage(_ref) {
|
|
|
53
54
|
}).catch(error => {
|
|
54
55
|
createErrorNotice(sprintf(
|
|
55
56
|
/* translators: 1. Error message */
|
|
56
|
-
__('Could not edit image. %s'), error.message), {
|
|
57
|
+
__('Could not edit image. %s'), stripHTML(error.message)), {
|
|
57
58
|
id: 'image-editing-error',
|
|
58
59
|
type: 'snackbar'
|
|
59
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","useSaveImage","crop","rotation","height","width","aspect","url","id","onSaveImage","onFinishEditing","createErrorNotice","isInProgress","setIsInProgress","cancel","apply","attrs","src","path","method","data","then","response","source_url","undefined","catch","error","message","type","finally"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AAEA,eAAe,SAASC,YAAT,OAUX;AAAA,MAVkC;AACrCC,IAAAA,IADqC;AAErCC,IAAAA,QAFqC;AAGrCC,IAAAA,MAHqC;AAIrCC,IAAAA,KAJqC;AAKrCC,IAAAA,MALqC;AAMrCC,IAAAA,GANqC;AAOrCC,IAAAA,EAPqC;AAQrCC,IAAAA,WARqC;AASrCC,IAAAA;AATqC,GAUlC;AACH,QAAM;AAAEC,IAAAA;AAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","useSaveImage","crop","rotation","height","width","aspect","url","id","onSaveImage","onFinishEditing","createErrorNotice","isInProgress","setIsInProgress","cancel","apply","attrs","src","path","method","data","then","response","source_url","undefined","catch","error","message","type","finally"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AACA,SAASC,mBAAmB,IAAIC,SAAhC,QAAiD,gBAAjD;AAEA,eAAe,SAASC,YAAT,OAUX;AAAA,MAVkC;AACrCC,IAAAA,IADqC;AAErCC,IAAAA,QAFqC;AAGrCC,IAAAA,MAHqC;AAIrCC,IAAAA,KAJqC;AAKrCC,IAAAA,MALqC;AAMrCC,IAAAA,GANqC;AAOrCC,IAAAA,EAPqC;AAQrCC,IAAAA,WARqC;AASrCC,IAAAA;AATqC,GAUlC;AACH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,CAAE,0BAAF,CAFI,EAGNK,SAAS,CAAE0B,KAAK,CAACC,OAAR,CAHH,CADS,EAMhB;AACCnB,QAAAA,EAAE,EAAE,qBADL;AAECoB,QAAAA,IAAI,EAAE;AAFP,OANgB,CAAjB;AAWA,KAxBF,EAyBEC,OAzBF,CAyBW,MAAM;AACfhB,MAAAA,eAAe,CAAE,KAAF,CAAf;AACAH,MAAAA,eAAe;AACf,KA5BF;AA6BA,GA9CwB,EA8CtB,CACFG,eADE,EAEFX,IAFE,EAGFC,QAHE,EAIFC,MAJE,EAKFC,KALE,EAMFC,MANE,EAOFC,GAPE,EAQFE,WARE,EASFE,iBATE,EAUFE,eAVE,EAWFH,eAXE,CA9CsB,CAAzB;AA4DA,SAAOjB,OAAO,CACb,OAAQ;AACPmB,IAAAA,YADO;AAEPG,IAAAA,KAFO;AAGPD,IAAAA;AAHO,GAAR,CADa,EAMb,CAAEF,YAAF,EAAgBG,KAAhB,EAAuBD,MAAvB,CANa,CAAd;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\nexport default function useSaveImage( {\n\tcrop,\n\trotation,\n\theight,\n\twidth,\n\taspect,\n\turl,\n\tid,\n\tonSaveImage,\n\tonFinishEditing,\n} ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst [ isInProgress, setIsInProgress ] = useState( false );\n\n\tconst cancel = useCallback( () => {\n\t\tsetIsInProgress( false );\n\t\tonFinishEditing();\n\t}, [ setIsInProgress, onFinishEditing ] );\n\n\tconst apply = useCallback( () => {\n\t\tsetIsInProgress( true );\n\n\t\tlet attrs = {};\n\n\t\t// The crop script may return some very small, sub-pixel values when the image was not cropped.\n\t\t// Crop only when the new size has changed by more than 0.1%.\n\t\tif ( crop.width < 99.9 || crop.height < 99.9 ) {\n\t\t\tattrs = crop;\n\t\t}\n\n\t\tif ( rotation > 0 ) {\n\t\t\tattrs.rotation = rotation;\n\t\t}\n\n\t\tattrs.src = url;\n\n\t\tapiFetch( {\n\t\t\tpath: `/wp/v2/media/${ id }/edit`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: attrs,\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tonSaveImage( {\n\t\t\t\t\tid: response.id,\n\t\t\t\t\turl: response.source_url,\n\t\t\t\t\theight: height && width ? width / aspect : undefined,\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: 1. Error message */\n\t\t\t\t\t\t__( 'Could not edit image. %s' ),\n\t\t\t\t\t\tstripHTML( error.message )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tsetIsInProgress( false );\n\t\t\t\tonFinishEditing();\n\t\t\t} );\n\t}, [\n\t\tsetIsInProgress,\n\t\tcrop,\n\t\trotation,\n\t\theight,\n\t\twidth,\n\t\taspect,\n\t\turl,\n\t\tonSaveImage,\n\t\tcreateErrorNotice,\n\t\tsetIsInProgress,\n\t\tonFinishEditing,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tisInProgress,\n\t\t\tapply,\n\t\t\tcancel,\n\t\t} ),\n\t\t[ isInProgress, apply, cancel ]\n\t);\n}\n"]}
|
|
@@ -10,7 +10,7 @@ export { BlockAlignmentControl, BlockAlignmentToolbar } from './block-alignment-
|
|
|
10
10
|
export { default as __experimentalBlockFullHeightAligmentControl } from './block-full-height-alignment-control';
|
|
11
11
|
export { default as __experimentalBlockAlignmentMatrixControl } from './block-alignment-matrix-control';
|
|
12
12
|
export { default as BlockBreadcrumb } from './block-breadcrumb';
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as __experimentalUseBlockOverlayActive } from './block-content-overlay';
|
|
14
14
|
export { BlockContextProvider } from './block-context';
|
|
15
15
|
export { default as BlockControls, BlockFormatControls } from './block-controls';
|
|
16
16
|
export { default as BlockColorsStyleSelector } from './color-style-selector';
|
|
@@ -38,7 +38,6 @@ export { default as __experimentalTextTransformControl } from './text-transform-
|
|
|
38
38
|
export { default as __experimentalColorGradientControl } from './colors-gradients/control';
|
|
39
39
|
export { default as __experimentalColorGradientSettingsDropdown } from './colors-gradients/dropdown';
|
|
40
40
|
export { default as __experimentalPanelColorGradientSettings } from './colors-gradients/panel-color-gradient-settings';
|
|
41
|
-
export { default as __experimentalToolsPanelColorDropdown } from './colors-gradients/tools-panel-color-dropdown';
|
|
42
41
|
export { default as __experimentalImageEditor, ImageEditingProvider as __experimentalImageEditingProvider } from './image-editor';
|
|
43
42
|
export { default as __experimentalImageSizeControl } from './image-size-control';
|
|
44
43
|
export { default as InnerBlocks, useInnerBlocksProps } from './inner-blocks';
|