|
@@ -10,7 +10,7 @@ import {
|
|
|
BlockCommandCallback,
|
|
BlockCommandCallback,
|
|
|
StyleString,
|
|
StyleString,
|
|
|
ThemeOptions,
|
|
ThemeOptions,
|
|
|
- UIOptions
|
|
|
|
|
|
|
+ UIOptions, IHookEvent
|
|
|
} from './LSPlugin'
|
|
} from './LSPlugin'
|
|
|
import Debug from 'debug'
|
|
import Debug from 'debug'
|
|
|
import * as CSS from 'csstype'
|
|
import * as CSS from 'csstype'
|
|
@@ -25,6 +25,35 @@ declare global {
|
|
|
|
|
|
|
|
const debug = Debug('LSPlugin:user')
|
|
const debug = Debug('LSPlugin:user')
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @param type
|
|
|
|
|
+ * @param opts
|
|
|
|
|
+ * @param action
|
|
|
|
|
+ */
|
|
|
|
|
+function registerSimpleCommand (
|
|
|
|
|
+ this: LSPluginUser,
|
|
|
|
|
+ type: string,
|
|
|
|
|
+ opts: {
|
|
|
|
|
+ key: string,
|
|
|
|
|
+ label: string
|
|
|
|
|
+ },
|
|
|
|
|
+ action: BlockCommandCallback
|
|
|
|
|
+) {
|
|
|
|
|
+ if (typeof action !== 'function') {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const { key, label } = opts
|
|
|
|
|
+ const eventKey = `SimpleCommandHook${key}${++registeredCmdUid}`
|
|
|
|
|
+
|
|
|
|
|
+ this.Editor['on' + eventKey](action)
|
|
|
|
|
+
|
|
|
|
|
+ this.caller?.call(`api:call`, {
|
|
|
|
|
+ method: 'register-plugin-simple-command',
|
|
|
|
|
+ args: [this.baseInfo.id, [{ key, label, type }, ['editor/hook', eventKey]]]
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const app: Partial<IAppProxy> = {
|
|
const app: Partial<IAppProxy> = {
|
|
|
registerUIItem (
|
|
registerUIItem (
|
|
|
type: 'toolbar' | 'pagebar',
|
|
type: 'toolbar' | 'pagebar',
|
|
@@ -38,6 +67,27 @@ const app: Partial<IAppProxy> = {
|
|
|
args: [pid, type, opts]
|
|
args: [pid, type, opts]
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ return false
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ registerPagebarMenuItem (
|
|
|
|
|
+ this: LSPluginUser,
|
|
|
|
|
+ tag: string,
|
|
|
|
|
+ action: (e: IHookEvent & { page: string }) => void
|
|
|
|
|
+ ): unknown {
|
|
|
|
|
+ if (typeof action !== 'function') {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const key = tag + '_' + this.baseInfo.id
|
|
|
|
|
+ const label = tag
|
|
|
|
|
+ const type = 'pagebar-menu-item'
|
|
|
|
|
+
|
|
|
|
|
+ registerSimpleCommand.call(this,
|
|
|
|
|
+ type, {
|
|
|
|
|
+ key, label
|
|
|
|
|
+ }, action)
|
|
|
|
|
+
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -95,28 +145,25 @@ const editor: Partial<IEditorProxy> = {
|
|
|
return false
|
|
return false
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- registerBlockContextMenu (
|
|
|
|
|
|
|
+ registerBlockContextMenuItem (
|
|
|
this: LSPluginUser,
|
|
this: LSPluginUser,
|
|
|
tag: string,
|
|
tag: string,
|
|
|
action: BlockCommandCallback
|
|
action: BlockCommandCallback
|
|
|
- ): boolean {
|
|
|
|
|
|
|
+ ): unknown {
|
|
|
if (typeof action !== 'function') {
|
|
if (typeof action !== 'function') {
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const key = tag
|
|
|
|
|
|
|
+ const key = + '_' + this.baseInfo.id
|
|
|
const label = tag
|
|
const label = tag
|
|
|
- const type = 'block-context-menu'
|
|
|
|
|
- const eventKey = `SimpleCommandHook${tag}${++registeredCmdUid}`
|
|
|
|
|
-
|
|
|
|
|
- this.Editor['on' + eventKey](action)
|
|
|
|
|
|
|
+ const type = 'block-context-menu-item'
|
|
|
|
|
|
|
|
- this.caller?.call(`api:call`, {
|
|
|
|
|
- method: 'register-plugin-simple-command',
|
|
|
|
|
- args: [this.baseInfo.id, [{ key, label, type }, ['editor/hook', eventKey]]]
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ registerSimpleCommand.call(this,
|
|
|
|
|
+ type, {
|
|
|
|
|
+ key, label
|
|
|
|
|
+ }, action)
|
|
|
|
|
|
|
|
- return true
|
|
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|