Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
1441 ariadna 2
 * TinyMCE version 7.7.1 (2025-03-05)
1 efrain 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_FRAGMENT = 11;
167
    const ELEMENT = 1;
168
    const TEXT = 3;
169
 
170
    const fromHtml = (html, scope) => {
171
      const doc = scope || document;
172
      const div = doc.createElement('div');
173
      div.innerHTML = html;
174
      if (!div.hasChildNodes() || div.childNodes.length > 1) {
175
        const message = 'HTML does not have a single root node';
176
        console.error(message, html);
177
        throw new Error(message);
178
      }
179
      return fromDom(div.childNodes[0]);
180
    };
181
    const fromTag = (tag, scope) => {
182
      const doc = scope || document;
183
      const node = doc.createElement(tag);
184
      return fromDom(node);
185
    };
186
    const fromText = (text, scope) => {
187
      const doc = scope || document;
188
      const node = doc.createTextNode(text);
189
      return fromDom(node);
190
    };
191
    const fromDom = node => {
192
      if (node === null || node === undefined) {
193
        throw new Error('Node cannot be null or undefined');
194
      }
195
      return { dom: node };
196
    };
197
    const fromPoint = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
198
    const SugarElement = {
199
      fromHtml,
200
      fromTag,
201
      fromText,
202
      fromDom,
203
      fromPoint
204
    };
205
 
206
    const is = (element, selector) => {
207
      const dom = element.dom;
208
      if (dom.nodeType !== ELEMENT) {
209
        return false;
210
      } else {
211
        const elem = dom;
212
        if (elem.matches !== undefined) {
213
          return elem.matches(selector);
214
        } else if (elem.msMatchesSelector !== undefined) {
215
          return elem.msMatchesSelector(selector);
216
        } else if (elem.webkitMatchesSelector !== undefined) {
217
          return elem.webkitMatchesSelector(selector);
218
        } else if (elem.mozMatchesSelector !== undefined) {
219
          return elem.mozMatchesSelector(selector);
220
        } else {
221
          throw new Error('Browser lacks native selectors');
222
        }
223
      }
224
    };
225
 
226
    typeof window !== 'undefined' ? window : Function('return this;')();
227
 
228
    const name = element => {
229
      const r = element.dom.nodeName;
230
      return r.toLowerCase();
231
    };
232
    const type = element => element.dom.nodeType;
233
    const isType = t => element => type(element) === t;
234
    const isElement = isType(ELEMENT);
235
    const isText = isType(TEXT);
236
    const isDocumentFragment = isType(DOCUMENT_FRAGMENT);
237
    const isTag = tag => e => isElement(e) && name(e) === tag;
238
 
239
    const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
240
    const children$2 = element => map(element.dom.childNodes, SugarElement.fromDom);
241
 
242
    const rawSet = (dom, key, value) => {
243
      if (isString(value) || isBoolean(value) || isNumber(value)) {
244
        dom.setAttribute(key, value + '');
245
      } else {
246
        console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
247
        throw new Error('Attribute value was not simple');
248
      }
249
    };
250
    const set = (element, key, value) => {
251
      rawSet(element.dom, key, value);
252
    };
253
    const remove = (element, key) => {
254
      element.dom.removeAttribute(key);
255
    };
256
 
257
    const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host);
1441 ariadna 258
    const getRootNode = e => SugarElement.fromDom(e.dom.getRootNode());
1 efrain 259
    const getShadowRoot = e => {
260
      const r = getRootNode(e);
261
      return isShadowRoot(r) ? Optional.some(r) : Optional.none();
262
    };
263
    const getShadowHost = e => SugarElement.fromDom(e.dom.host);
264
 
265
    const inBody = element => {
266
      const dom = isText(element) ? element.dom.parentNode : element.dom;
267
      if (dom === undefined || dom === null || dom.ownerDocument === null) {
268
        return false;
269
      }
270
      const doc = dom.ownerDocument;
271
      return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
272
    };
273
 
274
    const ancestor$1 = (scope, predicate, isRoot) => {
275
      let element = scope.dom;
276
      const stop = isFunction(isRoot) ? isRoot : never;
277
      while (element.parentNode) {
278
        element = element.parentNode;
279
        const el = SugarElement.fromDom(element);
280
        if (predicate(el)) {
281
          return Optional.some(el);
282
        } else if (stop(el)) {
283
          break;
284
        }
285
      }
286
      return Optional.none();
287
    };
