plugin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * TinyMCE version 6.0.3 (2022-05-25)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. var global = tinymce.util.Tools.resolve('tinymce.Env');
  8. const option = name => editor => editor.options.get(name);
  9. const register$2 = editor => {
  10. const registerOption = editor.options.register;
  11. registerOption('pagebreak_separator', {
  12. processor: 'string',
  13. default: '<!-- pagebreak -->'
  14. });
  15. registerOption('pagebreak_split_block', {
  16. processor: 'boolean',
  17. default: false
  18. });
  19. };
  20. const getSeparatorHtml = option('pagebreak_separator');
  21. const shouldSplitBlock = option('pagebreak_split_block');
  22. const pageBreakClass = 'mce-pagebreak';
  23. const getPlaceholderHtml = shouldSplitBlock => {
  24. const html = `<img src="${ global.transparentSrc }" class="${ pageBreakClass }" data-mce-resize="false" data-mce-placeholder />`;
  25. return shouldSplitBlock ? `<p>${ html }</p>` : html;
  26. };
  27. const setup$1 = editor => {
  28. const separatorHtml = getSeparatorHtml(editor);
  29. const shouldSplitBlock$1 = () => shouldSplitBlock(editor);
  30. const pageBreakSeparatorRegExp = new RegExp(separatorHtml.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, a => {
  31. return '\\' + a;
  32. }), 'gi');
  33. editor.on('BeforeSetContent', e => {
  34. e.content = e.content.replace(pageBreakSeparatorRegExp, getPlaceholderHtml(shouldSplitBlock$1()));
  35. });
  36. editor.on('PreInit', () => {
  37. editor.serializer.addNodeFilter('img', nodes => {
  38. let i = nodes.length, node, className;
  39. while (i--) {
  40. node = nodes[i];
  41. className = node.attr('class');
  42. if (className && className.indexOf(pageBreakClass) !== -1) {
  43. const parentNode = node.parent;
  44. if (editor.schema.getBlockElements()[parentNode.name] && shouldSplitBlock$1()) {
  45. parentNode.type = 3;
  46. parentNode.value = separatorHtml;
  47. parentNode.raw = true;
  48. node.remove();
  49. continue;
  50. }
  51. node.type = 3;
  52. node.value = separatorHtml;
  53. node.raw = true;
  54. }
  55. }
  56. });
  57. });
  58. };
  59. const register$1 = editor => {
  60. editor.addCommand('mcePageBreak', () => {
  61. editor.insertContent(getPlaceholderHtml(shouldSplitBlock(editor)));
  62. });
  63. };
  64. const setup = editor => {
  65. editor.on('ResolveName', e => {
  66. if (e.target.nodeName === 'IMG' && editor.dom.hasClass(e.target, pageBreakClass)) {
  67. e.name = 'pagebreak';
  68. }
  69. });
  70. };
  71. const register = editor => {
  72. const onAction = () => editor.execCommand('mcePageBreak');
  73. editor.ui.registry.addButton('pagebreak', {
  74. icon: 'page-break',
  75. tooltip: 'Page break',
  76. onAction
  77. });
  78. editor.ui.registry.addMenuItem('pagebreak', {
  79. text: 'Page break',
  80. icon: 'page-break',
  81. onAction
  82. });
  83. };
  84. var Plugin = () => {
  85. global$1.add('pagebreak', editor => {
  86. register$2(editor);
  87. register$1(editor);
  88. register(editor);
  89. setup$1(editor);
  90. setup(editor);
  91. });
  92. };
  93. Plugin();
  94. })();