1 |
efrain |
1 |
/**
|
|
|
2 |
* TinyMCE version 6.8.3 (2024-02-08)
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
(function () {
|
|
|
6 |
'use strict';
|
|
|
7 |
|
|
|
8 |
var global$3 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
|
9 |
|
|
|
10 |
const hasProto = (v, constructor, predicate) => {
|
|
|
11 |
var _a;
|
|
|
12 |
if (predicate(v, constructor.prototype)) {
|
|
|
13 |
return true;
|
|
|
14 |
} else {
|
|
|
15 |
return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
|
|
|
16 |
}
|
|
|
17 |
};
|
|
|
18 |
const typeOf = x => {
|
|
|
19 |
const t = typeof x;
|
|
|
20 |
if (x === null) {
|
|
|
21 |
return 'null';
|
|
|
22 |
} else if (t === 'object' && Array.isArray(x)) {
|
|
|
23 |
return 'array';
|
|
|
24 |
} else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
|
|
|
25 |
return 'string';
|
|
|
26 |
} else {
|
|
|
27 |
return t;
|
|
|
28 |
}
|
|
|
29 |
};
|
|
|
30 |
const isType = type => value => typeOf(value) === type;
|
|
|
31 |
const isSimpleType = type => value => typeof value === type;
|
|
|
32 |
const isString = isType('string');
|
|
|
33 |
const isObject = isType('object');
|
|
|
34 |
const isArray = isType('array');
|
|
|
35 |
const isNullable = a => a === null || a === undefined;
|
|
|
36 |
const isNonNullable = a => !isNullable(a);
|
|
|
37 |
const isFunction = isSimpleType('function');
|
|
|
38 |
const isArrayOf = (value, pred) => {
|
|
|
39 |
if (isArray(value)) {
|
|
|
40 |
for (let i = 0, len = value.length; i < len; ++i) {
|
|
|
41 |
if (!pred(value[i])) {
|
|
|
42 |
return false;
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
return true;
|
|
|
46 |
}
|
|
|
47 |
return false;
|
|
|
48 |
};
|
|
|
49 |
|
|
|
50 |
const constant = value => {
|
|
|
51 |
return () => {
|
|
|
52 |
return value;
|
|
|
53 |
};
|
|
|
54 |
};
|
|
|
55 |
function curry(fn, ...initialArgs) {
|
|
|
56 |
return (...restArgs) => {
|
|
|
57 |
const all = initialArgs.concat(restArgs);
|
|
|
58 |
return fn.apply(null, all);
|
|
|
59 |
};
|
|
|
60 |
}
|
|
|
61 |
const never = constant(false);
|
|
|
62 |
|
|
|
63 |
const escape = text => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
64 |
|
|
|
65 |
var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
|
|
66 |
|
|
|
67 |
const option = name => editor => editor.options.get(name);
|
|
|
68 |
const register$2 = editor => {
|
|
|
69 |
const registerOption = editor.options.register;
|
|
|
70 |
registerOption('template_cdate_classes', {
|
|
|
71 |
processor: 'string',
|
|
|
72 |
default: 'cdate'
|
|
|
73 |
});
|
|
|
74 |
registerOption('template_mdate_classes', {
|
|
|
75 |
processor: 'string',
|
|
|
76 |
default: 'mdate'
|
|
|
77 |
});
|
|
|
78 |
registerOption('template_selected_content_classes', {
|
|
|
79 |
processor: 'string',
|
|
|
80 |
default: 'selcontent'
|
|
|
81 |
});
|
|
|
82 |
registerOption('template_preview_replace_values', { processor: 'object' });
|
|
|
83 |
registerOption('template_replace_values', { processor: 'object' });
|
|
|
84 |
registerOption('templates', {
|
|
|
85 |
processor: value => isString(value) || isArrayOf(value, isObject) || isFunction(value),
|
|
|
86 |
default: []
|
|
|
87 |
});
|
|
|
88 |
registerOption('template_cdate_format', {
|
|
|
89 |
processor: 'string',
|
|
|
90 |
default: editor.translate('%Y-%m-%d')
|
|
|
91 |
});
|
|
|
92 |
registerOption('template_mdate_format', {
|
|
|
93 |
processor: 'string',
|
|
|
94 |
default: editor.translate('%Y-%m-%d')
|
|
|
95 |
});
|
|
|
96 |
};
|
|
|
97 |
const getCreationDateClasses = option('template_cdate_classes');
|
|
|
98 |
const getModificationDateClasses = option('template_mdate_classes');
|
|
|
99 |
const getSelectedContentClasses = option('template_selected_content_classes');
|
|
|
100 |
const getPreviewReplaceValues = option('template_preview_replace_values');
|
|
|
101 |
const getTemplateReplaceValues = option('template_replace_values');
|
|
|
102 |
const getTemplates = option('templates');
|
|
|
103 |
const getCdateFormat = option('template_cdate_format');
|
|
|
104 |
const getMdateFormat = option('template_mdate_format');
|
|
|
105 |
const getContentStyle = option('content_style');
|
|
|
106 |
const shouldUseContentCssCors = option('content_css_cors');
|
|
|
107 |
const getBodyClass = option('body_class');
|
|
|
108 |
|
|
|
109 |
const addZeros = (value, len) => {
|
|
|
110 |
value = '' + value;
|
|
|
111 |
if (value.length < len) {
|
|
|
112 |
for (let i = 0; i < len - value.length; i++) {
|
|
|
113 |
value = '0' + value;
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
return value;
|
|
|
117 |
};
|
|
|
118 |
const getDateTime = (editor, fmt, date = new Date()) => {
|
|
|
119 |
const daysShort = 'Sun Mon Tue Wed Thu Fri Sat Sun'.split(' ');
|
|
|
120 |
const daysLong = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday'.split(' ');
|
|
|
121 |
const monthsShort = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
|
|
|
122 |
const monthsLong = 'January February March April May June July August September October November December'.split(' ');
|
|
|
123 |
fmt = fmt.replace('%D', '%m/%d/%Y');
|
|
|
124 |
fmt = fmt.replace('%r', '%I:%M:%S %p');
|
|
|
125 |
fmt = fmt.replace('%Y', '' + date.getFullYear());
|
|
|
126 |
fmt = fmt.replace('%y', '' + date.getYear());
|
|
|
127 |
fmt = fmt.replace('%m', addZeros(date.getMonth() + 1, 2));
|
|
|
128 |
fmt = fmt.replace('%d', addZeros(date.getDate(), 2));
|
|
|
129 |
fmt = fmt.replace('%H', '' + addZeros(date.getHours(), 2));
|
|
|
130 |
fmt = fmt.replace('%M', '' + addZeros(date.getMinutes(), 2));
|
|
|
131 |
fmt = fmt.replace('%S', '' + addZeros(date.getSeconds(), 2));
|
|
|
132 |
fmt = fmt.replace('%I', '' + ((date.getHours() + 11) % 12 + 1));
|
|
|
133 |
fmt = fmt.replace('%p', '' + (date.getHours() < 12 ? 'AM' : 'PM'));
|
|
|
134 |
fmt = fmt.replace('%B', '' + editor.translate(monthsLong[date.getMonth()]));
|
|
|
135 |
fmt = fmt.replace('%b', '' + editor.translate(monthsShort[date.getMonth()]));
|
|
|
136 |
fmt = fmt.replace('%A', '' + editor.translate(daysLong[date.getDay()]));
|
|
|
137 |
fmt = fmt.replace('%a', '' + editor.translate(daysShort[date.getDay()]));
|
|
|
138 |
fmt = fmt.replace('%%', '%');
|
|
|
139 |
return fmt;
|
|
|
140 |
};
|
|
|
141 |
|
|
|
142 |
class Optional {
|
|
|
143 |
constructor(tag, value) {
|
|
|
144 |
this.tag = tag;
|
|
|
145 |
this.value = value;
|
|
|
146 |
}
|
|
|
147 |
static some(value) {
|
|
|
148 |
return new Optional(true, value);
|
|
|
149 |
}
|
|
|
150 |
static none() {
|
|
|
151 |
return Optional.singletonNone;
|
|
|
152 |
}
|
|
|
153 |
fold(onNone, onSome) {
|
|
|
154 |
if (this.tag) {
|
|
|
155 |
return onSome(this.value);
|
|
|
156 |
} else {
|
|
|
157 |
return onNone();
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
isSome() {
|
|
|
161 |
return this.tag;
|
|
|
162 |
}
|
|
|
163 |
isNone() {
|
|
|
164 |
return !this.tag;
|
|
|
165 |
}
|
|
|
166 |
map(mapper) {
|
|
|
167 |
if (this.tag) {
|
|
|
168 |
return Optional.some(mapper(this.value));
|
|
|
169 |
} else {
|
|
|
170 |
return Optional.none();
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
bind(binder) {
|
|
|
174 |
if (this.tag) {
|
|
|
175 |
return binder(this.value);
|
|
|
176 |
} else {
|
|
|
177 |
return Optional.none();
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
exists(predicate) {
|
|
|
181 |
return this.tag && predicate(this.value);
|
|
|
182 |
}
|
|
|
183 |
forall(predicate) {
|
|
|
184 |
return !this.tag || predicate(this.value);
|
|
|
185 |
}
|
|
|
186 |
filter(predicate) {
|
|
|
187 |
if (!this.tag || predicate(this.value)) {
|
|
|
188 |
return this;
|
|
|
189 |
} else {
|
|
|
190 |
return Optional.none();
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
getOr(replacement) {
|
|
|
194 |
return this.tag ? this.value : replacement;
|
|
|
195 |
}
|
|
|
196 |
or(replacement) {
|
|
|
197 |
return this.tag ? this : replacement;
|
|
|
198 |
}
|
|
|
199 |
getOrThunk(thunk) {
|
|
|
200 |
return this.tag ? this.value : thunk();
|
|
|
201 |
}
|
|
|
202 |
orThunk(thunk) {
|
|
|
203 |
return this.tag ? this : thunk();
|
|
|
204 |
}
|
|
|
205 |
getOrDie(message) {
|
|
|
206 |
if (!this.tag) {
|
|
|
207 |
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
|
208 |
} else {
|
|
|
209 |
return this.value;
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
static from(value) {
|
|
|
213 |
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
|
214 |
}
|
|
|
215 |
getOrNull() {
|
|
|
216 |
return this.tag ? this.value : null;
|
|
|
217 |
}
|
|
|
218 |
getOrUndefined() {
|
|
|
219 |
return this.value;
|
|
|
220 |
}
|
|
|
221 |
each(worker) {
|
|
|
222 |
if (this.tag) {
|
|
|
223 |
worker(this.value);
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
toArray() {
|
|
|
227 |
return this.tag ? [this.value] : [];
|
|
|
228 |
}
|
|
|
229 |
toString() {
|
|
|
230 |
return this.tag ? `some(${ this.value })` : 'none()';
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
Optional.singletonNone = new Optional(false);
|
|
|
234 |
|
|
|
235 |
const exists = (xs, pred) => {
|
|
|
236 |
for (let i = 0, len = xs.length; i < len; i++) {
|
|
|
237 |
const x = xs[i];
|
|
|
238 |
if (pred(x, i)) {
|
|
|
239 |
return true;
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
return false;
|
|
|
243 |
};
|
|
|
244 |
const map = (xs, f) => {
|
|
|
245 |
const len = xs.length;
|
|
|
246 |
const r = new Array(len);
|
|
|
247 |
for (let i = 0; i < len; i++) {
|
|
|
248 |
const x = xs[i];
|
|
|
249 |
r[i] = f(x, i);
|
|
|
250 |
}
|
|
|
251 |
return r;
|
|
|
252 |
};
|
|
|
253 |
const findUntil = (xs, pred, until) => {
|
|
|
254 |
for (let i = 0, len = xs.length; i < len; i++) {
|
|
|
255 |
const x = xs[i];
|
|
|
256 |
if (pred(x, i)) {
|
|
|
257 |
return Optional.some(x);
|
|
|
258 |
} else if (until(x, i)) {
|
|
|
259 |
break;
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
return Optional.none();
|
|
|
263 |
};
|
|
|
264 |
const find = (xs, pred) => {
|
|
|
265 |
return findUntil(xs, pred, never);
|
|
|
266 |
};
|
|
|
267 |
|
|
|
268 |
const hasOwnProperty = Object.hasOwnProperty;
|
|
|
269 |
const get = (obj, key) => {
|
|
|
270 |
return has(obj, key) ? Optional.from(obj[key]) : Optional.none();
|
|
|
271 |
};
|
|
|
272 |
const has = (obj, key) => hasOwnProperty.call(obj, key);
|
|
|
273 |
|
|
|
274 |
var global$1 = tinymce.util.Tools.resolve('tinymce.html.Serializer');
|
|
|
275 |
|
|
|
276 |
const entitiesAttr = {
|
|
|
277 |
'"': '"',
|
|
|
278 |
'<': '<',
|
|
|
279 |
'>': '>',
|
|
|
280 |
'&': '&',
|
|
|
281 |
'\'': '''
|
|
|
282 |
};
|
|
|
283 |
const htmlEscape = html => html.replace(/["'<>&]/g, match => get(entitiesAttr, match).getOr(match));
|
|
|
284 |
const hasAnyClasses = (dom, n, classes) => exists(classes.split(/\s+/), c => dom.hasClass(n, c));
|
|
|
285 |
const parseAndSerialize = (editor, html) => global$1({ validate: true }, editor.schema).serialize(editor.parser.parse(html, { insert: true }));
|
|
|
286 |
|
|
|
287 |
const createTemplateList = (editor, callback) => {
|
|
|
288 |
return () => {
|
|
|
289 |
const templateList = getTemplates(editor);
|
|
|
290 |
if (isFunction(templateList)) {
|
|
|
291 |
templateList(callback);
|
|
|
292 |
} else if (isString(templateList)) {
|
|
|
293 |
fetch(templateList).then(res => {
|
|
|
294 |
if (res.ok) {
|
|
|
295 |
res.json().then(callback);
|
|
|
296 |
}
|
|
|
297 |
});
|
|
|
298 |
} else {
|
|
|
299 |
callback(templateList);
|
|
|
300 |
}
|
|
|
301 |
};
|
|
|
302 |
};
|
|
|
303 |
const replaceTemplateValues = (html, templateValues) => {
|
|
|
304 |
global$2.each(templateValues, (v, k) => {
|
|
|
305 |
if (isFunction(v)) {
|
|
|
306 |
v = v(k);
|
|
|
307 |
}
|
|
|
308 |
html = html.replace(new RegExp('\\{\\$' + escape(k) + '\\}', 'g'), v);
|
|
|
309 |
});
|
|
|
310 |
return html;
|
|
|
311 |
};
|
|
|
312 |
const replaceVals = (editor, scope) => {
|
|
|
313 |
const dom = editor.dom, vl = getTemplateReplaceValues(editor);
|
|
|
314 |
global$2.each(dom.select('*', scope), e => {
|
|
|
315 |
global$2.each(vl, (v, k) => {
|
|
|
316 |
if (dom.hasClass(e, k)) {
|
|
|
317 |
if (isFunction(v)) {
|
|
|
318 |
v(e);
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
});
|
|
|
322 |
});
|
|
|
323 |
};
|
|
|
324 |
const insertTemplate = (editor, _ui, html) => {
|
|
|
325 |
const dom = editor.dom;
|
|
|
326 |
const sel = editor.selection.getContent();
|
|
|
327 |
html = replaceTemplateValues(html, getTemplateReplaceValues(editor));
|
|
|
328 |
let el = dom.create('div', {}, parseAndSerialize(editor, html));
|
|
|
329 |
const n = dom.select('.mceTmpl', el);
|
|
|
330 |
if (n && n.length > 0) {
|
|
|
331 |
el = dom.create('div');
|
|
|
332 |
el.appendChild(n[0].cloneNode(true));
|
|
|
333 |
}
|
|
|
334 |
global$2.each(dom.select('*', el), n => {
|
|
|
335 |
if (hasAnyClasses(dom, n, getCreationDateClasses(editor))) {
|
|
|
336 |
n.innerHTML = getDateTime(editor, getCdateFormat(editor));
|
|
|
337 |
}
|
|
|
338 |
if (hasAnyClasses(dom, n, getModificationDateClasses(editor))) {
|
|
|
339 |
n.innerHTML = getDateTime(editor, getMdateFormat(editor));
|
|
|
340 |
}
|
|
|
341 |
if (hasAnyClasses(dom, n, getSelectedContentClasses(editor))) {
|
|
|
342 |
n.innerHTML = sel;
|
|
|
343 |
}
|
|
|
344 |
});
|
|
|
345 |
replaceVals(editor, el);
|
|
|
346 |
editor.execCommand('mceInsertContent', false, el.innerHTML);
|
|
|
347 |
editor.addVisual();
|
|
|
348 |
};
|
|
|
349 |
|
|
|
350 |
var global = tinymce.util.Tools.resolve('tinymce.Env');
|
|
|
351 |
|
|
|
352 |
const getPreviewContent = (editor, html) => {
|
|
|
353 |
var _a;
|
|
|
354 |
let previewHtml = parseAndSerialize(editor, html);
|
|
|
355 |
if (html.indexOf('<html>') === -1) {
|
|
|
356 |
let contentCssEntries = '';
|
|
|
357 |
const contentStyle = (_a = getContentStyle(editor)) !== null && _a !== void 0 ? _a : '';
|
|
|
358 |
const cors = shouldUseContentCssCors(editor) ? ' crossorigin="anonymous"' : '';
|
|
|
359 |
global$2.each(editor.contentCSS, url => {
|
|
|
360 |
contentCssEntries += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '"' + cors + '>';
|
|
|
361 |
});
|
|
|
362 |
if (contentStyle) {
|
|
|
363 |
contentCssEntries += '<style type="text/css">' + contentStyle + '</style>';
|
|
|
364 |
}
|
|
|
365 |
const bodyClass = getBodyClass(editor);
|
|
|
366 |
const encode = editor.dom.encode;
|
|
|
367 |
const isMetaKeyPressed = global.os.isMacOS() || global.os.isiOS() ? 'e.metaKey' : 'e.ctrlKey && !e.altKey';
|
|
|
368 |
const preventClicksOnLinksScript = '<script>' + 'document.addEventListener && document.addEventListener("click", function(e) {' + 'for (var elm = e.target; elm; elm = elm.parentNode) {' + 'if (elm.nodeName === "A" && !(' + isMetaKeyPressed + ')) {' + 'e.preventDefault();' + '}' + '}' + '}, false);' + '</script> ';
|
|
|
369 |
const directionality = editor.getBody().dir;
|
|
|
370 |
const dirAttr = directionality ? ' dir="' + encode(directionality) + '"' : '';
|
|
|
371 |
previewHtml = '<!DOCTYPE html>' + '<html>' + '<head>' + '<base href="' + encode(editor.documentBaseURI.getURI()) + '">' + contentCssEntries + preventClicksOnLinksScript + '</head>' + '<body class="' + encode(bodyClass) + '"' + dirAttr + '>' + previewHtml + '</body>' + '</html>';
|
|
|
372 |
}
|
|
|
373 |
return replaceTemplateValues(previewHtml, getPreviewReplaceValues(editor));
|
|
|
374 |
};
|
|
|
375 |
const open = (editor, templateList) => {
|
|
|
376 |
const createTemplates = () => {
|
|
|
377 |
if (!templateList || templateList.length === 0) {
|
|
|
378 |
const message = editor.translate('No templates defined.');
|
|
|
379 |
editor.notificationManager.open({
|
|
|
380 |
text: message,
|
|
|
381 |
type: 'info'
|
|
|
382 |
});
|
|
|
383 |
return Optional.none();
|
|
|
384 |
}
|
|
|
385 |
return Optional.from(global$2.map(templateList, (template, index) => {
|
|
|
386 |
const isUrlTemplate = t => t.url !== undefined;
|
|
|
387 |
return {
|
|
|
388 |
selected: index === 0,
|
|
|
389 |
text: template.title,
|
|
|
390 |
value: {
|
|
|
391 |
url: isUrlTemplate(template) ? Optional.from(template.url) : Optional.none(),
|
|
|
392 |
content: !isUrlTemplate(template) ? Optional.from(template.content) : Optional.none(),
|
|
|
393 |
description: template.description
|
|
|
394 |
}
|
|
|
395 |
};
|
|
|
396 |
}));
|
|
|
397 |
};
|
|
|
398 |
const createSelectBoxItems = templates => map(templates, t => ({
|
|
|
399 |
text: t.text,
|
|
|
400 |
value: t.text
|
|
|
401 |
}));
|
|
|
402 |
const findTemplate = (templates, templateTitle) => find(templates, t => t.text === templateTitle);
|
|
|
403 |
const loadFailedAlert = api => {
|
|
|
404 |
editor.windowManager.alert('Could not load the specified template.', () => api.focus('template'));
|
|
|
405 |
};
|
|
|
406 |
const getTemplateContent = t => t.value.url.fold(() => Promise.resolve(t.value.content.getOr('')), url => fetch(url).then(res => res.ok ? res.text() : Promise.reject()));
|
|
|
407 |
const onChange = (templates, updateDialog) => (api, change) => {
|
|
|
408 |
if (change.name === 'template') {
|
|
|
409 |
const newTemplateTitle = api.getData().template;
|
|
|
410 |
findTemplate(templates, newTemplateTitle).each(t => {
|
|
|
411 |
api.block('Loading...');
|
|
|
412 |
getTemplateContent(t).then(previewHtml => {
|
|
|
413 |
updateDialog(api, t, previewHtml);
|
|
|
414 |
}).catch(() => {
|
|
|
415 |
updateDialog(api, t, '');
|
|
|
416 |
api.setEnabled('save', false);
|
|
|
417 |
loadFailedAlert(api);
|
|
|
418 |
});
|
|
|
419 |
});
|
|
|
420 |
}
|
|
|
421 |
};
|
|
|
422 |
const onSubmit = templates => api => {
|
|
|
423 |
const data = api.getData();
|
|
|
424 |
findTemplate(templates, data.template).each(t => {
|
|
|
425 |
getTemplateContent(t).then(previewHtml => {
|
|
|
426 |
editor.execCommand('mceInsertTemplate', false, previewHtml);
|
|
|
427 |
api.close();
|
|
|
428 |
}).catch(() => {
|
|
|
429 |
api.setEnabled('save', false);
|
|
|
430 |
loadFailedAlert(api);
|
|
|
431 |
});
|
|
|
432 |
});
|
|
|
433 |
};
|
|
|
434 |
const openDialog = templates => {
|
|
|
435 |
const selectBoxItems = createSelectBoxItems(templates);
|
|
|
436 |
const buildDialogSpec = (bodyItems, initialData) => ({
|
|
|
437 |
title: 'Insert Template',
|
|
|
438 |
size: 'large',
|
|
|
439 |
body: {
|
|
|
440 |
type: 'panel',
|
|
|
441 |
items: bodyItems
|
|
|
442 |
},
|
|
|
443 |
initialData,
|
|
|
444 |
buttons: [
|
|
|
445 |
{
|
|
|
446 |
type: 'cancel',
|
|
|
447 |
name: 'cancel',
|
|
|
448 |
text: 'Cancel'
|
|
|
449 |
},
|
|
|
450 |
{
|
|
|
451 |
type: 'submit',
|
|
|
452 |
name: 'save',
|
|
|
453 |
text: 'Save',
|
|
|
454 |
primary: true
|
|
|
455 |
}
|
|
|
456 |
],
|
|
|
457 |
onSubmit: onSubmit(templates),
|
|
|
458 |
onChange: onChange(templates, updateDialog)
|
|
|
459 |
});
|
|
|
460 |
const updateDialog = (dialogApi, template, previewHtml) => {
|
|
|
461 |
const content = getPreviewContent(editor, previewHtml);
|
|
|
462 |
const bodyItems = [
|
|
|
463 |
{
|
|
|
464 |
type: 'listbox',
|
|
|
465 |
name: 'template',
|
|
|
466 |
label: 'Templates',
|
|
|
467 |
items: selectBoxItems
|
|
|
468 |
},
|
|
|
469 |
{
|
|
|
470 |
type: 'htmlpanel',
|
|
|
471 |
html: `<p aria-live="polite">${ htmlEscape(template.value.description) }</p>`
|
|
|
472 |
},
|
|
|
473 |
{
|
|
|
474 |
label: 'Preview',
|
|
|
475 |
type: 'iframe',
|
|
|
476 |
name: 'preview',
|
|
|
477 |
sandboxed: false,
|
|
|
478 |
transparent: false
|
|
|
479 |
}
|
|
|
480 |
];
|
|
|
481 |
const initialData = {
|
|
|
482 |
template: template.text,
|
|
|
483 |
preview: content
|
|
|
484 |
};
|
|
|
485 |
dialogApi.unblock();
|
|
|
486 |
dialogApi.redial(buildDialogSpec(bodyItems, initialData));
|
|
|
487 |
dialogApi.focus('template');
|
|
|
488 |
};
|
|
|
489 |
const dialogApi = editor.windowManager.open(buildDialogSpec([], {
|
|
|
490 |
template: '',
|
|
|
491 |
preview: ''
|
|
|
492 |
}));
|
|
|
493 |
dialogApi.block('Loading...');
|
|
|
494 |
getTemplateContent(templates[0]).then(previewHtml => {
|
|
|
495 |
updateDialog(dialogApi, templates[0], previewHtml);
|
|
|
496 |
}).catch(() => {
|
|
|
497 |
updateDialog(dialogApi, templates[0], '');
|
|
|
498 |
dialogApi.setEnabled('save', false);
|
|
|
499 |
loadFailedAlert(dialogApi);
|
|
|
500 |
});
|
|
|
501 |
};
|
|
|
502 |
const optTemplates = createTemplates();
|
|
|
503 |
optTemplates.each(openDialog);
|
|
|
504 |
};
|
|
|
505 |
|
|
|
506 |
const showDialog = editor => templates => {
|
|
|
507 |
open(editor, templates);
|
|
|
508 |
};
|
|
|
509 |
const register$1 = editor => {
|
|
|
510 |
editor.addCommand('mceInsertTemplate', curry(insertTemplate, editor));
|
|
|
511 |
editor.addCommand('mceTemplate', createTemplateList(editor, showDialog(editor)));
|
|
|
512 |
};
|
|
|
513 |
|
|
|
514 |
const setup = editor => {
|
|
|
515 |
editor.on('PreProcess', o => {
|
|
|
516 |
const dom = editor.dom, dateFormat = getMdateFormat(editor);
|
|
|
517 |
global$2.each(dom.select('div', o.node), e => {
|
|
|
518 |
if (dom.hasClass(e, 'mceTmpl')) {
|
|
|
519 |
global$2.each(dom.select('*', e), e => {
|
|
|
520 |
if (hasAnyClasses(dom, e, getModificationDateClasses(editor))) {
|
|
|
521 |
e.innerHTML = getDateTime(editor, dateFormat);
|
|
|
522 |
}
|
|
|
523 |
});
|
|
|
524 |
replaceVals(editor, e);
|
|
|
525 |
}
|
|
|
526 |
});
|
|
|
527 |
});
|
|
|
528 |
};
|
|
|
529 |
|
|
|
530 |
const onSetupEditable = editor => api => {
|
|
|
531 |
const nodeChanged = () => {
|
|
|
532 |
api.setEnabled(editor.selection.isEditable());
|
|
|
533 |
};
|
|
|
534 |
editor.on('NodeChange', nodeChanged);
|
|
|
535 |
nodeChanged();
|
|
|
536 |
return () => {
|
|
|
537 |
editor.off('NodeChange', nodeChanged);
|
|
|
538 |
};
|
|
|
539 |
};
|
|
|
540 |
const register = editor => {
|
|
|
541 |
const onAction = () => editor.execCommand('mceTemplate');
|
|
|
542 |
editor.ui.registry.addButton('template', {
|
|
|
543 |
icon: 'template',
|
|
|
544 |
tooltip: 'Insert template',
|
|
|
545 |
onSetup: onSetupEditable(editor),
|
|
|
546 |
onAction
|
|
|
547 |
});
|
|
|
548 |
editor.ui.registry.addMenuItem('template', {
|
|
|
549 |
icon: 'template',
|
|
|
550 |
text: 'Insert template...',
|
|
|
551 |
onSetup: onSetupEditable(editor),
|
|
|
552 |
onAction
|
|
|
553 |
});
|
|
|
554 |
};
|
|
|
555 |
|
|
|
556 |
var Plugin = () => {
|
|
|
557 |
global$3.add('template', editor => {
|
|
|
558 |
register$2(editor);
|
|
|
559 |
register(editor);
|
|
|
560 |
register$1(editor);
|
|
|
561 |
setup(editor);
|
|
|
562 |
});
|
|
|
563 |
};
|
|
|
564 |
|
|
|
565 |
Plugin();
|
|
|
566 |
|
|
|
567 |
})();
|