vue-editify 0.2.16 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +289 -5
- package/lib/components/colors/colors.vue.d.ts +9 -0
- package/lib/components/colors/props.d.ts +4 -0
- package/lib/core/function.d.ts +120 -45
- package/lib/core/rule.d.ts +23 -17
- package/lib/core/tool.d.ts +1 -13
- package/lib/editify/editify.vue.d.ts +10 -1
- package/lib/editify/props.d.ts +1 -1
- package/lib/editify/toolbar/props.d.ts +1 -1
- package/lib/editify/toolbar/toolbar.vue.d.ts +3 -3
- package/lib/editify.es.js +13640 -13799
- package/lib/editify.umd.js +2 -2
- package/lib/feature/align.d.ts +0 -14
- package/lib/feature/heading.d.ts +0 -14
- package/lib/feature/lineHeight.d.ts +0 -14
- package/lib/feature/orderList.d.ts +1 -3
- package/lib/feature/task.d.ts +0 -14
- package/lib/feature/unorderList.d.ts +1 -3
- package/lib/index.d.ts +12 -3
- package/package.json +2 -2
- package/src/components/button/button.vue +3 -3
- package/src/components/checkbox/checkbox.vue +1 -1
- package/src/components/colors/colors.vue +4 -4
- package/src/components/colors/props.ts +6 -1
- package/src/components/insertAttachment/insertAttachment.vue +1 -1
- package/src/components/insertImage/insertImage.vue +1 -1
- package/src/components/insertLink/insertLink.vue +1 -1
- package/src/components/insertVideo/insertVideo.vue +1 -1
- package/src/components/layer/layer.vue +9 -3
- package/src/components/tooltip/tooltip.vue +1 -1
- package/src/components/updateLink/updateLink.vue +1 -1
- package/src/core/function.ts +961 -475
- package/src/core/rule.ts +85 -367
- package/src/core/tool.ts +8 -114
- package/src/editify/editify.less +88 -14
- package/src/editify/editify.vue +117 -65
- package/src/editify/props.ts +1 -1
- package/src/editify/toolbar/props.ts +2 -2
- package/src/editify/toolbar/toolbar.vue +12 -12
- package/src/feature/align.ts +1 -61
- package/src/feature/attachment.ts +13 -26
- package/src/feature/backColor.ts +1 -0
- package/src/feature/foreColor.ts +1 -0
- package/src/feature/heading.ts +2 -73
- package/src/feature/infoBlock.ts +4 -35
- package/src/feature/lineHeight.ts +1 -77
- package/src/feature/mathformula.ts +3 -50
- package/src/feature/orderList.ts +166 -35
- package/src/feature/panel.ts +4 -49
- package/src/feature/sub.ts +1 -1
- package/src/feature/super.ts +1 -1
- package/src/feature/task.ts +1 -55
- package/src/feature/unorderList.ts +106 -35
- package/src/feature/video.ts +1 -1
- package/src/icon/iconfont.css +40 -0
- package/src/icon/iconfont.ttf +0 -0
- package/src/icon/iconfont.woff +0 -0
- package/src/index.ts +14 -8
- package/src/locale/en_US.ts +112 -110
- package/src/locale/zh_CN.ts +11 -9
@@ -1,16 +1,20 @@
|
|
1
1
|
<template>
|
2
2
|
<Layer v-model="show" ref="layerRef" :node="node" :scroll-node="scrollNode" border placement="bottom-start" :useRange="type == 'text'" :z-index="zIndex" :inside-elements="insideElements">
|
3
3
|
<div class="editify-toolbar" :style="config.style">
|
4
|
-
<!-- 链接工具条 -->
|
5
|
-
<linkToolbar v-if="type == 'link'" :color="color" />
|
6
4
|
<!-- 图片工具条 -->
|
7
|
-
<ImageToolbar v-
|
5
|
+
<ImageToolbar v-if="type == 'image'" @reset-toolbar="layerRef!.setPosition()" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
8
6
|
<!-- 视频工具条 -->
|
9
7
|
<VideoToolbar v-else-if="type == 'video'" @reset-toolbar="layerRef!.setPosition()" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
10
|
-
<!-- 表格工具条 -->
|
11
|
-
<TableToolbar v-else-if="type == 'table'" @reset-toolbar="layerRef!.setPosition()" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
12
8
|
<!-- 代码块工具条 -->
|
13
9
|
<CodeBlockToolbar v-else-if="type == 'codeBlock'" ref="codeBlockToolbarRef" :language="config.codeBlock!.languages!" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
10
|
+
<!-- 链接工具条 -->
|
11
|
+
<linkToolbar v-else-if="type == 'link'" :color="color" />
|
12
|
+
<!-- 表格工具条 -->
|
13
|
+
<TableToolbar v-else-if="type == 'table'" @reset-toolbar="layerRef!.setPosition()" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
14
|
+
<!-- 有序列表工具条 -->
|
15
|
+
<OrderListToolbar v-else-if="type == 'orderList'" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
16
|
+
<!-- 无序列表工具条 -->
|
17
|
+
<UnorderListToolbar v-else-if="type == 'unorderList'" :tooltip="config.tooltip!" :color="color" :z-index="zIndex + 1" />
|
14
18
|
<!-- 文本工具条 -->
|
15
19
|
<template v-else-if="type == 'text'">
|
16
20
|
<component v-for="(btn, index) in textToolbarBtns" :ref="el => (textToolbarBtnRefs[index] = (el as BtnComponentPublicInstance))" :is="btn" :color="color" :z-index="zIndex + 1" :config="textButtonConfig(btn.name)" :tooltip="config.tooltip!" />
|
@@ -28,11 +32,8 @@ import { ImageToolbar } from '@/feature/image'
|
|
28
32
|
import { VideoToolbar } from '@/feature/video'
|
29
33
|
import { TableToolbar } from '@/feature/table'
|
30
34
|
import { CodeBlockToolbar } from '@/feature/codeBlock'
|
31
|
-
import {
|
32
|
-
import {
|
33
|
-
import { OrderListToolbarButton } from '@/feature/orderList'
|
34
|
-
import { UnorderListToolbarButton } from '@/feature/unorderList'
|
35
|
-
import { TaskToolbarButton } from '@/feature/task'
|
35
|
+
import { OrderListToolbar } from '@/feature/orderList'
|
36
|
+
import { UnorderListToolbar } from '@/feature/unorderList'
|
36
37
|
import { BoldToolbarButton } from '@/feature/bold'
|
37
38
|
import { ItalicToolbarButton } from '@/feature/italic'
|
38
39
|
import { StrikethroughToolbarButton } from '@/feature/strikethrough'
|
@@ -42,7 +43,6 @@ import { SuperToolbarButton } from '@/feature/super'
|
|
42
43
|
import { SubToolbarButton } from '@/feature/sub'
|
43
44
|
import { FontSizeToolbarButton } from '@/feature/fontSize'
|
44
45
|
import { FontFamilyToolbarButton } from '@/feature/fontFamily'
|
45
|
-
import { LineHeightToolbarButton } from '@/feature/lineHeight'
|
46
46
|
import { ForeColorToolbarButton } from '@/feature/foreColor'
|
47
47
|
import { BackColorToolbarButton } from '@/feature/backColor'
|
48
48
|
import { FormatClearToolbarButton } from '@/feature/formatClear'
|
@@ -62,7 +62,7 @@ type BtnComponentPublicInstance = ComponentPublicInstance & { btnRef: InstanceTy
|
|
62
62
|
//代码块语言选择按钮实例
|
63
63
|
const codeBlockToolbarRef = ref<BtnComponentPublicInstance | null>(null)
|
64
64
|
//文本工具条按钮数组
|
65
|
-
const textToolbarBtns = shallowRef([
|
65
|
+
const textToolbarBtns = shallowRef([BoldToolbarButton, ItalicToolbarButton, StrikethroughToolbarButton, UnderlineToolbarButton, CodeToolbarButton, SuperToolbarButton, SubToolbarButton, FontSizeToolbarButton, FontFamilyToolbarButton, ForeColorToolbarButton, BackColorToolbarButton, FormatClearToolbarButton])
|
66
66
|
//文本工具条按钮实例
|
67
67
|
const textToolbarBtnRefs = ref<BtnComponentPublicInstance[]>([])
|
68
68
|
|
package/src/feature/align.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { defineComponent, h, inject, PropType, Ref
|
1
|
+
import { defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
2
|
import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
|
3
3
|
import { MenuSelectButtonType } from '@/core/tool'
|
4
4
|
import { hasPreInRange, setAlign } from '@/core/function'
|
@@ -10,66 +10,6 @@ import { Icon } from '@/components/icon'
|
|
10
10
|
*/
|
11
11
|
const FEATURE_NAME = 'align'
|
12
12
|
|
13
|
-
/**
|
14
|
-
* 工具栏 - 对齐方式
|
15
|
-
*/
|
16
|
-
export const AlignToolbarButton = defineComponent(
|
17
|
-
(props, { expose }) => {
|
18
|
-
const editor = inject<Ref<AlexEditor>>('editor')!
|
19
|
-
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
20
|
-
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
21
|
-
|
22
|
-
const btnRef = ref<InstanceType<typeof Button> | null>(null)
|
23
|
-
|
24
|
-
expose({
|
25
|
-
btnRef
|
26
|
-
})
|
27
|
-
|
28
|
-
return () => {
|
29
|
-
return props.config.show
|
30
|
-
? h(
|
31
|
-
Button,
|
32
|
-
{
|
33
|
-
ref: btnRef,
|
34
|
-
name: FEATURE_NAME,
|
35
|
-
type: 'select',
|
36
|
-
title: $editTrans('align'),
|
37
|
-
tooltip: props.tooltip,
|
38
|
-
color: props.color,
|
39
|
-
zIndex: props.zIndex,
|
40
|
-
leftBorder: props.config.leftBorder,
|
41
|
-
rightBorder: props.config.rightBorder,
|
42
|
-
active: false,
|
43
|
-
disabled: props.config.disabled,
|
44
|
-
selectConfig: {
|
45
|
-
options: props.config.options,
|
46
|
-
width: props.config.width,
|
47
|
-
maxHeight: props.config.maxHeight
|
48
|
-
},
|
49
|
-
onOperate: (_name: string, val: 'left' | 'right' | 'center' | 'justify') => {
|
50
|
-
setAlign(editor.value, dataRangeCaches.value, val)
|
51
|
-
editor.value.domRender()
|
52
|
-
editor.value.rangeRender()
|
53
|
-
}
|
54
|
-
},
|
55
|
-
{
|
56
|
-
default: () => h(Icon, { value: 'align-left' })
|
57
|
-
}
|
58
|
-
)
|
59
|
-
: null
|
60
|
-
}
|
61
|
-
},
|
62
|
-
{
|
63
|
-
name: `_${FEATURE_NAME}`,
|
64
|
-
props: {
|
65
|
-
color: String,
|
66
|
-
zIndex: Number,
|
67
|
-
config: Object as PropType<MenuSelectButtonType>,
|
68
|
-
tooltip: Boolean
|
69
|
-
}
|
70
|
-
}
|
71
|
-
)
|
72
|
-
|
73
13
|
/**
|
74
14
|
* 菜单栏 - 对齐方式
|
75
15
|
*/
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { defineComponent, h, inject, PropType, ref, Ref } from 'vue'
|
2
|
-
import { AlexEditor,
|
3
|
-
import { MenuAttachmentButtonType
|
2
|
+
import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
|
3
|
+
import { MenuAttachmentButtonType } from '@/core/tool'
|
4
4
|
import { Button } from '@/components/button'
|
5
|
-
import { hasMathformulaInRange, hasPreInRange } from '@/core/function'
|
5
|
+
import { hasMathformulaInRange, hasPreInRange, insertAttachment } from '@/core/function'
|
6
6
|
import { Icon } from '@/components/icon'
|
7
7
|
import { InsertAttachment } from '@/components/insertAttachment'
|
8
8
|
|
@@ -62,30 +62,17 @@ export const AttachmentMenuButton = defineComponent(
|
|
62
62
|
urls = urls.filter(url => {
|
63
63
|
return !!url
|
64
64
|
})
|
65
|
-
|
66
|
-
if (urls.length) {
|
67
|
-
|
68
|
-
urls.forEach(url => {
|
69
|
-
const marks: ObjectType = {
|
70
|
-
'data-editify-attachment': url,
|
71
|
-
'data-editify-attachment-name': name || $editTrans('attachmentDefaultName')
|
72
|
-
}
|
73
|
-
//创建元素
|
74
|
-
const attachmentElement = AlexElement.create({
|
75
|
-
type: 'closed',
|
76
|
-
parsedom: 'span',
|
77
|
-
marks
|
78
|
-
})
|
79
|
-
//插入编辑器
|
80
|
-
editor.value.insertElement(attachmentElement)
|
81
|
-
//移动光标到新插入的元素
|
82
|
-
editor.value.range!.anchor.moveToEnd(attachmentElement)
|
83
|
-
editor.value.range!.focus.moveToEnd(attachmentElement)
|
84
|
-
})
|
85
|
-
//渲染
|
86
|
-
editor.value.domRender()
|
87
|
-
editor.value.rangeRender()
|
65
|
+
//如果数组为0
|
66
|
+
if (urls.length == 0) {
|
67
|
+
return
|
88
68
|
}
|
69
|
+
//遍历地址数组
|
70
|
+
urls.forEach(url => {
|
71
|
+
insertAttachment(editor.value, url, name || $editTrans('attachmentDefaultName'))
|
72
|
+
})
|
73
|
+
//渲染
|
74
|
+
editor.value.domRender()
|
75
|
+
editor.value.rangeRender()
|
89
76
|
//关闭浮层
|
90
77
|
btnRef.value!.show = false
|
91
78
|
}
|
package/src/feature/backColor.ts
CHANGED
package/src/feature/foreColor.ts
CHANGED
package/src/feature/heading.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { computed, defineComponent, h, inject, PropType, Ref
|
1
|
+
import { computed, defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
2
|
import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
|
3
3
|
import { common as DapCommon } from 'dap-util'
|
4
4
|
import { MenuDisplayButtonType } from '@/core/tool'
|
@@ -10,77 +10,6 @@ import { Button, ButtonOptionsItemType } from '@/components/button'
|
|
10
10
|
*/
|
11
11
|
const FEATURE_NAME = 'heading'
|
12
12
|
|
13
|
-
/**
|
14
|
-
* 工具栏 - 标题
|
15
|
-
*/
|
16
|
-
export const HeadingToolbarButton = defineComponent(
|
17
|
-
(props, { expose }) => {
|
18
|
-
const editor = inject<Ref<AlexEditor>>('editor')!
|
19
|
-
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
20
|
-
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
21
|
-
|
22
|
-
const btnRef = ref<InstanceType<typeof Button> | null>(null)
|
23
|
-
|
24
|
-
const selectVal = computed<string>(() => {
|
25
|
-
//显示已设置标题
|
26
|
-
const findHeadingItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
|
27
|
-
let val: string | number | ButtonOptionsItemType = item
|
28
|
-
if (DapCommon.isObject(item)) {
|
29
|
-
val = (item as ButtonOptionsItemType).value!
|
30
|
-
}
|
31
|
-
return dataRangeCaches.value.list.every(el => {
|
32
|
-
if (el.element.isBlock()) {
|
33
|
-
return el.element.parsedom == val
|
34
|
-
}
|
35
|
-
return el.element.getBlock().parsedom == val
|
36
|
-
})
|
37
|
-
})
|
38
|
-
return findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? ((findHeadingItem as ButtonOptionsItemType).value as string) : (findHeadingItem as string)) : (props.config.defaultValue as string)
|
39
|
-
})
|
40
|
-
|
41
|
-
expose({
|
42
|
-
btnRef
|
43
|
-
})
|
44
|
-
return () => {
|
45
|
-
return props.config.show
|
46
|
-
? h(Button, {
|
47
|
-
ref: btnRef,
|
48
|
-
name: FEATURE_NAME,
|
49
|
-
type: 'display',
|
50
|
-
title: $editTrans('heading'),
|
51
|
-
tooltip: props.tooltip,
|
52
|
-
color: props.color,
|
53
|
-
zIndex: props.zIndex,
|
54
|
-
leftBorder: props.config.leftBorder,
|
55
|
-
rightBorder: props.config.rightBorder,
|
56
|
-
active: false,
|
57
|
-
disabled: props.config.disabled,
|
58
|
-
displayConfig: {
|
59
|
-
options: props.config.options,
|
60
|
-
value: selectVal.value,
|
61
|
-
width: props.config.width,
|
62
|
-
maxHeight: props.config.maxHeight
|
63
|
-
},
|
64
|
-
onOperate: (_name: string, val: string) => {
|
65
|
-
setHeading(editor.value, dataRangeCaches.value, $editTrans, val)
|
66
|
-
editor.value.domRender()
|
67
|
-
editor.value.rangeRender()
|
68
|
-
}
|
69
|
-
})
|
70
|
-
: null
|
71
|
-
}
|
72
|
-
},
|
73
|
-
{
|
74
|
-
name: `_${FEATURE_NAME}`,
|
75
|
-
props: {
|
76
|
-
color: String,
|
77
|
-
zIndex: Number,
|
78
|
-
config: Object as PropType<MenuDisplayButtonType>,
|
79
|
-
tooltip: Boolean
|
80
|
-
}
|
81
|
-
}
|
82
|
-
)
|
83
|
-
|
84
13
|
/**
|
85
14
|
* 菜单栏 - 标题
|
86
15
|
*/
|
@@ -131,7 +60,7 @@ export const HeadingMenuButton = defineComponent(
|
|
131
60
|
active: false,
|
132
61
|
disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || hasPanelInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
|
133
62
|
onOperate: (_name: string, val: string) => {
|
134
|
-
setHeading(editor.value, dataRangeCaches.value,
|
63
|
+
setHeading(editor.value, dataRangeCaches.value, val)
|
135
64
|
editor.value.domRender()
|
136
65
|
editor.value.rangeRender()
|
137
66
|
}
|
package/src/feature/infoBlock.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
|
-
import { AlexEditor,
|
2
|
+
import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
|
3
3
|
import { Button } from '@/components/button'
|
4
4
|
import { MenuButtonType } from '@/core/tool'
|
5
5
|
import { Icon } from '@/components/icon'
|
6
|
-
import {
|
6
|
+
import { hasPanelInRange, hasPreInRange, hasTableInRange, insertInfoBlock, rangeIsInInfoBlock } from '@/core/function'
|
7
7
|
|
8
8
|
/**
|
9
9
|
* feature名称
|
@@ -35,39 +35,8 @@ export const InfoBlockMenuButton = defineComponent(
|
|
35
35
|
active: rangeIsInInfoBlock(editor.value, dataRangeCaches.value),
|
36
36
|
disabled: props.disabled || isSourceView.value || hasPanelInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
|
37
37
|
onOperate: () => {
|
38
|
-
|
39
|
-
|
40
|
-
//起点和终点在一起
|
41
|
-
if (editor.value.range!.anchor.isEqual(editor.value.range!.focus)) {
|
42
|
-
const block = editor.value.range!.anchor.element.getBlock()
|
43
|
-
elementToParagraph(block)
|
44
|
-
if (!flag) {
|
45
|
-
block.parsedom = 'div'
|
46
|
-
block.marks = {
|
47
|
-
'data-editify-info': 'true'
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
//起点和终点不在一起
|
52
|
-
else {
|
53
|
-
let blocks: AlexElement[] = []
|
54
|
-
dataRangeCaches.value.list.forEach(item => {
|
55
|
-
const block = item.element.getBlock()
|
56
|
-
const exist = blocks.some(el => block.isEqual(el))
|
57
|
-
if (!exist) {
|
58
|
-
blocks.push(block)
|
59
|
-
}
|
60
|
-
})
|
61
|
-
blocks.forEach(block => {
|
62
|
-
elementToParagraph(block)
|
63
|
-
if (!flag) {
|
64
|
-
block.parsedom = 'div'
|
65
|
-
block.marks = {
|
66
|
-
'data-editify-info': 'true'
|
67
|
-
}
|
68
|
-
}
|
69
|
-
})
|
70
|
-
}
|
38
|
+
//插入信息块
|
39
|
+
insertInfoBlock(editor.value, dataRangeCaches.value)
|
71
40
|
//渲染
|
72
41
|
editor.value.domRender()
|
73
42
|
editor.value.rangeRender()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { computed, defineComponent, h, inject, PropType, Ref
|
1
|
+
import { computed, defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
2
|
import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
|
3
3
|
import { common as DapCommon } from 'dap-util'
|
4
4
|
import { MenuDisplayButtonType } from '@/core/tool'
|
@@ -10,82 +10,6 @@ import { Button, ButtonOptionsItemType } from '@/components/button'
|
|
10
10
|
*/
|
11
11
|
const FEATURE_NAME = 'lineHeight'
|
12
12
|
|
13
|
-
/**
|
14
|
-
* 工具栏 - 行高
|
15
|
-
*/
|
16
|
-
export const LineHeightToolbarButton = defineComponent(
|
17
|
-
(props, { expose }) => {
|
18
|
-
const editor = inject<Ref<AlexEditor>>('editor')!
|
19
|
-
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
20
|
-
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
21
|
-
|
22
|
-
const btnRef = ref<InstanceType<typeof Button> | null>(null)
|
23
|
-
|
24
|
-
const selectVal = computed<string | number>(() => {
|
25
|
-
const findHeightItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
|
26
|
-
let val: string | number | ButtonOptionsItemType = item
|
27
|
-
if (DapCommon.isObject(item)) {
|
28
|
-
val = (item as ButtonOptionsItemType).value!
|
29
|
-
}
|
30
|
-
return dataRangeCaches.value.list.every(el => {
|
31
|
-
if (el.element.isBlock() || el.element.isInblock()) {
|
32
|
-
return el.element.hasStyles() && el.element.styles!['line-height'] == val
|
33
|
-
}
|
34
|
-
const block = el.element.getBlock()
|
35
|
-
const inblock = el.element.getInblock()
|
36
|
-
if (inblock) {
|
37
|
-
return inblock.hasStyles() && inblock.styles!['line-height'] == val
|
38
|
-
}
|
39
|
-
return block.hasStyles() && block.styles!['line-height'] == val
|
40
|
-
})
|
41
|
-
})
|
42
|
-
return findHeightItem ? (DapCommon.isObject(findHeightItem) ? ((findHeightItem as ButtonOptionsItemType).value as string | number) : (findHeightItem as string | number)) : (props.config.defaultValue as string | number)
|
43
|
-
})
|
44
|
-
|
45
|
-
expose({
|
46
|
-
btnRef
|
47
|
-
})
|
48
|
-
|
49
|
-
return () => {
|
50
|
-
return props.config.show
|
51
|
-
? h(Button, {
|
52
|
-
ref: btnRef,
|
53
|
-
name: FEATURE_NAME,
|
54
|
-
type: 'display',
|
55
|
-
title: $editTrans('lineHeight'),
|
56
|
-
tooltip: props.tooltip,
|
57
|
-
color: props.color,
|
58
|
-
zIndex: props.zIndex,
|
59
|
-
leftBorder: props.config.leftBorder,
|
60
|
-
rightBorder: props.config.rightBorder,
|
61
|
-
active: false,
|
62
|
-
disabled: props.config.disabled,
|
63
|
-
displayConfig: {
|
64
|
-
options: props.config.options,
|
65
|
-
value: selectVal.value,
|
66
|
-
width: props.config.width,
|
67
|
-
maxHeight: props.config.maxHeight
|
68
|
-
},
|
69
|
-
onOperate: (_name: string, val: string) => {
|
70
|
-
setLineHeight(editor.value, dataRangeCaches.value, val)
|
71
|
-
editor.value.domRender()
|
72
|
-
editor.value.rangeRender()
|
73
|
-
}
|
74
|
-
})
|
75
|
-
: null
|
76
|
-
}
|
77
|
-
},
|
78
|
-
{
|
79
|
-
name: `_${FEATURE_NAME}`,
|
80
|
-
props: {
|
81
|
-
color: String,
|
82
|
-
zIndex: Number,
|
83
|
-
config: Object as PropType<MenuDisplayButtonType>,
|
84
|
-
tooltip: Boolean
|
85
|
-
}
|
86
|
-
}
|
87
|
-
)
|
88
|
-
|
89
13
|
/**
|
90
14
|
* 菜单栏 - 行高
|
91
15
|
*/
|
@@ -1,10 +1,8 @@
|
|
1
1
|
import { computed, defineComponent, h, inject, PropType, ref, Ref } from 'vue'
|
2
2
|
import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
|
3
|
-
import 'katex/dist/katex.css'
|
4
|
-
import KaTex from 'katex'
|
5
3
|
import { MenuMathformulaButtonType } from '@/core/tool'
|
6
4
|
import { Button } from '@/components/button'
|
7
|
-
import { getMatchElementByRange, hasLinkInRange, hasPreInRange } from '@/core/function'
|
5
|
+
import { getMatchElementByRange, hasLinkInRange, hasPreInRange, insertMathformula } from '@/core/function'
|
8
6
|
import { Icon } from '@/components/icon'
|
9
7
|
import { InsertMathformula } from '@/components/insertMathformula'
|
10
8
|
|
@@ -77,53 +75,8 @@ export const MathformulaMenuButton = defineComponent(
|
|
77
75
|
color: props.color,
|
78
76
|
defaultLaTexContent: defaultLaTexContent.value,
|
79
77
|
onInsert: (content: string) => {
|
80
|
-
|
81
|
-
|
82
|
-
//获取选区所在的数学公式元素
|
83
|
-
const mathformulaElement = getMatchElementByRange(editor.value, dataRangeCaches.value, {
|
84
|
-
parsedom: 'span',
|
85
|
-
marks: {
|
86
|
-
'data-editify-mathformula': true
|
87
|
-
}
|
88
|
-
})
|
89
|
-
//如果在数学公式下
|
90
|
-
if (mathformulaElement) {
|
91
|
-
//清除该数学公式
|
92
|
-
mathformulaElement.toEmpty()
|
93
|
-
//移动光标到后一个元素上
|
94
|
-
editor.value.range!.anchor.moveToStart(editor.value.getNextElement(mathformulaElement)!)
|
95
|
-
editor.value.range!.focus.moveToStart(editor.value.getNextElement(mathformulaElement)!)
|
96
|
-
}
|
97
|
-
//定义转换后的mathml内容
|
98
|
-
let mathml: string = ''
|
99
|
-
try {
|
100
|
-
//获取转换后的mathml
|
101
|
-
mathml = KaTex.renderToString(content, {
|
102
|
-
output: 'mathml',
|
103
|
-
throwOnError: true
|
104
|
-
})
|
105
|
-
} catch (error) {
|
106
|
-
mathml = ''
|
107
|
-
if (typeof props.config!.handleError == 'function') {
|
108
|
-
props.config!.handleError(error as Error)
|
109
|
-
}
|
110
|
-
}
|
111
|
-
//如果mathml存在则表示数学公式渲染成功则插入到编辑器
|
112
|
-
if (mathml) {
|
113
|
-
//设置最终的html内容
|
114
|
-
const html = `<span data-editify-mathformula="${content}" contenteditable="false">${mathml}</span>`
|
115
|
-
//html内容转为元素数组
|
116
|
-
const elements = editor.value.parseHtml(html)
|
117
|
-
//插入编辑器
|
118
|
-
editor.value.insertElement(elements[0])
|
119
|
-
//移动光标到新插入的元素
|
120
|
-
editor.value.range!.anchor.moveToEnd(elements[0])
|
121
|
-
editor.value.range!.focus.moveToEnd(elements[0])
|
122
|
-
//渲染
|
123
|
-
editor.value.domRender()
|
124
|
-
editor.value.rangeRender()
|
125
|
-
}
|
126
|
-
}
|
78
|
+
//插入数学公式
|
79
|
+
insertMathformula(editor.value, dataRangeCaches.value, content, props.config.handleError)
|
127
80
|
//关闭浮层
|
128
81
|
btnRef.value!.show = false
|
129
82
|
}
|