Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
/**
1
/**
2
 * TinyMCE version 6.8.3 (2024-02-08)
2
 * TinyMCE version 7.7.1 (2025-03-05)
3
 */
3
 */
Línea 4... Línea 4...
4
 
4
 
5
(function () {
5
(function () {
Línea 277... Línea 277...
277
      });
277
      });
278
      registerOption('link_quicklink', {
278
      registerOption('link_quicklink', {
279
        processor: 'boolean',
279
        processor: 'boolean',
280
        default: false
280
        default: false
281
      });
281
      });
-
 
282
      registerOption('link_attributes_postprocess', { processor: 'function' });
282
    };
283
    };
283
    const assumeExternalTargets = option('link_assume_external_targets');
284
    const assumeExternalTargets = option('link_assume_external_targets');
284
    const hasContextToolbar = option('link_context_toolbar');
285
    const hasContextToolbar = option('link_context_toolbar');
285
    const getLinkList = option('link_list');
286
    const getLinkList = option('link_list');
286
    const getDefaultLinkTarget = option('link_default_target');
287
    const getDefaultLinkTarget = option('link_default_target');
Línea 289... Línea 290...
289
    const getRelList = option('link_rel_list');
290
    const getRelList = option('link_rel_list');
290
    const getLinkClassList = option('link_class_list');
291
    const getLinkClassList = option('link_class_list');
291
    const shouldShowLinkTitle = option('link_title');
292
    const shouldShowLinkTitle = option('link_title');
292
    const allowUnsafeLinkTarget = option('allow_unsafe_link_target');
293
    const allowUnsafeLinkTarget = option('allow_unsafe_link_target');
293
    const useQuickLink = option('link_quicklink');
294
    const useQuickLink = option('link_quicklink');
294
 
-
 
295
    var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');
-
 
296
 
-
 
297
    const getValue = item => isString(item.value) ? item.value : '';
295
    const attributesPostProcess = option('link_attributes_postprocess');
298
    const getText = item => {
-
 
299
      if (isString(item.text)) {
-
 
300
        return item.text;
-
 
301
      } else if (isString(item.title)) {
-
 
302
        return item.title;
-
 
303
      } else {
-
 
304
        return '';
-
 
305
      }
-
 
306
    };
-
 
307
    const sanitizeList = (list, extractValue) => {
-
 
308
      const out = [];
-
 
309
      global$4.each(list, item => {
-
 
310
        const text = getText(item);
-
 
311
        if (item.menu !== undefined) {
-
 
312
          const items = sanitizeList(item.menu, extractValue);
-
 
313
          out.push({
-
 
314
            text,
-
 
315
            items
-
 
316
          });
-
 
317
        } else {
-
 
318
          const value = extractValue(item);
-
 
319
          out.push({
-
 
320
            text,
-
 
321
            value
-
 
322
          });
-
 
323
        }
-
 
324
      });
-
 
325
      return out;
-
 
326
    };
-
 
327
    const sanitizeWith = (extracter = getValue) => list => Optional.from(list).map(list => sanitizeList(list, extracter));
-
 
328
    const sanitize = list => sanitizeWith(getValue)(list);
-
 
329
    const createUi = (name, label) => items => ({
-
 
330
      name,
-
 
331
      type: 'listbox',
-
 
332
      label,
-
 
333
      items
-
 
334
    });
-
 
335
    const ListOptions = {
-
 
336
      sanitize,
-
 
337
      sanitizeWith,
-
 
338
      createUi,
-
 
339
      getValue
-
 
340
    };
-
 
Línea 341... Línea 296...
341
 
296
 
342
    const keys = Object.keys;
297
    const keys = Object.keys;
343
    const hasOwnProperty = Object.hasOwnProperty;
298
    const hasOwnProperty = Object.hasOwnProperty;
344
    const each = (obj, f) => {
299
    const each = (obj, f) => {
Línea 363... Línea 318...
363
      return t;
318
      return t;
364
    };
319
    };
365
    const has = (obj, key) => hasOwnProperty.call(obj, key);
320
    const has = (obj, key) => hasOwnProperty.call(obj, key);
366
    const hasNonNullableKey = (obj, key) => has(obj, key) && obj[key] !== undefined && obj[key] !== null;
321
    const hasNonNullableKey = (obj, key) => has(obj, key) && obj[key] !== undefined && obj[key] !== null;
Línea -... Línea 322...
-
 
322
 
-
 
323
    var global$4 = tinymce.util.Tools.resolve('tinymce.util.URI');
367
 
324
 
Línea 368... Línea 325...
368
    var global$3 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker');
325
    var global$3 = tinymce.util.Tools.resolve('tinymce.dom.TreeWalker');
