tinymce_plugins_nonbreaking.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/nonbreaking/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/nonbreaking/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var global$1 = tinymce.util.Tools.resolve("tinymce.PluginManager");
  10. var getKeyboardSpaces = function(editor) {
  11. var spaces = editor.getParam("nonbreaking_force_tab", 0);
  12. if (typeof spaces === "boolean") {
  13. return spaces === true ? 3 : 0;
  14. } else {
  15. return spaces;
  16. }
  17. };
  18. var wrapNbsps = function(editor) {
  19. return editor.getParam("nonbreaking_wrap", true, "boolean");
  20. };
  21. var stringRepeat = function(string, repeats) {
  22. var str = "";
  23. for (var index = 0; index < repeats; index++) {
  24. str += string;
  25. }
  26. return str;
  27. };
  28. var isVisualCharsEnabled = function(editor) {
  29. return editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false;
  30. };
  31. var insertNbsp = function(editor, times) {
  32. var classes = function() {
  33. return isVisualCharsEnabled(editor) ? "mce-nbsp-wrap mce-nbsp" : "mce-nbsp-wrap";
  34. };
  35. var nbspSpan = function() {
  36. return '<span class="' + classes() + '" contenteditable="false">' + stringRepeat("&nbsp;", times) + "</span>";
  37. };
  38. var shouldWrap = wrapNbsps(editor);
  39. var html = shouldWrap || editor.plugins.visualchars ? nbspSpan() : stringRepeat("&nbsp;", times);
  40. editor.undoManager.transact(function() {
  41. return editor.insertContent(html);
  42. });
  43. };
  44. var register$1 = function(editor) {
  45. editor.addCommand("mceNonBreaking", function() {
  46. insertNbsp(editor, 1);
  47. });
  48. };
  49. var global = tinymce.util.Tools.resolve("tinymce.util.VK");
  50. var setup = function(editor) {
  51. var spaces = getKeyboardSpaces(editor);
  52. if (spaces > 0) {
  53. editor.on("keydown", function(e) {
  54. if (e.keyCode === global.TAB && !e.isDefaultPrevented()) {
  55. if (e.shiftKey) {
  56. return;
  57. }
  58. e.preventDefault();
  59. e.stopImmediatePropagation();
  60. insertNbsp(editor, spaces);
  61. }
  62. });
  63. }
  64. };
  65. var register = function(editor) {
  66. var onAction = function() {
  67. return editor.execCommand("mceNonBreaking");
  68. };
  69. editor.ui.registry.addButton("nonbreaking", {
  70. icon: "non-breaking",
  71. tooltip: "Nonbreaking space",
  72. onAction
  73. });
  74. editor.ui.registry.addMenuItem("nonbreaking", {
  75. icon: "non-breaking",
  76. text: "Nonbreaking space",
  77. onAction
  78. });
  79. };
  80. function Plugin() {
  81. global$1.add("nonbreaking", function(editor) {
  82. register$1(editor);
  83. register(editor);
  84. setup(editor);
  85. });
  86. }
  87. Plugin();
  88. })();
  89. }
  90. });
  91. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/nonbreaking/index.js
  92. require_plugin();
  93. //# sourceMappingURL=tinymce_plugins_nonbreaking.js.map