plugin.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * TinyMCE version 6.0.3 (2022-05-25)
  3. */
  4. (function () {
  5. 'use strict';
  6. const Cell = initial => {
  7. let value = initial;
  8. const get = () => {
  9. return value;
  10. };
  11. const set = v => {
  12. value = v;
  13. };
  14. return {
  15. get,
  16. set
  17. };
  18. };
  19. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  20. var global = tinymce.util.Tools.resolve('tinymce.Env');
  21. const fireResizeEditor = editor => editor.dispatch('ResizeEditor');
  22. const option = name => editor => editor.options.get(name);
  23. const register$1 = editor => {
  24. const registerOption = editor.options.register;
  25. registerOption('autoresize_overflow_padding', {
  26. processor: 'number',
  27. default: 1
  28. });
  29. registerOption('autoresize_bottom_margin', {
  30. processor: 'number',
  31. default: 50
  32. });
  33. };
  34. const getMinHeight = option('min_height');
  35. const getMaxHeight = option('max_height');
  36. const getAutoResizeOverflowPadding = option('autoresize_overflow_padding');
  37. const getAutoResizeBottomMargin = option('autoresize_bottom_margin');
  38. const isFullscreen = editor => editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
  39. const toggleScrolling = (editor, state) => {
  40. const body = editor.getBody();
  41. if (body) {
  42. body.style.overflowY = state ? '' : 'hidden';
  43. if (!state) {
  44. body.scrollTop = 0;
  45. }
  46. }
  47. };
  48. const parseCssValueToInt = (dom, elm, name, computed) => {
  49. const value = parseInt(dom.getStyle(elm, name, computed), 10);
  50. return isNaN(value) ? 0 : value;
  51. };
  52. const shouldScrollIntoView = trigger => {
  53. if ((trigger === null || trigger === void 0 ? void 0 : trigger.type.toLowerCase()) === 'setcontent') {
  54. const setContentEvent = trigger;
  55. return setContentEvent.selection === true || setContentEvent.paste === true;
  56. } else {
  57. return false;
  58. }
  59. };
  60. const resize = (editor, oldSize, trigger) => {
  61. var _a;
  62. const dom = editor.dom;
  63. const doc = editor.getDoc();
  64. if (!doc) {
  65. return;
  66. }
  67. if (isFullscreen(editor)) {
  68. toggleScrolling(editor, true);
  69. return;
  70. }
  71. const docEle = doc.documentElement;
  72. const resizeBottomMargin = getAutoResizeBottomMargin(editor);
  73. const minHeight = (_a = getMinHeight(editor)) !== null && _a !== void 0 ? _a : editor.getElement().offsetHeight;
  74. let resizeHeight = minHeight;
  75. const marginTop = parseCssValueToInt(dom, docEle, 'margin-top', true);
  76. const marginBottom = parseCssValueToInt(dom, docEle, 'margin-bottom', true);
  77. let contentHeight = docEle.offsetHeight + marginTop + marginBottom + resizeBottomMargin;
  78. if (contentHeight < 0) {
  79. contentHeight = 0;
  80. }
  81. const containerHeight = editor.getContainer().offsetHeight;
  82. const contentAreaHeight = editor.getContentAreaContainer().offsetHeight;
  83. const chromeHeight = containerHeight - contentAreaHeight;
  84. if (contentHeight + chromeHeight > minHeight) {
  85. resizeHeight = contentHeight + chromeHeight;
  86. }
  87. const maxHeight = getMaxHeight(editor);
  88. if (maxHeight && resizeHeight > maxHeight) {
  89. resizeHeight = maxHeight;
  90. toggleScrolling(editor, true);
  91. } else {
  92. toggleScrolling(editor, false);
  93. }
  94. if (resizeHeight !== oldSize.get()) {
  95. const deltaSize = resizeHeight - oldSize.get();
  96. dom.setStyle(editor.getContainer(), 'height', resizeHeight + 'px');
  97. oldSize.set(resizeHeight);
  98. fireResizeEditor(editor);
  99. if (global.browser.isSafari() && (global.os.isMacOS() || global.os.isiOS())) {
  100. const win = editor.getWin();
  101. win.scrollTo(win.pageXOffset, win.pageYOffset);
  102. }
  103. if (editor.hasFocus() && shouldScrollIntoView(trigger)) {
  104. editor.selection.scrollIntoView();
  105. }
  106. if ((global.browser.isSafari() || global.browser.isChromium()) && deltaSize < 0) {
  107. resize(editor, oldSize, trigger);
  108. }
  109. }
  110. };
  111. const setup = (editor, oldSize) => {
  112. editor.on('init', () => {
  113. const overflowPadding = getAutoResizeOverflowPadding(editor);
  114. const dom = editor.dom;
  115. dom.setStyles(editor.getDoc().documentElement, { height: 'auto' });
  116. dom.setStyles(editor.getBody(), {
  117. 'paddingLeft': overflowPadding,
  118. 'paddingRight': overflowPadding,
  119. 'min-height': 0
  120. });
  121. });
  122. editor.on('NodeChange SetContent keyup FullscreenStateChanged ResizeContent', e => {
  123. resize(editor, oldSize, e);
  124. });
  125. };
  126. const register = (editor, oldSize) => {
  127. editor.addCommand('mceAutoResize', () => {
  128. resize(editor, oldSize);
  129. });
  130. };
  131. var Plugin = () => {
  132. global$1.add('autoresize', editor => {
  133. register$1(editor);
  134. if (!editor.options.isSet('resize')) {
  135. editor.options.set('resize', false);
  136. }
  137. if (!editor.inline) {
  138. const oldSize = Cell(0);
  139. register(editor, oldSize);
  140. setup(editor, oldSize);
  141. }
  142. });
  143. };
  144. Plugin();
  145. })();