| 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 | 1×
1×
1×
1×
2746×
2746×
2746×
1×
2746×
2746×
2746×
1×
219×
219×
27×
27×
27×
10×
10×
2×
10×
2×
2×
2×
2×
2×
10×
2×
2×
2×
2×
2×
8×
8×
219×
15×
15×
15×
15×
1×
2745×
2745×
2745×
1×
5466×
2721×
2745×
2745×
1×
62201×
1×
2746×
2746×
2746×
1×
1×
| define(["require", "exports", "../base/constant", "../../editor-manager/plugin/autoformat", "@syncfusion/ej2-base"], function (require, exports, events, autoformat_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var AutoFormat = (function () {
function AutoFormat(parent) {
this.parent = parent;
this.isDestroyed = false;
this.addEventListener();
}
AutoFormat.prototype.addEventListener = function () {
this.parent.on(events.keyUp, this.onKeyUp, this);
this.parent.on(events.destroy, this.destroy, this);
this.parent.on(events.bindOnEnd, this.bindOnEnd, this);
};
AutoFormat.prototype.onKeyUp = function (e) {
var block = false;
if (e.args.which === 32 && this.parent.formatter.editorManager.autoFormatObj) {
var range = this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.inputElement.ownerDocument);
var isValidBlock = this.autoFormatObj.findBlockAutoFormatCommandInRange(range);
if (!ej2_base_1.isNullOrUndefined(isValidBlock)) {
var args = { item: { command: isValidBlock.format, subCommand: isValidBlock.tag } };
if (isValidBlock.tag === 'hr') {
args.item.value = '<hr/>';
}
if (isValidBlock.format === 'CodeBlock') {
var languages = this.parent.codeBlockSettings.languages;
var defaultLanguage = this.parent.codeBlockSettings.defaultLanguage;
var language = void 0;
var label = void 0;
for (var i = 0; i < languages.length; i++) {
if (languages[i].language === defaultLanguage) {
language = languages[i].language;
label = languages[i].label;
break;
}
}
this.parent.formatter.process(this.parent, args, e.args, { language: language, label: label, action: 'createCodeBlock', enterAction: this.parent.enterKey });
block = true;
}
else {
this.parent.formatter.process(this.parent, args, e.args);
block = true;
}
}
}
if (['*', '_', '`', '~'].indexOf(e.args.key) !== -1) {
var range = this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.inputElement.ownerDocument);
Eif (this.autoFormatObj.findAutoFormatCommandInRange(range) && !block) {
var args = { item: { command: 'autoformat', subCommand: 'inlinestyle' } };
this.parent.formatter.process(this.parent, args, e.args);
}
}
};
AutoFormat.prototype.removeEventListener = function () {
this.parent.off(events.keyUp, this.onKeyUp);
this.parent.off(events.destroy, this.destroy);
this.parent.off(events.bindOnEnd, this.bindOnEnd);
};
AutoFormat.prototype.destroy = function () {
if (this.isDestroyed) {
return;
}
this.isDestroyed = true;
this.removeEventListener();
};
AutoFormat.prototype.getModuleName = function () {
return 'autoFormat';
};
AutoFormat.prototype.bindOnEnd = function () {
Eif (!this.parent.formatter.editorManager.autoFormatObj) {
this.parent.formatter.editorManager.autoFormatObj = new autoformat_1.AutoFormatPlugin(this.parent.formatter.editorManager);
this.autoFormatObj = this.parent.formatter.editorManager.autoFormatObj;
}
};
return AutoFormat;
}());
exports.AutoFormat = AutoFormat;
});
|