suneditor 2.44.2 → 2.44.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE.txt +20 -20
  2. package/README.md +1585 -1585
  3. package/dist/css/suneditor.min.css +1 -1
  4. package/dist/suneditor.min.js +2 -2
  5. package/package.json +71 -71
  6. package/src/assets/css/suneditor-contents.css +556 -556
  7. package/src/assets/css/suneditor.css +0 -0
  8. package/src/assets/defaultIcons.js +103 -103
  9. package/src/lang/Lang.d.ts +143 -143
  10. package/src/lang/ckb.d.ts +4 -4
  11. package/src/lang/ckb.js +187 -187
  12. package/src/lang/da.d.ts +4 -4
  13. package/src/lang/da.js +191 -191
  14. package/src/lang/de.d.ts +4 -4
  15. package/src/lang/de.js +187 -187
  16. package/src/lang/en.d.ts +4 -4
  17. package/src/lang/en.js +187 -187
  18. package/src/lang/es.d.ts +4 -4
  19. package/src/lang/es.js +187 -187
  20. package/src/lang/fr.d.ts +4 -4
  21. package/src/lang/fr.js +188 -188
  22. package/src/lang/he.d.ts +4 -4
  23. package/src/lang/he.js +188 -188
  24. package/src/lang/index.d.ts +22 -21
  25. package/src/lang/index.js +25 -24
  26. package/src/lang/it.d.ts +4 -4
  27. package/src/lang/it.js +188 -188
  28. package/src/lang/ja.d.ts +4 -4
  29. package/src/lang/ja.js +187 -187
  30. package/src/lang/ko.d.ts +4 -4
  31. package/src/lang/ko.js +187 -187
  32. package/src/lang/lv.d.ts +4 -4
  33. package/src/lang/lv.js +187 -187
  34. package/src/lang/nl.d.ts +4 -4
  35. package/src/lang/nl.js +187 -187
  36. package/src/lang/pl.d.ts +4 -4
  37. package/src/lang/pl.js +187 -187
  38. package/src/lang/pt_br.d.ts +4 -4
  39. package/src/lang/pt_br.js +189 -189
  40. package/src/lang/ro.d.ts +4 -4
  41. package/src/lang/ro.js +187 -187
  42. package/src/lang/ru.d.ts +4 -4
  43. package/src/lang/ru.js +187 -187
  44. package/src/lang/se.d.ts +4 -4
  45. package/src/lang/se.js +191 -191
  46. package/src/lang/ua.d.ts +5 -5
  47. package/src/lang/ua.js +188 -188
  48. package/src/lang/ur.d.ts +5 -0
  49. package/src/lang/ur.js +188 -0
  50. package/src/lang/zh_cn.d.ts +4 -4
  51. package/src/lang/zh_cn.js +187 -187
  52. package/src/lib/constructor.js +1 -2
  53. package/src/lib/context.d.ts +42 -42
  54. package/src/lib/context.js +0 -0
  55. package/src/lib/core.d.ts +1101 -1101
  56. package/src/lib/core.js +220 -99
  57. package/src/lib/history.d.ts +48 -48
  58. package/src/lib/history.js +218 -218
  59. package/src/lib/util.d.ts +677 -677
  60. package/src/lib/util.js +38 -12
  61. package/src/options.d.ts +608 -608
  62. package/src/plugins/CommandPlugin.d.ts +7 -7
  63. package/src/plugins/DialogPlugin.d.ts +19 -19
  64. package/src/plugins/FileBrowserPlugin.d.ts +29 -29
  65. package/src/plugins/Module.d.ts +14 -14
  66. package/src/plugins/Plugin.d.ts +41 -41
  67. package/src/plugins/SubmenuPlugin.d.ts +7 -7
  68. package/src/plugins/command/blockquote.d.ts +4 -4
  69. package/src/plugins/command/blockquote.js +46 -46
  70. package/src/plugins/dialog/audio.d.ts +4 -4
  71. package/src/plugins/dialog/audio.js +556 -554
  72. package/src/plugins/dialog/image.d.ts +4 -4
  73. package/src/plugins/dialog/image.js +1122 -1107
  74. package/src/plugins/dialog/link.d.ts +4 -4
  75. package/src/plugins/dialog/link.js +223 -223
  76. package/src/plugins/dialog/math.d.ts +4 -4
  77. package/src/plugins/dialog/math.js +294 -294
  78. package/src/plugins/dialog/mention.d.ts +5 -5
  79. package/src/plugins/dialog/mention.js +242 -242
  80. package/src/plugins/dialog/video.d.ts +4 -4
  81. package/src/plugins/dialog/video.js +983 -981
  82. package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
  83. package/src/plugins/fileBrowser/imageGallery.js +63 -63
  84. package/src/plugins/index.d.ts +79 -79
  85. package/src/plugins/index.js +32 -32
  86. package/src/plugins/modules/_anchor.js +461 -462
  87. package/src/plugins/modules/_colorPicker.d.ts +59 -59
  88. package/src/plugins/modules/_colorPicker.js +0 -0
  89. package/src/plugins/modules/_notice.d.ts +20 -20
  90. package/src/plugins/modules/_notice.js +72 -72
  91. package/src/plugins/modules/_selectMenu.js +118 -118
  92. package/src/plugins/modules/component.d.ts +24 -24
  93. package/src/plugins/modules/component.js +82 -82
  94. package/src/plugins/modules/dialog.d.ts +27 -27
  95. package/src/plugins/modules/dialog.js +174 -174
  96. package/src/plugins/modules/fileBrowser.d.ts +41 -41
  97. package/src/plugins/modules/fileBrowser.js +373 -373
  98. package/src/plugins/modules/fileManager.d.ts +66 -66
  99. package/src/plugins/modules/fileManager.js +325 -324
  100. package/src/plugins/modules/index.d.ts +10 -10
  101. package/src/plugins/modules/index.js +8 -8
  102. package/src/plugins/modules/resizing.d.ts +153 -153
  103. package/src/plugins/modules/resizing.js +895 -895
  104. package/src/plugins/submenu/align.d.ts +4 -4
  105. package/src/plugins/submenu/align.js +160 -160
  106. package/src/plugins/submenu/font.d.ts +4 -4
  107. package/src/plugins/submenu/font.js +120 -120
  108. package/src/plugins/submenu/fontColor.d.ts +4 -4
  109. package/src/plugins/submenu/fontColor.js +0 -0
  110. package/src/plugins/submenu/fontSize.d.ts +4 -4
  111. package/src/plugins/submenu/fontSize.js +112 -112
  112. package/src/plugins/submenu/formatBlock.d.ts +4 -4
  113. package/src/plugins/submenu/formatBlock.js +273 -273
  114. package/src/plugins/submenu/hiliteColor.d.ts +4 -4
  115. package/src/plugins/submenu/hiliteColor.js +0 -0
  116. package/src/plugins/submenu/horizontalRule.d.ts +4 -4
  117. package/src/plugins/submenu/horizontalRule.js +98 -98
  118. package/src/plugins/submenu/lineHeight.d.ts +4 -4
  119. package/src/plugins/submenu/lineHeight.js +104 -104
  120. package/src/plugins/submenu/list.d.ts +4 -4
  121. package/src/plugins/submenu/list.js +456 -455
  122. package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
  123. package/src/plugins/submenu/paragraphStyle.js +135 -135
  124. package/src/plugins/submenu/table.d.ts +4 -4
  125. package/src/plugins/submenu/template.d.ts +4 -4
  126. package/src/plugins/submenu/template.js +71 -71
  127. package/src/plugins/submenu/textStyle.d.ts +4 -4
  128. package/src/plugins/submenu/textStyle.js +167 -167
  129. package/src/suneditor.d.ts +9 -9
  130. package/src/suneditor.js +75 -75
  131. package/src/suneditor_build.js +17 -17
