@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
795 lines • 155 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 } 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, characterFormatProperty, paragraphFormatProperty, listsProperty, abstractListsProperty, stylesProperty, commentsProperty, revisionsProperty, customXmlProperty, defaultTabWidthProperty, formattingProperty, trackChangesProperty, protectionTypeProperty, enforcementProperty, hashValueProperty, saltValueProperty, doNotUseHTMLParagraphAutoSpacingProperty, formFieldShadingProperty, footnotesProperty, endnotesProperty, compatibilityModeProperty, themeFontLanguagesProperty, themesProperty, nameProperty, basedOnProperty, nextProperty, linkProperty, fontSizeProperty, fontColorProperty, styleNameProperty, bidiProperty, fontSizeBidiProperty, 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 } 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.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;
this.blocks = [];
this.contentInline = [];
this.isContentControl = false;
this.isBlockClosed = true;
this.isWriteInlinesFootNote = false;
/**
* @private
*/
this.keywordIndex = undefined;
/**
* @private
*/
this.isExport = true;
/**
* @private
*/
this.isWordExport = false;
/**
* @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.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;
editRangeStart[z].editRangeEnd.editRangeId = index;
}
}
}
};
/**
* @private
*/
/* eslint-disable */
SfdtExport.prototype.write = function (index, line, startOffset, endLine, endOffset, writeInlineStyles, isExport) {
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 paragraph = this.createParagraph(line.paragraph);
section[blocksProperty[this.keywordIndex]].push(paragraph);
var lastBlock = line.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) {
lastBlock = nextBlock;
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) {
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);
}
}
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.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.document = {};
this.document.optimizeSfdt = this.owner.documentEditorSettings.optimizeSfdt;
this.document[sectionsProperty[this.keywordIndex]] = [];
this.document[characterFormatProperty[this.keywordIndex]] = this.writeCharacterFormat(this.documentHelper.characterFormat);
this.document[paragraphFormatProperty[this.keywordIndex]] = this.writeParagraphFormat(this.documentHelper.paragraphFormat);
this.document[themeFontLanguagesProperty[this.keywordIndex]] = this.writeCharacterFormat(this.documentHelper.themeFontLanguage);
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);
}
};
/**
* @private
*/
SfdtExport.prototype.writePage = function (page) {
if (page.bodyWidgets.length > 0) {
var nextBlock = page.bodyWidgets[0];
do {
nextBlock = this.writeBodyWidget(nextBlock, 0);
} while (!isNullOrUndefined(nextBlock));
}
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.
var islastEmptyParagraph;
if (!isNullOrUndefined(bodyWidget.lastChild) && bodyWidget.lastChild instanceof ParagraphWidget) {
islastEmptyParagraph = bodyWidget.lastChild.isEmpty();
}
if (!isNullOrUndefined(next) && next instanceof BodyWidget && bodyWidget.sectionIndex !== next.sectionIndex && islastEmptyParagraph && !this.isWordExport) {
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) {
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')) {
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.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 (!isNullOrUndefined(widget.contentControlProperties)
&& widget.containerWidget instanceof TableCellWidget
&& !isNullOrUndefined(widget.containerWidget.containerWidget)
&& !isNullOrUndefined(widget.containerWidget.containerWidget.containerWidget.contentControlProperties)) {
blocks = [];
}
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;
};
SfdtExport.prototype.contentControlProperty = function (contentControlPropertie) {
var contentControlProperties = {};
var contentControlListItems = [];
contentControlProperties[lockContentControlProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.lockContentControl, this.keywordIndex);
contentControlProperties[lockContentsProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.lockContents, this.keywordIndex);
contentControlProperties[tagProperty[this.keywordIndex]] = contentControlPropertie.tag;
contentControlProperties[colorProperty[this.keywordIndex]] = contentControlPropertie.color;
contentControlProperties[titleProperty[this.keywordIndex]] = contentControlPropertie.title;
if (!isNullOrUndefined(contentControlPropertie.appearance)) {
contentControlProperties[appearanceProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getContentControlAppearanceEnumValue(contentControlPropertie.appearance) : contentControlPropertie.appearance;
}
contentControlProperties[typeProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getContentControlTypeEnumValue(contentControlPropertie.type) : contentControlPropertie.type;
contentControlProperties[hasPlaceHolderTextProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.hasPlaceHolderText, this.keywordIndex);
contentControlProperties[multiLineProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.multiline, this.keywordIndex);
contentControlProperties[isTemporaryProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.isTemporary, this.keywordIndex);
if (!isNullOrUndefined(contentControlPropertie.isChecked)) {
contentControlProperties[isCheckedProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.isChecked, this.keywordIndex);
}
if (!isNullOrUndefined(contentControlPropertie.uncheckedState)) {
contentControlProperties[uncheckedStateProperty[this.keywordIndex]] = this.tounCheckedState(contentControlPropertie.uncheckedState);
}
if (!isNullOrUndefined(contentControlPropertie.checkedState)) {
contentControlProperties[checkedStateProperty[this.keywordIndex]] = this.toCheckedState(contentControlPropertie.checkedState);
}
if (!isNullOrUndefined(contentControlPropertie.dateCalendarType)) {
contentControlProperties[dateCalendarTypeProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getDateCalendarTypeEnumValue(contentControlPropertie.dateCalendarType) : contentControlPropertie.dateCalendarType;
}
if (!isNullOrUndefined(contentControlPropertie.dateStorageFormat)) {
contentControlProperties[dateStorageFormatProperty[this.keywordIndex]] = this.keywordIndex == 1 ? this.getDateStorageFormatEnumValue(contentControlPropertie.dateStorageFormat) : contentControlPropertie.dateStorageFormat;
}
if (!isNullOrUndefined(contentControlPropertie.dateDisplayLocale)) {
contentControlProperties[dateDisplayLocaleProperty[this.keywordIndex]] = contentControlPropertie.dateDisplayLocale;
}
if (!isNullOrUndefined(contentControlPropertie.dateDisplayFormat)) {
contentControlProperties[dateDisplayFormatProperty[this.keywordIndex]] = contentControlPropertie.dateDisplayFormat;
}
if (!isNullOrUndefined(contentControlPropertie.xmlMapping)) {
var xmlMapping = {};
var customXmlPart = {};
xmlMapping[isMappedProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.xmlMapping.isMapped, this.keywordIndex);
xmlMapping[isWordMlProperty[this.keywordIndex]] = HelperMethods.getBoolInfo(contentControlPropertie.xmlMapping.isWordMl, this.keywordIndex);
if (!isNullOrUndefined(contentControlPropertie.xmlMapping.prefixMapping)) {
xmlMapping[prefixMappingProperty[this.keywordIndex]] = contentControlPropertie.xmlMapping.prefixMapping;
}
xmlMapping[xPathProperty[this.keywordIndex]] = contentControlPropertie.xmlMapping.xPath;
xmlMapping[storeItemIdProperty[this.keywordIndex]] = contentControlPropertie.xmlMapping.storeItemId;
if (!isNullOrUndefined(contentControlPropertie.xmlMapping.customXmlPart)) {
customXmlPart[idProperty[this.keywordIndex]] = contentControlPropertie.xmlMapping.customXmlPart.id;
customXmlPart[xmlProperty[this.keywordIndex]] = contentControlPropertie.xmlMapping.customXmlPart.xml;
xmlMapping[customXmlPartProperty[this.keywordIndex]] = customXmlPart;
}
contentControlProperties[xmlMappingProperty[this.keywordIndex]] = xmlMapping;
}
if (!isNullOrUndefined(contentControlPropertie.characterFormat)) {
contentControlProperties[characterFormatProperty[this.keywordIndex]] = this.writeCharacterFormat(contentControlPropertie.characterFormat);
}
if (!isNullOrUndefined(contentControlPropertie.contentControlListItems)) {
for (var i = 0; i < contentControlPropertie.contentControlListItems.length; i++) {
var listItems = {};
listItems[displayTextProperty[this.keywordIndex]] = contentControlPropertie.contentControlListItems[i].displayText;
listItems[valueProperty[this.keywordIndex]] = contentControlPropertie.contentControlListItems[i].value;
contentControlListItems.push(listItems);
}
}
contentControlProperties[contentControlListItemsProperty[this.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;
}
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.keywordIndex]];
}
else {
this.isBlockClosed = true;
}
}
else {
this.isBlockClosed = true;
}
if (!isNullOrUndefined(block[blocksProperty[this.keywordIndex]])) {
var child = widget.childWidgets[0];
var firstChild = child.children[0];
var secondChild = child.children[1];
if (firstChild instanceof ListTextElementBox || secondChild instanceof ListTextElementBox) {
firstChild = child.children[2];
secondChild = child.children[3];
}
if ((firstChild instanceof ContentControl && secondChild instanceof ContentControl && !this.nestedBlockContent) || (this.blockContent && firstChild instanceof ContentControl && !this.nestedBlockContent)) {
if (!(secondChild instanceof ContentControl)) {
block[contentControlPropertiesProperty[this.keywordIndex]] = this.contentControlProperty(firstChild.contentControlProperties);
return block;
}
else if (secondChild.contentControlWidgetType === 'Block') {
block[contentControlPropertiesProperty[this.keywordIndex]] = this.contentControlProperty(secondChild.contentControlProperties);
}
else {
block[contentControlPropertiesProperty[this.keywordIndex]] = this.contentControlProperty(widget.contentControlProperties);
}
}
else {
block[contentControlPropertiesProperty[this.keywordIndex]] = this.contentControlProperty(widget.contentControlProperties);
}
return block;
}
};
SfdtExport.prototype.tableContentControl = function (tableWidget) {
var block = {};
block[blocksProperty[this.keywordIndex]] = this.tableContentControls(tableWidget);
if (!isNullOrUndefined(this.nextBlock)) {
if (tableWidget.contentControlProperties === this.nextBlock.contentControlProperties) {
this.isBlockClosed = false;
return this.blocks = block[blocksProperty[this.keywordIndex]];
}
else {
this.isBlockClosed = true;
}
}
block[contentControlPropertiesProperty[this.keywordIndex]] = this.contentControlProperty(tableWidget.contentControlProperties);
return block;
};
SfdtExport.prototype.tableContentControls = function (tableWidget) {
var blocks = [];
if (!this.isBlockClosed) {
blocks = this.blocks;
}
var table = this.createTable(tableWidget);
blocks.push(table);
this.nextBlock = this.writeTable(tableWidget, table, 0, blocks);
return blocks;
};
SfdtExport.prototype.writeParagraph = function (paragraphWidget, paragraph, blocks, lineIndex, start) {
if (isNullOrUndefined(lineIndex)) {
lineIndex = 0;
}
if (isNullOrUndefined(start)) {
start = 0;
}
var next = paragraphWidget;
while (next instanceof ParagraphWidget) {
if (this.writeLines(next, lineIndex, start, paragraph[inlinesProperty[this.keywordIndex]])) {
return undefined;
}
lineIndex = 0;
start = 0;
paragraphWidget = next;
next = paragraphWidget.nextSplitWidget;
}
next = paragraphWidget.nextRenderedWidget;
if (this.documentHelper.owner.layoutType !== 'Continuous' && isNullOrUndefined(next) && paragraphWidget.containerWidget instanceof BodyWidget &&
!isNullOrUndefined(paragraphWidget.containerWidget.page.nextPage) &&
!isNullOrUndefined(paragraphWidget.containerWidget.page.nextPage.bodyWidgets)) {
next = paragraphWidget.containerWidget.page.nextPage.bodyWidgets[0].childWidgets[0];
}
if (this.isExport) {
return (next instanceof BlockWidget && paragraphWidget.containerWidget.index === next.containerWidget.index) ? next : undefined;
}
else {
return next;
}
};
SfdtExport.prototype.writeInlines = function (paragraph, line, inlines) {
this.contentInline = [];
var lineWidget = line;
var isformField = false;
for (var i = 0; i < lineWidget.children.length; i++) {
var element = lineWidget.children[i];
if (this.isExport && this.checkboxOrDropdown) {
if (isformField && element instanceof TextElementBox) {
continue;
}
if (element instanceof FieldElementBox && element.fieldType === 2) {
isformField = true;
}
}
if (element instanceof ListTextElementBox) {
continue;
}
if (element instanceof FootnoteElementBox) {
inlines.push(this.writeInlinesFootNote(paragraph, element, line, inlines));
continue;
}
if (element instanceof ContentControl || this.startContent || this.blockContent) {
this.writeInlinesContentControl(element, line, inlines, i);
}
else {
var inline = this.writeInline(element);
if (!isNullOrUndefined(inline)) {
inlines.push(inline);
}
}
if (this.isExport && element instanceof FieldElementBox && element.fieldType === 1) {
isformField = false;
this.checkboxOrDropdown = false;
}
}
};
SfdtExport.prototype.inlineContentControl = function (element, nextElement, inlines) {
var inline = {};
var nestedContentInline = [];
if (!isNullOrUndefined(inlines)) {
if (this.nestedContent) {
inlines = inlines[inlines.length - 1][inlinesProperty[this.keywordIndex]];
if (inlines[inlines.length - 1][inlinesProperty[this.keywordIndex]] == undefined) {
inlines[inlines.length - 1][inline