mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
refactor(ckeditor5-mermaid): use proper method for config type
This commit is contained in:
parent
d6548f4cd6
commit
9f25162700
@ -3,17 +3,8 @@ import MermaidEditing from './mermaidediting.js';
|
|||||||
import MermaidToolbar from './mermaidtoolbar.js';
|
import MermaidToolbar from './mermaidtoolbar.js';
|
||||||
import MermaidUI from './mermaidui.js';
|
import MermaidUI from './mermaidui.js';
|
||||||
|
|
||||||
declare module 'ckeditor5' {
|
|
||||||
interface PluginsMap {
|
|
||||||
[ Mermaid.pluginName ]: Mermaid;
|
|
||||||
[ MermaidEditing.pluginName ]: MermaidEditing;
|
|
||||||
[ MermaidToolbar.pluginName ]: MermaidToolbar;
|
|
||||||
[ MermaidUI.pluginName]: MermaidUI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Mermaid {
|
interface MermaidInstance {
|
||||||
init(config: MermaidConfig, element: HTMLElement): void;
|
init(config: MermaidConfig, element: HTMLElement): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,3 +14,21 @@ declare global {
|
|||||||
|
|
||||||
var mermaid: Mermaid | null | undefined;
|
var mermaid: Mermaid | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'ckeditor5' {
|
||||||
|
interface PluginsMap {
|
||||||
|
[ Mermaid.pluginName ]: Mermaid;
|
||||||
|
[ MermaidEditing.pluginName ]: MermaidEditing;
|
||||||
|
[ MermaidToolbar.pluginName ]: MermaidToolbar;
|
||||||
|
[ MermaidUI.pluginName]: MermaidUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EditorConfig {
|
||||||
|
"mermaid"?: {
|
||||||
|
lazyLoad?: () => Promise<MermaidInstance> | MermaidInstance;
|
||||||
|
config: MermaidConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -8,24 +8,19 @@ import MermaidPreviewCommand from './commands/mermaidPreviewCommand.js';
|
|||||||
import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js';
|
import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js';
|
||||||
import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.js';
|
import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.js';
|
||||||
import InsertMermaidCommand from './commands/insertMermaidCommand.js';
|
import InsertMermaidCommand from './commands/insertMermaidCommand.js';
|
||||||
import { DowncastAttributeEvent, DowncastConversionApi, Element, EventInfo, Item, Node, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5';
|
import { DowncastAttributeEvent, DowncastConversionApi, EditorConfig, Element, EventInfo, Item, Node, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5';
|
||||||
|
|
||||||
// Time in milliseconds.
|
// Time in milliseconds.
|
||||||
const DEBOUNCE_TIME = 300;
|
const DEBOUNCE_TIME = 300;
|
||||||
|
|
||||||
/* global window */
|
/* global window */
|
||||||
|
|
||||||
interface MermaidConfig {
|
|
||||||
lazyLoad?: () => Promise<Mermaid> | Mermaid;
|
|
||||||
config: MermaidConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
type DowncastConversionData = DowncastAttributeEvent["args"][0];
|
type DowncastConversionData = DowncastAttributeEvent["args"][0];
|
||||||
|
|
||||||
export default class MermaidEditing extends Plugin {
|
export default class MermaidEditing extends Plugin {
|
||||||
|
|
||||||
private _config!: MermaidConfig;
|
private _config!: EditorConfig["mermaid"];
|
||||||
private mermaid?: Mermaid;
|
private mermaid?: MermaidInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
@ -40,7 +35,7 @@ export default class MermaidEditing extends Plugin {
|
|||||||
init() {
|
init() {
|
||||||
this._registerCommands();
|
this._registerCommands();
|
||||||
this._defineConverters();
|
this._defineConverters();
|
||||||
this._config = this.editor.config.get("mermaid") as MermaidConfig;
|
this._config = this.editor.config.get("mermaid");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,6 +271,6 @@ export default class MermaidEditing extends Plugin {
|
|||||||
this.mermaid = await this._config.lazyLoad();
|
this.mermaid = await this._config.lazyLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mermaid?.init( this._config.config, domElement );
|
this.mermaid?.init( this._config?.config ?? {}, domElement );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user