@wordpress/block-editor 15.8.1-next.16d95556a.0 → 15.9.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/build/components/block-inspector/edit-contents.js +19 -23
- package/build/components/block-inspector/edit-contents.js.map +3 -3
- package/build/components/block-inspector/index.js +7 -1
- package/build/components/block-inspector/index.js.map +2 -2
- package/build/components/block-list/block.js +4 -0
- package/build/components/block-list/block.js.map +2 -2
- package/build/components/block-list/index.js +2 -1
- package/build/components/block-list/index.js.map +2 -2
- package/build/components/block-list/use-block-props/index.js +3 -1
- package/build/components/block-list/use-block-props/index.js.map +2 -2
- package/build/components/block-list/use-block-props/use-is-hovered.js +16 -10
- package/build/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build/components/block-lock/modal.js +5 -5
- package/build/components/block-lock/modal.js.map +2 -2
- package/build/components/block-lock/use-block-lock.js +10 -13
- package/build/components/block-lock/use-block-lock.js.map +2 -2
- package/build/components/block-settings-menu-controls/edit-section-menu-item.js +64 -0
- package/build/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
- package/build/components/block-settings-menu-controls/index.js +9 -1
- package/build/components/block-settings-menu-controls/index.js.map +2 -2
- package/build/components/block-toolbar/block-toolbar-icon.js +9 -9
- package/build/components/block-toolbar/block-toolbar-icon.js.map +2 -2
- package/build/components/block-tools/index.js +56 -45
- package/build/components/block-tools/index.js.map +3 -3
- package/build/components/block-variation-transforms/index.js +32 -5
- package/build/components/block-variation-transforms/index.js.map +2 -2
- package/build/components/block-visibility/toolbar.js +1 -1
- package/build/components/block-visibility/toolbar.js.map +1 -1
- package/build/components/border-radius-control/single-input-control.js +1 -0
- package/build/components/border-radius-control/single-input-control.js.map +2 -2
- package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
- package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build/components/content-only-controls/index.js +444 -0
- package/build/components/content-only-controls/index.js.map +7 -0
- package/build/components/content-only-controls/link/index.js +193 -0
- package/build/components/content-only-controls/link/index.js.map +7 -0
- package/build/components/content-only-controls/media/index.js +264 -0
- package/build/components/content-only-controls/media/index.js.map +7 -0
- package/build/components/content-only-controls/rich-text/index.js +188 -0
- package/build/components/content-only-controls/rich-text/index.js.map +7 -0
- package/build/components/content-only-controls/use-inspector-popover-placement.js +41 -0
- package/build/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
- package/build/components/font-family/index.js +1 -15
- package/build/components/font-family/index.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +35 -2
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +1 -2
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/inserter/media-tab/media-tab.js +1 -33
- package/build/components/inserter/media-tab/media-tab.js.map +3 -3
- package/build/components/inspector-controls-tabs/content-tab.js +6 -2
- package/build/components/inspector-controls-tabs/content-tab.js.map +3 -3
- package/build/components/inspector-controls-tabs/index.js +7 -1
- package/build/components/inspector-controls-tabs/index.js.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build/components/link-control/index.js +15 -7
- package/build/components/link-control/index.js.map +2 -2
- package/build/components/list-view/block-select-button.js +7 -8
- package/build/components/list-view/block-select-button.js.map +2 -2
- package/build/components/list-view/block.js +9 -7
- package/build/components/list-view/block.js.map +2 -2
- package/build/components/media-placeholder/index.js +18 -35
- package/build/components/media-placeholder/index.js.map +3 -3
- package/build/components/media-placeholder/utils.js +60 -0
- package/build/components/media-placeholder/utils.js.map +7 -0
- package/build/components/media-replace-flow/index.js +24 -33
- package/build/components/media-replace-flow/index.js.map +3 -3
- package/build/components/use-block-commands/index.js +1 -1
- package/build/components/use-block-commands/index.js.map +2 -2
- package/build/components/use-block-display-information/index.js +21 -1
- package/build/components/use-block-display-information/index.js.map +3 -3
- package/build/components/use-block-drop-zone/index.js +1 -5
- package/build/components/use-block-drop-zone/index.js.map +2 -2
- package/build/hooks/block-bindings.js +52 -61
- package/build/hooks/block-bindings.js.map +3 -3
- package/build/hooks/dimensions.js +3 -3
- package/build/hooks/dimensions.js.map +2 -2
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/use-content-only-section-edit.js +67 -0
- package/build/hooks/use-content-only-section-edit.js.map +7 -0
- package/build/hooks/utils.js +5 -1
- package/build/hooks/utils.js.map +2 -2
- package/build/layouts/constrained.js +2 -2
- package/build/layouts/constrained.js.map +2 -2
- package/build/private-apis.js +2 -3
- package/build/private-apis.js.map +3 -3
- package/build/store/private-keys.js +3 -0
- package/build/store/private-keys.js.map +2 -2
- package/build/store/private-selectors.js +41 -2
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +2 -2
- package/build/utils/fit-text-utils.js +9 -1
- package/build/utils/fit-text-utils.js.map +2 -2
- package/build-module/components/block-inspector/edit-contents.js +9 -23
- package/build-module/components/block-inspector/edit-contents.js.map +2 -2
- package/build-module/components/block-inspector/index.js +7 -1
- package/build-module/components/block-inspector/index.js.map +2 -2
- package/build-module/components/block-list/block.js +4 -0
- package/build-module/components/block-list/block.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -1
- package/build-module/components/block-list/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/index.js +3 -1
- package/build-module/components/block-list/use-block-props/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-is-hovered.js +16 -10
- package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build-module/components/block-lock/modal.js +5 -5
- package/build-module/components/block-lock/modal.js.map +2 -2
- package/build-module/components/block-lock/use-block-lock.js +10 -13
- package/build-module/components/block-lock/use-block-lock.js.map +2 -2
- package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js +29 -0
- package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
- package/build-module/components/block-settings-menu-controls/index.js +9 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
- package/build-module/components/block-toolbar/block-toolbar-icon.js +10 -10
- package/build-module/components/block-toolbar/block-toolbar-icon.js.map +2 -2
- package/build-module/components/block-tools/index.js +56 -45
- package/build-module/components/block-tools/index.js.map +2 -2
- package/build-module/components/block-variation-transforms/index.js +32 -5
- package/build-module/components/block-variation-transforms/index.js.map +2 -2
- package/build-module/components/block-visibility/toolbar.js +1 -1
- package/build-module/components/block-visibility/toolbar.js.map +1 -1
- package/build-module/components/border-radius-control/single-input-control.js +1 -0
- package/build-module/components/border-radius-control/single-input-control.js.map +2 -2
- package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
- package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build-module/components/content-only-controls/index.js +420 -0
- package/build-module/components/content-only-controls/index.js.map +7 -0
- package/build-module/components/content-only-controls/link/index.js +160 -0
- package/build-module/components/content-only-controls/link/index.js.map +7 -0
- package/build-module/components/content-only-controls/media/index.js +242 -0
- package/build-module/components/content-only-controls/media/index.js.map +7 -0
- package/build-module/components/content-only-controls/rich-text/index.js +160 -0
- package/build-module/components/content-only-controls/rich-text/index.js.map +7 -0
- package/build-module/components/content-only-controls/use-inspector-popover-placement.js +16 -0
- package/build-module/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
- package/build-module/components/font-family/index.js +1 -15
- package/build-module/components/font-family/index.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +35 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +1 -2
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/inserter/media-tab/media-tab.js +2 -34
- package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/content-tab.js +7 -3
- package/build-module/components/inspector-controls-tabs/content-tab.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.js +7 -1
- package/build-module/components/inspector-controls-tabs/index.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build-module/components/link-control/index.js +16 -8
- package/build-module/components/link-control/index.js.map +2 -2
- package/build-module/components/list-view/block-select-button.js +14 -9
- package/build-module/components/list-view/block-select-button.js.map +2 -2
- package/build-module/components/list-view/block.js +9 -7
- package/build-module/components/list-view/block.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +19 -36
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-placeholder/utils.js +35 -0
- package/build-module/components/media-placeholder/utils.js.map +7 -0
- package/build-module/components/media-replace-flow/index.js +24 -33
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/use-block-commands/index.js +1 -1
- package/build-module/components/use-block-commands/index.js.map +2 -2
- package/build-module/components/use-block-display-information/index.js +21 -1
- package/build-module/components/use-block-display-information/index.js.map +3 -3
- package/build-module/components/use-block-drop-zone/index.js +1 -5
- package/build-module/components/use-block-drop-zone/index.js.map +2 -2
- package/build-module/hooks/block-bindings.js +57 -62
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/dimensions.js +3 -3
- package/build-module/hooks/dimensions.js.map +2 -2
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/use-content-only-section-edit.js +46 -0
- package/build-module/hooks/use-content-only-section-edit.js.map +7 -0
- package/build-module/hooks/utils.js +5 -1
- package/build-module/hooks/utils.js.map +2 -2
- package/build-module/layouts/constrained.js +2 -2
- package/build-module/layouts/constrained.js.map +2 -2
- package/build-module/private-apis.js +3 -3
- package/build-module/private-apis.js.map +2 -2
- package/build-module/store/private-keys.js +2 -0
- package/build-module/store/private-keys.js.map +2 -2
- package/build-module/store/private-selectors.js +37 -2
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/utils/fit-text-utils.js +9 -1
- package/build-module/utils/fit-text-utils.js.map +2 -2
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +145 -4
- package/build-style/style.css +145 -4
- package/package.json +38 -37
- package/src/components/block-inspector/edit-contents.js +10 -29
- package/src/components/block-inspector/index.js +4 -2
- package/src/components/block-list/block.js +6 -0
- package/src/components/block-list/content.scss +5 -0
- package/src/components/block-list/index.js +3 -1
- package/src/components/block-list/use-block-props/index.js +3 -1
- package/src/components/block-list/use-block-props/use-is-hovered.js +24 -12
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
- package/src/components/block-lock/modal.js +6 -5
- package/src/components/block-lock/use-block-lock.js +10 -14
- package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
- package/src/components/block-settings-menu-controls/edit-section-menu-item.js +39 -0
- package/src/components/block-settings-menu-controls/index.js +8 -1
- package/src/components/block-toolbar/block-toolbar-icon.js +14 -10
- package/src/components/block-tools/index.js +15 -2
- package/src/components/block-tools/style.scss +4 -0
- package/src/components/block-variation-transforms/index.js +96 -35
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/border-radius-control/single-input-control.js +1 -0
- package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
- package/src/components/content-only-controls/index.js +560 -0
- package/src/components/content-only-controls/link/index.js +200 -0
- package/src/components/content-only-controls/link/styles.scss +23 -0
- package/src/components/content-only-controls/media/index.js +306 -0
- package/src/components/content-only-controls/media/styles.scss +47 -0
- package/src/components/content-only-controls/rich-text/index.js +179 -0
- package/src/components/content-only-controls/rich-text/styles.scss +24 -0
- package/src/components/content-only-controls/styles.scss +44 -0
- package/src/components/content-only-controls/use-inspector-popover-placement.js +19 -0
- package/src/components/font-family/README.md +0 -9
- package/src/components/font-family/index.js +1 -16
- package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
- package/src/components/global-styles/dimensions-panel.js +36 -0
- package/src/components/global-styles/hooks.js +1 -1
- package/src/components/global-styles/typography-panel.js +0 -1
- package/src/components/inserter/media-tab/media-tab.js +2 -44
- package/src/components/inspector-controls-tabs/content-tab.js +12 -4
- package/src/components/inspector-controls-tabs/index.js +4 -1
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
- package/src/components/link-control/index.js +36 -12
- package/src/components/list-view/block-select-button.js +15 -10
- package/src/components/list-view/block.js +9 -7
- package/src/components/media-placeholder/index.js +21 -46
- package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
- package/src/components/media-placeholder/utils.js +65 -0
- package/src/components/media-replace-flow/index.js +25 -42
- package/src/components/use-block-commands/index.js +1 -1
- package/src/components/use-block-display-information/index.js +30 -2
- package/src/components/use-block-drop-zone/index.js +1 -5
- package/src/hooks/block-bindings.js +71 -82
- package/src/hooks/dimensions.js +8 -3
- package/src/hooks/metadata.js +1 -1
- package/src/hooks/test/metadata.js +1 -1
- package/src/hooks/use-content-only-section-edit.js +63 -0
- package/src/hooks/utils.js +4 -0
- package/src/layouts/constrained.js +8 -2
- package/src/private-apis.js +2 -2
- package/src/store/private-keys.js +1 -0
- package/src/store/private-selectors.js +121 -5
- package/src/store/selectors.js +6 -4
- package/src/store/test/private-selectors.js +242 -0
- package/src/style.scss +1 -1
- package/src/utils/fit-text-utils.js +19 -1
- package/tsconfig.json +1 -0
- package/build/components/media-upload-modal/index.js +0 -29
- package/build/components/media-upload-modal/index.js.map +0 -7
- package/build-module/components/media-upload-modal/index.js +0 -8
- package/build-module/components/media-upload-modal/index.js.map +0 -7
- package/src/components/font-family/style.scss +0 -7
- package/src/components/media-upload-modal/index.js +0 -18
- /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
- /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
- /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
store as blocksStore,
|
|
6
|
+
privateApis as blocksPrivateApis,
|
|
7
|
+
} from '@wordpress/blocks';
|
|
8
|
+
import {
|
|
9
|
+
__experimentalHStack as HStack,
|
|
10
|
+
Icon,
|
|
11
|
+
Navigator,
|
|
12
|
+
} from '@wordpress/components';
|
|
13
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
14
|
+
import { __ } from '@wordpress/i18n';
|
|
15
|
+
import { arrowLeft, arrowRight } from '@wordpress/icons';
|
|
16
|
+
import { DataForm } from '@wordpress/dataviews';
|
|
17
|
+
import { useState, useMemo } from '@wordpress/element';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import { unlock } from '../../lock-unlock';
|
|
23
|
+
import { store as blockEditorStore } from '../../store';
|
|
24
|
+
import BlockIcon from '../block-icon';
|
|
25
|
+
import useBlockDisplayTitle from '../block-title/use-block-display-title';
|
|
26
|
+
import useBlockDisplayInformation from '../use-block-display-information';
|
|
27
|
+
const { fieldsKey, formKey } = unlock( blocksPrivateApis );
|
|
28
|
+
import FieldsDropdownMenu from './fields-dropdown-menu';
|
|
29
|
+
|
|
30
|
+
// controls
|
|
31
|
+
import RichText from './rich-text';
|
|
32
|
+
import Media from './media';
|
|
33
|
+
import Link from './link';
|
|
34
|
+
|
|
35
|
+
const CONTROLS = {
|
|
36
|
+
richtext: RichText,
|
|
37
|
+
media: Media,
|
|
38
|
+
link: Link,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a configured control component that wraps a custom control
|
|
43
|
+
* and passes configuration as props.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} config - The control configuration
|
|
46
|
+
* @param {string} config.control - The control type (key in CONTROLS map)
|
|
47
|
+
* @return {Function} A wrapped control component
|
|
48
|
+
*/
|
|
49
|
+
function createConfiguredControl( config ) {
|
|
50
|
+
const { control, ...controlConfig } = config;
|
|
51
|
+
const ControlComponent = CONTROLS[ control ];
|
|
52
|
+
|
|
53
|
+
if ( ! ControlComponent ) {
|
|
54
|
+
throw new Error( `Control type "${ control }" not found` );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return function ConfiguredControl( props ) {
|
|
58
|
+
return <ControlComponent { ...props } config={ controlConfig } />;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a media value to a canonical structure.
|
|
64
|
+
* Only includes properties that are present in the field's mapping (if provided).
|
|
65
|
+
*
|
|
66
|
+
* @param {Object} value - The mapped value from the block attributes (with canonical keys)
|
|
67
|
+
* @param {Object} fieldDef - Optional field definition containing the mapping
|
|
68
|
+
* @return {Object} Normalized media value with canonical properties
|
|
69
|
+
*/
|
|
70
|
+
function normalizeMediaValue( value, fieldDef ) {
|
|
71
|
+
const defaults = {
|
|
72
|
+
id: null,
|
|
73
|
+
url: '',
|
|
74
|
+
caption: '',
|
|
75
|
+
alt: '',
|
|
76
|
+
type: 'image',
|
|
77
|
+
poster: '',
|
|
78
|
+
featuredImage: false,
|
|
79
|
+
link: '',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const result = {};
|
|
83
|
+
|
|
84
|
+
// If there's a mapping, only include properties that are in it
|
|
85
|
+
if ( fieldDef?.mapping ) {
|
|
86
|
+
Object.keys( fieldDef.mapping ).forEach( ( key ) => {
|
|
87
|
+
result[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';
|
|
88
|
+
} );
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Without mapping, include all default properties
|
|
93
|
+
Object.keys( defaults ).forEach( ( key ) => {
|
|
94
|
+
result[ key ] = value?.[ key ] ?? defaults[ key ];
|
|
95
|
+
} );
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Denormalize a media value from canonical structure back to mapped keys.
|
|
101
|
+
* Only includes properties that are present in the field's mapping.
|
|
102
|
+
*
|
|
103
|
+
* @param {Object} value - The normalized media value
|
|
104
|
+
* @param {Object} fieldDef - The field definition containing the mapping
|
|
105
|
+
* @return {Object} Value with only mapped properties
|
|
106
|
+
*/
|
|
107
|
+
function denormalizeMediaValue( value, fieldDef ) {
|
|
108
|
+
if ( ! fieldDef.mapping ) {
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const result = {};
|
|
113
|
+
Object.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {
|
|
114
|
+
if ( key in value ) {
|
|
115
|
+
result[ key ] = value[ key ];
|
|
116
|
+
}
|
|
117
|
+
} );
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Normalize a link value to a canonical structure.
|
|
123
|
+
* Only includes properties that are present in the field's mapping (if provided).
|
|
124
|
+
*
|
|
125
|
+
* @param {Object} value - The mapped value from the block attributes (with canonical keys)
|
|
126
|
+
* @param {Object} fieldDef - Optional field definition containing the mapping
|
|
127
|
+
* @return {Object} Normalized link value with canonical properties
|
|
128
|
+
*/
|
|
129
|
+
function normalizeLinkValue( value, fieldDef ) {
|
|
130
|
+
const defaults = {
|
|
131
|
+
url: '',
|
|
132
|
+
rel: '',
|
|
133
|
+
linkTarget: '',
|
|
134
|
+
destination: '',
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const result = {};
|
|
138
|
+
|
|
139
|
+
// If there's a mapping, only include properties that are in it
|
|
140
|
+
if ( fieldDef?.mapping ) {
|
|
141
|
+
Object.keys( fieldDef.mapping ).forEach( ( key ) => {
|
|
142
|
+
result[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';
|
|
143
|
+
} );
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Without mapping, include all default properties
|
|
148
|
+
Object.keys( defaults ).forEach( ( key ) => {
|
|
149
|
+
result[ key ] = value?.[ key ] ?? defaults[ key ];
|
|
150
|
+
} );
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Denormalize a link value from canonical structure back to mapped keys.
|
|
156
|
+
* Only includes properties that are present in the field's mapping.
|
|
157
|
+
*
|
|
158
|
+
* @param {Object} value - The normalized link value
|
|
159
|
+
* @param {Object} fieldDef - The field definition containing the mapping
|
|
160
|
+
* @return {Object} Value with only mapped properties
|
|
161
|
+
*/
|
|
162
|
+
function denormalizeLinkValue( value, fieldDef ) {
|
|
163
|
+
if ( ! fieldDef.mapping ) {
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const result = {};
|
|
168
|
+
Object.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {
|
|
169
|
+
if ( key in value ) {
|
|
170
|
+
result[ key ] = value[ key ];
|
|
171
|
+
}
|
|
172
|
+
} );
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function BlockFields( { clientId } ) {
|
|
177
|
+
const { attributes, blockType } = useSelect(
|
|
178
|
+
( select ) => {
|
|
179
|
+
const { getBlockAttributes, getBlockName } =
|
|
180
|
+
select( blockEditorStore );
|
|
181
|
+
const { getBlockType } = select( blocksStore );
|
|
182
|
+
const blockName = getBlockName( clientId );
|
|
183
|
+
return {
|
|
184
|
+
attributes: getBlockAttributes( clientId ),
|
|
185
|
+
blockType: getBlockType( blockName ),
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
[ clientId ]
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
192
|
+
const blockTitle = useBlockDisplayTitle( {
|
|
193
|
+
clientId,
|
|
194
|
+
context: 'list-view',
|
|
195
|
+
} );
|
|
196
|
+
const blockInformation = useBlockDisplayInformation( clientId );
|
|
197
|
+
|
|
198
|
+
const blockTypeFields = blockType?.[ fieldsKey ];
|
|
199
|
+
|
|
200
|
+
const [ form, setForm ] = useState( () => {
|
|
201
|
+
return blockType?.[ formKey ];
|
|
202
|
+
} );
|
|
203
|
+
|
|
204
|
+
// Build DataForm fields with proper structure
|
|
205
|
+
const dataFormFields = useMemo( () => {
|
|
206
|
+
if ( ! blockTypeFields?.length ) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return blockTypeFields.map( ( fieldDef ) => {
|
|
211
|
+
const ControlComponent = CONTROLS[ fieldDef.type ];
|
|
212
|
+
|
|
213
|
+
const defaultValues = {};
|
|
214
|
+
if ( fieldDef.mapping && blockType?.attributes ) {
|
|
215
|
+
Object.entries( fieldDef.mapping ).forEach(
|
|
216
|
+
( [ key, attrKey ] ) => {
|
|
217
|
+
defaultValues[ key ] =
|
|
218
|
+
blockType.attributes[ attrKey ]?.defaultValue ??
|
|
219
|
+
undefined;
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const field = {
|
|
225
|
+
id: fieldDef.id,
|
|
226
|
+
label: fieldDef.label,
|
|
227
|
+
type: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit
|
|
228
|
+
config: { ...fieldDef.args, defaultValues },
|
|
229
|
+
hideLabelFromVision: fieldDef.id === 'content',
|
|
230
|
+
// getValue and setValue handle the mapping to block attributes
|
|
231
|
+
getValue: ( { item } ) => {
|
|
232
|
+
if ( fieldDef.mapping ) {
|
|
233
|
+
// Extract mapped properties from the block attributes
|
|
234
|
+
const mappedValue = {};
|
|
235
|
+
Object.entries( fieldDef.mapping ).forEach(
|
|
236
|
+
( [ key, attrKey ] ) => {
|
|
237
|
+
mappedValue[ key ] = item[ attrKey ];
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
// Normalize to canonical structure based on field type
|
|
242
|
+
if ( fieldDef.type === 'media' ) {
|
|
243
|
+
return normalizeMediaValue( mappedValue, fieldDef );
|
|
244
|
+
}
|
|
245
|
+
if ( fieldDef.type === 'link' ) {
|
|
246
|
+
return normalizeLinkValue( mappedValue, fieldDef );
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// For other types, return as-is
|
|
250
|
+
return mappedValue;
|
|
251
|
+
}
|
|
252
|
+
// For simple id-based fields, use the id as the attribute key
|
|
253
|
+
return item[ fieldDef.id ];
|
|
254
|
+
},
|
|
255
|
+
setValue: ( { item, value } ) => {
|
|
256
|
+
if ( fieldDef.mapping ) {
|
|
257
|
+
// Denormalize from canonical structure back to mapped keys
|
|
258
|
+
let denormalizedValue = value;
|
|
259
|
+
if ( fieldDef.type === 'media' ) {
|
|
260
|
+
denormalizedValue = denormalizeMediaValue(
|
|
261
|
+
value,
|
|
262
|
+
fieldDef
|
|
263
|
+
);
|
|
264
|
+
} else if ( fieldDef.type === 'link' ) {
|
|
265
|
+
denormalizedValue = denormalizeLinkValue(
|
|
266
|
+
value,
|
|
267
|
+
fieldDef
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Build an object with all mapped attributes
|
|
272
|
+
const updates = {};
|
|
273
|
+
Object.entries( fieldDef.mapping ).forEach(
|
|
274
|
+
( [ key, attrKey ] ) => {
|
|
275
|
+
// If key is explicitly in value, use it (even if undefined to allow clearing)
|
|
276
|
+
// Otherwise, preserve the old value
|
|
277
|
+
if ( key in denormalizedValue ) {
|
|
278
|
+
updates[ attrKey ] =
|
|
279
|
+
denormalizedValue[ key ];
|
|
280
|
+
} else {
|
|
281
|
+
updates[ attrKey ] = item[ attrKey ];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
return updates;
|
|
286
|
+
}
|
|
287
|
+
// For simple id-based fields, use the id as the attribute key
|
|
288
|
+
return { [ fieldDef.id ]: value };
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// Only add custom Edit component if one exists for this type
|
|
293
|
+
if ( ControlComponent ) {
|
|
294
|
+
// Use EditConfig pattern: Edit is an object with control type and config props
|
|
295
|
+
field.Edit = createConfiguredControl( {
|
|
296
|
+
control: fieldDef.type,
|
|
297
|
+
clientId,
|
|
298
|
+
updateBlockAttributes,
|
|
299
|
+
fieldDef,
|
|
300
|
+
} );
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return field;
|
|
304
|
+
} );
|
|
305
|
+
}, [
|
|
306
|
+
blockTypeFields,
|
|
307
|
+
blockType?.attributes,
|
|
308
|
+
clientId,
|
|
309
|
+
updateBlockAttributes,
|
|
310
|
+
] );
|
|
311
|
+
|
|
312
|
+
const handleToggleField = ( fieldId ) => {
|
|
313
|
+
setForm( ( prev ) => {
|
|
314
|
+
if ( prev.fields?.includes( fieldId ) ) {
|
|
315
|
+
return {
|
|
316
|
+
...prev,
|
|
317
|
+
fields: prev.fields.filter( ( id ) => id !== fieldId ),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
...prev,
|
|
323
|
+
fields: [ ...( prev.fields || [] ), fieldId ],
|
|
324
|
+
};
|
|
325
|
+
} );
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
if ( ! blockTypeFields?.length ) {
|
|
329
|
+
// TODO - we might still want to show a placeholder for blocks with no fields.
|
|
330
|
+
// for example, a way to select the block.
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<div className="block-editor-content-only-controls__fields-container">
|
|
336
|
+
<div className="block-editor-content-only-controls__fields-header">
|
|
337
|
+
<HStack spacing={ 1 } justify="space-between" expanded>
|
|
338
|
+
<HStack spacing={ 1 } justify="flex-start">
|
|
339
|
+
<BlockIcon icon={ blockInformation?.icon } />
|
|
340
|
+
<div>{ blockTitle }</div>
|
|
341
|
+
</HStack>
|
|
342
|
+
<FieldsDropdownMenu
|
|
343
|
+
fields={ dataFormFields }
|
|
344
|
+
visibleFields={ form.fields }
|
|
345
|
+
onToggleField={ handleToggleField }
|
|
346
|
+
/>
|
|
347
|
+
</HStack>
|
|
348
|
+
</div>
|
|
349
|
+
<DataForm
|
|
350
|
+
data={ attributes }
|
|
351
|
+
fields={ dataFormFields }
|
|
352
|
+
form={ form }
|
|
353
|
+
onChange={ ( changes ) => {
|
|
354
|
+
// Map field values to block attributes using field.setValue
|
|
355
|
+
const mappedChanges = {};
|
|
356
|
+
Object.entries( changes ).forEach(
|
|
357
|
+
( [ fieldId, fieldValue ] ) => {
|
|
358
|
+
const field = dataFormFields.find(
|
|
359
|
+
( f ) => f.id === fieldId
|
|
360
|
+
);
|
|
361
|
+
if ( field && field.setValue ) {
|
|
362
|
+
const updates = field.setValue( {
|
|
363
|
+
item: attributes,
|
|
364
|
+
value: fieldValue,
|
|
365
|
+
} );
|
|
366
|
+
Object.assign( mappedChanges, updates );
|
|
367
|
+
} else {
|
|
368
|
+
// For fields without setValue, use the value directly
|
|
369
|
+
mappedChanges[ fieldId ] = fieldValue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
updateBlockAttributes( clientId, mappedChanges );
|
|
374
|
+
} }
|
|
375
|
+
/>
|
|
376
|
+
</div>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function DrillDownButton( { clientId } ) {
|
|
381
|
+
const blockTitle = useBlockDisplayTitle( {
|
|
382
|
+
clientId,
|
|
383
|
+
context: 'list-view',
|
|
384
|
+
} );
|
|
385
|
+
const blockInformation = useBlockDisplayInformation( clientId );
|
|
386
|
+
return (
|
|
387
|
+
<div className="block-editor-content-only-controls__button-panel">
|
|
388
|
+
<Navigator.Button
|
|
389
|
+
path={ `/${ clientId }` }
|
|
390
|
+
className="block-editor-content-only-controls__drill-down-button"
|
|
391
|
+
>
|
|
392
|
+
<HStack expanded justify="space-between">
|
|
393
|
+
<HStack justify="flex-start" spacing={ 1 }>
|
|
394
|
+
<BlockIcon icon={ blockInformation?.icon } />
|
|
395
|
+
<div>{ blockTitle }</div>
|
|
396
|
+
</HStack>
|
|
397
|
+
<Icon icon={ arrowRight } />
|
|
398
|
+
</HStack>
|
|
399
|
+
</Navigator.Button>
|
|
400
|
+
</div>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function ContentOnlyControlsScreen( {
|
|
405
|
+
rootClientId,
|
|
406
|
+
contentClientIds,
|
|
407
|
+
parentClientIds,
|
|
408
|
+
isNested,
|
|
409
|
+
} ) {
|
|
410
|
+
const isRootContentBlock = useSelect(
|
|
411
|
+
( select ) => {
|
|
412
|
+
const { getBlockName } = select( blockEditorStore );
|
|
413
|
+
const blockName = getBlockName( rootClientId );
|
|
414
|
+
const { hasContentRoleAttribute } = unlock( select( blocksStore ) );
|
|
415
|
+
return hasContentRoleAttribute( blockName );
|
|
416
|
+
},
|
|
417
|
+
[ rootClientId ]
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
if ( ! isRootContentBlock && ! contentClientIds.length ) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return (
|
|
425
|
+
<>
|
|
426
|
+
{ isNested && (
|
|
427
|
+
<div className="block-editor-content-only-controls__button-panel">
|
|
428
|
+
<Navigator.BackButton className="block-editor-content-only-controls__back-button">
|
|
429
|
+
<HStack expanded spacing={ 1 } justify="flex-start">
|
|
430
|
+
<Icon icon={ arrowLeft } />
|
|
431
|
+
<div>{ __( 'Back' ) }</div>
|
|
432
|
+
</HStack>
|
|
433
|
+
</Navigator.BackButton>
|
|
434
|
+
</div>
|
|
435
|
+
) }
|
|
436
|
+
{ isRootContentBlock && <BlockFields clientId={ rootClientId } /> }
|
|
437
|
+
{ contentClientIds.map( ( clientId ) => {
|
|
438
|
+
if ( parentClientIds?.[ clientId ] ) {
|
|
439
|
+
return (
|
|
440
|
+
<DrillDownButton
|
|
441
|
+
key={ clientId }
|
|
442
|
+
clientId={ clientId }
|
|
443
|
+
/>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return <BlockFields key={ clientId } clientId={ clientId } />;
|
|
448
|
+
} ) }
|
|
449
|
+
</>
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export default function ContentOnlyControls( { rootClientId } ) {
|
|
454
|
+
const { updatedRootClientId, nestedContentClientIds, contentClientIds } =
|
|
455
|
+
useSelect(
|
|
456
|
+
( select ) => {
|
|
457
|
+
const { getClientIdsOfDescendants, getBlockEditingMode } =
|
|
458
|
+
select( blockEditorStore );
|
|
459
|
+
|
|
460
|
+
// _nestedContentClientIds is for content blocks within 'drilldowns'.
|
|
461
|
+
// It's an object where the key is the parent clientId, and the element is
|
|
462
|
+
// an array of child clientIds whose controls are shown within the drilldown.
|
|
463
|
+
const _nestedContentClientIds = {};
|
|
464
|
+
|
|
465
|
+
// _contentClientIds is the list of contentClientIds for blocks being
|
|
466
|
+
// shown at the root level. Includes parent blocks that might have a drilldown,
|
|
467
|
+
// but not the children of those blocks.
|
|
468
|
+
const _contentClientIds = [];
|
|
469
|
+
|
|
470
|
+
// An array of all nested client ids. Used for ensuring blocks within drilldowns
|
|
471
|
+
// don't appear at the root level.
|
|
472
|
+
let allNestedClientIds = [];
|
|
473
|
+
|
|
474
|
+
// A flattened list of all content clientIds to arrange into the
|
|
475
|
+
// groups above.
|
|
476
|
+
const allContentClientIds = getClientIdsOfDescendants(
|
|
477
|
+
rootClientId
|
|
478
|
+
).filter(
|
|
479
|
+
( clientId ) =>
|
|
480
|
+
getBlockEditingMode( clientId ) === 'contentOnly'
|
|
481
|
+
);
|
|
482
|
+
|
|
483
|
+
for ( const clientId of allContentClientIds ) {
|
|
484
|
+
const childClientIds = getClientIdsOfDescendants(
|
|
485
|
+
clientId
|
|
486
|
+
).filter(
|
|
487
|
+
( childClientId ) =>
|
|
488
|
+
getBlockEditingMode( childClientId ) ===
|
|
489
|
+
'contentOnly'
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
// If there's more than one child block, use a drilldown.
|
|
493
|
+
if (
|
|
494
|
+
childClientIds.length > 1 &&
|
|
495
|
+
! allNestedClientIds.includes( clientId )
|
|
496
|
+
) {
|
|
497
|
+
_nestedContentClientIds[ clientId ] = childClientIds;
|
|
498
|
+
allNestedClientIds = [
|
|
499
|
+
allNestedClientIds,
|
|
500
|
+
...childClientIds,
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if ( ! allNestedClientIds.includes( clientId ) ) {
|
|
505
|
+
_contentClientIds.push( clientId );
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Avoid showing only one drilldown block at the root.
|
|
510
|
+
if (
|
|
511
|
+
_contentClientIds.length === 1 &&
|
|
512
|
+
Object.keys( _nestedContentClientIds ).length === 1
|
|
513
|
+
) {
|
|
514
|
+
const onlyParentClientId = Object.keys(
|
|
515
|
+
_nestedContentClientIds
|
|
516
|
+
)[ 0 ];
|
|
517
|
+
return {
|
|
518
|
+
updatedRootClientId: onlyParentClientId,
|
|
519
|
+
contentClientIds:
|
|
520
|
+
_nestedContentClientIds[ onlyParentClientId ],
|
|
521
|
+
nestedContentClientIds: {},
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return {
|
|
526
|
+
nestedContentClientIds: _nestedContentClientIds,
|
|
527
|
+
contentClientIds: _contentClientIds,
|
|
528
|
+
};
|
|
529
|
+
},
|
|
530
|
+
[ rootClientId ]
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
return (
|
|
534
|
+
<Navigator initialPath="/">
|
|
535
|
+
<Navigator.Screen
|
|
536
|
+
path="/"
|
|
537
|
+
className="block-editor-content-only-controls__screen"
|
|
538
|
+
>
|
|
539
|
+
<ContentOnlyControlsScreen
|
|
540
|
+
rootClientId={ updatedRootClientId ?? rootClientId }
|
|
541
|
+
contentClientIds={ contentClientIds }
|
|
542
|
+
parentClientIds={ nestedContentClientIds }
|
|
543
|
+
/>
|
|
544
|
+
</Navigator.Screen>
|
|
545
|
+
{ Object.keys( nestedContentClientIds ).map( ( clientId ) => (
|
|
546
|
+
<Navigator.Screen
|
|
547
|
+
key={ clientId }
|
|
548
|
+
path={ `/${ clientId }` }
|
|
549
|
+
className="block-editor-content-only-controls__screen"
|
|
550
|
+
>
|
|
551
|
+
<ContentOnlyControlsScreen
|
|
552
|
+
isNested
|
|
553
|
+
rootClientId={ clientId }
|
|
554
|
+
contentClientIds={ nestedContentClientIds[ clientId ] }
|
|
555
|
+
/>
|
|
556
|
+
</Navigator.Screen>
|
|
557
|
+
) ) }
|
|
558
|
+
</Navigator>
|
|
559
|
+
);
|
|
560
|
+
}
|