@syncfusion/ej2-documenteditor
Version:
Feature-rich document editor control with built-in support for context menu, options pane and dialogs.
1,168 lines • 352 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 __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
/* eslint-disable */
import { Dictionary } from '../../base/dictionary';
import { WAbstractList } from '../list/abstract-list';
import { WLevelOverride } from '../list/level-override';
import { WSectionFormat, WCharacterFormat, WParagraphFormat, WStyles, WColumnFormat } from '../format/index';
import { Layout } from './layout';
import { Renderer } from './render';
import { createElement, Browser, L10n, updateCSSText } from '@syncfusion/ej2-base';
import { Page, Rect, Widget, ListTextElementBox, FieldElementBox, ParagraphWidget, HeaderFooterWidget, Padding, DropDownFormField, TextFormField, CheckBoxFormField, ShapeElementBox, TextFrame, ContentControl, Footnote, FootnoteElementBox, FootNoteWidget, TextElementBox, ShapeBase, ImageElementBox } from './page';
import { BodyWidget, LineWidget, TableWidget, TableRowWidget, BookmarkElementBox } from './page';
import { HelperMethods, Point } from '../editor/editor-helper';
import { TextHelper } from './text-helper';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { CommentReviewPane } from '../index';
import { Zoom } from './zooming';
import { Dialog, createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-popups';
import { beforePaneSwitchEvent, keyDownEvent, beforeFormFieldFillEvent, afterFormFieldFillEvent } from '../../base/index';
import { RestrictEditing } from '../restrict-editing/restrict-editing-pane';
import { FormFieldPopUp } from '../dialogs/form-field-popup';
import { ContentControlPopUp } from '../dialogs/content-control-popup';
import { TrackChangesPane } from '../track-changes/track-changes-pane';
import { Themes } from '../themes/themes';
import { beforeAutoResize, internalAutoResize } from '../../base/constants';
import { incrementalOps } from '../../base/index';
/**
* @private
*/
var DocumentHelper = /** @class */ (function () {
//#endregion
function DocumentHelper(owner) {
var _this = this;
/**
* @private
*/
this.isCompleted = true;
/**
* @private
* To set the copied content to the clipboard. Reserved for internal use.
*/
this.isCopying = false;
/**
* @private
*/
this.isSelectionCompleted = true;
/**
* @private
*/
this.scrollbarWidth = 0;
/**
* @private
*/
this.isWebPrinting = false;
/**
* @private
*/
this.isHeaderFooter = false;
/**
* @private
*/
this.isSpellCheckPending = false;
/**
* @private
*/
this.currentPage = undefined;
this.selectionStartPageIn = undefined;
this.selectionEndPageIn = undefined;
/**
* @private
*/
this.fieldStacks = [];
/**
* @private
*/
this.showRevision = false;
/**
* @private
*/
this.splittedCellWidgets = [];
/**
* @private
*/
this.tableLefts = [];
/**
* @private
*/
this.tapCount = 0;
this.timer = -1;
this.isTimerStarted = false;
/**
* @private
*/
this.isFirstLineFitInShiftWidgets = false;
/**
* @private
*/
this.preZoomFactor = 0;
/**
* @private
*/
this.preDifference = -1;
/**
* @private
*/
this.isDragging = false;
/**
* @private
*/
this.fieldEndParagraph = undefined;
/**
* @private
*/
this.fieldToLayout = undefined;
/**
* @private
*/
this.backgroundColor = '#FFFFFF';
// Event
/**
* @private
*/
this.isMouseDown = false;
this.isMouseEntered = false;
this.scrollMoveTimer = 0;
/**
* @private
*/
this.isSelectionChangedOnMouseMoved = false;
/**
* @private
*/
this.isControlPressed = false;
/**
* @private
*/
this.isTouchInput = false;
/**
* @private
*/
this.isTouchMoved = false;
/**
* @private
*/
this.useTouchSelectionMark = false;
/**
* @private
*/
this.touchDownOnSelectionMark = 0;
/**
* @private
*/
this.isComposingIME = false;
/**
* @private
*/
this.lastComposedText = '';
/**
* @private
*/
this.isCompositionStart = false;
/**
* @private
*/
this.isCompositionUpdated = false;
/**
* @private
*/
this.isCompositionCanceled = false;
/**
* @private
*/
this.isCompositionEnd = false;
/**
* @private
*/
this.prefix = '';
/**
* @private
*/
this.suffix = '';
/**
* @private
*/
this.fields = [];
/**
* @private
*/
this.heightInfoCollection = {};
/**
* @private
*/
this.defaultTabWidth = 36;
/**
* @private
*/
this.dontUseHtmlParagraphAutoSpacing = false;
/**
* @private
*/
this.allowSpaceOfSameStyleInTable = false;
/**
* @private
*/
this.alignTablesRowByRow = false;
/**
* @private
*/
this.compatibilityMode = 'Word2013';
/**
* @private
*/
this.lists = [];
/**
* @private
*/
this.comments = [];
/**
* @private
*/
this.authors = new Dictionary();
/**
* @private
*/
this.revisionsInternal = new Dictionary();
/**
* @private
*/
this.commentUserOptionId = 1;
/**
* @private
*/
this.abstractLists = [];
/**
* @private
*/
this.styles = new WStyles();
/**
* @private
*/
this.stylesMap = new Dictionary();
/**
* @private
*/
this.preDefinedStyles = undefined;
/**
* @private
*/
this.isRowOrCellResizing = false;
/**
* @private
*/
this.endBookmarksUpdated = [];
/**
* @private
*/
this.formFields = [];
this.isMouseDownInFooterRegion = false;
this.pageFitTypeIn = 'None';
/**
* @private
*/
this.fieldCollection = [];
/**
* @private
*/
this.isPageField = false;
/**
* @private
*/
this.mouseDownOffset = new Point(0, 0);
this.zoomFactorInternal = 1;
/**
* If movecaretposition is 1, Home key is pressed
* If moveCaretPosition is 2, End key is pressed
*
* @private
*/
this.moveCaretPosition = 0;
/**
* @private
*/
this.isTextInput = false;
/**
* @private
*/
this.isScrollHandler = false;
/**
* @private
*/
this.triggerElementsOnLoading = false;
/**
* @private
*/
this.triggerSpellCheck = false;
//Document Protection Properties Starts
/**
* preserve the format
*
* @private
*/
this.restrictFormatting = false;
/**
* preserve the document protection type either readonly or no protection
*
* @private
*/
this.protectionType = 'NoProtection';
/**
* Preserve the password protection is enforced or not
*
* @private
*/
this.isDocumentProtected = false;
/**
* preserve the hash value of password
*
* @private
*/
this.hashValue = '';
/**
* @private
*/
this.saltValue = '';
/**
* @private
*/
this.userCollection = [];
/**
* @private
*/
this.cachedPages = [];
/**
* @private
*/
this.skipScrollToPosition = false;
/**
* @private
*/
this.isIosDevice = false;
/**
* @private
*/
this.isMobileDevice = false;
/**
* @private
*/
this.isLinuxOS = false;
/**
* @private
*/
this.isFormFilling = false;
/**
* @private
*/
this.fontSubstitutionTable = undefined;
/**
* @private
*/
this.themes = new Themes();
/**
* @private
*/
this.hasThemes = false;
/**
* @private
*/
this.footnotes = new Footnote();
/**
* @private
*/
this.endnotes = new Footnote();
/**
* @private
*/
this.isFootnoteWidget = false;
/**
* @private
*/
this.isDragStarted = false;
/**
* @private
*/
this.isMouseDownInSelection = false;
/**
* @private
*/
this.isSelectionActive = false;
/**
* @private
*/
this.isBookmarkInserted = true;
this.isMappedContentControlUpdated = true;
this.isAutoResizeCanStart = false;
this.isRestartNumbering = false;
this.isKeySelection = false;
/**
* @private
* Indicates whether the composition end event has been triggered.
*/
this.isCompositionEndTriggered = false;
/**
* @private
* @param {TextEvent} event - Specifies text event.
* @returns {void}
*/
this.onTextInput = function (event) {
if (!_this.isComposingIME && !_this.isCompositionEndTriggered) {
event.preventDefault();
var text = event.data;
_this.owner.editorModule.handleTextInput(text);
}
};
//#region Composition Event
/**
* Fires when composition starts.
*
* @private
* @returns {void}
*/
this.compositionStart = function () {
if (!Browser.isDevice && !_this.owner.isReadOnlyMode) {
_this.isComposingIME = true;
_this.positionEditableTarget();
if (_this.owner.editorHistoryModule) {
_this.owner.editorModule.initComplexHistory('IMEInput');
}
if (_this.editableDiv && _this.editableDiv.innerHTML != "") {
_this.editableDiv.innerHTML = "";
}
}
_this.isCompositionStart = true;
_this.isCompositionEndTriggered = false;
};
/**
* Fires on every input during composition.
*
* @private
* @returns {void}
*/
this.compositionUpdated = function () {
if (_this.isComposingIME && !_this.owner.isReadOnlyMode) {
setTimeout(function () {
_this.owner.editorModule.insertIMEText(_this.getEditableDivTextContent(), true);
}, 0);
}
_this.isCompositionUpdated = true;
};
/**
* Fires when user selects a character/word and finalizes the input.
*
* @private
* @param {CompositionEvent} event - Specifies text compisition event.
* @returns {void}
*/
this.compositionEnd = function (event) {
if (_this.isComposingIME && !_this.owner.isReadOnlyMode) {
_this.isCompositionEndTriggered = true;
var text = _this.getEditableDivTextContent();
if (text !== '') {
_this.owner.editorModule.insertIMEText(text, false);
}
_this.isComposingIME = false;
_this.lastComposedText = '';
var cssText = 'pointer-events:none;position:absolute;left:' + _this.owner.viewer.containerLeft + 'px;top:' + _this.owner.viewer.containerTop + 'px;outline:none;background-color:transparent;width:0px;height:0px;overflow:hidden';
updateCSSText(_this.iframe, cssText);
_this.editableDiv.innerHTML = '';
if (_this.owner.editorHistoryModule) {
if (text !== '') {
_this.owner.editorModule.isSkipOperationsBuild = _this.owner.enableCollaborativeEditing;
}
_this.owner.editorHistoryModule.updateComplexHistory();
if (text === '') {
//When the composition in live. The Undo operation will terminate the composition and empty text will be return from text box.
//At that time the the history should be updated. Undo the operation and clear the redo stack. This undo operation will not be saved for redo operation.
_this.owner.editorModule.isSkipOperationsBuild = _this.owner.enableCollaborativeEditing;
_this.owner.editorHistoryModule.undo();
_this.owner.editorHistoryModule.redoStack.pop();
}
_this.owner.editorModule.isSkipOperationsBuild = false;
}
}
event.preventDefault();
_this.isCompositionUpdated = false;
_this.isCompositionEnd = true;
};
/* eslint-disable @typescript-eslint/no-explicit-any */
this.onImageResizer = function (args) {
if (!isNullOrUndefined(_this.owner) && !isNullOrUndefined(_this.owner.imageResizerModule) &&
_this.owner.imageResizerModule.isImageResizerVisible && _this.owner.imageResizerModule.isImageResizing) {
if (args instanceof MouseEvent) {
_this.onMouseUpInternal(args);
}
else if (args instanceof TouchEvent) {
_this.onTouchUpInternal(args);
}
}
if (_this.scrollMoveTimer) {
_this.isMouseEntered = true;
if (_this.isMouseDown) {
_this.isSelectionActive = false;
_this.owner.fireSelectionChange();
}
clearInterval(_this.scrollMoveTimer);
}
};
/* eslint-enable @typescript-eslint/no-explicit-any */
/**
* @private
* @param {KeyboardEvent} event - Specifies keyboard event
* @returns {void}
*/
this.onKeyPressInternal = function (event) {
var key = event.which || event.keyCode;
_this.triggerElementsOnLoading = false;
var ctrl = (event.ctrlKey || event.metaKey) ? true : ((key === 17) ? true : false); // ctrl detection
var alt = event.altKey ? event.altKey : ((key === 18) ? true : false); // alt key detection
if (Browser.isIE && alt && ctrl) {
ctrl = false;
}
// tslint:disable-next-line:max-line-length
if (ctrl && event.key === 'v' || ctrl && event.key === 'a' || (ctrl || (_this.isControlPressed && Browser.isIE)) && event.key === 'p') {
if (Browser.isIE) {
_this.isControlPressed = false;
}
return;
}
if (!_this.owner.isReadOnlyMode && _this.owner.editorModule.canEditContentControl || (_this.owner.documentHelper.protectionType === 'FormFieldsOnly' && _this.owner.editorModule.canEditContentControl && !isNullOrUndefined(_this.owner.documentHelper.selection) && _this.owner.documentHelper.selection.checkContentControlLocked()) || (!isNullOrUndefined(_this.selection) && _this.selection.isInlineFormFillMode())) {
var key_1 = event.keyCode || event.charCode;
var char = '';
if (key_1) {
char = String.fromCharCode(key_1);
}
else if (event.key) {
char = event.key;
}
if (char !== ' ' && char !== '\r' && char !== '\b' && char !== String.fromCharCode(27) && !ctrl) {
_this.triggerSpellCheck = false;
_this.isSpellCheckPending = true;
_this.owner.editorModule.handleTextInput(char);
}
else if (char === ' ') {
_this.isSpellCheckPending = false;
_this.triggerSpellCheck = true;
_this.owner.editorModule.handleTextInput(' ');
_this.triggerSpellCheck = false;
}
event.preventDefault();
}
_this.owner.focusIn();
};
/**
* @private
* @param {KeyboardEvent} event - Specifies keyboard event
* @returns {void}
*/
this.onTextInputInternal = function (event) {
if (!_this.owner.isReadOnlyMode) {
_this.owner.editorModule.onTextInputInternal();
}
else {
_this.editableDiv.innerText = '';
}
};
/**
* Fired on copy.
*
* @private
* @param {ClipboardEvent} event - Specifies clipboard event.
* @returns {void}
*/
this.onCopy = function (event) {
if (_this.isCopying && !isNullOrUndefined(_this.selection) && !_this.selection.isEmpty) {
_this.owner.selection.onCopy(event);
event.preventDefault();
}
};
/**
* Fired on paste.
*
* @private
* @param {ClipboardEvent} event - Specifies clipboard event.
* @returns {void}
*/
this.onPaste = function (event) {
if ((!_this.owner.isReadOnlyMode && _this.owner.editorModule.canEditContentControl) || _this.selection.isInlineFormFillMode()) {
_this.owner.editorModule.pasteInternal(event);
}
_this.editableDiv.innerText = '';
event.preventDefault();
};
/**
* Fires when editable div loses focus.
*
* @private
* @returns {void}
*/
this.onFocusOut = function () {
if (!isNullOrUndefined(_this.selection)) {
if (_this.owner.contextMenuModule && _this.owner.contextMenuModule.contextMenuInstance &&
_this.owner.contextMenuModule.contextMenuInstance.element.style.display === 'block') {
return;
}
_this.selection.hideCaret();
}
};
/**
* Updates focus to editor area.
*
* @private
* @returns {void}
*/
this.updateFocus = function () {
if (_this.owner.enableCollaborativeEditing && _this.owner.editorModule.isRemoteAction) {
return;
}
if (!isNullOrUndefined(_this.currentSelectedComment) && !_this.owner.commentReviewPane.commentPane.isEditMode) {
if (_this.owner.commentReviewPane && _this.owner.commentReviewPane.commentPane.isEditMode) {
_this.owner.commentReviewPane.commentPane.selectComment(_this.currentSelectedComment);
}
_this.selection.hideCaret();
return;
}
if (_this.selection && !(_this.isMobileDevice && _this.owner.isReadOnly)) {
if (navigator !== undefined && !Browser.isDevice && !Browser.isIE && !navigator.userAgent.match('Edge')
&& !isNullOrUndefined(_this.iframe)) {
_this.iframe.focus();
}
if (!isNullOrUndefined(_this.editableDiv)) {
_this.editableDiv.focus();
}
_this.selection.showCaret();
}
};
/**
* Fires on scrolling.
*
* @returns {void}
*/
this.scrollHandler = function () {
if (_this.scrollTimer) {
clearTimeout(_this.scrollTimer);
}
_this.clearContent();
_this.isScrollHandler = true;
if (!Browser.isDevice && !_this.isComposingIME) {
_this.iframe.style.top = _this.owner.viewer.containerTop + 'px';
_this.iframe.style.left = _this.owner.viewer.containerLeft + 'px';
}
if (_this.owner.hRuler) {
_this.hRuler = document.getElementById(_this.owner.element.id + ('_hRulerBottom'));
_this.hRuler.style.top = _this.viewerContainer.scrollTop + 'px';
_this.markIndicator = document.getElementById(_this.owner.element.id + ('_markIndicator'));
if (_this.markIndicator) {
_this.markIndicator.style.top = _this.viewerContainer.scrollTop + 'px';
}
}
if (_this.owner.vRuler) {
_this.vRuler = document.getElementById(_this.owner.element.id + ('_vRulerBottom'));
_this.vRuler.style.left = _this.viewerContainer.scrollLeft + 'px';
_this.markIndicator = document.getElementById(_this.owner.element.id + ('_markIndicator'));
if (_this.markIndicator) {
_this.markIndicator.style.left = _this.viewerContainer.scrollLeft + 'px';
}
}
if (_this.owner.rulerHelper && !isNullOrUndefined(_this.owner.rulerHelper.vRulerBottom)) {
_this.owner.rulerHelper.vRulerBottom.style.height = _this.pageContainer.offsetHeight + 'px';
}
_this.owner.viewer.updateScrollBars();
var vtHeight = _this.owner.viewer.containerTop + _this.visibleBounds.height - (_this.owner.viewer.padding.top + _this.owner.viewer.padding.bottom);
if (vtHeight > _this.pageContainer.offsetHeight) {
_this.viewerContainer.scrollTop = _this.owner.viewer.containerTop - (vtHeight - _this.pageContainer.offsetHeight);
}
if (!isNullOrUndefined(_this.owner) && _this.owner.viewer instanceof PageLayoutViewer) {
_this.owner.fireViewChange();
}
_this.isScrollHandler = false;
_this.scrollTimer = setTimeout(function () {
if (!_this.isScrollHandler && !isNullOrUndefined(_this.owner) && _this.owner.isSpellCheck) {
_this.isScrollToSpellCheck = true;
_this.owner.viewer.updateScrollBars();
}
}, 200);
};
/**
* Fires when the window gets resized.
*
* @private
* @returns {void}
*/
this.onWindowResize = function () {
if (!isNullOrUndefined(_this.owner) && _this.owner.isContainerResize) {
_this.owner.isContainerResize = false;
return;
}
if (_this.resizeTimer) {
clearTimeout(_this.resizeTimer);
}
_this.resizeTimer = setTimeout(function () {
if (!isNullOrUndefined(_this.owner) && !isNullOrUndefined(_this.owner.element)) {
_this.updateViewerSize();
if (_this.owner.rulerHelper && _this.owner.documentEditorSettings && _this.owner.documentEditorSettings.showRuler) {
_this.owner.rulerHelper.updateRuler(_this.owner, true);
}
if (_this.owner.enableCollaborativeEditing && _this.owner.collaborativeEditingHandlerModule) {
_this.owner.collaborativeEditingHandlerModule.updateCaretPosition();
}
_this.clearContent();
_this.owner.viewer.updateScrollBars();
if (!isNullOrUndefined(_this.selection)) {
_this.selection.updateCaretPosition();
}
_this.updateTouchMarkPosition();
if (_this.owner.contextMenuModule && _this.owner.contextMenuModule.contextMenuInstance) {
_this.owner.contextMenuModule.contextMenuInstance.close();
}
if (_this.resizeTimer) {
clearTimeout(_this.resizeTimer);
}
}
}, 200);
};
/**
* @private
* @param {MouseEvent} event - Specified mouse event.
* @returns {void}
*/
this.onContextMenu = function (event) {
if (_this.owner.contextMenuModule) {
if (_this.isMouseDown) {
_this.isMouseDown = false;
}
_this.owner.contextMenuModule.onContextMenuInternal(event);
_this.updateFocus();
}
};
/**
* Called on mouse down.
*
* @private
* @param {MouseEvent} event - Specifies mouse event.
* @returns {void}
*/
this.onMouseDownInternal = function (event) {
var target = event.target;
_this.owner.focusIn();
if ((!isNullOrUndefined(target) && target !== _this.viewerContainer) || _this.owner.isTableMarkerDragging || _this.isTouchInput ||
event.offsetX > (_this.visibleBounds.width - (_this.visibleBounds.width - _this.viewerContainer.clientWidth))
|| event.offsetY > (_this.visibleBounds.height - (_this.visibleBounds.height - _this.viewerContainer.clientHeight))) {
return;
}
_this.isFootnoteWidget = false;
if (!isNullOrUndefined(_this.selection)) {
_this.updateCursor(event);
if (_this.formFillPopup) {
_this.formFillPopup.hidePopup();
}
if (_this.contentDropDown) {
_this.contentDropDown.hidePopup();
}
if (_this.isLeftButtonPressed(event) && !_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode && !isNullOrUndefined(_this.owner.imageResizerModule.selectedResizeElement)) {
if (_this.selection.isInShape) {
var textFram = _this.owner.selectionModule.getCurrentTextFrame();
var shape = textFram.containerShape;
_this.selection.selectShape(shape);
}
_this.owner.imageResizerModule.isImageResizing = true;
}
event.preventDefault();
if (!_this.isTouchInput) {
_this.selection.hideCaret();
}
var cursorPoint = new Point(event.offsetX, event.offsetY);
var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true, true);
_this.mouseDownOffset.x = touchPoint.x;
_this.mouseDownOffset.y = touchPoint.y;
_this.isMouseDownInFooterRegion = _this.selection.isCursorInsidePageRect(cursorPoint, _this.currentPage) && _this.selection.isCursorInFooterRegion(cursorPoint, _this.currentPage);
_this.isSelectionChangedOnMouseMoved = false;
if (!_this.owner.isReadOnlyMode && (_this.owner.editorModule.tableResize.isInCellResizerArea(touchPoint) ||
_this.owner.editorModule.tableResize.isInRowResizerArea(touchPoint))) {
_this.selection.hideCaret();
_this.isMouseDown = true;
_this.isSelectionChangedOnMouseMoved = false;
if (_this.isLeftButtonPressed(event)) {
_this.owner.editorModule.tableResize.startingPoint.x = touchPoint.x;
_this.owner.editorModule.tableResize.startingPoint.y = touchPoint.y;
_this.owner.editorModule.tableResize.handleResize(touchPoint);
}
return;
}
if (event.ctrlKey) {
_this.isControlPressed = true;
}
if (_this.owner.selectionModule.isEmpty) {
_this.useTouchSelectionMark = false;
}
var widget = _this.getLineWidget(touchPoint);
if (event.which === 3 && !_this.owner.selectionModule.isEmpty
&& _this.selection.checkCursorIsInSelection(widget, touchPoint)) {
event.preventDefault();
return;
}
if (_this.owner && _this.owner.documentEditorSettings && _this.owner.documentEditorSettings.allowDragAndDrop &&
!_this.owner.selectionModule.isEmpty
&& _this.selection.checkCursorIsInSelection(widget, touchPoint)) {
_this.isMouseDownInSelection = true;
}
_this.isTouchInput = false;
_this.isMouseDown = true;
_this.updateFocus();
/* eslint-disable @typescript-eslint/indent */
_this.timer = setTimeout(function () {
_this.tapCount++;
if (_this.tapCount > 1) {
_this.tapCount = 1;
}
if (!_this.isScrollHandler && !isNullOrUndefined(_this.owner) && _this.owner.isSpellCheck) {
_this.isScrollToSpellCheck = true;
_this.owner.viewer.updateScrollBars();
}
}, 100);
}
};
/**
* Called on mouse move.
*
* @private
* @param {MouseEvent} event - Specified mouse event.
* @returns {void}
*/
this.onMouseMoveInternal = function (event) {
if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer || _this.owner.isTableMarkerDragging) {
return;
}
event.preventDefault();
if (!isNullOrUndefined(_this.selection)) {
//For image Resizing
if (!_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode
&& _this.owner.imageResizerModule.isImageResizing) {
if (!_this.owner.imageResizerModule.isImageMoveToNextPage) {
_this.owner.imageResizerModule.handleImageResizingOnMouse(event);
}
return;
}
var cursorPoint = new Point(event.offsetX, event.offsetY);
var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, !_this.owner.enableHeaderAndFooter);
var widget = _this.getLineWidget(touchPoint);
if (_this.isMouseDown) {
if (!isNullOrUndefined(_this.currentPage)) {
var xPosition = touchPoint.x;
var yPosition = touchPoint.y;
if (!_this.owner.isReadOnlyMode && _this.isRowOrCellResizing) {
var table = _this.owner.editorModule.tableResize.currentResizingTable;
var startPosition = _this.selection.setPositionForBlock(table, true);
var endPosition = _this.selection.setPositionForBlock(table, false);
if (!(_this.owner.documentHelper.isDocumentProtected) || _this.selection.checkSelectionIsAtEditRegion(startPosition, endPosition)) {
_this.owner.editorModule.tableResize.handleResizing(touchPoint);
}
}
else {
if ((!_this.isDragStarted
&& _this.isMouseDownInSelection
&& _this.isLeftButtonPressed(event)
&& !_this.owner.selectionModule.isEmpty
&& _this.selection.checkCursorIsInSelection(widget, touchPoint)) || (!_this.owner.isReadOnlyMode && _this.owner.enableImageResizerMode && !_this.isDragStarted && _this.isLeftButtonPressed(event) && !_this.owner.selectionModule.isEmpty && !isNullOrUndefined(widget) && _this.owner.imageResizerModule.selectedImageWidget.containsKey(widget) && !_this.owner.imageResizerModule.isImageResizing)) {
_this.isDragStarted = true;
_this.isMouseDownInSelection = false;
if (_this.selection.isForward) {
_this.dragStartParaInfo = _this.selection.getParagraphInfo(_this.selection.start);
_this.dragEndParaInfo = _this.selection.getParagraphInfo(_this.selection.end);
}
else {
_this.dragStartParaInfo = _this.selection.getParagraphInfo(_this.selection.end);
_this.dragEndParaInfo = _this.selection.getParagraphInfo(_this.selection.start);
}
_this.selection.caret.classList.remove("e-de-cursor-animation");
}
if (!(_this.isTouchInput || _this.isSelectionChangedOnMouseMoved || _this.touchDownOnSelectionMark > 0 || _this.isDragStarted)) {
_this.updateTextPositionForSelection(touchPoint, 1);
if (!isNullOrUndefined(_this.currentSelectedComment) && _this.owner.commentReviewPane
&& !_this.owner.commentReviewPane.commentPane.isEditMode) {
_this.currentSelectedComment = undefined;
}
}
if (_this.isLeftButtonPressed(event) && !_this.isDragStarted) {
event.preventDefault();
var touchY = yPosition;
var textPosition = _this.owner.selectionModule.end;
var touchPoint_1 = new Point(xPosition, touchY);
if (!_this.owner.enableImageResizerMode || !_this.owner.imageResizerModule.isImageResizerVisible
|| _this.owner.imageResizerModule.isShapeResize) {
_this.isSelectionActive = true;
_this.isCompleted = false;
_this.owner.selectionModule.moveTextPosition(touchPoint_1, textPosition);
}
_this.isSelectionChangedOnMouseMoved = true;
}
if (_this.isDragStarted && _this.isLeftButtonPressed(event)) {
_this.autoScrollOnSelection(cursorPoint);
_this.selection.updateTextPosition(widget, touchPoint);
}
}
}
_this.selection.checkForCursorVisibility();
}
if (!_this.isRowOrCellResizing && !_this.isSelectionChangedOnMouseMoved) {
_this.updateCursor(event);
}
if (_this.isRowOrCellResizing) {
_this.selection.hideCaret();
}
}
};
/**
* @private
* @param {MouseEvent} event - Specifies mouse event
* @returns {void}
*/
this.onMouseLeaveInternal = function (event) {
event.preventDefault();
var cursorPoint = new Point(event.offsetX, event.offsetY);
if (_this.isMouseDown) {
var viewerTop = _this.viewerContainer.scrollTop;
clearInterval(_this.scrollMoveTimer);
if (event.offsetY + viewerTop > viewerTop) {
_this.scrollMoveTimer = setInterval(function () {
_this.isCompleted = false;
_this.scrollForwardOnSelection(cursorPoint);
}, 100);
}
else {
_this.scrollMoveTimer = setInterval(function () {
_this.isCompleted = false;
_this.scrollBackwardOnSelection(cursorPoint);
}, 100);
}
if (_this.isMouseEntered) {
_this.isMouseEntered = false;
}
}
if (_this.isDragStarted) {
_this.selection.hideCaret();
if (_this.scrollMoveTimer) {
clearInterval(_this.scrollMoveTimer);
_this.scrollMoveTimer = 0;
}
}
};
/**
* @private
* @returns {void}
*/
this.onMouseEnterInternal = function (event) {
if (!_this.isMouseEntered) {
_this.owner.viewer.updateScrollBars();
}
_this.isMouseEntered = true;
if (_this.scrollMoveTimer) {
clearInterval(_this.scrollMoveTimer);
}
if (!_this.isLeftButtonPressed(event) && _this.isDragStarted) {
if (!_this.selection.caret.classList.contains("e-de-cursor-animation")) {
_this.selection.caret.classList.add("e-de-cursor-animation");
}
_this.isDragStarted = false;
}
if (!_this.isLeftButtonPressed(event) && _this.isMouseDown) {
_this.onMouseUpInternal(event);
}
};
/**
* Fired on double tap.
*
* @private
* @param {MouseEvent} event - Specifies mouse event.
* @returns {void}
*/
this.onDoubleTap = function (event) {
_this.owner.focusIn();
if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer) {
return;
}
if (!isNullOrUndefined(_this.selection)) {
_this.isTouchInput = false;
var cursorPoint = new Point(event.offsetX, event.offsetY);
var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true);
if (_this.selection.checkAndEnableHeaderFooter(cursorPoint, _this.owner.viewer.findFocusedPage(cursorPoint, true))) {
return;
}
var widget = _this.getLineWidget(touchPoint);
if (isNullOrUndefined(widget)) {
return;
}
var formField = _this.selection.getHyperLinkFieldInCurrentSelection(widget, touchPoint, true);
if (isNullOrUndefined(formField)) {
formField = _this.selection.getCurrentFormField();
}
if (!_this.isDocumentProtected && _this.owner.enableFormField && !_this.owner.isReadOnlyMode) {
var formatType = _this.selection.getFormFieldType(formField);
if (formatType) {
if (formatType.toString() !== '') {
_this.selection.selectField(formField);
}
switch (formatType) {
case 'Text':
_this.owner.textFormFieldDialogModule.show();
break;
case 'CheckBox':
_this.owner.checkBoxFormFieldDialogModule.show();
break;
case 'DropDown':
_this.owner.dropDownFormFieldDialogModule.show();
break;
}
}
}
else if (_this.isDocumentProtected && formField && formField.formFieldData instanceof TextFormField
&& formField.formFieldData.type === 'Text') {
_this.selection.selectField();
}
var startPosition = _this.selection.start.clone();
var endPosition = _this.selection.end.clone();
var inlineObj = startPosition.currentWidget.getInline(startPosition.offset, 0);
var inline = inlineObj.element;
if (_this.owner.layoutType === 'Pages') {
if (inline instanceof FootnoteElementBox) {
if (inline.footnoteType === 'Footnote') {
var footnotes = _this.currentPage.footnoteWidget;
var i = void 0;
for (i = 0; i <= footnotes.bodyWidgets.length; i++) {
var footnoteText = (footnotes.bodyWidgets[i]).footNoteReference;
if (inline.text === footnoteText.text) {
break;
}
}
startPosition.setPositionParagraph(footnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0);
endPosition.setPositionParagraph(footnotes.bodyWidgets[i].childWidgets[0].childWidgets[0], 0);
_this.selection.selectRange(startPosition, endPosition);
}
else {
_this.navigateToEndNote(inline, startPosition, endPosition);
}
}
else {
if (inline instanceof TextElementBox && (_this.selection.isinEndnote || _this.selection.isinFootnote)) {
_this.selection.footnoteReferenceElement(startPosition, endPosition, inline);
}
}
}
if (_this.selection.isEmpty && !isNullOrUndefined(_this.currentPage) && !isNullOrUndefined(_this.owner.selectionModule.start)) {
_this.owner.selectionModule.selectCurrentWord();
_this.selection.checkForCursorVisibility();
_this.tapCount = 2;
}
}
};
/**
* Called on mouse up.
*
* @private
* @param {MouseEvent} event - Specifies mouse event.
* @return {void}
*/
/* eslint-disable */
this.onMouseUpInternal = function (event) {
if (!isNullOrUndefined(event.target) && event.target !== _this.viewerContainer || _this.owner.isTableMarkerDragging) {
return;
}
event.preventDefault();
_this.isListTextSelected = false;
var cursorPoint = new Point(event.offsetX, event.offsetY);
var touchPoint = _this.owner.viewer.findFocusedPage(cursorPoint, true);
if (!isNullOrUndefined(_this.selection)) {
var tapCount = 1;
if (!Browser.isIE) {
if (event.detail > 2) {
tapCount = event.detail;
}
}
else {
tapCount = _this.tapCount;
}
if (_this.isRowOrCellResizing) {
_this.owner.editorModule.tableResize.updateResizingHistory(touchPoint);
}
if (!isNullOrUndefined(_this.owner.editor) && _this.selection.checkContentControlLocked()) {
_this.owner.editorModule.insertContentControlPlaceholder();
}
if (_this.isMouseDown && !_this.isSelectionChangedOnMouseMoved
&& !isNullOrUndefined(_this.currentPage) && !isNullOrUndefined(_this.owner.selectionModule.start)
&& (!_this.owner.enableImageResizerMode || !_this.owner.imageResizerModule.isImageResizing)) {
if (_this.touchDownOnSelectionMark === 0 && !_this.isRowOrCellResizing) {
var isShiftKeyPressed = event.shiftKey;
if (isShiftKeyPressed) {
var textPosition = _this.owner.selectionModule.end;
_this.owner.selectionModule.moveTextPosition(touchPoint, textPosition);
}
else {
_this.updateTextPositionForSelection(touchPoint, tapCount);
// to check whether the image is selected
if (_this.owner.selectionModule.isImageSelected) {
var contentControlImage = _this.owner.getImageContentControl();
// to check whether selected image has content control and type as picture , then the dialog opens
if (contentControlImage instanceof ContentControl) {
if (contentControlImage.contentControlProperties.type == 'Picture') {
var picturePositionY = _this.owner.picturePositionY;
_this.owner.renderPictureContentControlElement(_this.owner, true, false, picturePositionY);
}
}
}
else {
_this.owner.renderPictureContentControlElement(_this.owner, false, false);
}
}
if (Browser.isIE && tapCount === 2) {
_this.selection.checkAndEnableHeaderFooter(cursorPoint, touchPoint);
}
}
_this.selection.checkForCursorVisibility();
if (!isNullOrUndefined(_this.currentSelectedComment) && _this.owner.commentReviewPane
&& !_this.owner.commentReviewPane.commentPane.isEditMode) {
_this.currentSelectedComment = u