feat: add history max record option #203
This commit is contained in:
@@ -39,8 +39,8 @@ interface IEditorOption {
|
|||||||
resizerColor?: string; // 图片尺寸器颜色。默认:#4182D9
|
resizerColor?: string; // 图片尺寸器颜色。默认:#4182D9
|
||||||
resizerSize?: number; // 图片尺寸器大小。默认:5
|
resizerSize?: number; // 图片尺寸器大小。默认:5
|
||||||
marginIndicatorSize?: number; // 页边距指示器长度。默认:35
|
marginIndicatorSize?: number; // 页边距指示器长度。默认:35
|
||||||
marginIndicatorColor?: string, // 页边距指示器颜色。默认:#BABABA
|
marginIndicatorColor?: string; // 页边距指示器颜色。默认:#BABABA
|
||||||
margins?: IMargin, // 页面边距。默认:[100, 120, 100, 120]
|
margins?: IMargin; // 页面边距。默认:[100, 120, 100, 120]
|
||||||
pageMode?: PageMode; // 纸张模式:连页、分页。默认:分页
|
pageMode?: PageMode; // 纸张模式:连页、分页。默认:分页
|
||||||
tdPadding?: number; // 单元格内边距。默认:5
|
tdPadding?: number; // 单元格内边距。默认:5
|
||||||
defaultTrMinHeight?: number; // 默认表格行最小高度。默认:40
|
defaultTrMinHeight?: number; // 默认表格行最小高度。默认:40
|
||||||
@@ -50,6 +50,7 @@ interface IEditorOption {
|
|||||||
pageNumber?: IPageNumber; // 页码信息。{bottom:number; size:number; font:string; color:string; rowFlex:RowFlex; format:string; numberType:NumberType;}
|
pageNumber?: IPageNumber; // 页码信息。{bottom:number; size:number; font:string; color:string; rowFlex:RowFlex; format:string; numberType:NumberType;}
|
||||||
paperDirection?: PaperDirection; // 纸张方向:纵向、横向
|
paperDirection?: PaperDirection; // 纸张方向:纵向、横向
|
||||||
inactiveAlpha?: number; // 正文内容失焦时透明度。默认值:0.6
|
inactiveAlpha?: number; // 正文内容失焦时透明度。默认值:0.6
|
||||||
|
historyMaxRecordCount: number; // 历史(撤销重做)最大记录次数。默认:100次
|
||||||
watermark?: IWatermark; // 水印信息。{data:string; color?:string; opacity?:number; size?:number; font?:string;}
|
watermark?: IWatermark; // 水印信息。{data:string; color?:string; opacity?:number; size?:number; font?:string;}
|
||||||
control?: IControlOption; // 控件信息。 {placeholderColor?:string; bracketColor?:string; prefix?:string; postfix?:string;}
|
control?: IControlOption; // 控件信息。 {placeholderColor?:string; bracketColor?:string; prefix?:string; postfix?:string;}
|
||||||
checkbox?: ICheckboxOption; // 复选框信息。{width?:number; height?:number; gap?:number; lineWidth?:number; fillStyle?:string; fontStyle?: string;}
|
checkbox?: ICheckboxOption; // 复选框信息。{width?:number; height?:number; gap?:number; lineWidth?:number; fillStyle?:string; fontStyle?: string;}
|
||||||
@@ -118,4 +119,4 @@ interface IPlaceholder {
|
|||||||
size?: number; // 字体大小。默认:16
|
size?: number; // 字体大小。默认:16
|
||||||
font?: string; // 字体。默认:Yahei
|
font?: string; // 字体。默认:Yahei
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export class Draw {
|
|||||||
this._createPage(0)
|
this._createPage(0)
|
||||||
|
|
||||||
this.i18n = new I18n()
|
this.i18n = new I18n()
|
||||||
this.historyManager = new HistoryManager()
|
this.historyManager = new HistoryManager(this)
|
||||||
this.position = new Position(this)
|
this.position = new Position(this)
|
||||||
this.zone = new Zone(this)
|
this.zone = new Zone(this)
|
||||||
this.range = new RangeManager(this)
|
this.range = new RangeManager(this)
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
|
import { Draw } from '../draw/Draw'
|
||||||
|
|
||||||
export class HistoryManager {
|
export class HistoryManager {
|
||||||
|
|
||||||
private readonly MAX_RECORD_COUNT = 1000
|
|
||||||
private undoStack: Array<Function> = []
|
private undoStack: Array<Function> = []
|
||||||
private redoStack: Array<Function> = []
|
private redoStack: Array<Function> = []
|
||||||
|
private maxRecordCount: number
|
||||||
|
|
||||||
|
constructor(draw: Draw) {
|
||||||
|
// 忽略第一次历史记录
|
||||||
|
this.maxRecordCount = draw.getOptions().historyMaxRecordCount + 1
|
||||||
|
}
|
||||||
|
|
||||||
public undo() {
|
public undo() {
|
||||||
if (this.undoStack.length > 1) {
|
if (this.undoStack.length > 1) {
|
||||||
@@ -27,7 +34,7 @@ export class HistoryManager {
|
|||||||
if (this.redoStack.length) {
|
if (this.redoStack.length) {
|
||||||
this.redoStack = []
|
this.redoStack = []
|
||||||
}
|
}
|
||||||
while (this.undoStack.length > this.MAX_RECORD_COUNT) {
|
while (this.undoStack.length > this.maxRecordCount) {
|
||||||
this.undoStack.shift()
|
this.undoStack.shift()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ export default class Editor {
|
|||||||
defaultHyperlinkColor: '#0000FF',
|
defaultHyperlinkColor: '#0000FF',
|
||||||
paperDirection: PaperDirection.VERTICAL,
|
paperDirection: PaperDirection.VERTICAL,
|
||||||
inactiveAlpha: 0.6,
|
inactiveAlpha: 0.6,
|
||||||
|
historyMaxRecordCount: 100,
|
||||||
...options,
|
...options,
|
||||||
header: headerOptions,
|
header: headerOptions,
|
||||||
footer: footerOptions,
|
footer: footerOptions,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export interface IEditorOption {
|
|||||||
defaultHyperlinkColor?: string;
|
defaultHyperlinkColor?: string;
|
||||||
paperDirection?: PaperDirection;
|
paperDirection?: PaperDirection;
|
||||||
inactiveAlpha?: number;
|
inactiveAlpha?: number;
|
||||||
|
historyMaxRecordCount?: number;
|
||||||
header?: IHeader;
|
header?: IHeader;
|
||||||
footer?: IFooter;
|
footer?: IFooter;
|
||||||
pageNumber?: IPageNumber;
|
pageNumber?: IPageNumber;
|
||||||
|
|||||||
Reference in New Issue
Block a user