1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 | 1×
1×
1×
1×
1×
1686×
1686×
1686×
1686×
1686×
1686×
236×
1686×
1686×
1582×
1181×
1181×
192×
989×
1686×
21×
1665×
5×
5×
3×
5×
2×
5×
5×
5×
5×
3×
1662×
366×
366×
366×
366×
366×
183×
183×
183×
2×
366×
364×
364×
364×
175×
364×
1296×
1041×
1041×
1041×
1040×
1040×
1040×
437×
1040×
1040×
1040×
999×
1040×
919×
919×
1040×
1040×
28×
1040×
8×
1032×
1032×
1662×
1658×
1×
910×
910×
1×
81×
81×
14×
14×
1×
1252×
1252×
1248×
1248×
1252×
1252×
1252×
54×
54×
4×
50×
1248×
1248×
1×
2092×
1×
2951×
1×
2186×
1×
2951×
2951×
66×
2885×
2866×
1×
16×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../base/constant", "../base/util", "./../../common/constant"], function (require, exports, ej2_base_1, CONSTANT, util_1, constant_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Formatter = (function () {
function Formatter() {
}
Formatter.prototype.process = function (self, args, event, value) {
var _this = this;
var selection = self.contentModule.getDocument().getSelection();
var range = (selection.rangeCount > 0) ? selection.getRangeAt(selection.rangeCount - 1) : null;
var saveSelection;
var newRange;
if (!ej2_base_1.isNullOrUndefined(value) && !ej2_base_1.isNullOrUndefined(value.selection)) {
newRange = value.selection.range;
}
var isKeyboardVideoInsert = (!ej2_base_1.isNullOrUndefined(value) && !ej2_base_1.isNullOrUndefined(value.cssClass) &&
value.cssClass !== 'e-video-inline');
if (self.editorMode === 'HTML') {
if (!ej2_base_1.isNullOrUndefined(args) && !isKeyboardVideoInsert) {
Eif (ej2_base_1.isNullOrUndefined(args.name) || (!ej2_base_1.isNullOrUndefined(args.name) && args.name !== 'showDialog')) {
if (newRange) {
saveSelection = this.editorManager.nodeSelection.save(newRange, self.contentModule.getDocument());
}
else {
saveSelection = this.editorManager.nodeSelection.save(range, self.contentModule.getDocument());
}
}
}
}
if (!ej2_base_1.isNullOrUndefined(args)
&& args.item.command
&& args.item.command !== 'Table'
&& args.item.command !== 'Actions'
&& args.item.command !== 'Links'
&& args.item.command !== 'Images'
&& args.item.command !== 'Files'
&& args.item.command !== 'Audios'
&& args.item.command !== 'Videos'
&& args.item.command !== 'EmojiPicker'
&& range
&& !(self.contentModule.getEditPanel().contains(this.getAncestorNode(range.commonAncestorContainer))
|| self.contentModule.getEditPanel() === range.commonAncestorContainer
|| self.contentModule.getPanel() === range.commonAncestorContainer)) {
return;
}
if (!ej2_base_1.isNullOrUndefined(args) && self.maxLength !== -1 && !ej2_base_1.isNullOrUndefined(args.item.command)) {
var currentInsertContentLength = 0;
if (args.item.command === 'Links') {
currentInsertContentLength = value.text.length === 0 ? value.url.length : value.text.length;
}
if (args.item.command === 'Images' || args.item.command === 'Videos' || args.item.command === 'Table' || args.item.command === 'Files') {
currentInsertContentLength = 1;
}
var currentLength = self.getText().trim().replace(/(\r\n|\n|\r|\t)/gm, '').replace(/\u200B/g, '').length;
var selectionLength = self.getSelection().length;
var totalLength = (currentLength - selectionLength) + currentInsertContentLength;
if (!(self.maxLength === -1 || totalLength <= self.maxLength)) {
return;
}
}
if (ej2_base_1.isNullOrUndefined(args)) {
var action_1 = event.action;
args = {};
var items = {
originalEvent: event, cancel: false,
requestType: action_1 || (event.key + 'Key'),
itemCollection: value
};
ej2_base_1.extend(args, args, items, true);
if (action_1 !== 'tab' && action_1 !== 'enter' && action_1 !== 'space' && action_1 !== 'escape') {
Iif (self.editorMode === 'Markdown' && action_1 === 'insert-table') {
value = {
'headingText': self.localeObj.getConstant('TableHeadingText'),
'colText': self.localeObj.getConstant('TableColText')
};
}
self.trigger(CONSTANT.actionBegin, args, function (actionBeginArgs) {
if (actionBeginArgs.cancel) {
Iif (action_1 === 'paste' || action_1 === 'cut' || action_1 === 'copy') {
event.preventDefault();
}
}
});
}
if (!args.cancel) {
var isTableModule = ej2_base_1.isNullOrUndefined(self.tableModule) ? true : self.tableModule ?
self.tableModule.ensureInsideTableList : false;
Eif ((event.which === 9 && isTableModule) || event.which !== 9) {
if (event.which === 13 && self.editorMode === 'HTML') {
value = {
'enterAction': self.enterKey
};
}
this.editorManager.observer.notify((event.type === 'keydown' ? constant_1.KEY_DOWN : constant_1.KEY_UP), {
event: event,
callBack: this.onSuccess.bind(this, self),
value: value,
enterAction: self.enterKey
});
}
}
}
else if (!ej2_base_1.isNullOrUndefined(args) && args.item.command && args.item.subCommand && ((args.item.command !== args.item.subCommand
&& args.item.command !== 'Font' && args.item.command !== 'Export')
|| ((args.item.subCommand === 'FontName' || args.item.subCommand === 'FontSize') && args.name === 'dropDownSelect')
|| ((args.item.subCommand === 'BackgroundColor' || args.item.subCommand === 'FontColor')
&& args.name === 'colorPickerChanged') || args.item.subCommand === 'FormatPainter' || args.item.subCommand === 'EmojiPicker')) {
ej2_base_1.extend(args, args, { requestType: args.item.subCommand, cancel: false, itemCollection: value, selectType: args.name }, true);
self.trigger(CONSTANT.actionBegin, args, function (actionBeginArgs) {
if (!actionBeginArgs.cancel) {
var formatPainterCopy = !ej2_base_1.isNullOrUndefined(actionBeginArgs.requestType) && actionBeginArgs.requestType === 'FormatPainter' && actionBeginArgs.name === 'format-copy';
var formatPainterPaste = !ej2_base_1.isNullOrUndefined(actionBeginArgs.requestType) && actionBeginArgs.requestType === 'FormatPainter' && actionBeginArgs.name === 'format-paste';
if ((_this.getUndoRedoStack().length === 0 && actionBeginArgs.item.command !== 'Links' && actionBeginArgs.item.command !== 'Images' && !formatPainterCopy)
|| formatPainterPaste) {
_this.saveData();
}
self.isBlur = false;
var quickToolbarAction = !ej2_base_1.isNullOrUndefined(event) && !ej2_base_1.isNullOrUndefined(event.target) && (!ej2_base_1.isNullOrUndefined(ej2_base_1.closest(event.target, '.e-rte-elements.e-dropdown-popup.e-rte-dropdown-popup.e-quick-dropdown.e-popup-open')) || !ej2_base_1.isNullOrUndefined(ej2_base_1.closest(event.target, '.e-rte-elements.e-rte-quick-popup.e-popup-open')));
if (ej2_base_1.isNullOrUndefined(saveSelection) || (!quickToolbarAction && (ej2_base_1.isNullOrUndefined(ej2_base_1.closest(saveSelection.range.startContainer.parentElement, '.e-img-caption')) ? true : !(ej2_base_1.closest(saveSelection.range.startContainer.parentElement, '.e-img-caption').getAttribute('contenteditable') === 'false'))) && !(ej2_base_1.Browser.userAgent.indexOf('Firefox') !== -1)) {
self.contentModule.getEditPanel().focus();
}
if (self.editorMode === 'HTML' && !isKeyboardVideoInsert) {
Eif (ej2_base_1.isNullOrUndefined(args.selectType) || (!ej2_base_1.isNullOrUndefined(args.selectType) && args.selectType !== 'showDialog')) {
saveSelection.restore();
}
}
var command = actionBeginArgs.item.subCommand.toLocaleLowerCase();
if (command === 'image') {
value = actionBeginArgs.itemCollection;
}
if (command === 'paste' || command === 'cut' || command === 'copy') {
self.clipboardAction(command, event);
}
else {
_this.editorManager.observer.notify(CONSTANT.checkUndo, { subCommand: actionBeginArgs.item.subCommand });
_this.editorManager.execCommand(actionBeginArgs.item.command, actionBeginArgs.item.subCommand, event, _this.onSuccess.bind(_this, self), actionBeginArgs.item.value, actionBeginArgs.item.subCommand === 'Pre' && actionBeginArgs.selectType === 'dropDownSelect' ?
{ name: actionBeginArgs.selectType } : value, ('#' + self.getID() + ' iframe'), self.enterKey);
}
}
});
}
if ((ej2_base_1.isNullOrUndefined(event) || event && event.action !== 'copy')) {
this.enableUndo(self);
}
};
Formatter.prototype.getAncestorNode = function (node) {
node = node.nodeType === 3 ? node.parentNode : node;
return node;
};
Formatter.prototype.onKeyHandler = function (self, e) {
var _this = this;
this.editorManager.observer.notify(constant_1.KEY_UP, {
event: e, callBack: function () {
self.notify(CONSTANT.contentChanged, {});
_this.enableUndo(self);
},
enterAction: self.enterKey
});
};
Formatter.prototype.onSuccess = function (self, events) {
self.notify(CONSTANT.contentChanged, {});
if (events && (ej2_base_1.isNullOrUndefined(events.event) || events.event.action !== 'copy')) {
this.enableUndo(self);
self.notify(CONSTANT.execCommandCallBack, events);
}
self.trigger(CONSTANT.actionComplete, events, function (callbackArgs) {
self.setPlaceHolder();
if ((callbackArgs.requestType === 'Images' || callbackArgs.requestType === 'Links' || callbackArgs.requestType === 'Audios' || callbackArgs.requestType === 'Videos') && self.editorMode === 'HTML') {
var args = callbackArgs;
if (callbackArgs.requestType === 'Links' && callbackArgs.event &&
callbackArgs.event.type === 'keydown' &&
callbackArgs.event.keyCode === 32) {
return;
}
self.notify(CONSTANT.insertCompleted, {
args: args.event, type: callbackArgs.requestType, isNotify: true,
elements: args.elements
});
}
Iif (callbackArgs.requestType === 'VideosPlayPause') {
self.notify('editAreaClick', { args: event });
}
self.autoResize();
});
};
Formatter.prototype.saveData = function (e) {
this.editorManager.undoRedoManager.saveData(e);
};
Formatter.prototype.getUndoStatus = function () {
return this.editorManager.undoRedoManager.getUndoStatus();
};
Formatter.prototype.getUndoRedoStack = function () {
return this.editorManager.undoRedoManager.undoRedoStack;
};
Formatter.prototype.enableUndo = function (self) {
var status = this.getUndoStatus();
if (self.inlineMode.enable && (!ej2_base_1.Browser.isDevice || util_1.isIDevice())) {
util_1.updateUndoRedoStatus(self.quickToolbarModule.inlineQTBar.quickTBarObj, status);
}
else {
if (self.toolbarModule && self.toolbarModule.baseToolbar) {
util_1.updateUndoRedoStatus(self.toolbarModule.baseToolbar, status);
}
}
};
Formatter.prototype.beforeSlashMenuApply = function () {
this.editorManager.beforeSlashMenuApplyFormat();
};
return Formatter;
}());
exports.Formatter = Formatter;
});
|