Commit e99c75d7 authored by Fred Chasen's avatar Fred Chasen

Merge branch 'issue-278-render-result' into 'master'

resolves #278 introduce a RenderResult object

Closes #278

See merge request !148
parents 89ad08e3 426b022e
Pipeline #746 passed with stage
in 4 minutes and 41 seconds
import {getBoundingClientRect, getClientRects} from "../utils/utils";
import { getBoundingClientRect, getClientRects } from "../utils/utils";
import {
breakInsideAvoidParentNode,
child,
......@@ -24,7 +24,8 @@ import {
walk,
words
} from "../utils/dom";
import BreakToken from "./breaktoken";
import BreakToken from "./breaktoken";
import RenderResult, { OverflowContentError } from "./renderresult";
import EventEmitter from "event-emitter";
import Hook from "../utils/hook";
......@@ -94,9 +95,9 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", prevNode);
return undefined;
return new RenderResult(undefined, new OverflowContentError("Unable to layout item", [prevNode]));
}
return newBreakToken;
return new RenderResult(newBreakToken);
}
this.hooks && this.hooks.layoutNode.trigger(node);
......@@ -118,7 +119,7 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", node);
return undefined;
return new RenderResult(undefined, new OverflowContentError("Unable to layout item", [node]));
}
length = 0;
......@@ -172,7 +173,7 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", node);
return undefined;
return new RenderResult(undefined, new OverflowContentError("Unable to layout item", [node]));
}
if (newBreakToken) {
......@@ -182,7 +183,7 @@ class Layout {
}
return newBreakToken;
return new RenderResult(newBreakToken);
}
breakAt(node, offset = 0) {
......
......@@ -127,8 +127,9 @@ class Page {
this.layoutMethod = new Layout(this.area, this.hooks, maxChars);
let newBreakToken = await this.layoutMethod.renderTo(this.wrapper, contents, breakToken);
let renderResult = await this.layoutMethod.renderTo(this.wrapper, contents, breakToken);
let newBreakToken = renderResult.breakToken;
this.addListeners(contents);
this.endToken = newBreakToken;
......@@ -142,7 +143,8 @@ class Page {
return this.layout(contents, breakToken);
}
let newBreakToken = await this.layoutMethod.renderTo(this.wrapper, contents, breakToken);
let renderResult = await this.layoutMethod.renderTo(this.wrapper, contents, breakToken);
let newBreakToken = renderResult.breakToken;
this.endToken = newBreakToken;
......
/**
* Render result.
* @class
*/
class RenderResult {
constructor(breakToken, error) {
this.breakToken = breakToken;
this.error = error;
}
}
export class OverflowContentError extends Error {
constructor(message, items) {
super(message);
this.items = items;
}
}
export default RenderResult;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment