mirror of
https://github.com/maputnik/editor.git
synced 2026-09-11 06:47:25 +00:00
656264f2bc
This is in continue to: - #850 - #848 The last files should be converted as part of this PR, there are only a handful left.
42 lines
883 B
TypeScript
42 lines
883 B
TypeScript
import type {StyleSpecification} from "maplibre-gl";
|
|
|
|
export class RevisionStore {
|
|
revisions: (StyleSpecification & {id: string})[];
|
|
currentIdx: number;
|
|
|
|
|
|
constructor(initialRevisions=[]) {
|
|
this.revisions = initialRevisions
|
|
this.currentIdx = initialRevisions.length - 1
|
|
}
|
|
|
|
get latest() {
|
|
return this.revisions[this.revisions.length - 1]
|
|
}
|
|
|
|
get current() {
|
|
return this.revisions[this.currentIdx]
|
|
}
|
|
|
|
addRevision(revision: StyleSpecification & {id: string}) {
|
|
//TODO: compare new revision style id with old ones
|
|
//and ensure that it is always the same id
|
|
this.revisions.push(revision)
|
|
this.currentIdx++
|
|
}
|
|
|
|
undo() {
|
|
if(this.currentIdx > 0) {
|
|
this.currentIdx--;
|
|
}
|
|
return this.current;
|
|
}
|
|
|
|
redo() {
|
|
if(this.currentIdx < this.revisions.length - 1) {
|
|
this.currentIdx++
|
|
}
|
|
return this.current;
|
|
}
|
|
}
|