Commit 426b022e authored by Guillaume's avatar Guillaume

resolves #278 introduce a RenderResult object

parent dd209156
Pipeline #701 passed with stage
in 4 minutes and 10 seconds
import {getBoundingClientRect, getClientRects} from "../utils/utils"; import { getBoundingClientRect, getClientRects } from "../utils/utils";
import { import {
breakInsideAvoidParentNode, breakInsideAvoidParentNode,
child, child,
...@@ -24,7 +24,8 @@ import { ...@@ -24,7 +24,8 @@ import {
walk, walk,
words words
} from "../utils/dom"; } from "../utils/dom";
import BreakToken from "./breaktoken"; import BreakToken from "./breaktoken";
import RenderResult, { OverflowContentError } from "./renderresult";
import EventEmitter from "event-emitter"; import EventEmitter from "event-emitter";
import Hook from "../utils/hook"; import Hook from "../utils/hook";
...@@ -93,9 +94,9 @@ class Layout { ...@@ -93,9 +94,9 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) { if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", prevNode); 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); this.hooks && this.hooks.layoutNode.trigger(node);
...@@ -117,7 +118,7 @@ class Layout { ...@@ -117,7 +118,7 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) { if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", node); console.warn("Unable to layout item: ", node);
return undefined; return new RenderResult(undefined, new OverflowContentError("Unable to layout item", [node]));
} }
length = 0; length = 0;
...@@ -171,7 +172,7 @@ class Layout { ...@@ -171,7 +172,7 @@ class Layout {
if (newBreakToken && newBreakToken.equals(prevBreakToken)) { if (newBreakToken && newBreakToken.equals(prevBreakToken)) {
console.warn("Unable to layout item: ", node); console.warn("Unable to layout item: ", node);
return undefined; return new RenderResult(undefined, new OverflowContentError("Unable to layout item", [node]));
} }
if (newBreakToken) { if (newBreakToken) {
...@@ -181,7 +182,7 @@ class Layout { ...@@ -181,7 +182,7 @@ class Layout {
} }
return newBreakToken; return new RenderResult(newBreakToken);
} }
breakAt(node, offset = 0) { breakAt(node, offset = 0) {
......
...@@ -125,8 +125,9 @@ class Page { ...@@ -125,8 +125,9 @@ class Page {
this.layoutMethod = new Layout(this.area, this.hooks, maxChars); 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.addListeners(contents);
this.endToken = newBreakToken; this.endToken = newBreakToken;
...@@ -140,7 +141,8 @@ class Page { ...@@ -140,7 +141,8 @@ class Page {
return this.layout(contents, breakToken); 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; 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