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

83 lines
2.8 KiB
React
Raw Normal View History

2017-01-06 20:49:37 +01:00
import { Enum } from 'enumify';
import CalculateGlobalStats from './transformations/textitem/CalculateGlobalStats.jsx';
import CompactLines from './transformations/textitem/CompactLines.jsx';
import RemoveRepetitiveElements from './transformations/textitem/RemoveRepetitiveElements.jsx'
import VerticalToHorizontal from './transformations/textitem/VerticalToHorizontal.jsx';
import PostprocessLines from './transformations/textitem/PostprocessLines.jsx';
import DetectTOC from './transformations/textitem/DetectTOC.jsx'
import DetectListItems from './transformations/textitem/DetectListItems.jsx'
import DetectHeaders from './transformations/textitem/DetectHeaders.jsx'
import GatherBlocks from './transformations/textitemblock/GatherBlocks.jsx'
import DetectCodeQuoteBlocks from './transformations/textitemblock/DetectCodeQuoteBlocks.jsx'
import DetectListLevels from './transformations/textitemblock/DetectListLevels.jsx'
2017-02-22 23:18:49 +01:00
// import DetectFormats from './transformations/DetectFormats.jsx'
// import HeadlineToUppercase from './transformations/HeadlineToUppercase.jsx'
import ToTextBlocks from './transformations/ToTextBlocks.jsx';
2017-02-06 19:13:43 +01:00
import ToMarkdown from './transformations/ToMarkdown.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-03-07 21:59:15 +01:00
this.pages = [];
2017-03-21 23:12:45 +01:00
this.fontMap;
this.transformations = [
2017-02-15 07:33:07 +01:00
new CalculateGlobalStats(),
new CompactLines(),
new RemoveRepetitiveElements(),
new VerticalToHorizontal(),
new PostprocessLines(),
new DetectTOC(),
2017-03-11 13:42:09 +01:00
new DetectListItems(),
new DetectHeaders(),
new GatherBlocks(),
2017-03-14 10:30:21 +01:00
new DetectCodeQuoteBlocks(),
2017-03-11 13:42:09 +01:00
new DetectListLevels(),
// new DetectFormats(),
// new HeadlineToUppercase(),
new ToTextBlocks(),
2017-02-06 19:13:43 +01:00
new ToMarkdown()];
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-02-06 19:13:43 +01:00
this.switchMainView = this.switchMainView.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-03-21 23:12:45 +01:00
storePdfPages(pages, fontMap) {
2017-03-07 21:59:15 +01:00
this.pages = pages;
2017-03-21 23:12:45 +01:00
this.fontMap = fontMap;
2017-01-09 20:08:32 +01:00
this.fileBuffer = null;
2017-02-06 19:13:43 +01:00
this.mainView = View.RESULT;
this.render();
}
switchMainView(view) {
this.mainView = view;
2017-01-09 20:08:32 +01:00
this.render();
2017-01-06 20:49:37 +01:00
}
}
export class View extends Enum {
}
2017-02-06 19:13:43 +01:00
View.initEnum(['UPLOAD', 'LOADING', 'RESULT', 'DEBUG'])