@wordpress/block-library 11.1.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/build/accordion-heading/block.json +1 -0
- package/build/archives/block.json +3 -0
- package/build/audio/edit.cjs +2 -1
- package/build/audio/edit.cjs.map +2 -2
- package/build/avatar/block.json +4 -0
- package/build/avatar/edit.cjs +31 -1
- package/build/avatar/edit.cjs.map +3 -3
- package/build/button/block.json +6 -0
- package/build/button/edit.cjs +9 -6
- package/build/button/edit.cjs.map +2 -2
- package/build/buttons/block.json +6 -1
- package/build/code/block.json +4 -0
- package/build/column/edit.cjs +5 -0
- package/build/column/edit.cjs.map +2 -2
- package/build/columns/block.json +4 -0
- package/build/columns/edit.cjs +21 -112
- package/build/columns/edit.cjs.map +3 -3
- package/build/comments/edit/placeholder.cjs +95 -87
- package/build/comments/edit/placeholder.cjs.map +2 -2
- package/build/comments-pagination/block.json +11 -0
- package/build/cover/block.json +2 -1
- package/build/cover/edit/index.cjs +26 -5
- package/build/cover/edit/index.cjs.map +2 -2
- package/build/cover/edit/inspector-controls.cjs +4 -1
- package/build/cover/edit/inspector-controls.cjs.map +2 -2
- package/build/cover/embed-video-utils.cjs +9 -8
- package/build/cover/embed-video-utils.cjs.map +2 -2
- package/build/cover/view.cjs +21 -0
- package/build/cover/view.cjs.map +7 -0
- package/build/details/block.json +3 -0
- package/build/embed/block.json +6 -1
- package/build/file/block.json +5 -0
- package/build/footnotes/block.json +4 -0
- package/build/gallery/block.json +13 -0
- package/build/gallery/dynamic-gallery.cjs +32 -93
- package/build/gallery/dynamic-gallery.cjs.map +3 -3
- package/build/gallery/edit.cjs +103 -40
- package/build/gallery/edit.cjs.map +2 -2
- package/build/gallery/order-controls.cjs +107 -0
- package/build/gallery/order-controls.cjs.map +7 -0
- package/build/gallery/order-images.cjs +92 -0
- package/build/gallery/order-images.cjs.map +7 -0
- package/build/gallery/order-options.cjs +62 -0
- package/build/gallery/order-options.cjs.map +7 -0
- package/build/gallery/use-dynamic-gallery.cjs +1 -7
- package/build/gallery/use-dynamic-gallery.cjs.map +2 -2
- package/build/gallery/use-get-media.cjs +2 -3
- package/build/gallery/use-get-media.cjs.map +2 -2
- package/build/group/edit.cjs +3 -3
- package/build/group/edit.cjs.map +2 -2
- package/build/heading/block.json +5 -0
- package/build/home-link/block.json +12 -0
- package/build/icon/components/custom-inserter/index.cjs +3 -1
- package/build/icon/components/custom-inserter/index.cjs.map +2 -2
- package/build/icon/edit.cjs +49 -5
- package/build/icon/edit.cjs.map +2 -2
- package/build/image/use-open-image-media-editor-modal.cjs +32 -28
- package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
- package/build/image/view.cjs +44 -50
- package/build/image/view.cjs.map +2 -2
- package/build/latest-comments/block.json +10 -0
- package/build/latest-posts/block.json +4 -0
- package/build/list/block.json +12 -1
- package/build/list-item/block.json +8 -1
- package/build/list-item/index.cjs +4 -0
- package/build/list-item/index.cjs.map +3 -3
- package/build/loginout/block.json +4 -0
- package/build/math/block.json +4 -0
- package/build/media-text/block.json +18 -0
- package/build/navigation-link/link-ui/index.cjs +33 -19
- package/build/navigation-link/link-ui/index.cjs.map +2 -2
- package/build/navigation-link/shared/index.cjs +5 -0
- package/build/navigation-link/shared/index.cjs.map +2 -2
- package/build/navigation-link/shared/use-block-suggestions.cjs +141 -0
- package/build/navigation-link/shared/use-block-suggestions.cjs.map +7 -0
- package/build/page-list/block.json +4 -0
- package/build/paragraph/block.json +1 -0
- package/build/post-author-biography/block.json +1 -0
- package/build/post-comments-form/block.json +5 -0
- package/build/post-content/block.json +2 -1
- package/build/post-excerpt/block.json +4 -0
- package/build/post-featured-image/block.json +1 -0
- package/build/post-featured-image/edit.cjs +1 -1
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/post-terms/block.json +4 -0
- package/build/post-time-to-read/block.json +4 -0
- package/build/post-title/block.json +4 -0
- package/build/preformatted/block.json +4 -0
- package/build/pullquote/block.json +2 -1
- package/build/query-no-results/block.json +4 -0
- package/build/query-pagination/block.json +17 -0
- package/build/query-total/block.json +4 -0
- package/build/quote/block.json +2 -0
- package/build/read-more/block.json +5 -0
- package/build/rss/block.json +4 -0
- package/build/search/block.json +2 -1
- package/build/site-tagline/block.json +4 -0
- package/build/site-title/block.json +4 -0
- package/build/social-links/block.json +1 -0
- package/build/tab-list/block.json +4 -0
- package/build/tab-list/edit.cjs +3 -1
- package/build/tab-list/edit.cjs.map +3 -3
- package/build/tab-list/save.cjs +3 -1
- package/build/tab-list/save.cjs.map +3 -3
- package/build/tab-panels/block.json +3 -0
- package/build/tabs/block.json +3 -0
- package/build/term-count/block.json +5 -0
- package/build/term-description/block.json +4 -0
- package/build/term-name/block.json +6 -1
- package/build/term-template/block.json +4 -0
- package/build/utils/waveform-utils.cjs +2 -2
- package/build/utils/waveform-utils.cjs.map +2 -2
- package/build/verse/block.json +4 -0
- package/build/video/block.json +7 -1
- package/build/video/edit.cjs +10 -2
- package/build/video/edit.cjs.map +2 -2
- package/build-module/accordion-heading/block.json +1 -0
- package/build-module/archives/block.json +3 -0
- package/build-module/audio/edit.mjs +2 -1
- package/build-module/audio/edit.mjs.map +2 -2
- package/build-module/avatar/block.json +4 -0
- package/build-module/avatar/edit.mjs +33 -2
- package/build-module/avatar/edit.mjs.map +2 -2
- package/build-module/button/block.json +6 -0
- package/build-module/button/edit.mjs +11 -7
- package/build-module/button/edit.mjs.map +2 -2
- package/build-module/buttons/block.json +6 -1
- package/build-module/code/block.json +4 -0
- package/build-module/column/edit.mjs +5 -0
- package/build-module/column/edit.mjs.map +2 -2
- package/build-module/columns/block.json +4 -0
- package/build-module/columns/edit.mjs +22 -122
- package/build-module/columns/edit.mjs.map +2 -2
- package/build-module/comments/edit/placeholder.mjs +95 -87
- package/build-module/comments/edit/placeholder.mjs.map +2 -2
- package/build-module/comments-pagination/block.json +11 -0
- package/build-module/cover/block.json +2 -1
- package/build-module/cover/edit/index.mjs +32 -6
- package/build-module/cover/edit/index.mjs.map +2 -2
- package/build-module/cover/edit/inspector-controls.mjs +5 -2
- package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
- package/build-module/cover/embed-video-utils.mjs +9 -8
- package/build-module/cover/embed-video-utils.mjs.map +2 -2
- package/build-module/cover/view.mjs +19 -0
- package/build-module/cover/view.mjs.map +7 -0
- package/build-module/details/block.json +3 -0
- package/build-module/embed/block.json +6 -1
- package/build-module/file/block.json +5 -0
- package/build-module/footnotes/block.json +4 -0
- package/build-module/gallery/block.json +13 -0
- package/build-module/gallery/dynamic-gallery.mjs +33 -97
- package/build-module/gallery/dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/edit.mjs +110 -42
- package/build-module/gallery/edit.mjs.map +2 -2
- package/build-module/gallery/order-controls.mjs +87 -0
- package/build-module/gallery/order-controls.mjs.map +7 -0
- package/build-module/gallery/order-images.mjs +66 -0
- package/build-module/gallery/order-images.mjs.map +7 -0
- package/build-module/gallery/order-options.mjs +33 -0
- package/build-module/gallery/order-options.mjs.map +7 -0
- package/build-module/gallery/use-dynamic-gallery.mjs +1 -7
- package/build-module/gallery/use-dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/use-get-media.mjs +2 -3
- package/build-module/gallery/use-get-media.mjs.map +2 -2
- package/build-module/group/edit.mjs +4 -4
- package/build-module/group/edit.mjs.map +2 -2
- package/build-module/heading/block.json +5 -0
- package/build-module/home-link/block.json +12 -0
- package/build-module/icon/components/custom-inserter/index.mjs +3 -1
- package/build-module/icon/components/custom-inserter/index.mjs.map +2 -2
- package/build-module/icon/edit.mjs +50 -6
- package/build-module/icon/edit.mjs.map +2 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs +32 -28
- package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
- package/build-module/image/view.mjs +44 -50
- package/build-module/image/view.mjs.map +2 -2
- package/build-module/latest-comments/block.json +10 -0
- package/build-module/latest-posts/block.json +4 -0
- package/build-module/list/block.json +12 -1
- package/build-module/list-item/block.json +8 -1
- package/build-module/list-item/index.mjs +4 -0
- package/build-module/list-item/index.mjs.map +2 -2
- package/build-module/loginout/block.json +4 -0
- package/build-module/math/block.json +4 -0
- package/build-module/media-text/block.json +18 -0
- package/build-module/navigation-link/link-ui/index.mjs +39 -20
- package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/index.mjs +6 -0
- package/build-module/navigation-link/shared/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-block-suggestions.mjs +120 -0
- package/build-module/navigation-link/shared/use-block-suggestions.mjs.map +7 -0
- package/build-module/page-list/block.json +4 -0
- package/build-module/paragraph/block.json +1 -0
- package/build-module/post-author-biography/block.json +1 -0
- package/build-module/post-comments-form/block.json +5 -0
- package/build-module/post-content/block.json +2 -1
- package/build-module/post-excerpt/block.json +4 -0
- package/build-module/post-featured-image/block.json +1 -0
- package/build-module/post-featured-image/edit.mjs +1 -1
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/post-terms/block.json +4 -0
- package/build-module/post-time-to-read/block.json +4 -0
- package/build-module/post-title/block.json +4 -0
- package/build-module/preformatted/block.json +4 -0
- package/build-module/pullquote/block.json +2 -1
- package/build-module/query-no-results/block.json +4 -0
- package/build-module/query-pagination/block.json +17 -0
- package/build-module/query-total/block.json +4 -0
- package/build-module/quote/block.json +2 -0
- package/build-module/read-more/block.json +5 -0
- package/build-module/rss/block.json +4 -0
- package/build-module/search/block.json +2 -1
- package/build-module/site-tagline/block.json +4 -0
- package/build-module/site-title/block.json +4 -0
- package/build-module/social-links/block.json +1 -0
- package/build-module/tab-list/block.json +4 -0
- package/build-module/tab-list/edit.mjs +4 -1
- package/build-module/tab-list/edit.mjs.map +2 -2
- package/build-module/tab-list/save.mjs +4 -1
- package/build-module/tab-list/save.mjs.map +2 -2
- package/build-module/tab-panels/block.json +3 -0
- package/build-module/tabs/block.json +3 -0
- package/build-module/term-count/block.json +5 -0
- package/build-module/term-description/block.json +4 -0
- package/build-module/term-name/block.json +6 -1
- package/build-module/term-template/block.json +4 -0
- package/build-module/utils/waveform-utils.mjs +1 -1
- package/build-module/utils/waveform-utils.mjs.map +1 -1
- package/build-module/verse/block.json +4 -0
- package/build-module/video/block.json +7 -1
- package/build-module/video/edit.mjs +10 -2
- package/build-module/video/edit.mjs.map +2 -2
- package/build-style/avatar/editor-rtl.css +4 -0
- package/build-style/avatar/editor.css +4 -0
- package/build-style/comments-pagination/style-rtl.css +3 -0
- package/build-style/comments-pagination/style.css +3 -0
- package/build-style/common-rtl.css +32 -1
- package/build-style/common.css +35 -2
- package/build-style/editor-rtl.css +11 -4
- package/build-style/editor.css +11 -4
- package/build-style/embed/style-rtl.css +4 -1
- package/build-style/embed/style.css +4 -1
- package/build-style/gallery/editor-rtl.css +1 -3
- package/build-style/gallery/editor.css +1 -3
- package/build-style/image/style-rtl.css +11 -2
- package/build-style/image/style.css +11 -2
- package/build-style/media-text/style-rtl.css +4 -1
- package/build-style/media-text/style.css +4 -1
- package/build-style/query-pagination/style-rtl.css +3 -0
- package/build-style/query-pagination/style.css +3 -0
- package/build-style/style-rtl.css +70 -9
- package/build-style/style.css +73 -10
- package/build-style/table/editor-rtl.css +6 -1
- package/build-style/table/editor.css +6 -1
- package/build-style/table/style-rtl.css +4 -2
- package/build-style/table/style.css +4 -2
- package/build-style/tag-cloud/style-rtl.css +1 -1
- package/build-style/tag-cloud/style.css +1 -1
- package/build-style/verse/style-rtl.css +8 -1
- package/build-style/verse/style.css +8 -1
- package/build-types/gallery/order-controls.d.ts +58 -0
- package/build-types/gallery/order-controls.d.ts.map +1 -0
- package/build-types/gallery/order-options.d.ts +67 -0
- package/build-types/gallery/order-options.d.ts.map +1 -0
- package/package.json +44 -41
- package/src/accordion-heading/README.md +1 -0
- package/src/accordion-heading/block.json +1 -0
- package/src/archives/README.md +2 -0
- package/src/archives/block.json +3 -0
- package/src/audio/edit.jsx +2 -1
- package/src/avatar/README.md +2 -0
- package/src/avatar/block.json +4 -0
- package/src/avatar/edit.jsx +48 -2
- package/src/avatar/editor.scss +4 -0
- package/src/avatar/index.php +5 -3
- package/src/breadcrumbs/index.php +1 -1
- package/src/button/README.md +4 -0
- package/src/button/block.json +6 -0
- package/src/button/edit.jsx +47 -52
- package/src/button/index.php +47 -0
- package/src/buttons/README.md +4 -0
- package/src/buttons/block.json +6 -1
- package/src/code/README.md +3 -0
- package/src/code/block.json +4 -0
- package/src/column/edit.jsx +6 -0
- package/src/columns/README.md +3 -0
- package/src/columns/block.json +4 -0
- package/src/columns/edit.jsx +1 -131
- package/src/comments/edit/placeholder.jsx +5 -1
- package/src/comments-pagination/README.md +4 -0
- package/src/comments-pagination/block.json +11 -0
- package/src/comments-pagination/style.scss +3 -0
- package/src/common.scss +38 -0
- package/src/cover/README.md +1 -0
- package/src/cover/block.json +2 -1
- package/src/cover/edit/index.jsx +38 -6
- package/src/cover/edit/inspector-controls.jsx +10 -1
- package/src/cover/embed-video-utils.js +18 -10
- package/src/cover/index.php +44 -15
- package/src/cover/test/edit.browser.test.js +182 -2
- package/src/cover/test/embed-video-utils.test.js +48 -0
- package/src/cover/view.js +22 -0
- package/src/details/README.md +2 -0
- package/src/details/block.json +3 -0
- package/src/embed/README.md +4 -0
- package/src/embed/block.json +6 -1
- package/src/embed/style.scss +7 -1
- package/src/file/README.md +4 -0
- package/src/file/block.json +5 -0
- package/src/footnotes/README.md +3 -0
- package/src/footnotes/block.json +4 -0
- package/src/gallery/README.md +13 -0
- package/src/gallery/block.json +13 -0
- package/src/gallery/dynamic-gallery.jsx +11 -91
- package/src/gallery/edit.jsx +146 -47
- package/src/gallery/editor.scss +5 -9
- package/src/gallery/order-controls.tsx +143 -0
- package/src/gallery/order-images.js +111 -0
- package/src/gallery/order-options.ts +75 -0
- package/src/gallery/test/edit.jsdom.test.js +87 -10
- package/src/gallery/test/order-images.js +162 -0
- package/src/gallery/use-dynamic-gallery.js +1 -9
- package/src/gallery/use-get-media.js +7 -2
- package/src/group/edit.jsx +5 -5
- package/src/heading/README.md +4 -0
- package/src/heading/block.json +5 -0
- package/src/home-link/README.md +6 -0
- package/src/home-link/block.json +12 -0
- package/src/icon/components/custom-inserter/index.jsx +5 -1
- package/src/icon/edit.jsx +68 -7
- package/src/icon/index.php +1 -1
- package/src/image/index.php +3 -4
- package/src/image/style.scss +14 -2
- package/src/image/test/use-open-image-media-editor-modal.jsdom.test.js +122 -60
- package/src/image/use-open-image-media-editor-modal.js +37 -41
- package/src/image/view.js +64 -68
- package/src/latest-comments/README.md +3 -0
- package/src/latest-comments/block.json +10 -0
- package/src/latest-posts/README.md +3 -0
- package/src/latest-posts/block.json +4 -0
- package/src/list/README.md +6 -0
- package/src/list/block.json +12 -1
- package/src/list-item/README.md +6 -0
- package/src/list-item/block.json +8 -1
- package/src/list-item/index.js +5 -0
- package/src/loginout/README.md +3 -0
- package/src/loginout/block.json +4 -0
- package/src/math/README.md +3 -0
- package/src/math/block.json +4 -0
- package/src/media-text/README.md +17 -0
- package/src/media-text/block.json +18 -0
- package/src/media-text/style.scss +5 -1
- package/src/navigation/test/use-navigation-menu.jsdom.test.js +1 -1
- package/src/navigation-link/README.md +1 -1
- package/src/navigation-link/link-ui/index.jsx +60 -27
- package/src/navigation-link/link-ui/test/get-suggestions-query.jsdom.test.js +67 -0
- package/src/navigation-link/shared/index.js +4 -0
- package/src/navigation-link/shared/test/use-block-suggestions.jsdom.test.js +158 -0
- package/src/navigation-link/shared/test/use-entity-binding.jsdom.test.js +1 -7
- package/src/navigation-link/shared/use-block-suggestions.js +192 -0
- package/src/page-list/README.md +3 -0
- package/src/page-list/block.json +4 -0
- package/src/paragraph/README.md +1 -0
- package/src/paragraph/block.json +1 -0
- package/src/playlist/test/edit-component.jsdom.test.jsx +11 -11
- package/src/playlist-track/test/edit.jsdom.test.jsx +3 -3
- package/src/post-author-biography/README.md +1 -0
- package/src/post-author-biography/block.json +1 -0
- package/src/post-comments-form/README.md +3 -0
- package/src/post-comments-form/block.json +5 -0
- package/src/post-content/README.md +1 -0
- package/src/post-content/block.json +2 -1
- package/src/post-excerpt/README.md +3 -0
- package/src/post-excerpt/block.json +4 -0
- package/src/post-featured-image/block.json +1 -0
- package/src/post-featured-image/edit.jsx +2 -2
- package/src/post-terms/README.md +3 -0
- package/src/post-terms/block.json +4 -0
- package/src/post-time-to-read/README.md +3 -0
- package/src/post-time-to-read/block.json +4 -0
- package/src/post-title/README.md +3 -0
- package/src/post-title/block.json +4 -0
- package/src/preformatted/README.md +3 -0
- package/src/preformatted/block.json +4 -0
- package/src/pullquote/README.md +1 -0
- package/src/pullquote/block.json +2 -1
- package/src/query-no-results/README.md +3 -0
- package/src/query-no-results/block.json +4 -0
- package/src/query-pagination/README.md +4 -0
- package/src/query-pagination/block.json +17 -0
- package/src/query-pagination/style.scss +3 -0
- package/src/query-total/README.md +3 -0
- package/src/query-total/block.json +4 -0
- package/src/quote/README.md +2 -0
- package/src/quote/block.json +2 -0
- package/src/read-more/README.md +3 -0
- package/src/read-more/block.json +5 -0
- package/src/rss/README.md +3 -0
- package/src/rss/block.json +4 -0
- package/src/search/README.md +1 -0
- package/src/search/block.json +2 -1
- package/src/site-tagline/README.md +3 -0
- package/src/site-tagline/block.json +4 -0
- package/src/site-title/README.md +3 -0
- package/src/site-title/block.json +4 -0
- package/src/social-links/README.md +1 -0
- package/src/social-links/block.json +1 -0
- package/src/tab-list/README.md +2 -0
- package/src/tab-list/block.json +4 -0
- package/src/tab-list/edit.jsx +3 -0
- package/src/tab-list/save.jsx +3 -0
- package/src/tab-panels/README.md +2 -0
- package/src/tab-panels/block.json +3 -0
- package/src/table/editor.scss +8 -2
- package/src/table/style.scss +4 -4
- package/src/tabs/README.md +2 -0
- package/src/tabs/block.json +3 -0
- package/src/tag-cloud/style.scss +1 -1
- package/src/template-part/index.php +16 -3
- package/src/term-count/README.md +4 -0
- package/src/term-count/block.json +5 -0
- package/src/term-description/README.md +3 -0
- package/src/term-description/block.json +4 -0
- package/src/term-name/README.md +4 -0
- package/src/term-name/block.json +6 -1
- package/src/term-template/README.md +3 -0
- package/src/term-template/block.json +4 -0
- package/src/utils/test/waveform-player-auto-init.jsdom.test.js +25 -0
- package/src/utils/test/waveform-player-dependency.jsdom.test.js +7 -60
- package/src/utils/test/waveform-utils.browser.test.js +3 -15
- package/src/utils/waveform-utils.js +1 -1
- package/src/verse/README.md +4 -0
- package/src/verse/block.json +4 -0
- package/src/verse/style.scss +11 -2
- package/src/video/README.md +4 -0
- package/src/video/block.json +7 -1
- package/src/video/edit.jsx +13 -2
- package/build/columns/utils.cjs +0 -112
- package/build/columns/utils.cjs.map +0 -7
- package/build-module/columns/utils.mjs +0 -78
- package/build-module/columns/utils.mjs.map +0 -7
- package/src/columns/test/utils.js +0 -331
- package/src/columns/utils.js +0 -176
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import deepFreeze from 'deep-freeze';
|
|
3
|
-
import {
|
|
4
|
-
toWidthPrecision,
|
|
5
|
-
getEffectiveColumnWidth,
|
|
6
|
-
getTotalColumnsWidth,
|
|
7
|
-
getColumnWidths,
|
|
8
|
-
getRedistributedColumnWidths,
|
|
9
|
-
hasExplicitPercentColumnWidths,
|
|
10
|
-
getMappedColumnWidths,
|
|
11
|
-
} from '../utils';
|
|
12
|
-
|
|
13
|
-
describe( 'toWidthPrecision', () => {
|
|
14
|
-
it( 'should round value to standard precision', () => {
|
|
15
|
-
const value = toWidthPrecision( 50.108 );
|
|
16
|
-
|
|
17
|
-
expect( value ).toBe( 50.11 );
|
|
18
|
-
} );
|
|
19
|
-
|
|
20
|
-
it( 'should convert a string value with unit to a number', () => {
|
|
21
|
-
expect( toWidthPrecision( '33.3%' ) ).toBe( 33.3 );
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
it( 'should return undefined for an invalid string', () => {
|
|
25
|
-
expect( toWidthPrecision( 'blahblah' ) ).toBe( undefined );
|
|
26
|
-
} );
|
|
27
|
-
|
|
28
|
-
it( 'should return undefined for invalid number', () => {
|
|
29
|
-
expect( toWidthPrecision( null ) ).toBe( undefined );
|
|
30
|
-
expect( toWidthPrecision( undefined ) ).toBe( undefined );
|
|
31
|
-
} );
|
|
32
|
-
} );
|
|
33
|
-
|
|
34
|
-
describe( 'getEffectiveColumnWidth', () => {
|
|
35
|
-
it( 'should return attribute value if set, rounded to precision', () => {
|
|
36
|
-
const block = { attributes: { width: 50.108 } };
|
|
37
|
-
|
|
38
|
-
const width = getEffectiveColumnWidth( block, 3 );
|
|
39
|
-
|
|
40
|
-
expect( width ).toBe( 50.11 );
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
|
-
it( 'should return assumed width if attribute value not set, rounded to precision', () => {
|
|
44
|
-
const block = { attributes: {} };
|
|
45
|
-
|
|
46
|
-
const width = getEffectiveColumnWidth( block, 3 );
|
|
47
|
-
|
|
48
|
-
expect( width ).toBe( 33.33 );
|
|
49
|
-
} );
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
describe( 'getTotalColumnsWidth', () => {
|
|
53
|
-
describe( 'explicit width', () => {
|
|
54
|
-
const blocks = [
|
|
55
|
-
{ clientId: 'a', attributes: { width: 30 } },
|
|
56
|
-
{ clientId: 'b', attributes: { width: 40 } },
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
it( 'returns the sum total of columns width', () => {
|
|
60
|
-
const width = getTotalColumnsWidth( blocks );
|
|
61
|
-
|
|
62
|
-
expect( width ).toBe( 70 );
|
|
63
|
-
} );
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
|
-
describe( 'implicit width', () => {
|
|
67
|
-
const blocks = [
|
|
68
|
-
{ clientId: 'a', attributes: {} },
|
|
69
|
-
{ clientId: 'b', attributes: {} },
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
it( 'returns the sum total of columns width', () => {
|
|
73
|
-
const widths = getTotalColumnsWidth( blocks );
|
|
74
|
-
|
|
75
|
-
expect( widths ).toBe( 100 );
|
|
76
|
-
} );
|
|
77
|
-
} );
|
|
78
|
-
} );
|
|
79
|
-
|
|
80
|
-
describe( 'getColumnWidths', () => {
|
|
81
|
-
describe( 'explicit width', () => {
|
|
82
|
-
const blocks = [
|
|
83
|
-
{ clientId: 'a', attributes: { width: 30.459 } },
|
|
84
|
-
{ clientId: 'b', attributes: { width: 29.543 } },
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
it( 'returns the column widths', () => {
|
|
88
|
-
const widths = getColumnWidths( blocks );
|
|
89
|
-
|
|
90
|
-
expect( widths ).toEqual( {
|
|
91
|
-
a: 30.46,
|
|
92
|
-
b: 29.54,
|
|
93
|
-
} );
|
|
94
|
-
} );
|
|
95
|
-
} );
|
|
96
|
-
|
|
97
|
-
describe( 'implicit width', () => {
|
|
98
|
-
const blocks = [
|
|
99
|
-
{ clientId: 'a', attributes: {} },
|
|
100
|
-
{ clientId: 'b', attributes: {} },
|
|
101
|
-
];
|
|
102
|
-
|
|
103
|
-
it( 'returns the column widths', () => {
|
|
104
|
-
const widths = getColumnWidths( blocks );
|
|
105
|
-
|
|
106
|
-
expect( widths ).toEqual( {
|
|
107
|
-
a: 50,
|
|
108
|
-
b: 50,
|
|
109
|
-
} );
|
|
110
|
-
} );
|
|
111
|
-
} );
|
|
112
|
-
} );
|
|
113
|
-
|
|
114
|
-
describe( 'getRedistributedColumnWidths', () => {
|
|
115
|
-
describe( 'explicit width', () => {
|
|
116
|
-
let blocks = [
|
|
117
|
-
{ clientId: 'a', attributes: { width: 30 } },
|
|
118
|
-
{ clientId: 'b', attributes: { width: 40 } },
|
|
119
|
-
];
|
|
120
|
-
|
|
121
|
-
it( 'should constrain to fit available width', () => {
|
|
122
|
-
const widths = getRedistributedColumnWidths( blocks, 60 );
|
|
123
|
-
|
|
124
|
-
expect( widths ).toEqual( {
|
|
125
|
-
a: 25.71,
|
|
126
|
-
b: 34.29,
|
|
127
|
-
} );
|
|
128
|
-
} );
|
|
129
|
-
|
|
130
|
-
it( 'should expand to fit available width', () => {
|
|
131
|
-
const widths = getRedistributedColumnWidths( blocks, 80 );
|
|
132
|
-
|
|
133
|
-
expect( widths ).toEqual( {
|
|
134
|
-
a: 34.29,
|
|
135
|
-
b: 45.71,
|
|
136
|
-
} );
|
|
137
|
-
} );
|
|
138
|
-
|
|
139
|
-
it( 'should decrease proportionally for third column', () => {
|
|
140
|
-
blocks = [
|
|
141
|
-
{ clientId: 'a', attributes: { width: 99 } },
|
|
142
|
-
{ clientId: 'b', attributes: { width: 1 } },
|
|
143
|
-
];
|
|
144
|
-
const widths = getRedistributedColumnWidths( blocks, 66.67 );
|
|
145
|
-
|
|
146
|
-
expect( widths ).toEqual( {
|
|
147
|
-
a: 66,
|
|
148
|
-
b: 0.67,
|
|
149
|
-
} );
|
|
150
|
-
} );
|
|
151
|
-
|
|
152
|
-
it( 'should decrease proportionally for fourth column', () => {
|
|
153
|
-
blocks = [
|
|
154
|
-
{ clientId: 'a', attributes: { width: 98 } },
|
|
155
|
-
{ clientId: 'b', attributes: { width: 1 } },
|
|
156
|
-
{ clientId: 'c', attributes: { width: 1 } },
|
|
157
|
-
];
|
|
158
|
-
const widths = getRedistributedColumnWidths( blocks, 75 );
|
|
159
|
-
|
|
160
|
-
expect( widths ).toEqual( {
|
|
161
|
-
a: 73.5,
|
|
162
|
-
b: 0.75,
|
|
163
|
-
c: 0.75,
|
|
164
|
-
} );
|
|
165
|
-
} );
|
|
166
|
-
} );
|
|
167
|
-
|
|
168
|
-
describe( 'implicit width', () => {
|
|
169
|
-
const blocks = [
|
|
170
|
-
{ clientId: 'a', attributes: {} },
|
|
171
|
-
{ clientId: 'b', attributes: {} },
|
|
172
|
-
];
|
|
173
|
-
|
|
174
|
-
it( 'should equally distribute to available width', () => {
|
|
175
|
-
const widths = getRedistributedColumnWidths( blocks, 60 );
|
|
176
|
-
|
|
177
|
-
expect( widths ).toEqual( {
|
|
178
|
-
a: 30,
|
|
179
|
-
b: 30,
|
|
180
|
-
} );
|
|
181
|
-
} );
|
|
182
|
-
|
|
183
|
-
it( 'should constrain to fit available width', () => {
|
|
184
|
-
const widths = getRedistributedColumnWidths( blocks, 66.66, 3 );
|
|
185
|
-
|
|
186
|
-
expect( widths ).toEqual( {
|
|
187
|
-
a: 33.33,
|
|
188
|
-
b: 33.33,
|
|
189
|
-
} );
|
|
190
|
-
} );
|
|
191
|
-
} );
|
|
192
|
-
} );
|
|
193
|
-
|
|
194
|
-
describe( 'hasExplicitPercentColumnWidths', () => {
|
|
195
|
-
it( 'returns false if no blocks have explicit width', () => {
|
|
196
|
-
const blocks = [ { attributes: {} } ];
|
|
197
|
-
|
|
198
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
199
|
-
|
|
200
|
-
expect( result ).toBe( false );
|
|
201
|
-
} );
|
|
202
|
-
|
|
203
|
-
it( 'returns true if a block has explicit width defined as a number', () => {
|
|
204
|
-
const blocks = [ { attributes: { width: 100 } } ];
|
|
205
|
-
|
|
206
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
207
|
-
|
|
208
|
-
expect( result ).toBe( true );
|
|
209
|
-
} );
|
|
210
|
-
|
|
211
|
-
it( 'returns true if a block has explicit percent width defined as a string', () => {
|
|
212
|
-
const blocks = [ { attributes: { width: '100%' } } ];
|
|
213
|
-
|
|
214
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
215
|
-
|
|
216
|
-
expect( result ).toBe( true );
|
|
217
|
-
} );
|
|
218
|
-
|
|
219
|
-
it( 'returns false if some, not all blocks have explicit width', () => {
|
|
220
|
-
const blocks = [
|
|
221
|
-
{ attributes: { width: 10 } },
|
|
222
|
-
{ attributes: { width: undefined } },
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
226
|
-
|
|
227
|
-
expect( result ).toBe( false );
|
|
228
|
-
} );
|
|
229
|
-
|
|
230
|
-
it( 'returns true if all blocks have explicit width', () => {
|
|
231
|
-
const blocks = [
|
|
232
|
-
{ attributes: { width: 10 } },
|
|
233
|
-
{ attributes: { width: 90 } },
|
|
234
|
-
];
|
|
235
|
-
|
|
236
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
237
|
-
|
|
238
|
-
expect( result ).toBe( true );
|
|
239
|
-
} );
|
|
240
|
-
|
|
241
|
-
it( 'returns true if blocks have width defined as percent strings and numbers', () => {
|
|
242
|
-
const blocks = [
|
|
243
|
-
{ attributes: { width: '10%' } },
|
|
244
|
-
{ attributes: { width: 90 } },
|
|
245
|
-
];
|
|
246
|
-
|
|
247
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
248
|
-
|
|
249
|
-
expect( result ).toBe( true );
|
|
250
|
-
} );
|
|
251
|
-
|
|
252
|
-
it( 'returns false if blocks have width defined as mixed unit strings', () => {
|
|
253
|
-
const blocks = [
|
|
254
|
-
{ attributes: { width: '20%' } },
|
|
255
|
-
{ attributes: { width: '90px' } },
|
|
256
|
-
];
|
|
257
|
-
|
|
258
|
-
const result = hasExplicitPercentColumnWidths( blocks );
|
|
259
|
-
|
|
260
|
-
expect( result ).toBe( false );
|
|
261
|
-
} );
|
|
262
|
-
} );
|
|
263
|
-
|
|
264
|
-
describe( 'getMappedColumnWidths', () => {
|
|
265
|
-
it( 'merges to block attributes using provided widths', () => {
|
|
266
|
-
const blocks = [
|
|
267
|
-
{ clientId: 'a', attributes: { width: 30 } },
|
|
268
|
-
{ clientId: 'b', attributes: { width: 40 } },
|
|
269
|
-
];
|
|
270
|
-
const widths = {
|
|
271
|
-
a: 25,
|
|
272
|
-
b: 35,
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const result = getMappedColumnWidths( blocks, widths );
|
|
276
|
-
|
|
277
|
-
expect( result ).toEqual( [
|
|
278
|
-
{ clientId: 'a', attributes: { width: '25%' } },
|
|
279
|
-
{ clientId: 'b', attributes: { width: '35%' } },
|
|
280
|
-
] );
|
|
281
|
-
} );
|
|
282
|
-
|
|
283
|
-
it( 'always returns new objects and does not mutate input blocks', () => {
|
|
284
|
-
const blocks = [
|
|
285
|
-
deepFreeze( { clientId: 'a', attributes: { width: 30 } } ),
|
|
286
|
-
deepFreeze( { clientId: 'b', attributes: { width: 40 } } ),
|
|
287
|
-
];
|
|
288
|
-
const widths = {
|
|
289
|
-
a: 25,
|
|
290
|
-
b: 35,
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const result = getMappedColumnWidths( blocks, widths );
|
|
294
|
-
|
|
295
|
-
expect( blocks[ 0 ] ).not.toBe( result[ 0 ] );
|
|
296
|
-
expect( blocks[ 1 ] ).not.toBe( result[ 1 ] );
|
|
297
|
-
} );
|
|
298
|
-
|
|
299
|
-
it( 'merges to block attributes if original blocks do not have any attributes', () => {
|
|
300
|
-
const blocks = [ { clientId: 'a' }, { clientId: 'b' } ];
|
|
301
|
-
const widths = {
|
|
302
|
-
a: 25,
|
|
303
|
-
b: 35,
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const result = getMappedColumnWidths( blocks, widths );
|
|
307
|
-
|
|
308
|
-
expect( result ).toEqual( [
|
|
309
|
-
{ clientId: 'a', attributes: { width: '25%' } },
|
|
310
|
-
{ clientId: 'b', attributes: { width: '35%' } },
|
|
311
|
-
] );
|
|
312
|
-
} );
|
|
313
|
-
|
|
314
|
-
it( 'merges to block attributes if original blocks do not have a width attribute', () => {
|
|
315
|
-
const blocks = [
|
|
316
|
-
{ clientId: 'a', attributes: { align: 'left' } },
|
|
317
|
-
{ clientId: 'b', attributes: { align: 'right' } },
|
|
318
|
-
];
|
|
319
|
-
const widths = {
|
|
320
|
-
a: 25,
|
|
321
|
-
b: 35,
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const result = getMappedColumnWidths( blocks, widths );
|
|
325
|
-
|
|
326
|
-
expect( result ).toEqual( [
|
|
327
|
-
{ clientId: 'a', attributes: { align: 'left', width: '25%' } },
|
|
328
|
-
{ clientId: 'b', attributes: { align: 'right', width: '35%' } },
|
|
329
|
-
] );
|
|
330
|
-
} );
|
|
331
|
-
} );
|
package/src/columns/utils.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a column width attribute value rounded to standard precision.
|
|
3
|
-
* Returns `undefined` if the value is not a valid finite number.
|
|
4
|
-
*
|
|
5
|
-
* @param {?number} value Raw value.
|
|
6
|
-
*
|
|
7
|
-
* @return {number} Value rounded to standard precision.
|
|
8
|
-
*/
|
|
9
|
-
export const toWidthPrecision = ( value ) => {
|
|
10
|
-
const unitlessValue = parseFloat( value );
|
|
11
|
-
return Number.isFinite( unitlessValue )
|
|
12
|
-
? parseFloat( unitlessValue.toFixed( 2 ) )
|
|
13
|
-
: undefined;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Returns an effective width for a given block. An effective width is equal to
|
|
17
|
-
* its attribute value if set, or a computed value assuming equal distribution.
|
|
18
|
-
*
|
|
19
|
-
* @param {WPBlock} block Block object.
|
|
20
|
-
* @param {number} totalBlockCount Total number of blocks in Columns.
|
|
21
|
-
*
|
|
22
|
-
* @return {number} Effective column width.
|
|
23
|
-
*/
|
|
24
|
-
export function getEffectiveColumnWidth( block, totalBlockCount ) {
|
|
25
|
-
const { width = 100 / totalBlockCount } = block.attributes;
|
|
26
|
-
return toWidthPrecision( width );
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Returns the total width occupied by the given set of column blocks.
|
|
31
|
-
*
|
|
32
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
33
|
-
* @param {?number} totalBlockCount Total number of blocks in Columns.
|
|
34
|
-
* Defaults to number of blocks passed.
|
|
35
|
-
*
|
|
36
|
-
* @return {number} Total width occupied by blocks.
|
|
37
|
-
*/
|
|
38
|
-
export function getTotalColumnsWidth(
|
|
39
|
-
blocks,
|
|
40
|
-
totalBlockCount = blocks.length
|
|
41
|
-
) {
|
|
42
|
-
return blocks.reduce(
|
|
43
|
-
( sum, block ) =>
|
|
44
|
-
sum + getEffectiveColumnWidth( block, totalBlockCount ),
|
|
45
|
-
0
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns an object of `clientId` → `width` of effective column widths.
|
|
51
|
-
*
|
|
52
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
53
|
-
* @param {?number} totalBlockCount Total number of blocks in Columns.
|
|
54
|
-
* Defaults to number of blocks passed.
|
|
55
|
-
*
|
|
56
|
-
* @return {Object<string,number>} Column widths.
|
|
57
|
-
*/
|
|
58
|
-
export function getColumnWidths( blocks, totalBlockCount = blocks.length ) {
|
|
59
|
-
return blocks.reduce( ( accumulator, block ) => {
|
|
60
|
-
const width = getEffectiveColumnWidth( block, totalBlockCount );
|
|
61
|
-
return Object.assign( accumulator, { [ block.clientId ]: width } );
|
|
62
|
-
}, {} );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Returns an object of `clientId` → `width` of column widths as redistributed
|
|
67
|
-
* proportional to their current widths, constrained or expanded to fit within
|
|
68
|
-
* the given available width.
|
|
69
|
-
*
|
|
70
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
71
|
-
* @param {number} availableWidth Maximum width to fit within.
|
|
72
|
-
* @param {?number} totalBlockCount Total number of blocks in Columns.
|
|
73
|
-
* Defaults to number of blocks passed.
|
|
74
|
-
*
|
|
75
|
-
* @return {Object<string,number>} Redistributed column widths.
|
|
76
|
-
*/
|
|
77
|
-
export function getRedistributedColumnWidths(
|
|
78
|
-
blocks,
|
|
79
|
-
availableWidth,
|
|
80
|
-
totalBlockCount = blocks.length
|
|
81
|
-
) {
|
|
82
|
-
const totalWidth = getTotalColumnsWidth( blocks, totalBlockCount );
|
|
83
|
-
|
|
84
|
-
return Object.fromEntries(
|
|
85
|
-
Object.entries( getColumnWidths( blocks, totalBlockCount ) ).map(
|
|
86
|
-
( [ clientId, width ] ) => {
|
|
87
|
-
const newWidth = ( availableWidth * width ) / totalWidth;
|
|
88
|
-
return [ clientId, toWidthPrecision( newWidth ) ];
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns true if column blocks within the provided set are assigned with
|
|
96
|
-
* explicit widths, or false otherwise.
|
|
97
|
-
*
|
|
98
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
99
|
-
*
|
|
100
|
-
* @return {boolean} Whether columns have explicit widths.
|
|
101
|
-
*/
|
|
102
|
-
export function hasExplicitPercentColumnWidths( blocks ) {
|
|
103
|
-
return blocks.every( ( block ) => {
|
|
104
|
-
const blockWidth = block.attributes.width;
|
|
105
|
-
return Number.isFinite(
|
|
106
|
-
blockWidth?.endsWith?.( '%' )
|
|
107
|
-
? parseFloat( blockWidth )
|
|
108
|
-
: blockWidth
|
|
109
|
-
);
|
|
110
|
-
} );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Returns a copy of the given set of blocks with new widths assigned from the
|
|
115
|
-
* provided object of redistributed column widths.
|
|
116
|
-
*
|
|
117
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
118
|
-
* @param {Object<string,number>} widths Redistributed column widths.
|
|
119
|
-
*
|
|
120
|
-
* @return {WPBlock[]} blocks Mapped block objects.
|
|
121
|
-
*/
|
|
122
|
-
export function getMappedColumnWidths( blocks, widths ) {
|
|
123
|
-
return blocks.map( ( block ) => ( {
|
|
124
|
-
...block,
|
|
125
|
-
attributes: {
|
|
126
|
-
...block.attributes,
|
|
127
|
-
width: `${ widths[ block.clientId ] }%`,
|
|
128
|
-
},
|
|
129
|
-
} ) );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Returns an array with columns widths values, parsed or no depends on `withParsing` flag.
|
|
134
|
-
*
|
|
135
|
-
* @param {WPBlock[]} blocks Block objects.
|
|
136
|
-
* @param {?boolean} withParsing Whether value has to be parsed.
|
|
137
|
-
*
|
|
138
|
-
* @return {Array<number,string>} Column widths.
|
|
139
|
-
*/
|
|
140
|
-
export function getWidths( blocks, withParsing = true ) {
|
|
141
|
-
return blocks.map( ( innerColumn ) => {
|
|
142
|
-
const innerColumnWidth =
|
|
143
|
-
innerColumn.attributes.width || 100 / blocks.length;
|
|
144
|
-
|
|
145
|
-
return withParsing ? parseFloat( innerColumnWidth ) : innerColumnWidth;
|
|
146
|
-
} );
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Returns a column width with unit.
|
|
151
|
-
*
|
|
152
|
-
* @param {string} width Column width.
|
|
153
|
-
* @param {string} unit Column width unit.
|
|
154
|
-
*
|
|
155
|
-
* @return {string} Column width with unit.
|
|
156
|
-
*/
|
|
157
|
-
export function getWidthWithUnit( width, unit ) {
|
|
158
|
-
width = 0 > parseFloat( width ) ? '0' : width;
|
|
159
|
-
|
|
160
|
-
if ( isPercentageUnit( unit ) ) {
|
|
161
|
-
width = Math.min( width, 100 );
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return `${ width }${ unit }`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns a boolean whether passed unit is percentage
|
|
169
|
-
*
|
|
170
|
-
* @param {string} unit Column width unit.
|
|
171
|
-
*
|
|
172
|
-
* @return {boolean} Whether unit is '%'.
|
|
173
|
-
*/
|
|
174
|
-
export function isPercentageUnit( unit ) {
|
|
175
|
-
return unit === '%';
|
|
176
|
-
}
|