@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,420 @@
|
|
|
1
|
+
// packages/block-editor/src/components/content-only-controls/index.js
|
|
2
|
+
import {
|
|
3
|
+
store as blocksStore,
|
|
4
|
+
privateApis as blocksPrivateApis
|
|
5
|
+
} from "@wordpress/blocks";
|
|
6
|
+
import {
|
|
7
|
+
__experimentalHStack as HStack,
|
|
8
|
+
Icon,
|
|
9
|
+
Navigator
|
|
10
|
+
} from "@wordpress/components";
|
|
11
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
12
|
+
import { __ } from "@wordpress/i18n";
|
|
13
|
+
import { arrowLeft, arrowRight } from "@wordpress/icons";
|
|
14
|
+
import { DataForm } from "@wordpress/dataviews";
|
|
15
|
+
import { useState, useMemo } from "@wordpress/element";
|
|
16
|
+
import { unlock } from "../../lock-unlock";
|
|
17
|
+
import { store as blockEditorStore } from "../../store";
|
|
18
|
+
import BlockIcon from "../block-icon";
|
|
19
|
+
import useBlockDisplayTitle from "../block-title/use-block-display-title";
|
|
20
|
+
import useBlockDisplayInformation from "../use-block-display-information";
|
|
21
|
+
import FieldsDropdownMenu from "./fields-dropdown-menu";
|
|
22
|
+
import RichText from "./rich-text";
|
|
23
|
+
import Media from "./media";
|
|
24
|
+
import Link from "./link";
|
|
25
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
26
|
+
var { fieldsKey, formKey } = unlock(blocksPrivateApis);
|
|
27
|
+
var CONTROLS = {
|
|
28
|
+
richtext: RichText,
|
|
29
|
+
media: Media,
|
|
30
|
+
link: Link
|
|
31
|
+
};
|
|
32
|
+
function createConfiguredControl(config) {
|
|
33
|
+
const { control, ...controlConfig } = config;
|
|
34
|
+
const ControlComponent = CONTROLS[control];
|
|
35
|
+
if (!ControlComponent) {
|
|
36
|
+
throw new Error(`Control type "${control}" not found`);
|
|
37
|
+
}
|
|
38
|
+
return function ConfiguredControl(props) {
|
|
39
|
+
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config: controlConfig });
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function normalizeMediaValue(value, fieldDef) {
|
|
43
|
+
const defaults = {
|
|
44
|
+
id: null,
|
|
45
|
+
url: "",
|
|
46
|
+
caption: "",
|
|
47
|
+
alt: "",
|
|
48
|
+
type: "image",
|
|
49
|
+
poster: "",
|
|
50
|
+
featuredImage: false,
|
|
51
|
+
link: ""
|
|
52
|
+
};
|
|
53
|
+
const result = {};
|
|
54
|
+
if (fieldDef?.mapping) {
|
|
55
|
+
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
56
|
+
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
Object.keys(defaults).forEach((key) => {
|
|
61
|
+
result[key] = value?.[key] ?? defaults[key];
|
|
62
|
+
});
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function denormalizeMediaValue(value, fieldDef) {
|
|
66
|
+
if (!fieldDef.mapping) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
const result = {};
|
|
70
|
+
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
71
|
+
if (key in value) {
|
|
72
|
+
result[key] = value[key];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
function normalizeLinkValue(value, fieldDef) {
|
|
78
|
+
const defaults = {
|
|
79
|
+
url: "",
|
|
80
|
+
rel: "",
|
|
81
|
+
linkTarget: "",
|
|
82
|
+
destination: ""
|
|
83
|
+
};
|
|
84
|
+
const result = {};
|
|
85
|
+
if (fieldDef?.mapping) {
|
|
86
|
+
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
87
|
+
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
Object.keys(defaults).forEach((key) => {
|
|
92
|
+
result[key] = value?.[key] ?? defaults[key];
|
|
93
|
+
});
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function denormalizeLinkValue(value, fieldDef) {
|
|
97
|
+
if (!fieldDef.mapping) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
const result = {};
|
|
101
|
+
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
102
|
+
if (key in value) {
|
|
103
|
+
result[key] = value[key];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function BlockFields({ clientId }) {
|
|
109
|
+
const { attributes, blockType } = useSelect(
|
|
110
|
+
(select) => {
|
|
111
|
+
const { getBlockAttributes, getBlockName } = select(blockEditorStore);
|
|
112
|
+
const { getBlockType } = select(blocksStore);
|
|
113
|
+
const blockName = getBlockName(clientId);
|
|
114
|
+
return {
|
|
115
|
+
attributes: getBlockAttributes(clientId),
|
|
116
|
+
blockType: getBlockType(blockName)
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
[clientId]
|
|
120
|
+
);
|
|
121
|
+
const { updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
122
|
+
const blockTitle = useBlockDisplayTitle({
|
|
123
|
+
clientId,
|
|
124
|
+
context: "list-view"
|
|
125
|
+
});
|
|
126
|
+
const blockInformation = useBlockDisplayInformation(clientId);
|
|
127
|
+
const blockTypeFields = blockType?.[fieldsKey];
|
|
128
|
+
const [form, setForm] = useState(() => {
|
|
129
|
+
return blockType?.[formKey];
|
|
130
|
+
});
|
|
131
|
+
const dataFormFields = useMemo(() => {
|
|
132
|
+
if (!blockTypeFields?.length) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return blockTypeFields.map((fieldDef) => {
|
|
136
|
+
const ControlComponent = CONTROLS[fieldDef.type];
|
|
137
|
+
const defaultValues = {};
|
|
138
|
+
if (fieldDef.mapping && blockType?.attributes) {
|
|
139
|
+
Object.entries(fieldDef.mapping).forEach(
|
|
140
|
+
([key, attrKey]) => {
|
|
141
|
+
defaultValues[key] = blockType.attributes[attrKey]?.defaultValue ?? void 0;
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const field = {
|
|
146
|
+
id: fieldDef.id,
|
|
147
|
+
label: fieldDef.label,
|
|
148
|
+
type: fieldDef.type,
|
|
149
|
+
// Use the field's type; DataForm will use built-in or custom Edit
|
|
150
|
+
config: { ...fieldDef.args, defaultValues },
|
|
151
|
+
hideLabelFromVision: fieldDef.id === "content",
|
|
152
|
+
// getValue and setValue handle the mapping to block attributes
|
|
153
|
+
getValue: ({ item }) => {
|
|
154
|
+
if (fieldDef.mapping) {
|
|
155
|
+
const mappedValue = {};
|
|
156
|
+
Object.entries(fieldDef.mapping).forEach(
|
|
157
|
+
([key, attrKey]) => {
|
|
158
|
+
mappedValue[key] = item[attrKey];
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
if (fieldDef.type === "media") {
|
|
162
|
+
return normalizeMediaValue(mappedValue, fieldDef);
|
|
163
|
+
}
|
|
164
|
+
if (fieldDef.type === "link") {
|
|
165
|
+
return normalizeLinkValue(mappedValue, fieldDef);
|
|
166
|
+
}
|
|
167
|
+
return mappedValue;
|
|
168
|
+
}
|
|
169
|
+
return item[fieldDef.id];
|
|
170
|
+
},
|
|
171
|
+
setValue: ({ item, value }) => {
|
|
172
|
+
if (fieldDef.mapping) {
|
|
173
|
+
let denormalizedValue = value;
|
|
174
|
+
if (fieldDef.type === "media") {
|
|
175
|
+
denormalizedValue = denormalizeMediaValue(
|
|
176
|
+
value,
|
|
177
|
+
fieldDef
|
|
178
|
+
);
|
|
179
|
+
} else if (fieldDef.type === "link") {
|
|
180
|
+
denormalizedValue = denormalizeLinkValue(
|
|
181
|
+
value,
|
|
182
|
+
fieldDef
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const updates = {};
|
|
186
|
+
Object.entries(fieldDef.mapping).forEach(
|
|
187
|
+
([key, attrKey]) => {
|
|
188
|
+
if (key in denormalizedValue) {
|
|
189
|
+
updates[attrKey] = denormalizedValue[key];
|
|
190
|
+
} else {
|
|
191
|
+
updates[attrKey] = item[attrKey];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
return updates;
|
|
196
|
+
}
|
|
197
|
+
return { [fieldDef.id]: value };
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
if (ControlComponent) {
|
|
201
|
+
field.Edit = createConfiguredControl({
|
|
202
|
+
control: fieldDef.type,
|
|
203
|
+
clientId,
|
|
204
|
+
updateBlockAttributes,
|
|
205
|
+
fieldDef
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return field;
|
|
209
|
+
});
|
|
210
|
+
}, [
|
|
211
|
+
blockTypeFields,
|
|
212
|
+
blockType?.attributes,
|
|
213
|
+
clientId,
|
|
214
|
+
updateBlockAttributes
|
|
215
|
+
]);
|
|
216
|
+
const handleToggleField = (fieldId) => {
|
|
217
|
+
setForm((prev) => {
|
|
218
|
+
if (prev.fields?.includes(fieldId)) {
|
|
219
|
+
return {
|
|
220
|
+
...prev,
|
|
221
|
+
fields: prev.fields.filter((id) => id !== fieldId)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
...prev,
|
|
226
|
+
fields: [...prev.fields || [], fieldId]
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
if (!blockTypeFields?.length) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return /* @__PURE__ */ jsxs("div", { className: "block-editor-content-only-controls__fields-container", children: [
|
|
234
|
+
/* @__PURE__ */ jsx("div", { className: "block-editor-content-only-controls__fields-header", children: /* @__PURE__ */ jsxs(HStack, { spacing: 1, justify: "space-between", expanded: true, children: [
|
|
235
|
+
/* @__PURE__ */ jsxs(HStack, { spacing: 1, justify: "flex-start", children: [
|
|
236
|
+
/* @__PURE__ */ jsx(BlockIcon, { icon: blockInformation?.icon }),
|
|
237
|
+
/* @__PURE__ */ jsx("div", { children: blockTitle })
|
|
238
|
+
] }),
|
|
239
|
+
/* @__PURE__ */ jsx(
|
|
240
|
+
FieldsDropdownMenu,
|
|
241
|
+
{
|
|
242
|
+
fields: dataFormFields,
|
|
243
|
+
visibleFields: form.fields,
|
|
244
|
+
onToggleField: handleToggleField
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
] }) }),
|
|
248
|
+
/* @__PURE__ */ jsx(
|
|
249
|
+
DataForm,
|
|
250
|
+
{
|
|
251
|
+
data: attributes,
|
|
252
|
+
fields: dataFormFields,
|
|
253
|
+
form,
|
|
254
|
+
onChange: (changes) => {
|
|
255
|
+
const mappedChanges = {};
|
|
256
|
+
Object.entries(changes).forEach(
|
|
257
|
+
([fieldId, fieldValue]) => {
|
|
258
|
+
const field = dataFormFields.find(
|
|
259
|
+
(f) => f.id === fieldId
|
|
260
|
+
);
|
|
261
|
+
if (field && field.setValue) {
|
|
262
|
+
const updates = field.setValue({
|
|
263
|
+
item: attributes,
|
|
264
|
+
value: fieldValue
|
|
265
|
+
});
|
|
266
|
+
Object.assign(mappedChanges, updates);
|
|
267
|
+
} else {
|
|
268
|
+
mappedChanges[fieldId] = fieldValue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
updateBlockAttributes(clientId, mappedChanges);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
)
|
|
276
|
+
] });
|
|
277
|
+
}
|
|
278
|
+
function DrillDownButton({ clientId }) {
|
|
279
|
+
const blockTitle = useBlockDisplayTitle({
|
|
280
|
+
clientId,
|
|
281
|
+
context: "list-view"
|
|
282
|
+
});
|
|
283
|
+
const blockInformation = useBlockDisplayInformation(clientId);
|
|
284
|
+
return /* @__PURE__ */ jsx("div", { className: "block-editor-content-only-controls__button-panel", children: /* @__PURE__ */ jsx(
|
|
285
|
+
Navigator.Button,
|
|
286
|
+
{
|
|
287
|
+
path: `/${clientId}`,
|
|
288
|
+
className: "block-editor-content-only-controls__drill-down-button",
|
|
289
|
+
children: /* @__PURE__ */ jsxs(HStack, { expanded: true, justify: "space-between", children: [
|
|
290
|
+
/* @__PURE__ */ jsxs(HStack, { justify: "flex-start", spacing: 1, children: [
|
|
291
|
+
/* @__PURE__ */ jsx(BlockIcon, { icon: blockInformation?.icon }),
|
|
292
|
+
/* @__PURE__ */ jsx("div", { children: blockTitle })
|
|
293
|
+
] }),
|
|
294
|
+
/* @__PURE__ */ jsx(Icon, { icon: arrowRight })
|
|
295
|
+
] })
|
|
296
|
+
}
|
|
297
|
+
) });
|
|
298
|
+
}
|
|
299
|
+
function ContentOnlyControlsScreen({
|
|
300
|
+
rootClientId,
|
|
301
|
+
contentClientIds,
|
|
302
|
+
parentClientIds,
|
|
303
|
+
isNested
|
|
304
|
+
}) {
|
|
305
|
+
const isRootContentBlock = useSelect(
|
|
306
|
+
(select) => {
|
|
307
|
+
const { getBlockName } = select(blockEditorStore);
|
|
308
|
+
const blockName = getBlockName(rootClientId);
|
|
309
|
+
const { hasContentRoleAttribute } = unlock(select(blocksStore));
|
|
310
|
+
return hasContentRoleAttribute(blockName);
|
|
311
|
+
},
|
|
312
|
+
[rootClientId]
|
|
313
|
+
);
|
|
314
|
+
if (!isRootContentBlock && !contentClientIds.length) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
318
|
+
isNested && /* @__PURE__ */ jsx("div", { className: "block-editor-content-only-controls__button-panel", children: /* @__PURE__ */ jsx(Navigator.BackButton, { className: "block-editor-content-only-controls__back-button", children: /* @__PURE__ */ jsxs(HStack, { expanded: true, spacing: 1, justify: "flex-start", children: [
|
|
319
|
+
/* @__PURE__ */ jsx(Icon, { icon: arrowLeft }),
|
|
320
|
+
/* @__PURE__ */ jsx("div", { children: __("Back") })
|
|
321
|
+
] }) }) }),
|
|
322
|
+
isRootContentBlock && /* @__PURE__ */ jsx(BlockFields, { clientId: rootClientId }),
|
|
323
|
+
contentClientIds.map((clientId) => {
|
|
324
|
+
if (parentClientIds?.[clientId]) {
|
|
325
|
+
return /* @__PURE__ */ jsx(
|
|
326
|
+
DrillDownButton,
|
|
327
|
+
{
|
|
328
|
+
clientId
|
|
329
|
+
},
|
|
330
|
+
clientId
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
return /* @__PURE__ */ jsx(BlockFields, { clientId }, clientId);
|
|
334
|
+
})
|
|
335
|
+
] });
|
|
336
|
+
}
|
|
337
|
+
function ContentOnlyControls({ rootClientId }) {
|
|
338
|
+
const { updatedRootClientId, nestedContentClientIds, contentClientIds } = useSelect(
|
|
339
|
+
(select) => {
|
|
340
|
+
const { getClientIdsOfDescendants, getBlockEditingMode } = select(blockEditorStore);
|
|
341
|
+
const _nestedContentClientIds = {};
|
|
342
|
+
const _contentClientIds = [];
|
|
343
|
+
let allNestedClientIds = [];
|
|
344
|
+
const allContentClientIds = getClientIdsOfDescendants(
|
|
345
|
+
rootClientId
|
|
346
|
+
).filter(
|
|
347
|
+
(clientId) => getBlockEditingMode(clientId) === "contentOnly"
|
|
348
|
+
);
|
|
349
|
+
for (const clientId of allContentClientIds) {
|
|
350
|
+
const childClientIds = getClientIdsOfDescendants(
|
|
351
|
+
clientId
|
|
352
|
+
).filter(
|
|
353
|
+
(childClientId) => getBlockEditingMode(childClientId) === "contentOnly"
|
|
354
|
+
);
|
|
355
|
+
if (childClientIds.length > 1 && !allNestedClientIds.includes(clientId)) {
|
|
356
|
+
_nestedContentClientIds[clientId] = childClientIds;
|
|
357
|
+
allNestedClientIds = [
|
|
358
|
+
allNestedClientIds,
|
|
359
|
+
...childClientIds
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
if (!allNestedClientIds.includes(clientId)) {
|
|
363
|
+
_contentClientIds.push(clientId);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (_contentClientIds.length === 1 && Object.keys(_nestedContentClientIds).length === 1) {
|
|
367
|
+
const onlyParentClientId = Object.keys(
|
|
368
|
+
_nestedContentClientIds
|
|
369
|
+
)[0];
|
|
370
|
+
return {
|
|
371
|
+
updatedRootClientId: onlyParentClientId,
|
|
372
|
+
contentClientIds: _nestedContentClientIds[onlyParentClientId],
|
|
373
|
+
nestedContentClientIds: {}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
nestedContentClientIds: _nestedContentClientIds,
|
|
378
|
+
contentClientIds: _contentClientIds
|
|
379
|
+
};
|
|
380
|
+
},
|
|
381
|
+
[rootClientId]
|
|
382
|
+
);
|
|
383
|
+
return /* @__PURE__ */ jsxs(Navigator, { initialPath: "/", children: [
|
|
384
|
+
/* @__PURE__ */ jsx(
|
|
385
|
+
Navigator.Screen,
|
|
386
|
+
{
|
|
387
|
+
path: "/",
|
|
388
|
+
className: "block-editor-content-only-controls__screen",
|
|
389
|
+
children: /* @__PURE__ */ jsx(
|
|
390
|
+
ContentOnlyControlsScreen,
|
|
391
|
+
{
|
|
392
|
+
rootClientId: updatedRootClientId ?? rootClientId,
|
|
393
|
+
contentClientIds,
|
|
394
|
+
parentClientIds: nestedContentClientIds
|
|
395
|
+
}
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
),
|
|
399
|
+
Object.keys(nestedContentClientIds).map((clientId) => /* @__PURE__ */ jsx(
|
|
400
|
+
Navigator.Screen,
|
|
401
|
+
{
|
|
402
|
+
path: `/${clientId}`,
|
|
403
|
+
className: "block-editor-content-only-controls__screen",
|
|
404
|
+
children: /* @__PURE__ */ jsx(
|
|
405
|
+
ContentOnlyControlsScreen,
|
|
406
|
+
{
|
|
407
|
+
isNested: true,
|
|
408
|
+
rootClientId: clientId,
|
|
409
|
+
contentClientIds: nestedContentClientIds[clientId]
|
|
410
|
+
}
|
|
411
|
+
)
|
|
412
|
+
},
|
|
413
|
+
clientId
|
|
414
|
+
))
|
|
415
|
+
] });
|
|
416
|
+
}
|
|
417
|
+
export {
|
|
418
|
+
ContentOnlyControls as default
|
|
419
|
+
};
|
|
420
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/content-only-controls/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tprivateApis as blocksPrivateApis,\n} from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\tIcon,\n\tNavigator,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { arrowLeft, arrowRight } from '@wordpress/icons';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as blockEditorStore } from '../../store';\nimport BlockIcon from '../block-icon';\nimport useBlockDisplayTitle from '../block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\nconst CONTROLS = {\n\trichtext: RichText,\n\tmedia: Media,\n\tlink: Link,\n};\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Object} config - The control configuration\n * @param {string} config.control - The control type (key in CONTROLS map)\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( config ) {\n\tconst { control, ...controlConfig } = config;\n\tconst ControlComponent = CONTROLS[ control ];\n\n\tif ( ! ControlComponent ) {\n\t\tthrow new Error( `Control type \"${ control }\" not found` );\n\t}\n\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ controlConfig } />;\n\t};\n}\n\n/**\n * Normalize a media value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized media value with canonical properties\n */\nfunction normalizeMediaValue( value, fieldDef ) {\n\tconst defaults = {\n\t\tid: null,\n\t\turl: '',\n\t\tcaption: '',\n\t\talt: '',\n\t\ttype: 'image',\n\t\tposter: '',\n\t\tfeaturedImage: false,\n\t\tlink: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a media value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized media value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeMediaValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\n/**\n * Normalize a link value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized link value with canonical properties\n */\nfunction normalizeLinkValue( value, fieldDef ) {\n\tconst defaults = {\n\t\turl: '',\n\t\trel: '',\n\t\tlinkTarget: '',\n\t\tdestination: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a link value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized link value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeLinkValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\nfunction BlockFields( { clientId } ) {\n\tconst { attributes, blockType } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType } = select( blocksStore );\n\t\t\tconst blockName = getBlockName( clientId );\n\t\t\treturn {\n\t\t\t\tattributes: getBlockAttributes( clientId ),\n\t\t\t\tblockType: getBlockType( blockName ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst [ form, setForm ] = useState( () => {\n\t\treturn blockType?.[ formKey ];\n\t} );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst ControlComponent = CONTROLS[ fieldDef.type ];\n\n\t\t\tconst defaultValues = {};\n\t\t\tif ( fieldDef.mapping && blockType?.attributes ) {\n\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\tdefaultValues[ key ] =\n\t\t\t\t\t\t\tblockType.attributes[ attrKey ]?.defaultValue ??\n\t\t\t\t\t\t\tundefined;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst field = {\n\t\t\t\tid: fieldDef.id,\n\t\t\t\tlabel: fieldDef.label,\n\t\t\t\ttype: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit\n\t\t\t\tconfig: { ...fieldDef.args, defaultValues },\n\t\t\t\thideLabelFromVision: fieldDef.id === 'content',\n\t\t\t\t// getValue and setValue handle the mapping to block attributes\n\t\t\t\tgetValue: ( { item } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Extract mapped properties from the block attributes\n\t\t\t\t\t\tconst mappedValue = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\tmappedValue[ key ] = item[ attrKey ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Normalize to canonical structure based on field type\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\treturn normalizeMediaValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\treturn normalizeLinkValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// For other types, return as-is\n\t\t\t\t\t\treturn mappedValue;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn item[ fieldDef.id ];\n\t\t\t\t},\n\t\t\t\tsetValue: ( { item, value } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Denormalize from canonical structure back to mapped keys\n\t\t\t\t\t\tlet denormalizedValue = value;\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeMediaValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeLinkValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Build an object with all mapped attributes\n\t\t\t\t\t\tconst updates = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\t// If key is explicitly in value, use it (even if undefined to allow clearing)\n\t\t\t\t\t\t\t\t// Otherwise, preserve the old value\n\t\t\t\t\t\t\t\tif ( key in denormalizedValue ) {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] =\n\t\t\t\t\t\t\t\t\t\tdenormalizedValue[ key ];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] = item[ attrKey ];\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\treturn updates;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn { [ fieldDef.id ]: value };\n\t\t\t\t},\n\t\t\t};\n\n\t\t\t// Only add custom Edit component if one exists for this type\n\t\t\tif ( ControlComponent ) {\n\t\t\t\t// Use EditConfig pattern: Edit is an object with control type and config props\n\t\t\t\tfield.Edit = createConfiguredControl( {\n\t\t\t\t\tcontrol: fieldDef.type,\n\t\t\t\t\tclientId,\n\t\t\t\t\tupdateBlockAttributes,\n\t\t\t\t\tfieldDef,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [\n\t\tblockTypeFields,\n\t\tblockType?.attributes,\n\t\tclientId,\n\t\tupdateBlockAttributes,\n\t] );\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"block-editor-content-only-controls__fields-container\">\n\t\t\t<div className=\"block-editor-content-only-controls__fields-header\">\n\t\t\t\t<HStack spacing={ 1 } justify=\"space-between\" expanded>\n\t\t\t\t\t<HStack spacing={ 1 } justify=\"flex-start\">\n\t\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } />\n\t\t\t\t\t\t<div>{ blockTitle }</div>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\tonToggleField={ handleToggleField }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ ( changes ) => {\n\t\t\t\t\t// Map field values to block attributes using field.setValue\n\t\t\t\t\tconst mappedChanges = {};\n\t\t\t\t\tObject.entries( changes ).forEach(\n\t\t\t\t\t\t( [ fieldId, fieldValue ] ) => {\n\t\t\t\t\t\t\tconst field = dataFormFields.find(\n\t\t\t\t\t\t\t\t( f ) => f.id === fieldId\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif ( field && field.setValue ) {\n\t\t\t\t\t\t\t\tconst updates = field.setValue( {\n\t\t\t\t\t\t\t\t\titem: attributes,\n\t\t\t\t\t\t\t\t\tvalue: fieldValue,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\tObject.assign( mappedChanges, updates );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// For fields without setValue, use the value directly\n\t\t\t\t\t\t\t\tmappedChanges[ fieldId ] = fieldValue;\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\t\tupdateBlockAttributes( clientId, mappedChanges );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction DrillDownButton( { clientId } ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\treturn (\n\t\t<div className=\"block-editor-content-only-controls__button-panel\">\n\t\t\t<Navigator.Button\n\t\t\t\tpath={ `/${ clientId }` }\n\t\t\t\tclassName=\"block-editor-content-only-controls__drill-down-button\"\n\t\t\t>\n\t\t\t\t<HStack expanded justify=\"space-between\">\n\t\t\t\t\t<HStack justify=\"flex-start\" spacing={ 1 }>\n\t\t\t\t\t\t<BlockIcon icon={ blockInformation?.icon } />\n\t\t\t\t\t\t<div>{ blockTitle }</div>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t<Icon icon={ arrowRight } />\n\t\t\t\t</HStack>\n\t\t\t</Navigator.Button>\n\t\t</div>\n\t);\n}\n\nfunction ContentOnlyControlsScreen( {\n\trootClientId,\n\tcontentClientIds,\n\tparentClientIds,\n\tisNested,\n} ) {\n\tconst isRootContentBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockName } = select( blockEditorStore );\n\t\t\tconst blockName = getBlockName( rootClientId );\n\t\t\tconst { hasContentRoleAttribute } = unlock( select( blocksStore ) );\n\t\t\treturn hasContentRoleAttribute( blockName );\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\n\tif ( ! isRootContentBlock && ! contentClientIds.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isNested && (\n\t\t\t\t<div className=\"block-editor-content-only-controls__button-panel\">\n\t\t\t\t\t<Navigator.BackButton className=\"block-editor-content-only-controls__back-button\">\n\t\t\t\t\t\t<HStack expanded spacing={ 1 } justify=\"flex-start\">\n\t\t\t\t\t\t\t<Icon icon={ arrowLeft } />\n\t\t\t\t\t\t\t<div>{ __( 'Back' ) }</div>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Navigator.BackButton>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isRootContentBlock && <BlockFields clientId={ rootClientId } /> }\n\t\t\t{ contentClientIds.map( ( clientId ) => {\n\t\t\t\tif ( parentClientIds?.[ clientId ] ) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<DrillDownButton\n\t\t\t\t\t\t\tkey={ clientId }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn <BlockFields key={ clientId } clientId={ clientId } />;\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n\nexport default function ContentOnlyControls( { rootClientId } ) {\n\tconst { updatedRootClientId, nestedContentClientIds, contentClientIds } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getClientIdsOfDescendants, getBlockEditingMode } =\n\t\t\t\t\tselect( blockEditorStore );\n\n\t\t\t\t// _nestedContentClientIds is for content blocks within 'drilldowns'.\n\t\t\t\t// It's an object where the key is the parent clientId, and the element is\n\t\t\t\t// an array of child clientIds whose controls are shown within the drilldown.\n\t\t\t\tconst _nestedContentClientIds = {};\n\n\t\t\t\t// _contentClientIds is the list of contentClientIds for blocks being\n\t\t\t\t// shown at the root level. Includes parent blocks that might have a drilldown,\n\t\t\t\t// but not the children of those blocks.\n\t\t\t\tconst _contentClientIds = [];\n\n\t\t\t\t// An array of all nested client ids. Used for ensuring blocks within drilldowns\n\t\t\t\t// don't appear at the root level.\n\t\t\t\tlet allNestedClientIds = [];\n\n\t\t\t\t// A flattened list of all content clientIds to arrange into the\n\t\t\t\t// groups above.\n\t\t\t\tconst allContentClientIds = getClientIdsOfDescendants(\n\t\t\t\t\trootClientId\n\t\t\t\t).filter(\n\t\t\t\t\t( clientId ) =>\n\t\t\t\t\t\tgetBlockEditingMode( clientId ) === 'contentOnly'\n\t\t\t\t);\n\n\t\t\t\tfor ( const clientId of allContentClientIds ) {\n\t\t\t\t\tconst childClientIds = getClientIdsOfDescendants(\n\t\t\t\t\t\tclientId\n\t\t\t\t\t).filter(\n\t\t\t\t\t\t( childClientId ) =>\n\t\t\t\t\t\t\tgetBlockEditingMode( childClientId ) ===\n\t\t\t\t\t\t\t'contentOnly'\n\t\t\t\t\t);\n\n\t\t\t\t\t// If there's more than one child block, use a drilldown.\n\t\t\t\t\tif (\n\t\t\t\t\t\tchildClientIds.length > 1 &&\n\t\t\t\t\t\t! allNestedClientIds.includes( clientId )\n\t\t\t\t\t) {\n\t\t\t\t\t\t_nestedContentClientIds[ clientId ] = childClientIds;\n\t\t\t\t\t\tallNestedClientIds = [\n\t\t\t\t\t\t\tallNestedClientIds,\n\t\t\t\t\t\t\t...childClientIds,\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! allNestedClientIds.includes( clientId ) ) {\n\t\t\t\t\t\t_contentClientIds.push( clientId );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Avoid showing only one drilldown block at the root.\n\t\t\t\tif (\n\t\t\t\t\t_contentClientIds.length === 1 &&\n\t\t\t\t\tObject.keys( _nestedContentClientIds ).length === 1\n\t\t\t\t) {\n\t\t\t\t\tconst onlyParentClientId = Object.keys(\n\t\t\t\t\t\t_nestedContentClientIds\n\t\t\t\t\t)[ 0 ];\n\t\t\t\t\treturn {\n\t\t\t\t\t\tupdatedRootClientId: onlyParentClientId,\n\t\t\t\t\t\tcontentClientIds:\n\t\t\t\t\t\t\t_nestedContentClientIds[ onlyParentClientId ],\n\t\t\t\t\t\tnestedContentClientIds: {},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tnestedContentClientIds: _nestedContentClientIds,\n\t\t\t\t\tcontentClientIds: _contentClientIds,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ rootClientId ]\n\t\t);\n\n\treturn (\n\t\t<Navigator initialPath=\"/\">\n\t\t\t<Navigator.Screen\n\t\t\t\tpath=\"/\"\n\t\t\t\tclassName=\"block-editor-content-only-controls__screen\"\n\t\t\t>\n\t\t\t\t<ContentOnlyControlsScreen\n\t\t\t\t\trootClientId={ updatedRootClientId ?? rootClientId }\n\t\t\t\t\tcontentClientIds={ contentClientIds }\n\t\t\t\t\tparentClientIds={ nestedContentClientIds }\n\t\t\t\t/>\n\t\t\t</Navigator.Screen>\n\t\t\t{ Object.keys( nestedContentClientIds ).map( ( clientId ) => (\n\t\t\t\t<Navigator.Screen\n\t\t\t\t\tkey={ clientId }\n\t\t\t\t\tpath={ `/${ clientId }` }\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__screen\"\n\t\t\t\t>\n\t\t\t\t\t<ContentOnlyControlsScreen\n\t\t\t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ACpB;AAAA,YACA,GAAG;AAAA,UACJ;AAAA,QACD;AAEA,YAAK,CAAE,mBAAmB,SAAU,QAAS,GAAI;AAChD,4BAAkB,KAAM,QAAS;AAAA,QAClC;AAAA,MACD;AAGA,UACC,kBAAkB,WAAW,KAC7B,OAAO,KAAM,uBAAwB,EAAE,WAAW,GACjD;AACD,cAAM,qBAAqB,OAAO;AAAA,UACjC;AAAA,QACD,EAAG,CAAE;AACL,eAAO;AAAA,UACN,qBAAqB;AAAA,UACrB,kBACC,wBAAyB,kBAAmB;AAAA,UAC7C,wBAAwB,CAAC;AAAA,QAC1B;AAAA,MACD;AAEA,aAAO;AAAA,QACN,wBAAwB;AAAA,QACxB,kBAAkB;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAE,YAAa;AAAA,EAChB;AAED,SACC,qBAAC,aAAU,aAAY,KACtB;AAAA;AAAA,MAAC,UAAU;AAAA,MAAV;AAAA,QACA,MAAK;AAAA,QACL,WAAU;AAAA,QAEV;AAAA,UAAC;AAAA;AAAA,YACA,cAAe,uBAAuB;AAAA,YACtC;AAAA,YACA,iBAAkB;AAAA;AAAA,QACnB;AAAA;AAAA,IACD;AAAA,IACE,OAAO,KAAM,sBAAuB,EAAE,IAAK,CAAE,aAC9C;AAAA,MAAC,UAAU;AAAA,MAAV;AAAA,QAEA,MAAO,IAAK,QAAS;AAAA,QACrB,WAAU;AAAA,QAEV;AAAA,UAAC;AAAA;AAAA,YACA,UAAQ;AAAA,YACR,cAAe;AAAA,YACf,kBAAmB,uBAAwB,QAAS;AAAA;AAAA,QACrD;AAAA;AAAA,MARM;AAAA,IASP,CACC;AAAA,KACH;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// packages/block-editor/src/components/content-only-controls/link/index.js
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Icon,
|
|
5
|
+
__experimentalGrid as Grid,
|
|
6
|
+
Popover
|
|
7
|
+
} from "@wordpress/components";
|
|
8
|
+
import { useMemo, useState } from "@wordpress/element";
|
|
9
|
+
import { __ } from "@wordpress/i18n";
|
|
10
|
+
import { link } from "@wordpress/icons";
|
|
11
|
+
import { prependHTTP } from "@wordpress/url";
|
|
12
|
+
import LinkControl from "../../link-control";
|
|
13
|
+
import { useInspectorPopoverPlacement } from "../use-inspector-popover-placement";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var NEW_TAB_REL = "noreferrer noopener";
|
|
16
|
+
var NEW_TAB_TARGET = "_blank";
|
|
17
|
+
var NOFOLLOW_REL = "nofollow";
|
|
18
|
+
function getUpdatedLinkAttributes({
|
|
19
|
+
rel = "",
|
|
20
|
+
url = "",
|
|
21
|
+
opensInNewTab,
|
|
22
|
+
nofollow
|
|
23
|
+
}) {
|
|
24
|
+
let newLinkTarget;
|
|
25
|
+
let updatedRel = rel;
|
|
26
|
+
if (opensInNewTab) {
|
|
27
|
+
newLinkTarget = NEW_TAB_TARGET;
|
|
28
|
+
updatedRel = updatedRel?.includes(NEW_TAB_REL) ? updatedRel : updatedRel + ` ${NEW_TAB_REL}`;
|
|
29
|
+
} else {
|
|
30
|
+
const relRegex = new RegExp(`\\b${NEW_TAB_REL}\\s*`, "g");
|
|
31
|
+
updatedRel = updatedRel?.replace(relRegex, "").trim();
|
|
32
|
+
}
|
|
33
|
+
if (nofollow) {
|
|
34
|
+
updatedRel = updatedRel?.includes(NOFOLLOW_REL) ? updatedRel : (updatedRel + ` ${NOFOLLOW_REL}`).trim();
|
|
35
|
+
} else {
|
|
36
|
+
const relRegex = new RegExp(`\\b${NOFOLLOW_REL}\\s*`, "g");
|
|
37
|
+
updatedRel = updatedRel?.replace(relRegex, "").trim();
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
url: prependHTTP(url),
|
|
41
|
+
linkTarget: newLinkTarget,
|
|
42
|
+
rel: updatedRel || void 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function Link({ data, field, config = {} }) {
|
|
46
|
+
const [isLinkControlOpen, setIsLinkControlOpen] = useState(false);
|
|
47
|
+
const { popoverProps } = useInspectorPopoverPlacement({
|
|
48
|
+
isControl: true
|
|
49
|
+
});
|
|
50
|
+
const { clientId, updateBlockAttributes, fieldDef } = config;
|
|
51
|
+
const updateAttributes = (newValue) => {
|
|
52
|
+
const mappedChanges = field.setValue({ item: data, value: newValue });
|
|
53
|
+
updateBlockAttributes(clientId, mappedChanges);
|
|
54
|
+
};
|
|
55
|
+
const value = field.getValue({ item: data });
|
|
56
|
+
const url = value?.url;
|
|
57
|
+
const rel = value?.rel || "";
|
|
58
|
+
const target = value?.linkTarget;
|
|
59
|
+
const opensInNewTab = target === NEW_TAB_TARGET;
|
|
60
|
+
const nofollow = rel === NOFOLLOW_REL;
|
|
61
|
+
const linkValue = useMemo(
|
|
62
|
+
() => ({ url, opensInNewTab, nofollow }),
|
|
63
|
+
[url, opensInNewTab, nofollow]
|
|
64
|
+
);
|
|
65
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
Button,
|
|
68
|
+
{
|
|
69
|
+
__next40pxDefaultSize: true,
|
|
70
|
+
className: "block-editor-content-only-controls__link",
|
|
71
|
+
onClick: () => {
|
|
72
|
+
setIsLinkControlOpen(true);
|
|
73
|
+
},
|
|
74
|
+
children: /* @__PURE__ */ jsxs(
|
|
75
|
+
Grid,
|
|
76
|
+
{
|
|
77
|
+
rowGap: 0,
|
|
78
|
+
columnGap: 8,
|
|
79
|
+
templateColumns: "24px 1fr",
|
|
80
|
+
className: "block-editor-content-only-controls__link-row",
|
|
81
|
+
children: [
|
|
82
|
+
url && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
83
|
+
/* @__PURE__ */ jsx(Icon, { icon: link, size: 24 }),
|
|
84
|
+
/* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: url })
|
|
85
|
+
] }),
|
|
86
|
+
!url && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
+
/* @__PURE__ */ jsx(
|
|
88
|
+
Icon,
|
|
89
|
+
{
|
|
90
|
+
icon: link,
|
|
91
|
+
size: 24,
|
|
92
|
+
style: { opacity: 0.3 }
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: __("Link") })
|
|
96
|
+
] })
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
isLinkControlOpen && /* @__PURE__ */ jsx(
|
|
103
|
+
Popover,
|
|
104
|
+
{
|
|
105
|
+
onClose: () => {
|
|
106
|
+
setIsLinkControlOpen(false);
|
|
107
|
+
},
|
|
108
|
+
...popoverProps ?? {},
|
|
109
|
+
children: /* @__PURE__ */ jsx(
|
|
110
|
+
LinkControl,
|
|
111
|
+
{
|
|
112
|
+
value: linkValue,
|
|
113
|
+
onChange: (newValues) => {
|
|
114
|
+
const updatedAttrs = getUpdatedLinkAttributes({
|
|
115
|
+
rel,
|
|
116
|
+
...newValues
|
|
117
|
+
});
|
|
118
|
+
const updateValue = { ...value };
|
|
119
|
+
if (fieldDef?.mapping) {
|
|
120
|
+
Object.keys(fieldDef.mapping).forEach(
|
|
121
|
+
(key) => {
|
|
122
|
+
if (key === "href" || key === "url") {
|
|
123
|
+
updateValue[key] = updatedAttrs.url;
|
|
124
|
+
} else if (key === "rel") {
|
|
125
|
+
updateValue[key] = updatedAttrs.rel;
|
|
126
|
+
} else if (key === "target" || key === "linkTarget") {
|
|
127
|
+
updateValue[key] = updatedAttrs.linkTarget;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
updateAttributes(updateValue);
|
|
133
|
+
},
|
|
134
|
+
onRemove: () => {
|
|
135
|
+
const removeValue = {};
|
|
136
|
+
if (fieldDef?.mapping) {
|
|
137
|
+
Object.keys(fieldDef.mapping).forEach(
|
|
138
|
+
(key) => {
|
|
139
|
+
if (key === "href" || key === "url" || key === "rel" || key === "target" || key === "linkTarget") {
|
|
140
|
+
removeValue[key] = void 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
updateAttributes(removeValue);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
] });
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
NEW_TAB_REL,
|
|
155
|
+
NEW_TAB_TARGET,
|
|
156
|
+
NOFOLLOW_REL,
|
|
157
|
+
Link as default,
|
|
158
|
+
getUpdatedLinkAttributes
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/content-only-controls/link/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n\tPopover,\n} from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { link } from '@wordpress/icons';\nimport { prependHTTP } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport LinkControl from '../../link-control';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\n\nexport const NEW_TAB_REL = 'noreferrer noopener';\nexport const NEW_TAB_TARGET = '_blank';\nexport const NOFOLLOW_REL = 'nofollow';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object} attributes The current block attributes.\n * @param {string} attributes.rel The current link rel attribute.\n * @param {string} attributes.url The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t\tupdatedRel = updatedRel?.includes( NEW_TAB_REL )\n\t\t\t? updatedRel\n\t\t\t: updatedRel + ` ${ NEW_TAB_REL }`;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTP( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n\nexport default function Link( { data, field, config = {} } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst { clientId, updateBlockAttributes, fieldDef } = config;\n\tconst updateAttributes = ( newValue ) => {\n\t\tconst mappedChanges = field.setValue( { item: data, value: newValue } );\n\t\tupdateBlockAttributes( clientId, mappedChanges );\n\t};\n\n\tconst value = field.getValue( { item: data } );\n\tconst url = value?.url;\n\tconst rel = value?.rel || '';\n\tconst target = value?.linkTarget;\n\n\tconst opensInNewTab = target === NEW_TAB_TARGET;\n\tconst nofollow = rel === NOFOLLOW_REL;\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/51256.\n\tconst linkValue = useMemo(\n\t\t() => ( { url, opensInNewTab, nofollow } ),\n\t\t[ url, opensInNewTab, nofollow ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"block-editor-content-only-controls__link\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsLinkControlOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Grid\n\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__link-row\"\n\t\t\t\t>\n\t\t\t\t\t{ url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon icon={ link } size={ 24 } />\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ url }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\t\t\tsize={ 24 }\n\t\t\t\t\t\t\t\tstyle={ { opacity: 0.3 } }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ __( 'Link' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Grid>\n\t\t\t</Button>\n\t\t\t{ isLinkControlOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsLinkControlOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...( popoverProps ?? {} ) }\n\t\t\t\t>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\tvalue={ linkValue }\n\t\t\t\t\t\tonChange={ ( newValues ) => {\n\t\t\t\t\t\t\tconst updatedAttrs = getUpdatedLinkAttributes( {\n\t\t\t\t\t\t\t\trel,\n\t\t\t\t\t\t\t\t...newValues,\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\t// Build update object dynamically based on what's in the mapping\n\t\t\t\t\t\t\tconst updateValue = { ...value };\n\n\t\t\t\t\t\t\tif ( fieldDef?.mapping ) {\n\t\t\t\t\t\t\t\tObject.keys( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t\t\t( key ) => {\n\t\t\t\t\t\t\t\t\t\tif ( key === 'href' || key === 'url' ) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.url;\n\t\t\t\t\t\t\t\t\t\t} else if ( key === 'rel' ) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.rel;\n\t\t\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\t\t\tkey === 'target' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'linkTarget'\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.linkTarget;\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);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tupdateAttributes( updateValue );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t// Remove all link-related properties based on what's in the mapping\n\t\t\t\t\t\t\tconst removeValue = {};\n\n\t\t\t\t\t\t\tif ( fieldDef?.mapping ) {\n\t\t\t\t\t\t\t\tObject.keys( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t\t\t( key ) => {\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\tkey === 'href' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'url' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'rel' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'target' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'linkTarget'\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tremoveValue[ key ] = undefined;\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);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tupdateAttributes( removeValue );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,EACtB;AAAA,OACM;AACP,SAAS,SAAS,gBAAgB;AAClC,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAK5B,OAAO,iBAAiB;AACxB,SAAS,oCAAoC;AA6FvC,mBACC,KADD;AA3FC,IAAM,cAAc;AACpB,IAAM,iBAAiB;AACvB,IAAM,eAAe;AAWrB,SAAS,yBAA0B;AAAA,EACzC,MAAM;AAAA,EACN,MAAM;AAAA,EACN;AAAA,EACA;AACD,GAAI;AACH,MAAI;AAEJ,MAAI,aAAa;AAEjB,MAAK,eAAgB;AACpB,oBAAgB;AAChB,iBAAa,YAAY,SAAU,WAAY,IAC5C,aACA,aAAa,IAAK,WAAY;AAAA,EAClC,OAAO;AACN,UAAM,WAAW,IAAI,OAAQ,MAAO,WAAY,QAAQ,GAAI;AAC5D,iBAAa,YAAY,QAAS,UAAU,EAAG,EAAE,KAAK;AAAA,EACvD;AAEA,MAAK,UAAW;AACf,iBAAa,YAAY,SAAU,YAAa,IAC7C,cACE,aAAa,IAAK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