From 5c7d0d728946dd7c6873d7d77cb79f5f82fbcc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E5=B0=91=E5=8D=AB?= Date: Wed, 5 Jun 2024 14:07:09 +0800 Subject: [PATCH] Update plugin.ts --- packages/core/plugin.ts | 134 ++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 73 deletions(-) diff --git a/packages/core/plugin.ts b/packages/core/plugin.ts index 9489c0a7..c31ec07c 100644 --- a/packages/core/plugin.ts +++ b/packages/core/plugin.ts @@ -1,89 +1,77 @@ import Editor from './Editor'; type IEditor = Editor; -class EditorWorkspacePlugin { +class FontPlugin { public canvas: fabric.Canvas; public editor: IEditor; - public defautOption = { - color: 'red', - size: 0.5, - }; - static pluginName = 'textPlugin'; - static events = ['textEvent1', 'textEvent2']; - static apis = ['textAPI1', 'textAPI2']; - public hotkeys: string[] = ['ctrl+v', 'ctrl+a']; - constructor(canvas: fabric.Canvas, editor: IEditor, options: IPluginOption = {}) { + // 插件名称 + static pluginName = 'FontPlugin'; + // 暴漏的API名称 + static apis = ['downFontByJSON']; + // 快捷键 keyCode hotkeys-js + public hotkeys: string[] = ['backspace', 'space']; + // 私有属性 + repoSrc: string; + + constructor(canvas: fabric.Canvas, editor: IEditor, config: { repoSrc: string }) { + // 初始化 this.canvas = canvas; this.editor = editor; - this.defautOption = { ...this.defautOption, ...options }; - this.init(); - } - init() { - console.log('pluginInit', this.canvas, this.editor, this.defautOption); + // 可插入外部配置 + this.repoSrc = config.repoSrc; } - destroy() { - console.log('pluginDestroy'); - } - // 保存文件前 - hookSaveBefore() { - console.log('pluginHookSaveBefore'); - } - // 保存文件前 - hookSaveAfter() { - console.log('pluginHookSaveAfter'); + // 钩子函数 hookImportAfter/hookSaveBefore/hookSaveAfter Promise + hookImportBefore(json: string) { + return this.downFontByJSON(json); } - // 快捷键扩展回调 - hotkeyEvent(eventName: string, e?: Event) { - console.log('pluginHotkeyEvent', eventName, e); - } - // 右键菜单扩展 + + // 挂载API方法 + downFontByJSON(str: string) {} + + // 私有方法 + _createFontCSS(){} + + // 右键菜单 contextMenu() { - return [ - { text: 'Back', hotkey: 'Alt+Left arrow', disabled: true }, - { text: 'Forward', hotkey: 'Alt+Right arrow', disabled: true }, - { text: 'Reload', hotkey: 'Ctrl+R' }, - null, - { text: 'Save as...', hotkey: 'Ctrl+S' }, - { text: 'Print...', hotkey: 'Ctrl+P' }, - { text: 'Cast...' }, - { text: 'Translate to English' }, - null, - { text: 'View page source', hotkey: 'Ctrl+U' }, - { text: 'Inspect', hotkey: 'Ctrl+Shift+I' }, - null, - { - text: 'Kali tools', - hotkey: '❯', - subitems: [ - { - text: 'Fuzzing Tools', - hotkey: '❯', - subitems: [ - { text: 'spike-generic_chunked' }, - { text: 'spike-generic_listen_tcp' }, - { text: 'spike-generic_send_tcp' }, - { text: 'spike-generic_send_udp' }, - ], - }, - { - text: 'VoIP Tools', - hotkey: '❯', - subitems: [{ text: 'voiphopper' }], - }, - { text: 'nikto' }, - { text: 'nmap' }, - { text: 'sparta' }, - { text: 'unix-privesc-check' }, - ], - }, - { text: 'Skins', hotkey: '❯' }, - ]; + const selectedMode = this.editor.getSelectMode(); + if (selectedMode === SelectMode.ONE) { + return [ + null, // 分割线 + { + text: '翻转', + hotkey: '❯', + subitems: [ + { + text: t('flip.x'), + hotkey: '|', + onclick: () => this.flip('X'), + }, + { + text: t('flip.y'), + hotkey: '-', + onclick: () => this.flip('Y'), + }, + ], + }, + ]; + } + } + + // 快捷键 + hotkeyEvent(eventName: string, e: { type, code }) { + // eventName:hotkeys中的属性 backspace、space + // type:keyUp keyDown + // code:hotkeys-js Code + if (eventName === 'backspace' && type === 'keydown') { + this.del(); + } } - _command() { - console.log('pluginContextMenuCommand'); + // 注销 + destroy() { + console.log('pluginDestroy'); } } -export default EditorWorkspacePlugin; +export default FontPlugin;