fix(types): add missing TypeScript declarations for v0.1.5-v0.1.7 APIs

- MarkdownEditorOptions: add lineNumbers, outline, autoBrackets
- PluginObject: add version, depends, priority
- EditorEventName: add themeChange, localeChange
- MarkdownEditor: add unuse, registerShortcut, configureToolbar, toast, setLocale, getLocale, t
- pluginUtils: add topologicalSort, validateConfig
- i18nUtils: add full API surface (loadRemote, formatNumber, etc.)
- Top-level exports: topologicalSort, validateConfig, createInstanceI18n, loadRemote, exportCSSVars, etc.
- MeEditorAPI: add all missing properties
This commit is contained in:
2026-07-24 13:14:08 +08:00
parent 6c0c5f0c81
commit 863c78bf47
+89 -3
View File
@@ -48,6 +48,12 @@ export interface MarkdownEditorOptions {
readOnly?: boolean;
/** 历史栈防抖延迟(ms),默认 400 */
historyDebounce?: number;
/** 显示行号,默认 truev0.1.7 */
lineNumbers?: boolean;
/** 显示大纲面板,默认 falsev0.1.7 */
outline?: boolean;
/** 自动括号闭合,默认 truev0.1.7 */
autoBrackets?: boolean;
/** 主题,默认 'auto' */
theme?: ThemeName;
/** 国际化语言,默认 'zh-CN' */
@@ -82,9 +88,12 @@ export interface MarkdownEditorOptions {
/** 插件对象 */
export interface PluginObject {
name: string;
version?: string;
description?: string;
depends?: string[];
priority?: number;
[key: string]: any;
install?: (editor: MarkdownEditor) => void;
install?: (editor: MarkdownEditor) => void | Promise<void>;
destroy?: (editor: MarkdownEditor) => void;
}
@@ -125,7 +134,8 @@ export interface EditorStatus {
export type EditorEventName =
| 'input' | 'change' | 'focus' | 'blur' | 'save'
| 'modeChange' | 'fullscreen' | 'autosave' | 'destroy'
| 'beforeRender' | 'afterRender';
| 'beforeRender' | 'afterRender'
| 'themeChange' | 'localeChange';
/** 全局钩子名 */
export type HookName =
@@ -218,9 +228,31 @@ export class MarkdownEditor {
// 插件
use(plugin: string | PluginObject, options?: object): this;
/** 卸载插件(v0.1.6 */
unuse(name: string): this;
getPlugins(): PluginObject[];
addToolbarButton(config: ToolbarButtonConfig): this;
// 快捷键(v0.1.6
registerShortcut(combo: string, handler: Function | string, description?: string): this;
unregisterShortcut(combo: string): this;
getShortcuts(): Array<{ combo: string; handler: Function | string; description: string }>;
// 工具栏(v0.1.6
configureToolbar(tools: ToolbarItem[]): this;
removeToolbarButton(action: string): this;
// 右键菜单(v0.1.6
registerContextMenu(items: Array<{ label: string; action?: string; shortcut?: string; type?: string }>): this;
// Toast 通知(v0.1.6
toast(message: string, opts?: { type?: 'success' | 'error' | 'warning' | 'info'; duration?: number; animation?: string }): this;
// 实例级 i18nv0.1.6
setLocale(locale: string): this;
getLocale(): string;
t(key: string, params?: object): string;
// 生命周期
destroy(): void;
isDestroyed(): boolean;
@@ -265,6 +297,30 @@ export function slugify(text: string): string;
/** 清除渲染缓存(主题切换等场景) */
export function clearRenderCache(): void;
// ============ 插件工具(v0.1.6============
/** 插件拓扑排序 */
export function topologicalSort(plugins: PluginObject[]): PluginObject[];
/** 插件配置校验 */
export function validateConfig(schema: object, config: object): { valid: boolean; errors: string[]; patched: object };
// ============ i18n 工具(v0.1.6============
/** 创建实例级 i18n 上下文 */
export function createInstanceI18n(editor: object): object;
/** 远程加载翻译包 */
export function loadRemote(url: string, locale: string): Promise<boolean>;
// ============ 主题工具(v0.1.5============
/** 导出 CSS 变量 */
export function exportCSSVars(el?: HTMLElement): Record<string, string>;
/** 获取单个 CSS 变量 */
export function getCSSVariable(name: string, el?: HTMLElement): string;
/** 外部主题跟随 */
export function followExternalTheme(opts: object, onChange: (theme: string) => void): () => void;
/** 从父容器继承主题 */
export function adoptFromParent(container: HTMLElement, onDetected: (theme: string) => void): () => void;
/** 创建实例级主题上下文 */
export function createInstanceTheme(editor: object): object;
// ============ 插件 ============
/** 预设插件表 */
export const presetPlugins: {
@@ -290,6 +346,8 @@ export const pluginUtils: {
getAllPresets(): { [key: string]: PluginObject };
createPlugin(config: object): PluginObject;
validatePlugin(plugin: PluginObject): { valid: boolean; errors: string[] };
topologicalSort(plugins: PluginObject[]): PluginObject[];
validateConfig(schema: object, config: object): { valid: boolean; errors: string[]; patched: object };
};
/** 插件管理器 */
@@ -348,10 +406,28 @@ export const i18nUtils: {
t(key: string, params?: object): string;
getCurrentLocale(): string;
setCurrentLocale(locale: string): void;
loadLocale(locale: string, messages: object): void;
switchLocale(locale: string): void;
getFallbackLocale(): string;
setFallbackLocale(locale: string): void;
hasTranslation(key: string): boolean;
getTranslations(locale: string): object;
addTranslations(locale: string, translations: object): void;
loadRemote(url: string, locale: string): Promise<boolean>;
getSupportedLocales(): string[];
isLocaleSupported(locale: string): boolean;
getLocaleName(locale: string): string;
getLocaleDirection(locale: string): 'ltr' | 'rtl';
formatNumber(n: number, opts?: object): string;
formatCurrency(amount: number, currency?: string, opts?: object): string;
formatDate(date: Date | string, opts?: object): string;
addLocaleListener(fn: (locale: string) => void): () => void;
removeLocaleListener(fn: (locale: string) => void): void;
clearLocaleListeners(): void;
initI18n(): void;
saveLocale(locale: string): void;
loadLocale(): string;
getDefaultLocale(): string;
createInstanceI18n(editor: object): object;
[key: string]: any;
};
@@ -377,6 +453,16 @@ export interface MeEditorAPI {
parseMarkdown: typeof parseMarkdown;
safeUrl: typeof safeUrl;
slugify: typeof slugify;
clearRenderCache: typeof clearRenderCache;
topologicalSort: typeof topologicalSort;
validateConfig: typeof validateConfig;
createInstanceI18n: typeof createInstanceI18n;
loadRemote: typeof loadRemote;
exportCSSVars: typeof exportCSSVars;
getCSSVariable: typeof getCSSVariable;
followExternalTheme: typeof followExternalTheme;
adoptFromParent: typeof adoptFromParent;
createInstanceTheme: typeof createInstanceTheme;
themes: typeof themeUtils;
i18n: typeof i18nUtils;
animations: typeof animationUtils;