feat: add override internal function api #260
This commit is contained in:
@@ -61,6 +61,10 @@ export default defineConfig({
|
|||||||
{ text: '自定义右键菜单', link: '/guide/contextmenu-custom' }
|
{ text: '自定义右键菜单', link: '/guide/contextmenu-custom' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: '重写方法',
|
||||||
|
items: [{ text: '重写方法', link: '/guide/override' }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'API',
|
text: 'API',
|
||||||
items: [{ text: '全局API', link: '/guide/api' }]
|
items: [{ text: '全局API', link: '/guide/api' }]
|
||||||
@@ -140,6 +144,10 @@ export default defineConfig({
|
|||||||
{ text: 'custom', link: '/en/guide/contextmenu-custom' }
|
{ text: 'custom', link: '/en/guide/contextmenu-custom' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Override',
|
||||||
|
items: [{ text: 'override', link: '/en/guide/override' }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'Api',
|
text: 'Api',
|
||||||
items: [{ text: 'api', link: '/en/guide/api' }]
|
items: [{ text: 'api', link: '/en/guide/api' }]
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Override
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import Editor from "@hufe921/canvas-editor"
|
||||||
|
|
||||||
|
const instance = new Editor(container, <IElement[]>data, options)
|
||||||
|
instance.override.overrideFunction = ()=>{}
|
||||||
|
```
|
||||||
|
|
||||||
|
## paste
|
||||||
|
|
||||||
|
Feature: Override internal paste function
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.override.paste = (evt: ClipboardEvent) => void
|
||||||
|
```
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# 重写方法
|
||||||
|
|
||||||
|
## 使用方式
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import Editor from "@hufe921/canvas-editor"
|
||||||
|
|
||||||
|
const instance = new Editor(container, <IElement[]>data, options)
|
||||||
|
instance.override.overrideFunction = ()=>{}
|
||||||
|
```
|
||||||
|
|
||||||
|
## paste
|
||||||
|
|
||||||
|
功能:重写粘贴方法
|
||||||
|
|
||||||
|
用法:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.override.paste = (evt: ClipboardEvent) => void
|
||||||
|
```
|
||||||
@@ -57,6 +57,12 @@ export class CursorAgent {
|
|||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
const clipboardData = evt.clipboardData
|
const clipboardData = evt.clipboardData
|
||||||
if (!clipboardData) return
|
if (!clipboardData) return
|
||||||
|
// 自定义粘贴事件
|
||||||
|
const { paste } = this.draw.getOverride()
|
||||||
|
if (paste) {
|
||||||
|
paste(evt)
|
||||||
|
return
|
||||||
|
}
|
||||||
const rangeManager = this.draw.getRange()
|
const rangeManager = this.draw.getRange()
|
||||||
const { startIndex } = rangeManager.getRange()
|
const { startIndex } = rangeManager.getRange()
|
||||||
const elementList = this.draw.getElementList()
|
const elementList = this.draw.getElementList()
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ import { WORD_LIKE_REG } from '../../dataset/constant/Regular'
|
|||||||
import { EventBus } from '../event/eventbus/EventBus'
|
import { EventBus } from '../event/eventbus/EventBus'
|
||||||
import { EventBusMap } from '../../interface/EventBus'
|
import { EventBusMap } from '../../interface/EventBus'
|
||||||
import { Group } from './interactive/Group'
|
import { Group } from './interactive/Group'
|
||||||
|
import { Override } from '../override/Override'
|
||||||
|
|
||||||
export class Draw {
|
export class Draw {
|
||||||
private container: HTMLDivElement
|
private container: HTMLDivElement
|
||||||
@@ -98,6 +99,7 @@ export class Draw {
|
|||||||
private elementList: IElement[]
|
private elementList: IElement[]
|
||||||
private listener: Listener
|
private listener: Listener
|
||||||
private eventBus: EventBus<EventBusMap>
|
private eventBus: EventBus<EventBusMap>
|
||||||
|
private override: Override
|
||||||
|
|
||||||
private i18n: I18n
|
private i18n: I18n
|
||||||
private canvasEvent: CanvasEvent
|
private canvasEvent: CanvasEvent
|
||||||
@@ -152,7 +154,8 @@ export class Draw {
|
|||||||
options: DeepRequired<IEditorOption>,
|
options: DeepRequired<IEditorOption>,
|
||||||
data: IEditorData,
|
data: IEditorData,
|
||||||
listener: Listener,
|
listener: Listener,
|
||||||
eventBus: EventBus<EventBusMap>
|
eventBus: EventBus<EventBusMap>,
|
||||||
|
override: Override
|
||||||
) {
|
) {
|
||||||
this.container = this._wrapContainer(rootContainer)
|
this.container = this._wrapContainer(rootContainer)
|
||||||
this.pageList = []
|
this.pageList = []
|
||||||
@@ -164,6 +167,7 @@ export class Draw {
|
|||||||
this.elementList = data.main
|
this.elementList = data.main
|
||||||
this.listener = listener
|
this.listener = listener
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
|
this.override = override
|
||||||
|
|
||||||
this._formatContainer()
|
this._formatContainer()
|
||||||
this.pageContainer = this._createPageContainer()
|
this.pageContainer = this._createPageContainer()
|
||||||
@@ -622,6 +626,10 @@ export class Draw {
|
|||||||
return this.eventBus
|
return this.eventBus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getOverride(): Override {
|
||||||
|
return this.override
|
||||||
|
}
|
||||||
|
|
||||||
public getCursor(): Cursor {
|
public getCursor(): Cursor {
|
||||||
return this.cursor
|
return this.cursor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export class Override {
|
||||||
|
public paste: ((evt: ClipboardEvent) => void) | undefined
|
||||||
|
}
|
||||||
+6
-1
@@ -62,11 +62,13 @@ import { EventBusMap } from './interface/EventBus'
|
|||||||
import { IGroup } from './interface/Group'
|
import { IGroup } from './interface/Group'
|
||||||
import { defaultGroupOption } from './dataset/constant/Group'
|
import { defaultGroupOption } from './dataset/constant/Group'
|
||||||
import { IRangeStyle } from './interface/Listener'
|
import { IRangeStyle } from './interface/Listener'
|
||||||
|
import { Override } from './core/override/Override'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
public command: Command
|
public command: Command
|
||||||
public listener: Listener
|
public listener: Listener
|
||||||
public eventBus: EventBus<EventBusMap>
|
public eventBus: EventBus<EventBusMap>
|
||||||
|
public override: Override
|
||||||
public register: Register
|
public register: Register
|
||||||
public destroy: () => void
|
public destroy: () => void
|
||||||
public use: UsePlugin
|
public use: UsePlugin
|
||||||
@@ -193,6 +195,8 @@ export default class Editor {
|
|||||||
this.listener = new Listener()
|
this.listener = new Listener()
|
||||||
// 事件
|
// 事件
|
||||||
this.eventBus = new EventBus<EventBusMap>()
|
this.eventBus = new EventBus<EventBusMap>()
|
||||||
|
// 重写
|
||||||
|
this.override = new Override()
|
||||||
// 启动
|
// 启动
|
||||||
const draw = new Draw(
|
const draw = new Draw(
|
||||||
container,
|
container,
|
||||||
@@ -203,7 +207,8 @@ export default class Editor {
|
|||||||
footer: footerElementList
|
footer: footerElementList
|
||||||
},
|
},
|
||||||
this.listener,
|
this.listener,
|
||||||
this.eventBus
|
this.eventBus,
|
||||||
|
this.override
|
||||||
)
|
)
|
||||||
// 命令
|
// 命令
|
||||||
this.command = new Command(new CommandAdapt(draw))
|
this.command = new Command(new CommandAdapt(draw))
|
||||||
|
|||||||
Reference in New Issue
Block a user