Línea 369... Línea 326...
369
 
326
 
370
    var global$2 = tinymce.util.Tools.resolve('tinymce.util.URI');
327
    var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
371
 
328
 
372
    const isAnchor = elm => isNonNullable(elm) && elm.nodeName.toLowerCase() === 'a';
329
    const isAnchor = elm => isNonNullable(elm) && elm.nodeName.toLowerCase() === 'a';
Línea 394... Línea 351...
394
      return (_b = (_a = elm.getAttribute('data-mce-href')) !== null && _a !== void 0 ? _a : elm.getAttribute('href')) !== null && _b !== void 0 ? _b : '';
351
      return (_b = (_a = elm.getAttribute('data-mce-href')) !== null && _a !== void 0 ? _a : elm.getAttribute('href')) !== null && _b !== void 0 ? _b : '';
395
    };
352
    };
396
    const applyRelTargetRules = (rel, isUnsafe) => {
353
    const applyRelTargetRules = (rel, isUnsafe) => {
397
      const rules = ['noopener'];
354
      const rules = ['noopener'];
398
      const rels = rel ? rel.split(/\s+/) : [];
355
      const rels = rel ? rel.split(/\s+/) : [];
399
      const toString = rels => global$4.trim(rels.sort().join(' '));
356
      const toString = rels => global$2.trim(rels.sort().join(' '));
400
      const addTargetRules = rels => {
357
      const addTargetRules = rels => {
401
        rels = removeTargetRules(rels);
358
        rels = removeTargetRules(rels);
402
        return rels.length > 0 ? rels.concat(rules) : rules;
359
        return rels.length > 0 ? rels.concat(rules) : rules;
403
      };
360
      };
404
      const removeTargetRules = rels => rels.filter(val => global$4.inArray(rules, val) === -1);
361
      const removeTargetRules = rels => rels.filter(val => global$2.inArray(rules, val) === -1);
405
      const newRels = isUnsafe ? addTargetRules(rels) : removeTargetRules(rels);
362
      const newRels = isUnsafe ? addTargetRules(rels) : removeTargetRules(rels);
406
      return newRels.length > 0 ? toString(newRels) : '';
363
      return newRels.length > 0 ? toString(newRels) : '';
407
    };
364
    };
408
    const trimCaretContainers = text => text.replace(/\uFEFF/g, '');
365
    const trimCaretContainers = text => text.replace(/\uFEFF/g, '');
409
    const getAnchorElement = (editor, selectedElm) => {
366
    const getAnchorElement = (editor, selectedElm) => {
Línea 418... Línea 375...
418
    const getAnchorText = (selection, anchorElm) => {
375
    const getAnchorText = (selection, anchorElm) => {
419
      const text = anchorElm.fold(() => selection.getContent({ format: 'text' }), anchorElm => anchorElm.innerText || anchorElm.textContent || '');
376
      const text = anchorElm.fold(() => selection.getContent({ format: 'text' }), anchorElm => anchorElm.innerText || anchorElm.textContent || '');
420
      return trimCaretContainers(text);
377
      return trimCaretContainers(text);
421
    };
378
    };
422
    const getLinksInSelection = rng => collectNodesInRange(rng, isLink);
379
    const getLinksInSelection = rng => collectNodesInRange(rng, isLink);
423
    const getLinks$1 = elements => global$4.grep(elements, isLink);
380
    const getLinks$1 = elements => global$2.grep(elements, isLink);
424
    const hasLinks = elements => getLinks$1(elements).length > 0;
381
    const hasLinks = elements => getLinks$1(elements).length > 0;
425
    const hasLinksInSelection = rng => getLinksInSelection(rng).length > 0;
382
    const hasLinksInSelection = rng => getLinksInSelection(rng).length > 0;
426
    const isOnlyTextSelected = editor => {
383
    const isOnlyTextSelected = editor => {
427
      const inlineTextElements = editor.schema.getTextInlineElements();
384
      const inlineTextElements = editor.schema.getTextInlineElements();
428
      const isElement = elm => elm.nodeType === 1 && !isAnchor(elm) && !has(inlineTextElements, elm.nodeName.toLowerCase());
385
      const isElement = elm => elm.nodeType === 1 && !isAnchor(elm) && !has(inlineTextElements, elm.nodeName.toLowerCase());
Línea 437... Línea 394...
437
      } else {
394
      } else {
438
        return true;
395
        return true;
439
      }
396
      }
440
    };
397
    };
441
    const isImageFigure = elm => isNonNullable(elm) && elm.nodeName === 'FIGURE' && /\bimage\b/i.test(elm.className);
398
    const isImageFigure = elm => isNonNullable(elm) && elm.nodeName === 'FIGURE' && /\bimage\b/i.test(elm.className);
