@wordpress/block-library 8.5.0 → 8.7.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 +4 -0
- package/build/buttons/edit.native.js +1 -1
- package/build/buttons/edit.native.js.map +1 -1
- package/build/buttons/index.js +1 -0
- package/build/buttons/index.js.map +1 -1
- package/build/buttons/transforms.js +1 -0
- package/build/buttons/transforms.js.map +1 -1
- package/build/columns/edit.js +14 -10
- package/build/columns/edit.js.map +1 -1
- package/build/columns/edit.native.js +1 -1
- package/build/columns/edit.native.js.map +1 -1
- package/build/columns/index.js +4 -0
- package/build/columns/index.js.map +1 -1
- package/build/comments/edit/placeholder.js +8 -5
- package/build/comments/edit/placeholder.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +2 -2
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +13 -4
- package/build/cover/index.js.map +1 -1
- package/build/cover/variations.js +29 -0
- package/build/cover/variations.js.map +1 -0
- package/build/embed/edit.js +13 -14
- package/build/embed/edit.js.map +1 -1
- package/build/embed/edit.native.js +18 -14
- package/build/embed/edit.native.js.map +1 -1
- package/build/embed/util.js +39 -12
- package/build/embed/util.js.map +1 -1
- package/build/gallery/edit.js +9 -5
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/use-image-sizes.js +1 -1
- package/build/gallery/use-image-sizes.js.map +1 -1
- package/build/group/deprecated.js +4 -2
- package/build/group/deprecated.js.map +1 -1
- package/build/group/edit.js +22 -5
- package/build/group/edit.js.map +1 -1
- package/build/group/placeholder.js +11 -1
- package/build/group/placeholder.js.map +1 -1
- package/build/group/variations.js +23 -3
- package/build/group/variations.js.map +1 -1
- package/build/image/edit.js +1 -1
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +1 -1
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +8 -6
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +7 -2
- package/build/image/index.js.map +1 -1
- package/build/latest-posts/edit.js +11 -10
- package/build/latest-posts/edit.js.map +1 -1
- package/build/latest-posts/edit.native.js +3 -3
- package/build/latest-posts/edit.native.js.map +1 -1
- package/build/media-text/constants.js +17 -1
- package/build/media-text/constants.js.map +1 -1
- package/build/media-text/deprecated.js +228 -18
- package/build/media-text/deprecated.js.map +1 -1
- package/build/media-text/edit.js +10 -22
- package/build/media-text/edit.js.map +1 -1
- package/build/media-text/edit.native.js +6 -5
- package/build/media-text/edit.native.js.map +1 -1
- package/build/media-text/index.js +1 -1
- package/build/media-text/transforms.js +32 -44
- package/build/media-text/transforms.js.map +1 -1
- package/build/navigation/edit/index.js +55 -96
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +2 -5
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +26 -22
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +14 -1
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build/navigation/edit/use-navigation-notice.js +1 -1
- package/build/navigation/edit/use-navigation-notice.js.map +1 -1
- package/build/navigation/index.js +0 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation-link/edit.js +0 -11
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/link-ui.js +0 -1
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-submenu/edit.js +1 -13
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/page-list/edit.js +59 -45
- package/build/page-list/edit.js.map +1 -1
- package/build/page-list-item/edit.js +3 -2
- package/build/page-list-item/edit.js.map +1 -1
- package/build/post-content/edit.js +6 -1
- package/build/post-content/edit.js.map +1 -1
- package/build/post-date/edit.js +2 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-date/index.js +4 -1
- package/build/post-date/index.js.map +1 -1
- package/build/post-date/variations.js +28 -0
- package/build/post-date/variations.js.map +1 -0
- package/build/post-excerpt/edit.js +39 -10
- package/build/post-excerpt/edit.js.map +1 -1
- package/build/post-featured-image/dimension-controls.js +2 -8
- package/build/post-featured-image/dimension-controls.js.map +1 -1
- package/build/post-featured-image/edit.js +1 -1
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-template/index.js +1 -1
- package/build/post-time-to-read/index.js +17 -1
- package/build/post-time-to-read/index.js.map +1 -1
- package/build/pullquote/deprecated.js +3 -3
- package/build/pullquote/deprecated.js.map +1 -1
- package/build/query/edit/query-placeholder.js +3 -2
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/utils.js +26 -9
- package/build/query/utils.js.map +1 -1
- package/build/quote/index.js +1 -0
- package/build/quote/index.js.map +1 -1
- package/build/spacer/edit.js +16 -6
- package/build/spacer/edit.js.map +1 -1
- package/build/table/state.js +12 -4
- package/build/table/state.js.map +1 -1
- package/build/template-part/edit/import-controls.js +4 -24
- package/build/template-part/edit/import-controls.js.map +1 -1
- package/build/template-part/edit/utils/transformers.js +69 -19
- package/build/template-part/edit/utils/transformers.js.map +1 -1
- package/build/text-columns/edit.js +3 -7
- package/build/text-columns/edit.js.map +1 -1
- package/build/text-columns/save.js +11 -13
- package/build/text-columns/save.js.map +1 -1
- package/build-module/buttons/edit.native.js +1 -1
- package/build-module/buttons/edit.native.js.map +1 -1
- package/build-module/buttons/index.js +1 -0
- package/build-module/buttons/index.js.map +1 -1
- package/build-module/buttons/transforms.js +1 -0
- package/build-module/buttons/transforms.js.map +1 -1
- package/build-module/columns/edit.js +14 -9
- package/build-module/columns/edit.js.map +1 -1
- package/build-module/columns/edit.native.js +1 -1
- package/build-module/columns/edit.native.js.map +1 -1
- package/build-module/columns/index.js +4 -0
- package/build-module/columns/index.js.map +1 -1
- package/build-module/comments/edit/placeholder.js +9 -5
- package/build-module/comments/edit/placeholder.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +2 -2
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +12 -4
- package/build-module/cover/index.js.map +1 -1
- package/build-module/cover/variations.js +19 -0
- package/build-module/cover/variations.js.map +1 -0
- package/build-module/embed/edit.js +14 -15
- package/build-module/embed/edit.js.map +1 -1
- package/build-module/embed/edit.native.js +19 -15
- package/build-module/embed/edit.native.js.map +1 -1
- package/build-module/embed/util.js +34 -10
- package/build-module/embed/util.js.map +1 -1
- package/build-module/gallery/edit.js +9 -5
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/use-image-sizes.js +1 -1
- package/build-module/gallery/use-image-sizes.js.map +1 -1
- package/build-module/group/deprecated.js +4 -2
- package/build-module/group/deprecated.js.map +1 -1
- package/build-module/group/edit.js +21 -5
- package/build-module/group/edit.js.map +1 -1
- package/build-module/group/placeholder.js +11 -1
- package/build-module/group/placeholder.js.map +1 -1
- package/build-module/group/variations.js +24 -1
- package/build-module/group/variations.js.map +1 -1
- package/build-module/image/edit.js +1 -1
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +1 -1
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +8 -6
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +7 -2
- package/build-module/image/index.js.map +1 -1
- package/build-module/latest-posts/edit.js +11 -9
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/latest-posts/edit.native.js +3 -3
- package/build-module/latest-posts/edit.native.js.map +1 -1
- package/build-module/media-text/constants.js +10 -0
- package/build-module/media-text/constants.js.map +1 -1
- package/build-module/media-text/deprecated.js +227 -18
- package/build-module/media-text/deprecated.js.map +1 -1
- package/build-module/media-text/edit.js +5 -17
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/media-text/edit.native.js +4 -3
- package/build-module/media-text/edit.native.js.map +1 -1
- package/build-module/media-text/index.js +1 -1
- package/build-module/media-text/transforms.js +32 -44
- package/build-module/media-text/transforms.js.map +1 -1
- package/build-module/navigation/edit/index.js +57 -98
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +2 -5
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +25 -22
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +14 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build-module/navigation/edit/use-navigation-notice.js +1 -1
- package/build-module/navigation/edit/use-navigation-notice.js.map +1 -1
- package/build-module/navigation/index.js +0 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation-link/edit.js +0 -11
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/link-ui.js +0 -1
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +1 -13
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/page-list/edit.js +61 -47
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/page-list-item/edit.js +3 -2
- package/build-module/page-list-item/edit.js.map +1 -1
- package/build-module/post-content/edit.js +6 -1
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-date/edit.js +2 -1
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-date/index.js +3 -1
- package/build-module/post-date/index.js.map +1 -1
- package/build-module/post-date/variations.js +18 -0
- package/build-module/post-date/variations.js.map +1 -0
- package/build-module/post-excerpt/edit.js +38 -11
- package/build-module/post-excerpt/edit.js.map +1 -1
- package/build-module/post-featured-image/dimension-controls.js +2 -8
- package/build-module/post-featured-image/dimension-controls.js.map +1 -1
- package/build-module/post-featured-image/edit.js +1 -1
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-template/index.js +1 -1
- package/build-module/post-time-to-read/index.js +17 -1
- package/build-module/post-time-to-read/index.js.map +1 -1
- package/build-module/pullquote/deprecated.js +3 -2
- package/build-module/pullquote/deprecated.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +4 -3
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/utils.js +21 -6
- package/build-module/query/utils.js.map +1 -1
- package/build-module/quote/index.js +1 -0
- package/build-module/quote/index.js.map +1 -1
- package/build-module/spacer/edit.js +16 -6
- package/build-module/spacer/edit.js.map +1 -1
- package/build-module/table/state.js +13 -5
- package/build-module/table/state.js.map +1 -1
- package/build-module/template-part/edit/import-controls.js +4 -23
- package/build-module/template-part/edit/import-controls.js.map +1 -1
- package/build-module/template-part/edit/utils/transformers.js +69 -20
- package/build-module/template-part/edit/utils/transformers.js.map +1 -1
- package/build-module/text-columns/edit.js +3 -6
- package/build-module/text-columns/edit.js.map +1 -1
- package/build-module/text-columns/save.js +11 -12
- package/build-module/text-columns/save.js.map +1 -1
- package/build-style/categories/editor-rtl.css +5 -0
- package/build-style/categories/editor.css +5 -0
- package/build-style/categories/style-rtl.css +4 -0
- package/build-style/categories/style.css +4 -0
- package/build-style/cover/style-rtl.css +11 -5
- package/build-style/cover/style.css +11 -5
- package/build-style/editor-rtl.css +11 -1
- package/build-style/editor.css +11 -1
- package/build-style/navigation/editor-rtl.css +1 -1
- package/build-style/navigation/editor.css +1 -1
- package/build-style/navigation/style-rtl.css +2 -0
- package/build-style/navigation/style.css +2 -0
- package/build-style/page-list/editor-rtl.css +4 -0
- package/build-style/page-list/editor.css +4 -0
- package/build-style/post-featured-image/editor-rtl.css +1 -0
- package/build-style/post-featured-image/editor.css +1 -0
- package/build-style/post-featured-image/style-rtl.css +1 -0
- package/build-style/post-featured-image/style.css +1 -0
- package/build-style/post-template/style-rtl.css +1 -1
- package/build-style/post-template/style.css +1 -1
- package/build-style/post-time-to-read/style-rtl.css +91 -0
- package/build-style/post-time-to-read/style.css +91 -0
- package/build-style/search/style-rtl.css +8 -7
- package/build-style/search/style.css +8 -7
- package/build-style/style-rtl.css +31 -13
- package/build-style/style.css +31 -13
- package/package.json +31 -31
- package/src/audio/test/__snapshots__/edit.native.js.snap +44 -4
- package/src/audio/test/__snapshots__/transforms.native.js.snap +25 -0
- package/src/audio/test/transforms.native.js +42 -0
- package/src/block/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/block/test/transforms.native.js +40 -0
- package/src/buttons/block.json +1 -0
- package/src/buttons/edit.native.js +1 -1
- package/src/buttons/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/buttons/test/transforms.native.js +48 -0
- package/src/categories/editor.scss +5 -0
- package/src/categories/style.scss +4 -0
- package/src/columns/block.json +4 -0
- package/src/columns/edit.js +30 -18
- package/src/columns/edit.native.js +1 -1
- package/src/columns/test/__snapshots__/transforms.native.js.snap +61 -0
- package/src/columns/test/transforms.native.js +91 -0
- package/src/comment-template/index.php +1 -2
- package/src/comments/edit/placeholder.js +16 -4
- package/src/comments/index.php +1 -0
- package/src/cover/block.json +9 -3
- package/src/cover/edit/inspector-controls.js +4 -5
- package/src/cover/index.js +2 -0
- package/src/cover/style.scss +16 -7
- package/src/cover/test/__snapshots__/transforms.native.js.snap +73 -0
- package/src/cover/test/edit.js +324 -0
- package/src/cover/test/transforms.native.js +112 -0
- package/src/cover/variations.js +20 -0
- package/src/embed/edit.js +16 -12
- package/src/embed/edit.native.js +28 -18
- package/src/embed/test/__snapshots__/transforms.native.js.snap +23 -0
- package/src/embed/test/index.js +12 -0
- package/src/embed/test/transforms.native.js +44 -0
- package/src/embed/util.js +29 -8
- package/src/file/test/__snapshots__/edit.native.js.snap +18 -2
- package/src/file/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/file/test/transforms.native.js +42 -0
- package/src/freeform/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/freeform/test/transforms.native.js +39 -0
- package/src/gallery/edit.js +8 -2
- package/src/gallery/test/__snapshots__/transforms.native.js.snap +53 -0
- package/src/gallery/test/transforms.native.js +52 -0
- package/src/gallery/use-image-sizes.js +1 -1
- package/src/group/deprecated.js +4 -2
- package/src/group/edit.js +27 -9
- package/src/group/placeholder.js +13 -1
- package/src/group/test/__snapshots__/transforms.native.js.snap +35 -0
- package/src/group/test/transforms.native.js +75 -0
- package/src/group/variations.js +14 -1
- package/src/heading/test/__snapshots__/transforms.native.js.snap +47 -0
- package/src/heading/test/transforms.native.js +46 -0
- package/src/home-link/index.php +2 -2
- package/src/image/block.json +7 -2
- package/src/image/edit.js +1 -1
- package/src/image/edit.native.js +1 -1
- package/src/image/image.js +15 -7
- package/src/image/index.php +7 -2
- package/src/image/test/__snapshots__/transforms.native.js.snap +49 -0
- package/src/image/test/transforms.native.js +48 -0
- package/src/latest-comments/style.scss +1 -1
- package/src/latest-posts/edit.js +14 -16
- package/src/latest-posts/edit.native.js +3 -3
- package/src/latest-posts/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/latest-posts/test/transforms.native.js +61 -0
- package/src/list/test/__snapshots__/transforms.native.js.snap +85 -0
- package/src/list/test/transforms.native.js +56 -0
- package/src/media-text/block.json +1 -1
- package/src/media-text/constants.js +16 -0
- package/src/media-text/deprecated.js +235 -3
- package/src/media-text/edit.js +15 -24
- package/src/media-text/edit.native.js +3 -9
- package/src/media-text/test/__snapshots__/transforms.native.js.snap +73 -0
- package/src/media-text/test/transforms.native.js +112 -0
- package/src/media-text/transforms.js +24 -51
- package/src/missing/test/__snapshots__/edit.native.js.snap +20 -2
- package/src/more/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/more/test/transforms.native.js +42 -0
- package/src/navigation/block.json +0 -1
- package/src/navigation/edit/index.js +99 -115
- package/src/navigation/edit/menu-inspector-controls.js +2 -7
- package/src/navigation/edit/navigation-menu-selector.js +41 -25
- package/src/navigation/edit/unsaved-inner-blocks.js +46 -33
- package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +82 -83
- package/src/navigation/edit/use-create-navigation-menu.js +1 -1
- package/src/navigation/edit/use-navigation-notice.js +1 -1
- package/src/navigation/editor.scss +23 -20
- package/src/navigation/index.php +18 -39
- package/src/navigation/style.scss +6 -4
- package/src/navigation-link/edit.js +0 -9
- package/src/navigation-link/index.php +7 -9
- package/src/navigation-link/link-ui.js +0 -1
- package/src/navigation-submenu/edit.js +0 -10
- package/src/navigation-submenu/index.php +45 -74
- package/src/nextpage/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/nextpage/test/transforms.native.js +42 -0
- package/src/page-list/edit.js +78 -44
- package/src/page-list/editor.scss +6 -0
- package/src/page-list-item/edit.js +2 -3
- package/src/paragraph/test/__snapshots__/transforms.native.js.snap +59 -0
- package/src/paragraph/test/transforms.native.js +50 -0
- package/src/post-author/index.php +1 -1
- package/src/post-content/edit.js +5 -1
- package/src/post-date/edit.js +4 -1
- package/src/post-date/index.js +2 -0
- package/src/post-date/variations.js +20 -0
- package/src/post-excerpt/edit.js +48 -16
- package/src/post-excerpt/index.php +1 -2
- package/src/post-featured-image/dimension-controls.js +2 -10
- package/src/post-featured-image/edit.js +1 -1
- package/src/post-featured-image/editor.scss +1 -0
- package/src/post-featured-image/style.scss +1 -0
- package/src/post-template/block.json +1 -1
- package/src/post-template/style.scss +1 -1
- package/src/post-time-to-read/block.json +17 -1
- package/src/post-time-to-read/style.scss +4 -0
- package/src/preformatted/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/preformatted/test/transforms.native.js +42 -0
- package/src/pullquote/deprecated.js +2 -6
- package/src/pullquote/test/__snapshots__/transforms.native.js.snap +47 -0
- package/src/pullquote/test/transforms.native.js +46 -0
- package/src/query/edit/query-placeholder.js +10 -5
- package/src/query/test/utils.js +33 -1
- package/src/query/utils.js +19 -6
- package/src/query-title/index.php +2 -5
- package/src/quote/block.json +1 -0
- package/src/quote/test/__snapshots__/transforms.native.js.snap +39 -0
- package/src/quote/test/transforms.native.js +67 -0
- package/src/search/style.scss +16 -12
- package/src/search/test/__snapshots__/edit.native.js.snap +11 -1
- package/src/search/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/search/test/transforms.native.js +40 -0
- package/src/separator/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/separator/test/transforms.native.js +42 -0
- package/src/shortcode/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/shortcode/test/transforms.native.js +42 -0
- package/src/social-links/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/social-links/test/transforms.native.js +53 -0
- package/src/spacer/edit.js +18 -5
- package/src/spacer/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/spacer/test/transforms.native.js +42 -0
- package/src/style.scss +1 -0
- package/src/table/state.js +8 -17
- package/src/template-part/edit/import-controls.js +2 -29
- package/src/template-part/edit/utils/transformers.js +96 -19
- package/src/text-columns/edit.js +1 -6
- package/src/text-columns/save.js +1 -6
- package/src/verse/test/__snapshots__/transforms.native.js.snap +25 -0
- package/src/verse/test/transforms.native.js +42 -0
- package/src/video/test/__snapshots__/transforms.native.js.snap +41 -0
- package/src/video/test/transforms.native.js +48 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/cover/test/block-controls.js +0 -62
package/build/quote/index.js
CHANGED
package/build/quote/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/quote/index.js"],"names":["name","metadata","settings","icon","example","attributes","citation","innerBlocks","content","transforms","edit","save","deprecated","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAdA;AACA;AACA;;AAIA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/quote/index.js"],"names":["name","metadata","settings","icon","example","attributes","citation","innerBlocks","content","transforms","edit","save","deprecated","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAdA;AACA;AACA;;AAIA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,YADuB;AAEvBC,EAAAA,OAAO,EAAE;AACRC,IAAAA,UAAU,EAAE;AACXC,MAAAA,QAAQ,EAAE;AADC,KADJ;AAIRC,IAAAA,WAAW,EAAE,CACZ;AACCP,MAAAA,IAAI,EAAE,gBADP;AAECK,MAAAA,UAAU,EAAE;AACXG,QAAAA,OAAO,EAAE,cAAI,uCAAJ;AADE;AAFb,KADY;AAJL,GAFc;AAevBC,EAAAA,UAAU,EAAVA,mBAfuB;AAgBvBC,EAAAA,IAAI,EAAJA,aAhBuB;AAiBvBC,EAAAA,IAAI,EAAJA,aAjBuB;AAkBvBC,EAAAA,UAAU,EAAVA;AAlBuB,CAAjB;;;AAqBA,MAAMC,IAAI,GAAG,MAAM,wBAAW;AAAEb,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAX,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { quote as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcitation: 'Julio Cortázar',\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( 'In quoting others, we cite ourselves.' ),\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
|
package/build/spacer/edit.js
CHANGED
|
@@ -93,11 +93,19 @@ const SpacerEdit = _ref2 => {
|
|
|
93
93
|
isSelected,
|
|
94
94
|
setAttributes,
|
|
95
95
|
toggleSelection,
|
|
96
|
-
context
|
|
96
|
+
context,
|
|
97
|
+
__unstableParentLayout: parentLayout
|
|
97
98
|
} = _ref2;
|
|
98
99
|
const {
|
|
99
100
|
orientation
|
|
100
101
|
} = context;
|
|
102
|
+
const {
|
|
103
|
+
orientation: parentOrientation,
|
|
104
|
+
type
|
|
105
|
+
} = parentLayout || {}; // If the spacer is inside a flex container, it should either inherit the orientation
|
|
106
|
+
// of the parent or use the flex default orientation.
|
|
107
|
+
|
|
108
|
+
const inheritedOrientation = !parentOrientation && type === 'flex' ? 'horizontal' : parentOrientation || orientation;
|
|
101
109
|
const {
|
|
102
110
|
height,
|
|
103
111
|
width
|
|
@@ -127,8 +135,10 @@ const SpacerEdit = _ref2 => {
|
|
|
127
135
|
};
|
|
128
136
|
|
|
129
137
|
const style = {
|
|
130
|
-
height:
|
|
131
|
-
width:
|
|
138
|
+
height: inheritedOrientation === 'horizontal' ? 24 : temporaryHeight || height || undefined,
|
|
139
|
+
width: inheritedOrientation === 'horizontal' ? temporaryWidth || width || undefined : undefined,
|
|
140
|
+
// In vertical flex containers, the spacer shrinks to nothing without a minimum width.
|
|
141
|
+
minWidth: inheritedOrientation === 'vertical' && type === 'flex' ? 48 : undefined
|
|
132
142
|
};
|
|
133
143
|
|
|
134
144
|
const resizableBoxWithOrientation = blockOrientation => {
|
|
@@ -178,7 +188,7 @@ const SpacerEdit = _ref2 => {
|
|
|
178
188
|
};
|
|
179
189
|
|
|
180
190
|
(0, _element.useEffect)(() => {
|
|
181
|
-
if (
|
|
191
|
+
if (inheritedOrientation === 'horizontal' && !width) {
|
|
182
192
|
setAttributes({
|
|
183
193
|
height: '0px',
|
|
184
194
|
width: '72px'
|
|
@@ -187,11 +197,11 @@ const SpacerEdit = _ref2 => {
|
|
|
187
197
|
}, []);
|
|
188
198
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_primitives.View, (0, _blockEditor.useBlockProps)({
|
|
189
199
|
style
|
|
190
|
-
}), resizableBoxWithOrientation(
|
|
200
|
+
}), resizableBoxWithOrientation(inheritedOrientation)), (0, _element.createElement)(_controls.default, {
|
|
191
201
|
setAttributes: setAttributes,
|
|
192
202
|
height: temporaryHeight || height,
|
|
193
203
|
width: temporaryWidth || width,
|
|
194
|
-
orientation:
|
|
204
|
+
orientation: inheritedOrientation,
|
|
195
205
|
isResizing: isResizing
|
|
196
206
|
}));
|
|
197
207
|
};
|
package/build/spacer/edit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/spacer/edit.js"],"names":["ResizableSpacer","orientation","onResizeStart","onResize","onResizeStop","isSelected","isResizing","setIsResizing","props","getCurrentSize","elt","clientWidth","clientHeight","getNextVal","_event","_direction","nextVal","axis","position","isVisible","SpacerEdit","attributes","setAttributes","toggleSelection","context","height","width","temporaryHeight","setTemporaryHeight","temporaryWidth","setTemporaryWidth","handleOnVerticalResizeStop","newHeight","handleOnHorizontalResizeStop","newWidth","style","undefined","resizableBoxWithOrientation","blockOrientation","MIN_SPACER_SIZE","top","right","bottom","left","topRight","bottomRight","bottomLeft","topLeft"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AAKA;;AACA;;AAEA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,eAAe,GAAG,QASjB;AAAA,MATmB;AACzBC,IAAAA,WADyB;AAEzBC,IAAAA,aAFyB;AAGzBC,IAAAA,QAHyB;AAIzBC,IAAAA,YAJyB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,OAFV;AAYC,MAAA,WAAW,EAAGT,gBAZf;AAaC,MAAA,aAAa,EAAGpC,aAbjB;AAcC,MAAA,QAAQ,EAAG0B,kBAdZ;AAeC,MAAA,YAAY,EAAGG,0BAfhB;AAgBC,MAAA,UAAU,EAAG1B,UAhBd;AAiBC,MAAA,UAAU,EAAGC,UAjBd;AAkBC,MAAA,aAAa,EAAGC;AAlBjB,MADD,CADD;AAwBA,GAlDD;;AAoDA,0BAAW,MAAM;AAChB,QAAKN,WAAW,KAAK,YAAhB,IAAgC,CAAEyB,KAAvC,EAA+C;AAC9CJ,MAAAA,aAAa,CAAE;AACdG,QAAAA,MAAM,EAAE,KADM;AAEdC,QAAAA,KAAK,EAAE;AAFO,OAAF,CAAb;AAIA;AACD,GAPD,EAOG,EAPH;AASA,SACC,qDACC,4BAAC,gBAAD,EAAW,gCAAe;AAAES,IAAAA;AAAF,GAAf,CAAX,EACGE,2BAA2B,CAAEpC,WAAF,CAD9B,CADD,EAIC,4BAAC,iBAAD;AACC,IAAA,aAAa,EAAGqB,aADjB;AAEC,IAAA,MAAM,EAAGK,eAAe,IAAIF,MAF7B;AAGC,IAAA,KAAK,EAAGI,cAAc,IAAIH,KAH3B;AAIC,IAAA,WAAW,EAAGzB,WAJf;AAKC,IAAA,UAAU,EAAGK;AALd,IAJD,CADD;AAcA,CApHD;;eAsHec,U","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { ResizableBox } from '@wordpress/components';\nimport { useState, useEffect } from '@wordpress/element';\nimport { View } from '@wordpress/primitives';\n\n/**\n * Internal dependencies\n */\nimport SpacerControls from './controls';\nimport { MIN_SPACER_SIZE } from './constants';\n\nconst ResizableSpacer = ( {\n\torientation,\n\tonResizeStart,\n\tonResize,\n\tonResizeStop,\n\tisSelected,\n\tisResizing,\n\tsetIsResizing,\n\t...props\n} ) => {\n\tconst getCurrentSize = ( elt ) => {\n\t\treturn orientation === 'horizontal'\n\t\t\t? elt.clientWidth\n\t\t\t: elt.clientHeight;\n\t};\n\n\tconst getNextVal = ( elt ) => {\n\t\treturn `${ getCurrentSize( elt ) }px`;\n\t};\n\n\treturn (\n\t\t<ResizableBox\n\t\t\tclassName={ classnames( 'block-library-spacer__resize-container', {\n\t\t\t\t'resize-horizontal': orientation === 'horizontal',\n\t\t\t\t'is-resizing': isResizing,\n\t\t\t\t'is-selected': isSelected,\n\t\t\t} ) }\n\t\t\tonResizeStart={ ( _event, _direction, elt ) => {\n\t\t\t\tconst nextVal = getNextVal( elt );\n\t\t\t\tonResizeStart( nextVal );\n\t\t\t\tonResize( nextVal );\n\t\t\t} }\n\t\t\tonResize={ ( _event, _direction, elt ) => {\n\t\t\t\tonResize( getNextVal( elt ) );\n\t\t\t\tif ( ! isResizing ) {\n\t\t\t\t\tsetIsResizing( true );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonResizeStop={ ( _event, _direction, elt ) => {\n\t\t\t\tconst nextVal = getCurrentSize( elt );\n\t\t\t\tonResizeStop( `${ nextVal }px` );\n\t\t\t\tsetIsResizing( false );\n\t\t\t} }\n\t\t\t__experimentalShowTooltip={ true }\n\t\t\t__experimentalTooltipProps={ {\n\t\t\t\taxis: orientation === 'horizontal' ? 'x' : 'y',\n\t\t\t\tposition: 'corner',\n\t\t\t\tisVisible: isResizing,\n\t\t\t} }\n\t\t\tshowHandle={ isSelected }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n};\n\nconst SpacerEdit = ( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\ttoggleSelection,\n\tcontext,\n} ) => {\n\tconst { orientation } = context;\n\tconst { height, width } = attributes;\n\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst [ temporaryHeight, setTemporaryHeight ] = useState( null );\n\tconst [ temporaryWidth, setTemporaryWidth ] = useState( null );\n\n\tconst onResizeStart = () => toggleSelection( false );\n\tconst onResizeStop = () => toggleSelection( true );\n\n\tconst handleOnVerticalResizeStop = ( newHeight ) => {\n\t\tonResizeStop();\n\n\t\tsetAttributes( { height: newHeight } );\n\t\tsetTemporaryHeight( null );\n\t};\n\n\tconst handleOnHorizontalResizeStop = ( newWidth ) => {\n\t\tonResizeStop();\n\t\tsetAttributes( { width: newWidth } );\n\t\tsetTemporaryWidth( null );\n\t};\n\n\tconst style = {\n\t\theight:\n\t\t\torientation === 'horizontal'\n\t\t\t\t? 24\n\t\t\t\t: temporaryHeight || height || undefined,\n\t\twidth:\n\t\t\torientation === 'horizontal'\n\t\t\t\t? temporaryWidth || width || undefined\n\t\t\t\t: undefined,\n\t};\n\n\tconst resizableBoxWithOrientation = ( blockOrientation ) => {\n\t\tif ( blockOrientation === 'horizontal' ) {\n\t\t\treturn (\n\t\t\t\t<ResizableSpacer\n\t\t\t\t\tminWidth={ MIN_SPACER_SIZE }\n\t\t\t\t\tenable={ {\n\t\t\t\t\t\ttop: false,\n\t\t\t\t\t\tright: true,\n\t\t\t\t\t\tbottom: false,\n\t\t\t\t\t\tleft: false,\n\t\t\t\t\t\ttopRight: false,\n\t\t\t\t\t\tbottomRight: false,\n\t\t\t\t\t\tbottomLeft: false,\n\t\t\t\t\t\ttopLeft: false,\n\t\t\t\t\t} }\n\t\t\t\t\torientation={ blockOrientation }\n\t\t\t\t\tonResizeStart={ onResizeStart }\n\t\t\t\t\tonResize={ setTemporaryWidth }\n\t\t\t\t\tonResizeStop={ handleOnHorizontalResizeStop }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tisResizing={ isResizing }\n\t\t\t\t\tsetIsResizing={ setIsResizing }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<ResizableSpacer\n\t\t\t\t\tminHeight={ MIN_SPACER_SIZE }\n\t\t\t\t\tenable={ {\n\t\t\t\t\t\ttop: false,\n\t\t\t\t\t\tright: false,\n\t\t\t\t\t\tbottom: true,\n\t\t\t\t\t\tleft: false,\n\t\t\t\t\t\ttopRight: false,\n\t\t\t\t\t\tbottomRight: false,\n\t\t\t\t\t\tbottomLeft: false,\n\t\t\t\t\t\ttopLeft: false,\n\t\t\t\t\t} }\n\t\t\t\t\torientation={ blockOrientation }\n\t\t\t\t\tonResizeStart={ onResizeStart }\n\t\t\t\t\tonResize={ setTemporaryHeight }\n\t\t\t\t\tonResizeStop={ handleOnVerticalResizeStop }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tisResizing={ isResizing }\n\t\t\t\t\tsetIsResizing={ setIsResizing }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n\n\tuseEffect( () => {\n\t\tif ( orientation === 'horizontal' && ! width ) {\n\t\t\tsetAttributes( {\n\t\t\t\theight: '0px',\n\t\t\t\twidth: '72px',\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<View { ...useBlockProps( { style } ) }>\n\t\t\t\t{ resizableBoxWithOrientation( orientation ) }\n\t\t\t</View>\n\t\t\t<SpacerControls\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\theight={ temporaryHeight || height }\n\t\t\t\twidth={ temporaryWidth || width }\n\t\t\t\torientation={ orientation }\n\t\t\t\tisResizing={ isResizing }\n\t\t\t/>\n\t\t</>\n\t);\n};\n\nexport default SpacerEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/spacer/edit.js"],"names":["ResizableSpacer","orientation","onResizeStart","onResize","onResizeStop","isSelected","isResizing","setIsResizing","props","getCurrentSize","elt","clientWidth","clientHeight","getNextVal","_event","_direction","nextVal","axis","position","isVisible","SpacerEdit","attributes","setAttributes","toggleSelection","context","__unstableParentLayout","parentLayout","parentOrientation","type","inheritedOrientation","height","width","temporaryHeight","setTemporaryHeight","temporaryWidth","setTemporaryWidth","handleOnVerticalResizeStop","newHeight","handleOnHorizontalResizeStop","newWidth","style","undefined","minWidth","resizableBoxWithOrientation","blockOrientation","MIN_SPACER_SIZ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AA2B,CAAEd,oBAAF,CAD9B,CADD,EAIC,4BAAC,iBAAD;AACC,IAAA,aAAa,EAAGP,aADjB;AAEC,IAAA,MAAM,EAAGU,eAAe,IAAIF,MAF7B;AAGC,IAAA,KAAK,EAAGI,cAAc,IAAIH,KAH3B;AAIC,IAAA,WAAW,EAAGF,oBAJf;AAKC,IAAA,UAAU,EAAGvB;AALd,IAJD,CADD;AAcA,CAjID;;eAmIec,U","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { ResizableBox } from '@wordpress/components';\nimport { useState, useEffect } from '@wordpress/element';\nimport { View } from '@wordpress/primitives';\n\n/**\n * Internal dependencies\n */\nimport SpacerControls from './controls';\nimport { MIN_SPACER_SIZE } from './constants';\n\nconst ResizableSpacer = ( {\n\torientation,\n\tonResizeStart,\n\tonResize,\n\tonResizeStop,\n\tisSelected,\n\tisResizing,\n\tsetIsResizing,\n\t...props\n} ) => {\n\tconst getCurrentSize = ( elt ) => {\n\t\treturn orientation === 'horizontal'\n\t\t\t? elt.clientWidth\n\t\t\t: elt.clientHeight;\n\t};\n\n\tconst getNextVal = ( elt ) => {\n\t\treturn `${ getCurrentSize( elt ) }px`;\n\t};\n\n\treturn (\n\t\t<ResizableBox\n\t\t\tclassName={ classnames( 'block-library-spacer__resize-container', {\n\t\t\t\t'resize-horizontal': orientation === 'horizontal',\n\t\t\t\t'is-resizing': isResizing,\n\t\t\t\t'is-selected': isSelected,\n\t\t\t} ) }\n\t\t\tonResizeStart={ ( _event, _direction, elt ) => {\n\t\t\t\tconst nextVal = getNextVal( elt );\n\t\t\t\tonResizeStart( nextVal );\n\t\t\t\tonResize( nextVal );\n\t\t\t} }\n\t\t\tonResize={ ( _event, _direction, elt ) => {\n\t\t\t\tonResize( getNextVal( elt ) );\n\t\t\t\tif ( ! isResizing ) {\n\t\t\t\t\tsetIsResizing( true );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonResizeStop={ ( _event, _direction, elt ) => {\n\t\t\t\tconst nextVal = getCurrentSize( elt );\n\t\t\t\tonResizeStop( `${ nextVal }px` );\n\t\t\t\tsetIsResizing( false );\n\t\t\t} }\n\t\t\t__experimentalShowTooltip={ true }\n\t\t\t__experimentalTooltipProps={ {\n\t\t\t\taxis: orientation === 'horizontal' ? 'x' : 'y',\n\t\t\t\tposition: 'corner',\n\t\t\t\tisVisible: isResizing,\n\t\t\t} }\n\t\t\tshowHandle={ isSelected }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n};\n\nconst SpacerEdit = ( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\ttoggleSelection,\n\tcontext,\n\t__unstableParentLayout: parentLayout,\n} ) => {\n\tconst { orientation } = context;\n\tconst { orientation: parentOrientation, type } = parentLayout || {};\n\t// If the spacer is inside a flex container, it should either inherit the orientation\n\t// of the parent or use the flex default orientation.\n\tconst inheritedOrientation =\n\t\t! parentOrientation && type === 'flex'\n\t\t\t? 'horizontal'\n\t\t\t: parentOrientation || orientation;\n\tconst { height, width } = attributes;\n\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst [ temporaryHeight, setTemporaryHeight ] = useState( null );\n\tconst [ temporaryWidth, setTemporaryWidth ] = useState( null );\n\n\tconst onResizeStart = () => toggleSelection( false );\n\tconst onResizeStop = () => toggleSelection( true );\n\n\tconst handleOnVerticalResizeStop = ( newHeight ) => {\n\t\tonResizeStop();\n\n\t\tsetAttributes( { height: newHeight } );\n\t\tsetTemporaryHeight( null );\n\t};\n\n\tconst handleOnHorizontalResizeStop = ( newWidth ) => {\n\t\tonResizeStop();\n\t\tsetAttributes( { width: newWidth } );\n\t\tsetTemporaryWidth( null );\n\t};\n\n\tconst style = {\n\t\theight:\n\t\t\tinheritedOrientation === 'horizontal'\n\t\t\t\t? 24\n\t\t\t\t: temporaryHeight || height || undefined,\n\t\twidth:\n\t\t\tinheritedOrientation === 'horizontal'\n\t\t\t\t? temporaryWidth || width || undefined\n\t\t\t\t: undefined,\n\t\t// In vertical flex containers, the spacer shrinks to nothing without a minimum width.\n\t\tminWidth:\n\t\t\tinheritedOrientation === 'vertical' && type === 'flex'\n\t\t\t\t? 48\n\t\t\t\t: undefined,\n\t};\n\n\tconst resizableBoxWithOrientation = ( blockOrientation ) => {\n\t\tif ( blockOrientation === 'horizontal' ) {\n\t\t\treturn (\n\t\t\t\t<ResizableSpacer\n\t\t\t\t\tminWidth={ MIN_SPACER_SIZE }\n\t\t\t\t\tenable={ {\n\t\t\t\t\t\ttop: false,\n\t\t\t\t\t\tright: true,\n\t\t\t\t\t\tbottom: false,\n\t\t\t\t\t\tleft: false,\n\t\t\t\t\t\ttopRight: false,\n\t\t\t\t\t\tbottomRight: false,\n\t\t\t\t\t\tbottomLeft: false,\n\t\t\t\t\t\ttopLeft: false,\n\t\t\t\t\t} }\n\t\t\t\t\torientation={ blockOrientation }\n\t\t\t\t\tonResizeStart={ onResizeStart }\n\t\t\t\t\tonResize={ setTemporaryWidth }\n\t\t\t\t\tonResizeStop={ handleOnHorizontalResizeStop }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tisResizing={ isResizing }\n\t\t\t\t\tsetIsResizing={ setIsResizing }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<ResizableSpacer\n\t\t\t\t\tminHeight={ MIN_SPACER_SIZE }\n\t\t\t\t\tenable={ {\n\t\t\t\t\t\ttop: false,\n\t\t\t\t\t\tright: false,\n\t\t\t\t\t\tbottom: true,\n\t\t\t\t\t\tleft: false,\n\t\t\t\t\t\ttopRight: false,\n\t\t\t\t\t\tbottomRight: false,\n\t\t\t\t\t\tbottomLeft: false,\n\t\t\t\t\t\ttopLeft: false,\n\t\t\t\t\t} }\n\t\t\t\t\torientation={ blockOrientation }\n\t\t\t\t\tonResizeStart={ onResizeStart }\n\t\t\t\t\tonResize={ setTemporaryHeight }\n\t\t\t\t\tonResizeStop={ handleOnVerticalResizeStop }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tisResizing={ isResizing }\n\t\t\t\t\tsetIsResizing={ setIsResizing }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t};\n\n\tuseEffect( () => {\n\t\tif ( inheritedOrientation === 'horizontal' && ! width ) {\n\t\t\tsetAttributes( {\n\t\t\t\theight: '0px',\n\t\t\t\twidth: '72px',\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<View { ...useBlockProps( { style } ) }>\n\t\t\t\t{ resizableBoxWithOrientation( inheritedOrientation ) }\n\t\t\t</View>\n\t\t\t<SpacerControls\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\theight={ temporaryHeight || height }\n\t\t\t\twidth={ temporaryWidth || width }\n\t\t\t\torientation={ inheritedOrientation }\n\t\t\t\tisResizing={ isResizing }\n\t\t\t/>\n\t\t</>\n\t);\n};\n\nexport default SpacerEdit;\n"]}
|
package/build/table/state.js
CHANGED
|
@@ -84,12 +84,14 @@ function getFirstRow(state) {
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
function getCellAttribute(state, cellLocation, attributeName) {
|
|
87
|
+
var _state$sectionName, _state$sectionName$ro, _state$sectionName$ro2, _state$sectionName$ro3;
|
|
88
|
+
|
|
87
89
|
const {
|
|
88
90
|
sectionName,
|
|
89
91
|
rowIndex,
|
|
90
92
|
columnIndex
|
|
91
93
|
} = cellLocation;
|
|
92
|
-
return (0
|
|
94
|
+
return (_state$sectionName = state[sectionName]) === null || _state$sectionName === void 0 ? void 0 : (_state$sectionName$ro = _state$sectionName[rowIndex]) === null || _state$sectionName$ro === void 0 ? void 0 : (_state$sectionName$ro2 = _state$sectionName$ro.cells) === null || _state$sectionName$ro2 === void 0 ? void 0 : (_state$sectionName$ro3 = _state$sectionName$ro2[columnIndex]) === null || _state$sectionName$ro3 === void 0 ? void 0 : _state$sectionName$ro3[attributeName];
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
95
97
|
* Returns updated cell attributes after applying the `updateCell` function to the selection.
|
|
@@ -180,13 +182,15 @@ function isCellSelected(cellLocation, selection) {
|
|
|
180
182
|
|
|
181
183
|
|
|
182
184
|
function insertRow(state, _ref3) {
|
|
185
|
+
var _firstRow$cells;
|
|
186
|
+
|
|
183
187
|
let {
|
|
184
188
|
sectionName,
|
|
185
189
|
rowIndex,
|
|
186
190
|
columnCount
|
|
187
191
|
} = _ref3;
|
|
188
192
|
const firstRow = getFirstRow(state);
|
|
189
|
-
const cellCount = columnCount === undefined ?
|
|
193
|
+
const cellCount = columnCount === undefined ? firstRow === null || firstRow === void 0 ? void 0 : (_firstRow$cells = firstRow.cells) === null || _firstRow$cells === void 0 ? void 0 : _firstRow$cells.length : columnCount; // Bail early if the function cannot determine how many cells to add.
|
|
190
194
|
|
|
191
195
|
if (!cellCount) {
|
|
192
196
|
return state;
|
|
@@ -197,7 +201,9 @@ function insertRow(state, _ref3) {
|
|
|
197
201
|
cells: Array.from({
|
|
198
202
|
length: cellCount
|
|
199
203
|
}).map((_, index) => {
|
|
200
|
-
|
|
204
|
+
var _firstRow$cells$index, _firstRow$cells2;
|
|
205
|
+
|
|
206
|
+
const firstCellInColumn = (_firstRow$cells$index = firstRow === null || firstRow === void 0 ? void 0 : (_firstRow$cells2 = firstRow.cells) === null || _firstRow$cells2 === void 0 ? void 0 : _firstRow$cells2[index]) !== null && _firstRow$cells$index !== void 0 ? _firstRow$cells$index : {};
|
|
201
207
|
const inheritedAttributes = Object.fromEntries(Object.entries(firstCellInColumn).filter(_ref4 => {
|
|
202
208
|
let [key] = _ref4;
|
|
203
209
|
return INHERITED_COLUMN_ATTRIBUTES.includes(key);
|
|
@@ -313,6 +319,8 @@ function deleteColumn(state, _ref8) {
|
|
|
313
319
|
|
|
314
320
|
|
|
315
321
|
function toggleSection(state, sectionName) {
|
|
322
|
+
var _state$body$0$cells$l, _state$body, _state$body$, _state$body$$cells;
|
|
323
|
+
|
|
316
324
|
// Section exists, replace it with an empty row to remove it.
|
|
317
325
|
if (!isEmptyTableSection(state[sectionName])) {
|
|
318
326
|
return {
|
|
@@ -321,7 +329,7 @@ function toggleSection(state, sectionName) {
|
|
|
321
329
|
} // Get the length of the first row of the body to use when creating the header.
|
|
322
330
|
|
|
323
331
|
|
|
324
|
-
const columnCount = (0
|
|
332
|
+
const columnCount = (_state$body$0$cells$l = (_state$body = state.body) === null || _state$body === void 0 ? void 0 : (_state$body$ = _state$body[0]) === null || _state$body$ === void 0 ? void 0 : (_state$body$$cells = _state$body$.cells) === null || _state$body$$cells === void 0 ? void 0 : _state$body$$cells.length) !== null && _state$body$0$cells$l !== void 0 ? _state$body$0$cells$l : 1; // Section doesn't exist, insert an empty row to create the section.
|
|
325
333
|
|
|
326
334
|
return insertRow(state, {
|
|
327
335
|
sectionName,
|
package/build/table/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/table/state.js"],"names":["INHERITED_COLUMN_ATTRIBUTES","createTable","rowCount","columnCount","body","Array","from","length","map","cells","content","tag","getFirstRow","state","isEmptyTableSection","head","foot","getCellAttribute","cellLocation","attributeName","sectionName","rowIndex","columnIndex","updateSelectedCell","selection","updateCell","tableSections","Object","fromEntries","entries","filter","key","includes","selectionSectionName","selectionRowIndex","section","row","cellAttributes","isCellSelected","type","insertRow","firstRow","cellCount","undefined","slice","_","index","firstCellInColumn","inheritedAttributes","deleteRow","insertColumn","isEmptyRow","deleteColumn","cell","toggleSection","every"],"mappings":";;;;;;;;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,2BAA2B,GAAG,CAAE,OAAF,CAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,WAAT,OAAkD;AAAA,MAA5B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACxD,SAAO;AACNC,IAAAA,IAAI,EAAEC,KAA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G,CAAC3B,KAAJ,CAAUF,MAA3B,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get, mapValues } from 'lodash';\n\nconst INHERITED_COLUMN_ATTRIBUTES = [ 'align' ];\n\n/**\n * Creates a table state.\n *\n * @param {Object} options\n * @param {number} options.rowCount Row count for the table to create.\n * @param {number} options.columnCount Column count for the table to create.\n *\n * @return {Object} New table state.\n */\nexport function createTable( { rowCount, columnCount } ) {\n\treturn {\n\t\tbody: Array.from( { length: rowCount } ).map( () => ( {\n\t\t\tcells: Array.from( { length: columnCount } ).map( () => ( {\n\t\t\t\tcontent: '',\n\t\t\t\ttag: 'td',\n\t\t\t} ) ),\n\t\t} ) ),\n\t};\n}\n\n/**\n * Returns the first row in the table.\n *\n * @param {Object} state Current table state.\n *\n * @return {Object | undefined} The first table row.\n */\nexport function getFirstRow( state ) {\n\tif ( ! isEmptyTableSection( state.head ) ) {\n\t\treturn state.head[ 0 ];\n\t}\n\tif ( ! isEmptyTableSection( state.body ) ) {\n\t\treturn state.body[ 0 ];\n\t}\n\tif ( ! isEmptyTableSection( state.foot ) ) {\n\t\treturn state.foot[ 0 ];\n\t}\n}\n\n/**\n * Gets an attribute for a cell.\n *\n * @param {Object} state Current table state.\n * @param {Object} cellLocation The location of the cell\n * @param {string} attributeName The name of the attribute to get the value of.\n *\n * @return {*} The attribute value.\n */\nexport function getCellAttribute( state, cellLocation, attributeName ) {\n\tconst { sectionName, rowIndex, columnIndex } = cellLocation;\n\treturn get( state, [\n\t\tsectionName,\n\t\trowIndex,\n\t\t'cells',\n\t\tcolumnIndex,\n\t\tattributeName,\n\t] );\n}\n\n/**\n * Returns updated cell attributes after applying the `updateCell` function to the selection.\n *\n * @param {Object} state The block attributes.\n * @param {Object} selection The selection of cells to update.\n * @param {Function} updateCell A function to update the selected cell attributes.\n *\n * @return {Object} New table state including the updated cells.\n */\nexport function updateSelectedCell( state, selection, updateCell ) {\n\tif ( ! selection ) {\n\t\treturn state;\n\t}\n\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\tconst { sectionName: selectionSectionName, rowIndex: selectionRowIndex } =\n\t\tselection;\n\n\treturn mapValues( tableSections, ( section, sectionName ) => {\n\t\tif ( selectionSectionName && selectionSectionName !== sectionName ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section.map( ( row, rowIndex ) => {\n\t\t\tif ( selectionRowIndex && selectionRowIndex !== rowIndex ) {\n\t\t\t\treturn row;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcells: row.cells.map( ( cellAttributes, columnIndex ) => {\n\t\t\t\t\tconst cellLocation = {\n\t\t\t\t\t\tsectionName,\n\t\t\t\t\t\tcolumnIndex,\n\t\t\t\t\t\trowIndex,\n\t\t\t\t\t};\n\n\t\t\t\t\tif ( ! isCellSelected( cellLocation, selection ) ) {\n\t\t\t\t\t\treturn cellAttributes;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn updateCell( cellAttributes );\n\t\t\t\t} ),\n\t\t\t};\n\t\t} );\n\t} );\n}\n\n/**\n * Returns whether the cell at `cellLocation` is included in the selection `selection`.\n *\n * @param {Object} cellLocation An object containing cell location properties.\n * @param {Object} selection An object containing selection properties.\n *\n * @return {boolean} True if the cell is selected, false otherwise.\n */\nexport function isCellSelected( cellLocation, selection ) {\n\tif ( ! cellLocation || ! selection ) {\n\t\treturn false;\n\t}\n\n\tswitch ( selection.type ) {\n\t\tcase 'column':\n\t\t\treturn (\n\t\t\t\tselection.type === 'column' &&\n\t\t\t\tcellLocation.columnIndex === selection.columnIndex\n\t\t\t);\n\t\tcase 'cell':\n\t\t\treturn (\n\t\t\t\tselection.type === 'cell' &&\n\t\t\t\tcellLocation.sectionName === selection.sectionName &&\n\t\t\t\tcellLocation.columnIndex === selection.columnIndex &&\n\t\t\t\tcellLocation.rowIndex === selection.rowIndex\n\t\t\t);\n\t}\n}\n\n/**\n * Inserts a row in the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {string} options.sectionName Section in which to insert the row.\n * @param {number} options.rowIndex Row index at which to insert the row.\n * @param {number} options.columnCount Column count for the table to create.\n *\n * @return {Object} New table state.\n */\nexport function insertRow( state, { sectionName, rowIndex, columnCount } ) {\n\tconst firstRow = getFirstRow( state );\n\tconst cellCount =\n\t\tcolumnCount === undefined\n\t\t\t? get( firstRow, [ 'cells', 'length' ] )\n\t\t\t: columnCount;\n\n\t// Bail early if the function cannot determine how many cells to add.\n\tif ( ! cellCount ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t[ sectionName ]: [\n\t\t\t...state[ sectionName ].slice( 0, rowIndex ),\n\t\t\t{\n\t\t\t\tcells: Array.from( { length: cellCount } ).map(\n\t\t\t\t\t( _, index ) => {\n\t\t\t\t\t\tconst firstCellInColumn = get(\n\t\t\t\t\t\t\tfirstRow,\n\t\t\t\t\t\t\t[ 'cells', index ],\n\t\t\t\t\t\t\t{}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst inheritedAttributes = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( firstCellInColumn ).filter(\n\t\t\t\t\t\t\t\t( [ key ] ) =>\n\t\t\t\t\t\t\t\t\tINHERITED_COLUMN_ATTRIBUTES.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...inheritedAttributes,\n\t\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t\t\ttag: sectionName === 'head' ? 'th' : 'td',\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t},\n\t\t\t...state[ sectionName ].slice( rowIndex ),\n\t\t],\n\t};\n}\n\n/**\n * Deletes a row from the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {string} options.sectionName Section in which to delete the row.\n * @param {number} options.rowIndex Row index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteRow( state, { sectionName, rowIndex } ) {\n\treturn {\n\t\t[ sectionName ]: state[ sectionName ].filter(\n\t\t\t( row, index ) => index !== rowIndex\n\t\t),\n\t};\n}\n\n/**\n * Inserts a column in the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {number} options.columnIndex Column index at which to insert the column.\n *\n * @return {Object} New table state.\n */\nexport function insertColumn( state, { columnIndex } ) {\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\n\treturn mapValues( tableSections, ( section, sectionName ) => {\n\t\t// Bail early if the table section is empty.\n\t\tif ( isEmptyTableSection( section ) ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section.map( ( row ) => {\n\t\t\t// Bail early if the row is empty or it's an attempt to insert past\n\t\t\t// the last possible index of the array.\n\t\t\tif ( isEmptyRow( row ) || row.cells.length < columnIndex ) {\n\t\t\t\treturn row;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcells: [\n\t\t\t\t\t...row.cells.slice( 0, columnIndex ),\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t\ttag: sectionName === 'head' ? 'th' : 'td',\n\t\t\t\t\t},\n\t\t\t\t\t...row.cells.slice( columnIndex ),\n\t\t\t\t],\n\t\t\t};\n\t\t} );\n\t} );\n}\n\n/**\n * Deletes a column from the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {number} options.columnIndex Column index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteColumn( state, { columnIndex } ) {\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\n\treturn mapValues( tableSections, ( section ) => {\n\t\t// Bail early if the table section is empty.\n\t\tif ( isEmptyTableSection( section ) ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section\n\t\t\t.map( ( row ) => ( {\n\t\t\t\tcells:\n\t\t\t\t\trow.cells.length >= columnIndex\n\t\t\t\t\t\t? row.cells.filter(\n\t\t\t\t\t\t\t\t( cell, index ) => index !== columnIndex\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: row.cells,\n\t\t\t} ) )\n\t\t\t.filter( ( row ) => row.cells.length );\n\t} );\n}\n\n/**\n * Toggles the existence of a section.\n *\n * @param {Object} state Current table state.\n * @param {string} sectionName Name of the section to toggle.\n *\n * @return {Object} New table state.\n */\nexport function toggleSection( state, sectionName ) {\n\t// Section exists, replace it with an empty row to remove it.\n\tif ( ! isEmptyTableSection( state[ sectionName ] ) ) {\n\t\treturn { [ sectionName ]: [] };\n\t}\n\n\t// Get the length of the first row of the body to use when creating the header.\n\tconst columnCount = get( state, [ 'body', 0, 'cells', 'length' ], 1 );\n\n\t// Section doesn't exist, insert an empty row to create the section.\n\treturn insertRow( state, { sectionName, rowIndex: 0, columnCount } );\n}\n\n/**\n * Determines whether a table section is empty.\n *\n * @param {Object} section Table section state.\n *\n * @return {boolean} True if the table section is empty, false otherwise.\n */\nexport function isEmptyTableSection( section ) {\n\treturn ! section || ! section.length || section.every( isEmptyRow );\n}\n\n/**\n * Determines whether a table row is empty.\n *\n * @param {Object} row Table row state.\n *\n * @return {boolean} True if the table section is empty, false otherwise.\n */\nexport function isEmptyRow( row ) {\n\treturn ! ( row.cells && row.cells.length );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/table/state.js"],"names":["INHERITED_COLUMN_ATTRIBUTES","createTable","rowCount","columnCount","body","Array","from","length","map","cells","content","tag","getFirstRow","state","isEmptyTableSection","head","foot","getCellAttribute","cellLocation","attributeName","sectionName","rowIndex","columnIndex","updateSelectedCell","selection","updateCell","tableSections","Object","fromEntries","entries","filter","key","includes","selectionSectionName","selectionRowIndex","section","row","cellAttributes","isCellSelected","type","insertRow","firstRow","cellCount","undefined","slice","_","index","firstCellInColumn","inheritedAttributes","deleteRow","insertColumn","isEmptyRow","deleteColumn","cell","toggleSection","every"],"mappings":";;;;;;;;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,2BAA2B,GAAG,CAAE,OAAF,CAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,WAAT,OAAkD;AAAA,MAA5B;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACxD,SAAO;AACNC,IAAAA,IAAI,EAAEC,KAAK,CAACC,IAAN,CAAY;AAAEC,MAAAA,MAAM,EAAEL;AAAV,KAAZ,EAAmCM,GAAnC,CAAwC,OAAQ;AACrDC,MAAAA,KAAK,EAAEJ,KAAK,CAACC,IAAN,CAAY;AAAEC,QAAAA,MAAM,EAAEJ;AAAV,OAAZ,EAAsCK,GAAtC,CAA2C,OAAQ;AACzDE,QAAAA,OAAO,EAAE,EADgD;AAEzDC,QAAAA,GAAG,EAAE;AAFoD,OAAR,CAA3C;AAD8C,KAAR,CAAxC;AADA,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAsBC,KAAtB,EAA8B;AACpC,MAAK,CAAEC,mBAAmB,CAAED,KAAK,CAACE,IAAR,CAA1B,EAA2C;AAC1C,WAAOF,KAAK,CAACE,IAAN,CAAY,CAAZ,CAAP;AACA;;AACD,MAAK,CAAED,mBAAmB,CAAED,KAAK,CAACT,IAAR,CAA1B,EAA2C;AAC1C,WAAOS,KAAK,CAACT,IAAN,CAAY,CAAZ,CAAP;AACA;;AACD,MAAK,CAAEU,mBAAmB,CAAED,KAAK,CAACG,IAAR,CAA1B,EAA2C;AAC1C,WAAOH,KAAK,CAACG,IAAN,CAAY,CAAZ,CAAP;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BJ,KAA3B,EAAkCK,YAAlC,EAAgDC,aAAhD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;;AACA,SAAOiC,SAAS,CAAE3B,KAAF,EAAS;AAAEO,IAAAA,WAAF;AAAeC,IAAAA,QAAQ,EAAE,CAAzB;AAA4BlB,IAAAA;AAA5B,GAAT,CAAhB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASW,mBAAT,CAA8BqB,OAA9B,EAAwC;AAC9C,SAAO,CAAEA,OAAF,IAAa,CAAEA,OAAO,CAAC5B,MAAvB,IAAiC4B,OAAO,CAACoB,KAAR,CAAeJ,UAAf,CAAxC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASA,UAAT,CAAqBf,GAArB,EAA2B;AACjC,SAAO,EAAIA,GAAG,CAAC3B,KAAJ,IAAa2B,GAAG,CAAC3B,KAAJ,CAAUF,MAA3B,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues } from 'lodash';\n\nconst INHERITED_COLUMN_ATTRIBUTES = [ 'align' ];\n\n/**\n * Creates a table state.\n *\n * @param {Object} options\n * @param {number} options.rowCount Row count for the table to create.\n * @param {number} options.columnCount Column count for the table to create.\n *\n * @return {Object} New table state.\n */\nexport function createTable( { rowCount, columnCount } ) {\n\treturn {\n\t\tbody: Array.from( { length: rowCount } ).map( () => ( {\n\t\t\tcells: Array.from( { length: columnCount } ).map( () => ( {\n\t\t\t\tcontent: '',\n\t\t\t\ttag: 'td',\n\t\t\t} ) ),\n\t\t} ) ),\n\t};\n}\n\n/**\n * Returns the first row in the table.\n *\n * @param {Object} state Current table state.\n *\n * @return {Object | undefined} The first table row.\n */\nexport function getFirstRow( state ) {\n\tif ( ! isEmptyTableSection( state.head ) ) {\n\t\treturn state.head[ 0 ];\n\t}\n\tif ( ! isEmptyTableSection( state.body ) ) {\n\t\treturn state.body[ 0 ];\n\t}\n\tif ( ! isEmptyTableSection( state.foot ) ) {\n\t\treturn state.foot[ 0 ];\n\t}\n}\n\n/**\n * Gets an attribute for a cell.\n *\n * @param {Object} state Current table state.\n * @param {Object} cellLocation The location of the cell\n * @param {string} attributeName The name of the attribute to get the value of.\n *\n * @return {*} The attribute value.\n */\nexport function getCellAttribute( state, cellLocation, attributeName ) {\n\tconst { sectionName, rowIndex, columnIndex } = cellLocation;\n\treturn state[ sectionName ]?.[ rowIndex ]?.cells?.[ columnIndex ]?.[\n\t\tattributeName\n\t];\n}\n\n/**\n * Returns updated cell attributes after applying the `updateCell` function to the selection.\n *\n * @param {Object} state The block attributes.\n * @param {Object} selection The selection of cells to update.\n * @param {Function} updateCell A function to update the selected cell attributes.\n *\n * @return {Object} New table state including the updated cells.\n */\nexport function updateSelectedCell( state, selection, updateCell ) {\n\tif ( ! selection ) {\n\t\treturn state;\n\t}\n\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\tconst { sectionName: selectionSectionName, rowIndex: selectionRowIndex } =\n\t\tselection;\n\n\treturn mapValues( tableSections, ( section, sectionName ) => {\n\t\tif ( selectionSectionName && selectionSectionName !== sectionName ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section.map( ( row, rowIndex ) => {\n\t\t\tif ( selectionRowIndex && selectionRowIndex !== rowIndex ) {\n\t\t\t\treturn row;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcells: row.cells.map( ( cellAttributes, columnIndex ) => {\n\t\t\t\t\tconst cellLocation = {\n\t\t\t\t\t\tsectionName,\n\t\t\t\t\t\tcolumnIndex,\n\t\t\t\t\t\trowIndex,\n\t\t\t\t\t};\n\n\t\t\t\t\tif ( ! isCellSelected( cellLocation, selection ) ) {\n\t\t\t\t\t\treturn cellAttributes;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn updateCell( cellAttributes );\n\t\t\t\t} ),\n\t\t\t};\n\t\t} );\n\t} );\n}\n\n/**\n * Returns whether the cell at `cellLocation` is included in the selection `selection`.\n *\n * @param {Object} cellLocation An object containing cell location properties.\n * @param {Object} selection An object containing selection properties.\n *\n * @return {boolean} True if the cell is selected, false otherwise.\n */\nexport function isCellSelected( cellLocation, selection ) {\n\tif ( ! cellLocation || ! selection ) {\n\t\treturn false;\n\t}\n\n\tswitch ( selection.type ) {\n\t\tcase 'column':\n\t\t\treturn (\n\t\t\t\tselection.type === 'column' &&\n\t\t\t\tcellLocation.columnIndex === selection.columnIndex\n\t\t\t);\n\t\tcase 'cell':\n\t\t\treturn (\n\t\t\t\tselection.type === 'cell' &&\n\t\t\t\tcellLocation.sectionName === selection.sectionName &&\n\t\t\t\tcellLocation.columnIndex === selection.columnIndex &&\n\t\t\t\tcellLocation.rowIndex === selection.rowIndex\n\t\t\t);\n\t}\n}\n\n/**\n * Inserts a row in the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {string} options.sectionName Section in which to insert the row.\n * @param {number} options.rowIndex Row index at which to insert the row.\n * @param {number} options.columnCount Column count for the table to create.\n *\n * @return {Object} New table state.\n */\nexport function insertRow( state, { sectionName, rowIndex, columnCount } ) {\n\tconst firstRow = getFirstRow( state );\n\tconst cellCount =\n\t\tcolumnCount === undefined ? firstRow?.cells?.length : columnCount;\n\n\t// Bail early if the function cannot determine how many cells to add.\n\tif ( ! cellCount ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t[ sectionName ]: [\n\t\t\t...state[ sectionName ].slice( 0, rowIndex ),\n\t\t\t{\n\t\t\t\tcells: Array.from( { length: cellCount } ).map(\n\t\t\t\t\t( _, index ) => {\n\t\t\t\t\t\tconst firstCellInColumn =\n\t\t\t\t\t\t\tfirstRow?.cells?.[ index ] ?? {};\n\n\t\t\t\t\t\tconst inheritedAttributes = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( firstCellInColumn ).filter(\n\t\t\t\t\t\t\t\t( [ key ] ) =>\n\t\t\t\t\t\t\t\t\tINHERITED_COLUMN_ATTRIBUTES.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...inheritedAttributes,\n\t\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t\t\ttag: sectionName === 'head' ? 'th' : 'td',\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t},\n\t\t\t...state[ sectionName ].slice( rowIndex ),\n\t\t],\n\t};\n}\n\n/**\n * Deletes a row from the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {string} options.sectionName Section in which to delete the row.\n * @param {number} options.rowIndex Row index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteRow( state, { sectionName, rowIndex } ) {\n\treturn {\n\t\t[ sectionName ]: state[ sectionName ].filter(\n\t\t\t( row, index ) => index !== rowIndex\n\t\t),\n\t};\n}\n\n/**\n * Inserts a column in the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {number} options.columnIndex Column index at which to insert the column.\n *\n * @return {Object} New table state.\n */\nexport function insertColumn( state, { columnIndex } ) {\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\n\treturn mapValues( tableSections, ( section, sectionName ) => {\n\t\t// Bail early if the table section is empty.\n\t\tif ( isEmptyTableSection( section ) ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section.map( ( row ) => {\n\t\t\t// Bail early if the row is empty or it's an attempt to insert past\n\t\t\t// the last possible index of the array.\n\t\t\tif ( isEmptyRow( row ) || row.cells.length < columnIndex ) {\n\t\t\t\treturn row;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcells: [\n\t\t\t\t\t...row.cells.slice( 0, columnIndex ),\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t\ttag: sectionName === 'head' ? 'th' : 'td',\n\t\t\t\t\t},\n\t\t\t\t\t...row.cells.slice( columnIndex ),\n\t\t\t\t],\n\t\t\t};\n\t\t} );\n\t} );\n}\n\n/**\n * Deletes a column from the table state.\n *\n * @param {Object} state Current table state.\n * @param {Object} options\n * @param {number} options.columnIndex Column index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteColumn( state, { columnIndex } ) {\n\tconst tableSections = Object.fromEntries(\n\t\tObject.entries( state ).filter( ( [ key ] ) =>\n\t\t\t[ 'head', 'body', 'foot' ].includes( key )\n\t\t)\n\t);\n\n\treturn mapValues( tableSections, ( section ) => {\n\t\t// Bail early if the table section is empty.\n\t\tif ( isEmptyTableSection( section ) ) {\n\t\t\treturn section;\n\t\t}\n\n\t\treturn section\n\t\t\t.map( ( row ) => ( {\n\t\t\t\tcells:\n\t\t\t\t\trow.cells.length >= columnIndex\n\t\t\t\t\t\t? row.cells.filter(\n\t\t\t\t\t\t\t\t( cell, index ) => index !== columnIndex\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: row.cells,\n\t\t\t} ) )\n\t\t\t.filter( ( row ) => row.cells.length );\n\t} );\n}\n\n/**\n * Toggles the existence of a section.\n *\n * @param {Object} state Current table state.\n * @param {string} sectionName Name of the section to toggle.\n *\n * @return {Object} New table state.\n */\nexport function toggleSection( state, sectionName ) {\n\t// Section exists, replace it with an empty row to remove it.\n\tif ( ! isEmptyTableSection( state[ sectionName ] ) ) {\n\t\treturn { [ sectionName ]: [] };\n\t}\n\n\t// Get the length of the first row of the body to use when creating the header.\n\tconst columnCount = state.body?.[ 0 ]?.cells?.length ?? 1;\n\n\t// Section doesn't exist, insert an empty row to create the section.\n\treturn insertRow( state, { sectionName, rowIndex: 0, columnCount } );\n}\n\n/**\n * Determines whether a table section is empty.\n *\n * @param {Object} section Table section state.\n *\n * @return {boolean} True if the table section is empty, false otherwise.\n */\nexport function isEmptyTableSection( section ) {\n\treturn ! section || ! section.length || section.every( isEmptyRow );\n}\n\n/**\n * Determines whether a table row is empty.\n *\n * @param {Object} row Table row state.\n *\n * @return {boolean} True if the table section is empty, false otherwise.\n */\nexport function isEmptyRow( row ) {\n\treturn ! ( row.cells && row.cells.length );\n}\n"]}
|
|
@@ -13,8 +13,6 @@ var _data = require("@wordpress/data");
|
|
|
13
13
|
|
|
14
14
|
var _components = require("@wordpress/components");
|
|
15
15
|
|
|
16
|
-
var _blocks = require("@wordpress/blocks");
|
|
17
|
-
|
|
18
16
|
var _coreData = require("@wordpress/core-data");
|
|
19
17
|
|
|
20
18
|
var _notices = require("@wordpress/notices");
|
|
@@ -113,32 +111,14 @@ function TemplatePartImportControls(_ref) {
|
|
|
113
111
|
});
|
|
114
112
|
const skippedWidgets = new Set();
|
|
115
113
|
const blocks = widgets.flatMap(widget => {
|
|
116
|
-
const block = (0, _transformers.transformWidgetToBlock)(widget);
|
|
117
|
-
|
|
118
|
-
if (block.name !== 'core/legacy-widget') {
|
|
119
|
-
return block;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const transforms = (0, _blocks.getPossibleBlockTransformations)([block]).filter(item => {
|
|
123
|
-
var _item$transforms, _item$transforms$from, _item$transforms2, _item$transforms2$to;
|
|
114
|
+
const block = (0, _transformers.transformWidgetToBlock)(widget); // Skip the block if we have no matching transformations.
|
|
124
115
|
|
|
125
|
-
|
|
126
|
-
if (!item.transforms) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const hasWildCardFrom = (_item$transforms = item.transforms) === null || _item$transforms === void 0 ? void 0 : (_item$transforms$from = _item$transforms.from) === null || _item$transforms$from === void 0 ? void 0 : _item$transforms$from.find(from => from.blocks && from.blocks.includes('*'));
|
|
131
|
-
const hasWildCardTo = (_item$transforms2 = item.transforms) === null || _item$transforms2 === void 0 ? void 0 : (_item$transforms2$to = _item$transforms2.to) === null || _item$transforms2$to === void 0 ? void 0 : _item$transforms2$to.find(to => to.blocks && to.blocks.includes('*'));
|
|
132
|
-
return !hasWildCardFrom && !hasWildCardTo;
|
|
133
|
-
}); // Skip the block if we have no matching transformations.
|
|
134
|
-
|
|
135
|
-
if (!transforms.length) {
|
|
116
|
+
if (!block) {
|
|
136
117
|
skippedWidgets.add(widget.id_base);
|
|
137
118
|
return [];
|
|
138
|
-
}
|
|
139
|
-
|
|
119
|
+
}
|
|
140
120
|
|
|
141
|
-
return
|
|
121
|
+
return block;
|
|
142
122
|
});
|
|
143
123
|
await createFromBlocks(blocks,
|
|
144
124
|
/* translators: %s: name of the widget area */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/import-controls.js"],"names":["SIDEBARS_QUERY","per_page","_fields","TemplatePartImportControls","area","setAttributes","selectedSidebar","setSelectedSidebar","isBusy","setIsBusy","registry","sidebars","hasResolved","select","getSidebars","hasFinishedResolution","coreStore","createErrorNotice","noticesStore","createFromBlocks","options","sidebarOptions","filter","widgetArea","id","widgets","length","map","value","label","name","createFromWidgets","event","preventDefault","sidebar","find","getWidgets","resolveSelect","_embed","skippedWidgets","Set","blocks","flatMap","widget","block","transforms","item","hasWildCardFrom","from","includes","hasWildCardTo","to","add","id_base","size","Array","join","type","marginBottom","marginTop"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AAQA;;AAIA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAmBA;AACA;AACA;AAIA,MAAMA,cAAc,GAAG;AACtBC,EAAAA,QAAQ,EAAE,CAAC,CADW;AAEtBC,EAAAA,OAAO,EAAE;AAFa,CAAvB;;AAKO,SAASC,0BAAT,OAA+D;AAAA,MAA1B;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA0B;AACrE,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAU,EAAV,CAAhD;AACA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,uBAAU,KAAV,CAA9B;AAEA,QAAMC,QAAQ,GAAG,wBAAjB;AACA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAA4B,qBAAaC,MAAF,IAAc;AAC1D,UAAM;AAAEC,MAAAA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,IAAA,QAAQ,EAAG,CAAER,OAAO,CAACM,MALtB;AAMC,IAAA,qBAAqB,MANtB;AAOC,IAAA,uBAAuB;AAPxB,IADD,CADD,EAYC,4BAAC,oBAAD;AACC,IAAA,KAAK,EAAG;AACPgC,MAAAA,YAAY,EAAE,KADP;AAEPC,MAAAA,SAAS,EAAE;AAFJ;AADT,KAMC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGnD,MAHV;AAIC,qBAAgBA,MAAM,IAAI,CAAEF;AAJ7B,KAMG,cAAI,QAAJ,CANH,CAND,CAZD,CADD,CADD;AAgCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport {\n\tButton,\n\tFlexBlock,\n\tFlexItem,\n\tSelectControl,\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n} from '@wordpress/components';\nimport {\n\tswitchToBlockType,\n\tgetPossibleBlockTransformations,\n} from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useCreateTemplatePartFromBlocks } from './utils/hooks';\nimport { transformWidgetToBlock } from './utils/transformers';\n\nconst SIDEBARS_QUERY = {\n\tper_page: -1,\n\t_fields: 'id,name,description,status,widgets',\n};\n\nexport function TemplatePartImportControls( { area, setAttributes } ) {\n\tconst [ selectedSidebar, setSelectedSidebar ] = useState( '' );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst registry = useRegistry();\n\tconst { sidebars, hasResolved } = useSelect( ( select ) => {\n\t\tconst { getSidebars, hasFinishedResolution } = select( coreStore );\n\n\t\treturn {\n\t\t\tsidebars: getSidebars( SIDEBARS_QUERY ),\n\t\t\thasResolved: hasFinishedResolution( 'getSidebars', [\n\t\t\t\tSIDEBARS_QUERY,\n\t\t\t] ),\n\t\t};\n\t}, [] );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst createFromBlocks = useCreateTemplatePartFromBlocks(\n\t\tarea,\n\t\tsetAttributes\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst sidebarOptions = ( sidebars ?? [] )\n\t\t\t.filter(\n\t\t\t\t( widgetArea ) =>\n\t\t\t\t\twidgetArea.id !== 'wp_inactive_widgets' &&\n\t\t\t\t\twidgetArea.widgets.length > 0\n\t\t\t)\n\t\t\t.map( ( widgetArea ) => {\n\t\t\t\treturn {\n\t\t\t\t\tvalue: widgetArea.id,\n\t\t\t\t\tlabel: widgetArea.name,\n\t\t\t\t};\n\t\t\t} );\n\n\t\tif ( ! sidebarOptions.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{ value: '', label: __( 'Select widget area' ) },\n\t\t\t...sidebarOptions,\n\t\t];\n\t}, [ sidebars ] );\n\n\t// Render an empty node while data is loading to avoid SlotFill re-positioning bug.\n\t// See: https://github.com/WordPress/gutenberg/issues/15641.\n\tif ( ! hasResolved ) {\n\t\treturn <Spacer marginBottom=\"0\" />;\n\t}\n\n\tif ( hasResolved && ! options.length ) {\n\t\treturn null;\n\t}\n\n\tasync function createFromWidgets( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy || ! selectedSidebar ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst sidebar = options.find(\n\t\t\t( { value } ) => value === selectedSidebar\n\t\t);\n\t\tconst { getWidgets } = registry.resolveSelect( coreStore );\n\n\t\t// The widgets API always returns a successful response.\n\t\tconst widgets = await getWidgets( {\n\t\t\tsidebar: sidebar.value,\n\t\t\t_embed: 'about',\n\t\t} );\n\n\t\tconst skippedWidgets = new Set();\n\t\tconst blocks = widgets.flatMap( ( widget ) => {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\n\t\t\tif ( block.name !== 'core/legacy-widget' ) {\n\t\t\t\treturn block;\n\t\t\t}\n\n\t\t\tconst transforms = getPossibleBlockTransformations( [\n\t\t\t\tblock,\n\t\t\t] ).filter( ( item ) => {\n\t\t\t\t// The block without any transformations can't be a wildcard.\n\t\t\t\tif ( ! item.transforms ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst hasWildCardFrom = item.transforms?.from?.find(\n\t\t\t\t\t( from ) => from.blocks && from.blocks.includes( '*' )\n\t\t\t\t);\n\t\t\t\tconst hasWildCardTo = item.transforms?.to?.find(\n\t\t\t\t\t( to ) => to.blocks && to.blocks.includes( '*' )\n\t\t\t\t);\n\n\t\t\t\treturn ! hasWildCardFrom && ! hasWildCardTo;\n\t\t\t} );\n\n\t\t\t// Skip the block if we have no matching transformations.\n\t\t\tif ( ! transforms.length ) {\n\t\t\t\tskippedWidgets.add( widget.id_base );\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\t// Try transforming the Legacy Widget into a first matching block.\n\t\t\treturn switchToBlockType( block, transforms[ 0 ].name );\n\t\t} );\n\n\t\tawait createFromBlocks(\n\t\t\tblocks,\n\t\t\t/* translators: %s: name of the widget area */\n\t\t\tsprintf( __( 'Widget area: %s' ), sidebar.label )\n\t\t);\n\n\t\tif ( skippedWidgets.size ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: the list of widgets */\n\t\t\t\t\t__( 'Unable to import the following widgets: %s.' ),\n\t\t\t\t\tArray.from( skippedWidgets ).join( ', ' )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tsetIsBusy( false );\n\t}\n\n\treturn (\n\t\t<Spacer marginBottom=\"4\">\n\t\t\t<HStack as=\"form\" onSubmit={ createFromWidgets }>\n\t\t\t\t<FlexBlock>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Import widget area' ) }\n\t\t\t\t\t\tvalue={ selectedSidebar }\n\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\tonChange={ ( value ) => setSelectedSidebar( value ) }\n\t\t\t\t\t\tdisabled={ ! options.length }\n\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t/>\n\t\t\t\t</FlexBlock>\n\t\t\t\t<FlexItem\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tmarginBottom: '8px',\n\t\t\t\t\t\tmarginTop: 'auto',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\taria-disabled={ isBusy || ! selectedSidebar }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Import' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</Spacer>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/import-controls.js"],"names":["SIDEBARS_QUERY","per_page","_fields","TemplatePartImportControls","area","setAttributes","selectedSidebar","setSelectedSidebar","isBusy","setIsBusy","registry","sidebars","hasResolved","select","getSidebars","hasFinishedResolution","coreStore","createErrorNotice","noticesStore","createFromBlocks","options","sidebarOptions","filter","widgetArea","id","widgets","length","map","value","label","name","createFromWidgets","event","preventDefault","sidebar","find","getWidgets","resolveSelect","_embed","skippedWidgets","Set","blocks","flatMap","widget","block","add","id_base","size","Array","from","join","type","marginBottom","marginTop"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AAQA;;AACA;;AAKA;;AACA;;AArBA;AACA;AACA;;AAeA;AACA;AACA;AAIA,MAAMA,cAAc,GAAG;AACtBC,EAAAA,QAAQ,EAAE,CAAC,CADW;AAEtBC,EAAAA,OAAO,EAAE;AAFa,CA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Press dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport {\n\tButton,\n\tFlexBlock,\n\tFlexItem,\n\tSelectControl,\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useCreateTemplatePartFromBlocks } from './utils/hooks';\nimport { transformWidgetToBlock } from './utils/transformers';\n\nconst SIDEBARS_QUERY = {\n\tper_page: -1,\n\t_fields: 'id,name,description,status,widgets',\n};\n\nexport function TemplatePartImportControls( { area, setAttributes } ) {\n\tconst [ selectedSidebar, setSelectedSidebar ] = useState( '' );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst registry = useRegistry();\n\tconst { sidebars, hasResolved } = useSelect( ( select ) => {\n\t\tconst { getSidebars, hasFinishedResolution } = select( coreStore );\n\n\t\treturn {\n\t\t\tsidebars: getSidebars( SIDEBARS_QUERY ),\n\t\t\thasResolved: hasFinishedResolution( 'getSidebars', [\n\t\t\t\tSIDEBARS_QUERY,\n\t\t\t] ),\n\t\t};\n\t}, [] );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst createFromBlocks = useCreateTemplatePartFromBlocks(\n\t\tarea,\n\t\tsetAttributes\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst sidebarOptions = ( sidebars ?? [] )\n\t\t\t.filter(\n\t\t\t\t( widgetArea ) =>\n\t\t\t\t\twidgetArea.id !== 'wp_inactive_widgets' &&\n\t\t\t\t\twidgetArea.widgets.length > 0\n\t\t\t)\n\t\t\t.map( ( widgetArea ) => {\n\t\t\t\treturn {\n\t\t\t\t\tvalue: widgetArea.id,\n\t\t\t\t\tlabel: widgetArea.name,\n\t\t\t\t};\n\t\t\t} );\n\n\t\tif ( ! sidebarOptions.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{ value: '', label: __( 'Select widget area' ) },\n\t\t\t...sidebarOptions,\n\t\t];\n\t}, [ sidebars ] );\n\n\t// Render an empty node while data is loading to avoid SlotFill re-positioning bug.\n\t// See: https://github.com/WordPress/gutenberg/issues/15641.\n\tif ( ! hasResolved ) {\n\t\treturn <Spacer marginBottom=\"0\" />;\n\t}\n\n\tif ( hasResolved && ! options.length ) {\n\t\treturn null;\n\t}\n\n\tasync function createFromWidgets( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy || ! selectedSidebar ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst sidebar = options.find(\n\t\t\t( { value } ) => value === selectedSidebar\n\t\t);\n\t\tconst { getWidgets } = registry.resolveSelect( coreStore );\n\n\t\t// The widgets API always returns a successful response.\n\t\tconst widgets = await getWidgets( {\n\t\t\tsidebar: sidebar.value,\n\t\t\t_embed: 'about',\n\t\t} );\n\n\t\tconst skippedWidgets = new Set();\n\t\tconst blocks = widgets.flatMap( ( widget ) => {\n\t\t\tconst block = transformWidgetToBlock( widget );\n\n\t\t\t// Skip the block if we have no matching transformations.\n\t\t\tif ( ! block ) {\n\t\t\t\tskippedWidgets.add( widget.id_base );\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn block;\n\t\t} );\n\n\t\tawait createFromBlocks(\n\t\t\tblocks,\n\t\t\t/* translators: %s: name of the widget area */\n\t\t\tsprintf( __( 'Widget area: %s' ), sidebar.label )\n\t\t);\n\n\t\tif ( skippedWidgets.size ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: the list of widgets */\n\t\t\t\t\t__( 'Unable to import the following widgets: %s.' ),\n\t\t\t\t\tArray.from( skippedWidgets ).join( ', ' )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tsetIsBusy( false );\n\t}\n\n\treturn (\n\t\t<Spacer marginBottom=\"4\">\n\t\t\t<HStack as=\"form\" onSubmit={ createFromWidgets }>\n\t\t\t\t<FlexBlock>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Import widget area' ) }\n\t\t\t\t\t\tvalue={ selectedSidebar }\n\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\tonChange={ ( value ) => setSelectedSidebar( value ) }\n\t\t\t\t\t\tdisabled={ ! options.length }\n\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t/>\n\t\t\t\t</FlexBlock>\n\t\t\t\t<FlexItem\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tmarginBottom: '8px',\n\t\t\t\t\t\tmarginTop: 'auto',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\taria-disabled={ isBusy || ! selectedSidebar }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Import' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</Spacer>\n\t);\n}\n"]}
|
|
@@ -18,31 +18,81 @@ var _blocks = require("@wordpress/blocks");
|
|
|
18
18
|
* @return {Object} a block (converted from the entity record).
|
|
19
19
|
*/
|
|
20
20
|
function transformWidgetToBlock(widget) {
|
|
21
|
-
if (widget.id_base
|
|
22
|
-
|
|
23
|
-
__unstableSkipAutop: true
|
|
24
|
-
});
|
|
21
|
+
if (widget.id_base !== 'block') {
|
|
22
|
+
let attributes;
|
|
25
23
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
24
|
+
if (widget._embedded.about[0].is_multi) {
|
|
25
|
+
attributes = {
|
|
26
|
+
idBase: widget.id_base,
|
|
27
|
+
instance: widget.instance
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
attributes = {
|
|
31
|
+
id: widget.id
|
|
32
|
+
};
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
return
|
|
35
|
+
return switchLegacyWidgetType((0, _blocks.createBlock)('core/legacy-widget', attributes));
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const parsedBlocks = (0, _blocks.parse)(widget.instance.raw.content, {
|
|
39
|
+
__unstableSkipAutop: true
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!parsedBlocks.length) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const block = parsedBlocks[0];
|
|
47
|
+
|
|
48
|
+
if (block.name === 'core/widget-group') {
|
|
49
|
+
return (0, _blocks.createBlock)((0, _blocks.getGroupingBlockName)(), undefined, transformInnerBlocks(block.innerBlocks));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (block.innerBlocks.length > 0) {
|
|
53
|
+
return (0, _blocks.cloneBlock)(block, undefined, transformInnerBlocks(block.innerBlocks));
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
return
|
|
56
|
+
return block;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Switch Legacy Widget to the first matching transformation block.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} block Legacy Widget block object
|
|
62
|
+
* @return {Object|undefined} a block
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
function switchLegacyWidgetType(block) {
|
|
67
|
+
const transforms = (0, _blocks.getPossibleBlockTransformations)([block]).filter(item => {
|
|
68
|
+
var _item$transforms, _item$transforms$from, _item$transforms2, _item$transforms2$to;
|
|
69
|
+
|
|
70
|
+
// The block without any transformations can't be a wildcard.
|
|
71
|
+
if (!item.transforms) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hasWildCardFrom = (_item$transforms = item.transforms) === null || _item$transforms === void 0 ? void 0 : (_item$transforms$from = _item$transforms.from) === null || _item$transforms$from === void 0 ? void 0 : _item$transforms$from.find(from => from.blocks && from.blocks.includes('*'));
|
|
76
|
+
const hasWildCardTo = (_item$transforms2 = item.transforms) === null || _item$transforms2 === void 0 ? void 0 : (_item$transforms2$to = _item$transforms2.to) === null || _item$transforms2$to === void 0 ? void 0 : _item$transforms2$to.find(to => to.blocks && to.blocks.includes('*')); // Skip wildcard transformations.
|
|
77
|
+
|
|
78
|
+
return !hasWildCardFrom && !hasWildCardTo;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!transforms.length) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (0, _blocks.switchToBlockType)(block, transforms[0].name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function transformInnerBlocks() {
|
|
89
|
+
let innerBlocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
90
|
+
return innerBlocks.flatMap(block => {
|
|
91
|
+
if (block.name === 'core/legacy-widget') {
|
|
92
|
+
return switchLegacyWidgetType(block);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (0, _blocks.createBlock)(block.name, block.attributes, transformInnerBlocks(block.innerBlocks));
|
|
96
|
+
}).filter(block => !!block);
|
|
47
97
|
}
|
|
48
98
|
//# sourceMappingURL=transformers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/utils/transformers.js"],"names":["transformWidgetToBlock","widget","id_base","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/template-part/edit/utils/transformers.js"],"names":["transformWidgetToBlock","widget","id_base","attributes","_embedded","about","is_multi","idBase","instance","id","switchLegacyWidgetType","parsedBlocks","raw","content","__unstableSkipAutop","length","undefined","block","name","transformInnerBlocks","innerBlocks","transforms","filter","item","hasWildCardFrom","from","find","blocks","includes","hasWildCardTo","to","flatMap"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAiCC,MAAjC,EAA0C;AAChD,MAAKA,MAAM,CAACC,OAAP,KAAmB,OAAxB,EAAkC;AACjC,QAAIC,UAAJ;;AACA,QAAKF,MAAM,CAACG,SAAP,CAAiBC,KAAjB,CAAwB,CAAxB,EAA4BC,QAAjC,EAA4C;AAC3CH,MAAAA,UAAU,GAAG;AACZI,QAAAA,MAAM,EAAEN,MAAM,CAACC,OADH;AAEZM,QAAAA,QAAQ,EAAEP,MAAM,CAACO;AAFL,OAAb;AAIA,KALD,MAKO;AACNL,MAAAA,UAAU,GAAG;AACZM,QAAAA,EAAE,EAAER,MAAM,CAACQ;AADC,OAAb;AAGA;;AAED,WAAOC,sBAAsB,CAC5B,yBAAa,oBAAb,EAAmCP,UAAnC,CAD4B,CAA7B;AAGA;;AAED,QAAMQ,YAAY,GAAG,mBAAOV,MAAM,CAACO,QAAP,CAAgBI,GAAhB,CAAoBC,OAA3B,EAAoC;AACxDC,IAAAA,mBAAmB,EAAE;AADmC,GAApC,CAArB;;AAIA,MAAK,CAAEH,YAAY,CAACI,MAApB,EAA6B;AAC5B,WAAOC,SAAP;AACA;;AAED,QAAMC,KAAK,GAAGN,YAAY,CAAE,CAAF,CAA1B;;AAEA,MAAKM,KAAK,CAACC,IAAN,KAAe,mBAApB,EAA0C;AACzC,WAAO,yBACN,mCADM,EAENF,SAFM,EAGNG,oBAAoB,CAAEF,KAAK,CAACG,WAAR,CAHd,CAAP;AAKA;;AAED,MAAKH,KAAK,CAACG,WAAN,CAAkBL,MAAlB,GAA2B,CAAhC,EAAoC;AACnC,WAAO,wBACNE,KADM,EAEND,SAFM,EAGNG,oBAAoB,CAAEF,KAAK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AACG,WAAR,CAHd,CAAP;AAKA,GAXK,EAYLE,MAZK,CAYKL,KAAF,IAAa,CAAC,CAAEA,KAZnB,CAAP;AAaA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tparse,\n\tcloneBlock,\n\tcreateBlock,\n\tgetGroupingBlockName,\n\tgetPossibleBlockTransformations,\n\tswitchToBlockType,\n} from '@wordpress/blocks';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base !== 'block' ) {\n\t\tlet attributes;\n\t\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\t\tattributes = {\n\t\t\t\tidBase: widget.id_base,\n\t\t\t\tinstance: widget.instance,\n\t\t\t};\n\t\t} else {\n\t\t\tattributes = {\n\t\t\t\tid: widget.id,\n\t\t\t};\n\t\t}\n\n\t\treturn switchLegacyWidgetType(\n\t\t\tcreateBlock( 'core/legacy-widget', attributes )\n\t\t);\n\t}\n\n\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t__unstableSkipAutop: true,\n\t} );\n\n\tif ( ! parsedBlocks.length ) {\n\t\treturn undefined;\n\t}\n\n\tconst block = parsedBlocks[ 0 ];\n\n\tif ( block.name === 'core/widget-group' ) {\n\t\treturn createBlock(\n\t\t\tgetGroupingBlockName(),\n\t\t\tundefined,\n\t\t\ttransformInnerBlocks( block.innerBlocks )\n\t\t);\n\t}\n\n\tif ( block.innerBlocks.length > 0 ) {\n\t\treturn cloneBlock(\n\t\t\tblock,\n\t\t\tundefined,\n\t\t\ttransformInnerBlocks( block.innerBlocks )\n\t\t);\n\t}\n\n\treturn block;\n}\n\n/**\n * Switch Legacy Widget to the first matching transformation block.\n *\n * @param {Object} block Legacy Widget block object\n * @return {Object|undefined} a block\n */\nfunction switchLegacyWidgetType( block ) {\n\tconst transforms = getPossibleBlockTransformations( [ block ] ).filter(\n\t\t( item ) => {\n\t\t\t// The block without any transformations can't be a wildcard.\n\t\t\tif ( ! item.transforms ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tconst hasWildCardFrom = item.transforms?.from?.find(\n\t\t\t\t( from ) => from.blocks && from.blocks.includes( '*' )\n\t\t\t);\n\t\t\tconst hasWildCardTo = item.transforms?.to?.find(\n\t\t\t\t( to ) => to.blocks && to.blocks.includes( '*' )\n\t\t\t);\n\n\t\t\t// Skip wildcard transformations.\n\t\t\treturn ! hasWildCardFrom && ! hasWildCardTo;\n\t\t}\n\t);\n\n\tif ( ! transforms.length ) {\n\t\treturn undefined;\n\t}\n\n\treturn switchToBlockType( block, transforms[ 0 ].name );\n}\n\nfunction transformInnerBlocks( innerBlocks = [] ) {\n\treturn innerBlocks\n\t\t.flatMap( ( block ) => {\n\t\t\tif ( block.name === 'core/legacy-widget' ) {\n\t\t\t\treturn switchLegacyWidgetType( block );\n\t\t\t}\n\n\t\t\treturn createBlock(\n\t\t\t\tblock.name,\n\t\t\t\tblock.attributes,\n\t\t\t\ttransformInnerBlocks( block.innerBlocks )\n\t\t\t);\n\t\t} )\n\t\t.filter( ( block ) => !! block );\n}\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = TextColumnsEdit;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
12
|
var _i18n = require("@wordpress/i18n");
|
|
15
13
|
|
|
16
14
|
var _components = require("@wordpress/components");
|
|
@@ -19,10 +17,6 @@ var _blockEditor = require("@wordpress/block-editor");
|
|
|
19
17
|
|
|
20
18
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
21
19
|
|
|
22
|
-
/**
|
|
23
|
-
* External dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
20
|
/**
|
|
27
21
|
* WordPress dependencies
|
|
28
22
|
*/
|
|
@@ -61,12 +55,14 @@ function TextColumnsEdit(_ref) {
|
|
|
61
55
|
}), Array.from({
|
|
62
56
|
length: columns
|
|
63
57
|
}).map((_, index) => {
|
|
58
|
+
var _content$index;
|
|
59
|
+
|
|
64
60
|
return (0, _element.createElement)("div", {
|
|
65
61
|
className: "wp-block-column",
|
|
66
62
|
key: `column-${index}`
|
|
67
63
|
}, (0, _element.createElement)(_blockEditor.RichText, {
|
|
68
64
|
tagName: "p",
|
|
69
|
-
value:
|
|
65
|
+
value: content === null || content === void 0 ? void 0 : (_content$index = content[index]) === null || _content$index === void 0 ? void 0 : _content$index.children,
|
|
70
66
|
onChange: nextContent => {
|
|
71
67
|
setAttributes({
|
|
72
68
|
content: [...content.slice(0, index), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/text-columns/edit.js"],"names":["TextColumnsEdit","attributes","setAttributes","width","content","columns","since","alternative","nextWidth","value","className","Array","from","length","map","_","index","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/text-columns/edit.js"],"names":["TextColumnsEdit","attributes","setAttributes","width","content","columns","since","alternative","nextWidth","value","className","Array","from","length","map","_","index","children","nextContent","slice"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAOA;;AAZA;AACA;AACA;AAYe,SAASA,eAAT,OAA0D;AAAA,MAAhC;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAAgC;AACxE,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA,OAAT;AAAkBC,IAAAA;AAAlB,MAA8BJ,UAApC;AAEA,2BAAY,wBAAZ,EAAsC;AACrCK,IAAAA,KAAK,EAAE,KAD8B;AAErCC,IAAAA,WAAW,EAAE;AAFwB,GAAtC;AAKA,SACC,qDACC,4BAAC,0BAAD,QACC,4BAAC,kCAAD;AACC,IAAA,KAAK,EAAGJ,KADT;AAEC,IAAA,QAAQ,EAAKK,SAAF,IACVN,aAAa,CAAE;AAAEC,MAAAA,KAAK,EAAEK;AAAT,KAAF,CAHf;AAKC,IAAA,Q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AAK,GAAG,CAHI,CAZd;AAiBC,MAAA,WAAW,EAAG,cAAI,YAAJ;AAjBf,MAJD,CADD;AA0BA,GA3BC,CALH,CAzBD,CADD;AA8DA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelBody, RangeControl } from '@wordpress/components';\nimport {\n\tBlockControls,\n\tBlockAlignmentToolbar,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport deprecated from '@wordpress/deprecated';\n\nexport default function TextColumnsEdit( { attributes, setAttributes } ) {\n\tconst { width, content, columns } = attributes;\n\n\tdeprecated( 'The Text Columns block', {\n\t\tsince: '5.3',\n\t\talternative: 'the Columns block',\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<BlockAlignmentToolbar\n\t\t\t\t\tvalue={ width }\n\t\t\t\t\tonChange={ ( nextWidth ) =>\n\t\t\t\t\t\tsetAttributes( { width: nextWidth } )\n\t\t\t\t\t}\n\t\t\t\t\tcontrols={ [ 'center', 'wide', 'full' ] }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody>\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Columns' ) }\n\t\t\t\t\t\tvalue={ columns }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { columns: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmin={ 2 }\n\t\t\t\t\t\tmax={ 4 }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div\n\t\t\t\t{ ...useBlockProps( {\n\t\t\t\t\tclassName: `align${ width } columns-${ columns }`,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ Array.from( { length: columns } ).map( ( _, index ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"wp-block-column\"\n\t\t\t\t\t\t\tkey={ `column-${ index }` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\ttagName=\"p\"\n\t\t\t\t\t\t\t\tvalue={ content?.[ index ]?.children }\n\t\t\t\t\t\t\t\tonChange={ ( nextContent ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t\t\t...content.slice( 0, index ),\n\t\t\t\t\t\t\t\t\t\t\t{ children: nextContent },\n\t\t\t\t\t\t\t\t\t\t\t...content.slice( index + 1 ),\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %d: column index (starting with 1)\n\t\t\t\t\t\t\t\t\t__( 'Column %d text' ),\n\t\t\t\t\t\t\t\t\tindex + 1\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'New Column' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -7,14 +7,8 @@ exports.default = save;
|
|
|
7
7
|
|
|
8
8
|
var _element = require("@wordpress/element");
|
|
9
9
|
|
|
10
|
-
var _lodash = require("lodash");
|
|
11
|
-
|
|
12
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
* External dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* WordPress dependencies
|
|
20
14
|
*/
|
|
@@ -31,12 +25,16 @@ function save(_ref) {
|
|
|
31
25
|
className: `align${width} columns-${columns}`
|
|
32
26
|
}), Array.from({
|
|
33
27
|
length: columns
|
|
34
|
-
}).map((_, index) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
}).map((_, index) => {
|
|
29
|
+
var _content$index;
|
|
30
|
+
|
|
31
|
+
return (0, _element.createElement)("div", {
|
|
32
|
+
className: "wp-block-column",
|
|
33
|
+
key: `column-${index}`
|
|
34
|
+
}, (0, _element.createElement)(_blockEditor.RichText.Content, {
|
|
35
|
+
tagName: "p",
|
|
36
|
+
value: content === null || content === void 0 ? void 0 : (_content$index = content[index]) === null || _content$index === void 0 ? void 0 : _content$index.children
|
|
37
|
+
}));
|
|
38
|
+
}));
|
|
41
39
|
}
|
|
42
40
|
//# sourceMappingURL=save.js.map
|