UNPKG

@syncfusion/ej2-documenteditor

Version:

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

713 lines 233 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, WTableStyle } 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, ElementBox, CommentCharacterElementBox, CommentElementBox, TextFormField, CheckBoxFormField, DropDownFormField, ShapeElementBox, LineFormat, TextFrame, ContentControlProperties, ContentControlListItems, ContentControl, CheckBoxState, XmlMapping, CustomXmlPart, Footnote, FootnoteElementBox, FillFormat, TablePosition, BreakElementBox, FootnoteEndnoteMarkerElementBox } 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, hiddenProperty, imagesProperty, paraStyleNameProperty, fontSubstitutionTableProperty, characterFormatProperty, paragraphFormatProperty, listsProperty, abstractListsProperty, backgroundProperty, stylesProperty, commentsProperty, revisionsProperty, customXmlProperty, defaultTabWidthProperty, formattingProperty, trackChangesProperty, protectionTypeProperty, enforcementProperty, hashValueProperty, saltValueProperty, doNotUseHTMLParagraphAutoSpacingProperty, alignTablesRowByRowProperty, formFieldShadingProperty, lastParagraphMarkCopiedProperty, footnotesProperty, endnotesProperty, compatibilityModeProperty, themeFontLanguagesProperty, themesProperty, nameProperty, basedOnProperty, nextProperty, linkProperty, localeIdProperty, localeIdFarEastProperty, localeIdBidiProperty, boldProperty, italicProperty, underlineProperty, fontHintTypeProperty, 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, incrementalOps, isLegalStyleNumberingProperty, horizontalRuleProperty, isAutoMajorProperty, underlineColorProperty, editingPointsProperty } 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.isContextBasedPaste = false; /** * @private */ this.isHtmlPaste = false; this.previousItemForRevision = undefined; 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, incrementalOperations) { this.commentStarts = new Dictionary(); this.commentEnds = new Dictionary(); this.commentsCollection = new Dictionary(); this.revisionCollection = new Dictionary(); this.fontInfoCollection = 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[fontSubstitutionTableProperty[this.keywordIndex]])) { this.parseFontSubstitutionTable(jsonObject[fontSubstitutionTableProperty[this.keywordIndex]]); } if (isNullOrUndefined(jsonObject[characterFormatProperty[this.keywordIndex]])) { this.parseCharacterFormat(0, this.viewer.owner.characterFormat, this.documentHelper.characterFormat); } else { this.documentHelper.characterFormat.clearFormat(); 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]])) { //when new document is open in collaborative editing, again building operation for enable track changes. So skipping it. if (this.documentHelper.owner.enableTrackChanges !== HelperMethods.parseBoolValue(jsonObject[trackChangesProperty[this.keywordIndex]])) { this.documentHelper.owner.skipSettingsOps = true; } 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(); if (!isNullOrUndefined(jsonObject[incrementalOps[0]])) { incrementalOperations[incrementalOps[0]] = (jsonObject[incrementalOps[0]]); } if (this.documentHelper.fieldStacks && this.documentHelper.fieldStacks.length > 0) { this.documentHelper.fieldStacks = []; } return sections; }; SfdtReader.prototype.parseFontSubstitutionTable = function (fontSubstitutionTable) { if (!isNullOrUndefined(this.documentHelper) && !isNullOrUndefined(this.documentHelper.fontSubstitutionTable)) { if (Object.keys(fontSubstitutionTable).length > 0) { var keys = Object.keys(fontSubstitutionTable); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; this.documentHelper.fontSubstitutionTable.add(key, fontSubstitutionTable[key]); } } } }; 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); } }; /** * @private */ 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.documentHelper.customXmlData.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.editorModule; 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 && !this.documentHelper.owner.editorModule.isRemoteAction) { // 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 && !this.documentHelper.owner.editorModule.isRemoteAction) { 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)) { var revision = this.revisionCollection.get(id); var itemRevision = this.documentHelper.owner.editorModule.retrieveRevisionByType(item, revision.revisionType); // If different revisions are applied in same line we need to split the revision var canInsertNewRevision = false; if (item instanceof ElementBox && !isNullOrUndefined(item.previousElement)) { if (item.previousElement instanceof TextElementBox && item.previousElement.revisions.length === 0) { canInsertNewRevision = true; } for (var i_1 = 0; i_1 < item.previousElement.revisions.length; i_1++) { var itemRevision = item.previousElement.revisions[i_1]; if (itemRevision.revisionType !== revision.revisionType || itemRevision.author !== revision.author) { canInsertNewRevision = true; } else { canInsertNewRevision = false; break; } } } // If previous item's revision & current item's revision type is matched, it will return the revision. var previousRevision = !isNullOrUndefined(this.previousItemForRevision) ? this.documentHelper.owner.editorModule.retrieveRevisionByType(this.previousItemForRevision, revision.revisionType) : undefined; // If the revision is already inserted & current revision differs from previous revision or if both types are same but the user is different we need to create new revision if (this.referedRevisions.indexOf(revision.revisionID) > -1 && (isNullOrUndefined(previousRevision) || (!isNullOrUndefined(previousRevision) && previousRevision.author !== revision.author) || canInsertNewRevision)) { //Create new revision id for next paragraph var revisionId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); //Clone the revision var clonedRevision = revision.cloneRevision(); clonedRevision.revisionID = revisionId; var currentRevisionIndex = this.revisionCollection.values.indexOf(revision); this.revisionCollection.keys.splice(currentRevisionIndex + 1, 0, revisionId); this.revisionCollection.values.splice(currentRevisionIndex + 1, 0, clonedRevision); revision = clonedRevision; id = revisionId; } //else If the revision already inserted & new revision is created for the previousItem & the current item map's with older revision which is already added, we need to set current revision as previousItem's revision. else if (this.referedRevisions.indexOf(revision.revisionID) > -1 && !isNullOrUndefined(previousRevision) && previousRevision !== revision && !(item instanceof ShapeElementBox)) { revision = this.revisionCollection.get(previousRevision.revisionID); } this.referedRevisions.push(id); if (!(item instanceof WParagraphFormat)) { revision.range.push(item); } item.revisions.push(revision); if (this.isPaste && this.documentHelper.owner.editorModule.isRemoteAction && item instanceof WRowFormat) { this.documentHelper.owner.editorModule.remotePasteRevision.push(revision); } } } this.previousItemForRevision = item; } }; 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]]); commentElement.mentions = this.parseCommentMentions(commentData[blocksProperty[this.keywordIndex]]); commentElement.isPosted = true; return commentElement; }; SfdtReader.prototype.parseCommentText = function (blocks) { var text = ''; var isFieldDisplayText = false; for (var i = 0; i < blocks.length; i++) { if (i !== 0) { text += '<div>'; } if (blocks[i][inlinesProperty[this.keywordIndex]].length > 0) { var inlines = blocks[i][inlinesProperty[this.keywordIndex]]; for (var j = 0; j < inlines.length; j++) { var inline = inlines[j]; if ((inline[fieldTypeProperty[this.keywordIndex]] === 0) || (inline[fieldTypeProperty[this.keywordIndex]] === 1) || (inline[fieldTypeProperty[this.keywordIndex]] === 2)) { if (inline[fieldTypeProperty[this.keywordIndex]] === 0) { j++; } else if (inline[fieldTypeProperty[this.keywordIndex]] === 2) { isFieldDisplayText = true; } continue; } var textValue = inline[textProperty[this.keywordIndex]]; if (isFieldDisplayText) { text = text + '<span contenteditable="false" class="e-mention-chip">' + textValue + '</span>'; isFieldDisplayText = false; } else if (textValue) { text = text + textValue.replace(/</g, "&lt;").replace(/>/g, "&gt;"); } } } else { text += i === 0 ? '<div><br></div>' : '<br>'; } if (i !== 0) { text += '</div>'; } } return text; }; SfdtReader.prototype.parseCommentMentions = function (blocks) { var data = []; var isFieldCode = false; var isFieldDisplayText = false; for (var i = 0; i < blocks.length; i++) { var inlines = blocks[i][inlinesProperty[this.keywordIndex]]; var mention = {}; for (var j = 0; j < inlines.length; j++) { var inline = inlines[j]; if ((inline[fieldTypeProperty[this.keywordIndex]] === 0) || (inline[fieldTypeProperty[this.keywordIndex]] === 1) || (inline[fieldTypeProperty[this.keywordIndex]] === 2)) { if (inline[fieldTypeProperty[this.keywordIndex]] === 0) { isFieldCode = true; } else if (inline[fieldTypeProperty[this.keywordIndex]] === 2) { isFieldDisplayText = true; } continue; } var textValue = inline[textProperty[this.keywordIndex]]; if (isFieldCode) { var updatedText = textValue.replace(/.*"(.*)".*/, '$1'); updatedText = updatedText.replace('mailto:', ''); mention.value = updatedText; isFieldCode = false; } else if (isFieldDisplayText) { mention.text = textValue; isFieldDisplayText = false; data.push(mention); mention = {}; } } } return data; }; SfdtReader.prototype.parseStyle = function (data, style, styles, resetKeyIndex) { var wStyle; var keyIndex = 0; var editor = this.documentHelper.owner.editorModule; 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 (this.getStyleType(style[typeProperty[this.keywordIndex]]) === 'Table') { wStyle = new WTableStyle(); wStyle.type = 'Table'; } 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; var baseStyle = this.getStyle(style[basedOnProperty[this.keywordIndex]], data); if (this.isPaste && !isNullOrUndefined(baseStyle)) { if (wStyle.type === 'Paragraph' && this.getStyleType(baseStyle[typeProperty[this.keywordIndex]]) === 'Paragraph') { this.updateParagraphFormatFromBaseStyle(style, baseStyle); } } } } 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 if (wStyle.type === 'Character') { 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[characterFormatProperty[this.keywordIndex]] = style[characterFormatProperty[this.keywordIndex]]; charaStyle[nameProperty[this.keywordIndex]] = style[nameProperty[this.keywordIndex]] + ' Char'; charaStyle[typeProperty[this.keywordIndex]] = 'Character'; //TODO: Implement basedOn charaStyle[basedOnProperty[this.keywordIndex]] = style[basedOnProperty[this.keywordIndex]] === 'Normal' ? 'Default Paragraph Font' : (style[basedOnProperty[this.keywordIndex]] + ' Char'); styleString = charaStyle; } else { styleString = linkStyle; } this.parseStyle(data, styleString, styles); var linkedStyle = void 0; if (!isNullOrUndefined(editor) && editor.isRemoteAction) { linkedStyle = this.documentHelper.styles.findByName(styleString[nameProperty[this.keywordIndex]]); wStyle.link = isNullOrUndefined(linkedStyle) ? style[linkProperty[this.keywordIndex]] : linkedStyle; } else { linkedStyle = styles.findByName(styleString[nameProperty[this.keywordIndex]]); wStyle.link = isNullOrUndefined(linkedStyle) ? style[linkProperty[this.keywordIndex]] : linkedStyle; } } 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) && wStyle.type !== 'Table') { this.documentHelper.addToStylesMap(wStyle); } }; SfdtReader.prototype.updateParagraphFormatFromBaseStyle = function (style, baseStyle) { if (!isNullOrUndefined(style[paragraphFormatProperty[this.keywordIndex]]) && !isNullOrUndefined(baseStyle[paragraphFormatProperty[this.keywordIndex]])) { var paragraphFormat = style[paragraphFormatProperty[this.keywordIndex]]; var baseParagraphFormat = baseStyle[paragraphFormatProperty[this.keywordIndex]]; if (!paragraphFormat.hasOwnProperty(leftIndentProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(leftIndentProperty[this.keywordIndex])) { paragraphFormat[leftIndentProperty[this.keywordIndex]] = baseParagraphFormat[leftIndentProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(rightIndentProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(rightIndentProperty[this.keywordIndex])) { paragraphFormat[rightIndentProperty[this.keywordIndex]] = baseParagraphFormat[rightIndentProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(beforeSpacingProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(beforeSpacingProperty[this.keywordIndex])) { paragraphFormat[beforeSpacingProperty[this.keywordIndex]] = baseParagraphFormat[beforeSpacingProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(afterSpacingProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(afterSpacingProperty[this.keywordIndex])) { paragraphFormat[afterSpacingProperty[this.keywordIndex]] = baseParagraphFormat[afterSpacingProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(lineSpacingProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(lineSpacingProperty[this.keywordIndex])) { paragraphFormat[lineSpacingProperty[this.keywordIndex]] = baseParagraphFormat[lineSpacingProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(lineSpacingTypeProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(lineSpacingTypeProperty[this.keywordIndex])) { paragraphFormat[lineSpacingTypeProperty[this.keywordIndex]] = baseParagraphFormat[lineSpacingTypeProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(textAlignmentProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(textAlignmentProperty[this.keywordIndex])) { paragraphFormat[textAlignmentProperty[this.keywordIndex]] = baseParagraphFormat[textAlignmentProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(outlineLevelProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(outlineLevelProperty[this.keywordIndex])) { paragraphFormat[outlineLevelProperty[this.keywordIndex]] = baseParagraphFormat[outlineLevelProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(contextualSpacingProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(contextualSpacingProperty[this.keywordIndex])) { paragraphFormat[contextualSpacingProperty[this.keywordIndex]] = baseParagraphFormat[contextualSpacingProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(keepWithNextProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(keepWithNextProperty[this.keywordIndex])) { paragraphFormat[keepWithNextProperty[this.keywordIndex]] = baseParagraphFormat[keepWithNextProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(keepLinesTogetherProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(keepLinesTogetherProperty[this.keywordIndex])) { paragraphFormat[keepLinesTogetherProperty[this.keywordIndex]] = baseParagraphFormat[keepLinesTogetherProperty[this.keywordIndex]]; } if (!paragraphFormat.hasOwnProperty(widowControlProperty[this.keywordIndex]) && baseParagraphFormat.hasOwnProperty(widowControlProperty[this.keywordIndex])) { paragraphFormat[widowControlProperty[this.keywordIndex]] = baseParagraphFormat[widowControlProperty[this.keywordIndex]]; }