-
 
399
 
442
    const getLinkAttrs = data => {
400
    const getLinkAttrs = data => {
443
      const attrs = [
401
      const attrs = [
444
        'title',
402
        'title',
445
        'rel',
403
        'rel',
446
        'class',
404
        'class',
Línea 478... Línea 436...
478
        } else {
436
        } else {
479
          anchorElm.textContent = text;
437
          anchorElm.textContent = text;
480
        }
438
        }
481
      });
439
      });
482
      editor.dom.setAttribs(anchorElm, linkAttrs);
440
      editor.dom.setAttribs(anchorElm, linkAttrs);
-
 
441
      const rng = editor.dom.createRng();
-
 
442
      rng.setStartAfter(anchorElm);
-
 
443
      rng.setEndAfter(anchorElm);
483
      editor.selection.select(anchorElm);
444
      editor.selection.setRng(rng);
484
    };
445
    };
485
    const createLink = (editor, selectedElm, text, linkAttrs) => {
446
    const createLink = (editor, selectedElm, text, linkAttrs) => {
486
      const dom = editor.dom;
447
      const dom = editor.dom;
487
      if (isImageFigure(selectedElm)) {
448
      if (isImageFigure(selectedElm)) {
488
        linkImageFigure(dom, selectedElm, linkAttrs);
449
        linkImageFigure(dom, selectedElm, linkAttrs);
489
      } else {
450
      } else {
490
        text.fold(() => {
451
        text.fold(() => {
491
          editor.execCommand('mceInsertLink', false, linkAttrs);
452
          editor.execCommand('mceInsertLink', false, linkAttrs);
-
 
453
          const end = editor.selection.getEnd();
-
 
454
          const rng = dom.createRng();
-
 
455
          rng.setStartAfter(end);
-
 
456
          rng.setEndAfter(end);
-
 
457
          editor.selection.setRng(rng);
492
        }, text => {
458
        }, text => {
493
          editor.insertContent(dom.createHTML('a', linkAttrs, dom.encode(text)));
459
          editor.insertContent(dom.createHTML('a', linkAttrs, dom.encode(text)));
494
        });
460
        });
495
      }
461
      }
496
    };
462
    };
