@wordpress/block-editor 15.8.1-next.dc3f6d3c1.0 → 15.9.1-next.6deb34194.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +12 -0
- package/build/components/block-alignment-matrix-control/index.js +1 -8
- package/build/components/block-alignment-matrix-control/index.js.map +2 -2
- package/build/components/block-bindings/attribute-control.js +172 -0
- package/build/components/block-bindings/attribute-control.js.map +7 -0
- package/build/components/block-bindings/index.js +47 -0
- package/build/components/block-bindings/index.js.map +7 -0
- package/build/components/block-bindings/source-fields-list.js +135 -0
- package/build/components/block-bindings/source-fields-list.js.map +7 -0
- package/build/components/block-bindings/use-block-bindings-utils.js +66 -0
- package/build/components/block-bindings/use-block-bindings-utils.js.map +7 -0
- package/build/components/block-edit/edit.js +1 -3
- package/build/components/block-edit/edit.js.map +2 -2
- package/build/components/block-list/index.js +2 -1
- package/build/components/block-list/index.js.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build/components/block-lock/modal.js +5 -5
- package/build/components/block-lock/modal.js.map +2 -2
- package/build/components/block-lock/use-block-lock.js +10 -13
- package/build/components/block-lock/use-block-lock.js.map +2 -2
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +2 -2
- package/build/components/block-styles/preview-panel.js +3 -5
- package/build/components/block-styles/preview-panel.js.map +2 -2
- package/build/components/block-styles/use-styles-for-block.js +2 -2
- package/build/components/block-styles/use-styles-for-block.js.map +2 -2
- package/build/components/block-toolbar/index.js +1 -8
- package/build/components/block-toolbar/index.js.map +3 -3
- package/build/components/block-tools/index.js +56 -45
- package/build/components/block-tools/index.js.map +3 -3
- package/build/components/block-visibility/toolbar.js +1 -1
- package/build/components/block-visibility/toolbar.js.map +1 -1
- package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
- package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build/components/content-only-controls/index.js +202 -44
- package/build/components/content-only-controls/index.js.map +3 -3
- package/build/components/content-only-controls/link/index.js +92 -103
- package/build/components/content-only-controls/link/index.js.map +3 -3
- package/build/components/content-only-controls/media/index.js +134 -134
- package/build/components/content-only-controls/media/index.js.map +3 -3
- package/build/components/content-only-controls/rich-text/index.js +66 -74
- package/build/components/content-only-controls/rich-text/index.js.map +3 -3
- package/build/components/dimensions-tool/width-height-tool.js +4 -16
- package/build/components/dimensions-tool/width-height-tool.js.map +3 -3
- package/build/components/font-family/index.js +1 -15
- package/build/components/font-family/index.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +35 -2
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +1 -2
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/image-editor/cropper.js +3 -34
- package/build/components/image-editor/cropper.js.map +3 -3
- package/build/components/image-editor/index.js +9 -3
- package/build/components/image-editor/index.js.map +2 -2
- package/build/components/image-editor/use-transform-image.js +62 -32
- package/build/components/image-editor/use-transform-image.js.map +2 -2
- package/build/components/image-editor/zoom-dropdown.js +2 -2
- package/build/components/image-editor/zoom-dropdown.js.map +2 -2
- package/build/components/index.js +10 -3
- package/build/components/index.js.map +2 -2
- package/build/components/inserter-draggable-blocks/index.js +8 -4
- package/build/components/inserter-draggable-blocks/index.js.map +2 -2
- package/build/components/inspector-controls-tabs/content-tab.js +3 -2
- package/build/components/inspector-controls-tabs/content-tab.js.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build/components/link-control/index.js +15 -7
- package/build/components/link-control/index.js.map +2 -2
- package/build/components/list-view/block-select-button.js +3 -11
- package/build/components/list-view/block-select-button.js.map +2 -2
- package/build/components/list-view/block.js +9 -7
- package/build/components/list-view/block.js.map +2 -2
- package/build/components/media-placeholder/index.js +17 -4
- package/build/components/media-placeholder/index.js.map +2 -2
- package/build/components/media-placeholder/utils.js +60 -0
- package/build/components/media-placeholder/utils.js.map +7 -0
- package/build/components/media-replace-flow/index.js +20 -3
- package/build/components/media-replace-flow/index.js.map +2 -2
- package/build/components/tool-selector/index.js +46 -0
- package/build/components/tool-selector/index.js.map +7 -0
- package/build/components/use-block-commands/index.js +1 -1
- package/build/components/use-block-commands/index.js.map +2 -2
- package/build/components/use-block-drop-zone/index.js +1 -5
- package/build/components/use-block-drop-zone/index.js.map +2 -2
- package/build/hooks/block-bindings.js +22 -260
- package/build/hooks/block-bindings.js.map +3 -3
- package/build/hooks/dimensions.js +3 -3
- package/build/hooks/dimensions.js.map +2 -2
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/utils.js +5 -1
- package/build/hooks/utils.js.map +2 -2
- package/build/layouts/grid.js +23 -28
- package/build/layouts/grid.js.map +2 -2
- package/build/store/private-selectors.js +43 -3
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/reducer.js +2 -1
- package/build/store/reducer.js.map +2 -2
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +2 -2
- package/build/utils/block-bindings.js +2 -44
- package/build/utils/block-bindings.js.map +3 -3
- package/build/utils/index.js +2 -5
- package/build/utils/index.js.map +2 -2
- package/build-module/components/block-alignment-matrix-control/index.js +1 -8
- package/build-module/components/block-alignment-matrix-control/index.js.map +2 -2
- package/build-module/components/block-bindings/attribute-control.js +150 -0
- package/build-module/components/block-bindings/attribute-control.js.map +7 -0
- package/build-module/components/block-bindings/index.js +10 -0
- package/build-module/components/block-bindings/index.js.map +7 -0
- package/build-module/components/block-bindings/source-fields-list.js +104 -0
- package/build-module/components/block-bindings/source-fields-list.js.map +7 -0
- package/build-module/components/block-bindings/use-block-bindings-utils.js +45 -0
- package/build-module/components/block-bindings/use-block-bindings-utils.js.map +7 -0
- package/build-module/components/block-edit/edit.js +1 -3
- package/build-module/components/block-edit/edit.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -1
- package/build-module/components/block-list/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build-module/components/block-lock/modal.js +5 -5
- package/build-module/components/block-lock/modal.js.map +2 -2
- package/build-module/components/block-lock/use-block-lock.js +10 -13
- package/build-module/components/block-lock/use-block-lock.js.map +2 -2
- package/build-module/components/block-settings-menu-controls/index.js +1 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
- package/build-module/components/block-styles/preview-panel.js +3 -5
- package/build-module/components/block-styles/preview-panel.js.map +2 -2
- package/build-module/components/block-styles/use-styles-for-block.js +2 -2
- package/build-module/components/block-styles/use-styles-for-block.js.map +2 -2
- package/build-module/components/block-toolbar/index.js +1 -8
- package/build-module/components/block-toolbar/index.js.map +2 -2
- package/build-module/components/block-tools/index.js +56 -45
- package/build-module/components/block-tools/index.js.map +2 -2
- package/build-module/components/block-visibility/toolbar.js +1 -1
- package/build-module/components/block-visibility/toolbar.js.map +1 -1
- package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
- package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build-module/components/content-only-controls/index.js +206 -46
- package/build-module/components/content-only-controls/index.js.map +2 -2
- package/build-module/components/content-only-controls/link/index.js +92 -104
- package/build-module/components/content-only-controls/link/index.js.map +2 -2
- package/build-module/components/content-only-controls/media/index.js +134 -135
- package/build-module/components/content-only-controls/media/index.js.map +2 -2
- package/build-module/components/content-only-controls/rich-text/index.js +68 -81
- package/build-module/components/content-only-controls/rich-text/index.js.map +2 -2
- package/build-module/components/dimensions-tool/width-height-tool.js +4 -6
- package/build-module/components/dimensions-tool/width-height-tool.js.map +2 -2
- package/build-module/components/font-family/index.js +1 -15
- package/build-module/components/font-family/index.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +35 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +1 -2
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/image-editor/cropper.js +3 -34
- package/build-module/components/image-editor/cropper.js.map +2 -2
- package/build-module/components/image-editor/index.js +9 -3
- package/build-module/components/image-editor/index.js.map +2 -2
- package/build-module/components/image-editor/use-transform-image.js +63 -33
- package/build-module/components/image-editor/use-transform-image.js.map +2 -2
- package/build-module/components/image-editor/zoom-dropdown.js +2 -2
- package/build-module/components/image-editor/zoom-dropdown.js.map +2 -2
- package/build-module/components/index.js +74 -66
- package/build-module/components/index.js.map +2 -2
- package/build-module/components/inserter-draggable-blocks/index.js +8 -4
- package/build-module/components/inserter-draggable-blocks/index.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/content-tab.js +3 -2
- package/build-module/components/inspector-controls-tabs/content-tab.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build-module/components/link-control/index.js +16 -8
- package/build-module/components/link-control/index.js.map +2 -2
- package/build-module/components/list-view/block-select-button.js +3 -11
- package/build-module/components/list-view/block-select-button.js.map +2 -2
- package/build-module/components/list-view/block.js +9 -7
- package/build-module/components/list-view/block.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +18 -5
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-placeholder/utils.js +35 -0
- package/build-module/components/media-placeholder/utils.js.map +7 -0
- package/build-module/components/media-replace-flow/index.js +20 -3
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/tool-selector/index.js +15 -0
- package/build-module/components/tool-selector/index.js.map +7 -0
- package/build-module/components/use-block-commands/index.js +1 -1
- package/build-module/components/use-block-commands/index.js.map +2 -2
- package/build-module/components/use-block-drop-zone/index.js +1 -5
- package/build-module/components/use-block-drop-zone/index.js.map +2 -2
- package/build-module/hooks/block-bindings.js +27 -270
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/dimensions.js +3 -3
- package/build-module/hooks/dimensions.js.map +2 -2
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/utils.js +5 -1
- package/build-module/hooks/utils.js.map +2 -2
- package/build-module/layouts/grid.js +23 -28
- package/build-module/layouts/grid.js.map +2 -2
- package/build-module/store/private-selectors.js +39 -3
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/reducer.js +2 -1
- package/build-module/store/reducer.js.map +2 -2
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/utils/block-bindings.js +1 -42
- package/build-module/utils/block-bindings.js.map +2 -2
- package/build-module/utils/index.js +1 -3
- package/build-module/utils/index.js.map +2 -2
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +20 -11
- package/build-style/style.css +20 -11
- package/package.json +39 -39
- package/src/components/block-alignment-matrix-control/index.js +1 -5
- package/src/components/block-bindings/attribute-control.js +174 -0
- package/src/components/block-bindings/index.js +6 -0
- package/src/components/block-bindings/source-fields-list.js +130 -0
- package/src/components/block-bindings/use-block-bindings-utils.js +156 -0
- package/src/components/block-edit/edit.js +1 -3
- package/src/components/block-list/content.scss +5 -0
- package/src/components/block-list/index.js +3 -1
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
- package/src/components/block-lock/modal.js +6 -5
- package/src/components/block-lock/use-block-lock.js +10 -14
- package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
- package/src/components/block-settings-menu-controls/index.js +1 -1
- package/src/components/block-styles/preview-panel.js +3 -5
- package/src/components/block-styles/use-styles-for-block.js +2 -2
- package/src/components/block-toolbar/index.js +1 -6
- package/src/components/block-toolbar/style.scss +6 -6
- package/src/components/block-tools/index.js +15 -2
- package/src/components/block-tools/style.scss +4 -0
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
- package/src/components/content-only-controls/index.js +289 -50
- package/src/components/content-only-controls/link/index.js +62 -57
- package/src/components/content-only-controls/media/index.js +177 -156
- package/src/components/content-only-controls/rich-text/index.js +31 -44
- package/src/components/content-only-controls/styles.scss +10 -1
- package/src/components/dimensions-tool/width-height-tool.js +6 -13
- package/src/components/font-family/README.md +0 -9
- package/src/components/font-family/index.js +1 -16
- package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
- package/src/components/global-styles/dimensions-panel.js +36 -0
- package/src/components/global-styles/hooks.js +1 -1
- package/src/components/global-styles/typography-panel.js +0 -1
- package/src/components/image-editor/cropper.js +3 -32
- package/src/components/image-editor/index.js +34 -29
- package/src/components/image-editor/use-transform-image.js +80 -34
- package/src/components/image-editor/zoom-dropdown.js +2 -2
- package/src/components/index.js +9 -1
- package/src/components/inserter/style.scss +1 -1
- package/src/components/inserter-draggable-blocks/index.js +19 -8
- package/src/components/inspector-controls-tabs/content-tab.js +6 -2
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
- package/src/components/link-control/index.js +36 -12
- package/src/components/list-view/block-select-button.js +22 -30
- package/src/components/list-view/block.js +9 -7
- package/src/components/media-placeholder/index.js +20 -5
- package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
- package/src/components/media-placeholder/utils.js +65 -0
- package/src/components/media-replace-flow/index.js +22 -3
- package/src/components/tool-selector/index.js +19 -0
- package/src/components/use-block-commands/index.js +1 -1
- package/src/components/use-block-drop-zone/index.js +1 -5
- package/src/hooks/block-bindings.js +27 -347
- package/src/hooks/dimensions.js +8 -3
- package/src/hooks/metadata.js +1 -1
- package/src/hooks/test/metadata.js +1 -1
- package/src/hooks/utils.js +4 -0
- package/src/layouts/grid.js +40 -72
- package/src/layouts/test/grid.js +14 -0
- package/src/store/private-selectors.js +123 -6
- package/src/store/reducer.js +3 -0
- package/src/store/selectors.js +6 -4
- package/src/store/test/private-selectors.js +242 -0
- package/src/store/test/reducer.js +17 -7
- package/src/style.scss +0 -1
- package/src/utils/block-bindings.js +0 -157
- package/src/utils/index.js +0 -1
- package/tsconfig.json +2 -0
- package/build/components/block-toolbar/block-name-context.js +0 -30
- package/build/components/block-toolbar/block-name-context.js.map +0 -7
- package/build/components/content-only-controls/plain-text/index.js +0 -68
- package/build/components/content-only-controls/plain-text/index.js.map +0 -7
- package/build-module/components/block-toolbar/block-name-context.js +0 -9
- package/build-module/components/block-toolbar/block-name-context.js.map +0 -7
- package/build-module/components/content-only-controls/plain-text/index.js +0 -50
- package/build-module/components/content-only-controls/plain-text/index.js.map +0 -7
- package/src/components/block-toolbar/block-name-context.js +0 -9
- package/src/components/content-only-controls/plain-text/index.js +0 -49
- package/src/components/font-family/style.scss +0 -7
- /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
- /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/{utils → components/block-bindings}/test/use-block-bindings-utils.js +0 -0
- /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
- /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
package/src/layouts/test/grid.js
CHANGED
|
@@ -30,6 +30,20 @@ describe( 'getLayoutStyle', () => {
|
|
|
30
30
|
layoutDefinitions: undefined,
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
|
+
expect( result ).toBe( expected );
|
|
34
|
+
} );
|
|
35
|
+
it( 'should return `grid-template-columns` with max() function if both minimumColumnWidth and columnCount are provided', () => {
|
|
36
|
+
const expected = `.my-container { grid-template-columns: repeat(auto-fill, minmax(max(12rem, ( 100% - (1.2rem*2) ) / 3), 1fr)); container-type: inline-size; }`;
|
|
37
|
+
|
|
38
|
+
const result = grid.getLayoutStyle( {
|
|
39
|
+
selector: '.my-container',
|
|
40
|
+
layout: { minimumColumnWidth: '12rem', columnCount: 3 },
|
|
41
|
+
style: {},
|
|
42
|
+
blockName: 'test-block',
|
|
43
|
+
hasBlockGapSupport: false,
|
|
44
|
+
layoutDefinitions: undefined,
|
|
45
|
+
} );
|
|
46
|
+
|
|
33
47
|
expect( result ).toBe( expected );
|
|
34
48
|
} );
|
|
35
49
|
} );
|
|
@@ -518,20 +518,31 @@ export function isSectionBlock( state, clientId ) {
|
|
|
518
518
|
}
|
|
519
519
|
|
|
520
520
|
const blockName = getBlockName( state, clientId );
|
|
521
|
-
if (
|
|
522
|
-
blockName === 'core/block' ||
|
|
523
|
-
getTemplateLock( state, clientId ) === 'contentOnly'
|
|
524
|
-
) {
|
|
521
|
+
if ( blockName === 'core/block' ) {
|
|
525
522
|
return true;
|
|
526
523
|
}
|
|
527
524
|
|
|
528
525
|
const attributes = getBlockAttributes( state, clientId );
|
|
526
|
+
const isTemplatePart = blockName === 'core/template-part';
|
|
529
527
|
if (
|
|
530
|
-
attributes?.metadata?.patternName &&
|
|
528
|
+
( attributes?.metadata?.patternName || isTemplatePart ) &&
|
|
531
529
|
!! window?.__experimentalContentOnlyPatternInsertion
|
|
532
530
|
) {
|
|
533
531
|
return true;
|
|
534
532
|
}
|
|
533
|
+
|
|
534
|
+
// TemplateLock cascades to all inner parent blocks. Only the top-level
|
|
535
|
+
// block that's contentOnly templateLocked is the true contentLocker,
|
|
536
|
+
// all the others are mere imitators.
|
|
537
|
+
const hasContentOnlyTempateLock =
|
|
538
|
+
getTemplateLock( state, clientId ) === 'contentOnly';
|
|
539
|
+
const rootClientId = getBlockRootClientId( state, clientId );
|
|
540
|
+
const hasRootContentOnlyTemplateLock =
|
|
541
|
+
getTemplateLock( state, rootClientId ) === 'contentOnly';
|
|
542
|
+
if ( hasContentOnlyTempateLock && ! hasRootContentOnlyTemplateLock ) {
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
|
|
535
546
|
return false;
|
|
536
547
|
}
|
|
537
548
|
|
|
@@ -699,7 +710,7 @@ export function getInsertionPoint( state ) {
|
|
|
699
710
|
*/
|
|
700
711
|
export const isBlockHidden = ( state, clientId ) => {
|
|
701
712
|
const blockName = getBlockName( state, clientId );
|
|
702
|
-
if ( ! hasBlockSupport( state, blockName, '
|
|
713
|
+
if ( ! hasBlockSupport( state, blockName, 'visibility', true ) ) {
|
|
703
714
|
return false;
|
|
704
715
|
}
|
|
705
716
|
const attributes = state.blocks.attributes.get( clientId );
|
|
@@ -719,3 +730,109 @@ export const isBlockHidden = ( state, clientId ) => {
|
|
|
719
730
|
export function hasBlockSpotlight( state ) {
|
|
720
731
|
return !! state.hasBlockSpotlight || !! state.editedContentOnlySection;
|
|
721
732
|
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Returns whether a block is locked to prevent editing.
|
|
736
|
+
*
|
|
737
|
+
* This selector only reasons about block lock, not associated features
|
|
738
|
+
* like `blockEditingMode` that might prevent user modifications to a block.
|
|
739
|
+
* Currently there's also no way to prevent editing via `templateLock`.
|
|
740
|
+
*
|
|
741
|
+
* This distinction is important as this selector specifically drives the block lock UI
|
|
742
|
+
* that a user interacts with. `blockEditingModes` aren't included as a user can't change
|
|
743
|
+
* them.
|
|
744
|
+
*
|
|
745
|
+
* @param {Object} state Global application state.
|
|
746
|
+
* @param {string} clientId ClientId of the block.
|
|
747
|
+
*
|
|
748
|
+
* @return {boolean} Whether the block is currently locked.
|
|
749
|
+
*/
|
|
750
|
+
export function isEditLockedBlock( state, clientId ) {
|
|
751
|
+
const attributes = getBlockAttributes( state, clientId );
|
|
752
|
+
return !! attributes?.lock?.edit;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Returns whether a block is locked to prevent moving.
|
|
757
|
+
*
|
|
758
|
+
* This selector only reasons about templateLock and block lock, not associated features
|
|
759
|
+
* like `blockEditingMode` that might prevent user modifications to a block.
|
|
760
|
+
*
|
|
761
|
+
* This distinction is important as this selector specifically drives the block lock UI
|
|
762
|
+
* that a user interacts with. `blockEditingModes` are excluded as a user can't change
|
|
763
|
+
* them.
|
|
764
|
+
*
|
|
765
|
+
* @param {Object} state Global application state.
|
|
766
|
+
* @param {string} clientId ClientId of the block.
|
|
767
|
+
*
|
|
768
|
+
* @return {boolean} Whether the block is currently locked.
|
|
769
|
+
*/
|
|
770
|
+
export function isMoveLockedBlock( state, clientId ) {
|
|
771
|
+
const attributes = getBlockAttributes( state, clientId );
|
|
772
|
+
// If a block explicitly has `move` set to `false`, it turns off
|
|
773
|
+
// any locking that might be inherited from a parent.
|
|
774
|
+
if ( attributes?.lock?.move !== undefined ) {
|
|
775
|
+
return !! attributes?.lock?.move;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
const rootClientId = getBlockRootClientId( state, clientId );
|
|
779
|
+
const templateLock = getTemplateLock( state, rootClientId );
|
|
780
|
+
|
|
781
|
+
// While `contentOnly` templateLock does sometimes prevent moving, a user can't modify
|
|
782
|
+
// this, so don't include it in this function. See the `canMoveBlock` selector
|
|
783
|
+
// as an alternative.
|
|
784
|
+
return templateLock === 'all';
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Returns whether a block is locked to prevent removal.
|
|
789
|
+
*
|
|
790
|
+
* This selector only reasons about templateLock and block lock, not associated features
|
|
791
|
+
* like `blockEditingMode` that might prevent user modifications to a block.
|
|
792
|
+
*
|
|
793
|
+
* This distinction is important as this selector specifically drives the block lock UI
|
|
794
|
+
* that a user interacts with. `blockEditingModes` are excluded as a user can't change
|
|
795
|
+
* them.
|
|
796
|
+
*
|
|
797
|
+
* @param {Object} state Global application state.
|
|
798
|
+
* @param {string} clientId ClientId of the block.
|
|
799
|
+
*
|
|
800
|
+
* @return {boolean} Whether the block is currently locked.
|
|
801
|
+
*/
|
|
802
|
+
export function isRemoveLockedBlock( state, clientId ) {
|
|
803
|
+
const attributes = getBlockAttributes( state, clientId );
|
|
804
|
+
if ( attributes?.lock?.remove !== undefined ) {
|
|
805
|
+
return !! attributes?.lock?.remove;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const rootClientId = getBlockRootClientId( state, clientId );
|
|
809
|
+
const templateLock = getTemplateLock( state, rootClientId );
|
|
810
|
+
|
|
811
|
+
// While `contentOnly` templateLock does sometimes prevent removal, a user can't modify
|
|
812
|
+
// this, so don't include it in this function. See the `canRemoveBlock` selector
|
|
813
|
+
// as an alternative.
|
|
814
|
+
return templateLock === 'all' || templateLock === 'insert';
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Returns whether a block is locked.
|
|
819
|
+
*
|
|
820
|
+
* This selector only reasons about templateLock and block lock, not associated features
|
|
821
|
+
* like `blockEditingMode` that might prevent user modifications to a block.
|
|
822
|
+
*
|
|
823
|
+
* This distinction is important as this selector specifically drives the block lock UI
|
|
824
|
+
* that a user interacts with. `blockEditingModes` are excluded as a user can't change
|
|
825
|
+
* them.
|
|
826
|
+
*
|
|
827
|
+
* @param {Object} state Global application state.
|
|
828
|
+
* @param {string} clientId ClientId of the block.
|
|
829
|
+
*
|
|
830
|
+
* @return {boolean} Whether the block is currently locked.
|
|
831
|
+
*/
|
|
832
|
+
export function isLockedBlock( state, clientId ) {
|
|
833
|
+
return (
|
|
834
|
+
isEditLockedBlock( state, clientId ) ||
|
|
835
|
+
isMoveLockedBlock( state, clientId ) ||
|
|
836
|
+
isRemoveLockedBlock( state, clientId )
|
|
837
|
+
);
|
|
838
|
+
}
|
package/src/store/reducer.js
CHANGED
|
@@ -2305,6 +2305,9 @@ function getDerivedBlockEditingModesForTree( state, treeClientId = '' ) {
|
|
|
2305
2305
|
const contentOnlyParents = [
|
|
2306
2306
|
...contentOnlyTemplateLockedClientIds,
|
|
2307
2307
|
...unsyncedPatternClientIds,
|
|
2308
|
+
...( window?.__experimentalContentOnlyPatternInsertion
|
|
2309
|
+
? templatePartClientIds
|
|
2310
|
+
: [] ),
|
|
2308
2311
|
];
|
|
2309
2312
|
|
|
2310
2313
|
traverseBlockTree( state, treeClientId, ( block ) => {
|
package/src/store/selectors.js
CHANGED
|
@@ -1693,7 +1693,8 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1693
1693
|
blockType = getBlockType( blockName );
|
|
1694
1694
|
}
|
|
1695
1695
|
|
|
1696
|
-
|
|
1696
|
+
const rootTemplateLock = getTemplateLock( state, rootClientId );
|
|
1697
|
+
if ( rootTemplateLock && rootTemplateLock !== 'contentOnly' ) {
|
|
1697
1698
|
return false;
|
|
1698
1699
|
}
|
|
1699
1700
|
|
|
@@ -1876,7 +1877,8 @@ export function canRemoveBlock( state, clientId ) {
|
|
|
1876
1877
|
}
|
|
1877
1878
|
|
|
1878
1879
|
const rootClientId = getBlockRootClientId( state, clientId );
|
|
1879
|
-
|
|
1880
|
+
const rootTemplateLock = getTemplateLock( state, rootClientId );
|
|
1881
|
+
if ( rootTemplateLock && rootTemplateLock !== 'contentOnly' ) {
|
|
1880
1882
|
return false;
|
|
1881
1883
|
}
|
|
1882
1884
|
|
|
@@ -1937,8 +1939,8 @@ export function canMoveBlock( state, clientId ) {
|
|
|
1937
1939
|
}
|
|
1938
1940
|
|
|
1939
1941
|
const rootClientId = getBlockRootClientId( state, clientId );
|
|
1940
|
-
const
|
|
1941
|
-
if (
|
|
1942
|
+
const rootTemplateLock = getTemplateLock( state, rootClientId );
|
|
1943
|
+
if ( rootTemplateLock === 'all' ) {
|
|
1942
1944
|
return false;
|
|
1943
1945
|
}
|
|
1944
1946
|
|
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
getExpandedBlock,
|
|
11
11
|
isDragging,
|
|
12
12
|
getBlockStyles,
|
|
13
|
+
isEditLockedBlock,
|
|
14
|
+
isMoveLockedBlock,
|
|
15
|
+
isRemoveLockedBlock,
|
|
16
|
+
isLockedBlock,
|
|
13
17
|
} from '../private-selectors';
|
|
14
18
|
import { getBlockEditingMode } from '../selectors';
|
|
15
19
|
|
|
@@ -681,4 +685,242 @@ describe( 'private selectors', () => {
|
|
|
681
685
|
} );
|
|
682
686
|
} );
|
|
683
687
|
} );
|
|
688
|
+
|
|
689
|
+
describe( 'isEditLockedBlock', () => {
|
|
690
|
+
it( 'returns false when block has no lock attribute', () => {
|
|
691
|
+
const state = {
|
|
692
|
+
blocks: {
|
|
693
|
+
byClientId: new Map( [
|
|
694
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
695
|
+
] ),
|
|
696
|
+
attributes: new Map( [ [ 'block-1', {} ] ] ),
|
|
697
|
+
},
|
|
698
|
+
};
|
|
699
|
+
expect( isEditLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
700
|
+
} );
|
|
701
|
+
|
|
702
|
+
it( 'returns false when block has lock attribute but edit is false', () => {
|
|
703
|
+
const state = {
|
|
704
|
+
blocks: {
|
|
705
|
+
byClientId: new Map( [
|
|
706
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
707
|
+
] ),
|
|
708
|
+
attributes: new Map( [
|
|
709
|
+
[ 'block-1', { lock: { edit: false, move: true } } ],
|
|
710
|
+
] ),
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
expect( isEditLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
714
|
+
} );
|
|
715
|
+
|
|
716
|
+
it( 'returns true when block has lock attribute with edit set to true', () => {
|
|
717
|
+
const state = {
|
|
718
|
+
blocks: {
|
|
719
|
+
byClientId: new Map( [
|
|
720
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
721
|
+
] ),
|
|
722
|
+
attributes: new Map( [
|
|
723
|
+
[ 'block-1', { lock: { edit: true } } ],
|
|
724
|
+
] ),
|
|
725
|
+
},
|
|
726
|
+
};
|
|
727
|
+
expect( isEditLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
728
|
+
} );
|
|
729
|
+
|
|
730
|
+
it( 'returns false when block has no attributes', () => {
|
|
731
|
+
const state = {
|
|
732
|
+
blocks: {
|
|
733
|
+
byClientId: new Map(),
|
|
734
|
+
attributes: new Map(),
|
|
735
|
+
},
|
|
736
|
+
};
|
|
737
|
+
expect( isEditLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
738
|
+
} );
|
|
739
|
+
} );
|
|
740
|
+
|
|
741
|
+
describe( 'isMoveLockedBlock', () => {
|
|
742
|
+
const createState = ( templateLock, blockLock ) => ( {
|
|
743
|
+
blocks: {
|
|
744
|
+
byClientId: new Map( [
|
|
745
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
746
|
+
[ 'parent-block', { clientId: 'parent-block' } ],
|
|
747
|
+
] ),
|
|
748
|
+
attributes: new Map( [
|
|
749
|
+
[ 'block-1', blockLock ? { lock: blockLock } : {} ],
|
|
750
|
+
[ 'parent-block', {} ],
|
|
751
|
+
] ),
|
|
752
|
+
parents: new Map( [
|
|
753
|
+
[ 'block-1', 'parent-block' ],
|
|
754
|
+
[ 'parent-block', '' ],
|
|
755
|
+
] ),
|
|
756
|
+
},
|
|
757
|
+
settings: {},
|
|
758
|
+
blockListSettings: {
|
|
759
|
+
'parent-block': templateLock ? { templateLock } : {},
|
|
760
|
+
},
|
|
761
|
+
} );
|
|
762
|
+
|
|
763
|
+
it( 'returns false when block has no lock and no templateLock', () => {
|
|
764
|
+
const state = createState( null, null );
|
|
765
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
766
|
+
} );
|
|
767
|
+
|
|
768
|
+
it( 'returns true when parent has templateLock set to "all"', () => {
|
|
769
|
+
const state = createState( 'all', null );
|
|
770
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
771
|
+
} );
|
|
772
|
+
|
|
773
|
+
it( 'returns false when parent has templateLock set to "contentOnly"', () => {
|
|
774
|
+
const state = createState( 'contentOnly', null );
|
|
775
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
776
|
+
} );
|
|
777
|
+
|
|
778
|
+
it( 'returns true when block has lock.move set to true', () => {
|
|
779
|
+
const state = createState( null, { move: true } );
|
|
780
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
781
|
+
} );
|
|
782
|
+
|
|
783
|
+
it( 'returns false when block has lock.move set to false', () => {
|
|
784
|
+
const state = createState( null, { move: false } );
|
|
785
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
786
|
+
} );
|
|
787
|
+
|
|
788
|
+
it( 'prioritizes block lock over template lock', () => {
|
|
789
|
+
const state = createState( 'all', { move: false } );
|
|
790
|
+
expect( isMoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
791
|
+
} );
|
|
792
|
+
} );
|
|
793
|
+
|
|
794
|
+
describe( 'isRemoveLockedBlock', () => {
|
|
795
|
+
const createState = ( templateLock, blockLock ) => ( {
|
|
796
|
+
blocks: {
|
|
797
|
+
byClientId: new Map( [
|
|
798
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
799
|
+
[ 'parent-block', { clientId: 'parent-block' } ],
|
|
800
|
+
] ),
|
|
801
|
+
attributes: new Map( [
|
|
802
|
+
[ 'block-1', blockLock ? { lock: blockLock } : {} ],
|
|
803
|
+
[ 'parent-block', {} ],
|
|
804
|
+
] ),
|
|
805
|
+
parents: new Map( [
|
|
806
|
+
[ 'block-1', 'parent-block' ],
|
|
807
|
+
[ 'parent-block', '' ],
|
|
808
|
+
] ),
|
|
809
|
+
},
|
|
810
|
+
settings: {},
|
|
811
|
+
blockListSettings: {
|
|
812
|
+
'parent-block': templateLock ? { templateLock } : {},
|
|
813
|
+
},
|
|
814
|
+
} );
|
|
815
|
+
|
|
816
|
+
it( 'returns false when block has no lock and no templateLock', () => {
|
|
817
|
+
const state = createState( null, null );
|
|
818
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
819
|
+
} );
|
|
820
|
+
|
|
821
|
+
it( 'returns true when parent has templateLock set to "all"', () => {
|
|
822
|
+
const state = createState( 'all', null );
|
|
823
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
824
|
+
} );
|
|
825
|
+
|
|
826
|
+
it( 'returns true when parent has templateLock set to "insert"', () => {
|
|
827
|
+
const state = createState( 'insert', null );
|
|
828
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
829
|
+
} );
|
|
830
|
+
|
|
831
|
+
it( 'returns false when parent has templateLock set to "contentOnly"', () => {
|
|
832
|
+
const state = createState( 'contentOnly', null );
|
|
833
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
834
|
+
} );
|
|
835
|
+
|
|
836
|
+
it( 'returns true when block has lock.remove set to true', () => {
|
|
837
|
+
const state = createState( null, { remove: true } );
|
|
838
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
839
|
+
} );
|
|
840
|
+
|
|
841
|
+
it( 'returns false when block has lock.remove set to false', () => {
|
|
842
|
+
const state = createState( null, { remove: false } );
|
|
843
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
844
|
+
} );
|
|
845
|
+
|
|
846
|
+
it( 'prioritizes block lock over template lock', () => {
|
|
847
|
+
const state = createState( 'all', { remove: false } );
|
|
848
|
+
expect( isRemoveLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
849
|
+
} );
|
|
850
|
+
} );
|
|
851
|
+
|
|
852
|
+
describe( 'isLockedBlock', () => {
|
|
853
|
+
const createState = ( templateLock, blockLock ) => ( {
|
|
854
|
+
blocks: {
|
|
855
|
+
byClientId: new Map( [
|
|
856
|
+
[ 'block-1', { clientId: 'block-1' } ],
|
|
857
|
+
[ 'parent-block', { clientId: 'parent-block' } ],
|
|
858
|
+
] ),
|
|
859
|
+
attributes: new Map( [
|
|
860
|
+
[ 'block-1', blockLock ? { lock: blockLock } : {} ],
|
|
861
|
+
[ 'parent-block', {} ],
|
|
862
|
+
] ),
|
|
863
|
+
parents: new Map( [
|
|
864
|
+
[ 'block-1', 'parent-block' ],
|
|
865
|
+
[ 'parent-block', '' ],
|
|
866
|
+
] ),
|
|
867
|
+
},
|
|
868
|
+
settings: {},
|
|
869
|
+
blockListSettings: {
|
|
870
|
+
'parent-block': templateLock ? { templateLock } : {},
|
|
871
|
+
},
|
|
872
|
+
} );
|
|
873
|
+
|
|
874
|
+
it( 'returns false when block is not locked in any way', () => {
|
|
875
|
+
const state = createState( null, null );
|
|
876
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
877
|
+
} );
|
|
878
|
+
|
|
879
|
+
it( 'returns true when block has lock.edit set to true', () => {
|
|
880
|
+
const state = createState( null, { edit: true } );
|
|
881
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
882
|
+
} );
|
|
883
|
+
|
|
884
|
+
it( 'returns true when block has lock.move set to true', () => {
|
|
885
|
+
const state = createState( null, { move: true } );
|
|
886
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
887
|
+
} );
|
|
888
|
+
|
|
889
|
+
it( 'returns true when block has lock.remove set to true', () => {
|
|
890
|
+
const state = createState( null, { remove: true } );
|
|
891
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
892
|
+
} );
|
|
893
|
+
|
|
894
|
+
it( 'returns true when parent has templateLock set to "all"', () => {
|
|
895
|
+
const state = createState( 'all', null );
|
|
896
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
897
|
+
} );
|
|
898
|
+
|
|
899
|
+
it( 'returns true when block has multiple locks', () => {
|
|
900
|
+
const state = createState( null, {
|
|
901
|
+
edit: true,
|
|
902
|
+
move: true,
|
|
903
|
+
remove: true,
|
|
904
|
+
} );
|
|
905
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
906
|
+
} );
|
|
907
|
+
|
|
908
|
+
it( 'returns true when only one lock type is active', () => {
|
|
909
|
+
const state = createState( null, {
|
|
910
|
+
edit: false,
|
|
911
|
+
move: true,
|
|
912
|
+
remove: false,
|
|
913
|
+
} );
|
|
914
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( true );
|
|
915
|
+
} );
|
|
916
|
+
|
|
917
|
+
it( 'returns false when all lock types are explicitly false', () => {
|
|
918
|
+
const state = createState( null, {
|
|
919
|
+
edit: false,
|
|
920
|
+
move: false,
|
|
921
|
+
remove: false,
|
|
922
|
+
} );
|
|
923
|
+
expect( isLockedBlock( state, 'block-1' ) ).toBe( false );
|
|
924
|
+
} );
|
|
925
|
+
} );
|
|
684
926
|
} );
|
|
@@ -4540,11 +4540,16 @@ describe( 'state', () => {
|
|
|
4540
4540
|
);
|
|
4541
4541
|
} );
|
|
4542
4542
|
|
|
4543
|
-
it( 'returns the expected block editing modes for
|
|
4544
|
-
// Currently, template parts are not considered sections, so
|
|
4545
|
-
// child blocks are not set to contentOnly.
|
|
4543
|
+
it( 'returns the expected block editing modes for synced patterns', () => {
|
|
4546
4544
|
expect( initialState.derivedBlockEditingModes ).toEqual(
|
|
4547
|
-
new Map(
|
|
4545
|
+
new Map(
|
|
4546
|
+
Object.entries( {
|
|
4547
|
+
'template-part-paragraph': 'contentOnly',
|
|
4548
|
+
'template-part-group': 'disabled',
|
|
4549
|
+
'template-part-grouped-paragraph':
|
|
4550
|
+
'contentOnly',
|
|
4551
|
+
} )
|
|
4552
|
+
)
|
|
4548
4553
|
);
|
|
4549
4554
|
} );
|
|
4550
4555
|
|
|
@@ -4568,7 +4573,7 @@ describe( 'state', () => {
|
|
|
4568
4573
|
expect( derivedBlockEditingModes ).toEqual( new Map() );
|
|
4569
4574
|
} );
|
|
4570
4575
|
|
|
4571
|
-
it( '
|
|
4576
|
+
it( 'allows explicitly set blockEditingModes to override the template part editing modes', () => {
|
|
4572
4577
|
const { derivedBlockEditingModes } = dispatchActions(
|
|
4573
4578
|
[
|
|
4574
4579
|
{
|
|
@@ -4582,8 +4587,13 @@ describe( 'state', () => {
|
|
|
4582
4587
|
);
|
|
4583
4588
|
|
|
4584
4589
|
expect( derivedBlockEditingModes ).toEqual(
|
|
4585
|
-
|
|
4586
|
-
|
|
4590
|
+
new Map(
|
|
4591
|
+
Object.entries( {
|
|
4592
|
+
'template-part-paragraph': 'contentOnly',
|
|
4593
|
+
'template-part-group': 'disabled',
|
|
4594
|
+
// template-part-grouped-paragraph already has an explicit mode, so isn't set as a derived mode.
|
|
4595
|
+
} )
|
|
4596
|
+
)
|
|
4587
4597
|
);
|
|
4588
4598
|
} );
|
|
4589
4599
|
} );
|
package/src/style.scss
CHANGED
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
@use "./components/date-format-picker/style.scss" as *;
|
|
34
34
|
@use "./components/duotone-control/style.scss" as *;
|
|
35
35
|
@use "./components/font-appearance-control/style.scss" as *;
|
|
36
|
-
@use "./components/font-family/style.scss" as *;
|
|
37
36
|
@use "./components/global-styles/style.scss" as *;
|
|
38
37
|
@use "./components/grid/style.scss" as *;
|
|
39
38
|
@use "./components/height-control/style.scss" as *;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useDispatch, useRegistry } from '@wordpress/data';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { store as blockEditorStore } from '../store';
|
|
10
|
-
import { useBlockEditContext } from '../components/block-edit';
|
|
11
|
-
|
|
12
1
|
const DEFAULT_ATTRIBUTE = '__default';
|
|
13
2
|
const PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides';
|
|
14
3
|
|
|
15
|
-
/**
|
|
16
|
-
* Checks if the given object is empty.
|
|
17
|
-
*
|
|
18
|
-
* @param {?Object} object The object to check.
|
|
19
|
-
*
|
|
20
|
-
* @return {boolean} Whether the object is empty.
|
|
21
|
-
*/
|
|
22
|
-
function isObjectEmpty( object ) {
|
|
23
|
-
return ! object || Object.keys( object ).length === 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
4
|
/**
|
|
27
5
|
* Checks if the block has the `__default` binding for pattern overrides.
|
|
28
6
|
*
|
|
@@ -66,138 +44,3 @@ export function replacePatternOverridesDefaultBinding(
|
|
|
66
44
|
|
|
67
45
|
return bindings;
|
|
68
46
|
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Contains utils to update the block `bindings` metadata.
|
|
72
|
-
*
|
|
73
|
-
* @typedef {Object} WPBlockBindingsUtils
|
|
74
|
-
*
|
|
75
|
-
* @property {Function} updateBlockBindings Updates the value of the bindings connected to block attributes.
|
|
76
|
-
* @property {Function} removeAllBlockBindings Removes the bindings property of the `metadata` attribute.
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Retrieves the existing utils needed to update the block `bindings` metadata.
|
|
81
|
-
* They can be used to create, modify, or remove connections from the existing block attributes.
|
|
82
|
-
*
|
|
83
|
-
* It contains the following utils:
|
|
84
|
-
* - `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.
|
|
85
|
-
* - `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.
|
|
86
|
-
*
|
|
87
|
-
* @since 6.7.0 Introduced in WordPress core.
|
|
88
|
-
*
|
|
89
|
-
* @param {?string} clientId Optional block client ID. If not set, it will use the current block client ID from the context.
|
|
90
|
-
*
|
|
91
|
-
* @return {?WPBlockBindingsUtils} Object containing the block bindings utils.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```js
|
|
95
|
-
* import { useBlockBindingsUtils } from '@wordpress/block-editor'
|
|
96
|
-
* const { updateBlockBindings, removeAllBlockBindings } = useBlockBindingsUtils();
|
|
97
|
-
*
|
|
98
|
-
* // Update url and alt attributes.
|
|
99
|
-
* updateBlockBindings( {
|
|
100
|
-
* url: {
|
|
101
|
-
* source: 'core/post-meta',
|
|
102
|
-
* args: {
|
|
103
|
-
* key: 'url_custom_field',
|
|
104
|
-
* },
|
|
105
|
-
* },
|
|
106
|
-
* alt: {
|
|
107
|
-
* source: 'core/post-meta',
|
|
108
|
-
* args: {
|
|
109
|
-
* key: 'text_custom_field',
|
|
110
|
-
* },
|
|
111
|
-
* },
|
|
112
|
-
* } );
|
|
113
|
-
*
|
|
114
|
-
* // Remove binding from url attribute.
|
|
115
|
-
* updateBlockBindings( { url: undefined } );
|
|
116
|
-
*
|
|
117
|
-
* // Remove bindings from all attributes.
|
|
118
|
-
* removeAllBlockBindings();
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
export function useBlockBindingsUtils( clientId ) {
|
|
122
|
-
const { clientId: contextClientId } = useBlockEditContext();
|
|
123
|
-
const blockClientId = clientId || contextClientId;
|
|
124
|
-
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
125
|
-
const { getBlockAttributes } = useRegistry().select( blockEditorStore );
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Updates the value of the bindings connected to block attributes.
|
|
129
|
-
* It removes the binding when the new value is `undefined`.
|
|
130
|
-
*
|
|
131
|
-
* @param {Object} bindings Bindings including the attributes to update and the new object.
|
|
132
|
-
* @param {string} bindings.source The source name to connect to.
|
|
133
|
-
* @param {Object} [bindings.args] Object containing the arguments needed by the source.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```js
|
|
137
|
-
* import { useBlockBindingsUtils } from '@wordpress/block-editor'
|
|
138
|
-
*
|
|
139
|
-
* const { updateBlockBindings } = useBlockBindingsUtils();
|
|
140
|
-
* updateBlockBindings( {
|
|
141
|
-
* url: {
|
|
142
|
-
* source: 'core/post-meta',
|
|
143
|
-
* args: {
|
|
144
|
-
* key: 'url_custom_field',
|
|
145
|
-
* },
|
|
146
|
-
* },
|
|
147
|
-
* alt: {
|
|
148
|
-
* source: 'core/post-meta',
|
|
149
|
-
* args: {
|
|
150
|
-
* key: 'text_custom_field',
|
|
151
|
-
* },
|
|
152
|
-
* }
|
|
153
|
-
* } );
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
const updateBlockBindings = ( bindings ) => {
|
|
157
|
-
const { metadata: { bindings: currentBindings, ...metadata } = {} } =
|
|
158
|
-
getBlockAttributes( blockClientId );
|
|
159
|
-
const newBindings = { ...currentBindings };
|
|
160
|
-
|
|
161
|
-
Object.entries( bindings ).forEach( ( [ attribute, binding ] ) => {
|
|
162
|
-
if ( ! binding && newBindings[ attribute ] ) {
|
|
163
|
-
delete newBindings[ attribute ];
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
newBindings[ attribute ] = binding;
|
|
167
|
-
} );
|
|
168
|
-
|
|
169
|
-
const newMetadata = {
|
|
170
|
-
...metadata,
|
|
171
|
-
bindings: newBindings,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
if ( isObjectEmpty( newMetadata.bindings ) ) {
|
|
175
|
-
delete newMetadata.bindings;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
updateBlockAttributes( blockClientId, {
|
|
179
|
-
metadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,
|
|
180
|
-
} );
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Removes the bindings property of the `metadata` attribute.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```js
|
|
188
|
-
* import { useBlockBindingsUtils } from '@wordpress/block-editor'
|
|
189
|
-
*
|
|
190
|
-
* const { removeAllBlockBindings } = useBlockBindingsUtils();
|
|
191
|
-
* removeAllBlockBindings();
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
const removeAllBlockBindings = () => {
|
|
195
|
-
const { metadata: { bindings, ...metadata } = {} } =
|
|
196
|
-
getBlockAttributes( blockClientId );
|
|
197
|
-
updateBlockAttributes( blockClientId, {
|
|
198
|
-
metadata: isObjectEmpty( metadata ) ? undefined : metadata,
|
|
199
|
-
} );
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
return { updateBlockBindings, removeAllBlockBindings };
|
|
203
|
-
}
|
package/src/utils/index.js
CHANGED