@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
558 lines (557 loc) • 32.1 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { BaseHistoryInfo } from './base-history-info';
import { CommentCharacterElementBox } from '../viewer/page';
import { CONTROL_CHARACTERS } from '../../base/types';
/**
* EditorHistory preservation class
*/
/**
* @private
*/
var HistoryInfo = /** @class */ (function (_super) {
__extends(HistoryInfo, _super);
function HistoryInfo(node, isChild) {
var _this = _super.call(this, node) || this;
_this.isChildHistoryInfo = false;
_this.editRangeStart = undefined;
_this.documentHelper = node.documentHelper;
_this.isChildHistoryInfo = isChild;
return _this;
}
Object.defineProperty(HistoryInfo.prototype, "hasAction", {
get: function () {
return !isNullOrUndefined(this.modifiedActions);
},
enumerable: true,
configurable: true
});
HistoryInfo.prototype.addModifiedAction = function (baseHistoryInfo) {
// For complex actions such as Replace text, Insert/Remove Hyperlink etc.
if (!(this.editorHistory.isUndoing || this.editorHistory.isRedoing)) {
if (isNullOrUndefined(this.modifiedActions)) {
this.modifiedActions = [];
}
this.modifiedActions.push(baseHistoryInfo);
}
};
/**
* @private
*/
HistoryInfo.prototype.getActionInfo = function (isInvertOperation) {
var action = this.action;
var operations = [];
switch (action) {
case 'InsertBookmark':
case 'RestrictEditing':
if (this.editorHistory.isUndoing) {
for (var i_1 = 0; i_1 < this.modifiedActions.length; i_1++) {
if (action == 'RestrictEditing') {
this.modifiedActions[parseInt(i_1.toString(), 10)].markerData.push(this.owner.editorModule.getMarkerData(this.modifiedActions[parseInt(i_1.toString(), 10)].removedNodes[0]));
}
operations.push(this.modifiedActions[parseInt(i_1.toString(), 10)].getDeleteOperation('DeleteBookmark', i_1 == 0 ? true : undefined));
this.modifiedActions[parseInt(i_1.toString(), 10)].markerData.shift();
}
}
else {
for (var i_2 = 0; i_2 < this.modifiedActions.length; i_2++) {
var currentHistory_1 = this.modifiedActions[parseInt(i_2.toString(), 10)];
if (currentHistory_1.action === 'DeleteBookmark') {
operations.push(currentHistory_1.getDeleteOperation('DeleteBookmark'));
operations.push(currentHistory_1.getDeleteOperation('DeleteBookmark', true));
continue;
}
operations.push(currentHistory_1.getInsertOperation(action));
}
}
break;
case 'BackSpace':
case 'Delete':
case 'RemoveEditRange':
if (this.editorHistory.isUndoing) {
for (var i_3 = 0; i_3 < this.modifiedActions.length; i_3++) {
var currentHistory_2 = this.modifiedActions[parseInt(i_3.toString(), 10)];
if (currentHistory_2.action === 'InsertInline') {
var operation = currentHistory_2.getDeleteOperation('DeleteBookmark', true);
operations.push(operation);
}
else {
var operationCollection = currentHistory_2.getActionInfo();
operations = operations.concat(operationCollection);
if (currentHistory_2.action === 'RemoveEditRange') {
operations.push(currentHistory_2.getDeleteOperation(action, true));
}
}
}
operations.reverse();
}
else {
for (var i_4 = 0; i_4 < this.modifiedActions.length; i_4++) {
var currentHistory_3 = this.modifiedActions[parseInt(i_4.toString(), 10)];
if (currentHistory_3.action === 'InsertInline') {
var operation = currentHistory_3.getInsertOperation('InsertBookmark');
operations.push(operation);
}
else {
operations.push(currentHistory_3.getDeleteOperation(action));
if (currentHistory_3.action === 'RemoveEditRange') {
operations.push(currentHistory_3.getDeleteOperation(action, true));
}
}
}
}
break;
case 'PageBreak':
case 'ColumnBreak':
if (this.owner.enableTrackChanges) {
for (var i_5 = 0; i_5 < this.modifiedActions.length; i_5++) {
var currentHistory_4 = this.modifiedActions[parseInt(i_5.toString(), 10)];
if (currentHistory_4.removedNodes.length > 0) {
operations = operations.concat(currentHistory_4.getDeleteOperationsForTrackChanges());
}
var markerData = currentHistory_4.markerData[currentHistory_4.markerData.length - 1];
var operation_1 = currentHistory_4.getInsertOperation('Enter');
var breakOperation = this.getInsertOperation(action);
operation_1.markerData = markerData;
breakOperation.markerData = this.owner.editorModule.getMarkerData(undefined, undefined, this.owner.editorModule.getRevision(markerData.revisionId));
operations.push(operation_1);
operations.push(breakOperation);
operations.push(operation_1);
operation_1.markerData.skipOperation = true;
}
}
else {
if (this.editorHistory.isUndoing) {
for (var i_6 = 0; i_6 < 3; i_6++) {
operations.push(this.getDeleteOperation('Delete'));
}
}
else {
for (var i_7 = 0; i_7 < this.modifiedActions.length; i_7++) {
var currentHistory_5 = this.modifiedActions[parseInt(i_7.toString(), 10)];
if (currentHistory_5.removedNodes.length > 0) {
operations.push(currentHistory_5.getDeleteOperation(action));
}
}
operations.push(this.getInsertOperation('Enter'));
operations.push(this.getInsertOperation(action));
operations.push(this.getInsertOperation('Enter'));
}
}
break;
case 'InsertHyperlink':
case 'AutoFormatHyperlink':
case 'RemoveHyperlink':
if (this.editorHistory.isUndoing && action === 'RemoveHyperlink') {
var length_1 = 0;
for (var i_8 = 0; i_8 < this.modifiedActions.length; i_8++) {
var currentHistory_6 = this.modifiedActions[parseInt(i_8.toString(), 10)];
if (currentHistory_6.action == 'FontColor' || currentHistory_6.action === 'Underline') {
length_1 = currentHistory_6.endIndex - currentHistory_6.startIndex;
}
}
if (!isNullOrUndefined(this.modifiedActions[parseInt((this.modifiedActions.length - 1).toString(), 10)].fieldBegin)) {
this.modifiedActions[parseInt((this.modifiedActions.length - 1).toString(), 10)].endIndex = this.modifiedActions[parseInt((this.modifiedActions.length - 1).toString(), 10)].startIndex + length_1;
var operation_2 = this.modifiedActions[parseInt((this.modifiedActions.length - 1).toString(), 10)].getDeleteOperation('Delete');
operation_2.markerData = undefined;
operations.push(operation_2);
var operationCollection = this.modifiedActions[parseInt((this.modifiedActions.length - 1).toString(), 10)].getFieldOperation();
operations = operations.concat(operationCollection);
}
}
else {
for (var i = 0; i < this.modifiedActions.length; i++) {
var currentHistory = this.modifiedActions[parseInt(i.toString(), 10)];
if (currentHistory.action === 'InsertHyperlink') {
operations.push.apply(operations, currentHistory.getActionInfo());
}
else if (currentHistory.action === 'InsertInline') {
if (currentHistory.insertedText === CONTROL_CHARACTERS.Marker_Start || currentHistory.insertedText === CONTROL_CHARACTERS.Marker_End) {
if (this.editorHistory.isUndoing) {
operations.push(currentHistory.getDeleteOperation(currentHistory.action));
}
else {
operations.push(currentHistory.getInsertOperation('InsertHyperlink'));
}
}
else {
if (this.editorHistory.isUndoing) {
operations.push(currentHistory.getDeleteOperation(currentHistory.action));
}
else {
operations.push(currentHistory.getInsertOperation('Insert'));
}
}
}
else if (currentHistory.action === 'Delete') {
operations.push(currentHistory.getDeleteOperation(currentHistory.action));
}
else if (currentHistory.action === 'Underline') {
operations = operations.concat(currentHistory.getActionInfo());
}
else if (currentHistory.action === 'FontColor') {
operations = operations.concat(currentHistory.getActionInfo());
if (action === 'RemoveHyperlink') {
// Clear format not synced when removeHyperlink
operations = operations.concat(currentHistory.buildFormatOperation('ClearFormat', true));
}
}
}
if (this.editorHistory.isUndoing) {
operations.reverse();
}
}
break;
case 'InsertComment':
if (this.editorHistory.isUndoing) {
this.getDeleteCommentOperation(this.modifiedActions, operations);
}
else {
for (var i_9 = 0; i_9 < this.modifiedActions.length; i_9++) {
var currentHistory_7 = this.modifiedActions[parseInt(i_9.toString(), 10)];
var operation_3 = currentHistory_7.getInsertOperation(currentHistory_7.action);
if ((currentHistory_7.insertedElement instanceof CommentCharacterElementBox && currentHistory_7.action === 'InsertInline')) {
operations.push(currentHistory_7.getCommentOperation(operation_3, currentHistory_7.action));
}
else if (currentHistory_7.action === 'InsertCommentWidget') {
operation_3 = this.getUpdateOperation();
operations.push(currentHistory_7.getCommentOperation(operation_3, currentHistory_7.action));
}
}
}
break;
case 'RemoveComment':
if (this.editorHistory.isUndoing) {
for (var i_10 = this.modifiedActions.length - 1; i_10 >= 0; i_10--) {
var currentHistory_8 = this.modifiedActions[parseInt(i_10.toString(), 10)];
var operation_4 = undefined;
var operationCollection = [];
if (currentHistory_8.action === 'InsertInline' && currentHistory_8.insertedElement instanceof CommentCharacterElementBox) {
operation_4 = currentHistory_8.getDeleteOperation(currentHistory_8.action);
operationCollection.push(currentHistory_8.getCommentOperation(operation_4, 'InsertInline'));
}
else if (currentHistory_8.action === 'RemoveInline') {
operation_4 = currentHistory_8.getDeleteOperation(currentHistory_8.action);
operationCollection.push(currentHistory_8.getCommentOperation(operation_4, 'InsertInline'));
operation_4 = currentHistory_8.getInsertOperation(currentHistory_8.action);
operationCollection.push(currentHistory_8.getCommentOperation(operation_4, 'InsertInline'));
}
else if (currentHistory_8.action === 'DeleteComment') {
operationCollection = currentHistory_8.getActionInfo();
}
else {
this.owner.sfdtExportModule.iscontentInsert = false;
operationCollection = currentHistory_8.getActionInfo();
this.owner.sfdtExportModule.iscontentInsert = true;
}
operations = operations.concat(operationCollection);
}
}
else {
for (var i_11 = 0; i_11 < this.modifiedActions.length; i_11++) {
var currentHistory_9 = this.modifiedActions[parseInt(i_11.toString(), 10)];
var operation_5 = undefined;
var operationCollection = [];
if (currentHistory_9.action === 'RemoveInline' && currentHistory_9.removedNodes[0] instanceof CommentCharacterElementBox) {
operation_5 = currentHistory_9.getDeleteOperation(currentHistory_9.action);
operationCollection.push(currentHistory_9.getCommentOperation(operation_5, currentHistory_9.action));
}
else if (currentHistory_9.action === 'InsertInline' && currentHistory_9.insertedElement instanceof CommentCharacterElementBox) {
operation_5 = currentHistory_9.getInsertOperation(currentHistory_9.action);
operationCollection.push(currentHistory_9.getCommentOperation(operation_5, currentHistory_9.action));
}
else {
operationCollection = currentHistory_9.getActionInfo();
}
operations = operations.concat(operationCollection);
}
}
break;
case 'DeleteComment':
if (this.editorHistory.isUndoing) {
for (var j = this.modifiedActions.length - 1; j >= 0; j--) {
var history_1 = this.modifiedActions[parseInt(j.toString(), 10)];
var operation_6 = history_1.getInsertOperation(history_1.action);
if ((history_1.insertedElement instanceof CommentCharacterElementBox && history_1.action === 'RemoveInline')) {
operations.push(history_1.getCommentOperation(operation_6, 'InsertInline'));
}
else if (history_1.action === 'DeleteCommentWidget') {
operation_6 = this.getUpdateOperation();
operations.push(history_1.getCommentOperation(operation_6, 'InsertCommentWidget'));
}
else if (history_1.action === 'DeleteComment') {
history_1.getActionInfo();
}
}
}
else {
this.getDeleteCommentOperation(this.modifiedActions, operations);
}
break;
case 'FormField':
var currentHistory = this.modifiedActions.pop();
operations = currentHistory.getFieldOperation();
break;
case 'IMEInput':
if (isInvertOperation && (!(this.editorHistory.isUndoing || this.editorHistory.isRedoing))) {
if (this.modifiedActions[0].removedNodes.length > 0) {
var removeOperation = this.modifiedActions[0].getDeleteOperation('Delete');
removeOperation.length = removeOperation.text.length;
operations.push(removeOperation);
}
var insertOperation = this.modifiedActions[this.modifiedActions.length - 1].getInsertOperation('Insert');
insertOperation.length = insertOperation.text.length;
operations.push(insertOperation);
operations.reverse();
for (var i_12 = 0; i_12 < operations.length; i_12++) {
var operation_7 = operations[parseInt(i_12.toString(), 10)];
if (operation_7.action === 'Insert') {
operation_7.action = 'Delete';
}
else if (operation_7.action === 'Delete') {
operation_7.action = 'Insert';
}
}
}
else {
var currentHistory_10 = this.modifiedActions[this.modifiedActions.length - 1];
if (this.editorHistory.isUndoing || this.editorHistory.isRedoing) {
for (var i_13 = 0; i_13 < this.modifiedActions.length; i_13++) {
currentHistory_10 = this.modifiedActions[parseInt(i_13.toString(), 10)];
if (currentHistory_10.removedNodes.length > 0) {
operations.push(currentHistory_10.getDeleteOperation(action));
}
if (currentHistory_10.isRemovedNodes) {
var operationCollection = currentHistory_10.getDeleteContent('BackSpace');
operations = operations.concat(operationCollection);
}
currentHistory_10.isRemovedNodes = false;
}
}
else {
if (currentHistory_10.removedNodes.length > 0) {
operations.push(currentHistory_10.getDeleteOperation(action));
}
operations.push(currentHistory_10.getInsertOperation(this.action));
}
currentHistory_10.isRemovedNodes = false;
}
break;
case 'Accept All':
case 'ReplaceAll':
case 'Reject All':
var isSkip = false;
if (this.editorHistory.isUndoing || this.editorHistory.isRedoing) {
var currentHistory_11 = this.modifiedActions[this.modifiedActions.length - 1];
operations.push.apply(operations, currentHistory_11.cellOperation);
currentHistory_11.cellOperation = [];
if (currentHistory_11.isRemovedNodes) {
var operationCollection = currentHistory_11.getDeleteContent('Insert');
operations = operations.concat(operationCollection);
}
}
else {
for (var i_14 = 0; i_14 < this.modifiedActions.length; i_14++) {
var currentHistory_12 = this.modifiedActions[parseInt(i_14.toString(), 10)];
if (!isNullOrUndefined(currentHistory_12.cellOperation) && currentHistory_12.cellOperation.length > 0) {
operations.push(currentHistory_12.cellOperation[0]);
isSkip = true;
currentHistory_12.cellOperation = [];
}
else {
var operationsCollection = currentHistory_12.getActionInfo();
operations.push.apply(operations, operationsCollection);
}
}
}
// if (!isSkip && (action === 'Accept All' || action === 'Reject All')) {
// operations.reverse();
// }
break;
case 'Paste':
for (var i_15 = 0; i_15 < this.modifiedActions.length; i_15++) {
var currentHistory_13 = this.modifiedActions[parseInt(i_15.toString(), 10)];
currentHistory_13.type = this.type === 'PasteToc' ? this.type : 'Paste';
var pasteOperations = currentHistory_13.getActionInfo();
operations.push.apply(operations, pasteOperations);
}
break;
case 'TOC':
for (var i_16 = 0; i_16 < this.modifiedActions.length; i_16++) {
var currentHistory_14 = this.modifiedActions[parseInt(i_16.toString(), 10)];
currentHistory_14.type = currentHistory_14.action === 'Paste' ? 'PasteToc' : undefined;
var tocOperations = currentHistory_14.getActionInfo();
operations.push.apply(operations, tocOperations);
}
if (this.editorHistory.isUndoing) {
var lastelement = operations.pop();
operations.unshift(lastelement);
}
break;
case 'DragAndDropContent':
for (var i_17 = 0; i_17 < this.modifiedActions.length; i_17++) {
var currentHistory_15 = this.modifiedActions[parseInt(i_17.toString(), 10)];
currentHistory_15.type = currentHistory_15.action === 'Paste' ? 'Paste' : undefined;
var ddcOperations = currentHistory_15.getActionInfo();
operations.push.apply(operations, ddcOperations);
}
break;
case 'ClearFormat':
if (this.editorHistory.isUndoing) {
for (var i_18 = 0; i_18 < this.modifiedActions.length; i_18++) {
operations.push.apply(operations, this.modifiedActions[parseInt(i_18.toString(), 10)].modifiedFormatOperation);
this.modifiedActions[parseInt(i_18.toString(), 10)].modifiedFormatOperation = [];
}
}
else {
var clearHistory = this.modifiedActions[this.modifiedActions.length - 1];
var formatOperation = clearHistory.buildFormatOperation('ClearFormat', true);
operations = formatOperation.slice();
}
break;
case 'ApplyStyle':
var styleHistory = void 0;
var formatstyleOperation = [];
if (this.modifiedActions[0] instanceof HistoryInfo) {
var historyInfo = this.modifiedActions[0];
styleHistory = historyInfo.modifiedActions[0];
formatstyleOperation = styleHistory.buildFormatOperation('ClearFormat', true);
operations = formatstyleOperation.slice();
}
if (!(this.modifiedActions[this.modifiedActions.length - 1] instanceof HistoryInfo)) {
formatstyleOperation = this.modifiedActions[this.modifiedActions.length - 1].buildFormatOperation(action, true);
for (var i_19 = 0; i_19 < formatstyleOperation.length; i_19++) {
operations.push(formatstyleOperation[parseInt(i_19.toString(), 10)]);
}
}
break;
case 'TableMarginsSelection':
this.modifiedActions[this.modifiedActions.length - 1].createTableFormat(this.modifiedActions[this.modifiedActions.length - 1].action);
this.modifiedActions[this.modifiedActions.length - 1].type = 'TableFormat';
operations.push(this.modifiedActions[this.modifiedActions.length - 1].getFormatOperation());
break;
case 'BordersAndShading':
if (this.modifiedActions[0].action === 'TableFormat') {
this.modifiedActions[0].type = 'TableFormat';
this.modifiedActions[0].createTableFormat('BordersAndShading');
operations.push(this.modifiedActions[0].getFormatOperation());
}
else {
this.modifiedActions[0].createCellFormat('BordersAndShading');
this.modifiedActions[0].type = 'CellFormat';
operations = this.modifiedActions[0].getSelectedCellOperation('BordersAndShading', undefined, true, true, true);
}
break;
case 'AutoList':
for (var i_20 = 0; i_20 < this.modifiedActions.length; i_20++) {
var currentHistory_16 = this.modifiedActions[parseInt(i_20.toString(), 10)];
var autoListOperations = currentHistory_16.getActionInfo();
operations.push.apply(operations, autoListOperations);
}
break;
case 'TableProperties':
for (var i_21 = 0; i_21 < this.modifiedActions.length; i_21++) {
var tablePropHistory = this.modifiedActions[parseInt(i_21.toString(), 10)];
if (tablePropHistory.action === 'TableFormat') {
tablePropHistory.createTableFormat(tablePropHistory.action);
tablePropHistory.type = 'TableFormat';
operations.push(tablePropHistory.getFormatOperation());
}
else if (tablePropHistory.action === 'RowFormat') {
if (this.editorHistory.isUndoing || this.editorHistory.isRedoing && tablePropHistory.modifiedProperties.length > 1) {
operations = tablePropHistory.modifiedFormatOperation;
tablePropHistory.modifiedFormatOperation = [];
}
else {
tablePropHistory.createRowFormat(tablePropHistory.action);
tablePropHistory.type = 'RowFormat';
operations.push(tablePropHistory.getFormatOperation());
}
}
else if (tablePropHistory.action === 'CellFormat') {
tablePropHistory.createCellFormat(tablePropHistory.action);
tablePropHistory.type = 'CellFormat';
var cellProp = tablePropHistory.getSelectedCellOperation(tablePropHistory.action, false, false, false, true);
for (var i_22 = 0; i_22 < cellProp.length; i_22++) {
operations.push(cellProp[parseInt(i_22.toString(), 10)]);
}
}
}
break;
case 'CellMarginsSelection':
this.modifiedActions[this.modifiedActions.length - 1].createCellFormat('CellOptions');
this.modifiedActions[this.modifiedActions.length - 1].type = 'CellFormat';
operations = this.modifiedActions[this.modifiedActions.length - 1].getSelectedCellOperation('CellOptions', false, false, false, true).slice();
break;
}
return operations;
};
HistoryInfo.prototype.revert = function () {
this.editorHistory.currentHistoryInfo = this;
if (this.action === 'BordersAndShading') {
this.owner.editorModule.isBordersAndShadingDialog = true;
}
if (!isNullOrUndefined(this.modifiedActions)) {
if (this.editorHistory.isUndoing) {
var i = this.modifiedActions.length;
while (i > 0) {
var baseHistoryInfo = this.modifiedActions[i - 1];
baseHistoryInfo.revert();
i = i - 1;
}
}
else {
var i = 0;
while (i < this.modifiedActions.length) {
var baseHistoryInfo = this.modifiedActions[parseInt(i.toString(), 10)];
baseHistoryInfo.revert();
i = i + 1;
}
}
}
if (this.action === 'RestrictEditing') {
var user = this.editRangeStart.user !== '' ? this.editRangeStart.user : this.editRangeStart.group;
if (this.editorHistory.isUndoing) {
var index = this.owner.documentHelper.editRanges.get(user).indexOf(this.editRangeStart);
if (index !== -1) {
this.owner.documentHelper.editRanges.get(user).splice(index, 1);
}
}
else {
this.owner.editorModule.updateRangeCollection(this.editRangeStart, user);
}
this.owner.selectionModule.updateEditRangeCollection();
}
if (!this.isChildHistoryInfo) {
this.editorHistory.updateComplexHistory();
}
else {
this.editorHistory.updateComplexHistoryInternal();
}
};
HistoryInfo.prototype.destroy = function () {
if (!isNullOrUndefined(this.modifiedActions)) {
while (this.modifiedActions.length > 0) {
var baseHistoryInfo = this.modifiedActions[this.modifiedActions.length - 1];
baseHistoryInfo.destroy();
this.modifiedActions.splice(this.modifiedActions.indexOf(baseHistoryInfo), 1);
}
this.modifiedActions = undefined;
}
_super.prototype.destroy.call(this);
};
return HistoryInfo;
}(BaseHistoryInfo));
export { HistoryInfo };