@syncfusion/ej2-richtexteditor 20.4.53 → 21.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -2
- package/dist/ej2-richtexteditor.min.js +2 -2
- package/dist/ej2-richtexteditor.umd.min.js +2 -2
- package/dist/ej2-richtexteditor.umd.min.js.map +1 -1
- package/dist/es6/ej2-richtexteditor.es2015.js +1479 -576
- package/dist/es6/ej2-richtexteditor.es2015.js.map +1 -1
- package/dist/es6/ej2-richtexteditor.es5.js +1516 -605
- package/dist/es6/ej2-richtexteditor.es5.js.map +1 -1
- package/dist/global/ej2-richtexteditor.min.js +2 -2
- package/dist/global/ej2-richtexteditor.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/package.json +13 -13
- package/src/common/config.js +3 -1
- package/src/common/constant.d.ts +6 -0
- package/src/common/constant.js +6 -0
- package/src/common/util.d.ts +1 -0
- package/src/common/util.js +1 -0
- package/src/editor-manager/base/editor-manager.d.ts +2 -0
- package/src/editor-manager/base/editor-manager.js +5 -0
- package/src/editor-manager/base/enum.d.ts +14 -0
- package/src/editor-manager/base/interface.d.ts +34 -0
- package/src/editor-manager/plugin/clearformat.js +13 -4
- package/src/editor-manager/plugin/format-painter-actions.d.ts +63 -0
- package/src/editor-manager/plugin/format-painter-actions.js +474 -0
- package/src/editor-manager/plugin/image.js +0 -1
- package/src/editor-manager/plugin/inserthtml.js +4 -2
- package/src/editor-manager/plugin/isformatted.js +1 -0
- package/src/editor-manager/plugin/link.js +0 -1
- package/src/editor-manager/plugin/lists.js +1 -1
- package/src/editor-manager/plugin/ms-word-clean-up.js +4 -4
- package/src/editor-manager/plugin/selection-commands.d.ts +4 -1
- package/src/editor-manager/plugin/selection-commands.js +70 -9
- package/src/editor-manager/plugin/video.js +2 -0
- package/src/editor-manager/plugin.d.ts +1 -0
- package/src/editor-manager/plugin.js +1 -0
- package/src/global.js +1 -1
- package/src/rich-text-editor/actions/base-quick-toolbar.d.ts +1 -0
- package/src/rich-text-editor/actions/base-quick-toolbar.js +21 -1
- package/src/rich-text-editor/actions/base-toolbar.js +33 -10
- package/src/rich-text-editor/actions/enter-key.js +5 -10
- package/src/rich-text-editor/actions/format-painter.d.ts +24 -0
- package/src/rich-text-editor/actions/format-painter.js +142 -0
- package/src/rich-text-editor/actions/full-screen.js +0 -1
- package/src/rich-text-editor/actions/html-editor.d.ts +1 -0
- package/src/rich-text-editor/actions/html-editor.js +117 -97
- package/src/rich-text-editor/actions/toolbar.js +5 -0
- package/src/rich-text-editor/actions.d.ts +1 -0
- package/src/rich-text-editor/actions.js +1 -0
- package/src/rich-text-editor/base/constant.d.ts +10 -0
- package/src/rich-text-editor/base/constant.js +10 -0
- package/src/rich-text-editor/base/enum.d.ts +4 -0
- package/src/rich-text-editor/base/interface.d.ts +30 -3
- package/src/rich-text-editor/base/interface.js +12 -0
- package/src/rich-text-editor/base/rich-text-editor-model.d.ts +30 -4
- package/src/rich-text-editor/base/rich-text-editor.d.ts +35 -5
- package/src/rich-text-editor/base/rich-text-editor.js +40 -9
- package/src/rich-text-editor/base/util.js +2 -0
- package/src/rich-text-editor/formatter/formatter.js +22 -13
- package/src/rich-text-editor/formatter/html-formatter.d.ts +5 -3
- package/src/rich-text-editor/formatter/html-formatter.js +7 -5
- package/src/rich-text-editor/models/default-locale.js +4 -2
- package/src/rich-text-editor/models/items.d.ts +3 -0
- package/src/rich-text-editor/models/items.js +32 -0
- package/src/rich-text-editor/models/toolbar-settings-model.d.ts +29 -1
- package/src/rich-text-editor/models/toolbar-settings.d.ts +24 -1
- package/src/rich-text-editor/models/toolbar-settings.js +20 -0
- package/src/rich-text-editor/renderer/audio-module.js +6 -3
- package/src/rich-text-editor/renderer/image-module.js +11 -6
- package/src/rich-text-editor/renderer/link-module.js +2 -1
- package/src/rich-text-editor/renderer/table-module.js +18 -6
- package/src/rich-text-editor/renderer/toolbar-renderer.js +10 -1
- package/src/rich-text-editor/renderer/video-module.js +8 -5
- package/src/rich-text-editor/renderer/view-source.js +1 -1
- package/styles/bootstrap-dark.css +31 -1
- package/styles/bootstrap.css +31 -1
- package/styles/bootstrap4.css +31 -1
- package/styles/bootstrap5-dark.css +32 -2
- package/styles/bootstrap5.css +32 -2
- package/styles/fabric-dark.css +31 -1
- package/styles/fabric.css +31 -1
- package/styles/fluent-dark.css +34 -4
- package/styles/fluent.css +34 -4
- package/styles/highcontrast-light.css +31 -1
- package/styles/highcontrast.css +31 -1
- package/styles/material-dark.css +31 -1
- package/styles/material.css +31 -1
- package/styles/rich-text-editor/_bootstrap-dark-definition.scss +25 -1
- package/styles/rich-text-editor/_bootstrap-definition.scss +25 -1
- package/styles/rich-text-editor/_bootstrap4-definition.scss +25 -1
- package/styles/rich-text-editor/_bootstrap5-definition.scss +28 -5
- package/styles/rich-text-editor/_fabric-dark-definition.scss +25 -1
- package/styles/rich-text-editor/_fabric-definition.scss +25 -1
- package/styles/rich-text-editor/_fluent-definition.scss +30 -7
- package/styles/rich-text-editor/_fusionnew-definition.scss +26 -3
- package/styles/rich-text-editor/_highcontrast-definition.scss +25 -1
- package/styles/rich-text-editor/_highcontrast-light-definition.scss +25 -1
- package/styles/rich-text-editor/_layout.scss +47 -15
- package/styles/rich-text-editor/_material-dark-definition.scss +26 -1
- package/styles/rich-text-editor/_material-definition.scss +25 -1
- package/styles/rich-text-editor/_tailwind-definition.scss +28 -5
- package/styles/rich-text-editor/_theme.scss +54 -6
- package/styles/rich-text-editor/bootstrap-dark.css +31 -1
- package/styles/rich-text-editor/bootstrap.css +31 -1
- package/styles/rich-text-editor/bootstrap4.css +31 -1
- package/styles/rich-text-editor/bootstrap5-dark.css +32 -2
- package/styles/rich-text-editor/bootstrap5.css +32 -2
- package/styles/rich-text-editor/fabric-dark.css +31 -1
- package/styles/rich-text-editor/fabric.css +31 -1
- package/styles/rich-text-editor/fluent-dark.css +34 -4
- package/styles/rich-text-editor/fluent.css +34 -4
- package/styles/rich-text-editor/highcontrast-light.css +31 -1
- package/styles/rich-text-editor/highcontrast.css +31 -1
- package/styles/rich-text-editor/icons/_bootstrap-dark.scss +8 -0
- package/styles/rich-text-editor/icons/_bootstrap.scss +8 -0
- package/styles/rich-text-editor/icons/_bootstrap4.scss +8 -0
- package/styles/rich-text-editor/icons/_bootstrap5.scss +8 -0
- package/styles/rich-text-editor/icons/_fabric-dark.scss +8 -0
- package/styles/rich-text-editor/icons/_fabric.scss +8 -0
- package/styles/rich-text-editor/icons/_fluent.scss +8 -0
- package/styles/rich-text-editor/icons/_fusionnew.scss +8 -0
- package/styles/rich-text-editor/icons/_highcontrast-light.scss +8 -0
- package/styles/rich-text-editor/icons/_highcontrast.scss +8 -0
- package/styles/rich-text-editor/icons/_material-dark.scss +8 -0
- package/styles/rich-text-editor/icons/_material.scss +8 -0
- package/styles/rich-text-editor/icons/_material3.scss +8 -0
- package/styles/rich-text-editor/icons/_tailwind.scss +8 -0
- package/styles/rich-text-editor/material-dark.css +31 -1
- package/styles/rich-text-editor/material.css +31 -1
- package/styles/rich-text-editor/tailwind-dark.css +31 -1
- package/styles/rich-text-editor/tailwind.css +31 -1
- package/styles/tailwind-dark.css +31 -1
- package/styles/tailwind.css +31 -1
- package/styles/rich-text-editor/_material3-definition.scss +0 -196
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { closest, createElement, detach, isNullOrUndefined as isNOU, removeClass } from '@syncfusion/ej2-base';
|
|
2
|
+
import * as EVENTS from '../../common/constant';
|
|
3
|
+
import { SelectionCommands } from '../plugin';
|
|
4
|
+
var FormatPainterActions = /** @class */ (function () {
|
|
5
|
+
function FormatPainterActions(parent, options) {
|
|
6
|
+
this.parent = parent;
|
|
7
|
+
this.settings = options;
|
|
8
|
+
this.addEventListener();
|
|
9
|
+
this.setDeniedFormats();
|
|
10
|
+
}
|
|
11
|
+
FormatPainterActions.prototype.addEventListener = function () {
|
|
12
|
+
this.parent.observer.on(EVENTS.FORMAT_PAINTER_ACTIONS, this.actionHandler, this);
|
|
13
|
+
};
|
|
14
|
+
FormatPainterActions.prototype.actionHandler = function (args) {
|
|
15
|
+
if (!isNOU(args) && !isNOU(args.item) && !isNOU(args.item.formatPainterAction)) {
|
|
16
|
+
switch (args.item.formatPainterAction) {
|
|
17
|
+
case 'format-copy':
|
|
18
|
+
this.copyAction();
|
|
19
|
+
break;
|
|
20
|
+
case 'format-paste':
|
|
21
|
+
this.pasteAction();
|
|
22
|
+
break;
|
|
23
|
+
case 'escape':
|
|
24
|
+
this.escapeAction();
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
FormatPainterActions.prototype.generateElement = function () {
|
|
30
|
+
var copyCollection = this.copyCollection.slice(); // To clone without reversing the collcection array
|
|
31
|
+
copyCollection.reverse();
|
|
32
|
+
var length = copyCollection.length;
|
|
33
|
+
var elemCollection = createElement('div', { className: 'e-format-paste-wrapper' });
|
|
34
|
+
var lastAppendChild;
|
|
35
|
+
for (var i = 0; i < length; i++) {
|
|
36
|
+
var _a = copyCollection[i], attrs = _a.attrs, className = _a.className, styles = _a.styles, tagName = _a.tagName;
|
|
37
|
+
var elem = createElement(tagName);
|
|
38
|
+
if (className !== '') {
|
|
39
|
+
elem.className = className;
|
|
40
|
+
}
|
|
41
|
+
for (var i_1 = 0; i_1 < attrs.length; i_1++) {
|
|
42
|
+
var property = attrs[i_1].name;
|
|
43
|
+
var value = attrs[i_1].value;
|
|
44
|
+
elem.setAttribute(property, value);
|
|
45
|
+
}
|
|
46
|
+
for (var i_2 = 0; i_2 < styles.length; i_2++) {
|
|
47
|
+
var property = styles[i_2].property;
|
|
48
|
+
var value = styles[i_2].value;
|
|
49
|
+
var priority = styles[i_2].priority;
|
|
50
|
+
elem.style.setProperty(property, value, priority);
|
|
51
|
+
}
|
|
52
|
+
if (elemCollection.childElementCount === 0) {
|
|
53
|
+
elemCollection.append(elem);
|
|
54
|
+
lastAppendChild = elem;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
lastAppendChild.append(elem);
|
|
58
|
+
lastAppendChild = elem;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var elemChild = this.removeDeniedFormats(elemCollection);
|
|
62
|
+
var currentElem = elemChild;
|
|
63
|
+
while (currentElem) {
|
|
64
|
+
if (currentElem.firstChild === null) {
|
|
65
|
+
lastAppendChild = currentElem;
|
|
66
|
+
currentElem = undefined;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
currentElem = currentElem.firstChild;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
this.newElem = elemChild;
|
|
73
|
+
this.newElemLastChild = lastAppendChild;
|
|
74
|
+
};
|
|
75
|
+
FormatPainterActions.prototype.pasteAction = function () {
|
|
76
|
+
if (isNOU(this.copyCollection) || this.copyCollection.length === 0) {
|
|
77
|
+
this.paintPlainTextFormat();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.insertFormatNode(this.newElem, this.newElemLastChild);
|
|
81
|
+
this.parent.undoRedoManager.saveData();
|
|
82
|
+
};
|
|
83
|
+
FormatPainterActions.prototype.removeDeniedFormats = function (parentElement) {
|
|
84
|
+
if (!isNOU(this.deniedFormatsCollection) && this.deniedFormatsCollection.length > 0) {
|
|
85
|
+
var deniedPropArray = this.deniedFormatsCollection;
|
|
86
|
+
var length_1 = deniedPropArray.length;
|
|
87
|
+
for (var i = 0; i < length_1; i++) {
|
|
88
|
+
var tag = deniedPropArray[i].tag;
|
|
89
|
+
if (deniedPropArray[i].tag) {
|
|
90
|
+
var elementsList = parentElement.querySelectorAll(tag);
|
|
91
|
+
for (var j = 0; j < elementsList.length; j++) {
|
|
92
|
+
if (deniedPropArray[i].classes.length > 0) {
|
|
93
|
+
var classes = deniedPropArray[i].classes;
|
|
94
|
+
var classLength = classes.length;
|
|
95
|
+
for (var k = 0; k < classLength; k++) {
|
|
96
|
+
if (elementsList[j].classList.contains(classes[k])) {
|
|
97
|
+
removeClass([elementsList[j]], classes[k]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (elementsList[j].classList.length === 0) {
|
|
101
|
+
elementsList[j].removeAttribute('class');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (deniedPropArray[i].styles.length > 0) {
|
|
105
|
+
var styles = deniedPropArray[i].styles;
|
|
106
|
+
var styleLength = styles.length;
|
|
107
|
+
for (var k = 0; k < styleLength; k++) {
|
|
108
|
+
elementsList[j].style.removeProperty(styles[k]);
|
|
109
|
+
}
|
|
110
|
+
if (elementsList[j].style.length === 0) {
|
|
111
|
+
elementsList[j].removeAttribute('style');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (deniedPropArray[i].attributes.length > 0) {
|
|
115
|
+
var attributes = deniedPropArray[i].attributes;
|
|
116
|
+
var attributeLength = attributes.length;
|
|
117
|
+
for (var k = 0; k < attributeLength; k++) {
|
|
118
|
+
elementsList[j].removeAttribute(attributes[k]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return parentElement.firstElementChild;
|
|
126
|
+
};
|
|
127
|
+
FormatPainterActions.prototype.copyAction = function () {
|
|
128
|
+
var copyCollection = [];
|
|
129
|
+
var range = this.parent.nodeSelection.getRange(document);
|
|
130
|
+
var parentElem = range.startContainer.parentElement;
|
|
131
|
+
var currentContext = this.findCurrentContext(parentElem);
|
|
132
|
+
var allowedRulesArray = this.settings.allowedFormats.split(';');
|
|
133
|
+
for (var i = 0; i < allowedRulesArray.length; i++) {
|
|
134
|
+
allowedRulesArray[i] = allowedRulesArray[i].trim();
|
|
135
|
+
}
|
|
136
|
+
var _a = this.getRangeParentElem(currentContext, range), rangeParentElem = _a[0], context = _a[1];
|
|
137
|
+
if (currentContext === null) {
|
|
138
|
+
currentContext = context;
|
|
139
|
+
}
|
|
140
|
+
if (!isNOU(currentContext) && this.settings.allowedContext.indexOf(currentContext) > -1) {
|
|
141
|
+
if (range.startContainer.nodeName === '#text') {
|
|
142
|
+
parentElem = range.startContainer.parentElement;
|
|
143
|
+
}
|
|
144
|
+
var lastElement = parentElem;
|
|
145
|
+
do {
|
|
146
|
+
if (allowedRulesArray.indexOf(parentElem.nodeName.toLowerCase()) > -1) {
|
|
147
|
+
var allAttributes = parentElem.attributes;
|
|
148
|
+
var attribute = [];
|
|
149
|
+
for (var i = 0; i < allAttributes.length; i++) {
|
|
150
|
+
if (allAttributes[i].name !== 'class' && allAttributes[i].name !== 'style') {
|
|
151
|
+
attribute.push(allAttributes[i]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var classes = parentElem.className;
|
|
155
|
+
var allStyles = parentElem.style;
|
|
156
|
+
var styleProp = [];
|
|
157
|
+
for (var i = 0; i < allStyles.length; i++) {
|
|
158
|
+
var property = allStyles[i];
|
|
159
|
+
var value = allStyles.getPropertyValue(property);
|
|
160
|
+
var priority = allStyles.getPropertyPriority(property);
|
|
161
|
+
styleProp.push({ property: property, value: value, priority: priority });
|
|
162
|
+
}
|
|
163
|
+
copyCollection.push({
|
|
164
|
+
attrs: attribute, className: classes, styles: styleProp, tagName: parentElem.nodeName
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (rangeParentElem === parentElem) {
|
|
168
|
+
parentElem = undefined;
|
|
169
|
+
}
|
|
170
|
+
else if (!isNOU(parentElem.parentElement)) {
|
|
171
|
+
parentElem = parentElem.parentElement;
|
|
172
|
+
}
|
|
173
|
+
if (lastElement === parentElem) {
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
} while (!isNOU(parentElem) || parentElem === this.parent.editableElement);
|
|
177
|
+
this.copyCollection = copyCollection;
|
|
178
|
+
}
|
|
179
|
+
this.generateElement();
|
|
180
|
+
};
|
|
181
|
+
FormatPainterActions.prototype.getRangeParentElem = function (currentContext, range) {
|
|
182
|
+
var startContainer = range.startContainer;
|
|
183
|
+
var rangeParentELem;
|
|
184
|
+
if (startContainer.nodeType === 3) {
|
|
185
|
+
startContainer = startContainer.parentElement;
|
|
186
|
+
}
|
|
187
|
+
switch (currentContext) {
|
|
188
|
+
case 'Table':
|
|
189
|
+
rangeParentELem = closest(startContainer, 'td');
|
|
190
|
+
if (isNOU(rangeParentELem)) {
|
|
191
|
+
rangeParentELem = closest(startContainer, 'th');
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
case 'List':
|
|
195
|
+
rangeParentELem = closest(startContainer, 'li');
|
|
196
|
+
break;
|
|
197
|
+
case 'Text':
|
|
198
|
+
rangeParentELem = closest(startContainer, 'p');
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
if (isNOU(rangeParentELem)) {
|
|
202
|
+
var nearBlockParentName = this.getNearestBlockParentElement(range);
|
|
203
|
+
if (!isNOU(nearBlockParentName) && nearBlockParentName !== 'UL' &&
|
|
204
|
+
nearBlockParentName !== 'OL' && nearBlockParentName !== 'LI') {
|
|
205
|
+
rangeParentELem = closest(startContainer, nearBlockParentName);
|
|
206
|
+
currentContext = 'Text';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (currentContext === 'List') {
|
|
210
|
+
rangeParentELem = rangeParentELem.parentElement;
|
|
211
|
+
}
|
|
212
|
+
return [rangeParentELem, currentContext];
|
|
213
|
+
};
|
|
214
|
+
FormatPainterActions.prototype.getNearestBlockParentElement = function (range) {
|
|
215
|
+
var node = range.commonAncestorContainer;
|
|
216
|
+
if (node.nodeType === 3) {
|
|
217
|
+
node = node.parentNode;
|
|
218
|
+
}
|
|
219
|
+
// iterate untill the content editable div
|
|
220
|
+
while (node && node !== this.parent.editableElement) {
|
|
221
|
+
// If true return the block node name.
|
|
222
|
+
if (!isNOU(node) && this.isBlockElement(node)) {
|
|
223
|
+
return node.nodeName;
|
|
224
|
+
}
|
|
225
|
+
// if false re assign node to parent node
|
|
226
|
+
node = node.parentNode;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
FormatPainterActions.prototype.isBlockElement = function (node) {
|
|
231
|
+
var blockTags = ['P', 'DIV', 'UL', 'OL', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6',
|
|
232
|
+
'ADDRESS', 'ARTICLE', 'ASIDE', 'BLOCKQUOTE', 'FIGCAPTION', 'FIGURE', 'FOOTER', 'HEADER',
|
|
233
|
+
'HR', 'MAIN', 'NAV', 'SECTION', 'SUMMARY', 'PRE'];
|
|
234
|
+
return blockTags.indexOf(node.nodeName) > -1;
|
|
235
|
+
};
|
|
236
|
+
FormatPainterActions.prototype.escapeAction = function () {
|
|
237
|
+
this.copyCollection = [];
|
|
238
|
+
};
|
|
239
|
+
FormatPainterActions.prototype.paintPlainTextFormat = function () {
|
|
240
|
+
var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
|
|
241
|
+
var domSelection = this.parent.nodeSelection;
|
|
242
|
+
var nodes = range.collapsed ? domSelection.getSelectionNodeCollection(range) :
|
|
243
|
+
domSelection.getSelectionNodeCollectionBr(range);
|
|
244
|
+
var isInValid;
|
|
245
|
+
if (nodes.length > 1) {
|
|
246
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
247
|
+
isInValid = this.validateELementTag(nodes[i]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
isInValid = this.validateELementTag(range.startContainer) && this.validateELementTag(range.endContainer);
|
|
252
|
+
}
|
|
253
|
+
if (!isInValid) {
|
|
254
|
+
this.parent.execCommand('Clear', 'ClearFormat', null, null);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
FormatPainterActions.prototype.validateELementTag = function (node) {
|
|
258
|
+
var INVALID_TAGS = ['A', 'AUDIO', 'IMG', 'VIDEO', 'IFRAME'];
|
|
259
|
+
if (node.nodeType === 3) {
|
|
260
|
+
node = node.parentElement;
|
|
261
|
+
}
|
|
262
|
+
return INVALID_TAGS.indexOf(node.tagName) > -1;
|
|
263
|
+
};
|
|
264
|
+
FormatPainterActions.prototype.findCurrentContext = function (parentElem) {
|
|
265
|
+
if (closest(parentElem, 'td') || closest(parentElem, 'tr') || closest(parentElem, 'tbody')) {
|
|
266
|
+
return 'Table';
|
|
267
|
+
}
|
|
268
|
+
else if (closest(parentElem, 'li')) {
|
|
269
|
+
return 'List';
|
|
270
|
+
}
|
|
271
|
+
else if (closest(parentElem, 'p')) {
|
|
272
|
+
return 'Text';
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
};
|
|
276
|
+
FormatPainterActions.prototype.insertFormatNode = function (elem, lastChild) {
|
|
277
|
+
var endNode = this.parent.editableElement;
|
|
278
|
+
var docElement = this.parent.currentDocument;
|
|
279
|
+
var domSelection = this.parent.nodeSelection;
|
|
280
|
+
var clonedElem = elem.cloneNode(true);
|
|
281
|
+
var childElem = clonedElem.firstChild;
|
|
282
|
+
var inlineElement;
|
|
283
|
+
while (childElem) {
|
|
284
|
+
if (this.isBlockElement(childElem)) {
|
|
285
|
+
childElem = childElem.firstChild;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
inlineElement = childElem.parentNode.removeChild(childElem);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
var formatValues = {
|
|
293
|
+
element: inlineElement,
|
|
294
|
+
lastChild: lastChild
|
|
295
|
+
};
|
|
296
|
+
SelectionCommands.applyFormat(docElement, null, endNode, 'P', 'formatPainter', null, formatValues);
|
|
297
|
+
var isFullNodeSelected;
|
|
298
|
+
var range = this.parent.nodeSelection.getRange(docElement);
|
|
299
|
+
var isCollapsed = range.collapsed;
|
|
300
|
+
var nodes = range.collapsed ? domSelection.getSelectionNodeCollection(range) :
|
|
301
|
+
domSelection.getSelectionNodeCollectionBr(range);
|
|
302
|
+
if (nodes.length === 1) {
|
|
303
|
+
while (!this.isBlockElement(nodes[0])) {
|
|
304
|
+
nodes[0] = nodes[0].parentElement;
|
|
305
|
+
}
|
|
306
|
+
isFullNodeSelected = nodes[0].textContent.trim() === range.commonAncestorContainer.wholeText.trim();
|
|
307
|
+
}
|
|
308
|
+
if (this.isBlockElement(elem) && isCollapsed || nodes.length > 1 || isFullNodeSelected) {
|
|
309
|
+
this.insertBlockNode(elem, range, docElement, endNode, nodes);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
FormatPainterActions.prototype.insertBlockNode = function (element, range, docElement, endNode, nodes) {
|
|
313
|
+
var domSelection = this.parent.nodeSelection;
|
|
314
|
+
var listElement; // To clone to multiple list elements
|
|
315
|
+
var cloneListParentNode;
|
|
316
|
+
if (element.nodeName === 'UL' || element.nodeName === 'OL') {
|
|
317
|
+
cloneListParentNode = element.cloneNode(true);
|
|
318
|
+
listElement = cloneListParentNode.firstChild;
|
|
319
|
+
}
|
|
320
|
+
var textNode = range.startContainer; // To set cursor position
|
|
321
|
+
for (var index = 0; index < nodes.length; index++) {
|
|
322
|
+
var lastTextNode = nodes[index];
|
|
323
|
+
if (nodes[index].nodeType === 3) {
|
|
324
|
+
nodes[index] = nodes[index].parentElement;
|
|
325
|
+
}
|
|
326
|
+
while (!this.isBlockElement(nodes[index])) {
|
|
327
|
+
nodes[index] = nodes[index].parentElement;
|
|
328
|
+
}
|
|
329
|
+
var cloneParentNode = void 0;
|
|
330
|
+
if (!isNOU(cloneListParentNode)) {
|
|
331
|
+
cloneParentNode = listElement.cloneNode(true);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
cloneParentNode = element.cloneNode(true);
|
|
335
|
+
}
|
|
336
|
+
// Appending all the child elements
|
|
337
|
+
while (nodes[index].firstChild) {
|
|
338
|
+
if (cloneParentNode.nodeName === 'LI') {
|
|
339
|
+
cloneParentNode.appendChild(nodes[index].firstChild);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
// Except list nodes other block nodes replaced here
|
|
343
|
+
if (nodes[index].nodeType === 3) {
|
|
344
|
+
cloneParentNode.appendChild(nodes[index].firstChild);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
cloneParentNode.innerHTML = nodes[index].innerHTML;
|
|
348
|
+
nodes[index].innerHTML = '';
|
|
349
|
+
}
|
|
350
|
+
nodes[index] = nodes[index].parentNode.replaceChild(cloneParentNode, nodes[index]);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (cloneParentNode.nodeName === 'LI') {
|
|
354
|
+
// Appending the li nodes to the ol or ul node
|
|
355
|
+
cloneListParentNode.append(cloneParentNode);
|
|
356
|
+
if (index === 0) {
|
|
357
|
+
var nodeName = nodes[index].nodeName;
|
|
358
|
+
nodes[index] = nodes[index].parentNode.replaceChild(cloneListParentNode, nodes[index]);
|
|
359
|
+
var parent_1 = nodeName === 'LI' ? cloneListParentNode.parentElement
|
|
360
|
+
: cloneListParentNode;
|
|
361
|
+
// Splicing and then inserting the node to previous element sibling of the Listparent.parent
|
|
362
|
+
this.parent.nodeCutter.SplitNode(range, parent_1, true);
|
|
363
|
+
if (!isNOU(parent_1.previousElementSibling)) {
|
|
364
|
+
parent_1.parentNode.insertBefore(cloneListParentNode, parent_1.nextElementSibling);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
parent_1.parentElement.insertBefore(cloneListParentNode, parent_1);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
detach(nodes[index]);
|
|
371
|
+
}
|
|
372
|
+
/**Removing the inserted block node in list and appending to previous element sibling */
|
|
373
|
+
if (cloneParentNode.nodeName !== 'LI' && (cloneParentNode.parentElement.nodeName === 'OL' ||
|
|
374
|
+
cloneParentNode.parentElement.nodeName === 'UL')) {
|
|
375
|
+
var parent_2 = cloneParentNode.parentElement;
|
|
376
|
+
// Cutting single ul or ol to two ul or ol based on the range
|
|
377
|
+
this.parent.nodeCutter.SplitNode(range, parent_2, true);
|
|
378
|
+
if (!isNOU(parent_2.previousElementSibling)) {
|
|
379
|
+
parent_2.previousElementSibling.after(cloneParentNode);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
parent_2.parentElement.prepend(cloneParentNode);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
nodes[index] = lastTextNode;
|
|
386
|
+
}
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
388
|
+
!isNOU(listElement) ? detach(listElement) : false;
|
|
389
|
+
this.cleanEmptyLists();
|
|
390
|
+
if (nodes.length > 1) {
|
|
391
|
+
var startSelectNode = nodes[0];
|
|
392
|
+
var endSelectNode = nodes[nodes.length - 1];
|
|
393
|
+
domSelection.setSelectionText(docElement, startSelectNode, endSelectNode, 0, endSelectNode.textContent.length);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
domSelection.setCursorPoint(docElement, textNode, textNode.textContent.length);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
FormatPainterActions.prototype.cleanEmptyLists = function () {
|
|
400
|
+
var listElem = this.parent.editableElement.querySelectorAll('ol, ul');
|
|
401
|
+
for (var i = 0; i < listElem.length; i++) {
|
|
402
|
+
if (listElem[i].textContent.trim() === '') {
|
|
403
|
+
detach(listElem[i]);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
FormatPainterActions.prototype.setDeniedFormats = function () {
|
|
408
|
+
var deniedFormatsCollection = [];
|
|
409
|
+
if (isNOU(this.settings) || isNOU(this.settings.deniedFormats)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
var deniedFormats = this.settings.deniedFormats.split(';');
|
|
413
|
+
var length = deniedFormats.length;
|
|
414
|
+
for (var i = 0; i < length; i++) {
|
|
415
|
+
var formatString = deniedFormats[i];
|
|
416
|
+
if (formatString !== '') {
|
|
417
|
+
formatString.trim();
|
|
418
|
+
var collection = this.makeDeniedFormatsCollection(formatString);
|
|
419
|
+
if (!isNOU(collection)) {
|
|
420
|
+
deniedFormatsCollection.push(collection);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
this.deniedFormatsCollection = deniedFormatsCollection;
|
|
425
|
+
};
|
|
426
|
+
FormatPainterActions.prototype.makeDeniedFormatsCollection = function (value) {
|
|
427
|
+
var openParenIndex = value.indexOf('(');
|
|
428
|
+
var closeParenIndex = value.indexOf(')');
|
|
429
|
+
var openBracketIndex = value.indexOf('[');
|
|
430
|
+
var closeBracketIndex = value.indexOf(']');
|
|
431
|
+
var openBraceIndex = value.indexOf('{');
|
|
432
|
+
var closeBraceIndex = value.indexOf('}');
|
|
433
|
+
var classes = [];
|
|
434
|
+
var attributes = '';
|
|
435
|
+
var styles = '';
|
|
436
|
+
var tagName = '';
|
|
437
|
+
var classList = [];
|
|
438
|
+
var attributesList = [];
|
|
439
|
+
var stylesList = [];
|
|
440
|
+
if (openParenIndex > -1 && closeParenIndex > -1) {
|
|
441
|
+
classes = value.substring(openParenIndex + 1, closeParenIndex).split(' ');
|
|
442
|
+
classList = classes[0].split(')')[0].split(',');
|
|
443
|
+
}
|
|
444
|
+
if (openBracketIndex > -1 && closeBracketIndex > -1) {
|
|
445
|
+
attributes = value.substring(openBracketIndex + 1, closeBracketIndex);
|
|
446
|
+
attributesList = attributes.split(',');
|
|
447
|
+
}
|
|
448
|
+
if (openBraceIndex > -1 && closeBraceIndex > -1) {
|
|
449
|
+
styles = value.substring(openBraceIndex + 1, closeBraceIndex);
|
|
450
|
+
stylesList = styles.split(',');
|
|
451
|
+
}
|
|
452
|
+
var openIndexArray = [openParenIndex, openBracketIndex, openBraceIndex];
|
|
453
|
+
openIndexArray = openIndexArray.filter(function (index) { return index > -1; });
|
|
454
|
+
var len = openIndexArray.length;
|
|
455
|
+
var min;
|
|
456
|
+
if (len === 1) {
|
|
457
|
+
min = openIndexArray[0];
|
|
458
|
+
}
|
|
459
|
+
else if (len === 2) {
|
|
460
|
+
min = Math.min(openIndexArray[0], openIndexArray[1]);
|
|
461
|
+
}
|
|
462
|
+
else if (len === 3) {
|
|
463
|
+
min = Math.min(openIndexArray[0], openIndexArray[1], openIndexArray[2]);
|
|
464
|
+
}
|
|
465
|
+
tagName = value.substring(0, min);
|
|
466
|
+
tagName.trim();
|
|
467
|
+
return ({
|
|
468
|
+
tag: tagName, styles: stylesList, classes: classList,
|
|
469
|
+
attributes: attributesList
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
return FormatPainterActions;
|
|
473
|
+
}());
|
|
474
|
+
export { FormatPainterActions };
|
|
@@ -182,7 +182,6 @@ var ImageCommand = /** @class */ (function () {
|
|
|
182
182
|
this.callBack(e);
|
|
183
183
|
};
|
|
184
184
|
ImageCommand.prototype.openImageLink = function (e) {
|
|
185
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
186
185
|
document.defaultView.open(e.item.url, e.item.target);
|
|
187
186
|
this.callBack(e);
|
|
188
187
|
};
|
|
@@ -221,7 +221,9 @@ var InsertHtml = /** @class */ (function () {
|
|
|
221
221
|
}
|
|
222
222
|
else {
|
|
223
223
|
range.deleteContents();
|
|
224
|
-
|
|
224
|
+
if (!isNOU(lasNode)) {
|
|
225
|
+
detach(lasNode);
|
|
226
|
+
}
|
|
225
227
|
// eslint-disable-next-line
|
|
226
228
|
!isNOU(sibNode) ? sibNode.parentNode.appendChild(fragment) : editNode.appendChild(fragment);
|
|
227
229
|
}
|
|
@@ -407,7 +409,7 @@ var InsertHtml = /** @class */ (function () {
|
|
|
407
409
|
detach(currentNode.nextSibling);
|
|
408
410
|
}
|
|
409
411
|
}
|
|
410
|
-
else if ((currentNode.nodeName === '#text' || currentNode.nodeName ===
|
|
412
|
+
else if ((currentNode.nodeName === '#text' || currentNode.nodeName === 'BR') && !isNOU(currentNode.parentElement) &&
|
|
411
413
|
(currentNode.parentElement.nodeName === 'LI' || (blockNode === editNode && currentNode.parentElement === blockNode)) &&
|
|
412
414
|
currentNode.parentElement.textContent.trim().length > 0) {
|
|
413
415
|
splitedElm = currentNode;
|
|
@@ -250,7 +250,6 @@ var LinkCommand = /** @class */ (function () {
|
|
|
250
250
|
return arr.join(' ') + ' ';
|
|
251
251
|
};
|
|
252
252
|
LinkCommand.prototype.openLink = function (e) {
|
|
253
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
254
253
|
document.defaultView.open(e.item.url, e.item.target);
|
|
255
254
|
this.callBack(e);
|
|
256
255
|
};
|
|
@@ -127,7 +127,7 @@ var Lists = /** @class */ (function () {
|
|
|
127
127
|
this.parent.domNode.insertAfter(insertTag, startNodeParent);
|
|
128
128
|
e.event.preventDefault();
|
|
129
129
|
this.parent.nodeSelection.setCursorPoint(this.parent.currentDocument, insertTag, 0);
|
|
130
|
-
if (startNodeParent.textContent === '') {
|
|
130
|
+
if (startNodeParent.textContent === '' && (startNodeParent.querySelectorAll('audio,video').length === 0)) {
|
|
131
131
|
detach(startNodeParent);
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
@@ -76,7 +76,7 @@ var MsWordPaste = /** @class */ (function () {
|
|
|
76
76
|
if (pattern4.test(tempHTMLContent)) {
|
|
77
77
|
this.addTableBorderClass(elm);
|
|
78
78
|
}
|
|
79
|
-
// Removing the margin for list items
|
|
79
|
+
// Removing the margin for list items
|
|
80
80
|
var liChildren = elm.querySelectorAll('li');
|
|
81
81
|
if (liChildren.length > 0) {
|
|
82
82
|
for (var i = 0; i < liChildren.length; i++) {
|
|
@@ -524,12 +524,12 @@ var MsWordPaste = /** @class */ (function () {
|
|
|
524
524
|
listStyleType = this.getlistStyleType(this.listContents[0], type);
|
|
525
525
|
if (type === 'ol' && (i === 0 || listNodes[i - 1] === null)) {
|
|
526
526
|
var startString = this.listContents[0].split('.')[0];
|
|
527
|
-
var listTypes = ['A', 'a', 'I', 'i', 'α', '1', '1-']; // Add '1-' for rare list type.
|
|
527
|
+
var listTypes = ['A', 'a', 'I', 'i', 'α', '1', '1-']; // Add '1-' for rare list type.
|
|
528
528
|
if (listTypes.indexOf(startString) === -1) {
|
|
529
529
|
if (listStyleType === 'decimal') {
|
|
530
530
|
// Bug in getlistStyleType() list style stype is returned as decimal for nested list with start attribute
|
|
531
|
-
if (!isNaN(parseInt(startString))) {
|
|
532
|
-
startAttr = parseInt(startString);
|
|
531
|
+
if (!isNaN(parseInt(startString, 10))) {
|
|
532
|
+
startAttr = parseInt(startString, 10);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
else if (listStyleType === 'upper-alpha') {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FormatPainterValue } from '../plugin';
|
|
1
2
|
export declare class SelectionCommands {
|
|
2
3
|
static enterAction: string;
|
|
3
4
|
/**
|
|
@@ -9,11 +10,12 @@ export declare class SelectionCommands {
|
|
|
9
10
|
* @param {string} enterAction - specifies the enter key action
|
|
10
11
|
* @param {string} value - specifies the string value
|
|
11
12
|
* @param {string} selector - specifies the string
|
|
13
|
+
* @param {FormatPainterValue} painterValues specifies the element created and last child
|
|
12
14
|
* @returns {void}
|
|
13
15
|
* @hidden
|
|
14
16
|
|
|
15
17
|
*/
|
|
16
|
-
static applyFormat(docElement: Document, format: string, endNode: Node, enterAction: string, value?: string, selector?: string): void;
|
|
18
|
+
static applyFormat(docElement: Document, format: string, endNode: Node, enterAction: string, value?: string, selector?: string, painterValues?: FormatPainterValue): void;
|
|
17
19
|
private static insertCursorNode;
|
|
18
20
|
private static getCursorFormat;
|
|
19
21
|
private static removeFormat;
|
|
@@ -24,4 +26,5 @@ export declare class SelectionCommands {
|
|
|
24
26
|
private static applySelection;
|
|
25
27
|
private static GetFormatNode;
|
|
26
28
|
private static updateStyles;
|
|
29
|
+
private static insertFormatPainterElem;
|
|
27
30
|
}
|