@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
758 lines • 176 kB
JavaScript
import { WParagraphFormat } from '../format/paragraph-format';
import { WCharacterFormat } from '../format/index';
import { LineWidget, ParagraphWidget, BodyWidget, TextElementBox, FieldElementBox, TableRowWidget, TableCellWidget, ImageElementBox, ContentControl, ListTextElementBox, BookmarkElementBox, EditRangeStartElementBox, EditRangeEndElementBox, ChartElementBox, CommentCharacterElementBox, TextFormField, CheckBoxFormField, ShapeElementBox, FootnoteElementBox, BreakElementBox, FootnoteEndnoteMarkerElementBox, FootNoteWidget } from '../viewer/page';
import { BlockWidget } from '../viewer/page';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { HelperMethods } from '../editor/editor-helper';
import { ZipArchive, ZipArchiveItem } from '@syncfusion/ej2-compression';
import { sectionsProperty, imagesProperty, fontSubstitutionTableProperty, paraStyleNameProperty, characterFormatProperty, paragraphFormatProperty, listsProperty, abstractListsProperty, backgroundProperty, stylesProperty, commentsProperty, revisionsProperty, customXmlProperty, defaultTabWidthProperty, formattingProperty, trackChangesProperty, protectionTypeProperty, enforcementProperty, hashValueProperty, saltValueProperty, doNotUseHTMLParagraphAutoSpacingProperty, formFieldShadingProperty, lastParagraphMarkCopiedProperty, footnotesProperty, endnotesProperty, compatibilityModeProperty, themeFontLanguagesProperty, themesProperty, nameProperty, basedOnProperty, nextProperty, linkProperty, fontSizeProperty, fontColorProperty, styleNameProperty, bidiProperty, boldBidiProperty, italicBidiProperty, revisionIdsProperty, listIdProperty, listLevelNumberProperty, leftIndentProperty, listFormatProperty, bordersProperty, tabsProperty, headerDistanceProperty, footerDistanceProperty, differentFirstPageProperty, differentOddAndEvenPagesProperty, pageWidthProperty, pageHeightProperty, leftMarginProperty, rightMarginProperty, topMarginProperty, bottomMarginProperty, restartPageNumberingProperty, pageStartingNumberProperty, endnoteNumberFormatProperty, footNoteNumberFormatProperty, restartIndexForFootnotesProperty, restartIndexForEndnotesProperty, initialFootNoteNumberProperty, initialEndNoteNumberProperty, pageNumberStyleProperty, columnsProperty, numberOfColumnsProperty, equalWidthProperty, lineBetweenColumnsProperty, breakCodeProperty, cellWidthProperty, columnSpanProperty, rowSpanProperty, verticalAlignmentProperty, allowBreakAcrossPagesProperty, isHeaderProperty, heightTypeProperty, gridBeforeProperty, gridBeforeWidthProperty, gridBeforeWidthTypeProperty, gridAfterProperty, gridAfterWidthProperty, gridAfterWidthTypeProperty, allowAutoFitProperty, cellSpacingProperty, shadingProperty, tableAlignmentProperty, preferredWidthProperty, preferredWidthTypeProperty, textureProperty, backgroundColorProperty, foregroundColorProperty, verticalProperty, horizontalProperty, diagonalUpProperty, diagonalDownProperty, lineStyleProperty, layoutProperty, dataFormatProperty, yValueProperty, chartDataProperty, categoryXNameProperty, lineProperty, foreColorProperty, layoutXProperty, layoutYProperty, directionProperty, endStyleProperty, numberValueProperty, markerStyleProperty, markerColorProperty, markerSizeProperty, forwardProperty, backwardProperty, interceptProperty, isDisplayRSquaredProperty, isDisplayEquationProperty, seriesNameProperty, dataLabelProperty, errorBarProperty, seriesFormatProperty, trendLinesProperty, dataPointsProperty, firstSliceAngleProperty, holeSizeProperty, isLegendKeyProperty, isBubbleSizeProperty, isCategoryNameProperty, isSeriesNameProperty, isValueProperty, isPercentageProperty, isLeaderLinesProperty, showSeriesKeysProperty, hasHorizontalBorderProperty, hasVerticalBorderProperty, hasBordersProperty, categoryTypeProperty, chartCategoryProperty, chartSeriesProperty, chartAreaProperty, chartTitleAreaProperty, plotAreaProperty, chartLegendProperty, chartPrimaryCategoryAxisProperty, chartPrimaryValueAxisProperty, chartTitleProperty, chartTypeProperty, gapWidthProperty, overlapProperty, chartDataTableProperty, textProperty, shapeIdProperty, alternativeTextProperty, visibleProperty, widthProperty, heightProperty, widthScaleProperty, heightScaleProperty, lineFormatProperty, fillFormatProperty, textWrappingStyleProperty, textWrappingTypeProperty, verticalRelativePercentProperty, horizontalRelativePercentProperty, heightRelativePercentProperty, widthRelativePercentProperty, zOrderPositionProperty, layoutInCellProperty, lockAnchorProperty, autoShapeTypeProperty, textFrameProperty, colorProperty, fillProperty, textVerticalAlignmentProperty, imageStringProperty, metaFileImageStringProperty, isMetaFileProperty, topProperty, bottomProperty, rightProperty, leftProperty, getImageHeightProperty, getImageWidthProperty, hasFieldEndProperty, formFieldDataProperty, fieldTypeProperty, enabledProperty, helpTextProperty, statusTextProperty, textInputProperty, checkBoxProperty, dropDownListProperty, maxLengthProperty, defaultValueProperty, formatProperty, sizeTypeProperty, sizeProperty, checkedProperty, dropDownItemsProperty, selectedIndexProperty, commentIdProperty, commentCharacterTypeProperty, authorProperty, dateProperty, doneProperty, replyCommentsProperty, revisionTypeProperty, revisionIdProperty, itemIDProperty, xmlProperty, footnoteTypeProperty, symbolCodeProperty, symbolFontNameProperty, customMarkerProperty, inlinesProperty, contentControlPropertiesProperty, lockContentControlProperty, lockContentsProperty, tagProperty, titleProperty, hasPlaceHolderTextProperty, multiLineProperty, isTemporaryProperty, dateCalendarTypeProperty, dateStorageFormatProperty, dateDisplayLocaleProperty, dateDisplayFormatProperty, isCheckedProperty, uncheckedStateProperty, checkedStateProperty, contentControlListItemsProperty, xmlMappingProperty, fontProperty, valueProperty, displayTextProperty, isMappedProperty, isWordMlProperty, prefixMappingProperty, xPathProperty, storeItemIdProperty, customXmlPartProperty, idProperty, cellFormatProperty, rowFormatProperty, cellsProperty, rowsProperty, descriptionProperty, wrapTextAroundProperty, positioningProperty, tableFormatProperty, allowOverlapProperty, distanceTopProperty, distanceRightProperty, distanceLeftProperty, distanceBottomProperty, verticalOriginProperty, verticalPositionProperty, horizontalOriginProperty, horizontalAlignmentProperty, horizontalPositionProperty, blocksProperty, headerProperty, footerProperty, evenHeaderProperty, evenFooterProperty, firstPageHeaderProperty, firstPageFooterProperty, headersFootersProperty, sectionFormatProperty, listLevelPatternProperty, followCharacterProperty, startAtProperty, restartLevelProperty, levelNumberProperty, numberFormatProperty, abstractListIdProperty, levelsProperty, overrideListLevelProperty, levelOverridesProperty, separatorProperty, continuationSeparatorProperty, continuationNoticeProperty, bookmarkTypeProperty, propertiesProperty, tabJustificationProperty, positionProperty, deletePositionProperty, tabLeaderProperty, editRangeIdProperty, columnFirstProperty, columnLastProperty, userProperty, groupProperty, editableRangeStartProperty, spaceProperty, fontSchemeProperty, fontSchemeNameProperty, majorFontSchemeProperty, minorFontSchemeProperty, fontSchemeListProperty, fontTypefaceProperty, typefaceProperty, panoseProperty, typeProperty, majorUnitProperty, maximumValueProperty, minimumValueProperty, hasMajorGridLinesProperty, hasMinorGridLinesProperty, majorTickMarkProperty, minorTickMarkProperty, tickLabelPositionProperty, rgbProperty, appearanceProperty, lineFormatTypeProperty, allowSpaceOfSameStyleInTableProperty, weightProperty, inlineFormatProperty, fontNameProperty, isCompressedProperty, columnIndexProperty, columnCountProperty, gridProperty, isAfterParagraphMarkProperty, isAfterCellMarkProperty, isAfterRowMarkProperty, isAfterTableMarkProperty, belowTextProperty, breakClearTypeProperty, nsidProperty, isLegalStyleNumberingProperty, horizontalRuleProperty, isAutoMajorProperty } from '../../index';
/**
* Exports the document to Sfdt format.
*/
var SfdtExport = /** @class */ (function () {
function SfdtExport(documentHelper) {
/* eslint-disable @typescript-eslint/no-explicit-any */
this.startLine = undefined;
this.endLine = undefined;
this.endOffset = undefined;
this.endCell = undefined;
this.startColumnIndex = undefined;
this.endColumnIndex = undefined;
this.lists = undefined;
this.images = undefined;
this.document = undefined;
this.writeInlineStyles = undefined;
this.blockContent = false;
this.startContent = false;
this.multipleLineContent = false;
this.nestedContent = false;
this.editRangeId = -1;
this.selectedCommentsId = [];
this.selectedRevisionId = [];
this.nestedBlockContent = false;
this.nestedBlockEnabled = false;
/**
* @private
*/
this.blocks = [];
this.contentInline = [];
this.isContentControl = false;
this.isBlockClosed = true;
this.isWriteInlinesFootNote = false;
this.isWriteEndFootNote = false;
this.bookmarkCollection = [];
/**
* @private
*/
// For spell check when serailize the page no to need to wirte the formatting. So we do this property as true it will skip the formatting.
this.skipExporting = false;
/**
* @private
*/
this.iscontentInsert = true;
/**
* @private
*/
this.keywordIndex = undefined;
/**
* @private
*/
this.isExport = true;
/**
* @private
*/
this.isPartialExport = false;
this.checkboxOrDropdown = false;
/**
* @private
*/
this.copyWithTrackChange = false;
this.documentHelper = documentHelper;
}
Object.defineProperty(SfdtExport.prototype, "viewer", {
get: function () {
return this.documentHelper.owner.viewer;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SfdtExport.prototype, "owner", {
get: function () {
return this.documentHelper.owner;
},
enumerable: true,
configurable: true
});
SfdtExport.prototype.getModuleName = function () {
return 'SfdtExport';
};
SfdtExport.prototype.clear = function () {
this.writeInlineStyles = undefined;
this.startLine = undefined;
this.endLine = undefined;
this.lists = undefined;
this.images = undefined;
this.document = undefined;
this.endCell = undefined;
this.startColumnIndex = undefined;
this.endColumnIndex = undefined;
this.selectedCommentsId = [];
this.selectedRevisionId = [];
this.startBlock = undefined;
this.endBlock = undefined;
this.isPartialExport = false;
this.keywordIndex = undefined;
};
/**
* Serialize the data as Syncfusion document text.
*
* @private
*/
SfdtExport.prototype.serialize = function () {
return this.seralizeInternal(this.owner.documentEditorSettings.optimizeSfdt ? 1 : 0);
};
/**
* Serialize the data as Syncfusion document text.
*
* @private
*/
SfdtExport.prototype.seralizeInternal = function (index) {
return JSON.stringify(this.write(index));
};
/**
* @private
* @param documentHelper - Specifies document helper instance.
* @returns {Promise<Blob>}
*/
SfdtExport.prototype.saveAsBlobNonOptimized = function (documentHelper) {
var sfdt = new Blob([this.serialize()], { type: 'text/plain' });
return new Promise(function (resolve, reject) {
resolve(sfdt);
});
};
/**
* @private
* @param documentHelper - Specifies document helper instance.
* @returns {Promise<Blob>}
*/
SfdtExport.prototype.saveAsBlob = function (documentHelper) {
var jsonString = this.serialize();
var blob = new Blob([jsonString], {
type: 'application/json'
});
var archiveItem = new ZipArchiveItem(blob, "sfdt");
var mArchive = new ZipArchive();
mArchive.addItem(archiveItem);
return mArchive.saveAsBlob();
};
SfdtExport.prototype.updateEditRangeId = function () {
var index = -1;
for (var i = 0; i < this.documentHelper.editRanges.keys.length; i++) {
var keys = this.documentHelper.editRanges.keys;
for (var j = 0; j < keys[i].length; j++) {
var editRangeStart = this.documentHelper.editRanges.get(keys[i]);
for (var z = 0; z < editRangeStart.length; z++) {
index++;
editRangeStart[z].editRangeId = index;
if (!isNullOrUndefined(editRangeStart[z].editRangeEnd)) {
editRangeStart[z].editRangeEnd.editRangeId = index;
}
}
}
}
};
/**
* @private
*/
/* eslint-disable */
SfdtExport.prototype.write = function (index, line, startOffset, endLine, endOffset, writeInlineStyles, isExport) {
var _a;
if (writeInlineStyles) {
this.writeInlineStyles = true;
}
if (!isNullOrUndefined(index)) {
this.keywordIndex = index;
}
else {
this.keywordIndex = this.owner.documentEditorSettings.optimizeSfdt ? 1 : 0;
}
this.Initialize();
this.updateEditRangeId();
if (line instanceof LineWidget && endLine instanceof LineWidget) {
this.isExport = false;
if (!isNullOrUndefined(isExport)) {
this.isExport = isExport;
}
// For selection
var startPara = line.paragraph;
var endPara = endLine.paragraph;
if (this.isPartialExport) {
this.startBlock = this.getParentBlock(startPara);
this.endBlock = this.getParentBlock(endPara);
}
var startCell = startPara.associatedCell;
var endCell = endPara.associatedCell;
// Creates section
var bodyWidget = startPara.bodyWidget;
var section = this.createSection(line.paragraph.bodyWidget);
this.document[sectionsProperty[this.keywordIndex]].push(section);
var selectionStartCell = startCell;
var selectionEndCell = endCell;
if (startCell instanceof TableCellWidget) {
selectionStartCell = this.getParentCell(selectionStartCell);
}
if (endCell instanceof TableCellWidget) {
selectionEndCell = this.getParentCell(selectionEndCell);
}
var isSameCell = selectionStartCell instanceof TableCellWidget && selectionEndCell instanceof TableCellWidget
&& selectionStartCell.equals(selectionEndCell);
if (isSameCell || isNullOrUndefined(endCell)) {
this.startLine = line;
this.endLine = endLine;
this.endOffset = endOffset;
}
else {
// Todo: Handle nested table cases
if (startCell instanceof TableCellWidget) {
var startTable = startCell.getContainerTable();
var endTable = endCell.getContainerTable();
if (startTable.tableFormat === endTable.tableFormat) {
this.endCell = endCell;
if (this.endCell.ownerTable !== startCell.ownerTable && startCell.ownerTable.associatedCell
&& startCell.ownerTable.associatedCell.ownerTable === this.endCell.ownerTable &&
(startCell.ownerTable.associatedCell.childWidgets.indexOf(startCell.ownerTable) === 0)) {
startCell = startCell.ownerTable.associatedCell;
}
this.endColumnIndex = this.endCell.columnIndex + this.endCell.cellFormat.columnSpan;
this.startColumnIndex = startCell.columnIndex;
}
}
else {
this.endCell = endCell;
}
}
var nextBlock = void 0;
if ((isSameCell && !this.isPartialExport) || isNullOrUndefined(startCell)) {
var lastBlock = line.paragraph;
var paraEndOffset = this.owner.selection.getLineLength(endPara.lastChild);
var isBlockContentControl = startPara === endPara && this.endOffset === paraEndOffset + 1;
if (this.owner.documentHelper.isCopying && !isNullOrUndefined(startPara.contentControlProperties) && (startOffset === 0 || startOffset === 1) && (startPara !== endPara || (isBlockContentControl))) {
this.isContentControl = true;
nextBlock = this.writeBlock(lastBlock, 0, section[blocksProperty[this.keywordIndex]]);
if (isBlockContentControl) {
var paragraph = this.createParagraph(line.paragraph);
section[blocksProperty[this.keywordIndex]].push(paragraph);
}
this.isContentControl = false;
}
else {
var paragraph = this.createParagraph(line.paragraph);
section[blocksProperty[this.keywordIndex]].push(paragraph);
nextBlock = this.writeParagraph(line.paragraph, paragraph, section[blocksProperty[this.keywordIndex]], line.indexInOwner, startOffset);
}
if (this.isPartialExport) {
nextBlock = this.getNextBlock(nextBlock, lastBlock);
section = this.document[sectionsProperty[this.keywordIndex]][this.document[sectionsProperty[this.keywordIndex]].length - 1];
}
while (nextBlock) {
var isDifferentSection = nextBlock.containerWidget instanceof BodyWidget && lastBlock.containerWidget instanceof BodyWidget && nextBlock.containerWidget.sectionIndex !== lastBlock.containerWidget.sectionIndex;
if (isDifferentSection) {
section = this.createSection(nextBlock.containerWidget);
this.document[sectionsProperty[this.keywordIndex]].push(section);
var paragraph = this.createParagraph(nextBlock);
section[blocksProperty[this.keywordIndex]].push(paragraph);
lastBlock = nextBlock;
nextBlock = this.writeParagraph(lastBlock, paragraph, section[blocksProperty[this.keywordIndex]], line.indexInOwner, startOffset);
continue;
}
lastBlock = nextBlock;
if (this.owner.documentHelper.isCopying && nextBlock instanceof ParagraphWidget && !isNullOrUndefined(nextBlock.contentControlProperties) && nextBlock === endPara && this.endOffset !== paraEndOffset + 1) {
this.isContentControl = true;
var paragraph = this.createParagraph(nextBlock);
section[blocksProperty[this.keywordIndex]].push(paragraph);
var offset = !nextBlock.isEmpty() ? this.owner.selection.getNextValidOffset(nextBlock.firstChild, 0) : 0;
nextBlock = this.writeParagraph(nextBlock, paragraph, section[blocksProperty[this.keywordIndex]], 0, offset);
this.isContentControl = false;
}
else {
nextBlock = this.writeBlock(nextBlock, 0, section[blocksProperty[this.keywordIndex]]);
}
if (this.isPartialExport && isNullOrUndefined(nextBlock)) {
nextBlock = this.getNextBlock(nextBlock, lastBlock);
section = this.document[sectionsProperty[this.keywordIndex]][this.document[sectionsProperty[this.keywordIndex]].length - 1];
}
}
// Todo:continue in next section
}
else {
// Specially handled for nested table cases
// selection start inside table and end in paragraph outside table
if (isNullOrUndefined(endCell) && startCell.ownerTable.associatedCell) {
var startTable = startCell.getContainerTable();
var lastRow = startTable.childWidgets[startTable.childWidgets.length - 1];
var endCell_1 = lastRow.childWidgets[lastRow.childWidgets.length - 1];
if (endCell_1.ownerTable !== startCell.ownerTable && startCell.ownerTable.associatedCell
&& (startCell.ownerTable.associatedCell.childWidgets.indexOf(startCell.ownerTable) === 0)) {
while (startCell.ownerTable !== endCell_1.ownerTable) {
startCell = startCell.ownerTable.associatedCell;
}
}
this.endColumnIndex = endCell_1.columnIndex + endCell_1.cellFormat.columnSpan;
this.startColumnIndex = startCell.columnIndex;
}
var table = this.createTable(startCell.ownerTable);
section[blocksProperty[this.keywordIndex]].push(table);
var lastBlock = startCell.ownerTable;
nextBlock = this.writeTable(startCell.ownerTable, table, startCell.ownerRow.indexInOwner, section[blocksProperty[this.keywordIndex]]);
if (this.isPartialExport) {
nextBlock = this.getNextBlock(nextBlock, lastBlock);
section = this.document[sectionsProperty[this.keywordIndex]][this.document[sectionsProperty[this.keywordIndex]].length - 1];
}
while (nextBlock) {
var isDifferentSection = nextBlock.containerWidget instanceof BodyWidget && lastBlock.containerWidget instanceof BodyWidget && nextBlock.containerWidget.sectionIndex !== lastBlock.containerWidget.sectionIndex;
if (isDifferentSection) {
section = this.createSection(nextBlock.containerWidget);
this.document[sectionsProperty[this.keywordIndex]].push(section);
var paragraph = this.createParagraph(nextBlock);
section[blocksProperty[this.keywordIndex]].push(paragraph);
lastBlock = nextBlock;
nextBlock = this.writeParagraph(lastBlock, paragraph, section[blocksProperty[this.keywordIndex]], line.indexInOwner, startOffset);
continue;
}
lastBlock = nextBlock;
nextBlock = this.writeBlock(nextBlock, 0, section[blocksProperty[this.keywordIndex]]);
if (this.isPartialExport) {
nextBlock = this.getNextBlock(nextBlock, lastBlock);
section = this.document[sectionsProperty[this.keywordIndex]][this.document[sectionsProperty[this.keywordIndex]].length - 1];
}
}
}
}
else {
this.isExport = true;
if (this.documentHelper.pages.length > 0) {
var page = this.documentHelper.pages[0];
this.writePage(page, false);
}
else {
this.serializeMinimal();
}
}
this.document[backgroundProperty[this.keywordIndex]] = (_a = {}, _a[colorProperty[this.keywordIndex]] = this.documentHelper.backgroundColor, _a);
this.writeStyles(this.documentHelper);
this.writeLists(this.documentHelper);
this.writeComments(this.documentHelper);
this.writeRevisions(this.documentHelper);
this.writeCustomXml(this.documentHelper);
this.writeImages(this.documentHelper);
this.footnotes(this.documentHelper);
this.endnotes(this.documentHelper);
var doc = this.document;
this.clear();
return doc;
};
SfdtExport.prototype.serializeMinimal = function () {
var section = {};
section[sectionFormatProperty[this.keywordIndex]] = {};
section[blocksProperty[this.keywordIndex]] = [];
var paragraph = {};
paragraph[inlinesProperty[this.keywordIndex]] = [];
section[blocksProperty[this.keywordIndex]].push(paragraph);
section[headersFootersProperty[this.keywordIndex]] = {};
this.document[sectionsProperty[this.keywordIndex]].push(section);
};
SfdtExport.prototype.getNextBlock = function (nextBlock, lastBlock) {
if (isNullOrUndefined(nextBlock) && this.isPartialExport && this.endBlock
&& !this.endBlock.equals(lastBlock)) {
nextBlock = lastBlock.getSplitWidgets().pop().nextRenderedWidget;
if (nextBlock && lastBlock.bodyWidget.index !== nextBlock.bodyWidget.index) {
var section = this.createSection(nextBlock.bodyWidget);
this.document[sectionsProperty[this.keywordIndex]].push(section);
}
else {
nextBlock = undefined;
}
}
return nextBlock;
};
/**
* @private
*/
SfdtExport.prototype.Initialize = function () {
this.lists = [];
this.images = [];
this.document = {};
this.document.optimizeSfdt = this.owner.documentEditorSettings.optimizeSfdt;
this.document[sectionsProperty[this.keywordIndex]] = [];
this.document[characterFormatProperty[this.keywordIndex]] = this.writeCharacterFormat(this.documentHelper.characterFormat, this.keywordIndex);
this.document[paragraphFormatProperty[this.keywordIndex]] = this.writeParagraphFormat(this.documentHelper.paragraphFormat, this.keywordIndex);
if (!isNullOrUndefined(this.documentHelper.fontSubstitutionTable)) {
this.document[fontSubstitutionTableProperty[this.keywordIndex]] = this.writeFontSubsitutionTable(this.documentHelper);
}
this.document[themeFontLanguagesProperty[this.keywordIndex]] = this.writeCharacterFormat(this.documentHelper.themeFontLanguage, this.keywordIndex);
this.document[defaultTabWidthProperty[this.keywordIndex]] = this.documentHelper.defaultTabWidth;
this.document[trackChangesProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.owner.enableTrackChanges, this.keywordIndex);
this.document[enforcementProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.documentHelper.isDocumentProtected, this.keywordIndex);
this.document[hashValueProperty[this.keywordIndex]] = this.documentHelper.hashValue;
this.document[saltValueProperty[this.keywordIndex]] = this.documentHelper.saltValue;
this.document[formattingProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.documentHelper.restrictFormatting, this.keywordIndex);
this.document[protectionTypeProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getProtectionTypeEnumValue(this.documentHelper.protectionType) : this.documentHelper.protectionType;
this.document[doNotUseHTMLParagraphAutoSpacingProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.documentHelper.dontUseHtmlParagraphAutoSpacing, this.keywordIndex);
this.document[formFieldShadingProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.documentHelper.owner.documentEditorSettings.formFieldSettings.applyShading, this.keywordIndex);
this.document[compatibilityModeProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getCompatibilityModeEnumValue(this.documentHelper.compatibilityMode) : this.documentHelper.compatibilityMode;
this.document[allowSpaceOfSameStyleInTableProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(this.documentHelper.allowSpaceOfSameStyleInTable, this.keywordIndex);
if (this.documentHelper.hasThemes) {
this.document[themesProperty[this.keywordIndex]] = this.writeThemes(this.documentHelper.themes);
}
};
SfdtExport.prototype.writeFontSubsitutionTable = function (documentHelper) {
var fontSubstitutionTable = {};
for (var i = 0; i < documentHelper.fontSubstitutionTable.length; i++) {
var key = documentHelper.fontSubstitutionTable.keys[i];
fontSubstitutionTable[key] = this.documentHelper.fontSubstitutionTable.get(key);
}
return fontSubstitutionTable;
};
/**
* @private
*/
SfdtExport.prototype.writePage = function (page, spellChecker) {
this.skipExporting = spellChecker;
if (page.bodyWidgets.length > 0) {
var nextBlock = page.bodyWidgets[0];
do {
nextBlock = this.writeBodyWidget(nextBlock, 0);
} while (!isNullOrUndefined(nextBlock));
}
this.skipExporting = false;
return this.document;
};
SfdtExport.prototype.writeBodyWidget = function (bodyWidget, index) {
if (!(bodyWidget instanceof BodyWidget)) {
return undefined;
}
var section = this.createSection(bodyWidget);
this.document[sectionsProperty[this.keywordIndex]].push(section);
this.writeHeaderFooters(this.documentHelper.headersFooters[bodyWidget.index], section);
var firstBlock = bodyWidget.childWidgets[index];
if (isNullOrUndefined(firstBlock) && bodyWidget.nextRenderedWidget) {
firstBlock = bodyWidget.nextRenderedWidget.childWidgets[index];
}
do {
firstBlock = this.writeBlock(firstBlock, 0, section[blocksProperty[this.keywordIndex]]);
} while (firstBlock);
var next = bodyWidget;
do {
bodyWidget = next;
next = next.nextRenderedWidget;
if (isNullOrUndefined(next) && !isNullOrUndefined(bodyWidget.page.nextPage) && !isNullOrUndefined(bodyWidget.page.nextPage)) {
next = bodyWidget.page.nextPage.bodyWidgets[0];
}
} while (next instanceof BodyWidget && next.index === bodyWidget.index);
// While importing, If the last paragraph is empty and the section break is present, then the empty paragraph is removed. So, added the empty paragraph at the end of the section while exporting.
// let islastEmptyParagraph: boolean;
// if (!isNullOrUndefined(bodyWidget.lastChild) && bodyWidget.lastChild instanceof ParagraphWidget) {
// islastEmptyParagraph = (bodyWidget.lastChild as ParagraphWidget).isEmpty();
// if (bodyWidget.lastChild.isSectionBreak && !isNullOrUndefined(bodyWidget.lastChild.previousRenderedWidget) && bodyWidget.lastChild.previousRenderedWidget instanceof TableWidget) {
// islastEmptyParagraph = false;
// }
// }
// if (!isNullOrUndefined(next) && next instanceof BodyWidget && bodyWidget.sectionIndex !== next.sectionIndex && islastEmptyParagraph) {
// var paragraph = {};
// paragraph[inlinesProperty[this.keywordIndex]] = [];
// section[blocksProperty[this.keywordIndex]].push(paragraph);
// }
return next;
};
SfdtExport.prototype.writeHeaderFooters = function (hfs, section) {
if (isNullOrUndefined(hfs)) {
return;
}
var headersFooters = section[headersFootersProperty[this.keywordIndex]];
if (!(isNullOrUndefined(hfs[0]) || hfs[0].isEmpty)) {
headersFooters[headerProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[0]);
if (JSON.stringify(headersFooters[headerProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[headerProperty[this.keywordIndex]];
}
}
if (!(isNullOrUndefined(hfs[1]) || hfs[1].isEmpty)) {
headersFooters[footerProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[1]);
if (JSON.stringify(headersFooters[footerProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[footerProperty[this.keywordIndex]];
}
}
if (!(isNullOrUndefined(hfs[2]) || hfs[2].isEmpty)) {
headersFooters[evenHeaderProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[2]);
if (JSON.stringify(headersFooters[evenHeaderProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[evenHeaderProperty[this.keywordIndex]];
}
}
if (!(isNullOrUndefined(hfs[3]) || hfs[3].isEmpty)) {
headersFooters[evenFooterProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[3]);
if (JSON.stringify(headersFooters[evenFooterProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[evenFooterProperty[this.keywordIndex]];
}
}
if (!(isNullOrUndefined(hfs[4]) || hfs[4].isEmpty)) {
headersFooters[firstPageHeaderProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[4]);
if (JSON.stringify(headersFooters[firstPageHeaderProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[firstPageHeaderProperty[this.keywordIndex]];
}
}
if (!(isNullOrUndefined(hfs[5]) || hfs[5].isEmpty)) {
headersFooters[firstPageFooterProperty[this.keywordIndex]] = this.writeHeaderFooter(hfs[5]);
if (JSON.stringify(headersFooters[firstPageFooterProperty[this.keywordIndex]]) == "{}") {
delete headersFooters[firstPageFooterProperty[this.keywordIndex]];
}
}
};
SfdtExport.prototype.writeHeaderFooter = function (widget) {
if (isNullOrUndefined(widget) || widget.isEmpty) {
return undefined;
}
var headerFooter = {};
if (widget && widget.childWidgets && widget.childWidgets.length > 0) {
headerFooter[blocksProperty[this.keywordIndex]] = [];
var firstBlock = widget.firstChild;
do {
firstBlock = this.writeBlock(firstBlock, 0, headerFooter[blocksProperty[this.keywordIndex]]);
} while (firstBlock);
}
return headerFooter;
};
SfdtExport.prototype.createSection = function (bodyWidget) {
var section = {};
section[sectionFormatProperty[this.keywordIndex]] = {};
section[sectionFormatProperty[this.keywordIndex]] = this.writeSectionFormat(bodyWidget.sectionFormat, section[sectionFormatProperty[this.keywordIndex]], this.keywordIndex);
section[blocksProperty[this.keywordIndex]] = [];
section[headersFootersProperty[this.keywordIndex]] = {};
return section;
};
/**
* @private
*/
SfdtExport.prototype.writeSectionFormat = function (sectionFormat, section, keywordIndex) {
if (this.skipExporting) {
return section;
}
section[pageWidthProperty[keywordIndex]] = sectionFormat.pageWidth;
section[pageHeightProperty[keywordIndex]] = sectionFormat.pageHeight;
section[leftMarginProperty[keywordIndex]] = sectionFormat.leftMargin;
section[rightMarginProperty[keywordIndex]] = sectionFormat.rightMargin;
section[topMarginProperty[keywordIndex]] = sectionFormat.topMargin;
section[bottomMarginProperty[keywordIndex]] = sectionFormat.bottomMargin;
section[headerDistanceProperty[keywordIndex]] = sectionFormat.headerDistance;
section[footerDistanceProperty[keywordIndex]] = sectionFormat.footerDistance;
section[differentFirstPageProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.differentFirstPage, keywordIndex);
section[differentOddAndEvenPagesProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.differentOddAndEvenPages, keywordIndex);
section[bidiProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.bidi, keywordIndex);
if (!isNullOrUndefined(sectionFormat.breakCode)) {
section[breakCodeProperty[keywordIndex]] = sectionFormat.breakCode;
}
if (sectionFormat.restartPageNumbering) {
section[restartPageNumberingProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.restartPageNumbering, keywordIndex);
section[pageStartingNumberProperty[keywordIndex]] = sectionFormat.pageStartingNumber;
}
section[endnoteNumberFormatProperty[keywordIndex]] = keywordIndex == 1 ? this.getFootEndNoteNumberFormatEnumValue(sectionFormat.endnoteNumberFormat) : sectionFormat.endnoteNumberFormat;
section[footNoteNumberFormatProperty[keywordIndex]] = keywordIndex == 1 ? this.getFootEndNoteNumberFormatEnumValue(sectionFormat.footNoteNumberFormat) : sectionFormat.footNoteNumberFormat;
section[restartIndexForFootnotesProperty[keywordIndex]] = keywordIndex == 1 ? this.getFootnoteRestartIndexEnumValue(sectionFormat.restartIndexForFootnotes) : sectionFormat.restartIndexForFootnotes;
section[restartIndexForEndnotesProperty[keywordIndex]] = keywordIndex == 1 ? this.getFootnoteRestartIndexEnumValue(sectionFormat.restartIndexForEndnotes) : sectionFormat.restartIndexForEndnotes;
section[initialFootNoteNumberProperty[keywordIndex]] = sectionFormat.initialFootNoteNumber;
section[initialEndNoteNumberProperty[keywordIndex]] = sectionFormat.initialEndNoteNumber;
if (!isNullOrUndefined(sectionFormat.pageNumberStyle)) {
section[pageNumberStyleProperty[keywordIndex]] = sectionFormat.pageNumberStyle;
}
if (!isNullOrUndefined(sectionFormat.columns) && !isNullOrUndefined(sectionFormat.numberOfColumns && sectionFormat.numberOfColumns > 1)) {
var cols = sectionFormat.columns;
section[numberOfColumnsProperty[keywordIndex]] = sectionFormat.numberOfColumns;
section[equalWidthProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.equalWidth, keywordIndex);
section[lineBetweenColumnsProperty[keywordIndex]] = HelperMethods.getBoolInfo(sectionFormat.lineBetweenColumns, keywordIndex);
section[columnsProperty[keywordIndex]] = [];
for (var i = 0; i < cols.length; i++) {
var newCol = {};
newCol[widthProperty[keywordIndex]] = HelperMethods.convertPixelToPoint(cols[i].width);
newCol[spaceProperty[keywordIndex]] = HelperMethods.convertPixelToPoint(cols[i].space);
section[columnsProperty[keywordIndex]].push(newCol);
}
}
return section;
};
SfdtExport.prototype.writeBlock = function (widget, index, blocks) {
if (!(widget instanceof BlockWidget)) {
return undefined;
}
if (widget instanceof ParagraphWidget) {
if (widget.hasOwnProperty('contentControlProperties') && widget.contentControlProperties && widget.contentControlProperties.type !== 'BuildingBlockGallery') {
var block = this.blockContentControl(widget);
this.blockContent = false;
if (!isNullOrUndefined(block) && (this.isBlockClosed || !this.nestedBlockContent)) {
this.nestedBlockEnabled = false;
blocks.push(block);
this.blocks = [];
}
return this.nextBlock;
}
else {
var paragraph = this.createParagraph(widget);
blocks.push(paragraph);
return this.writeParagraph(widget, paragraph, blocks);
}
}
else {
var tableWidget = widget;
if (tableWidget.hasOwnProperty('contentControlProperties') && tableWidget.contentControlProperties && tableWidget.contentControlProperties.type !== 'BuildingBlockGallery') {
var block = this.tableContentControl(tableWidget);
if (!isNullOrUndefined(block) && this.isBlockClosed) {
blocks.push(block);
}
return this.nextBlock;
}
var table = this.createTable(tableWidget);
blocks.push(table);
return this.writeTable(tableWidget, table, 0, blocks);
}
};
SfdtExport.prototype.writeParagraphs = function (widget) {
var blocks = this.blocks;
var child = widget.childWidgets[0];
var firstElement = child.children[0];
var secondElement = child.children[1];
if (firstElement instanceof ListTextElementBox || secondElement instanceof ListTextElementBox) {
firstElement = child.children[2];
secondElement = child.children[3];
}
if (this.nestedBlockEnabled) {
blocks = [];
}
if ((firstElement instanceof ContentControl && secondElement instanceof ContentControl && !this.nestedBlockContent) || (this.blockContent && firstElement instanceof ContentControl && !this.nestedBlockContent)) {
var nestedBlocks = false;
if (secondElement instanceof ContentControl) {
if (secondElement.contentControlWidgetType === 'Block') {
nestedBlocks = true;
}
}
if ((nestedBlocks || (this.blockContent && firstElement instanceof ContentControl && !this.nestedBlockContent && firstElement.type === 0 && secondElement instanceof ContentControl && firstElement.contentControlWidgetType === 'Block'))) {
this.nestedBlockContent = true;
this.nestedBlockEnabled = true;
var block = this.blockContentControl(widget);
if (!isNullOrUndefined(block)) {
this.blocks.push(block);
}
}
else {
var paragraph = this.createParagraph(widget);
blocks.push(paragraph);
this.nextBlock = this.writeParagraph(widget, paragraph, blocks);
}
}
else {
var paragraph = this.createParagraph(widget);
blocks.push(paragraph);
this.nextBlock = this.writeParagraph(widget, paragraph, blocks);
}
if (!this.nestedBlockContent && this.nestedBlockEnabled) {
this.nestedBlockEnabled = false;
}
return blocks;
};
/**
* @private
*/
SfdtExport.prototype.contentControlProperty = function (contentControlPropertie, keywordIndex) {
if (isNullOrUndefined(keywordIndex)) {
keywordIndex = this.keywordIndex;
}
var contentControlProperties = {};
var contentControlListItems = [];
contentControlProperties[lockContentControlProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.lockContentControl, keywordIndex);
contentControlProperties[lockContentsProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.lockContents, keywordIndex);
contentControlProperties[tagProperty[keywordIndex]] = contentControlPropertie.tag;
contentControlProperties[colorProperty[keywordIndex]] = contentControlPropertie.color;
contentControlProperties[titleProperty[keywordIndex]] = contentControlPropertie.title;
if (!isNullOrUndefined(contentControlPropertie.appearance)) {
contentControlProperties[appearanceProperty[keywordIndex]] = keywordIndex == 1 ? this.getContentControlAppearanceEnumValue(contentControlPropertie.appearance) : contentControlPropertie.appearance;
}
contentControlProperties[typeProperty[keywordIndex]] = keywordIndex == 1 ? this.getContentControlTypeEnumValue(contentControlPropertie.type) : contentControlPropertie.type;
contentControlProperties[hasPlaceHolderTextProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.hasPlaceHolderText, keywordIndex);
contentControlProperties[multiLineProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.multiline, keywordIndex);
contentControlProperties[isTemporaryProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.isTemporary, keywordIndex);
if (!isNullOrUndefined(contentControlPropertie.isChecked)) {
contentControlProperties[isCheckedProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.isChecked, keywordIndex);
}
if (!isNullOrUndefined(contentControlPropertie.uncheckedState)) {
contentControlProperties[uncheckedStateProperty[keywordIndex]] = this.tounCheckedState(contentControlPropertie.uncheckedState);
}
if (!isNullOrUndefined(contentControlPropertie.checkedState)) {
contentControlProperties[checkedStateProperty[keywordIndex]] = this.toCheckedState(contentControlPropertie.checkedState);
}
if (!isNullOrUndefined(contentControlPropertie.dateCalendarType)) {
contentControlProperties[dateCalendarTypeProperty[keywordIndex]] = keywordIndex == 1 ? this.getDateCalendarTypeEnumValue(contentControlPropertie.dateCalendarType) : contentControlPropertie.dateCalendarType;
}
if (!isNullOrUndefined(contentControlPropertie.dateStorageFormat)) {
contentControlProperties[dateStorageFormatProperty[keywordIndex]] = keywordIndex == 1 ? this.getDateStorageFormatEnumValue(contentControlPropertie.dateStorageFormat) : contentControlPropertie.dateStorageFormat;
}
if (!isNullOrUndefined(contentControlPropertie.dateDisplayLocale)) {
contentControlProperties[dateDisplayLocaleProperty[keywordIndex]] = contentControlPropertie.dateDisplayLocale;
}
if (!isNullOrUndefined(contentControlPropertie.dateDisplayFormat)) {
contentControlProperties[dateDisplayFormatProperty[keywordIndex]] = contentControlPropertie.dateDisplayFormat;
}
if (!isNullOrUndefined(contentControlPropertie.xmlMapping)) {
var xmlMapping = {};
var customXmlPart = {};
xmlMapping[isMappedProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.xmlMapping.isMapped, keywordIndex);
xmlMapping[isWordMlProperty[keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.xmlMapping.isWordMl, keywordIndex);
if (!isNullOrUndefined(contentControlPropertie.xmlMapping.prefixMapping)) {
xmlMapping[prefixMappingProperty[keywordIndex]] = contentControlPropertie.xmlMapping.prefixMapping;
}
xmlMapping[xPathProperty[keywordIndex]] = contentControlPropertie.xmlMapping.xPath;
xmlMapping[storeItemIdProperty[keywordIndex]] = contentControlPropertie.xmlMapping.storeItemId;
if (!isNullOrUndefined(contentControlPropertie.xmlMapping.customXmlPart)) {
customXmlPart[idProperty[keywordIndex]] = contentControlPropertie.xmlMapping.customXmlPart.id;
customXmlPart[xmlProperty[keywordIndex]] = contentControlPropertie.xmlMapping.customXmlPart.xml;
xmlMapping[customXmlPartProperty[keywordIndex]] = customXmlPart;
}
contentControlProperties[xmlMappingProperty[keywordIndex]] = xmlMapping;
}
if (!isNullOrUndefined(contentControlPropertie.characterFormat)) {
contentControlProperties[characterFormatProperty[keywordIndex]] = this.writeCharacterFormat(contentControlPropertie.characterFormat, keywordIndex);
}
if (!isNullOrUndefined(contentControlPropertie.contentControlListItems)) {
for (var i = 0; i < contentControlPropertie.contentControlListItems.length; i++) {
var listItems = {};
listItems[displayTextProperty[keywordIndex]] = contentControlPropertie.contentControlListItems[i].displayText;
listItems[valueProperty[keywordIndex]] = contentControlPropertie.contentControlListItems[i].value;
contentControlListItems.push(listItems);
}
}
contentControlProperties[contentControlListItemsProperty[keywordIndex]] = contentControlListItems;
return contentControlProperties;
};
SfdtExport.prototype.tounCheckedState = function (state) {
var unCheckedState = {};
unCheckedState[fontProperty[this.keywordIndex]] = state.font;
unCheckedState[valueProperty[this.keywordIndex]] = state.value;
return unCheckedState;
};
SfdtExport.prototype.toCheckedState = function (state) {
var checkedState = {};
checkedState[fontProperty[this.keywordIndex]] = state.font;
checkedState[valueProperty[this.keywordIndex]] = state.value;
return checkedState;
};
SfdtExport.prototype.blockContentControl = function (widget) {
var block = {};
if (widget.childWidgets.length === 0) {
this.nextBlock = widget.nextWidget;
return undefined;
}
if (!this.isBlockClosed && this.nestedBlockContent && !isNullOrUndefined(widget.associatedCell) && !isNullOrUndefined(widget.associatedCell.ownerTable)
&& !isNullOrUndefined(widget.associatedCell.ownerTable.contentControlProperties)) {
this.nestedBlockEnabled = true;
}
block[blocksProperty[this.keywordIndex]] = this.writeParagraphs(widget);
if (!isNullOrUndefined(this.nextBlock)) {
if (widget.contentControlProperties === this.nextBlock.contentControlProperties) {
this.isBlockClosed = false;
this.nestedBlockContent = true;
return this.blocks = block[blocksProperty[this.k