@wordpress/block-editor 12.1.0 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/autocompleters/block.js +13 -5
- package/build/autocompleters/block.js.map +1 -1
- package/build/components/block-breadcrumb/index.js +6 -3
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-editing-mode/index.js +84 -0
- package/build/components/block-editing-mode/index.js.map +1 -0
- package/build/components/block-list/block-list-block-context.js +15 -0
- package/build/components/block-list/block-list-block-context.js.map +1 -0
- package/build/components/block-list/block.js +29 -37
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +14 -22
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +107 -108
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +2 -2
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -5
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-list-appender/index.js +15 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +19 -4
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-styles/preview-panel.js +1 -2
- package/build/components/block-styles/preview-panel.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js +8 -0
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/block-variation-transformations.js +125 -0
- package/build/components/block-switcher/block-variation-transformations.js.map +1 -0
- package/build/components/block-switcher/index.js +34 -12
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-switcher/pattern-transformations-menu.js +3 -3
- package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build/components/block-toolbar/index.js +9 -7
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +5 -3
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +11 -5
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.js +7 -2
- package/build/components/convert-to-group-buttons/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.native.js +87 -3
- package/build/components/convert-to-group-buttons/index.native.js.map +1 -1
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +23 -37
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +3 -2
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/iframe/index.js +14 -7
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +2 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +7 -7
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js +13 -5
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/index.js +3 -7
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +2 -4
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-results.js +19 -6
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/list-view/appender.js +6 -1
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/list-view/block-contents.js +4 -2
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block.js +21 -25
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +1 -3
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +14 -7
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +27 -3
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/publish-date-time-picker/index.js +0 -2
- package/build/components/publish-date-time-picker/index.js.map +1 -1
- package/build/components/url-input/index.js +3 -0
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +25 -15
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +8 -1
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +13 -7
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/align.js +3 -7
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/behaviors.js +115 -0
- package/build/hooks/behaviors.js.map +1 -0
- package/build/hooks/dimensions.js +0 -30
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +4 -8
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +8 -9
- package/build/hooks/layout.js.map +1 -1
- package/build/private-apis.js +4 -7
- package/build/private-apis.js.map +1 -1
- package/build/store/private-actions.js +46 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +88 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +36 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +28 -18
- package/build/store/selectors.js.map +1 -1
- package/build/utils/order-inserter-block-items.js +41 -0
- package/build/utils/order-inserter-block-items.js.map +1 -0
- package/build-module/autocompleters/block.js +12 -5
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js +5 -3
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +72 -0
- package/build-module/components/block-editing-mode/index.js.map +1 -0
- package/build-module/components/block-list/block-list-block-context.js +6 -0
- package/build-module/components/block-list/block-list-block-context.js.map +1 -0
- package/build-module/components/block-list/block.js +26 -34
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +14 -22
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +108 -110
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -1
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +6 -5
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +15 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +18 -4
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-styles/preview-panel.js +1 -2
- package/build-module/components/block-styles/preview-panel.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js +7 -0
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/block-variation-transformations.js +108 -0
- package/build-module/components/block-switcher/block-variation-transformations.js.map +1 -0
- package/build-module/components/block-switcher/index.js +33 -12
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-switcher/pattern-transformations-menu.js +3 -3
- package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -7
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +4 -3
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +11 -5
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.js +7 -2
- package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.native.js +76 -1
- package/build-module/components/convert-to-group-buttons/index.native.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +22 -36
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +3 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/iframe/index.js +15 -8
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +2 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +7 -6
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-nested-settings-update.js +13 -5
- package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build-module/components/inserter/index.js +3 -7
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +2 -4
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-results.js +16 -6
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/list-view/appender.js +6 -2
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +4 -2
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block.js +20 -25
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -3
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +15 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +26 -3
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/publish-date-time-picker/index.js +0 -2
- package/build-module/components/publish-date-time-picker/index.js.map +1 -1
- package/build-module/components/url-input/index.js +3 -0
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +25 -16
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +8 -1
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +13 -7
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/hooks/align.js +3 -6
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/behaviors.js +97 -0
- package/build-module/hooks/behaviors.js.map +1 -0
- package/build-module/hooks/dimensions.js +0 -28
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +3 -6
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +7 -9
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/private-apis.js +3 -5
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/private-actions.js +42 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +79 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +34 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +26 -17
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/order-inserter-block-items.js +32 -0
- package/build-module/utils/order-inserter-block-items.js.map +1 -0
- package/build-style/content-rtl.css +32 -13
- package/build-style/content.css +32 -13
- package/build-style/default-editor-styles-rtl.css +1 -1
- package/build-style/default-editor-styles.css +1 -1
- package/build-style/style-rtl.css +19 -64
- package/build-style/style.css +20 -64
- package/package.json +32 -31
- package/src/autocompleters/block.js +15 -7
- package/src/components/block-breadcrumb/index.js +11 -3
- package/src/components/block-editing-mode/index.js +71 -0
- package/src/components/block-list/block-list-block-context.js +6 -0
- package/src/components/block-list/block.js +38 -56
- package/src/components/block-list/block.native.js +30 -41
- package/src/components/block-list/content.scss +5 -5
- package/src/components/block-list/index.native.js +164 -153
- package/src/components/block-list/test/index.native.js +2 -2
- package/src/components/block-list/use-block-props/index.js +1 -1
- package/src/components/block-list/use-in-between-inserter.js +7 -3
- package/src/components/block-list-appender/index.js +22 -4
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +23 -0
- package/src/components/block-mover/style.scss +1 -0
- package/src/components/block-styles/preview-panel.js +1 -3
- package/src/components/block-switcher/block-transformations-menu.js +12 -0
- package/src/components/block-switcher/block-variation-transformations.js +115 -0
- package/src/components/block-switcher/index.js +38 -5
- package/src/components/block-switcher/pattern-transformations-menu.js +5 -5
- package/src/components/block-switcher/style.scss +6 -5
- package/src/components/block-toolbar/index.js +10 -11
- package/src/components/block-tools/block-contextual-toolbar.js +4 -5
- package/src/components/block-tools/insertion-point.js +23 -9
- package/src/components/button-block-appender/content.scss +22 -0
- package/src/components/convert-to-group-buttons/index.js +9 -2
- package/src/components/convert-to-group-buttons/index.native.js +79 -1
- package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +32 -38
- package/src/components/global-styles/dimensions-panel.js +3 -2
- package/src/components/global-styles/style.scss +3 -0
- package/src/components/iframe/index.js +22 -12
- package/src/components/inner-blocks/README.md +5 -0
- package/src/components/inner-blocks/index.js +2 -0
- package/src/components/inner-blocks/index.native.js +16 -6
- package/src/components/inner-blocks/use-nested-settings-update.js +20 -3
- package/src/components/inserter/index.js +1 -9
- package/src/components/inserter/quick-inserter.js +0 -2
- package/src/components/inserter/search-results.js +32 -6
- package/src/components/list-view/appender.js +3 -2
- package/src/components/list-view/block-contents.js +8 -2
- package/src/components/list-view/block.js +29 -35
- package/src/components/list-view/branch.js +1 -7
- package/src/components/list-view/index.js +17 -4
- package/src/components/list-view/style.scss +2 -5
- package/src/components/list-view/use-list-view-client-ids.js +21 -4
- package/src/components/publish-date-time-picker/index.js +0 -2
- package/src/components/url-input/README.md +6 -0
- package/src/components/url-input/index.js +1 -0
- package/src/components/use-block-drop-zone/index.js +31 -17
- package/src/components/use-resize-canvas/index.js +9 -1
- package/src/components/writing-flow/test/index.js +15 -0
- package/src/components/writing-flow/use-arrow-nav.js +17 -4
- package/src/hooks/align.js +3 -11
- package/src/hooks/behaviors.js +104 -0
- package/src/hooks/dimensions.js +0 -40
- package/src/hooks/duotone.js +3 -11
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +10 -18
- package/src/private-apis.js +2 -4
- package/src/store/private-actions.js +39 -0
- package/src/store/private-selectors.js +95 -0
- package/src/store/reducer.js +27 -0
- package/src/store/selectors.js +25 -15
- package/src/store/test/private-actions.js +32 -1
- package/src/store/test/private-selectors.js +158 -0
- package/src/store/test/reducer.js +48 -0
- package/src/style.scss +0 -3
- package/src/utils/order-inserter-block-items.js +26 -0
- package/build/components/block-list/block-list-compact.native.js +0 -75
- package/build/components/block-list/block-list-compact.native.js.map +0 -1
- package/build/components/off-canvas-editor/appender.js +0 -125
- package/build/components/off-canvas-editor/appender.js.map +0 -1
- package/build/components/off-canvas-editor/block-contents.js +0 -141
- package/build/components/off-canvas-editor/block-contents.js.map +0 -1
- package/build/components/off-canvas-editor/block-select-button.js +0 -126
- package/build/components/off-canvas-editor/block-select-button.js.map +0 -1
- package/build/components/off-canvas-editor/block.js +0 -297
- package/build/components/off-canvas-editor/block.js.map +0 -1
- package/build/components/off-canvas-editor/branch.js +0 -197
- package/build/components/off-canvas-editor/branch.js.map +0 -1
- package/build/components/off-canvas-editor/context.js +0 -19
- package/build/components/off-canvas-editor/context.js.map +0 -1
- package/build/components/off-canvas-editor/drop-indicator.js +0 -118
- package/build/components/off-canvas-editor/drop-indicator.js.map +0 -1
- package/build/components/off-canvas-editor/expander.js +0 -41
- package/build/components/off-canvas-editor/expander.js.map +0 -1
- package/build/components/off-canvas-editor/index.js +0 -236
- package/build/components/off-canvas-editor/index.js.map +0 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +0 -148
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +0 -1
- package/build/components/off-canvas-editor/leaf.js +0 -60
- package/build/components/off-canvas-editor/leaf.js.map +0 -1
- package/build/components/off-canvas-editor/link-ui.js +0 -186
- package/build/components/off-canvas-editor/link-ui.js.map +0 -1
- package/build/components/off-canvas-editor/update-attributes.js +0 -108
- package/build/components/off-canvas-editor/update-attributes.js.map +0 -1
- package/build/components/off-canvas-editor/use-block-selection.js +0 -139
- package/build/components/off-canvas-editor/use-block-selection.js.map +0 -1
- package/build/components/off-canvas-editor/use-inserted-block.js +0 -58
- package/build/components/off-canvas-editor/use-inserted-block.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-client-ids.js +0 -33
- package/build/components/off-canvas-editor/use-list-view-client-ids.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js +0 -235
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -60
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +0 -1
- package/build/components/off-canvas-editor/utils.js +0 -60
- package/build/components/off-canvas-editor/utils.js.map +0 -1
- package/build-module/components/block-list/block-list-compact.native.js +0 -60
- package/build-module/components/block-list/block-list-compact.native.js.map +0 -1
- package/build-module/components/off-canvas-editor/appender.js +0 -108
- package/build-module/components/off-canvas-editor/appender.js.map +0 -1
- package/build-module/components/off-canvas-editor/block-contents.js +0 -121
- package/build-module/components/off-canvas-editor/block-contents.js.map +0 -1
- package/build-module/components/off-canvas-editor/block-select-button.js +0 -107
- package/build-module/components/off-canvas-editor/block-select-button.js.map +0 -1
- package/build-module/components/off-canvas-editor/block.js +0 -273
- package/build-module/components/off-canvas-editor/block.js.map +0 -1
- package/build-module/components/off-canvas-editor/branch.js +0 -179
- package/build-module/components/off-canvas-editor/branch.js.map +0 -1
- package/build-module/components/off-canvas-editor/context.js +0 -7
- package/build-module/components/off-canvas-editor/context.js.map +0 -1
- package/build-module/components/off-canvas-editor/drop-indicator.js +0 -111
- package/build-module/components/off-canvas-editor/drop-indicator.js.map +0 -1
- package/build-module/components/off-canvas-editor/expander.js +0 -32
- package/build-module/components/off-canvas-editor/expander.js.map +0 -1
- package/build-module/components/off-canvas-editor/index.js +0 -213
- package/build-module/components/off-canvas-editor/index.js.map +0 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +0 -130
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +0 -1
- package/build-module/components/off-canvas-editor/leaf.js +0 -45
- package/build-module/components/off-canvas-editor/leaf.js.map +0 -1
- package/build-module/components/off-canvas-editor/link-ui.js +0 -166
- package/build-module/components/off-canvas-editor/link-ui.js.map +0 -1
- package/build-module/components/off-canvas-editor/update-attributes.js +0 -97
- package/build-module/components/off-canvas-editor/update-attributes.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-block-selection.js +0 -124
- package/build-module/components/off-canvas-editor/use-block-selection.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-inserted-block.js +0 -47
- package/build-module/components/off-canvas-editor/use-inserted-block.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js +0 -24
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +0 -220
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -50
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +0 -1
- package/build-module/components/off-canvas-editor/utils.js +0 -44
- package/build-module/components/off-canvas-editor/utils.js.map +0 -1
- package/src/components/block-list/block-list-compact.native.js +0 -63
- package/src/components/off-canvas-editor/README.md +0 -5
- package/src/components/off-canvas-editor/appender.js +0 -124
- package/src/components/off-canvas-editor/block-contents.js +0 -156
- package/src/components/off-canvas-editor/block-select-button.js +0 -128
- package/src/components/off-canvas-editor/block.js +0 -347
- package/src/components/off-canvas-editor/branch.js +0 -238
- package/src/components/off-canvas-editor/context.js +0 -8
- package/src/components/off-canvas-editor/drop-indicator.js +0 -126
- package/src/components/off-canvas-editor/expander.js +0 -26
- package/src/components/off-canvas-editor/index.js +0 -271
- package/src/components/off-canvas-editor/leaf-more-menu.js +0 -158
- package/src/components/off-canvas-editor/leaf.js +0 -52
- package/src/components/off-canvas-editor/link-ui.js +0 -167
- package/src/components/off-canvas-editor/style.scss +0 -34
- package/src/components/off-canvas-editor/test/use-inserted-block.js +0 -108
- package/src/components/off-canvas-editor/test/utils.js +0 -50
- package/src/components/off-canvas-editor/update-attributes.js +0 -99
- package/src/components/off-canvas-editor/use-block-selection.js +0 -169
- package/src/components/off-canvas-editor/use-inserted-block.js +0 -47
- package/src/components/off-canvas-editor/use-list-view-client-ids.js +0 -29
- package/src/components/off-canvas-editor/use-list-view-drop-zone.js +0 -260
- package/src/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -58
- package/src/components/off-canvas-editor/utils.js +0 -58
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createBlock } from '@wordpress/blocks';
|
|
5
|
-
import {
|
|
6
|
-
addSubmenu,
|
|
7
|
-
chevronUp,
|
|
8
|
-
chevronDown,
|
|
9
|
-
moreVertical,
|
|
10
|
-
} from '@wordpress/icons';
|
|
11
|
-
import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components';
|
|
12
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal dependencies
|
|
17
|
-
*/
|
|
18
|
-
import { store as blockEditorStore } from '../../store';
|
|
19
|
-
import BlockTitle from '../block-title';
|
|
20
|
-
import { useListViewContext } from './context';
|
|
21
|
-
|
|
22
|
-
const POPOVER_PROPS = {
|
|
23
|
-
className: 'block-editor-block-settings-menu__popover',
|
|
24
|
-
position: 'bottom right',
|
|
25
|
-
variant: 'toolbar',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU = [
|
|
29
|
-
'core/navigation-link',
|
|
30
|
-
'core/navigation-submenu',
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
function AddSubmenuItem( { block, onClose } ) {
|
|
34
|
-
const { expandedState, expand } = useListViewContext();
|
|
35
|
-
const { insertBlock, replaceBlock, replaceInnerBlocks } =
|
|
36
|
-
useDispatch( blockEditorStore );
|
|
37
|
-
|
|
38
|
-
const clientId = block.clientId;
|
|
39
|
-
const isDisabled = ! BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU.includes(
|
|
40
|
-
block.name
|
|
41
|
-
);
|
|
42
|
-
return (
|
|
43
|
-
<MenuItem
|
|
44
|
-
icon={ addSubmenu }
|
|
45
|
-
disabled={ isDisabled }
|
|
46
|
-
onClick={ () => {
|
|
47
|
-
const updateSelectionOnInsert = false;
|
|
48
|
-
const newLink = createBlock( 'core/navigation-link' );
|
|
49
|
-
|
|
50
|
-
if ( block.name === 'core/navigation-submenu' ) {
|
|
51
|
-
insertBlock(
|
|
52
|
-
newLink,
|
|
53
|
-
block.innerBlocks.length,
|
|
54
|
-
clientId,
|
|
55
|
-
updateSelectionOnInsert
|
|
56
|
-
);
|
|
57
|
-
} else {
|
|
58
|
-
// Convert to a submenu if the block currently isn't one.
|
|
59
|
-
const newSubmenu = createBlock(
|
|
60
|
-
'core/navigation-submenu',
|
|
61
|
-
block.attributes,
|
|
62
|
-
block.innerBlocks
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// The following must happen as two independent actions.
|
|
66
|
-
// Why? Because the offcanvas editor relies on the getLastInsertedBlocksClientIds
|
|
67
|
-
// selector to determine which block is "active". As the UX needs the newLink to be
|
|
68
|
-
// the "active" block it must be the last block to be inserted.
|
|
69
|
-
// Therefore the Submenu is first created and **then** the newLink is inserted
|
|
70
|
-
// thus ensuring it is the last inserted block.
|
|
71
|
-
replaceBlock( clientId, newSubmenu );
|
|
72
|
-
|
|
73
|
-
replaceInnerBlocks(
|
|
74
|
-
newSubmenu.clientId,
|
|
75
|
-
[ newLink ],
|
|
76
|
-
updateSelectionOnInsert
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if ( ! expandedState[ block.clientId ] ) {
|
|
80
|
-
expand( block.clientId );
|
|
81
|
-
}
|
|
82
|
-
onClose();
|
|
83
|
-
} }
|
|
84
|
-
>
|
|
85
|
-
{ __( 'Add submenu link' ) }
|
|
86
|
-
</MenuItem>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export default function LeafMoreMenu( props ) {
|
|
91
|
-
const { block } = props;
|
|
92
|
-
const { clientId } = block;
|
|
93
|
-
|
|
94
|
-
const { moveBlocksDown, moveBlocksUp, removeBlocks } =
|
|
95
|
-
useDispatch( blockEditorStore );
|
|
96
|
-
|
|
97
|
-
const removeLabel = sprintf(
|
|
98
|
-
/* translators: %s: block name */
|
|
99
|
-
__( 'Remove %s' ),
|
|
100
|
-
BlockTitle( { clientId, maximumLength: 25 } )
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const rootClientId = useSelect(
|
|
104
|
-
( select ) => {
|
|
105
|
-
const { getBlockRootClientId } = select( blockEditorStore );
|
|
106
|
-
|
|
107
|
-
return getBlockRootClientId( clientId );
|
|
108
|
-
},
|
|
109
|
-
[ clientId ]
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<DropdownMenu
|
|
114
|
-
icon={ moreVertical }
|
|
115
|
-
label={ __( 'Options' ) }
|
|
116
|
-
className="block-editor-block-settings-menu"
|
|
117
|
-
popoverProps={ POPOVER_PROPS }
|
|
118
|
-
noIcons
|
|
119
|
-
{ ...props }
|
|
120
|
-
>
|
|
121
|
-
{ ( { onClose } ) => (
|
|
122
|
-
<>
|
|
123
|
-
<MenuGroup>
|
|
124
|
-
<MenuItem
|
|
125
|
-
icon={ chevronUp }
|
|
126
|
-
onClick={ () => {
|
|
127
|
-
moveBlocksUp( [ clientId ], rootClientId );
|
|
128
|
-
onClose();
|
|
129
|
-
} }
|
|
130
|
-
>
|
|
131
|
-
{ __( 'Move up' ) }
|
|
132
|
-
</MenuItem>
|
|
133
|
-
<MenuItem
|
|
134
|
-
icon={ chevronDown }
|
|
135
|
-
onClick={ () => {
|
|
136
|
-
moveBlocksDown( [ clientId ], rootClientId );
|
|
137
|
-
onClose();
|
|
138
|
-
} }
|
|
139
|
-
>
|
|
140
|
-
{ __( 'Move down' ) }
|
|
141
|
-
</MenuItem>
|
|
142
|
-
<AddSubmenuItem block={ block } onClose={ onClose } />
|
|
143
|
-
</MenuGroup>
|
|
144
|
-
<MenuGroup>
|
|
145
|
-
<MenuItem
|
|
146
|
-
onClick={ () => {
|
|
147
|
-
removeBlocks( [ clientId ], false );
|
|
148
|
-
onClose();
|
|
149
|
-
} }
|
|
150
|
-
>
|
|
151
|
-
{ removeLabel }
|
|
152
|
-
</MenuItem>
|
|
153
|
-
</MenuGroup>
|
|
154
|
-
</>
|
|
155
|
-
) }
|
|
156
|
-
</DropdownMenu>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { animated } from '@react-spring/web';
|
|
5
|
-
import classnames from 'classnames';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { __experimentalTreeGridRow as TreeGridRow } from '@wordpress/components';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import useMovingAnimation from '../use-moving-animation';
|
|
16
|
-
|
|
17
|
-
const AnimatedTreeGridRow = animated( TreeGridRow );
|
|
18
|
-
|
|
19
|
-
export default function ListViewLeaf( {
|
|
20
|
-
isSelected,
|
|
21
|
-
position,
|
|
22
|
-
level,
|
|
23
|
-
rowCount,
|
|
24
|
-
children,
|
|
25
|
-
className,
|
|
26
|
-
path,
|
|
27
|
-
...props
|
|
28
|
-
} ) {
|
|
29
|
-
const ref = useMovingAnimation( {
|
|
30
|
-
isSelected,
|
|
31
|
-
adjustScrolling: false,
|
|
32
|
-
enableAnimation: true,
|
|
33
|
-
triggerAnimationOnChange: path,
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<AnimatedTreeGridRow
|
|
38
|
-
ref={ ref }
|
|
39
|
-
className={ classnames(
|
|
40
|
-
'block-editor-list-view-leaf',
|
|
41
|
-
'offcanvas-editor-list-view-leaf',
|
|
42
|
-
className
|
|
43
|
-
) }
|
|
44
|
-
level={ level }
|
|
45
|
-
positionInSet={ position }
|
|
46
|
-
setSize={ rowCount }
|
|
47
|
-
{ ...props }
|
|
48
|
-
>
|
|
49
|
-
{ children }
|
|
50
|
-
</AnimatedTreeGridRow>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
// Note: this file is copied directly from packages/block-library/src/navigation-link/link-ui.js
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WordPress dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
7
|
-
import { Popover, Button } from '@wordpress/components';
|
|
8
|
-
import { __ } from '@wordpress/i18n';
|
|
9
|
-
import { switchToBlockType } from '@wordpress/blocks';
|
|
10
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
import { store as blockEditorStore } from '../../store';
|
|
16
|
-
import LinkControl from '../link-control';
|
|
17
|
-
import BlockIcon from '../block-icon';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Given the Link block's type attribute, return the query params to give to
|
|
21
|
-
* /wp/v2/search.
|
|
22
|
-
*
|
|
23
|
-
* @param {string} type Link block's type attribute.
|
|
24
|
-
* @param {string} kind Link block's entity of kind (post-type|taxonomy)
|
|
25
|
-
* @return {{ type?: string, subtype?: string }} Search query params.
|
|
26
|
-
*/
|
|
27
|
-
export function getSuggestionsQuery( type, kind ) {
|
|
28
|
-
switch ( type ) {
|
|
29
|
-
case 'post':
|
|
30
|
-
case 'page':
|
|
31
|
-
return { type: 'post', subtype: type };
|
|
32
|
-
case 'category':
|
|
33
|
-
return { type: 'term', subtype: 'category' };
|
|
34
|
-
case 'tag':
|
|
35
|
-
return { type: 'term', subtype: 'post_tag' };
|
|
36
|
-
case 'post_format':
|
|
37
|
-
return { type: 'post-format' };
|
|
38
|
-
default:
|
|
39
|
-
if ( kind === 'taxonomy' ) {
|
|
40
|
-
return { type: 'term', subtype: type };
|
|
41
|
-
}
|
|
42
|
-
if ( kind === 'post-type' ) {
|
|
43
|
-
return { type: 'post', subtype: type };
|
|
44
|
-
}
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Add transforms to Link Control
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} props Component props.
|
|
53
|
-
* @param {string} props.clientId Block client ID.
|
|
54
|
-
*/
|
|
55
|
-
function LinkControlTransforms( { clientId } ) {
|
|
56
|
-
const { getBlock, blockTransforms } = useSelect(
|
|
57
|
-
( select ) => {
|
|
58
|
-
const {
|
|
59
|
-
getBlock: _getBlock,
|
|
60
|
-
getBlockRootClientId,
|
|
61
|
-
getBlockTransformItems,
|
|
62
|
-
} = select( blockEditorStore );
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
getBlock: _getBlock,
|
|
66
|
-
blockTransforms: getBlockTransformItems(
|
|
67
|
-
_getBlock( clientId ),
|
|
68
|
-
getBlockRootClientId( clientId )
|
|
69
|
-
),
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
[ clientId ]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const { replaceBlock } = useDispatch( blockEditorStore );
|
|
76
|
-
|
|
77
|
-
const featuredBlocks = [
|
|
78
|
-
'core/page-list',
|
|
79
|
-
'core/site-logo',
|
|
80
|
-
'core/social-links',
|
|
81
|
-
'core/search',
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
const transforms = blockTransforms.filter( ( item ) => {
|
|
85
|
-
return featuredBlocks.includes( item.name );
|
|
86
|
-
} );
|
|
87
|
-
|
|
88
|
-
if ( ! transforms?.length ) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if ( ! clientId ) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<div className="link-control-transform">
|
|
98
|
-
<h3 className="link-control-transform__subheading">
|
|
99
|
-
{ __( 'Transform' ) }
|
|
100
|
-
</h3>
|
|
101
|
-
<div className="link-control-transform__items">
|
|
102
|
-
{ transforms.map( ( item ) => {
|
|
103
|
-
return (
|
|
104
|
-
<Button
|
|
105
|
-
key={ `transform-${ item.name }` }
|
|
106
|
-
onClick={ () =>
|
|
107
|
-
replaceBlock(
|
|
108
|
-
clientId,
|
|
109
|
-
switchToBlockType(
|
|
110
|
-
getBlock( clientId ),
|
|
111
|
-
item.name
|
|
112
|
-
)
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
className="link-control-transform__item"
|
|
116
|
-
>
|
|
117
|
-
<BlockIcon icon={ item.icon } />
|
|
118
|
-
{ item.title }
|
|
119
|
-
</Button>
|
|
120
|
-
);
|
|
121
|
-
} ) }
|
|
122
|
-
</div>
|
|
123
|
-
</div>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function LinkUI( props ) {
|
|
128
|
-
const { label, url, opensInNewTab, type, kind } = props.link;
|
|
129
|
-
const link = {
|
|
130
|
-
url,
|
|
131
|
-
opensInNewTab,
|
|
132
|
-
title: label && stripHTML( label ),
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<Popover
|
|
137
|
-
placement="bottom"
|
|
138
|
-
onClose={ props.onClose }
|
|
139
|
-
anchor={ props.anchor }
|
|
140
|
-
shift
|
|
141
|
-
>
|
|
142
|
-
<LinkControl
|
|
143
|
-
hasTextControl
|
|
144
|
-
hasRichPreviews
|
|
145
|
-
className={ props.className }
|
|
146
|
-
value={ link }
|
|
147
|
-
showInitialSuggestions={ true }
|
|
148
|
-
withCreateSuggestion={ props.hasCreateSuggestion }
|
|
149
|
-
noDirectEntry={ !! type }
|
|
150
|
-
noURLSuggestion={ !! type }
|
|
151
|
-
suggestionsQuery={ getSuggestionsQuery( type, kind ) }
|
|
152
|
-
onChange={ props.onChange }
|
|
153
|
-
onRemove={ props.onRemove }
|
|
154
|
-
onCancel={ props.onCancel }
|
|
155
|
-
renderControlBottom={
|
|
156
|
-
! url
|
|
157
|
-
? () => (
|
|
158
|
-
<LinkControlTransforms
|
|
159
|
-
clientId={ props.clientId }
|
|
160
|
-
/>
|
|
161
|
-
)
|
|
162
|
-
: null
|
|
163
|
-
}
|
|
164
|
-
/>
|
|
165
|
-
</Popover>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
.offcanvas-editor-appender .block-editor-inserter__toggle {
|
|
2
|
-
background-color: #1e1e1e;
|
|
3
|
-
color: #fff;
|
|
4
|
-
margin: $grid-unit-10 0 0 24px;
|
|
5
|
-
border-radius: 2px;
|
|
6
|
-
height: 24px;
|
|
7
|
-
min-width: 24px;
|
|
8
|
-
padding: 0;
|
|
9
|
-
|
|
10
|
-
&:hover,
|
|
11
|
-
&:focus {
|
|
12
|
-
background: var(--wp-admin-theme-color);
|
|
13
|
-
color: #fff;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.offcanvas-editor-appender__description {
|
|
18
|
-
display: none;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.offcanvas-editor-list-view-tree-wrapper {
|
|
22
|
-
max-width: 100%;
|
|
23
|
-
overflow-x: auto;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.offcanvas-editor-list-view-leaf {
|
|
27
|
-
display: block;
|
|
28
|
-
// sidebar width - tab panel padding
|
|
29
|
-
max-width: $sidebar-width - (2 * $grid-unit-20);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.offcanvas-editor-list-view-is-empty {
|
|
33
|
-
margin-left: $grid-unit-20;
|
|
34
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useInsertedBlock } from '../use-inserted-block';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* External dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { act, renderHook } from '@testing-library/react';
|
|
15
|
-
|
|
16
|
-
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
17
|
-
// This allows us to tweak the returned value on each test.
|
|
18
|
-
const mock = jest.fn();
|
|
19
|
-
return mock;
|
|
20
|
-
} );
|
|
21
|
-
|
|
22
|
-
jest.mock( '@wordpress/data/src/components/use-dispatch', () => ( {
|
|
23
|
-
useDispatch: jest.fn(),
|
|
24
|
-
} ) );
|
|
25
|
-
|
|
26
|
-
describe( 'useInsertedBlock', () => {
|
|
27
|
-
const mockUpdateBlockAttributes = jest.fn();
|
|
28
|
-
|
|
29
|
-
it( 'returns undefined values when called without a block clientId', () => {
|
|
30
|
-
useSelect.mockImplementation( () => ( {
|
|
31
|
-
insertedBlockAttributes: {
|
|
32
|
-
'some-attribute': 'some-value',
|
|
33
|
-
},
|
|
34
|
-
insertedBlockName: 'core/navigation-link',
|
|
35
|
-
} ) );
|
|
36
|
-
|
|
37
|
-
useDispatch.mockImplementation( () => ( {
|
|
38
|
-
updateBlockAttributes: mockUpdateBlockAttributes,
|
|
39
|
-
} ) );
|
|
40
|
-
|
|
41
|
-
const { result } = renderHook( () => useInsertedBlock() );
|
|
42
|
-
|
|
43
|
-
const {
|
|
44
|
-
insertedBlockName,
|
|
45
|
-
insertedBlockAttributes,
|
|
46
|
-
setInsertedBlockAttributes,
|
|
47
|
-
} = result.current;
|
|
48
|
-
|
|
49
|
-
expect( insertedBlockName ).toBeUndefined();
|
|
50
|
-
expect( insertedBlockAttributes ).toBeUndefined();
|
|
51
|
-
expect(
|
|
52
|
-
setInsertedBlockAttributes( { 'some-attribute': 'new-value' } )
|
|
53
|
-
).toBeUndefined();
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'returns name and attributes when called with a block clientId', () => {
|
|
57
|
-
useSelect.mockImplementation( () => ( {
|
|
58
|
-
insertedBlockAttributes: {
|
|
59
|
-
'some-attribute': 'some-value',
|
|
60
|
-
},
|
|
61
|
-
insertedBlockName: 'core/navigation-link',
|
|
62
|
-
} ) );
|
|
63
|
-
|
|
64
|
-
useDispatch.mockImplementation( () => ( {
|
|
65
|
-
updateBlockAttributes: mockUpdateBlockAttributes,
|
|
66
|
-
} ) );
|
|
67
|
-
|
|
68
|
-
const { result } = renderHook( () =>
|
|
69
|
-
useInsertedBlock( 'some-client-id-here' )
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const { insertedBlockName, insertedBlockAttributes } = result.current;
|
|
73
|
-
|
|
74
|
-
expect( insertedBlockName ).toBe( 'core/navigation-link' );
|
|
75
|
-
expect( insertedBlockAttributes ).toEqual( {
|
|
76
|
-
'some-attribute': 'some-value',
|
|
77
|
-
} );
|
|
78
|
-
} );
|
|
79
|
-
|
|
80
|
-
it( 'dispatches updateBlockAttributes on provided client ID with new attributes when setInsertedBlockAttributes is called', () => {
|
|
81
|
-
useSelect.mockImplementation( () => ( {
|
|
82
|
-
insertedBlockAttributes: {
|
|
83
|
-
'some-attribute': 'some-value',
|
|
84
|
-
},
|
|
85
|
-
insertedBlockName: 'core/navigation-link',
|
|
86
|
-
} ) );
|
|
87
|
-
|
|
88
|
-
useDispatch.mockImplementation( () => ( {
|
|
89
|
-
updateBlockAttributes: mockUpdateBlockAttributes,
|
|
90
|
-
} ) );
|
|
91
|
-
|
|
92
|
-
const clientId = '123456789';
|
|
93
|
-
|
|
94
|
-
const { result } = renderHook( () => useInsertedBlock( clientId ) );
|
|
95
|
-
|
|
96
|
-
const { setInsertedBlockAttributes } = result.current;
|
|
97
|
-
|
|
98
|
-
act( () => {
|
|
99
|
-
setInsertedBlockAttributes( {
|
|
100
|
-
'some-attribute': 'new-value',
|
|
101
|
-
} );
|
|
102
|
-
} );
|
|
103
|
-
|
|
104
|
-
expect( mockUpdateBlockAttributes ).toHaveBeenCalledWith( clientId, {
|
|
105
|
-
'some-attribute': 'new-value',
|
|
106
|
-
} );
|
|
107
|
-
} );
|
|
108
|
-
} );
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { getCommonDepthClientIds } from '../utils';
|
|
5
|
-
|
|
6
|
-
describe( 'getCommonDepthClientIds', () => {
|
|
7
|
-
it( 'should return start and end when no depth is provided', () => {
|
|
8
|
-
const result = getCommonDepthClientIds(
|
|
9
|
-
'start-id',
|
|
10
|
-
'clicked-id',
|
|
11
|
-
[],
|
|
12
|
-
[]
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
expect( result ).toEqual( { start: 'start-id', end: 'clicked-id' } );
|
|
16
|
-
} );
|
|
17
|
-
|
|
18
|
-
it( 'should return deepest start and end when depths match', () => {
|
|
19
|
-
const result = getCommonDepthClientIds(
|
|
20
|
-
'start-id',
|
|
21
|
-
'clicked-id',
|
|
22
|
-
[ 'start-1', 'start-2', 'start-3' ],
|
|
23
|
-
[ 'end-1', 'end-2', 'end-3' ]
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
expect( result ).toEqual( { start: 'start-id', end: 'clicked-id' } );
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
it( 'should return shallower ids when start is shallower', () => {
|
|
30
|
-
const result = getCommonDepthClientIds(
|
|
31
|
-
'start-id',
|
|
32
|
-
'clicked-id',
|
|
33
|
-
[ 'start-1' ],
|
|
34
|
-
[ 'end-1', 'end-2', 'end-3' ]
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
expect( result ).toEqual( { start: 'start-id', end: 'end-2' } );
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
it( 'should return shallower ids when end is shallower', () => {
|
|
41
|
-
const result = getCommonDepthClientIds(
|
|
42
|
-
'start-id',
|
|
43
|
-
'clicked-id',
|
|
44
|
-
[ 'start-1', 'start-2', 'start-3' ],
|
|
45
|
-
[ 'end-1', 'end-2' ]
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect( result ).toEqual( { start: 'start-3', end: 'clicked-id' } );
|
|
49
|
-
} );
|
|
50
|
-
} );
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { escapeHTML } from '@wordpress/escape-html';
|
|
5
|
-
import { safeDecodeURI } from '@wordpress/url';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Navigation Link Block Attributes
|
|
12
|
-
*
|
|
13
|
-
* @typedef {Object} WPNavigationLinkBlockAttributes
|
|
14
|
-
*
|
|
15
|
-
* @property {string} [label] Link text.
|
|
16
|
-
* @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status.
|
|
17
|
-
* @property {string} [type] The type such as post, page, tag, category and other custom types.
|
|
18
|
-
* @property {string} [rel] The relationship of the linked URL.
|
|
19
|
-
* @property {number} [id] A post or term id.
|
|
20
|
-
* @property {boolean} [opensInNewTab] Sets link target to _blank when true.
|
|
21
|
-
* @property {string} [url] Link href.
|
|
22
|
-
* @property {string} [title] Link title attribute.
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* Link Control onChange handler that updates block attributes when a setting is changed.
|
|
26
|
-
*
|
|
27
|
-
* @param {Object} updatedValue New block attributes to update.
|
|
28
|
-
* @param {Function} setAttributes Block attribute update function.
|
|
29
|
-
* @param {WPNavigationLinkBlockAttributes} blockAttributes Current block attributes.
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
export const updateAttributes = (
|
|
34
|
-
updatedValue = {},
|
|
35
|
-
setAttributes,
|
|
36
|
-
blockAttributes = {}
|
|
37
|
-
) => {
|
|
38
|
-
const {
|
|
39
|
-
label: originalLabel = '',
|
|
40
|
-
kind: originalKind = '',
|
|
41
|
-
type: originalType = '',
|
|
42
|
-
} = blockAttributes;
|
|
43
|
-
|
|
44
|
-
const {
|
|
45
|
-
title: newLabel = '', // the title of any provided Post.
|
|
46
|
-
url: newUrl = '',
|
|
47
|
-
opensInNewTab,
|
|
48
|
-
id,
|
|
49
|
-
kind: newKind = originalKind,
|
|
50
|
-
type: newType = originalType,
|
|
51
|
-
} = updatedValue;
|
|
52
|
-
|
|
53
|
-
const newLabelWithoutHttp = newLabel.replace( /http(s?):\/\//gi, '' );
|
|
54
|
-
const newUrlWithoutHttp = newUrl.replace( /http(s?):\/\//gi, '' );
|
|
55
|
-
|
|
56
|
-
const useNewLabel =
|
|
57
|
-
newLabel &&
|
|
58
|
-
newLabel !== originalLabel &&
|
|
59
|
-
// LinkControl without the title field relies
|
|
60
|
-
// on the check below. Specifically, it assumes that
|
|
61
|
-
// the URL is the same as a title.
|
|
62
|
-
// This logic a) looks suspicious and b) should really
|
|
63
|
-
// live in the LinkControl and not here. It's a great
|
|
64
|
-
// candidate for future refactoring.
|
|
65
|
-
newLabelWithoutHttp !== newUrlWithoutHttp;
|
|
66
|
-
|
|
67
|
-
// Unfortunately this causes the escaping model to be inverted.
|
|
68
|
-
// The escaped content is stored in the block attributes (and ultimately in the database),
|
|
69
|
-
// and then the raw data is "recovered" when outputting into the DOM.
|
|
70
|
-
// It would be preferable to store the **raw** data in the block attributes and escape it in JS.
|
|
71
|
-
// Why? Because there isn't one way to escape data. Depending on the context, you need to do
|
|
72
|
-
// different transforms. It doesn't make sense to me to choose one of them for the purposes of storage.
|
|
73
|
-
// See also:
|
|
74
|
-
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
75
|
-
// - https://github.com/WordPress/gutenberg/pull/18617.
|
|
76
|
-
const label = useNewLabel
|
|
77
|
-
? escapeHTML( newLabel )
|
|
78
|
-
: originalLabel || escapeHTML( newUrlWithoutHttp );
|
|
79
|
-
|
|
80
|
-
// In https://github.com/WordPress/gutenberg/pull/24670 we decided to use "tag" in favor of "post_tag"
|
|
81
|
-
const type = newType === 'post_tag' ? 'tag' : newType.replace( '-', '_' );
|
|
82
|
-
|
|
83
|
-
const isBuiltInType =
|
|
84
|
-
[ 'post', 'page', 'tag', 'category' ].indexOf( type ) > -1;
|
|
85
|
-
|
|
86
|
-
const isCustomLink =
|
|
87
|
-
( ! newKind && ! isBuiltInType ) || newKind === 'custom';
|
|
88
|
-
const kind = isCustomLink ? 'custom' : newKind;
|
|
89
|
-
|
|
90
|
-
setAttributes( {
|
|
91
|
-
// Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string.
|
|
92
|
-
...( newUrl && { url: encodeURI( safeDecodeURI( newUrl ) ) } ),
|
|
93
|
-
...( label && { label } ),
|
|
94
|
-
...( undefined !== opensInNewTab && { opensInNewTab } ),
|
|
95
|
-
...( id && Number.isInteger( id ) && { id } ),
|
|
96
|
-
...( kind && { kind } ),
|
|
97
|
-
...( type && type !== 'URL' && { type } ),
|
|
98
|
-
} );
|
|
99
|
-
};
|