vue-editify 0.1.26 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/core/function.d.ts +265 -0
- package/lib/core/rule.d.ts +32 -0
- package/lib/core/tool.d.ts +50 -1
- package/lib/editify/editify.vue.d.ts +2 -0
- package/lib/editify.es.js +241 -151
- package/lib/editify.umd.js +1 -1
- package/lib/hljs/index.d.ts +9 -0
- package/lib/index.d.ts +2 -2
- package/lib/locale/index.d.ts +5 -0
- package/lib/plugins/attachment/index.d.ts +20 -1
- package/lib/plugins/attachment/insertAttachment/insertAttachment.vue.d.ts +3 -3
- package/lib/plugins/attachment/insertAttachment/props.d.ts +1 -1
- package/lib/style.css +1 -1
- package/package.json +2 -2
- package/src/components/insertImage/insertImage.less +1 -0
- package/src/components/insertVideo/insertVideo.less +1 -0
- package/src/components/menu/menu.vue +45 -9
- package/src/core/function.ts +265 -42
- package/src/core/rule.ts +40 -7
- package/src/core/tool.ts +51 -9
- package/src/editify/editify.less +2 -1
- package/src/editify/editify.vue +20 -17
- package/src/hljs/index.ts +9 -2
- package/src/index.ts +6 -4
- package/src/locale/en_US.ts +3 -2
- package/src/locale/index.ts +5 -2
- package/src/locale/zh_CN.ts +4 -3
- package/src/plugins/attachment/index.ts +94 -36
- package/src/plugins/attachment/insertAttachment/insertAttachment.less +48 -19
- package/src/plugins/attachment/insertAttachment/insertAttachment.vue +26 -56
- package/src/plugins/attachment/insertAttachment/props.ts +1 -1
- package/src/plugins/attachment/images/attachment.png +0 -0
package/src/core/function.ts
CHANGED
@@ -6,7 +6,12 @@ import { common as DapCommon } from 'dap-util'
|
|
6
6
|
import { cloneData, queryHasValue, getButtonOptionsConfig, ObjectType } from './tool'
|
7
7
|
import { ButtonOptionsItemType } from '../components/button/props'
|
8
8
|
|
9
|
-
|
9
|
+
/**
|
10
|
+
* 判断元素是否在某个标签下,如果是返回该标签对应的元素,否则返回null
|
11
|
+
* @param element
|
12
|
+
* @param parsedom
|
13
|
+
* @returns
|
14
|
+
*/
|
10
15
|
export const getParsedomElementByElement = (element: AlexElement, parsedom: string): AlexElement | null => {
|
11
16
|
if (element.isBlock()) {
|
12
17
|
return element.parsedom == parsedom ? element : null
|
@@ -17,7 +22,13 @@ export const getParsedomElementByElement = (element: AlexElement, parsedom: stri
|
|
17
22
|
return getParsedomElementByElement(element.parent!, parsedom)
|
18
23
|
}
|
19
24
|
|
20
|
-
|
25
|
+
/**
|
26
|
+
* 获取光标是否在指定标签下,如果是返回该标签对应的元素,否则返回null
|
27
|
+
* @param editor
|
28
|
+
* @param dataRangeCaches
|
29
|
+
* @param parsedom
|
30
|
+
* @returns
|
31
|
+
*/
|
21
32
|
export const getCurrentParsedomElement = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, parsedom: string) => {
|
22
33
|
if (!editor.range) {
|
23
34
|
return null
|
@@ -54,7 +65,12 @@ export const getCurrentParsedomElement = (editor: AlexEditor, dataRangeCaches: A
|
|
54
65
|
return null
|
55
66
|
}
|
56
67
|
|
57
|
-
|
68
|
+
/**
|
69
|
+
* 判断元素是否在有序列表或者无序列表下
|
70
|
+
* @param element
|
71
|
+
* @param ordered
|
72
|
+
* @returns
|
73
|
+
*/
|
58
74
|
export const elementIsInList = (element: AlexElement, ordered: boolean): boolean => {
|
59
75
|
if (isList(element, ordered)) {
|
60
76
|
return true
|
@@ -65,7 +81,11 @@ export const elementIsInList = (element: AlexElement, ordered: boolean): boolean
|
|
65
81
|
return false
|
66
82
|
}
|
67
83
|
|
68
|
-
|
84
|
+
/**
|
85
|
+
* 判断元素是否在任务列表下
|
86
|
+
* @param element
|
87
|
+
* @returns
|
88
|
+
*/
|
69
89
|
export const elementIsInTask = (element: AlexElement): boolean => {
|
70
90
|
if (isTask(element)) {
|
71
91
|
return true
|
@@ -76,7 +96,12 @@ export const elementIsInTask = (element: AlexElement): boolean => {
|
|
76
96
|
return false
|
77
97
|
}
|
78
98
|
|
79
|
-
|
99
|
+
/**
|
100
|
+
* 判断元素是否有序或者无序列表
|
101
|
+
* @param element
|
102
|
+
* @param ordered
|
103
|
+
* @returns
|
104
|
+
*/
|
80
105
|
export const isList = (element: AlexElement, ordered: boolean | undefined = false) => {
|
81
106
|
if (element.isEmpty()) {
|
82
107
|
return false
|
@@ -84,7 +109,11 @@ export const isList = (element: AlexElement, ordered: boolean | undefined = fals
|
|
84
109
|
return element.parsedom == 'div' && element.hasMarks() && element.marks!['data-editify-list'] == (ordered ? 'ol' : 'ul')
|
85
110
|
}
|
86
111
|
|
87
|
-
|
112
|
+
/**
|
113
|
+
* 判断元素是否任务列表
|
114
|
+
* @param element
|
115
|
+
* @returns
|
116
|
+
*/
|
88
117
|
export const isTask = (element: AlexElement) => {
|
89
118
|
if (element.isEmpty()) {
|
90
119
|
return false
|
@@ -92,7 +121,12 @@ export const isTask = (element: AlexElement) => {
|
|
92
121
|
return element.parsedom == 'div' && element.hasMarks() && element.marks!.hasOwnProperty('data-editify-task')
|
93
122
|
}
|
94
123
|
|
95
|
-
|
124
|
+
/**
|
125
|
+
* 选区是否含有代码块
|
126
|
+
* @param editor
|
127
|
+
* @param dataRangeCaches
|
128
|
+
* @returns
|
129
|
+
*/
|
96
130
|
export const hasPreInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
97
131
|
if (!editor.range) {
|
98
132
|
return false
|
@@ -105,7 +139,12 @@ export const hasPreInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
105
139
|
})
|
106
140
|
}
|
107
141
|
|
108
|
-
|
142
|
+
/**
|
143
|
+
* 选区是否全部在代码块内
|
144
|
+
* @param editor
|
145
|
+
* @param dataRangeCaches
|
146
|
+
* @returns
|
147
|
+
*/
|
109
148
|
export const isRangeInPre = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
110
149
|
if (!editor.range) {
|
111
150
|
return false
|
@@ -118,7 +157,12 @@ export const isRangeInPre = (editor: AlexEditor, dataRangeCaches: AlexElementsRa
|
|
118
157
|
})
|
119
158
|
}
|
120
159
|
|
121
|
-
|
160
|
+
/**
|
161
|
+
* 选区是否含有引用
|
162
|
+
* @param editor
|
163
|
+
* @param dataRangeCaches
|
164
|
+
* @returns
|
165
|
+
*/
|
122
166
|
export const hasQuoteInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
123
167
|
if (!editor.range) {
|
124
168
|
return false
|
@@ -131,7 +175,12 @@ export const hasQuoteInRange = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
131
175
|
})
|
132
176
|
}
|
133
177
|
|
134
|
-
|
178
|
+
/**
|
179
|
+
* 选区是否全部在引用内
|
180
|
+
* @param editor
|
181
|
+
* @param dataRangeCaches
|
182
|
+
* @returns
|
183
|
+
*/
|
135
184
|
export const isRangeInQuote = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
136
185
|
if (!editor.range) {
|
137
186
|
return false
|
@@ -144,7 +193,13 @@ export const isRangeInQuote = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
144
193
|
})
|
145
194
|
}
|
146
195
|
|
147
|
-
|
196
|
+
/**
|
197
|
+
* 选区是否含有有序列表或者无序列表
|
198
|
+
* @param editor
|
199
|
+
* @param dataRangeCaches
|
200
|
+
* @param ordered
|
201
|
+
* @returns
|
202
|
+
*/
|
148
203
|
export const hasListInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, ordered: boolean | undefined = false) => {
|
149
204
|
if (!editor.range) {
|
150
205
|
return false
|
@@ -157,7 +212,13 @@ export const hasListInRange = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
157
212
|
})
|
158
213
|
}
|
159
214
|
|
160
|
-
|
215
|
+
/**
|
216
|
+
* 选区是否全部在有序列表或者无序列表内
|
217
|
+
* @param editor
|
218
|
+
* @param dataRangeCaches
|
219
|
+
* @param ordered
|
220
|
+
* @returns
|
221
|
+
*/
|
161
222
|
export const isRangeInList = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, ordered: boolean | undefined = false) => {
|
162
223
|
if (!editor.range) {
|
163
224
|
return false
|
@@ -170,7 +231,12 @@ export const isRangeInList = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
170
231
|
})
|
171
232
|
}
|
172
233
|
|
173
|
-
|
234
|
+
/**
|
235
|
+
* 选区是否含有任务列表
|
236
|
+
* @param editor
|
237
|
+
* @param dataRangeCaches
|
238
|
+
* @returns
|
239
|
+
*/
|
174
240
|
export const hasTaskInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
175
241
|
if (!editor.range) {
|
176
242
|
return false
|
@@ -183,7 +249,12 @@ export const hasTaskInRange = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
183
249
|
})
|
184
250
|
}
|
185
251
|
|
186
|
-
|
252
|
+
/**
|
253
|
+
* 选区是否全部在任务列表里
|
254
|
+
* @param editor
|
255
|
+
* @param dataRangeCaches
|
256
|
+
* @returns
|
257
|
+
*/
|
187
258
|
export const isRangeInTask = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
188
259
|
if (!editor.range) {
|
189
260
|
return false
|
@@ -196,7 +267,12 @@ export const isRangeInTask = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
196
267
|
})
|
197
268
|
}
|
198
269
|
|
199
|
-
|
270
|
+
/**
|
271
|
+
* 选区是否含有链接
|
272
|
+
* @param editor
|
273
|
+
* @param dataRangeCaches
|
274
|
+
* @returns
|
275
|
+
*/
|
200
276
|
export const hasLinkInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
201
277
|
if (!editor.range) {
|
202
278
|
return false
|
@@ -209,7 +285,12 @@ export const hasLinkInRange = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
209
285
|
})
|
210
286
|
}
|
211
287
|
|
212
|
-
|
288
|
+
/**
|
289
|
+
* 选区是否含有表格
|
290
|
+
* @param editor
|
291
|
+
* @param dataRangeCaches
|
292
|
+
* @returns
|
293
|
+
*/
|
213
294
|
export const hasTableInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
214
295
|
if (!editor.range) {
|
215
296
|
return false
|
@@ -222,7 +303,12 @@ export const hasTableInRange = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
222
303
|
})
|
223
304
|
}
|
224
305
|
|
225
|
-
|
306
|
+
/**
|
307
|
+
* 选区是否含有图片
|
308
|
+
* @param editor
|
309
|
+
* @param dataRangeCaches
|
310
|
+
* @returns
|
311
|
+
*/
|
226
312
|
export const hasImageInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
227
313
|
if (!editor.range) {
|
228
314
|
return false
|
@@ -235,7 +321,12 @@ export const hasImageInRange = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
235
321
|
})
|
236
322
|
}
|
237
323
|
|
238
|
-
|
324
|
+
/**
|
325
|
+
* 选区是否含有视频
|
326
|
+
* @param editor
|
327
|
+
* @param dataRangeCaches
|
328
|
+
* @returns
|
329
|
+
*/
|
239
330
|
export const hasVideoInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
240
331
|
if (!editor.range) {
|
241
332
|
return false
|
@@ -248,7 +339,14 @@ export const hasVideoInRange = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
248
339
|
})
|
249
340
|
}
|
250
341
|
|
251
|
-
|
342
|
+
/**
|
343
|
+
* 查询光标所在的文本元素是否具有某个样式
|
344
|
+
* @param editor
|
345
|
+
* @param dataRangeCaches
|
346
|
+
* @param name
|
347
|
+
* @param value
|
348
|
+
* @returns
|
349
|
+
*/
|
252
350
|
export const queryTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, name: string, value?: string | number) => {
|
253
351
|
if (!editor.range) {
|
254
352
|
return false
|
@@ -282,7 +380,14 @@ export const queryTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
282
380
|
return flag
|
283
381
|
}
|
284
382
|
|
285
|
-
|
383
|
+
/**
|
384
|
+
* 查询光标所在的文本元素是否具有某个标记
|
385
|
+
* @param editor
|
386
|
+
* @param dataRangeCaches
|
387
|
+
* @param name
|
388
|
+
* @param value
|
389
|
+
* @returns
|
390
|
+
*/
|
286
391
|
export const queryTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, name: string, value?: string | number) => {
|
287
392
|
if (!editor.range) {
|
288
393
|
return false
|
@@ -316,7 +421,11 @@ export const queryTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
316
421
|
return flag
|
317
422
|
}
|
318
423
|
|
319
|
-
|
424
|
+
/**
|
425
|
+
* 获取选区内的文字内容,用于预置链接文字
|
426
|
+
* @param dataRangeCaches
|
427
|
+
* @returns
|
428
|
+
*/
|
320
429
|
export const getRangeText = (dataRangeCaches: AlexElementsRangeType) => {
|
321
430
|
//存在选区的情况下预置链接文本值
|
322
431
|
let text = ''
|
@@ -332,7 +441,12 @@ export const getRangeText = (dataRangeCaches: AlexElementsRangeType) => {
|
|
332
441
|
return text
|
333
442
|
}
|
334
443
|
|
335
|
-
|
444
|
+
/**
|
445
|
+
* 获取光标选取内的扁平化元素数组(可能会分割文本元素导致stack变更,同时也会更新选取元素和光标位置)
|
446
|
+
* @param editor
|
447
|
+
* @param dataRangeCaches
|
448
|
+
* @returns
|
449
|
+
*/
|
336
450
|
export const getFlatElementsByRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
337
451
|
if (!editor.range) {
|
338
452
|
return []
|
@@ -393,14 +507,22 @@ export const getFlatElementsByRange = (editor: AlexEditor, dataRangeCaches: Alex
|
|
393
507
|
return elements
|
394
508
|
}
|
395
509
|
|
396
|
-
|
510
|
+
/**
|
511
|
+
* 将某个元素转为段落标签
|
512
|
+
* @param element
|
513
|
+
*/
|
397
514
|
export const elementToParagraph = (element: AlexElement) => {
|
398
515
|
element.marks = null
|
399
516
|
element.styles = null
|
400
517
|
element.parsedom = AlexElement.BLOCK_NODE
|
401
518
|
}
|
402
519
|
|
403
|
-
|
520
|
+
/**
|
521
|
+
* 其他元素转为有序或者无序列表
|
522
|
+
* @param element
|
523
|
+
* @param ordered
|
524
|
+
* @returns
|
525
|
+
*/
|
404
526
|
export const elementToList = (element: AlexElement, ordered: boolean | undefined = false) => {
|
405
527
|
//如果是列表则返回
|
406
528
|
if (isList(element, ordered)) {
|
@@ -416,7 +538,11 @@ export const elementToList = (element: AlexElement, ordered: boolean | undefined
|
|
416
538
|
element.marks!['data-editify-list'] = ordered ? 'ol' : 'ul'
|
417
539
|
}
|
418
540
|
|
419
|
-
|
541
|
+
/**
|
542
|
+
* 其他元素转为任务列表
|
543
|
+
* @param element
|
544
|
+
* @returns
|
545
|
+
*/
|
420
546
|
export const elementToTask = (element: AlexElement) => {
|
421
547
|
//如果是任务列表则返回
|
422
548
|
if (isTask(element)) {
|
@@ -432,7 +558,14 @@ export const elementToTask = (element: AlexElement) => {
|
|
432
558
|
element.marks!['data-editify-task'] = 'uncheck'
|
433
559
|
}
|
434
560
|
|
435
|
-
|
561
|
+
/**
|
562
|
+
* 设置标题
|
563
|
+
* @param editor
|
564
|
+
* @param dataRangeCaches
|
565
|
+
* @param editTrans
|
566
|
+
* @param parsedom
|
567
|
+
* @returns
|
568
|
+
*/
|
436
569
|
export const setHeading = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, editTrans: (key: string) => any, parsedom: string) => {
|
437
570
|
if (!editor.range) {
|
438
571
|
return
|
@@ -463,7 +596,12 @@ export const setHeading = (editor: AlexEditor, dataRangeCaches: AlexElementsRang
|
|
463
596
|
}
|
464
597
|
}
|
465
598
|
|
466
|
-
|
599
|
+
/**
|
600
|
+
* 根级块元素或者内部块元素增加缩进
|
601
|
+
* @param editor
|
602
|
+
* @param dataRangeCaches
|
603
|
+
* @returns
|
604
|
+
*/
|
467
605
|
export const setIndentIncrease = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
468
606
|
if (!editor.range) {
|
469
607
|
return
|
@@ -508,7 +646,12 @@ export const setIndentIncrease = (editor: AlexEditor, dataRangeCaches: AlexEleme
|
|
508
646
|
}
|
509
647
|
}
|
510
648
|
|
511
|
-
|
649
|
+
/**
|
650
|
+
* 根级块元素或者内部块元素减少缩进
|
651
|
+
* @param editor
|
652
|
+
* @param dataRangeCaches
|
653
|
+
* @returns
|
654
|
+
*/
|
512
655
|
export const setIndentDecrease = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
513
656
|
if (!editor.range) {
|
514
657
|
return
|
@@ -545,7 +688,12 @@ export const setIndentDecrease = (editor: AlexEditor, dataRangeCaches: AlexEleme
|
|
545
688
|
}
|
546
689
|
}
|
547
690
|
|
548
|
-
|
691
|
+
/**
|
692
|
+
* 插入或者取消引用
|
693
|
+
* @param editor
|
694
|
+
* @param dataRangeCaches
|
695
|
+
* @returns
|
696
|
+
*/
|
549
697
|
export const setQuote = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
550
698
|
if (!editor.range) {
|
551
699
|
return
|
@@ -579,7 +727,13 @@ export const setQuote = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeT
|
|
579
727
|
}
|
580
728
|
}
|
581
729
|
|
582
|
-
|
730
|
+
/**
|
731
|
+
* 设置对齐方式,参数取值justify/left/right/center
|
732
|
+
* @param editor
|
733
|
+
* @param dataRangeCaches
|
734
|
+
* @param value
|
735
|
+
* @returns
|
736
|
+
*/
|
583
737
|
export const setAlign = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, value: string) => {
|
584
738
|
if (!editor.range) {
|
585
739
|
return
|
@@ -639,7 +793,13 @@ export const setAlign = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeT
|
|
639
793
|
}
|
640
794
|
}
|
641
795
|
|
642
|
-
|
796
|
+
/**
|
797
|
+
* 插入或者取消 有序或者无序列表 ordered为true表示有序列表
|
798
|
+
* @param editor
|
799
|
+
* @param dataRangeCaches
|
800
|
+
* @param ordered
|
801
|
+
* @returns
|
802
|
+
*/
|
643
803
|
export const setList = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, ordered: boolean) => {
|
644
804
|
if (!editor.range) {
|
645
805
|
return
|
@@ -675,7 +835,12 @@ export const setList = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeTy
|
|
675
835
|
}
|
676
836
|
}
|
677
837
|
|
678
|
-
|
838
|
+
/**
|
839
|
+
* 插入或者取消任务列表
|
840
|
+
* @param editor
|
841
|
+
* @param dataRangeCaches
|
842
|
+
* @returns
|
843
|
+
*/
|
679
844
|
export const setTask = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
680
845
|
if (!editor.range) {
|
681
846
|
return
|
@@ -711,7 +876,13 @@ export const setTask = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeTy
|
|
711
876
|
}
|
712
877
|
}
|
713
878
|
|
714
|
-
|
879
|
+
/**
|
880
|
+
* 设置文本元素的样式,styles为{ 'font-weight':'bold' }这类格式
|
881
|
+
* @param editor
|
882
|
+
* @param dataRangeCaches
|
883
|
+
* @param styles
|
884
|
+
* @returns
|
885
|
+
*/
|
715
886
|
export const setTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, styles: ObjectType) => {
|
716
887
|
if (!editor.range) {
|
717
888
|
return
|
@@ -764,7 +935,13 @@ export const setTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElementsRa
|
|
764
935
|
}
|
765
936
|
}
|
766
937
|
|
767
|
-
|
938
|
+
/**
|
939
|
+
* 设置文本元素的标记,marks为{ 'class':'a' }这类格式
|
940
|
+
* @param editor
|
941
|
+
* @param dataRangeCaches
|
942
|
+
* @param marks
|
943
|
+
* @returns
|
944
|
+
*/
|
768
945
|
export const setTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, marks: ObjectType) => {
|
769
946
|
if (!editor.range) {
|
770
947
|
return
|
@@ -820,7 +997,13 @@ export const setTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsRan
|
|
820
997
|
}
|
821
998
|
}
|
822
999
|
|
823
|
-
|
1000
|
+
/**
|
1001
|
+
* 移除文本元素的样式,styleNames是样式名称数组,如果不存在则移除全部样式
|
1002
|
+
* @param editor
|
1003
|
+
* @param dataRangeCaches
|
1004
|
+
* @param styleNames
|
1005
|
+
* @returns
|
1006
|
+
*/
|
824
1007
|
export const removeTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, styleNames?: string[]) => {
|
825
1008
|
if (!editor.range) {
|
826
1009
|
return
|
@@ -873,7 +1056,13 @@ export const removeTextStyle = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
873
1056
|
}
|
874
1057
|
}
|
875
1058
|
|
876
|
-
|
1059
|
+
/**
|
1060
|
+
* 移除文本元素的标记,markNames是标记名称数组,如果不存在则移除全部标记
|
1061
|
+
* @param editor
|
1062
|
+
* @param dataRangeCaches
|
1063
|
+
* @param markNames
|
1064
|
+
* @returns
|
1065
|
+
*/
|
877
1066
|
export const removeTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, markNames?: string[]) => {
|
878
1067
|
if (!editor.range) {
|
879
1068
|
return
|
@@ -926,7 +1115,13 @@ export const removeTextMark = (editor: AlexEditor, dataRangeCaches: AlexElements
|
|
926
1115
|
}
|
927
1116
|
}
|
928
1117
|
|
929
|
-
|
1118
|
+
/**
|
1119
|
+
* 设置块元素或者根级块元素的行高
|
1120
|
+
* @param editor
|
1121
|
+
* @param dataRangeCaches
|
1122
|
+
* @param value
|
1123
|
+
* @returns
|
1124
|
+
*/
|
930
1125
|
export const setLineHeight = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, value: string | number) => {
|
931
1126
|
if (!editor.range) {
|
932
1127
|
return
|
@@ -986,7 +1181,14 @@ export const setLineHeight = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
986
1181
|
}
|
987
1182
|
}
|
988
1183
|
|
989
|
-
|
1184
|
+
/**
|
1185
|
+
* 插入链接
|
1186
|
+
* @param editor
|
1187
|
+
* @param text
|
1188
|
+
* @param url
|
1189
|
+
* @param newOpen
|
1190
|
+
* @returns
|
1191
|
+
*/
|
990
1192
|
export const insertLink = (editor: AlexEditor, text: string, url: string, newOpen: boolean) => {
|
991
1193
|
if (!editor.range) {
|
992
1194
|
return
|
@@ -1006,7 +1208,12 @@ export const insertLink = (editor: AlexEditor, text: string, url: string, newOpe
|
|
1006
1208
|
editor.insertElement(linkEle)
|
1007
1209
|
}
|
1008
1210
|
|
1009
|
-
|
1211
|
+
/**
|
1212
|
+
* 插入图片
|
1213
|
+
* @param editor
|
1214
|
+
* @param value
|
1215
|
+
* @returns
|
1216
|
+
*/
|
1010
1217
|
export const insertImage = (editor: AlexEditor, value: string) => {
|
1011
1218
|
if (!editor.range) {
|
1012
1219
|
return
|
@@ -1023,7 +1230,12 @@ export const insertImage = (editor: AlexEditor, value: string) => {
|
|
1023
1230
|
editor.insertElement(image)
|
1024
1231
|
}
|
1025
1232
|
|
1026
|
-
|
1233
|
+
/**
|
1234
|
+
* 插入视频
|
1235
|
+
* @param editor
|
1236
|
+
* @param value
|
1237
|
+
* @returns
|
1238
|
+
*/
|
1027
1239
|
export const insertVideo = (editor: AlexEditor, value: string) => {
|
1028
1240
|
if (!editor.range) {
|
1029
1241
|
return
|
@@ -1046,7 +1258,13 @@ export const insertVideo = (editor: AlexEditor, value: string) => {
|
|
1046
1258
|
editor.range.focus.moveToEnd(rightSpace)
|
1047
1259
|
}
|
1048
1260
|
|
1049
|
-
|
1261
|
+
/**
|
1262
|
+
* 插入表格
|
1263
|
+
* @param editor
|
1264
|
+
* @param rowLength
|
1265
|
+
* @param colLength
|
1266
|
+
* @returns
|
1267
|
+
*/
|
1050
1268
|
export const insertTable = (editor: AlexEditor, rowLength: number, colLength: number) => {
|
1051
1269
|
if (!editor.range) {
|
1052
1270
|
return
|
@@ -1074,7 +1292,12 @@ export const insertTable = (editor: AlexEditor, rowLength: number, colLength: nu
|
|
1074
1292
|
editor.range.focus.moveToStart(tbody)
|
1075
1293
|
}
|
1076
1294
|
|
1077
|
-
|
1295
|
+
/**
|
1296
|
+
* 插入或者取消代码块
|
1297
|
+
* @param editor
|
1298
|
+
* @param dataRangeCaches
|
1299
|
+
* @returns
|
1300
|
+
*/
|
1078
1301
|
export const insertCodeBlock = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
1079
1302
|
if (!editor.range) {
|
1080
1303
|
return
|
package/src/core/rule.ts
CHANGED
@@ -4,7 +4,14 @@ import { getColNumbers } from './tool'
|
|
4
4
|
import { isList, isTask } from './function'
|
5
5
|
import { common as DapCommon } from 'dap-util'
|
6
6
|
|
7
|
-
|
7
|
+
/**
|
8
|
+
* 更新代码块内的光标位置
|
9
|
+
* @param editor
|
10
|
+
* @param element
|
11
|
+
* @param originalTextElements
|
12
|
+
* @param newElements
|
13
|
+
* @returns
|
14
|
+
*/
|
8
15
|
const updateRangeInPre = (editor: AlexEditor, element: AlexElement, originalTextElements: AlexElement[], newElements: AlexElement[]) => {
|
9
16
|
if (!editor.range) {
|
10
17
|
return
|
@@ -55,7 +62,11 @@ const updateRangeInPre = (editor: AlexEditor, element: AlexElement, originalText
|
|
55
62
|
}
|
56
63
|
}
|
57
64
|
|
58
|
-
|
65
|
+
/**
|
66
|
+
* 元素格式化时转换ol和li标签
|
67
|
+
* @param editor
|
68
|
+
* @param element
|
69
|
+
*/
|
59
70
|
export const parseList = (editor: AlexEditor, element: AlexElement) => {
|
60
71
|
//ol标签和ul标签转为div
|
61
72
|
if (element.parsedom == 'ol' || element.parsedom == 'ul') {
|
@@ -76,7 +87,11 @@ export const parseList = (editor: AlexEditor, element: AlexElement) => {
|
|
76
87
|
}
|
77
88
|
}
|
78
89
|
|
79
|
-
|
90
|
+
/**
|
91
|
+
* 元素格式化时处理有序列表的序号值
|
92
|
+
* @param editor
|
93
|
+
* @param element
|
94
|
+
*/
|
80
95
|
export const orderdListHandle = function (editor: AlexEditor, element: AlexElement) {
|
81
96
|
//有序列表的序号处理
|
82
97
|
if (isList(element, true)) {
|
@@ -94,7 +109,11 @@ export const orderdListHandle = function (editor: AlexEditor, element: AlexEleme
|
|
94
109
|
}
|
95
110
|
}
|
96
111
|
|
97
|
-
|
112
|
+
/**
|
113
|
+
* 元素格式化时处理媒体元素和链接
|
114
|
+
* @param editor
|
115
|
+
* @param element
|
116
|
+
*/
|
98
117
|
export const mediaHandle = function (editor: AlexEditor, element: AlexElement) {
|
99
118
|
//图片、视频和链接设置marks
|
100
119
|
if (element.parsedom == 'img' || element.parsedom == 'video' || element.parsedom == 'a') {
|
@@ -125,7 +144,11 @@ export const mediaHandle = function (editor: AlexEditor, element: AlexElement) {
|
|
125
144
|
}
|
126
145
|
}
|
127
146
|
|
128
|
-
|
147
|
+
/**
|
148
|
+
* 元素格式化时处理表格
|
149
|
+
* @param editor
|
150
|
+
* @param element
|
151
|
+
*/
|
129
152
|
export const tableHandle = function (editor: AlexEditor, element: AlexElement) {
|
130
153
|
if (element.parsedom == 'table') {
|
131
154
|
const marks = {
|
@@ -191,7 +214,13 @@ export const tableHandle = function (editor: AlexEditor, element: AlexElement) {
|
|
191
214
|
}
|
192
215
|
}
|
193
216
|
|
194
|
-
|
217
|
+
/**
|
218
|
+
* 元素格式化时处理pre,将pre的内容根据语言进行样式处理
|
219
|
+
* @param editor
|
220
|
+
* @param element
|
221
|
+
* @param highlight
|
222
|
+
* @param languages
|
223
|
+
*/
|
195
224
|
export const preHandle = function (editor: AlexEditor, element: AlexElement, highlight: boolean, languages: (string | LanguagesItemType)[]) {
|
196
225
|
//如果是代码块进行处理
|
197
226
|
if (element.parsedom == 'pre') {
|
@@ -243,7 +272,11 @@ export const preHandle = function (editor: AlexEditor, element: AlexElement, hig
|
|
243
272
|
}
|
244
273
|
}
|
245
274
|
|
246
|
-
|
275
|
+
/**
|
276
|
+
* 元素格式化时处理一些特殊的内部块元素,转为根级块元素
|
277
|
+
* @param editor
|
278
|
+
* @param element
|
279
|
+
*/
|
247
280
|
export const specialInblockHandle = function (editor: AlexEditor, element: AlexElement) {
|
248
281
|
if (element.hasChildren()) {
|
249
282
|
element.children!.forEach(el => {
|