@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
910 lines • 850 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
/* eslint-disable */
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { Dictionary } from '../../base/dictionary';
import { CharacterRangeType } from '../../base/types';
import { HelperMethods, Point, WrapPosition } from '../editor/editor-helper';
import { WBorder, WBorders, WCharacterFormat, WParagraphFormat, WRowFormat } from '../format/index';
import { WListLevel } from '../list/list-level';
import { BlockContainer, BlockWidget, BodyWidget, BookmarkElementBox, EditRangeEndElementBox, EditRangeStartElementBox, ElementBox, FieldElementBox, FieldTextElementBox, HeaderFooterWidget, ImageElementBox, LineWidget, ListTextElementBox, Margin, ParagraphWidget, Rect, TabElementBox, TableCellWidget, TableRowWidget, TableWidget, TextElementBox, Widget, CheckBoxFormField, DropDownFormField, ShapeElementBox, TextFrame, ContentControl, FootnoteElementBox, FootNoteWidget, ShapeBase, CommentCharacterElementBox, FootnoteEndnoteMarkerElementBox, GroupShapeElementBox } from './page';
import { PageLayoutViewer, WebLayoutViewer } from './viewer';
import { TextHelper } from './text-helper';
import { internalAsyncPagesVisible } from '../../base/constants';
// Check box character is rendered smaller when compared to MS Word
// So, mutiplied the font side by below factor to render check box character large.
var CHECK_BOX_FACTOR = 1.35;
/**
* @private
*/
var Layout = /** @class */ (function () {
function Layout(documentHelper) {
/**
* @private
*/
this.islayoutFootnote = false;
/**
* @private
*/
this.isMultiColumnDoc = false;
/**
* @private
*/
this.allowLayout = true;
/**
* @private
*/
this.isReplaceAll = false;
/**
* @private
*/
this.isTextFormat = false;
/**
* @private
*/
this.isSectionBreakCont = false;
/**
* @private
*/
this.isReplacingAll = false;
/**
* @private
*/
this.footHeight = 0;
/**
* @private
*/
this.existFootnoteHeight = 0;
/**
* @private
*/
this.isfootMove = false;
/**
* @private
*/
this.footnoteHeight = 0;
/**
* @private
*/
this.isTableFootNote = false;
/**
* @private
*/
this.isRelayout = false;
/**
* @private
*/
this.isRelayoutneed = false;
/**
* @private
*/
this.isOverlapFloatTable = false;
this.isInitialLoad = true;
/**
* @private
*/
this.isInsertFormField = false;
this.isAsync = false;
this.fieldBegin = undefined;
this.maxTextHeight = 0;
this.maxBaseline = 0;
this.maxTextBaseline = 0;
this.isFieldCode = false;
this.isRtlFieldCode = false;
this.isRTLLayout = false;
this.isSkipFirstLineIndent = false;
this.currentCell = undefined;
this.isFootnoteContentChanged = false;
this.isEndnoteContentChanged = false;
this.keepWithNext = false;
this.is2013Justification = false;
this.nextElementToLayout = undefined;
this.endNoteHeight = 0;
this.isMultiColumnSplit = false;
this.isMultiColumnLayout = false;
this.skipUpdateContainerWidget = false;
this.isIFfield = false;
this.isLayoutWhole = false;
/**
* @private
*/
this.isBidiReLayout = false;
/**
* @private
*/
this.defaultTabWidthPixel = 48;
/**
* @private
*/
this.isRelayoutFootnote = false;
this.isRelayoutOverlap = false;
this.skipRelayoutOverlap = false;
this.isWrapText = false;
this.isYPositionUpdated = false;
this.isXPositionUpdated = false;
this.hasFloatingElement = false;
this.isFootNoteLayoutStart = false;
this.wrapPosition = [];
this.shiftedFloatingItemsFromTable = [];
this.isDocumentContainsRtl = false;
/**
* @private
*/
this.isPastingContent = false;
this.layoutedFootnoteElement = [];
/**
* @private
*/
this.lastScrollUpdatePageIndex = -1;
/**
* @private
*/
this.isAllColumnHasAutoWidthType = false;
this.documentHelper = documentHelper;
}
Object.defineProperty(Layout.prototype, "owner", {
get: function () {
if (this.documentHelper) {
return this.documentHelper.owner;
}
return undefined;
},
enumerable: true,
configurable: true
});
Layout.prototype.isSameStyle = function (currentParagraph, isAfterSpacing) {
var nextOrPrevSibling = undefined;
if (isAfterSpacing) {
if (currentParagraph.nextWidget instanceof ParagraphWidget) {
nextOrPrevSibling = currentParagraph.nextWidget;
}
}
else {
if (currentParagraph.previousWidget instanceof ParagraphWidget) {
nextOrPrevSibling = currentParagraph.previousWidget;
}
}
if (isNullOrUndefined(nextOrPrevSibling)) {
//Need to skip contextual spacing behavior when document is not Word 2013 and paragraph preserved inside the table cell with AllowSpaceOfSameStyleInTable compatiblity options.
if (currentParagraph.paragraphFormat.contextualSpacing && (currentParagraph.isInsideTable ? (!this.documentHelper.allowSpaceOfSameStyleInTable || this.documentHelper.compatibilityMode === 'Word2013') : false)) {
if (currentParagraph.index === 0) {
nextOrPrevSibling = this.updateFirstParagraphSpacingBasedOnContextualSpacing(currentParagraph, isAfterSpacing);
}
else if (currentParagraph.index === currentParagraph.associatedCell.childWidgets.length - 1) {
nextOrPrevSibling = this.updateLastParagraphSpacingBasedOnContextualSpacing(currentParagraph);
if (nextOrPrevSibling === currentParagraph) {
return true;
}
}
}
if (isNullOrUndefined(nextOrPrevSibling)) {
return false;
}
}
if (nextOrPrevSibling instanceof ParagraphWidget && currentParagraph.paragraphFormat.baseStyle === nextOrPrevSibling.paragraphFormat.baseStyle && (currentParagraph.isInsideTable ? !this.documentHelper.allowSpaceOfSameStyleInTable : true)) {
if (currentParagraph.paragraphFormat.listFormat.listId >= 0 && nextOrPrevSibling.paragraphFormat.listFormat.listId >= 0) {
if (!currentParagraph.paragraphFormat.contextualSpacing) {
if (isAfterSpacing && currentParagraph.paragraphFormat.spaceAfterAuto) {
return true;
}
else if (!isAfterSpacing && currentParagraph.paragraphFormat.spaceBeforeAuto) {
return true;
}
}
}
return currentParagraph.paragraphFormat.contextualSpacing;
}
return false;
};
Layout.prototype.updateFirstParagraphSpacingBasedOnContextualSpacing = function (paragraph, isAfterSpacing) {
var ownerCell = paragraph.associatedCell;
var ownerRow = ownerCell.ownerRow;
var ownerTable = ownerRow.ownerTable;
var nextOrPrevSibling;
if (isAfterSpacing) {
nextOrPrevSibling = isNullOrUndefined(paragraph.nextRenderedWidget) ? (!isNullOrUndefined(ownerCell.nextRenderedWidget) ? ownerCell.nextRenderedWidget.firstChild : undefined) : paragraph.nextRenderedWidget;
}
else {
nextOrPrevSibling = isNullOrUndefined(paragraph.previousRenderedWidget) ? (!isNullOrUndefined(ownerCell.previousRenderedWidget) ? ownerCell.previousRenderedWidget.firstChild : undefined) : paragraph.previousRenderedWidget;
}
if (ownerCell.index === 0 && paragraph.index === 0) {
if (ownerRow.index === 0) {
if (ownerTable.isInsideTable && ownerTable.index == 0) {
nextOrPrevSibling = this.checkOwnerTablePrevItem(ownerTable, paragraph);
}
else {
//If paragraph is preserved in first row first cell means, need to check owner table previous sibling.
var ownerTablePrevSibling = ownerTable.previousRenderedWidget;
return ownerTablePrevSibling;
}
}
else {
if (isNullOrUndefined(nextOrPrevSibling) && paragraph.paragraphFormat.baseStyle.name === "Normal" && paragraph.paragraphFormat.listFormat.listId < 0) {
return paragraph;
}
return nextOrPrevSibling;
}
}
else if (paragraph.index === 0 && !isAfterSpacing) {
//If para is first item in any cell excluding first cell, need to check previous cell last item.
var prevCell = ownerRow.childWidgets[ownerCell.index - 1];
var prevCelllastItem = prevCell.childWidgets[prevCell.childWidgets.length - 1];
//if previous cell last item is table means skip before spacing value no need to check any paragraph styles.
if (prevCelllastItem instanceof TableWidget && paragraph.paragraphFormat.baseStyle.name === "Normal" && paragraph.paragraphFormat.listFormat.listId < 0) {
return paragraph;
}
}
return nextOrPrevSibling;
};
Layout.prototype.updateLastParagraphSpacingBasedOnContextualSpacing = function (paragraph) {
var ownerCell = paragraph.associatedCell;
var ownerRow = ownerCell.ownerRow;
var nextCellFirstItem;
if (ownerCell.index === ownerRow.childWidgets.length - 1 && paragraph.index === ownerCell.childWidgets.length - 1) {
if (paragraph.paragraphFormat.baseStyle.name === "Normal" && paragraph.paragraphFormat.listFormat.listId < 0) {
//If para preserved in last item in cell and cell is last cell in current row means its after spacing value not considered.
return paragraph;
}
}
else if (paragraph.index === ownerCell.childWidgets.length - 1) {
//If current para is last item in current cell then need to check next cell first item.
var nextCell = ownerRow.childWidgets[ownerCell.index + 1];
nextCellFirstItem = nextCell.firstChild;
//If next cell first item is table then need to check inner table first para.
//This is applicable for multiple nested table so when first item is table it try to get its first paragraph.
while (nextCellFirstItem instanceof TableWidget) {
nextCellFirstItem = nextCellFirstItem.childWidgets[0].childWidgets[0].childWidgets[0];
}
}
return nextCellFirstItem;
};
Layout.prototype.checkOwnerTablePrevItem = function (ownerTable, paragraph) {
var row = ownerTable.associatedCell.ownerRow;
var prevSibling;
if (row.index > 0) {
if (paragraph.paragraphFormat.baseStyle.name === "Normal" && paragraph.paragraphFormat.listFormat.listId < 0) {
return paragraph;
}
}
else {
if (row.ownerTable.isInsideTable && row.ownerTable.index === 0) {
this.checkOwnerTablePrevItem(row.ownerTable, paragraph);
}
else {
var prevSibling_1 = row.ownerTable.previousRenderedWidget;
return prevSibling_1;
}
}
return prevSibling;
};
Object.defineProperty(Layout.prototype, "viewer", {
get: function () {
return this.documentHelper.owner.viewer;
},
enumerable: true,
configurable: true
});
Layout.prototype.layout = function () {
// Todo: Need to handle complete document layout(relayout).
//const page: Page = this.documentHelper.pages[0];
//const body: BodyWidget = page.bodyWidgets[0];
};
/**
* Releases un-managed and - optionally - managed resources.
*
* @returns {void}
*/
Layout.prototype.destroy = function () {
this.documentHelper = undefined;
this.value = undefined;
this.allowLayout = undefined;
this.isInitialLoad = undefined;
this.fieldBegin = undefined;
this.maxTextHeight = undefined;
this.maxBaseline = undefined;
this.maxTextBaseline = undefined;
this.isSkipFirstLineIndent = undefined;
this.isFieldCode = undefined;
this.footnoteHeight = undefined;
this.isMultiColumnDoc = undefined;
this.isIFfield = undefined;
this.isPastingContent = undefined;
};
/**
* @private
* @returns {void}
*/
Layout.prototype.layoutWholeDocument = function (isLayoutChanged, skipClearContent) {
this.isInitialLoad = true;
this.isLayoutWhole = true;
var startPosition = undefined;
var endPosition = undefined;
var startIndex = undefined;
var endIndex = undefined;
if (this.documentHelper.selection) {
startPosition = this.documentHelper.selection.start;
endPosition = this.documentHelper.selection.end;
if (startPosition.isExistAfter(endPosition)) {
startPosition = this.documentHelper.selection.end.clone();
endPosition = this.documentHelper.selection.start.clone();
}
if (this.documentHelper.owner.layoutType == 'Continuous' && (this.documentHelper.selection.isinEndnote || this.documentHelper.selection.isinFootnote)) {
this.documentHelper.selection.footnoteReferenceElement(startPosition, endPosition);
startPosition = endPosition;
}
var startInfo = this.documentHelper.selection.getParagraphInfo(startPosition);
var endInfo = this.documentHelper.selection.getParagraphInfo(endPosition);
startIndex = this.documentHelper.selection.getHierarchicalIndex(startInfo.paragraph, startInfo.offset.toString());
endIndex = this.documentHelper.selection.getHierarchicalIndex(endInfo.paragraph, endInfo.offset.toString());
}
this.documentHelper.renderedLists.clear();
this.documentHelper.renderedLevelOverrides = [];
// this.viewer.owner.isLayoutEnabled = true;
var sections = this.documentHelper.combineSection();
if (!skipClearContent) {
this.documentHelper.clearContent();
}
// this.documentHelper.layout.isRelayout = false;
this.layoutItems(sections, true);
// this.documentHelper.layout.isRelayout = true;
this.documentHelper.owner.isShiftingEnabled = false;
if (this.documentHelper.selection && this.documentHelper.owner.editorModule) {
this.documentHelper.owner.editorModule.setPositionForCurrentIndex(startPosition, startIndex);
this.documentHelper.owner.editorModule.setPositionForCurrentIndex(endPosition, endIndex);
this.documentHelper.selection.selectPosition(startPosition, endPosition);
this.documentHelper.owner.editorModule.reLayout(this.documentHelper.selection, undefined, isLayoutChanged);
}
this.isLayoutWhole = false;
this.isInitialLoad = false;
};
Layout.prototype.layoutItems = function (sections, isReLayout, isContinuousSection, isAsync) {
var _this = this;
var processLayout = function () { return __awaiter(_this, void 0, void 0, function () {
var page, height, width, i, section, headersFooters, key, currentHeaderFooter, nextSection, lastpage, bodyWidget, lastChild_1, previousWidget, removedPages, breakCode, prevSection, splitWidgets, nextColumn, lastChild, previousWidget, clientY, clientHeight, section_1, height_1, pageIndex, i_1, prevPage, prevSectionIndex, index, layoutResult, sectionHeight, i;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
height = 0;
width = 0;
i = 0;
_a.label = 1;
case 1:
if (!(i < sections.length)) return [3 /*break*/, 6];
section = sections[i];
if (!!this.documentHelper.owner.enableLayout) return [3 /*break*/, 2];
this.viewer.createNewPage(section);
headersFooters = this.documentHelper.headersFooters[section.index];
if (headersFooters) {
for (key in headersFooters) {
if (headersFooters.hasOwnProperty(key)) {
currentHeaderFooter = headersFooters[key];
currentHeaderFooter.page = section.page;
currentHeaderFooter.headerSectionIndex = section.index;
}
}
}
return [3 /*break*/, 5];
case 2:
if (section.sectionFormat.numberOfColumns > 1) {
this.isMultiColumnDoc = true;
}
nextSection = sections[i + 1];
this.viewer.columnLayoutArea.setColumns(section.sectionFormat);
lastpage = this.documentHelper.pages[this.documentHelper.pages.length - 1];
bodyWidget = void 0;
if (!isNullOrUndefined(lastpage) && !isNullOrUndefined(lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1]) && lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1].childWidgets.length === 0 && !isNullOrUndefined(lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1].previousSplitWidget)) {
bodyWidget = lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1].previousSplitWidget;
}
/* eslint-disable-next-line max-len */
// If page break next para is section last para and it is empty then ms word will layout in the section break in previous para. So checking the next para into existing behaviour.
if (i > 0 && !isNullOrUndefined(bodyWidget) && !isNullOrUndefined(bodyWidget.lastChild) && !(bodyWidget.lastChild instanceof TableWidget)) {
lastChild_1 = bodyWidget.lastChild;
previousWidget = lastChild_1.previousRenderedWidget;
if (lastChild_1 instanceof ParagraphWidget && lastChild_1.isSectionBreak && previousWidget instanceof ParagraphWidget && previousWidget.isEndsWithPageBreak) {
lastChild_1 = previousWidget;
}
if ((this.documentHelper.compatibilityMode === 'Word2013' && (lastChild_1.isEndsWithPageBreak || lastChild_1.isEndsWithColumnBreak)) && lastpage.bodyWidgets[0].childWidgets.length === 0) {
removedPages = this.documentHelper.pages.splice(this.documentHelper.pages.length - 1, 1);
removedPages[0].destroy();
lastpage = this.documentHelper.pages[this.documentHelper.pages.length - 1];
}
}
breakCode = section.sectionFormat.breakCode;
prevSection = undefined;
if (i !== 0 && this.documentHelper.compatibilityMode === 'Word2010' && breakCode === 'NewColumn') {
splitWidgets = sections[i - 1].getSplitWidgets();
prevSection = splitWidgets[splitWidgets.length - 1];
if (prevSection.sectionFormat.columns.length > 1 && section.sectionFormat.columns.length > 1 && prevSection.sectionFormat.columns.length === section.sectionFormat.columns.length && prevSection.sectionFormat.columns.length - 1 !== prevSection.columnIndex && !(prevSection.lastChild instanceof ParagraphWidget && prevSection.lastChild.isEndsWithPageBreak)) {
nextColumn = this.viewer.columnLayoutArea.getNextColumnByBodyWidget(prevSection);
if (!isNullOrUndefined(nextColumn)) {
section.columnIndex = nextColumn.index;
section.isWord2010NextColumn = true;
section.y = prevSection.y;
this.viewer.clientActiveArea.height -= section.y - this.viewer.clientActiveArea.y;
this.viewer.clientActiveArea.y = section.y;
}
}
}
if (!section.isWord2010NextColumn && breakCode !== 'NoBreak') {
breakCode = 'NewPage';
}
lastChild = void 0;
if (i !== 0) {
lastChild = lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1].lastChild;
if (lastChild) {
previousWidget = lastChild.previousRenderedWidget;
if (lastChild instanceof ParagraphWidget && lastChild.isSectionBreak && previousWidget instanceof ParagraphWidget) {
lastChild = previousWidget;
}
}
}
if ((i === 0 && !isContinuousSection) || (i !== 0 && !section.isWord2010NextColumn && (isNullOrUndefined(breakCode) || breakCode === 'NewPage' || height !== section.sectionFormat.pageHeight || width !== section.sectionFormat.pageWidth || (!isNullOrUndefined(lastChild) && lastChild.isEndsWithPageBreak)))) {
page = this.viewer.createNewPage(section);
}
else {
clientY = this.documentHelper.viewer.clientActiveArea.y;
clientHeight = this.documentHelper.viewer.clientActiveArea.height;
if (isContinuousSection) {
section_1 = this.getBodyWidget(lastpage.bodyWidgets[lastpage.bodyWidgets.length - 1], true);
height_1 = this.getNextWidgetHeight(section_1);
this.viewer.updateClientArea(section_1, section_1.page);
clientHeight = this.viewer.clientActiveArea.height - (height_1 - this.viewer.clientActiveArea.y);
clientY = height_1;
isContinuousSection = false;
}
page = lastpage;
page.bodyWidgets.push(section);
page.bodyWidgets[page.bodyWidgets.length - 1].page = page;
this.documentHelper.viewer.updateClientArea(section, page);
this.documentHelper.viewer.clientActiveArea.y = clientY;
this.documentHelper.viewer.clientActiveArea.height = clientHeight;
}
height = section.sectionFormat.pageHeight;
width = section.sectionFormat.pageWidth;
this.addBodyWidget(this.viewer.clientActiveArea, section);
if (this.documentHelper.pages.length > 1) {
pageIndex = 0;
for (i_1 = 0; i_1 < this.documentHelper.pages.length; i_1++) {
prevPage = this.documentHelper.pages[i_1];
prevSectionIndex = prevPage.sectionIndex;
index = section.index;
if (prevSectionIndex > index || prevPage === page) {
break;
}
pageIndex++;
}
if (pageIndex < this.documentHelper.pages.length - 1) {
this.documentHelper.insertPage(pageIndex, page);
}
}
layoutResult = this.layoutSection(section, 0, nextSection, isAsync);
if (!(layoutResult instanceof Promise)) return [3 /*break*/, 4];
return [4 /*yield*/, layoutResult];
case 3:
_a.sent();
_a.label = 4;
case 4:
if (section.isWord2010NextColumn && !isNullOrUndefined(prevSection)) {
sectionHeight = this.getNextWidgetHeight(prevSection);
if (this.viewer.clientActiveArea.y < sectionHeight) {
this.viewer.updateClientArea(prevSection, prevSection.page);
this.viewer.clientActiveArea.height = this.viewer.clientActiveArea.height - (sectionHeight - this.viewer.clientActiveArea.y);
this.viewer.clientActiveArea.y = sectionHeight;
}
}
_a.label = 5;
case 5:
i++;
return [3 /*break*/, 1];
case 6:
if (!isReLayout && !isAsync) {
this.layoutComments(this.documentHelper.comments);
}
if (this.documentHelper.owner.enableLayout) {
this.updateFieldElements();
}
else if (this.documentHelper.owner.layoutType === 'Pages') {
for (i = 0; i < this.documentHelper.footnoteCollection.length; i++) {
this.layoutFootEndNoteElement(this.documentHelper.footnoteCollection[i]);
}
}
if (this.documentHelper.owner.layoutType === 'Pages') {
this.layoutEndNoteElement();
}
/* tslint:disable:align */
setTimeout(function () {
if (_this.documentHelper) {
_this.documentHelper.isScrollHandler = true;
// if (this.documentHelper.owner.isSpellCheck && this.documentHelper.owner.spellChecker.enableOptimizedSpellCheck) {
// this.documentHelper.triggerElementsOnLoading = true;
// }
_this.viewer.updateScrollBars();
_this.documentHelper.isScrollHandler = false;
_this.isInitialLoad = false;
}
}, 50);
return [2 /*return*/];
}
});
}); };
// Determine execution path
if (isAsync) {
return processLayout();
}
else {
processLayout();
return;
}
};
/**
* @private
*/
Layout.prototype.layoutComments = function (comments) {
if (!isNullOrUndefined(comments)) {
this.viewer.owner.commentReviewPane.layoutComments(comments);
}
};
Layout.prototype.shouldScrollUpdateIn = function () {
var currentPageCount = this.documentHelper.pages.length;
var settings = this.owner.documentEditorSettings.openAsyncSettings;
var initialPageCount = isNullOrUndefined(settings.initialPageLoadCount) || settings.initialPageLoadCount < 0 ? 3 : settings.initialPageLoadCount;
var incrementalPageCount = isNullOrUndefined(settings.incrementalPageLoadCount) || settings.incrementalPageLoadCount < 0 ? 5 : settings.incrementalPageLoadCount;
if ((currentPageCount === initialPageCount || (currentPageCount > initialPageCount && (currentPageCount - initialPageCount) % incrementalPageCount === 0)) && currentPageCount !== this.lastScrollUpdatePageIndex) {
this.lastScrollUpdatePageIndex = currentPageCount;
return true;
}
return false;
};
Layout.prototype.layoutSection = function (section, index, nextSection, isAsync) {
var _this = this;
var block = section.firstChild;
var nextBlock;
var prevBlock;
var processBlocks = function () { return __awaiter(_this, void 0, void 0, function () {
var layoutResult, shouldScrollUpdate, splittedSection, bodyWidget, firstBody, height, page;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!block) return [3 /*break*/, 7];
if (!this.isLayoutWhole && block instanceof TableWidget && block.tableFormat.preferredWidthType === 'Auto'
&& !block.tableFormat.allowAutoFit) {
block.calculateGrid();
}
if (!!isNullOrUndefined(block)) return [3 /*break*/, 4];
this.viewer.updateClientAreaForBlock(block, true, undefined, true, true);
layoutResult = this.layoutBlock(block, index, undefined, isAsync);
if (!(layoutResult instanceof Promise)) return [3 /*break*/, 2];
return [4 /*yield*/, layoutResult];
case 1:
nextBlock = _a.sent();
return [3 /*break*/, 3];
case 2:
nextBlock = layoutResult;
_a.label = 3;
case 3:
index = 0;
this.viewer.updateClientAreaForBlock(block, false);
prevBlock = block;
block = nextBlock;
_a.label = 4;
case 4:
if (!isAsync) return [3 /*break*/, 6];
shouldScrollUpdate = this.shouldScrollUpdateIn();
if (!shouldScrollUpdate) return [3 /*break*/, 6];
this.processAsyncPageUpdate(section);
if (!this.documentHelper.isUpdatedWhileLoadAsync) {
this.documentHelper.performUpdateAfterLoad(true);
this.documentHelper.isUpdatedWhileLoadAsync = true;
}
return [4 /*yield*/, new Promise(function (resolve) {
var timeoutId = setTimeout(resolve, 0);
if (_this.documentHelper.currentDocumentLoadId) {
_this.documentHelper.storeTimeoutId(_this.documentHelper.currentDocumentLoadId, timeoutId);
}
})];
case 5:
_a.sent();
_a.label = 6;
case 6: return [3 /*break*/, 0];
case 7:
block = section.firstChild;
if (this.viewer instanceof PageLayoutViewer && section.sectionFormat.numberOfColumns > 1 && !isNullOrUndefined(nextSection) && nextSection.sectionFormat.breakCode === 'NoBreak' && (section.sectionFormat.breakCode === 'NoBreak' || (section.sectionIndex === section.page.bodyWidgets[0].sectionIndex))) {
if (this.getColumnBreak(section)) {
splittedSection = section.getSplitWidgets();
bodyWidget = splittedSection[splittedSection.length - 1];
if (!isNullOrUndefined(section.page.nextPage)) {
this.splitBodyWidgetBasedOnColumn(bodyWidget);
}
else {
firstBody = this.getBodyWidget(bodyWidget, true);
this.viewer.updateClientArea(firstBody, firstBody.page);
height = this.getNextWidgetHeight(firstBody);
this.viewer.clientActiveArea.height -= height - this.viewer.clientActiveArea.y;
this.viewer.clientActiveArea.y = height;
}
}
else {
if (!isNullOrUndefined(section.page.nextPage)) {
section = this.documentHelper.pages[this.documentHelper.pages.length - 1].bodyWidgets[0];
}
this.splitBodyWidgetBasedOnColumn(section);
}
}
if (block && block.bodyWidget && block.bodyWidget.page) {
page = block.bodyWidget.page;
}
while (page) {
if (page.footnoteWidget) {
this.layoutfootNote(page.footnoteWidget);
}
page = page.nextPage;
}
return [2 /*return*/];
}
});
}); };
if (isAsync) {
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, processBlocks()];
case 1:
_a.sent();
resolve();
return [2 /*return*/];
}
});
}); });
}
else {
processBlocks();
return;
}
};
Layout.prototype.processAsyncPageUpdate = function (section) {
this.documentHelper.owner.notify(internalAsyncPagesVisible, {});
this.documentHelper.isDocumentLoadAsynchronously = true;
var page;
if (section instanceof BodyWidget && section.firstChild && section.firstChild.bodyWidget && section.firstChild.bodyWidget.page) {
page = section.firstChild.bodyWidget.page;
}
while (page) {
if (page.footnoteWidget) {
this.layoutfootNote(page.footnoteWidget);
}
page = page.nextPage;
}
page = undefined;
// this.updateFieldElements();
if (this.owner.selectionModule) {
this.owner.selection.previousSelectedFormField = undefined;
if (this.documentHelper.formFields.length > 0) {
this.owner.selectionModule.highlightFormFields();
}
else {
this.viewer.updateScrollBars();
}
this.owner.selectionModule.editRangeCollection = [];
if (this.owner.documentHelper.isDocumentProtected) {
this.owner.selection.isHighlightEditRegion = true;
}
}
};
/**
* @private
*
*/
Layout.prototype.reLayoutMultiColumn = function (section, isFirstBlock, blockIndex) {
this.isInitialLoad = true;
section = section.getSplitWidgets()[0];
this.combineMultiColumnForRelayout(section);
if (section.sectionFormat.numberOfColumns > 1) {
this.isMultiColumnDoc = true;
}
this.isMultiColumnSplit = false;
var previousSection = section.previousRenderedWidget;
var nextSection = section.nextRenderedWidget;
var isUpdatedClientArea = false;
// Section's Y position is not updated properly when the two sections combined and layouted.
if (!isFirstBlock && !isNullOrUndefined(section.firstChild) && section.firstChild instanceof ParagraphWidget && section.y !== section.firstChild.y) {
section.y = section.firstChild.y;
}
if (isFirstBlock && nextSection && section.page !== nextSection.page && section.firstChild instanceof ParagraphWidget) {
var paragraph = section.firstChild;
var lineHeight = 0;
if (paragraph.isEmpty()) {
lineHeight = this.documentHelper.textHelper.getParagraphMarkSize(paragraph.characterFormat).Height;
}
else {
var firstLine = paragraph.childWidgets[0];
lineHeight = this.getMaxElementHeight(firstLine);
}
var previousBlock = paragraph.previousRenderedWidget;
if (section.y === this.viewer.clientActiveArea.y && lineHeight > this.viewer.clientActiveArea.height) {
previousBlock = isNullOrUndefined(previousBlock) ? paragraph : previousBlock;
this.moveBlocksToNextPage(previousBlock);
this.viewer.columnLayoutArea.setColumns(section.sectionFormat);
this.viewer.updateClientArea(section, section.page);
isUpdatedClientArea = true;
}
}
else if (!isNullOrUndefined(previousSection) && previousSection.page !== section.page && section.firstChild instanceof ParagraphWidget && previousSection.lastChild instanceof ParagraphWidget) {
var previousParagraph = previousSection.lastChild;
var paragraph = section.firstChild;
if (section instanceof BodyWidget && previousSection.lastChild && previousParagraph instanceof ParagraphWidget && previousSection.sectionFormat.breakCode === 'NoBreak' && section.page.index !== previousSection.page.index && section.index !== previousSection.index) {
var bodyWidget = previousSection;
if (bodyWidget.sectionFormat.columns.length > 1) {
bodyWidget = this.getBodyWidget(bodyWidget, true);
}
var bottom = HelperMethods.round((this.getNextWidgetHeight(bodyWidget) + paragraph.height), 2);
// Bug 858530: Shift the widgets to previous container widget if the client height is not enough to place this widget.
if (!previousSection.lastChild.isEndsWithPageBreak && !previousSection.lastChild.isEndsWithColumnBreak
&& bottom <= HelperMethods.round(this.viewer.clientActiveArea.bottom, 2)) {
var page = previousSection.page;
var nextPage = section.page;
for (var j = 0; j < nextPage.bodyWidgets.length; j++) {
var nextBodyWidget = nextPage.bodyWidgets[j];
nextPage.bodyWidgets.splice(nextPage.bodyWidgets.indexOf(nextBodyWidget), 1);
page.bodyWidgets.splice(page.bodyWidgets.length, 0, nextBodyWidget);
nextBodyWidget.page = page;
j--;
}
section.y = this.viewer.clientActiveArea.y;
this.documentHelper.removeEmptyPages();
}
}
}
if (!isUpdatedClientArea) {
this.viewer.columnLayoutArea.setColumns(section.sectionFormat);
this.viewer.updateClientArea(section, section.page);
this.viewer.clientActiveArea.height -= section.y - this.viewer.clientActiveArea.y;
this.viewer.clientActiveArea.y = section.y;
}
this.addBodyWidget(this.viewer.clientActiveArea, section);
this.clearBlockWidget(section.childWidgets, true, true, true);
this.isMultiColumnLayout = true;
this.reLayoutMultiColumnBlock(section, nextSection, blockIndex);
this.isMultiColumnLayout = false;
this.isInitialLoad = false;
var splitSections = section.getSplitWidgets();
var lastSection = splitSections[splitSections.length - 1];
var firstBody = this.getBodyWidget(lastSection, true);
this.viewer.updateClientArea(firstBody, firstBody.page);
var height = this.getNextWidgetHeight(firstBody);
this.viewer.clientActiveArea.height -= height - this.viewer.clientActiveArea.y;
this.viewer.clientActiveArea.y = height;
if (!isNullOrUndefined(lastSection) && !isNullOrUndefined(lastSection.nextRenderedWidget)) {
nextSection = lastSection.nextRenderedWidget;
var clientY = this.documentHelper.viewer.clientActiveArea.y;
var clientHeight = this.documentHelper.viewer.clientActiveArea.height;
this.documentHelper.viewer.updateClientArea(nextSection, nextSection.page);
this.documentHelper.viewer.clientActiveArea.y = clientY;
this.documentHelper.viewer.clientActiveArea.height = clientHeight;
this.documentHelper.blockToShift = nextSection.firstChild;
}
if (isNullOrUndefined(lastSection.nextRenderedWidget) ||
(!isNullOrUndefined(lastSection.nextRenderedWidget) && lastSection.sectionFormat.breakCode !== 'NoBreak' && lastSection.nextRenderedWidget.sectionFormat.pageHeight !== lastSection.sectionFormat.pageHeight && lastSection.nextRenderedWidget.sectionFormat.pageWidth !== lastSection.sectionFormat.pageWidth)) {
this.documentHelper.blockToShift = undefined;
}
};
Layout.prototype.combineMultiColumnForRelayout = function (section) {
var splitSections = section.getSplitWidgets();
var firstSection = splitSections[0];
section = splitSections[splitSections.length - 1];
while (section !== firstSection) {
var prevSection = section.previousRenderedWidget;
var isPreviousSplit = false;
for (var i = 0; i < section.childWidgets.length; i++) {
if (section.childWidgets[i] instanceof BlockWidget && !isNullOrUndefined(section.childWidgets[i].previousSplitWidget)
&& !isNullOrUndefined(section.childWidgets[i].previousSplitWidget.previousSplitWidget)
&& section.childWidgets[i].previousSplitWidget.bodyWidget.page !== section.childWidgets[i].previousSplitWidget.previousSplitWidget.bodyWidget.page) {
isPreviousSplit = true;
}
if ((section.childWidgets[i] instanceof BlockWidget && !isNullOrUndefined(section.childWidgets[i].previousSplitWidget) && section.childWidgets[i].previousSplitWidget.bodyWidget.page === section.childWidgets[i].bodyWidget.page && !isPreviousSplit)) {
section.childWidgets[i].combineWidget(this.viewer);
if (prevSection.lastChild instanceof TableWidget) {
this.updateCellHeightInCombinedTable(prevSection.lastChild);
}
i--;
continue;
}
prevSection.childWidgets.push(section.childWidgets[i]);
section.childWidgets[i].containerWidget = prevSection;
section.childWidgets[i].containerWidget.page = prevSection.page;
section.childWidgets.splice(0, 1);
i--;
}
section = section.previousRenderedWidget;
}
this.documentHelper.removeEmptyPages();
};
Layout.prototype.reLayoutMultiColumnBlock = function (section, nextSection, blockIndex) {
var block = section.firstChild;
var nextBlock;
do {
if (block instanceof TableWidget && block.tableFormat.preferredWidthType === 'Auto'
&& !block.tableFormat.allowAutoFit) {
block.calculateGrid();
}
if (!isNullOrUndefined(block)) {
this.viewer.updateClientAreaForBlock(block, true, undefined, true);
nextBlock = this.layoutBlock(block, 0, block.index < blockIndex ? true : false);
this.viewer.updateClientAreaForBlock(block, false);
block = nextBlock;
}
} while (block && section.getSplitWidgets().indexOf(block.bodyWidget) !== -1);
block = section.firstChild;
if (this.viewer instanceof PageLayoutViewer && section.sectionFormat.numberOfColumns > 1 && !isNullOrUndefined(nextSection) && nextSection.sectionFormat.breakCode === 'NoBreak' && (section.sectionFormat.breakCode === 'NoBreak' || (section.sectionIndex === section.page.bodyWidgets[0].sectionIndex))) {
var splittedSection = section.getSplitWidgets();
var bodyWidget = splittedSection[splittedSection.length - 1];
if (this.getColumnBreak(section)) {
if (section.page !== bodyWidget.page) {
this.splitBodyWidgetBasedOnColumn(bodyWidget);
}
else {
var firstBody = this.getBodyWidget(bodyWidget, true);
this.viewer.updateClientArea(firstBody, firstBody.page);
var height = this.getNextWidgetHeight(firstBody);
this.viewer.clientActiveArea.height -= height - this.viewer.clientActiveArea.y;
this.viewer.clientActiveArea.y = height;
}
}
else if (!isNullOrUndefined(section.page.nextPage)) {
this.splitBodyWidgetBasedOnColumn(bodyWidget);
}
}
};
Layout.prototype.splitBodyWidgetBasedOnColumn = function (section) {
section = this.getBodyWidget(section, true);
var firstSection = section;
this.isMultiColumnSplit = true;
if (!this.isInitialLoad && section.sectionFormat.equalWidth) {
var previousStartIndex = this.documentHelper.selection.startOffset;
var previousEndIndex = this.documentHelper.selection.endOffset;
this.combineMultiColumn(section);
this.layoutMultiColumnBody(section, false);
if (previousStartIndex !== this.documentHelper.selection.startOffset) {
this.documentHelper.selection.select(previousStartIndex, previousEndIndex);
}
}
this.combineMultiColumn(section);
var lineCountInfo = this.getCountOrLine(section, undefined, undefined, true);
var totalHeight = lineCountInfo.lineCount;
var lineToBeSplit = Math.round(totalHeight / section.sectionFormat.numberOfColumns);
while (section) {
var lineCountI