@wordpress/block-library 7.2.0 → 7.3.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 +1 -1
- package/build/archives/edit.js +21 -1
- package/build/archives/edit.js.map +1 -1
- package/build/archives/index.js +5 -1
- package/build/archives/index.js.map +1 -1
- package/build/audio/edit.native.js +0 -5
- package/build/audio/edit.native.js.map +1 -1
- package/build/avatar/edit.js +17 -11
- package/build/avatar/edit.js.map +1 -1
- package/build/block/edit.js +2 -1
- package/build/block/edit.js.map +1 -1
- package/build/column/index.js +1 -0
- package/build/column/index.js.map +1 -1
- package/build/comment-author-avatar/index.js +3 -3
- package/build/comment-author-name/index.js +7 -3
- package/build/comment-author-name/index.js.map +1 -1
- package/build/comment-content/index.js +1 -1
- package/build/comment-date/index.js +7 -3
- package/build/comment-date/index.js.map +1 -1
- package/build/comment-edit-link/index.js +5 -1
- package/build/comment-edit-link/index.js.map +1 -1
- package/build/comment-reply-link/index.js +5 -1
- package/build/comment-reply-link/index.js.map +1 -1
- package/build/comment-template/edit.js +7 -14
- package/build/comment-template/edit.js.map +1 -1
- package/build/comment-template/hooks.js +7 -23
- package/build/comment-template/hooks.js.map +1 -1
- package/build/comment-template/index.js +2 -2
- package/build/comments-pagination-next/index.js +2 -2
- package/build/comments-pagination-numbers/index.js +1 -1
- package/build/comments-pagination-previous/index.js +1 -1
- package/build/comments-query-loop/edit/comments-inspector-controls.js +2 -69
- package/build/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
- package/build/comments-query-loop/edit.js +22 -1
- package/build/comments-query-loop/edit.js.map +1 -1
- package/build/comments-query-loop/index.js +1 -23
- package/build/comments-query-loop/index.js.map +1 -1
- package/build/cover/edit.js +35 -6
- package/build/cover/edit.js.map +1 -1
- package/build/cover/index.js +5 -0
- package/build/cover/index.js.map +1 -1
- package/build/cover/save.js +3 -2
- package/build/cover/save.js.map +1 -1
- package/build/gallery/gap-styles.js +8 -2
- package/build/gallery/gap-styles.js.map +1 -1
- package/build/gallery/index.js +1 -0
- package/build/gallery/index.js.map +1 -1
- package/build/group/edit.js +3 -1
- package/build/group/edit.js.map +1 -1
- package/build/group/index.js +2 -4
- package/build/group/index.js.map +1 -1
- package/build/group/variations.js +31 -9
- package/build/group/variations.js.map +1 -1
- package/build/heading/edit.js +1 -1
- package/build/heading/edit.js.map +1 -1
- package/build/html/edit.js +3 -2
- package/build/html/edit.js.map +1 -1
- package/build/image/edit.native.js +8 -10
- package/build/image/edit.native.js.map +1 -1
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/list/deprecated.js +2 -2
- package/build/list/deprecated.js.map +1 -1
- package/build/list/v2/deprecated.js +117 -0
- package/build/list/v2/deprecated.js.map +1 -0
- package/build/list/v2/edit.js +106 -3
- package/build/list/v2/edit.js.map +1 -1
- package/build/list/v2/index.js +4 -1
- package/build/list/v2/index.js.map +1 -1
- package/build/list/v2/migrate.js +85 -0
- package/build/list/v2/migrate.js.map +1 -0
- package/build/list-item/edit.js +59 -10
- package/build/list-item/edit.js.map +1 -1
- package/build/list-item/hooks/index.js +32 -0
- package/build/list-item/hooks/index.js.map +1 -0
- package/build/list-item/hooks/use-enter.js +93 -0
- package/build/list-item/hooks/use-enter.js.map +1 -0
- package/build/list-item/hooks/use-indent-list-item.js +74 -0
- package/build/list-item/hooks/use-indent-list-item.js.map +1 -0
- package/build/list-item/hooks/use-outdent-list-item.js +77 -0
- package/build/list-item/hooks/use-outdent-list-item.js.map +1 -0
- package/build/list-item/index.js +1 -1
- package/build/list-item/index.js.map +1 -1
- package/build/list-item/utils.js +16 -0
- package/build/list-item/utils.js.map +1 -0
- package/build/media-text/media-container.native.js +1 -16
- package/build/media-text/media-container.native.js.map +1 -1
- package/build/navigation/edit/index.js +36 -17
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/navigation-menu-delete-control.js +1 -1
- package/build/navigation/edit/navigation-menu-delete-control.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +34 -7
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/index.js +9 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/use-navigation-menu.js +1 -0
- package/build/navigation/use-navigation-menu.js.map +1 -1
- package/build/navigation-link/edit.js +9 -5
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/index.js +1 -1
- package/build/navigation-submenu/edit.js +5 -9
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/navigation-submenu/index.js +1 -1
- package/build/post-comment/edit.js +2 -2
- package/build/post-comment/edit.js.map +1 -1
- package/build/post-comments-form/edit.js +3 -2
- package/build/post-comments-form/edit.js.map +1 -1
- package/build/post-featured-image/index.js +1 -1
- package/build/post-template/edit.js +7 -2
- package/build/post-template/edit.js.map +1 -1
- package/build/post-terms/edit.js +3 -1
- package/build/post-terms/edit.js.map +1 -1
- package/build/post-terms/variations.js +1 -1
- package/build/post-terms/variations.js.map +1 -1
- package/build/query-pagination/edit.js +1 -1
- package/build/query-pagination/edit.js.map +1 -1
- package/build/query-pagination-numbers/index.js +19 -1
- package/build/query-pagination-numbers/index.js.map +1 -1
- package/build/quote/index.js +15 -8
- package/build/quote/index.js.map +1 -1
- package/build/quote/v2/deprecated.js +133 -0
- package/build/quote/v2/deprecated.js.map +1 -0
- package/build/quote/v2/edit.js +131 -0
- package/build/quote/v2/edit.js.map +1 -0
- package/build/quote/v2/index.js +49 -0
- package/build/quote/v2/index.js.map +1 -0
- package/build/quote/v2/save.js +43 -0
- package/build/quote/v2/save.js.map +1 -0
- package/build/quote/v2/transforms.js +156 -0
- package/build/quote/v2/transforms.js.map +1 -0
- package/build/read-more/index.js +1 -1
- package/build/rss/edit.js +6 -1
- package/build/rss/edit.js.map +1 -1
- package/build/site-logo/edit.js +3 -2
- package/build/site-logo/edit.js.map +1 -1
- package/build/site-logo/index.js +1 -1
- package/build/social-links/index.js +1 -0
- package/build/social-links/index.js.map +1 -1
- package/build/spacer/controls.native.js +1 -1
- package/build/spacer/controls.native.js.map +1 -1
- package/build/template-part/edit/utils/hooks.js +5 -2
- package/build/template-part/edit/utils/hooks.js.map +1 -1
- package/build-module/archives/edit.js +22 -2
- package/build-module/archives/edit.js.map +1 -1
- package/build-module/archives/index.js +5 -1
- package/build-module/archives/index.js.map +1 -1
- package/build-module/audio/edit.native.js +0 -5
- package/build-module/audio/edit.native.js.map +1 -1
- package/build-module/avatar/edit.js +16 -11
- package/build-module/avatar/edit.js.map +1 -1
- package/build-module/block/edit.js +4 -3
- package/build-module/block/edit.js.map +1 -1
- package/build-module/column/index.js +1 -0
- package/build-module/column/index.js.map +1 -1
- package/build-module/comment-author-avatar/index.js +3 -3
- package/build-module/comment-author-name/index.js +7 -3
- package/build-module/comment-author-name/index.js.map +1 -1
- package/build-module/comment-content/index.js +1 -1
- package/build-module/comment-date/index.js +7 -3
- package/build-module/comment-date/index.js.map +1 -1
- package/build-module/comment-edit-link/index.js +5 -1
- package/build-module/comment-edit-link/index.js.map +1 -1
- package/build-module/comment-reply-link/index.js +5 -1
- package/build-module/comment-reply-link/index.js.map +1 -1
- package/build-module/comment-template/edit.js +7 -14
- package/build-module/comment-template/edit.js.map +1 -1
- package/build-module/comment-template/hooks.js +7 -23
- package/build-module/comment-template/hooks.js.map +1 -1
- package/build-module/comment-template/index.js +2 -2
- package/build-module/comments-pagination-next/index.js +2 -2
- package/build-module/comments-pagination-numbers/index.js +1 -1
- package/build-module/comments-pagination-previous/index.js +1 -1
- package/build-module/comments-query-loop/edit/comments-inspector-controls.js +4 -70
- package/build-module/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
- package/build-module/comments-query-loop/edit.js +22 -1
- package/build-module/comments-query-loop/edit.js.map +1 -1
- package/build-module/comments-query-loop/index.js +1 -23
- package/build-module/comments-query-loop/index.js.map +1 -1
- package/build-module/cover/edit.js +36 -8
- package/build-module/cover/edit.js.map +1 -1
- package/build-module/cover/index.js +5 -0
- package/build-module/cover/index.js.map +1 -1
- package/build-module/cover/save.js +3 -2
- package/build-module/cover/save.js.map +1 -1
- package/build-module/gallery/gap-styles.js +8 -2
- package/build-module/gallery/gap-styles.js.map +1 -1
- package/build-module/gallery/index.js +1 -0
- package/build-module/gallery/index.js.map +1 -1
- package/build-module/group/edit.js +3 -1
- package/build-module/group/edit.js.map +1 -1
- package/build-module/group/index.js +2 -4
- package/build-module/group/index.js.map +1 -1
- package/build-module/group/variations.js +30 -9
- package/build-module/group/variations.js.map +1 -1
- package/build-module/heading/edit.js +1 -1
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/html/edit.js +4 -3
- package/build-module/html/edit.js.map +1 -1
- package/build-module/image/edit.native.js +8 -10
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/index.js +3 -3
- package/build-module/index.js.map +1 -1
- package/build-module/list/deprecated.js +2 -2
- package/build-module/list/deprecated.js.map +1 -1
- package/build-module/list/v2/deprecated.js +104 -0
- package/build-module/list/v2/deprecated.js.map +1 -0
- package/build-module/list/v2/edit.js +104 -5
- package/build-module/list/v2/edit.js.map +1 -1
- package/build-module/list/v2/index.js +3 -1
- package/build-module/list/v2/index.js.map +1 -1
- package/build-module/list/v2/migrate.js +77 -0
- package/build-module/list/v2/migrate.js.map +1 -0
- package/build-module/list-item/edit.js +59 -13
- package/build-module/list-item/edit.js.map +1 -1
- package/build-module/list-item/hooks/index.js +4 -0
- package/build-module/list-item/hooks/index.js.map +1 -0
- package/build-module/list-item/hooks/use-enter.js +77 -0
- package/build-module/list-item/hooks/use-enter.js.map +1 -0
- package/build-module/list-item/hooks/use-indent-list-item.js +62 -0
- package/build-module/list-item/hooks/use-indent-list-item.js.map +1 -0
- package/build-module/list-item/hooks/use-outdent-list-item.js +66 -0
- package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -0
- package/build-module/list-item/index.js +1 -1
- package/build-module/list-item/index.js.map +1 -1
- package/build-module/list-item/utils.js +8 -0
- package/build-module/list-item/utils.js.map +1 -0
- package/build-module/media-text/media-container.native.js +1 -14
- package/build-module/media-text/media-container.native.js.map +1 -1
- package/build-module/navigation/edit/index.js +37 -17
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-delete-control.js +1 -1
- package/build-module/navigation/edit/navigation-menu-delete-control.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +35 -8
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/index.js +9 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation/use-navigation-menu.js +1 -0
- package/build-module/navigation/use-navigation-menu.js.map +1 -1
- package/build-module/navigation-link/edit.js +9 -5
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/index.js +1 -1
- package/build-module/navigation-submenu/edit.js +6 -10
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/navigation-submenu/index.js +1 -1
- package/build-module/post-comment/edit.js +2 -2
- package/build-module/post-comment/edit.js.map +1 -1
- package/build-module/post-comments-form/edit.js +3 -2
- package/build-module/post-comments-form/edit.js.map +1 -1
- package/build-module/post-featured-image/index.js +1 -1
- package/build-module/post-template/edit.js +7 -2
- package/build-module/post-template/edit.js.map +1 -1
- package/build-module/post-terms/edit.js +4 -2
- package/build-module/post-terms/edit.js.map +1 -1
- package/build-module/post-terms/variations.js +3 -3
- package/build-module/post-terms/variations.js.map +1 -1
- package/build-module/query-pagination/edit.js +1 -1
- package/build-module/query-pagination/edit.js.map +1 -1
- package/build-module/query-pagination-numbers/index.js +19 -1
- package/build-module/query-pagination-numbers/index.js.map +1 -1
- package/build-module/quote/index.js +13 -1
- package/build-module/quote/index.js.map +1 -1
- package/build-module/quote/v2/deprecated.js +116 -0
- package/build-module/quote/v2/deprecated.js.map +1 -0
- package/build-module/quote/v2/edit.js +115 -0
- package/build-module/quote/v2/edit.js.map +1 -0
- package/build-module/quote/v2/index.js +33 -0
- package/build-module/quote/v2/index.js.map +1 -0
- package/build-module/quote/v2/save.js +30 -0
- package/build-module/quote/v2/save.js.map +1 -0
- package/build-module/quote/v2/transforms.js +147 -0
- package/build-module/quote/v2/transforms.js.map +1 -0
- package/build-module/read-more/index.js +1 -1
- package/build-module/rss/edit.js +5 -1
- package/build-module/rss/edit.js.map +1 -1
- package/build-module/site-logo/edit.js +3 -2
- package/build-module/site-logo/edit.js.map +1 -1
- package/build-module/site-logo/index.js +1 -1
- package/build-module/social-links/index.js +1 -0
- package/build-module/social-links/index.js.map +1 -1
- package/build-module/spacer/controls.native.js +1 -1
- package/build-module/spacer/controls.native.js.map +1 -1
- package/build-module/template-part/edit/utils/hooks.js +5 -2
- package/build-module/template-part/edit/utils/hooks.js.map +1 -1
- package/build-style/avatar/editor-rtl.css +4 -0
- package/build-style/avatar/editor.css +4 -0
- package/build-style/avatar/style-rtl.css +79 -0
- package/build-style/avatar/style.css +79 -0
- package/build-style/editor-rtl.css +30 -9
- package/build-style/editor.css +30 -9
- package/build-style/group/editor-rtl.css +26 -0
- package/build-style/group/editor.css +26 -0
- package/build-style/heading/style-rtl.css +0 -8
- package/build-style/heading/style.css +0 -8
- package/build-style/list/style-rtl.css +1 -1
- package/build-style/list/style.css +1 -1
- package/build-style/navigation/style-rtl.css +11 -9
- package/build-style/navigation/style.css +11 -9
- package/build-style/navigation-link/style-rtl.css +3 -0
- package/build-style/navigation-link/style.css +3 -0
- package/build-style/paragraph/style-rtl.css +0 -4
- package/build-style/paragraph/style.css +0 -4
- package/build-style/quote/style-rtl.css +1 -0
- package/build-style/quote/style.css +1 -0
- package/build-style/reset-rtl.css +1 -1
- package/build-style/reset.css +1 -1
- package/build-style/style-rtl.css +20 -22
- package/build-style/style.css +20 -22
- package/build-style/template-part/editor-rtl.css +0 -9
- package/build-style/template-part/editor.css +0 -9
- package/package.json +28 -28
- package/src/archives/block.json +5 -1
- package/src/archives/edit.js +20 -2
- package/src/archives/index.php +4 -4
- package/src/audio/edit.native.js +0 -5
- package/src/avatar/edit.js +21 -13
- package/src/avatar/editor.scss +6 -0
- package/src/avatar/index.php +2 -2
- package/src/avatar/style.scss +5 -0
- package/src/block/edit.js +21 -11
- package/src/column/block.json +1 -0
- package/src/comment-author-avatar/block.json +3 -3
- package/src/comment-author-name/block.json +7 -3
- package/src/comment-author-name/index.php +3 -0
- package/src/comment-content/block.json +1 -1
- package/src/comment-date/block.json +7 -3
- package/src/comment-date/index.php +6 -1
- package/src/comment-edit-link/block.json +5 -1
- package/src/comment-edit-link/index.php +3 -0
- package/src/comment-reply-link/block.json +5 -1
- package/src/comment-reply-link/index.php +4 -1
- package/src/comment-template/block.json +2 -8
- package/src/comment-template/edit.js +12 -20
- package/src/comment-template/hooks.js +8 -24
- package/src/comment-template/index.php +1 -3
- package/src/comments-pagination-next/block.json +2 -9
- package/src/comments-pagination-numbers/block.json +2 -8
- package/src/comments-pagination-previous/block.json +2 -2
- package/src/comments-query-loop/block.json +1 -23
- package/src/comments-query-loop/edit/comments-inspector-controls.js +2 -83
- package/src/comments-query-loop/edit.js +54 -1
- package/src/cover/block.json +5 -0
- package/src/cover/edit.js +77 -29
- package/src/cover/index.php +85 -0
- package/src/cover/save.js +18 -14
- package/src/gallery/block.json +1 -0
- package/src/gallery/gap-styles.js +9 -4
- package/src/gallery/index.php +7 -6
- package/src/group/block.json +2 -4
- package/src/group/edit.js +4 -1
- package/src/group/editor.scss +31 -0
- package/src/group/variations.js +21 -4
- package/src/heading/edit.js +1 -1
- package/src/heading/style.scss +0 -3
- package/src/html/edit.js +22 -30
- package/src/image/edit.native.js +7 -11
- package/src/index.js +15 -15
- package/src/list/deprecated.js +2 -2
- package/src/list/style.scss +1 -2
- package/src/list/test/migrate.js +159 -0
- package/src/list/v2/deprecated.js +89 -0
- package/src/list/v2/edit.js +110 -1
- package/src/list/v2/index.js +2 -0
- package/src/list/v2/migrate.js +87 -0
- package/src/list-item/edit.js +69 -23
- package/src/list-item/hooks/index.js +3 -0
- package/src/list-item/hooks/use-enter.js +94 -0
- package/src/list-item/hooks/use-indent-list-item.js +89 -0
- package/src/list-item/hooks/use-outdent-list-item.js +95 -0
- package/src/list-item/index.js +1 -1
- package/src/list-item/utils.js +14 -0
- package/src/media-text/media-container.native.js +1 -14
- package/src/navigation/block.json +9 -1
- package/src/navigation/edit/index.js +50 -14
- package/src/navigation/edit/navigation-menu-delete-control.js +1 -1
- package/src/navigation/edit/unsaved-inner-blocks.js +57 -8
- package/src/navigation/index.php +6 -1
- package/src/navigation/style.scss +15 -13
- package/src/navigation/use-navigation-menu.js +4 -0
- package/src/navigation-link/block.json +1 -0
- package/src/navigation-link/edit.js +43 -35
- package/src/navigation-link/index.php +8 -0
- package/src/navigation-link/style.scss +6 -0
- package/src/navigation-submenu/block.json +1 -0
- package/src/navigation-submenu/edit.js +7 -9
- package/src/paragraph/style.scss +0 -5
- package/src/post-author/index.php +0 -1
- package/src/post-comment/edit.js +2 -2
- package/src/post-comments-form/edit.js +6 -3
- package/src/post-featured-image/block.json +1 -1
- package/src/post-template/edit.js +7 -1
- package/src/post-terms/edit.js +4 -1
- package/src/post-terms/variations.js +3 -3
- package/src/query-pagination/edit.js +1 -1
- package/src/query-pagination/index.php +9 -2
- package/src/query-pagination-numbers/block.json +19 -1
- package/src/quote/block.json +8 -0
- package/src/quote/index.js +6 -1
- package/src/quote/style.scss +1 -0
- package/src/quote/v2/deprecated.js +107 -0
- package/src/quote/v2/edit.js +136 -0
- package/src/quote/v2/index.js +36 -0
- package/src/quote/v2/save.js +26 -0
- package/src/quote/v2/test/migrate.js +92 -0
- package/src/quote/v2/transforms.js +155 -0
- package/src/read-more/block.json +1 -1
- package/src/reset.scss +1 -1
- package/src/rss/edit.js +3 -1
- package/src/rss/index.php +14 -1
- package/src/site-logo/block.json +1 -1
- package/src/site-logo/edit.js +2 -1
- package/src/site-logo/index.php +0 -4
- package/src/social-link/index.php +1 -2
- package/src/social-links/block.json +1 -0
- package/src/spacer/controls.native.js +1 -1
- package/src/spacer/test/__snapshots__/index.native.js.snap +31 -0
- package/src/spacer/test/index.native.js +180 -0
- package/src/style.scss +1 -0
- package/src/template-part/edit/utils/hooks.js +6 -1
- package/src/template-part/editor.scss +0 -10
- package/build/navigation/edit/use-list-view-modal.js +0 -73
- package/build/navigation/edit/use-list-view-modal.js.map +0 -1
- package/build-module/navigation/edit/use-list-view-modal.js +0 -63
- package/build-module/navigation/edit/use-list-view-modal.js.map +0 -1
- package/src/navigation/edit/use-list-view-modal.js +0 -72
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
createBlock,
|
|
6
|
+
getDefaultBlockName,
|
|
7
|
+
cloneBlock,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
9
|
+
import { useRef } from '@wordpress/element';
|
|
10
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
11
|
+
import { ENTER } from '@wordpress/keycodes';
|
|
12
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
13
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
import useIndentListItem from './use-indent-list-item';
|
|
19
|
+
|
|
20
|
+
export default function useEnter( props ) {
|
|
21
|
+
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
22
|
+
const {
|
|
23
|
+
getBlock,
|
|
24
|
+
getBlockRootClientId,
|
|
25
|
+
getBlockParents,
|
|
26
|
+
getBlockIndex,
|
|
27
|
+
} = useSelect( blockEditorStore );
|
|
28
|
+
const propsRef = useRef( props );
|
|
29
|
+
propsRef.current = props;
|
|
30
|
+
const [ canIndent, indentListItem ] = useIndentListItem(
|
|
31
|
+
propsRef.current.clientId
|
|
32
|
+
);
|
|
33
|
+
return useRefEffect(
|
|
34
|
+
( element ) => {
|
|
35
|
+
function onKeyDown( event ) {
|
|
36
|
+
if ( event.defaultPrevented || event.keyCode !== ENTER ) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const { content, clientId } = propsRef.current;
|
|
40
|
+
if ( content.length ) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
if ( canIndent ) {
|
|
45
|
+
indentListItem();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Here we are in top level list so we need to split.
|
|
49
|
+
const blockRootClientId = getBlockRootClientId( clientId );
|
|
50
|
+
const blockParents = getBlockParents( clientId );
|
|
51
|
+
const topParentListBlockClientId = blockParents[ 0 ];
|
|
52
|
+
const topParentListBlock = getBlock(
|
|
53
|
+
topParentListBlockClientId
|
|
54
|
+
);
|
|
55
|
+
const blockIndex = getBlockIndex( clientId );
|
|
56
|
+
const head = cloneBlock( {
|
|
57
|
+
...topParentListBlock,
|
|
58
|
+
innerBlocks: topParentListBlock.innerBlocks.slice(
|
|
59
|
+
0,
|
|
60
|
+
blockIndex
|
|
61
|
+
),
|
|
62
|
+
} );
|
|
63
|
+
const middle = createBlock( getDefaultBlockName() );
|
|
64
|
+
// Last list item might contain a `list` block innerBlock
|
|
65
|
+
// In that case append remaining innerBlocks blocks.
|
|
66
|
+
const after = [
|
|
67
|
+
...( topParentListBlock.innerBlocks[ blockIndex ]
|
|
68
|
+
.innerBlocks[ 0 ]?.innerBlocks || [] ),
|
|
69
|
+
...topParentListBlock.innerBlocks.slice( blockIndex + 1 ),
|
|
70
|
+
];
|
|
71
|
+
const tail = after.length
|
|
72
|
+
? [
|
|
73
|
+
cloneBlock( {
|
|
74
|
+
...topParentListBlock,
|
|
75
|
+
innerBlocks: after,
|
|
76
|
+
} ),
|
|
77
|
+
]
|
|
78
|
+
: [];
|
|
79
|
+
replaceBlocks(
|
|
80
|
+
blockRootClientId,
|
|
81
|
+
[ head, middle, ...tail ],
|
|
82
|
+
1,
|
|
83
|
+
0
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
element.addEventListener( 'keydown', onKeyDown );
|
|
88
|
+
return () => {
|
|
89
|
+
element.removeEventListener( 'keydown', onKeyDown );
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
[ canIndent ]
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { first } from 'lodash';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useCallback } from '@wordpress/element';
|
|
10
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { createListItem } from '../utils';
|
|
17
|
+
|
|
18
|
+
export default function useIndentListItem( clientId ) {
|
|
19
|
+
const { canIndent } = useSelect(
|
|
20
|
+
( innerSelect ) => {
|
|
21
|
+
const { getBlockIndex } = innerSelect( blockEditorStore );
|
|
22
|
+
return {
|
|
23
|
+
canIndent: getBlockIndex( clientId ) > 0,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
[ clientId ]
|
|
27
|
+
);
|
|
28
|
+
const { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );
|
|
29
|
+
const {
|
|
30
|
+
getBlockRootClientId,
|
|
31
|
+
getBlock,
|
|
32
|
+
getBlockOrder,
|
|
33
|
+
getSelectionStart,
|
|
34
|
+
getSelectionEnd,
|
|
35
|
+
getBlockIndex,
|
|
36
|
+
} = useSelect( blockEditorStore );
|
|
37
|
+
|
|
38
|
+
return [
|
|
39
|
+
canIndent,
|
|
40
|
+
useCallback( () => {
|
|
41
|
+
const selectionStart = getSelectionStart();
|
|
42
|
+
const selectionEnd = getSelectionEnd();
|
|
43
|
+
|
|
44
|
+
const parentId = getBlockRootClientId( clientId );
|
|
45
|
+
const previousSiblingId = getBlockOrder( parentId )[
|
|
46
|
+
getBlockIndex( clientId ) - 1
|
|
47
|
+
];
|
|
48
|
+
const previousSibling = getBlock( previousSiblingId );
|
|
49
|
+
const previousSiblingChildren =
|
|
50
|
+
first( previousSibling.innerBlocks )?.innerBlocks || [];
|
|
51
|
+
const previousSiblingListAttributes =
|
|
52
|
+
first( previousSibling.innerBlocks )?.attributes || {};
|
|
53
|
+
const block = getBlock( clientId );
|
|
54
|
+
|
|
55
|
+
const childListAttributes = first( block.innerBlocks )?.attributes;
|
|
56
|
+
const childItemBlocks =
|
|
57
|
+
first( block.innerBlocks )?.innerBlocks || [];
|
|
58
|
+
|
|
59
|
+
const newBlock = createListItem(
|
|
60
|
+
block.attributes,
|
|
61
|
+
childListAttributes,
|
|
62
|
+
childItemBlocks
|
|
63
|
+
);
|
|
64
|
+
// Replace the previous sibling of the block being indented and the indented block,
|
|
65
|
+
// with a new block whose attributes are equal to the ones of the previous sibling and
|
|
66
|
+
// whose descendants are the children of the previous sibling, followed by the indented block.
|
|
67
|
+
replaceBlocks(
|
|
68
|
+
[ previousSiblingId, clientId ],
|
|
69
|
+
[
|
|
70
|
+
createListItem(
|
|
71
|
+
previousSibling.attributes,
|
|
72
|
+
previousSiblingListAttributes,
|
|
73
|
+
[ ...previousSiblingChildren, newBlock ]
|
|
74
|
+
),
|
|
75
|
+
]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Restore the selection state.
|
|
79
|
+
selectionChange(
|
|
80
|
+
newBlock.clientId,
|
|
81
|
+
selectionEnd.attributeKey,
|
|
82
|
+
selectionEnd.clientId === selectionStart.clientId
|
|
83
|
+
? selectionStart.offset
|
|
84
|
+
: selectionEnd.offset,
|
|
85
|
+
selectionEnd.offset
|
|
86
|
+
);
|
|
87
|
+
}, [ clientId ] ),
|
|
88
|
+
];
|
|
89
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback } from '@wordpress/element';
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { createListItem } from '../utils';
|
|
12
|
+
|
|
13
|
+
export default function useOutdentListItem( clientId ) {
|
|
14
|
+
const { canOutdent } = useSelect(
|
|
15
|
+
( innerSelect ) => {
|
|
16
|
+
const { getBlockRootClientId } = innerSelect( blockEditorStore );
|
|
17
|
+
const grandParentId = getBlockRootClientId(
|
|
18
|
+
getBlockRootClientId( clientId )
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
canOutdent: !! grandParentId,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
[ clientId ]
|
|
25
|
+
);
|
|
26
|
+
const { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );
|
|
27
|
+
const {
|
|
28
|
+
getBlockRootClientId,
|
|
29
|
+
getBlockAttributes,
|
|
30
|
+
getBlock,
|
|
31
|
+
getBlockIndex,
|
|
32
|
+
getSelectionStart,
|
|
33
|
+
getSelectionEnd,
|
|
34
|
+
} = useSelect( blockEditorStore );
|
|
35
|
+
|
|
36
|
+
return [
|
|
37
|
+
canOutdent,
|
|
38
|
+
useCallback( () => {
|
|
39
|
+
const selectionStart = getSelectionStart();
|
|
40
|
+
const selectionEnd = getSelectionEnd();
|
|
41
|
+
|
|
42
|
+
const listParentId = getBlockRootClientId( clientId );
|
|
43
|
+
const listAttributes = getBlockAttributes( listParentId );
|
|
44
|
+
const listItemParentId = getBlockRootClientId( listParentId );
|
|
45
|
+
const listItemParentAttributes = getBlockAttributes(
|
|
46
|
+
listItemParentId
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const index = getBlockIndex( clientId );
|
|
50
|
+
const siblingBlocks = getBlock( listParentId ).innerBlocks;
|
|
51
|
+
const previousSiblings = siblingBlocks.slice( 0, index );
|
|
52
|
+
const afterSiblings = siblingBlocks.slice( index + 1 );
|
|
53
|
+
|
|
54
|
+
// Create a new parent list item block with just the siblings
|
|
55
|
+
// that existed before the child item being outdent.
|
|
56
|
+
const newListItemParent = createListItem(
|
|
57
|
+
listItemParentAttributes,
|
|
58
|
+
listAttributes,
|
|
59
|
+
previousSiblings
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const block = getBlock( clientId );
|
|
63
|
+
const childList = block.innerBlocks[ 0 ];
|
|
64
|
+
const childItems = childList?.innerBlocks || [];
|
|
65
|
+
const hasChildItems = !! childItems.length;
|
|
66
|
+
|
|
67
|
+
// Create a new list item block whose attributes are equal to the
|
|
68
|
+
// block being outdent and whose children are the children that it had (if any)
|
|
69
|
+
// followed by the siblings that existed after it.
|
|
70
|
+
const newItem = createListItem(
|
|
71
|
+
block.attributes,
|
|
72
|
+
hasChildItems ? childList.attributes : listAttributes,
|
|
73
|
+
[ ...childItems, ...afterSiblings ]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Replace the parent list item block, with a new block containing
|
|
77
|
+
// the previous siblings, followed by another block containing after siblings
|
|
78
|
+
// in relation to the block being outdent.
|
|
79
|
+
replaceBlocks(
|
|
80
|
+
[ listItemParentId ],
|
|
81
|
+
[ newListItemParent, newItem ]
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// Restore the selection state.
|
|
85
|
+
selectionChange(
|
|
86
|
+
newItem.clientId,
|
|
87
|
+
selectionEnd.attributeKey,
|
|
88
|
+
selectionEnd.clientId === selectionStart.clientId
|
|
89
|
+
? selectionStart.offset
|
|
90
|
+
: selectionEnd.offset,
|
|
91
|
+
selectionEnd.offset
|
|
92
|
+
);
|
|
93
|
+
}, [ clientId ] ),
|
|
94
|
+
];
|
|
95
|
+
}
|
package/src/list-item/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createBlock } from '@wordpress/blocks';
|
|
5
|
+
|
|
6
|
+
export function createListItem( listItemAttributes, listAttributes, children ) {
|
|
7
|
+
return createBlock(
|
|
8
|
+
'core/list-item',
|
|
9
|
+
listItemAttributes,
|
|
10
|
+
! children || ! children.length
|
|
11
|
+
? []
|
|
12
|
+
: [ createBlock( 'core/list', listAttributes, children ) ]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -26,8 +26,6 @@ import { Component } from '@wordpress/element';
|
|
|
26
26
|
import { __ } from '@wordpress/i18n';
|
|
27
27
|
import { isURL, getProtocol } from '@wordpress/url';
|
|
28
28
|
import { compose, withPreferredColorScheme } from '@wordpress/compose';
|
|
29
|
-
import { withDispatch } from '@wordpress/data';
|
|
30
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* Internal dependencies
|
|
@@ -152,10 +150,6 @@ class MediaContainer extends Component {
|
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
finishMediaUploadWithFailure() {
|
|
155
|
-
const { createErrorNotice } = this.props;
|
|
156
|
-
|
|
157
|
-
createErrorNotice( __( 'Failed to insert media.' ) );
|
|
158
|
-
|
|
159
153
|
this.setState( { isUploadInProgress: false } );
|
|
160
154
|
}
|
|
161
155
|
|
|
@@ -381,11 +375,4 @@ class MediaContainer extends Component {
|
|
|
381
375
|
}
|
|
382
376
|
}
|
|
383
377
|
|
|
384
|
-
export default compose( [
|
|
385
|
-
withDispatch( ( dispatch ) => {
|
|
386
|
-
const { createErrorNotice } = dispatch( noticesStore );
|
|
387
|
-
|
|
388
|
-
return { createErrorNotice };
|
|
389
|
-
} ),
|
|
390
|
-
withPreferredColorScheme,
|
|
391
|
-
] )( MediaContainer );
|
|
378
|
+
export default compose( [ withPreferredColorScheme ] )( MediaContainer );
|
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
},
|
|
60
60
|
"customOverlayTextColor": {
|
|
61
61
|
"type": "string"
|
|
62
|
+
},
|
|
63
|
+
"maxNestingLevel": {
|
|
64
|
+
"type": "number",
|
|
65
|
+
"default": 5
|
|
62
66
|
}
|
|
63
67
|
},
|
|
64
68
|
"usesContext": [ "navigationArea" ],
|
|
@@ -76,7 +80,8 @@
|
|
|
76
80
|
"showSubmenuIcon": "showSubmenuIcon",
|
|
77
81
|
"openSubmenusOnClick": "openSubmenusOnClick",
|
|
78
82
|
"style": "style",
|
|
79
|
-
"orientation": "orientation"
|
|
83
|
+
"orientation": "orientation",
|
|
84
|
+
"maxNestingLevel": "maxNestingLevel"
|
|
80
85
|
},
|
|
81
86
|
"supports": {
|
|
82
87
|
"align": [ "wide", "full" ],
|
|
@@ -90,6 +95,8 @@
|
|
|
90
95
|
"__experimentalFontWeight": true,
|
|
91
96
|
"__experimentalTextTransform": true,
|
|
92
97
|
"__experimentalFontFamily": true,
|
|
98
|
+
"__experimentalTextDecoration": true,
|
|
99
|
+
"__experimentalSkipSerialization": [ "textDecoration" ],
|
|
93
100
|
"__experimentalDefaultControls": {
|
|
94
101
|
"fontSize": true
|
|
95
102
|
}
|
|
@@ -104,6 +111,7 @@
|
|
|
104
111
|
"__experimentalLayout": {
|
|
105
112
|
"allowSwitching": false,
|
|
106
113
|
"allowInheriting": false,
|
|
114
|
+
"allowVerticalAlignment": false,
|
|
107
115
|
"default": {
|
|
108
116
|
"type": "flex"
|
|
109
117
|
}
|
|
@@ -38,13 +38,12 @@ import {
|
|
|
38
38
|
Button,
|
|
39
39
|
Spinner,
|
|
40
40
|
} from '@wordpress/components';
|
|
41
|
-
import { __ } from '@wordpress/i18n';
|
|
41
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
42
42
|
import { speak } from '@wordpress/a11y';
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Internal dependencies
|
|
46
46
|
*/
|
|
47
|
-
import useListViewModal from './use-list-view-modal';
|
|
48
47
|
import useNavigationMenu from '../use-navigation-menu';
|
|
49
48
|
import useNavigationEntities from '../use-navigation-entities';
|
|
50
49
|
import Placeholder from './placeholder';
|
|
@@ -167,6 +166,10 @@ function Navigation( {
|
|
|
167
166
|
// the Select Menu dropdown.
|
|
168
167
|
useNavigationEntities();
|
|
169
168
|
|
|
169
|
+
const [ showNavigationMenuDeleteNotice ] = useNavigationNotice( {
|
|
170
|
+
name: 'block-library/core/navigation/delete',
|
|
171
|
+
} );
|
|
172
|
+
|
|
170
173
|
const [
|
|
171
174
|
showNavigationMenuCreateNotice,
|
|
172
175
|
hideNavigationMenuCreateNotice,
|
|
@@ -267,6 +270,7 @@ function Navigation( {
|
|
|
267
270
|
const [ overlayMenuPreview, setOverlayMenuPreview ] = useState( false );
|
|
268
271
|
|
|
269
272
|
const {
|
|
273
|
+
hasResolvedNavigationMenus,
|
|
270
274
|
isNavigationMenuResolved,
|
|
271
275
|
isNavigationMenuMissing,
|
|
272
276
|
navigationMenus,
|
|
@@ -280,12 +284,25 @@ function Navigation( {
|
|
|
280
284
|
hasResolvedCanUserCreateNavigationMenu,
|
|
281
285
|
} = useNavigationMenu( ref );
|
|
282
286
|
|
|
287
|
+
// Attempt to retrieve and prioritize any existing navigation menu unless
|
|
288
|
+
// a specific ref is allocated or the user is explicitly creating a new menu. The aim is
|
|
289
|
+
// for the block to "just work" from a user perspective using existing data.
|
|
290
|
+
useEffect( () => {
|
|
291
|
+
if (
|
|
292
|
+
isCreatingNavigationMenu ||
|
|
293
|
+
ref ||
|
|
294
|
+
! navigationMenus?.length ||
|
|
295
|
+
navigationMenus?.length > 1
|
|
296
|
+
) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setRef( navigationMenus[ 0 ].id );
|
|
301
|
+
}, [ navigationMenus ] );
|
|
302
|
+
|
|
283
303
|
const navRef = useRef();
|
|
284
|
-
const isDraftNavigationMenu = navigationMenu?.status === 'draft';
|
|
285
304
|
|
|
286
|
-
const
|
|
287
|
-
clientId
|
|
288
|
-
);
|
|
305
|
+
const isDraftNavigationMenu = navigationMenu?.status === 'draft';
|
|
289
306
|
|
|
290
307
|
const {
|
|
291
308
|
convert,
|
|
@@ -310,6 +327,7 @@ function Navigation( {
|
|
|
310
327
|
! ref &&
|
|
311
328
|
! isCreatingNavigationMenu &&
|
|
312
329
|
! isConvertingClassicMenu &&
|
|
330
|
+
hasResolvedNavigationMenus &&
|
|
313
331
|
( ! hasUncontrolledInnerBlocks || isWithinUnassignedArea );
|
|
314
332
|
|
|
315
333
|
const isEntityAvailable =
|
|
@@ -322,10 +340,13 @@ function Navigation( {
|
|
|
322
340
|
// - there is a ref attribute pointing to a Navigation Post
|
|
323
341
|
// - the Navigation Post isn't available (hasn't resolved) yet.
|
|
324
342
|
const isLoading =
|
|
343
|
+
! hasResolvedNavigationMenus ||
|
|
325
344
|
isCreatingNavigationMenu ||
|
|
326
345
|
isConvertingClassicMenu ||
|
|
327
346
|
!! ( ref && ! isEntityAvailable && ! isConvertingClassicMenu );
|
|
328
347
|
|
|
348
|
+
const textDecoration = attributes.style?.typography?.textDecoration;
|
|
349
|
+
|
|
329
350
|
const blockProps = useBlockProps( {
|
|
330
351
|
ref: navRef,
|
|
331
352
|
className: classnames( className, {
|
|
@@ -346,6 +367,7 @@ function Navigation( {
|
|
|
346
367
|
'background-color',
|
|
347
368
|
backgroundColor?.slug
|
|
348
369
|
) ]: !! backgroundColor?.slug,
|
|
370
|
+
[ `has-text-decoration-${ textDecoration }` ]: textDecoration,
|
|
349
371
|
} ),
|
|
350
372
|
style: {
|
|
351
373
|
color: ! textColor?.slug && textColor?.color,
|
|
@@ -534,11 +556,12 @@ function Navigation( {
|
|
|
534
556
|
} );
|
|
535
557
|
}, [ clientId, ref ] );
|
|
536
558
|
|
|
537
|
-
// If the block has inner blocks, but no menu id,
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
//
|
|
541
|
-
//
|
|
559
|
+
// If the block has inner blocks, but no menu id, then these blocks are either:
|
|
560
|
+
// - inserted via a pattern.
|
|
561
|
+
// - inserted directly via Code View (or otherwise).
|
|
562
|
+
// - from an older version of navigation block added before the block used a wp_navigation entity.
|
|
563
|
+
// Consider this state as 'unsaved' and offer an uncontrolled version of inner blocks,
|
|
564
|
+
// that automatically saves the menu as an entity when changes are made to the inner blocks.
|
|
542
565
|
const hasUnsavedBlocks = hasUncontrolledInnerBlocks && ! isEntityAvailable;
|
|
543
566
|
if ( hasUnsavedBlocks ) {
|
|
544
567
|
return (
|
|
@@ -566,6 +589,10 @@ function Navigation( {
|
|
|
566
589
|
setHasSavedUnsavedInnerBlocks( true );
|
|
567
590
|
// Switch to using the wp_navigation entity.
|
|
568
591
|
setRef( post.id );
|
|
592
|
+
|
|
593
|
+
showNavigationMenuCreateNotice(
|
|
594
|
+
__( `New Navigation Menu created.` )
|
|
595
|
+
);
|
|
569
596
|
} }
|
|
570
597
|
/>
|
|
571
598
|
</ResponsiveWrapper>
|
|
@@ -646,9 +673,7 @@ function Navigation( {
|
|
|
646
673
|
/>
|
|
647
674
|
</ToolbarGroup>
|
|
648
675
|
) }
|
|
649
|
-
<ToolbarGroup>{ listViewToolbarButton }</ToolbarGroup>
|
|
650
676
|
</BlockControls>
|
|
651
|
-
{ listViewModal }
|
|
652
677
|
<InspectorControls>
|
|
653
678
|
{ hasSubmenuIndicatorSetting && (
|
|
654
679
|
<PanelBody title={ __( 'Display' ) }>
|
|
@@ -794,7 +819,18 @@ function Navigation( {
|
|
|
794
819
|
{ hasResolvedCanUserDeleteNavigationMenu &&
|
|
795
820
|
canUserDeleteNavigationMenu && (
|
|
796
821
|
<NavigationMenuDeleteControl
|
|
797
|
-
onDelete={
|
|
822
|
+
onDelete={ ( deletedMenuTitle = '' ) => {
|
|
823
|
+
resetToEmptyBlock();
|
|
824
|
+
showNavigationMenuDeleteNotice(
|
|
825
|
+
sprintf(
|
|
826
|
+
// translators: %s: the name of a menu (e.g. Header navigation).
|
|
827
|
+
__(
|
|
828
|
+
'Navigation menu %s successfully deleted.'
|
|
829
|
+
),
|
|
830
|
+
deletedMenuTitle
|
|
831
|
+
)
|
|
832
|
+
);
|
|
833
|
+
} }
|
|
798
834
|
/>
|
|
799
835
|
) }
|
|
800
836
|
</InspectorControls>
|
|
@@ -10,7 +10,7 @@ import { useInnerBlocksProps } from '@wordpress/block-editor';
|
|
|
10
10
|
import { Disabled, Spinner } from '@wordpress/components';
|
|
11
11
|
import { store as coreStore } from '@wordpress/core-data';
|
|
12
12
|
import { useSelect } from '@wordpress/data';
|
|
13
|
-
import { useContext, useEffect, useRef } from '@wordpress/element';
|
|
13
|
+
import { useContext, useEffect, useRef, useMemo } from '@wordpress/element';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Internal dependencies
|
|
@@ -25,6 +25,22 @@ const DRAFT_MENU_PARAMS = [
|
|
|
25
25
|
{ status: 'draft', per_page: -1 },
|
|
26
26
|
];
|
|
27
27
|
|
|
28
|
+
const DEFAULT_BLOCK = {
|
|
29
|
+
name: 'core/navigation-link',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ALLOWED_BLOCKS = [
|
|
33
|
+
'core/navigation-link',
|
|
34
|
+
'core/search',
|
|
35
|
+
'core/social-links',
|
|
36
|
+
'core/page-list',
|
|
37
|
+
'core/spacer',
|
|
38
|
+
'core/home-link',
|
|
39
|
+
'core/site-title',
|
|
40
|
+
'core/site-logo',
|
|
41
|
+
'core/navigation-submenu',
|
|
42
|
+
];
|
|
43
|
+
|
|
28
44
|
export default function UnsavedInnerBlocks( {
|
|
29
45
|
blockProps,
|
|
30
46
|
blocks,
|
|
@@ -33,6 +49,33 @@ export default function UnsavedInnerBlocks( {
|
|
|
33
49
|
onSave,
|
|
34
50
|
hasSelection,
|
|
35
51
|
} ) {
|
|
52
|
+
const originalBlocks = useRef();
|
|
53
|
+
|
|
54
|
+
useEffect( () => {
|
|
55
|
+
// Initially store the uncontrolled inner blocks for
|
|
56
|
+
// dirty state comparison.
|
|
57
|
+
if ( ! originalBlocks?.current ) {
|
|
58
|
+
originalBlocks.current = blocks;
|
|
59
|
+
}
|
|
60
|
+
}, [ blocks ] );
|
|
61
|
+
|
|
62
|
+
// If the current inner blocks object is different in any way
|
|
63
|
+
// from the original inner blocks from the post content then the
|
|
64
|
+
// user has made changes to the inner blocks. At this point the inner
|
|
65
|
+
// blocks can be considered "dirty".
|
|
66
|
+
const innerBlocksAreDirty = blocks !== originalBlocks.current;
|
|
67
|
+
|
|
68
|
+
const shouldDirectInsert = useMemo(
|
|
69
|
+
() =>
|
|
70
|
+
blocks.every(
|
|
71
|
+
( { name } ) =>
|
|
72
|
+
name === 'core/navigation-link' ||
|
|
73
|
+
name === 'core/navigation-submenu' ||
|
|
74
|
+
name === 'core/page-list'
|
|
75
|
+
),
|
|
76
|
+
[ blocks ]
|
|
77
|
+
);
|
|
78
|
+
|
|
36
79
|
// The block will be disabled in a block preview, use this as a way of
|
|
37
80
|
// avoiding the side-effects of this component for block previews.
|
|
38
81
|
const isDisabled = useContext( Disabled.Context );
|
|
@@ -40,6 +83,9 @@ export default function UnsavedInnerBlocks( {
|
|
|
40
83
|
|
|
41
84
|
const innerBlocksProps = useInnerBlocksProps( blockProps, {
|
|
42
85
|
renderAppender: hasSelection ? undefined : false,
|
|
86
|
+
allowedBlocks: ALLOWED_BLOCKS,
|
|
87
|
+
__experimentalDefaultBlock: DEFAULT_BLOCK,
|
|
88
|
+
__experimentalDirectInsert: shouldDirectInsert,
|
|
43
89
|
} );
|
|
44
90
|
|
|
45
91
|
const {
|
|
@@ -97,7 +143,8 @@ export default function UnsavedInnerBlocks( {
|
|
|
97
143
|
savingLock.current ||
|
|
98
144
|
! hasResolvedDraftNavigationMenus ||
|
|
99
145
|
! hasResolvedNavigationMenus ||
|
|
100
|
-
! hasSelection
|
|
146
|
+
! hasSelection ||
|
|
147
|
+
! innerBlocksAreDirty
|
|
101
148
|
) {
|
|
102
149
|
return;
|
|
103
150
|
}
|
|
@@ -118,19 +165,21 @@ export default function UnsavedInnerBlocks( {
|
|
|
118
165
|
blocks,
|
|
119
166
|
] );
|
|
120
167
|
|
|
168
|
+
const Wrapper = isSaving ? Disabled : 'div';
|
|
169
|
+
|
|
121
170
|
return (
|
|
122
|
-
<
|
|
123
|
-
<
|
|
171
|
+
<Wrapper className="wp-block-navigation__unsaved-changes">
|
|
172
|
+
<div
|
|
124
173
|
className={ classnames(
|
|
125
174
|
'wp-block-navigation__unsaved-changes-overlay',
|
|
126
175
|
{
|
|
127
|
-
'is-saving':
|
|
176
|
+
'is-saving': isSaving,
|
|
128
177
|
}
|
|
129
178
|
) }
|
|
130
179
|
>
|
|
131
180
|
<div { ...innerBlocksProps } />
|
|
132
|
-
</
|
|
133
|
-
{
|
|
134
|
-
</
|
|
181
|
+
</div>
|
|
182
|
+
{ isSaving && <Spinner /> }
|
|
183
|
+
</Wrapper>
|
|
135
184
|
);
|
|
136
185
|
}
|
package/src/navigation/index.php
CHANGED
|
@@ -486,6 +486,10 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
486
486
|
$layout_class .= ' no-wrap';
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
+
// Manually add block support text decoration as CSS class.
|
|
490
|
+
$text_decoration = _wp_array_get( $attributes, array( 'style', 'typography', 'textDecoration' ), null );
|
|
491
|
+
$text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
|
|
492
|
+
|
|
489
493
|
$colors = block_core_navigation_build_css_colors( $attributes );
|
|
490
494
|
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
|
|
491
495
|
$classes = array_merge(
|
|
@@ -493,7 +497,8 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
493
497
|
$font_sizes['css_classes'],
|
|
494
498
|
$is_responsive_menu ? array( 'is-responsive' ) : array(),
|
|
495
499
|
$layout_class ? array( $layout_class ) : array(),
|
|
496
|
-
$is_fallback ? array( 'is-fallback' ) : array()
|
|
500
|
+
$is_fallback ? array( 'is-fallback' ) : array(),
|
|
501
|
+
$text_decoration ? array( $text_decoration_class ) : array()
|
|
497
502
|
);
|
|
498
503
|
|
|
499
504
|
$inner_blocks_html = '';
|