Skip to content

Commit

Permalink
Use es-toolkit's isElement
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsobol committed Dec 16, 2024
1 parent eeaf860 commit 273fb99
Show file tree
Hide file tree
Showing 31 changed files with 74 additions and 59 deletions.
4 changes: 2 additions & 2 deletions packages/ckeditor5-autosave/src/autosave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DomEmitterMixin, type DomEmitter } from 'ckeditor5/src/utils.js';

import type { DocumentChangeEvent } from 'ckeditor5/src/engine.js';

import { debounce } from 'es-toolkit/compat';
import { debounce, type DebouncedFunction } from 'es-toolkit/compat';

/* globals window */

Expand Down Expand Up @@ -81,7 +81,7 @@ export default class Autosave extends Plugin {
* Debounced save method. The `save()` method is called the specified `waitingTime` after `debouncedSave()` is called,
* unless a new action happens in the meantime.
*/
private _debouncedSave: ReturnType<typeof debounce<( () => Promise<void> )>>;
private _debouncedSave: DebouncedFunction<( () => Promise<void> )>;

/**
* The last saved document version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { setData as setModelData, getData as getModelData } from '@ckeditor/cked
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view.js';
import { Notification } from 'ckeditor5/src/ui.js';
import TokenMock from '@ckeditor/ckeditor5-cloud-services/tests/_utils/tokenmock.js';
import * as _ from 'es-toolkit';
import * as _ from 'es-toolkit/compat';
import CloudServicesCoreMock from '../_utils/cloudservicescoremock.js';
import CKBoxEditing from '../../src/ckboxediting.js';
import CKBoxImageEditEditing from '../../src/ckboximageedit/ckboximageeditediting.js';
Expand Down
10 changes: 5 additions & 5 deletions packages/ckeditor5-core/tests/_utils/classictesteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

/* globals HTMLElement */
/* eslint-disable new-cap */

import Editor from '../../src/editor/editor.js';
Expand All @@ -13,6 +12,7 @@ import BoxedEditorUIView from '@ckeditor/ckeditor5-ui/src/editorui/boxed/boxeded
import ElementReplacer from '@ckeditor/ckeditor5-utils/src/elementreplacer.js';
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview.js';
import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement.js';
import { isElement } from 'es-toolkit/compat';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror.js';

/**
Expand All @@ -28,7 +28,7 @@ export default class ClassicTestEditor extends ElementApiMixin( Editor ) {
constructor( sourceElementOrData, config ) {
super( config );

if ( sourceElementOrData instanceof HTMLElement ) {
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}

Expand Down Expand Up @@ -84,9 +84,9 @@ export default class ClassicTestEditor extends ElementApiMixin( Editor ) {
editor.initPlugins()
// Simulate EditorUI.init() (e.g. like in ClassicEditorUI). The ui#view
// should be rendered after plugins are initialized.
.then( () => editor.ui.init( sourceElementOrData instanceof HTMLElement ? sourceElementOrData : null ) )
.then( () => editor.ui.init( isElement( sourceElementOrData ) ? sourceElementOrData : null ) )
.then( () => {
if ( !( sourceElementOrData instanceof HTMLElement ) && config.initialData ) {
if ( !isElement( sourceElementOrData ) && config.initialData ) {
// Documented in core/editor/editorconfig.jsdoc.
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
throw new CKEditorError( 'editor-create-initial-data', null );
Expand Down Expand Up @@ -171,5 +171,5 @@ export class ClassicTestEditorUI extends EditorUI {
}

function getInitialData( sourceElementOrData ) {
return sourceElementOrData instanceof HTMLElement ? getDataFromElement( sourceElementOrData ) : sourceElementOrData;
return isElement( sourceElementOrData ) ? getDataFromElement( sourceElementOrData ) : sourceElementOrData;
}
2 changes: 1 addition & 1 deletion packages/ckeditor5-core/tests/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Editor } from '@ckeditor/ckeditor5-core';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils.js';
import { cloneDeep } from 'es-toolkit';
import { cloneDeep } from 'es-toolkit/compat';

describe( 'Accessibility', () => {
let editor, accessibility;
Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-balloon/src/ballooneditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { CKEditorError, getDataFromElement } from 'ckeditor5/src/utils.js';
import BalloonEditorUI from './ballooneditorui.js';
import BalloonEditorUIView from './ballooneditoruiview.js';

import { isElement as _isElement } from 'es-toolkit/compat';

/**
* The balloon editor implementation (Medium-like editor).
* It uses an inline editable and a toolbar based on the {@link module:ui/toolbar/balloon/balloontoolbar~BalloonToolbar}.
Expand Down Expand Up @@ -228,5 +230,5 @@ function getInitialData( sourceElementOrData: HTMLElement | string ): string {
}

function isElement( value: any ): value is Element {
return value instanceof HTMLElement;
return _isElement( value );
}
7 changes: 4 additions & 3 deletions packages/ckeditor5-editor-balloon/tests/ballooneditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

/* globals document, Event, HTMLElement */
/* globals document, Event */

import BalloonEditor from '../src/ballooneditor.js';
import BalloonEditorUI from '../src/ballooneditorui.js';
Expand All @@ -15,6 +15,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import Heading from '@ckeditor/ckeditor5-heading/src/heading.js';

import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard.js';
import { isElement } from 'es-toolkit/compat';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor.js';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils.js';
Expand Down Expand Up @@ -353,7 +354,7 @@ class VirtualBalloonTestEditor extends VirtualTestEditor {
constructor( sourceElementOrData, config ) {
super( config );

if ( sourceElementOrData instanceof HTMLElement ) {
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}

Expand All @@ -376,7 +377,7 @@ class VirtualBalloonTestEditor extends VirtualTestEditor {
.then( () => {
editor.ui.init();

const initialData = sourceElementOrData instanceof HTMLElement ?
const initialData = isElement( sourceElementOrData ) ?
sourceElementOrData.innerHTML :
sourceElementOrData;

Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-classic/src/classiceditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
} from 'ckeditor5/src/core.js';
import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils.js';

import { isElement as _isElement } from 'lodash-es';

/**
* The classic editor implementation. It uses an inline editable and a sticky toolbar, all enclosed in a boxed UI.
* See the {@glink examples/builds/classic-editor demo}.
Expand Down Expand Up @@ -213,5 +215,5 @@ function getInitialData( sourceElementOrData: HTMLElement | string ): string {
}

function isElement( value: any ): value is Element {
return value instanceof HTMLElement;
return _isElement( value );
}
7 changes: 4 additions & 3 deletions packages/ckeditor5-editor-classic/tests/classiceditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

/* globals window, document, Event, console, HTMLElement */
/* globals window, document, Event, console */

import View from '@ckeditor/ckeditor5-ui/src/view.js';

Expand All @@ -19,6 +19,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard.js';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils.js';
import { isElement } from 'lodash-es';
import { ContextualBalloon, Dialog, DialogViewPosition } from '@ckeditor/ckeditor5-ui';

describe( 'ClassicEditorUI', () => {
Expand Down Expand Up @@ -1027,7 +1028,7 @@ class VirtualClassicTestEditor extends VirtualTestEditor {
constructor( sourceElementOrData, config ) {
super( config );

if ( sourceElementOrData instanceof HTMLElement ) {
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}

Expand All @@ -1053,7 +1054,7 @@ class VirtualClassicTestEditor extends VirtualTestEditor {
.then( () => {
editor.ui.init();

const initialData = sourceElementOrData instanceof HTMLElement ?
const initialData = isElement( sourceElementOrData ) ?
sourceElementOrData.innerHTML :
sourceElementOrData;

Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-decoupled/src/decouplededitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
import DecoupledEditorUI from './decouplededitorui.js';
import DecoupledEditorUIView from './decouplededitoruiview.js';

import { isElement as _isElement } from 'lodash-es';

/**
* The decoupled editor implementation. It provides an inline editable and a toolbar. However, unlike other editors,
* it does not render these components anywhere in the DOM unless configured.
Expand Down Expand Up @@ -255,5 +257,5 @@ function getInitialData( sourceElementOrData: HTMLElement | string ): string {
}

function isElement( value: any ): value is Element {
return value instanceof HTMLElement;
return _isElement( value );
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

/* globals document, Event, HTMLElement */
/* globals document, Event */

import View from '@ckeditor/ckeditor5-ui/src/view.js';

Expand All @@ -18,6 +18,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard.js';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils.js';
import { isElement } from 'lodash-es';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';

describe( 'DecoupledEditorUI', () => {
Expand Down Expand Up @@ -421,7 +422,7 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor {
constructor( sourceElementOrData, config ) {
super( config );

if ( sourceElementOrData instanceof HTMLElement ) {
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}

Expand All @@ -447,7 +448,7 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor {
.then( () => {
editor.ui.init();

const initialData = sourceElementOrData instanceof HTMLElement ?
const initialData = isElement( sourceElementOrData ) ?
sourceElementOrData.innerHTML :
sourceElementOrData;

Expand Down
4 changes: 3 additions & 1 deletion packages/ckeditor5-editor-inline/src/inlineeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils.js';
import InlineEditorUI from './inlineeditorui.js';
import InlineEditorUIView from './inlineeditoruiview.js';

import { isElement as _isElement } from 'lodash-es';

/**
* The inline editor implementation. It uses an inline editable and a floating toolbar.
* See the {@glink examples/builds/inline-editor demo}.
Expand Down Expand Up @@ -221,5 +223,5 @@ function getInitialData( sourceElementOrData: HTMLElement | string ): string {
}

function isElement( value: any ): value is HTMLElement {
return value instanceof HTMLElement;
return _isElement( value );
}
7 changes: 4 additions & 3 deletions packages/ckeditor5-editor-inline/tests/inlineeditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

/* globals document, Event, console, HTMLElement */
/* globals document, Event, console */

import View from '@ckeditor/ckeditor5-ui/src/view.js';

Expand All @@ -18,6 +18,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard.js';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils.js';
import { isElement } from 'lodash-es';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';

describe( 'InlineEditorUI', () => {
Expand Down Expand Up @@ -504,7 +505,7 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
constructor( sourceElementOrData, config ) {
super( config );

if ( sourceElementOrData instanceof HTMLElement ) {
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}

Expand All @@ -530,7 +531,7 @@ class VirtualInlineTestEditor extends VirtualTestEditor {
.then( () => {
editor.ui.init();

const initialData = sourceElementOrData instanceof HTMLElement ?
const initialData = isElement( sourceElementOrData ) ?
sourceElementOrData.innerHTML :
sourceElementOrData;

Expand Down
3 changes: 2 additions & 1 deletion packages/ckeditor5-editor-multi-root/src/multirooteditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import MultiRootEditorUI from './multirooteditorui.js';
import MultiRootEditorUIView from './multirooteditoruiview.js';

import { isElement as _isElement } from 'lodash-es';
import {
type RootElement,
type ViewRootEditableElement,
Expand Down Expand Up @@ -935,7 +936,7 @@ function getInitialData( sourceElementOrData: HTMLElement | string ): string {
}

function isElement( value: any ): value is HTMLElement {
return value instanceof HTMLElement;
return _isElement( value );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
ViewDocumentSelectionEventData
} from './selectionobserver.js';
import { keyCodes } from '@ckeditor/ckeditor5-utils';
import { debounce } from 'es-toolkit/compat';
import { debounce, type DebouncedFunction } from 'es-toolkit/compat';

/**
* Fake selection observer class. If view selection is fake it is placed in dummy DOM container. This observer listens
Expand All @@ -30,7 +30,7 @@ export default class FakeSelectionObserver extends Observer {
/**
* Fires debounced event `selectionChangeDone`. It uses `es-toolkit#debounce` method to delay function call.
*/
private readonly _fireSelectionChangeDoneDebounced: ReturnType<typeof debounce<( data: ViewDocumentSelectionEventData ) => void>>;
private readonly _fireSelectionChangeDoneDebounced: DebouncedFunction<( data: ViewDocumentSelectionEventData ) => void>;

/**
* Creates new FakeSelectionObserver instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Observer from './observer.js';
import MutationObserver from './mutationobserver.js';
import FocusObserver from './focusobserver.js';
import { env } from '@ckeditor/ckeditor5-utils';
import { debounce } from 'es-toolkit/compat';
import { debounce, type DebouncedFunction } from 'es-toolkit/compat';

import type View from '../view.js';
import type DocumentSelection from '../documentselection.js';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class SelectionObserver extends Observer {
/**
* Fires debounced event `selectionChangeDone`. It uses `es-toolkit#debounce` method to delay function call.
*/
private readonly _fireSelectionChangeDoneDebounced: ReturnType<typeof debounce<( data: ViewDocumentSelectionEventData ) => void>>;
private readonly _fireSelectionChangeDoneDebounced: DebouncedFunction<( data: ViewDocumentSelectionEventData ) => void>;

/**
* When called, starts clearing the {@link #_loopbackCounter} counter in time intervals. When the number of selection
Expand All @@ -83,7 +83,7 @@ export default class SelectionObserver extends Observer {
* correctly (for whatever reason). It is a safeguard (paranoid check), that returns document to the normal state
* after a certain period of time (debounced, postponed by each selectionchange event).
*/
private readonly _documentIsSelectingInactivityTimeoutDebounced: ReturnType<typeof debounce<() => boolean>>;
private readonly _documentIsSelectingInactivityTimeoutDebounced: DebouncedFunction<() => boolean>;

/**
* Private property to check if the code does not enter infinite loop.
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-html-embed/tests/manual/htmlembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* globals window, document */

import sanitizeHtml from 'sanitize-html';
import { clone } from 'es-toolkit';
import { clone } from 'es-toolkit/compat';
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor.js';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset.js';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/

import { range } from 'es-toolkit';
import { range } from 'es-toolkit/compat';

import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js';
import Image from '@ckeditor/ckeditor5-image/src/image.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed.js';
import GeneralHtmlSupport from '../../src/generalhtmlsupport.js';
import { getModelDataWithAttributes } from '../_utils/utils.js';
import { range } from 'es-toolkit';
import { range } from 'es-toolkit/compat';
import MediaEmbedElementSupport from '../../src/integrations/mediaembed.js';

/* global document */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import GeneralHtmlSupport from '../../src/generalhtmlsupport.js';
import { getModelDataWithAttributes } from '../_utils/utils.js';
import TableElementSupport from '../../src/integrations/table.js';

import { range } from 'es-toolkit';
import { range } from 'es-toolkit/compat';

/* global document */

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-media-embed/tests/mediaembedediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { setData as setModelData, getData as getModelData } from '@ckeditor/cked
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view.js';
import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml.js';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
import { escapeRegExp } from 'es-toolkit';
import { escapeRegExp } from 'es-toolkit/compat';

describe( 'MediaEmbedEditing', () => {
let editor, model, doc, view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const http = require( 'http' );
const fs = require( 'fs' );
const querystring = require( 'querystring' );
const url = require( 'url' );
const { upperFirst } = require( 'es-toolkit' );
const { upperFirst } = require( 'es-toolkit/compat' );

const hostname = '127.0.0.1';
const port = 3000;
Expand Down
Loading

0 comments on commit 273fb99

Please sign in to comment.