diff --git a/packages/basic-modules/__tests__/code-block/plugin.test.ts b/packages/basic-modules/__tests__/code-block/plugin.test.ts index c8763edad..560be47cf 100644 --- a/packages/basic-modules/__tests__/code-block/plugin.test.ts +++ b/packages/basic-modules/__tests__/code-block/plugin.test.ts @@ -6,6 +6,7 @@ import { Editor, Transforms } from 'slate' import createEditor from '../../../../tests/utils/create-editor' import withCodeBlock from '../../src/modules/code-block/plugin' +import { isDataTransfer } from '../../../core/src/utils/dom' // 模拟 DataTransfer class MyDataTransfer { diff --git a/packages/basic-modules/__tests__/color/color-menus.test.ts b/packages/basic-modules/__tests__/color/color-menus.test.ts index 2fd627d7b..80daaebd7 100644 --- a/packages/basic-modules/__tests__/color/color-menus.test.ts +++ b/packages/basic-modules/__tests__/color/color-menus.test.ts @@ -7,6 +7,7 @@ import { Editor, Transforms } from 'slate' import createEditor from '../../../../tests/utils/create-editor' import ColorMenu from '../../src/modules/color/menu/ColorMenu' import BgColorMenu from '../../src/modules/color/menu/BgColorMenu' +import { isHTMLElememt } from '../../../../packages/core/src/utils/dom' describe('color menus', () => { let editor: any @@ -68,7 +69,7 @@ describe('color menus', () => { it('get panel content elem', () => { menus.forEach(({ menu }) => { const elem = menu.getPanelContentElem(editor) - expect(elem instanceof HTMLElement).toBeTruthy() + expect(isHTMLElememt(elem)).toBeTruthy() }) }) it('should handle click event and add mark to editor', () => { diff --git a/packages/basic-modules/__tests__/emotion/emotion-menu.test.ts b/packages/basic-modules/__tests__/emotion/emotion-menu.test.ts index abad7f149..bcd987479 100644 --- a/packages/basic-modules/__tests__/emotion/emotion-menu.test.ts +++ b/packages/basic-modules/__tests__/emotion/emotion-menu.test.ts @@ -6,6 +6,7 @@ import { Editor, Transforms } from 'slate' import createEditor from '../../../../tests/utils/create-editor' import EmotionMenu from '../../src/modules/emotion/menu/EmotionMenu' +import { isHTMLElememt } from '../../../../packages/core/src/utils/dom' describe('font family menu', () => { const menu = new EmotionMenu() @@ -41,7 +42,7 @@ describe('font family menu', () => { it('get panel content elem', () => { const elem = menu.getPanelContentElem(editor) - expect(elem instanceof HTMLElement).toBeTruthy() + expect(isHTMLElememt(elem)).toBeTruthy() document.body.appendChild(elem) const li = elem.querySelector('li') as HTMLLIElement diff --git a/packages/table-module/__tests__/menu/insert-table.test.ts b/packages/table-module/__tests__/menu/insert-table.test.ts index 3cd30d96c..763621df3 100644 --- a/packages/table-module/__tests__/menu/insert-table.test.ts +++ b/packages/table-module/__tests__/menu/insert-table.test.ts @@ -4,7 +4,8 @@ import { TABLE_SVG } from '../../src/constants/svg' import locale from '../../src/locale/zh-CN' import * as slate from 'slate' import * as core from '@wangeditor-next/core' -import $, { DOMElement } from '../../src/utils/dom' +import $ from '../../src/utils/dom' +import { isDOMElement } from './../../../core/src/utils/dom' function setEditorSelection( editor: core.IDomEditor, @@ -111,7 +112,7 @@ describe('Table Module Insert Table Menu', () => { const insertTableMenu = new InsertTable() const editor = createEditor() - expect(insertTableMenu.getPanelContentElem(editor) instanceof DOMElement).toBeTruthy() + expect(isDOMElement(insertTableMenu.getPanelContentElem(editor))).toBeTruthy() expect(insertTableMenu.getPanelContentElem(editor).className).toBe('w-e-panel-content-table') }) diff --git a/packages/table-module/src/module/column-resize.ts b/packages/table-module/src/module/column-resize.ts index d68af7577..444dc71db 100644 --- a/packages/table-module/src/module/column-resize.ts +++ b/packages/table-module/src/module/column-resize.ts @@ -1,6 +1,6 @@ import throttle from 'lodash.throttle' import { Element as SlateElement, Transforms, Editor } from 'slate' -import { DomEditor, IDomEditor } from '@wangeditor-next/core' +import { IDomEditor, isHTMLElememt } from '@wangeditor-next/core' import { TableElement } from './custom-types' import { isOfType } from '../utils' import $ from '../utils/dom' @@ -40,7 +40,7 @@ export function getColumnWidthRatios(columnWidths: number[]) { */ let resizeObserver: ResizeObserver | null = null export function observerTableResize(editor: IDomEditor, elm: Node | undefined) { - if (elm instanceof HTMLElement) { + if (isHTMLElememt(elm)) { const table = elm.querySelector('table') if (table) { resizeObserver = new ResizeObserver(([{ contentRect }]) => { @@ -183,7 +183,7 @@ export function handleCellBorderVisible(editor: IDomEditor, elemNode: SlateEleme // Cell Border 宽度为 10px const { clientX, target } = e // 当单元格合并的时候,鼠标在 cell 中间,则不显示 cell border - if (target instanceof HTMLElement) { + if (isHTMLElememt(target)) { const rect = target.getBoundingClientRect() if (clientX > rect.x + 5 && clientX < rect.x + rect.width - 5) { @@ -197,7 +197,7 @@ export function handleCellBorderVisible(editor: IDomEditor, elemNode: SlateEleme return } } - if (target instanceof HTMLElement) { + if (isHTMLElememt(target)) { const parent = target.closest('.table') if (parent) { const { clientX } = e diff --git a/packages/video-module/__tests__/menu/insert-video-menu.test.ts b/packages/video-module/__tests__/menu/insert-video-menu.test.ts index 9abea9a70..951d05750 100644 --- a/packages/video-module/__tests__/menu/insert-video-menu.test.ts +++ b/packages/video-module/__tests__/menu/insert-video-menu.test.ts @@ -3,6 +3,7 @@ * @author luochao */ +import { isHTMLElememt } from '../../../../packages/core/src/utils/dom' import createEditor from '../../../../tests/utils/create-editor' import InsertVideoMenu from '../../src/module/menu/InsertVideoMenu' import * as core from '@wangeditor-next/core' @@ -55,7 +56,7 @@ describe('videoModule module', () => { }) test('InsertVideoMenu invoke getModalContentElem should return HTML element', () => { - expect(insertVideoMenu.getModalContentElem(editor) instanceof HTMLElement).toBe(true) + expect(isHTMLElememt(insertVideoMenu.getModalContentElem(editor))).toBe(true) }) }) })