-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9209f9
commit 6de07c0
Showing
9 changed files
with
286 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Context } from '@pictode/core'; | ||
|
||
import { Cmd, Command } from '../types'; | ||
|
||
export abstract class BaseCmd<T extends Cmd.Options = Cmd.Options> implements Command<T> { | ||
public context?: Context; | ||
public name: string; | ||
public id: number = 0; | ||
public executed: boolean = false; | ||
public options?: T; | ||
public executeTime: number = new Date().getTime(); | ||
|
||
constructor(context?: Context, options?: T) { | ||
this.context = context; | ||
this.name = this.constructor.name; | ||
this.options = options; | ||
} | ||
|
||
public abstract execute(): void; | ||
|
||
public abstract undo(): void; | ||
|
||
public toJSON(): Command<T> { | ||
return { | ||
id: this.id, | ||
name: this.name, | ||
options: this.options, | ||
executed: this.executed, | ||
executeTime: this.executeTime, | ||
}; | ||
} | ||
|
||
public fromJSON(json: Command<T>): void { | ||
this.id = json.id; | ||
this.name = json.name; | ||
this.options = json.options; | ||
this.executed = json.executed; | ||
this.executeTime = json.executeTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BaseError } from '@pictode/core'; | ||
|
||
import { BaseCmd } from '../commands/base'; | ||
|
||
export class CmdNotRegisterError extends BaseError { | ||
constructor(command: BaseCmd | string) { | ||
super(`${command instanceof BaseCmd ? command.name : command} not registered`); | ||
} | ||
} | ||
|
||
export class CmdNotOptionsError extends BaseError { | ||
constructor(command: BaseCmd | string) { | ||
super(`The options of the ${command instanceof BaseCmd ? command.name : command} command cannot be undefine`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
import { History } from './index'; | ||
export interface PluginMethods {} | ||
|
||
export namespace Cmd { | ||
export interface Options { | ||
[key: string]: any; | ||
} | ||
} | ||
|
||
export interface Options { | ||
enabled?: boolean; | ||
stackSize?: number; | ||
} | ||
|
||
export interface Command<T extends Cmd.Options = Cmd.Options> { | ||
id: number; | ||
name: string; | ||
options?: T; | ||
executed: boolean; | ||
executeTime: number; | ||
} | ||
|
||
export interface CmdStack { | ||
undoStack: Command[]; | ||
redoStack: Command[]; | ||
} | ||
|
||
export interface EventArgs { | ||
'stack:changed': CmdStack; | ||
'history:destroy': { | ||
history: History; | ||
}; | ||
'history:undo': { | ||
command: Command | undefined; | ||
step: number; | ||
}; | ||
'history:redo': { | ||
command: Command | undefined; | ||
step: number; | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.