suneditor 2.44.6 → 2.44.7

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 (130) hide show
  1. package/LICENSE.txt +20 -20
  2. package/README.md +1585 -1585
  3. package/dist/suneditor.min.js +2 -2
  4. package/package.json +71 -71
  5. package/src/assets/css/suneditor-contents.css +556 -556
  6. package/src/assets/css/suneditor.css +0 -0
  7. package/src/assets/defaultIcons.js +103 -103
  8. package/src/lang/Lang.d.ts +143 -143
  9. package/src/lang/ckb.d.ts +4 -4
  10. package/src/lang/ckb.js +187 -187
  11. package/src/lang/da.d.ts +4 -4
  12. package/src/lang/da.js +191 -191
  13. package/src/lang/de.d.ts +4 -4
  14. package/src/lang/de.js +187 -187
  15. package/src/lang/en.d.ts +4 -4
  16. package/src/lang/en.js +187 -187
  17. package/src/lang/es.d.ts +4 -4
  18. package/src/lang/es.js +187 -187
  19. package/src/lang/fr.d.ts +4 -4
  20. package/src/lang/fr.js +188 -188
  21. package/src/lang/he.d.ts +4 -4
  22. package/src/lang/he.js +188 -188
  23. package/src/lang/index.d.ts +22 -22
  24. package/src/lang/index.js +25 -25
  25. package/src/lang/it.d.ts +4 -4
  26. package/src/lang/it.js +188 -188
  27. package/src/lang/ja.d.ts +4 -4
  28. package/src/lang/ja.js +187 -187
  29. package/src/lang/ko.d.ts +4 -4
  30. package/src/lang/ko.js +187 -187
  31. package/src/lang/lv.d.ts +4 -4
  32. package/src/lang/lv.js +187 -187
  33. package/src/lang/nl.d.ts +4 -4
  34. package/src/lang/nl.js +187 -187
  35. package/src/lang/pl.d.ts +4 -4
  36. package/src/lang/pl.js +187 -187
  37. package/src/lang/pt_br.d.ts +4 -4
  38. package/src/lang/pt_br.js +189 -189
  39. package/src/lang/ro.d.ts +4 -4
  40. package/src/lang/ro.js +187 -187
  41. package/src/lang/ru.d.ts +4 -4
  42. package/src/lang/ru.js +187 -187
  43. package/src/lang/se.d.ts +4 -4
  44. package/src/lang/se.js +191 -191
  45. package/src/lang/ua.d.ts +5 -5
  46. package/src/lang/ua.js +188 -188
  47. package/src/lang/ur.d.ts +4 -4
  48. package/src/lang/ur.js +187 -187
  49. package/src/lang/zh_cn.d.ts +4 -4
  50. package/src/lang/zh_cn.js +187 -187
  51. package/src/lib/constructor.js +0 -0
  52. package/src/lib/context.d.ts +42 -42
  53. package/src/lib/context.js +0 -0
  54. package/src/lib/core.d.ts +1101 -1101
  55. package/src/lib/core.js +12 -22
  56. package/src/lib/history.d.ts +48 -48
  57. package/src/lib/history.js +218 -218
  58. package/src/lib/util.d.ts +677 -677
  59. package/src/lib/util.js +19 -0
  60. package/src/options.d.ts +608 -608
  61. package/src/plugins/CommandPlugin.d.ts +7 -7
  62. package/src/plugins/DialogPlugin.d.ts +19 -19
  63. package/src/plugins/FileBrowserPlugin.d.ts +29 -29
  64. package/src/plugins/Module.d.ts +14 -14
  65. package/src/plugins/Plugin.d.ts +41 -41
  66. package/src/plugins/SubmenuPlugin.d.ts +7 -7
  67. package/src/plugins/command/blockquote.d.ts +4 -4
  68. package/src/plugins/command/blockquote.js +46 -46
  69. package/src/plugins/dialog/audio.d.ts +4 -4
  70. package/src/plugins/dialog/audio.js +556 -556
  71. package/src/plugins/dialog/image.d.ts +4 -4
  72. package/src/plugins/dialog/image.js +1122 -1122
  73. package/src/plugins/dialog/link.d.ts +4 -4
  74. package/src/plugins/dialog/link.js +223 -223
  75. package/src/plugins/dialog/math.d.ts +4 -4
  76. package/src/plugins/dialog/math.js +294 -294
  77. package/src/plugins/dialog/mention.d.ts +5 -5
  78. package/src/plugins/dialog/mention.js +242 -242
  79. package/src/plugins/dialog/video.d.ts +4 -4
  80. package/src/plugins/dialog/video.js +983 -983
  81. package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
  82. package/src/plugins/fileBrowser/imageGallery.js +63 -63
  83. package/src/plugins/index.d.ts +79 -79
  84. package/src/plugins/index.js +32 -32
  85. package/src/plugins/modules/_anchor.js +461 -461
  86. package/src/plugins/modules/_colorPicker.d.ts +59 -59
  87. package/src/plugins/modules/_colorPicker.js +0 -0
  88. package/src/plugins/modules/_notice.d.ts +20 -20
  89. package/src/plugins/modules/_notice.js +72 -72
  90. package/src/plugins/modules/_selectMenu.js +118 -118
  91. package/src/plugins/modules/component.d.ts +24 -24
  92. package/src/plugins/modules/component.js +82 -82
  93. package/src/plugins/modules/dialog.d.ts +27 -27
  94. package/src/plugins/modules/dialog.js +174 -174
  95. package/src/plugins/modules/fileBrowser.d.ts +41 -41
  96. package/src/plugins/modules/fileBrowser.js +373 -373
  97. package/src/plugins/modules/fileManager.d.ts +66 -66
  98. package/src/plugins/modules/fileManager.js +325 -325
  99. package/src/plugins/modules/index.d.ts +10 -10
  100. package/src/plugins/modules/index.js +8 -8
  101. package/src/plugins/modules/resizing.d.ts +153 -153
  102. package/src/plugins/modules/resizing.js +895 -895
  103. package/src/plugins/submenu/align.d.ts +4 -4
  104. package/src/plugins/submenu/align.js +160 -160
  105. package/src/plugins/submenu/font.d.ts +4 -4
  106. package/src/plugins/submenu/font.js +120 -120
  107. package/src/plugins/submenu/fontColor.d.ts +4 -4
  108. package/src/plugins/submenu/fontColor.js +0 -0
  109. package/src/plugins/submenu/fontSize.d.ts +4 -4
  110. package/src/plugins/submenu/fontSize.js +112 -112
  111. package/src/plugins/submenu/formatBlock.d.ts +4 -4
  112. package/src/plugins/submenu/formatBlock.js +273 -273
  113. package/src/plugins/submenu/hiliteColor.d.ts +4 -4
  114. package/src/plugins/submenu/hiliteColor.js +0 -0
  115. package/src/plugins/submenu/horizontalRule.d.ts +4 -4
  116. package/src/plugins/submenu/horizontalRule.js +98 -98
  117. package/src/plugins/submenu/lineHeight.d.ts +4 -4
  118. package/src/plugins/submenu/lineHeight.js +104 -104
  119. package/src/plugins/submenu/list.d.ts +4 -4
  120. package/src/plugins/submenu/list.js +456 -456
  121. package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
  122. package/src/plugins/submenu/paragraphStyle.js +135 -135
  123. package/src/plugins/submenu/table.d.ts +4 -4
  124. package/src/plugins/submenu/template.d.ts +4 -4
  125. package/src/plugins/submenu/template.js +71 -71
  126. package/src/plugins/submenu/textStyle.d.ts +4 -4
  127. package/src/plugins/submenu/textStyle.js +167 -167
  128. package/src/suneditor.d.ts +9 -9
  129. package/src/suneditor.js +75 -75
  130. package/src/suneditor_build.js +17 -17
@@ -1,456 +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 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
- };
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
+ };