Skip to content

Build your personal knowledge base with Trilium Notes

refactor(ckeditor5-mermaid): get rid of any runtime dependencies

Elian Doranb606afa85812
diff --git a/packages/ckeditor5-mermaid/package.json b/packages/ckeditor5-mermaid/package.json
index bae41f26fa..73f4f7d57a 100644
--- a/packages/ckeditor5-mermaid/package.json
+++ b/packages/ckeditor5-mermaid/package.json
@@ -43,8 +43,5 @@
"stylelint": "stylelint --quiet --allow-empty-input 'theme/**/*.css'",
"test": "vitest",
"test:debug": "vitest --inspect-brk --no-file-parallelism --browser.headless=false"
- },
- "dependencies": {
- "es-toolkit": "^1.45.1"
}
}
diff --git a/packages/ckeditor5-mermaid/src/mermaidediting.ts b/packages/ckeditor5-mermaid/src/mermaidediting.ts
index 0d9939a273..88a7f7badf 100644
--- a/packages/ckeditor5-mermaid/src/mermaidediting.ts
+++ b/packages/ckeditor5-mermaid/src/mermaidediting.ts
@@ -2,14 +2,14 @@
* @module mermaid/mermaidediting
*/
-import { debounce } from 'es-toolkit/compat';
-
import MermaidPreviewCommand from './commands/mermaidPreviewCommand.js';
import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js';
import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.js';
import InsertMermaidCommand from './commands/insertMermaidCommand.js';
import { DowncastAttributeEvent, DowncastConversionApi, EditorConfig, ModelElement, EventInfo, ModelItem, ModelNode, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5';
+import { debounce } from './utils.js';
+
// Time in milliseconds.
const DEBOUNCE_TIME = 300;
diff --git a/packages/ckeditor5-mermaid/src/utils.ts b/packages/ckeditor5-mermaid/src/utils.ts
index 184d0bdd0e..894c863875 100644
--- a/packages/ckeditor5-mermaid/src/utils.ts
+++ b/packages/ckeditor5-mermaid/src/utils.ts
@@ -5,6 +5,16 @@
import { Editor } from "ckeditor5";
+export function debounce<T extends (...args: any[]) => void>( fn: T, waitMs: number ): T {
+ let timeout: ReturnType<typeof setTimeout> | null = null;
+ return function( this: unknown, ...args: Parameters<T> ) {
+ if ( timeout ) {
+ clearTimeout( timeout );
+ }
+ timeout = setTimeout( () => fn.apply( this, args ), waitMs );
+ } as T;
+}
+
/**
* Helper function for setting the `isOn` state of buttons.
*
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bc709a0603..fec8f5466f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1149,10 +1149,6 @@ importers:
packages/ckeditor5-mermaid:
- dependencies:
- es-toolkit:
- specifier: ^1.45.1
- version: 1.45.1
devDependencies:
'@ckeditor/ckeditor5-inspector':
specifier: '>=4.1.0'