@fabwcie/free-drawing / components/tools/UndoRedo/History
components/tools/UndoRedo/History
Classes
History
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:132
Undo / redo history of the changes of this user: shapes added, changed or removed by each change, and background color, at most historyLimit states. Changes of other users (collaboration) are not recorded, undo and redo keep them
Extended by
Constructors
Constructor
new History(
drawer):History
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:148
Create a history without change, the drawing being empty
Parameters
drawer
Drawer whose shapes are saved and restored
Returns
Properties
drawer
drawer:
Drawer
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:138
Drawer whose shapes are saved and restored
entries
entries:
HistoryEntry[] =[]
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:134
Changes of the drawing made by this user, oldest first
step
step:
number=0
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:136
Number of entries done: entries before it are undone by undo, entries from it redone by redo
Accessors
appHistory
Get Signature
get appHistory():
string[]
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:159
States of previous versions: first item stands for the state before the oldest change, each other one is the JSON of a change (HistoryEntry)
Deprecated
changes are in entries
Returns
string[]
Items of states, as many as states kept
appHistoryStep
Get Signature
get appHistoryStep():
number
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:168
Index of current state in appHistory of previous versions
Deprecated
use step
Returns
number
Number of entries done
Methods
_apply()
private_apply(entry,side):boolean
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:408
Put the shapes of a change in their state before it (undo) or after it (redo), other shapes kept as they are (changes of other users). A shape changed by it and removed since by another user is not put back
Parameters
entry
Change of this user
side
"before" | "after"
State to restore: 'before' to undo, 'after' to redo
Returns
boolean
True when the drawing changed
_diff()
private_diff(known,current):HistoryEntry|null
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:289
Change between two states of the drawing
Parameters
known
Map<string, string>
Drawing as last recorded
current
Map<string, string>
Drawing now
Returns
HistoryEntry | null
Shapes added, changed and removed, with their places when needed; null without difference
_place()
private_place(ids,order):void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:479
Put shapes back at their place: above the nearest shape below them in given order which is in the drawing
Parameters
ids
Set<string>
Ids of shapes to place (added on top)
order
string[]
Ids of drawing shapes, bottom first (before of an entry undone, after of an entry redone)
Returns
void
_push()
private_push(entry):void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:323
Add an entry after the entries done (removes the ones undone), keeps the last ones
Parameters
entry
Change of this user, done
Returns
void
_read()
private_read():Map<string,string>
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:278
JSON of each drawing shape
Returns
Map<string, string>
JSON by id, bottom first
_readBackground()
private_readBackground():ColorLike
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:270
Background color of the drawing
Returns
Fill of the background rectangle
canRedo()
canRedo():
boolean
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:384
A change undone can be done again
Returns
boolean
True when redo can restore a next state
canUndo()
canUndo():
boolean
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:364
A change of this user can be undone
Returns
boolean
True when undo can restore a previous state
fileIds()
fileIds():
Set<string>
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:337
Image files of the shapes of the history (put back by undo or redo): kept by the drawer
Returns
Set<string>
Ids of the files of the images in the entries
ignoreBackground()
ignoreBackground():
void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:262
Background color changed by another user (collaboration): known as it is now, undo does not revert it
Returns
void
ignoreChanges()
ignoreChanges(
ids):void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:214
Shapes changed by other users (collaboration): their state becomes the known one, so the next change of this user records only its own modifications, and undo does not revert changes of others
Parameters
ids
Iterable<string>
Ids of shapes added, changed or removed by another user
Returns
void
ignoreMerged()
ignoreMerged(
merge):void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:247
Group or frame changed by another user while this user changed it (collaboration: both changes merged): the change of the other user is applied to its known state, so the next change of this user records only its own modifications (a change already recorded: known as it is now)
Parameters
merge
States of the merge
Returns
void
redo()
redo():
void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:391
Do again the last change undone, nothing when there is none (changes without effect dropped, as by undo)
Returns
void
reset()
reset():
void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:353
Current drawing is the first state (e.g. loaded from storage): nothing to undo or redo
Returns
void
saveState()
saveState(
fromSaved?):void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:177
Record the change of the drawing made since last record (on each drawer change), nothing when the drawing did not change
Parameters
fromSaved?
boolean = false
drawing loaded from a save: one change per shape added, so that each one can be undone
Returns
void
undo()
undo():
void
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:372
Undo the last change of this user, nothing when there is none. A change of shapes removed since by other users has nothing left to undo: it is dropped, and the one before is undone
Returns
void
Functions
getShapeState()
getShapeState(
shape):ShapeState
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:17
State of a drawing shape or group (history, collaboration, files), without draggable which depends on active tool
Parameters
shape
Drawing shape or group (with its shapes) to serialize
Returns
Konva object of the shape, draggable removed at every level
getStateInDrawing()
getStateInDrawing(
shape):ShapeState
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:27
State of a drawing shape at its place in the drawing: a shape of a group or of a frame selected alone takes the transform of its parents (drawing files of a selection, library items)
Parameters
shape
Drawing shape or group
Returns
State of getShapeState, with its position, rotation and scale in the drawing
mergeState()
mergeState(
target,base,current):ShapeState
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:69
State of a shape, group or frame where a change of this user is undone or redone over the changes of other users made since (collaboration, another tab), or where changes of two users are merged (collaboration): its nodes take their state of target where the change set them, nodes added in it by others are kept, nodes removed from it by others not put back, attributes changed by others kept where the change did not set them
Parameters
target
State to restore: before the change to undo it, after it to redo it (merge: state of this user)
base
State on the other side of the change
current
State now (merge: state of the other user)
Returns
State to create
serializeShape()
serializeShape(
shape):string
Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:55
JSON of a drawing shape state
Parameters
shape
Drawing shape or group to serialize
Returns
string
JSON string of getShapeState, states of history entries