1 |
efrain |
1 |
/**
|
|
|
2 |
* TinyMCE version 6.8.3 (2024-02-08)
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
(function () {
|
|
|
6 |
'use strict';
|
|
|
7 |
|
|
|
8 |
var global = 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$1 = type => value => typeOf(value) === type;
|
|
|
31 |
const isSimpleType = type => value => typeof value === type;
|
|
|
32 |
const isString = isType$1('string');
|
|
|
33 |
const isBoolean = isSimpleType('boolean');
|
|
|
34 |
const isNullable = a => a === null || a === undefined;
|
|
|
35 |
const isNonNullable = a => !isNullable(a);
|
|
|
36 |
const isFunction = isSimpleType('function');
|
|
|
37 |
const isNumber = isSimpleType('number');
|
|
|
38 |
|
|
|
39 |
const compose1 = (fbc, fab) => a => fbc(fab(a));
|
|
|
40 |
const constant = value => {
|
|
|
41 |
return () => {
|
|
|
42 |
return value;
|
|
|
43 |
};
|
|
|
44 |
};
|
|
|
45 |
const never = constant(false);
|
|
|
46 |
|
|
|
47 |
class Optional {
|
|
|
48 |
constructor(tag, value) {
|
|
|
49 |
this.tag = tag;
|
|
|
50 |
this.value = value;
|
|
|
51 |
}
|
|
|
52 |
static some(value) {
|
|
|
53 |
return new Optional(true, value);
|
|
|
54 |
}
|
|
|
55 |
static none() {
|
|
|
56 |
return Optional.singletonNone;
|
|
|
57 |
}
|
|
|
58 |
fold(onNone, onSome) {
|
|
|
59 |
if (this.tag) {
|
|
|
60 |
return onSome(this.value);
|
|
|
61 |
} else {
|
|
|
62 |
return onNone();
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
isSome() {
|
|
|
66 |
return this.tag;
|
|
|
67 |
}
|
|
|
68 |
isNone() {
|
|
|
69 |
return !this.tag;
|
|
|
70 |
}
|
|
|
71 |
map(mapper) {
|
|
|
72 |
if (this.tag) {
|
|
|
73 |
return Optional.some(mapper(this.value));
|
|
|
74 |
} else {
|
|
|
75 |
return Optional.none();
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
bind(binder) {
|
|
|
79 |
if (this.tag) {
|
|
|
80 |
return binder(this.value);
|
|
|
81 |
} else {
|
|
|
82 |
return Optional.none();
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
exists(predicate) {
|
|
|
86 |
return this.tag && predicate(this.value);
|
|
|
87 |
}
|
|
|
88 |
forall(predicate) {
|
|
|
89 |
return !this.tag || predicate(this.value);
|
|
|
90 |
}
|
|
|
91 |
filter(predicate) {
|
|
|
92 |
if (!this.tag || predicate(this.value)) {
|
|
|
93 |
return this;
|
|
|
94 |
} else {
|
|
|
95 |
return Optional.none();
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
getOr(replacement) {
|
|
|
99 |
return this.tag ? this.value : replacement;
|
|
|
100 |
}
|
|
|
101 |
or(replacement) {
|
|
|
102 |
return this.tag ? this : replacement;
|
|
|
103 |
}
|
|
|
104 |
getOrThunk(thunk) {
|
|
|
105 |
return this.tag ? this.value : thunk();
|
|
|
106 |
}
|
|
|
107 |
orThunk(thunk) {
|
|
|
108 |
return this.tag ? this : thunk();
|
|
|
109 |
}
|
|
|
110 |
getOrDie(message) {
|
|
|
111 |
if (!this.tag) {
|
|
|
112 |
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
|
113 |
} else {
|
|
|
114 |
return this.value;
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
static from(value) {
|
|
|
118 |
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
|
119 |
}
|
|
|
120 |
getOrNull() {
|
|
|
121 |
return this.tag ? this.value : null;
|
|
|
122 |
}
|
|
|
123 |
getOrUndefined() {
|
|
|
124 |
return this.value;
|
|
|
125 |
}
|
|
|
126 |
each(worker) {
|
|
|
127 |
if (this.tag) {
|
|
|
128 |
worker(this.value);
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
toArray() {
|
|
|
132 |
return this.tag ? [this.value] : [];
|
|
|
133 |
}
|
|
|
134 |
toString() {
|
|
|
135 |
return this.tag ? `some(${ this.value })` : 'none()';
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
Optional.singletonNone = new Optional(false);
|
|
|
139 |
|
|
|
140 |
const map = (xs, f) => {
|
|
|
141 |
const len = xs.length;
|
|
|
142 |
const r = new Array(len);
|
|
|
143 |
for (let i = 0; i < len; i++) {
|
|
|
144 |
const x = xs[i];
|
|
|
145 |
r[i] = f(x, i);
|
|
|
146 |
}
|
|
|
147 |
return r;
|
|
|
148 |
};
|
|
|
149 |
const each = (xs, f) => {
|
|
|
150 |
for (let i = 0, len = xs.length; i < len; i++) {
|
|
|
151 |
const x = xs[i];
|
|
|
152 |
f(x, i);
|
|
|
153 |
}
|
|
|
154 |
};
|
|
|
155 |
const filter = (xs, pred) => {
|
|
|
156 |
const r = [];
|
|
|
157 |
for (let i = 0, len = xs.length; i < len; i++) {
|
|
|
158 |
const x = xs[i];
|
|
|
159 |
if (pred(x, i)) {
|
|
|
160 |
r.push(x);
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
return r;
|
|
|
164 |
};
|
|
|
165 |
|
|
|
166 |
const DOCUMENT = 9;
|
|
|
167 |
const DOCUMENT_FRAGMENT = 11;
|
|
|
168 |
const ELEMENT = 1;
|
|
|
169 |
const TEXT = 3;
|
|
|
170 |
|
|
|
171 |
const fromHtml = (html, scope) => {
|
|
|
172 |
const doc = scope || document;
|
|
|
173 |
const div = doc.createElement('div');
|
|
|
174 |
div.innerHTML = html;
|
|
|
175 |
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
|
176 |
const message = 'HTML does not have a single root node';
|
|
|
177 |
console.error(message, html);
|
|
|
178 |
throw new Error(message);
|
|
|
179 |
}
|
|
|
180 |
return fromDom(div.childNodes[0]);
|
|
|
181 |
};
|
|
|
182 |
const fromTag = (tag, scope) => {
|
|
|
183 |
const doc = scope || document;
|
|
|
184 |
const node = doc.createElement(tag);
|
|
|
185 |
return fromDom(node);
|
|
|
186 |
};
|
|
|
187 |
const fromText = (text, scope) => {
|
|
|
188 |
const doc = scope || document;
|
|
|
189 |
const node = doc.createTextNode(text);
|
|
|
190 |
return fromDom(node);
|
|
|
191 |
};
|
|
|
192 |
const fromDom = node => {
|
|
|
193 |
if (node === null || node === undefined) {
|
|
|
194 |
throw new Error('Node cannot be null or undefined');
|
|
|
195 |
}
|
|
|
196 |
return { dom: node };
|
|
|
197 |
};
|
|
|
198 |
const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
|
|
|
199 |
const SugarElement = {
|
|
|
200 |
fromHtml,
|
|
|
201 |
fromTag,
|
|
|
202 |
fromText,
|
|
|
203 |
fromDom,
|
|
|
204 |
fromPoint
|
|
|
205 |
};
|
|
|
206 |
|
|
|
207 |
const is = (element, selector) => {
|
|
|
208 |
const dom = element.dom;
|
|
|
209 |
if (dom.nodeType !== ELEMENT) {
|
|
|
210 |
return false;
|
|
|
211 |
} else {
|
|
|
212 |
const elem = dom;
|
|
|
213 |
if (elem.matches !== undefined) {
|
|
|
214 |
return elem.matches(selector);
|
|
|
215 |
} else if (elem.msMatchesSelector !== undefined) {
|
|
|
216 |
return elem.msMatchesSelector(selector);
|
|
|
217 |
} else if (elem.webkitMatchesSelector !== undefined) {
|
|
|
218 |
return elem.webkitMatchesSelector(selector);
|
|
|
219 |
} else if (elem.mozMatchesSelector !== undefined) {
|
|
|
220 |
return elem.mozMatchesSelector(selector);
|
|
|
221 |
} else {
|
|
|
222 |
throw new Error('Browser lacks native selectors');
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
};
|
|
|
226 |
|
|
|
227 |
typeof window !== 'undefined' ? window : Function('return this;')();
|
|
|
228 |
|
|
|
229 |
const name = element => {
|
|
|
230 |
const r = element.dom.nodeName;
|
|
|
231 |
return r.toLowerCase();
|
|
|
232 |
};
|
|
|
233 |
const type = element => element.dom.nodeType;
|
|
|
234 |
const isType = t => element => type(element) === t;
|
|
|
235 |
const isElement = isType(ELEMENT);
|
|
|
236 |
const isText = isType(TEXT);
|
|
|
237 |
const isDocument = isType(DOCUMENT);
|
|
|
238 |
const isDocumentFragment = isType(DOCUMENT_FRAGMENT);
|
|
|
239 |
const isTag = tag => e => isElement(e) && name(e) === tag;
|
|
|
240 |
|
|
|
241 |
const owner = element => SugarElement.fromDom(element.dom.ownerDocument);
|
|
|
242 |
const documentOrOwner = dos => isDocument(dos) ? dos : owner(dos);
|
|
|
243 |
const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
|
|
|
244 |
const children$2 = element => map(element.dom.childNodes, SugarElement.fromDom);
|
|
|
245 |
|
|
|
246 |
const rawSet = (dom, key, value) => {
|
|
|
247 |
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
|
248 |
dom.setAttribute(key, value + '');
|
|
|
249 |
} else {
|
|
|
250 |
console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
|
251 |
throw new Error('Attribute value was not simple');
|
|
|
252 |
}
|
|
|
253 |
};
|
|
|
254 |
const set = (element, key, value) => {
|
|
|
255 |
rawSet(element.dom, key, value);
|
|
|
256 |
};
|
|
|
257 |
const remove = (element, key) => {
|
|
|
258 |
element.dom.removeAttribute(key);
|
|
|
259 |
};
|
|
|
260 |
|
|
|
261 |
const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
|
|
|
262 |
const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
|
|
|
263 |
const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner;
|
|
|
264 |
const getShadowRoot = e => {
|
|
|
265 |
const r = getRootNode(e);
|
|
|
266 |
return isShadowRoot(r) ? Optional.some(r) : Optional.none();
|
|
|
267 |
};
|
|
|
268 |
const getShadowHost = e => SugarElement.fromDom(e.dom.host);
|
|
|
269 |
|
|
|
270 |
const inBody = element => {
|
|
|
271 |
const dom = isText(element) ? element.dom.parentNode : element.dom;
|
|
|
272 |
if (dom === undefined || dom === null || dom.ownerDocument === null) {
|
|
|
273 |
return false;
|
|
|
274 |
}
|
|
|
275 |
const doc = dom.ownerDocument;
|
|
|
276 |
return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
|
|
|
277 |
};
|
|
|
278 |
|
|
|
279 |
const ancestor$1 = (scope, predicate, isRoot) => {
|
|
|
280 |
let element = scope.dom;
|
|
|
281 |
const stop = isFunction(isRoot) ? isRoot : never;
|
|
|
282 |
while (element.parentNode) {
|
|
|
283 |
element = element.parentNode;
|
|
|
284 |
const el = SugarElement.fromDom(element);
|
|
|
285 |
if (predicate(el)) {
|
|
|
286 |
return Optional.some(el);
|
|
|
287 |
} else if (stop(el)) {
|
|
|
288 |
break;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
return Optional.none();
|
|
|
292 |
};
|
|
|
293 |
|
|
|
294 |
const ancestor = (scope, selector, isRoot) => ancestor$1(scope, e => is(e, selector), isRoot);
|
|
|
295 |
|
|
|
296 |
const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
|
297 |
|
|
|
298 |
const get = (element, property) => {
|
|
|
299 |
const dom = element.dom;
|
|
|
300 |
const styles = window.getComputedStyle(dom);
|
|
|
301 |
const r = styles.getPropertyValue(property);
|
|
|
302 |
return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
|
|
|
303 |
};
|
|
|
304 |
const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';
|
|
|
305 |
|
|
|
306 |
const getDirection = element => get(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
|
|
|
307 |
|
|
|
308 |
const children$1 = (scope, predicate) => filter(children$2(scope), predicate);
|
|
|
309 |
|
|
|
310 |
const children = (scope, selector) => children$1(scope, e => is(e, selector));
|
|
|
311 |
|
|
|
312 |
const getParentElement = element => parent(element).filter(isElement);
|
|
|
313 |
const getNormalizedBlock = (element, isListItem) => {
|
|
|
314 |
const normalizedElement = isListItem ? ancestor(element, 'ol,ul') : Optional.some(element);
|
|
|
315 |
return normalizedElement.getOr(element);
|
|
|
316 |
};
|
|
|
317 |
const isListItem = isTag('li');
|
|
|
318 |
const setDirOnElements = (dom, blocks, dir) => {
|
|
|
319 |
each(blocks, block => {
|
|
|
320 |
const blockElement = SugarElement.fromDom(block);
|
|
|
321 |
const isBlockElementListItem = isListItem(blockElement);
|
|
|
322 |
const normalizedBlock = getNormalizedBlock(blockElement, isBlockElementListItem);
|
|
|
323 |
const normalizedBlockParent = getParentElement(normalizedBlock);
|
|
|
324 |
normalizedBlockParent.each(parent => {
|
|
|
325 |
dom.setStyle(normalizedBlock.dom, 'direction', null);
|
|
|
326 |
const parentDirection = getDirection(parent);
|
|
|
327 |
if (parentDirection === dir) {
|
|
|
328 |
remove(normalizedBlock, 'dir');
|
|
|
329 |
} else {
|
|
|
330 |
set(normalizedBlock, 'dir', dir);
|
|
|
331 |
}
|
|
|
332 |
if (getDirection(normalizedBlock) !== dir) {
|
|
|
333 |
dom.setStyle(normalizedBlock.dom, 'direction', dir);
|
|
|
334 |
}
|
|
|
335 |
if (isBlockElementListItem) {
|
|
|
336 |
const listItems = children(normalizedBlock, 'li[dir],li[style]');
|
|
|
337 |
each(listItems, listItem => {
|
|
|
338 |
remove(listItem, 'dir');
|
|
|
339 |
dom.setStyle(listItem.dom, 'direction', null);
|
|
|
340 |
});
|
|
|
341 |
}
|
|
|
342 |
});
|
|
|
343 |
});
|
|
|
344 |
};
|
|
|
345 |
const setDir = (editor, dir) => {
|
|
|
346 |
if (editor.selection.isEditable()) {
|
|
|
347 |
setDirOnElements(editor.dom, editor.selection.getSelectedBlocks(), dir);
|
|
|
348 |
editor.nodeChanged();
|
|
|
349 |
}
|
|
|
350 |
};
|
|
|
351 |
|
|
|
352 |
const register$1 = editor => {
|
|
|
353 |
editor.addCommand('mceDirectionLTR', () => {
|
|
|
354 |
setDir(editor, 'ltr');
|
|
|
355 |
});
|
|
|
356 |
editor.addCommand('mceDirectionRTL', () => {
|
|
|
357 |
setDir(editor, 'rtl');
|
|
|
358 |
});
|
|
|
359 |
};
|
|
|
360 |
|
|
|
361 |
const getNodeChangeHandler = (editor, dir) => api => {
|
|
|
362 |
const nodeChangeHandler = e => {
|
|
|
363 |
const element = SugarElement.fromDom(e.element);
|
|
|
364 |
api.setActive(getDirection(element) === dir);
|
|
|
365 |
api.setEnabled(editor.selection.isEditable());
|
|
|
366 |
};
|
|
|
367 |
editor.on('NodeChange', nodeChangeHandler);
|
|
|
368 |
api.setEnabled(editor.selection.isEditable());
|
|
|
369 |
return () => editor.off('NodeChange', nodeChangeHandler);
|
|
|
370 |
};
|
|
|
371 |
const register = editor => {
|
|
|
372 |
editor.ui.registry.addToggleButton('ltr', {
|
|
|
373 |
tooltip: 'Left to right',
|
|
|
374 |
icon: 'ltr',
|
|
|
375 |
onAction: () => editor.execCommand('mceDirectionLTR'),
|
|
|
376 |
onSetup: getNodeChangeHandler(editor, 'ltr')
|
|
|
377 |
});
|
|
|
378 |
editor.ui.registry.addToggleButton('rtl', {
|
|
|
379 |
tooltip: 'Right to left',
|
|
|
380 |
icon: 'rtl',
|
|
|
381 |
onAction: () => editor.execCommand('mceDirectionRTL'),
|
|
|
382 |
onSetup: getNodeChangeHandler(editor, 'rtl')
|
|
|
383 |
});
|
|
|
384 |
};
|
|
|
385 |
|
|
|
386 |
var Plugin = () => {
|
|
|
387 |
global.add('directionality', editor => {
|
|
|
388 |
register$1(editor);
|
|
|
389 |
register(editor);
|
|
|
390 |
});
|
|
|
391 |
};
|
|
|
392 |
|
|
|
393 |
Plugin();
|
|
|
394 |
|
|
|
395 |
})();
|