UNPKG

@syncfusion/ej2-documenteditor

Version:

Feature-rich document editor control with built-in support for context menu, options pane and dialogs.

741 lines (740 loc) 193 kB
/* eslint-disable */ import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { WList } from '../list/list'; import { WListLevel } from '../list/list-level'; import { WAbstractList } from '../list/abstract-list'; import { WLevelOverride } from '../list/level-override'; import { WCharacterFormat, WListFormat, WParagraphFormat, WCellFormat, WSectionFormat, WRowFormat, WColumnFormat } from '../format/index'; import { WCharacterStyle, WParagraphStyle, WTabStop } from '../format/index'; import { LineWidget, ParagraphWidget, ImageElementBox, BodyWidget, TextElementBox, TableCellWidget, TableRowWidget, TableWidget, FieldElementBox, HeaderFooterWidget, BookmarkElementBox, FieldTextElementBox, TabElementBox, EditRangeStartElementBox, EditRangeEndElementBox, ChartElementBox, ChartDataFormat, ChartCategory, ChartData, ChartSeries, ChartDataLabels, ChartTrendLines, ChartSeriesFormat, CommentCharacterElementBox, CommentElementBox, TextFormField, CheckBoxFormField, DropDownFormField, ShapeElementBox, LineFormat, TextFrame, ContentControlProperties, ContentControlListItems, ContentControl, CheckBoxState, XmlMapping, CustomXmlPart, Footnote, FootnoteElementBox, FillFormat, TablePosition, BreakElementBox } from './page'; import { HelperMethods } from '../editor/editor-helper'; import { Dictionary } from '../../base/dictionary'; import { ChartComponent } from '@syncfusion/ej2-office-chart'; import { Revision } from '../track-changes/track-changes'; import { FontSchemeStruct } from '../index'; import { sectionsProperty, imagesProperty, characterFormatProperty, paragraphFormatProperty, listsProperty, abstractListsProperty, backgroundProperty, stylesProperty, commentsProperty, revisionsProperty, customXmlProperty, defaultTabWidthProperty, formattingProperty, trackChangesProperty, protectionTypeProperty, enforcementProperty, hashValueProperty, saltValueProperty, doNotUseHTMLParagraphAutoSpacingProperty, alignTablesRowByRowProperty, formFieldShadingProperty, footnotesProperty, endnotesProperty, compatibilityModeProperty, themeFontLanguagesProperty, themesProperty, nameProperty, basedOnProperty, nextProperty, linkProperty, localeIdProperty, localeIdFarEastProperty, localeIdBidiProperty, boldProperty, italicProperty, underlineProperty, baselineAlignmentProperty, strikethroughProperty, highlightColorProperty, fontSizeProperty, fontColorProperty, fontFamilyProperty, styleNameProperty, bidiProperty, bdoProperty, fontSizeBidiProperty, fontFamilyBidiProperty, boldBidiProperty, italicBidiProperty, allCapsProperty, complexScriptProperty, fontFamilyAsciiProperty, fontFamilyFarEastProperty, fontFamilyNonFarEastProperty, revisionIdsProperty, listIdProperty, listLevelNumberProperty, leftIndentProperty, rightIndentProperty, firstLineIndentProperty, textAlignmentProperty, afterSpacingProperty, beforeSpacingProperty, spaceAfterAutoProperty, spaceBeforeAutoProperty, lineSpacingProperty, lineSpacingTypeProperty, listFormatProperty, keepWithNextProperty, widowControlProperty, keepLinesTogetherProperty, outlineLevelProperty, contextualSpacingProperty, 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, horizontalPositionAbsProperty, textureProperty, backgroundColorProperty, foregroundColorProperty, shadowProperty, hasNoneStyleProperty, verticalProperty, horizontalProperty, diagonalUpProperty, diagonalDownProperty, lineStyleProperty, lineWidthProperty, 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, isInlineImageProperty, 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, initialProperty, 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, isAfterParagraphMarkProperty, isAfterRowMarkProperty, isAfterCellMarkProperty, isAfterTableMarkProperty, belowTextProperty, breakClearTypeProperty, characterSpacingProperty, scalingProperty, nsidProperty } from '../../index'; /** * @private */ var SfdtReader = /** @class */ (function () { function SfdtReader(documentHelper) { /* eslint-disable @typescript-eslint/no-explicit-any */ this.documentHelper = undefined; /** * @private */ this.commentStarts = undefined; /** * @private */ this.commentEnds = undefined; /** * @private */ this.commentsCollection = undefined; /** * @private */ this.revisionCollection = undefined; this.isPageBreakInsideTable = false; this.referedRevisions = []; this.isParseHeader = false; this.footnotes = undefined; this.endnotes = undefined; this.keywordIndex = undefined; this.themes = undefined; /** * @private */ this.isCutPerformed = false; /** * @private */ this.isPaste = false; /** * @private */ this.isHtmlPaste = false; this.documentHelper = documentHelper; this.editableRanges = new Dictionary(); } Object.defineProperty(SfdtReader.prototype, "isPasting", { get: function () { return this.viewer && this.viewer.owner.isPastingContent; }, enumerable: true, configurable: true }); Object.defineProperty(SfdtReader.prototype, "viewer", { get: function () { return this.documentHelper.owner.viewer; }, enumerable: true, configurable: true }); SfdtReader.prototype.convertJsonToDocument = function (json) { this.commentStarts = new Dictionary(); this.commentEnds = new Dictionary(); this.commentsCollection = new Dictionary(); this.revisionCollection = new Dictionary(); this.referedRevisions = []; this.keywordIndex = 0; this.footnotes = new Footnote(); this.endnotes = new Footnote(); var sections = []; var jsonObject = HelperMethods.getSfdtDocument(json); if (!isNullOrUndefined(jsonObject.optimizeSfdt) && jsonObject.optimizeSfdt) { this.keywordIndex = 1; } if (isNullOrUndefined(jsonObject[characterFormatProperty[this.keywordIndex]])) { this.parseCharacterFormat(0, this.viewer.owner.characterFormat, this.documentHelper.characterFormat); } else { this.parseCharacterFormat(this.keywordIndex, jsonObject[characterFormatProperty[this.keywordIndex]], this.documentHelper.characterFormat); } if (isNullOrUndefined(jsonObject[paragraphFormatProperty[this.keywordIndex]])) { this.parseParagraphFormat(0, this.viewer.owner.paragraphFormat, this.documentHelper.paragraphFormat); } else { this.parseParagraphFormat(this.keywordIndex, jsonObject[paragraphFormatProperty[this.keywordIndex]], this.documentHelper.paragraphFormat); } if (!isNullOrUndefined(jsonObject[themeFontLanguagesProperty[this.keywordIndex]])) { this.parseCharacterFormat(this.keywordIndex, jsonObject[themeFontLanguagesProperty[this.keywordIndex]], this.documentHelper.themeFontLanguage); } this.parseDocumentProtection(jsonObject); if (!isNullOrUndefined(jsonObject[defaultTabWidthProperty[this.keywordIndex]])) { this.documentHelper.defaultTabWidth = jsonObject[defaultTabWidthProperty[this.keywordIndex]]; } if (!isNullOrUndefined(jsonObject[trackChangesProperty[this.keywordIndex]])) { this.documentHelper.owner.enableTrackChanges = HelperMethods.parseBoolValue(jsonObject[trackChangesProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[doNotUseHTMLParagraphAutoSpacingProperty[this.keywordIndex]])) { this.documentHelper.dontUseHtmlParagraphAutoSpacing = HelperMethods.parseBoolValue(jsonObject[doNotUseHTMLParagraphAutoSpacingProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[allowSpaceOfSameStyleInTableProperty[this.keywordIndex]])) { this.documentHelper.allowSpaceOfSameStyleInTable = HelperMethods.parseBoolValue(jsonObject[allowSpaceOfSameStyleInTableProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[alignTablesRowByRowProperty[this.keywordIndex]])) { this.documentHelper.alignTablesRowByRow = HelperMethods.parseBoolValue(jsonObject[alignTablesRowByRowProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[backgroundProperty[this.keywordIndex]])) { this.documentHelper.backgroundColor = this.getColor(jsonObject[backgroundProperty[this.keywordIndex]][colorProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[compatibilityModeProperty[this.keywordIndex]])) { this.documentHelper.compatibilityMode = this.getCompatibilityMode(jsonObject[compatibilityModeProperty[this.keywordIndex]]); if (!isNullOrUndefined(this.documentHelper.owner.documentSettings)) { this.documentHelper.owner.documentSettings.compatibilityMode = this.getCompatibilityMode(jsonObject[compatibilityModeProperty[this.keywordIndex]]); } } if (!isNullOrUndefined(jsonObject[abstractListsProperty[this.keywordIndex]])) { this.parseAbstractList(jsonObject, this.documentHelper.abstractLists); } if (!isNullOrUndefined(jsonObject[listsProperty[this.keywordIndex]])) { this.parseList(jsonObject, this.documentHelper.lists); } if (!isNullOrUndefined(jsonObject[stylesProperty[this.keywordIndex]])) { this.parseStyles(jsonObject, this.documentHelper.styles); } if (!isNullOrUndefined(jsonObject[commentsProperty[this.keywordIndex]])) { this.parseComments(jsonObject, this.documentHelper.comments); } if (!isNullOrUndefined(jsonObject[revisionsProperty[this.keywordIndex]])) { this.parseRevisions(jsonObject, this.viewer.owner.revisionsInternal.changes); } if (!isNullOrUndefined(jsonObject[imagesProperty[this.keywordIndex]])) { this.parseImages(jsonObject[imagesProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[sectionsProperty[this.keywordIndex]])) { this.parseSections(jsonObject[sectionsProperty[this.keywordIndex]], sections); } if (!isNullOrUndefined(jsonObject[customXmlProperty[this.keywordIndex]])) { this.parseCustomXml(jsonObject); } if (!isNullOrUndefined(jsonObject[formFieldShadingProperty[this.keywordIndex]])) { this.documentHelper.owner.documentEditorSettings.formFieldSettings.applyShading = HelperMethods.parseBoolValue(jsonObject[formFieldShadingProperty[this.keywordIndex]]); } if (!isNullOrUndefined(jsonObject[footnotesProperty[this.keywordIndex]])) { this.parseFootnotes(jsonObject[footnotesProperty[this.keywordIndex]], this.documentHelper.footnotes); } if (!isNullOrUndefined(jsonObject[endnotesProperty[this.keywordIndex]])) { this.parseEndtnotes(jsonObject[endnotesProperty[this.keywordIndex]], this.documentHelper.endnotes); } if (!isNullOrUndefined(jsonObject[themesProperty[this.keywordIndex]])) { this.parseThemes(jsonObject[themesProperty[this.keywordIndex]], this.documentHelper.themes); } this.generalizeRevisions(); this.removeUnmappedBookmark(); return sections; }; SfdtReader.prototype.removeUnmappedBookmark = function () { var bookmarkKeys = this.documentHelper.bookmarks.keys; var endBookmark = this.documentHelper.endBookmarksUpdated; for (var i = 0; i < bookmarkKeys.length; i++) { if (endBookmark.indexOf(bookmarkKeys[i]) === -1) { var bookmark = this.documentHelper.bookmarks.get(bookmarkKeys[i]); if (bookmark) { bookmark.line.children.splice(bookmark.line.children.indexOf(bookmark), 1); } this.documentHelper.bookmarks.remove(bookmarkKeys[i]); } } this.documentHelper.endBookmarksUpdated = []; }; SfdtReader.prototype.generalizeRevisions = function () { var _this = this; var tempRevisionCollection = new Dictionary(); var tempRevisons = []; this.referedRevisions.forEach(function (element) { var revision = _this.documentHelper.revisionsInternal.get(element); if (tempRevisons.indexOf(revision) === -1) { tempRevisons.push(revision); tempRevisionCollection.add(element, revision); } }); this.viewer.owner.revisionsInternal.changes = tempRevisons; this.documentHelper.revisionsInternal = tempRevisionCollection; }; SfdtReader.prototype.parseFootnotes = function (data, footnote) { if (!isNullOrUndefined(data[separatorProperty[this.keywordIndex]])) { this.parseBody(data[separatorProperty[this.keywordIndex]], footnote.separator); } if (!isNullOrUndefined(data[continuationNoticeProperty[this.keywordIndex]])) { this.parseBody(data[continuationNoticeProperty[this.keywordIndex]], footnote.continuationNotice); } if (!isNullOrUndefined(data[continuationSeparatorProperty[this.keywordIndex]])) { this.parseBody(data[continuationSeparatorProperty[this.keywordIndex]], footnote.continuationSeparator); } }; /** * @private */ SfdtReader.prototype.parseImages = function (data) { for (var img in data) { if (Array.isArray(data["" + img])) { this.documentHelper.images.add(parseInt(img), data["" + img]); } else { var images = []; images.push(data["" + img]); this.documentHelper.images.add(parseInt(img), images); } } }; SfdtReader.prototype.parseEndtnotes = function (data, endnote) { if (!isNullOrUndefined(data[separatorProperty[this.keywordIndex]])) { this.parseBody(data[separatorProperty[this.keywordIndex]], endnote.separator); } if (!isNullOrUndefined(data[continuationNoticeProperty[this.keywordIndex]])) { this.parseBody(data[continuationNoticeProperty[this.keywordIndex]], endnote.continuationNotice); } if (!isNullOrUndefined(data[continuationSeparatorProperty[this.keywordIndex]])) { this.parseBody(data[continuationSeparatorProperty[this.keywordIndex]], endnote.continuationSeparator); } }; SfdtReader.prototype.parseCustomXml = function (data) { for (var i = 0; i < data[customXmlProperty[this.keywordIndex]].length; i++) { var xmlData = data[customXmlProperty[this.keywordIndex]][i]; if (!this.revisionCollection.containsKey(xmlData[itemIDProperty[this.keywordIndex]])) { this.documentHelper.customXmlData.add(xmlData[itemIDProperty[this.keywordIndex]], xmlData[xmlProperty[this.keywordIndex]]); } } }; SfdtReader.prototype.parseDocumentProtection = function (data) { if (!isNullOrUndefined(data[formattingProperty[this.keywordIndex]])) { this.documentHelper.restrictFormatting = HelperMethods.parseBoolValue(data[formattingProperty[this.keywordIndex]]); } if (!isNullOrUndefined(data[enforcementProperty[this.keywordIndex]])) { this.documentHelper.isDocumentProtected = HelperMethods.parseBoolValue(data[enforcementProperty[this.keywordIndex]]); } if (!isNullOrUndefined(data[protectionTypeProperty[this.keywordIndex]])) { this.documentHelper.protectionType = this.getProtectionType(data[protectionTypeProperty[this.keywordIndex]]); } if (!isNullOrUndefined(data[hashValueProperty[this.keywordIndex]])) { this.documentHelper.hashValue = data[hashValueProperty[this.keywordIndex]]; } if (!isNullOrUndefined(data[saltValueProperty[this.keywordIndex]])) { this.documentHelper.saltValue = data[saltValueProperty[this.keywordIndex]]; } }; /** * @private */ SfdtReader.prototype.parseStyles = function (data, styles) { for (var i = 0; i < data[stylesProperty[this.keywordIndex]].length; i++) { var editor = this.documentHelper.owner.editor; if ((!isNullOrUndefined(editor) && editor.isRemoteAction) || isNullOrUndefined(this.documentHelper.styles.findByName(data[stylesProperty[this.keywordIndex]][i][nameProperty[this.keywordIndex]]))) { this.parseStyle(data, data[stylesProperty[this.keywordIndex]][i], styles); } } }; SfdtReader.prototype.parseRevisions = function (data, revisions) { for (var i = 0; i < data[revisionsProperty[this.keywordIndex]].length; i++) { var revisionData = data[revisionsProperty[this.keywordIndex]][i]; if (!isNullOrUndefined(revisionData[revisionIdProperty[this.keywordIndex]]) && !isNullOrUndefined(revisionData[revisionTypeProperty[this.keywordIndex]])) { var revision = this.parseRevision(revisionData); var revisionCheck = true; if (!this.documentHelper.owner.sfdtExportModule.copyWithTrackChange && this.isPaste) { if (this.getRevisionType(revisionData[revisionTypeProperty[this.keywordIndex]]) === 'Insertion' && this.isPaste && this.documentHelper.owner.enableTrackChanges) { var editor = this.documentHelper.owner.editor; if (!isNullOrUndefined(editor) && editor.isRemoteAction) { this.documentHelper.owner.editor.revisionData.push(this.documentHelper.owner.editor.getMarkerData(undefined, undefined, revision)); } continue; } else { if (!this.revisionCollection.containsKey(revisionData[revisionIdProperty[this.keywordIndex]])) { this.revisionCollection.add(revisionData[revisionIdProperty[this.keywordIndex]], revision); } } } else { this.revisionCollection.add(revisionData[revisionIdProperty[this.keywordIndex]], revision); } for (var j = 0; j < revisions.length; j++) { if (revisions[j].revisionID === revision.revisionID) { revisionCheck = false; } } if (revisionCheck) { revisions.push(revision); } } } this.documentHelper.revisionsInternal = this.revisionCollection; if (this.documentHelper.owner.sfdtExportModule) { this.documentHelper.owner.sfdtExportModule.copyWithTrackChange = false; } }; SfdtReader.prototype.parseRevision = function (data) { if (!isNullOrUndefined(data)) { var revision = new Revision(this.viewer.owner, data[authorProperty[this.keywordIndex]], data[dateProperty[this.keywordIndex]]); revision.revisionID = data[revisionIdProperty[this.keywordIndex]]; revision.revisionType = this.getRevisionType(data[revisionTypeProperty[this.keywordIndex]]); return revision; } else { return undefined; } }; SfdtReader.prototype.checkAndApplyRevision = function (keyIndex, inline, item) { if (!isNullOrUndefined(inline[revisionIdsProperty[keyIndex]]) && inline[revisionIdsProperty[keyIndex]].length > 0) { for (var i = 0; i < inline[revisionIdsProperty[keyIndex]].length; i++) { var id = inline[revisionIdsProperty[keyIndex]][i]; if (this.revisionCollection.containsKey(id)) { this.referedRevisions.push(id); var revision = this.revisionCollection.get(id); if (!(item instanceof WParagraphFormat)) { revision.range.push(item); } item.revisions.push(revision); } } } }; SfdtReader.prototype.parseComments = function (data, comments) { var count = 0; for (var i = 0; i < data[commentsProperty[this.keywordIndex]].length; i++) { var commentData = data[commentsProperty[this.keywordIndex]][i]; var commentElement = undefined; commentElement = this.parseComment(commentData, commentElement); while (count < commentData[replyCommentsProperty[this.keywordIndex]].length) { var replyComment = undefined; replyComment = this.parseComment(commentData[replyCommentsProperty[this.keywordIndex]][count], replyComment); replyComment.ownerComment = commentElement; replyComment.isReply = true; commentElement.replyComments.push(replyComment); this.commentsCollection.add(replyComment.commentId, replyComment); count++; } this.commentsCollection.add(commentElement.commentId, commentElement); comments.push(commentElement); count = 0; } }; SfdtReader.prototype.parseComment = function (commentData, commentElement) { commentElement = new CommentElementBox(commentData[dateProperty[this.keywordIndex]]); commentElement.author = commentData[authorProperty[this.keywordIndex]]; commentElement.initial = commentData[initialProperty[this.keywordIndex]]; commentElement.commentId = commentData[commentIdProperty[this.keywordIndex]]; commentElement.isResolved = HelperMethods.parseBoolValue(commentData[doneProperty[this.keywordIndex]]); commentElement.text = this.parseCommentText(commentData[blocksProperty[this.keywordIndex]]); return commentElement; }; SfdtReader.prototype.parseCommentText = function (blocks) { var text = ''; for (var i = 0; i < blocks.length; i++) { if (i !== 0) { text += '\n'; } for (var j = 0; j < blocks[i][inlinesProperty[this.keywordIndex]].length; j++) { text = text + blocks[i][inlinesProperty[this.keywordIndex]][j][textProperty[this.keywordIndex]]; } } return text; }; SfdtReader.prototype.parseStyle = function (data, style, styles, resetKeyIndex) { var wStyle; var keyIndex = 0; var editor = this.documentHelper.owner.editor; if (!isNullOrUndefined(resetKeyIndex) && resetKeyIndex) { keyIndex = this.keywordIndex; this.keywordIndex = 0; } if (!isNullOrUndefined(style[typeProperty[this.keywordIndex]])) { if (this.getStyleType(style[typeProperty[this.keywordIndex]]) === 'Paragraph') { wStyle = new WParagraphStyle(); wStyle.type = 'Paragraph'; } if (this.getStyleType(style[typeProperty[this.keywordIndex]]) === 'Character') { wStyle = new WCharacterStyle(); wStyle.type = 'Character'; } if (!isNullOrUndefined(style[nameProperty[this.keywordIndex]])) { wStyle.name = style[nameProperty[this.keywordIndex]]; } styles.push(wStyle); if (!isNullOrUndefined(style[basedOnProperty[this.keywordIndex]])) { var basedOn = void 0; if (!isNullOrUndefined(editor) && editor.isRemoteAction) { basedOn = this.documentHelper.styles.findByName(style[basedOnProperty[this.keywordIndex]]); } else { basedOn = styles.findByName(style[basedOnProperty[this.keywordIndex]]); } if (!isNullOrUndefined(basedOn)) { if (basedOn.type === wStyle.type && basedOn.name !== wStyle.name) { wStyle.basedOn = basedOn; } } else { var basedStyle = this.getStyle(style[basedOnProperty[this.keywordIndex]], data); var styleString = void 0; if (!isNullOrUndefined(basedStyle) && this.getStyleType(basedStyle[typeProperty[this.keywordIndex]]) === wStyle.type) { styleString = basedStyle; } else { if (wStyle.type === 'Paragraph') { styleString = JSON.parse('{"type":"Paragraph","name":"Normal","next":"Normal"}'); } else { styleString = JSON.parse('{"type": "Character","name": "Default Paragraph Font"}'); } } this.parseStyle(data, styleString, styles); if (!isNullOrUndefined(editor) && editor.isRemoteAction) { wStyle.basedOn = this.documentHelper.styles.findByName(styleString[nameProperty[this.keywordIndex]]); } else { wStyle.basedOn = styles.findByName(styleString[nameProperty[this.keywordIndex]]); } } } if (!isNullOrUndefined(style[linkProperty[this.keywordIndex]])) { var link = styles.findByName(style[linkProperty[this.keywordIndex]]); var linkStyle = this.getStyle(style[linkProperty[this.keywordIndex]], data); if (!isNullOrUndefined(editor) && editor.isRemoteAction) { link = this.documentHelper.styles.findByName(style[linkProperty[this.keywordIndex]]); } var styleString = void 0; if (isNullOrUndefined(link)) { if (isNullOrUndefined(linkStyle)) { //Construct the CharacterStyle string var charaStyle = {}; charaStyle.characterFormat = style[characterFormatProperty[this.keywordIndex]]; charaStyle.name = style[nameProperty[this.keywordIndex]] + ' Char'; charaStyle.type = 'Character'; //TODO: Implement basedOn charaStyle.basedOn = style[basedOnProperty[this.keywordIndex]] === 'Normal' ? 'Default Paragraph Font' : (style[basedOnProperty[this.keywordIndex]] + ' Char'); styleString = charaStyle; } else { styleString = linkStyle; } this.parseStyle(data, styleString, styles); if (!isNullOrUndefined(editor) && editor.isRemoteAction) { wStyle.link = isNullOrUndefined(this.documentHelper.styles.findByName(styleString.name)) ? style[linkProperty[this.keywordIndex]] : this.documentHelper.styles.findByName(styleString.name); } else { wStyle.link = isNullOrUndefined(styles.findByName(styleString.name)) ? style[linkProperty[this.keywordIndex]] : styles.findByName(styleString.name); } } else { wStyle.link = link; } } if (!isNullOrUndefined(style[characterFormatProperty[this.keywordIndex]])) { this.parseCharacterFormat(this.keywordIndex, style[characterFormatProperty[this.keywordIndex]], wStyle.characterFormat); } if (!isNullOrUndefined(style[paragraphFormatProperty[this.keywordIndex]])) { this.parseParagraphFormat(this.keywordIndex, style[paragraphFormatProperty[this.keywordIndex]], wStyle.paragraphFormat); } if (!isNullOrUndefined(style[nextProperty[this.keywordIndex]])) { if (style[nextProperty[this.keywordIndex]] === style[nameProperty[this.keywordIndex]]) { wStyle.next = wStyle; } else { var next = void 0; if (!isNullOrUndefined(editor) && editor.isRemoteAction) { next = this.documentHelper.styles.findByName(style[nextProperty[this.keywordIndex]]); } else { next = styles.findByName(style[nextProperty[this.keywordIndex]]); } if (!isNullOrUndefined(next) && next.type === wStyle.type) { wStyle.next = next; } else { var nextStyleString = this.getStyle(style[nextProperty[this.keywordIndex]], data); if (!isNullOrUndefined(nextStyleString)) { this.parseStyle(data, nextStyleString, styles); if (!isNullOrUndefined(editor) && editor.isRemoteAction) { wStyle.next = this.documentHelper.styles.findByName(nextStyleString.name); } else { wStyle.next = styles.findByName(nextStyleString.name); } } else { wStyle.next = wStyle; } } } } } if (!isNullOrUndefined(resetKeyIndex) && resetKeyIndex) { this.keywordIndex = keyIndex; } if (!isNullOrUndefined(wStyle)) { this.documentHelper.addToStylesMap(wStyle); } }; SfdtReader.prototype.getStyle = function (name, data) { for (var i = 0; i < data[stylesProperty[this.keywordIndex]].length; i++) { if (data[stylesProperty[this.keywordIndex]][i][nameProperty[this.keywordIndex]] === name) { return data[stylesProperty[this.keywordIndex]][i]; } } return undefined; }; SfdtReader.prototype.parseAbstractList = function (data, abstractLists) { for (var i = 0; i < data[abstractListsProperty[this.keywordIndex]].length; i++) { var abstractList = new WAbstractList(); var abstract = data[abstractListsProperty[this.keywordIndex]][i]; if (!isNullOrUndefined(abstract)) { if (!isNullOrUndefined(abstract[abstractListIdProperty[this.keywordIndex]])) { abstractList.abstractListId = abstract[abstractListIdProperty[this.keywordIndex]]; } if (!isNullOrUndefined(abstract[nsidProperty])) { abstractList.nsid = abstract[nsidProperty]; } else { // Backward compatibility abstractList.nsid = HelperMethods.generateUniqueId(undefined, abstractLists); } if (!isNullOrUndefined(abstract[levelsProperty[this.keywordIndex]])) { for (var j = 0; j < abstract[levelsProperty[this.keywordIndex]].length; j++) { var level = abstract[levelsProperty[this.keywordIndex]][j]; if (!isNullOrUndefined(level)) { var listLevel = this.parseListLevel(level, abstractList); abstractList.levels.push(listLevel); } } } } abstractLists.push(abstractList); } }; SfdtReader.prototype.parseListLevel = function (data, owner) { var listLevel = new WListLevel(owner); if (this.getListLevelPattern(data[listLevelPatternProperty[this.keywordIndex]]) === 'Bullet') { listLevel.listLevelPattern = 'Bullet'; listLevel.numberFormat = !isNullOrUndefined(data[numberFormatProperty[this.keywordIndex]]) ? data[numberFormatProperty[this.keywordIndex]] : ''; } else { listLevel.listLevelPattern = this.getListLevelPattern(data[listLevelPatternProperty[this.keywordIndex]]); listLevel.startAt = data[startAtProperty[this.keywordIndex]]; listLevel.numberFormat = !isNullOrUndefined(data[numberFormatProperty[this.keywordIndex]]) ? data[numberFormatProperty[this.keywordIndex]] : ''; if (data[restartLevelProperty[this.keywordIndex]] >= 0) { listLevel.restartLevel = data[restartLevelProperty[this.keywordIndex]]; } else { listLevel.restartLevel = data[levelNumberProperty[this.keywordIndex]]; } } listLevel.followCharacter = this.getFollowCharacterType(data[followCharacterProperty[this.keywordIndex]]); this.parseCharacterFormat(this.keywordIndex, data[characterFormatProperty[this.keywordIndex]], listLevel.characterFormat); this.parseParagraphFormat(this.keywordIndex, data[paragraphFormatProperty[this.keywordIndex]], listLevel.paragraphFormat); return listLevel; }; SfdtReader.prototype.parseList = function (data, listCollection) { for (var i = 0; i < data[listsProperty[this.keywordIndex]].length; i++) { var list = new WList(); var lists = data[listsProperty[this.keywordIndex]][i]; if (!isNullOrUndefined(lists[abstractListIdProperty[this.keywordIndex]])) { list.abstractListId = lists[abstractListIdProperty[this.keywordIndex]]; list.abstractList = this.documentHelper.getAbstractListById(lists[abstractListIdProperty[this.keywordIndex]]); } listCollection.push(list); if (!isNullOrUndefined(lists[listIdProperty[this.keywordIndex]])) { list.listId = lists[listIdProperty[this.keywordIndex]]; } if (!isNullOrUndefined(lists[nsidProperty])) { list.nsid = lists[nsidProperty]; } else { list.nsid = list.abstractList.nsid; } if (lists.hasOwnProperty(levelOverridesProperty[this.keywordIndex])) { this.parseLevelOverride(lists[levelOverridesProperty[this.keywordIndex]], list); } } }; SfdtReader.prototype.parseLevelOverride = function (data, list) { if (isNullOrUndefined(data)) { return; } for (var i = 0; i < data.length; i++) { var levelOverrides = new WLevelOverride(); var levelOverride = data[i]; levelOverrides.startAt = levelOverride[startAtProperty[this.keywordIndex]]; levelOverrides.levelNumber = levelOverride[levelNumberProperty[this.keywordIndex]]; if (!isNullOrUndefined(levelOverride[overrideListLevelProperty[this.keywordIndex]])) { levelOverrides.overrideListLevel = this.parseListLevel(levelOverride[overrideListLevelProperty[this.keywordIndex]], levelOverrides); } list.levelOverrides.push(levelOverrides); } }; SfdtReader.prototype.parseSections = function (data, sections) { for (var i = 0; i < data.length; i++) { var section = new BodyWidget(); section.sectionFormat = new WSectionFormat(section); section.index = i; var item = data[i]; if (!isNullOrUndefined(item[sectionFormatProperty[this.keywordIndex]])) { this.parseSectionFormat(this.keywordIndex, item[sectionFormatProperty[this.keywordIndex]], section.sectionFormat); } if (isNullOrUndefined(item[headersFootersProperty[this.keywordIndex]])) { item[headersFootersProperty[this.keywordIndex]] = {}; } this.documentHelper.headersFooters.push(this.parseHeaderFooter(item[headersFootersProperty[this.keywordIndex]], this.documentHelper.headersFooters)); this.isParseHeader = false; this.parseTextBody(item[blocksProperty[this.keywordIndex]], section, i + 1 < data.length); for (var i_1 = 0; i_1 < section.childWidgets.length; i_1++) { section.childWidgets[i_1].containerWidget = section; } sections.push(section); } }; SfdtReader.prototype.parseHeaderFooter = function (data, headersFooters) { this.isParseHeader = true; var hfs = {}; if (!isNullOrUndefined(data[headerProperty[this.keywordIndex]])) { var oddHeader = new HeaderFooterWidget('OddHeader'); hfs[0] = oddHeader; this.parseTextBody(data[headerProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], oddHeader); } if (!isNullOrUndefined(data[footerProperty[this.keywordIndex]])) { var oddFooter = new HeaderFooterWidget('OddFooter'); hfs[1] = oddFooter; this.parseTextBody(data[footerProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], oddFooter); } if (!isNullOrUndefined(data[evenHeaderProperty[this.keywordIndex]])) { var evenHeader = new HeaderFooterWidget('EvenHeader'); hfs[2] = evenHeader; this.parseTextBody(data[evenHeaderProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], evenHeader); } if (!isNullOrUndefined(data[evenFooterProperty[this.keywordIndex]])) { var evenFooter = new HeaderFooterWidget('EvenFooter'); hfs[3] = evenFooter; this.parseTextBody(data[evenFooterProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], evenFooter); } if (!isNullOrUndefined(data[firstPageHeaderProperty[this.keywordIndex]])) { var firstPageHeader = new HeaderFooterWidget('FirstPageHeader'); hfs[4] = firstPageHeader; this.parseTextBody(data[firstPageHeaderProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], firstPageHeader); } if (!isNullOrUndefined(data[firstPageFooterProperty[this.keywordIndex]])) { var firstPageFooter = new HeaderFooterWidget('FirstPageFooter'); hfs[5] = firstPageFooter; this.parseTextBody(data[firstPageFooterProperty[this.keywordIndex]][blocksProperty[this.keywordIndex]], firstPageFooter); } return hfs; }; SfdtReader.prototype.parseTextBody = function (data, section, isSectionBreak) { this.parseBody(data, section.childWidgets, section, isSectionBreak); }; SfdtReader.prototype.addCustomStyles = function (data) { if (!isNullOrUndefined(data[stylesProperty[this.keywordIndex]])) { for (var i = 0; i < data[stylesProperty[this.keywordIndex]].length; i++) { var style = this.documentHelper.styles.findByName(data[stylesProperty[this.keywordIndex]][i][nameProperty[this.keywordIndex]]); if (style === undefined) { this.parseStyle(data, data[stylesProperty[this.keywordIndex]][i], this.documentHelper.styles); } } } }; SfdtReader.prototype.parseBody = function (data, blocks, container, isSectionBreak, contentControlProperties, styles) { if (!isNullOrUndefined(data)) { for (var i = 0; i < data.length; i++) { var block = data[i]; var hasValidElmts = false; if (block.hasOwnProperty(inlinesProperty[this.keywordIndex])) { var writeInlineFormat = false; //writeInlineFormat = this.isPasting && i === data.length - 1; var paragraph = new ParagraphWidget(); paragraph.characterFormat = new WCharacterFormat(paragraph); paragraph.paragraphFormat = new WParagraphFormat(paragraph); if (block[inlinesProperty[this.keywordIndex]].length > 0) { hasValidElmts = this.parseParagraph(block[inlinesProperty[this.keywordIndex]], paragraph, writeInlineFormat); } if (!(isSectionBreak && block === data[data.length - 1] && block[inlinesProperty[this.keywordIndex]].length === 0 && !hasValidElmts)) { this.parseCharacterFormat(this.keywordIndex, block[characterFormatProperty[this.keywordIndex]], paragraph.characterFormat); this.parseParagraphFormat(this.keywordIndex, block[paragraphFormatProperty[this.keywordIndex]], paragraph.paragraphFormat); var styleObj = void 0; var styleName = 'Normal'; if (!isNullOrUndefined(block[paragraphFormatProperty[this.keywordIndex]]) && !isNullOrUndefined(block[paragraphFormatProperty[this.keywordIndex]][styleNameProperty[this.keywordIndex]])) { //Default value to link style object. styleName = block[paragraphFormatProperty[this.keywordIndex]][styleNameProperty[this.keywordIndex]]; } styleObj = this.documentHelper.styles.findByName(styleName, 'Paragraph'); if (!isNullOrUndefined(styleObj)) { if (this.isPaste && styles) { for (var j = 0; j < styles.length; j++) { if (styles[j][nameProperty[this.keywordIndex]] === styleName) { var fontColor = styles[j][characterFormatProperty[this.keywordIndex]]; if (fontColor[fontColorProperty[this.keywordIndex]] !== styleObj.characterFormat.fontColor) { var charFormat = new WCharacterFormat(); this.parseCharacterFormat(this.keywordIndex, styles[j][characterFormatProperty[this.keywordIndex]], charFormat); styleObj.characterFormat.copyFormat(charFormat); break; } } } } paragraph.paragraphFormat.applyStyle(styleObj); } blocks.push(paragraph); } else if (isSectionBreak && data.length === 1) { blocks.push(paragraph); } paragraph.index = blocks.length - 1; paragraph.containerWidget = container; } else if (block.hasOwnProperty(rowsProperty[this.keywordIndex])) { this.parseTable(block, blocks, blocks.length, container); } else if (block.hasOwnProperty(contentControlPropertiesProperty[this.keywordIndex])) { var blockStartContentControl = new ContentControl('Block'); var blockEndContentControl = new ContentControl('Block'); this.parseContentControlProperties(block[contentControlPropertiesProperty[this.keywordIndex]], blockStartContentControl.contentControlProperties); blockEndContentControl.contentControlProperties = blockStartContentControl.contentControlProperties; blockStartContentControl.type = 0; blockEndContentControl.type = 1; this.parseBody(block[blocksProperty[this.keywordIndex]], blocks, container, isSectionBreak, blockStartContentControl.contentControlProperties); for (var j = 0; j < 2; j++) { var para = (blocks.length < block[blocksProperty[this.keywordIndex]].length) ? blocks[0] : j === 0 ? blocks[blocks.length - block[blocksProperty[this.keywordIndex]].length] : blocks[blocks.length - 1]; var blockWidget = void 0; if (para instanceof ParagraphWidget) { blockWidget = para; }