497
    const linkDomMutation = (editor, attachState, data) => {
463
    const linkDomMutation = (editor, attachState, data) => {
498
      const selectedElm = editor.selection.getNode();
464
      const selectedElm = editor.selection.getNode();
499
      const anchorElm = getAnchorElement(editor, selectedElm);
465
      const anchorElm = getAnchorElement(editor, selectedElm);
500
      const linkAttrs = applyLinkOverrides(editor, getLinkAttrs(data));
466
      const linkAttrs = applyLinkOverrides(editor, getLinkAttrs(data));
-
 
467
      const attributesPostProcess$1 = attributesPostProcess(editor);
-
 
468
      if (isNonNullable(attributesPostProcess$1)) {
-
 
469
        attributesPostProcess$1(linkAttrs);
-
 
470
      }
501
      editor.undoManager.transact(() => {
471
      editor.undoManager.transact(() => {
502
        if (data.href === attachState.href) {
472
        if (data.href === attachState.href) {
503
          attachState.attach();
473
          attachState.attach();
504
        }
474
        }
505
        anchorElm.fold(() => {
475
        anchorElm.fold(() => {
Línea 563... Línea 533...
563
        allow_svg_data_urls: getOption('allow_svg_data_urls')
533
        allow_svg_data_urls: getOption('allow_svg_data_urls')
564
      };
534
      };
565
      const href = data.href;
535
      const href = data.href;
566
      return {
536
      return {
567
        ...data,
537
        ...data,
568
        href: global$2.isDomSafe(href, 'a', uriOptions) ? href : ''
538
        href: global$4.isDomSafe(href, 'a', uriOptions) ? href : ''
569
      };
539
      };
570
    };
540
    };
571
    const link = (editor, attachState, data) => {
541
    const link = (editor, attachState, data) => {
572
      const sanitizedData = sanitizeData(editor, data);
542
      const sanitizedData = sanitizeData(editor, data);
573
      editor.hasPlugin('rtc', true) ? editor.execCommand('createlink', false, unwrapOptions(sanitizedData)) : linkDomMutation(editor, attachState, sanitizedData);
543
      editor.hasPlugin('rtc', true) ? editor.execCommand('createlink', false, unwrapOptions(sanitizedData)) : linkDomMutation(editor, attachState, sanitizedData);
Línea 594... Línea 564...
594
        (_a = img.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(a, img);
564
        (_a = img.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(a, img);
595
        a.appendChild(img);
565
        a.appendChild(img);
596
      }
566
      }
597
    };
567
    };
Línea -... Línea 568...
-
 
568
 
-
 
569
    const getValue = item => isString(item.value) ? item.value : '';
-
 
570
    const getText = item => {
-
 
571
      if (isString(item.text)) {
-
 
572
        return item.text;
-
 
573
      } else if (isString(item.title)) {
-
 
574
        return item.title;
-
 
575
      } else {
-
 
576
        return '';
-
 
577
      }
-
 
578
    };
-
 
579
    const sanitizeList = (list, extractValue) => {
-
 
580
      const out = [];
-
 
581
      global$2.each(list, item => {
-
 
582
        const text = getText(item);
-
 
583
        if (item.menu !== undefined) {
-
 
584
          const items = sanitizeList(item.menu, extractValue);
-
 
585
          out.push({
-
 
586
            text,
-
 
587
            items
-
 
588
          });
-
 
589
        } else {
-
 
590
          const value = extractValue(item);
-
 
591
          out.push({
-
 
592
            text,
-
 
593
            value
-
 
594
          });
-
 
595
        }
-
 
596
      });
-
 
597
      return out;
-
 
598
    };
-
 
599
    const sanitizeWith = (extracter = getValue) => list => Optional.from(list).map(list => sanitizeList(list, extracter));
-
 
600
    const sanitize = list => sanitizeWith(getValue)(list);
-
 
601
    const createUi = (name, label) => items => ({
-
 
602
      name,
-
 
603
      type: 'listbox',
-
 
604
      label,
-
 
605
      items
-
 
606
    });
-
 
607
    const ListOptions = {
-
 
608
      sanitize,
-
 
609
      sanitizeWith,
-
 
610
      createUi,
-
 
611
      getValue
-
 
612
    };
598
 
613
 
599
    const isListGroup = item => hasNonNullableKey(item, 'items');
614
    const isListGroup = item => hasNonNullableKey(item, 'items');
600
    const findTextByValue = (value, catalog) => findMap(catalog, item => {
615
    const findTextByValue = (value, catalog) => findMap(catalog, item => {
601
      if (isListGroup(item)) {
616
      if (isListGroup(item)) {
602
        return findTextByValue(value, item.items);
617
        return findTextByValue(value, item.items);
Línea 748... Línea 763...
748
    const ClassListOptions = { getClasses };
763
    const ClassListOptions = { getClasses };
Línea 749... Línea 764...
749
 
764
 
750
    const parseJson = text => {
765
    const parseJson = text => {
751
      try {
766
      try {
752
        return Optional.some(JSON.parse(text));
767
        return Optional.some(JSON.parse(text));
753
      } catch (err) {
768
      } catch (_a) {
754
        return Optional.none();
769
        return Optional.none();
755
      }
770
      }
756
    };
771
    };
757
    const getLinks = editor => {
772
    const getLinks = editor => {
Línea 959... Línea 974...
959
          });
974
          });
960
        },
975
        },
961
        onSubmit
976
        onSubmit
962
      };
977
      };
963
    };
978
    };
964
    const open$1 = editor => {
979
    const open = editor => {
965
      const data = collectData(editor);
980
      const data = collectData(editor);
966
      data.then(info => {
981
      data.then(info => {
967
        const onSubmit = handleSubmit(editor, info);
982
        const onSubmit = handleSubmit(editor, info);
968
        return makeDialog(info, onSubmit, editor);
983
        return makeDialog(info, onSubmit, editor);
969
      }).then(spec => {
984
      }).then(spec => {
Línea 972... Línea 987...
972
    };
987
    };
Línea 973... Línea 988...
973
 
988
 
974
    const register = editor => {
989
    const register = editor => {
975
      editor.addCommand('mceLink', (_ui, value) => {
990
      editor.addCommand('mceLink', (_ui, value) => {
976
        if ((value === null || value === void 0 ? void 0 : value.dialog) === true || !useQuickLink(editor)) {
991
        if ((value === null || value === void 0 ? void 0 : value.dialog) === true || !useQuickLink(editor)) {
977
          open$1(editor);
992
          open(editor);
978
        } else {
993
        } else {
979
          editor.dispatch('contexttoolbar-show', { toolbarKey: 'quicklink' });
994
          editor.dispatch('contexttoolbar-show', { toolbarKey: 'quicklink' });
980
        }
995
        }
981
      });
996
      });
Línea -... Línea 997...
-
 
997
    };
-
 
998
 
-
 
999
    const setup$2 = editor => {
-
 
1000
      editor.addShortcut('Meta+K', '', () => {
-
 
1001
        editor.execCommand('mceLink');
-
 
1002
      });
-
 
1003
    };
-
 
1004
 
-
 
1005
    const Cell = initial => {
-
 
1006
      let value = initial;
-
 
1007
      const get = () => {
-
 
1008
        return value;
-
 
1009
      };
-
 
1010
      const set = v => {
-
 
1011
        value = v;
-
 
1012
      };
-
 
1013
      return {
-
 
1014
        get,
-
 
1015
        set
-
 
1016
      };
-
 
1017
    };
-
 
1018
 
-
 
1019
    const singleton = doRevoke => {
-
 
1020
      const subject = Cell(Optional.none());
-
 
1021
      const revoke = () => subject.get().each(doRevoke);
-
 
1022
      const clear = () => {
-
 
1023
        revoke();
-
 
1024
        subject.set(Optional.none());
-
 
1025
      };
-
 
1026
      const isSet = () => subject.get().isSome();
-
 
1027
      const get = () => subject.get();
-
 
1028
      const set = s => {
-
 
1029
        revoke();
-
 
1030
        subject.set(Optional.some(s));
-
 
1031
      };
-
 
1032
      return {
-
 
1033
        clear,
-
 
1034
        isSet,
-
 
1035
        get,
-
 
1036
        set
-
 
1037
      };
-
 
1038
    };
-
 
1039
    const value = () => {
-
 
1040
      const subject = singleton(noop);
-
 
1041
      const on = f => subject.get().each(f);
-
 
1042
      return {
-
 
1043
        ...subject,
-
 
1044
        on
-
 
1045
      };
-
 
1046
    };
-
 
1047
 
-
 
1048
    const removeFromStart = (str, numChars) => {
-
 
1049
      return str.substring(numChars);
-
 
1050
    };
-
 
1051
 
-
 
1052
    const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
-
 
1053
    const removeLeading = (str, prefix) => {
-
 
1054
      return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
-
 
1055
    };
-
 
1056
    const startsWith = (str, prefix) => {
-
 
1057
      return checkRange(str, prefix, 0);
982
    };
1058
    };
Línea 983... Línea 1059...
983
 
1059
 
984
    var global = tinymce.util.Tools.resolve('tinymce.util.VK');
1060
    var global = tinymce.util.Tools.resolve('tinymce.util.VK');
985
 
1061
 
986
    const appendClickRemove = (link, evt) => {
1062
    const appendClickRemove = (link, evt) => {
987
      document.body.appendChild(link);
1063
      document.body.appendChild(link);
988
      link.dispatchEvent(evt);
1064
      link.dispatchEvent(evt);
989
      document.body.removeChild(link);
1065
      document.body.removeChild(link);
990
    };
1066
    };
991
    const open = url => {
1067
    const openLink = url => {
992
      const link = document.createElement('a');
1068
      const link = document.createElement('a');
993
      link.target = '_blank';
1069
      link.target = '_blank';
-
 
1070
      link.href = url;
-
 
1071
      link.rel = 'noreferrer noopener';
-
 
1072
      const evt = new MouseEvent('click', {
-
 
1073
        bubbles: true,
994
      link.href = url;
1074
        cancelable: true,
995
      link.rel = 'noreferrer noopener';
1075
        view: window
996
      const evt = document.createEvent('MouseEvents');
1076
      });
997
      evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
-
 
998
      appendClickRemove(link, evt);
-
 
999
    };
-
 
1000
 
1077
      document.dispatchEvent(evt);
1001
    const getLink = (editor, elm) => editor.dom.getParent(elm, 'a[href]');
1078
      appendClickRemove(link, evt);
1002
    const getSelectedLink = editor => getLink(editor, editor.selection.getStart());
1079
    };
1003
    const hasOnlyAltModifier = e => {
1080
    const hasOnlyAltModifier = e => {
1004
      return e.altKey === true && e.shiftKey === false && e.ctrlKey === false && e.metaKey === false;
1081
      return e.altKey === true && e.shiftKey === false && e.ctrlKey === false && e.metaKey === false;
1005
    };
1082
    };
1006
    const gotoLink = (editor, a) => {
1083
    const gotoLink = (editor, a) => {
1007
      if (a) {
1084
      if (a) {
1008
        const href = getHref(a);
1085
        const href = getHref(a);
1009
        if (/^#/.test(href)) {
1086
        if (/^#/.test(href)) {
1010
          const targetEl = editor.dom.select(href);
1087
          const targetEl = editor.dom.select(`${ href },[name="${ removeLeading(href, '#') }"]`);
1011
          if (targetEl.length) {
1088
          if (targetEl.length) {
1012
            editor.selection.scrollIntoView(targetEl[0], true);
1089
            editor.selection.scrollIntoView(targetEl[0], true);
1013
          }
1090
          }
1014
        } else {
1091
        } else {
1015
          open(a.href);
1092
          openLink(a.href);
1016
        }
1093
        }
1017
      }
1094
      }
1018
    };
-
 
1019
    const openDialog = editor => () => {
1095
    };
1020
      editor.execCommand('mceLink', false, { dialog: true });
1096
    const isSelectionOnImageWithEmbeddedLink = editor => {
1021
    };
1097
      const rng = editor.selection.getRng();
-
 
1098
      const node = rng.startContainer;
-
 
1099
      return isLink(node) && rng.startContainer === rng.endContainer && editor.dom.select('img', node).length === 1;
-
 
1100
    };
-
 
1101
    const getLinkFromElement = (editor, element) => {
-
 
1102
      const links = getLinks$1(editor.dom.getParents(element));
-
 
1103
      return someIf(links.length === 1, links[0]);
-
 
1104
    };
-
 
1105
    const getLinkInSelection = editor => {
-
 
1106
      const links = getLinksInSelection(editor.selection.getRng());
1022
    const gotoSelectedLink = editor => () => {
1107
      return someIf(links.length > 0, links[0]).or(getLinkFromElement(editor, editor.selection.getNode()));
-
 
1108
    };
-
 
1109
    const getLinkFromSelection = editor => editor.selection.isCollapsed() || isSelectionOnImageWithEmbeddedLink(editor) ? getLinkFromElement(editor, editor.selection.getStart()) : getLinkInSelection(editor);
-
 
1110
    const setup$1 = editor => {
-
 
1111
      const selectedLink = value();
-
 
1112
      const getSelectedLink = () => selectedLink.get().or(getLinkFromSelection(editor));
-
 
1113
      const gotoSelectedLink = () => getSelectedLink().each(link => gotoLink(editor, link));
-
 
1114
      editor.on('contextmenu', e => {
-
 
1115
        getLinkFromElement(editor, e.target).each(selectedLink.set);
-
 
1116
      });
-
 
1117
      editor.on('SelectionChange', () => {
-
 
1118
        if (!selectedLink.isSet()) {
1023
      gotoLink(editor, getSelectedLink(editor));
1119
          getLinkFromSelection(editor).each(selectedLink.set);
-
 
1120
        }
1024
    };
1121
      });
1025
    const setupGotoLinks = editor => {
1122
      editor.on('click', e => {
1026
      editor.on('click', e => {
1123
        selectedLink.clear();
1027
        const link = getLink(editor, e.target);
1124
        const links = getLinks$1(editor.dom.getParents(e.target));
1028
        if (link && global.metaKeyPressed(e)) {
1125
        if (links.length === 1 && global.metaKeyPressed(e)) {
1029
          e.preventDefault();
1126
          e.preventDefault();
1030
          gotoLink(editor, link);
1127
          gotoLink(editor, links[0]);
-
 
1128
        }
1031
        }
1129
      });
1032
      });
1130
      editor.on('keydown', e => {
1033
      editor.on('keydown', e => {
-
 
1034
        if (!e.isDefaultPrevented() && e.keyCode === 13 && hasOnlyAltModifier(e)) {
1131
        selectedLink.clear();
1035
          const link = getSelectedLink(editor);
1132
        if (!e.isDefaultPrevented() && e.keyCode === 13 && hasOnlyAltModifier(e)) {
1036
          if (link) {
1133
          getSelectedLink().each(link => {
1037
            e.preventDefault();
1134
            e.preventDefault();
1038
            gotoLink(editor, link);
1135
            gotoLink(editor, link);
-
 
1136
          });
-
 
1137
        }
-
 
1138
      });
-
 
1139
      return { gotoSelectedLink };
-
 
1140
    };
1039
          }
1141
 
1040
        }
1142
    const openDialog = editor => () => {
1041
      });
1143
      editor.execCommand('mceLink', false, { dialog: true });
1042
    };
1144
    };
1043
    const toggleState = (editor, toggler) => {
1145
    const toggleState = (editor, toggler) => {
Línea 1057... Línea 1159...
1057
        api.setEnabled(editor.selection.isEditable());
1159
        api.setEnabled(editor.selection.isEditable());
1058
      };
1160
      };
1059
      updateState();
1161
      updateState();
1060
      return toggleState(editor, updateState);
1162
      return toggleState(editor, updateState);
1061
    };
1163
    };
1062
    const hasExactlyOneLinkInSelection = editor => {
-
 
1063
      const links = editor.selection.isCollapsed() ? getLinks$1(editor.dom.getParents(editor.selection.getStart())) : getLinksInSelection(editor.selection.getRng());
-
 
1064
      return links.length === 1;
-
 
1065
    };
-
 
1066
    const toggleGotoLinkState = editor => api => {
1164
    const toggleRequiresLinkState = editor => api => {
1067
      const updateState = () => api.setEnabled(hasExactlyOneLinkInSelection(editor));
-
 
1068
      updateState();
-
 
1069
      return toggleState(editor, updateState);
-
 
1070
    };
-
 
1071
    const toggleUnlinkState = editor => api => {
-
 
1072
      const hasLinks$1 = parents => hasLinks(parents) || hasLinksInSelection(editor.selection.getRng());
1165
      const hasLinks$1 = parents => hasLinks(parents) || hasLinksInSelection(editor.selection.getRng());
1073
      const parents = editor.dom.getParents(editor.selection.getStart());
1166
      const parents = editor.dom.getParents(editor.selection.getStart());
1074
      const updateEnabled = parents => {
1167
      const updateEnabled = parents => {
1075
        api.setEnabled(hasLinks$1(parents) && editor.selection.isEditable());
1168
        api.setEnabled(hasLinks$1(parents) && editor.selection.isEditable());
1076
      };
1169
      };
1077
      updateEnabled(parents);
1170
      updateEnabled(parents);
1078
      return toggleState(editor, e => updateEnabled(e.parents));
1171
      return toggleState(editor, e => updateEnabled(e.parents));
1079
    };
1172
    };
1080
 
-
 
1081
    const setup = editor => {
-
 
1082
      editor.addShortcut('Meta+K', '', () => {
-
 
1083
        editor.execCommand('mceLink');
-
 
1084
      });
-
 
1085
    };
-
 
1086
 
-
 
1087
    const setupButtons = editor => {
1173
    const setupButtons = (editor, openLink) => {
1088
      editor.ui.registry.addToggleButton('link', {
1174
      editor.ui.registry.addToggleButton('link', {
1089
        icon: 'link',
1175
        icon: 'link',
1090
        tooltip: 'Insert/edit link',
1176
        tooltip: 'Insert/edit link',
-
 
1177
        shortcut: 'Meta+K',
1091
        onAction: openDialog(editor),
1178
        onAction: openDialog(editor),
1092
        onSetup: toggleLinkState(editor)
1179
        onSetup: toggleLinkState(editor)
1093
      });
1180
      });
1094
      editor.ui.registry.addButton('openlink', {
1181
      editor.ui.registry.addButton('openlink', {
1095
        icon: 'new-tab',
1182
        icon: 'new-tab',
1096
        tooltip: 'Open link',
1183
        tooltip: 'Open link',
1097
        onAction: gotoSelectedLink(editor),
1184
        onAction: openLink.gotoSelectedLink,
1098
        onSetup: toggleGotoLinkState(editor)
1185
        onSetup: toggleRequiresLinkState(editor)
1099
      });
1186
      });
1100
      editor.ui.registry.addButton('unlink', {
1187
      editor.ui.registry.addButton('unlink', {
1101
        icon: 'unlink',
1188
        icon: 'unlink',
1102
        tooltip: 'Remove link',
1189
        tooltip: 'Remove link',
1103
        onAction: () => unlink(editor),
1190
        onAction: () => unlink(editor),
1104
        onSetup: toggleUnlinkState(editor)
1191
        onSetup: toggleRequiresLinkState(editor)
1105
      });
1192
      });
1106
    };
1193
    };
1107
    const setupMenuItems = editor => {
1194
    const setupMenuItems = (editor, openLink) => {
1108
      editor.ui.registry.addMenuItem('openlink', {
1195
      editor.ui.registry.addMenuItem('openlink', {
1109
        text: 'Open link',
1196
        text: 'Open link',
1110
        icon: 'new-tab',
1197
        icon: 'new-tab',
1111
        onAction: gotoSelectedLink(editor),
1198
        onAction: openLink.gotoSelectedLink,
1112
        onSetup: toggleGotoLinkState(editor)
1199
        onSetup: toggleRequiresLinkState(editor)
1113
      });
1200
      });
1114
      editor.ui.registry.addMenuItem('link', {
1201
      editor.ui.registry.addMenuItem('link', {
1115
        icon: 'link',
1202
        icon: 'link',
1116
        text: 'Link...',
1203
        text: 'Link...',
1117
        shortcut: 'Meta+K',
1204
        shortcut: 'Meta+K',
1118
        onSetup: toggleLinkMenuState(editor),
1205
        onAction: openDialog(editor),
1119
        onAction: openDialog(editor)
1206
        onSetup: toggleLinkMenuState(editor)
1120
      });
1207
      });
1121
      editor.ui.registry.addMenuItem('unlink', {
1208
      editor.ui.registry.addMenuItem('unlink', {
1122
        icon: 'unlink',
1209
        icon: 'unlink',
1123
        text: 'Remove link',
1210
        text: 'Remove link',
1124
        onAction: () => unlink(editor),
1211
        onAction: () => unlink(editor),
1125
        onSetup: toggleUnlinkState(editor)
1212
        onSetup: toggleRequiresLinkState(editor)
1126
      });
1213
      });
1127
    };
1214
    };
1128
    const setupContextMenu = editor => {
1215
    const setupContextMenu = editor => {
1129
      const inLink = 'link unlink openlink';
1216
      const inLink = 'link unlink openlink';
1130
      const noLink = 'link';
1217
      const noLink = 'link';
Línea 1136... Línea 1223...
1136
          }
1223
          }
1137
          return hasLinks(editor.dom.getParents(element, 'a')) ? inLink : noLink;
1224
          return hasLinks(editor.dom.getParents(element, 'a')) ? inLink : noLink;
1138
        }
1225
        }
1139
      });
1226
      });
