From 40c05173a935a9ec319d95f0fad640c43db5e560 Mon Sep 17 00:00:00 2001 From: Ilya Moroz <37909603+ilyamore88@users.noreply.github.com> Date: Thu, 13 Jan 2022 00:46:07 +0300 Subject: [PATCH 1/2] [Fix] isFunction function for async functions (#1857) * fix test of async function, fix TS type because Function is banned type * add tests for isFunction function * fix eslint * add changelog for 2.23.1 * fix changelog * fix changelog --- docs/CHANGELOG.md | 1 + src/components/utils.ts | 4 +- test/cypress/tests/utils.spec.ts | 63 ++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/cypress/tests/utils.spec.ts diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 52adf8fc..e9a4f930 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -20,6 +20,7 @@ - `New` — `API` — The new `UiApi` section was added. It allows accessing some editor UI nodes and methods. - `Refactoring` — Toolbox became a standalone class instead of a Module. It can be accessed only through the Toolbar module. - `Refactoring` — CI flow optimized. +- `Fix` - Recognize async `onPaste` handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803). ### 2.22.3 diff --git a/src/components/utils.ts b/src/components/utils.ts index 8b402bbf..e1e756f6 100644 --- a/src/components/utils.ts +++ b/src/components/utils.ts @@ -194,8 +194,8 @@ export function typeOf(object: any): string { * @returns {boolean} */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isFunction(fn: any): fn is Function { - return typeOf(fn) === 'function'; +export function isFunction(fn: any): fn is (...args: any[]) => any { + return typeOf(fn) === 'function' || typeOf(fn) === 'asyncfunction'; } /** diff --git a/test/cypress/tests/utils.spec.ts b/test/cypress/tests/utils.spec.ts new file mode 100644 index 00000000..bb0cb51a --- /dev/null +++ b/test/cypress/tests/utils.spec.ts @@ -0,0 +1,63 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +import { isFunction } from '../../../src/components/utils'; + +function syncFunction(): void {} + +async function asyncFunction(): Promise {} + +const syncArrowFunction = (): void => {}; + +const asyncArrowFunction = async (): Promise => {}; + +describe('isFunction function', () => { + it('should recognise sync functions', () => { + /** + * Act + */ + const commonFunctionResult = isFunction(syncFunction); + const arrowFunctionResult = isFunction(syncArrowFunction); + + /** + * Assert + */ + expect(commonFunctionResult).to.eq(true); + expect(arrowFunctionResult).to.eq(true); + }); + + it('should recognise async functions', () => { + /** + * Act + */ + const commonFunctionResult = isFunction(asyncFunction); + const arrowFunctionResult = isFunction(asyncArrowFunction); + + /** + * Assert + */ + expect(commonFunctionResult).to.eq(true); + expect(arrowFunctionResult).to.eq(true); + }); + + it('should return false if it isn\'t a function', () => { + /** + * Arrange + */ + const obj = {}; + const num = 123; + const str = '123'; + + /** + * Act + */ + const objResult = isFunction(obj); + const numResult = isFunction(num); + const strResult = isFunction(str); + + /** + * Assert + */ + expect(objResult).to.eq(false); + expect(numResult).to.eq(false); + expect(strResult).to.eq(false); + }); +}); From 95141f0a2d1ab6fd3f689d52f54f4196995210cd Mon Sep 17 00:00:00 2001 From: Ilya Moroz <37909603+ilyamore88@users.noreply.github.com> Date: Thu, 13 Jan 2022 18:15:40 +0300 Subject: [PATCH 2/2] commit new submodules versions (#1858) --- example/tools/checklist | 2 +- example/tools/code | 2 +- example/tools/delimiter | 2 +- example/tools/embed | 2 +- example/tools/header | 2 +- example/tools/image | 2 +- example/tools/inline-code | 2 +- example/tools/link | 2 +- example/tools/list | 2 +- example/tools/marker | 2 +- example/tools/quote | 2 +- example/tools/raw | 2 +- example/tools/simple-image | 2 +- example/tools/table | 2 +- example/tools/warning | 2 +- src/tools/paragraph | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/example/tools/checklist b/example/tools/checklist index 6e81175e..a0aefce6 160000 --- a/example/tools/checklist +++ b/example/tools/checklist @@ -1 +1 @@ -Subproject commit 6e81175e48038d1244b9fc63fc8ecd49d6335a56 +Subproject commit a0aefce6bdc9819fa71649a3d042b15a28a8f344 diff --git a/example/tools/code b/example/tools/code index cd102da6..b4f252d1 160000 --- a/example/tools/code +++ b/example/tools/code @@ -1 +1 @@ -Subproject commit cd102da627f5138b94d960ace16fb1a62e1c8069 +Subproject commit b4f252d112a524e53e1f9c960746a61569eaae28 diff --git a/example/tools/delimiter b/example/tools/delimiter index a98f8005..48bf650e 160000 --- a/example/tools/delimiter +++ b/example/tools/delimiter @@ -1 +1 @@ -Subproject commit a98f800569c4d952caec16cb527b65b6f2b3b589 +Subproject commit 48bf650eadbb894606f3428d2fb30add022ad2b7 diff --git a/example/tools/embed b/example/tools/embed index a765a45e..b3c87948 160000 --- a/example/tools/embed +++ b/example/tools/embed @@ -1 +1 @@ -Subproject commit a765a45ec03a9ed5529dac0b3a03ff0a1e16f3b3 +Subproject commit b3c87948d5a5926f2557c2029d64aa819ca61920 diff --git a/example/tools/header b/example/tools/header index 491ada2f..585bca27 160000 --- a/example/tools/header +++ b/example/tools/header @@ -1 +1 @@ -Subproject commit 491ada2f1653de52cfaac6130244736f57f7afde +Subproject commit 585bca271f7696cd17533fa5877d1f72b3a03d2e diff --git a/example/tools/image b/example/tools/image index e3df500f..7edabc57 160000 --- a/example/tools/image +++ b/example/tools/image @@ -1 +1 @@ -Subproject commit e3df500fc62a88d3490fa4ba4030c07f0cd79d64 +Subproject commit 7edabc571ed4b5975b73073a9eaed857f0f10592 diff --git a/example/tools/inline-code b/example/tools/inline-code index 145be45a..3722d145 160000 --- a/example/tools/inline-code +++ b/example/tools/inline-code @@ -1 +1 @@ -Subproject commit 145be45a4fe991a40d3fdd99d275ef211116e6ee +Subproject commit 3722d145b02880fdd5b5792bdd6a9475284559bc diff --git a/example/tools/link b/example/tools/link index f3d72358..d452b461 160000 --- a/example/tools/link +++ b/example/tools/link @@ -1 +1 @@ -Subproject commit f3d72358b5a35e7fde58b08604b57eea2c4fa8ff +Subproject commit d452b46106766b5fc4c5747e99888f613a3764fd diff --git a/example/tools/list b/example/tools/list index cce71dc4..004a0645 160000 --- a/example/tools/list +++ b/example/tools/list @@ -1 +1 @@ -Subproject commit cce71dc42bdc9df04f5c3efefc48217126e483c5 +Subproject commit 004a06458d3881e8d922506381c21847900e3c62 diff --git a/example/tools/marker b/example/tools/marker index 3f388a64..40ef7e3a 160000 --- a/example/tools/marker +++ b/example/tools/marker @@ -1 +1 @@ -Subproject commit 3f388a64f92b408038eb1ab3db0c588dfb2b58ec +Subproject commit 40ef7e3adc32dea1762ffe4fa75f90c6ad8af7cc diff --git a/example/tools/quote b/example/tools/quote index fbccf7e3..d781cd0d 160000 --- a/example/tools/quote +++ b/example/tools/quote @@ -1 +1 @@ -Subproject commit fbccf7e35e1ca7a3b7b04422fbdfc10634302d1c +Subproject commit d781cd0d5c7529930440c254f0146ce5db63f9f8 diff --git a/example/tools/raw b/example/tools/raw index 208cbfd7..84cc4f39 160000 --- a/example/tools/raw +++ b/example/tools/raw @@ -1 +1 @@ -Subproject commit 208cbfd7ea1da507173686e1312f95788fb8f209 +Subproject commit 84cc4f393db0939c6246c9a579377f2540dac289 diff --git a/example/tools/simple-image b/example/tools/simple-image index 527d1224..0b392a90 160000 --- a/example/tools/simple-image +++ b/example/tools/simple-image @@ -1 +1 @@ -Subproject commit 527d12247f1a486a1627f5e69b6c8e809e8adecb +Subproject commit 0b392a90e4001efb048980955b4a72e6b132f6fc diff --git a/example/tools/table b/example/tools/table index 42e1281e..ddbc1147 160000 --- a/example/tools/table +++ b/example/tools/table @@ -1 +1 @@ -Subproject commit 42e1281e505de90968263ab88d977873e17500b6 +Subproject commit ddbc1147e127a727cfac4dbe0326b78e02dceb9e diff --git a/example/tools/warning b/example/tools/warning index 6355942a..d7fa1d81 160000 --- a/example/tools/warning +++ b/example/tools/warning @@ -1 +1 @@ -Subproject commit 6355942a1f4528004791d9f9af3a67d84a4b1b2e +Subproject commit d7fa1d81728cb225ccccafefdcd18c81e05918ba diff --git a/src/tools/paragraph b/src/tools/paragraph index 4b193c33..21cbdea6 160000 --- a/src/tools/paragraph +++ b/src/tools/paragraph @@ -1 +1 @@ -Subproject commit 4b193c33c3efe00ffc13b16839cffb5e339df526 +Subproject commit 21cbdea6e5e61094b046f47e8cb423a817cec3ed