feat:data persistence

This commit is contained in:
黄云飞
2021-12-29 20:42:34 +08:00
parent e4002c3415
commit 8a4688cfd1
8 changed files with 119 additions and 5 deletions
+16
View File
@@ -7,12 +7,14 @@ import { KeyMap } from "../../dataset/enum/Keymap"
import { IElement } from "../../interface/Element"
import { ICurrentPosition } from "../../interface/Position"
import { writeTextByElementList } from "../../utils/clipboard"
import { zipElementList } from "../../utils/element"
import { Cursor } from "../cursor/Cursor"
import { Draw } from "../draw/Draw"
import { HyperlinkParticle } from "../draw/particle/HyperlinkParticle"
import { ImageParticle } from "../draw/particle/ImageParticle"
import { TableTool } from "../draw/particle/table/TableTool"
import { HistoryManager } from "../history/HistoryManager"
import { Listener } from "../listener/Listener"
import { Position } from "../position/Position"
import { RangeManager } from "../range/RangeManager"
@@ -32,6 +34,7 @@ export class CanvasEvent {
private imageParticle: ImageParticle
private tableTool: TableTool
private hyperlinkParticle: HyperlinkParticle
private listener: Listener
constructor(draw: Draw) {
this.isAllowDrag = false
@@ -48,6 +51,7 @@ export class CanvasEvent {
this.imageParticle = this.draw.getImageParticle()
this.tableTool = this.draw.getTableTool()
this.hyperlinkParticle = this.draw.getHyperlinkParticle()
this.listener = this.draw.getListener()
}
public register() {
@@ -349,6 +353,12 @@ export class CanvasEvent {
this.cut()
} else if (evt.ctrlKey && evt.key === KeyMap.A) {
this.selectAll()
} else if (evt.ctrlKey && evt.key === KeyMap.S) {
const saved = this.listener.saved
if (saved) {
saved(this.save())
}
evt.preventDefault()
}
}
@@ -445,4 +455,10 @@ export class CanvasEvent {
this.isCompositing = false
}
public save(): IElement[] {
const elementList = this.draw.getOriginalElementList()
const data = zipElementList(elementList)
return data
}
}
+3
View File
@@ -3,6 +3,7 @@ import {
IPageScaleChange,
IPageSizeChange,
IRangeStyleChange,
ISaved,
IVisiblePageNoListChange
} from "../../interface/Listener"
@@ -13,6 +14,7 @@ export class Listener {
public intersectionPageNoChange: IIntersectionPageNoChange | null
public pageSizeChange: IPageSizeChange | null
public pageScaleChange: IPageScaleChange | null
public saved: ISaved | null
constructor() {
this.rangeStyleChange = null
@@ -20,6 +22,7 @@ export class Listener {
this.intersectionPageNoChange = null
this.pageSizeChange = null
this.pageScaleChange = null
this.saved = null
}
}