pdf-to-markdown/src/javascript/models/AppState.jsx

60 lines
1.9 KiB
React
Raw Normal View History

2017-01-06 20:49:37 +01:00
import { Enum } from 'enumify';
import NoOp from './transformations/NoOp.jsx';
import RoundCoordinates from './transformations/RoundCoordinates.jsx';
import CombineSameY from './transformations/CombineSameY.jsx';
import DetectFootnotes from './transformations/DetectFootnotes.jsx'
import RemoveRepetitiveElements from './transformations/RemoveRepetitiveElements.jsx'
2017-02-05 09:58:25 +01:00
import HeadlineDetector from './transformations/HeadlineDetector.jsx'
import HeadlineToUppercase from './transformations/HeadlineToUppercase.jsx'
import ToTextPages from './transformations/ToTextPages.jsx';
import ToSingleTextPage from './transformations/ToSingleTextPage.jsx'
2017-01-07 11:38:06 +01:00
2017-01-06 20:49:37 +01:00
// Holds the state of the Application
export default class AppState {
constructor(options) {
this.renderFunction = options.renderFunction;
this.mainView = View.UPLOAD;
2017-01-09 20:08:32 +01:00
this.fileBuffer;
2017-01-06 20:49:37 +01:00
this.pdfPages = [];
this.transformations = [
new NoOp,
new RoundCoordinates(),
new CombineSameY(),
new DetectFootnotes(),
new RemoveRepetitiveElements(),
2017-02-05 09:58:25 +01:00
new HeadlineDetector(),
new HeadlineToUppercase(),
new ToTextPages(),
new ToSingleTextPage()];
2017-01-06 20:49:37 +01:00
//bind functions
this.render = this.render.bind(this);
2017-01-09 20:08:32 +01:00
this.storeFileBuffer = this.storeFileBuffer.bind(this);
this.storePdfPages = this.storePdfPages.bind(this);
2017-01-06 20:49:37 +01:00
}
render() {
this.renderFunction(this)
}
2017-01-09 20:08:32 +01:00
// the uploaded pdf as file buffer
storeFileBuffer(fileBuffer:ArrayBuffer) {
this.fileBuffer = fileBuffer;
2017-01-06 20:49:37 +01:00
this.mainView = View.LOADING;
this.render()
}
2017-01-09 20:08:32 +01:00
storePdfPages(pdfPages) {
this.pdfPages = pdfPages;
this.fileBuffer = null;
2017-01-22 19:04:23 +01:00
this.mainView = View.DEBUG;
2017-01-09 20:08:32 +01:00
this.render();
2017-01-06 20:49:37 +01:00
}
}
export class View extends Enum {
}
2017-01-22 19:04:23 +01:00
View.initEnum(['UPLOAD', 'LOADING', 'DEBUG'])