@wordpress/block-editor 15.10.1-next.v.0 → 15.11.1-next.v.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-controls/index.cjs +1 -1
- package/build/components/block-controls/index.cjs.map +2 -2
- package/build/components/block-edit/context.cjs +5 -0
- package/build/components/block-edit/context.cjs.map +2 -2
- package/build/components/block-edit/index.cjs +3 -0
- package/build/components/block-edit/index.cjs.map +2 -2
- package/build/components/block-inspector/index.cjs +7 -27
- package/build/components/block-inspector/index.cjs.map +3 -3
- package/build/components/block-list/block.cjs +3 -0
- package/build/components/block-list/block.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs +37 -13
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs.map +2 -2
- package/build/components/block-settings-menu-controls/index.cjs +1 -1
- package/build/components/block-settings-menu-controls/index.cjs.map +2 -2
- package/build/components/block-toolbar/index.cjs +1 -1
- package/build/components/block-toolbar/index.cjs.map +2 -2
- package/build/components/block-tools/index.cjs +2 -26
- package/build/components/block-tools/index.cjs.map +2 -2
- package/build/components/block-visibility/index.cjs +7 -9
- package/build/components/block-visibility/index.cjs.map +3 -3
- package/build/components/block-visibility/modal.cjs +13 -11
- package/build/components/block-visibility/modal.cjs.map +2 -2
- package/build/components/block-visibility/use-block-visibility.cjs +1 -1
- package/build/components/block-visibility/use-block-visibility.cjs.map +2 -2
- package/build/components/block-visibility/utils.cjs +5 -1
- package/build/components/block-visibility/utils.cjs.map +2 -2
- package/build/components/block-visibility/viewport-menu-item.cjs +11 -4
- package/build/components/block-visibility/viewport-menu-item.cjs.map +2 -2
- package/build/components/block-visibility/viewport-toolbar.cjs +4 -6
- package/build/components/block-visibility/viewport-toolbar.cjs.map +2 -2
- package/build/components/block-visibility/viewport-visibility-info.cjs +121 -0
- package/build/components/block-visibility/viewport-visibility-info.cjs.map +7 -0
- package/build/components/button-block-appender/index.cjs +23 -19
- package/build/components/button-block-appender/index.cjs.map +2 -2
- package/build/components/color-palette/with-color-context.cjs +1 -1
- package/build/components/color-palette/with-color-context.cjs.map +2 -2
- package/build/components/color-style-selector/index.cjs +1 -1
- package/build/components/color-style-selector/index.cjs.map +2 -2
- package/build/components/colors/with-colors.cjs +5 -3
- package/build/components/colors/with-colors.cjs.map +2 -2
- package/build/components/colors-gradients/dropdown.cjs +1 -1
- package/build/components/colors-gradients/dropdown.cjs.map +2 -2
- package/build/components/editable-text/index.cjs +5 -1
- package/build/components/editable-text/index.cjs.map +2 -2
- package/build/components/font-sizes/font-size-picker.cjs +2 -1
- package/build/components/font-sizes/font-size-picker.cjs.map +2 -2
- package/build/components/font-sizes/with-font-sizes.cjs +5 -3
- package/build/components/font-sizes/with-font-sizes.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs +26 -13
- package/build/components/global-styles/advanced-panel.cjs.map +2 -2
- package/build/components/global-styles/filters-panel.cjs +1 -1
- package/build/components/global-styles/filters-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs +1 -1
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/gradients/with-gradient.cjs +1 -1
- package/build/components/gradients/with-gradient.cjs.map +2 -2
- package/build/components/inspector-controls/fill.cjs +14 -25
- package/build/components/inspector-controls/fill.cjs.map +2 -2
- package/build/components/inspector-controls/index.cjs +1 -1
- package/build/components/inspector-controls/index.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/index.cjs +1 -1
- package/build/components/inspector-controls-tabs/index.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +7 -7
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
- package/build/components/list-view/block-select-button.cjs +8 -16
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +29 -34
- package/build/components/list-view/block.cjs.map +3 -3
- package/build/components/list-view/utils.cjs +3 -1
- package/build/components/list-view/utils.cjs.map +2 -2
- package/build/components/provider/index.cjs +7 -8
- package/build/components/provider/index.cjs.map +2 -2
- package/build/components/provider/with-registry-provider.cjs +1 -1
- package/build/components/provider/with-registry-provider.cjs.map +2 -2
- package/build/components/use-block-commands/index.cjs +2 -34
- package/build/components/use-block-commands/index.cjs.map +2 -2
- package/build/hooks/block-fields/index.cjs +52 -86
- package/build/hooks/block-fields/index.cjs.map +3 -3
- package/build/hooks/block-fields/link/index.cjs +2 -11
- package/build/hooks/block-fields/link/index.cjs.map +2 -2
- package/build/hooks/block-fields/media/index.cjs +9 -14
- package/build/hooks/block-fields/media/index.cjs.map +2 -2
- package/build/hooks/cross-origin-isolation.cjs +1 -1
- package/build/hooks/cross-origin-isolation.cjs.map +2 -2
- package/build/hooks/custom-css.cjs +141 -0
- package/build/hooks/custom-css.cjs.map +7 -0
- package/build/hooks/fit-text.cjs +14 -7
- package/build/hooks/fit-text.cjs.map +2 -2
- package/build/hooks/grid-visualizer.cjs +1 -1
- package/build/hooks/grid-visualizer.cjs.map +2 -2
- package/build/hooks/index.cjs +6 -1
- package/build/hooks/index.cjs.map +3 -3
- package/build/hooks/layout.cjs +10 -4
- package/build/hooks/layout.cjs.map +2 -2
- package/build/hooks/list-view.cjs +32 -11
- package/build/hooks/list-view.cjs.map +3 -3
- package/build/hooks/utils.cjs +5 -4
- package/build/hooks/utils.cjs.map +2 -2
- package/build/layouts/grid.cjs +12 -1
- package/build/layouts/grid.cjs.map +2 -2
- package/build/store/defaults.cjs +3 -0
- package/build/store/defaults.cjs.map +2 -2
- package/build/store/private-selectors.cjs +45 -37
- package/build/store/private-selectors.cjs.map +2 -2
- package/build/store/selectors.cjs +7 -1
- package/build/store/selectors.cjs.map +2 -2
- package/build/utils/fit-text-utils.cjs +5 -1
- package/build/utils/fit-text-utils.cjs.map +2 -2
- package/build-module/components/block-controls/index.mjs +1 -1
- package/build-module/components/block-controls/index.mjs.map +2 -2
- package/build-module/components/block-edit/context.mjs +4 -0
- package/build-module/components/block-edit/context.mjs.map +2 -2
- package/build-module/components/block-edit/index.mjs +4 -0
- package/build-module/components/block-edit/index.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +7 -27
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-list/block.mjs +3 -0
- package/build-module/components/block-list/block.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs +37 -13
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map +2 -2
- package/build-module/components/block-settings-menu-controls/index.mjs +2 -2
- package/build-module/components/block-settings-menu-controls/index.mjs.map +2 -2
- package/build-module/components/block-toolbar/index.mjs +2 -2
- package/build-module/components/block-toolbar/index.mjs.map +2 -2
- package/build-module/components/block-tools/index.mjs +2 -26
- package/build-module/components/block-tools/index.mjs.map +2 -2
- package/build-module/components/block-visibility/index.mjs +6 -9
- package/build-module/components/block-visibility/index.mjs.map +2 -2
- package/build-module/components/block-visibility/modal.mjs +13 -11
- package/build-module/components/block-visibility/modal.mjs.map +2 -2
- package/build-module/components/block-visibility/use-block-visibility.mjs +1 -1
- package/build-module/components/block-visibility/use-block-visibility.mjs.map +2 -2
- package/build-module/components/block-visibility/utils.mjs +5 -1
- package/build-module/components/block-visibility/utils.mjs.map +2 -2
- package/build-module/components/block-visibility/viewport-menu-item.mjs +11 -4
- package/build-module/components/block-visibility/viewport-menu-item.mjs.map +2 -2
- package/build-module/components/block-visibility/viewport-toolbar.mjs +4 -6
- package/build-module/components/block-visibility/viewport-toolbar.mjs.map +2 -2
- package/build-module/components/block-visibility/viewport-visibility-info.mjs +95 -0
- package/build-module/components/block-visibility/viewport-visibility-info.mjs.map +7 -0
- package/build-module/components/button-block-appender/index.mjs +23 -19
- package/build-module/components/button-block-appender/index.mjs.map +2 -2
- package/build-module/components/color-palette/with-color-context.mjs +1 -1
- package/build-module/components/color-palette/with-color-context.mjs.map +2 -2
- package/build-module/components/color-style-selector/index.mjs +1 -1
- package/build-module/components/color-style-selector/index.mjs.map +2 -2
- package/build-module/components/colors/with-colors.mjs +5 -3
- package/build-module/components/colors/with-colors.mjs.map +2 -2
- package/build-module/components/colors-gradients/dropdown.mjs +1 -1
- package/build-module/components/colors-gradients/dropdown.mjs.map +2 -2
- package/build-module/components/editable-text/index.mjs +5 -1
- package/build-module/components/editable-text/index.mjs.map +2 -2
- package/build-module/components/font-sizes/font-size-picker.mjs +2 -1
- package/build-module/components/font-sizes/font-size-picker.mjs.map +2 -2
- package/build-module/components/font-sizes/with-font-sizes.mjs +5 -3
- package/build-module/components/font-sizes/with-font-sizes.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +22 -13
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/filters-panel.mjs +1 -1
- package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs +1 -1
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/gradients/with-gradient.mjs +1 -1
- package/build-module/components/gradients/with-gradient.mjs.map +2 -2
- package/build-module/components/inspector-controls/fill.mjs +16 -22
- package/build-module/components/inspector-controls/fill.mjs.map +2 -2
- package/build-module/components/inspector-controls/index.mjs +1 -1
- package/build-module/components/inspector-controls/index.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +7 -7
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
- package/build-module/components/list-view/block-select-button.mjs +8 -16
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +31 -36
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/list-view/utils.mjs +3 -1
- package/build-module/components/list-view/utils.mjs.map +2 -2
- package/build-module/components/provider/index.mjs +7 -8
- package/build-module/components/provider/index.mjs.map +2 -2
- package/build-module/components/provider/with-registry-provider.mjs +1 -1
- package/build-module/components/provider/with-registry-provider.mjs.map +2 -2
- package/build-module/components/use-block-commands/index.mjs +3 -37
- package/build-module/components/use-block-commands/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/index.mjs +45 -87
- package/build-module/hooks/block-fields/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/link/index.mjs +2 -11
- package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/media/index.mjs +9 -14
- package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
- package/build-module/hooks/cross-origin-isolation.mjs +1 -1
- package/build-module/hooks/cross-origin-isolation.mjs.map +2 -2
- package/build-module/hooks/custom-css.mjs +112 -0
- package/build-module/hooks/custom-css.mjs.map +7 -0
- package/build-module/hooks/fit-text.mjs +14 -7
- package/build-module/hooks/fit-text.mjs.map +2 -2
- package/build-module/hooks/grid-visualizer.mjs +1 -1
- package/build-module/hooks/grid-visualizer.mjs.map +2 -2
- package/build-module/hooks/index.mjs +6 -1
- package/build-module/hooks/index.mjs.map +2 -2
- package/build-module/hooks/layout.mjs +10 -4
- package/build-module/hooks/layout.mjs.map +2 -2
- package/build-module/hooks/list-view.mjs +33 -12
- package/build-module/hooks/list-view.mjs.map +2 -2
- package/build-module/hooks/utils.mjs +7 -5
- package/build-module/hooks/utils.mjs.map +2 -2
- package/build-module/layouts/grid.mjs +12 -1
- package/build-module/layouts/grid.mjs.map +2 -2
- package/build-module/store/defaults.mjs +3 -0
- package/build-module/store/defaults.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +42 -40
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/selectors.mjs +7 -1
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/utils/fit-text-utils.mjs +5 -1
- package/build-module/utils/fit-text-utils.mjs.map +2 -2
- package/build-style/style-rtl.css +3 -0
- package/build-style/style.css +3 -0
- package/package.json +39 -39
- package/src/components/block-controls/index.js +1 -1
- package/src/components/block-controls/test/index.js +1 -0
- package/src/components/block-edit/context.js +3 -0
- package/src/components/block-edit/index.js +6 -0
- package/src/components/block-edit/test/edit.js +10 -0
- package/src/components/block-inspector/index.js +16 -38
- package/src/components/block-list/block.js +3 -0
- package/src/components/block-list/block.native.js +5 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +49 -29
- package/src/components/block-patterns-list/stories/index.story.jsx +1 -1
- package/src/components/block-preview/test/index.js +11 -7
- package/src/components/block-settings-menu-controls/index.js +2 -2
- package/src/components/block-switcher/test/index.js +2 -0
- package/src/components/block-switcher/test/use-transformed.patterns.js +2 -0
- package/src/components/block-switcher/test/utils.js +2 -0
- package/src/components/block-toolbar/index.js +2 -2
- package/src/components/block-tools/index.js +2 -29
- package/src/components/block-visibility/index.js +3 -19
- package/src/components/block-visibility/modal.js +16 -14
- package/src/components/block-visibility/test/use-block-visibility.js +27 -25
- package/src/components/block-visibility/test/utils.js +24 -8
- package/src/components/block-visibility/use-block-visibility.js +1 -4
- package/src/components/block-visibility/utils.js +9 -1
- package/src/components/block-visibility/viewport-menu-item.js +11 -5
- package/src/components/block-visibility/viewport-toolbar.js +5 -6
- package/src/components/block-visibility/viewport-visibility-info.js +131 -0
- package/src/components/button-block-appender/index.js +2 -2
- package/src/components/color-palette/with-color-context.js +1 -1
- package/src/components/color-style-selector/index.js +2 -3
- package/src/components/colors/with-colors.js +23 -20
- package/src/components/colors-gradients/dropdown.js +2 -3
- package/src/components/editable-text/index.js +5 -1
- package/src/components/font-sizes/font-size-picker.js +1 -0
- package/src/components/font-sizes/with-font-sizes.js +13 -10
- package/src/components/global-styles/advanced-panel.js +35 -16
- package/src/components/global-styles/filters-panel.js +2 -3
- package/src/components/global-styles/shadow-panel-components.js +1 -1
- package/src/components/global-styles/style.scss +9 -5
- package/src/components/gradients/with-gradient.js +7 -4
- package/src/components/inner-blocks/test/index.js +2 -0
- package/src/components/inspector-controls/fill.js +30 -20
- package/src/components/inspector-controls/index.js +1 -1
- package/src/components/inspector-controls-tabs/index.js +5 -1
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +13 -11
- package/src/components/link-control/test/index.js +6 -1
- package/src/components/list-view/block-select-button.js +16 -25
- package/src/components/list-view/block.js +38 -43
- package/src/components/list-view/utils.js +4 -2
- package/src/components/media-replace-flow/test/index.js +13 -11
- package/src/components/provider/index.js +11 -10
- package/src/components/provider/test/use-block-sync.js +1 -0
- package/src/components/provider/with-registry-provider.js +1 -1
- package/src/components/use-block-commands/index.js +0 -41
- package/src/hooks/block-fields/index.js +66 -111
- package/src/hooks/block-fields/link/index.js +2 -14
- package/src/hooks/block-fields/media/index.js +9 -21
- package/src/hooks/cross-origin-isolation.js +19 -18
- package/src/hooks/custom-css.js +176 -0
- package/src/hooks/fit-text.js +20 -5
- package/src/hooks/grid-visualizer.js +15 -14
- package/src/hooks/index.js +6 -1
- package/src/hooks/layout.js +55 -43
- package/src/hooks/list-view.js +46 -12
- package/src/hooks/test/align.js +1 -0
- package/src/hooks/test/allowed-blocks.js +8 -0
- package/src/hooks/test/auto-inspector-controls.js +4 -0
- package/src/hooks/test/font-size.js +1 -0
- package/src/hooks/test/metadata.js +4 -0
- package/src/hooks/test/text-align.js +1 -0
- package/src/hooks/utils.js +124 -116
- package/src/layouts/grid.js +19 -3
- package/src/layouts/test/grid.js +1 -1
- package/src/store/defaults.js +4 -0
- package/src/store/private-selectors.js +94 -63
- package/src/store/selectors.js +14 -6
- package/src/store/test/actions.js +7 -0
- package/src/store/test/private-selectors.js +116 -119
- package/src/store/test/reducer.js +4 -0
- package/src/store/test/registry-selectors.js +2 -0
- package/src/store/test/selectors.js +19 -0
- package/src/utils/fit-text-utils.js +12 -2
- package/build/components/block-visibility/block-visibility-info.cjs +0 -63
- package/build/components/block-visibility/block-visibility-info.cjs.map +0 -7
- package/build/components/block-visibility/menu-item.cjs +0 -109
- package/build/components/block-visibility/menu-item.cjs.map +0 -7
- package/build/components/block-visibility/toolbar.cjs +0 -92
- package/build/components/block-visibility/toolbar.cjs.map +0 -7
- package/build-module/components/block-visibility/block-visibility-info.mjs +0 -47
- package/build-module/components/block-visibility/block-visibility-info.mjs.map +0 -7
- package/build-module/components/block-visibility/menu-item.mjs +0 -88
- package/build-module/components/block-visibility/menu-item.mjs.map +0 -7
- package/build-module/components/block-visibility/toolbar.mjs +0 -71
- package/build-module/components/block-visibility/toolbar.mjs.map +0 -7
- package/src/components/block-visibility/block-visibility-info.js +0 -62
- package/src/components/block-visibility/menu-item.js +0 -96
- package/src/components/block-visibility/toolbar.js +0 -88
- /package/src/components/block-icon/stories/{index.story.js → index.story.ts} +0 -0
- /package/src/components/contrast-checker/stories/{index.story.js → index.story.ts} +0 -0
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
// packages/block-editor/src/hooks/block-fields/index.js
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
privateApis as blocksPrivateApis,
|
|
4
|
+
getBlockType
|
|
5
|
+
} from "@wordpress/blocks";
|
|
4
6
|
import {
|
|
5
7
|
__experimentalHStack as HStack,
|
|
6
8
|
__experimentalTruncate as Truncate
|
|
7
9
|
} from "@wordpress/components";
|
|
8
|
-
import {
|
|
10
|
+
import { useSelect } from "@wordpress/data";
|
|
9
11
|
import { DataForm } from "@wordpress/dataviews";
|
|
10
12
|
import { useContext, useState, useMemo } from "@wordpress/element";
|
|
11
13
|
import { __ } from "@wordpress/i18n";
|
|
14
|
+
import { store as blockEditorStore } from "../../store/index.mjs";
|
|
12
15
|
import { unlock } from "../../lock-unlock.mjs";
|
|
13
16
|
import BlockIcon from "../../components/block-icon/index.mjs";
|
|
14
17
|
import useBlockDisplayTitle from "../../components/block-title/use-block-display-title.mjs";
|
|
15
18
|
import useBlockDisplayInformation from "../../components/use-block-display-information/index.mjs";
|
|
16
19
|
import FieldsDropdownMenu from "./fields-dropdown-menu.mjs";
|
|
17
20
|
import { PrivateBlockContext } from "../../components/block-list/private-block-context.mjs";
|
|
18
|
-
import
|
|
21
|
+
import InspectorControls from "../../components/inspector-controls/fill.mjs";
|
|
19
22
|
import RichText from "./rich-text/index.mjs";
|
|
20
23
|
import Media from "./media/index.mjs";
|
|
21
24
|
import Link from "./link/index.mjs";
|
|
22
25
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
23
26
|
var { fieldsKey, formKey } = unlock(blocksPrivateApis);
|
|
24
|
-
|
|
25
|
-
richtext: RichText,
|
|
26
|
-
media: Media,
|
|
27
|
-
link: Link
|
|
28
|
-
};
|
|
29
|
-
function createConfiguredControl(ControlComponent, type, config) {
|
|
30
|
-
if (!ControlComponent) {
|
|
31
|
-
throw new Error(`Control type "${type}" not found`);
|
|
32
|
-
}
|
|
27
|
+
function createConfiguredControl(ControlComponent, config = {}) {
|
|
33
28
|
return function ConfiguredControl(props) {
|
|
34
29
|
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config });
|
|
35
30
|
};
|
|
@@ -37,7 +32,6 @@ function createConfiguredControl(ControlComponent, type, config) {
|
|
|
37
32
|
function BlockFields({
|
|
38
33
|
clientId,
|
|
39
34
|
blockType,
|
|
40
|
-
attributes,
|
|
41
35
|
setAttributes,
|
|
42
36
|
isCollapsed = false
|
|
43
37
|
}) {
|
|
@@ -47,6 +41,10 @@ function BlockFields({
|
|
|
47
41
|
});
|
|
48
42
|
const blockInformation = useBlockDisplayInformation(clientId);
|
|
49
43
|
const blockTypeFields = blockType?.[fieldsKey];
|
|
44
|
+
const attributes = useSelect(
|
|
45
|
+
(select) => select(blockEditorStore).getBlockAttributes(clientId),
|
|
46
|
+
[clientId]
|
|
47
|
+
);
|
|
50
48
|
const computedForm = useMemo(() => {
|
|
51
49
|
if (!isCollapsed) {
|
|
52
50
|
return blockType?.[formKey];
|
|
@@ -63,41 +61,18 @@ function BlockFields({
|
|
|
63
61
|
}
|
|
64
62
|
return blockTypeFields.map((fieldDef) => {
|
|
65
63
|
const field = {
|
|
66
|
-
|
|
67
|
-
label: fieldDef.label,
|
|
68
|
-
type: fieldDef.type
|
|
69
|
-
// Use the field's type; DataForm will use built-in or custom Edit
|
|
64
|
+
...fieldDef
|
|
70
65
|
};
|
|
71
|
-
if (fieldDef.
|
|
72
|
-
field.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
field.setValue = ({ value }) => {
|
|
82
|
-
const attributeUpdates = {};
|
|
83
|
-
Object.entries(fieldDef.mapping).forEach(
|
|
84
|
-
([key, attrKey]) => {
|
|
85
|
-
attributeUpdates[attrKey] = value[key];
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
return attributeUpdates;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const ControlComponent = CONTROLS[fieldDef.type];
|
|
92
|
-
if (ControlComponent) {
|
|
93
|
-
field.Edit = createConfiguredControl(
|
|
94
|
-
ControlComponent,
|
|
95
|
-
fieldDef.type,
|
|
96
|
-
{
|
|
97
|
-
clientId,
|
|
98
|
-
fieldDef
|
|
99
|
-
}
|
|
100
|
-
);
|
|
66
|
+
if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "rich-text") {
|
|
67
|
+
field.Edit = createConfiguredControl(RichText, {
|
|
68
|
+
clientId
|
|
69
|
+
});
|
|
70
|
+
} else if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "link") {
|
|
71
|
+
field.Edit = createConfiguredControl(Link);
|
|
72
|
+
} else if ("object" === typeof fieldDef.Edit && fieldDef.Edit.control === "media") {
|
|
73
|
+
field.Edit = createConfiguredControl(Media, {
|
|
74
|
+
...fieldDef.Edit
|
|
75
|
+
});
|
|
101
76
|
}
|
|
102
77
|
return field;
|
|
103
78
|
});
|
|
@@ -152,45 +127,28 @@ function BlockFields({
|
|
|
152
127
|
)
|
|
153
128
|
] });
|
|
154
129
|
}
|
|
155
|
-
|
|
156
|
-
(
|
|
157
|
-
|
|
130
|
+
function hasBlockFieldsSupport(blockName) {
|
|
131
|
+
return !!(window?.__experimentalContentOnlyInspectorFields && getBlockType(blockName)?.[fieldsKey]);
|
|
132
|
+
}
|
|
133
|
+
function BlockFieldsPanel(props) {
|
|
134
|
+
const { blockType, isSelectionWithinCurrentSection } = useContext(PrivateBlockContext);
|
|
135
|
+
return /* @__PURE__ */ jsx(InspectorControls, { group: "content", children: /* @__PURE__ */ jsx(
|
|
136
|
+
BlockFields,
|
|
137
|
+
{
|
|
138
|
+
...props,
|
|
158
139
|
blockType,
|
|
159
|
-
isSelectionWithinCurrentSection
|
|
160
|
-
isSectionBlock,
|
|
161
|
-
blockEditingMode,
|
|
162
|
-
isSelected
|
|
163
|
-
} = useContext(PrivateBlockContext);
|
|
164
|
-
const shouldShowBlockFields = window?.__experimentalContentOnlyInspectorFields;
|
|
165
|
-
const blockTypeFields = blockType?.[fieldsKey];
|
|
166
|
-
if (!shouldShowBlockFields || !blockTypeFields?.length) {
|
|
167
|
-
return /* @__PURE__ */ jsx(BlockEdit, { ...props }, "edit");
|
|
140
|
+
isCollapsed: isSelectionWithinCurrentSection
|
|
168
141
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
blockType,
|
|
182
|
-
isCollapsed: true
|
|
183
|
-
}
|
|
184
|
-
)
|
|
185
|
-
}
|
|
186
|
-
),
|
|
187
|
-
!isSelectionWithinCurrentSection && isSelected && /* @__PURE__ */ jsx(PrivateInspectorControlsFill, { group: "content", children: /* @__PURE__ */ jsx(BlockFields, { ...props, blockType }) })
|
|
188
|
-
] });
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
addFilter(
|
|
192
|
-
"editor.BlockEdit",
|
|
193
|
-
"core/content-only-controls/block-fields",
|
|
194
|
-
withBlockFields
|
|
195
|
-
);
|
|
142
|
+
) });
|
|
143
|
+
}
|
|
144
|
+
var block_fields_default = {
|
|
145
|
+
edit: BlockFieldsPanel,
|
|
146
|
+
hasSupport: hasBlockFieldsSupport,
|
|
147
|
+
attributeKeys: [],
|
|
148
|
+
supportsPatternEditing: true
|
|
149
|
+
};
|
|
150
|
+
export {
|
|
151
|
+
BlockFieldsPanel,
|
|
152
|
+
block_fields_default as default
|
|
153
|
+
};
|
|
196
154
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/block-fields/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blocksPrivateApis,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport InspectorControls from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Component} ControlComponent The React component for the control.\n * @param {Object} config The control configuration passed as a prop.\n *\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( ControlComponent, config = {} ) {\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ config } />;\n\t};\n}\n\n/**\n * Component that renders a DataForm for a single block's attributes\n * @param {Object} props\n * @param {string} props.clientId The clientId of the block.\n * @param {Object} props.blockType The blockType definition.\n * @param {Function} props.setAttributes Action to set the block's attributes.\n * @param {boolean} props.isCollapsed Whether the DataForm is rendered as 'collapsed' with only the first field\n * displayed by default. When collapsed a dropdown is displayed to allow\n * displaying additional fields. The block's title is displayed as the title.\n * The collapsed mode is often used when multiple BlockForms are shown together.\n */\nfunction BlockFields( {\n\tclientId,\n\tblockType,\n\tsetAttributes,\n\tisCollapsed = false,\n} ) {\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 attributes = useSelect(\n\t\t( select ) => select( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t[ clientId ]\n\t);\n\n\tconst computedForm = useMemo( () => {\n\t\tif ( ! isCollapsed ) {\n\t\t\treturn blockType?.[ formKey ];\n\t\t}\n\n\t\t// For a collapsed form only show the first field by default.\n\t\treturn {\n\t\t\t...blockType?.[ formKey ],\n\t\t\tfields: [ blockType?.[ formKey ]?.fields?.[ 0 ] ],\n\t\t};\n\t}, [ blockType, isCollapsed ] );\n\n\tconst [ form, setForm ] = useState( computedForm );\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 field = {\n\t\t\t\t...fieldDef,\n\t\t\t};\n\n\t\t\t// These should be custom Edit components, not replaced here.\n\t\t\t//\n\t\t\t// - rich-text control: it needs clientId\n\t\t\t// - link control: does not need anything extra\n\t\t\t// - media control: needs the Edit config\n\t\t\tif (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'rich-text'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( RichText, {\n\t\t\t\t\tclientId,\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'link'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Link );\n\t\t\t} else if (\n\t\t\t\t'object' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit.control === 'media'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Media, {\n\t\t\t\t\t...fieldDef.Edit,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, clientId ] );\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\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\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t{ isCollapsed && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\t\t\tonToggleField={ handleToggleField }\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\t{ ! isCollapsed && (\n\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t{ __( 'Content' ) }\n\t\t\t\t\t\t</h2>\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={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction hasBlockFieldsSupport( blockName ) {\n\treturn !! (\n\t\twindow?.__experimentalContentOnlyInspectorFields &&\n\t\tgetBlockType( blockName )?.[ fieldsKey ]\n\t);\n}\n\nexport function BlockFieldsPanel( props ) {\n\tconst { blockType, isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\treturn (\n\t\t<InspectorControls group=\"content\">\n\t\t\t<BlockFields\n\t\t\t\t{ ...props }\n\t\t\t\tblockType={ blockType }\n\t\t\t\tisCollapsed={ isSelectionWithinCurrentSection }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Export block support definition.\n */\nexport default {\n\tedit: BlockFieldsPanel,\n\thasSupport: hasBlockFieldsSupport,\n\tattributeKeys: [],\n\tsupportsPatternEditing: true,\n};\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC,eA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;AAAA,QAC1B;AAAA,QACA,oBAAC,QAAG,WAAU,2CACb,8BAAC,YAAS,eAAgB,GACvB,sBACH,GACD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,QAAS;AAAA,YACT,eAAgB,KAAK;AAAA,YACrB,eAAgB;AAAA;AAAA,QACjB;AAAA,SACD;AAAA,MAEC,CAAE,eACH,oBAAC,QAAG,WAAU,2CACX,aAAI,SAAU,GACjB;AAAA,OAEF,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,QAAS;AAAA,QACT;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,KACD;AAEF;AAEA,SAAS,sBAAuB,WAAY;AAC3C,SAAO,CAAC,EACP,QAAQ,4CACR,aAAc,SAAU,IAAK,SAAU;AAEzC;AAEO,SAAS,iBAAkB,OAAQ;AACzC,QAAM,EAAE,WAAW,gCAAgC,IAClD,WAAY,mBAAoB;AAEjC,SACC,oBAAC,qBAAkB,OAAM,WACxB;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL;AAAA,MACA,aAAc;AAAA;AAAA,EACf,GACD;AAEF;AAKA,IAAO,uBAAQ;AAAA,EACd,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe,CAAC;AAAA,EAChB,wBAAwB;AACzB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -42,12 +42,11 @@ function getUpdatedLinkAttributes({
|
|
|
42
42
|
rel: updatedRel || void 0
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function Link({ data, field, onChange
|
|
45
|
+
function Link({ data, field, onChange }) {
|
|
46
46
|
const [isLinkControlOpen, setIsLinkControlOpen] = useState(false);
|
|
47
47
|
const { popoverProps } = useInspectorPopoverPlacement({
|
|
48
48
|
isControl: true
|
|
49
49
|
});
|
|
50
|
-
const { fieldDef } = config;
|
|
51
50
|
const value = field.getValue({ item: data });
|
|
52
51
|
const url = value?.url;
|
|
53
52
|
const rel = value?.rel || "";
|
|
@@ -119,18 +118,10 @@ function Link({ data, field, onChange, config = {} }) {
|
|
|
119
118
|
);
|
|
120
119
|
},
|
|
121
120
|
onRemove: () => {
|
|
122
|
-
const removeValue = {};
|
|
123
|
-
if (fieldDef?.mapping) {
|
|
124
|
-
Object.keys(fieldDef.mapping).forEach(
|
|
125
|
-
(key) => {
|
|
126
|
-
removeValue[key] = void 0;
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
121
|
onChange(
|
|
131
122
|
field.setValue({
|
|
132
123
|
item: data,
|
|
133
|
-
value:
|
|
124
|
+
value: {}
|
|
134
125
|
})
|
|
135
126
|
);
|
|
136
127
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/hooks/block-fields/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 '../../../components/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, onChange
|
|
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;
|
|
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 '../../../components/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, onChange } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\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\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: updatedAttrs,\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\tonRemove={ () => {\n\t\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: {},\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\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;AAuFvC,mBACC,KADD;AArFC,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;AA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MAAO,IAAK;AAAA,gBAChC,oBAAC,UAAK,WAAU,kDACb,eACH;AAAA,iBACD;AAAA,cAEC,CAAE,OACH,iCACC;AAAA;AAAA,kBAAC;AAAA;AAAA,oBACA,MAAO;AAAA,oBACP,MAAO;AAAA,oBACP,OAAQ,EAAE,SAAS,IAAI;AAAA;AAAA,gBACxB;AAAA,gBACA,oBAAC,UAAK,WAAU,kDACb,aAAI,MAAO,GACd;AAAA,iBACD;AAAA;AAAA;AAAA,QAEF;AAAA;AAAA,IACD;AAAA,IACE,qBACD;AAAA,MAAC;AAAA;AAAA,QACA,SAAU,MAAM;AACf,+BAAsB,KAAM;AAAA,QAC7B;AAAA,QACE,GAAK,gBAAgB,CAAC;AAAA,QAExB;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ;AAAA,YACR,UAAW,CAAE,cAAe;AAC3B,oBAAM,eAAe,yBAA0B;AAAA,gBAC9C;AAAA,gBACA,GAAG;AAAA,cACJ,CAAE;AAEF;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,YACD;AAAA,YACA,UAAW,MAAM;AAChB;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO,CAAC;AAAA,gBACT,CAAE;AAAA,cACH;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,8 +19,7 @@ import { getMediaSelectKey } from "../../../store/private-keys.mjs";
|
|
|
19
19
|
import { store as blockEditorStore } from "../../../store/index.mjs";
|
|
20
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
21
|
function MediaThumbnail({ data, field, attachment, config }) {
|
|
22
|
-
const {
|
|
23
|
-
const { allowedTypes = [], multiple = false } = fieldDef.args || {};
|
|
22
|
+
const { allowedTypes = [], multiple = false } = config || {};
|
|
24
23
|
if (multiple) {
|
|
25
24
|
return "todo multiple";
|
|
26
25
|
}
|
|
@@ -62,9 +61,11 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
62
61
|
isControl: true
|
|
63
62
|
});
|
|
64
63
|
const value = field.getValue({ item: data });
|
|
65
|
-
const {
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
const {
|
|
65
|
+
allowedTypes = [],
|
|
66
|
+
multiple = false,
|
|
67
|
+
useFeaturedImage = false
|
|
68
|
+
} = config;
|
|
68
69
|
const id = value?.id;
|
|
69
70
|
const url = value?.url;
|
|
70
71
|
const attachment = useSelect(
|
|
@@ -106,20 +107,14 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
106
107
|
multiple,
|
|
107
108
|
popoverProps,
|
|
108
109
|
onReset: () => {
|
|
109
|
-
const resetValue = {};
|
|
110
|
-
if (fieldDef?.mapping) {
|
|
111
|
-
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
112
|
-
resetValue[key] = void 0;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
110
|
onChange(
|
|
116
111
|
field.setValue({
|
|
117
112
|
item: data,
|
|
118
|
-
value:
|
|
113
|
+
value: {}
|
|
119
114
|
})
|
|
120
115
|
);
|
|
121
116
|
},
|
|
122
|
-
...
|
|
117
|
+
...useFeaturedImage && {
|
|
123
118
|
useFeaturedImage: !!value?.featuredImage,
|
|
124
119
|
onToggleFeaturedImage: () => {
|
|
125
120
|
onChange(
|
|
@@ -138,7 +133,7 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
138
133
|
...selectedMedia,
|
|
139
134
|
mediaType: selectedMedia.media_type
|
|
140
135
|
};
|
|
141
|
-
if (
|
|
136
|
+
if (useFeaturedImage) {
|
|
142
137
|
newValue.featuredImage = false;
|
|
143
138
|
}
|
|
144
139
|
onChange(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/hooks/block-fields/media/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taudio as audioIcon,\n\timage as imageIcon,\n\tmedia as mediaIcon,\n\tvideo as videoIcon,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport MediaReplaceFlow from '../../../components/media-replace-flow';\nimport MediaUploadCheck from '../../../components/media-upload/check';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\nimport { getMediaSelectKey } from '../../../store/private-keys';\nimport { store as blockEditorStore } from '../../../store';\n\nfunction MediaThumbnail( { data, field, attachment, config } ) {\n\tconst {
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,OAChB;AACP,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB;AAAA,EACC,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,OACH;AAKP,OAAO,sBAAsB;AAC7B,OAAO,sBAAsB;AAC7B,SAAS,oCAAoC;AAC7C,SAAS,yBAAyB;AAClC,SAAS,SAAS,wBAAwB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taudio as audioIcon,\n\timage as imageIcon,\n\tmedia as mediaIcon,\n\tvideo as videoIcon,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport MediaReplaceFlow from '../../../components/media-replace-flow';\nimport MediaUploadCheck from '../../../components/media-upload/check';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\nimport { getMediaSelectKey } from '../../../store/private-keys';\nimport { store as blockEditorStore } from '../../../store';\n\nfunction MediaThumbnail( { data, field, attachment, config } ) {\n\tconst { allowedTypes = [], multiple = false } = config || {};\n\n\tif ( multiple ) {\n\t\treturn 'todo multiple';\n\t}\n\n\tif ( attachment?.media_type === 'image' || attachment?.poster ) {\n\t\treturn (\n\t\t\t<div className=\"block-editor-content-only-controls__media-thumbnail\">\n\t\t\t\t<img\n\t\t\t\t\talt=\"\"\n\t\t\t\t\twidth={ 24 }\n\t\t\t\t\theight={ 24 }\n\t\t\t\t\tsrc={\n\t\t\t\t\t\tattachment.media_type === 'image'\n\t\t\t\t\t\t\t? attachment.source_url\n\t\t\t\t\t\t\t: attachment.poster\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( allowedTypes.length === 1 ) {\n\t\tconst value = field.getValue( { item: data } );\n\t\tconst url = value?.url;\n\n\t\tif ( allowedTypes[ 0 ] === 'image' && url ) {\n\t\t\treturn (\n\t\t\t\t<div className=\"block-editor-content-only-controls__media-thumbnail\">\n\t\t\t\t\t<img alt=\"\" width={ 24 } height={ 24 } src={ url } />\n\t\t\t\t</div>\n\t\t\t);\n\t\t}\n\n\t\tlet icon;\n\t\tif ( allowedTypes[ 0 ] === 'image' ) {\n\t\t\ticon = imageIcon;\n\t\t} else if ( allowedTypes[ 0 ] === 'video' ) {\n\t\t\ticon = videoIcon;\n\t\t} else if ( allowedTypes[ 0 ] === 'audio' ) {\n\t\t\ticon = audioIcon;\n\t\t} else {\n\t\t\ticon = mediaIcon;\n\t\t}\n\n\t\tif ( icon ) {\n\t\t\treturn <Icon icon={ icon } size={ 24 } />;\n\t\t}\n\t}\n\n\treturn <Icon icon={ mediaIcon } size={ 24 } />;\n}\n\nexport default function Media( { data, field, onChange, config = {} } ) {\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst value = field.getValue( { item: data } );\n\tconst {\n\t\tallowedTypes = [],\n\t\tmultiple = false,\n\t\tuseFeaturedImage = false,\n\t} = config;\n\n\tconst id = value?.id;\n\tconst url = value?.url;\n\n\tconst attachment = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\t\tconst getMedia = settings[ getMediaSelectKey ];\n\n\t\t\tif ( ! getMedia ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn getMedia( select, id );\n\t\t},\n\t\t[ id ]\n\t);\n\n\t// TODO - pluralize when multiple.\n\tlet chooseItemLabel;\n\tif ( allowedTypes.length === 1 ) {\n\t\tconst allowedType = allowedTypes[ 0 ];\n\t\tif ( allowedType === 'image' ) {\n\t\t\tchooseItemLabel = __( 'Choose an image\u2026' );\n\t\t} else if ( allowedType === 'video' ) {\n\t\t\tchooseItemLabel = __( 'Choose a video\u2026' );\n\t\t} else if ( allowedType === 'application' ) {\n\t\t\tchooseItemLabel = __( 'Choose a file\u2026' );\n\t\t} else {\n\t\t\tchooseItemLabel = __( 'Choose a media item\u2026' );\n\t\t}\n\t} else {\n\t\tchooseItemLabel = __( 'Choose a media item\u2026' );\n\t}\n\n\treturn (\n\t\t<MediaUploadCheck>\n\t\t\t<MediaReplaceFlow\n\t\t\t\tclassName=\"block-editor-content-only-controls__media-replace-flow\"\n\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\tmediaId={ id }\n\t\t\t\tmediaURL={ url }\n\t\t\t\tmultiple={ multiple }\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tonReset={ () => {\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\tvalue: {},\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t\t{ ...( useFeaturedImage && {\n\t\t\t\t\tuseFeaturedImage: !! value?.featuredImage,\n\t\t\t\t\tonToggleFeaturedImage: () => {\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\tfeaturedImage: ! value?.featuredImage,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t} ) }\n\t\t\t\tonSelect={ ( selectedMedia ) => {\n\t\t\t\t\tif ( selectedMedia.id && selectedMedia.url ) {\n\t\t\t\t\t\tconst newValue = {\n\t\t\t\t\t\t\t...selectedMedia,\n\t\t\t\t\t\t\tmediaType: selectedMedia.media_type,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Turn off featured image when manually selecting media\n\t\t\t\t\t\tif ( useFeaturedImage ) {\n\t\t\t\t\t\t\tnewValue.featuredImage = false;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\tvalue: newValue,\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} }\n\t\t\t\trenderToggle={ ( buttonProps ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-content-only-controls__media\"\n\t\t\t\t\t\t{ ...buttonProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Grid\n\t\t\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\t\t\tclassName=\"block-editor-content-only-controls__media-row\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ url && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<MediaThumbnail\n\t\t\t\t\t\t\t\t\t\tattachment={ attachment }\n\t\t\t\t\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\t\tconfig={ config }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__media-title\">\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// TODO - truncate long titles or url smartly (e.g. show filename).\n\t\t\t\t\t\t\t\t\t\t\tattachment?.title?.raw &&\n\t\t\t\t\t\t\t\t\t\t\tattachment?.title?.raw !== ''\n\t\t\t\t\t\t\t\t\t\t\t\t? attachment?.title?.raw\n\t\t\t\t\t\t\t\t\t\t\t\t: url\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ! url && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-content-only-controls__media-placeholder\"\n\t\t\t\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\t\t\t\twidth: '24px',\n\t\t\t\t\t\t\t\t\t\t\theight: '24px',\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__media-title\">\n\t\t\t\t\t\t\t\t\t\t{ chooseItemLabel }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Grid>\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t/>\n\t\t</MediaUploadCheck>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,OAChB;AACP,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB;AAAA,EACC,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAA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AA,UAEF;AAAA;AAAA,MACD;AAAA;AAAA,EAEF,GACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -74,7 +74,7 @@ if (window.crossOriginIsolated) {
|
|
|
74
74
|
if (window.crossOriginIsolated) {
|
|
75
75
|
const supportsCredentialless = "credentialless" in window.HTMLIFrameElement.prototype;
|
|
76
76
|
const disableEmbedPreviews = createHigherOrderComponent(
|
|
77
|
-
(BlockEdit) => (props)
|
|
77
|
+
(BlockEdit) => function DisableEmbedPreviews(props) {
|
|
78
78
|
if ("core/embed" !== props.name) {
|
|
79
79
|
return /* @__PURE__ */ jsx(BlockEdit, { ...props });
|
|
80
80
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/cross-origin-isolation.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Adds crossorigin and credentialless attributes to elements as needed.\n *\n * @param {Element} el The element to modify.\n */\nfunction addCrossOriginAttributes( el ) {\n\t// Add the crossorigin attribute if missing.\n\tif ( ! el.hasAttribute( 'crossorigin' ) ) {\n\t\tel.setAttribute( 'crossorigin', 'anonymous' );\n\t}\n\n\t// For iframes, add the credentialless attribute.\n\tif ( el.nodeName === 'IFRAME' && ! el.hasAttribute( 'credentialless' ) ) {\n\t\t// Do not modify the iframed editor canvas.\n\t\tif ( el.getAttribute( 'src' )?.startsWith( 'blob:' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tel.setAttribute( 'credentialless', '' );\n\n\t\t// Reload the iframe to ensure the new attribute is taken into account.\n\t\tconst origSrc = el.getAttribute( 'src' ) || '';\n\t\tel.setAttribute( 'src', '' );\n\t\tel.setAttribute( 'src', origSrc );\n\t}\n}\n\n// Only add the mutation observer if the site is cross-origin isolated.\nif ( window.crossOriginIsolated ) {\n\t/*\n\t * Detects dynamically added DOM nodes that are missing the `crossorigin` attribute.\n\t */\n\tconst observer = new window.MutationObserver( ( mutations ) => {\n\t\tmutations.forEach( ( mutation ) => {\n\t\t\t[ mutation.addedNodes, mutation.target ].forEach( ( value ) => {\n\t\t\t\tconst nodes =\n\t\t\t\t\tvalue instanceof window.NodeList ? value : [ value ];\n\t\t\t\tnodes.forEach( ( node ) => {\n\t\t\t\t\tconst el = node;\n\n\t\t\t\t\tif ( ! el.querySelectorAll ) {\n\t\t\t\t\t\t// Most likely a text node.\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tel.querySelectorAll(\n\t\t\t\t\t\t'img,source,script,video,link,iframe'\n\t\t\t\t\t).forEach( ( v ) => {\n\t\t\t\t\t\taddCrossOriginAttributes( v );\n\t\t\t\t\t} );\n\n\t\t\t\t\tif ( el.nodeName === 'IFRAME' ) {\n\t\t\t\t\t\tconst iframeNode = el;\n\n\t\t\t\t\t\t/*\n\t\t\t\t\t\t * Sandboxed iframes should not get modified. For example embedding a tweet served in a sandboxed\n\t\t\t\t\t\t * iframe, the tweet itself would not be modified.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tconst isEmbedSandboxIframe =\n\t\t\t\t\t\t\tiframeNode.classList.contains(\n\t\t\t\t\t\t\t\t'components-sandbox'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( ! isEmbedSandboxIframe ) {\n\t\t\t\t\t\t\tiframeNode.addEventListener( 'load', () => {\n\t\t\t\t\t\t\t\tif ( iframeNode.contentDocument ) {\n\t\t\t\t\t\t\t\t\tobserver.observe(\n\t\t\t\t\t\t\t\t\t\tiframeNode.contentDocument,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tchildList: true,\n\t\t\t\t\t\t\t\t\t\t\tattributes: true,\n\t\t\t\t\t\t\t\t\t\t\tsubtree: true,\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\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'IMG',\n\t\t\t\t\t\t\t'SOURCE',\n\t\t\t\t\t\t\t'SCRIPT',\n\t\t\t\t\t\t\t'VIDEO',\n\t\t\t\t\t\t\t'LINK',\n\t\t\t\t\t\t\t'IFRAME',\n\t\t\t\t\t\t].includes( el.nodeName )\n\t\t\t\t\t) {\n\t\t\t\t\t\taddCrossOriginAttributes( el );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t} );\n\t} );\n\n\tobserver.observe( document.body, {\n\t\tchildList: true,\n\t\tattributes: true,\n\t\tsubtree: true,\n\t} );\n}\n\n// Only apply the embed preview filter when cross-origin isolated.\nif ( window.crossOriginIsolated ) {\n\tconst supportsCredentialless =\n\t\t'credentialless' in window.HTMLIFrameElement.prototype;\n\n\tconst disableEmbedPreviews = createHigherOrderComponent(\n\t\t( BlockEdit )
|
|
5
|
-
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,kCAAkC;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Adds crossorigin and credentialless attributes to elements as needed.\n *\n * @param {Element} el The element to modify.\n */\nfunction addCrossOriginAttributes( el ) {\n\t// Add the crossorigin attribute if missing.\n\tif ( ! el.hasAttribute( 'crossorigin' ) ) {\n\t\tel.setAttribute( 'crossorigin', 'anonymous' );\n\t}\n\n\t// For iframes, add the credentialless attribute.\n\tif ( el.nodeName === 'IFRAME' && ! el.hasAttribute( 'credentialless' ) ) {\n\t\t// Do not modify the iframed editor canvas.\n\t\tif ( el.getAttribute( 'src' )?.startsWith( 'blob:' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tel.setAttribute( 'credentialless', '' );\n\n\t\t// Reload the iframe to ensure the new attribute is taken into account.\n\t\tconst origSrc = el.getAttribute( 'src' ) || '';\n\t\tel.setAttribute( 'src', '' );\n\t\tel.setAttribute( 'src', origSrc );\n\t}\n}\n\n// Only add the mutation observer if the site is cross-origin isolated.\nif ( window.crossOriginIsolated ) {\n\t/*\n\t * Detects dynamically added DOM nodes that are missing the `crossorigin` attribute.\n\t */\n\tconst observer = new window.MutationObserver( ( mutations ) => {\n\t\tmutations.forEach( ( mutation ) => {\n\t\t\t[ mutation.addedNodes, mutation.target ].forEach( ( value ) => {\n\t\t\t\tconst nodes =\n\t\t\t\t\tvalue instanceof window.NodeList ? value : [ value ];\n\t\t\t\tnodes.forEach( ( node ) => {\n\t\t\t\t\tconst el = node;\n\n\t\t\t\t\tif ( ! el.querySelectorAll ) {\n\t\t\t\t\t\t// Most likely a text node.\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tel.querySelectorAll(\n\t\t\t\t\t\t'img,source,script,video,link,iframe'\n\t\t\t\t\t).forEach( ( v ) => {\n\t\t\t\t\t\taddCrossOriginAttributes( v );\n\t\t\t\t\t} );\n\n\t\t\t\t\tif ( el.nodeName === 'IFRAME' ) {\n\t\t\t\t\t\tconst iframeNode = el;\n\n\t\t\t\t\t\t/*\n\t\t\t\t\t\t * Sandboxed iframes should not get modified. For example embedding a tweet served in a sandboxed\n\t\t\t\t\t\t * iframe, the tweet itself would not be modified.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tconst isEmbedSandboxIframe =\n\t\t\t\t\t\t\tiframeNode.classList.contains(\n\t\t\t\t\t\t\t\t'components-sandbox'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( ! isEmbedSandboxIframe ) {\n\t\t\t\t\t\t\tiframeNode.addEventListener( 'load', () => {\n\t\t\t\t\t\t\t\tif ( iframeNode.contentDocument ) {\n\t\t\t\t\t\t\t\t\tobserver.observe(\n\t\t\t\t\t\t\t\t\t\tiframeNode.contentDocument,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tchildList: true,\n\t\t\t\t\t\t\t\t\t\t\tattributes: true,\n\t\t\t\t\t\t\t\t\t\t\tsubtree: true,\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\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'IMG',\n\t\t\t\t\t\t\t'SOURCE',\n\t\t\t\t\t\t\t'SCRIPT',\n\t\t\t\t\t\t\t'VIDEO',\n\t\t\t\t\t\t\t'LINK',\n\t\t\t\t\t\t\t'IFRAME',\n\t\t\t\t\t\t].includes( el.nodeName )\n\t\t\t\t\t) {\n\t\t\t\t\t\taddCrossOriginAttributes( el );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t} );\n\t} );\n\n\tobserver.observe( document.body, {\n\t\tchildList: true,\n\t\tattributes: true,\n\t\tsubtree: true,\n\t} );\n}\n\n// Only apply the embed preview filter when cross-origin isolated.\nif ( window.crossOriginIsolated ) {\n\tconst supportsCredentialless =\n\t\t'credentialless' in window.HTMLIFrameElement.prototype;\n\n\tconst disableEmbedPreviews = createHigherOrderComponent(\n\t\t( BlockEdit ) =>\n\t\t\tfunction DisableEmbedPreviews( props ) {\n\t\t\t\tif ( 'core/embed' !== props.name ) {\n\t\t\t\t\treturn <BlockEdit { ...props } />;\n\t\t\t\t}\n\n\t\t\t\t// List of embeds that do not support a preview is from packages/block-library/src/embed/variations.js.\n\t\t\t\tconst previewable =\n\t\t\t\t\tsupportsCredentialless &&\n\t\t\t\t\t! [ 'facebook', 'smugmug' ].includes(\n\t\t\t\t\t\tprops.attributes.providerNameSlug\n\t\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<BlockEdit\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\tattributes={ { ...props.attributes, previewable } }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t},\n\t\t'withDisabledEmbedPreview'\n\t);\n\n\taddFilter(\n\t\t'editor.BlockEdit',\n\t\t'media-experiments/disable-embed-previews',\n\t\tdisableEmbedPreviews\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,kCAAkC;AAkH/B;AA3GZ,SAAS,yBAA0B,IAAK;AAEvC,MAAK,CAAE,GAAG,aAAc,aAAc,GAAI;AACzC,OAAG,aAAc,eAAe,WAAY;AAAA,EAC7C;AAGA,MAAK,GAAG,aAAa,YAAY,CAAE,GAAG,aAAc,gBAAiB,GAAI;AAExE,QAAK,GAAG,aAAc,KAAM,GAAG,WAAY,OAAQ,GAAI;AACtD;AAAA,IACD;AAEA,OAAG,aAAc,kBAAkB,EAAG;AAGtC,UAAM,UAAU,GAAG,aAAc,KAAM,KAAK;AAC5C,OAAG,aAAc,OAAO,EAAG;AAC3B,OAAG,aAAc,OAAO,OAAQ;AAAA,EACjC;AACD;AAGA,IAAK,OAAO,qBAAsB;AAIjC,QAAM,WAAW,IAAI,OAAO,iBAAkB,CAAE,cAAe;AAC9D,cAAU,QAAS,CAAE,aAAc;AAClC,OAAE,SAAS,YAAY,SAAS,MAAO,EAAE,QAAS,CAAE,UAAW;AAC9D,cAAM,QACL,iBAAiB,OAAO,WAAW,QAAQ,CAAE,KAAM;AACpD,cAAM,QAAS,CAAE,SAAU;AAC1B,gBAAM,KAAK;AAEX,cAAK,CAAE,GAAG,kBAAmB;AAE5B;AAAA,UACD;AAEA,aAAG;AAAA,YACF;AAAA,UACD,EAAE,QAAS,CAAE,MAAO;AACnB,qCAA0B,CAAE;AAAA,UAC7B,CAAE;AAEF,cAAK,GAAG,aAAa,UAAW;AAC/B,kBAAM,aAAa;AAMnB,kBAAM,uBACL,WAAW,UAAU;AAAA,cACpB;AAAA,YACD;AAED,gBAAK,CAAE,sBAAuB;AAC7B,yBAAW,iBAAkB,QAAQ,MAAM;AAC1C,oBAAK,WAAW,iBAAkB;AACjC,2BAAS;AAAA,oBACR,WAAW;AAAA,oBACX;AAAA,sBACC,WAAW;AAAA,sBACX,YAAY;AAAA,sBACZ,SAAS;AAAA,oBACV;AAAA,kBACD;AAAA,gBACD;AAAA,cACD,CAAE;AAAA,YACH;AAAA,UACD;AAEA,cACC;AAAA,YACC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD,EAAE,SAAU,GAAG,QAAS,GACvB;AACD,qCAA0B,EAAG;AAAA,UAC9B;AAAA,QACD,CAAE;AAAA,MACH,CAAE;AAAA,IACH,CAAE;AAAA,EACH,CAAE;AAEF,WAAS,QAAS,SAAS,MAAM;AAAA,IAChC,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS;AAAA,EACV,CAAE;AACH;AAGA,IAAK,OAAO,qBAAsB;AACjC,QAAM,yBACL,oBAAoB,OAAO,kBAAkB;AAE9C,QAAM,uBAAuB;AAAA,IAC5B,CAAE,cACD,SAAS,qBAAsB,OAAQ;AACtC,UAAK,iBAAiB,MAAM,MAAO;AAClC,eAAO,oBAAC,aAAY,GAAG,OAAQ;AAAA,MAChC;AAGA,YAAM,cACL,0BACA,CAAE,CAAE,YAAY,SAAU,EAAE;AAAA,QAC3B,MAAM,WAAW;AAAA,MAClB;AAED,aACC;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACL,YAAa,EAAE,GAAG,MAAM,YAAY,YAAY;AAAA;AAAA,MACjD;AAAA,IAEF;AAAA,IACD;AAAA,EACD;AAEA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// packages/block-editor/src/hooks/custom-css.js
|
|
2
|
+
import { useMemo } from "@wordpress/element";
|
|
3
|
+
import { useSelect } from "@wordpress/data";
|
|
4
|
+
import { useInstanceId } from "@wordpress/compose";
|
|
5
|
+
import { getBlockType, hasBlockSupport } from "@wordpress/blocks";
|
|
6
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
7
|
+
import { processCSSNesting } from "@wordpress/global-styles-engine";
|
|
8
|
+
import InspectorControls from "../components/inspector-controls/index.mjs";
|
|
9
|
+
import AdvancedPanel, {
|
|
10
|
+
validateCSS
|
|
11
|
+
} from "../components/global-styles/advanced-panel.mjs";
|
|
12
|
+
import { cleanEmptyObject, useStyleOverride } from "./utils.mjs";
|
|
13
|
+
import { store as blockEditorStore } from "../store/index.mjs";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
var CUSTOM_CSS_INSTANCE_REFERENCE = {};
|
|
16
|
+
var EMPTY_STYLE = {};
|
|
17
|
+
function CustomCSSControl({ blockName, setAttributes, style }) {
|
|
18
|
+
const blockType = getBlockType(blockName);
|
|
19
|
+
function onChange(newStyle) {
|
|
20
|
+
const css = newStyle?.css?.trim() ? newStyle.css : void 0;
|
|
21
|
+
setAttributes({
|
|
22
|
+
style: cleanEmptyObject({ ...newStyle, css })
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const cssHelpText = sprintf(
|
|
26
|
+
// translators: %s: is the name of a block e.g., 'Image' or 'Quote'.
|
|
27
|
+
__(
|
|
28
|
+
"Add your own CSS to customize the appearance of the %s block. You do not need to include a CSS selector, just add the property and value, e.g. color: red;."
|
|
29
|
+
),
|
|
30
|
+
blockType?.title
|
|
31
|
+
);
|
|
32
|
+
return /* @__PURE__ */ jsx(InspectorControls, { group: "advanced", children: /* @__PURE__ */ jsx(
|
|
33
|
+
AdvancedPanel,
|
|
34
|
+
{
|
|
35
|
+
value: style,
|
|
36
|
+
onChange,
|
|
37
|
+
inheritedValue: style,
|
|
38
|
+
help: cssHelpText
|
|
39
|
+
}
|
|
40
|
+
) });
|
|
41
|
+
}
|
|
42
|
+
function CustomCSSEdit({ clientId, name, setAttributes }) {
|
|
43
|
+
const { style, canEditCSS } = useSelect(
|
|
44
|
+
(select) => {
|
|
45
|
+
const { getBlockAttributes, getSettings } = select(blockEditorStore);
|
|
46
|
+
return {
|
|
47
|
+
style: getBlockAttributes(clientId)?.style || EMPTY_STYLE,
|
|
48
|
+
canEditCSS: getSettings().canEditCSS
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[clientId]
|
|
52
|
+
);
|
|
53
|
+
if (!canEditCSS) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
CustomCSSControl,
|
|
58
|
+
{
|
|
59
|
+
blockName: name,
|
|
60
|
+
setAttributes,
|
|
61
|
+
style
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function useBlockProps({ style }) {
|
|
66
|
+
const customCSS = style?.css;
|
|
67
|
+
const isValidCSS = typeof customCSS === "string" && customCSS.trim().length > 0 && validateCSS(customCSS);
|
|
68
|
+
const customCSSIdentifier = useInstanceId(
|
|
69
|
+
CUSTOM_CSS_INSTANCE_REFERENCE,
|
|
70
|
+
"wp-custom-css"
|
|
71
|
+
);
|
|
72
|
+
const customCSSSelector = `.${customCSSIdentifier}`;
|
|
73
|
+
const transformedCSS = useMemo(() => {
|
|
74
|
+
if (!isValidCSS) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
return processCSSNesting(customCSS, customCSSSelector);
|
|
78
|
+
}, [customCSS, customCSSSelector, isValidCSS]);
|
|
79
|
+
useStyleOverride({ css: transformedCSS });
|
|
80
|
+
if (!isValidCSS) {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
className: customCSSIdentifier
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function addSaveProps(props, blockType, attributes) {
|
|
88
|
+
if (!hasBlockSupport(blockType, "customCSS", true)) {
|
|
89
|
+
return props;
|
|
90
|
+
}
|
|
91
|
+
if (!attributes?.style?.css?.trim()) {
|
|
92
|
+
return props;
|
|
93
|
+
}
|
|
94
|
+
const className = props.className ? `${props.className} has-custom-css` : "has-custom-css";
|
|
95
|
+
return {
|
|
96
|
+
...props,
|
|
97
|
+
className
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var custom_css_default = {
|
|
101
|
+
edit: CustomCSSEdit,
|
|
102
|
+
useBlockProps,
|
|
103
|
+
addSaveProps,
|
|
104
|
+
attributeKeys: ["style"],
|
|
105
|
+
hasSupport(name) {
|
|
106
|
+
return hasBlockSupport(name, "customCSS", true);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export {
|
|
110
|
+
custom_css_default as default
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=custom-css.mjs.map
|