From b39996616c33de90bb82e3d7a009c865cf2b0f0c Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Tue, 8 Aug 2023 22:17:09 +0300 Subject: [PATCH] chore(perf): initialisation and rendering performance optimisations (#2430) * renderer batching * initialization and rendering performance optimized * insertMany api method added * Update index.html * rm old method * upd changelog * upd paragraph * paste tests fixed * api blocks tests fixed * backspace event tests fixed * async issues in tests fixed * eslint * stub block added, tests added * eslint * eslint * add test for insertMany() * Update package.json --- cypress.config.ts | 15 +- docs/CHANGELOG.md | 11 +- index.html | 2 + package.json | 5 +- src/components/block/index.ts | 19 +- src/components/blocks.ts | 38 ++++ src/components/core.ts | 40 ++-- src/components/modules/api/blocks.ts | 58 +++++- src/components/modules/blockEvents.ts | 10 +- src/components/modules/blockManager.ts | 94 ++++++--- src/components/modules/caret.ts | 17 +- src/components/modules/paste.ts | 9 +- src/components/modules/renderer.ts | 182 ++++++++---------- src/components/modules/saver.ts | 22 +-- src/components/modules/toolbar/index.ts | 62 ++++-- src/components/modules/toolbar/inline.ts | 9 +- src/components/modules/ui.ts | 35 +--- src/components/polyfills.ts | 24 +++ src/components/selection.ts | 2 +- src/components/utils.ts | 1 + src/components/utils/events.ts | 8 +- src/components/utils/promise-queue.ts | 28 +++ src/styles/stub.css | 29 ++- src/styles/ui.css | 50 +---- src/tools/stub/index.ts | 3 +- test/cypress/.eslintrc | 4 +- test/cypress/support/commands.ts | 13 +- test/cypress/support/index.ts | 3 + test/cypress/tests/api/blocks.cy.ts | 167 +++++++++------- test/cypress/tests/block-ids.cy.ts | 55 +++--- test/cypress/tests/copy-paste.cy.ts | 116 ++++++----- test/cypress/tests/i18n.cy.ts | 3 +- .../tests/modules/BlockEvents/Backspace.cy.ts | 6 +- .../tests/modules/BlockEvents/Enter.cy.ts | 3 - test/cypress/tests/modules/Renderer.cy.ts | 149 ++++++++++++++ test/cypress/tests/onchange.cy.ts | 83 +++++++- test/cypress/tests/sanitisation.cy.ts | 62 +++--- test/cypress/tests/utils/flipper.cy.ts | 36 ++-- types/api/blocks.d.ts | 11 +- vite.config.js | 2 +- yarn.lock | 36 +++- 41 files changed, 991 insertions(+), 531 deletions(-) create mode 100644 src/components/utils/promise-queue.ts create mode 100644 test/cypress/tests/modules/Renderer.cy.ts diff --git a/cypress.config.ts b/cypress.config.ts index ed2c10f0..11ac2de2 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -11,9 +11,22 @@ export default defineConfig({ // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. setupNodeEvents(on, config) { - return require('./test/cypress/plugins/index.ts')(on, config); + /** + * Plugin for cypress that adds better terminal output for easier debugging. + * Prints cy commands, browser console logs, cy.request and cy.intercept data. Great for your pipelines. + * https://github.com/archfz/cypress-terminal-report + */ + require('cypress-terminal-report/src/installLogsPrinter')(on); + + require('./test/cypress/plugins/index.ts')(on, config); }, specPattern: 'test/cypress/tests/**/*.cy.{js,jsx,ts,tsx}', supportFile: 'test/cypress/support/index.ts', }, + 'retries': { + // Configure retry attempts for `cypress run` + 'runMode': 2, + // Configure retry attempts for `cypress open` + 'openMode': 0, + }, }); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6600d997..daaaee87 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,12 +3,21 @@ ### 2.28.0 - `New` - Block ids now displayed in DOM via a data-id attribute. Could be useful for plugins that want access a Block's element by id. -- `New` - The `.convert(blockId, newType)` API method added +- `New` - The `blocks.convert(blockId, newType)` API method added. It allows to convert existed Block to a Block of another type. +- `New` - The `blocks.insertMany()` API method added. It allows to insert several Blocks to specified index. - `Improvement` - The Delete keydown at the end of the Block will now work opposite a Backspace at the start. Next Block will be removed (if empty) or merged with the current one. - `Improvement` - The Delete keydown will work like a Backspace when several Blocks are selected. - `Improvement` - If we have two empty Blocks, and press Backspace at the start of the second one, the previous will be removed instead of current. - `Improvement` - Tools shortcuts could be used to convert one Block to another. - `Improvement` - Tools shortcuts displayed in the Conversion Toolbar +- `Improvement` - Initialization Loader has been removed. +- `Improvement` - Selection style won't override your custom style for `::selection` outside the editor. +- `Improvement` - Performance optimizations: initialization speed increased, `blocks.render()` API method optimized. Big documents will be displayed faster. +- `Improvement` - "Editor saving" log removed +- `Improvement` - "I'm ready" log removed +- `Improvement` - The stub-block style simplified. +- `Improvement` - If some Block's tool will throw an error during construction, we will show Stub block instead of skipping it during render +- `Improvement` - Call of `blocks.clear()` now will trigger onChange will "block-removed" event for all removed blocks. ### 2.27.2 diff --git a/index.html b/index.html index 43c8b4ae..03037f39 100644 --- a/index.html +++ b/index.html @@ -404,6 +404,8 @@ localStorage.setItem('theme', document.body.classList.contains("dark-mode") ? 'dark' : 'default'); }) + + window.editor = editor; diff --git a/package.json b/package.json index bbb0329f..d5540e50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/editorjs", - "version": "2.28.0-rc.1", + "version": "2.28.0-rc.2", "description": "Editor.js — Native JS, based on API and Open Source", "main": "dist/editorjs.umd.js", "module": "dist/editorjs.mjs", @@ -44,7 +44,7 @@ "@editorjs/code": "^2.7.0", "@editorjs/delimiter": "^1.2.0", "@editorjs/header": "^2.7.0", - "@editorjs/paragraph": "^2.9.0", + "@editorjs/paragraph": "^2.10.0", "@editorjs/simple-image": "^1.4.1", "@types/node": "^18.15.11", "chai-subset": "^1.6.0", @@ -53,6 +53,7 @@ "core-js": "3.30.0", "cypress": "^12.9.0", "cypress-intellij-reporter": "^0.0.7", + "cypress-terminal-report": "^5.3.2", "eslint": "^8.37.0", "eslint-config-codex": "^1.7.1", "eslint-plugin-chai-friendly": "^0.7.2", diff --git a/src/components/block/index.ts b/src/components/block/index.ts index d568f25d..b47fe781 100644 --- a/src/components/block/index.ts +++ b/src/components/block/index.ts @@ -252,15 +252,20 @@ export default class Block extends EventsDispatcher { this.holder = this.compose(); /** - * Start watching block mutations + * Bind block events in RIC for optimizing of constructing process time */ - this.watchBlockMutations(); + window.requestIdleCallback(() => { + /** + * Start watching block mutations + */ + this.watchBlockMutations(); - /** - * Mutation observer doesn't track changes in "" and "