plugin.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * TinyMCE version 6.4.2 (2023-04-26)
  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. const constant = value => {
  21. return () => {
  22. return value;
  23. };
  24. };
  25. var global = tinymce.util.Tools.resolve('tinymce.Env');
  26. const fireResizeEditor = editor => editor.dispatch('ResizeEditor');
  27. const option = name => editor => editor.options.get(name);
  28. const register$1 = editor => {
  29. const registerOption = editor.options.register;
  30. registerOption('autoresize_overflow_padding', {
  31. processor: 'number',
  32. default: 1
  33. });
  34. registerOption('autoresize_bottom_margin', {
  35. processor: 'number',
  36. default: 50
  37. });
  38. };
  39. const getMinHeight = option('min_height');
  40. const getMaxHeight = option('max_height');
  41. const getAutoResizeOverflowPadding = option('autoresize_overflow_padding');
  42. const getAutoResizeBottomMargin = option('autoresize_bottom_margin');
  43. const isFullscreen = editor => editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
  44. const toggleScrolling = (editor, state) => {
  45. const body = editor.getBody();
  46. if (body) {
  47. body.style.overflowY = state ? '' : 'hidden';
  48. if (!state) {
  49. body.scrollTop = 0;
  50. }
  51. }
  52. };
  53. const parseCssValueToInt = (dom, elm, name, computed) => {
  54. var _a;
  55. const value = parseInt((_a = dom.getStyle(elm, name, computed)) !== null && _a !== void 0 ? _a : '', 10);
  56. return isNaN(value) ? 0 : value;
  57. };
  58. const shouldScrollIntoView = trigger => {
  59. if ((trigger === null || trigger === void 0 ? void 0 : trigger.type.toLowerCase()) === 'setcontent') {
  60. const setContentEvent = trigger;
  61. return setContentEvent.selection === true || setContentEvent.paste === true;
  62. } else {
  63. return false;
  64. }
  65. };
  66. const resize = (editor, oldSize, trigger, getExtraMarginBottom) => {
  67. var _a;
  68. const dom = editor.dom;
  69. const doc = editor.getDoc();
  70. if (!doc) {
  71. return;
  72. }
  73. if (isFullscreen(editor)) {
  74. toggleScrolling(editor, true);
  75. return;
  76. }
  77. const docEle = doc.documentElement;
  78. const resizeBottomMargin = getExtraMarginBottom ? getExtraMarginBottom() : getAutoResizeOverflowPadding(editor);
  79. const minHeight = (_a = getMinHeight(editor)) !== null && _a !== void 0 ? _a : editor.getElement().offsetHeight;
  80. let resizeHeight = minHeight;
  81. const marginTop = parseCssValueToInt(dom, docEle, 'margin-top', true);
  82. const marginBottom = parseCssValueToInt(dom, docEle, 'margin-bottom', true);
  83. let contentHeight = docEle.offsetHeight + marginTop + marginBottom + resizeBottomMargin;
  84. if (contentHeight < 0) {
  85. contentHeight = 0;
  86. }
  87. const containerHeight = editor.getContainer().offsetHeight;
  88. const contentAreaHeight = editor.getContentAreaContainer().offsetHeight;
  89. const chromeHeight = containerHeight - contentAreaHeight;
  90. if (contentHeight + chromeHeight > minHeight) {
  91. resizeHeight = contentHeight + chromeHeight;
  92. }
  93. const maxHeight = getMaxHeight(editor);
  94. if (maxHeight && resizeHeight > maxHeight) {
  95. resizeHeight = maxHeight;
  96. toggleScrolling(editor, true);
  97. } else {
  98. toggleScrolling(editor, false);
  99. }
  100. if (resizeHeight !== oldSize.get()) {
  101. const deltaSize = resizeHeight - oldSize.get();
  102. dom.setStyle(editor.getContainer(), 'height', resizeHeight + 'px');
  103. oldSize.set(resizeHeight);
  104. fireResizeEditor(editor);
  105. if (global.browser.isSafari() && (global.os.isMacOS() || global.os.isiOS())) {
  106. const win = editor.getWin();
  107. win.scrollTo(win.pageXOffset, win.pageYOffset);
  108. }
  109. if (editor.hasFocus() && shouldScrollIntoView(trigger)) {
  110. editor.selection.scrollIntoView();
  111. }
  112. if ((global.browser.isSafari() || global.browser.isChromium()) && deltaSize < 0) {
  113. resize(editor, oldSize, trigger, getExtraMarginBottom);
  114. }
  115. }
  116. };
  117. const setup = (editor, oldSize) => {
  118. let getExtraMarginBottom = () => getAutoResizeBottomMargin(editor);
  119. let resizeCounter;
  120. let sizeAfterFirstResize;
  121. editor.on('init', e => {
  122. resizeCounter = 0;
  123. const overflowPadding = getAutoResizeOverflowPadding(editor);
  124. const dom = editor.dom;
  125. dom.setStyles(editor.getDoc().documentElement, { height: 'auto' });
  126. if (global.browser.isEdge() || global.browser.isIE()) {
  127. dom.setStyles(editor.getBody(), {
  128. 'paddingLeft': overflowPadding,
  129. 'paddingRight': overflowPadding,
  130. 'min-height': 0
  131. });
  132. } else {
  133. dom.setStyles(editor.getBody(), {
  134. paddingLeft: overflowPadding,
  135. paddingRight: overflowPadding
  136. });
  137. }
  138. resize(editor, oldSize, e, getExtraMarginBottom);
  139. resizeCounter += 1;
  140. });
  141. editor.on('NodeChange SetContent keyup FullscreenStateChanged ResizeContent', e => {
  142. if (resizeCounter === 1) {
  143. sizeAfterFirstResize = editor.getContainer().offsetHeight;
  144. resize(editor, oldSize, e, getExtraMarginBottom);
  145. resizeCounter += 1;
  146. } else if (resizeCounter === 2) {
  147. const isLooping = sizeAfterFirstResize < editor.getContainer().offsetHeight;
  148. if (isLooping) {
  149. const dom = editor.dom;
  150. const doc = editor.getDoc();
  151. dom.setStyles(doc.documentElement, { 'min-height': 0 });
  152. dom.setStyles(editor.getBody(), { 'min-height': 'inherit' });
  153. }
  154. getExtraMarginBottom = isLooping ? constant(0) : getExtraMarginBottom;
  155. resizeCounter += 1;
  156. } else {
  157. resize(editor, oldSize, e, getExtraMarginBottom);
  158. }
  159. });
  160. };
  161. const register = (editor, oldSize) => {
  162. editor.addCommand('mceAutoResize', () => {
  163. resize(editor, oldSize);
  164. });
  165. };
  166. var Plugin = () => {
  167. global$1.add('autoresize', editor => {
  168. register$1(editor);
  169. if (!editor.options.isSet('resize')) {
  170. editor.options.set('resize', false);
  171. }
  172. if (!editor.inline) {
  173. const oldSize = Cell(0);
  174. register(editor, oldSize);
  175. setup(editor, oldSize);
  176. }
  177. });
  178. };
  179. Plugin();
  180. })();