288
 
289
    const ancestor = (scope, selector, isRoot) => ancestor$1(scope, e => is(e, selector), isRoot);
290
 
291
    const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
292
 
293
    const get = (element, property) => {
294
      const dom = element.dom;
295
      const styles = window.getComputedStyle(dom);
296
      const r = styles.getPropertyValue(property);
297
      return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
298
    };
299
    const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';
300
 
301
    const getDirection = element => get(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
302
 
303
    const children$1 = (scope, predicate) => filter(children$2(scope), predicate);
304
 
305
    const children = (scope, selector) => children$1(scope, e => is(e, selector));
306
 
307
    const getParentElement = element => parent(element).filter(isElement);
308
    const getNormalizedBlock = (element, isListItem) => {
309
      const normalizedElement = isListItem ? ancestor(element, 'ol,ul') : Optional.some(element);
310
      return normalizedElement.getOr(element);
311
    };
312
    const isListItem = isTag('li');
313
    const setDirOnElements = (dom, blocks, dir) => {
314
      each(blocks, block => {
315
        const blockElement = SugarElement.fromDom(block);
316
        const isBlockElementListItem = isListItem(blockElement);
317
        const normalizedBlock = getNormalizedBlock(blockElement, isBlockElementListItem);
318
        const normalizedBlockParent = getParentElement(normalizedBlock);
319
        normalizedBlockParent.each(parent => {
320
          dom.setStyle(normalizedBlock.dom, 'direction', null);
321
          const parentDirection = getDirection(parent);
322
          if (parentDirection === dir) {
323
            remove(normalizedBlock, 'dir');
324
          } else {
325
            set(normalizedBlock, 'dir', dir);
326
          }
327
          if (getDirection(normalizedBlock) !== dir) {
328
            dom.setStyle(normalizedBlock.dom, 'direction', dir);
329
          }
330
          if (isBlockElementListItem) {
331
            const listItems = children(normalizedBlock, 'li[dir],li[style]');
332
            each(listItems, listItem => {
333
              remove(listItem, 'dir');
334
              dom.setStyle(listItem.dom, 'direction', null);
335
            });
336
          }
337
        });
338
      });
339
    };
340
    const setDir = (editor, dir) => {
341
      if (editor.selection.isEditable()) {
342
        setDirOnElements(editor.dom, editor.selection.getSelectedBlocks(), dir);
343
        editor.nodeChanged();
344
      }
345
    };
346
 
347
    const register$1 = editor => {
348
      editor.addCommand('mceDirectionLTR', () => {
349
        setDir(editor, 'ltr');
350
      });
351
      editor.addCommand('mceDirectionRTL', () => {
352
        setDir(editor, 'rtl');
353
      });
354
    };
355
 
356
    const getNodeChangeHandler = (editor, dir) => api => {
357
      const nodeChangeHandler = e => {
358
        const element = SugarElement.fromDom(e.element);
359
        api.setActive(getDirection(element) === dir);
360
        api.setEnabled(editor.selection.isEditable());
361
      };
362
      editor.on('NodeChange', nodeChangeHandler);
363
      api.setEnabled(editor.selection.isEditable());
364
      return () => editor.off('NodeChange', nodeChangeHandler);
365
    };
366
    const register = editor => {
367
      editor.ui.registry.addToggleButton('ltr', {
368
        tooltip: 'Left to right',
369
        icon: 'ltr',
370
        onAction: () => editor.execCommand('mceDirectionLTR'),
371
        onSetup: getNodeChangeHandler(editor, 'ltr')
372
      });
373
      editor.ui.registry.addToggleButton('rtl', {
374
        tooltip: 'Right to left',
375
        icon: 'rtl',
376
        onAction: () => editor.execCommand('mceDirectionRTL'),
377
        onSetup: getNodeChangeHandler(editor, 'rtl')
378
      });
379
    };
380
 
381
    var Plugin = () => {
382
      global.add('directionality', editor => {
383
        register$1(editor);
384
        register(editor);
385
      });
386
    };
387
 
388
    Plugin();
389
 
390
})();