tinymce_plugins_advlist.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/advlist/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/advlist/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var global$1 = tinymce.util.Tools.resolve("tinymce.PluginManager");
  10. var applyListFormat = function(editor, listName, styleValue) {
  11. var cmd = listName === "UL" ? "InsertUnorderedList" : "InsertOrderedList";
  12. editor.execCommand(cmd, false, styleValue === false ? null : { "list-style-type": styleValue });
  13. };
  14. var register$1 = function(editor) {
  15. editor.addCommand("ApplyUnorderedListStyle", function(ui, value) {
  16. applyListFormat(editor, "UL", value["list-style-type"]);
  17. });
  18. editor.addCommand("ApplyOrderedListStyle", function(ui, value) {
  19. applyListFormat(editor, "OL", value["list-style-type"]);
  20. });
  21. };
  22. var global = tinymce.util.Tools.resolve("tinymce.util.Tools");
  23. var getNumberStyles = function(editor) {
  24. var styles = editor.getParam("advlist_number_styles", "default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman");
  25. return styles ? styles.split(/[ ,]/) : [];
  26. };
  27. var getBulletStyles = function(editor) {
  28. var styles = editor.getParam("advlist_bullet_styles", "default,circle,square");
  29. return styles ? styles.split(/[ ,]/) : [];
  30. };
  31. var noop = function() {
  32. };
  33. var constant = function(value) {
  34. return function() {
  35. return value;
  36. };
  37. };
  38. var identity = function(x) {
  39. return x;
  40. };
  41. var never = constant(false);
  42. var always = constant(true);
  43. var none = function() {
  44. return NONE;
  45. };
  46. var NONE = function() {
  47. var call = function(thunk) {
  48. return thunk();
  49. };
  50. var id = identity;
  51. var me = {
  52. fold: function(n, _s) {
  53. return n();
  54. },
  55. isSome: never,
  56. isNone: always,
  57. getOr: id,
  58. getOrThunk: call,
  59. getOrDie: function(msg) {
  60. throw new Error(msg || "error: getOrDie called on none.");
  61. },
  62. getOrNull: constant(null),
  63. getOrUndefined: constant(void 0),
  64. or: id,
  65. orThunk: call,
  66. map: none,
  67. each: noop,
  68. bind: none,
  69. exists: never,
  70. forall: always,
  71. filter: function() {
  72. return none();
  73. },
  74. toArray: function() {
  75. return [];
  76. },
  77. toString: constant("none()")
  78. };
  79. return me;
  80. }();
  81. var some = function(a) {
  82. var constant_a = constant(a);
  83. var self = function() {
  84. return me;
  85. };
  86. var bind = function(f) {
  87. return f(a);
  88. };
  89. var me = {
  90. fold: function(n, s) {
  91. return s(a);
  92. },
  93. isSome: always,
  94. isNone: never,
  95. getOr: constant_a,
  96. getOrThunk: constant_a,
  97. getOrDie: constant_a,
  98. getOrNull: constant_a,
  99. getOrUndefined: constant_a,
  100. or: self,
  101. orThunk: self,
  102. map: function(f) {
  103. return some(f(a));
  104. },
  105. each: function(f) {
  106. f(a);
  107. },
  108. bind,
  109. exists: bind,
  110. forall: bind,
  111. filter: function(f) {
  112. return f(a) ? me : NONE;
  113. },
  114. toArray: function() {
  115. return [a];
  116. },
  117. toString: function() {
  118. return "some(" + a + ")";
  119. }
  120. };
  121. return me;
  122. };
  123. var from = function(value) {
  124. return value === null || value === void 0 ? NONE : some(value);
  125. };
  126. var Optional = {
  127. some,
  128. none,
  129. from
  130. };
  131. var isChildOfBody = function(editor, elm) {
  132. return editor.$.contains(editor.getBody(), elm);
  133. };
  134. var isTableCellNode = function(node) {
  135. return node && /^(TH|TD)$/.test(node.nodeName);
  136. };
  137. var isListNode = function(editor) {
  138. return function(node) {
  139. return node && /^(OL|UL|DL)$/.test(node.nodeName) && isChildOfBody(editor, node);
  140. };
  141. };
  142. var getSelectedStyleType = function(editor) {
  143. var listElm = editor.dom.getParent(editor.selection.getNode(), "ol,ul");
  144. var style = editor.dom.getStyle(listElm, "listStyleType");
  145. return Optional.from(style);
  146. };
  147. var findIndex = function(list, predicate) {
  148. for (var index = 0; index < list.length; index++) {
  149. var element = list[index];
  150. if (predicate(element)) {
  151. return index;
  152. }
  153. }
  154. return -1;
  155. };
  156. var styleValueToText = function(styleValue) {
  157. return styleValue.replace(/\-/g, " ").replace(/\b\w/g, function(chr) {
  158. return chr.toUpperCase();
  159. });
  160. };
  161. var isWithinList = function(editor, e, nodeName) {
  162. var tableCellIndex = findIndex(e.parents, isTableCellNode);
  163. var parents = tableCellIndex !== -1 ? e.parents.slice(0, tableCellIndex) : e.parents;
  164. var lists = global.grep(parents, isListNode(editor));
  165. return lists.length > 0 && lists[0].nodeName === nodeName;
  166. };
  167. var makeSetupHandler = function(editor, nodeName) {
  168. return function(api) {
  169. var nodeChangeHandler = function(e) {
  170. api.setActive(isWithinList(editor, e, nodeName));
  171. };
  172. editor.on("NodeChange", nodeChangeHandler);
  173. return function() {
  174. return editor.off("NodeChange", nodeChangeHandler);
  175. };
  176. };
  177. };
  178. var addSplitButton = function(editor, id, tooltip, cmd, nodeName, styles) {
  179. editor.ui.registry.addSplitButton(id, {
  180. tooltip,
  181. icon: nodeName === "OL" ? "ordered-list" : "unordered-list",
  182. presets: "listpreview",
  183. columns: 3,
  184. fetch: function(callback) {
  185. var items = global.map(styles, function(styleValue) {
  186. var iconStyle = nodeName === "OL" ? "num" : "bull";
  187. var iconName = styleValue === "disc" || styleValue === "decimal" ? "default" : styleValue;
  188. var itemValue = styleValue === "default" ? "" : styleValue;
  189. var displayText = styleValueToText(styleValue);
  190. return {
  191. type: "choiceitem",
  192. value: itemValue,
  193. icon: "list-" + iconStyle + "-" + iconName,
  194. text: displayText
  195. };
  196. });
  197. callback(items);
  198. },
  199. onAction: function() {
  200. return editor.execCommand(cmd);
  201. },
  202. onItemAction: function(_splitButtonApi, value) {
  203. applyListFormat(editor, nodeName, value);
  204. },
  205. select: function(value) {
  206. var listStyleType = getSelectedStyleType(editor);
  207. return listStyleType.map(function(listStyle) {
  208. return value === listStyle;
  209. }).getOr(false);
  210. },
  211. onSetup: makeSetupHandler(editor, nodeName)
  212. });
  213. };
  214. var addButton = function(editor, id, tooltip, cmd, nodeName, _styles) {
  215. editor.ui.registry.addToggleButton(id, {
  216. active: false,
  217. tooltip,
  218. icon: nodeName === "OL" ? "ordered-list" : "unordered-list",
  219. onSetup: makeSetupHandler(editor, nodeName),
  220. onAction: function() {
  221. return editor.execCommand(cmd);
  222. }
  223. });
  224. };
  225. var addControl = function(editor, id, tooltip, cmd, nodeName, styles) {
  226. if (styles.length > 1) {
  227. addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
  228. } else {
  229. addButton(editor, id, tooltip, cmd, nodeName);
  230. }
  231. };
  232. var register = function(editor) {
  233. addControl(editor, "numlist", "Numbered list", "InsertOrderedList", "OL", getNumberStyles(editor));
  234. addControl(editor, "bullist", "Bullet list", "InsertUnorderedList", "UL", getBulletStyles(editor));
  235. };
  236. function Plugin() {
  237. global$1.add("advlist", function(editor) {
  238. if (editor.hasPlugin("lists")) {
  239. register(editor);
  240. register$1(editor);
  241. } else {
  242. console.error("Please use the Lists plugin together with the Advanced List plugin.");
  243. }
  244. });
  245. }
  246. Plugin();
  247. })();
  248. }
  249. });
  250. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/advlist/index.js
  251. require_plugin();
  252. //# sourceMappingURL=tinymce_plugins_advlist.js.map