aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/UndoStack.tsx
blob: f5af09e5b3c1a2af9d0f723a17cdbe0e0110dba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { UndoManager } from '../util/UndoManager';
import './UndoStack.scss';

interface UndoStackProps {
    width?: number;
    height?: number;
    inline?: boolean;
}
@observer
export class UndoStack extends React.Component<UndoStackProps> {
    @observable static HideInline: boolean;
    @observable static Expand: boolean;
    render() {
        return this.props.inline && UndoStack.HideInline ? null : (
            <div
                className="undoStack-outerContainer"
                style={{ width: this.props.width, height: this.props.height ? (UndoStack.Expand ? 4 : 1) * this.props.height : undefined, top: UndoStack.Expand && this.props.height ? -this.props.height * 3 : undefined }}
                onClick={action(e => (UndoStack.Expand = !UndoStack.Expand))}
                onDoubleClick={action(e => (UndoStack.Expand = UndoStack.HideInline = false))}>
                <div className="undoStack-commandsContainer" ref={r => r?.scroll({ behavior: 'auto', top: r?.scrollHeight + 20 })} style={{ background: UndoManager.batchCounter.get() ? 'yellow' : undefined }}>
                    <div className="undoStack-resultContainer" key={0}>
                        <div className="undoStack-commandString" style={{ fontWeight: 'bold', textAlign: 'center' }}>
                            Undo/Redo Stack
                        </div>
                    </div>
                    {UndoManager.undoStackNames.map((name, i) => (
                        <div className="undoStack-resultContainer" key={i}>
                            <div className="undoStack-commandString">{name.replace(/[^\.]*\./, '')}</div>
                        </div>
                    ))}
                    {Array.from(UndoManager.redoStackNames)
                        .reverse()
                        .map((name, i) => (
                            <div className="undoStack-resultContainer" key={i}>
                                <div className="undoStack-commandString" style={{ fontWeight: 'bold', color: 'red' }}>
                                    {name.replace(/[^\.]*\./, '')}
                                </div>
                            </div>
                        ))}
                </div>
            </div>
        );
    }
}