From 059287a5b1cc56b95fa6006fef33e9c44e29b52e Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 24 Oct 2023 21:21:29 +0200 Subject: [PATCH 01/27] Lazy load block edit functions --- packages/block-library/src/archives/index.js | 6 ++++-- packages/block-library/src/audio/index.js | 7 +++++-- packages/block-library/src/avatar/index.js | 6 ++++-- packages/block-library/src/block/index.js | 6 ++++-- packages/block-library/src/button/index.js | 7 +++++-- packages/block-library/src/buttons/index.js | 7 +++++-- packages/block-library/src/calendar/index.js | 7 +++++-- packages/block-library/src/categories/index.js | 6 ++++-- packages/block-library/src/code/index.js | 7 +++++-- packages/block-library/src/column/index.js | 7 +++++-- packages/block-library/src/columns/index.js | 7 +++++-- .../src/comment-author-avatar/index.js | 8 ++++++-- .../src/comment-author-name/index.js | 7 +++++-- .../block-library/src/comment-content/index.js | 6 ++++-- packages/block-library/src/comment-date/index.js | 7 +++++-- .../block-library/src/comment-edit-link/index.js | 6 ++++-- .../src/comment-reply-link/index.js | 6 ++++-- .../block-library/src/comment-template/index.js | 7 +++++-- .../src/comments-pagination-next/index.js | 8 ++++++-- .../src/comments-pagination-numbers/index.js | 8 ++++++-- .../src/comments-pagination-previous/index.js | 8 ++++++-- .../src/comments-pagination/index.js | 7 +++++-- .../block-library/src/comments-title/index.js | 7 +++++-- packages/block-library/src/comments/index.js | 7 +++++-- packages/block-library/src/cover/index.js | 6 ++++-- packages/block-library/src/details/index.js | 7 +++++-- packages/block-library/src/embed/index.js | 7 +++++-- packages/block-library/src/file/index.js | 7 +++++-- packages/block-library/src/footnotes/index.js | 7 +++++-- packages/block-library/src/form-input/index.js | 6 ++++-- .../src/form-submission-notification/index.js | 9 +++++++-- .../src/form-submit-button/index.js | 7 +++++-- packages/block-library/src/form/index.js | 7 +++++-- packages/block-library/src/freeform/index.js | 7 +++++-- packages/block-library/src/gallery/index.js | 6 ++++-- packages/block-library/src/group/index.js | 7 +++++-- packages/block-library/src/heading/index.js | 7 +++++-- packages/block-library/src/home-link/index.js | 7 +++++-- packages/block-library/src/html/index.js | 7 +++++-- packages/block-library/src/image/index.js | 6 ++++-- .../block-library/src/latest-comments/index.js | 6 ++++-- packages/block-library/src/latest-posts/index.js | 7 +++++-- packages/block-library/src/list-item/index.js | 7 +++++-- packages/block-library/src/list/index.js | 7 +++++-- packages/block-library/src/loginout/index.js | 7 +++++-- packages/block-library/src/media-text/index.js | 7 +++++-- packages/block-library/src/missing/index.js | 7 +++++-- packages/block-library/src/more/index.js | 7 +++++-- .../block-library/src/navigation-link/index.js | 7 +++++-- .../src/navigation-submenu/index.js | 6 ++++-- packages/block-library/src/navigation/index.js | 6 ++++-- packages/block-library/src/nextpage/index.js | 7 +++++-- .../block-library/src/page-list-item/index.js | 6 ++++-- packages/block-library/src/page-list/index.js | 6 ++++-- packages/block-library/src/paragraph/index.js | 6 ++++-- packages/block-library/src/pattern/index.js | 6 ++++-- .../src/post-author-biography/index.js | 8 ++++++-- .../block-library/src/post-author-name/index.js | 7 +++++-- packages/block-library/src/post-author/index.js | 6 ++++-- packages/block-library/src/post-comment/index.js | 7 +++++-- .../src/post-comments-count/index.js | 6 ++++-- .../src/post-comments-form/index.js | 6 ++++-- .../src/post-comments-link/index.js | 6 ++++-- packages/block-library/src/post-content/index.js | 6 ++++-- packages/block-library/src/post-date/index.js | 7 +++++-- packages/block-library/src/post-excerpt/index.js | 7 +++++-- .../src/post-featured-image/index.js | 6 ++++-- .../src/post-navigation-link/index.js | 7 +++++-- .../block-library/src/post-template/index.js | 7 +++++-- packages/block-library/src/post-terms/index.js | 7 +++++-- .../block-library/src/post-time-to-read/index.js | 7 +++++-- packages/block-library/src/post-title/index.js | 7 +++++-- packages/block-library/src/preformatted/index.js | 7 +++++-- packages/block-library/src/pullquote/index.js | 7 +++++-- .../block-library/src/query-no-results/index.js | 7 +++++-- .../src/query-pagination-next/index.js | 8 ++++++-- .../src/query-pagination-numbers/index.js | 8 ++++++-- .../src/query-pagination-previous/index.js | 8 ++++++-- .../block-library/src/query-pagination/index.js | 7 +++++-- packages/block-library/src/query-title/index.js | 7 +++++-- packages/block-library/src/query/index.js | 7 +++++-- packages/block-library/src/quote/index.js | 7 +++++-- packages/block-library/src/read-more/index.js | 6 ++++-- packages/block-library/src/rss/index.js | 6 ++++-- packages/block-library/src/search/index.js | 7 +++++-- packages/block-library/src/separator/index.js | 7 +++++-- packages/block-library/src/shortcode/index.js | 6 ++++-- packages/block-library/src/site-logo/index.js | 6 ++++-- packages/block-library/src/site-tagline/index.js | 6 ++++-- packages/block-library/src/site-title/index.js | 7 +++++-- packages/block-library/src/social-link/index.js | 6 ++++-- packages/block-library/src/social-links/index.js | 6 ++++-- packages/block-library/src/spacer/index.js | 7 +++++-- .../block-library/src/table-of-contents/index.js | 6 ++++-- packages/block-library/src/table/index.js | 6 ++++-- packages/block-library/src/tag-cloud/index.js | 6 ++++-- .../block-library/src/template-part/index.js | 7 +++++-- .../block-library/src/term-description/index.js | 6 ++++-- packages/block-library/src/text-columns/index.js | 7 +++++-- packages/block-library/src/utils/lazy-load.js | 16 ++++++++++++++++ packages/block-library/src/verse/index.js | 7 +++++-- packages/block-library/src/video/index.js | 7 +++++-- tools/webpack/packages.js | 14 ++++++++++++++ 103 files changed, 510 insertions(+), 202 deletions(-) create mode 100644 packages/block-library/src/utils/lazy-load.js diff --git a/packages/block-library/src/archives/index.js b/packages/block-library/src/archives/index.js index 40844eb9cb7d7..ea48208ad514b 100644 --- a/packages/block-library/src/archives/index.js +++ b/packages/block-library/src/archives/index.js @@ -6,9 +6,9 @@ import { archive as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "archives/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/audio/index.js b/packages/block-library/src/audio/index.js index aa1bba1c341d2..47483e045633d 100644 --- a/packages/block-library/src/audio/index.js +++ b/packages/block-library/src/audio/index.js @@ -6,9 +6,10 @@ import { audio as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -27,7 +28,9 @@ export const settings = { }, transforms, deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "audio/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/avatar/index.js b/packages/block-library/src/avatar/index.js index d318450aec390..1408dd55855de 100644 --- a/packages/block-library/src/avatar/index.js +++ b/packages/block-library/src/avatar/index.js @@ -6,16 +6,18 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "avatar/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/block/index.js b/packages/block-library/src/block/index.js index 7f1fa7bdab349..72eb72a2bc6e9 100644 --- a/packages/block-library/src/block/index.js +++ b/packages/block-library/src/block/index.js @@ -9,9 +9,9 @@ import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import deprecated from './deprecated'; const { name } = metadata; @@ -20,7 +20,9 @@ export { metadata, name }; export const settings = { deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "block/editor" */ './edit' ) + ), icon, __experimentalLabel: ( { ref } ) => { if ( ! ref ) { diff --git a/packages/block-library/src/button/index.js b/packages/block-library/src/button/index.js index 2b05b280028ab..6de6ea51089d3 100644 --- a/packages/block-library/src/button/index.js +++ b/packages/block-library/src/button/index.js @@ -7,9 +7,10 @@ import { button as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -25,7 +26,9 @@ export const settings = { text: __( 'Call to Action' ), }, }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "button/editor" */ './edit' ) + ), save, deprecated, merge: ( a, { text = '' } ) => ( { diff --git a/packages/block-library/src/buttons/index.js b/packages/block-library/src/buttons/index.js index 810922fbcb839..525add2157b94 100644 --- a/packages/block-library/src/buttons/index.js +++ b/packages/block-library/src/buttons/index.js @@ -7,10 +7,11 @@ import { buttons as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import transforms from './transforms'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -34,7 +35,9 @@ export const settings = { }, deprecated, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "buttons/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/calendar/index.js b/packages/block-library/src/calendar/index.js index 7fff20826e271..ef9c5befb0c16 100644 --- a/packages/block-library/src/calendar/index.js +++ b/packages/block-library/src/calendar/index.js @@ -6,9 +6,10 @@ import { calendar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import transforms from './transforms'; const { name } = metadata; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "calendar/editor" */ './edit' ) + ), transforms, }; diff --git a/packages/block-library/src/categories/index.js b/packages/block-library/src/categories/index.js index 8cdcad450862a..25a48e309749f 100644 --- a/packages/block-library/src/categories/index.js +++ b/packages/block-library/src/categories/index.js @@ -6,9 +6,9 @@ import { category as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "categories/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/code/index.js b/packages/block-library/src/code/index.js index c602045256d6e..738097b2f8695 100644 --- a/packages/block-library/src/code/index.js +++ b/packages/block-library/src/code/index.js @@ -7,8 +7,9 @@ import { code as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -35,7 +36,9 @@ export const settings = { }; }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "code/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/column/index.js b/packages/block-library/src/column/index.js index 687b8c180b1f5..520ea236b9390 100644 --- a/packages/block-library/src/column/index.js +++ b/packages/block-library/src/column/index.js @@ -6,9 +6,10 @@ import { column as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "column/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index 45f7bd70e61ff..6dec6008f07fc 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -7,9 +7,10 @@ import { columns as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import variations from './variations'; @@ -80,7 +81,9 @@ export const settings = { ], }, deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "columns/editor" */ './edit' ) + ), save, transforms, }; diff --git a/packages/block-library/src/comment-author-avatar/index.js b/packages/block-library/src/comment-author-avatar/index.js index d318450aec390..7382940585126 100644 --- a/packages/block-library/src/comment-author-avatar/index.js +++ b/packages/block-library/src/comment-author-avatar/index.js @@ -6,16 +6,20 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "comment-author-avatar/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-author-name/index.js b/packages/block-library/src/comment-author-name/index.js index 4d85bbebe047b..f4ece72b83ca1 100644 --- a/packages/block-library/src/comment-author-name/index.js +++ b/packages/block-library/src/comment-author-name/index.js @@ -6,9 +6,10 @@ import { commentAuthorName as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-author-name/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/comment-content/index.js b/packages/block-library/src/comment-content/index.js index 130f1d3012555..aee1976cf5eb5 100644 --- a/packages/block-library/src/comment-content/index.js +++ b/packages/block-library/src/comment-content/index.js @@ -6,16 +6,18 @@ import { commentContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-content/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-date/index.js b/packages/block-library/src/comment-date/index.js index fddae539acfa3..47ba124b80f49 100644 --- a/packages/block-library/src/comment-date/index.js +++ b/packages/block-library/src/comment-date/index.js @@ -6,9 +6,10 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-date/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/comment-edit-link/index.js b/packages/block-library/src/comment-edit-link/index.js index 6639dda86a7a4..6a2bd5a2615dc 100644 --- a/packages/block-library/src/comment-edit-link/index.js +++ b/packages/block-library/src/comment-edit-link/index.js @@ -6,16 +6,18 @@ import { commentEditLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-edit-link/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-reply-link/index.js b/packages/block-library/src/comment-reply-link/index.js index c04f8ce7b1bba..6f976b42b56f4 100644 --- a/packages/block-library/src/comment-reply-link/index.js +++ b/packages/block-library/src/comment-reply-link/index.js @@ -6,15 +6,17 @@ import { commentReplyLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-reply-link/editor" */ './edit' ) + ), icon, }; diff --git a/packages/block-library/src/comment-template/index.js b/packages/block-library/src/comment-template/index.js index afc295cad4c12..48adbe49c7622 100644 --- a/packages/block-library/src/comment-template/index.js +++ b/packages/block-library/src/comment-template/index.js @@ -6,9 +6,10 @@ import { layout as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comment-template/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/comments-pagination-next/index.js b/packages/block-library/src/comments-pagination-next/index.js index 2df0e8da6aa99..8488fee58627c 100644 --- a/packages/block-library/src/comments-pagination-next/index.js +++ b/packages/block-library/src/comments-pagination-next/index.js @@ -6,16 +6,20 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "comments-pagination-next/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-numbers/index.js b/packages/block-library/src/comments-pagination-numbers/index.js index 3fd903e2d9ef4..0569d3805d80d 100644 --- a/packages/block-library/src/comments-pagination-numbers/index.js +++ b/packages/block-library/src/comments-pagination-numbers/index.js @@ -6,16 +6,20 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "comments-pagination-numbers/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-previous/index.js b/packages/block-library/src/comments-pagination-previous/index.js index 80e555ccc79d9..08872418014ee 100644 --- a/packages/block-library/src/comments-pagination-previous/index.js +++ b/packages/block-library/src/comments-pagination-previous/index.js @@ -6,16 +6,20 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "comments-pagination-previous/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination/index.js b/packages/block-library/src/comments-pagination/index.js index 3d9bc853db140..97a81ffeac212 100644 --- a/packages/block-library/src/comments-pagination/index.js +++ b/packages/block-library/src/comments-pagination/index.js @@ -6,9 +6,10 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comments-pagination/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/comments-title/index.js b/packages/block-library/src/comments-title/index.js index 86bdab0dbccbf..21af7b4ab8de9 100644 --- a/packages/block-library/src/comments-title/index.js +++ b/packages/block-library/src/comments-title/index.js @@ -6,9 +6,10 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comments-title/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/comments/index.js b/packages/block-library/src/comments/index.js index 21db8b986d6e5..fba1feab5478f 100644 --- a/packages/block-library/src/comments/index.js +++ b/packages/block-library/src/comments/index.js @@ -6,10 +6,11 @@ import { postComments as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import deprecated from './deprecated'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "comments/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/cover/index.js b/packages/block-library/src/cover/index.js index e6797a3b51dbe..91ae540fbad21 100644 --- a/packages/block-library/src/cover/index.js +++ b/packages/block-library/src/cover/index.js @@ -7,9 +7,9 @@ import { cover as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -47,7 +47,9 @@ export const settings = { }, transforms, save, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "cover/editor" */ './edit' ) + ), deprecated, variations, }; diff --git a/packages/block-library/src/details/index.js b/packages/block-library/src/details/index.js index e30d1a8e04974..ec57143c22b42 100644 --- a/packages/block-library/src/details/index.js +++ b/packages/block-library/src/details/index.js @@ -7,9 +7,10 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -34,7 +35,9 @@ export const settings = { ], }, save, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "details/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/embed/index.js b/packages/block-library/src/embed/index.js index 065cf9665fa9b..66302a92aa9d6 100644 --- a/packages/block-library/src/embed/index.js +++ b/packages/block-library/src/embed/index.js @@ -1,8 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import save from './save'; import metadata from './block.json'; import transforms from './transforms'; @@ -15,7 +16,9 @@ export { metadata, name }; export const settings = { icon: embedContentIcon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "embed/editor" */ './edit' ) + ), save, transforms, variations, diff --git a/packages/block-library/src/file/index.js b/packages/block-library/src/file/index.js index 46b9691ea88a7..5c25d0fd926ce 100644 --- a/packages/block-library/src/file/index.js +++ b/packages/block-library/src/file/index.js @@ -7,9 +7,10 @@ import { file as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -28,7 +29,9 @@ export const settings = { }, transforms, deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "file/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/footnotes/index.js b/packages/block-library/src/footnotes/index.js index c5e851af7e033..cad77181e4e0f 100644 --- a/packages/block-library/src/footnotes/index.js +++ b/packages/block-library/src/footnotes/index.js @@ -7,8 +7,9 @@ import { registerFormatType } from '@wordpress/rich-text'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import { formatName, format } from './format'; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "footnotes/editor" */ './edit' ) + ), }; registerFormatType( formatName, format ); diff --git a/packages/block-library/src/form-input/index.js b/packages/block-library/src/form-input/index.js index 8e0548a6b24db..0bc89004056f8 100644 --- a/packages/block-library/src/form-input/index.js +++ b/packages/block-library/src/form-input/index.js @@ -1,9 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; import variations from './variations'; @@ -14,7 +14,9 @@ export { metadata, name }; export const settings = { deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "form-input/editor" */ './edit' ) + ), save, variations, }; diff --git a/packages/block-library/src/form-submission-notification/index.js b/packages/block-library/src/form-submission-notification/index.js index 67c359374eec1..87378197ccdde 100644 --- a/packages/block-library/src/form-submission-notification/index.js +++ b/packages/block-library/src/form-submission-notification/index.js @@ -6,8 +6,9 @@ import { group as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import variations from './variations'; @@ -18,7 +19,11 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "form-submission-notification/editor" */ './edit' + ) + ), save, variations, }; diff --git a/packages/block-library/src/form-submit-button/index.js b/packages/block-library/src/form-submit-button/index.js index 4c60b5f5c2063..fc780d08951e4 100644 --- a/packages/block-library/src/form-submit-button/index.js +++ b/packages/block-library/src/form-submit-button/index.js @@ -1,8 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -11,7 +12,9 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "form-submit-button/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/form/index.js b/packages/block-library/src/form/index.js index 1e45c642b6d48..79817e26bf277 100644 --- a/packages/block-library/src/form/index.js +++ b/packages/block-library/src/form/index.js @@ -1,8 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import variations from './variations'; @@ -17,7 +18,9 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "form/editor" */ './edit' ) + ), save, variations, }; diff --git a/packages/block-library/src/freeform/index.js b/packages/block-library/src/freeform/index.js index e94a459487b89..7489453a56f44 100644 --- a/packages/block-library/src/freeform/index.js +++ b/packages/block-library/src/freeform/index.js @@ -6,8 +6,9 @@ import { classic as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "freeform/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/gallery/index.js b/packages/block-library/src/gallery/index.js index f865072526098..f971a40e512c9 100644 --- a/packages/block-library/src/gallery/index.js +++ b/packages/block-library/src/gallery/index.js @@ -6,9 +6,9 @@ import { gallery as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit-wrapper'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -39,7 +39,9 @@ export const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "gallery/editor" */ './edit-wrapper' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/group/index.js b/packages/block-library/src/group/index.js index 2d06f1a965c52..b65caba6fc9db 100644 --- a/packages/block-library/src/group/index.js +++ b/packages/block-library/src/group/index.js @@ -7,9 +7,10 @@ import { group as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -82,7 +83,9 @@ export const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "group/editor" */ './edit' ) + ), save, deprecated, variations, diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index 3752ca70bc714..38881233252f6 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -7,9 +7,10 @@ import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -61,7 +62,9 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "heading/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index 71d62dcd8c44e..15fcb94ca209e 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -7,9 +7,10 @@ import { home } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -19,7 +20,9 @@ export { metadata, name }; export const settings = { icon: home, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "home-link/editor" */ './edit' ) + ), save, diff --git a/packages/block-library/src/html/index.js b/packages/block-library/src/html/index.js index cd25f25126a61..1f6a10f837789 100644 --- a/packages/block-library/src/html/index.js +++ b/packages/block-library/src/html/index.js @@ -7,8 +7,9 @@ import { html as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -27,7 +28,9 @@ export const settings = { '', }, }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "html/editor" */ './edit' ) + ), save, transforms, }; diff --git a/packages/block-library/src/image/index.js b/packages/block-library/src/image/index.js index 68625bd77cc87..5100f2a73fd7a 100644 --- a/packages/block-library/src/image/index.js +++ b/packages/block-library/src/image/index.js @@ -7,9 +7,9 @@ import { image as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -57,7 +57,9 @@ export const settings = { }; }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "image/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/latest-comments/index.js b/packages/block-library/src/latest-comments/index.js index 5c2bab45638df..f720c272bf1ed 100644 --- a/packages/block-library/src/latest-comments/index.js +++ b/packages/block-library/src/latest-comments/index.js @@ -6,9 +6,9 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "latest-comments/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/latest-posts/index.js b/packages/block-library/src/latest-posts/index.js index 5ea877488d72a..79651516be048 100644 --- a/packages/block-library/src/latest-posts/index.js +++ b/packages/block-library/src/latest-posts/index.js @@ -6,9 +6,10 @@ import { postList as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; const { name } = metadata; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "latest-posts/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/list-item/index.js b/packages/block-library/src/list-item/index.js index 07c5bb7fda901..8ce2819a09627 100644 --- a/packages/block-library/src/list-item/index.js +++ b/packages/block-library/src/list-item/index.js @@ -7,9 +7,10 @@ import { privateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; import transforms from './transforms'; import { unlock } from '../lock-unlock'; @@ -20,7 +21,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "list-item/editor" */ './edit' ) + ), save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index dc0f31822680a..896680c654c93 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -7,9 +7,10 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -45,7 +46,9 @@ const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "list/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/loginout/index.js b/packages/block-library/src/loginout/index.js index 65c611621fd62..3dd059ab0c6a2 100644 --- a/packages/block-library/src/loginout/index.js +++ b/packages/block-library/src/loginout/index.js @@ -6,8 +6,9 @@ import { login as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; const { name } = metadata; @@ -15,7 +16,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "loginout/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/media-text/index.js b/packages/block-library/src/media-text/index.js index 373050cb77fd5..ec8576d3261d5 100644 --- a/packages/block-library/src/media-text/index.js +++ b/packages/block-library/src/media-text/index.js @@ -7,9 +7,10 @@ import { mediaAndText as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -45,7 +46,9 @@ export const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "media-text/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/missing/index.js b/packages/block-library/src/missing/index.js index 766381156eb34..03933c3c03888 100644 --- a/packages/block-library/src/missing/index.js +++ b/packages/block-library/src/missing/index.js @@ -6,8 +6,9 @@ import { getBlockType } from '@wordpress/blocks'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -32,7 +33,9 @@ export const settings = { return ''; } }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "missing/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/more/index.js b/packages/block-library/src/more/index.js index b40bb2123bc72..001a7e8c248e8 100644 --- a/packages/block-library/src/more/index.js +++ b/packages/block-library/src/more/index.js @@ -6,8 +6,9 @@ import { more as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -31,7 +32,9 @@ export const settings = { } }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "more/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/navigation-link/index.js b/packages/block-library/src/navigation-link/index.js index 3d1f0207ff955..fcca9779c24a9 100644 --- a/packages/block-library/src/navigation-link/index.js +++ b/packages/block-library/src/navigation-link/index.js @@ -9,9 +9,10 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; import { enhanceNavigationLinkVariations } from './hooks'; import transforms from './transforms'; @@ -32,7 +33,9 @@ export const settings = { }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "navigation-link/editor" */ './edit' ) + ), save, diff --git a/packages/block-library/src/navigation-submenu/index.js b/packages/block-library/src/navigation-submenu/index.js index 69e97fb85325a..0582212ab1d60 100644 --- a/packages/block-library/src/navigation-submenu/index.js +++ b/packages/block-library/src/navigation-submenu/index.js @@ -6,9 +6,9 @@ import { page, addSubmenu } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import save from './save'; import transforms from './transforms'; @@ -36,7 +36,9 @@ export const settings = { return label; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "navigation-submenu/editor" */ './edit' ) + ), save, transforms, }; diff --git a/packages/block-library/src/navigation/index.js b/packages/block-library/src/navigation/index.js index d0405be794ffe..92dc20b6dbea5 100644 --- a/packages/block-library/src/navigation/index.js +++ b/packages/block-library/src/navigation/index.js @@ -7,9 +7,9 @@ import { navigation as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import save from './save'; import deprecated from './deprecated'; @@ -50,7 +50,9 @@ export const settings = { }, ], }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "cover/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/nextpage/index.js b/packages/block-library/src/nextpage/index.js index 5f425e7e952c6..e7b4c476ebe9a 100644 --- a/packages/block-library/src/nextpage/index.js +++ b/packages/block-library/src/nextpage/index.js @@ -6,8 +6,9 @@ import { pageBreak as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -20,7 +21,9 @@ export const settings = { icon, example: {}, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "nextpage/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/page-list-item/index.js b/packages/block-library/src/page-list-item/index.js index 6d1db7282af89..f71d6f100b318 100644 --- a/packages/block-library/src/page-list-item/index.js +++ b/packages/block-library/src/page-list-item/index.js @@ -6,9 +6,9 @@ import { page as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit.js'; const { name } = metadata; @@ -18,7 +18,9 @@ export const settings = { __experimentalLabel: ( { label } ) => label, icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "page-list-item/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/page-list/index.js b/packages/block-library/src/page-list/index.js index 4a128e7da58a8..a479117d1f2e4 100644 --- a/packages/block-library/src/page-list/index.js +++ b/packages/block-library/src/page-list/index.js @@ -6,9 +6,9 @@ import { pages } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit.js'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon: pages, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "page-list/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index 715fb35ec05ab..e3df57ca46009 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -7,9 +7,9 @@ import { paragraph as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -52,7 +52,9 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "paragraph/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/pattern/index.js b/packages/block-library/src/pattern/index.js index e4af712da8bb2..1af4716c0f445 100644 --- a/packages/block-library/src/pattern/index.js +++ b/packages/block-library/src/pattern/index.js @@ -1,15 +1,17 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import PatternEdit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { - edit: PatternEdit, + edit: lazyLoad( () => + import( /* webpackChunkName: "pattern/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-biography/index.js b/packages/block-library/src/post-author-biography/index.js index 8c91b99f7f6f5..191c51560b5e2 100644 --- a/packages/block-library/src/post-author-biography/index.js +++ b/packages/block-library/src/post-author-biography/index.js @@ -6,16 +6,20 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "post-author-biography/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-name/index.js b/packages/block-library/src/post-author-name/index.js index dce3e48c86f63..83f0d40e1fc82 100644 --- a/packages/block-library/src/post-author-name/index.js +++ b/packages/block-library/src/post-author-name/index.js @@ -6,9 +6,10 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import transforms from './transforms'; const { name } = metadata; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-author-name/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author/index.js b/packages/block-library/src/post-author/index.js index 8c91b99f7f6f5..252e2cc0198b6 100644 --- a/packages/block-library/src/post-author/index.js +++ b/packages/block-library/src/post-author/index.js @@ -6,16 +6,18 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-author/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comment/index.js b/packages/block-library/src/post-comment/index.js index 2fca916307a79..761a4a59e2e6a 100644 --- a/packages/block-library/src/post-comment/index.js +++ b/packages/block-library/src/post-comment/index.js @@ -6,9 +6,10 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-comment/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/post-comments-count/index.js b/packages/block-library/src/post-comments-count/index.js index 1d2525ddf2d9e..f69cd8306dc08 100644 --- a/packages/block-library/src/post-comments-count/index.js +++ b/packages/block-library/src/post-comments-count/index.js @@ -6,16 +6,18 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-comments-count/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-form/index.js b/packages/block-library/src/post-comments-form/index.js index 4d0444194241d..ac9e4b86e6056 100644 --- a/packages/block-library/src/post-comments-form/index.js +++ b/packages/block-library/src/post-comments-form/index.js @@ -6,16 +6,18 @@ import { postCommentsForm as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-comments-form/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-link/index.js b/packages/block-library/src/post-comments-link/index.js index 36e9673a08a1d..0df6a53de69ab 100644 --- a/packages/block-library/src/post-comments-link/index.js +++ b/packages/block-library/src/post-comments-link/index.js @@ -6,15 +6,17 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-comments-link/editor" */ './edit' ) + ), icon, }; diff --git a/packages/block-library/src/post-content/index.js b/packages/block-library/src/post-content/index.js index 80196db27878b..89ea2c43ba1e6 100644 --- a/packages/block-library/src/post-content/index.js +++ b/packages/block-library/src/post-content/index.js @@ -6,16 +6,18 @@ import { postContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-content/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-date/index.js b/packages/block-library/src/post-date/index.js index 232b715c3795b..44ba45092d34b 100644 --- a/packages/block-library/src/post-date/index.js +++ b/packages/block-library/src/post-date/index.js @@ -6,9 +6,10 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; import variations from './variations'; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-date/editor" */ './edit' ) + ), deprecated, variations, }; diff --git a/packages/block-library/src/post-excerpt/index.js b/packages/block-library/src/post-excerpt/index.js index 41b868965eec5..e9a649a383470 100644 --- a/packages/block-library/src/post-excerpt/index.js +++ b/packages/block-library/src/post-excerpt/index.js @@ -6,9 +6,10 @@ import { postExcerpt as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import transforms from './transforms'; const { name } = metadata; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-excerpt/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-featured-image/index.js b/packages/block-library/src/post-featured-image/index.js index aa28444114fb3..c34244356f742 100644 --- a/packages/block-library/src/post-featured-image/index.js +++ b/packages/block-library/src/post-featured-image/index.js @@ -6,16 +6,18 @@ import { postFeaturedImage as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-featured-image/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-navigation-link/index.js b/packages/block-library/src/post-navigation-link/index.js index e85e594990adb..92a230bde5f43 100644 --- a/packages/block-library/src/post-navigation-link/index.js +++ b/packages/block-library/src/post-navigation-link/index.js @@ -1,16 +1,19 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import variations from './variations'; const { name } = metadata; export { metadata, name }; export const settings = { - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-navigation-link/editor" */ './edit' ) + ), variations, }; diff --git a/packages/block-library/src/post-template/index.js b/packages/block-library/src/post-template/index.js index bc6f8ffa13ab6..6e2db6ac68701 100644 --- a/packages/block-library/src/post-template/index.js +++ b/packages/block-library/src/post-template/index.js @@ -6,9 +6,10 @@ import { layout } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon: layout, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-template/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/post-terms/index.js b/packages/block-library/src/post-terms/index.js index 3a00f04b77fd2..4fe85bc71af6b 100644 --- a/packages/block-library/src/post-terms/index.js +++ b/packages/block-library/src/post-terms/index.js @@ -7,9 +7,10 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import enhanceVariations from './hooks'; const { name } = metadata; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-terms/editor" */ './edit' ) + ), }; export const init = () => { diff --git a/packages/block-library/src/post-time-to-read/index.js b/packages/block-library/src/post-time-to-read/index.js index 95b379f55f0b3..107ab238b1803 100644 --- a/packages/block-library/src/post-time-to-read/index.js +++ b/packages/block-library/src/post-time-to-read/index.js @@ -1,9 +1,10 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import icon from './icon'; const { name } = metadata; @@ -11,7 +12,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-time-to-read/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-title/index.js b/packages/block-library/src/post-title/index.js index 86bdab0dbccbf..9d3c0590f898c 100644 --- a/packages/block-library/src/post-title/index.js +++ b/packages/block-library/src/post-title/index.js @@ -6,9 +6,10 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "post-title/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/preformatted/index.js b/packages/block-library/src/preformatted/index.js index a2e1fecc18552..0e8fade75a99c 100644 --- a/packages/block-library/src/preformatted/index.js +++ b/packages/block-library/src/preformatted/index.js @@ -7,8 +7,9 @@ import { preformatted as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -30,7 +31,9 @@ export const settings = { }, }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "preformatted/editor" */ './edit' ) + ), save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index 9d2b42f7698ab..0facf4323048c 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -7,9 +7,10 @@ import { pullquote as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -31,7 +32,9 @@ export const settings = { }, }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "pullquote/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/query-no-results/index.js b/packages/block-library/src/query-no-results/index.js index 1c56638cdfdba..eac234da75de4 100644 --- a/packages/block-library/src/query-no-results/index.js +++ b/packages/block-library/src/query-no-results/index.js @@ -6,9 +6,10 @@ import { loop as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; const { name } = metadata; @@ -16,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "query-no-results/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/query-pagination-next/index.js b/packages/block-library/src/query-pagination-next/index.js index 2df0e8da6aa99..0b5de92bb6f88 100644 --- a/packages/block-library/src/query-pagination-next/index.js +++ b/packages/block-library/src/query-pagination-next/index.js @@ -6,16 +6,20 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "query-pagination-next/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-numbers/index.js b/packages/block-library/src/query-pagination-numbers/index.js index 3fd903e2d9ef4..cf288bf278a9b 100644 --- a/packages/block-library/src/query-pagination-numbers/index.js +++ b/packages/block-library/src/query-pagination-numbers/index.js @@ -6,16 +6,20 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "query-pagination-numbers/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-previous/index.js b/packages/block-library/src/query-pagination-previous/index.js index 80e555ccc79d9..5119ac89674ab 100644 --- a/packages/block-library/src/query-pagination-previous/index.js +++ b/packages/block-library/src/query-pagination-previous/index.js @@ -6,16 +6,20 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( + /* webpackChunkName: "query-pagination-previous/editor" */ './edit' + ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination/index.js b/packages/block-library/src/query-pagination/index.js index b113a8384b043..3e3590fefbc54 100644 --- a/packages/block-library/src/query-pagination/index.js +++ b/packages/block-library/src/query-pagination/index.js @@ -6,9 +6,10 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; import deprecated from './deprecated'; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "query-pagination/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/query-title/index.js b/packages/block-library/src/query-title/index.js index 875c2b8b86504..997d2ca4be147 100644 --- a/packages/block-library/src/query-title/index.js +++ b/packages/block-library/src/query-title/index.js @@ -6,9 +6,10 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import variations from './variations'; import deprecated from './deprecated'; @@ -17,7 +18,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "query-title/editor" */ './edit' ) + ), variations, deprecated, }; diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index 8d82391923603..f2515cb844caf 100644 --- a/packages/block-library/src/query/index.js +++ b/packages/block-library/src/query/index.js @@ -6,9 +6,10 @@ import { loop as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import save from './save'; import variations from './variations'; import deprecated from './deprecated'; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "query/editor" */ './edit' ) + ), save, variations, deprecated, diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index d67685f3561b0..fdb5ce219d330 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -7,9 +7,10 @@ import { quote as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -34,7 +35,9 @@ export const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "quote/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/read-more/index.js b/packages/block-library/src/read-more/index.js index 497cd77f429e6..374ec510a8a3f 100644 --- a/packages/block-library/src/read-more/index.js +++ b/packages/block-library/src/read-more/index.js @@ -6,16 +6,18 @@ import { link as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "read-more/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/rss/index.js b/packages/block-library/src/rss/index.js index 439d14c4edcdd..51784dd833f2f 100644 --- a/packages/block-library/src/rss/index.js +++ b/packages/block-library/src/rss/index.js @@ -6,9 +6,9 @@ import { rss as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; @@ -21,7 +21,9 @@ export const settings = { feedURL: 'https://wordpress.org', }, }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "rss/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js index 85770a23268cb..bb1b3984dd408 100644 --- a/packages/block-library/src/search/index.js +++ b/packages/block-library/src/search/index.js @@ -7,9 +7,10 @@ import { search as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import variations from './variations'; const { name } = metadata; @@ -23,7 +24,9 @@ export const settings = { viewportWidth: 400, }, variations, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "search/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/separator/index.js b/packages/block-library/src/separator/index.js index 712caef775146..aec5fffe4e980 100644 --- a/packages/block-library/src/separator/index.js +++ b/packages/block-library/src/separator/index.js @@ -6,8 +6,9 @@ import { separator as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -26,7 +27,9 @@ export const settings = { }, }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "separator/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/shortcode/index.js b/packages/block-library/src/shortcode/index.js index 6fe36bdbfb3d3..e7085cb3b929f 100644 --- a/packages/block-library/src/shortcode/index.js +++ b/packages/block-library/src/shortcode/index.js @@ -6,8 +6,8 @@ import { shortcode as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; import save from './save'; import transforms from './transforms'; import metadata from './block.json'; @@ -19,7 +19,9 @@ export { metadata, name }; export const settings = { icon, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "shortcode/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/site-logo/index.js b/packages/block-library/src/site-logo/index.js index fc10df08e17de..26c1a0a6ab855 100644 --- a/packages/block-library/src/site-logo/index.js +++ b/packages/block-library/src/site-logo/index.js @@ -6,9 +6,9 @@ import { siteLogo as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import transforms from './transforms'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "site-logo/editor" */ './edit' ) + ), transforms, }; diff --git a/packages/block-library/src/site-tagline/index.js b/packages/block-library/src/site-tagline/index.js index 1d0090f9dcea1..04485620639db 100644 --- a/packages/block-library/src/site-tagline/index.js +++ b/packages/block-library/src/site-tagline/index.js @@ -1,9 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import icon from './icon'; import deprecated from './deprecated'; @@ -12,7 +12,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "site-tagline/editor" */ './edit' ) + ), deprecated, }; diff --git a/packages/block-library/src/site-title/index.js b/packages/block-library/src/site-title/index.js index 87934888ce438..9078a8cdbaf45 100644 --- a/packages/block-library/src/site-title/index.js +++ b/packages/block-library/src/site-title/index.js @@ -6,9 +6,10 @@ import { mapMarker as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import deprecated from './deprecated'; import transforms from './transforms'; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "site-title/editor" */ './edit' ) + ), transforms, deprecated, }; diff --git a/packages/block-library/src/social-link/index.js b/packages/block-library/src/social-link/index.js index 161e6f2697acc..1d4aa6ecdeef8 100644 --- a/packages/block-library/src/social-link/index.js +++ b/packages/block-library/src/social-link/index.js @@ -6,8 +6,8 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; import metadata from './block.json'; import variations from './variations'; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "social-link/editor" */ './edit' ) + ), variations, }; diff --git a/packages/block-library/src/social-links/index.js b/packages/block-library/src/social-links/index.js index 601a8c63ec539..4660866c720ad 100644 --- a/packages/block-library/src/social-links/index.js +++ b/packages/block-library/src/social-links/index.js @@ -6,9 +6,9 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -43,7 +43,9 @@ export const settings = { ], }, icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "social-links/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/spacer/index.js b/packages/block-library/src/spacer/index.js index d77c51bc96cea..598df25bd51f6 100644 --- a/packages/block-library/src/spacer/index.js +++ b/packages/block-library/src/spacer/index.js @@ -6,9 +6,10 @@ import { resizeCornerNE as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; @@ -18,7 +19,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "spacer/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/table-of-contents/index.js b/packages/block-library/src/table-of-contents/index.js index 408538a7dcadb..cd99919d93763 100644 --- a/packages/block-library/src/table-of-contents/index.js +++ b/packages/block-library/src/table-of-contents/index.js @@ -6,9 +6,9 @@ import { tableOfContents as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; import save from './save'; const { name } = metadata; @@ -17,7 +17,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "table-of-contents/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/table/index.js b/packages/block-library/src/table/index.js index dea09dd7c9829..ffc4a9d34fac0 100644 --- a/packages/block-library/src/table/index.js +++ b/packages/block-library/src/table/index.js @@ -7,9 +7,9 @@ import { blockTable as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -94,7 +94,9 @@ export const settings = { viewportWidth: 450, }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "table/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js index 6dc0931663fcd..c8380126ee1aa 100644 --- a/packages/block-library/src/tag-cloud/index.js +++ b/packages/block-library/src/tag-cloud/index.js @@ -6,10 +6,10 @@ import { tag as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import transforms from './transforms'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; @@ -18,7 +18,9 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "tag-cloud/editor" */ './edit' ) + ), transforms, }; diff --git a/packages/block-library/src/template-part/index.js b/packages/block-library/src/template-part/index.js index 20976e231d811..678875e24f3be 100644 --- a/packages/block-library/src/template-part/index.js +++ b/packages/block-library/src/template-part/index.js @@ -15,9 +15,10 @@ import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; + import { enhanceTemplatePartVariations } from './variations'; const { name } = metadata; @@ -47,7 +48,9 @@ export const settings = { decodeEntities( entity.title ) || capitalCase( entity.slug || '' ) ); }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "template-part/editor" */ './edit' ) + ), }; export const init = () => { diff --git a/packages/block-library/src/term-description/index.js b/packages/block-library/src/term-description/index.js index 0ff710a91f5d5..44b0f3e93588a 100644 --- a/packages/block-library/src/term-description/index.js +++ b/packages/block-library/src/term-description/index.js @@ -6,16 +6,18 @@ import { termDescription as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; -import edit from './edit'; const { name } = metadata; export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "term-description/editor" */ './edit' ) + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index c0bce35b96f4e..6976759f3a88e 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -1,8 +1,9 @@ /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -19,7 +20,9 @@ export const settings = { return { 'data-align': width }; } }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "text-columns/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/utils/lazy-load.js b/packages/block-library/src/utils/lazy-load.js new file mode 100644 index 0000000000000..f88679f8d1227 --- /dev/null +++ b/packages/block-library/src/utils/lazy-load.js @@ -0,0 +1,16 @@ +/** + * WordPress dependencies + */ +import { Suspense, lazy } from '@wordpress/element'; + +export default function lazyEdit( cb ) { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return + const Load = lazy( cb ); + return function Edit( props ) { + return ( + + + + ); + }; +} diff --git a/packages/block-library/src/verse/index.js b/packages/block-library/src/verse/index.js index 5d80b63a4ca84..aeb629a8757fb 100644 --- a/packages/block-library/src/verse/index.js +++ b/packages/block-library/src/verse/index.js @@ -7,9 +7,10 @@ import { verse as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -37,7 +38,9 @@ export const settings = { content: attributes.content + '\n\n' + attributesToMerge.content, }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "verse/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/video/index.js b/packages/block-library/src/video/index.js index 57201ef712565..f07c64b8eb1e6 100644 --- a/packages/block-library/src/video/index.js +++ b/packages/block-library/src/video/index.js @@ -7,9 +7,10 @@ import { video as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; -import edit from './edit'; + import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -29,7 +30,9 @@ export const settings = { }, transforms, deprecated, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "video/editor" */ './edit' ) + ), save, }; diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index 0a4b8cef57446..6571824ed192e 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -151,6 +151,12 @@ module.exports = { output: { devtoolNamespace: 'wp', filename: './build/[name]/index.min.js', + chunkFilename: ( { chunk } ) => { + if ( chunk.runtime === 'block-library' ) { + return './build/block-library/blocks/[name].min.js'; + } + return './build/' + chunk.runtime + '/[name].min.js'; + }, path: join( __dirname, '..', '..' ), devtoolModuleFilenameTemplate: ( info ) => { if ( info.resourcePath.includes( '/@wordpress/' ) ) { @@ -164,6 +170,14 @@ module.exports = { performance: { hints: false, // disable warnings about package sizes }, + optimization: { + splitChunks: { + cacheGroups: { + default: false, + defaultVendors: false, + }, + }, + }, plugins: [ ...plugins, new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ), From 767ab94c28fc25bdea3feb1c4cd99a3eba74d914 Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Wed, 29 Nov 2023 11:42:29 +0100 Subject: [PATCH 02/27] fix `editor/blocks/buttons.spec.js` to wait for block after insert --- test/e2e/specs/editor/blocks/buttons.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/e2e/specs/editor/blocks/buttons.spec.js b/test/e2e/specs/editor/blocks/buttons.spec.js index f62732470d974..413d162e7982f 100644 --- a/test/e2e/specs/editor/blocks/buttons.spec.js +++ b/test/e2e/specs/editor/blocks/buttons.spec.js @@ -35,6 +35,7 @@ test.describe( 'Buttons', () => { .click(); await page.keyboard.type( '/buttons' ); await page.keyboard.press( 'Enter' ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); // Check the content. @@ -143,6 +144,7 @@ test.describe( 'Buttons', () => { pageUtils, } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'WordPress' ); await pageUtils.pressKeys( 'primary+k' ); await page.keyboard.type( 'https://www.wordpress.org/' ); @@ -170,6 +172,7 @@ test.describe( 'Buttons', () => { pageUtils, } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'WordPress' ); await pageUtils.pressKeys( 'primary+k' ); await page.keyboard.type( 'https://www.wordpress.org/' ); @@ -259,6 +262,7 @@ test.describe( 'Buttons', () => { test( 'can resize width', async ( { editor, page } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); await page.click( @@ -281,6 +285,7 @@ test.describe( 'Buttons', () => { test( 'can apply named colors', async ( { editor, page } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); @@ -310,6 +315,7 @@ test.describe( 'Buttons', () => { test( 'can apply custom colors', async ( { editor, page } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); @@ -345,6 +351,7 @@ test.describe( 'Buttons', () => { page, } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); @@ -374,6 +381,7 @@ test.describe( 'Buttons', () => { page, } ) => { await editor.insertBlock( { name: 'core/buttons' } ); + await page.locator( 'role=textbox[name="Button text"i]' ).isVisible(); await page.keyboard.type( 'Content' ); await editor.openDocumentSettingsSidebar(); From 143e9991e7c985e8162317ab2962a1de547a09da Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Thu, 7 Dec 2023 17:51:10 +0100 Subject: [PATCH 03/27] fix a few more tests to wait for blocks to appear --- test/e2e/specs/editor/blocks/code.spec.js | 4 ++++ test/e2e/specs/editor/blocks/preformatted.spec.js | 1 + test/e2e/specs/editor/blocks/verse-code-preformatted.spec.js | 3 +++ 3 files changed, 8 insertions(+) diff --git a/test/e2e/specs/editor/blocks/code.spec.js b/test/e2e/specs/editor/blocks/code.spec.js index ba5af46f69cfd..3c0d8d02640ca 100644 --- a/test/e2e/specs/editor/blocks/code.spec.js +++ b/test/e2e/specs/editor/blocks/code.spec.js @@ -17,6 +17,9 @@ test.describe( 'Code', () => { .click(); await page.keyboard.type( '```' ); await page.keyboard.press( 'Enter' ); + + await editor.canvas.locator( 'pre' ).isVisible(); + await page.keyboard.type( ' { test( 'should paste plain text', async ( { editor, pageUtils } ) => { await editor.insertBlock( { name: 'core/code' } ); + await editor.canvas.locator( 'pre' ).isVisible(); // Test to see if HTML and white space is kept. pageUtils.setClipboardData( { plainText: '\n\t
' } ); diff --git a/test/e2e/specs/editor/blocks/preformatted.spec.js b/test/e2e/specs/editor/blocks/preformatted.spec.js index 5cd20a051c4fb..295db02993fb8 100644 --- a/test/e2e/specs/editor/blocks/preformatted.spec.js +++ b/test/e2e/specs/editor/blocks/preformatted.spec.js @@ -30,6 +30,7 @@ test.describe( 'Preformatted', () => { page, } ) => { await editor.insertBlock( { name: 'core/preformatted' } ); + await editor.canvas.locator( 'pre' ).isVisible(); await page.keyboard.type( '1' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( '2' ); diff --git a/test/e2e/specs/editor/blocks/verse-code-preformatted.spec.js b/test/e2e/specs/editor/blocks/verse-code-preformatted.spec.js index fdb76a8277a46..82db0b2a106f7 100644 --- a/test/e2e/specs/editor/blocks/verse-code-preformatted.spec.js +++ b/test/e2e/specs/editor/blocks/verse-code-preformatted.spec.js @@ -15,6 +15,9 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); page, } ) => { await editor.insertBlock( { name: blockName } ); + + await editor.canvas.locator( 'pre' ).isVisible(); + await page.keyboard.type( 'a' ); await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'Enter' ); From c6be29c364befc6a8fa382d99af81c778d1d4fff Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Thu, 7 Dec 2023 17:52:24 +0100 Subject: [PATCH 04/27] sync load `edit` for heading, list(-item), p, quote --- packages/block-library/src/heading/index.js | 6 ++---- packages/block-library/src/list-item/index.js | 6 ++---- packages/block-library/src/list/index.js | 6 ++---- packages/block-library/src/paragraph/index.js | 6 ++---- packages/block-library/src/quote/index.js | 6 ++---- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index 38881233252f6..302109b3532d8 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -7,7 +7,7 @@ import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; +import edit from './edit'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -62,9 +62,7 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "heading/editor" */ './edit' ) - ), + edit, save, }; diff --git a/packages/block-library/src/list-item/index.js b/packages/block-library/src/list-item/index.js index 8ce2819a09627..a8dec7255cc2e 100644 --- a/packages/block-library/src/list-item/index.js +++ b/packages/block-library/src/list-item/index.js @@ -7,7 +7,7 @@ import { privateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; +import edit from './edit'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -21,9 +21,7 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "list-item/editor" */ './edit' ) - ), + edit, save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 896680c654c93..18a94ff25ef01 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -7,7 +7,7 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; +import edit from './edit'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -46,9 +46,7 @@ const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "list/editor" */ './edit' ) - ), + edit, save, deprecated, }; diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index e3df57ca46009..26991709a5f38 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -7,7 +7,7 @@ import { paragraph as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; +import edit from './edit'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -52,9 +52,7 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "paragraph/editor" */ './edit' ) - ), + edit, save, }; diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index fdb5ce219d330..005d33566b7af 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -7,7 +7,7 @@ import { quote as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; +import edit from './edit'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -35,9 +35,7 @@ export const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "quote/editor" */ './edit' ) - ), + edit, save, deprecated, }; From bcb552faae212a3702b650ad19e657a19403aca0 Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Thu, 7 Dec 2023 17:52:31 +0100 Subject: [PATCH 05/27] Revert "sync load `edit` for heading, list(-item), p, quote" This reverts commit 1a75db77bdb0c060a257aa63abe4a6fc1712eb39. --- packages/block-library/src/heading/index.js | 6 ++++-- packages/block-library/src/list-item/index.js | 6 ++++-- packages/block-library/src/list/index.js | 6 ++++-- packages/block-library/src/paragraph/index.js | 6 ++++-- packages/block-library/src/quote/index.js | 6 ++++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index 302109b3532d8..38881233252f6 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -7,7 +7,7 @@ import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ -import edit from './edit'; +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -62,7 +62,9 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "heading/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/list-item/index.js b/packages/block-library/src/list-item/index.js index a8dec7255cc2e..8ce2819a09627 100644 --- a/packages/block-library/src/list-item/index.js +++ b/packages/block-library/src/list-item/index.js @@ -7,7 +7,7 @@ import { privateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ -import edit from './edit'; +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -21,7 +21,9 @@ export { metadata, name }; export const settings = { icon, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "list-item/editor" */ './edit' ) + ), save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 18a94ff25ef01..896680c654c93 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -7,7 +7,7 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import edit from './edit'; +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -46,7 +46,9 @@ const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "list/editor" */ './edit' ) + ), save, deprecated, }; diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index 26991709a5f38..e3df57ca46009 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -7,7 +7,7 @@ import { paragraph as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import edit from './edit'; +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -52,7 +52,9 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "paragraph/editor" */ './edit' ) + ), save, }; diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index 005d33566b7af..fdb5ce219d330 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -7,7 +7,7 @@ import { quote as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import edit from './edit'; +import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -35,7 +35,9 @@ export const settings = { ], }, transforms, - edit, + edit: lazyLoad( () => + import( /* webpackChunkName: "quote/editor" */ './edit' ) + ), save, deprecated, }; From 3d6e55545e30c98cb2e013dda2c44852d63c1cb9 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 13 Dec 2023 15:06:06 +0100 Subject: [PATCH 06/27] Experiment: capture input in suspense placeholder --- packages/block-library/src/utils/lazy-load.js | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/utils/lazy-load.js b/packages/block-library/src/utils/lazy-load.js index f88679f8d1227..312de4164a658 100644 --- a/packages/block-library/src/utils/lazy-load.js +++ b/packages/block-library/src/utils/lazy-load.js @@ -1,14 +1,62 @@ /** * WordPress dependencies */ -import { Suspense, lazy } from '@wordpress/element'; +import { Suspense, lazy, useEffect, useState } from '@wordpress/element'; +import { useBlockProps } from '@wordpress/block-editor'; + +const FallbackEdit = ( { tempContent, setTempContent } ) => { + const blockProps = useBlockProps(); + const onChange = ( e ) => { + setTempContent( e.target.value ); + }; + + return ( +
+ +
+ ); +}; + +// Sets the block content on mount +const Init = ( { content, setContent } ) => { + useEffect( () => { + if ( content.length > 0 ) { + setContent( content ); + } + }, [] ); + + return null; +}; + +// Add delay to the module load for better debugging +const delay = async ( cb, ms = 0 ) => { + if ( ms > 0 ) { + await new Promise( ( r ) => setTimeout( r, ms ) ); + } + return await cb(); +}; export default function lazyEdit( cb ) { // eslint-disable-next-line @wordpress/no-unused-vars-before-return - const Load = lazy( cb ); + const Load = lazy( () => delay( cb, 3000 ) ); return function Edit( props ) { + // captures what was typed into the placeholder while loading + const [ tempContent, setTempContent ] = useState( '' ); return ( - + + } + > + + props.setAttributes( { content } ) + } + /> ); From 1ea02d5db34949d380d271ea6f2c5615d671b36f Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 1 Feb 2024 10:03:19 +0100 Subject: [PATCH 07/27] Revert "Experiment: capture input in suspense placeholder" This reverts commit 5e969f3a8cd1334208364824a0251045b9ba2607. --- packages/block-library/src/utils/lazy-load.js | 54 ++----------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/packages/block-library/src/utils/lazy-load.js b/packages/block-library/src/utils/lazy-load.js index 312de4164a658..f88679f8d1227 100644 --- a/packages/block-library/src/utils/lazy-load.js +++ b/packages/block-library/src/utils/lazy-load.js @@ -1,62 +1,14 @@ /** * WordPress dependencies */ -import { Suspense, lazy, useEffect, useState } from '@wordpress/element'; -import { useBlockProps } from '@wordpress/block-editor'; - -const FallbackEdit = ( { tempContent, setTempContent } ) => { - const blockProps = useBlockProps(); - const onChange = ( e ) => { - setTempContent( e.target.value ); - }; - - return ( -
- -
- ); -}; - -// Sets the block content on mount -const Init = ( { content, setContent } ) => { - useEffect( () => { - if ( content.length > 0 ) { - setContent( content ); - } - }, [] ); - - return null; -}; - -// Add delay to the module load for better debugging -const delay = async ( cb, ms = 0 ) => { - if ( ms > 0 ) { - await new Promise( ( r ) => setTimeout( r, ms ) ); - } - return await cb(); -}; +import { Suspense, lazy } from '@wordpress/element'; export default function lazyEdit( cb ) { // eslint-disable-next-line @wordpress/no-unused-vars-before-return - const Load = lazy( () => delay( cb, 3000 ) ); + const Load = lazy( cb ); return function Edit( props ) { - // captures what was typed into the placeholder while loading - const [ tempContent, setTempContent ] = useState( '' ); return ( - - } - > - - props.setAttributes( { content } ) - } - /> + ); From e38f3f249e8683f4f6c3f6ecba49d689f6532806 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Fri, 2 Feb 2024 16:31:12 +0100 Subject: [PATCH 08/27] lazyEdit function, async transform with after-content --- .../src/components/block-edit/edit.js | 9 +- .../src/components/block-edit/edit.native.js | 7 +- .../components/rich-text/use-input-rules.js | 85 +++++++++++++------ packages/block-editor/src/hooks/index.js | 2 +- packages/block-library/src/heading/index.js | 5 +- packages/blocks/README.md | 4 + packages/blocks/src/api/index.js | 1 + packages/blocks/src/api/utils.js | 26 +++++- 8 files changed, 95 insertions(+), 44 deletions(-) diff --git a/packages/block-editor/src/components/block-edit/edit.js b/packages/block-editor/src/components/block-edit/edit.js index 31344b5433793..bf7397c082d29 100644 --- a/packages/block-editor/src/components/block-edit/edit.js +++ b/packages/block-editor/src/components/block-edit/edit.js @@ -11,6 +11,7 @@ import { getBlockDefaultClassName, hasBlockSupport, getBlockType, + getBlockEdit, } from '@wordpress/blocks'; import { useContext, useMemo } from '@wordpress/element'; @@ -33,15 +34,11 @@ const Edit = ( props ) => { const { name } = props; const blockType = getBlockType( name ); - if ( ! blockType ) { + const Component = useMemo( () => getBlockEdit( blockType ), [ blockType ] ); + if ( ! Component ) { return null; } - // `edit` and `save` are functions or components describing the markup - // with which a block is displayed. If `blockType` is valid, assign - // them preferentially as the render value for the block. - const Component = blockType.edit || blockType.save; - return ; }; diff --git a/packages/block-editor/src/components/block-edit/edit.native.js b/packages/block-editor/src/components/block-edit/edit.native.js index 12d16d155d7b3..23cfc3e9105f7 100644 --- a/packages/block-editor/src/components/block-edit/edit.native.js +++ b/packages/block-editor/src/components/block-edit/edit.native.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { withFilters } from '@wordpress/components'; -import { getBlockType } from '@wordpress/blocks'; +import { getBlockType, getBlockEdit } from '@wordpress/blocks'; import { useContext, useMemo } from '@wordpress/element'; /** @@ -37,12 +37,11 @@ export const Edit = ( props ) => { : DEFAULT_BLOCK_CONTEXT; }, [ blockType, blockContext ] ); - if ( ! blockType ) { + const Component = useMemo( () => getBlockEdit( blockType ), [ blockType ] ); + if ( ! Component ) { return null; } - const Component = blockType.edit; - return ; }; diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index ff871eb936323..a2c4284cbc03c 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -3,8 +3,12 @@ */ import { useRef } from '@wordpress/element'; import { useRefEffect } from '@wordpress/compose'; -import { insert, toHTMLString } from '@wordpress/rich-text'; -import { getBlockTransforms, findTransform } from '@wordpress/blocks'; +import { remove, toHTMLString } from '@wordpress/rich-text'; +import { + getBlockType, + getBlockTransforms, + findTransform, +} from '@wordpress/blocks'; import { useDispatch } from '@wordpress/data'; /** @@ -21,30 +25,31 @@ function findSelection( blocks ) { let i = blocks.length; while ( i-- ) { - const attributeKey = retrieveSelectedAttribute( - blocks[ i ].attributes - ); + const block = blocks[ i ]; + const attributeKey = retrieveSelectedAttribute( block.attributes ); if ( attributeKey ) { - blocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[ - attributeKey - ] - // To do: refactor this to use rich text's selection instead, so - // we no longer have to use on this hack inserting a special - // character. - .toString() - .replace( START_OF_SELECTED_AREA, '' ); - return [ blocks[ i ].clientId, attributeKey, 0, 0 ]; + return [ block, attributeKey ]; } - const nestedSelection = findSelection( blocks[ i ].innerBlocks ); + const nestedSelection = findSelection( block.innerBlocks ); if ( nestedSelection ) { return nestedSelection; } } - return []; + return null; +} + +function* getBlockNames( block ) { + yield block.name; + if ( ! block.innerBlocks ) { + return; + } + for ( const innerBlock of block.innerBlocks ) { + yield* getBlockNames( innerBlock ); + } } export function useInputRules( props ) { @@ -55,8 +60,9 @@ export function useInputRules( props ) { const propsRef = useRef( props ); propsRef.current = props; return useRefEffect( ( element ) => { - function inputRule() { - const { getValue, onReplace, selectionChange } = propsRef.current; + async function inputRule() { + const { getValue, onChange, onReplace, selectionChange } = + propsRef.current; if ( ! onReplace ) { return; @@ -79,28 +85,48 @@ export function useInputRules( props ) { ); const transformation = findTransform( prefixTransforms, - ( { prefix } ) => { - return trimmedTextBefore === prefix; - } + ( { prefix } ) => trimmedTextBefore === prefix ); if ( ! transformation ) { return; } - const content = toHTMLString( { - value: insert( value, START_OF_SELECTED_AREA, 0, start ), - } ); - const block = transformation.transform( content ); + onChange( remove( value, 0, start ) ); + const block = transformation.transform( START_OF_SELECTED_AREA ); + for ( const blockName of getBlockNames( block ) ) { + const blockType = getBlockType( blockName ); + if ( blockType.lazyEdit ) { + await blockType.lazyEdit(); + } + } - selectionChange( ...findSelection( [ block ] ) ); + const selection = findSelection( [ block ] ); + if ( selection ) { + const [ selectedBlock, selectedAttribute ] = selection; + const valueNow = getValue(); + const valueStr = toHTMLString( { value: valueNow } ); + // To do: refactor this to use rich text's selection instead, so + // we no longer have to use on this hack inserting a special + // character. + selectedBlock.attributes[ selectedAttribute ] = + selectedBlock.attributes[ selectedAttribute ] + .toString() + .replace( START_OF_SELECTED_AREA, valueStr ); + selectionChange( + selectedBlock.clientId, + selectedAttribute, + 0, + 0 + ); + } onReplace( [ block ] ); __unstableMarkAutomaticChange(); return true; } - function onInput( event ) { + async function onInput( event ) { const { inputType, type } = event; const { getValue, @@ -114,7 +140,10 @@ export function useInputRules( props ) { return; } - if ( __unstableAllowPrefixTransformations && inputRule() ) { + if ( + __unstableAllowPrefixTransformations && + ( await inputRule() ) + ) { return; } diff --git a/packages/block-editor/src/hooks/index.js b/packages/block-editor/src/hooks/index.js index 36efe3dcf409b..237ada8360222 100644 --- a/packages/block-editor/src/hooks/index.js +++ b/packages/block-editor/src/hooks/index.js @@ -28,7 +28,7 @@ import contentLockUI from './content-lock-ui'; import './metadata'; import blockHooks from './block-hooks'; import blockRenaming from './block-renaming'; -import './use-bindings-attributes'; +// import './use-bindings-attributes'; createBlockEditFilter( [ diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index 38881233252f6..0e5293ec170ff 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -7,7 +7,6 @@ import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -62,9 +61,7 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "heading/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "heading/editor" */ './edit' ), save, }; diff --git a/packages/blocks/README.md b/packages/blocks/README.md index 8e6fdc9d900db..7b3731cb44fac 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -126,6 +126,10 @@ _Returns_ - `string`: The block's default class. +### getBlockEdit + +Undocumented declaration. + ### getBlockFromExample Create a block object from the example API. diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index aa72979818c9c..52516552234d0 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -145,6 +145,7 @@ export { getAccessibleBlockLabel as __experimentalGetAccessibleBlockLabel, __experimentalSanitizeBlockAttributes, __experimentalGetBlockAttributesNamesByRole, + getBlockEdit, } from './utils'; // Templates are, in a general sense, a basic collection of block nodes with any diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index 0d17836faea7e..8587fad9af980 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -8,7 +8,7 @@ import a11yPlugin from 'colord/plugins/a11y'; /** * WordPress dependencies */ -import { Component, isValidElement } from '@wordpress/element'; +import { Component, Suspense, lazy, isValidElement } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; import { RichTextData } from '@wordpress/rich-text'; @@ -352,3 +352,27 @@ export function omit( object, keys ) { Object.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) ) ); } + +export function lazyEdit( cb ) { + // eslint-disable-next-line @wordpress/no-unused-vars-before-return + const Load = lazy( cb ); + return function Edit( props ) { + return ( + + + + ); + }; +} + +export function getBlockEdit( blockType ) { + if ( ! blockType ) { + return null; + } + + if ( blockType.lazyEdit ) { + return lazyEdit( blockType.lazyEdit ); + } + + return blockType.edit || blockType.save || null; +} From 2a57f9db8f97f8905c61229c4286b839f15f4ef1 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 5 Feb 2024 17:05:42 +0100 Subject: [PATCH 09/27] Spinner: change role to status so that it's not picked up by role=img locators --- packages/components/src/spinner/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/spinner/index.tsx b/packages/components/src/spinner/index.tsx index 9864819fa3d97..af059557af39a 100644 --- a/packages/components/src/spinner/index.tsx +++ b/packages/components/src/spinner/index.tsx @@ -26,7 +26,7 @@ export function UnforwardedSpinner( width="16" height="16" xmlns="http://www.w3.org/2000/svg" - role="presentation" + role="status" focusable="false" { ...props } ref={ forwardedRef } From 1293bd45002c2ffdf3981ddd018958aee5778d70 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 6 Feb 2024 11:18:22 +0100 Subject: [PATCH 10/27] Migrate all blocks to lazyEdit --- packages/block-library/src/archives/index.js | 6 ++---- packages/block-library/src/audio/index.js | 5 +---- packages/block-library/src/avatar/index.js | 5 +---- packages/block-library/src/block/index.js | 5 +---- packages/block-library/src/button/index.js | 5 +---- packages/block-library/src/buttons/index.js | 5 +---- packages/block-library/src/calendar/index.js | 6 ++---- packages/block-library/src/categories/index.js | 6 ++---- packages/block-library/src/code/index.js | 6 +----- packages/block-library/src/column/index.js | 5 +---- packages/block-library/src/columns/index.js | 5 +---- .../src/comment-author-avatar/index.js | 6 ++---- .../src/comment-author-name/index.js | 6 ++---- .../block-library/src/comment-content/index.js | 6 ++---- packages/block-library/src/comment-date/index.js | 6 ++---- .../block-library/src/comment-edit-link/index.js | 6 ++---- .../src/comment-reply-link/index.js | 6 ++---- .../block-library/src/comment-template/index.js | 6 ++---- .../src/comments-pagination-next/index.js | 6 ++---- .../src/comments-pagination-numbers/index.js | 6 ++---- .../src/comments-pagination-previous/index.js | 6 ++---- .../src/comments-pagination/index.js | 6 ++---- .../block-library/src/comments-title/index.js | 7 ++----- packages/block-library/src/comments/index.js | 6 ++---- packages/block-library/src/cover/index.js | 5 +---- packages/block-library/src/details/index.js | 6 +----- packages/block-library/src/embed/index.js | 6 +----- packages/block-library/src/file/index.js | 6 +----- packages/block-library/src/footnotes/index.js | 7 ++----- packages/block-library/src/form-input/index.js | 6 ++---- .../src/form-submission-notification/index.js | 6 ++---- .../src/form-submit-button/index.js | 6 ++---- packages/block-library/src/form/index.js | 6 +----- packages/block-library/src/freeform/index.js | 6 ++---- packages/block-library/src/gallery/index.js | 6 ++---- packages/block-library/src/group/index.js | 5 +---- packages/block-library/src/home-link/index.js | 10 ++-------- packages/block-library/src/html/index.js | 5 +---- packages/block-library/src/image/image.js | 1 + packages/block-library/src/image/index.js | 5 +---- .../block-library/src/latest-comments/index.js | 6 ++---- packages/block-library/src/latest-posts/index.js | 6 ++---- packages/block-library/src/list-item/index.js | 6 ++---- packages/block-library/src/list/index.js | 5 +---- packages/block-library/src/loginout/index.js | 6 ++---- packages/block-library/src/media-text/index.js | 6 ++---- packages/block-library/src/missing/index.js | 5 +---- packages/block-library/src/more/index.js | 5 +---- .../block-library/src/navigation-link/index.js | 7 ++----- .../src/navigation-submenu/index.js | 6 ++---- packages/block-library/src/navigation/index.js | 5 +---- packages/block-library/src/nextpage/index.js | 6 ++---- .../block-library/src/page-list-item/index.js | 6 ++---- packages/block-library/src/page-list/index.js | 6 ++---- packages/block-library/src/paragraph/index.js | 8 ++++---- packages/block-library/src/pattern/index.js | 5 +---- .../src/post-author-biography/index.js | 6 ++---- .../block-library/src/post-author-name/index.js | 6 ++---- packages/block-library/src/post-author/index.js | 6 ++---- packages/block-library/src/post-comment/index.js | 6 ++---- .../src/post-comments-count/index.js | 6 ++---- .../src/post-comments-form/index.js | 6 ++---- .../src/post-comments-link/index.js | 6 ++---- packages/block-library/src/post-content/index.js | 6 ++---- packages/block-library/src/post-date/index.js | 6 ++---- packages/block-library/src/post-excerpt/index.js | 6 ++---- .../src/post-featured-image/index.js | 6 ++---- .../src/post-navigation-link/index.js | 8 ++++---- .../block-library/src/post-template/index.js | 6 ++---- packages/block-library/src/post-terms/index.js | 6 ++---- .../block-library/src/post-time-to-read/index.js | 6 ++---- packages/block-library/src/post-title/index.js | 6 ++---- packages/block-library/src/preformatted/index.js | 6 ++---- packages/block-library/src/pullquote/index.js | 6 ++---- .../block-library/src/query-no-results/index.js | 6 ++---- .../src/query-pagination-next/index.js | 6 ++---- .../src/query-pagination-numbers/index.js | 6 ++---- .../src/query-pagination-previous/index.js | 6 ++---- .../block-library/src/query-pagination/index.js | 6 ++---- packages/block-library/src/query-title/index.js | 6 ++---- packages/block-library/src/query/index.js | 5 +---- packages/block-library/src/quote/index.js | 6 +----- packages/block-library/src/read-more/index.js | 6 ++---- packages/block-library/src/rss/index.js | 5 +---- packages/block-library/src/search/index.js | 5 +---- packages/block-library/src/separator/index.js | 6 ++---- packages/block-library/src/shortcode/index.js | 6 ++---- packages/block-library/src/site-logo/index.js | 6 ++---- packages/block-library/src/site-tagline/index.js | 6 ++---- packages/block-library/src/site-title/index.js | 6 ++---- packages/block-library/src/social-link/index.js | 6 ++---- packages/block-library/src/social-links/index.js | 6 ++---- packages/block-library/src/spacer/index.js | 5 +---- .../block-library/src/table-of-contents/index.js | 6 ++---- packages/block-library/src/table/index.js | 5 +---- packages/block-library/src/tag-cloud/index.js | 6 ++---- .../block-library/src/template-part/index.js | 6 ++---- .../block-library/src/term-description/index.js | 6 ++---- packages/block-library/src/text-columns/index.js | 7 ++----- packages/block-library/src/utils/lazy-load.js | 16 ---------------- packages/block-library/src/verse/index.js | 6 +----- packages/block-library/src/video/index.js | 5 +---- 102 files changed, 176 insertions(+), 431 deletions(-) delete mode 100644 packages/block-library/src/utils/lazy-load.js diff --git a/packages/block-library/src/archives/index.js b/packages/block-library/src/archives/index.js index ea48208ad514b..1a579f1e10809 100644 --- a/packages/block-library/src/archives/index.js +++ b/packages/block-library/src/archives/index.js @@ -6,7 +6,6 @@ import { archive as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "archives/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "archives/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/audio/index.js b/packages/block-library/src/audio/index.js index 47483e045633d..3f37ccdcf3b5a 100644 --- a/packages/block-library/src/audio/index.js +++ b/packages/block-library/src/audio/index.js @@ -6,7 +6,6 @@ import { audio as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -28,9 +27,7 @@ export const settings = { }, transforms, deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "audio/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "audio/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/avatar/index.js b/packages/block-library/src/avatar/index.js index 1408dd55855de..62de9d77e3cb9 100644 --- a/packages/block-library/src/avatar/index.js +++ b/packages/block-library/src/avatar/index.js @@ -6,7 +6,6 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,7 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "avatar/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "avatar/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/block/index.js b/packages/block-library/src/block/index.js index 72eb72a2bc6e9..a2d3ee89e3f75 100644 --- a/packages/block-library/src/block/index.js +++ b/packages/block-library/src/block/index.js @@ -9,7 +9,6 @@ import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import deprecated from './deprecated'; @@ -20,9 +19,7 @@ export { metadata, name }; export const settings = { deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "block/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "block/editor" */ './edit' ), icon, __experimentalLabel: ( { ref } ) => { if ( ! ref ) { diff --git a/packages/block-library/src/button/index.js b/packages/block-library/src/button/index.js index 6de6ea51089d3..a3d5670b51137 100644 --- a/packages/block-library/src/button/index.js +++ b/packages/block-library/src/button/index.js @@ -7,7 +7,6 @@ import { button as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -26,9 +25,7 @@ export const settings = { text: __( 'Call to Action' ), }, }, - edit: lazyLoad( () => - import( /* webpackChunkName: "button/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "button/editor" */ './edit' ), save, deprecated, merge: ( a, { text = '' } ) => ( { diff --git a/packages/block-library/src/buttons/index.js b/packages/block-library/src/buttons/index.js index 525add2157b94..aa19e5eca0311 100644 --- a/packages/block-library/src/buttons/index.js +++ b/packages/block-library/src/buttons/index.js @@ -7,7 +7,6 @@ import { buttons as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import transforms from './transforms'; @@ -35,9 +34,7 @@ export const settings = { }, deprecated, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "buttons/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "buttons/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/calendar/index.js b/packages/block-library/src/calendar/index.js index ef9c5befb0c16..09763ce3b4944 100644 --- a/packages/block-library/src/calendar/index.js +++ b/packages/block-library/src/calendar/index.js @@ -6,7 +6,6 @@ import { calendar as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -19,9 +18,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "calendar/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "calendar/editor" */ './edit' ), transforms, }; diff --git a/packages/block-library/src/categories/index.js b/packages/block-library/src/categories/index.js index 25a48e309749f..b59c61d9d2ae7 100644 --- a/packages/block-library/src/categories/index.js +++ b/packages/block-library/src/categories/index.js @@ -6,7 +6,6 @@ import { category as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "categories/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "categories/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/code/index.js b/packages/block-library/src/code/index.js index 738097b2f8695..9885c05730eb8 100644 --- a/packages/block-library/src/code/index.js +++ b/packages/block-library/src/code/index.js @@ -7,9 +7,7 @@ import { code as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; - import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -36,9 +34,7 @@ export const settings = { }; }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "code/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "code/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/column/index.js b/packages/block-library/src/column/index.js index 520ea236b9390..01a38f50799bf 100644 --- a/packages/block-library/src/column/index.js +++ b/packages/block-library/src/column/index.js @@ -6,7 +6,6 @@ import { column as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -19,9 +18,7 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "column/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "column/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index 6dec6008f07fc..a999800b8390c 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -7,7 +7,6 @@ import { columns as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -81,9 +80,7 @@ export const settings = { ], }, deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "columns/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "columns/editor" */ './edit' ), save, transforms, }; diff --git a/packages/block-library/src/comment-author-avatar/index.js b/packages/block-library/src/comment-author-avatar/index.js index 7382940585126..caff08add2fbb 100644 --- a/packages/block-library/src/comment-author-avatar/index.js +++ b/packages/block-library/src/comment-author-avatar/index.js @@ -6,7 +6,6 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "comment-author-avatar/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-author-name/index.js b/packages/block-library/src/comment-author-name/index.js index f4ece72b83ca1..ccf59e432288d 100644 --- a/packages/block-library/src/comment-author-name/index.js +++ b/packages/block-library/src/comment-author-name/index.js @@ -6,7 +6,6 @@ import { commentAuthorName as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-author-name/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-author-name/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/comment-content/index.js b/packages/block-library/src/comment-content/index.js index aee1976cf5eb5..8478879130867 100644 --- a/packages/block-library/src/comment-content/index.js +++ b/packages/block-library/src/comment-content/index.js @@ -6,7 +6,6 @@ import { commentContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-content/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-content/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-date/index.js b/packages/block-library/src/comment-date/index.js index 47ba124b80f49..4b667c2a07086 100644 --- a/packages/block-library/src/comment-date/index.js +++ b/packages/block-library/src/comment-date/index.js @@ -6,7 +6,6 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-date/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-date/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/comment-edit-link/index.js b/packages/block-library/src/comment-edit-link/index.js index 6a2bd5a2615dc..3d5224df678a6 100644 --- a/packages/block-library/src/comment-edit-link/index.js +++ b/packages/block-library/src/comment-edit-link/index.js @@ -6,7 +6,6 @@ import { commentEditLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-edit-link/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-edit-link/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-reply-link/index.js b/packages/block-library/src/comment-reply-link/index.js index 6f976b42b56f4..73b300ec3cd2e 100644 --- a/packages/block-library/src/comment-reply-link/index.js +++ b/packages/block-library/src/comment-reply-link/index.js @@ -6,7 +6,6 @@ import { commentReplyLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -14,9 +13,8 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-reply-link/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-reply-link/editor" */ './edit' ), icon, }; diff --git a/packages/block-library/src/comment-template/index.js b/packages/block-library/src/comment-template/index.js index 48adbe49c7622..d2ffe76c2c85b 100644 --- a/packages/block-library/src/comment-template/index.js +++ b/packages/block-library/src/comment-template/index.js @@ -6,7 +6,6 @@ import { layout as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comment-template/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comment-template/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/comments-pagination-next/index.js b/packages/block-library/src/comments-pagination-next/index.js index 8488fee58627c..ba141486263ef 100644 --- a/packages/block-library/src/comments-pagination-next/index.js +++ b/packages/block-library/src/comments-pagination-next/index.js @@ -6,7 +6,6 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "comments-pagination-next/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-numbers/index.js b/packages/block-library/src/comments-pagination-numbers/index.js index 0569d3805d80d..770300744b85c 100644 --- a/packages/block-library/src/comments-pagination-numbers/index.js +++ b/packages/block-library/src/comments-pagination-numbers/index.js @@ -6,7 +6,6 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "comments-pagination-numbers/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-previous/index.js b/packages/block-library/src/comments-pagination-previous/index.js index 08872418014ee..f7919d629100d 100644 --- a/packages/block-library/src/comments-pagination-previous/index.js +++ b/packages/block-library/src/comments-pagination-previous/index.js @@ -6,7 +6,6 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "comments-pagination-previous/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination/index.js b/packages/block-library/src/comments-pagination/index.js index 97a81ffeac212..ccf8eddac8d58 100644 --- a/packages/block-library/src/comments-pagination/index.js +++ b/packages/block-library/src/comments-pagination/index.js @@ -6,7 +6,6 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comments-pagination/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comments-pagination/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/comments-title/index.js b/packages/block-library/src/comments-title/index.js index 21af7b4ab8de9..847cfd8d64977 100644 --- a/packages/block-library/src/comments-title/index.js +++ b/packages/block-library/src/comments-title/index.js @@ -6,10 +6,8 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; - import deprecated from './deprecated'; const { name } = metadata; @@ -17,9 +15,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comments-title/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comments-title/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/comments/index.js b/packages/block-library/src/comments/index.js index fba1feab5478f..b544415964689 100644 --- a/packages/block-library/src/comments/index.js +++ b/packages/block-library/src/comments/index.js @@ -6,7 +6,6 @@ import { postComments as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import deprecated from './deprecated'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "comments/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "comments/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/cover/index.js b/packages/block-library/src/cover/index.js index 91ae540fbad21..4641864d3775a 100644 --- a/packages/block-library/src/cover/index.js +++ b/packages/block-library/src/cover/index.js @@ -7,7 +7,6 @@ import { cover as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -47,9 +46,7 @@ export const settings = { }, transforms, save, - edit: lazyLoad( () => - import( /* webpackChunkName: "cover/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "cover/editor" */ './edit' ), deprecated, variations, }; diff --git a/packages/block-library/src/details/index.js b/packages/block-library/src/details/index.js index ec57143c22b42..8c802b6d919da 100644 --- a/packages/block-library/src/details/index.js +++ b/packages/block-library/src/details/index.js @@ -7,10 +7,8 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; - import save from './save'; const { name } = metadata; @@ -35,9 +33,7 @@ export const settings = { ], }, save, - edit: lazyLoad( () => - import( /* webpackChunkName: "details/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "details/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/embed/index.js b/packages/block-library/src/embed/index.js index 66302a92aa9d6..fcd204c2a1a8b 100644 --- a/packages/block-library/src/embed/index.js +++ b/packages/block-library/src/embed/index.js @@ -1,9 +1,7 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; - import save from './save'; import metadata from './block.json'; import transforms from './transforms'; @@ -16,9 +14,7 @@ export { metadata, name }; export const settings = { icon: embedContentIcon, - edit: lazyLoad( () => - import( /* webpackChunkName: "embed/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "embed/editor" */ './edit' ), save, transforms, variations, diff --git a/packages/block-library/src/file/index.js b/packages/block-library/src/file/index.js index 5c25d0fd926ce..6b76c0ac6daf4 100644 --- a/packages/block-library/src/file/index.js +++ b/packages/block-library/src/file/index.js @@ -7,10 +7,8 @@ import { file as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; - import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -29,9 +27,7 @@ export const settings = { }, transforms, deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "file/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "file/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/footnotes/index.js b/packages/block-library/src/footnotes/index.js index cad77181e4e0f..06830434111c0 100644 --- a/packages/block-library/src/footnotes/index.js +++ b/packages/block-library/src/footnotes/index.js @@ -7,9 +7,7 @@ import { registerFormatType } from '@wordpress/rich-text'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; - import metadata from './block.json'; import { formatName, format } from './format'; @@ -19,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "footnotes/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "footnotes/editor" */ './edit' ), }; registerFormatType( formatName, format ); diff --git a/packages/block-library/src/form-input/index.js b/packages/block-library/src/form-input/index.js index 0bc89004056f8..6830e292a23b5 100644 --- a/packages/block-library/src/form-input/index.js +++ b/packages/block-library/src/form-input/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -14,9 +13,8 @@ export { metadata, name }; export const settings = { deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "form-input/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "form-input/editor" */ './edit' ), save, variations, }; diff --git a/packages/block-library/src/form-submission-notification/index.js b/packages/block-library/src/form-submission-notification/index.js index 87378197ccdde..77dbe1a961409 100644 --- a/packages/block-library/src/form-submission-notification/index.js +++ b/packages/block-library/src/form-submission-notification/index.js @@ -6,7 +6,6 @@ import { group as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -19,11 +18,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "form-submission-notification/editor" */ './edit' - ) - ), + ), save, variations, }; diff --git a/packages/block-library/src/form-submit-button/index.js b/packages/block-library/src/form-submit-button/index.js index fc780d08951e4..1f5a4ecbfc9e4 100644 --- a/packages/block-library/src/form-submit-button/index.js +++ b/packages/block-library/src/form-submit-button/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -12,9 +11,8 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "form-submit-button/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "form-submit-button/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/form/index.js b/packages/block-library/src/form/index.js index 79817e26bf277..3bb5c1d9c985f 100644 --- a/packages/block-library/src/form/index.js +++ b/packages/block-library/src/form/index.js @@ -1,9 +1,7 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; - import metadata from './block.json'; import save from './save'; import variations from './variations'; @@ -18,9 +16,7 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "form/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "form/editor" */ './edit' ), save, variations, }; diff --git a/packages/block-library/src/freeform/index.js b/packages/block-library/src/freeform/index.js index 7489453a56f44..5f1d1642c0d39 100644 --- a/packages/block-library/src/freeform/index.js +++ b/packages/block-library/src/freeform/index.js @@ -6,7 +6,6 @@ import { classic as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "freeform/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "freeform/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/gallery/index.js b/packages/block-library/src/gallery/index.js index f971a40e512c9..dd46e5144d8fe 100644 --- a/packages/block-library/src/gallery/index.js +++ b/packages/block-library/src/gallery/index.js @@ -6,7 +6,6 @@ import { gallery as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -39,9 +38,8 @@ export const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "gallery/editor" */ './edit-wrapper' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "gallery/editor" */ './edit-wrapper' ), save, deprecated, }; diff --git a/packages/block-library/src/group/index.js b/packages/block-library/src/group/index.js index b65caba6fc9db..24230b25d13ba 100644 --- a/packages/block-library/src/group/index.js +++ b/packages/block-library/src/group/index.js @@ -7,7 +7,6 @@ import { group as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -83,9 +82,7 @@ export const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "group/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "group/editor" */ './edit' ), save, deprecated, variations, diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index 15fcb94ca209e..b92f94a56cebe 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -7,10 +7,8 @@ import { home } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; - import save from './save'; const { name } = metadata; @@ -19,13 +17,9 @@ export { metadata, name }; export const settings = { icon: home, - - edit: lazyLoad( () => - import( /* webpackChunkName: "home-link/editor" */ './edit' ) - ), - + lazyEdit: () => + import( /* webpackChunkName: "home-link/editor" */ './edit' ), save, - example: { attributes: { label: _x( 'Home Link', 'block example' ), diff --git a/packages/block-library/src/html/index.js b/packages/block-library/src/html/index.js index 1f6a10f837789..ef2d91607eec9 100644 --- a/packages/block-library/src/html/index.js +++ b/packages/block-library/src/html/index.js @@ -7,7 +7,6 @@ import { html as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -28,9 +27,7 @@ export const settings = { '', }, }, - edit: lazyLoad( () => - import( /* webpackChunkName: "html/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "html/editor" */ './edit' ), save, transforms, }; diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index af7e518f49864..8deae27529c49 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -744,6 +744,7 @@ export default function Image( { { onImageError() } onLoad={ ( event ) => { setLoadedNaturalSize( { diff --git a/packages/block-library/src/image/index.js b/packages/block-library/src/image/index.js index 5100f2a73fd7a..5f8033cdf68da 100644 --- a/packages/block-library/src/image/index.js +++ b/packages/block-library/src/image/index.js @@ -7,7 +7,6 @@ import { image as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -57,9 +56,7 @@ export const settings = { }; }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "image/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "image/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/latest-comments/index.js b/packages/block-library/src/latest-comments/index.js index f720c272bf1ed..63da6d60d58b3 100644 --- a/packages/block-library/src/latest-comments/index.js +++ b/packages/block-library/src/latest-comments/index.js @@ -6,7 +6,6 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "latest-comments/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "latest-comments/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/latest-posts/index.js b/packages/block-library/src/latest-posts/index.js index 79651516be048..b64ea1cd2e00c 100644 --- a/packages/block-library/src/latest-posts/index.js +++ b/packages/block-library/src/latest-posts/index.js @@ -6,7 +6,6 @@ import { postList as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "latest-posts/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "latest-posts/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/list-item/index.js b/packages/block-library/src/list-item/index.js index 8ce2819a09627..41b1ecfdf311f 100644 --- a/packages/block-library/src/list-item/index.js +++ b/packages/block-library/src/list-item/index.js @@ -7,7 +7,6 @@ import { privateApis } from '@wordpress/block-editor'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -21,9 +20,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "list-item/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "list-item/editor" */ './edit' ), save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 896680c654c93..b51e34b7c4c2c 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -7,7 +7,6 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -46,9 +45,7 @@ const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "list/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "list/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/loginout/index.js b/packages/block-library/src/loginout/index.js index 3dd059ab0c6a2..acbcdee1cf8b1 100644 --- a/packages/block-library/src/loginout/index.js +++ b/packages/block-library/src/loginout/index.js @@ -6,7 +6,6 @@ import { login as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -16,9 +15,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "loginout/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "loginout/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/media-text/index.js b/packages/block-library/src/media-text/index.js index ec8576d3261d5..698a9f4a70fd8 100644 --- a/packages/block-library/src/media-text/index.js +++ b/packages/block-library/src/media-text/index.js @@ -7,7 +7,6 @@ import { mediaAndText as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -46,9 +45,8 @@ export const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "media-text/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "media-text/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/missing/index.js b/packages/block-library/src/missing/index.js index 03933c3c03888..ed07422ec039f 100644 --- a/packages/block-library/src/missing/index.js +++ b/packages/block-library/src/missing/index.js @@ -6,7 +6,6 @@ import { getBlockType } from '@wordpress/blocks'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -33,9 +32,7 @@ export const settings = { return ''; } }, - edit: lazyLoad( () => - import( /* webpackChunkName: "missing/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "missing/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/more/index.js b/packages/block-library/src/more/index.js index 001a7e8c248e8..438395833b6d7 100644 --- a/packages/block-library/src/more/index.js +++ b/packages/block-library/src/more/index.js @@ -6,7 +6,6 @@ import { more as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -32,9 +31,7 @@ export const settings = { } }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "more/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "more/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/navigation-link/index.js b/packages/block-library/src/navigation-link/index.js index fcca9779c24a9..e30c11c4dbee2 100644 --- a/packages/block-library/src/navigation-link/index.js +++ b/packages/block-library/src/navigation-link/index.js @@ -9,7 +9,6 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -33,10 +32,8 @@ export const settings = { }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "navigation-link/editor" */ './edit' ) - ), - + lazyEdit: () => + import( /* webpackChunkName: "navigation-link/editor" */ './edit' ), save, example: { diff --git a/packages/block-library/src/navigation-submenu/index.js b/packages/block-library/src/navigation-submenu/index.js index 0582212ab1d60..3dac0e2bc518b 100644 --- a/packages/block-library/src/navigation-submenu/index.js +++ b/packages/block-library/src/navigation-submenu/index.js @@ -6,7 +6,6 @@ import { page, addSubmenu } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import save from './save'; @@ -36,9 +35,8 @@ export const settings = { return label; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "navigation-submenu/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "navigation-submenu/editor" */ './edit' ), save, transforms, }; diff --git a/packages/block-library/src/navigation/index.js b/packages/block-library/src/navigation/index.js index 92dc20b6dbea5..998df0489c9fe 100644 --- a/packages/block-library/src/navigation/index.js +++ b/packages/block-library/src/navigation/index.js @@ -7,7 +7,6 @@ import { navigation as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import save from './save'; @@ -50,9 +49,7 @@ export const settings = { }, ], }, - edit: lazyLoad( () => - import( /* webpackChunkName: "cover/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "cover/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/nextpage/index.js b/packages/block-library/src/nextpage/index.js index e7b4c476ebe9a..8bd19f270d0e7 100644 --- a/packages/block-library/src/nextpage/index.js +++ b/packages/block-library/src/nextpage/index.js @@ -6,7 +6,6 @@ import { pageBreak as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -21,9 +20,8 @@ export const settings = { icon, example: {}, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "nextpage/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "nextpage/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/page-list-item/index.js b/packages/block-library/src/page-list-item/index.js index f71d6f100b318..919174802a9bf 100644 --- a/packages/block-library/src/page-list-item/index.js +++ b/packages/block-library/src/page-list-item/index.js @@ -6,7 +6,6 @@ import { page as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export const settings = { __experimentalLabel: ( { label } ) => label, icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "page-list-item/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "page-list-item/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/page-list/index.js b/packages/block-library/src/page-list/index.js index a479117d1f2e4..361088fdbe828 100644 --- a/packages/block-library/src/page-list/index.js +++ b/packages/block-library/src/page-list/index.js @@ -6,7 +6,6 @@ import { pages } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon: pages, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "page-list/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "page-list/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index e3df57ca46009..d359523496451 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -7,10 +7,10 @@ import { paragraph as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; +import edit from './edit'; import save from './save'; import transforms from './transforms'; @@ -52,9 +52,9 @@ export const settings = { ( attributesToMerge.content || '' ), }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "paragraph/editor" */ './edit' ) - ), + edit, + // lazyEdit: () => + // import( /* webpackChunkName: "paragraph/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/pattern/index.js b/packages/block-library/src/pattern/index.js index 1af4716c0f445..60e44074e9117 100644 --- a/packages/block-library/src/pattern/index.js +++ b/packages/block-library/src/pattern/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -9,9 +8,7 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "pattern/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "pattern/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-biography/index.js b/packages/block-library/src/post-author-biography/index.js index 191c51560b5e2..dd705f16c299c 100644 --- a/packages/block-library/src/post-author-biography/index.js +++ b/packages/block-library/src/post-author-biography/index.js @@ -6,7 +6,6 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "post-author-biography/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-name/index.js b/packages/block-library/src/post-author-name/index.js index 83f0d40e1fc82..fe593fe2b227c 100644 --- a/packages/block-library/src/post-author-name/index.js +++ b/packages/block-library/src/post-author-name/index.js @@ -6,7 +6,6 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-author-name/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-author-name/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author/index.js b/packages/block-library/src/post-author/index.js index 252e2cc0198b6..f0500f3560fd7 100644 --- a/packages/block-library/src/post-author/index.js +++ b/packages/block-library/src/post-author/index.js @@ -6,7 +6,6 @@ import { postAuthor as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-author/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-author/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comment/index.js b/packages/block-library/src/post-comment/index.js index 761a4a59e2e6a..7bd4201cb015e 100644 --- a/packages/block-library/src/post-comment/index.js +++ b/packages/block-library/src/post-comment/index.js @@ -6,7 +6,6 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-comment/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-comment/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/post-comments-count/index.js b/packages/block-library/src/post-comments-count/index.js index f69cd8306dc08..9b47a80a19042 100644 --- a/packages/block-library/src/post-comments-count/index.js +++ b/packages/block-library/src/post-comments-count/index.js @@ -6,7 +6,6 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-comments-count/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-comments-count/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-form/index.js b/packages/block-library/src/post-comments-form/index.js index ac9e4b86e6056..de99dbebaec0b 100644 --- a/packages/block-library/src/post-comments-form/index.js +++ b/packages/block-library/src/post-comments-form/index.js @@ -6,7 +6,6 @@ import { postCommentsForm as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-comments-form/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-comments-form/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-link/index.js b/packages/block-library/src/post-comments-link/index.js index 0df6a53de69ab..2b29f25dc88a9 100644 --- a/packages/block-library/src/post-comments-link/index.js +++ b/packages/block-library/src/post-comments-link/index.js @@ -6,7 +6,6 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -14,9 +13,8 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "post-comments-link/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-comments-link/editor" */ './edit' ), icon, }; diff --git a/packages/block-library/src/post-content/index.js b/packages/block-library/src/post-content/index.js index 89ea2c43ba1e6..cff13b0ab96e7 100644 --- a/packages/block-library/src/post-content/index.js +++ b/packages/block-library/src/post-content/index.js @@ -6,7 +6,6 @@ import { postContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-content/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-content/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-date/index.js b/packages/block-library/src/post-date/index.js index 44ba45092d34b..1c4e945d3e449 100644 --- a/packages/block-library/src/post-date/index.js +++ b/packages/block-library/src/post-date/index.js @@ -6,7 +6,6 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-date/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-date/editor" */ './edit' ), deprecated, variations, }; diff --git a/packages/block-library/src/post-excerpt/index.js b/packages/block-library/src/post-excerpt/index.js index e9a649a383470..7f000748c6fbd 100644 --- a/packages/block-library/src/post-excerpt/index.js +++ b/packages/block-library/src/post-excerpt/index.js @@ -6,7 +6,6 @@ import { postExcerpt as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-excerpt/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-excerpt/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-featured-image/index.js b/packages/block-library/src/post-featured-image/index.js index c34244356f742..b293cb1bafa85 100644 --- a/packages/block-library/src/post-featured-image/index.js +++ b/packages/block-library/src/post-featured-image/index.js @@ -6,7 +6,6 @@ import { postFeaturedImage as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-featured-image/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-featured-image/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-navigation-link/index.js b/packages/block-library/src/post-navigation-link/index.js index 92a230bde5f43..d89ec12b06703 100644 --- a/packages/block-library/src/post-navigation-link/index.js +++ b/packages/block-library/src/post-navigation-link/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -11,9 +10,10 @@ const { name } = metadata; export { metadata, name }; export const settings = { - edit: lazyLoad( () => - import( /* webpackChunkName: "post-navigation-link/editor" */ './edit' ) - ), + lazyEdit: () => + import( + /* webpackChunkName: "post-navigation-link/editor" */ './edit' + ), variations, }; diff --git a/packages/block-library/src/post-template/index.js b/packages/block-library/src/post-template/index.js index 6e2db6ac68701..54d4be87ed08a 100644 --- a/packages/block-library/src/post-template/index.js +++ b/packages/block-library/src/post-template/index.js @@ -6,7 +6,6 @@ import { layout } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon: layout, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-template/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-template/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/post-terms/index.js b/packages/block-library/src/post-terms/index.js index 4fe85bc71af6b..647976b21a311 100644 --- a/packages/block-library/src/post-terms/index.js +++ b/packages/block-library/src/post-terms/index.js @@ -7,7 +7,6 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-terms/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-terms/editor" */ './edit' ), }; export const init = () => { diff --git a/packages/block-library/src/post-time-to-read/index.js b/packages/block-library/src/post-time-to-read/index.js index 107ab238b1803..63f84018ee282 100644 --- a/packages/block-library/src/post-time-to-read/index.js +++ b/packages/block-library/src/post-time-to-read/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -12,9 +11,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-time-to-read/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-time-to-read/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-title/index.js b/packages/block-library/src/post-title/index.js index 9d3c0590f898c..29e6245526520 100644 --- a/packages/block-library/src/post-title/index.js +++ b/packages/block-library/src/post-title/index.js @@ -6,7 +6,6 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "post-title/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "post-title/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/preformatted/index.js b/packages/block-library/src/preformatted/index.js index 0e8fade75a99c..1aa928ff64c92 100644 --- a/packages/block-library/src/preformatted/index.js +++ b/packages/block-library/src/preformatted/index.js @@ -7,7 +7,6 @@ import { preformatted as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -31,9 +30,8 @@ export const settings = { }, }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "preformatted/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "preformatted/editor" */ './edit' ), save, merge( attributes, attributesToMerge ) { return { diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index 0facf4323048c..c6b8511ed8c07 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -7,7 +7,6 @@ import { pullquote as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -32,9 +31,8 @@ export const settings = { }, }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "pullquote/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "pullquote/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/query-no-results/index.js b/packages/block-library/src/query-no-results/index.js index eac234da75de4..b29cdf8ac9f54 100644 --- a/packages/block-library/src/query-no-results/index.js +++ b/packages/block-library/src/query-no-results/index.js @@ -6,7 +6,6 @@ import { loop as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "query-no-results/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "query-no-results/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/query-pagination-next/index.js b/packages/block-library/src/query-pagination-next/index.js index 0b5de92bb6f88..a341be4469209 100644 --- a/packages/block-library/src/query-pagination-next/index.js +++ b/packages/block-library/src/query-pagination-next/index.js @@ -6,7 +6,6 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "query-pagination-next/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-numbers/index.js b/packages/block-library/src/query-pagination-numbers/index.js index cf288bf278a9b..ec6a2e3d8de2e 100644 --- a/packages/block-library/src/query-pagination-numbers/index.js +++ b/packages/block-library/src/query-pagination-numbers/index.js @@ -6,7 +6,6 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "query-pagination-numbers/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-previous/index.js b/packages/block-library/src/query-pagination-previous/index.js index 5119ac89674ab..6b7bbf9255c93 100644 --- a/packages/block-library/src/query-pagination-previous/index.js +++ b/packages/block-library/src/query-pagination-previous/index.js @@ -6,7 +6,6 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,11 +14,10 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => + lazyEdit: () => import( /* webpackChunkName: "query-pagination-previous/editor" */ './edit' - ) - ), + ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination/index.js b/packages/block-library/src/query-pagination/index.js index 3e3590fefbc54..493d503e1a1d3 100644 --- a/packages/block-library/src/query-pagination/index.js +++ b/packages/block-library/src/query-pagination/index.js @@ -6,7 +6,6 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "query-pagination/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "query-pagination/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/query-title/index.js b/packages/block-library/src/query-title/index.js index 997d2ca4be147..83ea4fc4adcc0 100644 --- a/packages/block-library/src/query-title/index.js +++ b/packages/block-library/src/query-title/index.js @@ -6,7 +6,6 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "query-title/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "query-title/editor" */ './edit' ), variations, deprecated, }; diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index f2515cb844caf..d3281e3afeb2a 100644 --- a/packages/block-library/src/query/index.js +++ b/packages/block-library/src/query/index.js @@ -6,7 +6,6 @@ import { loop as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -19,9 +18,7 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "query/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "query/editor" */ './edit' ), save, variations, deprecated, diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index fdb5ce219d330..f92054836aaba 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -7,10 +7,8 @@ import { quote as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; - import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -35,9 +33,7 @@ export const settings = { ], }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "quote/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "quote/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/read-more/index.js b/packages/block-library/src/read-more/index.js index 374ec510a8a3f..bc9659962f79d 100644 --- a/packages/block-library/src/read-more/index.js +++ b/packages/block-library/src/read-more/index.js @@ -6,7 +6,6 @@ import { link as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "read-more/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "read-more/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/rss/index.js b/packages/block-library/src/rss/index.js index 51784dd833f2f..baac7a6d54b91 100644 --- a/packages/block-library/src/rss/index.js +++ b/packages/block-library/src/rss/index.js @@ -6,7 +6,6 @@ import { rss as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -21,9 +20,7 @@ export const settings = { feedURL: 'https://wordpress.org', }, }, - edit: lazyLoad( () => - import( /* webpackChunkName: "rss/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "rss/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js index bb1b3984dd408..82dca7c5485fe 100644 --- a/packages/block-library/src/search/index.js +++ b/packages/block-library/src/search/index.js @@ -7,7 +7,6 @@ import { search as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -24,9 +23,7 @@ export const settings = { viewportWidth: 400, }, variations, - edit: lazyLoad( () => - import( /* webpackChunkName: "search/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "search/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/separator/index.js b/packages/block-library/src/separator/index.js index aec5fffe4e980..ddbd8837c9302 100644 --- a/packages/block-library/src/separator/index.js +++ b/packages/block-library/src/separator/index.js @@ -6,7 +6,6 @@ import { separator as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -27,9 +26,8 @@ export const settings = { }, }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "separator/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "separator/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/shortcode/index.js b/packages/block-library/src/shortcode/index.js index e7085cb3b929f..29cc1ec8d3a5a 100644 --- a/packages/block-library/src/shortcode/index.js +++ b/packages/block-library/src/shortcode/index.js @@ -6,7 +6,6 @@ import { shortcode as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import save from './save'; import transforms from './transforms'; @@ -19,9 +18,8 @@ export { metadata, name }; export const settings = { icon, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "shortcode/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "shortcode/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/site-logo/index.js b/packages/block-library/src/site-logo/index.js index 26c1a0a6ab855..655424eed71e0 100644 --- a/packages/block-library/src/site-logo/index.js +++ b/packages/block-library/src/site-logo/index.js @@ -6,7 +6,6 @@ import { siteLogo as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import transforms from './transforms'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "site-logo/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "site-logo/editor" */ './edit' ), transforms, }; diff --git a/packages/block-library/src/site-tagline/index.js b/packages/block-library/src/site-tagline/index.js index 04485620639db..6f8ccf9cecabc 100644 --- a/packages/block-library/src/site-tagline/index.js +++ b/packages/block-library/src/site-tagline/index.js @@ -1,7 +1,6 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import icon from './icon'; @@ -12,9 +11,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "site-tagline/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "site-tagline/editor" */ './edit' ), deprecated, }; diff --git a/packages/block-library/src/site-title/index.js b/packages/block-library/src/site-title/index.js index 9078a8cdbaf45..d832d8323783f 100644 --- a/packages/block-library/src/site-title/index.js +++ b/packages/block-library/src/site-title/index.js @@ -6,7 +6,6 @@ import { mapMarker as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -19,9 +18,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "site-title/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "site-title/editor" */ './edit' ), transforms, deprecated, }; diff --git a/packages/block-library/src/social-link/index.js b/packages/block-library/src/social-link/index.js index 1d4aa6ecdeef8..e00105a386d34 100644 --- a/packages/block-library/src/social-link/index.js +++ b/packages/block-library/src/social-link/index.js @@ -6,7 +6,6 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import variations from './variations'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "social-link/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "social-link/editor" */ './edit' ), variations, }; diff --git a/packages/block-library/src/social-links/index.js b/packages/block-library/src/social-links/index.js index 4660866c720ad..9b0e039e4133f 100644 --- a/packages/block-library/src/social-links/index.js +++ b/packages/block-library/src/social-links/index.js @@ -6,7 +6,6 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -43,9 +42,8 @@ export const settings = { ], }, icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "social-links/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "social-links/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/spacer/index.js b/packages/block-library/src/spacer/index.js index 598df25bd51f6..a5c987c4497ff 100644 --- a/packages/block-library/src/spacer/index.js +++ b/packages/block-library/src/spacer/index.js @@ -6,7 +6,6 @@ import { resizeCornerNE as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -19,9 +18,7 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "spacer/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "spacer/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/table-of-contents/index.js b/packages/block-library/src/table-of-contents/index.js index cd99919d93763..610ecfa2e6ba7 100644 --- a/packages/block-library/src/table-of-contents/index.js +++ b/packages/block-library/src/table-of-contents/index.js @@ -6,7 +6,6 @@ import { tableOfContents as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import save from './save'; @@ -17,9 +16,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "table-of-contents/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "table-of-contents/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/table/index.js b/packages/block-library/src/table/index.js index ffc4a9d34fac0..82de376d09579 100644 --- a/packages/block-library/src/table/index.js +++ b/packages/block-library/src/table/index.js @@ -7,7 +7,6 @@ import { blockTable as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import metadata from './block.json'; @@ -94,9 +93,7 @@ export const settings = { viewportWidth: 450, }, transforms, - edit: lazyLoad( () => - import( /* webpackChunkName: "table/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "table/editor" */ './edit' ), save, deprecated, }; diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js index c8380126ee1aa..1e32c621b419a 100644 --- a/packages/block-library/src/tag-cloud/index.js +++ b/packages/block-library/src/tag-cloud/index.js @@ -6,7 +6,6 @@ import { tag as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import transforms from './transforms'; import metadata from './block.json'; @@ -18,9 +17,8 @@ export { metadata, name }; export const settings = { icon, example: {}, - edit: lazyLoad( () => - import( /* webpackChunkName: "tag-cloud/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "tag-cloud/editor" */ './edit' ), transforms, }; diff --git a/packages/block-library/src/template-part/index.js b/packages/block-library/src/template-part/index.js index 678875e24f3be..05b8a1cfe3aaf 100644 --- a/packages/block-library/src/template-part/index.js +++ b/packages/block-library/src/template-part/index.js @@ -15,7 +15,6 @@ import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -48,9 +47,8 @@ export const settings = { decodeEntities( entity.title ) || capitalCase( entity.slug || '' ) ); }, - edit: lazyLoad( () => - import( /* webpackChunkName: "template-part/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "template-part/editor" */ './edit' ), }; export const init = () => { diff --git a/packages/block-library/src/term-description/index.js b/packages/block-library/src/term-description/index.js index 44b0f3e93588a..26d2005edb875 100644 --- a/packages/block-library/src/term-description/index.js +++ b/packages/block-library/src/term-description/index.js @@ -6,7 +6,6 @@ import { termDescription as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import metadata from './block.json'; @@ -15,9 +14,8 @@ export { metadata, name }; export const settings = { icon, - edit: lazyLoad( () => - import( /* webpackChunkName: "term-description/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "term-description/editor" */ './edit' ), }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index 6976759f3a88e..33527132b644d 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -1,9 +1,7 @@ /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; - import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -20,9 +18,8 @@ export const settings = { return { 'data-align': width }; } }, - edit: lazyLoad( () => - import( /* webpackChunkName: "text-columns/editor" */ './edit' ) - ), + lazyEdit: () => + import( /* webpackChunkName: "text-columns/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/utils/lazy-load.js b/packages/block-library/src/utils/lazy-load.js deleted file mode 100644 index f88679f8d1227..0000000000000 --- a/packages/block-library/src/utils/lazy-load.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * WordPress dependencies - */ -import { Suspense, lazy } from '@wordpress/element'; - -export default function lazyEdit( cb ) { - // eslint-disable-next-line @wordpress/no-unused-vars-before-return - const Load = lazy( cb ); - return function Edit( props ) { - return ( - - - - ); - }; -} diff --git a/packages/block-library/src/verse/index.js b/packages/block-library/src/verse/index.js index aeb629a8757fb..ff7a6cfe2665f 100644 --- a/packages/block-library/src/verse/index.js +++ b/packages/block-library/src/verse/index.js @@ -7,10 +7,8 @@ import { verse as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; - import metadata from './block.json'; import save from './save'; import transforms from './transforms'; @@ -38,9 +36,7 @@ export const settings = { content: attributes.content + '\n\n' + attributesToMerge.content, }; }, - edit: lazyLoad( () => - import( /* webpackChunkName: "verse/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "verse/editor" */ './edit' ), save, }; diff --git a/packages/block-library/src/video/index.js b/packages/block-library/src/video/index.js index f07c64b8eb1e6..6576ea84cf909 100644 --- a/packages/block-library/src/video/index.js +++ b/packages/block-library/src/video/index.js @@ -7,7 +7,6 @@ import { video as icon } from '@wordpress/icons'; /** * Internal dependencies */ -import lazyLoad from '../utils/lazy-load'; import initBlock from '../utils/init-block'; import deprecated from './deprecated'; @@ -30,9 +29,7 @@ export const settings = { }, transforms, deprecated, - edit: lazyLoad( () => - import( /* webpackChunkName: "video/editor" */ './edit' ) - ), + lazyEdit: () => import( /* webpackChunkName: "video/editor" */ './edit' ), save, }; From 8da9ec721b69b0475bc92b52892e07bc5f3ee5e8 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 6 Feb 2024 11:31:08 +0100 Subject: [PATCH 11/27] Common lazyLoadBlock function to force block lazyEdit load --- .../components/rich-text/use-input-rules.js | 19 ++---------------- packages/blocks/README.md | 4 ++++ packages/blocks/src/api/index.js | 1 + packages/blocks/src/api/utils.js | 20 +++++++++++++++++++ .../src/editor/insert-block.ts | 4 +++- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index a2c4284cbc03c..4da854db6984e 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -5,9 +5,9 @@ import { useRef } from '@wordpress/element'; import { useRefEffect } from '@wordpress/compose'; import { remove, toHTMLString } from '@wordpress/rich-text'; import { - getBlockType, getBlockTransforms, findTransform, + lazyLoadBlock, } from '@wordpress/blocks'; import { useDispatch } from '@wordpress/data'; @@ -42,16 +42,6 @@ function findSelection( blocks ) { return null; } -function* getBlockNames( block ) { - yield block.name; - if ( ! block.innerBlocks ) { - return; - } - for ( const innerBlock of block.innerBlocks ) { - yield* getBlockNames( innerBlock ); - } -} - export function useInputRules( props ) { const { __unstableMarkLastChangeAsPersistent, @@ -94,12 +84,7 @@ export function useInputRules( props ) { onChange( remove( value, 0, start ) ); const block = transformation.transform( START_OF_SELECTED_AREA ); - for ( const blockName of getBlockNames( block ) ) { - const blockType = getBlockType( blockName ); - if ( blockType.lazyEdit ) { - await blockType.lazyEdit(); - } - } + await lazyLoadBlock( block ); const selection = findSelection( [ block ] ); if ( selection ) { diff --git a/packages/blocks/README.md b/packages/blocks/README.md index 7b3731cb44fac..b8c4d1660544a 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -406,6 +406,10 @@ _Returns_ - `boolean`: True if the parameter is a valid icon and false otherwise. +### lazyLoadBlock + +Undocumented declaration. + ### normalizeIconObject Function that receives an icon as set by the blocks during the registration and returns a new icon object that is normalized so we can rely on just on possible icon structure in the codebase. diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index 52516552234d0..1a9884d401d3a 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -146,6 +146,7 @@ export { __experimentalSanitizeBlockAttributes, __experimentalGetBlockAttributesNamesByRole, getBlockEdit, + lazyLoadBlock, } from './utils'; // Templates are, in a general sense, a basic collection of block nodes with any diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index 8587fad9af980..b4d2b7ed5f497 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -376,3 +376,23 @@ export function getBlockEdit( blockType ) { return blockType.edit || blockType.save || null; } + +function* getBlockNames( block ) { + yield block.name; + if ( ! block.innerBlocks ) { + return; + } + for ( const innerBlock of block.innerBlocks ) { + yield* getBlockNames( innerBlock ); + } +} + +export function lazyLoadBlock( block ) { + const blockNames = Array.from( new Set( getBlockNames( block ) ) ); + return Promise.all( + blockNames.map( ( blockName ) => { + const blockType = getBlockType( blockName ); + return blockType.lazyEdit?.(); + } ) + ); +} diff --git a/packages/e2e-test-utils-playwright/src/editor/insert-block.ts b/packages/e2e-test-utils-playwright/src/editor/insert-block.ts index a0a08ac6f847a..2a258be33cf6f 100644 --- a/packages/e2e-test-utils-playwright/src/editor/insert-block.ts +++ b/packages/e2e-test-utils-playwright/src/editor/insert-block.ts @@ -27,7 +27,7 @@ async function insertBlock( ); await this.page.evaluate( - ( [ _blockRepresentation, _clientId ] ) => { + async ( [ _blockRepresentation, _clientId ] ) => { function recursiveCreateBlock( { name, attributes = {}, @@ -43,6 +43,8 @@ async function insertBlock( } const block = recursiveCreateBlock( _blockRepresentation ); + await window.wp.blocks.lazyLoadBlock( block ); + window.wp.data .dispatch( 'core/block-editor' ) .insertBlock( block, undefined, _clientId ); From 5e2233fdc6ccaaaab7771a7b7db4d710a0b79b00 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 7 Feb 2024 14:29:51 +0100 Subject: [PATCH 12/27] useInputRules: track into which lazy loaded block are we currently typing --- .../components/rich-text/use-input-rules.js | 150 +++++++++--------- 1 file changed, 78 insertions(+), 72 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index 4da854db6984e..a46e4819d1a08 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -42,83 +42,82 @@ function findSelection( blocks ) { return null; } -export function useInputRules( props ) { - const { - __unstableMarkLastChangeAsPersistent, - __unstableMarkAutomaticChange, - } = useDispatch( blockEditorStore ); - const propsRef = useRef( props ); - propsRef.current = props; - return useRefEffect( ( element ) => { - async function inputRule() { - const { getValue, onChange, onReplace, selectionChange } = - propsRef.current; +function findPrefixTransform( prefixText ) { + const prefixTransforms = getBlockTransforms( 'from' ).filter( + ( t ) => t.type === 'prefix' + ); + return findTransform( prefixTransforms, ( t ) => t.prefix === prefixText ); +} - if ( ! onReplace ) { - return; - } +function inputRule( props, ctx, onReplace ) { + const { getValue, onChange, selectionChange } = props; - // We must use getValue() here because value may be update - // asynchronously. - const value = getValue(); - const { start, text } = value; - const characterBefore = text.slice( start - 1, start ); + if ( ! ctx.inserterActive ) { + return; + } - // The character right before the caret must be a plain space. - if ( characterBefore !== ' ' ) { - return; - } + // We must use getValue() here because value may be update + // asynchronously. + const value = getValue(); + const { start, text } = value; + const characterBefore = text.slice( start - 1, start ); - const trimmedTextBefore = text.slice( 0, start ).trim(); - const prefixTransforms = getBlockTransforms( 'from' ).filter( - ( { type } ) => type === 'prefix' - ); - const transformation = findTransform( - prefixTransforms, - ( { prefix } ) => trimmedTextBefore === prefix - ); + // The character right before the caret must be a plain space. + if ( characterBefore !== ' ' ) { + return; + } - if ( ! transformation ) { - return; - } + const trimmedTextBefore = text.slice( 0, start ).trim(); + const transformation = findPrefixTransform( trimmedTextBefore ); + if ( ! transformation ) { + return; + } - onChange( remove( value, 0, start ) ); - const block = transformation.transform( START_OF_SELECTED_AREA ); - await lazyLoadBlock( block ); - - const selection = findSelection( [ block ] ); - if ( selection ) { - const [ selectedBlock, selectedAttribute ] = selection; - const valueNow = getValue(); - const valueStr = toHTMLString( { value: valueNow } ); - // To do: refactor this to use rich text's selection instead, so - // we no longer have to use on this hack inserting a special - // character. - selectedBlock.attributes[ selectedAttribute ] = - selectedBlock.attributes[ selectedAttribute ] - .toString() - .replace( START_OF_SELECTED_AREA, valueStr ); - selectionChange( - selectedBlock.clientId, - selectedAttribute, - 0, - 0 - ); - } - onReplace( [ block ] ); - __unstableMarkAutomaticChange(); + // remove the prefix string from the input because it's going to be processed by the transform + onChange( remove( value, 0, start ) ); - return true; + const block = transformation.transform( START_OF_SELECTED_AREA ); + const selection = findSelection( [ block ] ); + if ( selection ) { + ctx.inserterActive = selection[ 0 ].name === 'core/paragraph'; + } + lazyLoadBlock( block ).then( () => { + if ( selection ) { + const [ selectedBlock, selectedAttribute ] = selection; + const valueStr = toHTMLString( { value: getValue() } ); + // To do: refactor this to use rich text's selection instead, so + // we no longer have to use on this hack inserting a special + // character. + selectedBlock.attributes[ selectedAttribute ] = + selectedBlock.attributes[ selectedAttribute ] + .toString() + .replace( START_OF_SELECTED_AREA, valueStr ); + selectionChange( selectedBlock.clientId, selectedAttribute, 0, 0 ); } + onReplace( [ block ] ); + } ); + + return true; +} - async function onInput( event ) { +export function useInputRules( props ) { + const { + __unstableMarkLastChangeAsPersistent, + __unstableMarkAutomaticChange, + } = useDispatch( blockEditorStore ); + + const propsRef = useRef( props ); + propsRef.current = props; + + const transformCtxRef = useRef( { + inserterActive: props.__unstableAllowPrefixTransformations, + } ); + + return useRefEffect( ( element ) => { + function onInput( event ) { const { inputType, type } = event; - const { - getValue, - onChange, - __unstableAllowPrefixTransformations, - formatTypes, - } = propsRef.current; + const { getValue, onChange, onReplace, formatTypes } = + propsRef.current; // Only run input rules when inserting text. if ( inputType !== 'insertText' && type !== 'compositionend' ) { @@ -126,20 +125,27 @@ export function useInputRules( props ) { } if ( - __unstableAllowPrefixTransformations && - ( await inputRule() ) + onReplace && + inputRule( + propsRef.current, + transformCtxRef.current, + ( blocks ) => { + onReplace( blocks ); + __unstableMarkAutomaticChange(); + } + ) ) { return; } const value = getValue(); const transformed = formatTypes.reduce( - ( accumlator, { __unstableInputRule } ) => { + ( accumulator, { __unstableInputRule } ) => { if ( __unstableInputRule ) { - accumlator = __unstableInputRule( accumlator ); + return __unstableInputRule( accumulator ); } - return accumlator; + return accumulator; }, preventEventDiscovery( value ) ); From d2d3699d9f6ea772e2926a0363e62e0706bcdb0d Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 7 Feb 2024 20:00:06 +0200 Subject: [PATCH 13/27] Fix LinkControl unit tests --- .../src/components/link-control/test/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/link-control/test/index.js b/packages/block-editor/src/components/link-control/test/index.js index 411ae62d4eee1..b4117050f9628 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -176,7 +176,7 @@ describe( 'Basic rendering', () => { await user.type( searchInput, 'Hello' ); // Wait for the spinner SVG icon to be rendered. - expect( await screen.findByRole( 'presentation' ) ).toBeVisible(); + expect( await screen.findByRole( 'status' ) ).toBeVisible(); // Check the suggestions list is not rendered yet. expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument(); @@ -190,7 +190,7 @@ describe( 'Basic rendering', () => { // Check the suggestions list is rendered. expect( resultsList ).toBeVisible(); // Check the spinner SVG icon is not rendered any longer. - expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument(); + expect( screen.queryByRole( 'status' ) ).not.toBeInTheDocument(); const searchResultElements = within( resultsList ).getAllByRole( 'option' ); @@ -455,14 +455,14 @@ describe( 'Searching for a link', () => { // Simulate searching for a term. await user.type( searchInput, searchTerm ); - expect( await screen.findByRole( 'presentation' ) ).toBeVisible(); + expect( await screen.findByRole( 'status' ) ).toBeVisible(); expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument(); // make the search suggestions fetch return a response resolver( fauxEntitySuggestions ); expect( await screen.findByRole( 'listbox' ) ).toBeVisible(); - expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument(); + expect( screen.queryByRole( 'status' ) ).not.toBeInTheDocument(); } ); it.each( [ 'With spaces', 'Uppercase', 'lowercase' ] )( From 3166afadc90b14411a5194c58bf3d3eb022f3249 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 7 Feb 2024 20:05:03 +0200 Subject: [PATCH 14/27] Fix role in test snapshot too --- .../post-publish-panel/test/__snapshots__/index.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/post-publish-panel/test/__snapshots__/index.js.snap b/packages/editor/src/components/post-publish-panel/test/__snapshots__/index.js.snap index aef3f40f48c61..91883035ed0f4 100644 --- a/packages/editor/src/components/post-publish-panel/test/__snapshots__/index.js.snap +++ b/packages/editor/src/components/post-publish-panel/test/__snapshots__/index.js.snap @@ -667,7 +667,7 @@ exports[`PostPublishPanel should render the spinner if the post is being saved 1 class="components-spinner emotion-0 emotion-1" focusable="false" height="16" - role="presentation" + role="status" viewBox="0 0 100 100" width="16" xmlns="http://www.w3.org/2000/svg" From 3ac83c568db323a8f669d7adb4e34d77caccd684 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 7 Feb 2024 20:27:42 +0100 Subject: [PATCH 15/27] Set caret at the end of the inserted content --- .../components/rich-text/use-input-rules.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index a46e4819d1a08..bfcb38783fee3 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -81,21 +81,29 @@ function inputRule( props, ctx, onReplace ) { if ( selection ) { ctx.inserterActive = selection[ 0 ].name === 'core/paragraph'; } - lazyLoadBlock( block ).then( () => { - if ( selection ) { - const [ selectedBlock, selectedAttribute ] = selection; - const valueStr = toHTMLString( { value: getValue() } ); - // To do: refactor this to use rich text's selection instead, so - // we no longer have to use on this hack inserting a special - // character. - selectedBlock.attributes[ selectedAttribute ] = - selectedBlock.attributes[ selectedAttribute ] + lazyLoadBlock( block ) + // .then( () => new Promise( ( r ) => setTimeout( r, 1000 ) ) ) + .then( () => { + if ( selection ) { + const [ selectedBlock, selectedAttribute ] = selection; + const valueStr = toHTMLString( { value: getValue() } ); + // To do: refactor this to use rich text's selection instead, so + // we no longer have to use on this hack inserting a special + // character. + const newValue = selectedBlock.attributes[ selectedAttribute ] .toString() .replace( START_OF_SELECTED_AREA, valueStr ); - selectionChange( selectedBlock.clientId, selectedAttribute, 0, 0 ); - } - onReplace( [ block ] ); - } ); + + selectedBlock.attributes[ selectedAttribute ] = newValue; + selectionChange( + selectedBlock.clientId, + selectedAttribute, + newValue.length, + newValue.length + ); + } + onReplace( [ block ] ); + } ); return true; } From 822a95ae6504f98f8637e875264ecd7cb5b071b9 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 8 Feb 2024 14:55:03 +0100 Subject: [PATCH 16/27] Memoize creating lazyEdit components globally, not per component --- packages/block-editor/src/components/block-edit/edit.js | 2 +- .../src/components/block-edit/edit.native.js | 2 +- packages/blocks/src/api/utils.js | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-edit/edit.js b/packages/block-editor/src/components/block-edit/edit.js index bf7397c082d29..bada583c63b4b 100644 --- a/packages/block-editor/src/components/block-edit/edit.js +++ b/packages/block-editor/src/components/block-edit/edit.js @@ -34,7 +34,7 @@ const Edit = ( props ) => { const { name } = props; const blockType = getBlockType( name ); - const Component = useMemo( () => getBlockEdit( blockType ), [ blockType ] ); + const Component = getBlockEdit( blockType ); if ( ! Component ) { return null; } diff --git a/packages/block-editor/src/components/block-edit/edit.native.js b/packages/block-editor/src/components/block-edit/edit.native.js index 23cfc3e9105f7..60c8719d5bcc1 100644 --- a/packages/block-editor/src/components/block-edit/edit.native.js +++ b/packages/block-editor/src/components/block-edit/edit.native.js @@ -37,7 +37,7 @@ export const Edit = ( props ) => { : DEFAULT_BLOCK_CONTEXT; }, [ blockType, blockContext ] ); - const Component = useMemo( () => getBlockEdit( blockType ), [ blockType ] ); + const Component = getBlockEdit( blockType ); if ( ! Component ) { return null; } diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index b4d2b7ed5f497..6e2b76d86043e 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -365,13 +365,20 @@ export function lazyEdit( cb ) { }; } +const lazyEditCache = new WeakMap(); + export function getBlockEdit( blockType ) { if ( ! blockType ) { return null; } if ( blockType.lazyEdit ) { - return lazyEdit( blockType.lazyEdit ); + let edit = lazyEditCache.get( blockType.lazyEdit ); + if ( ! edit ) { + edit = lazyEdit( blockType.lazyEdit ); + lazyEditCache.set( blockType.lazyEdit, edit ); + } + return edit; } return blockType.edit || blockType.save || null; From 69b797d6b18ec10fd1e03b2c94b660f473e5744f Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 15 Feb 2024 09:38:21 +0100 Subject: [PATCH 17/27] use-bindings-attributes: create init function --- packages/block-editor/src/hooks/index.js | 4 +++- .../src/hooks/use-bindings-attributes.js | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/hooks/index.js b/packages/block-editor/src/hooks/index.js index 237ada8360222..b1c07bfbe674e 100644 --- a/packages/block-editor/src/hooks/index.js +++ b/packages/block-editor/src/hooks/index.js @@ -28,7 +28,9 @@ import contentLockUI from './content-lock-ui'; import './metadata'; import blockHooks from './block-hooks'; import blockRenaming from './block-renaming'; -// import './use-bindings-attributes'; +import init from './use-bindings-attributes'; + +// init(); createBlockEditFilter( [ diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index 5cd8cb46b3b7e..7c401d90b4f2b 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -257,8 +257,10 @@ function shimAttributeSource( settings, name ) { }; } -addFilter( - 'blocks.registerBlockType', - 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', - shimAttributeSource -); +export default function init() { + addFilter( + 'blocks.registerBlockType', + 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', + shimAttributeSource + ); +} From f2cc5d43c44fdda92560f88958f7dca118cb6928 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 15 Feb 2024 09:39:47 +0100 Subject: [PATCH 18/27] Block tree reducer: avoid repetitive Map.get --- packages/block-editor/src/store/reducer.js | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 751a19a1c2a8c..759978c78e0c1 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -329,16 +329,13 @@ const withBlockTree = // If there are no replaced blocks, it means we're removing blocks so we need to update their parent. const parentsOfRemovedBlocks = []; for ( const clientId of action.clientIds ) { + const parentId = state.parents.get( clientId ); if ( - state.parents.get( clientId ) !== undefined && - ( state.parents.get( clientId ) === '' || - newState.byClientId.get( - state.parents.get( clientId ) - ) ) + parentId !== undefined && + ( parentId === '' || + newState.byClientId.get( parentId ) ) ) { - parentsOfRemovedBlocks.push( - state.parents.get( clientId ) - ); + parentsOfRemovedBlocks.push( parentId ); } } updateParentInnerBlocksInTree( @@ -351,16 +348,13 @@ const withBlockTree = case 'REMOVE_BLOCKS_AUGMENTED_WITH_CHILDREN': const parentsOfRemovedBlocks = []; for ( const clientId of action.clientIds ) { + const parentId = state.parents.get( clientId ); if ( - state.parents.get( clientId ) !== undefined && - ( state.parents.get( clientId ) === '' || - newState.byClientId.get( - state.parents.get( clientId ) - ) ) + parentId !== undefined && + ( parentId === '' || + newState.byClientId.get( parentId ) ) ) { - parentsOfRemovedBlocks.push( - state.parents.get( clientId ) - ); + parentsOfRemovedBlocks.push( parentId ); } } newState.tree = new Map( newState.tree ); From 3edf8e50a927acfe1d47d29e8c2c85aef9dd9797 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 15 Feb 2024 09:40:37 +0100 Subject: [PATCH 19/27] Block tree reducer: avoid nested update for insertUsage --- packages/block-editor/src/store/reducer.js | 56 ++++++++++++---------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 759978c78e0c1..e836a44e12012 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1697,36 +1697,42 @@ export function settings( state = SETTINGS_DEFAULTS, action ) { export function preferences( state = PREFERENCES_DEFAULTS, action ) { switch ( action.type ) { case 'INSERT_BLOCKS': - case 'REPLACE_BLOCKS': - return action.blocks.reduce( ( prevState, block ) => { - const { attributes, name: blockName } = block; - let id = blockName; - // If a block variation match is found change the name to be the same with the - // one that is used for block variations in the Inserter (`getItemFromVariation`). - const match = select( blocksStore ).getActiveBlockVariation( - blockName, - attributes - ); - if ( match?.name ) { - id += '/' + match.name; - } - if ( blockName === 'core/block' ) { - id += '/' + attributes.ref; - } + case 'REPLACE_BLOCKS': { + const nextInsertUsage = action.blocks.reduce( + ( prevUsage, block ) => { + const { attributes, name: blockName } = block; + let id = blockName; + // If a block variation match is found change the name to be the same with the + // one that is used for block variations in the Inserter (`getItemFromVariation`). + const match = select( blocksStore ).getActiveBlockVariation( + blockName, + attributes + ); + if ( match?.name ) { + id += '/' + match.name; + } + if ( blockName === 'core/block' ) { + id += '/' + attributes.ref; + } - return { - ...prevState, - insertUsage: { - ...prevState.insertUsage, + return { + ...prevUsage, [ id ]: { time: action.time, - count: prevState.insertUsage[ id ] - ? prevState.insertUsage[ id ].count + 1 + count: prevUsage[ id ] + ? prevUsage[ id ].count + 1 : 1, }, - }, - }; - }, state ); + }; + }, + state.insertUsage + ); + + return { + ...state, + insertUsage: nextInsertUsage, + }; + } } return state; From 4dc653fb06ff625f57b07179f2efa3bd726fc2d0 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 15 Feb 2024 09:41:08 +0100 Subject: [PATCH 20/27] Block tree reducer: more concise lastBlockInserted --- packages/block-editor/src/store/reducer.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index e836a44e12012..ef2183981c707 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1905,13 +1905,10 @@ export function lastBlockInserted( state = {}, action ) { return state; } - const clientIds = action.blocks.map( ( block ) => { - return block.clientId; - } ); - - const source = action.meta?.source; - - return { clientIds, source }; + return { + clientIds: action.blocks.map( ( block ) => block.clientId ), + source: action.meta?.source, + }; case 'RESET_BLOCKS': return {}; } From f023b3db6c4e7d244e6c04e088e3794f9a064566 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 15 Feb 2024 14:15:01 +0100 Subject: [PATCH 21/27] BlockListBlock: extract functions from the vast withDispatch callback --- .../src/components/block-list/block.js | 412 +++++++++--------- 1 file changed, 213 insertions(+), 199 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index 69fe316112618..c80f263aa609c 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -243,193 +243,109 @@ function BlockListBlock( { ); } -const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => { +/** + * Moves the block with clientId up one level. If the block type + * cannot be inserted at the new location, it will be attempted to + * convert to the default block type. + * + * @param {Object} registry + * @param {string} clientId The block to move. + * @param {boolean} changeSelection Whether to change the selection + * to the moved block. + */ +function moveFirstItemUp( registry, clientId, changeSelection = true ) { + const { insertBlocks, moveBlocksToPosition, removeBlock } = + registry.dispatch( blockEditorStore ); const { - updateBlockAttributes, - insertBlocks, - mergeBlocks, - replaceBlocks, - toggleSelection, - __unstableMarkLastChangeAsPersistent, - moveBlocksToPosition, - removeBlock, - } = dispatch( blockEditorStore ); + getBlock, + getBlockName, + getBlockOrder, + getBlockIndex, + getBlockRootClientId, + canInsertBlockType, + } = registry.select( blockEditorStore ); - // Do not add new properties here, use `useDispatch` instead to avoid - // leaking new props to the public API (editor.BlockListBlock filter). - return { - setAttributes( newAttributes ) { - const { getMultiSelectedBlockClientIds } = - registry.select( blockEditorStore ); - const multiSelectedBlockClientIds = - getMultiSelectedBlockClientIds(); - const { clientId } = ownProps; - const clientIds = multiSelectedBlockClientIds.length - ? multiSelectedBlockClientIds - : [ clientId ]; - - updateBlockAttributes( clientIds, newAttributes ); - }, - onInsertBlocks( blocks, index ) { - const { rootClientId } = ownProps; - insertBlocks( blocks, index, rootClientId ); - }, - onInsertBlocksAfter( blocks ) { - const { clientId, rootClientId } = ownProps; - const { getBlockIndex } = registry.select( blockEditorStore ); - const index = getBlockIndex( clientId ); - insertBlocks( blocks, index + 1, rootClientId ); - }, - onMerge( forward ) { - const { clientId, rootClientId } = ownProps; - const { - getPreviousBlockClientId, - getNextBlockClientId, - getBlock, - getBlockAttributes, - getBlockName, - getBlockOrder, - getBlockIndex, - getBlockRootClientId, - canInsertBlockType, - } = registry.select( blockEditorStore ); - - /** - * Moves the block with clientId up one level. If the block type - * cannot be inserted at the new location, it will be attempted to - * convert to the default block type. - * - * @param {string} _clientId The block to move. - * @param {boolean} changeSelection Whether to change the selection - * to the moved block. - */ - function moveFirstItemUp( _clientId, changeSelection = true ) { - const targetRootClientId = getBlockRootClientId( _clientId ); - const blockOrder = getBlockOrder( _clientId ); - const [ firstClientId ] = blockOrder; + const blockOrder = getBlockOrder( clientId ); + const [ firstClientId ] = blockOrder; - if ( - blockOrder.length === 1 && - isUnmodifiedBlock( getBlock( firstClientId ) ) - ) { - removeBlock( _clientId ); - } else { - registry.batch( () => { - if ( - canInsertBlockType( - getBlockName( firstClientId ), - targetRootClientId - ) - ) { - moveBlocksToPosition( - [ firstClientId ], - _clientId, - targetRootClientId, - getBlockIndex( _clientId ) - ); - } else { - const replacement = switchToBlockType( - getBlock( firstClientId ), - getDefaultBlockName() - ); + if ( + blockOrder.length === 1 && + isUnmodifiedBlock( getBlock( firstClientId ) ) + ) { + removeBlock( clientId ); + return; + } - if ( replacement && replacement.length ) { - insertBlocks( - replacement, - getBlockIndex( _clientId ), - targetRootClientId, - changeSelection - ); - removeBlock( firstClientId, false ); - } - } + registry.batch( () => { + const targetRootClientId = getBlockRootClientId( clientId ); + if ( + canInsertBlockType( + getBlockName( firstClientId ), + targetRootClientId + ) + ) { + moveBlocksToPosition( + [ firstClientId ], + clientId, + targetRootClientId, + getBlockIndex( clientId ) + ); + } else { + const replacement = switchToBlockType( + getBlock( firstClientId ), + getDefaultBlockName() + ); - if ( - ! getBlockOrder( _clientId ).length && - isUnmodifiedBlock( getBlock( _clientId ) ) - ) { - removeBlock( _clientId, false ); - } - } ); - } + if ( replacement && replacement.length ) { + insertBlocks( + replacement, + getBlockIndex( clientId ), + targetRootClientId, + changeSelection + ); + removeBlock( firstClientId, false ); } + } + + if ( + ! getBlockOrder( clientId ).length && + isUnmodifiedBlock( getBlock( clientId ) ) + ) { + removeBlock( clientId, false ); + } + } ); +} - // For `Delete` or forward merge, we should do the exact same thing - // as `Backspace`, but from the other block. - if ( forward ) { - if ( rootClientId ) { - const nextRootClientId = - getNextBlockClientId( rootClientId ); - - if ( nextRootClientId ) { - // If there is a block that follows with the same parent - // block name and the same attributes, merge the inner - // blocks. - if ( - getBlockName( rootClientId ) === - getBlockName( nextRootClientId ) - ) { - const rootAttributes = - getBlockAttributes( rootClientId ); - const previousRootAttributes = - getBlockAttributes( nextRootClientId ); - - if ( - Object.keys( rootAttributes ).every( - ( key ) => - rootAttributes[ key ] === - previousRootAttributes[ key ] - ) - ) { - registry.batch( () => { - moveBlocksToPosition( - getBlockOrder( nextRootClientId ), - nextRootClientId, - rootClientId - ); - removeBlock( nextRootClientId, false ); - } ); - return; - } - } else { - mergeBlocks( rootClientId, nextRootClientId ); - return; - } - } - } - - const nextBlockClientId = getNextBlockClientId( clientId ); - - if ( ! nextBlockClientId ) { - return; - } - - if ( getBlockOrder( nextBlockClientId ).length ) { - moveFirstItemUp( nextBlockClientId, false ); - } else { - mergeBlocks( clientId, nextBlockClientId ); - } - } else { - const previousBlockClientId = - getPreviousBlockClientId( clientId ); - - if ( previousBlockClientId ) { - mergeBlocks( previousBlockClientId, clientId ); - } else if ( rootClientId ) { - const previousRootClientId = - getPreviousBlockClientId( rootClientId ); - - // If there is a preceding block with the same parent block - // name and the same attributes, merge the inner blocks. +function makeOnMerge( registry, clientId, rootClientId ) { + return ( forward ) => { + const { mergeBlocks, moveBlocksToPosition, removeBlock } = + registry.dispatch( blockEditorStore ); + const { + getPreviousBlockClientId, + getNextBlockClientId, + getBlockAttributes, + getBlockName, + getBlockOrder, + } = registry.select( blockEditorStore ); + + // For `Delete` or forward merge, we should do the exact same thing + // as `Backspace`, but from the other block. + if ( forward ) { + if ( rootClientId ) { + const nextRootClientId = getNextBlockClientId( rootClientId ); + + if ( nextRootClientId ) { + // If there is a block that follows with the same parent + // block name and the same attributes, merge the inner + // blocks. if ( - previousRootClientId && getBlockName( rootClientId ) === - getBlockName( previousRootClientId ) + getBlockName( nextRootClientId ) ) { const rootAttributes = getBlockAttributes( rootClientId ); const previousRootAttributes = - getBlockAttributes( previousRootClientId ); + getBlockAttributes( nextRootClientId ); if ( Object.keys( rootAttributes ).every( @@ -440,41 +356,139 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => { ) { registry.batch( () => { moveBlocksToPosition( - getBlockOrder( rootClientId ), - rootClientId, - previousRootClientId + getBlockOrder( nextRootClientId ), + nextRootClientId, + rootClientId ); - removeBlock( rootClientId, false ); + removeBlock( nextRootClientId, false ); } ); return; } + } else { + mergeBlocks( rootClientId, nextRootClientId ); + return; } + } + } + + const nextBlockClientId = getNextBlockClientId( clientId ); + + if ( ! nextBlockClientId ) { + return; + } - moveFirstItemUp( rootClientId ); - } else { - removeBlock( clientId ); + if ( getBlockOrder( nextBlockClientId ).length ) { + moveFirstItemUp( registry, nextBlockClientId, false ); + } else { + mergeBlocks( clientId, nextBlockClientId ); + } + } else { + const previousBlockClientId = getPreviousBlockClientId( clientId ); + + if ( previousBlockClientId ) { + mergeBlocks( previousBlockClientId, clientId ); + } else if ( rootClientId ) { + const previousRootClientId = + getPreviousBlockClientId( rootClientId ); + + // If there is a preceding block with the same parent block + // name and the same attributes, merge the inner blocks. + if ( + previousRootClientId && + getBlockName( rootClientId ) === + getBlockName( previousRootClientId ) + ) { + const rootAttributes = getBlockAttributes( rootClientId ); + const previousRootAttributes = + getBlockAttributes( previousRootClientId ); + + if ( + Object.keys( rootAttributes ).every( + ( key ) => + rootAttributes[ key ] === + previousRootAttributes[ key ] + ) + ) { + registry.batch( () => { + moveBlocksToPosition( + getBlockOrder( rootClientId ), + rootClientId, + previousRootClientId + ); + removeBlock( rootClientId, false ); + } ); + return; + } } + + moveFirstItemUp( registry, rootClientId ); + } else { + removeBlock( clientId ); } + } + }; +} + +function makeOnReplace( registry, clientId ) { + return ( blocks, indexToSelect, initialPosition ) => { + const { replaceBlocks, __unstableMarkLastChangeAsPersistent } = + registry.dispatch( blockEditorStore ); + + if ( + blocks.length && + ! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] ) + ) { + __unstableMarkLastChangeAsPersistent(); + } + //Unsynced patterns are nested in an array so we need to flatten them. + const replacementBlocks = + blocks?.length === 1 && Array.isArray( blocks[ 0 ] ) + ? blocks[ 0 ] + : blocks; + replaceBlocks( + [ clientId ], + replacementBlocks, + indexToSelect, + initialPosition + ); + }; +} + +const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => { + const { updateBlockAttributes, insertBlocks, toggleSelection } = + dispatch( blockEditorStore ); + + // Do not add new properties here, use `useDispatch` instead to avoid + // leaking new props to the public API (editor.BlockListBlock filter). + return { + setAttributes( newAttributes ) { + const { getMultiSelectedBlockClientIds } = + registry.select( blockEditorStore ); + const multiSelectedBlockClientIds = + getMultiSelectedBlockClientIds(); + const { clientId } = ownProps; + const clientIds = multiSelectedBlockClientIds.length + ? multiSelectedBlockClientIds + : [ clientId ]; + + updateBlockAttributes( clientIds, newAttributes ); }, - onReplace( blocks, indexToSelect, initialPosition ) { - if ( - blocks.length && - ! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] ) - ) { - __unstableMarkLastChangeAsPersistent(); - } - //Unsynced patterns are nested in an array so we need to flatten them. - const replacementBlocks = - blocks?.length === 1 && Array.isArray( blocks[ 0 ] ) - ? blocks[ 0 ] - : blocks; - replaceBlocks( - [ ownProps.clientId ], - replacementBlocks, - indexToSelect, - initialPosition - ); + onInsertBlocks( blocks, index ) { + const { rootClientId } = ownProps; + insertBlocks( blocks, index, rootClientId ); + }, + onInsertBlocksAfter( blocks ) { + const { clientId, rootClientId } = ownProps; + const { getBlockIndex } = registry.select( blockEditorStore ); + const index = getBlockIndex( clientId ); + insertBlocks( blocks, index + 1, rootClientId ); }, + onMerge: makeOnMerge( + registry, + ownProps.clientId, + ownProps.rootClientId + ), + onReplace: makeOnReplace( registry, ownProps.clientId ), toggleSelection( selectionEnabled ) { toggleSelection( selectionEnabled ); }, From 623301eab745dfffdff3670b9fc0e612c261c8f5 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Thu, 29 Feb 2024 13:24:07 +0100 Subject: [PATCH 22/27] Quote: check if deeply nested child block is selected --- packages/block-library/src/quote/edit.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/quote/edit.js b/packages/block-library/src/quote/edit.js index 4689899c6a91e..a801459432ffa 100644 --- a/packages/block-library/src/quote/edit.js +++ b/packages/block-library/src/quote/edit.js @@ -78,11 +78,17 @@ export default function QuoteEdit( { useMigrateOnLoad( attributes, clientId ); - const hasSelection = useSelect( ( select ) => { - const { isBlockSelected, hasSelectedInnerBlock } = - select( blockEditorStore ); - return hasSelectedInnerBlock( clientId ) || isBlockSelected( clientId ); - }, [] ); + const hasSelection = useSelect( + ( select ) => { + const { isBlockSelected, hasSelectedInnerBlock } = + select( blockEditorStore ); + return ( + hasSelectedInnerBlock( clientId, true ) || + isBlockSelected( clientId ) + ); + }, + [ clientId ] + ); const blockProps = useBlockProps( { className: classNames( className, { From 62f6dfdc0eaa060e2aa8a2b98cf08e60e3ca9f32 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 4 Mar 2024 14:16:42 +0100 Subject: [PATCH 23/27] BlockList: extract block edit functions as thunk actions --- .../src/components/block-list/block.js | 263 +----------------- .../block-editor/src/store/private-actions.js | 226 +++++++++++++++ 2 files changed, 240 insertions(+), 249 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index c80f263aa609c..94c421c8c0e1e 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -16,11 +16,7 @@ import { import { getBlockType, getSaveContent, - isUnmodifiedDefaultBlock, serializeRawBlock, - switchToBlockType, - getDefaultBlockName, - isUnmodifiedBlock, isReusableBlock, getBlockDefaultClassName, store as blocksStore, @@ -243,255 +239,24 @@ function BlockListBlock( { ); } -/** - * Moves the block with clientId up one level. If the block type - * cannot be inserted at the new location, it will be attempted to - * convert to the default block type. - * - * @param {Object} registry - * @param {string} clientId The block to move. - * @param {boolean} changeSelection Whether to change the selection - * to the moved block. - */ -function moveFirstItemUp( registry, clientId, changeSelection = true ) { - const { insertBlocks, moveBlocksToPosition, removeBlock } = - registry.dispatch( blockEditorStore ); - const { - getBlock, - getBlockName, - getBlockOrder, - getBlockIndex, - getBlockRootClientId, - canInsertBlockType, - } = registry.select( blockEditorStore ); - - const blockOrder = getBlockOrder( clientId ); - const [ firstClientId ] = blockOrder; - - if ( - blockOrder.length === 1 && - isUnmodifiedBlock( getBlock( firstClientId ) ) - ) { - removeBlock( clientId ); - return; - } - - registry.batch( () => { - const targetRootClientId = getBlockRootClientId( clientId ); - if ( - canInsertBlockType( - getBlockName( firstClientId ), - targetRootClientId - ) - ) { - moveBlocksToPosition( - [ firstClientId ], - clientId, - targetRootClientId, - getBlockIndex( clientId ) - ); - } else { - const replacement = switchToBlockType( - getBlock( firstClientId ), - getDefaultBlockName() - ); - - if ( replacement && replacement.length ) { - insertBlocks( - replacement, - getBlockIndex( clientId ), - targetRootClientId, - changeSelection - ); - removeBlock( firstClientId, false ); - } - } - - if ( - ! getBlockOrder( clientId ).length && - isUnmodifiedBlock( getBlock( clientId ) ) - ) { - removeBlock( clientId, false ); - } - } ); -} - -function makeOnMerge( registry, clientId, rootClientId ) { - return ( forward ) => { - const { mergeBlocks, moveBlocksToPosition, removeBlock } = - registry.dispatch( blockEditorStore ); - const { - getPreviousBlockClientId, - getNextBlockClientId, - getBlockAttributes, - getBlockName, - getBlockOrder, - } = registry.select( blockEditorStore ); - - // For `Delete` or forward merge, we should do the exact same thing - // as `Backspace`, but from the other block. - if ( forward ) { - if ( rootClientId ) { - const nextRootClientId = getNextBlockClientId( rootClientId ); - - if ( nextRootClientId ) { - // If there is a block that follows with the same parent - // block name and the same attributes, merge the inner - // blocks. - if ( - getBlockName( rootClientId ) === - getBlockName( nextRootClientId ) - ) { - const rootAttributes = - getBlockAttributes( rootClientId ); - const previousRootAttributes = - getBlockAttributes( nextRootClientId ); - - if ( - Object.keys( rootAttributes ).every( - ( key ) => - rootAttributes[ key ] === - previousRootAttributes[ key ] - ) - ) { - registry.batch( () => { - moveBlocksToPosition( - getBlockOrder( nextRootClientId ), - nextRootClientId, - rootClientId - ); - removeBlock( nextRootClientId, false ); - } ); - return; - } - } else { - mergeBlocks( rootClientId, nextRootClientId ); - return; - } - } - } - - const nextBlockClientId = getNextBlockClientId( clientId ); - - if ( ! nextBlockClientId ) { - return; - } - - if ( getBlockOrder( nextBlockClientId ).length ) { - moveFirstItemUp( registry, nextBlockClientId, false ); - } else { - mergeBlocks( clientId, nextBlockClientId ); - } - } else { - const previousBlockClientId = getPreviousBlockClientId( clientId ); - - if ( previousBlockClientId ) { - mergeBlocks( previousBlockClientId, clientId ); - } else if ( rootClientId ) { - const previousRootClientId = - getPreviousBlockClientId( rootClientId ); - - // If there is a preceding block with the same parent block - // name and the same attributes, merge the inner blocks. - if ( - previousRootClientId && - getBlockName( rootClientId ) === - getBlockName( previousRootClientId ) - ) { - const rootAttributes = getBlockAttributes( rootClientId ); - const previousRootAttributes = - getBlockAttributes( previousRootClientId ); - - if ( - Object.keys( rootAttributes ).every( - ( key ) => - rootAttributes[ key ] === - previousRootAttributes[ key ] - ) - ) { - registry.batch( () => { - moveBlocksToPosition( - getBlockOrder( rootClientId ), - rootClientId, - previousRootClientId - ); - removeBlock( rootClientId, false ); - } ); - return; - } - } - - moveFirstItemUp( registry, rootClientId ); - } else { - removeBlock( clientId ); - } - } - }; -} - -function makeOnReplace( registry, clientId ) { - return ( blocks, indexToSelect, initialPosition ) => { - const { replaceBlocks, __unstableMarkLastChangeAsPersistent } = - registry.dispatch( blockEditorStore ); - - if ( - blocks.length && - ! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] ) - ) { - __unstableMarkLastChangeAsPersistent(); - } - //Unsynced patterns are nested in an array so we need to flatten them. - const replacementBlocks = - blocks?.length === 1 && Array.isArray( blocks[ 0 ] ) - ? blocks[ 0 ] - : blocks; - replaceBlocks( - [ clientId ], - replacementBlocks, - indexToSelect, - initialPosition - ); - }; -} - -const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => { - const { updateBlockAttributes, insertBlocks, toggleSelection } = - dispatch( blockEditorStore ); +const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { + const d = unlock( dispatch( blockEditorStore ) ); + const { clientId, rootClientId } = ownProps; // Do not add new properties here, use `useDispatch` instead to avoid // leaking new props to the public API (editor.BlockListBlock filter). return { - setAttributes( newAttributes ) { - const { getMultiSelectedBlockClientIds } = - registry.select( blockEditorStore ); - const multiSelectedBlockClientIds = - getMultiSelectedBlockClientIds(); - const { clientId } = ownProps; - const clientIds = multiSelectedBlockClientIds.length - ? multiSelectedBlockClientIds - : [ clientId ]; - - updateBlockAttributes( clientIds, newAttributes ); - }, - onInsertBlocks( blocks, index ) { - const { rootClientId } = ownProps; - insertBlocks( blocks, index, rootClientId ); - }, - onInsertBlocksAfter( blocks ) { - const { clientId, rootClientId } = ownProps; - const { getBlockIndex } = registry.select( blockEditorStore ); - const index = getBlockIndex( clientId ); - insertBlocks( blocks, index + 1, rootClientId ); - }, - onMerge: makeOnMerge( - registry, - ownProps.clientId, - ownProps.rootClientId - ), - onReplace: makeOnReplace( registry, ownProps.clientId ), - toggleSelection( selectionEnabled ) { - toggleSelection( selectionEnabled ); - }, + setAttributes: ( newAttributes ) => + d.setAttributesEdit( clientId, newAttributes ), + onInsertBlocks: ( blocks, index ) => + d.insertBlocks( blocks, index, rootClientId ), + onInsertBlocksAfter: ( blocks ) => + d.insertBlocksAfterEdit( blocks, clientId, rootClientId ), + onMerge: ( forward ) => d.mergeEdit( clientId, rootClientId, forward ), + onReplace: ( blocks, indexToSelect, initialPos ) => + d.replaceEdit( clientId, blocks, indexToSelect, initialPos ), + toggleSelection: ( selectionEnabled ) => + d.toggleSelection( selectionEnabled ), }; } ); diff --git a/packages/block-editor/src/store/private-actions.js b/packages/block-editor/src/store/private-actions.js index d402d45657704..968476cbba0fd 100644 --- a/packages/block-editor/src/store/private-actions.js +++ b/packages/block-editor/src/store/private-actions.js @@ -1,6 +1,12 @@ /** * WordPress dependencies */ +import { + getDefaultBlockName, + switchToBlockType, + isUnmodifiedDefaultBlock, + isUnmodifiedBlock, +} from '@wordpress/blocks'; import { Platform } from '@wordpress/element'; /** @@ -376,3 +382,223 @@ export function stopDragging() { type: 'STOP_DRAGGING', }; } + +export function setAttributesEdit( clientId, newAttributes ) { + return ( { select, dispatch } ) => { + const multiSelectedBlockClientIds = + select.getMultiSelectedBlockClientIds(); + const clientIds = multiSelectedBlockClientIds.length + ? multiSelectedBlockClientIds + : [ clientId ]; + + dispatch.updateBlockAttributes( clientIds, newAttributes ); + }; +} + +export function insertBlocksAfterEdit( blocks, clientId, rootClientId ) { + return ( { select, dispatch } ) => { + const index = select.getBlockIndex( clientId ); + dispatch.insertBlocks( blocks, index + 1, rootClientId ); + }; +} + +function moveFirstItemUp( clientId, changeSelection = true ) { + return ( { registry, select, dispatch } ) => { + const { + getBlock, + getBlockName, + getBlockOrder, + getBlockIndex, + getBlockRootClientId, + canInsertBlockType, + } = select; + + const blockOrder = getBlockOrder( clientId ); + const [ firstClientId ] = blockOrder; + + if ( + blockOrder.length === 1 && + isUnmodifiedBlock( getBlock( firstClientId ) ) + ) { + dispatch.removeBlock( clientId ); + return; + } + + registry.batch( () => { + const targetRootClientId = getBlockRootClientId( clientId ); + if ( + canInsertBlockType( + getBlockName( firstClientId ), + targetRootClientId + ) + ) { + dispatch.moveBlocksToPosition( + [ firstClientId ], + clientId, + targetRootClientId, + getBlockIndex( clientId ) + ); + } else { + const replacement = switchToBlockType( + getBlock( firstClientId ), + getDefaultBlockName() + ); + + if ( replacement && replacement.length ) { + dispatch.insertBlocks( + replacement, + getBlockIndex( clientId ), + targetRootClientId, + changeSelection + ); + dispatch.removeBlock( firstClientId, false ); + } + } + + if ( + ! getBlockOrder( clientId ).length && + isUnmodifiedBlock( getBlock( clientId ) ) + ) { + dispatch.removeBlock( clientId, false ); + } + } ); + }; +} + +export function mergeEdit( clientId, rootClientId, forward ) { + return ( { registry, select, dispatch } ) => { + const { + getPreviousBlockClientId, + getNextBlockClientId, + getBlockAttributes, + getBlockName, + getBlockOrder, + } = select; + + // For `Delete` or forward merge, we should do the exact same thing + // as `Backspace`, but from the other block. + if ( forward ) { + if ( rootClientId ) { + const nextRootClientId = getNextBlockClientId( rootClientId ); + + if ( nextRootClientId ) { + // If there is a block that follows with the same parent + // block name and the same attributes, merge the inner + // blocks. + if ( + getBlockName( rootClientId ) === + getBlockName( nextRootClientId ) + ) { + const rootAttributes = + getBlockAttributes( rootClientId ); + const previousRootAttributes = + getBlockAttributes( nextRootClientId ); + + if ( + Object.keys( rootAttributes ).every( + ( key ) => + rootAttributes[ key ] === + previousRootAttributes[ key ] + ) + ) { + registry.batch( () => { + dispatch.moveBlocksToPosition( + getBlockOrder( nextRootClientId ), + nextRootClientId, + rootClientId + ); + dispatch.removeBlock( nextRootClientId, false ); + } ); + return; + } + } else { + dispatch.mergeBlocks( rootClientId, nextRootClientId ); + return; + } + } + } + + const nextBlockClientId = getNextBlockClientId( clientId ); + + if ( ! nextBlockClientId ) { + return; + } + + if ( getBlockOrder( nextBlockClientId ).length ) { + dispatch( moveFirstItemUp( nextBlockClientId, false ) ); + } else { + dispatch.mergeBlocks( clientId, nextBlockClientId ); + } + } else { + const previousBlockClientId = getPreviousBlockClientId( clientId ); + + if ( previousBlockClientId ) { + dispatch.mergeBlocks( previousBlockClientId, clientId ); + } else if ( rootClientId ) { + const previousRootClientId = + getPreviousBlockClientId( rootClientId ); + + // If there is a preceding block with the same parent block + // name and the same attributes, merge the inner blocks. + if ( + previousRootClientId && + getBlockName( rootClientId ) === + getBlockName( previousRootClientId ) + ) { + const rootAttributes = getBlockAttributes( rootClientId ); + const previousRootAttributes = + getBlockAttributes( previousRootClientId ); + + if ( + Object.keys( rootAttributes ).every( + ( key ) => + rootAttributes[ key ] === + previousRootAttributes[ key ] + ) + ) { + registry.batch( () => { + dispatch.moveBlocksToPosition( + getBlockOrder( rootClientId ), + rootClientId, + previousRootClientId + ); + dispatch.removeBlock( rootClientId, false ); + } ); + return; + } + } + + dispatch( moveFirstItemUp( rootClientId ) ); + } else { + dispatch.removeBlock( clientId ); + } + } + }; +} + +export function replaceEdit( + clientId, + blocks, + indexToSelect, + initialPosition +) { + return ( { dispatch } ) => { + if ( + blocks.length && + ! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] ) + ) { + dispatch.__unstableMarkLastChangeAsPersistent(); + } + //Unsynced patterns are nested in an array so we need to flatten them. + const replacementBlocks = + blocks?.length === 1 && Array.isArray( blocks[ 0 ] ) + ? blocks[ 0 ] + : blocks; + dispatch.replaceBlocks( + [ clientId ], + replacementBlocks, + indexToSelect, + initialPosition + ); + }; +} From c5e643a50da2960bc5efbfa3a9bf2e79997ee04c Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 4 Mar 2024 14:17:08 +0100 Subject: [PATCH 24/27] List e2e tests: fix a typo in name --- test/e2e/specs/editor/blocks/list.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/list.spec.js b/test/e2e/specs/editor/blocks/list.spec.js index 10f25d6b3609f..850dba7449ef6 100644 --- a/test/e2e/specs/editor/blocks/list.spec.js +++ b/test/e2e/specs/editor/blocks/list.spec.js @@ -680,7 +680,7 @@ test.describe( 'List (@firefox)', () => { ); } ); - test( 'should be immeadiately saved on indentation', async ( { + test( 'should be immediately saved on indentation', async ( { editor, page, } ) => { From fbf5ac9ddbc565f5fa06e2cc8247a2b5387a7180 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 4 Mar 2024 14:18:21 +0100 Subject: [PATCH 25/27] Don't modify state when setting identical selection --- packages/block-editor/src/store/reducer.js | 89 ++++++++++++---------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index ef2183981c707..64efca4e06e89 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1336,14 +1336,14 @@ function selectionHelper( state = {}, action ) { if ( ! action.clientIds || ! action.clientIds.length || - action.clientIds.indexOf( state.clientId ) === -1 + ! action.clientIds.includes( state.clientId ) ) { return state; } return {}; case 'REPLACE_BLOCKS': { - if ( action.clientIds.indexOf( state.clientId ) === -1 ) { + if ( ! action.clientIds.includes( state.clientId ) ) { return state; } @@ -1366,6 +1366,20 @@ function selectionHelper( state = {}, action ) { return state; } +function selectionEqual( sel1, sel2 ) { + if ( sel1 === sel2 ) { + return true; + } + if ( ! sel1 || ! sel2 ) { + return false; + } + return ( + sel1.clientId === sel2.clientId && + sel1.attributeKey === sel2.attributeKey && + sel1.offset === sel2.offset + ); +} + /** * Reducer returning the selection state. * @@ -1375,33 +1389,30 @@ function selectionHelper( state = {}, action ) { * @return {boolean} Updated state. */ export function selection( state = {}, action ) { + let { selectionStart, selectionEnd } = state; + switch ( action.type ) { case 'SELECTION_CHANGE': if ( action.clientId ) { - return { - selectionStart: { - clientId: action.clientId, - attributeKey: action.attributeKey, - offset: action.startOffset, - }, - selectionEnd: { - clientId: action.clientId, - attributeKey: action.attributeKey, - offset: action.endOffset, - }, + selectionStart = { + clientId: action.clientId, + attributeKey: action.attributeKey, + offset: action.startOffset, + }; + selectionEnd = { + clientId: action.clientId, + attributeKey: action.attributeKey, + offset: action.endOffset, }; + } else { + selectionStart = action.start || selectionStart; + selectionEnd = action.end || selectionEnd; } - - return { - selectionStart: action.start || state.selectionStart, - selectionEnd: action.end || state.selectionEnd, - }; + break; case 'RESET_SELECTION': - const { selectionStart, selectionEnd } = action; - return { - selectionStart, - selectionEnd, - }; + selectionStart = action.selectionStart; + selectionEnd = action.selectionEnd; + break; case 'MULTI_SELECT': const { start, end } = action; @@ -1412,10 +1423,9 @@ export function selection( state = {}, action ) { return state; } - return { - selectionStart: { clientId: start }, - selectionEnd: { clientId: end }, - }; + selectionStart = { clientId: start }; + selectionEnd = { clientId: end }; + break; case 'RESET_BLOCKS': const startClientId = state?.selectionStart?.clientId; const endClientId = state?.selectionEnd?.clientId; @@ -1431,31 +1441,26 @@ export function selection( state = {}, action ) { ( block ) => block.clientId === startClientId ) ) { - return { - selectionStart: {}, - selectionEnd: {}, - }; + selectionStart = {}; + selectionEnd = {}; } - // If the end of the selection won't exist after reset, collapse selection. - if ( + else if ( ! action.blocks.some( ( block ) => block.clientId === endClientId ) ) { - return { - ...state, - selectionEnd: state.selectionStart, - }; + selectionEnd = selectionStart; } + break; + default: + selectionStart = selectionHelper( state.selectionStart, action ); + selectionEnd = selectionHelper( state.selectionEnd, action ); } - const selectionStart = selectionHelper( state.selectionStart, action ); - const selectionEnd = selectionHelper( state.selectionEnd, action ); - if ( - selectionStart === state.selectionStart && - selectionEnd === state.selectionEnd + selectionEqual( selectionStart, state.selectionStart ) && + selectionEqual( selectionEnd, state.selectionEnd ) ) { return state; } From 67862ad9b5223f351c5d3decae7029d2c4fb2750 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 6 Mar 2024 10:41:04 +0100 Subject: [PATCH 26/27] synchronizeBlocksWithTemplate: extract common functions --- packages/blocks/src/api/templates.js | 71 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/blocks/src/api/templates.js b/packages/blocks/src/api/templates.js index bc76218892688..e470ac2a5c3ed 100644 --- a/packages/blocks/src/api/templates.js +++ b/packages/blocks/src/api/templates.js @@ -31,6 +31,41 @@ export function doBlocksMatchTemplate( blocks = [], template = [] ) { ); } +const isHTMLAttribute = ( attributeDefinition ) => + attributeDefinition?.source === 'html'; +const isQueryAttribute = ( attributeDefinition ) => + attributeDefinition?.source === 'query'; + +const normalizeAttributes = ( schema, values ) => { + if ( ! values ) { + return {}; + } + + return Object.fromEntries( + Object.entries( values ).map( ( [ key, value ] ) => [ + key, + normalizeAttribute( schema[ key ], value ), + ] ) + ); +}; + +const normalizeAttribute = ( definition, value ) => { + if ( isHTMLAttribute( definition ) && Array.isArray( value ) ) { + // Introduce a deprecated call at this point + // When we're confident that "children" format should be removed from the templates. + + return renderToString( value ); + } + + if ( isQueryAttribute( definition ) && value ) { + return value.map( ( subValues ) => { + return normalizeAttributes( definition.query, subValues ); + } ); + } + + return value; +}; + /** * Synchronize a block list with a block template. * @@ -67,42 +102,6 @@ export function synchronizeBlocksWithTemplate( blocks = [], template ) { // before creating the blocks. const blockType = getBlockType( name ); - const isHTMLAttribute = ( attributeDefinition ) => - attributeDefinition?.source === 'html'; - const isQueryAttribute = ( attributeDefinition ) => - attributeDefinition?.source === 'query'; - - const normalizeAttributes = ( schema, values ) => { - if ( ! values ) { - return {}; - } - - return Object.fromEntries( - Object.entries( values ).map( ( [ key, value ] ) => [ - key, - normalizeAttribute( schema[ key ], value ), - ] ) - ); - }; - const normalizeAttribute = ( definition, value ) => { - if ( isHTMLAttribute( definition ) && Array.isArray( value ) ) { - // Introduce a deprecated call at this point - // When we're confident that "children" format should be removed from the templates. - - return renderToString( value ); - } - - if ( isQueryAttribute( definition ) && value ) { - return value.map( ( subValues ) => { - return normalizeAttributes( - definition.query, - subValues - ); - } ); - } - - return value; - }; const normalizedAttributes = normalizeAttributes( blockType?.attributes ?? {}, From b007e3c974e94a578ce4c3d2e9e5ab85d9b1b9e5 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 6 Mar 2024 10:42:09 +0100 Subject: [PATCH 27/27] Universal edit placeholder --- .../block-editor/src/autocompleters/block.js | 3 +- .../src/components/block-edit/edit.js | 85 +++++++++++- .../src/components/rich-text/index.js | 128 +++++++++--------- .../components/rich-text/use-input-rules.js | 86 +++++------- packages/block-editor/src/store/selectors.js | 9 +- packages/block-editor/src/utils/dom.js | 8 +- packages/block-library/src/list/index.js | 1 + packages/blocks/src/api/utils.js | 10 +- 8 files changed, 204 insertions(+), 126 deletions(-) diff --git a/packages/block-editor/src/autocompleters/block.js b/packages/block-editor/src/autocompleters/block.js index bc06c9de5aaaf..c9b74b55f7e7d 100644 --- a/packages/block-editor/src/autocompleters/block.js +++ b/packages/block-editor/src/autocompleters/block.js @@ -121,6 +121,7 @@ function createBlockCompleter() { name, initialAttributes, innerBlocks, + template, syncStatus, content, } = inserterItem; @@ -136,7 +137,7 @@ function createBlockCompleter() { name, initialAttributes, createBlocksFromInnerBlocksTemplate( - innerBlocks + innerBlocks || template ) ), }; diff --git a/packages/block-editor/src/components/block-edit/edit.js b/packages/block-editor/src/components/block-edit/edit.js index bada583c63b4b..f710fb0f57be9 100644 --- a/packages/block-editor/src/components/block-edit/edit.js +++ b/packages/block-editor/src/components/block-edit/edit.js @@ -13,12 +13,16 @@ import { getBlockType, getBlockEdit, } from '@wordpress/blocks'; -import { useContext, useMemo } from '@wordpress/element'; +import { AsyncModeProvider, useDispatch, useSelect } from '@wordpress/data'; +import { useContext, useMemo, useRef } from '@wordpress/element'; /** * Internal dependencies */ import BlockContext from '../block-context'; +import RichText from '../rich-text'; +import { store as blockEditorStore } from '../../store'; +import { unlock } from '../../lock-unlock'; /** * Default value used for blocks which do not define their own context needs, @@ -30,6 +34,83 @@ import BlockContext from '../block-context'; */ const DEFAULT_BLOCK_CONTEXT = {}; +function useSelectedChildBlock( clientId ) { + return useSelect( + ( select ) => { + const { + getSelectionStart, + isBlockSelected, + hasSelectedInnerBlock, + getBlockAttributes, + getBlockName, + } = select( blockEditorStore ); + + const isSelected = + isBlockSelected( clientId ) || + hasSelectedInnerBlock( clientId, true ); + + if ( ! isSelected ) { + return { + selClientId: null, + selBlockName: null, + selContent: undefined, + }; + } + + const sClientId = getSelectionStart().clientId; + return { + selClientId: sClientId, + selBlockName: getBlockName( sClientId ), + selContent: getBlockAttributes( sClientId ).content, + }; + }, + [ clientId ] + ); +} +function FallbackRichEdit( { clientId } ) { + const ref = useRef(); + const { selClientId, selBlockName, selContent } = + useSelectedChildBlock( clientId ); + const { updateBlockAttributes, replaceEdit } = unlock( + useDispatch( blockEditorStore ) + ); + + if ( ! selClientId ) { + return null; + } + + const onChange = ( value ) => + updateBlockAttributes( [ selClientId ], { content: value } ); + + const onReplace = ( blocks, indexToSelect, initialPos ) => + replaceEdit( selClientId, blocks, indexToSelect, initialPos ); + + return ( +
+ +
+ ); +} + +function FallbackEdit( { clientId } ) { + return ( + + + + ); +} + const Edit = ( props ) => { const { name } = props; const blockType = getBlockType( name ); @@ -39,7 +120,7 @@ const Edit = ( props ) => { return null; } - return ; + return ; }; const EditWithFilters = withFilters( 'editor.BlockEdit' )( Edit ); diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 3d1725c54fe71..645553a8e124f 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -89,6 +89,8 @@ export function RichTextWrapper( tagName = 'div', value: adjustedValue = '', onChange: adjustedOnChange, + clientId: originalClientId, + blockName: originalBlockName, isSelected: originalIsSelected, multiline, inlineToolbar, @@ -116,20 +118,18 @@ export function RichTextWrapper( forwardedRef ) { props = removeNativeProps( props ); - - const anchorRef = useRef(); const context = useBlockEditContext(); - const { clientId, isSelected: isBlockSelected, name: blockName } = context; - const blockBindings = context[ blockBindingsKey ]; + const clientId = originalClientId ?? context.clientId; + const blockName = originalBlockName ?? context.blockName; + const selector = ( select ) => { - // Avoid subscribing to the block editor store if the block is not - // selected. - if ( ! isBlockSelected ) { + const { isBlockSelected, getSelectionStart, getSelectionEnd } = + select( blockEditorStore ); + + if ( ! isBlockSelected( clientId ) ) { return { isSelected: false }; } - const { getSelectionStart, getSelectionEnd } = - select( blockEditorStore ); const selectionStart = getSelectionStart(); const selectionEnd = getSelectionEnd(); @@ -140,8 +140,9 @@ export function RichTextWrapper( selectionStart.clientId === clientId && selectionEnd.clientId === clientId && selectionStart.attributeKey === identifier; - } else if ( originalIsSelected ) { - isSelected = selectionStart.clientId === clientId; + } else { + isSelected = + originalIsSelected && selectionStart.clientId === clientId; } return { @@ -154,9 +155,9 @@ export function RichTextWrapper( clientId, identifier, originalIsSelected, - isBlockSelected, ] ); + const blockBindings = context[ blockBindingsKey ]; const disableBoundBlocks = useSelect( ( select ) => { // Disable Rich Text editing if block bindings specify that. @@ -333,11 +334,61 @@ export function RichTextWrapper( const keyboardShortcuts = useRef( new Set() ); const inputEvents = useRef( new Set() ); + const anchorRef = useRef(); function onFocus() { anchorRef.current?.focus(); } + const textRef = useMergeRefs( [ + // Rich text ref must be first because its focus listener + // must be set up before any other ref calls .focus() on + // mount. + richTextRef, + forwardedRef, + autocompleteProps.ref, + props.ref, + useBeforeInputRules( { value, onChange } ), + useInputRules( { + getValue, + onChange, + __unstableAllowPrefixTransformations, + formatTypes, + onReplace, + selectionChange, + } ), + useInsertReplacementText(), + useRemoveBrowserShortcuts(), + useShortcuts( keyboardShortcuts ), + useInputEvents( inputEvents ), + useUndoAutomaticChange(), + usePasteHandler( { + isSelected, + disableFormats, + onChange, + value, + formatTypes, + tagName, + onReplace, + onSplit, + __unstableEmbedURLOnPaste, + pastePlainText, + } ), + useDelete( { value, onMerge, onRemove } ), + useEnter( { + removeEditorOnlyFormats, + value, + onReplace, + onSplit, + onChange, + disableLineBreaks, + onSplitAtEnd, + onSplitAtDoubleLineEnd, + } ), + useFirefoxCompat(), + anchorRef, + ] ); + const TagName = tagName; return ( <> @@ -373,58 +424,7 @@ export function RichTextWrapper( aria-readonly={ shouldDisableEditing } { ...props } { ...autocompleteProps } - ref={ useMergeRefs( [ - // Rich text ref must be first because its focus listener - // must be set up before any other ref calls .focus() on - // mount. - richTextRef, - forwardedRef, - autocompleteProps.ref, - props.ref, - useBeforeInputRules( { value, onChange } ), - useInputRules( { - getValue, - onChange, - __unstableAllowPrefixTransformations, - formatTypes, - onReplace, - selectionChange, - } ), - useInsertReplacementText(), - useRemoveBrowserShortcuts(), - useShortcuts( keyboardShortcuts ), - useInputEvents( inputEvents ), - useUndoAutomaticChange(), - usePasteHandler( { - isSelected, - disableFormats, - onChange, - value, - formatTypes, - tagName, - onReplace, - onSplit, - __unstableEmbedURLOnPaste, - pastePlainText, - } ), - useDelete( { - value, - onMerge, - onRemove, - } ), - useEnter( { - removeEditorOnlyFormats, - value, - onReplace, - onSplit, - onChange, - disableLineBreaks, - onSplitAtEnd, - onSplitAtDoubleLineEnd, - } ), - useFirefoxCompat(), - anchorRef, - ] ) } + ref={ textRef } contentEditable={ ! shouldDisableEditing } suppressContentEditableWarning className={ classnames( diff --git a/packages/block-editor/src/components/rich-text/use-input-rules.js b/packages/block-editor/src/components/rich-text/use-input-rules.js index bfcb38783fee3..b4c2c133c84ea 100644 --- a/packages/block-editor/src/components/rich-text/use-input-rules.js +++ b/packages/block-editor/src/components/rich-text/use-input-rules.js @@ -4,11 +4,7 @@ import { useRef } from '@wordpress/element'; import { useRefEffect } from '@wordpress/compose'; import { remove, toHTMLString } from '@wordpress/rich-text'; -import { - getBlockTransforms, - findTransform, - lazyLoadBlock, -} from '@wordpress/blocks'; +import { getBlockTransforms, findTransform } from '@wordpress/blocks'; import { useDispatch } from '@wordpress/data'; /** @@ -49,12 +45,8 @@ function findPrefixTransform( prefixText ) { return findTransform( prefixTransforms, ( t ) => t.prefix === prefixText ); } -function inputRule( props, ctx, onReplace ) { - const { getValue, onChange, selectionChange } = props; - - if ( ! ctx.inserterActive ) { - return; - } +function inputRule( props, onReplace ) { + const { getValue, selectionChange } = props; // We must use getValue() here because value may be update // asynchronously. @@ -73,37 +65,29 @@ function inputRule( props, ctx, onReplace ) { return; } - // remove the prefix string from the input because it's going to be processed by the transform - onChange( remove( value, 0, start ) ); - const block = transformation.transform( START_OF_SELECTED_AREA ); const selection = findSelection( [ block ] ); if ( selection ) { - ctx.inserterActive = selection[ 0 ].name === 'core/paragraph'; + const [ selectedBlock, selectedAttribute ] = selection; + // To do: refactor this to use rich text's selection instead, so + // we no longer have to use on this hack inserting a special + // character. + const newValue = selectedBlock.attributes[ selectedAttribute ] + .toString() + .replace( + START_OF_SELECTED_AREA, + toHTMLString( { value: remove( value, 0, start ) } ) + ); + + selectedBlock.attributes[ selectedAttribute ] = newValue; + selectionChange( + selectedBlock.clientId, + selectedAttribute, + newValue.length, + newValue.length + ); } - lazyLoadBlock( block ) - // .then( () => new Promise( ( r ) => setTimeout( r, 1000 ) ) ) - .then( () => { - if ( selection ) { - const [ selectedBlock, selectedAttribute ] = selection; - const valueStr = toHTMLString( { value: getValue() } ); - // To do: refactor this to use rich text's selection instead, so - // we no longer have to use on this hack inserting a special - // character. - const newValue = selectedBlock.attributes[ selectedAttribute ] - .toString() - .replace( START_OF_SELECTED_AREA, valueStr ); - - selectedBlock.attributes[ selectedAttribute ] = newValue; - selectionChange( - selectedBlock.clientId, - selectedAttribute, - newValue.length, - newValue.length - ); - } - onReplace( [ block ] ); - } ); + onReplace( [ block ] ); return true; } @@ -117,15 +101,16 @@ export function useInputRules( props ) { const propsRef = useRef( props ); propsRef.current = props; - const transformCtxRef = useRef( { - inserterActive: props.__unstableAllowPrefixTransformations, - } ); - return useRefEffect( ( element ) => { function onInput( event ) { const { inputType, type } = event; - const { getValue, onChange, onReplace, formatTypes } = - propsRef.current; + const { + getValue, + onChange, + onReplace, + formatTypes, + __unstableAllowPrefixTransformations, + } = propsRef.current; // Only run input rules when inserting text. if ( inputType !== 'insertText' && type !== 'compositionend' ) { @@ -134,14 +119,11 @@ export function useInputRules( props ) { if ( onReplace && - inputRule( - propsRef.current, - transformCtxRef.current, - ( blocks ) => { - onReplace( blocks ); - __unstableMarkAutomaticChange(); - } - ) + __unstableAllowPrefixTransformations && + inputRule( propsRef.current, ( blocks ) => { + onReplace( blocks ); + __unstableMarkAutomaticChange(); + } ) ) { return; } diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 8f2e5e4e5ccc8..6fb6d4cc12aef 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1565,9 +1565,9 @@ const canInsertBlockTypeUnmemoized = ( // The parent block doesn't have settings indicating it doesn't support // inner blocks, return false. - if ( rootClientId && parentBlockListSettings === undefined ) { - return false; - } + // if ( rootClientId && parentBlockListSettings === undefined ) { + // return false; + // } const parentName = getBlockName( state, rootClientId ); const parentBlockType = getBlockType( parentName ); @@ -1862,7 +1862,7 @@ const getItemFromVariation = ( state, item ) => ( variation ) => { ...item.initialAttributes, ...variation.attributes, }, - innerBlocks: variation.innerBlocks, + innerBlocks: variation.innerBlocks || item.template, keywords: variation.keywords || item.keywords, frecency: calculateFrecency( time, count ), }; @@ -1944,6 +1944,7 @@ const buildBlockTypeItem = keywords: blockType.keywords, variations: inserterVariations, example: blockType.example, + template: blockType.template, utility: 1, // Deprecated. }; }; diff --git a/packages/block-editor/src/utils/dom.js b/packages/block-editor/src/utils/dom.js index 6af35aff73015..c5f409a66a6f6 100644 --- a/packages/block-editor/src/utils/dom.js +++ b/packages/block-editor/src/utils/dom.js @@ -1,3 +1,4 @@ +const BLOCK_PLACEHOLDER = '.block-placeholder'; const BLOCK_SELECTOR = '.block-editor-block-list__block'; const APPENDER_SELECTOR = '.block-list-appender'; const BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender'; @@ -26,7 +27,12 @@ export function isInSameBlock( a, b ) { */ export function isInsideRootBlock( blockElement, element ) { const parentBlock = element.closest( - [ BLOCK_SELECTOR, APPENDER_SELECTOR, BLOCK_APPENDER_CLASS ].join( ',' ) + [ + BLOCK_PLACEHOLDER, + BLOCK_SELECTOR, + APPENDER_SELECTOR, + BLOCK_APPENDER_CLASS, + ].join( ',' ) ); return parentBlock === blockElement; } diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index b51e34b7c4c2c..1ef477f6dd52c 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -44,6 +44,7 @@ const settings = { }, ], }, + template: [ [ 'core/list-item' ] ], transforms, lazyEdit: () => import( /* webpackChunkName: "list/editor" */ './edit' ), save, diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index 6e2b76d86043e..266539215880d 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -355,10 +355,16 @@ export function omit( object, keys ) { export function lazyEdit( cb ) { // eslint-disable-next-line @wordpress/no-unused-vars-before-return - const Load = lazy( cb ); + const Load = lazy( () => + cb().then( + ( i ) => new Promise( ( r ) => setTimeout( () => r( i ), 2000 ) ) + ) + ); + return function Edit( props ) { + const { FallbackEdit, clientId } = props; return ( - + }> );