vue-editify 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +49 -67
- package/lib/components/button/button.vue.d.ts +62 -60
- package/lib/components/button/index.d.ts +4 -0
- package/lib/components/button/props.d.ts +12 -1
- package/lib/components/checkbox/checkbox.vue.d.ts +9 -9
- package/lib/components/checkbox/index.d.ts +4 -0
- package/lib/components/checkbox/props.d.ts +2 -2
- package/lib/components/colors/colors.vue.d.ts +4 -4
- package/lib/components/colors/index.d.ts +4 -0
- package/lib/components/colors/props.d.ts +2 -2
- package/lib/components/icon/index.d.ts +4 -0
- package/lib/components/insertAttachment/index.d.ts +4 -0
- package/lib/{plugins/attachment → components}/insertAttachment/insertAttachment.vue.d.ts +3 -3
- package/lib/{plugins/attachment → components}/insertAttachment/props.d.ts +1 -1
- package/lib/components/insertImage/index.d.ts +4 -0
- package/lib/components/insertImage/insertImage.vue.d.ts +3 -3
- package/lib/components/insertImage/props.d.ts +1 -1
- package/lib/components/insertLink/index.d.ts +4 -0
- package/lib/components/insertLink/insertLink.vue.d.ts +6 -6
- package/lib/components/insertLink/props.d.ts +3 -3
- package/lib/components/insertMathformula/index.d.ts +4 -0
- package/lib/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue.d.ts +3 -3
- package/lib/{plugins/mathformula → components}/insertMathformula/props.d.ts +2 -2
- package/lib/components/insertTable/index.d.ts +4 -0
- package/lib/components/insertTable/insertTable.vue.d.ts +3 -3
- package/lib/components/insertTable/props.d.ts +2 -2
- package/lib/components/insertVideo/index.d.ts +4 -0
- package/lib/components/insertVideo/insertVideo.vue.d.ts +3 -3
- package/lib/components/insertVideo/props.d.ts +1 -1
- package/lib/components/layer/index.d.ts +4 -0
- package/lib/components/layer/layer.vue.d.ts +10 -8
- package/lib/components/tooltip/index.d.ts +4 -0
- package/lib/components/tooltip/tooltip.vue.d.ts +6 -4
- package/lib/components/triangle/index.d.ts +4 -0
- package/lib/components/triangle/triangle.vue.d.ts +1 -1
- package/lib/components/updateLink/index.d.ts +4 -0
- package/lib/components/updateLink/props.d.ts +17 -0
- package/lib/components/updateLink/updateLink.vue.d.ts +38 -0
- package/lib/core/function.d.ts +113 -36
- package/lib/core/rule.d.ts +20 -0
- package/lib/core/tool.d.ts +36 -34
- package/lib/editify/editify.vue.d.ts +18 -27
- package/lib/editify/menu/index.d.ts +4 -0
- package/lib/{components → editify}/menu/menu.vue.d.ts +3 -4
- package/lib/{components → editify}/menu/props.d.ts +1 -1
- package/lib/editify/props.d.ts +3 -7
- package/lib/editify/toolbar/index.d.ts +4 -0
- package/lib/{components → editify}/toolbar/props.d.ts +2 -2
- package/lib/{components → editify}/toolbar/toolbar.vue.d.ts +53 -53
- package/lib/editify.es.js +8797 -7560
- package/lib/editify.umd.js +2 -2
- package/lib/feature/align.d.ts +32 -0
- package/lib/feature/attachment.d.ts +18 -0
- package/lib/feature/backColor.d.ts +32 -0
- package/lib/feature/bold.d.ts +32 -0
- package/lib/feature/code.d.ts +32 -0
- package/lib/feature/codeBlock.d.ts +32 -0
- package/lib/feature/fontFamily.d.ts +32 -0
- package/lib/feature/fontSize.d.ts +32 -0
- package/lib/feature/foreColor.d.ts +32 -0
- package/lib/feature/formatClear.d.ts +32 -0
- package/lib/feature/fullScreen.d.ts +18 -0
- package/lib/feature/heading.d.ts +32 -0
- package/lib/feature/image.d.ts +32 -0
- package/lib/feature/indent.d.ts +18 -0
- package/lib/feature/infoBlock.d.ts +18 -0
- package/lib/feature/italic.d.ts +32 -0
- package/lib/feature/lineHeight.d.ts +32 -0
- package/lib/feature/link.d.ts +26 -0
- package/lib/feature/mathformula.d.ts +22 -0
- package/lib/feature/orderList.d.ts +32 -0
- package/lib/feature/panel.d.ts +18 -0
- package/lib/feature/quote.d.ts +18 -0
- package/lib/feature/redo.d.ts +18 -0
- package/lib/feature/separator.d.ts +18 -0
- package/lib/feature/sourceView.d.ts +18 -0
- package/lib/feature/strikethrough.d.ts +32 -0
- package/lib/feature/sub.d.ts +32 -0
- package/lib/feature/super.d.ts +32 -0
- package/lib/feature/table.d.ts +32 -0
- package/lib/feature/task.d.ts +32 -0
- package/lib/feature/underline.d.ts +32 -0
- package/lib/feature/undo.d.ts +18 -0
- package/lib/feature/unorderList.d.ts +32 -0
- package/lib/feature/video.d.ts +38 -0
- package/lib/index.d.ts +36 -43
- package/package.json +5 -5
- package/src/components/button/button.vue +21 -24
- package/src/components/button/index.ts +5 -0
- package/src/components/button/props.ts +14 -1
- package/src/components/checkbox/checkbox.vue +1 -1
- package/src/components/checkbox/index.ts +5 -0
- package/src/components/checkbox/props.ts +1 -1
- package/src/components/colors/colors.vue +3 -3
- package/src/components/colors/index.ts +5 -0
- package/src/components/colors/props.ts +2 -2
- package/src/components/icon/index.ts +5 -0
- package/src/components/insertAttachment/index.ts +5 -0
- package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.vue +4 -2
- package/src/{plugins/attachment → components}/insertAttachment/props.ts +1 -1
- package/src/components/insertImage/index.ts +5 -0
- package/src/components/insertImage/insertImage.vue +5 -5
- package/src/components/insertImage/props.ts +1 -1
- package/src/components/insertLink/index.ts +5 -0
- package/src/components/insertLink/insertLink.vue +10 -10
- package/src/components/insertLink/props.ts +3 -3
- package/src/components/insertMathformula/index.ts +5 -0
- package/src/{plugins/mathformula → components}/insertMathformula/props.ts +2 -2
- package/src/components/insertTable/index.ts +5 -0
- package/src/components/insertTable/props.ts +2 -2
- package/src/components/insertVideo/index.ts +5 -0
- package/src/components/insertVideo/insertVideo.vue +2 -2
- package/src/components/insertVideo/props.ts +1 -1
- package/src/components/layer/index.ts +5 -0
- package/src/components/layer/layer.vue +42 -4
- package/src/components/tooltip/index.ts +5 -0
- package/src/components/tooltip/tooltip.vue +1 -1
- package/src/components/triangle/index.ts +5 -0
- package/src/components/triangle/triangle.vue +1 -1
- package/src/components/updateLink/index.ts +5 -0
- package/src/components/updateLink/props.ts +21 -0
- package/src/components/{toolbar/toolbar.less → updateLink/updateLink.less} +4 -20
- package/src/components/updateLink/updateLink.vue +74 -0
- package/src/core/function.ts +289 -97
- package/src/core/rule.ts +96 -7
- package/src/core/tool.ts +234 -78
- package/src/editify/editify.less +2 -0
- package/src/editify/editify.vue +182 -185
- package/src/editify/menu/index.ts +5 -0
- package/src/editify/menu/menu.vue +215 -0
- package/src/{components → editify}/menu/props.ts +1 -1
- package/src/editify/props.ts +7 -11
- package/src/editify/toolbar/index.ts +5 -0
- package/src/{components → editify}/toolbar/props.ts +1 -1
- package/src/editify/toolbar/toolbar.less +10 -0
- package/src/editify/toolbar/toolbar.vue +103 -0
- package/src/feature/align.ts +128 -0
- package/src/feature/attachment.ts +109 -0
- package/src/feature/backColor.ts +171 -0
- package/src/feature/bold.ts +136 -0
- package/src/feature/code.ts +136 -0
- package/src/feature/codeBlock.ts +204 -0
- package/src/feature/fontFamily.ts +140 -0
- package/src/feature/fontSize.ts +142 -0
- package/src/feature/foreColor.ts +173 -0
- package/src/feature/formatClear.ts +118 -0
- package/src/feature/fullScreen.ts +57 -0
- package/src/feature/heading.ts +154 -0
- package/src/feature/image.ts +225 -0
- package/src/feature/indent.ts +73 -0
- package/src/feature/infoBlock.ts +94 -0
- package/src/feature/italic.ts +136 -0
- package/src/feature/lineHeight.ts +165 -0
- package/src/feature/link.ts +149 -0
- package/src/feature/mathformula.ts +147 -0
- package/src/feature/orderList.ts +116 -0
- package/src/feature/panel.ts +108 -0
- package/src/feature/quote.ts +61 -0
- package/src/feature/redo.ts +56 -0
- package/src/feature/separator.ts +62 -0
- package/src/feature/sourceView.ts +59 -0
- package/src/feature/strikethrough.ts +136 -0
- package/src/feature/sub.ts +136 -0
- package/src/feature/super.ts +136 -0
- package/src/feature/table.ts +994 -0
- package/src/feature/task.ts +116 -0
- package/src/feature/underline.ts +136 -0
- package/src/feature/undo.ts +56 -0
- package/src/feature/unorderList.ts +116 -0
- package/src/feature/video.ts +339 -0
- package/src/hljs/index.ts +1 -1
- package/src/index.ts +69 -21
- package/src/locale/en_US.ts +3 -3
- package/src/locale/zh_CN.ts +3 -3
- package/lib/plugins/attachment/index.d.ts +0 -37
- package/lib/plugins/infoBlock/index.d.ts +0 -55
- package/lib/plugins/mathformula/index.d.ts +0 -49
- package/lib/plugins/panel/index.d.ts +0 -48
- package/src/components/menu/menu.vue +0 -1655
- package/src/components/toolbar/toolbar.vue +0 -1677
- package/src/plugins/attachment/index.ts +0 -237
- package/src/plugins/infoBlock/index.ts +0 -238
- package/src/plugins/mathformula/index.ts +0 -295
- package/src/plugins/panel/index.ts +0 -228
- package/tsconfig.json +0 -31
- package/tsconfig.node.json +0 -11
- /package/src/{plugins/attachment → components}/insertAttachment/insertAttachment.less +0 -0
- /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.less +0 -0
- /package/src/{plugins/mathformula → components}/insertMathformula/insertMathformula.vue +0 -0
- /package/src/{components → editify}/menu/menu.less +0 -0
package/src/core/function.ts
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
* 这里的方法都是对编辑器内容元素进行判断或者操作的方法,不涉及到格式化、dom渲染和光标渲染
|
3
3
|
*/
|
4
4
|
import { common as DapCommon } from 'dap-util'
|
5
|
-
import { AlexElement, AlexElementsRangeType,
|
5
|
+
import { AlexEditor, AlexElement, AlexElementsRangeType, AlexElementCreateConfigType } from 'alex-editor'
|
6
|
+
import { ButtonOptionsItemType } from '@/components/button'
|
6
7
|
import { cloneData, queryHasValue, getButtonOptionsConfig, ObjectType } from './tool'
|
7
|
-
import { ButtonOptionsItemType } from '@/components/button/props'
|
8
8
|
|
9
9
|
export type ElementMatchConfigType = {
|
10
10
|
parsedom?: string
|
@@ -239,13 +239,13 @@ export const elementIsMatch = (element: AlexElement, config: ElementMatchConfigT
|
|
239
239
|
* @returns
|
240
240
|
*/
|
241
241
|
export const getMatchElementByElement = (element: AlexElement, config: ElementMatchConfigType): AlexElement | null => {
|
242
|
-
if (element.isBlock()) {
|
243
|
-
return elementIsMatch(element, config) ? element : null
|
244
|
-
}
|
245
242
|
if (elementIsMatch(element, config)) {
|
246
243
|
return element
|
247
244
|
}
|
248
|
-
|
245
|
+
if (element.parent) {
|
246
|
+
return getMatchElementByElement(element.parent, config)
|
247
|
+
}
|
248
|
+
return null
|
249
249
|
}
|
250
250
|
|
251
251
|
/**
|
@@ -293,258 +293,448 @@ export const getMatchElementByRange = (editor: AlexEditor, dataRangeCaches: Alex
|
|
293
293
|
}
|
294
294
|
|
295
295
|
/**
|
296
|
-
* Open API
|
296
|
+
* Open API:判断元素是否有序或者无序列表,不做空元素判断
|
297
297
|
* @param element
|
298
298
|
* @param ordered
|
299
299
|
* @returns
|
300
300
|
*/
|
301
|
-
export const
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
301
|
+
export const elementIsList = (element: AlexElement, ordered: boolean | undefined = false) => {
|
302
|
+
return elementIsMatch(element, {
|
303
|
+
parsedom: 'div',
|
304
|
+
marks: {
|
305
|
+
'data-editify-list': ordered ? 'ol' : 'ul'
|
306
|
+
}
|
307
|
+
})
|
306
308
|
}
|
307
309
|
|
308
310
|
/**
|
309
|
-
* Open API
|
311
|
+
* Open API:判断元素是否在有序列表或者无序列表下,是的话返回有序列表或者无序列表元素,否则返回null
|
310
312
|
* @param element
|
313
|
+
* @param ordered
|
311
314
|
* @returns
|
312
315
|
*/
|
313
|
-
export const
|
314
|
-
|
316
|
+
export const getListByElement = (element: AlexElement, ordered: boolean): AlexElement | null => {
|
317
|
+
return getMatchElementByElement(element, {
|
318
|
+
parsedom: 'div',
|
319
|
+
marks: {
|
320
|
+
'data-editify-list': ordered ? 'ol' : 'ul'
|
321
|
+
}
|
322
|
+
})
|
323
|
+
}
|
324
|
+
|
325
|
+
/**
|
326
|
+
* Open API:选区是否含有有序列表或者无序列表,不一定是同一个有序列表或者序列表,只要含有有序列表或者序列表即返回true
|
327
|
+
* @param editor
|
328
|
+
* @param dataRangeCaches
|
329
|
+
* @param ordered
|
330
|
+
* @returns
|
331
|
+
*/
|
332
|
+
export const hasListInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, ordered: boolean | undefined = false) => {
|
333
|
+
if (!editor.range) {
|
315
334
|
return false
|
316
335
|
}
|
317
|
-
|
336
|
+
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
337
|
+
return !!getListByElement(editor.range.anchor.element, ordered)
|
338
|
+
}
|
339
|
+
return dataRangeCaches.flatList.some(item => {
|
340
|
+
return !!getListByElement(item.element, ordered)
|
341
|
+
})
|
318
342
|
}
|
319
343
|
|
320
344
|
/**
|
321
|
-
* Open API
|
322
|
-
* @param
|
345
|
+
* Open API:选区是否全部在有序列表或者无序列表内,不一定是同一个有序列表或者无序列表
|
346
|
+
* @param editor
|
347
|
+
* @param dataRangeCaches
|
323
348
|
* @param ordered
|
324
349
|
* @returns
|
325
350
|
*/
|
326
|
-
export const
|
327
|
-
if (
|
328
|
-
return
|
351
|
+
export const rangeIsInList = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType, ordered: boolean | undefined = false) => {
|
352
|
+
if (!editor.range) {
|
353
|
+
return false
|
329
354
|
}
|
330
|
-
if (
|
331
|
-
return
|
355
|
+
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
356
|
+
return !!getListByElement(editor.range.anchor.element, ordered)
|
332
357
|
}
|
333
|
-
return
|
358
|
+
return dataRangeCaches.list.every(item => {
|
359
|
+
return !!getListByElement(item.element, ordered)
|
360
|
+
})
|
361
|
+
}
|
362
|
+
|
363
|
+
/**
|
364
|
+
* Open API:判断元素是否任务列表,不做空元素判断
|
365
|
+
* @param element
|
366
|
+
* @returns
|
367
|
+
*/
|
368
|
+
export const elementIsTask = (element: AlexElement) => {
|
369
|
+
return elementIsMatch(element, {
|
370
|
+
parsedom: 'div',
|
371
|
+
marks: {
|
372
|
+
'data-editify-task': true
|
373
|
+
}
|
374
|
+
})
|
334
375
|
}
|
335
376
|
|
336
377
|
/**
|
337
|
-
* Open API
|
378
|
+
* Open API:判断元素是否在任务列表下,是的话返回任务列表元素,否则返回null
|
338
379
|
* @param element
|
339
380
|
* @returns
|
340
381
|
*/
|
341
|
-
export const
|
342
|
-
|
343
|
-
|
382
|
+
export const getTaskByElement = (element: AlexElement): AlexElement | null => {
|
383
|
+
return getMatchElementByElement(element, {
|
384
|
+
parsedom: 'div',
|
385
|
+
marks: {
|
386
|
+
'data-editify-task': true
|
387
|
+
}
|
388
|
+
})
|
389
|
+
}
|
390
|
+
|
391
|
+
/**
|
392
|
+
* Open API:选区是否含有任务列表,不一定是同一个任务列表,只要含有任务列表即返回true
|
393
|
+
* @param editor
|
394
|
+
* @param dataRangeCaches
|
395
|
+
* @returns
|
396
|
+
*/
|
397
|
+
export const hasTaskInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
398
|
+
if (!editor.range) {
|
399
|
+
return false
|
344
400
|
}
|
345
|
-
if (
|
346
|
-
return
|
401
|
+
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
402
|
+
return !!getTaskByElement(editor.range.anchor.element)
|
347
403
|
}
|
348
|
-
return
|
404
|
+
return dataRangeCaches.flatList.some(item => {
|
405
|
+
return !!getTaskByElement(item.element)
|
406
|
+
})
|
349
407
|
}
|
350
408
|
|
351
409
|
/**
|
352
|
-
* Open API
|
410
|
+
* Open API:选区是否全部在任务列表里,不一定是同一个任务列表
|
353
411
|
* @param editor
|
354
412
|
* @param dataRangeCaches
|
355
413
|
* @returns
|
356
414
|
*/
|
357
|
-
export const
|
415
|
+
export const rangeIsInTask = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
358
416
|
if (!editor.range) {
|
359
417
|
return false
|
360
418
|
}
|
361
419
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
362
|
-
return !!
|
420
|
+
return !!getTaskByElement(editor.range.anchor.element)
|
421
|
+
}
|
422
|
+
return dataRangeCaches.list.every(item => {
|
423
|
+
return !!getTaskByElement(item.element)
|
424
|
+
})
|
425
|
+
}
|
426
|
+
|
427
|
+
/**
|
428
|
+
* Open API:判断元素是否附件,不做空元素判断
|
429
|
+
* @param element
|
430
|
+
* @returns
|
431
|
+
*/
|
432
|
+
export const elementIsAttachment = (element: AlexElement) => {
|
433
|
+
return elementIsMatch(element, {
|
434
|
+
parsedom: 'span',
|
435
|
+
marks: {
|
436
|
+
'data-editify-attachment': true
|
437
|
+
}
|
438
|
+
})
|
439
|
+
}
|
440
|
+
|
441
|
+
/**
|
442
|
+
* Open API:选区是否含有附件,不一定是同一个附件,只要含有附件即返回true
|
443
|
+
* @param editor
|
444
|
+
* @param dataRangeCaches
|
445
|
+
* @returns
|
446
|
+
*/
|
447
|
+
export const hasAttachmentInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
448
|
+
if (!editor.range) {
|
449
|
+
return false
|
450
|
+
}
|
451
|
+
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
452
|
+
return elementIsAttachment(editor.range.anchor.element)
|
363
453
|
}
|
364
454
|
return dataRangeCaches.flatList.some(item => {
|
365
|
-
return
|
455
|
+
return elementIsAttachment(item.element)
|
456
|
+
})
|
457
|
+
}
|
458
|
+
|
459
|
+
/**
|
460
|
+
* Open API:判断元素是否数学公式,不做空元素判断
|
461
|
+
* @param element
|
462
|
+
* @returns
|
463
|
+
*/
|
464
|
+
export const elementIsMathformula = (element: AlexElement) => {
|
465
|
+
return elementIsMatch(element, {
|
466
|
+
parsedom: 'span',
|
467
|
+
marks: {
|
468
|
+
'data-editify-mathformula': true
|
469
|
+
}
|
366
470
|
})
|
367
471
|
}
|
368
472
|
|
369
473
|
/**
|
370
|
-
* Open API
|
474
|
+
* Open API:判断元素是否在数学公式下,是的话返回数学公式元素,否则返回null
|
475
|
+
* @param element
|
476
|
+
* @returns
|
477
|
+
*/
|
478
|
+
export const getMathformulaByElement = (element: AlexElement): AlexElement | null => {
|
479
|
+
return getMatchElementByElement(element, {
|
480
|
+
parsedom: 'span',
|
481
|
+
marks: {
|
482
|
+
'data-editify-mathformula': true
|
483
|
+
}
|
484
|
+
})
|
485
|
+
}
|
486
|
+
|
487
|
+
/**
|
488
|
+
* Open API:选区是否含有数学公式,不一定是同一个数学公式,只要含有数学公式即返回true
|
371
489
|
* @param editor
|
372
490
|
* @param dataRangeCaches
|
373
491
|
* @returns
|
374
492
|
*/
|
375
|
-
export const
|
493
|
+
export const hasMathformulaInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
376
494
|
if (!editor.range) {
|
377
495
|
return false
|
378
496
|
}
|
379
497
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
380
|
-
return !!
|
498
|
+
return !!getMathformulaByElement(editor.range.anchor.element)
|
381
499
|
}
|
382
500
|
return dataRangeCaches.flatList.some(item => {
|
383
|
-
return !!
|
501
|
+
return !!getMathformulaByElement(item.element)
|
384
502
|
})
|
385
503
|
}
|
386
504
|
|
387
505
|
/**
|
388
|
-
* Open API
|
506
|
+
* Open API:判断元素是否面板,不做空元素判断
|
507
|
+
* @param el
|
508
|
+
* @returns
|
509
|
+
*/
|
510
|
+
export const elementIsPanel = (element: AlexElement) => {
|
511
|
+
return elementIsMatch(element, {
|
512
|
+
parsedom: 'div',
|
513
|
+
marks: {
|
514
|
+
'data-editify-panel': true
|
515
|
+
}
|
516
|
+
})
|
517
|
+
}
|
518
|
+
|
519
|
+
/**
|
520
|
+
* Open API:判断元素是否在面板内,是的话返回面板元素,否则返回null
|
521
|
+
* @param el
|
522
|
+
* @returns
|
523
|
+
*/
|
524
|
+
export const getPanelByElement = (element: AlexElement): AlexElement | null => {
|
525
|
+
return getMatchElementByElement(element, {
|
526
|
+
parsedom: 'div',
|
527
|
+
marks: {
|
528
|
+
'data-editify-panel': true
|
529
|
+
}
|
530
|
+
})
|
531
|
+
}
|
532
|
+
|
533
|
+
/**
|
534
|
+
* Open API:选区是否含有面板,不一定是同一个面板,只要含有面板即返回true
|
389
535
|
* @param editor
|
390
536
|
* @param dataRangeCaches
|
391
|
-
* @param ordered
|
392
537
|
* @returns
|
393
538
|
*/
|
394
|
-
export const
|
539
|
+
export const hasPanelInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
395
540
|
if (!editor.range) {
|
396
541
|
return false
|
397
542
|
}
|
398
543
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
399
|
-
return
|
544
|
+
return !!getPanelByElement(editor.range.anchor.element)
|
400
545
|
}
|
401
546
|
return dataRangeCaches.flatList.some(item => {
|
402
|
-
return
|
547
|
+
return !!getPanelByElement(item.element)
|
548
|
+
})
|
549
|
+
}
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Open API:判断元素是否信息块,不做空元素判断
|
553
|
+
* @param el
|
554
|
+
* @returns
|
555
|
+
*/
|
556
|
+
export const elementIsInfoBlock = (element: AlexElement) => {
|
557
|
+
return elementIsMatch(element, {
|
558
|
+
parsedom: 'div',
|
559
|
+
marks: {
|
560
|
+
'data-editify-info': true
|
561
|
+
}
|
562
|
+
})
|
563
|
+
}
|
564
|
+
|
565
|
+
/**
|
566
|
+
* Open API:判断元素是否在信息块内,是的话返回信息块元素,否则返回null
|
567
|
+
* @param el
|
568
|
+
* @returns
|
569
|
+
*/
|
570
|
+
export const getInfoBlockByElement = (element: AlexElement): AlexElement | null => {
|
571
|
+
return getMatchElementByElement(element, {
|
572
|
+
parsedom: 'div',
|
573
|
+
marks: {
|
574
|
+
'data-editify-info': true
|
575
|
+
}
|
403
576
|
})
|
404
577
|
}
|
405
578
|
|
406
579
|
/**
|
407
|
-
* Open API
|
580
|
+
* Open API:选区是否含有信息块,不一定是同一个信息块,只要含有信息块即返回true
|
408
581
|
* @param editor
|
409
582
|
* @param dataRangeCaches
|
410
583
|
* @returns
|
411
584
|
*/
|
412
|
-
export const
|
585
|
+
export const hasInfoBlockInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
413
586
|
if (!editor.range) {
|
414
587
|
return false
|
415
588
|
}
|
416
589
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
417
|
-
return
|
590
|
+
return !!getInfoBlockByElement(editor.range.anchor.element)
|
418
591
|
}
|
419
592
|
return dataRangeCaches.flatList.some(item => {
|
420
|
-
return
|
593
|
+
return !!getInfoBlockByElement(item.element)
|
421
594
|
})
|
422
595
|
}
|
423
596
|
|
424
597
|
/**
|
425
|
-
* Open API
|
598
|
+
* Open API:选区是否全部在信息块里,不一定是同一个信息块
|
426
599
|
* @param editor
|
427
600
|
* @param dataRangeCaches
|
428
601
|
* @returns
|
429
602
|
*/
|
430
|
-
export const
|
603
|
+
export const rangeIsInInfoBlock = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
431
604
|
if (!editor.range) {
|
432
605
|
return false
|
433
606
|
}
|
434
607
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
435
|
-
return !!
|
608
|
+
return !!getInfoBlockByElement(editor.range.anchor.element)
|
609
|
+
}
|
610
|
+
return dataRangeCaches.flatList.every(item => {
|
611
|
+
return !!getInfoBlockByElement(item.element)
|
612
|
+
})
|
613
|
+
}
|
614
|
+
|
615
|
+
/**
|
616
|
+
* Open API:选区是否含有代码块,不一定是同一个代码块,只要含有代码块即返回true
|
617
|
+
* @param editor
|
618
|
+
* @param dataRangeCaches
|
619
|
+
* @returns
|
620
|
+
*/
|
621
|
+
export const hasPreInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
622
|
+
if (!editor.range) {
|
623
|
+
return false
|
624
|
+
}
|
625
|
+
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
626
|
+
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: 'pre' })
|
436
627
|
}
|
437
628
|
return dataRangeCaches.flatList.some(item => {
|
438
|
-
return !!getMatchElementByElement(item.element, { parsedom: '
|
629
|
+
return !!getMatchElementByElement(item.element, { parsedom: 'pre' })
|
439
630
|
})
|
440
631
|
}
|
441
632
|
|
442
633
|
/**
|
443
|
-
* Open API
|
634
|
+
* Open API:选区是否含有引用,不一定是同一个引用,只要含有引用即返回true
|
444
635
|
* @param editor
|
445
636
|
* @param dataRangeCaches
|
446
637
|
* @returns
|
447
638
|
*/
|
448
|
-
export const
|
639
|
+
export const hasQuoteInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
449
640
|
if (!editor.range) {
|
450
641
|
return false
|
451
642
|
}
|
452
643
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
453
|
-
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: '
|
644
|
+
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: 'blockquote' })
|
454
645
|
}
|
455
646
|
return dataRangeCaches.flatList.some(item => {
|
456
|
-
return !!getMatchElementByElement(item.element, { parsedom: '
|
647
|
+
return !!getMatchElementByElement(item.element, { parsedom: 'blockquote' })
|
457
648
|
})
|
458
649
|
}
|
459
650
|
|
460
651
|
/**
|
461
|
-
* Open API
|
652
|
+
* Open API:选区是否含有链接,不一定是同一个链接,只要含有链接即返回true
|
462
653
|
* @param editor
|
463
654
|
* @param dataRangeCaches
|
464
655
|
* @returns
|
465
656
|
*/
|
466
|
-
export const
|
657
|
+
export const hasLinkInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
467
658
|
if (!editor.range) {
|
468
659
|
return false
|
469
660
|
}
|
470
661
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
471
|
-
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: '
|
662
|
+
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: 'a' })
|
472
663
|
}
|
473
664
|
return dataRangeCaches.flatList.some(item => {
|
474
|
-
return !!getMatchElementByElement(item.element, { parsedom: '
|
665
|
+
return !!getMatchElementByElement(item.element, { parsedom: 'a' })
|
475
666
|
})
|
476
667
|
}
|
477
668
|
|
478
669
|
/**
|
479
|
-
* Open API
|
670
|
+
* Open API:选区是否含有表格,不一定是同一个表格,只要含有表格即返回true
|
480
671
|
* @param editor
|
481
672
|
* @param dataRangeCaches
|
482
673
|
* @returns
|
483
674
|
*/
|
484
|
-
export const
|
675
|
+
export const hasTableInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
485
676
|
if (!editor.range) {
|
486
677
|
return false
|
487
678
|
}
|
488
679
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
489
|
-
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: '
|
680
|
+
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: 'table' })
|
490
681
|
}
|
491
682
|
return dataRangeCaches.flatList.some(item => {
|
492
|
-
return !!getMatchElementByElement(item.element, { parsedom: '
|
683
|
+
return !!getMatchElementByElement(item.element, { parsedom: 'table' })
|
493
684
|
})
|
494
685
|
}
|
495
686
|
|
496
687
|
/**
|
497
|
-
* Open API
|
688
|
+
* Open API:选区是否含有图片,不一定是同一个图片,只要含有图片即返回true
|
498
689
|
* @param editor
|
499
690
|
* @param dataRangeCaches
|
500
691
|
* @returns
|
501
692
|
*/
|
502
|
-
export const
|
693
|
+
export const hasImageInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
503
694
|
if (!editor.range) {
|
504
695
|
return false
|
505
696
|
}
|
506
697
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
507
|
-
return
|
698
|
+
return elementIsMatch(editor.range.anchor.element, { parsedom: 'img' })
|
508
699
|
}
|
509
|
-
return dataRangeCaches.
|
510
|
-
return
|
700
|
+
return dataRangeCaches.flatList.some(item => {
|
701
|
+
return elementIsMatch(item.element, { parsedom: 'img' })
|
511
702
|
})
|
512
703
|
}
|
513
704
|
|
514
705
|
/**
|
515
|
-
* Open API
|
706
|
+
* Open API:选区是否含有视频,不一定是同一个视频,只要含有视频即返回true
|
516
707
|
* @param editor
|
517
708
|
* @param dataRangeCaches
|
518
|
-
* @param ordered
|
519
709
|
* @returns
|
520
710
|
*/
|
521
|
-
export const
|
711
|
+
export const hasVideoInRange = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
522
712
|
if (!editor.range) {
|
523
713
|
return false
|
524
714
|
}
|
525
715
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
526
|
-
return
|
716
|
+
return elementIsMatch(editor.range.anchor.element, { parsedom: 'video' })
|
527
717
|
}
|
528
|
-
return dataRangeCaches.
|
529
|
-
return
|
718
|
+
return dataRangeCaches.flatList.some(item => {
|
719
|
+
return elementIsMatch(item.element, { parsedom: 'video' })
|
530
720
|
})
|
531
721
|
}
|
532
722
|
|
533
723
|
/**
|
534
|
-
* Open API
|
724
|
+
* Open API:选区是否全部在引用内,不一定是同一个引用
|
535
725
|
* @param editor
|
536
726
|
* @param dataRangeCaches
|
537
727
|
* @returns
|
538
728
|
*/
|
539
|
-
export const
|
729
|
+
export const rangeIsInQuote = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeType) => {
|
540
730
|
if (!editor.range) {
|
541
731
|
return false
|
542
732
|
}
|
543
733
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
544
|
-
return
|
734
|
+
return !!getMatchElementByElement(editor.range.anchor.element, { parsedom: 'blockquote' })
|
545
735
|
}
|
546
736
|
return dataRangeCaches.list.every(item => {
|
547
|
-
return
|
737
|
+
return !!getMatchElementByElement(item.element, { parsedom: 'blockquote' })
|
548
738
|
})
|
549
739
|
}
|
550
740
|
|
@@ -631,7 +821,7 @@ export const queryTextMark = (editor: AlexEditor, dataRangeCaches: AlexElementsR
|
|
631
821
|
}
|
632
822
|
|
633
823
|
/**
|
634
|
-
* Open API
|
824
|
+
* Open API:获取选区内的文字内容
|
635
825
|
* @param dataRangeCaches
|
636
826
|
* @returns
|
637
827
|
*/
|
@@ -734,7 +924,7 @@ export const elementToParagraph = (element: AlexElement) => {
|
|
734
924
|
*/
|
735
925
|
export const elementToList = (element: AlexElement, ordered: boolean | undefined = false) => {
|
736
926
|
//如果是列表则返回
|
737
|
-
if (
|
927
|
+
if (elementIsList(element, ordered)) {
|
738
928
|
return
|
739
929
|
}
|
740
930
|
//先转为段落
|
@@ -754,7 +944,7 @@ export const elementToList = (element: AlexElement, ordered: boolean | undefined
|
|
754
944
|
*/
|
755
945
|
export const elementToTask = (element: AlexElement) => {
|
756
946
|
//如果是任务列表则返回
|
757
|
-
if (
|
947
|
+
if (elementIsTask(element)) {
|
758
948
|
return
|
759
949
|
}
|
760
950
|
//先转为段落
|
@@ -908,7 +1098,7 @@ export const setQuote = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeT
|
|
908
1098
|
return
|
909
1099
|
}
|
910
1100
|
//是否都在引用里
|
911
|
-
const flag =
|
1101
|
+
const flag = rangeIsInQuote(editor, dataRangeCaches)
|
912
1102
|
//起点和终点在一起
|
913
1103
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
914
1104
|
const block = editor.range.anchor.element.getBlock()
|
@@ -1014,7 +1204,7 @@ export const setList = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeTy
|
|
1014
1204
|
return
|
1015
1205
|
}
|
1016
1206
|
//是否都在列表内
|
1017
|
-
const flag =
|
1207
|
+
const flag = rangeIsInList(editor, dataRangeCaches, ordered)
|
1018
1208
|
//起点和终点在一起
|
1019
1209
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
1020
1210
|
const block = editor.range.anchor.element.getBlock()
|
@@ -1054,8 +1244,8 @@ export const setTask = (editor: AlexEditor, dataRangeCaches: AlexElementsRangeTy
|
|
1054
1244
|
if (!editor.range) {
|
1055
1245
|
return
|
1056
1246
|
}
|
1057
|
-
|
1058
|
-
const flag =
|
1247
|
+
//是否都在任务列表里
|
1248
|
+
const flag = rangeIsInTask(editor, dataRangeCaches)
|
1059
1249
|
//起点和终点在一起
|
1060
1250
|
if (editor.range.anchor.isEqual(editor.range.focus)) {
|
1061
1251
|
const block = editor.range.anchor.element.getBlock()
|
@@ -1584,20 +1774,22 @@ export const insertCodeBlock = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
1584
1774
|
else {
|
1585
1775
|
editor.range.anchor.moveToStart(dataRangeCaches.list[0].element.getBlock())
|
1586
1776
|
editor.range.focus.moveToEnd(dataRangeCaches.list[dataRangeCaches.list.length - 1].element.getBlock())
|
1587
|
-
const
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1777
|
+
const result: ObjectType = {}
|
1778
|
+
editor
|
1779
|
+
.getElementsByRange()
|
1780
|
+
.flatList.filter(el => el.element.isText())
|
1781
|
+
.forEach(el => {
|
1782
|
+
if (result[`_${el.element.getBlock().key}`]) {
|
1783
|
+
result[`_${el.element.getBlock().key}`].push(el.element.clone())
|
1784
|
+
} else {
|
1785
|
+
result[`_${el.element.getBlock().key}`] = [el.element.clone()]
|
1786
|
+
}
|
1787
|
+
})
|
1596
1788
|
const pre = AlexElement.create({
|
1597
1789
|
type: 'block',
|
1598
1790
|
parsedom: 'pre'
|
1599
1791
|
})
|
1600
|
-
Object.keys(
|
1792
|
+
Object.keys(result).forEach((key, index) => {
|
1601
1793
|
if (index > 0) {
|
1602
1794
|
const text = AlexElement.create({
|
1603
1795
|
type: 'text',
|
@@ -1609,7 +1801,7 @@ export const insertCodeBlock = (editor: AlexEditor, dataRangeCaches: AlexElement
|
|
1609
1801
|
editor.addElementTo(text, pre)
|
1610
1802
|
}
|
1611
1803
|
}
|
1612
|
-
|
1804
|
+
result[key].forEach((el: AlexElement) => {
|
1613
1805
|
if (pre.hasChildren()) {
|
1614
1806
|
editor.addElementTo(el, pre, pre.children!.length)
|
1615
1807
|
} else {
|