@wordpress/block-editor 12.4.0 → 12.5.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 +5 -0
- package/build/components/block-heading-level-dropdown/heading-level-icon.js +10 -2
- package/build/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build/components/block-lock/toolbar.js +25 -6
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +3 -6
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +8 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +18 -25
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +8 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +7 -11
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build/components/dimensions-tool/index.js +207 -0
- package/build/components/dimensions-tool/index.js.map +1 -0
- package/build/components/dimensions-tool/scale-tool.js +111 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build/components/dimensions-tool/width-height-tool.js +125 -0
- package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build/components/global-styles/color-panel.js +1 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/filters-panel.js +1 -1
- package/build/components/global-styles/filters-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +2 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +34 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +1 -2
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +19 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +7 -35
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +2 -21
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +62 -0
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build/components/inserter/reusable-blocks-tab.js +6 -2
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +1 -1
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +9 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/link-control/constants.js +1 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/index.js +17 -15
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-create-button.js +5 -21
- package/build/components/link-control/search-create-button.js.map +1 -1
- package/build/components/link-control/search-input.js +4 -4
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/search-item.js +13 -30
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/search-results.js +2 -2
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +2 -3
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/list-view/appender.js +2 -6
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/provider/index.js +5 -2
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-sync.js +21 -0
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/resolution-tool/index.js +55 -0
- package/build/components/resolution-tool/index.js.map +1 -0
- package/build/components/url-input/index.js +4 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +10 -27
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-mode-control/index.js +70 -0
- package/build/components/writing-mode-control/index.js.map +1 -0
- package/build/hooks/behaviors.js +25 -20
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/supports.js +7 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +2 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +4 -2
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +10 -1
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +3 -0
- package/build/private-apis.native.js.map +1 -1
- package/build/store/actions.js +195 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +1 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +10 -1
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +46 -40
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +22 -8
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -15
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js +9 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build-module/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +25 -7
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +20 -24
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -5
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/index.js +195 -0
- package/build-module/components/dimensions-tool/index.js.map +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js +103 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
- package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +1 -1
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/filters-panel.js +2 -2
- package/build-module/components/global-styles/filters-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +2 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +33 -2
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +1 -2
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +5 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/index.js +6 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +7 -33
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +2 -21
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +48 -0
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build-module/components/inserter/reusable-blocks-tab.js +5 -2
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +1 -1
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +9 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/link-control/constants.js +1 -1
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/index.js +17 -15
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-create-button.js +7 -20
- package/build-module/components/link-control/search-create-button.js.map +1 -1
- package/build-module/components/link-control/search-input.js +4 -4
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/search-item.js +14 -28
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -3
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +4 -5
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/list-view/appender.js +2 -6
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/provider/index.js +5 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +21 -0
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +45 -0
- package/build-module/components/resolution-tool/index.js.map +1 -0
- package/build-module/components/url-input/index.js +4 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +8 -26
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-mode-control/index.js +57 -0
- package/build-module/components/writing-mode-control/index.js.map +1 -0
- package/build-module/hooks/behaviors.js +26 -20
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/supports.js +7 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +2 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +4 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +7 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +2 -0
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/actions.js +191 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +1 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +10 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +45 -36
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +22 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +33 -15
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +131 -129
- package/build-style/style.css +131 -129
- package/package.json +32 -31
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
- package/src/components/block-draggable/style.scss +1 -0
- package/src/components/block-heading-level-dropdown/heading-level-icon.js +6 -1
- package/src/components/block-heading-level-dropdown/index.native.js +8 -4
- package/src/components/block-inspector/style.scss +2 -1
- package/src/components/block-lock/toolbar.js +34 -6
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -8
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +20 -33
- package/src/components/block-toolbar/index.js +9 -6
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +73 -26
- package/src/components/default-block-appender/content.scss +11 -0
- package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
- package/src/components/dimensions-tool/index.js +212 -0
- package/src/components/dimensions-tool/scale-tool.js +124 -0
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
- package/src/components/dimensions-tool/stories/index.js +54 -0
- package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
- package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
- package/src/components/dimensions-tool/test/index.js +641 -0
- package/src/components/dimensions-tool/width-height-tool.js +113 -0
- package/src/components/font-family/README.md +71 -0
- package/src/components/global-styles/color-panel.js +1 -1
- package/src/components/global-styles/filters-panel.js +2 -2
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +40 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/src/components/image-editor/use-save-image.js +0 -1
- package/src/components/image-size-control/index.js +6 -0
- package/src/components/index.js +6 -0
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +8 -56
- package/src/components/inserter/hooks/use-block-types-state.js +3 -4
- package/src/components/inserter/hooks/use-patterns-state.js +35 -19
- package/src/components/inserter/media-tab/hooks.js +2 -22
- package/src/components/inserter/reusable-block-rename-hint.js +52 -0
- package/src/components/inserter/reusable-blocks-tab.js +5 -1
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/src/components/inserter/style.scss +28 -0
- package/src/components/inserter/tabs.native.js +5 -1
- package/src/components/inserter-draggable-blocks/index.js +13 -2
- package/src/components/link-control/constants.js +1 -1
- package/src/components/link-control/index.js +32 -28
- package/src/components/link-control/search-create-button.js +8 -26
- package/src/components/link-control/search-input.js +4 -3
- package/src/components/link-control/search-item.js +21 -43
- package/src/components/link-control/search-results.js +48 -46
- package/src/components/link-control/settings-drawer.js +6 -5
- package/src/components/link-control/style.scss +51 -123
- package/src/components/link-control/test/index.js +135 -123
- package/src/components/list-view/appender.js +5 -6
- package/src/components/list-view/style.scss +1 -2
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/panel-color-settings/README.md +98 -0
- package/src/components/provider/index.js +9 -2
- package/src/components/provider/test/use-block-sync.js +21 -6
- package/src/components/provider/use-block-sync.js +19 -0
- package/src/components/recursion-provider/README.md +101 -0
- package/src/components/resolution-tool/index.js +56 -0
- package/src/components/resolution-tool/stories/index.js +48 -0
- package/src/components/url-input/index.js +2 -0
- package/src/components/writing-flow/use-tab-nav.js +10 -33
- package/src/components/writing-mode-control/index.js +68 -0
- package/src/components/writing-mode-control/style.scss +18 -0
- package/src/hooks/behaviors.js +25 -16
- package/src/hooks/supports.js +7 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/utils.js +3 -0
- package/src/private-apis.js +6 -0
- package/src/private-apis.native.js +2 -0
- package/src/store/actions.js +194 -1
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +10 -0
- package/src/store/private-actions.js +39 -39
- package/src/store/private-selectors.js +2 -2
- package/src/store/reducer.js +22 -8
- package/src/store/selectors.js +54 -20
- package/src/store/test/actions.js +111 -0
- package/src/store/test/private-actions.js +56 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import styled from '@emotion/styled';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
11
|
+
__experimentalUnitControl as UnitControl,
|
|
12
|
+
} from '@wordpress/components';
|
|
13
|
+
import { __ } from '@wordpress/i18n';
|
|
14
|
+
|
|
15
|
+
const SingleColumnToolsPanelItem = styled( ToolsPanelItem )`
|
|
16
|
+
grid-column: span 1;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {Object} WidthHeightToolValue
|
|
25
|
+
* @property {string} [width] Width CSS value.
|
|
26
|
+
* @property {string} [height] Height CSS value.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @callback WidthHeightToolOnChange
|
|
31
|
+
* @param {WidthHeightToolValue} nextValue Next dimensions value.
|
|
32
|
+
* @return {void}
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {Object} WidthHeightToolProps
|
|
37
|
+
* @property {string} [panelId] ID of the panel that contains the controls.
|
|
38
|
+
* @property {WidthHeightToolValue} [value] Current dimensions values.
|
|
39
|
+
* @property {WidthHeightToolOnChange} [onChange] Callback to update the dimensions values.
|
|
40
|
+
* @property {WPUnitControlUnit[]} [units] Units options.
|
|
41
|
+
* @property {boolean} [isShownByDefault] Whether the panel is shown by default.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Component that renders controls to edit the dimensions of an image or container.
|
|
46
|
+
*
|
|
47
|
+
* @param {WidthHeightToolProps} props The component props.
|
|
48
|
+
*
|
|
49
|
+
* @return {import('@wordpress/element').WPElement} The width and height tool.
|
|
50
|
+
*/
|
|
51
|
+
export default function WidthHeightTool( {
|
|
52
|
+
panelId,
|
|
53
|
+
value = {},
|
|
54
|
+
onChange = () => {},
|
|
55
|
+
units,
|
|
56
|
+
isShownByDefault = true,
|
|
57
|
+
} ) {
|
|
58
|
+
// null, undefined, and 'auto' all represent the default value.
|
|
59
|
+
const width = value.width === 'auto' ? '' : value.width ?? '';
|
|
60
|
+
const height = value.height === 'auto' ? '' : value.height ?? '';
|
|
61
|
+
|
|
62
|
+
const onDimensionChange = ( dimension ) => ( nextDimension ) => {
|
|
63
|
+
const nextValue = { ...value };
|
|
64
|
+
// Empty strings or undefined may be passed and both represent removing the value.
|
|
65
|
+
if ( ! nextDimension ) {
|
|
66
|
+
delete nextValue[ dimension ];
|
|
67
|
+
} else {
|
|
68
|
+
nextValue[ dimension ] = nextDimension;
|
|
69
|
+
}
|
|
70
|
+
onChange( nextValue );
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
<SingleColumnToolsPanelItem
|
|
76
|
+
label={ __( 'Width' ) }
|
|
77
|
+
isShownByDefault={ isShownByDefault }
|
|
78
|
+
hasValue={ () => width !== '' }
|
|
79
|
+
onDeselect={ onDimensionChange( 'width' ) }
|
|
80
|
+
panelId={ panelId }
|
|
81
|
+
>
|
|
82
|
+
<UnitControl
|
|
83
|
+
label={ __( 'Width' ) }
|
|
84
|
+
placeholder={ __( 'Auto' ) }
|
|
85
|
+
labelPosition="top"
|
|
86
|
+
units={ units }
|
|
87
|
+
min={ 0 }
|
|
88
|
+
value={ width }
|
|
89
|
+
onChange={ onDimensionChange( 'width' ) }
|
|
90
|
+
size={ '__unstable-large' }
|
|
91
|
+
/>
|
|
92
|
+
</SingleColumnToolsPanelItem>
|
|
93
|
+
<SingleColumnToolsPanelItem
|
|
94
|
+
label={ __( 'Height' ) }
|
|
95
|
+
isShownByDefault={ isShownByDefault }
|
|
96
|
+
hasValue={ () => height !== '' }
|
|
97
|
+
onDeselect={ onDimensionChange( 'height' ) }
|
|
98
|
+
panelId={ panelId }
|
|
99
|
+
>
|
|
100
|
+
<UnitControl
|
|
101
|
+
label={ __( 'Height' ) }
|
|
102
|
+
placeholder={ __( 'Auto' ) }
|
|
103
|
+
labelPosition="top"
|
|
104
|
+
units={ units }
|
|
105
|
+
min={ 0 }
|
|
106
|
+
value={ height }
|
|
107
|
+
onChange={ onDimensionChange( 'height' ) }
|
|
108
|
+
size={ '__unstable-large' }
|
|
109
|
+
/>
|
|
110
|
+
</SingleColumnToolsPanelItem>
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# FontFamilyControl
|
|
2
|
+
|
|
3
|
+
FontFamilyControl is a React component that renders a UI that allows users to select a font family.
|
|
4
|
+
The component renders a user interface that allows the user to select from a set of predefined font families as defined by the `typography.fontFamilies` presets.
|
|
5
|
+
Optionally, you can provide a `fontFamilies` prop that overrides the predefined font families.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
import { FontFamilyControl } from '@wordpress/block-editor';
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
import { __ } from '@wordpress/i18n';
|
|
15
|
+
|
|
16
|
+
// ...
|
|
17
|
+
|
|
18
|
+
const MyFontFamilyControl = () => {
|
|
19
|
+
const [ fontFamily, setFontFamily ] = useState( '' );
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<FontFamilyControl
|
|
23
|
+
value={ fontFamily }
|
|
24
|
+
onChange={ ( newFontFamily ) => {
|
|
25
|
+
setFontFamily( newFontFamily );
|
|
26
|
+
} }
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/// ...
|
|
32
|
+
|
|
33
|
+
<MyFontFamilyControl />
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Props
|
|
37
|
+
|
|
38
|
+
The component accepts the following props:
|
|
39
|
+
|
|
40
|
+
### onChange
|
|
41
|
+
|
|
42
|
+
A function that receives the new font family value.
|
|
43
|
+
If onChange is called without any parameter, it should reset the value, attending to what reset means in that context, e.g., set the font family to undefined or set the font family a starting value.
|
|
44
|
+
|
|
45
|
+
- Type: `function`
|
|
46
|
+
- Required: Yes
|
|
47
|
+
|
|
48
|
+
### fontFamilies
|
|
49
|
+
|
|
50
|
+
A user-provided set of font families.
|
|
51
|
+
Optional, used in case we want to override the predefined ones coming from presets.
|
|
52
|
+
|
|
53
|
+
- Type: `Array`
|
|
54
|
+
- Required: No
|
|
55
|
+
|
|
56
|
+
The font families are provided as an array of objects with the following schema:
|
|
57
|
+
|
|
58
|
+
| Property | Description | Type |
|
|
59
|
+
| ---------- | ----------------------------------------- | ------ |
|
|
60
|
+
| fontFamily | Font family, as used in CSS. | string |
|
|
61
|
+
| name | Optional display name of the font family. | string |
|
|
62
|
+
|
|
63
|
+
### value
|
|
64
|
+
|
|
65
|
+
The current font family value.
|
|
66
|
+
|
|
67
|
+
- Type: `String`
|
|
68
|
+
- Required: No
|
|
69
|
+
- Default: ''
|
|
70
|
+
|
|
71
|
+
The rest of the props are passed down to the underlying `<SelectControl />` instance.
|
|
@@ -35,7 +35,7 @@ export function useHasColorPanel( settings ) {
|
|
|
35
35
|
const hasBackgroundPanel = useHasBackgroundPanel( settings );
|
|
36
36
|
const hasLinkPanel = useHasLinkPanel( settings );
|
|
37
37
|
const hasHeadingPanel = useHasHeadingPanel( settings );
|
|
38
|
-
const hasButtonPanel =
|
|
38
|
+
const hasButtonPanel = useHasButtonPanel( settings );
|
|
39
39
|
const hasCaptionPanel = useHasCaptionPanel( settings );
|
|
40
40
|
|
|
41
41
|
return (
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
Flex,
|
|
23
23
|
FlexItem,
|
|
24
24
|
} from '@wordpress/components';
|
|
25
|
-
import { __ } from '@wordpress/i18n';
|
|
25
|
+
import { __, _x } from '@wordpress/i18n';
|
|
26
26
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -77,7 +77,7 @@ function FiltersToolsPanel( {
|
|
|
77
77
|
|
|
78
78
|
return (
|
|
79
79
|
<ToolsPanel
|
|
80
|
-
label={
|
|
80
|
+
label={ _x( 'Filters', 'Name for applying graphical effects' ) }
|
|
81
81
|
resetAll={ resetAll }
|
|
82
82
|
panelId={ panelId }
|
|
83
83
|
>
|
|
@@ -71,6 +71,7 @@ const VALID_SETTINGS = [
|
|
|
71
71
|
'typography.textColumns',
|
|
72
72
|
'typography.textDecoration',
|
|
73
73
|
'typography.textTransform',
|
|
74
|
+
'typography.writingMode',
|
|
74
75
|
];
|
|
75
76
|
|
|
76
77
|
export const useGlobalStylesReset = () => {
|
|
@@ -292,6 +293,7 @@ export function useSettingsForBlockElement(
|
|
|
292
293
|
'letterSpacing',
|
|
293
294
|
'textTransform',
|
|
294
295
|
'textDecoration',
|
|
296
|
+
'writingMode',
|
|
295
297
|
].forEach( ( key ) => {
|
|
296
298
|
if ( ! supportedStyles.includes( key ) ) {
|
|
297
299
|
updatedSettings.typography = {
|
|
@@ -19,6 +19,7 @@ import LineHeightControl from '../line-height-control';
|
|
|
19
19
|
import LetterSpacingControl from '../letter-spacing-control';
|
|
20
20
|
import TextTransformControl from '../text-transform-control';
|
|
21
21
|
import TextDecorationControl from '../text-decoration-control';
|
|
22
|
+
import WritingModeControl from '../writing-mode-control';
|
|
22
23
|
import { getValueFromVariable } from './utils';
|
|
23
24
|
import { setImmutably } from '../../utils/object';
|
|
24
25
|
|
|
@@ -32,6 +33,7 @@ export function useHasTypographyPanel( settings ) {
|
|
|
32
33
|
const hasLetterSpacing = useHasLetterSpacingControl( settings );
|
|
33
34
|
const hasTextTransform = useHasTextTransformControl( settings );
|
|
34
35
|
const hasTextDecoration = useHasTextDecorationControl( settings );
|
|
36
|
+
const hasWritingMode = useHasWritingModeControl( settings );
|
|
35
37
|
const hasTextColumns = useHasTextColumnsControl( settings );
|
|
36
38
|
const hasFontSize = useHasFontSizeControl( settings );
|
|
37
39
|
|
|
@@ -43,6 +45,7 @@ export function useHasTypographyPanel( settings ) {
|
|
|
43
45
|
hasTextTransform ||
|
|
44
46
|
hasFontSize ||
|
|
45
47
|
hasTextDecoration ||
|
|
48
|
+
hasWritingMode ||
|
|
46
49
|
hasTextColumns
|
|
47
50
|
);
|
|
48
51
|
}
|
|
@@ -103,6 +106,10 @@ function useHasTextDecorationControl( settings ) {
|
|
|
103
106
|
return settings?.typography?.textDecoration;
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
function useHasWritingModeControl( settings ) {
|
|
110
|
+
return settings?.typography?.writingMode;
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
function useHasTextColumnsControl( settings ) {
|
|
107
114
|
return settings?.typography?.textColumns;
|
|
108
115
|
}
|
|
@@ -138,6 +145,7 @@ const DEFAULT_CONTROLS = {
|
|
|
138
145
|
letterSpacing: true,
|
|
139
146
|
textTransform: true,
|
|
140
147
|
textDecoration: true,
|
|
148
|
+
writingMode: true,
|
|
141
149
|
textColumns: true,
|
|
142
150
|
};
|
|
143
151
|
|
|
@@ -310,6 +318,21 @@ export default function TypographyPanel( {
|
|
|
310
318
|
const hasTextDecoration = () => !! value?.typography?.textDecoration;
|
|
311
319
|
const resetTextDecoration = () => setTextDecoration( undefined );
|
|
312
320
|
|
|
321
|
+
// Text Orientation
|
|
322
|
+
const hasWritingModeControl = useHasWritingModeControl( settings );
|
|
323
|
+
const writingMode = decodeValue( inheritedValue?.typography?.writingMode );
|
|
324
|
+
const setWritingMode = ( newValue ) => {
|
|
325
|
+
onChange(
|
|
326
|
+
setImmutably(
|
|
327
|
+
value,
|
|
328
|
+
[ 'typography', 'writingMode' ],
|
|
329
|
+
newValue || undefined
|
|
330
|
+
)
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
const hasWritingMode = () => !! value?.typography?.writingMode;
|
|
334
|
+
const resetWritingMode = () => setWritingMode( undefined );
|
|
335
|
+
|
|
313
336
|
const resetAllFilter = useCallback( ( previousValue ) => {
|
|
314
337
|
return {
|
|
315
338
|
...previousValue,
|
|
@@ -456,6 +479,23 @@ export default function TypographyPanel( {
|
|
|
456
479
|
/>
|
|
457
480
|
</ToolsPanelItem>
|
|
458
481
|
) }
|
|
482
|
+
{ hasWritingModeControl && (
|
|
483
|
+
<ToolsPanelItem
|
|
484
|
+
className="single-column"
|
|
485
|
+
label={ __( 'Text orientation' ) }
|
|
486
|
+
hasValue={ hasWritingMode }
|
|
487
|
+
onDeselect={ resetWritingMode }
|
|
488
|
+
isShownByDefault={ defaultControls.writingMode }
|
|
489
|
+
panelId={ panelId }
|
|
490
|
+
>
|
|
491
|
+
<WritingModeControl
|
|
492
|
+
value={ writingMode }
|
|
493
|
+
onChange={ setWritingMode }
|
|
494
|
+
size="__unstable-large"
|
|
495
|
+
__nextHasNoMarginBottom
|
|
496
|
+
/>
|
|
497
|
+
</ToolsPanelItem>
|
|
498
|
+
) }
|
|
459
499
|
{ hasTextTransformControl && (
|
|
460
500
|
<ToolsPanelItem
|
|
461
501
|
label={ __( 'Letter case' ) }
|
|
@@ -54,7 +54,7 @@ export default function AspectRatioDropdown( { toggleProps } ) {
|
|
|
54
54
|
} }
|
|
55
55
|
value={ aspect }
|
|
56
56
|
aspectRatios={ [
|
|
57
|
-
// All ratios should be mirrored in
|
|
57
|
+
// All ratios should be mirrored in AspectRatioTool in @wordpress/block-editor.
|
|
58
58
|
{
|
|
59
59
|
title: __( 'Original' ),
|
|
60
60
|
aspect: defaultAspect,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
__experimentalNumberControl as NumberControl,
|
|
9
9
|
__experimentalHStack as HStack,
|
|
10
10
|
} from '@wordpress/components';
|
|
11
|
+
import deprecated from '@wordpress/deprecated';
|
|
11
12
|
import { __ } from '@wordpress/i18n';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -30,6 +31,11 @@ export default function ImageSizeControl( {
|
|
|
30
31
|
onChange,
|
|
31
32
|
onChangeImage = noop,
|
|
32
33
|
} ) {
|
|
34
|
+
deprecated( 'wp.blockEditor.__experimentalImageSizeControl', {
|
|
35
|
+
since: '6.3',
|
|
36
|
+
alternative:
|
|
37
|
+
'wp.blockEditor.privateApis.DimensionsTool and wp.blockEditor.privateApis.ResolutionTool',
|
|
38
|
+
} );
|
|
33
39
|
const { currentHeight, currentWidth, updateDimension, updateDimensions } =
|
|
34
40
|
useDimensionHandler( height, width, imageHeight, imageWidth, onChange );
|
|
35
41
|
|
package/src/components/index.js
CHANGED
|
@@ -50,6 +50,7 @@ export { default as __experimentalFontFamilyControl } from './font-family';
|
|
|
50
50
|
export { default as __experimentalLetterSpacingControl } from './letter-spacing-control';
|
|
51
51
|
export { default as __experimentalTextDecorationControl } from './text-decoration-control';
|
|
52
52
|
export { default as __experimentalTextTransformControl } from './text-transform-control';
|
|
53
|
+
export { default as __experimentalWritingModeControl } from './writing-mode-control';
|
|
53
54
|
export { default as __experimentalColorGradientControl } from './colors-gradients/control';
|
|
54
55
|
export { default as __experimentalColorGradientSettingsDropdown } from './colors-gradients/dropdown';
|
|
55
56
|
export { default as __experimentalPanelColorGradientSettings } from './colors-gradients/panel-color-gradient-settings';
|
|
@@ -164,3 +165,8 @@ export { default as __experimentalInspectorPopoverHeader } from './inspector-pop
|
|
|
164
165
|
|
|
165
166
|
export { default as BlockEditorProvider } from './provider';
|
|
166
167
|
export { default as useSetting } from './use-setting';
|
|
168
|
+
|
|
169
|
+
/*
|
|
170
|
+
* The following rename hint component can be removed in 6.4.
|
|
171
|
+
*/
|
|
172
|
+
export { default as ReusableBlocksRenameHint } from './inserter/reusable-block-rename-hint';
|
|
@@ -52,6 +52,7 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
|
|
|
52
52
|
onInsertBlocks,
|
|
53
53
|
destinationRootClientId
|
|
54
54
|
);
|
|
55
|
+
|
|
55
56
|
const registeredPatternCategories = useMemo(
|
|
56
57
|
() =>
|
|
57
58
|
patternCategories.map(
|
|
@@ -75,7 +76,12 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
|
|
|
75
76
|
);
|
|
76
77
|
}
|
|
77
78
|
return searchItems( allPatterns, filterValue );
|
|
78
|
-
}, [
|
|
79
|
+
}, [
|
|
80
|
+
filterValue,
|
|
81
|
+
allPatterns,
|
|
82
|
+
selectedCategory,
|
|
83
|
+
registeredPatternCategories,
|
|
84
|
+
] );
|
|
79
85
|
|
|
80
86
|
// Announce search results on change.
|
|
81
87
|
useEffect( () => {
|
|
@@ -89,7 +95,7 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
|
|
|
89
95
|
count
|
|
90
96
|
);
|
|
91
97
|
debouncedSpeak( resultsFoundMessage );
|
|
92
|
-
}, [ filterValue, debouncedSpeak ] );
|
|
98
|
+
}, [ filterValue, debouncedSpeak, filteredBlockPatterns.length ] );
|
|
93
99
|
|
|
94
100
|
const currentShownPatterns = useAsyncList( filteredBlockPatterns, {
|
|
95
101
|
step: INITIAL_INSERTER_RESULTS,
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
Button,
|
|
19
19
|
} from '@wordpress/components';
|
|
20
20
|
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
|
|
21
|
-
import { parse } from '@wordpress/blocks';
|
|
22
21
|
import { focus } from '@wordpress/dom';
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -28,13 +27,13 @@ import usePatternsState from './hooks/use-patterns-state';
|
|
|
28
27
|
import BlockPatternList from '../block-patterns-list';
|
|
29
28
|
import PatternsExplorerModal from './block-patterns-explorer/explorer';
|
|
30
29
|
import MobileTabNavigation from './mobile-tab-navigation';
|
|
31
|
-
import useBlockTypesState from './hooks/use-block-types-state';
|
|
32
30
|
|
|
33
31
|
const noop = () => {};
|
|
34
32
|
|
|
35
33
|
// Preferred order of pattern categories. Any other categories should
|
|
36
34
|
// be at the bottom without any re-ordering.
|
|
37
35
|
const patternCategoriesOrder = [
|
|
36
|
+
'custom',
|
|
38
37
|
'featured',
|
|
39
38
|
'posts',
|
|
40
39
|
'text',
|
|
@@ -51,18 +50,6 @@ function usePatternsCategories( rootClientId ) {
|
|
|
51
50
|
rootClientId
|
|
52
51
|
);
|
|
53
52
|
|
|
54
|
-
const [ unsyncedPatterns ] = useBlockTypesState(
|
|
55
|
-
rootClientId,
|
|
56
|
-
undefined,
|
|
57
|
-
'unsynced'
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const filteredUnsyncedPatterns = useMemo( () => {
|
|
61
|
-
return unsyncedPatterns.filter(
|
|
62
|
-
( { category: unsyncedPatternCategory } ) =>
|
|
63
|
-
unsyncedPatternCategory === 'reusable'
|
|
64
|
-
);
|
|
65
|
-
}, [ unsyncedPatterns ] );
|
|
66
53
|
const hasRegisteredCategory = useCallback(
|
|
67
54
|
( pattern ) => {
|
|
68
55
|
if ( ! pattern.categories || ! pattern.categories.length ) {
|
|
@@ -107,20 +94,9 @@ function usePatternsCategories( rootClientId ) {
|
|
|
107
94
|
label: _x( 'Uncategorized' ),
|
|
108
95
|
} );
|
|
109
96
|
}
|
|
110
|
-
if ( filteredUnsyncedPatterns.length > 0 ) {
|
|
111
|
-
categories.push( {
|
|
112
|
-
name: 'reusable',
|
|
113
|
-
label: _x( 'Custom patterns' ),
|
|
114
|
-
} );
|
|
115
|
-
}
|
|
116
97
|
|
|
117
98
|
return categories;
|
|
118
|
-
}, [
|
|
119
|
-
allCategories,
|
|
120
|
-
allPatterns,
|
|
121
|
-
filteredUnsyncedPatterns.length,
|
|
122
|
-
hasRegisteredCategory,
|
|
123
|
-
] );
|
|
99
|
+
}, [ allCategories, allPatterns, hasRegisteredCategory ] );
|
|
124
100
|
|
|
125
101
|
return populatedCategories;
|
|
126
102
|
}
|
|
@@ -169,24 +145,6 @@ export function BlockPatternsCategoryPanel( {
|
|
|
169
145
|
onInsert,
|
|
170
146
|
rootClientId
|
|
171
147
|
);
|
|
172
|
-
const [ unsyncedPatterns ] = useBlockTypesState(
|
|
173
|
-
rootClientId,
|
|
174
|
-
onInsert,
|
|
175
|
-
'unsynced'
|
|
176
|
-
);
|
|
177
|
-
const filteredUnsyncedPatterns = useMemo( () => {
|
|
178
|
-
return unsyncedPatterns
|
|
179
|
-
.filter(
|
|
180
|
-
( { category: unsyncedPatternCategory } ) =>
|
|
181
|
-
unsyncedPatternCategory === 'reusable'
|
|
182
|
-
)
|
|
183
|
-
.map( ( syncedPattern ) => ( {
|
|
184
|
-
...syncedPattern,
|
|
185
|
-
blocks: parse( syncedPattern.content, {
|
|
186
|
-
__unstableSkipMigrationLogs: true,
|
|
187
|
-
} ),
|
|
188
|
-
} ) );
|
|
189
|
-
}, [ unsyncedPatterns ] );
|
|
190
148
|
|
|
191
149
|
const availableCategories = usePatternsCategories( rootClientId );
|
|
192
150
|
const currentCategoryPatterns = useMemo(
|
|
@@ -208,21 +166,15 @@ export function BlockPatternsCategoryPanel( {
|
|
|
208
166
|
|
|
209
167
|
return availablePatternCategories.length === 0;
|
|
210
168
|
} ),
|
|
211
|
-
[ allPatterns, category ]
|
|
169
|
+
[ allPatterns, availableCategories, category.name ]
|
|
212
170
|
);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
? filteredUnsyncedPatterns
|
|
216
|
-
: currentCategoryPatterns;
|
|
217
|
-
const currentShownPatterns = useAsyncList( patterns );
|
|
171
|
+
|
|
172
|
+
const categoryPatternsList = useAsyncList( currentCategoryPatterns );
|
|
218
173
|
|
|
219
174
|
// Hide block pattern preview on unmount.
|
|
220
175
|
useEffect( () => () => onHover( null ), [] );
|
|
221
176
|
|
|
222
|
-
if (
|
|
223
|
-
! currentCategoryPatterns.length &&
|
|
224
|
-
! filteredUnsyncedPatterns.length
|
|
225
|
-
) {
|
|
177
|
+
if ( ! currentCategoryPatterns.length ) {
|
|
226
178
|
return null;
|
|
227
179
|
}
|
|
228
180
|
|
|
@@ -233,8 +185,8 @@ export function BlockPatternsCategoryPanel( {
|
|
|
233
185
|
</div>
|
|
234
186
|
<p>{ category.description }</p>
|
|
235
187
|
<BlockPatternList
|
|
236
|
-
shownPatterns={
|
|
237
|
-
blockPatterns={
|
|
188
|
+
shownPatterns={ categoryPatternsList }
|
|
189
|
+
blockPatterns={ currentCategoryPatterns }
|
|
238
190
|
onClickPattern={ onClick }
|
|
239
191
|
onHover={ onHover }
|
|
240
192
|
label={ category.label }
|
|
@@ -19,10 +19,9 @@ import { store as blockEditorStore } from '../../../store';
|
|
|
19
19
|
*
|
|
20
20
|
* @param {string=} rootClientId Insertion's root client ID.
|
|
21
21
|
* @param {Function} onInsert function called when inserter a list of blocks.
|
|
22
|
-
* @param {?string} syncStatus Optional sync status to filter pattern blocks by.
|
|
23
22
|
* @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler)
|
|
24
23
|
*/
|
|
25
|
-
const useBlockTypesState = ( rootClientId, onInsert
|
|
24
|
+
const useBlockTypesState = ( rootClientId, onInsert ) => {
|
|
26
25
|
const { categories, collections, items } = useSelect(
|
|
27
26
|
( select ) => {
|
|
28
27
|
const { getInserterItems } = select( blockEditorStore );
|
|
@@ -31,10 +30,10 @@ const useBlockTypesState = ( rootClientId, onInsert, syncStatus ) => {
|
|
|
31
30
|
return {
|
|
32
31
|
categories: getCategories(),
|
|
33
32
|
collections: getCollections(),
|
|
34
|
-
items: getInserterItems( rootClientId
|
|
33
|
+
items: getInserterItems( rootClientId ),
|
|
35
34
|
};
|
|
36
35
|
},
|
|
37
|
-
[ rootClientId
|
|
36
|
+
[ rootClientId ]
|
|
38
37
|
);
|
|
39
38
|
|
|
40
39
|
const onSelectItem = useCallback(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { useCallback } from '@wordpress/element';
|
|
4
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
5
5
|
import { cloneBlock } from '@wordpress/blocks';
|
|
6
6
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
@@ -12,6 +12,12 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../../../store';
|
|
14
14
|
|
|
15
|
+
const CUSTOM_CATEGORY = {
|
|
16
|
+
name: 'custom',
|
|
17
|
+
label: __( 'My patterns' ),
|
|
18
|
+
description: __( 'Custom patterns add by site users' ),
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Retrieves the block patterns inserter state.
|
|
17
23
|
*
|
|
@@ -25,6 +31,7 @@ const usePatternsState = ( onInsert, rootClientId ) => {
|
|
|
25
31
|
( select ) => {
|
|
26
32
|
const { __experimentalGetAllowedPatterns, getSettings } =
|
|
27
33
|
select( blockEditorStore );
|
|
34
|
+
|
|
28
35
|
return {
|
|
29
36
|
patterns: __experimentalGetAllowedPatterns( rootClientId ),
|
|
30
37
|
patternCategories:
|
|
@@ -33,25 +40,34 @@ const usePatternsState = ( onInsert, rootClientId ) => {
|
|
|
33
40
|
},
|
|
34
41
|
[ rootClientId ]
|
|
35
42
|
);
|
|
43
|
+
|
|
44
|
+
const allCategories = useMemo(
|
|
45
|
+
() => [ ...patternCategories, CUSTOM_CATEGORY ],
|
|
46
|
+
[ patternCategories ]
|
|
47
|
+
);
|
|
48
|
+
|
|
36
49
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
37
|
-
const onClickPattern = useCallback(
|
|
38
|
-
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const onClickPattern = useCallback(
|
|
51
|
+
( pattern, blocks ) => {
|
|
52
|
+
onInsert(
|
|
53
|
+
( blocks ?? [] ).map( ( block ) => cloneBlock( block ) ),
|
|
54
|
+
pattern.name
|
|
55
|
+
);
|
|
56
|
+
createSuccessNotice(
|
|
57
|
+
sprintf(
|
|
58
|
+
/* translators: %s: block pattern title. */
|
|
59
|
+
__( 'Block pattern "%s" inserted.' ),
|
|
60
|
+
pattern.title
|
|
61
|
+
),
|
|
62
|
+
{
|
|
63
|
+
type: 'snackbar',
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
[ createSuccessNotice, onInsert ]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return [ patterns, allCategories, onClickPattern ];
|
|
55
71
|
};
|
|
56
72
|
|
|
57
73
|
export default usePatternsState;
|
|
@@ -9,28 +9,8 @@ import { useSelect } from '@wordpress/data';
|
|
|
9
9
|
*/
|
|
10
10
|
import { store as blockEditorStore } from '../../../store';
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @typedef {Object} InserterMediaRequest
|
|
16
|
-
* @property {number} per_page How many items to fetch per page.
|
|
17
|
-
* @property {string} search The search term to use for filtering the results.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Interface for inserter media responses. Any media resource should
|
|
22
|
-
* map their response to this interface, in order to create the core
|
|
23
|
-
* WordPress media blocks (image, video, audio).
|
|
24
|
-
*
|
|
25
|
-
* @typedef {Object} InserterMediaItem
|
|
26
|
-
* @property {string} title The title of the media item.
|
|
27
|
-
* @property {string} url The source url of the media item.
|
|
28
|
-
* @property {string} [previewUrl] The preview source url of the media item to display in the media list.
|
|
29
|
-
* @property {number} [id] The WordPress id of the media item.
|
|
30
|
-
* @property {number|string} [sourceId] The id of the media item from external source.
|
|
31
|
-
* @property {string} [alt] The alt text of the media item.
|
|
32
|
-
* @property {string} [caption] The caption of the media item.
|
|
33
|
-
*/
|
|
12
|
+
/** @typedef {import('./api').InserterMediaRequest} InserterMediaRequest */
|
|
13
|
+
/** @typedef {import('./api').InserterMediaItem} InserterMediaItem */
|
|
34
14
|
|
|
35
15
|
/**
|
|
36
16
|
* Fetches media items based on the provided category.
|