@gorpacrate/core-graphics
Version:
A core library for creating shape-based graphic editors
82 lines (81 loc) • 3.31 kB
TypeScript
import { IShapeData } from '../declarations/shapes';
import { IEvent } from '../event-sourcing/declarations';
export declare type IHistoryEvent = IShapeAddEvent | IShapeUpdateEvent | IShapeRemoveEvent | IShapeChangeOrderEvent | IEraseAllEvent | IHistoryEventsGroup | IIdentityEvent;
export declare function isHistoryEvent(event: IHistoryEvent | void): event is IHistoryEvent;
export interface IPersistedHistoryEvent extends IEvent {
id: string;
author: string;
applied: boolean;
ev: IHistoryEvent;
}
export declare function isPersistedHistoryEvent(event: IPersistedHistoryEvent | undefined): event is IPersistedHistoryEvent;
export interface IPersistedHistoryEventParams {
id: string;
author: string;
applied?: boolean;
}
export declare function getPersistedHistoryEvent(params: IPersistedHistoryEventParams, ev: IHistoryEvent): IPersistedHistoryEvent;
export declare function getHistoryEventFromPersisted(persisted: IPersistedHistoryEvent): IHistoryEvent;
export declare const enum HistoryEventType {
Identity = 0,
AddShape = 1,
UpdateShape = 2,
RemoveShape = 3,
ChangeShapeOrder = 4,
EraseAll = 5,
Grouped = 6
}
export interface IIdentityEvent {
type: HistoryEventType.Identity;
}
export interface IShapeAddEvent {
type: HistoryEventType.AddShape;
payload: IShapeData;
}
export interface IShapeUpdateEvent {
type: HistoryEventType.UpdateShape;
payload: {
id: string;
shapeData: IShapeData;
};
}
export interface IShapeRemoveEvent {
type: HistoryEventType.RemoveShape;
payload: {
id: string;
};
}
export interface IShapeChangeOrderEvent {
type: HistoryEventType.ChangeShapeOrder;
payload: {
id: string;
value: number;
relative: boolean;
};
}
export interface IEraseAllEvent {
type: HistoryEventType.EraseAll;
}
export interface IHistoryEventsGroup {
type: HistoryEventType.Grouped;
payload: IHistoryEvent[];
}
export declare function isIdentityEvent(base: IHistoryEvent): base is IIdentityEvent;
export declare function isShapeAddEvent(base: IHistoryEvent): base is IShapeAddEvent;
export declare function isShapeUpdateEvent(base: IHistoryEvent): base is IShapeUpdateEvent;
export declare function isShapeRemoveEvent(base: IHistoryEvent): base is IShapeRemoveEvent;
export declare function isShapeChangeOrderEvent(base: IHistoryEvent): base is IShapeChangeOrderEvent;
export declare function isEraseAllEvent(base: IHistoryEvent): base is IEraseAllEvent;
export declare function isHistoryEventsGroup(base: IHistoryEvent): base is IHistoryEventsGroup;
export declare function identityHistoryEvent(): IIdentityEvent;
export declare function shapeAddEvent(shapeData: IShapeData): IShapeAddEvent;
export declare function shapeUpdateEvent(id: string, shapeData: IShapeData): IShapeUpdateEvent;
export declare function shapeRemoveEvent(shapeId: string): IShapeRemoveEvent;
export declare function shapesRemoveEvent(shapesIds: string[]): IHistoryEventsGroup;
export declare function shapeChangeOrderEvent(params: {
shapeId: string;
value: number;
relative: boolean;
}): IShapeChangeOrderEvent;
export declare function eraseAllEvent(): IEraseAllEvent;
export declare function historyEventsGroup(events: IHistoryEvent[]): IHistoryEventsGroup;