plugin.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * TinyMCE version 8.0.2 (2025-08-14)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. /* eslint-disable @typescript-eslint/no-wrapper-object-types */
  8. const isSimpleType = (type) => (value) => typeof value === type;
  9. const isBoolean = isSimpleType('boolean');
  10. const isNumber = isSimpleType('number');
  11. const option = (name) => (editor) => editor.options.get(name);
  12. const register$2 = (editor) => {
  13. const registerOption = editor.options.register;
  14. registerOption('nonbreaking_force_tab', {
  15. processor: (value) => {
  16. if (isBoolean(value)) {
  17. return { value: value ? 3 : 0, valid: true };
  18. }
  19. else if (isNumber(value)) {
  20. return { value, valid: true };
  21. }
  22. else {
  23. return { valid: false, message: 'Must be a boolean or number.' };
  24. }
  25. },
  26. default: false
  27. });
  28. registerOption('nonbreaking_wrap', {
  29. processor: 'boolean',
  30. default: true
  31. });
  32. };
  33. const getKeyboardSpaces = option('nonbreaking_force_tab');
  34. const wrapNbsps = option('nonbreaking_wrap');
  35. const stringRepeat = (string, repeats) => {
  36. let str = '';
  37. for (let index = 0; index < repeats; index++) {
  38. str += string;
  39. }
  40. return str;
  41. };
  42. const isVisualCharsEnabled = (editor) => editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false;
  43. const insertNbsp = (editor, times) => {
  44. const classes = () => isVisualCharsEnabled(editor) ? 'mce-nbsp-wrap mce-nbsp' : 'mce-nbsp-wrap';
  45. const nbspSpan = () => `<span class="${classes()}" contenteditable="false">${stringRepeat('&nbsp;', times)}</span>`;
  46. const shouldWrap = wrapNbsps(editor);
  47. const html = shouldWrap || editor.plugins.visualchars ? nbspSpan() : stringRepeat('&nbsp;', times);
  48. editor.undoManager.transact(() => editor.insertContent(html));
  49. };
  50. const register$1 = (editor) => {
  51. editor.addCommand('mceNonBreaking', () => {
  52. insertNbsp(editor, 1);
  53. });
  54. };
  55. var global = tinymce.util.Tools.resolve('tinymce.util.VK');
  56. const setup = (editor) => {
  57. const spaces = getKeyboardSpaces(editor);
  58. if (spaces > 0) {
  59. editor.on('keydown', (e) => {
  60. if (e.keyCode === global.TAB && !e.isDefaultPrevented()) {
  61. if (e.shiftKey) {
  62. return;
  63. }
  64. e.preventDefault();
  65. e.stopImmediatePropagation();
  66. insertNbsp(editor, spaces);
  67. }
  68. });
  69. }
  70. };
  71. const onSetupEditable = (editor) => (api) => {
  72. const nodeChanged = () => {
  73. api.setEnabled(editor.selection.isEditable());
  74. };
  75. editor.on('NodeChange', nodeChanged);
  76. nodeChanged();
  77. return () => {
  78. editor.off('NodeChange', nodeChanged);
  79. };
  80. };
  81. const register = (editor) => {
  82. const onAction = () => editor.execCommand('mceNonBreaking');
  83. editor.ui.registry.addButton('nonbreaking', {
  84. icon: 'non-breaking',
  85. tooltip: 'Nonbreaking space',
  86. onAction,
  87. onSetup: onSetupEditable(editor)
  88. });
  89. editor.ui.registry.addMenuItem('nonbreaking', {
  90. icon: 'non-breaking',
  91. text: 'Nonbreaking space',
  92. onAction,
  93. onSetup: onSetupEditable(editor)
  94. });
  95. };
  96. /**
  97. * This class contains all core logic for the nonbreaking plugin.
  98. *
  99. * @class tinymce.nonbreaking.Plugin
  100. * @private
  101. */
  102. var Plugin = () => {
  103. global$1.add('nonbreaking', (editor) => {
  104. register$2(editor);
  105. register$1(editor);
  106. register(editor);
  107. setup(editor);
  108. });
  109. };
  110. Plugin();
  111. /** *****
  112. * DO NOT EXPORT ANYTHING
  113. *
  114. * IF YOU DO ROLLUP WILL LEAVE A GLOBAL ON THE PAGE
  115. *******/
  116. })();