plugin.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  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. /**
  39. * This class contains all core logic for the autoresize plugin.
  40. *
  41. * @class tinymce.autoresize.Plugin
  42. * @private
  43. */
  44. const isFullscreen = (editor) => editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
  45. const toggleScrolling = (editor, state) => {
  46. const body = editor.getBody();
  47. if (body) {
  48. body.style.overflowY = state ? '' : 'hidden';
  49. if (!state) {
  50. body.scrollTop = 0;
  51. }
  52. }
  53. };
  54. const parseCssValueToInt = (dom, elm, name, computed) => {
  55. var _a;
  56. const value = parseInt((_a = dom.getStyle(elm, name, computed)) !== null && _a !== void 0 ? _a : '', 10);
  57. // The value maybe be an empty string, so in that case treat it as being 0
  58. return isNaN(value) ? 0 : value;
  59. };
  60. const shouldScrollIntoView = (trigger) => {
  61. // Only scroll the selection into view when we're inserting content. Any other
  62. // triggers the selection should already be in view and resizing would only
  63. // extend the content area.
  64. if ((trigger === null || trigger === void 0 ? void 0 : trigger.type.toLowerCase()) === 'setcontent') {
  65. const setContentEvent = trigger;
  66. return setContentEvent.selection === true || setContentEvent.paste === true;
  67. }
  68. else {
  69. return false;
  70. }
  71. };
  72. /**
  73. * This method gets executed each time the editor needs to resize.
  74. */
  75. const resize = (editor, oldSize, trigger, getExtraMarginBottom) => {
  76. var _a;
  77. const dom = editor.dom;
  78. const doc = editor.getDoc();
  79. if (!doc) {
  80. return;
  81. }
  82. if (isFullscreen(editor)) {
  83. toggleScrolling(editor, true);
  84. return;
  85. }
  86. const docEle = doc.documentElement;
  87. const resizeBottomMargin = getExtraMarginBottom ? getExtraMarginBottom() : getAutoResizeOverflowPadding(editor);
  88. const minHeight = (_a = getMinHeight(editor)) !== null && _a !== void 0 ? _a : editor.getElement().offsetHeight;
  89. let resizeHeight = minHeight;
  90. // Calculate outer height of the doc element using CSS styles
  91. const marginTop = parseCssValueToInt(dom, docEle, 'margin-top', true);
  92. const marginBottom = parseCssValueToInt(dom, docEle, 'margin-bottom', true);
  93. let contentHeight = docEle.offsetHeight + marginTop + marginBottom + resizeBottomMargin;
  94. // Make sure we have a valid height
  95. if (contentHeight < 0) {
  96. contentHeight = 0;
  97. }
  98. // Determine the size of the chroming (menubar, toolbar, etc...)
  99. const containerHeight = editor.getContainer().offsetHeight;
  100. const contentAreaHeight = editor.getContentAreaContainer().offsetHeight;
  101. const chromeHeight = containerHeight - contentAreaHeight;
  102. // Don't make it smaller than the minimum height
  103. if (contentHeight + chromeHeight > minHeight) {
  104. resizeHeight = contentHeight + chromeHeight;
  105. }
  106. // If a maximum height has been defined don't exceed this height
  107. const maxHeight = getMaxHeight(editor);
  108. if (maxHeight && resizeHeight > maxHeight) {
  109. resizeHeight = maxHeight;
  110. toggleScrolling(editor, true);
  111. }
  112. else {
  113. toggleScrolling(editor, false);
  114. }
  115. const old = oldSize.get();
  116. if (old.set) {
  117. editor.dom.setStyles(editor.getDoc().documentElement, { 'min-height': 0 });
  118. editor.dom.setStyles(editor.getBody(), { 'min-height': 'inherit' });
  119. }
  120. // Resize content element
  121. if (resizeHeight !== old.totalHeight && (contentHeight - resizeBottomMargin !== old.contentHeight || !old.set)) {
  122. const deltaSize = (resizeHeight - old.totalHeight);
  123. dom.setStyle(editor.getContainer(), 'height', resizeHeight + 'px');
  124. oldSize.set({
  125. totalHeight: resizeHeight,
  126. contentHeight,
  127. set: true,
  128. });
  129. fireResizeEditor(editor);
  130. // iPadOS has an issue where it won't rerender the body when the iframe is resized
  131. // however if we reset the scroll position then it re-renders correctly
  132. if (global.browser.isSafari() && (global.os.isMacOS() || global.os.isiOS())) {
  133. const win = editor.getWin();
  134. win.scrollTo(win.pageXOffset, win.pageYOffset);
  135. }
  136. // Ensure the selection is in view, as it's potentially out of view after inserting content into the editor
  137. if (editor.hasFocus() && shouldScrollIntoView(trigger)) {
  138. editor.selection.scrollIntoView();
  139. }
  140. // WebKit doesn't decrease the size of the body element until the iframe gets resized
  141. // So we need to continue to resize the iframe down until the size gets fixed
  142. if ((global.browser.isSafari() || global.browser.isChromium()) && deltaSize < 0) {
  143. resize(editor, oldSize, trigger, getExtraMarginBottom);
  144. }
  145. }
  146. };
  147. const setup = (editor, oldSize) => {
  148. const getExtraMarginBottom = () => getAutoResizeBottomMargin(editor);
  149. editor.on('init', (e) => {
  150. const overflowPadding = getAutoResizeOverflowPadding(editor);
  151. const dom = editor.dom;
  152. // Disable height 100% on the root document element otherwise we'll end up resizing indefinitely
  153. dom.setStyles(editor.getDoc().documentElement, {
  154. height: 'auto'
  155. });
  156. if (global.browser.isEdge() || global.browser.isIE()) {
  157. dom.setStyles(editor.getBody(), {
  158. 'paddingLeft': overflowPadding,
  159. 'paddingRight': overflowPadding,
  160. // IE & Edge have a min height of 150px by default on the body, so override that
  161. 'min-height': 0
  162. });
  163. }
  164. else {
  165. dom.setStyles(editor.getBody(), {
  166. paddingLeft: overflowPadding,
  167. paddingRight: overflowPadding
  168. });
  169. }
  170. resize(editor, oldSize, e, getExtraMarginBottom);
  171. });
  172. editor.on('NodeChange SetContent keyup FullscreenStateChanged ResizeContent', (e) => {
  173. resize(editor, oldSize, e, getExtraMarginBottom);
  174. });
  175. };
  176. const register = (editor, oldSize) => {
  177. editor.addCommand('mceAutoResize', () => {
  178. resize(editor, oldSize);
  179. });
  180. };
  181. /**
  182. * This class contains all core logic for the autoresize plugin.
  183. *
  184. * @class tinymce.autoresize.Plugin
  185. * @private
  186. */
  187. var Plugin = () => {
  188. global$1.add('autoresize', (editor) => {
  189. register$1(editor);
  190. // If autoresize is enabled, disable resize if the user hasn't explicitly enabled it
  191. // TINY-8288: This currently does nothing because of a bug in the theme
  192. if (!editor.options.isSet('resize')) {
  193. editor.options.set('resize', false);
  194. }
  195. if (!editor.inline) {
  196. const oldSize = Cell({
  197. totalHeight: 0,
  198. contentHeight: 0,
  199. set: false,
  200. });
  201. register(editor, oldSize);
  202. setup(editor, oldSize);
  203. }
  204. });
  205. };
  206. Plugin();
  207. /** *****
  208. * DO NOT EXPORT ANYTHING
  209. *
  210. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  211. *******/
  212. })();