UNPKG

@syncfusion/ej2-documenteditor

Version:

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

806 lines 108 kB
/* eslint-disable */ import { HelperMethods, ParagraphWidget, TableWidget, CONTROL_CHARACTERS, SectionBreakType, ListTextElementBox, ShapeElementBox, FootnoteElementBox, CommentElementBox, CommentCharacterElementBox, FieldElementBox, WCharacterFormat, ImageElementBox, WParagraphFormat, WTableFormat, WRowFormat, WCellFormat, WSectionFormat, listIdProperty, abstractListsProperty, listsProperty, abstractListIdProperty, nsidProperty, ContentControlProperties, ContentControl } from '../../index'; import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { createElement } from '@syncfusion/ej2-base'; /** * Module to handle collaborative editing. */ var CollaborativeEditingHandler = /** @class */ (function () { function CollaborativeEditingHandler(documentEditor) { //TODO need to prevent document change on collaborative editing session i.e. New document, select new document //#region SignalR collabrative editing this.version = 0; this.userMap = {}; this.connectionId = ''; this.pendingOps = []; this.commentsStart = []; this.commentsEnd = []; this.deletedComments = []; this.serviceUrl = ''; this.isSyncServerChanges = false; this.logEventEnabled = true; this.message = ''; this.documentEditor = documentEditor; } ; /** * Get module name. * @returns - Returns the module name */ CollaborativeEditingHandler.prototype.getModuleName = function () { return 'CollaborativeEditingHandler'; }; /** * This function updates the room information and server url of the collaborative editing session. * @param roomName - Specifies the current collaborative editing room name. * @param version - Specifies the current version of the document. * @param serviceUrl - Specifies the base url of the collaborative editing service. */ CollaborativeEditingHandler.prototype.updateRoomInfo = function (roomName, version, serviceUrl) { this.roomName = roomName; this.serviceUrl = serviceUrl; this.version = version; }; /** * Send the current action to the server. * @param args - Specified the current action. * @returns */ CollaborativeEditingHandler.prototype.sendActionToServer = function (operations) { if (!isNullOrUndefined(operations) && operations.length === 0) { return; } var lastPendingOp = this.pendingOps[this.pendingOps.length - 1]; if (!lastPendingOp || !this.checkAndCombineOperation(lastPendingOp, operations)) { this.pendingOps.push(operations); } if (!this.isAcknowledgePending()) { this.sendLocalOperation(); } this.transformRemoteCursor(this.connectionId, operations[0], operations[0].offset); }; CollaborativeEditingHandler.prototype.checkAndCombineOperation = function (lastAction, currentAction) { if (lastAction.length !== 1 || currentAction.length !== 1) { return false; } var lastOperation = lastAction[0]; var currentOperation = currentAction[0]; if (this.isSameOperation(lastOperation, currentOperation) && this.canCombineOperation(lastOperation, currentOperation)) { if ((lastOperation.action === 'Insert' && lastOperation.offset + lastOperation.length === currentOperation.offset) || (lastOperation.action === 'Delete' && (lastOperation.offset === currentOperation.offset))) { lastOperation.length += currentOperation.length; lastOperation.text += currentOperation.text; return true; } else if (lastOperation.action === 'Delete' && currentOperation.offset + currentOperation.length === lastOperation.offset) { lastOperation.text = currentOperation.text + lastOperation.text; lastOperation.offset = currentOperation.offset; lastOperation.length += currentOperation.length; return true; } } return false; }; CollaborativeEditingHandler.prototype.canCombineOperation = function (lastOperation, currentOperation) { return lastOperation.format === currentOperation.format && !this.isControlCharacter(lastOperation.text) && !this.isControlCharacter(currentOperation.text) && isNullOrUndefined(lastOperation.markerData) && isNullOrUndefined(currentOperation.markerData); }; CollaborativeEditingHandler.prototype.isSameOperation = function (lastOperation, currentOperation) { return lastOperation.action === currentOperation.action; }; CollaborativeEditingHandler.prototype.isControlCharacter = function (text) { var controlCharacters = [ CONTROL_CHARACTERS.Table, CONTROL_CHARACTERS.Row, CONTROL_CHARACTERS.Cell, CONTROL_CHARACTERS.Image, CONTROL_CHARACTERS.PageBreak, CONTROL_CHARACTERS.ColumnBreak, CONTROL_CHARACTERS.Section_Break, CONTROL_CHARACTERS.Table, CONTROL_CHARACTERS.Field_Separator, CONTROL_CHARACTERS.Marker_Start, CONTROL_CHARACTERS.Marker_End, CONTROL_CHARACTERS.Tab, CONTROL_CHARACTERS.LineBreak ]; return controlCharacters.indexOf(text) !== -1; }; /** * Apply the remote operation to the current document. * @param action - Specifies the remote action type. * @param data - Specifies the remote operation data. */ CollaborativeEditingHandler.prototype.applyRemoteAction = function (action, data) { switch (action) { case 'connectionId': this.connectionId = data; break; case 'removeUser': this.removeCarets(data); break; case 'action': this.dataReceived(data); break; } }; CollaborativeEditingHandler.prototype.isAcknowledgePending = function () { return !isNullOrUndefined(this.acknowledgmentPending); }; CollaborativeEditingHandler.prototype.handleAcknowledgementReceived = function (action) { var versionDiff = this.getVersionDifference(action); if (versionDiff > 1) { this.checkAndRetriveChangesFromServer(); } else { this.logMessage('Ack received: ' + action.version); this.logMessage('Ack version diff: ' + versionDiff); if (action.version > this.version) { this.updateVersion(action.version); this.acknowledgementReceived(); this.sendLocalOperation(); } } }; CollaborativeEditingHandler.prototype.updateVersion = function (version) { if (version > this.version) { this.version = version; } }; CollaborativeEditingHandler.prototype.acknowledgementReceived = function () { this.acknowledgmentPending = undefined; }; //Send the local operation to server CollaborativeEditingHandler.prototype.sendLocalOperation = function () { var _this = this; if (this.pendingOps.length > 0) { var operations = this.pendingOps.shift(); var changes = {}; changes.currentUser = this.documentEditor.currentUser; changes.roomName = this.roomName; changes.connectionId = this.connectionId; changes.version = this.version; changes.operations = operations; this.acknowledgmentPending = operations; var httpRequest = new XMLHttpRequest(); httpRequest.open('Post', this.serviceUrl + 'UpdateAction', true); httpRequest.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); this.setCustomAjaxHeaders(httpRequest); httpRequest.onreadystatechange = function () { if (httpRequest.readyState === 4) { if (httpRequest.status === 200 || httpRequest.status === 304) { var dataObject = JSON.parse(httpRequest.responseText); if (!_this.isSyncServerChanges) { _this.handleAcknowledgementReceived(dataObject); } } else { var failedArgs = { status: (httpRequest.status).toString(), statusText: httpRequest.statusText, url: _this.serviceUrl + 'UpdateAction' }; _this.documentEditor.fireServiceFailure(failedArgs); } } }; this.logMessage('Sent: ' + JSON.stringify(changes)); httpRequest.send(JSON.stringify(changes)); } }; CollaborativeEditingHandler.prototype.dataReceived = function (action) { if ((action.connectionId === this.connectionId && !this.documentEditor.editor.isIncrementalSave) || this.isSyncServerChanges) { this.logMessage(this.isSyncServerChanges ? 'SignalR Server sync' + action.version : 'SignalR Same user sync:' + action.version); return; } var versionDiff = this.getVersionDifference(action); if (versionDiff <= 0 && !this.documentEditor.editor.isIncrementalSave) { this.logMessage('SignalR return diff:<=0' + action.version); return; } if (versionDiff > 1 && !this.documentEditor.editor.isIncrementalSave) { this.logMessage('SignalR return diff:>=1' + action.version); this.checkAndRetriveChangesFromServer(); return; } this.logMessage('SignalR ack: ' + action.version); // try { this.logMessage('Received: ' + JSON.stringify(action)); this.handleRemoteOperation(action); // } catch (e) { // if (e instanceof Error) { // this.logMessage('Error while handling remote operation: ' + e); // this.logMessage('Error while handling remote operation: ' + e.stack); // } else { // this.logMessage('Error while handling remote operation: ' + e); // } // } }; CollaborativeEditingHandler.prototype.getVersionDifference = function (action) { return action.version - this.version; }; CollaborativeEditingHandler.prototype.handleRemoteOperation = function (action) { //To Prevent the content change event while applying the remote operation this.documentEditor.editorModule.isRemoteAction = true; //TODO: Need to handle backward selection. var localStartOffset = this.documentEditor.selectionModule.getAbsolutePositionFromRelativePosition(this.documentEditor.selectionModule.start); var selectionLength = this.documentEditor.selectionModule.getAbsolutePositionFromRelativePosition(this.documentEditor.selectionModule.end) - localStartOffset; if (!isNullOrUndefined(this.acknowledgmentPending)) { this.logMessage('Acknowledge transform:' + this.acknowledgmentPending[0].text + 'version:' + action.version); this.transform([this.acknowledgmentPending], action.operations); } if (this.pendingOps.length > 0) { this.logMessage('Pending transform:' + this.pendingOps.length + 'version:' + action.version); } this.transform(this.pendingOps, action.operations); this.applyRemoteOperation(action, localStartOffset, selectionLength); this.updateVersion(action.version); this.documentEditor.editorModule.isRemoteAction = false; if (this.documentEditor.editorHistoryModule.canUndo()) { this.documentEditor.editorHistoryModule.undoStack.length = 0; } if (this.documentEditor.editorHistoryModule.canRedo()) { this.documentEditor.editorHistoryModule.redoStack.length = 0; } }; CollaborativeEditingHandler.prototype.transform = function (operation, remoteOperation) { for (var i = 0; i < remoteOperation.length; i++) { var remoteData = remoteOperation[i]; if (operation.length > 0) { for (var j = 0; j < operation.length; j++) { for (var k = 0; k < operation[j].length; k++) { var localOperation = operation[j][k]; this.transformSelectionOperation(localOperation, remoteData); var previousOffset = remoteData.offset; this.transformOperation(localOperation, remoteData, remoteOperation); this.logMessage('Transformed offset:' + (remoteData.offset - previousOffset)); } } } } }; CollaborativeEditingHandler.prototype.skipAction = function (remoteOperation) { for (var i = 0; i < remoteOperation.length; i++) { var data = remoteOperation[i]; data.length = 0; data.skipOperation = true; } }; CollaborativeEditingHandler.prototype.handleAcceptReject = function (revisions, operation) { for (var i = 0; i < revisions.length; i++) { var revision = revisions[i]; if (revision.author === operation.markerData.author && revision.revisionType === operation.markerData.revisionType) { var currentRevision = this.documentEditor.editorModule.getRevision(revision.revisionID); if (currentRevision) { if (operation.markerData.isAcceptOrReject === 'Accept') { revision.accept(); } else if (operation.markerData.isAcceptOrReject === 'Reject') { revision.reject(); } } } } }; CollaborativeEditingHandler.prototype.applyRemoteOperation = function (action, offset, selectionLength) { var currentUser = this.documentEditor.currentUser; var currentEditMode = this.documentEditor.commentReviewPane.commentPane.isEditMode; var currenteditorHistory = this.documentEditor.editorHistoryModule.lastOperation; var currentTextArea; if (!isNullOrUndefined(this.documentEditor.commentReviewPane.commentPane.currentEditingComment)) { currentTextArea = this.documentEditor.commentReviewPane.commentPane.currentEditingComment.textArea; } var contentControlProperties; for (var i = 0; i < action.operations.length; i++) { var markerData = action.operations[i].markerData; var tableLength = undefined; var trackingCurrentValue = this.documentEditor.enableTrackChanges; if (!isNullOrUndefined(markerData) && !isNullOrUndefined(markerData.author)) { this.documentEditor.currentUser = markerData.author; } if (!isNullOrUndefined(markerData) && !isNullOrUndefined(markerData.isSkipTracking) && markerData.isSkipTracking && this.documentEditor.enableTrackChanges) { this.documentEditor.skipSettingsOps = true; this.documentEditor.enableTrackChanges = false; } if (action.operations[i].skipOperation || (!isNullOrUndefined(action.operations[i].markerData) && action.operations[i].markerData.skipOperation)) { continue; } if (action.operations[i].action === 'Update') { if (!isNullOrUndefined(action.operations[i].styleData)) { var styleData = JSON.parse(action.operations[i].styleData); this.documentEditor.editor.updateStyleObject(styleData); } continue; } var startOffset = this.getRelativePositionFromAbsolutePosition(action.operations[i].offset, false, false, false); // Code for Comparing the offset calculated using old approach and optimized approach // this.documentEditor.selection.isNewApproach = true; // let newStartOffset = this.getRelativePositionFromAbsolutePosition(action.operations[i].offset, false, false, false); // this.documentEditor.selection.isNewApproach = false; // throwCustomError(startOffset !== newStartOffset, "New StartIndex " + newStartOffset + " and old StartIndex " + startOffset + " doesnot match"); var op2 = action.operations[i]; var endOffset = startOffset; if (isNullOrUndefined(action.operations[i].action)) { this.documentSettings(action.operations[i]); continue; } if (action.operations[i].action === 'Delete' || action.operations[i].action === 'Format') { //Update endOffset if (!(op2.action === 'Format' && op2.length === 0)) { this.documentEditor.selectionModule.isEndOffset = true; } endOffset = this.getRelativePositionFromAbsolutePosition(action.operations[i].offset + action.operations[i].length, false, false, false); this.documentEditor.selectionModule.isEndOffset = false; // Code for Comparing the offset calculated using old approach and optimized approach // this.documentEditor.selection.isNewApproach = true; // let newEndOffset = this.getRelativePositionFromAbsolutePosition(action.operations[i].offset + action.operations[i].length, false, false, false); // this.documentEditor.selection.isNewApproach = false; // throwCustomError(endOffset !== newEndOffset, "New EndIndex " + newEndOffset + " and old EndIndex " + endOffset + " doesnot match"); } if (op2.action === 'Insert' && (op2.text !== CONTROL_CHARACTERS.Row && op2.text !== CONTROL_CHARACTERS.Cell) && (isNullOrUndefined(op2.markerData) || isNullOrUndefined(op2.markerData.isAcceptOrReject))) { this.documentEditor.selectionModule.select(startOffset, endOffset); } else if (op2.action === 'Delete' && op2.text !== CONTROL_CHARACTERS.Cell && (isNullOrUndefined(op2.markerData) || isNullOrUndefined(op2.markerData.isAcceptOrReject))) { this.documentEditor.selectionModule.select(startOffset, endOffset); } else if (op2.action === 'Format' && (isNullOrUndefined(op2.markerData) || isNullOrUndefined(op2.markerData.isAcceptOrReject))) { this.documentEditor.selectionModule.select(startOffset, endOffset); } if (!isNullOrUndefined(op2.markerData)) { if (!isNullOrUndefined(op2.markerData.revisionForFootnoteEndnoteContent) || !isNullOrUndefined(op2.markerData.revisionId)) { this.documentEditor.editorModule.revisionData = []; } if (!isNullOrUndefined(op2.markerData.revisionForFootnoteEndnoteContent)) { this.documentEditor.editorModule.revisionData.push(op2.markerData.revisionForFootnoteEndnoteContent); } if (!isNullOrUndefined(op2.markerData.revisionId)) { this.documentEditor.editorModule.revisionData.push(op2.markerData); } if (!isNullOrUndefined(op2.markerData.splittedRevisions) && op2.markerData.splittedRevisions.length > 0) { this.documentEditor.editorModule.revisionData = this.documentEditor.editorModule.revisionData.concat(op2.markerData.splittedRevisions); } } if (!isNullOrUndefined(op2.markerData) && !isNullOrUndefined(op2.markerData.isAcceptOrReject) && op2.markerData.isAcceptOrReject !== '') { var revision = this.documentEditor.editorModule.getRevision(op2.markerData.revisionId); if (revision) { if (op2.markerData.isAcceptOrReject === 'Accept') { revision.accept(); } else if (op2.markerData.isAcceptOrReject === 'Reject') { revision.reject(); } } else { if (op2.text === CONTROL_CHARACTERS.Row) { var data_1 = this.getRelativePositionFromAbsolutePosition(op2.offset, false, true, false); if (data_1 && data_1.rowWidget) { this.handleAcceptReject(data_1.rowWidget.rowFormat.revisions, op2); } } else { this.documentEditor.selectionModule.select(startOffset, endOffset); var item = void 0; if (this.documentEditor.selection.start.isAtParagraphEnd) { item = this.documentEditor.selection.start.currentWidget.paragraph.characterFormat; } else { var elementInfo = this.documentEditor.selectionModule.start.currentWidget.getInline(this.documentEditor.selectionModule.start.offset + 1, 0); item = elementInfo.element; } if (!isNullOrUndefined(item)) { this.handleAcceptReject(item.revisions, op2); } } } continue; } if (op2.action === 'Insert') { if (op2.type === 'Paste') { this.documentEditor.editorModule.isPasteListUpdated = false; this.documentEditor.editorModule.pasteContents(HelperMethods.getSfdtDocument(op2.pasteContent)); } else if (op2.type === 'PasteToc') { this.documentEditor.editorModule.isInsertingTOC = true; this.documentEditor.editorModule.pasteContents(HelperMethods.getSfdtDocument(op2.pasteContent)); this.documentEditor.editorModule.isInsertingTOC = false; } else if (op2.text === CONTROL_CHARACTERS.Image.toString()) { this.insertImage(op2.imageData); } else if (op2.text === CONTROL_CHARACTERS.Section_Break.toString() && op2.type === 'NewPage') { this.documentEditor.editorModule.insertSectionBreak(); } else if (op2.text === CONTROL_CHARACTERS.Section_Break.toString() && op2.type === 'Continuous') { this.documentEditor.editorModule.insertSectionBreak(SectionBreakType.Continuous); } else if (markerData && (op2.text === CONTROL_CHARACTERS.Marker_Start || op2.text === CONTROL_CHARACTERS.Marker_End || op2.text === CONTROL_CHARACTERS.Field_Separator)) { var element = void 0; if (markerData.type && markerData.type === 'Bookmark') { if (op2.text === CONTROL_CHARACTERS.Marker_Start) { var bookmarks = this.documentEditor.editorModule.createBookmarkElements(markerData.bookmarkName); element = bookmarks[0]; this.documentEditor.documentHelper.isBookmarkInserted = false; this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [element]); } else { if (this.documentEditor.documentHelper.bookmarks.containsKey(markerData.bookmarkName)) { var bookmark = this.documentEditor.documentHelper.bookmarks.get(markerData.bookmarkName); if (bookmark) { element = bookmark.reference; this.documentEditor.documentHelper.isBookmarkInserted = true; this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [element]); this.documentEditor.selectionModule.selectBookmark(markerData.bookmarkName); bookmark.properties = this.documentEditor.selectionModule.getBookmarkProperties(bookmark); element.properties = this.documentEditor.selectionModule.getBookmarkProperties(element); this.documentEditor.editorModule.fireContentChange(); } } } } else if (markerData.type && markerData.type === 'EditRange') { var user = markerData.user; var id = markerData.editRangeId; if (op2.text === CONTROL_CHARACTERS.Marker_Start) { if (this.documentEditor.documentHelper.restrictEditingPane) { this.documentEditor.documentHelper.restrictEditingPane.addUserDialog.bindListData(user); } element = this.documentEditor.editorModule.addEditElement(user, id); element.columnFirst = parseInt(markerData.columnFirst); element.columnLast = parseInt(markerData.columnLast); element.line = this.documentEditor.selectionModule.start.currentWidget; } else { var editRanges = this.documentEditor.documentHelper.editRanges.get(user); for (var _i = 0, editRanges_1 = editRanges; _i < editRanges_1.length; _i++) { var editStart = editRanges_1[_i]; if (editStart.editRangeId === id) { element = editStart.editRangeEnd; element.line = this.documentEditor.selectionModule.start.currentWidget; break; } } } this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [element]); this.documentEditor.editorModule.fireContentChange(); } else if (markerData.type && markerData.type === 'Field') { this.documentEditor.editor.isFieldOperation = true; var type = op2.text === CONTROL_CHARACTERS.Marker_Start ? 0 : op2.text === CONTROL_CHARACTERS.Marker_End ? 1 : op2.text === CONTROL_CHARACTERS.Field_Separator ? 2 : undefined; if (!isNullOrUndefined(type) && isNullOrUndefined(markerData.checkBoxValue)) { var field = new FieldElementBox(type); if (type === 0 && !isNullOrUndefined(markerData.formFieldData)) { var formFieldData = this.documentEditor.editor.getFormFieldData(op2.type); this.documentEditor.parser.parseFormFieldData(0, JSON.parse(markerData.formFieldData), formFieldData); field.formFieldData = formFieldData; } var characterFormat = new WCharacterFormat(); if (op2.format) { var data_2 = JSON.parse(op2.format); this.documentEditor.parser.parseCharacterFormat(0, data_2, characterFormat); } field.characterFormat.copyFormat(characterFormat); this.documentEditor.editorModule.initInsertInline(field); } else { var inlineObj = this.documentEditor.selectionModule.start.currentWidget.getInline(this.documentEditor.selectionModule.start.offset, 0); var inline = inlineObj.element; if (inline instanceof FieldElementBox) { this.documentEditor.editorModule.toggleCheckBoxFormField(inline, true, markerData.checkBoxValue); } } } else if (!isNullOrUndefined(markerData) && !isNullOrUndefined(markerData.commentId)) { var commentType = op2.text === CONTROL_CHARACTERS.Marker_Start ? 0 : 1; var deleteComment = this.documentEditor.documentHelper.layout.getCommentById(this.deletedComments, markerData.commentId); var ownerDeleteComment = undefined; if (isNullOrUndefined(deleteComment)) { deleteComment = this.documentEditor.documentHelper.layout.getCommentById(this.documentEditor.documentHelper.comments, markerData.commentId); if (isNullOrUndefined(deleteComment) && !isNullOrUndefined(markerData.ownerCommentId)) { ownerDeleteComment = this.documentEditor.documentHelper.layout.getCommentById(this.documentEditor.documentHelper.comments, markerData.ownerCommentId); if (!isNullOrUndefined(ownerDeleteComment)) { deleteComment = this.documentEditor.documentHelper.layout.getCommentById(ownerDeleteComment.replyComments, markerData.commentId); } } } if (!isNullOrUndefined(deleteComment)) { var item = new CommentCharacterElementBox(commentType); item.commentId = markerData.commentId; this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [item]); item.comment = deleteComment; var index = this.documentEditor.selectionModule.start.currentWidget.children.indexOf(item); deleteComment.commentStart = this.documentEditor.selectionModule.start.currentWidget.children[index]; } else { var item = new CommentCharacterElementBox(commentType); item.commentId = markerData.commentId; this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [item]); commentType === 0 ? this.commentsStart.push(item) : this.commentsEnd.push(item); } } else if (!isNullOrUndefined(op2.markerData.type) && (op2.markerData.type === 'Footnote' || op2.markerData.type === 'Endnote')) { if (op2.markerData.type === 'Footnote') { this.documentEditor.editorModule.insertFootnote(); } else if (op2.markerData.type === 'Endnote') { this.documentEditor.editorModule.insertEndnote(); } } else if (markerData.type && markerData.type === 'ContentControl') { if (op2.text === CONTROL_CHARACTERS.Marker_Start) { contentControlProperties = new ContentControlProperties(markerData.text); if (!isNullOrUndefined(markerData.contentControlProperties)) { this.documentEditor.editorModule.assignContentControl(contentControlProperties, JSON.parse(markerData.contentControlProperties)); } } var contentControl = new ContentControl(contentControlProperties.contentControlWidgetType); contentControl.contentControlProperties = contentControlProperties; contentControl.type = op2.text === CONTROL_CHARACTERS.Marker_Start ? 0 : 1; this.documentEditor.editorModule.insertElementsInternal(this.documentEditor.selectionModule.start, [contentControl]); if (op2.text === CONTROL_CHARACTERS.Marker_End && contentControl.reference) { this.documentEditor.editorModule.updatePropertiesToBlock(contentControl.reference, true); } } } else if (markerData && !isNullOrUndefined(markerData.dropDownIndex) && op2.type === 'DropDown') { var inlineObj = this.documentEditor.selectionModule.start.currentWidget.getInline(this.documentEditor.selectionModule.start.offset, 0); var inline = inlineObj.element; if (inline instanceof FieldElementBox) { this.documentEditor.editorModule.updateFormField(inline, markerData.dropDownIndex, false); } } else if (op2.text === CONTROL_CHARACTERS.Section_Break.toString() && op2.type === 'NewPage') { this.documentEditor.editorModule.insertSectionBreak(); } else if (op2.text === CONTROL_CHARACTERS.Section_Break.toString() && op2.type === 'Continuous') { this.documentEditor.editorModule.insertSectionBreak(SectionBreakType.Continuous); } else if (op2.text === CONTROL_CHARACTERS.Table) { i = action.operations.length; this.buildTable(action.operations); tableLength = this.getOperationLength(action.operations); } else if (op2.text === CONTROL_CHARACTERS.Row) { i = action.operations.length; if (isNullOrUndefined(op2.format)) { action.operations.reverse(); } this.buildRow(action.operations); tableLength = this.getOperationLength(action.operations); } else if (op2.text === CONTROL_CHARACTERS.Cell) { var paraFormat = undefined; var charFormat = undefined; if (op2.type === 'CellFormat') { if (op2.length > 0) { paraFormat = action.operations[i - 1].format; charFormat = action.operations[i - 2].format; } this.buildCell(op2, paraFormat, charFormat); } } else if (op2.text === CONTROL_CHARACTERS.PageBreak.toString()) { this.documentEditor.editorModule.insertPageBreak(); } else if (op2.text === CONTROL_CHARACTERS.ColumnBreak.toString()) { this.documentEditor.editorModule.insertColumnBreak(); } else { if (op2.format) { var characterFormat = new WCharacterFormat(); var data = JSON.parse(op2.format); this.documentEditor.parser.parseCharacterFormat(0, data, characterFormat); this.documentEditor.selectionModule.isRetrieveFormatting = true; this.documentEditor.selectionModule.characterFormat.copyFormat(characterFormat); this.documentEditor.selectionModule.isRetrieveFormatting = false; } this.documentEditor.editorModule.insertText(op2.text); } } else if (op2.action === 'Delete') { // if (this.documentEditor.selection.isEmpty && this.documentEditor.selection.start.currentWidget.isLastLine() // && this.documentEditor.selection.start.offset === this.documentEditor.selection.getLineLength(this.documentEditor.selection.start.currentWidget) + 1) { // this.documentEditor.selection.start.offset--; // this.documentEditor.selection.end.offset--; // //Delete pargaraph marker // this.documentEditor.editor.delete(); // } else { if (op2.text === CONTROL_CHARACTERS.Marker_Start || op2.text === CONTROL_CHARACTERS.Marker_End) { if (!isNullOrUndefined(markerData) && !isNullOrUndefined(markerData.commentId)) { var selection = this.documentEditor.selectionModule; var commentType = op2.text === CONTROL_CHARACTERS.Marker_Start ? 0 : 1; var deleteComment = void 0; if (this.documentEditor.selection.getElementInfo(this.documentEditor.selection.end.currentWidget, this.documentEditor.selection.end.offset).element instanceof CommentCharacterElementBox) { deleteComment = this.documentEditor.selection.getElementInfo(this.documentEditor.selection.end.currentWidget, this.documentEditor.selection.end.offset).element; } if (commentType === 1) { var commentEnd = deleteComment; if (commentEnd.indexInOwner !== -1) { this.documentEditor.editorModule.removeAtOffset(selection.start.currentWidget, this.documentEditor.selectionModule, selection.start.offset); } } else { var commentStart = deleteComment; if (commentStart.indexInOwner !== -1) { this.documentEditor.editorModule.removeAtOffset(selection.start.currentWidget, this.documentEditor.selectionModule, selection.start.offset); } commentStart.removeCommentMark(); } } else { var selection = this.documentEditor.selectionModule; var offset_1 = selection.start.offset - 1; this.documentEditor.editorModule.removeAtOffset(selection.start.currentWidget, this.documentEditor.selectionModule, offset_1); } } else if (op2.text === CONTROL_CHARACTERS.Cell) { this.buildDeleteCells(op2); } else { this.documentEditor.editorModule.onBackSpace(); } //} } else if (op2.action === 'Format') { if (op2.text === (CONTROL_CHARACTERS.Marker_Start.toString() + CONTROL_CHARACTERS.Marker_End.toString())) { this.updateOperation(op2); } else if (op2.text === CONTROL_CHARACTERS.Marker_Start && !isNullOrUndefined(op2.format)) { var contentcontrol = this.documentEditor.selection.currentContentControl; if (contentcontrol) { this.documentEditor.editorModule.assignContentControl(contentcontrol.contentControlProperties, JSON.parse(op2.format)); } } else if (op2.text === CONTROL_CHARACTERS.Marker_Start && !isNullOrUndefined(op2.markerData) && op2.markerData.type === 'ContentControlCheckBox') { var contentcontrol = this.documentEditor.selection.currentContentControl; if (contentcontrol && contentcontrol.contentControlProperties.type === 'CheckBox') { this.documentEditor.editorModule.toggleContentControlCheckBox(contentcontrol, markerData.checkBoxValue); } } else if (!isNullOrUndefined(op2.markerData) && !isNullOrUndefined(op2.markerData.revisionId)) { if (!isNullOrUndefined(op2.markerData.revisionType)) { if (op2.markerData.revisionType === 'Deletion') { if (op2.text === CONTROL_CHARACTERS.Row) { var data_3 = this.getRelativePositionFromAbsolutePosition(op2.offset, false, true, false); if (!isNullOrUndefined(data_3.rowWidget)) { var row = data_3.rowWidget; this.documentEditor.editorModule.trackRowDeletion(row); this.documentEditor.trackChangesPane.updateTrackChanges(); continue; } } this.documentEditor.editorModule.onBackSpace(); } } } else if (op2.text === CONTROL_CHARACTERS.Row) { var data_4 = this.getRelativePositionFromAbsolutePosition(op2.offset, false, true, false); if (!isNullOrUndefined(data_4.rowWidget)) { var table = data_4.rowWidget.ownerTable; var rowData = JSON.parse(op2.format); this.documentEditor.documentHelper.owner.parser.parseRowFormat(rowData, data_4.rowWidget.rowFormat, 0); table.calculateGrid(false); this.documentEditor.documentHelper.layout.reLayoutTable(table); } } else if (op2.text === CONTROL_CHARACTERS.Cell) { if (op2.type === 'TableFormat') { var tableData = this.getRelativePositionFromAbsolutePosition(op2.offset, true, false, false); var table = JSON.parse(op2.format); this.documentEditor.documentHelper.owner.parser.parseTableFormat(table, tableData.tableWidget.tableFormat, 0); tableData.tableWidget.calculateGrid(false); this.documentEditor.documentHelper.layout.reLayoutTable(tableData.tableWidget); } if (op2.type === 'RowFormat') { var rowData = this.getRelativePositionFromAbsolutePosition(op2.offset, false, true, false); var row = JSON.parse(op2.format); this.documentEditor.documentHelper.owner.parser.parseRowFormat(row, rowData.rowWidget.rowFormat, 0); } if (op2.type === 'CellFormat') { var cellData = this.getRelativePositionFromAbsolutePosition(op2.offset, false, false, true); var cell = JSON.parse(op2.format); this.documentEditor.documentHelper.owner.parser.parseCellFormat(cell, cellData.cellWidget.cellFormat, 0); } } else if (op2.text === CONTROL_CHARACTERS.Image) { var inlineObj = this.documentEditor.selectionModule.end.currentWidget.getInline(this.documentEditor.selectionModule.end.offset, 0); var inline = inlineObj.element; if (inline instanceof ImageElementBox) { this.documentEditor.editorModule.onImageFormat(inline, HelperMethods.convertPointToPixel(op2.imageData.width), HelperMethods.convertPointToPixel(op2.imageData.height), op2.imageData.alternativeText); } } else if (op2.type === 'ListFormat') { var paragraphFormat = JSON.parse(op2.format); var format = new WParagraphFormat(undefined); this.documentEditor.parser.parseParagraphFormat(0, paragraphFormat, format); this.updateList(op2, format); var list = this.documentEditor.documentHelper.getListById(paragraphFormat.listFormat.nsid, true); if (!isNullOrUndefined(list)) { format.listFormat.listId = list.listId; format.listFormat.list = list; } this.documentEditor.editorModule.onApplyParagraphFormat(op2.text, format.listFormat, false, false); } else if (op2.type === 'RestartNumbering') { var nsid = this.updateList(op2); var list = this.documentEditor.documentHelper.getListById(nsid, true); this.documentEditor.editorModule.restartListAtInternal(this.documentEditor.selectionModule, list.listId, list.nsid); } else if (op2.type === 'ContinueNumbering') { var paragraphFormat = JSON.parse(op2.format); var format = new WParagraphFormat(undefined); this.documentEditor.parser.parseParagraphFormat(0, paragraphFormat, format); var list = this.documentEditor.documentHelper.getListById(format.listFormat.nsid, true); if (!isNullOrUndefined(list)) { format.listFormat.listId = list.listId; format.listFormat.list = list; } this.documentEditor.editorModule.applyContinueNumberingInternal(this.documentEditor.selectionModule, format); } else if (op2.type === 'CharacterFormat') { this.insertCharaterFormat(op2.type, op2.format); } else if (op2.type === 'ParagraphFormat') { this.insertParagraphFormat(op2, op2.format); } else if (op2.type === 'TableFormat') { this.insertTableFormat(op2.text, op2.format, op2.offset); } else if (op2.type === 'SectionFormat') { this.insertSectionFormat(op2.text, op2.format); } else if (op2.type === 'RowFormat') { this.insertRowFormat(op2.text, op2.format); } else if (op2.type === 'CellFormat') { this.insertCellFormat(op2.format); } } this.documentEditor.editor.revisionData = undefined; if (this.documentEditor.enableTrackChanges != trackingCurrentValue) { this.documentEditor.skipSettingsOps = true; this.documentEditor.enableTrackChanges = trackingCurrentValue; } this.documentEditor.currentUser = currentUser; var newOffset = this.documentEditor.selectionModule.startOffset; //op2.offset = newOffset; this.updateRemoteSelection(action, this.documentEditor.selectionModule.getAbsolutePositionFromRelativePosition(newOffset)); if (!isNullOrUndefined(tableLength)) { var temp = op2.length; op2.length = tableLength; tableLength = temp; } var tranformedOffset = this.transformSection(op2.action, op2, offset)[1]; //TODO: Need to handle backward selection. //TODO: Need to optimize the code. Need to transform selection end length based on remove content var tranformedEndOffset = this.transformSection(op2.action, op2, offset + selectionLength)[1]; offset = tranformedOffset; this.documentEditor.selectionModule.select(this.getRelativePositionFromAbsolutePosition(tranformedOffset, false, false, false), this.getRelativePositionFromAbsolutePosition(tranformedEndOffset, false, false, false)); if (!isNullOrUndefined(tableLength)) { op2.length = tableLength; } this.transformRemoteCursor(action.connectionId, op2, op2.offset); if (!isNullOrUndefined(this.documentEditor.searchModule) && !isNullOrUndefined(this.documentEditor.optionsPaneModule) && this.documentEditor.searchModule.searchResults.length > 0 && this.documentEditor.optionsPaneModule.isOptionsPaneShow) { this.documentEditor.optionsPaneModule.searchIconClickInternal(); } } contentControlProperties = undefined; if (this.documentEditor.editor.isFieldOperation) { this.documentEditor.documentHelper.layout.layoutWholeDocument(); this.documentEditor.editor.isFieldOperation = false; } if (!isNullOrUndefined(this.rowWidget)) { var ownerTable = this.rowWidget.ownerTable.combineWidget(this.documentEditor.viewer); ownerTable.updateRowIndex(0); ownerTable.calculateGrid(true); this.documentEditor.documentHelper.layout.reLayoutTable(ownerTable); this.documentEditor.editorModule.reLayout(this.documentEditor.selectionModule); this.rowWidget = undefined; } if (!isNullOrUndefined(this.table)) { this.table.calculateGrid(); this.documentEditor.editorModule.updateTable(this.table); this.documentEditor.editorModule.reLayout(this.documentEditor.selectionModule, true); this.table = undefined; } this.documentEditor.currentUser = currentUser; this.documentEditor.commentReviewPane.commentPane.isEditMode = currentEditMode; this.documentEditor.editorHistoryMod