@@ -1,455 +1,456 @@
1
- /*
2
- * wysiwyg web editor
3
- *
4
- * suneditor.js
5
- * Copyright 2017 JiHong Lee.
6
- * MIT license.
7
- */
8
- 'use strict';
9
-
10
- export default {
11
- name: 'list',
12
- display: 'submenu',
13
- add: function (core, targetElement) {
14
- const context = core.context;
15
- context.list = {
16
- targetButton: targetElement,
17
- _list: null,
18
- currentList: '',
19
- icons: {
20
- bullets: core.icons.list_bullets,
21
- number: core.icons.list_number
22
- }
23
- };
24
-
25
- /** set submenu */
26
- let listDiv = this.setSubmenu(core);
27
- let listUl = listDiv.querySelector('ul');
28
-
29
- /** add event listeners */
30
- listUl.addEventListener('click', this.pickup.bind(core));
31
- context.list._list = listUl.querySelectorAll('li button');
32
-
33
- /** append target button menu */
34
- core.initMenuTarget(this.name, targetElement, listDiv);
35
-
36
- /** empty memory */
37
- listDiv = null, listUl = null;
38
- },
39
-
40
- setSubmenu: function (core) {
41
- const lang = core.lang;
42
- const listDiv = core.util.createElement('DIV');
43
-
44
- listDiv.className = 'se-submenu se-list-layer';
45
- listDiv.innerHTML = '' +
46
- '<div class="se-list-inner">' +
47
- '<ul class="se-list-basic">' +
48
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="OL" title="' + lang.toolbar.orderList + '" aria-label="' + lang.toolbar.orderList + '">' +
49
- core.icons.list_number +
50
- '</button></li>' +
51
- '<li><button type="button" class="se-btn-list se-tooltip" data-command="UL" title="' + lang.toolbar.unorderList + '" aria-label="' + lang.toolbar.unorderList + '">' +
52
- core.icons.list_bullets +
53
- '</button></li>' +
54
- '</ul>' +
55
- '</div>';
56
-
57
- return listDiv;
58
- },
59
-
60
- /**
61
- * @Override core
62
- */
63
- active: function (element) {
64
- const button = this.context.list.targetButton;
65
- const icon = button.firstElementChild;
66
- const util = this.util;
67
-
68
- if (util.isList(element)) {
69
- const nodeName = element.nodeName;
70
- button.setAttribute('data-focus', nodeName);
71
- util.addClass(button, 'active');
72
- if (/UL/i.test(nodeName)) {
73
- util.changeElement(icon, this.context.list.icons.bullets);
74
- } else {
75
- util.changeElement(icon, this.context.list.icons.number);
76
- }
77
-
78
- return true;
79
- } else {
80
- button.removeAttribute('data-focus');
81
- util.changeElement(icon, this.context.list.icons.number);
82
- util.removeClass(button, 'active');
83
- }
84
-
85
- return false;
86
- },
87
-
88
- /**
89
- * @Override submenu
90
- */
91
- on: function () {
92
- const listContext = this.context.list;
93
- const list = listContext._list;
94
- const currentList = listContext.targetButton.getAttribute('data-focus') || '';
95
-
96
- if (currentList !== listContext.currentList) {
97
- for (let i = 0, len = list.length; i < len; i++) {
98
- if (currentList === list[i].getAttribute('data-command')) {
99
- this.util.addClass(list[i], 'active');
100
- } else {
101
- this.util.removeClass(list[i], 'active');
102
- }
103
- }
104
-
105
- listContext.currentList = currentList;
106
- }
107
- },
108
-
109
- editList: function (command, selectedCells, detach) {
110
- let range = this.getRange();
111
- let selectedFormats = !selectedCells ? this.getSelectedElementsAndComponents(false) : selectedCells;
112
-
113
- if (selectedFormats.length === 0) {
114
- if (selectedCells) return;
115
- range = this.getRange_addLine(range, null);
116
- selectedFormats = this.getSelectedElementsAndComponents(false);
117
- if (selectedFormats.length === 0) return;
118
- }
119
-
120
- const util = this.util;
121
- util.sortByDepth(selectedFormats, true);
122
-
123
- // merge
124
- let firstSel = selectedFormats[0];
125
- let lastSel = selectedFormats[selectedFormats.length - 1];
126
- let topEl = (util.isListCell(firstSel) || util.isComponent(firstSel)) && !firstSel.previousElementSibling ? firstSel.parentNode.previousElementSibling : firstSel.previousElementSibling;
127
- let bottomEl = (util.isListCell(lastSel) || util.isComponent(lastSel)) && !lastSel.nextElementSibling ? lastSel.parentNode.nextElementSibling : lastSel.nextElementSibling;
128
-
129
- const originRange = {
130
- sc: range.startContainer,
131
- so: (range.startContainer === range.endContainer && util.onlyZeroWidthSpace(range.startContainer) && range.startOffset === 0 && range.endOffset === 1) ? range.endOffset : range.startOffset,
132
- ec: range.endContainer,
133
- eo: range.endOffset
134
- };
135
-
136
- let isRemove = true;
137
-
138
- for (let i = 0, len = selectedFormats.length; i < len; i++) {
139
- if (!util.isList(util.getRangeFormatElement(selectedFormats[i], function (current) {
140
- return this.getRangeFormatElement(current) && current !== selectedFormats[i];
141
- }.bind(util)))) {
142
- isRemove = false;
143
- break;
144
- }
145
- }
146
-
147
- if (isRemove && (!topEl || (firstSel.tagName !== topEl.tagName || command !== topEl.tagName.toUpperCase())) && (!bottomEl || (lastSel.tagName !== bottomEl.tagName || command !== bottomEl.tagName.toUpperCase()))) {
148
- if (detach) {
149
- for (let i = 0, len = selectedFormats.length; i < len; i++) {
150
- for (let j = i - 1; j >= 0; j--) {
151
- if (selectedFormats[j].contains(selectedFormats[i])) {
152
- selectedFormats.splice(i, 1);
153
- i--; len--;
154
- break;
155
- }
156
- }
157
- }
158
- }
159
-
160
- const currentFormat = util.getRangeFormatElement(firstSel);
161
- const cancel = currentFormat && currentFormat.tagName === command;
162
- let rangeArr, tempList;
163
- const passComponent = function (current) {
164
- return !this.isComponent(current);
165
- }.bind(util);
166
-
167
- if (!cancel) tempList = util.createElement(command);
168
-
169
- for (let i = 0, len = selectedFormats.length, r, o; i < len; i++) {
170
- o = util.getRangeFormatElement(selectedFormats[i], passComponent);
171
- if (!o || !util.isList(o)) continue;
172
-
173
- if (!r) {
174
- r = o;
175
- rangeArr = {r: r, f: [util.getParentElement(selectedFormats[i], 'LI')]};
176
- } else {
177
- if (r !== o) {
178
- if (detach && util.isListCell(o.parentNode)) {
179
- this.plugins.list._detachNested.call(this, rangeArr.f);
180
- } else {
181
- this.detachRangeFormatElement(rangeArr.f[0].parentNode, rangeArr.f, tempList, false, true);
182
- }
183
-
184
- o = selectedFormats[i].parentNode;
185
- if (!cancel) tempList = util.createElement(command);
186
-
187
- r = o;
188
- rangeArr = {r: r, f: [util.getParentElement(selectedFormats[i], 'LI')]};
189
- } else {
190
- rangeArr.f.push(util.getParentElement(selectedFormats[i], 'LI'));
191
- }
192
- }
193
-
194
- if (i === len - 1) {
195
- if (detach && util.isListCell(o.parentNode)) {
196
- this.plugins.list._detachNested.call(this, rangeArr.f);
197
- } else {
198
- this.detachRangeFormatElement(rangeArr.f[0].parentNode, rangeArr.f, tempList, false, true);
199
- }
200
- }
201
- }
202
- } else {
203
- const topElParent = topEl ? topEl.parentNode : topEl;
204
- const bottomElParent = bottomEl ? bottomEl.parentNode : bottomEl;
205
- topEl = topElParent && !util.isWysiwygDiv(topElParent) && topElParent.nodeName === command ? topElParent : topEl;
206
- bottomEl = bottomElParent && !util.isWysiwygDiv(bottomElParent) && bottomElParent.nodeName === command ? bottomElParent : bottomEl;
207
-
208
- const mergeTop = topEl && topEl.tagName === command;
209
- const mergeBottom = bottomEl && bottomEl.tagName === command;
210
-
211
- let list = mergeTop ? topEl : util.createElement(command);
212
- let firstList = null;
213
- let lastList = null;
214
- let topNumber = null;
215
- let bottomNumber = null;
216
-
217
- const passComponent = function (current) {
218
- return !this.isComponent(current) && !this.isList(current);
219
- }.bind(util);
220
-
221
- for (let i = 0, len = selectedFormats.length, newCell, fTag, isCell, next, originParent, nextParent, parentTag, siblingTag, rangeTag; i < len; i++) {
222
- fTag = selectedFormats[i];
223
- if (fTag.childNodes.length === 0 && !util._isIgnoreNodeChange(fTag)) {
224
- util.removeItem(fTag);
225
- continue;
226
- }
227
- next = selectedFormats[i + 1];
228
- originParent = fTag.parentNode;
229
- nextParent = next ? next.parentNode : null;
230
- isCell = util.isListCell(fTag);
231
- rangeTag = util.isRangeFormatElement(originParent) ? originParent : null;
232
- parentTag = isCell && !util.isWysiwygDiv(originParent) ? originParent.parentNode : originParent;
233
- siblingTag = isCell && !util.isWysiwygDiv(originParent) ? (!next || util.isListCell(parentTag)) ? originParent : originParent.nextSibling : fTag.nextSibling;
234
-
235
- newCell = util.createElement('LI');
236
- util.copyFormatAttributes(newCell, fTag);
237
-
238
- if (i === 0 && originRange.sc === fTag) {
239
- originRange.sc = newCell;
240
- }
241
- if (i === len - 1 && originRange.ec === fTag) {
242
- originRange.ec = newCell;
243
- }
244
-
245
- if (util.isComponent(fTag)) {
246
- const isHR = /^HR$/i.test(fTag.nodeName);
247
- if (!isHR) newCell.innerHTML = '<br>';
248
- newCell.innerHTML += fTag.outerHTML;
249
- if (isHR) newCell.innerHTML += '<br>';
250
- } else {
251
- const fChildren = fTag.childNodes;
252
- while (fChildren[0]) {
253
- newCell.appendChild(fChildren[0]);
254
- }
255
- }
256
- list.appendChild(newCell);
257
-
258
- if (!next) lastList = list;
259
- if (!next || parentTag !== nextParent || util.isRangeFormatElement(siblingTag)) {
260
- if (!firstList) firstList = list;
261
- if ((!mergeTop || !next || parentTag !== nextParent) && !(next && util.isList(nextParent) && nextParent === originParent)) {
262
- if (list.parentNode !== parentTag) parentTag.insertBefore(list, siblingTag);
263
- }
264
- }
265
-
266
- util.removeItem(fTag);
267
- if (mergeTop && topNumber === null) topNumber = list.children.length - 1;
268
- if (next && (util.getRangeFormatElement(nextParent, passComponent) !== util.getRangeFormatElement(originParent, passComponent) || (util.isList(nextParent) && util.isList(originParent) && util.getElementDepth(nextParent) !== util.getElementDepth(originParent)))) {
269
- list = util.createElement(command);
270
- }
271
-
272
- if (rangeTag && rangeTag.children.length === 0) util.removeItem(rangeTag);
273
- }
274
-
275
- if (topNumber) {
276
- firstList = firstList.children[topNumber];
277
- }
278
-
279
- if (mergeBottom) {
280
- bottomNumber = list.children.length - 1;
281
- list.innerHTML += bottomEl.innerHTML;
282
- lastList = list.children[bottomNumber];
283
- util.removeItem(bottomEl);
284
- }
285
- }
286
-
287
- this.effectNode = null;
288
- return originRange;
289
- },
290
-
291
- _detachNested: function (cells) {
292
- const first = cells[0];
293
- const last = cells[cells.length - 1];
294
- const next = last.nextElementSibling;
295
- const originList = first.parentNode;
296
- const sibling = originList.parentNode.nextElementSibling;
297
- const parentNode = originList.parentNode.parentNode;
298
-
299
- for (let c = 0, cLen = cells.length; c < cLen; c++) {
300
- parentNode.insertBefore(cells[c], sibling);
301
- }
302
-
303
- if (next && originList.children.length > 0) {
304
- const newList = originList.cloneNode(false);
305
- const children = originList.childNodes;
306
- const index = this.util.getPositionIndex(next);
307
- while (children[index]) {
308
- newList.appendChild(children[index]);
309
- }
310
- last.appendChild(newList);
311
- }
312
-
313
- if (originList.children.length === 0) this.util.removeItem(originList);
314
- this.util.mergeSameTags(parentNode);
315
-
316
- const edge = this.util.getEdgeChildNodes(first, last);
317
-
318
- return {
319
- cc: first.parentNode,
320
- sc: edge.sc,
321
- ec: edge.ec
322
- };
323
- },
324
-
325
- editInsideList: function (remove, selectedCells) {
326
- selectedCells = !selectedCells ? this.getSelectedElements().filter(function (el) { return this.isListCell(el); }.bind(this.util)) : selectedCells;
327
- const cellsLen = selectedCells.length;
328
- if (cellsLen === 0 || (!remove && (!this.util.isListCell(selectedCells[0].previousElementSibling) && !this.util.isListCell(selectedCells[cellsLen - 1].nextElementSibling)))) {
329
- return {
330
- sc: selectedCells[0],
331
- so: 0,
332
- ec: selectedCells[cellsLen - 1],
333
- eo: 1
334
- };
335
- }
336
-
337
- let originList = selectedCells[0].parentNode;
338
- let lastCell = selectedCells[cellsLen - 1];
339
- let range = null;
340
-
341
- if (remove) {
342
- if (originList !== lastCell.parentNode && this.util.isList(lastCell.parentNode.parentNode) && lastCell.nextElementSibling) {
343
- lastCell = lastCell.nextElementSibling;
344
- while (lastCell) {
345
- selectedCells.push(lastCell);
346
- lastCell = lastCell.nextElementSibling;
347
- }
348
- }
349
- range = this.plugins.list.editList.call(this, originList.nodeName.toUpperCase(), selectedCells, true);
350
- } else {
351
- let innerList = this.util.createElement(originList.nodeName);
352
- let prev = selectedCells[0].previousElementSibling;
353
- let next = lastCell.nextElementSibling;
354
- const nodePath = { s: null, e: null, sl: originList, el: originList };
355
-
356
- for (let i = 0, len = cellsLen, c; i < len; i++) {
357
- c = selectedCells[i];
358
- if (c.parentNode !== originList) {
359
- this.plugins.list._insiedList.call(this, originList, innerList, prev, next, nodePath);
360
- originList = c.parentNode;
361
- innerList = this.util.createElement(originList.nodeName);
362
- }
363
-
364
- prev = c.previousElementSibling;
365
- next = c.nextElementSibling;
366
- innerList.appendChild(c);
367
- }
368
-
369
- this.plugins.list._insiedList.call(this, originList, innerList, prev, next, nodePath);
370
-
371
- const sc = this.util.getNodeFromPath(nodePath.s, nodePath.sl);
372
- const ec = this.util.getNodeFromPath(nodePath.e, nodePath.el);
373
- range = {
374
- sc: sc,
375
- so: 0,
376
- ec: ec,
377
- eo: ec.textContent.length
378
- };
379
- }
380
-
381
- return range;
382
- },
383
-
384
- _insiedList: function (originList, innerList, prev, next, nodePath) {
385
- let insertPrev = false;
386
-
387
- if (prev && innerList.tagName === prev.tagName) {
388
- const children = innerList.children;
389
- while (children[0]) {
390
- prev.appendChild(children[0]);
391
- }
392
-
393
- innerList = prev;
394
- insertPrev = true;
395
- }
396
-
397
- if (next && innerList.tagName === next.tagName) {
398
- const children = next.children;
399
- while (children[0]) {
400
- innerList.appendChild(children[0]);
401
- }
402
-
403
- const temp = next.nextElementSibling;
404
- next.parentNode.removeChild(next);
405
- next = temp;
406
- }
407
-
408
- if (!insertPrev) {
409
- if (this.util.isListCell(prev)) {
410
- originList = prev;
411
- next = null;
412
- }
413
-
414
- originList.insertBefore(innerList, next);
415
-
416
- if (!nodePath.s) {
417
- nodePath.s = this.util.getNodePath(innerList.firstElementChild.firstChild, originList, null);
418
- nodePath.sl = originList;
419
- }
420
-
421
- const slPath = originList.contains(nodePath.sl) ? this.util.getNodePath(nodePath.sl, originList) : null;
422
- nodePath.e = this.util.getNodePath(innerList.lastElementChild.firstChild, originList, null);
423
- nodePath.el = originList;
424
-
425
- this.util.mergeSameTags(originList, [nodePath.s, nodePath.e, slPath], false);
426
- this.util.mergeNestedTags(originList);
427
- if (slPath) nodePath.sl = this.util.getNodeFromPath(slPath, originList);
428
- }
429
-
430
- return innerList;
431
- },
432
-
433
- pickup: function (e) {
434
- e.preventDefault();
435
- e.stopPropagation();
436
-
437
- let target = e.target;
438
- let command = '';
439
-
440
- while (!command && !/^UL$/i.test(target.tagName)) {
441
- command = target.getAttribute('data-command');
442
- target = target.parentNode;
443
- }
444
-
445
- if (!command) return;
446
-
447
- const range = this.plugins.list.editList.call(this, command, null, false);
448
- if (range) this.setRange(range.sc, range.so, range.ec, range.eo);
449
-
450
- this.submenuOff();
451
-
452
- // history stack
453
- this.history.push(false);
454
- }
455
- };
1
+ /*
2
+ * wysiwyg web editor
3
+ *
4
+ * suneditor.js
5
+ * Copyright 2017 JiHong Lee.
6
+ * MIT license.
7
+ */
8
+ 'use strict';
9
+
10
+ export default {
11
+ name: 'list',
12
+ display: 'submenu',
13
+ add: function (core, targetElement) {
14
+ const context = core.context;
15
+ context.list = {
16
+ targetButton: targetElement,
17
+ _list: null,
18
+ currentList: '',
19
+ icons: {
20
+ bullets: core.icons.list_bullets,
21
+ number: core.icons.list_number
22
+ }
23
+ };
24
+
25
+ /** set submenu */
26
+ let listDiv = this.setSubmenu(core);
27
+ let listUl = listDiv.querySelector('ul');
28
+
29
+ /** add event listeners */
30
+ listUl.addEventListener('click', this.pickup.bind(core));
31
+ context.list._list = listUl.querySelectorAll('li button');
32
+
33
+ /** append target button menu */
34
+ core.initMenuTarget(this.name, targetElement, listDiv);
35
+
36
+ /** empty memory */
37
+ listDiv = null, listUl = null;
38
+ },
39
+
40
+ setSubmenu: function (core) {
41
+ const lang = core.lang;
42
+ const listDiv = core.util.createElement('DIV');
43
+
44
+ listDiv.className = 'se-submenu se-list-layer';
45
+ listDiv.innerHTML = '' +
46
+ '<div class="se-list-inner">' +
47
+ '<ul class="se-list-basic">' +
48
+ '<li><button type="button" class="se-btn-list se-tooltip" data-command="OL" title="' + lang.toolbar.orderList + '" aria-label="' + lang.toolbar.orderList + '">' +
49
+ core.icons.list_number +
50
+ '</button></li>' +
51
+ '<li><button type="button" class="se-btn-list se-tooltip" data-command="UL" title="' + lang.toolbar.unorderList + '" aria-label="' + lang.toolbar.unorderList + '">' +
52
+ core.icons.list_bullets +
53
+ '</button></li>' +
54
+ '</ul>' +
55
+ '</div>';
56
+
57
+ return listDiv;
58
+ },
59
+
60
+ /**
61
+ * @Override core
62
+ */
63
+ active: function (element) {
64
+ const button = this.context.list.targetButton;
65
+ const icon = button.firstElementChild;
66
+ const util = this.util;
67
+
68
+ if (util.isList(element)) {
69
+ const nodeName = element.nodeName;
70
+ button.setAttribute('data-focus', nodeName);
71
+ util.addClass(button, 'active');
72
+ if (/UL/i.test(nodeName)) {
73
+ util.changeElement(icon, this.context.list.icons.bullets);
74
+ } else {
75
+ util.changeElement(icon, this.context.list.icons.number);
76
+ }
77
+
78
+ return true;
79
+ } else {
80
+ button.removeAttribute('data-focus');
81
+ util.changeElement(icon, this.context.list.icons.number);
82
+ util.removeClass(button, 'active');
83
+ }
84
+
85
+ return false;
86
+ },
87
+
88
+ /**
89
+ * @Override submenu
90
+ */
91
+ on: function () {
92
+ const listContext = this.context.list;
93
+ const list = listContext._list;
94
+ const currentList = listContext.targetButton.getAttribute('data-focus') || '';
95
+
96
+ if (currentList !== listContext.currentList) {
97
+ for (let i = 0, len = list.length; i < len; i++) {
98
+ if (currentList === list[i].getAttribute('data-command')) {
99
+ this.util.addClass(list[i], 'active');
100
+ } else {
101
+ this.util.removeClass(list[i], 'active');
102
+ }
103
+ }
104
+
105
+ listContext.currentList = currentList;
106
+ }
107
+ },
108
+
109
+ editList: function (command, selectedCells, detach) {
110
+ let range = this.getRange();
111
+ let selectedFormats = !selectedCells ? this.getSelectedElementsAndComponents(false) : selectedCells;
112
+
113
+ if (selectedFormats.length === 0) {
114
+ if (selectedCells) return;
115
+ range = this.getRange_addLine(range, null);
116
+ selectedFormats = this.getSelectedElementsAndComponents(false);
117
+ if (selectedFormats.length === 0) return;
118
+ }
119
+
120
+ const util = this.util;
121
+ util.sortByDepth(selectedFormats, true);
122
+
123
+ // merge
124
+ let firstSel = selectedFormats[0];
125
+ let lastSel = selectedFormats[selectedFormats.length - 1];
126
+ let topEl = (util.isListCell(firstSel) || util.isComponent(firstSel)) && !firstSel.previousElementSibling ? firstSel.parentNode.previousElementSibling : firstSel.previousElementSibling;
127
+ let bottomEl = (util.isListCell(lastSel) || util.isComponent(lastSel)) && !lastSel.nextElementSibling ? lastSel.parentNode.nextElementSibling : lastSel.nextElementSibling;
128
+
129
+ const isCollapsed = range.collapsed;
130
+ const originRange = {
131
+ sc: range.startContainer,
132
+ so: (range.startContainer === range.endContainer && util.onlyZeroWidthSpace(range.startContainer) && range.startOffset === 0 && range.endOffset === 1) ? range.endOffset : range.startOffset,
133
+ ec: range.endContainer,
134
+ eo: range.endOffset
135
+ };
136
+ let afterRange = null;
137
+ let isRemove = true;
138
+
139
+ for (let i = 0, len = selectedFormats.length; i < len; i++) {
140
+ if (!util.isList(util.getRangeFormatElement(selectedFormats[i], function (current) {
141
+ return this.getRangeFormatElement(current) && current !== selectedFormats[i];
142
+ }.bind(util)))) {
143
+ isRemove = false;
144
+ break;
145
+ }
146
+ }
147
+
148
+ if (isRemove && (!topEl || (firstSel.tagName !== topEl.tagName || command !== topEl.tagName.toUpperCase())) && (!bottomEl || (lastSel.tagName !== bottomEl.tagName || command !== bottomEl.tagName.toUpperCase()))) {
149
+ if (detach) {
150
+ for (let i = 0, len = selectedFormats.length; i < len; i++) {
151
+ for (let j = i - 1; j >= 0; j--) {
152
+ if (selectedFormats[j].contains(selectedFormats[i])) {
153
+ selectedFormats.splice(i, 1);
154
+ i--; len--;
155
+ break;
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ const currentFormat = util.getRangeFormatElement(firstSel);
162
+ const cancel = currentFormat && currentFormat.tagName === command;
163
+ let rangeArr, tempList;
164
+ const passComponent = function (current) {
165
+ return !this.isComponent(current);
166
+ }.bind(util);
167
+
168
+ if (!cancel) tempList = util.createElement(command);
169
+
170
+ for (let i = 0, len = selectedFormats.length, r, o; i < len; i++) {
171
+ o = util.getRangeFormatElement(selectedFormats[i], passComponent);
172
+ if (!o || !util.isList(o)) continue;
173
+
174
+ if (!r) {
175
+ r = o;
176
+ rangeArr = {r: r, f: [util.getParentElement(selectedFormats[i], 'LI')]};
177
+ } else {
178
+ if (r !== o) {
179
+ if (detach && util.isListCell(o.parentNode)) {
180
+ this.plugins.list._detachNested.call(this, rangeArr.f);
181
+ } else {
182
+ afterRange = this.detachRangeFormatElement(rangeArr.f[0].parentNode, rangeArr.f, tempList, false, true);
183
+ }
184
+
185
+ o = selectedFormats[i].parentNode;
186
+ if (!cancel) tempList = util.createElement(command);
187
+
188
+ r = o;
189
+ rangeArr = {r: r, f: [util.getParentElement(selectedFormats[i], 'LI')]};
190
+ } else {
191
+ rangeArr.f.push(util.getParentElement(selectedFormats[i], 'LI'));
192
+ }
193
+ }
194
+
195
+ if (i === len - 1) {
196
+ if (detach && util.isListCell(o.parentNode)) {
197
+ this.plugins.list._detachNested.call(this, rangeArr.f);
198
+ } else {
199
+ afterRange = this.detachRangeFormatElement(rangeArr.f[0].parentNode, rangeArr.f, tempList, false, true);
200
+ }
201
+ }
202
+ }
203
+ } else {
204
+ const topElParent = topEl ? topEl.parentNode : topEl;
205
+ const bottomElParent = bottomEl ? bottomEl.parentNode : bottomEl;
206
+ topEl = topElParent && !util.isWysiwygDiv(topElParent) && topElParent.nodeName === command ? topElParent : topEl;
207
+ bottomEl = bottomElParent && !util.isWysiwygDiv(bottomElParent) && bottomElParent.nodeName === command ? bottomElParent : bottomEl;
208
+
209
+ const mergeTop = topEl && topEl.tagName === command;
210
+ const mergeBottom = bottomEl && bottomEl.tagName === command;
211
+
212
+ let list = mergeTop ? topEl : util.createElement(command);
213
+ let firstList = null;
214
+ let lastList = null;
215
+ let topNumber = null;
216
+ let bottomNumber = null;
217
+
218
+ const passComponent = function (current) {
219
+ return !this.isComponent(current) && !this.isList(current);
220
+ }.bind(util);
221
+
222
+ for (let i = 0, len = selectedFormats.length, newCell, fTag, isCell, next, originParent, nextParent, parentTag, siblingTag, rangeTag; i < len; i++) {
223
+ fTag = selectedFormats[i];
224
+ if (fTag.childNodes.length === 0 && !util._isIgnoreNodeChange(fTag)) {
225
+ util.removeItem(fTag);
226
+ continue;
227
+ }
228
+ next = selectedFormats[i + 1];
229
+ originParent = fTag.parentNode;
230
+ nextParent = next ? next.parentNode : null;
231
+ isCell = util.isListCell(fTag);
232
+ rangeTag = util.isRangeFormatElement(originParent) ? originParent : null;
233
+ parentTag = isCell && !util.isWysiwygDiv(originParent) ? originParent.parentNode : originParent;
234
+ siblingTag = isCell && !util.isWysiwygDiv(originParent) ? (!next || util.isListCell(parentTag)) ? originParent : originParent.nextSibling : fTag.nextSibling;
235
+
236
+ newCell = util.createElement('LI');
237
+ util.copyFormatAttributes(newCell, fTag);
238
+
239
+ if (i === 0 && originRange.sc === fTag) {
240
+ originRange.sc = newCell;
241
+ }
242
+ if (i === len - 1 && originRange.ec === fTag) {
243
+ originRange.ec = newCell;
244
+ }
245
+
246
+ if (util.isComponent(fTag)) {
247
+ const isHR = /^HR$/i.test(fTag.nodeName);
248
+ if (!isHR) newCell.innerHTML = '<br>';
249
+ newCell.innerHTML += fTag.outerHTML;
250
+ if (isHR) newCell.innerHTML += '<br>';
251
+ } else {
252
+ const fChildren = fTag.childNodes;
253
+ while (fChildren[0]) {
254
+ newCell.appendChild(fChildren[0]);
255
+ }
256
+ }
257
+ list.appendChild(newCell);
258
+
259
+ if (!next) lastList = list;
260
+ if (!next || parentTag !== nextParent || util.isRangeFormatElement(siblingTag)) {
261
+ if (!firstList) firstList = list;
262
+ if ((!mergeTop || !next || parentTag !== nextParent) && !(next && util.isList(nextParent) && nextParent === originParent)) {
263
+ if (list.parentNode !== parentTag) parentTag.insertBefore(list, siblingTag);
264
+ }
265
+ }
266
+
267
+ util.removeItem(fTag);
268
+ if (mergeTop && topNumber === null) topNumber = list.children.length - 1;
269
+ if (next && (util.getRangeFormatElement(nextParent, passComponent) !== util.getRangeFormatElement(originParent, passComponent) || (util.isList(nextParent) && util.isList(originParent) && util.getElementDepth(nextParent) !== util.getElementDepth(originParent)))) {
270
+ list = util.createElement(command);
271
+ }
272
+
273
+ if (rangeTag && rangeTag.children.length === 0) util.removeItem(rangeTag);
274
+ }
275
+
276
+ if (topNumber) {
277
+ firstList = firstList.children[topNumber];
278
+ }
279
+
280
+ if (mergeBottom) {
281
+ bottomNumber = list.children.length - 1;
282
+ list.innerHTML += bottomEl.innerHTML;
283
+ lastList = list.children[bottomNumber];
284
+ util.removeItem(bottomEl);
285
+ }
286
+ }
287
+
288
+ this.effectNode = null;
289
+ return !isCollapsed ? originRange : afterRange;
290
+ },
291
+
292
+ _detachNested: function (cells) {
293
+ const first = cells[0];
294
+ const last = cells[cells.length - 1];
295
+ const next = last.nextElementSibling;
296
+ const originList = first.parentNode;
297
+ const sibling = originList.parentNode.nextElementSibling;
298
+ const parentNode = originList.parentNode.parentNode;
299
+
300
+ for (let c = 0, cLen = cells.length; c < cLen; c++) {
301
+ parentNode.insertBefore(cells[c], sibling);
302
+ }
303
+
304
+ if (next && originList.children.length > 0) {
305
+ const newList = originList.cloneNode(false);
306
+ const children = originList.childNodes;
307
+ const index = this.util.getPositionIndex(next);
308
+ while (children[index]) {
309
+ newList.appendChild(children[index]);
310
+ }
311
+ last.appendChild(newList);
312
+ }
313
+
314
+ if (originList.children.length === 0) this.util.removeItem(originList);
315
+ this.util.mergeSameTags(parentNode);
316
+
317
+ const edge = this.util.getEdgeChildNodes(first, last);
318
+
319
+ return {
320
+ cc: first.parentNode,
321
+ sc: edge.sc,
322
+ ec: edge.ec
323
+ };
324
+ },
325
+
326
+ editInsideList: function (remove, selectedCells) {
327
+ selectedCells = !selectedCells ? this.getSelectedElements().filter(function (el) { return this.isListCell(el); }.bind(this.util)) : selectedCells;
328
+ const cellsLen = selectedCells.length;
329
+ if (cellsLen === 0 || (!remove && (!this.util.isListCell(selectedCells[0].previousElementSibling) && !this.util.isListCell(selectedCells[cellsLen - 1].nextElementSibling)))) {
330
+ return {
331
+ sc: selectedCells[0],
332
+ so: 0,
333
+ ec: selectedCells[cellsLen - 1],
334
+ eo: 1
335
+ };
336
+ }
337
+
338
+ let originList = selectedCells[0].parentNode;
339
+ let lastCell = selectedCells[cellsLen - 1];
340
+ let range = null;
341
+
342
+ if (remove) {
343
+ if (originList !== lastCell.parentNode && this.util.isList(lastCell.parentNode.parentNode) && lastCell.nextElementSibling) {
344
+ lastCell = lastCell.nextElementSibling;
345
+ while (lastCell) {
346
+ selectedCells.push(lastCell);
347
+ lastCell = lastCell.nextElementSibling;
348
+ }
349
+ }
350
+ range = this.plugins.list.editList.call(this, originList.nodeName.toUpperCase(), selectedCells, true);
351
+ } else {
352
+ let innerList = this.util.createElement(originList.nodeName);
353
+ let prev = selectedCells[0].previousElementSibling;
354
+ let next = lastCell.nextElementSibling;
355
+ const nodePath = { s: null, e: null, sl: originList, el: originList };
356
+
357
+ for (let i = 0, len = cellsLen, c; i < len; i++) {
358
+ c = selectedCells[i];
359
+ if (c.parentNode !== originList) {
360
+ this.plugins.list._insiedList.call(this, originList, innerList, prev, next, nodePath);
361
+ originList = c.parentNode;
362
+ innerList = this.util.createElement(originList.nodeName);
363
+ }
364
+
365
+ prev = c.previousElementSibling;
366
+ next = c.nextElementSibling;
367
+ innerList.appendChild(c);
368
+ }
369
+
370
+ this.plugins.list._insiedList.call(this, originList, innerList, prev, next, nodePath);
371
+
372
+ const sc = this.util.getNodeFromPath(nodePath.s, nodePath.sl);
373
+ const ec = this.util.getNodeFromPath(nodePath.e, nodePath.el);
374
+ range = {
375
+ sc: sc,
376
+ so: 0,
377
+ ec: ec,
378
+ eo: ec.textContent.length
379
+ };
380
+ }
381
+
382
+ return range;
383
+ },
384
+
385
+ _insiedList: function (originList, innerList, prev, next, nodePath) {
386
+ let insertPrev = false;
387
+
388
+ if (prev && innerList.tagName === prev.tagName) {
389
+ const children = innerList.children;
390
+ while (children[0]) {
391
+ prev.appendChild(children[0]);
392
+ }
393
+
394
+ innerList = prev;
395
+ insertPrev = true;
396
+ }
397
+
398
+ if (next && innerList.tagName === next.tagName) {
399
+ const children = next.children;
400
+ while (children[0]) {
401
+ innerList.appendChild(children[0]);
402
+ }
403
+
404
+ const temp = next.nextElementSibling;
405
+ next.parentNode.removeChild(next);
406
+ next = temp;
407
+ }
408
+
409
+ if (!insertPrev) {
410
+ if (this.util.isListCell(prev)) {
411
+ originList = prev;
412
+ next = null;
413
+ }
414
+
415
+ originList.insertBefore(innerList, next);
416
+
417
+ if (!nodePath.s) {
418
+ nodePath.s = this.util.getNodePath(innerList.firstElementChild.firstChild, originList, null);
419
+ nodePath.sl = originList;
420
+ }
421
+
422
+ const slPath = originList.contains(nodePath.sl) ? this.util.getNodePath(nodePath.sl, originList) : null;
423
+ nodePath.e = this.util.getNodePath(innerList.lastElementChild.firstChild, originList, null);
424
+ nodePath.el = originList;
425
+
426
+ this.util.mergeSameTags(originList, [nodePath.s, nodePath.e, slPath], false);
427
+ this.util.mergeNestedTags(originList);
428
+ if (slPath) nodePath.sl = this.util.getNodeFromPath(slPath, originList);
429
+ }
430
+
431
+ return innerList;
432
+ },
433
+
434
+ pickup: function (e) {
435
+ e.preventDefault();
436
+ e.stopPropagation();
437
+
438
+ let target = e.target;
439
+ let command = '';
440
+
441
+ while (!command && !/^UL$/i.test(target.tagName)) {
442
+ command = target.getAttribute('data-command');
443
+ target = target.parentNode;
444
+ }
445
+
446
+ if (!command) return;
447
+
448
+ const range = this.plugins.list.editList.call(this, command, null, false);
449
+ if (range) this.setRange(range.sc, range.so, range.ec, range.eo);
450
+
451
+ this.submenuOff();
452
+
453
+ // history stack
454
+ this.history.push(false);
455
+ }
456
+ };