@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
1,256 lines (1,255 loc) • 378 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/* eslint-disable */
import { WTableFormat, WRowFormat, WCellFormat } from '../format/index';
import { CharacterRangeType, FontScriptType } from '../../base/types';
import { WParagraphFormat, WCharacterFormat, WBorder, WBorders } from '../format/index';
import { isNullOrUndefined, createElement, classList } from '@syncfusion/ej2-base';
import { Dictionary } from '../../base/dictionary';
import { HelperMethods } from '../editor/editor-helper';
import { WebLayoutViewer } from './viewer';
import { Revision } from '../track-changes/track-changes';
/**
* @private
*/
var Rect = /** @class */ (function () {
function Rect(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
Object.defineProperty(Rect.prototype, "right", {
get: function () {
return this.x + this.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "bottom", {
get: function () {
return this.y + this.height;
},
enumerable: true,
configurable: true
});
/**
* @param currentBound
* @private
*/
Rect.prototype.isIntersecting = function (currentBound) {
if (currentBound.y > this.bottom || this.y > currentBound.bottom ||
currentBound.x > this.right || this.x > currentBound.right) {
return false;
}
return true;
};
/**
* @private
*/
Rect.prototype.clone = function () {
return new Rect(this.x, this.y, this.width, this.height);
};
return Rect;
}());
export { Rect };
/**
* @private
*/
var Padding = /** @class */ (function () {
function Padding(right, left, top, bottom) {
this.right = 10;
this.left = 10;
this.top = 10;
this.bottom = 10;
this.right = right;
this.left = left;
this.top = top;
this.bottom = bottom;
}
return Padding;
}());
export { Padding };
/**
* @private
*/
var Margin = /** @class */ (function () {
function Margin(leftMargin, topMargin, rightMargin, bottomMargin) {
this.left = leftMargin;
this.top = topMargin;
this.right = rightMargin;
this.bottom = bottomMargin;
}
Margin.prototype.clone = function () {
return new Margin(this.left, this.top, this.right, this.bottom);
};
Margin.prototype.destroy = function () {
this.left = undefined;
this.right = undefined;
this.top = undefined;
this.bottom = undefined;
};
return Margin;
}());
export { Margin };
/**
* @private
*/
var Widget = /** @class */ (function () {
function Widget() {
/**
* @private
*/
this.childWidgets = [];
/**
* @private
*/
this.x = 0;
/**
* @private
*/
this.y = 0;
/**
* @private
*/
this.width = 0;
/**
* @private
*/
this.height = 0;
/**
* @private
*/
this.index = 0;
}
Object.defineProperty(Widget.prototype, "indexInOwner", {
get: function () {
if (this instanceof BodyWidget && this.page) {
if (this.containerWidget instanceof FootNoteWidget) {
return this.containerWidget.bodyWidgets.indexOf(this);
}
else {
return this.page.bodyWidgets.indexOf(this);
}
}
else if (this.containerWidget && this.containerWidget.childWidgets) {
return this.containerWidget.childWidgets.indexOf(this);
}
else if (this instanceof FootNoteWidget) {
return 0;
}
return -1;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "firstChild", {
get: function () {
return this.childWidgets.length > 0 ? this.childWidgets[0] : undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "lastChild", {
get: function () {
if (this.childWidgets) {
return this.childWidgets.length > 0 ?
this.childWidgets[this.childWidgets.length - 1] : undefined;
}
return undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "previousWidget", {
get: function () {
var widget = this;
var index = this.indexInOwner;
if (widget instanceof BodyWidget) {
widget = index > 0 ? widget.page.bodyWidgets[index - 1] : undefined;
}
else {
widget = index > 0 ? widget.containerWidget.childWidgets[index - 1] : undefined;
}
return widget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "nextWidget", {
get: function () {
var widget = this;
var index = this.indexInOwner;
if (index === -1) {
return undefined;
}
if (widget instanceof BodyWidget) {
widget = index < widget.page.bodyWidgets.length - 1 ?
widget.page.bodyWidgets[index + 1] : undefined;
}
else {
widget = index < widget.containerWidget.childWidgets.length - 1 ?
widget.containerWidget.childWidgets[index + 1] : undefined;
}
return widget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "previousRenderedWidget", {
get: function () {
var widget = this;
var index = this.indexInOwner;
if (index < 0) {
return undefined;
}
if (widget instanceof BodyWidget) {
if (index > 0 && !(widget.containerWidget instanceof FootNoteWidget)) {
widget = widget.page.bodyWidgets[index - 1];
}
else if ((widget.containerWidget instanceof FootNoteWidget) && !widget.page.documentHelper.owner.editorModule.removeEditRange) {
if (index <= 0) {
return undefined;
}
widget = widget.containerWidget.bodyWidgets[index - 1];
}
else {
var page = widget.page.previousPage;
widget = page && page.bodyWidgets.length > 0 ? page.bodyWidgets[page.bodyWidgets.length - 1] : undefined;
}
}
else if (widget instanceof FootNoteWidget) {
var page = widget.page;
while (page.previousPage) {
page = page.previousPage;
widget = page.footnoteWidget;
if (!isNullOrUndefined(widget)) {
break;
}
}
}
else {
if (index > 0) {
widget = widget.containerWidget.childWidgets[index - 1];
}
else {
var previousContainer = undefined;
if (widget.containerWidget instanceof TableCellWidget) {
previousContainer = widget.containerWidget.getPreviousSplitWidget();
}
else if (widget.containerWidget && widget.containerWidget.containerWidget instanceof FootNoteWidget &&
widget.containerWidget.containerWidget.footNoteType === 'Endnote') {
previousContainer = widget.containerWidget.previousWidget ? widget.containerWidget.previousWidget : widget.containerWidget.previousRenderedWidget;
}
else if (!(widget.containerWidget instanceof TableRowWidget
|| widget.containerWidget instanceof HeaderFooterWidget || (widget.containerWidget && widget.containerWidget.containerWidget instanceof FootNoteWidget))) {
// Since cells are lay outed left to right, we should not navigate to previous row.
previousContainer = widget.containerWidget.previousRenderedWidget;
}
while (previousContainer && previousContainer.childWidgets.length === 0) {
previousContainer = previousContainer.previousRenderedWidget;
if (isNullOrUndefined(previousContainer)) {
break;
}
}
widget = previousContainer && previousContainer.constructor === widget.containerWidget.constructor ?
previousContainer.lastChild : undefined;
}
}
return widget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "nextRenderedWidget", {
get: function () {
var widget = this;
var index = this.indexInOwner;
if (index < 0) {
return undefined;
}
if (widget instanceof BodyWidget) {
if (index < widget.page.bodyWidgets.length - 1 && !(widget.containerWidget instanceof FootNoteWidget)) {
widget = widget.page.bodyWidgets[index + 1];
}
else if (widget.containerWidget instanceof FootNoteWidget) {
if (index >= widget.containerWidget.bodyWidgets.length - 1 && !widget.page.documentHelper.owner.editorModule.removeEditRange) {
return undefined;
}
widget = widget.containerWidget.bodyWidgets[index + 1];
}
else if (widget.page.allowNextPageRendering) {
var page = widget.page.nextPage;
widget = page && page.bodyWidgets.length > 0 ? page.bodyWidgets[0] : undefined;
}
else {
widget = undefined;
}
}
else if (widget instanceof FootNoteWidget) {
var page = widget.page;
while (page.allowNextPageRendering && page.nextPage) {
page = page.nextPage;
widget = page.footnoteWidget;
if (!isNullOrUndefined(widget)) {
break;
}
}
}
else {
if (index < widget.containerWidget.childWidgets.length - 1) {
widget = widget.containerWidget.childWidgets[index + 1];
}
else {
var nextContainer = undefined;
if (widget.containerWidget instanceof TableCellWidget) {
nextContainer = widget.containerWidget.getNextSplitWidget();
}
else if (widget.containerWidget && widget.containerWidget.containerWidget instanceof FootNoteWidget &&
widget.containerWidget.containerWidget.footNoteType === 'Endnote') {
nextContainer = widget.containerWidget.nextWidget ? widget.containerWidget.nextWidget : widget.containerWidget.nextRenderedWidget;
}
else if (!(widget.containerWidget instanceof TableRowWidget
|| widget.containerWidget instanceof HeaderFooterWidget || (widget.containerWidget && widget.containerWidget.containerWidget instanceof FootNoteWidget))) {
// Since cells are lay outed left to right, we should not navigate to next row.
nextContainer = widget.containerWidget.nextRenderedWidget;
}
while (nextContainer && nextContainer.childWidgets.length === 0 && !(nextContainer instanceof TableCellWidget)) {
nextContainer = nextContainer.nextRenderedWidget;
if (isNullOrUndefined(nextContainer)) {
break;
}
}
widget = nextContainer && nextContainer.constructor === widget.containerWidget.constructor ?
nextContainer.firstChild : undefined;
}
}
return widget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "previousSplitWidget", {
get: function () {
var widget = this;
if (widget instanceof TableCellWidget) {
return widget.getPreviousSplitWidget();
}
else {
var previous = widget.previousRenderedWidget;
if (widget instanceof BodyWidget && previous instanceof BodyWidget && widget.equals(previous) && !(widget.containerWidget instanceof FootNoteWidget && widget.containerWidget.footNoteType === 'Endnote')) {
return previous;
}
else if (previous instanceof BlockWidget && widget.index === previous.index && widget.equals(previous)) {
return previous;
}
else if (widget instanceof BodyWidget && widget.containerWidget instanceof FootNoteWidget
&& widget.containerWidget.footNoteType === 'Endnote' && !isNullOrUndefined(widget.page.previousPage)
&& !isNullOrUndefined(widget.page.previousPage.endnoteWidget)) {
previous = widget.page.previousPage.endnoteWidget.bodyWidgets[widget.page.previousPage.endnoteWidget.bodyWidgets.length - 1];
if (previous && previous instanceof BodyWidget && widget.index === previous.index && widget.equals(previous)) {
return previous;
}
}
else if (widget instanceof BlockWidget && widget.bodyWidget
&& widget.bodyWidget.containerWidget instanceof FootNoteWidget && widget.bodyWidget.containerWidget.footNoteType === 'Endnote'
&& !isNullOrUndefined(widget.bodyWidget.page.previousPage) && !isNullOrUndefined(widget.bodyWidget.page.previousPage.endnoteWidget)
&& widget.bodyWidget.page.previousPage.endnoteWidget.bodyWidgets.length > 0) {
var previousEndnotePage = widget.bodyWidget.page.previousPage.endnoteWidget;
var lastBodyWidget = previousEndnotePage.bodyWidgets[previousEndnotePage.bodyWidgets.length - 1];
previous = lastBodyWidget.childWidgets[lastBodyWidget.childWidgets.length - 1];
if (previous && previous instanceof BlockWidget && widget.index === previous.index && widget.equals(previous)) {
return previous;
}
}
}
return undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Widget.prototype, "nextSplitWidget", {
get: function () {
var widget = this;
if (widget instanceof TableCellWidget) {
return widget.getNextSplitWidget();
}
else {
var next = widget.nextRenderedWidget;
if (widget instanceof BodyWidget && next instanceof BodyWidget && widget.equals(next) && !(widget.containerWidget instanceof FootNoteWidget && widget.containerWidget.footNoteType === 'Endnote')) {
return next;
}
else if (next instanceof BlockWidget && widget.index === next.index && widget.equals(next)) {
return next;
}
else if (widget instanceof BodyWidget && widget.containerWidget instanceof FootNoteWidget
&& widget.containerWidget.footNoteType === 'Endnote' && !isNullOrUndefined(widget.page.nextPage)
&& !isNullOrUndefined(widget.page.nextPage.endnoteWidget)) {
next = widget.page.nextPage.endnoteWidget.bodyWidgets[0];
if (next && next instanceof BodyWidget && widget.index === next.index && widget.equals(next)) {
return next;
}
}
else if (widget instanceof BlockWidget && widget.bodyWidget
&& widget.bodyWidget.containerWidget instanceof FootNoteWidget && widget.bodyWidget.containerWidget.footNoteType === 'Endnote'
&& !isNullOrUndefined(widget.bodyWidget.page.nextPage) && !isNullOrUndefined(widget.bodyWidget.page.nextPage.endnoteWidget)
&& widget.bodyWidget.page.nextPage.endnoteWidget.bodyWidgets.length > 0) {
next = widget.bodyWidget.page.nextPage.endnoteWidget.bodyWidgets[0].childWidgets[0];
if (next && next instanceof BlockWidget && widget.index === next.index && widget.equals(next)) {
return next;
}
}
}
return undefined;
},
enumerable: true,
configurable: true
});
Widget.prototype.getPreviousSplitWidgets = function () {
var widgets = [];
var widget = this.previousSplitWidget;
while (widget) {
widgets.unshift(widget);
widget = widget.previousSplitWidget;
if (widget && widget == widget.previousSplitWidget) {
break;
}
}
return widgets;
};
Widget.prototype.getSplitWidgets = function () {
var widgets = this.getPreviousSplitWidgets();
var widget = this;
while (widget) {
widgets.push(widget);
widget = widget.nextSplitWidget;
}
return widgets;
};
Widget.prototype.combineWidget = function (viewer) {
var root = this;
var widgets = this.getSplitWidgets();
if (widgets.length > 1) {
root = widgets.shift();
while (widgets.length > 0) {
var splitWidget = widgets.shift();
root.combine(splitWidget, viewer);
}
}
if (root instanceof TableWidget) {
root.combineRows(viewer);
}
return root;
};
Widget.prototype.combine = function (widget, viewer) {
if (widget.childWidgets.length > 0) {
var lastChild = this.lastChild;
if (lastChild instanceof TableWidget) {
lastChild.combineWidget(viewer);
}
else {
var firstChild = widget.firstChild;
if (!(widget instanceof TableWidget) && lastChild instanceof Widget && firstChild instanceof Widget &&
lastChild.index === firstChild.index) {
lastChild.combine(widget.childWidgets.shift(), viewer);
}
}
this.addWidgets(widget.childWidgets);
widget.childWidgets = [];
}
widget.destroyInternal(viewer);
};
Widget.prototype.addWidgets = function (childWidgets) {
while (childWidgets.length > 0) {
var widget = childWidgets.shift();
if (widget instanceof LineWidget && this instanceof ParagraphWidget) {
widget.paragraph = this;
this.height += widget.height;
}
else if (widget instanceof Widget) {
var lastChild = this.lastChild;
widget.containerWidget = this;
widget.y = lastChild instanceof Widget ? lastChild.y + lastChild.height : this.y;
this.height += widget.height;
}
if (widget instanceof TableRowWidget) {
var previousRow = this.childWidgets[this.childWidgets.length - 1];
for (var i = 0; i < previousRow.childWidgets.length; i++) {
var previousCell = previousRow.childWidgets[i];
if (previousCell.cellFormat.rowSpan > 1) {
for (var j = 0; j < widget.childWidgets.length; j++) {
var currentCell = widget.childWidgets[j];
if (currentCell.columnIndex === previousCell.columnIndex && currentCell.isSplittedCell && currentCell.cellFormat.rowSpan === previousCell.cellFormat.rowSpan) {
for (var k = 0; k < currentCell.childWidgets.length; k++) {
var block = currentCell.childWidgets[k];
currentCell.childWidgets.splice(block.indexInOwner, 1);
previousCell.childWidgets.push(block);
block.containerWidget = previousCell;
k--;
}
currentCell.ownerRow.childWidgets.splice(currentCell.indexInOwner, 1);
currentCell.containerWidget = undefined;
j--;
}
}
}
}
}
this.childWidgets.push(widget);
}
};
Widget.prototype.removeChild = function (index) {
if (index > -1 && index < this.childWidgets.length) {
this.childWidgets.splice(index, 1);
}
};
Widget.prototype.destroy = function () {
if (this.childWidgets) {
while (this.childWidgets.length > 0) {
var child = this.childWidgets.pop();
if (child instanceof LineWidget || child instanceof Widget) {
child.destroy();
}
}
}
this.childWidgets = undefined;
if (this.containerWidget) {
this.containerWidget.removeChild(this.indexInOwner);
}
this.containerWidget = undefined;
// if (this.margin) {
// this.margin.destroy();
// }
this.margin = undefined;
this.x = undefined;
this.y = undefined;
this.width = undefined;
this.height = undefined;
this.index = undefined;
};
/**
* Disposes the internal objects which are maintained.
* @private
*/
Widget.prototype.componentDestroy = function () {
if (this.childWidgets) {
while (this.childWidgets.length > 0) {
var child = this.childWidgets.pop();
if (child instanceof LineWidget || child instanceof Widget) {
child.componentDestroy();
}
}
}
this.childWidgets = undefined;
if (this.margin) {
this.margin.destroy();
}
this.margin = undefined;
this.x = undefined;
this.y = undefined;
this.width = undefined;
this.height = undefined;
this.index = undefined;
this.containerWidget = undefined;
};
return Widget;
}());
export { Widget };
/**
* @private
*/
var BlockContainer = /** @class */ (function (_super) {
__extends(BlockContainer, _super);
function BlockContainer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.floatingElements = [];
/**
* @private
*/
_this.footNoteReference = undefined;
/**
* @private
*/
_this.sectionFormatIn = undefined;
/**
* @private
*/
_this.columnIndex = 0;
/**
* @private
*/
_this.isWord2010NextColumn = false;
return _this;
}
Object.defineProperty(BlockContainer.prototype, "sectionFormat", {
get: function () {
var container = this;
if (container instanceof BodyWidget) {
return container.sectionFormatIn;
}
else if (container.page && !isNullOrUndefined(container.page.bodyWidgets)) {
return container.page.bodyWidgets[0].sectionFormat;
}
return undefined;
},
set: function (value) {
if (this instanceof BodyWidget) {
this.sectionFormatIn = value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockContainer.prototype, "sectionIndex", {
get: function () {
var container = this;
var index = 0;
if (container instanceof BodyWidget) {
index = container.index;
}
else if (container.page) {
index = container.page.bodyWidgets[0].index;
}
return index;
},
enumerable: true,
configurable: true
});
BlockContainer.prototype.getHierarchicalIndex = function (hierarchicalIndex) {
var documentHelper = undefined;
var node = this;
if (node instanceof BodyWidget) {
hierarchicalIndex = node.index + ';' + hierarchicalIndex;
}
else if (node instanceof FootNoteWidget) {
if (node.footNoteType === 'Footnote') {
hierarchicalIndex = 'FN' + ';' + hierarchicalIndex;
}
else {
hierarchicalIndex = 'EN' + ';' + hierarchicalIndex;
}
}
else {
if (node.headerFooterType.indexOf('Header') !== -1) {
hierarchicalIndex = 'H' + ';' + hierarchicalIndex;
}
else {
hierarchicalIndex = 'F' + ';' + hierarchicalIndex;
}
}
if (!isNullOrUndefined(node.page)) {
documentHelper = this.page.documentHelper;
var pageIndex = documentHelper.pages.indexOf(this.page);
return pageIndex + ';' + hierarchicalIndex;
}
return hierarchicalIndex;
};
/**
* Disposes the internal objects which are maintained.
* @private
*/
BlockContainer.prototype.componentDestroy = function () {
if (this.sectionFormatIn) {
this.sectionFormatIn.destroy();
}
this.sectionFormatIn = undefined;
this.floatingElements = [];
this.removedHeaderFooters = [];
this.footNoteReference = undefined;
this.page = undefined;
_super.prototype.componentDestroy.call(this);
};
return BlockContainer;
}(Widget));
export { BlockContainer };
/**
* @private
*/
var BodyWidget = /** @class */ (function (_super) {
__extends(BodyWidget, _super);
/**
* Initialize the constructor of BodyWidget
*/
function BodyWidget() {
return _super.call(this) || this;
}
BodyWidget.prototype.equals = function (widget) {
return widget instanceof BodyWidget && widget.sectionFormat === this.sectionFormat;
};
BodyWidget.prototype.getHierarchicalIndex = function (hierarchicalIndex) {
var documentHelper = undefined;
var node = this;
if (node.containerWidget instanceof FootNoteWidget) {
hierarchicalIndex = node.containerWidget.bodyWidgets.indexOf(node) + ';' + hierarchicalIndex;
if (node.containerWidget.footNoteType === 'Footnote') {
hierarchicalIndex = 'FN' + ';' + hierarchicalIndex;
}
else {
hierarchicalIndex = 'EN' + ';' + hierarchicalIndex;
}
}
else {
if (this.page && this.page.bodyWidgets.indexOf(this) !== -1) {
hierarchicalIndex = this.page.bodyWidgets.indexOf(this) + ';' + hierarchicalIndex;
}
else {
hierarchicalIndex = node.index + ';' + hierarchicalIndex;
}
}
if (!isNullOrUndefined(node.page)) {
documentHelper = this.page.documentHelper;
var pageIndex = documentHelper.pages.indexOf(this.page);
return pageIndex + ';' + hierarchicalIndex;
}
return hierarchicalIndex;
};
BodyWidget.prototype.getTableCellWidget = function (touchPoint) {
for (var i = 0; i < this.childWidgets.length; i++) {
if (this.childWidgets[i] instanceof TableWidget) {
var childWidget = this.childWidgets[i];
var tableWidth = 0;
if (childWidget.wrapTextAround) {
tableWidth = childWidget.getTableCellWidth();
}
if (!(childWidget.wrapTextAround) && childWidget.y <= touchPoint.y && (childWidget.y + childWidget.height) >= touchPoint.y) {
return childWidget.getTableCellWidget(touchPoint);
}
if ((childWidget.wrapTextAround &&
(childWidget.x <= touchPoint.x && (childWidget.x + tableWidth) >= touchPoint.x &&
childWidget.y <= touchPoint.y && (childWidget.y + childWidget.height) >= touchPoint.y))) {
return childWidget.getTableCellWidget(touchPoint);
}
}
}
var tableCellWidget = undefined;
if (this.childWidgets.length > 0) {
if (this.childWidgets[0].y <= touchPoint.y) {
tableCellWidget = this.childWidgets[this.childWidgets.length - 1].getTableCellWidget(touchPoint);
}
else {
tableCellWidget = this.childWidgets[0].getTableCellWidget(touchPoint);
}
}
return tableCellWidget;
};
BodyWidget.prototype.destroyInternal = function (viewer) {
var height = this.height;
if (!isNullOrUndefined(this.childWidgets)) {
for (var n = 0; n < this.childWidgets.length; n++) {
var chilgWidget = this.childWidgets[n];
if (chilgWidget instanceof ParagraphWidget) {
chilgWidget.destroyInternal(viewer);
}
else {
chilgWidget.destroyInternal(viewer);
}
if (isNullOrUndefined(this.childWidgets)) {
break;
}
n--;
}
this.childWidgets = undefined;
}
// if (this instanceof HeaderFooterWidget && ((this as HeaderFooterWidget).currentNode ))) {
// if (((this as HeaderFooterWidget).currentNode as WHeaderFooter).layoutedWidgets )) {
// let index: number = ((this as HeaderFooterWidget).currentNode as WHeaderFooter).layoutedWidgets.indexOf(this);
// ((this as HeaderFooterWidget).currentNode as WHeaderFooter).layoutedWidgets.splice(index, 1);
// }
// this.currentNode = undefined;
if (!isNullOrUndefined(this.page)) {
var index = this.indexInOwner;
if (this.indexInOwner > -1) {
this.page.bodyWidgets.splice(index, 1);
if (this.page.bodyWidgets.length === 0) {
this.page.destroy();
// }
}
else if ((this instanceof HeaderFooterWidget)
&& this.page.headerWidget === this) {
this.page.headerWidget = undefined;
}
else if ((this instanceof HeaderFooterWidget)
&& this.page.footerWidget === this) {
this.page.footerWidget = undefined;
}
this.page = undefined;
}
}
this.destroy();
};
BodyWidget.prototype.destroy = function () {
// if (this.sectionFormatIn) {
// this.sectionFormatIn.destroy();
// }
this.sectionFormatIn = undefined;
if (this.page && this.page.headerWidgetIn) {
this.page.headerWidgetIn.page = undefined;
}
if (this.page && this.page.footerWidgetIn) {
this.page.footerWidgetIn.page = undefined;
}
this.page = undefined;
_super.prototype.destroy.call(this);
};
/**
* Disposes the internal objects which are maintained.
* @private
*/
BodyWidget.prototype.componentDestroy = function () {
_super.prototype.componentDestroy.call(this);
};
return BodyWidget;
}(BlockContainer));
export { BodyWidget };
/**
* @private
*/
var HeaderFooterWidget = /** @class */ (function (_super) {
__extends(HeaderFooterWidget, _super);
function HeaderFooterWidget(type) {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.isEmpty = false;
_this.headerFooterType = type;
return _this;
}
HeaderFooterWidget.prototype.getTableCellWidget = function (point) {
for (var i = 0; i < this.childWidgets.length; i++) {
if (this.childWidgets[i] instanceof TableWidget) {
var child = this.childWidgets[i];
var tableWidth = 0;
if (child.wrapTextAround) {
tableWidth = child.getTableCellWidth();
}
if (!(child.wrapTextAround) && child.y <= point.y && (child.y + child.height) >= point.y) {
return child.getTableCellWidget(point);
}
if ((child.wrapTextAround &&
(child.x <= point.x && (child.x + tableWidth) >= point.x &&
child.y <= point.y && (child.y + child.height) >= point.y))) {
return child.getTableCellWidget(point);
}
}
}
var tableCell = undefined;
if (this.childWidgets.length > 0) {
if (this.childWidgets[0].y <= point.y) {
tableCell = this.childWidgets[this.childWidgets.length - 1].getTableCellWidget(point);
}
else {
tableCell = this.childWidgets[0].getTableCellWidget(point);
}
}
return tableCell;
};
HeaderFooterWidget.prototype.equals = function (widget) {
// Todo: Need to work
return widget instanceof HeaderFooterWidget
&& widget.containerWidget === this.containerWidget;
};
HeaderFooterWidget.prototype.clone = function () {
var headerFooter = new HeaderFooterWidget(this.headerFooterType);
for (var i = 0; i < this.childWidgets.length; i++) {
var block = this.childWidgets[i].clone();
headerFooter.childWidgets.push(block);
block.index = i;
block.containerWidget = headerFooter;
}
headerFooter.isEmpty = this.isEmpty;
headerFooter.x = this.x;
headerFooter.y = this.y;
headerFooter.height = 0;
headerFooter.width = 0;
return headerFooter;
};
HeaderFooterWidget.prototype.destroyInternal = function (viewer) {
this.page = undefined;
_super.prototype.destroy.call(this);
};
/**
* Disposes the internal objects which are maintained.
* @private
*/
HeaderFooterWidget.prototype.componentDestroy = function () {
_super.prototype.componentDestroy.call(this);
this.parentHeaderFooter = undefined;
};
return HeaderFooterWidget;
}(BlockContainer));
export { HeaderFooterWidget };
/**
* @private
*/
var BlockWidget = /** @class */ (function (_super) {
__extends(BlockWidget, _super);
function BlockWidget() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.isLayouted = false;
/**
* @private
*/
_this.isFieldCodeBlock = false;
/**
* @private
*/
_this.locked = false;
/**
* @private
*/
_this.lockedBy = '';
return _this;
}
Object.defineProperty(BlockWidget.prototype, "bodyWidget", {
get: function () {
var widget = this;
while (widget.containerWidget) {
if (widget.containerWidget instanceof TextFrame) {
var paragraph = widget.containerWidget.containerShape.line.paragraph;
if (paragraph) {
return paragraph.bodyWidget;
}
}
else if (widget.containerWidget instanceof BlockContainer) {
return widget.containerWidget;
}
widget = widget.containerWidget;
}
return undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockWidget.prototype, "leftIndent", {
get: function () {
var blockAdv = this;
if (blockAdv instanceof ParagraphWidget && blockAdv.paragraphFormat instanceof WParagraphFormat) {
return blockAdv.paragraphFormat.leftIndent;
}
else if (blockAdv instanceof TableWidget && blockAdv.tableFormat instanceof WTableFormat) {
return blockAdv.tableFormat.leftIndent;
}
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockWidget.prototype, "rightIndent", {
get: function () {
var blockAdv = this;
if (blockAdv instanceof ParagraphWidget && blockAdv.paragraphFormat instanceof WParagraphFormat) {
return blockAdv.paragraphFormat.rightIndent;
}
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockWidget.prototype, "isInsideTable", {
get: function () {
return this.containerWidget instanceof TableCellWidget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockWidget.prototype, "isInHeaderFooter", {
get: function () {
return this.bodyWidget instanceof HeaderFooterWidget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlockWidget.prototype, "associatedCell", {
get: function () {
if (this.containerWidget instanceof TableCellWidget) {
return this.containerWidget;
}
return undefined;
},
enumerable: true,
configurable: true
});
/**
* Check whether the paragraph contains only page break.
*
* @private
* @returns {boolean}: Returns true if paragraph contains page break alone.
*/
BlockWidget.prototype.isPageBreak = function () {
var isPageBreak = false;
if (this instanceof ParagraphWidget) {
var paragraph = this;
if (paragraph != null && paragraph.childWidgets.length === 1 &&
paragraph.firstChild.children.length === 1) {
var pageBreak = paragraph.firstChild.children[0];
isPageBreak = pageBreak.isPageBreak;
}
}
return isPageBreak;
};
BlockWidget.prototype.isColumnBreak = function () {
var isColumnBreak = false;
if (this instanceof ParagraphWidget) {
var paragraph = this;
if (paragraph != null && paragraph.childWidgets.length === 1 &&
paragraph.firstChild.children.length === 1) {
var columnBreak = paragraph.firstChild.children[0];
isColumnBreak = columnBreak.isColumnBreak;
}
}
return isColumnBreak;
};
BlockWidget.prototype.getHierarchicalIndex = function (hierarchicalIndex) {
var node = this;
hierarchicalIndex = node.containerWidget.childWidgets.indexOf(node) + ';' + hierarchicalIndex;
if (!isNullOrUndefined(node.containerWidget)) {
if (node.containerWidget instanceof TextFrame) {
return node.containerWidget.getHierarchicalIndex(hierarchicalIndex);
}
else if (node.containerWidget instanceof BlockWidget) {
return node.containerWidget.getHierarchicalIndex(hierarchicalIndex);
}
else if (node.containerWidget instanceof BlockContainer) {
hierarchicalIndex = node.containerWidget.getHierarchicalIndex(hierarchicalIndex);
}
}
return hierarchicalIndex;
};
BlockWidget.prototype.getIndex = function () {
if (this instanceof ParagraphWidget || this instanceof TableWidget) {
return this.containerWidget.childWidgets.indexOf(this);
}
else if (this instanceof TableRowWidget) {
return this.ownerTable.childWidgets.indexOf(this);
}
else if (this instanceof TableCellWidget) {
return this.ownerRow.childWidgets.indexOf(this);
}
return 0;
};
BlockWidget.prototype.getContainerWidth = function () {
if (this.isInsideTable) {
var block = this;
if ((block instanceof TableWidget) && block.tableFormat.preferredWidthType === 'Auto' && this.associatedCell.ownerTable.isGridUpdated) {
var containerWidth = 0;
var columnSpan = this.associatedCell.cellFormat.columnSpan;
var columnIndex = this.associatedCell.columnIndex;
for (var i = 0; i < columnSpan; i++) {
containerWidth += this.associatedCell.ownerTable.tableHolder.columns[columnIndex].preferredWidth;
columnIndex++;
}
if (containerWidth > 0) {
return containerWidth;
}
}
return this.associatedCell.getCellWidth(this);
}
if (this.containerWidget instanceof TextFrame) {
var shape = this.containerWidget.containerShape;
return HelperMethods.convertPixelToPoint(shape.width) - HelperMethods.convertPixelToPoint(shape.textFrame.marginLeft)
- HelperMethods.convertPixelToPoint(shape.textFrame.marginRight);
}
else {
var bodyWidget = this.bodyWidget;
var sectionFormat = bodyWidget.sectionFormat;
var padding = 0;
if (!isNullOrUndefined(bodyWidget.page) && !isNullOrUndefined(bodyWidget.page.documentHelper) &&
bodyWidget.page.documentHelper.compatibilityMode !== 'Word2013' && !this.isInsideTable && this instanceof TableWidget) {
var firstRow = this.firstChild;
padding = firstRow.firstChild.leftMargin + (firstRow).lastChild.rightMargin;
}
if (bodyWidget instanceof BodyWidget && sectionFormat.columns.length > 1) {
var colIndex = bodyWidget.columnIndex;
return HelperMethods.convertPixelToPoint(sectionFormat.columns[colIndex].width);
}
else {
return sectionFormat.pageWidth - (sectionFormat.leftMargin + sectionFormat.rightMargin) + padding;
}
}
};
Object.defineProperty(BlockWidget.prototype, "bidi", {
get: function () {
if (this instanceof ParagraphWidget && this.paragraphFormat instanceof WParagraphFormat) {
return this.paragraphFormat.bidi;
}
if (this instanceof TableWidget && this.tableFormat instanceof WTableFormat) {
return this.tableFormat.bidi;
}
return false;
},
enumerable: true,
configurable: true
});
/**
* Disposes the internal objects which are maintained.
* @private
*/
BlockWidget.prototype.componentDestroy = function () {
_super.prototype.componentDestroy.call(this);
this.contentControlProperties = undefined;
};
return BlockWidget;
}(Widget));
export { BlockWidget };
/**
* @private
*/
var FootNoteWidget = /** @class */ (function (_super) {
__extends(FootNoteWidget, _super);
function FootNoteWidget() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
*/
_this.bodyWidgets = [];
return _this;
}
FootNoteWidget.prototype.getMinimumAndMaximumWordWidth = function (minimumWordWidth, maximumWordWidth) {
throw new Error('Method not implemented.');
};
FootNoteWidget.prototype.getTableCellWidget = function (point) {
return undefined;
};
FootNoteWidget.prototype.equals = function (widget) {
// Todo: Need to work
return widget instanceof FootNoteWidget
&& widget.containerWidget === this.containerWidget;
};
FootNoteWidget.prototype.clone = function () {
var footNote = new FootNoteWidget();
for (var i = 0; i < this.childWidgets.length; i++) {
var block = this.childWidgets[i].clone();
footNote.childWidgets.push(block);
block.index = i;
block.containerWidget = footNote;
}
footNote.block = this.block;
return footNote;
};
FootNoteWidget.prototype.destroyInternal = function (viewer) {
this.block = undefined;
_super.prototype.destroy.call(this);
};
/**
* Disposes the internal objects which are maintained.
* @private
*/
FootNoteWidget.prototype.componentDestroy = function () {
if (this.bodyWidgets && this.bodyWidgets.length > 0) {
for (var i = 0; i < this.bodyWidgets.length; i++) {
var bodyWidget = this.bodyWidgets[i];
bodyWidget.componentDestroy();
}
this.bodyWidgets = [];
}
this.bodyWidgets = undefined;
this.block = undefined;
_super.prototype.componentDestroy.call(this);
};
return FootNoteWidget;
}(BlockContainer));
export { FootNoteWidget };
/**
* @private
*/
var ParagraphWidget = /** @class */ (function (_super) {
__extends(ParagraphWidget, _super);
/**
* Initialize the constructor of ParagraphWidget
*/
function ParagraphWidget() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.isSectionBreak = false;
/**
* @private
*/
_this.isChangeDetected = false;
/**
* @private
*/
_this.textWrapWidth = false;
/**
* @private
* The clientX having previous left value of empty paragraph
*/
_this.clientX = undefined;
/**
* @private
*/
_this.floatingElements = [];
_this.paragraphFormat = new WParagraphFormat(_this);
_this.characterFormat = new WCharacterFormat(_this);
return _this;
}
Object.defineProperty(ParagraphWidget.prototype, "isEndsWithPageBreak", {
get: function () {
if (this.childWidgets.length > 0) {
return this.lastChild.isEndsWithPageBreak;
}
return false;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ParagraphWidget.prototype, "isEndsWithColumnBreak", {
get: function () {
if (this.childWidgets.length > 0) {
return this.lastChild.isEndsWithColumnBreak;
}
return false;
},
enumerable: true,
configurable: true
});
ParagraphWidget.prototype.equals = function (widget) {
return widget instanceof ParagraphWidget && widget.paragraphFormat === this.paragraphFormat;
};
ParagraphWidget.prototype.isContainsShapeAlone = function () {
var containsShape = false;
for (var i = 0; i < this.childWidgets.length; i++) {
var lineWidget = this.childWidgets[i];
for (var j = 0; j < lineWidget.children.length; j++) {
var inline = lineWidget.children[j];
if (!(inline instanceof ShapeBase) || (inline instanceof ShapeBase && inline.textWrappingStyle === 'Inline')) {
return false;
}
else {
containsShape = true;
}
}
}
return containsShape ? true : false;
};
ParagraphWidget.prototype.isEmptyInternal = function (layoutCheck) {
if (isNullOrUndefined(this.childWidgets) || this.childWidgets.length === 0) {
return true;
}
for (var j = 0; j < this.childWidgets.length; j++) {
var inlineElement = this.childWidgets[j];
for (var i = 0; i < inlineElement.children.length; i++) {
var inline = inlineElement.children[i];
if (inline.length === 0) {
continue;
}
if (inline instanceof TextElementBox || inline instanceof ImageElementBox || inline instanceof BookmarkElementBox