vue-editify 0.2.14 → 0.2.16
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +41 -88
- 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 -28
- 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 +38964 -37727
- 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 +194 -202
- 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 +108 -29
- package/src/core/tool.ts +237 -81
- package/src/editify/editify.less +4 -0
- package/src/editify/editify.vue +183 -194
- 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 +126 -0
- package/src/feature/attachment.ts +108 -0
- package/src/feature/backColor.ts +169 -0
- package/src/feature/bold.ts +134 -0
- package/src/feature/code.ts +134 -0
- package/src/feature/codeBlock.ts +201 -0
- package/src/feature/fontFamily.ts +138 -0
- package/src/feature/fontSize.ts +140 -0
- package/src/feature/foreColor.ts +171 -0
- package/src/feature/formatClear.ts +116 -0
- package/src/feature/fullScreen.ts +57 -0
- package/src/feature/heading.ts +152 -0
- package/src/feature/image.ts +222 -0
- package/src/feature/indent.ts +72 -0
- package/src/feature/infoBlock.ts +93 -0
- package/src/feature/italic.ts +134 -0
- package/src/feature/lineHeight.ts +163 -0
- package/src/feature/link.ts +146 -0
- package/src/feature/mathformula.ts +146 -0
- package/src/feature/orderList.ts +114 -0
- package/src/feature/panel.ts +107 -0
- package/src/feature/quote.ts +60 -0
- package/src/feature/redo.ts +56 -0
- package/src/feature/separator.ts +61 -0
- package/src/feature/sourceView.ts +59 -0
- package/src/feature/strikethrough.ts +134 -0
- package/src/feature/sub.ts +134 -0
- package/src/feature/super.ts +134 -0
- package/src/feature/table.ts +981 -0
- package/src/feature/task.ts +114 -0
- package/src/feature/underline.ts +134 -0
- package/src/feature/undo.ts +56 -0
- package/src/feature/unorderList.ts +114 -0
- package/src/feature/video.ts +335 -0
- package/src/hljs/index.ts +1 -1
- package/src/index.ts +82 -25
- 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
@@ -0,0 +1,152 @@
|
|
1
|
+
import { computed, defineComponent, h, inject, PropType, Ref, ref } from 'vue'
|
2
|
+
import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
|
3
|
+
import { common as DapCommon } from 'dap-util'
|
4
|
+
import { MenuDisplayButtonType } from '@/core/tool'
|
5
|
+
import { hasPanelInRange, hasPreInRange, hasTableInRange, setHeading } from '@/core/function'
|
6
|
+
import { Button, ButtonOptionsItemType } from '@/components/button'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* feature名称
|
10
|
+
*/
|
11
|
+
const FEATURE_NAME = 'heading'
|
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
|
+
/**
|
85
|
+
* 菜单栏 - 标题
|
86
|
+
*/
|
87
|
+
export const HeadingMenuButton = defineComponent(
|
88
|
+
props => {
|
89
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
90
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
91
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
92
|
+
const isSourceView = inject<Ref<boolean>>('isSourceView')!
|
93
|
+
const rangeKey = inject<Ref<number | null>>('rangeKey')!
|
94
|
+
|
95
|
+
const selectVal = computed<string>(() => {
|
96
|
+
const findHeadingItem = props.config.options!.find((item: string | number | ButtonOptionsItemType) => {
|
97
|
+
let val: string | number | ButtonOptionsItemType = item
|
98
|
+
if (DapCommon.isObject(item)) {
|
99
|
+
val = (item as ButtonOptionsItemType).value!
|
100
|
+
}
|
101
|
+
if (rangeKey.value && editor.value.range && editor.value.range.anchor.isEqual(editor.value.range!.focus)) {
|
102
|
+
return editor.value.range.anchor.element.getBlock().parsedom == val
|
103
|
+
}
|
104
|
+
return dataRangeCaches.value.list.every(el => {
|
105
|
+
if (el.element.isBlock()) {
|
106
|
+
return el.element.parsedom == val
|
107
|
+
}
|
108
|
+
return el.element.getBlock().parsedom == val
|
109
|
+
})
|
110
|
+
})
|
111
|
+
return findHeadingItem ? (DapCommon.isObject(findHeadingItem) ? ((findHeadingItem as ButtonOptionsItemType).value as string) : (findHeadingItem as string)) : (props.config.defaultValue as string)
|
112
|
+
})
|
113
|
+
|
114
|
+
return () => {
|
115
|
+
return props.config.show
|
116
|
+
? h(Button, {
|
117
|
+
name: FEATURE_NAME,
|
118
|
+
tooltip: props.tooltip,
|
119
|
+
color: props.color,
|
120
|
+
zIndex: props.zIndex,
|
121
|
+
type: 'display',
|
122
|
+
displayConfig: {
|
123
|
+
options: props.config.options,
|
124
|
+
value: selectVal.value,
|
125
|
+
width: props.config.width,
|
126
|
+
maxHeight: props.config.maxHeight
|
127
|
+
},
|
128
|
+
title: $editTrans('heading'),
|
129
|
+
leftBorder: props.config.leftBorder,
|
130
|
+
rightBorder: props.config.rightBorder,
|
131
|
+
active: false,
|
132
|
+
disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || hasPanelInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
|
133
|
+
onOperate: (_name: string, val: string) => {
|
134
|
+
setHeading(editor.value, dataRangeCaches.value, $editTrans, val)
|
135
|
+
editor.value.domRender()
|
136
|
+
editor.value.rangeRender()
|
137
|
+
}
|
138
|
+
})
|
139
|
+
: null
|
140
|
+
}
|
141
|
+
},
|
142
|
+
{
|
143
|
+
name: `_${FEATURE_NAME}`,
|
144
|
+
props: {
|
145
|
+
color: String,
|
146
|
+
zIndex: Number,
|
147
|
+
config: Object as PropType<MenuDisplayButtonType>,
|
148
|
+
tooltip: Boolean,
|
149
|
+
disabled: Boolean
|
150
|
+
}
|
151
|
+
}
|
152
|
+
)
|
@@ -0,0 +1,222 @@
|
|
1
|
+
import { defineComponent, h, inject, PropType, ref, Ref } from 'vue'
|
2
|
+
import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
|
3
|
+
import { Button } from '@/components/button'
|
4
|
+
import { Icon } from '@/components/icon'
|
5
|
+
import { getMatchElementByRange, hasMathformulaInRange, hasPreInRange, insertImage } from '@/core/function'
|
6
|
+
import { InsertImage } from '@/components/insertImage'
|
7
|
+
import { MenuImageButtonType } from '@/core/tool'
|
8
|
+
|
9
|
+
/**
|
10
|
+
* feature名称
|
11
|
+
*/
|
12
|
+
const FEATURE_NAME = 'image'
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 工具栏 - 图片操作
|
16
|
+
*/
|
17
|
+
export const ImageToolbar = defineComponent(
|
18
|
+
(props, { emit }) => {
|
19
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
20
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
21
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
22
|
+
|
23
|
+
//设置图片宽度
|
24
|
+
const setWidth = (value: string) => {
|
25
|
+
const element = editor.value.range!.anchor.element
|
26
|
+
if (element) {
|
27
|
+
const styles = {
|
28
|
+
width: value
|
29
|
+
}
|
30
|
+
if (element.hasStyles()) {
|
31
|
+
element.styles = Object.assign(element.styles!, styles)
|
32
|
+
} else {
|
33
|
+
element.styles = styles
|
34
|
+
}
|
35
|
+
editor.value.domRender()
|
36
|
+
editor.value.rangeRender()
|
37
|
+
//更新工具条位置
|
38
|
+
setTimeout(() => {
|
39
|
+
emit('reset-toolbar')
|
40
|
+
}, 0)
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
return () => {
|
45
|
+
return [
|
46
|
+
//30%
|
47
|
+
h(
|
48
|
+
Button,
|
49
|
+
{
|
50
|
+
name: 'set30Width',
|
51
|
+
title: $editTrans('width30'),
|
52
|
+
tooltip: props.tooltip,
|
53
|
+
color: props.color,
|
54
|
+
zIndex: props.zIndex,
|
55
|
+
onOperate: () => setWidth('30%')
|
56
|
+
},
|
57
|
+
{
|
58
|
+
default: () => ' 30% '
|
59
|
+
}
|
60
|
+
),
|
61
|
+
//50%
|
62
|
+
h(
|
63
|
+
Button,
|
64
|
+
{
|
65
|
+
name: 'set50Width',
|
66
|
+
title: $editTrans('width50'),
|
67
|
+
tooltip: props.tooltip,
|
68
|
+
color: props.color,
|
69
|
+
zIndex: props.zIndex,
|
70
|
+
onOperate: () => setWidth('50%')
|
71
|
+
},
|
72
|
+
{
|
73
|
+
default: () => ' 50% '
|
74
|
+
}
|
75
|
+
),
|
76
|
+
//100%
|
77
|
+
h(
|
78
|
+
Button,
|
79
|
+
{
|
80
|
+
name: 'set100Width',
|
81
|
+
title: $editTrans('width100'),
|
82
|
+
tooltip: props.tooltip,
|
83
|
+
color: props.color,
|
84
|
+
zIndex: props.zIndex,
|
85
|
+
onOperate: () => setWidth('100%')
|
86
|
+
},
|
87
|
+
{
|
88
|
+
default: () => ' 100% '
|
89
|
+
}
|
90
|
+
),
|
91
|
+
//宽度自适应
|
92
|
+
h(
|
93
|
+
Button,
|
94
|
+
{
|
95
|
+
name: 'setAutoWidth',
|
96
|
+
title: $editTrans('auto'),
|
97
|
+
tooltip: props.tooltip,
|
98
|
+
color: props.color,
|
99
|
+
zIndex: props.zIndex,
|
100
|
+
onOperate: () => setWidth('auto')
|
101
|
+
},
|
102
|
+
{
|
103
|
+
default: () => h(Icon, { value: 'auto-width' })
|
104
|
+
}
|
105
|
+
),
|
106
|
+
//删除图片
|
107
|
+
h(
|
108
|
+
Button,
|
109
|
+
{
|
110
|
+
name: 'deleteImage',
|
111
|
+
title: $editTrans('deleteImage'),
|
112
|
+
tooltip: props.tooltip,
|
113
|
+
color: props.color,
|
114
|
+
zIndex: props.zIndex,
|
115
|
+
onOperate: () => {
|
116
|
+
const element = getMatchElementByRange(editor.value, dataRangeCaches.value, { parsedom: 'img' })
|
117
|
+
if (element) {
|
118
|
+
element.toEmpty()
|
119
|
+
editor.value.domRender()
|
120
|
+
editor.value.rangeRender()
|
121
|
+
}
|
122
|
+
}
|
123
|
+
},
|
124
|
+
{
|
125
|
+
default: () => h(Icon, { value: 'delete' })
|
126
|
+
}
|
127
|
+
)
|
128
|
+
]
|
129
|
+
}
|
130
|
+
},
|
131
|
+
{
|
132
|
+
name: `_${FEATURE_NAME}`,
|
133
|
+
props: {
|
134
|
+
color: String,
|
135
|
+
zIndex: Number,
|
136
|
+
tooltip: Boolean
|
137
|
+
},
|
138
|
+
emits: ['reset-toolbar']
|
139
|
+
}
|
140
|
+
)
|
141
|
+
|
142
|
+
/**
|
143
|
+
* 菜单栏 - 插入图片
|
144
|
+
*/
|
145
|
+
export const ImageMenuButton = defineComponent(
|
146
|
+
props => {
|
147
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
148
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
149
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
150
|
+
const isSourceView = inject<Ref<boolean>>('isSourceView')!
|
151
|
+
|
152
|
+
const btnRef = ref<InstanceType<typeof Button> | null>(null)
|
153
|
+
|
154
|
+
return () => {
|
155
|
+
return props.config.show
|
156
|
+
? h(
|
157
|
+
Button,
|
158
|
+
{
|
159
|
+
ref: btnRef,
|
160
|
+
name: FEATURE_NAME,
|
161
|
+
tooltip: props.tooltip,
|
162
|
+
color: props.color,
|
163
|
+
zIndex: props.zIndex,
|
164
|
+
type: 'select',
|
165
|
+
hideScroll: true,
|
166
|
+
title: $editTrans('insertImage'),
|
167
|
+
leftBorder: props.config.leftBorder,
|
168
|
+
rightBorder: props.config.rightBorder,
|
169
|
+
active: false,
|
170
|
+
disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasMathformulaInRange(editor.value, dataRangeCaches.value) || props.config.disabled
|
171
|
+
},
|
172
|
+
{
|
173
|
+
default: () =>
|
174
|
+
h(Icon, {
|
175
|
+
value: 'image'
|
176
|
+
}),
|
177
|
+
layer: () =>
|
178
|
+
h(InsertImage, {
|
179
|
+
color: props.color,
|
180
|
+
allowedFileType: props.config.allowedFileType,
|
181
|
+
multiple: props.config.multiple,
|
182
|
+
maxSize: props.config.maxSize,
|
183
|
+
minSize: props.config.minSize,
|
184
|
+
customUpload: props.config.customUpload,
|
185
|
+
handleError: props.config.handleError,
|
186
|
+
onChange: () => {
|
187
|
+
btnRef.value!.layerRef!.setPosition()
|
188
|
+
},
|
189
|
+
onInsert: (val: string[]) => {
|
190
|
+
//过滤掉空的地址
|
191
|
+
const urls = val.filter(url => {
|
192
|
+
return !!url
|
193
|
+
})
|
194
|
+
//如果数组为0
|
195
|
+
if (urls.length == 0) {
|
196
|
+
return
|
197
|
+
}
|
198
|
+
//遍历每个地址进行插入
|
199
|
+
urls.forEach(url => {
|
200
|
+
insertImage(editor.value, url)
|
201
|
+
})
|
202
|
+
editor.value.domRender()
|
203
|
+
editor.value.rangeRender()
|
204
|
+
btnRef.value!.show = false
|
205
|
+
}
|
206
|
+
})
|
207
|
+
}
|
208
|
+
)
|
209
|
+
: null
|
210
|
+
}
|
211
|
+
},
|
212
|
+
{
|
213
|
+
name: `_${FEATURE_NAME}`,
|
214
|
+
props: {
|
215
|
+
color: String,
|
216
|
+
zIndex: Number,
|
217
|
+
config: Object as PropType<MenuImageButtonType>,
|
218
|
+
tooltip: Boolean,
|
219
|
+
disabled: Boolean
|
220
|
+
}
|
221
|
+
}
|
222
|
+
)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
|
+
import { AlexEditor, AlexElementsRangeType } from 'alex-editor'
|
3
|
+
import { Button } from '@/components/button'
|
4
|
+
import { MenuSelectButtonType } from '@/core/tool'
|
5
|
+
import { Icon } from '@/components/icon'
|
6
|
+
import { hasPreInRange, hasTableInRange, setIndentDecrease, setIndentIncrease } from '@/core/function'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* feature名称
|
10
|
+
*/
|
11
|
+
const FEATURE_NAME = 'indent'
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 菜单栏 - 缩进
|
15
|
+
*/
|
16
|
+
export const IndentMenuButton = defineComponent(
|
17
|
+
props => {
|
18
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
19
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
20
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
21
|
+
const isSourceView = inject<Ref<boolean>>('isSourceView')!
|
22
|
+
|
23
|
+
return () => {
|
24
|
+
return props.config.show
|
25
|
+
? h(
|
26
|
+
Button,
|
27
|
+
{
|
28
|
+
name: FEATURE_NAME,
|
29
|
+
tooltip: props.tooltip,
|
30
|
+
color: props.color,
|
31
|
+
zIndex: props.zIndex,
|
32
|
+
type: 'select',
|
33
|
+
title: $editTrans('indent'),
|
34
|
+
selectConfig: {
|
35
|
+
options: props.config.options,
|
36
|
+
width: props.config.width,
|
37
|
+
maxHeight: props.config.maxHeight
|
38
|
+
},
|
39
|
+
leftBorder: props.config.leftBorder,
|
40
|
+
rightBorder: props.config.rightBorder,
|
41
|
+
active: false,
|
42
|
+
disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || hasTableInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
|
43
|
+
onOperate: (_name, val: string) => {
|
44
|
+
if (val == 'indent-increase') {
|
45
|
+
setIndentIncrease(editor.value, dataRangeCaches.value)
|
46
|
+
}
|
47
|
+
//减少缩进
|
48
|
+
else if (val == 'indent-decrease') {
|
49
|
+
setIndentDecrease(editor.value, dataRangeCaches.value)
|
50
|
+
}
|
51
|
+
editor.value.domRender()
|
52
|
+
editor.value.rangeRender()
|
53
|
+
}
|
54
|
+
},
|
55
|
+
{
|
56
|
+
default: () => h(Icon, { value: 'indent-increase' })
|
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
|
+
disabled: Boolean
|
70
|
+
}
|
71
|
+
}
|
72
|
+
)
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { defineComponent, h, inject, PropType, Ref } from 'vue'
|
2
|
+
import { AlexEditor, AlexElement, AlexElementsRangeType } from 'alex-editor'
|
3
|
+
import { Button } from '@/components/button'
|
4
|
+
import { MenuButtonType } from '@/core/tool'
|
5
|
+
import { Icon } from '@/components/icon'
|
6
|
+
import { elementToParagraph, hasPanelInRange, hasPreInRange, hasTableInRange, rangeIsInInfoBlock } from '@/core/function'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* feature名称
|
10
|
+
*/
|
11
|
+
const FEATURE_NAME = 'infoBlock'
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 菜单栏 - 信息块
|
15
|
+
*/
|
16
|
+
export const InfoBlockMenuButton = defineComponent(
|
17
|
+
props => {
|
18
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
19
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
20
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
21
|
+
const isSourceView = inject<Ref<boolean>>('isSourceView')!
|
22
|
+
|
23
|
+
return () => {
|
24
|
+
return props.config.show
|
25
|
+
? h(
|
26
|
+
Button,
|
27
|
+
{
|
28
|
+
name: FEATURE_NAME,
|
29
|
+
tooltip: props.tooltip,
|
30
|
+
color: props.color,
|
31
|
+
zIndex: props.zIndex,
|
32
|
+
title: $editTrans('insertInfoBlock'),
|
33
|
+
leftBorder: props.config.leftBorder,
|
34
|
+
rightBorder: props.config.rightBorder,
|
35
|
+
active: rangeIsInInfoBlock(editor.value, dataRangeCaches.value),
|
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
|
+
onOperate: () => {
|
38
|
+
//是否都在信息块里
|
39
|
+
const flag = rangeIsInInfoBlock(editor.value, dataRangeCaches.value)
|
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
|
+
}
|
71
|
+
//渲染
|
72
|
+
editor.value.domRender()
|
73
|
+
editor.value.rangeRender()
|
74
|
+
}
|
75
|
+
},
|
76
|
+
{
|
77
|
+
default: () => h(Icon, { value: 'info' })
|
78
|
+
}
|
79
|
+
)
|
80
|
+
: null
|
81
|
+
}
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: `_${FEATURE_NAME}`,
|
85
|
+
props: {
|
86
|
+
color: String,
|
87
|
+
zIndex: Number,
|
88
|
+
config: Object as PropType<MenuButtonType>,
|
89
|
+
tooltip: Boolean,
|
90
|
+
disabled: Boolean
|
91
|
+
}
|
92
|
+
}
|
93
|
+
)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import { computed, defineComponent, h, inject, PropType, Ref, ref } from 'vue'
|
2
|
+
import { AlexElementsRangeType, AlexEditor } from 'alex-editor'
|
3
|
+
import { MenuButtonType } from '@/core/tool'
|
4
|
+
import { hasPreInRange, queryTextStyle, removeTextStyle, setTextStyle } from '@/core/function'
|
5
|
+
import { Button } from '@/components/button'
|
6
|
+
import { Icon } from '@/components/icon'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* feature名称
|
10
|
+
*/
|
11
|
+
const FEATURE_NAME = 'italic'
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 工具栏 - 斜体
|
15
|
+
*/
|
16
|
+
export const ItalicToolbarButton = 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 active = computed<boolean>(() => {
|
25
|
+
return queryTextStyle(editor.value, dataRangeCaches.value, 'font-style', 'italic')
|
26
|
+
})
|
27
|
+
|
28
|
+
expose({
|
29
|
+
btnRef
|
30
|
+
})
|
31
|
+
|
32
|
+
return () => {
|
33
|
+
return props.config.show
|
34
|
+
? h(
|
35
|
+
Button,
|
36
|
+
{
|
37
|
+
ref: btnRef,
|
38
|
+
name: FEATURE_NAME,
|
39
|
+
title: $editTrans('italic'),
|
40
|
+
tooltip: props.tooltip,
|
41
|
+
color: props.color,
|
42
|
+
zIndex: props.zIndex,
|
43
|
+
leftBorder: props.config.leftBorder,
|
44
|
+
rightBorder: props.config.rightBorder,
|
45
|
+
active: active.value,
|
46
|
+
disabled: props.config.disabled,
|
47
|
+
onOperate: () => {
|
48
|
+
if (active.value) {
|
49
|
+
removeTextStyle(editor.value, dataRangeCaches.value, ['font-style'])
|
50
|
+
} else {
|
51
|
+
setTextStyle(editor.value, dataRangeCaches.value, {
|
52
|
+
'font-style': 'italic'
|
53
|
+
})
|
54
|
+
}
|
55
|
+
editor.value.domRender()
|
56
|
+
editor.value.rangeRender()
|
57
|
+
}
|
58
|
+
},
|
59
|
+
{
|
60
|
+
default: () => h(Icon, { value: 'italic' })
|
61
|
+
}
|
62
|
+
)
|
63
|
+
: null
|
64
|
+
}
|
65
|
+
},
|
66
|
+
{
|
67
|
+
name: `_${FEATURE_NAME}`,
|
68
|
+
props: {
|
69
|
+
color: String,
|
70
|
+
zIndex: Number,
|
71
|
+
config: Object as PropType<MenuButtonType>,
|
72
|
+
tooltip: Boolean
|
73
|
+
}
|
74
|
+
}
|
75
|
+
)
|
76
|
+
|
77
|
+
/**
|
78
|
+
* 菜单栏 - 斜体
|
79
|
+
*/
|
80
|
+
export const ItalicMenuButton = defineComponent(
|
81
|
+
props => {
|
82
|
+
const editor = inject<Ref<AlexEditor>>('editor')!
|
83
|
+
const dataRangeCaches = inject<Ref<AlexElementsRangeType>>('dataRangeCaches')!
|
84
|
+
const $editTrans = inject<(key: string) => any>('$editTrans')!
|
85
|
+
const isSourceView = inject<Ref<boolean>>('isSourceView')!
|
86
|
+
|
87
|
+
const active = computed<boolean>(() => {
|
88
|
+
return queryTextStyle(editor.value, dataRangeCaches.value, 'font-style', 'italic')
|
89
|
+
})
|
90
|
+
|
91
|
+
return () => {
|
92
|
+
return props.config.show
|
93
|
+
? h(
|
94
|
+
Button,
|
95
|
+
{
|
96
|
+
name: FEATURE_NAME,
|
97
|
+
tooltip: props.tooltip,
|
98
|
+
color: props.color,
|
99
|
+
zIndex: props.zIndex,
|
100
|
+
title: $editTrans('italic'),
|
101
|
+
leftBorder: props.config.leftBorder,
|
102
|
+
rightBorder: props.config.rightBorder,
|
103
|
+
disabled: props.disabled || isSourceView.value || hasPreInRange(editor.value, dataRangeCaches.value) || props.config.disabled,
|
104
|
+
active: active.value,
|
105
|
+
onOperate: () => {
|
106
|
+
if (active.value) {
|
107
|
+
removeTextStyle(editor.value, dataRangeCaches.value, ['font-style'])
|
108
|
+
} else {
|
109
|
+
setTextStyle(editor.value, dataRangeCaches.value, {
|
110
|
+
'font-style': 'italic'
|
111
|
+
})
|
112
|
+
}
|
113
|
+
editor.value.domRender()
|
114
|
+
editor.value.rangeRender()
|
115
|
+
}
|
116
|
+
},
|
117
|
+
{
|
118
|
+
default: () => h(Icon, { value: 'italic' })
|
119
|
+
}
|
120
|
+
)
|
121
|
+
: null
|
122
|
+
}
|
123
|
+
},
|
124
|
+
{
|
125
|
+
name: `_${FEATURE_NAME}`,
|
126
|
+
props: {
|
127
|
+
color: String,
|
128
|
+
zIndex: Number,
|
129
|
+
config: Object as PropType<MenuButtonType>,
|
130
|
+
tooltip: Boolean,
|
131
|
+
disabled: Boolean
|
132
|
+
}
|
133
|
+
}
|
134
|
+
)
|