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
package/src/modules/Browser.js
CHANGED
|
@@ -1,667 +1,669 @@
|
|
|
1
|
-
import CoreInjector from '../editorInjector/_core';
|
|
2
|
-
import { dom, keyCodeMap } from '../helper';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @
|
|
8
|
-
* @property {string} [
|
|
9
|
-
* @property {string
|
|
10
|
-
* @property {string=}
|
|
11
|
-
* @property {
|
|
12
|
-
* @property {string=}
|
|
13
|
-
* @property {string=}
|
|
14
|
-
* @property {
|
|
15
|
-
* @property {
|
|
16
|
-
* @property {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @
|
|
22
|
-
* @property {string
|
|
23
|
-
* @property {
|
|
24
|
-
* @property {string
|
|
25
|
-
* @property {
|
|
26
|
-
* @property {
|
|
27
|
-
* @property {
|
|
28
|
-
* @property {
|
|
29
|
-
* @property {
|
|
30
|
-
* @property {string
|
|
31
|
-
* @property {
|
|
32
|
-
* @property {
|
|
33
|
-
* @property {
|
|
34
|
-
* @property {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* @
|
|
45
|
-
* @param {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
browserFrame.appendChild(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.eventManager.addEvent(this.
|
|
121
|
-
this.eventManager.addEvent(this.
|
|
122
|
-
this.eventManager.addEvent(
|
|
123
|
-
this.eventManager.addEvent(content, '
|
|
124
|
-
this.eventManager.addEvent(
|
|
125
|
-
this.eventManager.addEvent(
|
|
126
|
-
this.eventManager.addEvent(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* @
|
|
132
|
-
* @param {
|
|
133
|
-
* @param {string=} params.
|
|
134
|
-
* @param {string=} params.
|
|
135
|
-
* @param {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
168
|
-
|
|
169
|
-
this.
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
174
|
-
this.
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.keyword = keyword
|
|
190
|
-
this.
|
|
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
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
const
|
|
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
|
-
this.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
this.side.
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
current
|
|
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
|
-
const
|
|
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
|
-
const
|
|
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
|
-
this.
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
this._closeSignal =
|
|
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
|
-
dom.utils.
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
* @
|
|
590
|
-
* @
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
const
|
|
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
|
-
<div class="se-browser-
|
|
624
|
-
<div class="se-
|
|
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
|
-
const
|
|
656
|
-
const
|
|
657
|
-
const
|
|
658
|
-
const
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
|
|
1
|
+
import CoreInjector from '../editorInjector/_core';
|
|
2
|
+
import { dom, keyCodeMap } from '../helper';
|
|
3
|
+
import { _w } from '../helper/env';
|
|
4
|
+
import ApiManager from './ApiManager';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} BrowserFile
|
|
8
|
+
* @property {string} [src=""] - Source url
|
|
9
|
+
* @property {string} [name=""] - File name | Folder name
|
|
10
|
+
* @property {string=} thumbnail - Thumbnail url
|
|
11
|
+
* @property {string=} alt - Image alt
|
|
12
|
+
* @property {Array<string>|string=} tag - Tag name list
|
|
13
|
+
* @property {string=} type - Type (image, video, audio, etc.)
|
|
14
|
+
* @property {string=} frame - Frame name (iframe, video, etc.)
|
|
15
|
+
* @property {BrowserFile | string=} _data - The folder's contents or an API URL.
|
|
16
|
+
* @property {boolean=} default - Whether this folder is the default selection.
|
|
17
|
+
* @property {Object<string, *>=} meta - Metadata
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef BrowserParams
|
|
22
|
+
* @property {string} title - File browser window title. Required. Can be overridden in browser.
|
|
23
|
+
* @property {string=} className - Class name of the file browser. Optional. Default: ''.
|
|
24
|
+
* @property {Object<string, *>|Array<*>=} data - direct data without server calls
|
|
25
|
+
* @property {string=} url - File server url. Required. Can be overridden in browser.
|
|
26
|
+
* @property {Object<string, string>=} headers - File server http header. Required. Can be overridden in browser.
|
|
27
|
+
* @property {(target: Node) => void} selectorHandler - Function that actions when an item is clicked. Required. Can be overridden in browser.
|
|
28
|
+
* @property {boolean=} useSearch - Whether to use the search function. Optional. Default: true.
|
|
29
|
+
* @property {string=} searchUrl - File server search url. Optional. Can be overridden in browser.
|
|
30
|
+
* @property {Object<string, string>=} searchUrlHeader - File server search http header. Optional. Can be overridden in browser.
|
|
31
|
+
* @property {string=} listClass - Class name of list div. Required. Can be overridden in browser.
|
|
32
|
+
* @property {(item: BrowserFile) => string=} drawItemHandler - Function that defines the HTML of a file item. Required. Can be overridden in browser.
|
|
33
|
+
* @property {Array<*>=} props - "props" argument to "drawItemHandler" function. Optional. Can be overridden in browser.
|
|
34
|
+
* @property {number=} columnSize - Number of "div.se-file-item-column" to be created. Optional. Can be overridden in browser. Default: 4.
|
|
35
|
+
* @property {((item: BrowserFile) => string)=} thumbnail - Default thumbnail
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @class
|
|
40
|
+
* @description File browser plugin
|
|
41
|
+
*/
|
|
42
|
+
class Browser extends CoreInjector {
|
|
43
|
+
/**
|
|
44
|
+
* @constructor
|
|
45
|
+
* @param {*} inst The instance object that called the constructor.
|
|
46
|
+
* @param {BrowserParams} params Browser options
|
|
47
|
+
*/
|
|
48
|
+
constructor(inst, params) {
|
|
49
|
+
super(inst.editor);
|
|
50
|
+
|
|
51
|
+
// create HTML
|
|
52
|
+
this.useSearch = params.useSearch ?? true;
|
|
53
|
+
const browserFrame = dom.utils.createElement('DIV', { class: 'se-browser sun-editor-common' + (params.className ? ` ${params.className}` : '') });
|
|
54
|
+
const contentHTML = CreateHTMLInfos(inst.editor, this.useSearch);
|
|
55
|
+
const content = contentHTML.html;
|
|
56
|
+
|
|
57
|
+
// members
|
|
58
|
+
this.kind = inst.constructor.key || inst.constructor.name;
|
|
59
|
+
this.inst = inst;
|
|
60
|
+
this.area = browserFrame;
|
|
61
|
+
this.header = contentHTML.header;
|
|
62
|
+
this.titleArea = contentHTML.titleArea;
|
|
63
|
+
this.tagArea = contentHTML.tagArea;
|
|
64
|
+
this.body = contentHTML.body;
|
|
65
|
+
this.list = contentHTML.list;
|
|
66
|
+
this.side = contentHTML.side;
|
|
67
|
+
this.wrapper = contentHTML.wrapper;
|
|
68
|
+
this._loading = contentHTML._loading;
|
|
69
|
+
|
|
70
|
+
this.title = params.title;
|
|
71
|
+
this.listClass = params.listClass || 'se-preview-list';
|
|
72
|
+
this.directData = params.data;
|
|
73
|
+
this.url = params.url;
|
|
74
|
+
this.urlHeader = params.headers;
|
|
75
|
+
this.searchUrl = params.searchUrl;
|
|
76
|
+
this.searchUrlHeader = params.searchUrlHeader;
|
|
77
|
+
this.drawItemHandler = (params.drawItemHandler || DrawItems).bind({ thumbnail: params.thumbnail, props: params.props || [] });
|
|
78
|
+
this.selectorHandler = params.selectorHandler;
|
|
79
|
+
this.columnSize = params.columnSize || 4;
|
|
80
|
+
this.folderDefaultPath = '';
|
|
81
|
+
this.closeArrow = this.icons.menu_arrow_right;
|
|
82
|
+
this.openArrow = this.icons.menu_arrow_down;
|
|
83
|
+
this.icon_folder = this.icons.side_menu_folder_item;
|
|
84
|
+
this.icon_folder_item = this.icons.side_menu_folder;
|
|
85
|
+
this.icon_item = this.icons.side_menu_item;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @type {Array<BrowserFile>}
|
|
89
|
+
*/
|
|
90
|
+
this.items = [];
|
|
91
|
+
/**
|
|
92
|
+
* @type {Object<string, {name: string, meta: Object<string, *>}>}
|
|
93
|
+
*/
|
|
94
|
+
this.folders = {};
|
|
95
|
+
/**
|
|
96
|
+
* @type {Object<string, {key?: string, name?: string, children?: *}>}
|
|
97
|
+
*/
|
|
98
|
+
this.tree = {};
|
|
99
|
+
/**
|
|
100
|
+
* @type {BrowserFile}
|
|
101
|
+
*/
|
|
102
|
+
this.data = {};
|
|
103
|
+
this.selectedTags = [];
|
|
104
|
+
this.keyword = '';
|
|
105
|
+
this.sideInner = null;
|
|
106
|
+
this._closeSignal = false;
|
|
107
|
+
this._bindClose = null;
|
|
108
|
+
this.__globalEventHandler = (e) => {
|
|
109
|
+
if (!keyCodeMap.isEsc(e.code)) return;
|
|
110
|
+
this.close();
|
|
111
|
+
};
|
|
112
|
+
// api manager
|
|
113
|
+
this.apiManager = new ApiManager(this, { method: 'GET' });
|
|
114
|
+
|
|
115
|
+
// init
|
|
116
|
+
browserFrame.appendChild(dom.utils.createElement('DIV', { class: 'se-browser-back' }));
|
|
117
|
+
browserFrame.appendChild(content);
|
|
118
|
+
this.carrierWrapper.appendChild(browserFrame);
|
|
119
|
+
|
|
120
|
+
this.eventManager.addEvent(this.tagArea, 'click', this.#OnClickTag.bind(this));
|
|
121
|
+
this.eventManager.addEvent(this.list, 'click', this.#OnClickFile.bind(this));
|
|
122
|
+
this.eventManager.addEvent(this.side, 'click', this.#OnClickSide.bind(this));
|
|
123
|
+
this.eventManager.addEvent(content, 'mousedown', this.#OnMouseDown_browser.bind(this));
|
|
124
|
+
this.eventManager.addEvent(content, 'click', this.#OnClick_browser.bind(this));
|
|
125
|
+
this.eventManager.addEvent(browserFrame.querySelector('form.se-browser-search-form'), 'submit', this.#Search.bind(this));
|
|
126
|
+
this.eventManager.addEvent((this.sideOpenBtn = /** @type {HTMLButtonElement} */ (browserFrame.querySelector('.se-side-open-btn'))), 'click', this.#SideOpen.bind(this));
|
|
127
|
+
this.eventManager.addEvent([this.header, browserFrame.querySelector('.se-browser-main')], 'mousedown', this.#SideClose.bind(this));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @description Open a file browser plugin
|
|
132
|
+
* @param {Object} [params={}]
|
|
133
|
+
* @param {string=} params.listClass - Class name of list div. If not, use "this.listClass".
|
|
134
|
+
* @param {string=} params.title - File browser window title. If not, use "this.title".
|
|
135
|
+
* @param {string=} params.url - File server url. If not, use "this.url".
|
|
136
|
+
* @param {Object<string, string>=} params.urlHeader - File server http header. If not, use "this.urlHeader".
|
|
137
|
+
*/
|
|
138
|
+
open(params) {
|
|
139
|
+
if (!params) params = {};
|
|
140
|
+
this.__addGlobalEvent();
|
|
141
|
+
|
|
142
|
+
const listClassName = params.listClass || this.listClass;
|
|
143
|
+
if (!dom.utils.hasClass(this.list, listClassName)) {
|
|
144
|
+
this.list.className = 'se-browser-list ' + listClassName;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.titleArea.textContent = params.title || this.title;
|
|
148
|
+
this.area.style.display = 'block';
|
|
149
|
+
this.editor.opendBrowser = this;
|
|
150
|
+
this.closeArrow = this.options.get('_rtl') ? this.icons.menu_arrow_left : this.icons.menu_arrow_right;
|
|
151
|
+
|
|
152
|
+
if (this.directData) {
|
|
153
|
+
this.__drowItems(this.directData);
|
|
154
|
+
} else {
|
|
155
|
+
this._drawFileList(params.url || this.url, params.urlHeader || this.urlHeader, false);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.body.style.maxHeight = dom.utils.getClientSize().h - (this.editor.offset.getGlobal(this.body).top - _w.scrollY) - 20 + 'px';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @description Close a browser plugin
|
|
163
|
+
* - The plugin's "init" method is called.
|
|
164
|
+
*/
|
|
165
|
+
close() {
|
|
166
|
+
this.__removeGlobalEvent();
|
|
167
|
+
this.apiManager.cancel();
|
|
168
|
+
|
|
169
|
+
this.area.style.display = 'none';
|
|
170
|
+
this.selectedTags = [];
|
|
171
|
+
this.items = [];
|
|
172
|
+
this.folders = {};
|
|
173
|
+
this.tree = {};
|
|
174
|
+
this.data = {};
|
|
175
|
+
this.keyword = '';
|
|
176
|
+
this.list.innerHTML = this.tagArea.innerHTML = this.titleArea.textContent = '';
|
|
177
|
+
this.editor.opendBrowser = null;
|
|
178
|
+
this.sideInner = null;
|
|
179
|
+
|
|
180
|
+
if (typeof this.inst.init === 'function') this.inst.init();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @description Search files
|
|
185
|
+
* @param {string} keyword - Search keyword
|
|
186
|
+
*/
|
|
187
|
+
search(keyword) {
|
|
188
|
+
if (this.searchUrl) {
|
|
189
|
+
this.keyword = keyword;
|
|
190
|
+
this._drawFileList(this.searchUrl + '?keyword=' + keyword, this.searchUrlHeader, false);
|
|
191
|
+
} else {
|
|
192
|
+
this.keyword = keyword.toLowerCase();
|
|
193
|
+
this._drawListItem(this.items, false);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @description Filter items by tag
|
|
199
|
+
* @param {Array<BrowserFile>} items - Items to filter
|
|
200
|
+
* @returns {Array<BrowserFile>}
|
|
201
|
+
*/
|
|
202
|
+
tagfilter(items) {
|
|
203
|
+
const selectedTags = this.selectedTags;
|
|
204
|
+
return selectedTags.length === 0 ? items : items.filter((item) => !Array.isArray(item.tag) || item.tag.some((tag) => selectedTags.includes(tag)));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @description Show file browser loading box
|
|
209
|
+
*/
|
|
210
|
+
showBrowserLoading() {
|
|
211
|
+
this._loading.style.display = 'block';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @description Close file browser loading box
|
|
216
|
+
*/
|
|
217
|
+
closeBrowserLoading() {
|
|
218
|
+
this._loading.style.display = 'none';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @private
|
|
223
|
+
* @description Fetches the file list from the server.
|
|
224
|
+
* @param {string} url - The file server URL.
|
|
225
|
+
* @param {Object<string, string>} urlHeader - The HTTP headers for the request.
|
|
226
|
+
* @param {boolean} pageLoading - Indicates if this is a paginated request.
|
|
227
|
+
*/
|
|
228
|
+
_drawFileList(url, urlHeader, pageLoading) {
|
|
229
|
+
this.apiManager.call({ method: 'GET', url, headers: urlHeader, callBack: this.#CallBackGet.bind(this), errorCallBack: this.#CallBackError.bind(this) });
|
|
230
|
+
if (!pageLoading) {
|
|
231
|
+
this.sideOpenBtn.style.display = 'none';
|
|
232
|
+
this.showBrowserLoading();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @private
|
|
238
|
+
* @description Updates the displayed list of file items.
|
|
239
|
+
* @param {Array<BrowserFile>} items - The file items to display.
|
|
240
|
+
* @param {boolean} update - Whether to update the tags.
|
|
241
|
+
*/
|
|
242
|
+
_drawListItem(items, update) {
|
|
243
|
+
const keyword = this.keyword;
|
|
244
|
+
items = this.tagfilter(items).filter((item) => item.name.toLowerCase().indexOf(keyword) > -1);
|
|
245
|
+
|
|
246
|
+
const _tags = [];
|
|
247
|
+
const len = items.length;
|
|
248
|
+
const columnSize = this.columnSize;
|
|
249
|
+
const splitSize = columnSize <= 1 ? 1 : Math.round(len / columnSize) || 1;
|
|
250
|
+
const drawItemHandler = this.drawItemHandler;
|
|
251
|
+
|
|
252
|
+
let tagsHTML = '';
|
|
253
|
+
let listHTML = '<div class="se-file-item-column">';
|
|
254
|
+
let columns = 1;
|
|
255
|
+
for (let i = 0, item, tags; i < len; i++) {
|
|
256
|
+
item = items[i];
|
|
257
|
+
tags = !item.tag ? [] : typeof item.tag === 'string' ? item.tag.split(',') : item.tag;
|
|
258
|
+
tags = item.tag = tags.map((v) => v.trim());
|
|
259
|
+
listHTML += drawItemHandler(item);
|
|
260
|
+
|
|
261
|
+
if ((i + 1) % splitSize === 0 && columns < columnSize && i + 1 < len) {
|
|
262
|
+
columns++;
|
|
263
|
+
listHTML += '</div><div class="se-file-item-column">';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (update && tags.length > 0) {
|
|
267
|
+
for (let t = 0, tLen = tags.length, tag; t < tLen; t++) {
|
|
268
|
+
tag = tags[t];
|
|
269
|
+
if (tag && !_tags.includes(tag)) {
|
|
270
|
+
_tags.push(tag);
|
|
271
|
+
tagsHTML += `<a title="${tag}" aria-label="${tag}">${tag}</a>`;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
listHTML += '</div>';
|
|
277
|
+
|
|
278
|
+
this.list.innerHTML = listHTML;
|
|
279
|
+
|
|
280
|
+
if (update) {
|
|
281
|
+
this.items = items;
|
|
282
|
+
this.tagArea.innerHTML = tagsHTML;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @private
|
|
288
|
+
* @description Adds a global event listener for closing the browser.
|
|
289
|
+
*/
|
|
290
|
+
__addGlobalEvent() {
|
|
291
|
+
this.__removeGlobalEvent();
|
|
292
|
+
this._bindClose = this.eventManager.addGlobalEvent('keydown', this.__globalEventHandler, true);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @private
|
|
297
|
+
* @description Removes the global event listener for closing the browser.
|
|
298
|
+
*/
|
|
299
|
+
__removeGlobalEvent() {
|
|
300
|
+
if (this._bindClose) this._bindClose = this.eventManager.removeGlobalEvent(this._bindClose);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @private
|
|
305
|
+
* @description Renders the file items or folder structure from data.
|
|
306
|
+
* @param {BrowserFile[]|BrowserFile} data - The data representing the file structure.
|
|
307
|
+
* @returns {boolean} True if rendering was successful, false otherwise.
|
|
308
|
+
*/
|
|
309
|
+
__drowItems(data) {
|
|
310
|
+
if (Array.isArray(data)) {
|
|
311
|
+
if (data.length > 0) {
|
|
312
|
+
this._drawListItem(data, true);
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
} else if (typeof data === 'object') {
|
|
316
|
+
this.sideOpenBtn.style.display = '';
|
|
317
|
+
this.__parseFolderData(data);
|
|
318
|
+
|
|
319
|
+
this.side.innerHTML = '';
|
|
320
|
+
const sideInner = (this.sideInner = dom.utils.createElement('div', null));
|
|
321
|
+
this.__createFolderList(this.tree, sideInner);
|
|
322
|
+
this.side.appendChild(sideInner);
|
|
323
|
+
|
|
324
|
+
if (this.folderDefaultPath) {
|
|
325
|
+
const openFolder = /** @type {HTMLButtonElement} */ (sideInner.querySelector(`[data-command="${this.folderDefaultPath}"]`));
|
|
326
|
+
openFolder.click();
|
|
327
|
+
if (this.folderDefaultPath.includes('/')) {
|
|
328
|
+
dom.utils.removeClass(openFolder.parentElement, 'se-menu-hidden');
|
|
329
|
+
openFolder.parentElement.previousElementSibling.querySelector('button').innerHTML = this.openArrow;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @private
|
|
340
|
+
* @description Parses folder data into a structured format.
|
|
341
|
+
* @param {BrowserFile} data - The folder data.
|
|
342
|
+
* @param {string} [path] - The current path in the folder hierarchy.
|
|
343
|
+
*/
|
|
344
|
+
__parseFolderData(data, path) {
|
|
345
|
+
let current = this.tree;
|
|
346
|
+
|
|
347
|
+
// _data
|
|
348
|
+
if (data._data) {
|
|
349
|
+
this.data[path] = data._data;
|
|
350
|
+
if (!this.folderDefaultPath || data.default) {
|
|
351
|
+
this.folderDefaultPath = path;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const parts = path.split('/');
|
|
355
|
+
const len = parts.length - 1;
|
|
356
|
+
parts.forEach((part, index) => {
|
|
357
|
+
if (!current[part]) {
|
|
358
|
+
current[part] = { children: {} };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (index === len) {
|
|
362
|
+
current[part].key = path;
|
|
363
|
+
current[part].name = this.folders[path].name;
|
|
364
|
+
} else {
|
|
365
|
+
current = current[part].children;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
} else if (path) {
|
|
369
|
+
current[path] = { name: this.folders[path].name, children: {} };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// create folders, file path
|
|
373
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
374
|
+
if (key === '_data' || !value || typeof value !== 'object') return;
|
|
375
|
+
|
|
376
|
+
const v = /** @type {BrowserFile} */ (value);
|
|
377
|
+
const currentPath = path ? `${path}/${key}` : key;
|
|
378
|
+
|
|
379
|
+
this.folders[currentPath] = {
|
|
380
|
+
name: v.name || key,
|
|
381
|
+
meta: v.meta || {}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
this.__parseFolderData(v, currentPath);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @private
|
|
390
|
+
* @description Creates a nested folder list from parsed data.
|
|
391
|
+
* @param {BrowserFile[]|BrowserFile} folderData - The structured folder data.
|
|
392
|
+
* @param {HTMLElement} parentElement - The parent element to append folder structure to.
|
|
393
|
+
*/
|
|
394
|
+
__createFolderList(folderData, parentElement) {
|
|
395
|
+
for (const key in folderData) {
|
|
396
|
+
const item = folderData[key];
|
|
397
|
+
if (!item) continue;
|
|
398
|
+
|
|
399
|
+
if (Object.keys(item.children).length > 0) {
|
|
400
|
+
const folderLabel = dom.utils.createElement(
|
|
401
|
+
'div',
|
|
402
|
+
item.key ? { 'data-command': item.key, 'aria-label': item.name } : null,
|
|
403
|
+
`<span class="se-menu-icon">${item.key ? this.icon_folder : this.icon_folder_item}</span><span>${item.name}</span>`
|
|
404
|
+
);
|
|
405
|
+
const folderDiv = dom.utils.createElement('div', { class: 'se-menu-folder' }, folderLabel);
|
|
406
|
+
|
|
407
|
+
folderLabel.insertBefore(dom.utils.createElement('button', null, this.closeArrow), folderLabel.firstElementChild);
|
|
408
|
+
const childContainer = document.createElement('div');
|
|
409
|
+
dom.utils.addClass(childContainer, 'se-menu-child|se-menu-hidden');
|
|
410
|
+
this.__createFolderList(item.children, childContainer);
|
|
411
|
+
folderDiv.appendChild(childContainer);
|
|
412
|
+
|
|
413
|
+
parentElement.appendChild(folderDiv);
|
|
414
|
+
} else {
|
|
415
|
+
const folderLabel = dom.utils.createElement('div', { 'data-command': item.key, 'aria-label': item.name, class: 'se-menu-folder-item' }, `<span class="se-menu-icon">${this.icon_item}</span><span>${item.name}</span>`);
|
|
416
|
+
if (parentElement === this.sideInner) {
|
|
417
|
+
const folderDiv = dom.utils.createElement('div', { class: 'se-menu-folder' }, folderLabel);
|
|
418
|
+
parentElement.appendChild(folderDiv);
|
|
419
|
+
} else {
|
|
420
|
+
parentElement.appendChild(folderLabel);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* @param {XMLHttpRequest} xmlHttp - XMLHttpRequest object.
|
|
428
|
+
*/
|
|
429
|
+
#CallBackGet(xmlHttp) {
|
|
430
|
+
try {
|
|
431
|
+
const res = JSON.parse(xmlHttp.responseText);
|
|
432
|
+
const data = res.result;
|
|
433
|
+
if (this.__drowItems(data)) return;
|
|
434
|
+
|
|
435
|
+
if (res.nullMessage) {
|
|
436
|
+
this.list.innerHTML = res.nullMessage;
|
|
437
|
+
}
|
|
438
|
+
} catch (e) {
|
|
439
|
+
throw Error(`[SUNEDITOR.browser.drawList.fail] cause: "${e.message}"`);
|
|
440
|
+
} finally {
|
|
441
|
+
this.closeBrowserLoading();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* @param {*} res - response data.
|
|
447
|
+
* @param {XMLHttpRequest} xmlHttp - XMLHttpRequest object.
|
|
448
|
+
*/
|
|
449
|
+
#CallBackError(res, xmlHttp) {
|
|
450
|
+
this.closeBrowserLoading();
|
|
451
|
+
throw Error(`[SUNEDITOR.browser.get.serverException] status: ${xmlHttp.status}, response: ${res.errorMessage || xmlHttp.responseText}`);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @param {MouseEvent} e - Event object
|
|
456
|
+
*/
|
|
457
|
+
#OnClickTag(e) {
|
|
458
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
459
|
+
if (!dom.check.isAnchor(eventTarget)) return;
|
|
460
|
+
|
|
461
|
+
const tagName = eventTarget.textContent;
|
|
462
|
+
const selectTag = this.tagArea.querySelector('a[title="' + tagName + '"]');
|
|
463
|
+
const sTagIndex = this.selectedTags.indexOf(tagName);
|
|
464
|
+
|
|
465
|
+
if (sTagIndex > -1) {
|
|
466
|
+
this.selectedTags.splice(sTagIndex, 1);
|
|
467
|
+
dom.utils.removeClass(selectTag, 'on');
|
|
468
|
+
} else {
|
|
469
|
+
this.selectedTags.push(tagName);
|
|
470
|
+
dom.utils.addClass(selectTag, 'on');
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
this._drawListItem(this.items, false);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @param {MouseEvent} e - Event object
|
|
478
|
+
*/
|
|
479
|
+
#OnClickFile(e) {
|
|
480
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
481
|
+
|
|
482
|
+
e.preventDefault();
|
|
483
|
+
e.stopPropagation();
|
|
484
|
+
|
|
485
|
+
if (eventTarget === this.list) return;
|
|
486
|
+
|
|
487
|
+
const target = dom.query.getCommandTarget(eventTarget);
|
|
488
|
+
if (!target) return;
|
|
489
|
+
|
|
490
|
+
this.close();
|
|
491
|
+
this.selectorHandler(target);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* @param {MouseEvent} e - Event object
|
|
496
|
+
*/
|
|
497
|
+
#OnClickSide(e) {
|
|
498
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
499
|
+
e.stopPropagation();
|
|
500
|
+
|
|
501
|
+
if (/^button$/i.test(eventTarget.nodeName)) {
|
|
502
|
+
const childContainer = eventTarget.parentElement.parentElement.querySelector('.se-menu-child');
|
|
503
|
+
if (dom.utils.hasClass(childContainer, 'se-menu-hidden')) {
|
|
504
|
+
dom.utils.removeClass(childContainer, 'se-menu-hidden');
|
|
505
|
+
eventTarget.innerHTML = this.openArrow;
|
|
506
|
+
} else {
|
|
507
|
+
dom.utils.addClass(childContainer, 'se-menu-hidden');
|
|
508
|
+
eventTarget.innerHTML = this.closeArrow;
|
|
509
|
+
}
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const cmdTarget = dom.query.getCommandTarget(eventTarget);
|
|
514
|
+
if (!cmdTarget || dom.utils.hasClass(cmdTarget, 'active')) return;
|
|
515
|
+
|
|
516
|
+
const data = this.data[cmdTarget.getAttribute('data-command')];
|
|
517
|
+
|
|
518
|
+
dom.utils.removeClass(this.side.querySelectorAll('.active'), 'active');
|
|
519
|
+
dom.utils.addClass([cmdTarget, dom.query.getParentElement(cmdTarget, '.se-menu-folder')], 'active');
|
|
520
|
+
this.tagArea.innerHTML = '';
|
|
521
|
+
|
|
522
|
+
if (typeof data === 'string') {
|
|
523
|
+
this._drawFileList(data, this.urlHeader, true);
|
|
524
|
+
} else {
|
|
525
|
+
this._drawListItem(data, false);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* @param {MouseEvent} e - Event object
|
|
531
|
+
*/
|
|
532
|
+
#OnMouseDown_browser(e) {
|
|
533
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
534
|
+
if (/se-browser-inner/.test(eventTarget.className)) {
|
|
535
|
+
this._closeSignal = true;
|
|
536
|
+
} else {
|
|
537
|
+
this._closeSignal = false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @param {MouseEvent} e - Event object
|
|
543
|
+
*/
|
|
544
|
+
#OnClick_browser(e) {
|
|
545
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
546
|
+
e.stopPropagation();
|
|
547
|
+
|
|
548
|
+
if (/close/.test(eventTarget.getAttribute('data-command')) || this._closeSignal) {
|
|
549
|
+
this.close();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* @param {SubmitEvent} e - Event object
|
|
555
|
+
*/
|
|
556
|
+
#Search(e) {
|
|
557
|
+
const eventTarget = /** @type {HTMLElement} */ (e.currentTarget);
|
|
558
|
+
e.preventDefault();
|
|
559
|
+
this.search(/** @type {HTMLInputElement} */ (eventTarget.querySelector('input[type="text"]')).value);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @param {MouseEvent} e - Event object
|
|
564
|
+
*/
|
|
565
|
+
#SideOpen(e) {
|
|
566
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
567
|
+
if (dom.utils.hasClass(eventTarget, 'active')) {
|
|
568
|
+
dom.utils.removeClass(this.side, 'se-side-show');
|
|
569
|
+
dom.utils.removeClass(eventTarget, 'active');
|
|
570
|
+
} else {
|
|
571
|
+
dom.utils.addClass(this.side, 'se-side-show');
|
|
572
|
+
dom.utils.addClass(eventTarget, 'active');
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* @param {MouseEvent} e - Event object
|
|
578
|
+
*/
|
|
579
|
+
#SideClose({ target }) {
|
|
580
|
+
if (target === this.sideOpenBtn) return;
|
|
581
|
+
if (dom.utils.hasClass(this.sideOpenBtn, 'active')) {
|
|
582
|
+
dom.utils.removeClass(this.side, 'se-side-show');
|
|
583
|
+
dom.utils.removeClass(this.sideOpenBtn, 'active');
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* @private
|
|
590
|
+
* @param {__se__EditorCore} editor - editor instance
|
|
591
|
+
* @param {boolean} useSearch - Whether to use the search function
|
|
592
|
+
* @returns {{ html: HTMLElement, header: HTMLElement, titleArea: HTMLElement, tagArea: HTMLElement, body: HTMLElement, list: HTMLElement, side: HTMLElement, wrapper: HTMLElement, _loading: HTMLElement }} HTML
|
|
593
|
+
*/
|
|
594
|
+
function CreateHTMLInfos(editor, useSearch) {
|
|
595
|
+
const lang = editor.lang;
|
|
596
|
+
const icons = editor.icons;
|
|
597
|
+
const htmlString = /*html*/ `
|
|
598
|
+
<div class="se-browser-content">
|
|
599
|
+
<div class="se-browser-header">
|
|
600
|
+
<button type="button" data-command="close" class="se-btn se-browser-close" class="close" title="${lang.close}" aria-label="${lang.close}">
|
|
601
|
+
${icons.cancel}
|
|
602
|
+
</button>
|
|
603
|
+
<span class="se-browser-title"></span>
|
|
604
|
+
</div>
|
|
605
|
+
<div class="se-browser-wrapper">
|
|
606
|
+
<div class="se-browser-side"></div>
|
|
607
|
+
<div class="se-browser-main">
|
|
608
|
+
<div class="se-browser-bar">
|
|
609
|
+
<div class="se-browser-search">
|
|
610
|
+
<button class="se-btn se-side-open-btn">${icons.side_menu_hamburger}</button>
|
|
611
|
+
${
|
|
612
|
+
useSearch
|
|
613
|
+
? /*html*/ `
|
|
614
|
+
<form class="se-browser-search-form">
|
|
615
|
+
<input type="text" class="se-input-form" placeholder="${lang.search}" aria-label="${lang.search}">
|
|
616
|
+
<button type="submit" class="se-btn" title="${lang.search}" aria-label="${lang.search}">${icons.search}</button>
|
|
617
|
+
</form>`
|
|
618
|
+
: ''
|
|
619
|
+
}
|
|
620
|
+
</div>
|
|
621
|
+
</div>
|
|
622
|
+
<div class="se-browser-body">
|
|
623
|
+
<div class="se-browser-tags"></div>
|
|
624
|
+
<div class="se-loading-box sun-editor-common"><div class="se-loading-effect"></div></div>
|
|
625
|
+
<div class="se-browser-menus"></div>
|
|
626
|
+
<div class="se-browser-list"></div>
|
|
627
|
+
</div>
|
|
628
|
+
</div>
|
|
629
|
+
</div>
|
|
630
|
+
</div>`;
|
|
631
|
+
|
|
632
|
+
const content = dom.utils.createElement('DIV', { class: 'se-browser-inner' }, htmlString);
|
|
633
|
+
|
|
634
|
+
return {
|
|
635
|
+
html: content,
|
|
636
|
+
header: content.querySelector('.se-browser-header'),
|
|
637
|
+
titleArea: content.querySelector('.se-browser-title'),
|
|
638
|
+
tagArea: content.querySelector('.se-browser-tags'),
|
|
639
|
+
body: content.querySelector('.se-browser-body'),
|
|
640
|
+
list: content.querySelector('.se-browser-list'),
|
|
641
|
+
side: content.querySelector('.se-browser-side'),
|
|
642
|
+
wrapper: content.querySelector('.se-browser-wrapper'),
|
|
643
|
+
_loading: content.querySelector('.se-loading-box')
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @private
|
|
649
|
+
* @this {{ thumbnail: ((...args: *) => *), props: Array<*> }}
|
|
650
|
+
* @description Define the HTML of the item to be put in "div.se-file-item-column".
|
|
651
|
+
* - Format: [ { src: "image src", name: "name(@option)", alt: "image alt(@option)", tag: "tag name(@option)" } ]
|
|
652
|
+
* @param {BrowserFile} item Item of the response data's array
|
|
653
|
+
*/
|
|
654
|
+
function DrawItems(item) {
|
|
655
|
+
const srcName = item.src.split('/').pop();
|
|
656
|
+
const thumbnail = item.thumbnail || '';
|
|
657
|
+
const src = thumbnail || item.src;
|
|
658
|
+
const customProps = this.props?.map((v) => `data-${v}="${item[v]}"`).join(' ') || '';
|
|
659
|
+
const attrs = `data-type="${item.type}" data-command="${item.src}" data-name="${item.name || srcName}" data-thumbnail="${thumbnail}" data-extension="${item.src.split('.').pop()}" ${customProps}`;
|
|
660
|
+
const props = `class="${thumbnail || 'se-browser-empty-image'}" src="${src}" alt="${item.alt || srcName}" ${attrs}`;
|
|
661
|
+
return /*html*/ `
|
|
662
|
+
<div class="se-file-item-img">
|
|
663
|
+
${this.thumbnail && !thumbnail && item.type !== 'image' ? `<div class="se-browser-empty-thumbnail" ${props}>${this.thumbnail(item)}</div>` : `<img class="${thumbnail || 'se-browser-empty-image'}" ${props}>`}
|
|
664
|
+
<div class="se-file-name-image se-file-name-back"></div>
|
|
665
|
+
<div class="se-file-name-image">${item.name || srcName}</div>
|
|
666
|
+
</div>`;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export default Browser;
|