提交 8c00ed79 authored 作者: 王鹏飞's avatar 王鹏飞

feat: 添加对旧版对话框的支持,优化菜单键绑定逻辑

上级 dc06f0d4
import { describe, expect, it } from 'vitest' import { describe, expect, it, vi } from 'vitest'
import { defineEditorFeature } from '@/components/editor/wangeditor-customer/core/define-editor-feature' import { defineEditorFeature } from '@/components/editor/wangeditor-customer/core/define-editor-feature'
import { createFeatureRegistry } from '@/components/editor/wangeditor-customer/core/create-feature-registry' import { createFeatureRegistry } from '@/components/editor/wangeditor-customer/core/create-feature-registry'
...@@ -129,4 +129,18 @@ describe('createFeatureRegistry', () => { ...@@ -129,4 +129,18 @@ describe('createFeatureRegistry', () => {
expect(calls).toHaveLength(1 + expectedNodeTypes.length) expect(calls).toHaveLength(1 + expectedNodeTypes.length)
expect(calls[0].menus.map((menu) => menu.key)).toEqual(expectedMenuKeys) expect(calls[0].menus.map((menu) => menu.key)).toEqual(expectedMenuKeys)
}) })
it('opens legacy dialogs by the stable menu key', () => {
const calls = []
const Boot = { registerModule: (module) => calls.push(module) }
const emit = vi.fn()
registerEditorFeatures(Boot)
calls[0].menus.find((menu) => menu.key === 'AIRewrite').factory().exec({ emit })
expect(emit).toHaveBeenCalledWith('wangeditor-customer:dialog', {
id: 'ai-text.action',
payload: { action: 'rewrite' },
})
})
}) })
...@@ -34,7 +34,7 @@ export default class BaseModalMenu { ...@@ -34,7 +34,7 @@ export default class BaseModalMenu {
return false // or true return false // or true
} }
exec(editor) { exec(editor) {
const request = dialogByMenu[this.constructor.name] const request = dialogByMenu[this.menuKey]
if (!request) return if (!request) return
openEditorDialog(editor, request[0], request[1]) openEditorDialog(editor, request[0], request[1])
} }
......
...@@ -2,11 +2,20 @@ import { editorFeatureRegistry } from '../features' ...@@ -2,11 +2,20 @@ import { editorFeatureRegistry } from '../features'
const registrationKey = Symbol.for('ebook.admin.wangeditor-customer.registered') const registrationKey = Symbol.for('ebook.admin.wangeditor-customer.registered')
const bindMenuKey = (config) => ({
...config,
factory(...args) {
const menu = config.factory.apply(config, args)
menu.menuKey = config.key
return menu
},
})
export const registerEditorFeatures = (Boot) => { export const registerEditorFeatures = (Boot) => {
if (Boot[registrationKey]) return if (Boot[registrationKey]) return
Boot.registerModule({ Boot.registerModule({
menus: editorFeatureRegistry.menus.map((entry) => entry.config), menus: editorFeatureRegistry.menus.map((entry) => bindMenuKey(entry.config)),
}) })
editorFeatureRegistry.nodeModules.forEach((entry) => Boot.registerModule(entry.module)) editorFeatureRegistry.nodeModules.forEach((entry) => Boot.registerModule(entry.module))
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论