PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / vendors / imask / esm / controls / input-history.js

input-history.js in Booking Calendar 11.9, at vendors/imask/esm/controls/input-history.js

37 lines 932 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 class InputHistory {
2 constructor() {
3 this.states = [];
4 this.currentIndex = 0;
5 }
6 get currentState() {
7 return this.states[this.currentIndex];
8 }
9 get isEmpty() {
10 return this.states.length === 0;
11 }
12 push(state) {
13 // if current index points before the last element then remove the future
14 if (this.currentIndex < this.states.length - 1) this.states.length = this.currentIndex + 1;
15 this.states.push(state);
16 if (this.states.length > InputHistory.MAX_LENGTH) this.states.shift();
17 this.currentIndex = this.states.length - 1;
18 }
19 go(steps) {
20 this.currentIndex = Math.min(Math.max(this.currentIndex + steps, 0), this.states.length - 1);
21 return this.currentState;
22 }
23 undo() {
24 return this.go(-1);
25 }
26 redo() {
27 return this.go(+1);
28 }
29 clear() {
30 this.states.length = 0;
31 this.currentIndex = 0;
32 }
33 }
34 InputHistory.MAX_LENGTH = 100;
35
36 export { InputHistory as default };
37