feat:add image display contextmenu
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { IElement } from '../..'
|
import { IElement, ImageDisplay } from '../..'
|
||||||
import { EditorMode, PageMode } from '../../dataset/enum/Editor'
|
import { EditorMode, PageMode } from '../../dataset/enum/Editor'
|
||||||
import { RowFlex } from '../../dataset/enum/Row'
|
import { RowFlex } from '../../dataset/enum/Row'
|
||||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
||||||
@@ -59,6 +59,7 @@ export class Command {
|
|||||||
private static print: CommandAdapt['print']
|
private static print: CommandAdapt['print']
|
||||||
private static replaceImageElement: CommandAdapt['replaceImageElement']
|
private static replaceImageElement: CommandAdapt['replaceImageElement']
|
||||||
private static saveAsImageElement: CommandAdapt['saveAsImageElement']
|
private static saveAsImageElement: CommandAdapt['saveAsImageElement']
|
||||||
|
private static changeImageDisplay: CommandAdapt['changeImageDisplay']
|
||||||
private static getImage: CommandAdapt['getImage']
|
private static getImage: CommandAdapt['getImage']
|
||||||
private static getValue: CommandAdapt['getValue']
|
private static getValue: CommandAdapt['getValue']
|
||||||
private static getWordCount: CommandAdapt['getWordCount']
|
private static getWordCount: CommandAdapt['getWordCount']
|
||||||
@@ -122,6 +123,7 @@ export class Command {
|
|||||||
Command.print = adapt.print.bind(adapt)
|
Command.print = adapt.print.bind(adapt)
|
||||||
Command.replaceImageElement = adapt.replaceImageElement.bind(adapt)
|
Command.replaceImageElement = adapt.replaceImageElement.bind(adapt)
|
||||||
Command.saveAsImageElement = adapt.saveAsImageElement.bind(adapt)
|
Command.saveAsImageElement = adapt.saveAsImageElement.bind(adapt)
|
||||||
|
Command.changeImageDisplay = adapt.changeImageDisplay.bind(adapt)
|
||||||
Command.getImage = adapt.getImage.bind(adapt)
|
Command.getImage = adapt.getImage.bind(adapt)
|
||||||
Command.getValue = adapt.getValue.bind(adapt)
|
Command.getValue = adapt.getValue.bind(adapt)
|
||||||
Command.getWordCount = adapt.getWordCount.bind(adapt)
|
Command.getWordCount = adapt.getWordCount.bind(adapt)
|
||||||
@@ -342,6 +344,10 @@ export class Command {
|
|||||||
return Command.saveAsImageElement()
|
return Command.saveAsImageElement()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeChangeImageDisplay(element: IElement, display: ImageDisplay) {
|
||||||
|
return Command.changeImageDisplay(element, display)
|
||||||
|
}
|
||||||
|
|
||||||
public getImage(): string[] {
|
public getImage(): string[] {
|
||||||
return Command.getImage()
|
return Command.getImage()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { WRAP, ZERO } from '../../dataset/constant/Common'
|
import { WRAP, ZERO } from '../../dataset/constant/Common'
|
||||||
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
|
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
|
||||||
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
|
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
|
||||||
import { ControlComponent } from '../../dataset/enum/Control'
|
import { ControlComponent, ImageDisplay } from '../../dataset/enum/Control'
|
||||||
import { EditorContext, EditorMode, PageMode } from '../../dataset/enum/Editor'
|
import { EditorContext, EditorMode, PageMode } from '../../dataset/enum/Editor'
|
||||||
import { ElementType } from '../../dataset/enum/Element'
|
import { ElementType } from '../../dataset/enum/Element'
|
||||||
import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
|
import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
|
||||||
@@ -1355,6 +1355,15 @@ export class CommandAdapt {
|
|||||||
downloadFile(element.value, `${element.id!}.png`)
|
downloadFile(element.value, `${element.id!}.png`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public changeImageDisplay(element: IElement, display: ImageDisplay) {
|
||||||
|
if (element.imgDisplay === display) return
|
||||||
|
element.imgDisplay = display
|
||||||
|
this.draw.getPreviewer().clearResizer()
|
||||||
|
this.draw.render({
|
||||||
|
isSetCursor: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public getImage(): string[] {
|
public getImage(): string[] {
|
||||||
return this.draw.getDataURL()
|
return this.draw.getDataURL()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { ImageDisplay } from '../../../dataset/enum/Control'
|
||||||
import { ElementType } from '../../../dataset/enum/Element'
|
import { ElementType } from '../../../dataset/enum/Element'
|
||||||
import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
|
import { IContextMenuContext, IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
|
||||||
import { Command } from '../../command/Command'
|
import { Command } from '../../command/Command'
|
||||||
|
|
||||||
export const imageMenus: IRegisterContextMenu[] = [
|
export const imageMenus: IRegisterContextMenu[] = [
|
||||||
@@ -36,5 +37,28 @@ export const imageMenus: IRegisterContextMenu[] = [
|
|||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeSaveAsImageElement()
|
command.executeSaveAsImageElement()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '文字环绕',
|
||||||
|
when: (payload) => {
|
||||||
|
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
||||||
|
},
|
||||||
|
childMenus: [
|
||||||
|
{
|
||||||
|
name: '嵌入型',
|
||||||
|
when: () => true,
|
||||||
|
callback: (command: Command, context: IContextMenuContext) => {
|
||||||
|
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.BLOCK)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '上下型环绕',
|
||||||
|
when: () => true,
|
||||||
|
callback: (command: Command, context: IContextMenuContext) => {
|
||||||
|
command.executeChangeImageDisplay(context.startElement!, ImageDisplay.INLINE)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -571,9 +571,10 @@ export class Draw {
|
|||||||
const elementWidth = element.width! * scale
|
const elementWidth = element.width! * scale
|
||||||
const elementHeight = element.height! * scale
|
const elementHeight = element.height! * scale
|
||||||
// 图片超出尺寸后自适应
|
// 图片超出尺寸后自适应
|
||||||
if (curRow.width + elementWidth > innerWidth) {
|
const curRowWidth = element.imgDisplay === ImageDisplay.INLINE ? 0 : curRow.width
|
||||||
|
if (curRowWidth + elementWidth > innerWidth) {
|
||||||
// 计算剩余大小
|
// 计算剩余大小
|
||||||
const surplusWidth = innerWidth - curRow.width
|
const surplusWidth = innerWidth - curRowWidth
|
||||||
element.width = surplusWidth
|
element.width = surplusWidth
|
||||||
element.height = elementHeight * surplusWidth / elementWidth
|
element.height = elementHeight * surplusWidth / elementWidth
|
||||||
metrics.width = element.width
|
metrics.width = element.width
|
||||||
|
|||||||
Reference in New Issue
Block a user