plugin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * TinyMCE version 6.4.2 (2023-04-26)
  3. */
  4. (function () {
  5. 'use strict';
  6. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  7. const isSimpleType = type => value => typeof value === type;
  8. const isBoolean = isSimpleType('boolean');
  9. const isNumber = isSimpleType('number');
  10. const option = name => editor => editor.options.get(name);
  11. const register$2 = editor => {
  12. const registerOption = editor.options.register;
  13. registerOption('nonbreaking_force_tab', {
  14. processor: value => {
  15. if (isBoolean(value)) {
  16. return {
  17. value: value ? 3 : 0,
  18. valid: true
  19. };
  20. } else if (isNumber(value)) {
  21. return {
  22. value,
  23. valid: true
  24. };
  25. } else {
  26. return {
  27. valid: false,
  28. message: 'Must be a boolean or number.'
  29. };
  30. }
  31. },
  32. default: false
  33. });
  34. registerOption('nonbreaking_wrap', {
  35. processor: 'boolean',
  36. default: true
  37. });
  38. };
  39. const getKeyboardSpaces = option('nonbreaking_force_tab');
  40. const wrapNbsps = option('nonbreaking_wrap');
  41. const stringRepeat = (string, repeats) => {
  42. let str = '';
  43. for (let index = 0; index < repeats; index++) {
  44. str += string;
  45. }
  46. return str;
  47. };
  48. const isVisualCharsEnabled = editor => editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false;
  49. const insertNbsp = (editor, times) => {
  50. const classes = () => isVisualCharsEnabled(editor) ? 'mce-nbsp-wrap mce-nbsp' : 'mce-nbsp-wrap';
  51. const nbspSpan = () => `<span class="${ classes() }" contenteditable="false">${ stringRepeat('&nbsp;', times) }</span>`;
  52. const shouldWrap = wrapNbsps(editor);
  53. const html = shouldWrap || editor.plugins.visualchars ? nbspSpan() : stringRepeat('&nbsp;', times);
  54. editor.undoManager.transact(() => editor.insertContent(html));
  55. };
  56. const register$1 = editor => {
  57. editor.addCommand('mceNonBreaking', () => {
  58. insertNbsp(editor, 1);
  59. });
  60. };
  61. var global = tinymce.util.Tools.resolve('tinymce.util.VK');
  62. const setup = editor => {
  63. const spaces = getKeyboardSpaces(editor);
  64. if (spaces > 0) {
  65. editor.on('keydown', e => {
  66. if (e.keyCode === global.TAB && !e.isDefaultPrevented()) {
  67. if (e.shiftKey) {
  68. return;
  69. }
  70. e.preventDefault();
  71. e.stopImmediatePropagation();
  72. insertNbsp(editor, spaces);
  73. }
  74. });
  75. }
  76. };
  77. const register = editor => {
  78. const onAction = () => editor.execCommand('mceNonBreaking');
  79. editor.ui.registry.addButton('nonbreaking', {
  80. icon: 'non-breaking',
  81. tooltip: 'Nonbreaking space',
  82. onAction
  83. });
  84. editor.ui.registry.addMenuItem('nonbreaking', {
  85. icon: 'non-breaking',
  86. text: 'Nonbreaking space',
  87. onAction
  88. });
  89. };
  90. var Plugin = () => {
  91. global$1.add('nonbreaking', editor => {
  92. register$2(editor);
  93. register$1(editor);
  94. register(editor);
  95. setup(editor);
  96. });
  97. };
  98. Plugin();
  99. })();