@wordpress/block-editor 16.2.0 → 17.0.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 +39 -0
- package/build/components/block-inspector/index.cjs +9 -6
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-keyboard-shortcuts/index.cjs +201 -0
- package/build/components/block-keyboard-shortcuts/index.cjs.map +7 -0
- package/build/components/block-list/block.cjs +10 -3
- package/build/components/block-list/block.cjs.map +2 -2
- package/build/components/block-list/index.cjs +6 -1
- package/build/components/block-list/index.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs +4 -0
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs +6 -7
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs.map +2 -2
- package/build/components/block-parent-selector/index.cjs +98 -29
- package/build/components/block-parent-selector/index.cjs.map +3 -3
- package/build/components/block-popover/inbetween.cjs +2 -2
- package/build/components/block-popover/inbetween.cjs.map +2 -2
- package/build/components/block-preview/index.cjs +0 -4
- package/build/components/block-preview/index.cjs.map +2 -2
- package/build/components/block-styles/index.cjs +77 -33
- package/build/components/block-styles/index.cjs.map +3 -3
- package/build/components/block-visibility/constants.cjs.map +2 -2
- package/build/components/child-layout-control/index.cjs.map +2 -2
- package/build/components/colors/with-colors.cjs +55 -71
- package/build/components/colors/with-colors.cjs.map +2 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs +4 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +2 -2
- package/build/components/dimensions-tool/index.cjs +18 -16
- package/build/components/dimensions-tool/index.cjs.map +2 -2
- package/build/components/dimensions-tool/utils.cjs +61 -0
- package/build/components/dimensions-tool/utils.cjs.map +7 -0
- package/build/components/duotone-control/index.cjs +2 -0
- package/build/components/duotone-control/index.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs.map +3 -3
- package/build/components/global-styles/border-panel.cjs +2 -5
- package/build/components/global-styles/border-panel.cjs.map +2 -2
- package/build/components/global-styles/color-panel.cjs +14 -2
- package/build/components/global-styles/color-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +9 -5
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/filters-panel.cjs +12 -8
- package/build/components/global-styles/filters-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs +16 -11
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/global-styles/utils.cjs +9 -0
- package/build/components/global-styles/utils.cjs.map +2 -2
- package/build/components/inner-blocks/index.cjs +5 -3
- package/build/components/inner-blocks/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/index.cjs +39 -22
- package/build/components/inserter/block-patterns-explorer/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs +21 -55
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs +19 -44
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs.map +3 -3
- package/build/components/inserter/hooks/use-insertion-point.cjs +4 -4
- package/build/components/inserter/hooks/use-insertion-point.cjs.map +2 -2
- package/build/components/inserter/menu.cjs +18 -7
- package/build/components/inserter/menu.cjs.map +2 -2
- package/build/components/inserter/quick-inserter.cjs +30 -27
- package/build/components/inserter/quick-inserter.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/styles-tab.cjs +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
- package/build/components/list-view/index.cjs +31 -5
- package/build/components/list-view/index.cjs.map +3 -3
- package/build/components/list-view/utils.cjs +13 -1
- package/build/components/list-view/utils.cjs.map +2 -2
- package/build/components/media-placeholder/index.cjs +1 -1
- package/build/components/media-placeholder/index.cjs.map +3 -3
- package/build/components/provider/index.cjs +5 -1
- package/build/components/provider/index.cjs.map +3 -3
- package/build/components/publish-date-time-picker/index.cjs +3 -2
- package/build/components/publish-date-time-picker/index.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/enter.cjs +46 -39
- package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
- package/build/components/rich-text/index.cjs +7 -5
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/rich-text/multiline.cjs +105 -70
- package/build/components/rich-text/multiline.cjs.map +3 -3
- package/build/components/url-input/index.cjs.map +2 -2
- package/build/components/writing-flow/use-input.cjs +65 -13
- package/build/components/writing-flow/use-input.cjs.map +3 -3
- package/build/hooks/border.cjs +25 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +9 -2
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/duotone.cjs +4 -3
- package/build/hooks/duotone.cjs.map +2 -2
- package/build/hooks/gap.cjs +8 -2
- package/build/hooks/gap.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +35 -13
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/layout.cjs +23 -1
- package/build/hooks/layout.cjs.map +2 -2
- package/build/hooks/states.cjs +7 -4
- package/build/hooks/states.cjs.map +2 -2
- package/build/layouts/constrained.cjs +8 -1
- package/build/layouts/constrained.cjs.map +2 -2
- package/build/layouts/flex.cjs +9 -0
- package/build/layouts/flex.cjs.map +2 -2
- package/build/layouts/flow.cjs +4 -1
- package/build/layouts/flow.cjs.map +2 -2
- package/build/layouts/grid.cjs +5 -1
- package/build/layouts/grid.cjs.map +2 -2
- package/build/private-apis.cjs +3 -1
- package/build/private-apis.cjs.map +2 -2
- package/build/store/actions.cjs +1 -1
- package/build/store/actions.cjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +9 -6
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-keyboard-shortcuts/index.mjs +173 -0
- package/build-module/components/block-keyboard-shortcuts/index.mjs.map +7 -0
- package/build-module/components/block-list/block.mjs +10 -3
- package/build-module/components/block-list/block.mjs.map +2 -2
- package/build-module/components/block-list/index.mjs +6 -1
- package/build-module/components/block-list/index.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs +4 -0
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs +6 -7
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map +2 -2
- package/build-module/components/block-parent-selector/index.mjs +101 -32
- package/build-module/components/block-parent-selector/index.mjs.map +2 -2
- package/build-module/components/block-popover/inbetween.mjs +2 -2
- package/build-module/components/block-popover/inbetween.mjs.map +2 -2
- package/build-module/components/block-preview/index.mjs +0 -4
- package/build-module/components/block-preview/index.mjs.map +2 -2
- package/build-module/components/block-styles/index.mjs +79 -35
- package/build-module/components/block-styles/index.mjs.map +2 -2
- package/build-module/components/block-visibility/constants.mjs.map +2 -2
- package/build-module/components/child-layout-control/index.mjs +5 -5
- package/build-module/components/child-layout-control/index.mjs.map +1 -1
- package/build-module/components/colors/with-colors.mjs +56 -72
- package/build-module/components/colors/with-colors.mjs.map +2 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +4 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
- package/build-module/components/dimensions-tool/index.mjs +19 -17
- package/build-module/components/dimensions-tool/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/utils.mjs +35 -0
- package/build-module/components/dimensions-tool/utils.mjs.map +7 -0
- package/build-module/components/duotone-control/index.mjs +2 -0
- package/build-module/components/duotone-control/index.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +5 -2
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +2 -5
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/color-panel.mjs +14 -2
- package/build-module/components/global-styles/color-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +9 -5
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/filters-panel.mjs +16 -9
- package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs +16 -11
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/global-styles/utils.mjs +8 -0
- package/build-module/components/global-styles/utils.mjs.map +2 -2
- package/build-module/components/inner-blocks/index.mjs +5 -3
- package/build-module/components/inner-blocks/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/index.mjs +39 -22
- package/build-module/components/inserter/block-patterns-explorer/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs +22 -56
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs +20 -45
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs.map +2 -2
- package/build-module/components/inserter/hooks/use-insertion-point.mjs +4 -4
- package/build-module/components/inserter/hooks/use-insertion-point.mjs.map +2 -2
- package/build-module/components/inserter/menu.mjs +19 -8
- package/build-module/components/inserter/menu.mjs.map +2 -2
- package/build-module/components/inserter/quick-inserter.mjs +30 -27
- package/build-module/components/inserter/quick-inserter.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/list-view/index.mjs +32 -5
- package/build-module/components/list-view/index.mjs.map +3 -3
- package/build-module/components/list-view/utils.mjs +13 -1
- package/build-module/components/list-view/utils.mjs.map +2 -2
- package/build-module/components/media-placeholder/index.mjs +3 -3
- package/build-module/components/media-placeholder/index.mjs.map +2 -2
- package/build-module/components/provider/index.mjs +6 -2
- package/build-module/components/provider/index.mjs.map +2 -2
- package/build-module/components/publish-date-time-picker/index.mjs +3 -2
- package/build-module/components/publish-date-time-picker/index.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +46 -39
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +7 -5
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/rich-text/multiline.mjs +112 -72
- package/build-module/components/rich-text/multiline.mjs.map +2 -2
- package/build-module/components/url-input/index.mjs +2 -2
- package/build-module/components/url-input/index.mjs.map +1 -1
- package/build-module/components/writing-flow/use-input.mjs +66 -14
- package/build-module/components/writing-flow/use-input.mjs.map +3 -3
- package/build-module/hooks/border.mjs +26 -8
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +9 -2
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/duotone.mjs +8 -4
- package/build-module/hooks/duotone.mjs.map +2 -2
- package/build-module/hooks/gap.mjs +6 -1
- package/build-module/hooks/gap.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +36 -13
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/layout.mjs +22 -1
- package/build-module/hooks/layout.mjs.map +2 -2
- package/build-module/hooks/states.mjs +8 -5
- package/build-module/hooks/states.mjs.map +2 -2
- package/build-module/layouts/constrained.mjs +8 -1
- package/build-module/layouts/constrained.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +9 -0
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/layouts/flow.mjs +4 -1
- package/build-module/layouts/flow.mjs.map +2 -2
- package/build-module/layouts/grid.mjs +5 -1
- package/build-module/layouts/grid.mjs.map +2 -2
- package/build-module/private-apis.mjs +3 -1
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +1 -1
- package/build-module/store/actions.mjs.map +2 -2
- package/build-style/style-rtl.css +108 -71
- package/build-style/style.css +108 -71
- package/build-types/components/block-visibility/constants.d.ts +4 -3
- package/build-types/components/block-visibility/constants.d.ts.map +1 -1
- package/package.json +43 -43
- package/src/components/background-image-control/README.md +122 -0
- package/src/components/block-edit-visually-button/README.md +39 -0
- package/src/components/block-editing-mode/README.md +72 -0
- package/src/components/block-inspector/index.js +6 -6
- package/src/components/block-keyboard-shortcuts/index.js +256 -0
- package/src/components/block-list/block.js +7 -0
- package/src/components/block-list/index.js +7 -1
- package/src/components/block-list/use-block-props/use-focus-first-element.js +5 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +6 -8
- package/src/components/block-parent-selector/index.js +111 -30
- package/src/components/block-popover/README.md +10 -3
- package/src/components/block-popover/inbetween.js +8 -2
- package/src/components/block-popover/stories/index.story.jsx +143 -0
- package/src/components/block-preview/index.js +0 -2
- package/src/components/block-styles/index.js +95 -43
- package/src/components/block-styles/style.scss +5 -34
- package/src/components/block-tools/style.scss +94 -0
- package/src/components/block-visibility/constants.ts +4 -3
- package/src/components/child-layout-control/index.js +5 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +3 -29
- package/src/components/colors/test/with-colors.js +6 -7
- package/src/components/colors/with-colors.js +79 -105
- package/src/components/dimensions-tool/aspect-ratio-tool.js +16 -4
- package/src/components/dimensions-tool/index.js +34 -22
- package/src/components/dimensions-tool/test/index.js +166 -2
- package/src/components/dimensions-tool/test/utils.js +51 -0
- package/src/components/dimensions-tool/utils.js +67 -0
- package/src/components/duotone-control/index.js +2 -0
- package/src/components/duotone-control/test/index.js +100 -0
- package/src/components/global-styles/advanced-panel.js +5 -2
- package/src/components/global-styles/border-panel.js +11 -9
- package/src/components/global-styles/color-panel.js +13 -1
- package/src/components/global-styles/dimensions-panel.js +17 -5
- package/src/components/global-styles/filters-panel.js +24 -10
- package/src/components/global-styles/shadow-panel-components.js +38 -11
- package/src/components/global-styles/test/border-panel.js +230 -0
- package/src/components/global-styles/test/color-panel.js +24 -0
- package/src/components/global-styles/test/dimensions-panel.js +98 -7
- package/src/components/global-styles/test/filters-panel.js +84 -0
- package/src/components/global-styles/test/utils.js +30 -0
- package/src/components/global-styles/utils.js +23 -0
- package/src/components/inner-blocks/index.js +11 -2
- package/src/components/inner-blocks/stories/index.story.jsx +246 -0
- package/src/components/inserter/block-patterns-explorer/index.js +24 -11
- package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +18 -56
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +22 -47
- package/src/components/inserter/hooks/use-insertion-point.js +9 -4
- package/src/components/inserter/menu.js +23 -10
- package/src/components/inserter/quick-inserter.js +15 -13
- package/src/components/inserter/style.scss +44 -62
- package/src/components/inspector-controls-tabs/README.md +92 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/src/components/link-control/test/index.js +5 -0
- package/src/components/list-view/index.js +50 -7
- package/src/components/list-view/utils.js +16 -1
- package/src/components/media-placeholder/index.js +9 -4
- package/src/components/plain-text/stories/index.story.jsx +3 -0
- package/src/components/provider/index.js +7 -1
- package/src/components/publish-date-time-picker/README.md +10 -0
- package/src/components/publish-date-time-picker/index.js +17 -14
- package/src/components/rich-text/event-listeners/enter.js +58 -45
- package/src/components/rich-text/index.js +9 -4
- package/src/components/rich-text/multiline.js +126 -86
- package/src/components/url-input/index.js +2 -2
- package/src/components/url-input/test/fixtures/validated-input-control-deprecation.js +27 -0
- package/src/components/url-input/test/index.js +5 -0
- package/src/components/url-popover/README.md +7 -0
- package/src/components/url-popover/stories/index.story.jsx +133 -47
- package/src/components/writing-flow/use-input.js +105 -15
- package/src/hooks/border.js +27 -8
- package/src/hooks/dimensions.js +8 -1
- package/src/hooks/duotone.js +23 -7
- package/src/hooks/gap.js +16 -0
- package/src/hooks/layout-child.js +41 -9
- package/src/hooks/layout.js +117 -71
- package/src/hooks/states.js +8 -5
- package/src/hooks/test/gap.js +31 -1
- package/src/hooks/test/layout-child.js +60 -1
- package/src/hooks/test/layout.js +27 -0
- package/src/layouts/constrained.js +9 -1
- package/src/layouts/flex.js +15 -0
- package/src/layouts/flow.js +4 -1
- package/src/layouts/grid.js +9 -1
- package/src/layouts/test/constrained.js +26 -0
- package/src/layouts/test/flow.js +26 -0
- package/src/layouts/test/grid.js +46 -0
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +14 -1
- package/build/components/floating-toolbar/nav-up-icon.cjs +0 -52
- package/build/components/floating-toolbar/nav-up-icon.cjs.map +0 -7
- package/build/components/gradients/with-gradient.cjs +0 -36
- package/build/components/gradients/with-gradient.cjs.map +0 -7
- package/build/components/inserter-button/sparkles.cjs +0 -36
- package/build/components/inserter-button/sparkles.cjs.map +0 -7
- package/build-module/components/floating-toolbar/nav-up-icon.mjs +0 -31
- package/build-module/components/floating-toolbar/nav-up-icon.mjs.map +0 -7
- package/build-module/components/gradients/with-gradient.mjs +0 -11
- package/build-module/components/gradients/with-gradient.mjs.map +0 -7
- package/build-module/components/inserter-button/sparkles.mjs +0 -15
- package/build-module/components/inserter-button/sparkles.mjs.map +0 -7
- package/build-style/default-editor-styles-rtl.css +0 -68
- package/build-style/default-editor-styles.css +0 -68
- package/src/components/floating-toolbar/nav-up-icon.js +0 -22
- package/src/components/gradients/with-gradient.js +0 -9
- package/src/components/inserter-button/README.md +0 -62
- package/src/components/inserter-button/sparkles.js +0 -12
- package/src/default-editor-styles.scss +0 -25
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// packages/block-editor/src/components/block-styles/index.js
|
|
2
|
-
import clsx from "clsx";
|
|
3
2
|
import { useState, useMemo } from "@wordpress/element";
|
|
4
3
|
import { useSelect } from "@wordpress/data";
|
|
5
|
-
import { debounce } from "@wordpress/compose";
|
|
4
|
+
import { debounce, useInstanceId } from "@wordpress/compose";
|
|
6
5
|
import {
|
|
7
|
-
|
|
6
|
+
Composite,
|
|
8
7
|
__experimentalTruncate as Truncate,
|
|
9
8
|
__experimentalToolsPanel as ToolsPanel,
|
|
10
9
|
__experimentalToolsPanelItem as ToolsPanelItem
|
|
11
10
|
} from "@wordpress/components";
|
|
11
|
+
import { Button } from "@wordpress/ui";
|
|
12
12
|
import { __ } from "@wordpress/i18n";
|
|
13
13
|
import PreviewBlockPopover from "../block-switcher/preview-block-popover.mjs";
|
|
14
14
|
import useStylesForBlocks from "./use-styles-for-block.mjs";
|
|
@@ -18,6 +18,7 @@ import { store as blockEditorStore } from "../../store/index.mjs";
|
|
|
18
18
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
19
|
var noop = () => {
|
|
20
20
|
};
|
|
21
|
+
var getCompositeItemId = (instanceId, style) => `${instanceId}-${style.name}`;
|
|
21
22
|
function BlockStyles({ clientId, onSwitch = noop, onHoverClassName = noop }) {
|
|
22
23
|
const canEdit = useSelect(
|
|
23
24
|
(select) => select(blockEditorStore).canEditBlock(clientId),
|
|
@@ -36,6 +37,17 @@ function BlockStyles({ clientId, onSwitch = noop, onHoverClassName = noop }) {
|
|
|
36
37
|
const [hoveredStyle, setHoveredStyle] = useState(null);
|
|
37
38
|
const [blockStylesAnchor, setBlockStylesAnchor] = useState(null);
|
|
38
39
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
40
|
+
const instanceId = useInstanceId(
|
|
41
|
+
BlockStyles,
|
|
42
|
+
"block-editor-block-styles"
|
|
43
|
+
);
|
|
44
|
+
const styleRows = useMemo(() => {
|
|
45
|
+
const rows = [];
|
|
46
|
+
for (let i = 0; i < (stylesToRender?.length ?? 0); i += 2) {
|
|
47
|
+
rows.push(stylesToRender.slice(i, i + 2));
|
|
48
|
+
}
|
|
49
|
+
return rows;
|
|
50
|
+
}, [stylesToRender]);
|
|
39
51
|
const previewBlocks = useMemo(() => {
|
|
40
52
|
if (!hoveredStyle || !genericPreviewBlock) {
|
|
41
53
|
return null;
|
|
@@ -73,6 +85,14 @@ function BlockStyles({ clientId, onSwitch = noop, onHoverClassName = noop }) {
|
|
|
73
85
|
debouncedSetHoveredStyle(item);
|
|
74
86
|
onHoverClassName(item?.name ?? null);
|
|
75
87
|
};
|
|
88
|
+
const onSetActiveId = (nextActiveId) => {
|
|
89
|
+
const nextStyle = stylesToRender.find(
|
|
90
|
+
(style) => getCompositeItemId(instanceId, style) === nextActiveId
|
|
91
|
+
);
|
|
92
|
+
if (nextStyle && nextStyle.name !== activeStyle.name) {
|
|
93
|
+
onSelectStylePreview(nextStyle);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
76
96
|
const defaultStyle = getDefaultStyle(stylesToRender);
|
|
77
97
|
const hasValue = () => {
|
|
78
98
|
return activeStyle?.name !== defaultStyle?.name;
|
|
@@ -102,38 +122,62 @@ function BlockStyles({ clientId, onSwitch = noop, onHoverClassName = noop }) {
|
|
|
102
122
|
ref: setBlockStylesAnchor,
|
|
103
123
|
className: "block-editor-block-styles",
|
|
104
124
|
children: [
|
|
105
|
-
/* @__PURE__ */ jsx(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
/* @__PURE__ */ jsx(
|
|
126
|
+
Composite,
|
|
127
|
+
{
|
|
128
|
+
role: "radiogroup",
|
|
129
|
+
"aria-label": __("Styles"),
|
|
130
|
+
className: "block-editor-block-styles__variants",
|
|
131
|
+
activeId: getCompositeItemId(
|
|
132
|
+
instanceId,
|
|
133
|
+
activeStyle
|
|
134
|
+
),
|
|
135
|
+
setActiveId: onSetActiveId,
|
|
136
|
+
focusLoop: true,
|
|
137
|
+
focusWrap: true,
|
|
138
|
+
focusShift: true,
|
|
139
|
+
children: styleRows.map((row, rowIndex) => /* @__PURE__ */ jsx(
|
|
140
|
+
Composite.Row,
|
|
141
|
+
{
|
|
142
|
+
className: "block-editor-block-styles__row",
|
|
143
|
+
children: row.map((style) => /* @__PURE__ */ jsx(
|
|
144
|
+
Composite.Item,
|
|
145
|
+
{
|
|
146
|
+
id: getCompositeItemId(
|
|
147
|
+
instanceId,
|
|
148
|
+
style
|
|
149
|
+
),
|
|
150
|
+
render: /* @__PURE__ */ jsx(
|
|
151
|
+
Button,
|
|
152
|
+
{
|
|
153
|
+
className: "block-editor-block-styles__item",
|
|
154
|
+
tone: "neutral",
|
|
155
|
+
variant: activeStyle.name === style.name ? "solid" : "outline"
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
role: "radio",
|
|
159
|
+
"aria-checked": activeStyle.name === style.name,
|
|
160
|
+
onMouseEnter: () => styleItemHandler(style),
|
|
161
|
+
onFocus: () => styleItemHandler(style),
|
|
162
|
+
onMouseLeave: () => styleItemHandler(null),
|
|
163
|
+
onBlur: () => styleItemHandler(null),
|
|
164
|
+
onClick: () => onSelectStylePreview(style),
|
|
165
|
+
children: /* @__PURE__ */ jsx(
|
|
166
|
+
Truncate,
|
|
167
|
+
{
|
|
168
|
+
numberOfLines: 3,
|
|
169
|
+
className: "block-editor-block-styles__item-text",
|
|
170
|
+
children: style.label || style.name
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
},
|
|
174
|
+
style.name
|
|
175
|
+
))
|
|
176
|
+
},
|
|
177
|
+
rowIndex
|
|
178
|
+
))
|
|
179
|
+
}
|
|
180
|
+
),
|
|
137
181
|
previewBlocks && /* @__PURE__ */ jsx(
|
|
138
182
|
PreviewBlockPopover,
|
|
139
183
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-styles/index.js"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";AAAA,
|
|
4
|
+
"sourcesContent": ["import { useState, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { debounce, useInstanceId } from '@wordpress/compose';\nimport {\n\tComposite,\n\t__experimentalTruncate as Truncate,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\n// eslint-disable-next-line @wordpress/use-recommended-components\nimport { Button } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport PreviewBlockPopover from '../block-switcher/preview-block-popover';\nimport useStylesForBlocks from './use-styles-for-block';\nimport { useToolsPanelDropdownMenuProps } from '../global-styles/utils';\nimport { getDefaultStyle, replaceActiveStyle } from './utils';\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\nconst getCompositeItemId = ( instanceId, style ) =>\n\t`${ instanceId }-${ style.name }`;\n\n// Block Styles component for the Settings Sidebar.\nfunction BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {\n\tconst canEdit = useSelect(\n\t\t( select ) => select( blockEditorStore ).canEditBlock( clientId ),\n\t\t[ clientId ]\n\t);\n\tconst {\n\t\tonSelect,\n\t\tstylesToRender,\n\t\tactiveStyle,\n\t\tgenericPreviewBlock,\n\t\tclassName,\n\t} = useStylesForBlocks( {\n\t\tclientId,\n\t\tonSwitch,\n\t} );\n\tconst [ hoveredStyle, setHoveredStyle ] = useState( null );\n\tconst [ blockStylesAnchor, setBlockStylesAnchor ] = useState( null );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst instanceId = useInstanceId(\n\t\tBlockStyles,\n\t\t'block-editor-block-styles'\n\t);\n\n\tconst styleRows = useMemo( () => {\n\t\tconst rows = [];\n\t\tfor ( let i = 0; i < ( stylesToRender?.length ?? 0 ); i += 2 ) {\n\t\t\trows.push( stylesToRender.slice( i, i + 2 ) );\n\t\t}\n\t\treturn rows;\n\t}, [ stylesToRender ] );\n\n\tconst previewBlocks = useMemo( () => {\n\t\tif ( ! hoveredStyle || ! genericPreviewBlock ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst previewClassName = replaceActiveStyle(\n\t\t\tclassName,\n\t\t\tactiveStyle,\n\t\t\thoveredStyle\n\t\t);\n\t\treturn [\n\t\t\t{\n\t\t\t\t...genericPreviewBlock,\n\t\t\t\tattributes: {\n\t\t\t\t\t...( genericPreviewBlock.attributes || {} ),\n\t\t\t\t\tclassName: previewClassName,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}, [ hoveredStyle, genericPreviewBlock, className, activeStyle ] );\n\n\tif ( ! canEdit || ! stylesToRender || stylesToRender.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst debouncedSetHoveredStyle = debounce( setHoveredStyle, 250 );\n\n\tconst onSelectStylePreview = ( style ) => {\n\t\tonSelect( style );\n\t\tonHoverClassName( null );\n\t\tsetHoveredStyle( null );\n\t\tdebouncedSetHoveredStyle.cancel();\n\t};\n\n\tconst styleItemHandler = ( item ) => {\n\t\tif ( hoveredStyle === item ) {\n\t\t\tdebouncedSetHoveredStyle.cancel();\n\t\t\treturn;\n\t\t}\n\t\tdebouncedSetHoveredStyle( item );\n\t\tonHoverClassName( item?.name ?? null );\n\t};\n\n\tconst onSetActiveId = ( nextActiveId ) => {\n\t\tconst nextStyle = stylesToRender.find(\n\t\t\t( style ) =>\n\t\t\t\tgetCompositeItemId( instanceId, style ) === nextActiveId\n\t\t);\n\t\tif ( nextStyle && nextStyle.name !== activeStyle.name ) {\n\t\t\tonSelectStylePreview( nextStyle );\n\t\t}\n\t};\n\n\tconst defaultStyle = getDefaultStyle( stylesToRender );\n\n\tconst hasValue = () => {\n\t\treturn activeStyle?.name !== defaultStyle?.name;\n\t};\n\n\tconst onDeselect = () => {\n\t\tonSelectStylePreview( defaultStyle );\n\t};\n\n\treturn (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Styles' ) }\n\t\t\tresetAll={ onDeselect }\n\t\t\tpanelId={ clientId }\n\t\t\thasInnerWrapper\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ hasValue }\n\t\t\t\tlabel={ __( 'Variation' ) }\n\t\t\t\tonDeselect={ onDeselect }\n\t\t\t\tisShownByDefault\n\t\t\t\tpanelId={ clientId }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tref={ setBlockStylesAnchor }\n\t\t\t\t\tclassName=\"block-editor-block-styles\"\n\t\t\t\t>\n\t\t\t\t\t<Composite\n\t\t\t\t\t\trole=\"radiogroup\"\n\t\t\t\t\t\taria-label={ __( 'Styles' ) }\n\t\t\t\t\t\tclassName=\"block-editor-block-styles__variants\"\n\t\t\t\t\t\tactiveId={ getCompositeItemId(\n\t\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\t\tactiveStyle\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tsetActiveId={ onSetActiveId }\n\t\t\t\t\t\tfocusLoop\n\t\t\t\t\t\tfocusWrap\n\t\t\t\t\t\tfocusShift\n\t\t\t\t\t>\n\t\t\t\t\t\t{ styleRows.map( ( row, rowIndex ) => (\n\t\t\t\t\t\t\t<Composite.Row\n\t\t\t\t\t\t\t\tkey={ rowIndex }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-styles__row\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ row.map( ( style ) => (\n\t\t\t\t\t\t\t\t\t<Composite.Item\n\t\t\t\t\t\t\t\t\t\tkey={ style.name }\n\t\t\t\t\t\t\t\t\t\tid={ getCompositeItemId(\n\t\t\t\t\t\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\t\t\t\t\t\tstyle\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\trender={\n\t\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-block-styles__item\"\n\t\t\t\t\t\t\t\t\t\t\t\ttone=\"neutral\"\n\t\t\t\t\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\t\t\t\t\tactiveStyle.name ===\n\t\t\t\t\t\t\t\t\t\t\t\t\tstyle.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? 'solid'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: 'outline'\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\trole=\"radio\"\n\t\t\t\t\t\t\t\t\t\taria-checked={\n\t\t\t\t\t\t\t\t\t\t\tactiveStyle.name === style.name\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMouseEnter={ () =>\n\t\t\t\t\t\t\t\t\t\t\tstyleItemHandler( style )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonFocus={ () =>\n\t\t\t\t\t\t\t\t\t\t\tstyleItemHandler( style )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMouseLeave={ () =>\n\t\t\t\t\t\t\t\t\t\t\tstyleItemHandler( null )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonBlur={ () =>\n\t\t\t\t\t\t\t\t\t\t\tstyleItemHandler( null )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonSelectStylePreview( style )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<Truncate\n\t\t\t\t\t\t\t\t\t\t\tnumberOfLines={ 3 }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-block-styles__item-text\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ style.label || style.name }\n\t\t\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t\t\t</Composite.Item>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</Composite.Row>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Composite>\n\t\t\t\t\t{ previewBlocks && (\n\t\t\t\t\t\t<PreviewBlockPopover\n\t\t\t\t\t\t\tblocks={ previewBlocks }\n\t\t\t\t\t\t\tplacement=\"left-start\"\n\t\t\t\t\t\t\toffset={ 34 }\n\t\t\t\t\t\t\tanchor={ blockStylesAnchor }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</ToolsPanelItem>\n\t\t</ToolsPanel>\n\t);\n}\n\nexport default BlockStyles;\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,UAAU,eAAe;AAClC,SAAS,iBAAiB;AAC1B,SAAS,UAAU,qBAAqB;AACxC;AAAA,EACC;AAAA,EACA,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,OAC1B;AAEP,SAAS,cAAc;AACvB,SAAS,UAAU;AACnB,OAAO,yBAAyB;AAChC,OAAO,wBAAwB;AAC/B,SAAS,sCAAsC;AAC/C,SAAS,iBAAiB,0BAA0B;AACpD,SAAS,SAAS,wBAAwB;AAoHtC,SA8BO,KA9BP;AAlHJ,IAAM,OAAO,MAAM;AAAC;AAEpB,IAAM,qBAAqB,CAAE,YAAY,UACxC,GAAI,UAAW,IAAK,MAAM,IAAK;AAGhC,SAAS,YAAa,EAAE,UAAU,WAAW,MAAM,mBAAmB,KAAK,GAAI;AAC9E,QAAM,UAAU;AAAA,IACf,CAAE,WAAY,OAAQ,gBAAiB,EAAE,aAAc,QAAS;AAAA,IAChE,CAAE,QAAS;AAAA,EACZ;AACA,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,mBAAoB;AAAA,IACvB;AAAA,IACA;AAAA,EACD,CAAE;AACF,QAAM,CAAE,cAAc,eAAgB,IAAI,SAAU,IA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,cAAe,MACd,iBAAkB,KAAM;AAAA,4BAEzB,SAAU,MACT,iBAAkB,KAAM;AAAA,4BAEzB,cAAe,MACd,iBAAkB,IAAK;AAAA,4BAExB,QAAS,MACR,iBAAkB,IAAK;AAAA,4BAExB,SAAU,MACT,qBAAsB,KAAM;AAAA,4BAG7B;AAAA,8BAAC;AAAA;AAAA,gCACA,eAAgB;AAAA,gCAChB,WAAU;AAAA,gCAER,gBAAM,SAAS,MAAM;AAAA;AAAA,4BACxB;AAAA;AAAA,0BA1CM,MAAM;AAAA,wBA2Cb,CACC;AAAA;AAAA,sBAjDI;AAAA,oBAkDP,CACC;AAAA;AAAA,gBACH;AAAA,gBACE,iBACD;AAAA,kBAAC;AAAA;AAAA,oBACA,QAAS;AAAA,oBACT,WAAU;AAAA,oBACV,QAAS;AAAA,oBACT,QAAS;AAAA;AAAA,gBACV;AAAA;AAAA;AAAA,UAEF;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,uBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-visibility/constants.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactElement } from 'react';\nimport { __ } from '@wordpress/i18n';\nimport { desktop, tablet, mobile } from '@wordpress/icons';\n\n/**\n * The viewports for which block visibility can be controlled.\n */\nexport type BlockVisibilityViewport = 'desktop' | 'tablet' | 'mobile';\n\n/**\n * The choices for the block visibility.\n *\n * Duplicated in packages/editor/src/components/preview-dropdown/index.js (choices
|
|
5
|
-
"mappings": ";AACA,SAAS,UAAU;AACnB,SAAS,SAAS,QAAQ,cAAc;
|
|
4
|
+
"sourcesContent": ["import type { ReactElement } from 'react';\nimport { __ } from '@wordpress/i18n';\nimport { desktop, tablet, mobile } from '@wordpress/icons';\n\n/**\n * The viewports for which block visibility can be controlled.\n */\nexport type BlockVisibilityViewport = 'desktop' | 'tablet' | 'mobile';\n\n/**\n * The choices for the block visibility.\n *\n * Duplicated in packages/editor/src/components/preview-dropdown/index.js (choices\n * array), packages/edit-site/src/components/block-editor/viewport.js and\n * packages/boot/src/components/canvas/viewport.ts (VALID_VIEWPORTS). Update all\n * four when adding new viewport types.\n *\n * @todo create a single source of truth for the viewport types.\n */\nexport const BLOCK_VISIBILITY_VIEWPORTS = {\n\tdesktop: {\n\t\tlabel: __( 'Desktop' ),\n\t\ticon: desktop,\n\t\tkey: 'desktop',\n\t},\n\ttablet: {\n\t\tlabel: __( 'Tablet' ),\n\t\ticon: tablet,\n\t\tkey: 'tablet',\n\t},\n\tmobile: {\n\t\tlabel: __( 'Mobile' ),\n\t\ticon: mobile,\n\t\tkey: 'mobile',\n\t},\n} satisfies Record<\n\tBlockVisibilityViewport,\n\t{ label: string; icon: ReactElement; key: BlockVisibilityViewport }\n>;\n\nexport const BLOCK_VISIBILITY_VIEWPORT_ENTRIES = Object.entries(\n\tBLOCK_VISIBILITY_VIEWPORTS\n);\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,UAAU;AACnB,SAAS,SAAS,QAAQ,cAAc;AAiBjC,IAAM,6BAA6B;AAAA,EACzC,SAAS;AAAA,IACR,OAAO,GAAI,SAAU;AAAA,IACrB,MAAM;AAAA,IACN,KAAK;AAAA,EACN;AAAA,EACA,QAAQ;AAAA,IACP,OAAO,GAAI,QAAS;AAAA,IACpB,MAAM;AAAA,IACN,KAAK;AAAA,EACN;AAAA,EACA,QAAQ;AAAA,IACP,OAAO,GAAI,QAAS;AAAA,IACpB,MAAM;AAAA,IACN,KAAK;AAAA,EACN;AACD;AAKO,IAAM,oCAAoC,OAAO;AAAA,EACvD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
4
4
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
5
5
|
__experimentalUnitControl as UnitControl,
|
|
6
|
-
__experimentalInputControl as
|
|
6
|
+
__experimentalInputControl as WCInputControl,
|
|
7
7
|
__experimentalVStack as VStack,
|
|
8
8
|
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
9
9
|
__experimentalUseCustomUnits as useCustomUnits,
|
|
@@ -270,7 +270,7 @@ function GridControls({
|
|
|
270
270
|
panelId,
|
|
271
271
|
children: [
|
|
272
272
|
/* @__PURE__ */ jsx(FlexItem, { style: { width: "50%" }, children: /* @__PURE__ */ jsx(
|
|
273
|
-
|
|
273
|
+
WCInputControl,
|
|
274
274
|
{
|
|
275
275
|
label: __("Column span"),
|
|
276
276
|
type: "number",
|
|
@@ -290,7 +290,7 @@ function GridControls({
|
|
|
290
290
|
}
|
|
291
291
|
) }),
|
|
292
292
|
/* @__PURE__ */ jsx(FlexItem, { style: { width: "50%" }, children: /* @__PURE__ */ jsx(
|
|
293
|
-
|
|
293
|
+
WCInputControl,
|
|
294
294
|
{
|
|
295
295
|
label: __("Row span"),
|
|
296
296
|
type: "number",
|
|
@@ -326,7 +326,7 @@ function GridControls({
|
|
|
326
326
|
panelId,
|
|
327
327
|
children: [
|
|
328
328
|
/* @__PURE__ */ jsx(FlexItem, { style: { width: "50%" }, children: /* @__PURE__ */ jsx(
|
|
329
|
-
|
|
329
|
+
WCInputControl,
|
|
330
330
|
{
|
|
331
331
|
label: __("Column"),
|
|
332
332
|
type: "number",
|
|
@@ -355,7 +355,7 @@ function GridControls({
|
|
|
355
355
|
}
|
|
356
356
|
) }),
|
|
357
357
|
/* @__PURE__ */ jsx(FlexItem, { style: { width: "50%" }, children: /* @__PURE__ */ jsx(
|
|
358
|
-
|
|
358
|
+
WCInputControl,
|
|
359
359
|
{
|
|
360
360
|
label: __("Row"),
|
|
361
361
|
type: "number",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/child-layout-control/index.js"],
|
|
4
|
-
"sourcesContent": ["import {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalInputControl as InputControl,\n\t__experimentalVStack as VStack,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useGetNumberOfBlocksBeforeCell } from '../grid/use-get-number-of-blocks-before-cell';\nimport { store as blockEditorStore } from '../../store';\nimport { useSettings } from '../use-settings';\n\n// These are the serialized `selfStretch` values. `max` used to be called\n// \"Fixed\" in the UI, but was renamed and replaced by `fixedNoShrink`.\nconst FLEX_CHILD_LAYOUT_VALUES = {\n\tfit: 'fit',\n\tgrow: 'fill',\n\tmax: 'fixed',\n\tfixed: 'fixedNoShrink',\n};\n\nconst FLEX_SIZE_VALUES = [\n\tFLEX_CHILD_LAYOUT_VALUES.max,\n\tFLEX_CHILD_LAYOUT_VALUES.fixed,\n];\n\nfunction isFlexSizeValue( value ) {\n\treturn FLEX_SIZE_VALUES.includes( value );\n}\n\nfunction maxSizeLabel( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal'\n\t\t? _x( 'Max', 'Block with maximum width in flex layout' )\n\t\t: _x( 'Max', 'Block with maximum height in flex layout' );\n}\n\nfunction helpText( flexControlValue, parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\n\tif ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.grow ) {\n\t\treturn __( 'Stretch to fill available space.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.max &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a maximum width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.max ) {\n\t\treturn __( 'Specify a maximum height.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a fixed width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\treturn __( 'Specify a fixed height.' );\n\t}\n\treturn __( 'Fit contents.' );\n}\n\n/**\n * Form to edit the child layout value.\n *\n * @param {Object} props Props.\n * @param {Object} props.value The child layout value.\n * @param {Function} props.onChange Function to update the child layout value.\n * @param {Object} props.parentLayout The parent layout value.\n *\n * @param {boolean} props.isShownByDefault Whether the control is shown by default.\n * @param {string} props.panelId The panel ID.\n * @param {boolean} props.showGridSpanDefaults Whether unset grid span controls should show default values.\n * @return {Element} child layout edit element.\n */\nexport default function ChildLayoutControl( {\n\tvalue: childLayout = {},\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults = true,\n} ) {\n\tconst {\n\t\ttype: parentType,\n\t\tdefault: { type: defaultParentType = 'default' } = {},\n\t} = parentLayout ?? {};\n\tconst parentLayoutType = parentType || defaultParentType;\n\n\tif ( parentLayoutType === 'flex' ) {\n\t\treturn (\n\t\t\t<FlexControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t/>\n\t\t);\n\t} else if ( parentLayoutType === 'grid' ) {\n\t\treturn (\n\t\t\t<GridControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t\tshowGridSpanDefaults={ showGridSpanDefaults }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n\nfunction FlexControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n} ) {\n\tconst { selfStretch, flexSize } = childLayout;\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\tconst flexControlValue = selfStretch || FLEX_CHILD_LAYOUT_VALUES.fit;\n\tconst hasFlexSizeValue = isFlexSizeValue( flexControlValue );\n\tconst hasFlexValue = () => !! selfStretch;\n\tconst flexResetLabel =\n\t\torientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n\tconst [ availableUnits ] = useSettings( 'spacing.units' );\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: availableUnits || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vh',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst resetFlex = () => {\n\t\tonChange( {\n\t\t\tselfStretch: undefined,\n\t\t\tflexSize: undefined,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isFlexSizeValue( selfStretch ) && ! flexSize ) {\n\t\t\tonChange( {\n\t\t\t\t...childLayout,\n\t\t\t\tselfStretch: FLEX_CHILD_LAYOUT_VALUES.fit,\n\t\t\t} );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn (\n\t\t<VStack\n\t\t\tas={ ToolsPanelItem }\n\t\t\tspacing={ 2 }\n\t\t\thasValue={ hasFlexValue }\n\t\t\tlabel={ flexResetLabel }\n\t\t\tonDeselect={ resetFlex }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<ToggleGroupControl\n\t\t\t\tlabel={ childLayoutOrientation( parentLayout ) }\n\t\t\t\tvalue={ flexControlValue }\n\t\t\t\thelp={ helpText( flexControlValue, parentLayout ) }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newFlexSize = isFlexSizeValue( value )\n\t\t\t\t\t\t? flexSize\n\t\t\t\t\t\t: null;\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\tselfStretch: value,\n\t\t\t\t\t\tflexSize: newFlexSize,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tisBlock\n\t\t\t>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fit',\n\t\t\t\t\t\t'Intrinsic block width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Grow',\n\t\t\t\t\t\t'Block with expanding width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tlabel={ maxSizeLabel( parentLayout ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fixed',\n\t\t\t\t\t\t'Block with fixed width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToggleGroupControl>\n\t\t\t{ hasFlexSizeValue && (\n\t\t\t\t<UnitControl\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\tselfStretch: flexControlValue,\n\t\t\t\t\t\t\tflexSize: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ flexSize }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tlabel={ flexResetLabel }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport function childLayoutOrientation( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n}\n\nfunction GridControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults,\n} ) {\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = childLayout;\n\tconst { columnCount, rowCount } = parentLayout ?? {};\n\tconst rootClientId = useSelect( ( select ) =>\n\t\tselect( blockEditorStore ).getBlockRootClientId( panelId )\n\t);\n\tconst { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(\n\t\trootClientId,\n\t\tcolumnCount || 3\n\t);\n\tconst hasStartValue = () => !! columnStart || !! rowStart;\n\tconst hasSpanValue = () => !! columnSpan || !! rowSpan;\n\tconst resetGridStarts = () => {\n\t\tonChange( {\n\t\t\tcolumnStart: undefined,\n\t\t\trowStart: undefined,\n\t\t} );\n\t};\n\tconst resetGridSpans = () => {\n\t\tonChange( {\n\t\t\tcolumnSpan: undefined,\n\t\t\trowSpan: undefined,\n\t\t} );\n\t};\n\n\t// Calculate max column span based on current position and grid width\n\tconst maxColumnSpan = columnCount\n\t\t? columnCount - ( columnStart ?? 1 ) + 1\n\t\t: undefined;\n\n\t// Calculate max row span based on current position and grid height\n\tconst maxRowSpan =\n\t\twindow.__experimentalEnableGridInteractivity && rowCount\n\t\t\t? rowCount - ( rowStart ?? 1 ) + 1\n\t\t\t: undefined;\n\tconst columnSpanValue =\n\t\tcolumnSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\tconst rowSpanValue = rowSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\n\treturn (\n\t\t<>\n\t\t\t<Flex\n\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\thasValue={ hasSpanValue }\n\t\t\t\tlabel={ __( 'Grid span' ) }\n\t\t\t\tonDeselect={ resetGridSpans }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\tlabel={ __( 'Column span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\tconst newColumnSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxColumnSpan\n\t\t\t\t\t\t\t\t? Math.min( newColumnSpan, maxColumnSpan )\n\t\t\t\t\t\t\t\t: newColumnSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\tcolumnSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ columnSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxColumnSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\tlabel={ __( 'Row span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tconst newRowSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxRowSpan\n\t\t\t\t\t\t\t\t? Math.min( newRowSpan, maxRowSpan )\n\t\t\t\t\t\t\t\t: newRowSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\trowSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ rowSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxRowSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t{ window.__experimentalEnableGridInteractivity && (\n\t\t\t\t// Use Flex with an explicit width on the FlexItem instead of HStack to\n\t\t\t\t// work around an issue in webkit where inputs with a max attribute are\n\t\t\t\t// sized incorrectly.\n\t\t\t\t<Flex\n\t\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\t\thasValue={ hasStartValue }\n\t\t\t\t\tlabel={ __( 'Grid placement' ) }\n\t\t\t\t\tonDeselect={ resetGridStarts }\n\t\t\t\t\tisShownByDefault={ false }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<InputControl\n\t\t\t\t\t\t\tlabel={ __( 'Column' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newColumnStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart: newColumnStart,\n\t\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tnewColumnStart,\n\t\t\t\t\t\t\t\t\t\trowStart\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\tvalue={ columnStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\tcolumnCount\n\t\t\t\t\t\t\t\t\t? columnCount - ( columnSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<InputControl\n\t\t\t\t\t\t\tlabel={ __( 'Row' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newRowStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\trowStart: newRowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\t\tnewRowStart\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\tvalue={ rowStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\trowCount\n\t\t\t\t\t\t\t\t\t? rowCount - ( rowSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
4
|
+
"sourcesContent": ["import {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalInputControl as WCInputControl,\n\t__experimentalVStack as VStack,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useGetNumberOfBlocksBeforeCell } from '../grid/use-get-number-of-blocks-before-cell';\nimport { store as blockEditorStore } from '../../store';\nimport { useSettings } from '../use-settings';\n\n// These are the serialized `selfStretch` values. `max` used to be called\n// \"Fixed\" in the UI, but was renamed and replaced by `fixedNoShrink`.\nconst FLEX_CHILD_LAYOUT_VALUES = {\n\tfit: 'fit',\n\tgrow: 'fill',\n\tmax: 'fixed',\n\tfixed: 'fixedNoShrink',\n};\n\nconst FLEX_SIZE_VALUES = [\n\tFLEX_CHILD_LAYOUT_VALUES.max,\n\tFLEX_CHILD_LAYOUT_VALUES.fixed,\n];\n\nfunction isFlexSizeValue( value ) {\n\treturn FLEX_SIZE_VALUES.includes( value );\n}\n\nfunction maxSizeLabel( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal'\n\t\t? _x( 'Max', 'Block with maximum width in flex layout' )\n\t\t: _x( 'Max', 'Block with maximum height in flex layout' );\n}\n\nfunction helpText( flexControlValue, parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\n\tif ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.grow ) {\n\t\treturn __( 'Stretch to fill available space.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.max &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a maximum width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.max ) {\n\t\treturn __( 'Specify a maximum height.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a fixed width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\treturn __( 'Specify a fixed height.' );\n\t}\n\treturn __( 'Fit contents.' );\n}\n\n/**\n * Form to edit the child layout value.\n *\n * @param {Object} props Props.\n * @param {Object} props.value The child layout value.\n * @param {Function} props.onChange Function to update the child layout value.\n * @param {Object} props.parentLayout The parent layout value.\n *\n * @param {boolean} props.isShownByDefault Whether the control is shown by default.\n * @param {string} props.panelId The panel ID.\n * @param {boolean} props.showGridSpanDefaults Whether unset grid span controls should show default values.\n * @return {Element} child layout edit element.\n */\nexport default function ChildLayoutControl( {\n\tvalue: childLayout = {},\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults = true,\n} ) {\n\tconst {\n\t\ttype: parentType,\n\t\tdefault: { type: defaultParentType = 'default' } = {},\n\t} = parentLayout ?? {};\n\tconst parentLayoutType = parentType || defaultParentType;\n\n\tif ( parentLayoutType === 'flex' ) {\n\t\treturn (\n\t\t\t<FlexControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t/>\n\t\t);\n\t} else if ( parentLayoutType === 'grid' ) {\n\t\treturn (\n\t\t\t<GridControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t\tshowGridSpanDefaults={ showGridSpanDefaults }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n\nfunction FlexControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n} ) {\n\tconst { selfStretch, flexSize } = childLayout;\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\tconst flexControlValue = selfStretch || FLEX_CHILD_LAYOUT_VALUES.fit;\n\tconst hasFlexSizeValue = isFlexSizeValue( flexControlValue );\n\tconst hasFlexValue = () => !! selfStretch;\n\tconst flexResetLabel =\n\t\torientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n\tconst [ availableUnits ] = useSettings( 'spacing.units' );\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: availableUnits || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vh',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst resetFlex = () => {\n\t\tonChange( {\n\t\t\tselfStretch: undefined,\n\t\t\tflexSize: undefined,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isFlexSizeValue( selfStretch ) && ! flexSize ) {\n\t\t\tonChange( {\n\t\t\t\t...childLayout,\n\t\t\t\tselfStretch: FLEX_CHILD_LAYOUT_VALUES.fit,\n\t\t\t} );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn (\n\t\t<VStack\n\t\t\tas={ ToolsPanelItem }\n\t\t\tspacing={ 2 }\n\t\t\thasValue={ hasFlexValue }\n\t\t\tlabel={ flexResetLabel }\n\t\t\tonDeselect={ resetFlex }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<ToggleGroupControl\n\t\t\t\tlabel={ childLayoutOrientation( parentLayout ) }\n\t\t\t\tvalue={ flexControlValue }\n\t\t\t\thelp={ helpText( flexControlValue, parentLayout ) }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newFlexSize = isFlexSizeValue( value )\n\t\t\t\t\t\t? flexSize\n\t\t\t\t\t\t: null;\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\tselfStretch: value,\n\t\t\t\t\t\tflexSize: newFlexSize,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tisBlock\n\t\t\t>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fit',\n\t\t\t\t\t\t'Intrinsic block width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Grow',\n\t\t\t\t\t\t'Block with expanding width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tlabel={ maxSizeLabel( parentLayout ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fixed',\n\t\t\t\t\t\t'Block with fixed width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToggleGroupControl>\n\t\t\t{ hasFlexSizeValue && (\n\t\t\t\t<UnitControl\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\tselfStretch: flexControlValue,\n\t\t\t\t\t\t\tflexSize: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ flexSize }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tlabel={ flexResetLabel }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport function childLayoutOrientation( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n}\n\nfunction GridControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults,\n} ) {\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = childLayout;\n\tconst { columnCount, rowCount } = parentLayout ?? {};\n\tconst rootClientId = useSelect( ( select ) =>\n\t\tselect( blockEditorStore ).getBlockRootClientId( panelId )\n\t);\n\tconst { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(\n\t\trootClientId,\n\t\tcolumnCount || 3\n\t);\n\tconst hasStartValue = () => !! columnStart || !! rowStart;\n\tconst hasSpanValue = () => !! columnSpan || !! rowSpan;\n\tconst resetGridStarts = () => {\n\t\tonChange( {\n\t\t\tcolumnStart: undefined,\n\t\t\trowStart: undefined,\n\t\t} );\n\t};\n\tconst resetGridSpans = () => {\n\t\tonChange( {\n\t\t\tcolumnSpan: undefined,\n\t\t\trowSpan: undefined,\n\t\t} );\n\t};\n\n\t// Calculate max column span based on current position and grid width\n\tconst maxColumnSpan = columnCount\n\t\t? columnCount - ( columnStart ?? 1 ) + 1\n\t\t: undefined;\n\n\t// Calculate max row span based on current position and grid height\n\tconst maxRowSpan =\n\t\twindow.__experimentalEnableGridInteractivity && rowCount\n\t\t\t? rowCount - ( rowStart ?? 1 ) + 1\n\t\t\t: undefined;\n\tconst columnSpanValue =\n\t\tcolumnSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\tconst rowSpanValue = rowSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\n\treturn (\n\t\t<>\n\t\t\t<Flex\n\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\thasValue={ hasSpanValue }\n\t\t\t\tlabel={ __( 'Grid span' ) }\n\t\t\t\tonDeselect={ resetGridSpans }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\tlabel={ __( 'Column span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\tconst newColumnSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxColumnSpan\n\t\t\t\t\t\t\t\t? Math.min( newColumnSpan, maxColumnSpan )\n\t\t\t\t\t\t\t\t: newColumnSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\tcolumnSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ columnSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxColumnSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\tlabel={ __( 'Row span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tconst newRowSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxRowSpan\n\t\t\t\t\t\t\t\t? Math.min( newRowSpan, maxRowSpan )\n\t\t\t\t\t\t\t\t: newRowSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\trowSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ rowSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxRowSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t{ window.__experimentalEnableGridInteractivity && (\n\t\t\t\t// Use Flex with an explicit width on the FlexItem instead of HStack to\n\t\t\t\t// work around an issue in webkit where inputs with a max attribute are\n\t\t\t\t// sized incorrectly.\n\t\t\t\t<Flex\n\t\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\t\thasValue={ hasStartValue }\n\t\t\t\t\tlabel={ __( 'Grid placement' ) }\n\t\t\t\t\tonDeselect={ resetGridStarts }\n\t\t\t\t\tisShownByDefault={ false }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\t\tlabel={ __( 'Column' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newColumnStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart: newColumnStart,\n\t\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tnewColumnStart,\n\t\t\t\t\t\t\t\t\t\trowStart\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\tvalue={ columnStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\tcolumnCount\n\t\t\t\t\t\t\t\t\t? columnCount - ( columnSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\t\tlabel={ __( 'Row' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newRowStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\trowStart: newRowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\t\tnewRowStart\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\tvalue={ rowStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\trowCount\n\t\t\t\t\t\t\t\t\t? rowCount - ( rowSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],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"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/block-editor/src/components/colors/with-colors.js
|
|
2
|
-
import { useMemo,
|
|
2
|
+
import { useMemo, useRef } from "@wordpress/element";
|
|
3
3
|
import { compose, createHigherOrderComponent } from "@wordpress/compose";
|
|
4
4
|
import { kebabCase } from "@wordpress/kebab-case";
|
|
5
5
|
import {
|
|
@@ -46,87 +46,71 @@ function createColorHOC(colorTypes, withColorPalette) {
|
|
|
46
46
|
return compose([
|
|
47
47
|
withColorPalette,
|
|
48
48
|
(WrappedComponent) => {
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const { colors } = this.props;
|
|
60
|
-
return getMostReadableColor(colors, colorValue);
|
|
61
|
-
}
|
|
62
|
-
createSetters() {
|
|
63
|
-
return Object.keys(colorMap).reduce(
|
|
64
|
-
(settersAccumulator, colorAttributeName) => {
|
|
65
|
-
const upperFirstColorAttributeName = upperFirst(colorAttributeName);
|
|
66
|
-
const customColorAttributeName = `custom${upperFirstColorAttributeName}`;
|
|
67
|
-
settersAccumulator[`set${upperFirstColorAttributeName}`] = this.createSetColor(
|
|
68
|
-
colorAttributeName,
|
|
69
|
-
customColorAttributeName
|
|
70
|
-
);
|
|
71
|
-
return settersAccumulator;
|
|
72
|
-
},
|
|
73
|
-
{}
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
createSetColor(colorAttributeName, customColorAttributeName) {
|
|
77
|
-
return (colorValue) => {
|
|
78
|
-
const colorObject = getColorObjectByColorValue(
|
|
79
|
-
this.props.colors,
|
|
80
|
-
colorValue
|
|
81
|
-
);
|
|
82
|
-
this.props.setAttributes({
|
|
83
|
-
[colorAttributeName]: colorObject && colorObject.slug ? colorObject.slug : void 0,
|
|
84
|
-
[customColorAttributeName]: colorObject && colorObject.slug ? void 0 : colorValue
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
static getDerivedStateFromProps({ attributes, colors }, previousState) {
|
|
89
|
-
return Object.entries(colorMap).reduce(
|
|
90
|
-
(newState, [colorAttributeName, colorContext]) => {
|
|
91
|
-
const colorObject = getColorObjectByAttributeValues(
|
|
92
|
-
colors,
|
|
93
|
-
attributes[colorAttributeName],
|
|
94
|
-
attributes[`custom${upperFirst(
|
|
49
|
+
return function WithColors(props) {
|
|
50
|
+
const { colors: _colors, ...passedProps } = props;
|
|
51
|
+
const { attributes, setAttributes } = passedProps;
|
|
52
|
+
const prevColorPropsRef = useRef(null);
|
|
53
|
+
const colorProps = useMemo(() => {
|
|
54
|
+
const prevColorProps = prevColorPropsRef.current;
|
|
55
|
+
const result = Object.fromEntries(
|
|
56
|
+
Object.entries(colorMap).flatMap(
|
|
57
|
+
([colorAttributeName, colorContext]) => {
|
|
58
|
+
const customAttr = `custom${upperFirst(
|
|
95
59
|
colorAttributeName
|
|
96
|
-
)}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
60
|
+
)}`;
|
|
61
|
+
const upperFirstColorAttributeName = upperFirst(colorAttributeName);
|
|
62
|
+
const colorObject = getColorObjectByAttributeValues(
|
|
63
|
+
_colors,
|
|
64
|
+
attributes[colorAttributeName],
|
|
65
|
+
attributes[customAttr]
|
|
66
|
+
);
|
|
67
|
+
const prevColorValue = prevColorProps?.[colorAttributeName];
|
|
68
|
+
const colorValue = prevColorValue?.color === colorObject.color && prevColorValue ? prevColorValue : {
|
|
104
69
|
...colorObject,
|
|
105
70
|
class: getColorClassName(
|
|
106
71
|
colorContext,
|
|
107
72
|
colorObject.slug
|
|
108
73
|
)
|
|
109
74
|
};
|
|
75
|
+
const setter = (newColorValue) => {
|
|
76
|
+
const resolvedColorObject = getColorObjectByColorValue(
|
|
77
|
+
_colors,
|
|
78
|
+
newColorValue
|
|
79
|
+
);
|
|
80
|
+
setAttributes({
|
|
81
|
+
[colorAttributeName]: resolvedColorObject?.slug || void 0,
|
|
82
|
+
[customAttr]: resolvedColorObject?.slug ? void 0 : newColorValue
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return [
|
|
86
|
+
[colorAttributeName, colorValue],
|
|
87
|
+
[
|
|
88
|
+
`set${upperFirstColorAttributeName}`,
|
|
89
|
+
setter
|
|
90
|
+
]
|
|
91
|
+
];
|
|
110
92
|
}
|
|
111
|
-
|
|
112
|
-
},
|
|
113
|
-
{}
|
|
93
|
+
)
|
|
114
94
|
);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
95
|
+
prevColorPropsRef.current = result;
|
|
96
|
+
return result;
|
|
97
|
+
}, [attributes, _colors, setAttributes]);
|
|
98
|
+
const colorUtils = useMemo(
|
|
99
|
+
() => ({
|
|
100
|
+
getMostReadableColor: (colorValue) => getMostReadableColor(_colors, colorValue)
|
|
101
|
+
}),
|
|
102
|
+
[_colors]
|
|
103
|
+
);
|
|
104
|
+
return /* @__PURE__ */ jsx(
|
|
105
|
+
WrappedComponent,
|
|
106
|
+
{
|
|
107
|
+
...{
|
|
108
|
+
...passedProps,
|
|
109
|
+
...colorProps,
|
|
110
|
+
colorUtils
|
|
127
111
|
}
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
}
|
|
113
|
+
);
|
|
130
114
|
};
|
|
131
115
|
}
|
|
132
116
|
]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/colors/with-colors.js"],
|
|
4
|
-
"sourcesContent": ["import { useMemo,
|
|
5
|
-
"mappings": ";AAAA,SAAS,SAAS,
|
|
4
|
+
"sourcesContent": ["import { useMemo, useRef } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\nimport { kebabCase } from '@wordpress/kebab-case';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport { useSettings } from '../use-settings';\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param {string} str The string whose first letter the function will capitalize.\n *\n * @return {string} Capitalized string.\n */\nconst upperFirst = ( [ firstLetter, ...rest ] ) =>\n\tfirstLetter.toUpperCase() + rest.join( '' );\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithCustomColorPalette( props ) {\n\t\t\t\treturn <WrappedComponent { ...props } colors={ colorsArray } />;\n\t\t\t},\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithEditorColorPalette( props ) {\n\t\t\t\tconst [ userPalette, themePalette, defaultPalette ] =\n\t\t\t\t\tuseSettings(\n\t\t\t\t\t\t'color.palette.custom',\n\t\t\t\t\t\t'color.palette.theme',\n\t\t\t\t\t\t'color.palette.default'\n\t\t\t\t\t);\n\t\t\t\tconst allColors = useMemo(\n\t\t\t\t\t() => [\n\t\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t\t],\n\t\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t\t);\n\t\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {Component} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = colorTypes.reduce( ( colorObject, colorType ) => {\n\t\treturn {\n\t\t\t...colorObject,\n\t\t\t...( typeof colorType === 'string'\n\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t: colorType ),\n\t\t};\n\t}, {} );\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn function WithColors( props ) {\n\t\t\t\tconst { colors: _colors, ...passedProps } = props;\n\t\t\t\tconst { attributes, setAttributes } = passedProps;\n\t\t\t\tconst prevColorPropsRef = useRef( null );\n\n\t\t\t\tconst colorProps = useMemo( () => {\n\t\t\t\t\tconst prevColorProps = prevColorPropsRef.current;\n\n\t\t\t\t\tconst result = Object.fromEntries(\n\t\t\t\t\t\tObject.entries( colorMap ).flatMap(\n\t\t\t\t\t\t\t( [ colorAttributeName, colorContext ] ) => {\n\t\t\t\t\t\t\t\tconst customAttr = `custom${ upperFirst(\n\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t) }`;\n\t\t\t\t\t\t\t\tconst upperFirstColorAttributeName =\n\t\t\t\t\t\t\t\t\tupperFirst( colorAttributeName );\n\n\t\t\t\t\t\t\t\tconst colorObject =\n\t\t\t\t\t\t\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\t\t\t_colors,\n\t\t\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\t\t\tattributes[ customAttr ]\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconst prevColorValue =\n\t\t\t\t\t\t\t\t\tprevColorProps?.[ colorAttributeName ];\n\t\t\t\t\t\t\t\tconst colorValue =\n\t\t\t\t\t\t\t\t\tprevColorValue?.color ===\n\t\t\t\t\t\t\t\t\t\tcolorObject.color && prevColorValue\n\t\t\t\t\t\t\t\t\t\t? prevColorValue\n\t\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t };\n\n\t\t\t\t\t\t\t\tconst setter = ( newColorValue ) => {\n\t\t\t\t\t\t\t\t\tconst resolvedColorObject =\n\t\t\t\t\t\t\t\t\t\tgetColorObjectByColorValue(\n\t\t\t\t\t\t\t\t\t\t\t_colors,\n\t\t\t\t\t\t\t\t\t\t\tnewColorValue\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\t\t\t\tresolvedColorObject?.slug ||\n\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\t[ customAttr ]:\n\t\t\t\t\t\t\t\t\t\t\tresolvedColorObject?.slug\n\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t: newColorValue,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t\t[ colorAttributeName, colorValue ],\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`,\n\t\t\t\t\t\t\t\t\t\tsetter,\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\tprevColorPropsRef.current = result;\n\t\t\t\t\treturn result;\n\t\t\t\t}, [ attributes, _colors, setAttributes ] );\n\n\t\t\t\tconst colorUtils = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\tgetMostReadableColor: ( colorValue ) =>\n\t\t\t\t\t\t\tgetMostReadableColor( _colors, colorValue ),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ _colors ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t...passedProps,\n\t\t\t\t\t\t\t...colorProps,\n\t\t\t\t\t\t\tcolorUtils,\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,SAAS,cAAc;AAChC,SAAS,SAAS,kCAAkC;AACpD,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAwBjB;AAfX,IAAM,aAAa,CAAE,CAAE,aAAgB,OAAK,MAC3C,YAAY,YAAY,IAAI,KAAK,KAAM,EAAG;AAU3C,IAAM,yBAAyB,CAAE,gBAChC;AAAA,EACC,CAAE,qBACD,SAAS,uBAAwB,OAAQ;AACxC,WAAO,oBAAC,oBAAmB,GAAG,OAAQ,QAAS,aAAc;AAAA,EAC9D;AAAA,EACD;AACD;AAQD,IAAM,yBAAyB,MAC9B;AAAA,EACC,CAAE,qBACD,SAAS,uBAAwB,OAAQ;AACxC,UAAM,CAAE,aAAa,cAAc,cAAe,IACjD;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACD,UAAM,YAAY;AAAA,MACjB,MAAM;AAAA,QACL,GAAK,eAAe,CAAC;AAAA,QACrB,GAAK,gBAAgB,CAAC;AAAA,QACtB,GAAK,kBAAkB,CAAC;AAAA,MACzB;AAAA,MACA,CAAE,aAAa,cAAc,cAAe;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BACD,CAAE,UAAW,GACZ,qBAAqB,OAClB,SACA;AAAA,kBACL,CAAE;AAAA,gBACH;AAEA,uBAAO;AAAA,kBACN,CAAE,oBAAoB,UAAW;AAAA,kBACjC;AAAA,oBACC,MAAO,4BAA6B;AAAA,oBACpC;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAEA,4BAAkB,UAAU;AAC5B,iBAAO;AAAA,QACR,GAAG,CAAE,YAAY,SAAS,aAAc,CAAE;AAE1C,cAAM,aAAa;AAAA,UAClB,OAAQ;AAAA,YACP,sBAAsB,CAAE,eACvB,qBAAsB,SAAS,UAAW;AAAA,UAC5C;AAAA,UACA,CAAE,OAAQ;AAAA,QACX;AAEA,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,cACJ,GAAG;AAAA,cACH,GAAG;AAAA,cACH;AAAA,YACD;AAAA;AAAA,QACD;AAAA,MAEF;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAwBO,SAAS,sBAAuB,aAAc;AACpD,SAAO,IAAK,eAAgB;AAC3B,UAAM,mBAAmB,uBAAwB,WAAY;AAC7D,WAAO;AAAA,MACN,eAAgB,YAAY,gBAAiB;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACD;AA0Be,SAAR,cAAgC,YAAa;AACnD,QAAM,mBAAmB,uBAAuB;AAChD,SAAO;AAAA,IACN,eAAgB,YAAY,gBAAiB;AAAA,IAC7C;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import { SelectControl } from "@wordpress/components";
|
|
|
3
3
|
import { __, _x } from "@wordpress/i18n";
|
|
4
4
|
import { useSettings } from "../use-settings/index.mjs";
|
|
5
5
|
import { InheritanceToolsPanelItem } from "../global-styles/inheritance/index.mjs";
|
|
6
|
+
import { findAspectRatioOption } from "./utils.mjs";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
function AspectRatioTool({
|
|
8
9
|
panelId,
|
|
@@ -17,7 +18,6 @@ function AspectRatioTool({
|
|
|
17
18
|
isInherited,
|
|
18
19
|
hasLocalOverride
|
|
19
20
|
}) {
|
|
20
|
-
const displayValue = value ?? "auto";
|
|
21
21
|
const [defaultRatios, themeRatios, showDefaultRatios] = useSettings(
|
|
22
22
|
"dimensions.aspectRatios.default",
|
|
23
23
|
"dimensions.aspectRatios.theme",
|
|
@@ -48,6 +48,8 @@ function AspectRatioTool({
|
|
|
48
48
|
hidden: true
|
|
49
49
|
}
|
|
50
50
|
];
|
|
51
|
+
const resolvedOptions = options ?? aspectRatioOptions;
|
|
52
|
+
const displayValue = value === void 0 || value === null || value === "auto" ? "auto" : findAspectRatioOption(value, resolvedOptions)?.value ?? "custom";
|
|
51
53
|
return /* @__PURE__ */ jsx(
|
|
52
54
|
InheritanceToolsPanelItem,
|
|
53
55
|
{
|
|
@@ -64,7 +66,7 @@ function AspectRatioTool({
|
|
|
64
66
|
{
|
|
65
67
|
label: __("Aspect ratio"),
|
|
66
68
|
value: displayValue,
|
|
67
|
-
options:
|
|
69
|
+
options: resolvedOptions,
|
|
68
70
|
onChange
|
|
69
71
|
}
|
|
70
72
|
)
|