1140
    };
1227
    };
1141
    const setupContextToolbars = editor => {
1228
    const setupContextToolbars = (editor, openLink) => {
1142
      const collapseSelectionToEnd = editor => {
1229
      const collapseSelectionToEnd = editor => {
1143
        editor.selection.collapse(false);
1230
        editor.selection.collapse(false);
1144
      };
1231
      };
1145
      const onSetupLink = buttonApi => {
1232
      const onSetupLink = buttonApi => {
1146
        const node = editor.selection.getNode();
1233
        const node = editor.selection.getNode();
1147
        buttonApi.setEnabled(isInAnchor(editor, node));
1234
        buttonApi.setEnabled(isInAnchor(editor, node) && editor.selection.isEditable());
1148
        return noop;
1235
        return noop;
1149
      };
1236
      };
1150
      const getLinkText = value => {
1237
      const getLinkText = value => {
1151
        const anchor = getAnchorElement(editor);
1238
        const anchor = getAnchorElement(editor);
1152
        const onlyText = isOnlyTextSelected(editor);
1239
        const onlyText = isOnlyTextSelected(editor);
Línea 1191... Línea 1278...
1191
              link(editor, attachState, {
1278
              link(editor, attachState, {
1192
                href: value,
1279
                href: value,
1193
                text,
1280
                text,
1194
                title: Optional.none(),
1281
                title: Optional.none(),
1195
                rel: Optional.none(),
1282
                rel: Optional.none(),
1196
                target: Optional.none(),
1283
                target: Optional.from(getDefaultLinkTarget(editor)),
1197
                class: Optional.none()
1284
                class: Optional.none()
1198
              });
1285
              });
1199
              collapseSelectionToEnd(editor);
1286
              collapseSelectionToEnd(editor);
1200
              formApi.hide();
1287
              formApi.hide();
1201
            }
1288
            }
Línea 1214... Línea 1301...
1214
            type: 'contextformbutton',
1301
            type: 'contextformbutton',
1215
            icon: 'new-tab',
1302
            icon: 'new-tab',
1216
            tooltip: 'Open link',
1303
            tooltip: 'Open link',
1217
            onSetup: onSetupLink,
1304
            onSetup: onSetupLink,
1218
            onAction: formApi => {
1305
            onAction: formApi => {
1219
              gotoSelectedLink(editor)();
1306
              openLink.gotoSelectedLink();
1220
              formApi.hide();
1307
              formApi.hide();
1221
            }
1308
            }
1222
          }
1309
          }
1223
        ]
1310
        ]
1224
      });
1311
      });
1225
    };
1312
    };
-
 
1313
    const setup = editor => {
-
 
1314
      const openLink = setup$1(editor);
-
 
1315
      setupButtons(editor, openLink);
-
 
1316
      setupMenuItems(editor, openLink);
-
 
1317
      setupContextMenu(editor);
-
 
1318
      setupContextToolbars(editor, openLink);
-
 
1319
    };
Línea 1226... Línea 1320...
1226
 
1320
 
1227
    var Plugin = () => {
1321
    var Plugin = () => {
1228
      global$5.add('link', editor => {
1322
      global$5.add('link', editor => {
1229
        register$1(editor);
-
 
1230
        setupButtons(editor);
-
 
1231
        setupMenuItems(editor);
-
 
1232
        setupContextMenu(editor);
-
 
1233
        setupContextToolbars(editor);
-
 
1234
        setupGotoLinks(editor);
1323
        register$1(editor);
1235
        register(editor);
1324
        register(editor);
-
 
1325
        setup(editor);
1236
        setup(editor);
1326
        setup$2(editor);
1237
      });
1327
      });
Línea 1238... Línea 1328...
1238
    };
1328
    };