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,620 +1,710 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Selection class
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import CoreInjector from '../../editorInjector/_core';
|
|
6
|
-
import { dom, unicode, env } from '../../helper';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
* @param {
|
|
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
|
-
if (
|
|
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
|
-
selection.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.
|
|
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
|
-
let
|
|
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
|
-
|
|
358
|
-
if (ref
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
const
|
|
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
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Selection class
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import CoreInjector from '../../editorInjector/_core';
|
|
6
|
+
import { dom, unicode, env, numbers } from '../../helper';
|
|
7
|
+
const { _w, isTouchDevice } = env;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Omit<Selection_ & Partial<__se__EditorInjector>, 'selection'>} SelectionThis
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('./offset').RectsInfo} RectsInfo_selection
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @constructor
|
|
19
|
+
* @this {SelectionThis}
|
|
20
|
+
* @description Selection, Range related class
|
|
21
|
+
* @param {__se__EditorCore} editor - The root editor instance
|
|
22
|
+
*/
|
|
23
|
+
function Selection_(editor) {
|
|
24
|
+
CoreInjector.call(this, editor);
|
|
25
|
+
|
|
26
|
+
// members
|
|
27
|
+
/** @type {Range} */
|
|
28
|
+
this.range = null;
|
|
29
|
+
/** @type {HTMLElement|Text} */
|
|
30
|
+
this.selectionNode = null;
|
|
31
|
+
this.__iframeFocus = false;
|
|
32
|
+
|
|
33
|
+
_w.setTimeout(() => {
|
|
34
|
+
this.__hasScrollParents = this.eventManager.scrollparents.length > 0;
|
|
35
|
+
this._scrollMargin = (numbers.get(_w.getComputedStyle(editor.frameContext.get('wysiwyg')).scrollMargin, 0) || 40) + numbers.get(_w.getComputedStyle(editor.frameContext.get('wrapper')).paddingBottom, 0);
|
|
36
|
+
}, 1000);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Selection_.prototype = {
|
|
40
|
+
/**
|
|
41
|
+
* @this {SelectionThis}
|
|
42
|
+
* @description Get window selection obejct
|
|
43
|
+
* @returns {Selection}
|
|
44
|
+
*/
|
|
45
|
+
get() {
|
|
46
|
+
let selection = null;
|
|
47
|
+
|
|
48
|
+
if (typeof this.editor._shadowRoot?.getSelection === 'function') {
|
|
49
|
+
selection = this.editor._shadowRoot.getSelection();
|
|
50
|
+
} else {
|
|
51
|
+
selection = this.editor.frameContext.get('_ww').getSelection();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!selection) return null;
|
|
55
|
+
if (!this.status._range && !this.editor.frameContext.get('wysiwyg').contains(selection.focusNode)) {
|
|
56
|
+
selection.removeAllRanges();
|
|
57
|
+
selection.addRange(this._createDefaultRange());
|
|
58
|
+
}
|
|
59
|
+
return selection;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @this {SelectionThis}
|
|
64
|
+
* @description Check if the range object is valid
|
|
65
|
+
* @param {*} range Range object
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
isRange(range) {
|
|
69
|
+
// return /Range/.test(Object.prototype.toString.call(range?.__proto__));
|
|
70
|
+
return this.instanceCheck.isRange(range);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @this {SelectionThis}
|
|
75
|
+
* @description Get current editor's range object
|
|
76
|
+
* @returns {Range}
|
|
77
|
+
*/
|
|
78
|
+
getRange() {
|
|
79
|
+
const range = this.status._range || this._createDefaultRange();
|
|
80
|
+
const selection = this.get();
|
|
81
|
+
if (range.collapsed === selection.isCollapsed || !this.editor.frameContext.get('wysiwyg').contains(selection.focusNode)) {
|
|
82
|
+
if (this.component.is(range.startContainer)) {
|
|
83
|
+
const compInfo = this.component.get(range.startContainer);
|
|
84
|
+
const container = compInfo?.container;
|
|
85
|
+
if (!container) return range;
|
|
86
|
+
return this.setRange(container, 0, container, 1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return range;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (selection.rangeCount > 0) {
|
|
93
|
+
this.status._range = selection.getRangeAt(0);
|
|
94
|
+
return this.status._range;
|
|
95
|
+
} else {
|
|
96
|
+
const sc = selection.anchorNode,
|
|
97
|
+
ec = selection.focusNode,
|
|
98
|
+
so = selection.anchorOffset,
|
|
99
|
+
eo = selection.focusOffset;
|
|
100
|
+
const compareValue = dom.query.compareElements(sc, ec);
|
|
101
|
+
const rightDir = compareValue.ancestor && (compareValue.result === 0 ? so <= eo : compareValue.result > 1 ? true : false);
|
|
102
|
+
return this.setRange(rightDir ? sc : ec, rightDir ? so : eo, rightDir ? ec : sc, rightDir ? eo : so);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @this {SelectionThis}
|
|
108
|
+
* @description Set current editor's range object and return.
|
|
109
|
+
* @param {Node|Range} startCon Range object or The startContainer property of the selection object
|
|
110
|
+
* @param {number} [startOff] The startOffset property of the selection object.
|
|
111
|
+
* @param {Node} [endCon] The endContainer property of the selection object.
|
|
112
|
+
* @param {number} [endOff] The endOffset property of the selection object.
|
|
113
|
+
* @returns {Range}
|
|
114
|
+
*/
|
|
115
|
+
setRange(startCon, startOff, endCon, endOff) {
|
|
116
|
+
/** @type {Node} */
|
|
117
|
+
let sc;
|
|
118
|
+
/** @type {number} */
|
|
119
|
+
let so;
|
|
120
|
+
/** @type {Node} */
|
|
121
|
+
let ec;
|
|
122
|
+
/** @type {number} */
|
|
123
|
+
let eo;
|
|
124
|
+
|
|
125
|
+
if (this.isRange(startCon)) {
|
|
126
|
+
const r = /** @type {Range} */ (startCon);
|
|
127
|
+
sc = r.startContainer;
|
|
128
|
+
so = r.startOffset;
|
|
129
|
+
ec = r.endContainer;
|
|
130
|
+
eo = r.endOffset;
|
|
131
|
+
} else {
|
|
132
|
+
sc = /** @type {Node} */ (startCon);
|
|
133
|
+
so = startOff;
|
|
134
|
+
ec = endCon;
|
|
135
|
+
eo = endOff;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!sc || !ec) return;
|
|
139
|
+
if ((dom.check.isBreak(sc) || sc.nodeType === 3) && so > sc.textContent.length) so = sc.textContent.length;
|
|
140
|
+
if ((dom.check.isBreak(ec) || ec.nodeType === 3) && eo > ec.textContent.length) eo = ec.textContent.length;
|
|
141
|
+
if (this.format.isLine(sc)) {
|
|
142
|
+
sc = sc.childNodes[so > 0 ? sc.childNodes.length - 1 : 0] || sc;
|
|
143
|
+
so = so > 0 ? (sc.nodeType === 1 && !dom.check.isBreak(sc) ? 1 : sc.textContent ? sc.textContent.length : 0) : 0;
|
|
144
|
+
}
|
|
145
|
+
if (this.format.isLine(ec)) {
|
|
146
|
+
ec = ec.childNodes[eo > 0 ? ec.childNodes.length - 1 : 0] || ec;
|
|
147
|
+
eo = eo > 0 ? (ec.nodeType === 1 && !dom.check.isBreak(ec) ? 1 : ec.textContent ? ec.textContent.length : 0) : 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const range = this.editor.frameContext.get('_wd').createRange();
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
range.setStart(sc, so);
|
|
154
|
+
range.setEnd(ec, eo);
|
|
155
|
+
this.status.hasFocus = true;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.warn('[SUNEDITOR.selection.focus.warn]', error.message);
|
|
158
|
+
this.editor._nativeFocus();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const selection = this.get();
|
|
163
|
+
|
|
164
|
+
if (selection.removeAllRanges) {
|
|
165
|
+
selection.removeAllRanges();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
selection.addRange(range);
|
|
169
|
+
this.status._range = range;
|
|
170
|
+
this._rangeInfo(range, this.get());
|
|
171
|
+
|
|
172
|
+
if (this.editor.frameOptions.get('iframe')) this.__focus();
|
|
173
|
+
|
|
174
|
+
return range;
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @this {SelectionThis}
|
|
179
|
+
* @description Remove range object and button effect
|
|
180
|
+
*/
|
|
181
|
+
removeRange() {
|
|
182
|
+
this.status._range = null;
|
|
183
|
+
this.selectionNode = null;
|
|
184
|
+
this.editor.effectNode = null;
|
|
185
|
+
if (this.status.hasFocus) this.get().removeAllRanges();
|
|
186
|
+
this.eventManager._setKeyEffect([]);
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @this {SelectionThis}
|
|
191
|
+
* @description Returns the range (container and offset) near the given target node.
|
|
192
|
+
* - If the target node has a next sibling, it returns the next sibling with an offset of 0.
|
|
193
|
+
* - If there is no next sibling but a previous sibling exists, it returns the previous sibling with an offset of 1.
|
|
194
|
+
* @param {Node} target Target node whose neighboring range is to be determined.
|
|
195
|
+
* @returns {{container: Node, offset: number}|null} An object containing the nearest container node and its offset.
|
|
196
|
+
*/
|
|
197
|
+
getNearRange(target) {
|
|
198
|
+
const next = target.nextSibling;
|
|
199
|
+
const prev = target.previousSibling;
|
|
200
|
+
if (next) {
|
|
201
|
+
return {
|
|
202
|
+
container: next,
|
|
203
|
+
offset: 0
|
|
204
|
+
};
|
|
205
|
+
} else if (prev) {
|
|
206
|
+
return {
|
|
207
|
+
container: prev,
|
|
208
|
+
offset: 1
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return null;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @this {SelectionThis}
|
|
217
|
+
* @description If the "range" object is a non-editable area, add a line at the top of the editor and update the "range" object.
|
|
218
|
+
* @param {Range} range core.getRange()
|
|
219
|
+
* @param {?Node=} container If there is "container" argument, it creates a line in front of the container.
|
|
220
|
+
* @returns {Range} a new "range" or argument "range".
|
|
221
|
+
*/
|
|
222
|
+
getRangeAndAddLine(range, container) {
|
|
223
|
+
if (this._isNone(range)) {
|
|
224
|
+
const parent = container?.parentElement || this.editor.frameContext.get('wysiwyg');
|
|
225
|
+
const op = dom.utils.createElement(this.options.get('defaultLine'), null, '<br>');
|
|
226
|
+
parent.insertBefore(op, container && container !== parent ? (!(/** @type {HTMLElement} */ (container).previousElementSibling) ? container : /** @type {HTMLElement} */ (container).nextElementSibling) : parent.firstElementChild);
|
|
227
|
+
this.setRange(op.firstElementChild, 0, op.firstElementChild, 1);
|
|
228
|
+
range = this.status._range;
|
|
229
|
+
}
|
|
230
|
+
return range;
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @this {SelectionThis}
|
|
235
|
+
* @description Get current select node
|
|
236
|
+
* @returns {HTMLElement|Text}
|
|
237
|
+
*/
|
|
238
|
+
getNode() {
|
|
239
|
+
if (!this.editor.frameContext.get('wysiwyg').contains(this.selectionNode)) this._init();
|
|
240
|
+
if (!this.selectionNode) {
|
|
241
|
+
const selectionNode = /** @type {HTMLElement|Text} */ (dom.query.getEdgeChild(this.editor.frameContext.get('wysiwyg').firstChild, (current) => current.childNodes.length === 0 || current.nodeType === 3, false));
|
|
242
|
+
if (!selectionNode) {
|
|
243
|
+
this._init();
|
|
244
|
+
} else {
|
|
245
|
+
this.selectionNode = selectionNode;
|
|
246
|
+
return selectionNode;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return this.selectionNode;
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @this {SelectionThis}
|
|
254
|
+
* @description Get the Rects object.
|
|
255
|
+
* @param {?Range|Node} target Range | Node | null
|
|
256
|
+
* @param {"start"|"end"} position It is based on the position of the rect object to be returned in case of range selection.
|
|
257
|
+
* @returns {{rects: RectsInfo_selection, position: "start"|"end", scrollLeft: number, scrollTop: number}}
|
|
258
|
+
*/
|
|
259
|
+
getRects(target, position) {
|
|
260
|
+
const targetAbs = dom.check.isElement(/** @type {Node} */ (target)) ? _w.getComputedStyle(target).position === 'absolute' : false;
|
|
261
|
+
target = /** @type {Range} */ (!target || dom.check.isText(/** @type {Node} */ (target)) ? this.getRange() : target);
|
|
262
|
+
const globalScroll = this.offset.getGlobalScroll();
|
|
263
|
+
let isStartPosition = position === 'start';
|
|
264
|
+
let scrollLeft = globalScroll.left;
|
|
265
|
+
let scrollTop = globalScroll.top;
|
|
266
|
+
|
|
267
|
+
let rects = /** @type {*} */ (target).getClientRects();
|
|
268
|
+
rects = rects[isStartPosition ? 0 : rects.length - 1];
|
|
269
|
+
|
|
270
|
+
if (!rects) {
|
|
271
|
+
const node = this.getNode();
|
|
272
|
+
if (this.format.isLine(node)) {
|
|
273
|
+
const zeroWidth = dom.utils.createTextNode(unicode.zeroWidthSpace);
|
|
274
|
+
this.html.insertNode(zeroWidth, { afterNode: null, skipCharCount: true });
|
|
275
|
+
this.setRange(zeroWidth, 1, zeroWidth, 1);
|
|
276
|
+
this._init();
|
|
277
|
+
rects = this.getRange().getClientRects();
|
|
278
|
+
rects = rects[isStartPosition ? 0 : rects.length - 1];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!rects) {
|
|
282
|
+
const nodeOffset = this.offset.get(node);
|
|
283
|
+
rects = {
|
|
284
|
+
left: nodeOffset.left,
|
|
285
|
+
top: nodeOffset.top,
|
|
286
|
+
right: nodeOffset.left + /** @type {HTMLElement} */ (node).offsetWidth,
|
|
287
|
+
bottom: nodeOffset.top + /** @type {HTMLElement} */ (node).offsetHeight,
|
|
288
|
+
noText: true
|
|
289
|
+
};
|
|
290
|
+
scrollLeft = 0;
|
|
291
|
+
scrollTop = 0;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
isStartPosition = true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const iframeRects = /^iframe$/i.test(this.editor.frameContext.get('wysiwygFrame').nodeName) ? this.editor.frameContext.get('wysiwygFrame').getClientRects()[0] : null;
|
|
298
|
+
if (!targetAbs && iframeRects) {
|
|
299
|
+
rects = {
|
|
300
|
+
left: rects.left + iframeRects.left,
|
|
301
|
+
top: rects.top + iframeRects.top,
|
|
302
|
+
right: rects.right + iframeRects.right - iframeRects.width,
|
|
303
|
+
bottom: rects.bottom + iframeRects.bottom - iframeRects.height
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
rects: rects,
|
|
309
|
+
position: isStartPosition ? 'start' : 'end',
|
|
310
|
+
scrollLeft: scrollLeft,
|
|
311
|
+
scrollTop: scrollTop
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @this {SelectionThis}
|
|
317
|
+
* @description Get the custom range object of the event.
|
|
318
|
+
* @param {DragEvent} e Event object
|
|
319
|
+
* @returns {{sc: Node, so: number, ec: Node, eo: number}} {sc: startContainer, so: startOffset, ec: endContainer, eo: endOffset}
|
|
320
|
+
*/
|
|
321
|
+
getDragEventLocationRange(e) {
|
|
322
|
+
const wd = this.editor.frameContext.get('_wd');
|
|
323
|
+
let r, sc, so, ec, eo;
|
|
324
|
+
|
|
325
|
+
if (wd.caretPositionFromPoint) {
|
|
326
|
+
r = wd.caretPositionFromPoint(e.clientX, e.clientY);
|
|
327
|
+
sc = r.offsetNode;
|
|
328
|
+
so = r.offset;
|
|
329
|
+
ec = r.offsetNode;
|
|
330
|
+
eo = r.offset;
|
|
331
|
+
} else if (wd.caretRangeFromPoint) {
|
|
332
|
+
r = wd.caretRangeFromPoint(e.clientX, e.clientY);
|
|
333
|
+
sc = r.startContainer;
|
|
334
|
+
so = r.startOffset;
|
|
335
|
+
ec = r.endContainer;
|
|
336
|
+
eo = r.endOffset;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
sc,
|
|
341
|
+
so,
|
|
342
|
+
ec,
|
|
343
|
+
eo
|
|
344
|
+
};
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @this {SelectionThis}
|
|
349
|
+
* @description Scroll to the corresponding selection or range position.
|
|
350
|
+
* @param {Selection|Range|Node} ref selection or range object
|
|
351
|
+
* @param {?Object<string, *>=} scrollOption option of scrollTo
|
|
352
|
+
*/
|
|
353
|
+
scrollTo(ref, scrollOption) {
|
|
354
|
+
if (this.instanceCheck.isSelection(ref)) {
|
|
355
|
+
ref = ref.getRangeAt(0);
|
|
356
|
+
} else if (this.instanceCheck.isNode(ref)) {
|
|
357
|
+
ref = this.setRange(ref, 1, ref, 1);
|
|
358
|
+
} else if (typeof ref?.startContainer === 'undefined') {
|
|
359
|
+
console.warn('[SUNEDITOR.html.scrollTo.warn] "selectionRange" must be Selection or Range or Node object.', ref);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
scrollOption = { behavior: 'smooth', block: 'nearest', inline: 'nearest', ...scrollOption };
|
|
363
|
+
const el = dom.query.getParentElement(ref.startContainer, (current) => current.nodeType === 1);
|
|
364
|
+
|
|
365
|
+
const { frameContext, frameOptions } = this.editor;
|
|
366
|
+
const ww = frameContext.get('_ww');
|
|
367
|
+
const wwFrame = frameContext.get('wysiwygFrame');
|
|
368
|
+
const isIframe = frameOptions.get('iframe');
|
|
369
|
+
const isAutoHeight = frameOptions.get('height') === 'auto';
|
|
370
|
+
const initViewportHeight = this.status.initViewportHeight;
|
|
371
|
+
const viewportHeight = this.status.currentViewportHeight;
|
|
372
|
+
const scrollY = isAutoHeight ? _w.scrollY : isIframe ? ww.scrollY : wwFrame.scrollTop;
|
|
373
|
+
const realToolbarHeight = this.context.get('toolbar.main').offsetHeight;
|
|
374
|
+
const toolbarHeight = this.toolbar._sticky ? realToolbarHeight : 0;
|
|
375
|
+
const statusbarHeight = frameContext.get('statusbar')?.offsetHeight || 0;
|
|
376
|
+
|
|
377
|
+
if (this.__hasScrollParents || (!isIframe && (!isTouchDevice || initViewportHeight - viewportHeight < 150))) {
|
|
378
|
+
el?.scrollIntoView(scrollOption);
|
|
379
|
+
|
|
380
|
+
if (toolbarHeight && scrollY > _w.scrollY) {
|
|
381
|
+
_w.scrollBy(0, -toolbarHeight);
|
|
382
|
+
} else if (isAutoHeight) {
|
|
383
|
+
_w.scrollBy(0, statusbarHeight);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// --- When there is no upper scroll and it is an iframe ---
|
|
390
|
+
const PADDING = this._scrollMargin;
|
|
391
|
+
const viewHeight = isAutoHeight ? viewportHeight : wwFrame.offsetHeight;
|
|
392
|
+
const elH = el.offsetHeight || 0;
|
|
393
|
+
|
|
394
|
+
const behavior = scrollOption?.behavior;
|
|
395
|
+
if (isAutoHeight) {
|
|
396
|
+
if (isIframe) {
|
|
397
|
+
const rect = this.getRects(ref, 'end').rects;
|
|
398
|
+
const topMargin = rect.top + elH - toolbarHeight;
|
|
399
|
+
const bottomMargin = viewHeight - PADDING - (rect.top + elH);
|
|
400
|
+
if (topMargin >= 0 && bottomMargin >= 0) return;
|
|
401
|
+
|
|
402
|
+
const newScrollTop = scrollY - (topMargin < 0 ? -(topMargin - PADDING) : bottomMargin);
|
|
403
|
+
_w.scrollTo({
|
|
404
|
+
top: newScrollTop,
|
|
405
|
+
behavior
|
|
406
|
+
});
|
|
407
|
+
} else {
|
|
408
|
+
const rect = this.offset.getGlobal(el);
|
|
409
|
+
const scrollMargin = viewHeight + scrollY - rect.top - elH;
|
|
410
|
+
|
|
411
|
+
if (scrollMargin - PADDING > 0 && viewHeight > scrollMargin + PADDING + toolbarHeight) return;
|
|
412
|
+
|
|
413
|
+
const newScrollTop = scrollMargin <= PADDING ? scrollY - scrollMargin + PADDING + statusbarHeight : scrollY - scrollMargin + (viewHeight - elH - PADDING);
|
|
414
|
+
_w.scrollTo({
|
|
415
|
+
top: newScrollTop,
|
|
416
|
+
behavior
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
// local scroll
|
|
421
|
+
const { top } = this.offset.getLocal(el);
|
|
422
|
+
|
|
423
|
+
const keepLocalScroll = top - PADDING > 0 && top + PADDING <= viewHeight;
|
|
424
|
+
const rectScroll = top - PADDING > 0 ? top + PADDING - viewHeight : top - (toolbarHeight + elH);
|
|
425
|
+
let newScrollTop = scrollY + rectScroll;
|
|
426
|
+
|
|
427
|
+
// frame scroll
|
|
428
|
+
const gy = _w.scrollY;
|
|
429
|
+
const globalRect = this.offset.getGlobal();
|
|
430
|
+
const topMargin = gy - globalRect.top + realToolbarHeight;
|
|
431
|
+
const bottomMargin = globalRect.top + globalRect.height - (gy + viewportHeight) + realToolbarHeight;
|
|
432
|
+
|
|
433
|
+
// set frame scroll
|
|
434
|
+
if (topMargin > 0) {
|
|
435
|
+
const newFrameY = (keepLocalScroll ? top : top + scrollY - newScrollTop) - elH - PADDING - topMargin;
|
|
436
|
+
if (newFrameY < 0) {
|
|
437
|
+
newScrollTop += realToolbarHeight;
|
|
438
|
+
_w.scrollTo({
|
|
439
|
+
top: gy + newFrameY,
|
|
440
|
+
behavior: 'smooth'
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (bottomMargin > 0) {
|
|
445
|
+
const newFrameY = (keepLocalScroll ? top : top + scrollY - newScrollTop) + elH + PADDING - (globalRect.height - bottomMargin);
|
|
446
|
+
if (newFrameY > 0) {
|
|
447
|
+
newScrollTop += statusbarHeight;
|
|
448
|
+
_w.scrollTo({
|
|
449
|
+
top: gy + newFrameY,
|
|
450
|
+
behavior: 'smooth'
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// set local scroll
|
|
456
|
+
if (!keepLocalScroll) {
|
|
457
|
+
(isIframe ? ww : wwFrame).scrollTo({
|
|
458
|
+
top: newScrollTop,
|
|
459
|
+
behavior
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @private
|
|
467
|
+
* @this {SelectionThis}
|
|
468
|
+
* @description Returns true if there is no valid selection.
|
|
469
|
+
* @param {Range} range selection.getRange()
|
|
470
|
+
* @returns {boolean}
|
|
471
|
+
*/
|
|
472
|
+
_isNone(range) {
|
|
473
|
+
const comm = /** @type {HTMLElement} */ (range.commonAncestorContainer);
|
|
474
|
+
return (
|
|
475
|
+
(dom.check.isWysiwygFrame(range.startContainer) && dom.check.isWysiwygFrame(range.endContainer)) ||
|
|
476
|
+
/FIGURE/i.test(comm.nodeName) ||
|
|
477
|
+
(this.editor._fileManager.regExp.test(comm.nodeName) && (!this.editor._fileManager.tagAttrs[comm.nodeName] || this.editor._fileManager.tagAttrs[comm.nodeName]?.every((v) => comm.hasAttribute(v)))) ||
|
|
478
|
+
this.component.is(comm)
|
|
479
|
+
);
|
|
480
|
+
},
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @private
|
|
484
|
+
* @this {SelectionThis}
|
|
485
|
+
* @description Return the range object of editor's first child node
|
|
486
|
+
* @returns {Range}
|
|
487
|
+
*/
|
|
488
|
+
_createDefaultRange() {
|
|
489
|
+
const wysiwyg = this.editor.frameContext.get('wysiwyg');
|
|
490
|
+
const range = this.editor.frameContext.get('_wd').createRange();
|
|
491
|
+
|
|
492
|
+
let firstFormat = wysiwyg.firstElementChild;
|
|
493
|
+
let focusEl = null;
|
|
494
|
+
if (!firstFormat) {
|
|
495
|
+
focusEl = dom.utils.createElement('BR');
|
|
496
|
+
firstFormat = dom.utils.createElement(this.options.get('defaultLine'), null, focusEl);
|
|
497
|
+
wysiwyg.appendChild(firstFormat);
|
|
498
|
+
} else {
|
|
499
|
+
focusEl = firstFormat.firstChild;
|
|
500
|
+
if (!focusEl) {
|
|
501
|
+
focusEl = dom.utils.createElement('BR');
|
|
502
|
+
firstFormat.appendChild(focusEl);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
range.setStart(focusEl, 0);
|
|
507
|
+
range.setEnd(focusEl, 0);
|
|
508
|
+
|
|
509
|
+
return range;
|
|
510
|
+
},
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* @private
|
|
514
|
+
* @this {SelectionThis}
|
|
515
|
+
* @description Set "range" and "selection" info.
|
|
516
|
+
* @param {Range} range range object.
|
|
517
|
+
* @param {Selection} selection selection object.
|
|
518
|
+
*/
|
|
519
|
+
_rangeInfo(range, selection) {
|
|
520
|
+
let selectionNode = null;
|
|
521
|
+
this.status._range = range;
|
|
522
|
+
|
|
523
|
+
if (range.collapsed) {
|
|
524
|
+
if (dom.check.isWysiwygFrame(range.commonAncestorContainer)) selectionNode = range.commonAncestorContainer.children[range.startOffset] || range.commonAncestorContainer;
|
|
525
|
+
else selectionNode = range.commonAncestorContainer;
|
|
526
|
+
} else {
|
|
527
|
+
selectionNode = selection.anchorNode;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
this.selectionNode = /** @type {HTMLElement|Text} */ (selectionNode);
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* @private
|
|
535
|
+
* @this {SelectionThis}
|
|
536
|
+
* @description Saving the range object and the currently selected node of editor
|
|
537
|
+
*/
|
|
538
|
+
_init() {
|
|
539
|
+
const activeEl = this.editor.frameContext.get('_wd').activeElement;
|
|
540
|
+
if (dom.check.isInputElement(activeEl)) {
|
|
541
|
+
this.selectionNode = activeEl;
|
|
542
|
+
return activeEl;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const selection = this.get();
|
|
546
|
+
|
|
547
|
+
if (!selection) return null;
|
|
548
|
+
let range = null;
|
|
549
|
+
|
|
550
|
+
if (selection.rangeCount > 0) {
|
|
551
|
+
range = selection.getRangeAt(0);
|
|
552
|
+
} else {
|
|
553
|
+
range = this._createDefaultRange();
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
this._rangeInfo(range, selection);
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* @private
|
|
561
|
+
* @this {SelectionThis}
|
|
562
|
+
* @description Focus method
|
|
563
|
+
*/
|
|
564
|
+
__focus() {
|
|
565
|
+
try {
|
|
566
|
+
this.__iframeFocus = true;
|
|
567
|
+
const caption = dom.query.getParentElement(this.getNode(), 'figcaption');
|
|
568
|
+
if (caption) {
|
|
569
|
+
caption.focus();
|
|
570
|
+
} else {
|
|
571
|
+
this.editor.frameContext.get('wysiwyg').focus();
|
|
572
|
+
}
|
|
573
|
+
} finally {
|
|
574
|
+
_w.setTimeout(() => (this.__iframeFocus = false), 0);
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @private
|
|
580
|
+
* @this {SelectionThis}
|
|
581
|
+
* @description Reset range object to text node selected status.
|
|
582
|
+
* @returns {boolean} Returns false if there is no valid selection.
|
|
583
|
+
*/
|
|
584
|
+
_resetRangeToTextNode() {
|
|
585
|
+
let rangeObj = this.getRange();
|
|
586
|
+
if (this._isNone(rangeObj)) {
|
|
587
|
+
if (!dom.check.isWysiwygFrame(rangeObj.startContainer) || !dom.check.isWysiwygFrame(rangeObj.endContainer)) return false;
|
|
588
|
+
const ww = /** @type {HTMLElement} */ (rangeObj.commonAncestorContainer);
|
|
589
|
+
const first = ww.children[rangeObj.startOffset];
|
|
590
|
+
const end = ww.children[rangeObj.endOffset];
|
|
591
|
+
if (!(rangeObj = this.setRange(first, 0, end, first === end ? 0 : 1))) return false;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const range = rangeObj;
|
|
595
|
+
const collapsed = range.collapsed;
|
|
596
|
+
let startCon = range.startContainer;
|
|
597
|
+
let startOff = range.startOffset;
|
|
598
|
+
let endCon = range.endContainer;
|
|
599
|
+
let endOff = range.endOffset;
|
|
600
|
+
let tempCon, tempOffset, tempChild;
|
|
601
|
+
|
|
602
|
+
if (this.format.isLine(startCon)) {
|
|
603
|
+
if (!startCon.childNodes[startOff]) {
|
|
604
|
+
startCon = startCon.lastChild || startCon;
|
|
605
|
+
startOff = startCon.textContent.length;
|
|
606
|
+
} else {
|
|
607
|
+
startCon = startCon.childNodes[startOff] || startCon;
|
|
608
|
+
startOff = 0;
|
|
609
|
+
}
|
|
610
|
+
while (startCon?.nodeType === 1 && startCon.firstChild) {
|
|
611
|
+
startCon = startCon.firstChild || startCon;
|
|
612
|
+
startOff = 0;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (this.format.isLine(endCon)) {
|
|
616
|
+
endCon = endCon.childNodes[endOff] || endCon.lastChild || endCon;
|
|
617
|
+
while (endCon?.nodeType === 1 && endCon.lastChild) {
|
|
618
|
+
endCon = endCon.lastChild;
|
|
619
|
+
}
|
|
620
|
+
if (collapsed) endOff = 0;
|
|
621
|
+
else if (endOff > 0) endOff = endCon.textContent.length;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// startContainer
|
|
625
|
+
tempCon = dom.check.isWysiwygFrame(startCon) ? this.editor.frameContext.get('wysiwyg').firstChild : startCon;
|
|
626
|
+
tempOffset = startOff;
|
|
627
|
+
|
|
628
|
+
if (dom.check.isBreak(tempCon) || (tempCon.nodeType === 1 && tempCon.childNodes.length > 0)) {
|
|
629
|
+
const onlyBreak = dom.check.isBreak(tempCon);
|
|
630
|
+
if (!onlyBreak) {
|
|
631
|
+
const tempConCache = tempCon;
|
|
632
|
+
while (tempCon && !dom.check.isBreak(tempCon) && tempCon.nodeType === 1) {
|
|
633
|
+
tempChild = tempCon.childNodes;
|
|
634
|
+
if (tempChild.length === 0) break;
|
|
635
|
+
tempCon = tempChild[tempOffset > 0 ? tempOffset - 1 : tempOffset] || !/FIGURE/i.test(tempChild[0].nodeName) ? tempChild[0] : tempCon.previousElementSibling || tempCon.previousSibling || startCon;
|
|
636
|
+
tempOffset = tempOffset > 0 ? tempCon.textContent.length : tempOffset;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
let format = this.format.getLine(tempCon, null);
|
|
640
|
+
if (format === this.format.getBlock(format, null)) {
|
|
641
|
+
tempCon = tempCon || tempConCache;
|
|
642
|
+
format = dom.utils.createElement(dom.query.getParentElement(tempCon, dom.check.isTableCell) ? 'DIV' : this.options.get('defaultLine'));
|
|
643
|
+
tempCon.parentNode.insertBefore(format, tempCon);
|
|
644
|
+
if (tempCon !== tempConCache) format.appendChild(tempCon);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (dom.check.isBreak(tempCon) || this.component.is(tempCon)) {
|
|
649
|
+
const emptyText = dom.utils.createTextNode(unicode.zeroWidthSpace);
|
|
650
|
+
tempCon.parentNode.insertBefore(emptyText, tempCon);
|
|
651
|
+
tempCon = emptyText;
|
|
652
|
+
if (onlyBreak) {
|
|
653
|
+
if (startCon === endCon) {
|
|
654
|
+
endCon = tempCon;
|
|
655
|
+
endOff = 1;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// set startContainer
|
|
662
|
+
startCon = tempCon;
|
|
663
|
+
startOff = tempOffset;
|
|
664
|
+
|
|
665
|
+
// endContainer
|
|
666
|
+
tempCon = dom.check.isWysiwygFrame(endCon) ? this.editor.frameContext.get('wysiwyg').lastChild : endCon;
|
|
667
|
+
tempOffset = endOff;
|
|
668
|
+
|
|
669
|
+
if (dom.check.isBreak(tempCon) || (tempCon.nodeType === 1 && tempCon.childNodes.length > 0)) {
|
|
670
|
+
const onlyBreak = dom.check.isBreak(tempCon);
|
|
671
|
+
if (!onlyBreak) {
|
|
672
|
+
while (tempCon && !dom.check.isBreak(tempCon) && tempCon.nodeType === 1) {
|
|
673
|
+
tempChild = tempCon.childNodes;
|
|
674
|
+
if (tempChild.length === 0) break;
|
|
675
|
+
tempCon = tempChild[tempOffset > 0 ? tempOffset - 1 : tempOffset] || !/FIGURE/i.test(tempChild[0].nodeName) ? tempChild[0] : tempCon.previousElementSibling || tempCon.previousSibling || startCon;
|
|
676
|
+
tempOffset = tempOffset > 0 ? tempCon.textContent.length : tempOffset;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
let format = this.format.getLine(tempCon, null);
|
|
680
|
+
if (format === this.format.getBlock(format, null)) {
|
|
681
|
+
format = dom.utils.createElement(dom.check.isTableCell(format) ? 'DIV' : this.options.get('defaultLine'));
|
|
682
|
+
tempCon.parentNode.insertBefore(format, tempCon);
|
|
683
|
+
format.appendChild(tempCon);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (dom.check.isBreak(tempCon)) {
|
|
688
|
+
const emptyText = dom.utils.createTextNode(unicode.zeroWidthSpace);
|
|
689
|
+
tempCon.parentNode.insertBefore(emptyText, tempCon);
|
|
690
|
+
tempCon = emptyText;
|
|
691
|
+
tempOffset = 1;
|
|
692
|
+
if (onlyBreak && !tempCon.previousSibling) {
|
|
693
|
+
dom.utils.removeItem(endCon);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// set endContainer
|
|
699
|
+
endCon = tempCon;
|
|
700
|
+
endOff = tempOffset;
|
|
701
|
+
|
|
702
|
+
// set Range
|
|
703
|
+
this.setRange(startCon, startOff, endCon, endOff);
|
|
704
|
+
return true;
|
|
705
|
+
},
|
|
706
|
+
|
|
707
|
+
constructor: Selection_
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
export default Selection_;
|