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 | 1×
1×
1×
1×
29×
29×
29×
29×
29×
29×
29×
29×
29×
1×
29×
29×
1×
5×
5×
5×
5×
2×
1×
1×
2×
1×
1×
1×
1×
1×
1×
1×
32823×
1×
29×
29×
29×
29×
1×
29×
29×
29×
20×
1×
29×
1×
18×
18×
18×
18×
18×
18×
18×
1×
18×
18×
2×
16×
15×
15×
15×
1×
1×
1×
1×
5×
5×
5×
5×
1×
1×
1×
1×
7×
7×
1×
1×
1×
1×
1×
1×
30×
30×
30×
284×
282×
2538×
282×
216×
282×
282×
2×
30×
30×
284×
30×
1×
29×
29×
29×
29×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-dropdowns", "@syncfusion/ej2-base", "../models/slash-menu-settings", "../../selection/selection", "../models/default-locale", "../base/constant"], function (require, exports, ej2_dropdowns_1, ej2_base_1, slash_menu_settings_1, selection_1, default_locale_1, events) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var SlashMenu = (function () {
function SlashMenu(options, serviceLocator) {
this.parent = options;
this.currentDocument = this.parent.element.ownerDocument;
this.L10n = serviceLocator.getService('rteLocale');
this.savedSelection = new selection_1.NodeSelection(this.parent.inputElement);
this.defaultItems = slash_menu_settings_1.defaultSlashMenuDataModel;
this.injectibleItems = slash_menu_settings_1.injectibleSlashMenuDataModel;
this.parent.on(events.modelChanged, this.onPropertyChanged, this);
this.parent.on(events.destroy, this.removeEventListener, this);
this.parent.on(events.initialEnd, this.render, this);
}
SlashMenu.prototype.removeEventListener = function () {
this.parent.off(events.modelChanged, this.onPropertyChanged);
this.parent.off(events.destroy, this.removeEventListener);
};
SlashMenu.prototype.onPropertyChanged = function (e) {
for (var _i = 0, _a = Object.keys(e.newProp); _i < _a.length; _i++) {
var prop = _a[_i];
Eif (prop === 'slashMenuSettings') {
switch (Object.keys(e.newProp.slashMenuSettings)[0]) {
case 'enable':
if (!e.newProp.slashMenuSettings.enable) {
this.removeEventListener();
}
else {
this.render();
}
break;
case 'items':
this.mention.dataSource = this.getItems();
break;
case 'popupHeight':
this.mention.popupHeight = e.newProp.slashMenuSettings.popupHeight;
break;
case 'popupWidth':
this.mention.popupWidth = e.newProp.slashMenuSettings.popupWidth;
break;
}
}
}
};
SlashMenu.prototype.getModuleName = function () {
return 'slashMenu';
};
SlashMenu.prototype.destroy = function () {
Eif (this.mention && !this.mention.isDestroyed) {
this.mention.destroy();
this.defaultItems = [];
this.injectibleItems = [];
}
};
SlashMenu.prototype.generateMentionModel = function () {
var _this = this;
var dataSource = this.getItems();
var model = {
dataSource: dataSource,
cssClass: 'e-slash-menu' + this.parent.getCssClass(),
fields: { text: 'text', groupBy: 'type', iconCss: 'iconCss', value: 'description' },
mentionChar: '/',
target: this.parent.inputElement,
popupHeight: this.parent.slashMenuSettings.popupHeight,
popupWidth: this.parent.slashMenuSettings.popupWidth,
allowSpaces: true,
itemTemplate: '${if(iconCss && description)}' +
'<div class="e-rte-slash-menu-item-content" style="display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center;">' +
'<div class="e-slash-menu-icon"style="padding: 15px 15px 15px 15px;"><div class="${iconCss}"></div></div> ' +
'<div style="display: flex; flex-direction: column;">' +
'<span class="e-rte-slash-menu-item-text" style="font-weight: 500;">${text}</span>' +
'${if(description)}' +
'<span class="e-rte-slash-menu-item-description">${description}</span>' +
'${/if}' +
'</div>' +
'</div>' +
'${else}' +
'${if(iconCss && text)}' +
'<div class="e-rte-slash-menu-item-content" style="display: flex; flex-direction: row; align-items: center; height: 25px; font-weight: 500;">' +
'<div class="e-slash-menu-icon"style="margin-left: 15px; width: 30px"><div class="${iconCss}"></div></div> ' +
'<span class="e-rte-slash-menu-item-icon-text">${text}</span>' +
'</div>' +
'${/if}' +
'${/if}',
beforeOpen: function () {
_this.savedSelection = _this.savedSelection.save(_this.savedSelection.getRange(_this.currentDocument), _this.currentDocument);
},
filtering: function () {
_this.savedSelection = _this.savedSelection.save(_this.savedSelection.getRange(_this.currentDocument), _this.currentDocument);
},
select: this.handleSelect.bind(this)
};
return model;
};
SlashMenu.prototype.handleSelect = function (args) {
var _this = this;
args.cancel = true;
this.parent.focusIn();
this.savedSelection.restore();
var item = args.itemData;
var selectEventArgs = {
isInteracted: args.isInteracted,
item: args.item,
itemData: args.itemData,
originalEvent: args.e,
cancel: false
};
if (args.itemData.isCustomItem) {
this.parent.formatter.beforeSlashMenuApply();
}
this.parent.trigger('slashMenuItemSelect', selectEventArgs, function (selectArgs) {
if (selectArgs.cancel) {
return;
}
else {
if (!selectArgs.itemData.isCustomItem) {
_this.parent.formatter.beforeSlashMenuApply();
var itemModel_1 = item;
switch (itemModel_1.command) {
case 'OrderedList':
_this.parent.executeCommand('insertOrderedList');
break;
case 'UnorderedList':
_this.parent.executeCommand('insertUnorderedList');
break;
case 'Audio':
case 'Video':
case 'Image':
case 'Table':
case 'Link':
_this.mention.hidePopup();
setTimeout(function () {
_this.parent.showDialog(itemModel_1.subCommand);
}, 100);
break;
case 'Emojipicker':
_this.mention.hidePopup();
setTimeout(function () {
_this.parent.showEmojiPicker();
}, 100);
break;
default:
_this.parent.executeCommand('formatBlock', itemModel_1.subCommand);
break;
}
}
else {
Eif (_this.parent.inputElement.classList.contains('e-mention')) {
var slashMenuPopup = _this.parent.inputElement.ownerDocument.getElementById(_this.parent.inputElement.id + '_slash_menu_popup');
var isSlashMenuPopupOpen = slashMenuPopup && slashMenuPopup.classList.contains('e-popup-open');
Eif (isSlashMenuPopupOpen) {
_this.mention.hidePopup();
}
}
}
}
});
};
SlashMenu.prototype.getItems = function () {
var items = this.parent.slashMenuSettings.items;
var dataSource = [];
var _loop_1 = function (i) {
if (typeof items[i] === 'string') {
var commnadName_1 = items[i];
var model = this_1.defaultItems.filter(function (item) { return item.command === commnadName_1; })[0];
if (ej2_base_1.isNullOrUndefined(model)) {
model = this_1.injectibleItems.filter(function (item) { return item.module.toLowerCase().replace(' ', '') === commnadName_1.toLowerCase().replace(' ', ''); })[0];
}
var localeVariable = default_locale_1.slashMenuCommandsKey.get(commnadName_1);
dataSource.push({
text: this_1.L10n.getConstant(localeVariable.text),
command: model.command,
subCommand: model.subCommand,
type: model.type,
module: model.module,
iconCss: model.iconCss,
description: this_1.L10n.getConstant(localeVariable.description)
});
}
else {
dataSource.push({
text: items[i].text,
command: items[i].command,
type: items[i].type,
iconCss: items[i].iconCss,
description: items[i].description,
isCustomItem: true
});
}
};
var this_1 = this;
for (var i = 0; i < items.length; i++) {
_loop_1(i);
}
return dataSource;
};
SlashMenu.prototype.render = function () {
Eif (this.parent.editorMode === 'HTML' && this.parent.slashMenuSettings.enable) {
var options = this.generateMentionModel();
this.mention = new ej2_dropdowns_1.Mention(options);
this.mention.appendTo(this.parent.rootContainer.appendChild(this.parent.createElement('div', { className: 'e-rte-slash-menu', id: this.parent.getID() + '_slash_menu' })));
}
};
return SlashMenu;
}());
exports.SlashMenu = SlashMenu;
});
|