suneditor 3.0.0-beta.2 → 3.0.0-beta.20
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.
- package/CONTRIBUTING.md +186 -184
- package/LICENSE +21 -21
- package/README.md +157 -180
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +126 -123
- package/src/assets/design/color.css +131 -121
- package/src/assets/design/index.css +3 -3
- package/src/assets/design/size.css +37 -35
- package/src/assets/design/typography.css +37 -37
- package/src/assets/icons/defaultIcons.js +247 -232
- package/src/assets/suneditor-contents.css +779 -778
- package/src/assets/suneditor.css +43 -35
- package/src/core/base/eventHandlers/handler_toolbar.js +135 -135
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +56 -56
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +115 -113
- package/src/core/base/eventHandlers/handler_ww_key_input.js +1200 -1200
- package/src/core/base/eventHandlers/handler_ww_mouse.js +194 -194
- package/src/core/base/eventManager.js +1550 -1484
- package/src/core/base/history.js +355 -355
- package/src/core/class/char.js +163 -162
- package/src/core/class/component.js +856 -842
- package/src/core/class/format.js +3433 -3422
- package/src/core/class/html.js +1927 -1890
- package/src/core/class/menu.js +357 -346
- package/src/core/class/nodeTransform.js +424 -424
- package/src/core/class/offset.js +858 -891
- package/src/core/class/selection.js +710 -620
- package/src/core/class/shortcuts.js +98 -98
- package/src/core/class/toolbar.js +438 -430
- package/src/core/class/ui.js +424 -422
- package/src/core/class/viewer.js +750 -750
- package/src/core/editor.js +1810 -1708
- package/src/core/section/actives.js +268 -241
- package/src/core/section/constructor.js +1348 -1661
- package/src/core/section/context.js +102 -102
- package/src/core/section/documentType.js +582 -561
- package/src/core/section/options.js +367 -0
- package/src/core/util/instanceCheck.js +59 -0
- package/src/editorInjector/_classes.js +36 -36
- package/src/editorInjector/_core.js +92 -92
- package/src/editorInjector/index.js +75 -75
- package/src/events.js +634 -622
- package/src/helper/clipboard.js +59 -59
- package/src/helper/converter.js +586 -564
- package/src/helper/dom/domCheck.js +304 -304
- package/src/helper/dom/domQuery.js +677 -669
- package/src/helper/dom/domUtils.js +618 -557
- package/src/helper/dom/index.js +12 -12
- package/src/helper/env.js +249 -240
- package/src/helper/index.js +25 -25
- package/src/helper/keyCodeMap.js +183 -183
- package/src/helper/numbers.js +72 -72
- package/src/helper/unicode.js +47 -47
- package/src/langs/ckb.js +231 -231
- package/src/langs/cs.js +231 -231
- package/src/langs/da.js +231 -231
- package/src/langs/de.js +231 -231
- package/src/langs/en.js +230 -230
- package/src/langs/es.js +231 -231
- package/src/langs/fa.js +231 -231
- package/src/langs/fr.js +231 -231
- package/src/langs/he.js +231 -231
- package/src/langs/hu.js +230 -230
- package/src/langs/index.js +28 -28
- package/src/langs/it.js +231 -231
- package/src/langs/ja.js +230 -230
- package/src/langs/km.js +230 -230
- package/src/langs/ko.js +230 -230
- package/src/langs/lv.js +231 -231
- package/src/langs/nl.js +231 -231
- package/src/langs/pl.js +231 -231
- package/src/langs/pt_br.js +231 -231
- package/src/langs/ro.js +231 -231
- package/src/langs/ru.js +231 -231
- package/src/langs/se.js +231 -231
- package/src/langs/tr.js +231 -231
- package/src/langs/uk.js +231 -231
- package/src/langs/ur.js +231 -231
- package/src/langs/zh_cn.js +231 -231
- package/src/modules/ApiManager.js +191 -191
- package/src/modules/Browser.js +669 -667
- package/src/modules/ColorPicker.js +364 -362
- package/src/modules/Controller.js +474 -454
- package/src/modules/Figure.js +1620 -1617
- package/src/modules/FileManager.js +359 -359
- package/src/modules/HueSlider.js +577 -565
- package/src/modules/Modal.js +346 -346
- package/src/modules/ModalAnchorEditor.js +643 -643
- package/src/modules/SelectMenu.js +549 -549
- package/src/modules/_DragHandle.js +17 -17
- package/src/modules/index.js +14 -14
- package/src/plugins/browser/audioGallery.js +83 -83
- package/src/plugins/browser/fileBrowser.js +103 -103
- package/src/plugins/browser/fileGallery.js +83 -83
- package/src/plugins/browser/imageGallery.js +81 -81
- package/src/plugins/browser/videoGallery.js +103 -103
- package/src/plugins/command/blockquote.js +61 -60
- package/src/plugins/command/exportPDF.js +134 -134
- package/src/plugins/command/fileUpload.js +456 -456
- package/src/plugins/command/list_bulleted.js +149 -148
- package/src/plugins/command/list_numbered.js +152 -151
- package/src/plugins/dropdown/align.js +157 -155
- package/src/plugins/dropdown/backgroundColor.js +108 -104
- package/src/plugins/dropdown/font.js +141 -137
- package/src/plugins/dropdown/fontColor.js +109 -105
- package/src/plugins/dropdown/formatBlock.js +170 -178
- package/src/plugins/dropdown/hr.js +152 -152
- package/src/plugins/dropdown/layout.js +83 -83
- package/src/plugins/dropdown/lineHeight.js +131 -130
- package/src/plugins/dropdown/list.js +123 -122
- package/src/plugins/dropdown/paragraphStyle.js +138 -138
- package/src/plugins/dropdown/table.js +4110 -4000
- package/src/plugins/dropdown/template.js +83 -83
- package/src/plugins/dropdown/textStyle.js +149 -149
- package/src/plugins/field/mention.js +242 -242
- package/src/plugins/index.js +120 -120
- package/src/plugins/input/fontSize.js +414 -410
- package/src/plugins/input/pageNavigator.js +71 -70
- package/src/plugins/modal/audio.js +677 -677
- package/src/plugins/modal/drawing.js +537 -531
- package/src/plugins/modal/embed.js +886 -886
- package/src/plugins/modal/image.js +1377 -1376
- package/src/plugins/modal/link.js +248 -240
- package/src/plugins/modal/math.js +563 -563
- package/src/plugins/modal/video.js +1226 -1226
- package/src/plugins/popup/anchor.js +224 -222
- package/src/suneditor.js +114 -107
- package/src/themes/dark.css +132 -122
- package/src/typedef.js +132 -130
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/core/base/eventManager.d.ts +29 -4
- package/types/core/class/char.d.ts +2 -1
- package/types/core/class/component.d.ts +1 -2
- package/types/core/class/format.d.ts +8 -1
- package/types/core/class/html.d.ts +8 -0
- package/types/core/class/menu.d.ts +8 -0
- package/types/core/class/offset.d.ts +24 -26
- package/types/core/class/selection.d.ts +2 -0
- package/types/core/class/toolbar.d.ts +6 -0
- package/types/core/class/ui.d.ts +1 -1
- package/types/core/editor.d.ts +34 -12
- package/types/core/section/constructor.d.ts +5 -638
- package/types/core/section/documentType.d.ts +12 -2
- package/types/core/section/options.d.ts +740 -0
- package/types/core/util/instanceCheck.d.ts +50 -0
- package/types/editorInjector/_core.d.ts +5 -5
- package/types/editorInjector/index.d.ts +2 -2
- package/types/events.d.ts +2 -0
- package/types/helper/converter.d.ts +9 -0
- package/types/helper/dom/domQuery.d.ts +5 -5
- package/types/helper/dom/domUtils.d.ts +8 -0
- package/types/helper/env.d.ts +6 -1
- package/types/helper/index.d.ts +4 -1
- package/types/index.d.ts +122 -120
- package/types/langs/_Lang.d.ts +194 -194
- package/types/modules/ColorPicker.d.ts +5 -1
- package/types/modules/Controller.d.ts +8 -4
- package/types/modules/Figure.d.ts +2 -1
- package/types/modules/HueSlider.d.ts +4 -1
- package/types/modules/SelectMenu.d.ts +1 -1
- package/types/plugins/command/blockquote.d.ts +1 -0
- package/types/plugins/command/list_bulleted.d.ts +1 -0
- package/types/plugins/command/list_numbered.d.ts +1 -0
- package/types/plugins/dropdown/align.d.ts +1 -0
- package/types/plugins/dropdown/backgroundColor.d.ts +1 -0
- package/types/plugins/dropdown/font.d.ts +1 -0
- package/types/plugins/dropdown/fontColor.d.ts +1 -0
- package/types/plugins/dropdown/formatBlock.d.ts +3 -2
- package/types/plugins/dropdown/lineHeight.d.ts +1 -0
- package/types/plugins/dropdown/list.d.ts +1 -0
- package/types/plugins/dropdown/table.d.ts +6 -0
- package/types/plugins/input/fontSize.d.ts +1 -0
- package/types/plugins/modal/drawing.d.ts +4 -0
- package/types/plugins/modal/link.d.ts +32 -15
- package/types/suneditor.d.ts +13 -9
- package/types/typedef.d.ts +8 -0
|
@@ -1,1661 +1,1348 @@
|
|
|
1
|
-
import _icons from '../../assets/icons/defaultIcons';
|
|
2
|
-
import _defaultLang from '../../langs/en';
|
|
3
|
-
import { CreateContext, CreateFrameContext } from './context';
|
|
4
|
-
import { dom, numbers, converter, env } from '../../helper';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
*/
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
o.set('
|
|
695
|
-
o.set('
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
o.
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
)
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
)
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
let
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
let
|
|
1200
|
-
let
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
pageDown: ['se-component-enabled', lang.pageDown, 'pageDown', '', icons.page_down],
|
|
1350
|
-
pageNavigator: ['se-component-enabled', '', 'pageNavigator', 'input', '']
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
/**
|
|
1355
|
-
* @private
|
|
1356
|
-
* @description Create a group div containing each module
|
|
1357
|
-
* @returns {{div: Element, ul: Element}}
|
|
1358
|
-
*/
|
|
1359
|
-
function _createModuleGroup() {
|
|
1360
|
-
const oUl = dom.utils.createElement('UL', { class: 'se-menu-list' });
|
|
1361
|
-
const oDiv = dom.utils.createElement('DIV', { class: 'se-btn-module se-btn-module-border' }, oUl);
|
|
1362
|
-
|
|
1363
|
-
return {
|
|
1364
|
-
div: oDiv,
|
|
1365
|
-
ul: oUl
|
|
1366
|
-
};
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
/**
|
|
1370
|
-
* @private
|
|
1371
|
-
* @description Create a button element
|
|
1372
|
-
* @param {string} className className in button
|
|
1373
|
-
* @param {string} title Title in button
|
|
1374
|
-
* @param {string} dataCommand The data-command property of the button
|
|
1375
|
-
* @param {"command"|"dropdown"|"field"|"browser"|"input"|"modal"|"popup"} dataType The data-type property of the button
|
|
1376
|
-
* @param {string} innerHTML Html in button
|
|
1377
|
-
* @param {string} _disabled Button disabled
|
|
1378
|
-
* @param {Object<string, string>} icons Icons
|
|
1379
|
-
* @returns {{li: HTMLElement, button: HTMLElement}}
|
|
1380
|
-
*/
|
|
1381
|
-
function _createButton(className, title, dataCommand, dataType, innerHTML, _disabled, icons) {
|
|
1382
|
-
if (!innerHTML) innerHTML = '';
|
|
1383
|
-
|
|
1384
|
-
const oLi = dom.utils.createElement('LI');
|
|
1385
|
-
const label = title || '';
|
|
1386
|
-
const isDiv = /^INPUT|FIELD$/i.test(dataType);
|
|
1387
|
-
const oButton = /** @type {HTMLButtonElement} */ (
|
|
1388
|
-
'se-toolbar-separator-vertical' === className
|
|
1389
|
-
? dom.utils.createElement('DIV', { class: className, tabindex: '-1' }, null)
|
|
1390
|
-
: dom.utils.createElement(isDiv ? 'DIV' : 'BUTTON', {
|
|
1391
|
-
class: 'se-toolbar-btn se-btn se-tooltip' + (className ? ' ' + className : ''),
|
|
1392
|
-
'data-command': dataCommand,
|
|
1393
|
-
'data-type': dataType,
|
|
1394
|
-
'aria-label': label.replace(/<span .+<\/span>/, ''),
|
|
1395
|
-
tabindex: '-1'
|
|
1396
|
-
})
|
|
1397
|
-
);
|
|
1398
|
-
|
|
1399
|
-
if (!isDiv) {
|
|
1400
|
-
oButton.setAttribute('type', 'button');
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
if (/^default\./i.test(innerHTML)) {
|
|
1404
|
-
innerHTML = icons[innerHTML.replace(/^default\./i, '')];
|
|
1405
|
-
}
|
|
1406
|
-
if (/^text\./i.test(innerHTML)) {
|
|
1407
|
-
innerHTML = innerHTML.replace(/^text\./i, '');
|
|
1408
|
-
oButton.className += ' se-btn-more-text';
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
if (_disabled) oButton.disabled = true;
|
|
1412
|
-
|
|
1413
|
-
if (/^FIELD$/i.test(dataType)) dom.utils.addClass(oLi, 'se-toolbar-hidden-btn');
|
|
1414
|
-
|
|
1415
|
-
if (label) innerHTML += dom.utils.createTooltipInner(label);
|
|
1416
|
-
if (innerHTML) oButton.innerHTML = innerHTML;
|
|
1417
|
-
|
|
1418
|
-
oLi.appendChild(oButton);
|
|
1419
|
-
|
|
1420
|
-
return {
|
|
1421
|
-
li: oLi,
|
|
1422
|
-
button: oButton
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
/**
|
|
1427
|
-
* @description Update a button state, attributes, and icons
|
|
1428
|
-
* @param {HTMLElement|null} element Button element
|
|
1429
|
-
* @param {Object<string, *>} plugin Plugin
|
|
1430
|
-
* @param {Object<string, string>} icons Icons
|
|
1431
|
-
* @param {Object<string, string>} lang lang
|
|
1432
|
-
*/
|
|
1433
|
-
export function UpdateButton(element, plugin, icons, lang) {
|
|
1434
|
-
if (!element) return;
|
|
1435
|
-
|
|
1436
|
-
const noneInner = plugin.inner === false;
|
|
1437
|
-
|
|
1438
|
-
if (plugin.inner?.nodeType === 1) {
|
|
1439
|
-
element.appendChild(plugin.inner);
|
|
1440
|
-
} else {
|
|
1441
|
-
element.innerHTML = noneInner
|
|
1442
|
-
? ''
|
|
1443
|
-
: (plugin.inner || icons[plugin.icon] || plugin.icon || '<span class="se-icon-text">!</span>') + '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + (lang[plugin.title] || plugin.title) + '</span></span>';
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
element.setAttribute('aria-label', plugin.title);
|
|
1447
|
-
|
|
1448
|
-
if (plugin.type) {
|
|
1449
|
-
element.setAttribute('data-type', plugin.type);
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
if (plugin.className) {
|
|
1453
|
-
element.className += ' ' + plugin.className;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
// side, replace button
|
|
1457
|
-
if (plugin.afterItem) {
|
|
1458
|
-
dom.utils.addClass(plugin.afterItem, 'se-toolbar-btn');
|
|
1459
|
-
element.parentElement.appendChild(plugin.afterItem);
|
|
1460
|
-
|
|
1461
|
-
dom.utils.addClass(element, 'se-side-btn-a');
|
|
1462
|
-
dom.utils.addClass(plugin.afterItem, 'se-side-btn-after');
|
|
1463
|
-
}
|
|
1464
|
-
if (plugin.beforeItem) {
|
|
1465
|
-
dom.utils.addClass(plugin.beforeItem, 'se-toolbar-btn');
|
|
1466
|
-
element.parentElement.insertBefore(plugin.beforeItem, element);
|
|
1467
|
-
|
|
1468
|
-
if (plugin.afterItem) {
|
|
1469
|
-
dom.utils.addClass(element, 'se-side-btn');
|
|
1470
|
-
dom.utils.removeClass(element, 'se-side-btn-a');
|
|
1471
|
-
} else {
|
|
1472
|
-
dom.utils.addClass(element, 'se-side-btn-b');
|
|
1473
|
-
}
|
|
1474
|
-
dom.utils.addClass(plugin.beforeItem, 'se-side-btn-before');
|
|
1475
|
-
}
|
|
1476
|
-
if (plugin.replaceButton) {
|
|
1477
|
-
element.parentElement.appendChild(plugin.replaceButton);
|
|
1478
|
-
element.style.display = 'none';
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
if (!plugin.replaceButton && /^INPUT$/i.test(element.getAttribute('data-type'))) {
|
|
1482
|
-
const inputTarget = element.querySelector('input');
|
|
1483
|
-
if (inputTarget) {
|
|
1484
|
-
dom.utils.addClass(inputTarget, 'se-toolbar-btn');
|
|
1485
|
-
inputTarget.setAttribute('data-command', element.getAttribute('data-command'));
|
|
1486
|
-
inputTarget.setAttribute('data-type', element.getAttribute('data-type'));
|
|
1487
|
-
if (element.hasAttribute('disabled')) inputTarget.disabled = true;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
/**
|
|
1493
|
-
* @description Create editor HTML
|
|
1494
|
-
* @param {Array} buttonList option.buttonList
|
|
1495
|
-
* @param {?Object<string, *>} plugins Plugins
|
|
1496
|
-
* @param {Map<string, *>} options options
|
|
1497
|
-
* @param {Object<string, string>} icons icons
|
|
1498
|
-
* @param {Object<string, string>} lang lang
|
|
1499
|
-
* @param {boolean} isUpdate Is update
|
|
1500
|
-
* @returns {{element: HTMLElement, pluginCallButtons: Object<string, Array<HTMLElement>>, responsiveButtons: Array<HTMLElement>, buttonTray: HTMLElement, updateButtons: Array<{button: HTMLElement, plugin: *, key: string}>}}}
|
|
1501
|
-
*/
|
|
1502
|
-
export function CreateToolBar(buttonList, plugins, options, icons, lang, isUpdate) {
|
|
1503
|
-
/** create button list */
|
|
1504
|
-
buttonList = JSON.parse(JSON.stringify(buttonList));
|
|
1505
|
-
const defaultButtonList = _defaultButtons(options, icons, lang);
|
|
1506
|
-
/** @type {Object<string, Array<HTMLElement>>} */
|
|
1507
|
-
const pluginCallButtons = {};
|
|
1508
|
-
const responsiveButtons = [];
|
|
1509
|
-
const updateButtons = [];
|
|
1510
|
-
|
|
1511
|
-
let modules = null;
|
|
1512
|
-
let button = null;
|
|
1513
|
-
let plugin = null;
|
|
1514
|
-
let moduleElement = null;
|
|
1515
|
-
let buttonElement = null;
|
|
1516
|
-
// let vertical = false;
|
|
1517
|
-
const moreLayer = dom.utils.createElement('DIV', { class: 'se-toolbar-more-layer' });
|
|
1518
|
-
const buttonTray = dom.utils.createElement('DIV', { class: 'se-btn-tray' });
|
|
1519
|
-
const separator_vertical = dom.utils.createElement('DIV', { class: 'se-toolbar-separator-vertical' });
|
|
1520
|
-
|
|
1521
|
-
buttonGroupLoop: for (let i = 0, more, moreContainer, moreCommand, buttonGroup, align; i < buttonList.length; i++) {
|
|
1522
|
-
more = false;
|
|
1523
|
-
align = '';
|
|
1524
|
-
buttonGroup = buttonList[i];
|
|
1525
|
-
moduleElement = _createModuleGroup();
|
|
1526
|
-
|
|
1527
|
-
// button object
|
|
1528
|
-
if (typeof buttonGroup === 'object') {
|
|
1529
|
-
// buttons loop
|
|
1530
|
-
for (let j = 0, moreButton; j < buttonGroup.length; j++) {
|
|
1531
|
-
button = buttonGroup[j];
|
|
1532
|
-
moreButton = false;
|
|
1533
|
-
plugin = plugins[button];
|
|
1534
|
-
|
|
1535
|
-
if (/^%\d+/.test(button) && j === 0) {
|
|
1536
|
-
buttonGroup[0] = button.replace(/[^\d]/g, '');
|
|
1537
|
-
responsiveButtons.push(buttonGroup);
|
|
1538
|
-
buttonList.splice(i--, 1);
|
|
1539
|
-
continue buttonGroupLoop;
|
|
1540
|
-
}
|
|
1541
|
-
if (typeof plugin === 'function') {
|
|
1542
|
-
modules = [plugin.className, plugin.title, button, plugin.type, plugin.innerHTML, plugin._disabled];
|
|
1543
|
-
} else if (typeof plugin === 'object') {
|
|
1544
|
-
const originFnc = plugin.constructor;
|
|
1545
|
-
modules = [plugin.className || originFnc.className, plugin.title || originFnc.title, button, plugin.type || originFnc.type, plugin.innerHTML || originFnc.innerHTML, plugin._disabled || originFnc._disabled];
|
|
1546
|
-
} else {
|
|
1547
|
-
// align
|
|
1548
|
-
if (/^-/.test(button)) {
|
|
1549
|
-
align = button.substring(1);
|
|
1550
|
-
moduleElement.div.className += ' module-float-' + align;
|
|
1551
|
-
continue;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
// rtl fix
|
|
1555
|
-
if (/^#/.test(button)) {
|
|
1556
|
-
const option = button.substring(1);
|
|
1557
|
-
if (option === 'fix') moduleElement.ul.className += ' se-menu-dir-fix';
|
|
1558
|
-
continue;
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
// more button
|
|
1562
|
-
if (/^:/.test(button)) {
|
|
1563
|
-
moreButton = true;
|
|
1564
|
-
const matched = button.match(/^:([^-]+)-([^-]+)/);
|
|
1565
|
-
moreCommand = '__se__more_' + i;
|
|
1566
|
-
const title = matched[1].trim();
|
|
1567
|
-
const innerHTML = matched[2].trim();
|
|
1568
|
-
modules = ['se-btn-more', /^lang\./i.test(title) ? lang[title.replace(/^lang\./i, '')] : title, moreCommand, 'MORE', innerHTML];
|
|
1569
|
-
} else if (button === '|') {
|
|
1570
|
-
// separator vertical
|
|
1571
|
-
modules = ['se-toolbar-separator-vertical', '', '', 'separator', ''];
|
|
1572
|
-
} else {
|
|
1573
|
-
// default command
|
|
1574
|
-
if (button === 'copy' && !env.isClipboardSupported) {
|
|
1575
|
-
console.warn('[SUNEDITOR.constructor.warn] Clipboard is not supported in this browser. : [copy] button is not rendered.');
|
|
1576
|
-
continue;
|
|
1577
|
-
}
|
|
1578
|
-
modules = defaultButtonList[button];
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
if (!modules) {
|
|
1582
|
-
if (!plugin) throw Error(`[SUNEDITOR.create.toolbar.fail] The button name of a plugin that does not exist. [${button}]`);
|
|
1583
|
-
plugin = typeof plugin === 'object' ? plugin.constructor : plugin;
|
|
1584
|
-
modules = [plugin.className, plugin.title, plugin.key, plugin.type, plugin.innerHTML, plugin._disabled];
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
buttonElement = _createButton(modules[0], modules[1], modules[2], modules[3], modules[4], modules[5], icons);
|
|
1589
|
-
(more ? moreContainer : moduleElement.ul).appendChild(buttonElement.li);
|
|
1590
|
-
|
|
1591
|
-
if (plugin) {
|
|
1592
|
-
if (pluginCallButtons[button]) {
|
|
1593
|
-
pluginCallButtons[button].push(buttonElement.button);
|
|
1594
|
-
} else {
|
|
1595
|
-
pluginCallButtons[button] = [buttonElement.button];
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
if (isUpdate) {
|
|
1599
|
-
updateButtons.push({ button: buttonElement.button, plugin, key: button });
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
// more button
|
|
1604
|
-
if (moreButton) {
|
|
1605
|
-
more = true;
|
|
1606
|
-
moreContainer = dom.utils.createElement('DIV');
|
|
1607
|
-
moreContainer.className = 'se-more-layer ' + moreCommand;
|
|
1608
|
-
moreContainer.setAttribute('data-ref', moreCommand);
|
|
1609
|
-
moreContainer.innerHTML = '<div class="se-more-form"><ul class="se-menu-list"' + (align ? ' style="float: ' + align + ';"' : '') + '></ul></div>';
|
|
1610
|
-
moreLayer.appendChild(moreContainer);
|
|
1611
|
-
moreContainer = moreContainer.firstElementChild.firstElementChild;
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
// if (vertical) {
|
|
1616
|
-
// const sv = separator_vertical.cloneNode(false);
|
|
1617
|
-
// buttonTray.appendChild(sv);
|
|
1618
|
-
// }
|
|
1619
|
-
|
|
1620
|
-
buttonTray.appendChild(moduleElement.div);
|
|
1621
|
-
// vertical = true;
|
|
1622
|
-
} else if (buttonGroup === '|') {
|
|
1623
|
-
// // separator vertical
|
|
1624
|
-
const sv = separator_vertical.cloneNode(false);
|
|
1625
|
-
buttonTray.appendChild(sv);
|
|
1626
|
-
continue;
|
|
1627
|
-
} else if (/^\/$/.test(buttonGroup)) {
|
|
1628
|
-
/** line break */
|
|
1629
|
-
const enterDiv = dom.utils.createElement('DIV', { class: 'se-btn-module-enter' });
|
|
1630
|
-
buttonTray.appendChild(enterDiv);
|
|
1631
|
-
// vertical = false;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
switch (buttonTray.children.length) {
|
|
1636
|
-
case 0:
|
|
1637
|
-
buttonTray.style.display = 'none';
|
|
1638
|
-
break;
|
|
1639
|
-
case 1:
|
|
1640
|
-
dom.utils.removeClass(buttonTray.firstElementChild, 'se-btn-module-border');
|
|
1641
|
-
break;
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
if (moreLayer.children.length > 0) buttonTray.appendChild(moreLayer);
|
|
1645
|
-
if (responsiveButtons.length > 0) responsiveButtons.unshift(buttonList);
|
|
1646
|
-
|
|
1647
|
-
// rendering toolbar
|
|
1648
|
-
const tool_bar = dom.utils.createElement('DIV', { class: 'se-toolbar sun-editor-common' + (!options.get('shortcutsHint') ? ' se-shortcut-hide' : '') }, buttonTray);
|
|
1649
|
-
|
|
1650
|
-
if (options.get('toolbar_hide')) tool_bar.style.display = 'none';
|
|
1651
|
-
|
|
1652
|
-
return {
|
|
1653
|
-
element: tool_bar,
|
|
1654
|
-
pluginCallButtons,
|
|
1655
|
-
responsiveButtons,
|
|
1656
|
-
buttonTray,
|
|
1657
|
-
updateButtons
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
export default Constructor;
|
|
1
|
+
import _icons from '../../assets/icons/defaultIcons';
|
|
2
|
+
import _defaultLang from '../../langs/en';
|
|
3
|
+
import { CreateContext, CreateFrameContext } from './context';
|
|
4
|
+
import { dom, numbers, converter, env } from '../../helper';
|
|
5
|
+
import { DEFAULTS } from './options';
|
|
6
|
+
|
|
7
|
+
const _d = env._d;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('./options').EditorFrameOptions} EditorFrameOptions
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('./options').EditorInitOptions} EditorInitOptions
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description Creates a new SunEditor instance with specified options.
|
|
19
|
+
* @param {Array<{target: Element, key: *, options: EditorFrameOptions}>} editorTargets - Target element or multi-root object.
|
|
20
|
+
* @param {EditorInitOptions} options - Configuration options for the editor.
|
|
21
|
+
* @returns {Object<string, *>} - SunEditor instance with context, options, and DOM elements.
|
|
22
|
+
*/
|
|
23
|
+
function Constructor(editorTargets, options) {
|
|
24
|
+
if (typeof options !== 'object') options = {};
|
|
25
|
+
|
|
26
|
+
/** --- Plugins ------------------------------------------------------------------------------------------ */
|
|
27
|
+
const plugins = {};
|
|
28
|
+
if (options.plugins) {
|
|
29
|
+
const excludedPlugins = options.excludedPlugins || [];
|
|
30
|
+
const originPlugins = options.plugins;
|
|
31
|
+
const pluginsValues = (Array.isArray(originPlugins) ? originPlugins : Object.keys(originPlugins)).filter((name) => !excludedPlugins.includes(name)).map((name) => originPlugins[name]);
|
|
32
|
+
|
|
33
|
+
for (let i = 0, len = pluginsValues.length, p; i < len; i++) {
|
|
34
|
+
p = pluginsValues[i].default || pluginsValues[i];
|
|
35
|
+
plugins[p.key] = p;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** --- options --------------------------------------------------------------- */
|
|
40
|
+
const optionMap = InitOptions(options, editorTargets, plugins);
|
|
41
|
+
const o = optionMap.o;
|
|
42
|
+
const icons = optionMap.i;
|
|
43
|
+
const lang = optionMap.l;
|
|
44
|
+
const loadingBox = dom.utils.createElement('DIV', { class: 'se-loading-box sun-editor-common' }, '<div class="se-loading-effect"></div>');
|
|
45
|
+
|
|
46
|
+
/** --- carrier wrapper --------------------------------------------------------------- */
|
|
47
|
+
const editor_carrier_wrapper = dom.utils.createElement('DIV', { class: 'sun-editor sun-editor-carrier-wrapper sun-editor-common' + o.get('_themeClass') + (o.get('_rtl') ? ' se-rtl' : '') });
|
|
48
|
+
// menuTray
|
|
49
|
+
const menuTray = dom.utils.createElement('DIV', { class: 'se-menu-tray' });
|
|
50
|
+
editor_carrier_wrapper.appendChild(menuTray);
|
|
51
|
+
// focus temp element
|
|
52
|
+
const focusTemp = /** @type {HTMLInputElement} */ (
|
|
53
|
+
dom.utils.createElement('INPUT', {
|
|
54
|
+
class: '__se__focus__temp__',
|
|
55
|
+
style: 'position: fixed !important; top: -10000px !important; left: -10000px !important; display: block !important; width: 0 !important; height: 0 !important; margin: 0 !important; padding: 0 !important;'
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
focusTemp.tabIndex = 0;
|
|
59
|
+
editor_carrier_wrapper.appendChild(focusTemp);
|
|
60
|
+
|
|
61
|
+
// modal
|
|
62
|
+
const modal = dom.utils.createElement('DIV', { class: 'se-modal se-modal-area sun-editor-common' });
|
|
63
|
+
const modal_back = dom.utils.createElement('DIV', { class: 'se-modal-back' });
|
|
64
|
+
const modal_inner = dom.utils.createElement('DIV', { class: 'se-modal-inner' });
|
|
65
|
+
modal.appendChild(modal_back);
|
|
66
|
+
modal.appendChild(modal_inner);
|
|
67
|
+
editor_carrier_wrapper.appendChild(modal);
|
|
68
|
+
|
|
69
|
+
// alert
|
|
70
|
+
const alert = dom.utils.createElement('DIV', { class: 'se-alert se-modal-area sun-editor-common', style: 'display: none;' });
|
|
71
|
+
const alert_back = dom.utils.createElement('DIV', { class: 'se-modal-back' });
|
|
72
|
+
const alert_inner = dom.utils.createElement('DIV', { class: 'se-modal-inner' });
|
|
73
|
+
alert.appendChild(alert_back);
|
|
74
|
+
alert.appendChild(alert_inner);
|
|
75
|
+
editor_carrier_wrapper.appendChild(alert);
|
|
76
|
+
|
|
77
|
+
// loding box, resizing back
|
|
78
|
+
editor_carrier_wrapper.appendChild(dom.utils.createElement('DIV', { class: 'se-back-wrapper' }));
|
|
79
|
+
editor_carrier_wrapper.appendChild(loadingBox.cloneNode(true));
|
|
80
|
+
|
|
81
|
+
// drag cursor
|
|
82
|
+
const dragCursor = dom.utils.createElement('DIV', { class: 'se-drag-cursor' });
|
|
83
|
+
editor_carrier_wrapper.appendChild(dragCursor);
|
|
84
|
+
|
|
85
|
+
// set carrier wrapper
|
|
86
|
+
_d.body.appendChild(editor_carrier_wrapper);
|
|
87
|
+
|
|
88
|
+
/** --- toolbar --------------------------------------------------------------- */
|
|
89
|
+
let subbar = null,
|
|
90
|
+
sub_main = null;
|
|
91
|
+
const tool_bar_main = CreateToolBar(optionMap.buttons, plugins, o, icons, lang, false);
|
|
92
|
+
const toolbar = tool_bar_main.element;
|
|
93
|
+
toolbar.style.visibility = 'hidden';
|
|
94
|
+
// toolbar mode
|
|
95
|
+
if (/inline/i.test(o.get('mode'))) {
|
|
96
|
+
toolbar.className += ' se-toolbar-inline';
|
|
97
|
+
toolbar.style.width = o.get('toolbar_width');
|
|
98
|
+
} else if (/balloon/i.test(o.get('mode'))) {
|
|
99
|
+
toolbar.className += ' se-toolbar-balloon';
|
|
100
|
+
toolbar.style.width = o.get('toolbar_width');
|
|
101
|
+
toolbar.appendChild(dom.utils.createElement('DIV', { class: 'se-arrow' }));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** --- subToolbar --------------------------------------------------------------- */
|
|
105
|
+
if (optionMap.subButtons) {
|
|
106
|
+
sub_main = CreateToolBar(optionMap.subButtons, plugins, o, icons, lang, false);
|
|
107
|
+
subbar = sub_main.element;
|
|
108
|
+
subbar.style.visibility = 'hidden';
|
|
109
|
+
// subbar mode must be balloon-*
|
|
110
|
+
subbar.className += ' se-toolbar-balloon se-toolbar-sub';
|
|
111
|
+
subbar.style.width = o.get('toolbar.sub_width');
|
|
112
|
+
subbar.appendChild(dom.utils.createElement('DIV', { class: 'se-arrow' }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** frame - root set - start -------------------------------------------------------------- */
|
|
116
|
+
const rootId = editorTargets[0].key || null;
|
|
117
|
+
const rootKeys = [];
|
|
118
|
+
const frameRoots = new Map();
|
|
119
|
+
const statusbarContainer = optionMap.statusbarContainer;
|
|
120
|
+
let default_status_bar = null;
|
|
121
|
+
for (let i = 0, len = editorTargets.length; i < len; i++) {
|
|
122
|
+
const editTarget = editorTargets[i];
|
|
123
|
+
const to = optionMap.frameMap.get(editTarget.key);
|
|
124
|
+
const top_div = dom.utils.createElement('DIV', { class: 'sun-editor' + o.get('_themeClass') + (o.get('_rtl') ? ' se-rtl' : '') });
|
|
125
|
+
const container = dom.utils.createElement('DIV', { class: 'se-container' });
|
|
126
|
+
const editor_div = dom.utils.createElement('DIV', { class: 'se-wrapper' + (o.get('type') === 'document' ? ' se-type-document' : '') + (o.get('_type_options').includes('header') ? ' se-type-document-header' : '') });
|
|
127
|
+
|
|
128
|
+
container.appendChild(dom.utils.createElement('DIV', { class: 'se-toolbar-shadow' }));
|
|
129
|
+
|
|
130
|
+
// init element
|
|
131
|
+
const initElements = _initTargetElements(editTarget.key, o, top_div, to);
|
|
132
|
+
const bottomBar = initElements.bottomBar;
|
|
133
|
+
const statusbar = bottomBar.statusbar;
|
|
134
|
+
const wysiwyg_div = initElements.wysiwygFrame;
|
|
135
|
+
const placeholder_span = initElements.placeholder;
|
|
136
|
+
let textarea = initElements.codeView;
|
|
137
|
+
|
|
138
|
+
// line breaker
|
|
139
|
+
const line_breaker_t = dom.utils.createElement('DIV', { class: 'se-line-breaker-component se-line-breaker-component-t', title: lang.insertLine }, icons.line_break);
|
|
140
|
+
const line_breaker_b = dom.utils.createElement('DIV', { class: 'se-line-breaker-component se-line-breaker-component-b', title: lang.insertLine }, icons.line_break);
|
|
141
|
+
|
|
142
|
+
editor_div.appendChild(line_breaker_t);
|
|
143
|
+
editor_div.appendChild(line_breaker_b);
|
|
144
|
+
|
|
145
|
+
// append container
|
|
146
|
+
if (placeholder_span) editor_div.appendChild(placeholder_span);
|
|
147
|
+
container.appendChild(dom.utils.createElement('DIV', { class: 'se-toolbar-sticky-dummy' }));
|
|
148
|
+
container.appendChild(editor_div);
|
|
149
|
+
|
|
150
|
+
// statusbar
|
|
151
|
+
if (statusbar) {
|
|
152
|
+
if (statusbarContainer) {
|
|
153
|
+
if (!default_status_bar) {
|
|
154
|
+
statusbarContainer.appendChild(dom.utils.createElement('DIV', { class: 'sun-editor' + o.get('_themeClass') }, statusbar));
|
|
155
|
+
default_status_bar = statusbar;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
container.appendChild(statusbar);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// loading bar
|
|
163
|
+
container.appendChild(loadingBox.cloneNode(true));
|
|
164
|
+
|
|
165
|
+
// root key
|
|
166
|
+
const key = editTarget.key || null;
|
|
167
|
+
|
|
168
|
+
// code view - wrapper
|
|
169
|
+
const codeWrapper = dom.utils.createElement('DIV', { class: 'se-code-wrapper' }, textarea);
|
|
170
|
+
codeWrapper.style.setProperty('display', 'none', 'important');
|
|
171
|
+
editor_div.appendChild(codeWrapper);
|
|
172
|
+
|
|
173
|
+
// check code mirror
|
|
174
|
+
const codeMirrorEl = _checkCodeMirror(o, to, textarea);
|
|
175
|
+
// not used code mirror
|
|
176
|
+
if (textarea === codeMirrorEl) {
|
|
177
|
+
// add line nubers
|
|
178
|
+
const codeNumbers = dom.utils.createElement('TEXTAREA', { class: 'se-code-view-line', readonly: 'true' }, null);
|
|
179
|
+
codeWrapper.insertBefore(codeNumbers, textarea);
|
|
180
|
+
} else {
|
|
181
|
+
textarea = codeMirrorEl;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// document type
|
|
185
|
+
const documentTypeInner = { inner: null, page: null, pageMirror: null };
|
|
186
|
+
if (o.get('_type_options').includes('header')) {
|
|
187
|
+
documentTypeInner.inner = dom.utils.createElement('DIV', { class: 'se-document-lines', style: `height: ${to.get('height')};` }, '<div class="se-document-lines-inner"></div>');
|
|
188
|
+
}
|
|
189
|
+
if (o.get('_type_options').includes('page')) {
|
|
190
|
+
documentTypeInner.page = dom.utils.createElement('DIV', { class: 'se-document-page' }, null);
|
|
191
|
+
documentTypeInner.pageMirror = dom.utils.createElement(
|
|
192
|
+
'DIV',
|
|
193
|
+
{
|
|
194
|
+
class: 'sun-editor-editable se-document-page-mirror-a4',
|
|
195
|
+
style: `position: absolute; width: 21cm; columns: 21cm; border: 0; overflow: hidden; height: auto; top: -10000px; left: -10000px;`
|
|
196
|
+
},
|
|
197
|
+
null
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// set container
|
|
202
|
+
top_div.appendChild(container);
|
|
203
|
+
rootKeys.push(key);
|
|
204
|
+
frameRoots.set(key, CreateFrameContext({ target: editTarget.target, key: editTarget.key, options: to }, top_div, wysiwyg_div, codeWrapper, textarea, default_status_bar || statusbar, documentTypeInner, key));
|
|
205
|
+
}
|
|
206
|
+
/** frame - root set - end -------------------------------------------------------------- */
|
|
207
|
+
|
|
208
|
+
// toolbar container
|
|
209
|
+
const toolbar_container = o.get('toolbar_container');
|
|
210
|
+
if (toolbar_container) {
|
|
211
|
+
const top_div = dom.utils.createElement('DIV', { class: 'sun-editor' + o.get('_themeClass') + (o.get('_rtl') ? ' se-rtl' : '') });
|
|
212
|
+
const container = dom.utils.createElement('DIV', { class: 'se-container' });
|
|
213
|
+
container.appendChild(toolbar);
|
|
214
|
+
if (subbar) container.appendChild(subbar);
|
|
215
|
+
top_div.appendChild(container);
|
|
216
|
+
toolbar_container.appendChild(top_div);
|
|
217
|
+
toolbar_container.appendChild(dom.utils.createElement('DIV', { class: 'se-toolbar-sticky-dummy' }));
|
|
218
|
+
} else {
|
|
219
|
+
const rootContainer = frameRoots.get(rootId).get('container');
|
|
220
|
+
rootContainer.insertBefore(toolbar, rootContainer.firstElementChild);
|
|
221
|
+
if (subbar) rootContainer.insertBefore(subbar, rootContainer.firstElementChild);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
context: CreateContext(toolbar, toolbar_container, menuTray, subbar, statusbarContainer),
|
|
226
|
+
carrierWrapper: editor_carrier_wrapper,
|
|
227
|
+
options: o,
|
|
228
|
+
plugins: plugins,
|
|
229
|
+
icons: icons,
|
|
230
|
+
lang: lang,
|
|
231
|
+
value: optionMap.v,
|
|
232
|
+
rootId: rootId,
|
|
233
|
+
rootKeys: rootKeys,
|
|
234
|
+
frameRoots: frameRoots,
|
|
235
|
+
pluginCallButtons: tool_bar_main.pluginCallButtons,
|
|
236
|
+
responsiveButtons: tool_bar_main.responsiveButtons,
|
|
237
|
+
pluginCallButtons_sub: sub_main ? sub_main.pluginCallButtons : [],
|
|
238
|
+
responsiveButtons_sub: sub_main ? sub_main.responsiveButtons : []
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @description Create shortcuts desc span.
|
|
244
|
+
* @param {string} command Command string
|
|
245
|
+
* @param {Array<string>} values options.shortcuts[command]
|
|
246
|
+
* @param {Element|null} button Command button element
|
|
247
|
+
* @param {Map<string, *>} keyMap Map to store shortcut key info
|
|
248
|
+
* @param {Array} rc "_reverseCommandArray" option
|
|
249
|
+
* @param {Array} reverseKeys Reverse key array
|
|
250
|
+
*/
|
|
251
|
+
export function CreateShortcuts(command, button, values, keyMap, rc, reverseKeys) {
|
|
252
|
+
if (!values || values.length < 2) return;
|
|
253
|
+
const tooptip = button?.querySelector('.se-tooltip-text');
|
|
254
|
+
|
|
255
|
+
for (let i = 0, a, v, c, s, edge, space, enter, textTrigger, plugin, method, t, k, r, _i; i < values.length; i += 2 + _i) {
|
|
256
|
+
_i = 0;
|
|
257
|
+
a = values[i].split('+');
|
|
258
|
+
|
|
259
|
+
plugin = null;
|
|
260
|
+
method = a[a.length - 1].trim?.();
|
|
261
|
+
if (method.startsWith('~')) {
|
|
262
|
+
// plugin key, method
|
|
263
|
+
plugin = command;
|
|
264
|
+
method = a.pop().trim().substring(1);
|
|
265
|
+
} else if (method.startsWith('$~')) {
|
|
266
|
+
// custom key, plugin method
|
|
267
|
+
const a_ = a.pop().trim().substring(2).split('.');
|
|
268
|
+
plugin = a_[0];
|
|
269
|
+
method = a_[1];
|
|
270
|
+
} else if (method.startsWith('$')) {
|
|
271
|
+
// directly method
|
|
272
|
+
_i = 1;
|
|
273
|
+
method = values[i + 2];
|
|
274
|
+
} else {
|
|
275
|
+
method = '';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
c = s = edge = space = enter = textTrigger = v = null;
|
|
279
|
+
for (const a_ of a) {
|
|
280
|
+
switch (a_.trim()) {
|
|
281
|
+
case 'c':
|
|
282
|
+
c = true;
|
|
283
|
+
break;
|
|
284
|
+
case '!':
|
|
285
|
+
edge = true;
|
|
286
|
+
break;
|
|
287
|
+
case 's':
|
|
288
|
+
s = true;
|
|
289
|
+
break;
|
|
290
|
+
case '_':
|
|
291
|
+
space = true;
|
|
292
|
+
break;
|
|
293
|
+
case '=':
|
|
294
|
+
textTrigger = true;
|
|
295
|
+
break;
|
|
296
|
+
case '/':
|
|
297
|
+
enter = true;
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
v = a_;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
v = v.split('|');
|
|
305
|
+
for (let j = 0, len = v.length; j < len; j++) {
|
|
306
|
+
k = c ? v[j] + (s ? '1000' : '') : v[j];
|
|
307
|
+
if (!keyMap.has(k)) {
|
|
308
|
+
r = rc.indexOf(command);
|
|
309
|
+
r = r === -1 ? '' : numbers.isOdd(r) ? rc[r + 1] : rc[r - 1];
|
|
310
|
+
if (r) reverseKeys.push(k);
|
|
311
|
+
|
|
312
|
+
keyMap.set(k, { c, s, edge, space, enter, textTrigger, plugin, command, method, r, type: button?.getAttribute('data-type'), button, key: k });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (!(t = values[i + 1])) continue;
|
|
317
|
+
if (tooptip) _addTooltip(tooptip, s, t);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function _addTooltip(tooptipBtn, shift, shortcut) {
|
|
322
|
+
tooptipBtn.appendChild(dom.utils.createElement('SPAN', { class: 'se-shortcut' }, env.cmdIcon + (shift ? env.shiftIcon : '') + '+<span class="se-shortcut-key">' + shortcut + '</span>'));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* @private
|
|
327
|
+
* @description Returns a new object with merge "a" and "b"
|
|
328
|
+
* @param {Object<*, *>} a object
|
|
329
|
+
* @param {Object<*, *>} b object
|
|
330
|
+
* @returns {Object<*, *>} new object
|
|
331
|
+
*/
|
|
332
|
+
function _mergeObject(a, b) {
|
|
333
|
+
return [a, b].reduce((_default, _new) => {
|
|
334
|
+
for (const key in _new) {
|
|
335
|
+
_default[key] = (_new[key] || '').toLowerCase();
|
|
336
|
+
}
|
|
337
|
+
return _default;
|
|
338
|
+
}, {});
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @description Initialize options
|
|
343
|
+
* @param {EditorInitOptions} options Configuration options for the editor.
|
|
344
|
+
* @param {Array<{target: Element, key: *, options: EditorFrameOptions}>} editorTargets Target textarea
|
|
345
|
+
* @param {Object<string, *>} plugins Plugins object
|
|
346
|
+
* @returns {{o: Map<string, *>, i: Object<string, string>, l: Object<string, string>, v: string, buttons: Array<string[]|string>, subButtons: Array<string[]|string>, statusbarContainer: Element|null, frameMap: Map<*, *>}}
|
|
347
|
+
* - o: options
|
|
348
|
+
* - i: icons
|
|
349
|
+
* - l: lang
|
|
350
|
+
* - v: value
|
|
351
|
+
* - buttons: Toolbar button list
|
|
352
|
+
* - subButtons: Sub-Toolbar button list
|
|
353
|
+
* - statusbarContainer: statusbar container
|
|
354
|
+
* - frameMap: converted options map
|
|
355
|
+
*/
|
|
356
|
+
export function InitOptions(options, editorTargets, plugins) {
|
|
357
|
+
const buttonList = options.buttonList || DEFAULTS.BUTTON_LIST;
|
|
358
|
+
const o = new Map();
|
|
359
|
+
|
|
360
|
+
/** Multi root */
|
|
361
|
+
if (editorTargets.length > 1) {
|
|
362
|
+
if (!options.toolbar_container && !/inline|balloon/i.test(options.mode)) throw Error('[SUNEDITOR.create.fail] In multi root, The "mode" option cannot be "classic" without using the "toolbar_container" option.');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// migration data-.+
|
|
366
|
+
o.set('v2Migration', !!options.v2Migration);
|
|
367
|
+
|
|
368
|
+
/** Base */
|
|
369
|
+
o.set('buttons', new Set(buttonList.toString().split(',')));
|
|
370
|
+
const modeValue = options.strictMode !== false;
|
|
371
|
+
o.set('strictMode', {
|
|
372
|
+
tagFilter: modeValue,
|
|
373
|
+
formatFilter: modeValue,
|
|
374
|
+
classFilter: modeValue,
|
|
375
|
+
textStyleTagFilter: modeValue,
|
|
376
|
+
attrFilter: modeValue,
|
|
377
|
+
styleFilter: modeValue,
|
|
378
|
+
...(typeof options.strictMode === 'boolean' ? {} : options.strictMode)
|
|
379
|
+
});
|
|
380
|
+
o.set('freeCodeViewMode', !!options.freeCodeViewMode);
|
|
381
|
+
o.set('__lineFormatFilter', options.__lineFormatFilter ?? true);
|
|
382
|
+
o.set('__pluginRetainFilter', options.__pluginRetainFilter ?? true);
|
|
383
|
+
o.set('mode', options.mode || 'classic'); // classic, inline, balloon, balloon-always
|
|
384
|
+
o.set('type', options.type?.split(':')[0] || ''); // document:header,page
|
|
385
|
+
o.set('theme', options.theme || '');
|
|
386
|
+
o.set('_themeClass', options.theme ? ` se-theme-${options.theme}` : '');
|
|
387
|
+
o.set('_type_options', options.type?.split(':')[1] || '');
|
|
388
|
+
o.set('externalLibs', options.externalLibs || {});
|
|
389
|
+
o.set('fontSizeUnits', Array.isArray(options.fontSizeUnits) && options.fontSizeUnits.length > 0 ? options.fontSizeUnits.map((v) => v.toLowerCase()) : DEFAULTS.SIZE_UNITS);
|
|
390
|
+
o.set('allowedClassName', new RegExp(`${options.allowedClassName && typeof options.allowedClassName === 'string' ? options.allowedClassName + '|' : ''}${DEFAULTS.CLASS_NAME}`));
|
|
391
|
+
o.set('closeModalOutsideClick', !!options.closeModalOutsideClick);
|
|
392
|
+
|
|
393
|
+
// format
|
|
394
|
+
o.set('copyFormatKeepOn', !!options.copyFormatKeepOn);
|
|
395
|
+
o.set('syncTabIndent', options.syncTabIndent ?? true);
|
|
396
|
+
|
|
397
|
+
// auto convert on paste
|
|
398
|
+
o.set('autoLinkify', options.autoLinkify ?? !!plugins.link);
|
|
399
|
+
o.set('autoStyleify', Array.isArray(options.autoStyleify) ? options.autoStyleify : ['bold', 'underline', 'italic', 'strike']);
|
|
400
|
+
|
|
401
|
+
let retainStyleMode = options.retainStyleMode;
|
|
402
|
+
if (typeof retainStyleMode === 'string' && !DEFAULTS.RETAIN_STYLE_MODE.includes(retainStyleMode)) {
|
|
403
|
+
console.error(`Invalid retainStyleMode: ${retainStyleMode}. Valid options are ${DEFAULTS.RETAIN_STYLE_MODE.join(', ')}. Using default 'once'.`);
|
|
404
|
+
retainStyleMode = 'repeat';
|
|
405
|
+
}
|
|
406
|
+
o.set('retainStyleMode', retainStyleMode);
|
|
407
|
+
|
|
408
|
+
const allowedExtraTags = { ...DEFAULTS.EXTRA_TAG_MAP, ...options.allowedExtraTags, '-': true };
|
|
409
|
+
const extraKeys = Object.keys(allowedExtraTags);
|
|
410
|
+
const allowedKeys = extraKeys.filter((k) => allowedExtraTags[k]).join('|');
|
|
411
|
+
const disallowedKeys = extraKeys.filter((k) => !allowedExtraTags[k]).join('|');
|
|
412
|
+
o.set('_allowedExtraTag', allowedKeys);
|
|
413
|
+
o.set('_disallowedExtraTag', disallowedKeys);
|
|
414
|
+
|
|
415
|
+
o.set('events', options.events || {});
|
|
416
|
+
|
|
417
|
+
// text style tags
|
|
418
|
+
o.set('textStyleTags', (typeof options.__textStyleTags === 'string' ? options.__textStyleTags : DEFAULTS.TEXT_STYLE_TAGS) + (options.textStyleTags ? '|' + options.textStyleTags : ''));
|
|
419
|
+
const textTags = _mergeObject(
|
|
420
|
+
{
|
|
421
|
+
bold: 'strong',
|
|
422
|
+
underline: 'u',
|
|
423
|
+
italic: 'em',
|
|
424
|
+
strike: 'del',
|
|
425
|
+
subscript: 'sub',
|
|
426
|
+
superscript: 'sup'
|
|
427
|
+
},
|
|
428
|
+
options.convertTextTags || {}
|
|
429
|
+
);
|
|
430
|
+
o.set('convertTextTags', textTags);
|
|
431
|
+
o.set('_textStyleTags', Object.values(textTags).concat(['span', 'li']));
|
|
432
|
+
o.set(
|
|
433
|
+
'tagStyles',
|
|
434
|
+
[{ ...DEFAULTS.TAG_STYLES, ...(options.__tagStyles || {}) }, options.tagStyles || {}].reduce((_default, _new) => {
|
|
435
|
+
for (const key in _new) {
|
|
436
|
+
_default[key] = _new[key];
|
|
437
|
+
}
|
|
438
|
+
return _default;
|
|
439
|
+
}, {})
|
|
440
|
+
);
|
|
441
|
+
o.set('_textStylesRegExp', new RegExp(`\\s*[^-a-zA-Z](${DEFAULTS.SPAN_STYLES}${options.spanStyles ? '|' + options.spanStyles : ''})\\s*:[^;]+(?!;)*`, 'gi'));
|
|
442
|
+
o.set('_lineStylesRegExp', new RegExp(`\\s*[^-a-zA-Z](${DEFAULTS.LINE_STYLES}${options.lineStyles ? '|' + options.lineStyles : ''})\\s*:[^;]+(?!;)*`, 'gi'));
|
|
443
|
+
o.set('_defaultStyleTagMap', {
|
|
444
|
+
strong: textTags.bold,
|
|
445
|
+
b: textTags.bold,
|
|
446
|
+
u: textTags.underline,
|
|
447
|
+
ins: textTags.underline,
|
|
448
|
+
em: textTags.italic,
|
|
449
|
+
i: textTags.italic,
|
|
450
|
+
del: textTags.strike,
|
|
451
|
+
strike: textTags.strike,
|
|
452
|
+
s: textTags.strike,
|
|
453
|
+
sub: textTags.subscript,
|
|
454
|
+
sup: textTags.superscript
|
|
455
|
+
});
|
|
456
|
+
o.set(
|
|
457
|
+
'_styleCommandMap',
|
|
458
|
+
_mergeObject(converter.swapKeyValue(textTags), {
|
|
459
|
+
strong: 'bold',
|
|
460
|
+
b: 'bold',
|
|
461
|
+
u: 'underline',
|
|
462
|
+
ins: 'underline',
|
|
463
|
+
em: 'italic',
|
|
464
|
+
i: 'italic',
|
|
465
|
+
del: 'strike',
|
|
466
|
+
strike: 'strike',
|
|
467
|
+
s: 'strike',
|
|
468
|
+
sub: 'subscript',
|
|
469
|
+
sup: 'superscript'
|
|
470
|
+
})
|
|
471
|
+
);
|
|
472
|
+
o.set('_defaultTagCommand', {
|
|
473
|
+
bold: textTags.bold,
|
|
474
|
+
underline: textTags.underline,
|
|
475
|
+
italic: textTags.italic,
|
|
476
|
+
strike: textTags.strike,
|
|
477
|
+
subscript: textTags.sub,
|
|
478
|
+
superscript: textTags.sup
|
|
479
|
+
});
|
|
480
|
+
// text direction
|
|
481
|
+
o.set('textDirection', typeof options.textDirection !== 'string' ? 'ltr' : options.textDirection);
|
|
482
|
+
o.set('_rtl', o.get('textDirection') === 'rtl');
|
|
483
|
+
// An array of key codes generated with the reverseButtons option, used to reverse the action for a specific key combination.
|
|
484
|
+
o.set('reverseCommands', ['indent-outdent'].concat(options.reverseButtons || []));
|
|
485
|
+
o.set('_reverseCommandArray', ('-' + o.get('reverseCommands').join('-')).split('-'));
|
|
486
|
+
if (numbers.isEven(o.get('_reverseCommandArray').length)) {
|
|
487
|
+
console.warn('[SUNEDITOR.create.warning] The "reverseCommands" option is invalid, Shortcuts key may not work properly.');
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// etc
|
|
491
|
+
o.set('historyStackDelayTime', typeof options.historyStackDelayTime === 'number' ? options.historyStackDelayTime : 400);
|
|
492
|
+
o.set('_editableClass', 'sun-editor-editable' + o.get('_themeClass') + (o.get('_rtl') ? ' se-rtl' : '') + (o.get('type') === 'document' ? ' se-type-document-editable-a4' : ''));
|
|
493
|
+
o.set('lineAttrReset', ['id'].concat(options.lineAttrReset && typeof options.lineAttrReset === 'string' ? options.lineAttrReset.toLowerCase().split('|') : []));
|
|
494
|
+
o.set('printClass', typeof options.printClass === 'string' ? options.printClass + ' ' + o.get('_editableClass') : null);
|
|
495
|
+
|
|
496
|
+
/** whitelist, blacklist */
|
|
497
|
+
// default line
|
|
498
|
+
o.set('defaultLine', typeof options.defaultLine === 'string' && options.defaultLine.length > 0 ? options.defaultLine : 'p');
|
|
499
|
+
o.set('defaultLineBreakFormat', options.defaultLineBreakFormat || 'line');
|
|
500
|
+
o.set('scopeSelectionTags', options.scopeSelectionTags || DEFAULTS.SCOPE_SELECTION_TAGS);
|
|
501
|
+
// element
|
|
502
|
+
const elw = (typeof options.elementWhitelist === 'string' ? options.elementWhitelist : '').toLowerCase();
|
|
503
|
+
const mjxEls = o.get('externalLibs').mathjax ? DEFAULTS.CLASS_MJX + '|' : '';
|
|
504
|
+
o.set('elementWhitelist', elw + (elw ? '|' : '') + mjxEls + o.get('_allowedExtraTag'));
|
|
505
|
+
const elb = _createBlacklist((typeof options.elementBlacklist === 'string' ? options.elementBlacklist : '').toLowerCase(), o.get('defaultLine'));
|
|
506
|
+
o.set('elementBlacklist', elb + (elb ? '|' : '') + o.get('_disallowedExtraTag'));
|
|
507
|
+
// attribute
|
|
508
|
+
o.set('attributeWhitelist', !options.attributeWhitelist || typeof options.attributeWhitelist !== 'object' ? null : options.attributeWhitelist);
|
|
509
|
+
o.set('attributeBlacklist', !options.attributeBlacklist || typeof options.attributeBlacklist !== 'object' ? null : options.attributeBlacklist);
|
|
510
|
+
// format tag
|
|
511
|
+
o.set(
|
|
512
|
+
'formatClosureBrLine',
|
|
513
|
+
_createFormatInfo(
|
|
514
|
+
options.formatClosureBrLine,
|
|
515
|
+
(options.__defaultFormatClosureBrLine = typeof options.__defaultFormatClosureBrLine === 'string' ? options.__defaultFormatClosureBrLine : DEFAULTS.FORMAT_CLOSURE_BR_LINE).toLowerCase(),
|
|
516
|
+
o.get('elementBlacklist')
|
|
517
|
+
)
|
|
518
|
+
);
|
|
519
|
+
o.set(
|
|
520
|
+
'formatBrLine',
|
|
521
|
+
_createFormatInfo(
|
|
522
|
+
(options.formatBrLine || '') + '|' + o.get('formatClosureBrLine').str,
|
|
523
|
+
(options.__defaultFormatBrLine = typeof options.__defaultFormatBrLine === 'string' ? options.__defaultFormatBrLine : DEFAULTS.FORMAT_BR_LINE).toLowerCase(),
|
|
524
|
+
o.get('elementBlacklist')
|
|
525
|
+
)
|
|
526
|
+
);
|
|
527
|
+
o.set(
|
|
528
|
+
'formatLine',
|
|
529
|
+
_createFormatInfo(
|
|
530
|
+
DEFAULTS.REQUIRED_FORMAT_LINE + '|' + (options.formatLine || '') + '|' + o.get('formatBrLine').str,
|
|
531
|
+
(options.__defaultFormatLine = typeof options.__defaultFormatLine === 'string' ? options.__defaultFormatLine : DEFAULTS.FORMAT_LINE).toLowerCase(),
|
|
532
|
+
o.get('elementBlacklist')
|
|
533
|
+
)
|
|
534
|
+
);
|
|
535
|
+
|
|
536
|
+
// Error - default line
|
|
537
|
+
if (!o.get('formatLine').reg.test(o.get('defaultLine'))) {
|
|
538
|
+
throw Error(`[SUNEDITOR.create.fail] The "defaultLine(${o.get('defaultLine')})" option must be included in the "formatLine(${o.get('formatLine').str})" option.`);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
o.set(
|
|
542
|
+
'formatClosureBlock',
|
|
543
|
+
_createFormatInfo(
|
|
544
|
+
options.formatClosureBlock,
|
|
545
|
+
(options.__defaultFormatClosureBlock = typeof options.__defaultFormatClosureBlock === 'string' ? options.__defaultFormatClosureBlock : DEFAULTS.FORMAT_CLOSURE_BLOCK).toLowerCase(),
|
|
546
|
+
o.get('elementBlacklist')
|
|
547
|
+
)
|
|
548
|
+
);
|
|
549
|
+
o.set(
|
|
550
|
+
'formatBlock',
|
|
551
|
+
_createFormatInfo(
|
|
552
|
+
(options.formatBlock || '') + '|' + o.get('formatClosureBlock').str,
|
|
553
|
+
(options.__defaultFormatBlock = typeof options.__defaultFormatBlock === 'string' ? options.__defaultFormatBlock : DEFAULTS.FORMAT_BLOCK).toLowerCase(),
|
|
554
|
+
o.get('elementBlacklist')
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
o.set('allowedEmptyTags', DEFAULTS.ALLOWED_EMPTY_NODE_LIST + (options.allowedEmptyTags ? ', ' + options.allowedEmptyTags : ''));
|
|
559
|
+
|
|
560
|
+
/** __defaults */
|
|
561
|
+
o.set('__defaultElementWhitelist', DEFAULTS.REQUIRED_ELEMENT_WHITELIST + '|' + (typeof options.__defaultElementWhitelist === 'string' ? options.__defaultElementWhitelist : DEFAULTS.ELEMENT_WHITELIST).toLowerCase());
|
|
562
|
+
o.set('__defaultAttributeWhitelist', (typeof options.__defaultAttributeWhitelist === 'string' ? options.__defaultAttributeWhitelist : DEFAULTS.ATTRIBUTE_WHITELIST).toLowerCase());
|
|
563
|
+
// --- create element whitelist (__defaultElementWhiteList + elementWhitelist + format[line, BrLine, Block, Closureblock, ClosureBrLine] - elementBlacklist)
|
|
564
|
+
o.set('_editorElementWhitelist', o.get('elementWhitelist') === '*' ? '*' : _createWhitelist(o));
|
|
565
|
+
|
|
566
|
+
/** Toolbar */
|
|
567
|
+
o.set('toolbar_width', options.toolbar_width ? (numbers.is(options.toolbar_width) ? options.toolbar_width + 'px' : options.toolbar_width) : 'auto');
|
|
568
|
+
o.set('toolbar_container', options.toolbar_container && !/inline/i.test(o.get('mode')) ? (typeof options.toolbar_container === 'string' ? _d.querySelector(options.toolbar_container) : options.toolbar_container) : null);
|
|
569
|
+
o.set('toolbar_sticky', /balloon/i.test(o.get('mode')) ? -1 : options.toolbar_sticky === undefined ? 0 : numbers.is(options.toolbar_sticky) ? numbers.get(options.toolbar_sticky, 0) : -1);
|
|
570
|
+
o.set('toolbar_hide', !!options.toolbar_hide);
|
|
571
|
+
|
|
572
|
+
/** subToolbar */
|
|
573
|
+
let subButtons = null;
|
|
574
|
+
const subbar = options.subToolbar;
|
|
575
|
+
if (subbar?.buttonList?.length > 0) {
|
|
576
|
+
if (/balloon/.test(o.get('mode'))) {
|
|
577
|
+
console.warn('[SUNEDITOR.create.subToolbar.fail] When the "mode" option is "balloon-*", the "subToolbar" option is omitted.');
|
|
578
|
+
} else {
|
|
579
|
+
o.set('_subMode', subbar.mode || 'balloon');
|
|
580
|
+
o.set('toolbar.sub_width', subbar.width ? (numbers.is(subbar.width) ? subbar.width + 'px' : subbar.width) : 'auto');
|
|
581
|
+
subButtons = o.get('_rtl') ? subbar.buttonList.reverse() : subbar.buttonList;
|
|
582
|
+
o.set('buttons_sub', new Set(subButtons.toString().split(',')));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** root options */
|
|
587
|
+
const frameMap = new Map();
|
|
588
|
+
for (let i = 0, len = editorTargets.length; i < len; i++) {
|
|
589
|
+
frameMap.set(editorTargets[i].key, InitFrameOptions(editorTargets[i].options || {}, options));
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** Key actions */
|
|
593
|
+
o.set('tabDisable', !!options.tabDisable);
|
|
594
|
+
o.set('shortcutsHint', options.shortcutsHint === undefined ? true : !!options.shortcutsHint);
|
|
595
|
+
const shortcuts = !(options.shortcutsDisable === undefined ? true : !!options.shortcutsDisable)
|
|
596
|
+
? {}
|
|
597
|
+
: [
|
|
598
|
+
{
|
|
599
|
+
// default command
|
|
600
|
+
selectAll: ['c+KeyA', 'A'],
|
|
601
|
+
bold: ['c+KeyB', 'B'],
|
|
602
|
+
strike: ['c+s+KeyS', 'S'],
|
|
603
|
+
underline: ['c+KeyU', 'U'],
|
|
604
|
+
italic: ['c+KeyI', 'I'],
|
|
605
|
+
redo: ['c+KeyY', 'Y', 'c+s+KeyZ', 'Z'],
|
|
606
|
+
undo: ['c+KeyZ', 'Z'],
|
|
607
|
+
indent: ['c+BracketRight', ']'],
|
|
608
|
+
outdent: ['c+BracketLeft', '['],
|
|
609
|
+
save: ['c+KeyS', 'S'],
|
|
610
|
+
// plugins
|
|
611
|
+
link: ['c+KeyK', 'K'],
|
|
612
|
+
hr: ['!+---+=+~shortcut', ''],
|
|
613
|
+
list_numbered: ['!+1.+_+~shortcut', ''],
|
|
614
|
+
list_bulleted: ['!+*.+_+~shortcut', ''],
|
|
615
|
+
// custom
|
|
616
|
+
_h1: ['c+s+Digit1|Numpad1+$~formatBlock.applyHeaderByShortcut', ''],
|
|
617
|
+
_h2: ['c+s+Digit2|Numpad2+$~formatBlock.applyHeaderByShortcut', ''],
|
|
618
|
+
_h3: ['c+s+Digit3|Numpad3+$~formatBlock.applyHeaderByShortcut', '']
|
|
619
|
+
},
|
|
620
|
+
options.shortcuts || {}
|
|
621
|
+
].reduce((_default, _new) => {
|
|
622
|
+
for (const key in _new) {
|
|
623
|
+
_default[key] = _new[key];
|
|
624
|
+
}
|
|
625
|
+
return _default;
|
|
626
|
+
}, {});
|
|
627
|
+
o.set('shortcuts', shortcuts);
|
|
628
|
+
|
|
629
|
+
/** View */
|
|
630
|
+
o.set('fullScreenOffset', options.fullScreenOffset === undefined ? 0 : numbers.is(options.fullScreenOffset) ? numbers.get(options.fullScreenOffset, 0) : 0);
|
|
631
|
+
o.set('previewTemplate', typeof options.previewTemplate === 'string' ? options.previewTemplate : null);
|
|
632
|
+
o.set('printTemplate', typeof options.printTemplate === 'string' ? options.printTemplate : null);
|
|
633
|
+
|
|
634
|
+
/** --- Media select */
|
|
635
|
+
o.set('componentAutoSelect', options.componentAutoSelect === undefined ? false : !!options.componentAutoSelect);
|
|
636
|
+
|
|
637
|
+
/** --- Url input protocol */
|
|
638
|
+
o.set('defaultUrlProtocol', typeof options.defaultUrlProtocol === 'string' ? options.defaultUrlProtocol : null);
|
|
639
|
+
|
|
640
|
+
/** External library */
|
|
641
|
+
// CodeMirror
|
|
642
|
+
const cm = o.get('externalLibs').codeMirror;
|
|
643
|
+
if (cm) {
|
|
644
|
+
o.set('codeMirror', cm);
|
|
645
|
+
if (cm.EditorView) {
|
|
646
|
+
o.set('codeMirror6Editor', true);
|
|
647
|
+
} else if (cm.src) {
|
|
648
|
+
o.set('codeMirror5Editor', true);
|
|
649
|
+
} else {
|
|
650
|
+
console.warn('[SUNEDITOR.options.externalLibs.codeMirror.fail] The codeMirror option is set incorrectly.');
|
|
651
|
+
o.set('codeMirror', null);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** Private options */
|
|
656
|
+
o.set('__listCommonStyle', options.__listCommonStyle || ['fontSize', 'color', 'fontFamily', 'fontWeight', 'fontStyle']);
|
|
657
|
+
|
|
658
|
+
/** --- Icons ------------------------------------------------------------------------------------------ */
|
|
659
|
+
const icons =
|
|
660
|
+
!options.icons || typeof options.icons !== 'object'
|
|
661
|
+
? _icons
|
|
662
|
+
: [_icons, options.icons].reduce((_default, _new) => {
|
|
663
|
+
for (const key in _new) {
|
|
664
|
+
_default[key] = _new[key];
|
|
665
|
+
}
|
|
666
|
+
return _default;
|
|
667
|
+
}, {});
|
|
668
|
+
o.set('icons', icons);
|
|
669
|
+
|
|
670
|
+
/** Create all used styles */
|
|
671
|
+
const allUsedStyles = new Set(DEFAULTS.CONTENT_STYLES.split('|'));
|
|
672
|
+
const _ss = options.spanStyles?.split('|') || [];
|
|
673
|
+
const _ls = o.get('__listCommonStyle');
|
|
674
|
+
const _dts = DEFAULTS.SPAN_STYLES.split('|');
|
|
675
|
+
for (let i = 0, len = _dts.length; i < len; i++) {
|
|
676
|
+
allUsedStyles.add(_dts[i]);
|
|
677
|
+
}
|
|
678
|
+
for (const _ts of Object.values(o.get('tagStyles'))) {
|
|
679
|
+
const _tss = _ts.split('|');
|
|
680
|
+
for (let i = 0, len = _tss.length; i < len; i++) {
|
|
681
|
+
allUsedStyles.add(_tss[i]);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
for (let i = 0, len = _ss.length; i < len; i++) {
|
|
685
|
+
allUsedStyles.add(_ss[i]);
|
|
686
|
+
}
|
|
687
|
+
for (let i = 0, len = _ls.length; i < len; i++) {
|
|
688
|
+
allUsedStyles.add(_ls[i]);
|
|
689
|
+
}
|
|
690
|
+
const _aus = (typeof options.allUsedStyles === 'string' ? options.allUsedStyles.split('|') : options.allUsedStyles) || [];
|
|
691
|
+
for (let i = 0, len = _aus.length; i < len; i++) {
|
|
692
|
+
allUsedStyles.add(_aus[i]);
|
|
693
|
+
}
|
|
694
|
+
o.set('allUsedStyles', allUsedStyles);
|
|
695
|
+
o.set('toastMessageTime', { copy: 1500, ...options.toastMessageTime });
|
|
696
|
+
|
|
697
|
+
return {
|
|
698
|
+
o: o,
|
|
699
|
+
i: icons,
|
|
700
|
+
l: /** @type {Object<string, string>} */ (options.lang || _defaultLang),
|
|
701
|
+
v: (options.value = typeof options.value === 'string' ? options.value : null),
|
|
702
|
+
buttons: o.get('_rtl') ? buttonList.reverse() : buttonList,
|
|
703
|
+
subButtons: subButtons,
|
|
704
|
+
statusbarContainer: typeof options.statusbar_container === 'string' ? _d.querySelector(options.statusbar_container) : options.statusbar_container,
|
|
705
|
+
frameMap: frameMap
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* @description Create a context object for the editor frame.
|
|
711
|
+
* @param {Map<string, *>} targetOptions - editor.frameOptions
|
|
712
|
+
* @param {HTMLElement} statusbar - statusbar element
|
|
713
|
+
* @returns {{statusbar: HTMLElement, navigation: HTMLElement, charWrapper: HTMLElement, charCounter: HTMLElement}}
|
|
714
|
+
*/
|
|
715
|
+
export function CreateStatusbar(targetOptions, statusbar) {
|
|
716
|
+
let navigation = null;
|
|
717
|
+
let charWrapper = null;
|
|
718
|
+
let charCounter = null;
|
|
719
|
+
|
|
720
|
+
if (targetOptions.get('statusbar')) {
|
|
721
|
+
statusbar = statusbar || dom.utils.createElement('DIV', { class: 'se-status-bar sun-editor-common' });
|
|
722
|
+
|
|
723
|
+
/** navigation */
|
|
724
|
+
navigation = statusbar.querySelector('.se-navigation') || dom.utils.createElement('DIV', { class: 'se-navigation sun-editor-common' });
|
|
725
|
+
statusbar.appendChild(navigation);
|
|
726
|
+
|
|
727
|
+
/** char counter */
|
|
728
|
+
if (targetOptions.get('charCounter')) {
|
|
729
|
+
charWrapper = statusbar.querySelector('.se-char-counter-wrapper') || dom.utils.createElement('DIV', { class: 'se-char-counter-wrapper' });
|
|
730
|
+
|
|
731
|
+
if (targetOptions.get('charCounter_label')) {
|
|
732
|
+
const charLabel = charWrapper.querySelector('.se-char-label') || dom.utils.createElement('SPAN', { class: 'se-char-label' });
|
|
733
|
+
charLabel.textContent = targetOptions.get('charCounter_label');
|
|
734
|
+
charWrapper.appendChild(charLabel);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
charCounter = charWrapper.querySelector('.se-char-counter') || dom.utils.createElement('SPAN', { class: 'se-char-counter' });
|
|
738
|
+
charCounter.textContent = '0';
|
|
739
|
+
charWrapper.appendChild(charCounter);
|
|
740
|
+
|
|
741
|
+
if (targetOptions.get('charCounter_max') > 0) {
|
|
742
|
+
const char_max = charWrapper.querySelector('.se-char-max') || dom.utils.createElement('SPAN', { class: 'se-char-max' });
|
|
743
|
+
char_max.textContent = ' / ' + targetOptions.get('charCounter_max');
|
|
744
|
+
charWrapper.appendChild(char_max);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
statusbar.appendChild(charWrapper);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return {
|
|
752
|
+
statusbar: statusbar,
|
|
753
|
+
navigation: /** @type {HTMLElement} */ (navigation),
|
|
754
|
+
charWrapper: /** @type {HTMLElement} */ (charWrapper),
|
|
755
|
+
charCounter: /** @type {HTMLElement} */ (charCounter)
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* @description Initialize options.
|
|
761
|
+
* @param {EditorFrameOptions} o - Target options
|
|
762
|
+
* @param {EditorInitOptions} origin - Full options
|
|
763
|
+
* @returns {Map<string, *>}
|
|
764
|
+
*/
|
|
765
|
+
function InitFrameOptions(o, origin) {
|
|
766
|
+
const fo = new Map();
|
|
767
|
+
|
|
768
|
+
fo.set('_origin', o);
|
|
769
|
+
const barContainer = origin.statusbar_container;
|
|
770
|
+
|
|
771
|
+
// members
|
|
772
|
+
const value = o.value === undefined ? origin.value : o.value;
|
|
773
|
+
const placeholder = o.placeholder === undefined ? origin.placeholder : o.placeholder;
|
|
774
|
+
const editableFrameAttributes = o.editableFrameAttributes === undefined ? origin.editableFrameAttributes : o.editableFrameAttributes;
|
|
775
|
+
const width = o.width === undefined ? origin.width : o.width;
|
|
776
|
+
const minWidth = o.minWidth === undefined ? origin.minWidth : o.minWidth;
|
|
777
|
+
const maxWidth = o.maxWidth === undefined ? origin.maxWidth : o.maxWidth;
|
|
778
|
+
const height = o.height === undefined ? origin.height : o.height;
|
|
779
|
+
const minHeight = o.minHeight === undefined ? origin.minHeight : o.minHeight;
|
|
780
|
+
const maxHeight = o.maxHeight === undefined ? origin.maxHeight : o.maxHeight;
|
|
781
|
+
const editorStyle = o.editorStyle === undefined ? origin.editorStyle : o.editorStyle;
|
|
782
|
+
const iframe = o.iframe === undefined ? origin.iframe : o.iframe;
|
|
783
|
+
const iframe_fullPage = o.iframe_fullPage === undefined ? origin.iframe_fullPage : o.iframe_fullPage;
|
|
784
|
+
const iframe_attributes = o.iframe_attributes === undefined ? origin.iframe_attributes : o.iframe_attributes;
|
|
785
|
+
const iframe_cssFileName = o.iframe_cssFileName === undefined ? origin.iframe_cssFileName : o.iframe_cssFileName;
|
|
786
|
+
const statusbar = barContainer || o.statusbar === undefined ? origin.statusbar : o.statusbar;
|
|
787
|
+
const statusbar_showPathLabel = barContainer || o.statusbar_showPathLabel === undefined ? origin.statusbar_showPathLabel : o.statusbar_showPathLabel;
|
|
788
|
+
const statusbar_resizeEnable = barContainer ? false : o.statusbar_resizeEnable === undefined ? origin.statusbar_resizeEnable : o.statusbar_resizeEnable;
|
|
789
|
+
const charCounter = barContainer || o.charCounter === undefined ? origin.charCounter : o.charCounter;
|
|
790
|
+
const charCounter_max = barContainer || o.charCounter_max === undefined ? origin.charCounter_max : o.charCounter_max;
|
|
791
|
+
const charCounter_label = barContainer || o.charCounter_label === undefined ? origin.charCounter_label : o.charCounter_label;
|
|
792
|
+
const charCounter_type = barContainer || o.charCounter_type === undefined ? origin.charCounter_type : o.charCounter_type;
|
|
793
|
+
|
|
794
|
+
// value
|
|
795
|
+
fo.set('value', value);
|
|
796
|
+
fo.set('placeholder', placeholder);
|
|
797
|
+
fo.set('editableFrameAttributes', { spellcheck: 'false', ...editableFrameAttributes });
|
|
798
|
+
// styles
|
|
799
|
+
fo.set('width', width ? (numbers.is(width) ? width + 'px' : width) : '100%');
|
|
800
|
+
fo.set('minWidth', (numbers.is(minWidth) ? minWidth + 'px' : minWidth) || '');
|
|
801
|
+
fo.set('maxWidth', (numbers.is(maxWidth) ? maxWidth + 'px' : maxWidth) || '');
|
|
802
|
+
fo.set('height', height ? (numbers.is(height) ? height + 'px' : height) : 'auto');
|
|
803
|
+
fo.set('minHeight', (numbers.is(minHeight) ? minHeight + 'px' : minHeight) || '');
|
|
804
|
+
fo.set('maxHeight', (numbers.is(maxHeight) ? maxHeight + 'px' : maxHeight) || '');
|
|
805
|
+
fo.set('editorStyle', editorStyle);
|
|
806
|
+
fo.set('_defaultStyles', converter._setDefaultOptionStyle(fo, typeof editorStyle === 'string' ? editorStyle : ''));
|
|
807
|
+
// iframe
|
|
808
|
+
fo.set('iframe', !!(iframe_fullPage || iframe));
|
|
809
|
+
fo.set('iframe_fullPage', !!iframe_fullPage);
|
|
810
|
+
fo.set('iframe_attributes', iframe_attributes || {});
|
|
811
|
+
fo.set('iframe_cssFileName', iframe ? (typeof iframe_cssFileName === 'string' ? [iframe_cssFileName] : iframe_cssFileName || ['suneditor']) : null);
|
|
812
|
+
// status bar
|
|
813
|
+
const hasStatusbar = statusbar === undefined ? true : !!statusbar;
|
|
814
|
+
fo.set('statusbar', hasStatusbar);
|
|
815
|
+
fo.set('statusbar_showPathLabel', !hasStatusbar ? false : typeof statusbar_showPathLabel === 'boolean' ? statusbar_showPathLabel : true);
|
|
816
|
+
fo.set('statusbar_resizeEnable', !hasStatusbar ? false : statusbar_resizeEnable === undefined ? true : !!statusbar_resizeEnable);
|
|
817
|
+
// status bar - character count
|
|
818
|
+
fo.set('charCounter', charCounter_max > 0 ? true : typeof charCounter === 'boolean' ? charCounter : false);
|
|
819
|
+
fo.set('charCounter_max', numbers.is(charCounter_max) && charCounter_max > -1 ? charCounter_max * 1 : null);
|
|
820
|
+
fo.set('charCounter_label', typeof charCounter_label === 'string' ? charCounter_label.trim() : null);
|
|
821
|
+
fo.set('charCounter_type', typeof charCounter_type === 'string' ? charCounter_type : 'char');
|
|
822
|
+
|
|
823
|
+
return fo;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @private
|
|
828
|
+
* @description Initialize property of suneditor elements
|
|
829
|
+
* @param {string} key - The key of the editor frame
|
|
830
|
+
* @param {Map<string, *>} options - options
|
|
831
|
+
* @param {HTMLElement} topDiv - top div
|
|
832
|
+
* @param {Map<string, *>} targetOptions - editor.frameOptions
|
|
833
|
+
* @returns {{bottomBar: ReturnType<CreateStatusbar>, wysiwygFrame: HTMLElement, codeView: HTMLElement, placeholder: HTMLElement}}
|
|
834
|
+
*/
|
|
835
|
+
function _initTargetElements(key, options, topDiv, targetOptions) {
|
|
836
|
+
const editorStyles = targetOptions.get('_defaultStyles');
|
|
837
|
+
/** top div */
|
|
838
|
+
topDiv.style.cssText = editorStyles.top;
|
|
839
|
+
|
|
840
|
+
/** editor */
|
|
841
|
+
// wysiwyg div or iframe
|
|
842
|
+
const wysiwygDiv = dom.utils.createElement(!targetOptions.get('iframe') ? 'DIV' : 'IFRAME', {
|
|
843
|
+
class: 'se-wrapper-inner se-wrapper-wysiwyg' + (options.get('type') === 'document' ? ' se-type-document-iframe-a4' : ''),
|
|
844
|
+
'data-root-key': key
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
if (!targetOptions.get('iframe')) {
|
|
848
|
+
wysiwygDiv.setAttribute('contenteditable', 'true');
|
|
849
|
+
wysiwygDiv.setAttribute('scrolling', 'auto');
|
|
850
|
+
wysiwygDiv.className += ' ' + options.get('_editableClass');
|
|
851
|
+
wysiwygDiv.style.cssText = editorStyles.frame + editorStyles.editor;
|
|
852
|
+
} else {
|
|
853
|
+
const frameAttrs = targetOptions.get('iframe_attributes');
|
|
854
|
+
for (const frameKey in frameAttrs) {
|
|
855
|
+
wysiwygDiv.setAttribute(frameKey, frameAttrs[frameKey]);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
const iframeWW = /** @type {HTMLIFrameElement} */ (wysiwygDiv);
|
|
859
|
+
iframeWW.allowFullscreen = true;
|
|
860
|
+
iframeWW.frameBorder = '0';
|
|
861
|
+
iframeWW.style.cssText = editorStyles.frame;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// textarea for code view
|
|
865
|
+
const textarea = dom.utils.createElement('TEXTAREA', { class: 'se-wrapper-inner se-code-viewer', style: editorStyles.frame });
|
|
866
|
+
const placeholder = dom.utils.createElement('SPAN', { class: 'se-placeholder' });
|
|
867
|
+
if (targetOptions.get('placeholder')) {
|
|
868
|
+
placeholder.textContent = targetOptions.get('placeholder');
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
return {
|
|
872
|
+
bottomBar: CreateStatusbar(targetOptions, null),
|
|
873
|
+
wysiwygFrame: wysiwygDiv,
|
|
874
|
+
codeView: textarea,
|
|
875
|
+
placeholder: placeholder
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* @private
|
|
881
|
+
* @description Check the CodeMirror option to apply the CodeMirror and return the CodeMirror element.
|
|
882
|
+
* @param {Map<string, *>} options options
|
|
883
|
+
* @param {HTMLElement} textarea textarea element
|
|
884
|
+
*/
|
|
885
|
+
function _checkCodeMirror(options, targetOptions, textarea) {
|
|
886
|
+
let cmeditor = null;
|
|
887
|
+
let hasCodeMirror = false;
|
|
888
|
+
|
|
889
|
+
if (options.get('codeMirror6Editor')) {
|
|
890
|
+
const codeMirror = options.get('codeMirror');
|
|
891
|
+
const codeStyles = textarea.style.cssText;
|
|
892
|
+
const cm = new codeMirror.EditorView({
|
|
893
|
+
parent: textarea.parentElement,
|
|
894
|
+
extensions: codeMirror.extensions,
|
|
895
|
+
state: codeMirror.state
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
targetOptions.set('codeMirror6Editor', cm);
|
|
899
|
+
cmeditor = cm.dom;
|
|
900
|
+
cmeditor.style.cssText = codeStyles;
|
|
901
|
+
hasCodeMirror = true;
|
|
902
|
+
} else if (options.get('codeMirror5Editor')) {
|
|
903
|
+
const codeMirror = options.get('codeMirror');
|
|
904
|
+
const cmOptions = [
|
|
905
|
+
{
|
|
906
|
+
mode: 'htmlmixed',
|
|
907
|
+
htmlMode: true,
|
|
908
|
+
lineNumbers: true,
|
|
909
|
+
lineWrapping: true
|
|
910
|
+
},
|
|
911
|
+
codeMirror.options || {}
|
|
912
|
+
].reduce((init, option) => {
|
|
913
|
+
for (const key in option) {
|
|
914
|
+
init[key] = option[key];
|
|
915
|
+
}
|
|
916
|
+
return init;
|
|
917
|
+
}, {});
|
|
918
|
+
|
|
919
|
+
if (targetOptions.get('height') === 'auto') {
|
|
920
|
+
cmOptions.viewportMargin = Infinity;
|
|
921
|
+
cmOptions.height = 'auto';
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const codeStyles = textarea.style.cssText;
|
|
925
|
+
const cm = codeMirror.src.fromTextArea(textarea, cmOptions);
|
|
926
|
+
targetOptions.set('codeMirror5Editor', cm);
|
|
927
|
+
cmeditor = cm.display.wrapper;
|
|
928
|
+
cmeditor.style.cssText = codeStyles;
|
|
929
|
+
hasCodeMirror = true;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
options.set('hasCodeMirror', hasCodeMirror);
|
|
933
|
+
if (cmeditor) {
|
|
934
|
+
dom.utils.removeItem(textarea);
|
|
935
|
+
cmeditor.className += ' se-code-viewer-mirror';
|
|
936
|
+
return cmeditor;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
return textarea;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* @private
|
|
944
|
+
* @description create blacklist
|
|
945
|
+
* @param {string} blacklist blacklist
|
|
946
|
+
* @param {string} defaultLine options.get('defaultLine')
|
|
947
|
+
* @returns {string}
|
|
948
|
+
*/
|
|
949
|
+
function _createBlacklist(blacklist, defaultLine) {
|
|
950
|
+
defaultLine = defaultLine.toLowerCase();
|
|
951
|
+
return blacklist
|
|
952
|
+
.split('|')
|
|
953
|
+
.filter(function (v) {
|
|
954
|
+
if (v !== defaultLine) {
|
|
955
|
+
return true;
|
|
956
|
+
} else {
|
|
957
|
+
console.warn(`[SUNEDITOR.constructor.createBlacklist.warn] defaultLine("<${defaultLine}>") cannot be included in the blacklist and will be removed.`);
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
960
|
+
})
|
|
961
|
+
.join('|');
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* @private
|
|
966
|
+
* @description create formats regexp object.
|
|
967
|
+
* @param {string} value value
|
|
968
|
+
* @param {string} defaultValue default value
|
|
969
|
+
* @param {string} blacklist blacklist
|
|
970
|
+
* @returns {{reg: RegExp, str: string}}
|
|
971
|
+
*/
|
|
972
|
+
function _createFormatInfo(value, defaultValue, blacklist) {
|
|
973
|
+
const blist = blacklist.split('|');
|
|
974
|
+
const str = (defaultValue + '|' + (typeof value === 'string' ? value.toLowerCase() : ''))
|
|
975
|
+
.replace(/^\||\|$/g, '')
|
|
976
|
+
.split('|')
|
|
977
|
+
.filter((v) => v && !blist.includes(v))
|
|
978
|
+
.join('|');
|
|
979
|
+
return {
|
|
980
|
+
reg: new RegExp(`^(${str})$`, 'i'),
|
|
981
|
+
str: str
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* @private
|
|
987
|
+
* @description create whitelist or blacklist.
|
|
988
|
+
* @param {Map<string, *>} o options
|
|
989
|
+
* @returns {string} whitelist
|
|
990
|
+
*/
|
|
991
|
+
function _createWhitelist(o) {
|
|
992
|
+
const blacklist = o.get('elementBlacklist').split('|');
|
|
993
|
+
const whitelist = (o.get('__defaultElementWhitelist') + '|' + o.get('elementWhitelist') + '|' + o.get('formatLine').str + '|' + o.get('formatBrLine').str + '|' + o.get('formatClosureBlock').str + '|' + o.get('formatClosureBrLine').str)
|
|
994
|
+
.replace(/(^\||\|$)/g, '')
|
|
995
|
+
.split('|')
|
|
996
|
+
.filter((v, i, a) => v && a.indexOf(v) === i && !blacklist.includes(v));
|
|
997
|
+
|
|
998
|
+
return whitelist.join('|');
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* @private
|
|
1003
|
+
* @description Suneditor's Default button list
|
|
1004
|
+
* @param {Map<string, *>} options options
|
|
1005
|
+
*/
|
|
1006
|
+
function _defaultButtons(options, icons, lang) {
|
|
1007
|
+
const isRTL = options.get('_rtl');
|
|
1008
|
+
return {
|
|
1009
|
+
bold: ['', lang.bold, 'bold', '', icons.bold],
|
|
1010
|
+
underline: ['', lang.underline, 'underline', '', icons.underline],
|
|
1011
|
+
italic: ['', lang.italic, 'italic', '', icons.italic],
|
|
1012
|
+
strike: ['', lang.strike, 'strike', '', icons.strike],
|
|
1013
|
+
subscript: ['', lang.subscript, 'subscript', '', icons.subscript],
|
|
1014
|
+
superscript: ['', lang.superscript, 'superscript', '', icons.superscript],
|
|
1015
|
+
removeFormat: ['', lang.removeFormat, 'removeFormat', '', icons.remove_format],
|
|
1016
|
+
copyFormat: ['', lang.copyFormat, 'copyFormat', '', icons.format_paint],
|
|
1017
|
+
indent: ['se-icon-flip-rtl', lang.indent, 'indent', '', isRTL ? icons.outdent : icons.indent],
|
|
1018
|
+
outdent: ['se-icon-flip-rtl', lang.outdent, 'outdent', '', isRTL ? icons.indent : icons.outdent],
|
|
1019
|
+
fullScreen: ['se-code-view-enabled se-component-enabled', lang.fullScreen, 'fullScreen', '', icons.expansion],
|
|
1020
|
+
showBlocks: ['', lang.showBlocks, 'showBlocks', '', icons.show_blocks],
|
|
1021
|
+
codeView: ['se-code-view-enabled se-component-enabled', lang.codeView, 'codeView', '', icons.code_view],
|
|
1022
|
+
undo: ['se-component-enabled', lang.undo, 'undo', '', icons.undo],
|
|
1023
|
+
redo: ['se-component-enabled', lang.redo, 'redo', '', icons.redo],
|
|
1024
|
+
preview: ['se-component-enabled', lang.preview, 'preview', '', icons.preview],
|
|
1025
|
+
print: ['se-component-enabled', lang.print, 'print', '', icons.print],
|
|
1026
|
+
copy: ['', lang.copy, 'copy', '', icons.copy],
|
|
1027
|
+
dir: ['', lang[isRTL ? 'dir_ltr' : 'dir_rtl'], 'dir', '', icons[isRTL ? 'dir_ltr' : 'dir_rtl']],
|
|
1028
|
+
dir_ltr: ['', lang.dir_ltr, 'dir_ltr', '', icons.dir_ltr],
|
|
1029
|
+
dir_rtl: ['', lang.dir_rtl, 'dir_rtl', '', icons.dir_rtl],
|
|
1030
|
+
save: ['se-component-enabled', lang.save, 'save', '', icons.save],
|
|
1031
|
+
newDocument: ['se-component-enabled', lang.newDocument, 'newDocument', '', icons.new_document],
|
|
1032
|
+
selectAll: ['se-component-enabled', lang.selectAll, 'selectAll', '', icons.select_all],
|
|
1033
|
+
pageBreak: ['se-component-enabled', lang.pageBreak, 'pageBreak', '', icons.page_break],
|
|
1034
|
+
// document type buttons
|
|
1035
|
+
pageUp: ['se-component-enabled', lang.pageUp, 'pageUp', '', icons.page_up],
|
|
1036
|
+
pageDown: ['se-component-enabled', lang.pageDown, 'pageDown', '', icons.page_down],
|
|
1037
|
+
pageNavigator: ['se-component-enabled', '', 'pageNavigator', 'input', '']
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* @private
|
|
1043
|
+
* @description Create a group div containing each module
|
|
1044
|
+
* @returns {{div: Element, ul: Element}}
|
|
1045
|
+
*/
|
|
1046
|
+
function _createModuleGroup() {
|
|
1047
|
+
const oUl = dom.utils.createElement('UL', { class: 'se-menu-list' });
|
|
1048
|
+
const oDiv = dom.utils.createElement('DIV', { class: 'se-btn-module se-btn-module-border' }, oUl);
|
|
1049
|
+
|
|
1050
|
+
return {
|
|
1051
|
+
div: oDiv,
|
|
1052
|
+
ul: oUl
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* @private
|
|
1058
|
+
* @description Create a button element
|
|
1059
|
+
* @param {string} className className in button
|
|
1060
|
+
* @param {string} title Title in button
|
|
1061
|
+
* @param {string} dataCommand The data-command property of the button
|
|
1062
|
+
* @param {"command"|"dropdown"|"field"|"browser"|"input"|"modal"|"popup"} dataType The data-type property of the button
|
|
1063
|
+
* @param {string} innerHTML Html in button
|
|
1064
|
+
* @param {string} _disabled Button disabled
|
|
1065
|
+
* @param {Object<string, string>} icons Icons
|
|
1066
|
+
* @returns {{li: HTMLElement, button: HTMLElement}}
|
|
1067
|
+
*/
|
|
1068
|
+
function _createButton(className, title, dataCommand, dataType, innerHTML, _disabled, icons) {
|
|
1069
|
+
if (!innerHTML) innerHTML = '';
|
|
1070
|
+
|
|
1071
|
+
const oLi = dom.utils.createElement('LI');
|
|
1072
|
+
const label = title || '';
|
|
1073
|
+
const isDiv = /^INPUT|FIELD$/i.test(dataType);
|
|
1074
|
+
const oButton = /** @type {HTMLButtonElement} */ (
|
|
1075
|
+
'se-toolbar-separator-vertical' === className
|
|
1076
|
+
? dom.utils.createElement('DIV', { class: className, tabindex: '-1' }, null)
|
|
1077
|
+
: dom.utils.createElement(isDiv ? 'DIV' : 'BUTTON', {
|
|
1078
|
+
class: 'se-toolbar-btn se-btn se-tooltip' + (className ? ' ' + className : ''),
|
|
1079
|
+
'data-command': dataCommand,
|
|
1080
|
+
'data-type': dataType,
|
|
1081
|
+
'aria-label': label.replace(/<span .+<\/span>/, ''),
|
|
1082
|
+
tabindex: '-1'
|
|
1083
|
+
})
|
|
1084
|
+
);
|
|
1085
|
+
|
|
1086
|
+
if (!isDiv) {
|
|
1087
|
+
oButton.setAttribute('type', 'button');
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (/^default\./i.test(innerHTML)) {
|
|
1091
|
+
innerHTML = icons[innerHTML.replace(/^default\./i, '')];
|
|
1092
|
+
}
|
|
1093
|
+
if (/^text\./i.test(innerHTML)) {
|
|
1094
|
+
innerHTML = innerHTML.replace(/^text\./i, '');
|
|
1095
|
+
oButton.className += ' se-btn-more-text';
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
if (_disabled) oButton.disabled = true;
|
|
1099
|
+
|
|
1100
|
+
if (/^FIELD$/i.test(dataType)) dom.utils.addClass(oLi, 'se-toolbar-hidden-btn');
|
|
1101
|
+
|
|
1102
|
+
if (label) innerHTML += dom.utils.createTooltipInner(label);
|
|
1103
|
+
if (innerHTML) oButton.innerHTML = innerHTML;
|
|
1104
|
+
|
|
1105
|
+
oLi.appendChild(oButton);
|
|
1106
|
+
|
|
1107
|
+
return {
|
|
1108
|
+
li: oLi,
|
|
1109
|
+
button: oButton
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* @description Update a button state, attributes, and icons
|
|
1115
|
+
* @param {HTMLElement|null} element Button element
|
|
1116
|
+
* @param {Object<string, *>} plugin Plugin
|
|
1117
|
+
* @param {Object<string, string>} icons Icons
|
|
1118
|
+
* @param {Object<string, string>} lang lang
|
|
1119
|
+
*/
|
|
1120
|
+
export function UpdateButton(element, plugin, icons, lang) {
|
|
1121
|
+
if (!element) return;
|
|
1122
|
+
|
|
1123
|
+
const noneInner = plugin.inner === false;
|
|
1124
|
+
|
|
1125
|
+
if (plugin.inner?.nodeType === 1) {
|
|
1126
|
+
element.appendChild(plugin.inner);
|
|
1127
|
+
} else {
|
|
1128
|
+
element.innerHTML = noneInner
|
|
1129
|
+
? ''
|
|
1130
|
+
: (plugin.inner || icons[plugin.icon] || plugin.icon || '<span class="se-icon-text">!</span>') + '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + (lang[plugin.title] || plugin.title) + '</span></span>';
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
element.setAttribute('aria-label', plugin.title);
|
|
1134
|
+
|
|
1135
|
+
if (plugin.type) {
|
|
1136
|
+
element.setAttribute('data-type', plugin.type);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
if (plugin.className) {
|
|
1140
|
+
element.className += ' ' + plugin.className;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// side, replace button
|
|
1144
|
+
if (plugin.afterItem) {
|
|
1145
|
+
dom.utils.addClass(plugin.afterItem, 'se-toolbar-btn');
|
|
1146
|
+
element.parentElement.appendChild(plugin.afterItem);
|
|
1147
|
+
|
|
1148
|
+
dom.utils.addClass(element, 'se-side-btn-a');
|
|
1149
|
+
dom.utils.addClass(plugin.afterItem, 'se-side-btn-after');
|
|
1150
|
+
}
|
|
1151
|
+
if (plugin.beforeItem) {
|
|
1152
|
+
dom.utils.addClass(plugin.beforeItem, 'se-toolbar-btn');
|
|
1153
|
+
element.parentElement.insertBefore(plugin.beforeItem, element);
|
|
1154
|
+
|
|
1155
|
+
if (plugin.afterItem) {
|
|
1156
|
+
dom.utils.addClass(element, 'se-side-btn');
|
|
1157
|
+
dom.utils.removeClass(element, 'se-side-btn-a');
|
|
1158
|
+
} else {
|
|
1159
|
+
dom.utils.addClass(element, 'se-side-btn-b');
|
|
1160
|
+
}
|
|
1161
|
+
dom.utils.addClass(plugin.beforeItem, 'se-side-btn-before');
|
|
1162
|
+
}
|
|
1163
|
+
if (plugin.replaceButton) {
|
|
1164
|
+
element.parentElement.appendChild(plugin.replaceButton);
|
|
1165
|
+
element.style.display = 'none';
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
if (!plugin.replaceButton && /^INPUT$/i.test(element.getAttribute('data-type'))) {
|
|
1169
|
+
const inputTarget = element.querySelector('input');
|
|
1170
|
+
if (inputTarget) {
|
|
1171
|
+
dom.utils.addClass(inputTarget, 'se-toolbar-btn');
|
|
1172
|
+
inputTarget.setAttribute('data-command', element.getAttribute('data-command'));
|
|
1173
|
+
inputTarget.setAttribute('data-type', element.getAttribute('data-type'));
|
|
1174
|
+
if (element.hasAttribute('disabled')) inputTarget.disabled = true;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* @description Create editor HTML
|
|
1181
|
+
* @param {Array} buttonList option.buttonList
|
|
1182
|
+
* @param {?Object<string, *>} plugins Plugins
|
|
1183
|
+
* @param {Map<string, *>} options options
|
|
1184
|
+
* @param {Object<string, string>} icons icons
|
|
1185
|
+
* @param {Object<string, string>} lang lang
|
|
1186
|
+
* @param {boolean} isUpdate Is update
|
|
1187
|
+
* @returns {{element: HTMLElement, pluginCallButtons: Object<string, Array<HTMLElement>>, responsiveButtons: Array<HTMLElement>, buttonTray: HTMLElement, updateButtons: Array<{button: HTMLElement, plugin: *, key: string}>}}}
|
|
1188
|
+
*/
|
|
1189
|
+
export function CreateToolBar(buttonList, plugins, options, icons, lang, isUpdate) {
|
|
1190
|
+
/** create button list */
|
|
1191
|
+
buttonList = JSON.parse(JSON.stringify(buttonList));
|
|
1192
|
+
const defaultButtonList = _defaultButtons(options, icons, lang);
|
|
1193
|
+
/** @type {Object<string, Array<HTMLElement>>} */
|
|
1194
|
+
const pluginCallButtons = {};
|
|
1195
|
+
const responsiveButtons = [];
|
|
1196
|
+
const updateButtons = [];
|
|
1197
|
+
|
|
1198
|
+
let modules = null;
|
|
1199
|
+
let button = null;
|
|
1200
|
+
let plugin = null;
|
|
1201
|
+
let moduleElement = null;
|
|
1202
|
+
let buttonElement = null;
|
|
1203
|
+
// let vertical = false;
|
|
1204
|
+
const moreLayer = dom.utils.createElement('DIV', { class: 'se-toolbar-more-layer' });
|
|
1205
|
+
const buttonTray = dom.utils.createElement('DIV', { class: 'se-btn-tray' });
|
|
1206
|
+
const separator_vertical = dom.utils.createElement('DIV', { class: 'se-toolbar-separator-vertical' });
|
|
1207
|
+
|
|
1208
|
+
buttonGroupLoop: for (let i = 0, more, moreContainer, moreCommand, buttonGroup, align; i < buttonList.length; i++) {
|
|
1209
|
+
more = false;
|
|
1210
|
+
align = '';
|
|
1211
|
+
buttonGroup = buttonList[i];
|
|
1212
|
+
moduleElement = _createModuleGroup();
|
|
1213
|
+
|
|
1214
|
+
// button object
|
|
1215
|
+
if (typeof buttonGroup === 'object') {
|
|
1216
|
+
// buttons loop
|
|
1217
|
+
for (let j = 0, moreButton; j < buttonGroup.length; j++) {
|
|
1218
|
+
button = buttonGroup[j];
|
|
1219
|
+
moreButton = false;
|
|
1220
|
+
plugin = plugins[button];
|
|
1221
|
+
|
|
1222
|
+
if (/^%\d+/.test(button) && j === 0) {
|
|
1223
|
+
buttonGroup[0] = button.replace(/[^\d]/g, '');
|
|
1224
|
+
responsiveButtons.push(buttonGroup);
|
|
1225
|
+
buttonList.splice(i--, 1);
|
|
1226
|
+
continue buttonGroupLoop;
|
|
1227
|
+
}
|
|
1228
|
+
if (typeof plugin === 'function') {
|
|
1229
|
+
modules = [plugin.className, plugin.title, button, plugin.type, plugin.innerHTML, plugin._disabled];
|
|
1230
|
+
} else if (typeof plugin === 'object') {
|
|
1231
|
+
const originFnc = plugin.constructor;
|
|
1232
|
+
modules = [plugin.className || originFnc.className, plugin.title || originFnc.title, button, plugin.type || originFnc.type, plugin.innerHTML || originFnc.innerHTML, plugin._disabled || originFnc._disabled];
|
|
1233
|
+
} else {
|
|
1234
|
+
// align
|
|
1235
|
+
if (/^-/.test(button)) {
|
|
1236
|
+
align = button.substring(1);
|
|
1237
|
+
moduleElement.div.className += ' module-float-' + align;
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// rtl fix
|
|
1242
|
+
if (/^#/.test(button)) {
|
|
1243
|
+
const option = button.substring(1);
|
|
1244
|
+
if (option === 'fix') moduleElement.ul.className += ' se-menu-dir-fix';
|
|
1245
|
+
continue;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// more button
|
|
1249
|
+
if (/^:/.test(button)) {
|
|
1250
|
+
moreButton = true;
|
|
1251
|
+
const matched = button.match(/^:([^-]+)-([^-]+)/);
|
|
1252
|
+
moreCommand = '__se__more_' + i;
|
|
1253
|
+
const title = matched[1].trim();
|
|
1254
|
+
const innerHTML = matched[2].trim();
|
|
1255
|
+
modules = ['se-btn-more', /^lang\./i.test(title) ? lang[title.replace(/^lang\./i, '')] : title, moreCommand, 'MORE', innerHTML];
|
|
1256
|
+
} else if (button === '|') {
|
|
1257
|
+
// separator vertical
|
|
1258
|
+
modules = ['se-toolbar-separator-vertical', '', '', 'separator', ''];
|
|
1259
|
+
} else {
|
|
1260
|
+
// default command
|
|
1261
|
+
if (button === 'copy' && !env.isClipboardSupported) {
|
|
1262
|
+
console.warn('[SUNEDITOR.constructor.warn] Clipboard is not supported in this browser. : [copy] button is not rendered.');
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
modules = defaultButtonList[button];
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
if (!modules) {
|
|
1269
|
+
if (!plugin) throw Error(`[SUNEDITOR.create.toolbar.fail] The button name of a plugin that does not exist. [${button}]`);
|
|
1270
|
+
plugin = typeof plugin === 'object' ? plugin.constructor : plugin;
|
|
1271
|
+
modules = [plugin.className, plugin.title, plugin.key, plugin.type, plugin.innerHTML, plugin._disabled];
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
buttonElement = _createButton(modules[0], modules[1], modules[2], modules[3], modules[4], modules[5], icons);
|
|
1276
|
+
(more ? moreContainer : moduleElement.ul).appendChild(buttonElement.li);
|
|
1277
|
+
|
|
1278
|
+
if (plugin) {
|
|
1279
|
+
if (pluginCallButtons[button]) {
|
|
1280
|
+
pluginCallButtons[button].push(buttonElement.button);
|
|
1281
|
+
} else {
|
|
1282
|
+
pluginCallButtons[button] = [buttonElement.button];
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
if (isUpdate) {
|
|
1286
|
+
updateButtons.push({ button: buttonElement.button, plugin, key: button });
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// more button
|
|
1291
|
+
if (moreButton) {
|
|
1292
|
+
more = true;
|
|
1293
|
+
moreContainer = dom.utils.createElement('DIV');
|
|
1294
|
+
moreContainer.className = 'se-more-layer ' + moreCommand;
|
|
1295
|
+
moreContainer.setAttribute('data-ref', moreCommand);
|
|
1296
|
+
moreContainer.innerHTML = '<div class="se-more-form"><ul class="se-menu-list"' + (align ? ' style="float: ' + align + ';"' : '') + '></ul></div>';
|
|
1297
|
+
moreLayer.appendChild(moreContainer);
|
|
1298
|
+
moreContainer = moreContainer.firstElementChild.firstElementChild;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// if (vertical) {
|
|
1303
|
+
// const sv = separator_vertical.cloneNode(false);
|
|
1304
|
+
// buttonTray.appendChild(sv);
|
|
1305
|
+
// }
|
|
1306
|
+
|
|
1307
|
+
buttonTray.appendChild(moduleElement.div);
|
|
1308
|
+
// vertical = true;
|
|
1309
|
+
} else if (buttonGroup === '|') {
|
|
1310
|
+
// // separator vertical
|
|
1311
|
+
const sv = separator_vertical.cloneNode(false);
|
|
1312
|
+
buttonTray.appendChild(sv);
|
|
1313
|
+
continue;
|
|
1314
|
+
} else if (/^\/$/.test(buttonGroup)) {
|
|
1315
|
+
/** line break */
|
|
1316
|
+
const enterDiv = dom.utils.createElement('DIV', { class: 'se-btn-module-enter' });
|
|
1317
|
+
buttonTray.appendChild(enterDiv);
|
|
1318
|
+
// vertical = false;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
switch (buttonTray.children.length) {
|
|
1323
|
+
case 0:
|
|
1324
|
+
buttonTray.style.display = 'none';
|
|
1325
|
+
break;
|
|
1326
|
+
case 1:
|
|
1327
|
+
dom.utils.removeClass(buttonTray.firstElementChild, 'se-btn-module-border');
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
if (moreLayer.children.length > 0) buttonTray.appendChild(moreLayer);
|
|
1332
|
+
if (responsiveButtons.length > 0) responsiveButtons.unshift(buttonList);
|
|
1333
|
+
|
|
1334
|
+
// rendering toolbar
|
|
1335
|
+
const tool_bar = dom.utils.createElement('DIV', { class: 'se-toolbar sun-editor-common' + (!options.get('shortcutsHint') ? ' se-shortcut-hide' : '') }, buttonTray);
|
|
1336
|
+
|
|
1337
|
+
if (options.get('toolbar_hide')) tool_bar.style.display = 'none';
|
|
1338
|
+
|
|
1339
|
+
return {
|
|
1340
|
+
element: tool_bar,
|
|
1341
|
+
pluginCallButtons,
|
|
1342
|
+
responsiveButtons,
|
|
1343
|
+
buttonTray,
|
|
1344
|
+
updateButtons
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
export default Constructor;
|