pdf-to-markdown/oldSrc/javascript/models/LineItemBlock.jsx
2024-03-26 10:52:54 -06:00

37 lines
1006 B
JavaScript

import PageItem from './PageItem.jsx'
import LineItem from './LineItem.jsx'
// A block of LineItem[] within a Page
export default class LineItemBlock extends PageItem {
constructor(options) {
super(options);
this.items = [];
if (options.items) {
options.items.forEach(item => this.addItem(item));
}
}
addItem(item:LineItem) {
if (this.type && item.type && this.type !== item.type) {
throw `Adding item of type ${item.type} to block of type ${this.type}`
}
if (!this.type) {
this.type = item.type;
}
if (item.parsedElements) {
if (this.parsedElements) {
this.parsedElements.add(item.parsedElements);
} else {
this.parsedElements = item.parsedElements;
}
}
const copiedItem = new LineItem({
...item
});
copiedItem.type = null;
this.items.push(copiedItem);
}
}